Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/build-gameboy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Game Boy Build

on:
push:
branches: [ main ]
paths:
- 'targets/gameboy/**'
- 'backends/**'
- 'core/**'
- 'drivers/gb_sound/**'
- '.github/workflows/build-gameboy.yml'
pull_request:
branches: [ main ]
paths:
- 'targets/gameboy/**'
- 'backends/**'
- 'core/**'
- 'drivers/gb_sound/**'
- '.github/workflows/build-gameboy.yml'
workflow_dispatch:

jobs:

build-gameboy:
name: Game Boy ROM (GBDK-2020)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install GBDK-2020
run: |
wget -q https://github.com/gbdk-2020/gbdk-2020/releases/download/4.5.0/gbdk-linux64.tar.gz
tar -xzf gbdk-linux64.tar.gz
echo "GBDKDIR=$GITHUB_WORKSPACE/gbdk/" >> $GITHUB_ENV
echo "$GITHUB_WORKSPACE/gbdk/bin" >> $GITHUB_PATH

- name: Build Game Boy ROM
run: |
make -C targets/gameboy/

- name: Verify Game Boy ROM Output
run: |
if [ -f targets/gameboy/out/rom.gb ] && [ -f targets/gameboy/out/rom.gbc ]; then
echo "Successfully generated rom.gb and rom.gbc!"
ls -la targets/gameboy/out/
else
echo "Error: ROM output missing!"
ls -la targets/gameboy/out/ || true
false
fi

- name: Upload Game Boy ROM
uses: actions/upload-artifact@v4
with:
name: RDJ-gameboy-rom
path: |
targets/gameboy/out/rom.gb
targets/gameboy/out/rom.gbc
4 changes: 4 additions & 0 deletions .github/workflows/build-genesis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- 'backends/**'
- 'core/**'
- 'drivers/ym2612/**'
- 'drivers/gb_sound/**'
- 'tests/**'
- '.github/workflows/build-genesis.yml'
pull_request:
Expand All @@ -17,6 +18,7 @@ on:
- 'backends/**'
- 'core/**'
- 'drivers/ym2612/**'
- 'drivers/gb_sound/**'
- 'tests/**'
- '.github/workflows/build-genesis.yml'
workflow_dispatch:
Expand Down Expand Up @@ -82,10 +84,12 @@ jobs:
tests/test_main.c \
drivers/ym2612/ym2612_rdj.c \
drivers/nes_2a03/2a03_rdj.c \
drivers/gb_sound/gb_rdj.c \
backends/backend_null.c \
backends/backend_vgm.c \
backends/backend_serial.c \
backends/backend_genesis_hw.c \
backends/backend_gb_hw.c \
targets/genesis/src/ui.c \
targets/genesis/src/input_mapper.c \
-I. -Icore/ -o test_runner
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
*.s
!targets/nes/src/crt0.s
out/
targets/gameboy/out/
test_runner
test_output.vgm

# GBDK intermediate build artifacts
*.ihx
*.lst
*.sym
*.noi
*.map

# SGDK copied sources
targets/genesis/src/core/
targets/genesis/src/drivers/
Expand Down
105 changes: 105 additions & 0 deletions backends/backend_gb_hw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* GPLv3 - RetroDJ Project - Game Boy Real Hardware Backend */

/*
* Copyright (C) 2025 RetroDJ Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should receive a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#if defined(RDJ_GENESIS_HARDWARE) || defined(SGDK_GCC) || defined(__m68k__)
#include <genesis.h>
#elif defined(__PORT_sm83) || defined(__TARGET_gb) || defined(GBDK)
#include <gb/gb.h>
#include <stdint.h>
#include <stddef.h>
#else
#include <stdint.h>
#include <stddef.h>
#endif

#include "core/rdj_backend.h"

#if !defined(__PORT_sm83) && !defined(__TARGET_gb) && !defined(GBDK)
static uint8_t gb_apu_shadow[0x40];
#endif

static void gb_hw_write_apu(uint16_t addr, uint8_t val) {
#if defined(__PORT_sm83) || defined(__TARGET_gb) || defined(GBDK)
*((volatile uint8_t*)addr) = val;
#else
if (addr >= 0xFF10 && addr <= 0xFF3F) {
gb_apu_shadow[addr - 0xFF10] = val;
}
#endif
}

static void gb_hw_init(void) {
/* Master enable APU: Bit 7 = 1 in NR52 ($FF26) */
gb_hw_write_apu(0xFF26, 0x80);
/* Enable all output channels to left and right terminals in NR51 ($FF25) */
gb_hw_write_apu(0xFF25, 0xFF);
/* Set max stereo master volume in NR50 ($FF24) */
gb_hw_write_apu(0xFF24, 0x77);
}

static void gb_hw_shutdown(void) {
/* Disable APU master enable */
gb_hw_write_apu(0xFF26, 0x00);
}

static void gb_hw_write_ym2612(uint8_t port, uint8_t reg, uint8_t val) {
(void)port;
(void)reg;
(void)val;
}

static void gb_hw_wait_samples(uint16_t samples) {
(void)samples;
}

static void gb_hw_wait_frame(void) {
#if defined(__PORT_sm83) || defined(__TARGET_gb) || defined(GBDK)
wait_vbl_done();
#endif
}

static const char gb_backend_name[] = "Game Boy Real Hardware Backend";

rdj_backend_t backend_gb_hw = {
gb_backend_name,
gb_hw_init,
gb_hw_shutdown,
gb_hw_write_ym2612,
gb_hw_write_apu,
gb_hw_wait_samples,
gb_hw_wait_frame
};

#if defined(__PORT_sm83) || defined(__TARGET_gb) || defined(GBDK)
rdj_backend_t *rdj_active_backend = &backend_gb_hw;

void rdj_set_backend(rdj_backend_t *backend) {
if (backend) {
if (rdj_active_backend && rdj_active_backend->shutdown) {
rdj_active_backend->shutdown();
}
rdj_active_backend = backend;
if (rdj_active_backend->init) {
rdj_active_backend->init();
}
} else {
rdj_active_backend = &backend_gb_hw;
}
}
#endif
Loading
Loading