From 532240a2db6d494093040b94fbcafccf886d507c Mon Sep 17 00:00:00 2001 From: jede Date: Sun, 24 May 2020 22:47:20 +0200 Subject: [PATCH] Telestrat joystick management --- doc/telestrat.sgml | 13 +++- include/telestrat.h | 8 ++ libsrc/telestrat/joy/telestrat-joy.s | 109 +++++++++++++++++++++++++++ libsrc/telestrat/joy_stat_stddrv.s | 14 ++++ libsrc/telestrat/joy_stddrv.s | 13 ++++ libsrc/telestrat/libref.s | 3 +- 6 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 libsrc/telestrat/joy/telestrat-joy.s create mode 100644 libsrc/telestrat/joy_stat_stddrv.s create mode 100644 libsrc/telestrat/joy_stddrv.s diff --git a/doc/telestrat.sgml b/doc/telestrat.sgml index 0cb40c501..6d62ef7b7 100644 --- a/doc/telestrat.sgml +++ b/doc/telestrat.sgml @@ -189,15 +189,20 @@ port cardridge. Joystick drivers

-Telemon 2.4 & 3.0 manages joysticks but it had been handled yet. This means that -joysticks driver could be written easily. - Telemon 2.4 returns in keyboard buffer the direction of the joysticks. This means that if you get input from keyboard by conio cgetc function, you will get direction from joysticks. +Anyway, if you don't want to use ROM, you can use joysticks standard drivers in your code. + +The standard driver manages two joysticks. Only one button is managed for theses joysticks. + +Telestrat can handle one button for the left port, and three buttons for the right port (but this port was designed for a mouse). + +If you find a Telestrat mouse (which almost impossible :), these driver will work too because there is some extra hardware in the mouse to send direction. + Mouse drivers

-Telestrat manages also mouse, but it had been no handled yet in this version. +Telestrat manages also mouse (Joystick port) Telestrat mouse is really difficult to find. RS232 device drivers

diff --git a/include/telestrat.h b/include/telestrat.h index 1865f19a0..38762be1d 100644 --- a/include/telestrat.h +++ b/include/telestrat.h @@ -98,7 +98,15 @@ extern void telestrat_240_200_2_tgi[]; /* Referred to by tgi_static_stddrv[ #define CH_LIRA 95 #define CH_ESC 27 +/* Masks for joy_read */ +#define JOY_UP_MASK 0x10 +#define JOY_DOWN_MASK 0x08 +#define JOY_LEFT_MASK 0x01 +#define JOY_RIGHT_MASK 0x02 +#define JOY_BTN_1_MASK 0x04 +/* The addresses of the static drivers */ +extern void telestrat_joy[]; /* Referred to by joy_static_stddrv[] */ void oups(); void ping(); diff --git a/libsrc/telestrat/joy/telestrat-joy.s b/libsrc/telestrat/joy/telestrat-joy.s new file mode 100644 index 000000000..827e44a3f --- /dev/null +++ b/libsrc/telestrat/joy/telestrat-joy.s @@ -0,0 +1,109 @@ +; +; Telestrat joystick driver +; +; 2002-12-20, Based on Ullrich von Bassewitz's code. +; 2017-11-01, Stefan Haubenthal +; 2020-05-20n, Jede +; + + .include "joy-kernel.inc" + .include "joy-error.inc" + .include "telestrat.inc" + + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _telestrat_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READ + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 2 ; Number of joysticks we support + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #%11000000 + sta VIA2::DDRB + sta VIA2::PRB + ; We could detect joysticks because with previous command bit0,1,2,3,4 should be set to 1 after + ; But if some one press fire or press direction, we could reach others values which could break Joystick détection. + lda #JOY_ERR_OK +; rts ; Run into UNINSTALL instead + +; ------------------------------------------------------------------------ +; UNINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; + +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +; How telestrat joysticks works +; PB7 and PB6 select right or left port +; When PB7 and PB6 are high, it controls two CA3083 (2 NPN transistors array) bases. +; In that case, PB0 to PB4 are set to high (it means no action are pressed) +; When the user press something then bit will be set to 0. +; bit 0 is right +; bit 1 is left +; bit 2 is fire +; ... + +READ: + beq right + lda #%10000000 + ora VIA2::PRB + sta VIA2::PRB + ; then read + lda VIA2::PRB + eor #%10011111 + rts +right: + lda #%01000000 + ora VIA2::PRB + sta VIA2::PRB + ; then read + lda VIA2::PRB + eor #%01011111 + + rts diff --git a/libsrc/telestrat/joy_stat_stddrv.s b/libsrc/telestrat/joy_stat_stddrv.s new file mode 100644 index 000000000..0c4c3667b --- /dev/null +++ b/libsrc/telestrat/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _telestrat_joy + +.rodata + +_joy_static_stddrv := _telestrat_joy diff --git a/libsrc/telestrat/joy_stddrv.s b/libsrc/telestrat/joy_stddrv.s new file mode 100644 index 000000000..8dfdde36e --- /dev/null +++ b/libsrc/telestrat/joy_stddrv.s @@ -0,0 +1,13 @@ +; +; Name of the standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "telestrat_joy" diff --git a/libsrc/telestrat/libref.s b/libsrc/telestrat/libref.s index bdd0a671a..c737396a5 100644 --- a/libsrc/telestrat/libref.s +++ b/libsrc/telestrat/libref.s @@ -2,7 +2,8 @@ ; Jede (jede@oric.org), 2017-10-16 ; - .export tgi_libref + .export joy_libref, tgi_libref .import _exit +joy_libref := _exit tgi_libref := _exit