Prev: E3CC Up: Map Next: E46C
E3FD: Print screen colours for room object/creature
Used by the routines at D019 and D27D.
attribute colours for room items and creatures
Calculate attribute screen addresses and set screen colours for any items/creatures that have colours different from the standard room colours.
First identify attribute row using the item's vertical pixel position:
E3FD LD A,($EAD2) Item's vertical position, from top of playing area, in pixels
E400 ADD A,$12 Add an offset to avoid top border
E402 AND $F8 Filter out bits 0-2 (values 0-7) as attributes are in character (8-pixel) increments
E404 ADD A,A Double the value
E405 LD L,A Store calculated value in low byte of display attribute address
E406 SBC A,A If the earlier ADD has caused a carry, we're into the second third of the screen attribute display
E407 LD H,A ...Adjust the high byte accordingly
E408 ADD HL,HL
Vertical character row (left of screen) is now identified. Next consider horizontal position.
E409 LD A,($EAD3) Item's horizontal screen position, in pixels
E40C ADD A,$09 Adjust/increment base position. This value isn't quite right - see Bugs - Attribute bleed on left of screen
E40E RRA Divide by 8 to get character square from pixel
E40F RRA
E410 RRA
E411 AND $1F Attribute lines are 0-31 so only need to keep these bits
E413 ADD A,L And add it into the attribute address low byte
E414 LD L,A
E415 LD A,$58 High byte of attribute display address is %01010000, so add this into the high byte of the address
E417 ADD A,H
E418 LD H,A
HL register is now pointing at screen attribute address for the item.
The next set of instructions determines the size of the item to colour. There are two sizes - large (for creatures) and small (for objects - i.e. everything else).
Colour patterns at EBD6 and EBE6 identify the series of attributes to use for colouring each of these respectively.
E419 LD A,($EB43) Get item graphic type
E41C CP $00 0 = item no longer present, i.e. destroyed creature
E41E JR Z,$E424
E420 CP $03 3 = creature
E422 JR NZ,$E429
E424 LD DE,$EBD6 Colour pattern address = EBD6 for creature/destroyed creature
E427 JR $E42C
E429 LD DE,$EBE6 Colour pattern address = EBE6 for any other item
E42C LD A,(DE) First byte of set is number of total data bytes in set - either 15 or 9
E42D LD ($EAC7),A Store as counter
E430 INC DE Move to the first byte in the data set
Colouring loop:
E431 LD A,(DE) Get the byte
E432 INC DE
E433 LD C,A Store in C register
E434 RLA Shift bit 7 into carry
E435 SBC A,A And subtract
E436 LD B,A This will result in 0 (value will be added) or 255 (-1 = value subtracted) in the B register
E437 ADD HL,BC BC - containing the offset, either positive or negative - added to the screen attribute address (in HL)
Check that attribute display address isn't out of bounds (side border or bottom third of screen).
E438 LD A,L Get attribute column on screen (0-31)
E439 AND $1F Only need values 0-31
E43B SUB $02 Can't draw on left/right border, so check screen column number is between 2 and 29 (inclusive)
E43D CP $1C ...A subtraction of 2 and then comparing against a value of 28
E43F JR NC,$E462 ...will cause attribute addresses either in the left border 0, 1 or the right border (30, 31) to jump out here with a No Carry
E441 LD A,L Border check OK. Get low byte of screen attribute address
E442 CP $40 If attribute low byte address is 64 or less...
E444 LD A,H (High byte of screen attribute address)
E445 JR NC,$E44B
E447 CP $58 ...and high byte = 88, attribute display address is in the top third and the top two lines (border) of the screen
E449 JR Z,$E462 If so, skip and don't print any colour here
E44B SUB $58 High byte > 88 so we're past the top third
E44D CP $02 Check if we're into the bottom third of the screen
E44F JR NC,$E462 If so, this part of the item is off screen - don't set attribute colour here
Check if we're drawing or erasing and set colour accordingly:
E451 LD A,($EACF) Check DRAW/ERASE flag
E454 CP $00
E456 JR Z,$E45E
E458 LD A,($EAA8) It's DRAW (1) - so get graphic's attribute colour byte
E45B LD (HL),A ...and put on screen
E45C JR $E462
E45E LD A,($EAA9) It's ERASE (0) so get room's attribute colour byte
E461 LD (HL),A ...and put on screen
Repeat loop counter:
E462 LD A,($EAC7) Get the counter
E465 DEC A Decrement
E466 LD ($EAC7),A ...and re-store
E469 JR NZ,$E431 Continue printing attributes for the rest of the graphic
E46B RET
Prev: E3CC Up: Map Next: E46C