NEW
PREFIX
AUTO 4,1
*--------------------------------------
* DRV.DiskII
* X = IOCTL
* Y,A = PTR to S.IOCTL
*--------------------------------------
DRV.DiskII		cld
				cpx #IOCTL.FORMAT
				bcs DRV.RamDrive.9
				>STYA pIOCTL
				jmp (.1,x)
.1				.DA DRV.DiskII.STATUS
				.DA DRV.BLK				READ
				.DA DRV.BLK				WRITE
*--------------------------------------
DRV.DiskII.STATUS
				>LDYAI DRV.DiskII.DIB
				jmp DRV.STATUS.YA
*--------------------------------------
DRV.DiskII.DIB	.DA #S.DIB.S.BLOCK+S.DIB.S.WRITE+S.DIB.S.READ
				.DA 280
				.DA #0
				>PSTR "Disk ][ 5.25"
				.BS 4
				.DA #S.DIB.T.DISKII
				.DA #0
				.DA K.VER
*--------------------------------------
* DRV.RamDrive
* X = IOCTL
* Y,A = PTR to S.IOCTL
*--------------------------------------
DRV.RamDrive	cld
				cpx #IOCTL.CONTROL
				bcs DRV.RamDrive.9
				>STYA pIOCTL
				jmp (.1,x)
.1				.DA DRV.RamDrive.STATUS
				.DA DRV.BLK				READ
				.DA DRV.BLK				WRITE
				.DA DRV.BLK				FORMAT
DRV.RamDrive.9	jmp A2osX.BadCall
*--------------------------------------
DRV.RamDrive.STATUS
				jsr DRV.Blk
				bcs .9
				stx DRV.RamDrive.DIB+S.DIB.SIZE
				sty DRV.RamDrive.DIB+S.DIB.SIZE+1
				
				>LDYAI DRV.RamDrive.DIB
				jmp DRV.STATUS.YA

.9				rts
*--------------------------------------
DRV.RamDrive.DIB
				.DA #S.DIB.S.BLOCK+S.DIB.S.WRITE+S.DIB.S.READ
				.BS 3
				>PSTR "ProDOS /RAM Disk"
				.DA #S.DIB.T.RAM
				.DA #0
				.DA K.VER
*--------------------------------------
* DRV.BlkDevice
* X = IOCTL
* Y,A = PTR to S.IOCTL
*--------------------------------------
DRV.BlkDevice	cld
				cpx #IOCTL.CONTROL
				bcs DRV.RamDrive.9
				>STYA pIOCTL
				jmp (.1,x)
.1				.DA DRV.BlkDevice.STATUS
				.DA DRV.BLK				READ
				.DA DRV.BLK				WRITE
				.DA DRV.BLK				FORMAT
*--------------------------------------
DRV.BlkDevice.STATUS
				jsr DRV.Blk
				bcs .9
				stx DRV.BlkDevice.DIB+S.DIB.SIZE
				sty DRV.BlkDevice.DIB+S.DIB.SIZE+1

				>LDYAI DRV.BlkDevice.DIB
				jmp DRV.STATUS.YA
.9				rts
*--------------------------------------
DRV.BlkDevice.DIB
				.DA #S.DIB.S.BLOCK+S.DIB.S.WRITE+S.DIB.S.READ
				.BS 3
				>PSTR "ProDOS Block Dev"
				.DA #S.DIB.T.PRODOS
				.DA #0
				.DA K.VER
*--------------------------------------
* IOCTL to BLK protocol converter
* in : pIOCTL
*--------------------------------------
DRV.BLK			txa
				lsr
				sta DRV.BLK.PARAMS		CMD
				
				ldy #S.FD.DEV.DEVID	Drive 1, or 2
				lda (pFD),y
				dec						O or 1
				lsr						in Carry
				php
				
				ldy #S.FD.DEV.BUSID
				lda (pFD),y
				asl
				asl
				asl
				asl
				asl
				plp
				ror						DSSS0000

				sta DRV.BLK.PARAMS+1	UNITNUM
				
				ldx #3
				
				ldy #S.IOCTL.BUFPTR+3
				
.1				lda (pIOCTL),y			BUF,BLKNUM	
				sta DRV.BLK.PARAMS+2,x
				dey
				dex
				bpl .1
				
				ldy #S.FD.DEV.BUSPTR
				
				lda (pFD),y
				sta .3+1
				iny
				lda (pFD),y
				sta .3+2
				
				jsr GO.ProDOS
				
				ldx #5
				
.2				lda DRV.BLK.PARAMS,x
				sta $42,x
				dex
				bpl .2
				
.3				jsr $ffff				SELF MODIFIED

				jsr GO.A2osX
				rts
				
DRV.BLK.PARAMS	.BS 6				
*--------------------------------------
* Smartport	Driver
*--------------------------------------
DRV.SmartPort	cld
				>STYA pIOCTL
				>STYA .3				smartport Params

				txa
				lsr
				sta .2
				tax
				
				lda DRV.SmartPort.Cnt,x
				sta (pIOCTL)			CmdList
				
				ldy #S.FD.DEV.BUSPTR
				lda (pFD),y
				sta .1+1
				iny
				lda (pFD),y
				sta .1+2

.1				jsr $ffff
.2				.BS 1
.3				.BS 2
				rts

DRV.SmartPort.Cnt
				.HS 03030301030101010404
*--------------------------------------
* NULL DEVICE 
*  - OPEN,WRITE,CLOSE always succeed.
*  - READ returns EOF.
*--------------------------------------
DRV.NULL	 	cld
				>STYA pIOCTL
				txa
				beq DRV.NULL.STATUS
				jmp (.1-12,x)
*--------------------------------------
.1				
*				.DA DRV.NULL.STATUS
*				.DA A2osX.BADCALL		READBLOCK
*				.DA A2osX.BADCALL		WRITEBLOCK
*				.DA A2osX.BADCALL		FORMAT
*				.DA A2osX.BADCALL		CONTROL
*				.DA A2osX.BADCALL		INIT
				.DA DRV.NULL.OPEN
				.DA DRV.NULL.CLOSE
				.DA DRV.NULL.READ
				.DA DRV.NULL.WRITE
*--------------------------------------
DRV.NULL.DIB	.DA #S.DIB.S.WRITE+S.DIB.S.READ+S.DIB.S.OPENED
				.DA #0,#0,#0
				>PSTR "NULL Device"
				.BS 5
				.DA #S.DIB.T.CHAR
				.DA #0
				.DA K.VER
*--------------------------------------
DRV.NULL.STATUS	>LDYAI DRV.NULL.DIB
*--------------------------------------			
DRV.STATUS.YA	>STYA .2+1

				ldy #S.IOCTL.STATCODE
				lda (pIOCTL),y
				beq .1
				
				cmp #S.IOCTL.STATCODE.GETDIB
				bne .9
				
				ldx #S.DIB-1
				.HS 2C					bit abs
.1				ldx #3

				ldy #S.IOCTL.BUFPTR
				lda (pIOCTL),y
				sta .3+1
				iny
				lda (pIOCTL),y
				sta .3+2
				
.2				lda $ffff,x				SELF MODIFIED
.3				sta $ffff,x				SELF MODIFIED
				dex
				bpl .2
				
				clc
				rts

.9				lda #MLI.E.BADCTL
				sec
				rts
*--------------------------------------
DRV.NULL.READ	ldx #C.EOF
*--------------------------------------
DRV.READ.X		ldy #S.IOCTL.BYTECNT
				lda #1
				sta (pIOCTL),y
				iny
				dec
				sta (pIOCTL),y

				ldy #S.IOCTL.BUFPTR
				lda (pIOCTL),y
				sta .1+1
				iny
				lda (pIOCTL),y
				sta .1+2
				
.1				stx $ffff				SELF MODIFIED
*--------------------------------------
DRV.NULL.OPEN
DRV.NULL.WRITE
DRV.NULL.CLOSE	clc
				rts
*--------------------------------------
MAN
SAVE USR/SRC/SYS/KERNEL.S.DRV
LOAD USR/SRC/SYS/KERNEL.S
ASM
