l12n Posted February 19 Share Posted February 19 What's the best way to get the ATASCII codes from the keyboard in assembly? The CH address returns the keyboard code. ATACHR is supposed to return the ATASCII code, but it always returns $1D. Also, any upside with using one's own keyboard interrupt handler vs. just reading some registers? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 19 Share Posted February 19 (edited) ATACHR is only used by the CIO routine that reads the keyboard. If you want the ATASCII codes, you need to open a channel to the keyboard and read the character that way. Other than that, you could use a lookup table to convert the keyboard code to ATASCII. Here are the codes:- https://www.atariarchives.org/c3ba/kcindex.php Edited February 19 by TGB1718 1 Quote Link to comment Share on other sites More sharing options...
xxl Posted February 19 Share Posted February 19 KGETCH equ $F302 jsr KGETCH REG A = ATASCII KEY Quote Link to comment Share on other sites More sharing options...
+DjayBee Posted February 19 Share Posted February 19 19 minutes ago, xxl said: KGETCH equ $F302 jsr KGETCH REG A = ATASCII KEY On any OS? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 19 Share Posted February 19 1 hour ago, DjayBee said: On any OS? No Quote Link to comment Share on other sites More sharing options...
xxl Posted February 19 Share Posted February 19 14 minutes ago, TGB1718 said: No on what Atari OS does it not work? Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted February 19 Share Posted February 19 10 minutes ago, xxl said: on what Atari OS does it not work? 400/800 1 Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted February 19 Share Posted February 19 You could get the vector from the device table at $E400, the "keyboard get" being at $E424. This is a push and RTS value and so -1 from the actual address, i.e. stored lo/hi as $FC $F2 for $F2FD. GetKeyVec: JMP $FFFF InitGetKey: LDA $E424 CLC ADC #1 STA GetKeyVec+1 LDA $E425 ADC #0 STA GetKeyVec+2 RTS TestGetKey: JSR InitGetKey JSR GetKeyVec ... 5 Quote Link to comment Share on other sites More sharing options...
EddyFree Posted February 21 Share Posted February 21 I just do this: GETKEY LDA $E425 PHA LDA $E424 PHA RTS JSR GETKEY Waits for keyboard input and returns ATASCII value of key pressed in accumulator. Works on XL and 800 OS. 4 Quote Link to comment Share on other sites More sharing options...
pirx Posted March 6 Share Posted March 6 (edited) if you need to skip the OS entirely (happens sometimes) you can use this a bit wasteful technique: https://github.com/pkali/scorch_src/blob/7f21748f9fbbacefe3a20de3649ced4c031fbd8b/constants.asm#L587 in this source you've got 2 tables - one with kbcodes, the other one with resulting data. in this example these are INTERNAL codes, not ATASCII, but the idea is the same. You get value from CH, look it up in `keycodes` table and grab the corresponding value from the other table. cons - uses more memory pros - OS independent, somewhat faster clever rearranging the kbcodes table to be monotonic could get O(logN) complexity instead of naïve O(N). if you are not memory constrained you could just drop 2 pages of memory for these tables and get O(1) speed. Of course 1 page is enough - ATASCII / INTERNAL codes in the corresponding places indexed by CH value And the code to retrieve is trivial: ldx CH lda ch_to_atascii_conversion_table,x you can't get easier and faster than this. Edited March 13 by pirx 1 Quote Link to comment Share on other sites More sharing options...
tebe Posted March 8 Share Posted March 8 https://github.com/tebe6502/Mad-Assembler/blob/master/examples/input_string.asm without OS 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.