From 12270f7caa131fd6a3298b85d211ae40e78df6b1 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Sun, 7 Jan 2018 17:28:28 +0100 Subject: [PATCH] WDEF sample: PowerPC support --- Samples/WDEF/CMakeLists.txt | 43 ++++++++++++++++++++++++++----------- Samples/WDEF/wdef.c | 7 +++++- Samples/WDEF/wdef.r | 2 -- Samples/WDEF/wdefppc.r | 9 ++++++++ Samples/WDEF/wdefshell.c | 11 +++++++++- 5 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 Samples/WDEF/wdefppc.r diff --git a/Samples/WDEF/CMakeLists.txt b/Samples/WDEF/CMakeLists.txt index d200267854..30e96f152b 100644 --- a/Samples/WDEF/CMakeLists.txt +++ b/Samples/WDEF/CMakeLists.txt @@ -30,25 +30,44 @@ cmake_minimum_required(VERSION 2.8) # First, let's build a separate code resource: add_executable(WDEF wdef.c) -set_target_properties(WDEF PROPERTIES - # tell wdef.c that it is being compiled as a code resource - COMPILE_DEFINITIONS "COMPILING_AS_CODE_RESOURCE" - - COMPILE_OPTIONS -ffunction-sections # make things smaller - # set a linker flag that says we want a flat piece - # of code in a data file, specify entry point, - # and add -Wl,-gc-sections to make things smaller. - LINK_FLAGS "-Wl,--mac-flat -Wl,-eMYWINDOWDEFPROC -Wl,-gc-sections") - +if(CMAKE_SYSTEM_NAME MATCHES Retro68) + set_target_properties(WDEF PROPERTIES + # tell wdef.c that it is being compiled as a code resource + COMPILE_DEFINITIONS "COMPILING_AS_CODE_RESOURCE" + + COMPILE_OPTIONS -ffunction-sections # make things smaller + + # set a linker flag that says we want a flat piece + # of code in a data file, specify entry point, + # and add -Wl,-gc-sections to make things smaller. + LINK_FLAGS "-Wl,--mac-flat -Wl,-eMYWINDOWDEFPROC -Wl,-gc-sections") + set(WDEF_R wdef.r) + set(WDEF_RESOURCE WDEF) +elseif(CMAKE_SYSTEM_NAME MATCHES RetroPPC) + set_target_properties(WDEF PROPERTIES + COMPILE_OPTIONS -ffunction-sections # make things smaller + # tell wdef.c that it is being compiled as a code resource + COMPILE_DEFINITIONS "COMPILING_AS_CODE_RESOURCE" + LINK_FLAGS " -Wl,-eMyWindowDefProc -Wl,-gc-sections" + ) + set(WDEF_R wdefppc.r) + + add_custom_command( + OUTPUT WDEF.pef + COMMAND ${MAKE_PEF} WDEF -o "WDEF.pef" + DEPENDS WDEF) + set(WDEF_RESOURCE WDEF.pef) +endif() + # wrap the compiled WDEF into a resource add_custom_command( OUTPUT WDEF.rsrc.bin COMMAND ${REZ} -I ${REZ_INCLUDE_PATH} - ${CMAKE_CURRENT_SOURCE_DIR}/wdef.r + ${CMAKE_CURRENT_SOURCE_DIR}/${WDEF_R} -o WDEF.rsrc.bin - DEPENDS WDEF wdef.r) + DEPENDS ${WDEF_RESOURCE} ${WDEF_R}) # Now build the application add_application(WDEFShell diff --git a/Samples/WDEF/wdef.c b/Samples/WDEF/wdef.c index bf471f9e51..97104a4c6c 100644 --- a/Samples/WDEF/wdef.c +++ b/Samples/WDEF/wdef.c @@ -3,7 +3,9 @@ #include #ifdef COMPILING_AS_CODE_RESOURCE +#ifndef __PPC__ #include +#endif #include #endif @@ -14,7 +16,9 @@ pascal long MyWindowDefProc(short varCode, WindowRef window, short message, long // First, our machine code doesn't yet know where in RAM it is located, so things // will crash as soon as we call a function or access a global variable. // The following call, part of libretro, fixes that: +#ifndef __PPC__ RETRO68_RELOCATE(); +#endif // Next, Quickdraw's global variables are stored as part of the application's // global variables. If we acces "qd.", we'll get our own copy, which QuickDraw knows @@ -24,7 +28,7 @@ pascal long MyWindowDefProc(short varCode, WindowRef window, short message, long // alternatively, we could just avoid accessing QuickDraw globals. In our case, that would mean // using GetPort instead of qdPtr->thePort, and not using qdPtr->white and qdPtr->ltGray. #else - // We're part of the real application, we could be using qd. in the first place: + // We're part of the real application, we could be using `qd' in the first place: QDGlobalsPtr qdPtr = &qd; #endif @@ -49,6 +53,7 @@ pascal long MyWindowDefProc(short varCode, WindowRef window, short message, long MoveTo(r.left, r.top - 10); HLock((Handle) peek->titleHandle); + //TextMode(srcOr); DrawString(*peek->titleHandle); HUnlock((Handle) peek->titleHandle); } diff --git a/Samples/WDEF/wdef.r b/Samples/WDEF/wdef.r index 1f2da567a3..2da75ef9a5 100644 --- a/Samples/WDEF/wdef.r +++ b/Samples/WDEF/wdef.r @@ -1,5 +1,3 @@ -#include "Retro68.r" - data 'WDEF' (129) { $$read("WDEF") }; diff --git a/Samples/WDEF/wdefppc.r b/Samples/WDEF/wdefppc.r new file mode 100644 index 0000000000..78a1e8cd1a --- /dev/null +++ b/Samples/WDEF/wdefppc.r @@ -0,0 +1,9 @@ +#include "MixedMode.r" + +type 'WDEF' as 'rdes'; + +resource 'WDEF' (129) { + 0x00003BB0, // ProcInfo + $$Read("WDEF.pef") // Specify name of PEF file +}; + diff --git a/Samples/WDEF/wdefshell.c b/Samples/WDEF/wdefshell.c index e077a34b08..492b04602c 100644 --- a/Samples/WDEF/wdefshell.c +++ b/Samples/WDEF/wdefshell.c @@ -79,8 +79,14 @@ void InitCustomWDEF() Handle h = GetResource('WDEF', 128); HLock(h); - *(WindowDefProcPtr*)(*h + 6) = &MyWindowDefProc; + *(WindowDefUPP*)(*h + 6) = NewWindowDefUPP(&MyWindowDefProc); + // note: for 68K, the above is equivalent to: + // *(WindowDefProcPtr*)(*h + 6) = &MyWindowDefProc; + // for PPC, it creates a routine descriptor data structure to get out of the emulator again. + // On PPC only, we could also bypass the emulator by putting the routine descriptor into the resource, + // and putting the pointer to the code into it here. This wouldn't work for the 68K version of this code, though. + // By the way, this was the only part of this file relevant for dealing // with custom WDEFs. } @@ -222,6 +228,9 @@ void DoUpdate(WindowRef w) FillRect(&r, &qd.gray); FrameRect(&r); + MoveTo(100,100); + DrawString("\pHello, world."); + EndUpdate(w); }