Commodore 128 Alive!

Commodore 128 => 128 programmers => Assembly => Topic started by: MIRKOSOFT on May 05, 2010, 03:46 AM

Title: How to disable printing chars if ALT key is pressed?
Post by: MIRKOSOFT on May 05, 2010, 03:46 AM
Hi!

I have problem.

I need some combinations of ALT and any character as function, e.g. ALT+Q as quit. All works ok, function quits my program but letter Q is printed to screen.

HOW TO DISABLE PRINTING LETTERS/NUMBER IF ARE COMBINED WITH ALT?

Thanks for every help.

Miro
Title: Re: How to disable printing chars if ALT key is pressed?
Post by: Hydrophilic on May 06, 2010, 06:26 PM
Without seeing the code you use, it is difficult to say.  But the simple option would be to call KERNAL GETIN ($FFE4) to "eat" the key from the keyboard buffer.


BNE notAltKey
JSR function ; do something useful
JSR $FFE4 ; remove letter from keyboard buffer
notAltKey:
RTS


A more complicated solution would be to alter the keychk vector ($033c -> $c6ad) to point to your own code.  When this routine is called (normally during IRQ keyboard scan), .A = PETSCII code (for example $51 = "Q") and .X = shift key flags (for example $08 = ALT).  Normally this routine will put the key in the keyboard buffer ($34a~$352).  You might try something like this:


CPX #8 ;test (only) ALT key combination
BNE notAltKey
PHA
... test for supported ALT-Key (.A for PETSCII code)
BNE notAltRestore
... function ; do something usefull
PLA ;clean stack
JMP $C6C4 ;end keyscan routine
notAltRestore:
LDX #8
PLA
notAltKey:
JMP $C6AD ; default Editor ROM routine


With this 2nd method, your "function" should JMP to the default routine ($c6ad) if .A does NOT contain a supported ALT-Key combination (be sure .A and .X are preserved).  If .A DOES contain a supported ALT-Key combination, then you should exit with JMP $C6C4 which will reset CIA Keyboard lines and return to Editor ROM; in this case, the key is never put in the keyboard buffer.

I would recommend against this 2nd method simply because it requires altering system vectors.  You never know what kind of special utilities a user might have loaded...  As a general philosophy, never alter system vectors unless you HAVE to... just my opinion; use your best judgement...
EhPortal 1.34 © 2025, WebDev