exp.asm
flypie_Ace-2019/testrom/exp.asm
	INCLUDE "IODEFS.H"
		  
	INCLUDE "SYSVARS.H"

	INCLUDE "DEBUGMACROS.H"

	PUBLIC 	UNDEFINT0,UNDEFINT1,UNDEFINT2,UNDEFINT3,UNDEFINT4,UNDEFINT5,UNDEFINT6,UNDEFINT7

	EXTERN 	INTTABLEBASE,DATAOUTA,ENDFONTDATA
	EXTERN 	INTTBL
	EXTERN 	LOADCROM
	EXTERN	SIOTOTXBUFFB,SIORCVCHARB
	EXTERN	INCSYSCLOCK

	EXTERN	QUEUETEST,InitQueue, TxQB2Scr
	EXTERN KIO_INIT

	
	CPU = Z180

INTON	EQU 10000000B
INTOFF	EQU ~INTON

COUNTMODE	EQU 01000000B
TIMEMODE	EQU ~COUNTMODE

PRE256	EQU 00100000B
PRE16	EQU ~PRE256

RISING	EQU 00010000B
FALLING	EQU ~RISING

PULSESTARTS	EQU 00001000B
LOADSTARTS	EQU ~PULSESTARTS

TIMECONST	EQU 00000100B
NOTIMECONST	EQU ~TIMECONST

RESET		EQU 00000010B
CONSTINU	EQU ~RESET

CONTROL		EQU 00000001B
VCTOR		EQU ~CONTROL


	SEGMENT BOOT ; MAKE IT THE CURRENT SECTION
;	.ORG 00H

	DI
	JP MAIN

	SEGMENT CODE ; MAKE IT THE CURRENT SECTION
MAIN:
	LD		SP,7FFF
;	CALL TEST1

RAMTOPSEARCH:  
	LD		HL,RAMSTARTLOC			; START OF 'USER' RAM
RAMTOPLOOP
	INC		H						; INCREASE HIGH BYTE
	LD		A,000H					; A TEST BYTE AND 1K MASKING BYTE.
	CP		H
	JR		Z,RAMTOPLOOPEXIT		; LOOP BACK WHILE RAM IS POPULATED.
	LD		A,0FCH					; A TEST BYTE AND 1K MASKING BYTE.
	LD		(HL),A					; INSERT A VALUE
	CP		(HL)					; COMPARE TO EXPECTED
	JR		Z,RAMTOPLOOP			; LOOP BACK WHILE RAM IS POPULATED.
RAMTOPLOOPEXIT:
	DEC		HL
	DEC		HL						;MAKE IT EVEN.
	LD		HL,7FFEH
	LD		(RAMTOP),HL					; SET SYSTEM VARIABLE RAMTOP.
	LD		SP,HL					; INITIALIZE THE STACK POINTER.

	;CLEAR SCREEN TO X.

	LD HL,VIDSTARTLOC
	LD C,SCRLINES
SCRY:
	LD B,SCRWIDTH
SCRX:
	LD (HL),'X'

	INC HL
	DJNZ SCRX
	DEC C
	JR NZ,SCRY

	CALL LOADCROM

	CALL	InitQueue

;	JP	QUEUETEST

	SP2SCR	02H, 0
	SP2SCR	02H, 1
	SP2SCR	02H, 2
	
	STROUTXY 8,0, "V 005", 5 

	STROUTXY 15h,1, "RST08", 5 
	STROUTXY 15h,2, "RST10", 5 
	STROUTXY 15h,3, "RST18", 5 
	STROUTXY 15h,4, "RST20", 5 
	STROUTXY 15h,5, "RST28", 5 
	STROUTXY 15h,6, "RST30", 5 
	STROUTXY 15h,7, "RST38", 5 
	STROUTXY 15h,8, "RST66", 5 

	STROUTXY 15H,9, "     ", 5 

	STROUTXY 10H,0, "01234567", 8 

INTMOD2 EQU 1

	.IFDEF INTMOD2
	LD	HL,INTTBL
	LD	A,H
	LD	I,A
 
	HOUT 2550H,H 

	IM	2
	.ELSE
	IM	1
	.ENDIF

	CALL 	KIO_INIT

	LD HL,SYSCLOCK
	LD (HL),0
	INC HL
	LD (HL),0
	INC HL
	LD (HL),0
	INC HL
	LD (HL),0

	EI

TESTPAT EQU 0FFH

	LD  HL,LOOPCOUNT
	LD	(HL),0FDH
	INC HL
	LD	(HL),0FH
	LD  HL,LOOPCOUNT2
	LD	(HL),20h
	
	LD	D,0
NOPER:
	LD  HL,LOOPCOUNT
	DEC (HL)
	LD	A,(HL)
	CP	0FFh
	JR	NZ,NOC1
	INC HL
	DEC (HL)
NOC1:
	LD  HL,LOOPCOUNT
	LD	C,(HL)
	INC HL
	LD	B,(HL)

	LD  A,0
	CP B
	JR NZ,SKIP
	CP C
	JR NZ,SKIP

	LD HL,VIDSTARTLOC
	INC (HL)

	QUADOUT 18h,0, SYSCLOCK

	CALL DATAOUTA

	ld		e,22
	CALL TxQB2Scr
	CALL SIORCVCHARB
	CP 	1
	JP	NZ,NOCHARIN

	LD	HL,KeyB
	LD	a,(KeyBWritePos)
	ADD	L
	LD	L,a
	LD	(HL),c
	LD	a,(KeyBWritePos)
	inc	a
	and	1Fh
	ld	(KeyBWritePos),a

NOCHARIN:

	XY2SCR	0, 017h
	push	ix
	pop		de
	ld		bc,BufferSize*2
	ld		hl,KeyB
	LDIR
;	COUTXY 0, 20 , C

	LD  HL,LOOPCOUNT2
	DEC (HL)
	LD	A,(HL)

	HOUT 	25BEH, (HL)

	CP	0
	jr nz,NOGO

	LD	(HL),20h

	ld	A,0Dh
	call SIOTOTXBUFFB
	ld	A,0Ah
	call SIOTOTXBUFFB
	ld	A,'A'
	call SIOTOTXBUFFB
	ld	A,'B'
	call SIOTOTXBUFFB
	ld	A,'C'
	call SIOTOTXBUFFB
	ld	A,'D'
	call SIOTOTXBUFFB
	ld	A,'E'
	call SIOTOTXBUFFB
NOGO:

	.ifdef TESTINT
	LD	A,I
    JP PE,INTEN  
   	STROUTXY 0h,17H, "INT D", 5 
	JR IQDONE
INTEN:
	STROUTXY 0h,17H, "INT E", 5 
IQDONE:
	.endif

	LD HL,4800H
	LD A,TESTPAT
	LD (HL),A
	NOP
	LD A,(HL)
	CP TESTPAT
	JR NZ,ERR
	LD C,A
	HOUT VIDSTARTLOC+65H,C 
	STROUTXY 02h,03H, "OK ", 3 
	LD  HL,LOOPCOUNT
	LD	(HL),0FEH
	INC HL
	LD	(HL),0FH
	LD	D,0
	JR SKIP
ERR:
	LD C,A
	HOUT VIDSTARTLOC+85H, C 
	STROUTXY 02h,03H, "NOK", 3 
	LD  HL,LOOPCOUNT
	LD	(HL),0FEH
	INC HL
	LD	(HL),0FH
	LD	D,0
	SKIP:
	JR NOPER

UNDEFINT0:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+10H

	LD A,080H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT0", 9 
	
	POP HL
	POP	AF
	EI
	RETI

UNDEFINT1:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+11H

	LD A,080H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT1", 9 
	
	POP HL
	POP	AF
	EI
	RETI

UNDEFINT2:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+12H

	LD A,80H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT2", 9 
	POP HL
	POP	AF
	EI
	RETI


UNDEFINT3:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+13H

	LD A,80H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT3", 9 
	POP HL
	POP	AF
	EI
	RETI

UNDEFINT4:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+14H

	LD A,080H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT4", 9 
	POP HL
	POP	AF
	EI
	RETI

UNDEFINT5:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+15H

	LD A,080H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT5", 9 
	POP HL
	POP	AF
	EI
	RETI

UNDEFINT6:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+16H

	LD A,80H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT6", 9 
	POP HL
	POP	AF
	EI
	RETI


UNDEFINT7:
	PUSH	AF
	PUSH HL
	LD HL,VIDSTARTLOC+17H

	LD A,80H
	XOR (HL)
	LD (HL),A

	STROUTXY 10H,0Ch, "UNDEFINT7", 9 
	POP HL
	POP	AF
	EI
	RETI

RST08HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+3BH,B 
	HOUT VIDSTARTLOC+3DH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+30H
	INC (HL)
	STROUTXY 15H,09H, "RST08", 5 
	POP HL
	RET

RST10HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+5BH,B 
	HOUT VIDSTARTLOC+5DH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+50H
	INC (HL)
	STROUTXY 15H,09H, "RST10", 5 
	POP HL
	RET

RST18HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+7BH,B 
	HOUT VIDSTARTLOC+7DH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+70H
	INC (HL)
	STROUTXY 15H,09H, "RST18", 5 
	POP HL
	RET

RST20HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+9BH,B 
	HOUT VIDSTARTLOC+9DH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+90H
	INC (HL)
	STROUTXY 15H,09H, "RST20", 5 
	POP HL
	RET

RST28HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+0BBH,B 
	HOUT VIDSTARTLOC+0BDH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+0B0H
	INC (HL)
	STROUTXY 15H,09H, "RST28", 5 
	POP HL
	RET

RST30HANDLER:
	POP		BC
	PUSH	BC

	HOUT VIDSTARTLOC+0DBH,B 
	HOUT VIDSTARTLOC+0DDH,C 

	PUSH HL
	LD HL,VIDSTARTLOC+0D0H
	INC (HL)
	STROUTXY 15H,09H, "RST30", 5 
	POP HL
	RET

RST38HANDLER:
	POP		BC
	PUSH	BC

	SP2SCR 015H, 0CH

	PUSH HL

	HOUT VIDSTARTLOC+0FBH,B 
	HOUT VIDSTARTLOC+0FDH,C 
	
	LD HL,VIDSTARTLOC+0F0H
	INC (HL)
	STROUTXY 15H,09H, "RST38", 5 

;	HALT

	POP HL
	RET
	
RST66HANDLER:
	POP		BC
	PUSH	BC

	HOUT 251BH,B 
	HOUT 251DH,C 

	PUSH HL
	LD HL,2510H
	INC (HL)
	STROUTXY 15H,09H, "RST66", 5 
	POP HL
	RETN

	SEGMENT RST08SEG ; MAKE IT THE CURRENT SECTION

RST08:
;	...	INTERRUPT	ROUTINE
	JP RST08HANDLER
	
	SEGMENT RST10SEG ; MAKE IT THE CURRENT SECTION

RST10:
;	...	INTERRUPT	ROUTINE
	JP RST10HANDLER
	
	SEGMENT RST18SEG ; MAKE IT THE CURRENT SECTION

RST18:
;	...	INTERRUPT	ROUTINE
	JP RST18HANDLER
	
	SEGMENT RST20SEG ; MAKE IT THE CURRENT SECTION

RST020:
;	...	INTERRUPT	ROUTINE
	JP RST20HANDLER

	SEGMENT RST28SEG ; MAKE IT THE CURRENT SECTION

RST28:
;	...	INTERRUPT	ROUTINE
	JP RST28HANDLER

	SEGMENT RST30SEG ; MAKE IT THE CURRENT SECTION

RST30:
;	...	INTERRUPT	ROUTINE
	JP RST30HANDLER
	
	SEGMENT RST38SEG ; MAKE IT THE CURRENT SECTION

RST38:
;	...	INTERRUPT	ROUTINE
	JP RST38HANDLER
	
	SEGMENT RST66SEG ; MAKE IT THE CURRENT SECTION

RST66:
;	...	INTERRUPT	ROUTINE
	JP RST66HANDLER
.END

