Prev: DB98 Up: Map Next: DC41
DBF5: Draw/erase graphics - calculate screen display address position
Used by the routine at DB98.
Input
B Number of horizontal pixel shifts/rotates (rotated at DC2B) needed
C Pixel number in character row (0-7)
D Vertical pixel row at which to draw the graphic, from the top of the screen display
E Horizontal pixel column at which to draw the graphic, from the left of the screen display
This routine calculates the screen display address position to draw the graphic at, and checks if it's encroaching on the left or right border of the screen
DBF5 LD A,$01 This is the flag indicating whether (any part of the graphic) is visible on-screen (0 = not visible, 1 = visible)
DBF7 LD ($EAD5),A It's set here to visible (1) as part of the item is visible.
This calculates the LOW BYTE of the screen display address
DBFA LD A,E Horizontal pixel position, from left of screen display
DBFB RRA Divide by 8 to get the screen (character) column
DBFC RRA
DBFD RRA
DBFE AND $1F Filter out unnecessary bits (5-7) that may have been affected by the RRA instructions, just keeping bits 0-4 (values 0-31)
DC00 LD E,A Store in E register
DC01 LD A,D Get the calculated vertical (Y) pixel position - these need to go into bits 5-7 of the byte currently stored in E
DC02 RLA Character row is currently indicated by bits 3-5 so shift them left twice to bits 5-7
DC03 RLA
DC04 AND $E0 Get those top three bits (filter out any others)...
DC06 ADD A,E ...and combine them with bits 0-4 which hold the column number, to form the screen display address low byte
DC07 LD E,A Store back in E register
This routine calculates the HIGH BYTE of the screen address
DC08 LD A,D Vertical pixel position, from top of screen display
DC09 RRA Divide by 8 to get screen (character) row
DC0A RRA
DC0B RRA
DC0C AND $18 Bits 3 (8) and 4 (16) include the screen display address high byte character row (0-24)
DC0E ADD A,$40 Set bit 6 (always set for screen addresses)
DC10 ADD A,C C contains the pixel row number in the character line (0-7). Add this to the high byte of the address
DC11 LD D,A Put the calculated screen address high byte into the D register
DC12 LD A,($EAD1) Number of bytes in the graphic tile to draw
DC15 LD C,A Store in C as a counter (checked later at DC70)
Check if we're in the decorative screen border. Tiles are drawn (character) column by column, so we only need to check for the inner border (columns 1 & 30), not the outer ones (columns 0 & 31).
Mirrored graphic tiles have 'reversed' offsets so they tend to be drawn right-to-left, so we need to check both left and right columns.
DC16 LD A,E Retrieve the screen display low byte from the E register
DC17 AND $1F Bits 0-4 (values 0-31) give us the screen vertical (character) column
DC19 CP $01 Check if we're into the left border (column 1)
DC1B JP Z,$DCD5
DC1E CP $1D Check if we're into the right border (column 29)
DC20 JP Z,$DC89
Start of tile graphic draw/erase loop - jump back here from DC73
Shifts graphic so that shifted graphics byte contained in 2 bytes, H & L, ready to draw on screen
DC23 LD A,(HL) Get graphics byte
DC24 INC HL ...And move graphic address pointer along, ready for next one
DC25 CP $00 Byte empty?
DC27 JR Z,$DC56 ...If so, skip this byte, don't bother shifting or drawing
DC29 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
DC2A LD H,A H contains the unshifted graphic byte
DC2B LD L,$00 Clear L register ready to receive shifted bits
DC2D LD A,B Temp store for the 'shift counter' (containing number of right-shifts needed)
DC2E CP $00 Any more shifts needed?
DC30 JR Z,$DC39 ...If not, skip out of the shift loop
DC32 RR H Rotate byte in H register into L register
DC34 RR L
DC36 DJNZ $DC32 Repeat for number of shifts (counter)
DC38 LD B,A Reset the shift counter (from A register)
DC39 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
DC3A LD A,($EACF) Check draw/erase flag
DC3D CP $01 0 = Erase, 1 = Draw
DC3F JR Z,$DC4C If flag = 1, jump to DRAW routine. Otherwise ERASE (next routine)
Prev: DB98 Up: Map Next: DC41