Page 1 of 2

Joystick and keyboard input

Posted: Sun May 16, 2021 11:36 am
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 12:17 pm
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 12:19 pm
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 :)

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 3:42 pm
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)
                
                

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 6:21 pm
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?

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 6:37 pm
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 7:00 pm
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 7:14 pm
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 10:19 pm
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.

Re: Joystick and keyboard input

Posted: Sun May 16, 2021 10:21 pm
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...