Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Working GB ROM selection
Browse files Browse the repository at this point in the history
  • Loading branch information
nezza authored and kbeckmann committed Dec 27, 2020
1 parent d4854c7 commit da2df65
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 41 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ Makefile
Core/Inc/rom_info.h
roms

.mxproject
.mxproject

Core/Src/retro-go/nes_roms.c
Core/Src/retro-go/gb_roms.c
5 changes: 2 additions & 3 deletions Core/Inc/gb_rom.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#ifndef _GB_ROM_H_
#define _GB_ROM_H_

extern const unsigned char ROM_DATA[];
extern const unsigned ROM_DATA_LENGTH;

extern unsigned char *ROM_DATA;
extern unsigned ROM_DATA_LENGTH;

#endif
14 changes: 10 additions & 4 deletions Core/Src/porting/gb/main_gb.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ void pcm_submit() {
}
}

void app_main_gb(void)
{

rg_app_desc_t * init() {
odroid_gamepad_state_t joystick;

odroid_system_init(APP_ID, AUDIO_SAMPLE_RATE);
Expand Down Expand Up @@ -541,13 +541,19 @@ void app_main_gb(void)
if (!pause_pressed) {
state_load(&__SAVE_START__, &__SAVE_END__ - &__SAVE_START__);
}
return app;
}

void app_main_gb(void)
{
rg_app_desc_t *app = init();
odroid_gamepad_state_t joystick;


const int frameTime = get_frame_time(60);

while (true)
{
gui_redraw();
continue;


odroid_input_read_gamepad(&joystick);
Expand Down
6 changes: 5 additions & 1 deletion Core/Src/porting/odroid_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ bool odroid_input_key_is_pressed(odroid_gamepad_key_t key)
odroid_input_read_gamepad(&joystick);

if (key == ODROID_INPUT_ANY) {
return joystick.bitmask > 0 ? 1 : 0;
uint32_t buttons = buttons_get();
if(buttons) {
return true;
}
return false;
}

return joystick.values[key];
Expand Down
11 changes: 10 additions & 1 deletion Core/Src/porting/odroid_overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ int odroid_overlay_game_menu()
#include <stdio.h>
#include <math.h>

#include "gw_buttons.h"
#include "bitmaps/font_basic.h"
#include "odroid_system.h"
#include "odroid_overlay.h"
Expand Down Expand Up @@ -289,6 +290,10 @@ int odroid_overlay_dialog(const char *header, odroid_dialog_choice_t *options, i
odroid_overlay_draw_dialog(header, options, sel);

while (odroid_input_key_is_pressed(ODROID_INPUT_ANY));
uint32_t buttons = buttons_get();
while(buttons) {
buttons = buttons_get();
}

while (1)
{
Expand Down Expand Up @@ -365,10 +370,14 @@ int odroid_overlay_dialog(const char *header, odroid_dialog_choice_t *options, i
}

// usleep(20 * 1000UL);
HAL_Delay(20);
HAL_Delay(200);
}

odroid_input_wait_for_key(last_key, false);
buttons = buttons_get();
while(buttons) {
buttons = buttons_get();
}

odroid_display_force_refresh();

Expand Down
71 changes: 49 additions & 22 deletions Core/Src/retro-go/rg_emulators.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// #include "rg_favorites.h"
#include "bitmaps.h"
#include "gui.h"
#include "gb_rom.h"
#include "rom_manager.h"

static retro_emulator_t emulators[16];
static int emulators_count = 0;
Expand Down Expand Up @@ -100,13 +102,35 @@ void emulator_init(retro_emulator_t *emu)

printf("Retro-Go: Initializing emulator '%s'\n", emu->system_name);

retro_emulator_file_t *file = &emu->roms.files[emu->roms.count++];
strcpy(file->folder, "/");
strcpy(file->name, "test");
strcpy(file->ext, "gb");
file->emulator = (void*)emu;
file->crc_offset = emu->crc_offset;
file->checksum = 0;

const rom_system *system = rom_manager_system(&rom_mgr, emu->system_name);
if(system) {
emu->roms.files = malloc(system->roms_count * sizeof(retro_emulator_file_t));
for(int i=0; i < system->roms_count; i++) {
const rom_entry *rom = &system->roms[i];
retro_emulator_file_t *file = &emu->roms.files[emu->roms.count++];
// strcpy(file->folder, "/");
file->address = rom->flash_address;
file->size = rom->size;
strcpy(file->name, rom->rom_name);
strcpy(file->ext, system->extension);
}
} else {
while(1) {
lcd_backlight_on();
HAL_Delay(100);
lcd_backlight_off();
HAL_Delay(100);
}
}

// retro_emulator_file_t *file = &emu->roms.files[emu->roms.count++];
// strcpy(file->folder, "/");
// strcpy(file->name, "test");
// strcpy(file->ext, "gb");
// file->emulator = (void*)emu;
// file->crc_offset = emu->crc_offset;
// file->checksum = 0;


// char path[128];
Expand Down Expand Up @@ -153,15 +177,16 @@ void emulator_init(retro_emulator_t *emu)
// free(files);
}

const char *emu_get_file_path(retro_emulator_file_t *file)
const uint32_t *emu_get_file_address(retro_emulator_file_t *file)
{
static char buffer[192];
if (file == NULL) return NULL;
sprintf(buffer, "%s/%s.%s", file->folder, file->name, file->ext);
return (const char*)&buffer;
// static char buffer[192];
// if (file == NULL) return NULL;
// sprintf(buffer, "%s/%s.%s", file->folder, file->name, file->ext);
// return (const char*)&buffer;
return file->address;
}

bool emulator_build_file_object(const char *path, retro_emulator_file_t *file)
/*bool emulator_build_file_object(const char *path, retro_emulator_file_t *file)
{
const char *name = odroid_sdcard_get_filename(path);
const char *ext = odroid_sdcard_get_extension(path);
Expand All @@ -187,7 +212,7 @@ bool emulator_build_file_object(const char *path, retro_emulator_file_t *file)
}
return false;
}
}*/

void emulator_crc32_file(retro_emulator_file_t *file)
{
Expand Down Expand Up @@ -265,7 +290,7 @@ void emulator_show_file_info(retro_emulator_file_t *file)

sprintf(choices[0].value, "%.127s", file->name);
sprintf(choices[1].value, "%s", file->ext);
sprintf(choices[2].value, "%s", file->folder);
// sprintf(choices[2].value, "%s", file->folder);
// sprintf(choices[3].value, "%d KB", odroid_sdcard_get_filesize(emu_get_file_path(file)) / 1024);
sprintf(choices[3].value, "%d KB", 42);

Expand Down Expand Up @@ -331,16 +356,18 @@ void emulator_show_file_menu(retro_emulator_file_t *file)

void emulator_start(retro_emulator_file_t *file, bool load_state)
{
const char *path = emu_get_file_path(file);
assert(path != NULL);
const uint32_t address = emu_get_file_address(file);

printf("Retro-Go: Starting game: %s\n", path);
printf("Retro-Go: Starting game: %s\n", file->name);
ROM_DATA = address;
ROM_DATA_LENGTH = file->size;

odroid_settings_StartAction_set(load_state ? ODROID_START_ACTION_RESUME : ODROID_START_ACTION_NEWGAME);
odroid_settings_RomFilePath_set(path);
odroid_settings_commit();
// odroid_settings_StartAction_set(load_state ? ODROID_START_ACTION_RESUME : ODROID_START_ACTION_NEWGAME);
// odroid_settings_RomFilePath_set(path);
// odroid_settings_commit();

odroid_system_switch_app(((retro_emulator_t *)file->emulator)->partition);
// odroid_system_switch_app(((retro_emulator_t *)file->emulator)->partition);
app_main_gb();
}

void emulators_init()
Expand Down
3 changes: 2 additions & 1 deletion Core/Src/retro-go/rg_emulators.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
typedef struct {
char name[128];
char ext[8];
char folder[32];
// char folder[32];
uint32_t address;
size_t size;
size_t crc_offset;
uint32_t checksum;
Expand Down
8 changes: 5 additions & 3 deletions Core/Src/retro-go/rg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void retro_loop()

odroid_input_read_gamepad(&gui.joystick);

if (gui.idle_counter > 0 && gui.joystick.bitmask == 0)
uint32_t buttons = buttons_get();
if (gui.idle_counter > 0 && buttons == 0)
{
gui_event(TAB_IDLE, tab);

Expand Down Expand Up @@ -243,12 +244,13 @@ void retro_loop()
}
}

if (gui.joystick.bitmask) {

if (buttons) {
gui.idle_counter = 0;
} else {
gui.idle_counter++;
}

HAL_Delay(200);
// usleep(15 * 1000UL);
}
}
Expand Down
28 changes: 28 additions & 0 deletions Core/Src/retro-go/rom_manager.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "rom_manager.h"
#include <string.h>
#include "gb_rom.h"

unsigned char *ROM_DATA = NULL;
unsigned ROM_DATA_LENGTH;

#include "gb_roms.c"
#include "nes_roms.c"

const rom_system systems[] = {
nes_system,
gb_system
};

const rom_manager rom_mgr = {
.systems = systems,
.systems_count = sizeof(systems) / sizeof(rom_system)
};

const rom_system *rom_manager_system(const rom_manager *mgr, char *name) {
for(int i=0; i < mgr->systems_count; i++) {
if(strcmp(mgr->systems[i].system_name, name) == 0) {
return &mgr->systems[i];
}
}
return NULL;
}
26 changes: 26 additions & 0 deletions Core/Src/retro-go/rom_manager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <stdint.h>


typedef struct {
const char *rom_name;
uint32_t flash_address;
uint32_t size;
} rom_entry;

typedef struct {
char system_name[64];
const rom_entry *roms;
char *extension;
uint32_t roms_count;
} rom_system;

typedef struct {
const rom_system *systems;
uint32_t systems_count;
} rom_manager;

extern const rom_manager rom_mgr;

const rom_system *rom_manager_system(const rom_manager *mgr, char *name);
12 changes: 10 additions & 2 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ retro-go-stm32/components/miniz/miniz.c \
retro-go-stm32/retro-go/main/gui.c \
Core/Src/retro-go/rg_main.c \
Core/Src/retro-go/rg_emulators.c \
Core/Src/retro-go/rom_manager.c \
Core/Src/porting/odroid_settings.c \
Core/Src/retro-go/bitmaps/header_gb.c \
Core/Src/retro-go/bitmaps/header_nes.c \
Expand Down Expand Up @@ -249,19 +250,26 @@ $(BUILD_DIR):

OPENOCD ?= openocd
OCDIFACE ?= interface/stlink.cfg
TRANSPORT ?= hla_swd

# Starts openocd and attaches to the target. To be used with 'flashx' and 'gdb'
openocd:
$(OPENOCD) -f $(OCDIFACE) -c "transport select hla_swd" -f "target/stm32h7x.cfg" -c "reset_config none; init; halt"
$(OPENOCD) -f $(OCDIFACE) -c "transport select $(TRANSPORT)" -f "target/stm32h7x.cfg" -c "reset_config none; init; halt"
.PHONY: openocd


# Flashes using a new openocd instance
flash: $(BUILD_DIR)/$(TARGET).elf
$(OPENOCD) -f $(OCDIFACE) -c "transport select hla_swd" -f "target/stm32h7x.cfg" -c "reset_config none; program $(BUILD_DIR)/$(TARGET).elf reset exit"
$(OPENOCD) -f $(OCDIFACE) -c "transport select $(TRANSPORT)" -f "target/stm32h7x.cfg" -c "reset_config none; program $(BUILD_DIR)/$(TARGET).elf reset exit"
.PHONY: flash


# Flash without building or so
jflash:
$(OPENOCD) -f $(OCDIFACE) -c "transport select $(TRANSPORT)" -f "target/stm32h7x.cfg" -c "reset_config none; program $(BUILD_DIR)/$(TARGET).elf reset exit"
.PHONY: jflash


# Flashes using an existing openocd instance
flashx: $(BUILD_DIR)/$(TARGET).elf
echo "reset_config none; program $(BUILD_DIR)/$(TARGET).elf; reset run; exit" | nc localhost 4444
Expand Down
5 changes: 2 additions & 3 deletions Makefile.gb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ retro-go-stm32/gnuboy-go/components/gnuboy/lcd.c \
retro-go-stm32/gnuboy-go/components/gnuboy/loader.c \
retro-go-stm32/gnuboy-go/components/gnuboy/mem.c \
retro-go-stm32/gnuboy-go/components/gnuboy/rtc.c \
retro-go-stm32/gnuboy-go/components/gnuboy/sound.c \
roms/gb/loaded_gb_rom.c \
retro-go-stm32/gnuboy-go/components/gnuboy/sound.c


C_INCLUDES += \
Expand All @@ -48,7 +47,7 @@ C_INCLUDES += \

C_DEFS += \
-DIS_LITTLE_ENDIAN \
-DDISABLE_AHBRAM_DCACHE \
-DDISABLE_AHBRAM_DCACHE


REQUIRED_FILE=roms/gb/loaded_gb_rom.c
Expand Down
18 changes: 18 additions & 0 deletions STM32H7B0VBTx_FLASH.ld
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,29 @@ SECTIONS
*(.extflash_data)
. = ALIGN(4);
__extflash_data_end__ = .;
__extflash_odroid_start__ = .;
build_gb/main_gb.o (.text .text* .rodata .rodata*)
build_gb/sound.o (.text .text* .rodata .rodata*)
build_gb/odroid*.o (.text .text* .rodata .rodata*)
build_gb/rg*.o (.text .text* .rodata .rodata*)
build_gb/logo*.o (.text .text* .rodata .rodata*)
build_gb/rom_*.o (.text .text* .rodata .rodata*)
build_gb/miniz.o (.text .text* .rodata .rodata*)
build_gb/lupng.o (.text .text* .rodata .rodata*)
build_gb/gui.o (.text .text* .rodata .rodata*)
__extflash_odroid_end__ = .;
. = ALIGN(128K);
__extflash_game_rom_start__ = .;
. = ALIGN(4);
*(.extflash_game_rom)
. = ALIGN(4);
__extflash_game_rom_end__ = .;
. = ALIGN(128K);
__extflash_game_rom2_start__ = .;
. = ALIGN(4);
*(.extflash_game_rom2)
. = ALIGN(4);
__extflash_game_rom2_end__ = .;
__extflash_end__ = .;
} > EXTFLASH

Expand Down
Loading

0 comments on commit da2df65

Please sign in to comment.