Prev: D5B0 Up: Map Next: D609
D5B2: Unpack Screen Data
Used by the routine at DemoEntryPoint.
Input
HL Pointer to image data
Start by clearing the screen and attribute buffers.
UnpackScreenData D5B2 PUSH HL Stash the pointer to the image data on the stack temporarily.
D5B3 LD HL,$5800 HL=5800 (attribute buffer location).
D5B6 LD DE,$5801 DE=5801.
D5B9 LD (HL),$00 Write 00 to *HL.
D5BB LD BC,$02FF Copy 00 to 02FF more bytes, filling the whole of the attribute buffer.
D5BE LDIR
D5C0 POP HL Restore the pointer to the image data from the stack.
D5C1 LD DE,$4000 Initialise the target screen buffer location (4000) in DE.
The main loop
UnpackScreenData_Loop D5C4 LD A,(HL) Jump to Handler_Zeroes if *HL is equal to 00.
D5C5 CP $00
D5C7 JR Z,Handler_Zeroes
D5C9 LD (DE),A Write A to *DE.
D5CA INC HL Increment HL by one.
D5CB INC DE Increment DE by one.
D5CC JR UnpackScreenData_Loop Jump to UnpackScreenData_Loop.
Handle multiple zeroes.
Handler_Zeroes D5CE INC HL Move the pointer to the length byte.
D5CF LD A,(HL) Load the length into A.
D5D0 CP $00 Jump to Handler_Attributes if *A is equal to 00.
D5D2 JR Z,Handler_Attributes
D5D4 LD B,A Store the length in B.
D5D5 XOR A Set A to 00 the value to write.
Write the zeroes to the screen buffer.
Write_Zeroes D5D6 LD (DE),A Write 00 to the screen buffer location held by *DE.
D5D7 INC DE Increment the screen buffer pointer by one.
D5D8 DJNZ Write_Zeroes Decrease counter by one and loop back to Write_Zeroes until counter is zero.
D5DA INC HL Increment HL by one.
D5DB JR UnpackScreenData_Loop Jump to UnpackScreenData_Loop.
Process attributes.
Handler_Attributes D5DD INC HL Increment HL by one.
D5DE PUSH HL IX=HL (using the stack).
D5DF POP IX
D5E1 LD HL,$5800 HL=5800 (attribute buffer location).
D5E4 LD B,$18 Initialise B to 18 (number of character rows).
Handler_Attributes_Loop D5E6 PUSH BC Stash the row counter and attribute buffer pointer on the stack.
D5E7 PUSH HL
D5E8 LD A,$00 Initialise the column counter in A to 00.
Process the attribute bytes in a row.
UnpackScreenData_ProcessAttributesRow D5EA LD C,(IX+$00) C=attribute value.
D5ED INC IX
D5EF LD B,(IX+$00) B=run length.
D5F2 INC IX
D5F4 ADD A,B A=run length plus the column counter.
Write the run of attributes.
UnpackScreenData_WriteAttributes_Loop D5F5 LD (HL),C Write attribute byte to the attribute buffer.
D5F6 INC HL Increment the attribute pointer by one.
D5F7 DJNZ UnpackScreenData_WriteAttributes_Loop Decrease the length counter by one and loop back to UnpackScreenData_WriteAttributes_Loop until counter is zero.
D5F9 CP $20 Jump to UnpackScreenData_ProcessAttributesRow if A is not equal to 20.
D5FB JR NZ,UnpackScreenData_ProcessAttributesRow
D5FD POP HL Restore the start of the row into HL from the stack.
D5FE LD BC,$0020 Move HL 0020 bytes to point to the next row.
D601 ADD HL,BC
D602 POP BC Restore the row counter from the stack.
D603 DJNZ Handler_Attributes_Loop Decrease the row counter by one and loop back to Handler_Attributes_Loop until all the rows have been processed.
D605 PUSH IX BC=current position in attribute data (using the stack).
D607 POP BC
D608 RET Return.
Prev: D5B0 Up: Map Next: D609