Prev: 26361 Up: Map Next: 26413
26368: Fill New Attribute Column
Fills the edge column which has been newly placed on the screen.
FillNewAttributeColumn 26368 LD DE,30722 DE=30722.
26371 LD B,16 Set a counter in B to process 16 rows.
FillNewAttributeColumn_Loop 26373 LD A,(DE) Read the terrain data into A.
26374 INC E Move to the next column of terrain data.
26375 LD C,4 Set the default colour in C to GREEN.
26377 CP 15 Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 15 or higher than 144.
26379 JR C,SetNewAttributeColumn_Colour
26381 CP 144
26383 JR NC,SetNewAttributeColumn_Colour
26385 INC C Increment the colour byte in C by one (to CYAN).
26386 CP 61 Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 61.
26388 JR C,SetNewAttributeColumn_Colour
26390 INC C Increment the colour byte in C by one (to YELLOW).
26391 CP 81 Jump to SetNewAttributeColumn_Colour if #the terrain byte is lower than 81.
26393 JR C,SetNewAttributeColumn_Colour
26395 LD C,2 Set the colour in C to RED.
26397 CP 111 Jump to SetNewAttributeColumn_Colour if the terrain byte is lower than 111.
26399 JR C,SetNewAttributeColumn_Colour
26401 INC C Increment the colour byte in C by one (to MAGENTA).
SetNewAttributeColumn_Colour 26402 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 +32 Bytes
22559 22591
22591 22623
22751 22783
22783 22815
From a quick glance, the following code looks pretty straight-forward, just a little strange: L = L + 32 then H = H + carry - L.
The cleverness here is with the carry flag and the ZX Spectrum attribute buffer layout.
When adding 32 to L any overflow past 255 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.
26403 LD A,32 L+=32 to move down one position.
26405 ADD A,L
26406 LD L,A
26407 ADC A,H Add the carry to H.
26408 SUB L
26409 LD H,A
26410 DJNZ FillNewAttributeColumn_Loop Decrease the row counter by one and loop back to FillNewAttributeColumn_Loop until all the rows have been processed.
26412 RET Return.
Prev: 26361 Up: Map Next: 26413