Author Topic: Help needed for Z80 ASM lesson 18  (Read 2549 times)

0 Members and 1 Guest are viewing this topic.

Offline Hot_Dog

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2988
  • Rating: +445/-10
    • View Profile
Help needed for Z80 ASM lesson 18
« on: August 18, 2010, 11:56:13 am »
Hi, guys,

This is the code I'm using to teach people how to draw any-size sprites:  (In this case, an OR routine)

Code: [Select]
Put_Sprite_OR:
; A = x coordinate
; L = y coordinate
; B = number of rows
; Sprite_Width holds the width of the sprite
; IX = address of sprite
    LD     H, 0
    LD     D, H
    LD     E, L
    ADD    HL, HL
    ADD    HL, DE
    ADD    HL, HL
    ADD    HL, HL

    LD     E, A
    SRL    E
    SRL    E
    SRL    E
    ADD    HL, DE

    LD     DE, plotsscreen
    ADD    HL, DE
   
   
    AND    7
    JR     Z, _AlignedOR

    LD     C, A
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL   
   
_RowLoopOR:

    PUSH   BC
   
    ;Stores width into B, which will be decreased 1 by 1 until one row is complete
    LD A, (Sprite_Width)
    LD B, A
   

_ColumnLoopOR:
    PUSH BC
       
    LD     B, C
    LD     C, (IX)
    OR    A

_ShiftLoopOR:
    SRL    C
    RRA
 
    DJNZ   _ShiftLoopOR
 

    INC    HL
    OR   (HL)
    LD     (HL), A

    DEC    HL
    LD     A, C
    OR    (HL)
    LD     (HL), A

    POP BC
    INC HL
    INC IX
 
    DJNZ _ColumnLoopOR
   
    ADD    HL, DE
   
    POP    BC
    DJNZ   _RowLoopOR
   
    RET

_AlignedOR:
   
    PUSH HL
    LD A, 12
    LD HL, Sprite_Width
    SUB (HL)
    LD D,0
    LD E, A
    POP HL 
     
_PutLoopOR:
    PUSH BC
    LD A, (Sprite_Width)
    LD B, A

_PutLoopOR2:
   
    LD     A, (IX)
    OR (HL)
    LD     (HL), A
    INC  IX
 
    INC HL
    DJNZ _PutLoopOR2
_PutLoopORAdd:
    POP BC
   

 ADD HL, DE
 DJNZ _PutLoopOR
    RET

But, even though it's important that someone knows about clipping sprites, I an unskilled in that area, and I need help knowing how to do it with this particular routine.  The thing is, it has to be for THIS routine because this is one that beginners up to this point can understand.

Thanks for any help you can offer