
.macro MonitorA0A1RAPCm
	push ra
		move t6,ra
		jal MonitorA0A1RAPC
		nop
	pop ra
.endmacro
.macro DumpStack
	jal MonitorA0SP
	nop
	li t6,2			;Line Count
	jal MemDumpNoLabel	;Dump Stack to screen
	nop
	jal NewLine
	nop
.endmacro



.include "\SrcAll\Header.asm"
.include "\SrcAll\BasicMacros.asm"
  
CursorX equ 0x100 
CursorY equ 0x101
  

	jal Cls				;Zero Graphics cursor pos
	nop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  



	li ra,0

	;j AddressingModes
	
	; LoadStoreTypes
	
	j TestUnaligned
	;j StackTest
	nop



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

AddressingModes:

;Immediate Addressing 	A fixed number is the parameter for an operation. 
	
	li a0,0x1234

	jal MonitorA0A1A2 	
	nop

	jal NewLine
	nop
	
;Register Addressing 	A register itself will be used as a source or destination of an operation.
	
	move a1,a0

	jal MonitorA0A1A2 	
	nop
	
;Register Indirect with Offset Addressing 	This Addressing mode uses the value from the address in a register, 
											;offset by a fixed numeric value.	
	jal NewLine
	nop
	
	la a2,TestData
	
	lw a0,(a2)			;Load from address in A2 
	;lw a0,0(a2)		;Same as above
	
	lw a1,4(a2)			;Load from address in A2+4
	;lw a1,-4(a2)		;Load from address in A2-4
	
	jal MonitorA0A1A2 	
	nop
	
	
	jal NewLine
	nop

	la t7,TestData		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
		
	jal NewLine
	nop
		
;Program Counter Relative with Offset Addressing 	used for relative jump and branch operations.
	
	li a0,0
	
	beq a0,zero,EqualZero
	nop 
	
	li a1,0x6969
	
EqualZero:	

	jal MonitorA0A1A2 	
	nop
	
	jal NewLine
	nop
	
;Psuedo Direct Addressing	26 bits of the parameter are shifted left two bits, and the top 4 bits 
							;are taken from the program counter: %PPPPnnnnnnnnnnnnnnnnnnnnnnnnnn00
	
	li a0,0
	
	j JumpTest
	nop 
	
	li a1,0x0666
	
JumpTest:	

	jal MonitorA0A1A2 	
	nop
	
	

	j Shutdown
	nop
	

  
TestData:	;Little Endian - so this is F3F2F1F0
	.byte 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7
	.byte 0,0,0,0,0,0,0

	.align 4
	
	

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	
	
LoadStoreTypes:
	
	li a1,0				;Clear a1
	
	la t7,TestData		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	
	jal NewLine  
	nop
	
	la a2,TestData		;Load address of TestData
	lw a0,(a2)			;Load Word into A0 from address in A2
	jal MonitorA0A1A2 	
	nop
	
	lhu a0,(a2)			;Load Byte (other bits 0)
	lh a1,(a2)			;Load Byte (other bits bit7)
	jal MonitorA0A1A2 	
	nop
	
	lbu a0,(a2)			;Load Byte (other bits 0)
	lb a1,(a2)			;Load Byte (other bits bit7)
	jal MonitorA0A1A2 	
	nop
	
	jal NewLine  
	nop
	
	
	
	la t7,UserRam		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	
	jal NewLine  
	nop
	
	lw a0,(a2)			;Load Word into A0 from address in A2
	jal MonitorA0A1A2 	
	nop
	
	jal NewLine  
	nop
	
	
	la a3,UserRam
	
	sw a2,(a3)			;Store Word from A0 into address in A2
	sw a0,4(a3)			;Store Word from A0 into address in A2+4
		
	sh a0,8(a3)			;Store HalfWord from A0 into address in A2+8
	
	sb a0,12(a3)		;Store Byte from A0 into address in A2+12
	
	la t7,UserRam		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	
	
	j Shutdown
	nop
	


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

;We probably don't actually want to use these - they are used by psuedo ops

;ULH dest,addr
;ULHU dest,addr
;ULW dest,addr
;USH dest,expr
;USW dest,expr


TestUnaligned:
	
	li t7,Unaligneddata	;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	jal NewLine
	nop
	
	li a0,0
	li a1,0
	
	;la a3,Unaligneddata+7
	
	la a3,Unaligneddata+1
	
	lwl a0,3(a3)	;Load Word Left
	lwr a1,0(a3)	;Load Word Right
	
	lwl a2,3(a3)	;Load Word Left
	lwr a2,0(a3)	;Load Word Right
	
	jal MonitorA0A1A2 	; Show A0,A1,A2 to screen
	nop
	jal NewLine
	nop
	
	ulw a0,0(a3)		;Unaligned Load Word - Psuedoop
	ulh a1,0(a3)		;Unaligned Load Half - Psuedoop
	ulhu a2,0(a3)		;Unaligned Load Half Unsigned - Psuedoop
	
	jal MonitorA0A1A2 	; Show A0,A1,A2 to screen
	nop
	jal NewLine
	nop
	
	;la a3,UserRam+10
	
	la a3,UserRam+1
	li a0,0xFFEEDDCC
	li a1,0x11223344
	
	jal MonitorA0A1A2 	; Show A0,A1,A2 to screen
	nop
	
	swl a0,0(a3)		;Store Word Left
	swr a1,4(a3)		;Store Word Right
	
	li t7,UserRam		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	jal NewLine
	nop
	
	la a3,UserRam+1
	li a0,0x69686766
	
	jal MonitorA0A1A2 	; Show A0,A1,A2 to screen
	nop
	
	usw a0,9(a3)		;Unaligned Store word - Psuedoop
	ush a0,0(a3)		;Unaligned store half - Psuedoop
	
		
	li t7,UserRam		;Address
	li t6,2				;Line Count
	jal MemDump			;Dump Ram to screen
	nop
	
	j Shutdown
	nop
	
Unaligneddata:
	.byte 0xFF
	.byte 0x11,0x22,0x33,0x44	;This is not WORD aligned!
	.byte 0xDD,0xCC
	.byte 0x21,0x22,0x23,0x24	;This is not WORD aligned!
	.align 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 

	
StackTest:
	move t7,sp		;Address
	addi t7,t7,-16
	
	li a0,0xF4F3F2F1
	DumpStack		;Dump Stack to screen
	
	addi sp,sp,-4	;push a0
	sw a0,0(sp)    	;push a0
		li a0,0
		DumpStack	;Dump Stack to screen
		jal SubTest
		nop
	lw a0,0(sp)		;pop a0
	addi sp,sp,4	;pop a0
	
	DumpStack		;Dump Stack to screen
	
	j Shutdown
	nop
	
SubTest:
	addi sp,sp,-4		;push ra
	sw ra,0(sp)   		;push ra
		li a0,0x11223344
		push a0
			DumpStack	;Dump Stack to screen
		pop a0
		DumpStack		;Dump Stack to screen
		
	lw ra,0(sp)			;pop ra
	addi sp,sp,4		;pop ra
	jr ra
	nop
	
	
Shutdown:
	j Shutdown
	nop
	
	

MonitorA0A1:
	push ra
	pushAs
	    li t5,'a'
		li t6,'0'
		move t7,a0
		jal ShowRegTextB             
		nop
		li t5,'a'
		li t6,'1'
		move t7,a1
		jal ShowRegTextB             
		nop
		jal NewLine         
		nop
	popAs
	pop ra
	jr ra
	nop
	
 
MonitorA0A1A2:
	push ra
	pushAs
	pushTs
	    li t5,'a'
		li t6,'0'
		move t7,a0
		jal ShowRegTextB                ;A5 A6 : A7
		nop
		li t5,'a'
		li t6,'1'
		move t7,a1
		jal ShowRegTextB                ;A5 A6 : A7
		nop
		li t5,'a'
		li t6,'2'
		move t7,a2
		jal ShowRegTextB                ;A5 A6 : A7
		nop
		jal NewLine         
		nop
	popTs
	popAs
	pop ra
	jr ra
	nop
  	
	
MonitorA0SP:
	move t4,sp
	addi t4,t4,4
	push ra
	pushTs
	pushAs
		push ra
			push t4
				
			
				li t5,'a'
				li t6,'0'
				move t7,a0
				jal ShowRegTextB                ;A5 A6 : A7
				nop
				li t5,'s'
				li t6,'p'
			pop t7
			jal ShowRegTextB                ;A5 A6 : A7
			nop
			li t5,'p'
			li t6,'c'
		pop t7
		jal ShowRegTextB                ;A5 A6 : A7
		nop
	popAs
	popTs
	pop ra
	jr ra
	nop
  
MyFont:

.ifdef buildn64				;Can't use EQU to define with ifdef - use DefineLabel because reasons!
	.incbin "\ResN64\ChibiAkumas.fnt"
.endif
.ifdef buildPSX				;Can't use EQU to define with ifdef - use DefineLabel because reasons!
	.incbin "\ResPSX\ChibiAkumas.fnt"
.endif

.include "\SrcALL\graphics.asm"
	
.include "..\\SrcAll\monitor.asm"  	
.include "\SrcN64\Footer.asm"
