2021-08-08 02:48:24 +00:00
|
|
|
*********************************************************
|
|
|
|
* AppleMOS Kernel
|
|
|
|
*********************************************************
|
|
|
|
|
2021-08-10 01:27:44 +00:00
|
|
|
* KERNEL/SWROM.S
|
|
|
|
****************
|
|
|
|
|
|
|
|
* OSBYTE $8E - Enter language ROM
|
|
|
|
*
|
|
|
|
BYTE8E PHP ; Save CLC=RESET, SEC=Not RESET
|
|
|
|
LDA #$08
|
|
|
|
STA FAULT+0
|
|
|
|
LDA #$80
|
|
|
|
STA FAULT+1
|
|
|
|
JSR PRERR ; Print ROM name with PRERR to set FAULT
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR OSNEWL
|
|
|
|
JSR OSNEWL
|
2021-08-10 01:27:44 +00:00
|
|
|
PLP ; Get entry type back
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA #$01
|
|
|
|
JMP AUXADDR
|
2021-08-10 01:27:44 +00:00
|
|
|
|
|
|
|
* OSBYTE $8F - Issue service call
|
|
|
|
* X=service call, Y=parameter
|
|
|
|
*
|
|
|
|
BYTE8F TXA
|
|
|
|
SERVICE LDX #$0F
|
|
|
|
BIT $8006
|
|
|
|
BPL :SERVSKIP ; No service entry
|
|
|
|
JSR $8003 ; Call service entry
|
|
|
|
TAX
|
|
|
|
BEQ :SERVDONE
|
|
|
|
:SERVSKIP LDX #$FF
|
|
|
|
:SERVDONE RTS
|
|
|
|
|
|
|
|
|
|
|
|
* KERNEL/OSCLI.S
|
|
|
|
****************
|
2021-08-08 02:48:24 +00:00
|
|
|
|
|
|
|
* OSCLI HANDLER
|
|
|
|
* On entry, XY=>command string
|
2021-08-10 01:27:44 +00:00
|
|
|
* TO DO: line pointer in XY should be in LPTR
|
|
|
|
*
|
2021-08-08 02:48:24 +00:00
|
|
|
CLIHND PHX
|
|
|
|
PHY
|
2021-08-10 01:27:44 +00:00
|
|
|
STX ZP1+0 ; Pointer to CLI
|
2021-08-08 02:48:24 +00:00
|
|
|
STY ZP1+1
|
|
|
|
:L1 LDA (ZP1)
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #'*' ; Trim any leading stars
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :NEXT
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #' ' ; Trim any leading spaces
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :NEXT
|
|
|
|
BRA :TRIMMED
|
|
|
|
:NEXT INC ZP1
|
|
|
|
BNE :L1
|
|
|
|
INC ZP1+1
|
|
|
|
BRA :L1
|
2021-08-10 01:27:44 +00:00
|
|
|
:TRIMMED CMP #'|' ; | is comment
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :IEXIT
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #$0D ; Carriage return
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :IEXIT
|
|
|
|
LDA #<:QUIT
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:QUIT
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S1
|
|
|
|
JSR STARQUIT
|
|
|
|
BRA :IEXIT
|
|
|
|
:S1 LDA #<:CAT
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:CAT
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S2
|
|
|
|
JSR STARCAT
|
|
|
|
BRA :IEXIT
|
|
|
|
:S2 LDA #<:CAT2
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:CAT2
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S3
|
|
|
|
JSR STARCAT
|
|
|
|
BRA :IEXIT
|
|
|
|
:S3 LDA #<:DIR
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:DIR
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S4
|
|
|
|
JSR STARDIR
|
|
|
|
BRA :IEXIT
|
|
|
|
:S4 LDA #<:LOAD
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:LOAD
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S5
|
|
|
|
JSR STARLOAD
|
|
|
|
BRA :EXIT
|
|
|
|
:S5 LDA #<:SAVE
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:SAVE
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S6
|
|
|
|
JSR STARSAVE
|
|
|
|
:IEXIT BRA :EXIT
|
|
|
|
:S6 LDA #<:RUN
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:RUN
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :S7
|
|
|
|
JSR STARRUN
|
|
|
|
BRA :EXIT
|
|
|
|
:S7 LDA #<:HELP
|
|
|
|
STA ZP2
|
|
|
|
LDA #>:HELP
|
|
|
|
STA ZP2+1
|
|
|
|
JSR STRCMP
|
|
|
|
BCS :ASKROM
|
|
|
|
JSR STARHELP
|
|
|
|
BRA :EXIT
|
2021-08-10 01:27:44 +00:00
|
|
|
:ASKROM LDA $8006 ; Check for service entry
|
|
|
|
BPL :UNSUPP ; No service entry
|
|
|
|
* LDA $8003 ; Check for service entry
|
|
|
|
* CMP #$4C ; Not a JMP?
|
|
|
|
* BNE :UNSUPP ; Only BASIC has no srvc entry
|
|
|
|
LDA ZP1 ; String in (OSLPTR),Y
|
2021-08-08 02:48:24 +00:00
|
|
|
STA OSLPTR
|
|
|
|
LDA ZP1+1
|
|
|
|
STA OSLPTR+1
|
|
|
|
LDY #$00
|
2021-08-10 01:27:44 +00:00
|
|
|
LDA #$04 ; Service 4 Unrecognized Cmd
|
|
|
|
LDX #$0F ; ROM slot
|
|
|
|
JSR $8003 ; Service entry point
|
|
|
|
TAX ; Check return
|
|
|
|
BEQ :EXIT ; Call claimed
|
|
|
|
|
2021-08-08 02:48:24 +00:00
|
|
|
:UNSUPP LDA #<:OSCLIM
|
|
|
|
LDY #>:OSCLIM
|
|
|
|
JSR PRSTR
|
|
|
|
PLY
|
|
|
|
PLX
|
|
|
|
STX ZP3
|
|
|
|
STY ZP3+1
|
|
|
|
LDY #$00
|
|
|
|
:PL1 LDA (ZP3),Y
|
|
|
|
CMP #$0D
|
|
|
|
BEQ :PS1
|
|
|
|
CMP #$00
|
|
|
|
BEQ :PS1
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR OSWRCH
|
2021-08-08 02:48:24 +00:00
|
|
|
INY
|
|
|
|
BRA :PL1
|
|
|
|
:PS1 LDA #<:OSCLIM2
|
|
|
|
LDY #>:OSCLIM2
|
|
|
|
JSR PRSTR
|
|
|
|
RTS
|
|
|
|
:EXIT PLY
|
|
|
|
PLX
|
|
|
|
RTS
|
|
|
|
:QUIT ASC 'QUIT'
|
|
|
|
DB $00
|
|
|
|
:CAT ASC 'CAT'
|
|
|
|
DB $00
|
|
|
|
:CAT2 ASC '.'
|
|
|
|
DB $00
|
|
|
|
:DIR ASC 'DIR'
|
|
|
|
DB $00
|
|
|
|
:LOAD ASC 'LOAD'
|
|
|
|
DB $00
|
|
|
|
:SAVE ASC 'SAVE'
|
|
|
|
DB $00
|
|
|
|
:RUN ASC 'RUN'
|
|
|
|
DB $00
|
|
|
|
:HELP ASC 'HELP'
|
|
|
|
DB $00
|
|
|
|
:OSCLIM ASC 'OSCLI('
|
|
|
|
DB $00
|
|
|
|
:OSCLIM2 ASC ').'
|
|
|
|
DB $00
|
|
|
|
|
|
|
|
* String comparison for OSCLI
|
|
|
|
* Compares str in ZP1 with null-terminated str in ZP2
|
|
|
|
* Clear carry if match, set carry otherwise
|
|
|
|
* Leaves (ZP1),Y pointing to char after verb
|
|
|
|
STRCMP LDY #$00
|
|
|
|
:L1 LDA (ZP2),Y
|
|
|
|
BEQ :PMATCH
|
|
|
|
CMP (ZP1),Y
|
|
|
|
BNE :MISMTCH
|
|
|
|
INY
|
|
|
|
BRA :L1
|
|
|
|
:PMATCH LDA (ZP1),Y
|
|
|
|
CMP #$0D
|
|
|
|
BEQ :MATCH
|
|
|
|
CMP #' '
|
|
|
|
BEQ :MATCH
|
|
|
|
CMP #'"'
|
|
|
|
BEQ :MATCH
|
|
|
|
BRA :MISMTCH
|
|
|
|
:MATCH CLC
|
|
|
|
RTS
|
|
|
|
:MISMTCH SEC
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Print *HELP test
|
|
|
|
STARHELP LDA #<:MSG
|
|
|
|
LDY #>:MSG
|
|
|
|
JSR PRSTR
|
2021-08-10 01:27:44 +00:00
|
|
|
LDA #$09 ; Language name
|
2021-08-08 02:48:24 +00:00
|
|
|
LDY #$80
|
|
|
|
JSR PRSTR
|
|
|
|
LDA #<:MSG2
|
|
|
|
LDY #>:MSG2
|
|
|
|
JSR PRSTR
|
|
|
|
RTS
|
|
|
|
:MSG DB $0D
|
|
|
|
ASC 'Applecorn MOS v0.01'
|
|
|
|
DB $0D,$0D,$00
|
|
|
|
:MSG2 DB $0D,$00
|
|
|
|
|
|
|
|
* Handle *QUIT command
|
|
|
|
STARQUIT >>> XF2MAIN,QUIT
|
|
|
|
|
|
|
|
* Handle *CAT / *. command (list directory)
|
2021-08-10 01:27:44 +00:00
|
|
|
STARCAT JMP FSCCAT
|
2021-08-08 02:48:24 +00:00
|
|
|
|
|
|
|
* Consume spaces in command line. Treat " as space!
|
|
|
|
* Return C set if no space found, C clear otherwise
|
|
|
|
* Command line pointer in (ZP1),Y
|
2021-08-10 01:27:44 +00:00
|
|
|
EATSPC LDA (ZP1),Y ; Check first char is ...
|
|
|
|
CMP #' ' ; ... space
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :START
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #'"' ; Or quote mark
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :START
|
|
|
|
BRA :NOTFND
|
|
|
|
:START INY
|
2021-08-10 01:27:44 +00:00
|
|
|
:L1 LDA (ZP1),Y ; Eat any additional ...
|
|
|
|
CMP #' ' ; ... spaces
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :CONT
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #'"' ; Or quote marks
|
2021-08-08 02:48:24 +00:00
|
|
|
BNE :DONE
|
|
|
|
:CONT INY
|
|
|
|
BRA :L1
|
|
|
|
:DONE CLC
|
|
|
|
RTS
|
|
|
|
:NOTFND SEC
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Consume chars in command line until space or " is found
|
|
|
|
* Command line pointer in (ZP1),Y
|
|
|
|
* Returns with carry set if EOL
|
|
|
|
EATWORD LDA (ZP1),Y
|
|
|
|
CMP #' '
|
|
|
|
BEQ :SPC
|
|
|
|
CMP #'"'
|
|
|
|
BEQ :SPC
|
2021-08-10 01:27:44 +00:00
|
|
|
CMP #$0D ; Carriage return
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :EOL
|
|
|
|
INY
|
|
|
|
BRA EATWORD
|
|
|
|
:SPC CLC
|
|
|
|
RTS
|
|
|
|
:EOL SEC
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Add Y to ZP1 pointer. Clear Y.
|
|
|
|
ADDZP1Y CLC
|
|
|
|
TYA
|
|
|
|
ADC ZP1
|
|
|
|
STA ZP1
|
|
|
|
LDA #$00
|
|
|
|
ADC ZP1+1
|
|
|
|
STA ZP1+1
|
|
|
|
LDY #$00
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Decode ASCII hex digit in A
|
|
|
|
* Returns with carry set if bad char, C clear otherwise
|
|
|
|
HEXDIGIT CMP #'F'+1
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :BADCHAR ; char > 'F'
|
2021-08-08 02:48:24 +00:00
|
|
|
CMP #'A'
|
|
|
|
BCC :S1
|
2021-08-10 01:27:44 +00:00
|
|
|
SEC ; 'A' <= char <= 'F'
|
2021-08-08 02:48:24 +00:00
|
|
|
SBC #'A'-10
|
|
|
|
CLC
|
|
|
|
RTS
|
|
|
|
:S1 CMP #'9'+1
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :BADCHAR ; '9' < char < 'A'
|
2021-08-08 02:48:24 +00:00
|
|
|
CMP #'0'
|
2021-08-10 01:27:44 +00:00
|
|
|
BCC :BADCHAR ; char < '0'
|
|
|
|
SEC ; '0' <= char <= '9'
|
2021-08-08 02:48:24 +00:00
|
|
|
SBC #'0'
|
|
|
|
CLC
|
|
|
|
RTS
|
|
|
|
:BADCHAR SEC
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Decode hex constant on command line
|
|
|
|
* On entry, ZP1 points to command line
|
|
|
|
HEXCONST LDX #$00
|
2021-08-10 01:27:44 +00:00
|
|
|
:L1 STZ :BUF,X ; Clear :BUF
|
2021-08-08 02:48:24 +00:00
|
|
|
INX
|
|
|
|
CPX #$04
|
|
|
|
BNE :L1
|
|
|
|
LDX #$00
|
|
|
|
LDY #$00
|
2021-08-10 01:27:44 +00:00
|
|
|
:L2 LDA (ZP1),Y ; Parse hex digits into
|
|
|
|
JSR HEXDIGIT ; :BUF, left aligned
|
2021-08-08 02:48:24 +00:00
|
|
|
BCS :NOTHEX
|
|
|
|
STA :BUF,X
|
|
|
|
INY
|
|
|
|
INX
|
|
|
|
CPX #$04
|
|
|
|
BNE :L2
|
2021-08-10 01:27:44 +00:00
|
|
|
LDA (ZP1),Y ; Peek at next char
|
|
|
|
:NOTHEX CPX #$00 ; Was it the first digit?
|
|
|
|
BEQ :ERR ; If so, bad hex constant
|
|
|
|
CMP #' ' ; If whitespace, then okay
|
2021-08-08 02:48:24 +00:00
|
|
|
BEQ :OK
|
|
|
|
CMP #$0D
|
|
|
|
BEQ :OK
|
|
|
|
:ERR SEC
|
|
|
|
RTS
|
|
|
|
:OK LDA :BUF-4,X
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ORA :BUF-3,X
|
|
|
|
STA ADDRBUF+1
|
|
|
|
LDA :BUF-2,X
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ASL
|
|
|
|
ORA :BUF-1,X
|
|
|
|
STA ADDRBUF
|
|
|
|
CLC
|
|
|
|
RTS
|
|
|
|
:ZEROPAD DB $00,$00,$00
|
|
|
|
:BUF DB $00,$00,$00,$00
|
|
|
|
|
2021-08-10 01:27:44 +00:00
|
|
|
ADDRBUF DW $0000 ; Used by HEXCONST
|
2021-08-08 02:48:24 +00:00
|
|
|
|
|
|
|
* Handle *LOAD command
|
|
|
|
* On entry, ZP1 points to command line
|
|
|
|
STARLOAD JSR CLRCB
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATSPC ; Eat leading spaces
|
2021-08-08 02:48:24 +00:00
|
|
|
BCS :ERR
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR ADDZP1Y ; Advance ZP1
|
|
|
|
LDA ZP1 ; Pointer to filename
|
2021-08-08 02:48:24 +00:00
|
|
|
STA OSFILECB
|
|
|
|
LDA ZP1+1
|
|
|
|
STA OSFILECB+1
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATWORD ; Advance past filename
|
|
|
|
BCS :NOADDR ; No load address given
|
|
|
|
LDA #$0D ; Carriage return
|
|
|
|
STA (ZP1),Y ; Terminate filename
|
2021-08-08 02:48:24 +00:00
|
|
|
INY
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATSPC ; Eat any whitespace
|
|
|
|
JSR ADDZP1Y ; Update ZP1
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR HEXCONST
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :ERR ; Bad hex constant
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA ADDRBUF
|
2021-08-10 01:27:44 +00:00
|
|
|
STA OSFILECB+2 ; Load address LSB
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA ADDRBUF+1
|
2021-08-10 01:27:44 +00:00
|
|
|
STA OSFILECB+3 ; Load address MSB
|
2021-08-08 02:48:24 +00:00
|
|
|
:OSFILE LDX #<OSFILECB
|
|
|
|
LDY #>OSFILECB
|
2021-08-10 01:27:44 +00:00
|
|
|
LDA #$FF ; OSFILE load flag
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR OSFILE
|
|
|
|
:END RTS
|
2021-08-10 01:27:44 +00:00
|
|
|
:NOADDR LDA #$FF ; Set OSFILECB+6 to non-zero
|
|
|
|
STA OSFILECB+6 ; Means use the file's addr
|
2021-08-08 02:48:24 +00:00
|
|
|
BRA :OSFILE
|
|
|
|
:ERR JSR BEEP
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Handle *SAVE command
|
|
|
|
* On entry, ZP1 points to command line
|
|
|
|
STARSAVE JSR CLRCB
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATSPC ; Eat leading space
|
2021-08-08 02:48:24 +00:00
|
|
|
BCS :ERR
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR ADDZP1Y ; Advance ZP1
|
|
|
|
LDA ZP1 ; Pointer to filename
|
2021-08-08 02:48:24 +00:00
|
|
|
STA OSFILECB
|
|
|
|
LDA ZP1+1
|
|
|
|
STA OSFILECB+1
|
|
|
|
JSR EATWORD
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :ERR ; No start address given
|
|
|
|
LDA #$0D ; Carriage return
|
|
|
|
STA (ZP1),Y ; Terminate filename
|
2021-08-08 02:48:24 +00:00
|
|
|
INY
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATSPC ; Eat any whitespace
|
|
|
|
JSR ADDZP1Y ; Update ZP1
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR HEXCONST
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :ERR ; Bad start address
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA ADDRBUF
|
|
|
|
STA OSFILECB+10
|
|
|
|
LDA ADDRBUF+1
|
|
|
|
STA OSFILECB+11
|
2021-08-10 01:27:44 +00:00
|
|
|
JSR EATSPC ; Eat any whitespace
|
|
|
|
JSR ADDZP1Y ; Update ZP1
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR HEXCONST
|
2021-08-10 01:27:44 +00:00
|
|
|
BCS :ERR ; Bad end address
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA ADDRBUF
|
|
|
|
STA OSFILECB+14
|
|
|
|
LDA ADDRBUF+1
|
|
|
|
STA OSFILECB+15
|
|
|
|
LDX #<OSFILECB
|
|
|
|
LDY #>OSFILECB
|
2021-08-10 01:27:44 +00:00
|
|
|
LDA #$00 ; OSFILE save flag
|
2021-08-08 02:48:24 +00:00
|
|
|
JSR OSFILE
|
|
|
|
:END RTS
|
|
|
|
:ERR JSR BEEP
|
|
|
|
RTS
|
|
|
|
|
|
|
|
* Handle *RUN command
|
|
|
|
* On entry, ZP1 points to command line
|
2021-08-10 01:27:44 +00:00
|
|
|
STARRUN JSR ADDZP1Y
|
|
|
|
LDX ZP1+0
|
|
|
|
LDY ZP1+1
|
2021-08-08 02:48:24 +00:00
|
|
|
LDA #$04
|
2021-08-10 01:27:44 +00:00
|
|
|
CALLFSCV JMP (FSCV) ; Hand on to filing system
|
2021-08-08 02:48:24 +00:00
|
|
|
|
|
|
|
* Clear OSFILE control block to zeros
|
|
|
|
CLRCB LDA #$00
|
|
|
|
LDX #$00
|
|
|
|
:L1 STA OSFILECB,X
|
|
|
|
INX
|
|
|
|
CPX #18
|
|
|
|
BNE :L1
|
|
|
|
RTS
|
|
|
|
|
2021-08-10 01:27:44 +00:00
|
|
|
|
|
|
|
|