Exemplo n.º 1
0
__stkargs int setup_timer(LONG unit, struct timerequest ** tr)
{
    struct MsgPort *timerport;
    struct timerequest *req;

    if (*tr)
	return 1;

    if (!(timerport = (struct MsgPort *) CreatePort(0L, 0L))) {
	*tr = NULL;
	printf("setup_timer: could not create port\n");
	return 0;
    }
    if (!(req = (struct timerequest *) CreateExtIO(timerport
						,sizeof(struct timerequest))
	)) {
	DeletePort(timerport);
	*tr = NULL;
	printf("setup_timer: could not get request\n");
	return 0;
    }
    if (OpenDevice(TIMERNAME, unit, (struct IORequest *) req, 0L)) {
	CloseDevice((struct IORequest *) req);
	DeleteExtIO((struct IORequest *) req);
	DeletePort(timerport);
	printf("setup_timer: could not open timer\n");
	*tr = NULL;
	return 0;
    }
    *tr = req;
    return 1;
}
Exemplo n.º 2
0
struct timerequest *create_timer ( ULONG unit )
{
    /* return a pointer to a timer request.  If any problem, return NULL */
    LONG error;
    struct MsgPort *timerport;
    struct timerequest *TimerIO;

    timerport = ( struct MsgPort * ) CreatePort ( 0, 0 );
    if ( timerport == NULL )
        return ( NULL );

    TimerIO = ( struct timerequest * )
              CreateExtIO ( timerport, sizeof ( struct timerequest ) );
    if ( TimerIO == NULL )
    {
        DeletePort ( timerport );   /* Delete message port */
        return ( NULL );
    }

    error = OpenDevice ( TIMERNAME, unit, ( struct IORequest * ) TimerIO, 0L );
    if ( error != 0 )
    {
        delete_timer ( TimerIO );
        return ( NULL );
    }
    return ( TimerIO );
}
Exemplo n.º 3
0
void start_noise(void)
{
   nport = CreatePort(NULL,0);

   chipnoisedata = (UBYTE *)AllocMem(sizeof(noisedata), MEMF_CHIP);
   memcpy(chipnoisedata, noisedata, sizeof(noisedata));

   audioreq = (struct IOAudio *)CreateExtIO(nport, sizeof(*audioreq)*2);

   modifyreq = audioreq+1;

   audioreq->ioa_Data     = amap;
   audioreq->ioa_Length   = sizeof(amap);
   OpenDevice(AUDIONAME, 0, &(audioreq->ioa_Request), 0);

   audioreq->ioa_Request.io_Command = CMD_WRITE;
   audioreq->ioa_Request.io_Message.mn_Length = sizeof(audioreq);

   audioreq->ioa_Data     = chipnoisedata;
   audioreq->ioa_Length   = sizeof(noisedata);
   audioreq->ioa_Period   = PERIOD(440, sizeof(noisedata));
   audioreq->ioa_Volume   = 40;
   audioreq->ioa_Request.io_Flags = ADIOF_PERVOL;
   audioreq->ioa_Cycles   = 0;    /* Infinity */

   memcpy(modifyreq, audioreq, sizeof(*audioreq));
   modifyreq->ioa_Request.io_Command = ADCMD_PERVOL;

   BeginIO(&(audioreq->ioa_Request));
}
Exemplo n.º 4
0
static void gettimeofday_init(void)
{
    if (TimerMP = CreatePort(NULL, NULL)) {
        if (TimerIO = (struct timerequest *)CreateExtIO(TimerMP, sizeof(struct timerequest))) {
            if (!(OpenDevice(TIMERNAME, UNIT_MICROHZ, TimerIO, 0))) {
                TimerBase = (struct Library *)TimerIO->tr_node.io_Device;
            }
        }
    }
}
Exemplo n.º 5
0
int OpenIO(struct Window *iowin) {
	if(!(timerport=(struct MsgPort *)CreateMsgPort()))
		return(FALSE);
	if(!(timerreq=(struct timerequest *)CreateExtIO(timerport,(LONG)sizeof(struct timerequest))))
		return(FALSE);
	if(OpenTimer(timerreq)) return(FALSE);
	else timeryes=TRUE;

	if(!(conwriteport=(struct MsgPort *)CreateMsgPort()))
		return(FALSE);
	if(!(conwritereq=(struct IOStdReq *)CreateExtIO(conwriteport,(LONG)sizeof(struct IOStdReq))))
		return(FALSE);
	if(!(conreadport=(struct MsgPort *)CreateMsgPort()))
		return(FALSE);
	if(!(conreadreq=(struct IOStdReq *)CreateExtIO(conreadport,(LONG)sizeof(struct IOStdReq))))
		return(FALSE);
	if(OpenConsole(iowin))
		return(FALSE);
	else consoleyes=TRUE;

	return(TRUE);
}
Exemplo n.º 6
0
int cw_device_open(void)
{
    static int atexitinitialized = 0;
    unsigned int i;

    if (atexitinitialized) {
        cw_device_close();
    }

    gSIDs = 0;
    gSwapSIDs = FALSE;

    for (i = 0; i < 2; i++) {
        if ((gDiskPort[i] = CreatePort(NULL, 0)) != NULL) {
            if (gCatweaselReq[i] = (struct IOExtTD *)CreateExtIO(gDiskPort[i], sizeof(struct IOExtTD))) {
                if (OpenDevice("catweaselsid.device", i, (struct IORequest *)gCatweaselReq[i], 0)) {
                    DeleteExtIO((struct IORequest *)gCatweaselReq[i]);
                    DeletePort(gDiskPort[i]);
                    gCatweaselReq[i] = NULL;
                    gDiskPort[i] = NULL;
                } else {
                    gSIDs++;
                }
            }
        }
    }

    if (gSIDs == 0) {
        return -1;
    }

    if (gCatweaselReq[1] && gCatweaselReq[0] == NULL) {
        gSwapSIDs = TRUE;
    }
	
    /* install exit handler, so device is closed on exit */
    if (!atexitinitialized) {
        atexitinitialized = 1;
        atexit((voidfunc_t)cw_device_close);
    }

    sidfh = 1; /* ok */

    return 1;
}
Exemplo n.º 7
0
int opentimer()
{
	int rc=0;

	if ((TimerMP = CreatePort(0,0)))
	{
		if ((TimerIO = (struct timerequest *) CreateExtIO(TimerMP,sizeof(struct timerequest)) ))
		{
			/* Open the device once */
			if (!(OpenDevice (TIMERNAME, UNIT_VBLANK,(struct IORequest *) TimerIO, 0L)))
			{
				TimerBase = (struct Device *)TimerIO->tr_node.io_Device;
				rc = 1;
			}
		}
	}
	return rc;
}
Exemplo n.º 8
0
Arquivo: test.c Projeto: cnvogelg/axb
int main(void)
{
    struct IOStdReq *ior;
    struct MsgPort *mp;
    char buff[10];

    Printf("main\n");
    if (mp = (struct MsgPort *)CreatePort(0,0))
    {
        Printf("got port\n");
        if (ior = (struct IOStdReq *)
                       CreateExtIO(mp, sizeof(struct IOStdReq)))
        {
            Printf("got extio\n");
            if (OpenDevice("example.device",0,(struct IORequest*)ior,0) == 0)
            {
                Printf("opened device\n");

                ior->io_Data = buff;
                ior->io_Command = CMD_READ;
                ior->io_Length = 1;
                DoIO((struct IORequest *)ior);
                Printf("done read\n");

                ior->io_Data = buff;
                ior->io_Command = CMD_WRITE;
                ior->io_Length = 1;
                DoIO((struct IORequest *)ior);
                Printf("done write\n");

                CloseDevice((struct IORequest *)ior);
            }
            DeleteExtIO((struct IORequest *)ior);
        }
        DeletePort(mp);
    }
    Printf("done\n");
    return 0;
}
Exemplo n.º 9
0
int main( void )
{
	struct Process *Proc = ( struct Process * )FindTask( 0L );
	BlankMsg *FreeMsg;
	LONG ReturnVal = 0;
	
	if( Proc->pr_CLI )
	{
		STRPTR Str = BADDR((( struct CommandLineInterface * )
							BADDR( Proc->pr_CLI ))->cli_CommandName );
		CopyMem( Str + 1, PrefsPath, *Str );
		PrefsPath[*Str] = '\0';
		strcat( PrefsPath, ".prefs" );
	}
	
	IntuitionBase = OpenLibrary( "intuition.library", 37L );
	GfxBase = OpenLibrary( GRAPHICSNAME, 37L );
	GarshnelibBase = OpenLibrary( "Garshnelib.library", 37L );
	
	if( IntuitionBase && GfxBase && GarshnelibBase )
	{
		ClientPort = CreateMsgPort();
		TimerPort = CreateMsgPort();
		
		if( ClientPort && TimerPort )
		{
			TimeOutIO = ( struct timerequest * )
				CreateExtIO( TimerPort, sizeof( struct timerequest ));
			
			if( TimeOutIO && !OpenDevice( "timer.device", UNIT_VBLANK,
										 ( struct IORequest * )TimeOutIO, 0L ))
			{
				ClientPort->mp_Node.ln_Name = PortName;
				ClientPort->mp_Node.ln_Pri = 0L;
				AddPort( ClientPort );
				CurPrefs = LoadPrefs( PrefsPath );
				
				CurrentTime( &InitSecs, &InitMicros );
				RangeSeed = InitSecs + InitMicros;
				
				Blank( CurPrefs );

				while( FreeMsg = ( BlankMsg * )GetMsg( ClientPort ))
				{
					if( FreeMsg->bm_Type & BF_REPLY )
						FreeVec( FreeMsg );
					else
					{
						FreeMsg->bm_Type |= BF_REPLY;
						ReplyMsg(( struct Message * )FreeMsg );
					}
				}
				
				if( CurPrefs )
					FreeVec( CurPrefs );
			
				if( !PortRemoved )
					RemPort( ClientPort );
			}
			
			if( TimeOutIO )
			{
				if( TimeOutIO->tr_node.io_Device )
					CloseDevice(( struct IORequest * )TimeOutIO );
				DeleteExtIO(( struct IORequest * )TimeOutIO );
			}
		}
		else
		{
			Complain( "ClientPort or TimerPort failed to open." );
			ReturnVal = 2;
		}

		if( ClientPort )
		{
			BlankMsg *TmpMsg;
			while( TmpMsg = ( BlankMsg * )GetMsg( ClientPort ))
			{
				TmpMsg->bm_Flags |= BF_REPLY;
				ReplyMsg(( struct Message * )TmpMsg );
			}
			DeleteMsgPort( ClientPort );
		}

		if( TimerPort )
			DeleteMsgPort( TimerPort );
	}
	else
	{
		Complain( "A library failed to open." );
		ReturnVal = 1;
	}
	
	if( GarshnelibBase )
		CloseLibrary( GarshnelibBase );
	
	if( GfxBase )
		CloseLibrary( GfxBase );
	
	if( IntuitionBase )
		CloseLibrary( IntuitionBase );
	
	return ReturnVal;
}
Exemplo n.º 10
0
int _glfwPlatformOpenWindow( int width, int height, int redbits,
    int greenbits, int bluebits, int alphabits, int depthbits,
    int stencilbits, int mode, int accumredbits, int accumgreenbits,
    int accumbluebits, int accumalphabits, int auxbuffers, int stereo,
    int refreshrate )
{
    struct TagItem tagList[ 25 ];
    int tagNR, accumbits;

    // Calculate sum of accumulator bits
    accumbits = accumredbits + accumgreenbits + accumbluebits +
                accumalphabits;

    // Clear window state
    _glfwWin.Screen        = NULL;
    _glfwWin.Window        = NULL;
    _glfwWin.Context       = NULL;
    _glfwWin.PointerHidden = 0;
    _glfwWin.PointerSprite = NULL;
    _glfwWin.InputMP       = NULL;
    _glfwWin.InputIO       = NULL;

    // Create input.device message port
    if( !(_glfwWin.InputMP = CreatePort( NULL, 0 )) )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // Create input.device I/O request
    if( !(_glfwWin.InputIO = (struct IOStdReq *)
          CreateExtIO( _glfwWin.InputMP, sizeof(struct IOStdReq) )) )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // Open input.device (for pointer position manipulation)
    if( OpenDevice( "input.device", 0,
                    (struct IORequest *)_glfwWin.InputIO, 0 ) )
    {
        DeleteExtIO( (struct IORequest *) _glfwWin.InputIO );
        _glfwWin.InputIO = NULL;
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // Do we want fullscreen?
    if( _glfwWin.Fullscreen )
    {
        // Open a new Amiga screen
        if( !_glfwOpenScreen( &width, &height, &redbits, &greenbits,
                              &bluebits, refreshrate ) )
        {
            _glfwWin.Fullscreen = GL_FALSE;
        }
    }

    // Select window properties
    tagNR = 0;
    tagList[ tagNR   ].ti_Tag  = WA_Left;
    tagList[ tagNR++ ].ti_Data = 0;
    tagList[ tagNR   ].ti_Tag  = WA_Top;
    tagList[ tagNR++ ].ti_Data = 0;
    tagList[ tagNR   ].ti_Tag  = WA_IDCMP;
    tagList[ tagNR++ ].ti_Data = IDCMP_REFRESHWINDOW |
                                 IDCMP_CLOSEWINDOW |
                                 IDCMP_NEWSIZE |
                                 IDCMP_ACTIVEWINDOW |
                                 IDCMP_INACTIVEWINDOW |
                                 IDCMP_RAWKEY |
                                 IDCMP_MOUSEMOVE |
                                 IDCMP_MOUSEBUTTONS;
    tagList[ tagNR   ].ti_Tag  = WA_ReportMouse;
    tagList[ tagNR++ ].ti_Data = TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_RMBTrap;
    tagList[ tagNR++ ].ti_Data = TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_NoCareRefresh;
    tagList[ tagNR++ ].ti_Data = FALSE;
    tagList[ tagNR   ].ti_Tag  = WA_SimpleRefresh;
    tagList[ tagNR++ ].ti_Data = TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_Activate;
    tagList[ tagNR++ ].ti_Data = TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_CloseGadget;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? FALSE : TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_SizeGadget;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? FALSE : ( _glfwWinHints.WindowNoResize ? FALSE : TRUE );
    tagList[ tagNR   ].ti_Tag  = WA_DepthGadget;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? FALSE : TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_DragBar;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? FALSE : TRUE;
    tagList[ tagNR   ].ti_Tag  = WA_Borderless;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? TRUE : FALSE;
    tagList[ tagNR   ].ti_Tag  = WA_Backdrop;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Fullscreen ? TRUE : FALSE;
    if( _glfwWin.Fullscreen )
    {
        tagList[ tagNR   ].ti_Tag  = WA_CustomScreen;
        tagList[ tagNR++ ].ti_Data = (ULONG) _glfwWin.Screen;
        tagList[ tagNR   ].ti_Tag  = WA_Width;
        tagList[ tagNR++ ].ti_Data = width;
        tagList[ tagNR   ].ti_Tag  = WA_Height;
        tagList[ tagNR++ ].ti_Data = height;
    }
    else
    {
        tagList[ tagNR   ].ti_Tag  = WA_GimmeZeroZero;
        tagList[ tagNR++ ].ti_Data = TRUE;
        tagList[ tagNR   ].ti_Tag  = WA_InnerWidth;
        tagList[ tagNR++ ].ti_Data = width;
        tagList[ tagNR   ].ti_Tag  = WA_InnerHeight;
        tagList[ tagNR++ ].ti_Data = height;
        tagList[ tagNR   ].ti_Tag  = WA_MinWidth;
        tagList[ tagNR++ ].ti_Data = 20;
        tagList[ tagNR   ].ti_Tag  = WA_MinHeight;
        tagList[ tagNR++ ].ti_Data = 20;
        tagList[ tagNR   ].ti_Tag  = WA_MaxWidth;
        tagList[ tagNR++ ].ti_Data = 9999;
        tagList[ tagNR   ].ti_Tag  = WA_MaxHeight;
        tagList[ tagNR++ ].ti_Data = 9999;
        tagList[ tagNR   ].ti_Tag  = WA_Title;
        tagList[ tagNR++ ].ti_Data = (ULONG) "GLFW Window";
        tagList[ tagNR   ].ti_Tag  = WA_ScreenTitle;
        tagList[ tagNR++ ].ti_Data = (ULONG) "GLFW Application";
    }
    tagList[ tagNR ].ti_Tag = TAG_DONE;

    // Open window
    _glfwWin.Window = OpenWindowTagList( NULL, tagList );
    if( !_glfwWin.Window )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // Fullscreen/windowed post fixups
    if( _glfwWin.Fullscreen )
    {
        // Don't show screen title
        ShowTitle( _glfwWin.Screen, FALSE );

        // Remember window size
        _glfwWin.Width  = _glfwWin.Window->Width;
        _glfwWin.Height = _glfwWin.Window->Height;
    }
    else
    {
        // If we are not in fullscreen mode, get screen handle from window
        _glfwWin.Screen = _glfwWin.Window->WScreen;

        // Get ModeID for the current video mode
        _glfwWin.ModeID = GetVPModeID( &_glfwWin.Screen->ViewPort );

        // Remember window size
        _glfwWin.Width  = _glfwWin.Window->GZZWidth;
        _glfwWin.Height = _glfwWin.Window->GZZHeight;
    }

    // Put window on top
    WindowToFront( _glfwWin.Window );

    // Create OpenGL context
#ifdef _GLFW_STORMMESA
    tagNR = 0;
    tagList[ tagNR   ].ti_Tag  = AMA_Window;
    tagList[ tagNR++ ].ti_Data = (ULONG) _glfwWin.Window;
    tagList[ tagNR   ].ti_Tag  = AMA_RastPort;
    tagList[ tagNR++ ].ti_Data = (ULONG) _glfwWin.Window->RPort;
    tagList[ tagNR   ].ti_Tag  = AMA_Screen;
    tagList[ tagNR++ ].ti_Data = (ULONG) _glfwWin.Screen;
    tagList[ tagNR   ].ti_Tag  = AMA_Left;
    tagList[ tagNR++ ].ti_Data = 0;
    tagList[ tagNR   ].ti_Tag  = AMA_Bottom;
    tagList[ tagNR++ ].ti_Data = 0;
    tagList[ tagNR   ].ti_Tag  = AMA_Width;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Width;
    tagList[ tagNR   ].ti_Tag  = AMA_Height;
    tagList[ tagNR++ ].ti_Data = _glfwWin.Height;
    tagList[ tagNR   ].ti_Tag  = AMA_DoubleBuf;
    tagList[ tagNR++ ].ti_Data = GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_RGBMode;
    tagList[ tagNR++ ].ti_Data = GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_AlphaFlag;
    tagList[ tagNR++ ].ti_Data = alphabits ? GL_TRUE : GL_FALSE;
    tagList[ tagNR   ].ti_Tag  = AMA_NoDepth;
    tagList[ tagNR++ ].ti_Data = depthbits ? GL_FALSE : GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_NoStencil;
    tagList[ tagNR++ ].ti_Data = stencilbits ? GL_FALSE : GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_NoAccum;
    tagList[ tagNR++ ].ti_Data = accumbits ? GL_FALSE : GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_DirectRender;
    tagList[ tagNR++ ].ti_Data = GL_TRUE;
    tagList[ tagNR   ].ti_Tag  = AMA_DrawMode;
    tagList[ tagNR++ ].ti_Data = AMESA_AGA_C2P;
    tagList[ tagNR   ].ti_Tag  = TAG_DONE;
    _glfwWin.Context = AmigaMesaCreateContext( tagList );
#endif
    if( !_glfwWin.Context )
    {
        _glfwPlatformCloseWindow();
        return GL_FALSE;
    }

    // Make current
#ifdef _GLFW_STORMMESA
    AmigaMesaMakeCurrent( _glfwWin.Context, _glfwWin.Context->buffer );
#endif

    return GL_TRUE;
}
Exemplo n.º 11
0
struct IOStdReq *CreateStdIO (struct MsgPort *port)
{
    return (struct IOStdReq *)CreateExtIO (port, sizeof (struct IOStdReq));
}
Exemplo n.º 12
0
void main(int argc,char *argv[]) {
   int unit;

   char *devicename; /* ML */

   if (argc!=2 && argc!=3) exit(0);
   unit = argv[1][0]-'0';
   if (unit!=0 && unit!=1) exit(0);

   port = (struct MsgPort *)CreatePort(0,0);
   if (!port) exit(10);

   req = (struct IOStdReq *)CreateExtIO(port, sizeof(struct IOExtTD));
   if (!req) exit(11);

   devicename="ide.device";  /* ML */
   if (argc==3) devicename=argv[2]; /* ML */
   if (OpenDevice (devicename,unit,(struct IORequest *)req,0)) exit(12);

   mu = (struct MyUnit *)req->io_Unit;
   if (argc==2) {
      printf("Device %d:\n",mu->mdu_UnitNum);
      if (mu->mdu_drv_type==ATAPI_DRV) {
         printf("  ATAPI device\n");
         printf("  Motor is          : ");
         if (mu->mdu_motor==0) printf("OFF\n"); else printf("ON\n");
         printf("  Disk change count : %d\n",mu->mdu_change_cnt);
         printf("  Disk inserted     : ");
         if (mu->mdu_no_disk==0) printf("YES\n"); else printf("NO\n");
      }
      else if (mu->mdu_drv_type==ATA_DRV) {
         printf("  ATA device\n");
         if (mu->mdu_lba) {
            printf("  LBA");
            if (mu->mdu_numlba) printf(" - %d user addressable sectors\n",mu->mdu_numlba);
            else printf("\n");
         } else printf("  no LBA\n");
         printf("  Sectors per track : %d\n",mu->mdu_sectors_per_track);
         printf("  Heads             : %d\n",mu->mdu_heads);
         printf("  Cylinders         : %d\n",mu->mdu_cylinders);
         printf("  Size              : %d MB\n",mu->mdu_sectors_per_track*mu->mdu_heads*mu->mdu_cylinders/2048);
         printf("  Motor is          : ");
         if (mu->mdu_motor==0) printf("OFF\n"); else printf("ON\n");
      }
      else printf("  not present\n",unit);
      if (mu->mdu_drv_type!=UNKNOWN_DRV && mu->mdu_auto) {
         printf("  Serial number     : %s\n",mu->mdu_ser_num);
         printf("  Firmware revision : %s\n",mu->mdu_firm_rev);
         printf("  Model number      : %s\n",mu->mdu_model_num);
      }
   }
   else {
      sprintf(hlp,"Ram:Drive%d",unit);
      if ((fd = fopen(hlp,"w"))!=NULL) {
         if (mu->mdu_drv_type==ATAPI_DRV) {
            fprintf(fd,"ATAPI\n");
         }
         else if (mu->mdu_drv_type==ATA_DRV) {
            fprintf(fd,"ATA\n");
            if (mu->mdu_lba) {
               fprintf(fd,"LBA %d\n",mu->mdu_numlba);
            } else fprintf(fd,"noLBA 0\n");
            fprintf(fd,"%d\n",mu->mdu_sectors_per_track);
            fprintf(fd,"%d\n",mu->mdu_heads);
            fprintf(fd,"%d\n",mu->mdu_cylinders);
            fprintf(fd,"%d\n",mu->mdu_sectors_per_track*mu->mdu_heads*mu->mdu_cylinders/2048);
         }
         else fprintf(fd,"NONE\n");
         if (mu->mdu_drv_type!=UNKNOWN_DRV) {
            if (mu->mdu_auto) {
               fprintf(fd,"[%s]\n",mu->mdu_ser_num);
               fprintf(fd,"[%s]\n",mu->mdu_firm_rev);
               fprintf(fd,"[%s]\n",mu->mdu_model_num);
            }
            else fprintf(fd,"X\nX\nX\n");
         }
      }
      fclose(fd);
   }

   CloseDevice((struct IORequest *)req);
   DeleteExtIO((struct IORequest *)req);
   DeletePort(port);
   exit(0);
}
Exemplo n.º 13
0
int main(int argc, const char ** argv)
{
    struct IntuiMessage *winmsg;
    ULONG signals, conreadsig, windowsig;
    LONG lch;
    WORD InControl = 0;
    BOOL Done = FALSE;
    UBYTE ch, ibuf;
    UBYTE obuf[200];
    BYTE error;

    FromWb = (argc==0L) ? TRUE : FALSE;

    if(!(IntuitionBase=OpenLibrary("intuition.library",0)))
         cleanexit("Can't open intuition\n",RETURN_FAIL);

    /* Create reply port and io block for writing to console */
    if(!(writePort = CreatePort("RKM.console.write",0)))
         cleanexit("Can't create write port\n",RETURN_FAIL);

    if(!(writeReq = (struct IOStdReq *)
                    CreateExtIO(writePort,(LONG)sizeof(struct IOStdReq))))
         cleanexit("Can't create write request\n",RETURN_FAIL);

    /* Create reply port and io block for reading from console */
    if(!(readPort = CreatePort("RKM.console.read",0)))
         cleanexit("Can't create read port\n",RETURN_FAIL);

    if(!(readReq = (struct IOStdReq *)
                   CreateExtIO(readPort,(LONG)sizeof(struct IOStdReq))))
         cleanexit("Can't create read request\n",RETURN_FAIL);

    /* Open a window */
    if(!(win = OpenWindow(&nw)))
         cleanexit("Can't open window\n",RETURN_FAIL);

    /* Now, attach a console to the window */
    if(error = OpenConsole(writeReq,readReq,win))
         cleanexit("Can't open console.device\n",RETURN_FAIL);
    else OpenedConsole = TRUE;

    /* Demonstrate some console escape sequences */
    ConPuts(writeReq,"Here's some normal text\n");
    sprintf(obuf,"%s%sHere's text in color 3 & italics\n",COLOR03,ITALICS);
    ConPuts(writeReq,obuf);
    ConPuts(writeReq,NORMAL);
    Delay(50);      /* Delay for dramatic demo effect */
    ConPuts(writeReq,"We will now delete this asterisk =*=");
    Delay(50);
    ConPuts(writeReq,"\b\b");  /* backspace twice */
    Delay(50);
    ConPuts(writeReq,DELCHAR); /* delete the character */
    Delay(50);

    QueueRead(readReq,&ibuf); /* send the first console read request */

    ConPuts(writeReq,"\n\nNow reading console\n");
    ConPuts(writeReq,"Type some keys.  Close window when done.\n\n");

    conreadsig = 1 << readPort->mp_SigBit;
    windowsig = 1 << win->UserPort->mp_SigBit;

    while(!Done)
        {
        /* A character, or an IDCMP msg, or both could wake us up */
        signals = Wait(conreadsig|windowsig);

        /* If a console signal was received, get the character */
        if (signals & conreadsig)
            {
            if((lch = ConMayGetChar(readPort,&ibuf)) != -1)
                {
                ch = lch;
                /* Show hex and ascii (if printable) for char we got.
                 * If you want to parse received control sequences, such as
                 * function or Help keys,you would buffer control sequences
                 * as you receive them, starting to buffer whenever you
                 * receive 0x9B (or 0x1B[ for user-typed sequences) and
                 * ending when you receive a valid terminating character
                 * for the type of control sequence you are receiving.
                 * For CSI sequences, valid terminating characters
                 * are generally 0x40 through 0x7E.
                 * In our example, InControl has the following values:
                 * 0 = no, 1 = have 0x1B, 2 = have 0x9B OR 0x1B and [,
                 * 3 = now inside control sequence, -1 = normal end esc,
                 * -2 = non-CSI(no [) 0x1B end esc
                 * NOTE - a more complex parser is required to recognize
                 *  other types of control sequences.
                 */

                /* 0x1B ESC not followed by '[', is not CSI seq */
                if (InControl==1)
                    {
                    if(ch=='[') InControl = 2;
                    else InControl = -2;
                    }

                if ((ch==0x9B)||(ch==0x1B))  /* Control seq starting */
                    {
                    InControl = (ch==0x1B) ? 1 : 2;
                    ConPuts(writeReq,"=== Control Seq ===\n");
                    }

                /* We'll show value of this char we received */
                if (((ch >= 0x1F)&&(ch <= 0x7E))||(ch >= 0xA0))
                   sprintf(obuf,"Received: hex %02x = %c\n",ch,ch);
                else sprintf(obuf,"Received: hex %02x\n",ch);
                ConPuts(writeReq,obuf);

                /* Valid ESC sequence terminator ends an ESC seq */
                if ((InControl==3)&&((ch >= 0x40) && (ch <= 0x7E)))
                    {
                    InControl = -1;
                    }
                if (InControl==2) InControl = 3;
                /* ESC sequence finished (-1 if OK, -2 if bogus) */
                if (InControl < 0)
                    {
                    InControl = 0;
                    ConPuts(writeReq,"=== End Control ===\n");
                    }
                }
            }

        /* If IDCMP messages received, handle them */
        if (signals & windowsig)
            {
            /* We have to ReplyMsg these when done with them */
            while (winmsg = (struct IntuiMessage *)GetMsg(win->UserPort))
                {
                switch(winmsg->Class)
                    {
                    case IDCMP_CLOSEWINDOW:
                      Done = TRUE;
                      break;
                    default:
                      break;
                     }
                ReplyMsg((struct Message *)winmsg);
                }
            }
        }

    /* We always have an outstanding queued read request
     * so we must abort it if it hasn't completed,
     * and we must remove it.
     */
    if(!(CheckIO(readReq)))  AbortIO(readReq);
    WaitIO(readReq);     /* clear it from our replyport */

    cleanup();
    exit(RETURN_OK);
    }