SKPIC32-based 256-color Video Experimental Game

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

Re: SKPIC32-based 256-color Video Experimental Game

Postby Brian Griffin » Mon Jul 30, 2012 7:24 pm

takao21203 WROTE:
CODE: SELECT_ALL_CODE
void vga_draw_sprite(unsigned char x, unsigned char y, unsigned char spriteWidth, unsigned char spriteHeight, const unsigned char* sprite, unsigned char* inputBuffer)
{
    unsigned char i, j;
    x_temp0=(x+(y*256));
    for(i = 0; i < spriteHeight; i++)
    {
        x2_temp=i*spriteWidth;
        for(j = 0; j < spriteWidth; j++)
        {
            inputBuffer[x_temp++] = sprite[x2_temp++];
        }
        x2_temp+=256;
    }
}


Eventually you know about this already. When I wrote assembler games for MS-DOS,
optimization was kind of essential, since the VGA RAM access was very time consuming already.


Is it the modified code? I'm welcoming any optimizations. :)
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 256-color Video Experimental Game

Postby takao21203 » Mon Jul 30, 2012 7:29 pm

yes I modified it inside MPLABX. Hope it still works the same.
User avatar
takao21203
Discoverer
 
Posts: 111
Joined: Mon Mar 19, 2012 7:52 pm
Location: Ireland, Europe

Re: SKPIC32-based 256-color Video Experimental Game

Postby Brian Griffin » Mon Jul 30, 2012 8:19 pm

takao21203 WROTE:yes I modified it inside MPLABX. Hope it still works the same.


Thanks. I wished to write tile-rendering engine but not now. Maybe when I have some more free time. :)
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

Explanation of VGA signal generation.

Postby Brian Griffin » Tue Jul 31, 2012 11:09 pm

Note: For those who wants to test the VGA (at 640x480 resolution) code - make sure the Horizontal Syncs and Vertical Syncs are all accurate.

Here's the H-sync (Horizontal Sync) in oscilloscope:
hsync.jpg
Horizontal Sync profile.
hsync.jpg (42.71 KiB) Viewed 4684 times


The H-sync periods are approximately 31.77uS. The H-syncs are controlled by Timer2 in the PIC32. Any more or any less than that, your monitor won't be getting any signals. These H-sync "low-pulse" is generated by the Output Compare interrupt after approximately 3.77uS. Seperately, and meanwhile, then comes another Output Compare interrupt where the DMA started streaming pixels for 25.17uS.

Here's the V-sync (Vertical Sync) in oscilloscope:
vsync.jpg
Vertical Sync profile.
vsync.jpg (42.18 KiB) Viewed 4684 times


The V-sync periods are aprroximately 16.67ms. On a number of H-sync periods, the V-sync is "low-pulse", and then for an amount of 480 H-syncs alongside with the streaming pixels, you get a frame. One picture frame. Here's the entire signal profile, for easier reference:

Image
Source:
http://www.javiervalcarce.eu/wiki/VGA_Video_Signal_Format_and_Timing_Specifications

Continue these and you basically see something on a monitor, depending what you draw on the framebuffer.
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

Previous

Return to Project Showcase

Who is online

Users browsing this forum: No registered users and 8 guests

cron