Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreinfo project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "coreinfo.h" |
| 17 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 18 | #define KEY_ESC 27 |
| 19 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 20 | extern struct coreinfo_module cpuinfo_module; |
| 21 | extern struct coreinfo_module pci_module; |
| 22 | extern struct coreinfo_module coreboot_module; |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 23 | extern struct coreinfo_module multiboot_module; |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 24 | extern struct coreinfo_module nvram_module; |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 25 | extern struct coreinfo_module bootlog_module; |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 26 | extern struct coreinfo_module ramdump_module; |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 27 | extern struct coreinfo_module cbfs_module; |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 28 | extern struct coreinfo_module timestamps_module; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 29 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 30 | struct coreinfo_module *system_modules[] = { |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 31 | #if CONFIG(MODULE_CPUINFO) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 32 | &cpuinfo_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 33 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 34 | #if CONFIG(MODULE_PCI) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 35 | &pci_module, |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 36 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 37 | #if CONFIG(MODULE_NVRAM) |
Jordan Crouse | 7ce2666 | 2008-05-06 22:00:55 +0000 | [diff] [blame] | 38 | &nvram_module, |
| 39 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 40 | #if CONFIG(MODULE_RAMDUMP) |
Uwe Hermann | 2fbbb29 | 2008-07-08 16:18:38 +0000 | [diff] [blame] | 41 | &ramdump_module, |
| 42 | #endif |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 45 | struct coreinfo_module *firmware_modules[] = { |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 46 | #if CONFIG(MODULE_COREBOOT) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 47 | &coreboot_module, |
| 48 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 49 | #if CONFIG(MODULE_MULTIBOOT) |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 50 | &multiboot_module, |
| 51 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 52 | #if CONFIG(MODULE_BOOTLOG) |
Uwe Hermann | 0ab8cdd | 2008-04-22 20:19:53 +0000 | [diff] [blame] | 53 | &bootlog_module, |
| 54 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 55 | #if CONFIG(MODULE_CBFS) |
Uwe Hermann | 941c1fd | 2009-07-07 15:10:13 +0000 | [diff] [blame] | 56 | &cbfs_module, |
Jordan Crouse | aa6e378 | 2008-05-07 20:43:15 +0000 | [diff] [blame] | 57 | #endif |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 58 | #if CONFIG(MODULE_TIMESTAMPS) |
Antonello Dettori | 4b1668f | 2016-07-08 11:14:40 +0200 | [diff] [blame] | 59 | ×tamps_module, |
| 60 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 63 | struct coreinfo_cat { |
| 64 | char name[15]; |
| 65 | int cur; |
| 66 | int count; |
| 67 | struct coreinfo_module **modules; |
| 68 | } categories[] = { |
| 69 | { |
| 70 | .name = "System", |
| 71 | .modules = system_modules, |
| 72 | .count = ARRAY_SIZE(system_modules), |
| 73 | }, |
| 74 | { |
Jordan Crouse | 5cb4d9d | 2008-11-11 19:53:42 +0000 | [diff] [blame] | 75 | .name = "Firmware", |
| 76 | .modules = firmware_modules, |
| 77 | .count = ARRAY_SIZE(firmware_modules), |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 78 | } |
| 79 | }; |
| 80 | |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 81 | static WINDOW *modwin, *menuwin; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 82 | static int curwin; |
| 83 | |
| 84 | void print_module_title(WINDOW *win, const char *title) |
| 85 | { |
| 86 | int i; |
| 87 | |
| 88 | wattrset(win, COLOR_PAIR(2)); |
| 89 | mvwprintw(win, 0, 1, title); |
| 90 | |
| 91 | wmove(win, 1, 1); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 92 | for (i = 0; i < 78; i++) |
Ulf Jordan | d133d9a | 2008-08-11 20:35:32 +0000 | [diff] [blame] | 93 | waddch(win, ACS_HLINE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 96 | static void print_submenu(struct coreinfo_cat *cat) |
| 97 | { |
| 98 | int i, j; |
| 99 | char menu[80]; |
| 100 | char *ptr = menu; |
| 101 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 102 | wmove(menuwin, 0, 0); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 103 | |
| 104 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 105 | waddch(menuwin, ' '); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 106 | |
| 107 | if (!cat->count) |
| 108 | return; |
| 109 | |
| 110 | for (i = 0; i < cat->count; i++) |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 111 | ptr += sprintf(ptr, "[%c: %s] ", 'A' + i, |
| 112 | cat->modules[i]->name); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 113 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 114 | mvwprintw(menuwin, 0, 0, menu); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 117 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 118 | static void print_time_and_date(void) |
| 119 | { |
| 120 | struct tm tm; |
| 121 | |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 122 | while (nvram_updating()) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 123 | mdelay(10); |
| 124 | |
| 125 | rtc_read_clock(&tm); |
| 126 | |
Jonathan Neuschäfer | 2bf7a2c | 2016-04-04 19:44:30 +0200 | [diff] [blame] | 127 | mvwprintw(menuwin, 1, 57, "%02d/%02d/%04d - %02d:%02d:%02d", |
Yasha Cherikovsky | ae16c40 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 128 | tm.tm_mon + 1, tm.tm_mday, 1900 + tm.tm_year, tm.tm_hour, |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 129 | tm.tm_min, tm.tm_sec); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 130 | } |
| 131 | #endif |
| 132 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 133 | static void print_menu(void) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 134 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 135 | int j; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 136 | char menu[80]; |
| 137 | char *ptr = menu; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 138 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 139 | wmove(menuwin, 1, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 140 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 141 | waddch(menuwin, ' '); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 142 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 143 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) { |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 144 | if (categories[i].count == 0) |
| 145 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 146 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 147 | ptr += sprintf(ptr, "F%zu: %s ", i + 1, categories[i].name); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 150 | mvwprintw(menuwin, 1, 0, menu); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 151 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 152 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 153 | print_time_and_date(); |
Uwe Hermann | ab5b3e0 | 2008-03-31 20:30:18 +0000 | [diff] [blame] | 154 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 157 | static void center(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 158 | { |
Uwe Hermann | 695cff3 | 2008-08-07 14:35:39 +0000 | [diff] [blame] | 159 | int j, len = strlen(str); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 160 | |
| 161 | wmove(stdscr, row, 0); |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 162 | for (j = 0; j < SCREEN_X; j++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 163 | waddch(stdscr, ' '); |
| 164 | |
| 165 | mvprintw(row, (SCREEN_X - len) / 2, str); |
| 166 | } |
| 167 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 168 | /* FIXME: Currently unused. */ |
| 169 | #if 0 |
| 170 | static void header(int row, const char *str) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 171 | { |
| 172 | char buf[SCREEN_X]; |
| 173 | char *ptr = buf; |
| 174 | int i; |
| 175 | int len = strlen(str) + 4; |
| 176 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 177 | for (i = 0; i < (SCREEN_X - len) / 2; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 178 | ptr += sprintf(ptr, "="); |
| 179 | |
| 180 | ptr += sprintf(ptr, "[ %s ]", str); |
| 181 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 182 | for (i = ((SCREEN_X - len) / 2) + len; i < SCREEN_X; i++) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 183 | ptr += sprintf(ptr, "="); |
| 184 | |
| 185 | mvprintw(row, 0, buf); |
| 186 | } |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 187 | #endif |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 188 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 189 | static void redraw_module(struct coreinfo_cat *cat) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 190 | { |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 191 | if (cat->count == 0) |
Uwe Hermann | 6c44dfb | 2008-04-04 16:49:09 +0000 | [diff] [blame] | 192 | return; |
| 193 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 194 | wclear(modwin); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 195 | cat->modules[cat->cur]->redraw(modwin); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 196 | wrefresh(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 197 | } |
| 198 | |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 199 | static void handle_category_key(struct coreinfo_cat *cat, int key) |
| 200 | { |
Himanshu Sahdev | d3d38c9 | 2019-09-23 15:08:18 +0530 | [diff] [blame] | 201 | if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) { |
| 202 | int index; |
| 203 | if (key >= 'A' && key <= 'Z') { |
| 204 | index = key - 'A'; |
| 205 | } else { |
| 206 | index = key - 'a'; |
| 207 | } |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 208 | if (index < cat->count) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 209 | cat->cur = index; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 210 | redraw_module(cat); |
| 211 | return; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | if (cat->count && cat->modules[cat->cur]->handle) { |
| 216 | if (cat->modules[cat->cur]->handle(key)) |
| 217 | redraw_module(cat); |
| 218 | } |
| 219 | } |
| 220 | |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 221 | static void print_no_modules_selected(void) |
| 222 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 223 | int height = getmaxy(stdscr); |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 224 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 225 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 226 | if (categories[i].count > 0) |
| 227 | return; |
| 228 | |
| 229 | color_set(2, NULL); // White on black |
| 230 | center(height / 2, "No modules selected"); |
| 231 | } |
| 232 | |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 233 | static int first_nonempty_category(void) |
| 234 | { |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 235 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 236 | if (categories[i].count > 0) |
| 237 | return i; |
| 238 | return 0; |
| 239 | } |
| 240 | |
Uwe Hermann | 0bfb5c4 | 2008-03-23 15:34:04 +0000 | [diff] [blame] | 241 | static void loop(void) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 242 | { |
| 243 | int key; |
| 244 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 245 | center(0, CONFIG_PAYLOAD_INFO_NAME " " CONFIG_PAYLOAD_INFO_VERSION); |
Jonathan Neuschäfer | 8a61a2f | 2016-03-10 04:56:31 +0100 | [diff] [blame] | 246 | print_no_modules_selected(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 247 | refresh(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 248 | |
Jonathan Neuschäfer | ff09952 | 2016-03-10 06:33:00 +0100 | [diff] [blame] | 249 | curwin = first_nonempty_category(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 250 | print_menu(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 251 | print_submenu(&categories[curwin]); |
| 252 | redraw_module(&categories[curwin]); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 253 | |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 254 | halfdelay(10); |
| 255 | |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 256 | while (1) { |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 257 | int ch = -1; |
| 258 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 259 | #if CONFIG(SHOW_DATE_TIME) |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 260 | print_time_and_date(); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 261 | wrefresh(menuwin); |
Jordan Crouse | 1933786 | 2008-05-06 22:15:31 +0000 | [diff] [blame] | 262 | #endif |
| 263 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 264 | key = getch(); |
| 265 | |
| 266 | if (key == ERR) |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 267 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 268 | |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 269 | if (key >= KEY_F(1) && key <= KEY_F(9)) |
| 270 | ch = key - KEY_F(1); |
| 271 | if (key >= '1' && key <= '9') |
| 272 | ch = key - '1'; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 273 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 274 | if (ch >= 0 && (unsigned int)ch <= ARRAY_SIZE(categories)) { |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 275 | if (ch == ARRAY_SIZE(categories)) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 276 | continue; |
Stefan Reinauer | c2b50ac | 2016-03-11 23:17:28 -0800 | [diff] [blame] | 277 | if (categories[ch].count == 0) |
| 278 | continue; |
| 279 | |
| 280 | curwin = ch; |
| 281 | print_submenu(&categories[curwin]); |
| 282 | redraw_module(&categories[curwin]); |
| 283 | continue; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Uwe Hermann | 29413c7 | 2008-05-21 13:49:03 +0000 | [diff] [blame] | 286 | if (key == KEY_ESC) |
Jordan Crouse | 98cc056 | 2008-05-20 20:16:34 +0000 | [diff] [blame] | 287 | return; |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 288 | |
| 289 | handle_category_key(&categories[curwin], key); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Jacob Garber | bd62472 | 2019-10-02 14:44:28 -0600 | [diff] [blame] | 293 | int main(int argc, char **argv) |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 294 | { |
Jacob Garber | bd62472 | 2019-10-02 14:44:28 -0600 | [diff] [blame] | 295 | (void)argc; |
| 296 | (void)argv; |
| 297 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 298 | int j; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 299 | |
Julius Werner | eab2a29 | 2019-03-05 16:55:15 -0800 | [diff] [blame] | 300 | if (CONFIG(LP_USB)) |
Nicola Corna | 71693ba | 2017-03-14 10:26:58 +0100 | [diff] [blame] | 301 | usb_initialize(); |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 302 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 303 | initscr(); |
| 304 | |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 305 | start_color(); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 306 | init_pair(1, COLOR_WHITE, COLOR_GREEN); |
Dave Frodin | 1b0c352 | 2012-12-05 17:26:03 -0700 | [diff] [blame] | 307 | init_pair(2, COLOR_WHITE, COLOR_BLACK); |
| 308 | init_pair(3, COLOR_BLACK, COLOR_WHITE); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 309 | |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 310 | modwin = newwin(SCREEN_Y - 3, SCREEN_X, 1, 0); |
| 311 | menuwin = newwin(2, SCREEN_X, SCREEN_Y - 2, 0); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 312 | |
| 313 | wattrset(stdscr, COLOR_PAIR(1) | A_BOLD); |
| 314 | wattrset(modwin, COLOR_PAIR(2)); |
Jordan Crouse | 9b1c7c1 | 2008-05-20 20:16:03 +0000 | [diff] [blame] | 315 | wattrset(menuwin, COLOR_PAIR(1) | A_BOLD); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 316 | |
Ulf Jordan | 22d5ddc | 2008-09-24 14:21:02 +0000 | [diff] [blame] | 317 | werase(modwin); |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 318 | |
Jacob Garber | a711e9c | 2019-06-28 10:58:56 -0600 | [diff] [blame] | 319 | for (size_t i = 0; i < ARRAY_SIZE(categories); i++) { |
Uwe Hermann | 941aaee | 2008-07-18 14:08:18 +0000 | [diff] [blame] | 320 | for (j = 0; j < categories[i].count; j++) |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 321 | categories[i].modules[j]->init(); |
Jordan Crouse | de7fc55 | 2008-05-06 22:03:16 +0000 | [diff] [blame] | 322 | } |
Uwe Hermann | 3a406fe | 2008-03-20 01:11:28 +0000 | [diff] [blame] | 323 | |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 324 | noecho(); /* don't let curses echo keyboard chars */ |
| 325 | keypad(stdscr, TRUE); /* allow KEY_F(n) keys to be seen */ |
Yasha Cherikovsky | 619fc95 | 2015-11-14 19:16:58 +0200 | [diff] [blame] | 326 | curs_set(0); /* Hide blinking cursor */ |
Dave Frodin | 15a2c8f | 2012-12-05 17:22:47 -0700 | [diff] [blame] | 327 | |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 328 | loop(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 329 | |
Maxime de Roucy | 8190078 | 2015-09-27 15:53:40 +0200 | [diff] [blame] | 330 | /* reboot */ |
| 331 | outb(0x6, 0xcf9); |
| 332 | halt(); |
Uwe Hermann | 35845a2 | 2008-03-20 20:05:22 +0000 | [diff] [blame] | 333 | return 0; |
Jordan Crouse | 7249f79 | 2008-03-20 00:11:05 +0000 | [diff] [blame] | 334 | } |
Jordan Crouse | 5083811 | 2008-05-27 20:07:47 +0000 | [diff] [blame] | 335 | |
Uwe Hermann | a70872cf | 2008-08-05 14:36:20 +0000 | [diff] [blame] | 336 | PAYLOAD_INFO(name, CONFIG_PAYLOAD_INFO_NAME); |
| 337 | PAYLOAD_INFO(listname, CONFIG_PAYLOAD_INFO_LISTNAME); |
| 338 | PAYLOAD_INFO(desc, CONFIG_PAYLOAD_INFO_DESC); |