
;Warning! this assembler is case sensitive.


#include "\SrcAll\v1_Header.asm"
	
	Jp TestZ80Mode
	
	;jp TestInstructionMemoryModesFull
	;jp TestInstructionMemoryModesHalf1
	;jp TestInstructionMemoryModesHalf2
	
TestZ80Mode:
	di	;Need to disable interrupts before messing with MB
	
;STMIX enables Mixed mode (03/02 pushed)
;RSMIX turns it off		  (01/00 pushed)
	
	
	stmix			;Need to use STMIX before using legacy code!
	 
	
	ld   a,$d1 		;Top byte of address in 8 bit mode
	ld   mb,a

	ld ix,-16		;Get 24 bit stack pointer (SPL)
	add ix,sp
	
	ld.sis iy,-16	;Get 8/16 bit stack pointer (SPS)
	add.sis iy,sp
	ld bc,$D10000	;Patch in top byte
	add iy,bc
	
	ld hl,$FFFFFF
	push hl
	push.sis hl
	
	call.il ShowStack
	
	;Our program is currently running in 24 bit ADL ez80 mode
	
	ld hl,0
	ld de,0
	ld de,0
	
	Call Monitor

;L->S Long Call To Short ***************************************************************

	;call.is Z80Code & $ffff ;Call subroutine and enable 8 bit mode
	;call.is Z80Code2 & $ffff	;Nested Test
	Call Monitor

;L->L Long Call To Long ***************************************************************
	
	;call.il eZ80Code	
	
	;call eZ80Code	;This will crash, need to specify .IS/IL when using RET.L
	
	Call Monitor
	
	pop hl
	
	
	rsmix 		;Disable mixed mode
	jp FinishProgram
	

	.assume ADL=0	;Tell the assembler to compile z80 commands	
Z80Code2:			;This code runs in Z80 mode
	ld.lil hl,$DDDDDD
	push.lil hl
	push.sis hl
	
;S->S Short Call To Short ***************************************************************
	
	call.is Z80Code & $ffff
	pop.sis hl
	pop.lil hl
	
	ret.l
	
Z80Code:			;This code runs in Z80 mode
	ld.lil hl,$EEEEEE
	push.lil hl
	push.sis hl
;S->L Short Call To Long ***************************************************************
	call.il ShowStack
	pop.sis hl
	pop.lil hl


	dec hl			;This is a Z80 command
	call.il eZ80Code ;Switch to ez80 mode (24 bit ADL mode)
	dec bc			;This is a Z80 command
	ret.l			;Return and switch back to previous CPU mode
		
	.assume ADL=1	;Tell the assembler to compile ez80 commands
eZ80Code:			;This code runs in eZ80 mode (ADL)
	ld hl,$EEEEEE
	push.lil hl
	push.sis hl
	
	call.il ShowStack
	pop.sis hl
	pop.lil hl
	dec de			;This is an eZ80 command
	ret.l			;Return and switch back to previous CPU mode
		
ShowStack:
	push iy
	push ix
	push bc
	push de
	push hl
		call Newline
		push ix
		pop hl		;Load the address of TestData (24 bit)
		ld bc,16
		call Monitor_MemDump 	
		push iy
		pop hl		;Load the address of TestData (24 bit)
		ld bc,16
		call Monitor_MemDump 	
		call Newline
	pop hl
	pop de
	pop bc
	pop ix
	pop iy
	ret.l
			
	ret
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
	
TestInstructionMemoryModesFull:	
	
	di
	ld   a,$d1
	ld   mb,a
	
	call ShowTestData
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData
	call MiniMonitor	
	
	call.is Test8bitFull  & $ffff ;8 bit mode
	
	call ShowTestData
	
	call Newline
	call Newline
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData2
	call MiniMonitor	
	
	ld.SIS bc,(ix)
	ld.SIL de,(ix)
	ld.LIS hl,(ix)
	ld.LIL iy,(ix)
	call MiniMonitor	
	
	call Newline
	
	ld hl,$A1A2A3
	ld bc,$B1B2B3
	ld de,$C1C2C3
	ld IY,$D1D2D3
	
	ld.SIS (ix+0),bc
	ld.SIL (ix+4),de
	ld.LIS (ix+8),hl
	ld.LIL (ix+12),iy
	
	call MiniMonitor	
	call ShowTestData2
	jp FinishProgram
	
	
.assume ADL=0
Test8bitFull:

	call.sil  NewLine8Bit

	ld.SIS bc,(ix)
	ld.SIL de,(ix)
	ld.LIS hl,(ix)
	ld.LIL iy,(ix)
	
	call.sil MiniMonitorL
		
	ld.lil hl,$A1A2A3
	ld.lil bc,$B1B2B3
	ld.lil de,$C1C2C3
	ld.lil IY,$D1D2D3
	
	ld.SIS (ix+0),bc
	ld.SIL (ix+4),de
	ld.LIS (ix+8),hl
	ld.LIL (ix+12),iy
	
	call.sil MiniMonitorL
	
	ret.l
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	.assume ADL=1
	
TestInstructionMemoryModesHalf1:	
	
	di
	ld   a,$d1
	ld   mb,a
	
	call ShowTestData
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData
	call MiniMonitor	
	
	call.is Test8bitHalf1  & $ffff ;8 bit mode
	
	call ShowTestData
	
	call Newline
	call Newline
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData2
	call MiniMonitor	
	
	ld.IS bc,(ix)
	ld.IL de,(ix)
	ld.IS hl,(ix)
	ld.IL iy,(ix)
	call MiniMonitor	
	
	ld hl,$A1A2A3
	ld bc,$B1B2B3
	ld de,$C1C2C3
	ld IY,$D1D2D3
	
	ld.IS (ix+0),bc
	ld.IL (ix+4),de
	ld.IS (ix+8),hl
	ld.IL (ix+12),iy
	
	call MiniMonitor	
	call ShowTestData2
	jp FinishProgram
	
	
.assume ADL=0
Test8bitHalf1:

	ld.IS bc,(ix)
	ld.IL de,(ix)
	ld.IS hl,(ix)
	ld.IL iy,(ix)
	
	call.sil MiniMonitorL
		
	ld.lil hl,$A1A2A3
	ld.lil bc,$B1B2B3
	ld.lil de,$C1C2C3
	ld.lil IY,$D1D2D3
	
	ld.IS (ix+0),bc
	ld.IL (ix+4),de
	ld.IS (ix+8),hl
	ld.IL (ix+12),iy
	
	call.sil MiniMonitorL
	
	ret.l
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
		
.assume ADL=1
TestInstructionMemoryModesHalf2:	
	
	di
	ld   a,$d1
	ld   mb,a
	
	call ShowTestData
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData
	call MiniMonitor	
	
	call.is Test8bitHalf2  & $ffff ;8 bit mode
	
	;ld   a,$d0			;This will affect the S commands
	;ld   mb,a
	
	
	call ShowTestData
	
	call Newline
	call Newline
	call Newline
	
	ld hl,$888888
	ld bc,$888888
	ld de,$888888
	ld IY,$888888
	
	ld ix,TestData2
	call MiniMonitor	
	
	ld.S bc,(ix)
	ld.S de,(ix)
	ld.L hl,(ix)
	ld.L iy,(ix)
	call MiniMonitor	
	
	call Newline
	
	ld hl,$A1A2A3
	ld bc,$B1B2B3
	ld de,$C1C2C3
	ld IY,$D1D2D3
	
	ld.S (ix+0),bc
	ld.S (ix+4),de
	ld.L (ix+8),hl
	ld.L (ix+12),iy
	
	call MiniMonitor	
	call ShowTestData2
	
	jp FinishProgram
	
	
.assume ADL=0
Test8bitHalf2:

	call.sil  NewLine8Bit

	ld.S bc,(ix)
	ld.S de,(ix)
	ld.L hl,(ix)
	ld.L iy,(ix)
	
	call.sil MiniMonitorL
		
	ld.lil hl,$A1A2A3
	ld.lil bc,$B1B2B3
	ld.lil de,$C1C2C3
	ld.lil IY,$D1D2D3
	
	ld.S (ix+0),bc
	ld.S (ix+4),de
	ld.L (ix+8),hl
	ld.L (ix+12),iy
	
	call.sil MiniMonitorL
	
	ret.l
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
TestData:
	.db $11,$22,$33,$44,$55,$66,$77,$88,$99,$AA,$BB,$CC,$DD,$EE,$FF,$00
TestData2:
	.db $11,$22,$33,$44,$55,$66,$77,$88,$99,$AA,$BB,$CC,$DD,$EE,$FF,$00

.assume ADL=1	

ShowTestData2:
	push ix
	push hl
	push bc
	push de
		call Newline		
		ld hl,TestData2	;Load the address of TestData (24 bit)
		ld bc,16
		call Monitor_MemDump 
		call Newline
	pop de
	pop bc
	pop hl
	pop ix
	ret	
	
	
	
ShowTestData:
	push ix
	push hl
	push bc
	push de
		call Newline		
		ld hl,TestData	;Load the address of TestData (24 bit)
		ld bc,16
		call Monitor_MemDump 
		call Newline
	pop de
	pop bc
	pop hl
	pop ix
	ret	
	
MiniMonitorL:	
	call MiniMonitor
	ret.l
	
MiniMonitor:
	push af
	push bc
	push de
	push hl
	push ix
		push bc
			ld b,'B'
			ld c,'C'

		pop ix
		call MonitorOne
		
		ld b,'D'
		ld c,'E'
		push DE
		pop ix
		call MonitorOne
		
		ld b,'H'
		ld c,'L'
		push HL
		pop ix
		call MonitorOne
		
		ld b,'I'
		ld c,'Y'
		push IY
		pop ix
		call MonitorOne
		
		;call NewLine
		
		
		call NewLine
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ret
	

MiniMonitorSP:
	push af
	push bc
	push de
	push hl
	
			ld b,'A'
			ld c,'F'
			push AF
			pop ix
			call MonitorOne8

		
		ld b,'D'
		ld c,'E'
		push DE
		pop ix
		call MonitorOne
		
		ld b,'H'
		ld c,'L'
		push HL
		pop ix
		call MonitorOne
		
	ld ix,3*5
	add ix,sp
	
	ld b,'S'
	ld c,'P'
	call MonitorOne 
	
		call NewLine
	pop hl
	pop de
	pop bc
	pop af
	ret	
	
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	

 
	
#include "\SrcAll\Functions.asm"
#include "\SrcAll\Monitor.asm"
	
Font:
#import "\ResAll\Font96.FNT"

#include "\SrcAll\v1_Footer.asm"
