MCPcopy Create free account
hub / github.com/NetHack/NetHack / vesa_SetWindow

Function vesa_SetWindow

sys/msdos/vidvesa.c:272–313  ·  view source on GitHub ↗

Set the memory window and return the offset */

Source from the content-addressed store, hash-verified

270
271/* Set the memory window and return the offset */
272static unsigned long
273vesa_SetWindow(int window, unsigned long offset)
274{
275 /* If the desired offset is already within the window, leave the window
276 as it is and return the address based on the current window position.
277 This minimizes the use of the window switch function.
278
279 On the first call to the function, vesa_win_pos[window] == 0xFFFFFFFF,
280 the offset will always be less than this, and the BIOS will always be
281 called. */
282
283 unsigned long pos = vesa_win_pos[window];
284 if (offset < pos || pos + vesa_win_size <= offset) {
285 __dpmi_regs regs;
286
287 memset(&regs, 0, sizeof(regs));
288 regs.x.ax = 0x4F05;
289 regs.h.bh = 0x00;
290 regs.h.bl = window;
291 regs.x.dx = offset / vesa_win_gran;
292 pos = regs.x.dx * vesa_win_gran;
293
294 if (vesa_win_func != 0) {
295 regs.x.cs = vesa_win_func >> 16;
296 regs.x.ip = vesa_win_func & 0xFFFF;
297 (void) __dpmi_simulate_real_mode_procedure_retf(&regs);
298 } else {
299 (void) __dpmi_int(VIDEO_BIOS, &regs);
300 }
301 vesa_win_pos[window] = pos;
302 }
303
304 offset = offset - vesa_win_pos[window] + vesa_win_addr[window];
305 /* Keep from crashing the system if some malfunction gives us a bad
306 offset */
307 if (offset < 0xA0000 || offset > 0xBFFFF) {
308 vesa_SwitchMode(MODETEXT);
309 fprintf(stderr, "Abort: offset=%08lX\n", offset);
310 exit(1);
311 }
312 return offset;
313}
314
315static unsigned long
316vesa_ReadPixel32(unsigned x, unsigned y)

Callers 3

vesa_ReadPixel32Function · 0.85
vesa_WritePixel32Function · 0.85
vesa_WritePixelRowFunction · 0.85

Calls 2

vesa_SwitchModeFunction · 0.85
fprintfFunction · 0.85

Tested by

no test coverage detected