A2osX/SYS/KERNEL.S.DEV.txt
2015-03-23 08:28:03 +01:00

227 lines
4.6 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.BUILD
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
*--------------------------------------
* S.DevMgrInit
*--------------------------------------
S.DevMgrInit ldx #S.DEV.SIZE*K.DEV.MAX
.1 stz DEVMGR.TABLE-1,x
dex
bne .1
ldy #5
.2 lda DEVMGR.TABLE.NUL,y
sta DEVMGR.TABLE,y
dey
bpl .2
ldy #5
ldx #S.DEV.SIZE+5
.3 lda DEVMGR.TABLE.KBD,y
sta DEVMGR.TABLE,x
dex
dey
bpl .3
lda #1 reserve #0=NUL, #1=KBD
sta DEVMGR.LASTID
clc
rts
*--------------------------------------
* S.GetDevByIDA
* IN:
* A = DevID
* OUT:
* CC = OK, CS = ERROR
* Y,A = devslot
* X Unmodified
*--------------------------------------
S.GetDevByIDA sta ZPQuickPtr1
lda #K.DEV.MAX
sta ZPQuickPtr1+1
>LDYAI DEVMGR.TABLE
>STYA ZPQuickPtr2
.1 lda (ZPQuickPtr2) get S.DEV.F
bpl .2 In use ?
ldy #S.DEV.ID
lda (ZPQuickPtr2),y
cmp ZPQuickPtr1
beq .8
.2 lda ZPQuickPtr2
clc
adc #S.DEV.SIZE
sta ZPQuickPtr2
bcc .3
inc ZPQuickPtr2+1
.3 dec ZPQuickPtr1+1
bne .1
sec
rts
.8 >LDYA ZPQuickPtr2
clc
rts
*--------------------------------------
* GetDevIDByNameA
* IN:
* A = hPStr
* OUT:
* CC = OK, CS = ERROR
* A = DEVID
* set DEVMGR.DEVPTR to devslot
*--------------------------------------
S.GetDevByNameA jsr S.GetMemPtrA
S.GetDevByNameYA
>STYA ZPQuickPtr1
>LDYAI DEVMGR.TABLE
>STYA DEVMGR.DEVPTR
ldx #K.DEV.MAX
.1 lda (DEVMGR.DEVPTR) get S.DEV.F
bpl .3 empty ?
lda DEVMGR.DEVPTR
clc
adc #S.DEV.NAME
sta ZPQuickPtr2
lda DEVMGR.DEVPTR+1
adc /S.DEV.NAME
sta ZPQuickPtr2+1
lda (ZPQuickPtr1)
cmp (ZPQuickPtr2)
bne .3
tay
.2 lda (ZPQuickPtr1),y
cmp (ZPQuickPtr2),y
bne .3
dey
bne .2
ldy #S.DEV.ID
lda (DEVMGR.DEVPTR),y
clc
rts
.3 lda DEVMGR.DEVPTR
clc
adc #S.DEV.SIZE
sta DEVMGR.DEVPTR
bcc .5
inc DEVMGR.DEVPTR+1
.5 dex
bne .1
lda #DEVMGR.ERRDNF
sec
rts
*--------------------------------------
* S.GetDevTable
* IN :
* OUT CC = OK, CS = ERROR
* Y,A = PTR to dev table
* X = LASTID
*--------------------------------------
S.GetDevTable >LDYAI DEVMGR.TABLE
ldx DEVMGR.LASTID
rts
*--------------------------------------
* S.DevOutA
* IN :
* A = hDev
*--------------------------------------
S.DevOutA ldx #DEVMGR.OUT
jmp S.DevCallFunc
*--------------------------------------
* S.GetDevInfoA
*--------------------------------------
S.GetDevInfoA ldx #DEVMGR.GETINFO
jmp S.DevCallFunc
*--------------------------------------
* PRIVATE
*--------------------------------------
S.DevCallFunc jsr S.GetDevByIDA
bcs .9
>STYA pDevContext
ldy #S.DEV.hCS
lda (pDevContext),y
jsr S.GetMemPtrA X = unmodified
>STYA Kernel.JMP
>LDYA pDevContext
jsr Kernel.DRVCALL Call DRV function
.9 rts
*--------------------------------------
* S.CreateDevSlot
* IN : none
* OUT : A = DevID
* set DEVMGR.DEVPTR to freeslot
*--------------------------------------
S.CreateDevice >LDYAI DEVMGR.TABLE
>STYA DEVMGR.DEVPTR
ldx #K.DEV.MAX
.1 lda (DEVMGR.DEVPTR)
bpl .3
lda DEVMGR.DEVPTR
clc
adc #S.DEV.SIZE
sta DEVMGR.DEVPTR
bcc .2
inc DEVMGR.DEVPTR+1
.2 dex
bne .1
lda #DEVMGR.ERROOS
sec
rts
.3 lda #0
tay
.4 sta (DEVMGR.DEVPTR),y
iny
cpy #S.DEV.SIZE
bne .4
inc DEVMGR.LASTID
lda DEVMGR.LASTID
ldy #S.DEV.ID
sta (DEVMGR.DEVPTR),y
clc
rts
*--------------------------------------
* S.DestroyDevSlot
* selected by (DEVMGR.DEVPTR)
*--------------------------------------
S.DestroyDevice ldy #S.DEV.hCS
lda (DEVMGR.DEVPTR),y
beq .1
jsr S.FreeMemA
.1 ldy #S.DEV.hDS
lda (DEVMGR.DEVPTR),y
beq .2
jsr S.FreeMemA
.2 ldy #S.DEV.hCMD
lda (DEVMGR.DEVPTR),y
beq .3
jsr S.FreeMemA
.3 ldy #S.DEV.hARGS
lda (DEVMGR.DEVPTR),y
beq .4
jsr S.FreeMemA
.4 rts
*--------------------------------------
DEVMGR.TABLE.NUL .DA #S.DEV.F.INUSE+S.DEV.F.CHAR+S.DEV.F.BLOCK
.HS 00 ID
>PSTRING "NUL" NAME
DEVMGR.TABLE.KBD .DA #S.DEV.F.INUSE+S.DEV.F.CHAR
.HS 01 ID
>PSTRING "KBD" NAME
DEVMGR.LASTID .BS 1
*--------------------------------------
MAN
SAVE SYS/KERNEL.S.DEV
LOAD SYS/KERNEL.S
ASM