Prev: 57538 Up: Map Next: 57706
57589: Create flipped/mirrored version of a particular graphic
Input
B Graphics number for graphics address pointer table at 38851. 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 38851)
HL Points to relevant graphics address pointer at address table at 38851
right wall scenery graphic left wall scenery graphic
Right-hand wall and its left-hand 'mirrored' version
In the graphic address pointer table at 38851, 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:
57589 LD A,C
57590 AND 15 Get the offset stored in bits 0-3
57592 LD (60081),A
57595 INC HL Loop round n*4 bytes (i.e. two 16-bit addresses for each count) from the base graphic pointer address at 38851.
57596 INC HL
57597 INC HL
57598 INC HL
57599 DEC A
57600 JR NZ,57595
57602 LD (60082),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:
57605 LD HL,(60143) Get pointer to data/graphics storage area (32819)
57608 LD A,(HL) Check byte
57609 INC HL ...and move pointer one address forward
57610 CP 255 Is it 255 (end-of-data byte)
57612 JR Z,57619 If so, can store graphics from here
57614 CP B Is the graphics address pointer table offset byte stored here?
57615 JR Z,57705 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.
57617 JR 57608 Otherwise, keep moving through the data until a end-of-data byte is found
57619 LD (HL),255 Now we're at the right address. Set end-of-data byte (255)...
57621 DEC HL ...and the pre-graphic data byte before it
57622 LD (HL),B
57623 EX DE,HL HL now pointing to graphic data to mirror, e.g. 40463
57624 LD DE,(60253)
57628 LD B,H BC temporary store for HL e.g. 40463
57629 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 38851:
57630 LD HL,(60082) Get graphics pointer address from earlier (table at 38851), e.g. 38889
57633 DEC HL Put the flipped/mirrored graphics pointer into the 2-byte slot just before it.
57634 LD (HL),D
57635 DEC HL
57636 LD (HL),E
57637 LD (60082),HL Store the graphics address pointer to the flipped graphics
57640 LD H,B Restore HL, pointing at the graphics to mirror, e.g. 40463.
57641 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.
57642 LD A,(HL) Number of tiles that form the current graphic (tile counter).
57643 LD (DE),A Copy it to the mirrored data store. This is how many tiles will need mirroring and storing.
57644 INC DE Then move both address pointers to the next byte.
57645 INC HL
Mirror the graphic and store it.
57646 LD (60103),A Store the tile counter
57649 LD A,(HL) Copy over the horizontal (X axis) offset (in pixels)
57650 ADD A,8 Add 8 and use NEG so that the X axis pixel offsets are reversed
57652 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.
57654 LD (DE),A
57655 INC HL Copy over the vertical (Y axis) offset (this won't need changing)
57656 INC DE
57657 LD A,(HL)
57658 LD (DE),A
57659 INC HL ...Next, copy over the number of bytes in the tile
57660 INC DE
57661 LD A,(HL)
57662 LD (DE),A
57663 INC HL
57664 INC DE
57665 LD (60113),A Store this number as a counter
Mirror the graphic data for the tile and store the flipped tile data
57668 LD A,(HL) Get graphics byte
57669 INC HL Move graphics address pointer along to next one
57670 LD B,8 Rotate the bits from A register x8 backwards into C register to create the mirrored byte
57672 RLA
57673 RR C
57675 DJNZ 57672
57677 LD A,C Get the completed mirrored byte...
57678 LD (DE),A ...And store.
57679 INC DE Move the mirrored graphics address pointer along to next one
57680 LD A,(60113) Retrieve the tile byte counter
57683 DEC A Repeat for the rest of the bytes in the tile.
57684 JR NZ,57665
Tile is now flipped/mirrored. Now repeat for all tiles that make up the full graphic.
57686 LD A,(60103) Get the tile counter
57689 DEC A Decrement and repeat for the rest of the tiles that make up the graphic.
57690 JR NZ,57646
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 40144.
57692 LD A,(60081) Get the offset address counter
57695 DEC A Decrement and re-store
57696 LD (60081),A
57699 JR NZ,57628 If there are more graphics to mirror, go and do them.
57701 LD (60253),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 57538.
57705 RET All relevant graphic data is now mirrored/flipped.
Prev: 57538 Up: Map Next: 57706