
.macro MonitorA0A1RAPCm
	push ra
		move t6,ra
		jal MonitorA0A1RAPC
		nop
	pop ra
.endmacro


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

	jal Cls				;Zero Graphics cursor pos
	nop
	
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
	;j TestEqualsNotequals ;= !=
	;j TestLessGreaterUnsigned ;< <= > >=
	;j TestLessGreaterSigned ;< <= > >=
	;j TestLessGreaterZero	;<0 <=0 >0 >=0
	;j TestBranches
	j SetLessGreater
	
	
	nop

	
;Bcc				Description									Condition
;BEQ rs,rt,offset	Branch on Equals							rs = rt
;BGEZ rs,offset		Branch on Greater or Equal to Zero			rs >= 0
;BGEZAL rs,offset	Branch on Greater or Equal to Zero And Link	rs >= 0
;BGTZ rs,offset		Branch on Greater Than Zero					rs > 0
;BLEZ rs,offset		Branch on Less than or Equal to Zero		rs <= 0
;BLTZ rs,offset		Branch on Less Than Zero					rs < 0
;BLTZAL rs,offset	Branch on Less Than Zero And Link			rs < 0
;BNE rs,rt,offset	Branch on Not Equal							rs <> rt
;BGE rs,rt,offset	Branch on Greater than or Equals			rs >= rt
;BGEU rs,rt,offset	Branch on Greater than or Equals (Unsigned)	rs >= rt
;BGT rs,rt,offset	Branch on Greater Than						rs > rt
;BGTU rs,rt,offset	Branch on Greater Than Unsigned				rs > rt
;BLE rs,rt,offset	Branch on Less than or Equals				rs <= rt
;BLEU rs,rt,offset	Branch on Less than or Equals Unsigned		rs <= rt
;BLT rs,rt,offset	Branch on Less Than							rs < rt
;BLTU rs,rt,offset	Branch on Less Than Unsigned				rs <> rt
;BEQZ rs			Branch on EQual to Zero						rs = 0
;BNEZ rs			Branch on Not Equal to Zero					rs <> 0
	
TestEqualsNotequals:
	li a0,100			;TestVal1

	; li a1,100			;Equals Test
	li a1,101			;Not Equals Test
	
	jal MonitorA0A1
	nop
	beq a0,a1,PrintEquals		;Compare a0 to a1
	nop
	bne a0,a1,PrintNotEquals	;Compare a0 to a1
	nop
	j Shutdown
	nop
	
TestLessGreaterUnsigned:
	li a0,100			;TestVal1

	li a1,99			;Greater Than Test
	;li a1,100			;Equals Test
	;li a1,101			;Less than Test
	
	jal MonitorA0A1
	nop
	bltu a0,a1,PrintLessThan			;is a0 < a1
	nop
	bgtu a0,a1,PrintGreaterThan			;is a0 > a1
	nop
	bleu a0,a1,PrintLessThanEquals		;is a0 <= a1
	nop
	bgeu a0,a1,PrintGreaterThanEquals	;is a0 >= a1
	nop
	j Shutdown
	nop


TestLessGreaterSigned:
	li a0,-100			;TestVal1

	li a1,99			;Less Than Test
	;li a1,-100			;Equals Test
	;li a1,-101			;Greater than Test
	
	jal MonitorA0A1
	nop
	blt a0,a1,PrintLessThan			;is a0 < a1
	nop
	bgt a0,a1,PrintGreaterThan		;is a0 > a1
	nop
	ble a0,a1,PrintLessThanEquals	;is a0 <= a1
	nop
	bge a0,a1,PrintGreaterThanEquals ;is a0 >= a1
	nop
	j Shutdown
	nop
	
			
	
TestLessGreaterZero:
	;li a0,100			;Greater than zero
	;li a0,-100			;Less than zero
	li a0,0				;Equal zero

	jal MonitorA0A1
	nop
	beqz a0,PrintEquals				;Compare a0 to zero
	nop
	bnez a0,PrintNotEquals			;Compare a0 to zero
	nop
	bltz a0,PrintLessThan			;is a0 < zero
	nop
	bgtz a0,PrintGreaterThan		;is a0 > zero
	nop
	blez a0,PrintLessThanEquals		;is a0 <= zero
	nop
	bgez a0,PrintGreaterThanEquals	;is a0 >= zero
	nop
	j Shutdown
	nop
	

	

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

TestBranches:	

	b BranchTest1		;Branch to a label
	nop					;(Like Jump J)
	
ReturnFromBranchB:

	bal BranchTest3		;Branch And Link to label (PC->RA)
	nop					;(Like Jump and link JAL (Call Sub))

	j Shutdown
	nop
	
  
BranchTest1:
	MonitorA0A1RAPCm
	la a0,BranchTo
	jal PrintString
	nop
	push ra
		jal NewLine       
		nop
	pop ra
	j ReturnFromBranchB
	nop
		
BranchTest3:
	MonitorA0A1RAPCm
	push ra
		la a0,BranchAndLinkTo
		jal PrintString
		nop
		jal NewLine       
		nop
	pop ra
	jr ra	;jr RA
	nop

	
BranchAndLinkTo: 
  .ascii "BAL "
  .byte 255 
BranchTo: 
  .ascii "B   "
  .byte 255 
  .align 4
  	

	
	;SGT a0,a1,a2	;Set Greater
	;SGE a0,a1,a2	;Set Greater/Equal
	;SGEU a0,a1,a2	;Set Greater/Equal Unsigned
	;SGTU a0,a1,a2	;Set Greater Unsigned
	;SLT a0,a1,a2	;Set Less Than
	;SLE a0,a1,a2	;Set Less/Equal
	;SLEU a0,a1,a2	;Set Less/Equal Unsigned
	;SLTU a0,a1,a2	;Set Less Unsigned
	;SNE a0,a1,a2	;Set Not Equal
	

SetLessGreater:	 		;Set if LessThan / Greater To

	li a0,0
	li a1,20
	li a2,15
	
	sltu a0,a1,a2		;Set A0=1 if A1<A2 else 0 (unsigned)
	jal MonitorA0A1A2 
	nop
	sgtu a0,a1,a2		;Set A0=1 if A1>A2 else 0 (unsigned)
	jal MonitorA0A1A2 
	nop
	
	li a0,0
	li a1,20
	li a2,-100
	
	jal NewLine
	nop
	
	slt a0,a1,a2		;Set A0=1 if A1<A2 else 0 (signed)
	jal MonitorA0A1A2 
	nop
	
	sgt a0,a1,a2		;Set A0=1 if A1>A2 else 0 (signed)
	jal MonitorA0A1A2 
	nop
	
	j Shutdown
	nop
Shutdown:
	j Shutdown
	
	

PrintNotEquals:
	push ra
		li a1,'!'
		jal PrintChar
		nop
		li a1,'='
		jal PrintChar
		nop
	pop ra
	j Shutdown
	nop
PrintEquals:
	push ra
		li a1,'='
		jal PrintChar
		nop
	pop ra
	j Shutdown
	nop
PrintLessThan:
	push ra
		li a1,'<'
		jal PrintChar
		nop
	pop ra
	j Shutdown
	nop
PrintLessThanEquals:
	push ra
		li a1,'<'
		jal PrintChar
		nop
		li a1,'='
		jal PrintChar
		nop
	pop ra
	j Shutdown
	nop
PrintGreaterThan:
	push ra
		li a1,'>'
		jal PrintChar
		nop
	pop ra
	j Shutdown
PrintGreaterThanEquals:
	push ra
		li a1,'>'
		jal PrintChar
		nop
		li a1,'='
		jal PrintChar
		nop
	pop ra
	j Shutdown


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
		
	
MonitorA0A1RAPC:
	pushAs
	push ra
		push t6
			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
			
			jal NewLine         
			nop			
			li t5,'r'
			li t6,'a'
		pop t7
		jal ShowRegTextB                ;A5 A6 : A7
		nop
		li t5,'p'
		li t6,'c'
	pop t7
	push t7
		jal ShowRegTextB                ;A5 A6 : A7  
		nop
		jal NewLine         
		nop
	pop ra
	popAs
	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
  
  
  
  
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  
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"
