Prev: 66F9 Up: Map Next: 672D
6700: Fill New Attribute Column
Fills the edge column which has been newly placed on the screen.
FillNewAttributeColumn 6700 LD DE,$7802 DE=7802.
6703 LD B,$10 Set a counter in B to process 10 rows.
FillNewAttributeColumn_Loop 6705 LD A,(DE) Read the terrain data into A.
6706 INC E Move to the next column of terrain data.
6707 LD C,$04 Set the default colour in C to GREEN.
6709 CP $0F Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 0F or higher than 90.
670B JR C,SetNewAttributeColumn_Colour
670D CP $90
670F JR NC,SetNewAttributeColumn_Colour
6711 INC C Increment the colour byte in C by one (to CYAN).
6712 CP $3D Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 3D.
6714 JR C,SetNewAttributeColumn_Colour
6716 INC C Increment the colour byte in C by one (to YELLOW).
6717 CP $51 Jump to SetNewAttributeColumn_Colour if #the terrain byte is lower than 51.
6719 JR C,SetNewAttributeColumn_Colour
671B LD C,$02 Set the colour in C to RED.
671D CP $6F Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 6F.
671F JR C,SetNewAttributeColumn_Colour
6721 INC C Increment the colour byte in C by one (to MAGENTA).
SetNewAttributeColumn_Colour 6722 LD (HL),C Write the attribute byte in C to the attribute buffer pointer.
Move down to the next row in the same column.
This is quite clever, and very subtle. It's probably easier here to show examples:
Input in HL +20 Bytes
581F 583F
583F 585F
58DF 58FF
58FF 591F
From a quick glance, the following code looks pretty straight-forward, just a little strange: L = L + 20 then H = H + carry - L.
The cleverness here is with the carry flag and the ZX Spectrum attribute buffer layout.
When adding 20 to L any overflow past FF causes the carry flag to be set and this moves into the next page of attribute memory. The SUB L instruction then removes the low byte from the high byte calculation, leaving just the original high byte + the carry flag.
6723 LD A,$20 L+=20 to move down one position.
6725 ADD A,L
6726 LD L,A
6727 ADC A,H Add the carry to H.
6728 SUB L
6729 LD H,A
672A DJNZ FillNewAttributeColumn_Loop Decrease the row counter by one and loop back to FillNewAttributeColumn_Loop until all the rows have been processed.
672C RET Return.
Prev: 66F9 Up: Map Next: 672D