Skip to content

Commit 5b7f360

Browse files
committed
Update to mGBA 0.7.3
1 parent 7b3de70 commit 5b7f360

File tree

15 files changed

+94
-61
lines changed

15 files changed

+94
-61
lines changed

Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundleSignature</key>
1818
<string>????</string>
1919
<key>CFBundleVersion</key>
20-
<string>0.7.2</string>
20+
<string>0.7.3</string>
2121
<key>NSPrincipalClass</key>
2222
<string>OEGameCoreController</string>
2323
<key>OEGameCoreClass</key>

include/mgba-util/platform/switch/threading.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
typedef ThreadFunc ThreadEntry;
1515
typedef CondVar Condition;
1616

17+
#define ThreadJoin(T) ThreadJoinPtr(&T)
18+
1719
static inline int MutexInit(Mutex* mutex) {
1820
mutexInit(mutex);
1921
return 0;
@@ -71,12 +73,12 @@ static inline int ThreadCreate(Thread* thread, ThreadEntry entry, void* context)
7173
return threadStart(thread);
7274
}
7375

74-
static inline int ThreadJoin(Thread thread) {
75-
int res = threadWaitForExit(&thread);
76+
static inline int ThreadJoinPtr(Thread* thread) {
77+
int res = threadWaitForExit(thread);
7678
if(R_FAILED(res)) {
7779
return res;
7880
}
79-
return threadClose(&thread);
81+
return threadClose(thread);
8082
}
8183

8284
static inline void ThreadSetName(const char* name) {

src/core/cheats.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ void mCheatSetInit(struct mCheatSet* set, const char* name) {
8282
}
8383

8484
void mCheatSetDeinit(struct mCheatSet* set) {
85-
mCheatListDeinit(&set->list);
8685
size_t i;
8786
for (i = 0; i < StringListSize(&set->lines); ++i) {
8887
free(*StringListGetPointer(&set->lines, i));
8988
}
89+
mCheatListDeinit(&set->list);
9090
if (set->name) {
9191
free(set->name);
9292
}

src/core/core.c

+9
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ bool mCorePreloadFile(struct mCore* core, const char* path) {
157157
}
158158

159159
bool mCoreAutoloadSave(struct mCore* core) {
160+
if (!core->dirs.save) {
161+
return false;
162+
}
160163
return core->loadSave(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.save, ".sav", O_CREAT | O_RDWR));
161164
}
162165

163166
bool mCoreAutoloadPatch(struct mCore* core) {
167+
if (!core->dirs.patch) {
168+
return false;
169+
}
164170
return core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ups", O_RDONLY)) ||
165171
core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".ips", O_RDONLY)) ||
166172
core->loadPatch(core, mDirectorySetOpenSuffix(&core->dirs, core->dirs.patch, ".bps", O_RDONLY));
@@ -217,6 +223,9 @@ bool mCoreLoadState(struct mCore* core, int slot, int flags) {
217223
}
218224

219225
struct VFile* mCoreGetState(struct mCore* core, int slot, bool write) {
226+
if (!core->dirs.state) {
227+
return NULL;
228+
}
220229
char name[PATH_MAX];
221230
snprintf(name, sizeof(name), "%s.ss%i", core->dirs.baseName, slot);
222231
return core->dirs.state->openFile(core->dirs.state, name, write ? (O_CREAT | O_TRUNC | O_RDWR) : O_RDONLY);

src/gb/audio.c

+11-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static bool _updateSweep(struct GBAudioSquareChannel* sweep, bool initial);
3737
static void _updateSquareSample(struct GBAudioSquareChannel* ch);
3838
static int32_t _updateSquareChannel(struct GBAudioSquareChannel* ch);
3939

40-
static int8_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch);
40+
static int16_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch);
4141

4242
static void _updateFrame(struct mTiming* timing, void* user, uint32_t cyclesLate);
4343
static void _updateChannel1(struct mTiming* timing, void* user, uint32_t cyclesLate);
@@ -279,6 +279,7 @@ void GBAudioWriteNR24(struct GBAudio* audio, uint8_t value) {
279279
void GBAudioWriteNR30(struct GBAudio* audio, uint8_t value) {
280280
audio->ch3.enable = GBAudioRegisterBankGetEnable(value);
281281
if (!audio->ch3.enable) {
282+
mTimingDeschedule(audio->timing, &audio->ch3Event);
282283
audio->playingCh3 = false;
283284
*audio->nr52 &= ~0x0004;
284285
}
@@ -510,6 +511,9 @@ void GBAudioUpdateFrame(struct GBAudio* audio, struct mTiming* timing) {
510511
audio->playingCh1 = _updateSweep(&audio->ch1, false);
511512
*audio->nr52 &= ~0x0001;
512513
*audio->nr52 |= audio->playingCh1;
514+
if (!audio->playingCh1) {
515+
mTimingDeschedule(audio->timing, &audio->ch1Event);
516+
}
513517
}
514518
}
515519
// Fall through
@@ -626,8 +630,11 @@ void GBAudioSamplePSG(struct GBAudio* audio, int16_t* left, int16_t* right) {
626630
}
627631
}
628632

633+
sampleLeft <<= 3;
634+
sampleRight <<= 3;
635+
629636
if (audio->playingCh4 && !audio->forceDisableCh[3]) {
630-
int8_t sample = _coalesceNoiseChannel(&audio->ch4);
637+
int16_t sample = audio->style == GB_AUDIO_GBA ? (audio->ch4.sample << 3) : _coalesceNoiseChannel(&audio->ch4);
631638
if (audio->ch4Left) {
632639
sampleLeft += sample;
633640
}
@@ -637,9 +644,6 @@ void GBAudioSamplePSG(struct GBAudio* audio, int16_t* left, int16_t* right) {
637644
}
638645
}
639646

640-
sampleLeft <<= 3;
641-
sampleRight <<= 3;
642-
643647
*left = sampleLeft * (1 + audio->volumeLeft);
644648
*right = sampleRight * (1 + audio->volumeRight);
645649
}
@@ -762,12 +766,12 @@ static int32_t _updateSquareChannel(struct GBAudioSquareChannel* ch) {
762766
}
763767
}
764768

765-
static int8_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch) {
769+
static int16_t _coalesceNoiseChannel(struct GBAudioNoiseChannel* ch) {
766770
if (!ch->nSamples) {
767771
return ch->sample;
768772
}
769773
// TODO keep track of timing
770-
int8_t sample = ch->samples / ch->nSamples;
774+
int16_t sample = (ch->samples << 3) / ch->nSamples;
771775
ch->nSamples = 0;
772776
ch->samples = 0;
773777
return sample;

src/gb/gb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void GBResizeSram(struct GB* gb, size_t size) {
186186
vf->write(vf, extdataBuffer, vfSize & 0xFF);
187187
}
188188
gb->memory.sram = vf->map(vf, size, MAP_WRITE);
189-
memset(&gb->memory.sram[gb->sramSize], 0xFF, size - gb->sramSize);
189+
memset(&gb->memory.sram[vfSize], 0xFF, size - vfSize);
190190
} else if (size > gb->sramSize || !gb->memory.sram) {
191191
if (gb->memory.sram) {
192192
vf->unmap(vf, gb->memory.sram, gb->sramSize);

src/gb/io.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,11 @@ static void _writeSGBBits(struct GB* gb, int bits) {
119119
if (gb->sgbBit > 128) {
120120
switch (bits) {
121121
case 1:
122-
gb->sgbBit |= 2;
123-
break;
124-
case 2:
125-
gb->sgbBit |= 4;
122+
gb->sgbBit ^= 2;
126123
break;
127124
case 3:
128-
if (gb->sgbBit == 135) {
129-
gb->sgbBit &= ~6;
125+
if (gb->sgbBit == 131) {
126+
gb->sgbBit &= ~2;
130127
gb->sgbCurrentController = (gb->sgbCurrentController + 1) & gb->sgbControllers;
131128
}
132129
break;
@@ -497,8 +494,8 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
497494
case REG_BCPD:
498495
if (gb->video.mode != 3) {
499496
GBVideoProcessDots(&gb->video, 0);
500-
GBVideoWritePalette(&gb->video, address, value);
501497
}
498+
GBVideoWritePalette(&gb->video, address, value);
502499
return;
503500
case REG_OCPS:
504501
gb->video.ocpIndex = value & 0x3F;
@@ -508,8 +505,8 @@ void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) {
508505
case REG_OCPD:
509506
if (gb->video.mode != 3) {
510507
GBVideoProcessDots(&gb->video, 0);
511-
GBVideoWritePalette(&gb->video, address, value);
512508
}
509+
GBVideoWritePalette(&gb->video, address, value);
513510
return;
514511
case REG_SVBK:
515512
GBMemorySwitchWramBank(&gb->memory, value);

src/gb/sio/printer.c

+1
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static uint8_t GBPrinterWriteSC(struct GBSIODriver* driver, uint8_t value) {
222222
printer->print(printer, printer->currentIndex * 4 / GB_VIDEO_HORIZONTAL_PIXELS, printer->buffer);
223223
}
224224
printer->printWait = -1;
225+
printer->currentIndex = 0;
225226
} else if (printer->printWait > 0) {
226227
--printer->printWait;
227228
}

src/gb/video.c

+18-14
Original file line numberDiff line numberDiff line change
@@ -505,14 +505,16 @@ void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value)
505505
} else {
506506
switch (address) {
507507
case REG_BCPD:
508-
if (video->bcpIndex & 1) {
509-
video->palette[video->bcpIndex >> 1] &= 0x00FF;
510-
video->palette[video->bcpIndex >> 1] |= value << 8;
511-
} else {
512-
video->palette[video->bcpIndex >> 1] &= 0xFF00;
513-
video->palette[video->bcpIndex >> 1] |= value;
508+
if (video->mode != 3) {
509+
if (video->bcpIndex & 1) {
510+
video->palette[video->bcpIndex >> 1] &= 0x00FF;
511+
video->palette[video->bcpIndex >> 1] |= value << 8;
512+
} else {
513+
video->palette[video->bcpIndex >> 1] &= 0xFF00;
514+
video->palette[video->bcpIndex >> 1] |= value;
515+
}
516+
video->renderer->writePalette(video->renderer, video->bcpIndex >> 1, video->palette[video->bcpIndex >> 1]);
514517
}
515-
video->renderer->writePalette(video->renderer, video->bcpIndex >> 1, video->palette[video->bcpIndex >> 1]);
516518
if (video->bcpIncrement) {
517519
++video->bcpIndex;
518520
video->bcpIndex &= 0x3F;
@@ -522,14 +524,16 @@ void GBVideoWritePalette(struct GBVideo* video, uint16_t address, uint8_t value)
522524
video->p->memory.io[REG_BCPD] = video->palette[video->bcpIndex >> 1] >> (8 * (video->bcpIndex & 1));
523525
break;
524526
case REG_OCPD:
525-
if (video->ocpIndex & 1) {
526-
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0x00FF;
527-
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value << 8;
528-
} else {
529-
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0xFF00;
530-
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value;
527+
if (video->mode != 3) {
528+
if (video->ocpIndex & 1) {
529+
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0x00FF;
530+
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value << 8;
531+
} else {
532+
video->palette[8 * 4 + (video->ocpIndex >> 1)] &= 0xFF00;
533+
video->palette[8 * 4 + (video->ocpIndex >> 1)] |= value;
534+
}
535+
video->renderer->writePalette(video->renderer, 8 * 4 + (video->ocpIndex >> 1), video->palette[8 * 4 + (video->ocpIndex >> 1)]);
531536
}
532-
video->renderer->writePalette(video->renderer, 8 * 4 + (video->ocpIndex >> 1), video->palette[8 * 4 + (video->ocpIndex >> 1)]);
533537
if (video->ocpIncrement) {
534538
++video->ocpIndex;
535539
video->ocpIndex &= 0x3F;

src/gba/cheats/codebreaker.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ bool GBACheatAddCodeBreaker(struct GBACheatSet* cheats, uint32_t op1, uint16_t o
201201
struct mCheat* incompleteCheat = mCheatListGetPointer(&cheats->d.list, cheats->incompleteCheat);
202202
incompleteCheat->repeat = op1 & 0xFFFF;
203203
incompleteCheat->addressOffset = op2;
204-
incompleteCheat->operandOffset = 0;
204+
incompleteCheat->operandOffset = op1 >> 16;
205205
cheats->incompleteCheat = COMPLETE;
206206
return true;
207207
}

src/gba/cheats/parv3.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bool GBACheatAddProActionReplayRaw(struct GBACheatSet* cheats, uint32_t op1, uin
284284
return false;
285285
}
286286
cheats->hook = malloc(sizeof(*cheats->hook));
287-
cheats->hook->address = BASE_CART0 | (op1 & (SIZE_CART0 - 1));
287+
cheats->hook->address = BASE_CART0 | (op1 & (SIZE_CART0 - 2));
288288
cheats->hook->mode = MODE_THUMB;
289289
cheats->hook->refs = 1;
290290
cheats->hook->reentries = 0;

src/gba/gba.c

+1
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ bool GBALoadNull(struct GBA* gba) {
325325
if (gba->cpu) {
326326
gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]);
327327
}
328+
GBAHardwareInit(&gba->memory.hw, &((uint16_t*) gba->memory.rom)[GPIO_REG_DATA >> 1]);
328329
return true;
329330
}
330331

src/gba/memory.c

+35-21
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,12 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
394394
if ((address & (SIZE_VRAM | 0x00014000)) == SIZE_VRAM && (GBARegisterDISPCNTGetMode(gba->memory.io[REG_DISPCNT >> 1]) >= 3)) { \
395395
mLOG(GBA_MEM, GAME_ERROR, "Bad VRAM Load32: 0x%08X", address); \
396396
value = 0; \
397-
break; \
397+
} else { \
398+
LOAD_32(value, address & 0x00017FFC, gba->video.vram); \
398399
} \
399-
address &= 0x00017FFC; \
400+
} else { \
401+
LOAD_32(value, address & 0x0001FFFC, gba->video.vram); \
400402
} \
401-
LOAD_32(value, address & 0x0001FFFC, gba->video.vram); \
402403
wait += waitstatesRegion[REGION_VRAM];
403404

404405
#define LOAD_OAM LOAD_32(value, address & (SIZE_OAM - 4), gba->video.oam.raw);
@@ -530,9 +531,10 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
530531
value = 0;
531532
break;
532533
}
533-
address &= 0x00017FFE;
534+
LOAD_16(value, address & 0x00017FFE, gba->video.vram);
535+
} else {
536+
LOAD_16(value, address & 0x0001FFFE, gba->video.vram);
534537
}
535-
LOAD_16(value, address & 0x0001FFFE, gba->video.vram);
536538
break;
537539
case REGION_OAM:
538540
LOAD_16(value, address & (SIZE_OAM - 2), gba->video.oam.raw);
@@ -645,9 +647,10 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
645647
value = 0;
646648
break;
647649
}
648-
address &= 0x00017FFF;
650+
value = ((uint8_t*) gba->video.vram)[address & 0x00017FFF];
651+
} else {
652+
value = ((uint8_t*) gba->video.vram)[address & 0x0001FFFF];
649653
}
650-
value = ((uint8_t*) gba->video.vram)[address & 0x0001FFFF];
651654
break;
652655
case REGION_OAM:
653656
value = ((uint8_t*) gba->video.oam.raw)[address & (SIZE_OAM - 1)];
@@ -732,15 +735,21 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
732735
if ((address & 0x0001FFFF) >= SIZE_VRAM) { \
733736
if ((address & (SIZE_VRAM | 0x00014000)) == SIZE_VRAM && (GBARegisterDISPCNTGetMode(gba->memory.io[REG_DISPCNT >> 1]) >= 3)) { \
734737
mLOG(GBA_MEM, GAME_ERROR, "Bad VRAM Store32: 0x%08X", address); \
735-
break; \
738+
} else { \
739+
LOAD_32(oldValue, address & 0x00017FFC, gba->video.vram); \
740+
if (oldValue != value) { \
741+
STORE_32(value, address & 0x00017FFC, gba->video.vram); \
742+
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x00017FFC) + 2); \
743+
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x00017FFC)); \
744+
} \
745+
} \
746+
} else { \
747+
LOAD_32(oldValue, address & 0x0001FFFC, gba->video.vram); \
748+
if (oldValue != value) { \
749+
STORE_32(value, address & 0x0001FFFC, gba->video.vram); \
750+
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x0001FFFC) + 2); \
751+
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x0001FFFC)); \
736752
} \
737-
address &= 0x00017FFC; \
738-
} \
739-
LOAD_32(oldValue, address & 0x0001FFFC, gba->video.vram); \
740-
if (oldValue != value) { \
741-
STORE_32(value, address & 0x0001FFFC, gba->video.vram); \
742-
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x0001FFFC) + 2); \
743-
gba->video.renderer->writeVRAM(gba->video.renderer, (address & 0x0001FFFC)); \
744753
} \
745754
wait += waitstatesRegion[REGION_VRAM];
746755

@@ -855,12 +864,17 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle
855864
mLOG(GBA_MEM, GAME_ERROR, "Bad VRAM Store16: 0x%08X", address);
856865
break;
857866
}
858-
address &= 0x00017FFE;
859-
}
860-
LOAD_16(oldValue, address & 0x0001FFFE, gba->video.vram);
861-
if (value != oldValue) {
862-
STORE_16(value, address & 0x0001FFFE, gba->video.vram);
863-
gba->video.renderer->writeVRAM(gba->video.renderer, address & 0x0001FFFE);
867+
LOAD_16(oldValue, address & 0x00017FFE, gba->video.vram);
868+
if (value != oldValue) {
869+
STORE_16(value, address & 0x00017FFE, gba->video.vram);
870+
gba->video.renderer->writeVRAM(gba->video.renderer, address & 0x00017FFE);
871+
}
872+
} else {
873+
LOAD_16(oldValue, address & 0x0001FFFE, gba->video.vram);
874+
if (value != oldValue) {
875+
STORE_16(value, address & 0x0001FFFE, gba->video.vram);
876+
gba->video.renderer->writeVRAM(gba->video.renderer, address & 0x0001FFFE);
877+
}
864878
}
865879
break;
866880
case REGION_OAM:

src/gba/renderers/video-software.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,12 @@ static void _drawScanline(struct GBAVideoSoftwareRenderer* renderer, int y) {
834834
if ((y < sprite->y && (sprite->endY - 256 < 0 || y >= sprite->endY - 256)) || y >= sprite->endY) {
835835
continue;
836836
}
837-
if (GBAObjAttributesAIsMosaic(sprite->obj.a)) {
837+
if (GBAObjAttributesAIsMosaic(sprite->obj.a) && mosaicV > 1) {
838838
localY = mosaicY;
839-
if (localY < sprite->y) {
839+
if (localY < sprite->y && sprite->y < VIDEO_VERTICAL_PIXELS) {
840840
localY = sprite->y;
841841
}
842-
if (localY >= sprite->endY) {
842+
if (localY >= (sprite->endY & 0xFF)) {
843843
localY = sprite->endY - 1;
844844
}
845845
}

src/platform/openemu/mGBAGameCore.m

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ - (id)init
8787

8888
- (void)dealloc
8989
{
90+
mCoreConfigDeinit(&core->config);
9091
core->deinit(core);
9192
//[cheatSets release];
9293
free(outputBuffer);

0 commit comments

Comments
 (0)