![]() |
Routines |
| Prev: 57266 | Up: Map | Next: 57570 |
|
Used by the routine at Game_Initialisation.
|
||||||||||||||||||||||||||
|
IX will point to one of:
|
||||||||||||||||||||||||||
| GeneratePicture | 57348 | LD HL,41187 | HL=Buffer_Image. | |||||||||||||||||||||||
|
Clear down the buffer ready for the new image to be generated.
|
||||||||||||||||||||||||||
| 57351 | LD BC,2880 | BC=2880. | ||||||||||||||||||||||||
| 57354 | LD (HL),0 | Write 0 to *HL. | ||||||||||||||||||||||||
| 57356 | PUSH HL | DE=Buffer_Image+1 (using the stack). | ||||||||||||||||||||||||
| 57357 | POP DE | |||||||||||||||||||||||||
| 57358 | INC DE | |||||||||||||||||||||||||
| 57359 | LDIR | Clear 2880 bytes of data in Buffer_Image. | ||||||||||||||||||||||||
| 57361 | LD A,128 | Write 128 to *Line_Counter. | ||||||||||||||||||||||||
| 57363 | LD (57566),A | |||||||||||||||||||||||||
| GeneratePicture_Loop | 57366 | LD A,128 | A=128-*Line_Counter. | |||||||||||||||||||||||
| 57368 | LD HL,57566 | |||||||||||||||||||||||||
| 57371 | SUB (HL) | |||||||||||||||||||||||||
| 57372 | LD B,20 | B=20. | ||||||||||||||||||||||||
| 57374 | LD D,0 | Load A into DE. | ||||||||||||||||||||||||
| 57376 | LD E,A | |||||||||||||||||||||||||
| 57377 | LD HL,41187 | Starting from the first address at Buffer_Image, stored in HL... | ||||||||||||||||||||||||
| GeneratePicture_CurrentLine_Loop | 57380 | ADD HL,DE | Keep adding DE to HL. | |||||||||||||||||||||||
| 57381 | DJNZ GeneratePicture_CurrentLine_Loop | Decrease counter by one and loop back to GeneratePicture_CurrentLine_Loop until counter is zero. | ||||||||||||||||||||||||
| 57383 | LD (57568),HL | Write HL to *Buffer_Position. | ||||||||||||||||||||||||
| 57386 | LD A,(IX+0) | Fetch a byte from the level graphics data pointer. | ||||||||||||||||||||||||
| 57389 | INC IX | Increment the level graphics data pointer by one. | ||||||||||||||||||||||||
| 57391 | CP 201 | Jump to ProcessCompressedImageData if A is equal to 201. | ||||||||||||||||||||||||
| 57393 | JR Z,ProcessCompressedImageData | |||||||||||||||||||||||||
| 57395 | CP 202 | Jump to GeneratePicture_RLE_Decoding if A is equal to 202. | ||||||||||||||||||||||||
| 57397 | JR Z,GeneratePicture_RLE_Decoding | |||||||||||||||||||||||||
| 57399 | PUSH IX | Copy the level graphics data pointer into DE (using the stack). | ||||||||||||||||||||||||
| 57401 | POP DE | |||||||||||||||||||||||||
| 57402 | EX DE,HL | Exchange the DE and HL registers. | ||||||||||||||||||||||||
| 57403 | LD BC,20 | Copy 0020 bytes of data from HL to DE. | ||||||||||||||||||||||||
| 57406 | LDIR | |||||||||||||||||||||||||
| 57408 | PUSH HL | Update the level graphics data pointer in IX with the progress made from HL (using the stack). | ||||||||||||||||||||||||
| 57409 | POP IX | |||||||||||||||||||||||||
| 57411 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
|
Run-length decoding.
|
||||||||||||||||||||||||||
| GeneratePicture_RLE_Decoding | 57413 | PUSH IX | Copy the level graphics data pointer into DE (using the stack). | |||||||||||||||||||||||
| 57415 | POP DE | |||||||||||||||||||||||||
| GeneratePicture_RLE_NormalData | 57416 | LD A,(DE) | Fetch a byte from the level graphics data pointer in DE. | |||||||||||||||||||||||
| 57417 | CP 0 | Jump to GeneratePicture_RLE_RepeatZero if the byte is 0. | ||||||||||||||||||||||||
| 57419 | JR Z,GeneratePicture_RLE_RepeatZero | |||||||||||||||||||||||||
| 57421 | LD (HL),A | Else, write the byte to the image buffer. | ||||||||||||||||||||||||
| 57422 | INC HL | Increment the image buffer pointer by one. | ||||||||||||||||||||||||
| 57423 | INC DE | Increment the level graphics data pointer (in DE) by one. | ||||||||||||||||||||||||
| 57424 | JR GeneratePicture_RLE_NormalData | Jump to GeneratePicture_RLE_NormalData. | ||||||||||||||||||||||||
| GeneratePicture_RLE_RepeatZero | 57426 | INC DE | Increment the level graphics data pointer (in DE) by one. | |||||||||||||||||||||||
| 57427 | LD A,(DE) | Fetch a byte from the level graphics data pointer in DE. | ||||||||||||||||||||||||
| 57428 | CP 0 | Jump to GeneratePicture_RLE_Next if the byte is 0. | ||||||||||||||||||||||||
| 57430 | JR Z,GeneratePicture_RLE_Next | |||||||||||||||||||||||||
| 57432 | LD B,A | Copy the fetched byte into B as a repeat counter | ||||||||||||||||||||||||
| 57433 | XOR A | Write 0 to the image buffer. | ||||||||||||||||||||||||
| GeneratePicture_RLE_RepeatZero_Loop | 57434 | LD (HL),A | ||||||||||||||||||||||||
| 57435 | INC HL | Increment the image buffer pointer by one. | ||||||||||||||||||||||||
| 57436 | 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. | ||||||||||||||||||||||||
| 57438 | INC DE | Increment the level graphics data pointer (in DE) by one. | ||||||||||||||||||||||||
| 57439 | JR GeneratePicture_RLE_NormalData | Jump to GeneratePicture_RLE_NormalData. | ||||||||||||||||||||||||
| GeneratePicture_RLE_Next | 57441 | INC DE | Increment the level graphics data pointer (in DE) by one. | |||||||||||||||||||||||
| 57442 | PUSH DE | Update the level graphics data pointer in IX with the progress made from DE (using the stack). | ||||||||||||||||||||||||
| 57443 | POP IX | |||||||||||||||||||||||||
| 57445 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
|
Second
|
||||||||||||||||||||||||||
| ProcessCompressedImageData | 57447 | LD B,(IX+1) | Load the repeat count into B. | |||||||||||||||||||||||
| 57450 | LD A,(IX+0) | Write the operation code to *Operation_Code. | ||||||||||||||||||||||||
| 57453 | LD (57567),A | |||||||||||||||||||||||||
| ProcessOperationBlock_Loop | 57456 | PUSH BC | Stash the repeat count on the stack. | |||||||||||||||||||||||
| 57457 | LD A,(57567) | Load the operation code into A. | ||||||||||||||||||||||||
| 57460 | CP 201 | Jump to ProcessCompressedImageData_Next if the operation code is 201. | ||||||||||||||||||||||||
| 57462 | JR Z,ProcessCompressedImageData_Next | |||||||||||||||||||||||||
| 57464 | CP 202 | Jump to ProcessCompressedImageData_Next if the operation code is 202. | ||||||||||||||||||||||||
| 57466 | JR Z,ProcessCompressedImageData_Next | |||||||||||||||||||||||||
| 57468 | CP 203 | Jump to ProcessBitOperation if the operation code is not 203. | ||||||||||||||||||||||||
| 57470 | JR NZ,ProcessBitOperation | |||||||||||||||||||||||||
| ProcessCompressedImageData_Next | 57472 | POP BC | Restore the repeat count from the stack. | |||||||||||||||||||||||
| 57473 | JR GeneratePicture_Next | Jump to GeneratePicture_Next. | ||||||||||||||||||||||||
| ProcessBitOperation | 57475 | AND %11111000 | Mask to get the byte offset within the current line, store this in D. | |||||||||||||||||||||||
| 57477 | LD D,A | |||||||||||||||||||||||||
| 57478 | RRCA | Divide the byte offset by 8 to get the pixel offset, store this in E. | ||||||||||||||||||||||||
| 57479 | RRCA | |||||||||||||||||||||||||
| 57480 | RRCA | |||||||||||||||||||||||||
| 57481 | LD E,A | |||||||||||||||||||||||||
| 57482 | LD A,(57567) | Reload the operation code into A. | ||||||||||||||||||||||||
| 57485 | SUB D | Subtract to calculate the number of bits to modify. | ||||||||||||||||||||||||
| 57486 | LD D,0 | D=0. | ||||||||||||||||||||||||
| 57488 | ADD HL,DE | HL+=DE. | ||||||||||||||||||||||||
| 57489 | LD B,A | Set the bit count in B. | ||||||||||||||||||||||||
| 57490 | INC B | Adjust B for the loop. | ||||||||||||||||||||||||
| 57491 | LD A,(HL) | A=*HL. | ||||||||||||||||||||||||
| 57492 | AND A | Clear the carry flag. | ||||||||||||||||||||||||
| 57493 | PUSH BC | Stash the bit count on the stack. | ||||||||||||||||||||||||
| RotateBitsLeft_Loop | 57494 | RLA | Rotate left, moving bits one position to the left. | |||||||||||||||||||||||
| 57495 | DJNZ RotateBitsLeft_Loop | Decrease counter by one and loop back to RotateBitsLeft_Loop until counter is zero. | ||||||||||||||||||||||||
| 57497 | SCF | Set the carry flag. | ||||||||||||||||||||||||
| 57498 | POP BC | Restore the bit count from the stack. | ||||||||||||||||||||||||
| RotateBitsRight_Loop | 57499 | RRA | Rotate right, moving bits back and inserting 1. | |||||||||||||||||||||||
| 57500 | DJNZ RotateBitsRight_Loop | Decrease the bit count by one and loop back to RotateBitsRight_Loop until all bits have been processed. | ||||||||||||||||||||||||
| 57502 | LD (HL),A | Write A to *HL. | ||||||||||||||||||||||||
| 57503 | LD HL,57567 | Increment *Operation_Code by one. | ||||||||||||||||||||||||
| 57506 | INC (HL) | |||||||||||||||||||||||||
| 57507 | LD HL,(57568) | HL=*Buffer_Position. | ||||||||||||||||||||||||
| 57510 | POP BC | Restore the repeat count from the stack. | ||||||||||||||||||||||||
| 57511 | DJNZ ProcessOperationBlock_Loop | Decrease the repeat count by one and loop back to ProcessOperationBlock_Loop until all operations are done. | ||||||||||||||||||||||||
| 57513 | INC IX | Increment IX by two. | ||||||||||||||||||||||||
| 57515 | INC IX | |||||||||||||||||||||||||
| 57517 | JP ProcessCompressedImageData | Jump to ProcessCompressedImageData. | ||||||||||||||||||||||||
|
Has all the image been decompressed now? If not, loop back again.
|
||||||||||||||||||||||||||
| GeneratePicture_Next | 57520 | LD HL,57566 | HL=Line_Counter. | |||||||||||||||||||||||
| 57523 | DEC (HL) | Decrease *HL by one. | ||||||||||||||||||||||||
| 57524 | JP NZ,GeneratePicture_Loop | Jump to GeneratePicture_Loop until *HL is zero. | ||||||||||||||||||||||||
| 57527 | INC IX | Move IX to the start of the attribute data. | ||||||||||||||||||||||||
| 57529 | LD B,16 | Set a counter in B to process 16 rows of attribute data. | ||||||||||||||||||||||||
| 57531 | LD HL,43747 | Store the start of Buffer_Image_Attributes in HL. | ||||||||||||||||||||||||
| GeneratePicture_Attributes_Loop | 57534 | PUSH BC | Stash the attribute row counter and the image attributes buffer pointer on the stack. | |||||||||||||||||||||||
| 57535 | PUSH HL | |||||||||||||||||||||||||
| 57536 | LD A,0 | Initialise the column counter in A. | ||||||||||||||||||||||||
| GeneratePicture_Attribute_Row | 57538 | LD C,(IX+0) | Load the attribute value into C. | |||||||||||||||||||||||
| 57541 | INC IX | Load the repeat length into B. | ||||||||||||||||||||||||
| 57543 | LD B,(IX+0) | |||||||||||||||||||||||||
| 57546 | INC IX | Move IX to the next attribute/ repeat length pair. | ||||||||||||||||||||||||
| 57548 | ADD A,B | Add the repeat length to the column counter. | ||||||||||||||||||||||||
| GeneratePicture_Attribute_Run | 57549 | LD (HL),C | Write the attribute to the image attributes buffer. | |||||||||||||||||||||||
| 57550 | INC HL | Increment the image attributes buffer pointer by one. | ||||||||||||||||||||||||
| 57551 | DJNZ GeneratePicture_Attribute_Run | Decrease the repeat counter by one and loop back to GeneratePicture_Attribute_Run until counter is zero. | ||||||||||||||||||||||||
| 57553 | CP 20 | Jump to GeneratePicture_Attribute_Row if 20 columns have been processed. | ||||||||||||||||||||||||
| 57555 | JR NZ,GeneratePicture_Attribute_Row | |||||||||||||||||||||||||
| 57557 | POP HL | Restore the start of the current attribute row from the stack. | ||||||||||||||||||||||||
| 57558 | LD BC,20 | Move HL to the next row in the attribute buffer. | ||||||||||||||||||||||||
| 57561 | ADD HL,BC | |||||||||||||||||||||||||
| 57562 | POP BC | Restore the attribute row counter from the stack. | ||||||||||||||||||||||||
| 57563 | DJNZ GeneratePicture_Attributes_Loop | Decrease the attribute row counter by one and loop back to GeneratePicture_Attributes_Loop until counter is zero. | ||||||||||||||||||||||||
| 57565 | RET | Return. | ||||||||||||||||||||||||
|
Variables specifically for this routine.
|
||||||||||||||||||||||||||
| Line_Counter | 57566 | DEFB 0 | ||||||||||||||||||||||||
| Operation_Code | 57567 | DEFB 0 | ||||||||||||||||||||||||
| Buffer_Position | 57568 | DEFW 0 | ||||||||||||||||||||||||
| Prev: 57266 | Up: Map | Next: 57570 |