Discuss Scratch

elgooGmirror
Scratcher
26 posts

SNES Emulator Help

So,
I'm making a SNES emulator. The reason I decided to do this was because of @GenericHeroGuy's Cool NES, and @SpinningCube's unfinished NES emulator. I figured, if they could make a NES emulator, why can't I make a SNES one? Just to prove it's possible.
I need help finding SNES emulation resources, though. Does anyone know where I can find web sites for research, so I can make my emulator?
if <[SNES] = [Possible On Scratch]> then
forever
switch costume to [Victory is mine! v]
say [YES!!!]
end
end

Last edited by elgooGmirror (July 30, 2023 13:02:05)

Mystery96
Scratcher
100+ posts

SNES Emulator Help

you could try wikipedia, and start from researching the snes' cpu, the Ricoh 5A22.
elgooGmirror
Scratcher
26 posts

SNES Emulator Help

I know what the CPU is called. I actually used wikipedia a bit. Do you know where I could research 65c816 assembly?
EBWW
Scratcher
49 posts

SNES Emulator Help

to get samples working you'd have to use FFT sine wave thingies
EBWW
Scratcher
49 posts

SNES Emulator Help

elgooGmirror wrote:

I know what the CPU is called. I actually used wikipedia a bit. Do you know where I could research 65c816 assembly?

Maybe look it up….

Prepare to never get full speed, even on Turbowarp, because COOLNES doesn't run fast. :P
SpinningCube
Scratcher
100+ posts

SNES Emulator Help

First, know that emulating the SNES is notoriously hard. There are a lot of parts operating simultaneously, each of which is pretty complicated on its own, including but not limited to:
  • CPU (Ricoh 5A22, which is equivalent to the WDC 65C816)
  • PPU (PPU1 and PPU2)
  • Audio (SPC700 and S-DSP)
  • The cartridge (memory, parsing the ROM format, and sometimes co-processors such as SuperFX)

I'd recommend first understanding the overall architecture of the system you plan to emulate.
Here's an article for that: Super Nintendo Architecture | A Practical Analysis
This is just to get to know all the various parts so you can anticipate what challenges you might have to overcome.

For specific reference, there's this SNES Development Wiki, which should have a lot of reference material about all aspects of SNES hardware and functionality, including that for the CPU. There's also this big document: fullsnes.
,
There's also this nice video about SNES graphics: Graphics & Palettes - Super Nintendo Entertainment System Features Pt. 01

There are many other resources out there besides these, and I'd strongly recommend searching for other reference material to double-check information or to find information not covered by these other sources, and just to generally make the process less painful. It would also be a good idea to review general emudev topics, like degrees of emulation accuracy and their tradeoffs.

Emulators typically take a long time to develop, and this is especially true for Scratch. Emulators written in Scratch are often designed around speed, and require heavy optimization, though that's for emulators written with the intent of running at full speed. Since the SNES is probably too slow for Scratch, perhaps you don't need to stress about speed quite as much.

I have some tips, some of which I used for my (WIP for now) NES emulator:
  • Most bitwise operations (particularly bitshifts) can be replaced with simple arithmetic operators, such as multiplication, division, addition, subtraction, floor, and modulo.
  • Bitwise AND, OR, and XOR between two 8-bit values can be done with lookup tables that each have 65536 entries (256 x 256).
  • Pen strokes are expensive. Fast renderers try to reduce the number of pen strokes in an image by combining pixels of the same color into
    horizontal lines, and by only drawing what pixels of the image have changed to a different color since the previous frame.
  • When emulating an instruction set with as many opcodes as the 65C816 has, a large if/elseif/else chain is going to be pretty inefficient if it has to run hundreds of checks to find the opcode you want. There are a few methods to make decoding faster. One way is to find similarities between the functionality of different opcodes and design around those. Another way, which is the method I use, is to do binary search to find the right instruction for a certain opcode, which requires that your if/else statements are arranged into a specific structure: Essential Emulator Scripts.

Last edited by SpinningCube (Aug. 3, 2023 03:44:03)

elgooGmirror
Scratcher
26 posts

SNES Emulator Help

SpinningCube wrote:

First, know that emulating the SNES is notoriously hard. There are a lot of parts operating simultaneously, each of which is pretty complicated on its own, including but not limited to:
  • CPU (Ricoh 5A22, which is equivalent to the WDC 65C816)
  • PPU (PPU1 and PPU2)
  • Audio (SPC700 and S-DSP)
  • The cartridge (memory, parsing the ROM format, and sometimes co-processors such as SuperFX)

I'd recommend first understanding the overall architecture of the system you plan to emulate.
Here's an article for that: Super Nintendo Architecture | A Practical Analysis
This is just to get to know all the various parts so you can anticipate what challenges you might have to overcome.

For specific reference, there's this SNES Development Wiki, which should have a lot of reference material about all aspects of SNES hardware and functionality, including that for the CPU. There's also this big document: fullsnes.
,
There's also this nice video about SNES graphics: Graphics & Palettes - Super Nintendo Entertainment System Features Pt. 01

There are many other resources out there besides these, and I'd strongly recommend searching for other reference material to double-check information or to find information not covered by these other sources, and just to generally make the process less painful. It would also be a good idea to review general emudev topics, like degrees of emulation accuracy and their tradeoffs.

Emulators typically take a long time to develop, and this is especially true for Scratch. Emulators written in Scratch are often designed around speed, and require heavy optimization, though that's for emulators written with the intent of running at full speed. Since the SNES is probably too slow for Scratch, perhaps you don't need to stress about speed quite as much.

I have some tips, some of which I used for my (WIP for now) NES emulator:
  • Most bitwise operations (particularly bitshifts) can be replaced with simple arithmetic operators, such as multiplication, division, addition, subtraction, floor, and modulo.
  • Bitwise AND, OR, and XOR between two 8-bit values can be done with lookup tables that each have 65536 entries (256 x 256).
  • Pen strokes are expensive. Fast renderers try to reduce the number of pen strokes in an image by combining pixels of the same color into
    horizontal lines, and by only drawing what pixels of the image have changed to a different color since the previous frame.
  • When emulating an instruction set with as many opcodes as the 65C816 has, a large if/elseif/else chain is going to be pretty inefficient if it has to run hundreds of checks to find the opcode you want. There are a few methods to make decoding faster. One way is to find similarities between the functionality of different opcodes and design around those. Another way, which is the method I use, is to do binary search to find the right instruction for a certain opcode, which requires that your if/else statements are arranged into a specific structure: Essential Emulator Scripts.

Thank you Spinning Cube! This will be very helpful.

Last edited by elgooGmirror (Aug. 16, 2023 14:27:28)

antonfdiaz
Scratcher
12 posts

SNES Emulator Help

forever
set [noice v] to [1000]
end
s20191106J
Scratcher
3 posts

SNES Emulator Help

Holy poop I forgot how to craft- I mean code.











Bruh
-LevHr-
Scratcher
14 posts

SNES Emulator Help

This would be impossible, right?
EBWW
Scratcher
49 posts

SNES Emulator Help

-LevHr- wrote:

This would be impossible, right?
Not impossible, but very hard
Mystery96
Scratcher
100+ posts

SNES Emulator Help

-LevHr- wrote:

This would be impossible, right?

scratch is turing complete so you could theoretically emulate the switch, the xbox series x, ps5, etc., albeit it running at an EXTREMELY slow rate.
elgooGmirror
Scratcher
26 posts

SNES Emulator Help

Mystery96 wrote:

-LevHr- wrote:

This would be impossible, right?

scratch is turing complete so you could theoretically emulate the switch, the xbox series x, ps5, etc., albeit it running at an EXTREMELY slow rate.

I don't think this would be possible because the ROM sizes are just too huge. (Switch games are like 5 GB!) While you could technically emulate these consoles, it would only be able to run test ROMs.
-EMULATOREN-
Scratcher
5 posts

SNES Emulator Help

SpinningCube wrote:

First, know that emulating the SNES is notoriously hard. There are a lot of parts operating simultaneously, each of which is pretty complicated on its own, including but not limited to:
  • CPU (Ricoh 5A22, which is equivalent to the WDC 65C816)
  • PPU (PPU1 and PPU2)
  • Audio (SPC700 and S-DSP)
  • The cartridge (memory, parsing the ROM format, and sometimes co-processors such as SuperFX)

I'd recommend first understanding the overall architecture of the system you plan to emulate.
Here's an article for that: Super Nintendo Architecture | A Practical Analysis
This is just to get to know all the various parts so you can anticipate what challenges you might have to overcome.

For specific reference, there's this SNES Development Wiki, which should have a lot of reference material about all aspects of SNES hardware and functionality, including that for the CPU. There's also this big document: fullsnes.
,
There's also this nice video about SNES graphics: Graphics & Palettes - Super Nintendo Entertainment System Features Pt. 01

There are many other resources out there besides these, and I'd strongly recommend searching for other reference material to double-check information or to find information not covered by these other sources, and just to generally make the process less painful. It would also be a good idea to review general emudev topics, like degrees of emulation accuracy and their tradeoffs.

Emulators typically take a long time to develop, and this is especially true for Scratch. Emulators written in Scratch are often designed around speed, and require heavy optimization, though that's for emulators written with the intent of running at full speed. Since the SNES is probably too slow for Scratch, perhaps you don't need to stress about speed quite as much.

I have some tips, some of which I used for my (WIP for now) NES emulator:
  • Most bitwise operations (particularly bitshifts) can be replaced with simple arithmetic operators, such as multiplication, division, addition, subtraction, floor, and modulo.
  • Bitwise AND, OR, and XOR between two 8-bit values can be done with lookup tables that each have 65536 entries (256 x 256).
  • Pen strokes are expensive. Fast renderers try to reduce the number of pen strokes in an image by combining pixels of the same color into
    horizontal lines, and by only drawing what pixels of the image have changed to a different color since the previous frame.
  • When emulating an instruction set with as many opcodes as the 65C816 has, a large if/elseif/else chain is going to be pretty inefficient if it has to run hundreds of checks to find the opcode you want. There are a few methods to make decoding faster. One way is to find similarities between the functionality of different opcodes and design around those. Another way, which is the method I use, is to do binary search to find the right instruction for a certain opcode, which requires that your if/else statements are arranged into a specific structure: Essential Emulator Scripts.
I used Retro Game Mechanics Explained to learn about the Pac-Man Ghost AI on my main acc.
TechNerd64
Scratcher
500+ posts

SNES Emulator Help

Wow, such a daunting task!!! Good Luck!!!
-EMULATOREN-
Scratcher
5 posts

SNES Emulator Help

TechNerd64 wrote:

Wow, such a daunting task!!! Good Luck!!!
Thank you! I'm gonna need it.
NlNT3ND0
Scratcher
1 post

SNES Emulator Help

when green flag clicked
forever
set [GPUProcess] to [running]
end

Last edited by NlNT3ND0 (Aug. 20, 2023 19:47:59)

TechNerd64
Scratcher
500+ posts

SNES Emulator Help

I found a online 65c816 assembly tutorial that may help.
65c816 assembly tutorial
elgooGmirror
Scratcher
26 posts

SNES Emulator Help

TechNerd64 wrote:

I found a online 65c816 assembly tutorial that may help.
65c816 assembly tutorial
Thanks!
TechNerd64
Scratcher
500+ posts

SNES Emulator Help

elgooGmirror wrote:

TechNerd64 wrote:

I found a online 65c816 assembly tutorial that may help.
65c816 assembly tutorial
Thanks!
Was the tutorial helpful?

Powered by DjangoBB