800A1280	0x	handle 7F21 time:hours requests
ADDIU	SP,SP,FFE8
SW	RA,0014 (SP)
SW	A0,0018 (SP)	;save controller for text bank
OR	A3,A1,R0		;A3=A1=p->current position in bank
LW	T6,0018 (SP)	;T6=controller for text bank
LW	A1,0000 (A3)	;A1=current position in bank
LW	V0,000C (T6)	;V0=p->text bank data
ADDIU	A0,V0,0010	;A0=p->text bank
JAL	8009F098		;retrieve hours and insert the string; ret V0=new text bank size
LW	A2,0008 (V0)	;A2=size of bank
LW	T7,0018 (SP)	;T7=controller for text bank
LW	T8,000C (T7)	;T8=p->text bank data
SW	V0,0008 (T8)	;save new max size
LW	RA,0014 (SP)
OR	V0,R0,R0
JR	RA
ADDIU	SP,SP,0018


8009F098		code to retrieve hours (from 7F command jump)
	string winds up on stack for a time.  that limits size to 0x8...
ADDIU	SP,SP,FFC8
SW	RA,001C (SP)
SW	A0,0038 (SP)	;A0=msg_txt text bank
SW	A1,003C (SP)	;A1=current position in msg_txt (A0)
SW	A2,0040 (SP)	;A2=size of msg_txt
LW	A0,0038 (SP)
JAL	800903A8		;advance position to next 'character'
LW	A1,003C (SP)
//8009F0B8:
LUI	A1,8013
SW	V0,0034 (SP)	;save increment to new position in text bank
LBU	A1,6FBE (A1)	;A1=80136FBE - hours in military time
JAL	800C4228		;construct string to appear on-screen
ADDIU	A0,SP,002C	;A0=target location for new string
//8009F0CC:
LW	V1,003C (SP)	;V1=current position in msg_txt (A0)
LW	T6,0034 (SP)	;T6=new position in text bank
SW	V0,0028 (SP)	;save strlen for new, happy string
LW	A0,0038 (SP)	;A0=msg_txt text bank
LW	A3,0040 (SP)	;A3=size of msg_txt
SW	R0,0010 (SP)
ADDU	A1,V1,V0		;A1=strlen+msg_txt position
JAL	8009EA2C		;extend bank for new string: ret V0=new size
ADDU	A2,V1,T6		;A2=old msg_txt position + increment over command
//8009F0F4:
LW	T7,0038 (SP)	;p->text bank
LW	T8,003C (SP)	;T8=cur. pos in msg_txt
SW	V0,0024 (SP)	;save new bank size
ADDIU	A1,SP,002C	;p->new string
LW	A2,0028 (SP)	;A2=strlen for new string
JAL	8009EB44		;copy string to destination
ADDU	A0,T7,T8		;A0=p->cur pos in text bank
//8009F110:
LW	V0,0024 (SP)	;V0=new size of text bank
LW	RA,001C (SP)
ADDIU	SP,SP,0038
JR	RA
NOP

800C4228		construct hours	x.m.#Hour
ADDIU	SP,SP,FFC0
SW	S0,0020 (SP)
SW	A1,0044 (SP)	;save hours
ANDI	A1,A1,00FF
OR	S0,A0,R0		;S0=[8014786C]
SW	RA,0024 (SP)
SLTI	AT,A1,0018	;true if within 24 hours
BNEZ	AT,800C4250
OR	T0,A1,R0		;T0=hours
OR	T0,R0,R0		;if time is invalid, set it to midnight
//800C4250:	determine a.m. or p.m.
SLTI	AT,T0,000C	;true if a.m.
BEQ	AT,R0,800C4264
OR	A0,S0,R0		;A0 is set to itself...
BEQ	R0,R0,800C4268
ADDIU	A2,R0,0001	;A2=1: a.m. flag
//800C4264:	recall text and omit trailing spaces
ADDIU	A2,R0,0002	;A2=2: p.m. flag
ADDIU	A1,R0,0006
JAL	800C3F70		;recall text #A2, length A1?
SW	T0,002C (SP)	;save time (again)
OR	A0,S0,R0		;A0=string
JAL	8009E8D0		;omits trailing spaces; returns V0=new strlen
ADDIU	A1,R0,0006	;A1=strlen
//800C4280:
LW	T0,002C (SP)
ADDIU	AT,R0,000C
ADDIU	T6,R0,0006
DIV	T0,AT		;time % 12 hours
MFHI	A1		;A1=12-hour clock time
SUBU	A2,T6,V0		;A2=difference between real len(V0) and max (6)
ADDU	A0,S0,V0		;A0=end of string
ADDIU	A3,R0,0001
SW	R0,0010 (SP)
JAL	8009264C		;probably converts A1->time
SW	V0,0034 (SP)	;save real strlen
//800C42AC:	recall text "Hour", which is sort of silly in english
LW	V1,0034 (SP)	;V1=real strlen
ADDIU	T7,R0,0006
ADDIU	A2,R0,0006	;text	"Hour"
ADDU	V1,V1,V0		;add result to strlen
ADDU	A0,S0,V1		;A0=endpoint
JAL	800C3F70		;retrieve text
SUBU	A1,T7,V1		;A1=6-strlen.  should have made larger buffer
OR	A0,S0,R0
JAL	8009E8D0		;omit trailing spaces
ADDIU	A1,R0,0006
//800C42D4:	end
LW	RA,0024 (SP)
LW	S0,0020 (SP)
ADDIU	SP,SP,0040
JR	RA
NOP

that's just not acceptable.  will make this spit out hours alone
then, will need to make a type to return a.m./p.m. alone


you know, could give months names.  extend the table maybe?
should only overrun text...

+-+-+

800A12C4	0x	handle 7F22 'minutes' command
ADDIU	SP,SP,FFE8
SW	RA,0014 (SP)
SW	A0,0018 (SP)	;save controller for text bank
OR	A3,A1,R0		;A3=A1=p->current position in bank
LW	T6,0018 (SP)	;T6=controller for text bank
LW	A1,0000 (A3)	;A1=current position in bank
LW	V0,000C (T6)	;V0=p->text bank data
ADDIU	A0,V0,0010	;A0=p->text bank
JAL	8009F120		;retrieve mins and insert the string; ret V0=new text bank size
LW	A2,0008 (V0)	;A2=size of bank
LW	T7,0018 (SP)	;T7=controller for text bank
LW	T8,000C (T7)	;T8=p->text bank data
SW	V0,0008 (T8)	;save new max size
LW	RA,0014 (SP)
OR	V0,R0,R0
JR	RA
ADDIU	SP,SP,0018

8009F120	0x	generate minutes string and insert into text
ADDIU	SP,SP,FFC8
SW	RA,001C (SP)
SW	A0,0038 (SP)	;A0=msg_txt text bank
SW	A1,003C (SP)	;A1=current position in msg_txt (A0)
SW	A2,0040 (SP)	;A2=size of msg_txt
LW	A0,0038 (SP)
JAL	800903A8		;advance position to next 'character'
LW	A1,003C (SP)
//8009F140:
LUI	A1,8013
SW	V0,0034 (SP)	;save increment to new position in text bank
LBU	A1,6FBD (A1)	;A1=80136FBD - minutes
JAL	800C42E8		;construct string to appear on-screen
ADDIU	A0,SP,002C	;A0=target location for new string
//8009F154:
LW	V1,003C (SP)	;V1=current position in msg_txt (A0)
LW	T6,0034 (SP)	;T6=new position in text bank
SW	V0,0028 (SP)	;save strlen for new, happy string
LW	A0,0038 (SP)	;A0=msg_txt text bank
LW	A3,0040 (SP)	;A3=size of msg_txt
SW	R0,0010 (SP)
ADDU	A1,V1,V0		;A1=strlen+msg_txt position
JAL	8009EA2C		;extend bank for new string: ret V0=new size
ADDU	A2,V1,T6		;A2=old msg_txt position + increment over command
//8009F178:
LW	T7,0038 (SP)	;p->text bank
LW	T8,003C (SP)	;T8=cur. pos in msg_txt
SW	V0,0024 (SP)	;save new bank size
ADDIU	A1,SP,002C	;p->new string
LW	A2,0028 (SP)	;A2=strlen for new string
JAL	8009EB44		;copy string to destination
ADDU	A0,T7,T8		;A0=p->cur pos in text bank
//8009F194:
LW	V0,0024 (SP)	;V0=new size of text bank
LW	RA,001C (SP)
ADDIU	SP,SP,0038
JR	RA
NOP


800C42E8	0x	construct the 'minutes' string
ADDIU	SP,SP,FFE0
SW	A1,0024 (SP)	;save minutes
ANDI	A1,A1,00FF
SW	RA,001C (SP)
SW	A0,0020 (SP)	;save target location
SLTI	AT,A1,003C	;if 60 or over, manually set to 0
BNEZ	AT,800C430C
LW	A0,0020 (SP)	;A0=target loc for string (limit 8 char)
OR	A1,R0,R0
//800C430C:
ADDIU	A2,R0,0004	;A2=strlen (4)
ADDIU	A3,R0,0001
JAL	8009264C		;constructs the "X" minutes string
SW	R0,0010 (SP)
//800C431C:
LW	T6,0020 (SP)	;T6=target loc
ADDIU	T7,R0,0004	;T7=max strlen, 4
SUBU	A1,T7,V0		;A1=how many characters are left in string
ADDIU	A2,R0,0007	;A2="Minutes" string from string_txt
JAL	800C3F70		;retrieve string from string_txt
ADDU	A0,T6,V0		;A0=p->next available byte in string
//800C4334:
LW	A0,0020 (SP)	;A0=string
JAL	8009E8D0		;returns V0=true strlen
ADDIU	A1,R0,0004	;A1=strlen
LW	RA,001C (SP)
ADDIU	SP,SP,0020
JR	RA
NOP

+-+-+

800A1308	0x	handle 7F23 'seconds' command
ADDIU	SP,SP,FFE8
SW	RA,0014 (SP)
SW	A0,0018 (SP)	;save controller for text bank
OR	A3,A1,R0		;A3=A1=p->current position in bank
LW	T6,0018 (SP)	;T6=controller for text bank
LW	A1,0000 (A3)	;A1=current position in bank
LW	V0,000C (T6)	;V0=p->text bank data
ADDIU	A0,V0,0010	;A0=p->text bank
JAL	8009F1A8		;retrieve secs and insert the string; ret V0=new text bank size
LW	A2,0008 (V0)	;A2=size of bank
LW	T7,0018 (SP)	;T7=controller for text bank
LW	T8,000C (T7)	;T8=p->text bank data
SW	V0,0008 (T8)	;save new max size
LW	RA,0014 (SP)
OR	V0,R0,R0
JR	RA
ADDIU	SP,SP,0018

8009F1A8	0x	generate seconds string and insert into text
ADDIU	SP,SP,FFC8
SW	RA,001C (SP)
SW	A0,0038 (SP)	;A0=msg_txt text bank
SW	A1,003C (SP)	;A1=current position in msg_txt (A0)
SW	A2,0040 (SP)	;A2=size of msg_txt
LW	A0,0038 (SP)
JAL	800903A8		;advance position to next 'character'
LW	A1,003C (SP)
//8009F1C8:
LUI	A1,8013
SW	V0,0034 (SP)	;save increment to new position in text bank
LBU	A1,6FBC (A1)	;A1=80136FBC - seconds
JAL	800C4350		;construct string to appear on-screen
ADDIU	A0,SP,002C	;A0=target location for new string
//8009F1DC:
LW	V1,003C (SP)	;V1=current position in msg_txt (A0)
LW	T6,0034 (SP)	;T6=new position in text bank
SW	V0,0028 (SP)	;save strlen for new, happy string
LW	A0,0038 (SP)	;A0=msg_txt text bank
LW	A3,0040 (SP)	;A3=size of msg_txt
SW	R0,0010 (SP)
ADDU	A1,V1,V0		;A1=strlen+msg_txt position
JAL	8009EA2C		;extend bank for new string: ret V0=new size
ADDU	A2,V1,T6		;A2=old msg_txt position + increment over command
//8009F200:
LW	T7,0038 (SP)	;p->text bank
LW	T8,003C (SP)	;T8=cur. pos in msg_txt
SW	V0,0024 (SP)	;save new bank size
ADDIU	A1,SP,002C	;p->new string
LW	A2,0028 (SP)	;A2=strlen for new string
JAL	8009EB44		;copy string to destination
ADDU	A0,T7,T8		;A0=p->cur pos in text bank
//8009F21C:
LW	V0,0024 (SP)	;V0=new size of text bank
LW	RA,001C (SP)
ADDIU	SP,SP,0038
JR	RA
NOP


800C4350	0x	generate "#seconds" string
ADDIU	SP,SP,FFE0
SW	A1,0024 (SP)	;save minutes
ANDI	A1,A1,00FF
SW	RA,001C (SP)
SW	A0,0020 (SP)	;save target location
SLTI	AT,A1,003C	;if 60 or over, manually set to 0
BNEZ	AT,800C4374
LW	A0,0020 (SP)	;A0=target loc for string (limit 8 char)
OR	A1,R0,R0
//800C4374:
ADDIU	A2,R0,0005	;A2=strlen (5)
ADDIU	A3,R0,0001
JAL	8009264C		;constructs the "X" secs string
SW	R0,0010 (SP)
//800C4384:
LW	T6,0020 (SP)	;T6=target loc
ADDIU	T7,R0,0005	;T7=max strlen, 5
SUBU	A1,T7,V0		;A1=how many characters are left in string
ADDIU	A2,R0,0008	;A2="Seconds" string from string_txt
JAL	800C3F70		;retrieve string from string_txt
ADDU	A0,T6,V0		;A0=p->next available byte in string
//800C439C:
LW	A0,0020 (SP)	;A0=string
JAL	8009E8D0		;returns V0=true strlen
ADDIU	A1,R0,0005	;A1=strlen
LW	RA,001C (SP)
ADDIU	SP,SP,0020
JR	RA
NOP


+-+-+

Generic Functions

8009EA2C	0x	extend msg_txt bank for a newly-created string (ie. hours 7F com.)
	accepts: A0=p->text bank, A1=cur text pos.+size of created string.A2=cur text pos.+command size.A3=size of text bank
	returns: V0=new size of text bank
SLT	AT,A1,A2
BEQ	AT,R0,8009EAA4	;branch if created string > command size
OR	V1,A3,R0		;V1=max length of bank
SLT	AT,A2,A3
BEQ	AT,R0,8009EA68	;branch if cur+com exceeds bank size
ADDU	V0,A0,A1		;V0=p->cur+created
//8009EA44:	when string is smaller than command (0 or 1)
ADDU	V1,A0,A2		;V1=p->cur+com size
LBU	T6,0000 (V1)	;load org.
ADDIU	A2,A2,0001	;ORG++
SLT	AT,A2,A3
ADDIU	A1,A1,0001	;target++
ADDIU	V0,V0,0001	;p->target++
ADDIU	V1,V1,0001	;p->org++
BNEZ	AT,8009EA48	;continue until all copied
SB	T6,FFFF (V0)	;save to new
//8009EA68:
LW	T8,0010 (SP)	;???  probably a flag indicating 1=space-extend
SUBU	T7,A3,A2		;difference in bank size and command size
ADDU	V1,T7,A1		;V1=cur+difference
BEQ	T8,R0,8009EB38
SLT	AT,A1,A3		;true if cur<bank size
BEQ	AT,R0,8009EB38
ADDU	V0,A0,A1		;V0=p->cur+created
//8009EA84:	extend with spaces, maybe
ADDIU	A0,R0,0020	;A0=" " (space)
ADDIU	A1,A1,0001
SLT	AT,A1,A3
SB	A0,0000 (V0)
BNEZ	AT,8009EA88	;loop and fill with spaces
ADDIU	V0,V0,0001
BEQ	R0,R0,8009EB3C
OR	V0,V1,R0
//8009EAA4:
SLT	AT,A2,A1		;true if com < created
BEQ	AT,R0,8009EB38	;effectively, testing if equivalent from first test
SUBU	T0,A3,A2		;T0=difference in cur+com and endpoint
SUBU	T9,A1,A2		;T9=difference in cur and command
ADDU	V1,A3,T9		;V1=max+'extension' to write out created string
SLTI	AT,V1,0401
BEQ	AT,R0,8009EB38	;bail if exceeding max bank size 0x400
OR	V0,T0,R0		;V0=difference in cur+com and endpoint
ADDU	A1,A0,V1		;A1=p->extended endpoint
ADDU	A2,A0,A3		;A2=p->endpoint
ADDIU	A1,A1,FFFF	;A1--
ADDIU	A2,A2,FFFF	;A2--
BLEZ	T0,8009EB38	;branch if no change or reduction would occur
OR	T1,R0,R0		;T1=counter
ANDI	A3,T0,0003	;skip if no non-word aligned bytes hanging
BEQ	A3,R0,8009EB08
OR	A0,A3,R0		;A0=counter for the non-words
//8009EAE8:	copy non-words one byte at a time
LBU	T2,0000 (A2)
ADDIU	T1,T1,0001	;counter++
ADDIU	A1,A1,FFFF
ADDIU	A2,A2,FFFF
BNE	A0,T1,8009EAE8	;loop for small fries
SB	T2,0001 (A1)
BEQL	T1,T0,8009EB3C	;if that's it, quit
OR	V0,V1,R0		;V0=new endpoint
//8009EB08:
LBU	T3,0000 (A2)
ADDIU	T1,T1,0004
ADDIU	A1,A1,FFFC
SB	T3,0004 (A1)
LBU	T4,FFFF (A2)
ADDIU	A2,A2,FFFC
SB	T4,0003 (A1)
LBU	T5,0002 (A2)
SB	T5,0002 (A1)
LBU	T6,0001 (A2)
BNE	T1,V0,8009EB08
SB	T6,0001 (A1)
//8009EB38:	QUIT
OR	V0,V1,R0
JR	RA
NOP

8009EB44	0x	copy source to destination - used by text insertion routines
	accepts: A0=p->copy location,A1=source location, A2=strlen
	returns: 
BLEZ	A2,8009EBA8
OR	V0,R0,R0
ANDI	A3,A2,0003
BEQ	A3,R0,8009EB78	;branch if no non-word-aligned stuff hanging on
OR	V1,A3,R0
//8009EB58:	copy source (A1) to A0
LBU	T6,0000 (A1)
ADDIU	V0,V0,0001
ADDIU	A0,A0,0001
ADDIU	A1,A1,0001
BNE	V1,V0,8009EB58
SB	T6,FFFF (A0)
BEQ	V0,A2,8009EBA8	;if that was it, you're done
NOP
//8009EB78:	write 'words'
LBU	T7,0000 (A1)
ADDIU	V0,V0,0004
ADDIU	A0,A0,0004
SB	T7,FFFC (A0)
LBU	T8,0001 (A1)
ADDIU	A1,A1,0004
SB	T8,FFFD (A0)
LBU	T9,FFFE (A1)
SB	T9,FFFE (A0)
LBU	T0,FFFF (A1)
BNE	V0,A2,8009EB78
SB	T0,FFFF (A0)
//8009EBA8:	quit
JR	RA
NOP
