Page 2 of 2

Re: SKPIC32-based 256-color Video Experimental Game

PostPosted: Mon Jul 30, 2012 7:24 pm
by Brian Griffin
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. :)

Re: SKPIC32-based 256-color Video Experimental Game

PostPosted: Mon Jul 30, 2012 7:29 pm
by takao21203
yes I modified it inside MPLABX. Hope it still works the same.

Re: SKPIC32-based 256-color Video Experimental Game

PostPosted: Mon Jul 30, 2012 8:19 pm
by Brian Griffin
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. :)

Explanation of VGA signal generation.

PostPosted: Tue Jul 31, 2012 11:09 pm
by Brian Griffin
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 4949 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 4949 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.