25 enum { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE };
27 /* dimensions of the whole screen */
31 /* dimensions of the playfield */
34 /* offset of the playfield from the left side of the screen */
37 #define CHAR(c, fg, bg) \
38 ((uint16_t)(c) | ((uint16_t)(fg) << 12) | ((uint16_t)(bg) << 8))
40 uint16_t scr[SCR_COLS * SCR_ROWS];
42 static void wrchar(uint16_t c);
55 /* fill the screen buffer, and draw */
56 for(i=0; i<SCR_ROWS; i++) {
59 for(j=0; j<SCR_COLS; j++) {
60 if(i > PF_ROWS || j < PF_XOFFS - 1 || j > PF_XOFFS + PF_COLS) {
61 row[j] = CHAR(' ', WHITE, BLACK);
62 } else if((i == PF_ROWS && j >= PF_XOFFS && j < PF_XOFFS + PF_COLS) ||
63 j == PF_XOFFS - 1 || j == PF_XOFFS + PF_COLS) {
64 row[j] = CHAR(G_CHECKER, WHITE, BLACK);
66 row[j] = CHAR(' ', BLACK, WHITE);
79 void cleanup_game(void)
84 static int pos[2] = {0, PF_COLS / 2};
85 static int next_pos[2] = {0, PF_COLS / 2};
87 long update(long msec)
89 static long prev_tick;
92 dt = msec - prev_tick;
95 while(dt >= tick_interval) {
96 next_pos[0] = (pos[0] + 1) % PF_ROWS;
101 if(memcmp(pos, next_pos, sizeof pos) != 0) {
102 ansi_setcursor(pos[0], (PF_XOFFS + pos[1]) * 2);
103 wrchar(CHAR(' ', BLACK, WHITE));
105 memcpy(pos, next_pos, sizeof pos);
106 ansi_setcursor(pos[0], (PF_XOFFS + pos[1]) * 2);
107 wrchar(CHAR(' ', RED, RED));
111 return tick_interval - dt;
114 void game_input(int c)
123 next_pos[1] = pos[1] - 1;
128 if(pos[1] < PF_COLS - 1) {
129 next_pos[1] = pos[1] + 1;
138 static void wrchar(uint16_t c)
140 unsigned char cc = c & 0xff;
141 unsigned char ca = c >> 8;
143 ansi_ibmchar(cc, ca);
144 ansi_ibmchar(cc, ca);