1. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    Country:
    United States
    [Edit: see 5th post for binary]
    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!

    [pic of game running could not be posted because I'm a total noob! I'll come back and add one later...]
    upload_2020-11-23_9-50-17.png

    Edit: Lots of progress... wanted to update the top thread to show more fun stuff!
    [​IMG]
     
    Last edited by wavemotion, Dec 2, 2020
  2. Zense

    Zense GBARunner2 config: Touch the touchscreen + press R
    Member

    Joined:
    Apr 20, 2008
    Messages:
    1,839
    Country:
    Italy
    I think many would enjoy these improvements. I don't think that it's simply a coincidence that it was decided to include StellaDS with twilightmenu so to answer your question I'm sure many will find it valuable ^_^
     
    Last edited by Zense, Nov 25, 2020
  3. MyDePain

    MyDePain GBAtemp Regular
    Member

    Joined:
    Nov 23, 2016
    Messages:
    111
    Country:
    France
    That's amazing ! Great job !
     
    alexander1970 and wavemotion like this.
  4. MarioKartFan

    MarioKartFan GBAtemp Fan
    Member

    Joined:
    Aug 27, 2019
    Messages:
    342
    Country:
    Algeria
    Love the effort. Thanks!
     
    alexander1970 and wavemotion like this.
  5. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    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, Nov 26, 2020
  6. MarioKartFan

    MarioKartFan GBAtemp Fan
    Member

    Joined:
    Aug 27, 2019
    Messages:
    342
    Country:
    Algeria
    @wavemotion Wow. It’s like you came out of nowhere and dropped some serious updates on a favorite emulator. Thanks so much! Can’t wait to see what you do next.
     
  7. Zense

    Zense GBARunner2 config: Touch the touchscreen + press R
    Member

    Joined:
    Apr 20, 2008
    Messages:
    1,839
    Country:
    Italy
    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?
     
    alexander1970 likes this.
  8. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    Country:
    United States
    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, Nov 25, 2020
  9. zfreeman

    zfreeman GBAtemp Maniac
    Member

    Joined:
    Mar 9, 2013
    Messages:
    1,198
    Country:
    United States
    Thank you for this. It always confused me how emulating such an old system could have any slowdown.
     
    alexander1970 and wavemotion like this.
  10. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    Country:
    United States
    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!
     
    alexander1970, zfreeman and VinsCool like this.
  11. CMDreamer

    CMDreamer GBAtemp Advanced Fan
    Member

    Joined:
    Oct 29, 2014
    Messages:
    886
    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).
     
    alexander1970 and wavemotion like this.
  12. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    Country:
    United States
    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.
     
  13. CMDreamer

    CMDreamer GBAtemp Advanced Fan
    Member

    Joined:
    Oct 29, 2014
    Messages:
    886
    Country:
    Mexico
    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!
     
    alexander1970 and wavemotion like this.
  14. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    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, Nov 25, 2020
  15. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    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, Nov 27, 2020
  16. ber71

    ber71 Advanced Member
    Newcomer

    Joined:
    Apr 24, 2019
    Messages:
    91
    Country:
    Spain
    Any chance for a pure DS build? For use on flashcarts.
    Thank you. Pleased to see people keeping the scene alive.
     
  17. wavemotion

    OP wavemotion GBAtemp Regular
    Member

    Joined:
    Nov 23, 2020
    Messages:
    123
    Country:
    United States
    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, Nov 28, 2020
  18. Flame

    Flame Me > You
    Moderator

    Joined:
    Jul 15, 2008
    Messages:
    5,501
    amazing work buddy. looking to forward future updates.
     
    alexander1970, Robz8 and wavemotion like this.
  19. MarioKartFan

    MarioKartFan GBAtemp Fan
    Member

    Joined:
    Aug 27, 2019
    Messages:
    342
    Country:
    Algeria
    Wow. This is exciting stuff.
     
    alexander1970, Robz8 and wavemotion like this.
  20. Coto

    Coto -
    Member

    Joined:
    Jun 4, 2010
    Messages:
    2,717
    Country:
    Chile
    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, Nov 28, 2020
    Flame, alexander1970, Robz8 and 2 others like this.
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - Improved, Stella,