A2osX/SYS/KERNEL.S.GP.txt

624 lines
13 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-25 19:24:07 +00:00
AUTO 3,1
2016-06-07 06:10:18 +00:00
*--------------------------------------
2016-09-26 16:00:52 +00:00
* SYSCALL (AUXLC to AUXLC)
* Used by user & kernel for inter bank Calls
2016-06-07 06:10:18 +00:00
* In:
* X = SYSfnc.Index
* Y,A = free for Inline param
*--------------------------------------
GP.CodeStart jmp GP.SysCall
2016-06-07 06:10:18 +00:00
*--------------------------------------
* LIBCALL (AUXLC to AUXLC)
2016-09-26 16:00:52 +00:00
* Used by user
2016-06-07 06:10:18 +00:00
* In:
* Y = LIB.ID
* X = LIBfnc.Index
* A = free for Inline param
*--------------------------------------
2017-10-27 14:56:46 +00:00
jmp GP.LibCall
2016-06-07 06:10:18 +00:00
*--------------------------------------
* AppleTalk MLICALL (AUXLC to MAINLC)
* Used by user
2016-06-07 06:10:18 +00:00
* In:
* Y,A = Params
2016-06-07 06:10:18 +00:00
*--------------------------------------
jmp GP.AtkCall
*--------------------------------------
2018-06-14 15:31:36 +00:00
* ROMCALL (AUXLC to ROMLC)
* Used by Kernel
* In:
2018-06-14 15:31:36 +00:00
* X = ROM Function
* Y,A = Param
*--------------------------------------
2019-07-07 20:48:57 +00:00
jmp GP.FpuCall
*--------------------------------------
* BADCALL
*--------------------------------------
lda #MLI.E.BADCALL
sec
rts
*--------------------------------------
* SLEEP
*--------------------------------------
2019-02-19 14:51:33 +00:00
GP.Sleep php
sei
phy
ldy #S.PS.A
sta (pPs),y
2019-10-03 06:25:27 +00:00
txa
iny #S.PS.X
sta (pPs),y
2019-10-03 06:25:27 +00:00
pla
2019-05-04 21:13:50 +00:00
iny #S.PS.Y
sta (pPs),y
2019-10-03 06:25:27 +00:00
pla
iny #S.PS.P
sta (pPs),y
pla get PC LO
plx get PC HI
2019-10-03 06:25:27 +00:00
inc Advance one byte because of return by RTI
2019-05-04 21:13:50 +00:00
bne GP.Sleep2
inx
2019-10-03 06:25:27 +00:00
2019-05-04 21:13:50 +00:00
GP.Sleep2 ldy #S.PS.PC
sta (pPs),y
txa
iny #S.PS.PC+1
sta (pPs),y
tsx
2019-10-03 06:25:27 +00:00
inx
beq *
2019-01-04 13:17:31 +00:00
inx keep PC HI,LO from KERNEL jsr PSExec/PSResume
inx Stack Ptr is $1ff if empty
2019-10-03 06:25:27 +00:00
txa
2019-01-04 13:17:31 +00:00
beq .3
tay Save !Byte count for later
2019-10-03 06:25:27 +00:00
.2 pla
>PUSHA
inx
bne .2
2019-10-03 06:25:27 +00:00
tya
2019-01-04 13:17:31 +00:00
.3 >PUSHA push CPU Stack BC to restore on top of Soft Stack
2019-01-04 13:17:31 +00:00
inc $1fe PC=PC+1
bne .4
inc $1ff because of RTI
.4 lda (pPs)
ora #S.PS.F.SLEEP
sta (pPs)
lda #0 cld,clc,cli
pha
rti exit to kernel with CC
2016-06-07 06:10:18 +00:00
*--------------------------------------
2016-09-26 16:00:52 +00:00
* *** MUST BE REINTRANT ***
*--------------------------------------
GP.SysCall dec IRQ.InKernel
2016-09-26 16:00:52 +00:00
2019-05-04 21:13:50 +00:00
pha
phy
ldy #S.PS.A
sta (pPs),y
txa
iny #S.PS.X
sta (pPs),y
pla
iny #S.PS.Y
sta (pPs),y
tay
pla
2019-05-12 20:45:11 +00:00
jsr K.SYSCALL2
2019-05-04 21:13:50 +00:00
bcc .2 no error quit...
2019-02-19 14:51:33 +00:00
tax CS,A=0 ?
2019-05-04 21:13:50 +00:00
beq .3 Yes, BLOCKING I/O
2019-05-04 21:13:50 +00:00
.2 inc IRQ.InKernel
rts Unmodified Carry
2019-10-03 06:25:27 +00:00
.3 sei
pla get PC LO
plx get PC HI
2019-05-04 21:13:50 +00:00
* sec
sbc #2 move back JSR GP.SysCall -3 (jsr $BF00) +1 (RTI)
bcs .4
2019-02-19 14:51:33 +00:00
dex
2019-05-04 21:13:50 +00:00
.4 inc IRQ.InKernel
bra GP.Sleep2
2016-09-26 16:00:52 +00:00
*--------------------------------------
2019-03-27 17:01:01 +00:00
GP.LibCall dec IRQ.InLib
2018-06-21 15:12:10 +00:00
pha No need to save X, K.GetMemPtr will leave it unmodified
2016-09-26 16:00:52 +00:00
tya Get LIB hMem in A
2019-01-04 13:17:31 +00:00
jsr K.GetMemPtr Get LIB Code Segment (MemMgr in $E000, no BNK change)
>STYA .1+1
2016-06-07 06:10:18 +00:00
pla
2019-01-04 13:17:31 +00:00
.1 jsr $FFFF SELF MODIFIED
2019-03-27 17:01:01 +00:00
GP.LibCall.8 inc IRQ.InLib
2019-05-04 21:13:50 +00:00
GP.LibCall.RTS rts
2016-06-07 06:10:18 +00:00
*--------------------------------------
GP.AtkCall dec IRQ.InKernel
2019-05-04 21:13:50 +00:00
>STYA .1
jsr GO.ProDOS
jsr MLI
.DA #MLIATALK
.1 .DA *
jsr GO.A2osX
2019-08-01 14:59:15 +00:00
GP.AtkCall.INC inc IRQ.InKernel
2019-03-27 17:01:01 +00:00
rts
2019-08-01 14:59:15 +00:00
*/--------------------------------------
* # Add32,Sub32,Mul32,IMul32,Div32,IDiv32,Mod32,IMod32,Cmp32,ICmp32
* Return X+Y, X-Y, X*Y, X/Y, X mod Y....
* ## ASM
* **In:**
* `>PUSHF X (long)`
* `>PUSHF Y (long)`
* `>FPU add32`
* `...`
* ## RETURN VALUE
* On stack (long)
*\--------------------------------------
2019-07-28 20:39:30 +00:00
GP.FpuCall dec IRQ.InKernel
jsr .1
2019-08-01 14:59:15 +00:00
bra GP.AtkCall.INC
.1 cpx #FPU.FADD
bcc GP.RomCall.JmpX INT32, direct JMP
2019-07-28 20:39:30 +00:00
phx
jsr GP.SetFAC Get float from stack
plx
cpx #FPU.PWR+1
2019-08-01 14:59:15 +00:00
bcs GP.RomCallGetFacOnStack
2019-07-26 14:23:07 +00:00
*/--------------------------------------
* # FAdd,FSub,FMult,FDiv,FPwr
* Return X+Y, X-Y, X*Y, X/Y, X^Y
* ## ASM
* **In:**
* `>PUSHF X (float)`
* `>PUSHF Y (float)`
* `>FPU fadd`
* `>FPU fsub`
* `>FPU fmult`
* `>FPU fdiv`
* `>FPU fpwr`
* ## RETURN VALUE
* On stack (float)
*\--------------------------------------
2019-07-28 20:39:30 +00:00
lda pStack
clc
adc #5
sta pStack
phx
jsr GP.SetARG
plx
2019-07-26 14:23:07 +00:00
*/--------------------------------------
* # Log,Sqr,Exp,Cos,Sin,Tan,ATan
* Return Log(x), Sqr(x), E^X, Cos(x), Sin(X), Tan(x), ATan(x)
* ## C
* `float log ( float x);`
* `float sqr ( float x);`
* `float exp ( float x);`
* `float cos ( float x);`
* `float sin ( float x);`
* `float tan ( float x);`
* `float atan ( float x);`
* ## ASM
* **In:**
* `>PUSHF x (Float)`
* `>FPU log`
* ## RETURN VALUE
* On stack (Float)
*\--------------------------------------
2019-08-01 14:59:15 +00:00
GP.RomCallGetFacOnStack
jsr GP.ROMCALL
2019-07-28 20:39:30 +00:00
lda pStack
ldy pStack+1
sta FORPNT Ptr to dst buffer
sty FORPNT+1
ldx #FPU.GETFAC
*--------------------------------------
GP.RomCall phx
ldx $D000
stx .8+1
bit RROMBNK1
plx
jsr GP.RomCall.JmpX
.8 ldx #$ff
bit $C000,x
bit $C000,x
rts
2019-07-26 14:23:07 +00:00
*--------------------------------------
2019-08-01 14:59:15 +00:00
GP.SetARG ldx #FPU.SETARG
.HS 2C BIT ABS
GP.SetFAC ldx #FPU.SETFAC
2019-09-02 15:34:10 +00:00
lda pStack
ldy pStack+1
2019-08-01 14:59:15 +00:00
bra GP.RomCall
*/--------------------------------------
* # float
* Return 'floated' long
* ## C
* `float f = (float)l;
* ## ASM
* **In:**
* `>PUSHL l` (long)
* `>FPU float`
* ## RETURN VALUE
* On stack (float)
*\--------------------------------------
GP.Float ldy #3
.1 lda (pStack),y
sta FAC+1,y Reverse Order
dey
bpl .1
dec pStack keep 5 bytes on stack
stz FAC.SIGN
lda #$80+32
sta FAC Positive + Exp=32
ldx #FPU.LTOF
bra GP.RomCallGetFacOnStack
*/--------------------------------------
* # lrintf
* Return float rounded into a long
* ## C
* `long int lrintf (float x);`
* ## ASM
* **In:**
* `>PUSHF x`
* `>FPU lrintf`
* ## RETURN VALUE
* On stack (long)
*\--------------------------------------
GP.lrintf jsr GP.SetFAC
inc pStack keep 4 bytes on stack
ldx #FPU.QINT
jsr GP.ROMCALL
ldy #3
.1 lda FAC+1,y
sta (pStack),y
dey
bpl .1
rts
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.RomCall.JmpX jmp (.1,x)
.1 .DA GP.ADD32
.DA GP.SUB32
.DA GP.UMUL32
.DA GP.IMUL32
.DA GP.UDIV32
.DA GP.IDIV32
.DA GP.UMOD32
.DA GP.IMOD32
2019-08-01 14:59:15 +00:00
.DA GP.UCMP32
.DA GP.ICMP32
2019-07-28 20:39:30 +00:00
* http://www.txbobsc.com/scsc/scdocumentor/E7A0.html
.DA $E7C1 FADDT
.DA $E7AA FSUBT
.DA $E987 FMULTT.1
.DA $EA6B FDIVT+2
.DA $EE97 FPWRT
.DA $E941 LOG
.DA $EE8D SQR
.DA $EF09 EXP
.DA $EFEA COS
.DA $EFF1 SIN
.DA $F03A TAN
.DA $F09E ATN
2019-08-01 14:59:15 +00:00
*--------------------------------------
2019-07-28 20:39:30 +00:00
.DA $E9E3 LOAD.ARG.FROM.YA
.DA $EAF9 LOAD.FAC.FROM.YA
.DA $EB27 SETFOR (GETFAC)
2019-08-01 14:59:15 +00:00
.DA $EBB2 FCOMP (Y,A with FAC)
2019-07-28 20:39:30 +00:00
.DA $E82E NORMALIZE.FAC.2 (L->F)
.DA $EBF2 QINT (F->L)
.DA $EC4A FIN AToF
.DA $ED36 FOUT.1 PrintF
*--------------------------------------
GP.ADD32 clc
2019-07-26 14:23:07 +00:00
.HS B0 BCS
2019-07-28 20:39:30 +00:00
GP.SUB32 sec
2019-07-26 14:23:07 +00:00
php
2019-07-28 20:39:30 +00:00
jsr GP.PopACC32
2019-07-26 14:23:07 +00:00
ldy #0
ldx #3
plp
2019-08-01 14:59:15 +00:00
bcs .1
2019-11-27 22:04:55 +00:00
2019-08-01 14:59:15 +00:00
lda #$79 ADC Absolute,Y
.HS 2C BIT ABS
.1 lda #$F9 SBC Absolute,Y
sta .3
2019-11-27 22:04:55 +00:00
2019-07-26 14:23:07 +00:00
.2 lda (pStack),y
2019-08-01 14:59:15 +00:00
.3 adc ACC32,y SELF MODIFIED
2019-07-26 14:23:07 +00:00
sta (pStack),y
iny
dex
bpl .2
2019-07-28 20:39:30 +00:00
GP.SUB32.RTS rts
2019-07-26 14:23:07 +00:00
*--------------------------------------
2019-08-01 14:59:15 +00:00
* Returns:
* ff X < Y
* 0 X = Y
* 1 X > Y
*--------------------------------------
GP.UCMP32
GP.ICMP32 jsr GP.SUB32
jsr GP.PopACC32 A = ACC32+3 (sign)
tay
bmi .2
.1 ora ACC32+2
ora ACC32+1
ora ACC32
beq .8
lda #1
rts
.2 lda #$ff
.8 rts
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.UMUL32 clc
2019-07-26 14:23:07 +00:00
.HS B0 BCS
2019-07-28 20:39:30 +00:00
GP.IMUL32 sec
2019-07-26 14:23:07 +00:00
php
2019-07-28 20:39:30 +00:00
jsr GP.MULDIVMOD.COMMON
2019-07-26 14:23:07 +00:00
jsr MATH.MUL32
plp
2019-07-28 20:39:30 +00:00
bcc GP.SUB32.RTS
GP.RETURN.ITMP
2019-07-26 14:23:07 +00:00
lda ACC32.Sign
eor ARG32.Sign
2019-07-28 20:39:30 +00:00
bpl GP.PutTMP32
bra GP.PutNotTMP32
2019-07-26 14:23:07 +00:00
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.UDIV32 clc
2019-07-26 14:23:07 +00:00
.HS B0 BCS
2019-07-28 20:39:30 +00:00
GP.IDIV32 sec
2019-07-26 14:23:07 +00:00
clv
2019-07-28 20:39:30 +00:00
bra GP.DIVMOD
GP.UMOD32 clc
2019-07-26 14:23:07 +00:00
.HS B0 BCS
2019-07-28 20:39:30 +00:00
GP.IMOD32 sec
bit GP.SUB32.RTS $60
2019-07-26 14:23:07 +00:00
2019-07-28 20:39:30 +00:00
GP.DIVMOD php
jsr GP.MULDIVMOD.COMMON
2019-07-26 14:23:07 +00:00
jsr MATH.DIVMOD32
plp
2019-08-02 20:55:43 +00:00
bcc .3 unsigned
2019-07-28 20:39:30 +00:00
bvs GP.RETURN.ITMP IMOD
2019-07-26 14:23:07 +00:00
lda ACC32.Sign IDIV
eor ARG32.Sign
2019-08-02 20:55:43 +00:00
bpl GP.PutARG32
2019-07-28 20:39:30 +00:00
bra GP.PutNotARG32
2019-07-26 14:23:07 +00:00
2019-07-28 20:39:30 +00:00
.3 bvs GP.PutARG32 DIV
2019-07-26 14:23:07 +00:00
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.PutTMP32 lda #TMP32 MOD
2019-07-26 14:23:07 +00:00
.HS 2C BIT ABS
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.PutARG32 lda #ARG32
2019-07-26 14:23:07 +00:00
sta .1+1
ldy #3
.1 lda $ff,y SELF MODIFIED
sta (pStack),y
dey
bpl .1
rts
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.PutNotTMP32 lda #TMP32
2019-07-26 14:23:07 +00:00
.HS 2C BIT ABS
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.PutNotARG32 lda #ARG32
2019-07-26 14:23:07 +00:00
sta .1+1
ldy #0
ldx #3
sec
.1 lda $ff,y SELF MODIFIED
eor #$ff two's complement of X bytes
adc #0
sta (pStack),y
iny
dex
bpl .1
rts
*--------------------------------------
2019-08-01 14:59:15 +00:00
GP.PopACC32 ldy #0
2019-07-26 14:23:07 +00:00
2019-08-01 14:59:15 +00:00
.1 lda (pStack)
inc pStack
2019-07-26 14:23:07 +00:00
sta ACC32,y
2019-08-01 14:59:15 +00:00
iny
cpy #4
2019-07-26 14:23:07 +00:00
bne .1
sta ACC32.Sign
rts
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.GetARG32 ldy #0
2019-07-26 14:23:07 +00:00
.1 lda (pStack),y
sta ARG32,y
iny
cpy #4
bne .1
sta ARG32.Sign
2019-08-01 14:59:15 +00:00
GP.GetARG32.RTS rts
2019-07-26 14:23:07 +00:00
*--------------------------------------
2019-07-28 20:39:30 +00:00
GP.MULDIVMOD.COMMON
2019-07-26 14:23:07 +00:00
php
2019-07-28 20:39:30 +00:00
jsr GP.PopACC32
jsr GP.GetARG32
2019-07-26 14:23:07 +00:00
plp
2019-08-01 14:59:15 +00:00
bcc GP.GetARG32.RTS
2019-07-26 14:23:07 +00:00
jsr MATH.ACC32ABS
2019-08-01 14:59:15 +00:00
jmp MATH.ARG32ABS
*--------------------------------------
* MLI : From Kernel Aux LC to Main LC
2019-07-26 14:23:07 +00:00
*--------------------------------------
GP.MLICall stx .1
sta K.MLI.PARAMS
jsr GO.ProDOS
jsr MLI
.1 .BS 1
.DA K.MLI.PARAMS
jsr GO.A2osX
rts
*--------------------------------------
GO.ProDOS pha
lda $D000 We re coming from AUXLC, saving bank...
2016-09-26 16:00:52 +00:00
sta GO.A2osX.BNK+1
pla
php
2016-06-07 06:10:18 +00:00
clc
.HS 2C bit abs
2016-09-26 16:00:52 +00:00
GO.A2osX php
2016-06-07 06:10:18 +00:00
sec
sei
sta GO.EXIT.SaveA+1
stx GO.EXIT.SaveX+1
sty GO.EXIT.SaveY+1
pla Restore P in A for later
plx Get PC and add 1 for return
2016-06-07 06:10:18 +00:00
ply
inx
bne .1
iny
.1 stx GO.EXIT.JMP+1
sty GO.EXIT.JMP+2
2016-09-26 16:00:52 +00:00
bcs GO.A2osX.BNK if CS, go AUXLC
bit RRAMWRAMBNK1 Go MAINLC (ProDOS), always BNK1
bit RRAMWRAMBNK1
tsx
2016-06-07 06:10:18 +00:00
stx A2osX.SaveSX
ldx A2osX.SaveSM
txs
sta CLRALTZP
2016-06-07 06:10:18 +00:00
bra GO.EXIT
GO.A2osX.BNK ldx #RRAMWRAMBNK1 Self Modified, initialized to BNK1 for INIT3
bit $C000,x
bit $C000,x
sta SETALTZP
2016-06-07 06:10:18 +00:00
tsx
stx A2osX.SaveSM
ldx A2osX.SaveSX
txs
*--------------------------------------
GO.EXIT pha push P on stack
GO.EXIT.SaveY ldy #$ff
GO.EXIT.SaveX ldx #$ff
GO.EXIT.SaveA lda #$ff
2016-06-07 06:10:18 +00:00
plp
2018-11-19 07:43:00 +00:00
GO.EXIT.JMP jmp $FFFF SELF MODIFIED
2016-06-07 06:10:18 +00:00
*--------------------------------------
2017-11-23 16:51:52 +00:00
* Called from ProDOS IRQ Manager (LCBNK1)
* A,X,Y, $FA->$FF Already Saved
* Main RAM,ZP/LC selected
* must begin with CLD
* must exit with RTS
* - CC if IRQ cleared, CS if NOT
*--------------------------------------
GP.IrqH cld
bit IRQ.SkipA2osX After A2osX IRQ.H ?
bmi GP.IrqH.Exit
sta SETALTZP switch to aux LC
tsx
stx A2osX.SaveSM
ldx A2osX.SaveSX
txs
GP.IrqH.JSR jsr K.IrqH.DEV SELF MODIFIED
tsx go back to Main
stx A2osX.SaveSX
ldx A2osX.SaveSM
txs
sta CLRALTZP
2019-10-03 06:25:27 +00:00
rts
GP.IrqH.Exit stz IRQ.SkipA2osX reset flag
sec
rts
*--------------------------------------
2019-01-13 13:10:14 +00:00
CORE.VBLState .BS 1
CORE.IRQMode .BS 1
CORE.TickPerSec .BS 1
CORE.TickPer10t .BS 1
CORE.TickSec .BS 1
CORE.Tick10t .BS 1
CORE.CPUStatCnt .DA #100
CORE.LastPSID .DA #0
2019-11-27 22:04:55 +00:00
CORE.FSID .BS 1
2019-01-24 13:53:29 +00:00
*--------------------------------------
IRQ.InKernel .BS 1
2019-03-27 17:01:01 +00:00
IRQ.InLib .BS 1
2019-07-10 15:39:02 +00:00
IRQ.SkipA2osX .BS 1
IRQ.IntNum .BS 1
IRQ.VBL.n0 .BS 1
IRQ.VBL.0n .BS 1
2019-07-10 15:39:02 +00:00
IRQ.Mode .BS 1
IRQ.Tick .BS 1
*--------------------------------------
*GO.Reset jsr GO.A2osX
* jmp CORE.Run
*--------------------------------------
*BrkHandler bra *
*--------------------------------------
GP.CodeEnd .BS $BEE0-*
2017-10-27 14:56:46 +00:00
*--------------------------------------
* $BEE0->$BEEF : Public Variables
*--------------------------------------
.BS 16
*--------------------------------------
* $BEF0->$BEFF : Kernel Config Block
*--------------------------------------
.DA #6 A2osX.HZ=60hz
2019-01-21 21:45:47 +00:00
.DA #2 A2osX.TTYDEVS=2
2018-12-10 16:45:37 +00:00
.HS 000000000000
.DA #0 ChRoot/Preemptive Disabled
.HS 00000000000000 All Slots marked as "Free"
2016-06-07 06:10:18 +00:00
*--------------------------------------
GP.End .EQ *
2016-06-07 06:10:18 +00:00
MAN
2018-11-17 17:17:13 +00:00
SAVE USR/SRC/SYS/KERNEL.S.GP
LOAD USR/SRC/SYS/KERNEL.S
2016-06-07 06:10:18 +00:00
ASM