View Single Post
Old 04-15-2005, 10:06   #1 (permalink)
Acidmrp
No Life Poster
 
Acidmrp's Avatar
 
Join Date: Sep 2002
Location: EEPROM damaged
Age: 40
Posts: 578
Member: 15315
Status: Offline
Thanks Meter: 1
x65 patching technical discussion

Ok, I do the beginning. Please Post only technical articles here.

@Mod please make this sticky

File Handling

fopen
Code:
typedef int (*g_fopen)(const char * cFileName, unsigned int iFileFlags, unsigned int iFileMode, unsigned int *ErrorNumber);
g_fopen fopen = (g_fopen)(0xA1230050); // S65 FW47
// Pattern: FE402DE90270A0E10160A0E10350A0E10040A0E1????????0030E0E304308DE500508DE52CC090E5
fclose
Code:
typedef void (*g_fclose)(int FileHandler, unsigned int *ErrorNumber);
g_fclose fclose = (g_fclose)(0xA122FFA4); // S65 FW47
// Pattern: 38402DE90150A0E10040A0E1????????00C090E5
fflush
Code:
typedef void (*g_fflush)(int FileHandler, unsigned int *ErrorNumber);
g_fflush fflush = (g_fflush)(0xA122FFD4); // S65 FW47
// Pattern: 38402DE90150A0E10040A0E1????????08C090E5
lseek
Code:
typedef unsigned int (*g_lseek)(int FileHandler, unsigned int offset, unsigned int origin, unsigned int *ErrorNumber);
// g_lseek lseek = (g_lseek)(0xA1230004); // S65 FW47
// Pattern: FF412DE928509DE50280A0E10170A0E10360A0E10040A0E1
fread
Code:
typedef void (*g_fread)(int FileHandler, char *cBuffer, int iByteCount, unsigned int *ErrorNumber);
g_fread fread = (g_fread)(0xA1230090); // S65 FW47
// Pattern: FE402DE90270A0E10160A0E10350A0E10040A0E1????????0030E0E304308DE500508DE530C090E5
fwrite
Code:
typedef void (*g_fwrite)(int FileHandler, const char * cBuffer, int iByteCount, unsigned int *ErrorNumber);
g_fwrite fwrite = (g_fwrite)(0xA1230178); // S65 FW47
// Pattern: FE402DE90270A0E10160A0E10350A0E10040A0E1????????0030E0E304308DE500508DE55CC090E5
SetFileSize
Code:
typedef void (*g_SetFileSize)(int FileHandler, unsigned int iNewFileSize, unsigned int *ErrorNumber);
g_SetFileSize SetFileSize = (g_SetFileSize)(0xA12300D0); // S65 FW47
// Pattern: 7C402DE90160A0E10250A0E10040A0E1????????0030E0E300308DE544C090E5
Constants

Seek
Code:
#define S_SET 0
#define S_CUR 1
#define S_END 2
Permissions
Code:
#define P_WRITE 0x100
#define P_READ 0x80
Access
Code:
#define A_ReadOnly 0
#define A_WriteOnly 1
#define A_ReadWrite 2 
#define A_NoShare 4     
#define A_Append 8
#define A_Exclusive 0x10
#define A_MMCStream 0x20
#define A_Create 0x100
#define A_Truncate 0x200
#define A_FailCreateOnExist 0x400
#define A_FailOnReopen 0x800

#define A_TXT 0x4000
#define A_BIN  0x8000
Sample - File Read

Code:
	int iFileHandler
        unsigned int iError;
        unsigned int iFileSize;
        unsigned int iFilePos;
        char *cFileOutput = (char*)0xA8100000;

	// file read example:
	iFileHandler = fopen("0:\\test.bin\0", A_ReadOnly, P_READ, &iError);	

	if (iFileHandler != -1) {
		// get the file size:
		iFileSize = lseek(iFileHandler, 0, S_END, &iError);
		
		if (iFileSize > 0) {
		
			// seek the beginning of the file:
		    iFilePos = lseek(iFileHandler, 0, S_SET, &iError);

	            // read complete file:
		   fread(iFileHandler, cFileOutput, iFileSize, &iError);
		}
		
		// close the file
		fclose(iFileHandler, &iError);
	} else {
		// File not found
	}
Sample - File Write

Code:
	int iFileHandler
        unsigned int iError;
        unsigned int iFileSize;
        unsigned int iFilePos;
        char *cFileOutput = (char*)0xA8100000;

	// create file if it does not exist:
	iFileHandler = fopen("0:\\outfile.txt\0", A_Create, P_WRITE, &iError);	
	fclose(iFileHandler, &iError);
	
	iFileHandler = fopen("0:\\outfile.txt\0", A_WriteOnly, P_WRITE, &iError);	
	if (iFileHandler != -1) {
		// search the end of the file
		iFileSize = lseek(iFileHandler, 0, S_END, &iError);
		// add an line
  		fwrite(iFileHandler, "new line\x0D\x0A", 10, &iError);		

		// close the file
		fclose(iFileHandler, &iError);
	}
  Reply With Quote
 
Page generated in 0.12432 seconds with 6 queries