/* ============================================================================= File: STARS.C Author: Radouan Khechane (rad@cyberdude.com) Date: 21st December 1998 Description: Simulates a starfield on the Net Yaroze PlayStation Copyright (c) 1998 by Radouan Khechane. ============================================================================= */ /* ==================== I N C L U D E S ==================== */ #include // PlayStation library #include "pad.h" // joypad header file /* ==================== D E F I N E S ==================== */ #define OT_LENGTH (1) // length of Ordering Table #define SCREEN_WIDTH (320) // screen x resolution #define SCREEN_HEIGHT (240) // screen y resolution #define STARS_MAX (100) // number of stars /* ==================== S T R U C T U R E S ==================== */ typedef struct { int x, y; // position of star int z; // depth of star used to determine colour and speed int velocity; // speed int colour; // colour } star_t; /* ==================== G L O B A L S ==================== */ GsOT OT_Header[2]; // Ordering Table Headers GsOT_TAG OT_Tag[2][1<= SCREEN_WIDTH) star[i].x -= SCREEN_WIDTH; } } /* ================ DrawStarfield() draws the stars in the starfield ================ */ void DrawStarfield (void) { // register stars into the odering table for (i = 0; i < STARS_MAX; i++) { // position star_ot.x0 = star_ot.x1 = star[i].x; star_ot.y0 = star_ot.y1 = star[i].y; // colour star_ot.r = star_ot.g = star_ot.b = star[i].colour; // register GsSortLine(&star_ot, &OT_Header[activeBuffer], 1); } } /* ================ DrawScreen() ================ */ void DrawScreen (void) { // get drawing buffer number activeBuffer = GsGetActiveBuff(); // set drawing command storage address GsSetWorkBase((PACKET*)GpuPacketArea[activeBuffer]); // initialise odering table GsClearOt(0, 0, &OT_Header[activeBuffer]); DrawStarfield(); // wait for completion of all drawing DrawSync(0); // wait for vertical retrace VSync(0); // swap double buffers (display and drawing buffer) GsSwapDispBuff(); // register clear (screen) command GsSortClear(0x0, 0x0, 0x0, &OT_Header[activeBuffer]); // register request to draw ordering table GsDrawOt(&OT_Header[activeBuffer]); }