home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0600 / CCE_0628.ZIP / CCE_0628.PD / ALW2 / CHAP3 / PROG3MAC.S < prev   
Text File  |  1993-09-07  |  15KB  |  459 lines

  1. ;---------------------------------------------------------------------
  2. ; THE ST ASSEMBLY LANGUAGE WORKSHOP, VOLUME 2
  3. ; PROGRAM 3
  4. ;
  5. ; COPYRIGHT 1992 BY CLAYTON WALNUM
  6. ;---------------------------------------------------------------------
  7.  
  8. .include "MENU.H"
  9.  
  10. R_TREE          equ     0
  11. ARROW           equ     0
  12. NORMAL          equ     1
  13. MN_SELECTED     equ     10
  14. NUM_MENUS       equ     11
  15.  
  16. PTERM0          equ     0
  17. APPL_INIT       equ     10
  18. APPL_EXIT       equ     19
  19. EVNT_MESAG      equ     23
  20. MENU_BAR        equ     30
  21. MENU_ICHECK     equ     31
  22. MENU_IENABLE    equ     32
  23. MENU_TNORMAL    equ     33
  24. MENU_TEXT       equ     34
  25. FORM_ALERT      equ     52
  26. MSHRINK         equ     74
  27. GRAF_MOUSE      equ     78
  28. RSRC_LOAD       equ     110
  29. RSRC_FREE       equ     111
  30. RSRC_GADDR      equ     112
  31. AES_OPCODE      equ     200
  32.  
  33. ;--------------------------------------------------------------------
  34. ; MACROS
  35. ;--------------------------------------------------------------------
  36.  
  37. ;--------------------------------------------------------------------
  38. ; This macro calls up a simple, one-button GEM alert box, using the
  39. ; form_alert AES function. It requires two parameters: the default
  40. ; button number and the address of the alert-box string. Because this
  41. ; alert box will have only one button, the value for the default
  42. ; button must be 0 for no default or 1 for button 1.
  43. ;-------------------------------------------------------------------- 
  44. .macro alert
  45.         move    #FORM_ALERT,control0
  46.         move    #1,control1
  47.         move    #1,control2
  48.         move    #1,control3
  49.         clr     control4
  50.         move    #\1,int_in0
  51.         move.l  #\2,addr_in0
  52.         bsr     aes
  53. .endm
  54.  
  55. ;--------------------------------------------------------------------
  56. ; MAIN PROGRAM
  57. ;--------------------------------------------------------------------
  58.         text
  59.  
  60. ; Calculate the size of the program area.
  61.  
  62.         move.l  a7,a5                   ; Save addr of TPA.
  63.         lea     stack,sp                ; Load addr of our stack.
  64.         
  65.         move.l  4(a5),a5                ; Get addr of TPA.              
  66.         move.l  12(a5),d0               ; Get len of text segment.
  67.         add.l   20(a5),d0               ; Add len of data segment.
  68.         add.l   28(a5),d0               ; Add len of BSS segment.
  69.         add.l   #$100,d0                ; Add len of TPA. 
  70.  
  71. ; Release unused memory back to the system.
  72.         
  73.         move.l  d0,-(sp)                ; Push size of program on stack.
  74.         move.l  a5,-(sp)                ; Push program addr on stack.
  75.         clr     -(sp)                   ; Clear dummy word on stack.    
  76.         move    #MSHRINK,-(sp)          ; Push Mshrink opcode.
  77.         trap    #1                      ; Call GEMDOS.
  78.         add.l   #12,sp                  ; Reset stack pointer.
  79.  
  80. ; Clear some fields of the global array.
  81.  
  82.         clr.l   ap_ptree        
  83.         clr.l   ap_1resv
  84.         clr.l   ap_2resv
  85.         clr.l   ap_3resv
  86.         clr.l   ap_4resv
  87.  
  88. ; Call appl_init to initialize application.
  89.  
  90.         move    #APPL_INIT,control0     ; Place opcode in control array.
  91.         clr     control1                ; Load length of init_in. 
  92.         move    #1,control2             ; Load length of int_out.
  93.         clr     control3                ; Load length of addr_in.
  94.         clr     control4                ; Load length of addr_out.
  95.         bsr     aes                     ; Call the AES.
  96.         cmpi    #$FFFF,ap_id            ; Error?
  97.         beq     end                     ; Yep.  Outta here.
  98.  
  99. ; Change mouse pointer back to arrow.
  100.  
  101.         move    #GRAF_MOUSE,control0
  102.         move    #1,control1
  103.         move    #1,control2
  104.         move    #1,control3
  105.         clr     control4
  106.         move    #ARROW,int_in0          ; Mouse form number.
  107.         clr.l   addr_in0                ; Use 0 for address of form.
  108.         bsr     aes     
  109.  
  110. ; Load resource file.
  111.  
  112.         move    #RSRC_LOAD,control0
  113.         clr     control1
  114.         move    #1,control2
  115.         move    #1,control3
  116.         clr     control4
  117.         move.l  #rsrc_file,addr_in0     ; Addr of resource file name.
  118.         bsr     aes
  119.         tst     int_out0                ; Did the resource load okay?
  120.         bne     rsrc_okay               ; Yep.
  121.         alert   1,alert5                ; "Resource load error!"
  122.         bra     exit
  123.  
  124. ; Get resource address.
  125.         
  126. rsrc_okay:
  127.         move    #RSRC_GADDR,control0
  128.         move    #2,control1
  129.         move    #1,control2
  130.         clr     control3
  131.         move    #1,control4
  132.         move    #R_TREE,int_in0         ; Type number of data.
  133.         move    #TREE00,int_in1         ; Array index of data.
  134.         bsr     aes
  135.         tst     int_out0                ; Was there an error?
  136.         bne     addr_okay               ; Nope.
  137.         alert   1,alert6                ; "Resource address error!"
  138.         bra     exit
  139.  
  140. ; Show menu bar.
  141.  
  142. addr_okay:
  143.         move.l  addr_out,menu_adr       ; Save addr of menu resource.
  144.         move    #MENU_BAR,control0
  145.         move    #1,control1
  146.         move    #1,control2
  147.         move    #1,control3
  148.         clr     control4
  149.         move    #1,int_in0              ; Set flag to show menu.
  150.         move.l  menu_adr,addr_in0       ; Address of menu resource.
  151.         bsr     aes
  152.  
  153. ; Event loop.
  154.  
  155. event_loop:
  156.         move    #EVNT_MESAG,control0
  157.         clr     control1
  158.         move    #1,control2
  159.         move    #1,control3
  160.         clr     control4
  161.         move.l  #msgbuf,addr_in0        ; Address of message buffer.
  162.         bsr     aes
  163.  
  164. ; Decipher message.
  165.  
  166.         cmpi    #MN_SELECTED,msgbuf0
  167.         bne     event_loop
  168.         move    #NUM_MENUS-1,d5         ; Init loop counter.
  169.         move    d5,d6                   ; Init the...
  170.         add     d6,d6                   ; index register.
  171.         lea     menu_ids,a5             ; Get addr of ID table.
  172.         move    msgbuf4,d4              ; Get menu ID.
  173. find_id:
  174.         cmp     0(a5,d6),d4             ; Is this the ID?
  175.         beq     found_id                ; Yep.
  176.         subi    #2,d6                   ; No, so calculate new index...
  177.         dbra    d5,find_id              ; and loop back for another try.
  178.         bra     event_loop              ; ID not in table. Whoops!
  179.  
  180. found_id:
  181.         lea     menu_vecs,a5            ; Get addr of vector table.
  182.         add     d6,d6                   ; Calculate index.
  183.         move.l  0(a5,d6),a6             ; Get vector.
  184.         jmp     (a6)                    ; Jump to proper routine.
  185.  
  186. ; Respond to menu item chosen.
  187.         
  188. info:
  189.         alert   1,alert1
  190.         bsr     menu_normal
  191.         bra     event_loop
  192.  
  193. load:
  194.         alert   1,alert2
  195.         bsr     menu_normal
  196.         bra     event_loop
  197.  
  198. save:
  199.         alert   1,alert3
  200.         bsr     menu_normal
  201.         bra     event_loop
  202.  
  203. option1:
  204.         tst     optn1                   ; Is Option1 checked?
  205.         beq     setcheck1               ; No. Go add checkmark.
  206.         clr     optn1                   ; Yes. Clear checkmark.
  207.         clr     check_flag
  208.         bra     check
  209. setcheck1:
  210.         move    #1,optn1                ; Set option1 checkmark.
  211.         move    #1,check_flag
  212.         bra     check
  213.  
  214. option2:
  215.         tst     optn2                   ; Is option2 checked?
  216.         beq     setcheck2               ; No. Go add checkmark.
  217.         clr     optn2                   ; Yes. Clear checkmark.
  218.         clr     check_flag
  219.         bra     check
  220. setcheck2:
  221.         move    #1,optn2                ; Set option2 checkmark
  222.         move    #1,check_flag
  223.         bra     check
  224.         
  225. option3:
  226.         tst     optn3                   ; Is option3 checked?
  227.         beq     setcheck3               ; No. Go add checkmark.
  228.         clr     optn3                   ; Yes. Clear checkmark.
  229.         clr     check_flag
  230.         bra     check
  231. setcheck3:
  232.         move    #1,optn3                ; Set option3 checkmark.
  233.         move    #1,check_flag
  234.  
  235. check:
  236.         move    #MENU_ICHECK,control0
  237.         move    #2,control1
  238.         move    #1,control2
  239.         move    #1,control3
  240.         clr     control4
  241.         move    msgbuf4,int_in0         ; Menu item number.
  242.         move    check_flag,int_in1      ; Checkmark flag.
  243.         move.l  menu_adr,addr_in0       ; Address of resource tree.
  244.         bsr     aes
  245.         bsr     menu_normal
  246.         bra     event_loop
  247.  
  248. onoff:
  249.         tst     on                      ; Are selections on?
  250.         beq     turn_on                 ; No, so turn them on.
  251.         lea     on_str,a5               ; Yes. Get address of "On."
  252.         clr     on                      ; Clear flag.
  253.         bra     enable0
  254. turn_on:
  255.         lea     off_str,a5              ; Get address of "Off."
  256.         move    #1,on                   ; Set flag.
  257.  
  258. enable0:
  259.         move    #2,d5                   ; Init loop counter.
  260.         move    #SELECT1,d6             ; Get menu item number.
  261. enable1:
  262.         move    #MENU_IENABLE,control0
  263.         move    #2,control1
  264.         move    #1,control2
  265.         move    #1,control3
  266.         clr     control4
  267.         move    d6,int_in0              ; Menu item number.
  268.         move    on,int_in1              ; On/Off flag.
  269.         move.l  menu_adr,addr_in0       ; Address of resource tree.
  270.         bsr     aes
  271.         addi    #1,d6                   ; Next menu item number.
  272.         dbra    d5,enable1
  273.  
  274. ; Change text in menu.
  275.  
  276.         move    #MENU_TEXT,control0
  277.         move    #1,control1
  278.         move    #1,control2
  279.         move    #2,control3
  280.         clr     control4
  281.         move    #ONOFF,int_in0          ; Menu item number.
  282.         move.l  menu_adr,addr_in0       ; Address of resource tree.
  283.         move.l  a5,addr_in1             ; Address of new menu string.
  284.         bsr     aes
  285.         bsr     menu_normal
  286.         bra     event_loop
  287.  
  288. select1:
  289.         move.b  #'1',alert4+30          ; Add '1' to alert string.
  290.         alert   1,alert4
  291.         bsr     menu_normal
  292.         bra     event_loop
  293.  
  294. select2:
  295.         move.b  #'2',alert4+30          ; Add '2' to alert string.
  296.         alert   1,alert4
  297.         bsr     menu_normal
  298.         bra     event_loop
  299.  
  300. select3:
  301.         move.b  #'3',alert4+30          ; Add '3' to alert string.
  302.         alert   1,alert4
  303.         bsr     menu_normal
  304.         bra     event_loop
  305.  
  306. ; Remove menu bar.
  307.  
  308. quit:
  309.         move    #MENU_BAR,control0
  310.         move    #1,control1
  311.         move    #1,control2
  312.         move    #1,control3
  313.         clr     control4
  314.         clr     int_in0                 ; Menu display flag.
  315.         move.l  menu_adr,addr_in0       ; Address of resource tree.
  316.         bsr     aes
  317.         
  318. ; Release resource space.
  319.  
  320.         move    #RSRC_FREE,control0
  321.         clr     control1
  322.         move    #1,control2
  323.         clr     control3
  324.         clr     control4
  325.         bsr     aes
  326.         
  327. ; Close down application.
  328.  
  329. exit:
  330.         move    #APPL_EXIT,control0
  331.         move    #0,control1
  332.         move    #1,control2
  333.         move    #0,control3
  334.         move    #0,control4
  335.         bsr     aes
  336.         
  337. end:
  338.         move.w  #PTERM0,-(sp)           ; Back to desktop.
  339.         trap    #1
  340.  
  341. ;--------------------------------------------------------------------
  342. ; This subroutine calls the AES.  Before calling this subroutine, the
  343. ; program must have correctly initialized the AES control, int_in,
  344. ; and addr_in arrays.
  345. ;
  346. ; Input:        Appropriate values in the int_in, addr_in, and
  347. ;               control arrays.
  348. ; Output:       Appropriate values in the int_out, addr_out, and
  349. ;               global arrays.
  350. ; Regs changed: NONE
  351. ; Uses: apb, global, int_in, int_out, addr_in, addr_out
  352. ;--------------------------------------------------------------------
  353. aes:
  354.         movem.l a0-a7/d0-d7,-(sp)       ; Save registers.
  355.         move.l  #apb,d1                 ; Load addr of apb.
  356.         move.l  #AES_OPCODE,d0          ; Load AES opcode.
  357.         trap    #2                      ; Call AES.
  358.         movem.l (sp)+,a0-a7/d0-d7       ; Restore registers.
  359.         rts
  360.  
  361. ;--------------------------------------------------------------------
  362. ; This subroutine unhighlights a menu title.
  363. ;
  364. ; Input:        Menu object # in msgbuf3.
  365. ;               Address of resource tree in menu_adr.
  366. ; Output:       Appropriate values in the int_out and global arrays.
  367. ; Regs changed: NONE
  368. ; Uses:         control, int_in, int_out, addr_in, msgbuf3, menu_adr
  369. ; Calls:        aes
  370. ;--------------------------------------------------------------------
  371. menu_normal:
  372.         move    #MENU_TNORMAL,control0
  373.         move    #2,control1
  374.         move    #1,control2
  375.         move    #1,control3
  376.         clr     control4
  377.         move    msgbuf3,int_in0         ; Object number of menu title.
  378.         move    #NORMAL,int_in1         ; Highlight flag.
  379.         move.l  menu_adr,addr_in0       ; Address of resource tree.
  380.         bsr     aes
  381.         rts
  382.         
  383.         data
  384.         
  385.         even
  386. optn1:          dc.w    1
  387. optn2:          dc.w    0
  388. optn3:          dc.w    0
  389. on:             dc.w    1
  390.  
  391. menu_ids:       dc.w    INFO,LOAD,SAVE,QUIT,OPTION1,OPTION2
  392.                 dc.w    OPTION3,ONOFF,SELECT1,SELECT2,SELECT3
  393. menu_vecs:      dc.l    info,load,save,quit,option1,option2
  394.                 dc.l    option3,onoff,select1,select2,select3
  395.         
  396. apb:            dc.l    control,global,int_in,int_out,addr_in,addr_out
  397.  
  398. rsrc_file:      dc.b    "MENU.RSC",0
  399. alert1:         dc.b    "[0][Assembly Language Workshop  |"
  400.                 dc.b    "      Demo program.| |     Copyright 1992|"
  401.                 dc.b    "    by Clayton Walnum][  OK  ]",0
  402. alert2:         dc.b    "[0][You clicked on  |    LOAD][  OK  ]",0
  403. alert3:         dc.b    "[0][You clicked on  |    SAVE][  OK  ]",0
  404. alert4:         dc.b    "[0][You clicked on  |   Select ][  OK  ]",0
  405. alert5:         dc.b    "[0][Resource load error!  ][  OK  ]",0
  406. alert6:         dc.b    "[0][Resource address error!][  OK  ]",0
  407. off_str:        dc.b    "    Off",0
  408. on_str:         dc.b    "    On",0
  409.  
  410.         bss
  411.  
  412.         even
  413.         
  414. menu_adr:       ds.l    1
  415. check_flag:     ds.w    1
  416.  
  417. msgbuf:
  418. msgbuf0:        ds.w    1
  419. msgbuf1:        ds.w    1
  420. msgbuf2:        ds.w    1
  421. msgbuf3:        ds.w    1
  422. msgbuf4:        ds.w    1
  423. msgbuf5:        ds.w    1
  424. msgbuf6:        ds.w    1
  425. msgbuf7:        ds.w    1
  426.  
  427. global:
  428. ap_version:     ds.w    1
  429. ap_count:       ds.w    1
  430. ap_id:          ds.w    1
  431. ap_private:     ds.l    1
  432. ap_ptree:       ds.l    1
  433. ap_1resv:       ds.l    1
  434. ap_2resv:       ds.l    1
  435. ap_3resv:       ds.l    1
  436. ap_4resv:       ds.l    1
  437.  
  438. control:
  439. control0:       ds.w    1
  440. control1:       ds.w    1
  441. control2:       ds.w    1
  442. control3:       ds.w    1
  443. control4:       ds.w    1
  444.  
  445. int_in:
  446. int_in0:        ds.w    1
  447. int_in1:        ds.w    1
  448. int_out:
  449. int_out0:       ds.w    1
  450. int_out1:       ds.w    1
  451. addr_in:
  452. addr_in0:       ds.l    1
  453. addr_in1:       ds.l    1
  454. addr_out:       ds.l    1
  455.  
  456.                 ds.l    255
  457. stack:          ds.l    1
  458.  
  459.