A2osX/DRV/SSC.I.DRV.S.txt

376 lines
7.2 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/DRV/SSC.I.DRV
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/MLI.ERR.I
2017-02-04 22:07:06 +00:00
.INB /A2OSX.DEV/INC/COM.6551.I
*--------------------------------------
BUF.SIZE .EQ $40
BUF.MASK .EQ $3F
*--------------------------------------
ZPTmpPtr1 .EQ ZPDRV
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp Dev.Detect cld,jmp abs=DRV
.DA #$61 6502,Level 1 (65c02)
.DA #1 DRV Layout Version 1
.DA 0
.DA CS.END-CS.START Code Length
.DA DEV.HEADER-CS.START Device Header Offset
.DA DRV.CS.START-CS.START Driver Code Offset
.DA DRV.CS.END-DRV.CS.START Drv Code Length
*--------------------------------------
* Relocation Table
*--------------------------------------
L.MSG.DETECT .DA MSG.DETECT
L.MSG.DETECT.OK .DA MSG.DETECT.OK
L.MSG.DETECT.KO .DA MSG.DETECT.KO
L.DEV.HEADER.NAME .DA DEV.HEADER.NAME
.DA 0 End Of Reloc Table
*--------------------------------------
Dev.Detect sta hArgs
>LDYA L.MSG.DETECT
>SYSCALL CPrintFYA
stz ZPTmpPtr1
lda #$C1
sta ZPTmpPtr1+1
.1 ldx #DEVSIG.Length-1
.2 ldy DEVSIG.Offset,x
lda (ZPTmpPtr1),y
cmp DEVSIG.Value,x
bne .3
dex
bpl .2
bra .4
.3 inc ZPTmpPtr1+1 no match, try next slot....
lda ZPTmpPtr1+1
cmp #$C8
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL CPrintFYA
lda #MLI.ERR.NODEV Not Found in any slot, exiting
sec
rts
.4 lda ZPTmpPtr1+1
and #$0F
ora #$30
sta DEV.HEADER.NAME+4
asl
asl
asl
asl
sta DEVSLOTn0
>PUSHW L.DEV.HEADER.NAME
>LDYA L.MSG.DETECT.OK
>SYSCALL CPrintFYA
clc
rts
*--------------------------------------
CS.END
DEVSIG.Offset .HS 05070B0C
DEVSIG.Value .HS 38180131
DEVSIG.Length .EQ DEVSIG.Value-DEVSIG.Offset
MSG.DETECT >CSTR "Apple SSC (Super Serial Card,//c Serial Port) Driver (IRQ Enabled).\r\n"
MSG.DETECT.OK >CSTR "SSC Installed As Device : %S\r\n"
MSG.DETECT.KO >CSTR "No SSC Found.\r\n"
hArgs .BS 1
*--------------------------------------
* Device Header (16 Bytes)
*--------------------------------------
DEV.HEADER .DA DRV.CS.START
.DA #S.DEV.S.WRITE+S.DEV.S.READ+S.DEV.S.IRQ
DEV.HEADER.NAME >PSTR "COM1" NAME
*--------------------------------------
* Driver Code
*--------------------------------------
DRV.CS.START cld
jmp (.1,x)
.1 .DA STATUS
.DA BADCALL
.DA BADCALL
.DA BADCALL
.DA CONTROL
.DA BADCALL
.DA OPEN
.DA CLOSE
.DA READ
.DA WRITE
.DA IRQ
L.STAT .DA STAT
.DA 0 end or relocation
*--------------------------------------
BADCALL lda #MLI.ERR.BADCALL
sec
rts
*--------------------------------------
STATUS >LDYA L.STAT
clc
rts
*--------------------------------------
CONTROL clc
rts
*--------------------------------------
OPEN php
sei
ldx DEVSLOTn0
stz SSC.RESET,x
stz INBUF.HEAD
stz INBUF.TAIL
stz OUTBUF.HEAD
stz OUTBUF.TAIL
lda #SSC.CTL.CLKINT+SSC.CTL.B9600
sta SSC.CTL,x
lda #SSC.CMD.TEIRQ+SSC.CMD.TE+SSC.CMD.DTR
sta SSC.CMD,x
lda SSC.DATA,x discard any garbage byte
lda SSC.STATUS,x clear any IRQ pending
2016-01-04 07:22:57 +00:00
plp
clc
rts
*--------------------------------------
CLOSE php
sei
ldx DEVSLOTn0
stz SSC.RESET,x
plp
clc
rts
*--------------------------------------
READ php
sei
ldx INBUF.TAIL
cpx INBUF.HEAD
beq .9
lda INBUF,x
* jsr READ.DEBUG
inx
cpx #BUF.SIZE
bne .1
ldx #0
.1 stx INBUF.TAIL
plp
clc
rts
.9 plp
lda #0
sec
rts
*--------------------------------------
READ.DEBUG phx
phy
pha
lda #2
>SYSCALL GetDevByIDA
>STYA ZPTmpPtr1
lda (ZPTmpPtr1)
sta READ.DEBUG.JMP+1
ldy #1
lda (ZPTmpPtr1),y
sta READ.DEBUG.JMP+2
lda #'('
ldx #DEVMGR.WRITE
jsr READ.DEBUG.JMP
pla
pha
lsr
lsr
lsr
lsr
tax
lda READ.DEBUG.CHAR,x
ldx #DEVMGR.WRITE
jsr READ.DEBUG.JMP
pla
pha
and #$0F
tax
lda READ.DEBUG.CHAR,x
ldx #DEVMGR.WRITE
jsr READ.DEBUG.JMP
lda #')'
ldx #DEVMGR.WRITE
jsr READ.DEBUG.JMP
pla
ply
plx
rts
READ.DEBUG.JMP jmp $ffff
READ.DEBUG.CHAR .AS "0123456789ABCDEF"
*--------------------------------------
WRITE php
sei
tay save char in Y
ldx DEVSLOTn0
* lda SSC.STATUS,x
* bit #SSC.STATUS.DCD+SSC.STATUS.DSR true when 0
* bne .9
lda OUTBUF.HEAD
cmp OUTBUF.TAIL Buffer Empty?
bne .11 not empty, queue char
lda SSC.STATUS,x
and #SSC.STATUS.TDRE Register Empty ?
beq .10 not empty, queue char
tya yes, write directly to ACIA
sta SSC.DATA,x
plp
clc
rts
.10 lda OUTBUF.HEAD
.11 tax
inc
and #BUF.MASK
cmp OUTBUF.TAIL
beq .9 Buffer Full!!
sta OUTBUF.TAIL
tya
sta OUTBUF,x
2016-01-04 07:22:57 +00:00
* ldx DEVSLOTn0
* lda #SSC.CMD.TEIRQ+SSC.CMD.DTR
* sta SSC.CMD,x
plp
clc
rts
.9 plp
sec
rts
*--------------------------------------
* IRQ Handler
* on exit, CC if handled
*--------------------------------------
IRQ stz .8+1
.1 ldx DEVSLOTn0
lda SSC.STATUS,x
* bpl .9 IRQ from this device ? no, exit !!!!Applewin bug #308!!!!
bit #SSC.STATUS.RDRF incoming char?
beq .4
*------------ IRQ In
ldy SSC.DATA,x read data to clear IRQ
ldx INBUF.HEAD
txa
inc
and #BUF.MASK
cmp INBUF.TAIL
beq .8 buffer full, discard and exit
sta INBUF.HEAD
tya
sta INBUF,x
2016-01-04 07:22:57 +00:00
lda #$ff
sta .8+1
bra .1
*------------ IRQ Out
.3 ldx DEVSLOTn0
lda SSC.STATUS,x
.4 bit #SSC.STATUS.TDRE
beq .8 no transmition possible....
ldy OUTBUF.TAIL something to transmit ?
cpy OUTBUF.HEAD
beq .8
lda OUTBUF,y
sta SSC.DATA,x
iny
cpy #BUF.SIZE
bne .5
ldy #0
.5 sty OUTBUF.TAIL
lda #$ff
sta .8+1
bra .3
.8 lda #$ff did we finally handle and IRQ condtion ?
beq .9
clc
rts
.9 sec
rts
*--------------------------------------
DRV.CS.END
DEVSLOTn0 .BS 1
INBUF.TAIL .BS 1
INBUF.HEAD .BS 1
OUTBUF.TAIL .BS 1
OUTBUF.HEAD .BS 1
INBUF .BS BUF.SIZE
OUTBUF .BS BUF.SIZE
*--------------------------------------
STAT .DA #S.DEVSTAT.S.WRITE+S.DEVSTAT.S.READ+S.DEV.S.IRQ
.DA #0,#0,#0
>PSTR "Serial Card/Port"
.DA #S.DEVSTAT.TYPE.CHAR
.DA #0
.DA $0900
*--------------------------------------
MAN
SAVE DRV/SSC.DRV.I.S
ASM