====== Video game with PIC18 ====== ===== Intro ===== PIC18 is not quite effective controller to drive VGA monitor, but they are able to be implemented for these purposes. This example shows how to use PIC18F2550 to build video game. In 2004 I developed **[[osa:articles:vga_terminal|VGA-terminal]]**, where I used PIC18 to produce VGA control signals to form text data on the screen. When I was a boy (in early 80-th) I had a ZX Spectrum. My favorite game was a Bulder Dash by [[http://www.firststarsoftware.com|First Star Software]]. Now I tried to encode this game woth PIC18 controller. Here are source code, video and description of my works. Source codes: {{:osa:articles:vga_game.rar|}} All modules in this program were written in C (HT-PICC18), except interrupt service routine - it was fully written in assembler. Program controlled by RTOS OSA. Program specification: {|class = "fpl" |**Controller** |PIC18F2550 |- |**Fosc** |48 MHz (12 MIPS) |- |**RTOS** |OSA |- |**VGA** |256x200 pixels, 15 colors |- |**Polyphony** |5 voices (4 for music, 1 for game effects). Sample rate = 15 KHz |- |**Game field** |40x20 objects |- |**Viewable field size** |16x12 objects |} ===== Video (34 Mb) ===== Here is a small video. The quality is not very well since I used low-cost web-camera. Sound was recorded through line-in.
\\ \\ Unfortunately I could not to record video in better way. In fact, the picture is more clearly: {{:osa:articles:vga_game_big_plan.jpg|}} ===== Description ===== ==== Scheme ==== The principal scheme it rather simple: {{:osa:articles:vga_game_scheme.png|}} Logically, scheme can be splitted into four parts: - microcontroller - device's heart; - 3 resistors and 6 diodes to form RGB-signals; - low noize filter to produce sound; - 5 buttons with pull-up resistors. How to form image on VGA-monitor is described [[osa:articles:vga_terminal#view_generating|here]]. Here is device's photo: {{:osa:articles:vga_boulder_dash_device.jpg|}} ==== Controller's resources ==== As you can see, controller should to do many jobs simultaneously: sync signals for VGA generating, RGB-signals generating, multyvoice sound generating. All these jobs should be synchronized to within a cycle, otherwise the picture on the monitor will shake. Besides, the game should work in real-time: buttons reading, animation, objects moving, music playing, soung effects and ect. I decided to put all time critical processes into interrupt service routine, and all other to put into OS tasks functions. These tasks are placed into ISR: * VGA sync pulses generating; * RGB-singals generating; * sound sinthesizer; * button read with debounce. Other tasks are placed in remaining program part: * making animation; * game rules; * music and sound effects forming. ====== (UNFINISHED) ====== (see **[[http://www.pic24.ru/doku.php/osa/articles/vga_game|russian text]]**)