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

  1.  
  2. * a sample GEM program supplied with DevpacST version 2
  3. * Menu test program using the AES, VDI not required
  4.  
  5. * last changed:19.4.88
  6.  
  7.     opt x+                dump long labels for debugging
  8.  
  9.     include    gemmacro.s
  10.  
  11. MN_SELECTED    equ    10
  12.  
  13. * the program proper
  14. start    move.l    4(a7),a3        base page
  15.     move.l    #mystack,a7
  16.     move.l    $c(a3),d0        text len
  17.     add.l    $14(a3),d0        data len
  18.     add.l    $1c(a3),d0        BSS len
  19.     add.l    #$100,d0        basepage
  20.     move.l    d0,-(sp)
  21.     move.l    a3,-(sp)
  22.     clr.w    -(sp)
  23.     move.w    #$4a,-(sp)
  24.     trap    #1            shrink memory
  25.     lea    12(sp),sp
  26.  
  27.     appl_init
  28.     move.w    d0,ap_id        store the application id
  29.  
  30. * set the mouse to an arrow
  31.     graf_mouse    #0        arrow please
  32.  
  33.     bsr    load_resources
  34.  
  35.     menu_bar    #menu_start,#1    display it
  36.  
  37.     clr.w    check_state
  38.  
  39. * the main loop of the application
  40. * the only interesting events are messages
  41. waitforevent
  42.     evnt_mesag    #messagebuf
  43.     move.l    #messagebuf,a0
  44.     move.w    (a0),d0            message type
  45.     cmp.w    #MN_SELECTED,d0
  46.     beq    handle_menu
  47.  
  48. * nothing I'm interested in so try again
  49.     bra    waitforevent
  50.  
  51.  
  52. * to go away various things have to be tidied up
  53. quit    
  54.     menu_bar    #menu_start,#0
  55.     appl_exit            tell GEM I've finished
  56.  
  57. * now quit to the desktop
  58.     clr.w    -(a7)            status code
  59.     move.w    #$4c,-(a7)        P_TERM
  60.     trap    #1            and go away
  61.  
  62. * menu handling after one has been clicked on
  63. handle_menu
  64.     move.w    messagebuf+8,d4        menu item
  65.     bsr.s    do_menu            act on it
  66. * now unlight the menu title
  67.     menu_tnormal    #menu_start,messagebuf+6,#1
  68.     bra    waitforevent        and try again
  69.  
  70. * given a menu click (d4) work out what it is and act on it
  71. do_menu    cmp.w    #m_about,d4
  72.     beq.s    do_about
  73.     cmp.w    #m_hello,d4
  74.     beq.s    do_hello
  75.     cmp.w    #m_quit,d4
  76.     beq    quit
  77.     cmp.w    #m_check,d4
  78.     beq.s    do_check
  79.     cmp.w    #m_dialog,d4
  80.     beq.s    do_dialog
  81.     rts
  82.  
  83. do_about
  84.     form_alert    #1,#about_alert
  85.     rts
  86. do_hello
  87.     form_alert    #1,#hello_alert
  88.     rts
  89. do_check
  90.     eor.w    #1,check_state
  91.     menu_icheck    #menu_start,#m_check,check_state
  92.     rts
  93. do_dialog
  94.     form_center    #my_dialog
  95.     movem.w    int_out+2,d3-d6            d3-d6 are dialog co-ords
  96.     form_dial    #0,d3,d4,d5,d6,d3,d4,d5,d6
  97.     objc_draw    #my_dialog,#0,#2,d3,d4,d5,d6
  98.     form_do        #my_dialog,#0
  99.     mulu    #ob_sizeof,d0
  100.     move.l    #my_dialog,a0
  101.     bclr    #0,ob_state+1(a0,d0.w)        un-select button
  102.     form_dial    #3,d3,d4,d5,d6,d3,d4,d5,d6
  103.     rts
  104.  
  105. *************************
  106. *    RESOURCES    *
  107. *************************
  108. * done the hard way......
  109.  
  110. ob_flags    equ    8
  111. ob_state    equ    10
  112. ob_sizeof    equ    24
  113.  
  114. G_BOX        equ    20
  115. G_STRING    equ    28
  116. G_BUTTON    equ    26
  117.  
  118. NONE        equ    0
  119. SELECTABLE    equ    1
  120. DEFAULT        equ    2
  121. EXIT        equ    4
  122. LASTOB        equ    $20
  123.  
  124. NORMAL        equ    0
  125. OUTLINED    equ    $10
  126.  
  127.  
  128. nextobj    set    1
  129. object    macro    next,head,tail,type,flags,state
  130.     dc.w    \1,\2,\3
  131.     dc.w    G_\4,\5,\6
  132. nextobj    set    nextobj+1
  133.     endm
  134.  
  135. * doesn't actually load a resource file as we don't have one, but
  136. * instead converts the built-in resources co-ordinates
  137. load_resources
  138.     lea    menu_start(pc),a3
  139.     bsr.s    convert_resource
  140.     lea    my_dialog(pc),a3
  141.     bsr.s    convert_resource
  142.     rts
  143.  
  144. * given an object tree at a3, fixup its co-ordinates
  145. convert_resource
  146.     moveq    #0,d3
  147.     move.l    a3,a0
  148. .loop    move.l    a0,-(sp)
  149.     rsrc_obfix    a3,d3
  150.     move.l    (sp)+,a0
  151.     btst    #5,ob_flags+1(a0)
  152.     bne.s    .done
  153.     addq.w    #1,d3
  154.     add.w    #ob_sizeof,a0
  155.     bra.s    .loop            until LASTOB
  156. .done    rts
  157.  
  158. * once a menu is stabilised it is best to Insert the file
  159. menu_start
  160.     include    menutest.mnu
  161.  
  162.     even
  163. nextobj    set    1
  164. my_dialog
  165.     object    0,nextobj,nextobj+1,BOX,NONE,NORMAL
  166.     dc.l    2<<16+$1181
  167.     dc.w    0,0,35,10
  168.         object    nextobj,-1,-1,STRING,NONE,OUTLINED
  169.         dc.l    titletx
  170.         dc.w    5,2,25,2
  171.         object    0,-1,-1,BUTTON,SELECTABLE!DEFAULT!EXIT!LASTOB,NORMAL
  172.         dc.l    buttontx
  173.         dc.w    12,7,12,2
  174.  
  175.  
  176. * menu numbers are best calculated using the RS directive
  177.     rsset    4
  178. * titles first
  179.     rs.b    1        File title
  180.     rs.b    1        Test title
  181. *                other titles
  182.     rs.b    2
  183. * now the items
  184. m_about    rs.b    1            About item
  185.     rs.b    6+1            other items under Desk
  186.         rs.b    1    skip File title
  187. m_hello    rs.b    1
  188. m_quit    rs.b    1
  189.         rs.b    1    skip Test item
  190. m_check    rs.b    1
  191.     rs.b    1
  192. m_dialog rs.b    1
  193.  
  194.  
  195.     SECTION    DATA
  196. about_alert    dc.b    '[1][A test program written|'
  197.         dc.b    'with DevpacST Version 2][ Great ]',0
  198. hello_alert    dc.b    '[3][  ][ Hello! ]',0
  199. titletx        dc.b    ' A Hand-Made Dialog Box!',0
  200. buttontx    dc.b    'Click me',0
  201.  
  202.     SECTION    BSS
  203. * global variables
  204.  
  205. ws_handle    ds.w    1
  206.  
  207. ap_id        ds.w    1
  208. messagebuf    ds.b    16
  209. check_state    ds.w    1
  210.  
  211.     ds.l    100            stack space
  212. mystack    ds.w    1            (stacks go backwards)
  213.  
  214.  
  215. * if not linking then include the run-times
  216.  
  217.     IFEQ    __LK
  218.     include    aeslib.s
  219. * VDI not needed!!
  220.     ENDC
  221.