It is currently Tue Oct 17, 2017 5:27 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Jun 16, 2016 2:42 pm 
Offline

Joined: Thu Aug 28, 2008 1:17 am
Posts: 591
Sik wrote:
tomaitheous wrote:
I think having a 256 LUT, which outputs 0 to 99.

You only need 100 entries for that ;P

Well, you did mention speed...

Up the 256 to 512bytes..
Code:
ByteBin2Dec:
    lda TableDec,x
    ldy SwapLowNybble2BCD,x
    ldx TableDec,y
  rts

Input is byte in X. Returns BCD in two bytes via X:A.

Edit: I guess it doesn't make any sense to have a whole 'nother 256 LUT for high nybble shift and extraction, when it can just convert it directly. So just TableDec and TableDecUpper. I also thought you could simply cascade afterwards, for a larger binary conversion using this method, but I just realized that's not going to work. Meh...

_________________
__________________________
http://pcedev.wordpress.com


Top
 Profile  
 
PostPosted: Thu Jun 16, 2016 3:45 pm 
Offline

Joined: Thu Aug 12, 2010 3:43 am
Posts: 1589
tomaitheous wrote:
Well, you did mention speed...

Checking for 100 or 200 is nothing compared to doing a division by 10 to split the tens from the units.


Top
 Profile  
 
PostPosted: Thu Jun 16, 2016 4:30 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19091
Location: NE Indiana, USA (NTSC)
If you understand "checking for 200", then you can understand my routine as applying the same concept to 200, 100, 80, 40, 20, and 10.


Top
 Profile  
 
PostPosted: Fri Jun 17, 2016 9:09 pm 
Offline
User avatar

Joined: Tue Jun 10, 2014 8:15 pm
Posts: 35
Location: Canada
tomaitheous wrote:
Sik wrote:
The problem isn't that, the problem is doing it quickly.


What's the fast method for doing this on the NES?

I think having a 256 LUT, which outputs 0 to 99. And for the last digit in the 100s place, simply check of the original byte is greater than 200 (populate a 2) or greater than 100 (populate a 1). Since NES doesn't have decimal mode like other 65x, you can't easily cascade two more bytes in this process unfortunately.


Here are some quick Hex to Decimal methods I have wrote.

viewtopic.php?p=130363#p130363


And a quick summary of the routines byte usage and cycles. The cycles include the JSR/RTS.:
Code:
;slow routine - 174 bytes, 183 bytes with HexToDec255 and HexToDec999
;HexToDec99     ; 37 cycles
;HexToDec255    ; 52-57 cycles
;HexToDec999    ; 72-77 cycles
;HexToDec65535  ; 178-186 cycles


;Fast routine - 234 bytes, 243 bytes with HexToDec255 and HexToDec999
;HexToDec99     ; 37 cycles
;HexToDec255    ; 52-57 cycles
;HexToDec999    ; 72-77 cycles
;HexToDec65535  ; 157-162 cycles

;-------------------------------------------------------------------------------

;HexToDec99
; start in A
; end with A = 10's, decOnes

;HexToDec255
; start in A
; end with Y = 100's, A = 10's, decOnes

;HexToDec999
; start with A = high byte, X = low byte
; end with Y = 100's, A = 10's, decOnes
; requires 1 extra temp register on top of decOnes, could combine
; these two if HexToDec65535 was eliminiated...

;HexToDec65535
; start with A = high byte, X = low byte
; end with decTenThousand, decThousand, Y = 100's, A = 10's, decOnes
; requires 2 extra temp registers on top of decTenThousand, decThousand, decOnes


Top
 Profile  
 
PostPosted: Sat Jul 02, 2016 4:35 pm 
Offline
User avatar

Joined: Mon Jul 14, 2014 6:05 am
Posts: 88
Location: Lausanne, Switzerland
Sik wrote:
The problem isn't that, the problem is doing it quickly.


I actually wanted to do this once with 16-bit vars, and here is the code I came up with viewtopic.php?f=2&t=13816 if that's what you're asking for


Top
 Profile  
 
PostPosted: Sun Jul 03, 2016 8:55 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 709
Location: New York, NY
Off topic, but the original post reminded me of a question I had about Baskin-Robbins: Why 31 flavors instead of 32? But, it turns out to have nothing to do with base-2 math. Rather, it's a flavor for everyday of the month.

Edit: Also this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group