Ejemplo n.º 1
0
main()
{
    ulong i;

    Enable_Abort = 0;

    td_mp = CreatePort(0L,0L);
    if(!td_mp) exit(99);
    td_iob = CreateStdIO(td_mp);
    if(!td_iob) {
        DeletePort(td_mp);
        exit(99);
    }
    if(OpenDevice("trackdisk.device",0L,td_iob,0L)) {
        printf("Unable to open floppy device driver.\n");
        DeleteStdIO(td_iob);
        DeletePort(td_mp);
        exit(99);
    }

    diskbuf = AllocMem(TD_BUFSIZE,MEMF_PUBLIC|MEMF_CHIP);
    if(!diskbuf) {
        printf("Unable to obtain %ld byte buffer in chip memory.\n",TD_BUFSIZE);
        CloseDevice(td_iob);
        DeleteStdIO(td_iob);
        DeletePort(td_mp);
        exit(99);
    }
    for(i=0;i<80;i+=NUMTRKS) {
        printf("Reading tracks %ld to %ld.\n",i,i+NUMTRKS-1);
        td_iob->io_Command = CMD_READ;
        td_iob->io_Data = (APTR) diskbuf;
        td_iob->io_Length = TD_BUFSIZE;
        td_iob->io_Offset = 11L * 1024L * i;
        DoIO(td_iob);
        if(td_iob->io_Error) {
            printf("Floppy read failed, error number %d.\n",td_iob->io_Error);
            break;
        }
    }
    td_iob->io_Command = TD_MOTOR;
    td_iob->io_Length = 0;
    DoIO(td_iob);

    FreeMem(diskbuf,TD_BUFSIZE);
    CloseDevice(td_iob);
    DeleteStdIO(td_iob);
    DeletePort(td_mp);
}
Ejemplo n.º 2
0
int main (int argc, char **argv)
{
    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    int result = calltrap (0, 0);

    if (result == 1)
	fprintf (stderr, "timehack already running.\n");
    else if (result == 2)
	fprintf (stderr, "timehack not supported with this version of UAE.\n");
    if (result != 0)
	exit (5);

    timeport = CreatePort (0, 0);
    if (timeport)
	timereq = CreateStdIO(timeport);

    if (timereq == 0)
	goto fail;

    if (OpenDevice ("timer.device", UNIT_VBLANK, timereq, 0) != 0)
	goto fail;

    SetTaskPri (FindTask (NULL), 20); /* same as input.device */
    for (;;) {
        struct timeval cur_sys_time;

        timereq->tr_node.io_Command = TR_GETSYSTIME;
        DoIO(timereq);
        cur_sys_time = timereq->tr_time;
        calltrap (1, &timereq->tr_time);
        if (timereq->tr_time.tv_secs > cur_sys_time.tv_secs
	    || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
		&& timereq->tr_time.tv_micro > cur_sys_time.tv_micro))
	{
            timereq->tr_node.io_Command = TR_SETSYSTIME;
            DoIO(timereq);
        }

        timereq->tr_time.tv_secs = 1;
	timereq->tr_time.tv_micro = 0;
        timereq->tr_node.io_Command = TR_ADDREQUEST;
	DoIO(timereq);
    }
    fail:
    fprintf (stderr, "Couldn't start timehack (that's bad!)\n");
    exit (5);
}
Ejemplo n.º 3
0
/*
 * checks if a device exists
 */
static int device_exists (const char *device_name, int device_unit)
{
    struct IOStdReq *ioreq  = NULL;
    struct MsgPort  *port   = NULL;
    int ret = 0;

    port = CreatePort(0, 0);
    if(port) {
	ioreq = CreateStdIO(port);
	if(ioreq) {
	    if(!OpenDevice(device_name,device_unit,(void*)ioreq,0)) {
		CloseDevice((void*)ioreq);
		ret = 1;
	    }
	    DeleteStdIO(ioreq);
	}
	DeletePort(port);
    }
    return ret;
}
Ejemplo n.º 4
0
static struct InputEvent *IN_KeyboardHandlerFunc()
{
	struct InputEvent *moo = (struct InputEvent *)REG_A0;
	struct inputdata *id = (struct inputdata *)REG_A1;
#else
HANDLERPROTO(IN_KeyboardHandler, struct InputEvent *, struct InputEvent *moo, APTR id)
{
#endif
	struct InputEvent *coin;

	ULONG screeninfront;

	if (!window || !(window->Flags & WFLG_WINDOWACTIVE))
		return moo;

	if (window->WScreen)
	{
#ifdef __MORPHOS__
		if (IntuitionBase->LibNode.lib_Version > 50 || (IntuitionBase->LibNode.lib_Version == 50 && IntuitionBase->LibNode.lib_Revision >= 56))
			GetAttr(SA_Displayed, window->WScreen, &screeninfront);
		else
#endif
			screeninfront = (window->WScreen == IntuitionBase->FirstScreen);
	}
	else
		screeninfront = 1;

	for (coin = moo; coin; coin = coin->ie_NextEvent)
	{
		if (coin->ie_Class == IECLASS_RAWKEY)
		{
			int code;
			
			// mouse button 4, mouse wheel and keyboard
			code = coin->ie_Code & ~IECODE_UP_PREFIX;
			if (code >= NM_WHEEL_UP && code <= NM_BUTTON_FOURTH)
			{
				// we don't need these, they will be handled under IECLASS_NEWMOUSE
				/*if (mouseactive && screeninfront)
				{
					IN_AddEvent(coin);
					coin->ie_Code = IECODE_NOBUTTON;
				}*/
			}
			else
			{
				IN_AddEvent(coin);
			}
		}
		else if (coin->ie_Class == IECLASS_RAWMOUSE && mouseactive && screeninfront)
		{
			// mouse buttons 1-3
			if (coin->ie_Code != IECODE_NOBUTTON)
			{
				IN_AddEvent(coin);
				coin->ie_Code = IECODE_NOBUTTON;
			}

			// mouse movement
			mx += coin->ie_position.ie_xy.ie_x;
			my += coin->ie_position.ie_xy.ie_y;
			coin->ie_position.ie_xy.ie_x = 0;
			coin->ie_position.ie_xy.ie_y = 0;
		}
		else if (coin->ie_Class == IECLASS_NEWMOUSE && mouseactive && screeninfront)
		{
			// mouse button 4, mouse wheel
			IN_AddEvent(coin);
			coin->ie_Code = IECODE_NOBUTTON;
		}
	}

	return moo;
}
//MakeHandlerPri(InputHandler, &IN_KeyboardHandler, "Hexen II input handler", NULL, 100);

/*
===========
IN_Init
===========
*/
void IN_Init (void)
{
	static char handler_name[] = "Hexen II input handler";

	/* mouse variables */
	Cvar_RegisterVariable (&m_filter);
	/* joystick variables */
	Cvar_RegisterVariable (&in_joystick);
	Cvar_RegisterVariable (&joy_index);

	Cvar_SetCallback (&in_joystick, IN_Callback_JoyEnable);
	Cvar_SetCallback (&joy_index, IN_Callback_JoyIndex);

	Cmd_AddCommand ("force_centerview", Force_CenterView_f);

	pointermem = (UWORD *) AllocVec(2 * 6, MEMF_CHIP | MEMF_CLEAR);

	IN_StartupMouse ();
	IN_StartupJoystick ();

	imsglow = imsghigh = 0;

	inputport = CreateMsgPort();
	if (inputport)
	{
		//inputreq = (struct IOStdReq *) CreateIORequest(inputport, sizeof(*inputreq));
		inputreq = CreateStdIO(inputport);
		if (inputreq)
		{
			if (!OpenDevice("input.device", 0, (struct IORequest *)inputreq, 0))
			{
				InputHandler.is_Node.ln_Type = NT_INTERRUPT;
				InputHandler.is_Node.ln_Pri = 100;
				InputHandler.is_Node.ln_Name = handler_name;
				InputHandler.is_Code = (void (*)())&IN_KeyboardHandler;
				inputreq->io_Data = (void *)&InputHandler;
				inputreq->io_Command = IND_ADDHANDLER;
				DoIO((struct IORequest *)inputreq);
				return;
			}
			//DeleteIORequest(inputreq);
			DeleteStdIO(inputreq);
		}
		DeleteMsgPort(inputport);
	}

	Sys_Error ("Couldn't install input handler");
}

/*
===========
IN_Shutdown
===========
*/
void IN_Shutdown (void)
{
	if (inputreq)
	{
		inputreq->io_Data = (void *)&InputHandler;
		inputreq->io_Command = IND_REMHANDLER;
		DoIO((struct IORequest *)inputreq);

		CloseDevice((struct IORequest *)inputreq);
		//DeleteIORequest(inputreq);
		DeleteStdIO(inputreq);
	}

	if (inputport)
	{
		DeleteMsgPort(inputport);
	}

	IN_DeactivateMouse ();
	/*IN_ShowMouse ();*/

	if (pointermem)
	{
		FreeVec(pointermem);
	}

	mouseinitialized = false;

	if (LowLevelBase)
	{
		CloseLibrary(LowLevelBase);
		LowLevelBase = NULL;
	}

	joy_port = -1;
	joy_available = 0;
	oldjoyflag = 0;

#ifdef __CLIB2__
	if (KeymapBase) {
		CloseLibrary(KeymapBase);
		KeymapBase = NULL;
	}
#endif
}

/*
===========
IN_ReInit
===========
*/
void IN_ReInit (void)
{
	IN_StartupMouse ();
}


/*
===========
IN_MouseMove
===========
*/
static void IN_MouseMove (usercmd_t *cmd/*, int mx, int my*/)
{
	if (m_filter.integer)
	{
		mouse_x = (mx + old_mouse_x) * 0.5;
		mouse_y = (my + old_mouse_y) * 0.5;
	}
	else
	{
		mouse_x = mx;
		mouse_y = my;
	}

	old_mouse_x = mx;
	old_mouse_y = my;

	mouse_x *= sensitivity.value;
	mouse_y *= sensitivity.value;

/* add mouse X/Y movement to cmd */
	if ( (in_strafe.state & 1) || (lookstrafe.integer && (in_mlook.state & 1) ))
		cmd->sidemove += m_side.value * mouse_x;
	else
		cl.viewangles[YAW] -= m_yaw.value * mouse_x;

	if (in_mlook.state & 1)
	{
		if (mx || my)
			V_StopPitchDrift ();
	}

	if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
	{
		cl.viewangles[PITCH] += m_pitch.value * mouse_y;
		if (cl.viewangles[PITCH] > 80)
			cl.viewangles[PITCH] = 80;
		if (cl.viewangles[PITCH] < -70)
			cl.viewangles[PITCH] = -70;
	}
	else
	{
		if ((in_strafe.state & 1) && (cl.v.movetype == MOVETYPE_NOCLIP))
			cmd->upmove -= m_forward.value * mouse_y;
		else
			cmd->forwardmove -= m_forward.value * mouse_y;
	}

	if (cl.idealroll == 0) /* Did keyboard set it already?? */
	{
		if (cl.v.movetype == MOVETYPE_FLY)
		{
			if (mouse_x < 0)
				cl.idealroll = -10;
			else if (mouse_x > 0)
				cl.idealroll = 10;
		}
	}
}

static void IN_DiscardMove (void)
{
	if (mouseinitialized)
	{
		mx = my = old_mouse_x = old_mouse_y = 0;
	}
}

/*
===========
IN_Move
===========
*/
void IN_Move (usercmd_t *cmd)
{
	if (cl.v.cameramode)
	{
	/* stuck in a different camera so don't move */
		memset (cmd, 0, sizeof(*cmd));
	/* ignore any mouse movements in camera mode */
		IN_DiscardMove ();
		return;
	}

	if (mx != 0 || my != 0)
	{
		IN_MouseMove (cmd/*, x, y*/);
		mx = my = 0;
	}
}

static const char *JoystickName(int port)
{
	ULONG joyflag = ReadJoyPort(port);

	switch (joyflag & JP_TYPE_MASK)
	{
	case JP_TYPE_GAMECTLR:
		return "game controller";
	case JP_TYPE_JOYSTK:
		return "joystick controller";
	case JP_TYPE_MOUSE:
		return "mouse";
	case JP_TYPE_NOTAVAIL:
		return "not available";
	case JP_TYPE_UNKNOWN:
		return "unknown device";
	default:
		return "<unknown>";
	}
}
Ejemplo n.º 5
0
int main(int argc, char **argv)
{
    struct IntuitionBase *ibase;
    struct InputEvent *iev;
    struct IOStdReq *ioreq = 0;
    struct MsgPort *port;

    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    int oldx = 0, oldy = 0;
    int i;

    i = (*calltrap) (0);
    if (i == 0) {
	fprintf(stderr, "mousehack not needed for this version of UAE.\n");
	exit (0);
    }
    if (i == -1) {
	fprintf(stderr, "mousehack already running.\n");
	exit (5);
    }

    i = AllocSignal (-1);
    if (i < 0)
	goto fail;
    foo.sigbit = 1 << i;

    port = CreatePort(0, 0);
    timeport = CreatePort (0, 0);
    if (port)
	ioreq = CreateStdIO(port);

    if (timeport)
	timereq = CreateStdIO(timeport);

    if (ioreq == 0)
	goto fail;
    if (timereq == 0)
	goto fail;

    iev = AllocMem (sizeof (struct InputEvent), MEMF_CLEAR + MEMF_PUBLIC);
    if (iev == 0)
	goto fail;
    if (OpenDevice ("input.device", 0, ioreq, 0) != 0)
	goto fail;
    if (OpenDevice ("timer.device", 0, timereq, 0) != 0)
	goto fail;

    foo.mx = (ULONG)-1;
    foo.my = (ULONG)-1;
    foo.mt = FindTask (0);
    AddIntServer(INTB_VERTB, &myint);

    ibase = OpenLibrary ("intuition.library", 0);
    SetTaskPri (foo.mt, 20); /* same as input.device */
    for (;;) {
	int newx, newy;

	Wait (foo.sigbit);
	ioreq->io_Command = IND_WRITEEVENT;
	ioreq->io_Length = sizeof (struct InputEvent);
	ioreq->io_Data = iev;
	ioreq->io_Flags = IOF_QUICK;
	iev->ie_Class = IECLASS_POINTERPOS;
	iev->ie_SubClass = 0;
	iev->ie_Code = 0;
	iev->ie_Qualifier = 0;
#if 0
	newx = (*calltrap) (1);
	newy = (*calltrap) (2);

	if (oldy != newy || oldx != newx)
#endif
	{
	    timereq->tr_node.io_Flags = IOF_QUICK;
	    timereq->tr_node.io_Command = TR_GETSYSTIME;
	    DoIO (timereq);
	    iev->ie_TimeStamp = timereq->tr_time;
	    /* Those are signed, so I hope negative values are OK... */
	    /* I wonder why I have to multiply those by 2... but it works,
	     * at least for me. */
	    iev->ie_position.ie_xy.ie_x = foo.mx - ibase->ViewLord.DxOffset*2;
	    iev->ie_position.ie_xy.ie_y = foo.my - ibase->ViewLord.DyOffset*2;

	    oldx = newx;
	    oldy = newy;
	    DoIO(ioreq);
	}
#if 0
	timereq->tr_node.io_Flags = IOF_QUICK;
	timereq->tr_time.tv_secs = 0;
	timereq->tr_time.tv_micro = 20000;
	timereq->tr_node.io_Command = TR_ADDREQUEST;
	DoIO(timereq);
#endif
    }
    fail:
    fprintf (stderr, "Couldn't start mousehack (that's bad!)\n");
    exit (5);
}
Ejemplo n.º 6
0
/*
 * copy a device to a FILE*.
 */
static int raw_copy(char *dev_name, int dev_unit, FILE *dst)
{
    struct MsgPort  *port   = NULL;
    struct IOStdReq *ioreq  = NULL;
    int tracklen            = 512*11;
    int retstatus           = 1;
    int inhibited           = 0;
    char *buffer            = NULL;
    static char name[]      = {'D','F','0','\0'};

    if(!strcmp(dev_name, "trackdisk.device")) {
	inhibited = 1;
	name[2] = '0'+dev_unit;
    }

    /* allocate system stuff */
    if((port   = CreatePort(0, 0)))            {
    if((ioreq  = CreateStdIO(port)))           {
    if((buffer = AllocMem(tracklen, MEMF_CHIP))) {

    /* gain access to the device */
    if(!OpenDevice(dev_name, dev_unit, (struct IORequest*)ioreq, 0)) {

    /* check if a disk is present */
    myDoIO(ioreq, TD_CHANGESTATE, 0, -1, -1, -1);
    if(!ioreq->io_Error && ioreq->io_Actual) {
	fprintf(stderr,"No disk in %s unit %d !\n", dev_name, dev_unit);
	retstatus = 0;
    } else {
	int tr = 0;
	int write_protected = 0;
	/* check if disk is write-protected:
	myDoIO(ioreq, TD_PROTSTATUS, 0, -1, -1, -1);
	if(!ioreq->io_Error && ioreq->io_Actual) write_protected = 1;
	*/

	/* inhibit device */
	if(inhibited) inhibited = dev_inhibit(name,1);

	/* read tracks */
	for(tr = 0; tr < 160; ++tr) {
	    printf("Reading track %2d side %d of %s unit %d  \r",
		   tr/2, tr%2, dev_name, dev_unit);
	    fflush(stdout);
	    myDoIO(ioreq, CMD_READ, -1, tracklen*tr, tracklen, (LONG)buffer);
	    if(ioreq->io_Error) printf("Err. on\n");
	    if(fwrite(buffer, 1, tracklen, dst) != (unsigned int)tracklen) {
	       retstatus = 0;
	       break;
	    }
	}

	/* ok everything done! */
	printf("                                                                        \r");
	fflush(stdout);

	/* stop motor */
	myDoIO(ioreq, TD_MOTOR, 0, -1, 0, -1);

	/* uninhibit */
	if(inhibited) dev_inhibit(name,0);
    }
    CloseDevice((struct IORequest*)ioreq);   } else retstatus = 0;
    FreeMem(buffer,tracklen);                } else retstatus = 0;
    DeleteStdIO(ioreq);                      } else retstatus = 0;
    DeletePort(port);                        } else retstatus = 0;
    return retstatus;
}
Ejemplo n.º 7
0
int main (int argc, char **argv)
{
    struct timerequest *timereq = 0;
    struct MsgPort *timeport;
    struct timeval *tz_offset;
    struct Device *TimerBase;
    int quit = 0;
    int result = calltrap (0, 0);

    if (result == 1)
        fputs ("timehack already running.\n", stderr);
    else if (result == 2)
        fputs ("timehack not supported with this version of UAE.\n", stderr);
    if (result != 0)
        exit (5);

    timeport = (struct MsgPort *) CreatePort (0, 0);
    if (timeport)
        timereq = (struct timerequest *) CreateStdIO(timeport);

    if (timereq == 0)
        goto fail;

    if (OpenDevice ("timer.device", UNIT_VBLANK, (struct IORequest *) timereq, 0) != 0)
        goto fail;
    TimerBase = timereq->tr_node.io_Device;

    SetTaskPri (FindTask (NULL), 20); /* same as input.device */

    tz_offset = get_tz_offset();

    while (!quit) {
        struct timeval cur_sys_time;

        timereq->tr_node.io_Command = TR_GETSYSTIME;
        DoIO ((struct IORequest *)timereq);
        cur_sys_time = timereq->tr_time;
        calltrap (1, &timereq->tr_time);
        if (timereq->tr_time.tv_secs != cur_sys_time.tv_secs
                || (timereq->tr_time.tv_secs == cur_sys_time.tv_secs
                    && ABS(timereq->tr_time.tv_micro - cur_sys_time.tv_micro) > 1000))
        {
            AddTime (&timereq->tr_time, tz_offset);
            timereq->tr_node.io_Command = TR_SETSYSTIME;
            DoIO ((struct IORequest *)timereq);
        }

        timereq->tr_time.tv_secs = 1;
        timereq->tr_time.tv_micro = 0;
        timereq->tr_node.io_Command = TR_ADDREQUEST;
        DoIO ((struct IORequest *)timereq);

        if (SetSignal(0L,SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C)
            quit = TRUE;
    }
    /* Exit and error handling badly needs tidying up - Rich */
    CloseDevice ((struct IORequest *)timereq);
    DeleteStdIO ((struct IOStdReq *)timereq);
    DeletePort (timeport);
    exit (0);

fail:
    fputs ("Couldn't start timehack (that's bad!)\n", stderr);
    exit (5);
}
Ejemplo n.º 8
0
int32_t main(int32_t argc, char **argv)
{
    char *filename, *openMode="rb";
    FILE *ADFFile;
    int32_t write=0;
    struct IOStdReq *ioreq;
    struct MsgPort *port;

    UBYTE *buffer;
    char devicebuf[256];
    char *devicename = "trackdisk.device";
    char devicenum = 0;
    int32_t i;
    int32_t starttr = 0, endtr = 79;
    int32_t sectors = 11;

    for (i = 1; i < argc;) {
	if (argv[i][0] != '-' || argv[i][2] != 0) {
	    usage();
	    exit(1);
	}
	switch (argv[i][1]) {
	 case 'h':
	    sectors = 22;
	    i++;
	    break;
	case 'd':
	    if (i+2 >= argc) {
		usage();
		exit(1);
	    }
	    devicenum = atoi(argv[i+2]);
	    sprintf(devicebuf, "%s.device", argv[i+1]);
	    devicename = devicebuf;
	    i += 3;
	    break;
	case 's':
	    if (i+1 >= argc) {
		usage();
		exit(1);
	    }
	    starttr = atoi(argv[i+1]);
	    i += 2;
	    break;
	case 'e':
	    if (i+1 >= argc) {
		usage();
		exit(1);
	    }
	    endtr = atoi(argv[i+1]);
	    i += 2;
	    break;
	case 'w':
	    if (i+1 >= argc) {
		usage();
		exit(1);
	    }
	    filename=argv[i+1];
	    write=1;
	    i += 2;
	    break;
	default:
	    usage();
	    exit(1);
	}
    }
    fprintf(stderr,"Using %s unit %d\n", devicename, devicenum);
    fprintf(stderr,"Tracks are %d sectors\n", sectors);
    fprintf(stderr,"First track %d, last track %d\n", starttr, endtr);

    buffer = AllocMem(512, MEMF_CHIP);
    if (write) {
	ADFFile = fopen(filename,openMode);

	if (!ADFFile) {
	    fprintf(stderr,"Error while opening input file\n");
	    exit (1);
	}
    }

    port = CreatePort(0, 0);
    if (port) {
	ioreq = CreateStdIO(port);
	if (ioreq) {
	    if (OpenDevice(devicename, devicenum, (struct IORequest *) ioreq, 0) == 0) {
		int32_t tr, sec;

		ioreq->io_Command = write ? CMD_WRITE : CMD_READ;
		ioreq->io_Length = 512;
		ioreq->io_Data = buffer;
		for (tr = starttr*2; tr < (endtr+1)*2; tr++) {
		    fprintf(stderr,"Track: %d\r",tr/2);
		    for (sec = 0; sec < sectors; sec++) {
			fflush(stderr);
			if (write)
			    if (fread(buffer, sizeof(UBYTE), 512, ADFFile) < 512) {
				fprintf(stderr, "Error: ADF file to short?\n");
				exit(1);
			    }
			ioreq->io_Offset = 512 * (tr * sectors + sec);
			DoIO( (struct IORequest *) ioreq);
			if (!write)
			    fwrite(buffer, sizeof(UBYTE), 512, stdout);
		    }
		}
		if (write) {		/* Make sure the last track is written to disk */
		    ioreq->io_Command = CMD_UPDATE;
		    DoIO( (struct IORequest *) ioreq);
		}
		ioreq->io_Command = TD_MOTOR;	/* Turn Disk-motor off */
		ioreq->io_Length = 0;
		DoIO( (struct IORequest *) ioreq);
		CloseDevice( (struct IORequest *) ioreq);
	    } else
		fprintf(stderr,"Unable to open %s unit %d\n", devicename, devicenum);
	    DeleteStdIO(ioreq);
	}
	DeletePort(port);
    }
    fprintf(stderr,"\n");
    FreeMem(buffer, 512);
    if (write)
	fclose (ADFFile);
    return 0;
}