www.xbdev.net xbdev - software development
Friday December 14, 2018
home | about | contact | Donations

     
 

OpenXDK

The Free, Legal, Open Source XBox Development Kit...

 

File Output - Fantastically Simple!

 

Writing and reading to a file, allows us to save and read in data.  Or as I usually use file access for, is writing debug information :)  I know, its not the best method, but sometimes code can crash and writing the reason to a file can be useful :)

 

Download Project Code - File Output

 

// Basic writing to a file

 

#include <openxdk.h>

 

// Interesting thing, depending which directories and libs you've got added

// in Tools->Options in the VC++ Directories - I've only got:

//

//    "Include files" -> C:\OpenXDK\include\

//    "Library files" -> C:\OpenXDK\lib\

//    "Executable files" -> C:\OpenXDK\bin\

// as I was following the doc setup, which means I have to specify the

// full path of the stdio.h file if I want to use i/o functions.  Alternatively

// just add the extra path to your include above, so you get away with <stdio.h>

 

#include    "OpenXDK\include\xlibc\stdio.h"   // _open, _close etc...

#include    <string.h>                        // strlen(..)

 

VOID XBoxStartup()

{

      char Buffer[] = "Test text - simple but sweet";

 

      // These file functions are defined in stdio.h

      // e.g. int _open( char *filename, int oflag, int permission );

      int handle = _open( "D:\\test.txt", _O_RDWR|_O_BINARY|_O_CREAT|_O_TRUNC, 0 );

      int AmountRead = _write( handle, &Buffer[0], strlen(&Buffer[0]) );

      _close( handle );

     

      HalReturnToFirmware(ReturnFirmwareFatal);

}// End

 

 

Is that all?  Yup thats all there is to it.... later on I'm sure the openxdk will also implement the fopen and fclose library functions...but for know we can use these :)

 
 Visitor: 9534626  { 209.237.238.175 } Copyright (c) 2002-2017 xbdev.net - All rights reserved.
Designated tutorial and software are the property of their respective owners.