Pages: 1
Posted on 08-01-13, 08:10 pm (rev. 2 by ImageBot on 11-21-16, 02:36 am)
☭ coffee and cream


Karma: 10415
Posts: 1082/2768
Since: 06-26-11
lolSnes was a silly side project I started two years ago. The goal was to make a SNES emulator for the DS, that would be better than the current emulators available (none of them render without glitches, and one of them doesn't seem to work).

I first coded the CPU side, fully in ASM. It was nice and worked well. Then moved to the PPU, and wanted to implement a line-accurate software renderer. However, as discussed in this thread: Is the DS really that underpowered..., the DS isn't powerful enough to handle such a renderer, let alone running it alongside the CPU and other fun things to emulate.

After that discovery, I pretty much forgot about the project, leaving it in a dormant state like all my failed projects.

And now, for some reason (probably my constant need to work on something new), I decided to take my old code, shake dust off of it, and continue it.

I trashed the software PPU attempt, and started implementing the PPU in hardware, ie using the DS's 2D hardware to emulate the PPU. With some work, I got this: (HCC demo ROM-- running fine, minus wrong BG priorities)



All kinds of trickery will be used to get the most accurate possible PPU emulation. For example:

* SNES graphics are planar, while DS graphics are linear. To make up for this with the least overhead possible, there's a system that keeps track of what each 1K block of emulated VRAM is used for. Then, when BG modes/sizes/whatnot change, or the emulated VRAM is modified, the DS VRAM is updated accordingly.

* SNES backgrounds can be as low as 2bpp (4 colors). In this case, the palette numbers in the screen data select palettes with a granularity of 4 colors. On the DS, the lowest granularity you can get is 16 colors. As a workaround, we use extended palettes: each palette is filled with 4 or 16 colors depending on the BG's color depth. This wastes space, but it's the only simple way out of this problem.

Then come other fun features which aren't handled yet. Among which: per-tile priority (this will be a whole lotta fun), window combination logic, and perhaps some funky color effects which the DS can't emulate...


However, I have work in other areas. Namely, SPC700. I need to emulate that fucker if I want to get anything serious running. For now, games will get stuck in a loop while trying to communicate with the non-existent SPC700, and my attempts at faking that have failed miserably.

At some point, prior a release, I'll also need a basic interface, just to let people select a ROM. For now it's hardcoded to load 'snes/rom.smc'.


Current status

What runs:
* HCC demo
* dunno what else

What doesn't run
* anything that will use the SPC700 (that is, any serious game)

Support:
* Main CPU (65816c): 99% (all opcodes emulated, may miss a few unimportant bits)
* PPU: ~20% (supports rendering 2bpp and 4bpp BGs with scrolling)
* Memory mapping for various setups
* Intelligent ROM caching: ROM bank 0 is cached as well as the bank PBR points to (caching needed because there's not enough RAM to load a full ROM)


I may put the code on a github repo later on, when it's more... mature.
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 08-02-13, 01:53 pm
Birdo


Karma: 2754
Posts: 592/2091
Since: 06-26-11
*Something supportive*
Good job.
Posted on 08-03-13, 01:51 am
☭ coffee and cream


Karma: 10415
Posts: 1088/2768
Since: 06-26-11
For whoever's interested, I'll point out that lolSnes has its own Git repo now: https://github.com/Mega-Mario/lolSnes

Also yay, I got it to work on a DS too There was some silly issue that broke everything.
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 08-03-13, 01:52 am
Birdo


Karma: 3304
Posts: 1305/2021
Since: 06-28-11
Awesome. I guess you will try to make it run as smooth and accurate as possible?
(because SnemulDS only works with a few games...)
_________________________

Posted on 08-03-13, 04:01 pm
☭ coffee and cream


Karma: 10415
Posts: 1089/2768
Since: 06-26-11
I'll try. Perfect graphics accuracy is impossible without a software renderer, but I'll try to get as close as possible without adding huge overhead.

I also got another idea: running the CPU and SPC700 on the ARM7, and a software renderer on the ARM9. I don't know how feasible that would be though-- it'd mostly depend on how much power average games need. If this ever gets done, it'll be a separate project?
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 08-18-13, 02:09 am (rev. 1 by ImageBot on 11-21-16, 02:36 am)
☭ coffee and cream


Karma: 10415
Posts: 1098/2768
Since: 06-26-11
Progress!



Certainly not perfect, but atleast it gets the colors right

SMW is playable, to some extent. You can start a new game, but then the worldmap is broken and all you can play is the bonus level. That is, assuming the SPC700 core doesn't crash on you. It seems to still randomly crash.

Oh and this doesn't work on a DS for whatever obscure reason. It seems to get stuck during SPC code/data uploads.

The whole CPU/SPC sync needs improvement anyway; attempting to speedhack SMW like SNES Advance does, causes it to get stuck in a SPC transfer. It seems transfers fail for whatever reason if the ARM9 runs too fast. (or the speedhack breaks the game's SPC code-- SNES Advance just bypasses all SPC upload code iirc, when we're actually emulating it here)
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 08-18-13, 10:24 am


Karma: 3752
Posts: 1935/2112
Since: 06-28-11
Let's say, you put the emulator on a 3DS supported flashcart and start it on a 3DS. Will it still be slow as fuck or would it probably work with decent speed there?
Posted on 08-18-13, 10:40 am (rev. 1 by  Arisotura on 08-18-13, 06:11 pm)
☭ coffee and cream


Karma: 10415
Posts: 1099/2768
Since: 06-26-11
There's no reason it wouldn't run at the same speed as on a DS, considering the 3DS's DS-mode is likely a hardware mode and not virtualization/emulation/whatever.

On the topic of speed, SMW doesn't run at fullspeed, which is why speedhacking will be required. Many SNES games, including SMW, don't use WAI opcodes and instead use idle loops that consume all the CPU's power.

I implemented the opcode 0x42 speedhack, like in SNES Advance. However it seems that if the main CPU runs too fast, the SPC700 will desync. Probably the same issue that is happening on a DS. (read: I hope it is the same issue. It is really annoying.)

Edit- speedhack opcode was just fixed. Sadly, it was not the DS's freeze issue. Good news though, are that with the speedhack, SMW runs at fullspeed.
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 08-23-13, 08:55 pm
☭ coffee and cream


Karma: 10415
Posts: 1101/2768
Since: 06-26-11
lolSnes is out.

Have fun.
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Posted on 09-25-13, 06:13 pm
☭ coffee and cream


Karma: 10415
Posts: 1167/2768
Since: 06-26-11
How come I haven't updated this thread in so long...

See this for more info: http://gbatemp.net/threads/lolsnes-snes-emulator-for-ds.353252/page-13#post-4783082

lolSnes Git builds: http://lolsnes.net/download.php -- there's a RSS feed informing you whenever a new build is available.

Latest build features an improved version of SNemulDS's DSP. Enjoy interpolated SNES audio on your DS!
_________________________
Kuribo64 - RH-fucking-cafe - Kafuka

zrghij
Pages: 1