SKPIC32-based Experimental Mini-Game using VGA

Works done? Proud of it? Show off here! Let's see what you've built can help inspire others.

SKPIC32-based Experimental Mini-Game using VGA

Postby Brian Griffin » Fri May 25, 2012 2:56 pm

Project Name: SKPIC32-based Experimental Mini-Game using VGA and 1-bit colour.

Author/Designer: Y H

Project Description: As on the title, it is a experimental mini-game with 1-bit colour.

Due to the very short time of the creation, some parts of the game do not resemble the original "Space Invaders", like the barriers, "mystery saucer" and explodable alien projectile. Earlier games written during late 70s may only contain simple structured programming and many state machines, and this is also an attempt to imitate the progress but using high level language.

The laser shooter is controlled by the player through the PS2 Analog Joystick by Cytron, and the analog values are decoded in in the microcontroller on the fly.

The VGA part is controlled directly by taking advantage of the "Output Compare" modules in the PIC32, and all the Horizontal Sync and Vertical Sync are precisely timed. The horizontal drawing is done by using SPI, hence the 1-bit colour. An attempt to use partial shades and halftones are done but due to the PIC32's high-speed cache, this cannot be written in assembly code as each instruction in this MIPS processor has inconsistent number of cycles.

The system "paints" the screen from the frame buffer stored in the SKPIC32's RAM. As it has a lot of it, two frame buffers are used and double buffering is used to reduce screen tearing artifacts. Instead, while waiting for another vertical sync to happen, the system processes the logic of the game and such, so the maximum frame rate will be only limited to 30FPS. The resolution of the video is 432x480, and that resolution chews up 40% of the PIC32's available RAM.

Other attempts on the video was done using composite video, but unsuccessful due to the complexity of the signal itself. As a result, I broke a few fingernails trying to connect the thing to the TV.

There is no sound for now - as this is an experimental and a proof-of-concept build. The sound generated in the original Space Invaders arcade might be using completely analogue components. Modelling squarewaves and simple noises can be simply done in a PIC16F.

On the aliens returning fire - it is based on a random number generator. However, sometimes the thing is a bit wonky at times - some aliens can shoot a few times in a row until it is gotten rid of.

Photo:

frontscreen.jpg
Front Screen


gameover.jpg
Game Over Screen


playtime.jpg
Game in Progress


Compiler: MPLAB X IDE v1.10, MPLAB XC32 (latest)

Source code: Attached below.

Schematics:
schematic.jpg
Schematic


Video:


Note: All of the functions are lumped into one C file. I will seperate these functions in a later revision. :)
Attachments
skpic32-vga.X.zip
Source Code
(105.21 KiB) Downloaded 500 times
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby ABSF » Fri May 25, 2012 6:59 pm

Cool! 8-) I thought you wanted to do it on a small GLCD rather than on the PC VGA screen. :mrgreen:

Anyway, well done.... I love the graphics even though it was in B/W.

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby Brian Griffin » Fri May 25, 2012 7:42 pm

ABSF WROTE:Cool! 8-) I thought you wanted to do it on a small GLCD rather than on the PC VGA screen. :mrgreen:

Anyway, well done.... I love the graphics even though it was in B/W.

Allen


Thanks for the compliment.

Actually these are the remnants from the GLCD project I did 6 months ago back then. I ported them back to the VGA because the framerates are better. Painting these in a GLCD would just slow down the system.

I can attempt on the composite signal - just that it is very, very finicky and sensitive, and it never is a good result, so I tried something more simple like the VGA first. Plus, VGA connections are everywhere and won't break my fingernails every time I connect them. I zapped my hand twice on the composite signal connector due to the poor grounding and knocked my hand real hard when I connect them.

The problem in PIC32 is the cache - it made you can't count cycles in assembly, so I can't make any half-tones or shades effectively. Like those Atmel AVR and dsPIC, these are more easier to handle as they are straightforward when you count the cycles.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby yonghui » Sat May 26, 2012 11:14 am

wow, great!!
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby mec » Sat May 26, 2012 11:18 am

geng!
mec
Newbie
 
Posts: 12
Joined: Thu Sep 02, 2010 8:03 pm

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby takao21203 » Sat May 26, 2012 12:36 pm

I made composite video signal generator based on 2x NE555 from a book, some years ago.
Originally I wanted to build kind of a graphics card, and use a 18F PIC.
But this was way over my head, I had a PCB back then with some chips but have taken this apart again.

This NE555 signal worked OK for small mono television with composite input.
And should be easy to modulate via D/A. Some day I want to build such a circuit too.

I think if you want any kind of shades or colors, you need to design a small chipset, like a graphics card.

Trying to generate the composite timing via assembler or fast interrupts isn't so good for the software, the circuit from the book wasn't difficult at all, not full composite like in the specification but accepted by television set.

So if you want composite output, use external circuit for the timing. Actually isn't that just only 15 Khz? The circuit used R/C integrators to create the "porches" pulses when I remember right. I was thinking about this circuit a lot and how it works, somehow it is not properly caring about the interlace...
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby Brian Griffin » Sat May 26, 2012 4:34 pm

takao21203 WROTE:I made composite video signal generator based on 2x NE555 from a book, some years ago.
Originally I wanted to build kind of a graphics card, and use a 18F PIC.
But this was way over my head, I had a PCB back then with some chips but have taken this apart again.

This NE555 signal worked OK for small mono television with composite input.
And should be easy to modulate via D/A. Some day I want to build such a circuit too.

I think if you want any kind of shades or colors, you need to design a small chipset, like a graphics card.

Trying to generate the composite timing via assembler or fast interrupts isn't so good for the software, the circuit from the book wasn't difficult at all, not full composite like in the specification but accepted by television set.

So if you want composite output, use external circuit for the timing. Actually isn't that just only 15 Khz? The circuit used R/C integrators to create the "porches" pulses when I remember right. I was thinking about this circuit a lot and how it works, somehow it is not properly caring about the interlace...


That's cool. Initially I want to attempt it on an FPGA - but since it's just to demonstrate the capabilities of the PIC32, so I wrote that program.

A much, much better implementation to do it is actually on FPGA/CPLD, with plenty of SRAM as frame buffers. Unfortunately the FPGA board is glued in my workplace, so I do not have access to another one. Plus, not much here in Cytron forums are exposed to Verilog/VHDL, so I prefer to write it in a normal software form first. You can buy those cheap FPGA boards from Ebay directly, but will take weeks to come.

I will try the composite video on an STM32 discovery board I have lying for years. It has a DAC inside and that will reduce component count. :)
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby takao21203 » Sun May 27, 2012 1:01 am

Hmm yes CPLD or FPGA. I have one small Altera CPLD board here, have not done much with it, and software is gigabytes, need to download again...

Eventually I want to build a television interface for 68000 computer. Recently ordered PCI proto boards, since previous attemps did not work out so well. PCI is used as bus/backplane.

I have one Hitachi chip here that was used for graphics cards in the late 1980s but only for reference, not to use it in a circuit.

Back two years ago I did some circuits for graphics display on paper, figured out all that's needed is a two port memory, means buffers, or complicate memory bus timing. The related ICs are cheap these days, so it could be done with I/O buffers.

So the graphics card circuit reads out the memory for display continuously, and also tests the buffer, if there is data, it is copied into the graphics memory.

Well your project is different, generating timing for VGA in software! Can PIC32 be used with assembler at all? I have some PIC32 here, looked the manual, but assembler looks too complicated to me.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby Brian Griffin » Sun May 27, 2012 1:15 am

takao21203 WROTE:Hmm yes CPLD or FPGA. I have one small Altera CPLD board here, have not done much with it, and software is gigabytes, need to download again...

Eventually I want to build a television interface for 68000 computer. Recently ordered PCI proto boards, since previous attemps did not work out so well. PCI is used as bus/backplane.

I have one Hitachi chip here that was used for graphics cards in the late 1980s but only for reference, not to use it in a circuit.

Back two years ago I did some circuits for graphics display on paper, figured out all that's needed is a two port memory, means buffers, or complicate memory bus timing. The related ICs are cheap these days, so it could be done with I/O buffers.

So the graphics card circuit reads out the memory for display continuously, and also tests the buffer, if there is data, it is copied into the graphics memory.

Well your project is different, generating timing for VGA in software! Can PIC32 be used with assembler at all? I have some PIC32 here, looked the manual, but assembler looks too complicated to me.


The CPLD/FPGA is the easiest way out of all these problems, actually. But to learn Verilog and to get over with the parallelism (for starters from microcontroller background, it may be difficult) is another thing.

I do not know about driving PCI signals - they can be very complicated. On one time I thought of using an old ISA graphic card to communicate with the another microcontroller but I simply don't have the time to do it.

You can use the PIC32 with assembler, but timing can be difficult to calculate due to the cache and the architecture inside. Same as the ARM, these are not directly calculated like 8/16 bit-microcontrollers where counting cycles are very straightforward.
PIC - UIC00B from Cytron (replacement for my broken PICKit 2), Pickit 3, MikroC for PIC
dsPIC - MikroC for dsPIC, mikromedia board (dsPIC33)
AVR - AVR Dragon
Parallax - Prop tool
User avatar
Brian Griffin
Enthusiast
 
Posts: 403
Joined: Mon Jan 17, 2011 9:36 am

Re: SKPIC32-based Experimental Mini-Game using VGA

Postby takao21203 » Sun May 27, 2012 5:52 am

No, I bought PCI bus backplane PCB + empty PCI proto cards. Soldering wires for 68000 bus is way too much effort.
PCI is also just only the same like many wires in parallel. I can use the backplane PCB like I want, all connections seem to be 1:1.
The backplane PCB is here already, the PCBs were ordered...

I also don't have enough time to work out television interface, I would like to do it, have looked at some designs on the web, made some circuits years ago, but very likely will use color LCD. Actually in 2005 and 2006 I researched video interface ICs used in game consoles.

But composite video is not so difficult I think. I saw one circuit on the net, generating composite video in color, using a delay network, not a specialized IC.

I hope 68K computer running this year, and including 18F PIC. once it works, I can think about television interface eventually.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Next

Return to Project Showcase

Who is online

Users browsing this forum: No registered users and 6 guests

cron