Discuss Scratch

CoolCode16
Scratcher
16 posts

The best format to store registers; decimal or hex? (cpu emulation)

When emulating a cpu in scratch, should I store the cpu registers in decimal or hexadecimal?

Advantages of decimal: Easier to increment/decrement without needing to do conversions.
Advantages of hexadecimal: Easier to load/store values from/to ROM/RAM without needing to do conversions.
awesome-llama
Scratcher
1000+ posts

The best format to store registers; decimal or hex? (cpu emulation)

Why would hexadecimal be easier to load/store from memory?
The memory too can be represented as a decimal numbers, a list of them.

Last edited by awesome-llama (March 17, 2025 21:59:28)

CoolCode16
Scratcher
16 posts

The best format to store registers; decimal or hex? (cpu emulation)

awesome-llama wrote:

Why would hexadecimal be easier to load/store from memory?
The memory too can be represented as a decimal numbers, a list of them.

Also there is a performance consideration, decimal will be faster in maths as Scratch expects the numbers to be in that format, hexadecimal adds extra conversion steps.
If the ROM is converted using a file to hex converter, all the values that could be loaded into the registers will be in hex. And I don't know any file to list of something-separated numbers converters.
awesome-llama
Scratcher
1000+ posts

The best format to store registers; decimal or hex? (cpu emulation)

CoolCode16 wrote:

If the ROM is converted using a file to hex converter, all the values that could be loaded into the registers will be in hex. And I don't know any file to list of something-separated numbers converters.
You can still input hexadecimal but let the Scratch project do the conversion to its own internal decimal format.
CoolCode16
Scratcher
16 posts

The best format to store registers; decimal or hex? (cpu emulation)

awesome-llama wrote:

CoolCode16 wrote:

If the ROM is converted using a file to hex converter, all the values that could be loaded into the registers will be in hex. And I don't know any file to list of something-separated numbers converters.
You can still input hexadecimal but let the Scratch project do the conversion to its own internal decimal format.
That can take very long for larger ROMs.
RokCoder
Scratcher
1000+ posts

The best format to store registers; decimal or hex? (cpu emulation)

It doesn't take long and you'll be far more interested in getting the emulator performance at its best. Slower ROM conversion and faster emulation performance is better than the fast ROM conversion and slower emulation performance.
CoolCode16
Scratcher
16 posts

The best format to store registers; decimal or hex? (cpu emulation)

RokCoder wrote:

It doesn't take long and you'll be far more interested in getting the emulator performance at its best. Slower ROM conversion and faster emulation performance is better than the fast ROM conversion and slower emulation performance.
if the ROM is stored in a list, that limits the size to 200KB, unless you split it into multiple lists, which cloud slow down accessing since you need one or more if statements to run for each individual read (along with CPU memory maps aswell.) But with variables, you don't have any limit for size. However there's no fast way to tell where each number starts and ends since unlike hexadecimal. (unless you add zeroes to 1 and 2 digit numbers, making them all 3 digit. but assuming variable values that cant be represented as 32-bit float values are stored in ascii or utf, that's atleast 3x bigger in ram than originally as compared to the 2x hex uses) So really we need to some experimentation to find the truly most optimal option.
RokCoder
Scratcher
1000+ posts

The best format to store registers; decimal or hex? (cpu emulation)

I'm not sure what specific problem you're trying to solve. Do you have a ROM that's too large to fit into a list?
CoolCode16
Scratcher
16 posts

The best format to store registers; decimal or hex? (cpu emulation)

RokCoder wrote:

I'm not sure what specific problem you're trying to solve. Do you have a ROM that's too large to fit into a list?
Maybe for 4MB ROMs. like on the game.com and megadrive

Last edited by CoolCode16 (Yesterday 23:31:57)

Powered by DjangoBB