Homebrew Stella-DS Improved

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
New builds always here: https://github.com/wavemotion-dave/StellaDS

I've enjoyed reliving my youth playing Atari 2600 games on StellaDS via TWL. Huge thanks to the community for making that possible!

However, a few glitches and bugs distracted from the overall experience when playing Atari 2600 games.

I've never been into programming an emulator but decided my coding skills were probably up to snuff for modifying/improving an existing emulator. Fortunately, Stella-DS code base is rather clean and easy to understand - at least most of it!

So this weekend I got my development environment setup (on Ubuntu) and got to work. I've made the following improvements:
  • Removed Color TV switch and replaced it with a difficulty switch (stetting A/B renders the difficulty for both Left and Right player switches - I'll probably improve this later). I realize a few odd games do use the Color switch in gameplay... but far more use the difficulty switch and StellaDS was defaulting both switches to the A=Expert position. Until I can add all switches, this is a reasonable trade-off.
  • Used a bit more of the DSi screen resolution so that the occasional missing graphic doesn't get compressed away (e.g. if you fire the laser in Chopper Command you can see it sometimes disappears at certain vertical positions of the Chopper... this is no longer an issue). Generally this results in a few missing rows of pixels at the very bottom of the screen which is a better trade-off for 95% of games where almost no action takes place at the extremes.
  • Fixed all the on-screen touch button handling such that it's not so glitchy... press SELECT switch or START switch and it actually works every time (it's amazing what a little debounce code will do!). I increased the hot-spots where you can press for each switch so that you can cleanly operate it with a finger or thumb... I hated getting out the Stylus for the small hit-boxes that were originally used.
  • Improved the emulator core to handle the most common half-dozen instructions first and in special order plus re-ordered a bit of the math-y code to make computations slightly faster ... this gives about 10% speed up and most games now run at 60FPS or reasonably close to it (on a DSi running 137MHz... no idea on an original DS where I assume this emulator would still be on the struggle-bus).
  • Start and Select buttons now map to RESET (often used to start a game) and SELECT switches. That only seems logical. I remapped the FPS display to the right shoulder switch. I also only output the FPS once per second instead of the wasteful 60x per second which means you can run with the FPS enabled with very little (but not zero!) impact on emulation.
  • The left shoulder switch runs the game at max speed... but since this emulator is running pretty much full-bore already, it doesn't have a huge impact (for example, you can see the ships in space invaders moving at about 10-15% faster than normal ... hardly worth getting excited about - this was mostly for me to see improvements in core optimization).
  • The Power Off button no longer makes that hideous screeching noise. And if you decide not to quit, it renders the screen back properly.
Before I decide how to create a github account and get these changes checked back in - is this stuff of any value to anyone?! Sometimes I feel like I'm the only guy that was bothered by the glitches given the lack of any discussion on this ancient system emulation!

Edit: Lots of progress... wanted to update the top thread to show more fun stuff!
upload_2021-6-2_8-50-17.png


upload_2020-12-1_16-18-55-png.236288
 
Last edited by wavemotion,

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Okay, in case I get hit by the proverbial bus, here is the .NDS file for the "improved" version (1.1b and attached as .ZIP... unzip and place on your SD card and you can just launch it and hit the cartridge slot to select your games... I'd recommend NOT overwriting the default StellaDS for now). I added all switches and cleaned out a few long-standing bugs on specific games (Conquest of Mars works now!). There are still a few small sound glitches that have been in here forever that I'll try to tackle next as well as add some screen scaling options. I'll also make a pass through the latest Stella emucore sources to see if there any easy ports that can be made. I wouldn't mind seeing Atarivox support.

Right-Shoulder Button (press for 1 sec) will turn on FPS.
Press-and-Hold the Left Shoulder Button to overclock at max speed. Some games won't reach 60FPS while others will run at almost twice that. Most games, however, are running close to full frame rate.

Please Note
In order to get better performance, I had to do something I'm not especially proud of: direct global memory access. Stella is such a wonderful bit of code... beautiful and structured and reasonably efficient. However... it's not quite as efficient as doing some memory tricks that involve a few global variables. I'm not a fan of using these tricks as it makes the code less portable and less "clean"... however, the emulator has suffered from being "so close" for so long that I resorted to pull these few tricks to get that last bit of performance needed to make the games that much closer to ideal. In the end, I'm more interested in better gameplay than a codebase that looks beautiful. I'm sure I'll be forgiven for my sins. Or, more likely, I've got other sins that will eclipse this by a country mile :)

upload_2020-11-25_7-22-6.png

[Edit: you can always find the latest of my StellaDS fork at: https://github.com/wavemotion-dave/StellaDS ]
 
Last edited by wavemotion,

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Great job and thank you! It would seem like this build is better in all ways? Why do you not recommended replacing the default one?
Mostly because it's only had like a half-day of actual play and it's very possible I've introduced new bugs that weren't there before. So far, everything I've played has been good but there are a lot of games :)

Anyway, you can keep both the default version and this new version on the same SD card - they have different filenames. I still need to figure out how to get my code changes uploaded to github - maybe in a branch or something. But first, I must kill Dragons in Adventure!

[Edit: this improved version has the version number bumped to "1.1b" to distinguish it from the previous versions... all of which seem to be 1.0 even though there have been some changes over the years]
upload_2020-11-25_8-2-44.png
 
Last edited by wavemotion,

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Thank you for this. It always confused me how emulating such an old system could have any slowdown.
Me too - but after seeing how complex this is, I'm surprised it works as well as it does :)

Not only is there a core 6502 CPU running about a million cycles per second but there is also the RIOT (Input/Output ) chip that needs emulation and the all-important TIA which generates the TV/Scanline information. So it's like having 3 processors that need to be emulated in software and coordinated to make it all work. My improvements only give a small boost in performance - but so many of those games were running very close to full speed that it was enough to get them over the hump.

And to be sure, there are still games that don't run fast enough. Pitfall II for example is just too slow to be playable. And even little lowly 2k Freeway only runs at like 41FPS (it's playable however). Most of that comes not from the CPU core emulation but the TIA emulation which is... well, let's just say that was one hell of a dedicated hardware chip!
 

CMDreamer

Well-Known Member
Member
Joined
Oct 29, 2014
Messages
1,682
Trophies
1
Age
38
XP
3,463
Country
Mexico
Thanks a lot for this!

Didn't knew this existed at all, even though I'm into emulation long time ago.

Hope to see some improvements soon.

One question: Where should I put my games to be able to play them? (Thanks in advance).
 

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
One question: Where should I put my games to be able to play them? (Thanks in advance).
You can put them pretty much anywhere... I use the default .\roms\Atari folder which was supplied by TWL install. You can then click on the cart slot on the StellaDS emulator and browse down to that directory easily enough.

In theory if you replace the existing Stella.NDS file in the .\_nds\TWiLightMenu\emulators then it will launch .a26 extension files with the emulator (if you launch the emulator directly, you can load .bin or .a26 files which are both considered Atari files as far as the emulator is concerned).

One bit of warning - I noticed the emulator will not load files with names > 29 characters. It crashes. I have a fix coming - but just shorten any longer rom names for now.
 

CMDreamer

Well-Known Member
Member
Joined
Oct 29, 2014
Messages
1,682
Trophies
1
Age
38
XP
3,463
Country
Mexico
You can put them pretty much anywhere... I use the default .\roms\Atari folder which was supplied by TWL install. You can then click on the cart slot on the StellaDS emulator and browse down to that directory easily enough.

In theory if you replace the existing Stella.NDS file in the .\_nds\TWiLightMenu\emulators then it will launch .a26 extension files with the emulator (if you launch the emulator directly, you can load .bin or .a26 files which are both considered Atari files as far as the emulator is concerned).

One bit of warning - I noticed the emulator will not load files with names > 29 characters. It crashes. I have a fix coming - but just shorten any longer rom names for now.

Thanks a lot for the info and the advice... will test it when I get back home.

Will be waiting for that fix. Great job!
 

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Okay, I think I figured out GitHub... I forked the original repository for StellaDS and uploaded my changes along with the binary. If you want the newest binary, you can always grab it from my fork. If I f'ed this thing up somehow, hopefully some kind person will nudge me back to the path :)

https://github.com/wavemotion-dave/StellaDS
 
Last edited by wavemotion,

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Stella DS 1.1e released. Binary and source: https://github.com/wavemotion-dave/StellaDS

I've eeked out another 1-3% speed improvement on bank-switching optimization. Amazing homebrew games like Man Goes Down and Lady Bug will run full speed. I started a compatibility table as well to track what needs improvement - most games will run well beyond 60 FPS if you open the throttle.

I'm starting to look at correcting as many games as possible. This 1.1e release makes playable those half-dozen games that use the right-player joystick port for a single player (Surround, Air-Sea Battle, Basketball, Wizard of Wor, Space Ship, Slot Machine) and I've added support for Raiders of the Lost Ark which requires 2 joysticks (but the other joystick is only used to select and drop items... that's now handled with the previously unused X,Y and B buttons).

I plan on adding SaveKey support for the "new" (well, since 2006) homebrews that allow saving options and high-scores. And then paddle support via touch-screen.

There are still a handful of games that won't run right... most notably Starpath Supercharger games which I haven't taken the time to investigate yet. Also, Pitfall II is only running at 45FPS and the music is crappy... so it's not all roses. There is also a seldom heard brief "screech" of audio as if something is briefly out of sync... it's minor but annoying. It was present on the original StellaDS and nothing I've done has made it better (or worse). Anyway things are generally improving!

By the way, I've no idea if there is a way to debug/develop without using an actual DSi - for now, this is my debug environment when I'm trying to figure out where the bottlenecks are (here is Adventures of Tron running at 52FPS -- thanks to this debug I was able to improve it to 60FPS).
upload_2020-11-27_13-17-47.png
 
Last edited by wavemotion,

ber71

Well-Known Member
Member
Joined
Apr 24, 2019
Messages
558
Trophies
0
Age
58
XP
2,453
Country
Spain
Any chance for a pure DS build? For use on flashcarts.
Thank you. Pleased to see people keeping the scene alive.
 

wavemotion

Benign Geek
OP
Member
Joined
Nov 23, 2020
Messages
914
Trophies
1
XP
7,315
Country
United States
Any chance for a pure DS build? For use on flashcarts.
Thank you. Pleased to see people keeping the scene alive.
Honestly - don't know how! I do have an R4i clone card (those $10 cheap ones) and it plays everything fine but I tried loading this StellaDS onto it and it won't run (error -4). I got the Stella DS from the R4i link and that one does play but it's God awful slow to the point of being painful. Maybe I need to build the binary with some other settings to get it to run on a flashcart. I'll try to research this as time permits but no promises.

In the meantime, I've put up 1.1f: https://github.com/wavemotion-dave/StellaDS

I added a flicker-free mode that allows games like Yars Revenge, Stellar Track and Asteroids which use some aspect of 30Hz updates to look really clean. But it comes at a CPU performance cost. Fortunately, most of the recent improvements I've made allow most games to run full speed in Flicker Free mode but I would NOT use it unless you absolutely had no choice. The default is OFF (NO=normal rendering). I also changed up the buttons a bit... A or B is fire (for those whose thumbs naturally rest closer to B) and X and Y are now the FPS and Full-Speed options... the Left and Right triggers shift the screen up/down by one pixel at a time so that the new screen scaling (which does not miss lines as the old emulator did) can be positioned. Some games have information near the top and some near the bottom (scores, for example) and this lets you get your frame centered exactly as you want for maximum visual enjoyment. I've also eeked out just a bit more performance from the video handling by using a ping-pong DMA scheme.

Note1: I realize this flicker free mode is similar to the old Z26 and ancient Stella "phosphor mode" that some people liked but many purists didn't because it wasn't a true emulation of the actual device. Stella eventually did some amazing TV blending techniques that are very CPU intensive - which is fine when PCs are getting faster every year but the DSi is aging hardware ... so some caveman techniques will be necessary. At this point I'm favoring playability over true emulation because you can't have fun if the game won't run.

Note2: At some point I'll add detection of every known ROM with default settings on a per-rom basis (i.e. Stellar Track would enable Flicker-Free mode and every game can be custom scaled so that it's visually near-perfect).

upload_2020-11-28_13-4-11.png
 
Last edited by wavemotion,

MarioKartFan

Well-Known Member
Member
Joined
Aug 27, 2019
Messages
596
Trophies
0
XP
2,319
Country
Algeria
Honestly - don't know how! I do have an R4i clone card (those $10 cheap ones) and it plays everything fine but I tried loading this StellaDS onto it and it won't run (error -4). I got the Stella DS from the R4i link and that one does play but it's God awful slow to the point of being painful. Maybe I need to build the binary with some other settings to get it to run on a flashcart. I'll try to research this as time permits but no promises.

In the meantime, I've put up 1.1f: https://github.com/wavemotion-dave/StellaDS

I added a flicker-free mode that allows games like Yars Revenge, Stellar Track and Asteroids which use some aspect of 30Hz updates to look really clean. But it comes at a CPU performance cost. Fortunately, most of the recent improvements I've made allow most games to run full speed in Flicker Free mode but I would NOT use it unless you absolutely had no choice. The default is OFF (NO=normal rendering). I also changed up the buttons a bit... A or B is fire (for those whose thumbs naturally rest closer to B) and X and Y are now the FPS and Full-Speed options... the Left and Right triggers shift the screen up/down by one pixel at a time so that the new screen scaling (which does not miss lines as the old emulator did) can be positioned. Some games have information near the top and some near the bottom (scores, for example) and this lets you get your frame centered exactly as you want for maximum visual enjoyment. I've also eeked out just a bit more performance from the video handling by using a ping-pong DMA scheme.

Note1: I realize this flicker free mode is similar to the old Z26 and ancient Stella "phosphor mode" that some people liked but many purists didn't because it wasn't a true emulation of the actual device. Stella eventually did some amazing TV blending techniques that are very CPU intensive - which is fine when PCs are getting faster every year but the DSi is aging hardware ... so some caveman techniques will be necessary. At this point I'm favoring playability over true emulation because you can't have fun if the game won't run.

Note2: At some point I'll add detection of every known ROM with default settings on a per-rom basis (i.e. Stellar Track would enable Flicker-Free mode and every game can be custom scaled so that it's visually near-perfect).

View attachment 235780

Wow. This is exciting stuff.
 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,564
Country
Chile
By the way, I've no idea if there is a way to debug/develop without using an actual DSi - for now, this is my debug environment when I'm trying to figure out where the bottlenecks are (here is Adventures of Tron running at 52FPS -- thanks to this debug I was able to improve it to 60FPS).
View attachment 235694

Yes there is!

Use Desmume 0.9.11 and TGDS-ramdisk_dldi (gbatemp.net)

That way you can run your homebrew assets from a DLDI (slot-1) system!

edit: DS Mode only. But I guess the same changes would work on a DSi (except the memory layout and linker settings), given the DSi SD filesystem is hidden behind the DLDI API
 
Last edited by Coto,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    SylverReZ @ SylverReZ: @Psionic Roshambo, Hey, VSauce. Where are your fingers?