fast joystick support in assembler

Page 3/3
1 | 2 |

By e_sedes

Expert (112)

e_sedes's picture

07-07-2016, 03:32

The way I usually read directions and triggers is looking in RAM variables. BIOS does this job every int, it's easy to read it.

For Joystick triggers, TRGFLG ($F3E8,1 byte)
bit 1 - Space bar, trig(0) (0 = pressed)
bit 4 - Stick 1, Trigger 1 (0 = pressed)
bit 5 - Stick 1, Trigger 2 (0 = pressed)
bit 6 - Stick 2, Trigger 1 (0 = pressed)
bit 7 - Stick 2, Trigger 2 (0 = pressed)

In $FBED there is the state of those keys
 bit 7  bit 6  bit 5  bit 4  bit 3  bit 2   bit 1    bit 0
  →      ↓        ↑     ←     DEL   INS  HOME  SPACE
(I think it's the same for all keyboard layouts)

For joystick directions I use GTSTCK, but reading E instead of A. In E you can see the four directions in this way:
bit 3  - Right
bit 2  - Left
bit 1  - Down
bit 0 - Up

I tried it on several real computers and on all BIOS I could on emulator, and it worked in all of them (not in CBIOS).

Maybe not the fastest way, but I think this is very simple and short.

By Manuel

Ascended (18950)

Manuel's picture

07-07-2016, 22:57

Are these standard addresses? It looks like it should also work on C-BIOS:

; F3E8: information about the joystick and space bar
; 7 6 5 4 3 2 1 0
; | | | |       +-- Space bar, trig(0) (0 = pressed)
; | | | +---------- Stick 1, Trigger 1 (0 = pressed)
; | | +------------ Stick 1, Trigger 2 (0 = pressed)
; | +-------------- Stick 2, Trigger 1 (0 = pressed)
; +---------------- Stick 2, Trigger 2 (0 = pressed)
TRGFLG:         equ     $F3E8

Or were you talking about the GTSTCK? That should also be implemented in C-BIOS... which version did you try? Or is it perhaps buggy?

By e_sedes

Expert (112)

e_sedes's picture

08-07-2016, 00:38

Yes, It's about the GTSTCK. Reading the result in E is not an official feature, I think. I found it some time ago when I was studying the routine. E is used in the process, and at the end it stores the state of the joystick in a very useful way. It seems like GTSTCK is the same code in all generations, so it works on every official BIOS.


Enlighted (6862)

ARTRAG's picture

08-07-2016, 00:47

E in GTSTCK is nothing else than R#14 from the PSG
If you need those bits read the PSG register, it is faster and works always

By e_sedes

Expert (112)

e_sedes's picture

08-07-2016, 00:54

Sure it's faster, but when speed is not needed I found E in GTSTCK a good option. It's simpler and shorter. At the end, it depends on what you need.

By DarkSchneider

Paladin (944)

DarkSchneider's picture

14-07-2016, 09:57

The E register for GTSTCK should not be assumed. OK maybe it works because in all BIOS the implementations is the same, but is not defined in the function itself for that purpose. It could be assumed as "coincidence", looking at micro-code.

I like your way to use the system variables when available, as you say if the BIOS does the work why not to use it.

I always like too to use BIOS and system variables for improved compatibility. I use GTSTCK and then a table (direction = flags_table[GTSTCK]) setting the direction flags depending on result, so I can use my own input flags method in this way and vary it if wanted. Input is a function that you call only once per loop, so is not very important the way used with some more or less cycles.

Page 3/3
1 | 2 |