Prev: D6B4 Up: Map Next: D763
D70C: Unpack Screen Data
Used by the routine at Game_Loop.
Input
HL Pointer to image data
Start by clearing the screen and attribute buffers.
UnpackScreenData D70C PUSH HL Stash the pointer to the image data on the stack temporarily.
D70D LD HL,$5800 HL=5800 (attribute buffer location).
D710 LD DE,$5801 DE=5801.
D713 LD (HL),$00 Write 00 to *HL.
D715 LD BC,$02FF Copy 00 to 02FF more bytes, filling the whole of the attribute buffer.
D718 LDIR
D71A POP HL Restore the pointer to the image data from the stack.
D71B LD DE,$4000 Initialise the target screen buffer location (4000) in DE.
The main loop
UnpackScreenData_Loop D71E LD A,(HL) Jump to Handler_Zeroes if *HL is equal to 00.
D71F CP $00
D721 JR Z,Handler_Zeroes
D723 LD (DE),A Write A to *DE.
D724 INC HL Increment HL by one.
D725 INC DE Increment DE by one.
D726 JR UnpackScreenData_Loop Jump to UnpackScreenData_Loop.
Handle multiple zeroes.
Handler_Zeroes D728 INC HL Move the pointer to the length byte.
D729 LD A,(HL) Load the length into A.
D72A CP $00 Jump to Handler_Attributes if *A is equal to 00.
D72C JR Z,Handler_Attributes
D72E LD B,A Store the length in B.
D72F XOR A Set A to 00 the value to write.
Write the zeroes to the screen buffer.
Write_Zeroes D730 LD (DE),A Write 00 to the screen buffer location held by *DE.
D731 INC DE Increment the screen buffer pointer by one.
D732 DJNZ Write_Zeroes Decrease counter by one and loop back to Write_Zeroes until counter is zero.
D734 INC HL Increment HL by one.
D735 JR UnpackScreenData_Loop Jump to UnpackScreenData_Loop.
Process attributes.
Handler_Attributes D737 INC HL Increment HL by one.
D738 PUSH HL IX=HL (using the stack).
D739 POP IX
D73B LD HL,$5800 HL=5800 (attribute buffer location).
D73E LD B,$18 Initialise B to 18 (number of character rows).
Handler_Attributes_Loop D740 PUSH BC Stash the row counter and attribute buffer pointer on the stack.
D741 PUSH HL
D742 LD A,$00 Initialise the column counter in A to 00.
Process the attribute bytes in a row.
UnpackScreenData_ProcessAttributesRow D744 LD C,(IX+$00) C=attribute value.
D747 INC IX
D749 LD B,(IX+$00) B=run length.
D74C INC IX
D74E ADD A,B A=run length plus the column counter.
Write the run of attributes.
UnpackScreenData_WriteAttributes_Loop D74F LD (HL),C Write attribute byte to the attribute buffer.
D750 INC HL Increment the attribute pointer by one.
D751 DJNZ UnpackScreenData_WriteAttributes_Loop Decrease the length counter by one and loop back to UnpackScreenData_WriteAttributes_Loop until counter is zero.
D753 CP $20 Jump to UnpackScreenData_ProcessAttributesRow if A is not equal to 20.
D755 JR NZ,UnpackScreenData_ProcessAttributesRow
D757 POP HL Restore the start of the row into HL from the stack.
D758 LD BC,$0020 Move HL 0020 bytes to point to the next row.
D75B ADD HL,BC
D75C POP BC Restore the row counter from the stack.
D75D DJNZ Handler_Attributes_Loop Decrease the row counter by one and loop back to Handler_Attributes_Loop until all the rows have been processed.
D75F PUSH IX BC=current position in attribute data (using the stack).
D761 POP BC
D762 RET Return.
Prev: D6B4 Up: Map Next: D763