diff --git a/auxmem.chario.s b/auxmem.chario.s index f5d802e..3eb344a 100644 --- a/auxmem.chario.s +++ b/auxmem.chario.s @@ -36,13 +36,13 @@ * Hardware locations -KBDDATA EQU $C000 ; Read Keyboard data -KBDACK EQU $C010 ; Acknowledge keyboard data -KBDAPPLFT EQU $C061 ; Left Apple key -KBDAPPRGT EQU $C062 ; Right Apple key -IOVBLNK EQU $C019 ; VBLNK pulse +KBDDATA EQU $C000 ; Read Keyboard data +KBDACK EQU $C010 ; Acknowledge keyboard data +KBDAPPLFT EQU $C061 ; Left Apple key +KBDAPPRGT EQU $C062 ; Right Apple key +IOVBLNK EQU $C019 ; VBLNK pulse -FLASHER EQU BYTEVARBASE+176 ; VSync counter for flashing cursor +FLASHER EQU BYTEVARBASE+176 ; VSync counter for flashing cursor FXEXEC EQU BYTEVARBASE+198 FXSPOOL EQU BYTEVARBASE+199 @@ -54,79 +54,13 @@ FXESCEFFECT EQU BYTEVARBASE+230 FX200VAR EQU BYTEVARBASE+200 FXSOFTLEN EQU BYTEVARBASE+216 FXSOFTOK EQU BYTEVARBASE+244 +SOFTKEYOFF EQU $03FF ; *TEMP* FX254VAR EQU BYTEVARBASE+254 FX2VAR EQU BYTEVARBASE+$B1 FX3VAR EQU BYTEVARBASE+$EC FX4VAR EQU BYTEVARBASE+$ED -KEYBUF EQU $400 ; *KEY buffer from $400-$7FF - ; Beware of the screen holes! -KEYBUFFREE EQU KEYBUF + $20 ; Free space word - -* *KEY -* --------------------------- -STARKEY LDA FXSOFTLEN - BNE ERRKEYUSED ; Key being expanded - JSR SCANDEC - CMP #$10 - BCC STARKEY1 -ERRBADKEY BRK - DB $FB - ASC 'Bad key' -ERRKEYUSED BRK - DB $FA - ASC 'Key in use' - BRK -STARKEY1 ASL A ; Key num * 2 - PHA ; Preserve for later - JSR SKIPCOMMA - LDA KEYBUFFREE+0 ; Free space LS byte - STA OSTEXT+0 - PLX ; Recover key num * 2 - PHX - STA KEYBUF,X ; Store LS byte start address - LDA KEYBUFFREE+1 ; Free space MS byte - STA OSTEXT+1 - PLX ; Recover key num * 2 - STA KEYBUF+1,X ; Store MS byte start address -:L1 LDA (OSLPTR),Y ; Read char from input - STA (OSTEXT) ; Store in buffer - PHA - INY ; Advance source index - JSR INCKEYPTR ; Advance dest pointer - PLA - CMP #$0D ; Carriage return? - BNE :L1 -:S1 LDA OSTEXT+0 - STA KEYBUFFREE+0 ; Free space LS byte - LDA OSTEXT+1 - STA KEYBUFFREE+1 ; Free space MS byte - RTS - - -* Increment OSTEXT, skipping over screen holes -* Screen holes are $478-$47F, $4F8-$4FF -* $578-$57F, $5F8-$5FF -* $678-$67F, $6F8-$6FF -* $778-$77F, $7F8-$7FF -INCKEYPTR LDA OSTEXT+0 ; Least significant byte - INC A - STA OSTEXT+0 - AND #$F8 - CMP #$78 ; If $78 to $7F - BEQ :HOLE78 - CMP #$F8 ; If $F8 to $FF - BEQ :HOLEF8 - RTS -:HOLE78 LDA #$80 - STA OSTEXT+0 - RTS -:HOLEF8 STZ OSTEXT+0 - INC OSTEXT+1 - RTS - - * OSWRCH handler **************** @@ -181,6 +115,7 @@ KBDINIT LDX #DEFBYTEEND-DEFBYTE-1 STA BYTEVARBASE+DEFBYTELOW,X DEX BPL :KBDINITLP + JSR SOFTKEYCHK ; Clear soft keys LDX #$C0 STX FX254VAR ; b7-b4=default KBD map, b3-b0=default MODE BIT SETV ; Set V @@ -327,6 +262,149 @@ NEGCALL >>> XF2MAIN,MACHRD ; Try to read Machine ID * KERNEL/KEYBOARD.S ******************* + +* SOFT KEY PROCESSING +===================== + +* *KEY +* --------------------------- +STARKEY LDA FXSOFTLEN + BNE ERRKEYUSED ; Key being expanded + JSR SCANDEC + CMP #$10 + BCC STARKEY1 +ERRBADKEY BRK + DB $FB + ASC 'Bad key' +ERRKEYUSED BRK + DB $FA + ASC 'Key in use' + BRK +* A slightly fiddly procedure, as we need to check the new +* definition is valid before we insert it, we can't bomb +* out halfway through inserting a string, and we mustn't +* have mainmem paged in while parsing the string as the +* string might be "underneath" the memory we've paged in, +* we don't know how long the new definition is and if +* it will fit into memory until after we've parsed it, so +* we either have to store it to a temp area or parse it +* twice. +* +* All this, and we need a structure that is reasonably coded, +* but with the priority to be easy for KEYREAD to extract +* from (as called more often), even if at expense of storing +* being more complex. +* +* Optimisations: +* BBC doesn't care if the new definition is valid, it removes +* the current definition before parsing, so a parse error +* results in the definition being cleared. +* eg *KEY 1 HELLO, *KEY 1 "X gives Bad string and key 1="" +* +* BBC uses (simplified): +* SOFTBUF+key+0 -> start of definition +* SOFTBUF+key+1 -> after last byte of definition +* SOFTBUF+16 -> free space after end of last definition +* definitions stored in order of creation +* +* Master uses: +* SOFTBUF+key -> lo.start of definition +* SOFTBUF+key+17 -> hi.start of definition +* SOFTBUF+key+1 -> lo.after last byte definition +* SOFTBUF+key+18 -> hi.after last byte definition +* SOFTBUF+16/33 -> free space after last byte last definition +* definitions stored in key order +* +* Bobbi's initial layout: +* 00/01 - 1E/1F -> pointers to start of each string +* 20/21 -> pointer to end of all strings +* +* Bobbi's initial scheme: +KEYBUF EQU $400 ; *KEY buffer from $400-$7FF + ; Beware of the screen holes! +KEYBUFFREE EQU KEYBUF + $20 ; Free space word + +STARKEY1 + ASL A ; Key num * 2 + PHA ; Preserve for later + JSR SKIPCOMMA + LDA KEYBUFFREE+0 ; Free space LS byte + STA OSTEXT+0 + PLX ; Recover key num * 2 + PHX + STA KEYBUF,X ; Store LS byte start address + LDA KEYBUFFREE+1 ; Free space MS byte + STA OSTEXT+1 + PLX ; Recover key num * 2 + STA KEYBUF+1,X ; Store MS byte start address +:L1 LDA (OSLPTR),Y ; Read char from input + STA (OSTEXT) ; Store in buffer + PHA + INY ; Advance source index + JSR INCKEYPTR ; Advance dest pointer + PLA + CMP #$0D ; Carriage return? + BNE :L1 +:S1 LDA OSTEXT+0 + STA KEYBUFFREE+0 ; Free space LS byte + LDA OSTEXT+1 + STA KEYBUFFREE+1 ; Free space MS byte + RTS + + +* Increment OSTEXT, skipping over screen holes +* Screen holes are $478-$47F, $4F8-$4FF +* $578-$57F, $5F8-$5FF +* $678-$67F, $6F8-$6FF +* $778-$77F, $7F8-$7FF +INCKEYPTR LDA OSTEXT+0 ; Least significant byte + INC A + STA OSTEXT+0 + AND #$F8 + CMP #$78 ; If $78 to $7F + BEQ :HOLE78 + CMP #$F8 ; If $F8 to $FF + BEQ :HOLEF8 + RTS +:HOLE78 LDA #$80 + STA OSTEXT+0 + RTS +:HOLEF8 STZ OSTEXT+0 + INC OSTEXT+1 + RTS + +* OSBYTE &12 - Clear soft keys +* ---------------------------- +SOFTKEYCHK LDA FXSOFTOK + BEQ BYTE12OK ; Soft keys ok, exit +BYTE12 LDX #120 ; 120 bytes in each half page + STX FXSOFTOK ; Soft keys being updated + +* Bobbi's initial scheme + PHP + SEI ; Prevent IRQs while writing + STZ WRMAINRAM ; Write to main mem +BYTE12LP STZ $0400-1,X ; Could be more efficient + STZ $0480-1,X + STZ $0500-1,X + STZ $0580-1,X + STZ $0600-1,X + STZ $0680-1,X + STZ $0700-1,X + STZ $0780-1,X + DEX + BNE BYTE12LP + LDA #KEYBUFFREE + STA KEYBUFFREE+1 + STA WRCARDRAM ; Restore writing to aux + PLP ; And restore IRQs +* + STX FXSOFTOK ; Soft keys updated +BYTE12OK RTS + + * KEYREAD ************************ * Test for and read from input, @@ -335,22 +413,24 @@ NEGCALL >>> XF2MAIN,MACHRD ; Try to read Machine ID * On exit, CS=no keypress * CC=keypress * A =keycode, X,Y=corrupted -KEYREAD LDY FXEXEC ; See if EXEC file is open - BEQ KEYREAD1 ; No, skip past - JSR OSBGET ; Read character from file - BCC KEYREADOK ; Not EOF, return it - LDA #$00 ; EOF, close EXEC file - STA FXEXEC ; Clear EXEC handle - JSR OSFIND ; And close it +KEYREAD LDY FXEXEC ; See if EXEC file is open + BEQ KEYREAD1 ; No, skip past + JSR OSBGET ; Read character from file + BCC KEYREADOK ; Not EOF, return it + LDA #$00 ; EOF, close EXEC file + STA FXEXEC ; Clear EXEC handle + JSR OSFIND ; And close it KEYREAD1 * * TO DO: expand current soft key -* LDA SOFTKEYLEN +* LDA FXSOFTLEN * BEQ KEYREAD2 * LDX SOFTKEYOFF +* page in main memory * LDA SOFTKEYS,X +* page out main memory * INC SOFTKEYOFF -* DEC SOFTKEYLEN +* DEC FXSOFTLEN * CLC * RTS * KEYREAD2 @@ -524,8 +604,9 @@ BYTE7E STA KBDACK ; Flush keyboard BEQ BYTE7E2 CLI ; Allow IRQs while flushing STX FXLINES ; Clear scroll counter + STX FXSOFTLEN ; Cancel soft key expansion JSR CMDEXEC0 ; Close any EXEC file -* JSR BUFFLUSHALL ; Flush all buffers +* JSR BUFFLUSHALL ; Flush all buffers (this should do FXSOFTLEN) BYTE7E2 LDX #$FF ; X=$FF, Escape was pending BYTE7C CLC ; &7C = clear escape condition BYTE7D ROR ESCFLAG ; $7D = set escape condition diff --git a/auxmem.init.s b/auxmem.init.s index 38b45fd..a6c0dd5 100644 --- a/auxmem.init.s +++ b/auxmem.init.s @@ -55,26 +55,106 @@ MOSINIT SEI ; Ensure IRQs disabled BRA :NORELOC :RELOC LDA #AUXMOS1 - STA OSLPTR+1 + STA A1H LDA #AUXMOS - STA OSTEXT+1 ; Y=0 from earlier -:L1 LDA (OSLPTR),Y ; Copy from source - STA (OSTEXT),Y ; to dest + STA A2H ; Y=0 from earlier +:L1 LDA (A1L),Y ; Copy from source + STA (A2L),Y ; to dest INY BNE :L1 ; Do 256 bytes - INC OSLPTR+1 ; Update source - INC OSTEXT+1 ; Update dest + INC A1H ; Update source + INC A2H ; Update dest BMI :L1 ; Loop until wrap past &FFFF - +* :L2 LDA MOSVEND-AUXMOS+AUXMOS1-256,Y STA $FF00,Y ; Copy MOS API and vectors INY ; to proper place BNE :L2 +*:S4 LDA #MOSVEC-MOSINIT+AUXMOS1 +* STA A1H +* LDA #MOSVEND-MOSINIT+AUXMOS1 +* STA A2H +* LDA #MOSAPI +* STA A4H +*:L2 LDA (A1L) +* STA (A4L) +* LDA A1H +* CMP A2H +* BNE :S5 +* LDA A1L +* CMP A2L +* BNE :S5 + +* LDA #AUXMOS1 +* STA A1H +* LDA #EAUXMOS1 +* STA A2H +* LDA #AUXMOS +* STA A4H +*:L1 LDA (A1L) +* STA (A4L) +* LDA A1H +* CMP A2H +* BNE :S1 +* LDA A1L +* CMP A2L +* BNE :S1 +* BRA :S4 +*:S1 INC A1L +* BNE :S2 +* INC A1H +*:S2 INC A4L +* BNE :S3 +* INC A4H +*:S3 BRA :L1 +* +*:S4 LDA #MOSVEC-MOSINIT+AUXMOS1 +* STA A1H +* LDA #MOSVEND-MOSINIT+AUXMOS1 +* STA A2H +* LDA #MOSAPI +* STA A4H +*:L2 LDA (A1L) +* STA (A4L) +* LDA A1H +* CMP A2H +* BNE :S5 +* LDA A1L +* CMP A2L +* BNE :S5 +* BRA :S8 +*:S5 INC A1L +* BNE :S6 +* INC A1H +*:S6 INC A4L +* BNE :S7 +* INC A4H +*:S7 BRA :L2 + +:S8 LDA #$EA ; NOP opcode STA :MODBRA+0 ; Next time around, we're already STA :MODBRA+1 ; in high memory @@ -91,39 +171,30 @@ MOSINIT SEI ; Ensure IRQs disabled MOSHIGH SEI ; Ensure IRQs disabled LDX #$FF TXS ; Initialise stack - INX ; X=$00 - LDA FXLANG ; Y=ResetType, A=Language + PHY ; Stack ResetType + LDA FXLANG ; A=Language + LDY FXSOFTOK ; A=Language, Y=Soft Keys Ok + INX ; X=$00 :SCLR STZ $0000,X ; Clear Kernel memory STZ $0200,X STZ $0300,X INX BNE :SCLR -:KCLR STZ $0400,X ; Clear *KEY buffer (avoid scrn holes) - STZ $0500,X - STZ $0600,X - STZ $0700,X - STZ $0480,X - STZ $0580,X - STZ $0680,X - STZ $0780,X - INX - CPX #$78 - BNE :KCLR - - LDA #KEYBUFFREE - STA KEYBUFFREE+1 - - STY FXRESET ; Set ResetType STA FXLANG ; Current language + STY FXSOFTOK ; Soft key validity + PLA + STA FXRESET ; Set ResetType + BEQ :INITPG2 ; Soft Reset, preserve settings + DEX ; X=$FF + STX FXLANG ; Current language=none + STX FXSOFTOK ; Invalidate soft keys - LDX #ENDVEC-DEFVEC-1 -:INITPG2 LDA DEFVEC,X ; Set up vectors +:INITPG2 LDX #ENDVEC-DEFVEC-1 +:INITPG2LP LDA DEFVEC,X ; Set up vectors STA $200,X DEX - BPL :INITPG2 + BPL :INITPG2LP LDA CYAREG ; GS speed register AND #$80 ; Speed bit only @@ -138,10 +209,8 @@ MOSHIGH SEI ; Ensure IRQs disabled BEQ :INITSOFT ; Soft reset, skip past LDA #7 ; Beep on HardReset/PowerReset JSR OSWRCH - LDA #$FF - STA FXLANG ; Current language=none * -* AppleII MOS beeps anyway, so always get a Beep +* AppleII MOS beeps anyway, so we always get a Beep * APPLECORN startup -> BBC Beep * Press Ctrl-Reset -> AppleII Beep * @@ -227,7 +296,7 @@ BYTE00 BEQ BYTE00A ; OSBYTE 0,0 - generate error RTS ; %000x1xxx host type, 'A'pple BYTE00A BRK DB $F7 -HELLO ASC 'Applecorn MOS 2022-12-07' +HELLO ASC 'Applecorn MOS 2022-11-08' DB $00 ; Unify MOS messages * TO DO: Move into RAM GSSPEED DB $00 ; $80 if GS is fast, $00 for slow