From 7c24e9a9b02b04dcaf9507acb94091ea70a2c02d Mon Sep 17 00:00:00 2001 From: Xavi Del Campo Date: Fri, 31 Jan 2020 10:32:23 +0100 Subject: Imported pristine psxsdk-20190410 from official repo --- examples/puzzle/Makefile | 9 ++ examples/puzzle/puzzle.bmp | Bin 0 -> 150582 bytes examples/puzzle/puzzle.c | 216 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 examples/puzzle/Makefile create mode 100644 examples/puzzle/puzzle.bmp create mode 100644 examples/puzzle/puzzle.c (limited to 'examples/puzzle') diff --git a/examples/puzzle/Makefile b/examples/puzzle/Makefile new file mode 100644 index 0000000..ee00787 --- /dev/null +++ b/examples/puzzle/Makefile @@ -0,0 +1,9 @@ +PROJNAME = puzzle + +include ../project.mk + +$(PROJNAME)_extra: + mkdir -p cd_root + bmp2tim puzzle.bmp cd_root/puzzle.tim 16 -org=320,0 + +$(PROJNAME)_clean_extra: diff --git a/examples/puzzle/puzzle.bmp b/examples/puzzle/puzzle.bmp new file mode 100644 index 0000000..ed689c8 Binary files /dev/null and b/examples/puzzle/puzzle.bmp differ diff --git a/examples/puzzle/puzzle.c b/examples/puzzle/puzzle.c new file mode 100644 index 0000000..8f2786f --- /dev/null +++ b/examples/puzzle/puzzle.c @@ -0,0 +1,216 @@ +#include +#include +#include + + +unsigned char puzzle_pieces[7][7]; +unsigned char piece_taken[7 * 7]; + +int puzzle_x = 0, puzzle_y = 0; + +volatile int display_is_old = 1; + +void prog_vblank_handler() +{ + display_is_old=1; +} + +GsImage puzzle_image; +unsigned int prim_list[0x4000]; +unsigned char data_buffer[0x40000]; // 256 kilobytes + +int main() +{ + int x, y, ex, ey; + int wasleft=0; + int wasright=0; + int wasup=0; + int wasdown=0; + int wasexh=0; + int wasexv=0; + int dbuf=0; + unsigned char b; + unsigned short padbuf; + FILE *f; + GsSprite tile_sprite; + GsRectangle tile_rectangle; + + PSX_Init(); + GsInit(); + GsClearMem(); + GsSetList(prim_list); + GsSetVideoMode(320, 240, EXAMPLES_VMODE); + + f = fopen("cdrom:\\PUZZLE.TIM;1", "rb"); + fseek(f, 0, SEEK_END); + x = ftell(f); + fseek(f, 0, SEEK_SET); + + fread(data_buffer, sizeof(char), x, f); + fclose(f); + + GsImageFromTim(&puzzle_image, data_buffer); + + GsUploadImage(&puzzle_image); + while(GsIsDrawing()); + + GsLoadFont(768, 0, 768, 256); + while(GsIsDrawing()); + + tile_sprite.tpage = 5; + tile_sprite.w = 32; + tile_sprite.h = 32; + tile_sprite.attribute = COLORMODE(COLORMODE_16BPP); + tile_sprite.r = tile_sprite.g = tile_sprite.b = NORMAL_LUMINOSITY; + + SetVBlankHandler(prog_vblank_handler); + + for(x=0;x0) + puzzle_x--; + + wasleft=1; + } + + if((padbuf & PAD_RIGHT) && !wasright) + { + if(puzzle_x<6) + puzzle_x++; + + wasright=1; + } + + if((padbuf & PAD_UP) && !wasup) + { + if(puzzle_y>0) + puzzle_y--; + + wasup=1; + } + + if((padbuf & PAD_DOWN) && !wasdown) + { + if(puzzle_y<6) + puzzle_y++; + + wasdown=1; + } + + if(!(padbuf & PAD_LEFT)) + wasleft=0; + + if(!(padbuf & PAD_RIGHT)) + wasright=0; + + if(!(padbuf & PAD_UP)) + wasup=0; + + if(!(padbuf & PAD_DOWN)) + wasdown=0; + + if((padbuf & PAD_CROSS) && !wasexh) // x <--> y + { + ey = puzzle_y; + if(puzzle_x < 6) + ex = puzzle_x+1; + else + ex = puzzle_x-1; + + b = puzzle_pieces[puzzle_y][puzzle_x]; + puzzle_pieces[puzzle_y][puzzle_x] = + puzzle_pieces[ey][ex]; + puzzle_pieces[ey][ex] = b; + + wasexh=1; + } + + if((padbuf & PAD_CIRCLE) && !wasexv) + { + ex = puzzle_x; + if(puzzle_y < 6) + ey = puzzle_y+1; + else + ey = puzzle_y-1; + + b = puzzle_pieces[puzzle_y][puzzle_x]; + puzzle_pieces[puzzle_y][puzzle_x] = + puzzle_pieces[ey][ex]; + puzzle_pieces[ey][ex] = b; + + wasexv=1; + } + + if(!(padbuf & PAD_CROSS)) + wasexh=0; + + if(!(padbuf & PAD_CIRCLE)) + wasexv=0; + + GsSortCls(0, 0, 255); + + for(y = 0; y < 7; y++) + { + for(x = 0; x < 7; x++) + { + tile_sprite.x = x * 32; + tile_sprite.y = y * 32; + tile_sprite.u = ((puzzle_pieces[y][x]-1) % 7) * 32; + tile_sprite.v = ((puzzle_pieces[y][x]-1) / 7) * 32; + GsSortSimpleSprite(&tile_sprite); + + if(x == puzzle_x && y == puzzle_y) + { + tile_rectangle.x = x * 32; + tile_rectangle.y = y * 32; + tile_rectangle.r = 255; + tile_rectangle.g = 0; + tile_rectangle.b = 255; + tile_rectangle.w = 32; + tile_rectangle.h = 32; + tile_rectangle.attribute = ENABLE_TRANS; + GsSortRectangle(&tile_rectangle); + } + } + } + + GsPrintFont(232, 16, "Resolve\nPuzzle\n\n" + "Exchange:\n" + "\nX\nHorizontal\n" + "\nO\nVertical"); + + GsDrawList(); + while(GsIsDrawing()); + + display_is_old = 0; + } + } + + return 0; +} -- cgit v1.2.3