Sigrid Haflínudóttirfirst dirty version of the portd7ad0686 years agoHistory
1219 lines · 23.9 KB · C
RawDownload
/*	COMOSGLU.h 	Copyright (C) 2009 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.*/ /*	COMmon code for Operating System GLUe*/ #if EnableMouseMotion && MayFullScreen#define EnableFSMouseMotion 1#else#define EnableFSMouseMotion 0#endif #if EnableMagnify || VarFullScreen#define EnableRecreateW 1#else#define EnableRecreateW 0#endif #if EnableRecreateW || EnableFSMouseMotion#define EnableMoveMouse 1#else#define EnableMoveMouse 0#endif GLOBALVAR ui3p ROM = nullpr;LOCALVAR blnr ROM_loaded = falseblnr; GLOBALVAR ui5b vSonyWritableMask = 0;GLOBALVAR ui5b vSonyInsertedMask = 0; #if IncludeSonyRawModeGLOBALVAR blnr vSonyRawMode = falseblnr;#endif #if IncludeSonyNewGLOBALVAR blnr vSonyNewDiskWanted = falseblnr;GLOBALVAR ui5b vSonyNewDiskSize;#endif #if IncludeSonyNameNewGLOBALVAR tPbuf vSonyNewDiskName = NotAPbuf;#endif GLOBALVAR ui5b CurMacDateInSeconds = 0;#if AutoLocationGLOBALVAR ui5b CurMacLatitude = 0;GLOBALVAR ui5b CurMacLongitude = 0;#endif#if AutoTimeZoneGLOBALVAR ui5b CurMacDelta = 0;#endif #if 0 != vMacScreenDepthGLOBALVAR blnr UseColorMode = falseblnr;GLOBALVAR blnr ColorModeWorks = falseblnr;#endif #if 0 != vMacScreenDepthGLOBALVAR blnr ColorMappingChanged = falseblnr;#endif #if (0 != vMacScreenDepth) && (vMacScreenDepth < 4)GLOBALVAR ui4r CLUT_reds[CLUT_size];GLOBALVAR ui4r CLUT_greens[CLUT_size];GLOBALVAR ui4r CLUT_blues[CLUT_size];#endif LOCALVAR blnr RequestMacOff = falseblnr; GLOBALVAR blnr ForceMacOff = falseblnr; GLOBALVAR blnr WantMacInterrupt = falseblnr; GLOBALVAR blnr WantMacReset = falseblnr; GLOBALVAR ui3b SpeedValue = WantInitSpeedValue; #if EnableAutoSlowGLOBALVAR blnr WantNotAutoSlow = (WantInitNotAutoSlow != 0);#endif GLOBALVAR ui4b CurMouseV = 0;GLOBALVAR ui4b CurMouseH = 0; #if EnableFSMouseMotionLOCALVAR blnr HaveMouseMotion = falseblnr;#endif #if EnableAutoSlowGLOBALVAR ui5r QuietTime = 0;GLOBALVAR ui5r QuietSubTicks = 0;#endif #ifndef GrabKeysFullScreen#define GrabKeysFullScreen 1#endif #ifndef GrabKeysMaxFullScreen#define GrabKeysMaxFullScreen 0#endif #if IncludePbufsLOCALVAR ui5b PbufAllocatedMask;LOCALVAR ui5b PbufSize[NumPbufs];#endif #if IncludePbufs#define PbufIsAllocated(i) ((PbufAllocatedMask & ((ui5b)1 << (i))) != 0)#endif #if IncludePbufsLOCALFUNC blnr FirstFreePbuf(tPbuf *r){	tPbuf i; 	for (i = 0; i < NumPbufs; ++i) {		if (! PbufIsAllocated(i)) {			*r = i;			return trueblnr;		}	}	return falseblnr;}#endif #if IncludePbufsLOCALPROC PbufNewNotify(tPbuf Pbuf_No, ui5b count){	PbufSize[Pbuf_No] = count;	PbufAllocatedMask |= ((ui5b)1 << Pbuf_No);}#endif #if IncludePbufsLOCALPROC PbufDisposeNotify(tPbuf Pbuf_No){	PbufAllocatedMask &= ~ ((ui5b)1 << Pbuf_No);}#endif #if IncludePbufsGLOBALOSGLUFUNC tMacErr CheckPbuf(tPbuf Pbuf_No){	tMacErr result; 	if (Pbuf_No >= NumPbufs) {		result = mnvm_nsDrvErr;	} else if (! PbufIsAllocated(Pbuf_No)) {		result = mnvm_offLinErr;	} else {		result = mnvm_noErr;	} 	return result;}#endif #if IncludePbufsGLOBALOSGLUFUNC tMacErr PbufGetSize(tPbuf Pbuf_No, ui5r *Count){	tMacErr result = CheckPbuf(Pbuf_No); 	if (mnvm_noErr == result) {		*Count = PbufSize[Pbuf_No];	} 	return result;}#endif LOCALFUNC blnr FirstFreeDisk(tDrive *Drive_No){	tDrive i; 	for (i = 0; i < NumDrives; ++i) {		if (! vSonyIsInserted(i)) {			if (nullpr != Drive_No) {				*Drive_No = i;			}			return trueblnr;		}	}	return falseblnr;} GLOBALOSGLUFUNC blnr AnyDiskInserted(void){#if 0	tDrive i; 	for (i = 0; i < NumDrives; ++i) {		if (vSonyIsInserted(i)) {			return trueblnr;		}	}	return falseblnr;#endif	return 0 != vSonyInsertedMask;} GLOBALOSGLUPROC DiskRevokeWritable(tDrive Drive_No){	vSonyWritableMask &= ~ ((ui5b)1 << Drive_No);} LOCALPROC DiskInsertNotify(tDrive Drive_No, blnr locked){	vSonyInsertedMask |= ((ui5b)1 << Drive_No);	if (! locked) {		vSonyWritableMask |= ((ui5b)1 << Drive_No);	} 	QuietEnds();} LOCALPROC DiskEjectedNotify(tDrive Drive_No){	vSonyWritableMask &= ~ ((ui5b)1 << Drive_No);	vSonyInsertedMask &= ~ ((ui5b)1 << Drive_No);} /*	block type - for operating on multiple ui3b elements		at a time.*/ #if LittleEndianUnaligned || BigEndianUnaligned #define uibb ui5b#define uibr ui5r#define ln2uiblockn 2 #if 0#define uibb long long#define uibr long long#define ln2uiblockn 3#endif #else #define uibb ui3b#define uibr ui3r#define ln2uiblockn 0 #endif #define uiblockn (1 << ln2uiblockn)#define ln2uiblockbitsn (3 + ln2uiblockn)#define uiblockbitsn (8 * uiblockn) LOCALFUNC blnr FindFirstChangeInLVecs(uibb *ptr1, uibb *ptr2,					uimr L, uimr *j){/*	find index of first difference*/	uibb *p1 = ptr1;	uibb *p2 = ptr2;	uimr i; 	for (i = L; i != 0; --i) {		if (*p1++ != *p2++) {			--p1;			*j = p1 - ptr1;			return trueblnr;		}	}	return falseblnr;} LOCALPROC FindLastChangeInLVecs(uibb *ptr1, uibb *ptr2,					uimr L, uimr *j){/*	find index of last difference, assuming there is one*/	uibb *p1 = ptr1 + L;	uibb *p2 = ptr2 + L; 	while (*--p1 == *--p2) {	}	*j = p1 - ptr1;} LOCALPROC FindLeftRightChangeInLMat(uibb *ptr1, uibb *ptr2,	uimr width, uimr top, uimr bottom,	uimr *LeftMin0, uibr *LeftMask0,	uimr *RightMax0, uibr *RightMask0){	uimr i;	uimr j;	uibb *p1;	uibb *p2;	uibr x;	ui5r offset = top * width;	uibb *p10 = (uibb *)ptr1 + offset;	uibb *p20 = (uibb *)ptr2 + offset;	uimr LeftMin = *LeftMin0;	uimr RightMax = *RightMax0;	uibr LeftMask = 0;	uibr RightMask = 0;	for (i = top; i < bottom; ++i) {		p1 = p10;		p2 = p20;		for (j = 0; j < LeftMin; ++j) {			x = *p1++ ^ *p2++;			if (0 != x) {				LeftMin = j;				LeftMask = x;				goto Label_3;			}		}		LeftMask |= (*p1 ^ *p2);Label_3:		p1 = p10 + RightMax;		p2 = p20 + RightMax;		RightMask |= (*p1++ ^ *p2++);		for (j = RightMax + 1; j < width; ++j) {			x = *p1++ ^ *p2++;			if (0 != x) {				RightMax = j;				RightMask = x;			}		} 		p10 += width;		p20 += width;	}	*LeftMin0 = LeftMin;	*RightMax0 = RightMax;	*LeftMask0 = LeftMask;	*RightMask0 = RightMask;} LOCALVAR ui3p screencomparebuff = nullpr; LOCALVAR uimr NextDrawRow = 0;  #if BigEndianUnaligned #define FlipCheckMonoBits (uiblockbitsn - 1) #else #define FlipCheckMonoBits 7 #endif #define FlipCheckBits (FlipCheckMonoBits >> vMacScreenDepth) #ifndef WantColorTransValid#define WantColorTransValid 0#endif #if WantColorTransValidLOCALVAR blnr ColorTransValid = falseblnr;#endif LOCALFUNC blnr ScreenFindChanges(ui3p screencurrentbuff,	si3b TimeAdjust, si4b *top, si4b *left, si4b *bottom, si4b *right){	uimr j0;	uimr j1;	uimr j0h;	uimr j1h;	uimr j0v;	uimr j1v;	uimr copysize;	uimr copyoffset;	uimr copyrows;	uimr LimitDrawRow;	uimr MaxRowsDrawnPerTick;	uimr LeftMin;	uimr RightMax;	uibr LeftMask;	uibr RightMask;	int j; 	if (TimeAdjust < 4) {		MaxRowsDrawnPerTick = vMacScreenHeight;	} else if (TimeAdjust < 6) {		MaxRowsDrawnPerTick = vMacScreenHeight / 2;	} else {		MaxRowsDrawnPerTick = vMacScreenHeight / 4;	} #if 0 != vMacScreenDepth	if (UseColorMode) {		if (ColorMappingChanged) {			ColorMappingChanged = falseblnr;			j0h = 0;			j1h = vMacScreenWidth;			j0v = 0;			j1v = vMacScreenHeight;#if WantColorTransValid			ColorTransValid = falseblnr;#endif		} else {			if (! FindFirstChangeInLVecs(				(uibb *)screencurrentbuff					+ NextDrawRow * (vMacScreenBitWidth / uiblockbitsn),				(uibb *)screencomparebuff					+ NextDrawRow * (vMacScreenBitWidth / uiblockbitsn),				((uimr)(vMacScreenHeight - NextDrawRow)					* (uimr)vMacScreenBitWidth) / uiblockbitsn,				&j0))			{				NextDrawRow = 0;				return falseblnr;			}			j0v = j0 / (vMacScreenBitWidth / uiblockbitsn);			j0h = j0 - j0v * (vMacScreenBitWidth / uiblockbitsn);			j0v += NextDrawRow;			LimitDrawRow = j0v + MaxRowsDrawnPerTick;			if (LimitDrawRow >= vMacScreenHeight) {				LimitDrawRow = vMacScreenHeight;				NextDrawRow = 0;			} else {				NextDrawRow = LimitDrawRow;			}			FindLastChangeInLVecs((uibb *)screencurrentbuff,				(uibb *)screencomparebuff,				((uimr)LimitDrawRow					* (uimr)vMacScreenBitWidth) / uiblockbitsn,				&j1);			j1v = j1 / (vMacScreenBitWidth / uiblockbitsn);			j1h = j1 - j1v * (vMacScreenBitWidth / uiblockbitsn);			j1v++; 			if (j0h < j1h) {				LeftMin = j0h;				RightMax = j1h;			} else {				LeftMin = j1h;				RightMax = j0h;			} 			FindLeftRightChangeInLMat((uibb *)screencurrentbuff,				(uibb *)screencomparebuff,				(vMacScreenBitWidth / uiblockbitsn),				j0v, j1v, &LeftMin, &LeftMask, &RightMax, &RightMask); #if vMacScreenDepth > ln2uiblockbitsn			j0h =  (LeftMin >> (vMacScreenDepth - ln2uiblockbitsn));#elif ln2uiblockbitsn > vMacScreenDepth			for (j = 0; j < (1 << (ln2uiblockbitsn - vMacScreenDepth));				++j)			{				if (0 != (LeftMask					& (((((uibr)1) << (1 << vMacScreenDepth)) - 1)						<< ((j ^ FlipCheckBits) << vMacScreenDepth))))				{					goto Label_1c;				}			}Label_1c:			j0h =  (LeftMin << (ln2uiblockbitsn - vMacScreenDepth)) + j;#else			j0h =  LeftMin;#endif #if vMacScreenDepth > ln2uiblockbitsn			j1h = (RightMax >> (vMacScreenDepth - ln2uiblockbitsn)) + 1;#elif ln2uiblockbitsn > vMacScreenDepth			for (j = (uiblockbitsn >> vMacScreenDepth); --j >= 0; ) {				if (0 != (RightMask					& (((((uibr)1) << (1 << vMacScreenDepth)) - 1)						<< ((j ^ FlipCheckBits) << vMacScreenDepth))))				{					goto Label_2c;				}			}Label_2c:			j1h = (RightMax << (ln2uiblockbitsn - vMacScreenDepth))				+ j + 1;#else			j1h = RightMax + 1;#endif		} 		copyrows = j1v - j0v;		copyoffset = j0v * vMacScreenByteWidth;		copysize = copyrows * vMacScreenByteWidth;	} else#endif

Lines 1–500 of 1219.

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