Search found 35 matches

by Omegamatrix
Tue Jun 17, 2014 8:02 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

But so long as the cart doesn't put something with read side effects into $6xxx, BIT $6469 should work. (The addresses with read side effects on the NES are $2002, $2007, $4015-$4017, and $4020-$5FFF for the Vs. System's credit acknowledge.) The only mapper that I can think of that has read side ef...
by Omegamatrix
Tue Jun 17, 2014 7:48 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

Omegamatrix, nice code, but what I am more interested in at the moment is how you determine the following: ;-------------------------------- ;0-99 conversion stats ;-------------------------------- ;cycles occurances ;28 - 10 ;31 - 10 ;34 - 10 ;37 - 10 ;39 - 10 ;42 - 10 ;45 - 10 ;48 - 10 ;50 - 10 ;...
by Omegamatrix
Mon Jun 16, 2014 11:04 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

I updated the Hex to Decimal routine (0-255) to rev 2 in the above post. I've chopped 3 bytes out of the old routine and slightly speed it up.

I'm doing BIT $6469 to skip over the ADC #100. From what I've seen of the NES memory map $6469 is just SRAM so reading there should be no problem...
by Omegamatrix
Sun Jun 15, 2014 9:31 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

Okay here is one that I just tweaked to handle both (0-99) and (0-255) separately. It takes 43 bytes and cycles are listed below including the 12 cycles for jumping and returning from the subroutines. Edit - This is now rev 3... uses less bytes, slightly faster average execution time, and the BIT in...
by Omegamatrix
Sun Jun 15, 2014 6:10 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

Thanks. Got anything to do 0-255 to three digits? My current routine is 53 bytes and takes 80 cycles including the RTS. Yes I do have some three digits. I am just preparing supper so I'll take a look in a bit. I also just realized I'm using a TAY at the end of the 16 bit routine for no reason. I co...
by Omegamatrix
Sun Jun 15, 2014 5:05 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

I have some other Hex to Decimal routines. Here is one I wrote that takes converts 0-63 hex to 0-99 BCD. It doesn't split the digits apart but keeps them in the same bytes. The routine is doing a divide by 10 and then times it by 6 before adding it back to the original sum. The good thing about this...
by Omegamatrix
Sun Jun 15, 2014 3:54 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

I've updated the divide by 22 with a quicker routine. Same amount of bytes as before. Old: ;Divide by 22 ;1/22 = 1/11 * 1/2 ;21 bytes, 37 cycles sta temp lsr lsr adc temp ror adc temp ror adc temp ror lsr adc temp ror lsr lsr lsr lsr New: ;Divide by 22 ;21 bytes, 34 cycles lsr cmp #33 adc #0 sta tem...
by Omegamatrix
Sun Jun 15, 2014 2:21 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

I don't 100% follow what you are trying to do here Raw digits: $00 means zero and $09 means 9. ASCII: $30 means zero and $39 means 9. Possible layout of tiles in an actual game: $06 means zero and $0F means 9, or $F6 means zero and $FF means 9. Gotcha. This is my in-experience with the NES coming i...
by Omegamatrix
Sun Jun 15, 2014 12:31 pm
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Re: Hex to Decimal

Very fast. Such efficiency. Wow. To save 2 cycles and 2 bytes, can this: lda hexHigh ;3 @3 and #$F0 ;2 @5 lsr ;2 @7 lsr ;2 @9 carry is clear, shifting just 2 times instead of 4, tay ;2 @11 since interlaced tables are used. lda hexHigh ;3 @14 and #$0F ;2 @16 tax ;2 @18 be replaced with this? lda hex...
by Omegamatrix
Sun Jun 15, 2014 11:16 am
Forum: NESdev
Topic: Hex to Decimal
Replies: 25
Views: 15506

Hex to Decimal

Here is a routine I wrote to convert a 16 bit number (0-65535) to decimal, each digit separated. It only takes 150 to 162 cycles as shown below. Edit - This is now revision 2 of the code... ;-------------------------------- ;0-9999 conversion stats ;-------------------------------- ;cycles occurance...
by Omegamatrix
Sun Jun 15, 2014 12:12 am
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

Final thoughts on divide by 40 before I go to bed. This is such a big number that you are approaching the limit where it is simply better to do a looped divide... if you don't mind the extra cycles and spending X or Y. I had another idea, this time using both X and Y. This routine takes 3 more bytes...
by Omegamatrix
Sat Jun 14, 2014 10:09 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

How does this work? You are dividing and adding that result to your original sum, and then repeating the process. The key is find the correct and shortest sequence of divisions you have to do. I had a simple idea for finding the divisions. I used a brute attack approach running every possible combi...
by Omegamatrix
Sat Jun 14, 2014 9:41 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

These are great! I needed a divide by 40 and modulo 40 for a http://en.wikipedia.org/wiki/DEC_Radix-50 decoder in a game I'm writing for the Commodore PET 2001( http://pettil.tumblr.com ) and the divide by 10 here looks like a good start. Thank you! The good thing here is that the 6502 was used by ...
by Omegamatrix
Sat Jun 14, 2014 1:27 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

Might you add some for calculating modulo as well? As well as 16-bit routines? With modulo, most of the time it should be easy enough to run the division routine, times the result, and subtract from the original sum. Multiplication is generally pretty easy... but sometimes can gobble up a lot of cy...
by Omegamatrix
Sat Jun 14, 2014 1:15 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 35739

Re: Unsigned Integer Division Routines

Didn't want to continue off topic in the other thread, but cool! The latest divide by 5 was in the atariage thread, but I do wish I had seen more of the others. Might as well say what I'm using them for. My game detects 49 slope heights. (flat, and 24 facing downward left, 24 facing downward right)...