diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 2045f80..a77cfa9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -23,7 +23,7 @@ add_library( # Sets the name of the library. # src/main/cpp/cursor.c # src/main/cpp/ddeserv.c # src/main/cpp/debugger.c -# src/main/cpp/disasm.c + src/main/cpp/disasm.c src/main/cpp/dismem.c src/main/cpp/display.c src/main/cpp/disrpl.c @@ -34,7 +34,7 @@ add_library( # Sets the name of the library. src/main/cpp/files.c src/main/cpp/i28f160.c src/main/cpp/keyboard.c -# src/main/cpp/keymacro.c + src/main/cpp/keymacro.c src/main/cpp/kml.c src/main/cpp/lodepng.c src/main/cpp/lowbat.c diff --git a/app/src/main/cpp/android-emu48.c b/app/src/main/cpp/android-emu48.c index b8771a8..fa00572 100644 --- a/app/src/main/cpp/android-emu48.c +++ b/app/src/main/cpp/android-emu48.c @@ -2251,6 +2251,9 @@ BOOL emu48Start() // no default document, ask for new one if (NewDocument()) SetWindowTitle(_T("Untitled")); + mainViewResizeCallback(nBackgroundW, nBackgroundH); + + //BitBlt(hWindowDC, 0, 0, hMainDC->selectedBitmap->bitmapInfoHeader->biWidth, hMainDC->selectedBitmap->bitmapInfoHeader->biHeight, hMainDC, 0, 0, 0); OnPaint(NULL); //start: @@ -2314,8 +2317,6 @@ void draw() { OnPaint(NULL); } -INT nMacroState = MACRO_OFF; - void buttonDown(int x, int y) { OnLButtonDown(0, x, y); } diff --git a/app/src/main/cpp/android-layer.c b/app/src/main/cpp/android-layer.c index cd69305..7453872 100644 --- a/app/src/main/cpp/android-layer.c +++ b/app/src/main/cpp/android-layer.c @@ -31,63 +31,8 @@ VOID SoundOut(CHIPSET* w, WORD wOut) { VOID SoundBeep(DWORD dwFrequency, DWORD dwDuration) { } -// Emu48.c - -#define VERSION "1.59+" - -//static BOOL bOwnCursor = FALSE; -//static BOOL bTitleBar = TRUE; -// -//CRITICAL_SECTION csGDILock; // critical section for hWindowDC -//CRITICAL_SECTION csLcdLock; // critical section for display update -//CRITICAL_SECTION csKeyLock; // critical section for key scan -//CRITICAL_SECTION csIOLock; // critical section for I/O access -//CRITICAL_SECTION csT1Lock; // critical section for timer1 access -//CRITICAL_SECTION csT2Lock; // critical section for timer2 access -//CRITICAL_SECTION csTxdLock; // critical section for transmit byte -//CRITICAL_SECTION csRecvLock; // critical section for receive byte -//CRITICAL_SECTION csSlowLock; // critical section for speed slow down -//CRITICAL_SECTION csDbgLock; // critical section for debugger purpose -//INT nArgc; // no. of command line arguments -//LPCTSTR *ppArgv; // command line arguments -//LARGE_INTEGER lFreq; // high performance counter frequency -//LARGE_INTEGER lAppStart; // high performance counter value at Appl. start -//DWORD idDdeInst; // DDE server id -//UINT uCF_HpObj; // DDE clipboard format -//HANDLE hThread; -//HANDLE hEventShutdn; // event handle to stop cpu thread -// -//HINSTANCE hApp = NULL; -//HWND hWnd = NULL; -//HWND hDlgDebug = NULL; // handle for debugger dialog -//HWND hDlgFind = NULL; // handle for debugger find dialog -//HWND hDlgProfile = NULL; // handle for debugger profile dialog -//HWND hDlgRplObjView = NULL; // handle for debugger rpl object viewer -//HDC hWindowDC = NULL; -//HPALETTE hPalette = NULL; -//HPALETTE hOldPalette = NULL; // old palette of hWindowDC -//DWORD dwTColor = (DWORD) -1; // transparency color -//DWORD dwTColorTol = 0; // transparency color tolerance -//HRGN hRgn = NULL; -//HCURSOR hCursorArrow = NULL; -//HCURSOR hCursorHand = NULL; -//UINT uWaveDevId = WAVE_MAPPER; // default audio device -//DWORD dwWakeupDelay = 200; // ON key hold time to switch on calculator -//BOOL bAutoSave = FALSE; -//BOOL bAutoSaveOnExit = TRUE; -//BOOL bSaveDefConfirm = TRUE; // yes -//BOOL bStartupBackup = FALSE; -//BOOL bAlwaysDisplayLog = TRUE; -//BOOL bLoadObjectWarning = TRUE; -//BOOL bShowTitle = TRUE; // show main window title bar -//BOOL bShowMenu = TRUE; // show main window menu bar -//BOOL bAlwaysOnTop = FALSE; // emulator window always on top -//BOOL bActFollowsMouse = FALSE; // emulator window activation follows mouse -//BOOL bClientWinMove = FALSE; // emulator window can be moved over client area -//BOOL bSingleInstance = FALSE; // multiple emulator instances allowed // udp.c - TCHAR szUdpServer[1024] = _T("localhost"); WORD wUdpPort = 5025; // scpi-raw @@ -127,25 +72,4 @@ VOID CreateBackupBreakpointList(VOID) { VOID RestoreBackupBreakpointList(VOID) { return; } - -// Disasm.c -BOOL disassembler_mode = HP_MNEMONICS; -BOOL disassembler_symb = FALSE; -DWORD disassemble(DWORD addr, LPTSTR out) { - return 0; -} - -// Keymacro.c -//INT nMacroState; -INT nMacroTimeout; -BOOL bMacroRealSpeed; -DWORD dwMacroMinDelay; -VOID KeyMacroRecord(BOOL bPress, UINT out, UINT in) { - return; -} -//LRESULT OnToolMacroNew(VOID); -//LRESULT OnToolMacroPlay(VOID); -LRESULT OnToolMacroStop(VOID) { - return 0; -} -//LRESULT OnToolMacroSettings(VOID); \ No newline at end of file +; \ No newline at end of file diff --git a/app/src/main/cpp/emu48-jni.c b/app/src/main/cpp/emu48-jni.c index a6998af..2627499 100644 --- a/app/src/main/cpp/emu48-jni.c +++ b/app/src/main/cpp/emu48-jni.c @@ -31,8 +31,28 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_6; } -// https://stackoverflow.com/questions/9630134/jni-how-to-callback-from-c-or-c-to-java +enum CALLBACK_TYPE { + CALLBACK_TYPE_INVALIDATE = 0, + CALLBACK_TYPE_WINDOW_RESIZE = 1 +}; + void mainViewUpdateCallback() { + mainViewCallback(CALLBACK_TYPE_INVALIDATE, 0, 0); +} + +void mainViewResizeCallback(int x, int y) { + mainViewCallback(CALLBACK_TYPE_WINDOW_RESIZE, x, y); + + JNIEnv * jniEnv; + int ret = (*java_machine)->GetEnv(java_machine, &jniEnv, JNI_VERSION_1_6); + ret = AndroidBitmap_getInfo(jniEnv, bitmapMainScreen, &androidBitmapInfo); + if (ret < 0) { + LOGE("AndroidBitmap_getInfo() failed ! error=%d", ret); + } +} + +// https://stackoverflow.com/questions/9630134/jni-how-to-callback-from-c-or-c-to-java +int mainViewCallback(int type, int param1, int param2) { if (viewToUpdate) { JNIEnv * jniEnv; jint ret; @@ -47,10 +67,12 @@ void mainViewUpdateCallback() { } jclass viewToUpdateClass = (*jniEnv)->GetObjectClass(jniEnv, viewToUpdate); - jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "()V"); - (*jniEnv)->CallVoidMethod(jniEnv, viewToUpdate, midStr); + //jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "()V"); + jmethodID midStr = (*jniEnv)->GetMethodID(jniEnv, viewToUpdateClass, "updateCallback", "(III)I"); + int result = (*jniEnv)->CallIntMethod(jniEnv, viewToUpdate, midStr, type, param1, param2); // if(needDetach) // ret = (*java_machine)->DetachCurrentThread(java_machine); + return result; } } diff --git a/app/src/main/cpp/pch.h b/app/src/main/cpp/pch.h index b2af195..c613914 100644 --- a/app/src/main/cpp/pch.h +++ b/app/src/main/cpp/pch.h @@ -29,7 +29,7 @@ #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) extern void mainViewUpdateCallback(); - +extern void mainViewResizeCallback(int x, int y); #include "win32-layer.h" diff --git a/app/src/main/cpp/win32-layer.c b/app/src/main/cpp/win32-layer.c index b27a07e..8157133 100644 --- a/app/src/main/cpp/win32-layer.c +++ b/app/src/main/cpp/win32-layer.c @@ -661,7 +661,13 @@ BOOL DestroyWindow(HWND hWnd) { return 0; } -BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT *lpwndpl) { return 0; } +BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT *lpwndpl) { + if(lpwndpl) { + lpwndpl->rcNormalPosition.left = 0; + lpwndpl->rcNormalPosition.top = 0; + } + return TRUE; +} BOOL SetWindowPlacement(HWND hWnd, CONST WINDOWPLACEMENT *lpwndpl) { return 0; } BOOL InvalidateRect(HWND hWnd, CONST RECT *lpRect, BOOL bErase) { return 0; } BOOL AdjustWindowRect(LPRECT lpRect, DWORD dwStyle, BOOL bMenu) { return 0; } @@ -1099,6 +1105,11 @@ VOID GetLocalTime(LPSYSTEMTIME lpSystemTime) { } return; } +WORD GetTickCount(VOID) { + //TODO + return 0; +} + BOOL EnableWindow(HWND hWnd, BOOL bEnable) { //TODO @@ -1119,6 +1130,10 @@ BOOL SetDlgItemText(HWND hDlg, int nIDDlgItem, LPCSTR lpString) { //TODO return 0; } +LRESULT SendDlgItemMessage(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam) { + //TODO + return 0; +} BOOL CheckDlgButton(HWND hDlg, int nIDButton, UINT uCheck) { //TODO return 0; diff --git a/app/src/main/cpp/win32-layer.h b/app/src/main/cpp/win32-layer.h index cdc4866..e4744a7 100644 --- a/app/src/main/cpp/win32-layer.h +++ b/app/src/main/cpp/win32-layer.h @@ -332,6 +332,7 @@ enum { #define TEXT(x) @x #define LOWORD(x) x +#define MAKELONG(a, b) ((LONG)(((WORD)(((DWORD_PTR)(a)) & 0xffff)) | ((DWORD)((WORD)(((DWORD_PTR)(b)) & 0xffff))) << 16)) #define HIBYTE(i) ((i)>>8) #define LOBYTE(i) (i) @@ -445,6 +446,11 @@ extern HANDLE LoadImage(HINSTANCE hInst, LPCSTR name, UINT type, int cx, int cy, #define BFFM_SETSELECTION BFFM_SETSELECTIONA #define CB_GETITEMDATA 0x0150 #define CB_SETITEMDATA 0x0151 +#define TBM_GETPOS (WM_USER) +#define TBM_SETPOS (WM_USER+5) +#define TBM_SETRANGE (WM_USER+6) +#define TBM_SETTICFREQ (WM_USER+20) +#define BST_CHECKED 0x0001 extern LRESULT SendMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); extern BOOL PostMessage(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); extern int MessageBox(HANDLE, LPCTSTR szMessage, LPCTSTR szTitle, int flags); @@ -780,13 +786,14 @@ extern MMRESULT timeGetDevCaps(LPTIMECAPS ptc, UINT cbtc); extern MMRESULT timeBeginPeriod(UINT uPeriod); extern MMRESULT timeEndPeriod(UINT uPeriod); extern VOID GetLocalTime(LPSYSTEMTIME lpSystemTime); - +extern WORD GetTickCount(VOID); extern BOOL EnableWindow(HWND hWnd, BOOL bEnable); extern HWND GetDlgItem(HWND hDlg, int nIDDlgItem); extern UINT GetDlgItemTextA(HWND hDlg, int nIDDlgItem, LPSTR lpString,int cchMax); #define GetDlgItemText GetDlgItemTextA extern BOOL SetDlgItemText(HWND hDlg, int nIDDlgItem, LPCSTR lpString); +extern LRESULT SendDlgItemMessage(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam); extern BOOL CheckDlgButton(HWND hDlg, int nIDButton, UINT uCheck); extern UINT IsDlgButtonChecked(HWND hDlg, int nIDButton); extern BOOL EndDialog(HWND hDlg, INT_PTR nResult); diff --git a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java index 9a98911..065edda 100644 --- a/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java +++ b/app/src/main/java/com/regis/cosnier/emu48/MainScreenView.java @@ -29,7 +29,9 @@ public class MainScreenView extends SurfaceView { protected static final String TAG = "MainScreenView"; private Bitmap bitmapMainScreen; private HashMap vkmap; - private float screenScale = 3.0f; + private float screenScale = 1.0f; + private float screenOffsetX = 0.0f; + private float screenOffsetY= 0.0f; public MainScreenView(Context context) { super(context); @@ -149,12 +151,12 @@ public class MainScreenView extends SurfaceView { switch (action) { case MotionEvent.ACTION_DOWN: //Log.d(TAG, "ACTION_DOWN count: " + touchCount + ", PanPrevious: " + mPanPrevious.toString()); - NativeLib.buttonDown((int)(event.getX(0) / screenScale), (int)(event.getY(0) / screenScale)); + NativeLib.buttonDown((int)((event.getX(0) - screenOffsetX) / screenScale), (int)((event.getY(0) - screenOffsetY) / screenScale)); break; // case MotionEvent.ACTION_MOVE: // break; case MotionEvent.ACTION_UP: - NativeLib.buttonUp((int)(event.getX(0) / screenScale), (int)(event.getY(0) / screenScale)); + NativeLib.buttonUp((int)((event.getX(0) - screenOffsetX) / screenScale), (int)((event.getY(0) - screenOffsetY) / screenScale)); break; // case MotionEvent.ACTION_CANCEL: // break; @@ -210,6 +212,29 @@ public class MainScreenView extends SurfaceView { protected void onSizeChanged(int viewWidth, int viewHeight, int oldViewWidth, int oldViewHeight) { super.onSizeChanged(viewWidth, viewHeight, oldViewWidth, oldViewHeight); + float imageSizeX = bitmapMainScreen.getWidth(); + float imageSizeY = bitmapMainScreen.getHeight(); + + if(imageSizeX > 0 && imageSizeY > 0 && viewWidth > 0.0f && viewHeight > 0.0f) { + // Find the scale factor and the translate offset to fit and to center the vectors in the view bounds. + float translateX, translateY, scale; + float viewRatio = (float)viewHeight / (float)viewWidth; + float imageRatio = imageSizeY / imageSizeX; + if(viewRatio > imageRatio) { + scale = viewWidth / imageSizeX; + translateX = 0.0f; + translateY = (viewHeight - scale * imageSizeY) / 2.0f; + } else { + scale = viewHeight / imageSizeY; + translateX = (viewWidth - scale * imageSizeX) / 2.0f; + translateY = 0.0f; + } + + screenScale = scale; + screenOffsetX = translateX; + screenOffsetY = translateY; + } + NativeLib.resize(viewWidth, viewHeight); } @@ -218,13 +243,26 @@ public class MainScreenView extends SurfaceView { //Log.d(TAG, "onDraw() mIsScaling: " + mIsScaling + ", mIsPanning: " + mIsPanning + ", mIsFlinging: " + mIsFlinging); //NativeLib.draw(); canvas.save(); - //canvas.translate(mViewPanOffsetX, mViewPanOffsetY); + canvas.translate(screenOffsetX, screenOffsetY); canvas.scale(screenScale, screenScale); canvas.drawBitmap(bitmapMainScreen, 0, 0, null); canvas.restore(); } - void updateCallback() { - postInvalidate(); + final int CALLBACK_TYPE_INVALIDATE = 0; + final int CALLBACK_TYPE_WINDOW_RESIZE = 1; + + int updateCallback(int type, int param1, int param2) { + switch (type) { + case CALLBACK_TYPE_INVALIDATE: + postInvalidate(); + break; + case CALLBACK_TYPE_WINDOW_RESIZE: + // New Bitmap size + bitmapMainScreen.reconfigure(/* x */ param1, /* y */ param2, Bitmap.Config.ARGB_8888); + bitmapMainScreen.eraseColor(Color.LTGRAY); + break; + } + return -1; } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e76021c..c59318f 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -28,6 +28,7 @@ android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" + android:visibility="gone" app:srcCompat="@android:drawable/ic_dialog_email" /> \ No newline at end of file