LOCAL boolean open_ems_store(j_common_ptr cinfo, backing_store_ptr info, long total_bytes_needed) { EMScontext ctx; /* Is EMS driver there? */ if(!jems_available()) return FALSE; /* Get status, make sure EMS is OK */ ctx.ax = 0x4000; jems_calldriver((EMScontext far *) & ctx); if(HIBYTE(ctx.ax) != 0) return FALSE; /* Get version, must be >= 4.0 */ ctx.ax = 0x4600; jems_calldriver((EMScontext far *) & ctx); if(HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40) return FALSE; /* Try to allocate requested space */ ctx.ax = 0x4300; ctx.bx = (unsigned short)((total_bytes_needed + EMSPAGESIZE - 1L) / EMSPAGESIZE); jems_calldriver((EMScontext far *) & ctx); if(HIBYTE(ctx.ax) != 0) return FALSE; /* Succeeded, save the handle and away we go */ info->handle.ems_handle = ctx.dx; info->read_backing_store = read_ems_store; info->write_backing_store = write_ems_store; info->close_backing_store = close_ems_store; TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx); return TRUE; /* succeeded */ }
close_ems_store (j_common_ptr cinfo, backing_store_ptr info) { EMScontext ctx; ctx.ax = 0x4500; ctx.dx = info->handle.ems_handle; jems_calldriver((EMScontext far *) & ctx); TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle); /* we ignore any error return from the driver */ }
METHODDEF void close_ems_store (backing_store_ptr info) { EMScontext ctx; ctx.ax = 0x4500; ctx.dx = info->handle.ems_handle; jems_calldriver((EMScontext far *) & ctx); TRACEMS1(methods, 1, "Freed EMS handle %u", info->handle.ems_handle); /* we ignore any error return from the driver */ }
METHODDEF void write_ems_store(j_common_ptr cinfo, backing_store_ptr info, void FAR * buffer_address, long file_offset, long byte_count) { EMScontext ctx; EMSspec spec; spec.length = byte_count; SRC_TYPE(spec) = 0; SRC_HANDLE(spec) = 0; SRC_PTR(spec) = buffer_address; DST_TYPE(spec) = 1; DST_HANDLE(spec) = info->handle.ems_handle; DST_PAGE(spec) = (unsigned short)(file_offset / EMSPAGESIZE); DST_OFFSET(spec) = (unsigned short)(file_offset % EMSPAGESIZE); ctx.ds_si = (void far *)&spec; ctx.ax = 0x5700; /* move memory region */ jems_calldriver((EMScontext far *) & ctx); if(HIBYTE(ctx.ax) != 0) ERREXIT(cinfo, JERR_EMS_WRITE); }
METHODDEF void read_ems_store (backing_store_ptr info, void FAR * buffer_address, long file_offset, long byte_count) { EMScontext ctx; EMSspec spec; spec.length = byte_count; SRC_TYPE(spec) = 1; SRC_HANDLE(spec) = info->handle.ems_handle; SRC_PAGE(spec) = (unsigned short) (file_offset / EMSPAGESIZE); SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE); DST_TYPE(spec) = 0; DST_HANDLE(spec) = 0; DST_PTR(spec) = buffer_address; ctx.ds_si = (void far *) & spec; ctx.ax = 0x5700; /* move memory region */ jems_calldriver((EMScontext far *) & ctx); if (HIBYTE(ctx.ax) != 0) ERREXIT(methods, "read from expanded memory failed"); }