Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Libretro
bk-emulator
Commits
15901551
Commit
15901551
authored
Nov 03, 2019
by
Vladimir Serbinenko
Browse files
Implement joystick
parent
448671a9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
15901551
...
...
@@ -49,11 +49,11 @@ UTILS = maketape readtape
SRCS
=
access.c boot.c branch.c conf.c covox.c double.c ea.c itab.c
\
main.c service.c ui.c scr-sdl.c scr.c timer.c tape.c disk.c mouse.c printer.c
\
single.c weird.c tty.c io.c timing.c sound.c disas.c serial.c bkplip.c
\
terakdisk.c synth.c emu2149.c standalone.c sdlsound.c sdltty.c
terakdisk.c synth.c emu2149.c standalone.c sdlsound.c sdltty.c
joystick.c
OBJS
=
access.o boot.o branch.o conf.o covox.o double.o ea.o itab.o icon.o
\
main.o service.o ui.o scr-sdl.o scr.o timer.o tape.o disk.o mouse.o printer.o
\
single.o weird.o tty.o io.o timing.o sound.o disas.o serial.o bkplip.o
\
terakdisk.o synth.o emu2149.o standalone.
c
sdlsound.o sdltty.o
terakdisk.o synth.o emu2149.o standalone.
o
sdlsound.o sdltty.o
joystick.o
INCS
=
defines.h scr.h conf.h emu2149.h emutypes.h
USRCS
=
readtape.c maketape.c pngtorgba.c
TEXTS
=
README.html configure.in icon.c
...
...
access.c
View file @
15901551
...
...
@@ -134,6 +134,12 @@ pdp_qmap q_synth = {
pdp_qmap
q_bkplip
=
{
PORT_REG
,
PORT_SIZE
,
bkplip_init
,
bkplip_read
,
bkplip_write
,
bkplip_bwrite
};
pdp_qmap
q_joystick
=
{
PORT_REG
,
PORT_SIZE
,
joystick_init
,
joystick_read
,
joystick_write
,
joystick_bwrite
};
void
plug_joystick
()
{
qmap
[
0
]
=
q_joystick
;
}
void
plug_printer
()
{
qmap
[
0
]
=
q_printer
;
}
void
plug_mouse
()
{
qmap
[
0
]
=
q_mouse
;
}
void
plug_covox
()
{
qmap
[
0
]
=
q_covox
;
}
...
...
defines.h
View file @
15901551
...
...
@@ -470,6 +470,11 @@ extern const _itab_t itab[];
else \
SET_CC_V()
int
joystick_read
(
c_addr
addr
,
d_word
*
word
);
void
joystick_init
(
void
);
int
joystick_write
(
c_addr
addr
,
d_word
word
);
int
joystick_bwrite
(
c_addr
addr
,
d_byte
byte
);
typedef
enum
{
nopD
,
rtcD
,
stepinD
,
stepoutD
,
readtsD
,
readD
,
writeD
,
delD
}
disk_cmd
;
...
...
@@ -501,5 +506,22 @@ extern unsigned char req_page[512], req_palette[512];
extern
int
cybuf
[
1024
];
extern
int
cybufidx
;
void
intr_hand
(
void
);
d_word
platform_joystick_get_state
();
void
platform_joystick_init
();
enum
joystick_state
{
JOYSTICK_BUTTON1
=
0x1
,
JOYSTICK_BUTTON2
=
0x2
,
JOYSTICK_BUTTON3
=
0x4
,
JOYSTICK_BUTTON4
=
0x8
,
JOYSTICK_RIGHT
=
0x10
,
JOYSTICK_DOWN
=
0x20
,
JOYSTICK_LEFT
=
0x200
,
JOYSTICK_UP
=
0x400
};
static
inline
enum
joystick_state
JOYSTICK_BUTTON
(
int
idx
)
{
return
1
<<
idx
;
}
#endif
joystick.c
0 → 100644
View file @
15901551
#include "defines.h"
int
joystick_read
(
c_addr
addr
,
d_word
*
word
)
{
*
word
=
platform_joystick_get_state
();
return
OK
;
}
void
joystick_init
()
{
platform_joystick_init
();
}
int
joystick_write
(
c_addr
addr
,
d_word
word
)
{
return
OK
;
}
int
joystick_bwrite
(
c_addr
addr
,
d_byte
byte
)
{
return
OK
;
}
sdltty.c
View file @
15901551
...
...
@@ -11,8 +11,42 @@ int special_keys[SDLK_LAST], shifted[256];
int
grab_mode
;
static
int
joystick_state_buttons
=
0
,
joystick_state_hat
=
0
;
void
tty_keyevent
(
int
c
);
void
joystick_event
(
SDL_Event
*
pev
)
{
switch
(
pev
->
type
)
{
case
SDL_JOYBUTTONDOWN
:
joystick_state_buttons
|=
JOYSTICK_BUTTON
(
pev
->
jbutton
.
button
);
break
;
case
SDL_JOYBUTTONUP
:
joystick_state_buttons
&=
~
(
JOYSTICK_BUTTON
(
pev
->
jbutton
.
button
));
break
;
case
SDL_JOYHATMOTION
:
{
int
hat
=
pev
->
jhat
.
value
;
int
newval
=
0
;
if
(
hat
&
SDL_HAT_UP
)
newval
|=
JOYSTICK_UP
;
if
(
hat
&
SDL_HAT_DOWN
)
newval
|=
JOYSTICK_DOWN
;
if
(
hat
&
SDL_HAT_LEFT
)
newval
|=
JOYSTICK_LEFT
;
if
(
hat
&
SDL_HAT_RIGHT
)
newval
|=
JOYSTICK_RIGHT
;
joystick_state_hat
=
newval
;
}
}
}
void
platform_joystick_init
()
{
}
d_word
platform_joystick_get_state
()
{
return
joystick_state_buttons
|
joystick_state_hat
;
}
void
mouse_event
(
SDL_Event
*
pev
)
{
switch
(
pev
->
type
)
{
...
...
@@ -134,6 +168,13 @@ tty_recv()
case
SDL_MOUSEMOTION
:
mouse_event
(
&
ev
);
break
;
case
SDL_JOYBUTTONDOWN
:
case
SDL_JOYBUTTONUP
:
case
SDL_JOYHATMOTION
:
case
SDL_JOYAXISMOTION
:
case
SDL_JOYBALLMOTION
:
joystick_event
(
&
ev
);
break
;
case
SDL_VIDEORESIZE
:
scr_switch
(
ev
.
resize
.
w
,
ev
.
resize
.
h
);
break
;
...
...
standalone.c
View file @
15901551
...
...
@@ -45,6 +45,7 @@ flag_t covoxflag; /* covox flag */
flag_t
synthflag
;
/* AY-3-8910 flag */
flag_t
plipflag
;
/* PLIP flag */
flag_t
turboflag
;
/* "Turbo" mode with doubled clock speed */
flag_t
joystickflag
;
long
long
ticks_screen
=
0
;
unsigned
int
hasexit
=
0
;
...
...
@@ -86,6 +87,7 @@ char **argv;
fprintf
(
stderr
,
_
(
" -v Enable Covox
\n
"
)
);
fprintf
(
stderr
,
_
(
" -y Enable AY-3-8910
\n
"
)
);
fprintf
(
stderr
,
_
(
" -m Enable mouse
\n
"
)
);
fprintf
(
stderr
,
_
(
" -j Enable joystick
\n
"
)
);
fprintf
(
stderr
,
_
(
" -S Full speed mode
\n
"
)
);
fprintf
(
stderr
,
_
(
" -s
\"
TURBO
\"
mode (Real overclocked BK)
\n
"
)
);
fprintf
(
stderr
,
_
(
" -R<file> Specify an alternative ROM file @ 120000.
\n
"
)
);
...
...
@@ -154,7 +156,11 @@ by the environment variable BK_PATH.\n"), romdir );
printf
(
_
(
"Initializing SDL.
\n
"
)
);
if
((
SDL_Init
(
SDL_INIT_VIDEO
|
SDL_INIT_TIMER
)
==-
1
))
{
Uint32
sdlflags
=
SDL_INIT_VIDEO
|
SDL_INIT_TIMER
;
if
(
joystickflag
)
sdlflags
|=
SDL_INIT_JOYSTICK
;
if
((
SDL_Init
(
sdlflags
)
==-
1
))
{
printf
(
_
(
"Could not initialize SDL: %s.
\n
"
),
SDL_GetError
());
exit
(
-
1
);
}
...
...
@@ -169,6 +175,8 @@ by the environment variable BK_PATH.\n"), romdir );
fake_disk
&=
bkmodel
>=
2
;
terak
=
bkmodel
==
9
;
bkmodel
=
bkmodel
>=
3
;
if
(
joystickflag
)
joystick_init
();
tty_open
();
/* initialize the tty stuff */
ev_init
();
/* initialize the event system */
sim_init
();
/* ...the simulated cpu */
...
...
@@ -180,6 +188,8 @@ by the environment variable BK_PATH.\n"), romdir );
}
else
{
if
(
mouseflag
)
plug_mouse
();
if
(
joystickflag
)
plug_joystick
();
if
(
printer_file
)
plug_printer
();
if
(
covoxflag
)
...
...
@@ -293,6 +303,9 @@ char **argv;
case
'm'
:
mouseflag
=
*
(
farg
+
1
)
?
*
(
farg
+
1
)
-
'0'
:
1
;
break
;
case
'j'
:
joystickflag
=
*
(
farg
+
1
)
?
*
(
farg
+
1
)
-
'0'
:
1
;
break
;
case
'p'
:
plipflag
=
1
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment