sega_logo-a1.png
gfx.res
Code: Select all
IMAGE sega_logo_image "sega_logo-a1.png" -1
Code: Select all
#ifndef _GFX_H_
#define _GFX_H_
extern const Image sega_logo_image;
#endif // _GFX_H_
Code: Select all
#include <genesis.h>
#include "gfx.h"
//Sets default values for VDP register
//Cleans video RAM
//Loads 4 default palettes ; Grey, Red, Green and Blue
//Loads a default font for text print need
//Initializes input handling
//Resets sound and music
//Loads a default sound driver
int main( )
{
// Disable interrupts when accessing VDP
SYS_disableInts();
// Initialization
VDP_setScreenWidth320();
VDP_setScreenHeight240();
// Define variables
u16 palette[64];
u16 ind = TILE_USERINDEX;
// Load image
VDP_drawImageEx(APLAN, &sega_logo_image, TILE_ATTR_FULL(PAL0, FALSE, FALSE, FALSE, ind), 14, 11, FALSE, TRUE);
ind += sega_logo_image.tileset->numTile;
// Prepare palettes
memcpy(&palette[16], sega_logo_image.palette->data, 16 * 2);
VDP_setPalette(0, sega_logo_image.palette->data);
//VDP process done - re-enable interrupts
SYS_enableInts();
while(1)
{
//Wait for screen refresh
VDP_waitVSync();
}
return 0;
}
The tutorials were out of date so I had to go through the forum and SGDK samples to find the bits and pieces I needed to get it to work.
My biggest obstacle with this project was to get the palette to work. I decided to share my code so as to make things easier for new developers.
Upon running this to generate a rom you'll notice that the logo has no animation yet. I did get some animation ,but the images got messed up.
I think it has something to do with the tile arrangement or indexing. The frames are also displaying letters in between the image tiles.
Adding some text for testing purposes;
Code: Select all
//Writes "Test" above the sega logo image
VDP_setTextPalette(PAL2); //PAL0 = Grey/Custom ,PAL1 = Red ,PAL2 = Green ,PAL3 = Blue
VDP_drawText("Test", 14, 9);
gfx.res
Code: Select all
IMAGE frame1 "sega_anim-1.png" -1
IMAGE frame2 "sega_anim-2.png" -1
IMAGE frame3 "sega_anim-3.png" -1
IMAGE frame4 "sega_anim-4.png" -1
IMAGE frame5 "sega_anim-5.png" -1
IMAGE frame6 "sega_anim-6.png" -1
IMAGE frame7 "sega_anim-7.png" -1
IMAGE frame8 "sega_anim-8.png" -1
IMAGE frame9 "sega_anim-9.png" -1
IMAGE frame10 "sega_anim-10.png" -1
IMAGE frame11 "sega_anim-11.png" -1
IMAGE frame12 "sega_anim-12.png" -1
IMAGE frame13 "sega_anim-13.png" -1
IMAGE frame14 "sega_anim-14.png" -1
IMAGE frame15 "sega_anim-15.png" -1
IMAGE frame16 "sega_anim-16.png" -1
Code: Select all
#ifndef _GFX_H_
#define _GFX_H_
extern const Image frame1;
extern const Image frame2;
extern const Image frame3;
extern const Image frame4;
extern const Image frame5;
extern const Image frame6;
extern const Image frame7;
extern const Image frame8;
extern const Image frame9;
extern const Image frame10;
extern const Image frame11;
extern const Image frame12;
extern const Image frame13;
extern const Image frame14;
extern const Image frame15;
extern const Image frame16;
#endif // _GFX_H_
Code: Select all
#include <genesis.h>
#include "gfx.h"
//Sets default values for VDP register
//Cleans video RAM
//Loads 4 default palettes ; Grey, Red, Green and Blue
//Loads a default font for text print need
//Initializes input handling
//Resets sound and music
//Loads a default sound driver
int main( )
{
// Disable interrupts when accessing VDP
SYS_disableInts();
// Initialization
VDP_setScreenWidth320();
VDP_setScreenHeight240();
// Load animation frames into an array
const Image *images[16] =
{
&frame1,
&frame2,
&frame3,
&frame4,
&frame5,
&frame6,
&frame7,
&frame8,
&frame9,
&frame10,
&frame11,
&frame12,
&frame13,
&frame14,
&frame15,
&frame16
};
// Define variables
u16 ind = TILE_USERINDEX;
u16 i = 0;
u16 pal = PAL0;
u16 vpos = 0; //Vpos
char str[8]; //
u16 newInd = ind;
u16 maxInd = newInd + 1080;
intToStr(ind, str, 1); //
VDP_setTextPlan(PLAN_A);
VDP_drawText(str, 0, 0);
//Animation
for(i = 0; i < 16; i++)
{
Image *img = images[i]; //Pointer warning
// Number of tiles for the current image
u16 numTile = img->tileset->numTile;
// Not enough VRAM space for the current image? Reset the index
if ((ind + numTile) >= maxInd)
{
ind = newInd;
}
u16 nextvpos = vpos ^ 0x20; //Vertical position fix
VDP_drawImageEx(BPLAN, images[i], TILE_ATTR_FULL(pal, FALSE, FALSE, FALSE, ind), 14, vpos + 11, TRUE, TRUE);
// Move to new image
VDP_waitVSync();
VDP_setVerticalScroll(PLAN_B, nextvpos * 8); //Vpos
ind += images[i]->tileset->numTile;
pal ^= 1;
//waitTick(10);
vpos = nextvpos; //Vpos
waitTick(100);
//ypos = nextypos;
}
VDP_setTextPalette(PAL2);
VDP_drawText("Test", 14, 9);
// VDP process done, re enable interrupts
SYS_enableInts();
while(1)
{
//Wait for screen refresh
VDP_waitVSync();
}
return 0;
}