Index

Function Name: SCNKEY

Purpose: Scan the keyboard
Call address: $FF9F (hex) 65439 (decimal)
Preparation:

	Registers:	none
	Memory:		system map
	Flags:		none
	Calls:		none
Results:
	Registers:	none
	Memory:		keyboard buffer
			keyboard flags
	Flags:		none

Description: SCNKEY is an Editor routine that scans the entire C128 keyboard (except the 40/80 key). It distinguishes between ASCII keys, control keys, and programmable keys, setting keyboard status bytes and managing the keyboard buffer. After decoding the key, SCNKEY will manage such features as toggling cases, pauses or delays, and key repeats. It is normally called by the operating system during the 60Hz IRQ processing. Upon conclusion, SCNKEY leaves the keyboard hardware driving the keyline on which the STOP key is located.
There are two indirect RAM jumps encountered during a keyscan: KEYVEC ($33A) and KEYCHK ($33C). KEYVEC (alias KEYLOG) is taken whenever a key depression is discovered, before the key in .A has been decoded. KEYCHK is taken after the key has been decoded, just before putting it into the key buffer. KEYCHK carries the ASCII character in .A, the keycode in .Y, and the skiftkey status in .X.
The keyboard decode matrices are addressed via indirect RAM vectors as well, located at DECODE ($33E).
The following table describes them:

$33EMode 1->normal keys
$340Mode 2->SHIFT keys
$342Mode 3->C= keys
$344Mode 4->CONTROL keys
$346Mode 5->CAPS LOCK keys
$348Mode 6->ALT keys

The following list briefly describes some of the more vital variables utilized or maintained by SCNKEY:

ROWS$DC01->I/O port outputting keys
COLM$DC00->I/O port driving C64 keys
VIC #47$D02F->I/O port driving new keys
8502 P6$0001->I/O port sensing CAPS key
NDX$D0->keyboard buffer index
KEYD$34A->keyboard buffer
XMAX$A20->keyboard buffer size
SHFLAG$D3->shift key status
RPTFLG$A22->repeat key enables
LOCKS$F7->pause, mode disables

SCNKEY is also found in the Editor jump table at $C012.

Example:

	JSR	$FF9F	;scan the keyboard