Skip to content

Commit

Permalink
switch to CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzziqersoftware committed Dec 29, 2021
1 parent 9c4f797 commit 8101e43
Show file tree
Hide file tree
Showing 45 changed files with 527 additions and 472 deletions.
20 changes: 15 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
*.o
*.dSYM
# Finder files (macOS)
.DS_Store
resource_dasm
render_bits

# Build products
libresource_file.a
bt_render
dc_dasm
ferazel_render
Expand All @@ -14,6 +14,16 @@ macski_decomp
mohawk_dasm
mshines_render
realmz_dasm
render_bits
resource_dasm
sc2k_render
step_on_it_render
libresource_dasm.a

# CMake files
CMakeCache.txt
CMakeFiles
Makefile
CTestTestFile.cmake
Testing
cmake_install.cmake
install_manifest.txt
52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
cmake_minimum_required(VERSION 3.10)



# Project setup

project(resource_dasm)

set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
if (MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra -Werror)
endif()

include_directories("/usr/local/include")
link_directories("/usr/local/lib")



# Library and executable definitions

add_library(resource_file src/QuickDrawFormats.cc src/QuickDrawEngine.cc src/ResourceFile.cc src/SystemTemplates.cc src/AudioCodecs.cc src/MemoryContext.cc src/InterruptManager.cc src/M68KEmulator.cc src/PEFFFile.cc src/PPC32Emulator.cc src/TrapInfo.cc)

foreach(ExecutableName IN ITEMS resource_dasm dc_dasm ferazel_render hypercard_dasm infotron_render mohawk_dasm gamma_zee_render mshines_render sc2k_render step_on_it_render)
add_executable(${ExecutableName} src/${ExecutableName}.cc)
target_link_libraries(${ExecutableName} resource_file phosg)
endforeach()

add_executable(realmz_dasm src/realmz_dasm.cc src/RealmzLib.cc)
target_link_libraries(realmz_dasm resource_file phosg)

foreach(ExecutableName IN ITEMS bt_render harry_render)
add_executable(${ExecutableName} src/${ExecutableName}.cc src/AmbrosiaSprites.cc)
target_link_libraries(${ExecutableName} resource_file phosg)
endforeach()

foreach(ExecutableName IN ITEMS macski_decomp render_bits)
add_executable(${ExecutableName} src/${ExecutableName}.cc)
target_link_libraries(${ExecutableName} phosg)
endforeach()



# Installation configuration

file(GLOB Headers ${CMAKE_SOURCE_DIR}/src/*.hh)
install(TARGETS resource_file DESTINATION lib)
install(TARGETS resource_dasm DESTINATION bin)
install(FILES ${Headers} DESTINATION include/resource_file)
80 changes: 0 additions & 80 deletions Makefile

This file was deleted.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This project contains multiple tools for reverse-engineering classic Mac OS applications and games.

The most general of these is **resource_dasm**, which reads and converts resources from the resource fork of any classic Mac OS file, including applications. resource_dasm can also disassemble raw 68k or PowerPC machine code, as well as PEFF executables that contain code for either of those CPU architectures. Most of resource_dasm's functionality is also included in a library built alongside it named libresource_dasm.
The most general of these is **resource_dasm**, which reads and converts resources from the resource fork of any classic Mac OS file, including applications. resource_dasm can also disassemble raw 68k or PowerPC machine code, as well as PEFF executables that contain code for either of those CPU architectures. Most of resource_dasm's functionality is also included in a library built alongside it named libresource_file.

There are several programs for working with specific programs (mostly games):
- **bt_render**: converts sprites from Bubble Trouble and Harry the Handsome Executive into BMP images
Expand All @@ -24,8 +24,9 @@ There's also a basic image renderer called **render_bits** which is useful in fi
## Building

- Install Netpbm (http://netpbm.sourceforge.net/). This is only needed for converting PICT resources that resource_dasm can't decode by itself - if you don't care about PICTs, you can skip this step.
- Install CMake.
- Build and install phosg (https://github.com/fuzziqersoftware/phosg).
- Run `make`.
- Run `cmake .`, then `make`.

This project should build properly on sufficiently recent versions of macOS and Linux.

Expand Down Expand Up @@ -342,9 +343,9 @@ There are probably other decompressors out there that I haven't seen which may n

### Using resource_dasm as a library

Run `sudo make install-lib` to copy the header files and library to the relevant paths after building (see the Makefile for the exact paths).
Run `sudo make install` to copy the header files and library to the relevant paths after building.

You can then `#include <resource_dasm/ResourceFile.hh>` and create `ResourceFile` objects in your own projects to read and decode resource fork data. Make sure to link with `-lresource_dasm` as well. There is not much documentation for this library beyond what's in the header file, but usage of the `ResourceFile` class should be fairly straightforward.
You can then `#include <resource_file/ResourceFile.hh>` and create `ResourceFile` objects in your own projects to read and decode resource fork data. Make sure to link with `-lresource_file` as well. There is not much documentation for this library beyond what's in the header file, but usage of the `ResourceFile` class should be fairly straightforward.

## Using the more specific tools

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
31 changes: 19 additions & 12 deletions M68KEmulator.cc → src/M68KEmulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,14 @@ static string format_immediate(int64_t value) {


M68KRegisters::M68KRegisters() {
memset(this, 0, sizeof(*this));
for (size_t x = 0; x < 8; x++) {
this->a[x] = 0;
this->d[x].u = 0;
}
this->pc = 0;
this->sr = 0;
this->debug.read_addr = 0;
this->debug.write_addr = 0;
}

uint32_t M68KRegisters::get_reg_value(bool is_a_reg, uint8_t reg_num) {
Expand Down Expand Up @@ -904,11 +911,11 @@ bool M68KEmulator::check_condition(uint8_t condition) {



void M68KEmulator::exec_unimplemented(uint16_t opcode) {
void M68KEmulator::exec_unimplemented(uint16_t) {
throw runtime_error("unimplemented opcode");
}

string M68KEmulator::dasm_unimplemented(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_unimplemented(StringReader& r, uint32_t, map<uint32_t, bool>&) {
return string_printf(".unimplemented %04hX", r.get_u16r());
}

Expand Down Expand Up @@ -1077,7 +1084,7 @@ void M68KEmulator::exec_0123(uint16_t opcode) {
}
}

string M68KEmulator::dasm_0123(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_0123(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
// 1, 2, 3 are actually also handled by 0 (this is the only case where the i
// field is split)

Expand Down Expand Up @@ -1854,7 +1861,7 @@ void M68KEmulator::exec_7(uint16_t opcode) {
this->regs.set_ccr_flags(-1, (y & 0x80000000), (y == 0), 0, 0);
}

string M68KEmulator::dasm_7(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_7(StringReader& r, uint32_t, map<uint32_t, bool>&) {
uint16_t op = r.get_u16r();
int32_t value = static_cast<int32_t>(static_cast<int8_t>(op_get_y(op)));
return string_printf("moveq.l D%d, 0x%02X", op_get_a(op), value);
Expand Down Expand Up @@ -1915,7 +1922,7 @@ void M68KEmulator::exec_8(uint16_t opcode) {
this->regs.set_ccr_flags(-1, is_negative(value, size), (value == 0), 0, 0);
}

string M68KEmulator::dasm_8(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_8(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
uint16_t op = r.get_u16r();
uint8_t a = op_get_a(op);
uint8_t opmode = op_get_b(op);
Expand Down Expand Up @@ -2027,7 +2034,7 @@ void M68KEmulator::exec_9D(uint16_t opcode) {
this->regs.set_ccr_flags(this->regs.ccr & 0x01, -1, -1, -1, -1);
}

string M68KEmulator::dasm_9D(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_9D(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
uint32_t opcode_start_address = start_address + r.where();
uint16_t op = r.get_u16r();
const char* op_name = ((op & 0xF000) == 0x9000) ? "sub" : "add";
Expand Down Expand Up @@ -2077,7 +2084,7 @@ void M68KEmulator::exec_A(uint16_t opcode) {
}
}

string M68KEmulator::dasm_A(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_A(StringReader& r, uint32_t, map<uint32_t, bool>&) {
uint16_t op = r.get_u16r();

uint16_t trap_number;
Expand Down Expand Up @@ -2148,7 +2155,7 @@ void M68KEmulator::exec_B(uint16_t opcode) {
this->regs.set_ccr_flags_integer_subtract(left_value, right_value, size);
}

string M68KEmulator::dasm_B(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_B(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
uint32_t opcode_start_address = start_address + r.where();
uint16_t op = r.get_u16r();
uint8_t dest = op_get_a(op);
Expand Down Expand Up @@ -2261,7 +2268,7 @@ void M68KEmulator::exec_C(uint16_t opcode) {
}
}

string M68KEmulator::dasm_C(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_C(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
uint16_t op = r.get_u16r();
uint8_t a = op_get_a(op);
uint8_t b = op_get_b(op);
Expand Down Expand Up @@ -2538,7 +2545,7 @@ void M68KEmulator::exec_E(uint16_t opcode) {
}
}

string M68KEmulator::dasm_E(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_E(StringReader& r, uint32_t start_address, map<uint32_t, bool>&) {
uint16_t op = r.get_u16r();

static const vector<const char*> op_names({
Expand Down Expand Up @@ -2619,7 +2626,7 @@ void M68KEmulator::exec_F(uint16_t opcode) {
}
}

string M68KEmulator::dasm_F(StringReader& r, uint32_t start_address, map<uint32_t, bool>& branch_target_addresses) {
string M68KEmulator::dasm_F(StringReader& r, uint32_t, map<uint32_t, bool>&) {
uint16_t opcode = r.get_u16r();
return string_printf(".extension 0x%03hX // unimplemented", opcode & 0x0FFF);
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8101e43

Please sign in to comment.