Jump to content
IGNORED

Reading ATASCII from the keyboard in assembly


Recommended Posts

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?

Link to comment
Share on other sites

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 by TGB1718
  • Like 1
Link to comment
Share on other sites

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
  ...

 

  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

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 by pirx
  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...