Jump to content
IGNORED

Reading keyboard controllers


Wickeycolumbus

Recommended Posts

I'm working on a project that I'd like to use keyboard controllers for. The TIA programming manual says there should be a 400 microsecond delay between writing to the output port and reading the results from the TIA inputs. How many machine cycles does 400 microseconds translate to? Alternatively, are there any examples posted for reading the keyboard controllers? Thanks.

Link to comment
Share on other sites

I'm working on a project that I'd like to use keyboard controllers for. The TIA programming manual says there should be a 400 microsecond delay between writing to the output port and reading the results from the TIA inputs. How many machine cycles does 400 microseconds translate to? Alternatively, are there any examples posted for reading the keyboard controllers? Thanks.

1 microsecond = 1/1,000,000 seconds

1 color clock = 1/3,579,575 seconds

1 machine cycle = 1/1,193,192 seconds

 

400 microseconds = 400/1,000,000 = 4/10,000 = 1/2,500 seconds

 

1,193,192/2,500 = 478 machine cycles

 

478/76 = 6.3 scan lines

 

I posted some code in the batari Basic forum for reading the keypad controllers, and someone else cleaned it up and posted an improved version.

  • Like 1
Link to comment
Share on other sites

This is the keypad code I used in the 2600 dumper. It only check 1 keypad on the left controller port. At the end of the routine the value in X indicates which key has been pressed:

X=0 -> no key

X=1-9 -> 1-9

X=10 -> *

X=11 -> 0

X=12 -> #

(x values are decimal)

 

.readkeypad
lda #$FF
ldx #12
clc
.new_row
ror
sta SWCHA
ldy #120 ;2
.wait
dey		 ;2
bne .wait ;2*
bit INPT4
bpl .keypressed
dex
bit INPT1
bpl .keypressed
dex
bit INPT0
bpl .keypressed
dex
bne .new_row
.keypressed

I increased the delay to about 500us instead of the 400us suggested in the Stella guide, because the code wasn't working on one of my consoles (probably due to aging of the components on the board).

Also note that in Stella emulator the pot lines go low instantly when you write to SWCHA, so the code works even without the delay. I plan to write some test roms to help stephena improve this aspect, but that's not big deal anyway, as any rom which works on real hardware will work correctly on the emulator. A similar problem happens when dumping the paddle capacitors: in stella they are discharged instantly, but they takes a few cycles on real hardware, so if you set VBLANK d7 to 1 for too little cycles you can't read the entire range of paddle movement or you can't read them at all.

 

It seems that the "code" tag isn't working right on the forums as the TABs at the beginning of the lines are gone. :(

Edited by alex_79
Link to comment
Share on other sites

I posted some code in the batari Basic forum for reading the keypad controllers, and someone else cleaned it up and posted an improved version.

 

Another thing that needs to be added to the bB page:

 

www.atariage.com/forums/topic/105865-keypads-and-batari-basic/page__st__25#entry1800609

 

 

 

 

It seems that the "code" tag isn't working right on the forums as the TABs at the beginning of the lines are gone. :(

 

Try this the next time, before you post code:

 

http://alienbill.com...asic/aabbcc.cgi

 

It will keep your code looking the way it should.

Link to comment
Share on other sites

Also note that in Stella emulator the pot lines go low instantly when you write to SWCHA, so the code works even without the delay. I plan to write some test roms to help stephena improve this aspect, but that's not big deal anyway, as any rom which works on real hardware will work correctly on the emulator. A similar problem happens when dumping the paddle capacitors: in stella they are discharged instantly, but they takes a few cycles on real hardware, so if you set VBLANK d7 to 1 for too little cycles you can't read the entire range of paddle movement or you can't read them at all.

 

Yes, please :) Because the opposite won't necessarily be true; a ROM that works in the emulator may not work on real hardware.

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