A2osX/DRV/X.SSC.DRV.S.txt
2018-08-31 17:35:08 +02:00

583 lines
10 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.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.OP 65C02
.OR $2000
*--------------------------------------
.DO SSCIRQ=1
.TF DRV/SSC.I.DRV
.ELSE
.TF DRV/SSC.DRV
.FIN
*--------------------------------------
.DO SSCIRQ=1
BUF.SIZE .EQ $40
BUF.MASK .EQ $3F
.FIN
*--------------------------------------
ZPArgPtr .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 0
.DA 0
.DA 0
*--------------------------------------
* 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.DRV.CS.START .DA DRV.CS.START
L.FD.DEV .DA FD.DEV
L.FD.DEV.NAME .DA FD.DEV.NAME
.DA 0 End Of Reloc Table
*--------------------------------------
Dev.Detect >STYA ARGS
>LDYA L.MSG.DETECT
>SYSCALL puts
stz ZPArgPtr
lda #$C1
sta ZPArgPtr+1
.1 and #$0f
tay
lda A2osX.S,y
bne .3
ldx #DEVSIG.Length-1
.2 ldy DEVSIG.Offset,x
lda (ZPArgPtr),y
cmp DEVSIG.Value,x
bne .3
dex
bpl .2
bra .4
.3 inc FD.DEV.NAME+3
inc ZPArgPtr+1 no match, try next slot....
lda ZPArgPtr+1
cmp #$C8
bne .1
>LDYA L.MSG.DETECT.KO
>SYSCALL puts
lda #MLI.E.NODEV Not Found in any slot, exiting
sec
rts
.4 lda ZPArgPtr+1
and #$0F
pha
tay
lda #A2osX.S.COM
sta A2osX.S,y
pla
asl
asl
asl
asl
clc
adc #$8F
sta DEVSLOTn08F
jsr Dev.ParseArgs
bcs .9
.8 >PUSHW L.FD.DEV.NAME
>PUSHBI 2
>LDYA L.MSG.DETECT.OK
>SYSCALL printf
>PUSHWI DRV.END
>PUSHWI DRV.CS.END
>PUSHWI DRV.CS.START
>LDYA L.DRV.CS.START
>SYSCALL InsDrv
bcs .9
>STYA FD.DEV+S.FD.DEV.DRVPTR
>LDYA L.FD.DEV
>SYSCALL MKDEV
.9 rts
*--------------------------------------
Dev.ParseArgs >LDYA ARGS
>STYA ZPArgPTR
lda (ZPArgPTR)
beq .8
.8 clc
rts
*--------------------------------------
CS.END
DEVSIG.Offset .HS 05070B0C
DEVSIG.Value .HS 38180131
DEVSIG.Length .EQ DEVSIG.Value-DEVSIG.Offset
MSG.DETECT .DO SSCIRQ=1
.AZ "Apple SSC (Super Serial Card,//c Serial Port) Driver (IRQ Enabled)."
.ELSE
.AZ "Apple SSC (Super Serial Card,//c Serial Port) Driver."
.FIN
MSG.DETECT.OK .AZ "SSC Installed As Device : %s\r\n"
MSG.DETECT.KO .AZ "No SSC Found."
ARGS .BS 2
*--------------------------------------
FD.DEV .DA #S.FD.T.CDEV
.DA #0 HANDLER
.DA #0 BUSID
.DA #0 DEVID
.DA 0 BUSPTR
.BS 2 DRVPTR
FD.DEV.NAME .AZ "COM1" NAME
.HS 000000
*--------------------------------------
* Driver Code
*--------------------------------------
ZPIOCTL .EQ ZPDRV
ZPBufPtr .EQ ZPDRV+2
ZPCount .EQ ZPDRV+4
ZPCount2 .EQ ZPDRV+6
*--------------------------------------
DRV.CS.START cld
jmp (.1,x)
.1 .DA STATUS
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA A2osX.BADCALL
.DA CONTROL
.DA A2osX.BADCALL
.DA OPEN
.DA CLOSE
.DA READ
.DA WRITE
.DO SSCIRQ=1
.DA IRQ
.ELSE
.DA A2osX.BADCALL
.FIN
.DA 0 end or relocation
*--------------------------------------
STATUS >STYA ZPIOCTL
ldy #S.IOCTL.STATCODE
lda (ZPIOCTL),y
beq .1
cmp #S.IOCTL.STATCODE.GETDIB
bne STATUS.DCB
ldx #S.DIB-1
.HS 2C bit abs
.1 ldx #3
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
.2 lda DIB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.DCB cmp #S.IOCTL.STATCODE.GETDCB
bne STATUS.9
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .3+1
iny
lda (ZPIOCTL),y
sta .3+2
ldx #S.DCB.COM-1
.2 lda DCB,x
.3 sta $ffff,x SELF MODIFIED
dex
bpl .2
clc
rts
STATUS.9 lda #MLI.E.BADCTL
sec
rts
*--------------------------------------
CONTROL >STYA ZPIOCTL
ldy #S.IOCTL.CTRLCODE
lda (ZPIOCTL),y
cmp #S.IOCTL.CTRLCODE.SETDCB
bne STATUS.9
.1 ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta .2+1
iny
lda (ZPIOCTL),y
sta .2+2
ldx #S.DCB.COM-1
.2 lda $ffff,x SELF MODIFIED
sta DCB,x
dex
bpl .2
*--------------------------------------
OPEN php
sei
ldx DEVSLOTn08F
stz SSC.RESET-$8F,x
lda #SSC.CTL.CLKINT+SSC.CTL.B9600+SSC.CTL.8D+SSC.CTL.1S+SSC.CMD.NOP
sta SSC.CTL-$8F,x
.DO SSCIRQ=1
lda #SSC.CMD.TEIRQ+SSC.CMD.TE+SSC.CMD.DTR
sta SSC.CMD-$8F,x
stz INBUF.HEAD
stz INBUF.TAIL
stz OUTBUF.HEAD
stz OUTBUF.TAIL
.ELSE
lda #SSC.CMD.RIRQDIS+SSC.CMD.TE+SSC.CMD.DTR
sta SSC.CMD-$8F,x
.FIN
lda SSC.DATA-$8F,x discard any garbage byte
lda SSC.STATUS-$8F,x clear any IRQ pending
plp
clc
rts
*--------------------------------------
CLOSE php
sei
ldx DEVSLOTn08F
stz SSC.RESET-$8F,x
plp
clc
rts
*--------------------------------------
READ >STYA ZPIOCTL
php
sei
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta ZPBufPtr
iny
lda (ZPIOCTL),y
sta ZPBufPtr+1
* ldy #S.IOCTL.BYTECNT
iny
lda (ZPIOCTL),y
eor #$ff
sta ZPCount
iny
lda (ZPIOCTL),y
eor #$ff
sta ZPCount+1
stz ZPCount2
stz ZPCount2+1
ldx DEVSLOTn08F
.10 inc ZPCount
bne .11
inc ZPCount+1
beq .8
.11 .DO SSCIRQ=1
ldy INBUF.TAIL
cpy INBUF.HEAD
beq .2
lda INBUF,y
iny
cpy #BUF.SIZE
bne .1
ldy #0
.1 sty INBUF.TAIL
sta (ZPBufPtr)
inc ZPBufPtr
bne .12
inc ZPBufPtr+1
.12 inc ZPCount2
bne .10
inc ZPCount2+1
bra .10
.FIN
.2 lda SSC.STATUS-$8F,x
bit #SSC.STATUS.nDSR true when 0
bne .9
ldx DEVSLOTn08F
lda SSC.STATUS-$8F,x
and #SSC.STATUS.RDRF incoming char?
beq .8
sta (ZPBufPtr)
inc ZPBufPtr
bne .13
inc ZPBufPtr+1
.13 inc ZPCount2
bne .2
inc ZPCount2+1
bra .2
.8 lda ZPCount2
bne .81
ldx ZPCount2+1
beq .99
.81 ldy #S.IOCTL.BYTECNT
sta (ZPIOCTL),y
iny
txa
sta (ZPIOCTL),y
plp
clc
rts
.90 lda #0
.HS 2C BIT ABS
.9 lda #C.EOF
.99 plp
sec
rts
*--------------------------------------
WRITE >STYA ZPIOCTL
php
sei
ldy #S.IOCTL.BUFPTR
lda (ZPIOCTL),y
sta ZPBufPtr
iny
lda (ZPIOCTL),y
sta ZPBufPtr+1
* ldy #S.IOCTL.BYTECNT
iny
lda (ZPIOCTL),y
eor #$ff
sta ZPCount
iny
lda (ZPIOCTL),y
eor #$ff
sta ZPCount+1
.2 inc ZPCount
bne .3
inc ZPCount+1
beq .8
.3 .DO SSCIRQ=1
ldx DEVSLOTn08F
lda SSC.STATUS-$8F,x
bit #SSC.STATUS.nDSR true when 0
bne .90
lda OUTBUF.HEAD
cmp OUTBUF.TAIL Buffer Empty?
bne .6 not empty, queue char
lda SSC.STATUS-$8F,x
and #SSC.STATUS.TDRE Register Empty ?
beq .5 not empty, queue char
lda (ZPBufPtr) yes, write directly to ACIA
inc ZPBufPtr
bne .4
inc ZPBufPtr+1
.4 sta SSC.DATA-$8F,x
bra .2
.5 lda OUTBUF.HEAD
.6 tax
inc
and #BUF.MASK
cmp OUTBUF.TAIL
beq .9 Buffer Full!!
sta OUTBUF.HEAD
lda (ZPBufPtr)
inc ZPBufPtr
bne .7
inc ZPBufPtr+1
.7 sta OUTBUF,x
bra .2
.ELSE
ldx DEVSLOTn08F
.4 lda SSC.STATUS-$8F,x
* and #SSC.STATUS.DCD+SSC.STATUS.nDSR
* beq .9
and #SSC.STATUS.TDRE Outgoing char?
beq .4
lda (ZPBufPtr)
inc ZPBufPtr
bne .5
inc ZPBufPtr+1
.5 sta SSC.DATA-$8F,x
bra .2
.FIN
.8 plp
clc
rts
.90 lda #0
.HS 2C BIT ABS
.9 lda #C.EOF
plp
sec
rts
*--------------------------------------
* IRQ Handler
* on exit, CC if handled
*--------------------------------------
.DO SSCIRQ=1
IRQ ldx DEVSLOTn08F
lda SSC.STATUS-$8F,x
* and #SSC.STATUS.IRQ Useless
bpl .9 IRQ from this device ? no, exit !!!!Applewin bug #308!!!!
bit #SSC.STATUS.RDRF incoming char?
beq .2
*------------ IRQ In
pha
lda INBUF.HEAD
tay save actual head for later
inc
and #BUF.MASK
cmp INBUF.TAIL
beq .1 buffer full, discard and exit
sta INBUF.HEAD
lda SSC.DATA-$8F,x read data to clear IRQ
sta INBUF,y
.1 pla
*------------ IRQ Out
.2 bit #SSC.STATUS.TDRE
beq .8 no transmition possible....
ldy OUTBUF.TAIL something to transmit ?
cpy OUTBUF.HEAD
beq .8 in that case, HOW TO CLEAR IRQ ????
lda OUTBUF,y
sta SSC.DATA-$8F,x write data to clear IRQ
tya
inc
and #BUF.MASK
sta OUTBUF.TAIL
.8 clc
rts
.9 sec
rts
.FIN
*--------------------------------------
DRV.CS.END
DEVSLOTn08F .BS 1
.DO SSCIRQ=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
.FIN
*--------------------------------------
DIB .DO SSCIRQ=1
.DA #S.DIB.S.WRITE+S.DIB.S.READ+S.DIB.S.IRQ
.ELSE
.DA #S.DIB.S.WRITE+S.DIB.S.READ
.FIN
.DA #0,#0,#0
>PSTR "Serial Card/Port"
.DA #S.DIB.T.CHAR
.DA #0
.DA K.VER
*--------------------------------------
DCB .DA #S.DCB.T.COM
.DA #0 FLAGS
.DA >9600 BAUD (DWORD)
.DA #8 DATA
.DA #1 STOP
.DA #S.DCB.COM.P.NONE PARITY
.DA #S.DCB.COM.C.XONXOFF
*--------------------------------------
DRV.END
MAN
SAVE /A2OSX.SRC/DRV/X.SSC.DRV.S
LOAD /A2OSX.SRC/DRV/SSC.I.DRV.S
ASM