fast joystick support in assembler

Pagina 1/3
| 2 | 3

Door santiontanon

Paragon (1633)

afbeelding van santiontanon

01-07-2016, 06:17

I'm working on adding joystick support to Transball, and the easy way (below) seems very wasteful of CPU cycles (specially, since looking at the C-BIOS implementation of the GTSTCK function here ( https://sourceforge.net/p/cbios/cbios/ci/master/tree/src/mai... ), I see that this is not a quick routine at all!

  ;; first we check the keyboard:
  xor a
  call GTSTCK
  cp 0
  call z, checkJoystick  ;; if keyboard is not pressed, then check joystick
  ;; ... do whatever we want to do with the input
  ret

checkJoystick:
  inc a
  call GTSTCK
  ret

Is there a common better way in which people usually do this?

Thanks in advance!

Aangemeld of registreer om reacties te plaatsen

Van gdx

Enlighted (5360)

afbeelding van gdx

01-07-2016, 07:26

The same but a bit faster:

  ;; first we check the keyboard:
  xor a
  call GTSTCK
  or a
  call z, checkJoystick  ;; if keyboard is not pressed, then check joystick
  ;; ... do whatever we want to do with the input
  ret

checkJoystick:
  inc a
  jp GTSTCK

Van ARTRAG

Enlighted (6832)

afbeelding van ARTRAG

01-07-2016, 08:03

I'll see if I find something in my code
In the meantime note that
Cp 0
is equivalent to
And a
that is faster

Gdx was faster than me Smile

Van Bit Addict

Resident (34)

afbeelding van Bit Addict

01-07-2016, 09:14

An another approach is to directly read the PSG.

A link to the scanned Dutch article (the code is commented in English):
http://msx.hansotten.com/uploads/msxdocs/joyml.pdf

Van NYYRIKKI

Enlighted (5918)

afbeelding van NYYRIKKI

01-07-2016, 12:22

I think handling joystick directions with numbers 0-8 is quite stupid... This method comes from BASIC and makes things pretty complicated from assembler point of view. To read Joystick directly, see here.

Van NYYRIKKI

Enlighted (5918)

afbeelding van NYYRIKKI

01-07-2016, 12:30

... or maybe this is more easy to understand:

Van santiontanon

Paragon (1633)

afbeelding van santiontanon

01-07-2016, 15:00

Great! thanks guys! I think this is exactly what I needed! and indeed directions between 0-8 is quite stupid! I end up having to decode it with a bunch of conditionals that make the code longer than necessary Smile

Also, I actually never owned a joystick in the MSX era, but I see that there are two triggers in these pin specifications. Is it safe to assume joysticks have 2 buttons? or should I not make this assumption?

Van Daemos

Paragon (1959)

afbeelding van Daemos

01-07-2016, 15:52

assume 2 buttons unless you would love to support more.

Try this code as well. Fast and direct:

;Standard keyboard mapping/ this is the same for joystick
; bit	7	  6	  5		    4		    3		    2		  1		  0
;		     	Z 	C 		  X   	  right	  left	down	up	(keyboard)
;
Readjoystick:	

  di
	ld	a, 15	; Lee el puerto de joystick y almacena
	out	($A0), a	; los estados en las variables.
	in	a, ($A2)
	and	10101111b
	out	($A1), a
	ld	a, 14
	out	($A0), a
	ei
	in	a, ($A2) ;read left right up down and button 1 and 2

Van NYYRIKKI

Enlighted (5918)

afbeelding van NYYRIKKI

01-07-2016, 15:57

Any joystick will have one button... (ie. if you plug in C64 / Atari joystick) Practically all MSX users use MSX joysticks, so I think it is safe to assume 2 buttons. Lately some people have started to use Sega game pads with adapter to allow 6-buttons, but I think it is quite uncommon setup generally... Most safe is to double all the functions to MSX keyboard as well.

Van gdx

Enlighted (5360)

afbeelding van gdx

01-07-2016, 16:02

By direct access I use:

GetJoy1:
	ld	a,15
;	di
	out	(0a0h),a
	in	a,(0a2h)	; Read register 15
	and	08f		; and 10001111
	out	(0a1h),a	; Write to register 15

	ld	a,14
	out	(0a0h),a
;	ei
	in	a,(0a2h)	; Read register 14
	ret

GetJoy2:
	ld	a,15
;	di
	out	(0a0h),a
	in	a,(0a2h)	; Read register 15
	or	040h		; set bit 6
	out	(0a1h),a	; Write to register 15

	ld	a,14
	out	(0a0h),a
;	ei
	in	a,(0a2h)	; Read register 14
	ret

; EI/DI is needed depending your program

Van santiontanon

Paragon (1633)

afbeelding van santiontanon

01-07-2016, 16:36

wow, really good solutions guys! thanks! (and also thanks ARTRAG for the link in your message!!). I plan to play around with this tonight Smile

Pagina 1/3
| 2 | 3