Autoformatter Source Code

From Dq5r

Jump to: navigation, search

; New design.  no matter what 4 registers will be available
; (except for initializer)
; v0 will always contain 6E83F0
; a0 a1 a2 will be cleared for usage using a routine
; if v0 is in use it will be backed up using a disposable register

; Character size jump table at 6E83F0~ 6E844F

; 120A12121212131212121112121206120B0C0C0C0C0B0B0B0B0B06121012100F120C0B0B0B0B0B0B0A0A0B0A0A0B0A0B0B0B0B0B0B0B0C0C0B0B0B1212121212120B0B0B0B0B0B0B0A0A0A0B060B0A0B0B0B0A0B0B0B0C0C0B0C0B1212121212



;
;                                         0                                   4                                    6                                  8                                 A                 C
; Memory Map  |Pointer to last space | Width Running total | Width at last space | Already subtracted width | Unused | Scroll pointer |
;                         |              V0                 |                                  A1                                 |                          A2                              |          A3          |
;
; ****Initialize Routine****   6E8450~ 6E849F
; ****Initialize Routine****   6E83F0~ 6E843F
; 
org $006E8450
;	First 32 bytes is for storage.  Need to set this to 0 before usage
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop	
	
;	daddu	$s2, $a1, $0
;a0 and s0 are available	2D90A000
;	db	$2D, $80, $00, $00	
; 	6E8410

	lui 	s0,	0x6f 
	addiu 	s0,	s0,	0x8450

;	li  s0,	0x6e83f0
;	lui	s0, 0x006E
;	ori	s0, s0, 0x83F0

	sw 	r0, 0x0000(s0)	
	sw 	r0, 0x0004(s0)	
	sw 	r0, 0x0008(s0)	
	sw 	r0, 0x000C(s0)
	sw 	r0, 0x0010(s0)	
	sw 	r0, 0x0014(s0)	
	sw 	r0, 0x0018(s0)	
	sw 	r0, 0x001C(s0)
	j	$00631E38
	nop

	
;	lbu	s0, 0x0000(s2)
;6E84A0
; ****Character/Item Routine**** 6E84A0~6E852F

	
; v0 is usable, a1 needs to be backed up
; This handles Names/Items
; a1 contains location of byte

	lui 	v0,	0x6f 
	addiu 	v0,	v0,	0x8450
	
;	li  	v0,	0x6e83f0
;	lui		v0, 0x006E
;	ori		v0, v0, 0x83F0

	sw		a1, 0x0014(v0) ; Back up a1
	sw		a2, 0x0018(v0) ; Back up a2
	sw		a3, 0x001C(v0) ; Back up a3

;;;;;;;;;	
;	beq		r0, r0, no_counter
;	nop


	lbu		a2, 0x0000(a1) ; Load current byte
	; Check if 7B
	;addiu	a3, r0, 0x007B
	;bne		a3, a2, not_seven_b

	; Check if AF or 0A
	addiu	a3, r0, 0x00AF
	bne		a3, a2, not_AF

is_0A
	addu	a3, r0, r0		; zero out width for now
	sh		a3, 0x0004(v0)	
	beq		r0, r0, no_counter
	nop	
	
not_AF	
	addiu	a3, r0, 0x000A
	beq		a3, a2, is_0A
	
	nop

	
	
	; See if > 7F or < 21

	
	
	slti	a3, a2, 0x0020 ; If less than 20 then don't count. **

	bne		a3, r0, no_counter
	nop

	
	slti	a3, a2, 0x007F ; If greater than 7F then don't count. **
	
	
	beq		a3, r0, no_counter
	

	
	; grab size of char from jump table
	lui 	a1,	0x6F 
	addiu 	a1,	a1,	0x83D0	; This subtracts 20 to made the base address allign
	addu	a3, a1, a2  	; Add the actual value to get the correct address
	

	lbu		a1, 0x0000(a3)	; a1 now contains width	
	
	
	lhu  	a2, 0x0004(v0) ; Keeps running tab of width
	addu	a3, a1, a2
	sh		a3, 0x0004(v0)
	

no_counter	

	
	lw		a1, 0x0014(v0) ; Restore a1
	lw		a2, 0x0018(v0) ; Restore a2
	lw		a3, 0x001C(v0) ; Restore a3
	
	LBU		v0, 0x0000(a1)
	ADDIU	a1, a1, 0x0001
	SB		v0, 0x0000(v1)
	SLL		v0, v0, 0x0018
	j		$004a5c80
	ADDIU	v1, v1, 0x0001



	
;00631f10 00000000: NOP    ,
;00631f14 826205bc: LB     , 00000000_0000000a (v0), 05bc (007454b0 (s3)),
;00631f18 24420001: ADDIU  , 00000000_00000001 (v0), 00000001 (v0), 0001 (1),
;00631f1c a26205bc: SB     , 00000000_00000002 (v0), 05bc (007454b0 (s3)),	
















; ****Regular Text Routine**** 6E8530  starts at 120 = 

; Current location is 6E8490
; v1, a0 is usable
; s0 contains the current byte
; s1 contains pointer to memory address to put next character


	lui 	v1,	0x6f 
	addiu 	v1,	v1,	0x8450
	
;	li  	v1,	0x6E83F0
;	lui		v1, 0x006E
;	ori		v1, v1, 0x83F0
	sw		v0, 0x0010(v1) ; Back up v0
	
	lui 	v0,	0x6f 
	addiu 	v0,	v0,	0x8450
	
;	li  	v0,	0x6E83F0
;	lui		v0, 0x006E
;	ori		v0, v0, 0x83F0	
	
	sw		a1, 0x0014(v0) ; Back up a1
	sw		a2, 0x0018(v0) ; Back up a2
	sw		a3, 0x001C(v0) ; Back up a3


	
	; Check if AF
	addiu	a3, r0, 0x00AF
	bne		a3, s0, not_AF_2

is_0A_2	
	addu	a3, r0, r0		; zero out width for now
	sh		a3, 0x0004(v0)	
	beq		r0, r0, not_max_pixels
	nop

not_AF_2
	addiu	a3, r0, 0x000A
	beq		a3, s0, is_0A_2
	
	
	nop

	
	slti	a3, s0, 0x0020 ; If less than 20 then don't count. **

	bne		a3, r0, not_max_pixels
	nop

	
	slti	a3, s0, 0x007F ; If greater than 7F then don't count. **
	
	
	beq		a3, r0, not_max_pixels
	nop	

	
	; grab size of char from jump table
	lui 	a1,	0x6F 
	addiu 	a1,	a1,	0x83D0	; This subtracts 20 to made the base address allign
	addu	a3, a1, s0  	; Add the actual value to get the correct address
	

	lbu		a1, 0x0000(a3)	; a1 now contains width		
	sll		a1, a1,0x0001 ; Multiply by 2 ( Takes into account names count
	                      ; double)	
						  
	
	lhu  	a2, 0x0004(v0) ; Keeps running tab of width
	addu	a3, a2, a1
	sh		a3, 0x0004(v0)


	addiu	a1, zero, 0x0020
	bne		s0, a1, not_20
	nop

	; If 20 then keep track of location and current conbined width
    ; Also backup s3 (Newline)

	
;	li		v0,0x6e83f0
;	lui		v0, 0x006E
;	ori		v0, v0, 0x83F0
	sw		s3, 0x000C(v0)
	
	addiu	a2, zero, 0x0002 ; if space then keep track of some things
	subu	a1, s1, a2       ; This calculates the pointer to the last counter

	
	; Needs to be redone!
	sw		a1, 0x0000(v0)
	lhu  	a1, 0x0004(v0)
	sh		a1, 0x0006(v0)   ; current total width at space

not_20
	
	
	; check if counter is greater than max pixels on line
	lhu		a1, 0x0004(v0)
	slti	a2, a1, 0x02D0
	
	bne		a2, r0, not_max_pixels
	nop

;006E859C
		
	; insert newline stuff
	; Need one more variable



;00631f10 00000000: NOP    ,
;00631f14 826205bc: LB     , 00000000_0000000a (v0), 05bc (007454b0 (s3)),
;00631f18 24420001: ADDIU  , 00000000_00000001 (v0), 00000001 (v0), 0001 (1),
;00631f1c a26205bc: SB     , 00000000_00000002 (v0), 05bc (007454b0 (s3)),	
	
	lw		a2, 0x000C(v0) ; This fixes scroll
	lb      a1, 0x05bc(a2) 
	addiu	a1, a1, 0x0001
	sb		a1, 0x05bc(a2)
	
	

	lw  	a2, 0x0000(v0) ; Grab from first memory slot address of last space
	addiu	a1, zero, 0x0020
	sb		a1, 0x0000(a2)  ; Inserts newline
	addiu	a2, a2, 0x0001
	addiu	a1, zero, 0x000A
	sb		a1, 0x0000(a2)	
	
	; Subtract space position from counter

	lhu  	a3, 0x0006(v0)  ;  This takes into account previously scrolled text
	lhu  	a2, 0x0004(v0)  ; Width of prior lines
;	sh		a3, 0x0008(v0)   

; commented to keep the size the same	
	subu	a3, a2, a3
	sh		a3, 0x0004(v0) ; Running width counter
	
;	lhu  	a1, 0x0004(v0)  
;	subu	a2, a1, a3
	

	
	
	;sh		r0, 0x0006(a0) ;0x0006 = position of last time space was encountered
		
	
not_max_pixels
	lw		a1, 0x0014(v0) ; Restore a1
	lw		a2, 0x0018(v0) ; Restore a2
	lw		a3, 0x001C(v0) ; Restore a3

	lui 	a1,	0x6f 
	addiu 	a1,	a1,	0x8450
		
;	lui		a1, 0x006E
;	ori		a1, a1, 0x83F0	
	lw		v0, 0x0010(a1) ; Restore v0	
	
	j		$00631f94
	nop
	

Personal tools