mirror of
https://github.com/ksherlock/mpw.git
synced 2025-02-22 08:29:08 +00:00
toolbox code...
This commit is contained in:
parent
54f10c88e5
commit
64618097a1
@ -1,9 +1,11 @@
|
||||
set(CMAKE_C_COMPILER "clang")
|
||||
set(CMAKE_CXX_COMPILER "clang++")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -g")
|
||||
set(CMAKE_C_FLAGS " -Wall -g")
|
||||
|
||||
project(mpw)
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
||||
add_subdirectory(bin)
|
||||
add_subdirectory(cpu)
|
||||
add_subdirectory(cpu)
|
||||
add_subdirectory(toolbox)
|
@ -1,6 +1,6 @@
|
||||
#set(CMAKE_C_COMPILER "clang")
|
||||
#set(CMAKE_CXX_COMPILER "clang++")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -g -Wno-deprecated-declarations ")
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Wno-deprecated-declarations -g")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-framework Carbon")
|
||||
|
||||
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
|
||||
@ -8,3 +8,4 @@ add_definitions(-I ${CMAKE_SOURCE_DIR}/)
|
||||
|
||||
add_executable(mpw loader.cpp)
|
||||
target_link_libraries(mpw CPU_LIB)
|
||||
target_link_libraries(mpw TOOLBOX_LIB)
|
||||
|
14
toolbox/CMakeLists.txt
Normal file
14
toolbox/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Wno-deprecated-declarations -g")
|
||||
|
||||
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
|
||||
|
||||
set(TOOLBOX_SRC
|
||||
dispatch.cpp
|
||||
rm.cpp
|
||||
)
|
||||
|
||||
|
||||
|
||||
add_library(TOOLBOX_LIB ${TOOLBOX_SRC})
|
37
toolbox/dispatch.cpp
Normal file
37
toolbox/dispatch.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
#include <cstdio>
|
||||
#include <cstdint>
|
||||
|
||||
#include <cpu/defs.h>
|
||||
#include <cpu/CpuModule.h>
|
||||
#include <cpu/fmem.h>
|
||||
|
||||
#include "toolbox.h"
|
||||
|
||||
// yuck. TST.W d0
|
||||
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
|
||||
|
||||
|
||||
|
||||
void toolbox(uint16_t trap)
|
||||
{
|
||||
// todo -- remove extra bits for save a0, toolglue
|
||||
|
||||
uint32_t d0 = 0;
|
||||
switch (trap)
|
||||
{
|
||||
|
||||
_Get1NamedResource
|
||||
// Get1NamedResource (theType: ResType; name: Str255) : Handle;
|
||||
case 0xa820:
|
||||
d0 = RM::Get1NamedResource();
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unsupported tool trap: %08x\n", trap);
|
||||
fprintf(stderr, "pc: %08x\n", cpuGetPC());
|
||||
exit(255);
|
||||
}
|
||||
|
||||
cpuSetDReg(0, d0);
|
||||
cpuSetFlagsNZ00NewW(d0);
|
||||
}
|
90
toolbox/rm.cpp
Normal file
90
toolbox/rm.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "rm.h"
|
||||
|
||||
#include <cpu/defs.h>
|
||||
#include <cpu/CpuModule.h>
|
||||
#include <cpu/fmem.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
uint32_t PopLong()
|
||||
{
|
||||
uint32_t sp = cpuGetAReg(7);
|
||||
uint32_t value = memoryReadLong(a7);
|
||||
cpuSetAReg(7, sp + 4);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
uint16_t PopWord()
|
||||
{
|
||||
uint32_t sp = cpuGetAReg(7);
|
||||
uint16_t value = memoryReadWord(a7);
|
||||
cpuSetAReg(7, sp + 2);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t StackFrame(uint32_t &b, uint32_t &a)
|
||||
{
|
||||
uint32_t sp = cpuGetAReg(7);
|
||||
a = memoryReadLong(sp); sp += 4;
|
||||
b = memoryReadLong(sp); sp += 4;
|
||||
cpuSetAReg(7, sp);
|
||||
}
|
||||
|
||||
void ToolReturn(uint32_t sp, uint32_t value)
|
||||
{
|
||||
memoryWriteLong(sp, value);
|
||||
}
|
||||
|
||||
std::string PString(uint32_t address)
|
||||
{
|
||||
std::string s;
|
||||
|
||||
unsigned length = address == 0 ? 0 : memoryReadByte(address++);
|
||||
if (length == 0)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
s.reserve(length);
|
||||
for (unsigned i = 0; i < length; ++i)
|
||||
{
|
||||
s.push_back((char)memoryReadByte(address++));
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
namespace RM
|
||||
{
|
||||
uint16_t Get1NamedResource()
|
||||
{
|
||||
// Get1NamedResource (theType: ResType; name: Str255) : Handle;
|
||||
|
||||
/*
|
||||
* -----------
|
||||
* +8 outHandle
|
||||
* ------------
|
||||
* +4 theType
|
||||
* ------------
|
||||
* +0 name
|
||||
* ------------
|
||||
*
|
||||
*/
|
||||
|
||||
// nb - return address is not on the stack.
|
||||
|
||||
uint32_t sp;
|
||||
uint32_t theType;
|
||||
uint32_t name;
|
||||
|
||||
sp = StackFrame(theType, name);
|
||||
|
||||
std::string sname = PString(name);
|
||||
|
||||
printf(stderr, "Get1NamedResource(%08x, %s)\n", theType, sname.c_str());
|
||||
|
||||
ToolReturn(sp, (uint32_t)0);
|
||||
return –192;
|
||||
}
|
||||
}
|
11
toolbox/rm.h
Normal file
11
toolbox/rm.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef __mpw_rm_h__
|
||||
#define __mpw_rm_h__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace RM
|
||||
{
|
||||
uint16_t Get1NamedResource();
|
||||
}
|
||||
|
||||
#endif
|
6
toolbox/toolbox.h
Normal file
6
toolbox/toolbox.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef __mpw_toolbox_h__
|
||||
#define __mpw_toolbox_h__
|
||||
|
||||
extern "C" void toolbox(uint16_t trap);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user