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

  1. ;---------------------------------------------------------------------
  2. ; THE ST ASSEMBLY LANGUAGE WORKSHOP, VOLUME 2
  3. ; PROGRAM 5
  4. ;
  5. ; COPYRIGHT 1992 BY CLAYTON WALNUM
  6. ;---------------------------------------------------------------------
  7.  
  8. CCONIN          equ     1
  9. PTERM0          equ     0
  10. MSHRINK         equ     74
  11.  
  12. V_CLRWK         equ     3
  13. V_PLINE         equ     6
  14. VSL_TYPE        equ     15
  15. VSL_WIDTH       equ     16
  16. VSL_COLOR       equ     17
  17. V_OPNVWK        equ     100
  18. V_CLSVWK        equ     101
  19. VSL_ENDS        equ     108
  20.  
  21. AES_OPCODE      equ     200
  22. VDI_OPCODE      equ     115
  23.  
  24. ;--------------------------------------------------------------------
  25. ; MACROS
  26. ;--------------------------------------------------------------------
  27.  
  28. ;--------------------------------------------------------------------
  29. ; This macro gets a single character from the keyboard, using the
  30. ; Cconin GEMDOS function.
  31. ;--------------------------------------------------------------------
  32. .macro get_char
  33.         move    #CCONIN,-(sp)
  34.         trap    #1
  35.         addq.l  #2,sp
  36.         .endm
  37.         
  38. ;--------------------------------------------------------------------
  39. ; MAIN PROGRAM
  40. ;--------------------------------------------------------------------
  41.         .text
  42.  
  43. ; Calculate the size of the program area.
  44.  
  45.         move.l  a7,a5                   ; Save addr of TPA.
  46.         lea     stack,sp                ; Load addr of our stack.
  47.         
  48.         move.l  4(a5),a5                ; Get addr of TPA.              
  49.         move.l  12(a5),d0               ; Get len of text segment.
  50.         add.l   20(a5),d0               ; Add len of data segment.
  51.         add.l   28(a5),d0               ; Add len of BSS segment.
  52.         add.l   #$100,d0                ; Add len of TPA. 
  53.  
  54. ; Release unused memory back to the system.
  55.         
  56.         move.l  d0,-(sp)                ; Push size of program on stack.
  57.         move.l  a5,-(sp)                ; Push program addr on stack.
  58.         clr     -(sp)                   ; Clear dummy word on stack.    
  59.         move    #MSHRINK,-(sp)          ; Push Mshrink opcode.
  60.         trap    #1                      ; Call GEMDOS.
  61.         add.l   #12,sp                  ; Reset stack pointer.
  62.  
  63. ; Clear some fields of the global array.
  64.  
  65.         clr.l   ap_ptree        
  66.         clr.l   ap_1resv
  67.         clr.l   ap_2resv
  68.         clr.l   ap_3resv
  69.         clr.l   ap_4resv
  70.  
  71. ; Call appl_init to initialize application.
  72.  
  73.         move.l  #appl_init,apb
  74.         bsr     aes
  75.         cmpi    #$FFFF,ap_id            ; Error?
  76.         beq     end                     ; Yep.  Outta here.
  77.  
  78. ; Get handle to screen device.
  79.  
  80.         move.l  #graf_handle,apb
  81.         jsr     aes
  82.         move    int_out,gr_handle       ; Save screen device handle.
  83.  
  84. ; Open virtual workstation.
  85.  
  86.         move    #V_OPNVWK,contrl        ; v_opnvwk opcode.
  87.         clr     contrl+2                ; # of points in pts_in.
  88.         move    #11,contrl+6            ; # of ints in int_in.
  89.         move    gr_handle,contrl+12     ; Screen device handle. 
  90.         movea.l #int_in,a5              ; Get address of int_in.
  91.         move    #9,d5                   ; Init loop counter.
  92. loop:
  93.         move    #1,(a5)+                ; Place 1 in element of int_in.
  94.         dbra    d5,loop                 ; Go init next element of int_in.
  95.         move    #2,int_in+20            ; Set for raster coordinates.
  96.         jsr     vdi
  97.         move    contrl+12,vws_handle    ; Save virtual workstation handle.
  98.  
  99. ; Clear workstation.
  100.  
  101.         move    #V_CLRWK,contrl         ; v_clrwk opcode.
  102.         clr     contrl+2                ; # of points in pts_in.
  103.         clr     contrl+6                ; # of ints in int_in.
  104.         jsr     vdi
  105.  
  106.         move    #3,d5                   ; Init loop counter.
  107. polyline:
  108.  
  109. ; Set line color.
  110.  
  111.         move    #VSL_COLOR,contrl       ; vsl_color opcode.
  112.         clr     contrl+2                ; # of points in pts_in.
  113.         move    #1,contrl+6             ; # of ints in int_in.
  114.         move    color,int_in            ; New line color.
  115.         jsr     vdi
  116.         addq    #1,color
  117.  
  118. ; Set line ends.
  119.  
  120.         move    #VSL_ENDS,contrl        ; vsl_ends opcode.
  121.         clr     contrl+2                ; # points in pts_in.
  122.         move    #2,contrl+6             ; # ints in int_in.
  123.         move    ends,int_in             ; End style for start of line.
  124.         move    ends,int_in+2           ; End style for end of line.
  125.         jsr     vdi
  126.         addq    #1,ends
  127.  
  128. ; Set line width.
  129.  
  130.         move    #VSL_WIDTH,contrl       ; vsl_width opcode.
  131.         move    #1,contrl+2             ; # points in pts_in.
  132.         clr     contrl+6                ; # of ints in int_in.
  133.         move    width,pts_in            ; New line width.
  134.         clr     pts_in+2
  135.         jsr     vdi
  136.         addq    #2,width                ; calculate next line width.
  137.  
  138. ; Draw polyline.
  139.  
  140.         move    #V_PLINE,contrl         ; v_pline opcode.
  141.         move    #2,contrl+2             ; # of points in pts_in.
  142.         clr     contrl+6                ; # of ints in int_in.
  143.         move    #30,pts_in              ; X coord of first point.
  144.         move    y1,pts_in+2             ; Y coord of first point.
  145.         move    #280,pts_in+4           ; X coord of second point.
  146.         move    y2,pts_in+6             ; Y coord of second point.
  147.         jsr     vdi
  148.         add     #10,y1                  ; Calculate next Y coords.
  149.         add     #10,y2
  150.         dbra    d5,polyline             ; Go draw next line.
  151.  
  152. ; Reset line widths.
  153.  
  154.         move    #VSL_WIDTH,contrl       ; vsl_width opcode.
  155.         move    #1,contrl+2             ; # of points in pts_in.
  156.         clr     contrl+6                ; # of ints in int_in.
  157.         move    #1,pts_in               ; New line width.
  158.         clr     pts_in+2
  159.         jsr     vdi
  160.  
  161. ; Reset line ends.
  162.  
  163.         move    #VSL_ENDS,contrl        ; vsl_ends opcode.
  164.         clr     contrl+2                ; # of points in pts_in.
  165.         move    #2,contrl+6             ; # of ints in int_in.
  166.         move    #0,int_in               ; End style for start of line.
  167.         move    #0,int_in+2             ; End style for end of line.
  168.         jsr     vdi
  169.  
  170.         move    #5,d5                   ; Init loop counter.
  171. polyline2:
  172.  
  173. ; Set line type.
  174.  
  175.         move    #VSL_TYPE,contrl        ; vsl_type opcode.
  176.         clr     contrl+2                ; # of points in pts_in.
  177.         move    #1,contrl+6             ; # of ints in int_in.
  178.         move    type,int_in             ; Line pattern type.
  179.         jsr     vdi
  180.         addq    #1,type                 ; Calculate next line type.
  181.  
  182. ; Draw polyline.
  183.  
  184.         move    #V_PLINE,contrl         ; v_pline opcode.
  185.         move    #2,contrl+2             ; # of points in pts_in.
  186.         clr     contrl+6                ; # of ints in int_in.
  187.         move    #30,pts_in              ; X coord of first point.
  188.         move    y1,pts_in+2             ; Y coord of first point.
  189.         move    #280,pts_in+4           ; X coord of second point.
  190.         move    y2,pts_in+6             ; Y coord of second point.
  191.         jsr     vdi
  192.         add     #10,y1                  ; Calculate next Y coords.
  193.         add     #10,y2
  194.         dbra    d5,polyline2            ; Go draw another line.
  195.  
  196.         get_char        
  197.  
  198. ; Close the virtual workstation.
  199.  
  200.         move    #V_CLSVWK,contrl        ; v_clsvwk opcode.
  201.         clr     contrl+2                ; # of points in pts_in.
  202.         clr     contrl+6                ; # of ints in int_in.
  203.         jsr     vdi
  204.                 
  205. ; Close down application.
  206.  
  207. exit:
  208.         move.l  #appl_exit,apb          ; appl_exit control array.
  209.         bsr     aes
  210.         
  211. end:
  212.         move.w  #PTERM0,-(sp)           ; Back to desktop.
  213.         trap    #1
  214.  
  215. ;--------------------------------------------------------------------
  216. ; This subroutine calls the AES.  Before calling this subroutine, the
  217. ; program must have correctly initialized the AES control, int_in,
  218. ; and addr_in arrays.
  219. ;
  220. ; Input:        Appropriate values in the int_in, addr_in, and
  221. ;               control arrays.
  222. ; Output:       Appropriate values in the int_out, addr_out, and
  223. ;               global arrays.
  224. ; Regs changed: NONE
  225. ; Uses: apb, global, int_in, int_out, addr_in, addr_out
  226. ;--------------------------------------------------------------------
  227. aes:
  228.         movem.l a0-a7/d0-d7,-(sp)       ; Save registers.
  229.         move.l  #apb,d1                 ; Load addr of apb.
  230.         move.w  #AES_OPCODE,d0          ; Load AES opcode.
  231.         trap    #2                      ; Call AES.
  232.         movem.l (sp)+,a0-a7/d0-d7       ; Restore registers.
  233.         rts
  234.  
  235. ;--------------------------------------------------------------------
  236. ; This subroutine calls the VDI. Before calling this subroutine, the
  237. ; program must have correctly initialized the VDI contrl, intin,
  238. ; and ptsin arrays.
  239. ;
  240. ; Input:        Appropriate values in the intin, ptsin, and
  241. ;               contrl arrays.
  242. ; Output:       Appropriate values in the intout and ptsout arrays.
  243. ; Regs changed: NONE
  244. ; Uses: vpb, intin, intout, ptsin, ptsout
  245. ;--------------------------------------------------------------------
  246. vdi:
  247.         movem.l a0-a7/d0-d7,-(sp)       ; Save registers.
  248.         move.l  #vpb,d1                 ; Load addr of vpb.
  249.         move.w  #VDI_OPCODE,d0          ; Load VDI opcode.
  250.         trap    #2                      ; Call VDI.
  251.         movem.l (sp)+,a0-a7/d0-d7       ; Restore registers.
  252.         rts
  253.  
  254.         data
  255.         
  256.         even
  257.  
  258. y1:             dc.w    20
  259. y2:             dc.w    20
  260. color:          dc.w    1
  261. type:           dc.w    1
  262. width:          dc.w    1
  263. ends:           dc.w    0
  264.  
  265. apb:            dc.l    0,global,int_in,int_out,addr_in,addr_out
  266. vpb:            dc.l    contrl,int_in,pts_in,int_out,pts_out
  267.  
  268. appl_init:      dc.w    10,0,1,0,0
  269. appl_exit:      dc.w    19,0,1,0,0
  270. graf_handle:    dc.w    77,0,5,0,0
  271.  
  272.         .bss
  273.  
  274.         .even
  275.  
  276. gr_handle:      ds.w    1
  277. vws_handle:     ds.w    1
  278.         
  279. global:
  280. ap_version:     ds.w    1
  281. ap_count:       ds.w    1
  282. ap_id:          ds.w    1
  283. ap_private:     ds.l    1
  284. ap_ptree:       ds.l    1
  285. ap_1resv:       ds.l    1
  286. ap_2resv:       ds.l    1
  287. ap_3resv:       ds.l    1
  288. ap_4resv:       ds.l    1
  289.  
  290. contrl:         ds.w    12
  291. int_in:         ds.w    128
  292. int_out:        ds.w    128
  293. addr_in:        ds.l    64
  294. addr_out:       ds.l    64
  295. pts_in:         ds.w    128
  296. pts_out:        ds.w    128
  297.  
  298.                 ds.l    255
  299. stack:          ds.l    1
  300.  
  301.