static void HugeMemCopy( void far *dst, void far *src, unsigned bytes ) { long offset, selector; long bytes_before_segment_end; offset = FP_OFF( dst ); selector = FP_SEG( dst ); bytes_before_segment_end = 0x10000L - offset; if( bytes_before_segment_end < bytes ) { _fmemcpy( dst, src, bytes_before_segment_end ); bytes -= bytes_before_segment_end; selector += HUGE_SHIFT; dst = MK_FP( selector, 0 ); src = (char *)src + bytes_before_segment_end; } _fmemcpy( dst, src, bytes ); }
BOOL FcbWrite(xfcb FAR * lpXfcb, COUNT * nErrorCode) { sft FAR *s; LONG lPosit; COUNT nWritten; psp FAR *p = MK_FP(cu_psp, 0); /* Convert to fcb if necessary */ lpFcb = ExtFcbToFcb(lpXfcb); /* Get the SFT block that contains the SFT */ if ((s = idx_to_sft(lpFcb->fcb_sftno)) == (sft FAR *) - 1) return FALSE; /* If this is not opened another error */ if (s->sft_count == 0) return FALSE; /* Now update the fcb and compute where we need to position */ /* to. */ lPosit = FcbRec() * lpFcb->fcb_recsiz; if (SftSeek(s, lPosit, 0) != SUCCESS) { *nErrorCode = FCB_ERR_EOF; return FALSE; } nWritten = DosWriteSft(s, lpFcb->fcb_recsiz, p->ps_dta, nErrorCode); /* Now find out how we will return and do it. */ if (nWritten == lpFcb->fcb_recsiz) { lpFcb->fcb_fsize = s->sft_size; FcbNextRecord(lpFcb); *nErrorCode = FCB_SUCCESS; return TRUE; } else if (nWritten <= 0) { *nErrorCode = FCB_ERR_WRITE; return TRUE; } *nErrorCode = FCB_ERR_WRITE; return FALSE; }
static int scan (void * arg, word segm, word ofs) { Context_Tag tag; ctxt_info_t *info; (void)arg; assert(segm); assert(ofs != (word)-1); redo: if((tag = peekb(segm, ofs), ctxtIsInfoTag(tag))) { info = &CTXT_INFO_STRUCT(tag); if(peekb(segm, ofs + 1) == '=' && peekb(segm, ofs + 4) == 0) { /* status entry */ info->c_sizemax = peekw(segm, ofs + 2) & ~0x8001; } else { /* normal entry */ char far *p = MK_FP(segm, ofs + 1); unsigned num; for(num = 0; isxdigit(*p); ++p) { num <<= 8; if(isdigit(*p)) num |= *p & 0xf; else { assert(islower(*p)); num |= *p - 'a' + 10; } } if(*p == '=') { info->c_sizecur += env_varlen(segm, ofs); if(num < info->c_nummin) info->c_nummin = num; if(num > info->c_nummax) info->c_nummax = num; } else { /* Invalid entry -> remove to make room for useful stuff */ env_subVarOffset(segm, ofs); goto redo; } } } else if(tag > ' ') { /* Alias */ CTXT_INFO(CTXT_TAG_ALIAS, sizecur) += env_varlen(segm ,ofs); } return 0; /* proceed */ }
/* * restoreState: * * Restore register state back to the fault frame from the IntResult * data structure. */ static void restoreState( volatile fault_frame *ff ) { WORD __far *wptr; /* * we save all this stuff in our own code segment (see int.asm) * because do not have data segment addressability when we need it * (when we go to push it onto a new stack) */ wptr = MK_FP( CSAlias, FP_OFF( &NewAX ) ); *wptr = (WORD) IntResult.EAX; wptr = MK_FP( CSAlias, FP_OFF( &NewCS ) ); *wptr = IntResult.CS; wptr = MK_FP( CSAlias, FP_OFF( &NewIP ) ); *wptr = (WORD) IntResult.EIP; wptr = MK_FP( CSAlias, FP_OFF( &NewFLAGS ) ); *wptr = (WORD) IntResult.EFlags; wptr = MK_FP( CSAlias, FP_OFF( &OldretCS ) ); *wptr = ff->intf.retCS; wptr = MK_FP( CSAlias, FP_OFF( &OldretIP ) ); *wptr = ff->intf.retIP; wptr = MK_FP( CSAlias, FP_OFF( &Oldintnumber ) ); *wptr = ff->intf.intnumber; wptr = MK_FP( CSAlias, FP_OFF( &Oldhandle ) ); *wptr = ff->intf.handle; ff->SS = IntResult.SS; ff->GS = IntResult.GS; ff->FS = IntResult.FS; ff->ES = IntResult.ES; ff->DS = IntResult.DS; ff->EDI = IntResult.EDI; ff->ESI = IntResult.ESI; // have ESP include the excess crap again ff->ESP = IntResult.ESP-EXCESS_CRAP_ON_STACK; ff->EBX = IntResult.EBX; ff->EDX = IntResult.EDX; ff->ECX = IntResult.ECX; ff->oldEAX = IntResult.EAX; ff->intf.oldEBP = IntResult.EBP; } /* restoreState */
trap_retval ReqSet_break( void ) { opcode_type __far *loc_brk_opcode; set_break_req *acc; set_break_ret *ret; acc = GetInPtr( 0 ); ret = GetOutPtr( 0 ); loc_brk_opcode = MK_FP( acc->break_addr.segment, acc->break_addr.offset ); ret->old = *loc_brk_opcode; *loc_brk_opcode = BRKPOINT; if( *loc_brk_opcode != BRKPOINT ) { BadBreak = acc->break_addr; GotABadBreak = TRUE; } return( sizeof( *ret ) ); }
static void Load_MCGA( short rows, short font, short cursor ) /*=========================================================== This routines loads an alphanumeric font for the MCGA. */ { VideoInt( _BIOS_VIDEO_PAGE, 0, 0, 0 ); // set active page to 0 VideoInt( _BIOS_SET_MODE + GetVideoMode(), 0, 0, 0 ); _fmemset( MK_FP( _EgaSeg, _EgaOff ), 0, 0x2000 ); // must do for MCGA 40 rows VideoInt( font & 0xFF0F, 0, 0, 0 ); // load character set VideoInt( 0x1103, 0, 0, 0 ); VideoInt( _BIOS_CURSOR_SIZE, 0, cursor, 0 ); // reset the cursor outpw( 0x03D4, ( cursor & 0xFF00 ) + 0x09 ); // # double scan lines *(char far *)_BIOS_data( ROWS ) = rows - 1; // # of rows // # of vertical points per character *(short far *)_BIOS_data( POINTS ) = 2 * ( cursor & 0xFF + 1 ); _GrCursor = 1; // cursor is on }
/* ----- test to see if the mouse driver is installed ----- */ BOOL mouse_installed(void) { unsigned char far *ms; unsigned short aa, bb; aa = peek(__seg0000, MOUSE *4 + 2); bb = peek(__seg0000, MOUSE * 4); asm { mov ax,2 mov bx,[aa] int 0x31 mov [aa],ax jnc ok } return FALSE; ok: ms = MK_FP(aa, bb); return (SCREENWIDTH <= 80 && ms != NULL && *ms != 0xcf); }
/* * getIntVect - get a 32-bit interrupt vector */ static void getIntVect( int vect, int_vect_32 *vinfo ) { union REGS inregs, outregs; struct SREGS segregs; segread( &segregs ); inregs.w.ax = 0x2502; /* get prot. mode vect */ inregs.h.cl = vect; intdosx( &inregs, &outregs, &segregs ); vinfo->prot = MK_FP( segregs.es, outregs.x.ebx ); inregs.w.ax = 0x2503; /* get real mode vect */ inregs.h.cl = vect; intdos( &inregs, &outregs ); vinfo->real = (void *) outregs.x.ebx; } /* getIntVect */
const char __far *DOSEnvFind( const char __far *name ) { const char __far *env; const char __far *p; env = MK_FP( GET_ENV_FROM_PSP(), 0 ); do { p = name; do { if( *p == NULLCHAR && *env == '=' ) { return( env + 1 ); } } while( *env++ == *p++ ); while( *env++ != NULLCHAR ) ; } while( *env != NULLCHAR ); return( NULL ); }
void DGraphics::ORPutImage( unsigned char far *VirtualScreen, int IgnoredColor, int x, int y, int width, int height ) { char far* Screen=(char far*)MK_FP( 0xA000, 0x000 ); int SrcOff=0, DstOff=y*320+x, // x is counted from 0 j,k; for(j=0;j<height;j++) { for( k=0; k<width; k++ ) { if( VirtualScreen[SrcOff+k]!=IgnoredColor ) Screen[DstOff+k]=VirtualScreen[SrcOff+k]; } DstOff+=320; SrcOff+=width; } }
int init_tty (void) /*{{{*/ { union REGS r; struct SREGS s; if (TTY_Initialized) return 0; bios_key_f = peekb(0x40,0x96) & 0x10; /* enhanced keyboard flag */ /* Check for system type */ delay_ptr = delay; r.x.ax = 0xC000; int86x (0x15, &r, &r, &s); if ((r.x.cflag == 0) && (r.h.al == 0)) { unsigned char *table; table = MK_FP(s.es, r.x.bx); switch (table[2]) { case 0xFF: /* pc */ case 0xFE: /* xt */ case 0xFB: /* xt */ case 0xFD: /* pc-jr */ break; /* AT and higher */ default: delay_ptr = my_delay; } } set_ctrl_break(0); ctrlbrk(ctrl_break); init_int9_handler(); TTY_Initialized = 1; if (Batch == 0) { if (X_Open_Mouse_Hook != NULL) (*X_Open_Mouse_Hook) (); } X_Set_Abort_Char_Hook = ibmpc_set_abort_char; return 0; }
/* If we're running on OS/2 2.x and it's an LX style file, spawn off the OS/2 2.x sampler to collect things */ bool VersionCheck( void ) { USHORT env_sel; USHORT cmd_off; RESULTCODES res; DosGetVersion( &OSVer ); if( OSVer >= 0x1400 && IsLX() ) { if( DosSearchPath( 0x0003, "PATH", OS22SAMPLER, (unsigned char *)UtilBuff, sizeof( UtilBuff ) ) ) { InternalError( MsgArray[MSG_SAMPLE_8 - ERR_FIRST_MESSAGE] ); } DosGetEnv( &env_sel, &cmd_off ); if( DosExecPgm( NULL, 0, EXEC_ASYNC, MK_FP( env_sel, cmd_off ), NULL, &res, UtilBuff ) != 0 ) { InternalError( MsgArray[MSG_SAMPLE_9 - ERR_FIRST_MESSAGE] ); } _exit( 0 ); } return( OSVer >= 0x0a14 ); }
/////////////////////////////////////////////////////////////////////////// // // USL_ScreenDraw() - Draws a chunk of the text screen (called only by // US_TextScreen()) // /////////////////////////////////////////////////////////////////////////// static void USL_ScreenDraw(word x,word y,char *s,byte attr) { byte far *screen,far *oscreen; screen = MK_FP(0xb800,(x * 2) + (y * 80 * 2)); oscreen = (&introscn + 7) + ((x - 1) * 2) + (y * 80 * 2) + 1; while (*s) { *screen++ = *s++; if (attr != 0xff) { *screen++ = (attr & 0x8f) | (*oscreen & 0x70); oscreen += 2; } else screen++; } }
void SetColorRegisters(struct Registers * registers) { Word i; //Get a pointer to the color register values Byte far * colorRegisterValues = MK_FP(registers->r_es, registers->r_dx.w); //Set the color register index outportb(0x03c8, registers->r_bx.b.l); //Loop through the color registers to set for(i = 0; i < registers->r_cx.w; ++i) { //Set the color register outportb(0x03c9, *colorRegisterValues++); outportb(0x03c9, *colorRegisterValues++); outportb(0x03c9, *colorRegisterValues++); } }
int main() { int msmouse=0; struct pos2 point[2],clipped[2]; int c,redraw=1; int pointsel=0; int doclip=1; /* microsoft mouse present? */ #if TARGET_BITS == 16 if (*((unsigned long*)MK_FP(0,0x33*4)) != 0) { __asm { xor ax,ax ; AH=0 reset driver int 33h or ax,ax jz notinst inc [msmouse] notinst: } }
/* init PC ROM routines, must be called in graphics mode*/ void pcrom_init(PSD psd) { char * p; /* use INT 10h to get address of rom character table*/ rom_char_addr = int10(FNGETROMADDR, GETROM8x14); #if 0 /* check bios data area for actual character height, * as the returned font isn't always 14 high */ ROM_CHAR_HEIGHT = GETBYTE_FP(MK_FP(0x0040, 0x0085)); if(ROM_CHAR_HEIGHT > MAX_ROM_HEIGHT) ROM_CHAR_HEIGHT = MAX_ROM_HEIGHT; #endif p = getenv("CHARHEIGHT"); if(p) ROM_CHAR_HEIGHT = atoi(p); }
char *InitSys() { SEL global; SEL local; int i; DosGetInfoSeg( &global, &local ); GInfoSeg = MK_FP( global, 0 ); PortsFound = 0; for( i = 0; i < NUM_ELTS( PortTest ); ++i ) { AccessPorts( PortTest[i], PortTest[i] ); if( CheckForPort( i, 0x55 ) && CheckForPort( i, 0xaa ) ) { PortAddress[ PortsFound++ ] = PortTest[ i ]; } FreePorts( PortTest[i], PortTest[i] ); } return( 0 ); }
static bool setupscrnbuff( void ) /*******************************/ { int rows, cols; LP_PIXEL scrn; size_t num; int i; if( console_size( UIConCtrl, UIConsole, 0, 0, &rows, &cols ) != 0 ) { return( false ); } UIData->width = cols; UIData->height = rows; num = UIData->width * UIData->height * 2; scrn = UIData->screen.origin; #if defined( __386__ ) scrn = realloc( scrn, num ); if( scrn == NULL ) return( false ); #else { unsigned seg; if( scrn == NULL ) { seg = qnx_segment_alloc( num ); } else { seg = qnx_segment_realloc( FP_SEG( scrn ), num ); } if( seg == -1 ) return( false ); scrn = MK_FP( seg, 0 ); } #endif num /= 2; for( i = 0; i < num; ++i ) { scrn[i].ch = ' '; /* a space with normal attributes */ scrn[i].attr = 7; /* a space with normal attributes */ } UIData->screen.origin = scrn; UIData->screen.increment = UIData->width; return( true ); }
char far *printspool_getqueue(void) { char far *result; union REGS r; struct SREGS s; r.x.ax = 0x0104; int86x(0x2f, &r, &r, &s); result = MK_FP(s.ds,r.x.si); if (!r.x.cflag) { printspool_errno = 0; return result; } else { printspool_errno = r.x.ax; return NULL; } }
/* Draws a pixel at screen coordinate (X,Y) */ void DrawDot(int X, int Y) { unsigned char far *ScreenPtr; /* Point to the byte the pixel is in */ #ifdef __TURBOC__ ScreenPtr = MK_FP(SCREEN_SEGMENT, (Y*SCREEN_WIDTH_IN_BYTES) + (X/8)); #else FP_SEG(ScreenPtr) = SCREEN_SEGMENT; FP_OFF(ScreenPtr) = (Y * SCREEN_WIDTH_IN_BYTES) + (X / 8); #endif /* Set the bit mask within the byte for the pixel */ outp(GC_INDEX + 1, 0x80 >> (X & 0x07)); /* Draw the pixel. ORed to force read/write to load latches. Data written doesn't matter, because set/reset is enabled for all planes. Note: don't OR with 0; MSC optimizes that statement to no operation */ *ScreenPtr |= 0xFE; }
void CheckPointRestore( void ) { dos_mem_block *chk; tiny_ret_t rc; tiny_handle_t hdl; rc = TinyOpen( ChkFile, TIO_READ ); if( TINY_ERROR( rc ) ) return; hdl = TINY_INFO( rc ); TinyRead( hdl, &chk, sizeof( chk ) ); TinyRead( hdl, chk, sizeof( *chk ) ); TinyRead( hdl, &chk, sizeof( chk ) ); while( TinyRead( hdl, chk, 0x8000 ) == 0x8000 ) { chk = MK_FP( FP_SEG( chk ) + 0x800, 0 ); } TinyClose( hdl ); Cleanup(); }
/* * chkRead - read checkpoint "file" */ static bool chkRead( void **buff ) { switch( isWhere ) { case ON_DISK: if( TinyRead( fileHandle, *buff, 0x8000 ) == 0x8000 ) { *buff = MK_FP( FP_SEG( *buff ) + 0x800, 0 ); return( true ); } return( false ); #ifndef NOEMS case IN_EMS: return( memBlockRead( EMSBlockRead, buff ) ); #endif #ifndef NOXMS case IN_XMS: return( memBlockRead( XMSBlockRead, buff ) ); #endif } } /* chkRead */
int initMouse(void) { int x = 0, y = 0; union REGS r; struct SREGS sr; r.w.ax = 0; /* check mouse driver */ int86(0x33, &r, &r); if (r.w.ax != 0xFFFF) return 0; r.w.ax = 0x0007; /* set horizontal range */ r.w.cx = 0; r.w.dx = _width - 1; int86(0x33, &r, &r); r.w.ax = 0x0008; /* set vertical range */ r.w.cx = 0; r.w.dx = _height - 1; int86(0x33, &r, &r); r.w.ax = 0x0004; /* position cursor */ r.w.cx = x; r.w.dx = y; int86(0x33, &r, &r); r.w.ax = 2; /* hide cursor */ int86(0x33, &r, &r); r.w.ax = 0x0014; /* install mouse event handler */ r.w.cx = MOUSE_MOVE | MOUSE_LEFT_DOWN | MOUSE_LEFT_UP | MOUSE_RIGHT_DOWN | MOUSE_RIGHT_UP; /* monitor these events */ r.x.edx = FP_OFF(mouseEvent); memset(&sr, 0, sizeof(sr)); sr.es = FP_SEG(mouseEvent); int86x(0x33, &r, &r, &sr); oldMouseEvent = MK_FP(sr.es, r.x.edx); buildMouseImage(); saveMouseBackground(x, y); moveMouse(x, y); return 1; }
/* ---------------------- deinit_keyboard() -------------- April 17,1993 */ void setkb(int vq){ int i; /* Index variable */ if(!vq){ // deinitiation /* Abort if our function pointer has no valid address */ if(oldkb == NULL) return; /* Set address in our function pointer in interrupt vector table */ _dos_setvect(9, oldkb); /* Reset our function pointer to contain no valid address */ oldkb = NULL; #ifdef TESTING /* Print the key heap */ printf("\n"); for(i=0; i<NUM_SCANCODES; i++){ if(i==NUM_SCANCODES/2) printf("================================\n"); printf("%03d[%d][%d]",i+1,key[i],kea[i]); if(key[i]==1)printf("===="); printf(",\n"); } #endif }else if(vq == 1){ // initiation byte far *lock_key; /* Abort if our function pointer has a valid address. */ if(oldkb != NULL) return; /* Clear the keyboard buttons state arrays */ for(i = 0; i < NUM_SCANCODES; i++) key[i] = kea[i] = 0; /* save old BIOS key board handler */ oldkb = _dos_getvect(9); // turn off num-lock via BIOS lock_key = MK_FP(0x040, 0x017); // Pointing to the address of the bios shift state keys *lock_key&=(~(16 | 32 | 64)); // toggle off the locks by changing the values of the 4th, 5th, and 6th bits of the address byte of 0040:0017 oldkb(); // call BIOS keyhandler to change keyboard lights /* setup our own handler */ _dos_setvect(9, newkb); } }
// test di installazione // reg: // ah code // al 0xFF // cx RUT_ACK1 // dx RUT_ACK2 // es:bx &tsr_type static struct tsr_type far * rut_is_installed_code(uint8 code) { asm mov ah, [code] asm xor al, al asm xor bx, bx asm xor cx, cx asm xor dx, dx int_2f_call(); asm cmp al, 0FFh asm jne notinst asm cmp cx, TSR_RUTACK1 asm jne notinst asm cmp dx, TSR_RUTACK2 asm jne notinst asm mov dx, es asm mov ax, bx return (struct tsr_type far*)MK_FP(_DX, _AX); notinst: return 0; }
//-------------------------------------------------------------------------- // // UMB::UMB. // // Attempt to construct a UMB block of the specified size. // UMB::UMB (long size) { address = 0; allocation = 0; if (size > (64 * K - 1) * PARA) status = XMS::BLOCK_TOO_BIG; else if ((status = XMSinit()) == XMS::SUCCESS) { size += PARA - 1; _DX = unsigned (size/PARA); _AH = 0x10; XMSdriver (); if (_AX != 0) { int bx = _BX; address = MK_FP (bx,0); allocation = unsigned (_DX); } else status = XMS::error (_BL); } allocation *= PARA; }
int EmsCheck(void) { static char DriverName[] = { 'E', 'M', 'M', 'X', 'X', 'X', 'X', '0' }; union REGS regs; struct SREGS sregs; char far *s; int i; /* retrieve pointer to driver header */ regs.x.ax = 0x3567; intdosx(®s, ®s, &sregs); /* getvect */ s = (char far *)MK_FP(sregs.es, 10); /* build far pointer */ /* now compare with what it should be */ for(i = 0; i < sizeof(DriverName); i++) { if(s[i] != DriverName[i]) break; } return i == sizeof(DriverName); }
int PASCAL WinMain( HINSTANCE this_inst, HINSTANCE prev_inst, LPSTR cmdline, int cmdshow ) /***************************************************************************************** Initialization, message loop. */ { MSG msg; INTER_FUNC **func; unsigned count; struct { INTER_FUNC *load; INTER_FUNC *unload; } *link; unsigned seg; unsigned off; prev_inst = prev_inst; cmdshow = cmdshow; seg = strtoul( cmdline, &cmdline, 16 ); off = strtoul( cmdline, NULL, 16 ); if( seg == 0 || off == 0 ) return( 1 ); link = MK_FP( seg, off ); TaskId = GetCurrentTask(); ThisInst = this_inst; func = (INTER_FUNC **)&MadImpInterface.MIInit; count = ( sizeof( mad_imp_routines ) - offsetof( mad_imp_routines, MIInit ) ) / sizeof( INTER_FUNC * ); while( count != 0 ) { *func = (INTER_FUNC *)MakeProcInstance( (FARPROC)*func, this_inst ); ++func; --count; } link->load = (INTER_FUNC *)MakeProcInstance( (FARPROC)MADLOAD, this_inst ); link->unload = (INTER_FUNC *)MakeProcInstance( (FARPROC)MADUNLOAD, this_inst ); while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return( 0 ); }
void DrawRadios(radiogroup_t *rg) { int i; int value; radio_t *r; char far *screen; byte color; value = *(rg->master); color = (rg->bgcolor << 4)+rg->fgcolor; r = rg->radios; for (i = 0; i < rg->amount; i++) { screen = MK_FP(0xb800,(r->y*160)+(r->x*2)); *(screen+1) = color; if (value == r->value) *screen = 7; else *screen = ' '; r++; } }
int check_quotes() { union REGS regs; static unsigned char far *psp; /* Get the segment address of PSP. */ regs.x.ax = 0x6200; intdos(®s, ®s); /* Get address of original command line. */ psp = MK_FP(regs.x.bx, 0x81); /* Check for double quotes. */ for (;*psp != '\r';psp++) { if (*psp==DBQ) return(1); } /* end for. */ return(0); } /* end check_quotes. */