GithubHelp home page GithubHelp logo

emrsmsrli / gameboiadvance Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 4.49 MB

A Gameboy Advance emulator that kinda works

License: GNU General Public License v3.0

CMake 2.60% C++ 97.40%
emulator emulators gameboy-advance gameboy gameboy-emulator gameboy-advance-emulator cpp cpp17 sdl2 sfml

gameboiadvance's Introduction

gameboi advance

Build Status GitHub license

A Game Boy Advance emulator built upon the GBC emulator gameboi

Features

gameboiadvance does not aim to be the perfect emulator, its features are limited compared to other emulators.

  • Accurate ARM7 emulation
  • Scanline based PPU emulation
  • APU emulation (based on gameboi)
  • Accurate DMA interleaving
  • EEPROM, FLASH and SRAM save-load capability
  • RTC support (sadly, no other GPIO extensions)
  • Gamepak prefetch emulation
  • Disassembler and a powerful debugger
    • Capable of showing all the internals of the emulator
    • Execution and data access breakpoint support

Feature TODO

  • SIO emulation, and networked multiplayer support

Screenshots

Using as a library

gameboiadvance library can be easily integrated to your own frontend implementation:

#include <gba/core.h>

// WITH_DEBUGGER can be set with CMake argument -DWITH_DEBUGGER=ON
#if WITH_DEBUGGER
  #include <gba_debugger/debugger.h>
#endif // WITH_DEBUGGER

void on_scanline(const gba::u8 line_number, const gba::ppu::scanline_buffer& buffer) noexcept;
void on_vblank() noexcept;
void on_audio(const gba::vector<gba::apu::stereo_sample<float>>& buffer) noexcept;

int main(int argc, char* argv[]) 
{
    // BIOS is required to boot
    gba::core core{"file/path/to/bios.gba"};
    core.load_pak("file/path/to/rom.gba");

#if WITH_DEBUGGER
    gba::debugger::window debugger_window(&core);

    while(true) {
        // debugger window handles input, video and audio output
        debugger_window.tick();
    }
#else
    core.on_scanline_event().add_delegate(gba::connect_arg<&on_scanline>);
    core.on_vblank_event().add_delegate(gba::connect_arg<&on_vblank>);
    core.sound_buffer_overflow_event().add_delegate(gba::connect_arg<&on_audio>);

    // optionally set audio generation parameters
    // core.set_dst_sample_rate(some_audio_device.sample_rate());
    // core.set_sound_buffer_capacity(some_audio_device.sample_count());

    while(true) {
        // core.press_key(gba::keypad::key::a);
        // core.release_key(gba::keypad::key::start);

        core.tick_one_frame();
        // or core.tick(n); which executes at least `n` cycles every iteration
    }
#endif // WITH_DEBUGGER

    return 0;
}

Compiling

Dependencies

  • CMake 3.16
  • fmt (as git submodule)
  • spdlog (as git submodule)
  • SFML
  • SDL2 (for sound only)

Install dependencies however you like. Below example is installing using vcpkg, in Ubuntu:

$ git clone https://github.com/Microsoft/vcpkg.git
$ ./vcpkg/bootstrap-vcpkg.sh -disableMetrics
$ ./vcpkg/vcpkg install sfml sdl2
$ sudo apt install cmake

Compile using CMake

gameboiadvance uses CMake and can be easily built with a script like below.

$ mkdir build && cd build
$ cmake --config Release --target gameboiadvance ..
$ cmake --build -- -j $(nproc)

gameboiadvance's People

Contributors

emrsmsrli avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

gameboiadvance's Issues

ARM Debugger

Implement a debugger module which shows the current CPU state

  • Registers with all modes
  • Pipeline state
  • Timers
  • DMA states
  • Disassembly around PC (?)
  • Halt state
  • Interrupts
  • BIOS latch
  • Open bus value
  • Breakpoints

Gamepak

See this GBATEK section.

Rough TODO list:

  • Pull metadata from cartridge header
  • Search for backup id string in rom
    • Optionally add some backup type database consisting roms with known save types
  • Implement backup types
    • SRAM/FRAM
    • EEPROM
    • Flash ROM
  • Implement some GPIO functionality. Maybe only RTC?
  • Implement erase, write etc timings

Memory view debugger

Should show the contents of memory within a certain region.
Included regions taken from GBATEK:

General Internal Memory

00000000-00003FFF BIOS - System ROM
00004000-01FFFFFF Not used
02000000-0203FFFF WRAM - On-board Work RAM
02040000-02FFFFFF Not used
03000000-03007FFF WRAM - On-chip Work RAM
03008000-03FFFFFF Not used
04000000-040003FE I/O Register
04000400-04FFFFFF Not used

Internal Display Memory

05000000-050003FF BG/OBJ Palette RAM
05000400-05FFFFFF Not used
06000000-06017FFF VRAM - Video RAM
06018000-06FFFFFF Not used
07000000-070003FF OAM - OBJ Attributes
07000400-07FFFFFF Not used

External Memory (Game Pak)

08000000-09FFFFFF Game Pak ROM/FlashROM (max 32MB)
0A000000-0BFFFFFF Game Pak ROM/FlashROM (max 32MB)
0C000000-0DFFFFFF Game Pak ROM/FlashROM (max 32MB)
0E000000-0E00FFFF Game Pak SRAM

  • ewram
  • iwram
  • io regs
  • palette ram
  • vram
  • oam
  • pak rom
  • pak backup memory

Stack based vector

implement a stack based vector (or use PMR) for use in hot loops, where variable size container are needed (i.e block data transfer -> generate rlist)

ARM7

This issue tracks ARM7TDMI emulation

  • ARM instructions
    • DataProc
    • PSR
    • BX
    • Multiply
    • MulLong
    • Trans
    • Undefined
    • BlockTrans
    • B,BL
    • SWI
  • Thumb instructions
    • move_shifted_reg
    • add_subtract
    • mov_cmp_add_sub_imm
    • alu
    • hireg_bx
    • pc_rel_load
    • ld_str_reg
    • ld_str_sign_extended_byte_hword
    • ld_str_imm
    • ld_str_hword
    • ld_str_sp_relative
    • ld_addr
    • add_offset_to_sp
    • push_pop
    • ld_str_multiple
    • branch_cond
    • swi_thumb
    • branch
    • long_branch_link
  • Timers
  • Interrupt handling
  • Interrupt delay
  • Halt, stop mode

PPU debugger

  • Registers
  • BG views
    • BG0
    • BG1
    • BG2 (also bitmap view)
    • BG3
  • OAM view
  • Tile view
  • Palette view
  • Screen buffer
  • Window buffer

Input controller

Implement input controller as follows:

  • KEYINPUT reg, status of keys
  • KEYCNT reg, irq control

DMA interleaving issues

When 3 channels are running simultaneously, the length field of the last one gets corrupted. this generally happens in the case of dma1(fifo) + dma2(fifo) + dma3(imm).

Take Mother 3 for example, it freezes the emulator on title screen, or shortly after the game begins

Broken backup systems

  • EEPROM4 is not being detected
  • EEPROM is not really working, games report "cannot save" messages

Serial IO

  • SIO Normal Mode
  • SIO Multi-Player Mode
  • SIO UART Mode
  • SIO JOY BUS Mode
  • SIO General-Purpose Mode
  • Implement actual connection using sfml network module

Gamepak debugger

Should show gamepak metadata info.

  • Pak path
  • Title
  • Game code
  • Maker code
  • Checksum
  • Backup type string

Optionally show memory views of the Pak and the backup medium. Or alternatively they should be shown in memory debugger mentioned in #4

TONC demos

A list of TONC demos. Won't try to run them all correctly probably:

  • bm_modes
  • brin_demo
  • bm_modes
  • brin_demo
  • first
  • hello
  • key_demo
  • m3_demo
  • pageflip
  • sbb_reg
  • second
  • bigmap
  • m7_demo_mb
  • obj_aff
  • sbb_aff
  • tmr_demo
  • txt_obj
  • dma_demo
  • m7_ex
  • obj_demo
  • snd1_demo
  • txt_se1
  • bld_demo
  • irq_demo
  • mos_demo
  • octtest
  • swi_demo
  • tte_demo
  • txt_se2
  • cbb_demo
  • m7_demo
  • oacombo
  • prio_demo
  • swi_vsync
  • txt_bm
  • win_demo

Video controller

This should be one of the hardest aspects of the emulator. Lots of things to do:

  • DISPCNT and GREEN SWAP registers
  • DISPSTAT and VCOUNT registers
  • BG*CNT registers (1-4)
  • bg offset registers
  • bg rotate scale registers
  • window registers
  • mosaic
  • special color effect regs (alpha blending etc)
  • see TIMINGS (render takes 4 cpu cycle per dot)
  • bitmap rendering
  • normal bg rendering
  • affine bg rendering
  • obj rendering
  • composition
    • blending
    • windowing
    • obj windowing

Disassembler

Implement a full fledged disassembler.

ARM instructions

  • Branch and Branch with Link (B, BL, BX, SWI)
  • Data Processing (ALU)
  • Multiply and Multiply-Accumulate (MUL, MLA)
  • PSR Transfer (MRS, MSR)
  • Memory: Single Data Transfer (LDR, STR)
  • Memory: Halfword, Doubleword, and Signed Data Transfer
  • Memory: Block Data Transfer (LDM, STM)
  • Memory: Single Data Swap (SWP)
  • Coprocessor (MRC/MCR, LDC/STC, CDP, MCRR/MRRC) -- no need since GBA does not have any coprocessors

Thumb instructions

  • Register Operations (ALU, BX)
  • Memory Load/Store (LDR/STR)
  • Memory Addressing (ADD PC/SP)
  • Memory Multiple Load/Store (PUSH/POP and LDM/STM)
  • Jumps and Calls

Following format should be fine:
[address] | [instruction_dword] - [disassembly]

APU Debugger

  • Registers
  • FIFO representation
  • Wave ram memory view
  • Wave representations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.