diff --git a/mbc_none.cpp b/mbc_none.cpp index 6d23be9..9567ff3 100644 --- a/mbc_none.cpp +++ b/mbc_none.cpp @@ -1,6 +1,7 @@ #include "mbc_none.h" #include "mem.h" #include +#include namespace mbc_none { @@ -13,6 +14,26 @@ namespace mbc_none uint8_t tags[65536]; + uint8_t getKeypad(uint8_t value) + { + const uint8_t *keys = SDL_GetKeyboardState(NULL); + value = value & 0xf0; + if (value & 0x10) { + if (!keys[SDL_SCANCODE_RETURN]) value = value | 0x8; + if (!keys[SDL_SCANCODE_SPACE]) value = value | 0x4; + if (!keys[SDL_SCANCODE_Z]) value = value | 0x2; + if (!keys[SDL_SCANCODE_X]) value = value | 0x1; + } else if (value & 0x20) { + if (!keys[SDL_SCANCODE_DOWN]) value = value | 0x8; + if (!keys[SDL_SCANCODE_UP]) value = value | 0x4; + if (!keys[SDL_SCANCODE_LEFT]) value = value | 0x2; + if (!keys[SDL_SCANCODE_RIGHT]) value = value | 0x1; + } else { + value = value | 0x0f; + } + return value; + } + uint8_t readMem(uint16_t address) { if (address < 0x8000) { @@ -27,6 +48,9 @@ namespace mbc_none } else if (address < 0xFE00) { return wram[address - 0xE000]; } else { + if (address==0xFF00) { + hram[address - 0XFE00] = getKeypad(hram[address - 0XFE00]); + } return hram[address - 0XFE00]; } } @@ -46,6 +70,7 @@ namespace mbc_none wram[address - 0xE000] = value; } else { if ( (address==0xFF50) && ((value&0x01) != 1) ) return; //Only allow disabling boot room + if ( (address==0xFF00) ) { value = value & 0x30; } hram[address - 0xFE00] = value; } } diff --git a/sm83.cpp b/sm83.cpp index 80c1a4b..3a0dd6e 100644 --- a/sm83.cpp +++ b/sm83.cpp @@ -474,6 +474,7 @@ namespace sm83 void processInterrupts() { const uint8_t IF = mem::readMem(0xff0f); + if (ime==0) return; if ( (IF & 0x1f) == 0) return; DI(); PUSH(rPC);