Prev: DC77 Up: Map Next: DCD5
DC89: Draw/erase graphics - graphic partly out of bounds - RIGHT 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
The graphics byte is pixel-shifted into two screen bytes, but the second byte is now in the right border area.
graphic partly on right 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 left-hand screen border) is at DCD5.
DC89 LD A,(HL) Get graphics byte
DC8A INC HL ...and move graphic address pointer along, ready for next one
DC8B CP $00 Byte empty?
DC8D JR Z,$DCB2 ...If so, skip this byte, don't bother shifting or drawing
DC8F 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:
DC90 LD H,A H contains the unshifted graphic byte
DC91 LD L,$00 Clear L register ready to receive shifted bits
DC93 LD A,B Temp store for the 'shift counter' (containing number of right-shifts needed)
DC94 CP $00 Any more shifts needed?
DC96 JR Z,$DC9F ...If not, skip out of the shift loop
DC98 RR H Rotate byte in H register into L register
DC9A RR L
DC9C DJNZ $DC98 Repeat for number of shifts needed (counter)
DC9E LD B,A Reset the shift counter (from A register)
DC9F 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
DCA0 LD A,($EACF) Check draw/erase flag
DCA3 CP $01 0 = Erase, 1 = Draw
DCA5 JR Z,$DCAD If flag = 1, jump to DRAW routine. Otherwise ERASE (next routine)
ERASE SCREEN BYTE
Don't need to erase the second graphic byte (stored in E register) as it's on the screen border.
DCA7 LD A,D Get first graphic byte
DCA8 CPL Invert it
DCA9 AND (HL) AND with screen byte (i.e. keeps existing screen byte, clears sprite byte)
DCAA LD (HL),A ...and put back on screen.
DCAB JR $DCB0
DRAW SCREEN BYTE
No need to draw the second graphic byte (stored in E register) as it's on the screen border.
DCAD LD A,D Get first graphic byte
DCAE OR (HL) OR with existing screen byte, preserve any background graphics
DCAF LD (HL),A ...and draw back on screen.
DCB0 EX DE,HL
DCB1 POP HL HL now back to the graphic display address pointer, DE contains the screen display address
Recalculate screen address 1 pixel line down after drawing/erasing the graphic byte (also jump in to here from DC8D if byte empty)
DCB2 LD A,D Get high byte of screen address
DCB3 INC A ...and increment (move down 1 pixel row)
DCB4 AND $07 Are we crossing into a new character row (8th pixel row)?
DCB6 JR Z,$DCBB
DCB8 INC D If not, increment screen display address pointer (move down 1 pixel row)
DCB9 JR $DCC9
DCBB LD A,D Otherwise, adjust high byte to the correct screen address
DCBC AND $F8 Reset the low 3 bits (pixel row number) to zero
DCBE LD D,A
DCBF LD A,E Get the low byte of the screen address
DCC0 ADD A,$20 Increment column by 32 to move down to next screen row
DCC2 LD E,A
DCC3 JR NC,$DCC9 Crossing a 1/3 screen boundary? ...If not, skip next 3 instructions
DCC5 LD A,D ...If so, adjust high byte of screen address accordingly
DCC6 ADD A,$08
DCC8 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
DCC9 LD A,D
DCCA CP $50 Are we into the last 3rd of the screen?
DCCC DEC C (Decrement number of tile bytes to draw)
DCCD JP NC,$DC7A Jump to DC7A if into last 3rd of screen (out of bounds)
DCD0 JR NZ,$DC89 If bytes left to draw in the tile - continue to draw next tile byte
DCD2 JP $DC7E
Prev: DC77 Up: Map Next: DCD5