Example #1
0
int main(void) {
    float *a = createvect(NUM),
           *b = createvect(NUM);

    // incrementing up to 20
    setvect(NUM, a, 1);
    basicIncrement(NUM, a);
    printf("0: a = ");
    printvect(NUM, a);
    printf("\n");

    // nested while loop
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    nested(NUM, a, b);
    printf("1: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // nested while loop
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    nested2(NUM, a, b);
    printf("2: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // a and b changing relative to each other
    setvect(NUM, a, 1);
    setvect(NUM, b, 2);
    relativeChange(NUM, a, b);
    printf("3: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // while with an if loop inside it
    setvect(NUM, a, 1);
    setvect(NUM, b, 3);
    whileIf(NUM, a, b);
    printf("4: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // if with a while loop inside it
    setvect(NUM, a, 1);
    setvect(NUM, b, 0);
    ifWhile(NUM, a, b);
    printf("5: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    // else in big if else statement
    setvect(NUM, a, 1);
    setvect(NUM, b, 4);
    ifWhile(NUM, a, b);
    printf("6: a = ");
    printvect(NUM, a);
    printf("\n");
    printf("   b = ");
    printvect(NUM, b);
    printf("\n");

    return 0;
}
Example #2
0
void backgroundon( void )
{
    oldinterrupt = getvect( 0x08 );
    setvect( 0x08, newinterrupt );
}
Example #3
0
void
jabunhack(void)
{
	setvect(MyInterrupt,oldintaddr);
}
Example #4
0
 void backgroundoff (void)
 {
   setvect (TIMER_INTR, oldinterrupt);
 }
Example #5
0
Int11trap::Int11trap()
{
    oldHandler = getvect( 0x11 );
    setvect( 0x11, &Int11trap::handler );
}
Example #6
0
File: ibmpc.c Project: hankem/jed
void init_int9_handler(void) /*{{{*/
{
   oldint9 = getvect(9);
   setvect(9, int9_handler);
}
/*inicializar el pcb*/
void initPCB(...)

{

	//Inicializa el primer nodo del PCB
	pcb[0].offset = FP_OFF(filosofo1);
	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(filosofo2);
	pcb[1].quantum = quantum;
	pcb[1].id = 'B';
	pcb[1].status = 2;

	//Inicializa el tercer nodo del PCB
	pcb[2].offset = FP_OFF(filosofo3);
	pcb[2].quantum = quantum;
	pcb[2].id = 'C';
	pcb[2].status = 2;

	//Inicializa el cuarto nodo del PCB
	pcb[3].offset = FP_OFF(filosofo4);
	pcb[3].quantum = quantum;
	pcb[3].id = 'D';
	pcb[3].status = 2;

	//Inicializa el quinto nodo del PCB
	pcb[4].offset = FP_OFF(filosofo5);
	pcb[4].quantum = quantum;
	pcb[4].id = 'D';
	pcb[4].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;

	//Realiza un corrimiento en la pila para el segundo proceso
	stackPointerAux = stackPointerAux - 1024;
	indexOffset = pcb[2].offset;

	//Guarda todo el contexto del proceso 2
	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[2].stcPtr = stackPointerAux;

	//Realiza un corrimiento en la pila para el tercer proceso

	stackPointerAux = stackPointerAux - 1536;
	indexOffset = pcb[3].offset;

	//Guarda todo el contexto del proceso 3
	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[3].stcPtr = stackPointerAux;
	
	//Realiza un corrimiento en la pila para el tercer proceso

	stackPointerAux = stackPointerAux - 2048;
	indexOffset = pcb[4].offset;
	
	//Guarda todo el contexto del proceso 3
	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
	};
	pcb[4].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
	filosofo1();
	clrscr();
	while(1)
	{}
}
/*Codigo fuente de nuestra interrupcion del timer*/
void interrupt myTimer(...)
{
	disable();		//Apaga las demás interrupciones
	(*prev)();		//Llama al antiguo c¢digo de interrupcion
	//Espera una tecla y verifica si es la tecla Enter
	if(kbhit()  && getch() == 0xD)
	{
		//Devuelve la interrupción original
		setvect(8,prev);
		exit(0);
	}
	if (quantumProcess > 0 && pcb[indexProcess].status == 1)
	{
		quantumProcess--;
	}
	else
	{
		if ( pcb[indexProcess].status == 1)
		{
			pcb[indexProcess].status = 2;
		}
		//Salva el SP del proceso que se quedo sin quantum
		asm mov stackPointer, SP
		pcb[indexProcess].stcPtr = stackPointer;
		indexProcess = (indexProcess + 1) % N;
		stackPointer = pcb[indexProcess].stcPtr;
		quantumProcess = pcb[indexProcess].quantum;
		if(pcb[indexProcess].status == 2)
		{
			pcb[indexProcess].status = 1;
		}
		//Mueve el SP a donde esta el contexto del nuevo proceso que va ejecutar
		asm mov sp,stackPointer
		//Cambio de proceso.
		f = 0;
		mutex = 1;
	}
	enable(); //Activa las demás interrupciones
}
/*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)
	{}
}
Example #9
0
void main ( int argc , char **argv )
{
#define QTD_MPRINC 8
#define QTD_MSECUN 4
   char *opcao1[8] = { "Configuracao","Calibrar Sistema","Dados do Paciente",
		               "Ventilacao Voluntaria Maxima","Espirometria Forcada",
		               "Capacidade Vital Lenta","Resultados","Terminar" };
   char *opcao2[4] = { "Visualizar","Imprimir","Arquivo","Retornar"};


	int	exit = FALSE;
	extern int GlobOffSetP;

	if (argc > 1 && strcmp ( strupr ( argv[1] ) , "-V1" ) == 0)
/* sem correcao de BTPS */
		Versao = 1, --argc, ++argv;

	else if (argc > 1 && strcmp ( strupr ( argv[1] ) , "-V2" ) == 0)
/* com correcao para ar expirado */
		Versao = 2, --argc, ++argv;

	else if (argc > 1 && strcmp ( strupr ( argv[1] ) , "-V3" ) == 0)
/* com correcao para ar ambiente a 37 graus */
		Versao = 3, --argc, ++argv;

	else /* Nao escolheu nenhuma versao, assume -V2 */
		Versao = 2;

	if (argc > 1)
		GlobOffSetP = atoi(argv[1]);
	else
		GlobOffSetP = 4;

/*	printf( "Usando OffsetP==%d\n", GlobOffSetP );
	getchar();                                               */

#if defined(ENT_ARQ) || defined(ENT_ARQ_R)
	strcpy ( NomeCurva , argv[1] );
#endif

	_control87 ( MCW_EM  ,  MCW_EM );

#ifdef LINX
   vetor = getvect(0x1c);
   setvect(0x1c,TrataInterrup); /* seta a Interrupcao 11 do vetor para a funcao a*/
#endif

#ifdef PLACA12
	setvect ( 10  ,  TrataInterrup );
#else
	setvect ( 11  ,  TrataInterrup );
#endif
	LeCoef ();             /* le coeficientes */

/*	*ApontEspirometria = NULL;
	*ApontVVM = NULL;
	*ApontFluxPreBD = NULL;
	*ApontFluxPosBD = NULL;
*/
	RegistroTimer();
	LeData ();
	ModoGrafico ();
   Chama_Padrao();  /* pega valores default de cor,laudo,pereira,impressora */
	do{
		if (limpar) LimpaTela ();
		LimpaBufferTeclado ();
		InitialScreen();
		switch (menu(MENUPRINCIPAL,QTD_MPRINC,opcao1)) {
		  case 0 : Padrao();
			 limpar=TRUE;
			 break;

			case 1 : if(GanhoOk) LiberaAreas();
				  Calibragem ();
				 if(GanhoOk) ReservaAreas ();
				limpar = TRUE;
				break;
			case 2 :if(GanhoOk){
				DadosPaciente ();
				limpar = TRUE; }
				break;
			case 3 :
				if (GanhoOk && DadosPacienteOk)
					{
					VentVol ();
					limpar = TRUE;
					}
				else
					limpar = FALSE;
				break;
			case 4 :
#if !defined(ENT_ARQ) && !defined(ENT_ARQ_R)
				if ((GanhoOk && DadosPacienteOk) || (Versao == 3))
					{
#endif
					FluxVol ();
#if !defined(ENT_ARQ) && !defined(ENT_ARQ_R)
					limpar = TRUE;
					}
				else
					limpar = FALSE;
#endif
				break;
			case 5 :
			  if (GanhoOk && DadosPacienteOk)
			   {
                            setviewport ( 0 , 0 , 719 , 347 , 1 );
			    gprintf(585,280,"Ar Residual ? (S/N)");
			    do{
			       LEITURA('c',683,280,Resp,1,0,0);
			    }while(!pertence(*Resp,"SsNn"));
			    if(pertence(*Resp,"Ss")) {
			      VAR_RESP=TRUE;
			      Volume_de_ar_residual();
			    }
			    else  VAR_RESP=FALSE;
			    Espirometria ();
			    limpar = TRUE;
			    }
			    else
			    limpar = FALSE;
			    break;
			case 6 :if ((DadosPacienteOk || OK) && GanhoOk){
				switch(menu(MENUSECUNDARIO,QTD_MSECUN,opcao2)){
				 case SALVAR: Arquivar();
					      break;

				 case IMPRIMIR:	if (DadosPacienteOk)
					Impressao(1);
					break;

				 case VISUALIZAR:if (DadosPacienteOk)
					Impressao(0);
					break;

				 case 27:
				 case  3: break;
				/* case 9: chama_help(002);  break;*/
				}
				limpar=TRUE;
			}
				else limpar=FALSE;
				break;

		/*case 9: chama_help(002);  break;*/
			case 7:
				exit = TRUE;
			break;
			}
		}
	while (!exit);
	closegraph ();
	LiberaAreas ();
	}
Example #10
0
void
restore_kbd(void)
{
	setvect(KBD_INT, old_kbd);
}
/*Codigo fuente de nuestra interrupcion del timer*/
void interrupt myTimer(...)
{
	disable();		//Apaga las demás interrupciones
	(*prev)();		//Llama al antiguo c¢digo de interrupcion
	//Espera una tecla y verifica si es la tecla Enter
	if(kbhit()  && getch() == 0xD)
	{
		//Devuelve la interrupción original
		setvect(8,prev);
		exit(0);
	}
	if (quantumProcess > 0)
	{
		//Si el proceso aun  tiene quantum lo disminuye.
		quantumProcess--;
	}
	else
	{
		//Salva el SP del proceso que se quedo sin quantum
		asm mov  stackPointer, SP
		pcb[indexProcess].stcPtr = stackPointer;
		if (pcb[indexProcess].status == 1)
		{
			pcb[indexProcess].status = 2;
		}
		//copia el valor que posee el quantum del proceso actual
		int q = pcb[indexProcess].quantum;
		if (q > 20)
		{ 
			//Si el quantum del proceso es mayor a 20 reinicia el quantum en su valor original
			q = quantum;
		}
		else
		{
			/*Si el quantum del proceso actual no es mayor a 20 le aumenta uno para que a la siguiente ejecución
			tenga un tick de reloj más*/
			q++;
		}
		//Asigna el nuevo quantum al proceso.
		pcb[indexProcess].quantum = q;
		//Cambio de proceso.
		indexAux = indexProcess;
		indexProcess++;
		indexProcess = indexProcess % 2;
		if (pcb[indexProcess].status != 2)
		{
			indexProcess++;
			indexProcess = indexProcess % 2;
		}
		//Guarda el quantum del nuevo proceso.
		quantumProcess = pcb[indexProcess].quantum;

		//revisa que no se repita el proceso que se acaba de quedar sin quantum
		if (indexAux != indexProcess)
		{
			//Le indica que el nuevo proceso va estar en estado ejecutado.
			pcb[indexProcess].status = 1;
			stackPointer = pcb[indexProcess].stcPtr;
			//Mueve el SP a donde esta el contexto del nuevo proceso que va ejecutar
			asm mov sp,stackPointer
		}
	}
IVTEntry::~IVTEntry(){
	setvect(ivtNo, old);
	//arr[ivtNo] = NULL;
	(*old)();
}
IVTEntry::IVTEntry(IVTNo ivtNo, pointerInterrupt newInterrupt):ivtNo(ivtNo){
	old = getvect(ivtNo);
	setvect(ivtNo, newInterrupt);
}
Example #14
0
int OpenComPort(
    char Port)
{       /* install int. handler */
    unsigned status;
    int retval = -1;

    /* allocate input and output queues */

    Serial_In_Queue = alloc_queue(SerInBufSize);
    if ((QUEUE *) 0 == Serial_In_Queue)
        return retval;
    Serial_Out_Queue = alloc_queue(SerOutBufSize);
    if ((QUEUE *) 0 == Serial_Out_Queue) {
        free(Serial_In_Queue);
        return retval;
    }
    retval = 0;

    /* Setup Comm base port address and IRQ number */

    switch (Port) {
        case '1':
            ComBase = 0x3F8;
            IrqNum = 4;
            break;
        case '2':
            ComBase = 0x2F8;
            IrqNum = 3;
            break;
        case '3':
            ComBase = 0x3E8;
            IrqNum = 4;
            break;
        case '4':
            ComBase = 0x2E8;
            IrqNum = 3;
            break;
        default:
            ComBase = 0x3F8;
            IrqNum = 4;
            break;
    }
    old_comm_params.int_enable = inp(ComBase + INT_EN);
    outp(ComBase + INT_EN, 0);  /* turn off comm interrupts */

    /* save old comm parameters */

    old_comm_params.line = inp(ComBase + LINE_CNTRL);
    old_comm_params.modem = inp(ComBase + MODEM_CNTRL);
    status = inp(ComBase + LINE_CNTRL);
    outp(ComBase + LINE_CNTRL, (unsigned char) status | 0x80);
    old_comm_params.baud_lsb = inp(ComBase + BAUD_LSB);
    old_comm_params.baud_msb = inp(ComBase + BAUD_MSB);
    status = inp(ComBase + LINE_CNTRL);
    outp(ComBase + LINE_CNTRL, (unsigned char) status | 0x7F);
    status = OUT2 | DTR;        /* DTR/OUT2 must be set! */
    outp(ComBase + MODEM_CNTRL, (unsigned char) status);

    /* get serial port address/vector */

    oldvector_serial = (void (INTERRUPT FAR *) (void)) getvect(IrqNum + 8);

    /* set our interrupt handler */

    setvect(IrqNum + 8, serial);

    /* save the PIC */

    old_comm_params.int_cntrl = inp(0x21);
    status = (1 << IrqNum);     /* calculate int enable bit */
    status = ~status;

    /* ok enable comm ints */

    outp(0x21,
        (unsigned char) old_comm_params.int_cntrl & (unsigned char) status);

    atexit(CloseComPort);

    return retval;
}
Example #15
0
int main(int argc, char *argv[])
{
    char ans[2];
    char *fileargs[64];
    char *optargs[64];
    int n_options;
    int index;
    int help_flag = 0;

#ifdef __TURBOC__
    setvect(0x23, ctrlc_hndlr);
#else
    _dos_setvect(0x23, ctrlc_hndlr);
#endif
    atexit(on_exit);
    n_options = classify_args(argc, argv, fileargs, optargs);
    for (index=0;index<n_options;index++)
        {
        if (optargs[index][0] == '?') help_flag=1;
        else
            {
            myprintf("Invalid parameter - /",0);
            myprintf(optargs[index],0); /* removed strupr */
            myprintf("\r\n",0);
            exit(1);
            } /* end else. */

        } /* end for. */

    if (help_flag)
        {
        myprintf("\r\nLABEL Version " VERSION "\r\n", 0);
        myprintf("Creates, changes or deletes the volume label of a disk.\r\n",0);
        myprintf("\r\n",0);
        myprintf("Syntax: LABEL [drive:][label] [/?]\r\n",0);
        myprintf("  [drive:]  Specifies which drive you want to label\r\n",0);
        myprintf("  [label]   Specifies the new label you want to label the drive\r\n",0);
        myprintf("  /?        Displays this help message\r\n",0);
        return 0;
        } /* end if. */

    do_cmdline(argc, argv);
    if (*Drive == '?')  /* If no drive specified, use current. */
        GetDrive();

    /* Save current directory and move to root. */
    GetCurDir(curdir);
    if (curdir[0] != 0)
        {
        *rootdir = *Drive;
        SetCurDir(rootdir);
        } /* end if. */
   
    /* If no label was specified, show current one first and then get new one. */
    if (*Label == '\0')
        {
        disp_label();
        get_label();
        } /* end if. */
    
    /* If they entered an empty label, then ask them if they want to */
    /* delete the existing volume label. */
    if ((*Label == '\0') && (!NoLabel))
        {
        do
            {
	    myprintf("\nDelete current volume label (Y/N)? ",0);
            mygets(ans,2); /* WHY not use getch? ??? */
            } /* end do. */
        while (((*ans=(char)toupper(*ans)) != 'Y') && (*ans != 'N'));
    
        if (toupper(*ans) == 'N')
            exit(1);

        } /* end if. */

    /* Delete the old volume label. */
    del_label();
  
    /* Create the new one, if there is one to create. */
    if (*Label != '\0')
        {
        if (make_label())
            {
            exit(1);
            } /* end if. */

        } /* end if. */

    exit(0);
    return 0;

} /* end main. */
Example #16
0
//------------------------------------------------------------------------------
void fin_input(void)
{
	setvect(keyboard_interrupt, bios_keyboard_handler);
}
Example #17
0
/* Uninstall our vectors before exiting the program */
void GSerial::ResetVects(void)
{
    setvect(InterruptNo[m_unPortNo-1], OldVects);
}
Example #18
0
/* 恢复原有的时钟中断处理过程 */
void KillTimer()
{
    disable();
    setvect(TIMER,oldhandler);
    enable();
}
Example #19
0
File: ibmpc.c Project: hankem/jed
void restore_int9_handler(void) /*{{{*/
{
   setvect(9, oldint9);
}
Example #20
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 ;
}
Example #21
0
 void backgroundon (void)
 {
   oldinterrupt = getvect (TIMER_INTR);
   setvect (TIMER_INTR, newinterrupt);
 }
Example #22
0
/*************************************************************************
 *
 *N  vpfopencheck
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function tries its darndest to open a file.  It initially calls
 *     fopen with the given filename and mode.  If that doesn't work and
 *     the file is not on the hard disk, it displays a message asking the
 *     user to enter the correct disk in the drive, waits for either a retry
 *     or a cancel response, and, if told to retry, tries again.  This
 *     process is repeated until either the file is opened or the user
 *     requests cancel.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    filename <input> == (char *) full path name of the file to be opened.
 *    mode     <input> == (char *) mode of the file.
 *    diskname <input> == (char *) descriptive name of the disk the file is
 *                                 on.
 *    return  <output> == (FILE *) file pointer newly associated with
 *                                 filename.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels    May 1991                       DOS Turbo C
 *    Dave Flinn        July 1991     Updated for UNIX
 *E
 *************************************************************************/
FILE *vpfopencheck( const char *filename,
		    const char *mode,
		    const char * diskname )
{
   FILE *fp;
   char* tmpFilename = (char*) malloc ( strlen(filename) + 1 );
/*
   char *text[] = {"Please insert",
		   "                                        ",
		   "in data drive",
		   "                                                      "};
*/
   rspf_int32 retry = 0;
#ifdef __MSDOS__
   extern char home[255];
   void interrupt (*doshandler)();

   doshandler = getvect(36);
   harderr(vpfhandler);

   strncpy(text[1],diskname,strlen(text[1]));
   strcpy(text[3],filename);
#endif
   fp = NULL;


   /* copy the filename because we might modify it. */
   tmpFilename[strlen(filename)] = '\0'; /* just in case */
   strcpy(tmpFilename, filename);
   
   while (fp == NULL)
   {
      fp = fopen(tmpFilename,mode);
      if (fp == NULL)
      {
#ifdef __MSDOS__
	 if ( toupper(home[0]) != toupper(tmpFilename[0]) )
	    retry = displayerror(text,   4);
	 else
#else
            /* give names ending in dot another chance without the dot */
            if (tmpFilename[strlen(tmpFilename)-1] == '.')
            {
               tmpFilename[strlen(tmpFilename)-1] = '\0';
               retry = TRUE;
            }
            else
#endif
               retry = FALSE;
	 if (!retry) break;
      }
   }

   free(tmpFilename);
   tmpFilename = 0;
   
#ifdef __MSDOS__
   setvect(36,doshandler);
#endif
   return fp;
}
Example #23
0
int initialize(void)
{
  //int rc;
  int comPath;                /* path to COMMAND.COM (for COMSPEC/reload) */
  char *newTTY;                 /* what to change TTY to */
  int showinfo;                 /* show initial info only if no command line options */

  int ec;           /* error code */
  unsigned offs;        /* offset into environment segment */

  int cmdlen;         /* length of command line */
  char *cmdline;        /* command line duplicated into heap */
  char *p, *h, *q;
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  FILE *f;
#endif
#endif

/* Set up the host environment of COMMAND.COM */

	/* Install the dummy handlers for Criter and ^Break */
	initCBreak();
	setvect(0x23, cbreak_handler);
	setvect(0x24, dummy_criter_handler);

  /* DOS shells patch the PPID to the own PID, how stupid this is, however,
    because then DOS won't terminate them, e.g. when a Critical Error
    occurs that is not detected by COMMAND.COM */

  oldPSP = OwnerPSP;
  atexit(exitfct);
  OwnerPSP = _psp;

	dbg_printmem();
#ifdef DEBUG
	{ void* p;
		if((p = malloc(5*1024)) == 0)
			dprintf(("[MEM: Out of memory allocating test block during INIT]"));
		else free(p);
	}
#endif

#ifdef FEATURE_KERNEL_SWAP_SHELL
	if(kswapInit()) {		/* re-invoked */
		if(kswapLoadStruc()) {
			/* OK, on success we need not really keep the shell trick
				(pretend we are our own parent), which might cause
				problems with beta-software-bugs ;-)
				In fact, KSSF will catch up our crashes and re-invoke
				FreeCOM, probably with the loss of any internal
				settings. */
			  OwnerPSP = oldPSP;
			return E_None;
		}
	}
#endif

  /* Some elder DOSs may not pass an initializied environment segment */
  if (env_glbSeg && !isMCB(SEG2MCB(env_glbSeg)))
    env_setGlbSeg(0);       /* Disable the environment */

/* Now parse the command line parameters passed to COMMAND.COM */
  /* Preparations */
  newTTY = 0;
  comPath = tracemode = 0;
  showinfo = 1;

  /* Because FreeCom should be executed in a DOS3+ compatible
    environment most of the time, it is assumed that its path
    can be determined from the environment.
    This has the advantage that the string area is accessable
    very early in the run.
    The name of the current file is string #0. */
  if((offs = env_string(0, 0)) != 0)    /* OK, environment filled */
    grabComFilename(0, (char far *)MK_FP(env_glbSeg, offs));
  /* After that argv[0] is no longer used and maybe zapped.
  	This also will help, as most programs altering the environment
  	segment externally don't expect a string area. */
  env_nullStrings(0);

  /* Aquire the command line, there are three possible sources:
    1) DOS command line @PSP:0x80 as pascal string,
    2) extended DOS command line environment variable CMDLINE,
      if peekb(PSP, 0x80) == 127,&
    3) MKS command line @ENV:2, if peekb(ENV, 0) == '~'
    	&& peekb(ENV, 1) == '='

    Currently implemented is version #1 only
  */
  cmdlen = peekb(_psp, 0x80);
  if(cmdlen < 0 || cmdlen > 126) {
    error_corrupt_command_line();
    cmdlen = 0;
  }
    /* duplicate the command line into the local address space */
  if((cmdline = malloc(cmdlen + 1)) == 0) {
    error_out_of_memory();  /* Cannot recover from this problem */
    return E_NoMem;
  }
  _fmemcpy((char far*)cmdline, MK_FP(_psp, 0x81), cmdlen);
  cmdline[cmdlen] = '\0';
#ifdef FEATURE_CALL_LOGGING
#ifndef INCLUDE_CMD_FDDEBUG
  if((f = fopen(logFilename, "at")) == 0) {
    fprintf(stderr, "Cannot open logfile: \"%s\"\n", logFilename);
  } else {

  putc('"', f);
  if(ComPath)   /* path to command.com already known */
    fputs(ComPath, f);
  putc('"', f);
  putc(':', f);

  fputs(cmdline, f);
  putc('\n', f);
  fclose(f);
  }
#else
	cmd_fddebug(logFilename);

	dbg_outc('"');
	dbg_outs(ComPath);
	dbg_outc('"');
	dbg_outc(':');
	dbg_outsn(cmdline);
#endif
#endif

  canexit = 1;
  p = cmdline;    /* start of the command line */
  do {
  ec = leadOptions(&p, opt_init, 0);
  if(ec == E_NoOption) {    /* /C or /K */
    assert(p && *p);
    if(!isoption(p)) {
      error_quoted_c_k();
      p = 0;
      break;
    }
    assert(p[1] && strchr("kKcC", p[1]));
    p += 2;   /* p := start of command line to execute */
    break;
  } else if(ec != E_None) {
        showhelp = 1;
    p = 0;
    break;
  }

  assert(p && !isoption(p) && !isspace(*p));
  if(!*p) {
    p = 0;
    break;      /* end of line reached */
  }
  q = unquote(p, h = skip_word(p));
  p = h;      /* Skip this word */
  if(!q) {
    error_out_of_memory();
    p = 0;
    break;
  }
  if(!comPath) {      /* 1st argument */
    grabComFilename(1, (char far*)q);
    comPath = 1;
    free(q);
  } else if(!newTTY) {  /* 2nd argument */
#ifdef INCLUDE_CMD_CTTY
    newTTY = q;
#else
      error_ctty_excluded();
    free(q);
#endif
      } else {
        error_too_many_parameters(q);
        showhelp = 1;
        free(q);
        break;
      }
   } while(1);

   /*
    * Now:
    * + autoexec: AUTOEXEC.BAT file to be executed if /P switch
    *   is enabled; if NULL, use default
    * + comPath: user-defined PATH to COMMAND.COM; if NULL, use
    *   the one from the environment
    * + newTTY: the name of the device to be CTTY'ed; if NULL,
    *   no change
    * + p: pointer to the command to be executed:
    *   *p == 'c' or 'C' --> spawn command, then terminate shell
    *   *p == 'k' or 'K' --> spawn command, then go interactive
    *   &p[1] --> command line, unless the first character is an
    *   argument character
    */

/* Now process the options */

#ifdef INCLUDE_CMD_CTTY
  if (newTTY) {      /* change TTY as early as possible so the caller gets
                          the messages into the correct channel */
    cmd_ctty(newTTY);
    free(newTTY);
  }
#endif

  if(!ComPath) {
    /* FreeCom is unable to find itself --> print error message */
    /* Emergency error */
#undef TEXT_MSG_FREECOM_NOT_FOUND
	puts(TEXT_MSG_FREECOM_NOT_FOUND);
    return E_Useage;
  }

  /* First of all, set up the environment */
    /* If a new valid size is specified, use that */
  env_resizeCtrl |= ENV_USEUMB | ENV_ALLOWMOVE;
  if(newEnvSize > 16 && newEnvSize < 32767)
    env_setsize(0, newEnvSize);

  /* Otherwise the path is placed into the environment */
    /* Set the COMSPEC variable. */
  if(chgEnv("COMSPEC", ComPath)) {		/* keep it silent */
    /* Failed to add this variable, the most likely problem should be that
      the environment is too small --> it is increased and the
      operation is redone */
    env_resize(0, strlen(ComPath) + 10);
    if(chgEnv("COMSPEC", ComPath))
    	chgEnv("COMSPEC",  NULL);	/* Cannot set -> zap an old one */
  }
  	inInit = 0;

	/* Install INT 24 Critical error handler */
	/* Needs the ComPath variable, eventually */
	if(!kswapContext) {
		/* Load the module/context into memory */
		if((kswapContext = modContext()) == 0) {
			error_loading_context();
			return E_NoMem;
		}
#ifdef FEATURE_KERNEL_SWAP_SHELL
		if(swapOnExec != ERROR)
			kswapRegister(kswapContext);
#endif
	}

	ctxtCreate();

	/* re-use the already loaded Module */
	setvect(0x24, (void interrupt(*)())
	 MK_FP(FP_SEG(kswapContext->cbreak_hdlr), kswapContext->ofs_criter));

  if(internalBufLen)
    error_l_notimplemented();
  if(inputBufLen)
    error_u_notimplemented();

  if(tracemode)
    showinfo = 0;

  if (showhelp)
    displayString(TEXT_CMDHELP_COMMAND);

  if ((showhelp || exitflag) && canexit)
    return E_None;

  /* Now the /P option can be processed */
	if(!canexit) {
		char *autoexec;

		autoexec = user_autoexec? user_autoexec: AUTO_EXEC;

		showinfo = 0;
		short_version();

		if(skipAUTOEXEC) {		/* /D option */
			showinfo = 0;
			displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
		} else {
			if(exist(autoexec)) {
#ifdef FEATURE_BOOT_KEYS
				struct REGPACK r;
				int key;

				r.r_ax = 0x3000;	/* Get DOS version & OEM ID */
				intr(0x21, &r);
				if(!tracemode	/* /Y --> F8 on CONFIG.SYS */
				 || ((r.r_bx & 0xff00) == 0xfd00	/* FreeDOS >= build 2025 */
				      && !(r.r_cx > 0x101 || (r.r_bx & 0xff) > 24))) {
					displayString(TEXT_MSG_INIT_BYPASS_AUTOEXEC, autoexec);
					key = cgetchar_timed(3);
					putchar('\n');
				} else key = 0;

				if(key == KEY_F8)
					tracemode = 1;

				if(key == KEY_F5)
					displayString(TEXT_MSG_INIT_BYPASSING_AUTOEXEC, autoexec);
				else
#endif
					process_input(1, autoexec);
			} else {
				if(user_autoexec)
					error_sfile_not_found(user_autoexec);
#ifdef INCLUDE_CMD_DATE
					cmd_date(0);
#endif
#ifdef INCLUDE_CMD_TIME
					cmd_time(0);
#endif
			}
		}

		free(user_autoexec);
	} else {
		assert(user_autoexec == 0);
	}

  /* Now the /C or /K option can be processed */
  if (p)
  {
    process_input(1, p);
    return spawnAndExit;
  }

  /* Don't place something here that must be executed after a /K or /C */

  if (showinfo)
  {
    short_version();
#ifndef DEBUG
    putchar('\n');
    showcmds(0);
    putchar('\n');
#endif
  }

  return E_None;
}
Example #24
0
void Done (void) {
  _setcursortype (_NORMALCURSOR);
  setvect (9,old9handler);
}
Example #25
0
Int11trap::~Int11trap()
{
    setvect( 0x11, oldHandler );
}
Example #26
0
XInstrument::~XInstrument() {
	setvect(0x1c,old1cvect);
	AboutQuitAnalog();
	delete pCh;
}
Example #27
0
void backgroundoff( void )
{
    setvect( 0x08, oldinterrupt );
}
Example #28
0
static void execute(char *first, char *rest)
{
  /*
   * This command (in first) was not found in the command table
   *
   *
   * first - first word on command line
   * rest  - rest of command line
   *
   */

  char *fullname;

  assert(first);
  assert(rest);

  /* check for a drive change */
  if ((strcmp(first + 1, ":") == 0) && isalpha(*first))
  {
  	changeDrive(*first);
    return;
  }

  if (strchr(first,'?') || strchr(first,'*'))
  {
    error_bad_command();
    return;
  }

  /* search through %PATH% for the binary */
  errno = 0;
  fullname = find_which(first);
  dprintf(("[find_which(%s) returned %s]\n", first, fullname));

  if (!fullname)
  {
    error_bad_command();
    return;
  }

  /* check if this is a .BAT file */
  assert(strrchr(fullname, '.'));

  if (stricmp(strrchr(fullname, '.'), ".bat") == 0)
  {
    dprintf(("[BATCH: %s %s]\n", fullname, rest));
    batch(fullname, first, rest);
  }
  else
    /* exec the program */
  {
    int result;

    dprintf(("[EXEC: %s %s]\n", fullname, rest));

	if (strlen(rest) > MAX_EXTERNAL_COMMAND_SIZE)
	{
		error_line_too_long();
		return;
	}

/* Prepare to call an external program */

	/* Unload the message block if not loaded persistently */
	if(!persistentMSGs)
		unloadMsgs();

/* Execute the external program */
#ifdef FEATURE_KERNEL_SWAP_SHELL
    if(swapOnExec == TRUE
	 && kswapMkStruc(fullname, rest)) {
	 	/* The Criter and ^Break handlers has been installed within
	 		the PSP in kswapRegister() --> nothing to do here */
	 	dprintf(("[EXEC: exiting to kernel swap support]\n"));
	 	exit(123);		/* Let the kernel swap support do the rest */
	}
#ifdef DEBUG
	if(swapOnExec == TRUE)
		dprintf(("KSWAP: failed to save context, proceed without swapping\n"));
#endif
#endif
		/* Install the dummy (always abort) handler */
	setvect(0x23, (void interrupt(*)()) kswapContext->cbreak_hdlr);
    result = exec(fullname, rest, 0);
	setvect(0x23, cbreak_handler);		/* Install local CBreak handler */

    perform_exec_result(result);
  }
}
/*--------------------------------------------------------------------------*

Name            ctrlbrk - sets control-break handler

Usage           void ctrlbrk(int (*fptr)(void));

Prototype in    dos.h

Description     ctrlbrk sets  a new control-break handler  function pointed
                to by fptr.  The interrupt vector 0x23 is  modified to call
                the named function.

                The  named   function  is  not  called   directly.  ctrlbrk
                establishes a  DOS interrupt handler  that calls the  named
                function.

Return value    ctrlbrk returns nothing. The  handler function returns 0 to
                abort the current  program; any other value will  cause the
                program to resume execution.

*---------------------------------------------------------------------------*/
void    ctrlbrk(int (*fptr)())
{
        Hfunc = fptr;

        setvect(0x23, FARINT(hentry));
}
Example #30
0
void
iC_quit(int sig)
{
#ifdef	RASPBERRYPI
    sig = (*iC_term)(sig);			/* clear and unexport RASPBERRYPI stuff */
#endif	/* RASPBERRYPI */
    /********************************************************************
     *  The following termination function is an empty function
     *  in the libict.a support library.
     *  	int iCend(void) { return -1; }
     *  It may be implemented in a literal block of an iC source, in
     *  which case that function will be linked in preference.
     *  User implementations of iCend() should return 0, to activate
     *  the debug message "== iCend complete ======".
     *
     *  It can be used to free allocated memory, etc.
     *
     *  If the iCbegin() function contains a fork() call, iCend() may have
     *  a matching wait() call.
     *******************************************************************/
    if ((sig >= QUIT_TERMINAL || sig == SIGINT)
	&& iCend() != -1			/* iC termination function */
    ) {
#if	YYDEBUG
	if (iC_debug & 0100) {
	    fprintf(iC_outFP, "\n== iCend complete ======\n");
	}
#endif	/* YYDEBUG */
    }
#ifdef TCP
    if (iC_sockFN > 0) {
	if (sig < SIGUSR1 || sig == QUIT_TERMINAL || sig == QUIT_DEBUGGER) {	/* but not QUIT_SERVER */
#ifdef LOAD
	    if (C_channel) {
		/* disconnect iClive - follow with '0' for iCserver */
		snprintf(regBuf, REQUEST, "%hu:5,%hu:0", C_channel, C_channel);
		iC_send_msg_to_server(iC_sockFN, regBuf);
#ifdef	WIN32
		Sleep(200);			/* 200 ms in ms */
#else	/* WIN32 */
		nanosleep(&ms200, NULL);
#endif	/* WIN32 */
		if (iC_micro) iC_microPrint("Disconnected", 0);
	    }
#endif /* LOAD */
	    if (iC_Xflag) {			/* stop iCserver if this process started it */
		snprintf(regBuf, REQUEST, "X%s", iC_iccNM);
		iC_send_msg_to_server(iC_sockFN, regBuf);
	    }
	    iC_send_msg_to_server(iC_sockFN, "");	/* 0 length message to disconnect from iCserver */
	}
	close(iC_sockFN);			/* close connection to iCserver */
    }
#endif /* TCP */
    /********************************************************************
     *  Normal quit
     *******************************************************************/
    fflush(iC_outFP);				/* in case dangling debug messages without CR */
    if (iC_outFP != stdout) {
	fclose(iC_outFP);
    }
    if ((iC_debug & DQ) == 0) {
	if (sig == QUIT_TERMINAL) {
	    fprintf(iC_errFP, "\n'%s' stopped from terminal\n", iC_iccNM);
	} else if (sig == QUIT_DEBUGGER) {
	    fprintf(iC_errFP, "\n'%s' stopped by debugger\n", iC_iccNM);
	} else if (sig == QUIT_SERVER) {
	    fprintf(iC_errFP, "\n'%s' disconnected by server\n", iC_iccNM);
	}
    }
    if (sig == SIGINT) {
	fprintf(iC_errFP, "\n'%s' stopped by interrupt from terminal\n", iC_iccNM);
    } else if (sig == SIGSEGV) {
	fprintf(iC_errFP, "\n'%s' stopped by 'Invalid memory reference'\n", iC_iccNM);
    } else if (sig == SIGUSR1) {
	fprintf(iC_errFP, "\n'%s' stopped by 'non-recoverable run-time error'\n", iC_iccNM);
    }
#if defined(TCP) && defined(LOAD)
    if (iC_savFP) {
	fflush(iC_savFP);
	fclose(iC_savFP);
    }
    if (iC_vcdFP) {
	fflush(iC_vcdFP);
	fclose(iC_vcdFP);
    }
#endif /* defined(TCP) && defined(LOAD) */
#ifdef	_MSDOS_
    if (oldhandler && iC_debug & 03000) {
	/* reset the old interrupt handler */
#ifdef	MSC
	_dos_setvect(INTR, oldhandler);
#else	/* MSC */
	setvect(INTR, oldhandler);
#endif	/* MSC */
    }
#else	/* ! _MSDOS_ Linux */
    if (ttyparmFlag) {
	if (tcsetattr(0, TCSAFLUSH, &ttyparms) == -1) exit(-1);
    }
#endif	/* ! _MSDOS_ Linux */
    if (iC_errFP != stderr) {
	fflush(iC_errFP);
	fclose(iC_errFP);
    }
#if defined(TCP) && defined(EFENCE)
    free(rpyBuf);
    free(regBuf);
#ifdef	LOAD
    free(msgBuf);
    free(iC_outBuf);
#endif	/* LOAD */
#endif /* defined(TCP) && defined(EFENCE) */
    exit(sig < QUIT_TERMINAL ? sig : 0);	/* really quit */
} /* iC_quit */