From 3a4a0d3f39c25adb6bc8ead135ed39634b2bcfbf Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 29 Jul 2010 17:50:14 +0100 Subject: Commit of kuni's original sdl/cygwin version --- font.h | 204 +++++++++++++++ license.txt | 19 ++ makefile | 32 +++ piece.c | 278 +++++++++++++++++++++ piece.h | 61 +++++ sintable.h | 131 ++++++++++ spout.c | 819 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1544 insertions(+) create mode 100644 font.h create mode 100644 license.txt create mode 100644 makefile create mode 100644 piece.c create mode 100644 piece.h create mode 100644 sintable.h create mode 100644 spout.c diff --git a/font.h b/font.h new file mode 100644 index 0000000..b2c439d --- /dev/null +++ b/font.h @@ -0,0 +1,204 @@ +const unsigned char FONT6[] = { +// 80, 77, 66, 80, 20, 6, 0, 0, 1, 0, 128, 0, 96, 0, 223, 119, +// 0, 6, 0, 0, + 0, 64, 192, 64, 64, 128, 96, 64, 64, 128, 0, 0, + 0, 0, 0, 0, 0, 64, 192, 224, 96, 32, 96, 64, 128, 64, 160, 64, + 0, 0, 0, 32, 0, 64, 0, 64, 64, 64, 64, 0, 128, 64, 64, 224, + 0, 224, 0, 64, 0, 0, 0, 224, 192, 128, 224, 0, 128, 64, 160, 64, + 0, 0, 0, 128, 0, 64, 0, 64, 64, 32, 224, 0, 64, 128, 0, 0, + 64, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 224, 64, 224, 224, 32, 224, 224, 224, 224, 224, 0, 0, + 32, 0, 128, 192, 160, 192, 32, 32, 96, 128, 128, 32, 160, 160, 64, 64, + 64, 224, 64, 32, 160, 64, 224, 224, 160, 224, 224, 64, 224, 224, 0, 0, + 128, 0, 32, 64, 160, 64, 128, 32, 224, 32, 160, 64, 160, 32, 64, 64, + 64, 224, 64, 0, 224, 64, 224, 224, 32, 224, 224, 64, 224, 224, 0, 64, + 32, 0, 128, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 64, 64, 192, 64, 192, 224, 224, 96, 160, 64, 32, 160, + 128, 224, 192, 64, 160, 160, 160, 160, 160, 128, 128, 128, 160, 64, 32, 160, + 128, 224, 160, 160, 224, 224, 192, 128, 160, 224, 224, 160, 224, 64, 32, 192, + 128, 224, 160, 160, 224, 160, 160, 160, 160, 128, 128, 160, 160, 64, 160, 160, + 128, 160, 160, 160, 64, 160, 192, 64, 192, 224, 128, 96, 160, 64, 224, 160, + 224, 160, 160, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 192, 64, 192, 96, 224, 160, 160, 160, 160, 160, 224, 192, + 160, 192, 64, 0, 160, 160, 160, 128, 64, 160, 160, 160, 160, 160, 32, 128, + 64, 64, 160, 0, 192, 160, 192, 64, 64, 160, 160, 224, 64, 224, 64, 128, + 224, 64, 0, 0, 128, 224, 160, 32, 64, 160, 64, 224, 160, 64, 128, 128, + 224, 64, 0, 0, 128, 96, 160, 192, 64, 64, 64, 224, 160, 64, 224, 192, + 64, 192, 0, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 128, 0, 128, 0, 32, 0, 32, 0, 128, 64, 64, 128, + 64, 0, 0, 0, 64, 0, 128, 0, 32, 0, 64, 0, 128, 0, 0, 128, + 64, 0, 0, 0, 0, 96, 192, 96, 96, 64, 224, 224, 192, 64, 64, 160, + 64, 224, 192, 224, 0, 160, 160, 128, 160, 160, 64, 224, 160, 64, 64, 192, + 64, 224, 160, 160, 0, 96, 192, 96, 96, 192, 64, 32, 160, 64, 64, 160, + 64, 160, 160, 224, 0, 0, 0, 0, 0, 96, 0, 192, 0, 0, 192, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, + 64, 192, 224, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 64, + 64, 64, 0, 0, 192, 96, 224, 96, 224, 160, 160, 160, 160, 160, 224, 128, + 64, 32, 0, 64, 160, 160, 128, 64, 64, 160, 160, 224, 64, 224, 64, 64, + 64, 64, 0, 0, 192, 96, 128, 192, 64, 224, 64, 224, 160, 32, 224, 96, + 64, 192, 0, 0, 128, 32, 0, 0, 0, 0, 0, 0, 0, 192, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; + +const unsigned char FONT16[] = { +// 80, 77, 66, 80, 20, 6, 0, 0, 1, 0, 128, 0, 96, 0, 223, 119, +// 0, 6, 0, 0, + 0, 0, 54, 0, 24, 0, 0, 56, 24, 192, 0, 0, + 0, 0, 0, 0, 0, 24, 54, 102, 60, 115, 56, 56, 48, 96, 0, 0, + 0, 0, 0, 3, 0, 24, 108, 102, 126, 219, 108, 24, 96, 48, 0, 0, + 0, 0, 0, 3, 0, 24, 0, 102, 219, 222, 108, 48, 96, 48, 24, 0, + 0, 0, 0, 6, 0, 24, 0, 102, 219, 222, 108, 0, 192, 24, 219, 24, + 0, 0, 0, 6, 0, 24, 0, 255, 120, 124, 108, 0, 192, 24, 126, 24, + 0, 0, 0, 12, 0, 24, 0, 102, 56, 12, 56, 0, 192, 24, 60, 24, + 0, 0, 0, 12, 0, 24, 0, 102, 28, 24, 48, 0, 192, 24, 24, 255, + 0, 126, 0, 24, 0, 24, 0, 102, 30, 48, 126, 0, 192, 24, 60, 24, + 0, 0, 0, 48, 0, 24, 0, 102, 27, 62, 222, 0, 192, 24, 126, 24, + 0, 0, 0, 48, 0, 0, 0, 255, 219, 123, 204, 0, 192, 24, 219, 24, + 0, 0, 0, 96, 0, 0, 0, 102, 219, 123, 204, 0, 96, 48, 24, 0, + 28, 0, 0, 96, 0, 24, 0, 102, 126, 219, 222, 0, 96, 48, 0, 0, + 28, 0, 28, 192, 0, 24, 0, 102, 60, 206, 115, 0, 48, 96, 0, 0, + 12, 0, 28, 192, 0, 0, 0, 102, 24, 0, 0, 0, 24, 192, 0, 0, + 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 28, 12, 28, 28, 6, 127, 28, 127, 28, 28, 0, 0, + 0, 0, 0, 24, 54, 60, 54, 54, 6, 96, 54, 3, 54, 54, 0, 0, + 3, 0, 96, 60, 99, 12, 99, 99, 14, 96, 99, 3, 99, 99, 0, 0, + 6, 0, 48, 102, 99, 12, 99, 99, 14, 96, 99, 6, 99, 99, 0, 0, + 12, 0, 24, 102, 99, 12, 3, 3, 30, 124, 96, 6, 99, 99, 28, 28, + 24, 126, 12, 6, 99, 12, 6, 6, 30, 118, 124, 12, 54, 99, 28, 28, + 48, 0, 6, 6, 99, 12, 6, 28, 54, 99, 118, 12, 28, 55, 0, 0, + 96, 0, 3, 12, 99, 12, 12, 6, 54, 3, 99, 12, 54, 31, 0, 0, + 48, 0, 6, 24, 99, 12, 24, 3, 102, 3, 99, 24, 99, 3, 0, 0, + 24, 126, 12, 24, 99, 12, 24, 99, 127, 3, 99, 24, 99, 99, 0, 0, + 12, 0, 24, 0, 99, 12, 48, 99, 6, 99, 99, 24, 99, 99, 28, 28, + 6, 0, 48, 0, 54, 12, 96, 54, 6, 54, 54, 24, 54, 54, 28, 28, + 3, 0, 96, 24, 28, 12, 127, 28, 6, 28, 28, 24, 28, 28, 0, 12, + 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 60, 24, 252, 60, 252, 255, 255, 60, 195, 60, 3, 195, + 192, 195, 195, 60, 102, 24, 198, 102, 198, 192, 192, 102, 195, 24, 3, 198, + 192, 195, 227, 102, 195, 60, 195, 195, 195, 192, 192, 195, 195, 24, 3, 198, + 192, 195, 227, 195, 223, 60, 195, 195, 195, 192, 192, 195, 195, 24, 3, 204, + 192, 231, 243, 195, 255, 60, 195, 192, 195, 192, 192, 192, 195, 24, 3, 216, + 192, 231, 243, 195, 255, 60, 198, 192, 195, 192, 192, 192, 195, 24, 3, 216, + 192, 231, 219, 195, 255, 102, 252, 192, 195, 254, 254, 192, 255, 24, 3, 240, + 192, 255, 219, 195, 255, 102, 198, 192, 195, 192, 192, 207, 195, 24, 3, 248, + 192, 255, 207, 195, 255, 102, 195, 192, 195, 192, 192, 195, 195, 24, 3, 204, + 192, 255, 207, 195, 222, 126, 195, 195, 195, 192, 192, 195, 195, 24, 99, 204, + 192, 255, 199, 195, 192, 195, 195, 195, 195, 192, 192, 195, 195, 24, 99, 198, + 192, 219, 199, 195, 99, 195, 198, 102, 198, 192, 192, 103, 195, 24, 54, 195, + 192, 219, 195, 102, 62, 195, 252, 60, 252, 255, 192, 63, 195, 60, 28, 195, + 255, 219, 195, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, + 0, 126, 24, 0, 252, 60, 252, 60, 255, 195, 195, 219, 195, 195, 255, 96, + 195, 6, 60, 0, 198, 102, 198, 102, 24, 195, 195, 219, 195, 195, 3, 96, + 195, 6, 102, 0, 195, 195, 195, 195, 24, 195, 195, 219, 102, 102, 6, 96, + 102, 6, 0, 0, 195, 195, 195, 195, 24, 195, 102, 219, 102, 102, 6, 96, + 102, 6, 0, 0, 195, 195, 195, 192, 24, 195, 102, 219, 60, 60, 12, 96, + 60, 6, 0, 0, 198, 195, 198, 112, 24, 195, 102, 255, 60, 60, 12, 96, + 60, 6, 0, 0, 252, 195, 252, 28, 24, 195, 102, 255, 24, 24, 24, 96, + 126, 6, 0, 0, 192, 195, 204, 6, 24, 195, 60, 255, 60, 24, 48, 96, + 24, 6, 0, 0, 192, 195, 204, 3, 24, 195, 60, 102, 60, 24, 48, 96, + 24, 6, 0, 0, 192, 219, 198, 195, 24, 195, 60, 102, 102, 24, 96, 96, + 126, 6, 0, 0, 192, 207, 198, 195, 24, 195, 24, 102, 102, 24, 96, 96, + 24, 6, 0, 0, 192, 102, 195, 102, 24, 102, 24, 102, 195, 24, 192, 96, + 24, 6, 0, 0, 192, 63, 195, 60, 24, 60, 24, 102, 195, 24, 255, 96, + 24, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 126, + 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 255, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 24, 0, 192, 0, 3, 0, 14, 0, 192, 0, 0, 192, + 24, 0, 0, 0, 12, 0, 192, 0, 3, 0, 24, 0, 192, 24, 24, 192, + 24, 0, 0, 0, 0, 0, 192, 0, 3, 0, 24, 0, 192, 24, 24, 192, + 24, 0, 0, 0, 0, 0, 192, 0, 3, 0, 24, 0, 192, 0, 0, 192, + 24, 0, 0, 0, 0, 0, 192, 0, 3, 0, 24, 0, 192, 0, 0, 192, + 24, 0, 0, 0, 0, 124, 252, 62, 63, 60, 126, 63, 252, 24, 24, 198, + 24, 254, 252, 60, 0, 198, 230, 99, 103, 102, 24, 102, 230, 24, 24, 204, + 24, 219, 230, 102, 0, 6, 195, 192, 195, 195, 24, 102, 195, 24, 24, 216, + 24, 219, 195, 195, 0, 62, 195, 192, 195, 255, 24, 60, 195, 24, 24, 240, + 24, 219, 195, 195, 0, 102, 195, 192, 195, 192, 24, 96, 195, 24, 24, 248, + 24, 219, 195, 195, 0, 198, 195, 192, 195, 192, 24, 126, 195, 24, 24, 204, + 24, 219, 195, 195, 0, 206, 230, 99, 103, 99, 24, 195, 195, 24, 24, 198, + 24, 219, 195, 102, 0, 127, 252, 62, 63, 62, 24, 195, 195, 24, 24, 195, + 24, 219, 195, 60, 0, 0, 0, 0, 0, 0, 0, 126, 0, 0, 112, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, + 24, 60, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24, + 24, 12, 110, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 24, + 24, 12, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 24, + 24, 12, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 24, + 24, 12, 0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 24, + 24, 12, 0, 0, 252, 63, 126, 126, 126, 195, 195, 219, 195, 195, 255, 24, + 24, 12, 0, 0, 230, 103, 112, 195, 24, 195, 195, 219, 102, 195, 6, 48, + 24, 6, 0, 0, 195, 195, 96, 192, 24, 195, 102, 219, 60, 98, 12, 24, + 24, 12, 0, 0, 195, 195, 96, 112, 24, 195, 102, 255, 24, 102, 24, 24, + 24, 12, 0, 0, 195, 195, 96, 30, 24, 195, 60, 255, 24, 52, 48, 24, + 24, 12, 0, 0, 230, 103, 96, 3, 24, 195, 60, 102, 60, 60, 96, 24, + 24, 12, 0, 0, 252, 63, 96, 195, 24, 103, 24, 102, 102, 24, 192, 24, + 24, 12, 0, 0, 192, 3, 96, 126, 14, 63, 24, 102, 195, 48, 255, 24, + 24, 12, 0, 0, 192, 3, 0, 0, 0, 0, 0, 0, 0, 224, 0, 30, + 24, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 24, 0, 0, 0 +}; + diff --git a/license.txt b/license.txt new file mode 100644 index 0000000..83d7981 --- /dev/null +++ b/license.txt @@ -0,0 +1,19 @@ +Copyright (c) 2002-2006 Kuni + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/makefile b/makefile new file mode 100644 index 0000000..4b7cc36 --- /dev/null +++ b/makefile @@ -0,0 +1,32 @@ +# spout +# SDLÍÑmakefile + +.SUFFIXES: .o .c + +SDL_LIB = /usr/local/lib +SDL_INCLUDE = /usr/local/include/SDL + +CC = gcc +CFLAGS = -I$(SDL_INCLUDE) -O2 -mno-cygwin + +LD = gcc +LDFLAGS = -L$(SDL_LIB) -L. -lmingw32 -lSDLmain -lSDL -mwindows + +PRGNAME = spout +OBJS = spout.o piece.o + + +$(PRGNAME).exe: $(OBJS) + $(LD) $(CFLAGS) -o $(PRGNAME).exe $(OBJS) $(RES) $(LDFLAGS) +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +spout.o: piece.h font.h sintable.h +piece.c: piece.h + +clean: + rm -f $(PRGNAME).exe *.o + +run: $(PRGNAME).exe + $(PRGNAME).exe + diff --git a/piece.c b/piece.c new file mode 100644 index 0000000..4ab9057 --- /dev/null +++ b/piece.c @@ -0,0 +1,278 @@ +#include +#include +#include +#include +#include +#include + +#include "SDL.h" +#include "piece.h" +#include "font.h" + +SDL_Surface *video, *layer; +SDL_Rect layerRect; + +unsigned char *vBuffer = NULL; + +void pceLCDDispStop() +{ +} + +void pceLCDDispStart() +{ +} + +void initSDL() { + SDL_PixelFormat *pfrm; + + if(SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); + exit(1); + } + atexit(SDL_Quit); + + video = SDL_SetVideoMode(SDL_WIDTH, SDL_HEIGHT, 8, SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWPALETTE); + if(video == NULL) { + fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); + exit(1); + } + + pfrm = video->format; + layer = SDL_CreateRGBSurface(SDL_SWSURFACE, SDL_WIDTH, SDL_HEIGHT, 8, pfrm->Rmask, pfrm->Gmask, pfrm->Bmask, pfrm->Amask); + if(layer == NULL) { + fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError()); + exit(1); + } + + layerRect.x = 0; + layerRect.y = 0; + layerRect.w = SDL_WIDTH; + layerRect.h = SDL_HEIGHT; + + { + static SDL_Color pltTbl[4] = { + {255, 255, 255}, + {170, 170, 170}, + {85, 85, 85}, + {0, 0, 0} + }; + SDL_SetColors(video, pltTbl, 0, 4); + SDL_SetColors(layer, pltTbl, 0, 4); + } +} + +void pceLCDTrans() { + int x, y; + unsigned char *vbi, *bi; + + bi = layer->pixels; + for(y = 0; y < SDL_HEIGHT; y ++) { + vbi = vBuffer + (y / ZOOM) * 128; + for(x = 0; x < SDL_WIDTH; x ++) { + *bi ++ = *(vbi + x / ZOOM); + } + bi += layer->pitch - SDL_WIDTH; + } + + SDL_BlitSurface(layer, NULL, video, &layerRect); + SDL_Flip(video); +} + +unsigned char *keys; + +int pcePadGet() { + static int pad = 0; + int i = 0, op = pad & 0x00ff; + + int k[] = { + SDLK_UP, SDLK_DOWN, SDLK_LEFT, SDLK_RIGHT, + SDLK_KP8, SDLK_KP2, SDLK_KP4, SDLK_KP6, + SDLK_x, SDLK_z, SDLK_SPACE, SDLK_RETURN, + SDLK_ESCAPE, SDLK_LSHIFT, SDLK_RSHIFT + }; + + int p[] = { + PAD_UP, PAD_DN, PAD_LF, PAD_RI, + PAD_UP, PAD_DN, PAD_LF, PAD_RI, + PAD_A, PAD_B, PAD_A, PAD_B, + PAD_C, PAD_D, PAD_D, + -1 + }; + + pad = 0; + + do { + if(keys[k[i]] == SDL_PRESSED) { + pad |= p[i]; + } + i ++; + } while(p[i] >= 0); + + pad |= (pad & (~op)) << 8; + + return pad; +} + +int interval = 0; + +void pceAppSetProcPeriod(int period) { + interval = period; +} + +int exec = 1; + +void pceAppReqExit(int c) { + exec = 0; +} + +unsigned char *pceLCDSetBuffer(unsigned char *pbuff) +{ + if(pbuff) { + vBuffer = pbuff; + } + return vBuffer; +} + +int font_posX = 0, font_posY = 0, font_width = 4, font_height = 6; +unsigned char font_fgcolor = 3, font_bgcolor = 0, font_bgclear = 0; +const char *font_adr = FONT6; + +void pceFontSetType(int type) +{ + const int width[] = {5, 8, 4}; + const int height[] = {10, 16, 6}; + const char* adr[] ={FONT6, FONT16, FONT6}; + + type &= 3; + font_width = width[type]; + font_height = height[type]; + font_adr = adr[type]; +} + +void pceFontSetTxColor(int color) +{ + font_fgcolor = (unsigned char)color; +} + +void pceFontSetBkColor(int color) +{ + if(color >= 0) { + font_bgcolor = (unsigned char)color; + font_bgclear = 0; + } else { + font_bgclear = 1; + } +} + +void pceFontSetPos(int x, int y) +{ + font_posX = x; + font_posY = y; +} + +int pceFontPrintf(const char *fmt, ...) +{ + unsigned char *adr = vBuffer + font_posX + font_posY * 128; + unsigned char *pC; + char c[1024]; + va_list argp; + + va_start(argp, fmt); + vsprintf(c, fmt, argp); + va_end(argp); + + pC = c; + while(*pC) { + int i, x, y; + const unsigned char *sAdr; + if(*pC >= 0x20 && *pC < 0x80) { + i = *pC - 0x20; + } else { + i = 0; + } + sAdr = font_adr + (i & 15) + (i >> 4) * 16 * 16; + for(y = 0; y < font_height; y ++) { + unsigned char c = *sAdr; + for(x = 0; x < font_width; x ++) { + if(c & 0x80) { + *adr = font_fgcolor; + } else if(font_bgclear == 0) { + *adr = font_bgcolor; + } + adr ++; + c <<= 1; + } + adr += 128 - font_width; + sAdr += 16; + } + adr -= 128 * font_height - font_width; + pC ++; + } +} + +int pceFileOpen(FILEACC *pfa, const char *fname, int mode) +{ + if(mode == FOMD_RD) { + *pfa = open(fname, O_RDONLY | O_BINARY); + } else if(mode == FOMD_WR) { + *pfa = open(fname, O_CREAT | O_RDWR | O_BINARY | O_TRUNC, S_IREAD | S_IWRITE); + } + + if(*pfa >= 0) { + return 0; + } else { + return 1; + } +} + +int pceFileReadSct(FILEACC *pfa, void *ptr, int sct, int len) +{ + return read(*pfa, ptr, len); +} + +int pceFileWriteSct(FILEACC *pfa, const void *ptr, int sct, int len) +{ + return write(*pfa, ptr, len); +} + +int pceFileClose(FILEACC *pfa) +{ + close(*pfa); + return 0; +} + +int main(int argc, char *argv[]) +{ + SDL_Event event; + long nextTick, wait; + int cnt = 0; + + initSDL(); + pceAppInit(); + + SDL_WM_SetCaption("spout", NULL); + + nextTick = SDL_GetTicks() + interval; + while(exec) { + SDL_PollEvent(&event); + keys = SDL_GetKeyState(NULL); + + wait = nextTick - SDL_GetTicks(); + if(wait > 0) { + SDL_Delay(wait); + } + + pceAppProc(cnt); + // SDL_Flip(video); + + nextTick += interval; + cnt ++; + + if((keys[SDLK_ESCAPE] == SDL_PRESSED && (keys[SDLK_LSHIFT] == SDL_PRESSED || keys[SDLK_RSHIFT] == SDL_PRESSED)) || event.type == SDL_QUIT) { + exec = 0; + } + } + + pceAppExit(); +} + diff --git a/piece.h b/piece.h new file mode 100644 index 0000000..383e1fb --- /dev/null +++ b/piece.h @@ -0,0 +1,61 @@ +#include "SDL.h" + +#define ZOOM 2 +#define SDL_WIDTH (128 * ZOOM) +#define SDL_HEIGHT (88 * ZOOM) + +#define PAD_RI 0x01 +#define PAD_LF 0x02 +#define PAD_DN 0x04 +#define PAD_UP 0x08 +#define PAD_B 0x10 +#define PAD_A 0x20 +#define PAD_D 0x40 +#define PAD_C 0x80 + +#define TRG_RI 0x0100 +#define TRG_LF 0x0200 +#define TRG_DN 0x0400 +#define TRG_UP 0x0800 +#define TRG_B 0x1000 +#define TRG_A 0x2000 +#define TRG_D 0x4000 +#define TRG_C 0x8000 + +#define pcesprintf sprintf + +#define CPU_SPEED_NORMAL 0 +#define pceCPUSetSpeed + +#define FILEACC int +#define FOMD_RD 0 +#define FOMD_WR 1 +#define pceFileCreate + +#define pceTimerGetCount SDL_GetTicks + +#define PP_MODE_SINGLE 0 +#define PP_MODE_REPEAT 1 +#define pcePadSetTrigMode + +int pceFontPrintf(const char *fmt, ... ); +void pceFontSetTxColor(int color); +void pceFontSetBkColor(int color); +void pceFontSetPos(int x, int y); +void pceFontSetType(int type); + +void pceLCDDispStop(); +void pceLCDDispStart(); +unsigned char *pceLCDSetBuffer(unsigned char *pbuff); +void pceLCDTrans(); + +void pceAppSetProcPeriod(int period); +void pceAppReqExit(int c); + +int pceFileOpen(FILEACC *pfa, const char *fname, int mode); +int pceFileReadSct(FILEACC *pfa, void *ptr, int sct, int len); +int pceFileWriteSct(FILEACC *pfa, const void *ptr, int sct, int len); +int pceFileClose(FILEACC *pfa); + +int pcePadGet(); + diff --git a/sintable.h b/sintable.h new file mode 100644 index 0000000..243b141 --- /dev/null +++ b/sintable.h @@ -0,0 +1,131 @@ +short sintable[1024]={ + 0, 25, 50, 75, 101, 126, 151, 176, + 201, 226, 251, 276, 301, 326, 351, 376, + 401, 426, 451, 476, 501, 526, 551, 576, + 601, 626, 651, 675, 700, 725, 750, 774, + 799, 824, 848, 873, 897, 922, 946, 971, + 995, 1020, 1044, 1068, 1092, 1117, 1141, 1165, + 1189, 1213, 1237, 1261, 1285, 1309, 1332, 1356, + 1380, 1404, 1427, 1451, 1474, 1498, 1521, 1544, + 1567, 1591, 1614, 1637, 1660, 1683, 1706, 1729, + 1751, 1774, 1797, 1819, 1842, 1864, 1886, 1909, + 1931, 1953, 1975, 1997, 2019, 2041, 2062, 2084, + 2106, 2127, 2149, 2170, 2191, 2213, 2234, 2255, + 2276, 2296, 2317, 2338, 2359, 2379, 2399, 2420, + 2440, 2460, 2480, 2500, 2520, 2540, 2559, 2579, + 2598, 2618, 2637, 2656, 2675, 2694, 2713, 2732, + 2751, 2769, 2788, 2806, 2824, 2843, 2861, 2878, + 2896, 2914, 2932, 2949, 2967, 2984, 3001, 3018, + 3035, 3052, 3068, 3085, 3102, 3118, 3134, 3150, + 3166, 3182, 3198, 3214, 3229, 3244, 3260, 3275, + 3290, 3305, 3320, 3334, 3349, 3363, 3378, 3392, + 3406, 3420, 3433, 3447, 3461, 3474, 3487, 3500, + 3513, 3526, 3539, 3551, 3564, 3576, 3588, 3600, + 3612, 3624, 3636, 3647, 3659, 3670, 3681, 3692, + 3703, 3713, 3724, 3734, 3745, 3755, 3765, 3775, + 3784, 3794, 3803, 3812, 3822, 3831, 3839, 3848, + 3857, 3865, 3873, 3881, 3889, 3897, 3905, 3912, + 3920, 3927, 3934, 3941, 3948, 3954, 3961, 3967, + 3973, 3979, 3985, 3991, 3996, 4002, 4007, 4012, + 4017, 4022, 4027, 4031, 4036, 4040, 4044, 4048, + 4052, 4055, 4059, 4062, 4065, 4068, 4071, 4074, + 4076, 4079, 4081, 4083, 4085, 4087, 4088, 4090, + 4091, 4092, 4093, 4094, 4095, 4095, 4096, 4096, + 4096, 4096, 4096, 4095, 4095, 4094, 4093, 4092, + 4091, 4090, 4088, 4087, 4085, 4083, 4081, 4079, + 4076, 4074, 4071, 4068, 4065, 4062, 4059, 4055, + 4052, 4048, 4044, 4040, 4036, 4031, 4027, 4022, + 4017, 4012, 4007, 4002, 3996, 3991, 3985, 3979, + 3973, 3967, 3961, 3954, 3948, 3941, 3934, 3927, + 3920, 3912, 3905, 3897, 3889, 3881, 3873, 3865, + 3857, 3848, 3839, 3831, 3822, 3812, 3803, 3794, + 3784, 3775, 3765, 3755, 3745, 3734, 3724, 3713, + 3703, 3692, 3681, 3670, 3659, 3647, 3636, 3624, + 3612, 3600, 3588, 3576, 3564, 3551, 3539, 3526, + 3513, 3500, 3487, 3474, 3461, 3447, 3433, 3420, + 3406, 3392, 3378, 3363, 3349, 3334, 3320, 3305, + 3290, 3275, 3260, 3244, 3229, 3214, 3198, 3182, + 3166, 3150, 3134, 3118, 3102, 3085, 3068, 3052, + 3035, 3018, 3001, 2984, 2967, 2949, 2932, 2914, + 2896, 2878, 2861, 2843, 2824, 2806, 2788, 2769, + 2751, 2732, 2713, 2694, 2675, 2656, 2637, 2618, + 2598, 2579, 2559, 2540, 2520, 2500, 2480, 2460, + 2440, 2420, 2399, 2379, 2359, 2338, 2317, 2296, + 2276, 2255, 2234, 2213, 2191, 2170, 2149, 2127, + 2106, 2084, 2062, 2041, 2019, 1997, 1975, 1953, + 1931, 1909, 1886, 1864, 1842, 1819, 1797, 1774, + 1751, 1729, 1706, 1683, 1660, 1637, 1614, 1591, + 1567, 1544, 1521, 1498, 1474, 1451, 1427, 1404, + 1380, 1356, 1332, 1309, 1285, 1261, 1237, 1213, + 1189, 1165, 1141, 1117, 1092, 1068, 1044, 1020, + 995, 971, 946, 922, 897, 873, 848, 824, + 799, 774, 750, 725, 700, 675, 651, 626, + 601, 576, 551, 526, 501, 476, 451, 426, + 401, 376, 351, 326, 301, 276, 251, 226, + 201, 176, 151, 126, 101, 75, 50, 25, + 0, -24, -49, -74, -100, -125, -150, -175, + -200, -225, -250, -275, -300, -325, -350, -375, + -400, -425, -450, -475, -500, -525, -550, -575, + -600, -625, -650, -674, -699, -724, -749, -773, + -798, -823, -847, -872, -896, -921, -945, -970, + -994, -1019, -1043, -1067, -1091, -1116, -1140, -1164, + -1188, -1212, -1236, -1260, -1284, -1308, -1331, -1355, + -1379, -1403, -1426, -1450, -1473, -1497, -1520, -1543, + -1566, -1590, -1613, -1636, -1659, -1682, -1705, -1728, + -1750, -1773, -1796, -1818, -1841, -1863, -1885, -1908, + -1930, -1952, -1974, -1996, -2018, -2040, -2061, -2083, + -2105, -2126, -2148, -2169, -2190, -2212, -2233, -2254, + -2275, -2295, -2316, -2337, -2358, -2378, -2398, -2419, + -2439, -2459, -2479, -2499, -2519, -2539, -2558, -2578, + -2597, -2617, -2636, -2655, -2674, -2693, -2712, -2731, + -2750, -2768, -2787, -2805, -2823, -2842, -2860, -2877, + -2895, -2913, -2931, -2948, -2966, -2983, -3000, -3017, + -3034, -3051, -3067, -3084, -3101, -3117, -3133, -3149, + -3165, -3181, -3197, -3213, -3228, -3243, -3259, -3274, + -3289, -3304, -3319, -3333, -3348, -3362, -3377, -3391, + -3405, -3419, -3432, -3446, -3460, -3473, -3486, -3499, + -3512, -3525, -3538, -3550, -3563, -3575, -3587, -3599, + -3611, -3623, -3635, -3646, -3658, -3669, -3680, -3691, + -3702, -3712, -3723, -3733, -3744, -3754, -3764, -3774, + -3783, -3793, -3802, -3811, -3821, -3830, -3838, -3847, + -3856, -3864, -3872, -3880, -3888, -3896, -3904, -3911, + -3919, -3926, -3933, -3940, -3947, -3953, -3960, -3966, + -3972, -3978, -3984, -3990, -3995, -4001, -4006, -4011, + -4016, -4021, -4026, -4030, -4035, -4039, -4043, -4047, + -4051, -4054, -4058, -4061, -4064, -4067, -4070, -4073, + -4075, -4078, -4080, -4082, -4084, -4086, -4087, -4089, + -4090, -4091, -4092, -4093, -4094, -4094, -4095, -4095, + -4095, -4095, -4095, -4094, -4094, -4093, -4092, -4091, + -4090, -4089, -4087, -4086, -4084, -4082, -4080, -4078, + -4075, -4073, -4070, -4067, -4064, -4061, -4058, -4054, + -4051, -4047, -4043, -4039, -4035, -4030, -4026, -4021, + -4016, -4011, -4006, -4001, -3995, -3990, -3984, -3978, + -3972, -3966, -3960, -3953, -3947, -3940, -3933, -3926, + -3919, -3911, -3904, -3896, -3888, -3880, -3872, -3864, + -3856, -3847, -3838, -3830, -3821, -3811, -3802, -3793, + -3783, -3774, -3764, -3754, -3744, -3733, -3723, -3712, + -3702, -3691, -3680, -3669, -3658, -3646, -3635, -3623, + -3611, -3599, -3587, -3575, -3563, -3550, -3538, -3525, + -3512, -3499, -3486, -3473, -3460, -3446, -3432, -3419, + -3405, -3391, -3377, -3362, -3348, -3333, -3319, -3304, + -3289, -3274, -3259, -3243, -3228, -3213, -3197, -3181, + -3165, -3149, -3133, -3117, -3101, -3084, -3067, -3051, + -3034, -3017, -3000, -2983, -2966, -2948, -2931, -2913, + -2895, -2877, -2860, -2842, -2823, -2805, -2787, -2768, + -2750, -2731, -2712, -2693, -2674, -2655, -2636, -2617, + -2597, -2578, -2558, -2539, -2519, -2499, -2479, -2459, + -2439, -2419, -2398, -2378, -2358, -2337, -2316, -2295, + -2275, -2254, -2233, -2212, -2190, -2169, -2148, -2126, + -2105, -2083, -2061, -2040, -2018, -1996, -1974, -1952, + -1930, -1908, -1885, -1863, -1841, -1818, -1796, -1773, + -1750, -1728, -1705, -1682, -1659, -1636, -1613, -1590, + -1566, -1543, -1520, -1497, -1473, -1450, -1426, -1403, + -1379, -1355, -1331, -1308, -1284, -1260, -1236, -1212, + -1188, -1164, -1140, -1116, -1091, -1067, -1043, -1019, + -994, -970, -945, -921, -896, -872, -847, -823, + -798, -773, -749, -724, -699, -674, -650, -625, + -600, -575, -550, -525, -500, -475, -450, -425, + -400, -375, -350, -325, -300, -275, -250, -225, + -200, -175, -150, -125, -100, -74, -49, -24 +}; + diff --git a/spout.c b/spout.c new file mode 100644 index 0000000..cd04f38 --- /dev/null +++ b/spout.c @@ -0,0 +1,819 @@ +#include +#include +#include + +#include "piece.h" + +#include "sintable.h" + +#define FRAMERATE 50 +#define MAX_GRAIN 500 + +const unsigned char MATSUMI[] = { +// 80, 77, 66, 80, 180, 0, 0, 0, 1, 0, 128, 0, 10, 0, 223, 119, +// 160, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 34, 56, 68, 10, 4, + 80, 129, 202, 0, 0, 0, 0, 0, 8, 0, 8, 34, 73, 255, 127, 223, + 241, 241, 95, 0, 0, 0, 0, 0, 8, 0, 0, 71, 72, 254, 10, 5, + 67, 17, 68, 0, 1, 2, 59, 187, 137, 75, 136, 66, 164, 16, 81, 31, + 84, 225, 155, 0, 2, 25, 10, 168, 138, 74, 72, 135, 33, 255, 49, 5, + 97, 177, 78, 0, 2, 33, 58, 171, 142, 74, 72, 134, 32, 16, 23, 215, + 86, 77, 117, 0, 2, 33, 34, 170, 9, 74, 73, 2, 73, 255, 49, 21, + 176, 33, 78, 0, 1, 26, 59, 187, 137, 50, 73, 2, 76, 40, 81, 28, + 0, 193, 181, 0, 0, 0, 0, 0, 0, 0, 0, 2, 245, 199, 23, 211, + 240, 33, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; + +typedef struct { + short x, y; +} SVECTOR; + +typedef struct { + long x, y; +} VECTOR; + +typedef struct tagGRAIN { + struct tagGRAIN *next; + struct tagGRAIN *prev; + + SVECTOR s, v; + short pos; + unsigned char color; +} GRAIN; + +GRAIN *grainUseLink, *grainFreeLink; + +unsigned char vbuff[128 * 88]; +unsigned char vbuff2[128 * 128]; + +GRAIN grain[MAX_GRAIN]; +GRAIN *v2g[128 * 128]; + +SVECTOR box; + +VECTOR mPos, mSpeed; +int mR; + +int nGrain; + +int time = FRAMERATE * 60, score = 0, height = 0, dispscore = 0; +int hiScore[2] = {0, 0}; +int dispPos, upperLine, rollCount; + +void spout(int t, int x, int y); +void sweep(unsigned char c1, unsigned char c2); +void initGrain(void); +GRAIN *allocGrain(void); +GRAIN *freeGrain(GRAIN *current); + +void pceAppInit(void) +{ + pceLCDDispStop(); + pceLCDSetBuffer(vbuff); + pceAppSetProcPeriod(1000 / FRAMERATE); + + memset(vbuff, 0, 128 * 88); + + pceLCDDispStart(); + + pceCPUSetSpeed(CPU_SPEED_NORMAL); + + { + FILEACC fa; + if(!pceFileOpen(&fa, "spout.sco", FOMD_RD)) { + pceFileReadSct(&fa, (void *)hiScore, 0, 8); + pceFileClose(&fa); + } + } + + pcePadSetTrigMode(PP_MODE_SINGLE); + + srand(pceTimerGetCount()); +} + +void pceAppProc(int cnt) +{ + static int gamePhase = 0, gameover; + + int pad = pcePadGet(); + + if( (pad & (PAD_C | TRG_D)) == (PAD_C | TRG_D) || + (pad & (TRG_C | PAD_D)) == (TRG_C | PAD_D)) { + if(gamePhase >= 2) { + gamePhase = 0; + } else { + pceAppReqExit(0); + } + pad = 0; + } + + if(gamePhase == 4) { + if(pad & (TRG_C)) { + gamePhase = 3; + } + return; + } + + if(!(gamePhase & 1)) { + if(gamePhase == 0) { + if(score > hiScore[0] || (score == hiScore[0] && height > hiScore[1])) { + FILEACC fa; + hiScore[0] = score; + hiScore[1] = height; + if(!pceFileOpen(&fa, "spout.sco", FOMD_WR)) { + pceFileWriteSct(&fa, (void *)hiScore, 0, 8); + } else if(!pceFileCreate("spout.sco", 8)) { + if(!pceFileOpen(&fa, "spout.sco", FOMD_WR)) { + pceFileWriteSct(&fa, (void *)hiScore, 0, 8); + } + } + pceFileClose(&fa); + } + } else { + score = 0; + dispscore = 0; + height = - 58; + time = 60 * FRAMERATE; + } + + { + int i; + for(i = 0; i < 128 * 128; i ++) { + v2g[i] = NULL; + } + initGrain(); + nGrain = 0; + } + + if(gamePhase & 2) { + memset(vbuff2, 0xd2, 128 * 128); + memset(vbuff2 + 128 * 0, 0, 128 * 78); + memset(vbuff2 + 128 * (128 - 32), 0, 128 * 32); + } else { + memset(vbuff2, 0, 128 * 128); + } + + memset(vbuff, 0, 128 * 88); + + { + int i; + unsigned char *pC; + + pC = vbuff2; + for(i = 0; i < 128; i ++) { + *pC++ = 0x0b; + *pC++ = 0x0b; + *pC++ = 0x0b; + *pC++ = 0x0b; + pC += 128 - 8; + *pC++ = 0x0b; + *pC++ = 0x0b; + *pC++ = 0x0b; + *pC++ = 0x0b; + } + } + + mPos.x = 40 * 256; + mPos.y = 0 * 256; + mSpeed.x = 0; + mSpeed.y = 0; + mR = 256 + (gamePhase & 2) * 224; + + dispPos = 0; + upperLine = 0; + gameover = 0; + rollCount = 0; + gamePhase ++; + + memset(vbuff + 128, 0x03, 128); + pceFontSetType(2 + 128); + pceFontSetPos(0, 82); + if(height > 0) { + pceFontPrintf("time:%2d height:%4d score:%6d", (time + FRAMERATE - 1) / FRAMERATE, height % 10000, score % 1000000); + } else { + pceFontPrintf("time:%2d height: 0 score:%6d", (time + FRAMERATE - 1) / FRAMERATE, score % 1000000); + } + pceFontSetType(0); + } + + if((pad & TRG_C) && gamePhase == 3 && gameover == 0) { + pceFontSetType(2 + 128); + pceFontSetPos(64 - 7 * 4 / 2, 33); + pceFontPrintf(" pause "); + pceFontSetType(0); + + gamePhase = 4; + + pceLCDTrans(); + return; + } + + if(gamePhase & 2) { + if(gameover == 0) { + if((pad & PAD_RI)) { + mR = (mR - 16) & 1023; + } else if((pad & PAD_LF)) { + mR = (mR + 16) & 1023; + } + if((pad & (PAD_A | PAD_B))) { + mSpeed.x -= sintable[(256 + mR) & 1023] / 128; + mSpeed.y += sintable[mR] / 128; + } + mSpeed.y += 8; + + if(mSpeed.x < -256 * 4) { + mSpeed.x = -256 * 4; + } else if(mSpeed.x > 256 * 4) { + mSpeed.x = 256 * 4; + } + if(mSpeed.y < -256 * 4) { + mSpeed.y = -256 * 4; + } else if(mSpeed.y > 256 * 4) { + mSpeed.y = 256 * 4; + } + + mPos.x += mSpeed.x / 16; + mPos.y += mSpeed.y / 16; + + if(mPos.x >= 125 * 256) { + mPos.x = 124 * 256; + gameover = 1; + } else if(mPos.x <= 2 * 256) { + mPos.x = 3 * 256; + gameover = 1; + } + if(mPos.y >= 78 * 256) { + mPos.y = 77 * 256; + gameover = 1; + } + + if(mPos.y < 40 * 256) { + unsigned char *pC; + int i, j, w, x1 , x2; + mPos.y += 256; + upperLine = (upperLine - 1) & 127; + height ++; + + if(height > 0) { + score ++; + if((height & 127) == 0) { + score += (time + FRAMERATE - 1) / FRAMERATE * 10; + time += 60 * FRAMERATE; + if(time > 99 * FRAMERATE) { + time = 99 * FRAMERATE; + } + pceFontSetType(2 + 128); + pceFontSetPos(4 * 5, 82); + pceFontPrintf("%2d", (time + FRAMERATE - 1) / FRAMERATE); + pceFontSetType(0); + } + pceFontSetType(2 + 128); + pceFontSetPos(4 * 15, 82); + pceFontPrintf("%4d", height % 10000); + pceFontSetType(0); + } + + if(upperLine == 111 && height > 0) { + unsigned long *pL; + pL = (unsigned long *)(vbuff2 + 128 * 108 + 4); + while(pL < (unsigned long *)(vbuff2 + 128 * 109 - 4)) { + *pL++ = 0; + } + pL += 2; + while(pL < (unsigned long *)(vbuff2 + 128 * 110 - 4)) { + *pL++ = 0xd3d3d3d3; + } + pL += 2; + while(pL < (unsigned long *)(vbuff2 + 128 * 111 - 4)) { + *pL++ = 0; + } + } + + box.x = 20 - (height + 40) / 64; + if(box.x < 4) { + box.x = 4; + } + box.y = 20 - (height + 40) / 64; + if(box.y < 4) { + box.y = 4; + } + + for(j = 0; j < 1; j ++) { + int x, y; + x = 4 + (rand() % box.x); + y = 4 + (rand() % box.y); + pC = vbuff2 + ((upperLine - 20 - (rand() & 7)) & 127) * 128; + x1 = 4 + (rand() % (120 - x)); + x2 = x; + i = y; + while(i > 0) { + if(pC < vbuff2) { + pC += 128 * 128; + } + pC += x1; + w = x2; + while(w > 0) { + *pC++ = 0; + w --; + } + pC -= x1 + x2 + 128; + i --; + } + } + + sweep(0x13, 0xd2); + } + } + } else { + mPos.x = 7 * 256; + mPos.y = 60 * 256; + mR = 0; + + if((rollCount & 7) == 0) { + int i, j; + + if((upperLine & 31) == 0) { + unsigned long *pL; + pceLCDSetBuffer(vbuff2 + ((upperLine - 24) & 127) * 128); + pceFontSetBkColor(0); + + switch(upperLine / 32) { + case 0: + pL = (unsigned long *)(vbuff2 + 12 + ((upperLine - 24) & 127) * 128); + for(i = 0; i < 16; i ++) { + for(j = 0; j < 26 / 2; j ++) { + *pL = 0x91919191; + pL += 2; + } + if((i & 7) == 3) { + pL += 7; + } else if((i & 7) == 7) { + pL += 5; + } else { + pL += 6; + } + } + + pceFontSetTxColor(0x03); + pceFontSetType(1 + 128); + pceFontSetPos(64 - 4 * 5, 0); + pceFontPrintf("spout"); + break; + + case 2: + pceFontSetTxColor(0xc3); + pceFontSetType(2 + 128); + pceFontSetPos(118 - 20 * 4, 0); + pceFontPrintf(" height: %8d", hiScore[1] % 1000000); + pceFontSetPos(118 - 20 * 4, 6); + pceFontPrintf("high-score: %8d", hiScore[0] % 1000000); + break; + + case 1: + { + const unsigned char *pS = MATSUMI; + unsigned char *pD = vbuff2 + ((upperLine - 16) & 127) * 128; + for(i = 0; i < 128 / 8 * 10; i ++) { + unsigned char t = *pS++; + for(j = 0; j < 8; j ++) { + if(t & 0x80) { + *pD = 0xc3; + } + pD ++; + t <<= 1; + } + } + } + break; + } + + pceFontSetType(0); + pceFontSetTxColor(0x03); + pceFontSetBkColor(0); + + pceLCDSetBuffer(vbuff); + } + upperLine = (upperLine - 1) & 127; + + sweep(0x13, 0x00); + } + } + + rollCount ++; + + { + static int gx[] = {-2, 2, -1, 1, 0}; + int r, t; + + r = rand() & 3; + t = gx[r]; gx[r] = gx[r + 1]; gx[r + 1] = t; + if(gamePhase & 2) { + if(gameover == 0 && (pad & (PAD_A | PAD_B))) { + int i, t, x, y; + for(i = 0; i < 5; i ++) { + t = mPos.x / 256 + gx[i] + ((mPos.y / 256 - 1 + abs(gx[i]) + dispPos) & 127) * 128; + x = mSpeed.x / 16 + sintable[(256 + mR) & 1023] / 8; + y = mSpeed.y / 16 - sintable[mR] / 8; + spout(t, x, y); + } + } + } else { + int i, t; + for(i = -1; i <= 2; i ++) { + t = 7 + i + ((60 - 1 + dispPos) & 127) * 128; + spout(t, 512, -384); + } + } + } + + { + GRAIN *pG, *pG2; + SVECTOR svt; + + pG = grainUseLink; + while(pG) { + int f = 0; + unsigned char *c; + + pG->v.y += 8; + + pG->s.x += pG->v.x; + pG->s.y += pG->v.y; + + *(vbuff2 + pG->pos) = 0; + *(v2g + pG->pos) = NULL; + + if(pG->s.y >= 256) { + do { + pG->s.y -= 256; + pG->pos = (pG->pos + 128) & 16383; + c = (vbuff2 + pG->pos); + + if(*c) { + if(*c & 0x04) { + int r; + pG2 = *(v2g + pG->pos); + r = 31 - (rand() & 63); + svt = pG->v; + pG->v = pG2->v; + pG2->v = svt; + pG->v.x += r; + pG2->v.x -= r; + } else { + pG->v.y = -pG->v.y / 2; + pG->v.x += 15 - (rand() & 31); + if(*c & 0xc0) { + *c -= 0x40; + if(!(*c & 0xc0)) { + *c = 0; + } + } + if(pG->color & 0xc0) { + pG->color -= 0x40; + } else { + pG->color = 0; + f = 1; + } + } + pG->pos = (pG->pos - 128) & 16383; + break; + } + } while(pG->s.y >= 256); + } else { + while(pG->s.y <= -256) { + pG->s.y += 256; + pG->pos = (pG->pos - 128) & 16383; + c = (vbuff2 + pG->pos); + + if(*c) { + if(*c & 4) { + pG2 = *(v2g + pG->pos); + svt = pG->v; + pG->v = pG2->v; + pG2->v = svt; + } else { + pG->v.y = -pG->v.y / 2; + if(*c & 0xc0) { + *c -= 0x40; + if(!(*c & 0xc0)) { + *c = 0; + } + } + if(pG->color & 0xc0) { + pG->color -= 0x40; + } else { + pG->color = 0; + f = 1; + } + } + pG->pos = (pG->pos + 128) & 16383; + break; + } + } + } + + if(pG->s.x >= 256) { + do { + pG->s.x -= 256; + pG->pos = (pG->pos + 1) & 16383; + c = (vbuff2 + pG->pos); + + if(*c) { + if(*c & 4) { + pG2 = *(v2g + pG->pos); + svt = pG->v; + pG->v = pG2->v; + pG2->v = svt; + } else { + pG->v.x = -pG->v.x / 2; + if(*c & 0xc0) { + *c -= 0x40; + if(!(*c & 0xc0)) { + *c = 0; + } + } + if(pG->color & 0xc0) { + pG->color -= 0x40; + } else { + pG->color = 0; + f = 1; + } + } + pG->pos = (pG->pos - 1) & 16383; + break; + } + } while(pG->s.x >= 256); + } else { + while(pG->s.x <= -256) { + pG->s.x += 256; + pG->pos = (pG->pos - 1) & 16383; + c = (vbuff2 + pG->pos); + + if(*c) { + if(*c & 4) { + pG2 = *(v2g + pG->pos); + svt = pG->v; + pG->v = pG2->v; + pG2->v = svt; + } else { + pG->v.x = -pG->v.x / 2; + if(*c & 0xc0) { + *c -= 0x40; + if(!(*c & 0xc0)) { + *c = 0; + } + } + if(pG->color & 0xc0) { + pG->color -= 0x40; + } else { + pG->color = 0; + f = 1; + } + } + pG->pos = (pG->pos + 1) & 16383; + break; + } + } + } + + if(f) { + *(vbuff2 + pG->pos) = pG->color; + nGrain --; + *(v2g + pG->pos) = NULL; + pG = freeGrain(pG); + } else { + *(vbuff2 + pG->pos) = pG->color; + *(v2g + pG->pos) = pG; + pG = pG->next; + } + } + } + + dispPos = upperLine; + + { + unsigned long *pL, *pL2, *pLe; + pL = (unsigned long *)(vbuff + 2 * 128); + pL2 = (unsigned long *)(vbuff2 + dispPos * 128); + + pLe = pL2 + 128 * 78 / 4; + if(pLe > (unsigned long *)(vbuff2 + 128 * 128)) { + pLe = (unsigned long *)(vbuff2 + 128 * 128); + } + + while(pL2 < pLe) { + *pL = *pL2 & 0x03030303; + pL ++; + pL2 ++; + } + + pL2 = (unsigned long *)(vbuff2); + while(pL < (unsigned long *)(vbuff + 128 * (78 + 2))) { + *pL = *pL2 & 0x03030303; + pL ++; + pL2 ++; + } + } + + { + unsigned char *pC; + pC = vbuff2 + mPos.x / 256 + ((mPos.y / 256 + dispPos) & 127) * 128; + if(*pC != 0 && (*pC & 4) == 0) { + gameover = *pC; + } + } + + { + static int gPhase = 0; + unsigned char *pC; + int i, x, y; + if(gameover == 0 && (gamePhase & 2)) { + x = mPos.x + sintable[(256 + mR) & 1023] * gPhase / 64; + y = mPos.y - sintable[mR] * gPhase / 64; + for(i = 0; i < 3; i ++) { + if(y >= 78 * 256) { + break; + } + *(vbuff + x / 256 + (y / 256 + 2) * 128) = 3; + x += sintable[(256 + mR) & 1023] / 16; + y -= sintable[mR] / 16; + + if(y >= 78 * 256) { + break; + } + *(vbuff + x / 256 + (y / 256 + 2) * 128) = 3; + x += sintable[(256 + mR) & 1023] / 16; + y -= sintable[mR] / 16; + + if(y >= 78 * 256) { + break; + } + *(vbuff + x / 256 + (y / 256 + 2) * 128) = 3; + x += sintable[(256 + mR) & 1023] * 2 / 16; + y -= sintable[mR] * 2 / 16; + } + gPhase = (gPhase + 1) & 15; + } + + pC = vbuff + mPos.x / 256 + (mPos.y / 256 + 2) * 128; + *(pC - 129) = 0x03; + *(pC - 128) = 0x03; + *(pC - 127) = 0x03; + *(pC - 1) = 0x03; + *pC = 0x00; + *(pC + 1) = 0x03; + *(pC + 127) = 0x03; + *(pC + 128) = 0x03; + *(pC + 129) = 0x03; + } + + if(gamePhase == 1) { + if(pad & (TRG_A | TRG_B)) { + gamePhase = 2; + } + } else if(gameover) { + if(pad & (TRG_A | TRG_B)) { + gamePhase = 0; + } + } + + if((gamePhase & 2) && time && gameover == 0) { + time --; + if((time % FRAMERATE) == 0) { + pceFontSetType(2 + 128); + pceFontSetPos(4 * 5, 82); + pceFontPrintf("%2d", (time + FRAMERATE - 1) / FRAMERATE); + pceFontSetType(0); + } + if(time == 0) { + gameover = 1; + } + } + + if(dispscore < score) { + dispscore ++; + if(dispscore < score) { + dispscore ++; + } + pceFontSetType(2 + 128); + pceFontSetPos(4 * 26, 82); + pceFontPrintf("%6d", dispscore % 1000000); + pceFontSetType(0); + } + + if(gamePhase == 3 && gameover != 0) { + pceFontSetType(2 + 128); + pceFontSetPos(64 - 11 * 4 / 2, 33); + pceFontPrintf(" game over "); + pceFontSetType(0); + } + + pceLCDTrans(); +} + + +void pceAppExit( void ) +{ + pceCPUSetSpeed(CPU_SPEED_NORMAL); +} + +void spout(int t, int x, int y) +{ + if(*(vbuff2 + t) == 0) { + if(nGrain < MAX_GRAIN) { + GRAIN *pG = allocGrain(); + + pG->v.x = x; + pG->v.y = y; + pG->s.x = 0; + pG->s.y = 0; + + pG->color = (2 + (rand() & 1)) + 4 + 64 * 3; + + pG->pos = t; + *(vbuff2 + t) = pG->color; + v2g[t] = pG; + nGrain ++; + } + } +} + +void sweep(unsigned char c1, unsigned char c2) +{ + int i; + + unsigned char *pC = vbuff2 + 4 + 128 * ((upperLine + 77) & 127); + for(i = 0; i < 120; i ++) { + if(*pC & 4) { + GRAIN **ppG; + ppG = v2g + (int)(pC - vbuff2); + freeGrain(*ppG); + *ppG = NULL; + nGrain --; + } + *pC++ = c1; + } + + pC += 8; + if(pC >= vbuff2 + 128 * 128) { + pC -= 128 * 128; + } + + for(i = 0; i < 120; i ++) { + *pC++ = c2; + } +} + +void initGrain(void) +{ + int i; + + for(i = 0; i < MAX_GRAIN - 1; i ++) { + grain[i].next = &grain[i + 1]; + } + grain[i].next = NULL; + + grainFreeLink = grain; + grainUseLink = NULL; + + return; +} + +GRAIN *allocGrain(void) +{ + GRAIN *current = grainFreeLink; + + if(current) { + grainFreeLink = current->next; + + current->next = grainUseLink; + current->prev = NULL; + if(current->next) { + current->next->prev = current; + } + grainUseLink = current; + } + + return current; +} + +GRAIN *freeGrain(GRAIN *current) +{ + GRAIN *next = current->next; + + if(next) { + next->prev = current->prev; + } + if(current->prev) { + current->prev->next = next; + } else { + grainUseLink = next; + } + + current->next = grainFreeLink; + grainFreeLink = current; + + return next; +} + -- cgit v1.2.3