void GUImain( void ) { #if defined(__OSI__) || __WATCOMC__ < 1000 { long result; #if defined(__OSI__) _Extender = 1; #endif result = DPMIAllocateLDTDescriptors( 1 ); if( result < 0 ) { StartupErr( LIT( Unable_to_get_rm_sel ) ); } _ExtenderRealModeSelector = result & 0xffff; if( DPMISetSegmentLimit( _ExtenderRealModeSelector, 0xfffff ) ) { StartupErr( LIT( Unable_to_get_rm_sel ) ); } } #endif SaveOrigVectors(); Orig28.a = MyGetRMVector( 0x28 ); RMData.a = DPMIAllocateDOSMemoryBlock( _NBPARAS( RMSegEnd - RMSegStart ) ); if( RMData.s.pm == 0 ) { StartupErr( LIT( Unable_to_alloc_DOS_mem ) ); } PMData = MK_FP( RMData.s.pm, 0 ); _fmemcpy( PMData, RMSegStart, RMSegEnd - RMSegStart ); if( _osmajor == 2 ) { PMData->fail = 0; } else { PMData->fail = 3; } DebugMain(); }
static char *ReadInTrap( tiny_handle_t fh ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; rm_call_struct read; unsigned offset; if( TINY_ERROR( TinyRead( fh, &hdr, sizeof( hdr ) ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = ( hdr.file_size * 0x200 ) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } TinySeek( fh, hdrsize, TIO_SEEK_SET ); memset( &read, 0, sizeof( read ) ); for( offset = 0; offset < imagesize; offset += (unsigned_16)read.eax ) { read.ss = RMData.segm.rm; read.sp = offsetof( rm_data, stack ) + STACK_SIZE; read.edx = offset; read.ebx = fh; read.ds = TrapMem.segm.rm; read.ecx = imagesize - offset; read.eax = 0x3f00; #if 1 relocnb = DPMISimulateRealModeInterrupt( 0x21, 0, 0, &read ); if( (read.flags & 1) || (unsigned_16)read.eax == 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #else read.eax = TinyRead( fh, (void *)((TrapMem.segm.rm << 4) + offset), imagesize - offset ); if( (signed_32)read.eax < 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } #endif } TinySeek( fh, hdr.reloc_offset, TIO_SEEK_SET ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( TINY_ERROR( TinyRead( fh, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)MK_PM( TrapMem.segm.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.segm.rm; } return( NULL ); }
static char *SetTrapHandler( void ) { char dummy; long result; descriptor desc; version_info ver; PMData->vecttable1[DOS4G_COMM_VECTOR].s.segment = RMData.segm.rm; PMData->vecttable1[DOS4G_COMM_VECTOR].s.offset = RM_OFF( Interrupt15 ); PMData->vecttable2[DOS4G_COMM_VECTOR].s.segment = RMData.segm.rm; PMData->vecttable2[DOS4G_COMM_VECTOR].s.offset = RM_OFF( Interrupt15 ); if( IntrState == IS_NONE ) { DPMIGetVersion( &ver ); if( (ver.major_version >= 1 || ver.minor_version > 90) || DPMICheck == 2 ) { RawPMtoRMSwitchAddr = DPMIRawPMtoRMAddr(); PMData->switchaddr.a= DPMIRawRMtoPMAddr(); } if( RawPMtoRMSwitchAddr == 0 || PMData->switchaddr.a == 0 || DPMICheck == 1 ) { IntrState = IS_RATIONAL; } else { PMData->saveaddr.a = DPMISavePMStateAddr(); PMData->savesize = DPMISaveStateSize(); if( PMData->savesize == 0 ) { PMData->saveseg.dpmi_adr = 0; } else { PMData->saveseg.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS(PMData->savesize*2) ); if( PMData->saveseg.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } } PMData->othersaved = false; result = DPMIAllocateLDTDescriptors( 1 ); if( result < 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } DPMIGetDescriptor( FP_SEG( PMData ), &desc ); PMData->pmode_cs = (unsigned_16)result; desc.xtype.use32 = 0; desc.type.execute = 1; DPMISetDescriptor( PMData->pmode_cs, &desc ); PMData->pmode_eip = RM_OFF( BackFromRealMode ); PMData->pmode_ds = FP_SEG( &PMData ); PMData->pmode_es = PMData->pmode_ds; PMData->pmode_ss = FP_SEG( &dummy ); IntrState = IS_DPMI; } } if( IntrState == IS_RATIONAL ) { MySetRMVector( TRAP_VECTOR, RMData.segm.rm, RM_OFF( RMTrapHandler ) ); } return( NULL ); }
static char *ReadInTrap( dig_ldhandle ldfh ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; rm_call_struct rm_dos_read; unsigned offset; if( DIGLoader( Read )( ldfh, &hdr, sizeof( hdr ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = ( hdr.file_size * 0x200 ) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } DIGLoader( Seek )( ldfh, hdrsize, DIG_ORG ); // DPMI file read to real mode memory memset( &rm_dos_read, 0, sizeof( rm_dos_read ) ); for( offset = 0; offset < imagesize; offset += (unsigned_16)rm_dos_read.eax ) { rm_dos_read.ss = RMData.segm.rm; rm_dos_read.sp = offsetof( rm_data, stack ) + STACK_SIZE; rm_dos_read.edx = offset; rm_dos_read.ebx = ldfh; rm_dos_read.ds = TrapMem.segm.rm; rm_dos_read.ecx = imagesize - offset; rm_dos_read.eax = 0x3f00; relocnb = DPMISimulateRealModeInterrupt( 0x21, 0, 0, &rm_dos_read ); if( (rm_dos_read.flags & 1) || (unsigned_16)rm_dos_read.eax == 0 ) { return( TC_ERR_CANT_LOAD_TRAP ); } } DIGLoader( Seek )( ldfh, hdr.reloc_offset, DIG_ORG ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( DIGLoader( Read )( ldfh, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)MK_PM( TrapMem.segm.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.segm.rm; } return( NULL ); }
static char *CopyEnv( void ) { char __far *envarea; uint_16 envsize; #ifdef __OSI__ { extern char *_EnvPtr; envarea = _EnvPtr; } #else envarea = MK_FP( *(addr_seg __far *)MK_FP( _psp, PSP_ENVSEG_OFF ), 0 ); #endif envsize = EnvAreaSize( envarea ); PMData->envseg.dpmi_adr = DPMIAllocateDOSMemoryBlock( _NBPARAS( envsize ) ); if( PMData->envseg.segm.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } _fmemcpy( MK_PM( PMData->envseg.segm.rm, 0 ), envarea, envsize ); return( NULL ); }
static char *ReadInTrap( FILE *fp ) { dos_exe_header hdr; memptr relocbuff[NUM_BUFF_RELOCS]; unsigned relocnb; unsigned imagesize; unsigned hdrsize; if( DIGLoader( Read )( fp, &hdr, sizeof( hdr ) ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } if( hdr.signature != DOS_SIGNATURE ) { return( TC_ERR_BAD_TRAP_FILE ); } hdrsize = hdr.hdr_size * 16; imagesize = ( hdr.file_size * 0x200 ) - (-hdr.mod_size & 0x1ff) - hdrsize; TrapMem = DPMIAllocateDOSMemoryBlock( _NBPARAS( imagesize ) + hdr.min_16 ); if( TrapMem.pm == 0 ) { return( TC_ERR_OUT_OF_DOS_MEMORY ); } DIGLoader( Seek )( fp, hdrsize, DIG_ORG ); if( DIGLoader( Read )( fp, (void *)DPMIGetSegmentBaseAddress( TrapMem.pm ), imagesize ) != imagesize ) { return( TC_ERR_CANT_LOAD_TRAP ); } DIGLoader( Seek )( fp, hdr.reloc_offset, DIG_ORG ); for( relocnb = NUM_BUFF_RELOCS; hdr.num_relocs > 0; --hdr.num_relocs, ++relocnb ) { if( relocnb >= NUM_BUFF_RELOCS ) { if( DIGLoader( Read )( fp, relocbuff, sizeof( memptr ) * NUM_BUFF_RELOCS ) ) { return( TC_ERR_CANT_LOAD_TRAP ); } relocnb = 0; } *(addr_seg __far *)EXTENDER_RM2PM( TrapMem.rm + relocbuff[relocnb].s.segment, relocbuff[relocnb].s.offset ) += TrapMem.rm; } return( NULL ); }