int main(int argc, char **argv) { struct options options = { 8, 8, 8, 8, 16 }; int r; char *fname; struct stat stat_buf; r = get_options(&options, argc, argv); if (r < 0) return -1; fname = argv[r]; if (0 == stat(fname, &stat_buf)) { fprintf(stderr, "loading %s...\n", fname); r = sheet_read(fname, &sheet); if (r) { fprintf(stderr, "failed\n"); return -1; } } else { fprintf(stderr, "create %s containing %ux%u %ux%u sprites...\n", fname, options.sh_width, options.sh_height, options.spr_width, options.spr_height); r = sheet_init(&sheet, options.sh_width, options.sh_height, options.spr_width, options.spr_height, options.pal_colors); if (r) { fprintf(stderr, "failed\n"); return -1; } } sleep(1); /* so you get to see the message */ vga13h_init(); ui_13(&sheet, fname); vga13h_done(); return 0; }
/** @brief Init OS after load. * @param NULL * @return NULL */ void OS_Init(void) { BOOTINFO* info; int32 screenWidth, screenHeight; uint8* bgBuf, *resVram; boolean re[2]; uint32 tmpAddr; InitPeripheralBuffer(); init_gdtidt(); init_pic(); io_sti(); // 恢复中断 tim_init(); io_out8(PIC0_IMR, 0xf8); /* PIT和PIC1和键盘设置为许可(11111000) */ io_out8(PIC1_IMR, 0xef); /* 鼠标设置为许可(11101111) */ info = (BOOTINFO*) ADR_BOOTINFO; screenHeight = info->screenHeight; screenWidth = info->screenWidth; init_palette(); mem_init(); fat_init(); re[0] = mem_alloc(768 * 1024, &tmpAddr); resVram = (uint8*)tmpAddr; sheet_init(resVram); InitMouse(); InitKeyboard(); re[1] = mem_alloc(768 * 1024, &tmpAddr); bgBuf = (uint8*)tmpAddr; //screenWidth * screenHeight sheet_add(bgBuf, screenWidth, screenHeight, 0, 0, NONE_COL, &bgSheet); fill_box(bgSheet, DARKGRASS, 0, 0, info->screenWidth, info->screenHeight); if(re[0] == FALSE || re[1] == FALSE) { fill_box(bgSheet, RED, 0, 0, info->screenWidth, info->screenHeight); } }
int main(int argc, char *argv[]) { kbd_event_t ev; coord_t coord; bool new_file; spt_t pt; con = console_init(stdin, stdout); console_clear(con); console_get_size(con, &scr_columns, &scr_rows); pane.rows = scr_rows - 1; pane.columns = scr_columns; pane.sh_row = 1; pane.sh_column = 1; /* Start with an empty sheet. */ sheet_init(&doc.sh); /* Place caret at the beginning of file. */ coord.row = coord.column = 1; sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); pane.ideal_column = coord.column; if (argc == 2) { doc.file_name = str_dup(argv[1]); } else if (argc > 1) { printf("Invalid arguments.\n"); return -2; } else { doc.file_name = NULL; } new_file = false; if (doc.file_name == NULL || file_insert(doc.file_name) != EOK) new_file = true; /* Move to beginning of file. */ caret_move(-ED_INFTY, -ED_INFTY, dir_before); /* Place selection start tag. */ tag_get_pt(&pane.caret_pos, &pt); sheet_place_tag(&doc.sh, &pt, &pane.sel_start); /* Initial display */ cursor_visible = true; cursor_hide(); console_clear(con); pane_text_display(); pane_status_display(); if (new_file && doc.file_name != NULL) status_display("File not found. Starting empty file."); pane_caret_display(); cursor_show(); done = false; while (!done) { console_get_kbd_event(con, &ev); pane.rflags = 0; if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_SHIFT) == 0) && (ev.mods & KM_CTRL) != 0) { key_handle_ctrl(&ev); } else if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_CTRL) == 0) && (ev.mods & KM_SHIFT) != 0) { key_handle_shift(&ev); } else if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { key_handle_unmod(&ev); } } /* Redraw as necessary. */ cursor_hide(); if (pane.rflags & REDRAW_TEXT) pane_text_display(); if (pane.rflags & REDRAW_ROW) pane_row_display(); if (pane.rflags & REDRAW_STATUS) pane_status_display(); if (pane.rflags & REDRAW_CARET) pane_caret_display(); cursor_show(); } console_clear(con); return 0; }