Formatting 16-bit number as decimal?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

The simplest routines just need to specify how they accept and return values, and what registers they preserve. More complex ones need to specify any memory they use for temporary and persistent variables. That covers most routines. It's not hard at all to make modular libraries. When I realized this years ago, that assembly could be modularized just like C code, my assembly code became much cleaner and easy to work with. As with a high-level language, it helps to work out a small set of techniques, rather than doing obscure, unique things for each routine.
tepples
Posts: 22785
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Bregalad wrote:(I use [a square root function as a black box] to compute the distance between an enemy and the player on the screen).
PROTIP: A lot of the time, you can get away with comparing the square of the distance between the two to the square of the sum of their radii, no roots involved.

If we standardize local variables to be $0000-$000F, that might make modularization a bit easier.
User avatar
blargg
Posts: 3715
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

Local volatile variables (ones whose values need not be preserved across routine calls)? Sure.
User avatar
Dwedit
Posts: 5000
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

Hopefully not changed by IRQ code :)
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
dasefx
Posts: 7
Joined: Mon Sep 02, 2024 2:48 pm

Re:

Post by dasefx »

blargg wrote: Mon Apr 05, 2010 11:52 pm Celius, it's interesting how yours are branchless in order to be constant-time.

If you want fastest, we beat that to death a few years ago, with one that at worst does 8-bit in 56 clocks, 16-bit in 208 clocks, and 24-bit in 430 clocks.
This link is dead ... any leads?? Would love to explore some of the fast code.
Fiskbit
Site Admin
Posts: 1006
Joined: Sat Nov 18, 2017 9:15 pm

Re: Formatting 16-bit number as decimal?

Post by Fiskbit »

The linked thread can now be found here. We've had some domain and subdomain changes over the years that have broken early links.
dasefx
Posts: 7
Joined: Mon Sep 02, 2024 2:48 pm

Re: Formatting 16-bit number as decimal?

Post by dasefx »

Thank you!
Oziphantom
Posts: 1669
Joined: Tue Feb 07, 2017 2:03 am

Re: Formatting 16-bit number as decimal?

Post by Oziphantom »

either way the "number converting" section here might be of interest https://codebase64.org/doku.php?id=base:6502_6510_maths
Post Reply