Sigrid Haflínudóttirfirst dirty version of the portd7ad0686 years agoHistory
4217 lines · 94.7 KB · C
RawDownload
/*	OSGLUSD2.c 	Copyright (C) 2012 Paul C. Pratt, Manuel Alfayate 	You can redistribute this file and/or modify it under the terms	of version 2 of the GNU General Public License as published by	the Free Software Foundation.  You should have received a copy	of the license along with this file; see the file COPYING. 	This file is distributed in the hope that it will be useful,	but WITHOUT ANY WARRANTY; without even the implied warranty of	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	license for more details.*/ /*	Operating System GLUe for SDl 2.0 library 	All operating system dependent code for the	SDL Library should go here.*/ #include "CNFGRAPI.h"#include "SYSDEPNS.h"#include "ENDIANAC.h" #include "MYOSGLUE.h" #include "STRCONST.h" /* --- some simple utilities --- */ GLOBALOSGLUPROC MyMoveBytes(anyp srcPtr, anyp destPtr, si5b byteCount){	(void) memcpy((char *)destPtr, (char *)srcPtr, byteCount);} /* --- control mode and internationalization --- */ #define NeedCell2PlainAsciiMap 1 #include "INTLCHAR.h" #ifndef CanGetAppPath#define CanGetAppPath 1#endif LOCALVAR char *d_arg = NULL;LOCALVAR char *n_arg = NULL; #if CanGetAppPathLOCALVAR char *app_parent = NULL;LOCALVAR char *pref_dir = NULL;#endif #ifdef _WIN32#define MyPathSep '\\'#else#define MyPathSep '/'#endif LOCALFUNC tMacErr ChildPath(char *x, char *y, char **r){	tMacErr err = mnvm_miscErr;	int nx = strlen(x);	int ny = strlen(y);	{		if ((nx > 0) && (MyPathSep == x[nx - 1])) {			--nx;		}		{			int nr = nx + 1 + ny;			char *p = malloc(nr + 1);			if (p != NULL) {				char *p2 = p;				(void) memcpy(p2, x, nx);				p2 += nx;				*p2++ = MyPathSep;				(void) memcpy(p2, y, ny);				p2 += ny;				*p2 = 0;				*r = p;				err = mnvm_noErr;			}		}	} 	return err;} LOCALPROC MyMayFree(char *p){	if (NULL != p) {		free(p);	}} /* --- sending debugging info to file --- */ #if dbglog_HAVE #ifndef dbglog_ToStdErr#define dbglog_ToStdErr 0#endif#ifndef dbglog_ToSDL_Log#define dbglog_ToSDL_Log 0#endif #if ! dbglog_ToStdErrLOCALVAR FILE *dbglog_File = NULL;#endif LOCALFUNC blnr dbglog_open0(void){#if dbglog_ToStdErr || dbglog_ToSDL_Log	return trueblnr;#else	if (NULL == app_parent) {		dbglog_File = fopen("dbglog.txt", "w");	} else {		char *t; 		if (mnvm_noErr == ChildPath(app_parent, "dbglog.txt", &t)) {			dbglog_File = fopen(t, "w");			free(t);		}	} 	return (NULL != dbglog_File);#endif} LOCALPROC dbglog_write0(char *s, uimr L){#if dbglog_ToStdErr	(void) fwrite(s, 1, L, stderr);#elif dbglog_ToSDL_Log	char t[256 + 1]; 	if (L > 256) {		L = 256;	}	(void) memcpy(t, s, L);	t[L] = 1; 	SDL_Log("%s", t);#else	if (dbglog_File != NULL) {		(void) fwrite(s, 1, L, dbglog_File);	}#endif} LOCALPROC dbglog_close0(void){#if ! dbglog_ToStdErr	if (dbglog_File != NULL) {		fclose(dbglog_File);		dbglog_File = NULL;	}#endif} #endif /* --- information about the environment --- */ #define WantColorTransValid 0 #include "COMOSGLU.h" #include "PBUFSTDC.h" #include "CONTROLM.h" /* --- text translation --- */ LOCALPROC NativeStrFromCStr(char *r, char *s){	ui3b ps[ClStrMaxLength];	int i;	int L; 	ClStrFromSubstCStr(&L, ps, s); 	for (i = 0; i < L; ++i) {		r[i] = Cell2PlainAsciiMap[ps[i]];	} 	r[L] = 0;} /* --- drives --- */ #define NotAfileRef NULL #ifndef UseRWops#define UseRWops 0#endif #if UseRWops#define MyFilePtr SDL_RWops *#define MySeek SDL_RWseek#define MySeekSet RW_SEEK_SET#define MySeekCur RW_SEEK_CUR#define MySeekEnd RW_SEEK_END#define MyFileRead(ptr, size, nmemb, stream) \	SDL_RWread(stream, ptr, size, nmemb)#define MyFileWrite(ptr, size, nmemb, stream) \	SDL_RWwrite(stream, ptr, size, nmemb)#define MyFileTell SDL_RWtell#define MyFileClose SDL_RWclose#define MyFileOpen SDL_RWFromFile#else#define MyFilePtr FILE *#define MySeek fseek#define MySeekSet SEEK_SET#define MySeekCur SEEK_CUR#define MySeekEnd SEEK_END#define MyFileRead fread#define MyFileWrite fwrite#define MyFileTell ftell#define MyFileClose fclose#define MyFileOpen fopen#define MyFileEof feof#endif LOCALVAR MyFilePtr Drives[NumDrives]; /* open disk image files */ LOCALPROC InitDrives(void){	/*		This isn't really needed, Drives[i] and DriveNames[i]		need not have valid values when not vSonyIsInserted[i].	*/	tDrive i; 	for (i = 0; i < NumDrives; ++i) {		Drives[i] = NotAfileRef;	}} GLOBALOSGLUFUNC tMacErr vSonyTransfer(blnr IsWrite, ui3p Buffer,	tDrive Drive_No, ui5r Sony_Start, ui5r Sony_Count,	ui5r *Sony_ActCount){	tMacErr err = mnvm_miscErr;	MyFilePtr refnum = Drives[Drive_No];	ui5r NewSony_Count = 0; 	if (MySeek(refnum, Sony_Start, MySeekSet) >= 0) {		if (IsWrite) {			NewSony_Count = MyFileWrite(Buffer, 1, Sony_Count, refnum);		} else {			NewSony_Count = MyFileRead(Buffer, 1, Sony_Count, refnum);		} 		if (NewSony_Count == Sony_Count) {			err = mnvm_noErr;		}	} 	if (nullpr != Sony_ActCount) {		*Sony_ActCount = NewSony_Count;	} 	return err; /*& figure out what really to return &*/} GLOBALOSGLUFUNC tMacErr vSonyGetSize(tDrive Drive_No, ui5r *Sony_Count){	tMacErr err = mnvm_miscErr;	MyFilePtr refnum = Drives[Drive_No];	long v; 	if (MySeek(refnum, 0, MySeekEnd) >= 0) {		v = MyFileTell(refnum);		if (v >= 0) {			*Sony_Count = v;			err = mnvm_noErr;		}	} 	return err; /*& figure out what really to return &*/} LOCALFUNC tMacErr vSonyEject0(tDrive Drive_No, blnr deleteit){	MyFilePtr refnum = Drives[Drive_No]; 	DiskEjectedNotify(Drive_No); 	MyFileClose(refnum);	Drives[Drive_No] = NotAfileRef; /* not really needed */ 	return mnvm_noErr;} GLOBALOSGLUFUNC tMacErr vSonyEject(tDrive Drive_No){	return vSonyEject0(Drive_No, falseblnr);} LOCALPROC UnInitDrives(void){	tDrive i; 	for (i = 0; i < NumDrives; ++i) {		if (vSonyIsInserted(i)) {			(void) vSonyEject(i);		}	}} LOCALFUNC blnr Sony_Insert0(MyFilePtr refnum, blnr locked,	char *drivepath){	tDrive Drive_No;	blnr IsOk = falseblnr; 	if (! FirstFreeDisk(&Drive_No)) {		MacMsg(kStrTooManyImagesTitle, kStrTooManyImagesMessage,			falseblnr);	} else {		/* printf("Sony_Insert0 %d\n", (int)Drive_No); */ 		{			Drives[Drive_No] = refnum;			DiskInsertNotify(Drive_No, locked); 			IsOk = trueblnr;		}	} 	if (! IsOk) {		MyFileClose(refnum);	} 	return IsOk;} LOCALFUNC blnr Sony_Insert1(char *drivepath, blnr silentfail){	blnr locked = falseblnr;	/* printf("Sony_Insert1 %s\n", drivepath); */	MyFilePtr refnum = MyFileOpen(drivepath, "rb+");	if (NULL == refnum) {		locked = trueblnr;		refnum = MyFileOpen(drivepath, "rb");	}	if (NULL == refnum) {		if (! silentfail) {			MacMsg(kStrOpenFailTitle, kStrOpenFailMessage, falseblnr);		}	} else {		return Sony_Insert0(refnum, locked, drivepath);	}	return falseblnr;} LOCALFUNC tMacErr LoadMacRomFrom(char *path){	tMacErr err;	MyFilePtr ROM_File;	int File_Size; 	ROM_File = MyFileOpen(path, "rb");	if (NULL == ROM_File) {		err = mnvm_fnfErr;	} else {		File_Size = MyFileRead(ROM, 1, kROM_Size, ROM_File);		if (File_Size != kROM_Size) {#ifdef MyFileEof			if (MyFileEof(ROM_File))#else			if (File_Size > 0)#endif			{				MacMsgOverride(kStrShortROMTitle,					kStrShortROMMessage);				err = mnvm_eofErr;			} else {				MacMsgOverride(kStrNoReadROMTitle,					kStrNoReadROMMessage);				err = mnvm_miscErr;			}		} else {			err = ROM_IsValid();		}		MyFileClose(ROM_File);	} 	return err;} LOCALFUNC blnr Sony_Insert1a(char *drivepath, blnr silentfail){	blnr v; 	if (! ROM_loaded) {		v = (mnvm_noErr == LoadMacRomFrom(drivepath));	} else {		v = Sony_Insert1(drivepath, silentfail);	} 	return v;} LOCALFUNC blnr Sony_Insert2(char *s){	char *d =#if CanGetAppPath		(NULL == d_arg) ? app_parent :#endif		d_arg;	blnr IsOk = falseblnr; 	if (NULL == d) {		IsOk = Sony_Insert1(s, trueblnr);	} else {		char *t; 		if (mnvm_noErr == ChildPath(d, s, &t)) {			IsOk = Sony_Insert1(t, trueblnr);			free(t);		}	} 	return IsOk;} LOCALFUNC blnr Sony_InsertIth(int i){	blnr v; 	if ((i > 9) || ! FirstFreeDisk(nullpr)) {		v = falseblnr;	} else {		char s[] = "disk?.dsk"; 		s[4] = '0' + i; 		v = Sony_Insert2(s);	} 	return v;} LOCALFUNC blnr LoadInitialImages(void){	if (! AnyDiskInserted()) {		int i; 		for (i = 1; Sony_InsertIth(i); ++i) {			/* stop on first error (including file not found) */		}	} 	return trueblnr;} /* --- ROM --- */ LOCALVAR char *rom_path = NULL; #if CanGetAppPathLOCALFUNC tMacErr LoadMacRomFromPrefDir(void){	tMacErr err;	char *t = NULL;	char *t2 = NULL; 	if (NULL == pref_dir) {		err = mnvm_fnfErr;	} else	if (mnvm_noErr != (err =		ChildPath(pref_dir, "mnvm_rom", &t)))	{		/* fail */	} else	if (mnvm_noErr != (err =		ChildPath(t, RomFileName, &t2)))	{		/* fail */	} else	{		err = LoadMacRomFrom(t2);	} 	MyMayFree(t2);	MyMayFree(t); 	return err;}#endif #if CanGetAppPathLOCALFUNC tMacErr LoadMacRomFromAppPar(void){

Lines 1–500 of 4217.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t