Prev: E0C2 Up: Map Next: E16A
E0F5: Create flipped/mirrored version of a particular graphic
Input
B Graphics number for graphics address pointer table at 97C3. This relates to scenery graphics (wall/floor connectors, door frames etc.).
C Graphic address offset (bits 0-3 of this byte give the offset for graphics pointer address frames at 97C3)
HL Points to relevant graphics address pointer at address table at 97C3
right wall scenery graphic left wall scenery graphic
Right-hand wall and its left-hand 'mirrored' version
In the graphic address pointer table at 97C3, spaces have been left after 'flippable' graphics to store the graphics address pointer for the mirrored graphic.
For example, right-hand wall door frame graphics can be flipped/mirrored to create left-hand wall door frames.
Bits 0-3 of the pre-graphics byte in the C register tell us how far to move the address pointer forward (each value = 4 bytes) to point to the space in which address pointer for the flipped/mirrored graphics is stored.
First, calculate the address at which to store the mirrored graphics:
E0F5 LD A,C
E0F6 AND $0F Get the offset stored in bits 0-3
E0F8 LD ($EAB1),A
E0FB INC HL Loop round n*4 bytes (i.e. two 16-bit addresses for each count) from the base graphic pointer address at 97C3.
E0FC INC HL
E0FD INC HL
E0FE INC HL
E0FF DEC A
E100 JR NZ,$E0FB
E102 LD ($EAB2),HL ...And store the new calculated address. The mirrored graphic address pointer will actually be stored in the two bytes prior to this address.
Identify the memory address locations at which to store the mirrored graphics:
E105 LD HL,($EAEF) Get pointer to data/graphics storage area (8033)
E108 LD A,(HL) Check byte
E109 INC HL ...and move pointer one address forward
E10A CP $FF Is it 255 (end-of-data byte)
E10C JR Z,$E113 If so, can store graphics from here
E10E CP B Is the graphics address pointer table offset byte stored here?
E10F JR Z,$E169 If so, can skip straight to RET at the end of the routine.
This may be a check to see if the graphics data has already been dealt with, but this condition isn't normally met during the game, as each room will start with a bunch of scenery items.
E111 JR $E108 Otherwise, keep moving through the data until a end-of-data byte is found
E113 LD (HL),$FF Now we're at the right address. Set end-of-data byte (255)...
E115 DEC HL ...and the pre-graphic data byte before it
E116 LD (HL),B
E117 EX DE,HL HL now pointing to graphic data to mirror, e.g. 9E0F
E118 LD DE,($EB5D)
E11C LD B,H BC temporary store for HL e.g. 9E0F
E11D LD C,L
Store the address pointer to the reflected/flipped graphics address in a free slot by the base graphics address pointer, in the table at 97C3:
E11E LD HL,($EAB2) Get graphics pointer address from earlier (table at 97C3), e.g. 97E9
E121 DEC HL Put the flipped/mirrored graphics pointer into the 2-byte slot just before it.
E122 LD (HL),D
E123 DEC HL
E124 LD (HL),E
E125 LD ($EAB2),HL Store the graphics address pointer to the flipped graphics
E128 LD H,B Restore HL, pointing at the graphics to mirror, e.g. 9E0F.
E129 LD L,C
The following routine gets graphic data and mirrors it, storing the mirrored bytes.
First, transfer across the few data bytes before the graphics which hold (a) number of tiles in the current graphic, (b) horizontal/vertical pixel offsets, and (c) number of bytes in the tile.
E12A LD A,(HL) Number of tiles that form the current graphic (tile counter).
E12B LD (DE),A Copy it to the mirrored data store. This is how many tiles will need mirroring and storing.
E12C INC DE Then move both address pointers to the next byte.
E12D INC HL
Mirror the graphic and store it.
E12E LD ($EAC7),A Store the tile counter
E131 LD A,(HL) Copy over the horizontal (X axis) offset (in pixels)
E132 ADD A,$08 Add 8 and use NEG so that the X axis pixel offsets are reversed
E134 NEG e.g. horizontal pixel offsets for a 4 character-wide graphic of -16, -8, 0 and +8 become +8, 0, -8, -16 in the mirrored version as they're drawn in reverse order in the reflected version.
E136 LD (DE),A
E137 INC HL Copy over the vertical (Y axis) offset (this won't need changing)
E138 INC DE
E139 LD A,(HL)
E13A LD (DE),A
E13B INC HL ...Next, copy over the number of bytes in the tile
E13C INC DE
E13D LD A,(HL)
E13E LD (DE),A
E13F INC HL
E140 INC DE
E141 LD ($EAD1),A Store this number as a counter
Mirror the graphic data for the tile and store the flipped tile data
E144 LD A,(HL) Get graphics byte
E145 INC HL Move graphics address pointer along to next one
E146 LD B,$08 Rotate the bits from A register x8 backwards into C register to create the mirrored byte
E148 RLA
E149 RR C
E14B DJNZ $E148
E14D LD A,C Get the completed mirrored byte...
E14E LD (DE),A ...And store.
E14F INC DE Move the mirrored graphics address pointer along to next one
E150 LD A,($EAD1) Retrieve the tile byte counter
E153 DEC A Repeat for the rest of the bytes in the tile.
E154 JR NZ,$E141
Tile is now flipped/mirrored. Now repeat for all tiles that make up the full graphic.
E156 LD A,($EAC7) Get the tile counter
E159 DEC A Decrement and repeat for the rest of the tiles that make up the graphic.
E15A JR NZ,$E12E
Check if there are any more graphics to mirror in the 'set'. For instance, there are 3 lots of mirrored graphics for the doors at 9CD0.
E15C LD A,($EAB1) Get the offset address counter
E15F DEC A Decrement and re-store
E160 LD ($EAB1),A
E163 JR NZ,$E11C If there are more graphics to mirror, go and do them.
E165 LD ($EB5D),DE All graphics now mirrored. Store the mirrored graphics address pointer, ready for any other graphics that may need mirroring.
This entry point is used by the routine at E0C2.
E169 RET All relevant graphic data is now mirrored/flipped.
Prev: E0C2 Up: Map Next: E16A