Prev: 58316 Up: Map Next: 58476
58365: Print screen colours for room object/creature
Used by the routines at 53273 and 53885.
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:
58365 LD A,(60114) Item's vertical position, from top of playing area, in pixels
58368 ADD A,18 Add an offset to avoid top border
58370 AND 248 Filter out bits 0-2 (values 0-7) as attributes are in character (8-pixel) increments
58372 ADD A,A Double the value
58373 LD L,A Store calculated value in low byte of display attribute address
58374 SBC A,A If the earlier ADD has caused a carry, we're into the second third of the screen attribute display
58375 LD H,A ...Adjust the high byte accordingly
58376 ADD HL,HL
Vertical character row (left of screen) is now identified. Next consider horizontal position.
58377 LD A,(60115) Item's horizontal screen position, in pixels
58380 ADD A,9 Adjust/increment base position. This value isn't quite right - see Bugs - Attribute bleed on left of screen
58382 RRA Divide by 8 to get character square from pixel
58383 RRA
58384 RRA
58385 AND 31 Attribute lines are 0-31 so only need to keep these bits
58387 ADD A,L And add it into the attribute address low byte
58388 LD L,A
58389 LD A,88 High byte of attribute display address is %01010000, so add this into the high byte of the address
58391 ADD A,H
58392 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 60374 and 60390 identify the series of attributes to use for colouring each of these respectively.
58393 LD A,(60227) Get item graphic type
58396 CP 0 0 = item no longer present, i.e. destroyed creature
58398 JR Z,58404
58400 CP 3 3 = creature
58402 JR NZ,58409
58404 LD DE,60374 Colour pattern address = 60374 for creature/destroyed creature
58407 JR 58412
58409 LD DE,60390 Colour pattern address = 60390 for any other item
58412 LD A,(DE) First byte of set is number of total data bytes in set - either 15 or 9
58413 LD (60103),A Store as counter
58416 INC DE Move to the first byte in the data set
Colouring loop:
58417 LD A,(DE) Get the byte
58418 INC DE
58419 LD C,A Store in C register
58420 RLA Shift bit 7 into carry
58421 SBC A,A And subtract
58422 LD B,A This will result in 0 (value will be added) or 255 (-1 = value subtracted) in the B register
58423 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).
58424 LD A,L Get attribute column on screen (0-31)
58425 AND 31 Only need values 0-31
58427 SUB 2 Can't draw on left/right border, so check screen column number is between 2 and 29 (inclusive)
58429 CP 28 ...A subtraction of 2 and then comparing against a value of 28
58431 JR NC,58466 ...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
58433 LD A,L Border check OK. Get low byte of screen attribute address
58434 CP 64 If attribute low byte address is 64 or less...
58436 LD A,H (High byte of screen attribute address)
58437 JR NC,58443
58439 CP 88 ...and high byte = 88, attribute display address is in the top third and the top two lines (border) of the screen
58441 JR Z,58466 If so, skip and don't print any colour here
58443 SUB 88 High byte > 88 so we're past the top third
58445 CP 2 Check if we're into the bottom third of the screen
58447 JR NC,58466 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:
58449 LD A,(60111) Check DRAW/ERASE flag
58452 CP 0
58454 JR Z,58462
58456 LD A,(60072) It's DRAW (1) - so get graphic's attribute colour byte
58459 LD (HL),A ...and put on screen
58460 JR 58466
58462 LD A,(60073) It's ERASE (0) so get room's attribute colour byte
58465 LD (HL),A ...and put on screen
Repeat loop counter:
58466 LD A,(60103) Get the counter
58469 DEC A Decrement
58470 LD (60103),A ...and re-store
58473 JR NZ,58417 Continue printing attributes for the rest of the graphic
58475 RET
Prev: 58316 Up: Map Next: 58476