/*
* Includes
*/
#include "genesis.h"
/*
* Function prototypes
*/
void init_gfx();
/*
* External Calls/Data
*/
extern uint back2_pal[];
extern ulong back2[];
extern uint back2_VSize;
extern uint back2_HSize;
extern uint shake_pal[];
extern ulong shake[];
extern uint shake_VSize;
extern uint shake_HSize;
/*
* Main program
*/
void main()
{
uint posx, posy, joy;
register uint x,y,k;
/* Initialize Genesis GFX registers */
init_gfx();
/* Initialize Genesis joypads */
init_joypad();
/* Set Palette Colors */
set_colors(0,back2_pal);
set_colors(1,shake_pal);
/* Load Tiles and Sprite into VRAM */
dma_vram_copy(back2, 32, 32 * back2_HSize * back2_VSize);
dma_vram_copy(shake, 32 + 32 * back2_HSize * back2_VSize, 32 * shake_HSize * shake_VSize);
wait_sync();
/* Display Background */
k=1;
for(y=0;y<back2_VSize*2;y++,y++)
{
for(x=0;x<back2_HSize;x++)
{
show_tiles(k, k, 0,x,y, BPLAN, 0,0,0);
k++;
}
}
/* Set Start sprite position */
posx=160;
posy=165;
/* Define and show the sprite in Plane A, with Palette 1 */
def_sprite(1,posx,posy,0xF00,0xA000 + (32 + 32 * back2_HSize * back2_VSize)/32 );
show_sprite(1,1);
wait_sync();
/* Program Loop, read joypad and move sprite */
while(1)
{
joy= read_joypad1();
if (joy)
{
switch(joy & 0xff)
{
case JOY_RIGHT:
posx++;
break;
case JOY_LEFT:
posx--;
break;
case JOY_UP:
posy--;
break;
case JOY_DOWN:
posy++;
break;
case JOY_ULEFT:
posy--;
posx--;
break;
case JOY_URIGHT:
posy--;
posx++;
break;
case JOY_DLEFT:
posy++;
posx--;
break;
case JOY_DRIGHT:
posy++;
posx++;
break;
}
def_sprite(1,posx,posy,0xF00,0xA000 + (32 + 32 * back2_HSize * back2_VSize)/32 );
show_sprite(1,1);
wait_sync();
}
}
}
/*
* Initilize the GFX.
*/
void init_gfx()
{
register uint *pw;
pw = (uint *) GFXCNTL;
*pw = 0x8016; /* reg. 0 - Enable HBL */
*pw = 0x8174; /* reg. 1 - Enable display, VBL, DMA + VCell size */
*pw = 0x8230; /* reg. 2 - Plane A =$30*$400=$C000 */
*pw = 0x832C; /* reg. 3 - Window =$2C*$400=$B000 */
*pw = 0x8407; /* reg. 4 - Plane B =$7*$2000=$E000 */
*pw = 0x855F; /* reg. 5 - sprite table begins at $BC00=$5E*$200 */
*pw = 0x8600; /* reg. 6 - not used */
*pw = 0x8700; /* reg. 7 - Background Color number*/
*pw = 0x8800; /* reg. 8 - not used */
*pw = 0x8900; /* reg. 9 - not used */
*pw = 0x8a01; /* reg 10 - HInterrupt timing */
*pw = 0x8b00; /* reg 11 - $0000abcd a=extr.int b=vscr cd=hscr */
*pw = 0x8c00; /* reg 12 - hcell mode + shadow/highight + interlaced mode (40 cell, no shadow, no interlace)*/
*pw = 0x8d2E; /* reg 13 - HScoll Table = $B800 */
*pw = 0x8e00; /* reg 14 - not used */
*pw = 0x8f02; /* reg 15 - auto increment data */
*pw = 0x9011; /* reg 16 - scrl screen v&h size (64x64) */
*pw = 0x9100; /* reg 17 - window hpos */
*pw = 0x92ff; /* reg 18 - window vpos */
}