Jump to content

3

Omegamatrix's Blog



Multiplying Two Integers (The Story of Maths)

Posted by Omegamatrix, in Math General 27 February 2016 · 513 views

I was watching The Story of Maths  on Netflix. One of the episodes discussed how ancient people discovered (example below):
 
4*6 = (5^2) - 1
 
or:
a*b = (a+1)^2 - 1, when b = a+2
 
The pattern here is that 4, 5, and 6 are all sequential integers. They also proved this pattern was valid for all integers. I found this interesting and ma...


Economical Initialization

Posted by Omegamatrix, in 2600 Routines 02 June 2015 · 635 views
Initialization
A while back I did an entry on Faster Initialization for the 2600. Today's entry is about squeezing the bytes out of the Initialization routine to the bare minimum. Here is a routine I came up with a while back:;Economical 8 byte initialization routine;By Omegamatrix cld.loopClear: ldx #$0A ; ASL opcode = $0A inx txs pha bne...


Hex to BCD conversion (0-99) Part Trois

Posted by Omegamatrix, in 6502 Math Routines 01 June 2015 · 678 views
Hex, BCD, Hex Conversion
I've covered some Hex to Decimal conversions like 0-255 and 0-65535 already in my blog, and have had done some previous solutions to 0-99 as well. Today I was thinking about converting a single byte from a hex value to BCD (0-99) once again. I came up with this routine which is the shortest, simplest, and fastest yet.;Hex2Bcd (good 0-99);22 bytes, 26 c...


Hex to Ascii String

Posted by Omegamatrix, in 6502 Math Routines 26 January 2015 · 872 views

I saw a topic on 6502.org about converting byte to hex string . I remembered Lee Davison's code shorts about converting 0 to 15 to ascii 0 to 15 by using decimal mode. I know Lee passed along this year so RIP Lee, I didn't know you but you seemed like a genius to me. :)
 
 
Using his basic code I came up with this for converting a byte:;HEX to...


Embedded Tables, Divide by 40, Mod 40

Posted by Omegamatrix, in Assembly Tricks, 6502 Math Routines 21 June 2014 · 1,072 views
Divide by 40, Mod 40
While posting my Unsigned Integer Division Routines on NesDev, a new member there said he was looking for a divide by 40 and mod 40. I wrote a few routines, but this one really sticks out as a neat idea.;Divide by and Mod 40 combined;38 bytes, 45 cycles;Y = value to be dividedInterlacedMultiplyByFortyTable: lda #0 ; dummy load, #0 used in LUT l...


Interlacing Tables, Table Reduction

Posted by Omegamatrix, in Assembly Tricks 21 June 2014 · 877 views

Sometimes you end up with routines that use a lot of tables. While writing my (0-65535) Hex to Decimal routine I ended up with a lot of 16 byte tables (6 of them actually). I realized that an optimization could be made by interlacing the tables. Normally I would do something like this: lda hexValue ;3 @3 lsr...


The Magic of EOR

Posted by Omegamatrix, in Assembly Tricks 21 June 2014 · 1,132 views
EOR
EOR is a useful function. I often use it in a situation where I already have "myNumber" in the accumulator, and I want to do a subtraction. Instead of doing this: sta temp ; myNumber (0 to 255) lda #$FF ; 255 sec sbc temp ; 255 - myNumber
You can just do this: eor #$FF ; 255 - myNumber
You save a lot of...


Hex to Decimal (0-255) Pt II

Posted by Omegamatrix, in 6502 Math Routines 08 June 2014 · 1,061 views
hex to decimal
I had another go at an one byte 'hex to decimal' conversion routine. This time I kept it simple. It's a much better effort, and much quicker then before! :)
 
Boring stats:;--------------------------------;0-255 conversion stats;--------------------------------;cycles occurances ;47 - 20 ;48 - 0 ;49 - 10 ;50 - 36 ;51 - 0 ;52 - 40...


Hex to Decimal (0-65535)

Posted by Omegamatrix, in 6502 Math Routines 07 June 2014 · 1,407 views
hex to decimal, 16 bit, NES
Continuing with my Hex to Decimal routines, I have written one for 16 bit numbers. :)
 
This routine is really geared toward a NES. The NES has no decimal mode. I think most of the time programmers will just break their scores out into multiple bytes (one for each digit), and then handle rollover cases for greater than 9, and less than 0.
 
Here...


(16 bit division), Fast divide by 10

Posted by Omegamatrix, in 6502 Math Routines 26 May 2014 · 1,871 views
16 bit, divide by 10
I took a stab at making a 16 bit division routine tonight. I took the approach of dividing the high and low bytes separately, since I have already written a bunch of 8 bit division routines. I then corrected the result with a couple of small look up tables.
 
 
This is the 16 bit routine I came up with. At 111 cycles max, and 96 bytes total it's...






August 2018

S M T W T F S
   1234
567891011
12131415161718
19 20 2122232425
262728293031 

Recent Comments

Latest Visitors

0 user(s) viewing

0 members, 0 guests, 0 anonymous users