mirror of
https://github.com/aap/pdp6.git
synced 2026-03-09 04:20:05 +00:00
BIN
emu/@.spcwar
Normal file
BIN
emu/@.spcwar
Normal file
Binary file not shown.
@@ -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)
|
||||
|
||||
|
||||
@@ -235,6 +235,8 @@ DevDef definitions[] = {
|
||||
{ DX_IDENT, makedx },
|
||||
#ifdef GRAPHICS
|
||||
{ DIS_IDENT, makedis },
|
||||
{ JOY_IDENT, makejoy },
|
||||
{ OJOY_IDENT, makeojoy },
|
||||
#endif
|
||||
{ NETMEM_IDENT, makenetmem },
|
||||
{ NETCONS_IDENT, makenetcons },
|
||||
|
||||
@@ -8,6 +8,8 @@ mkdev dt0 dt551
|
||||
mkdev dx1 dx555
|
||||
mkdev dx2 dx555
|
||||
mkdev dis dis340
|
||||
mkdev joy joy420
|
||||
mkdev ojoy joy724
|
||||
mkdev fmem fmem162 0
|
||||
mkdev mem0 moby mem_0
|
||||
#mkdev cmem0 cmem161C mem_0
|
||||
@@ -28,6 +30,8 @@ connectio ptp apr
|
||||
connectio dc apr
|
||||
connectio dt0 apr
|
||||
connectio dis apr
|
||||
connectio joy apr
|
||||
connectio ojoy apr
|
||||
connectmem fmem 0 apr -1
|
||||
connectmem mem0 0 apr 0
|
||||
#connectmem cmem0 0 apr 0
|
||||
|
||||
287
emu/joy.c
Normal file
287
emu/joy.c
Normal file
@@ -0,0 +1,287 @@
|
||||
#include "pdp6.h"
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
char *joy_ident = JOY_IDENT;
|
||||
char *ojoy_ident = OJOY_IDENT;
|
||||
|
||||
typedef struct Joy Joy;
|
||||
struct Joy
|
||||
{
|
||||
Device dev;
|
||||
IOBus *bus;
|
||||
};
|
||||
|
||||
|
||||
typedef struct OJoy OJoy;
|
||||
struct OJoy
|
||||
{
|
||||
Device dev;
|
||||
IOBus *bus;
|
||||
};
|
||||
|
||||
|
||||
#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;
|
||||
static word obits = 0;
|
||||
|
||||
void joy_motion (SDL_JoyAxisEvent *ev)
|
||||
{
|
||||
int m, n = ev->which;
|
||||
m = n * 18;
|
||||
n *= 9;
|
||||
|
||||
if (ev->axis == 0) {
|
||||
bits |= 0600LL << n;
|
||||
if (ev->value < -10000)
|
||||
bits &= ~(0200LL << n);
|
||||
if (ev->value > 10000)
|
||||
bits &= ~(0400LL << n);
|
||||
|
||||
obits &= ~(060LL << m);
|
||||
if (ev->value < -10000)
|
||||
obits |= 020LL << m;
|
||||
if (ev->value > 10000)
|
||||
obits |= 040LL << m;
|
||||
} else if (ev->axis == 1) {
|
||||
bits |= 0100LL << n;
|
||||
obits &= ~(0300LL << m);
|
||||
if (ev->value < -10000) {
|
||||
bits &= ~(0100LL << n);
|
||||
obits |= 0200LL << m;
|
||||
} else if (ev->value > 10000) {
|
||||
bits &= ~(0100LL << n);
|
||||
obits |= 0100LL << m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void joy_button (SDL_JoyButtonEvent *ev)
|
||||
{
|
||||
int m, n = ev->which;
|
||||
word x = 0, y = 0;
|
||||
m = n * 18;
|
||||
n *= 9;
|
||||
|
||||
switch (ev->button) {
|
||||
case 0: x = 000010; y = 020; break; //Torpedo
|
||||
case 1: x = 000004; y = 040; break; //Hyperspace
|
||||
case 2: x = 020000; break; //Beacon beam
|
||||
case 3: x = 000001; break; //Time K
|
||||
case 4: x = 000002; break; //Time 0
|
||||
case 5: x = 000400; break; //"Xmit data" = torpedo
|
||||
case 6: x = 010000; break; //"General cancel" = destruct
|
||||
}
|
||||
|
||||
if (ev->state) {
|
||||
bits &= ~(y << n);
|
||||
obits |= x << m;
|
||||
} else {
|
||||
bits |= y << n;
|
||||
obits &= ~(x << m);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
wake_ojoy(void *dev)
|
||||
{
|
||||
OJoy *joy;
|
||||
IOBus *bus;
|
||||
|
||||
joy = dev;
|
||||
bus = joy->bus;
|
||||
|
||||
if(bus->devcode == OJOY){
|
||||
if(IOB_STATUS){
|
||||
}
|
||||
if(IOB_DATAI){
|
||||
bus->c12 |= obits;
|
||||
}
|
||||
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 void
|
||||
ojoyioconnect(Device *dev, IOBus *bus)
|
||||
{
|
||||
OJoy *joy;
|
||||
joy = (OJoy*)dev;
|
||||
joy->bus = bus;
|
||||
bus->dev[OJOY] = (Busdev){ joy, wake_ojoy, 0 };
|
||||
}
|
||||
|
||||
|
||||
static Device joyproto = {
|
||||
nil, nil, "",
|
||||
nil, nil,
|
||||
joyioconnect,
|
||||
nil, nil
|
||||
};
|
||||
|
||||
static Device ojoyproto = {
|
||||
nil, nil, "",
|
||||
nil, nil,
|
||||
ojoyioconnect,
|
||||
nil, nil
|
||||
};
|
||||
|
||||
Device*
|
||||
makejoy(int argc, char *argv[])
|
||||
{
|
||||
Joy *joy;
|
||||
|
||||
joy = malloc(sizeof(Joy));
|
||||
memset(joy, 0, sizeof(Joy));
|
||||
|
||||
joy->dev = joyproto;
|
||||
joy->dev.type = joy_ident;
|
||||
|
||||
|
||||
joyinit();
|
||||
|
||||
return &joy->dev;
|
||||
}
|
||||
|
||||
Device*
|
||||
makeojoy(int argc, char *argv[])
|
||||
{
|
||||
OJoy *joy;
|
||||
|
||||
joy = malloc(sizeof(OJoy));
|
||||
memset(joy, 0, sizeof(OJoy));
|
||||
|
||||
joy->dev = ojoyproto;
|
||||
joy->dev.type = ojoy_ident;
|
||||
|
||||
joyinit();
|
||||
|
||||
return &joy->dev;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
12
emu/pdp6.h
12
emu/pdp6.h
@@ -660,6 +660,18 @@ 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;
|
||||
|
||||
|
||||
#define OJOY (0724>>2)
|
||||
#define OJOY_IDENT "joy724"
|
||||
Device *makeojoy(int argc, char *argv[]);
|
||||
extern char *ojoy_ident;
|
||||
|
||||
|
||||
typedef struct Netmem Netmem;
|
||||
struct Netmem
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user