• Please review our updated Terms and Rules here

PET Keystroke detection

MicroCoreLabs

Experienced Member
Joined
Feb 12, 2016
Messages
283
Does anyone know what register sequence the 6502 polls or reads to detect a keystroke on the PET computer?
 
If you're talking about polling the KB matrix directly here you go:

http://www.6502.org/users/andre/petindex/progmod.html

You poke a 4 bit address row into the bottom half of 0xE810 and read the row from 0xE812. Keyboard matrix is 8x10 and is radically different depending on which keyboard (Business or Graphics) you have on your PET. (Of course beware if you're running BASIC its keyboard scan routine will probably clobber your row select poke before you can read the line, the software polling routine is linked to a 60hz interrupt.)

Edit: More info
 
Actually I was hoping for something simpler if it is available... Is there some address that the BIOS will read to see if a new key is available and what the keystroke was?

Hmm.. it seems easy enough to first detect that the ROW was written to PA1_PA and then detect when a non-0xFF value is read from PIA1_PB...
 
Last edited:
http://www.zimmers.net/cbmpics/cbm/PETx/petmem.txt

If you're letting the normal KERNAL routines run there are several interesting addresses. 151 tells you the ascii code of a key currently held down, and there are additional addresses for the number of bytes in the FIFO keyboard buffer. Or you can look up the EDIT/KERNEL ROM jump table and call the keyboard handler routines from your assembly language program.
 
If you JSR #$FFE4 (from assembly) the accumulator should return with the next character from the keyboard buffer.

If you load a character into the accumulator and JSR #$FFD2 the character should be output to the screen.

These ‘universal’ routines are part of the Kernal ROM jump table and ‘should’ be relatively stable across the different versions of BASIC, different keyboard models and (even) between the PET, VIC-20 etc.

If you can give us a little more information about what you are trying to achieve, then we way be able to advise you further.

Dave
 
I am investigating porting my MCL65+, a drop-in 6502 emulator, to the PET. The emulator can snoop accesses to registers on the motherboard to detect things like RAM/ROM bank switching or keystroke combinations. For the Apple II I snoop accesses to 0xC000 to detect new keystrokes, so I was wondering if there was a similar address I could snoop on there PET to do the same.
 
The Apple II uses a parallel ASCII-encoded keyboard. That is probably the exception for low-cost home computers, many of them use a CPU driven matrix like the PET. You can snoop those documented memory addresses used by the BASIC/KERNAL scanning routines if you want to see processed keystrokes without following the PIA accesses but if the PET runs a machine language program that overrides the scanning routine with its own then you’ll lose it.
 
I think Eudi's hit the nail on the head. It all depends upon the 'level' of compatibility you desire. The only absolute foolproof method to track keystrokes properly is to monitor the PIA ports and 'track' the scanning. It doesn't matter then whether it is BASIC or a machine code program (or a hybrid) that is running - your emulator will work. Once you start 'delving into the memory' you then run into compatibility issues and (as Eudi has already stated) a piece of machine code could just take over the machine and do what it liked...

Dave
 
FWIW, it looks like you already tried this emulator on a VIC-20; the VIC-20 (and C64, basically any Commodore 8-bit) scans its keyboard in an identical way. The I/O chip in front of it is a VIA instead of a PIA (that doesn't really matter except at initialization time) and it's at a different memory address but the mechanics are the same; a column number gets stuffed in one memory location and the down keys are on that row are read at the next location.
 
Back
Top