diff --git a/NABULIB/NABU-LIB.c b/NABULIB/NABU-LIB.c index afb77d0..b150f02 100644 --- a/NABULIB/NABU-LIB.c +++ b/NABULIB/NABU-LIB.c @@ -222,33 +222,53 @@ void RightShift(uint8_t *arr, uint16_t len, uint8_t n) { uint8_t inKey = IO_KEYBOARD; - if (inKey >= 0x80 && inKey <= 0x83) { - - _lastKeyboardIntVal = inKey; - } else if (inKey < 0x90 || inKey > 0x95) { - - switch (_lastKeyboardIntVal) { + if (inKey >= 0x80 && inKey <= 0x8a) { + _paddleByteCount = 0; + switch (inKey) { case 0x80: - _lastKeyboardIntVal = 0; - _joyStatus[0] = inKey; + _inputIndex = 0; break; case 0x81: - _lastKeyboardIntVal = 0; - _joyStatus[1] = inKey; + _inputIndex = 1; break; case 0x82: - _lastKeyboardIntVal = 0; - _joyStatus[2] = inKey; + _inputIndex = 2; break; case 0x83: - _lastKeyboardIntVal = 0; - _joyStatus[3] = inKey; + _inputIndex = 3; break; - default: { - - _kbdBuffer[_kbdBufferWritePos] = inKey; - - _kbdBufferWritePos++; + case 0x84: + _inputIndex = 0; + break; + case 0x86: + _inputIndex = 2; + break; + case 0x88: + _inputIndex = 4; + break; + case 0x8a: + _inputIndex = 6; + break; + default: + _inputIndex = 0xff; + } + } else if (inKey < 0x80 || inKey >= 0xe0) { + _kbdBuffer[_kbdBufferWritePos] = inKey; + _kbdBufferWritePos++; + _paddleByteCount = 0; + _inputIndex = 0xff; + } else if (_inputIndex != 0xff) { + if (inKey >= 0xa0 && inKey < 0xc0) { + _joyStatus[_inputIndex] = inKey; + _paddleByteCount = 0; + _inputIndex = 0xff; + } else { + _paddleTemp[_paddleByteCount++] = inKey; + if (_paddleByteCount == 4) { + _paddleValue[_inputIndex] = (_paddleTemp[0] & 0x0F) | (_paddleTemp[1] << 4); + _paddleValue[_inputIndex+1] = (_paddleTemp[2] & 0x0F) | (_paddleTemp[3] << 4); + _paddleByteCount = 0; + _inputIndex = 0xff; } } } @@ -547,6 +567,11 @@ void playNoteDelay(uint8_t channel, uint8_t note, uint16_t delayLength) { return _joyStatus[joyNum]; } + uint8_t getPaddleValue(uint8_t paddleNum) { + + return _paddleValue[paddleNum]; + } + #ifndef DISABLE_VDP uint8_t readLine(uint8_t *buffer, uint8_t maxInputLen) { @@ -1711,4 +1736,4 @@ void playNoteDelay(uint8_t channel, uint8_t note, uint16_t delayLength) { vdp_print(str); } -#endif \ No newline at end of file +#endif diff --git a/NABULIB/NABU-LIB.h b/NABULIB/NABU-LIB.h index 796be63..7eabeb2 100644 --- a/NABULIB/NABU-LIB.h +++ b/NABULIB/NABU-LIB.h @@ -320,7 +320,7 @@ volatile uint8_t _randomSeed = 0; volatile uint8_t _kbdBuffer[256]; volatile uint8_t _kbdBufferReadPos = 0; volatile uint8_t _kbdBufferWritePos = 0; - volatile uint8_t _lastKeyboardIntVal = 0; + volatile uint8_t _inputIndex = 0xff; volatile uint8_t _joyStatus[4] = {0}; typedef enum JOYSTICKENUM { @@ -331,6 +331,10 @@ volatile uint8_t _randomSeed = 0; Joy_Button = 0b00010000, }; + volatile uint8_t _paddleValue[8] = {0}; + volatile uint8_t _paddleTemp[4] = {0}; + volatile uint8_t _paddleByteCount = 0; + #warning #warning Keyboard Interupt Enabled. Use NABU-LIB keyboard functions only (no CPM STDIN) #warning @@ -837,6 +841,11 @@ inline uint8_t ayRead(uint8_t reg); // // ************************************************************************** inline uint8_t getJoyStatus(uint8_t joyNum); + + // ************************************************************************** + // Returns the current position of the paddle at the specified index (0 - 7) + // ************************************************************************** + inline uint8_t getPaddleValue(uint8_t paddleNum); #endif #if BIN_TYPE == BIN_CPM diff --git a/Utilities/Input Test/build.bat b/Utilities/Input Test/build.bat new file mode 100644 index 0000000..b0a072b --- /dev/null +++ b/Utilities/Input Test/build.bat @@ -0,0 +1,14 @@ +@echo off + +SET Z88DK_DIR=c:\z88dk\ +SET ZCCCFG=%Z88DK_DIR%lib\config\ +SET PATH=%Z88DK_DIR%bin;%PATH% + +echo. +echo **************************************************************************** + +zcc +nabu -vn --list -m -create-app -compiler=sdcc main.c -o "C:\NABU Segments\000001.nabu" + +echo **************************************************************************** + +pause diff --git a/Utilities/Input Test/main.c b/Utilities/Input Test/main.c new file mode 100644 index 0000000..951a6ba --- /dev/null +++ b/Utilities/Input Test/main.c @@ -0,0 +1,142 @@ +#define FONT_LM80C +#define DISABLE_CURSOR +#define BIN_TYPE BIN_HOMEBREW + +#include "../../NABULIB/NABU-LIB.h" +#include "../../NABULIB/patterns.h" + +// decode and print joystick byte +void printJoystick(uint8_t b) +{ + char state[6]; + + state[0] = '.'; + state[1] = '.'; + state[2] = '.'; + state[3] = '.'; + state[4] = '.'; + state[5] = 0; + + if (b & Joy_Left) { + state[0] = 'L'; + } + if (b & Joy_Down) { + state[1] = 'D'; + } + if (b & Joy_Right) { + state[2] = 'R'; + } + if (b & Joy_Up) { + state[3] = 'U'; + } + if (b & Joy_Button) { + state[4] = 'F'; + } + vdp_print(state); +} + +// print hex byte +void printHexByte(uint8_t b) +{ + uint8_t high = b >> 4; + uint8_t low = b & 0x0F; + char val[3]; + val[2] = 0; + if (low < 10) { + low += 0x30; + } + if (low > 9 && low <= 15) { + low += 0x37; + } + if (high < 10) { + high += 0x30; + } + if (high > 9 && high <= 15) { + high += 0x37; + } + val[0] = high; + val[1] = low; + vdp_print(val); +} + +void main() { + // init the nabu lib which does interrupts and all that jazz + initNABULib(); + + // Set the text mode to foreground color white, bg black + vdp_initTextMode(0xf, 0x0, true); + vdp_loadASCIIFont(ASCII); + + // print title + vdp_setCursor2(14, 0); + vdp_print("Input Tester"); + + // print Paddle 1 header + vdp_setCursor2(5, 5); + vdp_print("Paddle 1: "); + + // print Paddle 2 header + vdp_setCursor2(23, 5); + vdp_print("Paddle 2: "); + + // print Paddle 3 header + vdp_setCursor2(5, 10); + vdp_print("Paddle 3: "); + + // print Paddle 4 header + vdp_setCursor2(23, 10); + vdp_print("Paddle 4: "); + + // print Joystick 1 header + vdp_setCursor2(2, 15); + vdp_print("Joystick 1: "); + + // print Joystick 2 header + vdp_setCursor2(21, 15); + vdp_print("Joystick 2: "); + + // print Keyboard header + vdp_setCursor2(14, 20); + vdp_print("Keyboard: 00"); + + while (true) { + // read paddle 1 value + uint8_t p1 = getPaddleValue(0); + // read paddle 2 value + uint8_t p2 = getPaddleValue(1); + // read paddle 3 value + uint8_t p3 = getPaddleValue(2); + // read paddle 4 value + uint8_t p4 = getPaddleValue(3); + + // read joystick 1 status + uint8_t j1 = getJoyStatus(0); + // read joystick 2 status + uint8_t j2 = getJoyStatus(1); + + // display paddle 1 value + vdp_setCursor2(15, 5); + printHexByte(p1); + // display paddle 2 value + vdp_setCursor2(33, 5); + printHexByte(p2); + // display paddle 3 value + vdp_setCursor2(15, 10); + printHexByte(p3); + // display paddle 4 value + vdp_setCursor2(33, 10); + printHexByte(p4); + // display joystick 1 state + vdp_setCursor2(14, 15); + printJoystick(j1); + // display joystick 2 state + vdp_setCursor2(33, 15); + printJoystick(j2); + + // display last keyboard keycode + if (isKeyPressed()) { + vdp_setCursor2(24, 20); + printHexByte(getChar()); + } + } +}