
	
	.include "\SrcALL\V1_Header.asm"		;Cartridge/Program header - platform specific
	.include "\SrcAll\BasicMacros.asm"		;Basic macros for ASM tasks
MyProg:
	clc
	xce	;16 bit mode (65816 Native)

	jsr ScreenInit			;Init the graphics screen
	jsr Cls
	
	
	Mode16bit
	
;WARNING: These are only tested on the SNES emulator!

;As we're writing to fixed addresses it probably won't work on others.	
	lda #$300	;Set Direct page to $0003xx
	TCD			;
	stz CursorX
	stz CursorY
	
	
	
	ldx #ChunkDP20
	ldy #$0380
	jsr CopyChunk
	
	
	
	ldx #Chunk0200
	ldy #$0200
	jsr CopyChunk
	
	
	ldx #Chunk030200
	ldy #$0200
	jsr CopyChunk03
	
	;jmp DirectPage	
	;jmp DirectPageIndirect
	;jmp AbsoluteIndexedIndirect 
	
	
	;jmp StackRelative
	
	;jmp BlockMove
	jmp AbsoluteLong
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
DirectPage:

	lda #$300	;Set Direct page to $0003xx
	TCD			;Transfer C (16 bit accumulator) to Direct page
		
	;Show part of the direct page
	jsr MemDump			;Dump an address to screen
	.dl $00380     		;Address to show (24 bit)
	.db $1          	;Lines to show
	
	
	jsr NewLineZ
	jsr NewLineZ
	
	
	jsr Monitor	
	ldx $80				;Load X from Direct page $80 ($380)
	ldy $82				;Load X from Direct page $82 ($382)
	jsr Monitor	

	jmp infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
DirectPageIndirect:		;Works best on Apple II emulator

	jsr MemDump			;Dump an address to screen
	.dl $00380     		;Address to show (24 bit)
	.db $1          	;Lines to show
	
	jsr MemDump			;Dump an address to screen
	.dl $000200    		;Address to show (24 bit)
	.db $1          	;Lines to show
		
	jsr MemDump			;Dump an address to screen
	.dl $030200    		;Address to show (24 bit)
	.db $1          	;Lines to show
	
	jsr NewLineZ
		
	lda ($81)			;Direct Page Indirect ($0201) (65c02 command)
	jsr Monitor
	
	lda [$81]			;Direct Page Indirect Long	[$030201]
	jsr Monitor
	
	ldy #1
	lda [$81],Y			;Direct Page Indirect Long Indexed with Y
	jsr Monitor
	
	jmp infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
AbsoluteIndexedIndirect:	;Absolute Indexed Indirect (65c02 command)
	
	;This command only works with Jump
	
	Mode8bit			;Needed for PrintChar Routine
	
;	ldx #0				;PrintA
;	ldx #2				;PrintB
	ldx #4				;PrintC
	jmp (TestJumps,X)	;Jump to address at TestJumps+X
		
TestJumps:
	.dw PrintA		;0
	.dw PrintB		;2
	.dw PrintC		;4
	
PrintA:
	lda #'A'
	jsr PrintChar
	jmp infloop
PrintB:
	lda #'B'
	jsr PrintChar
	jmp infloop
PrintC:
	lda #'C'
	jsr PrintChar
	jmp infloop
	
	Mode16bit
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	

StackRelative:
	
	ldx #$FFFF
	phx
		ldx #$1234
		phx
		ldx #$5678
		phx
			ldx #0
			jsr Monitor
			
			jsr MemDump			;Dump an address to screen
			.dl $0001F0    		;Address to show (24 bit)
			.db $2	         	;Lines to show
		
			jsr NewLineZ
		
			lda 1,S				;Load from SP+1
			jsr Monitor
			lda 2,S				;Load from SP+2
			jsr Monitor
			
			jsr NewLineZ
			jsr NewLineZ
						
;Stack Relative Indirect Indexed with Y

		plx
		ldx #$0102
		phx
			ldx #$0304
			phx
				jsr MemDump			;Dump an address to screen
				.dl $0001F0    		;Address to show (24 bit)
				.db $2	         	;Lines to show

				jsr MemDump			;Dump an address to screen
				.dl $000200    		;Address to show (24 bit)
				.db $1          	;Lines to show
					
				ldy #1
				lda (2,S),Y			;Load from address at (SP+2)
				jsr Monitor
			plx
		plx
	plx
	jmp infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
BlockMove:
	
	jsr MemDump			;Dump an address to screen
	.dl $030000    		;Address to show (24 bit)
	.db $2          	;Lines to show

	lda #7			;Bytes to copy-1
	ldx	#TestData	;Source
	ldy #$0000		;Destination
	
	phb
		MVN $00,$03		;MoveNext (Sourcebank,DestBank)
	plb	;MVN alters bank
	
	jsr MemDump			;Dump an address to screen
	.dl $030000    		;Address to show (24 bit)
	.db $2          	;Lines to show
	
	
	lda #7			;Bytes to copy
	ldx	#TestData_End-1;Source
	ldy #$000F		;Destination
	
	phb
		MVP $00,$03		;MovePrevious (Sourcebank,DestBank)
	plb	;MVP alters bank
	
	
	jsr MemDump			;Dump an address to screen
	.dl $030000    		;Address to show (24 bit)
	.db $2          	;Lines to show
	
	jmp infloop
	
TestData:
	.db $FF,$FE,$FD,$FC,$FB,$FA,$F9,$F8
TestData_End:	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	

AbsoluteLong:			
	
	jsr MemDump			;Dump an address to screen
	.dl $030200    		;Address to show (24 bit)
	.db $2          	;Lines to show

	jsr Monitor
	jsr NewLineZ
	
;Absolute Long
	lda $030200			;Load from $030200
	
	jsr Monitor
	jsr NewLineZ

	ldx #1
;Absolute Long Indexed with X
	lda $030200,x		;Load from $030201
	jsr Monitor
	jsr NewLineZ
	
	ldx #2
	lda $030200,x		;Load from $030202
	jsr Monitor
	jsr NewLineZ
	
	
	
;Copy the Absolute Indirect Long Test Data
	lda #8			;Bytes to copy
	ldx	#LongTest2	;Source
	ldy #$0400		;Destination
	phb
		MVN $00,$03		;MoveNext (Sourcebank,DestBank)
	plb	;MVN alters bank
	jsr MemDump			;Dump an address to screen
	.dl $030400    		;Address to show (24 bit)
	.db $2          	;Lines to show

	jsr NewLineZ
;Absolute Indirect Long	
	jml [LongTest] 		;Absolute Indirect Long
	
	jmp infloop
		
LongTest:
	.dl  $030400		;Jump to Longtest2 (after copy)

LongTest2:
	lda #$6666
	jsl MonitorL
	
	jml infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	

NewLineZ:
	php
	Mode16bit
	phd 
	pha
		lda #0
		tcd
		stz CursorX
		inc CursorY
	pla
	pld
	plp	
	rts	
	
MonitorL:
	jsr Monitor
	rtl
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
CopyChunk03:
	phb
		lda #7			;Bytes to copy-1
		MVN $00,$03		;MoveNext
	plb
	rts
CopyChunk:
	lda #7			;Bytes to copy-1
	MVN $00,$00		;MoveNext
	rts
		
infloop:
	jmp infloop
	
ChunkDP20:
	.db $00,$01,$02,$03,$04,$05,$06,$07
Chunk030200:
	.db $61,$62,$63,$64,$65,$66,$67,$68
Chunk0200:
	.db $40,$41,$42,$43,$44,$45,$46,$47

	
	.include "\SrcAll\Monitor.asm"			;Debugging tools
	.include "\SrcAll\BasicFunctions.asm"	;Basic commands for ASM tasks
	
BitmapFont:									;Chibiakumas bitmap font
	.incbin "\ResALL\Font96.FNT"		
	

	.include "\SrcALL\V1_Functions.asm"	;Basic text to screen functions
	.include "\SrcAll\V1_BitmapMemory.asm"	;Bitmap functions for Bitmap screen systems
	.include "\SrcAll\V1_VdpMemory.asm"		;VRAM functions for Tilemap Systems
	.include "\SrcALL\V1_Palette.asm"		;Palette functions
	.include "\SrcALL\V1_Footer.asm"		;Footer for systems that need it
	
	