Prev: DC89 Up: Map Next: DD24
DCD5: Draw/erase graphics - graphic partly out of bounds - LEFT border of play area
Used by the routine at DBF5.
Input
HL Graphic data address pointer
DE Screen display address
A Screen column (0-31)
C Number of remaining bytes in the tile to draw
B Number of (right) pixel shifts needed for graphic byte
graphic partly on left border of screen
This routine incorporates slightly tweaked versions of the:
  • Bit shifting routine at DC2A
  • Erase graphic byte routine at DC41
  • Draw graphic byte routine at DC4C
  • Re-calculate screen display address 1 pixel lower routine at DC53
The opposite routine (graphic partially obscured by right-hand screen border) is at DC89.
DCD5 LD A,(HL) Get graphics byte
DCD6 INC HL ...and move graphic address pointer along, ready for next one
DCD7 CP $00 Byte empty?
DCD9 JR Z,$DD01 ...If so, skip this byte, don't bother shifting or drawing
DCDB PUSH HL Store address pointer
Shifts graphic so that the right-shifted graphics byte is contained in 2 bytes, H and L, ready to draw on screen
DCDC LD H,A H contains the unshifted graphic byte
DCDD LD L,$00 Clear L register ready to receive shifted bits
DCDF LD A,B Temp store for the 'shift counter' (containing number of right-shifts needed)
DCE0 CP $00 Any more shifts needed?
DCE2 JR Z,$DCEB ...If not, skip out of the shift loop
DCE4 RR H Rotate byte in H register into L register
DCE6 RR L
DCE8 DJNZ $DCE4 Repeat for number of shifts needed (counter)
DCEA LD B,A Reset the shift counter (from A register)
DCEB EX DE,HL Swap registers so that D & E contain the byte values to draw, and HL contains the screen display address to draw at
DCEC LD A,($EACF) Check draw/erase flag
DCEF CP $01 0 = Erase, 1 = Draw
DCF1 JR Z,$DCFA If flag = 1, jump to DRAW routine. Otherwise ERASE (next routine)
ERASE SCREEN BYTE
DCF3 LD A,E Don't need to erase the first graphic byte (stored in D register) as it's on the screen border, instead get the second byte (stored in E)
DCF4 INC HL Move display address pointer right one character square to character column 2, just inside the left border
DCF5 CPL Invert the graphics byte
DCF6 AND (HL) AND with screen byte (i.e. keeps existing screen byte, clears sprite byte)
DCF7 LD (HL),A ...and put back on screen.
DCF8 JR $DCFE
DRAW SCREEN BYTE
DCFA LD A,E Don't need to draw the first graphic byte (stored in D register) as it's on the screen border, instead get the second byte (stored in E)
DCFB INC HL Move display address pointer right one character square
DCFC OR (HL) OR with existing screen byte, preserve any background graphics
DCFD LD (HL),A ...and put back on screen.
Graphic byte now drawn/erased
DCFE DEC HL Move back left one character space/screen display address
DCFF EX DE,HL
DD00 POP HL HL now back to the graphic display address pointer, DE contains the screen display address
Recalculate screen address after drawing/erasing the graphic byte (also jump in to here from DCD9 if byte to draw is empty)
DD01 LD A,D Get high byte of screen address
DD02 INC A ...and increment (move down 1 pixel row)
DD03 AND $07 Are we crossing into a new character row (8th pixel row)?
DD05 JR Z,$DD0A
DD07 INC D If not, increment screen display address pointer (move down 1 pixel row)
DD08 JR $DD18
DD0A LD A,D Otherwise, adjust high byte to the correct screen address
DD0B AND $F8 Reset the low 3 bits (pixel row number) to zero
DD0D LD D,A
DD0E LD A,E Get the low byte of the screen address
DD0F ADD A,$20 Increment column by 32 to move down to next screen row
DD11 LD E,A
DD12 JR NC,$DD18 Crossing a 1/3 screen boundary? ...If not, skip next 3 instructions
DD14 LD A,D ...If so, adjust high byte of screen address accordingly
DD15 ADD A,$08
DD17 LD D,A Store correct screen address high byte back in D register
Check if encroaching out of bounds into bottom third of screen, where the scroll status panel is
DD18 LD A,D
DD19 CP $50 Are we into the last 3rd of the screen?
DD1B DEC C (Decrement number of tile bytes to draw)
DD1C JP NC,$DC7A Jump to DC7A if into last 3rd of screen (out of bounds)
DD1F JR NZ,$DCD5 If bytes left to draw in the tile - continue to draw next tile byte
DD21 JP $DC7E
Prev: DC89 Up: Map Next: DD24