UINT32 image_fwrite(mess_image *image, const void *buffer, UINT32 length) { /* if we are not associated with a file, clip the length */ if (!image->file) length = MIN(length, image->length - image->pos); if (image->file) { osd_write(image->file, buffer, image->pos, length, &length); /* since we've written to the file, we may need to invalidate the pointer */ if (image->ptr) { image_freeptr(image, image->ptr); image->ptr = NULL; } } else if (image->ptr) { memcpy(((UINT8 *) image->ptr) + image->pos, buffer, length); } else length = 0; image->pos += length; /* did we grow the file? */ if (image->length < image->pos) image->length = image->pos; /* return */ return length; }
void device_pty_interface::write(UINT8 tx_char) const { UINT32 actual_bytes; if (m_opened) { osd_write(m_pty_master, &tx_char, 0, 1, &actual_bytes); } }
static file_error osd_or_zlib_write(core_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual) { /* if no compression, just pass through */ if (file->zdata == NULL) return osd_write(file->file, buffer, offset, length, actual); /* if the offset doesn't match the next offset, fail */ if (offset != file->zdata->nextoffset) return FILERR_INVALID_ACCESS; /* set up the source */ file->zdata->stream.next_in = (Bytef *)buffer; file->zdata->stream.avail_in = length; while (file->zdata->stream.avail_in != 0) { file_error filerr; UINT32 actualdata; int zerr; /* if we didn't make progress, report an error or the end */ zerr = deflate(&file->zdata->stream, Z_NO_FLUSH); if (zerr != Z_OK) { *actual = length - file->zdata->stream.avail_in; file->zdata->nextoffset += *actual; return FILERR_INVALID_DATA; } /* write more data if we are full up */ if (file->zdata->stream.avail_out == 0) { filerr = osd_write(file->file, file->zdata->buffer, file->zdata->realoffset, sizeof(file->zdata->buffer), &actualdata); if (filerr != FILERR_NONE) return filerr; file->zdata->realoffset += actualdata; file->zdata->stream.next_out = file->zdata->buffer; file->zdata->stream.avail_out = sizeof(file->zdata->buffer); } } /* we read everything */ *actual = length; file->zdata->nextoffset += *actual; return FILERR_NONE; }
file_error core_fcompress(core_file *file, int level) { file_error result = FILERR_NONE; /* can only do this for read-only and write-only cases */ if ((file->openflags & OPEN_FLAG_WRITE) != 0 && (file->openflags & OPEN_FLAG_READ) != 0) return FILERR_INVALID_ACCESS; /* if we have been compressing, flush and free the data */ if (file->zdata != NULL && level == FCOMPRESS_NONE) { int zerr = Z_OK; /* flush any remaining data if we are writing */ while ((file->openflags & OPEN_FLAG_WRITE) != 0 && zerr != Z_STREAM_END) { UINT32 actualdata; file_error filerr; /* deflate some more */ zerr = deflate(&file->zdata->stream, Z_FINISH); if (zerr != Z_STREAM_END && zerr != Z_OK) { result = FILERR_INVALID_DATA; break; } /* write the data */ if (file->zdata->stream.avail_out != sizeof(file->zdata->buffer)) { filerr = osd_write(file->file, file->zdata->buffer, file->zdata->realoffset, sizeof(file->zdata->buffer) - file->zdata->stream.avail_out, &actualdata); if (filerr != FILERR_NONE) break; file->zdata->realoffset += actualdata; file->zdata->stream.next_out = file->zdata->buffer; file->zdata->stream.avail_out = sizeof(file->zdata->buffer); } } /* end the appropriate operation */ if ((file->openflags & OPEN_FLAG_WRITE) != 0) deflateEnd(&file->zdata->stream); else inflateEnd(&file->zdata->stream); /* free memory */ free(file->zdata); file->zdata = NULL; } /* if we are just starting to compress, allocate a new buffer */ if (file->zdata == NULL && level > FCOMPRESS_NONE) { int zerr; /* allocate memory */ file->zdata = (zlib_data *)malloc(sizeof(*file->zdata)); if (file->zdata == NULL) return FILERR_OUT_OF_MEMORY; memset(file->zdata, 0, sizeof(*file->zdata)); /* initialize the stream and compressor */ if ((file->openflags & OPEN_FLAG_WRITE) != 0) { file->zdata->stream.next_out = file->zdata->buffer; file->zdata->stream.avail_out = sizeof(file->zdata->buffer); zerr = deflateInit(&file->zdata->stream, level); } else zerr = inflateInit(&file->zdata->stream); /* on error, return an error */ if (zerr != Z_OK) { free(file->zdata); file->zdata = NULL; return FILERR_OUT_OF_MEMORY; } /* flush buffers */ file->bufferbytes = 0; /* set the initial offset */ file->zdata->realoffset = file->offset; file->zdata->nextoffset = file->offset; } return result; }
/** * prints a string */ void dev_print(const char *str) { osd_write(str); }