mirror of https://github.com/mgba-emu/mgba.git
3DS: Use GBAContext
This commit is contained in:
parent
2c7926ef66
commit
ca42faae3c
|
@ -3,10 +3,10 @@
|
|||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
#include "gba/gba.h"
|
||||
#include "gba/video.h"
|
||||
|
||||
#include "gba/renderers/video-software.h"
|
||||
#include "gba/supervisor/context.h"
|
||||
#include "gba/video.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
#include "3ds-vfs.h"
|
||||
|
@ -19,6 +19,7 @@ static void GBA3DSLog(struct GBAThread* thread, enum GBALogLevel level, const ch
|
|||
static Handle logFile;
|
||||
|
||||
int main() {
|
||||
struct GBAContext context;
|
||||
srvInit();
|
||||
aptInit();
|
||||
hidInit(0);
|
||||
|
@ -32,41 +33,34 @@ int main() {
|
|||
FSUSER_OpenArchive(0, &sdmcArchive);
|
||||
FSUSER_OpenFile(0, &logFile, sdmcArchive, FS_makePath(PATH_CHAR, "/mgba.log"), FS_OPEN_WRITE | FS_OPEN_CREATE, FS_ATTRIBUTE_NONE);
|
||||
|
||||
GBAContextInit(&context, 0);
|
||||
struct GBAOptions opts = {
|
||||
.useBios = true,
|
||||
.logLevel = 0,
|
||||
.idleOptimization = IDLE_LOOP_REMOVE
|
||||
};
|
||||
GBAConfigLoadDefaults(&context.config, &opts);
|
||||
context.gba->logHandler = GBA3DSLog;
|
||||
|
||||
struct GBAVideoSoftwareRenderer renderer;
|
||||
GBAVideoSoftwareRendererCreate(&renderer);
|
||||
|
||||
size_t stride = VIDEO_HORIZONTAL_PIXELS * BYTES_PER_PIXEL;
|
||||
color_t* videoBuffer = anonymousMemoryMap(stride * VIDEO_VERTICAL_PIXELS);
|
||||
struct GBA* gba = anonymousMemoryMap(sizeof(struct GBA));
|
||||
struct ARMCore* cpu = anonymousMemoryMap(sizeof(struct ARMCore));
|
||||
int activeKeys = 0;
|
||||
|
||||
renderer.outputBuffer = videoBuffer;
|
||||
renderer.outputBufferStride = VIDEO_HORIZONTAL_PIXELS;
|
||||
GBAVideoAssociateRenderer(&context.gba->video, &renderer.d);
|
||||
|
||||
struct VFile* rom = VFileOpen3DS(&sdmcArchive, "/rom.gba", FS_OPEN_READ);
|
||||
struct VFile* save = VFileOpen3DS(&sdmcArchive, "/rom.sav", FS_OPEN_READ | FS_OPEN_WRITE);
|
||||
GBAContextLoadROM(&context, "/rom.gba", true);
|
||||
GBAContextStart(&context);
|
||||
|
||||
GBACreate(gba);
|
||||
ARMSetComponents(cpu, &gba->d, 0, 0);
|
||||
ARMInit(cpu);
|
||||
|
||||
gba->keySource = &activeKeys;
|
||||
gba->sync = 0;
|
||||
|
||||
GBAVideoAssociateRenderer(&gba->video, &renderer.d);
|
||||
|
||||
GBALoadROM(gba, rom, save, 0);
|
||||
|
||||
gba->logHandler = GBA3DSLog;
|
||||
|
||||
ARMReset(cpu);
|
||||
|
||||
int frameCounter = 0;
|
||||
while (aptMainLoop()) {
|
||||
ARMRunLoop(cpu);
|
||||
hidScanInput();
|
||||
int activeKeys = hidKeysHeld() & 0x3FF;
|
||||
if (hidKeysDown() & KEY_X) {
|
||||
break;
|
||||
}
|
||||
GBAContextFrame(&context, activeKeys);
|
||||
|
||||
if (frameCounter != gba->video.frameCounter) {
|
||||
u16 width, height;
|
||||
u16* screen = (u16*) gfxGetFramebuffer(GFX_BOTTOM, GFX_BOTTOM, &height, &width);
|
||||
u32 startX = (width - VIDEO_HORIZONTAL_PIXELS) / 2;
|
||||
|
@ -80,23 +74,10 @@ int main() {
|
|||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
gspWaitForVBlank1();
|
||||
hidScanInput();
|
||||
activeKeys = hidKeysHeld() & 0x3FF;
|
||||
if (hidKeysDown() & KEY_X) {
|
||||
break;
|
||||
}
|
||||
frameCounter = gba->video.frameCounter;
|
||||
}
|
||||
}
|
||||
|
||||
ARMDeinit(cpu);
|
||||
GBADestroy(gba);
|
||||
|
||||
rom->close(rom);
|
||||
save->close(save);
|
||||
|
||||
mappedMemoryFree(gba, 0);
|
||||
mappedMemoryFree(cpu, 0);
|
||||
GBAContextStop(&context);
|
||||
GBAContextDeinit(&context);
|
||||
|
||||
mappedMemoryFree(videoBuffer, 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue