Wickeycolumbus Posted November 2, 2012 Share Posted November 2, 2012 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. Quote Link to comment Share on other sites More sharing options...
SeaGtGruff Posted November 2, 2012 Share Posted November 2, 2012 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. 1 Quote Link to comment Share on other sites More sharing options...
alex_79 Posted November 4, 2012 Share Posted November 4, 2012 (edited) 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 November 4, 2012 by alex_79 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted November 4, 2012 Share Posted November 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
+stephena Posted November 4, 2012 Share Posted November 4, 2012 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. Quote Link to comment Share on other sites More sharing options...
Wickeycolumbus Posted November 6, 2012 Author Share Posted November 6, 2012 Thanks for the info guys. Also very good to know that Stella doesn't require the delay, saves future headaches. 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.