Joystick and keyboard input

Anything QL Software or Programming Related.
spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Joystick and keyboard input

Post by spkr »

Hi there guys,

Does anyone happen to have some assembly programming reference material they got top of mind regarding reading and handling joystick and keyboard input for the QL? I havent looked into it just yet, but I reckoned just asking never hurt anyone.

I intend to handle joystick and keyboard input without using interrupts and without using the OS; I assuming this is possibe.


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Joystick and keyboard input

Post by NormanDunbar »

I've never used joysticks, so I can't help you there. As for reading the keyboard, without the OS, good luck! :D

I am 99.9% certain that you will need to talk to the second processor, which might be the 8049 (can you tell I have a good grasp of these things?) to be able to read the keyboard.

There are some details here on doing so: http://qdosmsq.dunbar-it.co.uk/doku.php ... rap_1:hdop unfortunately, no examples at this time. I'll sort something out later.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Re: Joystick and keyboard input

Post by spkr »

Hi there! Thanks for the quick response! As you can perhaps tell, Im a complete noob to these things, but I am hoping that one could poll the hardware, rather than being interrupted by it :)


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Joystick and keyboard input

Post by tofro »

The joystick is (like the keyboard) handled by the 8049 - So, you need to talk to the coprocessor in order to get both.

In BASIC, you would check the joystick with the KEYROW command, joystick 1 is the same as keyrow 1 (cursor keys, ESC and ENTER - in principle, moving the joystick is the same as pressing a key, see QL Manual). Joystick 2 is the same as pressing F1-F5

In order to do the same thing in assembly, you prepare a message to the 8049, send it, receive the answer and evaluate what you got (note evaluation is not complete...).

note it's easy to hang the CoPro on the QL with a wrong command string - There's no such thing as error checking in the communications, so be careful!

Code: Select all

                curLeft         EQU     1        ; cursor or joystick 1 left
                curUp           EQU     2        ; cursor or joystick 1 up
                escape          EQU     3        ; Escape pressed
                curRight        EQU     4        ; cursor or joystick 1 right
                space           EQU     6        ; space or joystick 1 fire
                curDown         EQU     7        ; cursor or joystick 1 down

                lea.l   IPCCmd,a3
                QDOSMT$ MT.IPCOM
                btst.b #curLeft,d1
                bne    moveLeft
                btst.b #curRight,d1 ....
                rts
                

IPCCmd    dc.l    $09010000               ;IPC command
                dc.l    $00000102               ;9=kbd,1=4bits in,2=8bits out (set to read row 1)
                
                


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Re: Joystick and keyboard input

Post by spkr »

tofro wrote:The joystick is (like the keyboard) handled by the 8049 - So, you need to talk to the coprocessor in order to get both.

In BASIC, you would check the joystick with the KEYROW command, joystick 1 is the same as keyrow 1 (cursor keys, ESC and ENTER - in principle, moving the joystick is the same as pressing a key, see QL Manual). Joystick 2 is the same as pressing F1-F5

In order to do the same thing in assembly, you prepare a message to the 8049, send it, receive the answer and evaluate what you got (note evaluation is not complete...).

note it's easy to hang the CoPro on the QL with a wrong command string - There's no such thing as error checking in the communications, so be careful!

Code: Select all

                curLeft         EQU     1        ; cursor or joystick 1 left
                curUp           EQU     2        ; cursor or joystick 1 up
                escape          EQU     3        ; Escape pressed
                curRight        EQU     4        ; cursor or joystick 1 right
                space           EQU     6        ; space or joystick 1 fire
                curDown         EQU     7        ; cursor or joystick 1 down

                lea.l   IPCCmd,a3
                QDOSMT$ MT.IPCOM
                btst.b #curLeft,d1
                bne    moveLeft
                btst.b #curRight,d1 ....
                rts
                

IPCCmd    dc.l    $09010000               ;IPC command
                dc.l    $00000102               ;9=kbd,1=4bits in,2=8bits out (set to read row 1)
                
                
Hej, thanks for your reply! What does the

Code: Select all

                QDOSMT$ MT.IPCOM

macro expand to, opcode or raw assembly wise?


User avatar
M68008
Trump Card
Posts: 223
Joined: Sat Jan 29, 2011 1:55 am
Contact:

Re: Joystick and keyboard input

Post by M68008 »

You can replace the macro with

Code: Select all

    moveq   #$11,d0
    trap       #1
On Sinclair ROMs, you can call this even when interrupts and the OS are disabled. Communication with the IPC is very slow, so use sparingly.


Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Joystick and keyboard input

Post by Derek_Stewart »

Hi,

Have a look at the QDOS Technical Manual:
http://www.dilwyn.me.uk/docs/manuals/qltm.pdf

or

SMSQ/E Reference Manual:
http://www.dilwyn.me.uk/docs/manuals/QD ... 20v4.5.pdf

give details for QDOS and SMSQ/E operating systems.


Regards,

Derek
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Joystick and keyboard input

Post by tofro »

Derek_Stewart wrote:Hi,

Have a look at the QDOS Technical Manual:
http://www.dilwyn.me.uk/docs/manuals/qltm.pdf

or

SMSQ/E Reference Manual:
http://www.dilwyn.me.uk/docs/manuals/QD ... 20v4.5.pdf

give details for QDOS and SMSQ/E operating systems.
Well, I can very well understand that the docs are not really helpful on this specific question. The SMSQ/E manual unfortunately mentions the "joystick" term only exactly once in conjunction with SMS.HDOP, the Technical Manual not at all. What you need to know is really a mix of the SuperBASIC manual (where it is mentioned that joystick input maps to KEYROW and which rows are affected) and how to obtain a raw keyboard scan from assembly via MT.IPCOM (where the command string format is really only scarcely explained) and that MT.IPCOM is at all related to KEYROW.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Re: Joystick and keyboard input

Post by spkr »

M68008 wrote:You can replace the macro with

Code: Select all

    moveq   #$11,d0
    trap       #1
On Sinclair ROMs, you can call this even when interrupts and the OS are disabled. Communication with the IPC is very slow, so use sparingly.
Hi, thanks! Yes this is what I thought would be happening, but in the end, the trap would just execute code from rom again. Perhaps Im stepping on limbs here, but are there disassembled ROM listings floating around somewhere? A quick google brings me down to http://www.dilwyn.me.uk/qlrom/index.html but the first notated ROM dumps I downloaded didnt contain the actual asm listings :(. Alternatively I could step through the trap execution using the lovely QemuLator debugger; but having the disassembled roms in searchable text format always comes in handy.


spkr
Bent Pin Expansion Port
Posts: 98
Joined: Tue May 04, 2021 6:52 pm

Re: Joystick and keyboard input

Post by spkr »

spkr wrote:
M68008 wrote:You can replace the macro with

Code: Select all

    moveq   #$11,d0
    trap       #1
On Sinclair ROMs, you can call this even when interrupts and the OS are disabled. Communication with the IPC is very slow, so use sparingly.
Hi, thanks! Yes this is what I thought would be happening, but in the end, the trap would just execute code from rom again. Perhaps Im stepping on limbs here, but are there disassembled ROM listings floating around somewhere? A quick google brings me down to http://www.dilwyn.me.uk/qlrom/index.html but the first notated ROM dumps I downloaded didnt contain the actual asm listings :(. Alternatively I could step through the trap execution using the lovely QemuLator debugger; but having the disassembled roms in searchable text format always comes in handy.
Hmmm now I realize. Perhaps the disassembled listings are meant to be loaded in an actual native assembler which in turn shows it as text again, rather than saving it as ascii...


Post Reply