int main() { PSX_Init(); GsInit(); GsSetList(prim_list); GsClearMem(); GsSetVideoMode(320, 240, VMODE_PAL); GsLoadFont(768, 0, 768, 256); SetVBlankHandler(prog_vblank_handler); while(1) { if(display_is_old) { dbuf=!dbuf; GsSetDispEnvSimple(0, dbuf ? 0 : 256); GsSetDrawEnvSimple(0, dbuf ? 256 : 0, 320, 240); GsSortCls(0,0,0); GsPrintFont(70, 120, "Hello World"); GsDrawList(); while(GsIsDrawing()); display_is_old=0; } } return 0; }
int InitGraphics() { GsInit(); GsSetVideoMode(1, 2, 0); GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT1, 255); //display context 1 on tv GsSetDefaultDrawEnv(&draw_env, SCREEN_OFFSET_X, SCREEN_OFFSET_Y, SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDrawEnvAddress(&draw_env, 0, SCREEN_WIDTH/64, GS_PIXMODE_32); GsSetDefaultDisplayEnv(&disp_env, 656, 36+(36/2), SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDisplayEnvAddress(&disp_env, 0, SCREEN_WIDTH/64, GS_PIXMODE_32); //execute draw/display environment(s) (context 1) GsPutDrawEnv1(&draw_env); GsPutDisplayEnv1(&disp_env); //set some common stuff GsOverridePrimAttributes(GS_DISABLE, 0, 0, 0, 0, 0, 0, 0, 0); // contex 1 GsEnableAlphaTransparency1(GS_ENABLE, GS_ALPHA_GEQUAL, 0x01, 0x00); // contex 2 GsEnableAlphaTransparency2(GS_ENABLE, GS_ALPHA_GEQUAL, 0x01, 0x00); GsEnableAlphaBlending1(GS_ENABLE, 0); GsEnableAlphaBlending2(GS_ENABLE, 0); return 0; }
int main() { PSX_Init(); GsInit(); GsSetList(prim_list); GsClearMem(); GsSetVideoMode(320, 240, COMPILE_VMODE); GsLoadFont(768, 0, 768, 256); SetVBlankHandler(prog_vblank_handler); volatile int player1_score = 0; volatile int player2_score = 0; volatile int weapon1 = 0; volatile int weapon2 = 0; volatile int pause = 0; volatile int newround = 0; while(1) { if(display_is_old) { dbuf=!dbuf; GsSetDispEnvSimple(0, dbuf ? 0 : 256); GsSetDrawEnvSimple(0, dbuf ? 256 : 0, 320, 240); if(newround == 1) { while((pause + 240) > time_counter) { }; newround = 0; }; GsSortCls(0,0,255); if(player1_score == 10) { GsPrintFont(5, 100, " Player 1 wins. Take that, Player 2."); player1_score = 0; player2_score = 0; newround = 1; } else if(player2_score == 10) { GsPrintFont(5, 100, " Player 2 wins. Hah, Player 1 fails."); player1_score = 0; player2_score = 0; newround = 1; } else { GsPrintFont(5, 100, " Take 10 paces and draw your weapons!"); }; GsPrintFont(5, 15, " Rock, Paper, Scissors by Moonlit"); GsPrintFont(5, 22, " ----------------------------------"); GsPrintFont(5, 45, " Choose your weapon: Scores: "); GsPrintFont(5, 52, "--------------------- ---------"); GsPrintFont(5, 60, " SQUARE = Rock P1: %d", player1_score); GsPrintFont(5, 70, " CROSS = Paper P2: %d", player2_score); GsPrintFont(5, 80, " CIRCLE = Scissors "); PSX_ReadPad(&pad1, &pad2); if(pad1 & PAD_SQUARE) { //P1 ROCK weapon1 = 1; } else if(pad1 & PAD_CROSS) { //P1 PAPER weapon1 = 2; } else if(pad1 & PAD_CIRCLE) { //P1 SCISSORS weapon1 = 3; }; if(pad2 & PAD_SQUARE) { //P2 ROCK weapon2 = 1; } else if(pad2 & PAD_CROSS) { //P2 PAPER weapon2 = 2; } else if(pad2 & PAD_CIRCLE) { //P2 SCISSORS weapon2 = 3; }; pause = time_counter; if(weapon1 > 0 && weapon2 > 0) { if(weapon1 == 1) GsPrintFont(5, 130, " Player 1 chose rock...");; if(weapon1 == 2) GsPrintFont(5, 130, " Player 1 chose paper...");; if(weapon1 == 3) GsPrintFont(5, 130, " Player 1 chose scissors...");; if(weapon2 == 1) GsPrintFont(5, 140, " Player 2 chose rock...");; if(weapon2 == 2) GsPrintFont(5, 140, " Player 2 chose paper...");; if(weapon2 == 3) GsPrintFont(5, 140, " Player 2 chose scissors...");; // It's a draw. if(weapon1 == 1 && weapon2 == 1) { GsPrintFont(5, 170, " Thick as two bricks."); GsPrintFont(5, 180, " Surely there's mortar life..?"); }; if(weapon1 == 2 && weapon2 == 2) { GsPrintFont(5, 170, " Two sheets to the wind."); GsPrintFont(5, 180, " It's blowing up in here."); }; if(weapon1 == 3 && weapon2 == 3) { GsPrintFont(5, 170, " Neither of you are the "); GsPrintFont(5, 180, " sharpest in the drawer, are you?"); }; // Player 1 wins. if(weapon1 == 1 && weapon2 == 3) { GsPrintFont(5, 160, " Careful Player 2... "); GsPrintFont(5, 170, " You'll ruin those scissors."); GsPrintFont(5, 180, " That's a point for Player 1."); player1_score++; }; if(weapon1 == 2 && weapon2 == 1) { GsPrintFont(5, 160, " Aw, gift wrapped rocks."); GsPrintFont(5, 170, " Really, Player 2."); GsPrintFont(5, 180, " You shouldn't have."); player1_score++; }; if(weapon1 == 3 && weapon2 == 2) { GsPrintFont(5, 160, " Player 2 gets the chop."); GsPrintFont(5, 170, " A ticker tape parade for Player 1."); GsPrintFont(5, 180, " What other use for shredded paper?"); player1_score++; }; // Player 2 wins. if(weapon2 == 1 && weapon1 == 3) { GsPrintFont(5, 160, " Stab in the back for Player 1."); GsPrintFont(5, 170, " At least those blades"); GsPrintFont(5, 180, " are safer now."); player2_score++; }; if(weapon2 == 2 && weapon1 == 1) { GsPrintFont(5, 160, " +1 for Player 2."); GsPrintFont(5, 170, " Player 1 gets stoned."); GsPrintFont(5, 180, " Too wrapped up in the game."); player2_score++; }; if(weapon2 == 3 && weapon1 == 2) { GsPrintFont(5, 160, " Player 1's all cut up."); GsPrintFont(5, 170, " It's twice as nice when "); GsPrintFont(5, 180, " the paper's sliced."); player2_score++; }; newround = 1; weapon1 = 0; weapon2 = 0; }; GsDrawList(); while(GsIsDrawing()); display_is_old=1; } } return 0; }
int InitGraphics() { static int env0_address; static int env1_address; GsInit(); GsSetVideoMode(1, 2, 0); GsSetCRTCSettings(CRTC_SETTINGS_DEFAULT1, 255); //display contex 1 //alloc 2 buffers in vram env0_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32); env1_address = GsVramAllocFrameBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, GS_PIXMODE_32); /*********SETUP CONTEX 1 ENVIRONMENT*************/ GsSetDefaultDrawEnv (&draw_env[0], SCREEN_OFFSET_X, SCREEN_OFFSET_Y, SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDrawEnvAddress(&draw_env[0], env0_address, SCREEN_WIDTH/64, GS_PIXMODE_32); GsSetDefaultDisplayEnv (&disp_env[0], 656, 36+(36/2), SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDisplayEnvAddress(&disp_env[0], env1_address, SCREEN_WIDTH/64, GS_PIXMODE_32); /*********SETUP CONTEX 2 ENVIRONMENT*************/ GsSetDefaultDrawEnv (&draw_env[1], SCREEN_OFFSET_X, SCREEN_OFFSET_Y, SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDrawEnvAddress(&draw_env[1], env1_address, SCREEN_WIDTH/64, GS_PIXMODE_32); GsSetDefaultDisplayEnv (&disp_env[1], 656, 36+(36/2), SCREEN_WIDTH, SCREEN_HEIGHT); GsSetDefaultDisplayEnvAddress(&disp_env[1], env0_address, SCREEN_WIDTH/64, GS_PIXMODE_32); //execute draw/display environment(s) (contex 1) GsPutDrawEnv1 (&draw_env[0]); GsPutDisplayEnv1(&disp_env[0]); //execute draw/display environment(s) (contex 2) GsPutDrawEnv2 (&draw_env[1]); GsPutDisplayEnv2(&disp_env[1]); //set some common stuff GsOverridePrimAttributes(GS_DISABLE, 0, 0, 0, 0, 0, 0, 0, 0); // contex 1 GsEnableAlphaTransparency1(GS_ENABLE, GS_ALPHA_GEQUAL, 0x01, 0x00); // contex 2 GsEnableAlphaTransparency2(GS_ENABLE, GS_ALPHA_GEQUAL, 0x01, 0x00); GsEnableAlphaBlending1(GS_ENABLE, 0); GsEnableAlphaBlending2(GS_ENABLE, 0); return 0; }
void game_run() { int x, y, a, b, c; unsigned short padbuf; while(speed_counter > 0) { scc++; if(vibration_cntdown > 0) { printf("vibration = %d\n", vibration_cntdown); pad_enable_vibration(0); pad_set_vibration(0, 0xFF, 0x80); vibration_cntdown--; if(vibration_cntdown == 0) pad_set_vibration(0, 0, 0); } PSX_ReadPad(&padbuf, NULL); if(scc == 5 && !game_over) { if(snake_dir <= SNAKE_DIR_RIGHT) { if(padbuf & PAD_UP) snake_dir = SNAKE_DIR_UP; if(padbuf & PAD_DOWN) snake_dir = SNAKE_DIR_DOWN; } else { if(padbuf & PAD_LEFT) snake_dir = SNAKE_DIR_LEFT; if(padbuf & PAD_RIGHT) snake_dir = SNAKE_DIR_RIGHT; } for(y = 0; y < 29; y++) for(x = 0; x < 40; x++) { if(snake_array[y][x] == snake_size) { switch(snake_dir) { case SNAKE_DIR_LEFT: b = y; a = x-1; break; case SNAKE_DIR_RIGHT: b = y; a = x+1; break; case SNAKE_DIR_UP: b = y-1; a = x; break; case SNAKE_DIR_DOWN: b = y+1; a = x; break; } c = check_snake_collision(a,b); if(c) { snake_array[b][a] = snake_size+1; if(c==2) { snake_size++; score+=100; //printf("%d\n", score); SsKeyOn(2); new_apple(); } } else { vibration_cntdown = 10; game_over = 1; SsKeyOff(0); SsKeyOn(1); scc = 0; } if(snake_array[y][x] == 1 && c!=2) snake_array[y][x] = 0; goto out_of_collision_checking; } } out_of_collision_checking: for(y = 0; y < 29; y++) for(x = 0; x < 40; x++) if(snake_array[y][x]&&snake_array[y][x]<0x80&&c!=2) snake_array[y][x]--; scc = 0; } else if(game_over) { scc++; if(scc >= 510) { if((padbuf & PAD_CROSS) && !cross_pressed) { game_setup(); cross_pressed = 1; } else if((padbuf & PAD_CIRCLE) && !circle_pressed) { circle_pressed = 1; GsSetVideoMode(320, 240, pal_or_ntsc_selection()); game_setup(); } if(!(padbuf & PAD_CROSS)) cross_pressed = 0; if(!(padbuf & PAD_CIRCLE)) circle_pressed = 0; } } speed_counter--; } if(screen_old) { game_rect.x = 0; game_rect.y = 0; game_rect.w = 320; game_rect.h = 240; game_rect.r = 0; game_rect.g = 0; game_rect.b = 0; game_rect.attribute = 0; GsSortRectangle(&game_rect); game_sprite.x = 0; game_sprite.y = 0; game_sprite.w = 256; game_sprite.h = 240; game_sprite.u = 0; game_sprite.v = 0; game_sprite.r = NORMAL_LUMINOSITY; game_sprite.g = NORMAL_LUMINOSITY; game_sprite.b = NORMAL_LUMINOSITY; game_sprite.tpage = 5; game_sprite.attribute = COLORMODE(COLORMODE_16BPP); GsSortSimpleSprite(&game_sprite); game_sprite.x += 256; game_sprite.w = 64; game_sprite.tpage = 9; GsSortSimpleSprite(&game_sprite); game_rect.w = 8; game_rect.h = 8; game_rect.attribute = ENABLE_TRANS | TRANS_MODE(0); for(y = 0; y < 29; y++) { for(x = 0; x < 40; x++) { game_rect.x = x * 8; game_rect.y = y * 8; if(snake_array[y][x] >= 1 && snake_array[y][x] <= 0x7F) { game_rect.r = 0; game_rect.g = 255; game_rect.b = 0; GsSortRectangle(&game_rect); } else if(snake_array[y][x] == 0x80) { game_rect.r = 255; game_rect.g = 0; game_rect.b = 255; GsSortRectangle(&game_rect); } else if(snake_array[y][x] == 0x81) { game_rect.r = 0; game_rect.g = 0; game_rect.b = 128; GsSortRectangle(&game_rect); } } } sprintf(string_buf, "SCORE: %d", score); game_print(string_buf, 0, 232); if(game_over) { game_rect.w = 320; game_rect.h = 240; game_rect.x = 0; game_rect.y = 0; if(scc<=255)x=scc;else x=255; game_rect.r = x; game_rect.g = x; game_rect.b = x; game_rect.attribute = ENABLE_TRANS|TRANS_MODE(2); GsSortRectangle(&game_rect); if(scc>=300) { game_center_print("GAME OVER!", 160, 120); } if(scc>=420) game_center_print("WHAT DO YOU WANT TO DO NOW?", 160, 136); if(scc>=450) game_center_print("PRESS X TO RESTART THE GAME.",160, 152); if(scc>=480) game_center_print("PRESS O FOR PAL/NTSC SELECTION SCREEN.",160,168); if(scc>=510) game_center_print("MADE WITH PSXSDK BY GIUSEPPE GATTA, 2010", 160, 200); } GsDrawList(); // While the graphic synthesizer (video card) is drawing // just sleep. while(GsIsDrawing()); // Swap drawing and display Y position, and swap list array // to use. In this way we achieve a double buffer. if(game_dispenv.y == 0) { game_dispenv.y = 256; game_drawenv.y = 0; } else { game_dispenv.y = 0; game_drawenv.y = 256; } GsSetDispEnv(&game_dispenv); GsSetDrawEnv(&game_drawenv); screen_old = 0; } }
int main() { int c; // Initialize game_init(); printf("PSXsnake\n"); printf("(c) 2009 Giuseppe Gatta\n"); printf("Made with PSXSDK\n\n"); load_file_into_buffer("cdrom:FONT.TIM;1"); GsImageFromTim(&game_image, file_buffer); GsUploadImage(&game_image); game_clut[0] = 0x0; game_clut[1] = 0x7fff; LoadImage(game_clut, 640, 24, 16, 1); GsSetVideoMode(320, 240, EXAMPLES_VMODE); vmode = pal_or_ntsc_selection(); //printf("vmode = %d\n", vmode); GsSetVideoMode(320, 240, vmode); load_file_into_buffer("cdrom:BACKGRND.TIM;1"); GsImageFromTim(&game_image, file_buffer); GsUploadImage(&game_image); sample_pos[0] = SPU_DATA_BASE_ADDR; c = load_file_into_buffer("cdrom:MUSIC.RAW;1"); SsUpload(file_buffer, c, sample_pos[0]); if(c&0x7) { c|=0x7; c++; } sample_pos[1] = c + sample_pos[0]; c = load_file_into_buffer("cdrom:BOMB.RAW;1"); SsUpload(file_buffer, c, sample_pos[1]); /* ... */ if(c&0x7) { c|=0x7; c++; } sample_pos[2] = c + sample_pos[1]; c = load_file_into_buffer("cdrom:APPLE.RAW;1"); SsUpload(file_buffer, c, sample_pos[2]); SsVoiceStartAddr(0, sample_pos[0]); SsVoiceStartAddr(1, sample_pos[1]); SsVoiceStartAddr(2, sample_pos[2]); SsVoiceVol(0, 0x3fff, 0x3fff); SsVoiceVol(1, 0x3fff, 0x3fff); SsVoiceVol(2, 0x3fff, 0x3fff); SsVoicePitch(0, 0x1000 / (44100 / 11025)); SsVoicePitch(1, 0x1000 / (44100 / 11025)); SsVoicePitch(2, 0x1000); game_setup(); SetVBlankHandler(game_vblank_handler); while(1) game_run(); return 0; }