avr: initial commit
[z80.git] / avr / monitor / slots.c
diff --git a/avr/monitor/slots.c b/avr/monitor/slots.c
new file mode 100644 (file)
index 0000000..98ef292
--- /dev/null
@@ -0,0 +1,85 @@
+/* Slot Configuration */
+
+#include <stdio.h>
+
+#include <avr/pgmspace.h>
+
+#include "../uart.h"
+#include "../monitor.h"
+
+static char* boards[] = {
+       "Empty",
+       "AVR Board",
+       "32K SRAM",
+       "-- ID 0x03 --",
+       "-- ID 0x04 --",
+};
+static uint8_t num_boards = sizeof(boards) / sizeof(boards[0]);
+
+static uint8_t change_slot(uint8_t slot)
+{
+       if(slot > 8) return(0);
+
+       uint8_t changed = 0;
+       uint8_t old_id = slots[slot];
+       char    sel = 0;
+
+       printf_P(PSTR("CHANGING SLOT\n============\n"), slot);
+       for(uint8_t i = 0; i < num_boards; i++) {
+               printf_P(PSTR("\t(%2u) %s\n"), i, boards[i]);
+       }
+
+       while(1) {
+               /* TODO: fix this for IDs greater 9 */
+               printf_P(PSTR("Select new board for slot %u: "), slot);
+               sel = uart_getc(NULL);
+               printf("\n\n");
+
+               if((unsigned)(sel - '0') < num_boards) {
+                       slots[slot] = (sel - '0');
+                       if(slots[slot] != old_id) changed = 1;
+                       printf_P(PSTR("Set to ID 0x%02x ['%s']\n"),
+                               (sel - '0'), boards[slots[slot]]);
+               } else {
+                       printf_P(PSTR("ID was NOT not changed.\n"));
+               }
+               break;
+       }
+
+       return(changed);
+}
+
+uint8_t menu_slots(void)
+{
+       int slots_changed = 0;
+       char sel = 0;
+
+       while(sel != '9') {
+               printf_P(PSTR("\nSLOT CONFIGURATION\n==================\n"));
+               for(uint8_t i = 1; i <= 8; i++) {
+                       char *name = "Invalid Entry";
+
+                       if(slots[i] != 0xFF) name = boards[slots[i]];
+                       printf_P(PSTR("\t(%u) Change Slot %u: 0x%02x [%s]\n"),
+                               i, (i-1), slots[i], name);
+               }
+               printf_P(PSTR("\t(9) Exit\n"));
+               printf_P(PSTR("Select: "));
+               sel = uart_getc(NULL);
+               printf_P(PSTR("\n\n"));
+
+               switch(sel) {
+               case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8':
+                       printf_P(PSTR("Changing Slot %i\n"), (sel - '0'));
+                       if(change_slot(sel - '0')) slots_changed = 1;
+                       break;
+               case '9':
+                       break;
+               default:
+                       printf_P(PSTR("Invalid Entry!\n")); break;
+               }
+       }
+       return(slots_changed);
+}
+