open_xms_store (j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { XMScontext ctx; /* Get address of XMS driver */ jxms_getdriver((XMSDRIVER far *) & xms_driver); if (xms_driver == NULL) return FALSE; /* no driver to be had */ /* Get version number, must be >= 2.00 */ ctx.ax = 0x0000; jxms_calldriver(xms_driver, (XMScontext far *) & ctx); if (ctx.ax < (unsigned short) 0x0200) return FALSE; /* Try to get space (expressed in kilobytes) */ ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10); ctx.ax = 0x0900; jxms_calldriver(xms_driver, (XMScontext far *) & ctx); if (ctx.ax != 1) return FALSE; /* Succeeded, save the handle and away we go */ info->handle.xms_handle = ctx.dx; info->read_backing_store = read_xms_store; info->write_backing_store = write_xms_store; info->close_backing_store = close_xms_store; TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx); return TRUE; /* succeeded */ }
write_xms_store (j_common_ptr cinfo, backing_store_ptr info, void FAR * buffer_address, long file_offset, long byte_count) { XMScontext ctx; XMSspec spec; char endbuffer[2]; /* The XMS driver can't cope with an odd length, so handle the last byte * specially if byte_count is odd. We don't expect this to be common. */ spec.length = byte_count & (~ 1L); spec.src_handle = 0; spec.src.ptr = buffer_address; spec.dst_handle = info->handle.xms_handle; spec.dst.offset = file_offset; ctx.ds_si = (void far *) & spec; ctx.ax = 0x0b00; /* EMB move */ jxms_calldriver(xms_driver, (XMScontext far *) & ctx); if (ctx.ax != 1) ERREXIT(cinfo, JERR_XMS_WRITE); if (ODD(byte_count)) { read_xms_store(cinfo, info, (void FAR *) endbuffer, file_offset + byte_count - 1L, 2L); endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L]; write_xms_store(cinfo, info, (void FAR *) endbuffer, file_offset + byte_count - 1L, 2L); } }
METHODDEF void read_xms_store (backing_store_ptr info, void FAR * buffer_address, long file_offset, long byte_count) { XMScontext ctx; XMSspec spec; char endbuffer[2]; /* The XMS driver can't cope with an odd length, so handle the last byte * specially if byte_count is odd. We don't expect this to be common. */ spec.length = byte_count & (~ 1L); spec.src_handle = info->handle.xms_handle; spec.src.offset = file_offset; spec.dst_handle = 0; spec.dst.ptr = buffer_address; ctx.ds_si = (void far *) & spec; ctx.ax = 0x0b00; /* EMB move */ jxms_calldriver(xms_driver, (XMScontext far *) & ctx); if (ctx.ax != 1) ERREXIT(methods, "read from extended memory failed"); if (ODD(byte_count)) { read_xms_store(info, (void FAR *) endbuffer, file_offset + byte_count - 1L, 2L); ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0]; } }
close_xms_store (j_common_ptr cinfo, backing_store_ptr info) { XMScontext ctx; ctx.dx = info->handle.xms_handle; ctx.ax = 0x0a00; jxms_calldriver(xms_driver, (XMScontext far *) & ctx); TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle); /* we ignore any error return from the driver */ }
METHODDEF void close_xms_store (backing_store_ptr info) { XMScontext ctx; ctx.dx = info->handle.xms_handle; ctx.ax = 0x0a00; jxms_calldriver(xms_driver, (XMScontext far *) & ctx); TRACEMS1(methods, 1, "Freed XMS handle %u", info->handle.xms_handle); /* we ignore any error return from the driver */ }