A86: Custom Number Displaying Routines
[Prev][Next][Index][Thread]
A86: Custom Number Displaying Routines
I wrote up a small document about writing your own custom number
displaying routines if anyone is interested. It will be on my web page
when I have the time... Also.., some of these routines are very useful
for diagnosing problems in asm programs.
Later,
Matt
Custom number displaying routines v1.0
Matt Johnson
1st revision: 7/21/98
I have thrown this document together because many people requested better methods for
displaying a number. BTW, Please don't read my old tutorials that are in text format.
Please check out my web site. Some things of mine are still lurking around on TICALC.ORG
or TI-Files that is almost a year old! The newest ones will always be in HTML and on my
site.
Future revisions:
1.) I plan to convert this into HTML and put it on my site
2.) I plan to have it so you can display the number in HEX
3.) I plan to make a custom _puts routine, based on the bitmaps stored in the rom.
This will be useful for cool effects in grayscale, for example.
4.) Maybe a 24-bit number displaying routine. That shouldn't be too hard
5.) Any suggestions??
http://www.dogtech.com/cybop/ti86/
matt2000@gte.net
-----------------------------------------------
UNPACK_HL, defined in asm86.h puts (HL mod 10) in A and (HL div 10)
A = HL mod 10 (the remainder after you divide HL by 10)
HL = HL / 10 (HL is divided by 10)
So suppose HL = 56
call UNPACK_HL
HL now is 5
and A = 6
Now save A into B and call it again
call UNPACK_HL
Now HL is 0
and A = 5
So A is the first digit and B is the second digit
Once we have the digit, we can add it with 48 (which is the ASCII start of the '0'
character) and the correct character will be selected, based on that number.
---------------------------------------------------------------
The following routine will display a 2-digit number from 0 - 99
---------------------------------------------------------------
Disp2dNum:
push af \ push bc \ push de \ push hl
ld h, 0
ld l, a
call UNPACK_HL
add a, 48
ld b, a ; Save 2nd digit
call UNPACK_HL
add a, 48 ; 48 starts at ASCII character '0'
call _vputmap ; Display 1st digit
ld a, b
call _vputmap ; Display 2nd digit
pop hl \ pop de \ pop bc \ pop af
ret
---------------------------------------------------------------
Now a 8-bit number can have up to 3 digits, because it is in the range of 0 to 255
And a 16-bit number can have up to 5 digits, because it is in the range of 0 to 65,535
.
.
.
---------------------------------------------------------------
The following routine will display a 3-digit number from 0 - 255
---------------------------------------------------------------
Display3dNum:
push af \ push bc \ push de \ push hl
ld h, 0
ld l, a
call UNPACK_HL
add a, 48 ; 48 is the start of character '0' (zero)
ld c, a ; Save 3rd digit
call UNPACK_HL
add a, 48
ld b, a ; Save 2nd digit
call UNPACK_HL
add a, 48 ; A = 1st digit
call _vputmap ; Display 1st digit
ld a, b
call _vputmap ; Display 2nd digit
ld a, c
call _vputmap ; Display 3rd digit
pop hl \ pop de \ pop bc \ pop af
ret
---------------------------------------------------------------
As you see it supports three digits. The above routine is useful for diagnosing problems. You can easily keep track
of registers and variables in a loop. If you add a call _getkey then you can pause your program for each step to track
the current number. And the above routine will display any 8-bit number as a small font. If you need to display a 16-bit
number, see below.
If you plan on displaying HL, you will need a total of 5 digits.
Because of this, it is best that you use a loop. I can't help but love Jimmy Mardells DispHL routine.
He uses the OP register to store each digit. It was only designed for 4 digits, but all you have to do
is change a few things to make it 5 digits. The routine stores a null terminator at _OP1 + 5, because
it uses a _puts routine. A loop then simply decreases the pointer and stores each digit. You can use
any memory location if you wish, and you can even use the stack if you wish also. Let's check out
his routine:
---------------------------------------------------------------
Jimmy Mardell's DispHL routine (0-9999)
---------------------------------------------------------------
push af \ push bc \ push de \ push hl
ld b, 5 ; Up to 4 digits (max 9,999) and 1 byte for the null terminator
ld de, _OP1 + 5 ; The start where the last digit will be stored
xor a
ld (de), a ; _OP1 + 5 = null terminator (signals _puts to stop putting :))
RepDispHL:
call UNPACK_HL ; Truncate HL it's rightmost digit (stored in A)
dec de ; Decrease pointer
add a, 48 ; Points at the start of the '0' (zero) character
ld (de), a ; Store character into memory
djnz RepDispHL ; Create character string which is the number
ex de, hl ; HL -> Start of the string which contains each
; character representation of each digit
call _puts ; Display it
pop hl \ pop de \ pop bc \ pop af
ret
---------------------------------------------------------------
If you change all the 5's to 6's, like change ld b, 5 to ld b, 6 and ld de, _OP1+5 to ld de, _OP1+6 this should
allow you to display HL as a 5-digit number, that is, in the range of 0 - 65,535
Any corrections, comments, complaints, additions, etc?
E-mail me at: matt2000@gte.net
Later,
Matt
Follow-Ups: