Index: trunk/Assembly_Library/Src/Display/DisplayFormatCompressed.asm
===================================================================
--- trunk/Assembly_Library/Src/Display/DisplayFormatCompressed.asm	(revision 195)
+++ trunk/Assembly_Library/Src/Display/DisplayFormatCompressed.asm	(revision 202)
@@ -1,23 +1,16 @@
 ; Project name	:	Assembly Library
 ; Description	:	Functions for displaying formatted strings.
-;                   ** Compressed Strings edition **
-;
-; Authors   	:	Greg Lindhorst
-;				:	gregli@hotmail.com
-;               :		
-;				:	Tomi Tilli
-;				:	aitotat@gmail.com
-;				:
-; Description	:	This is a plug replacement for DisplayFormat.asm,
-;                   working instead with precompiled and slightly compressed strings.
+;					** Compressed Strings edition **
+;					This is a plug replacement for DisplayFormat.asm,
+;					working instead with precompiled and slightly compressed strings.
 ;
 ; Strings are compressed in a simple manner:
 ;	1. The two most common characters, space and null, are removed
-;   2. Format specifiers are reduced to a single byte, including length information
+;	2. Format specifiers are reduced to a single byte, including length information
 ;
 ; Format of bytes in the string are:
 ;     01 xxxxxx     Character in x plus StringsCompressed_NormalBase
 ;     10 xxxxxx     Character in x plus StringsCompressed_NormalBase, followed by a null (last character)
-;     11 xxxxxx     Character in x plus StringsCompressed_NormalBase, followed by a space		
+;     11 xxxxxx     Character in x plus StringsCompressed_NormalBase, followed by a space
 ;     00 1 yyyyy    Character/Format in lookup table StringsCopmressed_TranslatesAndFormats
 ;     00 0 yyyyy    Character/Format in lookup table StringsCompressed_TranslatesAndFormats, followed by a null
@@ -31,8 +24,8 @@
 ;
 ; The assignments of the first two bits above is not by accident.  The translates/format branch is 00
-; which is easy to test for.  The '01' for "normal" (no null or space) and '001' for translates/format "normal" 
+; which is easy to test for.  The '01' for "normal" (no null or space) and '001' for translates/format "normal"
 ; match, allowing the translates/format codes to be shifted left by 1 and then tested with the same instructions.
 ;
-; It is always possible to say that a null character follows the current character - thus there is 
+; It is always possible to say that a null character follows the current character - thus there is
 ; no way (nor need) to specify a zero character.
 ;
@@ -41,5 +34,5 @@
 ; much "preload", just in case a branch is taken, but that is cheaper (in size) than adding additional branches.
 ;
-		
+
 ; Section containing code
 SECTION .text
@@ -49,5 +42,5 @@
 ;
 ; Names of format handlers are DisplayFormatCompressed_Format_* where * is
-; replaced with the format code after the '%' in the original string, 
+; replaced with the format code after the '%' in the original string,
 ; with '-' replaced with '_'.
 ;
@@ -87,9 +80,9 @@
 	jz		DisplayFormat_ParseCharacters
 	; fall through
-		
+
 DisplayFormatCompressed_Format_2_u:
 	mov		bh,2						; only two characters (instead of the default 5)
 	; fall through
-		
+
 DisplayFormatCompressed_Format_u:
 DisplayFormatCompressed_Format_5_u:
@@ -101,6 +94,6 @@
 	div		si							; DX:AX / 10 => AX=quot, DX=rem
  	push	dx							; Push digit
-		
-	dec		bh							
+
+	dec		bh
 	jnz		.DivLoop
 
@@ -114,18 +107,17 @@
 												; if it is zero, DisplayPrint_CharacterFromAL will not emit
 
-	or		bh, al						; skip leading zeros, bh keeps track if we have emitted anythng non-zero
+	or		bh, al						; skip leading zeros, bh keeps track if we have emitted anything non-zero
 	jnz		.PrintDigit					; note that bh starts at zero, from the loop above
 
-	test	ch,2						; are we padding with leading spaces?  
+	test	ch,2						; are we padding with leading spaces?
 	jnz		.PrintLoop					; test the even/odd of the format byte in the string
 
-	mov		al,' '-'0'					; emit space, but let the following instuctions add '0'
-
-.PrintDigit:	
-	add		al,'0'						; Digit to character
-	cmp		al,'9'						; for hex output, greater than '9'?
-	jle		.NoHexAdjustment
-	add		al,'A'-'9'-1				; adjust for hex output ('A' to 'F')
-.NoHexAdjustment:		
+	mov		al, 89h						; emit space
+
+.PrintDigit:
+	add		al, 90h						; Convert binary digit in AL to ASCII hex digit (0 - 9 or A - F)
+	daa
+	adc		al, 40h
+	daa
 
 	call	DisplayPrint_CharacterFromAL
@@ -133,5 +125,5 @@
 	jmp		.PrintLoop
 
-		
+
 ;--------------------------------------------------------------------
 ; DisplayFormat_ParseCharacters
@@ -146,16 +138,16 @@
 ;	Corrupts registers:
 ;		AX, BX, CX, DX, BP
-;--------------------------------------------------------------------		
+;--------------------------------------------------------------------
 
 DisplayFormatCompressed_BaseFormatOffset:
-		
+
 DisplayFormat_ParseCharacters_FromAX:
 	mov		si,ax
 	; fall through to DisplayFormat_ParseCharacters
 
-ALIGN JUMP_ALIGN		
-DisplayFormat_ParseCharacters:	
-;
-; This routine is used to outptu all strings from the ROM.  The strings in ROMVARS are not compressed, 
+ALIGN JUMP_ALIGN
+DisplayFormat_ParseCharacters:
+;
+; This routine is used to output all strings from the ROM.  The strings in ROMVARS are not compressed,
 ; and must be handled differently.
 ;
@@ -165,6 +157,6 @@
 
 .decode:
-	mov		al,[cs:si]			; load next byte of the string
-	inc		si
+	eSEG	cs
+	lodsb						; load next byte of the string
 
 	mov		ch,al				; save a copy for later processing of high order bits
@@ -175,7 +167,7 @@
 	and		al,03fh								; "Normal" character, mask off high order bits
 	add		al,StringsCompressed_NormalBase		; and add character offset (usually around 0x40)
-		
+
 .output:
-	call 	DisplayPrint_CharacterFromAL		
+	call 	DisplayPrint_CharacterFromAL
 
 .process_after_output:
@@ -189,5 +181,5 @@
 
 ALIGN JUMP_ALIGN
-DisplayFormatCompressed_TranslatesAndFormats:		
+DisplayFormatCompressed_TranslatesAndFormats:
 ;
 ; This routine is here (above DisplayFormat_ParseCharacters) to reduce the amount of code between
@@ -201,5 +193,5 @@
 
 	cmp		al,StringsCompressed_FormatsBegin			; determine if this is a translation or a format
-														
+
 	mov		al,[cs:bx]									; fetch translation/formats byte
 
@@ -208,5 +200,5 @@
 														; note that the flags for this conditional jump were
 														; set with the cmp al,StringsCompressed_FormatsBegin
-		
+
 	mov		dx,DisplayFormatCompressed_BaseFormatOffset   ; calculate address to jump to for format handler
 	sub		dx,ax
@@ -231,13 +223,2 @@
 	jmp		DisplayFormat_ParseCharacters.process_after_output	; continue postprocessing, check for end of string
 
-
-
-
-
-
-		
-
-		
-	
-
-
