+#include "board.h"
+
+static const char shapes[7][4][4][4] = {
+ { { {0x00, 0x00, 0x00, 0x00}, {0x47, 0xC7, 0x97, 0x00},
+ {0x00, 0x00, 0x27, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp horizontal
+ { {0x00, 0x17, 0x00, 0x00}, {0x00, 0x37, 0x00, 0x00},
+ {0x47, 0xA7, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt vertical J
+ { {0x17, 0x00, 0x00, 0x00}, {0x67, 0xC7, 0x87, 0x00},
+ {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt horizontal
+ { {0x00, 0x57, 0x87, 0x00}, {0x00, 0x37, 0x00, 0x00},
+ {0x00, 0x27, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //J (yellow)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x53, 0xC3, 0x83, 0x00},
+ {0x23, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp horizontal
+ { {0x43, 0x93, 0x00, 0x00}, {0x00, 0x33, 0x00, 0x00},
+ {0x00, 0x23, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //sharp vertical
+ { {0x00, 0x00, 0x13, 0x00}, {0x43, 0xC3, 0xA3, 0x00},
+ {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //blunt horizontal
+ { {0x00, 0x13, 0x00, 0x00}, {0x00, 0x33, 0x00, 0x00},
+ {0x00, 0x63, 0x83, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //L (cyan)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x48, 0xD8, 0x88, 0x00},
+ {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing down
+ { {0x00, 0x18, 0x00, 0x00}, {0x48, 0xB8, 0x00, 0x00},
+ {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing left
+ { {0x00, 0x18, 0x00, 0x00}, {0x48, 0xE8, 0x88, 0x00},
+ {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //pointing up
+ { {0x00, 0x18, 0x00, 0x00}, {0x00, 0x78, 0x88, 0x00},
+ {0x00, 0x28, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //T (white)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x52, 0x82, 0x00},
+ {0x42, 0xA2, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} },
+ { {0x12, 0x00, 0x00, 0x00}, {0x62, 0x92, 0x00, 0x00},
+ {0x00, 0x22, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} },
+ { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x52, 0x82, 0x00},
+ {0x42, 0xA2, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep
+ { {0x12, 0x00, 0x00, 0x00}, {0x62, 0x92, 0x00, 0x00},
+ {0x00, 0x22, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //S (green)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x46, 0x96, 0x00, 0x00},
+ {0x00, 0x66, 0x86, 0x00}, {0x00, 0x00, 0x00, 0x00} },
+ { {0x00, 0x16, 0x00, 0x00}, {0x56, 0xA6, 0x00, 0x00},
+ {0x26, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} },
+ { {0x00, 0x00, 0x00, 0x00}, {0x46, 0x96, 0x00, 0x00},
+ {0x00, 0x66, 0x86, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep
+ { {0x00, 0x16, 0x00, 0x00}, {0x56, 0xA6, 0x00, 0x00},
+ {0x26, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} } }, //Z (red)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x44, 0xC4, 0xC4, 0x84},
+ {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //lieing
+ { {0x00, 0x14, 0x00, 0x00}, {0x00, 0x34, 0x00, 0x00},
+ {0x00, 0x34, 0x00, 0x00}, {0x00, 0x24, 0x00, 0x00} }, //standing
+ { {0x00, 0x00, 0x00, 0x00}, {0x44, 0xC4, 0xC4, 0x84},
+ {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep
+ { {0x00, 0x14, 0x00, 0x00}, {0x00, 0x34, 0x00, 0x00},
+ {0x00, 0x34, 0x00, 0x00}, {0x00, 0x24, 0x00, 0x00} } }, //stick (blue)
+
+ { { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00},
+ {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} },
+ { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00},
+ {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep
+ { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00},
+ {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} }, //rep
+ { {0x00, 0x00, 0x00, 0x00}, {0x00, 0x55, 0x95, 0x00},
+ {0x00, 0x65, 0xA5, 0x00}, {0x00, 0x00, 0x00, 0x00} } } //square (purple)
+};
+
+int ShapeIterate(char s, int scr, int y, int x, ShapeDrawFunc func)
+{ //Draw a certain shape using <ShapeDrawFunc>
+ int i, j, result;
+ char type, rotation;
+
+ type = s / 4;
+ rotation = s & 3;
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ if (shapes[type][rotation][i][j])
+ if (result = func(scr, y-i, x+j, shapes[type][rotation][i][j]))
+ return result;
+ return 0;
+}