Skip to content

Commit 2c6e1f2

Browse files
committed
GBA: Fixed compilation on all targets
1 parent e1d6642 commit 2c6e1f2

File tree

7 files changed

+49
-12
lines changed

7 files changed

+49
-12
lines changed

gbsp/components/gbsp-libretro/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ set(COMPONENT_ADD_INCLUDEDIRS ". libretro/libretro-common/include")
33
set(COMPONENT_REQUIRES "retro-go")
44
register_component()
55
rg_setup_compile_options(
6-
-O2
6+
-O3
77
-fomit-frame-pointer -ffast-math
88
-DOVERCLOCK_60FPS
9+
-DROM_BUFFER_SIZE=2
910
-Wno-unused-variable
1011
-Wno-implicit-fallthrough
1112
-Wno-missing-field-initializers

gbsp/components/gbsp-libretro/cpu.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,13 +1450,15 @@ u32 reg[64];
14501450
u32 spsr[6];
14511451
u32 reg_mode[7][7];
14521452

1453-
EXT_RAM_ATTR u8 *memory_map_read [8 * 1024];
14541453
u16 oam_ram[512];
14551454
u16 palette_ram[512];
14561455
u16 palette_ram_converted[512];
1457-
EXT_RAM_ATTR u8 ewram[1024 * 256 * 2];
1458-
EXT_RAM_ATTR u8 iwram[1024 * 32 * 2];
1459-
EXT_RAM_ATTR u8 vram[1024 * 96];
1456+
#ifndef RETRO_GO
1457+
u8 ewram[1024 * 256 * 2];
1458+
u8 iwram[1024 * 32 * 2];
1459+
u8 vram[1024 * 96];
1460+
u8 *memory_map_read[8 * 1024];
1461+
#endif
14601462
u16 io_registers[512];
14611463
#endif
14621464

gbsp/components/gbsp-libretro/gba_memory.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,12 @@ const u32 def_seq_cycles[16][2] =
336336
{ 9, 17 }, // Gamepak (wait 2)
337337
};
338338

339-
340-
EXT_RAM_ATTR u8 bios_rom[1024 * 16];
339+
#ifndef RETRO_GO
340+
u8 bios_rom[1024 * 16];
341341

342342
// Up to 128kb, store SRAM, flash ROM, or EEPROM here.
343-
EXT_RAM_ATTR u8 gamepak_backup[1024 * 128];
343+
u8 gamepak_backup[1024 * 128];
344+
#endif
344345

345346
u32 dma_bus_val;
346347
dma_transfer_type dma[4];

gbsp/components/gbsp-libretro/gba_memory.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ extern u32 oam_update;
258258
extern u32 gbc_sound_wave_update;
259259
extern dma_transfer_type dma[DMA_CHAN_CNT];
260260

261-
extern const u8 open_gba_bios_rom[1024*16];
262261
extern u16 palette_ram[512];
263262
extern u16 oam_ram[512];
264263
extern u16 palette_ram_converted[512];
@@ -328,4 +327,32 @@ bool memory_check_savestate(const u8*src);
328327
bool memory_read_savestate(const u8*src);
329328
unsigned memory_write_savestate(u8 *dst);
330329

330+
331+
#ifdef RETRO_GO
332+
// We wrap certain globals to move them under a dynamic allocation, whilst still preserving the functionality
333+
// of any code treating them as fixed arrays. This results in very minimal code changes to the rest of gbSP.
334+
typedef struct
335+
{
336+
// TODO: Evaluate what is best left in internal memory for performance reasons (for the few that could fit)
337+
u8 vram[1024 * 96];
338+
u8 bios_rom[1024 * 16];
339+
u8 ewram[1024 * 256 * 2];
340+
u8 iwram[1024 * 32 * 2];
341+
u8 *memory_map_read[8 * 1024];
342+
u8 gamepak_backup[1024 * 128];
343+
// There's also stuff from video.cpp to consider:
344+
// u8 obj_priority_list[5][160][128];
345+
// u8 obj_priority_count[5][160];
346+
// u8 obj_alpha_count[160];
347+
} gbsp_memory_t;
348+
349+
extern gbsp_memory_t *gbsp_memory;
350+
#define vram gbsp_memory->vram
351+
#define bios_rom gbsp_memory->bios_rom
352+
#define ewram gbsp_memory->ewram
353+
#define iwram gbsp_memory->iwram
354+
#define memory_map_read gbsp_memory->memory_map_read
355+
#define gamepak_backup gbsp_memory->gamepak_backup
356+
#endif
357+
331358
#endif

gbsp/components/gbsp-libretro/gpsp_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Default ROM buffer size in megabytes (this is a maximum value!) */
1010
#ifndef ROM_BUFFER_SIZE
11-
#define ROM_BUFFER_SIZE 2
11+
#define ROM_BUFFER_SIZE 32
1212
#endif
1313

1414
/* Cache sizes and their config knobs */

gbsp/main/main.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ boot_mode selected_boot_mode = boot_game;
2020
u32 skip_next_frame = 0;
2121
int sprite_limit = 1;
2222

23+
gbsp_memory_t *gbsp_memory;
24+
2325
static rg_surface_t *updates[2];
2426
static rg_surface_t *currentUpdate;
2527
static rg_app_t *app;
2628

2729
void netpacket_poll_receive()
2830
{
2931
}
32+
3033
void netpacket_send(uint16_t client_id, const void *buf, size_t len)
3134
{
3235
}
@@ -95,11 +98,14 @@ void app_main(void)
9598

9699
updates[0] = rg_surface_create(GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT + 1, RG_PIXEL_565_LE, MEM_FAST);
97100
updates[0]->height = GBA_SCREEN_HEIGHT;
101+
// updates[1] = rg_surface_create(GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT + 1, RG_PIXEL_565_LE, MEM_FAST);
102+
// updates[1]->height = GBA_SCREEN_HEIGHT;
98103
currentUpdate = updates[0];
99104

100105
gba_screen_pixels = currentUpdate->data;
101106

102-
RG_LOGI("GBA");
107+
gbsp_memory = rg_alloc(sizeof(*gbsp_memory), MEM_ANY);
108+
RG_LOGI("gbsp_memory=%p", gbsp_memory);
103109

104110
libretro_supports_bitmasks = true;
105111
retro_set_input_state(input_cb);

rg_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'prboom-go': [0, 0, 851968],
2222
'gwenesis': [0, 0, 983040],
2323
'fmsx': [0, 0, 589824],
24-
'gbsp': [0, 0, 589824],
24+
'gbsp': [0, 0, 851968],
2525
}
2626
# PROJECT_APPS = {}
2727
# for t in glob.glob("*/CMakeLists.txt"):

0 commit comments

Comments
 (0)