255 rubies in "The Legend of Zelda"?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

tomaitheous
Posts: 592
Joined: Thu Aug 28, 2008 1:17 am
Contact:

Re: 255 rubies in "The Legend of Zelda"?

Post by tomaitheous »

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: Select all

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
Sik
Posts: 1589
Joined: Thu Aug 12, 2010 3:43 am

Re: 255 rubies in "The Legend of Zelda"?

Post by Sik »

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.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: 255 rubies in "The Legend of Zelda"?

Post by tepples »

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.
User avatar
Omegamatrix
Posts: 35
Joined: Tue Jun 10, 2014 8:15 pm
Location: Canada

Re: 255 rubies in "The Legend of Zelda"?

Post by Omegamatrix »

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: Select all

;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
User avatar
Vectrex2809
Posts: 97
Joined: Mon Jul 14, 2014 6:05 am
Location: Tokyo, Japan

Re: 255 rubies in "The Legend of Zelda"?

Post by Vectrex2809 »

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
User avatar
zeroone
Posts: 933
Joined: Mon Dec 29, 2014 1:46 pm
Location: New York, NY
Contact:

Re: 255 rubies in "The Legend of Zelda"?

Post by zeroone »

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.
Post Reply