	TITLE *** DRIVERS -- SOFTWARE DYNAMICS SDOS DRIVERS (C) 1978 ***
	PAGE	defaults
	TABS	20,28,44,45
	NAME	SDOSDRIVERS

	PCC	1
	PSR	0	don't print skipped records
	PCA	0	don't print conditional assembly records
	PCC	0

	IFUND	YES
YES	EQU	1
	FIN	YES
	IFUND	NO
NO	EQU	0
	FIN	NO
	IFUND	LIST.ALL
LIST.ALL	EQU	YES
	FIN	LIST.ALL
	IFUND	LIST.SDOSDEFS
LIST.SDOSDEFS	EQU	LIST.ALL
	FIN	LIST.SDOSDEFS
	IFUND	LIST.IOPACKAGE
LIST.IOPACKAGE	EQU	LIST.ALL
	FIN	LIST.IOPACKAGE
	IFUND	CLOCK
CLOCK	EQU	YES
	FIN	CLOCK
	IF	CLOCK
	IFUND	LIST.CLOCK
LIST.CLOCK	EQU	LIST.ALL
	FIN	LIST.CLOCK
	IFUND	TICKSPERSECOND
TICKSPERSECOND	EQU	60
	FIN	TICKSPERSECOND
	IFUND	REALTIMECLOCK	"THERE EXISTS A REAL PIECE OF CLOCK HARDWARE"
	IFUND	STORAGEDEMON
	IFUND	USECONSOLEACIAASCLOCK	"NO REAL CLOCK HARDWARE, SO USE CONSOLE TO FAKE IT"
USECONSOLEACIAASCLOCK	EQU	YES
	FIN	USECONSOLEACIAASCLOCK
	ELSE
	IFUND	USECONSOLEACIAASCLOCK	"NO REAL CLOCK HARDWARE, SO USE CONSOLE TO FAKE IT"
USCONSOLEACIAASCLOCK	EQU	&STORAGEDEMON
	FIN	USECONSOLEACIAASCLOCK
	FIN	STORAGEDEMON
REALTIMECLOCK	EQU	&USECONSOLEACIAASCLOCK
	FIN	REALTIMECLOCK
	FIN	CLOCK
	IFUND	VIRTUALFLOPPY
VIRTUALFLOPPY	EQU	NO
	FIN	VIRTUALFLOPPY
	IFUND	SERIES2000
SERIES2000	EQU	0
	FIN	SERIES2000
	IF	VIRTUALFLOPPY
	IFUND	LIST.VIRTUALFLOPPY
LIST.VIRTUALFLOPPY	EQU	LIST.ALL
	FIN	LISTVIRTUALFLOPPY
	IF	SERIES2000
	IFUND	TANDONDS
TANDONDS	EQU	0
	FIN	TANDONDS
	IFUND	TANDONSS
TANDONSS	EQU	0
	FIN	TANDONSS
	IFUND	TANDE
TANDE	EQU	0
	FIN	TANDE
	ELSE
	IFUND	PERSCI
PERSCI	EQU	0
	FIN	PERSCI
	IFUND	DAMFLOPPY
DAMFLOPPY	EQU	0
	FIN	DAMFLOPPY
	IF	PERSCI
	IFUND	WMFORMAT
WMFORMAT	EQU	YES
	FIN	WMFORMAT
	IFUND	IBMFORMAT
IBMFORMAT	EQU	MEMSIZE>32
	FIN	IBMFORMAT
	FIN	PERSCI
	FIN	SERIES2000
	FIN	VIRTUALFLOPPY
	IFUND	WMPERSCI
WMPERSCI	EQU	NO
	FIN
	IF	WMPERSCI
	IFUND	LIST.WMPERSCI
LIST.WMPERSCI	EQU	LIST.ALL
	FIN	LIST.WMPERSCI
	IFUND	NFLOPPIES
NFLOPPIES	EQU	2
	FIN	NFLOPPIES
	FIN	WMPERSCI
	IFUND	WMDAMFLOPPY
WMDAMFLOPPY	EQU	NO
	FIN	WMDAMFLOPPY
	IF	WMDAMFLOPPY
	IF	WMPERSCI
	?ERROR	Must use virtual floppy driver for more than one type of floppy
	ELSE
	IFUND	LIST.WMDAMFLOPPY
LIST.WMDAMFLOPPY	EQU	LIST.ALL
	FIN	LIST.WMDAMFLOPPY
	IFUND	NFLOPPIES
NFLOPPIES	EQU	2
	FIN	NFLOPPIES
	FIN	WMPERSCI
	FIN	WMDAMFLOPPY
	IFUND	WMHYTYPE
WMHYTYPE	EQU	NO
	FIN	WMHYTYPE
	IF	WMHYTYPE
	IFUND	LIST.WMHYTYPE
LIST.WMHYTYPE	EQU	LIST.ALL
	FIN	LIST.WMHYTYPE
	FIN	WMHYTYPE
	IFUND	STORAGEDEMON
STORAGEDEMON	EQU	NO
	FIN	STORAGEDEMON
	IF	STORAGEDEMON
	IFUND	LIST.STORAGEDEMON
LIST.STORAGEDEMON	EQU	LIST.ALL
	FIN	LIST.STORAGEDEMON
	FIN	STORAGEDEMON
	IFUND	BLACKHOLE
BLACKHOLE	EQU	NO
	FIN	BLACKHOLE
	IF	BLACKHOLE
	IFUND	LIST.BLACKHOLE
LIST.BLACKHOLE	EQU	LIST.ALL
	FIN	LIST.BLACKHOLE
	FIN	BLACKHOLE
	IFUND	LIST.VIRTUALTERMINAL
LIST.VIRTUALTERMINAL	EQU	LIST.ALL
	FIN	LIST.VIRTUALTERMINAL
	IFUND	M6800
M6800	EQU	YES
	FIN	M6800
	IFUND	M6809
M6809	EQU	&M6800
	FIN	M6809

OUTASPACE	EQU	YES
IOPKDEFS	EQU	YES

	LIST	LIST.SDOSDEFS
	INCLUDE	SDOS11DEFS.ASM
	LIST	LIST.IOPACKAGE
	PAGE	I/O Package
*
*	BY SOFTWARE DYNAMICS
*	AND A CAST OF THOUSANDS!
*
EDITDATE	EQU	$1008	/81 MMDD IN HEX FORMAT
EDITYEAR	EQU	$81	YY IN HEX FORMAT
*
	IFUND	MEMSIZE
MEMSIZE	EQU	32
	FIN	MEMSIZE
	IFUND	NIOCHANNELS
	IF	MEMSIZE>32
NIOCHANNELS	EQU	8
	ELSE
NIOCHANNELS	EQU	5
	FIN	MEMSIZE>32
	FIN	NIOCHANNELS
*
K	EQU	1024	# BYTES PER "K" OF MEMORY
*
	IFUND	CODE
CODE	EQU	$4000
	FIN	CODE
*
	IFUND	SDOS
SDOS	EQU	MEMSIZE*K-$2A80-$100
	FIN	SDOS
*
	IFUND	DRIVERBASE
	IF	CODE<<SDOS
DRIVERBASE	EQU	CODE
	ELSE
DRIVERBASE	EQU	SDOS-3
	FIN	CODE<<SDOS
	FIN	DRIVERBASE
*
INICV	EQU	$FC03	INITIALIZE CONSOLE DEVICE VECTOR
PUTCV	EQU	$FC06	PUT A CHARACTER TO CONSOLE VECTOR
GETCV	EQU	$FC09	GET A CHARACTER TO CONSOLE VECTOR
TESTCV	EQU	$FC0C	TEST FOR ARRIVAL OF CHARACTER FROM CONSOLE
INIDV	EQU	$FC12	INIT DEFAULT DEVICE (FOR LPT)
PUTDV	EQU	$FC15	PUT A CHARACTER TO DEFAULT DEVICE VECTOR
	PAGE
*
*
*	SDOS-TO-IOPACKAGE COMMUNICATION REGION
*
	ORG	SDOS+1
****	FCB	$10	SDOS VERSION NUMBER
	FDB	0	LAST ERROR ENCOUNTERED
	FDB	CNFGTABLE	TELL SDOS WHERE ALL THE GOODIES ARE
	FDB	0	SERIAL NUMBER
	FDB	0	IOBLOCKPTR
	FDB	0	IOCB POINTER (FOR FILE-TYPE DEVICE DRIVERS)
	FCB	0,0,0	SET CLOCK TO "MIDNITE"
	FCB	0	DAY, LET COMMAND INTERPRETER KNOW
	FCB	0	MONTH, THAT THE TIME HASN'T BEEN SET
	FCB	EDITYEAR	YEAR
*
	ORG	0
*TEMPX	EQU	*
POINTER1	RMB	2
BUFFERPOINTER	EQU	*
POINTER2	RMB	2
COUNT	RMB	2
	PAGE
	ORG	DRIVERBASE
SYSCALLIO	JMP	SYSCALLIO	SDOS SETS JUMP ADDR TO ITS ENTRY POINT
BADINTCOUNT	FCB	0,0,0		COUNT OF UNRECOGNIZED INTERRUPTS
*
*	ALL THE PERIPHERAL DRIVERS MUST BE AFTER THIS
*	PAGE AND BEFORE THE CONFIG TABLE
*
BADINTERRUPT	EQU	*
	INC	BADINTCOUNT+2	COUNT BAD INTERRUPTS
	BNE	BADINTERRUPT1
	INC	BADINTCOUNT+1
	BNE	BADINTERRUPT1
	INC	BADINTCOUNT
BADINTERRUPT1
	JMP	SDOS+SDOS:RTI

NEXTTIMEOUT	SET	0
NEXTDISKDCB	SET	0
NEXTDEVICEDCB	SET	0
NEXTTCB	SET	0
NEXTPOLLDEVICE	SET	BADINTERRUPT
NTIMEOUTS	SET	0
NDISKDCBS	SET	0
RESET	SET	NO	not assembling reset code, yet
	PAGE	IDB "DRIVER"
IDBBASE	EQU	$F000
	IFUND	IDBBASE
IDBTRAP	EQU	0
	ELSE
IDBTRAP	EQU	*
	DES		MAKE ROOM FOR INDEX REGISTER
	DES
	DES		MAKE ROOM FOR CONTENTS OF (A)
	DES		MAKE ROOM FOR CONTENTS OF (B)
	TPA
	PSHA		SAVE CC BITS
	NOP		TURN OFF INTERRUPTS
	SEI
ILIDBTRAP			; INTERRUPT LEVEL ENTRY TO IDB
	JMP	IDBBASE+$8	FAKE NMI TO IDB
	FIN	IDBBASE
	IF	BLACKHOLE
	LIST	LIST.BLACKHOLE
	PAGE	'BLACK HOLE' DRIVER
	INCLUDE	IOBLACKHOLE.ASM
	FIN	BLACKHOLE
	LIST	LIST.CLOCK
	PAGE	CLOCK: DRIVER
	INCLUDE	IOCLOCK.ASM
	IF	WMHYTYPE
	LIST	LIST.WMHYTYPE
	PAGE	WAVEMATE HYTYPE I DRIVERS
	INCLUDE	IOWMHYTYPE.ASM
	FIN	WMHYTYPE
	IF	VIRTUALFLOPPY
	LIST	LIST.VIRTUALFLOPPY
	PAGE	Virtual Floppy Driver
	IF	SERIES2000
	INCLUDE	S2000VFD.ASM
	ELSE
	INCLUDE	IOVFD.ASM
	FIN	SERIES2000
	FIN	VIRTUALFLOPPY
	IF	STORAGEDEMON
	LIST	LIST.STORAGEDEMON
	PAGE	*** STORAGE DEMON DRIVERS ***
	INCLUDE	IOSTOREDEMON.ASM
	FIN	STOREAGEDEMON
	LIST	LIST.VIRTUALTERMINAL
	PAGE	*** Virtual Terminal Configuration ***
	TABS	11,20
	INCLUDE	IOVT.ASM
	TABS	20,28,44,45
	LIST	LIST.IOPACKAGE
	PAGE	CONFIG TABLE
DISKDCBS	SET	NEXTDISKDCB
NDRIVES	SET	NDISKDCBS
DEVICEDCBS	SET	NEXTDEVICEDCB
TIMEOUTQUEUE	SET	NEXTTIMEOUT
NTIMEOUTBLOCKS	SET	NTIMEOUTS
TASKQUEUE	EQU	TTYTCB
INTERRUPTDEVICEPOLL	SET	NEXTPOLLDEVICE
	IFUND	ATTNCHECK
ATTNCHECK	EQU	SDOS+SDOS:VTATTNCHECK
	FIN	ATTNCHECK
	IFUND	INTERRUPTSTACKSIZE
INTERRUPTSTACKSIZE	EQU	MINSTACK+7+7+7+7+7+7+7	7 FOR EACH POSSIBLE
*			NESTED INTERRUPT RESULTING FROM A DEVICE
	FIN	INTERRUPTSTACKSIZE
	PAGE
*	I/O PACKAGE CONFIGURATION

::	SET	*
	ORG	$4000			TELL DEFAULTPATCH ABOUT CONFIG TABLE
	FDB	::
	ORG	::

CNFGTABLE
	FDB	DISKDCBS	DEFAULT DISK MUST BE FIRST
	FDB	TTYDCB			CONSOLE MUST BE FIRST
	FDB	IOCBPOINTERS
	FCB	NIOCHANNELS
	FDB	DSKBUFFERPOOL
	FDB	DSKPOOLSIZE
	FDB	ATTNCHECK
	FDB	IDBTRAP
	FDB	DRIVERBASE
	FDB	INTSETUP
	NOP				DISABLE INTERRUPTS
	SEI
	RTS
	CLI				ENABLE INTERRUPTS
	RTS
	NOP
	RTI				RETURN FROM INTERRUPT
	NOP
	NOP
	FDB	INTERRUPTSTACKEND-1
	FDB	INTERRUPTDEVICEPOLL	ROUTINE TO DETERMINE INTERRUPTING DEVICE
	FDB	TASKQUEUE
	FDB	TIMEOUTQUEUE
	FDB	PROFILECHAIN
	FDB	ILIDBTRAP
	FDB	0			NO SDOS/MT PRIMITIVES
	PAGE	FCBS, IOCBS, INTERRUPT STACK AND POLLING ROUTINES
	PCA	1
*
*	FCBS (MUST PRECEDE IOCBS)
*
FCBS	RPT	FCB:SIZE*(NIOCHANNELS+2*NDRIVES+NMAGICFCBS)
	FCB	0
*
*	IOCBS
*
IOCBS	RPT	IOCB:SIZE*NIOCHANNELS
	FCB	0
IOCBPOINTERS	RPT	NIOCHANNELS
	FDB	IOCBS+IOCB:SIZE*(*-IOCBPOINTERS)/2
*
INTERRUPTSTACK	EQU	*	STACK SPACE FOR INTERRUPT ROUTINES
	RPT	INTERRUPTSTACKSIZE
	FCB	0
INTERRUPTSTACKEND	EQU	*


ILLDEVICEOP	JSR	SDOS+SDOS:ERROR
	FDB	ERR:ILLDEVICEOP
*
ERRETX	JSR	SDOS+SDOS:ERRORSAVE
	JMP	SDOS+SDOS:ERRORED
	PAGE	DISK BUFFERS & RESET CODE
PATCH	RPT	50
	FCB	0
	PCA	0
	EQU	*-CODE
DSKBUFFERPOOL	EQU	*

RESET	SET	YES	now we're assembling reset code

SYSPG	EQU	$FE
SYSIIRQ	EQU	$FD

::	SET	*
	ORG	TTYBUFFERS

INTSETUP	LDX	SYSPG
	LDAA	#(SDOS+SDOS:IOINT)/256
	LDAB	#(SDOS+SDOS:IOINT)&$FF
	STAA	SYSIIRQ+1,X
	STAB	SYSIIRQ+2,X
	OKRTS

	ORG	::

	IF	CLOCK
	IF	SERIES2000
S2000VIAT1LL	EQU	$FC49
S2000VIAT1CH	EQU	$FC4A
S2000VIAACR	EQU	$FC44
S2000VIAIER	EQU	$FC41
S2000VIAIFR	EQU	$FC42

CLOCKRESET	EQU	*	USE VIA CLOCK, ASSUME 1MHZ CPU
	LDAA	#16666/256	16666 US = 16.6 MS = 60HZ
	LDAB	#16666&$FF
	STAB	S2000VIAT1LL	; SET INTERVAL IN LOW LATCH
	STAA	S2000VIAT1CH	; LOAD HIGH LATCH AND INTO COUNTER
	LDAA	#%01000000
	STAA	S2000VIAACR	; SET CONTINUOUS INTERRUPTS FROM COUNTER
	LDAA	#%11000000
	STAA	S2000VIAIER	; ENABLE INTERRUPT REQUEST FROM CLOCK
	OKRTS
	ELSEIF	STORAGEDEMON	
CLOCKRESET	EQU	*	USE VIA CLOCK, ASSUME 1MHZ CPU
	LDAA	#16666/256	16666 US = 16.6 MS = 60HZ
	LDAB	#16666&$FF
	STAB	VIAT1LL	; SET INTERVAL IN LOW LATCH
	STAA	VIAT1CH	; LOAD HIGH LATCH AND INTO COUNTER
	LDAA	#%01000000
	STAA	VIAACR	; SET CONTINUOUS INTERRUPTS FROM COUNTER
	LDAA	#%11000000
	STAA	VIAIER	; ENABLE INTERRUPT REQUEST FROM CLOCK
	OKRTS
	FIN	SERIES2000

	IF	&STORAGEDEMON
CLOCKRESET	EQU	*
	OKRTS
	FIN	&STORAGEDEMON
	FIN	CLOCK
	PAGE
	IF	WMHYTYPE
HYRESET	EQU	*
	CLR	HYICA	INITZ THE WM HYTYPE INTERFACE
	CLR	HYICB
	LDAA	#$FF	SELECT OUTPUT MODE
	STAA	HYIDA
	STAB	HYIDB
	LDAA	#$35		THIS MAGIC NUMBER IS GIVEN BY HARDWARE DESCRIPTION
	STAA	HYICA
	LDAA	#$2F	ANOTHER MAGIC NUMBER
	STAA	HYICB
	OKRTS		THAT'S ALL, FOLKS!
	FIN	WMHYTYPE
	IF	VIRTUALFLOPPY
	LIST	LIST.VIRTUALFLOPPY
	PAGE	Virtual Floppy Driver -- Reset Code
	IF	SERIES2000
	INCLUDE	S2000VFD.ASM
	ELSE
	INCLUDE	IOVFD.ASM
	FIN	SERIES2000
	FIN	VIRTUALFLOPPY
	PAGE
	IF	CODE<<SDOS
	IF	*>/SDOS
	? DRIVERS TOO BIG ?
	ELSE
	RMB	SDOS-*-$1780
	FIN	*>/SDOS
	ELSE
	IF	*>/MEMSIZE*K
	? DRIVERS TOO BIG ?
	FIN	*>/MEMSIZE*K
	RMB	MEMSIZE*K-$100-*
	FIN	CODE<<SDOS
DSKPOOLSIZE	EQU	*-DSKBUFFERPOOL
	EQU	*-CODE	SO I CAN SEE HOW BIG THE WORLD IS
	END
