|  | Routines | 
| Prev: DFB2 | Up: Map | Next: E0E2 | 
| 
Used by the routine at Game_Initialisation.
 
 | ||||||||||||||||||||||||||
| 
IX will point to one of:  
 | ||||||||||||||||||||||||||
| GeneratePicture | E004 | LD HL,$A0E3 | HL=Buffer_Image. | |||||||||||||||||||||||
| 
Clear down the buffer ready for the new image to be generated.
 | ||||||||||||||||||||||||||
| E007 | LD BC,$0B40 | BC=0B40. | ||||||||||||||||||||||||
| E00A | LD (HL),$00 | Write 00 to *HL. | ||||||||||||||||||||||||
| E00C | PUSH HL | DE=Buffer_Image+01 (using the stack). | ||||||||||||||||||||||||
| E00D | POP DE | |||||||||||||||||||||||||
| E00E | INC DE | |||||||||||||||||||||||||
| E00F | LDIR | Clear 0B40 bytes of data in Buffer_Image. | ||||||||||||||||||||||||
| E011 | LD A,$80 | Write 80 to *Line_Counter. | ||||||||||||||||||||||||
| E013 | LD ($E0DE),A | |||||||||||||||||||||||||
| GeneratePicture_Loop | E016 | LD A,$80 | A=80-*Line_Counter. | |||||||||||||||||||||||
| E018 | LD HL,$E0DE | |||||||||||||||||||||||||
| E01B | SUB (HL) | |||||||||||||||||||||||||
| E01C | LD B,$14 | B=14. | ||||||||||||||||||||||||
| E01E | LD D,$00 | Load A into DE. | ||||||||||||||||||||||||
| E020 | LD E,A | |||||||||||||||||||||||||
| E021 | LD HL,$A0E3 | Starting from the first address at Buffer_Image, stored in HL... | ||||||||||||||||||||||||
| GeneratePicture_CurrentLine_Loop | E024 | ADD HL,DE | Keep adding DE to HL. | |||||||||||||||||||||||
| E025 | DJNZ GeneratePicture_CurrentLine_Loop | Decrease counter by one and loop back to GeneratePicture_CurrentLine_Loop until counter is zero. | ||||||||||||||||||||||||
| E027 | LD ($E0E0),HL | Write HL to *Buffer_Position. | ||||||||||||||||||||||||
| E02A | LD A,(IX+$00) | Fetch a byte from the level graphics data pointer. | ||||||||||||||||||||||||
| E02D | INC IX | Increment the level graphics data pointer by one. | ||||||||||||||||||||||||
| E02F | CP $C9 | Jump to ProcessCompressedImageData if A is equal to C9. | ||||||||||||||||||||||||
| E031 | JR Z,ProcessCompressedImageData | |||||||||||||||||||||||||
| E033 | CP $CA | Jump to GeneratePicture_RLE_Decoding if A is equal to CA. | ||||||||||||||||||||||||
| E035 | JR Z,GeneratePicture_RLE_Decoding | |||||||||||||||||||||||||
| E037 | PUSH IX | Copy the level graphics data pointer into DE (using the stack). | ||||||||||||||||||||||||
| E039 | POP DE | |||||||||||||||||||||||||
| E03A | EX DE,HL | Exchange the DE and HL registers. | ||||||||||||||||||||||||
| E03B | LD BC,$0014 | Copy 0014 bytes of data from HL to DE. | ||||||||||||||||||||||||
| E03E | LDIR | |||||||||||||||||||||||||
| E040 | PUSH HL | Update the level graphics data pointer in IX with the progress made from HL (using the stack). | ||||||||||||||||||||||||
| E041 | POP IX | |||||||||||||||||||||||||
| E043 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
| 
Run-length decoding.
 | ||||||||||||||||||||||||||
| GeneratePicture_RLE_Decoding | E045 | PUSH IX | Copy the level graphics data pointer into DE (using the stack). | |||||||||||||||||||||||
| E047 | POP DE | |||||||||||||||||||||||||
| GeneratePicture_RLE_NormalData | E048 | LD A,(DE) | Fetch a byte from the level graphics data pointer in DE. | |||||||||||||||||||||||
| E049 | CP $00 | Jump to GeneratePicture_RLE_RepeatZero if the byte is 00. | ||||||||||||||||||||||||
| E04B | JR Z,GeneratePicture_RLE_RepeatZero | |||||||||||||||||||||||||
| E04D | LD (HL),A | Else, write the byte to the image buffer. | ||||||||||||||||||||||||
| E04E | INC HL | Increment the image buffer pointer by one. | ||||||||||||||||||||||||
| E04F | INC DE | Increment the level graphics data pointer (in DE) by one. | ||||||||||||||||||||||||
| E050 | JR GeneratePicture_RLE_NormalData | Jump to GeneratePicture_RLE_NormalData. | ||||||||||||||||||||||||
| GeneratePicture_RLE_RepeatZero | E052 | INC DE | Increment the level graphics data pointer (in DE) by one. | |||||||||||||||||||||||
| E053 | LD A,(DE) | Fetch a byte from the level graphics data pointer in DE. | ||||||||||||||||||||||||
| E054 | CP $00 | Jump to GeneratePicture_RLE_Next if the byte is 00. | ||||||||||||||||||||||||
| E056 | JR Z,GeneratePicture_RLE_Next | |||||||||||||||||||||||||
| E058 | LD B,A | Copy the fetched byte into B as a repeat counter | ||||||||||||||||||||||||
| E059 | XOR A | Write 00 to the image buffer. | ||||||||||||||||||||||||
| GeneratePicture_RLE_RepeatZero_Loop | E05A | LD (HL),A | ||||||||||||||||||||||||
| E05B | INC HL | Increment the image buffer pointer by one. | ||||||||||||||||||||||||
| E05C | DJNZ GeneratePicture_RLE_RepeatZero_Loop | Decrease the byte repeat counter by one and loop back to GeneratePicture_RLE_RepeatZero_Loop until the counter is zero. | ||||||||||||||||||||||||
| E05E | INC DE | Increment the level graphics data pointer (in DE) by one. | ||||||||||||||||||||||||
| E05F | JR GeneratePicture_RLE_NormalData | Jump to GeneratePicture_RLE_NormalData. | ||||||||||||||||||||||||
| GeneratePicture_RLE_Next | E061 | INC DE | Increment the level graphics data pointer (in DE) by one. | |||||||||||||||||||||||
| E062 | PUSH DE | Update the level graphics data pointer in IX with the progress made from DE (using the stack). | ||||||||||||||||||||||||
| E063 | POP IX | |||||||||||||||||||||||||
| E065 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
| 
Second
 | ||||||||||||||||||||||||||
| ProcessCompressedImageData | E067 | LD B,(IX+$01) | Load the repeat count into B. | |||||||||||||||||||||||
| E06A | LD A,(IX+$00) | Write the operation code to *Operation_Code. | ||||||||||||||||||||||||
| E06D | LD ($E0DF),A | |||||||||||||||||||||||||
| ProcessOperationBlock_Loop | E070 | PUSH BC | Stash the repeat count on the stack. | |||||||||||||||||||||||
| E071 | LD A,($E0DF) | Load the operation code into A. | ||||||||||||||||||||||||
| E074 | CP $C9 | Jump to ProcessCompressedImageData_Next if the operation code is C9. | ||||||||||||||||||||||||
| E076 | JR Z,ProcessCompressedImageData_Next | |||||||||||||||||||||||||
| E078 | CP $CA | Jump to ProcessCompressedImageData_Next if the operation code is CA. | ||||||||||||||||||||||||
| E07A | JR Z,ProcessCompressedImageData_Next | |||||||||||||||||||||||||
| E07C | CP $CB | Jump to ProcessBitOperation if the operation code is not CB. | ||||||||||||||||||||||||
| E07E | JR NZ,ProcessBitOperation | |||||||||||||||||||||||||
| ProcessCompressedImageData_Next | E080 | POP BC | Restore the repeat count from the stack. | |||||||||||||||||||||||
| E081 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
| ProcessBitOperation | E083 | AND %11111000 | Mask to get the byte offset within the current line, store this in D. | |||||||||||||||||||||||
| E085 | LD D,A | |||||||||||||||||||||||||
| E086 | RRCA | Divide the byte offset by 08 to get the pixel offset, store this in E. | ||||||||||||||||||||||||
| E087 | RRCA | |||||||||||||||||||||||||
| E088 | RRCA | |||||||||||||||||||||||||
| E089 | LD E,A | |||||||||||||||||||||||||
| E08A | LD A,($E0DF) | Reload the operation code into A. | ||||||||||||||||||||||||
| E08D | SUB D | Subtract to calculate the number of bits to modify. | ||||||||||||||||||||||||
| E08E | LD D,$00 | D=00. | ||||||||||||||||||||||||
| E090 | ADD HL,DE | HL+=DE. | ||||||||||||||||||||||||
| E091 | LD B,A | Set the bit count in B. | ||||||||||||||||||||||||
| E092 | INC B | Adjust B for the loop. | ||||||||||||||||||||||||
| E093 | LD A,(HL) | A=*HL. | ||||||||||||||||||||||||
| E094 | AND A | Clear the carry flag. | ||||||||||||||||||||||||
| E095 | PUSH BC | Stash the bit count on the stack. | ||||||||||||||||||||||||
| RotateBitsLeft_Loop | E096 | RLA | Rotate left, moving bits one position to the left. | |||||||||||||||||||||||
| E097 | DJNZ RotateBitsLeft_Loop | Decrease counter by one and loop back to RotateBitsLeft_Loop until counter is zero. | ||||||||||||||||||||||||
| E099 | SCF | Set the carry flag. | ||||||||||||||||||||||||
| E09A | POP BC | Restore the bit count from the stack. | ||||||||||||||||||||||||
| RotateBitsRight_Loop | E09B | RRA | Rotate right, moving bits back and inserting 01. | |||||||||||||||||||||||
| E09C | DJNZ RotateBitsRight_Loop | Decrease the bit count by one and loop back to RotateBitsRight_Loop until all bits have been processed. | ||||||||||||||||||||||||
| E09E | LD (HL),A | Write A to *HL. | ||||||||||||||||||||||||
| E09F | LD HL,$E0DF | Increment *Operation_Code by one. | ||||||||||||||||||||||||
| E0A2 | INC (HL) | |||||||||||||||||||||||||
| E0A3 | LD HL,($E0E0) | HL=*Buffer_Position. | ||||||||||||||||||||||||
| E0A6 | POP BC | Restore the repeat count from the stack. | ||||||||||||||||||||||||
| E0A7 | DJNZ ProcessOperationBlock_Loop | Decrease the repeat count by one and loop back to ProcessOperationBlock_Loop until all operations are done. | ||||||||||||||||||||||||
| E0A9 | INC IX | Increment IX by two. | ||||||||||||||||||||||||
| E0AB | INC IX | |||||||||||||||||||||||||
| E0AD | JP ProcessCompressedImageData | Jump to ProcessCompressedImageData. | ||||||||||||||||||||||||
| 
Has all the image been decompressed now? If not, loop back again.
 | ||||||||||||||||||||||||||
| GeneratePicture_Next | E0B0 | LD HL,$E0DE | HL=Line_Counter. | |||||||||||||||||||||||
| E0B3 | DEC (HL) | Decrease *HL by one. | ||||||||||||||||||||||||
| E0B4 | JP NZ,GeneratePicture_Loop | Jump to GeneratePicture_Loop until *HL is zero. | ||||||||||||||||||||||||
| E0B7 | INC IX | Move IX to the start of the attribute data. | ||||||||||||||||||||||||
| E0B9 | LD B,$10 | Set a counter in B to process 10 rows of attribute data. | ||||||||||||||||||||||||
| E0BB | LD HL,$AAE3 | Store the start of Buffer_Image_Attributes in HL. | ||||||||||||||||||||||||
| GeneratePicture_Attributes_Loop | E0BE | PUSH BC | Stash the attribute row counter and the image attributes buffer pointer on the stack. | |||||||||||||||||||||||
| E0BF | PUSH HL | |||||||||||||||||||||||||
| E0C0 | LD A,$00 | Initialise the column counter in A. | ||||||||||||||||||||||||
| GeneratePicture_Attribute_Row | E0C2 | LD C,(IX+$00) | Load the attribute value into C. | |||||||||||||||||||||||
| E0C5 | INC IX | Load the repeat length into B. | ||||||||||||||||||||||||
| E0C7 | LD B,(IX+$00) | |||||||||||||||||||||||||
| E0CA | INC IX | Move IX to the next attribute/ repeat length pair. | ||||||||||||||||||||||||
| E0CC | ADD A,B | Add the repeat length to the column counter. | ||||||||||||||||||||||||
| GeneratePicture_Attribute_Run | E0CD | LD (HL),C | Write the attribute to the image attributes buffer. | |||||||||||||||||||||||
| E0CE | INC HL | Increment the image attributes buffer pointer by one. | ||||||||||||||||||||||||
| E0CF | DJNZ GeneratePicture_Attribute_Run | Decrease the repeat counter by one and loop back to GeneratePicture_Attribute_Run until counter is zero. | ||||||||||||||||||||||||
| E0D1 | CP $14 | Jump to GeneratePicture_Attribute_Row if 14 columns have been processed. | ||||||||||||||||||||||||
| E0D3 | JR NZ,GeneratePicture_Attribute_Row | |||||||||||||||||||||||||
| E0D5 | POP HL | Restore the start of the current attribute row from the stack. | ||||||||||||||||||||||||
| E0D6 | LD BC,$0014 | Move HL to the next row in the attribute buffer. | ||||||||||||||||||||||||
| E0D9 | ADD HL,BC | |||||||||||||||||||||||||
| E0DA | POP BC | Restore the attribute row counter from the stack. | ||||||||||||||||||||||||
| E0DB | DJNZ GeneratePicture_Attributes_Loop | Decrease the attribute row counter by one and loop back to GeneratePicture_Attributes_Loop until counter is zero. | ||||||||||||||||||||||||
| E0DD | RET | Return. | ||||||||||||||||||||||||
| 
Variables specifically for this routine.
 | ||||||||||||||||||||||||||
| Line_Counter | E0DE | DEFB $00 | ||||||||||||||||||||||||
| Operation_Code | E0DF | DEFB $00 | ||||||||||||||||||||||||
| Buffer_Position | E0E0 | DEFW $0000 | ||||||||||||||||||||||||
| Prev: DFB2 | Up: Map | Next: E0E2 |