
**********************************************************************
files: ROM.TXT, ROM.TAP
       KeyScan.BAS, KeyScan.ASM
       http://www.users.globalnet.co.uk/~jg27paw4/pourri/rom-routines.txt
**********************************************************************


** Which BASIC commands/functions affect FRAMES?
   =============================================

Whatever does a DI will interrupt the updating of FRAMES. Searching the ROM disassembly gives seven occurrences:
START, BEEPER, SA-BYTES, LD-BYTES, COPY, COPY-BUFF, NEW
So the only other one is COPY-BUFF, which does a DI when the printer buffer is full and it's going to send a line to the printer, so LPRINT might call that.

As mentioned above, indirect calls to those routines have to be considered as well, so MERGE & VERIFY call LD-BYTES and thus would do a DI. OPEN# & CLOSE# don't do a DI. I don't have the Shadow ROM disassembly to hand to check CAT, ERASE, FORMAT & MOVE.

Then there's also PLAY and RS232 I/O to channel "P" on the 128k, plus the 128ks DI all over the place when they're paging RAM in & out.


**********************************************************************


** System Flag Variables
   =====================

FLAGS (IY+1)
0 Set for no leading spaces before keyword
1 Set if printer active
2 Set if L/C cursor, reset if K
3 Set if L/C input mode, reset if K
4 Set for +3 ROM, reset for 48k ROM (+2A/+3 only)
5 Set if new key pressed (in LAST_K)
6 Set if type numeric, reset if string
7 Set if runtime, reset if syntax checking

TV_FLAG (IY+2)
0 Set if printing in lower screen
1 -
2 -
3 Set to print edit line when key input called
4 Set if auto LIST
5 Set to clear lower screen when key pressed
6 -
7 -

FLAGS2 (IY+48)
0 Reset if screen just cleared
1 Reset if printer buffer empty
2 Set if inside quotes
3 Set if CAPS LOCK on
4 Set if 'k' is current channel
5 -
6 -
7 -

FLAGX (IY+55)
0 -
1 Set if undefined variable
2 -
3 -
4 -
5 Set if INPUT mode, reset if EDIT mode
6 -
7 Set if INPUT LINE

P_FLAG (IY+87)
0 temporary value for OVER
1 permanent value for OVER
2 temporary value for INVERSE
3 permanent value for INVERSE
4 temporary value for INK 9
5 permanent value for INK 9
6 temporary value for PAPER 9
7 permanent value for PAPER 9

   =====================

  Bit 4 of FLAGS is Set for +3 ROM, Reset for 48k ROM (+2A/+3 only).

P_FLAG (IY+87)
0 temporary value for OVER
1 permanent value for OVER
2 temporary value for INVERSE
3 permanent value for INVERSE
4 temporary value for INK 9
5 permanent value for INK 9
6 temporary value for PAPER 9
7 permanent value for PAPER 9


**********************************************************************


** The $028e KEY_SCAN routine
   ==========================

On returning from $028e KEY_SCAN the DE register and the Zero flag indicate which keys are being pressed.

. The Zero flag is reset if pressing more than two keys, or pressing two keys and neither is a shift key; DE identifies two of the keys.
. The Zero flag is set otherwise, and DE identifies the keys.
. If pressing just the two shift keys then DE = $2718.
. If pressing one shift key and one other key, then D identifies the shift key and E identifies the other key.
. If pressing any one key, then D=$ff and E identifies the key.
. If pressing no key, then DE=$ffff.

The key codes returned by KEY_SCAN are shown below.

[code]
? hh dd bbbbbbbb   ? hh dd bbbbbbbb   ? hh dd bbbbbbbb   ? hh dd bbbbbbbb
1 24 36 00100011   Q 25 37 00100101   A 26 38 00100110  CS 27 39 00100111
2 1c 28 00011100   W 1d 29 00011101   S 1e 30 00011110   Z 1f 31 00011111
3 14 20 00010100   E 15 21 00010101   D 16 22 00010110   X 17 23 00010111
4 0c 12 00001100   R 0d 13 00001101   F 0e 14 00001110   C 0f 15 00001111
5 04  4 00000100   T 05  5 00000101   G 06  6 00000110   V 07  7 00000111
6 03  3 00000011   Y 02  2 00000010   H 01  1 00000001   B 00  0 00000000
7 0b 11 00001011   U 0a 10 00001010   J 09  9 00001001   N 08  8 00001000
8 13 19 00010011   I 12 18 00010010   K 11 17 00010001   M 10 16 00010000
9 1b 27 00011011   O 1a 26 00011010   L 19 25 00011001  SS 18 24 00011000
0 23 35 00100011   P 22 34 00100010  EN 21 33 00100001  SP 20 32 00100000
[/code]

This routine demonstrates the results.

KeyScan.BAS [code]
  10 LET bc=USR 23296
  11 LET k$=INKEY$: IF k$<" " THEN LET k$=" "
  12 IF INKEY$<>"" THEN GO TO 12
  13 PRINT "key ";k$;" : E=";PEEK 23670;" D=";PEEK 23671;" Z=";NOT bc
  14 POKE 23692,255: GO TO 10
[/code]

KeyScan.ASM [code]
        org  23296
        di
LOOP1:
        call $028e           ;KEY_SCAN
        ex   af,af'
        ld   a,$ff
        cp   e
        jr   z,LOOP1         ;"no key" pressed if E=$ff
        ld   (23670),de      ;(SEED)=DE
        ex   af,af'
        ei
        ld   bc,0
        ret  z
        inc  bc
        ret
[/code]


**********************************************************************