/* * Nonie's Dots-and-Boxes (Header File) * Written by Arnon Politi */ #define ROWS 4 #define COLS 4 #define SIZEY (ROWS * 2 + 1) #define SIZEX (COLS * 2 + 1) #define TOTALBOXES (ROWS * COLS) #define TOTALSCORE (player[0].score + player[1].score) #define MAXMOVES (2 * ROWS * COLS + ROWS + COLS) #define EMPTY -1 #define LINE 1 #define CHAINMARK 1 #define CLOSED -1 #define EDGE -2 #define PRIO_MAX 65536 #define NUM_PORTS 5 #define SW_UP 0x01 #define SW_DOWN 0x02 #define SW_LEFT 0x04 #define SW_RIGHT 0x08 #define SW_ROTATE 0x10 #define SW_SET 0x20 #define SW_RESET 0x80 #define SW_ALL 0xFF #define LCD_CHARS 6 #define LCD_LINES 4 #define LCD_IR 0x00 #define LCD_DR 0x02 #define LCD_EN 0x01 #define LCD_RW 0x04 #define LCD_SET_CGRAM 0x40 #define LCD_SET_DDRAM 0x80 #define COMP_FLASHES 4 #define RESET_DELAY 3000 #define PLAY_DELAY 1000 #define FLASH_DELAY 250 #define ANIM_DELAY 100 #define ROLL_DELAY 100 #define BOUNCE_DELAY 25 #define LCD_DELAY 5 typedef unsigned char byte; typedef struct players { const char NAME[5]; int score; } players; typedef struct xymove { int x; int y; } xymove; typedef struct prmove { int x; int y; int priority; } prmove; typedef struct ports { volatile byte *data; volatile byte *control; } ports; typedef struct portmaps { const int ENABLED; const int PORT; const int BIT; } portmaps; players player[] = { {"Plyr", 0}, {"Comp", 0} }; const char LOSE_MSG[] = "The computer wins! Better luck next time... "; const char WIN_MSG[] = "Congratulations! You're a winner!! "; const char TIE_MSG[] = "Almost there, but not quite... Its a tie! "; volatile byte *portA = (volatile byte *) (0x10000000); volatile byte *portB = (volatile byte *) (0x10000004); volatile byte *Timer = (volatile byte *) (0x10000008); ports port[NUM_PORTS] = { { (volatile byte *) (0x20000000), (volatile byte *) (0x20000001) }, // port[0] = SA_L { (volatile byte *) (0x20000002), (volatile byte *) (0x20000003) }, // port[1] = SA_H { (volatile byte *) (0x20000004), (volatile byte *) (0x20000005) }, // port[2] = SB_L { (volatile byte *) (0x20000006), (volatile byte *) (0x20000007) }, // port[3] = SB_H { (volatile byte *) (0x20000008), (volatile byte *) (0x20000009) } // port[4] = VS_L }; ports SWPort = { (volatile byte *) (0x2000000A), (volatile byte *) (0x2000000B) }; // SWPort = SA_L const portmaps PORTMAP[SIZEY][SIZEX] = { { {0}, {1, 0, 0}, {0}, {1, 0, 1}, {0}, {1, 0, 2}, {0}, {1, 0, 3}, {0} }, { {1, 2, 0}, {0}, {1, 2, 4}, {0}, {1, 3, 0}, {0}, {1, 3, 4}, {0}, {1, 4, 4} }, { {0}, {1, 0, 4}, {0}, {1, 0, 5}, {0}, {1, 0, 6}, {0}, {1, 0, 7}, {0} }, { {1, 2, 1}, {0}, {1, 2, 5}, {0}, {1, 3, 1}, {0}, {1, 3, 5}, {0}, {1, 4, 5} }, { {0}, {1, 1, 0}, {0}, {1, 1, 1}, {0}, {1, 1, 2}, {0}, {1, 1, 3}, {0} }, { {1, 2, 2}, {0}, {1, 2, 6}, {0}, {1, 3, 2}, {0}, {1, 3, 6}, {0}, {1, 4, 6} }, { {0}, {1, 1, 4}, {0}, {1, 1, 5}, {0}, {1, 1, 6}, {0}, {1, 1, 7}, {0} }, { {1, 2, 3}, {0}, {1, 2, 7}, {0}, {1, 3, 3}, {0}, {1, 3, 7}, {0}, {1, 4, 7} }, { {0}, {1, 4, 0}, {0}, {1, 4, 1}, {0}, {1, 4, 2}, {0}, {1, 4, 3}, {0} } }; const byte LCD_CGRAM[LCD_CHARS][8] = { {0x1F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F}, {0x1F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1F}, {0x1F, 0x10, 0x12, 0x10, 0x14, 0x13, 0x10, 0x1F}, {0x1F, 0x01, 0x09, 0x01, 0x05, 0x19, 0x01, 0x1F}, {0x1F, 0x10, 0x13, 0x12, 0x17, 0x14, 0x16, 0x1F}, {0x1F, 0x01, 0x19, 0x09, 0x1D, 0x05, 0x0D, 0x1F} }; const byte LCD_LINE_ADR[LCD_LINES] = {0x00, 0x40, 0x14, 0x54}; void initialize(void); xymove get_move(int playernum); int mod(int op1, int op2); int complete_boxes(xymove move, int playernum); int check_box(int y, int x, int playernum); void lcdwrite(byte data, const byte RS); void display_score(void); void display_box(int y, int x, int playernum); void display_arrow(int playernum); void roll_message(const char *MSG); byte delay_poll(int msec, byte pollbits); void delay(int msec); void init_comp(void); int long_chains(void); int closed_four_chains(void); int two_chains(void); int any_good_move(void); int count_chain(int nexty, int nextx, int *isclosed); void next_in_chain(int *nexty, int *nextx); int lines_around(int y, int x); void clear_chainmarks(void); void add_missing_line(int *moveindex, int y, int x, int priority); void add_move(int *moveindex, int y, int x, int priority); int min_count(void); int move_chain_length(int y, int x, int *c1, int *c2);