D004ROM ASM 
;**********************************
;***				***
;***  D004-EPROM reassembliert	***
;***	von haftmann#software	***
;***	und $ieber$oft		***
;***	25.02.93 / 28.02.93	***
;***				***
;**********************************
 
	ORG	0E000H
;In Abarbeitung ist der ROM fast stets
;auf AAdr E000h geschaltet; in den
;RAM kopierte Bereiche werden wie im
;RAM stehend assembliert, stehen jedoch
;hintereinander im EPROM
 
RESET	EQU	RESET
PV1	EQU	0F003H
PV3	EQU	0F009H
RC	EQU	0F00FH
IRMON	EQU	0F018H
IRMOFF	EQU	0F01BH
 
	JP	RDARG
DOSIN	;Start
	DI
	LD	A,(0B781H)
	CP	2
	JR	NC,RDARG
	LD	A,2
	OUT	0F4H,A
	XOR	A	;D004 in
	OUT	0F4H,A	;Dauer-RESET
	LD	E,3
	LD	BC,0F1H
KRL1	XOR	A	;Koppelram
	OUT	(C),A	;l|schen
	DJNZ	KRL1
	INC	C
	DEC	E
	JR	NZ,KRL1
	LD	HL,RBOOT;Urlader
	LD	BC,1F0H	;=FC00h
	LD	DE,200H
URLD1	OUTI		;Urlader
	INC	B	;in Koppelram
	INC	B	;kopieren
	DEC	E
	JR	NZ,URLD1
	INC	C
	LD	E,22H
	DEC	D
	JR	NZ,URLD1
	LD	A,1
	OUT	0F4H,A
	XOR	A	;Start D004
	OUT	0F4H,A
	DEC	D	;D=FFh
UROK1	LD	BC,0B3F3H ;=FFB3h
	IN	A,(C)	  ;>UROK<
	AND	A	  ;0=TimeOut
	JR	NZ,FINDMD ;1=PC-Mode
	LD	B,0	  ;2=Not Ready
UROK2	DJNZ	UROK2	  ;3=Can't Read
	DEC	DE	  ;4=No System
	LD	A,E	  ;5=CAOS-Mode
	OR	D
	JR	NZ,UROK1  ;Warten
;TimeOut
LDERRM	LD	HL,RERRM
	LD	DE,ERRM	  ;Zieladr.
	LD	BC,RV24I-RERRM
	CP	0FFH
	JR	NZ,LDERR1
	XOR	A
LDERR1	LDIR
	JP	0	  ;anspringen
	;
RDARG	LD	A,(0B784H);ARG2
	AND	A
	JP	NZ,JPARG
	LD	BC,0B3F3H ;=FFB3h
	IN	A,(C)	  ;>UROK<
	CP	5
	JP	Z,CAOSMD
	CP	1
	JR	Z,PCMD
LDERR2	JR	LDERRM
	;
FINDMD	CP	5
	JP	Z,CAOSMD
	CP	1
	JR	NZ,LDERRM
 
PCMD	LD	HL,RCAOSON
	LD	DE,CAOSON
	LD	BC,RZAS-RCAOSON
	LDIR	;CAOS-Schalter kopieren
	;
	LD	HL,RGAT
	LD	DE,GAT
	LD	BC,RCAOSON-RGAT
	LDIR	;Adre~tabellengenerie-
		;rungsprogramm kopieren
	LD	BC,PCMD1 ;Fortsetzung
	LD	HL,GAT	 ;Ansprung
PCMD0	PUSH	BC
	LD	BC,CAOSOFF
	PUSH	BC
	JP	CAOSON
PCMD1	LD	HL,RV24I
	LD	DE,V24INI
	LD	BC,RV24D-RV24I
	LDIR	;Ausgabeprogramm
	LD	BC,PCMD2
	LD	HL,V24INI
	JR	PCMD0
PCMD2	LD	HL,RV24D
	LD	DE,V24DUP
	LD	BC,RSIOT-RV24D
	LDIR	;Eingabeprogramm
	LD	BC,PCMD3
	LD	HL,V24DUP
	JR	PCMD0
PCMD3	LD	HL,RZAS
	LD	BC,0CFBH ;fiktive L{nge
	LD	DE,ZAS
	LDIR	;Zentrale Abfrageschl.
	LD	HL,ICTC3 ;Tastatur-CTC
	LD	(1EEH),HL
	LD	HL,IPIOB ;Tastatur-PIO
	LD	(1E6H),HL
	LD	(IX+7),1
	LD	(IX+8),80H
	XOR	A
	LD	(WS+8),A
	EI
	LD	A,38H
	LD	(0B7D6H),A;FARB
	LD	BC,0B4F3H ;=FFB4
	LD	HL,KTAB	  ;>KTABAD<
	OUT	(C),L
	INC	B
	OUT	(C),H
	LD	HL,0
	LD	(0B7A0H),HL ;Cursorpos
	LD	HL,ESCTAB
	INC	B
	INC	B
	OUT	(C),L	  ;BC=FFB7
	INC	B	  ;>ESCTAB<
	OUT	(C),H
	LD	HL,PCMD4
	PUSH	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D	C,8	;Segmente
	JR	MOSU6
	;
MO256K	LD	C,16	;Segmente
MOSU6	LD	D,4
	JR	MOSU5
	;
MO1M	LD	C,64	;Segmente
	JR	MOSU6
	;
MO512K	LD	C,32	;Segmente
	JR	MOSU6
 
;******************************
;** Beginn der RAM-Programme **
;******************************
 
RGAT	ORG	200H
GAT	;Generierung Adre~tabelle
	LD	A,2	;2 H{lften
	LD	DE,3D00H
	LD	HL,800H	;Linke H{lfte
GAT1	LD	C,24	;Zeilen (1920)
	PUSH	AF
GAT2	LD	B,8
GAT3	PUSH	HL
	PUSH	DE
	CALL	PV1
	DB	34H	;PADR
	POP	DE
	LD	A,L
	LD	(DE),A
	INC	DE
	LD	A,H
	LD	(DE),A
	INC	DE
	POP	HL
	INC	H
	DJNZ	GAT3
	INC	H
	INC	H
	DEC	C
	JR	NZ,GAT2
	POP	AF
	LD	HL,820H	;Rechte H{lfte
	DEC	A
	JR	NZ,GAT1
	RET
	ORG	RGAT+$-GAT
RCAOSON	ORG	370H
 
CAOSON	IN	A,88H
	SET	0,A
	OUT	88H,A
	JP	(HL)
 
CAOSOFF	LD	A,(DE)
	LD	D,A
	IN	A,88H
	RES	0,A
	OUT	88H,A
	RET
 
	ORG	RCAOSON+$-CAOSON
RZAS	ORG	400H
 
ZAS	;Zentrale Abfrageschleife
	LD	BC,0A7F3H ;=FFA7
	IN	E,(C)	  ;>OUTPTR+1<
	DEC	B
	IN	A,(C)
	CP	E
	LD	D,A
	JR	NZ,ZAS1
	LD	A,(WS+7)
	AND	A
	JR	NZ,ZAS3
	CALL	CUCP
	LD	A,1
	LD	(WS+7),A
	JR	ZAS3
	;
ZAS1	LD	A,(WS+7)
	BIT	0,A
	JR	Z,ZAS2
	CALL	CUCP
	XOR	A
	LD	(WS+7),A
ZAS2	LD	A,20H
	ADD	D
	INC	D
	PUSH	BC
	LD	B,A
	IN	A,(C)
	LD	L,0
	CALL	IOPV
	POP	BC
	JR	C,ZAS3
	LD	A,D
	AND	1FH
	OUT	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4
	SET	4,(IX+8)
	JR	TI3
	;
TI9	BIT	0,(IX+10)
	JR	NZ,TI3
	JR	TI4
 
KTAB	;Tastaturumcodierungstabelle
	;Aufbau: 1 Byte ohne SHIFT
	;	 1	mit SHIFT
	;	 1	mit CONTROL
	DB	'W','w',17H
	DB	'A','a',1
	DB	'2','"','|'
	DB	8,1,8		;CUL
	DB	84H,85H,86H	;HOME
	DB	'-','=',' '
	DB	0F2H,0F8H,0F1H	;F2
	DB	'Y','y',19H
	DB	'E','e',5
	DB	'S','s',13H
	DB	'3','#','}'
	DB	'^','~',1EH
	DB	10H,87H,88H	;CLR
	DB	':','*',' '
	DB	0F3H,0F9H,0F7H	;F3
	DB	'X','x',18H
	DB	'T','t',14H
	DB	'F','f',6
	DB	'5','%','\'
	DB	'P','p',10H
	DB	7FH,19H,89H	;DEL
	DB	'0',40H,'~'
	DB	0F5H,0FBH,83H	;F5
	DB	'V','v',16H
	DB	'U','u',15H
	DB	'H','h',8
	DB	'7',27H,' '
	DB	'O','o',0FH
	DB	16H,8AH,8BH	;INS
	DB	'9',')',8CH
	DB	3,3,8EH		;BRK
	DB	'N','n',0EH
	DB	'I','i',9
	DB	'J','j',0AH
	DB	'8','(',' '
	DB	' ',9,' '	;SPC
	DB	'K','k',0BH
	DB	',','<',' '
	DB	13H,11H,8FH	;STOP
	DB	'M','m',0DH
	DB	'Z','z',1AH
	DB	'G','g',7
	DB	'6','&',']'
	DB	20H,20H,20H	;TA44
	DB	'L','l',0CH
	DB	'.','>',' '
	DB	0F6H,0FCH,' '	;F6
	DB	'B','b',2
	DB	'R','r',12H
	DB	'D','d',4
	DB	'4','$','['
	DB	'_','|',1FH
	DB	'+',';',' '
	DB	'/','?',' '
	DB	0F4H,0FAH,82H	;F4
	DB	'C','c',3
	DB	'Q','q',11H
	DB	90H,90H,90H	;SHL
	DB	'1','!','{'
	DB	18H,3,18H	;CUD
	DB	5,12H,5		;CUU
	DB	4,6,4		;CUR
	DB	91H,1BH,91H	;F1
	D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P	14H
	JR	Z,CLCE
	CP	16H
	JR	Z,CLLE
	CP	15H
	JR	NZ,CRT1
	LD	A,9
CRT1	CP	7FH
	JR	NZ,CRT2
	LD	A,1FH
CRT2	CALL	PV1
	DB	0
	RET
	;
CUP83	LD	A,2
	JR	CUP831
	;
CUP82	XOR	A
CUP831	LD	(WS+7),A
	RET
	;
CLLE	LD	A,(0B7A0H)
	PUSH	AF
	LD	B,A
	LD	A,(0B79EH)
	INC	A
	SUB	B
	LD	B,A
	LD	A,11H	;Page Mode
	CALL	PV1
	DB	0
CLLE1	LD	A,20H
	CALL	CRT2
	DJNZ	CLLE1
	LD	A,12H	;Scroll Mode
	CALL	PV1
	DB	0
	POP	AF
	JP	CLLE2
 
CLCE	CALL	CLLE
	LD	A,(0B7A1H)
	INC	A
	PUSH	AF
	LD	B,A
	LD	A,(0B79FH)
	INC	A
	SUB	B
	RET	Z
	LD	B,A
	POP	AF
	PUSH	AF
CLCE1	LD	(0B7A1H),A
	LD	A,2	;CLLN
	CALL	CRT2
	LD	A,(0B7A1H)
	INC	A
	DJNZ	CLCE1
	POP	AF
	DEC	A
	LD	B,A
	JP	CBL
 
POPX3	;Gemeinsames POP-Ende
	XOR	A
POPS3	POP	BC
	POP	DE
	POP	HL
	RET
 
CRT4	LD	A,80H	;ESC merken
	LD	(WS),A	;(Bit 7)
	RET
 
CRT3	;wenn ESC aktiv ist (A=(WS))
	BIT	7,A	;ESC frisch?
	JR	NZ,CRT6
	BIT	6,A
	JR	NZ,CRT7	;Locate aktiv?
	LD	HL,(WS+3)
	LD	M,B
	INC	HL
	LD	(WS+3),HL
	LD	A,(WS)
	DEC	A
	LD	(WS),A
	RET	NZ
	LD	HL,(WS+1)
CRT5	PUSH	HL	;Adr. kellern
	LD	HL,WS+11
	LD	(WS+3),HL
	LD	A,M
	RET	;ESC-Routine anspringen
	;dabei HL: Parameterliste und
	;A: erster Parameter mitgeben
 
CRT6	LD	A,B
	CP	7FH	;>7F, Locate?
	JR	C,CRT8	;kein Locate
	LD	A,40H
	LD	(WS),A	;Locate merken
	LD	A,B
	AND	1FH	;Zeile setzen
	LD	(0B7A1H),A
	RET
	;
CRT7	XOR	A
	LD	(WS),A	;ESC beenden
	LD	A,B
	AND	7FH	;Spalte setzen
CLLE2	LD	(0B7A0H),A
	RET
	;
CRT8	SUB	41H	;Falscher
	JR	C,CRT9	;Buchstabe?
	LD	C,A
	LD	B,0
	LD	HL,ESCTAB
	ADD	HL,BC
	ADD	HL,BC
	ADD	HL,BC	;*3
	LD	A,M	;Parameterzahl
	INC	HL
	LD	B,M
	INC	HL
	LD	H,M
	LD	L,B	;HL:Sprungadr.
	AND	A
	LD	(WS),A
	JR	Z,CRT5	;sofort Sprung
	LD	(WS+1),HL ;merken
ESCI	RET		;nichts tun
	;
CRT9	XOR	A	;ESC vergessen
ESCT1	LD	(WS),A
	RET
	;
ESCA	LD	E,30H	;PSET
	DB	1	;LD BC,
ESCB	LD	E,2FH	;PRESET
	LD	B,3
	PUSH	DE
	LD	DE,0B7D3H ;HOR+VERT
	LD	BC,3	;f}ttern
	LDIR
	POP	DE
CRT10	JP	PV3
	;
ESCC	AND	1FH	;Grafikfarbe
	RLCA
	RLCA
	RLCA
	LD	(0B7D6H),A;FARB
	RET
	;
ESCD	LD	DE,0B782H ;Linie
	LD	BC,3	;ARG1..2
	LDIR		;f}ttern
	XOR	A
	LD	(DE),A
	INC	DE
	LD	C,3	;ARG3..4
	LDIR		;f}ttern
	LD	(DE),A
	LD	E,3EH	;CIRCLE
	JR	CRT10
	;
ESCE	LD	DE,0B782H ;Kreis
	LD	BC,3	;ARG1..2
	LDIR		;f}ttern
	XOR	A
	LD	(DE),A
	INC	DE
	LDI		;Radius
	LD	(DE),A
	LD	E,3FH	;CIRCL
	JR	CRT10
	;
ESCF	CP	10H	;Fenster-Nr.
	RET	NC	;Fehler
	LD	E,3DH	;WINAK
	JR	CRT10
	;
ESCG	LD	DE,0B782H ;Tonausgabe
	LD	BC,6	;3 Argumente
	LDIR		;f}ttern
	LD	E,35H	;TON
	JR	CRT10
	;
ESCH	AND	1FH	;V/H-Farbe
	RLCA
	RLCA
	RLCA		;VFarbe*8
	INC	HL
	LD	B,A
	LD	A,M	;HFarbe
	AND	7
	OR	B
	LD	(0B7A3H),A
	RET
	;
ESCL	INC	HL	;Fensterinit.
	LD	C,M	;Nr. in A
	INC	HL
	LD	B,M
	INC	HL
	LD	E,M
	INC	HL
	LD	D,M
	LD	L,C
	LD	H,B
	CALL	PV1
	DB	3CH	;WININ
	RET
 
QCLS	;Quick-ClearScreen
	LD	A,(0B7A3H);A=Farbe
	LD	D,0	;??
ESCM	;CLS
	LD	HL,8000H
	LD	DE,8001H
	LD	BC,27FFH
	LD	M,L	;Null
	LDIR
	RET
	;
ESCN	AND	1FH	;Neue VFarbe
	RLCA		;des Schirms(!)
	RLCA
	RLCA
	LD	D,7
ESCO1	LD	E,A
	LD	A,(0B7A3H)
	AND	D
	OR	E
	LD	(0B7A3H),A
	LD	A,(WS+10) ;KC/4?
	LD	HL,0A800H
	LD	BC,0A00H
	AND	A
	JR	Z,ESCN1
	LD	A,(IX+1)
	SET	1,A
	OUT	84H,A
	LD	HL,8000H  ;KC/4-Extra
	LD	BC,2800H
ESCN1	LD	A,M
	AND	D
	OR	E
	LD	M,A
	INC	HL
	DEC	BC
	LD	A,C
	OR	B
	JR	NZ,ESCN1
	LD	A,(IX+1)
	OUT	84H,A
	RET
	;
ESCO	AND	7	;Neue HFarbe
	LD	D,0F8H	;des Schirms(!)
	JR	ESCO1
	;
ESCP	;Bildschirmmodus wechseln
	LD	A,(WS+7);Cursor?
	AND	A
	XOR	A
	LD	(WS+7),A;ein!
	CALL	NZ,CUCP
	LD	A,(WS+8);Modus
	XOR	1
	LD	(WS+8),A
	CALL	PAGEPG
	LD	L,1
BSSWAP	LD	BC,0B6F3H ;=FFB6
	IN	A,(C)	;>BSSTAT<
	XOR	L	;Bit 0 swappen
	OUT	(C),A
	RET
	;
ESCQ	;1 Byte lesen (nach FE00h)
	INC	HL
	LD	H,M
	LD	L,A
	LD	BC,1F2H
	OUTI	;zum Sektorpuffer
MEMQ	XOR	A
	LD	BC,0AEF3H ;=FFAE
	OUT	(C),A	;>MEMANF<
	RET
	;
ESCR	;256 Bytes lesen (nach FE00h..
	INC	HL	;FEFFh)
	LD	H,M
	LD	L,A
	LD	E,0	;256mal
	LD	BC,1F2H
ESCR1	OUTI
	INC	B
	INC	B
	DEC	E
	JR	NZ,ESCR1
	JR	MEMQ
	;
ESCS	;1 Byte schreiben (vom Stream)
	LD	E,M
	INC	HL
	LD	D,M
	INC	HL
	LDI
	RET
	;
ESCT	;N Bytes schreiben (vom Stream)
	;N: 1..65536, Parameterzahl: 5
	;(Mindestzahl)
	LD	HL,(WS+11)
	LD	A,(WS+15)
	LD	M,A	;einpoken
	INC	HL
	LD	(WS+11),HL
	LD	HL,(WS+13)
	DEC	HL	;z{hlen
	LD	(WS+13),HL
	LD	A,L
	OR	H	;Null? (Ende?)
	RET	Z
	LD	HL,WS+15;Parameter^
	LD	(WS+3),HL ;vorgaukeln
	LD	A,1	;Noch ein Par.
	JP	ESCT1	;vorgaukeln
	;(Weiterlaufende ESC-Sequenz
	;emulieren!)
 
ESCU	;Programmaufruf
	INC	HL
	LD	H,M
	LD	L,A
	JP	(HL)
	;
ESCV	LD	E,24H	;Zeichenausgabe
ESCW1	JP	PV3
	;
ESCW	LD	E,2	;USER#2
	JR	ESCW1
	;
ESCX	LD	E,3	;USER#3
	JR	ESCW1
	;
	RET		;??
	;
ESCAE	;CAOS-Ruf mit Nummer
	LD	E,A
	JR	ESCW1
	;
ESCOE	JP	RESET	;Reset
	;
CUP8C	;Wechsel amerik./deutsch
	LD	HL,CCTL1X
	LD	DE,CCTL2X
	LD	B,18H	;[\]
	CALL	SWAP
	LD	HL,CCTL3X
	LD	B,20H	;{|}~
	CALL	SWAP
	LD	L,2
BSSW01	JP	BSSWAP	;kennzeichnen
	;
SWAP	LD	A,(DE)	;(HL):=:(DE)
	LDI		;INC DE
	DEC	HL	;INC HL
	INC	BC	;B mal
	LD	M,A
	INC	HL
	DJNZ	SWAP
	RET
	;
CUP85	;Page/Scrollmode
	LD	A,(WS+9)
	XOR	1
	LD	(WS+9),A
	LD	L,8
	CALL	BSSWAP
	LD	A,11H	;Page Mode
	JR	Z,CUP852
	LD	HL,PAGEPG
CUP851	LD	(WS+5),HL ;WEND setzen
	JR	ESCV
	;
CUP852	LD	HL,SCRLPG
	INC	A	;A=12H, Scroll
	JR	CUP851
	;
CUP8B	;Keyboard klein/gro~
	DI
	LD	HL,KTAB	;durch Herum-
	LD	B,0C0H	;poken in KTAB!
KTM1	LD	A,M
	CP	'A'
	JR	C,KTM3
	CP	'['
	JR	NC,KTM2
	SET	5,M	;Gro~->Klein
	JR	KTM3
	;
KTM2	CP	'a'
	JR	C,KTM3
	CP	'{'
	JR	NC,KTM3
	RES	5,M	;Klein->Gro~
KTM3	INC	HL
	DJNZ	KTM1
	EI
	LD	L,4
	JR	BSSW01	;kennzeichnen
	;
ESCZ3	;Wechsel IRM-Ebene
	AND	7
	LD	B,A
	LD	A,0F8H
ESCAK1	AND	(IX+1)
	OR	B
	LD	(IX+1),A
	OUT	84H,A
	RET
	;
ESCAK	;hochaufl|sende Grafik
	LD	B,8
ESCBK1	LD	A,0F7H
	JR	ESCAK1
	;
ESCBK	;normale Grafik
	LD	B,0
	JR	ESCBK1
	;
ESCCK	;Modul schalten
	INC	HL
	LD	D,M
	LD	E,D
	LD	L,A
	LD	A,2
	CALL	PV1
	DB	26H	;MODU
	RET
	;
ESCEK	;F-Taste belegen
	CALL	PV1
	DB	39H
	RET
	;
ESCDK	;Punkttesten
	INC	HL
	LD	H,M
	LD	L,A
	LD	(0B7D3H),A
	CALL	PV1
	DB	2FH	;PUDE
	JR	Z,ESCDK1
	LD	(0B7D6H),A
	CALL	PV1
	DB	30H	;PUDE
	LD	A,1	;wenn gesetzt
	DEFB	0EH	;LD C,
ESCDK1	XOR	A	;wenn gel|scht
	LD	BC,0AEF3H ;=FFAEh
	OUT	(C),A	;>MEMANF<
	RET
	;
ROLL	;eigentliche Scrollroutine
	;(1. Overlay f}r KC85/4)
;Diese Routine rollt nur die Text-
;Pixelzeilen, NICHT die Zwischenzeilen!
	;
	LD	(IX+7),23*8 ;Zeilen
	LD	IY,3E80H;rechte H{lfte
	PUSH	IY
	LD	IY,3D00H;linke H{lfte
ROLL1	LD	E,(IY)
	LD	D,(IY+1)
	LD	L,(IY+10H)
	LD	H,(IY+11H)
	LD	BC,20H
	LDIR		;Roll links
	INC	IY
	INC	IY
	EX	(SP),IY
	LD	E,(IY)
	LD	D,(IY+1)
	LD	L,(IY+10H)
	LD	H,(IY+11H)
	LD	C,8
	LDIR		;Roll rechts
	INC	IY
	INC	IY
	EX	(SP),IY
	DEC	(IX+7)	;mitz{hlen
	JR	NZ,ROLL1
	POP	IY	;Stack Clear
;Letzte Zeile l|schen
	LD	HL,3E70H
	LD	C,8
ROLL2	LD	E,M
	INC	HL
	LD	D,M
	INC	HL
	LD	B,20H
	XOR	A
ROLL3	LD	(DE),A	;Linke H{lfte
	INC	DE
	DJNZ	ROLL3
	DEC	C
	JR	NZ,ROLL2
	LD	HL,3FF0H
	LD	C,8
ROLL4	LD	E,M
	INC	HL
	LD	D,M
	INC	HL
	LD	B,8
	XOR	A
ROLL5	LD	(DE),A	;Rechte H{lfte
	INC	DE
	DJNZ	ROLL5
	DEC	C
	JR	NZ,ROLL4
	RET
	;
CUCP	;Cursor kompeln
	PUSH	HL
	PUSH	DE
	PUSH	BC
	LD	HL,(0B7A0H)
	PUSH	AF
	LD	A,(WS+8)
	AND	A	;1920-Format?
	JR	Z,CUCP2	;ja
	CALL	PV1
	DB	25H	;CUCP (CAOS)
CUCP1	POP	AF
	JP	POPX3	;Ende
CUCP2	;1920-Modus
	;(2. Overlay f}r KC85/4)
	SRL	L	;LSB Spalte->CY
	LD	C,0F0H
	JR	NC,CUCP3
	LD	C,0FH	;CY=1: rechts
CUCP3	LD	A,L
	CP	20H
	LD	IY,3D00H;Tabelle li
	JR	C,CUCP4
	LD	IY,3E80H;Tabelle re
	LD	A,L
	SUB	20H
	LD	L,A
CUCP4	LD	E,L
	LD	D,0
	LD	L,H	;L=Zeile
	LD	H,D	;H=0
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,HL	;*16
	EX	DE,HL
	ADD	IY,DE	;Tab-Adr.
	EX	DE,HL
	LD	B,8
	LD	H,0
CUCP5	LD	L,(IY)
	INC	IY
	LD	H,(IY)	;HL=Pix-Adr.
	INC	IY
	ADD	HL,DE	;Spalte add.
	LD	A,M
	XOR	C	;Nibble
	LD	M,A
	DJNZ	CUCP5	;8mal
	JR	CUCP1	;Ende
 
;1920-Zeichen-Routine
CRT801	LD	E,M
	INC	HL
	LD	D,M
	EX	DE,HL
	LD	BC,(0B7A0H)
	JP	(HL)
 
CRT80	;Haupteinsprung
	LD	HL,CTAB
	LD	B,12
CRT802	CP	M	;Steuerfunktion
	INC	HL	;suchen
	JR	Z,CRT801
	INC	HL
	INC	HL
	DJNZ	CRT802	;12 Funktionen
CRT80X	AND	7FH	;Bit 7 tilgen
	SUB	20H	;nicht
	RET	C	;darstellbar
	LD	H,0
	LD	L,A
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,HL	;*8, CCTL-Adr.
	LD	DE,CCTL80
	ADD	HL,DE
	EX	DE,HL
	LD	BC,(0B7A0H)
CRT803	;(3. Overlay f}r KC85/4)
	LD	HL,3D00H;Links
	LD	A,C
	CP	40H
	JR	C,CRT804
	SUB	40H
	LD	HL,3E80H;Rechts
CRT804	PUSH	HL
	LD	L,B
	LD	H,0
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,HL
	ADD	HL,HL	;*16
	POP	BC
	ADD	HL,BC
	RRA
	LD	C,A
	LD	B,8
CRT805	PUSH	HL
	LD	A,(DE)
	PUSH	AF
	LD	A,M
	INC	HL
	LD	H,M
	OR	C
	LD	L,A
	POP	AF
	PUSH	AF
	LD	A,M
	JR	C,CRT806
	AND	0FH
	LD	M,A
	POP	AF
	PUSH	AF
	AND	0F0H
	JR	CRT807
	;
CRT806	AND	0F0H
	LD	M,A
	POP	AF
	PUSH	AF
	AND	0FH
CRT807	OR	M
	LD	M,A
	INC	DE
	POP	AF
	POP	HL
	INC	HL
	INC	HL
	DJNZ	CRT805
CUR	LD	BC,(0B7A0H)
	INC	C
	LD	A,C
	CP	80	;Spalten
	JR	NZ,CRT809
	LD	C,0
CUD	INC	B
	LD	A,24	;Zeilen
	CP	B
	JR	Z,CRT80J
CRT809	LD	(0B7A0H),BC
KEINPG	;Keine WEND-Reaktion
	RET
	;
CRT80J	LD	HL,(WS+5) ;WEND -
	JP	(HL)	;Reaktionsprog.
	;
SCRLPG	;Scroll-Reaktion
	CALL	ROLL
	LD	BC,23*100H;Cursorzeile
	JR	CRT809
	;
PAGEPG	;Page-Reaktion
	CALL	QCLS
HOME	LD	BC,0	;HOME-Position
	JR	CRT809
	;
CLR	;Backstep, 7Fh
	CALL	CUL
	LD	A,' '
	CALL	CRT80X
CUL	LD	BC,(0B7A0H)
	DEC	C
	LD	A,0FFH
	CP	C
	JR	NZ,CRT809
	LD	C,4FH
CUU	LD	A,0FFH
	DEC	B
	CP	B
	JR	NZ,CRT809
	INC	B
CRT808	JR	CRT809
	;
CBL	LD	C,0
	JR	CRT809
	;
CLC	;Cursor rechts bis Ende l|schen
	LD	BC,(0B7A0H)
	PUSH	BC
	LD	HL,(WS+5) ;WEND-Adr.
	PUSH	HL	  ;retten
	LD	HL,KEINPG
	LD	(WS+5),HL
	LD	A,80	;Spalte
	SUB	C
	LD	H,0
	LD	L,A
	LD	DE,80
	LD	A,23	;Zeile
	SUB	B
	JR	Z,CLC2
CLC1	ADD	HL,DE
	DEC	A
	JR	NZ,CLC1
CLC2	LD	C,L
	LD	B,H
CLC3	LD	A,20H
	PUSH	BC
	CALL	CRT80X
	POP	BC
	DEC	BC
	LD	A,C	;Null?
	OR	B
	JR	NZ,CLC3
	JR	CLL2
	;
CLL	PUSH	BC
	LD	HL,(WS+5)
	PUSH	HL	;retten
	LD	HL,KEINPG
	LD	(WS+5),HL
	LD	A,80
	SUB	C
	LD	B,A
CLL1	LD	A,20H
	PUSH	BC
	CALL	CRT80X
	POP	BC
	DJNZ	CLL1
CLL2	POP	HL
	LD	(WS+5),HL ;r}cktragen
	POP	BC
	JR	CRT808	;BC eintragen
	;
CLLN	XOR	A
	LD	(0B7A0H),A
	LD	C,A
	JR	CLL
	;
;Zeichenbildtabelle
;Aufbau: High-Nibble=Low-Nibble
;(Speicherverschwendung)
;Pro Zeichen 8 Bytes
 
CCTL80
 DB 0,0,0,0,0,0,0,0		;SPC
 DB 22H,22H,22H,22H,22H,0,22H,0	;!
 DB 33H,33H,0,0,0,0,0,0		;"
 DB 0,55H,77H,55H,77H,55H,0,0	;#
 DB 22H,77H,66H,22H,33H,77H,22H,0 ;$
 DB 0,55H,11H,22H,22H,44H,55H,0	;%
 DB 0,22H,55H,22H,55H,44H,33H,0	;&
 DB 22H,22H,0,0,0,0,0,0		;'
 DB 33H,44H,44H,44H,44H,44H,33H,0 ;(
 DB 66H,11H,11H,11H,11H,11H,66H,0 ;)
 DB 0,0,55H,22H,55H,0,0,0	;*
 DB 0,0,22H,77H,22H,0,0,0	;+
 DB 0,0,0,0,0,22H,22H,44H	;,
 DB 0,0,0,77H,0,0,0,0		;-
 DB 0,0,0,0,0,0,22H,0		;.
 DB 11H,11H,22H,22H,22H,44H,44H,0 ;/
 DB 22H,55H,55H,55H,55H,55H,22H,0 ;0
 DB 11H,33H,55H,11H,11H,11H,11H,0 ;1
 DB 22H,55H,55H,11H,22H,44H,77H,0 ;2
 DB 22H,55H,11H,22H,11H,55H,22H,0 ;3
 DB 55H,55H,55H,77H,11H,11H,11H,0 ;4
 DB 77H,44H,44H,77H,11H,55H,22H,0 ;5
 DB 22H,44H,44H,66H,55H,55H,22H,0 ;6
 DB 77H,11H,11H,11H,22H,22H,22H,0 ;7
 DB 22H,55H,55H,22H,55H,55H,22H,0 ;8
 DB 22H,55H,55H,33H,11H,11H,22H,0 ;9
 DB 0,0,22H,0,0,22H,0,0		;:
 DB 0,0,22H,0,0,22H,22H,44H	;;
 DB 0,11H,22H,44H,22H,11H,0,0	;<
 DB 0,0,77H,0,77H,0,0,0		;=
 DB 0,44H,22H,11H,22H,44H,0,0	;>
 DB 22H,55H,11H,22H,22H,0,22H,0	;?
 DB 66H,55H,11H,22H,55H,55H,33H,0 ;40H
 DB 22H,55H,55H,77H,55H,55H,55H,0 ;A
 DB 66H,55H,55H,66H,55H,55H,66H,0 ;B
 DB 22H,55H,44H,44H,44H,55H,22H,0 ;C
 DB 66H,55H,55H,55H,55H,55H,66H,0 ;D
 DB 77H,44H,44H,66H,44H,44H,77H,0 ;E
 DB 77H,44H,44H,66H,44H,44H,44H,0 ;F
 DB 22H,55H,44H,44H,55H,55H,33H,0 ;G
 DB 55H,55H,55H,77H,55H,55H,55H,0 ;H
 DB 77H,22H,22H,22H,22H,22H,77H,0 ;I
 DB 77H,11H,11H,11H,11H,55H,22H,0 ;J
 DB 55H,55H,66H,44H,66H,55H,55H,0 ;K
 DB 44H,44H,44H,44H,44H,44H,77H,0 ;L
 DB 55H,77H,77H,55H,55H,55H,55H,0 ;M
 DB 66H,55H,55H,55H,55H,55H,55H,0 ;N
 DB 77H,55H,55H,55H,55H,55H,77H,0 ;O
 DB 66H,55H,55H,66H,44H,44H,44H,0 ;P
 DB 77H,55H,55H,55H,55H,77H,77H,11H ;Q
 DB 66H,55H,55H,66H,55H,55H,55H,0 ;R
 DB 22H,55H,44H,22H,11H,55H,22H,0 ;S
 DB 77H,22H,22H,22H,22H,22H,22H,0 ;T
 DB 55H,55H,55H,55H,55H,55H,77H,0 ;U
 DB 55H,55H,55H,55H,55H,55H,22H,0 ;V
 DB 55H,55H,55H,55H,77H,77H,55H,0 ;W
 DB 55H,55H,55H,22H,55H,55H,55H,0 ;X
 DB 55H,55H,55H,77H,22H,22H,22H,0 ;Y
 DB 77H,11H,11H,22H,44H,44H,77H,0 ;Z
CCTL1X	;Eckige Klammern (amerik.)
 DB 77H,44H,44H,44H,44H,44H,77H,0 ;(.
 DB 44H,44H,22H,22H,22H,11H,11H,0 ;/.
 DB 77H,11H,11H,11H,11H,11H,77H,0 ;.)
 DB 0,22H,55H,0,0,0,0,0		;^
 DB 0,0,0,0,0,0,0,77H		;_
 DB 66H,11H,22H,55H,22H,44H,33H,0 ;Para
 DB 0,0,22H,55H,55H,55H,33H,0	  ;a
 DB 44H,44H,66H,55H,55H,55H,66H,0 ;b
 DB 0,0,33H,44H,44H,44H,33H,0	  ;c
 DB 11H,11H,33H,55H,55H,55H,33H,0 ;d
 DB 0,0,22H,55H,77H,44H,77H,0	  ;e
 DB 22H,55H,44H,66H,44H,44H,44H,44H ;f
 DB 0,0,33H,55H,55H,33H,11H,66H	  ;g
 DB 44H,44H,66H,55H,55H,55H,55H,0 ;h
 DB 0,22H,0,22H,22H,22H,22H,0	  ;i
 DB 0,22H,0,22H,22H,22H,22H,66H	  ;j
 DB 44H,44H,55H,55H,66H,55H,55H,0 ;k
 DB 44H,44H,44H,44H,44H,55H,22H,0 ;l
 DB 0,0,55H,77H,55H,55H,55H,0	  ;m
 DB 0,0,22H,55H,55H,55H,55H,0	  ;n
 DB 0,0,22H,55H,55H,55H,22H,0	  ;o
 DB 0,0,22H,55H,55H,66H,44H,44H	  ;p
 DB 0,0,22H,55H,55H,33H,11H,11H	  ;q
 DB 0,0,66H,55H,44H,44H,44H,0	  ;r
 DB 0,0,21H,44H,22H,11H,66H,0	  ;s
	;^ s mit Fehler!!!
 DB 22H,22H,77H,22H,22H,22H,11H,0 ;t
 DB 0,0,55H,55H,55H,55H,77H,0	  ;u
 DB 0,0,55H,55H,55H,55H,22H,0	  ;v
 DB 0,0,55H,55H,77H,77H,55H,0	  ;w
 DB 0,0,55H,55H,22H,55H,55H,0	  ;x
 DB 0,0,55H,55H,55H,33H,11H,77H	  ;y
 DB 0,0,77H,11H,22H,44H,77H,0	  ;z
CCTL3X	;Geschweifte Klammern (amerik.)
 DB 33H,22H,22H,44H,22H,22H,33H,0 ;(*
 DB 22H,22H,22H,22H,22H,22H,22H,0 ;/*
 DB 66H,22H,22H,11H,22H,22H,66H,0 ;*)
 DB 77H,0,0,0,0,0,0,0		  ;^*
 DB 77H,77H,77H,77H,77H,77H,77H,77H ;CU
CCTL2X	;Umlaute (deutsch)
 DB 55H,22H,55H,55H,77H,55H,55H,0 ;[
 DB 55H,0,77H,55H,55H,55H,77H,0	  ;\
 DB 55H,0,55H,55H,55H,55H,77H,0	  ;]
 DB 0,55H,0,22H,55H,55H,33H,0	  ;{
 DB 0,55H,0,22H,55H,55H,22H,0	  ;|
 DB 0,55H,0,55H,55H,55H,77H,0	  ;}
 DB 22H,55H,55H,66H,55H,55H,66H,44H ;~
 
;Ende der Zeichenbildtabelle
;Beginn CTAB
;Aufbau: 1 Byte ASCII-Code
;	 1 Word Adresse
;12 Tripletts lang
CTAB
	DB	1
	DW	HOME
	DB	7
	DW	CRT2	;BEEP
	DB	8
	DW	CUL
	DB	0AH
	DW	CUD
	DB	0CH
	DW	PAGEPG	;CLS
	DB	0DH
	DW	CBL
	DB	14H
	DW	CLC
	DB	15H
	DW	CUR
	DB	16H
	DW	CLL
	DB	18H
	DW	CLLN
	DB	1AH
	DW	CUU
	DB	7FH
	DW	CLR
;Workspace
;L{nge 18 Bytes
WS
	DB 0	;ESC-Flag/ParamZ{hler
	DW ESCI	;ESC-Progr.-Zeiger
	DW WS+11;ESC-ParamZeiger
	DW SCRLPG ;WEND-Reaktion
	DB 0	;Cursor ein=0/aus<>0
	DB 0	;1920 ein=0/aus<>0
	DB 0	;Scroll ein=0/aus<>0
	DB 0	;KC85/3 ja=0/nein<>0
	DS 8,0	;ESC-Parameterliste
;ESC-Funktionstabelle
;Aufbau: 1 Byte Anzahl Parameter
;	 1 Word Adresse
;L{nge 37 Tripletts
 
ESCTAB
	DB	3
	DW	ESCA
	DB	3
	DW	ESCB
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JNZ	CUCP6
	JP	CUCP1
 
	ORG	RKC4OV2+$-CUCP2
RKC4OV3	ORG	CRT803
 
	;80-Zeichen-Ausgabe
	PUSH	BC
	POP	HL
	CALL	CUCP7
CRT84	PUSH	BC
	LD	A,(DE)
	AND	C
	LD	B,A
	LD	A,C
	CPL
	AND	M
	OR	B
	LD	M,A
	POP	BC
	INC	HL
	INC	DE
	DJNZ	CRT84
	JP	CUR
 
CUCP7	SRL	L
	LD	C,0F0H
	JR	NC,CUCP8
	LD	C,0FH
CUCP8	LD	A,80H
	ADD	L
	LD	B,H
	LD	H,A
	LD	A,B
	ADD	A
	ADD	A
	ADD	A
	ADD	B
	ADD	B
	ADD	8
	LD	L,A
	LD	B,8
	RET
 
	ORG	RKC4OV3+$-CRT803
RKC4OVE	;Ende Overlays
	DS	0F000H-$,0
 
;*********************
;*** Adresse F000h ***
;*********************
 
	DS	12H,0	;frei
	JP	DOSIN
CAOSMD	;Start CAOS-Betriebsart
	LD	HL,RFLPG
	LD	DE,FLPG
	LD	BC,RFILEIN-RFLPG
	LDIR		;bis NMI-Vektor
	LD	HL,RFILEIN
	LD	E,FILEIN;nach NMI-Vekt.
	LD	BC,ENDCM0-FILEIN
		;mit INITIAL.UUU
	LD	A,(0B781H)
	CP	2
	JR	C,FLCPY	;ohne..
	LD	BC,ENDCM1-FILEIN
FLCPY	LDIR
	JP	BACK
 
JPARG	CP	0FFH
	JR	Z,SELFT
	LD	HL,RSIOT
	LD	DE,SIOT
	LD	BC,100H
	LDIR
	LD	(SIOT+1),A
	JP	SIOINI
 
SELFT	LD	HL,RSWIT
	LD	BC,RBOOT-RSWIT
	LD	DE,SWIT
	LDIR
	JP	SWIT
 
;*************************
;** Folgender Programm- **
;** bereich Abarbeitung **
;** mit Modul als ROMC! **
;*************************
RSTEST	ORG	$-2000H
 
STEST	EI
	CALL	PV1
	DB	23H
	DB 'Version 2.0 (02/01/89)'
	DB	13,10,0
	LD	BC,0F4H
	LD	A,2	;RESET
	OUT	(C),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FC00H	;bzgl. D004!
KRP	;Koppelram-Programm
	DB	0,0	;zun{chst 2*NOP
KRP1	LD	HL,KRP
	LD	A,M
	INC	A
	LD	M,A
	CP	0FEH	;Kennbyte
	JR	NZ,KRP1
	;dRAM-Testprogramm }bertragen
	LD	HL,RDRP
	LD	DE,DRP
	LD	BC,RDRPE-RDRP+2	;2 mehr
	LDIR
	JP	DRP1
 
RDRP	ORG	0	;bzgl. D004!
DRP	;dRAM-Programm
	DB	0
DRP1	LD	HL,DRP
DRP2	INC	M	;bis 99h
	LD	A,M	;durchz{hlen
	LD	(KRP+1),A
	CP	99H	;Kennbyte
	JR	NZ,DRP2
	HALT		;Ende
 
	ORG	RDRP+$-DRP
RDRPE	;Koppelram-Adresse
	ORG	RKRP+$-KRP
	;ROMC-Adresse
	ORG	RSTEST+$-STEST
RSWIT	;ROME-Adresse
	ORG	0	;bzgl. D001!
SWIT	;schaltet D004-ROM auf C000h
	LD	BC,0FC80H
	LD	A,7
	OUT	(C),A
	IN	A,88H
	SET	0,A	;CAOS ein
	OUT	88H
	JP	STEST	;zum Selbsttest
SWITB	;zur R}ckkehr
	IN	A,88H
	SET	7,A	;BASIC ein
	OUT	88H	;(Fehler: auch
	RET		;am KC85/4!)
	;(RET i.a. zu LOOP)
	ORG	RSWIT+$-SWIT
RBOOT	;ROME-Adresse
	ORG	0FC00H	;bzgl. D004!
BOOT	;Urlade-Programm
 
;>>> HILFE, SPAGHETTI-TEUFEL!!! <<<
 
	LD SP,8000H	;mitten im RAM
	CALL FDINI
	LD B,12		;Leseversuche
NBOOT	;weiterer Versuch
	PUSH BC
	CALL FDRES	;Spur 0 usw.
	JR NZ,NTRDY	;Klappe offen..
	;oder Kopf in innerer Spur (!)
	LD HL,9000H	;Ziel
	LD BC,200H	;200H Bytes
	CALL FDRD	;lesen, Z=0:OK
	POP BC		;bei Fehlversuch
	JR NZ,NLOOP	;Format wechseln
	LD HL,(9000H)	;Kennung
	LD DE,'Y'*256+'S' ;'SY'
	AND A
	SBC HL,DE	;gleich?
	JR NZ,NOSYS	;kein System
	LD A,(9002H)	;3.Buchstabe
	CP 'S'
	LD A,5		;CAOS-Diskette
	JR NZ,TUROK	;wenn 'SYx'
	LD A,1		;PC, wenn 'SYS'
TUROK	LD (0FFB3H),A	;>UROK<
	JP 09004H	;Eigentlichen
		;Bootvorgang starten!
 
NOSYS	;No System eintragen
	LD A,4
FUROK	;>UROK< eintragen und Stop
	LD (0FFB3H),A	;>UROK<
	XOR A
	OUT 0F6H,A
	HALT		;Ende
 
NTRDY	;Not Ready eintragen
	POP BC
	LD A,2
	JR FUROK
 
BOBY1	DW LISTE1	;1. Sequenz
BOBY2	DW LISTE2	;2. Sequenz
NLOOP	;Neuer Schleifendurchlauf,
	;vorher Tausch von BOBY1 u. '2
	LD HL,(BOBY1)
	LD DE,(BOBY2)
	LD (CMDT0+1),HL	;Modifizierung
	LD (BOBY1),DE	;des Codes
	LD (BOBY2),HL	;(grausam!)
	DJNZ NBOOT	;12 Versuche
	LD A,3		;Can't Read
	JR FUROK	;eintragen
 
;** 0F0H: HSR-Hauptstatusregister
;** Bit 6: Datenrichtung: 1=zur CPU
;** Bit 7: Fertigmeldung: 1=fertig
;** 0F1h: Kommando- bzw. Resultatreg.
 
FDINI	;FDC initialisieren
	LD B,0
FDIW	DJNZ FDIW	;etwas warten
	IN A,0F0H
	CP 80H		;fertig?
	JR Z,FDI1	;ja
	AND 0FH		;eine Floppy
			;aktiv? (0..3)
	CALL NZ,FDI2
	IN A,0F1H	;Resultat holen
	JR FDINI	;und ignorieren
 
BOBY3	DB 9FH,14H
 
FDI1	LD HL,BOBY3
	LD BC,303H	;Bytes 03,9F,14
	JR CMDPH	;Kommandophase
 
FDRES	;Spur 0 anfahren
	LD A,21H	;Drive 0 aktiv
	OUT 0F6H,A
	LD BC,0		;65536 Zyklen
FDRES1	IN A,0F4H
	BIT 5,A
	JR NZ,FDRES2	;LW bereit
	DEC BC
	LD A,B
	OR C
	JR NZ,FDRES1
	INC A		;A=1,Z=0,Fehler
	RET	;(Neuer Versuch)
 
FDRES2	;Kopf zur Spur 0 befehlen
	LD BC,207H
	CALL CMDT0	;Bytes 07,00
		;(00 f}r Laufwerk 0!)
FDI2	IN A,0F0H	;HSR
	AND 1FH	;Keine Floppy aktiv
		;und kein Kommando?
	RET Z		;ja, Z=1:OK
FDRES3	IN A,0F4H
	BIT 6,A
	JR NZ,FDRES3
	LD BC,108H	;Byte 08: Pr}fe
			;Interruptstatus
	CALL CMDPH	;Kommando
	CALL RESULT	;1. Resultat
	LD B,A		;merken
	ADD A		;A=x0000000?
	RET Z		;ja, OK
	CALL RESULT	;2. Resultat
	LD A,B		;ignorieren
	AND 0F0H	;A=1100xxxx?
	CP 0C0H
	JR Z,FDRES3	;ja,wiederholen
	XOR 20H
	RET	;A=0010xxxx-> Z=1: OK
 
CMDT0	;Kommando nach Tabelle
	;abarbeiten, 1. Byte und
	;Anzahl in BC
	LD HL,LISTE1	;auch LISTE2,
	;		;s.o.!!
CMDPH	;Kommandophase
	;PE: B: Anzahl der Bytes
	;    C: 1. Byte
	;   HL: Adresse weiterer Bytes
	IN A,0F0H	;HSR
	AND 0C0H	;=10xxxxxx?
	CP 80H
	JR NZ,CMDPH	;nicht fertig
	LD A,C
	OUT 0F1H,A	;Kommandobyte
	LD C,M		;n{chstes -"-
	INC HL		;Tabellenzeiger
	DJNZ CMDPH	;B-mal
	RET
 
RESULT	;1 Resultat abholen
	;(bei Resultatphase)
	;PA: A: Resultat
	IN A,0F0H	;HSR
	AND 0C0H	;=11xxxxxx?
	CP 0C0H
	JR NZ,RESULT	;nicht bereit
	IN A,0F1H	;das Resultat
	RET
 
FDRD	;Sektorlesen
	PUSH BC		;BC war 200H
	PUSH HL
	LD BC,946H	;9 Bytes
	;46H bedeutet: Lesen MFM
	CALL CMDT0	;Sektor(en)lesen
	POP HL
	POP DE		;was BC war
	LD B,E		;war 0
	LD C,0F2H	;DMA-Adresse
	CALL RDSECT	;Lesen 512 Bytes
	LD B,7		;7 Resultate
	LD HL,LISTE4	;Resultatliste
FDRD1	CALL RESULT
	LD M,A		;Resultate
	INC HL		;einsammeln
	DJNZ FDRD1
	LD A,(LISTE4)	;ST0 interessant
	AND 0C0H	;A=00xxxxxx?
	RET		;ja->Z=1
 
RDSECT	;Sektor (hier 512 Bytes) lesen
	IN A,0F4H
	ADD A		;wenn x0xxxxxx
	RET P		;zu fr}h fertig
	JR C,RDSECT	;wenn 11xxxxxx
	INI		;1 Byte
	JR NZ,RDSECT	;wenn B<>0
	DEC D
	JR NZ,RDSECT	;2mal
	OUT 0F8H,A	;A=01xxxxxx
	RET
 
LISTE2	;Format 2 (PC1715-780K)
	DB 0	;Laufwerk 0
	DB 0	;Spur 0
	DB 0	;Kopf 0
	DB 1	;Erster Cluster
	DB 1	;Letzter Cluster
	DB 10H	;L{nge der L}cke
	DB 0EH	;Datenblockl{nge
	DB 0FFH	;??
;Freier Bereich, k|nnte f}r LISTE3
;reserviert worden sein
	DS 8,0
LISTE1	;Format 1 (kleinere L}cken)
	DB 0,0,0,1,3,5,0EH,0FFH
LISTE4	;Resultatliste
 
	ORG	RBOOT+$-BOOT
RERRM	ORG	0
ERRM	;Fehlermitteilungen
	LD	B,A
	IN	A,88H
	SET	0,A	;CAOS ein
	OUT	88H
	EI
	LD	A,B
	CP	2
	JR	NZ,ERRM1
	CALL	PV1
	DB 23H,'Not ready  ',0
	JR	ERRME
	;
ERRM1	CP	3
	JR	NZ,ERRM2
	CALL	PV1
	DB 23H,'Cannot read ',0
	JR	ERRME
	;
ERRM2	CP	4
	JR	NZ,ERRM3
	CALL	PV1
	DB 23H,'No System ',0
	JR	ERRME
	;
ERRM3	CALL	PV1
	DB	1CH
ERRME	CALL	PV1
	DB	19H	;ERRM
	RET
 
	ORG	RERRM+$-ERRM
RV24I	ORG	200H
 
V24INI	JR	V24I1
PRINT	JR	PRINT1
 
V24IT	DB	47H,2EH		;F}r CTC
	DB 18H,4,44H,3,20H,5,6AH;F}r SIO
 
V24I1	LD	BC,880H
V24I2	IN	A,(C)
	CP	0EEH	;M003/M053?
	JR	Z,V24I3	;Endlich!!
	INC	B	;Alle Sch{chte
	JR	NZ,V24I2;absuchen
	RET
V24I3	;V24-Modul gefunden
	LD	L,B
	LD	A,2
	LD	D,1
	LD	E,D	;V24-Modul
	CALL	PV1	;einschalten
	DB	26H	;MODU
	LD	C,0CH
	LD	B,2
	LD	HL,204H
	DI
	OTIR		;F}r CTC
	LD	C,0AH
	LD	B,7
	OTIR		;F}r SIO
	RET		;Kein EI?
	;
PRINT1	PUSH	AF
PRINT2	IN	A,0AH
	BIT	2,A	;Puffer frei?
	JR	Z,PRINT2
	POP	AF
	OUT	8,A	;Ausgabe
	RET
 
	ORG	RV24I+$-V24INI
RV24D	ORG	380H
 
V24DUP	JR	V24D1
V24OT	JR	V24D2
V24IN	JR	V24D6
 
V24DT	DB	47H,2EH		  ;CTC
	DB 18H,4,44H,3,0E1H,5,6AH ;SIO
 
V24D1	LD	C,0DH
	LD	B,2
	LD	HL,V24DT
	OTIR		;CTC rechts
	LD	C,0BH
	LD	B,7	;SIO rechts
	OTIR
	RET
 
V24D2	;Ausgabe
	PUSH	AF
V24D3	IN	A,0BH
	BIT	2,A
	JR	Z,V24D5
	POP	AF
V24D4	OUT	9,A	;Ausgabe
	RET
 
V24D5	LD	A,(IX+13)
	CP	3	;Break?
	JR	NZ,V24D3
	POP	AF
	LD	A,1AH	;^Z = EOF
	JR	V24D4	;liefern
 
V24D6	;Eingabe
	IN	A,0BH
	BIT	0,A
	JR	NZ,V24D8
	LD	A,5
	OUT	0BH,A
	LD	A,0EAH
	OUT	0BH,A
V24D7	IN	A,0BH
	BIT	0,A
	JR	Z,V24D9
V24D8	IN	A,9
	JR	V24D10
 
V24D9	LD	A,(IX+13)
	AND	0EFH
	CP	3	;Break/Stop?
	JR	NZ,V24D7
	LD	A,1AH	;^Z = EOF
V24D10	PUSH	AF
	LD	A,5
	OUT	0BH,A
	LD	A,6AH
	OUT	0BH,A
	POP	AF
	RET
 
	ORG	RV24D+$-V24DUP
RSIOT	ORG	0BC00H
SIOT	;SIO-CTC-Tabelle
	DB	47H,0	;0 zum Modifi-
			;zieren	 ;CTC
	DB 18H,4,44H,3,0C1H,5,6AH;SIO
SIOINI	;Init
	EI
	IN	A,88H
	SET	0,A	;CAOS ein
	OUT	88H,A
	LD	BC,880H
SIOT1	IN	A,(C)
	CP	0EEH	;M003/M053?
	JR	Z,SIOT2
	INC	B
	JR	NZ,SIOT1
	CALL	PV1
	DB	19H	;Fehlermeldung
	RET
	;
SIOT2	LD	A,2
	LD	L,B
	LD	D,1
	LD	E,D
	CALL	PV1	;V24-Modul
	DB	26H	;einschalten
	IN	A,9	;SIO
	IN	A,9	;ausr{umen
	IN	A,9
	IN	A,9
	LD	HL,SIOT
	LD	BC,20DH
	OTIR
	LD	BC,70BH
	OTIR
	LD	HL,SIOTO
	LD	(0B7C1H),HL ;USER-IN#2
	LD	HL,SIOTI
	LD	(0B7C4H),HL ;USER-OUT#3
 
;Irgendwie ham' die was verwechselt!
;>> ICH GLAUB', ICH SPINNE! <<
 
	CALL	SIOTI
	RET	C	;CY=1: Abbruch
	LD	L,A
	CALL	SIOTI
	RET	C
	LD	H,A	;HL=AAdr
	CALL	SIOTI
	RET	C
	LD	C,A
	CALL	SIOTI
	RET	C
	LD	B,A	;BC=L{nge
	CALL	SIOTI
	RET	C
	LD	E,A
	CALL	SIOTI
	RET	C
	LD	D,A	;DE=SAdr
	PUSH	DE
SIOT3	CALL	SIOTI
	RET	C	;Ansprung (DE)
;Der Computer tut das, was man program-
;miert, NICHT das, was man will!
;(BRK - der sichere Absturz...)
	LD	M,A
	INC	HL
	DEC	BC	;mitz{hlen
	LD	A,B
	OR	C
	JR	NZ,SIOT3
	RET		;Ansprung (DE)
 
SIOTO	;Ausgabe
	PUSH	AF
SIOT4	IN	A,0BH
	BIT	2,A
	JR	NZ,SIOT6
	POP	AF
SIOT5	OUT	9,A
	RET
	;
SIOT6	LD	A,(IX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ADD	HL,BC
	POP	AF
	JR	C,ENDADR
	EX	(SP),HL
	ADD	HL,BC
	EX	(SP),HL
ENDADR	EX	DE,HL
	ADD	HL,BC
	EX	DE,HL
	PUSH	AF
RDSEC	POP	AF
RDSEC1	LD	A,1
	LD	BC,80F3H
	OUT	(C),A
WTSEC	IN	A,(C)
	RRCA
	JR	C,WTSEC
	BIT	6,A
	JR	Z,DATAIN
RDERRN	INC	B
	IN	A,(C)
	CALL	PV1
	DB	1CH
RDERR	CALL	PV1
	DB	19H
	LD	HL,(0B797H)
	JP	(HL)
	;
DATAIN	DEC	C
DATIN1	INI
	INC	B
	INC	B
	PUSH	HL
	SBC	HL,DE
	POP	HL
	RET	NC
	LD	A,B
	AND	A
	JR	NZ,DATIN1
	JR	RDSEC1
	;
BACK	IN	A,88H
	OR	1	;CAOS ein
	OUT	88H,A
	LD	A,(0B781H)
	CP	2
	JP	NC,RESET
ENDCM1	;Ende bei JUMP FC mit Parameter
	LD	A,(0E011H)
	CP	7FH
	JR	Z,NOTC31
	IN	A,88H
	OR	80H	;BASIC ein
	OUT	88H,A
NOTC31	LD	L,46H
WFRDE	LD	BC,80F3H
	IN	A,(C)
	CP	48H
	JR	Z,AEXEC
	CP	0C8H
	JR	Z,FLEND
	LD	A,11H
	CALL	PV1
	DB	14H
	DEC	L
	JR	NZ,WFRDE
FLEND	JP	RESET
	;
AEXEC	LD	HL,0B700H
	LD	BC,80F2H
AE1	IN	A,(C)
	LD	M,A
	INC	L
	INC	B
	JR	NZ,AE1
	LD	L,B
	LD	(0B7D1H),HL
	SET	6,(IX+8)
	CALL	PV1
	DB	23H,0CH,13,10,0
	CALL	PV1
	DB	12H	;LOOP
ENDCM0	;Ende bei JUMP FC ohne Param.
 
	ORG	RFILEIN+$-FILEIN
;Programmschrott, von Diskette her-
;r}hrend (Ende=FC80h, Kopie von F5BC!)
	LD	A,C
	IN	A,(C)
	RRCA
	JR	C,$-3
	BIT	6,A
	JR	Z,$+17
	INC	B
	IN	A,(C)
	CALL	PV1
	DB	1CH
	CALL	PV1
	DB	19H
	LD	HL,(0B797H)
	JP	(HL)
	DEC	C
	INI
	INC	B
	INC	B
	PUSH	HL
	SBC	HL,DE
	POP	HL
	RET	NC
	LD	A,B
	AND	A
	JR	NZ,$-11
	JR	$-45
	IN	A,88H
	OR	1
	OUT	88H,A
	LD	A,(0B781H)
	CP	2
	JP	NC,0E000H
	LD	A,(0E011H)
	CP	7FH
	JR	Z,$+8
	IN	A,88H
	OR	80H
	OUT	88H
	;Freier ROM-Speicher
	DS	0FFFEH-$,0FFH
	DW	23FFH	;Pr}fsumme ROM
 
	END
À@Àt(Àp6ÀnTop of Text: End of Text: Start of MC: ASM-OffM-Speicher
	DS	0FFFEH-$,0FFH
	DW	23FFH	;Pr}fsumme ROM
 
	END
À@Àt(Àp6ÀnTop of Text: End of Text: Start of MC: ASM-Off