Page 1 of 1

[TI ASM] Event driven keypad input

Posted: Fri 12 Jun, 2009 10:26 am
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!

Re: [TI ASM] Event driven keypad input

Posted: Fri 12 Jun, 2009 12:12 pm
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!

Re: [TI ASM] Event driven keypad input

Posted: Fri 12 Jun, 2009 12:37 pm
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!