Sigrid Haflínudóttirfirst dirty version of the portd7ad0686 years agoHistory
1387 lines · 25.9 KB · C
RawDownload
/*	OSGLUNDS.c 	Copyright (C) 2012 Lazyone, Paul C. Pratt 	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 Nintendo DS*/ #include "CNFGRAPI.h"#include "SYSDEPNS.h"#include "ENDIANAC.h" #include "MYOSGLUE.h" #include "STRCONST.h" #include "FB1BPP2I.h" #define CONSOLE_TRACE() \	fprintf(stderr, "%s() at line %d\n", __FUNCTION__, __LINE__) /* --- some simple utilities --- */ GLOBALOSGLUPROC MyMoveBytes(anyp srcPtr, anyp destPtr, si5b byteCount){	(void) memcpy((char *)destPtr, (char *)srcPtr, byteCount);} /*	Nintendo DS port globals*/#define DS_ScreenWidth 256#define DS_ScreenHeight 192 LOCALVAR volatile int VBlankCounter = 0;LOCALVAR volatile int HBlankCounter = 0;LOCALVAR volatile unsigned int TimerBaseMSec = 0;LOCALVAR Keyboard* DSKeyboard = NULL;LOCALVAR volatile int LastKeyboardKey = NOKEY;LOCALVAR volatile int KeyboardKey = NOKEY;LOCALVAR volatile int KeysHeld = 0;LOCALVAR volatile int CursorX = 0;LOCALVAR volatile int CursorY = 0;LOCALVAR int Display_bg2_Main = 0; /* --- control mode and internationalization --- */ #define NeedCell2PlainAsciiMap 1 #include "INTLCHAR.h" /* --- sending debugging info to file --- */ #if dbglog_HAVE #define dbglog_ToStdErr 1 #if ! dbglog_ToStdErrLOCALVAR FILE *dbglog_File = NULL;#endif LOCALFUNC blnr dbglog_open0(void){#if dbglog_ToStdErr	return trueblnr;#else	dbglog_File = fopen("dbglog.txt", "w");	return (NULL != dbglog_File);#endif} LOCALPROC dbglog_write0(char *s, uimr L){#if dbglog_ToStdErr	(void) fwrite(s, 1, L, stderr);#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 /* --- debug settings and utilities --- */ #if ! dbglog_HAVE#define WriteExtraErr(s)#elseLOCALPROC WriteExtraErr(char *s){	dbglog_writeCStr("*** error: ");	dbglog_writeCStr(s);	dbglog_writeReturn();}#endif /* --- information about the environment --- */ #define WantColorTransValid 0 #include "COMOSGLU.h"#include "CONTROLM.h" 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 LOCALVAR FILE *Drives[NumDrives]; /* open disk image files */#if IncludeSonyGetName || IncludeSonyNewLOCALVAR char *DriveNames[NumDrives];#endif 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;#if IncludeSonyGetName || IncludeSonyNew		DriveNames[i] = NULL;#endif	}} GLOBALOSGLUFUNC tMacErr vSonyTransfer(blnr IsWrite, ui3p Buffer,	tDrive Drive_No, ui5r Sony_Start, ui5r Sony_Count,	ui5r *Sony_ActCount){	tMacErr err = mnvm_miscErr;	FILE *refnum = Drives[Drive_No];	ui5r NewSony_Count = 0; 	if (0 == fseek(refnum, Sony_Start, SEEK_SET)) {		if (IsWrite) {			NewSony_Count = fwrite(Buffer, 1, Sony_Count, refnum);		} else {			NewSony_Count = fread(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;	FILE *refnum = Drives[Drive_No];	long v; 	if (0 == fseek(refnum, 0, SEEK_END)) {		v = ftell(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){	FILE *refnum = Drives[Drive_No]; 	DiskEjectedNotify(Drive_No); 	fclose(refnum);	Drives[Drive_No] = NotAfileRef; /* not really needed */ #if IncludeSonyGetName || IncludeSonyNew	{		char *s = DriveNames[Drive_No];		if (NULL != s) {			if (deleteit) {				remove(s);			}			free(s);			DriveNames[Drive_No] = NULL; /* not really needed */		}	}#endif 	return mnvm_noErr;} GLOBALOSGLUFUNC tMacErr vSonyEject(tDrive Drive_No){	return vSonyEject0(Drive_No, falseblnr);} #if IncludeSonyNewGLOBALOSGLUFUNC tMacErr vSonyEjectDelete(tDrive Drive_No){	return vSonyEject0(Drive_No, trueblnr);}#endif LOCALPROC UnInitDrives(void){	tDrive i; 	for (i = 0; i < NumDrives; ++i) {		if (vSonyIsInserted(i)) {			(void) vSonyEject(i);		}	}} #if IncludeSonyGetNameGLOBALOSGLUFUNC tMacErr vSonyGetName(tDrive Drive_No, tPbuf *r){	char *drivepath = DriveNames[Drive_No];	if (NULL == drivepath) {		return mnvm_miscErr;	} else {		char *s = strrchr(drivepath, '/');		if (NULL == s) {			s = drivepath;		} else {			++s;		}		return NativeTextToMacRomanPbuf(s, r);	}}#endif LOCALFUNC blnr Sony_Insert0(FILE *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); #if IncludeSonyGetName || IncludeSonyNew			{				ui5b L = strlen(drivepath);				char *p = malloc(L + 1);				if (p != NULL) {					(void) memcpy(p, drivepath, L + 1);				}				DriveNames[Drive_No] = p;			}#endif 			IsOk = trueblnr;		}	} 	if (! IsOk) {		fclose(refnum);	} 	return IsOk;} LOCALFUNC blnr Sony_Insert1(char *drivepath, blnr silentfail){	blnr locked = falseblnr;	/* printf("Sony_Insert1 %s\n", drivepath); */	FILE *refnum = fopen(drivepath, "rb+");	if (NULL == refnum) {		locked = trueblnr;		refnum = fopen(drivepath, "rb");		CONSOLE_TRACE();	}	if (NULL == refnum) {		if (! silentfail) {			MacMsg(kStrOpenFailTitle, kStrOpenFailMessage, falseblnr);			CONSOLE_TRACE();		}	} else {		CONSOLE_TRACE();		return Sony_Insert0(refnum, locked, drivepath);	} 	return falseblnr;} #define Sony_Insert2(s) Sony_Insert1(s, trueblnr) 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){	int i; 	CONSOLE_TRACE(); 	for (i = 1; Sony_InsertIth(i); ++i) {		/* stop on first error (including file not found) */	} 	return trueblnr;} #if IncludeSonyNewLOCALFUNC blnr WriteZero(FILE *refnum, ui5b L){#define ZeroBufferSize 2048	ui5b i;	ui3b buffer[ZeroBufferSize]; 	memset(&buffer, 0, ZeroBufferSize); 	while (L > 0) {		i = (L > ZeroBufferSize) ? ZeroBufferSize : L;		if (fwrite(buffer, 1, i, refnum) != i) {			return falseblnr;		}		L -= i;	}	return trueblnr;}#endif #if IncludeSonyNewLOCALPROC MakeNewDisk(ui5b L, char *drivepath){	blnr IsOk = falseblnr;	FILE *refnum = fopen(drivepath, "wb+");	if (NULL == refnum) {		MacMsg(kStrOpenFailTitle, kStrOpenFailMessage, falseblnr);	} else {		if (WriteZero(refnum, L)) {			IsOk = Sony_Insert0(refnum, falseblnr, drivepath);			refnum = NULL;		}		if (refnum != NULL) {			fclose(refnum);		}		if (! IsOk) {			(void) remove(drivepath);		}	}}#endif #if IncludeSonyNewLOCALPROC MakeNewDiskAtDefault(ui5b L){	char s[ClStrMaxLength + 1]; 	NativeStrFromCStr(s, "untitled.dsk");	MakeNewDisk(L, s);}#endif /* --- ROM --- */ LOCALFUNC tMacErr LoadMacRomFrom(char *path){	tMacErr err;	FILE *ROM_File;	int File_Size; 	ROM_File = fopen(path, "rb");	if (NULL == ROM_File) {		err = mnvm_fnfErr;	} else {		File_Size = fread(ROM, 1, kROM_Size, ROM_File);		if (kROM_Size != File_Size) {			if (feof(ROM_File)) {				MacMsgOverride(kStrShortROMTitle,					kStrShortROMMessage);				err = mnvm_eofErr;			} else {				MacMsgOverride(kStrNoReadROMTitle,					kStrNoReadROMMessage);				err = mnvm_miscErr;			}		} else {			err = ROM_IsValid();		}		fclose(ROM_File);	} 	return err;} LOCALFUNC blnr LoadMacRom(void){	tMacErr err; 	if (mnvm_fnfErr == (err = LoadMacRomFrom(RomFileName)))	{	} 	return trueblnr; /* keep launching Mini vMac, regardless */} /* --- video out --- */ #if MayFullScreenLOCALVAR short hOffset;LOCALVAR short vOffset;#endif #if VarFullScreenLOCALVAR blnr UseFullScreen = (WantInitFullScreen != 0);#endif #if EnableMagnifyLOCALVAR blnr UseMagnify = (WantInitMagnify != 0);#endif LOCALVAR blnr CurSpeedStopped = trueblnr; #if EnableMagnify#define MaxScale MyWindowScale#else#define MaxScale 1#endif LOCALPROC HaveChangedScreenBuff(ui4r top, ui4r left,	ui4r bottom, ui4r right){	/*		Oh god, clean this up.	*/	u8 *octpix = NULL;	u32 *vram = NULL; 	octpix = (u8 *)GetCurDrawBuff();	vram = (u32 *)BG_BMP_RAM(0); 	octpix += ((top * vMacScreenWidth ) >> 3);

Lines 1–500 of 1387.

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