-
Notifications
You must be signed in to change notification settings - Fork 0
Keyboard Integration
Rudolf Stepan edited this page Jun 20, 2026
·
2 revisions
Keyboard input is routed through VIA6522 Port A and exposed to 6502 software via memory-mapped reads. SDL keyboard events feed an internal FIFO queue in the VIA implementation.
- VIA base: typically
$8800 - ORA (
$8801): read next key byte - DDRA (
$8803): set to input mode ($00) - IFR (
$880D): CA1 bit indicates key available - IER (
$880E): enable CA1 interrupt if desired
VIA_ORA = $8801
VIA_DDRA = $8803
VIA_IFR = $880D
LDA #$00
STA VIA_DDRA
.wait:
LDA VIA_IFR
AND #$02
BEQ .wait
LDA VIA_ORA#include <stdint.h>
#define VIA_ORA (*(volatile uint8_t *)0x8801)
#define VIA_DDRA (*(volatile uint8_t *)0x8803)
#define VIA_IFR (*(volatile uint8_t *)0x880D)
static inline void kb_init(void) {
VIA_DDRA = 0x00;
}
static inline uint8_t kb_getc_blocking(void) {
while ((VIA_IFR & 0x02u) == 0) {
}
return VIA_ORA;
}- ASCII letters and numbers
- common punctuation
- Enter (
0x0D) - Backspace (
0x08) - Arrow keys move the VIC hardware cursor around the 40x25 text screen.
- Backspace in screen-edit mode deletes the character left of the hardware cursor, including on recalled lines above the prompt.
- Enter in screen-edit mode reads the entire screen line (all 40 columns), trims trailing spaces, and replays the text to BASIC — matching C64 behavior. Echo is suppressed during replay so the line is not duplicated on screen.
- Pause/Break or Ctrl+C in the SDL window sends BASIC STOP (
0x03). - Home moves the cursor to the top-left cell; Shift+Home or Ctrl+L clears the screen and homes the cursor.
- ESC closes emulator window
Generated from 6502-sbc-emulator Markdown documentation. FPGA hardware track: 6502-sbc-fpga (FPGA Wiki).