Shop OBEX P1 Docs P2 Docs Learn Events
Hydra NES Pacman Emulator — Parallax Forums

Hydra NES Pacman Emulator

DarrylDarryl Posts: 3
edited 2011-11-25 15:47 in Propeller 1
In case anyone is interested I am attaching an implementation of an emulator of the original 1980s Nintendo Entertainment System (NES) for the Hydra, running the original Pacman game.

This is an emulation - meaning that every original 6502 instruction is read in and interpreted by the Hydra in real-time. It's not yet perfect but I think it is somewhat amazing that it works at all. This project ran up against all the limitations of the Hydra - only 32 KB of memory to hold the original ROM code, the ROM Pattern Table information, the Name Table information, sprite data, pallettes, scratch memory, etc. In addition there is the constraint of only 512 longs per cog. Inevitably this means that you can't put everything you want in. In particular I wasn't able to include quite all of the original pattern table and unused 6502 instructions are not emulated. The program uses all the available cogs. If I could I would like one more cog to emulate the sound of the original NES. The Hydra appears fast enough at least for this game, but a few more CPU cycles would be nice.

Why was Pacman chosen for this NES emulation project? The answer is that Pacman is a relatively early game which uses only 16KB (out of the 32 KB available on the NES) and only vertical scrolling (no horizontal scrolling) and horizontal mirroring. Therefore it was potentially feasible. Many larger games simply will not be feasible without a major change in approach (such as the use of the Hydra 512K RAM extension card). My objective was to run the original Pacman ROM code. This was nearly achieved. The ROM code was altered slightly for a couple of reasons - one was to change the original pallette of colors (I haven't yet worked out how to do color mapping in real time), another was to take out one KB of unused space to give me just a little more room.

The program seems to run fine. It emulates all the sprites, name tables, scrolling etc. of the original NES, together with the ability to read the gamepad. It also emulates the PPU's non-maskable interrupt which occurs every time the screen is refreshed (during vertical blanking).

One of the nice features of running an emulator is that debugging on the Hydra is made a lot easier. The emulator allows you to step through one instruction at a time, observing changes to each register (including the stack and the status register), together with changes to any memory location you wish to observe. You can add a breakpoint at any instruction.

This code is not perfect. In particular there are some color artifacts of two kinds. First the colors on the title screen are not quite right due to some problems implementing the PPU's attribute table feature. Perhaps someone can figure out what I am doing wrong. The second problem is related to the sprites themselves. Each sprite somehow picks up the color set of another sprite on the same line. This is a subtle error which has proved hard to debug. I am putting the code up as it is. Still, the sprites are mostly the right colors. Also, as noted above, there is no emulation of sound, due to a lack of cogs and a lack of memory space.

This project uses Eric Ball's 6502 emulator which is clever and efficient. But there were a few "errors" in Eric's original code which I spent many hours trying to track down. Hopefully that is now done.

Having put in a lot of effort to get Pacman running I am hoping to move on to test the emulator on some other NES game. I figure that once I have tried this approach on a few different (simple) games I'll be in a better position to know just how much this emulation approach is feasible. Again, the amazing thing here is that it works at all. We are not quite yet in the position of having an NES-on-a-chip, but this comes close.

I am attaching the code as it is. This is my first attempt at distributing code in this way. If there are any concerns about copyright etc. I will, of course, take it down. I am happy to discuss...

Post Edited (Darryl) : 1/11/2010 11:23:50 AM GMT
«1

Comments

  • BaggersBaggers Posts: 3,019
    edited 2010-01-11 12:56
    WOW, Darryl, what a first post [noparse]:)[/noparse] congrats, on achieving your emu [noparse]:)[/noparse] this is indeed a great moment!

    Edit: Darryl, your main Spin is in a repeat loop, you could use that for an audio cog [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite



    Post Edited (Baggers) : 1/11/2010 1:59:59 PM GMT
  • potatoheadpotatohead Posts: 10,253
    edited 2010-01-11 15:11
    This is excellent... And I'm a nice chunk of the way through soldering a 6502 board...

    I love being wrong about what a Prop can do, like this!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!

    Post Edited (potatohead) : 1/11/2010 3:32:04 PM GMT
  • trodosstrodoss Posts: 577
    edited 2010-01-11 15:30
    What Baggers said...WOW! Great job!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-11 16:24
    Great step forward!

    Would someone post the change to run this on the demoboard? (Video)

    Thanks!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • BaggersBaggers Posts: 3,019
    edited 2010-01-11 16:55
    OBC, there you go.
    You'll have to sort out the joypad stuff yourself, I don't know what pins you've got them on.

    it was three simple changes.

    in NES_Pacman_emulator_010.spin

    · _clkmode = xtal1 + pll16x· ' Set clock multiplier to 8x
    · _xinfreq = 5_000_000 + 0_000 ' Set to 10Mhz (and add 5000 to fix crystal imperfection of hydra prototype)
    and·in NES_tv_017

    _pins·················· long··· %001_0101······ 'pins
    Hope this helps.

    Baggers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-11 17:48
    Thanks Baggers!

    @Potatohead.. Have you got a chance to do a screenshot? I'm working today.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • potatoheadpotatohead Posts: 10,253
    edited 2010-01-11 17:51
    Yeah, I can get one in a little bit. Gotta get a start on the work week first [noparse]:)[/noparse]

    (trust me, I'm itching to run this)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!
  • ericballericball Posts: 774
    edited 2010-01-11 18:16
    Excellent!· I'm glad my 6502 core found some use.· (Although I appologise that you had to spend time finding my bugs.)



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Composite NTSC sprite driver: Forum
    NTSC & PAL driver templates: ObEx Forum
    OnePinTVText driver: ObEx Forum
  • trodosstrodoss Posts: 577
    edited 2010-01-11 18:18
    @Darryl,
    Maybe something from http://www.pdroms.de/files/nes/Games/?page=1 for the next one (if you are worried about legality).

    Also, Bob Rost had written a few demos/games (and had class projects) in NES game dev. Could be that you could use something from there:
    http://bobrost.com/nes/resources.php

    I wish they would have had classes in that when I was going through university [noparse];)[/noparse]

    Post Edited (trodoss) : 1/12/2010 3:13:51 AM GMT
  • BaggersBaggers Posts: 3,019
    edited 2010-01-11 18:29
    Darryl, there are some jumps to exit_emulation also, that should probably be jmp #exit_emulation [noparse]:D[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-11 18:47
    Elite is on that page.. I know that the author "released" it.

    I started to sweat a little when I saw that... [noparse]:)[/noparse]

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • trodosstrodoss Posts: 577
    edited 2010-01-11 22:59
    Thanks OBC for keepin' me honest [noparse];)[/noparse]
    They are all supposed to be "Public Domain," however, I can't vouch for the content (or sources for said content).
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-12 04:17
    I finally got the chance to run this...


    AWESOME work! Some minor screen jitter, and of course that color issue that
    was mentioned, but I'm actually playing NES pacman on my propeller! Neato!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Ahle2Ahle2 Posts: 1,178
    edited 2010-01-12 21:31
    @Darryl
    That must be the most awesome opening post ever.
    If you want I can make the APU, it shouldn't be any problem compared to a SID.
    Okey, I just read trough your entire post and I realize that fitting the APU isn't possible thanks to memory limitation [noparse]:([/noparse]

    Post Edited (Ahle2) : 1/13/2010 9:46:44 AM GMT
  • potatoheadpotatohead Posts: 10,253
    edited 2010-01-13 15:39
    Here are a few screen shots. I got called outta town and just got to run this myself.

    Very cool. I'm looking forward to giving this a more detailed look tonight. (hotel room Propeller time again!!)


    Running on HYBRID, which is 96Mhz. There is some screen tearing and such. Are there timing dependent elements in there? Probably 80 percent of the frames are solid, the rest vary a bit.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!

    Post Edited (potatohead) : 1/14/2010 10:23:50 AM GMT
    720 x 540 - 263K
    720 x 540 - 324K
    720 x 540 - 320K
  • CassLanCassLan Posts: 586
    edited 2010-01-22 00:52
    WOW!!!
    That is truly awesome.

    Rick

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PrEditor·- Text Editor


    NYC Area Prop Club





    ·
  • HumanoidoHumanoido Posts: 5,770
    edited 2010-01-22 16:00
    Fantastic!!!! A great accomplishment!

    humanoido
  • potatoheadpotatohead Posts: 10,253
    edited 2010-01-22 18:45
    Yeah, it's killer. I've been looking things over, eager to start some hacking of my own. I've shown this off some, and it packs a nice punch!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Propeller Wiki: Share the coolness!
    8x8 color 80 Column NTSC Text Object
    Safety Tip: Life is as good as YOU think it is!
  • heaterheater Posts: 3,370
    edited 2010-01-23 18:39
    Phenomenal !

    Us poor saps have been struggling along for two years now to get a Z80 emulator up with CP/M and a text mode display on the Prop. And here you are with a 6502 emulation and full graphics glory.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    For me, the past is not over yet.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-01-26 04:02
    Has anyone made any headway into correcting the color issue with this?

    I'd like to load this into my Propacade.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Cluso99Cluso99 Posts: 18,066
    edited 2010-02-08 02:06
    Great news that the 6502 emulation is running. And pacman, though I am not really into games. Thus I missed the original post.

    Would you like to make a post, in particular about the 6502 emulation, to my emulator thread index (see link in my signature).

    I think we need a Games index thread too. Anyone up to the challange of maintaining it? - The creator needs to maintain it, because every so often you should update the first post with new additions and links. This is what I do for the Emulator and Tools indexes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • VaatiVaati Posts: 712
    edited 2010-02-08 02:18
    Whoah!!! Am I reading right--this emulates the NES?!?!?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Quit buying all those fixed voltage regulators, and·get an Adjustable Power Supply·for your projects!· Includes an LED testing terminal!

    (no longer new) SD Card Adapter·Now available!· Add extra memory to your next Propeller project with ease!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-02-08 04:26
    See what happens when you leave... tisk..tisk.. [noparse]:)[/noparse]

    Yup.. but we haven't heard much out of the author after his inital post..

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-02-09 15:33
    Cluso99 said...


    I think we need a Games index thread too. Anyone up to the challange of maintaining it? - The creator needs to maintain it, because every so often you should update the first post with new additions and links. This is what I do for the Emulator and Tools indexes.

    I'll update the PROJECTS: master list tonight.
    It includes a list of games at the top.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • Cluso99Cluso99 Posts: 18,066
    edited 2010-02-09 16:54
    Thanks OBC. Sorry, I had forgotten about your list.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Links to other interesting threads:

    · Home of the MultiBladeProps: TriBlade,·RamBlade,·SixBlade, website
    · Single Board Computer:·3 Propeller ICs·and a·TriBladeProp board (ZiCog Z80 Emulator)
    · Prop Tools under Development or Completed (Index)
    · Emulators: CPUs Z80 etc; Micros Altair etc;· Terminals·VT100 etc; (Index) ZiCog (Z80) , MoCog (6809)·
    · Prop OS: SphinxOS·, PropDos , PropCmd··· Search the Propeller forums·(uses advanced Google search)
    My cruising website is: ·www.bluemagic.biz·· MultiBlade Props: www.cluso.bluemagic.biz
  • DarrylDarryl Posts: 3
    edited 2010-02-12 23:55
    Following up my earlier post, I have sorted out a lot of the problems with the first version of the emulator that was distributed in January.

    The emulator now works fine on three different NES games - Galaga, Pacman, and Donkey Kong.

    These games were all chosen because they use only 16K of the 32K available ROM space on the NES and because they use only horizontal mirroring. It should not be too big a deal to emulate a game with vertical mirroring - that is one of the next tasks.

    The color artifacts present in the last version of the emulator have been resolved. The PPU driver also now does 8x16 sprites (necessary for Galaga). Also some remaining problems in the 6502 emulation were corrected. There are still some minor issues with sprites. The Hydra is not quite fast enough to display numbers of sprites on a single line so sometimes sprites drop out.

    There is still no emulation of sound (not enough memory space) and currently only one of the game controllers is active.

    I have packaged all three games in the attached zip file. The "top level" file is NES_DonkeyKong_emulator_010, NES_Galaga_emulator_010, and NES_Pacman_emulator_010, respectively. However, if you check these files you will see that they are basically the same spin code, but just loading different game cartridge ROM and PPU ROM data.

    I have also attached a file which shows my view of the best mapping between Hydra colors and NES colors. I have found that, in order to get the best correspondence between the Hydra and NES colors I need to turn up the "saturation" control on my video-in device to about the 90% level. This makes the colors on the Hydra much more vivid and there is quite a close match between the Hydra and the NES for colors.

    In the case of the Donkey Kong game, after you press the start button there is a delay of a couple of seconds before the game starts - during this period the original game plays a short tune, which of course you can't hear in these emulations, so just be a bit patient!

    If you want to contact me directly email darryl.biggar@stanfordalumni.org.
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-02-13 04:54
    Aweome!

    Is anyone else experiencing horizontal? (screen rolling down) roll with these games?
    I don't have an adjustment for that on the TV.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • BaggersBaggers Posts: 3,019
    edited 2010-02-13 10:57
    Darryl, awesome job, looks great now, and two additional classics [noparse]:D[/noparse], ( apart from the very slight screen wobble )

    OBC, I'm having the same screen rolling also.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-02-16 15:26
    TV roll seems to be hit and miss depending on the screen.

    I just changed out the tube in my arcade box and it seems to be a bit more tolerant of the hold.
    I can't help but think that we had a similar discussion in another thread about a problem like this,
    but I can't find it. (Darn forum software! )

    Anyone remember?

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Visit the: The Propeller Pages @ Warranty Void.
  • FredBlaisFredBlais Posts: 370
    edited 2010-02-17 20:52
    Darryl, thanks for this! I'm hyped for next releases... glad to see elite programmers for the hydra.
Sign In or Register to comment.