Login
Back to forumReply to this topicGo to last reply

Posted By

Spektro
on 2018-11-13
23:01:42
 How to read joystick?

Hi,
What's the correct/best way to read the first joystick port in assembly language?

Posted By

Mad
on 2018-11-14
00:57:30
 Re: How to read joystick?

That's the routine I gathered from the sparse information I found.. Just as a actually working scribble.. I think everyone at plus4world has it's own routines. And maybe all of them are better (and optimized) happy.. The thing with disabling left if you move right is just for the emulator it can not happen in real life as far as I know..

;-------------------------------------------------------------
;-- gathers the joystick --
;-------------------------------------------------------------
; 7 Joystick 2 Fire (0=Pressed, 1=Released)
; 6 Joystick 1 Fire (0=Pressed, 1=Released)
; 3 Joystick 1/2 Right (0=Moved, 1=Released)
; 2 Joystick 1/2 Left (0=Moved, 1=Released)
; 1 Joystick 1/2 Down (0=Moved, 1=Released)
; 0 Joystick 1/2 Up (0=Moved, 1=Released)
JOYSTICKSELECT1 = %00000010
JOYSTICKSELECT2 = %00000100
SUBROUTINE
.temp dc.b $00
gatherJoystick1
lda #$ff
sta $fd30
lda #JOYSTICKSELECT1
sta $ff08
lda $ff08
eor #$ff
sta .temp
and #$02
sta joyMoveDown1
beq .notdown
lda #$00
sta joyMoveUp1
.notdown
lda .temp
and #$01
sta joyMoveUp1
beq .notup
lda #$00
sta joyMoveDown1
.notup
lda .temp
and #$04
sta joyMoveLeft1
beq .notleft
lda #$00
sta joyMoveRight1
.notleft
lda .temp
and #$08
sta joyMoveRight1
beq .notright
lda #$00
sta joyMoveLeft1
.notright
lda .temp
and #$40
sta joyPressed1
rts

Posted By

Spektro
on 2018-11-14
20:00:49
 Re: How to read joystick?

Works more reliably than mine happy I was using the keyboard latch register ($ff08) only.

Is it so that there is no way of knowing if the letters 5, 6, R, D and T where typed or if they were generated by joystick in port 1?

Posted By

Csabo
on 2018-11-14
20:10:17
 Re: How to read joystick?

Spektro, what you said is right. STA $FF08/LDA $FF08: check Joystick (only). STA $FD30/STA $FF08/LDA $FF08: check keyboard (if you're checking for 5/6/R/D/T, that can come from the joystick as well).

My games (e.g. 2048, FloodIt) come with ready-to use libraries including a keyboard handler loop, which includes Joystick handling as well. There's also a generic high score list handler and a generic string input routine. I wrote these in hopes that no-one ever have to code them again happy Anyway, you might want to check that out.

Posted By

Spektro
on 2018-11-18
04:43:31
 Re: How to read joystick?

Thanks Csabo!

It would be fantastic if we had a software development kit (SDK) for the Commodore 264 Series with documentation, examples, and assembly include files (libraries). I don't have skills to write the libraries (graphics, audio, I/O, etc.) but I can help maintaining and putting the SDK together. There is something in the Plus/4 Encyclopedia already: examples and documentation.



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon