home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / cegdac.asm < prev    next >
Assembly Source File  |  1991-04-15  |  13KB  |  300 lines

  1. ; Assembly routines for Edsun CEG/DAC animation program.
  2.  
  3. SCREEN_SEGMENT  equ     0a000h
  4. SCREEN_WIDTH    equ     320
  5. SCREEN_HEIGHT   equ     200
  6.  
  7. ; Draws a frame around the screen, drawing the top scan line of the
  8. ; frame in color StartColor, the next in color StartColor+1, and so on
  9. ; up through color 190, then jumping to color 224 and continuing to
  10. ; color 255, and back around to color StartColor if the screen has
  11. ; that many scan lines.
  12. ;
  13. ; C near callable as: void DrawFrame(int StartColor, int FrameWidth);
  14. ;
  15. ; All assembly code tested with TASM 2.
  16.  
  17. parms   struc
  18.         dw      2 dup (?)       ;pushed BP & return address
  19. StartColor dw   ?               ;color of first scan line
  20. FrameWidth dw   ?               ;width of frame
  21. parms   ends
  22.  
  23. ; Macro to advance to the next color, going from StartColor to 190,
  24. ; then to 224 up through 255, and then back to StartColor.
  25. CYCLE_COLOR     macro
  26.         local   NoTurnover,CycleColorDone
  27.  
  28.         inc     al              ;advance the color
  29.         jnz     NoTurnover      ;didn't turn over from 255 to 0
  30.         mov     al,byte ptr StartColor[bp] ;did turn over; force to
  31.         jmp     CycleColorDone             ;  StartColor
  32. NoTurnover:
  33.         cmp     al,191          ;time to jump to second block?
  34.         jnz     CycleColorDone  ;no, the color is fine as is
  35.         mov     al,224          ;yes, jump to first color in 2nd block
  36. CycleColorDone:
  37.         endm
  38.  
  39.         .model small
  40.         .code
  41.         public  _DrawFrame
  42. _DrawFrame      proc    near
  43.         push    bp      ;preserve caller's stack frame
  44.         mov     bp,sp   ;point to local stack frame
  45.         push    si      ;preserve caller's register variables
  46.         push    di
  47.         cld
  48.         mov     ax,SCREEN_SEGMENT
  49.         mov     es,ax
  50.         sub     di,di           ;point to the first byte of the frame
  51.         mov     al,byte ptr StartColor[bp] ;initial color
  52. ; First, draw the top of the frame.
  53.         mov     dx,FrameWidth[bp] ;height of top part of frame
  54.         mov     bx,SCREEN_WIDTH ;# of bytes per scan line
  55. DrawTopLoop:
  56.         mov     cx,bx
  57.         rep     stosb           ;draw one scan line of the frame top
  58.         CYCLE_COLOR             ;advance to the next color
  59.         dec     dx              ;count down frame top scan lines
  60.         jnz     DrawTopLoop
  61. ; Next, draw the sides of the frame.
  62.         mov     cx,FrameWidth[bp]
  63.         mov     si,cx           ;SI = FrameWidth for later
  64.         add     cx,cx           ;FrameWidth * 2
  65.         mov     dx,SCREEN_HEIGHT ;height of entire frame
  66.         sub     dx,cx           ;height of sides =
  67.                                 ; SCREEN_HEIGHT - (FrameWidth * 2)
  68.         sub     bx,cx           ;distance from one side to other =
  69.                                 ; SCREEN_WIDTH - (FrameWidth * 2)
  70. DrawSidesLoop:
  71.         mov     cx,si           ;width of each side = FrameWidth
  72.         rep     stosb           ;draw one scan line of the left side
  73.         add     di,bx           ;point to the start of the right side
  74.         mov     cx,si           ;width of each side = FrameWidth
  75.         rep     stosb           ;draw one scan line of the right side
  76.         CYCLE_COLOR             ;advance to the next color
  77.         dec     dx              ;count down frame top scan lines
  78.         jnz     DrawSidesLoop
  79. ; Finally, draw the bottom of the frame.
  80.         mov     bx,SCREEN_WIDTH ;# of bytes per scan line
  81. DrawBottomLoop:
  82.         mov     cx,bx
  83.         rep     stosb           ;draw one scan line of frame bottom
  84.         CYCLE_COLOR             ;advance to the next color
  85.         dec     si              ;count down frame bottom scan lines
  86.         jnz     DrawBottomLoop
  87.         pop     di              ;restore caller's register variables
  88.         pop     si
  89.         pop     bp              ;restore caller's stack frame
  90.         ret
  91. _DrawFrame      endp
  92.  
  93. ; Sets the 5 rightmost pixels on each scan line to perform an EDP load
  94. ; of the corresponding element from AttributeSettings to the DAC
  95. ; register specified by DACRegisterToLoad. (Every scan line reloads
  96. ; DACRegisterToLoad.) Stores each EDP sequence in display memory in
  97. ; this order: DAC register #, the EDP opcode, and finally RGB color to
  98. ; load, in order to avoid accidentally loading the wrong DAC register
  99. ; if those bytes happen to be scanned just as the EDP sequence is
  100. ; half-written to memory.
  101. ;
  102. ; C near-callable as: SetEDPAtRight(int DACRegisterToLoad,
  103. ;       RGB* AttributeSettings, int FirstEntryToSet, int LastEntry);
  104.  
  105. SEARparms struc
  106.         dw      2 dup (?)       ;pushed BP & return address
  107. DACRegisterToLoad dw    ?       ;DAC register to perform EDP load to
  108. AttributeSettings dw    ?       ;palette value table to load from
  109.                                 ; (array of RGB triplets)
  110. FirstEntryToSet dw      ?       ;# of first entry in AttributeSettings
  111.                                 ; from which to load
  112. LastEntry       dw      ?       ;# of last entry in AttributeSettings
  113. SEARparms ends
  114.  
  115.         public _SetEDPAtRight
  116. _SetEDPAtRight  proc    near
  117.         push    bp      ;preserve caller's stack frame
  118.         mov     bp,sp   ;point to local stack frame
  119.         push    si      ;preserve caller's register variables
  120.         push    di
  121.         cld
  122.         mov     ax,SCREEN_SEGMENT
  123.         mov     es,ax
  124.         mov     di,SCREEN_WIDTH-5 ;point to the first byte at which to
  125.                                 ; store EDP sequence on scan line 0
  126.         mov     si,FirstEntryToSet[bp]
  127.         add     si,si           ;first entry index * 2
  128.         add     si,FirstEntryToSet[bp] ;first entry index * 3
  129.         mov     cx,AttributeSettings[bp]
  130.         add     si,cx           ;point to first entry to load
  131.         mov     bx,LastEntry[bp]
  132.         add     bx,bx           ;last entry index * 2
  133.         add     bx,LastEntry[bp] ;last entry index * 3
  134.         add     bx,cx          ;point to byte after last entry to load
  135.         mov     ah,byte ptr DACRegisterToLoad[bp] ;DAC reg to load
  136.         mov     cx,SCREEN_HEIGHT ;put one EDP sequence on each line
  137. SetEDPLoop:
  138.         mov     es:[di+4],ah    ;set the # of the DAC register to load
  139.         mov     al,191          ;EDP opcode
  140.         stosb                   ;put EDP opcode in bitmap
  141.         movsb                   ;copy over the RGB value to load with
  142.         movsb                   ; this EDP opcode
  143.         movsb
  144.         add     di,SCREEN_WIDTH-4 ;point to the first byte of the EDP
  145.                                 ; sequence on the next scan line
  146.         cmp     si,bx           ;have we wrapped off the end of the
  147.                                 ; attribute array?
  148.         jb      EDPLoopBottom   ;no
  149.         mov     si,AttributeSettings[bp] ;point to start of attr array
  150. EDPLoopBottom:
  151.         loop    SetEDPLoop
  152.         pop     di              ;restore caller's register variables
  153.         pop     si
  154.         pop     bp              ;restore caller's stack frame
  155.         ret
  156. _SetEDPAtRight  endp
  157.  
  158. ; Fills the rectangle from (StartX,StartY) to (EndX-1,EndY-1); the row
  159. ; at EndY and the column at EndX are not drawn. No clipping or error
  160. ; checking is performed.
  161. ;
  162. ; C near-callable as: FillRect(int StartX, int StartY, int EndX,
  163. ;       int EndY, int FillColor);
  164.  
  165. FRparms struc
  166.         dw      2 dup (?) ;pushed BP & return address
  167. StartX  dw      ?       ;left edge of fill rect
  168. StartY  dw      ?       ;top edge of fill rect
  169. EndX    dw      ?       ;right edge of fill rect + 1
  170. EndY    dw      ?       ;bottom edge of fill rect + 1
  171. FillColor dw    ?       ;color with which to fill rect
  172. FRparms ends
  173.  
  174.         public _FillRect
  175. _FillRect       proc    near
  176.         push    bp      ;preserve caller's stack frame
  177.         mov     bp,sp   ;point to local stack frame
  178.         push    si      ;preserve caller's register variables
  179.         push    di
  180.         cld
  181.         mov     ax,SCREEN_SEGMENT
  182.         mov     es,ax
  183.         mov     bx,SCREEN_WIDTH
  184.         mov     ax,StartY[bp]
  185.         mov     si,EndY[bp]
  186.         sub     si,ax           ;# of scan lines to fill
  187.         mul     bx              ;start of top scan line of rect
  188.         mov     dx,EndX[bp]
  189.         mov     di,StartX[bp]
  190.         sub     dx,di           ;# of bytes across rect
  191.         add     di,ax           ;ES:DI = upper left byte of rect
  192.         sub     bx,dx           ;distance from end of one rect scan
  193.                                 ; line to start of next
  194.         mov     al,byte ptr FillColor[bp] ;color with which to fill
  195. FillLoop:
  196.         mov     cx,dx           ;# of bytes across
  197.         rep     stosb           ;fill one scan line
  198.         add     di,bx           ;point to start of next line to fill
  199.         dec     si              ;count off scan lines
  200.         jnz     FillLoop
  201.         pop     di              ;restore caller's register variables
  202.         pop     si
  203.         pop     bp              ;restore caller's stack frame
  204.         ret
  205. _FillRect       endp
  206.  
  207. ; Copies the image pointed to by ImagePtr with the upper left corner
  208. ; at (StartX,StartY). No clipping or error checking is performed.
  209. ;
  210. ; C near-callable as: DrawImage(int StartX, int StartY,
  211. ;       Image* ImagePtr);
  212.  
  213. DIparms struc
  214.         dw      2 dup (?) ;pushed BP & return address
  215. DIStartX dw     ?       ;left edge of block destination
  216. DIStartY dw     ?       ;top edge of block destination
  217. ImagePtr dw     ?       ;pointer to Image struc to draw
  218. DIparms ends
  219.  
  220. Image   struc
  221. Width   dw      ?
  222. Height  dw      ?
  223. PixMap  dw      ?
  224. Image   ends
  225.  
  226.         public _DrawImage
  227. _DrawImage      proc    near
  228.         push    bp      ;preserve caller's stack frame
  229.         mov     bp,sp   ;point to local stack frame
  230.         push    si      ;preserve caller's register variables
  231.         push    di
  232.         cld
  233.         mov     ax,SCREEN_SEGMENT
  234.         mov     es,ax
  235.         mov     ax,SCREEN_WIDTH
  236.         mul     DIStartY[bp]    ;start of top scan line of rect
  237.         add     ax,DIStartX[bp]
  238.         mov     di,ax           ;ES:DI = upper left byte of rect
  239.         mov     si,ImagePtr[bp] ;point to Image struc to draw
  240.         mov     dx,[si].Width   ;# of bytes across rect to draw
  241.         mov     ax,[si].Height  ;# of scan lines to copy
  242.         mov     si,[si].PixMap  ;image bytes to copy
  243.         mov     bx,SCREEN_WIDTH
  244.         sub     bx,dx           ;distance from end of one rect scan
  245.                                 ; line to start of next
  246. CopyLoop:
  247.         mov     cx,dx           ;# of bytes across
  248.         rep     movsb           ;copy one scan line
  249.         add     di,bx           ;point to next line to copy to
  250.         dec     ax              ;count off scan lines
  251.         jnz     CopyLoop
  252.         pop     di              ;restore caller's register variables
  253.         pop     si
  254.         pop     bp              ;restore caller's stack frame
  255.         ret
  256. _DrawImage      endp
  257.  
  258. ; Puts the EDP sequence that loads the specified RGB color into the
  259. ; specified DAC register (that is, palette location, changing the
  260. ; color of the corresponding attribute) in the second through sixth
  261. ; pixels of the specified scan lines. Like SetEDPAtRight, stores EDP
  262. ; sequences in DAC register #/EDP opcode/RGB order to avoid
  263. ; accidentally loading the wrong palette register by chance timing.
  264. ;
  265. ; C near-callable as: SetEDPAtLeft(int Attribute, int Red, int Green,
  266. ;       int Blue, int ScanLine);
  267.  
  268. SEALparms struc
  269.         dw      2 dup (?) ;pushed BP & return address
  270. Attribute dw    ?       ;DAC register to load (attribute for which to
  271.             ; change color)
  272. Red     dw      ?       ;red component to load
  273. Green   dw      ?       ;green component to load
  274. Blue    dw      ?       ;blue component to load
  275. ScanLine dw     ?       ;scan line at start of which to put EDP load
  276. SEALparms ends
  277.  
  278.         public _SetEDPAtLeft
  279. _SetEDPAtLeft proc      near
  280.         push    bp      ;preserve caller's stack frame
  281.         mov     bp,sp   ;point to local stack frame
  282.         mov     ax,SCREEN_SEGMENT
  283.         mov     es,ax
  284.         mov     ax,SCREEN_WIDTH
  285.         mul     ScanLine[bp]    ;start of scan line on which to load
  286.         mov     bx,ax           ;ES:BX = start of scan line
  287.         mov     al,byte ptr Attribute[bp]
  288.         mov     es:[bx+5],al    ;DAC register to load
  289.         mov     es:byte ptr [bx+1],191 ;EDP opcode
  290.         mov     al,byte ptr Red[bp]
  291.         mov     es:[bx+2],al    ;new red value
  292.         mov     al,byte ptr Green[bp]
  293.         mov     es:[bx+3],al    ;new green value
  294.         mov     al,byte ptr Blue[bp]
  295.         mov     es:[bx+4],al    ;new blue value
  296.         pop     bp              ;restore caller's stack frame
  297.         ret
  298. _SetEDPAtLeft endp
  299.         end
  300.