Prev: CF36 Up: Map Next: D04F
CF38: Colour the attribute cells under a landscape piece
Used by the routine at after_step_drawn.
Called by after_step_drawn after a piece is drawn. The landscape takes its colour from its attribute cells, a colour for the upper tiles (map_row_colour) and another for the lower ones (map_row_colour_next), both set from the level's pair of colours (start_landscape) by set_landscape_colours (the deeper colour from map row $0C down: the caverns). Where the surface meets the caverns (map row $0B in a lower tile, or $0C in an upper one) the deeper colour is used, or the upper one for a piece starting above y $67.
For each step of the piece it colours a column of cells (the rows per step, attribute_rows) one, two or three cells wide (the column step plus one: colour_one_cell, colour_two_cells, colour_three_cells), then moves up by the rise and across by the column step; a flat piece colours three cells wide and as deep as its graphic (about two cells). Only cells inside the play area (in_play_area) and its columns 1-28 are coloured. A piece ending in the special end piece $13 on the right gets one more column when the scroll is not on a byte boundary.
Nothing is coloured while the landscape is being built after a restart (map_rebuild), nor for a piece with no columns drawn.
Input
IX The piece state (current_piece): +0 +1 the screen x and y of its first column, +2 the number of steps drawn, +3 the direction
colour_piece CF38 LD A,(map_rebuild) Building after a restart, or nothing drawn: no colour.
CF3B AND A
CF3C RET NZ
CF3D LD A,(IX+$01)
CF40 AND A
CF41 RET Z
CF42 LD A,(IX+$02)
CF45 AND A
CF46 RET Z
CF47 LD A,(piece_dx_copy) A wall: no column step, and one byte (two cells) wide.
CF4A AND A
CF4B JR NZ,colour_piece_0
CF4D LD (piece_dcolumn),A
CF50 INC A
CF51 LD (piece_step_y),A
colour_piece_0 CF54 LD A,(piece_step_y) The width in cells.
CF57 INC A
CF58 LD C,A
CF59 LD A,(direction_flag) A piece going left starts a cell further left.
CF5C CP $FF
CF5E JR Z,colour_piece_1
CF60 LD A,(IX+$00)
CF63 SUB $02
CF65 AND $F8
CF67 LD (IX+$00),A
colour_piece_1 CF6A LD A,C The colouring routine for the width.
CF6B LD IY,colour_one_cell
CF6F CP $01
CF71 JR Z,colour_piece_2
CF73 LD IY,colour_two_cells
CF77 CP $02
CF79 JR Z,colour_piece_2
CF7B LD IY,colour_three_cells
colour_piece_2 CF7F LD A,(piece_rise) The rise in cells per step; the screen position.
CF82 SRL A
CF84 SRL A
CF86 SRL A
CF88 LD (piece_rows),A
CF8B LD L,(IX+$00)
CF8E LD H,(IX+$01)
CF91 LD A,(piece_rows) Rows to colour: the rise in cells, one more if the first row does not end on a cell boundary.
CF94 LD (attribute_rows),A
CF97 LD A,H
CF98 AND $07
CF9A XOR $07
CF9C JR Z,colour_piece_3
CF9E LD A,(attribute_rows)
CFA1 INC A
CFA2 LD (attribute_rows),A
colour_piece_3 CFA5 LD A,(IX+$03) A flat piece (direction 0 or 7):
CFA8 AND A
CFA9 JR Z,colour_piece_4
CFAB CP $07
CFAD JR NZ,colour_piece_5
colour_piece_4 CFAF LD IY,colour_three_cells three cells wide, no rise, and the cells from its y down to $0B rows below.
CFB3 XOR A
CFB4 LD (piece_rows),A
CFB7 LD A,H
CFB8 SUB $0B
CFBA LD B,A
CFBB LD A,H
CFBC OR $07
CFBE SUB B
CFBF SRL A
CFC1 SRL A
CFC3 SRL A
CFC5 LD (attribute_rows),A
colour_piece_5 CFC8 LD B,L The attribute address (an x of $F0 or more, off the right, wraps to the start of the row).
CFC9 LD A,L
CFCA CP $F0
CFCC JR C,colour_piece_6
CFCE LD L,$00
colour_piece_6 CFD0 CALL pixel_to_attribute
CFD3 LD A,B
CFD4 CP $F0
CFD6 JR C,colour_piece_7
CFD8 DEC HL
colour_piece_7 CFD9 LD A,(map_row_colour) The upper or lower colour.
CFDC LD C,A
CFDD LD A,(ground_cell)
CFE0 BIT 0,A
CFE2 JR Z,colour_piece_8
CFE4 LD A,(map_row_colour_next)
CFE7 LD C,A
colour_piece_8 CFE8 LD A,(view_row) Where the surface meets the caverns, the deeper colour, or the upper one above y $67.
CFEB CP $0B
CFED JR Z,colour_piece_9
CFEF CP $0C
CFF1 JR NZ,colour_piece_11
CFF3 LD A,(ground_cell)
CFF6 BIT 0,A
CFF8 JR NZ,colour_piece_11
CFFA JR colour_piece_10
colour_piece_9 CFFC LD A,(ground_cell)
CFFF BIT 0,A
D001 JR Z,colour_piece_11
colour_piece_10 D003 LD A,(ground_attr_below)
D006 LD C,A
D007 LD A,(box_height)
D00A CP $67
D00C JR NC,colour_piece_11
D00E LD A,(ground_attr_above)
D011 LD C,A
colour_piece_11 D012 LD DE,$0020 Each step of the piece:
D015 LD B,(IX+$02)
colour_piece_12 D018 PUSH BC a column of cells,
D019 LD A,(attribute_rows)
D01C LD B,A
D01D PUSH HL
D01E CALL jump_iy
D021 POP HL
D022 LD A,(piece_rows) up by the rise,
D025 AND A
D026 JR Z,colour_piece_14
D028 LD B,A
colour_piece_13 D029 AND A
D02A SBC HL,DE
D02C DJNZ colour_piece_13
colour_piece_14 D02E LD A,(piece_dcolumn) and across by the column step (signed).
D031 LD C,A
D032 LD B,$00
D034 BIT 7,A
D036 JR Z,colour_piece_15
D038 DEC B
colour_piece_15 D039 ADD HL,BC
D03A POP BC
D03B DJNZ colour_piece_12
D03D LD A,(piece_extra_b) The end piece $13 on the right, scrolled off a byte boundary: one more column.
D040 AND $7F
D042 CP $13
D044 RET NZ
D045 LD A,(origin_x)
D048 AND $07
D04A RET Z
D04B LD A,(attribute_rows)
D04E LD B,A
Prev: CF36 Up: Map Next: D04F