Prev: C5E9 Up: Map Next: C6C3
C5F9: Draw Wall Strip
Used by the routine at DrawWallStrips.
Draws a wall tile, sixteen pixels wide, into PlayfieldBuffer. The image has the same format as DrawStripGraphic, but it replaces the buffer. The masks from WallTileMasks are written into the AND instructions. The image is flipped if FlipFlag is not zero.
Input
D The vertical position of the bottom of the tile
E The horizontal position of the tile
IY The address of the tile number
Find the image and clip it to the buffer.
DrawWallStrip C5F9 LD A,(IY+$00) Fetch the tile number.
C5FC LD BC,$8FF8 Point BC at WallImagePointers.
C5FF CALL GetTableEntry Call GetTableEntry.
C602 LD A,D Subtract 48 from the vertical position.
C603 SUB $48
C605 JR C,ClipWallStripTop Jump to ClipWallStripTop if it is below the bottom.
C607 SUB $70 Subtract 70.
C609 RET NC Return if it is above the top.
C60A NEG Make it the number of rows in the buffer.
C60C CP (HL) Compare it with the height of the image.
C60D JR C,DrawWallStrip_FirstRow Jump to DrawWallStrip_FirstRow if it is fewer.
C60F LD A,(HL) Use the height of the image.
Draw the rows that are in the buffer.
DrawWallStrip_FirstRow C610 INC HL Move on to the first row of the image.
This entry point is used by the routine at ClipWallStripTop.
DrawWallStrip_Rows C611 EX AF,AF' Keep the number of rows in A'.
C612 EX DE,HL Put the position in HL.
C613 CALL CalculateBufferAddress Call CalculateBufferAddress.
C616 EX DE,HL Switch the buffer and the image.
C617 PUSH HL Stash the image on the stack.
Write the masks from WallTileMasks into the AND instructions.
C618 LD A,($A24E) Fetch ScreenHorizontalPosition.
C61B RRCA Move the shift into the lowest bits.
C61C AND %00000011 Keep the lowest two bits.
C61E LD HL,$C6C3 Point HL at WallTileMasks.
C621 CALL AddAToHL Call AddAToHL.
C624 LD A,(HL) Fetch the mask.
C625 LD ($C650),A Set the left-hand AND operands.
C628 LD ($C677),A
C62B CPL Complement the mask.
C62C LD ($C65E),A Set the right-hand AND operands.
C62F LD ($C686),A
Choose the draw path.
C632 POP HL Restore the image from the stack.
C633 LD ($A21D),SP Set SavedStackPointer.
C637 LD SP,HL Point the stack at the image.
C638 LD A,($A24E) Fetch ScreenHorizontalPosition.
C63B AND %00000110 Keep bits 1 and 2.
C63D JR Z,DrawWallStrip_Aligned Jump to DrawWallStrip_Aligned if the image is aligned.
C63F OR %11110000 Set the high bits of the page.
C641 LD H,A Set H.
C642 LD A,($A252) Fetch FlipFlag.
C645 AND A Jump to DrawWallStrip_Flipped if it is set.
C646 JR NZ,DrawWallStrip_Flipped
C648 SET 3,H Set bit 3 of H.
C64A EX AF,AF' Switch in the number of rows.
Draw a shifted row.
DrawWallStrip_ShiftedRow C64B EX AF,AF' Keep the number of rows in A'.
C64C POP BC Fetch a row and point at the first byte.
C64D LD L,C
C64E LD A,(DE) Fetch the first byte of the buffer.
C64F AND %00000000 Keep the bits which are not covered.
C651 OR (HL) Combine it and store the byte.
C652 LD (DE),A
C653 INC DE Move on to the next byte and page.
C654 INC H
C655 LD A,(HL) Look up the bits which moved on.
C656 DEC H Go back to the first page.
C657 LD L,B Point at the second byte of the image.
C658 OR (HL) Combine it and store the byte.
C659 LD (DE),A
C65A INC DE Move on to the next byte and page.
C65B INC H
C65C LD A,(DE) Fetch the third byte of the buffer.
C65D AND %00000000 Keep the bits which are not covered.
C65F OR (HL) Combine it and store the byte.
C660 LD (DE),A
C661 DEC H Go back to the first page.
C662 EX DE,HL Move on to the next row of the buffer.
C663 LD BC,$0016
C666 ADD HL,BC
C667 EX DE,HL
C668 EX AF,AF' Switch in the number of rows.
C669 DEC A Count it down.
C66A JR NZ,DrawWallStrip_ShiftedRow Jump to DrawWallStrip_ShiftedRow until the rows are done.
Put the stack back.
DrawWallStrip_Finish C66C LD SP,($A21D) Fetch SavedStackPointer and return.
C670 RET
Draw a shifted row that is flipped.
DrawWallStrip_Flipped C671 EX AF,AF' Switch in the number of rows.
DrawWallStrip_FlippedRow C672 EX AF,AF' Keep the number of rows in A'.
C673 POP BC Fetch a row and point at the second byte.
C674 LD L,B
C675 LD A,(DE) Fetch the first byte of the buffer.
C676 AND %00000000 Keep the bits which are not covered.
C678 OR (HL) Combine it and store the byte.
C679 LD (DE),A
C67A INC DE Move on to the next byte and page.
C67B INC H
C67C LD B,(HL) Look up the bits which moved on.
C67D DEC H Go back to the first page.
C67E LD L,C Point at the first byte of the image.
C67F LD A,(HL) Fetch the bits which stay.
C680 OR B Combine them and store the byte.
C681 LD (DE),A
C682 INC DE Move on to the next byte and page.
C683 INC H
C684 LD A,(DE) Fetch the third byte of the buffer.
C685 AND %00000000 Keep the bits which are not covered.
C687 OR (HL) Combine it and store the byte.
C688 LD (DE),A
C689 DEC H Go back to the first page.
C68A EX DE,HL Move on to the next row of the buffer.
C68B LD BC,$0016
C68E ADD HL,BC
C68F EX DE,HL
C690 EX AF,AF' Switch in the number of rows.
C691 DEC A Count it down.
C692 JR NZ,DrawWallStrip_FlippedRow Jump to DrawWallStrip_FlippedRow until the rows are done.
C694 JR DrawWallStrip_Finish Jump to DrawWallStrip_Finish.
Draw an aligned image.
DrawWallStrip_Aligned C696 EX DE,HL Put the buffer address in HL.
C697 LD A,($A252) Fetch FlipFlag and test it.
C69A AND A
C69B JR NZ,DrawWallStrip_FlippedAligned Jump to DrawWallStrip_FlippedAligned if it is set.
C69D LD BC,$0017 Set BC to 17.
C6A0 EX AF,AF' Switch in the number of rows.
DrawWallStrip_AlignedRow C6A1 EX AF,AF' Keep the number of rows in A'.
C6A2 POP DE Fetch a row of the image.
C6A3 LD (HL),E Store the first byte and move on.
C6A4 INC HL
C6A5 LD (HL),D Store the second byte.
C6A6 ADD HL,BC Move on to the next row of the buffer.
C6A7 EX AF,AF' Switch in the number of rows.
C6A8 DEC A Count it down.
C6A9 JR NZ,DrawWallStrip_AlignedRow Jump to DrawWallStrip_AlignedRow until the rows are done.
C6AB JR DrawWallStrip_Finish Jump to DrawWallStrip_Finish.
Draw an aligned image that is flipped.
DrawWallStrip_FlippedAligned C6AD LD B,$F9 Set B to F9.
C6AF EX AF,AF' Switch in the number of rows.
DrawWallStrip_FlippedAlignedRow C6B0 EX AF,AF' Keep the number of rows in A'.
C6B1 POP DE Fetch a row of the image.
C6B2 LD C,D Point at the second byte, turned round.
C6B3 LD A,(BC) Store it in the first byte of the buffer.
C6B4 LD (HL),A
C6B5 INC HL Move on to the next byte of the buffer.
C6B6 LD C,E Point at the first byte, turned round.
C6B7 LD A,(BC) Store it in the second byte of the buffer.
C6B8 LD (HL),A
C6B9 LD DE,$0017 Move on to the next row of the buffer.
C6BC ADD HL,DE
C6BD EX AF,AF' Switch in the number of rows.
C6BE DEC A Count it down.
C6BF JR NZ,DrawWallStrip_FlippedAlignedRow Jump to DrawWallStrip_FlippedAlignedRow until the rows are done.
C6C1 JR DrawWallStrip_Finish Jump to DrawWallStrip_Finish.
View the equivalent code in;
Prev: C5E9 Up: Map Next: C6C3