From 82a8448d616507698b75962ea291954aa7a0db54 Mon Sep 17 00:00:00 2001 From: "U-OMMADAWN\\slack" Date: Wed, 17 Sep 2008 03:47:50 +0200 Subject: [PATCH] Initial joypad+buttons input support. Some games are quasi-playable now ;) --- GBMemory.cc | 6 ++- GBMemory.h | 2 + gbcore.cc | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++ gbcore.h | 16 +++++++ 4 files changed, 141 insertions(+), 1 deletion(-) diff --git a/GBMemory.cc b/GBMemory.cc index 5a8e118..25d86fe 100644 --- a/GBMemory.cc +++ b/GBMemory.cc @@ -55,7 +55,11 @@ void GBMemory::write(u16 addr, u8 value, WatchpointControl watch) else if (addr < 0xE000) WRAM[addr - WRAM_BASE] = value; else if (addr < 0xFE00) write(addr-0x2000, value); else if (addr < 0xFEA0) core->video.write_OAM (addr, value); - else if (addr >= 0xFF00) { + else if (addr == 0xFF00) { + high[0] = (high[0] & 0xCF) | (value & 0x30); + core->update_JOYP(); + } + else if (addr > 0xFF00) { high[addr-0xFF00] = value; if (addr == DIV) { diff --git a/GBMemory.h b/GBMemory.h index ba34be8..6b9aa68 100644 --- a/GBMemory.h +++ b/GBMemory.h @@ -85,6 +85,7 @@ class GBMemory void write (u16 addr, u8 value, WatchpointControl watch = WATCH); public: + static const u16 JOYP = 0xFF00; // Joypad (R/W) static const u16 DIV = 0xFF04; // Divider register (R/W) static const u16 TIMA = 0xFF05; // Timer counter (R/W) static const u16 TMA = 0xFF06; // Timer modulo (R/W) @@ -105,6 +106,7 @@ class GBMemory static const u16 IE = 0xFFFF; // Interrupt enable (R/W) private: + static const u16 I_JOYP = 0xFF00 - IO_BASE; // Joypad (R/W) static const u16 I_DIV = 0xFF04 - IO_BASE; // Divider register (R/W) static const u16 I_TIMA = 0xFF05 - IO_BASE; // Timer counter (R/W) static const u16 I_TMA = 0xFF06 - IO_BASE; // Timer modulo (R/W) diff --git a/gbcore.cc b/gbcore.cc index a744d18..7e9d48d 100644 --- a/gbcore.cc +++ b/gbcore.cc @@ -70,6 +70,7 @@ void GameBoy::reset() memory.write(i, 0); } + memory.write(0xFF00, 0xFF); // TIMA memory.write(0xFF05, 0x00); // TIMA memory.write(0xFF06, 0x00); // TMA memory.write(0xFF07, 0x00); // TAC @@ -105,6 +106,9 @@ void GameBoy::reset() memory.write(0xFF4A, 0x00); // WY memory.write(0xFF4B, 0x00); // WX memory.write(0xFFFF, 0x00); // IE + + for (int i=0; i