/* * A simple ball-and-paddle video game for the Yaroze. * By: Ed Federmeyer (Just messing around with the Yaroze functions) */ #include #include "pad.h" typedef struct { char *fname; void *addr; CdlFILE finfo; } FILE_INFO; #define VH_ADDR 0x80090000 #define VB_ADDR 0x800a0000 #define SEQ_ADDR 0x80110000 #define MVOL 127 /* Main volume level*/ #define SVOL 96 /* SEQ volume level*/ #define DFILE 3 /* File number*/ FILE_INFO dfile[DFILE] = { {"\\DATA\\SOUND\\STD0.VH;1", (void *)VH_ADDR, 0}, {"\\DATA\\SOUND\\STD0.VB;1", (void *)VB_ADDR, 0}, {"\\DATA\\SOUND\\MUSI.SEQ;1", (void *)SEQ_ADDR, 0}, /* or GOGO.SEQ */ }; short vabID, seq; void datafile_search(); /* File retrieval on CD-ROM */ void datafile_read(); /* File reading on CD-ROM */ void init_sound(); /* Sound data on memory playback preparation */ void play_sound(); /* Sound playback start */ void stop_sound(); /* Sound playback termination */ #define PAD_SPEED 5 #define PAD_X_SIZE 8 #define PAD_Y_SIZE 32 #define BALL_SPEED 2 #define BALL_X_SIZE 8 #define BALL_Y_SIZE 8 #define BG_X_MIN 20 #define BG_X_MAX 492 #define BG_Y_MIN 40 #define BG_Y_MAX 220 #define PACKETMAX (10000) #define PACKETMAX2 (PACKETMAX*24) #define OT_LENGTH (5) GsOT WorldOrderingTable[2]; GsOT_TAG zSortTable[2][1<BG_Y_MAX-PAD_Y_SIZE ) { pad1_sprite.y = BG_Y_MAX-PAD_Y_SIZE; } } GsSortFastSprite( &pad1_sprite, &WorldOrderingTable[outputBufferIndex], 1 ); if ( pad_data & PAD2Lup ) { pad2_sprite.y -= PAD_SPEED; if ( pad2_sprite.yBG_Y_MAX-PAD_Y_SIZE ) { pad2_sprite.y = BG_Y_MAX-PAD_Y_SIZE; } } GsSortFastSprite( &pad2_sprite, &WorldOrderingTable[outputBufferIndex], 2 ); ball_sprite.x += xi; if ((ball_sprite.xBG_X_MAX-BALL_X_SIZE-1)) { if ( ball_sprite.xBG_Y_MAX-BALL_Y_SIZE-1) ) { SsUtKeyOn(vabID, 9, 0, 58, 0, 127, 127); ball_sprite.y -= yi; yi = -yi; } if ((ball_sprite.y+BALL_Y_SIZE > pad1_sprite.y) && (ball_sprite.y < pad1_sprite.y+PAD_Y_SIZE) && (ball_sprite.x+BALL_X_SIZE > pad1_sprite.x) && (ball_sprite.x < pad1_sprite.x+PAD_X_SIZE)) { SsUtKeyOn(vabID, 8, 0, 58, 0, 127, 127); ball_sprite.x -= xi; xi = -xi; if ( ball_sprite.y+(BALL_Y_SIZE/2) < pad1_sprite.y+(PAD_Y_SIZE/3) ) { ball_sprite.y -= yi; yi = -abs(yi); } if ( ball_sprite.y+(BALL_Y_SIZE/2) > pad1_sprite.y+PAD_Y_SIZE-(PAD_Y_SIZE/3) ) { ball_sprite.y -= yi; yi = abs(yi); } pad1_sprite.r = 128; pad1_sprite.g = 128; pad1_sprite.b = 128; } else if ( (ball_sprite.y+BALL_Y_SIZE > pad2_sprite.y) && (ball_sprite.y < pad2_sprite.y+PAD_Y_SIZE) && (ball_sprite.x+BALL_X_SIZE > pad2_sprite.x) && (ball_sprite.x < pad2_sprite.x+PAD_X_SIZE)) { SsUtKeyOn(vabID, 8, 0, 58, 0, 127, 127); ball_sprite.x -= xi; xi = -xi; if ( ball_sprite.y+(BALL_Y_SIZE/2) < pad2_sprite.y+(PAD_Y_SIZE/3) ) { ball_sprite.y -= yi; yi = -abs(yi); } if ( ball_sprite.y+(BALL_Y_SIZE/2) > pad2_sprite.y+PAD_Y_SIZE-(PAD_Y_SIZE/3) ) { ball_sprite.y -= yi; yi = abs(yi); } pad2_sprite.r = 128; pad2_sprite.g = 128; pad2_sprite.b = 128; } else { pad1_sprite.r = 0; pad1_sprite.g = 128; pad1_sprite.b = 0; pad2_sprite.r = 0; pad2_sprite.g = 0; pad2_sprite.b = 128+64; } GsSortFastSprite( &ball_sprite, &WorldOrderingTable[outputBufferIndex], 3 ); /* Draw a box */ GsSortLine( &line1, &WorldOrderingTable[outputBufferIndex], 10 ); GsSortLine( &line2, &WorldOrderingTable[outputBufferIndex], 11 ); GsSortLine( &line3, &WorldOrderingTable[outputBufferIndex], 12 ); GsSortLine( &line4, &WorldOrderingTable[outputBufferIndex], 13 ); /* Draw a background */ if ( bg_timer++ > 1 ) { if ( xi > 0 ) { bg.scrollx--; } else { bg.scrollx++; } if ( yi > 0 ) { bg.scrolly--; } else { bg.scrolly++; } bg_timer = 0; } GsSortFixBg16( &bg, &bg_work_area[0], &WorldOrderingTable[outputBufferIndex], 15 ); /* Mask out the background we don't want */ GsSortBoxFill( &box1, &WorldOrderingTable[outputBufferIndex], 14 ); GsSortBoxFill( &box2, &WorldOrderingTable[outputBufferIndex], 14 ); GsSortBoxFill( &box3, &WorldOrderingTable[outputBufferIndex], 14 ); GsSortBoxFill( &box4, &WorldOrderingTable[outputBufferIndex], 14 ); DrawSync(0); VSync(0); pad_data = PadRead(); GsSwapDispBuff(); GsSortClear( 0x0, 0x0, 0x0, &WorldOrderingTable[outputBufferIndex] ); GsDrawOt( &WorldOrderingTable[outputBufferIndex] ); FntPrint( "Player1: %03d", score1 ); FntPrint( " " ); FntPrint( "Player2: %03d\n", score2 ); FntFlush( -1 ); } while ( !(pad_data & PADselect) ); /* Execute this by pressing select button and verifying */ // Stop the music stop_sound(); ResetGraph(3); } /********************************************************************** * Code snarfed from other demos **********************************************************************/ void datafile_search() { int i, j; for (i = 0; i < DFILE; i++) /* Deal with DFILE file */ { for (j = 0; j < 10; j++) /* Return loop */ { if (CdSearchFile(&(dfile[i].finfo), dfile[i].fname) != 0) break; else /* Retry loop interruption on normal termination */ printf("%s not found.\n", dfile[i].fname); } } } void datafile_read() { int i, j; int cnt; for (i = 0; i < DFILE; i++) /* Deal with DFILE file */ { for (j = 0; j < 10; j++) /* Retry loop */ { CdReadFile(dfile[i].fname, dfile[i].addr,dfile[i].finfo.size); /* Normal processing can be executed by other side of read */ /* Here, remaining sector number is monitored until Read terminated */ /* Wait for VSync for time adjustment */ while ((cnt = CdReadSync(1, 0)) > 0 ) VSync(0); /* Retry loop interruption on normal termination*/ if (cnt == 0) break; } } } void init_sound() { /* VAB opening and transmission to sound buffer */ vabID = SsVabTransfer( (u_char*)VH_ADDR, (u_char*)VB_ADDR, -1, 1 ); if (vabID < 0) { printf("SsVabTransfer failed (%d)\n", vabID); return; } /* SEQ opening */ seq = SsSeqOpen((u_long *)SEQ_ADDR, vabID); if (seq < 0) printf("SsSeqOpen failed (%d)\n", seq); } void play_sound() { SsSetMVol(MVOL, MVOL); /* Main volume setting*/ SsSeqSetVol(seq, SVOL, SVOL); /* Volume setting for each SEQ */ SsSeqPlay(seq, SSPLAY_PLAY, SSPLAY_INFINITY); /* Playback switch ON */ } void stop_sound() { SsSeqStop(seq); /* Playback switch OFF */ VSync(0); VSync(0); SsSeqClose(seq); /* SEQ close */ SsVabClose(vabID); /* VAB close */ }