best way to display decimal number?
Moderator: Moderators
best way to display decimal number?
Okay.. so you're coding completely in assembler. Now, you have a number from $00 to $FF that you want to display on the screen for the user, but it needs to be displayed in decimal 000 to 255. What is the easiest/best way to accomplish this?
- Mike
- Herr VC
- Posts: 4816
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
The easiest is most probably using three 256 byte tables for hundreds, tenths, and units of the number to be displayed.
For a more compact version take a look at the 6502 source code repository, binary to BCD conversion. Be forewarned though, these examples use the decimal mode of the 6502, and you'll need to include an IRQ routine wedge that makes a CLD before entering other interrupt processing.
The routines result in a BCD number, where 4 bits at a time can be shifted out, and an offset value (for example, $30) added to display a single digit.
There's also the routine to print the line number at $DDCD. It prints the integer in X/A. It however relies on kernal print routines, and will require you to position the cursor beforehand.
Greetings,
Michael
P.S.: Since this is already the 4th thread of a programming question regarding the same project of yours, I'd like to kindly ask you to keep these questions in a single thread.
For a more compact version take a look at the 6502 source code repository, binary to BCD conversion. Be forewarned though, these examples use the decimal mode of the 6502, and you'll need to include an IRQ routine wedge that makes a CLD before entering other interrupt processing.
The routines result in a BCD number, where 4 bits at a time can be shifted out, and an offset value (for example, $30) added to display a single digit.
There's also the routine to print the line number at $DDCD. It prints the integer in X/A. It however relies on kernal print routines, and will require you to position the cursor beforehand.
Greetings,
Michael
P.S.: Since this is already the 4th thread of a programming question regarding the same project of yours, I'd like to kindly ask you to keep these questions in a single thread.
Use HEXOUT for printing a word (two bytes, 4 digits) and HEX2 to print a byte.adric22 wrote:Well, it was too much work, so I just had it display in hex.
Code: Select all
;------------ PRINT HEX VALUE IN X/A
HEXOUT
pha
lda #"$"
jsr BSOUT
pla
beq HEX0
_relo0200 = . +1
jsr HEX2
HEX0
txa
HEX2
pha
lsr
lsr
lsr
lsr
jsr HEX1
pla
and #15
HEX1
clc
adc #246
bcc HEX1_2
adc #6
HEX1_2
adc #58
jmp BSOUT
An example would have been helpful, and I do use a lot of zero-page, but so far I've tried to stick with areas that only affect BASIC, and not the kernel.carlsson wrote:Do you need an exact example how to call the ROM routines? Does your program rely a lot on using the zeropage so you can't call Basic ROM which assumes certain things are not altered?
Still, I think I'm pretty happy with the way I am doing it now, because I don't think there would really be enough room on the screen for decimal numbers anyway. Here's a screenshot with the "GPS" turned on. You can toggle it on and off with the G key. that way it isn't overlaying your screens the whole time.
- Mike
- Herr VC
- Posts: 4816
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
(At least) three points to note here:adric22 wrote:... I don't think there would really be enough room on the screen for decimal numbers anyway.
- The VIC chip allows you to change the number of displayed rows, and columns,
- It is possible to dedicate 2 UDG's to a certain number, and produce a 3-digit display with 5 pixel wide digits, or even a 4-digit display with 4 pixel wide digits,
- For an example of a table-driven conversion, you might take a look at the display of TI$ in the border I wrote some time ago. It's a no-brainer to adjust the table to numbers of different size, and base.
Michael
I had already thought about doing #2, but it is just too much work. I've never heard of #1. How many columns can you get out of the VIC? I thought 22 was the max.Mike wrote:(At least) three points to note here:adric22 wrote:... I don't think there would really be enough room on the screen for decimal numbers anyway.
- The VIC chip allows you to change the number of displayed rows, and columns,
- It is possible to dedicate 2 UDG's to a certain number, and produce a 3-digit display with 5 pixel wide digits, or even a 4-digit display with 4 pixel wide digits,
- For an example of a table-driven conversion, you might take a look at the display of TI$ in the border I wrote some time ago. It's a no-brainer to adjust the table to numbers of different size, and base.
- Mike
- Herr VC
- Posts: 4816
- Joined: Wed Dec 01, 2004 1:57 pm
- Location: Munich, Germany
- Occupation: electrical engineer
That depends on whether you're using PAL or NTSC. With PAL, you easily can display 26 columns, and 32 rows. NTSC is more restricted. In most cases you don't get beyond 24 columns, and 27 or 28 rows.adric22 wrote:How many columns can you get out of the VIC?
This is because PAL VICs display a bigger border to begin with. The absolute size of the character cells isn't changed for this.
The number of rows, and columns, and horizontal, and vertical positioning are controlled by the VIC registers 36864 .. 36867. The default register values are stored from $EDE4 onwards, and they are different between PAL, and NTSC.
-
- Vic 20 Devotee
- Posts: 269
- Joined: Mon Feb 04, 2008 6:06 am
I wrote a Binary to BCD subroutine for the SX28 recently. I posted some notes for how it works on my blog http://richardjames13.wordpress.com/200 ... onversion/
Change is inevitable except from a vending machine.