avr: initial commit
[z80.git] / avr / monitor / slots.c
1 /* Slot Configuration */
2
3 #include <stdio.h>
4
5 #include <avr/pgmspace.h>
6
7 #include "../uart.h"
8 #include "../monitor.h"
9
10 static char* boards[] = {
11         "Empty",
12         "AVR Board",
13         "32K SRAM",
14         "-- ID 0x03 --",
15         "-- ID 0x04 --",
16 };
17 static uint8_t num_boards = sizeof(boards) / sizeof(boards[0]);
18
19 static uint8_t change_slot(uint8_t slot)
20 {
21         if(slot > 8) return(0);
22
23         uint8_t changed = 0;
24         uint8_t old_id = slots[slot];
25         char    sel = 0;
26
27         printf_P(PSTR("CHANGING SLOT\n============\n"), slot);
28         for(uint8_t i = 0; i < num_boards; i++) {
29                 printf_P(PSTR("\t(%2u) %s\n"), i, boards[i]);
30         }
31
32         while(1) {
33                 /* TODO: fix this for IDs greater 9 */
34                 printf_P(PSTR("Select new board for slot %u: "), slot);
35                 sel = uart_getc(NULL);
36                 printf("\n\n");
37
38                 if((unsigned)(sel - '0') < num_boards) {
39                         slots[slot] = (sel - '0');
40                         if(slots[slot] != old_id) changed = 1;
41                         printf_P(PSTR("Set to ID 0x%02x ['%s']\n"),
42                                 (sel - '0'), boards[slots[slot]]);
43                 } else {
44                         printf_P(PSTR("ID was NOT not changed.\n"));
45                 }
46                 break;
47         }
48
49         return(changed);
50 }
51
52 uint8_t menu_slots(void)
53 {
54         int slots_changed = 0;
55         char sel = 0;
56
57         while(sel != '9') {
58                 printf_P(PSTR("\nSLOT CONFIGURATION\n==================\n"));
59                 for(uint8_t i = 1; i <= 8; i++) {
60                         char *name = "Invalid Entry";
61
62                         if(slots[i] != 0xFF) name = boards[slots[i]];
63                         printf_P(PSTR("\t(%u) Change Slot %u: 0x%02x [%s]\n"),
64                                 i, (i-1), slots[i], name);
65                 }
66                 printf_P(PSTR("\t(9) Exit\n"));
67                 printf_P(PSTR("Select: "));
68                 sel = uart_getc(NULL);
69                 printf_P(PSTR("\n\n"));
70
71                 switch(sel) {
72                 case '1': case '2': case '3': case '4':
73                 case '5': case '6': case '7': case '8':
74                         printf_P(PSTR("Changing Slot %i\n"), (sel - '0'));
75                         if(change_slot(sel - '0')) slots_changed = 1;
76                         break;
77                 case '9':
78                         break;
79                 default:
80                         printf_P(PSTR("Invalid Entry!\n")); break;
81                 }
82         }
83         return(slots_changed);
84 }
85