/* TSR exit: trying to free as many resources as possible */ static void tsrExit (void) { if (isBackgrounded) { unsigned long pspAddress = _go32_info_block.linear_address_of_original_psp; if (restore(TIMER_INTERRUPT, &timerSeginfo, &origTimerSeginfo) + restore(IDLE_INTERRUPT, &idleSeginfo, &origIdleSeginfo)) { /* failed, hang */ setjmp(mainContext); longjmp(interruptContext, 1); } { __dpmi_regs r; /* free environment */ r.x.es = _farpeekw(_dos_ds, pspAddress+0X2C); r.x.ax = 0X4900; __dpmi_int(DOS_INTERRUPT, &r); /* free Program Segment Prefix */ r.x.es = pspAddress / 0X10; r.x.ax = 0X4900; __dpmi_int(DOS_INTERRUPT, &r); } /* and return */ longjmp(interruptContext, 1); /* TODO: free protected mode memory */ } }
int twin::getca ( int row, int col ) { int r, c ; r = (row==0 ? row_+vR1_ : row+vR0_) ; c = (col==0 ? col_+vC1_ : col+vC0_) ; if ( toVideo() ) #if defined(__DJGPP__) return _farpeekw(_dos_ds,(long)(&videoPtr[r*videoWidth+c])) ; #else return videoPtr[r*videoWidth+c] ; #endif if ( toBuffer() && pBuffer_ != 0 ) return pBuffer_[(r-_R1_)*(_C2_-_C1_+1)+(c-_C1_)] ; int ca ; int notCurr = (r!=row_ || c!=col_) ; if ( notCurr ) Bios_locate(page_,r,c) ; ca = Bios_getca(page_) ; if ( notCurr ) Bios_locate(page_,row_,col_) ; return ca ; }
/* TSR exit: trying to free as many resources as possible */ static void tsr_exit(void) { __dpmi_regs regs; unsigned long pspAddr = _go32_info_block.linear_address_of_original_psp; if (restore(TIMER_INT, &timerSeginfo, &origTimerSeginfo) + restore(IDLE_INT, &idleSeginfo, &origIdleSeginfo)) { /* failed, hang */ setjmp(mainCtx); longjmp(intCtx, 1); } /* free environment */ regs.x.es = _farpeekw(_dos_ds,pspAddr+0x2c); regs.x.ax = 0x4900; __dpmi_int(DOS_INT, ®s); /* free PSP */ regs.x.es = pspAddr/0x10; regs.x.ax = 0x4900; __dpmi_int(DOS_INT, ®s); /* and return */ longjmp(intCtx, 1); /* TODO: free protected mode memory */ }
/*find port for given LPT joystick*/ int test_LPTjoy(int portno,int *port) { int addr; if (portno < 1 || portno > 3) return FALSE; addr = _farpeekw(_dos_ds, (portno - 1) * 2 + 0x408); if (addr == 0) return FALSE; if (port!=NULL) *port=addr; return TRUE; }
static int parsid_init(void) { int j; unsigned long ptraddr = 0x0408; /* Base Address: segment is zero*/ unsigned int address; /* Address of Port */ int ports=0; for (j = 0; j < 3; j++) { parsid_port_address[j] = _farpeekw(_dos_ds,ptraddr); if (parsid_port_address[j]!=0) ports++; ptraddr += 2; } if (ports==0) return -1; else return 0; }
static unsigned short serialPortBase (SerialDevice *serial) { return _farpeekw(_dos_ds, (0X0400 + (2 * serial->package.deviceIndex))); }
/* Compute table of pointers to look for directory entry of a file. */ static int init_dirent_table (void) { short get_sda_func; unsigned short dirent_offset; unsigned short true_dos_version; unsigned short dos_major, dos_minor; __dpmi_regs regs; if (dirent_count == -1) /* we already tried and found we can't */ return 0; /* Compute INT 21h function number and offset of directory entry from start of SDA. These depend on the DOS version. We need exact knowledge about DOS internals, so we need the TRUE DOS version (not the simulated one by SETVER), if that's available. */ true_dos_version = _get_dos_version(1); dos_major = true_dos_version >> 8; dos_minor = true_dos_version & 0xff; if ((dos_major == 3) && (dos_minor >= 10)) { get_sda_func = 0x5d06; dirent_offset = 0x1a7; } else if (dos_major == 4) { /* According to ``Undocumented DOS, 2nd edition'', I could have used 5d06 here, as for DOS 5 and above, but I like to be defensive. In fact, the above book itself uses 5d0b, contrary to its own recommendation. */ get_sda_func = 0x5d0b; dirent_offset = 0x1b3; } else if (dos_major >= 5) { get_sda_func = 0x5d06; dirent_offset = 0x1b3; } else { _djstat_fail_bits |= _STFAIL_OSVER; dirent_count = -1; return 0; } _djstat_fail_bits &= ~_STFAIL_OSVER; /* version is OK */ /* Get the pointer to SDA by calling undocumented function 5dh of INT 21. */ regs.x.ax = get_sda_func; __dpmi_int(0x21, ®s); if (regs.x.flags & 1) { _djstat_fail_bits |= _STFAIL_SDA; dirent_count = -1; /* if the call failed, never try this later */ return 0; } _djstat_fail_bits &= ~_STFAIL_SDA; /* Get SDA succeeded */ /* DOS 4.x might have several SDA's, which means we might have more than one place to look into. (It is typical of DOS 4 to complicate things.) Compute all the possible addresses where we will have to look. */ if (dos_major == 4) { /* The pointer returned by INT 21h, AX=5D0b points to a header which holds a number of SDA's and then an array of that number of records each one of which includes address of an SDA (DWORD) and its length and type (encoded in a WORD). While walking this list of SDA's, we add to each pointer the offset of directory entry and stash the resulting address in our table for later use. */ int sda_list_walker = MK_FOFF(regs.x.ds, regs.x.si); int i; int *tbl; dirent_count = _farpeekw(_dos_ds, sda_list_walker); /* number of SDA's */ /* Allocate storage for table. */ tbl = dirent_table = (int *)malloc(dirent_count*sizeof(int)); if (!dirent_table) { /* If malloc() failed, maybe later it will succeed, so don't store -1 in dirent_count. */ dirent_count = 0; _djstat_fail_bits |= _STFAIL_DCOUNT; return 0; } memset(dirent_table, 0, dirent_count*sizeof(int)); _djstat_fail_bits &= ~_STFAIL_DCOUNT; /* dirent_count seems OK */ /* Walk the array of pointers, computing addresses of directory entries and stashing them in our table. */ _farsetsel(_dos_ds); for (i = dirent_count, sda_list_walker += 2; i--; sda_list_walker += 6) { int sda_start = _farnspeekl(sda_list_walker); unsigned short sda_len = _farnspeekw(sda_list_walker + 4) & 0x7fff; /* Let's be defensive here: if this SDA is too short to have place for directory entry, we won't use it. */ if (sda_len > dirent_offset) *tbl++ = sda_start + dirent_offset; else dirent_count--; } } /* DOS 3.1 and 5.0 or later. We have only one SDA pointed to by whatever INT 21h, AH=5d returns. */ else { dirent_count = 1; dirent_place = MK_FOFF(regs.x.ds, regs.x.si) + dirent_offset; dirent_table = &dirent_place; } return 1; }
static unsigned short serialPortBase (SerialDevice *serial) { return _farpeekw(_dos_ds, (0X0400 + (2 * serialGetPort(serial)))); }
short vm_getscreensize(void) { return (short)_farpeekw(_go32_conventional_mem_selector(), 0x044c); }