diff --git a/source/frontends/ncurses/world.cpp b/source/frontends/ncurses/world.cpp index 886fc007..c5c889cd 100644 --- a/source/frontends/ncurses/world.cpp +++ b/source/frontends/ncurses/world.cpp @@ -48,6 +48,9 @@ namespace BYTE nextKey = 0; bool keyReady = false; + bool openApple = false; + bool solidApple = false; + bool g_bTextFlashState = false; void sig_handler(int signo) @@ -379,54 +382,59 @@ void VideoRedrawScreen() void ProcessKeyboard() { - int ch = wgetch(frame->getWindow()); + const int inch = wgetch(frame->getWindow()); + + int ch = ERR; + + switch (inch) + { + case ERR: + break; + case KEY_PPAGE: // Page Up + openApple = true; + break; + case KEY_NPAGE: // Page Down + solidApple = true; + break; + case '\n': + ch = 0x0d; // ENTER + break; + case KEY_BACKSPACE: + case KEY_LEFT: + ch = 0x08; + break; + case KEY_RIGHT: + ch = 0x15; + break; + case KEY_UP: + ch = 0x0b; + break; + case KEY_DOWN: + ch = 0x0a; + break; + case 0x14a: // DEL + ch = 0x7f; + break; + default: + if (inch < 0x80) + { + ch = inch; + // Standard for Apple II is Upper case + if (ch >= 'A' && ch <= 'Z') + { + ch += 'a' - 'A'; + } + else if (ch >= 'a' && ch <= 'z') + { + ch -= 'a' - 'A'; + } + } + } + if (ch != ERR) { - switch (ch) - { - case '\n': - ch = 0x0d; // ENTER - break; - case KEY_BACKSPACE: - case KEY_LEFT: - ch = 0x08; - break; - case KEY_RIGHT: - ch = 0x15; - break; - case KEY_UP: - ch = 0x0b; - break; - case KEY_DOWN: - ch = 0x0a; - break; - case 0x14a: // DEL - ch = 0x7f; - break; - default: - if (ch >= 0x80) - { - ch = ERR; - } - else - { - // Standard for Apple II is Upper case - if (ch >= 'A' && ch <= 'Z') - { - ch += 'a' - 'A'; - } - else if (ch >= 'a' && ch <= 'z') - { - ch -= 'a' - 'A'; - } - } - } - - if (ch != ERR) - { - nextKey = ch | 0x80; - keyReady = true; - } + nextKey = ch | 0x80; + keyReady = true; } } @@ -446,3 +454,42 @@ BYTE __stdcall KeybReadFlag (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyc nextKey = 0; return result; } + +BYTE __stdcall JoyReadButton(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) +{ + addr &= 0xFF; + BOOL pressed = 0; + + /* In ncurses it is not possible to detect key UP or DOWN, just characters. + So when do we stop advertising button pressed? + We read it once and then reset. + We should probably have a timer, like x ms after a press. + */ + + switch (addr) + { + case 0x61: + pressed = openApple; + openApple = false; + break; + case 0x62: + pressed = solidApple; + solidApple = false; + break; + case 0x63: + break; + } + return MemReadFloatingBus(pressed, nCyclesLeft); +} + +BYTE __stdcall JoyReadPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) +{ + int nJoyNum = (addr & 2) ? 1 : 0; // $C064..$C067 + BOOL nPdlCntrActive = 0; + return MemReadFloatingBus(nPdlCntrActive, nCyclesLeft); +} + +BYTE __stdcall JoyResetPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) +{ + return MemReadFloatingBus(nCyclesLeft); +} diff --git a/source/linux/dummies.cpp b/source/linux/dummies.cpp index 05de3c31..f24d3cb8 100644 --- a/source/linux/dummies.cpp +++ b/source/linux/dummies.cpp @@ -115,21 +115,6 @@ void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value) // Joystick -BYTE __stdcall JoyReadButton(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) -{ - return 0; -} - -BYTE __stdcall JoyReadPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) -{ - return 0; -} - -BYTE __stdcall JoyResetPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft) -{ - return 0; -} - void JoyportControl(const UINT uControl) { } diff --git a/source/linux/interface.h b/source/linux/interface.h index 3f83eb0e..05bd7d9e 100644 --- a/source/linux/interface.h +++ b/source/linux/interface.h @@ -11,3 +11,9 @@ void FrameRefreshStatus(int x, bool); BYTE KeybGetKeycode (); BYTE __stdcall KeybReadData (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); BYTE __stdcall KeybReadFlag (WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); + +// Joystick + +BYTE __stdcall JoyReadButton(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); +BYTE __stdcall JoyReadPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft); +BYTE __stdcall JoyResetPosition(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG nCyclesLeft);