[TI ASM] Event driven keypad input

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
User avatar
qarnos
Maxcoderz Staff
Posts: 227
Joined: Thu 01 Dec, 2005 9:04 am
Location: Melbourne, Australia

[TI ASM] Event driven keypad input

Post by qarnos »

Hi, all!

I've been working on some code for an event-driven keypad manager, which I have been meaning to attempt for ages. I finally got something working so I thought I'd share it with you.

The idea is you register event handlers for certain keypad events (up, down and hold) and in the main loop of your program, you call a despatch routine which calls the required handlers.

A typical program might look something like this:

Code: Select all

            .glBeginKeyEventList()
            
                .onKeyDown(GL_KEY_CLEAR)    myOnKeyClearHandler
                .onKeyDown(GL_KEY_MODE)     quittoshell
                .onKeyHold(GL_KEY_LEFT)     myOnKeyLeftHandler
                .onKeyHold(GL_KEY_RIGHT)    myOnKeyRightHandler

            .glEndKeyEventList()

            
Forever:    call    glPollKeyEvents
            call    glDespatchKeyEvents
            
            ; program code
            
            jp      Forever

myOnKeyClearHandler:

            ; etc

The "gl" prefix is because this started as an offshoot of a 2D game library which I need for a cool game idea I have. Of course, this code is a diversion of a diversion from that project, so maybe I should get back to work! :mrgreen:

Although doing direct-input yourself would be faster, for people like me who can't be bothered writing keyboard input code, this could be ideal. It's also handy for test-bed code when you just need some quick-n-dirty keyboard input.

The source can be downloaded here

The files:

* glinput.inc - equates 'n' stuff
* glinput.asm - the code
* glinput.txt - "I can't believe it's not documentation" (tm).
* etch.asm - quick-n-dirty example "etch-a-sketch" program for MirageOS.

If you use it and find it useful, find any bugs, or have a suggestion, let me know!
"I don't know why a refrigerator is now involved, but put that aside for now". - Jim e on unitedti.org

avatar courtesy of driesguldolf.
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Re: [TI ASM] Event driven keypad input

Post by benryves »

Excellent idea, as keypad input is generally a tedious thing to implement. :-) Next time I do any Z80 work I'll remember to try it out!
User avatar
qarnos
Maxcoderz Staff
Posts: 227
Joined: Thu 01 Dec, 2005 9:04 am
Location: Melbourne, Australia

Re: [TI ASM] Event driven keypad input

Post by qarnos »

benryves wrote:Excellent idea, as keypad input is generally a tedious thing to implement. :-) Next time I do any Z80 work I'll remember to try it out!
Tedious! That's the word I was looking for! :D

EDIT: I have just noticed a serious error in the "I can't believe it's not documentation" file (I told you not to believe it!), with regard to the macros. If you downloaded the file before reading this, download it again!
"I don't know why a refrigerator is now involved, but put that aside for now". - Jim e on unitedti.org

avatar courtesy of driesguldolf.
Post Reply