1
0
mirror of https://github.com/aap/pdp6.git synced 2026-01-11 23:53:31 +00:00

Device 420 with support for Spacewar consoles.

This commit is contained in:
Lars Brinkhoff 2019-04-28 20:51:47 +02:00
parent ab481592d6
commit accf09549b
5 changed files with 227 additions and 2 deletions

View File

@ -11,8 +11,8 @@ LIBS=-lpthread -lm
SDLLIBS=`sdl2-config --libs` `pkg-config SDL2_image --libs`
pdp6: main_panel.c dis340.c chargen.inc $(SRC) $(H)
$(CC) -o $@ $(CFLAGS) $(SDLFLAGS) main_panel.c dis340.c $(SRC) $(LIBS) $(SDLLIBS)
pdp6: main_panel.c dis340.c chargen.inc joy.c $(SRC) $(H)
$(CC) -o $@ $(CFLAGS) $(SDLFLAGS) main_panel.c dis340.c joy.c $(SRC) $(LIBS) $(SDLLIBS)
pdp6_s: main_serial.c $(SRC) $(H)
$(CC) -o $@ $(CFLAGS) main_serial.c $(SRC) $(LIBS)

View File

@ -235,6 +235,7 @@ DevDef definitions[] = {
{ DX_IDENT, makedx },
#ifdef GRAPHICS
{ DIS_IDENT, makedis },
{ JOY_IDENT, makejoy },
#endif
{ NETMEM_IDENT, makenetmem },
{ NETCONS_IDENT, makenetcons },

199
emu/joy.c Normal file
View File

@ -0,0 +1,199 @@
#include "pdp6.h"
#include <SDL2/SDL.h>
char *joy_ident = JOY_IDENT;
typedef struct Joy Joy;
struct Joy
{
Device dev;
IOBus *bus;
int pia_data;
int pia_spec;
};
#define HAVE_GAMECONTROLLERFROMINSTANCEID \
((SDL_MAJOR_VERSION > 2) || (SDL_MAJOR_VERSION == 2 && \
(SDL_MINOR_VERSION > 0) || (SDL_PATCHLEVEL >= 4)))
static void
joyinit(void)
{
SDL_Joystick *y;
int i, n;
SDL_InitSubSystem(SDL_INIT_JOYSTICK);
#if HAVE_GAMECONTROLLERFROMINSTANCEID
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
#endif
if (SDL_JoystickEventState (SDL_ENABLE) < 0) {
fprintf (stderr, "Joystick event state failure\r\n");
return;
}
#if HAVE_GAMECONTROLLERFROMINSTANCEID
if (SDL_GameControllerEventState (SDL_ENABLE) < 0) {
fprintf (stderr, "Game controller event state failure\r\n");
return;
}
#endif
n = SDL_NumJoysticks();
fprintf (stderr, "Controllers: %d\r\n", n);
for (i = 0; i < n; i++) {
#if HAVE_GAMECONTROLLERFROMINSTANCEID
SDL_GameController *x;
if (SDL_IsGameController (i)) {
x = SDL_GameControllerOpen (i);
if (x == NULL) {
fprintf (stderr, "Controller %d FAIL\r\n", i);
} else {
fprintf (stderr, "Controller %d OK\r\n", i);
printf("Name: %s\r\n", SDL_GameControllerNameForIndex(i));
}
} else
#endif
{
y = SDL_JoystickOpen (i);
if (y == NULL) {
fprintf (stderr, "Joystick %d FAIL\r\n", i);
} else {
fprintf (stderr, "Joystick %d OK\r\n", i);
printf("Name: %s\r\n", SDL_JoystickNameForIndex(i));
printf("Number of Axes: %d\r\n", SDL_JoystickNumAxes(y));
printf("Number of Buttons: %d\r\n", SDL_JoystickNumButtons(y));
printf("Number of Balls: %d\r\n", SDL_JoystickNumBalls(y));
}
}
}
}
static word bits = 0777777777777;
void joy_motion (SDL_JoyAxisEvent *ev)
{
int n = ev->which;
n *= 9;
if (ev->axis == 0) {
bits |= 0600LL << n;
if (ev->value < -10000)
bits &= ~(0200LL << n);
if (ev->value > 10000)
bits &= ~(0400LL << n);
} else if (ev->axis == 1) {
bits |= 0100LL << n;
if (ev->value < -3000)
bits &= ~(0100LL << n);
}
}
void joy_button (SDL_JoyButtonEvent *ev)
{
int n = ev->which;
word y = 0;
n *= 9;
switch (ev->button) {
case 0: y = 020; break; //Torpedo
case 1: y = 040; break; //Hyperspace
}
if (ev->state)
bits &= ~(y << n);
else
bits |= y << n;
}
void controller_motion (SDL_ControllerAxisEvent *event)
{
SDL_JoyAxisEvent e;
e.which = event->which;
e.axis = event->axis;
e.value = event->value;
joy_motion (&e);
}
void controller_button (SDL_ControllerButtonEvent *event)
{
SDL_JoyButtonEvent e;
SDL_GameControllerButtonBind b;
SDL_GameController *c;
#if HAVE_GAMECONTROLLERFROMINSTANCEID
c = SDL_GameControllerFromInstanceID (event->which);
#endif
b = SDL_GameControllerGetBindForButton (c, event->button);
e.which = event->which;
e.button = b.value.button;
e.state = event->state;
joy_button (&e);
}
static void
wake_joy(void *dev)
{
Joy *joy;
IOBus *bus;
joy = dev;
bus = joy->bus;
if(bus->devcode == JOY){
if(IOB_STATUS){
}
if(IOB_DATAI){
bus->c12 |= bits;
}
if(IOB_CONO_CLEAR){
}
if(IOB_CONO_SET){
}
if(IOB_DATAO_CLEAR){
}
if(IOB_DATAO_SET){
}
}
}
static void
joyioconnect(Device *dev, IOBus *bus)
{
Joy *joy;
joy = (Joy*)dev;
joy->bus = bus;
bus->dev[JOY] = (Busdev){ joy, wake_joy, 0 };
}
static Device joyproto = {
nil, nil, "",
nil, nil,
joyioconnect,
nil, nil
};
Device*
makejoy(int argc, char *argv[])
{
Joy *joy;
Task t;
joy = malloc(sizeof(Joy));
memset(joy, 0, sizeof(Joy));
joy->dev = joyproto;
joy->dev.type = joy_ident;
//addtask(t);
joyinit();
return &joy->dev;
}

View File

@ -1172,6 +1172,11 @@ usage(void)
exit(1);
}
extern void joy_motion (SDL_JoyAxisEvent *event);
extern void joy_button (SDL_JoyButtonEvent *event);
extern void controller_motion (SDL_ControllerAxisEvent *event);
extern void controller_button (SDL_ControllerButtonEvent *event);
int
threadmain(int argc, char *argv[])
{
@ -1276,6 +1281,20 @@ void main340(void);
mbev = (SDL_MouseButtonEvent*)&ev;
mouse(mbev->button, mbev->state, mbev->x, mbev->y);
break;
case SDL_CONTROLLERAXISMOTION:
controller_motion (&ev.caxis);
break;
case SDL_JOYAXISMOTION:
joy_motion (&ev.jaxis);
break;
case SDL_JOYBUTTONUP:
case SDL_JOYBUTTONDOWN:
joy_button (&ev.jbutton);
break;
case SDL_CONTROLLERBUTTONUP:
case SDL_CONTROLLERBUTTONDOWN:
controller_button (&ev.cbutton);
break;
case SDL_KEYDOWN:
keydown(ev.key.keysym);
break;

View File

@ -660,6 +660,12 @@ Device *makedis(int argc, char *argv[]);
extern char *dis_ident;
#define JOY (0420>>2)
#define JOY_IDENT "joy420"
Device *makejoy(int argc, char *argv[]);
extern char *joy_ident;
typedef struct Netmem Netmem;
struct Netmem
{