;Date:        Sun, 26 Nov 1995 16:44:33 -0600 (CST)
;From:        site  [site@xnet.com]
;Subject:     LZ: sprite routine

;This message comes from the List-ZShell mailing list:

;In order to write some programs with the Zshell 3.1 (this is unteseted
;with 4.0). I needed a sprite routine.  I wrote this and tested it, and
;had hoped to release it in a library or sometihng, but seeing as Zshell
;isn't supporting libraries (I was waiting to see if 4.0 did) I will just
;release the code.  The data format of the sprite is a byte of the width,
;then a byte of the length, then the actuall sprite.  Unfortuanatly this
;only does width in units of bytes, or 8 pixels :(  but it's better then
;anything I have ever seen.  Make sure to put the offset of the pic in
;de.  I havn't looked at this code in a while, so if you have any
;questions, I'll try to help.  Here goes:



DrawSprite:

     ;ld   B, $02                   ; Number of bytes
     ;ld   hl, (PROGRAM_ADDR)
     ;ld   de, Test
     ;add  hl, de                   ; Put Sprite addr in hl
     ;ld   de, $FC20                ; Put Graphics Mem in d
     ;ldir                          ; Copy them
     ;ret


     ld   hl, (PROGRAM_ADDR)       ; For offset
     add  hl, de                   ; Add Sprite offset to addres hl=Source
     ex   de, hl                   ; save hl in de

     ld   hl, $FC00                ; de=Beg of LCD
     push bc                       ; save b
     ld   b, c                     ; b=counter  loop that many times
     push de
     ld   de, $0010
AddYLoop:
     add  hl, de                   ; add one y coor to hl
     djnz AddYLoop
     pop  de
     pop  bc                       ; restore b
     ld   c, b
     ld   b, $00                   ; clear c so next line is add hl,b
     add  hl, bc                   ; now hl=destination
     ex   de, hl                   ; restore de and hl
                                   ; hl=source de=destination
     ld   B, (hl)                  ; put width in b (so to draw line)
     inc  hl                       ; point to next byte (y height)

     ld   c, (hl)                  ; put height in b
     inc  hl                       ; point to beg of bitmap
     push bc                       ; save height and width in stack
                                   ;  b=width  c=height
     jr   SpriteLoop               ; Start drawing first line

DrawLine:
     dec  c                        ; lower c
     ld   a, c                     ; put c(height) in accumulator for cp
     cp   $00                      ; is this the last line?
     jr   z, Done
     push bc                       ; store bc (width,height) for next loop
                                   ;  if quit there was no extra push.
SpriteLoop:
     ld   a, (hl)
     ld   (de), a
     inc  de
     inc  hl
     djnz SpriteLoop


     pop  bc
     ld   a, e
 add  a, $10                   ; add 10 to de for next line
     sub  b                        ; sub width for next line
     ld   e, a
     jr   DrawLine

Done:
     ret

Test:
     .db  $04, $0C
     .db  11111111b,11111111b,11111111b,11111111b
     .db  10000000b,10000000b,10000000b,10000000b
     .db  11111111b,11111111b,11111111b,11111111b
     .db  00001000b,00001000b,00001000b,00001000b
     .db  11111111b,11111111b,11111111b,11111111b
     .db  10000000b,10000000b,10000000b,10000000b
     .db  11111111b,11111111b,11111111b,11111111b
     .db  00001000b,00001000b,00001000b,00001000b
     .db  11111111b,11111111b,11111111b,11111111b
     .db  10000000b,10000000b,10000000b,10000000b
     .db  11111111b,11111111b,11111111b,11111111b
     .db  00001000b,00001000b,00001000b,00001000b
     .db  11111111b,11111111b,11111111b,11111111

