void ScreenSaverC::TurnOff(void) { #ifndef WINCIT if (On) { On = FALSE; logiScreen = physScreen; dgLogiScreen = logiScreen; restore_screen(); curson(); StatusLine.Update(WC_TWp); } #endif }
void putlogo(void) { /* this function display the uvea logo on the screen */ unsigned size; void far *ptr[3]; FILE *fptr; int color; int x,y,count; /* logo based on these dimensions: 105,0,565,465 */ size=imagesize(105,0,565,(465+1)/3); fptr=fopen("LOGO3.PIC","rb"); restore_screen(fptr,size); fclose(fptr); /* wait */ sleep(2); removelogo(); }
void keyboard_handler(uint32_t scancode){ if(scancode != 250){ if(sleep_time >= screensaver_time){ restore_screen(); }else{ if(piano == 1){ //print_number(scancode); uint32_t frec = getFrec(scancode); if(frec == 8){ sys_write('\n',0xFF); piano = 0; } playPiano(frec); } else if(check_special_key(scancode)){ if(keyboard_set_key(scancode_to_char(scancode))) sys_write(scancode_to_char(scancode),0xFF); } } sleep_time = 0; } }
void shell_out(void){ char *comspec; #ifndef __TURBOC__ char key; int val; char *str; #endif /* __TURBOC__ */ save_screen(); clear_screen(); puts("[Entering DOS shell, type exit to return to game.]"); msdos_noraw(); ignore_signals(); if((comspec=getenv("COMSPEC")) ==NULL || spawnl(P_WAIT,comspec,comspec,(char *)NULL)<0){ puts("Sorry, there seems to be a problem with shell_out()"); printf("comspec = %s\n",comspec); flush(); puts("Hit a key to continue"); while(!kbhit()) ; } restore_signals(); restore_screen(); }
int error(const char *string, unsigned int type, unsigned int options, unsigned int code) { const char *type_name; int t1 = 9, ret = 0; char temp[5]; int x; // Find the name of this error type. if(type >= sizeof(error_type_names) / sizeof(*error_type_names)) type = 0; type_name = error_type_names[type]; // If graphics couldn't initialize, print the error to stderr and abort. if(!has_video_initialized()) { fprintf(stderr, "%s%s\n", type_name, string); exit(-1); } // Window set_context(code >> 8); m_hide(); save_screen(); dialog_fadein(); draw_window_box(1, 10, 78, 14, 76, 64, 72, 1, 1); // Add title and error name x = 40 - (int)strlen(type_name)/2; write_string(type_name, x, 10, 78, 0); write_string(string, 40 - ((Uint32)strlen(string) / 2), 11, 79, 0); // Add options write_string("Press", 4, 13, 78, 0); if(options & ERROR_OPT_FAIL) { write_string(", F for Fail", t1, 13, 78, 0); t1 += 12; } if(options & ERROR_OPT_RETRY) { write_string(", R to Retry", t1, 13, 78, 0); t1 += 12; } if(options & ERROR_OPT_EXIT) { write_string(", E to Exit", t1, 13, 78, 0); t1 += 11; } if(options & ERROR_OPT_OK) { write_string(", O for OK", t1, 13, 78, 0); t1 += 10; } draw_char('.', 78, t1, 13); draw_char(':', 78, 9, 13); // Add code if not 0 if(code != 0) { write_string(" Debug code:0000h ", 30, 14, 64, 0); sprintf(temp, "%x", code); write_string(temp, 46 - (Uint32)strlen(temp), 14, 64, 0); } update_screen(); // Get key do { wait_event(); t1 = get_key(keycode_internal); //Process switch(t1) { case IKEY_f: fail: if(!(options & ERROR_OPT_FAIL)) break; ret = ERROR_OPT_FAIL; break; case IKEY_r: retry: if(!(options & ERROR_OPT_RETRY)) break; ret = ERROR_OPT_RETRY; break; case IKEY_e: exit: if(!(options & ERROR_OPT_EXIT)) break; ret = ERROR_OPT_EXIT; break; case IKEY_o: ok: if(!(options & ERROR_OPT_OK)) break; ret = ERROR_OPT_OK; break; case IKEY_h: if(!(options & ERROR_OPT_HELP)) break; // Call help break; case IKEY_ESCAPE: // Escape. Order of options this applies to- // Fail, Ok, Retry, Exit. if(options & ERROR_OPT_FAIL ) goto fail; if(options & ERROR_OPT_OK ) goto ok; if(options & ERROR_OPT_RETRY) goto retry; goto exit; case IKEY_RETURN: // Enter. Order of options this applies to- // OK, Retry, Fail, Exit. if(options & ERROR_OPT_OK ) goto ok; if(options & ERROR_OPT_RETRY) goto retry; if(options & ERROR_OPT_FAIL ) goto fail; goto exit; } } while(ret == 0); pop_context(); // Restore screen and exit appropriately dialog_fadeout(); restore_screen(); m_show(); if(ret == ERROR_OPT_EXIT) // Exit the program { platform_quit(); exit(-1); } return ret; }
void help_display(struct world *mzx_world, char *help, int offs, char *file, char *label) { // Display a help file int pos = offs, old_pos; // Where int key = 0; int t1; char mclick; // allow_help = 0; // Draw screen save_screen(); dialog_fadein(); scroll_edging_ext(mzx_world, 3, 256, 16); // Loop file[0] = label[0] = 0; do { // Display scroll help_frame(mzx_world, help, pos); mclick = 0; update_screen(); update_event_status_delay(); if(get_mouse_press()) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); // Move to line clicked on if mouse is in scroll, else exit if((mouse_y >= 6) && (mouse_y <= 18) && (mouse_x >= 8) && (mouse_x <= 71)) { mclick = 1; t1 = mouse_y - 12; if(t1 == 0) goto option; //t1<0 = PGUP t1 lines //t1>0 = PGDN t1 lines if(t1 < 0) goto pgup; goto pgdn; } key = IKEY_ESCAPE; } key = get_key(keycode_internal); old_pos = pos; switch(key) { case IKEY_F1: { if(get_alt_status(keycode_internal)) { // Jump to label 072 in MAIN.HLP strcpy(file,"MAIN.HLP"); strcpy(label,"072"); } else { // Jump to label 000 in HELPONHE.HLP strcpy(file, "HELPONHE.HLP"); strcpy(label, "000"); } goto ex; } case IKEY_UP: { // Go back a line (if possible) if(help[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((help[pos] != '\n') && (help[pos] != 1)); pos++; // Done. break; } case IKEY_DOWN: { // Go forward a line (if possible) while(help[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(help[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. break; } case IKEY_RETURN: { option: // Option? if((help[pos] == 255) && ((help[pos + 1] == '>') || (help[pos + 1] == '<'))) { // Yep! pos++; if(help[pos] == '<') { // Get file and label and exit t1 = 0; pos++; do { pos++; file[t1] = help[pos]; t1++; } while(help[pos] != ':'); file[t1 - 1] = 0; strcpy(label, help + pos + 1); goto ex; } // Get label and jump strcpy(label, help + pos + 2); // Search backwards for a 1 do { pos--; } while(help[pos] != 1); // Search for label OR a \n followed by a \0 do { pos++; if(help[pos] == 255) if(help[pos + 1] == ':') if(!strcmp(help + pos + 3, label)) // pos is correct! goto labdone; if(help[pos] == '\n') if(help[pos + 1] == 0) break; } while(1); } // If there WAS an option, any existing label was found. labdone: break; } case IKEY_PAGEDOWN: { for(t1 = 6; t1 > 0; t1--) { pgdn: // Go forward a line (if possible) old_pos = pos; while(help[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(help[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. } if(mclick) goto option; break; } case IKEY_PAGEUP: { for(t1 = -6; t1 < 0; t1++) { pgup: // Go back a line (if possible) if(help[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((help[pos] != '\n') && (help[pos] != 1)); pos++; // Done. } if(mclick) goto option; break; } case IKEY_HOME: { // FIXME - :( t1 = -30000; goto pgup; } case IKEY_END: { t1 = 30000; goto pgdn; } default: { break; } } } while(key != IKEY_ESCAPE); // Restore screen and exit ex: dialog_fadeout(); restore_screen(); }
void scroll_edit(struct world *mzx_world, struct scroll *scroll, int type) { // Important status vars (insert kept in intake.cpp) unsigned int pos = 1, old_pos; // Where IN scroll? int currx = 0; // X position in line int key; // Key returned by intake() int t1, t2 = -1, t3; char *where; // Where scroll is char line[80]; // For editing int scroll_base_color = mzx_world->scroll_base_color; bool editing = (type == 2); // Draw screen save_screen(); dialog_fadein(); if(editing) scroll_edging_ext(mzx_world, type, 256, 16); else scroll_edging_ext(mzx_world, type, 0, 16); // Loop where = scroll->mesg; do { // If the user wants to mask, and we're in the editor.. bool mask = mzx_world->conf.mask_midchars && editing; // Display scroll scroll_frame(mzx_world, scroll, pos, mask); update_screen(); if(editing) { // Figure length for(t1 = 0; t1 < 80; t1++) { if(where[pos + t1] == '\n') break; } // t1 == length // Edit line where[pos + t1] = 0; strcpy(line, where + pos); where[pos + t1] = '\n'; key = intake(mzx_world, line, 64, 8, 12, scroll_base_color, 2, 0, &currx, 0, NULL); // Modify scroll to hold new line (give errors here) t2 = (int)strlen(line); // Get length of NEW line // Resize and move t3 = scroll->mesg_size; if(t2 - t1 > 0) { reallocate_scroll(scroll, t3 + t2 - t1); where = scroll->mesg; memmove(where + pos + t2, where + pos + t1, t3 - pos - t1); } else if(t2 - t1 < 0) { memmove(where + pos + t2, where + pos + t1, t3 - pos - t1); reallocate_scroll(scroll, t3 + t2 - t1); where = scroll->mesg; } // Copy in new line strcpy(where + pos, line); where[pos + t2] = '\n'; } else { update_event_status_delay(); key = get_key(keycode_internal); } old_pos = pos; if(get_mouse_press() || (key == -1)) { int mouse_x, mouse_y; get_mouse_position(&mouse_x, &mouse_y); if((mouse_y >= 6) && (mouse_y <= 18) && (mouse_x >= 8) && (mouse_x <= 71)) { t1 = mouse_y - 12; if(t1) { if(t1 < 0) goto pgdn; else goto pgup; } } key = IKEY_ESCAPE; } switch(key) { case IKEY_UP: { // Go back a line (if possible) if(where[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((where[pos] != '\n') && (where[pos] != 1)); pos++; // Done. break; } case IKEY_DOWN: { // Go forward a line (if possible) while(where[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(where[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. break; } case IKEY_RETURN: { if(type < 2) { key = IKEY_ESCAPE; } else { // Add in new line below. Need only add one byte. t3 = scroll->mesg_size; reallocate_scroll(scroll, t3 + 1); where = scroll->mesg; // Move all at pos + currx up a space memmove(where + pos + currx + 1, where + pos + currx, t3 - pos - currx); // Insert a \n where[pos + currx] = '\n'; // Change pos and currx pos = pos + currx + 1; currx = 0; scroll->num_lines++; } break; } case IKEY_BACKSPACE: { if(type < 2) break; // We are at the start of the current line and we are trying to // append it to the end of the previous line. First, remember // the size of the current line is in t2. Now we go back a line, // if there is one. if(where[pos - 1] == 1) break; // Nope. pos--; // Go to start of this line, COUNTING CHARACTERS. t1 = 0; do { pos--; t1++; } while((where[pos] != '\n') && (where[pos] != 1)); // pos is at one before the start of this line. WHO CARES!? :) // Now we have to see if the size, t2, is over 64 characters. // t2 + t1 is currently one too many so check for >65 for error. if((t2 + t1) > 65) { pos = old_pos; break; // Too long. Reset position. } // OKAY! Just copy backwards over the \n in the middle to // append... t3 = scroll->mesg_size; memmove(where + (old_pos - 1), where + old_pos, t3 - (old_pos + 1)); // ...and reallocate to one space less! reallocate_scroll(scroll, t3 - 1); where = scroll->mesg; // pos is one before this start. Fix to the start of this new // line. Set currx to the length of the old line this was. pos++; currx = (int)t1 - 1; scroll->num_lines--; // FIXME - total hack! scroll->mesg[scroll->mesg_size - 1] = 0; // Done. break; } case IKEY_PAGEDOWN: { for(t1 = 6; t1 > 0; t1--) { pgdn: // Go forward a line (if possible) old_pos = pos; while(where[pos] != '\n') pos++; // At end of current. Is there a next line? pos++; if(where[pos] == 0) { // Nope. pos = old_pos; break; } // Yep. Done. } break; } case IKEY_PAGEUP: { for(t1 = -6; t1 < 0; t1++) { pgup: // Go back a line (if possible) if(where[pos - 1] == 1) break; // Can't. pos--; // Go to start of this line. do { pos--; } while((where[pos] != '\n') && (where[pos] != 1)); pos++; // Done. } break; } case IKEY_HOME: { // FIXME - This is so dirty. Please replace it. t1 = -30000; goto pgup; } case IKEY_END: { // FIXME - See above. t1 = 30000; goto pgdn; } default: case IKEY_ESCAPE: case 0: break; } // Continue? } while(key != IKEY_ESCAPE); // Restore screen and exit restore_screen(); dialog_fadeout(); }
void screen_map() { register int i, j; static int8u screen_border[2][6] = { {'+', '+', '+', '+', '-', '|'}, /* normal chars */ {201, 187, 200, 188, 205, 186} /* graphics chars */ }; int8u map[MAX_WIDTH / RATIO + 1]; int8u tmp; int priority[256]; int row, orow, col, myrow, mycol = 0; char prntscrnbuf[80]; for (i = 0; i < 256; i++) priority[i] = 0; priority['<'] = 5; priority['>'] = 5; priority['@'] = 10; priority[wallsym] = -5; priority[floorsym] = -10; priority['\''] = -3; priority[' '] = -15; save_screen(); clear_screen(); gotoxy(1,1); putch(CH(TL)); for (i = 0; i < MAX_WIDTH / RATIO; i++) putch(CH(HE)); putch(CH(TR)); orow = -1; map[MAX_WIDTH / RATIO] = '\0'; for (i = 0; i < MAX_HEIGHT; i++) { row = i / RATIO; if (row != orow) { if (orow >= 0) { sprintf(prntscrnbuf,"%c%s%c",CH(VE), map, CH(VE)); gotoxy(1,orow+2); cputs(prntscrnbuf); } for (j = 0; j < MAX_WIDTH / RATIO; j++) map[j] = ' '; orow = row; } for (j = 0; j < MAX_WIDTH; j++) { col = j / RATIO; tmp = loc_symbol(i, j); if (priority[map[col]] < priority[tmp]) map[col] = tmp; if (map[col] == '@') { mycol = col + 1; /* account for border */ myrow = row + 1; } } } if (orow >= 0) { sprintf(prntscrnbuf,"%c%s%c",CH(VE), map, CH(VE)); gotoxy(1,orow+2); cputs(prntscrnbuf); } gotoxy(1,orow+3); putch(CH(BL)); for (i = 0; i < MAX_WIDTH / RATIO; i++) putch(CH(HE)); putch(CH(BR)); gotoxy(24,24); cputs("Hit any key to continue"); if (mycol > 0) gotoxy(mycol+1, myrow+1); inkey(); restore_screen(); }
Bool StatusLineC::ToggleFullScreen(WC_TW) { #ifndef WINCIT if (!ScreenSaver.IsOn()) { if (State == SL_FULLSCREEN) { State = SL_ONELINE; logiScreen = physScreen; dgLogiScreen = logiScreen; restore_screen(); curson(); UnlockMessages(MSG_F4SCREEN); return (TRUE); } else { if (!Visible) { Toggle(); } if (State == SL_TWOLINES) { ToggleSecond(); } State = SL_FULLSCREEN; updateStatus = TRUE; if (save_screen()) { logiScreen = saveBuffer; dgLogiScreen = logiScreen; const int oldrow = logiRow, oldcol = logiCol; if (!cfg.really_really_fucking_stupid) { cursoff(); } outPhys(TRUE); cls(SCROLL_NOSAVE); outPhys(FALSE); position(oldrow, oldcol); LockMessages(MSG_F4SCREEN); return (TRUE); } else { State = SL_ONELINE; } } } #endif return (FALSE); }
int start_game(){ char board[ BOARD_HEIGHT ][ BOARD_WIDTH ]; char mtx_brick[4][4]; int score = 0; int level = 0; int lines = 0; int tmp_lines = 0; char x, y; char brick; char next_brick; int vel = 10; timespec req; req.tv_sec = 0; req.tv_nsec = vel * PULSE; srand( time( 0 ) ); memset( board, 0, BOARD_HEIGHT * BOARD_WIDTH ); next_brick = rand() % 7 + 1; init_screen(); WINDOW* wboard = create_wboard(); WINDOW* wpreview = create_wpreview(); WINDOW* wscore = create_wscore(); show_title(); show_score( wscore, score, level, lines ); wait_start( wboard ); bool play = true; while( play ){ brick = next_brick; next_brick = rand() % 7 + 1; show_preview( wpreview, next_brick ); show_score( wscore, score, level, lines ); show_board( wboard, board ); x = ( ( BOARD_WIDTH / 3 ) % 2 == 0 ) ? BOARD_WIDTH / 3 : BOARD_WIDTH / 3 + 1; y = - 3; get_brick( brick, mtx_brick ); bool move = true; int delay = 0; while( move ){ switch( getch() ){ case KEY_UP: move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'z': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_R ); break; case 'x': move_brick( wboard, board, mtx_brick, brick, &y, &x, ROTATE_L ); break; case KEY_DOWN: move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); break; case KEY_LEFT: move_brick( wboard, board, mtx_brick, brick, &y, &x, LEFT ); break; case KEY_RIGHT: move_brick( wboard, board, mtx_brick, brick, &y, &x, RIGHT ); break; case ' ': move_brick( wboard, board, mtx_brick, brick, &y, &x, BOTTOM ); break; case 27: play = move = false; break; case 'q': play = move = false; break; default: break; } // switch( getch() ) if( ++delay == DELAY_DOWN ){ move_brick( wboard, board, mtx_brick, brick, &y, &x, DOWN ); } if( delay == DELAY_BOTTOM ){ delay = 0; if( check_brick(mtx_brick, board, y + 1, x ) ){ move = false; if( y < 0 ) play = false; } } nanosleep( &req, 0 ); } // while( move ) set_board( board, mtx_brick, brick, y, x ); tmp_lines += check_lines( board, &score, &lines ); if( tmp_lines >= CH_LEV ){ req.tv_nsec = vel * PULSE; score += 1; level++; if( vel > 1 ) vel--; tmp_lines = tmp_lines % CH_LEV; } } // while( quit ) delwin( wboard ); delwin( wpreview ); delwin( wscore ); restore_screen(); return 0; }
static void meter_restore_screen(void) { restore_screen(); update_screen(); }
void ident_char() { char command, query; register int i, n; if (get_com("Enter character to be identified :", &command)) switch(command) { /* every printing ASCII character is listed here, in the order in which they appear in the ASCII character set */ case ' ': prt(" - An open pit.", 0, 0); break; case '!': prt("! - A potion.", 0, 0); break; case '"': prt("\" - An amulet, periapt, or necklace.", 0, 0); break; case '#': prt("# - A stone wall.", 0, 0); break; case '$': prt("$ - Treasure.", 0, 0); break; case '%': if (highlight_seams == TRUE) prt("% - A magma or quartz vein.", 0, 0); else prt("% - Not used.", 0, 0); break; case '&': prt("& - Demon (Oh dear!).", 0, 0); break; case '\'': prt("' - An open door.", 0, 0); break; case '(': prt("( - Soft armor.", 0, 0); break; case ')': prt(") - A shield.", 0, 0); break; case '*': prt("* - Gems.", 0, 0); break; case '+': prt("+ - A closed door.", 0, 0); break; case ',': prt(", - Food or mushroom patch.", 0, 0); break; case '-': prt("- - A wand", 0, 0); break; case '.': prt(". - Floor.", 0, 0); break; case '/': prt("/ - A pole weapon.", 0, 0); break; /* case '0': prt("0 - Not used.", 0, 0); break; */ case '1': prt("1 - Entrance to General Store.", 0, 0); break; case '2': prt("2 - Entrance to Armory.", 0, 0); break; case '3': prt("3 - Entrance to Weaponsmith.", 0, 0); break; case '4': prt("4 - Entrance to Temple.", 0, 0); break; case '5': prt("5 - Entrance to Alchemy shop.", 0, 0); break; case '6': prt("6 - Entrance to Magic-Users store.", 0, 0); break; case '7': prt("7 - Entrance to the Healers.", 0, 0); break; case '8': prt("8 - Entrance to your home.", 0, 0); break; /* case '9': prt("9 - Not used.", 0, 0); break;*/ case ':': prt(": - Rubble.", 0, 0); break; case ';': prt("; - A loose rock.", 0, 0); break; case '<': prt("< - An up staircase.", 0, 0); break; case '=': prt("= - A ring.", 0, 0); break; case '>': prt("> - A down staircase.", 0, 0); break; case '?': prt("? - A scroll.", 0, 0); break; case '@': prt(py.misc.name, 0, 0); break; case 'A': prt("A - Angel.", 0, 0); break; case 'B': prt("B - Birds", 0, 0); break; case 'C': prt("C - Canine.", 0, 0); break; case 'D': prt("D - An Ancient Dragon (Beware).", 0, 0); break; case 'E': prt("E - Elemental.", 0, 0); break; case 'F': prt("F - Giant Fly.", 0, 0); break; case 'G': prt("G - Ghost.", 0, 0); break; case 'H': prt("H - Hybrid.", 0, 0); break; case 'I': prt("I - Minor Demon.", 0, 0); break; case 'J': prt("J - Jabberwock.", 0, 0); break; case 'K': prt("K - Killer Beetle.", 0, 0); break; case 'L': prt("L - Lich.", 0, 0); break; case 'M': prt("M - Mummy.", 0, 0); break; /* case 'N': prt("N - Not used.", 0, 0); break; */ case 'O': prt("O - Ogre.", 0, 0); break; case 'P': prt("P - Giant humanoid.", 0, 0); break; case 'Q': prt("Q - Quylthulg (Pulsing Flesh Mound).", 0, 0); break; case 'R': prt("R - Reptiles and Amphibians.", 0, 0); break; case 'S': prt("S - Giant Scorpion/Spider.", 0, 0); break; case 'T': prt("T - Troll.", 0, 0); break; case 'U': prt("U - Umber Hulk.", 0, 0); break; case 'V': prt("V - Vampire.", 0, 0); break; case 'W': prt("W - Wight or Wraith.", 0, 0); break; case 'X': prt("X - Xorn/Xaren.", 0, 0); break; case 'Y': prt("Y - Yeti.", 0, 0); break; case 'Z': prt("Z - Zepher hound (Elemental hound).", 0, 0); break; case '[': prt("[ - Hard armor.", 0, 0); break; case '\\': prt("\\ - A hafted weapon.", 0, 0); break; case ']': prt("] - Misc. armor.", 0, 0); break; case '^': prt("^ - A trap.", 0, 0); break; case '_': prt("_ - A staff.", 0, 0); break; /* case '`': prt("` - Not used.", 0, 0); break; */ case 'a': prt("a - Giant Ant/Ant Lion.", 0, 0); break; case 'b': prt("b - Giant Bat.", 0, 0); break; case 'c': prt("c - Giant Centipede.", 0, 0); break; case 'd': prt("d - a Dragon.", 0, 0); break; case 'e': prt("e - Floating Eye.", 0, 0); break; case 'f': prt("f - Felines", 0, 0); break; case 'g': prt("g - Golem.", 0, 0); break; case 'h': prt("h - Demi-humans.", 0, 0); break; case 'i': prt("i - Icky Thing.", 0, 0); break; case 'j': prt("j - Jelly.", 0, 0); break; case 'k': prt("k - Kobold.", 0, 0); break; case 'l': prt("l - Giant Louse.", 0, 0); break; case 'm': prt("m - Mold.", 0, 0); break; case 'n': prt("n - Naga.", 0, 0); break; case 'o': prt("o - Orc.", 0, 0); break; case 'p': prt("p - Person (Humanoid).", 0, 0); break; case 'q': prt("q - Quadroped.", 0, 0); break; case 'r': prt("r - Rodent.", 0, 0); break; case 's': prt("s - Skeleton.", 0, 0); break; case 't': prt("t - Giant Tick.", 0, 0); break; /* case 'u': prt("u - Unicorn.", 0, 0); break; */ case 'v': prt("v - Vortex.", 0, 0); break; case 'w': prt("w - Worm or Worm Mass.", 0, 0); break; /* case 'x': prt("x - Not used.", 0, 0); break; */ case 'y': prt("y - Yeek.", 0, 0); break; case 'z': prt("z - Zombie.", 0, 0); break; case '{': prt("{ - Arrow, bolt, or bullet.", 0, 0); break; case '|': prt("| - A sword or dagger.", 0, 0); break; case '}': prt("} - Bow, crossbow, or sling.", 0, 0); break; case '~': prt("~ - Tool or miscellaneous item.", 0, 0); break; default: prt("Not Used.", 0, 0); break; } /* Allow access to monster memory. -CJS- */ n = 0; for (i = MAX_CREATURES-1; i >= 0; i--) if ((c_list[i].cchar == command) && bool_roff_recall (i)) { if (n == 0) { put_buffer ("You recall those details? [y/n]", 0, 40); query = inkey(); if (query != 'y' && query != 'Y') break; erase_line (0, 40); save_screen (); } n++; query = roff_recall (i); restore_screen (); if (query == ESCAPE) break; } }
void exec_image(char *image) /* Get a Minix image into core, patch it up and execute. */ { int i; struct image_header hdr; char *buf; u32_t vsec, addr, limit, aout, n, totalmem = 0; struct process *procp; /* Process under construction. */ long a_text, a_data, a_bss, a_stack; int banner= 0; long processor= a2l(b_value("processor")); u16_t kmagic, mode; char *console; char params[SECTOR_SIZE]; extern char *sbrk(int); char *verb; /* The stack is pretty deep here, so check if heap and stack collide. */ (void) sbrk(0); if ((verb= b_value(VERBOSEBOOTVARNAME)) != nil) verboseboot = a2l(verb); printf("\nLoading "); pretty_image(image); printf(".\n"); vsec= 0; /* Load this sector from image next. */ addr= mem[0].base; /* Into this memory block. */ limit= mem[0].base + mem[0].size; if (limit > caddr) limit= caddr; /* Allocate and clear the area where the headers will be placed. */ aout = (limit -= PROCESS_MAX * A_MINHDR); /* Clear the area where the headers will be placed. */ raw_clear(aout, PROCESS_MAX * A_MINHDR); /* Read the many different processes: */ for (i= 0; vsec < image_size; i++) { u32_t startaddr; startaddr = addr; if (i == PROCESS_MAX) { printf("There are more then %d programs in %s\n", PROCESS_MAX, image); errno= 0; return; } procp= &process[i]; /* Read header. */ DEBUGEXTRA(("Reading header... ")); for (;;) { if ((buf= get_sector(vsec++)) == nil) return; memcpy(&hdr, buf, sizeof(hdr)); if (BADMAG(hdr.process)) { errno= ENOEXEC; return; } /* Check the optional label on the process. */ if (selected(hdr.name)) break; /* Bad label, skip this process. */ vsec+= proc_size(&hdr); } DEBUGEXTRA(("done\n")); /* Sanity check: an 8086 can't run a 386 kernel. */ if (hdr.process.a_cpu == A_I80386 && processor < 386) { printf("You can't run a 386 kernel on this 80%ld\n", processor); errno= 0; return; } /* Get the click shift from the kernel text segment. */ if (i == KERNEL_IDX) { if (!get_clickshift(vsec, &hdr)) return; addr= align(addr, click_size); /* big kernels must be loaded into extended memory */ if (k_flags & K_KHIGH) { addr= mem[1].base; limit= mem[1].base + mem[1].size; } } /* Save a copy of the header for the kernel, with a_syms * misused as the address where the process is loaded at. */ DEBUGEXTRA(("raw_copy(0x%x, 0x%lx, 0x%x)... ", aout + i * A_MINHDR, mon2abs(&hdr.process), A_MINHDR)); hdr.process.a_syms= addr; raw_copy(aout + i * A_MINHDR, mon2abs(&hdr.process), A_MINHDR); DEBUGEXTRA(("done\n")); if (!banner) { DEBUGBASIC((" cs ds text data bss")); if (k_flags & K_CHMEM) DEBUGBASIC((" stack")); DEBUGBASIC(("\n")); banner= 1; } /* Segment sizes. */ DEBUGEXTRA(("a_text=0x%lx; a_data=0x%lx; a_bss=0x%lx; a_flags=0x%x)\n", hdr.process.a_text, hdr.process.a_data, hdr.process.a_bss, hdr.process.a_flags)); a_text= hdr.process.a_text; a_data= hdr.process.a_data; a_bss= hdr.process.a_bss; if (k_flags & K_CHMEM) { a_stack= hdr.process.a_total - a_data - a_bss; if (!(hdr.process.a_flags & A_SEP)) a_stack-= a_text; } else { a_stack= 0; } /* Collect info about the process to be. */ procp->cs= addr; /* Process may be page aligned so that the text segment contains * the header, or have an unmapped zero page against vaxisms. */ procp->entry= hdr.process.a_entry; if (hdr.process.a_flags & A_PAL) a_text+= hdr.process.a_hdrlen; if (hdr.process.a_flags & A_UZP) procp->cs-= click_size; /* Separate I&D: two segments. Common I&D: only one. */ if (hdr.process.a_flags & A_SEP) { /* Read the text segment. */ DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", vsec, a_text, addr, limit)); if (!get_segment(&vsec, &a_text, &addr, limit)) return; DEBUGEXTRA(("get_segment done vsec=0x%lx a_text=0x%lx " "addr=0x%lx\n", vsec, a_text, addr)); /* The data segment follows. */ procp->ds= addr; if (hdr.process.a_flags & A_UZP) procp->ds-= click_size; procp->data= addr; } else { /* Add text to data to form one segment. */ procp->data= addr + a_text; procp->ds= procp->cs; a_data+= a_text; } /* Read the data segment. */ DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", vsec, a_data, addr, limit)); if (!get_segment(&vsec, &a_data, &addr, limit)) return; DEBUGEXTRA(("get_segment done vsec=0x%lx a_data=0x%lx " "addr=0x%lx\n", vsec, a_data, addr)); /* Make space for bss and stack unless... */ if (i != KERNEL_IDX && (k_flags & K_CLAIM)) a_bss= a_stack= 0; DEBUGBASIC(("%07lx %07lx %8ld %8ld %8ld", procp->cs, procp->ds, hdr.process.a_text, hdr.process.a_data, hdr.process.a_bss)); if (k_flags & K_CHMEM) DEBUGBASIC((" %8ld", a_stack)); /* Note that a_data may be negative now, but we can look at it * as -a_data bss bytes. */ /* Compute the number of bss clicks left. */ a_bss+= a_data; n= align(a_bss, click_size); a_bss-= n; /* Zero out bss. */ DEBUGEXTRA(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr, n, limit)); if (addr + n > limit) { errno= ENOMEM; return; } raw_clear(addr, n); DEBUGEXTRA(("done\n")); addr+= n; /* And the number of stack clicks. */ a_stack+= a_bss; n= align(a_stack, click_size); a_stack-= n; /* Add space for the stack. */ addr+= n; /* Process endpoint. */ procp->end= addr; if (verboseboot >= VERBOSEBOOT_BASIC) printf(" %s\n", hdr.name); else { u32_t mem; mem = addr-startaddr; printf("%s ", hdr.name); totalmem += mem; } if (i == 0 && (k_flags & (K_HIGH | K_KHIGH)) == K_HIGH) { /* Load the rest in extended memory. */ addr= mem[1].base; limit= mem[1].base + mem[1].size; } } if (verboseboot < VERBOSEBOOT_BASIC) printf("(%dk)\n", totalmem/1024); if ((n_procs= i) == 0) { printf("There are no programs in %s\n", image); errno= 0; return; } /* Check the kernel magic number. */ raw_copy(mon2abs(&kmagic), process[KERNEL_IDX].data + MAGIC_OFF, sizeof(kmagic)); if (kmagic != KERNEL_D_MAGIC) { printf("Kernel magic number is incorrect (0x%x@0x%lx)\n", kmagic, process[KERNEL_IDX].data + MAGIC_OFF); errno= 0; return; } /* Patch sizes, etc. into kernel data. */ DEBUGEXTRA(("patch_sizes()... ")); patch_sizes(); DEBUGEXTRA(("done\n")); #if !DOS if (!(k_flags & K_MEML)) { /* Copy the a.out headers to the old place. */ raw_copy(HEADERPOS, aout, PROCESS_MAX * A_MINHDR); } #endif /* Run the trailer function just before starting Minix. */ DEBUGEXTRA(("run_trailer()... ")); if (!run_trailer()) { errno= 0; return; } DEBUGEXTRA(("done\n")); /* Translate the boot parameters to what Minix likes best. */ DEBUGEXTRA(("params2params(0x%x, 0x%x)... ", params, sizeof(params))); if (!params2params(params, sizeof(params))) { errno= 0; return; } DEBUGEXTRA(("done\n")); /* Set the video to the required mode. */ if ((console= b_value("console")) == nil || (mode= a2x(console)) == 0) { mode= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE : MONO_MODE; } DEBUGEXTRA(("set_mode(%d)... ", mode)); set_mode(mode); DEBUGEXTRA(("done\n")); /* Close the disk. */ DEBUGEXTRA(("dev_close()... ")); (void) dev_close(); DEBUGEXTRA(("done\n")); /* Minix. */ DEBUGEXTRA(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n", process[KERNEL_IDX].entry, process[KERNEL_IDX].cs, process[KERNEL_IDX].ds, params, sizeof(params), aout)); minix(process[KERNEL_IDX].entry, process[KERNEL_IDX].cs, process[KERNEL_IDX].ds, params, sizeof(params), aout); if (!(k_flags & K_BRET)) { extern u32_t reboot_code; raw_copy(mon2abs(params), reboot_code, sizeof(params)); } parse_code(params); /* Return from Minix. Things may have changed, so assume nothing. */ fsok= -1; errno= 0; /* Read leftover character, if any. */ scan_keyboard(); /* Restore screen contents. */ restore_screen(); }
void exec_mb(char *kernel, char* modules) /* Get a Minix image into core, patch it up and execute. */ { int i; static char hdr[SECTOR_SIZE]; char *buf; u32_t vsec, addr, limit, n, totalmem = 0; u16_t kmagic, mode; char *console; char params[SECTOR_SIZE]; extern char *sbrk(int); char *verb; u32_t text_vaddr, text_paddr, text_filebytes, text_membytes; u32_t data_vaddr, data_paddr, data_filebytes, data_membytes; u32_t pc; u32_t text_offset, data_offset; i32_t segsize; int r; u32_t cs, ds; char *modstring, *mod; multiboot_info_t *mbinfo; multiboot_module_t *mbmodinfo; u32_t mbinfo_size, mbmodinfo_size; char *memvar; memory *mp; u32_t mod_cmdline_start, kernel_cmdline_start; u32_t modstringlen; int modnr; /* The stack is pretty deep here, so check if heap and stack collide. */ (void) sbrk(0); if ((verb= b_value(VERBOSEBOOTVARNAME)) != nil) verboseboot = a2l(verb); printf("\nLoading %s\n", kernel); vsec= 0; /* Load this sector from kernel next. */ addr= mem[0].base; /* Into this memory block. */ limit= mem[0].base + mem[0].size; if (limit > caddr) limit= caddr; /* set click size for get_segment */ click_size = PAGE_SIZE; k_flags = K_KHIGH|K_BRET|K_MEML|K_INT86|K_RET|K_HDR |K_HIGH|K_CHMEM|K_I386; /* big kernels must be loaded into extended memory */ addr= mem[1].base; limit= mem[1].base + mem[1].size; /* Get first sector */ DEBUGEXTRA(("get_sector\n")); if ((buf= get_sector(vsec++)) == nil) { DEBUGEXTRA(("get_sector failed\n")); return; } memcpy(hdr, buf, SECTOR_SIZE); /* Get ELF header */ DEBUGEXTRA(("read_header_elf\n")); r = read_header_elf(hdr, &text_vaddr, &text_paddr, &text_filebytes, &text_membytes, &data_vaddr, &data_paddr, &data_filebytes, &data_membytes, &pc, &text_offset, &data_offset); if (r < 0) { errno= ENOEXEC; return; } /* Read the text segment. */ addr = text_paddr; segsize = (i32_t) text_filebytes; vsec = text_offset / SECTOR_SIZE; DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", vsec, segsize, addr, limit)); if (!get_segment(&vsec, &segsize, &addr, limit)) return; DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx " "addr=0x%lx\n", vsec, segsize, addr)); /* Read the data segment. */ addr = data_paddr; segsize = (i32_t) data_filebytes; vsec = data_offset / SECTOR_SIZE; DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", vsec, segsize, addr, limit)); if (!get_segment(&vsec, &segsize, &addr, limit)) return; DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx " "addr=0x%lx\n", vsec, segsize, addr)); n = data_membytes - align(data_filebytes, click_size); /* Zero out bss. */ DEBUGEXTRA(("\nraw_clear(0x%lx, 0x%lx); limit=0x%lx... ", addr, n, limit)); if (addr + n > limit) { errno= ENOMEM; return; } raw_clear(addr, n); DEBUGEXTRA(("done\n")); addr+= n; /* Check the kernel magic number. */ raw_copy(mon2abs(&kmagic), data_paddr + MAGIC_OFF, sizeof(kmagic)); if (kmagic != KERNEL_D_MAGIC) { printf("Kernel magic number is incorrect (0x%x@0x%lx)\n", kmagic, data_paddr + MAGIC_OFF); errno= 0; return; } /* Translate the boot parameters to what Minix likes best. */ DEBUGEXTRA(("params2params(0x%x, 0x%x)... ", params, sizeof(params))); if (!params2params(params, sizeof(params))) { errno= 0; return; } DEBUGEXTRA(("done\n")); /* Create multiboot info struct */ mbinfo = malloc(sizeof(multiboot_info_t)); if (mbinfo == nil) { errno= ENOMEM; return; } memset(mbinfo, 0, sizeof(multiboot_info_t)); /* Module info structs start where kernel ends */ mbinfo->mods_addr = addr; modstring = strdup(modules); if (modstring == nil) {errno = ENOMEM; return; } modstringlen = strlen(modules); mbinfo->mods_count = split_module_list(modules); mbmodinfo_size = sizeof(multiboot_module_t) * mbinfo->mods_count; mbmodinfo = malloc(mbmodinfo_size); if (mbmodinfo == nil) { errno= ENOMEM; return; } addr+= mbmodinfo_size; addr= align(addr, click_size); mod_cmdline_start = mbinfo->mods_addr + sizeof(multiboot_module_t) * mbinfo->mods_count; raw_copy(mod_cmdline_start, mon2abs(modules), modstringlen+1); mbmodinfo[0].cmdline = mod_cmdline_start; modnr = 1; for (i= 0; i < modstringlen; ++i) { if (modules[i] == '\0') { mbmodinfo[modnr].cmdline = mod_cmdline_start + i + 1; ++modnr; } } kernel_cmdline_start = mod_cmdline_start + modstringlen + 1; mbinfo->cmdline = kernel_cmdline_start; raw_copy(kernel_cmdline_start, mon2abs(kernel), strlen(kernel)+1); mbinfo->flags = MULTIBOOT_INFO_MODS|MULTIBOOT_INFO_CMDLINE| MULTIBOOT_INFO_BOOTDEV|MULTIBOOT_INFO_MEMORY; mbinfo->boot_device = mbdev; mbinfo->mem_lower = mem[0].size/1024; mbinfo->mem_upper = mem[1].size/1024; for (i = 0, mod = strtok(modstring, " "); mod != nil; mod = strtok(nil, " "), i++) { mod = select_image(mod); if (mod == nil) {errno = 0; return; } mbmodinfo[i].mod_start = addr; mbmodinfo[i].mod_end = addr + image_bytes; mbmodinfo[i].pad = 0; segsize= image_bytes; vsec= 0; DEBUGEXTRA(("get_segment(0x%lx, 0x%lx, 0x%lx, 0x%lx)\n", vsec, segsize, addr, limit)); if (!get_segment(&vsec, &segsize, &addr, limit)) return; DEBUGEXTRA(("get_segment done vsec=0x%lx size=0x%lx " "addr=0x%lx\n", vsec, segsize, addr)); addr+= segsize; addr= align(addr, click_size); } free(modstring); DEBUGEXTRA(("modinfo raw_copy: dst 0x%lx src 0x%lx sz 0x%lx\n", mbinfo->mods_addr, mon2abs(mbmodinfo), mbmodinfo_size)); raw_copy(mbinfo->mods_addr, mon2abs(mbmodinfo), mbmodinfo_size); free(mbmodinfo); raw_copy(MULTIBOOT_INFO_ADDR, mon2abs(mbinfo), sizeof(multiboot_info_t)); free(mbinfo); /* Run the trailer function just before starting Minix. */ DEBUGEXTRA(("run_trailer()... ")); if (!run_trailer()) { errno= 0; return; } DEBUGEXTRA(("done\n")); /* Set the video to the required mode. */ if ((console= b_value("console")) == nil || (mode= a2x(console)) == 0) { mode= strcmp(b_value("chrome"), "color") == 0 ? COLOR_MODE : MONO_MODE; } DEBUGEXTRA(("set_mode(%d)... ", mode)); set_mode(mode); DEBUGEXTRA(("done\n")); /* Close the disk. */ DEBUGEXTRA(("dev_close()... ")); (void) dev_close(); DEBUGEXTRA(("done\n")); /* Minix. */ cs = ds = text_paddr; DEBUGEXTRA(("minix(0x%lx, 0x%lx, 0x%lx, 0x%x, 0x%x, 0x%lx)\n", pc, cs, ds, params, sizeof(params), 0)); minix(pc, cs, ds, params, sizeof(params), 0); if (!(k_flags & K_BRET)) { extern u32_t reboot_code; raw_copy(mon2abs(params), reboot_code, sizeof(params)); } parse_code(params); /* Return from Minix. Things may have changed, so assume nothing. */ fsok= -1; errno= 0; /* Read leftover character, if any. */ scan_keyboard(); /* Restore screen contents. */ restore_screen(); }
void end_popup(char *b, int *_x, int *_y, int *_w) { n_vid(); restore_screen(*_x, *_y, *_w, 5, b); }
int do_listbox(LISTBOX *l, int *oklist, int *cancellist, int init_key, int instant_mouse) { int key; int *pos; int done; int ret; int c; char *b = save_screen(l->x, l->y, l->w, l->h); int is_key; hide_c(); draw_listbox(l); l->key = init_key; l->key2 = -1; display_mouse(); while (m_b) { poll_mouse(); if ((instant_mouse) && ((m_b & 2) || (mouse_inside_list(l)) || ((mouse_inside_parent(l)) && (get_mouse_item(l->parent) != l->parent->current)))) break; } do { if (l->key == -1) { while (!input_waiting()) { poll_mouse(); if (m_b) break; } if (input_waiting()) { key = input_char().key; is_key = TRUE; } else { int ox, oy, ob; int sel_item; int first = TRUE; key = 0; is_key = FALSE; while (m_b) { if ((m_b & 2) && (!(l->flags & LISTBOX_USE_RMB))) { key = ESC; is_key = TRUE; break; } sel_item = -1; if (mouse_inside_list(l)) { l->current = get_mouse_item(l); if (l->current >= l->count) l->current = l->count-1; else sel_item = l->current; } hide_mouse(); draw_contents(l); display_mouse(); if (first) { if (sel_item >= 0) { if (l->flags & LISTBOX_MOUSE_OK) { key = CR; is_key = TRUE; break; } if (!(l->flags & LISTBOX_MOUSE_OK2)) { if (!mouse_dclick(FALSE)) { if (mouse_dclick(TRUE)) { key = CR; is_key = TRUE; break; } } } } else if (mouse_outside_list(l)) { if (l->flags & LISTBOX_MOUSE_CANCEL) { key = ESC; is_key = TRUE; break; } } first = FALSE; } if (mouse_inside_parent(l)) { if (l->flags & LISTBOX_MOUSE_CANCEL) { key = ESC; is_key = TRUE; break; } } if (l->flags & LISTBOX_SCROLL) { int changed = FALSE; if ((m_y < l->y + l->yoff) && (l->scroll > 0)) { l->scroll--; l->current = l->scroll; m_y = -1; changed = TRUE; } else if ((m_y >= l->y + l->yoff + l->height) && (l->scroll < l->count - l->height)) { l->scroll++; l->current = l->scroll + l->height - 1; if (l->current >= l->count) l->current = l->count-1; m_y = -1; changed = TRUE; } if (changed) { hide_mouse(); draw_contents(l); display_mouse(); delay(20); } } do { ox = m_x; oy = m_y; ob = m_b; poll_mouse(); } while ((m_x == ox) && (m_y == oy) && (m_b == ob) && (m_b) && (!input_waiting())); if ((!m_b) && (sel_item >= 0) && (l->flags & LISTBOX_MOUSE_OK2)) { key = CR; is_key = TRUE; break; } } } } else { key = l->key; l->key = l->key2; l->key2 = -1; is_key = TRUE; } done = FALSE; if (is_key) { pos = oklist; while (*pos) { if ((*pos == key) || (ascii(key)==CR) || (ascii(key)==LF)) { if ((l->current >= 0) && (l->current < l->count)) { hide_mouse(); if (l->data[l->current].click_proc) ret = (l->data[l->current].click_proc) (l, l->data+l->current); else ret = l->data[l->current].data; if (ret >= 0) { l->key = key; restore_screen(l->x, l->y, l->w, l->h, b); show_c(); return ret; } else { hide_c(); display_mouse(); } } done = TRUE; break; } pos++; } if (!done) { pos = cancellist; while (*pos) { if ((*pos == key) || (ascii(key)==ESC)) { hide_mouse(); l->key = key; restore_screen(l->x, l->y, l->w, l->h, b); show_c(); return -1; } pos++; } } if (!done) { if (key==LEFT_ARROW) l->current--; else if (key==UP_ARROW) l->current -= l->width; else if (key==RIGHT_ARROW) l->current++; else if (key==DOWN_ARROW) l->current += l->width; else if (key==PAGE_UP) l->current -= l->width * l->height - 1; else if (key==PAGE_DOWN) l->current += l->width * l->height - 1; else if (key==K_HOME) l->current = 0; else if (key==K_END) l->current = l->count-1; else if (l->process_proc) if ((*l->process_proc)(l, key)) goto skip; for (c=0; c<l->count; c++) if (tolower(l->data[c].text[0]) == tolower(ascii(key))) { l->current = c; if (l->flags & LISTBOX_FASTKEY) l->key = oklist[0]; break; } skip: if (l->current < 0) { if (l->flags & LISTBOX_WRAP) l->current = MAX(0, l->count-1); else l->current = 0; } else if (l->current >= l->count) { if (l->flags & LISTBOX_WRAP) l->current = 0; else l->current = MAX(0, l->count-1); } while (l->current < l->scroll) l->scroll -= l->width; while (l->current >= l->scroll+l->width*l->height) l->scroll += l->width; } } hide_mouse(); draw_contents(l); display_mouse(); } while (TRUE); }