Jump to content
Sign in to follow this  
ParanoidLittleMan

Reading joystick state via TOS

Recommended Posts


  Reading joystick, keyboard via TOS in simple way

This is certainly part for which TOS documentation is not well done, some necessary details just

missing from avalable Atari DOCs.

So, there is XBIOS 34 function Kbdvbase, which will return in d0 address of structure:

 

long midivec
long vkbderr
long wmiderr
long statvec
long mousevec
long clockvec
long joyvec   * pos 24
long midisys
long ikbdsys

 

Those ending with 'vec' are vector addresses, and SW can put there own rutine to transfer current

status of those input devices.
Atari DOC s(and Atari ProfiBuch auch, pardon too) says only this:
"Address of packets will be in a0 and on stack too. Rutine must end with rts, and last not longer than

1 mS."  And that's just not enough to use it. Despite that it is really simple.

So, here is working example:

 
* Setting joystick monitoring rutine :

   move.w  #34,-(sp)   *Kbdvbase
   trap    #14
   addq.l    #2,sp    
 
   move.l  d0,a1
   lea 24(a1),a1   * Joystick vector
   move.l  (a1),joymorg  *Save original one (which is just an rts) - for restoring at PRG end
   move.l  #moni,(a1)   * put there address of own code to pick joystick state

*******

moni     * Joystick monitoring, very simple:
  * it is at joyvec address set with   XBIOS 34

    addq.l  #1,a0   *a0 is odd
    move.w  (a0),joyc    * first byte is for joy 0, second for joy 1
    rts   

 

 It activates every time when some joystick action is performed. And during ACIA interrupt - that's

why must be fast.  SW can now simply read when want values at variable joyc .
Of course, it can be done different - so, for instance that joystick interrupt initiates something

immediately. But normal usage is just reading joyc periodically.

Bits for joystick status:   7 - fire, 0 - down, 1 - up, 2 - left , 3 - right
Active when bit is set.

 

  • Like 1

Share this post


Link to post
Share on other sites

Nice stuff, thanks for sharing :)
And about some code to read a .PI1 file and display it on the screen?

 

Thanks in advance,
José Mário aka MadAxe

Share this post


Link to post
Share on other sites

OK, here is it is ASM, Devpac compatible:

 


 	move.w #2,-(sp) * Get screen address
   	trap #14
   	addq.l #2,sp

   	move.l d0,a6
   	lea  -100(a6),sp

   	
	clr.w	-(a7)
	pea	picn(pc)
	move.w	#$3D,-(a7)
	trap	#1
	addq.l	#8,a7
	move.w	d0,d7
	bmi	exitu
		
	lea  	-34(a6),a6
	pea	(a6)
	pea	32034 
	move.w	d7,-(a7)
	move.w	#$3F,-(a7)
	trap	#1
	lea	12(sp),sp

	move.w	d7,-(a7)
	move.w	#$3E,-(a7)
	trap	#1
	addq.l	#4,a7


	lea	2(a6),a6
	pea	(a6)
	move.w	#6,-(sp)
	trap	#14
	addq.l	#6,sp


	move.w	#7,-(sp)
	trap	#1
	addq.l	#2,sp


exitu	clr.w  -(sp)
	trap  #1

picn	dc.b "GITP.PI1",0
	even

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...