Skip to content

Commit

Permalink
added support for emulator build
Browse files Browse the repository at this point in the history
- Allows build compatible with Dolphin emulator for easy testing.
  • Loading branch information
yo1dog committed Nov 5, 2024
1 parent a163d17 commit 2a2afa5
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ipl.rom
*.zip

/subprojects/libogc2
/subprojects/libfat

!res/qoob_pro_none_upgrade.elf
!res/qoob_sx_13c_upgrade.elf
Expand Down
10 changes: 6 additions & 4 deletions buildtools/qoob_injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
out = bytearray(f.read())

if bios.endswith(".gcb"):
if len(img) > 128 * 1024:
raise "Qoob Pro BIOS image too big to fit in flasher"
oversize_bytes = len(img) - (128 * 1024)
if oversize_bytes > 0:
raise Exception("Qoob Pro BIOS image too big to fit in flasher. %i bytes too large" % (oversize_bytes))

msg = b"gekkoboot for QOOB Pro\0"
msg_offset = 0x1A68
img_offset = 0x1AE0

if bios.endswith(".qbsx"):
if len(img) > 62800:
raise "Qoob SX BIOS image too big to fit in flasher"
oversize_bytes = len(img) - 62800
if oversize_bytes > 0:
raise Exception("Qoob SX BIOS image too big to fit in flasher. %i bytes too large" % (oversize_bytes))

msg = b"gekkoboot for QOOB SX\0"
msg_offset = 7240
Expand Down
3 changes: 2 additions & 1 deletion devkitPPC.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[constants]
prefix = 'powerpc-eabi-'
common_args = ['-DGEKKO','-mogc','-mcpu=750','-meabi','-mhard-float']
platform_args = ['-mogc']
common_args = ['-DGEKKO','-mcpu=750','-meabi','-mhard-float'] + platform_args
link_args = []

[binaries]
Expand Down
2 changes: 2 additions & 0 deletions devkitPPCEmu.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[constants]
platform_args = ['-mrvl','-DEMU_BUILD']
256 changes: 147 additions & 109 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@ project(
},
)

emu_build = get_option('emu_build')

platform = 'cube'
libogc_libs = ['ogc']

if emu_build
platform = 'wii'
libogc_libs += ['bte', 'wiiuse']
endif

libogc_proj = subproject(
'libogc2',
default_options: {
'libraries': ['ogc'],
'platform': platform,
'libraries': libogc_libs,
},
)
libogc_deps = libogc_proj.get_variable('deps')
libogc_deps_dic = libogc_proj.get_variable('deps')
libogc_deps = []
foreach lib : libogc_libs
libogc_deps += [libogc_deps_dic[lib]]
endforeach

if emu_build
libfat_proj = subproject('libfat')
libfat_dep = libfat_proj.get_variable('dep')
endif

subdir('buildtools')
subdir('res')
Expand All @@ -33,8 +53,6 @@ compressed_exes = {}

subdir('stub')

linker_script = meson.current_source_dir() / 'ogc.ld'

git = find_program('git')
version_file = vcs_tag(
command: [git, 'describe', '--always', '--tags', '--dirty'],
Expand All @@ -49,6 +67,18 @@ font = custom_target(
command: [psf2c, '@INPUT@', '@OUTPUT@', 'console_font_8x16'],
)

gekkoboot_link_args = []
gekkoboot_link_depends = []
if emu_build
# Always link the math library because it is used by wiiuse.
# It is never explicitly included so the --as-needed flag would omit it otherwise.
gekkoboot_link_args += ['-lm']
else
linker_script = meson.current_source_dir() / 'ogc.ld'
gekkoboot_link_args += ['-T' + linker_script]
gekkoboot_link_depends += [linker_script]
endif

gekkoboot = executable(
'gekkoboot',
'source/main.c',
Expand All @@ -64,41 +94,47 @@ gekkoboot = executable(
'source/inih/ini.c',
version_file,
font,
dependencies: [
libogc_deps['ogc'],
stub_dep,
],
link_args: ['-T' + linker_script],
link_depends: [linker_script],
dependencies: (
libogc_deps +
[stub_dep] +
(emu_build? [libfat_dep] : [])
),
link_args: gekkoboot_link_args,
link_depends: gekkoboot_link_depends,
name_suffix: 'elf',
)
compressed_exes += {
'gekkoboot': {
'exe': gekkoboot,
'link_args': [
'-Wl,--section-start,.init=0x01300000'
],
'dol': true,
},
'gekkoboot_sx': {
'exe': gekkoboot,
'link_args': [
# This is the same entry point as the original BIOS,
# but the recovery slot hangs on "starting flashed app..."
# when loading it. A lowmem image works just fine.
#'-Wl,--section-start,.init=0x01500000',

# Makes the ELF smaller so it actually fits
'-Wl,--nmagic',
],
},
'gekkoboot_lowmem': {
'exe': gekkoboot,
'dol': true,
},
}

subdir('packer')
if emu_build
dols += {'gekkoboot_emu': gekkoboot}
else
compressed_exes += {
'gekkoboot': {
'exe': gekkoboot,
'link_args': [
'-Wl,--section-start,.init=0x01300000'
],
'dol': true,
},
'gekkoboot_sx': {
'exe': gekkoboot,
'link_args': [
# This is the same entry point as the original BIOS,
# but the recovery slot hangs on "starting flashed app..."
# when loading it. A lowmem image works just fine.
#'-Wl,--section-start,.init=0x01500000',

# Makes the ELF smaller so it actually fits
'-Wl,--nmagic',
],
},
'gekkoboot_lowmem': {
'exe': gekkoboot,
'dol': true,
},
}

subdir('packer')
endif

foreach name, exe: dols
dol = custom_target(
Expand All @@ -111,87 +147,89 @@ foreach name, exe: dols
set_variable(name + '_dol', dol)
endforeach

if full_rom_opt.allowed()
qoob_pro = custom_target(
'qoob_pro',
input: [gekkoboot_dol, ipl_rom],
output: 'gekkoboot_qoob_pro.gcb',
if not emu_build
if full_rom_opt.allowed()
qoob_pro = custom_target(
'qoob_pro',
input: [gekkoboot_dol, ipl_rom],
output: 'gekkoboot_qoob_pro.gcb',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/qoob_pro',
)
qoob_pro_updater_tgt = custom_target(
'qoob_pro_updater',
input: [qoob_pro, qoob_pro_updater],
output: 'qoob_pro_gekkoboot_upgrade.elf',
command: [qoob_injector, '@INPUT@', '@OUTPUT@'],
build_by_default: true,
install: true,
install_dir: '/qoob_pro',
)
endif

gekkoboot_sx_stripped = custom_target(
gekkoboot_sx_compressed.name() + '_stripped',
input: gekkoboot_sx_compressed,
output: gekkoboot_sx_compressed.name() + '_stripped.elf',
command: [objcopy, '-S', '@INPUT@', '@OUTPUT@'],
)
qoob_sx = custom_target(
'qoob_sx',
input: gekkoboot_sx_stripped,
output: 'gekkoboot_qoob_sx.qbsx',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/qoob_pro',
)
qoob_pro_updater_tgt = custom_target(
'qoob_pro_updater',
input: [qoob_pro, qoob_pro_updater],
output: 'qoob_pro_gekkoboot_upgrade.elf',
qoob_sx_updater_tgt = custom_target(
'qoob_sx_updater',
input: [qoob_sx, qoob_sx_updater],
output: 'qoob_sx_gekkoboot_upgrade.elf',
command: [qoob_injector, '@INPUT@', '@OUTPUT@'],
build_by_default: true,
install: true,
install_dir: '/qoob_pro',
install_dir: '/',
)
endif

gekkoboot_sx_stripped = custom_target(
gekkoboot_sx_compressed.name() + '_stripped',
input: gekkoboot_sx_compressed,
output: gekkoboot_sx_compressed.name() + '_stripped.elf',
command: [objcopy, '-S', '@INPUT@', '@OUTPUT@'],
)
qoob_sx = custom_target(
'qoob_sx',
input: gekkoboot_sx_stripped,
output: 'gekkoboot_qoob_sx.qbsx',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
)
qoob_sx_updater_tgt = custom_target(
'qoob_sx_updater',
input: [qoob_sx, qoob_sx_updater],
output: 'qoob_sx_gekkoboot_upgrade.elf',
command: [qoob_injector, '@INPUT@', '@OUTPUT@'],
build_by_default: true,
install: true,
install_dir: '/',
)

viper = custom_target(
'viper',
input: gekkoboot_dol,
output: 'gekkoboot_viper.vgc',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/',
)
viper = custom_target(
'viper',
input: gekkoboot_dol,
output: 'gekkoboot_viper.vgc',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/',
)

pico = custom_target(
'pico',
input: gekkoboot_dol,
output: 'gekkoboot_pico.uf2',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/',
)
pico = custom_target(
'pico',
input: gekkoboot_dol,
output: 'gekkoboot_pico.uf2',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/',
)

gci = custom_target(
'gci',
input: gekkoboot_lowmem_dol,
output: 'gekkoboot_memcard.gci',
command: [dol2gci, '@INPUT@', '@OUTPUT@', 'boot.dol'],
build_by_default: true,
install: true,
install_dir: '/',
)
gci = custom_target(
'gci',
input: gekkoboot_lowmem_dol,
output: 'gekkoboot_memcard.gci',
command: [dol2gci, '@INPUT@', '@OUTPUT@', 'boot.dol'],
build_by_default: true,
install: true,
install_dir: '/',
)

apploader = custom_target(
'apploader',
input: gekkoboot_dol,
output: 'apploader.img',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/swiss_igr/swiss/patches',
)
apploader = custom_target(
'apploader',
input: gekkoboot_dol,
output: 'apploader.img',
command: [dol2ipl, '@OUTPUT@', '@INPUT@'],
build_by_default: true,
install: true,
install_dir: '/swiss_igr/swiss/patches',
)

install_data('README.md', install_dir: '/')
install_data('README.md', install_dir: '/')
endif
1 change: 1 addition & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
option('full_rom', type: 'feature', description: 'Whether to enable full ROM builds (Qoob Pro support)')
option('emu_build', type: 'boolean', value: false)
2 changes: 1 addition & 1 deletion packer/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packer_stub = static_library(
link_with: packer_crt,
dependencies: [
# For the headers
libogc_deps['ogc'].partial_dependency(
libogc_deps_dic['ogc'].partial_dependency(
compile_args: true,
sources: true,
),
Expand Down
5 changes: 5 additions & 0 deletions source/filesystem.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "filesystem.h"

#ifdef EMU_BUILD
#include "filesystem_emu.c"
#else
#include "fatfs/ff.h"
#include "ffshim.h"
#include <ogc/system.h>
Expand Down Expand Up @@ -72,6 +76,7 @@ _fs_read_file(void **contents_, const char *path, int is_string) {
*contents_ = contents;
return FS_OK;
}
#endif

FS_RESULT
fs_read_file(void **contents, const char *path) {
Expand Down
Loading

0 comments on commit 2a2afa5

Please sign in to comment.