Make Atari joystick test for A2560U.

This commit is contained in:
Vincent Barrilliot 2023-02-01 22:56:34 +01:00
parent 627c16463b
commit 4bfc669dbc
2 changed files with 69 additions and 1 deletions

View file

@ -27,7 +27,9 @@
#include "simpleio.h"
#include "syscalls.h"
#include "sys_general.h"
// TODO: the CLI should use system calls rather than depend on hardware directly
#include "uart_reg.h"
#include "gabe_reg.h"
#include "vicky_general.h"
#if MODEL == MODEL_FOENIX_A2560K
@ -87,6 +89,56 @@ short cli_test_ps2(short channel, int argc, const char * argv[]) {
* Test the joystick ports
*/
short cli_test_joystick(short channel, int argc, const char * argv[]) {
#if MODEL == MODEL_FOENIX_A2560U
volatile uint16_t * const atari_db9 = (uint16_t *)0xb00500;
uint16_t current,previous;
//const char msg[] = "Displays UPLR012 as Up/Down/Left/Right/Button0/Button1/Button2\nPress ESC to exit.\n";
//sys_chan_write(channel, msg, strlen(msg));
current = previous = ~*atari_db9;
// CAVEAT: this tests the hardware, not the MCP Device driver.
while (sys_kbd_scancode() != 0x01) {
if ((current = ~*atari_db9) == previous)
continue;
else {
char state[40];
int i = 0;
if ((current & 0x00ff) != (previous & 0x00ff)) {
state[i] = '\0';
strcat(state, "JOY1:");
i = strlen(state);
if (current & JOY1_UP) state[i++] = 'U';
if (current & JOY1_DOWN) state[i++] = 'D';
if (current & JOY1_LEFT) state[i++] = 'L';
if (current & JOY1_RIGHT) state[i++] = 'R';
if (current & JOY1_BTN0) state[i++] = '0';
if (current & JOY1_BTN1) state[i++] = '1';
if (current & JOY1_BTN2) state[i++] = '2';
state[i++] = ' ';
}
if ((current & 0xff00) != (previous & 0xff00)) {
state[i] = '\0';
strcat(state, "JOY2:");
i = strlen(state);
if (current & JOY2_UP) state[i++] = 'U';
if (current & JOY2_DOWN) state[i++] = 'D';
if (current & JOY2_LEFT) state[i++] = 'L';
if (current & JOY2_RIGHT) state[i++] = 'R';
if (current & JOY2_BTN0) state[i++] = '0';
if (current & JOY2_BTN1) state[i++] = '1';
if (current & JOY2_BTN2) state[i++] = '2';
}
state[i++] = '\n';
state[i] = '\0';
sys_chan_write(channel, state, strlen(state));
previous = current;
}
}
#else
char message[80];
volatile unsigned int * joystick_port = (volatile unsigned int *)0xFEC00500;
volatile unsigned int * game_ctrl_port = (volatile unsigned int *)0xFEC00504;
@ -109,7 +161,7 @@ short cli_test_joystick(short channel, int argc, const char * argv[]) {
scancode = sys_kbd_scancode();
} while (sys_chan_ioctrl(channel, 5, 0, 0) == 0);
#endif
return 0;
}

View file

@ -28,6 +28,22 @@
#define GABE_CPU_SPEED 0x0F00
#define GABE_CPU_ID 0xF000 // 0000 = MC68SEC000 @ 20MHz
#define GAVIN_ATARI_JOYSTICK ((volatile unsigned short *)0x00B00500)
#define JOY1_UP 0x0001
#define JOY1_DOWN 0x0002
#define JOY1_LEFT 0x0004
#define JOY1_RIGHT 0x0008
#define JOY1_BTN0 0x0010
#define JOY1_BTN1 0x0040
#define JOY1_BTN2 0x0080
#define JOY2_UP 0x0100
#define JOY2_DOWN 0x0200
#define JOY2_LEFT 0x0400
#define JOY2_RIGHT 0x0800
#define JOY2_BTN0 0x1000
#define JOY2_BTN1 0x4000
#define JOY2_BTN2 0x8000
#define FPGA_DATE_YEAR ((volatile unsigned short *)0x00B40030) // YYYY
#define FPGA_DATE_MONTHDAY ((volatile unsigned short *)0x00B40032) // MMDD