
	
	.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)

	SEI						;Stop interrupts
	jsr ScreenInit			;Init the graphics screen
	jsr Cls

	;jmp SwitchModes
	jmp AccumulatorMemory
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
SwitchModes:	

;Set The CPU mode	
	sec					;8 bit mode (6502 Emulation)
	xce		

;Tell the assembler what to do	
	.ACCU 8				;Accumulator 8 bit
	.INDEX 8			;XY 8 bit
	
	lda #$66			;Load A with Hex $66
	ldx #66				;Load A with Decimal 66
	ldy 66				;Load A from memory address 0066
	jsr Monitor			;Show the monitor
	
;We can use new commands even in 6502 mode!!!
	xba					;Swap A/B
	txy					;Transfer X to Y
	jsr Monitor			;Show the monitor
	
	jsr NewLine
	
;Enable 65816 Native mode	
	clc
	xce	;16 bit mode (65816 Native)
		
;Set 16 bit Accumulator/Memory and XY registers

		;  --MX---- M=Accumulator X=XY
	REP  #%00110000		;16 bit XY+Accumulator
	
	.ACCU 16			;Accumulator 16 bit
	.INDEX 16			;XY 16 bit	
		
		
	lda #$6660			;Load A with Hex $6660
	ldx #666			;Load A with Decimal 666 ($029A)
	ldy 666				;Load A from memory address 0666
	jsr Monitor			;Show the monitor

	
		;  --MX---- M=Accumulator X=XY
	SEP  #%00110000		; 8 bit XY+Accumulator
	
	.ACCU 8				;Accumulator 8 bit
	.INDEX 8			;XY 8 bit
	
;Top byte of X,Y Lost!
	jsr Monitor			;Show the monitor
	
		;  --MX---- M=Accumulator X=XY
	REP  #%00110000		;16 bit XY + Accumulator/Memory
	.ACCU 16			;Accumulator 16 bit
	.INDEX 16			;XY 16 bit	
	
;Doesn't come back in 16 bit mode	
	jsr Monitor			;Show the monitor
	
	
	jsr NewLine
		
	
		;  --MX---- M=Accumulator X=XY
	SEP  #%00100000		; 8 bit Accumulator/Memory
	REP  #%00010000		;16 bit XY
	.ACCU 8				;Accumulator 8 bit
	.INDEX 16			;XY 16 bit	
		
	lda #$88			;Load A with Hex $88
	ldx #$888			;Load X with Hex $888
	
	jsr Monitor			;Show the monitor
	
	
		;  --MX---- M=Accumulator X=XY
	REP  #%00100000		;16 bit Accumulator/Memory
	SEP  #%00010000		; 8 bit XY
	.ACCU 16			;Accumulator 16 bit
	.INDEX 8			;XY 8 bit	
		
	lda #$999			;Load A with Hex $999
	ldy #$99			;Load A with Hex $99
		
	jsr Monitor			;Show the monitor
	
	jmp infloop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
		
AccumulatorMemory:

;When the M flag = 0 all operations on the Accumulator or Memory now work in 16 bit.

;These commands are:
;ADC  AND  ASL  BIT  CMP  DEC  EOR  INC  LDA  LSR  ORA  PHA  PLA  ROL  ROR  SBC  STA  STZ  TRB  TSB

	REP  #%00100000 	;16 Bit Accumulator / Memory
	.ACCU 16			;Accumulator 16 bit
	
;16 bit test
	
	ldx #10				;Counter
	
	LDA #$80FC			;Test Values
	sta z_HL
	LDA #$4321
Again16:
	jsr ShowPairHL
	asl					;Accumulator now 16 bit.
	inc z_HL			;Memory modes are all now 16 bit too!
	
	dex
	bne Again16			;Repeat
	
	jsr NewLine
	
; 8 Bit test
	
	ldx #10				;Counter
	
	LDA #$80FC			;Test Values
	sta z_HL
	LDA #$4321
	
	SEP  #%00100000 	;8 Bit Accumulator / Memory
	.ACCU 8				;Accumulator 8 bit
	
Again8:
	jsr ShowPairHL
	asl
	inc z_HL
	
	dex
	bne Again8			;Repeat
	
	
		
infloop:
	jmp infloop



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

ShowPairHL:
	php
	Mode16bit
	pha
	phy
	phx
		Mode8bit
		pha
			lda #'C'
			jsr PrintChar
			lda #':'
			jsr PrintChar
			xba
			jsr printhex
		pla
		jsr printhex
		lda #' '
		jsr PrintChar
		
		lda #'H'
		jsr PrintChar
		lda #'L'
		jsr PrintChar
		lda #':'
		jsr PrintChar
		lda z_H
		jsr printhex
		lda z_L
		jsr printhex
		
		jsr NewLine
		
	Mode16bit
	plx
	ply
	pla
	plp
	rts 
	


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;	
	
	
	.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
	
	