/* **************************************************************** * Imprime uma mensagem de erro * **************************************************************** */ void draw_error_msg_text (const char *format, ...) { const WINDATA *wp = &msg; char err; if ((err = *format) == '*') format++; msg_len = vsnprintf (msg_text, sizeof (msg_text), format, va_first (format)); if (err == '*' && errno != 0) { msg_len += snprintf ( msg_text + msg_len, sizeof (msg_text) - msg_len, " (%s)", strerror (errno) ); } msg_type = ERROR_MSG; XClearWindow (display, wp->win); draw_msg_win (); } /* end draw_error_msg_text */
/* **************************************************************** * Imprime uma mensagem com pergunta * **************************************************************** */ void draw_question_msg_text (int rm, const char *question, const char *format, ...) { const WINDATA *wp = &msg; char err; msg_rm = rm; if ((err = *format) == '*') format++; msg_len = vsnprintf (msg_text, sizeof (msg_text), format, va_first (format)); if (err == '*' && errno != 0) { msg_len += snprintf ( msg_text + msg_len, sizeof (msg_text) - msg_len, " (%s)", strerror (errno) ); } if (question != NOSTR) msg_len += snprintf (msg_text + msg_len, sizeof (msg_text) - msg_len, question); msg_type = QUESTION_MSG; XClearWindow (display, wp->win); draw_msg_win (); } /* end draw_msg_text */
/* **************************************************************** * Imprime uma mensagem normal * **************************************************************** */ void draw_msg_text (const char *format, ...) { const WINDATA *wp = &msg; msg_len = vsnprintf (msg_text, sizeof (msg_text), format, va_first (format)); msg_type = GOOD_MSG; XClearWindow (display, wp->win); draw_msg_win (); } /* end draw_msg_text */
void badapple_main(void) { int i; // initialize the global flags. sched_next_buffer = 0; sched_skip_frames = 0; // Detect data disk. if (badapple_detect_disk() != 0) return; // Open VGA display. va = va_first(); va_switch_mode(va, VM_VGA_CG640); va_set_palette(va, &kDefault16GrayPalette); va_clear_output(va); // Initialize the buffers. for (i=0; i<2; ++i) { atomic_set(&(buffers[i].ready), 0); buffers[i].data = kmalloc(PIC_GROUP_SIZE); } // Display loading image. uint8_t *badapple_loading_data = badapple_loading_image; do { int compress_size = *(int*)badapple_loading_data; int size = LZ4_decompress_safe( (const char*)badapple_loading_data + sizeof(int), (char*)buffers[0].data, compress_size, PIC_FRAME_SIZE ); if (size != PIC_FRAME_SIZE) { panic("[badapple] Error decoding image: got %d bytes instead of %d.\n", size, PIC_FRAME_SIZE); } va_video_write(va, buffers[0].data, 0, 0, DST_WIDTH, DST_HEIGHT); } while (0); // Create video data memory jar. uint8_t* video_compressed_data = (uint8_t*)kmalloc(BADAPPLE_VIDEO_DATA_SIZE * SECTSIZE); // Load video data from external disk. if (kdisk_read_secs(ideno, video_compressed_data, BADAPPLE_VIDEO_DATA_SIZE, BADAPPLE_VIDEO_DATA_OFFSET + ideoff) != 0) { panic("[badapple] Cannot load video data from disk.\n"); } printf("[badapple] Video data already loaded from disk.\n"); // Loop and decode data. do { int group = 0; uint8_t *p = video_compressed_data; i = 0; sched_inited = 1; for (;;) { // wait for buffer to be used up. while (atomic_read(&(buffers[i].ready)) != 0) io_delay(); // get next group compressed size. int compress_size = *(int*)p; p += sizeof(int); ++group; if (compress_size == 0) { va_clear_output(va); printf("[badapple] All frames decoded, badapple_main exit.\n"); break; } // decompress this group. int size = LZ4_decompress_safe((const char*)p, (char*)buffers[i].data, compress_size, PIC_GROUP_SIZE); if (size != PIC_GROUP_SIZE) { printf("[badapple] Error decoding %d sec (offset 0x%08x): " "got %d bytes instead of %d; compress size is %d.\n", group, p - video_compressed_data, size, PIC_GROUP_SIZE, compress_size ); } #if 0 else { printf("[badapple] Decoded %d sec on buffer[%d].\n", group, i); } #endif p += compress_size; // Set the ready flag. atomic_set(&(buffers[i].ready), 1); i = 1 - i; } } while (0); // Free all resources. kfree(video_compressed_data); }