A2osX/SYS/KERNEL.S.INIT2.txt
2016-09-21 17:20:37 +02:00

489 lines
9.7 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
Kernel.Init2 >LDAXI MSG.Init2
jsr PrintCStrAX
>LDAXI MSG.Relocate
jsr PrintCStrAX
sei
sta SETALTZP
>LDYAI A2osX.BE00
>STYA ZPQuickPtr1
>LDYAI $BE00
>STYA ZPQuickPtr2
>LDYAI A2osX.BE00.SIZE^$FFFF
>STYA ZPQuickPtr3
jsr Kernel.Move
lda RRAMWRAMBNK2
lda RRAMWRAMBNK2
>LDYAI A2osX.D002
>STYA ZPQuickPtr1
>LDYAI $D000
>STYA ZPQuickPtr2
>LDYAI A2osX.D002.SIZE^$FFFF
>STYA ZPQuickPtr3
jsr Kernel.Move
lda RRAMWRAMBNK1
lda RRAMWRAMBNK1
>LDYAI A2osX.D001
>STYA ZPQuickPtr1
>LDYAI $D000
>STYA ZPQuickPtr2
>LDYAI A2osX.D001.SIZE^$FFFF
>STYA ZPQuickPtr3
jsr Kernel.Move
>LDYAI A2osX.E000
>STYA ZPQuickPtr1
>LDYAI $E000
>STYA ZPQuickPtr2
>LDYAI A2osX.E000.SIZE^$FFFF
>STYA ZPQuickPtr3
jsr Kernel.Move
>LDYAI D.STACK.TOP
>STYA pStack init Soft Stack
sta CLRALTZP Make MAIN ZP is enabled for X.PRINT.F
lda RROMBNK1 Make sure ROM is enabled for X.PRINT.F
cli
lda #6
sta A2osX.HZ
pha push HZ
>LDAXI MSG.HZ
jsr PrintCStrAX
jsr CPU.Init
>LDAXI MSG.Setup
jsr PrintCStrAX
jsr GO.AUXLC
jsr K.IrqMgrInit
bcs *
jsr K.MemMgrInit
bcs *
jsr K.DevMgrInit
bcs *
jsr K.EvtMgrInit
bcs *
jsr K.FltMgrInit
bcs *
jsr K.TskMgrInit
bcs *
jsr GO.MAINLC Make sure MAIN ZP...
lda RROMBNK1 ... & ROM is enabled for X.PRINT.F
>LDAXI MSG.Init2.OK
jsr PrintCStrAX
rts
*--------------------------------------
MSG.Init2 >CSTRING "A2osX[Stage2]:Init\n"
MSG.Relocate >CSTRING "Relocating KERNEL...\n"
MSG.HZ >CSTRING "Kernel SYS Timer Set For %d0 hz Machine.\n"
MSG.Setup >CSTRING "Kernel Setup...\n"
MSG.Init2.OK >CSTRING "A2osX[Stage2]:Complete.\n"
*--------------------------------------
CPU.Init >LDAXI MSG.CPU
jsr PrintCStrAX
jsr Detect6502 A = CPU type
sta A2osX.CPUTYPE
lda MSG.CPUTYPEH,y
tax
lda MSG.CPUTYPEL,y
jsr PrintCStrAX
lda MACHID
and #MACHID.TYPE
cmp #MACHID.TYPE.IIc
beq CPU.Init.Z80
>LDAXI MSG.CPU.SPEED
jsr PrintCStrAX
stz A2osX.RANDOM16
stz A2osX.RANDOM16+1
php
sei
.1 bit VBL
bpl .2
.2 bit VBL
bmi .2
ldx #0 Count LO
lda #0 Count HI
.3 ldy #3 (2)
.4 nop (2)
dey (2)
bne .4 (2*)
inc A2osX.RANDOM16 (6)
bne .5 (2*)
inc A2osX.RANDOM16+1 (6)
bit VBL (4)
bpl .3 (2*)
bmi .6
.5 nop (2)
nop (2)
nop (2)
bit VBL (4)
bpl .3 (2*)
.6 plp
stz A2osX.CPUSPEED
.7 sec
lda A2osX.RANDOM16
sbc #100
tax
lda A2osX.RANDOM16+1
sbc /100
bcc .8
stx A2osX.RANDOM16
sta A2osX.RANDOM16+1
inc A2osX.CPUSPEED
bra .7
.8 lda A2osX.RANDOM16
sta A2osX.CPUSPEED+1
pha push CPU speed LO
lda A2osX.CPUSPEED
pha push CPU speed HI
>LDAXI MSG.CPU.SPEEDOK
jsr PrintCStrAX
CPU.Init.Z80 >LDAXI MSG.Z80
jsr PrintCStrAX
jsr DetectZ80
bcs .9
sta A2osX.Z80SLOT
pha Push Z80Slot
>LDAXI MSG.Z80.OK
jsr PrintCStrAX
rts
.9 >LDAXI MSG.Z80.KO
jsr PrintCStrAX
rts
*--------------------------------------
* Out:
* A = $60, 6502
* A = $61, 65C02
* A = $62, R65C02
* A = $63, 65C816
*--------------------------------------
Detect6502 ldy #0 Test 6502 BCD bug
sed
lda #$99
clc
adc #$01
cld
bmi .9 BUG!, we have 6502
ldy #3 test 65C816 TYX Instruction
ldx #0
.OP 65816
tyx TYX: if 65C816, x becomes non-zero
.OP 65C02
bne .9 worked! 65C816
dey y=2 -> R65C02
ldx $EA save zp $EA
stz $EA store 0 in $EA
* .OP 65R02
.HS F7EA For compatibility with A2osX.ASM
* smb 7,$EA if not Rockwell, assemble as nop nop
* .OP 65C02
asl $EA cs if Rockwell
stx $EA restore zp $EA
bcs .9
dey y=1 -> 65C02
.9 tya
ora #$60
rts
*--------------------------------------
* Out:
* A = Z80 Slot
*--------------------------------------
DetectZ80 ldx #Z80Code.Size
.1 lda Z80Code.Start-1,x
sta $1000-1,x 00000H for Z80
dex
bne .1
stz ZPQuickPtr1
lda #$C1
sta ZPQuickPtr1+1
.2 sta (ZPQuickPtr1)
lda $100D
bmi .8
inc ZPQuickPtr1+1
lda ZPQuickPtr1+1
cmp #$C8
beq .9 CS
clc
adc #$20
sta $100A
bra .2
.8 lda ZPQuickPtr1+1
and #$0F
clc
.9 rts
*--------------------------------------
Z80Code.Start .HS 31FFFF START: LD SP,0FFFFH Init Stack
.HS 3EFF LD A,0FFH Set Flag
.HS 320D00 LD (FLAG),A
.HS 3200E1 LD (0E100H),A Back to 6502
.HS 18F3 JR START Loop
.HS 00 FLAG: .DB 0
Z80Code.End .EQ *
Z80Code.Size .EQ Z80Code.End-Z80Code.Start
*--------------------------------------
MSG.CPU >CSTRING "Checking CPU..."
MSG.CPU.SPEED >CSTRING "Detecting CPU Speed..."
MSG.CPUTYPEL .DA #MSG.6502
.DA #MSG.65C02
.DA #MSG.65R02
.DA #MSG.65816
MSG.CPUTYPEH .DA /MSG.6502
.DA /MSG.65C02
.DA /MSG.65R02
.DA /MSG.65816
MSG.6502 >CSTRING "6502.\n"
MSG.65C02 >CSTRING "65C02.\n"
MSG.65R02 >CSTRING "65R02.\n"
MSG.65816 >CSTRING "65816.\n"
MSG.CPU.SPEEDOK >CSTRING "%d.%02d Mhz.\n"
MSG.Z80 >CSTRING "Detecting Z80 CPU..."
MSG.Z80.OK >CSTRING "Detected In Slot %d.\n"
MSG.Z80.KO >CSTRING "Not Detected.\n"
*--------------------------------------
Kernel.Move ldy #0
.1 inc ZPQuickPtr3
bne .2
inc ZPQuickPtr3+1
beq .9
.2 lda (ZPQuickPtr1),y
sta (ZPQuickPtr2),y
iny
bne .1
inc ZPQuickPtr1+1
inc ZPQuickPtr2+1
bne .1
.9 rts
*--------------------------------------
* Setup MainLC ($3FE)
*
*
* Setup AuxLC $FFFE->Kernel IRQ Handler
* if irq not handled, jmp (S.IrqMgrOldFFFE)
*--------------------------------------
K.IrqMgrInit php
sei
>LDYA $FFFE
cpy #K.IrqHandlerAuxLC
bne .1
cmp /K.IrqHandlerAuxLC
beq .2
.1 >STYA K.IrqMgrOldFFFE
>LDYAI K.IrqHandlerAuxLC
>STYA $FFFE
.2
* >LDYAI $BE0C
* >STYA $3F0
plp
clc
rts
*--------------------------------------
K.MemMgrInit >LDYAI MemMgr.MHiMem
>STYA MemMgr.HiMem
>STYA MemMgr.Free
>LDYAI MemMgr.MLoMem
>STYA MemMgr.LoMem
stz MemMgr.LastSlot Reserve Slot #0
sta SETWRITEAUX
>LDYAI MemMgr.XHiMem
>STYA MemMgr.HiMem
>STYA MemMgr.Free
>LDYAI MemMgr.XLoMem
>STYA MemMgr.LoMem
stz MemMgr.LastSlot Reserve Slot #0
sta CLRWRITEAUX
clc
rts
*--------------------------------------
* K.DevMgrInit
*--------------------------------------
K.DevMgrInit ldx #S.DEV.SIZE*DevMgr.Count
.1 lda DevMgr.NUL-1,x
sta DevMgr.Table-1,x
dex
bne .1
stz DevMgr.Table+S.DEV.SIZE*DevMgr.Count+1
lda #DevMgr.Count-1
sta DevMgr.LastDevID
>LDYAI DevMgr.End
>STYA DevMgr.Free
clc
rts
*--------------------------------------
* K.EvtMgrInit
*--------------------------------------
K.EvtMgrInit lda #10
sta EVTMGR.10TH.CNT
lda A2osX.HZ
sta EVTMGR.HZ.CNT
lda MACHID
and #MACHID.TYPE
cmp #MACHID.TYPE.IIc
bne .8
* sta CLRIOUDIS
* sta ENBVBLIIC
.8 lda /EvtMgr.Table
sta pEvent+1
clc
rts
*--------------------------------------
* K.TskMgrInit
*--------------------------------------
K.TskMgrInit stz TSKMGR.LASTID
lda #1
sta TSKMGR.SIZE One Slot Busy (Kernel PS=0)
>LDYAI TskMgr.Table Clear whole process table
>STYA pPs
ldx #K.PS.MAX
.1 lda #0
ldy #S.PS.SIZE-1
.2 sta (pPs),y
dey
bpl .2
lda pPs
clc
adc #S.PS.SIZE
sta pPs
bcc .3
inc pPs+1
.3 dex
bne .1
>LDYAI TskMgr.Table Select Process 0 (Kernel)
>STYA pPs
lda #1
ldy #S.PS.hINDEV
sta (pPs),y Make In DEV = SYS
ldy #S.PS.hOUTDEV
sta (pPs),y Make OUT DEV = SYS
ldy #S.PS.hERRDEV
sta (pPs),y Make ERR DEV = SYS
>SYSCALL SYS.GetDevByIDA
>STYA pDev
ldx #DEVMGR.OPEN
jsr pDevJmp
>PUSHWI K.ENV.SIZE get a buffer for ENV
>PUSHBI S.MEM.F.INIT0 make sure blank
>SYSCALL SYS.GetMem create it...
bcs .9
txa
ldy #S.PS.hENV
sta (pPs),y
>LDYAI TmpBuffer256
>SYSCALL SYS.MLIGetPrefixYA
bcs .9
>LDYAI TmpBuffer256
>SYSCALL SYS.NewPStrYA
bcs .9
txa
ldy #S.PS.hPREFIX
sta (pPs),y
>PUSHWI TmpBuffer256 push ENV value
>PUSHWI I.ENV.A2osX push ENV name
>SYSCALL SYS.SetEnv
bcs .9
>LDYAI I.ENV.PATH
>SYSCALL SYS.PutEnvYA
bcs .9
>LDYAI I.ENV.LIB
>SYSCALL SYS.PutEnvYA
bcs .9
>LDYAI I.ENV.DRV
>SYSCALL SYS.PutEnvYA
.9 rts
*--------------------------------------
K.FltMgrInit stz FltMgr.Table
clc
rts
*--------------------------------------
I.ENV.A2osX >PSTRING "A2OSX"
I.ENV.PATH >PSTRING "PATH=${A2OSX}SBIN/;${A2OSX}BIN/"
I.ENV.LIB >PSTRING "LIB=${A2OSX}LIB/"
I.ENV.DRV >PSTRING "DRV=${A2OSX}DRV/"
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.INIT2
LOAD SYS/KERNEL.S
ASM