mirror of
https://github.com/autc04/Retro68.git
synced 2024-11-26 06:49:33 +00:00
WDEF sample: PowerPC support
This commit is contained in:
parent
b585d65962
commit
12270f7caa
@ -30,25 +30,44 @@ cmake_minimum_required(VERSION 2.8)
|
|||||||
|
|
||||||
# First, let's build a separate code resource:
|
# First, let's build a separate code resource:
|
||||||
add_executable(WDEF wdef.c)
|
add_executable(WDEF wdef.c)
|
||||||
set_target_properties(WDEF PROPERTIES
|
|
||||||
|
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
|
# tell wdef.c that it is being compiled as a code resource
|
||||||
COMPILE_DEFINITIONS "COMPILING_AS_CODE_RESOURCE"
|
COMPILE_DEFINITIONS "COMPILING_AS_CODE_RESOURCE"
|
||||||
|
LINK_FLAGS " -Wl,-eMyWindowDefProc -Wl,-gc-sections"
|
||||||
|
)
|
||||||
|
set(WDEF_R wdefppc.r)
|
||||||
|
|
||||||
COMPILE_OPTIONS -ffunction-sections # make things smaller
|
add_custom_command(
|
||||||
|
OUTPUT WDEF.pef
|
||||||
# set a linker flag that says we want a flat piece
|
COMMAND ${MAKE_PEF} WDEF -o "WDEF.pef"
|
||||||
# of code in a data file, specify entry point,
|
DEPENDS WDEF)
|
||||||
# and add -Wl,-gc-sections to make things smaller.
|
set(WDEF_RESOURCE WDEF.pef)
|
||||||
LINK_FLAGS "-Wl,--mac-flat -Wl,-eMYWINDOWDEFPROC -Wl,-gc-sections")
|
endif()
|
||||||
|
|
||||||
# wrap the compiled WDEF into a resource
|
# wrap the compiled WDEF into a resource
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT WDEF.rsrc.bin
|
OUTPUT WDEF.rsrc.bin
|
||||||
COMMAND ${REZ} -I ${REZ_INCLUDE_PATH}
|
COMMAND ${REZ} -I ${REZ_INCLUDE_PATH}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/wdef.r
|
${CMAKE_CURRENT_SOURCE_DIR}/${WDEF_R}
|
||||||
-o WDEF.rsrc.bin
|
-o WDEF.rsrc.bin
|
||||||
|
|
||||||
DEPENDS WDEF wdef.r)
|
DEPENDS ${WDEF_RESOURCE} ${WDEF_R})
|
||||||
|
|
||||||
# Now build the application
|
# Now build the application
|
||||||
add_application(WDEFShell
|
add_application(WDEFShell
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
#include <Fonts.h>
|
#include <Fonts.h>
|
||||||
|
|
||||||
#ifdef COMPILING_AS_CODE_RESOURCE
|
#ifdef COMPILING_AS_CODE_RESOURCE
|
||||||
|
#ifndef __PPC__
|
||||||
#include <Retro68Runtime.h>
|
#include <Retro68Runtime.h>
|
||||||
|
#endif
|
||||||
#include <LowMem.h>
|
#include <LowMem.h>
|
||||||
#endif
|
#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
|
// 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.
|
// will crash as soon as we call a function or access a global variable.
|
||||||
// The following call, part of libretro, fixes that:
|
// The following call, part of libretro, fixes that:
|
||||||
|
#ifndef __PPC__
|
||||||
RETRO68_RELOCATE();
|
RETRO68_RELOCATE();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Next, Quickdraw's global variables are stored as part of the application's
|
// 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
|
// 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
|
// 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.
|
// using GetPort instead of qdPtr->thePort, and not using qdPtr->white and qdPtr->ltGray.
|
||||||
#else
|
#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;
|
QDGlobalsPtr qdPtr = &qd;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -49,6 +53,7 @@ pascal long MyWindowDefProc(short varCode, WindowRef window, short message, long
|
|||||||
|
|
||||||
MoveTo(r.left, r.top - 10);
|
MoveTo(r.left, r.top - 10);
|
||||||
HLock((Handle) peek->titleHandle);
|
HLock((Handle) peek->titleHandle);
|
||||||
|
//TextMode(srcOr);
|
||||||
DrawString(*peek->titleHandle);
|
DrawString(*peek->titleHandle);
|
||||||
HUnlock((Handle) peek->titleHandle);
|
HUnlock((Handle) peek->titleHandle);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
#include "Retro68.r"
|
|
||||||
|
|
||||||
data 'WDEF' (129) {
|
data 'WDEF' (129) {
|
||||||
$$read("WDEF")
|
$$read("WDEF")
|
||||||
};
|
};
|
||||||
|
9
Samples/WDEF/wdefppc.r
Normal file
9
Samples/WDEF/wdefppc.r
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "MixedMode.r"
|
||||||
|
|
||||||
|
type 'WDEF' as 'rdes';
|
||||||
|
|
||||||
|
resource 'WDEF' (129) {
|
||||||
|
0x00003BB0, // ProcInfo
|
||||||
|
$$Read("WDEF.pef") // Specify name of PEF file
|
||||||
|
};
|
||||||
|
|
@ -79,7 +79,13 @@ void InitCustomWDEF()
|
|||||||
|
|
||||||
Handle h = GetResource('WDEF', 128);
|
Handle h = GetResource('WDEF', 128);
|
||||||
HLock(h);
|
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
|
// By the way, this was the only part of this file relevant for dealing
|
||||||
// with custom WDEFs.
|
// with custom WDEFs.
|
||||||
@ -222,6 +228,9 @@ void DoUpdate(WindowRef w)
|
|||||||
FillRect(&r, &qd.gray);
|
FillRect(&r, &qd.gray);
|
||||||
FrameRect(&r);
|
FrameRect(&r);
|
||||||
|
|
||||||
|
MoveTo(100,100);
|
||||||
|
DrawString("\pHello, world.");
|
||||||
|
|
||||||
EndUpdate(w);
|
EndUpdate(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user