![]() |
Routines |
| Prev: BB98 | Up: Map | Next: BCEE |
|
This turns a map position (from map_position), adds on the given (x,y) offset and turns that resulting coordinate into a tile set pointer.
Used by the routine at restore_tiles.
|
||||||||||||||||
| select_tile_set | BCAA | EX AF,AF' | Preserve A during this routine | |||||||||||||
| BCAB | LD A,($68A0) | Fetch the global current room index | ||||||||||||||
| BCAE | AND A | Is it room_0_OUTDOORS? | ||||||||||||||
| BCAF | JR Z,sts_exterior | Jump if so | ||||||||||||||
| sts_interior | BCB1 | LD BC,$9768 | Otherwise point BC at interior_tiles[0] | |||||||||||||
| BCB4 | EX AF,AF' | Restore A | ||||||||||||||
| BCB5 | RET | Return | ||||||||||||||
|
Convert map position to an index into map_buf: a 7x5 array of supertile indices.
Compute row offset
|
||||||||||||||||
| sts_exterior | BCB6 | LD A,($81BC) | Get the map position's Y component and isolate its low-order bits | |||||||||||||
| BCB9 | AND $03 | |||||||||||||||
| BCBB | ADD A,L | Add on the Y shift from L | ||||||||||||||
| BCBC | RRA | Divide by two (rotate right by two then clear the rotated-out bits) | ||||||||||||||
| BCBD | RRA | |||||||||||||||
| BCBE | AND $3F | |||||||||||||||
| BCC0 | LD L,A | Multiply by 7 (columns per row of supertiles) | ||||||||||||||
| BCC1 | ADD A,A | |||||||||||||||
| BCC2 | ADD A,A | |||||||||||||||
| BCC3 | ADD A,A | |||||||||||||||
| BCC4 | SUB L | |||||||||||||||
| BCC5 | LD L,A | Save for later | ||||||||||||||
|
Compute column offset
|
||||||||||||||||
| BCC6 | LD A,($81BB) | Get the map position's X component and isolate its low-order bits | ||||||||||||||
| BCC9 | AND $03 | |||||||||||||||
| BCCB | ADD A,H | Add on the X shift from H | ||||||||||||||
| BCCC | RRA | Divide by two (rotate right by two then clear the rotated-out bits) | ||||||||||||||
| BCCD | RRA | |||||||||||||||
| BCCE | AND $3F | |||||||||||||||
|
Combine offsets
|
||||||||||||||||
| BCD0 | ADD A,L | Combine the row and column offsets | ||||||||||||||
| BCD1 | LD HL,$FF58 | Point HL at map_buf (a 7x5 cut-down copy of the main map which holds supertile indices) | ||||||||||||||
| BCD4 | ADD A,L | Add offset (quick version since the values can't overflow) | ||||||||||||||
| BCD5 | LD L,A | |||||||||||||||
| BCD6 | LD A,(HL) | Fetch the supertile index from map_buf | ||||||||||||||
| BCD7 | LD BC,$8590 | Point BC at exterior_tiles[0] | ||||||||||||||
|
Choose the tile index for the current supertile:
|
||||||||||||||||
| BCDA | CP $2D | Is the supertile index < 45? | ||||||||||||||
| BCDC | JR C,sts_exit | Jump if so | ||||||||||||||
| BCDE | LD BC,$8A18 | Point BC at exterior_tiles[145] | ||||||||||||||
| BCE1 | CP $8B | Is the supertile index < 139? | ||||||||||||||
| BCE3 | JR C,sts_exit | Jump if so | ||||||||||||||
| BCE5 | CP $CC | Is the supertile index >= 204? | ||||||||||||||
| BCE7 | JR NC,sts_exit | Jump if so | ||||||||||||||
| BCE9 | LD BC,$90F8 | Point BC at exterior_tiles[145 + 220] | ||||||||||||||
| sts_exit | BCEC | EX AF,AF' | Restore A | |||||||||||||
| BCED | RET | Return | ||||||||||||||
| Prev: BB98 | Up: Map | Next: BCEE |