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
f2b872c4
Commit
f2b872c4
authored
Nov 01, 2019
by
Vladimir Serbinenko
Browse files
Encapsulate SDL-tty code into separate file
parent
9d32ba5a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
f2b872c4
...
...
@@ -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
terakdisk.c synth.c emu2149.c
sdltty.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
terakdisk.o synth.o emu2149.o
sdltty.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
...
...
mouse.c
View file @
f2b872c4
#include "defines.h"
#include "
SDL/SDL
.h"
#include "
tty
.h"
#define LOGARITHMIC
d_word
mouse_button_state
;
int
grab_mode
;
unsigned
short
mouse_up
,
mouse_right
,
mouse_down
,
mouse_left
,
mouse_but0
,
mouse_strobe
;
d_word
mouse_button_state
;
int
relx
,
rely
;
void
mouse_init
()
{
...
...
@@ -31,27 +30,6 @@ void mouse_init() {
}
}
void
mouse_event
(
SDL_Event
*
pev
)
{
switch
(
pev
->
type
)
{
case
SDL_MOUSEBUTTONDOWN
:
if
(
pev
->
button
.
button
==
3
)
{
/* middle button switches grab mode */
grab_mode
^=
1
;
SDL_WM_GrabInput
(
grab_mode
?
SDL_GRAB_ON
:
SDL_GRAB_OFF
);
return
;
}
mouse_button_state
|=
mouse_but0
<<
pev
->
button
.
button
;
break
;
case
SDL_MOUSEBUTTONUP
:
mouse_button_state
&=
~
(
mouse_but0
<<
pev
->
button
.
button
);
break
;
case
SDL_MOUSEMOTION
:
relx
+=
pev
->
motion
.
xrel
;
rely
+=
pev
->
motion
.
yrel
;
break
;
}
}
int
mouse_read
(
c_addr
addr
,
d_word
*
word
)
{
*
word
=
mouse_button_state
;
if
(
relx
)
{
...
...
sdltty.c
0 → 100644
View file @
f2b872c4
#include "defines.h"
#include "tty.h"
#include "SDL/SDL.h"
#include "SDL/SDL_keysym.h"
#include "SDL/SDL_events.h"
#include <ctype.h>
#include <libintl.h>
#define _(String) gettext (String)
int
special_keys
[
SDLK_LAST
],
shifted
[
256
];
int
grab_mode
;
void
tty_keyevent
(
int
c
);
void
mouse_event
(
SDL_Event
*
pev
)
{
switch
(
pev
->
type
)
{
case
SDL_MOUSEBUTTONDOWN
:
if
(
pev
->
button
.
button
==
3
)
{
/* middle button switches grab mode */
grab_mode
^=
1
;
SDL_WM_GrabInput
(
grab_mode
?
SDL_GRAB_ON
:
SDL_GRAB_OFF
);
return
;
}
mouse_button_state
|=
mouse_but0
<<
pev
->
button
.
button
;
break
;
case
SDL_MOUSEBUTTONUP
:
mouse_button_state
&=
~
(
mouse_but0
<<
pev
->
button
.
button
);
break
;
case
SDL_MOUSEMOTION
:
relx
+=
pev
->
motion
.
xrel
;
rely
+=
pev
->
motion
.
yrel
;
break
;
}
}
int
handle_special_key
(
int
k
)
{
if
(
SDLK_UNKNOWN
==
k
)
{
return
0
;
}
switch
(
k
)
{
case
SDLK_F12
:
{
ui_download
();
return
1
;
}
case
SDLK_SCROLLOCK
:
scr_switch
(
0
,
0
);
return
1
;
default:
return
0
;
}
}
static
int
ar2
=
0
;
tty_keyevent_transform
(
int
ksym
,
int
kmod
,
int
is_keyup
)
{
int
k
,
c
;
k
=
ksym
;
if
(
SDLK_UNKNOWN
==
k
)
{
return
;
}
if
(
k
==
SDLK_LCTRL
)
k
=
SDLK_RETURN
;
else
if
(
k
==
SDLK_LALT
)
k
=
SDLK_SPACE
;
else
if
(
k
==
SDLK_BACKSPACE
)
k
=
265
;
else
if
(
k
==
SDLK_TAB
)
k
=
257
;
else
if
(
k
==
SDLK_LSHIFT
)
k
=
259
;
if
(
is_keyup
)
{
if
(
special_keys
[
k
]
==
TTY_AR2
)
ar2
=
0
;
tty_keyevent
(
-
1
);
return
;
}
/* modifier keys handling */
if
(
special_keys
[
k
]
!=
-
1
)
{
if
(
special_keys
[
k
]
==
TTY_AR2
)
{
ar2
=
1
;
return
;
}
c
=
special_keys
[
k
];
}
else
{
// Keysym follows ASCII
c
=
k
;
if
((
kmod
&
KMOD_CAPS
)
&&
isalpha
(
c
))
{
c
&=
~
040
;
/* make it capital */
}
if
(
kmod
&
KMOD_SHIFT
)
{
c
=
shifted
[
c
];
}
if
((
kmod
&
KMOD_CTRL
)
&&
(
c
&
0100
))
{
c
&=
037
;
}
}
// Win is AP2
if
(
ar2
)
{
c
|=
0200
;
}
tty_keyevent
(
c
);
}
/*
* tty_recv() - Called at various times during simulation to
* set if the user typed something.
*/
tty_recv
()
{
SDL_Event
ev
;
/* fprintf(stderr, "Polling events..."); */
while
(
SDL_PollEvent
(
&
ev
))
{
extern
void
mouse_event
(
SDL_Event
*
pev
);
switch
(
ev
.
type
)
{
case
SDL_KEYDOWN
:
if
(
handle_special_key
(
ev
.
key
.
keysym
.
sym
))
break
;
/* Fallthrough */
case
SDL_KEYUP
:
tty_keyevent_transform
(
ev
.
key
.
keysym
.
sym
,
ev
.
key
.
keysym
.
mod
,
ev
.
type
==
SDL_KEYUP
);
break
;
case
SDL_VIDEOEXPOSE
:
case
SDL_ACTIVEEVENT
:
/* the visibility changed */
scr_dirty
=
256
;
break
;
case
SDL_MOUSEBUTTONDOWN
:
case
SDL_MOUSEBUTTONUP
:
case
SDL_MOUSEMOTION
:
mouse_event
(
&
ev
);
break
;
case
SDL_VIDEORESIZE
:
scr_switch
(
ev
.
resize
.
w
,
ev
.
resize
.
h
);
break
;
case
SDL_QUIT
:
exit
(
0
);
default:
;
fprintf
(
stderr
,
_
(
"Unexpected event %d
\n
"
),
ev
.
type
);
}
}
/* fprintf(stderr, "done\n"); */
}
tty_open
()
{
int
i
;
/* initialize the keytables */
for
(
i
=
0
;
i
<
SDLK_LAST
;
i
++
)
{
special_keys
[
i
]
=
-
1
;
}
special_keys
[
SDLK_BACKSPACE
]
=
030
;
special_keys
[
SDLK_TAB
]
=
011
;
special_keys
[
SDLK_RETURN
]
=
012
;
special_keys
[
SDLK_CLEAR
]
=
014
;
/* sbr */
for
(
i
=
SDLK_NUMLOCK
;
i
<=
SDLK_COMPOSE
;
i
++
)
special_keys
[
i
]
=
TTY_NOTHING
;
special_keys
[
SDLK_SCROLLOCK
]
=
TTY_SWITCH
;
special_keys
[
SDLK_LSUPER
]
=
TTY_AR2
;
special_keys
[
SDLK_LALT
]
=
TTY_AR2
;
special_keys
[
SDLK_ESCAPE
]
=
TTY_STOP
;
special_keys
[
SDLK_DELETE
]
=
-
1
;
special_keys
[
SDLK_LEFT
]
=
010
;
special_keys
[
SDLK_UP
]
=
032
;
special_keys
[
SDLK_RIGHT
]
=
031
;
special_keys
[
SDLK_DOWN
]
=
033
;
special_keys
[
SDLK_HOME
]
=
023
;
/* vs */
special_keys
[
SDLK_PAGEUP
]
=
-
1
;
/* PgUp */
special_keys
[
SDLK_PAGEDOWN
]
=
-
1
;
/* PgDn */
special_keys
[
SDLK_END
]
=
-
1
;
special_keys
[
SDLK_INSERT
]
=
-
1
;
special_keys
[
SDLK_BREAK
]
=
TTY_STOP
;
special_keys
[
SDLK_F1
]
=
0201
;
/* povt */
special_keys
[
SDLK_F2
]
=
003
;
/* kt */
special_keys
[
SDLK_F3
]
=
0213
;
/* -|--> */
special_keys
[
SDLK_F4
]
=
026
;
/* |<--- */
special_keys
[
SDLK_F5
]
=
027
;
/* |---> */
special_keys
[
SDLK_F6
]
=
0202
;
/* ind su */
special_keys
[
SDLK_F7
]
=
0204
;
/* blk red */
special_keys
[
SDLK_F8
]
=
0200
;
/* shag */
special_keys
[
SDLK_F9
]
=
014
;
/* sbr */
special_keys
[
SDLK_F10
]
=
TTY_STOP
;
special_keys
[
SDLK_F11
]
=
TTY_RESET
;
special_keys
[
SDLK_F12
]
=
TTY_DOWNLOAD
;
for
(
i
=
0
;
i
<
256
;
i
++
)
{
shifted
[
i
]
=
i
;
}
for
(
i
=
'A'
;
i
<=
'Z'
;
i
++
)
{
shifted
[
i
]
=
i
^
040
;
shifted
[
i
^
040
]
=
i
;
}
shifted
[
'1'
]
=
'!'
;
shifted
[
'2'
]
=
'@'
;
shifted
[
'3'
]
=
'#'
;
shifted
[
'4'
]
=
'$'
;
shifted
[
'5'
]
=
'%'
;
shifted
[
'6'
]
=
'^'
;
shifted
[
'7'
]
=
'&'
;
shifted
[
'8'
]
=
'*'
;
shifted
[
'9'
]
=
'('
;
shifted
[
'0'
]
=
')'
;
shifted
[
'-'
]
=
'_'
;
shifted
[
'='
]
=
'+'
;
shifted
[
'\\'
]
=
'|'
;
shifted
[
'['
]
=
'{'
;
shifted
[
']'
]
=
'}'
;
shifted
[
';'
]
=
':'
;
shifted
[
'\''
]
=
'"'
;
shifted
[
'`'
]
=
'~'
;
shifted
[
','
]
=
'<'
;
shifted
[
'.'
]
=
'>'
;
shifted
[
'/'
]
=
'?'
;
}
tty.c
View file @
f2b872c4
...
...
@@ -19,9 +19,7 @@
*/
#include "defines.h"
#include "SDL/SDL.h"
#include "SDL/SDL_keysym.h"
#include "SDL/SDL_events.h"
#include "tty.h"
#include <ctype.h>
#include "intl.h"
...
...
@@ -37,91 +35,10 @@
/* magic numbers for special keys */
#define TTY_NOTHING 0377
#define TTY_STOP 0376
#define TTY_RESET 0375
/* "reset buton", only with AR2 */
#define TTY_AR2 0374
/* AP2 */
#define TTY_SWITCH 0373
/* video mode switch */
#define TTY_DOWNLOAD 0372
/* direct file load */
d_word
tty_reg
;
d_word
tty_data
;
int
special_keys
[
SDLK_LAST
],
shifted
[
256
];
static
tty_pending_int
=
0
;
extern
unsigned
long
pending_interrupts
;
tty_open
()
{
int
i
;
/* initialize the keytables */
for
(
i
=
0
;
i
<
SDLK_LAST
;
i
++
)
{
special_keys
[
i
]
=
-
1
;
}
special_keys
[
SDLK_BACKSPACE
]
=
030
;
special_keys
[
SDLK_TAB
]
=
011
;
special_keys
[
SDLK_RETURN
]
=
012
;
special_keys
[
SDLK_CLEAR
]
=
014
;
/* sbr */
for
(
i
=
SDLK_NUMLOCK
;
i
<=
SDLK_COMPOSE
;
i
++
)
special_keys
[
i
]
=
TTY_NOTHING
;
special_keys
[
SDLK_SCROLLOCK
]
=
TTY_SWITCH
;
special_keys
[
SDLK_LSUPER
]
=
TTY_AR2
;
special_keys
[
SDLK_LALT
]
=
TTY_AR2
;
special_keys
[
SDLK_ESCAPE
]
=
TTY_STOP
;
special_keys
[
SDLK_DELETE
]
=
-
1
;
special_keys
[
SDLK_LEFT
]
=
010
;
special_keys
[
SDLK_UP
]
=
032
;
special_keys
[
SDLK_RIGHT
]
=
031
;
special_keys
[
SDLK_DOWN
]
=
033
;
special_keys
[
SDLK_HOME
]
=
023
;
/* vs */
special_keys
[
SDLK_PAGEUP
]
=
-
1
;
/* PgUp */
special_keys
[
SDLK_PAGEDOWN
]
=
-
1
;
/* PgDn */
special_keys
[
SDLK_END
]
=
-
1
;
special_keys
[
SDLK_INSERT
]
=
-
1
;
special_keys
[
SDLK_BREAK
]
=
TTY_STOP
;
special_keys
[
SDLK_F1
]
=
0201
;
/* povt */
special_keys
[
SDLK_F2
]
=
003
;
/* kt */
special_keys
[
SDLK_F3
]
=
0213
;
/* -|--> */
special_keys
[
SDLK_F4
]
=
026
;
/* |<--- */
special_keys
[
SDLK_F5
]
=
027
;
/* |---> */
special_keys
[
SDLK_F6
]
=
0202
;
/* ind su */
special_keys
[
SDLK_F7
]
=
0204
;
/* blk red */
special_keys
[
SDLK_F8
]
=
0200
;
/* shag */
special_keys
[
SDLK_F9
]
=
014
;
/* sbr */
special_keys
[
SDLK_F10
]
=
TTY_STOP
;
special_keys
[
SDLK_F11
]
=
TTY_RESET
;
special_keys
[
SDLK_F12
]
=
TTY_DOWNLOAD
;
for
(
i
=
0
;
i
<
256
;
i
++
)
{
shifted
[
i
]
=
i
;
}
for
(
i
=
'A'
;
i
<=
'Z'
;
i
++
)
{
shifted
[
i
]
=
i
^
040
;
shifted
[
i
^
040
]
=
i
;
}
shifted
[
'1'
]
=
'!'
;
shifted
[
'2'
]
=
'@'
;
shifted
[
'3'
]
=
'#'
;
shifted
[
'4'
]
=
'$'
;
shifted
[
'5'
]
=
'%'
;
shifted
[
'6'
]
=
'^'
;
shifted
[
'7'
]
=
'&'
;
shifted
[
'8'
]
=
'*'
;
shifted
[
'9'
]
=
'('
;
shifted
[
'0'
]
=
')'
;
shifted
[
'-'
]
=
'_'
;
shifted
[
'='
]
=
'+'
;
shifted
[
'\\'
]
=
'|'
;
shifted
[
'['
]
=
'{'
;
shifted
[
']'
]
=
'}'
;
shifted
[
';'
]
=
':'
;
shifted
[
'\''
]
=
'"'
;
shifted
[
'`'
]
=
'~'
;
shifted
[
','
]
=
'<'
;
shifted
[
'.'
]
=
'>'
;
shifted
[
'/'
]
=
'?'
;
}
static
int
tty_pending_int
=
0
;
/*
* tty_init() - Initialize the BK-0010 keyboard
...
...
@@ -135,10 +52,10 @@ void tty_init()
tty_pending_int
=
0
;
tty_scroll
=
01330
;
timer_intr_enabled
=
0
;
key_pressed
=
0100
;
if
(
old_scroll
!=
tty_scroll
)
{
scr_dirty
=
1
;
}
key_pressed
=
0100
;
}
/*
...
...
@@ -291,83 +208,22 @@ void stop_key() {
* LALT : 308
*/
static
int
ar2
=
0
;
void
tty_keyevent
(
SDL_Event
*
pev
)
{
int
k
,
c
;
k
=
pev
->
key
.
keysym
.
sym
;
if
(
SDLK_UNKNOWN
==
k
)
{
return
;
}
if
(
k
==
SDLK_LCTRL
)
k
=
SDLK_RETURN
;
else
if
(
k
==
SDLK_LALT
)
k
=
SDLK_SPACE
;
else
if
(
k
==
SDLK_BACKSPACE
)
k
=
265
;
else
if
(
k
==
SDLK_TAB
)
k
=
257
;
else
if
(
k
==
SDLK_LSHIFT
)
k
=
259
;
else
if
(
k
==
SDLK_SPACE
)
hasexit
=
1
;
if
(
pev
->
type
==
SDL_KEYUP
)
{
key_pressed
=
0100
;
if
(
special_keys
[
k
]
==
TTY_AR2
)
ar2
=
0
;
return
;
void
tty_keyevent
(
int
c
)
{
if
(
c
==
-
1
)
{
key_pressed
=
0100
;
return
;
}
/* modifier keys handling */
if
(
special_keys
[
k
]
!=
-
1
)
{
switch
(
special_keys
[
k
])
{
case
TTY_STOP
:
switch
(
c
)
{
case
TTY_STOP
:
stop_key
();
/* STOP is NMI */
return
;
case
TTY_NOTHING
:
return
;
case
TTY_AR2
:
ar2
=
1
;
return
;
case
TTY_RESET
:
if
(
ar2
)
{
lc_word
(
0177716
,
&
pdp
.
regs
[
PC
]);
pdp
.
regs
[
PC
]
&=
0177400
;
}
return
;
case
TTY_DOWNLOAD
:
{
char
buf
[
1024
];
extern
ui_load
(
const
char
*
);
fputs
(
_
(
"NAME? "
),
stderr
);
fgets
(
buf
,
1024
,
stdin
);
if
(
buf
[
strlen
(
buf
)
-
1
]
==
'\n'
)
{
buf
[
strlen
(
buf
)
-
1
]
=
'\0'
;
}
ui_load
(
buf
);
case
TTY_NOTHING
:
return
;
}
case
TTY_SWITCH
:
scr_switch
(
0
,
0
)
;
case
TTY_RESET
|
0200
:
lc_word
(
0177716
,
&
pdp
.
regs
[
PC
]);
pdp
.
regs
[
PC
]
&=
0177400
;
return
;
default:
c
=
special_keys
[
k
];
}
}
else
{
// Keysym follows ASCII
c
=
k
;
if
((
pev
->
key
.
keysym
.
mod
&
KMOD_CAPS
)
&&
isalpha
(
c
))
{
c
&=
~
040
;
/* make it capital */
}
if
(
pev
->
key
.
keysym
.
mod
&
KMOD_SHIFT
)
{
c
=
shifted
[
c
];
}
if
((
pev
->
key
.
keysym
.
mod
&
KMOD_CTRL
)
&&
(
c
&
0100
))
{
c
&=
037
;
}
}
// Win is AP2
if
(
ar2
)
{
c
|=
0200
;
}
tty_reg
|=
TTY_DONE
;
tty_data
=
c
&
0177
;
...
...
@@ -378,41 +234,4 @@ void tty_keyevent(SDL_Event * pev) {
}
}
/*
* tty_recv() - Called at various times during simulation to
* set if the user typed something.
*/
tty_recv
()
{
SDL_Event
ev
;
/* fprintf(stderr, "Polling events..."); */
while
(
SDL_PollEvent
(
&
ev
))
{
extern
void
mouse_event
(
SDL_Event
*
pev
);
switch
(
ev
.
type
)
{
case
SDL_KEYDOWN
:
case
SDL_KEYUP
:
tty_keyevent
(
&
ev
);
break
;
case
SDL_VIDEOEXPOSE
:
case
SDL_ACTIVEEVENT
:
/* the visibility changed */
scr_dirty
=
256
;
break
;
case
SDL_MOUSEBUTTONDOWN
:
case
SDL_MOUSEBUTTONUP
:
case
SDL_MOUSEMOTION
:
mouse_event
(
&
ev
);
break
;
case
SDL_VIDEORESIZE
:
scr_switch
(
ev
.
resize
.
w
,
ev
.
resize
.
h
);
break
;
case
SDL_QUIT
:
exit
(
0
);
default:
;
fprintf
(
stderr
,
_
(
"Unexpected event %d
\n
"
),
ev
.
type
);
}
}
/* fprintf(stderr, "done\n"); */
}
tty.h
0 → 100644
View file @
f2b872c4
extern
d_word
mouse_button_state
;
extern
int
relx
,
rely
;
extern
unsigned
short
mouse_but0
;
#define TTY_NOTHING 0377
#define TTY_STOP 0376
#define TTY_RESET 0375
/* "reset buton", only with AR2 */
#define TTY_AR2 0374
/* AP2 */
#define TTY_SWITCH 0373
/* video mode switch */
#define TTY_DOWNLOAD 0372
/* direct file load */
ui.c
View file @
f2b872c4
...
...
@@ -531,3 +531,14 @@ ui_viewbuf ( char * s )
}
}
}
void
ui_download
()
{
char
buf
[
1024
];
fputs
(
_
(
"NAME? "
),
stderr
);
fgets
(
buf
,
1024
,
stdin
);
if
(
buf
[
strlen
(
buf
)
-
1
]
==
'\n'
)
{
buf
[
strlen
(
buf
)
-
1
]
=
'\0'
;
}
ui_load
(
buf
);
}
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