Simulating decimal mode
Moderator: Moderators
- TmEE
- Posts: 789
- Joined: Wed Feb 13, 2008 9:10 am
- Location: Estonia, Rapla city (50 and 60Hz compatible :P)
- Contact:
Re: Simulating decimal mode
In my case summing scores and stuff in binary and then converting to decimal once a frame for showing takes a lot less time than trying to calculate stuff in BCD so in the ond you could show it in an easier manner...
- Omegamatrix
- Posts: 35
- Joined: Tue Jun 10, 2014 8:15 pm
- Location: Canada
Re: Simulating decimal mode
Hello Bregalad,Bregalad wrote:True, my binary -> decimal routines takes a total of 23 bytes, and I don't think it's possible to shrink it further (it could be simplified if 0-9 digits were 0-9 in the pattern table instead of $d0-$d9 but I don't want to do that).Code: Select all
ldy #$00 - cmp #10 bcc + sbc #10 iny ;Y count tens bne - + ora #$d0 sta StringBuffer+1.w,X ;The units is written 1 tile forwad tya ora #$d0 ;Convert into tile # sta StringBuffer.w,X ;Write the tens rts
I was looking at your code, and I believe you can reduce it further like this:
Code: Select all
ldy #$D0-1
sec
.loopDivTen:
iny
sbc #10
bcs .loopDivTen
adc #$DA
sta StringBuffer+1,X
sty StringBuffer,X
rtsI am new to the NES, but no stranger to 6502 assembly. I've programmed a lot of 2600 code... not too sure if there is anyone else on these boards from AtariAge, but they may recognize my username from there.
I have always been interested in math routines. I have wrote a lot of unsigned integer division routines, and lately have become more interested in hex to decimal routines. All of these routines are posted in my blog here:
http://atariage.com/forums/blog/563-omegamatrixs-blog/
Early in this thread it was mentioned limiting each byte to 0-63 Hex, and then convert each byte as need be. This seems like a reasonable approach to me. Is this what most NES programmers do? It would keep the addition pretty simple. In my blog I have tackled a hex to decimal (0-65535) conversion, and while my routine does the job in 156-168 cycles, it still requires 263 bytes.
Re: Simulating decimal mode
Oh! Hey, Omegamatrix. I do recognize the name from this thread: http://atariage.com/forums/topic/113254 ... ven/page-5
Off topic: I'd planned to ask a few people eventually, but I've generally operated under the assumption routines posted in threads like that are public domain. Is this true for yours? I'm currently using your divide by 5/10 routine. More on topic, how about this decimal routine that probably beats whatever I'm using now? Was gonna PM you on atariage to ask how/if you'd like credit, but now you're here.
Off topic: I'd planned to ask a few people eventually, but I've generally operated under the assumption routines posted in threads like that are public domain. Is this true for yours? I'm currently using your divide by 5/10 routine. More on topic, how about this decimal routine that probably beats whatever I'm using now? Was gonna PM you on atariage to ask how/if you'd like credit, but now you're here.
- Omegamatrix
- Posts: 35
- Joined: Tue Jun 10, 2014 8:15 pm
- Location: Canada
Re: Simulating decimal mode
Hello Kasumi,Kasumi wrote:Oh! Hey, Omegamatrix. I do recognize the name from this thread: http://atariage.com/forums/topic/113254 ... ven/page-5
Off topic: I'd planned to ask a few people eventually, but I've generally operated under the assumption routines posted in threads like that are public domain. Is this true for yours? I'm currently using your divide by 5/10 routine. More on topic, how about this decimal routine that probably beats whatever I'm using now? Was gonna PM you on atariage to ask how/if you'd like credit, but now you're here.
All of the math routines I post are public domain. I want people to use them.
If you are using the divide by 5 and divide by 10 routines, then be sure to check my blog for the latest and greatest as I didn't post all of the updated routines in the thread you linked to.
By the way, here is the divide by 5:
Code: Select all
sta temp
lsr
adc #13
adc temp
ror
lsr
lsr
adc temp
ror
adc temp
ror
lsr
lsr- Omegamatrix
- Posts: 35
- Joined: Tue Jun 10, 2014 8:15 pm
- Location: Canada
Re: Simulating decimal mode
I just realized that you are storing Absolute,X and not Zeropage,X.
In this case a TYA has to be added back in since there is no STY Absolute,X instruction. It now uses 18 bytes which is still not too bad.
In this case a TYA has to be added back in since there is no STY Absolute,X instruction. It now uses 18 bytes which is still not too bad.
Code: Select all
ldy #$D0-1
sec
.loopDivTen:
iny
sbc #10
bcs .loopDivTen
adc #$DA
sta StringBuffer+1,X
tya
sta StringBuffer,X
rts