示例#1
0
//--------------------------------------------------------
// returns 0 if no mouse
//           else number of buttons
int mouse_init(int enable_cyberman)
{
	dpmi_real_regs rr;
	cyberman_info *ci;
	struct SREGS sregs;
	union REGS inregs, outregs;
	ubyte *Mouse_dos_mem;

	if (Mouse_installed)
		return Mouse.num_buttons;

   if (_dos_getvect(0x33) == NULL) {
      // No mouse driver loaded
      return 0;
   }

	// Reset the mouse driver
	memset( &inregs, 0, sizeof(inregs) );
	inregs.w.ax = 0;
	int386(0x33, &inregs, &outregs);
	if (outregs.w.ax != 0xffff)
		return 0;

	Mouse.num_buttons = outregs.w.bx;
	Mouse.cyberman = 0;

	// Enable mouse driver
	memset( &inregs, 0, sizeof(inregs) );
	inregs.w.ax = 0x0020;
	int386(0x33, &inregs, &outregs);
	if (outregs.w.ax != 0xffff )
		return 0;

	if ( enable_cyberman )	{
		Mouse_dos_mem = dpmi_get_temp_low_buffer( 64 );
		if (Mouse_dos_mem==NULL)	{
			printf( "Unable to allocate DOS buffer in mouse.c\n" );
		} else {
			// Check for Cyberman...	
			memset( &rr, 0, sizeof(dpmi_real_regs) );
			rr.es = DPMI_real_segment(Mouse_dos_mem);
			rr.edx = DPMI_real_offset(Mouse_dos_mem);
			rr.eax = 0x53c1;
			dpmi_real_int386x( 0x33, &rr );
			if (rr.eax==1)	{
				// SWIFT functions supported
				ci	= (cyberman_info *)Mouse_dos_mem;
				if (ci->device_type==1)	{	// Cyberman	
					Mouse.cyberman = 1;
					//printf( "Cyberman mouse detected\n" );
					Mouse.num_buttons = 11;
				}
			}
		}
	}

	if (!dpmi_lock_region(&Mouse,sizeof(mouse_info)))	{
		Error( "Unable to lock mouse data region" );
	}
	if (!dpmi_lock_region((void near *)mouse_handler,(char *)mouse_handler_end - (char near *)mouse_handler))	{
		Error( "Unable to lock mouse handler" );
	}

	// Install mouse handler
	memset( &inregs, 0, sizeof(inregs));
	memset( &sregs, 0, sizeof(sregs));
	inregs.w.ax 	= 0xC;
	inregs.w.cx 	= ME_LB_P|ME_LB_R|ME_RB_P|ME_RB_R|ME_MB_P|ME_MB_R;	// watch all 3 button ups/downs
	if (Mouse.cyberman)
		inregs.w.cx 	|= ME_Z_C| ME_P_C| ME_B_C| ME_H_C;	// if using a cyberman, also watch z, pitch, bank, heading.
	inregs.x.edx	= FP_OFF(mouse_handler);
	sregs.es 		= FP_SEG(mouse_handler);
	int386x(0x33, &inregs, &outregs, &sregs);

	Mouse_installed = 1;

	atexit( mouse_close );

	mouse_flush();

	return Mouse.num_buttons;
}
示例#2
0
/* variables needed for the rest of the handler.                        */
VOID int21_syscall(iregs FAR * irp)
{
  Int21AX = irp->AX;

  switch (irp->AH)
  {
      /* DosVars - get/set dos variables                              */
    case 0x33:
      switch (irp->AL)
      {
          /* Get Ctrl-C flag                                      */
        case 0x00:
          irp->DL = break_ena ? TRUE : FALSE;
          break;

          /* Set Ctrl-C flag                                      */
        case 0x01:
          break_ena = irp->DL ? TRUE : FALSE;
          break;

          /* Get Boot Drive                                       */
        case 0x05:
          irp->DL = BootDrive;
          break;

          /* Get DOS-C version                                    */
        case 0x06:
          irp->BL = os_major;
          irp->BH = os_minor;
          irp->DL = rev_number;
          irp->DH = version_flags;
          break;

        default:
          irp->AX = -DE_INVLDFUNC;
          irp->FLAGS |= FLG_CARRY;
          break;

          /* Toggle DOS-C rdwrblock trace dump                    */
        case 0xfd:
#ifdef DEBUG
          bDumpRdWrParms = !bDumpRdWrParms;
#endif
          break;

          /* Toggle DOS-C syscall trace dump                      */
        case 0xfe:
#ifdef DEBUG
          bDumpRegs = !bDumpRegs;
#endif
          break;

          /* Get DOS-C release string pointer                     */
        case 0xff:
          irp->DX = FP_SEG(os_release);
          irp->AX = FP_OFF(os_release);
          break;
      }
      break;

      /* Set PSP                                                      */
    case 0x50:
      cu_psp = irp->BX;
      break;

      /* Get PSP                                                      */
    case 0x51:
      irp->BX = cu_psp;
      break;

      /* UNDOCUMENTED: return current psp                             */
    case 0x62:
      irp->BX = cu_psp;
      break;

      /* Normal DOS function - switch stacks          */
    default:
      int21_service(user_r);
      break;
  }
}
示例#3
0
T_directTalkHandle DirectTalkInit(
           T_directTalkReceiveCallback p_callRecv,
           T_directTalkSendCallback p_callSend,
           T_directTalkConnectCallback p_callConnect,
           T_directTalkDisconnectCallback p_callDisconnect,
           T_directTalkHandle handle)
{
    T_directTalkStruct *p_talk ;
    T_directTalkHandle newHandle = DIRECT_TALK_HANDLE_BAD ;
    T_word16 vector ;
    T_byte8 **p_vector ;

    DebugRoutine("DirectTalkInit") ;

    /* Record the send and receive callbacks. */
    G_receiveCallback = p_callRecv ;
    G_sendCallback = p_callSend ;
    G_connectCallback = p_callConnect ;
    G_disconnectCallback = p_callDisconnect ;

    memset(&G_blankAddress, 0, sizeof(G_blankAddress)) ;

#ifdef COMPILE_OPTION_DIRECT_TALK_IS_DOS32
    DebugCheck(p_callRecv != NULL) ;
    DebugCheck(p_callSend == NULL) ;
    DebugCheck(p_callConnect == NULL) ;
    DebugCheck(p_callDisconnect == NULL) ;

    if ((handle == DIRECT_TALK_HANDLE_BAD) ||
        (((T_word32)handle) >= 0x100000))  {
        puts("DirectTalk Failure: BAD TALK HANDLE.  Is a driver running?") ;
        exit(1) ;
    }

    /* Get access to the structure from the given handle. */
    p_talk = (T_directTalkStruct *)handle ;

    /* Store the pointer for future use. */
    G_talk = p_talk ;

    if (p_talk->tag != DIRECT_TALK_TAG)  {
        puts("DirectTalk Failure: BAD TALK HANDLE.  Is a driver running?") ;
        exit(1) ;
    }

    /* Make sure we are talking about the same handle. */
    if (p_talk->handle != handle)  {
        puts("DirectTalk Failure: INCONSISTENT HANDLES.") ;
        exit(1) ;
    }

    if ((p_talk->vector < VALID_LOW_VECTOR) ||
        (p_talk->vector > VALID_HIGH_VECTOR))  {
        puts("DirectTalk Failure: BAD VECTOR NUMBER.") ;
        exit(1) ;
    }

    /* Init is successful. */
    newHandle = handle ;
#else
    DebugCheck(p_callRecv != NULL) ;
    DebugCheck(p_callSend != NULL) ;
    DebugCheck(p_callConnect != NULL) ;
    DebugCheck(p_callDisconnect != NULL) ;

    /* Allocate memory for the talk structure. */
    p_talk = G_talk = MemAlloc(sizeof(T_directTalkStruct)) ;
    if (p_talk == NULL)  {
        puts("DirectTalk Failure: NOT ENOUGH MEMORY.") ;
        exit(1) ;
    }

    /* Clear the talk structure. */
    memset(G_talk, 0, sizeof(T_directTalkStruct)) ;

    /* Mark the talk structure as valid. */
    p_talk->tag = DIRECT_TALK_TAG ;

    /* Convert the address into an appropriate handle. */
    handle = (((T_word32)(FP_SEG((T_void far *)p_talk)))<<4) +
                 ((T_word32)(FP_OFF((T_void far *)p_talk))) ;

    /* Store the handle for validation later. */
    p_talk->handle = handle ;

    /* Now, look for a vector that we can use. */
    for (vector=VALID_LOW_VECTOR; vector <= VALID_HIGH_VECTOR; vector++)  {
        p_vector = (T_byte8 **)(vector * 4) ;
        if ((!(*p_vector)) || (**p_vector == 0xCF))  {
            /* Found a vector I can use. */
            break ;
        }
    }

    /* Check if the vector is now good. */
    if (vector > VALID_HIGH_VECTOR)  {
        puts("DirectTalk Failure: CANNOT FIND USABLE VECTOR") ;
        exit(1) ;
    }

    /* Vector is good.  Store it. */
    p_talk->vector = vector ;

    /* Install vector. */
    printf("Installing on vector 0x%02X\n", vector) ;
	G_oldVector = getvect(vector);
	setvect(vector, IDirectTalkISR);
    G_interruptInstalled = TRUE ;

    atexit(IDirectTalkUndoISR) ;

    /* Record the new handle we are to use. */
    newHandle = handle ;
#endif

    DebugEnd() ;

    return newHandle ;
}
示例#4
0
void interrupt sys_call(void){

	static IOD *temp;
	
	//Saves the ss and sp register to a temp storage
	ss_save2 = _SS;
	sp_save2 = _SP;
	COP->stack = (unsigned char *)MK_FP(ss_save2,sp_save2);
	//Updates the stacktop for context switch
	
	
	//Access Parameters that sys_req placed on the stack
	param_ptr = (params*)(COP->stack+sizeof(context));
	
	//Switching to a temp stack
	new_ss = FP_SEG(sys_stack);
	new_sp = FP_OFF(sys_stack)+ SYS_STACK_SIZE;
	_SS = new_ss;
	_SP = new_sp;
	
	trm_getc();
	
	if(TerminalQueue->event_flag==1 && TerminalQueue->count > 0){
		TerminalQueue->event_flag = 0;
		temp = TerminalQueue->head;
		TerminalQueue->head = TerminalQueue->head->next;
		unblockPCB(temp->ppt->processName);
		sys_free_mem(temp);
		TerminalQueue->count--;
		if(TerminalQueue->count!=0){
			ProcessIORequest(1);
		}
	}
	if(Com_PortQueue->event_flag==1 && Com_PortQueue->count > 0){
		Com_PortQueue->event_flag = 0;
		temp = Com_PortQueue->head;
		Com_PortQueue->head = Com_PortQueue->head->next;
		unblockPCB(temp->ppt->processName);
		sys_free_mem(temp);
		Com_PortQueue->count--;
		if(Com_PortQueue->count!=0){
			ProcessIORequest(1);
		}
	}
	
	//Process is idle
	if (param_ptr -> op_code == IDLE){
		//Sets state to running and adds it back into the readyQueue
		COP -> state = 2; 
		PriorityEnqueue(readyQueue,COP);
	}
	//Process is completed and ready for deletion 
	if (param_ptr -> op_code == EXIT){
		//Frees the memory of the PCB and sets the PCB to NULL
		freePCB(COP);
		COP = NULL;
	}
	if (param_ptr -> op_code == READ ||param_ptr -> op_code == WRITE ||param_ptr -> op_code == CLEAR ||param_ptr -> op_code == GOTOXY ){
		IOScheduler();
	}
	//Dispatches the next process in the readyQueue
	dispatch();
}
示例#5
0
VOID int21_service(iregs FAR * r)
{
  COUNT rc = 0,
	  rc1;
  psp FAR *p = MK_FP(cu_psp, 0);
  void FAR *FP_DS_DX = MK_FP(r->DS, r->DX); /* this is saved so often,
                                               that this saves ~100 bytes */

    
#define CLEAR_CARRY_FLAG()  r->FLAGS &= ~FLG_CARRY
#define SET_CARRY_FLAG()    r->FLAGS |= FLG_CARRY

  p->ps_stack = (BYTE FAR *) r;

#ifdef DEBUG 
  if (bDumpRegs)
  {
    fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs));
    printf("System call (21h): %02x\n", user_r->AX);
    dump_regs = TRUE;
    dump();
  }
#endif

  if(r->AH >=0x38 && r->AH <= 0x4F)
      CLEAR_CARRY_FLAG();
      /* Clear carry by default for these functions */

dispatch:

  /* Check for Ctrl-Break */
  switch (r->AH)
  {
    default:
      if (!break_ena)
        break;
    case 0x01:
    case 0x02:
    case 0x03:
    case 0x04:
    case 0x05:
    case 0x08:
    case 0x09:
    case 0x0a:
    case 0x0b:
      if (control_break())
        handle_break();
  }

  /* The dispatch handler                                         */
  switch (r->AH)
  {
      /* int 21h common error handler                                 */
    case 0x64:
    error_invalid:
      r->AX = -DE_INVLDFUNC;
      goto error_out;
    error_exit:
      r->AX = -rc;
    error_out:
      CritErrCode = r->AX;  /* Maybe set */
      SET_CARRY_FLAG();
      break;

       /* case 0x00:   --> Simulate a DOS-4C-00 */

      /* Read Keyboard with Echo                      */
    case 0x01:
      r->AL = _sti(TRUE);
      sto(r->AL);
      break;

      /* Display Character                                            */
    case 0x02:
      sto(r->DL);
      break;

      /* Auxiliary Input                                                      */
    case 0x03:
     {
      COUNT scratch;
      GenericRead(STDAUX, 1, (BYTE FAR *) & r->AL, (COUNT FAR *) & scratch, TRUE);
      break;
     }

      /* Auxiliary Output                                                     */
    case 0x04:
     {
      COUNT scratch;
      DosWrite(STDAUX, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch);
      break;
     }
      /* Print Character                                                      */
    case 0x05:
     {       
      COUNT scratch;       
      DosWrite(STDPRN, 1, (BYTE FAR *) & r->DL, (COUNT FAR *) &scratch);
      break;      
     }

      /* Direct Console I/O                                            */
    case 0x06:
      if (r->DL != 0xff)
        sto(r->DL);
      else if (StdinBusy())
      {
        r->AL = 0x00;
        r->FLAGS |= FLG_ZERO;
      }
      else
      {
        r->FLAGS &= ~FLG_ZERO;
        r->AL = _sti(FALSE);
      }
      break;

      /* Direct Console Input                                         */
    case 0x07:
      r->AL = _sti(FALSE);
      break;

      /* Read Keyboard Without Echo                                   */
    case 0x08:
      r->AL = _sti(TRUE);
      break;

      /* Display String                                               */
    case 0x09:
      {
        BYTE FAR * q;
        q = FP_DS_DX;
        while (*q != '$')
          ++q;
        DosWrite(STDOUT, FP_OFF(q) - FP_OFF(FP_DS_DX), FP_DS_DX, (COUNT FAR *) & UnusedRetVal);
      }
      r->AL = '$';
      break;

      /* Buffered Keyboard Input                                      */
    case 0x0a:
      sti_0a((keyboard FAR *) FP_DS_DX);
      break;

      /* Check Stdin Status                                           */
    case 0x0b:
      if (StdinBusy())
        r->AL = 0x00;
      else
        r->AL = 0xFF;
      break;

      /* Flush Buffer, Read Keayboard                                 */
    case 0x0c:
      KbdFlush();
      switch (r->AL)
      {
        case 0x01:
        case 0x06:
        case 0x07:
        case 0x08:
        case 0x0a:
          r->AH = r->AL;
          goto dispatch;

        default:
          r->AL = 0x00;
          break;
      }
      break;

      /* Reset Drive                                                  */
    case 0x0d:
      flush();
      break;

      /* Set Default Drive                                            */
    case 0x0e:
      r->AL = DosSelectDrv(r->DL);
      break;

    case 0x0f:
      if (FcbOpen(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x10:
      if (FcbClose(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x11:
      if (FcbFindFirst(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x12:
      if (FcbFindNext(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x13:
      if (FcbDelete(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x14:
      {
        if (FcbRead(FP_DS_DX, &CritErrCode))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

    case 0x15:
      {
        if (FcbWrite(FP_DS_DX, &CritErrCode))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

    case 0x16:
      if (FcbCreate(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x17:
      if (FcbRename(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    default:
#ifdef DEBUG
       printf("Unsupported INT21 AH = 0x%x, AL = 0x%x.\n", r->AH, r->AL);
#endif
      /* Fall through. */

    /* CP/M compatibility functions                                 */
    case 0x18:
    case 0x1d:
    case 0x1e:
    case 0x20:
#ifndef TSC
    case 0x61:
#endif
    case 0x6b:
      r->AL = 0;
      break;

      /* Get Default Drive                                            */
    case 0x19:
      r->AL = default_drive;
      break;

      /* Set DTA                                                      */
    case 0x1a:
      {
        psp FAR *p = MK_FP(cu_psp, 0);

        p->ps_dta = FP_DS_DX;
        dos_setdta(p->ps_dta);
      }
      break;

      /* Get Default Drive Data                                       */
    case 0x1b:
      {
        BYTE FAR *p;

        FatGetDrvData(0,
                      (COUNT FAR *) & r->AX,
                      (COUNT FAR *) & r->CX,
                      (COUNT FAR *) & r->DX,
                      (BYTE FAR **) & p);
        r->DS = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get Drive Data                                               */
    case 0x1c:
      {
        BYTE FAR *p;

        FatGetDrvData(r->DL,
                      (COUNT FAR *) & r->AX,
                      (COUNT FAR *) & r->CX,
                      (COUNT FAR *) & r->DX,
                      (BYTE FAR **) & p);
        r->DS = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get default DPB                                              */
      /* case 0x1f: see case 0x32 */

      /* Random read using FCB */
    case 0x21:
      {
        if (FcbRandomIO(FP_DS_DX, &CritErrCode, FcbRead))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

      /* Random write using FCB */
    case 0x22:
      {
        if (FcbRandomIO(FP_DS_DX, &CritErrCode, FcbWrite))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

      /* Get file size in records using FCB */
    case 0x23:
      if (FcbGetFileSize(FP_DS_DX))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

      /* Set random record field in FCB */
    case 0x24:
      FcbSetRandom(FP_DS_DX);
      break;

      /* Set Interrupt Vector                                         */
    case 0x25:
      {
        VOID(INRPT FAR * p) () = FP_DS_DX;

        setvec(r->AL, p);
      }
      break;

      /* Dos Create New Psp                                           */
    case 0x26:
      {
        psp FAR *p = MK_FP(cu_psp, 0);

        new_psp((psp FAR *) MK_FP(r->DX, 0), p->ps_size);
      }
      break;

      /* Read random record(s) using FCB */
    case 0x27:
      {
        if (FcbRandomBlockRead(FP_DS_DX, r->CX, &CritErrCode))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

      /* Write random record(s) using FCB */
    case 0x28:
      {
        if (FcbRandomBlockWrite(FP_DS_DX, r->CX, &CritErrCode))
          r->AL = 0;
        else
          r->AL = CritErrCode;
        break;
      }

      /* Parse File Name                                              */
    case 0x29:
      {
        BYTE FAR *lpFileName;

        lpFileName = MK_FP(r->DS, r->SI);
        r->AL = FcbParseFname(r->AL,
                              &lpFileName,
                              MK_FP(r->ES, r->DI));
        r->DS = FP_SEG(lpFileName);
        r->SI = FP_OFF(lpFileName);
      }
      break;

      /* Get Date                                                     */
    case 0x2a:
      DosGetDate(
                  (BYTE FAR *) & (r->AL),	/* WeekDay              */
                  (BYTE FAR *) & (r->DH),	/* Month                */
                  (BYTE FAR *) & (r->DL),	/* MonthDay             */
                  (COUNT FAR *) & (r->CX));	/* Year                 */
      break;

      /* Set Date                                                     */
    case 0x2b:
      rc = DosSetDate(
                       (BYTE FAR *) & (r->DH),	/* Month                */
                       (BYTE FAR *) & (r->DL),	/* MonthDay             */
                       (COUNT FAR *) & (r->CX));	/* Year                 */
      if (rc != SUCCESS)
        r->AL = 0xff;
      else
        r->AL = 0;
      break;

      /* Get Time                                                     */
    case 0x2c:
      DosGetTime(
                  (BYTE FAR *) & (r->CH),	/* Hour                 */
                  (BYTE FAR *) & (r->CL),	/* Minutes              */
                  (BYTE FAR *) & (r->DH),	/* Seconds              */
                  (BYTE FAR *) & (r->DL));	/* Hundredths           */
      break;

      /* Set Date                                                     */
    case 0x2d:
      rc = DosSetTime(
                       (BYTE FAR *) & (r->CH),	/* Hour                 */
                       (BYTE FAR *) & (r->CL),	/* Minutes              */
                       (BYTE FAR *) & (r->DH),	/* Seconds              */
                       (BYTE FAR *) & (r->DL));	/* Hundredths           */
      if (rc != SUCCESS)
        r->AL = 0xff;
      else
        r->AL = 0;
      break;

      /* Set verify flag                                              */
    case 0x2e:
      verify_ena = (r->AL ? TRUE : FALSE);
      break;

      /* Get DTA                                                      */
    case 0x2f:
      r->ES = FP_SEG(dta);
      r->BX = FP_OFF(dta);
      break;

      /* Get DOS Version                                              */
    case 0x30:
      r->AL = os_major;
      r->AH = os_minor;
      r->BH = OEM_ID;
      r->CH = REVISION_MAJOR;   /* JPP */
      r->CL = REVISION_MINOR;
      r->BL = REVISION_SEQ;
      
      if (ReturnAnyDosVersionExpected)  
      {
                            /* TE for testing purpose only and NOT 
                               to be documented:
                               return programs, who ask for version == XX.YY
                               exactly this XX.YY. 
                               this makes most MS programs more happy.
                            */
        UBYTE FAR *retp = MK_FP(r->cs, r->ip);
        
        if (     retp[0] == 0x3d  &&     /* cmp ax, xxyy */
                (retp[3] == 0x75 || retp[3] == 0x74)) /* je/jne error    */
        {
            r->AL = retp[1];
            r->AH = retp[2];
        }
        else if(retp[0] == 0x86 &&      /* xchg al,ah   */
                retp[1] == 0xc4 &&
                retp[2] == 0x3d &&      /* cmp ax, xxyy */
               (retp[5] == 0x75 || retp[5] == 0x74)) /* je/jne error    */                               
        {
            r->AL = retp[4];
            r->AH = retp[3];
        }                
            
      }
      
      break;

      /* Keep Program (Terminate and stay resident) */
    case 0x31:
      DosMemChange(cu_psp, r->DX < 6 ? 6 : r->DX, 0);
      return_mode = 3;
      return_code = r->AL;
      tsr = TRUE;
      return_user();
      break;

      /* Get default BPB */
    case 0x1f:
      /* Get DPB                                                      */
    case 0x32:
      /* r->DL is NOT changed by MS 6.22 */
      /* INT21/32 is documented to reread the DPB */
      {
      struct dpb FAR *dpb;  
      UCOUNT drv = r->DL;
      
      if (drv == 0 || r->AH == 0x1f) drv = default_drive;
      else          drv--;

      if (drv >= lastdrive)
      {
        r->AL = 0xFF;
        CritErrCode = 0x0f;
        break;
      }  
        
      dpb = CDSp->cds_table[drv].cdsDpb;
      if (dpb == 0 ||
          CDSp->cds_table[drv].cdsFlags & CDSNETWDRV)
      {
        r->AL = 0xFF;
        CritErrCode = 0x0f;
        break;
      }  
      dpb->dpb_flags = M_CHANGED;       /* force reread of drive BPB/DPB */
          
      if (media_check(dpb) < 0)
      {
          r->AL = 0xff;
          CritErrCode = 0x0f;
          break;
      }
      r->DS = FP_SEG(dpb);
      r->BX = FP_OFF(dpb);
      r->AL = 0;
      }

      break;
/*
    case 0x33:  
    see int21_syscall
*/
      /* Get InDOS flag                                               */
    case 0x34:
      {
        BYTE FAR *p;

        p = (BYTE FAR *) ((BYTE *) & InDOS);
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get Interrupt Vector                                         */
    case 0x35:
      {
        BYTE FAR *p;

        p = getvec((COUNT) r->AL);
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Dos Get Disk Free Space                                      */
    case 0x36:
      DosGetFree(
                  r->DL,
                  (COUNT FAR *) & r->AX,
                  (COUNT FAR *) & r->BX,
                  (COUNT FAR *) & r->CX,
                  (COUNT FAR *) & r->DX);
      break;

      /* Undocumented Get/Set Switchar                                */
    case 0x37:
      switch (r->AL)
      {
          /* Get switch character */
        case 0x00:
          r->DL = switchar;
          r->AL = 0x00;
          break;

          /* Set switch character */
        case 0x01:
          switchar = r->DL;
          r->AL = 0x00;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Get/Set Country Info                                         */
    case 0x38:
      {
      	UWORD cntry = r->AL;

      	if(cntry == 0)
      		cntry = (UWORD)-1;
      	else if(cntry == 0xff)
      		cntry = r->BX;

        if (0xffff == r->DX) {
        	/* Set Country Code */
            if((rc = DosSetCountry(cntry)) < 0)
        		goto error_invalid;
        } else {
        	/* Get Country Information */
            if((rc = DosGetCountryInformation(cntry, FP_DS_DX)) < 0)
        		goto error_invalid;
            /* HACK FIXME */
	    if(cntry == (UWORD)-1)
		cntry = 1;
            /* END OF HACK */
            r->AX = r->BX = cntry;
        }
      }
      break;

      /* Dos Create Directory                                         */
    case 0x39:
      rc = DosMkdir((BYTE FAR *) FP_DS_DX);
      if (rc != SUCCESS)
        goto error_exit;
      break;

      /* Dos Remove Directory                                         */
    case 0x3a:
      rc = DosRmdir((BYTE FAR *) FP_DS_DX);
      if (rc != SUCCESS)
        goto error_exit;
      break;

      /* Dos Change Directory                                         */
    case 0x3b:
      if ((rc = DosChangeDir((BYTE FAR *) FP_DS_DX)) < 0)
        goto error_exit;
      break;

      /* Dos Create File                                              */
    case 0x3c:
      if ((rc = DosCreat(FP_DS_DX, r->CX)) < 0)
        goto error_exit;
      else
        r->AX = rc;
      break;

      /* Dos Open                                                     */
    case 0x3d:
      if ((rc = DosOpen(FP_DS_DX, r->AL)) < 0)
        goto error_exit;
      else
        r->AX = rc;
      break;

      /* Dos Close                                                    */
    case 0x3e:
      if ((rc = DosClose(r->BX)) < 0)
        goto error_exit;
      break;

      /* Dos Read                                                     */
    case 0x3f:
      rc1 = DosRead(r->BX, r->CX, FP_DS_DX, (COUNT FAR *) & rc);
      if (rc != SUCCESS)
        goto error_exit;
      else
        r->AX = rc1;
      break;

      /* Dos Write                                                    */
    case 0x40:
      rc1 = DosWrite(r->BX, r->CX, FP_DS_DX, (COUNT FAR *) & rc);
      if (rc != SUCCESS)
        goto error_exit;
      else
        r->AX = rc1;
      break;

      /* Dos Delete File                                              */
    case 0x41:
      rc = DosDelete((BYTE FAR *) FP_DS_DX);
      if (rc < 0)
        goto error_exit;
      break;

      /* Dos Seek                                                     */
    case 0x42:
      {
      ULONG lrc;
      if ((rc = DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) + r->DX), r->AL, &lrc)) < 0)
        goto error_exit;
      else
      {
        r->DX = (lrc >> 16);
        r->AX = (UWORD)lrc;
      }
      }
      break;

      /* Get/Set File Attributes                                      */
    case 0x43:
      switch (r->AL)
      {
        case 0x00:
          rc = DosGetFattr((BYTE FAR *) FP_DS_DX);
          if (rc >= SUCCESS)
              r->CX = rc;
          break;

        case 0x01:
          rc = DosSetFattr((BYTE FAR *) FP_DS_DX, r->CX);
          break;

        default:
          goto error_invalid;
      }
      if (rc < SUCCESS)
        goto error_exit;
      break;

      /* Device I/O Control                                           */
    case 0x44:
      rc = DosDevIOctl(r);

      if (rc != SUCCESS)
        goto error_exit;
      break;

      /* Duplicate File Handle                                        */
    case 0x45:
      rc = DosDup(r->BX);
      if (rc < SUCCESS)
        goto error_exit;
      else
        r->AX = rc;
      break;

      /* Force Duplicate File Handle                                  */
    case 0x46:
      rc = DosForceDup(r->BX, r->CX);
      if (rc < SUCCESS)
        goto error_exit;
      break;

      /* Get Current Directory                                        */
    case 0x47:
      if ((rc = DosGetCuDir(r->DL, MK_FP(r->DS, r->SI))) < 0)
        goto error_exit;
      else
        r->AX = 0x0100;         /*jpp: from interrupt list */
      break;

      /* Allocate memory */
    case 0x48:
      if ((rc = DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0)
      {
        DosMemLargest(&(r->BX));
        goto error_exit;
      }
      else
        ++(r->AX);              /* DosMemAlloc() returns seg of MCB rather than data */
      break;

      /* Free memory */
    case 0x49:
      if ((rc = DosMemFree((r->ES) - 1)) < 0)
        goto error_exit;
      break;

      /* Set memory block size */
    case 0x4a:
      {
        UWORD maxSize;

        if ((rc = DosMemChange(r->ES, r->BX, &maxSize)) < 0)
        {
          if (rc == DE_NOMEM)
            r->BX = maxSize;

#if 0
          if (cu_psp == r->ES)
          {

            psp FAR *p;

            p = MK_FP(cu_psp, 0);
            p->ps_size = r->BX + cu_psp;
          }
#endif
          goto error_exit;
        }

        break;
      }

      /* Load and Execute Program */
    case 0x4b:
      break_flg = FALSE;

      if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), FP_DS_DX))
          != SUCCESS)
        goto error_exit;
      break;

      /* Terminate Program                                            */
    case 0x00:
      r->AX = 0x4c00;

      /* End Program                                                  */
    case 0x4c:
      if (cu_psp == RootPsp
          || ((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp)
        break;
      tsr = FALSE;
      if (ErrorMode)
      {
        ErrorMode = FALSE;
        return_mode = 2;
      }
      else if (break_flg)
      {
        break_flg = FALSE;
        return_mode = 1;
      }
      else
      {
        return_mode = 0;
      }
      return_code = r->AL;
      if (DosMemCheck() != SUCCESS)
        panic("MCB chain corrupted");
#ifdef TSC
      StartTrace();
#endif
      return_user();
      break;

      /* Get Child-program Return Value                               */
    case 0x4d:
      r->AL = return_code;
      r->AH = return_mode;
      break;

      /* Dos Find First                                               */
    case 0x4e:
      /* dta for this call is set on entry.  This     */
      /* needs to be changed for new versions.        */
      if ((rc = DosFindFirst((UCOUNT) r->CX, (BYTE FAR *) FP_DS_DX)) < 0)
        goto error_exit;
      r->AX = 0;
      break;

      /* Dos Find Next                                                */
    case 0x4f:
      /* dta for this call is set on entry.  This     */
      /* needs to be changed for new versions.        */
      if ((rc = DosFindNext()) < 0)
      {
        if (rc == DE_FILENOTFND)
          rc = DE_NFILES;
        goto error_exit;
      }
      else
        r->AX = -SUCCESS;
      break;
/*
    case 0x50:  
    case 0x51:
    see int21_syscall
*/
      /* ************UNDOCUMENTED************************************* */
      /* Get List of Lists                                            */
    case 0x52:
      {
        BYTE FAR *p;

        p = (BYTE FAR *) & DPBp;
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

    case 0x53:
      /*  DOS 2+ internal - TRANSLATE BIOS PARAMETER BLOCK TO DRIVE PARAM BLOCK */
      bpb_to_dpb((bpb FAR *)MK_FP(r->DS, r->SI), (struct dpb FAR *)MK_FP(r->ES, r->BP));
      break;
      
      /* Get verify state                                             */
    case 0x54:
      r->AL = (verify_ena ? TRUE : FALSE);
      break;

      /* ************UNDOCUMENTED************************************* */
      /* Dos Create New Psp & set p_size                              */
    case 0x55:
      new_psp((psp FAR *) MK_FP(r->DX, 0), r->SI);
      cu_psp = r->DX;
      break;

      /* Dos Rename                                                   */
    case 0x56:
      rc = DosRename((BYTE FAR *) FP_DS_DX, (BYTE FAR *) MK_FP(r->ES, r->DI));
      if (rc < SUCCESS)
        goto error_exit;
      else
        CLEAR_CARRY_FLAG();
      break;

      /* Get/Set File Date and Time                                   */
    case 0x57:
      CLEAR_CARRY_FLAG();
      switch (r->AL)
      {
        case 0x00:
          rc = DosGetFtime(
                            (COUNT) r->BX,	/* Handle               */
                            (date FAR *) & r->DX,	/* FileDate             */
                            (time FAR *) & r->CX);	/* FileTime             */
          if (rc < SUCCESS)
            goto error_exit;
          break;

        case 0x01:
          rc = DosSetFtime(
                            (COUNT) r->BX,	/* Handle               */
                            (date) r->DX,	/* FileDate             */
                            (time) r->CX);	/* FileTime             */
          if (rc < SUCCESS)
            goto error_exit;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Get/Set Allocation Strategy                                  */
    case 0x58:
      CLEAR_CARRY_FLAG();
      switch (r->AL)
      {
        case 0x00:
          r->AL = mem_access_mode;
          r->AH = 0;
          break;

        case 0x01:
        {
            switch (r->BL)
            {
            case LAST_FIT:
            case LAST_FIT_U:
            case LAST_FIT_UO:
            case BEST_FIT:
            case BEST_FIT_U:
            case BEST_FIT_UO:
            case FIRST_FIT:
            case FIRST_FIT_U:
            case FIRST_FIT_UO:
                mem_access_mode = r->BL;
                break;

            default:
                goto error_invalid;
            }
        }
            break;

        case 0x02:
            r->AL = uppermem_link;
            break;

        case 0x03:
            if (uppermem_root) {
                DosUmbLink(r->BL);
                break;
            } /* else fall through */            

        default:
          goto error_invalid;
#ifdef DEBUG
        case 0xff:
          show_chain();
          break;
#endif
      }
      break;

      /* Get Extended Error */
    case 0x59:
        r->AX = CritErrCode;
        r->ES = FP_SEG(CritErrDev);
        r->DI = FP_OFF(CritErrDev);
        r->CH = CritErrLocus;
        r->BH = CritErrClass;
        r->BL = CritErrAction;
        CLEAR_CARRY_FLAG();
      break;

      /* Create Temporary File */
    case 0x5a:
      if ((rc = DosMkTmp(FP_DS_DX, r->CX)) < 0)
        goto error_exit;
      else
      {
        r->AX = rc;
        CLEAR_CARRY_FLAG();
      }
      break;

      /* Create New File */
    case 0x5b:
      if (!IsDevice(FP_DS_DX) && (rc = DosOpen(FP_DS_DX, 0)) >= 0)
      {
        DosClose(rc);
        r->AX = 80;
        goto error_out;
      }
      else
      {
        if ((rc = DosCreat(FP_DS_DX, r->CX)) < 0)
          goto error_exit;
        else
        {
          r->AX = rc;
          CLEAR_CARRY_FLAG();
        }
      }
      break;

/* /// Added for SHARE.  - Ron Cemer */
      /* Lock/unlock file access */
    case 0x5c:
      if ((rc = DosLockUnlock
        (r->BX,
         (((unsigned long)r->CX)<<16)|(((unsigned long)r->DX)&0xffffL),
         (((unsigned long)r->SI)<<16)|(((unsigned long)r->DI)&0xffffL),
         ((r->AX & 0xff) != 0))) != 0)
          goto error_exit;
      CLEAR_CARRY_FLAG();
      break;
/* /// End of additions for SHARE.  - Ron Cemer */

      /* UNDOCUMENTED: server, share.exe and sda function             */
    case 0x5d:
      switch (r->AL)
      {
          /* Remote Server Call */
        case 0x00:
          {
            UWORD FAR *x = FP_DS_DX;
            r->AX = x[0];
            r->BX = x[1];
            r->CX = x[2];
            r->DX = x[3];
            r->SI = x[4];
            r->DI = x[5];
            r->DS = x[6];
            r->ES = x[7];
          }
          goto dispatch;

        case 0x06:
          r->DS = FP_SEG(internal_data);
          r->SI = FP_OFF(internal_data);
          r->CX = swap_always - internal_data;
          r->DX = swap_indos - internal_data;
          CLEAR_CARRY_FLAG();
          break;

        case 0x07:
        case 0x08:
        case 0x09:
	  rc = -int2f_Remote_call(REM_PRINTREDIR, 0, 0, r->DX, 0, 0, (MK_FP(0, Int21AX)));
	  if (rc != SUCCESS)
            goto error_exit;
          CLEAR_CARRY_FLAG();
          break;
        default:
          goto error_invalid;
      }
      break;

    case 0x5e:
      CLEAR_CARRY_FLAG();
      switch (r->AL)
      {
        case 0x00:
          r->CX = get_machine_name(FP_DS_DX);
          break;

        case 0x01:
          set_machine_name(FP_DS_DX, r->CX);
          break;

        default:
          rc = -int2f_Remote_call(REM_PRINTSET, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX)));
	  if (rc != SUCCESS) goto error_exit;
          r->AX=SUCCESS;
          break;
      }
      break;

    case 0x5f:
      CLEAR_CARRY_FLAG();
      switch (r->AL)
      {
        case 0x07:
          if (r->DL < lastdrive) {
            CDSp->cds_table[r->DL].cdsFlags |= 0x100;
	  }
          break;

        case 0x08:
          if (r->DL < lastdrive) {
            CDSp->cds_table[r->DL].cdsFlags &= ~0x100;
	  }
          break;

        default:
/*              
            void int_2f_111e_call(iregs FAR *r);
            int_2f_111e_call(r);          
          break;*/

          rc = -int2f_Remote_call(REM_DOREDIRECT, r->BX, r->CX, r->DX,
                                 (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX)));
	  if (rc != SUCCESS)
            goto error_exit;
          r->AX=SUCCESS;
          break;
      }
      break;

    case 0x60:                 /* TRUENAME */
      CLEAR_CARRY_FLAG();
      if ((rc = truename(MK_FP(r->DS, r->SI),
                      adjust_far(MK_FP(r->ES, r->DI)), FALSE)) != SUCCESS)
        goto error_exit;
      break;

#ifdef TSC
      /* UNDOCUMENTED: no-op                                          */
      /*                                                              */
      /* DOS-C: tsc support                                           */
    case 0x61:
#ifdef DEBUG
      switch (r->AL)
      {
        case 0x01:
          bTraceNext = TRUE;
          break;

        case 0x02:
          bDumpRegs = FALSE;
          break;
      }
#endif
      r->AL = 0x00;
      break;
#endif

      /* UNDOCUMENTED: return current psp                             
    case 0x62: is in int21_syscall
      r->BX = cu_psp;
      break;
      */
      
      /* UNDOCUMENTED: Double byte and korean tables                  */
    case 0x63:
      {
#define DBLBYTE
#ifdef DBLBYTE
        static char dbcsTable[2] =
        {
          0, 0
        };
        void FAR *dp = &dbcsTable;

        r->DS = FP_SEG(dp);
        r->SI = FP_OFF(dp);
        r->AL = 0;
#else
        /* not really supported, but will pass.                 */
        r->AL = 0x00;           /*jpp: according to interrupt list */	
				/*Bart: fails for PQDI: use the above again */
#endif
        break;
      }
/*
    case 0x64:
      see above (invalid)
*/      

      /* Extended country info                                        */
    case 0x65:
    	switch(r->AL) {
    	case 0x20:				/* upcase single character */
            r->DL = DosUpChar(r->DL);
            break;
        case 0x21:				/* upcase memory area */
            DosUpMem(FP_DS_DX, r->CX);
            break;
        case 0x22:				/* upcase ASCIZ */
            DosUpString(FP_DS_DX);
            break;
    	case 0xA0:				/* upcase single character of filenames */
            r->DL = DosUpFChar(r->DL);
            break;
        case 0xA1:				/* upcase memory area of filenames */
            DosUpFMem(FP_DS_DX, r->CX);
            break;
        case 0xA2:				/* upcase ASCIZ of filenames */
            DosUpFString(FP_DS_DX);
            break;
        case 0x23:				/* check Yes/No response */
            r->AX = DosYesNo(r->DL);
            break;
      	default:
            if ((rc = DosGetData(
                         r->AL, r->BX, r->DX, r->CX,
                         MK_FP(r->ES, r->DI))) < 0) {
#ifdef NLS_DEBUG
   printf("DosGetData() := %d\n", rc);
#endif
               goto error_exit;
            }
#ifdef NLS_DEBUG
   printf("DosGetData() returned successfully\n", rc);
#endif

            break;
         }
		CLEAR_CARRY_FLAG();
      break;
      

      /* Code Page functions */
    case 0x66: {
    	int rc;
      switch (r->AL)
      {
        case 1:
          rc = DosGetCodepage(&r->BX, &r->DX);
			break;
        case 2:
          rc = DosSetCodepage(r->BX, r->DX);
          break;

        default:
          goto error_invalid;
      }
      if(rc != SUCCESS)
      	goto error_exit;
      CLEAR_CARRY_FLAG();
      break;
     }

      /* Set Max file handle count */
    case 0x67:
      if ((rc = SetJFTSize(r->BX)) != SUCCESS)
        goto error_exit;
      else
        CLEAR_CARRY_FLAG();
      break;

      /* Flush file buffer -- COMMIT FILE -- dummy function right now.  */
    case 0x68:
    case 0x6a:
      CLEAR_CARRY_FLAG();
      break;

      /* Get/Set Serial Number */
    case 0x69:
      rc = ( r->BL == 0 ? default_drive : r->BL - 1);
      if (rc < lastdrive)
      {
        UWORD saveCX = r->CX;
        if (CDSp->cds_table[rc].cdsFlags & CDSNETWDRV) {
          goto error_invalid;
        }
        switch(r->AL){
            case 0x00:
            r->AL = 0x0d;
            r->CX = 0x0866;
            rc = DosDevIOctl(r);
            break;

            case 0x01:
            r->AL = 0x0d;
            r->CX = 0x0846;
            rc = DosDevIOctl(r);
            break;
        }
        r->CX = saveCX;
        if (rc != SUCCESS)
          goto error_exit;
        CLEAR_CARRY_FLAG();
        break;
      }
      else
        r->AL = 0xFF;
      break;
/*
    case 0x6a: see case 0x68
    case 0x6b: dummy func: return AL=0
*/    
    /* Extended Open-Creat, not fully functional. (bits 4,5,6 of BH) */
    case 0x6c:
      {
        COUNT x = 0;
      
        if (r->AL != 0 || r->DH != 0 ||
              (r->DL&0x0f) > 0x2 || (r->DL&0xf0) > 0x10)
            goto error_invalid;
        CLEAR_CARRY_FLAG();
        if ((rc = DosOpen(MK_FP(r->DS, r->SI),
                          (r->DL&0x0f) == 0x1 ? r->BL : 0)) < 0)
        {
            if (r->DL < 0x10)
                goto error_exit;
            /* else try to create below */
        }
        else switch (r->DL & 0x0f)
        {
          case 0x0:
            /* fail if file exists */
            DosClose(rc);
            rc = DE_FILEEXISTS;
            goto error_exit;
          case 0x1:
            /* file exists and opened: OK */
            r->CX = 0x01;
            goto break_out;
          case 0x2:  
            /* file exists: replace/open */
            DosClose(rc);
            x = 1;
            break;
        }
        /* cases 0x00, 0x01 are finished now */
        if ((rc = DosCreat(MK_FP(r->DS, r->SI), r->CX)) < 0)
            goto error_exit;
            
        r->CX = x+2;
break_out:        
        r->AX = rc;
        break;
      }


    /* case 0x6d and above not implemented : see default; return AL=0 */
        
  }

#ifdef DEBUG
  if (bDumpRegs)
  {
    fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs,
           sizeof(iregs));
    dump_regs = TRUE;
    dump();
  }
#endif
}
示例#6
0
/* See header file for description. */
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
portSTACK_TYPE DS_Reg = 0;

	/* Place a few bytes of known values on the bottom of the stack.
	This is just useful for debugging. */

	*pxTopOfStack = 0x1111;
	pxTopOfStack--;
	*pxTopOfStack = 0x2222;
	pxTopOfStack--;
	*pxTopOfStack = 0x3333;
	pxTopOfStack--;
	*pxTopOfStack = 0x4444;
	pxTopOfStack--;
	*pxTopOfStack = 0x5555;
	pxTopOfStack--;


	/*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */

	/* We are going to start the scheduler using a return from interrupt
	instruction to load the program counter, so first there would be the
	function call with parameters preamble. */
	
	*pxTopOfStack = FP_SEG( pvParameters );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pvParameters );
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pxCode );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxCode );
	pxTopOfStack--;

	/* Next the status register and interrupt return address. */
	*pxTopOfStack = portINITIAL_SW; 
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pxCode );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxCode );
	pxTopOfStack--;

	/* The remaining registers would be pushed on the stack by our context
	switch function.  These are loaded with values simply to make debugging
	easier. */
	*pxTopOfStack = ( portSTACK_TYPE ) 0xAAAA;	/* AX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;	/* BX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;	/* CX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;	/* DX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;	/* ES */
	pxTopOfStack--;

	/* We need the true data segment. */
	__asm{	MOV DS_Reg, DS };

	*pxTopOfStack = DS_Reg;						/* DS */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0x0123;	/* SI */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;	/* DI */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;	/* BP */

	/*lint +e950 +e611 +e923 */

	return pxTopOfStack;
}
示例#7
0
void main ( )
{

    int *base, *tope, *avail, *max ;
    int n,inf,crear_pila;
    unsigned int sw;
    char opcion;

    // creacion del menu de pila lls

    sw=0;
    do {
        clrscr();
        gotoxy (35,2);
        printf ("M  E  N  U ");
        gotoxy (32,3);
        printf (" MANEJO DE PILAS");
        gotoxy (15,6);
        printf ("1_CREAR PILA");
        gotoxy (15,8);
        printf ("2_INCLUIR NODO EN UNA PILA(PUSH)");
        gotoxy (15,10);
        printf ("3_CANCELAR NODO EN UNA PILA(POP)");
        gotoxy (15,12);
        printf ("4_MOSTRAR PILA");
        gotoxy (15,14);
        printf ("5_ SALIR\n\n");
        //  gotoxy (15,20);
        printf ("DIGITE OPCION : ");
        do {
            opcion=getchar ( );
        } while ( opcion<'0' && opcion>'5');
        switch(opcion) {

        case '1':
            if (sw==0) {
                sw=1;
                clrscr ( );
                // definir el espacio disponible

                printf("DIGITE EL MAXIMO NUMERO DE NODOS DE LA LISTA");
                do {
                    scanf ("%d",&n);
                } while (n<=0);
                crear_pila (&base,&tope,n);
                max=Maximo (base,n);
                printf ("  BASE=%04X:%04X\n",FP_SEG(base),FP_OFF(base));
                printf ("  TOPE=%04X:%04X\n",FP_SEG(tope),FP_OFF(tope));
                printf ("\n MAXIMO=%04X:%04X\n",FP_SEG(max),FP_OFF(max));
                printf ("\n  DIGITE 0 Y <ENTER> CONTONUA");
                do {
                    opcion=getchar ( );
                } while (opcion !='0');
            }
            else {
                clrscr ( );
                printf ("PILA YA CREADA.. DIGITE O Y <ENTER> CONTINUA");
                do {
                    opcion=getchar();
                } while (opcion !='0');
            }
            break;


        case '2':
            if (sw==1) {
                clrscr();
                printf ("\n DIGITE INFORMACION DEL NODO A INCLUIR");
                scanf ("%d",&inf);
                Push(&tope,max,inf);
            }
            else {
                clrscr();
                printf ("PILA NO CREADA.. DIGITE 0 Y <ENTER> CONTINUA");
                do {
                    opcion=getchar ( );
                } while (opcion !='0');
            }
            break;


        case '3':
            if (sw==1) {
                clrscr();
                Pop (&tope,base,&inf);
                printf ("\n NODO CANCELADO=%d",inf);
                printf ("\n \n DIGITE 0 Y <ENTER> CONTINUA");
                do {
                    opcion=getchar ( );
                } while (opcion!='0');

            }
            else {
                clrscr();
                printf ("PILA NO CREADA.. DIGITE 0 Y <ENTER> CONTINUA");
                do {
                    opcion=getchar ( );
                } while (opcion!='0');
            }
            break;

        case '4':
            if (sw==1) {
                clrscr ();
                escribir_Pila(base,&tope,max,n);
                printf ("\n\n DIGITE O Y <ENTER> CONTINUA");
                do {
                    opcion=getchar ( );
                } while (opcion !='0');
            }
            else {
                clrscr();
                printf ("PILA NO CREADA.. DIGITE 0 Y <ENTER> CONTINUA");
                do {
                    opcion=getchar ( );
                } while (opcion !='0');
            }
            break;

        default :
            break;

        }
    } while (opcion != '5');
    clrscr();
    gotoxy(35,12);
    printf ("FIN PROCESO");
    delay(700);
}
示例#8
0
/* See header file for description. */
StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
{
StackType_t DS_Reg = 0;

	/* Place a few bytes of known values on the bottom of the stack.
	This is just useful for debugging. */

	*pxTopOfStack = 0x1111;
	pxTopOfStack--;
	*pxTopOfStack = 0x2222;
	pxTopOfStack--;
	*pxTopOfStack = 0x3333;
	pxTopOfStack--;

	/* We are going to start the scheduler using a return from interrupt
	instruction to load the program counter, so first there would be the
	function call with parameters preamble. */
	
	*pxTopOfStack = FP_SEG( pvParameters );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pvParameters );
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pxCode );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxCode );
	pxTopOfStack--;

	/* Next the status register and interrupt return address. */
	*pxTopOfStack = portINITIAL_SW;
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pxCode );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxCode );
	pxTopOfStack--;

	/* The remaining registers would be pushed on the stack by our context
	switch function.  These are loaded with values simply to make debugging
	easier. */
	*pxTopOfStack = ( StackType_t ) 0xAAAA;	/* AX */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xBBBB;	/* BX */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xCCCC;	/* CX */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xDDDD;	/* DX */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xEEEE;	/* ES */
	pxTopOfStack--;

	/* We need the true data segment. */
	__asm{	MOV DS_Reg, DS };

	*pxTopOfStack = DS_Reg;						/* DS */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0x0123;	/* SI */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xDDDD;	/* DI */
	pxTopOfStack--;
	*pxTopOfStack = ( StackType_t ) 0xBBBB;	/* BP */

	return pxTopOfStack;
}
示例#9
0
/* Non-DOS formats count as formats as well! (Eric) */
static char Check_For_Format(void)
{
	regs.h.ah = 0x0d;	/* this is in Check_For_Format */
	__dpmi_int(0x21, &regs);; /* flush buffers, reset disk system */
	#ifdef __FORMAT_DEBUG__
	puts("[DEBUG]	Test-reading boot sector.");
	#endif

	/* as int 21.32 does not work for FAT32, we ALWAYS read the boot sector */
	param.fat_type = FAT16; /* Check_For_Format: guess "not FAT32" first */
	regs.x.ax = Drive_IO(READ, 0, -1);

	if ((regs.x.ax != 0) && (param.drive_type != FLOPPY)) {
		#ifdef __FORMAT_DEBUG__
		printf(" maybe FAT32?\n");
		#endif
		param.fat_type = FAT32; /* Check_ForFormat: try FAT32 Drive_IO next */
		regs.x.ax = Drive_IO(READ, 0, -1);
		if (regs.x.ax != 0)
			param.fat_type = FAT16; /* Check_For_Format: revert to FAT1x Drive_IO */
	}

	if (regs.x.ax != 0) { /* could not even read boot sector */
		#ifdef __FORMAT_DEBUG__
		printf("[DEBUG]  Error code: 0x%x\n", regs.x.ax);
		#endif
		/* bits: 80 timeout 40 seek 20 controller fail 10 CRC error        */
		/* 8 DMA error 4 sector not found 2 bad address mark 1 bad command */
		/*  (int 26 would have special extra code 3, write protect error)  */
		printf("  Boot sector unreadable, disk not yet formatted\n");
		return FALSE;
	}

	if (param.fat_type == FAT32) {
		/* if (debug_prog==TRUE) printf("[DEBUG]  Checking xBPB (FAT32)\n"); */
		regs.x.ax = 0x7302; /* this is in Check_For_Format */ /* read xBPB */
		regs.h.dl = param.drive_number + 1; /* 0 default 1 A: 2 B: ... */
		regs.x.es = FP_SEG(sector_buffer);
		regs.x.di = FP_OFF(sector_buffer);
		regs.x.cx = 0x3f; /* amount of to-be-used buffer size */
		regs.x.si = 0; /* (can be a magic value to get more data) */
		regs.x.flags &= ~CARRY_FLAG;
		__dpmi_int(0x21, &regs);; /* read xBPB for that drive */
		if (!(regs.x.flags&CARRY_FLAG))
			regs.x.ax = 0; /* call worked */
	} else {
		regs.h.ah = 0x32; /* this is in Check_For_Format */ /* read BPB/DPB */
		regs.h.dl = param.drive_number + 1; /* 0 default 1 A: 2 B: ... */
		__dpmi_int(0x21, &regs);; /* re-read info for that drive */
		/* this can cause a critical error if boot sector not readable! */
		regs.h.ah = 0;
	}

	if (regs.x.ax == 0) {
		/* could analyze returned DPB  - pointer is DS:BX if FAT16/FAT12 */
		/* could analyze returned xBPB - it is in sector_buffer if FAT32 */
		#ifdef __FORMAT_DEBUG__
		printf("[DEBUG]  Existing format detected.\n");
		#endif
		return TRUE;
	} else {
		printf("Invalid %sBPB (code 0x%x). NOT yet formatted. Or network / CD-ROM?\n",
			((param.fat_type == FAT32) ? "x" : ""), regs.x.ax);
		return FALSE; /* this is a network drive or something */
	}
}
示例#10
0
文件: dgraphic.cpp 项目: dvorka/naaga
void DGraphics::PutFrom0x0y( unsigned char far *VirtualScreen, unsigned int Size )
{
 movedata( FP_SEG(VirtualScreen), FP_OFF(VirtualScreen),
	   0xA000,  		  0x0000, 		Size);
}
示例#11
0
/*
/////////////////////////////////////////////////////////////////////////////
//  MAIN ROUTINE
/////////////////////////////////////////////////////////////////////////////
*/
int main(int argc, char *argv[])
{
	int ch;
	int index;
	int n;
	int found_format_sectors_per_track = 0;
	int found_format_heads = 0;

#define MIRROR 1
#define UNFORMAT 2

#define WHAT_FORMAT 1	/* new 0.91p, for custom "... completed" messages */
#define WHAT_QUICK 2
#define WHAT_SAFE 3
#define WHAT_UN 4
#define WHAT_MIRROR 5
	int what_completed = 0; /* new 0.91p */

	int special = 0;	/* mirror / unformat mode indicator */
	int align = 1;	/* new 0.91m */

	int drive_letter_found = FALSE;

	Initialization();

	param.n = FALSE;
	param.t = FALSE;
	param.v = FALSE;
	param.q = FALSE;
	param.u = FALSE;
	param.b = FALSE;
	param.s = FALSE;
	param.f = FALSE;
	param.one = FALSE;
	param.four = FALSE;
	param.eight = FALSE;

	/* if FORMAT is typed without any options */

	if (argc == 1)
	{
		Display_Help_Screen(0); /* SHORT version */
		return 0;
	}

	/* (jh) check command line */

	while (  (index = getopt (argc, argv, "V:v:Z:z:QqUuBbSsYyAa148F:f:T:t:N:n")) != EOF)
	{
		switch(index)
		{
		case 'V':
		case 'v':
			param.v = TRUE;
			/* avoid overflow of param.volume_label (12 chars) */
			/* need to skip over first character (':') */

			strncpy (param.volume_label, optarg+1, 11);
			param.volume_label[11] = '\0';

			for (n = 0; param.volume_label[n] != '\0'; n++)
			{
				ch = param.volume_label[n];
				param.volume_label[n] = toupper (ch);
			}
			break;

		case 'Z': /* our getopt has no "long" support, so we use -Z:keyword */
		case 'z': /* 0.91l - extra (long) options */
			if (!stricmp(optarg+1,"mirror")) /* +1 to skip initial ":" */
			{
				special = MIRROR;      /* take a new mirror data snapshot */
				break;
			}
			if (!stricmp(optarg+1,"unformat"))
			{
				special = UNFORMAT;	   /* revert to mirrored state, dangerous! */
				break;
			}
			if (!stricmp(optarg+1,"seriously"))
			{
				param.force_yes = TRUE + TRUE; /* User MEANS to format harddisk */
				break;
			}
			if (!stricmp(optarg+1,"longhelp"))
			{
				Display_Help_Screen(1); /* LONG version */
				Exit(0,1);
			}
			printf("Invalid -Z:mode - valid: MIRROR, UNFORMAT, SERIOUSLY\n");
			Exit(0,2);
			break;

		case 'Q': /* quick - flush metadata only */
		case 'q':
			param.q = TRUE;
			break;
		case 'U': /* unconditional - full format */
		case 'u':
			param.u = TRUE;
			break;
		case 'B': /* reserve space for system, deprecated */
		case 'b':
			param.b = TRUE;
			break;
		case 'S': /* run SYS command */
		case 's':
			param.s = TRUE;
			break;
		case 'Y': /* assume yes for confirmations - "undocumented" */
		case 'y':
			if (param.force_yes == FALSE) param.force_yes = TRUE;
			break;
		case 'A': /* 0.91m - align mode, force FAT size to 2k*n and */
		case 'a': /* so on to force data clusters to start at 4k*n  */
			align = 8;
			break;
		case '1': /* one side only */
			param.one = TRUE;
			break;
		case '4': /* 360k disk in 1.2M drive */
			param.four = TRUE;
			break;
		case '8': /* 8 sectors per track */
			param.eight = TRUE;
			break;

		case 'F':           /* -F:size */
		case 'f':           /* -F:size */
			param.f = TRUE;
			n = atoi (optarg + 1);

			if ((n == 160) || (n == 180) || (n == 320) || (n == 360) ||
			        (n == 720) || (n == 1200) || (n == 1440) || (n == 2880) ||
			        (n == 400) || (n == 800) || (n == 1680) || (n == 3360) ||
			        (n == 1494) || (n == 1743) || (n == 3486))
			{
				param.size = n;
			}
			else
			{
				printf("Ok: 160, 180, 320, 360, 720, 1200, 1440, 2880.\n");
				printf("???: 400, 800, 1680, 3360,   1494, 1743, 3486.\n");
				IllegalArg("-F",optarg);
			}
			break;

		case 'T': /* tracks (cylinders) */
		case 't': /* tracks (cylinders) */
			param.t = TRUE;
			n = atoi (optarg + 1);

			if ((n == 40) || (n == 80) || (n == 83))
			{
				param.cylinders = n;
			}
			else
			{
				printf("Ok: 40, 80. ???: 83.\n");
				IllegalArg("-T",optarg);
			}
			break;

		case 'N': /* sectors per track */
		case 'n': /* sectors per track */
			param.n = TRUE;
			n = atoi (optarg + 1);

			if ((n == 8) || (n == 9) || (n == 15) || (n == 18) || (n == 36) ||
			        (n == 10) || (n == 21) || (n == 42))
			{
				param.sectors = n;
			}
			else
			{
				printf("Ok: 8, 9, 15, 18, 36. ???: 10, 21, 42.\n");
				IllegalArg("-N",optarg);
			}
			break;

		case '~':
			param.drive_letter[0] = toupper (optarg[0]);
			param.drive_number = param.drive_letter[0] - 'A';
			param.drive_letter[1] = ':';
			drive_letter_found = TRUE;
			break;

		case '?':
			Display_Help_Screen(0); /* SHORT version */
			Exit(0,1);

		default:
			printf("Unrecognized option: -%c\n", index);
			Display_Help_Screen(0); /* SHORT version */
			Exit(4,2);

		}       /* switch (index) */
	}         /* for all args (getopt) */


	if ( (argc > optind) && (isalpha (argv[optind][0])) &&
	        (argv[optind][1] == ':') && (argv[optind][2] == '\0') &&
	        (drive_letter_found == FALSE) )
	{
		param.drive_letter[0] = toupper (argv[optind][0]);
		param.drive_number = param.drive_letter[0] - 'A';
		param.drive_letter[1] = ':';
	}
	else
		if (drive_letter_found == FALSE)
		{
			printf("Required parameter missing - Drive Letter\n");
			Exit(0,2);
		}

	/* (jh) done with parsing command line */



	/* if FORMAT is typed with a drive letter */

	#ifdef __FORMAT_DEBUG__
	printf("\n[DEBUG]	This is FORMAT " VERSION ", selected drive -> %c:\n",
		param.drive_letter[0]);
	printf("[DEBUG]	Using 1 sector buffer at %4.4x:%4.4x and 1 track buffer at %4.4x:%4.4x\n",
		FP_SEG(sector_buffer), FP_OFF(sector_buffer),
		FP_SEG(huge_sector_buffer), FP_OFF(huge_sector_buffer) );
	/* moved this message to this place in 0.91s */
	#endif

	/* Set the type of disk */
	if (param.drive_number>1)
		param.drive_type=HARD;
	else
		param.drive_type=FLOPPY;


	/* *** TODO: complain about ANY size determination if type HARD *** */


	/* Ensure that valid switch combinations were entered */
	if ( (param.b==TRUE) && (param.s==TRUE) )
		Display_Invalid_Combination();
	/* cannot reserve space for SYS and actually SYS at the same time */
	if ( (param.v==TRUE) && (param.eight==TRUE) )
		Display_Invalid_Combination();
	/* no label allowed if 160k / 320k */

	if ( ( (param.one==TRUE) || (param.four==TRUE) /* 360k in 1.2M drive */ ) &&
	        ( (param.f==TRUE) || (param.t==TRUE) || (param.n==TRUE) ) )
		Display_Invalid_Combination();
	/* cannot combine size/track/sector override with 1-sided / 360k */

	if ( ( (param.t==TRUE) && (param.n!=TRUE) ) ||
	        ( (param.n==TRUE) && (param.t!=TRUE) ) )
	{
		puts("You can only give -T _and_ -N or _neither_ of them.");
		Display_Invalid_Combination();
		/* you must give BOTH track and sector arguments if giving either */
	}

	if ( (param.f==TRUE) && ( (param.t==TRUE) || (param.n==TRUE) ) )
		Display_Invalid_Combination();
	/* you can only give EITHER size OR track/sector arguments */

	/* we do allow /8 to reach 160k (with /1) and 320k (with /4) */
	/* it is more the other way round: we do not want 8 sector/track > 320k! */

	/* ... */

	if (param.one==TRUE) /* one-sided: 160k and 180k only */
	{
		param.sides = 1;
		param.cylinders = 40;
		/* *** this is actually handled in Set_Floppy_Media_Type mostly *** */
	}

	if (param.four==TRUE) /* 360k in 1200k drive */
	{
		param.cylinders = 40;
		param.sectors = 9;
	}

	if (param.eight==TRUE) /* DOS 1.0 formats: 160k and 320k only */
	{
		param.sectors = 8;
	}

	Lock_Unlock_Drive(1); /* lock drive (needed in Win9x / DOS 7.x) */
	/* FIRST lock, file system still enabled. */

next_disk:

	/* User interaction. */
	if (param.drive_type==FLOPPY && param.force_yes==FALSE)
		Ask_User_To_Insert_Disk();

	if (!special)
	{
		if (param.drive_type==HARD && (param.force_yes!=(TRUE+TRUE)) )
			Confirm_Hard_Drive_Formatting(1); /* 1 means "format" */
		/* disabled harddisk "/Y" forced confirmation in 0.91b unless ZAPME -ea */
		/* replaced by "/Z:seriously" in 0.91l -ea */
	} else {
		if ((param.force_yes == FALSE) && (special == UNFORMAT))
			Confirm_Hard_Drive_Formatting(0); /* 0 means "unformat" - 0.91l */
		/* no confirmation requested for MIRROR ! */
	}

	/* "optimized" a lot in 0.91h, hopefully not too much... -ea */
	if ((!special) && (param.u==TRUE) && (param.q==FALSE)) /* full format / wipe? */
	{
		param.existing_format = FALSE; /* do not even check if /U non-/Q mode */
	} else {
		/* /Q /U clears metadata but does no format / wipe */
		/* /Q -- clears metadata after backing it up */
		/* -- -- works like /Q */
		/* CONCLUSION: We do not really have to worry about current  */
		/* for harddisks in /Q /U mode (uses DOS kernel default BPB) */

		if ( (param.drive_type!=FLOPPY) && (param.u==TRUE) )
		{
			/* no check for harddisk /U mode nor for /U /Q mode there. */
			param.existing_format = FALSE;
		} else { /* it is a floppy --- or no /U flag given */
			#ifdef __FORMAT_DEBUG__
			if (special)
			{
				puts("[DEBUG]	Checking for existing format");
			}
			else
			{
				if (param.drive_type==FLOPPY)
					puts("[DEBUG]	Checking whether we need low-level floppy format.");
				else
					puts("[DEBUG]	Checking whether UNFORMAT data can be saved.");
			}
			#endif

			/* Check to see if the media is currently formatted. */
			/* Needed for non-/U modes and for floppy disks, but in */
			/* /U non-/Q mode we already assume "not formatted" anyway. */
			param.existing_format = Check_For_Format(); /* trashes fat_type value! */
			/* no problem, done before media type / harddisk parameter setup */

		} /* check for existing format */
	} /* not FORMAT /U mode */


	Lock_Unlock_Drive(2);	/* lock drive (needed in Win9x / DOS 7.x) */
	/* SECOND lock, going lowlevel... - 0.91q */


	/* Determine and set media parameters */
	if (param.drive_type==FLOPPY)
	{ /* <FLOPPY> */
		if (param.existing_format==TRUE)
		{
			dosmemget(sector_buffer+0x18, 1, &found_format_sectors_per_track);
			dosmemget(sector_buffer+0x1a, 1, &found_format_heads);
		}
		Set_Floppy_Media_Type(); /* configure hardware, set up BPB, fat_type FAT12 */

#if DETECT_FLOPPY_TWICE
		if ((param.existing_format == FALSE) && (param.u==FALSE))
		{
			/* try finding existing format again - after setting media type */
			#ifdef __FORMAT_DEBUG__
				puts("[DEBUG]	Searching for existing format again...");
			#endif

			Lock_Unlock_Drive(0);	/* re-enable filesystem access - 0.91q */

			param.existing_format = Check_For_Format(); /* trashes fat_type! No prob. */
			/* ... because it is done just before Set_Floppy_Media_Type */

			Lock_Unlock_Drive(2);	/* re-disable filesystem access - 0.91q */

			Set_Floppy_Media_Type(); /* configure hardware AGAIN, set up BPB, fat_type FAT12 */
			/* set media type again! - 0.91i */

			if (param.existing_format==TRUE)
			{
				/* depends on Check_For_Format to fill sector_buffer... */
				dosmemget(sector_buffer+0x18, 1, &found_format_sectors_per_track);
				dosmemget(sector_buffer+0x1a, 1, &found_format_heads);
			}
		} /* not /U and no existing format found */
#endif /* DETECT_FLOPPY_TWICE */

		/* if already formatted floppy, check whether geometry will change */
		if (param.existing_format == TRUE)
		{
			if ( ( parameter_block.bpb.sectors_per_cylinder != found_format_sectors_per_track ) ||
					( found_format_heads != parameter_block.bpb.number_of_heads ) )
			{
				puts("Will change size by formatting - forcing full format");
				printf("Old: %d sectors per track, %d heads. New: %d sect. %d heads\n",
					found_format_sectors_per_track, found_format_heads,
					parameter_block.bpb.sectors_per_cylinder,
					parameter_block.bpb.number_of_heads);
				param.existing_format = FALSE;
			}
		} /* existing format */
		/* if no existing format, we force full format anyway */
	/* </FLOPPY> */
	} else { /* if harddisk: */
	/* <HARDDISK> */
		/* 0.91m: the only place where "align" is used is here, in BPB setup!!! */
		Set_Hard_Drive_Media_Parameters(align); /* get default BPB etc., find FATxx fat_type */
		Enable_Disk_Access();
	/* </HARDDISK> */
	}
	/* *** Maybe we should have done drive setup earlier, for Check_...? *** */

	if (param.existing_format == FALSE) /* details changed in 0.91h */
	{
		if ( (param.drive_type==FLOPPY) &&
		        ( (param.u!=TRUE) || (param.q!=FALSE) ) )
			puts("Cannot find existing format - forcing full format.");
		if ( (param.drive_type!=FLOPPY) && (param.u==FALSE) )
			puts("Cannot find existing format - not saving UNFORMAT data.");
	}

	switch (special) /* 0.91l - special modes MIRROR and UNFORMAT */
	{
	case 0:		/* do nothing special */
		break;
	case MIRROR:	/* only update mirror data */
		puts("Writing a copy of the system sectors to the end of the drive:");
		puts("Boot sector, one FAT, root directory. Useful for UNFORMAT.");
		Save_File_System(0);	/* includes filesystem usage stats display */
		/* 0.91r: 0 is "abort if we would damage data" -ea */
		what_completed = WHAT_MIRROR; /* new 0.91p */
		goto format_complete;
		/* break; */
	case UNFORMAT:	/* only write back FAT/root/boot from mirror */
		puts("Overwriting boot sector, FATs and root directory with");
		puts("MIRROR/UNFORMAT data which you have saved earlier.");
		Restore_File_System(); /* restore is an euphemism for what it does! */
		what_completed = WHAT_UN; /* new 0.91p */
		goto format_complete;
		/* break; */
	default:
		puts("/Z:what???"); /* should never be reached */
	} /* switch special */


	/* ask for label if none given yet - 0.91r */
	if ((!param.v) && (!param.force_yes))
	{
		param.v = (Ask_Label(param.volume_label) != 0);
		/* printf("\n[%s]%s\n", param.volume_label, (param.v) ? "" : " (none)"); */
	} /* ask for label */


	/* Format Drive */
	if ( ( (param.existing_format==FALSE) && (param.drive_type==FLOPPY) ) ||
	        ( (param.u==TRUE) && (param.q==FALSE) ) )
	{
		/* /U is Unconditional Format. */
		/* If floppy is unformatted or geometry changes, we must use this. */
		puts(" Full Formatting (wiping all data)");
		Unconditional_Format();
		Create_File_System();
		what_completed = WHAT_FORMAT; /* new 0.91p */
		goto format_complete;
	}

	if ( ( (param.existing_format==FALSE) && (param.drive_type!=FLOPPY) ) ||
	        ( (param.u==TRUE) && (param.q==TRUE) ) ) /* changed in 0.91h */
	{
		/* /Q /U is Quick Unconditional format */
		/* Even unformatted harddisks do not need full "/U" format    */
		/* (harddisk /U format means "wipe all data, do surface scan) */
		/* (harddisk LOWLEVEL format is never done by this program!)  */
		puts(" QuickFormatting (only flushing metadata)");
		puts(" Warning: Resets bad cluster marks if any.");
		Create_File_System();
		what_completed = WHAT_QUICK; /* new 0.91p */
		goto format_complete;
	}

	if ( (param.u==FALSE) /* && (param.q==TRUE) */ )
	{

		/* this is the default, so if no /U given, it is irrelevant   */
		/* whether /Q is given or not... Should trigger FULL format   */
		/* if existing filesystem has other size or disk needs format */

		/* /Q is Safe Quick Format (checking for existing bad cluster list) */
		/* -- is Safe Quick Format (the same :-)) */
		puts(" Safe QuickFormatting (trying to save UnFormat data)");
		Save_File_System(1); /* side effect: checks for existing bad clust list */
		/* 0.91r: 1 is "allow trashing of data clusters" -ea */
		/* (unformat data is allowed to overwrite files)     */
		Create_File_System();
		what_completed = WHAT_SAFE; /* new 0.91p */
		goto format_complete;
	}

format_complete:

	if ((bad_sector_map[0]>0) && (!special))
		Record_Bad_Clusters(); /* write list of bad clusters */
	/* may include copied list from previous filesystem - not in special modes! */

	switch (what_completed) /* new 0.91p - custom message */
	{
	case WHAT_FORMAT: printf("\nFormat"); break;
	case WHAT_QUICK: printf("\nQuickFormat"); break;
	case WHAT_SAFE: printf("\nSafe QuickFormat"); break;
	case WHAT_MIRROR: printf("\nMirror"); break;
	case WHAT_UN: printf("\nUnFormat"); break;
	} /* switch */
	puts(" complete.");

	Lock_Unlock_Drive(0);	/* unlock drive again (in Win9x / DOS 7.x) */
	/* release SECOND lock: enable filesystem  */
	Force_Drive_Recheck();		/* just in case... - 0.91q */
	Lock_Unlock_Drive(0);	/* unlock drive again (in Win9x / DOS 7.x) */
	/* release FIRST lock: allow full access!  */

	if ((param.s==TRUE) && (!special))
	{
		Write_System_Files();		/* call SYS */
		Force_Drive_Recheck();		/* just in case... - 0.91q */
	}

	if (!special) Display_Drive_Statistics();

	if ((param.drive_type==FLOPPY) && (param.force_yes==FALSE))
	{
		/* printf("\nFormat another floppy (y/n)?\n"); */
		if (!special) /* or use what_completed switch / case with WHAT_...? */
			write(isatty(1) ? 1 : 2, "\nFormat", 7);
		else
			write(isatty(1) ? 1 : 2, "\nProcess", 8);
		write(isatty(1) ? 1 : 2, " another floppy (y/n)?\n", 23);
		/* write to STDERR to keep message visible even if STDOUT redirected */

		/* Get keypress */
		regs.h.al = toupper(getch());

		if (regs.h.al == 'Y')
		{
			int bads;
			printf("\n%s next floppy...\n",
			       special ? "Processing" : "Formatting");

			drive_statistics.bad_sectors = 0;
			bad_sector_map_pointer = 0;
			for (bads=0; bads < MAX_BAD_SECTORS; bads++)
			{
				bad_sector_map[bads] = 0;
			}

			Lock_Unlock_Drive(1);	/* lock drive (needed in Win9x / DOS 7.x) */
			/* FIRST lock, file system still enabled. */
			/* (second level will be entered again when we really need it...) */

			param.v = FALSE;	/* force asking for new label for next disk */

			goto next_disk; /* *** LOOP AROUND FOR MULTIPLE FLOPPY DISKS *** */
		}
	} /* another floppy question, possibly jumping back */

	return 0;	/* not using Exit() here: no dual errorlevel, no unlock */

}
示例#12
0
int __F_NAME(__cenvarg,__wcenvarg)(
/*
 *  Build environment and command line for new process.  Length of environment
 *  (in bytes) is returned on success.  -1 is returned on failure.
 */
    const CHAR_TYPE     *const argv[],  /* i: arguments for new process */
    const CHAR_TYPE     *const envp[],  /* i: env strings for new process */
    CHAR_TYPE           **envptr,       /* o: allocated memory for env */
    CHAR_TYPE           **envstrings,   /* o: pointer to environment strings */
    unsigned            *envseg,        /* o: start of env (on para boundary) */
    size_t              *cmdline_len,   /* o: size required to hold cmd line */
    int                 exec )          /* i: TRUE if for exec */
{
    unsigned            length;
    unsigned            oamblksiz;
    CHAR_TYPE           *p;
    CHAR_TYPE _WCNEAR   *np;
    unsigned            len;
    int                 i;

    if( envp == NULL ){
#ifdef __WIDECHAR__
        if( _RWD_wenviron == NULL )
            __create_wide_environment();
#endif
        envp = (const CHAR_TYPE * const *)__F_NAME(_RWD_environ,_RWD_wenviron);
    }
    length = 0;
    if( envp != NULL ){
        for( i = 0; envp[i] != NULL; i++ ) {
            length += __F_NAME(strlen,wcslen)( envp[i] ) + 1;
        }
    }
    ++length; /* trailing \0 for env */
    if( exec ){
        /* store argv[0] at 2 bytes past end of env */
        length += 2 + __F_NAME(strlen,wcslen)( argv[0] ) + 1;
    }
    length += 15;       /* so we can start on a paragraph boundary */

    oamblksiz = _RWD_amblksiz;
    _RWD_amblksiz = 16; /* force allocation in 16 byte increments */
    p = np = lib_nmalloc( length*sizeof(CHAR_TYPE) );
    if( np == NULL ){   /* 03-aug-88 */
        p = lib_malloc( length*sizeof(CHAR_TYPE) );
        if( p == NULL ){
            __set_errno( ENOMEM );
            __set_doserrno( E_nomem );
            _RWD_amblksiz = oamblksiz;
            return( -1 );
        }
    }
    _RWD_amblksiz = oamblksiz;
    *envptr = p;
#if defined( _M_I86 ) && defined( __DOS__ )
  #if defined(__SMALL_DATA__)
    p = (char *) (((unsigned) p + 15) & 0xfff0);
  #else           /* large data models */         /* 12-aug-88 */
    p = MK_FP( FP_SEG(p), (( FP_OFF(p) + 15) & 0xfff0) );
  #endif
    {
        CHAR_TYPE _WCFAR *temp;

        temp = p;
        *envseg = FP_SEG( temp ) + FP_OFF( temp )/16;
    }
#else
    *envseg = 0;
#endif
    *envstrings = p;            /* save ptr to env strings. 07-oct-92 */
    if( envp != NULL ){
        for( i = 0; envp[i] != NULL; ++i ){
            p = stpcpy( p, envp[i] ) + 1;
        }
    }
    *p++ = '\0';
    if( exec ) {
        __F_NAME(strcpy,wcscpy)( p + 2, argv[0] );
    }

    len = 0;
    if( argv[0] != NULL ) {
        for( i = 1; argv[i] != NULL; ++i ){
            if( len != 0 ) ++len;       /* plus 1 for blank separator */
            len += __F_NAME(strlen,wcslen)( argv[i] );
        }
    }
#if defined( __NT__ )
    // we are going to add quotes around program name (argv[0])
    len += _MAX_PATH2 + 3;
#elif defined( __OS2__ )
    len += _MAX_PATH2 + 1;
#elif defined( __RDOS__ )
    len += _MAX_PATH2 + 1;
#else
    if( len > 126 ) {
        __set_errno( E2BIG );
        __set_doserrno( E_badenv );
        lib_free( *envptr );
        return( -1 );
    }
    len = _MAX_PATH;    /* always use _MAX_PATH chars for DOS */
#endif
    *cmdline_len = len;

    return( length / 16 );
}
示例#13
0
VOID int21_service(iregs FAR * r)
{
  COUNT rc,
    rc1;
  ULONG lrc;
  psp FAR *p = MK_FP(cu_psp, 0);

  p->ps_stack = (BYTE FAR *) r;

#ifdef DEBUG
  if (bDumpRegs)
  {
    fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs, sizeof(iregs));
    printf("System call (21h): %02x\n", user_r->AX);
    dump_regs = TRUE;
    dump();
  }
#endif

dispatch:

  /* Check for Ctrl-Break */
  switch (r->AH)
  {
    default:
      if (!break_ena)
        break;
    case 0x01:
    case 0x02:
    case 0x03:
    case 0x04:
    case 0x05:
    case 0x08:
    case 0x09:
    case 0x0a:
    case 0x0b:
      if (control_break())
        handle_break();
  }

  /* The dispatch handler                                         */
  switch (r->AH)
  {
      /* int 21h common error handler                                 */
    case 0x64:
    case 0x6b:
    default:
    error_invalid:
      r->AX = -DE_INVLDFUNC;
      goto error_out;
    error_exit:
      r->AX = -rc;
    error_out:
      r->FLAGS |= FLG_CARRY;
      break;

#if 0
      /* Moved to simulate a 0x4c00 -- 1999/04/21 ska */
      /* Terminate Program                                            */
    case 0x00:
      if (cu_psp == RootPsp)
        break;
      else if (((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp)
        break;
      tsr = FALSE;
      return_mode = break_flg ? 1 : 0;
      return_code = r->AL;
      if (DosMemCheck() != SUCCESS)
        panic("MCB chain corrupted");
#ifdef TSC
      StartTrace();
#endif
      return_user();
      break;
#endif

      /* Read Keyboard with Echo                      */
    case 0x01:
      Do_DosIdle_loop();
      r->AL = _sti();
      sto(r->AL);
      break;

      /* Display Character                                            */
    case 0x02:
      sto(r->DL);
      break;

      /* Auxiliary Input                                                      */
    case 0x03:
      r->AL = _sti();
      break;

      /* Auxiliary Output                                                     */
    case 0x04:
      sto(r->DL);
      break;

      /* Print Character                                                      */
    case 0x05:
      sto(r->DL);
      break;

      /* Direct Cosole I/O                                            */
    case 0x06:
      if (r->DL != 0xff)
        sto(r->DL);
      else if (StdinBusy())
      {
        r->AL = 0x00;
        r->FLAGS |= FLG_ZERO;
      }
      else
      {
        r->FLAGS &= ~FLG_ZERO;
        r->AL = _sti();
      }
      break;

      /* Direct Console Input                                         */
    case 0x07:
      /* Read Keyboard Without Echo                                   */
    case 0x08:
      Do_DosIdle_loop();
      r->AL = _sti();
      break;

      /* Display String                                               */
    case 0x09:
      {
        static COUNT scratch;
        BYTE FAR *p = MK_FP(r->DS, r->DX),
          FAR * q;
        q = p;
        while (*q != '$')
          ++q;
        DosWrite(STDOUT, q - p, p, (COUNT FAR *) & scratch);
      }
      r->AL = '$';
      break;

      /* Buffered Keyboard Input                                      */
    case 0x0a:
      ((keyboard FAR *) MK_FP(r->DS, r->DX))->kb_count = 0;
      sti((keyboard FAR *) MK_FP(r->DS, r->DX));
      ((keyboard FAR *) MK_FP(r->DS, r->DX))->kb_count -= 2;
      break;

      /* Check Stdin Status                                           */
    case 0x0b:
      if (StdinBusy())
        r->AL = 0xFF;
      else
        r->AL = 0x00;
      break;

      /* Flush Buffer, Read Keayboard                                 */
    case 0x0c:
      KbdFlush();
      switch (r->AL)
      {
        case 0x01:
        case 0x06:
        case 0x07:
        case 0x08:
        case 0x0a:
          r->AH = r->AL;
          goto dispatch;

        default:
          r->AL = 0x00;
          break;
      }
      break;

      /* Reset Drive                                                  */
    case 0x0d:
      flush();
      break;

      /* Set Default Drive                                            */
    case 0x0e:
      r->AL = DosSelectDrv(r->DL);
      break;

    case 0x0f:
      if (FcbOpen(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x10:
      if (FcbClose(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x11:
      if (FcbFindFirst(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x12:
      if (FcbFindNext(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x13:
      if (FcbDelete(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x14:
      {
        COUNT nErrorCode;

        if (FcbRead(MK_FP(r->DS, r->DX), &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

    case 0x15:
      {
        COUNT nErrorCode;

        if (FcbWrite(MK_FP(r->DS, r->DX), &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

    case 0x16:
      if (FcbCreate(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

    case 0x17:
      if (FcbRename(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

      /* CP/M compatibility functions                                 */
    case 0x18:
    case 0x1d:
    case 0x1e:
    case 0x20:
#ifndef TSC
    case 0x61:
#endif
      r->AL = 0;
      break;

      /* Get Default Drive                                            */
    case 0x19:
      r->AL = default_drive;
      break;

      /* Set DTA                                                      */
    case 0x1a:
      {
        psp FAR *p = MK_FP(cu_psp, 0);

        p->ps_dta = MK_FP(r->DS, r->DX);
        dos_setdta(p->ps_dta);
      }
      break;

      /* Get Default Drive Data                                       */
    case 0x1b:
      {
        BYTE FAR *p;

        FatGetDrvData(0,
                      (COUNT FAR *) & r->AX,
                      (COUNT FAR *) & r->CX,
                      (COUNT FAR *) & r->DX,
                      (BYTE FAR **) & p);
        r->DS = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get Drive Data                                               */
    case 0x1c:
      {
        BYTE FAR *p;

        FatGetDrvData(r->DL,
                      (COUNT FAR *) & r->AX,
                      (COUNT FAR *) & r->CX,
                      (COUNT FAR *) & r->DX,
                      (BYTE FAR **) & p);
        r->DS = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get default DPB                                              */
    case 0x1f:
      if (default_drive < lastdrive)
      {
        struct dpb FAR *dpb = (struct dpb FAR *)CDSp->cds_table[default_drive].cdsDpb;
        if (dpb == 0)
        {
          r->AL = 0xff;
          break;
        }

        r->DS = FP_SEG(dpb);
        r->BX = FP_OFF(dpb);
        r->AL = 0;
      }
      else
        r->AL = 0xff;
      break;

      /* Random read using FCB */
    case 0x21:
      {
        COUNT nErrorCode;

        if (FcbRandomRead(MK_FP(r->DS, r->DX), &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

      /* Random write using FCB */
    case 0x22:
      {
        COUNT nErrorCode;

        if (FcbRandomWrite(MK_FP(r->DS, r->DX), &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

      /* Get file size in records using FCB */
    case 0x23:
      if (FcbGetFileSize(MK_FP(r->DS, r->DX)))
        r->AL = 0;
      else
        r->AL = 0xff;
      break;

      /* Set random record field in FCB */
    case 0x24:
      FcbSetRandom(MK_FP(r->DS, r->DX));
      break;

      /* Set Interrupt Vector                                         */
    case 0x25:
      {
        VOID(INRPT FAR * p) () = MK_FP(r->DS, r->DX);

        setvec(r->AL, p);
      }
      break;

      /* Dos Create New Psp                                           */
    case 0x26:
      {
        psp FAR *p = MK_FP(cu_psp, 0);

        new_psp((psp FAR *) MK_FP(r->DX, 0), p->ps_size);
      }
      break;

      /* Read random record(s) using FCB */
    case 0x27:
      {
        COUNT nErrorCode;

        if (FcbRandomBlockRead(MK_FP(r->DS, r->DX), r->CX, &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

      /* Write random record(s) using FCB */
    case 0x28:
      {
        COUNT nErrorCode;

        if (FcbRandomBlockWrite(MK_FP(r->DS, r->DX), r->CX, &nErrorCode))
          r->AL = 0;
        else
          r->AL = nErrorCode;
        break;
      }

      /* Parse File Name                                              */
    case 0x29:
      {
        BYTE FAR *lpFileName;

        lpFileName = MK_FP(r->DS, r->SI);
        r->AL = FcbParseFname(r->AL,
                              &lpFileName,
                              MK_FP(r->ES, r->DI));
        r->DS = FP_SEG(lpFileName);
        r->SI = FP_OFF(lpFileName);
      }
      break;

      /* Get Date                                                     */
    case 0x2a:
      DosGetDate(
                  (BYTE FAR *) & (r->AL),	/* WeekDay              */
                  (BYTE FAR *) & (r->DH),	/* Month                */
                  (BYTE FAR *) & (r->DL),	/* MonthDay             */
                  (COUNT FAR *) & (r->CX));	/* Year                 */
      break;

      /* Set Date                                                     */
    case 0x2b:
      rc = DosSetDate(
                       (BYTE FAR *) & (r->DH),	/* Month                */
                       (BYTE FAR *) & (r->DL),	/* MonthDay             */
                       (COUNT FAR *) & (r->CX));	/* Year                 */
      if (rc != SUCCESS)
        r->AL = 0xff;
      else
        r->AL = 0;
      break;

      /* Get Time                                                     */
    case 0x2c:
      DosGetTime(
                  (BYTE FAR *) & (r->CH),	/* Hour                 */
                  (BYTE FAR *) & (r->CL),	/* Minutes              */
                  (BYTE FAR *) & (r->DH),	/* Seconds              */
                  (BYTE FAR *) & (r->DL));	/* Hundredths           */
      break;

      /* Set Date                                                     */
    case 0x2d:
      rc = DosSetTime(
                       (BYTE FAR *) & (r->CH),	/* Hour                 */
                       (BYTE FAR *) & (r->CL),	/* Minutes              */
                       (BYTE FAR *) & (r->DH),	/* Seconds              */
                       (BYTE FAR *) & (r->DL));	/* Hundredths           */
      if (rc != SUCCESS)
        r->AL = 0xff;
      else
        r->AL = 0;
      break;

      /* Set verify flag                                              */
    case 0x2e:
      verify_ena = (r->AL ? TRUE : FALSE);
      break;

      /* Get DTA                                                      */
    case 0x2f:
      r->ES = FP_SEG(dta);
      r->BX = FP_OFF(dta);
      break;

      /* Get DOS Version                                              */
    case 0x30:
      r->AL = os_major;
      r->AH = os_minor;
      r->BH = OEM_ID;
      r->CH = REVISION_MAJOR;   /* JPP */
      r->CL = REVISION_MINOR;
      r->BL = REVISION_SEQ;
      break;

      /* Keep Program (Terminate and stay resident) */
    case 0x31:
      DosMemChange(cu_psp, r->DX < 6 ? 6 : r->DX, 0);
      return_mode = 3;
      return_code = r->AL;
      tsr = TRUE;
      return_user();
      break;

      /* Get DPB                                                      */
    case 0x32:
      if (r->DL < lastdrive)
      {
        struct dpb FAR *dpb = CDSp->cds_table[r->DL].cdsDpb;
        if (dpb == 0)
        {
          r->AL = 0xff;
          break;
        }
        r->DS = FP_SEG(dpb);
        r->BX = FP_OFF(dpb);
        r->AL = 0;
      }
      else
        r->AL = 0xFF;
      break;

      /* Get InDOS flag                                               */
    case 0x34:
      {
        BYTE FAR *p;

        p = (BYTE FAR *) ((BYTE *) & InDOS);
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get Interrupt Vector                                         */
    case 0x35:
      {
        BYTE FAR *p;

        p = getvec((COUNT) r->AL);
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Dos Get Disk Free Space                                      */
    case 0x36:
      DosGetFree(
                  (COUNT) r->DL,
                  (COUNT FAR *) & r->AX,
                  (COUNT FAR *) & r->BX,
                  (COUNT FAR *) & r->CX,
                  (COUNT FAR *) & r->DX);
      break;

      /* Undocumented Get/Set Switchar                                */
    case 0x37:
      switch (r->AL)
      {
          /* Get switch character */
        case 0x00:
          r->DL = switchar;
          r->AL = 0x00;
          break;

          /* Set switch character */
        case 0x01:
          switchar = r->DL;
          r->AL = 0x00;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Get/Set Country Info                                         */
    case 0x38:
      {
        BYTE FAR *lpTable
        = (BYTE FAR *) MK_FP(r->DS, r->DX);
        BYTE nRetCode;

        if (0xffff == r->DX)
        {
          r->BX = SetCtryInfo(
                               (UBYTE FAR *) & (r->AL),
                               (UWORD FAR *) & (r->BX),
                               (BYTE FAR *) & lpTable,
                               (UBYTE *) & nRetCode);

          if (nRetCode != 0)
          {
            r->AX = 0xff;
            r->FLAGS |= FLG_CARRY;
          }
          else
          {
            r->AX = nRetCode;
            r->FLAGS &= ~FLG_CARRY;
          }
        }
        else
        {
          r->BX = GetCtryInfo(&(r->AL), &(r->BX), lpTable);
          r->FLAGS &= ~FLG_CARRY;
        }
      }
      break;

      /* Dos Create Directory                                         */
    case 0x39:
      rc = dos_mkdir((BYTE FAR *) MK_FP(r->DS, r->DX));
      if (rc != SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Dos Remove Directory                                         */
    case 0x3a:
      rc = dos_rmdir((BYTE FAR *) MK_FP(r->DS, r->DX));
      if (rc != SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Dos Change Directory                                         */
    case 0x3b:
      if ((rc = DosChangeDir((BYTE FAR *) MK_FP(r->DS, r->DX))) < 0)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Dos Create File                                              */
    case 0x3c:
      if ((rc = DosCreat(MK_FP(r->DS, r->DX), r->CX)) < 0)
        goto error_exit;
      else
      {
        r->AX = rc;
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Dos Open                                                     */
    case 0x3d:
      if ((rc = DosOpen(MK_FP(r->DS, r->DX), r->AL)) < 0)
        goto error_exit;
      else
      {
        r->AX = rc;
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Dos Close                                                    */
    case 0x3e:
      if ((rc = DosClose(r->BX)) < 0)
        goto error_exit;
      else
        r->FLAGS &= ~FLG_CARRY;
      break;

      /* Dos Read                                                     */
    case 0x3f:
      rc = DosRead(r->BX, r->CX, MK_FP(r->DS, r->DX), (COUNT FAR *) & rc1);

      if (rc1 != SUCCESS)
      {
        r->FLAGS |= FLG_CARRY;
        r->AX = -rc1;
      }
      else
      {
        r->FLAGS &= ~FLG_CARRY;
        r->AX = rc;
      }
      break;

      /* Dos Write                                                    */
    case 0x40:
      rc = DosWrite(r->BX, r->CX, MK_FP(r->DS, r->DX), (COUNT FAR *) & rc1);
      if (rc1 != SUCCESS)
      {
        r->FLAGS |= FLG_CARRY;
        r->AX = -rc1;
      }
      else
      {
        r->FLAGS &= ~FLG_CARRY;
        r->AX = rc;
      }
      break;

      /* Dos Delete File                                              */
    case 0x41:
      rc = dos_delete((BYTE FAR *) MK_FP(r->DS, r->DX));
      if (rc < 0)
      {
        r->FLAGS |= FLG_CARRY;
        r->AX = -rc1;
      }
      else
        r->FLAGS &= ~FLG_CARRY;
      break;

      /* Dos Seek                                                     */
    case 0x42:
      if ((rc = DosSeek(r->BX, (LONG) ((((LONG) (r->CX)) << 16) + r->DX), r->AL, &lrc)) < 0)
        goto error_exit;
      else
      {
        r->DX = (lrc >> 16);
        r->AX = lrc & 0xffff;
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Get/Set File Attributes                                      */
    case 0x43:
      switch (r->AL)
      {
        case 0x00:
          rc = DosGetFattr((BYTE FAR *) MK_FP(r->DS, r->DX), (UWORD FAR *) & r->CX);
          if (rc < SUCCESS)
            goto error_exit;
          else
          {
            r->FLAGS &= ~FLG_CARRY;
          }
          break;

        case 0x01:
          rc = DosSetFattr((BYTE FAR *) MK_FP(r->DS, r->DX), (UWORD FAR *) & r->CX);
          if (rc != SUCCESS)
            goto error_exit;
          else
            r->FLAGS &= ~FLG_CARRY;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Device I/O Control                                           */
    case 0x44:
      {
        rc = DosDevIOctl(r, (COUNT FAR *) & rc1);

        if (rc1 != SUCCESS)
        {
          r->FLAGS |= FLG_CARRY;
          r->AX = -rc1;
        }
        else
        {
          r->FLAGS &= ~FLG_CARRY;
        }
      }
      break;

      /* Duplicate File Handle                                        */
    case 0x45:
      rc = DosDup(r->BX);
      if (rc < SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
        r->AX = rc;
      }
      break;

      /* Force Duplicate File Handle                                  */
    case 0x46:
      rc = DosForceDup(r->BX, r->CX);
      if (rc < SUCCESS)
        goto error_exit;
      else
        r->FLAGS &= ~FLG_CARRY;
      break;

      /* Get Current Directory                                        */
    case 0x47:
      if ((rc = DosGetCuDir(r->DL, MK_FP(r->DS, r->SI))) < 0)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
        r->AX = 0x0100;         /*jpp: from interrupt list */
      }
      break;

      /* Allocate memory */
    case 0x48:
      if ((rc = DosMemAlloc(r->BX, mem_access_mode, &(r->AX), &(r->BX))) < 0)
      {
        DosMemLargest(&(r->BX));
        goto error_exit;
      }
      else
      {
        ++(r->AX);              /* DosMemAlloc() returns seg of MCB rather than data */
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Free memory */
    case 0x49:
      if ((rc = DosMemFree((r->ES) - 1)) < 0)
        goto error_exit;
      else
        r->FLAGS &= ~FLG_CARRY;
      break;

      /* Set memory block size */
    case 0x4a:
      {
        UWORD maxSize;

        if ((rc = DosMemChange(r->ES, r->BX, &maxSize)) < 0)
        {
          if (rc == DE_NOMEM)
            r->BX = maxSize;

#if 0
          if (cu_psp == r->ES)
          {

            psp FAR *p;

            p = MK_FP(cu_psp, 0);
            p->ps_size = r->BX + cu_psp;
          }
#endif
          goto error_exit;
        }
        else
          r->FLAGS &= ~FLG_CARRY;

        break;
      }

      /* Load and Execute Program */
    case 0x4b:
      break_flg = FALSE;

      if ((rc = DosExec(r->AL, MK_FP(r->ES, r->BX), MK_FP(r->DS, r->DX)))
          != SUCCESS)
        goto error_exit;
      else
        r->FLAGS &= ~FLG_CARRY;
      break;

      /* Terminate Program                                            */
    case 0x00:
      r->AX = 0x4c00;

      /* End Program                                                  */
    case 0x4c:
      if (cu_psp == RootPsp
          || ((psp FAR *) (MK_FP(cu_psp, 0)))->ps_parent == cu_psp)
        break;
      tsr = FALSE;
/*      int2f_Remote_call(0x1122, 0, 0, 0, 0, 0, 0);
   int2f_Remote_call(REM_CLOSEALL, 0, 0, 0, 0, 0, 0);
 */
      if (ErrorMode)
      {
        ErrorMode = FALSE;
        return_mode = 2;
      }
      else if (break_flg)
      {
        break_flg = FALSE;
        return_mode = 1;
      }
      else
      {
        return_mode = 0;
      }
      return_code = r->AL;
      if (DosMemCheck() != SUCCESS)
        panic("MCB chain corrupted");
#ifdef TSC
      StartTrace();
#endif
      return_user();
      break;

      /* Get Child-program Return Value                               */
    case 0x4d:
      r->AL = return_code;
      r->AH = return_mode;
      break;

      /* Dos Find First                                               */
    case 0x4e:
      {
        /* dta for this call is set on entry.  This     */
        /* needs to be changed for new versions.        */
        if ((rc = DosFindFirst((UCOUNT) r->CX, (BYTE FAR *) MK_FP(r->DS, r->DX))) < 0)
          goto error_exit;
        else
        {
          r->AX = 0;
          r->FLAGS &= ~FLG_CARRY;
        }
      }
      break;

      /* Dos Find Next                                                */
    case 0x4f:
      {
        /* dta for this call is set on entry.  This     */
        /* needs to be changed for new versions.        */
        if ((rc = DosFindNext()) < 0)
        {
          r->AX = -rc;

          if (r->AX == 2)
            r->AX = 18;

          r->FLAGS |= FLG_CARRY;
        }
        else
        {
          r->FLAGS &= ~FLG_CARRY;
        }
      }
      break;

      /* ************UNDOCUMENTED************************************* */
      /* Get List of Lists                                            */
    case 0x52:
      {
        BYTE FAR *p;

        p = (BYTE FAR *) & DPBp;
        r->ES = FP_SEG(p);
        r->BX = FP_OFF(p);
      }
      break;

      /* Get verify state                                             */
    case 0x54:
      r->AL = (verify_ena ? TRUE : FALSE);
      break;

      /* ************UNDOCUMENTED************************************* */
      /* Dos Create New Psp & set p_size                              */
    case 0x55:
      new_psp((psp FAR *) MK_FP(r->DX, 0), r->SI);
      break;

      /* Dos Rename                                                   */
    case 0x56:
      rc = dos_rename(
                       (BYTE FAR *) MK_FP(r->DS, r->DX),	/* OldName      */
                       (BYTE FAR *) MK_FP(r->ES, r->DI));	/* NewName      */
      if (rc < SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Get/Set File Date and Time                                   */
    case 0x57:
      switch (r->AL)
      {
        case 0x00:
          rc = DosGetFtime(
                            (COUNT) r->BX,	/* Handle               */
                            (date FAR *) & r->DX,	/* FileDate             */
                            (time FAR *) & r->CX);	/* FileTime             */
          if (rc < SUCCESS)
            goto error_exit;
          else
            r->FLAGS &= ~FLG_CARRY;
          break;

        case 0x01:
          rc = DosSetFtime(
                            (COUNT) r->BX,	/* Handle               */
                            (date FAR *) & r->DX,	/* FileDate             */
                            (time FAR *) & r->CX);	/* FileTime             */
          if (rc < SUCCESS)
            goto error_exit;
          else
            r->FLAGS &= ~FLG_CARRY;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Get/Set Allocation Strategy                                  */
    case 0x58:
      switch (r->AL)
      {
        case 0x00:
          r->AX = mem_access_mode;
          break;

        case 0x01:
          if (((COUNT) r->BX) < 0 || r->BX > 2)
            goto error_invalid;
          else
          {
            mem_access_mode = r->BX;
            r->FLAGS &= ~FLG_CARRY;
          }
          break;

        default:
          goto error_invalid;
#ifdef DEBUG
        case 0xff:
          show_chain();
          break;
#endif
      }
      break;

      /* Create Temporary File */
    case 0x5a:
      if ((rc = DosMkTmp(MK_FP(r->DS, r->DX), r->CX)) < 0)
        goto error_exit;
      else
      {
        r->AX = rc;
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Create New File */
    case 0x5b:
      if ((rc = DosOpen(MK_FP(r->DS, r->DX), 0)) >= 0)
      {
        DosClose(rc);
        r->AX = 80;
        r->FLAGS |= FLG_CARRY;
      }
      else
      {
        if ((rc = DosCreat(MK_FP(r->DS, r->DX), r->CX)) < 0)
          goto error_exit;
        else
        {
          r->AX = rc;
          r->FLAGS &= ~FLG_CARRY;
        }
      }
      break;

      /* UNDOCUMENTED: server, share.exe and sda function             */
    case 0x5d:
      switch (r->AL)
      {
          /* Remote Server Call */
        case 0x00:
          {
            UWORD FAR *x = MK_FP(r->DS, r->DX);
            r->AX = x[0];
            r->BX = x[1];
            r->CX = x[2];
            r->DX = x[3];
            r->SI = x[4];
            r->DI = x[5];
            r->DS = x[6];
            r->ES = x[7];
          }
          goto dispatch;

        case 0x06:
          r->DS = FP_SEG(internal_data);
          r->SI = FP_OFF(internal_data);
          r->CX = swap_always - internal_data;
          r->DX = swap_indos - internal_data;
          r->FLAGS &= ~FLG_CARRY;
          break;

        case 0x07:
        case 0x08:
        case 0x09:
          int2f_Remote_call(REM_PRINTREDIR, 0, 0, r->DX, 0, 0, (MK_FP(0, Int21AX)));
          break;

        default:
          goto error_invalid;
      }
      break;

    case 0x5e:
      switch (r->AL)
      {
        case 0x00:
          r->CX = get_machine_name(MK_FP(r->DS, r->DX));
          break;

        case 0x01:
          set_machine_name(MK_FP(r->DS, r->DX), r->CX);
          break;

        default:
          int2f_Remote_call(REM_PRINTSET, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX)));
          break;
      }
      break;

    case 0x5f:
      switch (r->AL)
      {
        case 0x07:
          CDSp->cds_table[r->DL].cdsFlags |= 0x100;
          break;

        case 0x08:
          CDSp->cds_table[r->DL].cdsFlags &= ~0x100;
          break;

        default:
          int2f_Remote_call(REM_DOREDIRECT, r->BX, r->CX, r->DX, (MK_FP(r->ES, r->DI)), r->SI, (MK_FP(r->DS, Int21AX)));
          break;
      }
      break;

    case 0x60:                 /* TRUENAME */
      if ((rc = truename(MK_FP(r->DS, r->SI),
                      adjust_far(MK_FP(r->ES, r->DI)), TRUE)) != SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

#ifdef TSC
      /* UNDOCUMENTED: no-op                                          */
      /*                                                              */
      /* DOS-C: tsc support                                           */
    case 0x61:
#ifdef DEBUG
      switch (r->AL)
      {
        case 0x01:
          bTraceNext = TRUE;
          break;

        case 0x02:
          bDumpRegs = FALSE;
          break;
      }
#endif
      r->AL = 0x00;
      break;
#endif

      /* UNDOCUMENTED: return current psp                             */
    case 0x62:
      r->BX = cu_psp;
      break;

      /* UNDOCUMENTED: Double byte and korean tables                  */
    case 0x63:
      {
#ifdef DBLBYTE
        static char dbcsTable[2] =
        {
          0, 0
        };
        void FAR *dp = &dbcsTable;

        r->DS = FP_SEG(dp);
        r->SI = FP_OFF(dp);
        r->AL = 0;
#else
        /* not really supported, but will pass.                 */
        r->AL = 0x00;           /*jpp: according to interrupt list */
#endif
        break;
      }

      /* Extended country info                                        */
    case 0x65:
      if (r->AL <= 0x7)
      {
        if (ExtCtryInfo(
                         r->AL,
                         r->BX,
                         r->CX,
                         MK_FP(r->ES, r->DI)))
          r->FLAGS &= ~FLG_CARRY;
        else
          goto error_invalid;
      }
      else if ((r->AL >= 0x20) && (r->AL <= 0x22))
      {
        switch (r->AL)
        {
          case 0x20:
            r->DL = upChar(r->DL);
            goto okay;

          case 0x21:
            upMem(
                   MK_FP(r->DS, r->DX),
                   r->CX);
            goto okay;

          case 0x22:
            upString(MK_FP(r->DS, r->DX));
          okay:
            r->FLAGS &= ~FLG_CARRY;
            break;

          case 0x23:
            r->AX = yesNo(r->DL);
            goto okay;

          default:
            goto error_invalid;
        }
      }
      else
        r->FLAGS |= FLG_CARRY;
      break;

      /* Code Page functions */
    case 0x66:
      switch (r->AL)
      {
        case 1:
          GetGlblCodePage(
                           (UWORD FAR *) & (r->BX),
                           (UWORD FAR *) & (r->DX));
          goto okay_66;

        case 2:
          SetGlblCodePage(
                           (UWORD FAR *) & (r->BX),
                           (UWORD FAR *) & (r->DX));
        okay_66:
          r->FLAGS &= ~FLG_CARRY;
          break;

        default:
          goto error_invalid;
      }
      break;

      /* Set Max file handle count */
    case 0x67:
      if ((rc = SetJFTSize(r->BX)) != SUCCESS)
        goto error_exit;
      else
      {
        r->FLAGS &= ~FLG_CARRY;
      }
      break;

      /* Flush file buffer -- dummy function right now.  */
    case 0x68:
      r->FLAGS &= ~FLG_CARRY;
      break;
  }

#ifdef DEBUG
  if (bDumpRegs)
  {
    fbcopy((VOID FAR *) user_r, (VOID FAR *) & error_regs,
           sizeof(iregs));
    dump_regs = TRUE;
    dump();
  }
#endif
}
示例#14
0
void main()
{
char opcion;
unsigned int sw;
int *tope, *base, *lo, *max, *li;
int n, inf;

//Menú
sw=0;
do{
   clrscr();
   gotoxy (20,2);
   printf ("MENÚ PRINCIPAL")
   gotoxy (15,4);
   printf ("1-CREAR DOBLE COLA");
   gotoxy (15,6);
   printf ("2-INSERTAR NODO EN LA DOBLE COLA");
   gotoxy (15,8);
   printf ("3-CANCELAR NODO EN LA DOBLE COLA");
   gotoxy (15,10);
   printf ("4-MOSTRAR DOBLE COLA");
   gotoxy (15,12);
   printf ("5-SALIR");
   gotoxy (15,14);
   printf (" DIGITE OPCION");

   do{
     opcion=getchar ();
     }while(opcion<'0' && opcion <'5');
     switch (opcion){

     case '1': if(sw==0){
     sw=1;
     clrscr();
     //Espacio diponible
     printf ("DIGIE EL MÁXIMO NÚMERO DE NODOS DE LA LISTA");
     do{
     scanf ("%d",&n);
     }while (n<=0);
     //Crear_DQ (&lo,&base,&tope,n);max=maximo (lo,n);
     printf ("lo=%04x:%04x",FP_SEG(lo),FP_OFF(lo));
     printf ("base=%04x:%04x",FP_SEG(base),FP_OFF(base));
     printf ("tope=%04x:%04x",FP_SEG(tope),FP_OFF(tope));
     printf ("max=%04x:%04x",FP_SEG(max),FP_OFF(max));
     printf ("\n\n DIGITE 0 Y <ENTER> CONTINUA ");
     do{
     opcion= getchar();
     }while (opcion!='0');
     }
     else{
		   clrscr();
		   printf ("PILA YA CREADA...  DIGITE 0 Y <ENTER> CONTINUA ");
		   do{
		     opcion=getchar ();
		     }while (opcion!='0');
	       }	      
	       break;

     case '2': do{                 
                 clrscr();
		 gotoxy(15,4);
		 printf ("1- INSERTAR NODO POR TOPE");
		 gotoxy(15,5);
		 printf ("2- INSERTAR NODO POR BASE");
		 gotoxy(15,6);
		 printf ("3- RETORNAR MENU PRINCIPAL");
		 gotoxy(15,8);
		 printf ("POR FAVOR DIGITE LA OPCION ");
		 do{
		   opcion=getchar();
		 }while (opcion<='0' && opcion>'3');
		 switch(opcion){

		 case '1': if (sw==1){
                 
			      clrscr();
			      printf ("\n DIGITE INFORMACION DEL NODO A  INCLUIR");
			      scanf  ("%d",&inf);
			    //  Insertt(lo,base,tope,inf);
		           }
			   else{
			       clrscr();
			       printf ("PILA NO CREADA..DIGITE 0 Y <ENTER> CONTINUA");
			       do{
				 opcion=getchar();
			       }while (opcion!='0');
			   }
			   break;


		 case '2': if(sw==1){
			     clrscr();
			     printf ("\n DIGITE INFORMACION DEL NODO A INCLUIR");
			     scanf ("%d",&inf);
			     //Insertb(lo,base,tope,inf);
			   }   
			   else{
			       clrscr();
			       printf("PILA NO CREADA...DIGITE 0 Y <ENTER> CONTINUA");
			       do{
				 opcion =getchar();
			       }while (opcion !='0');
			   }
			   break;

		   default:break;
		   }

		   }while (opcion!='3');
		    return;

     case '3': if (sw==1){
		   clrscr();
		   gotoxy(15,4);
		   printf ("1- REMOVER O CANCELAR POR TOPE");
		   gotoxy(15,5);
		   printf ("2- REMOVER O CANCELAR POR BASE");
		   gotoxy(15,6);
		   printf ("3- RETORNAR AL MENÚ PRINCIPAL ");
		   gotoxy(15,14);
		   printf ("POR FAVOR DIGITE LA OPCION DESEADA");
		   do{
		     opcion=getchar();
		   }while(opcion<='0' && opcion>'3');
		   switch (opcion){

		   case '1': if (sw==1){
				clrscr();
				Removet(lo,base,tope,inf);
				printf ("\n NODO CANCELADO = %d",inf);
				printf ("\n \n DIGITE 0 Y <ENTER> CONTINUA");
				do{
				  opcion=getchar();
				}while (opcion!='0');
			     }
			     else{
				 clrscr();
				 printf ("PILA NO CREADA... DIGITE 0 Y <ENTER> CONTINUA");
				 do{
				   opcion=getchar();
				 }while (opcion!='0');
			     }
			     break;

		   case '2': if (sw==1){
				clrscr();
				Removeb(lo,base,tope,inf);
				printf ("\n NODO CANCELADO =%d",inf);
				printf ("\n\n DIGITE 0 Y <ENTER> CONTINUA");
				do{
				  opcion=getchar();
				}while (opcion!='0');

			     }
                             else{
				  clrscr();
				  printf ("PILA NO CREADA... DIGITE 0 Y <ENTER> CONTINUA");
				 do{
				   opcion=getchar();
				 }while (opcion!='0');
			     }
			     break;
		       default:break;
		       }
		       }while (opcion!='3');
		        return;

		   case '4': if (sw==1){
				clrscr();
				Escribir_DQ(lo, base, &tope, max);
				printf ("\n\n DIGITE 0 Y <ENTER> CONTINUA");
				do{
				  opcion=getchar();
				}while (opcion!='0');

			     }
                             else{
				  clrscr();
				  printf ("PILA NO CREADA... DIGITE 0 Y <ENTER> CONTINUA");
				 do{
				   opcion=getchar();
				 }while (opcion!='0');
			     }
			     break;
		       default:break;
		       }
		       }while (opcion!='5');
			clrscr();
			printf("FIN DEL PROCESO");
		       }
示例#15
0
文件: blockio.c 项目: TijmenW/FreeDOS
BOOL searchblock(ULONG blkno, COUNT dsk, 
                            struct buffer FAR ** pBuffp)
{
    int    fat_count = 0;
    struct buffer FAR *bp;
    struct buffer FAR *lbp        = NULL;
    struct buffer FAR *lastNonFat = NULL;
    struct buffer FAR *uncacheBuf = NULL;

    
#ifdef DISPLAY_GETBLOCK
    printf("[searchblock %d, blk %ld, buf ", dsk, blkno);
#endif
    
    

  /* Search through buffers to see if the required block  */
  /* is already in a buffer                               */

  for (bp = firstbuf; bp != NULL;lbp = bp, bp = bp->b_next)
  {
    if ((getblkno(bp) == blkno)  &&
        (bp->b_flag & BFR_VALID) && (bp->b_unit == dsk))
    {
      /* found it -- rearrange LRU links      */
      if (lbp != NULL)
      {
	    lbp->b_next = bp->b_next;
	    bp->b_next = firstbuf;
	    firstbuf = bp;
      }
#ifdef DISPLAY_GETBLOCK
      printf("HIT %04x:%04x]\n", FP_SEG(bp), FP_OFF(bp));
#endif
      *pBuffp = bp;
      return TRUE;
    }

    if (bp->b_flag & BFR_UNCACHE)
    	uncacheBuf = bp;
    

    if (bp->b_flag & BFR_FAT)
    	fat_count++;
    else
        lastNonFat = bp;
  }
  
  /*
    now take either the last buffer in chain (not used recently)
    or, if we are low on FAT buffers, the last non FAT buffer
  */  

  if (uncacheBuf) 
  {
    lbp = uncacheBuf;    
  }    	
  else 
  {
    if (lbp ->b_flag & BFR_FAT && fat_count < 3 && lastNonFat)
    {
    lbp = lastNonFat;  
    }
  }    
  
  lbp->b_flag &= ~BFR_UNCACHE;      /* reset uncache attribute */
  
  *pBuffp = lbp;
  
#ifdef DISPLAY_GETBLOCK
  printf("MISS, replace %04x:%04x]\n", FP_SEG(lbp), FP_OFF(lbp));
#endif

  

  if (lbp != firstbuf)      /* move to front */
    {
    for (bp = firstbuf; bp->b_next != lbp; bp = bp->b_next)
        ;
    bp->b_next = bp->b_next->b_next;
    lbp->b_next = firstbuf;
    firstbuf = lbp;
    }
  
  return FALSE;
}                                
示例#16
0
/*
 * Init32BitTask - load and initialize the 32-bit application
 */
int Init32BitTask( HINSTANCE thishandle, HINSTANCE prevhandle, LPSTR cmdline,
                    int cmdshow )
{
    WORD                i,amount,bytes_read,j;
    WORD                sel;
    int                 handle;
    tiny_ret_t          rc;
    DWORD               size,currsize,curroff,minmem,maxmem;
    DWORD               relsize,exelen;
    struct wstart_vars  __far *dataptr;
    void                __far *aliasptr;
    DWORD               __far *relptr;
    struct fpu_area     __far *fpuptr;
    rex_exe             exe;
    exe_data            exedat;
    char                file[128];
    DWORD               flags;
    version_info        vi;
    DWORD               file_header_size;
    BOOL                tried_global_compact;
    DWORD               save_maxmem;
    dpmi_mem_block      adata;

    flags = GetWinFlags();
    /*
     * verify that we are running on a 32-bit DPMI
     */
    _fDPMIGetVersion( &vi );
    if( !(vi.flags & VERSION_80386) ) {
        MessageBox( NULL, "Not running on a 386 DPMI implementation",MsgTitle,
                        MB_OK | MB_ICONHAND | MB_TASKMODAL );
        return( FALSE );
    }

    /*
     * get exe to load
     */
    GetModuleFileName( thishandle, file, 128 );
    rc = _fTinyOpen( file, TIO_READ );
    if( TINY_ERROR( rc ) ) {
        return( Fini( 2, (char _FAR *)"Error opening file",
                    (char _FAR *)file) );
    }
    handle = TINY_INFO( rc );

    _TinySeek( handle, 0x38, TIO_SEEK_START );
    _fTinyRead( handle, &exelen, sizeof( DWORD ) );
    _TinySeek( handle, exelen, TIO_SEEK_START );

    /*
     * check if we are being run by the debugger.  When the debugger
     * sees the 'DEADBEEF' bytes at the start of the code segment
     * (see begin.asm), it swaps them to be BEEFDEAD.  The debugger
     * then tells us to go, and if we see that we have BEEFDEAD,
     * we execute a breakpoint just before we call our 32-bit code.
     * Then the debugger traces a single instruction and it looks to
     * the user like the start of his/her code is the start of
     * the application.
     */
    if( deadbeef == 0xBEEFDEAD ) {
        InDebugger = 0;
    } else {
        InDebugger = 1;
    }
    DPL = (CS() & 0x03) << 5;   /* our privilege level */

    /*
     * validate header signature
     */
    _fTinyRead( handle, &exe, sizeof( rex_exe ) );
//    BreakPoint();
    if( !(exe.sig[0] == 'M' && exe.sig[1] == 'Q') ) {
        return( Fini( 1,(char _FAR *)"Invalid EXE" ) );
    }
    file_header_size = (DWORD) exe.file_header * 16L;
    /*
     * exe.one is supposed to always contain a 1 for a .REX file.
     * However, to allow relocation tables bigger than 64K, the
     * we extended the linker to have the .one field contain the
     * number of full 64K chunks of relocations, minus 1.
     */
    file_header_size += (exe.one-1)*0x10000L*16L;

    /*
     * get exe data - data start and stack start
     */
    _TinySeek( handle, exelen + file_header_size + (long)exe.initial_eip, TIO_SEEK_START );
    _fTinyRead( handle, &exedat, sizeof( exe_data ) );
    /*
     * get file size
     */
    size = (long) exe.file_size2 * 512L;
    if( exe.file_size1 > 0 ) {
        size += (long) exe.file_size1 - 512L;
    }

    /*
     * get stack size
     */
    StackSize = Align4K( exe.initial_esp - ((exedat.stackstart+15) & ~15ul) );
    if( StackSize < 0x1000 ) {
        StackSize = 0x1000;
    }

    /*
     * get minimum/maximum amounts of heap, then add in exe size
     * to get total area
     */
//    BreakPoint();
    minmem = (DWORD) exe.min_data *(DWORD) 4096L;
    if( exe.max_data == (WORD)-1 ) {
        maxmem = 4096L;
    } else {
        maxmem = (DWORD) exe.max_data*4096L;
    }
    minmem = Align4K( minmem + size + 0x10000ul );
    maxmem = Align4K( maxmem + size + 0x10000ul );
    if( minmem > maxmem ) {
        maxmem = minmem;
    }

    /*
     * get memory to load file
     */
    tried_global_compact = FALSE;
    save_maxmem = maxmem;
    while( (i = _DPMIGet32( &adata, maxmem )) != 0 ) {
        if( maxmem == minmem ) {
            if( tried_global_compact ) {
                return( Fini( 3,
                  (char _FAR *)"Not enough memory for application\n(minimum ",
                  dwordToStr( minmem ),(char _FAR *)" required)" ));
            }
            /*
             * GlobalCompact(-1) causes Windows to unfragment its
             * memory.  This might give us a chance to get a linear
             * chunk big enough
             */
            GlobalCompact( GlobalCompact( 0 ) );
            maxmem = save_maxmem;
            tried_global_compact = TRUE;
        } else if( maxmem < 64L * 1024L ) {
            maxmem = minmem;
        } else {
            maxmem -= 64L * 1024L;
            if( maxmem < minmem ) {                     /* 09-aug-93 */
                maxmem = minmem;
            }
        }
    }
    DataHandle = adata.handle;
    BaseAddr   = adata.linear + 0x10000ul;
#if FLAT
    i = InitFlatAddrSpace( BaseAddr, 0L );
#else
    i = InitFlatAddrSpace( BaseAddr, maxmem );
#endif
    BaseAddr = 0L;
    if( i ) {
        DPMIFreeMemoryBlock( DataHandle );
        return( Fini( 2,(char _FAR *)"Allocation error ", dwordToStr( i ) ) );
    }
    SaveSP = BaseAddr + StackSize;
    CodeLoadAddr = SaveSP;
    MyDataSelector = DataSelector;
    GetDataSelectorInfo();
    CodeEntry.off = exe.initial_eip + CodeLoadAddr + sizeof( exe_data );

    /*
     * this builds a collection of LDT selectors that are ready for
     * allocation
     */
    if( InitSelectorCache() != 0 ) {
        return( Fini( 1,(char _FAR *)outOfSelectors) );
    }

    /*
     * read the exe into memory
     */
    currsize = size - file_header_size;
    _TinySeek( handle, exelen + file_header_size, TIO_SEEK_START );
    i = _DPMIGetAliases( CodeLoadAddr, (LPDWORD)&aliasptr, 0 );
    if( i ) {
        return( Fini( 3,(char _FAR *)"Error ",
                dwordToStr( i ),
                (char _FAR *)" getting alias for read" ) );
    }
    dataptr = aliasptr;
    sel = ((DWORD)dataptr) >> 16;
    curroff = CodeLoadAddr;
    while( currsize != 0 ) {

        if( currsize >= (DWORD) READSIZE ) {
            amount = READSIZE;
        } else {
            amount = (WORD) currsize;
        }
        rc = _fTinyRead( handle, dataptr, amount );
        bytes_read = TINY_INFO( rc );
        if( bytes_read != amount ) {
            return( Fini( 1,(char _FAR *)"Read error" ) );
        }
        currsize -= (DWORD) amount;
        curroff += (DWORD) amount;
        DPMISetSegmentBaseAddress( sel, DataSelectorBase + curroff );
    }
    EDataAddr = curroff;                        // 03-jan-95

    DPMISetSegmentBaseAddress( sel, DataSelectorBase );
    relptr = (DWORD __far *)aliasptr;             // point to 32-bit stack area
    /*
     * get and apply relocation table
     */
    relsize = sizeof( DWORD ) * (DWORD) exe.reloc_cnt;
    {
        DWORD   realsize;
        WORD    kcnt;

        realsize = file_header_size - (DWORD) exe.first_reloc;
        kcnt = realsize / (0x10000L*sizeof(DWORD));
        relsize += kcnt * (0x10000L*sizeof(DWORD));
    }
    if( relsize != 0 ) {
        _TinySeek( handle, exelen + (DWORD)exe.first_reloc, TIO_SEEK_START );
        if( StackSize >= (DWORD) READSIZE ) {
            amount = READSIZE;
        } else {
            amount = (WORD) StackSize;
        }
        while( relsize != 0L ) {
            if( relsize < (DWORD)amount ) {
                amount = (WORD) relsize;
            }
            rc = _fTinyRead( handle, relptr, amount );
            bytes_read = TINY_INFO( rc );
            if( bytes_read != amount ) {
                return( Fini( 1,(char _FAR *)"Relocation read error" ) );
            }
            CodeRelocate( relptr, amount/sizeof(DWORD) );
            relsize -= (DWORD) amount;
        }
    }

    _TinyClose( handle );

    /* initialize emulator 8087 save area 20-oct-94 */

    fpuptr = (struct fpu_area __far *)((char __far *)aliasptr + FPU_AREA);
    _fmemset( fpuptr, 0, sizeof(struct fpu_area) );
    fpuptr->control_word = 0x033F;
    fpuptr->tag_word = 0xFFFF;

    /*
     * set dataptr to special area in data segment of 32-bit app
     */
    curroff = exedat.datastart;
    if( exe.reloc_cnt != 0 )  curroff += CodeLoadAddr;
    DPMISetSegmentBaseAddress( sel, DataSelectorBase + curroff );

    /*
     * insert command line parms
     */
    dataptr->thishandle = (WORD)thishandle;
    dataptr->prevhandle = (WORD)prevhandle;
    dataptr->cmdline    = (DWORD) cmdline;
    dataptr->cmdshow    = cmdshow;
    dataptr->_no87      = _no87;

    /*
     * set hardware selectors for screen memory
     */
    dataptr->_A000H     = (WORD) &_A000H;
    dataptr->_B000H     = (WORD) &_B000H;
    dataptr->_B800H     = (WORD) &_B800H;
    dataptr->_C000H     = (WORD) &_C000H;
    dataptr->_D000H     = (WORD) &_D000H;
    dataptr->_E000H     = (WORD) &_E000H;
    dataptr->_F000H     = (WORD) &_F000H;

    /*
     * ptrs to some data areas
     */
    dataptr->CodeSelectorBase.seg =  (WORD) FP_SEG( &CodeSelectorBase );
    dataptr->CodeSelectorBase.off = (DWORD) FP_OFF( &CodeSelectorBase );
    dataptr->DataSelectorBase.seg =  (WORD) FP_SEG( &DataSelectorBase );
    dataptr->DataSelectorBase.off = (DWORD) FP_OFF( &DataSelectorBase );
    dataptr->_32BitCallBackAddr.seg =  (WORD) FP_SEG( &_32BitCallBackAddr );
    dataptr->_32BitCallBackAddr.off = (DWORD) FP_OFF( &_32BitCallBackAddr );
    dataptr->_DLLEntryAddr.seg =  (WORD) FP_SEG( &_DLLEntryAddr );
    dataptr->_DLLEntryAddr.off = (DWORD) FP_OFF( &_DLLEntryAddr );
    dataptr->_WEPAddr.seg =  (WORD) FP_SEG( &_WEPAddr );
    dataptr->_WEPAddr.off = (DWORD) FP_OFF( &_WEPAddr );
    dataptr->_16BitCallBackAddr = &__CallBack;

    /*
     * insert glue routines into data area of caller
     */
    for( j = 0; j < MaxGlueRoutines; j++ ) {
        dataptr->gluertns[j].seg =  (WORD) FP_SEG( Glue[j].rtn );
        dataptr->gluertns[j].off = (DWORD) FP_OFF( Glue[j].rtn );
    }
    _DPMIFreeAlias( sel );

    /*
     * check for FPU and WGod
     */
    if( flags & WF_80x87 ) {
        Has87 = TRUE;
    } else {
        Has87 = FALSE;
    }
    if( CheckWin386Debug() == WGOD_VERSION ) {
//    BreakPoint();
        HasWGod = TRUE;
        if( !Has87 ) {
            EMUInit();
            EMURegister( CodeEntry.seg, SaveSP - StackSize + FPU_AREA );
        }
    } else {
        HasWGod = FALSE;
    }
    return( TRUE );

} /* Init32BitTask */
示例#17
0
文件: anim.c 项目: TermiT/sw-redux
void 
playanm(short anim_num)
    {
    char *animbuf, *palptr;
    long i, j, k, length = 0, numframes = 0;
    int32 handle = -1;
    char ANIMvesapal[4*256];
    char tempbuf[256];
    char *palook_bak = palookup[0];
    extern BOOL noanim;
        
    if (noanim) return;

    ANIMnum = anim_num;

    KB_FlushKeyboardQueue();    
    KB_ClearKeysDown();    
    
    DSPRINTF(ds,"PlayAnm");
    MONO_PRINT(ds);

    DSPRINTF(ds,"PlayAnm");
    MONO_PRINT(ds);

    animbuf = LoadAnm(anim_num);
    if (!animbuf)    
        return;
    
    DSPRINTF(ds,"PlayAnm - Palette Stuff");
    MONO_PRINT(ds);

    for (i = 0; i < 256; i++)
        tempbuf[i] = i;
    palookup[0] = tempbuf;    
        
    ANIM_LoadAnim(animbuf);
    ANIMnumframes = ANIM_NumFrames();
    numframes = ANIMnumframes;
    
    palptr = ANIM_GetPalette();
    for (i = 0; i < 768; i++)
	ANIMvesapal[i] = palptr[i]>>2;

    tilesizx[ANIM_TILE(ANIMnum)] = 200;
    tilesizy[ANIM_TILE(ANIMnum)] = 320;

    setbrightness(gs.Brightness,ANIMvesapal,2);
        
    if (ANIMnum == 1)
        {
        // draw the first frame
        waloff[ANIM_TILE(ANIMnum)] = FP_OFF(ANIM_DrawFrame(1));
	invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4);
        rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);
        }

    SoundState = 0;
    //ototalclock = totalclock + 120*2;
    ototalclock = totalclock;
    

    for (i = 1; i < numframes; i++)
        {
        while (totalclock < ototalclock)
            {
			handleevents();
            switch (ANIMnum)
                {
                case 0:
                    if (KB_KeyWaiting() || quitevent)
                        goto ENDOFANIMLOOP;
                    break;
                case 1:
                    if (KEY_PRESSED(KEYSC_ESC) || quitevent)
                        goto ENDOFANIMLOOP;
                    break;
                }
#if MEGAWANG
            if (KEY_PRESSED(KEYSC_ESC) || quitevent)
                    goto ENDOFANIMLOOP;
#endif
                
            getpackets();
            }

        switch (ANIMnum)
            {
            case ANIM_INTRO:
                AnimShareIntro(i,numframes);    
                break;
            case ANIM_SERP:
                AnimSerp(i,numframes);    
                break;
            case ANIM_SUMO:
                AnimSumo(i,numframes);    
                break;
            case ANIM_ZILLA:
                AnimZilla(i,numframes);    
                break;
            }    
            
        waloff[ANIM_TILE(ANIMnum)] = FP_OFF(ANIM_DrawFrame(i));
	invalidatetile(ANIM_TILE(ANIMnum), 0, 1<<4);
            

        rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);
        nextpage();
        }

    // pause on final frame    
    while (totalclock < ototalclock) {
		handleevents();
        getpackets();
	}
        
ENDOFANIMLOOP:

    clearview(0);
    nextpage();
    palookup[0] = palook_bak;
    setbrightness(gs.Brightness, (char*)palette_data, 2);
    
    KB_FlushKeyboardQueue();    
    KB_ClearKeysDown();    
    ANIM_FreeAnim();
    walock[ANIM_TILE(ANIMnum)] = 1;
    }
示例#18
0
/* this here works on the users stack !! and only very few functions 
   are allowed                                                          */
VOID int21_syscall(iregs FAR * irp)
{
  Int21AX = irp->AX;

  switch (irp->AH)
  {
      /* DosVars - get/set dos variables                              */
    case 0x33:
      switch (irp->AL)
      {
          /* Get Ctrl-C flag                                      */
        case 0x00:
          irp->DL = break_ena ? TRUE : FALSE;
          break;

          /* Set Ctrl-C flag                                      */
        case 0x01:
          break_ena = irp->DL ? TRUE : FALSE;
          break;

          /* Get Boot Drive                                       */
        case 0x05:
          irp->DL = BootDrive;
          break;

          /* Get DOS-C version                                    */
        case 0x06:
          irp->BL = os_major;
          irp->BH = os_minor;
          irp->DL = rev_number;
          irp->DH = version_flags; /* bit3:runs in ROM,bit 4: runs in HMA*/
          break;
          
        case 0x02:  /* andrew schulman: get/set extended control break 
                       should be done */
        case 0x03:  /* DOS 7 does not set AL */
        case 0x07:  /* neither here */

        default:    /* set AL=0xFF as error, NOT carry */
          irp->AL  = 0xff;
          break;

          /* Toggle DOS-C rdwrblock trace dump                    */
        case 0xfd:
#ifdef DEBUG
          bDumpRdWrParms = !bDumpRdWrParms;
#endif
          break;

          /* Toggle DOS-C syscall trace dump                      */
        case 0xfe:
#ifdef DEBUG
          bDumpRegs = !bDumpRegs;
#endif
          break;

          /* Get DOS-C release string pointer                     */
        case 0xff:
          irp->DX = FP_SEG(os_release);
          irp->AX = FP_OFF(os_release);
          break;
      }
      break;

      /* Set PSP                                                      */
    case 0x50:
      cu_psp = irp->BX;
      break;

      /* Get PSP                                                      */
    case 0x51:
      irp->BX = cu_psp;
      break;

      /* UNDOCUMENTED: return current psp                             */
    case 0x62:
      irp->BX = cu_psp;
      break;

      /* Normal DOS function - DO NOT ARRIVE HERE          */
    default:
      break;
  }
}
示例#19
0
/**
 * Converts a segment:offset pair into a 32bit physical address.
 */
static uint32_t ahci_addr_to_phys(void __far *ptr)
{
    return ((uint32_t)FP_SEG(ptr) << 4) + FP_OFF(ptr);
}
示例#20
0
文件: c4_main.c 项目: NY00123/refkeen
void InitGame (void)
{
	//id0_unsigned_t	segstart,seglength;
	id0_int_t			i,x,y;
	id0_unsigned_t	*blockstart;

//	US_TextScreen();

	MM_Startup ();
	VW_Startup ();
#ifndef PROFILE
	IN_Startup ();
	SD_Startup ();
#endif
	US_Startup ();

//	US_UpdateTextScreen();

	CA_Startup ();
	US_Setup ();

	US_SetLoadSaveHooks(LoadTheGame,SaveTheGame,ResetGame);


//
// load in and lock down some basic chunks
//

	CA_ClearMarks ();

	CA_MarkGrChunk(STARTFONT);
	CA_MarkGrChunk(STARTTILE8);
	CA_MarkGrChunk(STARTTILE8M);
	CA_MarkGrChunk(HAND1PICM);

	CA_MarkGrChunk(NORTHICONSPR);
	CA_CacheMarks (NULL);

	MM_SetLock (&grsegs[STARTFONT],true);
	MM_SetLock (&grsegs[STARTTILE8],true);
	MM_SetLock (&grsegs[STARTTILE8M],true);
	MM_SetLock (&grsegs[HAND1PICM],true);

	fontcolor = WHITE;


//
// build some tables
//
	for (i=0;i<MAPSIZE;i++)
		nearmapylookup[i] = &tilemap[0][0]+MAPSIZE*i;

	for (i=0;i<PORTTILESHIGH;i++)
		uwidthtable[i] = UPDATEWIDE*i;

	blockstart = &blockstarts[0];
	for (y=0;y<UPDATEHIGH;y++)
		for (x=0;x<UPDATEWIDE;x++)
			*blockstart++ = SCREENWIDTH*16*y+x*TILEWIDTH;

	BuildTables ();			// 3-d tables

	SetupScaling ();

#ifndef PROFILE
//	US_FinishTextScreen();
#endif

#if 0
//
// reclaim the memory from the linked in text screen
//
	segstart = FP_SEG(&introscn);
	seglength = 4000/16;
	if (FP_OFF(&introscn))
	{
		segstart++;
		seglength--;
	}
	MML_UseSpace (segstart,seglength);
#endif

	VW_SetScreenMode (GRMODE);
	ge_textmode = false;
//	VW_ColorBorder (3);
	VW_ClearVideo (BLACK);

//
// initialize variables
//
	updateptr = &update[0];
	// REFKEEN - Safe unaligned accesses
	*(updateptr + UPDATEWIDE*PORTTILESHIGH) = 1;
	*(updateptr + UPDATEWIDE*PORTTILESHIGH + 1) = 3;
	//*(id0_unsigned_t *)(updateptr + UPDATEWIDE*PORTTILESHIGH) = UPDATETERMINATE;
	bufferofs = 0;
	displayofs = 0;
	VW_SetLineWidth(SCREENWIDTH);
}
示例#21
0
int GetCountryCode (void)
{
#if (DOSX & DJGPP)    /* _osmajor/_osminor not set in crt0.o */
  _get_dos_version (0);
#endif

  if (_osmajor >= 3)
  {
#if (DOSX & DJGPP)
    __dpmi_regs reg;

    reg.d.edx = 0;
    reg.x.ds  = __tb / 16;
    reg.d.eax = 0x3800;
    __dpmi_int (0x21, &reg);
    if (reg.x.flags & 1)
       return (0);
    dosmemget (__tb, sizeof(_country_info), &_country_info);
    return (reg.x.bx);

#elif (DOSX & PHARLAP)
    SWI_REGS reg;

    if (_watt_dosTbSize < sizeof(_country_info))
       return (0);

    reg.edx = RP_OFF (_watt_dosTbr);
    reg.ds  = RP_SEG (_watt_dosTbr);
    reg.eax = 0x3800;
    _dx_real_int (0x21, &reg);
    if (reg.flags & 1)
       return (0);
    ReadRealMem (&_country_info, _watt_dosTbr, sizeof(_country_info));
    return (reg.ebx);

#elif (DOSX & (DOS4GW|WDOSX))
    union  REGS  reg;
    struct SREGS sreg;

    if (_watt_dosTbSize < sizeof(_country_info))
       return (0);
 
    reg.x.edx = 0;
    sreg.ds   = _watt_dosTbSeg;
    reg.x.eax = 0x3800;
    int386x (0x21, &reg, &reg, &sreg);
    if (reg.x.cflag)
       return (0);
    memcpy (&_country_info, SEG_OFS_TO_LIN(_watt_dosTbSeg,0),
            sizeof(_country_info));
    return (reg.w.bx);

#elif (DOSX & POWERPAK)
    UNFINISED();

#elif (DOSX == 0)        /* real-mode */
    union  REGS  reg;
    struct SREGS sreg;
 
    reg.x.dx = FP_OFF (_country_info);
    sreg.ds  = FP_SEG (_country_info);
    reg.x.ax = 0x3800;
    int86x (0x21, &reg, &reg, &sreg);
    if (reg.x.cflag)
       return (0);
    return (reg.x.bx);

#else
  #error Unsupported target
#endif
  }
  return (0);
}
示例#22
0
文件: demo1.c 项目: joncampbell123/16
void main(){
  int  i, j, xinc, yinc, Margin;
  char ch;
  WORD curr_x=0, curr_y=0;

  pal    = (char far *) farmalloc(256*3);
  pal2   = (char far *) farmalloc(256*3);
  userfnt1 = (char far *) farmalloc(256*16+4);


  /* INITIALIZE XLIB */

  /* we set up Mode X 360x200x256 with a logical width of ~ 500 */
  /* pixels; we actually get 496 due to the fact that the width */
  /* must be divisible by 8                                     */

  x_text_mode(); /* make sure VGA is in color mode, if possible */
  x_set_mode(X_MODE_360x200,500);           /* actually is set to 496      */
  x_install_vsync_handler(2);
  x_set_splitscreen(ScrnPhysicalHeight-60); /* split screen 60 pixels high */
  x_set_doublebuffer(220);
  x_text_init();
  x_hide_splitscreen();
  x_mouse_init();
  MouseColor=2;
  atexit(exitfunc);

  /* DRAW BACKGROUND LINES */

  for(j=0;j<ScrnPhysicalHeight;j++){
   x_line(0,j,ScrnLogicalPixelWidth,j,16+(j%239),VisiblePageOffs);
  }

  ctrlbrk(terminate);
  x_get_pal_struc(pal, 240,16);
  load_user_fonts();

  intro_1();
  x_set_font(2);
  x_hide_mouse();
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Hi, folks. This is yet another FREEWARE Mode X");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " graphics library. It is by no means complete,");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " but I believe it contains a rich enough set of");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " functions to achieve its design goal - to be");
  x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " a game development oriented library for");
  x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Borland TC/BC/BC++ and TASM programmers.");

  x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, "   This library comes with TASM and C sources.");
  x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " It was inspired by the DDJ Graphics column and");
  x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " many INTERNET and USENET authors who, unlike the");
  x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " majority of programmers (you know who you are!),");
  x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " willingly share their code and ideas with others.");

  x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, "   I can't afford, nor do I want, to copyright");
  x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " this code - but if you use it, some credit would ");
  x_printf(textwindow_x+5,50+104,VisiblePageOffs,9," be appreciated. ");

  wait_for_keypress();

  subsequent_page();
  x_set_font(0);
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"Supported 256 colour resolutions.");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"Supported 256 colour resolutions.");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " 320x200   Standard for games       ~ 4 pages");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " 320x240   DDJ Mode X square pixels ~ 3.5 pages");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " 360x200   My favourite for games   ~ 3 pages  ");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " 360x240                            ~ 2.8 pages");
  x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " 320x400                            ~ 2 pages  ");
  x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " 320x480   All subsequent modes support");
  x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, " 360x400     less than two pages.");
  x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " 360x480");
  x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " 376x282,360x360,376x308,376x564,256x200,256x240");
  x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " Phew! and they'll run on all VGA cards and ");
  x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " monitors (some of the weird ones are best suited");
  x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, " to monitors with both vert & horiz adjustments)");
  x_printf(textwindow_x+5,50+98,VisiblePageOffs,2, "  ");
  x_printf(textwindow_x+5,50+106,VisiblePageOffs,2," Overkill? Maybe!! ");


  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"      Text display functions.");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"      Text display functions.");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Several text printing functions are provided.");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " They support the VGA ROM 8x14 and 8x8 fonts as");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " well as user-defined fonts (like this 6x8 font).");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " Furthermore, a function similar to printf is");
  x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " included which provides formatted text output.");
  x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " User defined fonts may be proportionally spaced");
  x_printf(textwindow_x+5,50+58,VisiblePageOffs,9, " but have a maximum width of 8 pixels.");


  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    Advanced screen functions.");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    Advanced screen functions.");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   The library supports virtual screens larger");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " than the physical screen, panning of such");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " screens, and a split screen option.");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, "   These functions can be used together or");
  x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " in isolation, and in the lower resolutions");
  x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " double buffering can also be accomplished.");

  x_rect_fill(0, 0, ScrnPhysicalPixelWidth,60,SplitScrnOffs,5);
  x_line(0,0,ScrnPhysicalPixelWidth,0,2,SplitScrnOffs);
  x_set_font(1);
  x_printf(10,10,SplitScrnOffs,2, " This is a split screen, tops for scores.");
  x_set_font(0);
  for (i=ScrnPhysicalHeight;i>ScrnPhysicalHeight-60;i--){
	x_adjust_splitscreen(i);
  }
  x_printf(10,25,SplitScrnOffs,2, " Even better for scrolling games etc.");

  x_cp_vid_rect(0,0,ScrnLogicalPixelWidth,ScrnLogicalHeight,0,0,
		VisiblePageOffs,HiddenPageOffs,
		ScrnLogicalPixelWidth,ScrnLogicalPixelWidth);


  x_show_mouse();
  wait_for_keypress();

  curr_x=curr_y=0;


  init_object(60,90,4, 12, -1, 1, MK_FP(FP_SEG(bm2),FP_OFF(bm2)));
  init_object(30,30,4, 12, 1, 1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  init_object(80,120,4, 12, 2, 1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  init_object(300,200,4, 12, 1, -2, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  init_object(360,30,4, 12, -1, -1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  init_object(360,10,4, 12, -2, 2, MK_FP(FP_SEG(bm),FP_OFF(bm)));

  x_hide_mouse();

  while (!kbhit()&& !(MouseButtonStatus==LEFT_PRESSED)){
	animate();
	if (objects[0].X>=curr_x+ScrnPhysicalPixelWidth-32 &&
	curr_x < MaxScrollX) curr_x++;
	else if (objects[0].X < curr_x+16 && curr_x > 0) curr_x--;
	if (objects[0].Y>=curr_y+ScrnPhysicalHeight-92 &&
	   curr_y < MaxScrollY) curr_y++;
	else if (objects[0].Y < curr_y+16 && curr_y > 0) curr_y--;
	x_page_flip(curr_x,curr_y);
	while(StartAddressFlag);
  }
  while(MouseButtonStatus==LEFT_PRESSED);
  while(kbhit()) getch();

  clear_objects();
  x_page_flip(curr_x,curr_y);
  while(StartAddressFlag);


  x_set_start_addr(0,0);


  for (j=0;j<4;j++){
	x_hide_splitscreen();
	delay(100);
	x_show_splitscreen();
	delay(100);
  }


  for (i=ScrnPhysicalHeight-60;i<=ScrnPhysicalHeight;i++){
	x_adjust_splitscreen(i);
  }

  x_hide_mouse();
  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"        Palette functions.");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"        Palette functions.");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   A number of palette manipulation functions");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " are provided. You have already seen some of");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " them in action. Another common operation is");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " palette fading.                     ");

  i=0;
  ch=255;
  while (x_cpcontrast_pal_struc(pal, pal2,ch-=2)){
	x_put_pal_struc(pal2);
	x_rot_pal_struc(pal,palscrolldir);
	i++;
  };
  for (j=0;j<i;j++){
	x_cpcontrast_pal_struc(pal, pal2,ch+=2);
	x_put_pal_struc(pal2);
	x_rot_pal_struc(pal,palscrolldir);
  };
  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 3.0 Functions!");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 3.0 Functions!");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - RLE data compression");
  x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, "  - FAST compiled masked bitmaps");
  x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, "  - Hardware detection");

  x_show_mouse();
  wait_for_keypress();

  x_hide_mouse();
  for (i = 0; i < 150; i++) {
	  x_circle(0, 0, i, 181 - i, VisiblePageOffs);
	  x_circle(360 - i, 0, i, i + 30, VisiblePageOffs);
	  x_circle(0, 200 - i, i, i + 30, VisiblePageOffs);
	  x_circle(360 - i, 200 - i, i, 181 - i, VisiblePageOffs);
  }
  for (i = 0; i < 100; i++)
	x_filled_circle(80 + i, i, 201 - (i << 1), 30+i, VisiblePageOffs);
  x_show_mouse();
  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 4.0 Functions!");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 4.0 Functions!");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - FAST VRAM-based masked bitmaps, including");
  x_printf(textwindow_x+5,50+18,VisiblePageOffs,9, "      support for clipping regions");
  x_printf(textwindow_x+5,50+28,VisiblePageOffs,9, "  - Faster, smaller compiled bitmaps");
  x_printf(textwindow_x+5,50+38,VisiblePageOffs,9, "  - Improved planar bitmap performance and");
  x_printf(textwindow_x+5,50+46,VisiblePageOffs,9, "      additional support for clipping");
  x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, "  - mouse module");
  x_printf(textwindow_x+5,50+66,VisiblePageOffs,9, "  - Detection of math co-processor and mouse");
  x_printf(textwindow_x+5,50+76,VisiblePageOffs,9, "  - Bezier curve module");
  x_printf(textwindow_x+5,50+86,VisiblePageOffs,9, "  - Four new resolutions, including one with");
  x_printf(textwindow_x+5,50+94,VisiblePageOffs,9, "      square pixels (376x282)");
  x_printf(textwindow_x+5,50+104,VisiblePageOffs,9, "  - More bug fixes");

  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 5.0 Functions!");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 5.0 Functions!");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " - *FAST* filled and clipped triangles ideal for");
  x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "   3D work. Thanks to S. Dollins for the code.");
  x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Filled and clipped polygons, C++ Compatible");
  x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - header files, and of course bug fixes!");

  x_show_mouse();
  wait_for_keypress();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 6.0 Functions!");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 6.0 Functions!");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " - Fast flood filling functions ");
  x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, " - New pbm flipping put functions.");
  x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Timer synchronized vertical retrace");
  x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - Tripple buffering extensions");
  x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Checkout demo 9 and 10 for previews");
  


  x_show_mouse();
  wait_for_keypress();


  randomize();
  x_hide_mouse();
  while(kbhit()) getch();
  palscrolldir^=1;
  do {
	int x0,x1,x2,y0,y1,y2,i;
	i=random(256);
	x0=random(ScrnLogicalPixelWidth);
	x1=random(ScrnLogicalPixelWidth);
	x2=random(ScrnLogicalPixelWidth);
	y0=random(ScrnPhysicalHeight);
	y1=random(ScrnPhysicalHeight);
	y2=random(ScrnPhysicalHeight);
	x_triangle(x0,y0,x1,y1,x2,y2,i,VisiblePageOffs);
  } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED));
  while(MouseButtonStatus==LEFT_PRESSED);
  while(kbhit()) getch();
  x_show_mouse();

  subsequent_page();
  x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"             PLEASE...");
  x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"             PLEASE...");
  x_set_font(2);
  x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Please mention my name in programs that use XLIB");
  x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " just to make me feel it was worth the effort.");
  x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " If you have any bug to report please feel free to");
  x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " mail me a message. Any hints, suggestions and");
  x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " contributions are welcome and encouraged.");
  x_printf(textwindow_x+5,50+52,VisiblePageOffs,9, " I have contributed this code to the public domain.");
  x_printf(textwindow_x+5,50+60,VisiblePageOffs,9, "    Please respect my wishes and leave it there.");

  x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, "   Finally, I hope you all find this stuff useful,");
  x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " Themie Gouthas - [email protected]");

  wait_for_keypress();

  x_hide_mouse();

  x_shift_rect (27, 27, 360-27, 177, 27, 23, VisiblePageOffs);
  x_rect_fill(25, 173, 335, 176, VisiblePageOffs, 1);
  for (i = 0; i < 50; i++) {
	x_shift_rect (27, 26, 360-27, 177 - (i * 3), 27, 23, VisiblePageOffs);
  }
}
示例#23
0
void main()
{
int *base,*dir;
int a[4][4][4],m3,y,y1,m2,col1,s1;
int lit,lst,lif,lsf,m1,lic,lsc,col,n,k,m,sum[10],s,i,j;
gotoxy(14,3);
printf("ingrese el número de filas de la matriz : ");
do{
scanf("%d",&n);
}while (n<=0);
gotoxy(14,5);
printf("ingrese el número de columnas de la matriz : ");
do{
scanf("%d",&m);
}while (m<=0);
gotoxy(14,7);
printf("ingrese el número de altura de la matriz : ");
do{
scanf("%d",&y);
}while (y<=0);
gotoxy(14,9);
printf ("ingrese los límites inferiores : ");
do{
scanf ("%d",&lif);
}while (lif<0);
lic=lif;
lit=lif;
m1=4-y;
m2=4-m;
//m3=m2+m;
// límites
lsf=lif+n-1;
lsc=lic+m-1;
lst=lit+y-1;
s=(lsc-lic+1+m2);
s1=(lst-lit+1+m1)*s;
//matriz
for (i=lif;i<=lsf;i++){
  for (j=lic;j<=lsc;j++){
     for (k=lit;k<=lst;k++){
     printf("a[%d][%d][%d]=",i,j,k);
     scanf("%d",&a[i][j][k]);
     dir=&a[i][j][k];
   }
}
}
// función de direccionamiento 

base=&a[lif][lic][lit];
printf("\n visualización de la matriz usando funciones de acceso\n");
     for(i=lif;i<=lsf;i++){
       col=(i-lif)*s1;
       for (j=lic;j<=lsc;j++){
          col1=(j-lic)*s;
	for (k=lit;k<=lst;k++){
	  dir=base+col+col1+(k-lit);
          printf("a[%d][%d][%d]=%d   ",i,j,k,*dir);
	  printf("dirección=%04x:%04x\n",FP_SEG(dir),FP_OFF(dir));
	}              
     }
     }

    }
示例#24
0
////////////////////////////////////////////////////////////////////////////
//
// LoadLIBShape()
//
int LoadLIBShape(char *SLIB_Filename, char *Filename,struct Shape *SHP)
{
	#define CHUNK(Name)	(*ptr == *Name) &&			\
								(*(ptr+1) == *(Name+1)) &&	\
								(*(ptr+2) == *(Name+2)) &&	\
								(*(ptr+3) == *(Name+3))


	int RT_CODE;
	FILE *fp;
	char CHUNK[5];
	char far *ptr;
	memptr IFFfile = NULL;
	unsigned long FileLen, size, ChunkLen;
	int loop;


	RT_CODE = 1;

	// Decompress to ram and return ptr to data and return len of data in
	//	passed variable...

	if (!LoadLIBFile(SLIB_Filename,Filename,&IFFfile))
		TrashProg("Error Loading Compressed lib shape!");

	// Evaluate the file
	//
	ptr = MK_FP(IFFfile,0);
	if (!CHUNK("FORM"))
		goto EXIT_FUNC;
	ptr += 4;

	FileLen = *(long far *)ptr;
	SwapLong((long far *)&FileLen);
	ptr += 4;

	if (!CHUNK("ILBM"))
		goto EXIT_FUNC;
	ptr += 4;

	FileLen += 4;
	while (FileLen)
	{
		ChunkLen = *(long far *)(ptr+4);
		SwapLong((long far *)&ChunkLen);
		ChunkLen = (ChunkLen+1) & 0xFFFFFFFE;

		if (CHUNK("BMHD"))
		{
			ptr += 8;
			SHP->bmHdr.w = ((struct BitMapHeader far *)ptr)->w;
			SHP->bmHdr.h = ((struct BitMapHeader far *)ptr)->h;
			SHP->bmHdr.x = ((struct BitMapHeader far *)ptr)->x;
			SHP->bmHdr.y = ((struct BitMapHeader far *)ptr)->y;
			SHP->bmHdr.d = ((struct BitMapHeader far *)ptr)->d;
			SHP->bmHdr.trans = ((struct BitMapHeader far *)ptr)->trans;
			SHP->bmHdr.comp = ((struct BitMapHeader far *)ptr)->comp;
			SHP->bmHdr.pad = ((struct BitMapHeader far *)ptr)->pad;
			SwapWord(&SHP->bmHdr.w);
			SwapWord(&SHP->bmHdr.h);
			SwapWord(&SHP->bmHdr.x);
			SwapWord(&SHP->bmHdr.y);
			ptr += ChunkLen;
		}
		else
		if (CHUNK("BODY"))
		{
			ptr += 4;
			size = *((long far *)ptr);
			ptr += 4;
			SwapLong((long far *)&size);
			SHP->BPR = (SHP->bmHdr.w+7) >> 3;
			MM_GetPtr(&SHP->Data,size);
			if (!SHP->Data)
				goto EXIT_FUNC;
			movedata(FP_SEG(ptr),FP_OFF(ptr),FP_SEG(SHP->Data),0,size);
			ptr += ChunkLen;

			break;
		}
		else
/*inicializar el pcb*/
void initPCB(...)
{
	//Inicializa el primer nodo del PCB
	pcb[0].offset = FP_OFF(processA);
	pcb[0].quantum = quantum;
	pcb[0].id = 'A';
	pcb[0].status = 1;
	pcb[0].stcPtr = 0;
	
	//Inicializa el segundo nodo del PCB
	pcb[1].offset = FP_OFF(processB);
	pcb[1].quantum = quantum;
	pcb[1].id = 'B';
	pcb[1].status = 2;
	
	//Guarda el SP de nuestro programa
	asm mov stackPointer,sp
	stackPointerAux = stackPointer;
	
	//Realiza un corrimiento en la pila para el primer proceso
	stackPointerAux = stackPointerAux - 512;
	indexOffset = pcb[1].offset; //Direccion del proceso i
	
	//Guarda todo el contexto del proceso 1
	asm {
		mov SP, stackPointerAux
		pushf
		push cs
		push indexOffset
		push ax
		push bx
		push cx
		push dx
		push es
		push ds
		push si
		push di
		push bp
		mov stackPointerAux, SP
		mov SP, stackPointer
	};
	//Guarda en el PCB el SP donde se encuentran el contexto del proceso
	pcb[1].stcPtr = stackPointerAux;
	
	indexProcess = 0;
	quantumProcess =pcb[indexProcess].quantum;
}

/*Procemiento que reemplaza la interrupcion del timer con nuestro
codigo fuente.*/
void main()
{
	clrscr();
	initPCB();
	prev=getvect(8);	//Guarda la interrupci¢n antigua del timer
	setvect(8,myTimer);	//Inserta con nuestro c¢digo la interrupcion del time
	actualProcess = 1;
	processA();
	clrscr();
	while(1)
	{}
}
示例#26
0
void load_proc() { 
	//Creates Process1 that contains the test process test1_R3 then adds it to the ready readyQueue
	if (findPCB("Process1")==NULL){
		COP = setupPCB("Process1", 1 ,0); 
		aContext = (context*)COP -> stack;
		aContext -> IP = FP_OFF(&test1_R3);
		aContext -> CS = FP_SEG(&test1_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process1 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process1' is already in system\n");	
	}
	//Creates Process2 that contains the test process test2_R3 then adds it to the ready readyQueue
	if(findPCB("Process2")==NULL){
		COP = setupPCB("Process2", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test2_R3);
		aContext -> CS = FP_SEG(&test2_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP); 
		print("Process2 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process2' is already in system\n");	
	}
	
	//Creates Process3 that contains the test process test3_R3 then adds it to the ready readyQueue
	if(findPCB("Process3")==NULL){
		COP = setupPCB("Process3", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test3_R3);
		aContext -> CS = FP_SEG(&test3_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process3 is now Loaded!\n");		
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process3' is already in system\n");	
	}
	
	//Creates Process4 that contains the test process test4_R3 then adds it to the ready readyQueue
	if(findPCB("Process4")==NULL){
	COP = setupPCB("Process4", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test4_R3);
		aContext -> CS = FP_SEG(&test4_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP); 
		print("Process4 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process4' is already in system\n");	
	}
	
	//Creates Process5 that contains the test process test5_R3 then adds it to the ready readyQueue
	if(findPCB("Process5")==NULL){
		COP = setupPCB("Process5", 1 ,0); 
		aContext = COP -> stack;
		aContext -> IP = FP_OFF(&test5_R3);
		aContext -> CS = FP_SEG(&test5_R3);
		aContext -> FLAGS = 0x200;
		aContext -> DS = _DS;
		aContext -> ES = _ES;
		PriorityEnqueue(readyQueue, COP);
		print("Process5 is now Loaded!\n");
	}else{
		//Error PCB is already in system
		print("Error: PCB with the name 'Process5' is already in system\n");
		
	}
 }
示例#27
0
文件: bsdname.c 项目: basecq/q2dos
/**
 * Try asking a LAN extension of DOS for a host-name.
 */
int _get_machine_name (char *buf, int size)
{
  IREGS reg;
  char *h;
  char  dosBuf[16];
  int   len;

  memset (&reg, 0, sizeof(reg));
  reg.r_ax = 0x5E00;

#if (DOSX & DJGPP)
  if (_go32_info_block.size_of_transfer_buffer < sizeof(dosBuf))
     return (-1);
  reg.r_ds = __tb / 16;
  reg.r_dx = __tb & 15;

#elif (DOSX & (PHARLAP|X32VM|POWERPAK))
  if (_watt_dosTbSize < sizeof(dosBuf) || !_watt_dosTbr)
     return (-1);
  reg.r_ds = RP_SEG (_watt_dosTbr);
  reg.r_dx = RP_OFF (_watt_dosTbr);

#elif (DOSX & DOS4GW)
  if (_watt_dosTbSize < sizeof(dosBuf) || !_watt_dosTbSeg)
     return (-1);
  reg.r_ds = _watt_dosTbSeg;
  reg.r_dx = 0;

#elif (DOSX == 0)
  reg.r_ds = FP_SEG (dosBuf);
  reg.r_dx = FP_OFF (dosBuf);

#else
  #error Help me!
#endif

  GEN_INTERRUPT (0x21, &reg);
  if ((reg.r_flags & CARRY_BIT) || hiBYTE(reg.r_cx) == 0)
     return (-1);

#if (DOSX & DJGPP)
  dosmemget (__tb, sizeof(dosBuf), dosBuf);

#elif (DOSX & (PHARLAP|X32VM|POWERPAK))
  ReadRealMem ((void*)&dosBuf, _watt_dosTbr, sizeof(dosBuf));

#elif (DOSX & DOS4GW)
  memcpy (dosBuf, SEG_OFS_TO_LIN(_watt_dosTbSeg,0), sizeof(dosBuf));
#endif

  /* Remove right space padding
   */
  h = dosBuf + min (strlen(dosBuf), sizeof(dosBuf)-1);
  while (h > dosBuf && h[-1] == ' ')
        h--;

  *h  = '\0';
  h   = dosBuf;
  len = strlen (h);
  if (len + 1 > size)
  {
    SOCK_ERRNO (ERANGE);
    return (-1);
  }
  strcpy (buf, h);
  strlwr (buf);
  return (0);
}
示例#28
0
/* See header file for description. */
portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
{
portSTACK_TYPE DS_Reg = 0, *pxOriginalSP;

	/* Place a few bytes of known values on the bottom of the stack. 
	This is just useful for debugging. */

	*pxTopOfStack = 0x1111;
	pxTopOfStack--;
	*pxTopOfStack = 0x2222;
	pxTopOfStack--;
	*pxTopOfStack = 0x3333;
	pxTopOfStack--;
	*pxTopOfStack = 0x4444;
	pxTopOfStack--;
	*pxTopOfStack = 0x5555;
	pxTopOfStack--;


	/*lint -e950 -e611 -e923 Lint doesn't like this much - but nothing I can do about it. */

	/* We are going to start the scheduler using a return from interrupt
	instruction to load the program counter, so first there would be the
	status register and interrupt return address.  We make this the start 
	of the task. */
	*pxTopOfStack = portINITIAL_SW; 
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pxCode );
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxCode );
	pxTopOfStack--;

	/* We are going to setup the stack for the new task to look like
	the stack frame was setup by a compiler generated ISR.  We need to know
	the address of the existing stack top to place in the SP register within
	the stack frame.  pxOriginalSP holds SP before (simulated) pusha was 
	called. */
	pxOriginalSP = pxTopOfStack;

	/* The remaining registers would be pushed on the stack by our context 
	switch function.  These are loaded with values simply to make debugging
	easier. */
	*pxTopOfStack = FP_OFF( pvParameters );		/* AX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xCCCC;	/* CX */
	pxTopOfStack--;
	*pxTopOfStack = FP_SEG( pvParameters );		/* DX */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;	/* BX */
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pxOriginalSP );		/* SP */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xBBBB;	/* BP */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0x0123;	/* SI */
	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xDDDD;	/* DI */

	/* We need the true data segment. */
	__asm{	MOV DS_Reg, DS };

	pxTopOfStack--;
	*pxTopOfStack = DS_Reg;	/* DS */

	pxTopOfStack--;
	*pxTopOfStack = ( portSTACK_TYPE ) 0xEEEE;	/* ES */

	/* The AX register is pushed again twice - don't know why. */
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pvParameters );		/* AX */
	pxTopOfStack--;
	*pxTopOfStack = FP_OFF( pvParameters );		/* AX */


	#ifdef DEBUG_BUILD
		/* The compiler adds space to each ISR stack if building to
		include debug information.  Presumably this is used by the
		debugger - we don't need to initialise it to anything just
		make sure it is there. */
		pxTopOfStack--;
	#endif

	/*lint +e950 +e611 +e923 */

	return pxTopOfStack;
}
示例#29
0
int _OS2Main( char _WCI86FAR *stklow, char _WCI86FAR *stktop,
                        unsigned envseg, unsigned cmdoff )
/***********************************************************/
{
    USHORT      shftval;

    cmdoff = cmdoff;    /* supress warnings */
    envseg = envseg;
    stktop = stktop;

    /* set up global variables */
#if defined(__SW_BD)
    _STACKTOP = 0;
    _curbrk = _dynend = (unsigned)&end;
    stklow = NULL;
#else
    _STACKTOP = FP_OFF( stktop );
    _curbrk = _dynend = _STACKTOP;
#endif
    DosGetHugeShift( (PUSHORT)&shftval );
    _HShift = shftval;
    DosGetMachineMode( (PBYTE)&_osmode );
    {
        unsigned short      version;
    
        DosGetVersion( (PUSHORT)&version );
        _RWD_osmajor = version >> 8;
        _RWD_osminor = version & 0xff;
    }

#if defined(__SW_BD)
    _LpPgmName = "";
    _LpCmdLine = "";
#else
    /* copy progname and arguments to bottom of stack */
    {
        char    _WCI86FAR *src;
        char    _WCI86FAR *pgmp;
    
        src = MK_FP( envseg, cmdoff );
        _LpPgmName = stklow;
        /* back up from the ao: pointer to the eo: pointer (see OS/2 2.0 docs)*/
        for( pgmp = src - 1; *--pgmp != '\0'; )
            ;
        ++pgmp;
        while( *stklow++ = *pgmp++ )
            ;
        while( *src )
            ++src;
        ++src;
        _LpCmdLine = stklow;
        while( *stklow++ = *src++ ) {
            ;
        }
    }
#endif

#if defined( __MT__ )
    {
        SEL             globalseg;
        SEL             localseg;

        DosGetInfoSeg( &globalseg, &localseg );
        _threadid = MK_FP( localseg, offsetof( LINFOSEG, tidCurrent ) );
        if( __InitThreadProcessing() == NULL )
            __fatal_runtime_error( "Not enough memory", 1 );
    #if defined(__SW_BD)
        {
            unsigned    i;
            unsigned    j;
            j = __MaxThreads;
            for( i = 1; i <= j; i++ ) {
                __SetupThreadProcessing( i );
            }
        }
    #else
        __SetupThreadProcessing( 1 );
    #endif
        _STACKLOW = (unsigned)stklow;
    }
#else
    _nothread = getpid();
    _threadid = &_nothread;
    _STACKLOW = (unsigned)stklow; /* set bottom of stack */
#endif
//  {   /* removed JBS 99/11/10 */
//      // make sure the iomode array is of the proper length
//      // this needs to be done before the InitRtns
//      extern  void    __grow_iomode(int);

//      if( _RWD_osmode == OS2_MODE ) {
//          __grow_iomode( 100 );
//      }
//  }
    __InitRtns( 255 );
#ifdef __SW_BD
    {
        int status;
        status = setjmp( JmpBuff );
        if( status == 0 )
            return( _CMain() );
        return( RetCode );
    }
#else
    _CMain();   // this doesn't return, following line quiet compiler only
    return( EXIT_FAILURE );
#endif
}