Results 1 to 9 of 9

Thread: Project pictures: Tetris from scratch

  1. #1
    I asked for a
    Custom Rank and
    Learned My Lesson.

    Join Date
    Oct 2005
    Location
    USA

    Posts
    5,327

    Project pictures: Tetris from scratch

    After playing around a bit with my Analog Blackfin JAMMA board, I decided I wanted to try a more classic hardware design. I set out to make a working JAMMA PCB using nothing but standard 5v through-hole parts, using a well-known CPU that already had free tools.

    Quickly, I realized that it would require a ton of parts to build anything approximating a sprite engine. With an 8-bit CPU, I didn't want to deal with a framebuffer, either. So I decided my project would be limited in scope, to a machine with just a tilemap for video.

    This generally meant that I'd be building a puzzle game, as anything else would likely require some form of pixel-writing. So I decided to make a Tetris clone.

    I like the Z80, and it's still made in speed grades up to 20MHz, so I started with that. I decided to use 32KBytes of RAM and 32KBytes of ROM, because those parts (62256 and 27256) are commonly available as well. That made the memory address space easy.

    The video system is nearly as simple as possible. A set of dual-port RAMs (so the timing is easier) contains a tilemap, 2 bytes per 8x8 tile. 13 bits from each tilemap word address a pattern, and 3 bits address a palette. The patterns are stored in 4 64KByte ROMs, which are attached to 4 74LS166 shift registers to read out 8x 4bpp pixels. The 3 bits from the tilemap, and 4 bits from the pattern pixel, are used to address a palette ROM, containing a color palette. The color palette output goes to a set of 3x 4-bit DACs, made from resistor arrays. So it's basically one big chain of look-up tables in ROMs.

    I initially thought that I'd use a bunch of individual 8-bit output ports to control the video system. With a single interrupt at 15KHz, I should be able to re-load a starting tile address at each line, straight from the CPU. It would work something like the Atari 2600 in that respect. I decided that was too much overhead, though. It was simpler to get a microcontroller for that stuff. So the video system is controlled by an 8051-compatible microcontroller, running at 500KHz machine cycles. It's essentially a big busy-loop that toggles vsync/vblank pulses at the right time. It controls a port to set which video line is scanned out, and can reset a pair of 74LS193 counters to count tiles within the line.

    For other peripherals, I eventually settled on an 8255. It takes up the whole IO address space. I use port A to output commands to a microcontroller that makes sounds, and port B to output some extra address bits to the ROM containing the video color palettes. Port C, being bit-addressable, controls a set of shift registers an an I2C bus.

    I spent a while working out each part of this design, drawing up a schematic in Eagle. I laid out a circuit board and ordered it from DirtyPCBs.

    boards.jpg

    I put the board together, enough to get it booting and theoretically put something on screen. I had to wire up an adapter for the program ROM, because I wanted to use a battery-backed SRAM package instead of a UV EPROM.

    firstboot.jpg

    Having waited 10 days for the order, I had whipped up an emulator on my computer. I could run my Z80 code on the emulator to see what it would look like. So when I put it together - and sorted out a devious issue with a transposed address line on the ROM - I got it up and running with the same test code.

    booting.jpg

    Unfortunately, the 8255 didn't seem to work. I could read the ports as inputs just fine, but nothing I wrote to it seemed to do anything. Much debugging followed. I have an HP 1662CS logic analyzer which helped with logging tons of signals.

    debugmess.jpg

    Eventually I re-read the datasheet and found out that the 8255 treats the ~CS pin like an address pin, not a strobe. Deasserting ~CS won't properly terminate a write, and I had just wired the ~CS, ~RD, and ~WR straight to the Z80's ~IORQ, ~RD, and ~RW. So I effectively wasn't holding the ~CS pin long enough. I re-did the decoding to just tie that pin low, and decode ~IORQ and ~RD/~WR into strobes specifically for the 8255, using a 74LS38.

    For the sake of testing, I attached a Super Nintendo controller cable instead of the shift-registers on board. Normally, there would be a set of 3x 8-bit shift registers to latch 24 switch inputs from the JAMMA edge. A Super Nintendo controller is basically the same thing in a nice small package, though. Aside from inverting some of the signals in software, and getting them in a different order, it hooks right up.

    ioworking.jpg

    I've gotten the software to the point where I can run through a bunch of test-mode screens, and at least start to display the game graphics. There are some utilities on my computer for converting PNG files into tile-mapped backgrounds for the hardware.

    backgrounds.jpg

    I'm writing up the basics of the actual game loop now. I hope to post some more progress when it's ready.
    I turned off signatures. So should you.

  2. #2
    Krauser's Shoe Shiner
    -SD-'s Avatar
    Join Date
    May 2016
    Location
    UK

    Posts
    247
    This is really quite impressive. Looking forward to reading future updates. Awesome work
    Check out my sonís Pokťmon YouTube Channel.

  3. #3
    Skanky Turd.
    Simple Troll's Avatar
    Join Date
    Aug 2013
    Location
    Half Machine Lip Moves

    Posts
    654
    Amazing, man. Will you put it in a kind of case to make of consolized? Maybe even make the controls built in so itís like a plug n play super gun thing

    The universe is flat

  4. #4
    SouthTown StreetSweeper

    Join Date
    Oct 2016
    Location
    Pico Rivera, CA.

    Posts
    560
    Good luck completing your project.
    Looks like a bit of work, but fun.
    What's the grey stuff under the chip with the yellow wires
    After this, will you focus on other games?

  5. #5
    Disciple Of Orochi
    fenikso's Avatar
    Join Date
    Oct 2004
    Location
    Wandering through quiet lands

    Posts
    3,280
    Any plans to make and sell as a kit?

  6. #6
    Chroma Ma' Doma!
    Jedah Doma's Avatar
    Join Date
    Jun 2004
    Location
    VirKansas

    Posts
    9,876
    Nice idea. Looking forward to seeing where this goes.

  7. #7
    I asked for a
    Custom Rank and
    Learned My Lesson.

    Join Date
    Oct 2005
    Location
    USA

    Posts
    5,327
    Quote Originally Posted by Simple Troll View Post
    Amazing, man. Will you put it in a kind of case to make of consolized? Maybe even make the controls built in so it’s like a plug n play super gun thing
    I have trouble finishing projects, to put it nicely. I'm trying to keep the scope of the project down - just a plain JAMMA board that plays a game.

    Quote Originally Posted by sr20det510 View Post
    Good luck completing your project.
    Looks like a bit of work, but fun.
    What's the grey stuff under the chip with the yellow wires
    After this, will you focus on other games?
    It's duct tape. When I build the other copies (I've got 10 bare PCBs) the extra chip will probably sit on top of the 8255. And yeah, I have a couple other designs I want to try. One thing at a time, though.

    Quote Originally Posted by fenikso View Post
    Any plans to make and sell as a kit?
    I'm probably going to publish the source code and gerbers on my web site, so it shouldn't be hard to duplicate. I might sell my extra copies at-cost if I get them to a point where it's actually a usable game.


    I worked on the structure of the game code a bit today. I've got it cycling through some full-screen graphics as an attract mode, and accounting for coins/credits. There's an I2C EEPROM on board, so the plan is to score bookkeeping, high-scores, and coinage settings in the EEPROM. Right now I've got it stubbed-out so it's just 1 coin per credit.
    emu_shot.png
    I turned off signatures. So should you.

  8. #8
    . Totino's Avatar
    Join Date
    Apr 2018
    Location
    United States

    Posts
    10
    It would definitely be cool if you shared the nitty gritty, even if you didn't sell any sort of kit.

    I can't wait to read more about this. Hobbyists can do some really amazing things, so I look forward to reading about your progress!

  9. #9
    Formerly Giltygear
    xROTx
    FilthyRear's Avatar
    Join Date
    Jan 2007
    Location
    Parking in handicap spaces, while handicapped people make handicapped faces

    Posts
    6,701
    Quote Originally Posted by SpamYouToDeath View Post
    PLEASE keep this name.

    Real talk: Good luck, I'm looking forward seeing where this goes.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •