[CODE] Poll IKBD joysticks in asm

All 680x0 related coding posts in this section please.

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

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

[CODE] Poll IKBD joysticks in asm

Postby simonsunnyboy » Wed Apr 07, 2004 8:33 am

Hi folks,

this time a small routine for reading the standard IKBD joystick ports in asm. Comments are in german but I hope you'll understand anyway.

Code: Select all

; Joysticktestprogramm
;

gemdos equ 1
xbios equ 14
bios equ 13

text

; init program
go:   move.l sp,a5
   lea stackend,sp

; calculate program and data size for TOS - to free unused space
   movea.l 4(a5),a5   ; a5 points 100bytes below program start
   move.l $c(a5),d0
   add.l $14(a5),d0
   add.l $1c(a5),d0
   add.l #$100,d0
   move.l d0,-(sp)
   move.l a5,-(sp)
   move.w #0,-(sp)
   move.w #$4a,-(sp)
   trap #gemdos      ; SETBLOCK Gemdos
   add.l #12,sp      ; correct stack
   tst.l d0
   bne exit      ; error occured? -> go to error
   
; -------------------------
; main program entry point:
; -------------------------
main:

   jsr initjoystick
   
loop:
   cmpi.b #1,joyevent+1
   beq hoch
   
   cmpi.b #2,joyevent+1
   beq runter
   
   cmpi.b #4,joyevent+1
   beq links
   
   cmpi.b #8,joyevent+1
   beq rechts
   
   bra testtrig

hoch:   pea hochstring
   bra ausgabe
runter: pea runterstring
   bra ausgabe
links:   pea linksstring
   bra ausgabe
rechts:   pea rechtsstring
ausgabe:move.w #9,-(sp)
   trap #gemdos
   add.l #6,sp
   
   ; Joystick 1
testtrig:
   cmpi.b #128,joyevent+1
   bne loop
   
   
   
   
   
entprell:
   cmp.b #128,joyevent+1
   beq entprell
   
   jsr exitjoystick

; terminate program properly and return to desktop or shell...   
exit:   clr.l -(sp)
   trap #gemdos   ; TERM PROCESS Gemdos

;------------------------
; SUBROUTINES/ FUNCTIONS
;------------------------

initjoystick:

   ; save old joystick vector and set new one...
   
   move.w #$22,-(sP)
   trap #xbios
   addq.l #2,sp
   move.l d0,kbdvbase

   move.l kbdvbase,a0
   adda.l #24,a0
   move.l (a0),old_joyvec

   ; set new joystick vector
   move.l #new_joyvec,(a0)

   ; set joystick event reporting....

   pea initjoycommand
   move.w #0,-(sp)
   move.w #25,-(sp)
   trap #xbios
   addq.l #8,sp
   
   rts
   
exitjoystick:

   
   ; unset joystick event reporting
   pea exitjoycommand
   move.w #0,-(sp)
   move.w #25,-(sp)
   trap #xbios
   addq.l #8,sp
   
   ; restore old joystick vector
   move.l kbdvbase,a0
   adda.l #24,a0   
   move.l old_joyvec,(a0)

   rts

   ; actual joystick reporting routine   
new_joyvec:
   lea joyevent,a1
   addq.l #1,a0
   rept 2
   move.b (a0)+,(a1)+
   endr
   rts
;

hochstring:   dc.b "hoch ",0
runterstring:   dc.b "runter ",0
linksstring:   dc.b "links ",0
rechtsstring:     dc.b "rechts ",0
      even

initjoycommand: dc.b $14,0,0,0,0
exitjoycommand:   dc.b $08,0,0,0,0

      even
; stack
joyevent:    ds.l 0
      even
kbdvbase:   ds.l 0
old_joyvec:   ds.l 0

stkstart:    ds.l 1024
stackend:   ds.l 1   


Have fun!
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

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

Perihelion

Postby Perihelion » Thu Apr 15, 2004 2:09 pm

And here's MY version

http://emulazione.multiplayer.it/stgraveyard/Assembler/tuts/tut12.htm

although it has lots of sprite code and poo as well ...

User avatar
GT Turbo
Captain Atari
Captain Atari
Posts: 335
Joined: Tue Feb 17, 2004 9:41 am
Location: Alsace, France
Contact:

And IKBD interupt ?

Postby GT Turbo » Thu Apr 15, 2004 2:36 pm

Nobody use IKBD interrupt rout to read joy ? and for mouse ?

That's better, no request, no xbios, faster, ......


GT Turbo (Cerebral Vortex) :lol:
Never forget : Power is in your minds !!!

http://Cerebral-Vortex.net

http://Jagware.org

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

Postby simonsunnyboy » Thu Apr 15, 2004 3:52 pm

Seems you don't understand my code ;)
Ofcourse it hooks up into the IKBD interrupts.
There is no method to poll the standard joysticks using TOS calls.
You always need to hookup an IKBD interrupt to query them as TOS provides no routine.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

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

junosix
Captain Atari
Captain Atari
Posts: 289
Joined: Sun Jul 08, 2007 3:22 pm
Location: Plymouth

Re: [CODE] Poll IKBD joysticks in asm

Postby junosix » Sun Jan 10, 2010 12:10 pm

Had a go at reading the joystick this morning, works fine but my only question is about a0 which gets used in the process. If I'm using a0 for anything else at the time, does that simply get destroyed, or does it get recorded somehow before the joystick vector kicks in, then restored? I can't see how it would, but what I also find odd is that my program uses a0 for other stuff and doesn't seem to be affected any time the joystick interrupt needs to use it?

Is that right or am I just lucky at the moment? Is the answer not to use a0 for anything other than to reserve it for the joystick reading vector?

User avatar
Desty
Atari God
Atari God
Posts: 1970
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Re: [CODE] Poll IKBD joysticks in asm

Postby Desty » Sun Jan 10, 2010 6:01 pm

junosix wrote:Had a go at reading the joystick this morning, works fine but my only question is about a0 which gets used in the process. If I'm using a0 for anything else at the time, does that simply get destroyed, or does it get recorded somehow before the joystick vector kicks in, then restored? I can't see how it would, but what I also find odd is that my program uses a0 for other stuff and doesn't seem to be affected any time the joystick interrupt needs to use it?

Is that right or am I just lucky at the moment? Is the answer not to use a0 for anything other than to reserve it for the joystick reading vector?

I think the general practice with interrupt vectors is to save and restore all registers that could be changed during the routine?

You might wrap the interrupt code with something like this:

Code: Select all

joystick_isr:
  movem.l  d0-d2/a0-a2,-(sp)
  (do stuff that trashes d0-d2 and a0-a2)
  movem.l  (sp)+,d0-d2/a0-a2
  rte


Had a quick look at ssb's "new_joyvec" and I don't see how a0 or a1 are saved, which both get trashed. It should save and restore them, but his program was just an example I guess.

[edit]
(I was wrong, looks like there's no need to save and restore them since the IKBD handler apparently does it.)
Last edited by Desty on Sun Jan 10, 2010 9:03 pm, edited 1 time in total.
tá'n poc ar buile!

junosix
Captain Atari
Captain Atari
Posts: 289
Joined: Sun Jul 08, 2007 3:22 pm
Location: Plymouth

Re: [CODE] Poll IKBD joysticks in asm

Postby junosix » Sun Jan 10, 2010 6:54 pm

I'm basing it on perihelion's code from the tutorial which is even more basic than that. It's:

Code: Select all

read_joy
       move.b 2(a0),joy
       rts

So that's storing something that's already been placed into a0 by the interrupt so we can read it when wanted. I'd be right in thinking that putting an instruction to save a0 just above the "move.b 2(a0),joy" bit would be too late?

User avatar
Desty
Atari God
Atari God
Posts: 1970
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Re: [CODE] Poll IKBD joysticks in asm

Postby Desty » Sun Jan 10, 2010 8:59 pm

junosix wrote:I'm basing it on perihelion's code from the tutorial which is even more basic than that. It's:

Code: Select all

read_joy
       move.b 2(a0),joy
       rts

So that's storing something that's already been placed into a0 by the interrupt so we can read it when wanted. I'd be right in thinking that putting an instruction to save a0 just above the "move.b 2(a0),joy" bit would be too late?

Ah, ok. Had a quick look at the Perihelion tut on the wiki, which explains a little bit. So it's not really an interrupt routine - the IKBD sets up a0 to point to joystick data, rather than putting it in some fixed address (I guess). This implies that after your joystick routine exits (with RTS), then the IKBD interrupt (or whatever it is...) tidies up after you, at least restoring a0.

Found a little more on this on the Atari compendium:
When an IKBD message is pending, the interrupt handler for the ACIAs calls either the midisys handler or the ikbdsys handler to retrieve the data and handle any errors. The default action for the ikbdsys handler is to decide whether the packet contains error, status, joystick, clock, or mouse information and to route it appropriately to vkbderr, statvec, joyvec, clockvec, or mousevec. Keyboard packets are handled internally by ikbdsys.

Your handler should be patched into the appropriate vector and, if appropriate, expect the packet buffer to be pointed to by register A0. Unless your handler is designed to completely replace the functions of the default handler you should jump through the original vector pointer upon exit, otherwise simply use the 680x0 RTS instruction.


It doesn't explicitly say that the IKBD handler restores A0 and other registers, but it sounds from what you said that it does. You could test it by having your main program set all the registers to some constant value and loop checking that every register = 1234 (or whatever), terminating with a descriptive error if any is changed (and waggle the joystick and mouse about while the test program is running :D).
tá'n poc ar buile!

junosix
Captain Atari
Captain Atari
Posts: 289
Joined: Sun Jul 08, 2007 3:22 pm
Location: Plymouth

Re: [CODE] Poll IKBD joysticks in asm

Postby junosix » Sun Jan 10, 2010 9:26 pm

Desty wrote:This implies that after your joystick routine exits (with RTS), then the IKBD interrupt (or whatever it is...) tidies up after you, at least restoring a0.

Cool, thought so, thanks for looking into it! I'll put the theory into practise later to double-check but I'm sure you're right.

And that's purely the IKBD interfacing with the 68000 doing that then, no TOS involved whatsoever?

User avatar
Desty
Atari God
Atari God
Posts: 1970
Joined: Thu Apr 01, 2004 2:36 pm
Location: 53 21N 6 18W
Contact:

Re: [CODE] Poll IKBD joysticks in asm

Postby Desty » Sun Jan 10, 2010 9:39 pm

junosix wrote:And that's purely the IKBD interfacing with the 68000 doing that then, no TOS involved whatsoever?

I'm not sure, but would expect that part of TOS sets up the various jump tables and interrupt service routines, initialising the various peripherals including the IKBD? I suppose you couldn't just plug the IKBD into the bus and the 68k would automatically know what to do with it :)

[edit]
More speculation: probably at boot time, TOS sets up an interrupt handler for the ACIA/IKBD, which either polls the device regularly and calls the user (or default TOS handler) routine when the state changes or something.... or the interrupt is actually triggered by the IKBD and the TOS handler simply passes the information onto your routine via a0. So without TOS, you'd probably have to set up your own interrupt handler which polls the keyboard registers/etc.
Some smarter who can read faster than me (ironically usually be people like Nyh who speak English as a second language) would know for sure :D
tá'n poc ar buile!

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: [CODE] Poll IKBD joysticks in asm

Postby Nyh » Mon Jan 11, 2010 9:26 am

Desty wrote:More speculation: probably at boot time, TOS sets up an interrupt handler for the ACIA/IKBD, which either polls the device regularly and calls the user (or default TOS handler) routine when the state changes or something.

No need to speculate on the workings of the keyboard handler.

The keyboard is interfaced with a serial link by an ACIA. The ACIA generates an MFP interrupt when it has received a keyboard packed. This interrupt handler translated the keyboard data into key data, joystick data and mouse data.

You can do the complete keyboard handling yourself. This routine handles 3 joysticks (the two normal ones and the cursor joystick, arrow up, down, left, right), all other scan codes are put into 'last_key'. The C code sets up the keyboard interrupt and a 50 Hz timer D code (for playing music).

Code: Select all

/* init code in C */
  { /* flush keyboard, init interrupts */
    byte *p=(byte *)0xfffffc00UL;
    move_sr(0x2700);
    while(*p&1)
    {
      (void)p[2];
    }
    *(void**)0x110=timer_d_code;
    *(void**)0x118=key_interrupt;
    *(byte*)0xfffffa07UL=0;
    *(byte*)0xfffffa09UL=0x50; /* keyboard and timer d intterupt needed */
    *(byte*)0xfffffa13UL=0;    /* interrupt mask */
    *(byte*)0xfffffa15UL=0x50; /* keyboard and timer d intterupt needed */
    *(byte*)0xfffffa17UL=game.old_eoim&0xf0;
    *(byte*)0xfffffa1dUL=7;    /* timer d control */
    *(byte*)0xfffffa25UL=246;  /* timer d data */
  }

**********************************
** Handler in assembly
**********************************
JOY_UP    equ 1
JOY_LEFT  equ 4
JOY_RIGHT equ 8
JOY_DOWN  equ 2
JOY_FIRE  equ $80

;/* key handeler info */
;struct key_handler_info_struct

key_info:
joy0:     dc.b   0     ;  volatile byte joy0;
joy1:     dc.b   0     ;  volatile byte joy1;
joy2:     dc.b   0     ;  volatile byte joy2; /* cursor joystick */
last_key: dc.b   0     ;  volatile byte last_key;

.even

key_interrupt:
     move.l    d0,-(sp)          ;
     moveq     #0,d0             ; clear register
     move.b    $fffffc02.w,d0    ; get scancode
     add.w     d0,d0             ; verdubbel keycode
     move.w    .table_start(pc,d0.w),d0; get jump offset
     jmp       .table_start(pc,d0.w)

.table_start:
     dc.w      .default-.table_start ;00
     dc.w      .default-.table_start ;01
     dc.w      .default-.table_start ;02
     dc.w      .default-.table_start ;03
     dc.w      .default-.table_start ;04
     dc.w      .default-.table_start ;05
     dc.w      .default-.table_start ;06
     dc.w      .default-.table_start ;07
     dc.w      .default-.table_start ;08
     dc.w      .default-.table_start ;09
     dc.w      .default-.table_start ;0a
     dc.w      .default-.table_start ;0b
     dc.w      .default-.table_start ;0c
     dc.w      .default-.table_start ;0d
     dc.w      .default-.table_start ;0e
     dc.w      .default-.table_start ;0f
     dc.w      .default-.table_start ;10
     dc.w      .default-.table_start ;11
     dc.w      .default-.table_start ;12
     dc.w      .default-.table_start ;13
     dc.w      .default-.table_start ;14
     dc.w      .default-.table_start ;15
     dc.w      .default-.table_start ;16
     dc.w      .default-.table_start ;17
     dc.w      .default-.table_start ;18
     dc.w      .default-.table_start ;19
     dc.w      .default-.table_start ;1a
     dc.w      .default-.table_start ;1b
     dc.w      .default-.table_start ;1c
     dc.w      .default-.table_start ;1d
     dc.w      .default-.table_start ;1e
     dc.w      .default-.table_start ;1f
     dc.w      .default-.table_start ;20
     dc.w      .default-.table_start ;21
     dc.w      .default-.table_start ;22
     dc.w      .default-.table_start ;23
     dc.w      .default-.table_start ;24
     dc.w      .default-.table_start ;25
     dc.w      .default-.table_start ;26
     dc.w      .default-.table_start ;27
     dc.w      .default-.table_start ;28
     dc.w      .default-.table_start ;29
     dc.w      .default-.table_start ;2a
     dc.w      .default-.table_start ;2b
     dc.w      .default-.table_start ;2c
     dc.w      .default-.table_start ;2d
     dc.w      .default-.table_start ;2e
     dc.w      .default-.table_start ;2f
     dc.w      .default-.table_start ;30
     dc.w      .default-.table_start ;31
     dc.w      .default-.table_start ;32
     dc.w      .default-.table_start ;33
     dc.w      .default-.table_start ;34
     dc.w      .default-.table_start ;35
     dc.w      .default-.table_start ;36
     dc.w      .default-.table_start ;37
     dc.w      .default-.table_start ;38
     dc.w      .cur_fire_p-.table_start ;39
     dc.w      .default-.table_start ;3a
     dc.w      .default-.table_start ;3b
     dc.w      .default-.table_start ;3c
     dc.w      .default-.table_start ;3d
     dc.w      .default-.table_start ;3e
     dc.w      .default-.table_start ;3f
     dc.w      .default-.table_start ;40
     dc.w      .default-.table_start ;41
     dc.w      .default-.table_start ;42
     dc.w      .default-.table_start ;43
     dc.w      .default-.table_start ;44
     dc.w      .default-.table_start ;45
     dc.w      .default-.table_start ;46
     dc.w      .default-.table_start ;47
     dc.w      .cur_up_p-.table_start ;48
     dc.w      .default-.table_start ;49
     dc.w      .default-.table_start ;4a
     dc.w      .cur_left_p-.table_start ;4b
     dc.w      .default-.table_start ;4c
     dc.w      .cur_right_p-.table_start ;4d
     dc.w      .default-.table_start ;4e
     dc.w      .default-.table_start ;4f
     dc.w      .cur_down_p-.table_start ;50
     dc.w      .default-.table_start ;51
     dc.w      .default-.table_start ;52
     dc.w      .default-.table_start ;53
     dc.w      .default-.table_start ;54
     dc.w      .default-.table_start ;55
     dc.w      .default-.table_start ;56
     dc.w      .default-.table_start ;57
     dc.w      .default-.table_start ;58
     dc.w      .default-.table_start ;59
     dc.w      .default-.table_start ;5a
     dc.w      .default-.table_start ;5b
     dc.w      .default-.table_start ;5c
     dc.w      .default-.table_start ;5d
     dc.w      .default-.table_start ;5e
     dc.w      .default-.table_start ;5f
     dc.w      .default-.table_start ;60
     dc.w      .default-.table_start ;61
     dc.w      .default-.table_start ;62
     dc.w      .default-.table_start ;63
     dc.w      .default-.table_start ;64
     dc.w      .default-.table_start ;65
     dc.w      .default-.table_start ;66
     dc.w      .default-.table_start ;67
     dc.w      .default-.table_start ;68
     dc.w      .default-.table_start ;69
     dc.w      .default-.table_start ;6a
     dc.w      .default-.table_start ;6b
     dc.w      .default-.table_start ;6c
     dc.w      .default-.table_start ;6d
     dc.w      .default-.table_start ;6e
     dc.w      .default-.table_start ;6f
     dc.w      .default-.table_start ;70
     dc.w      .default-.table_start ;71
     dc.w      .default-.table_start ;72
     dc.w      .default-.table_start ;73
     dc.w      .default-.table_start ;74
     dc.w      .default-.table_start ;75
     dc.w      .default-.table_start ;76
     dc.w      .default-.table_start ;77
     dc.w      .default-.table_start ;78
     dc.w      .default-.table_start ;79
     dc.w      .default-.table_start ;7a
     dc.w      .default-.table_start ;7b
     dc.w      .default-.table_start ;7c
     dc.w      .default-.table_start ;7d
     dc.w      .default-.table_start ;7e
     dc.w      .default-.table_start ;7f
     dc.w      .default-.table_start ;80
     dc.w      .default-.table_start ;81
     dc.w      .default-.table_start ;82
     dc.w      .default-.table_start ;83
     dc.w      .default-.table_start ;84
     dc.w      .default-.table_start ;85
     dc.w      .default-.table_start ;86
     dc.w      .default-.table_start ;87
     dc.w      .default-.table_start ;88
     dc.w      .default-.table_start ;89
     dc.w      .default-.table_start ;8a
     dc.w      .default-.table_start ;8b
     dc.w      .default-.table_start ;8c
     dc.w      .default-.table_start ;8d
     dc.w      .default-.table_start ;8e
     dc.w      .default-.table_start ;8f
     dc.w      .default-.table_start ;90
     dc.w      .default-.table_start ;91
     dc.w      .default-.table_start ;92
     dc.w      .default-.table_start ;93
     dc.w      .default-.table_start ;94
     dc.w      .default-.table_start ;95
     dc.w      .default-.table_start ;96
     dc.w      .default-.table_start ;97
     dc.w      .default-.table_start ;98
     dc.w      .default-.table_start ;99
     dc.w      .default-.table_start ;9a
     dc.w      .default-.table_start ;9b
     dc.w      .default-.table_start ;9c
     dc.w      .default-.table_start ;9d
     dc.w      .default-.table_start ;9e
     dc.w      .default-.table_start ;9f
     dc.w      .default-.table_start ;a0
     dc.w      .default-.table_start ;a1
     dc.w      .default-.table_start ;a2
     dc.w      .default-.table_start ;a3
     dc.w      .default-.table_start ;a4
     dc.w      .default-.table_start ;a5
     dc.w      .default-.table_start ;a6
     dc.w      .default-.table_start ;a7
     dc.w      .default-.table_start ;a8
     dc.w      .default-.table_start ;a9
     dc.w      .default-.table_start ;aa
     dc.w      .default-.table_start ;ab
     dc.w      .default-.table_start ;ac
     dc.w      .default-.table_start ;ad
     dc.w      .default-.table_start ;ae
     dc.w      .default-.table_start ;af
     dc.w      .default-.table_start ;b0
     dc.w      .default-.table_start ;b1
     dc.w      .default-.table_start ;b2
     dc.w      .default-.table_start ;b3
     dc.w      .default-.table_start ;b4
     dc.w      .default-.table_start ;b5
     dc.w      .default-.table_start ;b6
     dc.w      .default-.table_start ;b7
     dc.w      .default-.table_start ;b8
     dc.w      .cur_fire_r-.table_start ;b9
     dc.w      .default-.table_start ;ba
     dc.w      .default-.table_start ;bb
     dc.w      .default-.table_start ;bc
     dc.w      .default-.table_start ;bd
     dc.w      .default-.table_start ;be
     dc.w      .default-.table_start ;bf
     dc.w      .default-.table_start ;c0
     dc.w      .default-.table_start ;c1
     dc.w      .default-.table_start ;c2
     dc.w      .default-.table_start ;c3
     dc.w      .default-.table_start ;c4
     dc.w      .default-.table_start ;c5
     dc.w      .default-.table_start ;c6
     dc.w      .default-.table_start ;c7
     dc.w      .cur_up_r-.table_start ;c8
     dc.w      .default-.table_start ;c9
     dc.w      .default-.table_start ;ca
     dc.w      .cur_left_r-.table_start ;cb
     dc.w      .default-.table_start ;cc
     dc.w      .cur_right_r-.table_start ;cd
     dc.w      .default-.table_start ;ce
     dc.w      .default-.table_start ;cf
     dc.w      .cur_down_r-.table_start ;d0
     dc.w      .default-.table_start ;d1
     dc.w      .default-.table_start ;d2
     dc.w      .default-.table_start ;d3
     dc.w      .default-.table_start ;d4
     dc.w      .default-.table_start ;5d
     dc.w      .default-.table_start ;d6
     dc.w      .default-.table_start ;d7
     dc.w      .default-.table_start ;d8
     dc.w      .default-.table_start ;d9
     dc.w      .default-.table_start ;da
     dc.w      .default-.table_start ;db
     dc.w      .default-.table_start ;dc
     dc.w      .default-.table_start ;dd
     dc.w      .default-.table_start ;de
     dc.w      .default-.table_start ;df
     dc.w      .default-.table_start ;e0
     dc.w      .default-.table_start ;e1
     dc.w      .default-.table_start ;e2
     dc.w      .default-.table_start ;e3
     dc.w      .default-.table_start ;e4
     dc.w      .default-.table_start ;e5
     dc.w      .default-.table_start ;e6
     dc.w      .default-.table_start ;e7
     dc.w      .default-.table_start ;e8
     dc.w      .default-.table_start ;e9
     dc.w      .default-.table_start ;ea
     dc.w      .default-.table_start ;eb
     dc.w      .default-.table_start ;ec
     dc.w      .default-.table_start ;ed
     dc.w      .default-.table_start ;ee
     dc.w      .default-.table_start ;ef
     dc.w      .default-.table_start ;f0
     dc.w      .default-.table_start ;f1
     dc.w      .default-.table_start ;f2
     dc.w      .default-.table_start ;f3
     dc.w      .default-.table_start ;f4
     dc.w      .default-.table_start ;f5
     dc.w      .default-.table_start ;f6
     dc.w      .default-.table_start ;f7
     dc.w      .default-.table_start ;f8
     dc.w      .default-.table_start ;f9
     dc.w      .default-.table_start ;fa
     dc.w      .default-.table_start ;fb
     dc.w      .default-.table_start ;fc
     dc.w      .default-.table_start ;fd
     dc.w      .new_joy0-.table_start ;fe
     dc.w      .new_joy1-.table_start ;ff

; key action code
.default:
     move.b    $fffffc02.w,last_key; store last key
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.new_joy0:
     move.l    #.get_joy0,$118.w
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.new_joy1:
     move.l    #.get_joy1,$118.w
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done

.get_joy0:
     move.b    $fffffc02.w,joy0  ; get joy0 status
     move.l    #key_interrupt,$118.w
     rte                         ; done
     
.get_joy1:
     move.b    $fffffc02.w,joy1  ; get joy1 status
     move.l    #key_interrupt,$118.w
     rte                         ; done

.cur_up_p:
     or.b      #JOY_UP,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_up_r:
     and.b     #!JOY_UP,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_left_p:
     or.b      #JOY_LEFT,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_left_r:
     and.b     #!JOY_LEFT,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_right_p:
     or.b      #JOY_RIGHT,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_right_r:
     and.b     #!JOY_RIGHT,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_down_p:
     or.b      #JOY_DOWN,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_down_r:
     and.b     #!JOY_DOWN,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_fire_p:
     or.b      #JOY_FIRE,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done
.cur_fire_r:
     and.b     #$7f,joy2
     move.l    (sp)+,d0          ; restore registers
     rte                         ; done


Hans Wessels

junosix
Captain Atari
Captain Atari
Posts: 289
Joined: Sun Jul 08, 2007 3:22 pm
Location: Plymouth

Re: [CODE] Poll IKBD joysticks in asm

Postby junosix » Mon Jan 11, 2010 10:11 am

Ah, cool - I'll have a go with that. Thanks :)

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

Re: [CODE] Poll IKBD joysticks in asm

Postby simonsunnyboy » Tue Jan 12, 2010 7:37 pm

I think I remember that it was clearly stated that a0 etc are saved by the TOS handler so I relied on that.
I haven't tried this code for 5 years or even longer...
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

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

JohnLeather
Atari User
Atari User
Posts: 34
Joined: Sat Dec 06, 2008 8:36 pm

Re: [CODE] Poll IKBD joysticks in asm

Postby JohnLeather » Sun Mar 28, 2010 6:28 pm

Code: Select all

SCANCODE    PACKETS      Description
F6         7          Status Report
F7         5         Absolute mouse position record
F8         2         Mouse button released or not pressed, followed by RELATIVE X,Y mouse position record
F9          2         Right mouse button pressed or being held down followed by RELATIVE X,Y mouse position record
FA         2         Left mouse button pressed or being held down followed by RELATIVE X,Y mouse position record
FB         2         Both mouse button pressed or being held down followed by RELATIVE X,Y mouse position record
FC         6         Time of day
FD         2         Both Joystick report header
FE         1         FxxxRLDU, joystick (port 0)
FF         1         FxxxRLDU, joystick (port 1)


Might be useful for someone who handling the ACIA/IKBD directly.

Note: When you have the mouse and joystick enabled, and you press Fire on the joystick it doesn't send $FE / $FF with bit 7 set, it sends scan code $F9 when you press the fire button and $F8 when you release instead.

User avatar
LaurentS
Captain Atari
Captain Atari
Posts: 284
Joined: Mon Jan 05, 2009 5:41 pm

Re: [CODE] Poll IKBD joysticks in asm

Postby LaurentS » Wed Aug 15, 2012 3:58 pm

Hi,

Sorry to reopen an old thread, but I've got a question :

Is there a easy way to use a routine in asm for a joystick detection + keyboard arrows ?
(I mean I'd like to use either a joystick or the arrow keyboard).

I'd like to be able to detect UP, LEFT, RIGHT, DOWN, but also UP-LEFT, UP-RIGHT, DOWN-LEFT and DOWN-RIGHT both for keyboard and joystick.

I'd also like this rout to be able to run under hatari (it means no reprogramming of the 6301).

Best regards

Laurent

User avatar
Eero Tamminen
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2000
Joined: Sun Jul 31, 2011 1:11 pm

Re: [CODE] Poll IKBD joysticks in asm

Postby Eero Tamminen » Fri Aug 24, 2012 11:30 am

LaurentS wrote:Hi,
Is there a easy way to use a routine in asm for a joystick detection + keyboard arrows ?
(I mean I'd like to use either a joystick or the arrow keyboard).

I'd like to be able to detect UP, LEFT, RIGHT, DOWN, but also UP-LEFT, UP-RIGHT, DOWN-LEFT and DOWN-RIGHT both for keyboard and joystick.

I'd also like this rout to be able to run under hatari (it means no reprogramming of the 6301).
Laurent


These don't reprogram IKBD, they just set up what "vector" (handler) the interrupt should call to handle the packet from IKBD, and have the ASM implementation for the interrupt handler.

I've done also one, see the PUNSSi game sources:
http://koti.mbnet.fi/tammat/open.shtml#punssi

Check the device.h, test.c and joyisrz.s (Motorola syntax) or joyisr.s (MIT syntax) source files.

device.h defines the array into which joystick and keyboard-emulating-joystick values put are, and a mapping from key codes to joystick directions.

It supports 2 joysticks + 1 key for exiting (as the interrupt handler replaces normal keyboard handling).

2 different keyboard key sets (of 5 keys) can emulate joysticks in case there's no real joystick(s). Which keys are used for which direction, are set in the mapping array in device.h.

NOTE: a potential problem with Hatari is that very rare PC keyboards support more than couple of keys being pressed at the same time and how many are supported can depend on where in the keyboard matrix they are. Ancient Keytronic keyboards and expensive gamer keyboards can support simultaneous presses from few more keys.

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: [CODE] Poll IKBD joysticks in asm

Postby Nyh » Fri Aug 24, 2012 12:01 pm

LaurentS wrote:Is there a easy way to use a routine in asm for a joystick detection + keyboard arrows ?
(I mean I'd like to use either a joystick or the arrow keyboard).

I'd like to be able to detect UP, LEFT, RIGHT, DOWN, but also UP-LEFT, UP-RIGHT, DOWN-LEFT and DOWN-RIGHT both for keyboard and joystick.

I'd also like this rout to be able to run under hatari (it means no reprogramming of the 6301).

The assembly routine I posted in my previous post in this thread does exactly that (plus it stores the last key pressed in at last_key). joy0 is joystick 0, joy1 is joystick 1 and joy2 is the cursor joystick (left arrow, right arrow, up arrow, down arrow and space for fire). The three variables are one byte each with bits set for the directions thar are taken and one bit (the MSB) for fire pressed.

Hans Wessels

User avatar
LaurentS
Captain Atari
Captain Atari
Posts: 284
Joined: Mon Jan 05, 2009 5:41 pm

Re: [CODE] Poll IKBD joysticks in asm

Postby LaurentS » Mon Aug 27, 2012 7:27 pm

Hi,

I thank you both very much for the help.
Nyh fits exactly my needs.

Thanks a lot.
Laurent


Social Media

     

Return to “680x0”

Who is online

Users browsing this forum: No registered users and 4 guests