Skip to content

Commit

Permalink
Mirror ROM based on the header size
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydr8gon committed Nov 2, 2024
1 parent e222d07 commit 4b1d3b8
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/memory.S
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ map_lorom:
li t1, 0xFFFFFF // Maximum address
li t2, 0x2000 // Block size (8KB)

// Set the ROM mask using the header size
lw t4, 0xA0007FD4(t8)
li t7, 0x7F0000
li t3, 0x800
andi t4, t4, 0xFF
sll t4, t3, t4
addi t4, t4, -1
and t7, t7, t4

// Set the SRAM mask using the header size
lw t9, 0xA0007FD8(t8)
srl t9, t9, 24
Expand Down Expand Up @@ -260,8 +269,7 @@ lowram_area:

lorom_area:
// Special case LoROM; the exception handler will dynamically load blocks
li t4, 0x7F0000
and t4, t4, t0 // Mirrored bank
and t4, t7, t0 // Mirrored bank
srl t4, t4, 1 // 32KB every 64KB bank
add t3, t8, t4
li t4, 0x7FFF
Expand Down Expand Up @@ -320,6 +328,15 @@ map_hirom:
li t1, 0xFFFFFF // Maximum address
li t2, 0x2000 // Block size (8KB)

// Set the ROM mask using the header size
lw t4, 0xA000FFD4(t8)
li t7, 0x3FFFFF
li t3, 0x400
andi t4, t4, 0xFF
sll t4, t3, t4
addi t4, t4, -1
and t7, t7, t4

// Set the SRAM mask using the header size
lw t9, 0xA000FFD8(t8)
srl t9, t9, 24
Expand Down Expand Up @@ -362,8 +379,7 @@ hiwram_area:

hirom_area:
// Special case HiROM; the exception handler will dynamically load blocks
li t4, 0x3FFFFF // ROM mask
and t4, t4, t0
and t4, t7, t0
add t3, t8, t4
b map_hinone

Expand Down

0 comments on commit 4b1d3b8

Please sign in to comment.