KBDVBASE data passing

GFA, ASM, STOS, ...

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

KBDVBASE data passing

Post by simonsunnyboy »

TOS provides internal handlers to process data from the IKBD.

Code: Select all

4.22.6 KBDVBASE
typedef struct
{
   void   (*kb_midivec)();   /* MIDI interrupt vector    */
   void   (*kb_vkbderr)();   /* Keyboard error vector    */
   void   (*kb_vmiderr)();   /* MIDI error vector        */
   void   (*kb_statvec)();   /* Keyboard status          */
   void   (*kb_mousevec)();  /* Keyboard mouse status    */
   void   (*kb_clockvec)();  /* Keyboard clock           */
   void   (*kb_joyvec)();    /* Keyboard joystick status */
   void   (*kb_midisys)();   /* System Midi vector       */
   void   (*kb_kbdsys)();    /* Keyboard vector          */
   int8_t drvstat;           /* Keyboard driver status   */
} KBDVBASE;
Note: For the elements kb_clockvec and kb_joyvec one should note that the address of the packet is passed in register A0 and on the stack; also, the routines should be terminated with an RTS, and if possible run for no more than 1ms.

The element drvstat contains a non-zero value when the IKBD is in the process of sending a packet.
See http://toshyp.atari.org/en/004016.html#KBDVBASE

Is there a description available what sort of data is passed into those routines? For joystick a apointer in a0, but to what sort of data does this point? A single byte? Two bytes per stick?

I remember writing my own handler but what to use to intercept the official ones?
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: KBDVBASE data passing

Post by mfro »

if the IKDB is in "joystick event reporting mode" (should be if you didn't program it otherwise), that said pointer will point to a struct:

Code: Select all

typedef struct
{
    char header;    /* 0xfe joystick 0, 0xff joystick 1 */
    char val;       /* bits 0..3 set/clear for the four possible motion directions and bit 7 for the fire button */
} JOYEVENT;
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2370
Joined: Sun Aug 03, 2014 5:54 pm

Re: KBDVBASE data passing

Post by ThorstenOtto »

...unless you send an interrogate joystick command (0x16) to the IKBD, and are using 2 joysticks. In that case, the header byte will be 0xfd, followed by 2 bytes for the current state of the 2 joysticks.
simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: KBDVBASE data passing

Post by simonsunnyboy »

Thank you, that's what I was looking for.

Is the header byte always the first one pointed to by a0 so one can distinguish between them?
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
mfro
Atari God
Atari God
Posts: 1167
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: KBDVBASE data passing

Post by mfro »

simonsunnyboy wrote: Mon Aug 15, 2022 7:54 pm Is the header byte always the first one pointed to by a0 so one can distinguish between them?
This should be the case.

I think you however need to make sure the IKBD is not in the middle of a transfer when you exchange the vectors (only do that if the drvstat member is 0) to avoid getting out of sync. You'll probably need to block interrupts to implement the vector exchange properly.
simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: KBDVBASE data passing

Post by simonsunnyboy »

I'll keep that in mind, I think I read about this hint somewhere else aswell.
The packets themselves it seems are 1:1 the IKBD packets as received.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
Eero Tamminen
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2837
Joined: Sun Jul 31, 2011 1:11 pm

Re: KBDVBASE data passing

Post by Eero Tamminen »

simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: KBDVBASE data passing

Post by simonsunnyboy »

Eero Tamminen wrote: Wed Aug 17, 2022 9:34 am Code here might be of interest: http://eerott.mbnet.fi/hatari/programs.shtml#punssi
Indeed...if I understand correctly, the commented portions in _JoyISR are actually routines to be placed into the joystick packet handler slot?
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
User avatar
shoggoth
Nature
Nature
Posts: 1222
Joined: Tue Aug 01, 2006 9:21 am
Location: Halmstad, Sweden
Contact:

Re: KBDVBASE data passing

Post by shoggoth »

simonsunnyboy wrote: Wed Aug 17, 2022 3:06 pm
Eero Tamminen wrote: Wed Aug 17, 2022 9:34 am Code here might be of interest: http://eerott.mbnet.fi/hatari/programs.shtml#punssi
Indeed...if I understand correctly, the commented portions in _JoyISR are actually routines to be placed into the joystick packet handler slot?
Sequence of events:
IKBD ==> isr@0x118() ==> KBDVBASE.ikbdsys() ==> KBDVBASE.kb_joyvec()

isr@0x118 determines which ACIA initiated the interrupt (MIDI or IKBD), then in the case of the IKBD, calls ikbdsys(). This is where the IKBD parser is, and in turn calls kb_joyvec, kb_mousevec etc. So kb_joyvec receives the decoded joystick packed in full.
Ain't no space like PeP-space.
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2929
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: KBDVBASE data passing

Post by charles »

inside tos one of 12 books from abbucus or attic
gives a hexadecimal dump of the tos

it can be quite helpful at understanding which routines are polled and when and what section of code is called under each interupt
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2370
Joined: Sun Aug 03, 2014 5:54 pm

Re: KBDVBASE data passing

Post by ThorstenOtto »

LOL charles. Why look at a hexdump, when you can look at the source?
User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2929
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: KBDVBASE data passing

Post by charles »

cause addresses differ from theroy to practical
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!
User avatar
Eero Tamminen
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2837
Joined: Sun Jul 31, 2011 1:11 pm

Re: KBDVBASE data passing

Post by Eero Tamminen »

simonsunnyboy wrote: Wed Aug 17, 2022 3:06 pm
Eero Tamminen wrote: Wed Aug 17, 2022 9:34 am Code here might be of interest: http://eerott.mbnet.fi/hatari/programs.shtml#punssi
Indeed...if I understand correctly, the commented portions in _JoyISR are actually routines to be placed into the joystick packet handler slot?
The commented out old assembly version handles just joystick data. The assembly code that is actually used in the game, also simulates 2 joysticks with 9 + 9 keyboard keys. I.e. C-code does not need to care whether whether joystick or keyboard is used by either of the players.

Only limit is that many keyboards do not support pressing that many keys down at the same time, so if both players use a keyboard, they may be able to affect each other's input. This is not a bug in the assembly, game C-code or TOS, but a property of the given keyboard, and how it's wired.
simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: KBDVBASE data passing

Post by simonsunnyboy »

Back to KBDVBASE, on replacing the routines, is it also recommended to use XBRA here?
I think it wouldn't hurt.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
ThorstenOtto
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2370
Joined: Sun Aug 03, 2014 5:54 pm

Re: KBDVBASE data passing

Post by ThorstenOtto »

Dunno whether that is useful in this case. If someone else is already using the joystick, you are in trouble. Also you certainly don't want to call the previous handler, since that will probably read the ACIA data register again.
simonsunnyboy
Moderator
Moderator
Posts: 5520
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: KBDVBASE data passing

Post by simonsunnyboy »

I didn't necessarily plan to make use of the old vector as stored within the XBRA block but sometimes it could be useful to see if it has been replaced at all and by what software.

I am thinking more from a global emulator state perspective, e.g. inspecting if it really is in place or not.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee
Post Reply

Return to “Coding”