2021-08-20 22:57:14 +00:00
|
|
|
* AUXMEM.INIT.S
|
|
|
|
* (c) Bobbi 2021 GPL v3
|
|
|
|
*
|
|
|
|
* Initialization code running in Apple //e aux memory
|
2022-11-08 15:11:55 +00:00
|
|
|
* 08-Nov-2022 ResetType OSBYTE set
|
2022-11-09 18:50:54 +00:00
|
|
|
* 09-Nov-2022 Current language re-entered, reset on Power/Hard Reset
|
2022-12-14 15:03:55 +00:00
|
|
|
* 12-Dec-2022 Copy loop uses OSvars, single byte for MODBRA jump.
|
2022-12-31 07:01:21 +00:00
|
|
|
* 15-Dec-2022 Added check for *FX200,2/3 force PowerOn reset.
|
2022-11-09 18:50:54 +00:00
|
|
|
* BUG: If Ctrl-Break pressed during a service call, wrong ROM gets paged in
|
2022-11-08 15:11:55 +00:00
|
|
|
|
2021-08-20 22:57:14 +00:00
|
|
|
|
2021-08-08 02:48:24 +00:00
|
|
|
***********************************************************
|
|
|
|
* BBC Micro 'virtual machine' in Apple //e aux memory
|
|
|
|
***********************************************************
|
|
|
|
|
2022-10-19 18:02:01 +00:00
|
|
|
MAXROM EQU $F9 ; Max sideways ROM number
|
2022-11-09 18:50:54 +00:00
|
|
|
FXLANG EQU BYTEVARBASE+$FC ; Current language
|
|
|
|
FXRESET EQU BYTEVARBASE+$FD ; Last Reset type
|
|
|
|
FXOPTIONS EQU BYTEVARBASE+$FF ; Startup options
|
|
|
|
|
2021-10-29 03:13:47 +00:00
|
|
|
|
2022-11-07 12:25:54 +00:00
|
|
|
ZP1 EQU $90 ; $90-$9f are spare Econet space
|
|
|
|
; so safe to use
|
2021-08-08 02:48:24 +00:00
|
|
|
ZP2 EQU $92
|
|
|
|
ZP3 EQU $94
|
|
|
|
|
|
|
|
MOSSHIM
|
2022-10-19 18:02:01 +00:00
|
|
|
ORG AUXMOS ; MOS shim implementation
|
2021-08-08 02:48:24 +00:00
|
|
|
|
|
|
|
*
|
|
|
|
* Shim code to service Acorn MOS entry points using
|
|
|
|
* Apple II monitor routines
|
|
|
|
* This code is initially loaded into aux mem at AUXMOS1
|
|
|
|
* Then relocated into aux LC at AUXMOS by MOSINIT
|
|
|
|
*
|
2022-11-08 15:11:55 +00:00
|
|
|
* Initially executing at $2000 until copied to $D000
|
|
|
|
*
|
2022-11-09 18:50:54 +00:00
|
|
|
* When first run from loading from disk:
|
2022-11-08 15:11:55 +00:00
|
|
|
* Code will be at $2000-$4FFF, then copied to $D000-$FFFF
|
|
|
|
* When Ctrl-Reset pressed:
|
|
|
|
* AUX RESET code jumps to MAIN $D000
|
|
|
|
*
|
2022-10-19 18:02:01 +00:00
|
|
|
MOSINIT SEI ; Ensure IRQs disabled
|
|
|
|
LDX #$FF ; Initialize Alt SP to $1FF
|
2021-08-12 21:14:03 +00:00
|
|
|
TXS
|
2022-12-14 15:52:16 +00:00
|
|
|
|
2022-12-31 07:01:21 +00:00
|
|
|
* Ensure memory map set up:
|
2022-11-08 15:11:55 +00:00
|
|
|
STA WRCARDRAM ; Make sure we are writing aux
|
|
|
|
STA 80STOREOFF ; Make sure 80STORE is off
|
2022-12-14 15:03:55 +00:00
|
|
|
STA SET80VID ; 80 col on
|
|
|
|
STA CLRALTCHAR ; Alt charset off
|
|
|
|
STA PAGE2 ; PAGE2
|
2022-11-08 15:11:55 +00:00
|
|
|
LDA LCBANK1 ; LC RAM Rd/Wt, 1st 4K bank
|
2022-10-12 04:00:36 +00:00
|
|
|
LDA LCBANK1
|
2022-12-31 07:01:21 +00:00
|
|
|
* (Move these later to prevent brief glimpse of screen with code in it?)
|
2022-12-14 15:03:55 +00:00
|
|
|
|
2022-11-09 18:50:54 +00:00
|
|
|
LDY #$00 ; $00=Soft Reset
|
2022-12-14 15:03:55 +00:00
|
|
|
:MODBRA SEC ; Changed to CLC after first run
|
|
|
|
BCC :NORELOC ; Subsequent run, skip to code
|
2021-08-08 02:48:24 +00:00
|
|
|
|
2022-12-14 15:03:55 +00:00
|
|
|
* Copy code to high memory, (OSCTRL)=>source, (OSLPTR)=>dest
|
2022-11-09 18:50:54 +00:00
|
|
|
:RELOC LDA #<AUXMOS1 ; Source
|
2022-12-14 15:03:55 +00:00
|
|
|
STA OSCTRL+0
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA #>AUXMOS1
|
2022-12-14 15:03:55 +00:00
|
|
|
STA OSCTRL+1
|
|
|
|
STY OSLPTR+0 ; Y=0 from earlier
|
|
|
|
LDA #>AUXMOS ; AUXMOS is always &xx00
|
|
|
|
STA OSLPTR+1
|
|
|
|
:L1 LDA (OSCTRL),Y ; Copy from source
|
|
|
|
STA (OSLPTR),Y ; to dest
|
2022-11-09 18:50:54 +00:00
|
|
|
INY
|
|
|
|
BNE :L1 ; Do 256 bytes
|
2022-12-14 15:03:55 +00:00
|
|
|
INC OSCTRL+1 ; Update source
|
|
|
|
INC OSLPTR+1 ; Update dest
|
2022-11-09 18:50:54 +00:00
|
|
|
BMI :L1 ; Loop until wrap past &FFFF
|
2022-12-11 15:48:22 +00:00
|
|
|
*
|
2022-11-09 18:50:54 +00:00
|
|
|
:L2 LDA MOSVEND-AUXMOS+AUXMOS1-256,Y
|
|
|
|
STA $FF00,Y ; Copy MOS API and vectors
|
|
|
|
INY ; to proper place
|
|
|
|
BNE :L2
|
|
|
|
|
2022-12-14 15:03:55 +00:00
|
|
|
LDA #$18 ; CLC opcode, next time around, we're
|
|
|
|
STA :MODBRA ; already in high memory
|
2022-11-08 15:11:55 +00:00
|
|
|
LDY #$02 ; $02=PowerOn
|
2022-12-31 07:01:21 +00:00
|
|
|
* We only change one byte to protect against a RESET happening halfway between
|
|
|
|
* two bytes being changed, leaving the code inconsistant.
|
2022-11-08 15:11:55 +00:00
|
|
|
|
2022-12-14 15:52:16 +00:00
|
|
|
:NORELOC JMP MOSHIGH ; Ensure executing in high memory from here
|
2021-08-08 02:48:24 +00:00
|
|
|
|
2022-11-08 15:11:55 +00:00
|
|
|
* From here onwards we are always executing at $D000 onwards
|
|
|
|
* Y=ResetType
|
|
|
|
|
|
|
|
MOSHIGH SEI ; Ensure IRQs disabled
|
2021-08-10 01:27:44 +00:00
|
|
|
LDX #$FF
|
2022-11-08 15:11:55 +00:00
|
|
|
TXS ; Initialise stack
|
2022-12-31 07:01:21 +00:00
|
|
|
LDA FX200VAR ; Check *FX200
|
|
|
|
AND #$02 ; Check if bit 1 set
|
|
|
|
BEQ :SCLR0 ; No, keep existing ResetType
|
|
|
|
TAY ; Otherwise, force to PowerOn reset
|
|
|
|
:SCLR0 PHY ; Stack ResetType
|
2022-12-11 15:48:22 +00:00
|
|
|
LDA FXLANG ; A=Language
|
2022-12-14 15:03:55 +00:00
|
|
|
LDY FXSOFTOK ; Y=Soft Keys Ok
|
2022-11-09 18:50:54 +00:00
|
|
|
|
2022-12-11 15:48:22 +00:00
|
|
|
INX ; X=$00
|
2022-11-09 18:50:54 +00:00
|
|
|
:SCLR STZ $0000,X ; Clear Kernel memory
|
|
|
|
STZ $0200,X
|
|
|
|
STZ $0300,X
|
2021-08-10 01:27:44 +00:00
|
|
|
INX
|
|
|
|
BNE :SCLR
|
2022-11-09 18:50:54 +00:00
|
|
|
STA FXLANG ; Current language
|
2022-12-11 15:48:22 +00:00
|
|
|
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
|
2021-08-10 01:27:44 +00:00
|
|
|
|
2022-12-11 15:48:22 +00:00
|
|
|
:INITPG2 LDX #ENDVEC-DEFVEC-1
|
|
|
|
:INITPG2LP LDA DEFVEC,X ; Set up vectors
|
2021-08-08 02:48:24 +00:00
|
|
|
STA $200,X
|
|
|
|
DEX
|
2022-12-11 15:48:22 +00:00
|
|
|
BPL :INITPG2LP
|
2021-08-10 01:27:44 +00:00
|
|
|
|
2022-11-08 15:11:55 +00:00
|
|
|
LDA CYAREG ; GS speed register
|
|
|
|
AND #$80 ; Speed bit only
|
|
|
|
STA GSSPEED ; In Alt LC for IRQ/BRK hdlr
|
2022-09-24 00:24:39 +00:00
|
|
|
|
2022-11-08 15:11:55 +00:00
|
|
|
JSR ROMINIT ; Build list of sideways ROMs
|
|
|
|
JSR KBDINIT ; Returns A=startup MODE
|
|
|
|
JSR VDUINIT ; Initialise VDU driver
|
2021-08-26 21:36:46 +00:00
|
|
|
JSR PRHELLO
|
2022-11-09 18:50:54 +00:00
|
|
|
JSR OSNEWL
|
|
|
|
LDA FXRESET ; Get ResetType
|
|
|
|
BEQ :INITSOFT ; Soft reset, skip past
|
|
|
|
LDA #7 ; Beep on HardReset/PowerReset
|
2021-08-26 21:36:46 +00:00
|
|
|
JSR OSWRCH
|
2022-11-09 18:50:54 +00:00
|
|
|
*
|
2022-12-11 15:48:22 +00:00
|
|
|
* AppleII MOS beeps anyway, so we always get a Beep
|
2022-11-09 18:50:54 +00:00
|
|
|
* APPLECORN startup -> BBC Beep
|
|
|
|
* Press Ctrl-Reset -> AppleII Beep
|
2022-11-08 15:11:55 +00:00
|
|
|
*
|
2022-11-09 18:50:54 +00:00
|
|
|
* Find a language to enter
|
|
|
|
:INITSOFT LDX FXLANG ; Get current language
|
2022-12-14 15:03:55 +00:00
|
|
|
BPL INITLANG ; b7=ok, use it
|
2022-11-09 18:50:54 +00:00
|
|
|
LDX ROMMAX ; Look for a language
|
|
|
|
:FINDLANG JSR ROMSELECT ; Bring ROM X into memory
|
|
|
|
BIT $8006 ; Check ROM type
|
2022-12-14 15:03:55 +00:00
|
|
|
BVS INITLANG ; b6=set, use it
|
2022-11-09 18:50:54 +00:00
|
|
|
DEX ; Step down to next ROM
|
|
|
|
BPL :FINDLANG ; Loop until all tested
|
2022-12-14 15:03:55 +00:00
|
|
|
ERRNOLANG BRK ; No language found
|
2022-11-09 18:50:54 +00:00
|
|
|
DB $F9
|
|
|
|
ASC 'No Language'
|
|
|
|
BRK
|
2022-11-08 15:11:55 +00:00
|
|
|
*
|
2022-12-14 15:03:55 +00:00
|
|
|
INITLANG CLC ; CLC=Entering from RESET
|
2021-09-12 03:07:05 +00:00
|
|
|
|
|
|
|
* OSBYTE $8E - Enter language ROM
|
2022-10-19 18:02:01 +00:00
|
|
|
*********************************
|
2022-11-08 15:11:55 +00:00
|
|
|
* X=ROM number to select, CC=RESET, CS=*COMMAND/OSBYTE
|
2021-09-12 03:07:05 +00:00
|
|
|
*
|
2022-10-19 18:02:01 +00:00
|
|
|
BYTE8E PHP ; Save CLC=RESET, SEC=Not RESET
|
2022-11-08 15:11:55 +00:00
|
|
|
JSR ROMSELECT ; Bring ROM X into memory
|
2022-12-14 15:03:55 +00:00
|
|
|
BIT $8006
|
|
|
|
BVC ERRNOLANG ; No language in this ROM
|
2021-09-12 06:05:17 +00:00
|
|
|
LDA #$00
|
|
|
|
STA FAULT+0
|
|
|
|
LDA #$80
|
|
|
|
STA FAULT+1
|
|
|
|
LDY #$09
|
2022-10-19 18:02:01 +00:00
|
|
|
JSR PRERRLP ; Print ROM name with PRERR to set
|
|
|
|
STY FAULT+0 ; FAULT pointing to version string
|
2021-09-12 06:05:17 +00:00
|
|
|
JSR OSNEWL
|
|
|
|
JSR OSNEWL
|
2022-12-14 15:03:55 +00:00
|
|
|
STX FXLANG ; Set as current language ROM
|
2022-10-19 18:02:01 +00:00
|
|
|
PLP ; Get entry type back
|
|
|
|
LDA #$01 ; $01=Entering code with a header
|
2022-10-12 04:00:36 +00:00
|
|
|
JMP ROMAUXADDR
|
2021-09-12 03:07:05 +00:00
|
|
|
|
2022-10-19 18:02:01 +00:00
|
|
|
|
2021-09-12 03:07:05 +00:00
|
|
|
* OSBYTE $8F - Issue service call
|
2022-10-19 18:02:01 +00:00
|
|
|
*********************************
|
2021-09-12 03:07:05 +00:00
|
|
|
* X=service call, Y=parameter
|
|
|
|
*
|
2022-11-07 12:25:54 +00:00
|
|
|
* SERVICE TAX ; Enter here with A=Service Num
|
2022-11-09 18:50:54 +00:00
|
|
|
SERVICEX
|
|
|
|
BYTE8F LDA $F4 ; Enter here with X=Service Number
|
2022-10-19 18:02:01 +00:00
|
|
|
PHA ; Save current ROM
|
|
|
|
*DEBUG
|
|
|
|
LDA $E0
|
|
|
|
AND #$20 ; Test debug *OPT255,32
|
|
|
|
BEQ :SERVDEBUG
|
|
|
|
CPX #$06
|
|
|
|
BEQ :SERVDONE ; If debug on, ignore SERV06
|
|
|
|
:SERVDEBUG
|
|
|
|
*DEBUG
|
2022-11-07 12:25:54 +00:00
|
|
|
TXA ; A=service number
|
2022-11-09 18:50:54 +00:00
|
|
|
LDX ROMMAX ; Start at highest ROM
|
2022-10-19 18:02:01 +00:00
|
|
|
:SERVLP JSR ROMSELECT ; Bring it into memory
|
2021-09-12 06:05:17 +00:00
|
|
|
BIT $8006
|
2022-10-19 18:02:01 +00:00
|
|
|
BPL :SERVSKIP ; No service entry
|
|
|
|
JSR $8003 ; Call service entry
|
2021-09-12 06:05:17 +00:00
|
|
|
TAX
|
|
|
|
BEQ :SERVDONE
|
2022-10-19 18:02:01 +00:00
|
|
|
:SERVSKIP LDX $F4 ; Restore X=current ROM
|
|
|
|
DEX ; Step down to next
|
|
|
|
BPL :SERVLP ; Loop until ROM 0 done
|
|
|
|
:SERVDONE PLA ; Get caller's ROM back
|
|
|
|
PHX ; Save return from service call
|
2021-10-23 18:41:47 +00:00
|
|
|
TAX
|
2022-10-19 18:02:01 +00:00
|
|
|
JSR ROMSELECT ; Restore caller's ROM
|
|
|
|
PLX ; Get return value back
|
|
|
|
TXA ; Return in A and X and set EQ/NE
|
2021-10-23 18:41:47 +00:00
|
|
|
RTS
|
2021-09-12 03:07:05 +00:00
|
|
|
|
2022-10-19 18:02:01 +00:00
|
|
|
PRHELLO LDX #<HELLO
|
2021-08-26 21:36:46 +00:00
|
|
|
LDY #>HELLO
|
2022-10-19 18:02:01 +00:00
|
|
|
JSR OSPRSTR
|
2021-08-26 21:36:46 +00:00
|
|
|
JMP OSNEWL
|
|
|
|
|
2022-11-08 15:11:55 +00:00
|
|
|
BYTE00 BEQ BYTE00A ; OSBYTE 0,0 - generate error
|
|
|
|
LDX #$0A ; Identify Host
|
|
|
|
RTS ; %000x1xxx host type, 'A'pple
|
2021-08-26 21:36:46 +00:00
|
|
|
BYTE00A BRK
|
|
|
|
DB $F7
|
2023-01-10 21:45:18 +00:00
|
|
|
HELLO ASC 'Applecorn MOS 2022-01-10'
|
2022-11-08 15:11:55 +00:00
|
|
|
DB $00 ; Unify MOS messages
|