- Save the Port 2 at the same time we save the state file.
This commit is contained in:
parent
8583bcefdb
commit
f4384c5484
6 changed files with 84 additions and 40 deletions
|
@ -50,6 +50,7 @@ Version 1.2alpha (2019-03-XX)
|
|||
- Build with Android 4.4 support.
|
||||
- Prevent empty MRU.
|
||||
- Allow to go back from the settings in Android 4.4 and may be more recent versions.
|
||||
- Save the Port 2 at the same time we save the state file.
|
||||
|
||||
|
||||
Version 1.1 (2019-03-01)
|
||||
|
@ -77,6 +78,7 @@ Note: some included files are not covered by the GPL; these include ROM image fi
|
|||
The Eric's Real scripts ("real*.kml" and "real*.bmp") are embedded in this application with the kind permission of Eric Rechlin.
|
||||
|
||||
TODO
|
||||
- But in the MRU (the MRU is not always well refreshed)
|
||||
- Issue with random settings in Android 4.4 emulator
|
||||
- Add a separation between the pixels (Suggestion from Jaime Meza)
|
||||
- Sometimes the "busy" annunciator gets stuck
|
||||
|
|
|
@ -50,6 +50,7 @@ Version 1.2alpha (2019-03-XX)
|
|||
- Build with Android 4.4 support.
|
||||
- Prevent empty MRU.
|
||||
- Allow to go back from the settings in Android 4.4 and may be more recent versions.
|
||||
- Save the Port 2 at the same time we save the state file.
|
||||
|
||||
|
||||
Version 1.1 (2019-03-01)
|
||||
|
|
|
@ -507,6 +507,7 @@ JNIEXPORT jint JNICALL Java_org_emulator_forty_eight_NativeLib_onFileSave(JNIEnv
|
|||
{
|
||||
SwitchToState(SM_INVALID);
|
||||
result = SaveDocument();
|
||||
SaveMapViewToFile(pbyPort2);
|
||||
SwitchToState(SM_RUN);
|
||||
}
|
||||
return result;
|
||||
|
@ -520,11 +521,7 @@ JNIEXPORT jint JNICALL Java_org_emulator_forty_eight_NativeLib_onFileSaveAs(JNIE
|
|||
SwitchToState(SM_INVALID);
|
||||
_tcscpy(szBufferFilename, newStateFilenameUTF8);
|
||||
result = SaveDocumentAs(szBufferFilename);
|
||||
if (result)
|
||||
MruAdd(szCurrentFilename);
|
||||
else {
|
||||
//TODO ERROR !!!!!!!!!
|
||||
}
|
||||
SaveMapViewToFile(pbyPort2);
|
||||
SwitchToState(SM_RUN);
|
||||
}
|
||||
|
||||
|
|
|
@ -277,7 +277,10 @@ HANDLE CreateFileMapping(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappingAttrib
|
|||
HANDLE handle = malloc(sizeof(struct _HANDLE));
|
||||
memset(handle, 0, sizeof(struct _HANDLE));
|
||||
if(hFile->handleType == HANDLE_TYPE_FILE) {
|
||||
handle->handleType = HANDLE_TYPE_FILE_MAPPING;
|
||||
if(hFile->fileOpenFileFromContentResolver)
|
||||
handle->handleType = HANDLE_TYPE_FILE_MAPPING_CONTENT;
|
||||
else
|
||||
handle->handleType = HANDLE_TYPE_FILE_MAPPING;
|
||||
handle->fileDescriptor = hFile->fileDescriptor;
|
||||
} else if(hFile->handleType == HANDLE_TYPE_FILE_ASSET) {
|
||||
handle->handleType = HANDLE_TYPE_FILE_MAPPING_ASSET;
|
||||
|
@ -293,7 +296,7 @@ HANDLE CreateFileMapping(HANDLE hFile, LPSECURITY_ATTRIBUTES lpFileMappingAttrib
|
|||
|
||||
//https://msdn.microsoft.com/en-us/library/Aa366761(v=VS.85).aspx
|
||||
LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap) {
|
||||
off_t offset = (dwFileOffsetHigh << 32) & dwFileOffsetLow;
|
||||
hFileMappingObject->fileMappingOffset = (dwFileOffsetHigh << 32) & dwFileOffsetLow;
|
||||
LPVOID result = NULL;
|
||||
if(hFileMappingObject->handleType == HANDLE_TYPE_FILE_MAPPING) {
|
||||
int prot = PROT_NONE;
|
||||
|
@ -303,11 +306,18 @@ LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwF
|
|||
prot |= PROT_WRITE;
|
||||
hFileMappingObject->fileMappingAddress = mmap(NULL, hFileMappingObject->fileMappingSize,
|
||||
prot, MAP_PRIVATE,
|
||||
hFileMappingObject->fileDescriptor, offset);
|
||||
hFileMappingObject->fileDescriptor, hFileMappingObject->fileMappingOffset);
|
||||
} else if(hFileMappingObject->handleType == HANDLE_TYPE_FILE_MAPPING_CONTENT) {
|
||||
size_t numberOfBytesToRead = hFileMappingObject->fileMappingSize - hFileMappingObject->fileMappingOffset;
|
||||
hFileMappingObject->fileMappingAddress = malloc(numberOfBytesToRead);
|
||||
off_t currentPosition = lseek(hFileMappingObject->fileDescriptor, 0, SEEK_CUR);
|
||||
lseek(hFileMappingObject->fileDescriptor, hFileMappingObject->fileMappingOffset, SEEK_SET);
|
||||
DWORD readByteCount = (DWORD) read(hFileMappingObject->fileDescriptor, hFileMappingObject->fileMappingAddress, numberOfBytesToRead);
|
||||
lseek(hFileMappingObject->fileDescriptor, currentPosition, SEEK_SET);
|
||||
} else if(hFileMappingObject->handleType == HANDLE_TYPE_FILE_MAPPING_ASSET) {
|
||||
if (dwDesiredAccess & FILE_MAP_WRITE)
|
||||
return NULL;
|
||||
hFileMappingObject->fileMappingAddress = (LPVOID) (AAsset_getBuffer(hFileMappingObject->fileAsset) + offset);
|
||||
hFileMappingObject->fileMappingAddress = (LPVOID) (AAsset_getBuffer(hFileMappingObject->fileAsset) + hFileMappingObject->fileMappingOffset);
|
||||
}
|
||||
if(hFileMappingObject->fileMappingAddress) {
|
||||
for (int i = 0; i < MAX_FILE_MAPPING_HANDLE; ++i) {
|
||||
|
@ -330,10 +340,15 @@ BOOL UnmapViewOfFile(LPCVOID lpBaseAddress) {
|
|||
if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING) {
|
||||
// munmap does not seem to work, so:
|
||||
off_t currentPosition = lseek(fileMappingHandle->fileDescriptor, 0, SEEK_CUR);
|
||||
lseek(fileMappingHandle->fileDescriptor, 0, SEEK_SET);
|
||||
write(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingAddress, fileMappingHandle->fileMappingSize);
|
||||
lseek(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingOffset, SEEK_SET);
|
||||
write(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingAddress, fileMappingHandle->fileMappingSize - fileMappingHandle->fileMappingOffset);
|
||||
lseek(fileMappingHandle->fileDescriptor, currentPosition, SEEK_SET);
|
||||
result = munmap(lpBaseAddress, fileMappingHandle->fileMappingSize);
|
||||
} else if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING_CONTENT) {
|
||||
off_t currentPosition = lseek(fileMappingHandle->fileDescriptor, 0, SEEK_CUR);
|
||||
lseek(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingOffset, SEEK_SET);
|
||||
write(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingAddress, fileMappingHandle->fileMappingSize - fileMappingHandle->fileMappingOffset);
|
||||
lseek(fileMappingHandle->fileDescriptor, currentPosition, SEEK_SET);
|
||||
} else if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING_ASSET) {
|
||||
// No need to unmap
|
||||
result = 0;
|
||||
|
@ -346,6 +361,30 @@ BOOL UnmapViewOfFile(LPCVOID lpBaseAddress) {
|
|||
return result == 0;
|
||||
}
|
||||
|
||||
// This is not a Win32 function
|
||||
BOOL SaveMapViewToFile(LPCVOID lpBaseAddress) {
|
||||
int result = -1;
|
||||
for (int i = 0; i < MAX_FILE_MAPPING_HANDLE; ++i) {
|
||||
HANDLE fileMappingHandle = fileMappingHandles[i];
|
||||
if(fileMappingHandle && lpBaseAddress == fileMappingHandle->fileMappingAddress) {
|
||||
if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING
|
||||
|| fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING_CONTENT) {
|
||||
// munmap does not seem to work, so:
|
||||
off_t currentPosition = lseek(fileMappingHandle->fileDescriptor, 0, SEEK_CUR);
|
||||
lseek(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingOffset, SEEK_SET);
|
||||
write(fileMappingHandle->fileDescriptor, fileMappingHandle->fileMappingAddress, fileMappingHandle->fileMappingSize - fileMappingHandle->fileMappingOffset);
|
||||
lseek(fileMappingHandle->fileDescriptor, currentPosition, SEEK_SET);
|
||||
} else if(fileMappingHandle->handleType == HANDLE_TYPE_FILE_MAPPING_ASSET) {
|
||||
// No need to unmap
|
||||
result = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
//https://github.com/neosmart/pevents/blob/master/src/pevents.cpp
|
||||
HANDLE CreateEvent(LPVOID lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPCTSTR name) {
|
||||
HANDLE handle = malloc(sizeof(struct _HANDLE));
|
||||
|
@ -601,16 +640,11 @@ BOOL WINAPI CloseHandle(HANDLE hObject) {
|
|||
free(hObject);
|
||||
return TRUE;
|
||||
}
|
||||
case HANDLE_TYPE_FILE_MAPPING: {
|
||||
hObject->handleType = HANDLE_TYPE_INVALID;
|
||||
hObject->fileDescriptor = 0;
|
||||
hObject->fileMappingSize = 0;
|
||||
hObject->fileMappingAddress = NULL;
|
||||
free(hObject);
|
||||
return TRUE;
|
||||
}
|
||||
case HANDLE_TYPE_FILE_MAPPING:
|
||||
case HANDLE_TYPE_FILE_MAPPING_CONTENT:
|
||||
case HANDLE_TYPE_FILE_MAPPING_ASSET: {
|
||||
hObject->handleType = HANDLE_TYPE_INVALID;
|
||||
hObject->fileDescriptor = 0;
|
||||
hObject->fileAsset = NULL;
|
||||
hObject->fileMappingSize = 0;
|
||||
hObject->fileMappingAddress = NULL;
|
||||
|
|
|
@ -348,7 +348,8 @@ enum HANDLE_TYPE {
|
|||
HANDLE_TYPE_FILE,
|
||||
HANDLE_TYPE_FILE_ASSET,
|
||||
HANDLE_TYPE_FILE_MAPPING,
|
||||
HANDLE_TYPE_FILE_MAPPING_ASSET,
|
||||
HANDLE_TYPE_FILE_MAPPING_CONTENT,
|
||||
HANDLE_TYPE_FILE_MAPPING_ASSET,
|
||||
HANDLE_TYPE_EVENT,
|
||||
HANDLE_TYPE_THREAD,
|
||||
};
|
||||
|
@ -360,6 +361,7 @@ struct _HANDLE {
|
|||
|
||||
AAsset* fileAsset;
|
||||
|
||||
off_t fileMappingOffset;
|
||||
size_t fileMappingSize;
|
||||
void* fileMappingAddress;
|
||||
|
||||
|
@ -418,6 +420,9 @@ extern LPVOID MapViewOfFile(HANDLE hFileMappingObject,DWORD dwDesiredAccess, DWO
|
|||
extern BOOL UnmapViewOfFile(LPCVOID lpBaseAddress);
|
||||
extern BOOL SetEndOfFile(HANDLE hFile);
|
||||
|
||||
// This is not a Win32 function
|
||||
extern BOOL SaveMapViewToFile(LPCVOID lpBaseAddress);
|
||||
|
||||
typedef UINT_PTR (CALLBACK *LPOFNHOOKPROC) (HWND, UINT, WPARAM, LPARAM);
|
||||
typedef struct tagOFNA {
|
||||
DWORD lStructSize;
|
||||
|
|
|
@ -8,30 +8,35 @@ import android.provider.OpenableColumns;
|
|||
public class Utils {
|
||||
static String getFileName(Context context, String url) {
|
||||
String result = null;
|
||||
Uri uri = Uri.parse(url);
|
||||
if(uri != null) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme != null && scheme.equals("content")) {
|
||||
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
|
||||
if(cursor != null) {
|
||||
try {
|
||||
if (cursor.moveToFirst())
|
||||
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result = uri.getPath();
|
||||
if(result != null) {
|
||||
int cut = result.lastIndexOf('/');
|
||||
if (cut != -1) {
|
||||
result = result.substring(cut + 1);
|
||||
try {
|
||||
Uri uri = Uri.parse(url);
|
||||
if(uri != null) {
|
||||
String scheme = uri.getScheme();
|
||||
if (scheme != null && scheme.equals("content")) {
|
||||
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
|
||||
if(cursor != null) {
|
||||
try {
|
||||
if (cursor.moveToFirst())
|
||||
result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result == null) {
|
||||
result = uri.getPath();
|
||||
if(result != null) {
|
||||
int cut = result.lastIndexOf('/');
|
||||
if (cut != -1) {
|
||||
result = result.substring(cut + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
result = url;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue