Welcome, Guest. Please login or register.

Author Topic: keyboard I/O using system calls  (Read 6022 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline DamageXTopic starter

  • Sr. Member
  • ****
  • Join Date: Jun 2005
  • Posts: 339
    • Show all replies
    • http://www.hyakushiki.net/
keyboard I/O using system calls
« on: March 23, 2019, 10:00:00 PM »
Hey, my login still works. (And my old thread is still on the front page!?!?!?)

I want to write a more substantial program using this compiler and it's my understanding that 68K Amiga programs can also run on PPC systems when abstaining from direct hardware access in favor of using OS functions. So in the interest of cross-platform goodness, I'm looking for some help with keyboard I/O using input.device.

The code posted in my old thread has a section which appears to install an input handler. I tried to repurpose this code but the call to "DoIO" causes a freeze in this context.

I saw this documentation but unfortunately it is full of Amiga OS jargon like signals, message ports, and such, and it refers to header files that I don't have.
Quote
Three primary steps are required to open the input device:

    Create a message port using AllocSysObject() and ASOT_PORT type. Reply messages from the device must be directed to a message port.
    Create an extended I/O request structure of type IOStdReq or TimeRequest using AllocSysObject() and ASOT_IOREQUEST type. The I/O request created by the AllocSysObject() function will be used to pass commands and data to the input device.
    Open the Input device. Call OpenDevice(), passing the I/O request.
I don't see AllocSysObject in my listing of exec functions.

If anyone can point me to assembly language source for a simple WB program that accepts keyboard input it would be enlightening.

P.S. apologies to anyone who sent me a PM during the last five years. I just noticed a bunch of them.
 

Offline DamageXTopic starter

  • Sr. Member
  • ****
  • Join Date: Jun 2005
  • Posts: 339
    • Show all replies
    • http://www.hyakushiki.net/
Re: keyboard I/O using system calls
« Reply #1 on: March 25, 2019, 07:16:01 PM »
I got something to work. It seems that createmsgport and createiorequest are the proper system calls.
Code: [Select]
        asm
        move [4].d,a6

        ; create msgport
        jsr [a6-666]
        tst d0.d
        beq fail5
        move d0,[msgport].d

        ; createiorequest
        move [msgport].d,a0
        move $30,d0.d
        jsr [a6-654]
        tst d0.d
        beq fail6
        move d0,[ioreq].d

        ; open input.device
        move inputname,a0.d
        move [ioreq],a1.d
        move 0,d0.d
        move 0,d1.d
        jsr [a6-444]            ; opendevice
        tst d0.b
        bne fail7

        ; install input handler
        move [ioreq],a1.d
        move 9,[a1+$1C].w
        move ihheader.a,[a1+$28].d
        jsr [a6-456]            ; doio
Also need this goofy thing and an input routine.
Code: [Select]
ihheader:
        dd 0,0
        db 2,127
        dd ihname.a
        dd 0
        dd ihcode.a
ihname:
        db "great input handler",0
Code: [Select]
        ; input handler
        asm
ihcode:
        move a0.d,[a7-]

ihloop:
        move [a0+4].w,d0
        cmp $0100,d0                   ; keyboard event?
        bne ihnotkey       

        move [a0+6].w,d0
        move $7F,d1.d
        and d0,d1.w
        add keytable,d1
        move d1,a1.d
        move d0.b,[a1]

;        move 0,[a0+4].b                ; clear event
ihnotkey:
        move [a0].d,a0
        move a0.d,d0
        bne ihloop

        move [a7+],d0.d
        rts
        endasm
This receives all input though even if its window is not in focus. That's a bit awkward.
 

Offline DamageXTopic starter

  • Sr. Member
  • ****
  • Join Date: Jun 2005
  • Posts: 339
    • Show all replies
    • http://www.hyakushiki.net/
Re: keyboard I/O using system calls
« Reply #2 on: March 26, 2019, 12:43:14 PM »
Thanks for the input (no pun intended). Does IDCMP work with a custom screen instead of a window? Or do I have to open some kind of dummy window first?

Currently my test program opens a window or a screen (according to command line option) and then only uses writechunkypixels to update it in either case.

WaitForChar doesn't sound adequate in this instance, since I want key up/down events rather than characters.
 

Offline DamageXTopic starter

  • Sr. Member
  • ****
  • Join Date: Jun 2005
  • Posts: 339
    • Show all replies
    • http://www.hyakushiki.net/
Re: keyboard I/O using system calls
« Reply #3 on: March 29, 2019, 08:13:01 PM »
Everything seems to be working. An example program is here. This only uses the keyboard to stop decoding and close the window, but I am using similar code in a game engine I'm working on to move sprites around and whatnot. My A2000 doesn't feel like booting today but I tested in winuae and amazingly, I dug up my old Efika with morphos 2.1 demo and it worked there as well.