static int bmpdrv_write_file_header(screenshot_t *screenshot) { gfxoutputdrv_data_t *sdata; BYTE header[14]; sdata = screenshot->gfxoutputdrv_data; memset(header, 0, sizeof(header)); header[0] = 'B'; header[1] = 'M'; util_dword_to_le_buf(&header[2], bmpdrv_bmp_size(screenshot)); if (sdata->bpp == 24) { util_dword_to_le_buf(&header[10], BMP_HDR_OFFSET24); } else { util_dword_to_le_buf(&header[10], BMP_HDR_OFFSET); } if (fwrite(header, sizeof(header), 1, screenshot->gfxoutputdrv_data->fd) < 1) { return -1; } return 0; }
static void network_event_record_sync_test(WORD addr, void *data) { BYTE regbuf[5 * 4]; util_dword_to_le_buf(®buf[0 * 4], (DWORD)(maincpu_regs.pc)); util_dword_to_le_buf(®buf[1 * 4], (DWORD)(maincpu_regs.a)); util_dword_to_le_buf(®buf[2 * 4], (DWORD)(maincpu_regs.x)); util_dword_to_le_buf(®buf[3 * 4], (DWORD)(maincpu_regs.y)); util_dword_to_le_buf(®buf[4 * 4], (DWORD)(maincpu_regs.sp)); network_event_record(EVENT_SYNC_TEST, (void *)regbuf, sizeof(regbuf)); }
static int bmpdrv_memmap_write_file_header(int x_size, int y_size) { BYTE header[14]; memset(header, 0, sizeof(header)); header[0] = 'B'; header[1] = 'M'; util_dword_to_le_buf(&header[2], bmpdrv_memmap_bmp_size(x_size, y_size)); util_dword_to_le_buf(&header[10], (14 + 40 + 4 * 256)); if (fwrite(header, sizeof(header), 1, bmpdrv_memmap_fd) < 1) { return -1; } return 0; }
static int bmpdrv_memmap_write_bitmap_info(int x_size, int y_size, BYTE *palette) { BYTE binfo[40]; BYTE *bcolor; unsigned int i; memset(binfo, 0, sizeof(binfo)); util_dword_to_le_buf(&binfo[0], sizeof(binfo)); util_dword_to_le_buf(&binfo[4], x_size); util_dword_to_le_buf(&binfo[8], y_size); binfo[12] = 1; binfo[13] = 0; binfo[14] = 8; /* 8 bits per pixel */ binfo[15] = 0; util_dword_to_le_buf(&binfo[16], 0); /* BI_RGB */ util_dword_to_le_buf(&binfo[20], 0); /* DPI in Pixels per Meter*/ util_dword_to_le_buf(&binfo[24], 0 * 10000 / 254); util_dword_to_le_buf(&binfo[28], 0 * 10000 / 254); util_dword_to_le_buf(&binfo[32], 256); util_dword_to_le_buf(&binfo[36], 256); if (fwrite(binfo, sizeof(binfo), 1, bmpdrv_memmap_fd) < 1) return -1; bcolor = lib_malloc(256 * 4); for (i = 0; i < 256; i++) { bcolor[i * 4] = palette[(i*3)+2]; bcolor[i * 4 + 1] = palette[(i*3)+1]; bcolor[i * 4 + 2] = palette[(i*3)]; bcolor[i * 4 + 3] = 0; } if (fwrite(bcolor, 256 * 4, 1, bmpdrv_memmap_fd) < 1) { lib_free(bcolor); return -1; } lib_free(bcolor); return 0; }
static unsigned int network_create_event_buffer(BYTE **buf, event_list_state_t *list) { int size; BYTE *bufptr; event_list_t *current_event, *last_event; int data_len = 0; int num_of_events; if (list == NULL) return 0; /* calculate the buffer length */ num_of_events = 0; current_event = list->base; do { num_of_events++; data_len += current_event->size; last_event = current_event; current_event = current_event->next; } while (last_event->type != EVENT_LIST_END); size = num_of_events * 3 * sizeof(DWORD) + data_len; *buf = lib_malloc(size); /* fill the buffer with the events */ current_event = list->base; bufptr = *buf; do { util_dword_to_le_buf(&bufptr[0], (DWORD)(current_event->type)); util_dword_to_le_buf(&bufptr[4], (DWORD)(current_event->clk)); util_dword_to_le_buf(&bufptr[8], (DWORD)(current_event->size)); memcpy(&bufptr[12], current_event->data, current_event->size); bufptr += 12 + current_event->size; last_event = current_event; current_event = current_event->next; } while (last_event->type != EVENT_LIST_END); return size; }
static int bmpdrv_write_bitmap_info(screenshot_t *screenshot) { BYTE binfo[40]; BYTE *bcolor; unsigned int i; memset(binfo, 0, sizeof(binfo)); util_dword_to_le_buf(&binfo[0], sizeof(binfo)); util_dword_to_le_buf(&binfo[4], screenshot->width); util_dword_to_le_buf(&binfo[8], screenshot->height); binfo[12] = 1; binfo[13] = 0; binfo[14] = screenshot->gfxoutputdrv_data->bpp; binfo[15] = 0; util_dword_to_le_buf(&binfo[16], 0); /* BI_RGB */ util_dword_to_le_buf(&binfo[20], 0); /* DPI in Pixels per Meter*/ util_dword_to_le_buf(&binfo[24], screenshot->dpi_x * 10000 / 254); util_dword_to_le_buf(&binfo[28], screenshot->dpi_y * 10000 / 254); if (screenshot->gfxoutputdrv_data->bpp == 24) { util_dword_to_le_buf(&binfo[32], 0); util_dword_to_le_buf(&binfo[36], 0); } else { util_dword_to_le_buf(&binfo[32], screenshot->palette->num_entries); util_dword_to_le_buf(&binfo[36], screenshot->palette->num_entries); } if (fwrite(binfo, sizeof(binfo), 1, screenshot->gfxoutputdrv_data->fd) < 1) { return -1; } if (screenshot->gfxoutputdrv_data->bpp != 24) { bcolor = lib_malloc(screenshot->palette->num_entries * 4); for (i = 0; i < screenshot->palette->num_entries; i++) { bcolor[i * 4] = screenshot->palette->entries[i].blue; bcolor[i * 4 + 1] = screenshot->palette->entries[i].green; bcolor[i * 4 + 2] = screenshot->palette->entries[i].red; bcolor[i * 4 + 3] = 0; } if (fwrite(bcolor, screenshot->palette->num_entries * 4, 1, screenshot->gfxoutputdrv_data->fd) < 1) { lib_free(bcolor); return -1; } lib_free(bcolor); } return 0; }
int fsimage_gcr_write_half_track(disk_image_t *image, unsigned int half_track, const disk_track_t *raw) { int gap, extend = 0, res; WORD max_track_length; BYTE buf[4]; long offset; fsimage_t *fsimage; BYTE num_half_tracks; fsimage = image->media.fsimage; offset = fsimage_gcr_seek_half_track(fsimage, half_track, &max_track_length, &num_half_tracks); if (offset < 0) { return -1; } if (image->read_only != 0) { log_error(fsimage_gcr_log, "Attempt to write to read-only disk image."); return -1; } if (raw->size > max_track_length) { log_error(fsimage_gcr_log, "Track too long for image."); return -1; } if (offset == 0) { offset = fseek(fsimage->fd, 0, SEEK_END); if (offset == 0) { offset = ftell(fsimage->fd); } if (offset < 0) { log_error(fsimage_gcr_log, "Could not extend GCR disk image."); return -1; } extend = 1; } if (raw->data != NULL) { util_word_to_le_buf(buf, (WORD)raw->size); if (util_fpwrite(fsimage->fd, buf, 2, offset) < 0) { log_error(fsimage_gcr_log, "Could not write GCR disk image."); return -1; } /* Clear gap between the end of the actual track and the start of the next track. */ if (fwrite(raw->data, raw->size, 1, fsimage->fd) < 1) { log_error(fsimage_gcr_log, "Could not write GCR disk image."); return -1; } gap = max_track_length - raw->size; if (gap > 0) { BYTE *padding = lib_calloc(1, gap); res = fwrite(padding, gap, 1, fsimage->fd); lib_free(padding); if (res < 1) { log_error(fsimage_gcr_log, "Could not write GCR disk image."); return -1; } } if (extend) { util_dword_to_le_buf(buf, offset); if (util_fpwrite(fsimage->fd, buf, 4, 12 + (half_track - 2) * 4) < 0) { log_error(fsimage_gcr_log, "Could not write GCR disk image."); return -1; } util_dword_to_le_buf(buf, disk_image_speed_map(image->type, half_track / 2)); if (util_fpwrite(fsimage->fd, buf, 4, 12 + (half_track - 2 + num_half_tracks) * 4) < 0) { log_error(fsimage_gcr_log, "Could not write GCR disk image."); return -1; } } } /* Make sure the stream is visible to other readers. */ fflush(fsimage->fd); return 0; }