Changeset 57c8555003f53800da1bb93a765d80678ae230ae
- Timestamp:
- 10/27/09 20:04:31 (2 years ago)
- Children:
- 4dc540d979c770c6131217d6e94b29a6f188e1c1
- Parents:
- 47ac912cd5d8df0a96b8f5b98d7476f7cfb1cb19, 3fc3126d0c7df5701680e043c34f200166f24564
- git-committer:
- Pierre-Alexandre Meyer <pierre@ning.com> / 2009-10-27T13:04:31Z-0700
- Files:
-
- 12 added
- 3 removed
- 49 modified
-
MCONFIG (modified) (1 diff)
-
NEWS (modified) (1 diff)
-
com32/cmenu/adv_menu.tpl (modified) (4 diffs)
-
com32/cmenu/complex.c (modified) (8 diffs)
-
com32/cmenu/libmenu/com32io.c (modified) (6 diffs)
-
com32/cmenu/libmenu/com32io.h (modified) (5 diffs)
-
com32/cmenu/libmenu/help.c (modified) (9 diffs)
-
com32/cmenu/libmenu/help.h (modified) (2 diffs)
-
com32/cmenu/libmenu/menu.c (modified) (39 diffs)
-
com32/cmenu/libmenu/menu.h (modified) (6 diffs)
-
com32/cmenu/libmenu/scancodes.h (deleted)
-
com32/cmenu/libmenu/tui.c (modified) (15 diffs)
-
com32/cmenu/libmenu/tui.h (modified) (4 diffs)
-
com32/gplinclude/cpuid.h (modified) (1 diff)
-
com32/gplinclude/disk/bootloaders.h (added)
-
com32/gplinclude/disk/common.h (modified) (1 diff)
-
com32/gplinclude/disk/error.h (modified) (1 diff)
-
com32/gplinclude/disk/mbrs.h (added)
-
com32/gplinclude/disk/util.h (modified) (1 diff)
-
com32/gpllib/cpuid.c (modified) (1 diff)
-
com32/gpllib/disk/ata.c (modified) (1 diff)
-
com32/gpllib/disk/bootloaders.c (added)
-
com32/gpllib/disk/error.c (modified) (1 diff)
-
com32/gpllib/disk/mbrs.c (added)
-
com32/hdt/Makefile (modified) (2 diffs)
-
com32/hdt/README (added)
-
com32/hdt/floppy/hdt.cfg (added)
-
com32/hdt/floppy/mtools.conf (added)
-
com32/hdt/hdt-cli-cpu.c (modified) (1 diff)
-
com32/hdt/hdt-cli-disk.c (modified) (11 diffs)
-
com32/hdt/hdt-cli-hdt.c (modified) (1 diff)
-
com32/hdt/hdt-cli.c (modified) (2 diffs)
-
com32/hdt/hdt-common.c (modified) (3 diffs)
-
com32/hdt/hdt-common.h (modified) (5 diffs)
-
com32/hdt/hdt-menu-disk.c (modified) (8 diffs)
-
com32/hdt/hdt-menu-kernel.c (modified) (1 diff)
-
com32/hdt/hdt-menu-pci.c (modified) (1 diff)
-
com32/hdt/hdt-menu-processor.c (modified) (1 diff)
-
com32/hdt/hdt-menu-summary.c (modified) (1 diff)
-
com32/hdt/hdt-menu-syslinux.c (modified) (1 diff)
-
com32/hdt/hdt-menu.c (modified) (3 diffs)
-
com32/hdt/hdt-menu.h (modified) (3 diffs)
-
com32/hdt/hdt.c (modified) (1 diff)
-
com32/hdt/lib-ansi.c (deleted)
-
com32/hdt/lib-ansi.h (deleted)
-
com32/include/cpufeature.h (modified) (2 diffs)
-
com32/include/libansi.h (added)
-
com32/lib/Makefile (modified) (1 diff)
-
com32/lib/sys/ansi.c (modified) (7 diffs)
-
com32/lib/sys/ansi.h (modified) (3 diffs)
-
com32/lib/sys/ansicon_write.c (modified) (4 diffs)
-
com32/lib/sys/libansi.c (added)
-
com32/mboot/map.c (modified) (1 diff)
-
com32/modules/Makefile (modified) (1 diff)
-
com32/modules/chain.c (modified) (4 diffs)
-
com32/modules/cpuidtest.c (modified) (1 diff)
-
com32/modules/gpxecmd.c (added)
-
core/localboot.inc (modified) (1 diff)
-
core/pxelinux.asm (modified) (10 diffs)
-
core/serirq.inc (modified) (4 diffs)
-
modules/Makefile (modified) (1 diff)
-
modules/int18.asm (added)
-
utils/Makefile (modified) (1 diff)
-
utils/pxelinux-options (added)
Legend:
- Unmodified
- Added
- Removed
-
MCONFIG
rfe9385 r18d726 53 53 GZIPPROG = gzip 54 54 PNGTOPNM = pngtopnm 55 MCOPY = mcopy 56 MFORMAT = mformat 57 MKISOFS = mkisofs 55 58 56 59 com32 = $(topdir)/com32 -
NEWS
r788da30 r0d5291 19 19 * Simple menu: fix crash on some platforms. 20 20 * Gfxboot: fixes to the configuration file parsing. 21 * PXELINUX: add a tool to override specific DHCP options via 22 values hardcoded in the pxelinux.0 file. These hardcoded 23 values can be either "before DHCP" (defaults if DHCP do not 24 provide values), or "after DHCP" (overrides DHCP). The tool 25 pxelinux-options can be used to set these options. This 26 feature does not apply to gpxelinux.0; when used with gPXE 27 this is better handled by modifying the embedded script. 21 28 22 29 Changes in 3.82: -
com32/cmenu/adv_menu.tpl
r37bfb1 r352337 41 41 #include <string.h> 42 42 #include <stdlib.h> 43 #include <unistd.h> 43 44 44 45 #define MAX_CMD_LINE_LENGTH 514 … … 193 194 } 194 195 195 void keys_handler(t_menusystem *ms, t_menuitem *mi,unsigned int scancode) 196 { 197 char nc; 198 199 if ( ((scancode >> 8) == F1) && (mi->helpid != 0xFFFF) ) { // If scancode of F1 and non-trivial helpid 196 void keys_handler(t_menusystem * ms __attribute__ (( unused )), t_menuitem * mi, int scancode) 197 { 198 int nc, nr; 199 200 if (getscreensize(1, &nr, &nc)) { 201 /* Unknown screen size? */ 202 nc = 80; 203 nr = 24; 204 } 205 206 if ( (scancode == KEY_F1) && (mi->helpid != 0xFFFF) ) { // If scancode of F1 and non-trivial helpid 200 207 runhelpsystem(mi->helpid); 201 208 } … … 203 210 // If user hit TAB, and item is an "executable" item 204 211 // and user has privileges to edit it, edit it in place. 205 if (( (scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&206 (EDIT_ROW < getnumrows()) && (EDIT_ROW > 0) &&212 if ((scancode == KEY_TAB) && (mi->action == OPT_RUN) && 213 (EDIT_ROW < nr) && (EDIT_ROW > 0) && 207 214 (isallowed(username,"editcmd") || isallowed(username,"root"))) { 208 nc = getnumcols();209 215 // User typed TAB and has permissions to edit command line 210 gotoxy(EDIT_ROW,1 ,ms->menupage);216 gotoxy(EDIT_ROW,1); 211 217 csprint("Command line:",0x07); 212 218 editstring(mi->data,ACTIONLEN); 213 gotoxy(EDIT_ROW,1 ,ms->menupage);214 cprint(' ',0x07,nc-1 ,ms->menupage);215 } 216 } 217 218 t_handler_return login_handler(t_menu system *ms, t_menuitem *mi)219 gotoxy(EDIT_ROW,1); 220 cprint(' ',0x07,nc-1); 221 } 222 } 223 224 t_handler_return login_handler(t_menuitem *mi) 219 225 { 220 226 (void)mi; // Unused 221 227 char pwd[40]; 222 228 char login[40]; 223 char nc;229 int nc, nr; 224 230 t_handler_return rv; 225 231 … … 228 234 229 235 if (mi->item == loginstr) { /* User wants to login */ 230 nc = getnumcols(); 231 gotoxy(PWD_ROW,1,ms->menupage); 236 if (getscreensize(1, &nr, &nc)) { 237 /* Unknown screen size? */ 238 nc = 80; 239 nr = 24; 240 } 241 242 gotoxy(PWD_ROW,1); 232 243 csprint("Enter Username: ",0x07); 233 244 getstring(login, sizeof username); 234 gotoxy(PWD_ROW,1 ,ms->menupage);235 cprint(' ',0x07,nc ,ms->menupage);245 gotoxy(PWD_ROW,1); 246 cprint(' ',0x07,nc); 236 247 csprint("Enter Password: ",0x07); 237 248 getpwd(pwd, sizeof pwd); 238 gotoxy(PWD_ROW,1 ,ms->menupage);239 cprint(' ',0x07,nc ,ms->menupage);249 gotoxy(PWD_ROW,1); 250 cprint(' ',0x07,nc); 240 251 241 252 if (authenticate_user(login,pwd)) -
com32/cmenu/complex.c
r9e5b97 r3e8d9f 22 22 #include <stdlib.h> 23 23 #include <stdio.h> 24 #include <unistd.h> 25 #include <getkey.h> 24 26 25 27 /* Global variables */ … … 66 68 #define EDITPROMPT 21 67 69 68 void keys_handler(t_menusystem * ms , t_menuitem * mi, unsignedint scancode)69 { 70 char nc;71 72 if ((scancode >> 8) == F1) { // If scancode of F170 void keys_handler(t_menusystem * ms __attribute__ (( unused )), t_menuitem * mi, int scancode) 71 { 72 int nc, nr; 73 74 if ((scancode) == KEY_F1 && mi->helpid != 0xFFFF) { // If scancode of F1 73 75 runhelpsystem(mi->helpid); 74 76 } 75 77 // If user hit TAB, and item is an "executable" item 76 78 // and user has privileges to edit it, edit it in place. 77 if (( (scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN) &&79 if ((scancode == KEY_TAB) && (mi->action == OPT_RUN) && 78 80 (isallowed(username, "editcmd") || isallowed(username, "root"))) { 79 nc = getnumcols(); 81 if (getscreensize(1, &nr, &nc)) { 82 /* Unknown screen size? */ 83 nc = 80; 84 nr = 24; 85 } 80 86 // User typed TAB and has permissions to edit command line 81 gotoxy(EDITPROMPT, 1 , ms->menupage);87 gotoxy(EDITPROMPT, 1); 82 88 csprint("Command line:", 0x07); 83 89 editstring(mi->data, ACTIONLEN); 84 gotoxy(EDITPROMPT, 1 , ms->menupage);85 cprint(' ', 0x07, nc - 1, ms->menupage);86 } 87 } 88 89 t_handler_return login_handler(t_menu system * ms, t_menuitem * mi)90 gotoxy(EDITPROMPT, 1); 91 clear_line(); 92 } 93 } 94 95 t_handler_return login_handler(t_menuitem * mi) 90 96 { 91 97 (void)mi; // Unused 92 98 char pwd[40]; 93 99 char login[40]; 94 char nc;100 int nc, nr; 95 101 t_handler_return rv; 96 102 97 103 if (mi->item == loginstr) { /* User wants to login */ 98 nc = getnumcols(); 99 gotoxy(PWDPROMPT, 1, ms->menupage); 104 if (getscreensize(1, &nr, &nc)) { 105 /* Unknown screen size? */ 106 nc = 80; 107 nr = 24; 108 } 109 gotoxy(PWDPROMPT, 1); 100 110 csprint("Enter Username: ", 0x07); 101 111 getstring(login, sizeof username); 102 gotoxy(PWDPROMPT, 1 , ms->menupage);103 cprint(' ', 0x07, nc, ms->menupage);112 gotoxy(PWDPROMPT, 1); 113 clear_line(); 104 114 csprint("Enter Password: ", 0x07); 105 115 getpwd(pwd, sizeof pwd); 106 gotoxy(PWDPROMPT, 1 , ms->menupage);107 cprint(' ', 0x07, nc, ms->menupage);116 gotoxy(PWDPROMPT, 1); 117 clear_line(); 108 118 109 119 if (authenticate_user(login, pwd)) { … … 134 144 void msys_handler(t_menusystem * ms, t_menuitem * mi) 135 145 { 136 char nc;146 int nc, nr; 137 147 void *v; 138 nc = getnumcols(); // Get number of columns 139 140 gotoxy(PWDLINE, PWDCOLUMN, ms->menupage); 148 149 if (getscreensize(1, &nr, &nc)) { 150 /* Unknown screen size? */ 151 nc = 80; 152 nr = 24; 153 } 154 gotoxy(PWDLINE, PWDCOLUMN); 141 155 csprint("User: ", PWDATTR); 142 cprint(ms->fillchar, ms->fillattr, sizeof username , ms->menupage);143 gotoxy(PWDLINE, PWDCOLUMN + 6 , ms->menupage);156 cprint(ms->fillchar, ms->fillattr, sizeof username); 157 gotoxy(PWDLINE, PWDCOLUMN + 6); 144 158 csprint(username, PWDATTR); 145 159 146 160 if (mi->parindex != PREPMENU) // If we are not in the PREP MENU 147 161 { 148 gotoxy(INFLINE, 0, ms->menupage); 149 cprint(' ', 0x07, nc, ms->menupage); 150 gotoxy(INFLINE + 1, 0, ms->menupage); 151 cprint(' ', 0x07, nc, ms->menupage); 162 gotoxy(INFLINE, 0); 163 reset_colors(); 164 clear_line(); 165 gotoxy(INFLINE + 1, 0); 166 clear_line(); 152 167 return; 153 168 } … … 168 183 strcat(infoline, "repair=lin "); 169 184 170 gotoxy(INFLINE, 0, ms->menupage); 171 cprint(' ', 0x07, nc, ms->menupage); 172 gotoxy(INFLINE + 1, 0, ms->menupage); 173 cprint(' ', 0x07, nc, ms->menupage); 174 gotoxy(INFLINE, 0, ms->menupage); 185 gotoxy(INFLINE, 0); 186 reset_colors(); 187 clear_line(); 188 gotoxy(INFLINE + 1, 0); 189 clear_line(); 190 gotoxy(INFLINE, 0); 175 191 csprint("Kernel Arguments:", 0x07); 176 gotoxy(INFLINE, 17 , ms->menupage);192 gotoxy(INFLINE, 17); 177 193 csprint(infoline, 0x07); 178 194 } … … 195 211 { 196 212 (void)ms; /* Unused */ 213 214 t_handler_return rv; 197 215 198 216 if (mi->action != OPT_CHECKBOX) … … 221 239 if (strcmp(mi->data, "mountcd") == 0) 222 240 flags.mountcd = (mi->itemdata.checked ? 1 : 0); 223 return ACTION_VALID; 224 } 225 226 /* 227 Clears keyboard buffer and then 228 wait for stepsize*numsteps milliseconds for user to press any key 229 checks for keypress every stepsize milliseconds. 230 Returns: 1 if user pressed a key (not read from the buffer), 231 0 if time elapsed 232 */ 233 int checkkeypress(int stepsize, int numsteps) 234 { 235 int i; 236 clearkbdbuf(); 237 for (i = 0; i < numsteps; i++) { 238 if (checkkbdbuf()) 239 return 1; 240 sleep(stepsize); 241 } 242 return 0; 241 242 rv.valid = 0; 243 rv.refresh = 1; 244 return rv; 243 245 } 244 246 … … 272 274 reg_handler(HDLR_KEYS, &keys_handler); 273 275 // Register the ontimeout handler, with a time out of 10 seconds 274 reg_ontimeout(ontimeout, 10 00, 0);276 reg_ontimeout(ontimeout, 10, 0); 275 277 276 278 NETMENU = add_menu(" Init Network ", -1); … … 402 404 set_item_options(-1, 30); 403 405 csprint("Press any key within 5 seconds to show menu...", 0x07); 404 if ( !checkkeypress(100, 50)) // Granularity of 100 milliseconds406 if (get_key(stdin, 50) == KEY_NONE) // Granularity of 100 milliseconds 405 407 { 406 408 csprint("Sorry! Time's up.\r\n", 0x07); 407 409 return 1; 408 } else 409 clearkbdbuf(); // Just in case user pressed something important 410 } 410 411 curr = showmenus(MAIN); 411 412 if (curr) { -
com32/cmenu/libmenu/com32io.c
r62038f r9df342 14 14 #include <com32.h> 15 15 #include "com32io.h" 16 #include "tui.h" 16 17 #include "syslnx.h" 17 18 18 19 com32sys_t inreg, outreg; // Global register sets for use 19 20 /* Print character and attribute at cursor */21 void cprint(char chr, char attr, unsigned int times, char disppage)22 {23 REG_AH(inreg) = 0x09;24 REG_AL(inreg) = chr;25 REG_BH(inreg) = disppage;26 REG_BL(inreg) = attr;27 REG_CX(inreg) = times;28 __intcall(0x10, &inreg, &outreg);29 }30 31 void setdisppage(char num) // Set the display page to specified number32 {33 REG_AH(inreg) = 0x05;34 REG_AL(inreg) = num;35 __intcall(0x10, &inreg, &outreg);36 }37 38 char getdisppage() // Get current display page39 {40 REG_AH(inreg) = 0x0f;41 __intcall(0x10, &inreg, &outreg);42 return REG_BH(outreg);43 }44 20 45 21 void getpos(char *row, char *col, char page) … … 50 26 *row = REG_DH(outreg); 51 27 *col = REG_DL(outreg); 52 }53 54 void gotoxy(char row, char col, char page)55 {56 REG_AH(inreg) = 0x02;57 REG_BH(inreg) = page;58 REG_DX(inreg) = (row << 8) + col;59 __intcall(0x10, &inreg, &outreg);60 28 } 61 29 … … 69 37 __intcall(0x15, &inreg, &outreg); 70 38 return REG_AH(outreg); 71 }72 73 void beep()74 {75 REG_AH(inreg) = 0x0E;76 REG_AL(inreg) = 0x07;77 REG_BH(inreg) = 0;78 __intcall(0x10, &inreg, &outreg);79 }80 81 void scrollupwindow(char top, char left, char bot, char right, char attr,82 char numlines)83 {84 REG_AH(inreg) = 0x06;85 REG_AL(inreg) = numlines;86 REG_BH(inreg) = attr; // Attribute to write blanks lines87 REG_DX(inreg) = (bot << 8) + right; // BOT RIGHT corner of window88 REG_CX(inreg) = (top << 8) + left; // TOP LEFT of window89 __intcall(0x10, &inreg, &outreg);90 39 } 91 40 … … 102 51 void getcursorshape(char *start, char *end) 103 52 { 104 char page = getdisppage();53 char page = 0; // XXX TODO 105 54 REG_AH(inreg) = 0x03; 106 55 REG_BH(inreg) = page; … … 118 67 } 119 68 120 char getchar(void)121 {122 REG_AH(inreg) = 0x08;123 __intcall(0x21, &inreg, &outreg);124 return REG_AL(outreg);125 }126 127 69 void setvideomode(char mode) 128 70 { … … 130 72 REG_AL(inreg) = mode; 131 73 __intcall(0x10, &inreg, &outreg); 132 }133 134 unsigned char checkkbdbuf()135 {136 REG_AH(inreg) = 0x11;137 __intcall(0x16, &inreg, &outreg);138 return !(outreg.eflags.l & EFLAGS_ZF);139 74 } 140 75 -
com32/cmenu/libmenu/com32io.h
r0b19ab r9df342 15 15 16 16 #include <com32.h> 17 #include <stdio.h> 18 #include <libansi.h> 17 19 18 20 #ifndef NULL … … 20 22 #endif 21 23 24 /* Bits representing ShiftFlags, See Int16/Function 2 or Mem[0x417] to get this info */ 25 26 #define INSERT_ON (1<<7) 27 #define CAPSLOCK_ON (1<<6) 28 #define NUMLOCK_ON (1<<5) 29 #define SCRLLOCK_ON (1<<4) 30 #define ALT_PRESSED (1<<3) 31 #define CTRL_PRESSED (1<<2) 32 // actually 1<<1 is Left Shift, 1<<0 is right shift 33 #define SHIFT_PRESSED (1<<1 | 1 <<0) 34 22 35 /* BIOS Assisted output routines */ 23 24 void cswprint(const char *str, char attr, char left);25 // Print a C str (NUL-terminated) respecting the left edge of window26 // i.e. \n in str will move cursor to column left27 // Print a C str (NUL-terminated)28 29 static inline void csprint(const char *str, char attr)30 {31 cswprint(str, attr, 0);32 }33 34 void cprint(char chr, char attr, unsigned int times, char disppage); // Print a char35 36 void setdisppage(char num); // Set the display page to specified number37 38 char getdisppage(); // Get current display page39 40 void gotoxy(char row, char col, char page);41 36 42 37 void getpos(char *row, char *col, char page); 43 38 44 39 char inputc(char *scancode); // Return ASCII char by val, and scancode by reference 45 46 static inline void putch(char x, char attr, char page)47 {48 cprint(x, attr, 1, page);49 }50 40 51 41 void setcursorshape(char start, char end); // Set cursor shape … … 55 45 unsigned char getcharat(char page); 56 46 57 static inline void cursoroff(void)58 { /* Turns off cursor */59 setcursorshape(32, 33);60 }61 62 static inline void cursoron(void)63 { /* Turns on cursor */64 setcursorshape(6, 7);65 }66 67 47 static inline unsigned char readbiosb(unsigned int ofs) 68 48 { 69 49 return *((unsigned char *)MK_PTR(0, ofs)); 70 }71 72 static inline char getnumrows()73 {74 return readbiosb(0x484)+1; // Actually numrows - 175 }76 77 static inline char getnumcols(void)78 {79 return readbiosb(0x44a); // Actually numcols80 50 } 81 51 … … 86 56 87 57 void scrollupwindow(char top, char left, char bot, char right, char attr, char numlines); //Scroll up given window 88 89 static inline void scrollup(void) //Scroll up display screen by one line90 {91 scrollupwindow(0, 0, getnumrows(), getnumcols(), 0x07, 1);92 }93 58 94 59 void setvideomode(char mode); // Set the video mode. … … 101 66 unsigned char sleep(unsigned int msec); // Sleep for specified time 102 67 103 void beep(); // A Bell104 105 unsigned char checkkbdbuf(); // Check to see if there is kbd buffer is non-empty?106 107 static inline void clearkbdbuf() // Clear the kbd buffer (how many chars removed?)108 {109 while (checkkbdbuf())110 inputc(NULL);111 }112 113 68 #endif -
com32/cmenu/libmenu/help.c
rd8b2ee r1913ab 17 17 #include <syslinux/loadfile.h> // to read entire file into memory 18 18 19 int nc, nr; // Number of columns/rows of the screen 19 20 char helpbasedir[HELPDIRLEN]; // name of help directory limited to HELPDIRLEN 20 21 21 22 // Find the occurence of the count'th \n in buffer (or NULL) if not found 22 char *findline(char *buffer, int count)23 static char *findline(char *buffer, int count) 23 24 { 24 25 int ctr; … … 36 37 37 38 // return the number of lines in buffer 38 int countlines(char *buffer)39 static int countlines(char *buffer) 39 40 { 40 41 int ans; … … 51 52 52 53 // Print numlines of text starting from buf 53 void printtext(char *buf, int from)54 { 55 char * p, *f;56 char right, bot, nlines;54 static void printtext(char *buf, int from) 55 { 56 char *f, *t; 57 int right, nlines, i; 57 58 58 59 // clear window to print 59 right = getnumcols() - HELP_RIGHT_MARGIN; 60 bot = getnumrows() - HELP_BOTTOM_MARGIN; 61 nlines = bot - HELP_BODY_ROW + 1; 62 scrollupwindow(HELP_BODY_ROW, HELP_LEFT_MARGIN, bot, right, 0x07, nlines); 60 right = nc - HELP_RIGHT_MARGIN; 61 nlines = nr - HELP_BODY_ROW - HELP_BOTTOM_MARGIN - 1; 63 62 64 63 f = findline(buf, from); … … 67 66 if (*f == '\n') 68 67 f++; // start of from+1st line 69 p = findline(f, nlines); 70 if (p && (*p == '\n')) 71 *p = '\0'; // change to NUL 72 gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); 73 cswprint(f, 0x07, HELP_LEFT_MARGIN); 74 if (p) 75 *p = '\n'; // set it back 68 t = f; 69 while (i < nlines) { 70 gotoxy(HELP_BODY_ROW + i, HELP_LEFT_MARGIN); 71 clear_end_of_line(); 72 putchar(SO); 73 gotoxy(HELP_BODY_ROW + i, nc - 1); 74 putch(LEFT_BORDER, 0x07); 75 putchar(SI); 76 77 gotoxy(HELP_BODY_ROW + i, HELP_LEFT_MARGIN); 78 while (*t != '\n') { 79 if (*t == '\0') 80 return; 81 putchar(*t); 82 t++; 83 } 84 putchar('\n'); 85 t++; 86 i++; 87 } 76 88 } 77 89 78 90 void showhelp(const char *filename) 79 91 { 80 char nc, nr,ph;92 char ph; 81 93 char *title, *text; 82 94 union { … … 87 99 char line[512]; 88 100 size_t size; 89 charscan;101 int scan; 90 102 int rv, numlines, curr_line; 91 103 92 nc = getnumcols(); 93 nr = getnumrows(); 94 ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1; 104 if (getscreensize(1, &nr, &nc)) { 105 /* Unknown screen size? */ 106 nc = 80; 107 nr = 24; 108 } 109 ph = nr - HELP_BODY_ROW; 95 110 cls(); 96 drawbox(0, 0, nr, nc - 1, HELPPAGE, 0x07, HELPBOX); 97 98 drawhorizline(2, 0, nc - 1, HELPPAGE, 0x07, HELPBOX, 0); // dumb==0 111 112 /* Turn autowrap off, to avoid scrolling the menu */ 113 printf(CSI "?7l"); 114 99 115 if (filename == NULL) { // print file contents 100 gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); 101 cswprint("Filename not given", 0x07, HELP_LEFT_MARGIN); 102 while (1) { 103 inputc(&scan); 104 if (scan == ESCAPE) 105 break; 106 } 107 cls(); 108 return; 116 strcpy(line, "Filename not given"); 117 goto puke; 109 118 } 110 119 111 120 rv = loadfile(filename, (void **)&buf.vbuf, &size); // load entire file into memory 112 121 if (rv < 0) { // Error reading file or no such file 113 sprintf(line, "Error reading file or file not found\n file=%s", 114 filename); 115 gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN, HELPPAGE); 116 cswprint(line, 0x07, HELP_LEFT_MARGIN); 117 while (1) { 118 inputc(&scan); 119 if (scan == ESCAPE) 120 break; 121 } 122 cls(); 123 return; 122 sprintf(line, "Error reading file or file not found\n file=%s", filename); 123 goto puke; 124 124 } 125 125 … … 129 129 130 130 // Now we have a file just print it. 131 gotoxy(1, (nc - strlen(title)) / 2, HELPPAGE);132 csprint(title, 0x07);133 131 numlines = countlines(text); 134 132 curr_line = 0; 135 scan = ESCAPE + 1; // anything except ESCAPE 136 137 while (scan != ESCAPE) { 133 scan = KEY_ESC + 1; // anything except ESCAPE 134 135 /* top, left, bottom, right, attr */ 136 drawbox(0, 0, nr - 1, nc - 1, 0x07); 137 while (scan != KEY_ESC) { 138 /* Title */ 139 gotoxy(1, (nc - strlen(title)) / 2); 140 fputs(title, stdout); 141 drawhorizline(2, HELP_LEFT_MARGIN - 1, nc - HELP_RIGHT_MARGIN, 0x07, 0); // dumb==0 142 /* Text */ 138 143 printtext(text, curr_line); 139 gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);144 gotoxy(HELP_BODY_ROW - 1, nc - HELP_RIGHT_MARGIN); 140 145 if (curr_line > 0) 141 putch (HELP_MORE_ABOVE, 0x07, HELPPAGE);146 putchar(HELP_MORE_ABOVE); 142 147 else 143 putch (' ', 0x07, HELPPAGE);144 gotoxy(nr - HELP_BOTTOM_MARGIN + 1, nc - HELP_RIGHT_MARGIN, HELPPAGE);148 putchar(' '); 149 gotoxy(nr - HELP_BOTTOM_MARGIN - 1, nc - HELP_RIGHT_MARGIN); 145 150 if (curr_line < numlines - ph) 146 putch (HELP_MORE_BELOW, 0x07, HELPPAGE);151 putchar(HELP_MORE_BELOW); 147 152 else 148 putch (' ', 0x07, HELPPAGE);149 150 inputc(&scan);// wait for user keypress153 putchar(' '); 154 155 scan = get_key(stdout, 0); // wait for user keypress 151 156 152 157 switch (scan) { 153 case HOMEKEY:158 case KEY_HOME: 154 159 curr_line = 0; 155 160 break; 156 case ENDKEY:161 case KEY_END: 157 162 curr_line = numlines; 158 163 break; 159 case UPARROW:164 case KEY_UP: 160 165 curr_line--; 161 166 break; 162 case DNARROW:167 case KEY_DOWN: 163 168 curr_line++; 164 169 break; 165 case PAGEUP:170 case KEY_PGUP: 166 171 curr_line -= ph; 167 172 break; 168 case PAGEDN:173 case KEY_PGDN: 169 174 curr_line += ph; 170 175 break; … … 177 182 curr_line = 0; 178 183 } 184 out: 179 185 cls(); 180 186 return; 187 188 puke: 189 gotoxy(HELP_BODY_ROW, HELP_LEFT_MARGIN); 190 fputs(line, stdout); 191 while (1) { 192 scan = get_key(stdin, 0); 193 if (scan == KEY_ESC) 194 break; 195 } 196 goto out; 181 197 } 182 198 183 199 void runhelp(const char *filename) 184 200 { 185 char dp;186 201 char fullname[HELPDIRLEN + 16]; 187 202 188 dp = getdisppage(); 189 if (dp != HELPPAGE) 190 setdisppage(HELPPAGE); 203 cls(); 191 204 cursoroff(); 192 205 if (helpbasedir[0] != 0) { … … 197 210 } else 198 211 showhelp(filename); // Assume filename is absolute 199 if (dp != HELPPAGE)200 setdisppage(dp);201 212 } 202 213 … … 205 216 char filename[15]; 206 217 207 sprintf(filename, "hlp% 5d.txt", helpid);218 sprintf(filename, "hlp%05d.txt", helpid); 208 219 runhelp(filename); 209 220 } -
com32/cmenu/libmenu/help.h
r610468 r9dbacd3 24 24 #define HELP_LEFT_MARGIN 2 25 25 #define HELP_RIGHT_MARGIN 2 // Assume all lines dont cross this 26 #define HELP_BOTTOM_MARGIN 2// Number of lines not use from bottom of screen26 #define HELP_BOTTOM_MARGIN 1 // Number of lines not use from bottom of screen 27 27 28 28 #define HELPBOX BOX_SINSIN … … 30 30 #define HELPPAGE 2 31 31 32 #define HELP_MORE_ABOVE 24// to print when more is available above33 #define HELP_MORE_BELOW 25// same as above but for below32 #define HELP_MORE_ABOVE '^' // to print when more is available above 33 #define HELP_MORE_BELOW 'v' // same as above but for below 34 34 35 35 // Display one screen of help information -
com32/cmenu/libmenu/menu.c
r204ff3 r397586 14 14 #include "com32io.h" 15 15 #include <stdlib.h> 16 #include <console.h> 16 17 17 18 // Local Variables 18 static pt_menusystem ms; // Pointer to the menusystem19 static pt_menusystem ms; // Pointer to the menusystem 19 20 char TITLESTR[] = 20 21 "COMBOOT Menu System for SYSLINUX developed by Murali Krishnan Ganapathy"; … … 40 41 // and calls it when needed. For the callee, there is no difference 41 42 // as this will not return unless a key has been pressed. 42 char getch(char *scan) 43 { 43 static int getch() 44 { 45 t_timeout_handler th; 46 int key; 44 47 unsigned long i; 45 TIMEOUTCODE c;46 t_timeout_handler th;47 48 48 49 // Wait until keypress if no handler specified 49 50 if ((ms->ontimeout == NULL) && (ms->ontotaltimeout == NULL)) 50 return inputc(scan);51 return get_key(stdin, 0); 51 52 52 53 th = ms->ontimeout; 53 while (1) // Forever do 54 { 55 for (i = 0; i < ms->tm_numsteps; i++) { 56 if (checkkbdbuf()) 57 return inputc(scan); 58 sleep(ms->tm_stepsize); 59 if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL)) 60 continue; // Dont bother with calculations if no handler 61 ms->tm_sofar_timeout += ms->tm_stepsize; 62 if (ms->tm_sofar_timeout >= ms->tm_total_timeout) { 63 th = ms->ontotaltimeout; 64 ms->tm_sofar_timeout = 0; 65 break; // Get out of the for loop 66 } 67 } 68 if (!th) 69 continue; // no handler dont call 70 c = th(); 71 switch (c) { 72 case CODE_ENTER: // Pretend user hit enter 73 *scan = ENTERA; 74 return '\015'; // \015 octal = 13 75 case CODE_ESCAPE: // Pretend user hit escape 76 *scan = ESCAPE; 77 return '\033'; // \033 octal = 27 78 default: 79 break; 80 } 81 } 82 return 0; 83 } 84 85 /* Print a menu item */ 86 /* attr[0] is non-hilite attr, attr[1] is highlight attr */ 87 void printmenuitem(const char *str, uchar * attr) 88 { 89 uchar page = getdisppage(); 90 uchar row, col; 91 int hlite = NOHLITE; // Initially no highlighting 92 93 getpos(&row, &col, page); 94 while (*str) { 95 switch (*str) { 96 case '\b': 97 --col; 98 break; 99 case '\n': 100 ++row; 101 break; 102 case '\r': 103 col = 0; 104 break; 105 case BELL: // No Bell Char 106 break; 107 case ENABLEHLITE: // Switch on highlighting 108 hlite = HLITE; 109 break; 110 case DISABLEHLITE: // Turn off highlighting 111 hlite = NOHLITE; 112 break; 113 default: 114 putch(*str, attr[hlite], page); 115 ++col; 116 } 117 if (col > getnumcols()) { 118 ++row; 119 col = 0; 120 } 121 if (row > getnumrows()) { 122 scrollup(); 123 row = getnumrows(); 124 } 125 gotoxy(row, col, page); 126 str++; 127 } 54 for (;;) { 55 for (i = 0; i < ms->tm_numsteps; i++) { 56 key = get_key(stdin, ms->tm_stepsize); 57 if (key != KEY_NONE) 58 return key; 59 60 if ((ms->tm_total_timeout == 0) || (ms->ontotaltimeout == NULL)) 61 continue; // Dont bother with calculations if no handler 62 ms->tm_sofar_timeout += ms->tm_stepsize; 63 if (ms->tm_sofar_timeout >= ms->tm_total_timeout) { 64 th = ms->ontotaltimeout; 65 ms->tm_sofar_timeout = 0; 66 break; // Get out of the for loop 67 } 68 } 69 if (!th) 70 continue; // no handler 71 key = th(); 72 switch (key) { 73 case CODE_ENTER: // Pretend user hit enter 74 return KEY_ENTER; 75 case CODE_ESCAPE: // Pretend user hit escape 76 return KEY_ESC; 77 default: 78 break; 79 } 80 } 81 return KEY_NONE; 128 82 } 129 83 … … 136 90 // Garbage in garbage out 137 91 if ((index < 0) || (index >= menu->numitems)) 138 return index;92 return index; 139 93 ans = index + 1; 140 94 // Go till end of menu 141 95 while (ans < menu->numitems) { 142 mi = menu->items[ans];143 if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP)144 || (mi->shortcut != shortcut))145 ans++;146 else147 return ans;96 mi = menu->items[ans]; 97 if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) 98 || (mi->shortcut != shortcut)) 99 ans++; 100 else 101 return ans; 148 102 } 149 103 // Start at the beginning and try again 150 104 ans = 0; 151 105 while (ans < index) { 152 mi = menu->items[ans]; 153 if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) 154 || (mi->shortcut != shortcut)) 155 ans++; 156 else 157 return ans; 158 } 159 return index; // Sorry not found 106 mi = menu->items[ans]; 107 if ((mi->action == OPT_INVISIBLE) || (mi->action == OPT_SEP) 108 || (mi->shortcut != shortcut)) 109 ans++; 110 else 111 return ans; 112 } 113 return index; // Sorry not found 114 } 115 116 /* Redraw background and title */ 117 static void reset_ui(void) 118 { 119 uchar tpos; 120 121 cls(); 122 clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol, 123 ms->fillchar, ms->fillattr); 124 125 tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line 126 gotoxy(ms->minrow, ms->mincol); 127 cprint(ms->tfillchar, ms->titleattr, ms->numcols); 128 gotoxy(ms->minrow, ms->mincol + tpos); 129 csprint(ms->title, ms->titleattr); 130 131 cursoroff(); 132 } 133 134 /* 135 * Print a menu item 136 * 137 * attr[0] is non-hilite attr, attr[1] is highlight attr 138 */ 139 void printmenuitem(const char *str, uchar * attr) 140 { 141 int hlite = NOHLITE; // Initially no highlighting 142 143 while (*str) { 144 switch (*str) { 145 case BELL: // No Bell Char 146 break; 147 case ENABLEHLITE: // Switch on highlighting 148 hlite = HLITE; 149 break; 150 case DISABLEHLITE: // Turn off highlighting 151 hlite = NOHLITE; 152 break; 153 default: 154 putch(*str, attr[hlite]); 155 } 156 str++; 157 } 158 } 159 160 161 /** 162 * print_line - Print a whole line in a menu 163 * @menu: current menu to handle 164 * @curr: index of the current entry highlighted 165 * @top: top coordinate of the @menu 166 * @left: left coordinate of the @menu 167 * @x: index in the menu of curr 168 * @row: row currently displayed 169 * @radio: radio item? 170 **/ 171 static void print_line(pt_menu menu, int curr, uchar top, uchar left, 172 int x, int row, bool radio) 173 { 174 pt_menuitem ci; 175 char fchar[6], lchar[6]; // The first and last char in for each entry 176 const char *str; // Item string (cf printmenuitem) 177 char sep[MENULEN]; // Separator (OPT_SEP) 178 uchar *attr; // Attribute 179 int menuwidth = menu->menuwidth + 3; 180 181 if (row >= menu->menuheight) 182 return; 183 184 ci = menu->items[x]; 185 186 memset(sep, ms->box_horiz, menuwidth); 187 sep[menuwidth - 1] = 0; 188 189 // Setup the defaults now 190 if (radio) { 191 fchar[0] = '\b'; 192 fchar[1] = SO; 193 fchar[2] = (x == curr ? RADIOSEL : RADIOUNSEL); 194 fchar[3] = SI; 195 fchar[4] = '\0'; // Unselected ( ) 196 lchar[0] = '\0'; // Nothing special after 197 attr = ms->normalattr; // Always same attribute 198 } else { 199 lchar[0] = fchar[0] = ' '; 200 lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces 201 attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes 202 } 203 str = ci->item; // Pointer to item string 204 switch (ci->action) // set up attr,str,fchar,lchar for everything 205 { 206 case OPT_INACTIVE: 207 if (radio) 208 attr = ms->inactattr; 209 else 210 attr = (x == curr ? ms->revinactattr : ms->inactattr); 211 break; 212 case OPT_SUBMENU: 213 if (radio) 214 break; // Not supported for radio menu 215 lchar[0] = '>'; 216 lchar[1] = 0; 217 break; 218 case OPT_RADIOMENU: 219 if (radio) 220 break; // Not supported for radio menu 221 lchar[0] = RADIOMENUCHAR; 222 lchar[1] = 0; 223 break; 224 case OPT_CHECKBOX: 225 if (radio) 226 break; // Not supported for radio menu 227 lchar[0] = '\b'; 228 lchar[1] = SO; 229 lchar[2] = (ci->itemdata.checked ? CHECKED : UNCHECKED); 230 lchar[3] = SI; 231 lchar[4] = 0; 232 break; 233 case OPT_SEP: 234 fchar[0] = '\b'; 235 fchar[1] = SO; 236 fchar[2] = LEFT_MIDDLE_BORDER; 237 fchar[3] = MIDDLE_BORDER; 238 fchar[4] = MIDDLE_BORDER; 239 fchar[5] = 0; 240 memset(sep, MIDDLE_BORDER, menuwidth); 241 sep[menuwidth - 1] = 0; 242 str = sep; 243 lchar[0] = MIDDLE_BORDER; 244 lchar[1] = RIGHT_MIDDLE_BORDER; 245 lchar[2] = SI; 246 lchar[3] = 0; 247 break; 248 case OPT_EXITMENU: 249 if (radio) 250 break; // Not supported for radio menu 251 fchar[0] = '<'; 252 fchar[1] = 0; 253 break; 254 default: // Just to keep the compiler happy 255 break; 256 } 257 258 // Wipe area with spaces 259 gotoxy(top + row, left - 2); 260 cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2); 261 262 // Print first part 263 gotoxy(top + row, left - 2); 264 csprint(fchar, attr[NOHLITE]); 265 266 // Print main part 267 gotoxy(top + row, left); 268 printmenuitem(str, attr); 269 270 // Print last part 271 gotoxy(top + row, left + menuwidth - 1); 272 csprint(lchar, attr[NOHLITE]); 160 273 } 161 274 162 275 // print the menu starting from FIRST 163 276 // will print a maximum of menu->menuheight items 164 void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first)165 { 166 int x, row; // x = index, row = position from top277 static void printmenu(pt_menu menu, int curr, uchar top, uchar left, uchar first, bool radio) 278 { 279 int x, row; // x = index, row = position from top 167 280 int numitems, menuwidth; 168 char fchar[5], lchar[5]; // The first and last char in for each entry169 const char *str; // and inbetween the item or a seperator is printed170 uchar *attr; // attribute attr171 char sep[MENULEN]; // and inbetween the item or a seperator is printed172 281 pt_menuitem ci; 173 282 174 283 numitems = calc_visible(menu, first); 175 284 if (numitems > menu->menuheight) 176 numitems = menu->menuheight;285 numitems = menu->menuheight; 177 286 178 287 menuwidth = menu->menuwidth + 3; 179 288 clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1, 180 ms->menupage,ms->fillchar, ms->shadowattr);289 ms->fillchar, ms->shadowattr); 181 290 drawbox(top - 1, left - 3, top + numitems, left + menuwidth, 182 ms->menupage, ms->normalattr[NOHLITE], ms->menubt); 183 memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string 184 sep[menuwidth - 1] = 0; 291 ms->normalattr[NOHLITE]); 292 185 293 // Menu title 186 294 x = (menuwidth - strlen(menu->title) - 1) >> 1; 187 gotoxy(top - 1, left + x , ms->menupage);295 gotoxy(top - 1, left + x); 188 296 printmenuitem(menu->title, ms->normalattr); 189 row = -1; // 1 less than inital value of x 297 298 // All lines in the menu 299 row = -1; // 1 less than inital value of x 190 300 for (x = first; x < menu->numitems; x++) { 191 ci = menu->items[x]; 192 if (ci->action == OPT_INVISIBLE) 193 continue; 194 row++; 195 if (row >= numitems) 196 break; // Already have enough number of items 197 // Setup the defaults now 198 lchar[0] = fchar[0] = ' '; 199 lchar[1] = fchar[1] = '\0'; // fchar and lchar are just spaces 200 str = ci->item; // Pointer to item string 201 attr = (x == curr ? ms->reverseattr : ms->normalattr); // Normal attributes 202 switch (ci->action) // set up attr,str,fchar,lchar for everything 203 { 204 case OPT_INACTIVE: 205 attr = (x == curr ? ms->revinactattr : ms->inactattr); 206 break; 207 case OPT_SUBMENU: 208 lchar[0] = SUBMENUCHAR; 209 lchar[1] = 0; 210 break; 211 case OPT_RADIOMENU: 212 lchar[0] = RADIOMENUCHAR; 213 lchar[1] = 0; 214 break; 215 case OPT_CHECKBOX: 216 lchar[0] = (ci->itemdata.checked ? CHECKED : UNCHECKED); 217 lchar[1] = 0; 218 break; 219 case OPT_SEP: 220 fchar[0] = '\b'; 221 fchar[1] = ms->box_ltrt; 222 fchar[2] = ms->box_horiz; 223 fchar[3] = ms->box_horiz; 224 fchar[4] = 0; 225 lchar[0] = ms->box_horiz; 226 lchar[1] = ms->box_rtlt; 227 lchar[2] = 0; 228 str = sep; 229 break; 230 case OPT_EXITMENU: 231 fchar[0] = EXITMENUCHAR; 232 fchar[1] = 0; 233 break; 234 default: // Just to keep the compiler happy 235 break; 236 } 237 gotoxy(top + row, left - 2, ms->menupage); 238 cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces 239 gotoxy(top + row, left - 2, ms->menupage); 240 csprint(fchar, attr[NOHLITE]); // Print first part 241 gotoxy(top + row, left, ms->menupage); 242 printmenuitem(str, attr); // Print main part 243 gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any 244 csprint(lchar, attr[NOHLITE]); // Print last part 301 ci = menu->items[x]; 302 if (ci->action == OPT_INVISIBLE) 303 continue; 304 row++; 305 if (row >= numitems) 306 break; // Already have enough number of items 307 print_line(menu, curr, top, left, x, row, radio); 245 308 } 246 309 // Check if we need to MOREABOVE and MOREBELOW to be added 247 310 // reuse x 248 311 row = 0; 249 x = next_visible_sep(menu, 0); // First item250 if (!isvisible(menu, first, x)) // There is more above312 x = next_visible_sep(menu, 0); // First item 313 if (!isvisible(menu, first, x)) // There is more above 251 314 { 252 row = 1;253 gotoxy(top, left + menuwidth, ms->menupage);254 cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage);255 } 256 x = prev_visible_sep(menu, menu->numitems); // last item257 if (!isvisible(menu, first, x)) // There is more above315 row = 1; 316 gotoxy(top, left + menuwidth); 317 cprint(MOREABOVE, ms->normalattr[NOHLITE], 1); 318 } 319 x = prev_visible_sep(menu, menu->numitems); // last item 320 if (!isvisible(menu, first, x)) // There is more above 258 321 { 259 row = 1;260 gotoxy(top + numitems - 1, left + menuwidth, ms->menupage);261 cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage);322 row = 1; 323 gotoxy(top + numitems - 1, left + menuwidth); 324 cprint(MOREBELOW, ms->normalattr[NOHLITE], 1); 262 325 } 263 326 // Add a scroll box 264 327 x = ((numitems - 1) * curr) / (menu->numitems); 265 328 if ((x > 0) && (row == 1)) { 266 gotoxy(top + x, left + menuwidth, ms->menupage);267 cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage);329 gotoxy(top + x, left + menuwidth); 330 csprint("\016\141\017", ms->normalattr[NOHLITE]); 268 331 } 269 332 if (ms->handler) 270 ms->handler(ms, menu->items[curr]); 271 } 272 273 // Difference between this and regular menu, is that only 274 // OPT_INVISIBLE, OPT_SEP are honoured 275 void printradiomenu(pt_menu menu, int curr, uchar top, uchar left, int first) 276 { 277 int x, row; // x = index, row = position from top 278 int numitems, menuwidth; 279 char fchar[5], lchar[5]; // The first and last char in for each entry 280 const char *str; // and inbetween the item or a seperator is printed 281 uchar *attr; // all in the attribute attr 282 char sep[MENULEN]; // and inbetween the item or a seperator is printed 283 pt_menuitem ci; 284 285 numitems = calc_visible(menu, first); 333 ms->handler(ms, menu->items[curr]); 334 } 335 336 void cleanupmenu(pt_menu menu, uchar top, uchar left, int numitems) 337 { 286 338 if (numitems > menu->menuheight) 287 numitems = menu->menuheight; 288 289 menuwidth = menu->menuwidth + 3; 290 clearwindow(top, left - 2, top + numitems + 1, left + menuwidth + 1, 291 ms->menupage, ms->fillchar, ms->shadowattr); 292 drawbox(top - 1, left - 3, top + numitems, left + menuwidth, 293 ms->menupage, ms->normalattr[NOHLITE], ms->menubt); 294 memset(sep, ms->box_horiz, menuwidth); // String containing the seperator string 295 sep[menuwidth - 1] = 0; 296 // Menu title 297 x = (menuwidth - strlen(menu->title) - 1) >> 1; 298 gotoxy(top - 1, left + x, ms->menupage); 299 printmenuitem(menu->title, ms->normalattr); 300 row = -1; // 1 less than inital value of x 301 for (x = first; x < menu->numitems; x++) { 302 ci = menu->items[x]; 303 if (ci->action == OPT_INVISIBLE) 304 continue; 305 row++; 306 if (row > numitems) 307 break; 308 // Setup the defaults now 309 fchar[0] = RADIOUNSEL; 310 fchar[1] = '\0'; // Unselected ( ) 311 lchar[0] = '\0'; // Nothing special after 312 str = ci->item; // Pointer to item string 313 attr = ms->normalattr; // Always same attribute 314 fchar[0] = (x == curr ? RADIOSEL : RADIOUNSEL); 315 switch (ci->action) // set up attr,str,fchar,lchar for everything 316 { 317 case OPT_INACTIVE: 318 attr = ms->inactattr; 319 break; 320 case OPT_SEP: 321 fchar[0] = '\b'; 322 fchar[1] = ms->box_ltrt; 323 fchar[2] = ms->box_horiz; 324 fchar[3] = ms->box_horiz; 325 fchar[4] = 0; 326 lchar[0] = ms->box_horiz; 327 lchar[1] = ms->box_rtlt; 328 lchar[3] = 0; 329 str = sep; 330 break; 331 default: // To keep the compiler happy 332 break; 333 } 334 gotoxy(top + row, left - 2, ms->menupage); 335 cprint(ms->spacechar, attr[NOHLITE], menuwidth + 2, ms->menupage); // Wipe area with spaces 336 gotoxy(top + row, left - 2, ms->menupage); 337 csprint(fchar, attr[NOHLITE]); // Print first part 338 gotoxy(top + row, left, ms->menupage); 339 printmenuitem(str, attr); // Print main part 340 gotoxy(top + row, left + menuwidth - 1, ms->menupage); // Last char if any 341 csprint(lchar, attr[NOHLITE]); // Print last part 342 } 343 // Check if we need to MOREABOVE and MOREBELOW to be added 344 // reuse x 345 row = 0; 346 x = next_visible_sep(menu, 0); // First item 347 if (!isvisible(menu, first, x)) // There is more above 348 { 349 row = 1; 350 gotoxy(top, left + menuwidth, ms->menupage); 351 cprint(MOREABOVE, ms->normalattr[NOHLITE], 1, ms->menupage); 352 } 353 x = prev_visible_sep(menu, menu->numitems); // last item 354 if (!isvisible(menu, first, x)) // There is more above 355 { 356 row = 1; 357 gotoxy(top + numitems - 1, left + menuwidth, ms->menupage); 358 cprint(MOREBELOW, ms->normalattr[NOHLITE], 1, ms->menupage); 359 } 360 // Add a scroll box 361 x = ((numitems - 1) * curr) / (menu->numitems); 362 if ((x > 0) && (row == 1)) { 363 gotoxy(top + x, left + menuwidth, ms->menupage); 364 cprint(SCROLLBOX, ms->normalattr[NOHLITE], 1, ms->menupage); 365 } 366 if (ms->handler) 367 ms->handler(ms, menu->items[curr]); 368 } 369 370 void cleanupmenu(pt_menu menu, uchar top, uchar left, int numitems) 371 { 372 if (numitems > menu->menuheight) 373 numitems = menu->menuheight; 374 clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->menupage, ms->fillchar, ms->fillattr); // Clear the shadow 375 clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->menupage, ms->fillchar, ms->fillattr); // main window 376 } 377 378 /* Handle a radio menu */ 379 pt_menuitem getradiooption(pt_menu menu, uchar top, uchar left, uchar startopt) 339 numitems = menu->menuheight; 340 clearwindow(top, left - 2, top + numitems + 1, left + menu->menuwidth + 4, ms->fillchar, ms->fillattr); // Clear the shadow 341 clearwindow(top - 1, left - 3, top + numitems, left + menu->menuwidth + 3, ms->fillchar, ms->fillattr); // main window 342 } 343 344 345 /* Handle one menu */ 346 static pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar startopt, bool radio) 380 347 // Return item chosen or NULL if ESC was hit. 381 348 { 382 int curr, i, first, tmp; 383 uchar asc, scan; 349 int prev, prev_first, curr, i, first, tmp; 350 int asc = 0; 351 bool redraw = true; // Need to draw the menu the first time 384 352 uchar numitems; 385 pt_menuitem ci; // Current item 353 pt_menuitem ci; // Current item 354 t_handler_return hr; // Return value of handler 386 355 387 356 numitems = calc_visible(menu, 0); 388 357 // Setup status line 389 gotoxy(ms->minrow + ms->statline, ms->mincol , ms->menupage);390 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols , ms->menupage);358 gotoxy(ms->minrow + ms->statline, ms->mincol); 359 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols); 391 360 392 361 // Initialise current menu item 393 362 curr = next_visible(menu, startopt); 394 395 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 396 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1); 397 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 363 prev = curr; 364 365 gotoxy(ms->minrow + ms->statline, ms->mincol); 366 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols); 367 gotoxy(ms->minrow + ms->statline, ms->mincol); 398 368 printmenuitem(menu->items[curr]->status, ms->statusattr); 399 369 first = calc_first_early(menu, curr); 400 while (1) // Forever 370 prev_first = first; 371 while (1) // Forever 401 372 { 402 printradiomenu(menu, curr, top, left, first); 403 ci = menu->items[curr]; 404 405 asc = getch(&scan); 406 switch (scan) { 407 case HOMEKEY: 408 curr = next_visible(menu, 0); 409 first = calc_first_early(menu, curr); 410 break; 411 case ENDKEY: 412 curr = prev_visible(menu, numitems - 1); 413 first = calc_first_late(menu, curr); 414 break; 415 case PAGEDN: 416 for (i = 0; i < 5; i++) 417 curr = next_visible(menu, curr + 1); 418 first = calc_first_late(menu, curr); 419 break; 420 case PAGEUP: 421 for (i = 0; i < 5; i++) 422 curr = prev_visible(menu, curr - 1); 423 first = calc_first_early(menu, curr); 424 break; 425 case UPARROW: 426 curr = prev_visible(menu, curr - 1); 427 if (curr < first) 428 first = calc_first_early(menu, curr); 429 break; 430 case DNARROW: 431 curr = next_visible(menu, curr + 1); 432 if (!isvisible(menu, first, curr)) 433 first = calc_first_late(menu, curr); 434 break; 435 case LTARROW: 436 case ESCAPE: 437 return NULL; 438 break; 439 case RTARROW: 440 case ENTERA: 441 case ENTERB: 442 if (ci->action == OPT_INACTIVE) 443 break; 444 if (ci->action == OPT_SEP) 445 break; 446 return ci; 447 break; 448 default: 449 // Check if this is a shortcut key 450 if (((asc >= 'A') && (asc <= 'Z')) || 451 ((asc >= 'a') && (asc <= 'z')) || 452 ((asc >= '0') && (asc <= '9'))) { 453 tmp = find_shortcut(menu, asc, curr); 454 if ((tmp > curr) && (!isvisible(menu, first, tmp))) 455 first = calc_first_late(menu, tmp); 456 if (tmp < curr) 457 first = calc_first_early(menu, tmp); 458 curr = tmp; 459 } else { 460 if (ms->keys_handler) // Call extra keys handler 461 ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc); 462 } 463 break; 464 } 465 // Update status line 466 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 467 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 468 ms->menupage); 469 printmenuitem(menu->items[curr]->status, ms->statusattr); 470 } 471 return NULL; // Should never come here 472 } 473 474 /* Handle one menu */ 475 pt_menuitem getmenuoption(pt_menu menu, uchar top, uchar left, uchar startopt) 476 // Return item chosen or NULL if ESC was hit. 477 { 478 int curr, i, first, tmp; 479 uchar asc, scan; 480 uchar numitems; 481 pt_menuitem ci; // Current item 482 t_handler_return hr; // Return value of handler 483 484 numitems = calc_visible(menu, 0); 485 // Setup status line 486 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 487 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, ms->menupage); 488 489 // Initialise current menu item 490 curr = next_visible(menu, startopt); 491 492 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 493 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 1); 494 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 373 /* Redraw everything if: 374 * + we need to scroll (take care of scroll bars, ...) 375 * + menuoption 376 */ 377 if (prev_first != first || redraw) { 378 printmenu(menu, curr, top, left, first, radio); 379 } else { 380 /* Redraw only the highlighted entry */ 381 print_line(menu, curr, top, left, prev, prev - first, radio); 382 print_line(menu, curr, top, left, curr, curr - first, radio); 383 } 384 redraw = false; 385 prev = curr; 386 prev_first = first; 387 ci = menu->items[curr]; 388 asc = getch(); 389 switch (asc) { 390 case KEY_CTRL('L'): 391 redraw = true; 392 break; 393 case KEY_HOME: 394 curr = next_visible(menu, 0); 395 first = calc_first_early(menu, curr); 396 break; 397 case KEY_END: 398 curr = prev_visible(menu, numitems - 1); 399 first = calc_first_late(menu, curr); 400 break; 401 case KEY_PGDN: 402 for (i = 0; i < 5; i++) 403 curr = next_visible(menu, curr + 1); 404 first = calc_first_late(menu, curr); 405 break; 406 case KEY_PGUP: 407 for (i = 0; i < 5; i++) 408 curr = prev_visible(menu, curr - 1); 409 first = calc_first_early(menu, curr); 410 break; 411 case KEY_UP: 412 curr = prev_visible(menu, curr - 1); 413 if (curr < first) 414 first = calc_first_early(menu, curr); 415 break; 416 case KEY_DOWN: 417 curr = next_visible(menu, curr + 1); 418 if (!isvisible(menu, first, curr)) 419 first = calc_first_late(menu, curr); 420 break; 421 case KEY_LEFT: 422 case KEY_ESC: 423 return NULL; 424 break; 425 case KEY_RIGHT: 426 case KEY_ENTER: 427 if (ci->action == OPT_INACTIVE) 428 break; 429 if (ci->action == OPT_CHECKBOX) 430 break; 431 if (ci->action == OPT_SEP) 432 break; 433 if (ci->action == OPT_EXITMENU) 434 return NULL; // As if we hit Esc 435 // If we are going into a radio menu, dont call handler, return ci 436 if (ci->action == OPT_RADIOMENU) 437 return ci; 438 if (ci->handler != NULL) // Do we have a handler 439 { 440 hr = ci->handler(ms, ci); 441 if (hr.refresh) // Do we need to refresh 442 { 443 // Cleanup menu using old number of items 444 cleanupmenu(menu, top, left, numitems); 445 // Recalculate the number of items 446 numitems = calc_visible(menu, 0); 447 // Reprint the menu 448 printmenu(menu, curr, top, left, first, radio); 449 } 450 if (hr.valid) 451 return ci; 452 } else 453 return ci; 454 break; 455 case SPACECHAR: 456 if (ci->action != OPT_CHECKBOX) 457 break; 458 ci->itemdata.checked = !ci->itemdata.checked; 459 if (ci->handler != NULL) // Do we have a handler 460 { 461 hr = ci->handler(ms, ci); 462 if (hr.refresh) // Do we need to refresh 463 { 464 // Cleanup menu using old number of items 465 cleanupmenu(menu, top, left, numitems); 466 // Recalculate the number of items 467 numitems = calc_visible(menu, 0); 468 // Reprint the menu 469 printmenu(menu, curr, top, left, first, radio); 470 } 471 } 472 break; 473 default: 474 // Check if this is a shortcut key 475 if (((asc >= 'A') && (asc <= 'Z')) || 476 ((asc >= 'a') && (asc <= 'z')) || 477 ((asc >= '0') && (asc <= '9'))) { 478 tmp = find_shortcut(menu, asc, curr); 479 if ((tmp > curr) && (!isvisible(menu, first, tmp))) 480 first = calc_first_late(menu, tmp); 481 if (tmp < curr) 482 first = calc_first_early(menu, tmp); 483 curr = tmp; 484 } else { 485 if (ms->keys_handler) // Call extra keys handler 486 ms->keys_handler(ms, menu->items[curr], asc); 487 488 /* The handler may have changed the UI, reset it on exit */ 489 reset_ui(); 490 // Cleanup menu using old number of items 491 cleanupmenu(menu, top, left, numitems); 492 // Recalculate the number of items 493 numitems = calc_visible(menu, 0); 494 // Reprint the menu 495 printmenu(menu, curr, top, left, first, radio); 496 } 497 break; 498 } 499 // Update status line 500 /* Erase the previous status */ 501 gotoxy(ms->minrow + ms->statline, ms->mincol); 502 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols); 503 /* Print the new status */ 504 gotoxy(ms->minrow + ms->statline, ms->mincol); 495 505 printmenuitem(menu->items[curr]->status, ms->statusattr); 496 first = calc_first_early(menu, curr); 497 while (1) // Forever 498 { 499 printmenu(menu, curr, top, left, first); 500 ci = menu->items[curr]; 501 asc = getch(&scan); 502 switch (scan) { 503 case HOMEKEY: 504 curr = next_visible(menu, 0); 505 first = calc_first_early(menu, curr); 506 break; 507 case ENDKEY: 508 curr = prev_visible(menu, numitems - 1); 509 first = calc_first_late(menu, curr); 510 break; 511 case PAGEDN: 512 for (i = 0; i < 5; i++) 513 curr = next_visible(menu, curr + 1); 514 first = calc_first_late(menu, curr); 515 break; 516 case PAGEUP: 517 for (i = 0; i < 5; i++) 518 curr = prev_visible(menu, curr - 1); 519 first = calc_first_early(menu, curr); 520 break; 521 case UPARROW: 522 curr = prev_visible(menu, curr - 1); 523 if (curr < first) 524 first = calc_first_early(menu, curr); 525 break; 526 case DNARROW: 527 curr = next_visible(menu, curr + 1); 528 if (!isvisible(menu, first, curr)) 529 first = calc_first_late(menu, curr); 530 break; 531 case LTARROW: 532 case ESCAPE: 533 return NULL; 534 break; 535 case RTARROW: 536 case ENTERA: 537 case ENTERB: 538 if (ci->action == OPT_INACTIVE) 539 break; 540 if (ci->action == OPT_CHECKBOX) 541 break; 542 if (ci->action == OPT_SEP) 543 break; 544 if (ci->action == OPT_EXITMENU) 545 return NULL; // As if we hit Esc 546 // If we are going into a radio menu, dont call handler, return ci 547 if (ci->action == OPT_RADIOMENU) 548 return ci; 549 if (ci->handler != NULL) // Do we have a handler 550 { 551 hr = ci->handler(ms, ci); 552 if (hr.refresh) // Do we need to refresh 553 { 554 // Cleanup menu using old number of items 555 cleanupmenu(menu, top, left, numitems); 556 // Recalculate the number of items 557 numitems = calc_visible(menu, 0); 558 // Reprint the menu 559 printmenu(menu, curr, top, left, first); 560 } 561 if (hr.valid) 562 return ci; 563 } else 564 return ci; 565 break; 566 case SPACEKEY: 567 if (ci->action != OPT_CHECKBOX) 568 break; 569 ci->itemdata.checked = !ci->itemdata.checked; 570 if (ci->handler != NULL) // Do we have a handler 571 { 572 hr = ci->handler(ms, ci); 573 if (hr.refresh) // Do we need to refresh 574 { 575 // Cleanup menu using old number of items 576 cleanupmenu(menu, top, left, numitems); 577 // Recalculate the number of items 578 numitems = calc_visible(menu, 0); 579 // Reprint the menu 580 printmenu(menu, curr, top, left, first); 581 } 582 } 583 break; 584 default: 585 // Check if this is a shortcut key 586 if (((asc >= 'A') && (asc <= 'Z')) || 587 ((asc >= 'a') && (asc <= 'z')) || 588 ((asc >= '0') && (asc <= '9'))) { 589 tmp = find_shortcut(menu, asc, curr); 590 if ((tmp > curr) && (!isvisible(menu, first, tmp))) 591 first = calc_first_late(menu, tmp); 592 if (tmp < curr) 593 first = calc_first_early(menu, tmp); 594 curr = tmp; 595 } else { 596 if (ms->keys_handler) // Call extra keys handler 597 ms->keys_handler(ms, menu->items[curr], (scan << 8) | asc); 598 } 599 break; 600 } 601 // Update status line 602 gotoxy(ms->minrow + ms->statline, ms->mincol, ms->menupage); 603 cprint(ms->spacechar, ms->statusattr[NOHLITE], ms->numcols, 604 ms->menupage); 605 printmenuitem(menu->items[curr]->status, ms->statusattr); 606 } 607 return NULL; // Should never come here 506 } 507 return NULL; // Should never come here 608 508 } 609 509 610 510 /* Handle the entire system of menu's. */ 611 511 pt_menuitem runmenusystem(uchar top, uchar left, pt_menu cmenu, uchar startopt, 612 uchar menutype)512 uchar menutype) 613 513 /* 614 514 * cmenu … … 630 530 631 531 if (cmenu == NULL) 632 return NULL; 532 return NULL; 533 633 534 startover: 634 535 // Set the menu height 635 536 cmenu->menuheight = ms->maxrow - top - 3; 636 537 if (cmenu->menuheight > ms->maxmenuheight) 637 cmenu->menuheight = ms->maxmenuheight;538 cmenu->menuheight = ms->maxmenuheight; 638 539 if (menutype == NORMALMENU) 639 opt = getmenuoption(cmenu, top, left, startopt);640 else // menutype == RADIOMENU641 opt = getradiooption(cmenu, top, left, startopt);540 opt = getmenuoption(cmenu, top, left, startopt, false); 541 else // menutype == RADIOMENU 542 opt = getmenuoption(cmenu, top, left, startopt, true); 642 543 643 544 if (opt == NULL) { 644 // User hit Esc645 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));646 return NULL;545 // User hit Esc 546 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); 547 return NULL; 647 548 } 648 549 // Are we done with the menu system? 649 550 if ((opt->action != OPT_SUBMENU) && (opt->action != OPT_RADIOMENU)) { 650 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));651 return opt;// parent cleanup other menus551 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); 552 return opt; // parent cleanup other menus 652 553 } 653 554 // Either radiomenu or submenu 654 555 // Do we have a valid menu number? The next hack uses the fact that 655 556 // itemdata.submenunum = itemdata.radiomenunum (since enum data type) 656 if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad....557 if (opt->itemdata.submenunum >= ms->nummenus) // This is Bad.... 657 558 { 658 gotoxy(12, 12, ms->menupage);// Middle of screen659 csprint("ERROR: Invalid submenu requested.", 0x07);660 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));661 return NULL;// Pretend user hit esc559 gotoxy(12, 12); // Middle of screen 560 csprint("ERROR: Invalid submenu requested.", 0x07); 561 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); 562 return NULL; // Pretend user hit esc 662 563 } 663 564 // Call recursively for submenu … … 667 568 col = ms->menus[(unsigned int)opt->itemdata.submenunum]->col; 668 569 if (row == 0xFF) 669 row = top + opt->index + 2;570 row = top + opt->index + 2; 670 571 if (col == 0xFF) 671 col = left + 3 + (cmenu->menuwidth >> 1);572 col = left + 3 + (cmenu->menuwidth >> 1); 672 573 mt = (opt->action == OPT_SUBMENU ? NORMALMENU : RADIOMENU); 673 574 startat = 0; 674 575 if ((opt->action == OPT_RADIOMENU) && (opt->data != NULL)) 675 startat = ((t_menuitem *) opt->data)->index;576 startat = ((t_menuitem *) opt->data)->index; 676 577 677 578 choice = runmenusystem(row, col, 678 ms->menus[(unsigned int)opt->itemdata.submenunum],679 startat, mt);579 ms->menus[(unsigned int)opt->itemdata.submenunum], 580 startat, mt); 680 581 if (opt->action == OPT_RADIOMENU) { 681 if (choice != NULL)682 opt->data = (void *)choice;// store choice in data field683 if (opt->handler != NULL)684 opt->handler(ms, opt);685 choice = NULL;// Pretend user hit esc686 } 687 if (choice == NULL) // User hit Esc in submenu582 if (choice != NULL) 583 opt->data = (void *)choice; // store choice in data field 584 if (opt->handler != NULL) 585 opt->handler(ms, opt); 586 choice = NULL; // Pretend user hit esc 587 } 588 if (choice == NULL) // User hit Esc in submenu 688 589 { 689 // Startover690 startopt = opt->index;691 goto startover;590 // Startover 591 startopt = opt->index; 592 goto startover; 692 593 } else { 693 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0));694 return choice;594 cleanupmenu(cmenu, top, left, calc_visible(cmenu, 0)); 595 return choice; 695 596 } 696 597 } … … 703 604 704 605 if (name == NULL) 705 return (uchar) (-1);606 return (uchar) (-1); 706 607 for (i = 0; i < ms->nummenus; i++) { 707 m = ms->menus[i];708 if ((m->name) && (strcmp(m->name, name) == 0))709 return i;608 m = ms->menus[i]; 609 if ((m->name) && (strcmp(m->name, name) == 0)) 610 return i; 710 611 } 711 612 return (uchar) (-1); … … 723 624 i = 0; 724 625 for (i = 0; i < ms->nummenus; i++) { 725 m = ms->menus[i];726 for (j = 0; j < m->numitems; j++) {727 mi = m->items[j];728 // if item is a submenu and has non-empty non-trivial data string729 if (mi->data && strlen(mi->data) > 0 &&730 ((mi->action == OPT_SUBMENU)731 || (mi->action == OPT_RADIOMENU))) {732 mi->itemdata.submenunum = find_menu_num(mi->data);733 }734 }626 m = ms->menus[i]; 627 for (j = 0; j < m->numitems; j++) { 628 mi = m->items[j]; 629 // if item is a submenu and has non-empty non-trivial data string 630 if (mi->data && strlen(mi->data) > 0 && 631 ((mi->action == OPT_SUBMENU) 632 || (mi->action == OPT_RADIOMENU))) { 633 mi->itemdata.submenunum = find_menu_num(mi->data); 634 } 635 } 735 636 } 736 637 } … … 741 642 { 742 643 pt_menuitem rv; 743 uchar oldpage, tpos; 744 745 fix_submenus(); // Fix submenu numbers incase nick names were used 644 645 fix_submenus(); // Fix submenu numbers incase nick names were used 646 647 /* Turn autowrap off, to avoid scrolling the menu */ 648 printf(CSI "?7l"); 746 649 747 650 // Setup screen for menusystem 748 oldpage = getdisppage(); 749 setdisppage(ms->menupage); 750 cls(); 751 clearwindow(ms->minrow, ms->mincol, ms->maxrow, ms->maxcol, 752 ms->menupage, ms->fillchar, ms->fillattr); 753 tpos = (ms->numcols - strlen(ms->title) - 1) >> 1; // center it on line 754 gotoxy(ms->minrow, ms->mincol, ms->menupage); 755 cprint(ms->tfillchar, ms->titleattr, ms->numcols, ms->menupage); 756 gotoxy(ms->minrow, ms->mincol + tpos, ms->menupage); 757 csprint(ms->title, ms->titleattr); 758 759 cursoroff(); // Doesn't seem to work? 651 reset_ui(); 760 652 761 653 // Go, main menu cannot be a radio menu 762 654 rv = runmenusystem(ms->minrow + MENUROW, ms->mincol + MENUCOL, 763 ms->menus[(unsigned int)startmenu], 0, NORMALMENU);655 ms->menus[(unsigned int)startmenu], 0, NORMALMENU); 764 656 765 657 // Hide the garbage we left on the screen 766 658 cursoron(); 767 if (oldpage == ms->menupage) 768 cls(); 769 else 770 setdisppage(oldpage); 659 cls(); 771 660 772 661 // Return user choice … … 781 670 ms = (pt_menusystem) malloc(sizeof(t_menusystem)); 782 671 if (ms == NULL) 783 return NULL;672 return NULL; 784 673 ms->nummenus = 0; 785 674 // Initialise all menu pointers 786 675 for (i = 0; i < MAXMENUS; i++) 787 ms->menus[i] = NULL;676 ms->menus[i] = NULL; 788 677 789 678 ms->title = (char *)malloc(TITLELEN + 1); 790 679 if (title == NULL) 791 strcpy(ms->title, TITLESTR);// Copy string680 strcpy(ms->title, TITLESTR); // Copy string 792 681 else 793 strcpy(ms->title, title);682 strcpy(ms->title, title); 794 683 795 684 // Timeout settings … … 821 710 ms->shadowattr = SHADOWATTR; 822 711 823 ms->menupage = MENUPAGE; // Usually no need to change this at all712 ms->menupage = MENUPAGE; // Usually no need to change this at all 824 713 825 714 // Initialise all handlers 826 715 ms->handler = NULL; 827 716 ms->keys_handler = NULL; 828 ms->ontimeout = NULL; // No timeout handler717 ms->ontimeout = NULL; // No timeout handler 829 718 ms->tm_total_timeout = 0; 830 719 ms->tm_sofar_timeout = 0; … … 839 728 // Figure out the size of the screen we are in now. 840 729 // By default we use the whole screen for our menu 730 if (getscreensize(1, &ms->numrows, &ms->numcols)) { 731 /* Unknown screen size? */ 732 ms->numcols = 80; 733 ms->numrows = 24; 734 } 841 735 ms->minrow = ms->mincol = 0; 842 ms->numcols = getnumcols();843 ms->numrows = getnumrows();844 736 ms->maxcol = ms->numcols - 1; 845 737 ms->maxrow = ms->numrows - 1; … … 848 740 ms->maxmenuheight = ms->maxrow - ms->minrow - 3; 849 741 if (ms->maxmenuheight > MAXMENUHEIGHT) 850 ms->maxmenuheight = MAXMENUHEIGHT;851 852 // Set up the look of the box853 set_box_type(MENUBOXTYPE); 742 ms->maxmenuheight = MAXMENUHEIGHT; 743 744 console_ansi_raw(); 745 854 746 return ms; 855 747 } 856 748 857 749 void set_normal_attr(uchar normal, uchar selected, uchar inactivenormal, 858 uchar inactiveselected)750 uchar inactiveselected) 859 751 { 860 752 if (normal != 0xFF) 861 ms->normalattr[0] = normal;753 ms->normalattr[0] = normal; 862 754 if (selected != 0xFF) 863 ms->reverseattr[0] = selected;755 ms->reverseattr[0] = selected; 864 756 if (inactivenormal != 0xFF) 865 ms->inactattr[0] = inactivenormal;757 ms->inactattr[0] = inactivenormal; 866 758 if (inactiveselected != 0xFF) 867 ms->revinactattr[0] = inactiveselected;759 ms->revinactattr[0] = inactiveselected; 868 760 } 869 761 870 762 void set_normal_hlite(uchar normal, uchar selected, uchar inactivenormal, 871 uchar inactiveselected)763 uchar inactiveselected) 872 764 { 873 765 if (normal != 0xFF) 874 ms->normalattr[1] = normal;766 ms->normalattr[1] = normal; 875 767 if (selected != 0xFF) 876 ms->reverseattr[1] = selected;768 ms->reverseattr[1] = selected; 877 769 if (inactivenormal != 0xFF) 878 ms->inactattr[1] = inactivenormal;770 ms->inactattr[1] = inactivenormal; 879 771 if (inactiveselected != 0xFF) 880 ms->revinactattr[1] = inactiveselected;772 ms->revinactattr[1] = inactiveselected; 881 773 } 882 774 … … 884 776 { 885 777 if (statusattr != 0xFF) 886 ms->statusattr[NOHLITE] = statusattr;778 ms->statusattr[NOHLITE] = statusattr; 887 779 if (statushlite != 0xFF) 888 ms->statusattr[HLITE] = statushlite;780 ms->statusattr[HLITE] = statushlite; 889 781 // statline is relative to minrow 890 782 if (statline >= ms->numrows) 891 statline = ms->numrows - 1;892 ms->statline = statline; // relative to ms->minrow, 0 based783 statline = ms->numrows - 1; 784 ms->statline = statline; // relative to ms->minrow, 0 based 893 785 } 894 786 … … 896 788 { 897 789 if (tfillchar != 0xFF) 898 ms->tfillchar = tfillchar;790 ms->tfillchar = tfillchar; 899 791 if (titleattr != 0xFF) 900 ms->titleattr = titleattr;792 ms->titleattr = titleattr; 901 793 } 902 794 903 795 void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar, 904 uchar shadowattr)796 uchar shadowattr) 905 797 { 906 798 if (fillchar != 0xFF) 907 ms->fillchar = fillchar;799 ms->fillchar = fillchar; 908 800 if (fillattr != 0xFF) 909 ms->fillattr = fillattr;801 ms->fillattr = fillattr; 910 802 if (spacechar != 0xFF) 911 ms->spacechar = spacechar;803 ms->spacechar = spacechar; 912 804 if (shadowattr != 0xFF) 913 ms->shadowattr = shadowattr; 914 } 915 916 void set_box_type(boxtype bt) 917 { 918 uchar *bxc; 919 ms->menubt = bt; 920 bxc = getboxchars(bt); 921 ms->box_horiz = bxc[BOX_HORIZ]; // The char used to draw top line 922 ms->box_ltrt = bxc[BOX_LTRT]; 923 ms->box_rtlt = bxc[BOX_RTLT]; 805 ms->shadowattr = shadowattr; 924 806 } 925 807 … … 927 809 { 928 810 if (maxmenuheight != 0xFF) 929 ms->maxmenuheight = maxmenuheight;811 ms->maxmenuheight = maxmenuheight; 930 812 } 931 813 … … 933 815 void set_window_size(uchar top, uchar left, uchar bot, uchar right) 934 816 { 935 936 uchar nr, nc; 817 int nr, nc; 818 937 819 if ((top > bot) || (left > right)) 938 return; // Sorry no change will happen here 939 nr = getnumrows(); 940 nc = getnumcols(); 820 return; // Sorry no change will happen here 821 822 if (getscreensize(1, &nr, &nc)) { 823 /* Unknown screen size? */ 824 nr = 80; 825 nc = 24; 826 } 941 827 if (bot >= nr) 942 bot = nr - 1;828 bot = nr - 1; 943 829 if (right >= nc) 944 right = nc - 1;830 right = nc - 1; 945 831 ms->minrow = top; 946 832 ms->mincol = left; … … 950 836 ms->numrows = bot - top + 1; 951 837 if (ms->statline >= ms->numrows) 952 ms->statline = ms->numrows - 1;// Clip statline if need be838 ms->statline = ms->numrows - 1; // Clip statline if need be 953 839 } 954 840 … … 958 844 switch (htype) { 959 845 case HDLR_KEYS: 960 ms->keys_handler = (t_keys_handler) handler;961 break;846 ms->keys_handler = (t_keys_handler) handler; 847 break; 962 848 default: 963 ms->handler = (t_menusystem_handler) handler;964 break;849 ms->handler = (t_menusystem_handler) handler; 850 break; 965 851 } 966 852 } … … 970 856 switch (htype) { 971 857 case HDLR_KEYS: 972 ms->keys_handler = NULL;973 break;858 ms->keys_handler = NULL; 859 break; 974 860 default: 975 ms->handler = NULL;976 break;861 ms->handler = NULL; 862 break; 977 863 } 978 864 } 979 865 980 866 void reg_ontimeout(t_timeout_handler handler, unsigned int numsteps, 981 unsigned int stepsize)867 unsigned int stepsize) 982 868 { 983 869 ms->ontimeout = handler; 984 870 if (numsteps != 0) 985 ms->tm_numsteps = numsteps;871 ms->tm_numsteps = numsteps; 986 872 if (stepsize != 0) 987 ms->tm_stepsize = stepsize;873 ms->tm_stepsize = stepsize; 988 874 } 989 875 … … 994 880 995 881 void reg_ontotaltimeout(t_timeout_handler handler, 996 unsigned long numcentiseconds)882 unsigned long numcentiseconds) 997 883 { 998 884 if (numcentiseconds != 0) { 999 ms->ontotaltimeout = handler;1000 ms->tm_total_timeout = numcentiseconds * 10;// to convert to milliseconds1001 ms->tm_sofar_timeout = 0;885 ms->ontotaltimeout = handler; 886 ms->tm_total_timeout = numcentiseconds * 10; // to convert to milliseconds 887 ms->tm_sofar_timeout = 0; 1002 888 } 1003 889 } … … 1012 898 int ans; 1013 899 if (index < 0) 1014 ans = 0;900 ans = 0; 1015 901 else if (index >= menu->numitems) 1016 ans = menu->numitems - 1;902 ans = menu->numitems - 1; 1017 903 else 1018 ans = index;904 ans = index; 1019 905 while ((ans < menu->numitems - 1) && 1020 ((menu->items[ans]->action == OPT_INVISIBLE) ||1021 (menu->items[ans]->action == OPT_SEP)))1022 ans++;906 ((menu->items[ans]->action == OPT_INVISIBLE) || 907 (menu->items[ans]->action == OPT_SEP))) 908 ans++; 1023 909 return ans; 1024 910 } 1025 911 1026 int prev_visible(pt_menu menu, int index) // Return index of prev visible912 int prev_visible(pt_menu menu, int index) // Return index of prev visible 1027 913 { 1028 914 int ans; 1029 915 if (index < 0) 1030 ans = 0;916 ans = 0; 1031 917 else if (index >= menu->numitems) 1032 ans = menu->numitems - 1;918 ans = menu->numitems - 1; 1033 919 else 1034 ans = index;920 ans = index; 1035 921 while ((ans > 0) && 1036 ((menu->items[ans]->action == OPT_INVISIBLE) ||1037 (menu->items[ans]->action == OPT_SEP)))1038 ans--;922 ((menu->items[ans]->action == OPT_INVISIBLE) || 923 (menu->items[ans]->action == OPT_SEP))) 924 ans--; 1039 925 return ans; 1040 926 } … … 1044 930 int ans; 1045 931 if (index < 0) 1046 ans = 0;932 ans = 0; 1047 933 else if (index >= menu->numitems) 1048 ans = menu->numitems - 1;934 ans = menu->numitems - 1; 1049 935 else 1050 ans = index;936 ans = index; 1051 937 while ((ans < menu->numitems - 1) && 1052 (menu->items[ans]->action == OPT_INVISIBLE))1053 ans++;938 (menu->items[ans]->action == OPT_INVISIBLE)) 939 ans++; 1054 940 return ans; 1055 941 } 1056 942 1057 int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible943 int prev_visible_sep(pt_menu menu, int index) // Return index of prev visible 1058 944 { 1059 945 int ans; 1060 946 if (index < 0) 1061 ans = 0;947 ans = 0; 1062 948 else if (index >= menu->numitems) 1063 ans = menu->numitems - 1;949 ans = menu->numitems - 1; 1064 950 else 1065 ans = index;951 ans = index; 1066 952 while ((ans > 0) && (menu->items[ans]->action == OPT_INVISIBLE)) 1067 ans--;953 ans--; 1068 954 return ans; 1069 955 } … … 1074 960 1075 961 if (menu == NULL) 1076 return 0;962 return 0; 1077 963 ans = 0; 1078 964 for (i = first; i < menu->numitems; i++) 1079 if (menu->items[i]->action != OPT_INVISIBLE)1080 ans++;965 if (menu->items[i]->action != OPT_INVISIBLE) 966 ans++; 1081 967 return ans; 1082 968 } … … 1086 972 { 1087 973 if (curr < first) 1088 return 0;974 return 0; 1089 975 return (calc_visible(menu, first) - calc_visible(menu, curr) < 1090 menu->menuheight);976 menu->menuheight); 1091 977 } 1092 978 … … 1099 985 nv = calc_visible(menu, 0); 1100 986 if (nv <= menu->menuheight) 1101 return 0;987 return 0; 1102 988 // Start with curr and go back menu->menuheight times 1103 989 ans = curr + 1; 1104 990 for (i = 0; i < menu->menuheight; i++) 1105 ans = prev_visible_sep(menu, ans - 1);991 ans = prev_visible_sep(menu, ans - 1); 1106 992 return ans; 1107 993 } … … 1115 1001 nv = calc_visible(menu, 0); 1116 1002 if (nv <= menu->menuheight) 1117 return 0;1003 return 0; 1118 1004 // Start with curr and go back till >= menu->menuheight 1119 1005 // items are visible 1120 nv = calc_visible(menu, curr); // Already nv of them are visible1006 nv = calc_visible(menu, curr); // Already nv of them are visible 1121 1007 ans = curr; 1122 1008 for (i = 0; i < menu->menuheight - nv; i++) 1123 ans = prev_visible_sep(menu, ans - 1);1009 ans = prev_visible_sep(menu, ans - 1); 1124 1010 return ans; 1125 1011 } … … 1133 1019 num = ms->nummenus; 1134 1020 if (num >= MAXMENUS) 1135 return -1;1021 return -1; 1136 1022 m = NULL; 1137 1023 m = (pt_menu) malloc(sizeof(t_menu)); 1138 1024 if (m == NULL) 1139 return -1;1025 return -1; 1140 1026 ms->menus[num] = m; 1141 1027 m->numitems = 0; … … 1144 1030 m->col = 0xFF; 1145 1031 if (maxmenusize < 1) 1146 m->maxmenusize = MAXMENUSIZE;1032 m->maxmenusize = MAXMENUSIZE; 1147 1033 else 1148 m->maxmenusize = maxmenusize;1034 m->maxmenusize = maxmenusize; 1149 1035 m->items = (pt_menuitem *) malloc(sizeof(pt_menuitem) * (m->maxmenusize)); 1150 1036 for (i = 0; i < m->maxmenusize; i++) 1151 m->items[i] = NULL;1037 m->items[i] = NULL; 1152 1038 1153 1039 m->title = (char *)malloc(MENULEN + 1); 1154 1040 if (title) { 1155 if (strlen(title) > MENULEN - 2)1156 strcpy(m->title, TITLELONG);1157 else1158 strcpy(m->title, title);1041 if (strlen(title) > MENULEN - 2) 1042 strcpy(m->title, TITLELONG); 1043 else 1044 strcpy(m->title, title); 1159 1045 } else 1160 strcpy(m->title, EMPTYSTR);1046 strcpy(m->title, EMPTYSTR); 1161 1047 m->menuwidth = strlen(m->title); 1162 1048 ms->nummenus++; … … 1164 1050 } 1165 1051 1166 void set_menu_name(const char *name) // Set the "name" of this menu1052 void set_menu_name(const char *name) // Set the "name" of this menu 1167 1053 { 1168 1054 pt_menu m; 1169 1055 1170 1056 m = ms->menus[ms->nummenus - 1]; 1171 if (m->name) // Free up previous name1057 if (m->name) // Free up previous name 1172 1058 { 1173 free(m->name);1174 m->name = NULL;1059 free(m->name); 1060 m->name = NULL; 1175 1061 } 1176 1062 1177 1063 if (name) { 1178 m->name = (char *)malloc(strlen(name) + 1);1179 strcpy(m->name, name);1064 m->name = (char *)malloc(strlen(name) + 1); 1065 strcpy(m->name, name); 1180 1066 } 1181 1067 } … … 1189 1075 } 1190 1076 1191 void set_menu_pos(uchar row, uchar col) // Set the position of this menu.1077 void set_menu_pos(uchar row, uchar col) // Set the position of this menu. 1192 1078 { 1193 1079 pt_menu m; … … 1198 1084 } 1199 1085 1200 pt_menuitem add_sep() // Add a separator to current menu1086 pt_menuitem add_sep() // Add a separator to current menu 1201 1087 { 1202 1088 pt_menuitem mi; … … 1207 1093 mi = (pt_menuitem) malloc(sizeof(t_menuitem)); 1208 1094 if (mi == NULL) 1209 return NULL;1095 return NULL; 1210 1096 m->items[(unsigned int)m->numitems] = mi; 1211 mi->handler = NULL; // No handler1097 mi->handler = NULL; // No handler 1212 1098 mi->item = mi->status = mi->data = NULL; 1213 1099 mi->action = OPT_SEP; … … 1221 1107 // Add item to the "current" menu 1222 1108 pt_menuitem add_item(const char *item, const char *status, t_action action, 1223 const char *data, uchar itemdata)1109 const char *data, uchar itemdata) 1224 1110 { 1225 1111 pt_menuitem mi; 1226 1112 pt_menu m; 1227 1113 const char *str; 1228 uchar inhlite = 0; // Are we inside hlite area1114 uchar inhlite = 0; // Are we inside hlite area 1229 1115 1230 1116 m = (ms->menus[ms->nummenus - 1]); … … 1232 1118 mi = (pt_menuitem) malloc(sizeof(t_menuitem)); 1233 1119 if (mi == NULL) 1234 return NULL;1120 return NULL; 1235 1121 m->items[(unsigned int)m->numitems] = mi; 1236 mi->handler = NULL; // No handler1122 mi->handler = NULL; // No handler 1237 1123 1238 1124 // Allocate space to store stuff … … 1242 1128 1243 1129 if (item) { 1244 if (strlen(item) > MENULEN) {1245 strcpy(mi->item, ITEMLONG);1246 } else {1247 strcpy(mi->item, item);1248 }1249 if (strlen(mi->item) > m->menuwidth)1250 m->menuwidth = strlen(mi->item);1130 if (strlen(item) > MENULEN) { 1131 strcpy(mi->item, ITEMLONG); 1132 } else { 1133 strcpy(mi->item, item); 1134 } 1135 if (strlen(mi->item) > m->menuwidth) 1136 m->menuwidth = strlen(mi->item); 1251 1137 } else 1252 strcpy(mi->item, EMPTYSTR);1138 strcpy(mi->item, EMPTYSTR); 1253 1139 1254 1140 if (status) { 1255 if (strlen(status) > STATLEN) {1256 strcpy(mi->status, STATUSLONG);1257 } else {1258 strcpy(mi->status, status);1259 }1141 if (strlen(status) > STATLEN) { 1142 strcpy(mi->status, STATUSLONG); 1143 } else { 1144 strcpy(mi->status, status); 1145 } 1260 1146 } else 1261 strcpy(mi->status, EMPTYSTR);1147 strcpy(mi->status, EMPTYSTR); 1262 1148 1263 1149 mi->action = action; … … 1265 1151 mi->shortcut = 0; 1266 1152 mi->helpid = 0xFFFF; 1267 inhlite = 0; // We have not yet seen an ENABLEHLITE char1153 inhlite = 0; // We have not yet seen an ENABLEHLITE char 1268 1154 // Find the first char in [A-Za-z0-9] after ENABLEHLITE and not arg to control char 1269 1155 while (*str) { 1270 if (*str == ENABLEHLITE) {1271 inhlite = 1;1272 }1273 if (*str == DISABLEHLITE) {1274 inhlite = 0;1275 }1276 if ((inhlite == 1) &&1277 (((*str >= 'A') && (*str <= 'Z')) ||1278 ((*str >= 'a') && (*str <= 'z')) ||1279 ((*str >= '0') && (*str <= '9')))) {1280 mi->shortcut = *str;1281 break;1282 }1283 ++str;1284 } 1285 if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case1286 mi->shortcut = mi->shortcut - 'A' + 'a';1156 if (*str == ENABLEHLITE) { 1157 inhlite = 1; 1158 } 1159 if (*str == DISABLEHLITE) { 1160 inhlite = 0; 1161 } 1162 if ((inhlite == 1) && 1163 (((*str >= 'A') && (*str <= 'Z')) || 1164 ((*str >= 'a') && (*str <= 'z')) || 1165 ((*str >= '0') && (*str <= '9')))) { 1166 mi->shortcut = *str; 1167 break; 1168 } 1169 ++str; 1170 } 1171 if ((mi->shortcut >= 'A') && (mi->shortcut <= 'Z')) // Make lower case 1172 mi->shortcut = mi->shortcut - 'A' + 'a'; 1287 1173 1288 1174 if (data) { 1289 if (strlen(data) > ACTIONLEN) {1290 strcpy(mi->data, ACTIONLONG);1291 } else {1292 strcpy(mi->data, data);1293 }1175 if (strlen(data) > ACTIONLEN) { 1176 strcpy(mi->data, ACTIONLONG); 1177 } else { 1178 strcpy(mi->data, data); 1179 } 1294 1180 } else 1295 strcpy(mi->data, EMPTYSTR);1181 strcpy(mi->data, EMPTYSTR); 1296 1182 1297 1183 switch (action) { 1298 1184 case OPT_SUBMENU: 1299 mi->itemdata.submenunum = itemdata;1300 break;1185 mi->itemdata.submenunum = itemdata; 1186 break; 1301 1187 case OPT_CHECKBOX: 1302 mi->itemdata.checked = itemdata;1303 break;1188 mi->itemdata.checked = itemdata; 1189 break; 1304 1190 case OPT_RADIOMENU: 1305 mi->itemdata.radiomenunum = itemdata;1306 if (mi->data)1307 free(mi->data);1308 mi->data = NULL;// No selection made1309 break;1310 default: // to keep the compiler happy1311 break;1191 mi->itemdata.radiomenunum = itemdata; 1192 if (mi->data) 1193 free(mi->data); 1194 mi->data = NULL; // No selection made 1195 break; 1196 default: // to keep the compiler happy 1197 break; 1312 1198 } 1313 1199 mi->index = m->numitems++; … … 1324 1210 m = (ms->menus[ms->nummenus - 1]); 1325 1211 if (m->numitems <= 0) 1326 return;1212 return; 1327 1213 mi = m->items[(unsigned int)m->numitems - 1]; 1328 1214 1329 1215 if (shortcut != 0xFF) 1330 mi->shortcut = shortcut;1216 mi->shortcut = shortcut; 1331 1217 if (helpid != 0xFFFF) 1332 mi->helpid = helpid;1218 mi->helpid = helpid; 1333 1219 } 1334 1220 … … 1345 1231 char *app; 1346 1232 int ctr; 1347 char dp; 1348 1349 dp = getdisppage(); 1233 1350 1234 menu = ms->menus[menunum]; 1351 1235 for (ctr = 0; ctr < (int)menu->numitems; ctr++) { 1352 mi = menu->items[ctr];1353 app = NULL;//What to append1354 switch (mi->action) {1355 case OPT_CHECKBOX:1356 if (mi->itemdata.checked)1357 app = mi->data;1358 break;1359 case OPT_RADIOMENU:1360 if (mi->data) {// Some selection has been made1361 ri = (pt_menuitem) (mi->data);1362 app = ri->data;1363 }1364 break;1365 case OPT_SUBMENU:1366 append_line_helper(mi->itemdata.submenunum, line);1367 break;1368 default:1369 break;1370 }1371 if (app) {1372 strcat(line, " ");1373 strcat(line, app);1374 }1236 mi = menu->items[ctr]; 1237 app = NULL; //What to append 1238 switch (mi->action) { 1239 case OPT_CHECKBOX: 1240 if (mi->itemdata.checked) 1241 app = mi->data; 1242 break; 1243 case OPT_RADIOMENU: 1244 if (mi->data) { // Some selection has been made 1245 ri = (pt_menuitem) (mi->data); 1246 app = ri->data; 1247 } 1248 break; 1249 case OPT_SUBMENU: 1250 append_line_helper(mi->itemdata.submenunum, line); 1251 break; 1252 default: 1253 break; 1254 } 1255 if (app) { 1256 strcat(line, " "); 1257 strcat(line, app); 1258 } 1375 1259 } 1376 1260 } … … 1384 1268 menunum = find_menu_num(menu_name); 1385 1269 if (menunum < 0) 1386 return;// No such menu1270 return; // No such menu 1387 1271 append_line_helper(menunum, line); 1388 1272 } -
com32/cmenu/libmenu/menu.h
r1ef30e r397586 23 23 #include "tui.h" 24 24 #include "syslnx.h" 25 #include "scancodes.h"26 25 #include <string.h> 26 #include <unistd.h> 27 27 28 28 // TIMEOUT PARAMETERS … … 60 60 #define STATUSHLITE 0x7B // Status highlight 61 61 62 #define FILLCHAR 17763 #define FILLATTR 0x0162 #define FILLCHAR ' ' 63 #define FILLATTR NORMALATTR 64 64 #define SHADOWATTR 0x00 65 65 #define SPACECHAR ' ' … … 73 73 #define HLITE 1 // The offset for Hlite attrib 74 74 75 #define MOREABOVE 24 // char to print when more menu items available above 76 #define MOREBELOW 25 // more items available below 77 #define SCROLLBOX 176 // Filled char to display 75 #define MOREABOVE '^' // char to print when more menu items available above 76 #define MOREBELOW 'v' // more items available below 78 77 79 78 // Attributes of the menu system … … 100 99 101 100 // Other Chars 102 #define SUBMENUCHAR 175 // This is >> symbol103 101 #define RADIOMENUCHAR '>' // > symbol for radio menu? 104 #define EXITMENUCHAR 174 // This is << symbol 105 #define CHECKED 251 // Check mark 106 #define UNCHECKED 250 // Light bullet 102 #define CHECKED '\140' // Check mark 103 #define UNCHECKED '\146' // Light bullet 107 104 #define RADIOSEL '.' // Current Radio Selection 108 105 #define RADIOUNSEL ' ' // Radio option not selected … … 215 212 uchar statline; 216 213 uchar menupage; 217 ucharmaxrow, minrow, numrows; // Number of rows in the window218 ucharmaxcol, mincol, numcols; // Number of columns in the window214 int maxrow, minrow, numrows; // Number of rows in the window 215 int maxcol, mincol, numcols; // Number of columns in the window 219 216 220 217 // Menu box look 221 boxtype menubt; // What type of boxes should be drawn222 218 char box_horiz, box_ltrt, box_rtlt; // Some chars of the box, for redrawing portions of the box 223 219 … … 244 240 void set_misc_info(uchar fillchar, uchar fillattr, uchar spacechar, 245 241 uchar shadowattr); 246 void set_box_type(boxtype bt);247 242 248 243 void set_window_size(uchar top, uchar left, uchar bot, uchar right); // Set the window which menusystem should use -
com32/cmenu/libmenu/tui.c
r9ee1ad r843f0e 15 15 #include <com32.h> 16 16 #include <stdlib.h> 17 #include "com32io.h" 17 18 18 19 com32sys_t inreg, outreg; // Global register sets for use … … 20 21 char bkspstr[] = " \b$"; 21 22 char eolstr[] = "\n$"; 22 #define GETSTRATTR 0x0723 23 24 24 // Reads a line of input from stdin. Replace CR with NUL byte … … 30 30 unsigned int showoldvalue) 31 31 { 32 unsigned char c, scan;32 unsigned int c; 33 33 char *p, *q; // p = current char of string, q = tmp 34 34 char *last; // The current last char of string 35 35 char *str; // pointer to string which is going to be allocated 36 char page;37 36 char row, col; 38 37 char start, end; // Cursor shape … … 40 39 char insmode; // Are we in insert or overwrite 41 40 42 page = getdisppage(); 43 getpos(&row, &col, page); // Get current position 41 getpos(&row, &col, 0); // Get current position 44 42 getcursorshape(&start, &end); 45 43 insmode = 1; … … 68 66 if (password == 0) // Not a password, print initial value 69 67 { 70 gotoxy(row, col , page);68 gotoxy(row, col); 71 69 csprint(str, GETSTRATTR); 72 70 } 73 71 while (1) { // Do forever 74 c = inputc(&scan);75 if (c == '\r')72 c = get_key(stdin, 0); 73 if (c == KEY_ENTER) 76 74 break; // User hit Enter getout of loop 77 if ( scan == ESCAPE) // User hit escape getout and nullify string75 if (c == KEY_ESC) // User hit escape getout and nullify string 78 76 { 79 77 *str = 0; … … 84 82 // else if char code is recognized do something 85 83 // else ignore 86 switch ( scan) {87 case HOMEKEY:84 switch (c) { 85 case KEY_HOME: 88 86 p = str; 89 87 break; 90 case ENDKEY:88 case KEY_END: 91 89 p = last; 92 90 break; 93 case LTARROW:91 case KEY_LEFT: 94 92 if (p > str) 95 93 p--; 96 94 break; 97 case CTRLLT:95 case KEY_CTRL(KEY_LEFT): 98 96 if (p == str) 99 97 break; … … 111 109 p--; 112 110 break; 113 case RTARROW:111 case KEY_RIGHT: 114 112 if (p < last) 115 113 p++; 116 114 break; 117 case CTRLRT:115 case KEY_CTRL(KEY_RIGHT): 118 116 if (*p == 0) 119 117 break; // At end of string … … 126 124 p++; 127 125 break; 128 case DELETE: 126 case KEY_DEL: 127 case KEY_DELETE: 129 128 q = p; 130 129 while (*(q + 1)) { … … 136 135 fudge = 1; 137 136 break; 138 case INSERT:137 case KEY_INSERT: 139 138 insmode = 1 - insmode; // Switch mode 140 139 if (insmode == 0) … … 143 142 setcursorshape(6, 7); // Normal cursor 144 143 break; 145 146 default: // Unrecognized scan code, look at the ascii value 147 switch (c) { 148 case '\b': // Move over by one 144 case KEY_BACKSPACE: // Move over by one 149 145 q = p; 150 146 while (q <= last) { … … 158 154 fudge = 1; 159 155 break; 160 case '\x15': /* Ctrl-U: kill input */156 case KEY_CTRL('U'): /* Ctrl-U: kill input */ 161 157 fudge = last - str; 162 158 while (p > str) … … 166 162 last = str; 167 163 break; 168 default: // Handle insert and overwrite mode164 default: // Handle insert and overwrite mode 169 165 if ((c >= ' ') && (c < 128) && 170 166 ((unsigned int)(p - str) < size - 1)) { … … 190 186 } else 191 187 beep(); 192 }193 188 break; 194 189 } 195 190 // Now the string has been modified, print it 196 191 if (password == 0) { 197 gotoxy(row, col , page);192 gotoxy(row, col); 198 193 csprint(str, GETSTRATTR); 199 194 if (fudge > 0) 200 cprint(' ', GETSTRATTR, fudge , page);201 gotoxy(row, col + (p - str) , page);195 cprint(' ', GETSTRATTR, fudge); 196 gotoxy(row, col + (p - str)); 202 197 } 203 } 198 } /* while */ 204 199 *p = '\0'; 205 200 if (password == 0) … … 207 202 setcursorshape(start, end); // Block cursor 208 203 // If user hit ESCAPE so return without any changes 209 if ( scan != ESCAPE)204 if (c != KEY_ESC) 210 205 strcpy(stra, str); 211 206 free(str); 212 207 } 213 208 214 /* Print a C string (NUL-terminated) */ 215 void cswprint(const char *str, char attr, char left) 209 //////////////////////////////Box Stuff 210 211 // Draw box and lines 212 void drawbox(const char top, const char left, const char bot, 213 const char right, const char attr) 216 214 { 217 char page = getdisppage();218 char newattr = 0, cha, chb;219 char row, col;220 char nr, nc;221 222 nr = getnumrows();223 nc = getnumcols();224 getpos(&row, &col, page);225 while (*str) {226 switch (*str) {227 case '\b':228 --col;229 break;230 case '\n':231 ++row;232 col = left;233 break;234 case '\r':235 //col=left;236 break;237 case BELL: // Bell Char238 beep();239 break;240 case CHRELATTR: // change attribute (relatively)241 case CHABSATTR: // change attribute (absolute)242 cha = *(str + 1);243 chb = *(str + 2);244 if ((((cha >= '0') && (cha <= '9')) || ((cha >= 'A') && (cha <= 'F'))) && (((chb >= '0') && (chb <= '9')) || ((chb >= 'A') && (chb <= 'F')))) // Next two chars are legal245 {246 if ((cha >= 'A') && (cha <= 'F'))247 cha = cha - 'A' + 10;248 else249 cha = cha - '0';250 if ((chb >= 'A') && (chb <= 'F'))251 chb = chb - 'A' + 10;252 else253 chb = chb - '0';254 newattr = (cha << 4) + chb;255 attr = (*str == CHABSATTR ? newattr : attr ^ newattr);256 str += 2; // Will be incremented again later257 }258 break;259 default:260 putch(*str, attr, page);261 ++col;262 }263 if (col >= nc) {264 ++row;265 col = left;266 }267 if (row > nr) {268 scrollup();269 row = nr;270 }271 gotoxy(row, col, page);272 str++;273 }274 }275 276 void clearwindow(char top, char left, char bot, char right, char page,277 char fillchar, char fillattr)278 {279 char x;280 for (x = top; x < bot + 1; x++) {281 gotoxy(x, left, page);282 cprint(fillchar, fillattr, right - left + 1, page);283 }284 }285 286 void cls(void)287 {288 unsigned char dp = getdisppage();289 gotoxy(0, 0, dp);290 cprint(' ', GETSTRATTR, (1 + getnumrows()) * getnumcols(), dp);291 }292 293 //////////////////////////////Box Stuff294 295 // This order of numbers must match296 // the values of BOX_TOPLEFT,... in the header file297 298 unsigned char SINSIN_CHARS[] = { 218, 192, 191, 217, //Corners299 196, 179, // Horiz and Vertical300 195, 180, 194, 193, 197301 }; // Connectors & Middle302 303 unsigned char DBLDBL_CHARS[] = { 201, 200, 187, 188, // Corners304 205, 186, // Horiz and Vertical305 199, 182, 203, 202, 206306 }; // Connectors & Middle307 308 unsigned char SINDBL_CHARS[] = { 214, 211, 183, 189, // Corners309 196, 186, // Horiz & Vert310 199, 182, 210, 208, 215311 }; // Connectors & Middle312 313 unsigned char DBLSIN_CHARS[] = { 213, 212, 184, 190, // Corners314 205, 179, // Horiz & Vert315 198, 181, 209, 207, 216316 }; // Connectors & Middle317 318 unsigned char *getboxchars(boxtype bt)319 {320 switch (bt) {321 case BOX_SINSIN:322 return SINSIN_CHARS;323 break;324 case BOX_DBLDBL:325 return DBLDBL_CHARS;326 break;327 case BOX_SINDBL:328 return SINDBL_CHARS;329 break;330 case BOX_DBLSIN:331 return DBLSIN_CHARS;332 break;333 default:334 return SINSIN_CHARS;335 break;336 }337 return SINSIN_CHARS;338 }339 340 // Draw box and lines341 void drawbox(char top, char left, char bot, char right,342 char page, char attr, boxtype bt)343 {344 unsigned char *box_chars; // pointer to array of box chars345 215 unsigned char x; 346 347 box_chars = getboxchars(bt); 216 putchar(SO); 348 217 // Top border 349 gotoxy(top, left, page); 350 cprint(box_chars[BOX_TOPLEFT], attr, 1, page); 351 gotoxy(top, left + 1, page); 352 cprint(box_chars[BOX_TOP], attr, right - left, page); 353 gotoxy(top, right, page); 354 cprint(box_chars[BOX_TOPRIGHT], attr, 1, page); 218 gotoxy(top, left); 219 putch(TOP_LEFT_CORNER_BORDER, attr); 220 cprint(TOP_BORDER, attr, right - left - 1); 221 putch(TOP_RIGHT_CORNER_BORDER, attr); 355 222 // Bottom border 356 gotoxy(bot, left, page); 357 cprint(box_chars[BOX_BOTLEFT], attr, 1, page); 358 gotoxy(bot, left + 1, page); 359 cprint(box_chars[BOX_BOT], attr, right - left, page); 360 gotoxy(bot, right, page); 361 cprint(box_chars[BOX_BOTRIGHT], attr, 1, page); 223 gotoxy(bot, left); 224 putch(BOTTOM_LEFT_CORNER_BORDER, attr); 225 cprint(BOTTOM_BORDER, attr, right - left - 1); 226 putch(BOTTOM_RIGHT_CORNER_BORDER, attr); 362 227 // Left & right borders 363 228 for (x = top + 1; x < bot; x++) { 364 gotoxy(x, left, page); 365 cprint(box_chars[BOX_LEFT], attr, 1, page); 366 gotoxy(x, right, page); 367 cprint(box_chars[BOX_RIGHT], attr, 1, page); 368 } 229 gotoxy(x, left); 230 putch(LEFT_BORDER, attr); 231 gotoxy(x, right); 232 putch(RIGHT_BORDER, attr); 233 } 234 putchar(SI); 369 235 } 370 236 371 void drawhorizline(c har top, char left, char right, char page, char attr,372 boxtype bt, char dumb)237 void drawhorizline(const char top, const char left, const char right, 238 const char attr, char dumb) 373 239 { 374 240 unsigned char start, end; 375 unsigned char *box_chars = getboxchars(bt);376 241 if (dumb == 0) { 377 242 start = left + 1; … … 381 246 end = right; 382 247 } 383 gotoxy(top, start, page); 384 cprint(box_chars[BOX_HORIZ], attr, end - start + 1, page); 248 gotoxy(top, start); 249 putchar(SO); 250 cprint(MIDDLE_BORDER, attr, end - start + 1); 385 251 if (dumb == 0) { 386 gotoxy(top, left, page); 387 cprint(box_chars[BOX_LTRT], attr, 1, page); 388 gotoxy(top, right, page); 389 cprint(box_chars[BOX_RTLT], attr, 1, page); 390 } 252 gotoxy(top, left); 253 putch(MIDDLE_BORDER, attr); 254 gotoxy(top, right); 255 putch(MIDDLE_BORDER, attr); 256 } 257 putchar(SI); 391 258 } -
com32/cmenu/libmenu/tui.h
rc70547f r843f0e 15 15 16 16 #include <com32.h> 17 #include <getkey.h> 18 #include <consoles.h> 17 19 #include "syslnx.h" 18 20 #include "com32io.h" 19 #include "scancodes.h"20 21 21 22 #ifndef NULL … … 23 24 #endif 24 25 26 #define SO '\016' 27 #define SI '\017' 28 29 #define TOP_LEFT_CORNER_BORDER '\154' 30 #define TOP_BORDER '\161' 31 #define TOP_RIGHT_CORNER_BORDER '\153' 32 #define BOTTOM_LEFT_CORNER_BORDER '\155' 33 #define BOTTOM_BORDER '\161' 34 #define BOTTOM_RIGHT_CORNER_BORDER '\152' 35 #define LEFT_BORDER '\170' 36 #define RIGHT_BORDER '\170' 37 #define LEFT_MIDDLE_BORDER '\164' 38 #define MIDDLE_BORDER '\161' 39 #define RIGHT_MIDDLE_BORDER '\165' 40 25 41 #define BELL 0x07 26 // CHRELATTR = ^N, CHABSATTR = ^O 27 #define CHABSATTR 15 28 #define CHRELATTR 14 29 30 void clearwindow(char top, char left, char bot, char right, 31 char page, char fillchar, char fillattr); 32 33 void cls(void); /* Clears the entire current screen page */ 42 #define GETSTRATTR 0x07 34 43 35 44 // Generic user input, … … 54 63 } 55 64 56 // Box drawing Chars offsets into array 57 #define BOX_TOPLEFT 0x0 58 #define BOX_BOTLEFT 0x1 59 #define BOX_TOPRIGHT 0x2 60 #define BOX_BOTRIGHT 0x3 61 #define BOX_TOP 0x4 // TOP = BOT = HORIZ 62 #define BOX_BOT 0x4 63 #define BOX_HORIZ 0x4 64 #define BOX_LEFT 0x5 65 #define BOX_RIGHT 0x5 66 #define BOX_VERT 0x5 // LEFT=RIGHT=VERT 67 #define BOX_LTRT 0x6 68 #define BOX_RTLT 0x7 69 #define BOX_TOPBOT 0x8 70 #define BOX_BOTTOP 0x9 71 #define BOX_MIDDLE 0xA 72 73 typedef enum { BOX_SINSIN, BOX_DBLDBL, BOX_SINDBL, BOX_DBLSIN } boxtype; 74 75 unsigned char *getboxchars(boxtype bt); 76 77 void drawbox(char top, char left, char bot, char right, 78 char page, char attr, boxtype bt); 65 void drawbox(const char, const char, const char, const char, 66 const char); 79 67 80 68 // Draw a horizontal line … … 82 70 // dumb == 0 means check the first and last positions and depending on what is 83 71 // currently on the screen make it a LTRT and/or RTLT appropriately. 84 void drawhorizline(c har top, char left, char right, char page, char attr,85 boxtype bt,char dumb);72 void drawhorizline(const char, const char, const char, const char, 73 const char dumb); 86 74 87 75 #endif -
com32/gplinclude/cpuid.h
rc93e27 r57c855 66 66 bool now; /* 3DNow! */ 67 67 bool smp; /* A smp configuration has been found */ 68 bool vmx; /* Hardware virtualization */ 69 bool svm; /* Secure virtual machine */ 68 70 } s_cpu_flags; 69 71 -
com32/gplinclude/disk/common.h
rb3a797 r29fc5c 18 18 #include <stdint.h> 19 19 20 /* For PAGE_SIZE */ 21 #include <cpuid.h> 22 20 23 #define SECTOR 512 /* bytes/sector */ 21 22 #undef PAGE_SIZE23 #define PAGE_SIZE (1<<12)24 24 25 25 struct ebios_dapa { -
com32/gplinclude/disk/error.h
rd93474 r196e20 10 10 #ifndef _ERROR_H_ 11 11 #define _ERROR_H_ 12 void get_error( void*);13 #endif /* _ UTIL_H_ */12 void get_error(const char*); 13 #endif /* _ERROR_H_ */ -
com32/gplinclude/disk/util.h
rb3a797 r196e20 19 19 20 20 int int13_retry(const com32sys_t *inreg, com32sys_t *outreg); 21 void get_error(const int, char**);22 21 #endif /* _UTIL_H_ */ -
com32/gpllib/cpuid.c
r5b5b1b r8ba991 296 296 cpu->flags.now = cpu_has(c, X86_FEATURE_3DNOW); 297 297 cpu->flags.smp = find_smp_config(); 298 cpu->flags.vmx = cpu_has(c, X86_FEATURE_VMX); 299 cpu->flags.svm = cpu_has(c, X86_FEATURE_SVM); 298 300 } 299 301 -
com32/gpllib/disk/ata.c
r4d9e46 r5e5230 1 1 #include <inttypes.h> 2 #include <string.h> 2 3 3 4 /** -
com32/gpllib/disk/error.c
r9ffe8b r39c3e6 14 14 /** 15 15 * get_error - decode a disk error status 16 * @ buffer_ptr: Preallocated buffer16 * @s: Preallocated buffer 17 17 * 18 18 * Fill @buffer_ptr with the last errno_disk -
com32/hdt/Makefile
rb8f633 r18d726 28 28 OBJS = $(patsubst %.c,%.o,$(wildcard *.c)) 29 29 30 KERNEL_VERSION ?= $(shell uname -r) 31 MODULES_ALIAS_FILE ?= /lib/modules/$(KERNEL_VERSION)/modules.alias 32 MODULES_PCIMAP_FILE ?= /lib/modules/$(KERNEL_VERSION)/modules.pcimap 33 ISO_DIR ?= iso 34 ISOLINUX_DIR ?= isolinux 35 FLOPPY_DIR ?= floppy 36 PCI_IDS_FILE ?= $(PWD)/$(FLOPPY_DIR)/pci.ids 37 30 38 all: $(MODULES) $(TESTFILES) 31 39 32 40 hdt.elf : $(OBJS) $(LIBS) $(C_LIBS) 33 41 $(LD) $(LDFLAGS) -o $@ $^ 42 43 hdt.img: hdt.c32 $(FLOPPY_DIR)/hdt.cfg $(FLOPPY_DIR)/mtools.conf $(topdir)/mtools/syslinux 44 rm -f hdt.img 45 MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MFORMAT) -v HDT -f 2880 -C a: 46 $(topdir)/mtools/syslinux hdt.img 47 -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(PCI_IDS_FILE) 48 -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(PCI_IDS_FILE) 49 -[ -f $(MODULES_ALIAS_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(MODULES_ALIAS_FILE) a: 50 -[ -f $(MODULES_PCIMAP_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(MODULES_PCIMAP_FILE) a: 51 MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) hdt.c32 a: 52 @ [ -f $(PCI_IDS_FILE) ] && MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(PCI_IDS_FILE) a: || printf "\nThe $(FLOPPY_DIR)/pci.ids file is missing and can be downloaded from http://pciids.sourceforge.net and put in\nthe ./com32/hdt/$(FLOPPY_DIR) directory of the extracted Syslinux source.\n\n" 53 MTOOLSRC=$(PWD)/$(FLOPPY_DIR)/mtools.conf $(MCOPY) $(FLOPPY_DIR)/hdt.cfg a:syslinux.cfg 54 55 hdt.iso: hdt.c32 $(topdir)/core/isolinux.bin $(FLOPPY_DIR)/hdt.cfg 56 rm -rf $(ISO_DIR) 57 rm -f hdt.iso 58 mkdir -p $(ISO_DIR)/$(ISOLINUX_DIR) 59 cp $(topdir)/core/isolinux.bin $(ISO_DIR)/$(ISOLINUX_DIR) 60 cp $(FLOPPY_DIR)/hdt.cfg $(ISO_DIR)/$(ISOLINUX_DIR)/isolinux.cfg 61 cp hdt.c32 $(ISO_DIR)/$(ISOLINUX_DIR) 62 -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/hwdata/pci.ids $(ISO_DIR)/$(ISOLINUX_DIR) 63 -[ ! -f $(PCI_IDS_FILE) ] && cp /usr/share/pci.ids $(ISO_DIR)/$(ISOLINUX_DIR) 64 -[ -f $(MODULES_ALIAS_FILE) ] && cp $(MODULES_ALIAS_FILE) $(ISO_DIR)/$(ISOLINUX_DIR) 65 -[ -f $(MODULES_PCIMAP_FILE) ] && cp $(MODULES_PCIMAP_FILE) $(ISO_DIR)/$(ISOLINUX_DIR) 66 -[ ! -f $(ISO_DIR)/$(ISOLINUX_DIR)/pci.ids ] && printf "\nThe $(FLOPPY_DIR)/pci.ids file is missing and can be downloaded from http://pciids.sourceforge.net and put in\nthe ./com32/hdt/$(FLOPPY_DIR) directory of the extracted Syslinux source.\n\n" 67 $(MKISOFS) -o hdt.iso -b $(ISOLINUX_DIR)/isolinux.bin -c $(ISOLINUX_DIR)/boot.cat \ 68 -no-emul-boot -boot-load-size 4 -boot-info-table \ 69 $(ISO_DIR) 34 70 35 71 tidy dist: … … 40 76 41 77 spotless: clean 42 rm -f *.lss *.c32 *.com 78 rm -f *.lss *.c32 *.com hdt.img hdt.iso 79 rm -rf $(ISO_DIR) 43 80 rm -f *~ \#* 44 81 -
com32/hdt/hdt-cli-cpu.c
rd0a0e5 r8ba991 175 175 if (hardware->cpu.flags.now) 176 176 strcat(buffer1, "3dnow! "); 177 if (hardware->cpu.flags.svm) 178 strcat(buffer1, "svm "); 179 if (hardware->cpu.flags.vmx) 180 strcat(buffer1, "vmx "); 177 181 if (buffer1[0]) { 178 182 snprintf(buffer, sizeof buffer, "Flags : %s\n", buffer1); -
com32/hdt/hdt-cli-disk.c
rb7ec0f re9069c 31 31 #include <stdlib.h> 32 32 #include <errno.h> 33 34 #include <disk/errno_disk.h>35 #include <disk/geom.h>36 #include <disk/read.h>37 #include <disk/error.h>38 #include <disk/swsusp.h>39 #include <disk/msdos.h>40 33 41 34 #include "hdt-cli.h" … … 64 57 { 65 58 char size[9]; 59 char bootloader_name[9]; 66 60 char *parttype; 67 61 unsigned int start, end; … … 78 72 79 73 if (i == 1) 80 more_printf(" # B Start End Size Id Type\n");74 more_printf(" # B Start End Size Id Type\n"); 81 75 82 76 get_label(ptab->ostype, &parttype); 83 more_printf(" %2d %s %11d %11d %s %02X %s",77 more_printf("%2d %s %11d %11d %s %02X %s", 84 78 i, (ptab->active_flag == 0x80) ? "x" : " ", 85 79 start, … … 92 86 more_printf("%s", " (Swsusp sig. detected)"); 93 87 88 if (get_bootloader_string(drive_info, ptab, bootloader_name, 9) == 0) 89 more_printf("%-46s %s %s", " ", "Bootloader:", bootloader_name); 90 94 91 more_printf("\n"); 95 92 … … 100 97 struct s_hardware *hardware) 101 98 { 102 reset_more_printf();103 99 if (!argc) { 104 100 more_printf("Which disk?\n"); … … 116 112 struct driveinfo *d = &hardware->disk_info[i]; 117 113 char disk_size[9]; 114 char mbr_name[50]; 118 115 119 116 detect_disks(hardware); 120 117 if (!hardware->disk_info[i].cbios) 121 118 return; /* Invalid geometry */ 119 120 get_mbr_string(hardware->mbr_ids[i], &mbr_name, 50); 122 121 123 122 if ((int) d->edd_params.sectors > 0) … … 128 127 more_printf("DISK 0x%X:\n" 129 128 " C/H/S: %d cylinders, %d heads, %d sectors/track\n" 130 " EDD:Version: %X\n"129 " EDD: Version: %X\n" 131 130 " Size: %s, %d bytes/sector, %d sectors/track\n" 132 " Host bus: %s, Interface type: %s\n\n", 131 " Host bus: %s, Interface type: %s\n" 132 " MBR: %s (id 0x%X)\n\n", 133 133 d->disk, 134 134 d->legacy_max_cylinder + 1, d->legacy_max_head + 1, d->legacy_sectors_per_track, 135 135 d->edd_version, 136 136 disk_size, (int) d->edd_params.bytes_per_sector, (int) d->edd_params.sectors_per_track, 137 remove_spaces(d->edd_params.host_bus_type), remove_spaces(d->edd_params.interface_type)); 137 remove_spaces((char *) d->edd_params.host_bus_type), remove_spaces((char*) d->edd_params.interface_type), 138 mbr_name, hardware->mbr_ids[i]); 139 display_line_nb += 6; 138 140 139 141 if (parse_partition_table(d, &show_partition_information)) { … … 146 148 fprintf(stderr, "\n"); 147 149 } 150 151 more_printf("\n"); 148 152 } 149 153 … … 154 158 detect_disks(hardware); 155 159 160 int first_one = 0; 156 161 for (int drive = 0x80; drive < 0xff; drive++) { 157 char buf[5] = ""; 158 sprintf(buf, "0x%x", drive); 159 char *argv[1] = { buf }; 160 main_show_disk(1, argv, hardware); 162 if (hardware->disk_info[drive - 0x80].cbios) { 163 if (!first_one) { 164 first_one = 1; 165 } else { 166 pause_printf(); 167 } 168 char buf[5] = ""; 169 sprintf(buf, "0x%x", drive); 170 char *argv[1] = { buf }; 171 main_show_disk(1, argv, hardware); 172 } 161 173 } 162 174 } … … 168 180 169 181 detect_disks(hardware); 182 reset_more_printf(); 170 183 171 184 for (int drive = 0x80; drive < 0xff; drive++) { … … 188 201 disk_size); 189 202 more_printf(" Host bus: %s, Interface type: %s\n\n", 190 remove_spaces( d->edd_params.host_bus_type),191 remove_spaces( d->edd_params.interface_type));203 remove_spaces((char*) d->edd_params.host_bus_type), 204 remove_spaces((char*) d->edd_params.interface_type)); 192 205 } 193 206 } -
com32/hdt/hdt-cli-hdt.c
ra872cb r486ec6 192 192 { 193 193 char version_string[256]; 194 snprintf(version_string, sizeof version_string, "%s %s by %s",195 PRODUCT_NAME, VERSION , AUTHOR);194 snprintf(version_string, sizeof version_string, "%s %s", 195 PRODUCT_NAME, VERSION); 196 196 start_menu_mode(hardware, version_string); 197 197 return; -
com32/hdt/hdt-cli.c
r18366f r47ac91 33 33 #include "hdt-cli.h" 34 34 #include "hdt-common.h" 35 #include "lib-ansi.h"36 35 37 36 struct cli_mode_descr *list_modes[] = { … … 55 54 * strings first. 56 55 */ 57 c har *exit_aliases[] = {"q", "quit"};58 c har *help_aliases[] = {"h", "?"};56 const char *exit_aliases[] = {"q", "quit"}; 57 const char *help_aliases[] = {"h", "?"}; 59 58 60 59 /* List of aliases */ -
com32/hdt/hdt-common.c
r9ffe8b r47ac91 34 34 #include "../lib/sys/vesa/vesa.h" 35 35 #include "hdt-common.h" 36 #include "lib-ansi.h"37 36 #include <disk/util.h> 37 #include <disk/mbrs.h> 38 38 39 39 /* ISOlinux requires a 8.3 format */ … … 269 269 if (err == -1 || !hardware->disk_info[i].cbios) 270 270 continue; 271 272 /* Detect MBR */ 273 hardware->mbr_ids[i] = get_mbr_id(&hardware->disk_info[i]); 271 274 272 275 hardware->disks_count++; … … 535 538 } 536 539 540 /* remove trailing LF */ 541 char *remove_trailing_lf(char *p) 542 { 543 char *save=p; 544 p+=strlen(p)-1; 545 while (*p && *p == 10) { 546 *p='\0'; 547 p--; 548 } 549 p=save; 550 551 return p; 552 } 553 537 554 /* delete multiple spaces, one is enough */ 538 555 char *del_multi_spaces(char *p) { -
com32/hdt/hdt-common.h
rf8ac66 r47ac91 33 33 #include "sys/pci.h" 34 34 35 #include <disk/bootloaders.h> 36 #include <disk/errno_disk.h> 37 #include <disk/error.h> 35 38 #include <disk/geom.h> 39 #include <disk/mbrs.h> 40 #include <disk/msdos.h> 41 #include <disk/partition.h> 42 #include <disk/swsusp.h> 43 #include <disk/read.h> 36 44 37 45 #include "cpuid.h" … … 40 48 #include "../lib/sys/vesa/vesa.h" 41 49 #include <vpd/vpd.h> 50 #include <libansi.h> 42 51 43 52 /* Declare a variable or data structure as unused. */ … … 51 60 extern int display_line_nb; 52 61 62 #define pause_printf() do {\ 63 printf("--More--");\ 64 get_key(stdin, 0);\ 65 printf("\n");\ 66 } while (0); 67 53 68 #define more_printf(...) do {\ 54 if (display_line_nb == 2 3) {\55 printf(" Press any key to continue\n");\69 if (display_line_nb == 20) {\ 70 printf("\nPress any key to continue");\ 56 71 display_line_nb=0;\ 57 72 get_key(stdin, 0);\ … … 115 130 struct pci_domain *pci_domain; /* PCI Devices */ 116 131 struct driveinfo disk_info[256]; /* Disk Information */ 132 uint32_t mbr_ids[256]; /* MBR ids */ 117 133 int disks_count; /* Number of detected disks */ 118 134 struct s_pxe pxe; … … 147 163 const char *find_argument(const char **argv, const char *argument); 148 164 char *remove_spaces(char *p); 165 char *remove_trailing_lf(char *p); 149 166 char *skip_spaces(char *p); 150 167 char *del_multi_spaces(char *p); -
com32/hdt/hdt-menu-disk.c
r9ffe8b re9069c 28 28 29 29 #include <stdlib.h> 30 #include <disk/errno_disk.h>31 #include <disk/geom.h>32 #include <disk/read.h>33 #include <disk/partition.h>34 #include <disk/error.h>35 #include <disk/msdos.h>36 #include <disk/swsusp.h>37 30 38 31 #include "hdt-menu.h" … … 82 75 { 83 76 char size[9]; 77 char bootloader_name[9]; 84 78 char *parttype; 85 79 unsigned int start, end; … … 121 115 add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); 122 116 117 if (get_bootloader_string(drive_info, ptab, bootloader_name, 9) == 0) { 118 snprintf(buffer, sizeof buffer, "Bootloader : %s", 119 bootloader_name); 120 snprintf(statbuffer, sizeof statbuffer, "Bootloader: %s", 121 bootloader_name); 122 add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); 123 } 124 123 125 snprintf(buffer, sizeof buffer, "Bootable : %s", 124 126 (ptab->active_flag == 0x80) ? "Yes" : "No"); … … 158 160 /* Compute the disk submenu */ 159 161 static int compute_disk_module(struct s_my_menu *menu, int nb_sub_disk_menu, 160 struct driveinfo *d, int disk_number)162 const struct s_hardware *hardware, int disk_number) 161 163 { 162 164 char buffer[MENULEN + 1]; 163 165 char statbuffer[STATLEN + 1]; 166 char mbr_name[50]; 167 struct driveinfo *d = (struct driveinfo*) hardware->disk_info; 164 168 165 169 snprintf(buffer, sizeof buffer, " Disk <0x%X> (EDD %X)", d[disk_number].disk, … … 182 186 183 187 snprintf(buffer, sizeof buffer, "Host Bus / Interface : %s / %s", 184 remove_spaces( d[disk_number].edd_params.host_bus_type),188 remove_spaces((char *) d[disk_number].edd_params.host_bus_type), 185 189 d[disk_number].edd_params.interface_type); 186 190 snprintf(statbuffer, sizeof statbuffer, "Host Bus / Interface: %s / %s", 187 remove_spaces( d[disk_number].edd_params.host_bus_type),191 remove_spaces((char *) d[disk_number].edd_params.host_bus_type), 188 192 d[disk_number].edd_params.interface_type); 189 193 add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); … … 208 212 menu[nb_sub_disk_menu].items_count++; 209 213 214 get_mbr_string(hardware->mbr_ids[disk_number], &mbr_name, 50); 215 216 snprintf(buffer, sizeof buffer, "MBR : %s (0x%X)", 217 remove_spaces(mbr_name), 218 hardware->mbr_ids[disk_number]); 219 snprintf(statbuffer, sizeof statbuffer, "MBR: %s (id 0x%X)", 220 remove_spaces(mbr_name), 221 hardware->mbr_ids[disk_number]); 222 add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); 223 menu[nb_sub_disk_menu].items_count++; 224 210 225 dn=disk_number; 211 226 … … 220 235 221 236 /* Compute the Disks menu */ 222 void compute_disks(struct s_hdt_menu *menu, struct driveinfo *disk_info, structs_hardware *hardware)237 void compute_disks(struct s_hdt_menu *menu, struct s_hardware *hardware) 223 238 { 224 239 char buffer[MENULEN + 1]; … … 233 248 continue; /* Invalid geometry */ 234 249 compute_disk_module 235 ((struct s_my_menu*) &(menu->disk_sub_menu), nb_sub_disk_menu, disk_info,236 i);250 ((struct s_my_menu*) &(menu->disk_sub_menu), nb_sub_disk_menu, 251 hardware, i); 237 252 nb_sub_disk_menu++; 238 253 } -
com32/hdt/hdt-menu-kernel.c
rdb265a9 r8e7362 76 76 pci_device->dev_info->class_name); 77 77 snprintf(infobar, sizeof infobar, 78 "%04x:%04x %s : %s \n",78 "%04x:%04x %s : %s", 79 79 pci_device->vendor, 80 80 pci_device->product, -
com32/hdt/hdt-menu-pci.c
r157629 r8e7362 168 168 pci_device->dev_info->product_name); 169 169 snprintf(infobar[i], STATLEN, 170 "%02x:%02x.%01x # %s # ID:%04x:%04x[%04x:%04x] # Kmod:%s \n",170 "%02x:%02x.%01x # %s # ID:%04x:%04x[%04x:%04x] # Kmod:%s", 171 171 __pci_bus, __pci_slot, __pci_func, 172 172 pci_device->dev_info->class_name, pci_device->vendor, -
com32/hdt/hdt-menu-processor.c
r5f036a r8ba991 232 232 if (hardware->cpu.flags.now) 233 233 strcat(buffer1, "3dnow! "); 234 if (hardware->cpu.flags.vmx) 235 strcat(buffer1, "vmx "); 236 if (hardware->cpu.flags.svm) 237 strcat(buffer1, "svm "); 234 238 snprintf(buffer, sizeof buffer, "Flags : %s", buffer1); 235 239 snprintf(statbuffer, sizeof statbuffer, "Flags: %s", buffer1); -
com32/hdt/hdt-menu-summary.c
ra00023 r8e7362 190 190 pci_device->dev_info->class_name); 191 191 snprintf(statbuffer, sizeof statbuffer, 192 "%04x:%04x %s : %s \n",192 "%04x:%04x %s : %s", 193 193 pci_device->vendor, 194 194 pci_device->product, -
com32/hdt/hdt-menu-syslinux.c
ra00023 r8e7362 77 77 snprintf(buffer, sizeof buffer, "%s", 78 78 hardware->sv->copyright_string + 1); 79 /* Remove the trailing LF in the copyright string to avoid scrolling */ 79 80 snprintf(statbuffer, sizeof statbuffer, "%s", 80 hardware->sv->copyright_string + 1);81 remove_trailing_lf(hardware->sv->copyright_string + 1)); 81 82 add_item(buffer, statbuffer, OPT_INACTIVE, NULL, 0); 82 83 menu->items_count++; -
com32/hdt/hdt-menu.c
rea541f r47ac91 28 28 29 29 #include "hdt-menu.h" 30 #include <unistd.h> 30 31 31 32 int start_menu_mode(struct s_hardware *hardware, char *version_string) … … 85 86 86 87 /* Keyboard handler for the menu system */ 87 void keys_handler(t_menusystem * ms, t_menuitem * mi, unsigned int scancode) 88 { 89 char nc; 90 91 if ((scancode >> 8) == F1) { // If scancode of F1 88 void keys_handler(t_menusystem * ms __attribute__ (( unused )), t_menuitem * mi, int scancode) 89 { 90 int nr, nc; 91 92 /* 0xFFFF is an invalid helpid */ 93 if (scancode == KEY_F1 && mi->helpid != 0xFFFF) { 92 94 runhelpsystem(mi->helpid); 93 95 } 96 94 97 /* 95 98 * If user hit TAB, and item is an "executable" item 96 99 * and user has privileges to edit it, edit it in place. 97 100 */ 98 if (( (scancode & 0xFF) == 0x09) && (mi->action == OPT_RUN)) {101 if ((scancode == KEY_TAB) && (mi->action == OPT_RUN)) { 99 102 //(isallowed(username,"editcmd") || isallowed(username,"root"))) { 100 nc = getnumcols(); 103 if (getscreensize(1, &nr, &nc)) { 104 /* Unknown screen size? */ 105 nc = 80; 106 nr = 24; 107 } 101 108 /* User typed TAB and has permissions to edit command line */ 102 gotoxy(EDITPROMPT, 1 , ms->menupage);109 gotoxy(EDITPROMPT, 1); 103 110 csprint("Command line:", 0x07); 104 111 editstring(mi->data, ACTIONLEN); 105 gotoxy(EDITPROMPT, 1 , ms->menupage);106 cprint(' ', 0x07, nc - 1 , ms->menupage);112 gotoxy(EDITPROMPT, 1); 113 cprint(' ', 0x07, nc - 1); 107 114 } 108 115 } … … 155 162 compute_processor(&(hdt_menu->cpu_menu), hardware); 156 163 compute_vpd(&(hdt_menu->vpd_menu), hardware); 157 compute_disks(hdt_menu, hardware ->disk_info, hardware);164 compute_disks(hdt_menu, hardware); 158 165 159 166 #ifdef WITH_PCI -
com32/hdt/hdt-menu.h
rf5e4ae r47ac91 30 30 #define DEFINE_HDT_MENU_H 31 31 #include <stdio.h> 32 #include <getkey.h> 32 33 33 34 #include "menu.h" … … 83 84 84 85 TIMEOUTCODE ontimeout(); 85 void keys_handler(t_menusystem * ms , t_menuitem * mi, unsignedint scancode);86 void keys_handler(t_menusystem * ms __attribute__ (( unused )), t_menuitem * mi, int scancode); 86 87 87 88 // PCI Stuff … … 92 93 93 94 // Disk Stuff 94 void compute_disks(struct s_hdt_menu *menu, struct driveinfo *disk_info, structs_hardware *hardware);95 void compute_disks(struct s_hdt_menu *menu, struct s_hardware *hardware); 95 96 96 97 // DMI Stuff -
com32/hdt/hdt.c
r2d34df r486ec6 49 49 struct s_hardware hardware; 50 50 51 snprintf(version_string, sizeof version_string, "%s %s by %s",52 PRODUCT_NAME,VERSION ,AUTHOR);51 snprintf(version_string, sizeof version_string, "%s %s", 52 PRODUCT_NAME,VERSION); 53 53 54 54 /* Opening the Syslinux console */ -
com32/include/cpufeature.h
rb71004 r8ba991 73 73 #define X86_FEATURE_MWAIT (4*32+ 3) /* Monitor/Mwait support */ 74 74 #define X86_FEATURE_DSCPL (4*32+ 4) /* CPL Qualified Debug Store */ 75 #define X86_FEATURE_VMX (4*32+ 5) /* Hardware virtualization */ 75 76 #define X86_FEATURE_EST (4*32+ 7) /* Enhanced SpeedStep */ 76 77 #define X86_FEATURE_TM2 (4*32+ 8) /* Thermal Monitor 2 */ … … 88 89 #define X86_FEATURE_LAHF_LM (6*32+ 0) /* LAHF/SAHF in long mode */ 89 90 #define X86_FEATURE_CMP_LEGACY (6*32+ 1) /* If yes HyperThreading not valid */ 91 #define X86_FEATURE_SVM (6*32+ 2) /* Secure virtual machine */ 90 92 91 93 #endif /* __ASM_I386_CPUFEATURE_H */ -
com32/lib/Makefile
r3ec185 rfa1b9d 53 53 \ 54 54 sys/ansi.o \ 55 \ 56 sys/libansi.o \ 55 57 \ 56 58 sys/ansicon_write.o sys/ansiserial_write.o \ -
com32/lib/sys/ansi.c
redeeda r86e267 37 37 38 38 static const struct term_state default_state = { 39 .state = st_init, 40 .pvt = false, 41 .nparms = 0, 39 42 .xy = {0, 0}, 40 43 .cindex = 0, /* First color table entry */ 41 .vtgraphics = 0,44 .vtgraphics = false, 42 45 .intensity = 1, 43 .underline = 0,44 .blink = 0,45 .reverse = 0,46 .underline = false, 47 .blink = false, 48 .reverse = false, 46 49 .fg = 7, 47 50 .bg = 0, 48 .autocr = 1, /* Mimic \n -> \r\n conversion by default */ 51 .autocr = true, /* Mimic \n -> \r\n conversion by default */ 52 .autowrap = true, /* Wrap lines by default */ 49 53 .saved_xy = {0, 0}, 50 .cursor = 1, 51 .state = st_init, 52 .pvt = 0, 53 .nparms = 0, 54 .cursor = true, 54 55 }; 55 56 … … 124 125 ch = decvt_to_cp437[ch - 0x60]; 125 126 126 op->write_char(xy.x, xy.y, ch, st);127 op->write_char(xy.x, xy.y, BIOS_PAGE, ch, st); 127 128 xy.x++; 128 129 } … … 142 143 case '[': 143 144 st->state = st_csi; 144 st->nparms = st->pvt = 0; 145 st->nparms = 0; 146 st->pvt = false; 145 147 memset(st->parms, 0, sizeof st->parms); 146 148 break; … … 171 173 break; 172 174 } else if (ch == '?') { 173 st->pvt = 1;175 st->pvt = true; 174 176 } else { 175 177 switch (ch) { … … 279 281 case 'h': 280 282 case 'l': 281 { 282 int set = (ch == 'h'); 283 switch (st->parms[0]) { 284 case 20: 285 st->autocr = set; 286 break; 287 case 25: 288 st->cursor = set; 289 op->showcursor(st); 290 break; 291 default: 292 /* Ignore */ 293 break; 294 } 295 } 296 break; 283 { 284 bool set = (ch == 'h'); 285 switch (st->parms[0]) { 286 case 7: /* DECAWM */ 287 st->autowrap = set; 288 break; 289 case 20: /* LNM */ 290 st->autocr = set; 291 break; 292 case 25: /* DECTECM */ 293 st->cursor = set; 294 op->showcursor(st); 295 break; 296 default: 297 /* Ignore */ 298 break; 299 } 300 break; 301 } 297 302 case 'm': 298 303 { … … 422 427 /* If we fell off the end of the screen, adjust */ 423 428 if (xy.x >= cols) { 424 xy.x = 0; 425 xy.y++; 429 if (st->autowrap) { 430 xy.x = 0; 431 xy.y++; 432 } else { 433 xy.x = cols - 1; 434 } 426 435 } 427 436 while (xy.y >= rows) { … … 431 440 432 441 /* Update cursor position */ 433 op->set_cursor(xy.x, xy.y, st->cursor);442 op->set_cursor(xy.x, xy.y, BIOS_PAGE, st->cursor); 434 443 st->xy = xy; 435 444 } -
com32/lib/sys/ansi.h
r6aa75e r86e267 7 7 8 8 #include <inttypes.h> 9 #include <stdbool.h> 9 10 10 11 #define ANSI_MAX_PARMS 16 12 13 #define BIOS_CURXY ((struct curxy *)0x450) /* Array for each page */ 14 #define BIOS_ROWS (*(uint8_t *)0x484) /* Minus one; if zero use 24 (= 25 lines) */ 15 #define BIOS_COLS (*(uint16_t *)0x44A) /* Number of columns on screen */ 16 #define BIOS_PAGE (*(uint8_t *)0x462) /* Current page number */ 11 17 12 18 enum ansi_state { … … 23 29 24 30 struct term_state { 25 struct curxy xy;26 int cindex; /* SOH color index */27 int vtgraphics; /* VT graphics on/off */28 int intensity;29 int underline;30 int blink;31 int reverse;32 int fg;33 int bg;34 int autocr;35 struct curxy saved_xy;36 int cursor;37 31 enum ansi_state state; 38 int pvt; /* Private code? */39 32 int nparms; /* Number of parameters seen */ 40 33 int parms[ANSI_MAX_PARMS]; 34 bool pvt; /* Private code? */ 35 struct curxy xy; 36 struct curxy saved_xy; 37 uint8_t cindex; /* SOH color index */ 38 uint8_t fg; 39 uint8_t bg; 40 uint8_t intensity; 41 bool vtgraphics; /* VT graphics on/off */ 42 bool underline; 43 bool blink; 44 bool reverse; 45 bool autocr; 46 bool autowrap; 47 bool cursor; 41 48 }; 42 49 … … 44 51 void (*erase) (const struct term_state * st, int x0, int y0, int x1, 45 52 int y1); 46 void (*write_char) (int x, int y, uint8_t ch, const struct term_state * st);53 void (*write_char) (int x, int y, int page, uint8_t ch, const struct term_state * st); 47 54 void (*showcursor) (const struct term_state * st); 48 55 void (*scroll_up) (const struct term_state * st); 49 void (*set_cursor) (int x, int y, int visible);56 void (*set_cursor) (int x, int y, int page, int visible); 50 57 void (*beep) (void); 51 58 }; -
com32/lib/sys/ansicon_write.c
r11c6d38 re9b317 45 45 46 46 static void ansicon_erase(const struct term_state *, int, int, int, int); 47 static void ansicon_write_char(int, int, uint8_t, const struct term_state *);47 static void ansicon_write_char(int, int, int, uint8_t, const struct term_state *); 48 48 static void ansicon_showcursor(const struct term_state *); 49 49 static void ansicon_scroll_up(const struct term_state *); 50 static void ansicon_set_cursor(int, int, int );50 static void ansicon_set_cursor(int, int, int, int); 51 51 52 52 static struct term_state ts; … … 65 65 .op = &__ansicon_ops 66 66 }; 67 68 #define BIOS_CURXY ((struct curxy *)0x450) /* Array for each page */69 #define BIOS_ROWS (*(uint8_t *)0x484) /* Minus one; if zero use 24 (= 25 lines) */70 #define BIOS_COLS (*(uint16_t *)0x44A)71 #define BIOS_PAGE (*(uint8_t *)0x462)72 67 73 68 /* Reference counter to the screen, to keep track of if we need … … 177 172 } 178 173 179 static void ansicon_set_cursor(int x, int y, int visible) 180 { 181 const int page = BIOS_PAGE; 174 static void ansicon_set_cursor(int x, int y, int page, int visible) 175 { 182 176 struct curxy xy = BIOS_CURXY[page]; 183 177 static com32sys_t ireg; … … 194 188 } 195 189 196 static void ansicon_write_char(int x, int y, uint8_t ch,190 static void ansicon_write_char(int x, int y, int page, uint8_t ch, 197 191 const struct term_state *st) 198 192 { 199 193 static com32sys_t ireg; 200 194 201 ansicon_set_cursor(x, y, 0 );195 ansicon_set_cursor(x, y, 0, page); 202 196 203 197 ireg.eax.b[1] = 0x09; 204 198 ireg.eax.b[0] = ch; 205 ireg.ebx.b[1] = BIOS_PAGE;199 ireg.ebx.b[1] = page; 206 200 ireg.ebx.b[0] = ansicon_attribute(st); 207 201 ireg.ecx.w[0] = 1; -
com32/mboot/map.c
rfd0064 r3d6f51 128 128 mbh_len = 12; 129 129 130 if (i + mbh_len <len)130 if (i + mbh_len > len) 131 131 mbh_len = 0; /* Invalid... */ 132 132 else -
com32/modules/Makefile
r0b19ab r08d95c 19 19 include ../MCONFIG 20 20 21 MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 disk.c32\22 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 meminfo.c32 \23 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 kbdmap.c32 cmd.c32 \24 vpdtest.c3221 MODULES = chain.c32 config.c32 ethersel.c32 dmitest.c32 cpuidtest.c32 \ 22 disk.c32 pcitest.c32 elf.c32 linux.c32 reboot.c32 pmload.c32 \ 23 meminfo.c32 sdi.c32 sanboot.c32 ifcpu64.c32 vesainfo.c32 \ 24 kbdmap.c32 cmd.c32 vpdtest.c32 gpxecmd.c32 25 25 26 26 TESTFILES = -
com32/modules/chain.c
rf4b44a r3fc312 447 447 448 448 if (!mmap) { 449 error("Cannot read system memory map ");449 error("Cannot read system memory map\n"); 450 450 return; 451 451 } … … 548 548 549 549 too_big: 550 error("Loader file too large ");550 error("Loader file too large\n"); 551 551 return; 552 552 553 553 enomem: 554 error("Out of memory ");554 error("Out of memory\n"); 555 555 return; 556 556 } … … 615 615 uint32_t segval = strtoul(argv[i] + 4, NULL, 0); 616 616 if (segval < 0x50 || segval > 0x9f000) { 617 error("Invalid segment ");617 error("Invalid segment\n"); 618 618 goto bail; 619 619 } … … 651 651 } else { 652 652 error 653 ("Usage: chain.c32 (hd#|fd#|mbr:#|boot)[,partition] [options]\n"); 653 ("Usage: chain.c32 hd<disk#> [<partition>] [options]\n" 654 " chain.c32 fd<disk#> [options]\n" 655 " chain.c32 mbr:<id> [<partition>] [options]\n" 656 " chain.c32 boot [<partition>] [options]\n" 657 "Options: file=<loader> load file, instead of boot sector\n" 658 " ntldr=<loader> load Windows bootloaders: NTLDR, SETUPLDR, BOOTMGR\n" 659 " freedos=<loader> load FreeDOS kernel.sys\n" 660 " msdos=<loader> load MS-DOS io.sys\n" 661 " pcdos=<loader> load PC-DOS ibmbio.com\n" 662 " seg=<segment> jump to <seg>:0000 instead of 0000:7C00\n" 663 " swap swap drive numbers, if bootdisk is not fd0/hd0\n" 664 " hide hide primary partitions, except selected partition\n"); 654 665 goto bail; 655 666 } -
com32/modules/cpuidtest.c
r7dc104 r8ba991 122 122 if (cpu.flags.now) 123 123 printf("3dnow! "); 124 if (cpu.flags.vmx) 125 printf("vmx "); 126 if (cpu.flags.svm) 127 printf("svm "); 124 128 printf("\n"); 125 129 printf("SMP = "); -
core/localboot.inc
r541778 r96281d 32 32 mov si,localboot_msg 33 33 call writestr 34 call cleanup_hardware 34 35 cmp ax,-1 35 36 je .int18 -
core/pxelinux.asm
r3cdc49 r1d8b22 225 225 bootsec equ $ 226 226 _start: 227 jmp 0:_start1 ; Canonicalize the address and skip 228 ; the patch header 229 230 ; 231 ; Patch area for adding hardwired DHCP options 232 ; 233 align 4 234 235 hcdhcp_magic dd 0x2983c8ac ; Magic number 236 hcdhcp_len dd 7*4 ; Size of this structure 237 hcdhcp_flags dd 0 ; Reserved for the future 238 ; Parameters to be parsed before the ones from PXE 239 bdhcp_offset dd 0 ; Offset (entered by patcher) 240 bdhcp_len dd 0 ; Length (entered by patcher) 241 ; Parameters to be parsed *after* the ones from PXE 242 adhcp_offset dd 0 ; Offset (entered by patcher) 243 adhcp_len dd 0 ; Length (entered by patcher) 244 245 _start1: 227 246 pushfd ; Paranoia... in case of return to PXE 228 247 pushad ; ... save as much state as possible … … 237 256 mov es,ax 238 257 239 jmp 0:_start1 ; Canonicalize address240 _start1:241 258 ; That is all pushed onto the PXE stack. Save the pointer 242 259 ; to it and switch to an internal stack. … … 253 270 lss esp,[BaseStack] 254 271 sti ; Stack set up and ready 272 ; 273 ; Move the hardwired DHCP options (if present) to a safe place... 274 ; 275 bdhcp_copy: 276 mov cx,[bdhcp_len] 277 mov ax,trackbufsize/2 278 jcxz .none 279 cmp cx,ax 280 jbe .oksize 281 mov cx,ax 282 mov [bdhcp_len],ax 283 .oksize: 284 mov eax,[bdhcp_offset] 285 add eax,_start 286 mov si,ax 287 and si,000Fh 288 shr eax,4 289 push ds 290 mov ds,ax 291 mov di,trackbuf 292 add cx,3 293 shr cx,2 294 rep movsd 295 pop ds 296 .none: 297 298 adhcp_copy: 299 mov cx,[adhcp_len] 300 mov ax,trackbufsize/2 301 jcxz .none 302 cmp cx,ax 303 jbe .oksize 304 mov cx,ax 305 mov [adhcp_len],ax 306 .oksize: 307 mov eax,[adhcp_offset] 308 add eax,_start 309 mov si,ax 310 and si,000Fh 311 shr eax,4 312 push ds 313 mov ds,ax 314 mov di,trackbuf+trackbufsize/2 315 add cx,3 316 shr cx,2 317 rep movsd 318 pop ds 319 .none: 255 320 256 321 ; … … 267 332 mov si,copyright_str 268 333 call writestr_early 334 335 ; 336 ; Look to see if we are on an EFI CSM system. Some EFI 337 ; CSM systems put the BEV stack in low memory, which means 338 ; a return to the PXE stack will crash the system. However, 339 ; INT 18h works reliably, so in that case hack the stack and 340 ; point the "return address" to an INT 18h instruction. 341 ; 342 ; Hack the stack instead of the much simpler "just invoke INT 18h 343 ; if we want to reset", so that chainloading other NBPs will work. 344 ; 345 efi_csm_workaround: 346 les bp,[InitStack] ; GS:SP -> original stack 347 les bx,[es:bp+44] ; Return address 348 cmp word [es:bx],18CDh ; Already pointing to INT 18h? 349 je .skip 350 351 ; Search memory from E0000 to FFFFF for a $EFI structure 352 mov bx,0E000h 353 .scan_mem: 354 mov es,bx 355 cmp dword [es:0],'IFE$' ; $EFI is byte-reversed... 356 jne .not_here 357 ; 358 ; Verify the table. We don't check the checksum because 359 ; it seems some CSMs leave it at zero. 360 ; 361 movzx cx,byte [es:5] ; Table length 362 cmp cx,83 ; 83 bytes is the current length... 363 jae .found_it 364 365 .not_here: 366 inc bx 367 jnz .scan_mem 368 jmp .skip ; No $EFI structure found 369 370 ; 371 ; Found a $EFI structure. Move down the original stack 372 ; and put an INT 18h instruction there instead. 373 ; 374 .found_it: 375 %if USE_PXE_PROVIDED_STACK 376 mov cx,efi_csm_hack_size 377 mov si,sp 378 sub sp,cx 379 mov di,sp 380 mov ax,ss 381 mov es,ax 382 sub [InitStack],cx 383 sub [BaseStack],cx 384 %else 385 les si,[InitStack] 386 lea di,[si-efi_csm_hack_size] 387 mov [InitStack],di 388 %endif 389 lea cx,[bp+52] ; End of the stack we care about 390 sub cx,si 391 es rep movsb 392 mov [es:di-8],di ; Clobber the return address 393 mov [es:di-6],es 394 mov si,efi_csm_hack 395 mov cx,efi_csm_hack_size 396 rep movsb 397 398 .skip: 399 400 section .data 401 alignz 4 402 efi_csm_hack: 403 int 18h 404 jmp 0F000h:0FFF0h 405 hlt 406 efi_csm_hack_size equ $-efi_csm_hack 407 408 section .text 269 409 270 410 ; … … 451 591 mov [LocalDomain],al ; No LocalDomain received 452 592 593 594 ; This is a good time to initialize DHCPMagic... 595 ; Initialize it to 1 meaning we will accept options found; 596 ; in earlier versions of PXELINUX bit 0 was used to indicate 597 ; we have found option 208 with the appropriate magic number; 598 ; we no longer require that, but MAY want to re-introduce 599 ; it in the future for vendor encapsulated options. 600 mov byte [DHCPMagic],1 601 602 ; 603 ; Process any hardwired options the user may have specified. This is 604 ; different than the actual packets in that there is no header, just 605 ; an option field. 606 ; 607 mov cx,[bdhcp_len] 608 mov si,trackbuf 609 call parse_dhcp_options 610 453 611 ; 454 612 ; The DHCP client identifiers are best gotten from the DHCPREQUEST … … 462 620 call pxe_get_cached_info 463 621 call parse_dhcp 464 465 ; We don't use flags from the request packet, so466 ; this is a good time to initialize DHCPMagic...467 ; Initialize it to 1 meaning we will accept options found;468 ; in earlier versions of PXELINUX bit 0 was used to indicate469 ; we have found option 208 with the appropriate magic number;470 ; we no longer require that, but MAY want to re-introduce471 ; it in the future for vendor encapsulated options.472 mov byte [DHCPMagic],1473 622 474 623 ; … … 513 662 call parse_dhcp ; Parse DHCP packet 514 663 call crlf 664 665 ; 666 ; Process any hardwired options the user may have specified. This is 667 ; different than the actual packets in that there is no header, just 668 ; an option field. This handles the "after" options 669 ; 670 mov cx,[adhcp_len] 671 mov si,trackbuf+trackbufsize/2 672 call parse_dhcp_options 515 673 516 674 ; … … 790 948 call writestr_early 791 949 ; Restore the environment we were called with 950 call cleanup_hardware 792 951 lss sp,[InitStack] 793 952 pop gs … … 2177 2336 ; 2178 2337 ; Get a DHCP packet from the PXE stack into the trackbuf. 2338 ; Leaves the upper half of the trackbuf untouched. 2179 2339 ; 2180 2340 ; Input: … … 2197 2357 movzx ax,dl 2198 2358 stosw ; Packet type 2199 mov ax,trackbufsize 2359 mov ax,trackbufsize/2 2200 2360 stosw ; Buffer size 2201 2361 mov ax,trackbuf -
core/serirq.inc
ree8989 r03ae23 92 92 SerialTail dw 0 ; Tail of serial port rx buffer 93 93 94 section .bss 95 IRQMask resw 1 ; PIC IRQ mask status 96 94 97 section .text 95 98 … … 133 136 mov al,1 ; Enable receive interrupt 134 137 slow_out dx,al 138 139 ; 140 ; Enable all ther interupt lines at the PIC. Some BIOSes 141 ; only enable the timer interrupts and other interrupts 142 ; actively in use by the BIOS. 143 ; 144 in al,0xA1 ; Secondary PIC mask register 145 mov ah,al 146 in al,0x21 ; Primary PIC mask register 147 mov [IRQMask],ax 148 149 io_delay 150 151 xor ax,ax ; Remove all interrupt masks 152 out 0x21,al 153 out 0xA1,al 135 154 136 155 popad … … 157 176 slow_out dx,al ; Clear IER 158 177 178 ; Restore PIC masks 179 mov ax,[IRQMask] 180 out 0x21,al 181 mov al,ah 182 out 0xA1,al 183 159 184 ; Restore the original interrupt vectors 160 185 mov si,oldirq0 … … 165 190 mov cx,8 166 191 rep movsd 192 193 xor ax,ax 194 mov [SerialIRQPort],ax ; No active interrupt system 167 195 168 196 .done: -
modules/Makefile
rcc460b r37dce9 20 20 INCLUDES = -I$(com32)/include 21 21 22 BINS = pxechain.com gfxboot.com poweroff.com 22 BINS = pxechain.com gfxboot.com poweroff.com int18.com 23 23 24 24 all: $(BINS) -
utils/Makefile
re462c2 r87d502 22 22 23 23 TARGETS = mkdiskimage isohybrid gethostip 24 ASIS = keytab-lilo lss16toppm md5pass ppmtolss16 sha1pass syslinux2ansi 24 ASIS = keytab-lilo lss16toppm md5pass ppmtolss16 sha1pass syslinux2ansi \ 25 pxelinux-options 25 26 26 27 ISOHDPFX = ../mbr/isohdpfx.bin ../mbr/isohdpfx_f.bin ../mbr/isohdpfx_c.bin \
