Compare commits

...

60 Commits

Author SHA1 Message Date
ksherlock 9951892251
Create FUNDING.yml
eh
2024-04-05 09:49:09 -04:00
Kelvin Sherlock 79a8a93e03 update m68k cpu to match current upstream code, which includes a handful of bug fixes (mostly timing related). 2023-10-05 18:47:48 -04:00
Stefan f619ed31b3
Fixed a few typos (#65) 2023-09-14 13:27:53 -04:00
Kelvin Sherlock f460696b4f Add _RelString support, fix the case-sensitive flag in _CmpString 2023-09-02 14:50:02 -04:00
Kelvin Sherlock 6151ca1e87 use rl_attempted_completion_over to suppress standard filename completion logic. 2023-06-30 18:17:50 -04:00
Kelvin Sherlock b9c7d9f95f submodule bump 2023-06-30 16:51:07 -04:00
Kelvin Sherlock 2dcb161f5e ResolveAliasFile - byte ptrs should only write 1 byte. 2022-11-23 13:28:53 -05:00
Ryan Schmidt f08d67333d
Remove macOS 10.15 runner; add macOS 12 runner (#53)
The macOS 10.15 runner is deprecated and will be unsupported by December 1.
2022-11-21 21:14:20 -05:00
Ryan Schmidt 2e7e75a2a9
Return error from FSMakeFSSpec if file not found (#58)
Fixes #56
2022-11-21 21:13:29 -05:00
Ryan Schmidt bdb1f4b2b9
Fix typos in comments (#57) 2022-11-19 23:52:37 -05:00
Ryan Schmidt b8d17f4481
Don't overwrite user-specified CFLAGS and CXXFLAGS (#51)
* Check C and C++ compiler separately

It's possible (however unlikely) that the C++ compiler might be clang
but the C compiler might not be.

* Don't overwrite user-specified CFLAGS and CXXFLAGS
2022-11-19 22:32:44 -05:00
Ryan Schmidt a76287876c
Add error message when loader can't load command (#55)
And change exit code from EX_CONFIG to EX_SOFTWARE.
2022-11-19 22:14:57 -05:00
Kelvin Sherlock 022d4cffe9 update github actions 2022-11-17 21:21:18 -05:00
Kelvin Sherlock 843ea2764c search for ragel and exit if not found. Also use found path when running ragel or lemon. 2022-11-17 21:07:45 -05:00
Ryan Schmidt fc15ad1d81
Update version in CMakeLists.txt to 0.8.3 (#50)
Closes #45
2022-11-17 20:44:22 -05:00
Ryan Schmidt 7ac2a88974
Add newline after read() debug output (#44) 2022-11-15 19:01:21 -05:00
Ryan Schmidt 2703e00201
Use /bin/sh; quote shell variables (#46)
* On macOS, sh is /bin/sh not /usr/bin/sh

* Quote shell variables correctly
2022-11-15 19:00:16 -05:00
Kelvin Sherlock 5facdb095c version bump, allow MB/KB (vs M/K) for ram sizes 2022-10-11 21:11:36 -04:00
Kelvin Sherlock 194c36c89a add GetCurrentProcess / GetProcessInformation (SetVers)
GetProcessInformation is not currently implemented in a meaningful manner.
2022-10-10 21:07:58 -04:00
Kelvin Sherlock 3e2c02f796 .x is a binary extension used for xcoff object files (MrC, etc) 2022-10-10 21:07:13 -04:00
Kelvin Sherlock 48d869c6e8 more SANE tests. 2022-10-10 21:06:44 -04:00
ksherlock 8c911ab83d
Merge pull request #39 from potomak/patch-1
Add step to initialize and fetch submodules
2022-10-08 17:52:07 -04:00
Giovanni Cappellotto b6b0abefbf
Add step to initialize and fetch submodules 2022-10-08 10:19:16 -04:00
ksherlock 67253a69e5
Update cmake-fat.yml 2022-09-23 18:11:20 -04:00
ksherlock f3b3d221be
Merge pull request #37 from uliwitness/patch-1
Make build instructions no longer be on a single line.
2022-09-23 16:11:09 -04:00
Uli Kusterer f4e3bd70a1
Make build instructions no longer be on a single line. 2022-09-23 19:34:06 +02:00
ksherlock 1925dc172b
Update .travis.yml 2021-05-31 00:33:52 -04:00
Kelvin Sherlock 4730a70874 include generated lemon code so lemon isn't needed. 2021-05-30 23:29:34 -04:00
Kelvin Sherlock a70270be52 bump submodule 2021-05-30 23:00:53 -04:00
Kelvin Sherlock f12b3789c4 typo 2021-05-30 22:42:13 -04:00
Kelvin Sherlock 6dfefb2343 bump submodule 2020-11-26 22:11:09 -05:00
ksherlock 35443c9aa8
Update cmake-fat.yml 2020-11-26 15:58:17 -05:00
ksherlock fcdfe76817
Update cmake-fat.yml 2020-11-26 15:52:45 -05:00
ksherlock a55b38104b
Update cmake-fat.yml 2020-11-26 15:51:18 -05:00
ksherlock fb0d353716
Update cmake-fat.yml 2020-11-26 15:42:45 -05:00
ksherlock 7dc85091a3
Create cmake-fat.yml 2020-11-26 15:36:09 -05:00
Kelvin Sherlock 0cca883287 xp support for reading 80-bit extended numbers on platforms without a native 80-bit extended type.
previously this meant win32 and linux arm, now this includes Apple ARM as well.
2020-11-26 09:39:39 -05:00
ksherlock 58f2557df5
Update cmake.yml 2020-11-16 09:17:26 -05:00
ksherlock 031cdf0d08
Update cmake.yml 2020-11-16 09:11:13 -05:00
Kelvin Sherlock c8310c0dbd fixup clang range warnings. 2020-11-05 18:53:52 -05:00
ksherlock 3480881001
Update cmake.yml 2020-11-05 18:50:36 -05:00
ksherlock 8f64923f9c
Update cmake.yml 2020-11-05 13:29:39 -05:00
ksherlock 7cb4c8cbc3
Create cmake.yml 2020-11-05 12:04:53 -05:00
Kelvin Sherlock 1a9cb0d766 Beef up the IUDateString/UIDateTime functions. Needed for a Date built-in replacement. 2020-07-13 23:43:24 -04:00
Kelvin Sherlock 02629c4eee 0-byte read request should not trigger eof error. 2019-08-17 10:33:12 -04:00
Kelvin Sherlock fa1f4623c9 submodule update. 2018-07-24 11:23:32 -04:00
Kelvin Sherlock b560c66dda fix case-insensitive includes. 2018-01-01 14:15:17 -05:00
Kelvin Sherlock 2eb90481bc remove old sane code (moved to libsane). 2018-01-01 14:13:30 -05:00
Kelvin Sherlock 8c38175492 bump version. 2017-12-14 10:50:50 -05:00
Kelvin Sherlock 08fef2cef5 update libsane 2017-12-14 10:47:45 -05:00
Kelvin Sherlock fb6d52a93d sync cpu code with fellow. fixes some instruction times and 64-bit division. 2017-12-14 08:23:17 -05:00
Kelvin Sherlock 26bd3f53b7 submodule update. 2017-12-13 21:59:18 -05:00
Kelvin Sherlock d11dab46e2 use libsane... 2017-12-13 21:58:43 -05:00
Kelvin Sherlock c3d1121f36 case sensitive headers. 2017-10-02 21:16:12 -04:00
Kelvin Sherlock 776b385a41 update mpw open to be more consistent with actual implementation. Also support for non-HFS volumes. 2017-10-02 21:15:51 -04:00
Kelvin Sherlock 119d9aab57 APFS - when opening a resource fork as rdwr, create it as well
--
Under HFS, empty resource fork always exists. on APFS, it must be specifically created.
2017-10-02 16:31:33 -04:00
Kelvin Sherlock 60b49a1ff4 fix ptr bug. 2017-10-02 15:11:43 -04:00
Kelvin Sherlock e21aac4022 clean up makefiles a bit. 2017-10-02 15:11:28 -04:00
Kelvin Sherlock 60c4977dfa fix build error. 2016-08-01 16:02:51 -04:00
Kelvin Sherlock 58f4ca4ac6 improve PBGetCatInfo 2016-07-31 13:26:41 -04:00
76 changed files with 15497 additions and 11786 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,3 @@
# These are supported funding model platforms
github: [ksherlock]

38
.github/workflows/cmake-fat.yml vendored Normal file
View File

@ -0,0 +1,38 @@
name: CMake fat
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Brew
run: brew install ragel lemon
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: make mpw
- name: Archive
uses: actions/upload-artifact@v3
with:
name: mpw fat
path: ${{runner.workspace}}/build/bin/mpw

42
.github/workflows/cmake.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: CMake
on: [push]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-12, macos-11]
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Brew
run: brew install ragel lemon
- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
shell: bash
working-directory: ${{runner.workspace}}/build
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: cmake --build . --config $BUILD_TYPE
- name: Archive
uses: actions/upload-artifact@v3
with:
name: mpw ${{ matrix.os }}
path: ${{runner.workspace}}/build/bin/mpw

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "libsane"]
path = libsane
url = https://github.com/ksherlock/libsane.git

View File

@ -1,4 +1,8 @@
os: osx
osx_image:
- xcode11
- xcode12
- xcode12.5
language: cpp
compiler: clang
before_script:

View File

@ -1,10 +1,32 @@
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")
cmake_minimum_required(VERSION 3.1)
project(mpw VERSION 0.8.3 LANGUAGES CXX C)
project(mpw)
cmake_minimum_required(VERSION 2.6)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_EXTENSIONS FALSE)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_C_EXTENSIONS FALSE)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_CXX_FLAGS "-Wall ${CMAKE_CXX_FLAGS}")
endif()
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_C_FLAGS "-Wall ${CMAKE_C_FLAGS}")
endif()
find_program(RAGEL NAMES ragel)
if (NOT RAGEL)
message(FATAL_ERROR "ragel (version 6) is required.")
endif()
include_directories("${CMAKE_SOURCE_DIR}")
add_subdirectory(bin)
add_subdirectory(cpu)
@ -12,3 +34,5 @@ add_subdirectory(toolbox)
add_subdirectory(mplite)
add_subdirectory(mpw)
add_subdirectory(macos)
add_subdirectory(libsane)

View File

@ -24,13 +24,18 @@ is in the public domain.
## Building
First initialize and fetch submodules:
git submodule init
git submodule update
Compiling requires cmake, ragel, lemon, and a recent version of clang++ with
c++11 support. It has only been built and tested with OS X 10.8+.
mkdir build
cd build
cmake ..
make
mkdir build
cd build
cmake ..
make
This will generate `bin/mpw` and `bin/disasm`.
@ -85,9 +90,9 @@ or create a shell script (in `/usr/local/bin`, etc)
`/usr/local/bin/AsmIIgs`:
#!/usr/bin/sh
#!/bin/sh
exec mpw AsmIIgs $@
exec mpw AsmIIgs "$@"
mpw uses the MPW `$Commands` variable to find the command, similar to `$PATH` on Unix. If the `$Commands` variable

View File

@ -84,9 +84,9 @@ or create a shell script (in /usr/local/bin, etc)
/usr/local/bin/AsmIIgs:
#!/usr/bin/sh
#!/bin/sh
exec mpw AsmIIgs $@
exec mpw AsmIIgs "$@"
mpw looks in the current directory and then in the $MPW:Tools: directory
for the command to run. The MPW $Commands variable is not yet supported.

View File

@ -1,53 +1,47 @@
#set(CMAKE_C_COMPILER "clang")
#set(CMAKE_CXX_COMPILER "clang++")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Wno-deprecated-declarations -g")
SET(CMAKE_EXE_LINKER_FLAGS "-framework Carbon")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
# add_custom_command(
# OUTPUT lexer.cpp
# COMMAND re2c -b -i -o lexer.cpp "${CMAKE_CURRENT_SOURCE_DIR}/lexer.re.cpp"
# MAIN_DEPENDENCY lexer.re.cpp
# DEPENDS debugger.h parser.h
# )
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-unused-variable")
endif()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_command(
OUTPUT lexer.cpp
COMMAND ragel -p -G2 -o lexer.cpp "${CMAKE_CURRENT_SOURCE_DIR}/lexer.rl"
COMMAND "${RAGEL}" -p -G2 -o lexer.cpp "${CMAKE_CURRENT_SOURCE_DIR}/lexer.rl"
MAIN_DEPENDENCY lexer.rl
)
add_custom_command(
OUTPUT parser.cpp parser.h
COMMAND cp -f "${CMAKE_CURRENT_SOURCE_DIR}/parser.lemon" "parser.lemon"
COMMAND lemon parser.lemon
COMMAND cp -f parser.h "${CMAKE_CURRENT_SOURCE_DIR}/"
COMMAND cp -f parser.out "${CMAKE_CURRENT_SOURCE_DIR}/"
COMMAND mv -f parser.c parser.cpp
MAIN_DEPENDENCY parser.lemon
DEPENDS debugger.h
)
find_program(LEMON NAMES lemon)
if (LEMON)
add_custom_command(
OUTPUT template_parser.cpp template_parser.h
COMMAND cp -f "${CMAKE_CURRENT_SOURCE_DIR}/template_parser.lemon" "template_parser.lemon"
COMMAND lemon template_parser.lemon
COMMAND cp -f template_parser.h "${CMAKE_CURRENT_SOURCE_DIR}/"
COMMAND cp -f template_parser.out "${CMAKE_CURRENT_SOURCE_DIR}/"
COMMAND mv -f template_parser.c template_parser.cpp
MAIN_DEPENDENCY template_parser.lemon
DEPENDS debugger.h
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/parser.h
# COMMAND cp -f "${CMAKE_CURRENT_SOURCE_DIR}/parser.lemon" "parser.lemon"
COMMAND ${LEMON} parser.lemon
COMMAND mv -f parser.c parser.cpp
MAIN_DEPENDENCY parser.lemon
DEPENDS debugger.h
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/template_parser.cpp ${CMAKE_CURRENT_SOURCE_DIR}/template_parser.h
# COMMAND cp -f "${CMAKE_CURRENT_SOURCE_DIR}/template_parser.lemon" "template_parser.lemon"
COMMAND ${LEMON} template_parser.lemon
COMMAND mv -f template_parser.c template_parser.cpp
MAIN_DEPENDENCY template_parser.lemon
DEPENDS debugger.h
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
endif()
add_custom_command(
OUTPUT loadtrap.cpp
COMMAND ragel -p -G2 -o loadtrap.cpp "${CMAKE_CURRENT_SOURCE_DIR}/loadtrap.rl"
COMMAND "${RAGEL}" -p -G2 -o loadtrap.cpp "${CMAKE_CURRENT_SOURCE_DIR}/loadtrap.rl"
MAIN_DEPENDENCY loadtrap.rl
DEPENDS debugger.h
)
@ -55,20 +49,12 @@ add_custom_command(
add_custom_command(
OUTPUT template_loader.cpp
COMMAND ragel -p -G2 -o template_loader.cpp "${CMAKE_CURRENT_SOURCE_DIR}/template_loader.rl"
COMMAND "${RAGEL}" -p -G2 -o template_loader.cpp "${CMAKE_CURRENT_SOURCE_DIR}/template_loader.rl"
MAIN_DEPENDENCY template_loader.rl
DEPENDS debugger.h template_parser.h
)
set_source_files_properties(
loadtrap.cpp lexer.cpp template_loader.cpp
PROPERTIES
COMPILE_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-unused-variable"
)
add_executable(mpw loader.cpp debugger.cpp debugger_internal.cpp
address_map.cpp lexer.cpp parser.cpp loadtrap.cpp
commands.cpp
@ -80,12 +66,14 @@ target_link_libraries(mpw TOOLBOX_LIB)
target_link_libraries(mpw MPW_LIB)
target_link_libraries(mpw MPLITE_LIB)
target_link_libraries(mpw MACOS_LIB)
set_target_properties(mpw PROPERTIES LINK_FLAGS "-ledit")
target_link_libraries(mpw -ledit)
target_link_libraries(mpw "-framework Carbon")
add_executable(disasm disasm.cpp)
target_link_libraries(disasm CPU_LIB)
target_link_libraries(disasm MACOS_LIB)
target_link_libraries(disasm "-framework Carbon")
install(
PROGRAMS

View File

@ -1135,6 +1135,8 @@ namespace {
{
std::string s(text);
rl_attempted_completion_over = 1; // suppress filename completion if no results.
// returns iter to first element _not less_ than key
// ie, >= key.
auto iter = SymbolTable.lower_bound(s);
@ -1213,19 +1215,11 @@ namespace {
return buffer;
}
// this is here to prevent filename tab completion, for now.
// state is 0 for first call, non-zero for subsequent calls. It
// should return 1 match per invocation, NULL if no more matches.
char *mpw_completion_entry_function(const char *text, int state)
{
return NULL;
}
void readline_init()
{
rl_readline_name = (char *)"mpw";
rl_attempted_completion_function = mpw_attempted_completion_function;
rl_completion_entry_function = (Function *)mpw_completion_entry_function;
}
}
@ -1252,13 +1246,13 @@ void Shell()
// load the error code to error mnemonic
ErrorTableInvert.reserve(ErrorTable.size());
for (const auto kv : ErrorTable) {
for (const auto &kv : ErrorTable) {
ErrorTableInvert.emplace(std::make_pair(kv.second, kv.first));
}
// address to function name.
SymbolTableInvert.reserve(SymbolTable.size());
for (const auto kv : SymbolTable) {
for (const auto &kv : SymbolTable) {
SymbolTableInvert.emplace(std::make_pair(kv.second.first, kv.first));
}

View File

@ -583,7 +583,7 @@ void MidInstructionExceptionFunc()
}
#define MPW_VERSION "0.8.0"
#define MPW_VERSION "0.8.3"
void help()
{
printf("MPW " MPW_VERSION "\n");
@ -624,9 +624,9 @@ bool parse_number(const char *input, uint32_t *dest)
if (*end)
{
int old = value;
if (strcasecmp(end, "M") == 0)
if (strcasecmp(end, "M") == 0 || strcasecmp(end, "MB") == 0)
value *= 1024 * 1024;
else if (strcasecmp(end, "K") == 0)
else if (strcasecmp(end, "K") == 0 || strcasecmp(end, "KB") == 0)
value *= 1024;
else
{
@ -957,10 +957,19 @@ int main(int argc, char **argv)
#ifdef LOADER_LOAD
uint16_t err = Loader::Native::LoadFile(command);
if (err) exit(EX_CONFIG);
if (err) {
const char *cp = ErrorName(err);
fprintf(stderr, "Unable to load command %s: ", command.c_str());
if (cp) printf("%s\n", cp);
else printf("%hd\n", err);
exit(EX_SOFTWARE);
}
#else
uint32_t address = load(command.c_str());
if (!address) exit(EX_CONFIG);
if (!address) {
fprintf(stderr, "Unable to load command %s\n", command.c_str());
exit(EX_SOFTWARE);
}
#endif
GlobalInit();

1868
bin/parser.cpp Normal file

File diff suppressed because it is too large Load Diff

51
bin/parser.h Normal file
View File

@ -0,0 +1,51 @@
#define tkPIPEPIPE 1
#define tkAMPAMP 2
#define tkPIPE 3
#define tkCARET 4
#define tkAMP 5
#define tkEQEQ 6
#define tkBANGEQ 7
#define tkLT 8
#define tkLTEQ 9
#define tkGT 10
#define tkGTEQ 11
#define tkLTLT 12
#define tkGTGT 13
#define tkPLUS 14
#define tkMINUS 15
#define tkSTAR 16
#define tkSLASH 17
#define tkPERCENT 18
#define tkBANG 19
#define tkTILDE 20
#define tkEOL 21
#define tkPRINT 22
#define tkBREAK 23
#define tkBACKTRACE 24
#define tkCONTINUE 25
#define tkTBREAK 26
#define tkRBREAK 27
#define tkWBREAK 28
#define tkRWBREAK 29
#define tkNEXT 30
#define tkDUMP 31
#define tkCOLON 32
#define tkAT 33
#define tkLIST 34
#define tkSTACKCRAWL 35
#define tkSEMI 36
#define tkSEMIH 37
#define tkSEMII 38
#define tkSEMIL 39
#define tkSEMIDATE 40
#define tkSEMIERROR 41
#define tkSEMIT 42
#define tkIDENTIFIER 43
#define tkDREGISTER 44
#define tkEQ 45
#define tkAREGISTER 46
#define tkXREGISTER 47
#define tkHELP 48
#define tkLPAREN 49
#define tkRPAREN 50
#define tkINTEGER 51

View File

@ -11,7 +11,7 @@
#include <cstddef>
#include "debugger.h"
#include <toolbox/MM.h>
#include <toolbox/mm.h>
using Debug::Token;

1291
bin/template_parser.cpp Normal file

File diff suppressed because it is too large Load Diff

20
bin/template_parser.h Normal file
View File

@ -0,0 +1,20 @@
#define tkTYPEDEF 1
#define tkIDENTIFIER 2
#define tkSTRUCT 3
#define tkLBRACE 4
#define tkRBRACE 5
#define tkSEMI 6
#define tkTEMPLATE 7
#define tkLBRACKET 8
#define tkINTEGER 9
#define tkRBRACKET 10
#define tkVOLATILE 11
#define tkSIGNED 12
#define tkUNSIGNED 13
#define tkCHAR 14
#define tkSHORT 15
#define tkLONG 16
#define tkTYPECODE 17
#define tkVOID 18
#define tkSTAR 19
#define tkINT 20

View File

@ -1,6 +1,12 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_CXX_FLAGS "-Wall -Wno-unused-function")
endif()
set(CMAKE_C_FLAGS " -Wall -Wno-unused-function -g")
if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_C_FLAGS "-Wall -Wno-unused-function")
endif()
set(CPU_SRC
CpuModule.c

View File

@ -1,8 +1,7 @@
/* @(#) $Id: CpuIntegration.c,v 1.10 2013-01-08 19:17:33 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* Initialization of 68000 core */
/* Integrates the 68k emulation with custom chips */
/* Integrates the 68k emulation with custom chips */
/* */
/* Author: Petter Schau */
/* */
@ -34,47 +33,47 @@
#include "interrupt.h"
jmp_buf cpu_integration_exception_buffer;
ULO cpu_integration_chip_interrupt_number;
uint32_t cpu_integration_chip_interrupt_number;
/* Cycles spent by chips (Blitter) as a result of an instruction */
static ULO cpu_integration_chip_cycles;
static ULO cpu_integration_chip_slowdown;
static uint32_t cpu_integration_chip_cycles;
static uint32_t cpu_integration_chip_slowdown;
/*===========================================================================*/
/* CPU properties */
/*===========================================================================*/
ULO cpu_integration_speed; // The speed as expressed in the fellow configuration settings
ULO cpu_integration_speed_multiplier; // The cycle multiplier used to adjust the cpu-speed, calculated from cpu_integration_speed
uint32_t cpu_integration_speed; // The speed as expressed in the fellow configuration settings
uint32_t cpu_integration_speed_multiplier; // The cycle multiplier used to adjust the cpu-speed, calculated from cpu_integration_speed
cpu_integration_models cpu_integration_model; // The cpu model as expressed in the fellow configuration settings
/*===========================================================================*/
/* CPU properties */
/*===========================================================================*/
void cpuIntegrationSetSpeed(ULO speed)
void cpuIntegrationSetSpeed(uint32_t speed)
{
cpu_integration_speed = speed;
}
ULO cpuIntegrationGetSpeed(void)
uint32_t cpuIntegrationGetSpeed(void)
{
return cpu_integration_speed;
}
static void cpuIntegrationSetSpeedMultiplier(ULO multiplier)
static void cpuIntegrationSetSpeedMultiplier(uint32_t multiplier)
{
cpu_integration_speed_multiplier = multiplier;
}
static ULO cpuIntegrationGetSpeedMultiplier(void)
static uint32_t cpuIntegrationGetSpeedMultiplier(void)
{
return cpu_integration_speed_multiplier;
}
void cpuIntegrationCalculateMultiplier(void)
{
ULO multiplier = 12;
uint32_t multiplier = 12;
switch (cpuGetModelMajor())
{
@ -121,39 +120,39 @@ cpu_integration_models cpuIntegrationGetModel(void)
return cpu_integration_model;
}
void cpuIntegrationSetChipCycles(ULO chip_cycles)
void cpuIntegrationSetChipCycles(uint32_t chip_cycles)
{
cpu_integration_chip_cycles = chip_cycles;
}
ULO cpuIntegrationGetChipCycles(void)
uint32_t cpuIntegrationGetChipCycles(void)
{
return cpu_integration_chip_cycles;
}
void cpuIntegrationSetChipSlowdown(ULO chip_slowdown)
void cpuIntegrationSetChipSlowdown(uint32_t chip_slowdown)
{
cpu_integration_chip_slowdown = chip_slowdown;
}
ULO cpuIntegrationGetChipSlowdown(void)
uint32_t cpuIntegrationGetChipSlowdown(void)
{
return cpu_integration_chip_slowdown;
}
void cpuIntegrationSetChipInterruptNumber(ULO chip_interrupt_number)
void cpuIntegrationSetChipInterruptNumber(uint32_t chip_interrupt_number)
{
cpu_integration_chip_interrupt_number = chip_interrupt_number;
}
ULO cpuIntegrationGetChipInterruptNumber(void)
uint32_t cpuIntegrationGetChipInterruptNumber(void)
{
return cpu_integration_chip_interrupt_number;
}
// A wrapper for cpuSetIrqLevel that restarts the
// scheduling of cpu events if the cpu was stoppped
void cpuIntegrationSetIrqLevel(ULO new_interrupt_level, ULO chip_interrupt_number)
void cpuIntegrationSetIrqLevel(uint32_t new_interrupt_level, uint32_t chip_interrupt_number)
{
if (cpuSetIrqLevel(new_interrupt_level))
{
@ -241,7 +240,7 @@ void cpuIntegrationInstructionLogging(void)
fprintf(CPUINSTRUCTIONLOG, "SSP:%.6X USP:%.6X SP:%.4X %s %s\t%s\t%s\n", cpuGetSspDirect(), cpuGetUspDirect(), cpuGetSR(), saddress, sdata, sinstruction, soperands);
}
void cpuIntegrationExceptionLogging(STR *description, ULO original_pc, UWO opcode)
void cpuIntegrationExceptionLogging(char *description, uint32_t original_pc, uint16_t opcode)
{
if (cpu_disable_instruction_log) return;
cpuInstructionLogOpen();
@ -250,7 +249,7 @@ void cpuIntegrationExceptionLogging(STR *description, ULO original_pc, UWO opcod
fprintf(CPUINSTRUCTIONLOG, "%s for opcode %.4X at PC %.8X from PC %.8X\n", description, opcode, original_pc, cpuGetPC());
}
void cpuIntegrationInterruptLogging(ULO level, ULO vector_address)
void cpuIntegrationInterruptLogging(uint32_t level, uint32_t vector_address)
{
if (cpu_disable_instruction_log) return;
cpuInstructionLogOpen();
@ -263,8 +262,7 @@ void cpuIntegrationInterruptLogging(ULO level, ULO vector_address)
void cpuIntegrationExecuteInstructionEventHandler68000Fast(void)
{
ULO cycles;
cycles = cpuExecuteInstruction();
uint32_t cycles = cpuExecuteInstruction();
if (cpuGetStop())
{
@ -279,8 +277,8 @@ void cpuIntegrationExecuteInstructionEventHandler68000Fast(void)
void cpuIntegrationExecuteInstructionEventHandler68000General(void)
{
ULO cycles = 0;
ULO time_used = 0;
uint32_t cycles = 0;
uint32_t time_used = 0;
do
{
@ -303,7 +301,7 @@ void cpuIntegrationExecuteInstructionEventHandler68000General(void)
void cpuIntegrationExecuteInstructionEventHandler68020(void)
{
ULO time_used = 0;
uint32_t time_used = 0;
do
{
cpuExecuteInstruction();

View File

@ -1,5 +1,4 @@
#ifndef CpuIntegration_H
#define CpuIntegration_H
#pragma once
#ifdef __cplusplus
extern "C" {
@ -16,25 +15,23 @@ typedef enum {
extern void cpuIntegrationCalculateMultiplier(void);
extern void cpuIntegrationSetUpInterruptEventHandler(void);
extern void cpuIntegrationExecuteInstructionEventHandler68000Fast(void);
extern void cpuIntegrationExecuteInstructionEventHandler68000General(void);
extern void cpuIntegrationExecuteInstructionEventHandler68020(void);
extern void cpuIntegrationCheckPendingInterrupts(void);
extern ULO cpuIntegrationDisOpcode(ULO disasm_pc, STR *saddress, STR *sdata, STR *sinstruction, STR *soperands);
extern uint32_t cpuIntegrationDisOpcode(uint32_t disasm_pc, char *saddress, char *sdata, char *sinstruction, char *soperands);
extern BOOLE cpuIntegrationSetModel(cpu_integration_models model);
extern cpu_integration_models cpuIntegrationGetModel(void);
extern ULO cpuIntegrationGetModelMajor(void);
extern ULO cpuIntegrationGetPC(void);
extern uint32_t cpuIntegrationGetModelMajor(void);
extern ULO cpuIntegrationGetInstructionTime(void);
extern void cpuIntegrationSetSpeed(ULO speed);
extern ULO cpuIntegrationGetSpeed(void);
extern void cpuIntegrationSetChipCycles(ULO chip_cycles);
extern ULO cpuIntegrationGetChipCycles(void);
extern void cpuIntegrationSetChipSlowdown(ULO chip_slowdown);
extern ULO cpuIntegrationGetChipSlowdown(void);
void cpuIntegrationSetIrqLevel(uint32_t new_interrupt_level, uint32_t chip_interrupt_number);
extern uint32_t cpuIntegrationGetInstructionTime(void);
extern void cpuIntegrationSetSpeed(uint32_t speed);
extern uint32_t cpuIntegrationGetSpeed(void);
extern void cpuIntegrationSetChipCycles(uint32_t chip_cycles);
extern uint32_t cpuIntegrationGetChipCycles(void);
extern void cpuIntegrationSetChipSlowdown(uint32_t chip_slowdown);
extern uint32_t cpuIntegrationGetChipSlowdown(void);
extern jmp_buf cpu_integration_exception_buffer;
@ -50,5 +47,3 @@ extern void cpuIntegrationShutdown(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule.c,v 1.7 2012-08-12 16:51:02 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* Initialization of 68000 core */
@ -29,10 +28,8 @@
void cpuClearEverything(void)
{
ULO i,j;
for (j = 0; j < 2; j++)
for (i = 0; i < 8; i++)
for (uint32_t j = 0; j < 2; j++)
for (uint32_t i = 0; i < 8; i++)
cpuSetReg(j, i, 0);
cpuSetUspDirect(0);
@ -47,7 +44,6 @@ void cpuClearEverything(void)
cpuSetSfc(0);
cpuSetDfc(0);
cpuSetIrqLevel(0);
cpuSetRaiseInterrupt(FALSE);
cpuSetStop(FALSE);
cpuSetInstructionTime(0);
cpuSetOriginalPC(0);

View File

@ -1,87 +1,88 @@
#ifndef CpuModule_H
#define CpuModule_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
// This header file defines the internal interfaces of the CPU module.
// MPW additions.
typedef void (*cpuLineExceptionFunc)(uint16_t);
extern void cpuSetALineExceptionFunc(cpuLineExceptionFunc func);
extern void cpuSetFLineExceptionFunc(cpuLineExceptionFunc func);
// This header file defines the internal interfaces of the CPU module.
//#define CPU_INSTRUCTION_LOGGING
// Function to check if there are any external interrupt sources wanting to issue interrupts
typedef BOOLE (*cpuCheckPendingInterruptsFunc)(void);
extern void cpuSetCheckPendingInterruptsFunc(cpuCheckPendingInterruptsFunc func);
extern void cpuCheckPendingInterrupts(void);
extern void cpuSetUpInterrupt(ULO new_interrupt_level);
extern void cpuInitializeFromNewPC(ULO new_pc);
typedef void (*memoryLoggingFunc)(uint32_t address, int size, int readWrite, uint32_t value);
extern void memorySetLoggingFunc(memoryLoggingFunc func);
#ifdef _DEBUG
#define CPU_INSTRUCTION_LOGGING
#endif
// Function to check if there are any external interrupt sources wanting to issue interrupts
typedef void (*cpuCheckPendingInterruptsFunc)(void);
extern void cpuSetCheckPendingInterruptsFunc(cpuCheckPendingInterruptsFunc func);
extern void cpuCheckPendingInterrupts(void);
extern void cpuSetUpInterrupt(uint32_t new_interrupt_level);
extern void cpuInitializeFromNewPC(uint32_t new_pc);
// Logging interface
#ifdef CPU_INSTRUCTION_LOGGING
typedef void (*cpuInstructionLoggingFunc)(void);
extern void cpuSetInstructionLoggingFunc(cpuInstructionLoggingFunc func);
typedef void (*cpuExceptionLoggingFunc)(STR *description, ULO original_pc, UWO opcode);
typedef void (*cpuExceptionLoggingFunc)(char *description, uint32_t original_pc, uint16_t opcode);
extern void cpuSetExceptionLoggingFunc(cpuExceptionLoggingFunc func);
typedef void (*cpuInterruptLoggingFunc)(ULO level, ULO vector_address);
typedef void (*cpuInterruptLoggingFunc)(uint32_t level, uint32_t vector_address);
extern void cpuSetInterruptLoggingFunc(cpuInterruptLoggingFunc func);
#endif
// CPU register and control properties
extern void cpuSetPC(ULO pc);
extern ULO cpuGetPC(void);
extern void cpuSetPC(uint32_t pc);
extern uint32_t cpuGetPC(void);
extern void cpuSetReg(ULO da, ULO i, ULO value);
extern ULO cpuGetReg(ULO da, ULO i);
extern void cpuSetReg(uint32_t da, uint32_t i, uint32_t value);
extern uint32_t cpuGetReg(uint32_t da, uint32_t i);
extern void cpuSetDReg(ULO i, ULO value);
extern ULO cpuGetDReg(ULO i);
extern void cpuSetDReg(uint32_t i, uint32_t value);
extern uint32_t cpuGetDReg(uint32_t i);
extern void cpuSetAReg(ULO i, ULO value);
extern ULO cpuGetAReg(ULO i);
extern void cpuSetAReg(uint32_t i, uint32_t value);
extern uint32_t cpuGetAReg(uint32_t i);
extern void cpuSetSR(ULO sr);
extern ULO cpuGetSR(void);
extern void cpuSetSR(uint32_t sr);
extern uint32_t cpuGetSR(void);
extern void cpuSetUspDirect(ULO usp);
extern ULO cpuGetUspDirect(void);
extern ULO cpuGetUspAutoMap(void);
extern void cpuSetUspDirect(uint32_t usp);
extern uint32_t cpuGetUspDirect(void);
extern uint32_t cpuGetUspAutoMap(void);
extern void cpuSetMspDirect(ULO msp);
extern ULO cpuGetMspDirect(void);
extern void cpuSetMspDirect(uint32_t msp);
extern uint32_t cpuGetMspDirect(void);
extern void cpuSetSspDirect(ULO ssp);
extern ULO cpuGetSspDirect(void);
extern ULO cpuGetSspAutoMap(void);
extern void cpuSetSspDirect(uint32_t ssp);
extern uint32_t cpuGetSspDirect(void);
extern uint32_t cpuGetSspAutoMap(void);
extern ULO cpuGetVbr(void);
extern uint32_t cpuGetVbr(void);
extern void cpuSetStop(BOOLE stop);
extern BOOLE cpuGetStop(void);
extern void cpuSetInitialPC(ULO pc);
extern ULO cpuGetInitialPC(void);
extern void cpuSetInitialPC(uint32_t pc);
extern uint32_t cpuGetInitialPC(void);
extern void cpuSetInitialSP(ULO sp);
extern ULO cpuGetInitialSP(void);
extern void cpuSetInitialSP(uint32_t sp);
extern uint32_t cpuGetInitialSP(void);
extern ULO cpuGetInstructionTime(void);
extern uint32_t cpuGetInstructionTime(void);
extern BOOLE cpuSetIrqLevel(ULO irq_level);
extern ULO cpuGetIrqLevel(void);
extern BOOLE cpuSetIrqLevel(uint32_t irq_level);
extern uint32_t cpuGetIrqLevel(void);
extern ULO cpuExecuteInstruction(void);
extern ULO cpuDisOpcode(ULO disasm_pc, STR *saddress, STR *sdata, STR *sinstruction, STR *soperands);
extern uint32_t cpuExecuteInstruction(void);
extern uint32_t cpuDisOpcode(uint32_t disasm_pc, char *saddress, char *sdata, char *sinstruction, char *soperands);
extern void cpuSaveState(FILE *F);
extern void cpuLoadState(FILE *F);
@ -96,12 +97,10 @@ typedef void (*cpuResetExceptionFunc)(void);
extern void cpuSetResetExceptionFunc(cpuResetExceptionFunc func);
// Configuration settings
extern void cpuSetModel(ULO major, ULO minor);
extern ULO cpuGetModelMajor(void);
extern ULO cpuGetModelMinor(void);
extern void cpuSetModel(uint32_t major, uint32_t minor);
extern uint32_t cpuGetModelMajor(void);
extern uint32_t cpuGetModelMinor(void);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,105 +1,102 @@
#ifndef CPUMODULE_DISASSEMBLER_H
#define CPUMODULE_DISASSEMBLER_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
extern ULO cpuDisOpcode(ULO disasm_pc, STR *saddress, STR *sdata, STR *sinstruction, STR *soperands);
extern uint32_t cpuDisOpcode(uint32_t disasm_pc, char *saddress, char *sdata, char *sinstruction, char *soperands);
extern ULO cpuDisIllegal(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAbcd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAdd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAdda(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAddi(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAddq(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAddx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAnd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAndi(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisAsx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisBcc(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisBt(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisChk(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisClr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCmp(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCmpa(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCmpi(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCmpm(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisDBcc(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisDivs(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisDivu(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisEor(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisEori(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisExg(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisExt(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisJmp(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisJsr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisLea(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisLink(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisLsx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMove(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveToCcr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveToSr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveFromSr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveUsp(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMovea(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMovem(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMovep(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveq(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMuls(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMulu(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisNbcd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisNeg(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisNegx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisNop(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisNot(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisOr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisOri(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisPea(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisReset(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRox(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRoxx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRte(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRtr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRts(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSbcd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisScc(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisStop(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSub(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSuba(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSubi(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSubq(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSubx(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisSwap(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisTas(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisTrap(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisTrapv(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisTst(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisUnlk(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisBkpt(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisBf(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCas(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisChkl(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisChk2(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisDivl(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisExtb(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisLinkl(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoveFromCcr(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMovec(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMoves(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisMull(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisPack(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisPflush030(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisPflush040(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisPtest040(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRtd(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisTrapcc(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisUnpk(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisCallm(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern ULO cpuDisRtm(ULO prc, ULO opc, STR *sdata, STR *sinstruction, STR *soperands);
extern uint32_t cpuDisIllegal(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAbcd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAdd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAdda(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAddi(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAddq(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAddx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAnd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAndi(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisAsx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisBcc(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisBt(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisChk(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisClr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCmp(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCmpa(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCmpi(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCmpm(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisDBcc(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisDivs(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisDivu(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisEor(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisEori(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisExg(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisExt(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisJmp(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisJsr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisLea(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisLink(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisLsx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMove(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveToCcr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveToSr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveFromSr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveUsp(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMovea(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMovem(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMovep(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveq(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMuls(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMulu(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisNbcd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisNeg(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisNegx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisNop(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisNot(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisOr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisOri(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisPea(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisReset(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRox(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRoxx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRte(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRtr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRts(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSbcd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisScc(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisStop(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSub(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSuba(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSubi(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSubq(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSubx(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisSwap(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisTas(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisTrap(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisTrapv(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisTst(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisUnlk(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisBkpt(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisBf(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCas(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisChkl(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisChk2(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisDivl(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisExtb(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisLinkl(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoveFromCcr(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMovec(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMoves(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisMull(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisPack(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisPflush030(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisPflush040(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisPtest040(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRtd(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisTrapcc(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisUnpk(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisCallm(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
extern uint32_t cpuDisRtm(uint32_t prc, uint32_t opc, char *sdata, char *sinstruction, char *soperands);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,7 +1,6 @@
#ifndef CPUMODULE_DISASSEMBLERFUNC_H
#define CPUMODULE_DISASSEMBLERFUNC_H
#pragma once
static UBY cpu_dis_func_tab[65536] =
static uint8_t cpu_dis_func_tab[65536] =
{
60,60,60,60,60,60,60,60,0,0,0,0,0,0,0,0,
60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,
@ -259,7 +258,7 @@ static UBY cpu_dis_func_tab[65536] =
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
11,11,11,11,11,11,11,11,11,11,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -267,31 +266,31 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -299,31 +298,31 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -331,23 +330,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -355,7 +354,7 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -363,23 +362,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -387,7 +386,7 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -395,23 +394,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -419,7 +418,7 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -427,23 +426,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -451,7 +450,7 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -459,23 +458,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -483,7 +482,7 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -491,23 +490,23 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,0,0,0,0,0,0,0,0,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,39,
39,39,39,39,39,39,39,39,39,39,39,39,39,0,0,0,
@ -4100,4 +4099,3 @@ static UBY cpu_dis_func_tab[65536] =
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
#endif

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_EffectiveAddress.c,v 1.3 2012-07-15 22:20:35 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* CPU 68k effective address calculation functions */
@ -30,22 +29,22 @@
#include "CpuModule_Internal.h"
/* Calculates EA for (Ax). */
ULO cpuEA02(ULO regno)
uint32_t cpuEA02(uint32_t regno)
{
return cpuGetAReg(regno);
}
/* Calculates EA for (Ax)+ */
ULO cpuEA03(ULO regno, ULO size)
uint32_t cpuEA03(uint32_t regno, uint32_t size)
{
ULO tmp = cpuGetAReg(regno);
uint32_t tmp = cpuGetAReg(regno);
if (regno == 7 && size == 1) size++;
cpuSetAReg(regno, tmp + size);
return tmp;
}
/* Calculates EA for -(Ax) */
ULO cpuEA04(ULO regno, ULO size)
uint32_t cpuEA04(uint32_t regno, uint32_t size)
{
if (regno == 7 && size == 1) size++;
cpuSetAReg(regno, cpuGetAReg(regno) - size);
@ -53,20 +52,20 @@ ULO cpuEA04(ULO regno, ULO size)
}
/* Calculates EA for disp16(Ax) */
ULO cpuEA05(ULO regno)
uint32_t cpuEA05(uint32_t regno)
{
return cpuGetAReg(regno) + cpuGetNextWordSignExt();
}
/* Calculates EA for disp8(Ax,Ri.size) with 68020 extended modes. */
static ULO cpuEA06Ext(UWO ext, ULO base_reg_value, ULO index_value)
static uint32_t cpuEA06Ext(uint16_t ext, uint32_t base_reg_value, uint32_t index_value)
{
ULO base_displacement;
ULO outer_displacement;
uint32_t base_displacement;
uint32_t outer_displacement;
BOOLE index_register_suppressed = (ext & 0x0040);
BOOLE base_register_suppressed = (ext & 0x0080);
ULO base_displacement_size = (ext >> 4) & 3;
ULO memory_indirect_action = (ext & 7);
uint32_t base_displacement_size = (ext >> 4) & 3;
uint32_t memory_indirect_action = (ext & 7);
if (memory_indirect_action == 4
|| (memory_indirect_action > 4 && index_register_suppressed))
@ -126,14 +125,14 @@ static ULO cpuEA06Ext(UWO ext, ULO base_reg_value, ULO index_value)
}
/* Calculates EA for disp8(Ax,Ri.size), calls cpuEA06Ext() for 68020 extended modes. */
ULO cpuEA06(ULO regno)
uint32_t cpuEA06(uint32_t regno)
{
ULO reg_value = cpuGetAReg(regno);
UWO ext = cpuGetNextWord();
ULO index_value = cpuGetReg(ext >> 15, (ext >> 12) & 7);
uint32_t reg_value = cpuGetAReg(regno);
uint16_t ext = cpuGetNextWord();
uint32_t index_value = cpuGetReg(ext >> 15, (ext >> 12) & 7);
if (!(ext & 0x0800))
{
index_value = cpuSignExtWordToLong((UWO)index_value);
index_value = cpuSignExtWordToLong((uint16_t)index_value);
}
if (cpuGetModelMajor() >= 2)
{
@ -143,17 +142,17 @@ ULO cpuEA06(ULO regno)
return cpuEA06Ext(ext, reg_value, index_value);
}
}
return reg_value + index_value + cpuSignExtByteToLong((UBY)ext);
return reg_value + index_value + cpuSignExtByteToLong((uint8_t)ext);
}
/* Calculates EA for xxxx.W */
ULO cpuEA70(void)
uint32_t cpuEA70()
{
return cpuGetNextWordSignExt();
}
/* Calculates EA for xxxxxxxx.L */
ULO cpuEA71(void)
uint32_t cpuEA71()
{
return cpuGetNextLong();
}
@ -162,9 +161,9 @@ ULO cpuEA71(void)
/// Calculates EA for disp16(PC)
/// </summary>
/// <returns>Address</returns>
ULO cpuEA72(void)
uint32_t cpuEA72()
{
ULO pc_tmp = cpuGetPC();
uint32_t pc_tmp = cpuGetPC();
return pc_tmp + cpuGetNextWordSignExt();
}
@ -172,14 +171,14 @@ ULO cpuEA72(void)
/// Calculates EA for disp8(PC,Ri.size). Calls cpuEA06Ext() to calculate extended 68020 modes.
/// </summary>
/// <returns>Address</returns>
ULO cpuEA73(void)
uint32_t cpuEA73()
{
ULO reg_value = cpuGetPC();
UWO ext = cpuGetNextWord();
ULO index_value = cpuGetReg(ext >> 15, (ext >> 12) & 0x7);
uint32_t reg_value = cpuGetPC();
uint16_t ext = cpuGetNextWord();
uint32_t index_value = cpuGetReg(ext >> 15, (ext >> 12) & 0x7);
if (!(ext & 0x0800))
{
index_value = cpuSignExtWordToLong((UWO)index_value);
index_value = cpuSignExtWordToLong((uint16_t)index_value);
}
if (cpuGetModelMajor() >= 2)
{
@ -189,5 +188,5 @@ ULO cpuEA73(void)
return cpuEA06Ext(ext, reg_value, index_value);
}
}
return reg_value + index_value + cpuSignExtByteToLong((UBY)ext);
return reg_value + index_value + cpuSignExtByteToLong((uint8_t)ext);
}

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_Exceptions.c,v 1.5 2012-08-12 16:51:02 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* CPU 68k exception handling functions */
@ -29,6 +28,22 @@
#include "CpuModule.h"
#include "CpuModule_Internal.h"
// MPW
static cpuLineExceptionFunc cpu_a_line_exception_func = NULL;
static cpuLineExceptionFunc cpu_f_line_exception_func = NULL;
void cpuSetALineExceptionFunc(cpuLineExceptionFunc func)
{
cpu_a_line_exception_func = func;
}
void cpuSetFLineExceptionFunc(cpuLineExceptionFunc func)
{
cpu_f_line_exception_func = func;
}
/* Function for exiting from mid-instruction exceptions */
static cpuMidInstructionExceptionFunc cpu_mid_instruction_exception_func;
@ -55,12 +70,12 @@ void cpuSetResetExceptionFunc(cpuResetExceptionFunc func)
cpu_reset_exception_func = func;
}
static STR *cpuGetExceptionName(ULO vector_offset)
static char *cpuGetExceptionName(uint32_t vector_offset)
{
char *name;
if (vector_offset == 0x8)
name = "Exception: 2 - Access fault";
name = "Exception: 2 - Bus error";
else if (vector_offset == 0xc)
name = "Exception: 3 - Address error";
else if (vector_offset == 0x10)
@ -106,9 +121,9 @@ void cpuExceptionFail(BOOLE executejmp)
}
}
void cpuThrowException(ULO vector_offset, ULO pc, BOOLE executejmp)
void cpuThrowException(uint32_t vector_offset, uint32_t pc, BOOLE executejmp)
{
ULO vector_address;
uint32_t vector_address;
BOOLE is_address_error_on_sub_020 = (cpuGetModelMajor() < 2 && vector_offset == 0xc);
BOOLE stack_is_even = !(cpuGetAReg(7) & 1);
BOOLE vbr_is_even = !(cpuGetVbr() & 1);
@ -133,7 +148,7 @@ void cpuThrowException(ULO vector_offset, ULO pc, BOOLE executejmp)
return;
}
cpuStackFrameGenerate((UWO) vector_offset, pc);
cpuStackFrameGenerate((uint16_t) vector_offset, pc);
// read a memory position
vector_address = memoryReadLong(cpuGetVbr() + vector_offset);
@ -152,7 +167,40 @@ void cpuThrowException(ULO vector_offset, ULO pc, BOOLE executejmp)
cpuSetStop(FALSE);
cpuInitializeFromNewPC(vector_address);
cpuSetInstructionTime(40);
uint32_t exceptionCycles = 0;
switch (vector_offset)
{
case 0x08: exceptionCycles = 50; break; // Bus
case 0x0c: exceptionCycles = 50; break; // Address
case 0x10: exceptionCycles = 34; break; // Illegal
case 0x14: exceptionCycles = 42; break; // Division by zero
case 0x18: exceptionCycles = 28; break; // Chk
case 0x1c: exceptionCycles = 34; break; // Trapcc/trapv
case 0x20: exceptionCycles = 34; break; // Privilege
case 0x24: exceptionCycles = 34; break; // Trace
case 0x28: exceptionCycles = 34; break; // Line A
case 0x2c: exceptionCycles = 34; break; // Line F
case 0x80:
case 0x84:
case 0x88:
case 0x8c:
case 0x90:
case 0x94:
case 0x98:
case 0x9c:
case 0xa0:
case 0xa4:
case 0xa8:
case 0xac:
case 0xb0:
case 0xb4:
case 0xb8:
case 0xbc: exceptionCycles = 34; break; // TRAP
default: exceptionCycles = 4; break; // Should not come here
}
cpuSetInstructionTime(exceptionCycles);
}
// If the exception happened mid-instruction...
@ -164,6 +212,7 @@ void cpuThrowException(ULO vector_offset, ULO pc, BOOLE executejmp)
void cpuThrowPrivilegeViolationException(void)
{
cpuSetInstructionAborted(true);
// The saved pc points to the instruction causing the violation
// (And the kickstart excpects pc in the stack frame to be the opcode PC.)
cpuThrowException(0x20, cpuGetOriginalPC(), FALSE);
@ -171,18 +220,48 @@ void cpuThrowPrivilegeViolationException(void)
void cpuThrowIllegalInstructionException(BOOLE executejmp)
{
cpuSetInstructionAborted(true);
// The saved pc points to the illegal instruction
cpuThrowException(0x10, cpuGetOriginalPC(), executejmp);
}
void cpuThrowIllegalInstructionExceptionFromBreakpoint(void)
{
cpuSetInstructionAborted(true);
// The saved pc points to the illegal instruction
cpuThrowException(0x10, cpuGetPC(), FALSE);
}
void cpuThrowALineException(void)
{
// MPW
if (cpu_a_line_exception_func)
{
uint16_t opcode = memoryReadWord(cpuGetPC() - 2);
cpu_a_line_exception_func(opcode);
cpuInitializeFromNewPC(cpuGetPC());
cpuSetInstructionTime(512);
return;
}
cpuSetInstructionAborted(true);
// The saved pc points to the a-line instruction
cpuThrowException(0x28, cpuGetOriginalPC(), FALSE);
}
void cpuThrowFLineException(void)
{
// MPW
if (cpu_f_line_exception_func)
{
uint16_t opcode = memoryReadWord(cpuGetPC() - 2);
cpu_f_line_exception_func(opcode);
cpuInitializeFromNewPC(cpuGetPC());
cpuSetInstructionTime(512);
return;
}
cpuSetInstructionAborted(true);
// The saved pc points to the f-line instruction
cpuThrowException(0x2c, cpuGetOriginalPC(), FALSE);
}
@ -193,13 +272,13 @@ void cpuThrowTrapVException(void)
cpuThrowException(0x1c, cpuGetPC(), FALSE);
}
void cpuThrowDivisionByZeroException()
void cpuThrowDivisionByZeroException(void)
{
// The saved pc points to the next instruction, which is now in pc
cpuThrowException(0x14, cpuGetPC(), FALSE);
}
void cpuThrowTrapException(ULO vector_no)
void cpuThrowTrapException(uint32_t vector_no)
{
// The saved pc points to the next instruction, which is now in pc
cpuThrowException(0x80 + vector_no*4, cpuGetPC(), FALSE);
@ -219,6 +298,7 @@ void cpuThrowTraceException(void)
void cpuThrowAddressErrorException(void)
{
cpuSetInstructionAborted(true);
cpuThrowException(0xc, cpuGetPC() - 2, TRUE);
}

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_Flags.c,v 1.3 2011-07-18 17:22:55 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* 68000 flag and condition code handling */
@ -27,23 +26,23 @@
/// Sets the Z flag for bit operations
void cpuSetZFlagBitOpsB(UBY res)
void cpuSetZFlagBitOpsB(uint8_t res)
{
ULO flags = cpu_sr & 0xfffb;
uint32_t flags = cpu_sr & 0xfffb;
if (res == 0) flags |= 4;
cpu_sr = flags;
}
/// Sets the Z flag for bit operations
void cpuSetZFlagBitOpsL(ULO res)
void cpuSetZFlagBitOpsL(uint32_t res)
{
ULO flags = cpu_sr & 0xfffb;
uint32_t flags = cpu_sr & 0xfffb;
if (res == 0) flags |= 4;
cpu_sr = flags;
}
// rm,dm,sm
ULO cpu_xnvc_flag_add_table[2][2][2] = { 0,0x11,0x11,0x13,0xa,8,8,0x19};
uint32_t cpu_xnvc_flag_add_table[2][2][2] = { 0,0x11,0x11,0x13,0xa,8,8,0x19};
/// <summary>
/// Calculate XNVC flags of an add operation.
@ -51,13 +50,13 @@ ULO cpu_xnvc_flag_add_table[2][2][2] = { 0,0x11,0x11,0x13,0xa,8,8,0x19};
/// <param name="rm">The MSB of the result.</param>
/// <param name="dm">The MSB of the destination source.</param>
/// <param name="sm">The MSB of the source.</param>
static ULO cpuMakeFlagXNVCAdd(BOOLE rm, BOOLE dm, BOOLE sm)
static uint32_t cpuMakeFlagXNVCAdd(BOOLE rm, BOOLE dm, BOOLE sm)
{
return cpu_xnvc_flag_add_table[rm][dm][sm];
}
// rm,dm,sm
ULO cpu_nvc_flag_add_table[2][2][2] = { 0,1,1,3,0xa,8,8,9};
uint32_t cpu_nvc_flag_add_table[2][2][2] = { 0,1,1,3,0xa,8,8,9};
/// <summary>
/// Calculate NVC flags of an add operation for instructions not setting X.
@ -65,13 +64,13 @@ ULO cpu_nvc_flag_add_table[2][2][2] = { 0,1,1,3,0xa,8,8,9};
/// <param name="rm">The MSB of the result.</param>
/// <param name="dm">The MSB of the destination source.</param>
/// <param name="sm">The MSB of the source.</param>
static ULO cpuMakeFlagNVCAdd(BOOLE rm, BOOLE dm, BOOLE sm)
static uint32_t cpuMakeFlagNVCAdd(BOOLE rm, BOOLE dm, BOOLE sm)
{
return cpu_nvc_flag_add_table[rm][dm][sm];
}
// rm,dm,sm
ULO cpu_xnvc_flag_sub_table[2][2][2] = { 0,0x11,2,0,0x19,0x1b,8,0x19};
uint32_t cpu_xnvc_flag_sub_table[2][2][2] = { 0,0x11,2,0,0x19,0x1b,8,0x19};
/// <summary>
/// Calculate XNVC flags of a sub operation.
@ -79,13 +78,13 @@ ULO cpu_xnvc_flag_sub_table[2][2][2] = { 0,0x11,2,0,0x19,0x1b,8,0x19};
/// <param name="rm">The MSB of the result.</param>
/// <param name="dm">The MSB of the destination source.</param>
/// <param name="sm">The MSB of the source.</param>
static ULO cpuMakeFlagXNVCSub(BOOLE rm, BOOLE dm, BOOLE sm)
static uint32_t cpuMakeFlagXNVCSub(BOOLE rm, BOOLE dm, BOOLE sm)
{
return cpu_xnvc_flag_sub_table[rm][dm][sm];
}
// rm,dm,sm
ULO cpu_nvc_flag_sub_table[2][2][2] = { 0,1,2,0,9,0xb,8,9};
uint32_t cpu_nvc_flag_sub_table[2][2][2] = { 0,1,2,0,9,0xb,8,9};
/// <summary>
/// Calculate NVC flags of a sub operation for instructions not setting X.
@ -93,7 +92,7 @@ ULO cpu_nvc_flag_sub_table[2][2][2] = { 0,1,2,0,9,0xb,8,9};
/// <param name="rm">The MSB of the result.</param>
/// <param name="dm">The MSB of the destination source.</param>
/// <param name="sm">The MSB of the source.</param>
static ULO cpuMakeFlagNVCSub(BOOLE rm, BOOLE dm, BOOLE sm)
static uint32_t cpuMakeFlagNVCSub(BOOLE rm, BOOLE dm, BOOLE sm)
{
return cpu_nvc_flag_sub_table[rm][dm][sm];
}
@ -125,14 +124,6 @@ void cpuSetFlagV(BOOLE f)
cpu_sr = (cpu_sr & 0xfffd) | ((f) ? 2 : 0);
}
/// <summary>
/// Clear the V flag.
/// </summary>
static void cpuClearFlagV(void)
{
cpu_sr = cpu_sr & 0xfffd;
}
/// <summary>
/// Get the V flag.
/// </summary>
@ -159,22 +150,6 @@ void cpuSetFlagZ(BOOLE f)
cpu_sr = (cpu_sr & 0xfffb) | ((f) ? 4 : 0);
}
/// <summary>
/// Clear the Z flag.
/// </summary>
static void cpuClearFlagZ(void)
{
cpu_sr = cpu_sr & 0xfffb;
}
/// <summary>
/// Get the Z flag.
/// </summary>
static BOOLE cpuGetFlagZ(void)
{
return cpu_sr & 0x4;
}
/// <summary>
/// Get the X flag.
/// </summary>
@ -199,13 +174,13 @@ void cpuClearFlagsVC(void)
cpu_sr = cpu_sr & 0xfffc;
}
UWO cpuGetZFlagB(UBY res) {return (UWO)((res) ? 0 : 4);}
UWO cpuGetZFlagW(UWO res) {return (UWO)((res) ? 0 : 4);}
UWO cpuGetZFlagL(ULO res) {return (UWO)((res) ? 0 : 4);}
uint16_t cpuGetZFlagB(uint8_t res) {return (uint16_t)((res) ? 0 : 4);}
uint16_t cpuGetZFlagW(uint16_t res) {return (uint16_t)((res) ? 0 : 4);}
uint16_t cpuGetZFlagL(uint32_t res) {return (uint16_t)((res) ? 0 : 4);}
UWO cpuGetNFlagB(UBY res) {return (UWO)((res & 0x80) >> 4);}
UWO cpuGetNFlagW(UWO res) {return (UWO)((res & 0x8000) >> 12);}
UWO cpuGetNFlagL(ULO res) {return (UWO)((res & 0x80000000) >> 28);}
uint16_t cpuGetNFlagB(uint8_t res) {return (uint16_t)((res & 0x80) >> 4);}
uint16_t cpuGetNFlagW(uint16_t res) {return (uint16_t)((res & 0x8000) >> 12);}
uint16_t cpuGetNFlagL(uint32_t res) {return (uint16_t)((res & 0x80000000) >> 28);}
/// <summary>
/// Set the flags NZVC.
@ -216,7 +191,7 @@ UWO cpuGetNFlagL(ULO res) {return (UWO)((res & 0x80000000) >> 28);}
/// <param name="c">The C flag.</param>
void cpuSetFlagsNZVC(BOOLE z, BOOLE n, BOOLE v, BOOLE c)
{
ULO flags = cpu_sr & 0xfff0;
uint32_t flags = cpu_sr & 0xfff0;
if (n) flags |= 8;
else if (z) flags |= 4;
if (v) flags |= 2;
@ -231,7 +206,7 @@ void cpuSetFlagsNZVC(BOOLE z, BOOLE n, BOOLE v, BOOLE c)
/// <param name="c">The C flag.</param>
void cpuSetFlagsVC(BOOLE v, BOOLE c)
{
ULO flags = cpu_sr & 0xfffc;
uint32_t flags = cpu_sr & 0xfffc;
if (v) flags |= 2;
if (c) flags |= 1;
cpu_sr = flags;
@ -246,7 +221,7 @@ void cpuSetFlagsVC(BOOLE v, BOOLE c)
/// <param name="sm">The MSB of the source.</param>
void cpuSetFlagsAdd(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
{
ULO flags = cpu_sr & 0xffe0;
uint32_t flags = cpu_sr & 0xffe0;
if (z) flags |= 4;
flags |= cpuMakeFlagXNVCAdd(rm, dm, sm);
cpu_sr = flags;
@ -261,7 +236,7 @@ void cpuSetFlagsAdd(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
/// <param name="sm">The MSB of the source.</param>
void cpuSetFlagsSub(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
{
ULO flags = cpu_sr & 0xffe0;
uint32_t flags = cpu_sr & 0xffe0;
if (z) flags |= 4;
flags |= cpuMakeFlagXNVCSub(rm, dm, sm);
cpu_sr = flags;
@ -276,7 +251,7 @@ void cpuSetFlagsSub(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
/// <param name="sm">The MSB of the source.</param>
void cpuSetFlagsAddX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
{
ULO flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
uint32_t flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
flags |= cpuMakeFlagXNVCAdd(rm, dm, sm);
cpu_sr = flags;
}
@ -290,7 +265,7 @@ void cpuSetFlagsAddX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
/// <param name="sm">The MSB of the source.</param>
void cpuSetFlagsSubX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
{
ULO flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
uint32_t flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
flags |= cpuMakeFlagXNVCSub(rm, dm, sm);
cpu_sr = flags;
}
@ -303,7 +278,7 @@ void cpuSetFlagsSubX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
/// <param name="dm">The MSB of the destination source.</param>
void cpuSetFlagsNeg(BOOLE z, BOOLE rm, BOOLE dm)
{
ULO flags = cpu_sr & 0xffe0;
uint32_t flags = cpu_sr & 0xffe0;
if (z) flags |= 4;
else
{
@ -325,7 +300,7 @@ void cpuSetFlagsNeg(BOOLE z, BOOLE rm, BOOLE dm)
/// <param name="dm">The MSB of the destination source.</param>
void cpuSetFlagsNegx(BOOLE z, BOOLE rm, BOOLE dm)
{
ULO flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
uint32_t flags = cpu_sr & ((z) ? 0xffe4 : 0xffe0); // Clear z if result is non-zero
if (dm || rm)
{
flags |= 0x11; // XC
@ -347,7 +322,7 @@ void cpuSetFlagsNegx(BOOLE z, BOOLE rm, BOOLE dm)
/// <param name="sm">The MSB of the source.</param>
void cpuSetFlagsCmp(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
{
ULO flags = cpu_sr & 0xfff0;
uint32_t flags = cpu_sr & 0xfff0;
if (z) flags |= 4;
flags |= cpuMakeFlagNVCSub(rm, dm, sm);
cpu_sr = flags;
@ -360,7 +335,7 @@ void cpuSetFlagsCmp(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm)
/// <param name="rm">The MSB of the result.</param>
void cpuSetFlagsShiftZero(BOOLE z, BOOLE rm)
{
ULO flags = cpu_sr & 0xfff0; // Always clearing the VC flag
uint32_t flags = cpu_sr & 0xfff0; // Always clearing the VC flag
if (rm) flags |= 8;
else if (z) flags |= 4;
cpu_sr = flags;
@ -375,7 +350,7 @@ void cpuSetFlagsShiftZero(BOOLE z, BOOLE rm)
/// <param name="c">The overflow of the result.</param>
void cpuSetFlagsShift(BOOLE z, BOOLE rm, BOOLE c, BOOLE v)
{
ULO flags = cpu_sr & 0xffe0;
uint32_t flags = cpu_sr & 0xffe0;
if (rm) flags |= 8;
else if (z) flags |= 4;
if (v) flags |= 2;
@ -391,7 +366,7 @@ void cpuSetFlagsShift(BOOLE z, BOOLE rm, BOOLE c, BOOLE v)
/// <param name="c">The carry of the result.</param>
void cpuSetFlagsRotate(BOOLE z, BOOLE rm, BOOLE c)
{
ULO flags = cpu_sr & 0xfff0; // Always clearing the V flag
uint32_t flags = cpu_sr & 0xfff0; // Always clearing the V flag
if (rm) flags |= 8;
else if (z) flags |= 4;
@ -406,7 +381,7 @@ void cpuSetFlagsRotate(BOOLE z, BOOLE rm, BOOLE c)
/// <param name="z">The Z flag.</param>
/// <param name="rm">The MSB of the result.</param>
/// <param name="c">The extend bit and carry of the result.</param>
void cpuSetFlagsRotateX(UWO z, UWO rm, UWO x)
void cpuSetFlagsRotateX(uint16_t z, uint16_t rm, uint16_t x)
{
cpu_sr = (cpu_sr & 0xffe0) | z | rm | x;
}
@ -414,9 +389,9 @@ void cpuSetFlagsRotateX(UWO z, UWO rm, UWO x)
/// <summary>
/// Set the flags (ZN00).
/// </summary>
void cpuSetFlagsNZ00NewB(UBY res)
void cpuSetFlagsNZ00NewB(uint8_t res)
{
ULO flag = cpu_sr & 0xfff0;
uint32_t flag = cpu_sr & 0xfff0;
if (res & 0x80) flag |= 0x8;
else if (res == 0) flag |= 0x4;
cpu_sr = flag;
@ -425,9 +400,9 @@ void cpuSetFlagsNZ00NewB(UBY res)
/// <summary>
/// Set the flags (ZN00).
/// </summary>
void cpuSetFlagsNZ00NewW(UWO res)
void cpuSetFlagsNZ00NewW(uint16_t res)
{
ULO flag = cpu_sr & 0xfff0;
uint32_t flag = cpu_sr & 0xfff0;
if (res & 0x8000) flag |= 0x8;
else if (res == 0) flag |= 0x4;
cpu_sr = flag;
@ -436,9 +411,9 @@ void cpuSetFlagsNZ00NewW(UWO res)
/// <summary>
/// Set the flags (ZN00).
/// </summary>
void cpuSetFlagsNZ00NewL(ULO res)
void cpuSetFlagsNZ00NewL(uint32_t res)
{
ULO flag = cpu_sr & 0xfff0;
uint32_t flag = cpu_sr & 0xfff0;
if (res & 0x80000000) flag |= 0x8;
else if (res == 0) flag |= 0x4;
cpu_sr = flag;
@ -447,9 +422,9 @@ void cpuSetFlagsNZ00NewL(ULO res)
/// <summary>
/// Set the flags (ZN00).
/// </summary>
void cpuSetFlagsNZ00New64(LLO res)
void cpuSetFlagsNZ00New64(int64_t res)
{
ULO flag = cpu_sr & 0xfff0;
uint32_t flag = cpu_sr & 0xfff0;
if (res < 0) flag |= 0x8;
else if (res == 0) flag |= 0x4;
cpu_sr = flag;
@ -459,7 +434,7 @@ void cpuSetFlagsNZ00New64(LLO res)
/// Set the 4 flags absolute.
/// </summary>
/// <param name="f">flags</param>
void cpuSetFlagsAbs(UWO f)
void cpuSetFlagsAbs(uint16_t f)
{
cpu_sr = (cpu_sr & 0xfff0) | f;
}
@ -530,29 +505,29 @@ BOOLE cpuCalculateConditionCode11(void)
BOOLE cpuCalculateConditionCode12(void)
{
ULO tmp = cpu_sr & 0xa;
uint32_t tmp = cpu_sr & 0xa;
return (tmp == 0xa) || (tmp == 0); // GE - (N && V) || (!N && !V)
}
BOOLE cpuCalculateConditionCode13(void)
{
ULO tmp = cpu_sr & 0xa;
uint32_t tmp = cpu_sr & 0xa;
return (tmp == 0x8) || (tmp == 0x2); // LT - (N && !V) || (!N && V)
}
BOOLE cpuCalculateConditionCode14(void)
{
ULO tmp = cpu_sr & 0xa;
uint32_t tmp = cpu_sr & 0xa;
return (!(cpu_sr & 0x4)) && ((tmp == 0xa) || (tmp == 0)); // GT - (N && V && !Z) || (!N && !V && !Z)
}
BOOLE cpuCalculateConditionCode15(void)
{
ULO tmp = cpu_sr & 0xa;
uint32_t tmp = cpu_sr & 0xa;
return (cpu_sr & 0x4) || (tmp == 0x8) || (tmp == 2);// LE - Z || (N && !V) || (!N && V)
}
BOOLE cpuCalculateConditionCode(ULO cc)
BOOLE cpuCalculateConditionCode(uint32_t cc)
{
switch (cc & 0xf)
{

File diff suppressed because it is too large Load Diff

View File

@ -1,115 +1,112 @@
#ifndef CpuModule_Internal_H
#define CpuModule_Internal_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma once
// This header file defines the internal interfaces of the CPU module.
extern void cpuMakeOpcodeTableForModel(void);
extern void cpuCreateMulTimeTables(void);
// StackFrameGen
extern void cpuStackFrameGenerate(UWO vector_no, ULO pc);
extern void cpuStackFrameGenerate(uint16_t vector_no, uint32_t pc);
extern void cpuStackFrameInit(void);
// Registers
extern ULO cpu_sr; // Not static because the flags calculation uses it extensively
extern uint32_t cpu_sr; // Not static because the flags calculation uses it extensively
extern BOOLE cpuGetFlagSupervisor(void);
extern BOOLE cpuGetFlagMaster(void);
extern void cpuSetUspDirect(ULO usp);
extern ULO cpuGetUspDirect(void);
extern ULO cpuGetUspAutoMap(void);
extern void cpuSetSspDirect(ULO ssp);
extern ULO cpuGetSspDirect(void);
extern ULO cpuGetSspAutoMap(void);
extern void cpuSetMspDirect(ULO msp);
extern ULO cpuGetMspDirect(void);
extern ULO cpuGetMspAutoMap(void);
extern void cpuSetMspAutoMap(ULO new_msp);
extern ULO cpuGetIspAutoMap(void);
extern void cpuSetIspAutoMap(ULO new_isp);
extern void cpuSetDReg(ULO i, ULO value);
extern ULO cpuGetDReg(ULO i);
extern void cpuSetAReg(ULO i, ULO value);
extern ULO cpuGetAReg(ULO i);
extern void cpuSetReg(ULO da, ULO i, ULO value);
extern ULO cpuGetReg(ULO da, ULO i);
extern void cpuSetPC(ULO address);
extern ULO cpuGetPC(void);
extern void cpuSetUspDirect(uint32_t usp);
extern uint32_t cpuGetUspDirect(void);
extern uint32_t cpuGetUspAutoMap(void);
extern void cpuSetSspDirect(uint32_t ssp);
extern uint32_t cpuGetSspDirect(void);
extern uint32_t cpuGetSspAutoMap(void);
extern void cpuSetMspDirect(uint32_t msp);
extern uint32_t cpuGetMspDirect(void);
extern uint32_t cpuGetMspAutoMap(void);
extern void cpuSetMspAutoMap(uint32_t new_msp);
extern uint32_t cpuGetIspAutoMap(void);
extern void cpuSetIspAutoMap(uint32_t new_isp);
extern void cpuSetDReg(uint32_t i, uint32_t value);
extern uint32_t cpuGetDReg(uint32_t i);
extern void cpuSetAReg(uint32_t i, uint32_t value);
extern uint32_t cpuGetAReg(uint32_t i);
extern void cpuSetReg(uint32_t da, uint32_t i, uint32_t value);
extern uint32_t cpuGetReg(uint32_t da, uint32_t i);
extern void cpuSetPC(uint32_t address);
extern uint32_t cpuGetPC(void);
extern void cpuSetStop(BOOLE stop);
extern BOOLE cpuGetStop(void);
extern void cpuSetVbr(ULO vbr);
extern ULO cpuGetVbr(void);
extern void cpuSetSfc(ULO sfc);
extern ULO cpuGetSfc(void);
extern void cpuSetDfc(ULO dfc);
extern ULO cpuGetDfc(void);
extern void cpuSetCacr(ULO cacr);
extern ULO cpuGetCacr(void);
extern void cpuSetCaar(ULO caar);
extern ULO cpuGetCaar(void);
extern void cpuSetSR(ULO sr);
extern ULO cpuGetSR(void);
extern void cpuSetInstructionTime(ULO cycles);
extern ULO cpuGetInstructionTime(void);
extern void cpuSetOriginalPC(ULO pc);
extern ULO cpuGetOriginalPC(void);
extern void cpuSetVbr(uint32_t vbr);
extern uint32_t cpuGetVbr(void);
extern void cpuSetSfc(uint32_t sfc);
extern uint32_t cpuGetSfc(void);
extern void cpuSetDfc(uint32_t dfc);
extern uint32_t cpuGetDfc(void);
extern void cpuSetCacr(uint32_t cacr);
extern uint32_t cpuGetCacr(void);
extern void cpuSetCaar(uint32_t caar);
extern uint32_t cpuGetCaar(void);
extern void cpuSetSR(uint32_t sr);
extern uint32_t cpuGetSR(void);
extern void cpuSetInstructionTime(uint32_t cycles);
extern uint32_t cpuGetInstructionTime(void);
extern void cpuSetOriginalPC(uint32_t pc);
extern uint32_t cpuGetOriginalPC(void);
extern void cpuSetInstructionAborted(bool aborted);
extern bool cpuGetInstructionAborted(void);
#ifdef CPU_INSTRUCTION_LOGGING
extern void cpuSetCurrentOpcode(UWO opcode);
extern UWO cpuGetCurrentOpcode(void);
extern void cpuSetCurrentOpcode(uint16_t opcode);
extern uint16_t cpuGetCurrentOpcode(void);
#endif
extern void cpuProfileWrite(void);
extern void cpuSetModelMask(UBY model_mask);
extern UBY cpuGetModelMask(void);
extern void cpuSetDRegWord(ULO regno, UWO val);
extern void cpuSetDRegByte(ULO regno, UBY val);
extern UWO cpuGetRegWord(ULO i, ULO regno);
extern UWO cpuGetDRegWord(ULO regno);
extern UBY cpuGetDRegByte(ULO regno);
extern ULO cpuGetDRegWordSignExtLong(ULO regno);
extern UWO cpuGetDRegByteSignExtWord(ULO regno);
extern ULO cpuGetDRegByteSignExtLong(ULO regno);
extern UWO cpuGetARegWord(ULO regno);
extern UBY cpuGetARegByte(ULO regno);
extern void cpuSetModelMask(uint8_t model_mask);
extern uint8_t cpuGetModelMask(void);
extern void cpuSetDRegWord(uint32_t regno, uint16_t val);
extern void cpuSetDRegByte(uint32_t regno, uint8_t val);
extern uint16_t cpuGetRegWord(uint32_t i, uint32_t regno);
extern uint16_t cpuGetDRegWord(uint32_t regno);
extern uint8_t cpuGetDRegByte(uint32_t regno);
extern uint32_t cpuGetDRegWordSignExtLong(uint32_t regno);
extern uint16_t cpuGetDRegByteSignExtWord(uint32_t regno);
extern uint32_t cpuGetDRegByteSignExtLong(uint32_t regno);
extern uint16_t cpuGetARegWord(uint32_t regno);
extern uint8_t cpuGetARegByte(uint32_t regno);
extern UWO cpuGetNextWord(void);
extern ULO cpuGetNextWordSignExt(void);
extern ULO cpuGetNextLong(void);
extern uint16_t cpuGetNextWord(void);
extern uint32_t cpuGetNextWordSignExt(void);
extern uint32_t cpuGetNextLong(void);
extern void cpuSkipNextWord(void);
extern void cpuSkipNextLong(void);
extern void cpuClearPrefetch(void);
extern void cpuValidateReadPointer(void);
extern void cpuInitializeFromNewPC(ULO new_pc);
extern void cpuInitializeFromNewPC(uint32_t new_pc);
// Effective address
extern ULO cpuEA02(ULO regno);
extern ULO cpuEA03(ULO regno, ULO size);
extern ULO cpuEA04(ULO regno, ULO size);
extern ULO cpuEA05(ULO regno);
extern ULO cpuEA06(ULO regno);
extern ULO cpuEA70(void);
extern ULO cpuEA71(void);
extern ULO cpuEA72(void);
extern ULO cpuEA73(void);
extern uint32_t cpuEA02(uint32_t regno);
extern uint32_t cpuEA03(uint32_t regno, uint32_t size);
extern uint32_t cpuEA04(uint32_t regno, uint32_t size);
extern uint32_t cpuEA05(uint32_t regno);
extern uint32_t cpuEA06(uint32_t regno);
extern uint32_t cpuEA70(void);
extern uint32_t cpuEA71(void);
extern uint32_t cpuEA72(void);
extern uint32_t cpuEA73(void);
// Flags
extern void cpuSetFlagsAdd(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm);
extern void cpuSetFlagsSub(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm);
extern void cpuSetFlagsCmp(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm);
extern void cpuSetZFlagBitOpsB(UBY res);
extern void cpuSetZFlagBitOpsL(ULO res);
extern void cpuSetZFlagBitOpsB(uint8_t res);
extern void cpuSetZFlagBitOpsL(uint32_t res);
extern void cpuSetFlagsNZ00NewB(UBY res);
extern void cpuSetFlagsNZ00NewW(UWO res);
extern void cpuSetFlagsNZ00NewL(ULO res);
extern void cpuSetFlagsNZ00New64(LLO res);
extern void cpuSetFlagsNZ00NewB(uint8_t res);
extern void cpuSetFlagsNZ00NewW(uint16_t res);
extern void cpuSetFlagsNZ00NewL(uint32_t res);
extern void cpuSetFlagsNZ00New64(int64_t res);
extern void cpuSetFlagZ(BOOLE f);
extern void cpuSetFlagN(BOOLE f);
@ -126,16 +123,16 @@ extern void cpuSetFlagsVC(BOOLE v, BOOLE c);
extern void cpuSetFlagsShiftZero(BOOLE z, BOOLE rm);
extern void cpuSetFlagsShift(BOOLE z, BOOLE rm, BOOLE c, BOOLE v);
extern void cpuSetFlagsRotate(BOOLE z, BOOLE rm, BOOLE c);
extern void cpuSetFlagsRotateX(UWO z, UWO rm, UWO x);
extern void cpuSetFlagsRotateX(uint16_t z, uint16_t rm, uint16_t x);
extern void cpuSetFlagsAddX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm);
extern void cpuSetFlagsSubX(BOOLE z, BOOLE rm, BOOLE dm, BOOLE sm);
extern void cpuSetFlagsAbs(UWO f);
extern UWO cpuGetZFlagB(UBY res);
extern UWO cpuGetZFlagW(UWO res);
extern UWO cpuGetZFlagL(ULO res);
extern UWO cpuGetNFlagB(UBY res);
extern UWO cpuGetNFlagW(UWO res);
extern UWO cpuGetNFlagL(ULO res);
extern void cpuSetFlagsAbs(uint16_t f);
extern uint16_t cpuGetZFlagB(uint8_t res);
extern uint16_t cpuGetZFlagW(uint16_t res);
extern uint16_t cpuGetZFlagL(uint32_t res);
extern uint16_t cpuGetNFlagB(uint8_t res);
extern uint16_t cpuGetNFlagW(uint16_t res);
extern uint16_t cpuGetNFlagL(uint32_t res);
extern void cpuClearFlagsVC(void);
extern BOOLE cpuCalculateConditionCode0(void);
@ -154,53 +151,47 @@ extern BOOLE cpuCalculateConditionCode12(void);
extern BOOLE cpuCalculateConditionCode13(void);
extern BOOLE cpuCalculateConditionCode14(void);
extern BOOLE cpuCalculateConditionCode15(void);
extern BOOLE cpuCalculateConditionCode(ULO cc);
extern BOOLE cpuCalculateConditionCode(uint32_t cc);
// Logging
#ifdef CPU_INSTRUCTION_LOGGING
extern void cpuCallInstructionLoggingFunc(void);
extern void cpuCallExceptionLoggingFunc(STR *description, ULO original_pc, UWO opcode);
extern void cpuCallInterruptLoggingFunc(ULO level, ULO vector_address);
extern void cpuCallExceptionLoggingFunc(char *description, uint32_t original_pc, uint16_t opcode);
extern void cpuCallInterruptLoggingFunc(uint32_t level, uint32_t vector_address);
#endif
// Interrupt
extern ULO cpuActivateSSP(void);
extern uint32_t cpuActivateSSP(void);
extern void cpuSetRaiseInterrupt(BOOLE raise_irq);
extern BOOLE cpuGetRaiseInterrupt(void);
extern void cpuSetRaiseInterruptLevel(ULO raise_irq_level);
extern ULO cpuGetRaiseInterruptLevel(void);
extern void cpuSetRaiseInterruptLevel(uint32_t raise_irq_level);
extern uint32_t cpuGetRaiseInterruptLevel(void);
// Exceptions
extern void cpuThrowPrivilegeViolationException(void);
extern void cpuThrowIllegalInstructionException(BOOLE executejmp);
extern void cpuThrowIllegalInstructionExceptionFromBreakpoint(void);
extern void cpuThrowFLineException(void);
extern void cpuThrowALineException(void);
extern void cpuThrowTrapVException(void);
extern void cpuThrowTrapException(ULO vector_no);
extern void cpuThrowDivisionByZeroException();
extern void cpuThrowTrapException(uint32_t vector_no);
extern void cpuThrowDivisionByZeroException(void);
extern void cpuThrowChkException(void);
extern void cpuThrowTraceException(void);
extern void cpuThrowResetException(void);
extern void cpuCallResetExceptionFunc(void);
extern void cpuFrame1(UWO vector_offset, ULO pc);
extern void cpuFrame1(uint16_t vector_offset, uint32_t pc);
// Private help functions
static ULO cpuSignExtByteToLong(UBY v) {return (ULO)(LON)(BYT) v;}
static UWO cpuSignExtByteToWord(UBY v) {return (UWO)(WOR)(BYT) v;}
static ULO cpuSignExtWordToLong(UWO v) {return (ULO)(LON)(WOR) v;}
static ULO cpuJoinWordToLong(UWO upper, UWO lower) {return (((ULO)upper) << 16) | ((ULO)lower);}
static ULO cpuJoinByteToLong(UBY upper, UBY midh, UBY midl, UBY lower) {return (((ULO)upper) << 24) | (((ULO)midh) << 16) | (((ULO)midl) << 8) | ((ULO)lower);}
static UWO cpuJoinByteToWord(UBY upper, UBY lower) {return (((UWO)upper) << 8) | ((UWO)lower);}
static BOOLE cpuMsbB(UBY v) {return v>>7;}
static BOOLE cpuMsbW(UWO v) {return v>>15;}
static BOOLE cpuMsbL(ULO v) {return v>>31;}
static BOOLE cpuIsZeroB(UBY v) {return v == 0;}
static BOOLE cpuIsZeroW(UWO v) {return v == 0;}
static BOOLE cpuIsZeroL(ULO v) {return v == 0;}
#ifdef __cplusplus
}
#endif
#endif
static uint32_t cpuSignExtByteToLong(uint8_t v) {return (uint32_t)(int32_t)(int8_t) v;}
static uint16_t cpuSignExtByteToWord(uint8_t v) {return (uint16_t)(int16_t)(int8_t) v;}
static uint32_t cpuSignExtWordToLong(uint16_t v) {return (uint32_t)(int32_t)(int16_t) v;}
static uint32_t cpuJoinWordToLong(uint16_t upper, uint16_t lower) {return (((uint32_t)upper) << 16) | ((uint32_t)lower);}
static uint32_t cpuJoinByteToLong(uint8_t upper, uint8_t midh, uint8_t midl, uint8_t lower) {return (((uint32_t)upper) << 24) | (((uint32_t)midh) << 16) | (((uint32_t)midl) << 8) | ((uint32_t)lower);}
static uint16_t cpuJoinByteToWord(uint8_t upper, uint8_t lower) {return (((uint16_t)upper) << 8) | ((uint16_t)lower);}
static BOOLE cpuMsbB(uint8_t v) {return v>>7;}
static BOOLE cpuMsbW(uint16_t v) {return v>>15;}
static BOOLE cpuMsbL(uint32_t v) {return v>>31;}
static BOOLE cpuIsZeroB(uint8_t v) {return v == 0;}
static BOOLE cpuIsZeroW(uint16_t v) {return v == 0;}
static BOOLE cpuIsZeroL(uint32_t v) {return v == 0;}

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_InternalState.c,v 1.9 2012-08-12 16:51:02 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* 68000 internal state */
@ -27,57 +26,58 @@
#include "CpuModule_Internal.h"
/* M68k registers */
static ULO cpu_regs[2][8]; /* 0 - data, 1 - address */
static ULO cpu_pc;
static ULO cpu_usp;
static ULO cpu_ssp;
static ULO cpu_msp;
static ULO cpu_sfc;
static ULO cpu_dfc;
ULO cpu_sr; // Not static because flags calculation use it extensively
static ULO cpu_vbr;
static UWO cpu_prefetch_word;
static ULO cpu_cacr;
static ULO cpu_caar;
static uint32_t cpu_regs[2][8]; /* 0 - data, 1 - address */
static uint32_t cpu_pc;
static uint32_t cpu_usp;
static uint32_t cpu_ssp;
static uint32_t cpu_msp;
static uint32_t cpu_sfc;
static uint32_t cpu_dfc;
uint32_t cpu_sr; // Not static because flags calculation use it extensively
static uint32_t cpu_vbr;
static uint16_t cpu_prefetch_word;
static uint32_t cpu_cacr;
static uint32_t cpu_caar;
/* Irq management */
static BOOLE cpu_raise_irq;
static ULO cpu_raise_irq_level;
static uint32_t cpu_raise_irq_level;
/* Reset values */
static ULO cpu_initial_pc;
static ULO cpu_initial_sp;
static uint32_t cpu_initial_pc;
static uint32_t cpu_initial_sp;
/* Flag set if CPU is stopped */
static BOOLE cpu_stop;
/* The current CPU model */
static ULO cpu_model_major = -1;
static ULO cpu_model_minor;
static UBY cpu_model_mask;
static uint32_t cpu_model_major = -1;
static uint32_t cpu_model_minor;
static uint8_t cpu_model_mask;
/* For exception handling */
#ifdef CPU_INSTRUCTION_LOGGING
static UWO cpu_current_opcode;
static uint16_t cpu_current_opcode;
#endif
static ULO cpu_original_pc;
static uint32_t cpu_original_pc;
static bool cpu_instruction_aborted;
/* Number of cycles taken by the last intstruction */
static ULO cpu_instruction_time;
static uint32_t cpu_instruction_time;
/* Getters and setters */
void cpuSetDReg(ULO i, ULO value) {cpu_regs[0][i] = value;}
ULO cpuGetDReg(ULO i) {return cpu_regs[0][i];}
void cpuSetDReg(uint32_t i, uint32_t value) {cpu_regs[0][i] = value;}
uint32_t cpuGetDReg(uint32_t i) {return cpu_regs[0][i];}
void cpuSetAReg(ULO i, ULO value) {cpu_regs[1][i] = value;}
ULO cpuGetAReg(ULO i) {return cpu_regs[1][i];}
void cpuSetAReg(uint32_t i, uint32_t value) {cpu_regs[1][i] = value;}
uint32_t cpuGetAReg(uint32_t i) {return cpu_regs[1][i];}
void cpuSetReg(ULO da, ULO i, ULO value) {cpu_regs[da][i] = value;}
ULO cpuGetReg(ULO da, ULO i) {return cpu_regs[da][i];}
void cpuSetReg(uint32_t da, uint32_t i, uint32_t value) {cpu_regs[da][i] = value;}
uint32_t cpuGetReg(uint32_t da, uint32_t i) {return cpu_regs[da][i];}
/// <summary>
/// Get the supervisor bit from sr.
@ -95,21 +95,21 @@ BOOLE cpuGetFlagMaster(void)
return cpu_sr & 0x1000;
}
void cpuSetUspDirect(ULO usp) {cpu_usp = usp;}
ULO cpuGetUspDirect(void) {return cpu_usp;}
ULO cpuGetUspAutoMap(void) {return (cpuGetFlagSupervisor()) ? cpuGetUspDirect() : cpuGetAReg(7);}
void cpuSetUspDirect(uint32_t usp) {cpu_usp = usp;}
uint32_t cpuGetUspDirect() {return cpu_usp;}
uint32_t cpuGetUspAutoMap() {return (cpuGetFlagSupervisor()) ? cpuGetUspDirect() : cpuGetAReg(7);}
void cpuSetSspDirect(ULO ssp) {cpu_ssp = ssp;}
ULO cpuGetSspDirect(void) {return cpu_ssp;}
ULO cpuGetSspAutoMap(void) {return (cpuGetFlagSupervisor()) ? cpuGetAReg(7) : cpuGetSspDirect();}
void cpuSetSspDirect(uint32_t ssp) {cpu_ssp = ssp;}
uint32_t cpuGetSspDirect() {return cpu_ssp;}
uint32_t cpuGetSspAutoMap() {return (cpuGetFlagSupervisor()) ? cpuGetAReg(7) : cpuGetSspDirect();}
void cpuSetMspDirect(ULO msp) {cpu_msp = msp;}
ULO cpuGetMspDirect(void) {return cpu_msp;}
void cpuSetMspDirect(uint32_t msp) {cpu_msp = msp;}
uint32_t cpuGetMspDirect() {return cpu_msp;}
/// <summary>
/// Returns the master stack pointer.
/// </summary>
ULO cpuGetMspAutoMap(void)
uint32_t cpuGetMspAutoMap(void)
{
if (cpuGetFlagSupervisor() && cpuGetFlagMaster())
{
@ -121,7 +121,7 @@ ULO cpuGetMspAutoMap(void)
/// <summary>
/// Sets the master stack pointer.
/// </summary>
void cpuSetMspAutoMap(ULO new_msp)
void cpuSetMspAutoMap(uint32_t new_msp)
{
if (cpuGetFlagSupervisor() && cpuGetFlagMaster())
{
@ -136,7 +136,7 @@ void cpuSetMspAutoMap(ULO new_msp)
/// <summary>
/// Returns the interrupt stack pointer. ssp is used as isp.
/// </summary>
ULO cpuGetIspAutoMap(void)
uint32_t cpuGetIspAutoMap(void)
{
if (cpuGetFlagSupervisor() && !cpuGetFlagMaster())
{
@ -148,7 +148,7 @@ ULO cpuGetIspAutoMap(void)
/// <summary>
/// Sets the interrupt stack pointer. ssp is used as isp.
/// </summary>
void cpuSetIspAutoMap(ULO new_isp)
void cpuSetIspAutoMap(uint32_t new_isp)
{
if (cpuGetFlagSupervisor() && !cpuGetFlagMaster())
{
@ -160,61 +160,64 @@ void cpuSetIspAutoMap(ULO new_isp)
}
}
void cpuSetPC(ULO address) {cpu_pc = address;}
ULO cpuGetPC(void) {return cpu_pc;}
void cpuSetPC(uint32_t address) {cpu_pc = address;}
uint32_t cpuGetPC() {return cpu_pc;}
void cpuSetStop(BOOLE stop) {cpu_stop = stop;}
BOOLE cpuGetStop(void) {return cpu_stop;}
BOOLE cpuGetStop() {return cpu_stop;}
void cpuSetVbr(ULO vbr) {cpu_vbr = vbr;}
ULO cpuGetVbr(void) {return cpu_vbr;}
void cpuSetVbr(uint32_t vbr) {cpu_vbr = vbr;}
uint32_t cpuGetVbr() {return cpu_vbr;}
void cpuSetSfc(ULO sfc) {cpu_sfc = sfc;}
ULO cpuGetSfc(void) {return cpu_sfc;}
void cpuSetSfc(uint32_t sfc) {cpu_sfc = sfc;}
uint32_t cpuGetSfc() {return cpu_sfc;}
void cpuSetDfc(ULO dfc) {cpu_dfc = dfc;}
ULO cpuGetDfc(void) {return cpu_dfc;}
void cpuSetDfc(uint32_t dfc) {cpu_dfc = dfc;}
uint32_t cpuGetDfc() {return cpu_dfc;}
void cpuSetCacr(ULO cacr) {cpu_cacr = cacr;}
ULO cpuGetCacr(void) {return cpu_cacr;}
void cpuSetCacr(uint32_t cacr) {cpu_cacr = cacr;}
uint32_t cpuGetCacr() {return cpu_cacr;}
void cpuSetCaar(ULO caar) {cpu_caar = caar;}
ULO cpuGetCaar(void) {return cpu_caar;}
void cpuSetCaar(uint32_t caar) {cpu_caar = caar;}
uint32_t cpuGetCaar() {return cpu_caar;}
void cpuSetSR(ULO sr) {cpu_sr = sr;}
ULO cpuGetSR(void) {return cpu_sr;}
void cpuSetSR(uint32_t sr) {cpu_sr = sr;}
uint32_t cpuGetSR() {return cpu_sr;}
void cpuSetInstructionTime(ULO cycles) {cpu_instruction_time = cycles;}
ULO cpuGetInstructionTime(void) {return cpu_instruction_time;}
void cpuSetInstructionTime(uint32_t cycles) {cpu_instruction_time = cycles;}
uint32_t cpuGetInstructionTime() {return cpu_instruction_time;}
void cpuSetOriginalPC(ULO pc) {cpu_original_pc = pc;}
ULO cpuGetOriginalPC(void) {return cpu_original_pc;}
void cpuSetOriginalPC(uint32_t pc) {cpu_original_pc = pc;}
uint32_t cpuGetOriginalPC() {return cpu_original_pc;}
void cpuSetInstructionAborted(bool aborted) {cpu_instruction_aborted = aborted;}
bool cpuGetInstructionAborted() {return cpu_instruction_aborted;}
#ifdef CPU_INSTRUCTION_LOGGING
void cpuSetCurrentOpcode(UWO opcode) {cpu_current_opcode = opcode;}
UWO cpuGetCurrentOpcode(void) {return cpu_current_opcode;}
void cpuSetCurrentOpcode(uint16_t opcode) {cpu_current_opcode = opcode;}
uint16_t cpuGetCurrentOpcode() {return cpu_current_opcode;}
#endif
void cpuSetRaiseInterrupt(BOOLE raise_irq) {cpu_raise_irq = raise_irq;}
BOOLE cpuGetRaiseInterrupt(void) {return cpu_raise_irq;}
void cpuSetRaiseInterruptLevel(ULO raise_irq_level) {cpu_raise_irq_level = raise_irq_level;}
ULO cpuGetRaiseInterruptLevel(void) {return cpu_raise_irq_level;}
BOOLE cpuGetRaiseInterrupt() {return cpu_raise_irq;}
void cpuSetRaiseInterruptLevel(uint32_t raise_irq_level) {cpu_raise_irq_level = raise_irq_level;}
uint32_t cpuGetRaiseInterruptLevel() {return cpu_raise_irq_level;}
ULO cpuGetIrqLevel(void) {return (cpu_sr & 0x0700) >> 8;}
uint32_t cpuGetIrqLevel() {return (cpu_sr & 0x0700) >> 8;}
void cpuSetInitialPC(ULO pc) {cpu_initial_pc = pc;}
ULO cpuGetInitialPC(void) {return cpu_initial_pc;}
void cpuSetInitialPC(uint32_t pc) {cpu_initial_pc = pc;}
uint32_t cpuGetInitialPC() {return cpu_initial_pc;}
void cpuSetInitialSP(ULO sp) {cpu_initial_sp = sp;}
ULO cpuGetInitialSP(void) {return cpu_initial_sp;}
void cpuSetInitialSP(uint32_t sp) {cpu_initial_sp = sp;}
uint32_t cpuGetInitialSP() {return cpu_initial_sp;}
void cpuSetModelMask(UBY model_mask) {cpu_model_mask = model_mask;}
UBY cpuGetModelMask(void) {return cpu_model_mask;}
void cpuSetModelMask(uint8_t model_mask) {cpu_model_mask = model_mask;}
uint8_t cpuGetModelMask() {return cpu_model_mask;}
ULO cpuGetModelMajor(void) {return cpu_model_major;}
ULO cpuGetModelMinor(void) {return cpu_model_minor;}
uint32_t cpuGetModelMajor() {return cpu_model_major;}
uint32_t cpuGetModelMinor() {return cpu_model_minor;}
static void cpuCalculateModelMask(void)
{
@ -235,7 +238,7 @@ static void cpuCalculateModelMask(void)
}
}
void cpuSetModel(ULO major, ULO minor)
void cpuSetModel(uint32_t major, uint32_t minor)
{
BOOLE makeOpcodeTable = (cpu_model_major != major);
cpu_model_major = major;
@ -245,57 +248,59 @@ void cpuSetModel(ULO major, ULO minor)
if (makeOpcodeTable) cpuMakeOpcodeTableForModel();
}
#if defined(__BIG_ENDIAN__)
void cpuSetDRegWord(ULO regno, UWO val) {*((WOR*)&cpu_regs[0][regno]+1) = val;}
void cpuSetDRegByte(ULO regno, UBY val) {*((UBY*)&cpu_regs[0][regno]+3) = val;}
#if 0
void cpuSetDRegWord(uint32_t regno, uint16_t val) {*((int16_t*)&cpu_regs[0][regno]) = val;}
void cpuSetDRegByte(uint32_t regno, uint8_t val) {*((uint8_t*)&cpu_regs[0][regno]) = val;}
#else
void cpuSetDRegWord(ULO regno, UWO val) {*((WOR*)&cpu_regs[0][regno]) = val;}
void cpuSetDRegByte(ULO regno, UBY val) {*((UBY*)&cpu_regs[0][regno]) = val;}
// MPW -- above assumes little endian.
void cpuSetDRegWord(uint32_t regno, uint16_t val) {cpu_regs[0][regno] &= 0xffff0000; cpu_regs[0][regno] |= val;}
void cpuSetDRegByte(uint32_t regno, uint8_t val) {cpu_regs[0][regno] &= 0xffffff00; cpu_regs[0][regno] |= val;}
#endif
UWO cpuGetRegWord(ULO i, ULO regno) {return (UWO)cpu_regs[i][regno];}
UWO cpuGetDRegWord(ULO regno) {return (UWO)cpu_regs[0][regno];}
UBY cpuGetDRegByte(ULO regno) {return (UBY)cpu_regs[0][regno];}
uint16_t cpuGetRegWord(uint32_t i, uint32_t regno) {return (uint16_t)cpu_regs[i][regno];}
uint16_t cpuGetDRegWord(uint32_t regno) {return (uint16_t)cpu_regs[0][regno];}
uint8_t cpuGetDRegByte(uint32_t regno) {return (uint8_t)cpu_regs[0][regno];}
UWO cpuGetARegWord(ULO regno) {return (UWO)cpu_regs[1][regno];}
UBY cpuGetARegByte(ULO regno) {return (UBY)cpu_regs[1][regno];}
ULO cpuGetDRegWordSignExtLong(ULO regno) {return cpuSignExtWordToLong(cpuGetDRegWord(regno));}
UWO cpuGetDRegByteSignExtWord(ULO regno) {return cpuSignExtByteToWord(cpuGetDRegByte(regno));}
ULO cpuGetDRegByteSignExtLong(ULO regno) {return cpuSignExtByteToLong(cpuGetDRegByte(regno));}
uint32_t cpuGetDRegWordSignExtLong(uint32_t regno) {return cpuSignExtWordToLong(cpuGetDRegWord(regno));}
uint16_t cpuGetDRegByteSignExtWord(uint32_t regno) {return cpuSignExtByteToWord(cpuGetDRegByte(regno));}
uint32_t cpuGetDRegByteSignExtLong(uint32_t regno) {return cpuSignExtByteToLong(cpuGetDRegByte(regno));}
typedef UWO (*cpuGetWordFunc)(void);
typedef ULO (*cpuGetLongFunc)(void);
uint16_t cpuGetARegWord(uint32_t regno) {return (uint16_t)cpu_regs[1][regno];}
uint8_t cpuGetARegByte(uint32_t regno) {return (uint8_t)cpu_regs[1][regno];}
static UWO cpuGetNextWordInternal(void)
typedef uint16_t (*cpuGetWordFunc)(void);
typedef uint32_t (*cpuGetLongFunc)(void);
static uint16_t cpuGetNextWordInternal(void)
{
UWO data = memoryReadWord(cpuGetPC() + 2);
uint16_t data = memoryReadWord(cpuGetPC() + 2);
return data;
}
static ULO cpuGetNextLongInternal(void)
static uint32_t cpuGetNextLongInternal(void)
{
ULO data = memoryReadLong(cpuGetPC() + 2);
uint32_t data = memoryReadLong(cpuGetPC() + 2);
return data;
}
UWO cpuGetNextWord(void)
uint16_t cpuGetNextWord(void)
{
UWO tmp = cpu_prefetch_word;
uint16_t tmp = cpu_prefetch_word;
cpu_prefetch_word = cpuGetNextWordInternal();
cpuSetPC(cpuGetPC() + 2);
return tmp;
}
ULO cpuGetNextWordSignExt(void)
uint32_t cpuGetNextWordSignExt(void)
{
return cpuSignExtWordToLong(cpuGetNextWord());
}
ULO cpuGetNextLong(void)
uint32_t cpuGetNextLong(void)
{
ULO tmp = cpu_prefetch_word << 16;
ULO data = cpuGetNextLongInternal();
cpu_prefetch_word = (UWO) data;
uint32_t tmp = cpu_prefetch_word << 16;
uint32_t data = cpuGetNextLongInternal();
cpu_prefetch_word = (uint16_t) data;
cpuSetPC(cpuGetPC() + 4);
return tmp | (data >> 16);
}
@ -322,7 +327,7 @@ void cpuSkipNextLong(void)
cpuInitializePrefetch();
}
void cpuInitializeFromNewPC(ULO new_pc)
void cpuInitializeFromNewPC(uint32_t new_pc)
{
cpuSetPC(new_pc);
cpuInitializePrefetch();
@ -330,13 +335,11 @@ void cpuInitializeFromNewPC(ULO new_pc)
void cpuSaveState(FILE *F)
{
ULO i, j;
fwrite(&cpu_model_major, sizeof(cpu_model_major), 1, F);
fwrite(&cpu_model_minor, sizeof(cpu_model_minor), 1, F);
for (i = 0; i < 2; i++)
for (uint32_t i = 0; i < 2; i++)
{
for (j = 0; j < 7; j++)
for (uint32_t j = 0; j < 7; j++)
{
fwrite(&cpu_regs[i][j], sizeof(cpu_regs[i][j]), 1, F);
}
@ -358,13 +361,11 @@ void cpuSaveState(FILE *F)
void cpuLoadState(FILE *F)
{
ULO i, j;
fread(&cpu_model_major, sizeof(cpu_model_major), 1, F);
fread(&cpu_model_minor, sizeof(cpu_model_minor), 1, F);
for (i = 0; i < 2; i++)
for (uint32_t i = 0; i < 2; i++)
{
for (j = 0; j < 7; j++)
for (uint32_t j = 0; j < 7; j++)
{
fread(&cpu_regs[i][j], sizeof(cpu_regs[i][j]), 1, F);
}

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_Interrupts.c,v 1.5 2012-08-12 16:51:02 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* 68000 interrupt handling */
@ -32,7 +31,7 @@ cpuCheckPendingInterruptsFunc cpu_check_pending_interrupts_func;
void cpuCheckPendingInterrupts(void)
{
if (cpuGetRaiseInterrupt()) return;
if (cpu_check_pending_interrupts_func) cpu_check_pending_interrupts_func();
cpu_check_pending_interrupts_func();
}
void cpuSetCheckPendingInterruptsFunc(cpuCheckPendingInterruptsFunc func)
@ -40,9 +39,9 @@ void cpuSetCheckPendingInterruptsFunc(cpuCheckPendingInterruptsFunc func)
cpu_check_pending_interrupts_func = func;
}
ULO cpuActivateSSP(void)
uint32_t cpuActivateSSP(void)
{
ULO currentSP = cpuGetAReg(7);
uint32_t currentSP = cpuGetAReg(7);
// check supervisor bit number (bit 13) within the system byte of the status register
if (!cpuGetFlagSupervisor())
@ -66,7 +65,7 @@ ULO cpuActivateSSP(void)
// Retrns TRUE if the CPU is in the stopped state,
// this allows our scheduling queue to start
// scheduling CPU events again.
BOOLE cpuSetIrqLevel(ULO new_interrupt_level)
BOOLE cpuSetIrqLevel(uint32_t new_interrupt_level)
{
cpuSetRaiseInterrupt(TRUE);
cpuSetRaiseInterruptLevel(new_interrupt_level);
@ -83,10 +82,10 @@ BOOLE cpuSetIrqLevel(ULO new_interrupt_level)
Transfers control to an interrupt routine
============================================================*/
void cpuSetUpInterrupt(ULO new_interrupt_level)
void cpuSetUpInterrupt(uint32_t new_interrupt_level)
{
UWO vector_offset = (UWO) (0x60 + new_interrupt_level*4);
ULO vector_address = memoryReadLong(cpuGetVbr() + vector_offset);
uint16_t vector_offset = (uint16_t) (0x60 + new_interrupt_level*4);
uint32_t vector_address = memoryReadLong(cpuGetVbr() + vector_offset);
cpuActivateSSP(); // Switch to using ssp or msp. Loads a7 and preserves usp if we came from user-mode.
@ -94,7 +93,7 @@ void cpuSetUpInterrupt(ULO new_interrupt_level)
cpuSetSR(cpuGetSR() & 0x38ff); // Clear interrupt level
cpuSetSR(cpuGetSR() | 0x2000); // Set supervisor mode
cpuSetSR(cpuGetSR() | (UWO)(new_interrupt_level << 8)); // Set interrupt level
cpuSetSR(cpuGetSR() | (uint16_t)(new_interrupt_level << 8)); // Set interrupt level
#ifdef CPU_INSTRUCTION_LOGGING
cpuCallInterruptLoggingFunc(new_interrupt_level, vector_address);
@ -104,7 +103,7 @@ void cpuSetUpInterrupt(ULO new_interrupt_level)
{
if (cpuGetFlagMaster())
{ // If the cpu was in master mode, preserve msp, and switch to using ssp (isp) in a7.
ULO oldA7 = cpuGetAReg(7);
uint32_t oldA7 = cpuGetAReg(7);
cpuSetMspDirect(oldA7);
cpuSetAReg(7, cpuGetSspDirect());
cpuFrame1(vector_offset, cpuGetPC()); // Make the throwaway frame on ssp/isp

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_Logging.c,v 1.3 2012-08-12 16:51:02 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* CPU 68k logging functions */
@ -49,7 +48,7 @@ void cpuSetExceptionLoggingFunc(cpuExceptionLoggingFunc func)
cpu_exception_logging_func = func;
}
void cpuCallExceptionLoggingFunc(STR *description, ULO original_pc, UWO opcode)
void cpuCallExceptionLoggingFunc(char *description, uint32_t original_pc, uint16_t opcode)
{
if (cpu_exception_logging_func != NULL)
cpu_exception_logging_func(description, original_pc, opcode);
@ -60,7 +59,7 @@ void cpuSetInterruptLoggingFunc(cpuInterruptLoggingFunc func)
cpu_interrupt_logging_func = func;
}
void cpuCallInterruptLoggingFunc(ULO level, ULO vector_address)
void cpuCallInterruptLoggingFunc(uint32_t level, uint32_t vector_address)
{
if (cpu_interrupt_logging_func != NULL)
cpu_interrupt_logging_func(level, vector_address);

View File

@ -1 +1 @@
#include "fmem.h"
#include "fmem.h"

View File

@ -1,7 +1,5 @@
#ifndef CPUMODULE_PROFILE_H
#define CPUMODULE_PROFILE_H
#pragma once
void cpuProfileWrite(void)
{
}
#endif

View File

@ -1,4 +1,3 @@
/* @(#) $Id: CpuModule_StackFrameGen.c,v 1.3 2011-07-18 17:22:55 peschau Exp $ */
/*=========================================================================*/
/* Fellow */
/* 68000 stack frame generation */
@ -27,10 +26,10 @@
#include "CpuModule_Internal.h"
/* Exception stack frame jmptables */
typedef void(*cpuStackFrameGenFunc)(UWO, ULO);
typedef void(*cpuStackFrameGenFunc)(uint16_t, uint32_t);
static cpuStackFrameGenFunc cpu_stack_frame_gen_func[64];
static void cpuSetStackFrameGenFunc(ULO vector_no, cpuStackFrameGenFunc func)
static void cpuSetStackFrameGenFunc(uint32_t vector_no, cpuStackFrameGenFunc func)
{
cpu_stack_frame_gen_func[vector_no] = func;
}
@ -41,7 +40,7 @@ static void cpuSetStackFrameGenFunc(ULO vector_no, cpuStackFrameGenFunc func)
000: All, except bus and address error
========================================================================*/
static void cpuFrameGroup1(UWO vector_offset, ULO pcPtr)
static void cpuFrameGroup1(uint16_t vector_offset, uint32_t pcPtr)
{
// save PC
cpuSetAReg(7, cpuGetAReg(7) - 4);
@ -49,7 +48,7 @@ static void cpuFrameGroup1(UWO vector_offset, ULO pcPtr)
// save SR
cpuSetAReg(7, cpuGetAReg(7) - 2);
memoryWriteWord((UWO)cpuGetSR(), cpuGetAReg(7));
memoryWriteWord((uint16_t)cpuGetSR(), cpuGetAReg(7));
}
/*========================================================================
@ -61,7 +60,7 @@ static void cpuFrameGroup1(UWO vector_offset, ULO pcPtr)
memory_fault_read is TRUE if the access was a read
========================================================================*/
static void cpuFrameGroup2(UWO vector_offset, ULO pcPtr)
static void cpuFrameGroup2(uint16_t vector_offset, uint32_t pcPtr)
{
// save PC
cpuSetAReg(7, cpuGetAReg(7) - 4);
@ -69,7 +68,7 @@ static void cpuFrameGroup2(UWO vector_offset, ULO pcPtr)
// save SR
cpuSetAReg(7, cpuGetAReg(7) - 2);
memoryWriteWord((UWO)cpuGetSR(), cpuGetAReg(7));
memoryWriteWord((uint16_t)cpuGetSR(), cpuGetAReg(7));
// fault address, skip ireg
cpuSetAReg(7, cpuGetAReg(7) - 6);
@ -79,7 +78,7 @@ static void cpuFrameGroup2(UWO vector_offset, ULO pcPtr)
memoryWriteLong(memory_fault_read << 4, cpuGetAReg(7));
}
static void cpuFrame4Words(UWO frame_code, UWO vector_offset, ULO pc)
static void cpuFrame4Words(uint16_t frame_code, uint16_t vector_offset, uint32_t pc)
{
// save vector_offset word
cpuSetAReg(7, cpuGetAReg(7) - 2);
@ -91,7 +90,7 @@ static void cpuFrame4Words(UWO frame_code, UWO vector_offset, ULO pc)
// save SR
cpuSetAReg(7, cpuGetAReg(7) - 2);
memoryWriteWord((UWO)cpuGetSR(), cpuGetAReg(7));
memoryWriteWord((uint16_t)cpuGetSR(), cpuGetAReg(7));
}
@ -111,7 +110,7 @@ static void cpuFrame4Words(UWO frame_code, UWO vector_offset, ULO pc)
030: Same as for 020
========================================================================*/
static void cpuFrame0(UWO vector_offset, ULO pc)
static void cpuFrame0(uint16_t vector_offset, uint32_t pc)
{
cpuFrame4Words(0x0000, vector_offset, pc);
}
@ -131,7 +130,7 @@ static void cpuFrame0(UWO vector_offset, ULO pc)
040: Same as for 020
========================================================================*/
void cpuFrame1(UWO vector_offset, ULO pc)
void cpuFrame1(uint16_t vector_offset, uint32_t pc)
{
cpuFrame4Words(0x1000, vector_offset, pc);
}
@ -147,7 +146,7 @@ void cpuFrame1(UWO vector_offset, ULO pc)
060: Same as for 040
========================================================================*/
static void cpuFrame2(UWO vector_offset, ULO pc)
static void cpuFrame2(uint16_t vector_offset, uint32_t pc)
{
// save inst address
cpuSetAReg(7, cpuGetAReg(7) - 4);
@ -162,7 +161,7 @@ static void cpuFrame2(UWO vector_offset, ULO pc)
========================================================================*/
static void cpuFrame8(UWO vector_offset, ULO pc)
static void cpuFrame8(uint16_t vector_offset, uint32_t pc)
{
cpuSetAReg(7, cpuGetAReg(7) - 50);
cpuFrame4Words(0x8000, vector_offset, pc);
@ -178,14 +177,14 @@ static void cpuFrame8(UWO vector_offset, ULO pc)
Fellow will always generate this frame for bus/address errors
========================================================================*/
static void cpuFrameA(UWO vector_offset, ULO pc)
static void cpuFrameA(uint16_t vector_offset, uint32_t pc)
{
// save vector_offset offset
cpuSetAReg(7, cpuGetAReg(7) - 24);
cpuFrame4Words(0xa000, vector_offset, pc);
}
void cpuStackFrameGenerate(UWO vector_offset, ULO pc)
void cpuStackFrameGenerate(uint16_t vector_offset, uint32_t pc)
{
cpu_stack_frame_gen_func[vector_offset>>2](vector_offset, pc);
}
@ -196,8 +195,7 @@ void cpuStackFrameGenerate(UWO vector_offset, ULO pc)
static void cpuStackFrameInitSetDefaultFunc(cpuStackFrameGenFunc default_func)
{
ULO i;
for (i = 0; i < 64; i++)
for (uint32_t i = 0; i < 64; i++)
cpuSetStackFrameGenFunc(i, default_func);
}

View File

@ -1,14 +1,10 @@
#ifndef DEFS_H
#define DEFS_H
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Maximum values for memory, don't change */
@ -17,27 +13,19 @@ extern "C" {
#define BOGOMEM 0x1c0000
#define KICKMEM 0x080000
/* Fellow types to ensure correct sizes */
typedef uint8_t UBY;
typedef uint16_t UWO;
typedef uint32_t ULO;
typedef uint64_t ULL;
typedef int8_t BYT;
typedef int16_t WOR;
typedef int32_t LON;
typedef int64_t LLO;
typedef int BOOLE;
#define FALSE 0
#define TRUE 1
typedef char STR;
/*
#ifndef X64
#define PTR_TO_INT(i) ((ULO)i)
#define PTR_TO_INT(i) ((uint32_t)i)
#define PTR_TO_INT_MASK_TYPE(i) ((uint32_t)i)
#endif
#ifdef X64
#define PTR_TO_INT(i) ((ULL)i)
#define PTR_TO_INT(i) ((uint64_t)i)
#define PTR_TO_INT_MASK_TYPE(i) ((uint64_t)i)
#endif
*/
@ -49,17 +37,17 @@ typedef char STR;
/* The decode routines have this type */
/*------------------------------------*/
typedef void (*decoderoutinetype)(ULO,ULO);
typedef void (*decoderoutinetype)(uint32_t, uint32_t);
extern UBY configromname[];
extern uint8_t configromname[];
typedef union {
ULO *lptr;
UWO *wptr;
UBY *bptr;
ULO lval;
UWO wval[2];
UBY bval[4];
uint32_t *lptr;
uint16_t *wptr;
uint8_t *bptr;
uint32_t lval;
uint16_t wval[2];
uint8_t bval[4];
} ptunion;
typedef void (*planar2chunkyroutine)(void);
@ -69,13 +57,3 @@ typedef void (*sound_before_emu_routine)(void);
typedef void (*sound_after_emu_routine)(void);
typedef void (*buseventfunc)(void);
#define FELLOWVERSION "WinFellow alpha v0.5.0 build 0 (CVS)"
#define FELLOWLONGVERSION "WinFellow Amiga Emulator alpha v0.5.0 - CVS"
#define FELLOWNUMERICVERSION "0.5.0.0"
#ifdef __cplusplus
}
#endif
#endif

1692
cpu/fmem.c

File diff suppressed because it is too large Load Diff

View File

@ -1,41 +1,50 @@
#ifndef FMEM_H
#define FMEM_H
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
// new functions
// MPW
extern void memorySetMemory(uint8_t *memory, uint32_t size);
extern void memorySetGlobalLog(uint32_t globalLog);
extern uint8_t *memoryPointer(uint32_t address);
/* Access for chipset emulation that already have validated addresses */
#define chipmemReadByte(address) (memory_chip[address])
#define chipmemReadWord(address) ((((uint16_t) memory_chip[address]) << 8) | ((uint16_t) memory_chip[address + 1]))
#define chipmemWriteWord(data, address) \
memory_chip[address] = (uint8_t) (data >> 8); \
memory_chip[address + 1] = (uint8_t) data
/* Memory access functions */
extern UBY memoryReadByte(ULO address);
extern UWO memoryReadWord(ULO address);
extern ULO memoryReadLong(ULO address);
extern uint64_t memoryReadLongLong(ULO address);
extern void memoryWriteByte(UBY data, ULO address);
extern void memoryWriteWord(UWO data, ULO address);
extern void memoryWriteLong(ULO data, ULO address);
extern void memoryWriteLongLong(uint64_t data, ULO address);
extern uint8_t memoryReadByte(uint32_t address);
extern uint16_t memoryReadWord(uint32_t address);
extern uint32_t memoryReadLong(uint32_t address);
extern uint64_t memoryReadLongLong(uint32_t address);
extern void memoryWriteByte(uint8_t data, uint32_t address);
extern void memoryWriteWord(uint16_t data, uint32_t address);
extern void memoryWriteLong(uint32_t data, uint32_t address);
extern void memoryWriteLongLong(uint64_t data, uint32_t address);
extern UWO memoryChipReadWord(ULO address);
extern void memoryChipWriteWord(UWO data, ULO address);
extern uint16_t memoryChipReadWord(uint32_t address);
extern void memoryChipWriteWord(uint16_t data, uint32_t address);
#define memoryReadByteFromPointer(address) (address[0])
#define memoryReadWordFromPointer(address) ((address[0] << 8) | address[1])
#define memoryReadLongFromPointer(address) ((address[0] << 24) | (address[1] << 16) | (address[2] << 8) | address[3])
extern void memoryWriteLongToPointer(uint32_t data, uint8_t *address);
/* IO Bank functions */
typedef UWO (*memoryIoReadFunc)(ULO address);
typedef void (*memoryIoWriteFunc)(UWO data, ULO address);
typedef uint16_t (*memoryIoReadFunc)(uint32_t address);
typedef void (*memoryIoWriteFunc)(uint16_t data, uint32_t address);
extern void memorySetIoReadStub(ULO index, memoryIoReadFunc ioreadfunction);
extern void memorySetIoWriteStub(ULO index, memoryIoWriteFunc iowritefunction);
extern void memorySetIoReadStub(uint32_t index, memoryIoReadFunc ioreadfunction);
extern void memorySetIoWriteStub(uint32_t index, memoryIoWriteFunc iowritefunction);
/* For the copper */
extern memoryIoWriteFunc memory_iobank_write[257];
@ -43,23 +52,24 @@ extern memoryIoWriteFunc memory_iobank_write[257];
/* Expansion card functions */
typedef void (*memoryEmemCardInitFunc)(void);
typedef void (*memoryEmemCardMapFunc)(ULO);
typedef void (*memoryEmemCardMapFunc)(uint32_t);
extern void memoryEmemClear(void);
extern void memoryEmemCardAdd(memoryEmemCardInitFunc cardinit,
memoryEmemCardMapFunc cardmap);
extern void memoryEmemSet(ULO index, ULO data);
extern void memoryEmemMirror(ULO emem_offset, UBY *src, ULO size);
extern void memoryEmemSet(uint32_t index, uint32_t data);
extern void memoryEmemMirror(uint32_t emem_offset, uint8_t *src, uint32_t size);
/* Device memory functions. fhfile is using these. */
extern void memoryDmemSetByte(UBY data);
extern void memoryDmemSetWord(UWO data);
extern void memoryDmemSetLong(ULO data);
extern void memoryDmemSetLongNoCounter(ULO data, ULO offset);
extern void memoryDmemSetString(STR *data);
extern void memoryDmemSetCounter(ULO val);
extern ULO memoryDmemGetCounter(void);
extern void memoryDmemSetByte(uint8_t data);
extern void memoryDmemSetWord(uint16_t data);
extern void memoryDmemSetLong(uint32_t data);
extern void memoryDmemSetLongNoCounter(uint32_t data, uint32_t offset);
extern void memoryDmemSetString(const char *data);
extern void memoryDmemSetCounter(uint32_t val);
extern uint32_t memoryDmemGetCounter(void);
extern uint32_t memoryDmemGetCounterWithoutOffset(void);
extern void memoryDmemClear(void);
/* Module management functions */
@ -76,12 +86,12 @@ extern void memoryShutdown(void);
/* Memory bank functions */
typedef UBY (*memoryReadByteFunc)(ULO address);
typedef UWO (*memoryReadWordFunc)(ULO address);
typedef ULO (*memoryReadLongFunc)(ULO address);
typedef void (*memoryWriteByteFunc)(UBY data, ULO address);
typedef void (*memoryWriteWordFunc)(UWO data, ULO address);
typedef void (*memoryWriteLongFunc)(ULO data, ULO address);
typedef uint8_t (*memoryReadByteFunc)(uint32_t address);
typedef uint16_t (*memoryReadWordFunc)(uint32_t address);
typedef uint32_t (*memoryReadLongFunc)(uint32_t address);
typedef void (*memoryWriteByteFunc)(uint8_t data, uint32_t address);
typedef void (*memoryWriteWordFunc)(uint16_t data, uint32_t address);
typedef void (*memoryWriteLongFunc)(uint32_t data, uint32_t address);
extern memoryReadByteFunc memory_bank_readbyte[65536];
extern memoryReadWordFunc memory_bank_readword[65536];
@ -90,8 +100,8 @@ extern memoryWriteByteFunc memory_bank_writebyte[65536];
extern memoryWriteWordFunc memory_bank_writeword[65536];
extern memoryWriteLongFunc memory_bank_writelong[65536];
extern UBY *memory_bank_pointer[65536];
extern UBY *memory_bank_datapointer[65536];
extern uint8_t *memory_bank_pointer[65536];
extern uint8_t *memory_bank_datapointer[65536];
extern void memoryBankSet(memoryReadByteFunc rb,
memoryReadWordFunc rw,
@ -99,39 +109,43 @@ extern void memoryBankSet(memoryReadByteFunc rb,
memoryWriteByteFunc wb,
memoryWriteWordFunc ww,
memoryWriteLongFunc wl,
UBY *basep,
ULO bank,
ULO basebank,
uint8_t *basep,
uint32_t bank,
uint32_t basebank,
BOOLE pointer_can_write);
extern UBY *memoryAddressToPtr(ULO address);
extern void memoryChipMap(BOOLE overlay);
extern uint8_t *memoryAddressToPtr(uint32_t address);
extern void memoryChipMap(bool overlay);
/* Memory configuration properties */
extern BOOLE memorySetChipSize(ULO chipsize);
extern ULO memoryGetChipSize(void);
extern BOOLE memorySetFastSize(ULO fastsize);
extern ULO memoryGetFastSize(void);
extern void memorySetFastAllocatedSize(ULO fastallocatedsize);
extern ULO memoryGetFastAllocatedSize(void);
extern BOOLE memorySetSlowSize(ULO bogosize);
extern ULO memoryGetSlowSize(void);
extern BOOLE memorySetUseAutoconfig(BOOLE useautoconfig);
extern BOOLE memoryGetUseAutoconfig(void);
extern BOOLE memorySetChipSize(uint32_t chipsize);
extern uint32_t memoryGetChipSize(void);
extern BOOLE memorySetFastSize(uint32_t fastsize);
extern uint32_t memoryGetFastSize(void);
extern void memorySetFastAllocatedSize(uint32_t fastallocatedsize);
extern uint32_t memoryGetFastAllocatedSize(void);
extern BOOLE memorySetSlowSize(uint32_t bogosize);
extern uint32_t memoryGetSlowSize(void);
extern bool memorySetUseAutoconfig(bool useautoconfig);
extern bool memoryGetUseAutoconfig(void);
extern BOOLE memorySetAddress32Bit(BOOLE address32bit);
extern BOOLE memoryGetAddress32Bit(void);
extern BOOLE memorySetKickImage(STR *kickimage);
extern STR *memoryGetKickImage(void);
extern void memorySetKey(STR *key);
extern STR *memoryGetKey(void);
extern BOOLE memorySetKickImage(char *kickimage);
extern BOOLE memorySetKickImageExtended(char *kickimageext);
extern char *memoryGetKickImage(void);
extern void memorySetKey(char *key);
extern char *memoryGetKey(void);
extern BOOLE memoryGetKickImageOK(void);
/* Derived from memory configuration */
extern ULO memoryGetKickImageBaseBank(void);
extern ULO memoryGetKickImageVersion(void);
extern ULO memoryInitialPC(void);
extern ULO memoryInitialSP(void);
extern uint32_t memoryGetKickImageBaseBank(void);
extern uint32_t memoryGetKickImageVersion(void);
extern uint32_t memoryInitialPC(void);
extern uint32_t memoryInitialSP(void);
/* Kickstart decryption */
extern int memoryKickLoadAF2(char *filename, FILE *F, uint8_t *memory_kick, const bool);
/* Kickstart load error handling */
@ -148,21 +162,19 @@ extern ULO memoryInitialSP(void);
/* Global variables */
extern UBY memory_chip[];
extern UBY *memory_fast;
extern UBY memory_slow[];
extern UBY memory_kick[];
extern ULO memory_chipsize;
extern UBY memory_emem[];
extern uint8_t memory_chip[];
extern uint8_t *memory_fast;
extern uint8_t memory_slow[];
extern uint8_t memory_kick[];
extern uint32_t memory_chipsize;
extern uint8_t memory_emem[];
extern ULO intenar,intena,intreq;
extern ULO potgor;
extern uint32_t potgor;
extern ULO memory_fault_address;
extern uint32_t memory_fault_address;
extern BOOLE memory_fault_read;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -8,14 +8,14 @@
/*============================================================================*/
BOOLE memory_fault_read = FALSE; /* TRUE - read / FALSE - write */
ULO memory_fault_address = 0;
uint32_t memory_fault_address = 0;
/*==============================================================================
Raises exception 3 when a word or long is accessing an odd address
and the CPU is < 020
==============================================================================*/
static void memoryOddRead(ULO address)
static void memoryOddRead(uint32_t address)
{
if (address & 1)
{
@ -28,7 +28,7 @@ static void memoryOddRead(ULO address)
}
}
static void memoryOddWrite(ULO address)
static void memoryOddWrite(uint32_t address)
{
if (address & 1)
{
@ -75,7 +75,7 @@ uint8_t *memoryPointer(uint32_t address)
// memory read of 0xffffffff not handled correctly
// since the unsigned compare overflows.
UBY memoryReadByte(ULO address)
uint8_t memoryReadByte(uint32_t address)
{
if (MemoryLoggingFunc)
@ -88,7 +88,7 @@ UBY memoryReadByte(ULO address)
return 0;
}
UWO memoryReadWord(ULO address)
uint16_t memoryReadWord(uint32_t address)
{
if (MemoryLoggingFunc)
@ -103,7 +103,7 @@ UWO memoryReadWord(ULO address)
return 0;
}
ULO memoryReadLong(ULO address)
uint32_t memoryReadLong(uint32_t address)
{
if (MemoryLoggingFunc)
@ -121,7 +121,7 @@ ULO memoryReadLong(ULO address)
}
uint64_t memoryReadLongLong(ULO address)
uint64_t memoryReadLongLong(uint32_t address)
{
uint64_t tmp;
@ -132,7 +132,7 @@ uint64_t memoryReadLongLong(ULO address)
return tmp;
}
void memoryWriteByte(UBY data, ULO address)
void memoryWriteByte(uint8_t data, uint32_t address)
{
if (MemoryLoggingFunc)
@ -144,7 +144,7 @@ void memoryWriteByte(UBY data, ULO address)
}
}
void memoryWriteWord(UWO data, ULO address)
void memoryWriteWord(uint16_t data, uint32_t address)
{
if (MemoryLoggingFunc)
@ -159,7 +159,7 @@ void memoryWriteWord(UWO data, ULO address)
}
}
void memoryWriteLong(ULO data, ULO address)
void memoryWriteLong(uint32_t data, uint32_t address)
{
if (MemoryLoggingFunc)
@ -178,7 +178,7 @@ void memoryWriteLong(ULO data, ULO address)
}
void memoryWriteLongLong(uint64_t data, ULO address)
void memoryWriteLongLong(uint64_t data, uint32_t address)
{
if (address & 0x01) memoryOddWrite(address);

1
libsane Submodule

@ -0,0 +1 @@
Subproject commit 8a47aacd7d8a19566701ae60dd03ff3c6e6b3634

View File

@ -1,10 +1,3 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -g")
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
set(MACOS_SRC traps.c sysequ.c errors.cpp)
add_library(MACOS_LIB ${MACOS_SRC})

View File

@ -107,7 +107,7 @@ enum macos_error {
envVersTooBig = -5502, /*Version bigger than call can handle*/
fontDecError = -64, /*error during font declaration*/
fontNotDeclared = -65, /*font not declared*/
fontSubErr = -66, /*font substitution occured*/
fontSubErr = -66, /*font substitution occurred*/
fontNotOutlineErr = -32615, /*bitmap font passed to routine that does outlines only*/
firstDskErr = -84, /*I/O System Errors*/
lastDskErr = -64, /*I/O System Errors*/
@ -196,7 +196,7 @@ enum macos_error {
rgnTooBigErr = -500,
updPixMemErr = -125, /*insufficient memory to update a pixmap*/
pictInfoVersionErr = -11000, /* wrong version of the PictInfo structure */
pictInfoIDErr = -11001, /* the internal consistancy check for the PictInfoID is wrong */
pictInfoIDErr = -11001, /* the internal consistency check for the PictInfoID is wrong */
pictInfoVerbErr = -11002, /* the passed verb was invalid */
cantLoadPickMethodErr = -11003, /* unable to load the custom pick proc */
colorsRequestedErr = -11004, /* the number of colors requested was illegal */
@ -249,7 +249,7 @@ enum macos_error {
smEmptySlot = -300, /*No card in slot*/
smCRCFail = -301, /*CRC check failed for declaration data*/
smFormatErr = -302, /*FHeader Format is not Apple's*/
smRevisionErr = -303, /*Wrong revison level*/
smRevisionErr = -303, /*Wrong revision level*/
smNoDir = -304, /*Directory offset is Nil */
smDisabledSlot = -305, /*This slot is disabled (-305 use to be smLWTstBad)*/
smNosInfoArray = -306, /*No sInfoArray. Memory Mgr error.*/
@ -258,14 +258,14 @@ enum macos_error {
smResrvErr = -307, /*Fatal reserved error. Resreved field <> 0.*/
smUnExBusErr = -308, /*Unexpected BusError*/
smBLFieldBad = -309, /*ByteLanes field was bad.*/
smFHBlockRdErr = -310, /*Error occured during _sGetFHeader.*/
smFHBlkDispErr = -311, /*Error occured during _sDisposePtr (Dispose of FHeader block).*/
smFHBlockRdErr = -310, /*Error occurred during _sGetFHeader.*/
smFHBlkDispErr = -311, /*Error occurred during _sDisposePtr (Dispose of FHeader block).*/
smDisposePErr = -312, /*_DisposePointer error*/
smNoBoardSRsrc = -313, /*No Board sResource.*/
smGetPRErr = -314, /*Error occured during _sGetPRAMRec (See SIMStatus).*/
smGetPRErr = -314, /*Error occurred during _sGetPRAMRec (See SIMStatus).*/
smNoBoardId = -315, /*No Board Id.*/
smInitStatVErr = -316, /*The InitStatusV field was negative after primary or secondary init.*/
smInitTblVErr = -317, /*An error occured while trying to initialize the Slot Resource Table.*/
smInitTblVErr = -317, /*An error occurred while trying to initialize the Slot Resource Table.*/
smNoJmpTbl = -318, /*SDM jump table could not be created.*/
smBadBoardId = -319, /*BoardId was wrong; re-init the PRAM record.*/
smBusErrTO = -320, /*BusError time out.*/
@ -285,20 +285,20 @@ but a special error is needed to patch secondary inits.*/
smCPUErr = -334, /*Code revision is wrong*/
smsPointerNil = -335, /*LPointer is nil From sOffsetData. If this error occurs; check sInfo rec for more information.*/
smNilsBlockErr = -336, /*Nil sBlock error (Dont allocate and try to use a nil sBlock)*/
smNilsBlockErr = -336, /*Nil sBlock error (Don't allocate and try to use a nil sBlock)*/
smSlotOOBErr = -337, /*Slot out of bounds error*/
smSelOOBErr = -338, /*Selector out of bounds error*/
smNewPErr = -339, /*_NewPtr error*/
smBlkMoveErr = -340, /*_BlockMove error*/
smCkStatusErr = -341, /*Status of slot = fail.*/
smGetDrvrNamErr = -342, /*Error occured during _sGetDrvrName.*/
smDisDrvrNamErr = -343, /*Error occured during _sDisDrvrName.*/
smGetDrvrNamErr = -342, /*Error occurred during _sGetDrvrName.*/
smDisDrvrNamErr = -343, /*Error occurred during _sDisDrvrName.*/
smNoMoresRsrcs = -344, /*No more sResources*/
smsGetDrvrErr = -345, /*Error occurred during _sGetDriver.*/
smBadsPtrErr = -346, /*Bad pointer was passed to sCalcsPointer*/
smByteLanesErr = -347, /*NumByteLanes was determined to be zero.*/
smOffsetErr = -348, /*Offset was too big (temporary error*/
smNoGoodOpens = -349, /*No opens were successfull in the loop.*/
smNoGoodOpens = -349, /*No opens were successful in the loop.*/
smSRTOvrFlErr = -350, /*SRT over flow.*/
smRecNotFnd = -351, /*Record not found in the SRT.*/
editionMgrInitErr = -450, /*edition manager not inited by this app*/
@ -333,7 +333,7 @@ but a special error is needed to patch secondary inits.*/
interruptsMaskedErr = -624, /*don't call with interrupts masked*/
cannotDeferErr = -625, /*unable to defer additional functions*/
ddpSktErr = -91, /*error in soket number*/
ddpSktErr = -91, /*error in socket number*/
ddpLenErr = -92, /*data length too big*/
noBridgeErr = -93, /*no network bridge for non-local send*/
lapProtErr = -94, /*error in attaching/detaching protocol*/
@ -453,7 +453,7 @@ but a special error is needed to patch secondary inits.*/
noDefaultUserErr = -922, /* user hasn't typed in owners name in Network Setup Control Pannel */
notLoggedInErr = -923, /* The default userRefNum does not yet exist */
noUserRefErr = -924, /* unable to create a new userRefNum */
networkErr = -925, /* An error has occured in the network, not too likely */
networkErr = -925, /* An error has occurred in the network, not too likely */
noInformErr = -926, /* PPCStart failed because destination did not have inform pending */
authFailErr = -927, /* unable to authenticate user at destination */
noUserRecErr = -928, /* Invalid user reference number */

View File

@ -60,7 +60,7 @@ enum {
SMGlobals = 0x0CC4, /* (long) pointer to Sound Manager Globals*/
TheGDevice = 0x0CC8, /*[GLOBAL VAR] (long) the current graphics device*/
CQDGlobals = 0x0CCC, /* (long) quickDraw global extensions*/
ADBBase = 0x0CF8, /*[GLOBAL VAR] (long) pointer to Front Desk Buss Variables*/
ADBBase = 0x0CF8, /*[GLOBAL VAR] (long) pointer to Front Desk Bus Variables*/
WarmStart = 0x0CFC, /*[GLOBAL VAR] (long) flag to indicate it is a warm start*/
TimeDBRA = 0x0D00, /*[GLOBAL VAR] (word) number of iterations of DBRA per millisecond*/
TimeSCCDB = 0x0D02, /*[GLOBAL VAR] (word) number of iter's of SCC access & DBRA.*/

View File

@ -1047,7 +1047,7 @@ enum {
};
enum {
_ALMDispatch = 0xAAA4 /* Apple Location Manger*/
_ALMDispatch = 0xAAA4 /* Apple Location Manager*/
};
enum {

View File

@ -1,5 +1,3 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(MPLITE_SRC mplite.c)
add_library(MPLITE_LIB ${MPLITE_SRC})

View File

@ -73,7 +73,7 @@
* include stdint.h. The hope is that one or the other can be
* used with no real difference.
*
* 5) In the current verison, if your platform can't represent
* 5) In the current version, if your platform can't represent
* int32_t, int16_t and int8_t, it just dumps out with a compiler
* error.
*

View File

@ -1,41 +1,17 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -g")
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
set(MPW_SRC mpw.cpp mpw_io.cpp mpw_close.cpp mpw_access.cpp mpw_ioctl.cpp mpw_errno.cpp
environment.cpp)
# add_custom_command(
# OUTPUT environ.cpp
# COMMAND ragel -p -G2 -o environ.cpp "${CMAKE_CURRENT_SOURCE_DIR}/environ.rl"
# MAIN_DEPENDENCY environ.rl
# )
add_custom_command(
OUTPUT environment.cpp
COMMAND ragel -p -G2 -o environment.cpp "${CMAKE_CURRENT_SOURCE_DIR}/environment.rl"
COMMAND "${RAGEL}" -p -G2 -o environment.cpp "${CMAKE_CURRENT_SOURCE_DIR}/environment.rl"
MAIN_DEPENDENCY environment.rl
)
# add_custom_command(
# OUTPUT epv.cpp
# COMMAND ragel -p -G2 -o epv.cpp "${CMAKE_CURRENT_SOURCE_DIR}/epv.rl"
# MAIN_DEPENDENCY epv.rl
# )
# add_custom_command(
# OUTPUT ep.cpp
# COMMAND ragel -p -G2 -o ep.cpp "${CMAKE_CURRENT_SOURCE_DIR}/ep.rl"
# MAIN_DEPENDENCY ep.rl
# )
set_source_files_properties(
environment.cpp # environ.cpp ep.cpp epv.cpp
PROPERTIES

View File

@ -46,7 +46,7 @@
#include <cpu/defs.h>
#include <cpu/fmem.h>
#include <cpu/cpuModule.h>
#include <cpu/CpuModule.h>
#include <toolbox/toolbox.h>
#include <toolbox/mm.h>

View File

@ -44,7 +44,7 @@
#include <cpu/defs.h>
#include <cpu/fmem.h>
#include <cpu/cpuModule.h>
#include <cpu/CpuModule.h>
#include <toolbox/toolbox.h>
#include <toolbox/os.h>
@ -155,6 +155,46 @@ namespace MPW
}
/*
MPW's open logic pseudo code:
if (flags & 0x1000) { // undocumented - use old tool calls
oserr = flags & O_RSRC ? PBOPENRF() : PBOPEN();
} else {
oserr = flags & O_RSRC ? PBHOPENRF() : PBHOPEN();
}
if (!oserr) {
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)) {
errno = EEXIST;
return;
}
return;
}
if (oserr == file not found) {
if (flags & O_CREAT) {
oserr = PBCreate();
if (!oserr) {
oserr = flag & O_RSRC ? PBOpenRF() : PBOpen();
}
}
PBGETFCBINFO();
if (file size) {
if (flags & O_TRUNC) {
oserr = PBSetEOF();
}
if (!permission check) {
errno = EPERM;
PBClose();
}
*/
uint32_t ftrap_open(uint32_t name, uint32_t parm)
{
uint32_t d0;
@ -162,7 +202,7 @@ namespace MPW
std::string sname;
MPWFile f;
int nativeFlags;
int nativeFlags = 0;
std::memset(&f, 0, sizeof(f));
f.flags = memoryReadWord(parm);
@ -194,15 +234,30 @@ namespace MPW
Log(" open(%s, %04x)\n", sname.c_str(), f.flags);
// TODO -- can you create a resource file like this?
if (f.flags & kO_RSRC)
sname.append(_PATH_RSRCFORKSPEC);
if (f.flags & kO_RSRC) {
if (f.flags & kO_CREAT)
// O_CREAT and O_EXCL apply to the file, not the fork.
int flags = O_RDONLY | (nativeFlags & (O_CREAT | O_EXCL));
int parent = ::open(sname.c_str(), flags, 0666);
fd = -1;
if (parent >= 0) {
sname.append(_PATH_RSRCFORKSPEC);
nativeFlags &= ~O_EXCL;
// APFS, etc - resource fork doesn't automatically exist so
// need O_CREAT.
if ((nativeFlags & O_ACCMODE) != O_RDONLY) nativeFlags |= O_CREAT;
fd = ::open(sname.c_str(), nativeFlags, 0666);
close(parent);
}
} else {
fd = ::open(sname.c_str(), nativeFlags, 0666);
else
fd = ::open(sname.c_str(), nativeFlags);
}
if (fd < 0)
{

View File

@ -36,7 +36,7 @@
#include <cpu/defs.h>
#include <cpu/fmem.h>
#include <cpu/cpuModule.h>
#include <cpu/CpuModule.h>
#include <macos/errors.h>

View File

@ -38,7 +38,7 @@
#include <cpu/defs.h>
#include <cpu/fmem.h>
#include <cpu/cpuModule.h>
#include <cpu/CpuModule.h>
#include <macos/errors.h>
@ -74,7 +74,7 @@ namespace MPW
int fd = f.cookie;
ssize_t size;
Log(" read(%04x, %08x, %08x)", fd, f.buffer, f.count);
Log(" read(%04x, %08x, %08x)\n", fd, f.buffer, f.count);
size = OS::Internal::FDEntry::read(fd, memoryPointer(f.buffer), f.count);
//Log(" -> %ld\n", size);

View File

@ -44,7 +44,7 @@
#include <cpu/defs.h>
#include <cpu/fmem.h>
#include <cpu/cpuModule.h>
#include <cpu/CpuModule.h>
#include <macos/errors.h>

View File

@ -46,7 +46,7 @@ clean :
# mpw Link $(LDFLAGS) -o $@ $^ $(LIBS)
test_sane: o/nan.o o/test_sane.o
$(MPW) $(MPWFLAGS) Link $(LDFLAGS) -o $@ $^ $(LIBS)
$(MPW) $(MPWFLAGS) Link $(LDFLAGS) -o $@ $^ $(LIBS) {CLibraries}CSANELib.o
% : o/%.o
$(MPW) $(MPWFLAGS) Link $(LDFLAGS) -o $@ $^ $(LIBS)

View File

@ -253,6 +253,104 @@ void test_fxc2dec(void)
dump_decimal(&d);
// s/b -4 0
df.style = 1;
df.digits = 6;
num2dec(&df, 0.0625, &d);
dump_decimal(&d);
// s/b -6 62500
df.style = 1;
df.digits = 6;
num2dec(&df, 1.125, &d);
dump_decimal(&d);
// s/b -6 1125000
df.style = 1;
df.digits = 6;
num2dec(&df, 1.0625, &d);
dump_decimal(&d);
// s/b -6 1062500
}
pascal void fp68k_3(void *, void *, unsigned short) = 0xA9EB;
void test_fx2l(void) {
long double x;
long int l;
int i;
static long double data[] = {
1.25,
1.5,
1.75,
2.25,
2.5,
2.75,
-1.25,
-1.5,
-1.75,
-2.25,
-2.5,
-2.75,
};
x = inf(); // 1.0 / 0.0;
fp68k_3(&x, &l, 0x2810);
printf("fx2l(inf) = %lx\n", l);
x = -inf(); // -1.0 / 0.0;
fp68k_3(&x, &l, 0x2810);
printf("fx2l(-inf) = %lx\n", l);
x = nan(1); // -1.0 / 0.0;
fp68k_3(&x, &l, 0x2810);
printf("fx2l(nan) = %lx\n", l);
x = 1e21;
fp68k_3(&x, &l, 0x2810);
printf("fx2l(1e21) = %lx\n", l);
x = -1e21;
fp68k_3(&x, &l, 0x2810);
printf("fx2l(-1e21) = %lx\n", l);
setround(UPWARD);
for (i = 0; i < 12; ++i) {
x = data[i];
fp68k_3(&x, &l, 0x2810);
printf("fx2l(%f) = %ld\n", x, l);
}
setround(DOWNWARD);
for (i = 0; i < 12; ++i) {
x = data[i];
fp68k_3(&x, &l, 0x2810);
printf("fx2l(%f) = %ld\n", x, l);
}
setround(TONEAREST);
for (i = 0; i < 12; ++i) {
x = data[i];
fp68k_3(&x, &l, 0x2810);
printf("fx2l(%f) = %ld\n", x, l);
}
setround(TOWARDZERO);
for (i = 0; i < 12; ++i) {
x = data[i];
fp68k_3(&x, &l, 0x2810);
printf("fx2l(%f) = %ld\n", x, l);
}
}
int main(int argc, char **argv)
@ -276,6 +374,7 @@ int main(int argc, char **argv)
test_nan();
test_fxc2dec();
test_fx2l();
return 0;
}

View File

@ -1,8 +1,10 @@
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall -Wno-deprecated-declarations -g")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Clang or AppleClang
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations")
endif()
add_definitions(-I ${CMAKE_SOURCE_DIR}/)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
set(TOOLBOX_SRC
toolbox.cpp
@ -20,7 +22,6 @@ set(TOOLBOX_SRC
os_volume.cpp
qd.cpp
sane.cpp
saneparser.cpp
packages.cpp
pathnames.cpp
process.cpp
@ -30,26 +31,22 @@ set(TOOLBOX_SRC
dispatch.cpp
fpinfo.cpp
debug.cpp
)
add_custom_command(
OUTPUT saneparser.cpp
COMMAND ragel -p -G2 -o saneparser.cpp "${CMAKE_CURRENT_SOURCE_DIR}/saneparser.rl"
MAIN_DEPENDENCY saneparser.rl
)
add_custom_command(
OUTPUT pathnames.cpp
COMMAND ragel -p -G2 -o pathnames.cpp "${CMAKE_CURRENT_SOURCE_DIR}/pathnames.rl"
COMMAND "${RAGEL}" -p -G2 -o pathnames.cpp "${CMAKE_CURRENT_SOURCE_DIR}/pathnames.rl"
MAIN_DEPENDENCY pathnames.rl
)
set_source_files_properties(
saneparser.cpp pathnames.cpp
pathnames.cpp
PROPERTIES
COMPILE_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-unused-variable"
)
add_library(TOOLBOX_LIB ${TOOLBOX_SRC})
add_library(TOOLBOX_LIB ${TOOLBOX_SRC})
target_link_libraries(TOOLBOX_LIB MACOS_LIB sane)

View File

@ -42,6 +42,7 @@
#include "mm.h"
#include "os.h"
#include "packages.h"
#include "process.h"
#include "qd.h"
#include "rm.h"
#include "sane.h"
@ -55,7 +56,7 @@
#include <macos/traps.h>
// yuck. TST.W d0
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
extern "C" void cpuSetFlagsNZ00NewW(uint16_t res);
namespace {
@ -329,6 +330,11 @@ namespace OS {
case 0x0020:
return MM::TempDisposeHandle();
case 0x0037:
return Process::GetCurrentProcess();
case 0x003a:
return Process::GetProcessInformation();
default:
fprintf(stderr, "OSDispatch: selector %04x not implemented\n",
@ -499,7 +505,7 @@ namespace ToolBox {
*/
Push<4>(returnPC == 0 ? cpuGetPC() : returnPC);
Log("$04x *%s - $%08x", trap, TrapName(trap), address);
Log("$04x *%s - $%08x\n", trap, TrapName(trap), address);
cpuInitializeFromNewPC(address);
return;
}
@ -829,6 +835,15 @@ namespace ToolBox {
d0 = OS::CmpString(trap);
break;
//_RelString [MARKS,CASE]
case 0xa050:
case 0xa250:
case 0xa450:
case 0xa650:
d0 = OS::RelString(trap);
break;
// NewPtr [Sys, Clear] (logicalSize: Size): Ptr;
case 0xa11e:
case 0xa31e:
@ -1095,6 +1110,10 @@ namespace ToolBox {
d0 = OS::OSDispatch(trap);
break;
case 0xa8b5:
d0 = Packages::ScriptUtil(trap);
break;
case 0xABFF:
d0 = Debug::DebugStr(trap);
break;

View File

@ -35,7 +35,7 @@ namespace OS {
char *cp;
cp = getcwd(buffer, sizeof(buffer));
if (cp < 0) return 0;
if (cp == 0) return 0;
std::string path(cp);

View File

@ -40,8 +40,8 @@
#include "toolbox.h"
#include "stackframe.h"
#include "RM.h"
#include "MM.h"
#include "rm.h"
#include "mm.h"
#include <macos/sysequ.h>

View File

@ -154,7 +154,7 @@ namespace MM
}
// 2. check if it's contained in a pointer
for (const auto kv : PtrMap)
for (const auto &kv : PtrMap)
{
if (address < kv.first) continue;
if (address >= kv.first + kv.second) continue;
@ -184,7 +184,7 @@ namespace MM
// 3. check if the address is within a handle.
{
for (const auto kv : HandleMap)
for (const auto &kv : HandleMap)
{
const HandleInfo &info = kv.second;
@ -1145,7 +1145,7 @@ namespace MM
Log("%04x RecoverHandle(%08x)\n", trap, p);
uint16_t error = MacOS::memBCErr;
for (const auto kv : HandleMap)
for (const auto &kv : HandleMap)
{
const HandleInfo &info = kv.second;
@ -1203,7 +1203,7 @@ namespace MM
const auto &info = iter->second;
// resouce not yet supported...
// resource not yet supported...
// would need extra field and support in RM:: when
// creating.
// see HSetRBit, HClrRBit

View File

@ -288,6 +288,11 @@ namespace OS
if (ext == "sym")
return true;
break;
case 'x':
// xcoff object file
if (ext == "x")
return true;
break;
}
return false;
@ -511,7 +516,7 @@ namespace OS
memoryWriteLong(count, parm + 40);
}
if (count == 0)
if (count == 0 && ioReqCount > 0)
{
d0 = MacOS::eofErr;
}
@ -795,8 +800,8 @@ namespace OS
*
*/
bool caseSens = trap & (1 << 9);
//bool diacSens = trap & (1 << 10); // ignore for now...
//bool diacSens = trap & (1 << 9); // ignore for now...
bool caseSens = trap & (1 << 10);
uint32_t aStr = cpuGetAReg(0);
uint32_t bStr = cpuGetAReg(1);
@ -833,6 +838,55 @@ namespace OS
}
uint16_t RelString(uint16_t trap)
{
/*
* on entry:
* A0 Pointer to first character of first string
* A1 Pointer to first character of second string
* D0 (high) length of first string
* D0 (low) length of second string
*
* on exit:
* D0 0 if strings equal, -1 if first < second, 1 if first > second
*
*/
//bool diacSens = trap & (1 << 9); // ignore for now...
bool caseSens = trap & (1 << 10);
uint32_t aStr = cpuGetAReg(0);
uint32_t bStr = cpuGetAReg(1);
uint32_t length = cpuGetDReg(0);
uint32_t aLen = (length >> 16);
uint32_t bLen = (length & 0xffff);
std::string a = ToolBox::ReadString(aStr, aLen);
std::string b = ToolBox::ReadString(bStr, bLen);
Log("%04x RelString(%s, %s)\n", trap, a.c_str(), b.c_str());
if (aStr == bStr) return 0; // same ptr...
for (uint32_t i = 0; i < std::min(aLen, bLen); ++i) {
unsigned aa = a[i];
unsigned bb = b[i];
if (!caseSens) {
aa = toupper(aa);
bb = toupper(bb);
}
if (aa == bb) continue;
return aa < bb ? -1 : 1;
}
if (aLen == bLen) return 0;
return aLen < bLen ? -1 : 1;
}
#pragma mark - Time Utilities
time_t UnixToMac(time_t t)

View File

@ -71,6 +71,7 @@ namespace OS
#pragma mark String Utilities
uint16_t CmpString(uint16_t trap);
uint16_t RelString(uint16_t trap);
#pragma mark - Time Utilities

View File

@ -43,6 +43,7 @@
#include <dirent.h>
#include <strings.h>
#include <sys/param.h>
#include <cpu/defs.h>
#include <cpu/CpuModule.h>
@ -301,11 +302,18 @@ namespace OS {
//uint16_t ioVRefNum = memoryReadWord(parm + _ioVRefNum);
//uint8_t ioFVersNum = memoryReadByte(parm + _ioFVersNum);
int16_t ioFDirIndex = memoryReadWord(parm + _ioFDirIndex);
uint32_t ioDirID = memoryReadLong(parm + _ioDirID);
if (ioFDirIndex <= 0)
if (ioFDirIndex == 0)
{
// based name
std::string sname;
/*
* If this field contains 0, PBGetCatInfo returns
* information about the file or directory whose name is
* specified in the ioNamePtr field and that is located in the
* directory specified by the ioVRefNum field. (Once again, if
* ioVRefNum contains a volume reference number, the specified
* directory is that volume's root directory.)
*/
if (!ioNamePtr)
{
@ -313,23 +321,59 @@ namespace OS {
return MacOS::bdNamErr;
}
sname = ToolBox::ReadPString(ioNamePtr, true);
{
uint32_t ioDirID = memoryReadLong(parm + _ioDirID);
sname = FSSpecManager::ExpandPath(sname, ioDirID);
}
std::string sname = ToolBox::ReadPString(ioNamePtr, true);
sname = FSSpecManager::ExpandPath(sname, ioDirID);
Log(" PBGetCatInfo(%s)\n", sname.c_str());
d0 = CatInfoByName(sname, parm);
memoryWriteWord(d0, parm + _ioResult);
return d0;
}
else if (ioFDirIndex < 0) {
/*
* If this field contains a negative number, PBGetCatInfo ignores the
* ioNamePtr field and returns information about the directory specified
* in the ioDirID field. If both ioDirID and ioVRefNum are set to 0,
* PBGetCatInfo returns information about the current default directory.
*/
Log(" PBGetCatInfo(%04x)\n", ioDirID);
std::string sname = FSSpecManager::PathForID(ioDirID);
if (sname.empty()) {
char buffer[MAXPATHLEN];
char *cp;
cp = getcwd(buffer, sizeof(buffer));
sname = cp ? cp : ".";
}
d0 = CatInfoByName(sname, parm);
if (ioNamePtr) {
std::string basename;
auto pos = sname.rfind('/');
if (pos == sname.npos) basename = std::move(sname);
else basename = sname.substr(pos+1);
ToolBox::WritePString(ioNamePtr, basename);
}
}
else
{
// dirent ish. ioFDirIndex is the 1-based entry.
uint32_t ioDirID = memoryReadLong(parm + _ioDirID);
/*
* If this field contains a positive number, PBGetCatInfo returns
* information about the file or directory having that directory index in
* the directory specified by the ioVRefNum field. (If ioVRefNum contains a
* volume reference number, the specified directory is that volume's root
* directory.)
*/
Log(" PBGetCatInfo(%04x, %04x)\n", ioDirID, ioFDirIndex);
@ -375,11 +419,11 @@ namespace OS {
d0 = CatInfoByName(sname, parm);
memoryWriteWord(d0, parm + _ioResult);
return d0;
}
memoryWriteWord(d0, parm + _ioResult);
return d0;
return 0;
}

View File

@ -83,8 +83,8 @@ namespace OS {
{
char buffer[PATH_MAX + 1];
// FSSpecs are valid for non-existant files
// but not non-existant directories.
// FSSpecs are valid for non-existent files
// but not non-existent directories.
// realpath does not behave in such a manner.
// expand the path. Also handles relative paths.
@ -106,8 +106,6 @@ namespace OS {
{
// FSMakeFSSpec(vRefNum: Integer; dirID: LongInt; fileName: Str255; VAR spec: FSSpec): OSErr;
// todo -- if the file does not exist (but the path is otherwise valid), create the spec but return fnfErr.
/*
* See Chapter 2, File Manager / Using the File Manager, 2-35
*
@ -176,7 +174,9 @@ namespace OS {
// write the filename...
ToolBox::WritePString(spec + 6, leaf);
return 0;
struct stat st;
int rv = ::stat(sname.c_str(), &st);
if (rv < 0) return macos_error_from_errno();
}
else
@ -394,17 +394,17 @@ namespace OS {
rv = ::stat(path.c_str(), &st);
if (rv < 0)
{
if (wasAliased) memoryWriteWord(0, wasAliased);
if (targetIsFolder) memoryWriteWord(0, targetIsFolder);
if (wasAliased) memoryWriteByte(0, wasAliased);
if (targetIsFolder) memoryWriteByte(0, targetIsFolder);
return macos_error_from_errno();
}
if (targetIsFolder)
memoryWriteWord(S_ISDIR(st.st_mode) ? 1 : 0, targetIsFolder);
memoryWriteByte(S_ISDIR(st.st_mode) ? 1 : 0, targetIsFolder);
// don't bother pretending a soft link is an alias.
if (wasAliased) memoryWriteWord(0, wasAliased);
if (wasAliased) memoryWriteByte(0, wasAliased);
return 0;
}

View File

@ -548,12 +548,21 @@ namespace OS { namespace Internal {
}
std::string xname = filename;
if (fork)
if (fork) {
xname.append(_PATH_RSRCFORKSPEC);
// O_RDWR should also O_CREAT
}
Log(" open(%s, %04x)\n", xname.c_str(), access);
fd = ::open(xname.c_str(), access);
if (fd < 0 && access == O_RDWR && errno == ENOENT && fork)
{
fd = ::open(xname.c_str(), O_RDWR | O_CREAT, 0666);
}
if (fd < 0 && ioPermission == fsCurPerm && errno == EACCES)
{
fd = ::open(xname.c_str(), O_RDONLY);

View File

@ -52,14 +52,308 @@ using OS::MacToUnix;
namespace Packages {
enum {
shortDate = 0,
longDate = 1,
abbrevDate = 2
};
enum {
mdy = 0,
dmy = 1,
ymd = 2,
myd = 3,
dym = 4,
ydm = 5
};
enum {
timeCycle24 = 0, /*time sequence 0:00 - 23:59*/
timeCycleZero = 1, /*time sequence 0:00-11:59, 0:00 - 11:59*/
timeCycle12 = 255, /*time sequence 12:00 - 11:59, 12:00 - 11:59*/
zeroCycle = 1, /*old name for timeCycleZero*/
longDay = 0, /*day of the month*/
longWeek = 1, /*day of the week*/
longMonth = 2, /*month of the year*/
longYear = 3, /*year*/
supDay = 1, /*suppress day of month*/
supWeek = 2, /*suppress day of week*/
supMonth = 4, /*suppress month*/
supYear = 8, /*suppress year*/
dayLdingZ = 32,
mntLdingZ = 64,
century = 128,
secLeadingZ = 32,
minLeadingZ = 64,
hrLeadingZ = 128
};
#if 0
struct Intl0Rec {
char decimalPt; /*decimal point character*/
char thousSep; /*thousands separator character*/
char listSep; /*list separator character*/
char currSym1; /*currency symbol*/
char currSym2;
char currSym3;
UInt8 currFmt; /*currency format flags*/
UInt8 dateOrder; /*order of short date elements: mdy, dmy, etc.*/
UInt8 shrtDateFmt; /*format flags for each short date element*/
char dateSep; /*date separator character*/
UInt8 timeCycle; /*specifies time cycle: 0..23, 1..12, or 0..11*/
UInt8 timeFmt; /*format flags for each time element*/
char mornStr[4]; /*trailing string for AM if 12-hour cycle*/
char eveStr[4]; /*trailing string for PM if 12-hour cycle*/
char timeSep; /*time separator character*/
char time1Suff; /*trailing string for AM if 24-hour cycle*/
char time2Suff;
char time3Suff;
char time4Suff;
char time5Suff; /*trailing string for PM if 24-hour cycle*/
char time6Suff;
char time7Suff;
char time8Suff;
UInt8 metricSys; /*255 if metric, 0 if inches etc.*/
short intl0Vers; /*region code (hi byte) and version (lo byte)*/
};
#endif
enum {
o_decimalPt = 0,
o_thousSep = 1,
o_listSep = 2,
o_currSym1 = 3,
o_currSym2 = 4,
o_currSym3 = 5,
o_currFmt = 6,
o_dateOrder = 7,
o_shrtDateFmt = 8,
o_dateSep = 9,
o_timeCycle = 10,
o_timeFmt = 11,
o_mornStr = 12,
o_eveStr = 16,
o_timeSep = 20,
o_time1Suff = 21,
o_time2Suff = 22,
o_time3Suff = 23,
o_time4Suff = 24,
o_time5Suff = 25,
o_time6Suff = 26,
o_time7Suff = 27,
o_time8Suff = 28,
o_metricSys = 29,
o_intl0Vers = 30, /* 16-bit */
};
struct DateFormat {
uint8_t dateOrder = mdy;
uint8_t dateSep = '/';
uint8_t shrtDateFmt = 0;
void unpack(uint32_t intlPtr) {
if (!intlPtr) return;
dateOrder = memoryReadByte(intlPtr + o_dateOrder);
shrtDateFmt = memoryReadByte(intlPtr + o_shrtDateFmt);
dateSep = memoryReadByte(intlPtr + o_dateSep);
}
};
struct TimeFormat {
uint8_t timeCycle = timeCycle12;
uint8_t timeSep = ':';
uint8_t timeFmt = secLeadingZ + minLeadingZ;
std::string mornStr = " AM";
std::string eveStr = " PM";
void unpack(uint32_t intlPtr) {
if (!intlPtr) return;
timeCycle = memoryReadByte(intlPtr + o_timeCycle);
timeFmt = memoryReadByte(intlPtr + o_timeFmt);
timeSep = memoryReadByte(intlPtr + o_timeSep);
if (timeCycle == timeCycle24) {
mornStr = read_string(intlPtr + o_time1Suff);
eveStr = read_string(intlPtr + o_time5Suff);
} else {
mornStr = read_string(intlPtr + o_mornStr);
eveStr = read_string(intlPtr + o_eveStr);
}
}
static std::string read_string(uint32_t address) {
std::string rv;
for (unsigned i = 0; i < 4; ++i, ++address) {
char c = memoryReadByte(address);
if (!c) break;
rv.push_back(c);
}
return rv;
}
};
namespace {
std::string FormatAbbrDate(uint32_t dateTime, uint32_t intlPtr) {
std::string rv;
char dd[8];
char mm[8];
char yy[8];
std::string sep;
DateFormat df;
time_t t = MacToUnix(dateTime);
struct tm *tm = ::localtime(&t);
if (intlPtr) df.unpack(intlPtr);
if (df.dateSep) sep.push_back(df.dateSep);
if (df.shrtDateFmt & dayLdingZ) snprintf(dd, sizeof(dd), "%02u", tm->tm_mday);
else snprintf(dd, sizeof(dd), "%u", tm->tm_mday);
if (df.shrtDateFmt & mntLdingZ) snprintf(mm, sizeof(mm), "%02u", tm->tm_mon + 1);
else snprintf(mm, sizeof(mm), "%u", tm->tm_mon + 1);
if (df.shrtDateFmt & century) snprintf(yy, sizeof(yy), "%04u", tm->tm_year + 1900);
else snprintf(yy, sizeof(yy), "%02u", tm->tm_year % 100);
switch(df.dateOrder) {
default:
case mdy:
rv = mm + sep + dd + sep + yy;
break;
case dmy:
rv = dd + sep + mm + sep + yy;
break;
case ymd:
rv = yy + sep + mm + sep + dd;
break;
case myd:
rv = mm + sep + yy + sep + dd;
break;
case dym:
rv = dd + sep + yy + sep + mm;
break;
case ydm:
rv = yy + sep + dd + sep + mm;
break;
}
return rv;
}
std::string FormatDate(uint32_t dateTime, unsigned form, uint32_t intlPtr) {
/* not localized. some foreign day/month strings include macroman chars */
if (form == abbrevDate)
return FormatAbbrDate(dateTime, intlPtr);
char buffer[256];
int length;
std::string rv;
time_t t = MacToUnix(dateTime);
struct tm *tm = ::localtime(&t);
switch(form) {
case shortDate:
// Sat, Jul 11, 2020
// length = std::strftime(buffer, sizeof(buffer), "%a, %b %e, %Y", tm);
length = std::strftime(buffer, sizeof(buffer), "%a, %b ", tm);
rv = std::string(buffer, buffer + length);
length = std::snprintf(buffer, sizeof(buffer), "%u, %04u",
tm->tm_mday, tm->tm_year + 1900);
rv.append(buffer, buffer + length);
break;
case longDate:
default:
// Saturday, July 11, 2020
// length = std::strftime(buffer, sizeof(buffer), "%A, %B %e, %Y", tm);
length = std::strftime(buffer, sizeof(buffer), "%A, %B ", tm);
rv = std::string(buffer, buffer + length);
length = std::snprintf(buffer, sizeof(buffer), "%u, %04u",
tm->tm_mday, tm->tm_year + 1900);
rv.append(buffer, buffer + length);
break;
}
return rv;
}
std::string FormatTime(uint32_t dateTime, bool seconds, uint32_t intlPtr) {
char hh[8];
char mm[8];
char ss[8];
std::string rv;
std::string sep;
TimeFormat tf;
time_t t = MacToUnix(dateTime);
struct tm *tm = ::localtime(&t);
if (intlPtr) tf.unpack(intlPtr);
if (tf.timeSep) sep.push_back(tf.timeSep);
if (tf.timeFmt & secLeadingZ) snprintf(ss, sizeof(ss), "%02u", tm->tm_sec);
else snprintf(ss, sizeof(ss), "%u", tm->tm_sec);
if (tf.timeFmt & minLeadingZ) snprintf(mm, sizeof(mm), "%02u", tm->tm_min);
else snprintf(mm, sizeof(mm), "%u", tm->tm_min);
unsigned h = tm->tm_hour;
bool am = h < 12;
switch (tf.timeCycle) {
default:
case timeCycle12:
h %= 12;
if (!h) h = 12;
break;
case timeCycle24:
break;
case timeCycleZero:
h %= 12;
break;
}
if (tf.timeFmt & hrLeadingZ) snprintf(hh, sizeof(hh), "%02u", h);
else snprintf(hh, sizeof(hh), "%u", h);
rv = hh + sep + mm;
if (seconds) {
rv += sep + ss;
}
rv.append( am ? tf.mornStr : tf.eveStr);
return rv;
}
}
uint16_t IUDateString()
{
// void IUDateString(long dateTime,DateForm longFlag,Str255 result)
// DateForm doesn't seem to do anything.
// void IUDateString(long dateTime, DateForm longFlag, Str255 result)
char buffer[256];
int length;
std::string out;
uint32_t dateTime;
@ -71,15 +365,35 @@ namespace Packages {
Log(" IUDateString(%08x, %02x, %08x)\n", dateTime, flag, result);
time_t t = MacToUnix(dateTime);
struct tm *tm = ::localtime(&t);
// not strictly correct -- uses %d/%d/%2d form.
length = std::strftime(buffer, sizeof(buffer), "%m/%d/%y", tm);
out.assign(buffer, length);
out = FormatDate(dateTime, flag, 0);
ToolBox::WritePString(result, out);
return 0;
}
uint16_t IUDatePString()
{
// void IUDateString(long dateTime, DateForm longFlag, Str255 result, Handle intlHandle)
std::string out;
uint32_t dateTime;
uint8_t flag;
uint32_t result;
uint32_t intlHandle;
uint32_t intlPtr;
StackFrame<14>(dateTime, flag, result, intlHandle);
Log(" IUDatePString(%08x, %02x, %08x, %08x)\n", dateTime, flag, result, intlHandle);
intlPtr = intlHandle ? memoryReadLong(intlHandle) : 0;
out = FormatDate(dateTime, flag, intlPtr);
ToolBox::WritePString(result, out);
return 0;
}
uint16_t IUTimeString()
@ -87,8 +401,6 @@ namespace Packages {
// void IUTimeString(long dateTime,Boolean wantSeconds,Str255 result)
// output: 12:00:00 AM or 12:00 AM
char buffer[256];
int length;
std::string out;
uint32_t dateTime;
@ -99,17 +411,210 @@ namespace Packages {
StackFrame<10>(dateTime, wantSeconds, result);
Log(" IUTimeString(%08x, %02x, %08x)\n", dateTime, wantSeconds, result);
time_t t = MacToUnix(dateTime);
struct tm *tm = ::localtime(&t);
length = std::strftime(buffer, sizeof(buffer), wantSeconds ? "%I:%M:%S %p" : "%I:%M %p", tm);
out.assign(buffer, length);
out = FormatTime(dateTime, wantSeconds, 0);
ToolBox::WritePString(result, out);
return 0;
}
uint16_t IUTimePString() {
// void IUTimePString(long dateTime, Boolean wantSeconds, Str255 result, Handle intlHandle)
std::string out;
uint32_t dateTime;
uint8_t wantSeconds;
uint32_t result;
uint32_t intlHandle;
uint32_t intlPtr;
StackFrame<14>(dateTime, wantSeconds, result, intlHandle);
Log(" IUTimePString(%08x, %02x, %08x, %08x)\n", dateTime, wantSeconds, result, intlHandle);
intlPtr = intlHandle ? memoryReadLong(intlHandle) : 0;
out = FormatTime(dateTime, wantSeconds, intlPtr);
ToolBox::WritePString(result, out);
return 0;
}
uint16_t InitDateCache()
{
// OSErr InitDateCache(DateCachePtr theCache)
uint32_t theCache;
uint32_t sp;
sp = StackFrame<4>(theCache);
Log(" InitDateCache(%08x)\n", theCache);
/* cache not used */
ToolReturn<4>(sp, 0);
return 0;
}
enum {
/* StringToDate status values */
fatalDateTime = 0x8000, /* StringToDate and String2Time mask to a fatal error */
longDateFound = 1, /* StringToDate mask to long date found */
leftOverChars = 2, /* StringToDate & Time mask to warn of left over characters */
sepNotIntlSep = 4, /* StringToDate & Time mask to warn of non-standard separators */
fieldOrderNotIntl = 8, /* StringToDate & Time mask to warn of non-standard field order */
extraneousStrings = 16, /* StringToDate & Time mask to warn of unparsable strings in text */
tooManySeps = 32, /* StringToDate & Time mask to warn of too many separators */
sepNotConsistent = 64, /* StringToDate & Time mask to warn of inconsistent separators */
tokenErr = 0x8100, /* StringToDate & Time mask for 'tokenizer err encountered' */
cantReadUtilities = 0x8200,
dateTimeNotFound = 0x8400,
dateTimeInvalid = 0x8800
};
#if 0
typedef short StringToDateStatus;
typedef StringToDateStatus String2DateStatus;
struct DateCacheRecord {
short hidden[256]; /* only for temporary use */
};
typedef struct DateCacheRecord DateCacheRecord;
typedef DateCacheRecord * DateCachePtr;
struct DateTimeRec {
short year;
short month;
short day;
short hour;
short minute;
short second;
short dayOfWeek;
};
typedef struct DateTimeRec DateTimeRec;
typedef SInt64 LongDateTime;
union LongDateCvt {
SInt64 c;
struct {
UInt32 lHigh;
UInt32 lLow;
} hl;
};
typedef union LongDateCvt LongDateCvt;
union LongDateRec {
struct {
short era;
short year;
short month;
short day;
short hour;
short minute;
short second;
short dayOfWeek;
short dayOfYear;
short weekOfYear;
short pm;
short res1;
short res2;
short res3;
} ld;
short list[14]; /*Index by LongDateField!*/
struct {
short eraAlt;
DateTimeRec oldDate;
} od;
};
typedef union LongDateRec LongDateRec;
#endif
enum {
o_era = 0, /* 0 = AD, -1 = BC */
o_year = 2,
o_month = 4, /* 1-12 */
o_day = 6, /* 1-31 */
o_hour = 8,
o_minute = 10,
o_second = 12,
o_dayOfWeek = 14, /*1-7, sun-sat */
o_dayOfYear = 16, /* 1-365 (366) */
o_weekOfYear = 18, /* 1- 52 */
o_pm = 20, /* 0 = am, 1 = pm */
o_res1 = 22,
o_res2 = 24,
o_res3 = 26,
};
uint16_t StringToDate()
{
// StringToDateStatus StringToDate(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime)
uint32_t sp;
uint32_t textPtr;
uint32_t textLen;
uint32_t theCache;
uint32_t lengthUsed;
uint32_t dateTime;
uint16_t rv = 0;
uint32_t used = 0;
struct tm tm = {};
sp = StackFrame<20>(textPtr, textLen, theCache, lengthUsed, dateTime);
std::string s = ToolBox::ReadString(textPtr, textLen);
Log(" StringToDate(%s, %08lx)\n", s.c_str(), dateTime);
rv = dateTimeNotFound;
if (s.length()) {
/* only allow %Y-%m-%d for now */
char *cp;
cp = strptime(s.c_str(), " %Y-%m-%d", &tm);
if (!cp) cp = strptime(s.c_str(), "%m/%d/%Y", &tm);
if (cp) {
rv = longDateFound;
used = cp - s.c_str();
memoryWriteWord(0, dateTime+o_era); /* o = AD, -1 = BC */
memoryWriteWord(1900 + tm.tm_year, dateTime+o_year);
memoryWriteWord(1 + tm.tm_mon, dateTime+o_month);
memoryWriteWord(0 + tm.tm_mday, dateTime+o_day);
/* not populated */
//memoryWriteWord(1 + tm.tm_wday, dateTime+o_dayOfWeek);
//memoryWriteWord(1 + tm.tm_yday, dateTime+o_dayOfYear);
// unsupported - week of year....
}
}
memoryWriteLong(used, lengthUsed);
ToolReturn<2>(sp, rv);
return 0;
}
uint16_t StringToTime()
{
// StringToDateStatus StringToTime(Ptr textPtr, long textLen, DateCachePtr theCache, long *lengthUsed, LongDateRec *dateTime)
uint32_t sp;
uint32_t textPtr;
uint32_t textLen;
uint32_t theCache;
uint32_t lengthUsed;
uint32_t dateTime;
uint16_t rv = 0;
uint32_t used = 0;
sp = StackFrame<20>(textPtr, textLen, theCache, lengthUsed, dateTime);
std::string s = ToolBox::ReadString(textPtr, textLen);
Log(" StringToTime(%s, %08lx)\n", s.c_str(), dateTime);
rv = dateTimeNotFound;
memoryWriteLong(used, lengthUsed);
ToolReturn<2>(sp, rv);
return 0;
}
uint16_t GetIntlResource()
{
// FUNCTION GetIntlResource (theID: Integer) :Handle;
@ -147,8 +652,14 @@ namespace Packages {
return IUDateString();
case 0x0002:
return IUTimeString();
// case 0x0004: return IsMetric();
case 0x0006:
return GetIntlResource();
// case 0x0008: return SetIntlResource();
case 0x000e:
return IUDatePString();
case 0x0010:
return IUTimePString();
default:
fprintf(stderr, "Pack6: selector %04x not supported\n", selector);
@ -158,4 +669,27 @@ namespace Packages {
}
uint16_t ScriptUtil(uint16_t trap)
{
uint32_t selector;
StackFrame<4>(selector);
Log("%04x ScriptUtil(%08x)\n", trap, selector);
switch(selector)
{
case 0x8204fff8:
return InitDateCache();
case 0x8214fff6:
return StringToDate();
case 0x8214fff4:
return StringToTime();
default:
fprintf(stderr, "ScriptUtil: selector %08x not supported\n", selector);
exit(1);
}
}
}

View File

@ -22,6 +22,7 @@ namespace Packages {
uint16_t Pack14(uint16_t);
uint16_t Pack15(uint16_t);
uint16_t ScriptUtil(uint16_t);
}
#endif

View File

@ -848,7 +848,7 @@ namespace RM
if (nativeSize != info->size) {
// resize...
// chould get state / unlock / set state ... but that does nothing in OS X.
// could get state / unlock / set state ... but that does nothing in OS X.
::SetHandleSize(nativeHandle, info->size);
OSErr err = MemError();

View File

@ -39,12 +39,18 @@
#include <cmath>
#include "stackframe.h"
#include "complex.h"
#include "fpinfo.h"
#include <sane/floating_point.h>
#include <sane/sane.h>
#include <sane/comp.h>
using ToolBox::Log;
enum {
SIGDIGLEN = 20,
};
namespace SANE
{
@ -53,9 +59,7 @@ using std::fpclassify;
using std::signbit;
using std::abs;
using its_complicated::to_string;
using its_complicated::fpclassify;
using its_complicated::signbit;
namespace fp = floating_point;
namespace {
// default environment is:
@ -140,9 +144,9 @@ using its_complicated::signbit;
template<>
complex readnum<complex>(uint32_t address)
comp readnum<comp>(uint32_t address)
{
return complex(memoryReadLongLong(address));
return comp(memoryReadLongLong(address));
}
@ -167,25 +171,17 @@ using its_complicated::signbit;
template<>
long double readnum<long double>(uint32_t address)
{
char buffer[16];
static_assert(sizeof(long double) == 16, "unexpected long double size");
// read and swap 10 bytes
// this is very much little endian.
uint8_t buffer[16];
long double ld;
for (unsigned i = 0; i < 10; ++i)
{
buffer[9 - i] = memoryReadByte(address + i);
}
// remainder are 0-filled.
for (unsigned i = 10; i < 16; ++i)
buffer[i] = 0;
buffer[i] = memoryReadByte(address + i);
// now cast...
fp::info fpi;
fpi.read(fp::format<10, endian::big>{}, buffer);
return *((long double *)buffer);
fpi.write(ld);
return ld;
}
@ -211,9 +207,9 @@ using its_complicated::signbit;
}
template<>
void writenum<complex>(complex value, uint32_t address)
void writenum<comp>(comp value, uint32_t address)
{
memoryWriteLongLong(value, address);
memoryWriteLongLong((uint64_t)value, address);
}
template<>
@ -235,19 +231,18 @@ using its_complicated::signbit;
template<>
void writenum<long double>(long double value, uint32_t address)
{
static_assert(sizeof(value) == 16, "unexpected long double size");
uint8_t buffer[16];
char buffer[16];
fp::info fpi;
fpi.read(value);
std::memcpy(buffer, &value, sizeof(value));
fpi.write(fp::format<10, endian::big>{}, buffer);
// copy 10 bytes over
// little-endian specific.
for(unsigned i = 0; i < 10; ++i)
memoryWriteByte(buffer[9 - i], address + i);
for (unsigned i = 0; i < 10; ++i)
memoryWriteByte(buffer[i], address + i);
}
decform decform::read(uint32_t address)
decform read_decform(uint32_t address)
{
enum {
_style = 0,
@ -261,7 +256,8 @@ using its_complicated::signbit;
d.digits = memoryReadWord(address + _digits);
return d;
}
void decform::write(uint32_t address)
void write_decform(const decform &df, uint32_t address)
{
enum {
_style = 0,
@ -270,18 +266,17 @@ using its_complicated::signbit;
};
if (!address) return;
memoryWriteByte(style, address + _style);
memoryWriteWord(digits, address + _digits);
memoryWriteByte(df.style, address + _style);
memoryWriteByte(0, address + _unused);
memoryWriteWord(df.digits, address + _digits);
}
decimal decimal::read(uint32_t address)
decimal read_decimal(uint32_t address)
{
enum {
_sgn = 0,
_exp = 2,
_sig = 4,
SIGDIGLEN = 20,
};
decimal d;
@ -294,90 +289,23 @@ using its_complicated::signbit;
d.sig = ToolBox::ReadPString(address + _sig, false);
return d;
}
void decimal::write(uint32_t address)
void write_decimal(const decimal &d, uint32_t address)
{
enum {
_sgn = 0,
_exp = 2,
_sig = 4,
SIGDIGLEN = 20,
};
memoryWriteByte(sgn, address + _sgn);
memoryWriteByte(d.sgn, address + _sgn);
memoryWriteByte(0, address + _sgn + 1); // unused.
memoryWriteWord(exp, address + _exp);
memoryWriteWord(d.exp, address + _exp);
// check if <= SIGDIGLEN?
ToolBox::WritePString(address + _sig, sig);
ToolBox::WritePString(address + _sig, d.sig);
}
void format_f(extended x, int precision, std::string &mm, std::string &nn)
{
char *buffer = nullptr;
mm.clear();
nn.clear();
if (precision < 0) precision = 0;
int length = asprintf(&buffer, "%.*Lf", precision, x);
std::string tmp(buffer, length);
free(buffer);
auto dot = tmp.find('.');
if (dot == tmp.npos)
{
mm = std::move(tmp);
}
else
{
mm = tmp.substr(0, dot);
nn = tmp.substr(dot + 1);
}
// skip mm if it's 0
if (mm.length() == 1 && mm.front() == '0') mm.clear();
// skip nn if it's 0000...
if (std::all_of(nn.begin(), nn.end(), [](char c){ return c == '0'; }))
nn.clear();
}
void format_e(extended x, int precision, std::string &mm, std::string &nn, int &exp)
{
char *buffer = nullptr;
exp = 0;
mm.clear();
nn.clear();
if (precision < 0) precision = 0;
if (precision > 19) precision = 19;
int length = asprintf(&buffer, "%.*Le", precision, x);
// output mm . nn e[+-]exp
// mm e[+-]exp
std::string tmp(buffer, length);
free(buffer);
auto dot = tmp.find('.');
auto e = tmp.find('e');
if (dot == tmp.npos)
{
mm = tmp.substr(0, e);
}
else
{
mm = tmp.substr(0, dot);
nn = tmp.substr(dot + 1, e - dot - 1);
}
char sign = tmp[e+1];
tmp = tmp.substr(e + 2);
exp = std::stoi(tmp);
if (sign == '-') exp = -exp;
}
uint16_t fx2dec()
{
@ -392,7 +320,6 @@ using its_complicated::signbit;
uint32_t d_adr;
decform df;
decimal d;
StackFrame<14>(f_adr, a_adr, d_adr, op);
@ -400,7 +327,7 @@ using its_complicated::signbit;
Log(" FX2DEC(%08x, %08x, %08x, %04x)\n", f_adr, a_adr, d_adr, op);
extended s = readnum<extended>(a_adr);
df = decform::read(f_adr);
df = read_decform(f_adr);
if (ToolBox::Trace)
{
@ -408,147 +335,10 @@ using its_complicated::signbit;
Log(" %s (style: %d digits: %d)\n", tmp1.c_str(), df.style, df.digits);
}
/*
* SANE pp 30, 31
*
* Floating style:
* [-| ]m[.nnn]e[+|-]dddd
*
* Fixed style:
* [-]mmm[.nnn]
*/
if (df.digits < 0) df.digits = 0;
if (df.digits > 19) df.digits = 19;
fpinfo fpi(s);
//fprintf(stderr, "%02x %02x %d %016llx\n", fpi.sign, fpi.one, fpi.exp, fpi.sig);
d.sgn = signbit(s);
// handle infinity, nan as a special case.
switch (fpclassify(s))
{
case FP_ZERO:
d.sig = "0";
d.write(d_adr);
return 0;
case FP_NAN:
// NAN type encoded in the sig.
{
char buffer[20]; // 16 + 2 needed
snprintf(buffer, 20, "N%016llx", fpi.sig);
d.sig = buffer;
d.write(d_adr);
}
return 0;
case FP_INFINITE:
d.sig = "I";
d.write(d_adr);
return 0;
default:
break;
}
// normal and subnormal handled here....
// float decimal: df.digits refers to the total length
// fixed decimal: df.digits refers to the fractional part only.
s = abs(s);
if (s < 1.0 && df.style == decform::FLOATDECIMAL)
{
std::string mm;
std::string nn;
format_e(s, df.digits - 1, mm, nn, d.exp);
d.sig = mm + nn;
// better be < 0...
if (d.exp < 0)
d.exp -= nn.length();
d.write(d_adr);
return 0;
}
else // s > 1
{
std::string mm;
std::string nn;
format_f(s, df.digits, mm, nn);
if (mm.empty() && nn.empty())
{
// very large 0.
d.sig = "0";
d.write(d_adr);
return 0;
}
// if nn is empty (or 0s), this is a large number,
// and we don't have to worry about the fraction.
if (nn.empty())
{
d.exp = 0;
if (df.style == decform::FIXEDDECIMAL) df.digits = 19;
// limit the length.
if (mm.length() > df.digits)
{
d.exp = mm.length() - df.digits;
mm.resize(df.digits);
}
d.sig = std::move(mm);
}
else
{
if (df.style == decform::FIXEDDECIMAL)
{
// digits is the total size, mm + nn
// re-format with new precision.
// this is getting repetitive...
if (mm.length())
{
int precision = df.digits - mm.length();
if (precision < 0) precision = 1;
format_f(s, precision, mm, nn);
}
}
// todo -- if mm is empty and nn has leading 0s,
// drop the leading 0s and adjust the exponent
// accordingly.
d.sig = mm + nn;
d.exp = -nn.length();
if (d.sig.length() > 19)
{
d.exp += (d.sig.length() - 19);
d.sig.resize(19);
}
}
d.write(d_adr);
return 0;
}
decimal d = x2dec(s, df);
truncate(d, SIGDIGLEN);
write_decimal(d, d_adr);
return 0;
}
@ -758,45 +548,16 @@ using its_complicated::signbit;
StackFrame<10>(decimalPtr, dest, op);
uint16_t sgn = memoryReadByte(decimalPtr);
int16_t exp = memoryReadWord(decimalPtr + 2);
std::string sig;
sig = ToolBox::ReadPString(decimalPtr + 4, false);
decimal d = read_decimal(decimalPtr);
Log(" %s({%c %s e%d}, %08x)\n",
name,
sgn ? '-' : ' ', sig.c_str(), exp,
d.sgn ? '-' : ' ', d.sig.c_str(), d.exp,
dest
);
extended tmp = 0;
if (sig.length())
{
if (sig[0] == 'I')
{
tmp = INFINITY;
}
else if (sig[0] == 'N')
{
tmp = NAN; // todo -- nan type
}
else
{
tmp = stold(sig);
while (exp > 0)
{
tmp = tmp * 10.0;
exp--;
}
while (exp < 0)
{
tmp = tmp / 10.0;
exp++;
}
}
}
if (sgn) tmp = -tmp;
extended tmp = dec2x(d);
writenum<DestType>((DestType)tmp, dest);
@ -975,7 +736,7 @@ using its_complicated::signbit;
return 0;
}
extern "C" void cpuSetFlagsAbs(UWO f);
extern "C" void cpuSetFlagsAbs(uint16_t f);
uint16_t fp68k(uint16_t trap)
{
uint16_t op;
@ -996,7 +757,7 @@ using its_complicated::signbit;
case 0x0000: return fadd<extended>("FADDX");
case 0x0800: return fadd<double>("FADDD");
case 0x1000: return fadd<float>("FADDS");
//case 0x3000: return fadd<complex>("FADDC");
//case 0x3000: return fadd<comp>("FADDC");
case 0x2000: return fadd<int16_t>("FADDI");
case 0x2800: return fadd<int32_t>("FADDL");
@ -1004,7 +765,7 @@ using its_complicated::signbit;
case 0x0002: return fsub<extended>("FSUBX");
case 0x0802: return fsub<double>("FSUBD");
case 0x1002: return fsub<float>("FSUBS");
//case 0x3002: return fsub<complex>("FSUBC");
//case 0x3002: return fsub<comp>("FSUBC");
case 0x2002: return fsub<int16_t>("FSUBI");
case 0x2802: return fsub<int32_t>("FSUBL");
@ -1012,7 +773,7 @@ using its_complicated::signbit;
case 0x0004: return fmul<extended>("FMULX");
case 0x0804: return fmul<double>("FMULD");
case 0x1004: return fmul<float>("FMULS");
//case 0x3004: return fmul<complex>("FMUlC");
//case 0x3004: return fmul<comp>("FMULC");
case 0x2004: return fmul<int16_t>("FMULI");
case 0x2804: return fmul<int32_t>("FMULL");
@ -1020,7 +781,7 @@ using its_complicated::signbit;
case 0x0006: return fdiv<extended>("FDIVX");
case 0x0806: return fdiv<double>("FDIVD");
case 0x1006: return fdiv<float>("FDIVS");
//case 0x3006: return fdiv<complex>("FDIVC");
//case 0x3006: return fdiv<comp>("FDIVC");
case 0x2006: return fdiv<int16_t>("FDIVI");
case 0x2806: return fdiv<int32_t>("FDIVL");
@ -1028,14 +789,14 @@ using its_complicated::signbit;
case 0x0008: return fcmp<extended>("FCMPX");
case 0x0808: return fcmp<double>("FCMPD");
case 0x1008: return fcmp<float>("FCMPS");
//case 0x3008: return fcmp<complex>("FCMPC");
//case 0x3008: return fcmp<comp>("FCMPC");
case 0x2008: return fcmp<int16_t>("FCMPI");
case 0x2808: return fcmp<int32_t>("FCMPL");
case 0x000a: return fcmp<extended>("FCPXX");
case 0x080a: return fcmp<double>("FCPXD");
case 0x100a: return fcmp<float>("FCPXS");
//case 0x300a: return fcmp<complex>("FCPXC");
//case 0x300a: return fcmp<comp>("FCPXC");
case 0x200a: return fcmp<int16_t>("FCPXI");
case 0x280a: return fcmp<int32_t>("FCPXL");
@ -1044,7 +805,7 @@ using its_complicated::signbit;
case 0x0010: return fconvert<extended, extended>("FX2X");
case 0x0810: return fconvert<extended, double>("FX2D");
case 0x1010: return fconvert<extended, float>("FX2S");
case 0x3010: return fconvert<extended, complex>("FX2C");
case 0x3010: return fconvert<extended, comp>("FX2C");
case 0x2010: return fconvert<extended, int16_t>("FX2I");
case 0x2810: return fconvert<extended, int32_t>("FX2L");
@ -1052,7 +813,7 @@ using its_complicated::signbit;
case 0x000e: return fconvert<extended, extended>("FX2X");
case 0x080e: return fconvert<double, extended>("FD2X");
case 0x100e: return fconvert<float, extended>("FS2X");
case 0x300e: return fconvert<complex, extended>("FC2X");
case 0x300e: return fconvert<comp, extended>("FC2X");
case 0x200e: return fconvert<int16_t, extended>("FI2X");
case 0x280e: return fconvert<int32_t, extended>("FL2X");
@ -1060,7 +821,7 @@ using its_complicated::signbit;
case 0x001c: return fclassify<extended>("FCLASSX");
case 0x081c: return fclassify<double>("FCLASSD");
case 0x101c: return fclassify<float>("FCLASSS");
case 0x301c: return fclassify<complex>("FCLASSC");
case 0x301c: return fclassify<comp>("FCLASSC");
case 0x0009:
// fdec2x
@ -1159,22 +920,6 @@ using its_complicated::signbit;
{
// void str2dec(const char *s,short *ix,decimal *d,short *vp);
#if 0
#define SIGDIGLEN 20 /* significant decimal digits */
#define DECSTROUTLEN 80 /* max length for dec2str output */
struct decimal {
char sgn; /*sign 0 for +, 1 for -*/
char unused;
short exp; /*decimal exponent*/
struct{
unsigned char length;
unsigned char text[SIGDIGLEN]; /*significant digits */
unsigned char unused;
}sig;
};
#endif
uint32_t stringPtr;
uint32_t indexPtr;
uint32_t decimalPtr;
@ -1199,23 +944,13 @@ struct decimal {
str2dec(str, index, d, valid);
if (type == 'P') index++;
truncate(d, SIGDIGLEN);
memoryWriteWord(index, indexPtr);
memoryWriteWord(valid, validPtr);
if (d.sig.length() > 20)
{
// truncate and adjust the exponent
// 1234e0 -> 123e1 -> 12e2 -> 1e3
// 1234e-1 -> 123e-0 -> 12e1
int over = d.sig.length() - 20;
d.sig.resize(20);
d.exp += over;
}
memoryWriteByte(d.sgn, decimalPtr);
memoryWriteByte(0, decimalPtr + 1);
memoryWriteWord(d.exp, decimalPtr + 2);
ToolBox::WritePString(decimalPtr + 4, d.sig);
write_decimal(d, decimalPtr);
return 0;
}
@ -1236,8 +971,8 @@ struct decimal {
Log(" FDEC2STR(%08x, %08x, %08x)\n", f_adr, d_adr, s_adr);
df = decform::read(f_adr);
d = decimal::read(d_adr);
df = read_decform(f_adr);
d = read_decimal(d_adr);
if (ToolBox::Trace)
{
@ -1247,130 +982,9 @@ struct decimal {
std::string s;
if (df.digits < 0) df.digits = 0;
if (d.sig.empty()) d.sig = "0";
if (df.style == decform::FLOATDECIMAL)
{
// [-| m[.nnn]e[+|-]dddd
// - or space.
if (d.sgn) s.push_back('-');
else s.push_back(' ');
if (d.sig[0] == 'I')
{
s.append("INF");
ToolBox::WritePString(s_adr, s);
return 0;
}
if (d.sig[0] == 'N')
{
// todo -- include actual nan code.
s.append("NAN(000)");
ToolBox::WritePString(s_adr, s);
return 0;
}
// 1 leading digit.
s.push_back(d.sig[0]);
if (d.sig.length() > 1)
{
s.push_back('.');
s.append(d.sig.substr(1));
}
s.push_back('e');
if (d.exp < 0)
{
// to_string() will include the -
s.append(std::to_string(d.exp));
}
else
{
s.push_back('+');
s.append(std::to_string(d.exp));
}
ToolBox::WritePString(s_adr, s);
return 0;
}
else
{
// [-] mmmm [. nnn]
if (d.sgn) s.push_back('-');
std::string mm;
std::string nn;
if (d.sig[0] == 'I')
{
s.append("INF");
ToolBox::WritePString(s_adr, s);
return 0;
}
if (d.sig[0] == 'N')
{
// todo -- include actual nan code.
// check how SANE format it (hex/dec)
s.append("NAN(000)");
ToolBox::WritePString(s_adr, s);
return 0;
}
//
std::string tmp = std::move(d.sig);
if (d.exp >= 0)
{
// 0, 5 == 5
// 1, 12 = 120
mm = std::move(tmp);
mm.append(d.exp, '0');
tmp.clear();
}
else
{
// -1, 12 = 1.2
// -2, 12 = 0.12
// -3 12 = 0.012
int m = tmp.length() + d.exp;
if (m > 0)
{
mm = tmp.substr(0, m);
tmp.erase(0, m);
d.exp = 0;
}
else
{
mm = "0";
}
}
s.append(mm);
if (df.digits > 0)
{
s.push_back('.');
// if negative exp, need to put in leading 0s.
// for a pathological case like -32768, this would
// be silly.
if (d.exp < 0)
nn.append(-d.exp, '0');
nn.append(tmp);
nn.resize(df.digits, '0'); // todo -- should round...
s.append(nn);
}
// if > 80 in length, return '?'
if (s.length() > 80) s = "?";
ToolBox::WritePString(s_adr, s);
return 0;
}
dec2str(df, d, s);
ToolBox::WritePString(s_adr, s);
return 0;
}

View File

@ -3,36 +3,9 @@
#include <cstdint>
#include <string>
#include <sane/sane.h>
namespace SANE
{
struct decimal {
enum {
SIGDIGLEN = 20,
};
int sgn = 0;
int exp = 0;
std::string sig;
static decimal read(uint32_t address);
void write(uint32_t address);
};
struct decform
{
enum {
FLOATDECIMAL = 0,
FIXEDDECIMAL = 1,
};
uint8_t style = 0;
uint16_t digits = 0;
static decform read(uint32_t address);
void write(uint32_t address);
};
namespace SANE {
void str2dec(const std::string &s, uint16_t &index, decimal &d, uint16_t &vp);

View File

@ -1,293 +0,0 @@
/*
* Copyright (c) 2013, Kelvin W Sherlock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "sane.h"
#include <string>
namespace SANE {
/*
* %{} is a final transition. fpc points to the next character
* %!{} is a final transition to an error state. fpc " " " "
*
*/
%%{
machine fpstr;
action check { checkpoint = fpc; }
nantype =
'('
digit* ${ nantype = nantype * 10 + fc - '0'; }
')'
$!{ nantype = 0; }
%check
;
nan = 'NAN'i
>{ nan = true; }
%check
%!check
nantype?
;
infinity = 'INF'i
>{ nan = true; }
%{ nan = false; infinity = true; checkpoint = fpc; }
%!{ nan = false; infinity = true; checkpoint = fpc; };
exponent =
[eE]
[+\-]? ${ if (fc == '-') negative_exp = true; }
digit+ ${ exp = exp * 10 + fc - '0'; }
%check
%!check
;
significand =
(
(
digit+ ${
// don't push leading 0s
if (fc != '0' || siga.size())
siga.push_back(fc);
}
( '.' digit* ${ sigb.push_back(fc); })?
)
|
(
'.'
digit+ ${ sigb.push_back(fc); }
)
)
%check
%!check
;
finite_number = significand exponent?;
unsigned_decimal = finite_number | infinity | nan;
left_decimal =
[+\-]? ${ if (fc == '-') negative = true; }
unsigned_decimal
;
decimal_number = [ \t]* left_decimal;
main := decimal_number;
}%%
std::string normalize(std::string &a, std::string &b, int &exponent)
{
int pos;
// 1 = 1e0 10 = 1e1
// 12 = 12e0
// 123 = 123e0
// 1.1 = 11e-1
// 0.1 = 1e-1
// remove trailing 0s
while (b.size() && b.back() == '0')
b.pop_back();
int bits = 0;
if (a.length()) bits |= 0x01;
if (b.length()) bits |= 0x02;
std::string out;
switch(bits)
{
case 0x00:
// should never happen...
break;
case 0x01:
// a only.
// remove trailing 0s and add 1 exp for each.
while (a.length() && a.back() == '0')
{
a.pop_back();
exponent++;
}
out = a;
break;
case 0x02:
// b only.
//.001 = e1-3
exponent -= b.length();
pos = b.find_first_not_of('0');
out = b.substr(pos);
break;
case 0x03:
// a and b
// 10.01 = 1001e-2
exponent -= b.length();
out = a;
out += b;
break;
}
if (out.empty()) out = "0";
return out;
}
void str2dec(const std::string &s, uint16_t &index, decimal &d, uint16_t &vp)
{
%%write data;
bool infinity = false;
bool nan = false;
int nantype = 0;
bool negative = false;
bool negative_exp = false;
int exp = 0;
std::string siga, sigb;
if (index >= s.size()) return;
/*
char *p = s.c_str();
char *pe = p + s.size();
char *eof = pe;
char *checkpoint = p;
*/
auto p = s.begin();
auto checkpoint = s.begin();
auto pe = s.end();
auto eof = s.end();
int cs;
p += index;
%%write init;
%%write exec;
d.sgn = negative ? 1 : 0;
if (infinity)
{
d.sig = "I";
}
else if (nan)
{
d.sig = "N";
if (nantype)
{
const char *hexstr = "0123456789abcdef";
// 4-byte hex
d.sig.push_back(hexstr[(nantype >> 24) & 0xff]);
d.sig.push_back(hexstr[(nantype >> 16) & 0xff]);
d.sig.push_back(hexstr[(nantype >> 8) & 0xff]);
d.sig.push_back(hexstr[(nantype >> 0) & 0xff]);
}
}
else
{
d.sig = normalize(siga, sigb, exp);
d.exp = negative_exp ? -exp : exp;
}
vp = cs != fpstr_error;
index = checkpoint - s.begin();
return;
#if 0
printf("%s\n", str);
bool valid = cs != fpstr_error;
int index = checkpoint - str;
printf("infinity: %d\n", infinity);
printf(" nan: %d\n", nan);
printf(" nantype: %d\n", nantype);
if (negative_exp) exp = -exp;
printf(" exp: %d\n", exp);
printf("negative: %d\n", negative);
printf(" sig: %s.%s\n", siga.c_str(), sigb.c_str());
printf(" valid: %d\n", valid);
printf(" index: %d\n", index);
printf("\n");
/*
* now we need to normalize the significand / exponent
* 1.2 e0 -> 12 e-1
* 1000 e0 -> 1 e 3
*/
std::string sig = normalize(siga, sigb, exp);
printf("normalized: %s e %d\n", sig.c_str(), exp);
#endif
}
} // namespace
#ifdef MAIN
#include <cstdio>
int main(int argc, char **argv)
{
for (int i = 1; i < argc; ++i)
{
std::string s = argv[i];
SANE::decimal d;
short index = 0;
short valid = 0;
SANE::str2dec(s, index, d, valid);
printf("index: %d\n", index);
printf("valid: %d\n", valid);
printf(" sign: %d\n", d.sgn);
printf(" exp: %d\n", d.exp);
printf(" sig: %s\n", d.sig.c_str());
printf("\n");
}
}
#endif

View File

@ -56,7 +56,7 @@
// yuck. TST.W d0
extern "C" void cpuSetFlagsNZ00NewW(UWO res);
extern "C" void cpuSetFlagsNZ00NewW(uint16_t res);
@ -199,6 +199,14 @@ namespace ToolBox {
d0 = OS::SetFPos(trap);
break;
// _RelString [,MARKS, CASE]
case 0xa050:
case 0xa250:
case 0xa450:
case 0xa650:
d0 = OS::RelString(trap);
break;
case 0xa051:
d0 = OS::ReadXPRam(trap);
break;

View File

@ -257,8 +257,8 @@ struct VolumeParam {
unsigned short ioVNmFls; /*number of files in directory*/
unsigned short ioVDirSt; /*start block of file directory*/
short ioVBlLn; /*GetVolInfo: length of dir in blocks*/
unsigned short ioVNmAlBlks; /*for compatibilty ioVNmAlBlks * ioVAlBlkSiz <= 2 GB*/
unsigned long ioVAlBlkSiz; /*for compatibilty ioVAlBlkSiz is <= $0000FE00 (65,024)*/
unsigned short ioVNmAlBlks; /*for compatibility ioVNmAlBlks * ioVAlBlkSiz <= 2 GB*/
unsigned long ioVAlBlkSiz; /*for compatibility ioVAlBlkSiz is <= $0000FE00 (65,024)*/
unsigned long ioVClpSiz; /*GetVolInfo: bytes to allocate at a time*/
unsigned short ioAlBlSt; /*starting disk(512-byte) block in block map*/
unsigned long ioVNxtFNum; /*GetVolInfo: next free file number*/

View File

@ -1,4 +1,4 @@
#!/usr/bin/sh
#!/bin/sh
infile="$1"