Code: Select all
/******************************************************************************
DEMO TEST SPOTLIGHT EFFECT (LINE SCROLL + SHADOW MODE)
******************************************************************************/
#include <genesis.h>
// CONSTANTS ==================================================================
// Some data to deal with graphical data
#define NUM_COLUMNS 40
#define NUM_ROWS 28
#define NUM_LINES NUM_ROWS * 8
#define NUM_TILES_TILESET 3
// Places where we place tiles at Genesis VRAM
#define VRAM_POS_TILE1 1
#define VRAM_POS_BRICK_A 1
#define VRAM_POS_BRICK_B 2
#define VRAM_POS_TILE_VOID 3
// How many pixels bottom line is going to swing
#define SPOTLIGHT_SWING_RANGE 50
// Some other data
#define SPOTLIGHT_WIDTH 8
#define NUM_SPOTLIGHTS NUM_COLUMNS / SPOTLIGHT_WIDTH
// TILESET ====================================================================
const u32 background_tileset[NUM_TILES_TILESET*8] =
{
// TILE 1: brick left half
0x11211111, 0x12222222, 0x12422222, 0x12242222, 0x12422222, 0x12222222, 0x12222222, 0x33333333,
// TILE 2: brick right half
0x11111113, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x22222223, 0x32333333,
// TILE 3: empty/transparent tile
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
};
// PALETTE ====================================================================
const u16 background_palette[16] = {
0x0000,0x06CE,0x044E,0x0008,0x008C,0x0000,0x0000,0x0000,
0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
};
// MACROS =====================================================================
#define DrawWall(); \
for(row = 0; row < NUM_ROWS; row += 2) \
for(column = 0; column < NUM_COLUMNS; column += 2) \
{ \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column, row); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column+1, row); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_B, column, row+1); \
VDP_setTileMap( BPLAN, VRAM_POS_BRICK_A, column+1, row+1); \
}
#define DrawSpotlights(); \
for(row = 0; row < NUM_ROWS; row++) \
for(column = 0; column < NUM_SPOTLIGHTS; column++) \
for(tile_spotlight = 0; tile_spotlight < SPOTLIGHT_WIDTH; tile_spotlight++) \
{ \
VDP_setTileMap( APLAN, TILE_ATTR_FULL(PAL0, column%2, 0, 0, VRAM_POS_TILE_VOID), \
(column * SPOTLIGHT_WIDTH) + tile_spotlight, row); \
}
#define InitializeScrollTable(); \
for(line = 0; line < NUM_LINES; line++) line_scroll_data[line] = FIX16(0);
#define InitializeSpeedTable(); \
line_speed_data[0] = FIX16(0.05); \
for(line = 1; line < NUM_LINES; line++) \
line_speed_data[line] = fix16Add(line_speed_data[line-1], FIX16(0.04));
//=============================================================================
// MAIN =======================================================================
//=============================================================================
int main()
{
// Local data _____________________________________________________________
// Indexes
u8 row, column; // Horizontal and vertical tile placement index/coords
u8 line; // Pixel line/row index
u8 tile_spotlight; // Horizontal tile counter for drawing spotlights
u8 i; // Auxiliar loop index
// Line scroll buffers
fix16 line_scroll_data[NUM_LINES]; // Current line scroll values
fix16 line_speed_data[NUM_LINES]; // Line scroll speeds
s16 aux[NUM_LINES]; // Needed for VDP_setHorizontalScrollLine
// Initialization lot _____________________________________________________
// Scroll
InitializeScrollTable();
InitializeSpeedTable();
// Process ________________________________________________________________
// Screen setting
VDP_setScrollingMode(HSCROLL_LINE, VSCROLL_PLANE);
VDP_setHilightShadow(1); // Hilight/shadow activation
// Loading tile stuff and color data into VRAM/CRAM
VDP_setPalette(PAL0, (u16 *) background_palette);
VDP_loadTileData( (const u32 *) background_tileset, VRAM_POS_TILE1, NUM_TILES_TILESET, 1);
// Drawing
DrawWall();
DrawSpotlights();
// MAIN LOOP ______________________________________________________________
while(1)
{
for(line = 0; line < NUM_LINES; line++)
{
// Sum the speed value
line_scroll_data[line] = fix16Add(line_scroll_data[line], line_speed_data[line]);
// Rebound when movement of bottom line reaches its left or right boundary
if(line_scroll_data[NUM_LINES-1] >= FIX16(SPOTLIGHT_SWING_RANGE)
|| line_scroll_data[NUM_LINES-1] <= FIX16(-SPOTLIGHT_SWING_RANGE))
line_speed_data[line] *= -1;
// An auxiliar "regular integer" buffer is needed for VDP_setHorizontalScrollLine
aux[line] = fix16ToInt(line_scroll_data[line]);
}// end for(NUM_LINES)
// Set Horizontal Scroll
VDP_setHorizontalScrollLine(APLAN, 0, aux, NUM_LINES, 1);
// Drawing/movement speed down
for(i=0; i<4; i++) VDP_waitVSync();
} // end main loop
return 0; // Ok ... we'll return something
} // end main()