EDITORASM;
;	Maschinencode-Editor
;
	ORG	0BA00H
;
;---------------------------------------
ARGN	EQU	0B781H
ARG1	EQU	0B782H
ARG2	EQU	0B784H
ARG3	EQU	0B786H
ARG4	EQU	0B788H
ARG5	EQU	0B78AH
ARG6	EQU	0B78CH
NUMVX	EQU	0B797H
WINON	EQU	0B79CH
WINLG	EQU	0B79EH
CURSO	EQU	0B7A0H
STBT	EQU	0B7A2H
COLOR	EQU	0B7A3H
PV1	EQU	0F003H
CRT	EQU	0
KBD	EQU	4
RHEX	EQU	18H
HLHX	EQU	1AH
AHEX	EQU	1CH
OSTR	EQU	23H
SPACE	EQU	2BH
;-------
;Wandlung ASCII --> Hex-Zahl:
;
HEXA:	LD	B,A
	SUB	30H
	JP	M,HEX1
	SUB	0AH
	RET	M
	SUB	7
	JP	M,HEX1
	SUB	6
	RET	M
HEX1:	LD	B,0
	RET
;-------
;Display 8 Zeilen, 8 Spalten:
;PE:	(ARG4)	Adresse
;	(ARG3)	max. Adresse
;PA:	(ARG4)	Adresse nach Display
;VR:	AF,HL,DE
;
DISPL:	PUSH	BC
	LD	HL,(ARG4)	;Adr
	LD	DE,(ARG3)
	AND	A
	SBC	HL,DE
	JP	M,DISP1
	LD	(ARG4),DE	;Adr neu
	JP	DISP2
DISP1:	LD	HL,(ARG4)
	LD	BC,38H
	ADD	HL,BC
	AND	A
	SBC	HL,DE
	JP	P,DISP2
	EX	DE,HL
	AND	A
	SBC	HL,BC
	LD	(ARG4),HL	;Adr neu
DISP2:	LD	HL,(ARG4)
	LD	DE,0400H
	LD	(CURSO),DE
	LD	A,8	;8 Zeilen
DISP3:	PUSH	AF
	PUSH	HL
	LD	DE,(ARG3)
	LD	A,20H
	AND	A
	SBC	HL,DE
	JR	NZ,DISP4
	LD	A,28H
DISP4:	LD	(COLOR),A
	POP	HL
	CALL	PV1
	DEFB	HLHX	;Adresse
	PUSH	HL
	LD	A,8	;8 Bytes
	PUSH	AF
DISP5:	PUSH	AF
	LD	A,M
	CALL	PV1
	DEFB	AHEX	;Byte
	CALL	PV1
	DEFB	SPACE
	INC	HL
	POP	AF
	DEC	A
	JR	NZ,DISP5
	LD	HL,STBT
	SET	3,M
	POP	AF
	POP	DE
DISP6:	PUSH	AF
	LD	A,(DE)
	CALL	PV1
	DEFB	CRT	;Zeichen
	INC	DE
	POP	AF
	DEC	A
	JR	NZ,DISP6
	RES	3,M
	EX	DE,HL
	CALL	PV1
	DEFB	OSTR
	DEFB	0AH
	DEFB	19H
	DEFB	0AH
	DEFB	0
	POP	AF
	DEC	A
	JP	NZ,DISP3
	POP	BC
	RET
;-------
;Anzeige einer Display-Zeile ohne Summe:
;
DINS:	PUSH	AF
	LD	HL,1500H
	LD	(CURSO),HL
	LD	A,28H
	LD	(COLOR),A
	LD	HL,(ARG3)
	CALL	PV1
	DEFB	HLHX	;Adresse
	LD	A,8
DINS1:	PUSH	AF
	LD	A,M
	CALL	PV1
	DEFB	AHEX
	CALL	PV1
	DEFB	SPACE
	INC	HL
	POP	AF
	DEC	A
	JR	NZ,DINS1
	CALL	PV1
	DEFB	OSTR
	DEFM	'    '
	DEFB	0
	POP	AF
	RET
;-------
;Anzeige einer Display-Zeile mit Summe:
;
DSUM:	LD	A,20H
DSUM1:	LD	(COLOR),A
	LD	HL,1500H
	LD	(CURSO),HL
	LD	HL,(ARG3)
	CALL	PV1
	DEFB	HLHX	;Adresse
	LD	DE,0
	LD	BC,0
	LD	A,8	;8 Bytes
DSUM2:	PUSH	AF
	LD	A,M
	CALL	PV1
	DEFB	AHEX	;Byte
	CALL	PV1
	DEFB	SPACE
	LD	C,M
	EX	DE,HL
	ADD	HL,BC	;summieren
	EX	DE,HL
	INC	HL
	POP	AF
	DEC	A
	JR	NZ,DSUM2
	EX	DE,HL
	CALL	PV1
	DEFB	HLHX	;Summe
	RET
;-------
;Adressenvergleich (ARG1/ARG3)
;
VERGL1:	LD	HL,(ARG3)
VERGL2:	LD	DE,(ARG1)
VERGL3:	AND	A
	SBC	HL,DE
	RET
;-------
;Adressenvergleich (ARG2/ARG3)
;
VERGL4:	LD	HL,(ARG2)
	LD	DE,(ARG3)
	JR	VERGL3
;-------
;Adresse 8 kleiner:
;
MINU8:	LD	HL,(ARG3)
	LD	A,8
MIN8:	DEC	HL
	DEC	A
	JR	NZ,MIN8
	LD	(ARG3),HL
	CALL	DISPL
	RET
;-------
;Adresse 8 gr|~er:
;
PLUS8:	LD	HL,(ARG3)
	LD	A,8
PLU8:	INC	HL
	DEC	A
	JR	NZ,PLU8
	LD	(ARG3),HL
	CALL	DISPL
	RET
;-------
;Aktualisieren der Cursorposition:
;
CUAKT:	LD	A,(CURSO)
	CP	1CH
	RET	NZ
	CALL	PLUS8
	CALL	DINS
	LD	A,5
	LD	(CURSO),A
	RET
;-------
DCUR:	CALL	DINS
	LD	HL,1505H
	LD	(CURSO),HL
	JP	MKEY
;-------
DCUU:	CALL	VERGL1
	CALL	NZ,MINU8
	CALL	DSUM
	JP	DKEY
;-------
DCUL:	CALL	DINS
	LD	HL,151AH
	LD	(CURSO),HL
	JP	MKEY
;-------
MCUL:	CALL	CUAKT
	LD	A,(CURSO)
	CP	5
	JR	Z,MCUL1
	CALL	DINS
	SUB	3
	LD	(CURSO),A
	JP	MKEY
MCUL1:	CALL	VERGL1
	JP	Z,MENT
	CALL	MINU8
	JP	DCUL
;-------
MCUR:	CALL	CUAKT
	LD	A,(CURSO)
MCUR1:	CP	1AH
	JR	Z,MCUR2
	CALL	DINS
	ADD	3
	LD	(CURSO),A
	JP	MKEY
MCUR2:	CALL	VERGL4
	JP	Z,MENT
	LD	A,28H
	CALL	DSUM1
	LD	HL,151CH
	LD	(CURSO),HL
	JP	MKEY
;-------
DCUD:	CALL	VERGL4
	CALL	NZ,PLUS8
;-------
;Zum Display-Modus:
;
MENT:	CALL	DSUM
	LD	HL,1504H
	LD	(CURSO),HL
	JP	DKEY
;-------
MODIF:	CALL	CUAKT
	LD	A,B
	CALL	PV1
	DEFB	CRT	;1. Zeichen
	LD	(ARG5),A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HLHX
	CALL	PV1
	DEFB	OSTR
	DEFM	'>>'
	DEFB	0
	LD	HL,021EH
	LD	(CURSO),HL
	CALL	PV1
	DEFB	OSTR
	DEFM	'<< '
	DEFB	0
	LD	HL,(ARG2)	;Eadr
	CALL	PV1
	DEFB	HLHX
	CALL	DISPL	;Disp-Seite
	CALL	DSUM	;Zeile m. Summe
;Tastaturabfrage im Display-Modus:
DKEY:	LD	HL,1504H
	LD	(CURSO),HL
	CALL	PV1
	DEFB	KBD
	CP	0BH		;CUU
	JP	Z,DCUU
	CP	0AH		;CUD
	JP	Z,DCUD
	CP	9		;CUR
	JP	Z,DCUR
	CP	8		;CUL
	JP	Z,DCUL
	CP	3		;BRK
	CALL	Z,0E000H
	CALL	HEXA
	LD	A,B
	INC	A
	DEC	A
	JP	NZ,NADR	;neue Adresse
	JP	DKEY	;keine HEX-Zahl
;-------
;Tastaturabfrage im Modify-Modus:
MKEY:	CALL	PV1
	DEFB	KBD
	LD	B,A
	CP	9		;CUR
	JP	Z,MCUR
	CP	8		;CUL
	JP	Z,MCUL
	CP	1AH		;INS
	JP	Z,MINS
	CP	1FH		;DEL
	JP	Z,MDEL
	CP	0DH		;ENT
	JP	Z,MENT
	SUB	20H
	JP	M,MKEY
	JP	MODIF
;-------
jÿÿÿÿÿÿÿÿÿÿ