Skip to content

Commit f056558

Browse files
committed
react-gbajs: add hacks
1 parent 9a4092d commit f056558

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/emulator/gba.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function GameBoyAdvance() {
2020
this.keypad = new GameBoyAdvanceKeypad();
2121
this.sio = new GameBoyAdvanceSIO();
2222

23+
this.frozenAddresses = {};
24+
2325
// TODO: simplify this graph
2426
this.cpu.mmu = this.mmu;
2527
this.cpu.irq = this.irq;
@@ -71,6 +73,14 @@ function GameBoyAdvance() {
7173

7274
window.GameBoyAdvance = GameBoyAdvance
7375

76+
GameBoyAdvance.prototype.addFreezeAddress = function({ address, size, value }) {
77+
this.frozenAddresses[address] = { size, value };
78+
};
79+
80+
GameBoyAdvance.prototype.removeFreezeAddress = function(address) {
81+
delete this.frozenAddresses[address];
82+
};
83+
7484
GameBoyAdvance.prototype.setCanvas = function(canvas) {
7585
var self = this;
7686
if (canvas.offsetWidth != 240 || canvas.offsetHeight != 160) {
@@ -144,8 +154,26 @@ GameBoyAdvance.prototype.reset = function() {
144154
};
145155

146156
GameBoyAdvance.prototype.step = function() {
157+
const mmuMemoryIram = this.mmu.memory[this.mmu.REGION_WORKING_IRAM];
158+
147159
while (this.doStep()) {
148160
this.cpu.step();
161+
162+
for (const address in this.frozenAddresses) {
163+
const { size, value } = this.frozenAddresses[address];
164+
165+
switch (size) {
166+
case 8:
167+
mmuMemoryIram.store8(address, value);
168+
break;
169+
case 16:
170+
mmuMemoryIram.store16(address, value);
171+
break;
172+
case 16:
173+
mmuMemoryIram.store32(address, value);
174+
break;
175+
}
176+
}
149177
}
150178
};
151179

src/react/gba-provider.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const GbaProvider = ({ children }) => {
88
const [gba, setGba] = useState()
99
const [volume, setVolume] = useState(null)
1010
const [romBufferMemory, setRomBufferMemory] = useState()
11+
const [frozenAddresses, setFrozenAddresses] = useState({})
1112

1213
const play = (newRomBufferMemory) => {
1314
setRomBufferMemory(newRomBufferMemory)
@@ -25,13 +26,25 @@ const GbaProvider = ({ children }) => {
2526
gba.runStable()
2627
}
2728

29+
const updateFrozenAddreses = () =>
30+
setFrozenAddresses(cloneDeep(gba.frozenAddresses))
31+
2832
return (
2933
<GbaContext.Provider value={{
3034
gba,
3135
setRomBufferMemory,
3236
play,
3337
saveState,
3438
restoreState,
39+
frozenAddresses,
40+
addFreezeAddress: gba && ((args) => {
41+
gba.addFreezeAddress(args)
42+
updateFrozenAddreses()
43+
}),
44+
removeFreezeAddress: gba && ((args) => {
45+
gba.removeFreezeAddress(args)
46+
updateFrozenAddreses()
47+
}),
3548
}}
3649
>
3750
{children}

0 commit comments

Comments
 (0)