home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / STFORMAT / STF48.MSA / ASSEMBLY / MENU.S < prev   
Text File  |  1993-04-26  |  8KB  |  391 lines

  1. *If you are running Devpac2, you may need to rename gemmacro.i
  2. *to gemmacro.s, or alter the include  gemmacro.i directive below
  3. *The IFD __G2 directive will assemble everything following it
  4. *until an ELSE or ENDC if you are using Devpac, otherwise
  5. *everything between ELSE and ENDC is assembled 
  6. *make sure your compiler knows where to find the include files
  7. *if in doubt, put everything in the root of A:\, and run
  8. *your compiler from the root of A:\
  9.  
  10. _sysbase    equ    $4f2
  11. type_string    equ    5
  12. R_TREE equ 0
  13. stacksize equ 1000
  14.  
  15.     opt    XDEBUG
  16.  
  17.     
  18.  
  19.     include    gmdosmac.i
  20.     include    xbiosmac.i
  21.     include    menu.i
  22.  
  23.     IFD    __G2    *this tells us if we are running Devpac
  24.     include    gemmacro.i
  25.     ENDC
  26.  
  27.     move.l    4(a7),a3
  28.     move.l    #ourstack+(stacksize*2),a7    
  29.     bsr    initialise_program    
  30. *We need to find which version of TOS we have for the file selector
  31.     Supexec    #which_tos    
  32.     IFD    __G2
  33.     appl_init
  34.     ELSE
  35.     move.w    #10,control    appl_init
  36.     move.w    #0,control+2
  37.     move.w    #1,control+4
  38.     move.w    #0,control+6
  39.     move.w    #0,control+8
  40.     bsr    call_aes
  41.     ENDC
  42.     move.w    d0,ap_id        
  43.     IFD    __G2
  44.     rsrc_load    #rsc_file
  45.     ELSE
  46.     move.w    #110,control    rsrc_load
  47.     move.w    #0,control+2
  48.     move.w    #1,control+4
  49.     move.w    #1,control+6
  50.     move.w    #0,control+8
  51.     move.l    #rsc_file,addr_in
  52.     bsr    call_aes
  53.     ENDC
  54.     beq    cant_find_it
  55.     IFD    __G2
  56.     graf_mouse    #0    
  57.     ELSE
  58.     move.w    #78,control    graf_mouse
  59.     move.w    #1,control+2
  60.     move.w    #1,control+4
  61.     move.w    #1,control+6
  62.     clr.w    control+8
  63.     move.w    #0,int_in
  64.     bsr    call_aes
  65.     ENDC
  66.     IFD    __G2
  67.     rsrc_gaddr    #R_TREE,#menu1
  68.     ELSE
  69.     move.w    #R_TREE,int_in
  70.     move.w    #menu1,int_in+2
  71.     move.w    #112,control    rsrc_gaddr
  72.     move.w    #2,control+2
  73.     move.w    #1,control+4
  74.     move.w    #0,control+6
  75.     move.w    #1,control+8
  76.     bsr    call_aes
  77.     ENDC
  78.     move.l    addr_out,menu_tree
  79.     IFD    __G2
  80.     menu_bar    menu_tree,#1
  81.     ELSE
  82.     move.l    menu_tree,addr_in
  83.     move.w    #1,int_in
  84.     move.w    #30,control    menu_bar
  85.     move.w    #1,control+2
  86.     move.w    #1,control+4
  87.     move.w    #1,control+6
  88.     move.w    #0,control+8
  89.     bsr    call_aes
  90.     ENDC
  91.     bset    #0,enable+1    this instruction sets bit #0 of address
  92.                 *enable+1. We will cange this bit
  93.                 *whenever the file selector menu is
  94.                 *enabled/disabled
  95.  
  96. main_loop
  97. MU_KEYBD equ %1
  98. MU_MESAG equ %10000    binary for decimal 16
  99.     IFD    __G2
  100.     evnt_multi    #%10001,,,,,,,,,,,,,,#message_buffer
  101.  
  102.     ELSE
  103.  
  104.     move.w    #25,control    evnt_multi
  105.     move.w    #%10001,int_in
  106.     move.l    #message_buffer,addr_in
  107.     move.w    #16,control+2
  108.     move.w    #7,control+4
  109.     move.w    #1,control+6
  110.     clr.w    control+8
  111.     bsr    call_aes
  112.     ENDC
  113.     cmp.w    #MU_KEYBD,d0
  114.     bne    try_menu
  115. alt_q equ $1000    this is the key code for <Alternate> <q>
  116.     move.w    int_out+10,d0    this is the keycode for the key pressed
  117.     cmp.w    #alt_q,d0    was it alternate q?
  118. *if you want to check the keycodes for other keys, set a breakpoint
  119. *here in your debugger, run the program, and the value in d0 
  120. *is the hex key code for the key you pressed
  121.     bne    main_loop    no - next message
  122.     bra    finished    yes - quit
  123. try_menu
  124.     lea    message_buffer,a0
  125.     move.w    (a0),d0
  126. MN_SELECTED    equ    10
  127.     cmp.w    #MN_SELECTED,d0
  128.     beq    handle_menu
  129.  
  130.     bra    main_loop
  131.  
  132. handle_menu
  133.     move.w    8(a0),d1
  134.     move.w    6(a0),d2
  135.     cmp.w    #mymessage,d1
  136.     bne    .notmymessage
  137.     IFD    __G2
  138.     form_alert    #1,#about_dialog
  139.     ELSE
  140.     move.l    #about_dialog,addr_in
  141.     move.w    #1,int_in
  142.     move.w    #52,control    form_alert
  143.     move.w    #1,control+2
  144.     move.w    #1,control+4
  145.     move.w    #1,control+6
  146.     move.w    #0,control+8
  147.     bsr    call_aes
  148.     ENDC
  149.     bra    .back_to_loop
  150.     
  151. .notmymessage
  152.     cmp.w    #quit,d1
  153.     bne    .notquit
  154.     bra    finished
  155. .notquit
  156.     cmp.w    #select,d1
  157.     bne    .notselect
  158.     Dgetdrv        fetch current drive
  159.     add.w    #'A',d0        0=drive A, 1=B etc
  160.     move.b    d0,path
  161.     move.b    #':',path+1
  162.     Dgetpath    #0,#file
  163.     move.l    #path+2,a3
  164.     move.l    #file,a4
  165. .move_char
  166.     move.b    (a4)+,(a3)+
  167.     bne    .move_char
  168.     move.b    #'\',-1(a3)
  169.     move.b    #'*',(a3)+
  170.     move.b    #'.',(a3)+
  171.     move.b    #'*',(a3)+
  172.     move.b    #0,(a3)+
  173.     move.w    #0,file
  174.     cmp.w    #$0104,tos    TOS 1.4 or greater?
  175.     bge    .tos104
  176.     IFD    __G2
  177.     fsel_input    #path,#file
  178.     ELSE
  179.     move.l    #path,addr_in
  180.     move.l    #file,addr_in+4
  181.     move.w    #90,control    fsel_input
  182.     move.w    #0,control+2
  183.     move.w    #2,control+4
  184.     move.w    #2,control+6
  185.     move.w    #0,control+8
  186.     bsr    call_aes
  187.     ENDC
  188.     bra    .not104
  189. .tos104
  190.     IFD    __G2
  191.     fsel_exinput    #path,#file,#label
  192.     ELSE
  193.     move.l    #path,addr_in
  194.     move.l    #file,addr_in+4
  195.     move.l    #label,addr_in+8
  196.     move.w    #91,control    fsel_exinput
  197.     move.w    #0,control+2
  198.     move.w    #2,control+4
  199.     move.w    #3,control+6
  200.     move.w    #0,control+8
  201.     bsr    call_aes
  202.     ENDC
  203. .not104
  204. *after the fsel_ call, path and file will be updated
  205.     move.w    int_out+2,button 
  206. *button now contains 0 if user selects Cancel, 1 for OK or Return
  207.     bra    .back_to_loop
  208. .notselect
  209.     cmp.w    #checkmark,d1
  210.     bne    .notcheck
  211.     bchg    #0,check+1    an easy way to remember if the check
  212.                 *is on or off
  213.     IFD    __G2
  214.     menu_icheck    menu_tree,#checkmark,check
  215.     ELSE
  216.     move.l    menu_tree,addr_in
  217.     move.w    #checkmark,int_in
  218.     move.w    check,int_in+2
  219.     move.w    #31,control    menu_icheck
  220.     move.w    #2,control+2
  221.     move.w    #1,control+4
  222.     move.w    #1,control+6
  223.     move.w    #0,control+8
  224.     bsr    call_aes
  225.     ENDC
  226.     bra    .back_to_loop
  227. .notcheck
  228.     cmp.w    #onoff,d1
  229.     bne    .notonoff
  230.     bchg    #0,enable+1
  231.     move.l    #toggle_string,a3
  232.     move.w    enable,d1
  233.     asl.w    #2,d1    
  234.     move.l    0(a3,d1.w),a3    
  235.     IFD    __G2
  236.     menu_ienable    menu_tree,#select,enable
  237.     menu_text    menu_tree,#onoff,a3
  238.     ELSE
  239.     move.l    menu_tree,addr_in
  240.     move.w    #select,int_in
  241.     move.w    enable,int_in+2
  242.     move.w    #32,control    menu_ienable
  243.     move.w    #2,control+2
  244.     move.w    #1,control+4
  245.     move.w    #1,control+6
  246.     move.w    #0,control+8
  247.     bsr    call_aes
  248.  
  249.     move.w    #onoff,int_in
  250.     move.l    menu_tree,addr_in
  251.     move.l    a3,addr_in+4
  252.     move.w    #34,control    menu_text
  253.     move.w    #1,control+2
  254.     move.w    #1,control+4
  255.     move.w    #2,control+6
  256.     move.w    #0,control+8
  257.     bsr    call_aes
  258.     ENDC
  259.     bra    .back_to_loop
  260.     
  261. .notonoff
  262. .back_to_loop    
  263.     IFD    __G2
  264.     menu_tnormal    menu_tree,d2,#1
  265.     ELSE
  266.     move.l    menu_tree,addr_in
  267.     move.w    d2,int_in
  268.     move.w    #1,int_in+2
  269.     move.w    #33,control    menu_tnormal
  270.     move.w    #2,control+2
  271.     move.w    #1,control+4
  272.     move.w    #1,control+6
  273.     move.w    #0,control+8
  274.     bsr    call_aes
  275.     ENDC
  276.     bra    main_loop
  277.     
  278.     
  279. cant_find_it
  280.     IFD    __G2
  281.     form_alert    #1,#rsc_load_error
  282.     ELSE
  283.     move.l    #rsc_load_error,addr_in
  284.     move.w    #1,int_in
  285.     move.w    #52,control    form_alert
  286.     move.w    #1,control+2
  287.     move.w    #1,control+4
  288.     move.w    #1,control+6
  289.     move.w    #0,control+8
  290.     bsr    call_aes
  291.     ENDC
  292.     bra    stop
  293.  
  294. initialise_program    
  295.     move.l    $c(a3),d0    *length of text
  296.     add.l    $14(a3),d0    *length of data
  297.     add.l    $1c(a3),d0    *length of BSS
  298.     add.l    #$100,d0    *length of basepage
  299.     Mshrink    d0,a3        *Macro to return unwanted memory
  300.     rts
  301.  
  302. which_tos
  303.     move.l    _sysbase,a0
  304.     move.w    2(a0),tos    this stores our version of TOS
  305.     rts
  306.  
  307. finished
  308.     IFD    __G2
  309.     menu_bar    menu_tree,#0
  310.     rsrc_free
  311.     ELSE
  312.     move.l    menu_tree,addr_in
  313.     move.w    #0,int_in
  314.     move.w    #30,control    menu_bar
  315.     move.w    #1,control+2
  316.     move.w    #1,control+4
  317.     move.w    #1,control+6
  318.     move.w    #0,control+8
  319.     bsr    call_aes
  320.  
  321.     move.w    #111,control    rsrc_free
  322.     move.w    #0,control+2
  323.     move.w    #1,control+4
  324.     move.w    #0,control+6
  325.     move.w    #0,control+8
  326.     bsr    call_aes
  327.     ENDC
  328. stop    
  329.     IFD    __G2
  330.     appl_exit    tell the AES we're finished
  331.     ELSE
  332.     move.w    #19,control    appl_exit
  333.     move.w    #0,control+2
  334.     move.w    #1,control+4
  335.     move.w    #0,control+6
  336.     move.w    #0,control+8
  337.     bsr    call_aes
  338.     ENDC
  339.     Pterm    #0    and quit
  340.         
  341.     IFND    __G2
  342. call_aes
  343.     move.l    #aes_params,d1
  344.     move.w    #$C8,d0
  345.     trap    #2
  346.     move.w    int_out,d0
  347.     rts
  348.  
  349.     DATA
  350. aes_params    dc.l    control,global,int_in,int_out,addr_in,addr_out
  351.     ENDC
  352.     DATA
  353.  
  354. rsc_file    dc.b    'MENU.RSC',0
  355. rsc_load_error    dc.b    '[3][Could not find Resource file][Bye]',0
  356. about_dialog    dc.b    '[3][St Formats Example Menu][OK]',0
  357. label        dc.b    'Select a File',0
  358. menu_string1    dc.b    ' Enable Select ',0    
  359. menu_string2    dc.b    ' Disable Select ',0
  360. **********
  361. *keep these two together
  362. toggle_string    dc.l    menu_string1
  363.         dc.l    menu_string2
  364. **********
  365.     BSS
  366. menu_tree    ds.l    1
  367. ap_id        ds.w    1
  368. message_buffer    ds.b    16
  369. savessp        ds.l    1
  370. tos        ds.w    1
  371. check        ds.w    1
  372. enable        ds.w    1
  373. path        ds.b    128
  374. file        ds.b    128
  375. button        ds.b    1
  376. ourstack    ds.w    stacksize
  377.     IFD    __G2
  378.     include    aeslib.s
  379.     ELSE
  380.     
  381. *the AES parameters
  382. control        ds.w    5
  383. global        ds.w    14
  384. int_in        ds.w    16
  385. int_out        ds.w    7
  386. addr_in        ds.l    3
  387. addr_out    ds.l    1
  388.  
  389.     ENDC
  390.  
  391.