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