home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1993 / USERJN93.MSA / DEVPAC2_OLDGEM_GEMDEMO.S < prev    next >
Text File  |  1993-04-20  |  9KB  |  338 lines

  1.  
  2. * a sample GEM program supplied with DevpacST version 2
  3.  
  4. * Source code Copyright (C) 1988 HiSoft. All rights reserved.
  5. * No part of this source may be reproduced, transmitted,
  6. * transcribed, or stored in a retrieval system, or translated
  7. * in any form or by any means without the prior written
  8. * permission of HiSoft.
  9.  
  10. * HiSoft makes no representations or warranties with respect
  11. * to the contents hereof and specifically disclaims any
  12. * implied warranties or merchantability or fitness for any
  13. * particular purpose.
  14.  
  15. * feel free to use any or all of the object code
  16.  
  17. * if you find any bugs in the GEMINC file, please tell us.
  18. * we cannot guarantee that this program itself is free of bugs!!
  19.  
  20. * If you cannot assemble this exactly as supplied, tell us.
  21. * If the object doesn't run after you have made any changes,
  22. * please do not tell us, as you're on your own once you
  23. * start messing with it!
  24.  
  25. * this is mainly to show the calling sequence for GEM
  26. * from assembler - the program itself doesn't do much
  27.  
  28. * last changed:21.3.88
  29.  
  30.     opt x+                dump long labels for debugging
  31.  
  32. * the important include file
  33.     bra    main            shouldn't execute it
  34.  
  35.     include    geminc.s
  36.  
  37. * the program proper
  38. main    do_start            set up stack and memory
  39.     bsr initvdipars            and the VDI arrays
  40.     bsr initgempars            and the AES arrays
  41.     gem APPL_INIT
  42.     move.w d0,ap_id(a6)        store the application id
  43.  
  44.     gem    GRAF_HANDLE
  45.     move.w    int_out(a6),d2        Desktop VDI handle
  46.  
  47. * start by opening a virtual workstation
  48.     move.l #$00010001,d0
  49.     move.l d0,intin(a6)        most parameters are 1
  50.     move.l d0,intin+4(a6)
  51.     move.l d0,intin+8(a6)
  52.     move.l d0,intin+12(a6)
  53.     move.l d0,intin+16(a6)
  54.     move.w #2,intin+20(a6)        use the RC system
  55.     clr.w    contrl+2(a6)
  56.     move.w    #11,contrl+6(a6)
  57.     move.w    d2,contrl+12(a6)
  58.     vdi V_OPNVWK            open one
  59.     move.w contrl+12(a6),d0        the handle
  60.     move.w d0,ws_handle(a6)        save it
  61.  
  62. * set the mouse to an arrow
  63.     clr.w int_in(a6)        arrow please
  64.     clr.l addr_in(a6)
  65.     gem GRAF_MOUSE
  66.  
  67. * we want to open a window, so find the size of the workstation
  68.     clr.w int_in(a6)        the desktop handle
  69.     move.w #4,int_in+2(a6)        work area wanted
  70.     gem WIND_GET            get the size
  71.  
  72. * the type of the window
  73. wtype    equ %000000101111        title, close, full, move, size
  74.  
  75. * the size lies in int_out(1..4), so calculate the window size
  76.     move.w #1,int_in(a6)        work area wanted
  77.     move.w #wtype,int_in+2(a6)    full feature window
  78.     movem.w int_out+2(a6),d0-d3
  79.     movem.w d0-d3,int_in+4(a6)    the size
  80.     gem WIND_CALC
  81.  
  82. * now get its offsets
  83.     move.w int_out+2(a6),xstart(a6)
  84.     move.w int_out+4(a6),ystart(a6)
  85.     move.w int_out+6(a6),xwidth(a6)
  86.     move.w int_out+8(a6),ywidth(a6)
  87.  
  88. * and create the window
  89.     move.w #wtype,int_in(a6)    full feature
  90.     movem.w int_out+2(a6),d0-d3
  91.     movem.w d0-d3,int_in+2(a6)    the size
  92.     gem WIND_CREATE            create it
  93.     move.w d0,w_handle(a6)        save the handle
  94.  
  95. * now set its title
  96.     move.w d0,int_in(a6)
  97.     move.w #2,int_in+2(a6)        title string
  98.     lea windowname(pc),a0
  99.     move.l a0,int_in+4(a6)        the address
  100.     gem WIND_SET
  101.  
  102. * now actually show it by opening
  103.     move.w w_handle(a6),int_in(a6)
  104.     movem.w xstart(a6),d0-d3
  105.     add.w #10,d0            x start
  106.     add.w #10,d1            y start
  107.     sub.w #20,d2            width
  108.     sub.w #20,d3            height
  109.     movem.w d0-d3,int_in+2(a6)    the size
  110.     gem WIND_OPEN            open it
  111.     bsr recalcwindow
  112.     bsr setupmode
  113.  
  114. * the main loop of the application
  115. * the only interesting events are messages
  116. waitforevent
  117.     lea messagebuf(a6),a0
  118.     move.l a0,addr_in(a6)
  119.     gem EVNT_MESAG            get the message
  120.     lea messagebuf(a6),a0
  121.     move.w (a0),d0            message type
  122.     cmp.w #20,d0
  123.     beq updateit            if Redraw
  124.     cmp.w #22,d0
  125.     beq quit            if Close button
  126.     cmp.w #23,d0
  127.     beq fullit            if Full button
  128.     cmp.w #27,d0
  129.     beq sizeit            if re-size required
  130.     cmp.w #28,d0
  131.     beq moveit            if window moved
  132.  
  133. * nothing I'm interested in so try again
  134.     bra waitforevent
  135.  
  136. * move the window around the screen
  137. moveit    move.w 6(a0),d0
  138.     cmp.w w_handle(a6),d0
  139.     bne waitforevent        if not my window then don't
  140. changedwindow
  141.     move.w d0,int_in(a6)
  142.     move.w #5,int_in+2(a6)
  143.     move.w 8(a0),int_in+4(a6)    new x pos
  144.     move.w 10(a0),int_in+6(a6)    new y pos
  145.     move.w 12(a0),d0
  146.     cmp.w #40,d0
  147.     bcc.s widok
  148.     moveq #40,d0            cant be too narrow
  149. widok    move.w d0,int_in+8(a6)        width
  150.     move.w 14(a0),d0
  151.     cmp.w #50,d0
  152.     bcc.s hiteok
  153.     moveq #50,d0            cant be too thin either
  154. hiteok    move.w d0,int_in+10(a6)        height
  155.     gem WIND_SET            move it
  156.     movem.w xwidth(a6),d4-d5    old size
  157.     bsr recalcwindow
  158.     cmp.w xwidth(a6),d4
  159.     bcs waitforevent
  160.     cmp.w ywidth(a6),d5
  161.     bcs waitforevent
  162.     bne.s forceupdate
  163.     cmp.w xwidth(a6),d4
  164.     beq waitforevent        not if exactly the same
  165. * if the new size is smaller in both dimensions than the old size
  166. * then an update event will not be posted, so the re-draw will
  167. * have to be done manually
  168. forceupdate
  169.     bsr drawwindow            draw it
  170.     bra waitforevent        and carry on
  171.  
  172. * re-size the window
  173. sizeit    move.w 6(a0),d0
  174.     cmp.w w_handle(a6),d0
  175.     bne waitforevent        if not my window
  176.     bra.s changedwindow
  177.  
  178. * there's an update
  179. updateit
  180.     move.w 6(a0),d0
  181.     cmp.w w_handle(a6),d0
  182.     bne waitforevent        if not my window
  183. * there are two ways of doing updates:
  184. * (a) to support overlapping windows
  185. * this takes a lot of code, and is very slow and tricky
  186. * (b) to ignore the possibility of overlapping windows
  187. * this takes little code and is easy
  188. * Here method (b) is used! (method (a) is described in the
  189. * window chapter of the DR GEM manual, and used in EdST)
  190.  
  191. * start by clipping the rectangle
  192.     movem.w 8(a0),d0-d3        the rectangle
  193.     add.w d0,d2
  194.     add.w d1,d3
  195.     movem.w d0-d3,ptsin(a6)
  196.     move.w #2,contrl+2(a6)
  197.     move.w #1,contrl+6(a6)
  198.     move.w ws_handle(a6),contrl+12(a6)
  199.     st intin(a6)            clipping on
  200.     vdi VS_CLIP            clip it
  201.     bsr drawwindow            draw the window
  202.     bra waitforevent
  203.  
  204. * the full button has been clicked
  205. * this puts up an alert box
  206. fullit
  207.     move.w #1,int_in(a6)        default=1st button
  208.     lea myalert(pc),a0
  209.     move.l a0,addr_in(a6)        the alert definition
  210.     gem FORM_ALERT
  211.     bra waitforevent
  212.  
  213. * to go away various things have to be tidied up
  214. * starting with closing the window
  215. quit    move.w w_handle(a6),int_in(a6)
  216.     gem WIND_CLOSE            close it
  217.     gem WIND_DELETE            and delete it
  218. * then closing the virtual workstation
  219.     clr.w contrl+2(a6)
  220.     clr.w contrl+6(a6)
  221.     move.w ws_handle(a6),contrl+12(a6)
  222.     vdi V_CLSVWK            close it
  223.     gem APPL_EXIT            tell GEM I've finished
  224. * now quit to the desktop
  225.     clr.w -(a7)            status code
  226.     move.w #$4c,-(a7)        P_TERM
  227.     trap #1                and go away
  228.  
  229. * calculate the work area of the window
  230. recalcwindow
  231.     move.w w_handle(a6),int_in(a6)
  232.     move.w #4,int_in+2(a6)        work area required
  233.     gem WIND_GET
  234.     movem.w int_out+2(a6),d0-d3
  235.     movem.w d0-d3,xstart(a6)
  236.     rts
  237.  
  238. * this draws the picture in the window
  239. * which is an oval on top of a rectangle
  240.  
  241. * before drawing anywhere you have to hide the mouse
  242. drawwindow
  243.     clr.l contrl+2(a6)
  244.     move.w ws_handle(a6),contrl+12(a6)
  245.     vdi V_HIDE_C            hide the mouse
  246.     clr.w contrl+2(a6)
  247.     move.w #1,contrl+6(a6)
  248.     move.w #2,intin(a6)        pattern please
  249.     vdi VSF_INTERIOR
  250.     move.w #2,contrl+2(a6)
  251.     clr.w contrl+6(a6)
  252.     move.w ws_handle(a6),contrl+12(a6)
  253.     movem.w xstart(a6),d0-d3
  254.     add.w d0,d2
  255.     subq.w #1,d2
  256.     add.w d1,d3
  257.     subq.w #1,d3
  258.     movem.w d0-d3,ptsin(a6)        the rectangle
  259.     vdi VR_RECFL            filled rectangle
  260. * the oval has to be drawn in the user defined pattern
  261.     clr.w contrl+2(a6)
  262.     move.w #1,contrl+6(a6)
  263.     move.w #4,intin(a6)
  264.     vdi VSF_INTERIOR        set fill style
  265.     move.w #2,contrl+2(a6)
  266.     clr.w contrl+6(a6)
  267.     move.w #5,contrl+10(a6)
  268.     move.w ws_handle(a6),contrl+12(a6)
  269.     movem.w xstart(a6),d0-d3
  270.     asr.w #1,d2            half width
  271.     asr.w #1,d3            half height
  272.     add.w d2,d0            x centre
  273.     add.w d3,d1            y centre
  274.     movem.w d0-d3,ptsin(a6)
  275.     vdi V_GDP            GDP ellipse
  276. * we have finished drawing so get the mouse back
  277.     clr.w contrl+2(a6)
  278.     move.w #1,contrl+6(a6)
  279.     clr.w intin(a6)
  280.     vdi V_SHOW_C            show the mouse
  281.     rts
  282.  
  283. * this prepares the drawing mode etc
  284. setupmode
  285.     clr.w contrl+2(a6)
  286.     move.w #16,contrl+6(a6)
  287.     move.w ws_handle(a6),contrl+12(a6)
  288.     move.w #%0000100101000000,intin(a6)
  289.     move.w #%0000100101000000,intin+2(a6)
  290.     move.w #%0000111101000000,intin+4(a6)
  291.     move.w #%0000100101000000,intin+6(a6)
  292.     move.w #%0000100101000000,intin+8(a6)
  293.     move.w #%0000000000000000,intin+10(a6)
  294.     move.w #%0110010011011100,intin+12(a6)
  295.     move.w #%1000101010001000,intin+14(a6)
  296.     move.w #%1100101011001000,intin+16(a6)
  297.     move.w #%0010101010001000,intin+18(a6)
  298.     move.w #%1100010010001000,intin+20(a6)
  299.     clr.l intin+22(a6)
  300.     clr.l intin+26(a6)
  301.     clr.w intin+30(a6)
  302.     vdi VSF_UDPAT            set user defined fill style
  303.     clr.w contrl+2(a6)
  304.     move.w #1,contrl+6(a6)
  305.     move.w #1,intin(a6)
  306.     vdi VSF_COLOR            use colour/color 1
  307.     rts
  308.  
  309. * all C strings must end in a null
  310. windowname dc.b ' An Example GEM Program by HiSoft ',0
  311.  
  312. myalert dc.b "[1][This is written in 68000|assembler using HiSoft's|"
  313.     dc.b 'DevpacST development system][ OK ]',0
  314.  
  315. * global constants, referenced off A6
  316.  
  317. * these have to remain together
  318. xstart    rs.w 1
  319. ystart    rs.w 1
  320. xwidth    rs.w 1
  321. ywidth    rs.w 1
  322.  
  323. w_handle    rs.w 1
  324. ws_handle    rs.w 1
  325. ap_id        rs.w 1
  326. messagebuf    rs.b 16
  327.  
  328.     rs.l    100            stack space
  329. mystack    rs.w    1            (stacks go backwards)
  330.  
  331. datalength    rs.w 0            this is the total required
  332.  
  333. * data lies in the BSS section
  334.     section    BSS
  335.  
  336.     ds.b    datalength
  337.  
  338.