Update to v094r29 release.

byuu says:

Note: for Windows users, please go to nall/intrinsics.hpp line 60 and
correct the typo from "DISPLAY_WINDOW" to "DISPLAY_WINDOWS" before
compiling, otherwise things won't work at all.

This will be a really major WIP for the core SNES emulation, so please
test as thoroughly as possible.

I rewrote the 65816 CPU core's dispatcher from a jump table to a switch
table. This was so that I could pass class variables as parameters to
opcodes without crazy theatrics.

With that, I killed the regs.r[N] stuff, the flag_t operator|=, &=, ^=
stuff, and all of the template versions of opcodes.

I also removed some stupid pointless flag tests in xcn and pflag that
would always be true.

I sure hope that AWJ is happy with this; because this change was so that
my flag assignments and branch tests won't need to build regs.P into
a full 8-bit variable anymore.

It does of course incur a slight performance hit when you pass in
variables by-value to functions, but it should help with binary size
(and thus cache) by reducing a lot of extra functions. (I know I could
have used template parameters for some things even with a switch table,
but chose not to for the aforementioned reasons.)

Overall, it's about a ~1% speedup from the previous build. The CPU core
instructions were never a bottleneck, but I did want to fix the P flag
building stuff because that really was a dumb mistake v_v'
This commit is contained in:
Tim Allen 2015-06-22 23:31:49 +10:00
parent e0815b55b9
commit 83f684c66c
52 changed files with 1151 additions and 1033 deletions

View File

@ -8,7 +8,7 @@ using namespace nall;
namespace Emulator {
static const string Name = "higan";
static const string Version = "094.28";
static const string Version = "094.29";
static const string Author = "byuu";
static const string License = "GPLv3";
static const string Website = "http://byuu.org/";

View File

@ -149,6 +149,7 @@ auto BrowserDialogWindow::run() -> lstring {
window.setCentered(state.parent);
window.setVisible();
view.resizeColumns();
view.setFocused();
window.setModal();
window.setVisible(false);

View File

@ -2,15 +2,15 @@
namespace hiro {
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XlibDisplay* pApplication::display = nullptr;
#endif
void pApplication::run() {
if(Application::state.onMain) {
while(Application::state.quit == false) {
processEvents();
while(!Application::state.quit) {
Application::doMain();
processEvents();
}
} else {
gtk_main();
@ -29,7 +29,7 @@ void pApplication::quit() {
//if gtk_main() was invoked, call gtk_main_quit()
if(gtk_main_level()) gtk_main_quit();
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
//todo: Keyboard::poll() is being called after Application::quit();
//so if display is closed; this causes a segfault
//XCloseDisplay(display);
@ -38,7 +38,7 @@ void pApplication::quit() {
}
void pApplication::initialize() {
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
display = XOpenDisplay(nullptr);
#endif
@ -69,7 +69,7 @@ void pApplication::initialize() {
g_type_class_unref(g_type_class_ref(GTK_TYPE_BUTTON));
g_object_set(gtkSettings, "gtk-button-images", true, nullptr);
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
//there is a serious bug in GTK 2.24 for Windows with the "ime" (Windows IME) input method:
//by default, it will be impossible to type in text fields at all.
//there are various tricks to get around this; but they are unintuitive and unreliable.

View File

@ -3,7 +3,7 @@
namespace hiro {
struct pApplication {
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
static XlibDisplay* display;
#endif

View File

@ -10,13 +10,13 @@ Size pDesktop::size() {
}
Geometry pDesktop::workspace() {
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XlibDisplay* display = XOpenDisplay(nullptr);
int screen = DefaultScreen(display);

View File

@ -1,4 +1,4 @@
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
#define UNICODE
#define WINVER 0x0601
#define _WIN32_WINNT WINVER
@ -20,15 +20,15 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#if defined(Hiro_SourceEdit)
#include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#endif
#include <nall/windows/registry.hpp>
#include <nall/windows/utf8.hpp>
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
#include <nall/xorg/guard.hpp>
#include <X11/Xatom.h>
#include <cairo.h>
@ -37,9 +37,9 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#if defined(Hiro_SourceEdit)
#include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#include <gtksourceview/gtksourceview.h>
#include <gtksourceview/gtksourcelanguagemanager.h>
#include <gtksourceview/gtksourcestyleschememanager.h>
#endif
#include <nall/xorg/guard.hpp>
#endif

View File

@ -5,7 +5,7 @@ namespace hiro {
auto pKeyboard::poll() -> vector<bool> {
vector<bool> result;
char state[256];
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XQueryKeymap(pApplication::display, state);
#endif
for(auto& code : settings->keycodes) {
@ -16,7 +16,7 @@ auto pKeyboard::poll() -> vector<bool> {
auto pKeyboard::pressed(unsigned code) -> bool {
char state[256];
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XQueryKeymap(pApplication::display, state);
#endif
return _pressed(state, code);
@ -26,12 +26,12 @@ auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool {
uint8_t lo = code >> 0;
uint8_t hi = code >> 8;
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
if(lo && GetAsyncKeyState(lo) & 0x8000) return true;
if(hi && GetAsyncKeyState(hi) & 0x8000) return true;
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
if(lo && state[lo >> 3] & (1 << (lo & 7))) return true;
if(hi && state[hi >> 3] & (1 << (hi & 7))) return true;
#endif
@ -223,7 +223,7 @@ auto pKeyboard::_translate(unsigned code) -> signed {
auto pKeyboard::initialize() -> void {
auto append = [](unsigned lo, unsigned hi = 0) {
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::display, lo) : 0;
hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::display, hi) : 0;
#endif
@ -232,11 +232,11 @@ auto pKeyboard::initialize() -> void {
#define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; }
for(auto& key : Keyboard::keys) {
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
#include <hiro/platform/windows/keyboard.hpp>
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
#include <hiro/platform/xorg/keyboard.hpp>
#endif

View File

@ -3,13 +3,13 @@
namespace hiro {
auto pMouse::position() -> Position {
#if defined(PLATFORM_WINDOWS)
POINT point = {0};
#if defined(DISPLAY_WINDOWS)
POINT point{0};
GetCursorPos(&point);
return {point.x, point.y};
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XlibWindow root, child;
int rootx, rooty, winx, winy;
unsigned int mask;
@ -19,7 +19,7 @@ auto pMouse::position() -> Position {
}
auto pMouse::pressed(Mouse::Button button) -> bool {
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
switch(button) {
case Mouse::Button::Left: return GetAsyncKeyState(VK_LBUTTON) & 0x8000;
case Mouse::Button::Middle: return GetAsyncKeyState(VK_MBUTTON) & 0x8000;
@ -27,7 +27,7 @@ auto pMouse::pressed(Mouse::Button button) -> bool {
}
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
XlibWindow root, child;
int rootx, rooty, winx, winy;
unsigned int mask;

View File

@ -67,11 +67,11 @@ auto pViewport::destruct() -> void {
}
auto pViewport::handle() const -> uintptr_t {
#if defined(PLATFORM_WINDOWS)
#if defined(DISPLAY_WINDOWS)
return (uintptr_t)GDK_WINDOW_HWND(gtk_widget_get_window(gtkWidget));
#endif
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
return GDK_WINDOW_XID(gtk_widget_get_window(gtkWidget));
#endif
}

View File

@ -281,13 +281,13 @@ auto pWindow::setGeometry(Geometry geometry) -> void {
auto pWindow::setModal(bool modal) -> void {
if(modal) {
gtk_window_set_modal(GTK_WINDOW(widget), true);
while(state().modal) {
Application::processEvents();
while(!Application::state.quit && state().modal) {
if(Application::state.onMain) {
Application::doMain();
} else {
usleep(20 * 1000);
}
Application::processEvents();
}
gtk_window_set_modal(GTK_WINDOW(widget), false);
}

View File

@ -1,11 +1,16 @@
/*
libco.amd64 (2009-10-12)
libco.amd64 (2015-06-19)
author: byuu
license: public domain
*/
#define LIBCO_C
#include "libco.h"
//Win64 only: provides a substantial speed-up, but will thrash XMM regs
//do not use this unless you are certain your application won't use SSE
//#define LIBCO_AMD64_NO_SSE
#include <assert.h>
#include <stdlib.h>
@ -18,21 +23,54 @@ static thread_local cothread_t co_active_handle = 0;
static void (*co_swap)(cothread_t, cothread_t) = 0;
#ifdef _WIN32
//ABI: Win64
/* ABI: Win64 */
static unsigned char co_swap_function[] = {
0x48, 0x89, 0x22, 0x48, 0x8B, 0x21, 0x58, 0x48, 0x89, 0x6A, 0x08, 0x48, 0x89, 0x72, 0x10, 0x48,
0x89, 0x7A, 0x18, 0x48, 0x89, 0x5A, 0x20, 0x4C, 0x89, 0x62, 0x28, 0x4C, 0x89, 0x6A, 0x30, 0x4C,
0x89, 0x72, 0x38, 0x4C, 0x89, 0x7A, 0x40, 0x48, 0x81, 0xC2, 0x80, 0x00, 0x00, 0x00, 0x48, 0x83,
0xE2, 0xF0, 0x0F, 0x29, 0x32, 0x0F, 0x29, 0x7A, 0x10, 0x44, 0x0F, 0x29, 0x42, 0x20, 0x44, 0x0F,
0x29, 0x4A, 0x30, 0x44, 0x0F, 0x29, 0x52, 0x40, 0x44, 0x0F, 0x29, 0x5A, 0x50, 0x44, 0x0F, 0x29,
0x62, 0x60, 0x44, 0x0F, 0x29, 0x6A, 0x70, 0x44, 0x0F, 0x29, 0xB2, 0x80, 0x00, 0x00, 0x00, 0x44,
0x0F, 0x29, 0xBA, 0x90, 0x00, 0x00, 0x00, 0x48, 0x8B, 0x69, 0x08, 0x48, 0x8B, 0x71, 0x10, 0x48,
0x8B, 0x79, 0x18, 0x48, 0x8B, 0x59, 0x20, 0x4C, 0x8B, 0x61, 0x28, 0x4C, 0x8B, 0x69, 0x30, 0x4C,
0x8B, 0x71, 0x38, 0x4C, 0x8B, 0x79, 0x40, 0x48, 0x81, 0xC1, 0x80, 0x00, 0x00, 0x00, 0x48, 0x83,
0xE1, 0xF0, 0x0F, 0x29, 0x31, 0x0F, 0x29, 0x79, 0x10, 0x44, 0x0F, 0x29, 0x41, 0x20, 0x44, 0x0F,
0x29, 0x49, 0x30, 0x44, 0x0F, 0x29, 0x51, 0x40, 0x44, 0x0F, 0x29, 0x59, 0x50, 0x44, 0x0F, 0x29,
0x61, 0x60, 0x44, 0x0F, 0x29, 0x69, 0x70, 0x44, 0x0F, 0x29, 0xB1, 0x80, 0x00, 0x00, 0x00, 0x44,
0x0F, 0x29, 0xB9, 0x90, 0x00, 0x00, 0x00, 0xFF, 0xE0,
0x48, 0x89, 0x22, /* mov [rdx],rsp */
0x48, 0x8b, 0x21, /* mov rsp,[rcx] */
0x58, /* pop rax */
0x48, 0x89, 0x6a, 0x08, /* mov [rdx+ 8],rbp */
0x48, 0x89, 0x72, 0x10, /* mov [rdx+16],rsi */
0x48, 0x89, 0x7a, 0x18, /* mov [rdx+24],rdi */
0x48, 0x89, 0x5a, 0x20, /* mov [rdx+32],rbx */
0x4c, 0x89, 0x62, 0x28, /* mov [rdx+40],r12 */
0x4c, 0x89, 0x6a, 0x30, /* mov [rdx+48],r13 */
0x4c, 0x89, 0x72, 0x38, /* mov [rdx+56],r14 */
0x4c, 0x89, 0x7a, 0x40, /* mov [rdx+64],r15 */
#if !defined(LIBCO_AMD64_NO_SSE)
0x0f, 0x29, 0x72, 0x50, /* movaps [rdx+ 80],xmm6 */
0x0f, 0x29, 0x7a, 0x60, /* movaps [rdx+ 96],xmm7 */
0x44, 0x0f, 0x29, 0x42, 0x70, /* movaps [rdx+112],xmm8 */
0x48, 0x83, 0xc2, 0x70, /* add rdx,112 */
0x44, 0x0f, 0x29, 0x4a, 0x10, /* movaps [rdx+ 16],xmm9 */
0x44, 0x0f, 0x29, 0x52, 0x20, /* movaps [rdx+ 32],xmm10 */
0x44, 0x0f, 0x29, 0x5a, 0x30, /* movaps [rdx+ 48],xmm11 */
0x44, 0x0f, 0x29, 0x62, 0x40, /* movaps [rdx+ 64],xmm12 */
0x44, 0x0f, 0x29, 0x6a, 0x50, /* movaps [rdx+ 80],xmm13 */
0x44, 0x0f, 0x29, 0x72, 0x60, /* movaps [rdx+ 96],xmm14 */
0x44, 0x0f, 0x29, 0x7a, 0x70, /* movaps [rdx+112],xmm15 */
#endif
0x48, 0x8b, 0x69, 0x08, /* mov rbp,[rcx+ 8] */
0x48, 0x8b, 0x71, 0x10, /* mov rsi,[rcx+16] */
0x48, 0x8b, 0x79, 0x18, /* mov rdi,[rcx+24] */
0x48, 0x8b, 0x59, 0x20, /* mov rbx,[rcx+32] */
0x4c, 0x8b, 0x61, 0x28, /* mov r12,[rcx+40] */
0x4c, 0x8b, 0x69, 0x30, /* mov r13,[rcx+48] */
0x4c, 0x8b, 0x71, 0x38, /* mov r14,[rcx+56] */
0x4c, 0x8b, 0x79, 0x40, /* mov r15,[rcx+64] */
#if !defined(LIBCO_AMD64_NO_SSE)
0x0f, 0x28, 0x71, 0x50, /* movaps xmm6, [rcx+ 80] */
0x0f, 0x28, 0x79, 0x60, /* movaps xmm7, [rcx+ 96] */
0x44, 0x0f, 0x28, 0x41, 0x70, /* movaps xmm8, [rcx+112] */
0x48, 0x83, 0xc1, 0x70, /* add rcx,112 */
0x44, 0x0f, 0x28, 0x49, 0x10, /* movaps xmm9, [rcx+ 16] */
0x44, 0x0f, 0x28, 0x51, 0x20, /* movaps xmm10,[rcx+ 32] */
0x44, 0x0f, 0x28, 0x59, 0x30, /* movaps xmm11,[rcx+ 48] */
0x44, 0x0f, 0x28, 0x61, 0x40, /* movaps xmm12,[rcx+ 64] */
0x44, 0x0f, 0x28, 0x69, 0x50, /* movaps xmm13,[rcx+ 80] */
0x44, 0x0f, 0x28, 0x71, 0x60, /* movaps xmm14,[rcx+ 96] */
0x44, 0x0f, 0x28, 0x79, 0x70, /* movaps xmm15,[rcx+112] */
#endif
0xff, 0xe0, /* jmp rax */
};
#include <windows.h>
@ -42,12 +80,24 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
VirtualProtect(co_swap_function, sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
}
#else
//ABI: SystemV
/* ABI: SystemV */
static unsigned char co_swap_function[] = {
0x48, 0x89, 0x26, 0x48, 0x8B, 0x27, 0x58, 0x48, 0x89, 0x6E, 0x08, 0x48, 0x89, 0x5E, 0x10, 0x4C,
0x89, 0x66, 0x18, 0x4C, 0x89, 0x6E, 0x20, 0x4C, 0x89, 0x76, 0x28, 0x4C, 0x89, 0x7E, 0x30, 0x48,
0x8B, 0x6F, 0x08, 0x48, 0x8B, 0x5F, 0x10, 0x4C, 0x8B, 0x67, 0x18, 0x4C, 0x8B, 0x6F, 0x20, 0x4C,
0x8B, 0x77, 0x28, 0x4C, 0x8B, 0x7F, 0x30, 0xFF, 0xE0,
0x48, 0x89, 0x26, /* mov [rsi],rsp */
0x48, 0x8b, 0x27, /* mov rsp,[rdi] */
0x58, /* pop rax */
0x48, 0x89, 0x6e, 0x08, /* mov [rsi+ 8],rbp */
0x48, 0x89, 0x5e, 0x10, /* mov [rsi+16],rbx */
0x4c, 0x89, 0x66, 0x18, /* mov [rsi+24],r12 */
0x4c, 0x89, 0x6e, 0x20, /* mov [rsi+32],r13 */
0x4c, 0x89, 0x76, 0x28, /* mov [rsi+40],r14 */
0x4c, 0x89, 0x7e, 0x30, /* mov [rsi+48],r15 */
0x48, 0x8b, 0x6f, 0x08, /* mov rbp,[rdi+ 8] */
0x48, 0x8b, 0x5f, 0x10, /* mov rbx,[rdi+16] */
0x4c, 0x8b, 0x67, 0x18, /* mov r12,[rdi+24] */
0x4c, 0x8b, 0x6f, 0x20, /* mov r13,[rdi+32] */
0x4c, 0x8b, 0x77, 0x28, /* mov r14,[rdi+40] */
0x4c, 0x8b, 0x7f, 0x30, /* mov r15,[rdi+48] */
0xff, 0xe0, /* jmp rax */
};
#include <unistd.h>
@ -62,7 +112,7 @@ static void (*co_swap)(cothread_t, cothread_t) = 0;
#endif
static void crash() {
assert(0); /* called only if cothread_t entrypoint returns */
assert(0); /* called only if cothread_t entrypoint returns */
}
cothread_t co_active() {
@ -77,14 +127,14 @@ cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
co_swap = (void (*)(cothread_t, cothread_t))co_swap_function;
}
if(!co_active_handle) co_active_handle = &co_active_buffer;
size += 512; /* allocate additional space for storage */
size &= ~15; /* align stack to 16-byte boundary */
size += 512; /* allocate additional space for storage */
size &= ~15; /* align stack to 16-byte boundary */
if(handle = (cothread_t)malloc(size)) {
long long *p = (long long*)((char*)handle + size); /* seek to top of stack */
*--p = (long long)crash; /* crash if entrypoint returns */
*--p = (long long)entrypoint; /* start of function */
*(long long*)handle = (long long)p; /* stack pointer */
long long *p = (long long*)((char*)handle + size); /* seek to top of stack */
*--p = (long long)crash; /* crash if entrypoint returns */
*--p = (long long)entrypoint; /* start of function */
*(long long*)handle = (long long)p; /* stack pointer */
}
return handle;

71
libco/arm.c Normal file
View File

@ -0,0 +1,71 @@
/*
libco.arm (2015-06-18)
author: byuu
license: public domain
*/
#define LIBCO_C
#include "libco.h"
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#ifdef __cplusplus
extern "C" {
#endif
static thread_local unsigned long co_active_buffer[64];
static thread_local cothread_t co_active_handle = 0;
static void (*co_swap)(cothread_t, cothread_t) = 0;
static unsigned long co_swap_function[] = {
0xe8a16ff0, /* stmia r1!, {r4-r11,sp,lr} */
0xe8b0aff0, /* ldmia r0!, {r4-r11,sp,pc} */
0xe12fff1e, /* bx lr */
};
void co_init() {
unsigned long addr = (unsigned long)co_swap_function;
unsigned long base = addr - (addr % sysconf(_SC_PAGESIZE));
unsigned long size = (addr - base) + sizeof co_swap_function;
mprotect((void*)base, size, PROT_READ | PROT_WRITE | PROT_EXEC);
}
cothread_t co_active() {
if(!co_active_handle) co_active_handle = &co_active_buffer;
return co_active_handle;
}
cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
unsigned long* handle = 0;
if(!co_swap) {
co_init();
co_swap = (void (*)(cothread_t, cothread_t))co_swap_function;
}
if(!co_active_handle) co_active_handle = &co_active_buffer;
size += 256;
size &= ~15;
if(handle = (unsigned long*)malloc(size)) {
unsigned long* p = (unsigned long*)((unsigned char*)handle + size);
handle[8] = (unsigned long)p;
handle[9] = (unsigned long)entrypoint;
}
return handle;
}
void co_delete(cothread_t handle) {
free(handle);
}
void co_switch(cothread_t handle) {
cothread_t co_previous_handle = co_active_handle;
co_swap(co_active_handle = handle, co_previous_handle);
}
#ifdef __cplusplus
}
#endif

View File

@ -6,9 +6,9 @@
#define LIBCO_C
#include "libco.h"
#define WINVER 0x0400
#define _WIN32_WINNT 0x0400
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifdef __cplusplus

View File

@ -1,23 +1,30 @@
/*
libco
auto-selection module
license: public domain
*/
#if defined(__GNUC__) && defined(__i386__)
#include "x86.c"
#elif defined(__GNUC__) && defined(__amd64__)
#include "amd64.c"
#elif defined(__GNUC__) && defined(_ARCH_PPC)
#include "ppc.c"
#elif defined(__GNUC__)
#include "sjlj.c"
#elif defined(_MSC_VER) && defined(_M_IX86)
#include "x86.c"
#elif defined(_MSC_VER) && defined(_M_AMD64)
#include "amd64.c"
#if defined(__clang__) || defined(__GNUC__)
#if defined(__i386__)
#include "x86.c"
#elif defined(__amd64__)
#include "amd64.c"
#elif defined(__arm__)
#include "arm.c"
#elif defined(_ARCH_PPC)
#include "ppc.c"
#elif defined(_WIN32)
#include "fiber.c"
#else
#include "sjlj.c"
#endif
#elif defined(_MSC_VER)
#include "fiber.c"
#if defined(_M_IX86)
#include "x86.c"
#elif defined(_M_AMD64)
#include "amd64.c"
#else
#include "fiber.c"
#endif
#else
#error "libco: unsupported processor, compiler or operating system"
#endif

View File

@ -1,6 +1,7 @@
/*
libco
version: 0.16 (2010-12-24)
version: 0.17 (2015-06-18)
author: byuu
license: public domain
*/

View File

@ -9,6 +9,7 @@ floating-point and AltiVec save/restore */
#define LIBCO_C
#include "libco.h"
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

View File

@ -13,6 +13,7 @@
#define LIBCO_C
#include "libco.h"
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>

View File

@ -6,6 +6,7 @@
#define LIBCO_C
#include "libco.h"
#include <assert.h>
#include <stdlib.h>
@ -13,10 +14,10 @@
extern "C" {
#endif
#if defined(_MSC_VER)
#define fastcall __fastcall
#elif defined(__GNUC__)
#if defined(__clang__) || defined(__GNUC__)
#define fastcall __attribute__((fastcall))
#elif defined(_MSC_VER)
#define fastcall __fastcall
#else
#error "libco: please define fastcall macro"
#endif
@ -25,10 +26,20 @@ static thread_local long co_active_buffer[64];
static thread_local cothread_t co_active_handle = 0;
static void (fastcall *co_swap)(cothread_t, cothread_t) = 0;
//ABI: fastcall
/* ABI: fastcall */
static unsigned char co_swap_function[] = {
0x89, 0x22, 0x8B, 0x21, 0x58, 0x89, 0x6A, 0x04, 0x89, 0x72, 0x08, 0x89, 0x7A, 0x0C, 0x89, 0x5A,
0x10, 0x8B, 0x69, 0x04, 0x8B, 0x71, 0x08, 0x8B, 0x79, 0x0C, 0x8B, 0x59, 0x10, 0xFF, 0xE0,
0x89, 0x22, /* mov [edx],esp */
0x8b, 0x21, /* mov esp,[ecx] */
0x58, /* pop eax */
0x89, 0x6a, 0x04, /* mov [edx+ 4],ebp */
0x89, 0x72, 0x08, /* mov [edx+ 8],esi */
0x89, 0x7a, 0x0c, /* mov [edx+12],edi */
0x89, 0x5a, 0x10, /* mov [edx+16],ebx */
0x8b, 0x69, 0x04, /* mov ebp,[ecx+ 4] */
0x8b, 0x71, 0x08, /* mov esi,[ecx+ 8] */
0x8b, 0x79, 0x0c, /* mov edi,[ecx+12] */
0x8b, 0x59, 0x10, /* mov ebx,[ecx+16] */
0xff, 0xe0, /* jmp eax */
};
#ifdef _WIN32
@ -51,7 +62,7 @@ static unsigned char co_swap_function[] = {
#endif
static void crash() {
assert(0); /* called only if cothread_t entrypoint returns */
assert(0); /* called only if cothread_t entrypoint returns */
}
cothread_t co_active() {
@ -66,14 +77,14 @@ cothread_t co_create(unsigned int size, void (*entrypoint)(void)) {
co_swap = (void (fastcall*)(cothread_t, cothread_t))co_swap_function;
}
if(!co_active_handle) co_active_handle = &co_active_buffer;
size += 256; /* allocate additional space for storage */
size &= ~15; /* align stack to 16-byte boundary */
size += 256; /* allocate additional space for storage */
size &= ~15; /* align stack to 16-byte boundary */
if(handle = (cothread_t)malloc(size)) {
long *p = (long*)((char*)handle + size); /* seek to top of stack */
*--p = (long)crash; /* crash if entrypoint returns */
*--p = (long)entrypoint; /* start of function */
*(long*)handle = (long)p; /* stack pointer */
long *p = (long*)((char*)handle + size); /* seek to top of stack */
*--p = (long)crash; /* crash if entrypoint returns */
*--p = (long)entrypoint; /* start of function */
*(long*)handle = (long)p; /* stack pointer */
}
return handle;

View File

@ -8,11 +8,11 @@
#include <nall/string.hpp>
#include <nall/utility.hpp>
#if defined(PLATFORM_XORG) || defined(PLATFORM_MACOSX)
#include <dlfcn.h>
#elif defined(PLATFORM_WINDOWS)
#if defined(PLATFORM_WINDOWS)
#include <windows.h>
#include <nall/windows/utf8.hpp>
#else
#include <dlfcn.h>
#endif
namespace nall {
@ -35,7 +35,7 @@ private:
uintptr_t handle = 0;
};
#if defined(PLATFORM_XORG)
#if defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
inline bool library::open(const string& name, const string& path) {
if(handle) close();
if(path) handle = (uintptr_t)dlopen(string(path, "lib", name, ".so"), RTLD_LAZY);

View File

@ -2,19 +2,21 @@
#define NALL_INTRINSICS_HPP
namespace nall {
struct Intrinsics {
enum class Compiler : unsigned { Clang, GCC, VisualCPP, Unknown };
enum class Platform : unsigned { Windows, MacOSX, Linux, BSD, Unknown };
enum class API : unsigned { Windows, Posix, Unknown };
enum class Display : unsigned { Windows, Quartz, Xorg, Unknown };
enum class Processor : unsigned { x86, amd64, ARM, PPC32, PPC64, Unknown };
enum class Endian : unsigned { LSB, MSB, Unknown };
struct Intrinsics {
enum class Compiler : unsigned { Clang, GCC, CL, Unknown };
enum class Platform : unsigned { Windows, MacOSX, Linux, BSD, Unknown };
enum class Architecture : unsigned { x86, amd64, Unknown };
enum class Endian : unsigned { LSB, MSB, Unknown };
static inline Compiler compiler();
static inline Platform platform();
static inline Architecture architecture();
static inline Endian endian();
};
static inline auto compiler() -> Compiler;
static inline auto platform() -> Platform;
static inline auto api() -> API;
static inline auto display() -> Display;
static inline auto processor() -> Processor;
static inline auto endian() -> Endian;
};
}
/* Compiler detection */
@ -23,7 +25,7 @@ namespace nall {
#if defined(__clang__)
#define COMPILER_CLANG
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Clang; }
auto Intrinsics::compiler() -> Compiler { return Compiler::Clang; }
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wempty-body"
@ -34,16 +36,16 @@ namespace nall {
#pragma clang diagnostic ignored "-Wtautological-compare"
#elif defined(__GNUC__)
#define COMPILER_GCC
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::GCC; }
auto Intrinsics::compiler() -> Compiler { return Compiler::GCC; }
#elif defined(_MSC_VER)
#define COMPILER_CL
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::CL; }
#define COMPILER_VISUALCPP
auto Intrinsics::compiler() -> Compiler { return Compiler::VisualCPP; }
#pragma warning(disable:4996) //disable libc "deprecation" warnings
#else
#warning "unable to detect compiler"
#define COMPILER_UNKNOWN
Intrinsics::Compiler Intrinsics::compiler() { return Intrinsics::Compiler::Unknown; }
auto Intrinsics::compiler() -> Compiler { return Compiler::Unknown; }
#endif
}
@ -54,31 +56,44 @@ namespace nall {
#if defined(_WIN32)
#define PLATFORM_WINDOWS
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Windows; }
#define API_WINDOWS
#define DISPLAY_WINDOW
auto Intrinsics::platform() -> Platform { return Platform::Windows; }
auto Intrinsics::api() -> API { return API::Windows; }
auto Intrinsics::display() -> Display { return Display::Windows; }
#elif defined(__APPLE__)
#define PLATFORM_POSIX
#define PLATFORM_MACOSX
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::MacOSX; }
#define API_POSIX
#define DISPLAY_QUARTZ
auto Intrinsics::platform() -> Platform { return Platform::MacOSX; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Quartz; }
#elif defined(linux) || defined(__linux__)
#define PLATFORM_POSIX
#define PLATFORM_LINUX
#define PLATFORM_XORG
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Linux; }
#define API_POSIX
#define DISPLAY_XORG
auto Intrinsics::platform() -> Platform { return Platform::Linux; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Xorg; }
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__)
#define PLATFORM_POSIX
#define PLATFORM_BSD
#define PLATFORM_XORG
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::BSD; }
#define API_POSIX
#define DISPLAY_XORG
auto Intrinsics::platform() -> Platform { return Platform::BSD; }
auto Intrinsics::api() -> API { return API::Posix; }
auto Intrinsics::display() -> Display { return Display::Xorg; }
#else
#warning "unable to detect platform"
#define PLATFORM_UNKNOWN
Intrinsics::Platform Intrinsics::platform() { return Intrinsics::Platform::Unknown; }
#define API_UNKNOWN
#define DISPLAY_UNKNOWN
auto Intrinsics::platform() -> Platform { return Platform::Unknown; }
auto Intrinsics::api() -> API { return API::Unknown; }
auto Intrinsics::display() -> Display { return Display::Unknown; }
#endif
}
/* Architecture Detection */
#if defined(PLATFORM_MACOSX)
#include <machine/endian.h>
#elif defined(PLATFORM_LINUX)
@ -87,18 +102,29 @@ namespace nall {
#include <sys/endian.h>
#endif
/* Processor Detection */
namespace nall {
#if defined(__i386__) || defined(_M_IX86)
#define ARCH_X86
Intrinsics::Architecture Intrinsics::architecture() { return Intrinsics::Architecture::x86; }
#define PROCESSOR_X86
auto Intrinsics::processor() -> Processor { return Processor::x86; }
#elif defined(__amd64__) || defined(_M_AMD64)
#define ARCH_AMD64
Intrinsics::Architecture Intrinsics::architecture() { return Intrinsics::Architecture::amd64; }
#define PROCESSOR_AMD64
auto Intrinsics::processor() -> Processor { return Processor::amd64; }
#elif defined(__arm__)
#define PROCESSOR_ARM
auto Intrinsics::processor() -> Processor { return Processor::ARM; }
#elif defined(__ppc64__) || defined(_ARCH_PPC64)
#define PROCESSOR_PPC64
auto Intrinsics::processor() -> Processor { return Processor::PPC64; }
#elif defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC)
#define PROCESSOR_PPC32
auto Intrinsics::processor() -> Processor { return Processor::PPC32; }
#else
#warning "unable to detect architecture"
#define ARCH_UNKNOWN
Intrinsics::Architecture Intrinsics::architecture() { return Intrinsics::Architecture::Unknown; }
#warning "unable to detect processor"
#define PROCESSOR_UNKNOWN
auto Intrinsics::processor() -> Processor { return Processor::Unknown; }
#endif
}
@ -109,14 +135,14 @@ namespace nall {
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64)
#define ENDIAN_LSB
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::LSB; }
auto Intrinsics::endian() -> Endian { return Endian::LSB; }
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(__powerpc__) || defined(_M_PPC)
#define ENDIAN_MSB
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::MSB; }
auto Intrinsics::endian() -> Endian { return Endian::MSB; }
#else
#warning "unable to detect endian"
#define ENDIAN_UNKNOWN
Intrinsics::Endian Intrinsics::endian() { return Intrinsics::Endian::Unknown; }
auto Intrinsics::endian() -> Endian { return Endian::Unknown; }
#endif
}

View File

@ -1,7 +1,7 @@
#ifndef NALL_INVOKE_HPP
#define NALL_INVOKE_HPP
//void invoke(const string &name, const string& args...);
//auto invoke(const string &name, const string& args...) -> void;
//if a program is specified, it is executed with the arguments provided
//if a file is specified, the file is opened using the program associated with said file type
//if a folder is specified, the folder is opened using the associated file explorer
@ -20,16 +20,16 @@ namespace nall {
#if defined(PLATFORM_WINDOWS)
template<typename... Args> inline void invoke(const string& name, Args&&... args) {
template<typename... Args> inline auto invoke(const string& name, Args&&... args) -> void {
lstring argl(std::forward<Args>(args)...);
for(auto& arg : argl) if(arg.find(" ")) arg = {"\"", arg, "\""};
string arguments = argl.merge(" ");
ShellExecuteW(NULL, NULL, utf16_t(name), utf16_t(arguments), NULL, SW_SHOWNORMAL);
}
#elif defined(PLATFORM_XORG)
#elif defined(PLATFORM_LINUX) || defined(PLATFORM_BSD)
template<typename... Args> inline void invoke(const string& name, Args&&... args) {
template<typename... Args> inline auto invoke(const string& name, Args&&... args) -> void {
pid_t pid = fork();
if(pid == 0) {
const char* argv[1 + sizeof...(args) + 1];
@ -48,7 +48,7 @@ template<typename... Args> inline void invoke(const string& name, Args&&... args
#else
template<typename... Args> inline void invoke(const string& name, Args&&... args) {
template<typename... Args> inline auto invoke(const string& name, Args&&... args) -> void {
}
#endif

View File

@ -10,7 +10,7 @@ namespace nall {
auto main(int argc, char** argv) -> int {
#if defined(PLATFORM_WINDOWS)
CoInitialize(0);
WSAData wsaData = {0};
WSAData wsaData{0};
WSAStartup(MAKEWORD(2, 2), &wsaData);
utf8_args(argc, argv);
#endif

View File

@ -70,7 +70,7 @@
#include <nall/windows/utf8.hpp>
#endif
#if defined(PLATFORM_XORG)
#if defined(API_POSIX)
#include <nall/serial.hpp>
#endif

View File

@ -54,7 +54,7 @@ namespace Math {
#include <poll.h>
#endif
#if defined(COMPILER_CL)
#if defined(COMPILER_VISUALCPP)
#define va_copy(dest, src) ((dest) = (src))
#endif
@ -101,7 +101,7 @@ namespace Math {
#define neverinline __attribute__((noinline))
#define alwaysinline inline __attribute__((always_inline))
#define deprecated __attribute__((deprecated))
#elif defined(COMPILER_CL)
#elif defined(COMPILER_VISUALCPP)
#define neverinline __declspec(noinline)
#define alwaysinline inline __forceinline
#define deprecated __declspec(deprecated)

View File

@ -5,8 +5,8 @@
#include <nall/stdint.hpp>
#include <nall/string.hpp>
#if !defined(PLATFORM_XORG) && !defined(PLATFORM_MACOSX)
#error "nall/serial: unsupported platform"
#if !defined(API_POSIX)
#error "nall/serial: unsupported system"
#endif
#include <sys/ioctl.h>

View File

@ -5,11 +5,11 @@
#include <nall/shared-memory.hpp>
#if defined(PLATFORM_POSIX)
#if defined(API_POSIX)
#include <nall/posix/service.hpp>
#endif
#if defined(PLATFORM_WINDOWS)
#if defined(API_WINDOWS)
#include <nall/windows/service.hpp>
#endif

View File

@ -4,11 +4,11 @@
#include <nall/memory.hpp>
#include <nall/string.hpp>
#if defined(PLATFORM_POSIX)
#if defined(API_POSIX)
#include <nall/posix/shared-memory.hpp>
#endif
#if defined(PLATFORM_WINDOWS)
#if defined(API_WINDOWS)
#include <nall/windows/shared-memory.hpp>
#endif

View File

@ -11,7 +11,7 @@
#include <nall/function.hpp>
#include <nall/intrinsics.hpp>
#if defined(PLATFORM_BSD) || defined(PLATFORM_LINUX) || defined(PLATFORM_MACOSX)
#if defined(API_POSIX)
#include <pthread.h>
@ -69,7 +69,7 @@ auto thread::exit() -> void {
}
#elif defined(PLATFORM_WINDOWS)
#elif defined(API_WINDOWS)
namespace nall {

View File

@ -1,4 +1,4 @@
inline void R65816::op_adc_b() {
auto R65816::op_adc_b() {
int result;
if(!regs.p.d) {
@ -19,7 +19,7 @@ inline void R65816::op_adc_b() {
regs.a.l = result;
}
inline void R65816::op_adc_w() {
auto R65816::op_adc_w() {
int result;
if(!regs.p.d) {
@ -46,133 +46,133 @@ inline void R65816::op_adc_w() {
regs.a.w = result;
}
inline void R65816::op_and_b() {
auto R65816::op_and_b() {
regs.a.l &= rd.l;
regs.p.n = regs.a.l & 0x80;
regs.p.z = regs.a.l == 0;
}
inline void R65816::op_and_w() {
auto R65816::op_and_w() {
regs.a.w &= rd.w;
regs.p.n = regs.a.w & 0x8000;
regs.p.z = regs.a.w == 0;
}
inline void R65816::op_bit_b() {
auto R65816::op_bit_b() {
regs.p.n = rd.l & 0x80;
regs.p.v = rd.l & 0x40;
regs.p.z = (rd.l & regs.a.l) == 0;
}
inline void R65816::op_bit_w() {
auto R65816::op_bit_w() {
regs.p.n = rd.w & 0x8000;
regs.p.v = rd.w & 0x4000;
regs.p.z = (rd.w & regs.a.w) == 0;
}
inline void R65816::op_cmp_b() {
auto R65816::op_cmp_b() {
int r = regs.a.l - rd.l;
regs.p.n = r & 0x80;
regs.p.z = (uint8)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_cmp_w() {
auto R65816::op_cmp_w() {
int r = regs.a.w - rd.w;
regs.p.n = r & 0x8000;
regs.p.z = (uint16)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_cpx_b() {
auto R65816::op_cpx_b() {
int r = regs.x.l - rd.l;
regs.p.n = r & 0x80;
regs.p.z = (uint8)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_cpx_w() {
auto R65816::op_cpx_w() {
int r = regs.x.w - rd.w;
regs.p.n = r & 0x8000;
regs.p.z = (uint16)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_cpy_b() {
auto R65816::op_cpy_b() {
int r = regs.y.l - rd.l;
regs.p.n = r & 0x80;
regs.p.z = (uint8)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_cpy_w() {
auto R65816::op_cpy_w() {
int r = regs.y.w - rd.w;
regs.p.n = r & 0x8000;
regs.p.z = (uint16)r == 0;
regs.p.c = r >= 0;
}
inline void R65816::op_eor_b() {
auto R65816::op_eor_b() {
regs.a.l ^= rd.l;
regs.p.n = regs.a.l & 0x80;
regs.p.z = regs.a.l == 0;
}
inline void R65816::op_eor_w() {
auto R65816::op_eor_w() {
regs.a.w ^= rd.w;
regs.p.n = regs.a.w & 0x8000;
regs.p.z = regs.a.w == 0;
}
inline void R65816::op_lda_b() {
auto R65816::op_lda_b() {
regs.a.l = rd.l;
regs.p.n = regs.a.l & 0x80;
regs.p.z = regs.a.l == 0;
}
inline void R65816::op_lda_w() {
auto R65816::op_lda_w() {
regs.a.w = rd.w;
regs.p.n = regs.a.w & 0x8000;
regs.p.z = regs.a.w == 0;
}
inline void R65816::op_ldx_b() {
auto R65816::op_ldx_b() {
regs.x.l = rd.l;
regs.p.n = regs.x.l & 0x80;
regs.p.z = regs.x.l == 0;
}
inline void R65816::op_ldx_w() {
auto R65816::op_ldx_w() {
regs.x.w = rd.w;
regs.p.n = regs.x.w & 0x8000;
regs.p.z = regs.x.w == 0;
}
inline void R65816::op_ldy_b() {
auto R65816::op_ldy_b() {
regs.y.l = rd.l;
regs.p.n = regs.y.l & 0x80;
regs.p.z = regs.y.l == 0;
}
inline void R65816::op_ldy_w() {
auto R65816::op_ldy_w() {
regs.y.w = rd.w;
regs.p.n = regs.y.w & 0x8000;
regs.p.z = regs.y.w == 0;
}
inline void R65816::op_ora_b() {
auto R65816::op_ora_b() {
regs.a.l |= rd.l;
regs.p.n = regs.a.l & 0x80;
regs.p.z = regs.a.l == 0;
}
inline void R65816::op_ora_w() {
auto R65816::op_ora_w() {
regs.a.w |= rd.w;
regs.p.n = regs.a.w & 0x8000;
regs.p.z = regs.a.w == 0;
}
inline void R65816::op_sbc_b() {
auto R65816::op_sbc_b() {
int result;
rd.l ^= 0xff;
@ -194,7 +194,7 @@ inline void R65816::op_sbc_b() {
regs.a.l = result;
}
inline void R65816::op_sbc_w() {
auto R65816::op_sbc_w() {
int result;
rd.w ^= 0xffff;
@ -222,59 +222,59 @@ inline void R65816::op_sbc_w() {
regs.a.w = result;
}
inline void R65816::op_inc_b() {
auto R65816::op_inc_b() {
rd.l++;
regs.p.n = rd.l & 0x80;
regs.p.z = rd.l == 0;
}
inline void R65816::op_inc_w() {
auto R65816::op_inc_w() {
rd.w++;
regs.p.n = rd.w & 0x8000;
regs.p.z = rd.w == 0;
}
inline void R65816::op_dec_b() {
auto R65816::op_dec_b() {
rd.l--;
regs.p.n = rd.l & 0x80;
regs.p.z = rd.l == 0;
}
inline void R65816::op_dec_w() {
auto R65816::op_dec_w() {
rd.w--;
regs.p.n = rd.w & 0x8000;
regs.p.z = rd.w == 0;
}
inline void R65816::op_asl_b() {
auto R65816::op_asl_b() {
regs.p.c = rd.l & 0x80;
rd.l <<= 1;
regs.p.n = rd.l & 0x80;
regs.p.z = rd.l == 0;
}
inline void R65816::op_asl_w() {
auto R65816::op_asl_w() {
regs.p.c = rd.w & 0x8000;
rd.w <<= 1;
regs.p.n = rd.w & 0x8000;
regs.p.z = rd.w == 0;
}
inline void R65816::op_lsr_b() {
auto R65816::op_lsr_b() {
regs.p.c = rd.l & 1;
rd.l >>= 1;
regs.p.n = rd.l & 0x80;
regs.p.z = rd.l == 0;
}
inline void R65816::op_lsr_w() {
auto R65816::op_lsr_w() {
regs.p.c = rd.w & 1;
rd.w >>= 1;
regs.p.n = rd.w & 0x8000;
regs.p.z = rd.w == 0;
}
inline void R65816::op_rol_b() {
auto R65816::op_rol_b() {
unsigned carry = (unsigned)regs.p.c;
regs.p.c = rd.l & 0x80;
rd.l = (rd.l << 1) | carry;
@ -282,7 +282,7 @@ inline void R65816::op_rol_b() {
regs.p.z = rd.l == 0;
}
inline void R65816::op_rol_w() {
auto R65816::op_rol_w() {
unsigned carry = (unsigned)regs.p.c;
regs.p.c = rd.w & 0x8000;
rd.w = (rd.w << 1) | carry;
@ -290,7 +290,7 @@ inline void R65816::op_rol_w() {
regs.p.z = rd.w == 0;
}
inline void R65816::op_ror_b() {
auto R65816::op_ror_b() {
unsigned carry = (unsigned)regs.p.c << 7;
regs.p.c = rd.l & 1;
rd.l = carry | (rd.l >> 1);
@ -298,7 +298,7 @@ inline void R65816::op_ror_b() {
regs.p.z = rd.l == 0;
}
inline void R65816::op_ror_w() {
auto R65816::op_ror_w() {
unsigned carry = (unsigned)regs.p.c << 15;
regs.p.c = rd.w & 1;
rd.w = carry | (rd.w >> 1);
@ -306,22 +306,22 @@ inline void R65816::op_ror_w() {
regs.p.z = rd.w == 0;
}
inline void R65816::op_trb_b() {
auto R65816::op_trb_b() {
regs.p.z = (rd.l & regs.a.l) == 0;
rd.l &= ~regs.a.l;
}
inline void R65816::op_trb_w() {
auto R65816::op_trb_w() {
regs.p.z = (rd.w & regs.a.w) == 0;
rd.w &= ~regs.a.w;
}
inline void R65816::op_tsb_b() {
auto R65816::op_tsb_b() {
regs.p.z = (rd.l & regs.a.l) == 0;
rd.l |= regs.a.l;
}
inline void R65816::op_tsb_w() {
auto R65816::op_tsb_w() {
regs.p.z = (rd.w & regs.a.w) == 0;
rd.w |= regs.a.w;
}

View File

@ -1,4 +1,4 @@
uint8 R65816::dreadb(uint32 addr) {
auto R65816::dreadb(uint32 addr) -> uint8 {
if((addr & 0x40ffff) >= 0x2000 && (addr & 0x40ffff) <= 0x5fff) {
//$[00-3f|80-bf]:[2000-5fff]
//do not read MMIO registers within debugger
@ -7,14 +7,14 @@ uint8 R65816::dreadb(uint32 addr) {
return disassembler_read(addr);
}
uint16 R65816::dreadw(uint32 addr) {
auto R65816::dreadw(uint32 addr) -> uint16 {
uint16 r;
r = dreadb((addr + 0) & 0xffffff) << 0;
r |= dreadb((addr + 1) & 0xffffff) << 8;
return r;
}
uint32 R65816::dreadl(uint32 addr) {
auto R65816::dreadl(uint32 addr) -> uint32 {
uint32 r;
r = dreadb((addr + 0) & 0xffffff) << 0;
r |= dreadb((addr + 1) & 0xffffff) << 8;
@ -22,7 +22,7 @@ uint32 R65816::dreadl(uint32 addr) {
return r;
}
uint32 R65816::decode(uint8 offset_type, uint32 addr) {
auto R65816::decode(uint8 offset_type, uint32 addr) -> uint32 {
uint32 r = 0;
switch(offset_type) {
@ -102,11 +102,11 @@ uint32 R65816::decode(uint8 offset_type, uint32 addr) {
return(r & 0xffffff);
}
void R65816::disassemble_opcode(char* output) {
auto R65816::disassemble_opcode(char* output) -> void {
return disassemble_opcode(output, regs.pc.d, regs.e, regs.p.m, regs.p.x);
}
void R65816::disassemble_opcode(char* output, uint32 addr, bool e, bool m, bool x) {
auto R65816::disassemble_opcode(char* output, uint32 addr, bool e, bool m, bool x) -> void {
static reg24_t pc;
char t[256];
char* s = output;

View File

@ -22,9 +22,9 @@ enum : unsigned {
OPTYPE_RELW, //relw
};
void disassemble_opcode(char* output);
void disassemble_opcode(char* output, uint32 addr, bool e, bool m, bool x);
uint8 dreadb(uint32 addr);
uint16 dreadw(uint32 addr);
uint32 dreadl(uint32 addr);
uint32 decode(uint8 offset_type, uint32 addr);
auto disassemble_opcode(char* output) -> void;
auto disassemble_opcode(char* output, uint32 addr, bool e, bool m, bool x) -> void;
auto dreadb(uint32 addr) -> uint8;
auto dreadw(uint32 addr) -> uint16;
auto dreadl(uint32 addr) -> uint32;
auto decode(uint8 offset_type, uint32 addr) -> uint32;

View File

@ -1,33 +1,33 @@
alwaysinline uint8 op_readpc() {
alwaysinline auto op_readpc() -> uint8 {
return op_read((regs.pc.b << 16) + regs.pc.w++);
}
alwaysinline uint8 op_readstack() {
alwaysinline auto op_readstack() -> uint8 {
regs.e ? regs.s.l++ : regs.s.w++;
return op_read(regs.s.w);
}
alwaysinline uint8 op_readstackn() {
alwaysinline auto op_readstackn() -> uint8 {
return op_read(++regs.s.w);
}
alwaysinline uint8 op_readaddr(uint32 addr) {
alwaysinline auto op_readaddr(uint32 addr) -> uint8 {
return op_read(addr & 0xffff);
}
alwaysinline uint8 op_readlong(uint32 addr) {
alwaysinline auto op_readlong(uint32 addr) -> uint8 {
return op_read(addr & 0xffffff);
}
alwaysinline uint8 op_readdbr(uint32 addr) {
alwaysinline auto op_readdbr(uint32 addr) -> uint8 {
return op_read(((regs.db << 16) + addr) & 0xffffff);
}
alwaysinline uint8 op_readpbr(uint32 addr) {
alwaysinline auto op_readpbr(uint32 addr) -> uint8 {
return op_read((regs.pc.b << 16) + (addr & 0xffff));
}
alwaysinline uint8 op_readdp(uint32 addr) {
alwaysinline auto op_readdp(uint32 addr) -> uint8 {
if(regs.e && regs.d.l == 0x00) {
return op_read((regs.d & 0xff00) + ((regs.d + (addr & 0xffff)) & 0xff));
} else {
@ -35,36 +35,36 @@ alwaysinline uint8 op_readdp(uint32 addr) {
}
}
alwaysinline uint8 op_readsp(uint32 addr) {
alwaysinline auto op_readsp(uint32 addr) -> uint8 {
return op_read((regs.s + (addr & 0xffff)) & 0xffff);
}
alwaysinline void op_writestack(uint8 data) {
alwaysinline auto op_writestack(uint8 data) -> void {
op_write(regs.s.w, data);
regs.e ? regs.s.l-- : regs.s.w--;
}
alwaysinline void op_writestackn(uint8 data) {
alwaysinline auto op_writestackn(uint8 data) -> void {
op_write(regs.s.w--, data);
}
alwaysinline void op_writeaddr(uint32 addr, uint8 data) {
alwaysinline auto op_writeaddr(uint32 addr, uint8 data) -> void {
op_write(addr & 0xffff, data);
}
alwaysinline void op_writelong(uint32 addr, uint8 data) {
alwaysinline auto op_writelong(uint32 addr, uint8 data) -> void {
op_write(addr & 0xffffff, data);
}
alwaysinline void op_writedbr(uint32 addr, uint8 data) {
alwaysinline auto op_writedbr(uint32 addr, uint8 data) -> void {
op_write(((regs.db << 16) + addr) & 0xffffff, data);
}
alwaysinline void op_writepbr(uint32 addr, uint8 data) {
alwaysinline auto op_writepbr(uint32 addr, uint8 data) -> void {
op_write((regs.pc.b << 16) + (addr & 0xffff), data);
}
alwaysinline void op_writedp(uint32 addr, uint8 data) {
alwaysinline auto op_writedp(uint32 addr, uint8 data) -> void {
if(regs.e && regs.d.l == 0x00) {
op_write((regs.d & 0xff00) + ((regs.d + (addr & 0xffff)) & 0xff), data);
} else {
@ -72,6 +72,6 @@ alwaysinline void op_writedp(uint32 addr, uint8 data) {
}
}
alwaysinline void op_writesp(uint32 addr, uint8 data) {
alwaysinline auto op_writesp(uint32 addr, uint8 data) -> void {
op_write((regs.s + (addr & 0xffff)) & 0xffff, data);
}

View File

@ -1,12 +1,12 @@
void R65816::op_nop() {
auto R65816::op_nop() {
L op_io_irq();
}
void R65816::op_wdm() {
auto R65816::op_wdm() {
L op_readpc();
}
void R65816::op_xba() {
auto R65816::op_xba() {
op_io();
L op_io();
regs.a.l ^= regs.a.h;
@ -16,7 +16,7 @@ L op_io();
regs.p.z = (regs.a.l == 0);
}
template<int adjust> void R65816::op_move_b() {
auto R65816::op_move_b(signed adjust) {
dp = op_readpc();
sp = op_readpc();
regs.db = dp;
@ -29,7 +29,7 @@ L op_io();
if(regs.a.w--) regs.pc.w -= 3;
}
template<int adjust> void R65816::op_move_w() {
auto R65816::op_move_w(signed adjust) {
dp = op_readpc();
sp = op_readpc();
regs.db = dp;
@ -42,40 +42,40 @@ L op_io();
if(regs.a.w--) regs.pc.w -= 3;
}
template<int vectorE, int vectorN> void R65816::op_interrupt_e() {
auto R65816::op_interrupt_e(uint16 vector) {
op_readpc();
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
op_writestack(regs.p);
rd.l = op_readlong(vectorE + 0);
rd.l = op_readlong(vector + 0);
regs.pc.b = 0;
regs.p.i = 1;
regs.p.d = 0;
L rd.h = op_readlong(vectorE + 1);
L rd.h = op_readlong(vector + 1);
regs.pc.w = rd.w;
}
template<int vectorE, int vectorN> void R65816::op_interrupt_n() {
auto R65816::op_interrupt_n(uint16 vector) {
op_readpc();
op_writestack(regs.pc.b);
op_writestack(regs.pc.h);
op_writestack(regs.pc.l);
op_writestack(regs.p);
rd.l = op_readlong(vectorN + 0);
rd.l = op_readlong(vector + 0);
regs.pc.b = 0x00;
regs.p.i = 1;
regs.p.d = 0;
L rd.h = op_readlong(vectorN + 1);
L rd.h = op_readlong(vector + 1);
regs.pc.w = rd.w;
}
void R65816::op_stp() {
auto R65816::op_stp() {
while(regs.wai = true) {
L op_io();
}
}
void R65816::op_wai() {
auto R65816::op_wai() {
regs.wai = true;
while(regs.wai) {
L op_io();
@ -83,40 +83,36 @@ L op_io();
op_io();
}
void R65816::op_xce() {
auto R65816::op_xce() {
L op_io_irq();
bool carry = regs.p.c;
regs.p.c = regs.e;
regs.e = carry;
if(regs.e) {
regs.p |= 0x30;
regs.p.m = 1;
regs.p.x = 1;
regs.x.h = 0x00;
regs.y.h = 0x00;
regs.s.h = 0x01;
}
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
update_table();
}
template<int mask, int value> void R65816::op_flag() {
auto R65816::op_flag(bool& flag, bool value) {
L op_io_irq();
regs.p = (regs.p & ~mask) | value;
flag = value;
}
template<int mode> void R65816::op_pflag_e() {
auto R65816::op_pflag_e(bool mode) {
rd.l = op_readpc();
L op_io();
regs.p = (mode ? regs.p | rd.l : regs.p & ~rd.l);
regs.p |= 0x30;
if(regs.p.x) {
regs.x.h = 0x00;
regs.y.h = 0x00;
}
update_table();
regs.p.m = 1;
regs.p.x = 1;
regs.x.h = 0x00;
regs.y.h = 0x00;
}
template<int mode> void R65816::op_pflag_n() {
auto R65816::op_pflag_n(bool mode) {
rd.l = op_readpc();
L op_io();
regs.p = (mode ? regs.p | rd.l : regs.p & ~rd.l);
@ -124,114 +120,113 @@ L op_io();
regs.x.h = 0x00;
regs.y.h = 0x00;
}
update_table();
}
template<int from, int to> void R65816::op_transfer_b() {
auto R65816::op_transfer_b(reg16_t& from, reg16_t& to) {
L op_io_irq();
regs.r[to].l = regs.r[from].l;
regs.p.n = (regs.r[to].l & 0x80);
regs.p.z = (regs.r[to].l == 0);
to.l = from.l;
regs.p.n = (to.l & 0x80);
regs.p.z = (to.l == 0);
}
template<int from, int to> void R65816::op_transfer_w() {
auto R65816::op_transfer_w(reg16_t& from, reg16_t& to) {
L op_io_irq();
regs.r[to].w = regs.r[from].w;
regs.p.n = (regs.r[to].w & 0x8000);
regs.p.z = (regs.r[to].w == 0);
to.w = from.w;
regs.p.n = (to.w & 0x8000);
regs.p.z = (to.w == 0);
}
void R65816::op_tcs_e() {
auto R65816::op_tcs_e() {
L op_io_irq();
regs.s.l = regs.a.l;
}
void R65816::op_tcs_n() {
auto R65816::op_tcs_n() {
L op_io_irq();
regs.s.w = regs.a.w;
}
void R65816::op_tsx_b() {
auto R65816::op_tsx_b() {
L op_io_irq();
regs.x.l = regs.s.l;
regs.p.n = (regs.x.l & 0x80);
regs.p.z = (regs.x.l == 0);
}
void R65816::op_tsx_w() {
auto R65816::op_tsx_w() {
L op_io_irq();
regs.x.w = regs.s.w;
regs.p.n = (regs.x.w & 0x8000);
regs.p.z = (regs.x.w == 0);
}
void R65816::op_txs_e() {
auto R65816::op_txs_e() {
L op_io_irq();
regs.s.l = regs.x.l;
}
void R65816::op_txs_n() {
auto R65816::op_txs_n() {
L op_io_irq();
regs.s.w = regs.x.w;
}
template<int n> void R65816::op_push_b() {
auto R65816::op_push_b(reg16_t& reg) {
op_io();
L op_writestack(regs.r[n].l);
L op_writestack(reg.l);
}
template<int n> void R65816::op_push_w() {
auto R65816::op_push_w(reg16_t& reg) {
op_io();
op_writestack(regs.r[n].h);
L op_writestack(regs.r[n].l);
op_writestack(reg.h);
L op_writestack(reg.l);
}
void R65816::op_phd_e() {
auto R65816::op_phd_e() {
op_io();
op_writestackn(regs.d.h);
L op_writestackn(regs.d.l);
regs.s.h = 0x01;
}
void R65816::op_phd_n() {
auto R65816::op_phd_n() {
op_io();
op_writestackn(regs.d.h);
L op_writestackn(regs.d.l);
}
void R65816::op_phb() {
auto R65816::op_phb() {
op_io();
L op_writestack(regs.db);
}
void R65816::op_phk() {
auto R65816::op_phk() {
op_io();
L op_writestack(regs.pc.b);
}
void R65816::op_php() {
auto R65816::op_php() {
op_io();
L op_writestack(regs.p);
}
template<int n> void R65816::op_pull_b() {
auto R65816::op_pull_b(reg16_t& reg) {
op_io();
op_io();
L regs.r[n].l = op_readstack();
regs.p.n = (regs.r[n].l & 0x80);
regs.p.z = (regs.r[n].l == 0);
L reg.l = op_readstack();
regs.p.n = (reg.l & 0x80);
regs.p.z = (reg.l == 0);
}
template<int n> void R65816::op_pull_w() {
auto R65816::op_pull_w(reg16_t& reg) {
op_io();
op_io();
regs.r[n].l = op_readstack();
L regs.r[n].h = op_readstack();
regs.p.n = (regs.r[n].w & 0x8000);
regs.p.z = (regs.r[n].w == 0);
reg.l = op_readstack();
L reg.h = op_readstack();
regs.p.n = (reg.w & 0x8000);
regs.p.z = (reg.w == 0);
}
void R65816::op_pld_e() {
auto R65816::op_pld_e() {
op_io();
op_io();
regs.d.l = op_readstackn();
@ -241,7 +236,7 @@ L regs.d.h = op_readstackn();
regs.s.h = 0x01;
}
void R65816::op_pld_n() {
auto R65816::op_pld_n() {
op_io();
op_io();
regs.d.l = op_readstackn();
@ -250,7 +245,7 @@ L regs.d.h = op_readstackn();
regs.p.z = (regs.d.w == 0);
}
void R65816::op_plb() {
auto R65816::op_plb() {
op_io();
op_io();
L regs.db = op_readstack();
@ -258,7 +253,7 @@ L regs.db = op_readstack();
regs.p.z = (regs.db == 0);
}
void R65816::op_plp_e() {
auto R65816::op_plp_e() {
op_io();
op_io();
L regs.p = op_readstack() | 0x30;
@ -266,10 +261,9 @@ L regs.p = op_readstack() | 0x30;
regs.x.h = 0x00;
regs.y.h = 0x00;
}
update_table();
}
void R65816::op_plp_n() {
auto R65816::op_plp_n() {
op_io();
op_io();
L regs.p = op_readstack();
@ -277,10 +271,9 @@ L regs.p = op_readstack();
regs.x.h = 0x00;
regs.y.h = 0x00;
}
update_table();
}
void R65816::op_pea_e() {
auto R65816::op_pea_e() {
aa.l = op_readpc();
aa.h = op_readpc();
op_writestackn(aa.h);
@ -288,14 +281,14 @@ L op_writestackn(aa.l);
regs.s.h = 0x01;
}
void R65816::op_pea_n() {
auto R65816::op_pea_n() {
aa.l = op_readpc();
aa.h = op_readpc();
op_writestackn(aa.h);
L op_writestackn(aa.l);
}
void R65816::op_pei_e() {
auto R65816::op_pei_e() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -305,7 +298,7 @@ L op_writestackn(aa.l);
regs.s.h = 0x01;
}
void R65816::op_pei_n() {
auto R65816::op_pei_n() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -314,7 +307,7 @@ void R65816::op_pei_n() {
L op_writestackn(aa.l);
}
void R65816::op_per_e() {
auto R65816::op_per_e() {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@ -324,7 +317,7 @@ L op_writestackn(rd.l);
regs.s.h = 0x01;
}
void R65816::op_per_n() {
auto R65816::op_per_n() {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();

View File

@ -1,5 +1,5 @@
template<int bit, int val> void R65816::op_branch() {
if((bool)(regs.p & bit) != val) {
auto R65816::op_branch(bool flag, bool value) {
if(flag != value) {
L rd.l = op_readpc();
} else {
rd.l = op_readpc();
@ -10,7 +10,7 @@ L op_io();
}
}
void R65816::op_bra() {
auto R65816::op_bra() {
rd.l = op_readpc();
aa.w = regs.pc.d + (int8)rd.l;
op_io_cond6(aa.w);
@ -18,27 +18,27 @@ L op_io();
regs.pc.w = aa.w;
}
void R65816::op_brl() {
auto R65816::op_brl() {
rd.l = op_readpc();
rd.h = op_readpc();
L op_io();
regs.pc.w = regs.pc.d + (int16)rd.w;
}
void R65816::op_jmp_addr() {
auto R65816::op_jmp_addr() {
rd.l = op_readpc();
L rd.h = op_readpc();
regs.pc.w = rd.w;
}
void R65816::op_jmp_long() {
auto R65816::op_jmp_long() {
rd.l = op_readpc();
rd.h = op_readpc();
L rd.b = op_readpc();
regs.pc.d = rd.d & 0xffffff;
}
void R65816::op_jmp_iaddr() {
auto R65816::op_jmp_iaddr() {
aa.l = op_readpc();
aa.h = op_readpc();
rd.l = op_readaddr(aa.w + 0);
@ -46,7 +46,7 @@ L rd.h = op_readaddr(aa.w + 1);
regs.pc.w = rd.w;
}
void R65816::op_jmp_iaddrx() {
auto R65816::op_jmp_iaddrx() {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@ -55,7 +55,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1);
regs.pc.w = rd.w;
}
void R65816::op_jmp_iladdr() {
auto R65816::op_jmp_iladdr() {
aa.l = op_readpc();
aa.h = op_readpc();
rd.l = op_readaddr(aa.w + 0);
@ -64,7 +64,7 @@ L rd.b = op_readaddr(aa.w + 2);
regs.pc.d = rd.d & 0xffffff;
}
void R65816::op_jsr_addr() {
auto R65816::op_jsr_addr() {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@ -74,7 +74,7 @@ L op_writestack(regs.pc.l);
regs.pc.w = aa.w;
}
void R65816::op_jsr_long_e() {
auto R65816::op_jsr_long_e() {
aa.l = op_readpc();
aa.h = op_readpc();
op_writestackn(regs.pc.b);
@ -87,7 +87,7 @@ L op_writestackn(regs.pc.l);
regs.s.h = 0x01;
}
void R65816::op_jsr_long_n() {
auto R65816::op_jsr_long_n() {
aa.l = op_readpc();
aa.h = op_readpc();
op_writestackn(regs.pc.b);
@ -99,7 +99,7 @@ L op_writestackn(regs.pc.l);
regs.pc.d = aa.d & 0xffffff;
}
void R65816::op_jsr_iaddrx_e() {
auto R65816::op_jsr_iaddrx_e() {
aa.l = op_readpc();
op_writestackn(regs.pc.h);
op_writestackn(regs.pc.l);
@ -111,7 +111,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1);
regs.s.h = 0x01;
}
void R65816::op_jsr_iaddrx_n() {
auto R65816::op_jsr_iaddrx_n() {
aa.l = op_readpc();
op_writestackn(regs.pc.h);
op_writestackn(regs.pc.l);
@ -122,7 +122,7 @@ L rd.h = op_readpbr(aa.w + regs.x.w + 1);
regs.pc.w = rd.w;
}
void R65816::op_rti_e() {
auto R65816::op_rti_e() {
op_io();
op_io();
regs.p = op_readstack() | 0x30;
@ -131,7 +131,7 @@ L rd.h = op_readstack();
regs.pc.w = rd.w;
}
void R65816::op_rti_n() {
auto R65816::op_rti_n() {
op_io();
op_io();
regs.p = op_readstack();
@ -143,10 +143,9 @@ void R65816::op_rti_n() {
rd.h = op_readstack();
L rd.b = op_readstack();
regs.pc.d = rd.d & 0xffffff;
update_table();
}
void R65816::op_rts() {
auto R65816::op_rts() {
op_io();
op_io();
rd.l = op_readstack();
@ -155,7 +154,7 @@ L op_io();
regs.pc.w = ++rd.w;
}
void R65816::op_rtl_e() {
auto R65816::op_rtl_e() {
op_io();
op_io();
rd.l = op_readstackn();
@ -166,7 +165,7 @@ L rd.b = op_readstackn();
regs.s.h = 0x01;
}
void R65816::op_rtl_n() {
auto R65816::op_rtl_n() {
op_io();
op_io();
rd.l = op_readstackn();

View File

@ -1,33 +1,33 @@
template<void (R65816::*op)()> void R65816::op_read_const_b() {
auto R65816::op_read_const_b(fp op) {
L rd.l = op_readpc();
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_const_w() {
auto R65816::op_read_const_w(fp op) {
rd.l = op_readpc();
L rd.h = op_readpc();
call(op);
}
void R65816::op_read_bit_const_b() {
auto R65816::op_read_bit_const_b() {
L rd.l = op_readpc();
regs.p.z = ((rd.l & regs.a.l) == 0);
}
void R65816::op_read_bit_const_w() {
auto R65816::op_read_bit_const_w() {
rd.l = op_readpc();
L rd.h = op_readpc();
regs.p.z = ((rd.w & regs.a.w) == 0);
}
template<void (R65816::*op)()> void R65816::op_read_addr_b() {
auto R65816::op_read_addr_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
L rd.l = op_readdbr(aa.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_addr_w() {
auto R65816::op_read_addr_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
rd.l = op_readdbr(aa.w + 0);
@ -35,7 +35,7 @@ L rd.h = op_readdbr(aa.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_addrx_b() {
auto R65816::op_read_addrx_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io_cond4(aa.w, aa.w + regs.x.w);
@ -43,7 +43,7 @@ L rd.l = op_readdbr(aa.w + regs.x.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_addrx_w() {
auto R65816::op_read_addrx_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io_cond4(aa.w, aa.w + regs.x.w);
@ -52,7 +52,7 @@ L rd.h = op_readdbr(aa.w + regs.x.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_addry_b() {
auto R65816::op_read_addry_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io_cond4(aa.w, aa.w + regs.y.w);
@ -60,7 +60,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_addry_w() {
auto R65816::op_read_addry_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io_cond4(aa.w, aa.w + regs.y.w);
@ -69,7 +69,7 @@ L rd.h = op_readdbr(aa.w + regs.y.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_long_b() {
auto R65816::op_read_long_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
@ -77,7 +77,7 @@ L rd.l = op_readlong(aa.d);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_long_w() {
auto R65816::op_read_long_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
@ -86,7 +86,7 @@ L rd.h = op_readlong(aa.d + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_longx_b() {
auto R65816::op_read_longx_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
@ -94,7 +94,7 @@ L rd.l = op_readlong(aa.d + regs.x.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_longx_w() {
auto R65816::op_read_longx_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
@ -103,14 +103,14 @@ L rd.h = op_readlong(aa.d + regs.x.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_dp_b() {
auto R65816::op_read_dp_b(fp op) {
dp = op_readpc();
op_io_cond2();
L rd.l = op_readdp(dp);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_dp_w() {
auto R65816::op_read_dp_w(fp op) {
dp = op_readpc();
op_io_cond2();
rd.l = op_readdp(dp + 0);
@ -118,24 +118,24 @@ L rd.h = op_readdp(dp + 1);
call(op);
}
template<void (R65816::*op)(), int n> void R65816::op_read_dpr_b() {
auto R65816::op_read_dpr_b(fp op, reg16_t& reg) {
dp = op_readpc();
op_io_cond2();
op_io();
L rd.l = op_readdp(dp + regs.r[n].w);
L rd.l = op_readdp(dp + reg.w);
call(op);
}
template<void (R65816::*op)(), int n> void R65816::op_read_dpr_w() {
auto R65816::op_read_dpr_w(fp op, reg16_t& reg) {
dp = op_readpc();
op_io_cond2();
op_io();
rd.l = op_readdp(dp + regs.r[n].w + 0);
L rd.h = op_readdp(dp + regs.r[n].w + 1);
rd.l = op_readdp(dp + reg.w + 0);
L rd.h = op_readdp(dp + reg.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idp_b() {
auto R65816::op_read_idp_b(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -144,7 +144,7 @@ L rd.l = op_readdbr(aa.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idp_w() {
auto R65816::op_read_idp_w(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -154,7 +154,7 @@ L rd.h = op_readdbr(aa.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idpx_b() {
auto R65816::op_read_idpx_b(fp op) {
dp = op_readpc();
op_io_cond2();
op_io();
@ -164,7 +164,7 @@ L rd.l = op_readdbr(aa.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idpx_w() {
auto R65816::op_read_idpx_w(fp op) {
dp = op_readpc();
op_io_cond2();
op_io();
@ -175,7 +175,7 @@ L rd.h = op_readdbr(aa.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idpy_b() {
auto R65816::op_read_idpy_b(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -185,7 +185,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_idpy_w() {
auto R65816::op_read_idpy_w(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -196,7 +196,7 @@ L rd.h = op_readdbr(aa.w + regs.y.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_ildp_b() {
auto R65816::op_read_ildp_b(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -206,7 +206,7 @@ L rd.l = op_readlong(aa.d);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_ildp_w() {
auto R65816::op_read_ildp_w(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -217,7 +217,7 @@ L rd.h = op_readlong(aa.d + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_ildpy_b() {
auto R65816::op_read_ildpy_b(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -227,7 +227,7 @@ L rd.l = op_readlong(aa.d + regs.y.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_ildpy_w() {
auto R65816::op_read_ildpy_w(fp op) {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -238,14 +238,14 @@ L rd.h = op_readlong(aa.d + regs.y.w + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_sr_b() {
auto R65816::op_read_sr_b(fp op) {
sp = op_readpc();
op_io();
L rd.l = op_readsp(sp);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_sr_w() {
auto R65816::op_read_sr_w(fp op) {
sp = op_readpc();
op_io();
rd.l = op_readsp(sp + 0);
@ -253,7 +253,7 @@ L rd.h = op_readsp(sp + 1);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_isry_b() {
auto R65816::op_read_isry_b(fp op) {
sp = op_readpc();
op_io();
aa.l = op_readsp(sp + 0);
@ -263,7 +263,7 @@ L rd.l = op_readdbr(aa.w + regs.y.w);
call(op);
}
template<void (R65816::*op)()> void R65816::op_read_isry_w() {
auto R65816::op_read_isry_w(fp op) {
sp = op_readpc();
op_io();
aa.l = op_readsp(sp + 0);

View File

@ -1,18 +1,18 @@
template<int n, int adjust> void R65816::op_adjust_imm_b() {
auto R65816::op_adjust_imm_b(reg16_t& reg, signed adjust) {
L op_io_irq();
regs.r[n].l += adjust;
regs.p.n = (regs.r[n].l & 0x80);
regs.p.z = (regs.r[n].l == 0);
reg.l += adjust;
regs.p.n = (reg.l & 0x80);
regs.p.z = (reg.l == 0);
}
template<int n, int adjust> void R65816::op_adjust_imm_w() {
auto R65816::op_adjust_imm_w(reg16_t& reg, signed adjust) {
L op_io_irq();
regs.r[n].w += adjust;
regs.p.n = (regs.r[n].w & 0x8000);
regs.p.z = (regs.r[n].w == 0);
reg.w += adjust;
regs.p.n = (reg.w & 0x8000);
regs.p.z = (reg.w == 0);
}
void R65816::op_asl_imm_b() {
auto R65816::op_asl_imm_b() {
L op_io_irq();
regs.p.c = (regs.a.l & 0x80);
regs.a.l <<= 1;
@ -20,7 +20,7 @@ L op_io_irq();
regs.p.z = (regs.a.l == 0);
}
void R65816::op_asl_imm_w() {
auto R65816::op_asl_imm_w() {
L op_io_irq();
regs.p.c = (regs.a.w & 0x8000);
regs.a.w <<= 1;
@ -28,7 +28,7 @@ L op_io_irq();
regs.p.z = (regs.a.w == 0);
}
void R65816::op_lsr_imm_b() {
auto R65816::op_lsr_imm_b() {
L op_io_irq();
regs.p.c = (regs.a.l & 0x01);
regs.a.l >>= 1;
@ -36,7 +36,7 @@ L op_io_irq();
regs.p.z = (regs.a.l == 0);
}
void R65816::op_lsr_imm_w() {
auto R65816::op_lsr_imm_w() {
L op_io_irq();
regs.p.c = (regs.a.w & 0x0001);
regs.a.w >>= 1;
@ -44,7 +44,7 @@ L op_io_irq();
regs.p.z = (regs.a.w == 0);
}
void R65816::op_rol_imm_b() {
auto R65816::op_rol_imm_b() {
L op_io_irq();
bool carry = regs.p.c;
regs.p.c = (regs.a.l & 0x80);
@ -53,7 +53,7 @@ L op_io_irq();
regs.p.z = (regs.a.l == 0);
}
void R65816::op_rol_imm_w() {
auto R65816::op_rol_imm_w() {
L op_io_irq();
bool carry = regs.p.c;
regs.p.c = (regs.a.w & 0x8000);
@ -62,7 +62,7 @@ L op_io_irq();
regs.p.z = (regs.a.w == 0);
}
void R65816::op_ror_imm_b() {
auto R65816::op_ror_imm_b() {
L op_io_irq();
bool carry = regs.p.c;
regs.p.c = (regs.a.l & 0x01);
@ -71,7 +71,7 @@ L op_io_irq();
regs.p.z = (regs.a.l == 0);
}
void R65816::op_ror_imm_w() {
auto R65816::op_ror_imm_w() {
L op_io_irq();
bool carry = regs.p.c;
regs.p.c = (regs.a.w & 0x0001);
@ -80,7 +80,7 @@ L op_io_irq();
regs.p.z = (regs.a.w == 0);
}
template<void (R65816::*op)()> void R65816::op_adjust_addr_b() {
auto R65816::op_adjust_addr_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
rd.l = op_readdbr(aa.w);
@ -89,7 +89,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_addr_b() {
L op_writedbr(aa.w, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_addr_w() {
auto R65816::op_adjust_addr_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
rd.l = op_readdbr(aa.w + 0);
@ -100,7 +100,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_addr_w() {
L op_writedbr(aa.w + 0, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_addrx_b() {
auto R65816::op_adjust_addrx_b(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@ -110,7 +110,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_addrx_b() {
L op_writedbr(aa.w + regs.x.w, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_addrx_w() {
auto R65816::op_adjust_addrx_w(fp op) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
@ -122,7 +122,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_addrx_w() {
L op_writedbr(aa.w + regs.x.w + 0, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_dp_b() {
auto R65816::op_adjust_dp_b(fp op) {
dp = op_readpc();
op_io_cond2();
rd.l = op_readdp(dp);
@ -131,7 +131,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_dp_b() {
L op_writedp(dp, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_dp_w() {
auto R65816::op_adjust_dp_w(fp op) {
dp = op_readpc();
op_io_cond2();
rd.l = op_readdp(dp + 0);
@ -142,7 +142,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_dp_w() {
L op_writedp(dp + 0, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_dpx_b() {
auto R65816::op_adjust_dpx_b(fp op) {
dp = op_readpc();
op_io_cond2();
op_io();
@ -152,7 +152,7 @@ template<void (R65816::*op)()> void R65816::op_adjust_dpx_b() {
L op_writedp(dp + regs.x.w, rd.l);
}
template<void (R65816::*op)()> void R65816::op_adjust_dpx_w() {
auto R65816::op_adjust_dpx_w(fp op) {
dp = op_readpc();
op_io_cond2();
op_io();

View File

@ -1,75 +1,75 @@
template<int n> void R65816::op_write_addr_b() {
auto R65816::op_write_addr_b(reg16_t& reg) {
aa.l = op_readpc();
aa.h = op_readpc();
L op_writedbr(aa.w, regs.r[n]);
L op_writedbr(aa.w, reg);
}
template<int n> void R65816::op_write_addr_w() {
auto R65816::op_write_addr_w(reg16_t& reg) {
aa.l = op_readpc();
aa.h = op_readpc();
op_writedbr(aa.w + 0, regs.r[n] >> 0);
L op_writedbr(aa.w + 1, regs.r[n] >> 8);
op_writedbr(aa.w + 0, reg >> 0);
L op_writedbr(aa.w + 1, reg >> 8);
}
template<int n, int i> void R65816::op_write_addrr_b() {
auto R65816::op_write_addrr_b(reg16_t& reg, reg16_t& idx) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
L op_writedbr(aa.w + regs.r[i], regs.r[n]);
L op_writedbr(aa.w + idx, reg);
}
template<int n, int i> void R65816::op_write_addrr_w() {
auto R65816::op_write_addrr_w(reg16_t& reg, reg16_t& idx) {
aa.l = op_readpc();
aa.h = op_readpc();
op_io();
op_writedbr(aa.w + regs.r[i] + 0, regs.r[n] >> 0);
L op_writedbr(aa.w + regs.r[i] + 1, regs.r[n] >> 8);
op_writedbr(aa.w + idx + 0, reg >> 0);
L op_writedbr(aa.w + idx + 1, reg >> 8);
}
template<int i> void R65816::op_write_longr_b() {
auto R65816::op_write_longr_b(reg16_t& idx) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
L op_writelong(aa.d + regs.r[i], regs.a.l);
L op_writelong(aa.d + idx, regs.a.l);
}
template<int i> void R65816::op_write_longr_w() {
auto R65816::op_write_longr_w(reg16_t& idx) {
aa.l = op_readpc();
aa.h = op_readpc();
aa.b = op_readpc();
op_writelong(aa.d + regs.r[i] + 0, regs.a.l);
L op_writelong(aa.d + regs.r[i] + 1, regs.a.h);
op_writelong(aa.d + idx + 0, regs.a.l);
L op_writelong(aa.d + idx + 1, regs.a.h);
}
template<int n> void R65816::op_write_dp_b() {
auto R65816::op_write_dp_b(reg16_t& reg) {
dp = op_readpc();
op_io_cond2();
L op_writedp(dp, regs.r[n]);
L op_writedp(dp, reg);
}
template<int n> void R65816::op_write_dp_w() {
auto R65816::op_write_dp_w(reg16_t& reg) {
dp = op_readpc();
op_io_cond2();
op_writedp(dp + 0, regs.r[n] >> 0);
L op_writedp(dp + 1, regs.r[n] >> 8);
op_writedp(dp + 0, reg >> 0);
L op_writedp(dp + 1, reg >> 8);
}
template<int n, int i> void R65816::op_write_dpr_b() {
auto R65816::op_write_dpr_b(reg16_t& reg, reg16_t& idx) {
dp = op_readpc();
op_io_cond2();
op_io();
L op_writedp(dp + regs.r[i], regs.r[n]);
L op_writedp(dp + idx, reg);
}
template<int n, int i> void R65816::op_write_dpr_w() {
auto R65816::op_write_dpr_w(reg16_t& reg, reg16_t& idx) {
dp = op_readpc();
op_io_cond2();
op_io();
op_writedp(dp + regs.r[i] + 0, regs.r[n] >> 0);
L op_writedp(dp + regs.r[i] + 1, regs.r[n] >> 8);
op_writedp(dp + idx + 0, reg >> 0);
L op_writedp(dp + idx + 1, reg >> 8);
}
void R65816::op_sta_idp_b() {
auto R65816::op_sta_idp_b() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -77,7 +77,7 @@ void R65816::op_sta_idp_b() {
L op_writedbr(aa.w, regs.a.l);
}
void R65816::op_sta_idp_w() {
auto R65816::op_sta_idp_w() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -86,7 +86,7 @@ void R65816::op_sta_idp_w() {
L op_writedbr(aa.w + 1, regs.a.h);
}
void R65816::op_sta_ildp_b() {
auto R65816::op_sta_ildp_b() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -95,7 +95,7 @@ void R65816::op_sta_ildp_b() {
L op_writelong(aa.d, regs.a.l);
}
void R65816::op_sta_ildp_w() {
auto R65816::op_sta_ildp_w() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -105,7 +105,7 @@ void R65816::op_sta_ildp_w() {
L op_writelong(aa.d + 1, regs.a.h);
}
void R65816::op_sta_idpx_b() {
auto R65816::op_sta_idpx_b() {
dp = op_readpc();
op_io_cond2();
op_io();
@ -114,7 +114,7 @@ void R65816::op_sta_idpx_b() {
L op_writedbr(aa.w, regs.a.l);
}
void R65816::op_sta_idpx_w() {
auto R65816::op_sta_idpx_w() {
dp = op_readpc();
op_io_cond2();
op_io();
@ -124,7 +124,7 @@ void R65816::op_sta_idpx_w() {
L op_writedbr(aa.w + 1, regs.a.h);
}
void R65816::op_sta_idpy_b() {
auto R65816::op_sta_idpy_b() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -133,7 +133,7 @@ void R65816::op_sta_idpy_b() {
L op_writedbr(aa.w + regs.y.w, regs.a.l);
}
void R65816::op_sta_idpy_w() {
auto R65816::op_sta_idpy_w() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -143,7 +143,7 @@ void R65816::op_sta_idpy_w() {
L op_writedbr(aa.w + regs.y.w + 1, regs.a.h);
}
void R65816::op_sta_ildpy_b() {
auto R65816::op_sta_ildpy_b() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -152,7 +152,7 @@ void R65816::op_sta_ildpy_b() {
L op_writelong(aa.d + regs.y.w, regs.a.l);
}
void R65816::op_sta_ildpy_w() {
auto R65816::op_sta_ildpy_w() {
dp = op_readpc();
op_io_cond2();
aa.l = op_readdp(dp + 0);
@ -162,20 +162,20 @@ void R65816::op_sta_ildpy_w() {
L op_writelong(aa.d + regs.y.w + 1, regs.a.h);
}
void R65816::op_sta_sr_b() {
auto R65816::op_sta_sr_b() {
sp = op_readpc();
op_io();
L op_writesp(sp, regs.a.l);
}
void R65816::op_sta_sr_w() {
auto R65816::op_sta_sr_w() {
sp = op_readpc();
op_io();
op_writesp(sp + 0, regs.a.l);
L op_writesp(sp + 1, regs.a.h);
}
void R65816::op_sta_isry_b() {
auto R65816::op_sta_isry_b() {
sp = op_readpc();
op_io();
aa.l = op_readsp(sp + 0);
@ -184,7 +184,7 @@ void R65816::op_sta_isry_b() {
L op_writedbr(aa.w + regs.y.w, regs.a.l);
}
void R65816::op_sta_isry_w() {
auto R65816::op_sta_isry_w() {
sp = op_readpc();
op_io();
aa.l = op_readsp(sp + 0);

View File

@ -8,12 +8,6 @@ namespace Processor {
#include "serialization.cpp"
#define L last_cycle();
#define A 0
#define X 1
#define Y 2
#define Z 3
#define S 4
#define D 5
#define call(op) (this->*op)()
#include "opcode_read.cpp"
@ -21,15 +15,9 @@ namespace Processor {
#include "opcode_rmw.cpp"
#include "opcode_pc.cpp"
#include "opcode_misc.cpp"
#include "table.cpp"
#include "switch.cpp"
#undef L
#undef A
#undef X
#undef Y
#undef Z
#undef S
#undef D
#undef call
//immediate, 2-cycle opcodes with I/O cycle will become bus read
@ -40,7 +28,7 @@ namespace Processor {
// tcd, tcs, tdc, tsc, tsx, txs,
// inc, inx, iny, dec, dex, dey,
// asl, lsr, rol, ror, nop, xce.
alwaysinline void R65816::op_io_irq() {
auto R65816::op_io_irq() -> void {
if(interrupt_pending()) {
//modify I/O cycle to bus read cycle, do not increment PC
op_read(regs.pc.d);
@ -49,25 +37,25 @@ alwaysinline void R65816::op_io_irq() {
}
}
alwaysinline void R65816::op_io_cond2() {
auto R65816::op_io_cond2() -> void {
if(regs.d.l != 0x00) {
op_io();
}
}
alwaysinline void R65816::op_io_cond4(uint16 x, uint16 y) {
auto R65816::op_io_cond4(uint16 x, uint16 y) -> void {
if(!regs.p.x || (x & 0xff00) != (y & 0xff00)) {
op_io();
}
}
alwaysinline void R65816::op_io_cond6(uint16 addr) {
auto R65816::op_io_cond6(uint16 addr) -> void {
if(regs.e && (regs.pc.w & 0xff00) != (addr & 0xff00)) {
op_io();
}
}
void R65816::op_irq() {
auto R65816::op_irq() -> void {
op_read(regs.pc.d);
op_io();
if(!regs.e) op_writestack(regs.pc.b);
@ -82,8 +70,4 @@ void R65816::op_irq() {
regs.pc.w = rd.w;
}
R65816::R65816() {
initialize_opcode_table();
}
}

View File

@ -12,219 +12,218 @@ struct R65816 {
#include "memory.hpp"
#include "disassembler.hpp"
using fp = auto (R65816::*)() -> void;
virtual auto op_io() -> void = 0;
virtual auto op_read(uint32_t addr) -> uint8_t = 0;
virtual auto op_write(uint32_t addr, uint8_t data) -> void = 0;
virtual auto last_cycle() -> void = 0;
virtual auto interrupt_pending() -> bool = 0;
virtual auto op_irq() -> void;
virtual auto disassembler_read(uint32 addr) -> uint8 { return 0u; }
//r65816.cpp
alwaysinline auto op_io_irq() -> void;
alwaysinline auto op_io_cond2() -> void;
alwaysinline auto op_io_cond4(uint16 x, uint16 y) -> void;
alwaysinline auto op_io_cond6(uint16 addr) -> void;
//algorithms.cpp
auto op_adc_b();
auto op_adc_w();
auto op_and_b();
auto op_and_w();
auto op_bit_b();
auto op_bit_w();
auto op_cmp_b();
auto op_cmp_w();
auto op_cpx_b();
auto op_cpx_w();
auto op_cpy_b();
auto op_cpy_w();
auto op_eor_b();
auto op_eor_w();
auto op_lda_b();
auto op_lda_w();
auto op_ldx_b();
auto op_ldx_w();
auto op_ldy_b();
auto op_ldy_w();
auto op_ora_b();
auto op_ora_w();
auto op_sbc_b();
auto op_sbc_w();
auto op_inc_b();
auto op_inc_w();
auto op_dec_b();
auto op_dec_w();
auto op_asl_b();
auto op_asl_w();
auto op_lsr_b();
auto op_lsr_w();
auto op_rol_b();
auto op_rol_w();
auto op_ror_b();
auto op_ror_w();
auto op_trb_b();
auto op_trb_w();
auto op_tsb_b();
auto op_tsb_w();
//opcode_read.cpp
auto op_read_const_b(fp);
auto op_read_const_w(fp);
auto op_read_bit_const_b();
auto op_read_bit_const_w();
auto op_read_addr_b(fp);
auto op_read_addr_w(fp);
auto op_read_addrx_b(fp);
auto op_read_addrx_w(fp);
auto op_read_addry_b(fp);
auto op_read_addry_w(fp);
auto op_read_long_b(fp);
auto op_read_long_w(fp);
auto op_read_longx_b(fp);
auto op_read_longx_w(fp);
auto op_read_dp_b(fp);
auto op_read_dp_w(fp);
auto op_read_dpr_b(fp, reg16_t&);
auto op_read_dpr_w(fp, reg16_t&);
auto op_read_idp_b(fp);
auto op_read_idp_w(fp);
auto op_read_idpx_b(fp);
auto op_read_idpx_w(fp);
auto op_read_idpy_b(fp);
auto op_read_idpy_w(fp);
auto op_read_ildp_b(fp);
auto op_read_ildp_w(fp);
auto op_read_ildpy_b(fp);
auto op_read_ildpy_w(fp);
auto op_read_sr_b(fp);
auto op_read_sr_w(fp);
auto op_read_isry_b(fp);
auto op_read_isry_w(fp);
//opcode_write.cpp
auto op_write_addr_b(reg16_t&);
auto op_write_addr_w(reg16_t&);
auto op_write_addrr_b(reg16_t&, reg16_t&);
auto op_write_addrr_w(reg16_t&, reg16_t&);
auto op_write_longr_b(reg16_t&);
auto op_write_longr_w(reg16_t&);
auto op_write_dp_b(reg16_t&);
auto op_write_dp_w(reg16_t&);
auto op_write_dpr_b(reg16_t&, reg16_t&);
auto op_write_dpr_w(reg16_t&, reg16_t&);
auto op_sta_idp_b();
auto op_sta_idp_w();
auto op_sta_ildp_b();
auto op_sta_ildp_w();
auto op_sta_idpx_b();
auto op_sta_idpx_w();
auto op_sta_idpy_b();
auto op_sta_idpy_w();
auto op_sta_ildpy_b();
auto op_sta_ildpy_w();
auto op_sta_sr_b();
auto op_sta_sr_w();
auto op_sta_isry_b();
auto op_sta_isry_w();
//opcode_rmw.cpp
auto op_adjust_imm_b(reg16_t&, signed);
auto op_adjust_imm_w(reg16_t&, signed);
auto op_asl_imm_b();
auto op_asl_imm_w();
auto op_lsr_imm_b();
auto op_lsr_imm_w();
auto op_rol_imm_b();
auto op_rol_imm_w();
auto op_ror_imm_b();
auto op_ror_imm_w();
auto op_adjust_addr_b(fp op);
auto op_adjust_addr_w(fp op);
auto op_adjust_addrx_b(fp op);
auto op_adjust_addrx_w(fp op);
auto op_adjust_dp_b(fp op);
auto op_adjust_dp_w(fp op);
auto op_adjust_dpx_b(fp op);
auto op_adjust_dpx_w(fp op);
//opcode_pc.cpp
auto op_branch(bool flag, bool value);
auto op_bra();
auto op_brl();
auto op_jmp_addr();
auto op_jmp_long();
auto op_jmp_iaddr();
auto op_jmp_iaddrx();
auto op_jmp_iladdr();
auto op_jsr_addr();
auto op_jsr_long_e();
auto op_jsr_long_n();
auto op_jsr_iaddrx_e();
auto op_jsr_iaddrx_n();
auto op_rti_e();
auto op_rti_n();
auto op_rts();
auto op_rtl_e();
auto op_rtl_n();
//opcode_misc.cpp
auto op_nop();
auto op_wdm();
auto op_xba();
auto op_move_b(signed adjust);
auto op_move_w(signed adjust);
auto op_interrupt_e(uint16);
auto op_interrupt_n(uint16);
auto op_stp();
auto op_wai();
auto op_xce();
auto op_flag(bool& flag, bool value);
auto op_pflag_e(bool);
auto op_pflag_n(bool);
auto op_transfer_b(reg16_t&, reg16_t&);
auto op_transfer_w(reg16_t&, reg16_t&);
auto op_tcs_e();
auto op_tcs_n();
auto op_tsx_b();
auto op_tsx_w();
auto op_txs_e();
auto op_txs_n();
auto op_push_b(reg16_t&);
auto op_push_w(reg16_t&);
auto op_phd_e();
auto op_phd_n();
auto op_phb();
auto op_phk();
auto op_php();
auto op_pull_b(reg16_t&);
auto op_pull_w(reg16_t&);
auto op_pld_e();
auto op_pld_n();
auto op_plb();
auto op_plp_e();
auto op_plp_n();
auto op_pea_e();
auto op_pea_n();
auto op_pei_e();
auto op_pei_n();
auto op_per_e();
auto op_per_n();
//switch.cpp
auto op_exec() -> void;
//serialization.cpp
auto serialize(serializer&) -> void;
regs_t regs;
reg24_t aa, rd;
uint8_t sp, dp;
virtual void op_io() = 0;
virtual uint8_t op_read(uint32_t addr) = 0;
virtual void op_write(uint32_t addr, uint8_t data) = 0;
virtual void last_cycle() = 0;
virtual bool interrupt_pending() = 0;
virtual void op_irq();
virtual uint8 disassembler_read(uint32 addr) { return 0u; }
void op_io_irq();
void op_io_cond2();
void op_io_cond4(uint16 x, uint16 y);
void op_io_cond6(uint16 addr);
void op_adc_b();
void op_adc_w();
void op_and_b();
void op_and_w();
void op_bit_b();
void op_bit_w();
void op_cmp_b();
void op_cmp_w();
void op_cpx_b();
void op_cpx_w();
void op_cpy_b();
void op_cpy_w();
void op_eor_b();
void op_eor_w();
void op_lda_b();
void op_lda_w();
void op_ldx_b();
void op_ldx_w();
void op_ldy_b();
void op_ldy_w();
void op_ora_b();
void op_ora_w();
void op_sbc_b();
void op_sbc_w();
void op_inc_b();
void op_inc_w();
void op_dec_b();
void op_dec_w();
void op_asl_b();
void op_asl_w();
void op_lsr_b();
void op_lsr_w();
void op_rol_b();
void op_rol_w();
void op_ror_b();
void op_ror_w();
void op_trb_b();
void op_trb_w();
void op_tsb_b();
void op_tsb_w();
template<void (R65816::*)()> void op_read_const_b();
template<void (R65816::*)()> void op_read_const_w();
void op_read_bit_const_b();
void op_read_bit_const_w();
template<void (R65816::*)()> void op_read_addr_b();
template<void (R65816::*)()> void op_read_addr_w();
template<void (R65816::*)()> void op_read_addrx_b();
template<void (R65816::*)()> void op_read_addrx_w();
template<void (R65816::*)()> void op_read_addry_b();
template<void (R65816::*)()> void op_read_addry_w();
template<void (R65816::*)()> void op_read_long_b();
template<void (R65816::*)()> void op_read_long_w();
template<void (R65816::*)()> void op_read_longx_b();
template<void (R65816::*)()> void op_read_longx_w();
template<void (R65816::*)()> void op_read_dp_b();
template<void (R65816::*)()> void op_read_dp_w();
template<void (R65816::*)(), int> void op_read_dpr_b();
template<void (R65816::*)(), int> void op_read_dpr_w();
template<void (R65816::*)()> void op_read_idp_b();
template<void (R65816::*)()> void op_read_idp_w();
template<void (R65816::*)()> void op_read_idpx_b();
template<void (R65816::*)()> void op_read_idpx_w();
template<void (R65816::*)()> void op_read_idpy_b();
template<void (R65816::*)()> void op_read_idpy_w();
template<void (R65816::*)()> void op_read_ildp_b();
template<void (R65816::*)()> void op_read_ildp_w();
template<void (R65816::*)()> void op_read_ildpy_b();
template<void (R65816::*)()> void op_read_ildpy_w();
template<void (R65816::*)()> void op_read_sr_b();
template<void (R65816::*)()> void op_read_sr_w();
template<void (R65816::*)()> void op_read_isry_b();
template<void (R65816::*)()> void op_read_isry_w();
template<int> void op_write_addr_b();
template<int> void op_write_addr_w();
template<int, int> void op_write_addrr_b();
template<int, int> void op_write_addrr_w();
template<int> void op_write_longr_b();
template<int> void op_write_longr_w();
template<int> void op_write_dp_b();
template<int> void op_write_dp_w();
template<int, int> void op_write_dpr_b();
template<int, int> void op_write_dpr_w();
void op_sta_idp_b();
void op_sta_idp_w();
void op_sta_ildp_b();
void op_sta_ildp_w();
void op_sta_idpx_b();
void op_sta_idpx_w();
void op_sta_idpy_b();
void op_sta_idpy_w();
void op_sta_ildpy_b();
void op_sta_ildpy_w();
void op_sta_sr_b();
void op_sta_sr_w();
void op_sta_isry_b();
void op_sta_isry_w();
template<int, int> void op_adjust_imm_b();
template<int, int> void op_adjust_imm_w();
void op_asl_imm_b();
void op_asl_imm_w();
void op_lsr_imm_b();
void op_lsr_imm_w();
void op_rol_imm_b();
void op_rol_imm_w();
void op_ror_imm_b();
void op_ror_imm_w();
template<void (R65816::*)()> void op_adjust_addr_b();
template<void (R65816::*)()> void op_adjust_addr_w();
template<void (R65816::*)()> void op_adjust_addrx_b();
template<void (R65816::*)()> void op_adjust_addrx_w();
template<void (R65816::*)()> void op_adjust_dp_b();
template<void (R65816::*)()> void op_adjust_dp_w();
template<void (R65816::*)()> void op_adjust_dpx_b();
template<void (R65816::*)()> void op_adjust_dpx_w();
template<int, int> void op_branch();
void op_bra();
void op_brl();
void op_jmp_addr();
void op_jmp_long();
void op_jmp_iaddr();
void op_jmp_iaddrx();
void op_jmp_iladdr();
void op_jsr_addr();
void op_jsr_long_e();
void op_jsr_long_n();
void op_jsr_iaddrx_e();
void op_jsr_iaddrx_n();
void op_rti_e();
void op_rti_n();
void op_rts();
void op_rtl_e();
void op_rtl_n();
void op_nop();
void op_wdm();
void op_xba();
template<int> void op_move_b();
template<int> void op_move_w();
template<int, int> void op_interrupt_e();
template<int, int> void op_interrupt_n();
void op_stp();
void op_wai();
void op_xce();
template<int, int> void op_flag();
template<int> void op_pflag_e();
template<int> void op_pflag_n();
template<int, int> void op_transfer_b();
template<int, int> void op_transfer_w();
void op_tcs_e();
void op_tcs_n();
void op_tsx_b();
void op_tsx_w();
void op_txs_e();
void op_txs_n();
template<int> void op_push_b();
template<int> void op_push_w();
void op_phd_e();
void op_phd_n();
void op_phb();
void op_phk();
void op_php();
template<int> void op_pull_b();
template<int> void op_pull_w();
void op_pld_e();
void op_pld_n();
void op_plb();
void op_plp_e();
void op_plp_n();
void op_pea_e();
void op_pea_n();
void op_pei_e();
void op_pei_n();
void op_per_e();
void op_per_n();
void (R65816::**opcode_table)();
void (R65816::*op_table[5 * 256])();
void initialize_opcode_table();
void update_table();
enum {
table_EM = 0, // 8-bit accumulator, 8-bit index (emulation mode)
table_MX = 256, // 8-bit accumulator, 8-bit index
table_Mx = 512, // 8-bit accumulator, 16-bit index
table_mX = 768, //16-bit accumulator, 8-bit index
table_mx = 1024, //16-bit accumulator, 16-bit index
};
void serialize(serializer&);
R65816();
uint8 sp, dp;
};
}

View File

@ -1,83 +1,80 @@
struct flag_t {
bool n, v, m, x, d, i, z, c;
bool n{0};
bool v{0};
bool m{0};
bool x{0};
bool d{0};
bool i{0};
bool z{0};
bool c{0};
inline operator unsigned() const {
return (n << 7) + (v << 6) + (m << 5) + (x << 4)
+ (d << 3) + (i << 2) + (z << 1) + (c << 0);
}
inline unsigned operator=(uint8 data) {
inline auto operator=(uint8 data) -> unsigned {
n = data & 0x80; v = data & 0x40; m = data & 0x20; x = data & 0x10;
d = data & 0x08; i = data & 0x04; z = data & 0x02; c = data & 0x01;
return data;
}
inline unsigned operator|=(unsigned data) { return operator=(operator unsigned() | data); }
inline unsigned operator^=(unsigned data) { return operator=(operator unsigned() ^ data); }
inline unsigned operator&=(unsigned data) { return operator=(operator unsigned() & data); }
flag_t() : n(0), v(0), m(0), x(0), d(0), i(0), z(0), c(0) {}
};
struct reg16_t {
union {
uint16 w;
uint16 w = 0;
struct { uint8 order_lsb2(l, h); };
};
inline operator unsigned() const { return w; }
inline unsigned operator = (unsigned i) { return w = i; }
inline unsigned operator |= (unsigned i) { return w |= i; }
inline unsigned operator ^= (unsigned i) { return w ^= i; }
inline unsigned operator &= (unsigned i) { return w &= i; }
inline unsigned operator <<= (unsigned i) { return w <<= i; }
inline unsigned operator >>= (unsigned i) { return w >>= i; }
inline unsigned operator += (unsigned i) { return w += i; }
inline unsigned operator -= (unsigned i) { return w -= i; }
inline unsigned operator *= (unsigned i) { return w *= i; }
inline unsigned operator /= (unsigned i) { return w /= i; }
inline unsigned operator %= (unsigned i) { return w %= i; }
reg16_t() : w(0) {}
inline auto operator = (unsigned i) -> unsigned { return w = i; }
inline auto operator |= (unsigned i) -> unsigned { return w |= i; }
inline auto operator ^= (unsigned i) -> unsigned { return w ^= i; }
inline auto operator &= (unsigned i) -> unsigned { return w &= i; }
inline auto operator <<= (unsigned i) -> unsigned { return w <<= i; }
inline auto operator >>= (unsigned i) -> unsigned { return w >>= i; }
inline auto operator += (unsigned i) -> unsigned { return w += i; }
inline auto operator -= (unsigned i) -> unsigned { return w -= i; }
inline auto operator *= (unsigned i) -> unsigned { return w *= i; }
inline auto operator /= (unsigned i) -> unsigned { return w /= i; }
inline auto operator %= (unsigned i) -> unsigned { return w %= i; }
};
struct reg24_t {
union {
uint32 d;
uint32 d = 0;
struct { uint16 order_lsb2(w, wh); };
struct { uint8 order_lsb4(l, h, b, bh); };
};
inline operator unsigned() const { return d; }
inline unsigned operator = (unsigned i) { return d = uclip<24>(i); }
inline unsigned operator |= (unsigned i) { return d = uclip<24>(d | i); }
inline unsigned operator ^= (unsigned i) { return d = uclip<24>(d ^ i); }
inline unsigned operator &= (unsigned i) { return d = uclip<24>(d & i); }
inline unsigned operator <<= (unsigned i) { return d = uclip<24>(d << i); }
inline unsigned operator >>= (unsigned i) { return d = uclip<24>(d >> i); }
inline unsigned operator += (unsigned i) { return d = uclip<24>(d + i); }
inline unsigned operator -= (unsigned i) { return d = uclip<24>(d - i); }
inline unsigned operator *= (unsigned i) { return d = uclip<24>(d * i); }
inline unsigned operator /= (unsigned i) { return d = uclip<24>(d / i); }
inline unsigned operator %= (unsigned i) { return d = uclip<24>(d % i); }
reg24_t() : d(0) {}
inline auto operator = (unsigned i) -> unsigned { return d = uclip<24>(i); }
inline auto operator |= (unsigned i) -> unsigned { return d = uclip<24>(d | i); }
inline auto operator ^= (unsigned i) -> unsigned { return d = uclip<24>(d ^ i); }
inline auto operator &= (unsigned i) -> unsigned { return d = uclip<24>(d & i); }
inline auto operator <<= (unsigned i) -> unsigned { return d = uclip<24>(d << i); }
inline auto operator >>= (unsigned i) -> unsigned { return d = uclip<24>(d >> i); }
inline auto operator += (unsigned i) -> unsigned { return d = uclip<24>(d + i); }
inline auto operator -= (unsigned i) -> unsigned { return d = uclip<24>(d - i); }
inline auto operator *= (unsigned i) -> unsigned { return d = uclip<24>(d * i); }
inline auto operator /= (unsigned i) -> unsigned { return d = uclip<24>(d / i); }
inline auto operator %= (unsigned i) -> unsigned { return d = uclip<24>(d % i); }
};
struct regs_t {
reg24_t pc;
reg16_t r[6], &a, &x, &y, &z, &s, &d;
reg16_t a;
reg16_t x;
reg16_t y;
reg16_t z; //pseudo-register (zero register)
reg16_t s;
reg16_t d;
flag_t p;
uint8 db;
bool e;
uint8 db{0};
bool e{0};
bool irq; //IRQ pin (0 = low, 1 = trigger)
bool wai; //raised during wai, cleared after interrupt triggered
uint8 mdr; //memory data register
uint16 vector; //interrupt vector address
regs_t():
a(r[0]), x(r[1]), y(r[2]), z(r[3]), s(r[4]), d(r[5]), db(0), e(false), irq(false), wai(false), mdr(0), vector(0) {
z = 0;
}
bool irq{0}; //IRQ pin (0 = low, 1 = trigger)
bool wai{0}; //raised during wai, cleared after interrupt triggered
uint8 mdr{0}; //memory data register
uint16 vector{0}; //interrupt vector address
};

View File

@ -1,4 +1,4 @@
void R65816::serialize(serializer& s) {
auto R65816::serialize(serializer& s) -> void {
s.integer(regs.pc.d);
s.integer(regs.a.w);
@ -28,6 +28,4 @@ void R65816::serialize(serializer& s) {
s.integer(rd.d);
s.integer(sp);
s.integer(dp);
update_table();
}

292
processor/r65816/switch.cpp Normal file
View File

@ -0,0 +1,292 @@
auto R65816::op_exec() -> void {
#define opA( n, o ) case n: return op_##o();
#define opAII(n, o, i, j) case n: return op_##o(i, j);
#define opE( n, o ) case n: return regs.e ? op_##o##_e() : op_##o##_n();
#define opEI( n, o, i ) case n: return regs.e ? op_##o##_e(i) : op_##o##_n(i);
#define opEII(n, o, i, j) case n: return regs.e ? op_##o##_e(i) : op_##o##_n(j);
#define opM( n, o ) case n: return regs.p.m ? op_##o##_b() : op_##o##_w();
#define opMF( n, o, f ) case n: return regs.p.m ? op_##o##_b(&R65816::op_##f##_b) : op_##o##_w(&R65816::op_##f##_w);
#define opMFI(n, o, f, i) case n: return regs.p.m ? op_##o##_b(&R65816::op_##f##_b, i) : op_##o##_w(&R65816::op_##f##_w, i);
#define opMI( n, o, i ) case n: return regs.p.m ? op_##o##_b(i) : op_##o##_w(i);
#define opMII(n, o, i, j) case n: return regs.p.m ? op_##o##_b(i, j) : op_##o##_w(i, j);
#define opX( n, o) case n: return regs.p.x ? op_##o##_b() : op_##o##_w();
#define opXF( n, o, f ) case n: return regs.p.x ? op_##o##_b(&R65816::op_##f##_b) : op_##o##_w(&R65816::op_##f##_w);
#define opXFI(n, o, f, i) case n: return regs.p.x ? op_##o##_b(&R65816::op_##f##_b, i) : op_##o##_w(&R65816::op_##f##_w, i);
#define opXI( n, o, i ) case n: return regs.p.x ? op_##o##_b(i) : op_##o##_w(i);
#define opXII(n, o, i, j) case n: return regs.p.x ? op_##o##_b(i, j) : op_##o##_w(i, j);
switch(op_readpc()) {
opEII(0x00, interrupt, 0xfffe, 0xffe6)
opMF (0x01, read_idpx, ora)
opEII(0x02, interrupt, 0xfff4, 0xffe4)
opMF (0x03, read_sr, ora)
opMF (0x04, adjust_dp, tsb)
opMF (0x05, read_dp, ora)
opMF (0x06, adjust_dp, asl)
opMF (0x07, read_ildp, ora)
opA (0x08, php)
opMF (0x09, read_const, ora)
opM (0x0a, asl_imm)
opE (0x0b, phd)
opMF (0x0c, adjust_addr, tsb)
opMF (0x0d, read_addr, ora)
opMF (0x0e, adjust_addr, asl)
opMF (0x0f, read_long, ora)
opAII(0x10, branch, regs.p.n, 0)
opMF (0x11, read_idpy, ora)
opMF (0x12, read_idp, ora)
opMF (0x13, read_isry, ora)
opMF (0x14, adjust_dp, trb)
opMFI(0x15, read_dpr, ora, regs.x)
opMF (0x16, adjust_dpx, asl)
opMF (0x17, read_ildpy, ora)
opAII(0x18, flag, regs.p.c, 0)
opMF (0x19, read_addry, ora)
opMII(0x1a, adjust_imm, regs.a, +1)
opE (0x1b, tcs)
opMF (0x1c, adjust_addr, trb)
opMF (0x1d, read_addrx, ora)
opMF (0x1e, adjust_addrx, asl)
opMF (0x1f, read_longx, ora)
opA (0x20, jsr_addr)
opMF (0x21, read_idpx, and)
opE (0x22, jsr_long)
opMF (0x23, read_sr, and)
opMF (0x24, read_dp, bit)
opMF (0x25, read_dp, and)
opMF (0x26, adjust_dp, rol)
opMF (0x27, read_ildp, and)
opE (0x28, plp)
opMF (0x29, read_const, and)
opM (0x2a, rol_imm)
opE (0x2b, pld)
opMF (0x2c, read_addr, bit)
opMF (0x2d, read_addr, and)
opMF (0x2e, adjust_addr, rol)
opMF (0x2f, read_long, and)
opAII(0x30, branch, regs.p.n, 1)
opMF (0x31, read_idpy, and)
opMF (0x32, read_idp, and)
opMF (0x33, read_isry, and)
opMFI(0x34, read_dpr, bit, regs.x)
opMFI(0x35, read_dpr, and, regs.x)
opMF (0x36, adjust_dpx, rol)
opMF (0x37, read_ildpy, and)
opAII(0x38, flag, regs.p.c, 1)
opMF (0x39, read_addry, and)
opMII(0x3a, adjust_imm, regs.a, -1)
opAII(0x3b, transfer_w, regs.s, regs.a)
opMF (0x3c, read_addrx, bit)
opMF (0x3d, read_addrx, and)
opMF (0x3e, adjust_addrx, rol)
opMF (0x3f, read_longx, and)
opE (0x40, rti)
opMF (0x41, read_idpx, eor)
opA (0x42, wdm)
opMF (0x43, read_sr, eor)
opXI (0x44, move, -1)
opMF (0x45, read_dp, eor)
opMF (0x46, adjust_dp, lsr)
opMF (0x47, read_ildp, eor)
opMI (0x48, push, regs.a)
opMF (0x49, read_const, eor)
opM (0x4a, lsr_imm)
opA (0x4b, phk)
opA (0x4c, jmp_addr)
opMF (0x4d, read_addr, eor)
opMF (0x4e, adjust_addr, lsr)
opMF (0x4f, read_long, eor)
opAII(0x50, branch, regs.p.v, 0)
opMF (0x51, read_idpy, eor)
opMF (0x52, read_idp, eor)
opMF (0x53, read_isry, eor)
opXI (0x54, move, +1)
opMFI(0x55, read_dpr, eor, regs.x)
opMF (0x56, adjust_dpx, lsr)
opMF (0x57, read_ildpy, eor)
opAII(0x58, flag, regs.p.i, 0)
opMF (0x59, read_addry, eor)
opXI (0x5a, push, regs.y)
opAII(0x5b, transfer_w, regs.a, regs.d)
opA (0x5c, jmp_long)
opMF (0x5d, read_addrx, eor)
opMF (0x5e, adjust_addrx, lsr)
opMF (0x5f, read_longx, eor)
opA (0x60, rts)
opMF (0x61, read_idpx, adc)
opE (0x62, per)
opMF (0x63, read_sr, adc)
opMI (0x64, write_dp, regs.z)
opMF (0x65, read_dp, adc)
opMF (0x66, adjust_dp, ror)
opMF (0x67, read_ildp, adc)
opMI (0x68, pull, regs.a)
opMF (0x69, read_const, adc)
opM (0x6a, ror_imm)
opE (0x6b, rtl)
opA (0x6c, jmp_iaddr)
opMF (0x6d, read_addr, adc)
opMF (0x6e, adjust_addr, ror)
opMF (0x6f, read_long, adc)
opAII(0x70, branch, regs.p.v, 1)
opMF (0x71, read_idpy, adc)
opMF (0x72, read_idp, adc)
opMF (0x73, read_isry, adc)
opMII(0x74, write_dpr, regs.z, regs.x)
opMFI(0x75, read_dpr, adc, regs.x)
opMF (0x76, adjust_dpx, ror)
opMF (0x77, read_ildpy, adc)
opAII(0x78, flag, regs.p.i, 1)
opMF (0x79, read_addry, adc)
opXI (0x7a, pull, regs.y)
opAII(0x7b, transfer_w, regs.d, regs.a)
opA (0x7c, jmp_iaddrx)
opMF (0x7d, read_addrx, adc)
opMF (0x7e, adjust_addrx, ror)
opMF (0x7f, read_longx, adc)
opA (0x80, bra)
opM (0x81, sta_idpx)
opA (0x82, brl)
opM (0x83, sta_sr)
opXI (0x84, write_dp, regs.y)
opMI (0x85, write_dp, regs.a)
opXI (0x86, write_dp, regs.x)
opM (0x87, sta_ildp)
opXII(0x88, adjust_imm, regs.y, -1)
opM (0x89, read_bit_const)
opMII(0x8a, transfer, regs.x, regs.a)
opA (0x8b, phb)
opXI (0x8c, write_addr, regs.y)
opMI (0x8d, write_addr, regs.a)
opXI (0x8e, write_addr, regs.x)
opMI (0x8f, write_longr, regs.z)
opAII(0x90, branch, regs.p.c, 0)
opM (0x91, sta_idpy)
opM (0x92, sta_idp)
opM (0x93, sta_isry)
opXII(0x94, write_dpr, regs.y, regs.x)
opMII(0x95, write_dpr, regs.a, regs.x)
opXII(0x96, write_dpr, regs.x, regs.y)
opM (0x97, sta_ildpy)
opMII(0x98, transfer, regs.y, regs.a)
opMII(0x99, write_addrr, regs.a, regs.y)
opE (0x9a, txs)
opXII(0x9b, transfer, regs.x, regs.y)
opMI (0x9c, write_addr, regs.z)
opMII(0x9d, write_addrr, regs.a, regs.x)
opMII(0x9e, write_addrr, regs.z, regs.x)
opMI (0x9f, write_longr, regs.x)
opXF (0xa0, read_const, ldy)
opMF (0xa1, read_idpx, lda)
opXF (0xa2, read_const, ldx)
opMF (0xa3, read_sr, lda)
opXF (0xa4, read_dp, ldy)
opMF (0xa5, read_dp, lda)
opXF (0xa6, read_dp, ldx)
opMF (0xa7, read_ildp, lda)
opXII(0xa8, transfer, regs.a, regs.y)
opMF (0xa9, read_const, lda)
opXII(0xaa, transfer, regs.a, regs.x)
opA (0xab, plb)
opXF (0xac, read_addr, ldy)
opMF (0xad, read_addr, lda)
opXF (0xae, read_addr, ldx)
opMF (0xaf, read_long, lda)
opAII(0xb0, branch, regs.p.c, 1)
opMF (0xb1, read_idpy, lda)
opMF (0xb2, read_idp, lda)
opMF (0xb3, read_isry, lda)
opXFI(0xb4, read_dpr, ldy, regs.x)
opMFI(0xb5, read_dpr, lda, regs.x)
opXFI(0xb6, read_dpr, ldx, regs.y)
opMF (0xb7, read_ildpy, lda)
opAII(0xb8, flag, regs.p.v, 0)
opMF (0xb9, read_addry, lda)
opX (0xba, tsx)
opXII(0xbb, transfer, regs.y, regs.x)
opXF (0xbc, read_addrx, ldy)
opMF (0xbd, read_addrx, lda)
opXF (0xbe, read_addry, ldx)
opMF (0xbf, read_longx, lda)
opXF (0xc0, read_const, cpy)
opMF (0xc1, read_idpx, cmp)
opEI (0xc2, pflag, 0)
opMF (0xc3, read_sr, cmp)
opXF (0xc4, read_dp, cpy)
opMF (0xc5, read_dp, cmp)
opMF (0xc6, adjust_dp, dec)
opMF (0xc7, read_ildp, cmp)
opXII(0xc8, adjust_imm, regs.y, +1)
opMF (0xc9, read_const, cmp)
opXII(0xca, adjust_imm, regs.x, -1)
opA (0xcb, wai)
opXF (0xcc, read_addr, cpy)
opMF (0xcd, read_addr, cmp)
opMF (0xce, adjust_addr, dec)
opMF (0xcf, read_long, cmp)
opAII(0xd0, branch, regs.p.z, 0)
opMF (0xd1, read_idpy, cmp)
opMF (0xd2, read_idp, cmp)
opMF (0xd3, read_isry, cmp)
opE (0xd4, pei)
opMFI(0xd5, read_dpr, cmp, regs.x)
opMF (0xd6, adjust_dpx, dec)
opMF (0xd7, read_ildpy, cmp)
opAII(0xd8, flag, regs.p.d, 0)
opMF (0xd9, read_addry, cmp)
opXI (0xda, push, regs.x)
opA (0xdb, stp)
opA (0xdc, jmp_iladdr)
opMF (0xdd, read_addrx, cmp)
opMF (0xde, adjust_addrx, dec)
opMF (0xdf, read_longx, cmp)
opXF (0xe0, read_const, cpx)
opMF (0xe1, read_idpx, sbc)
opEI (0xe2, pflag, 1)
opMF (0xe3, read_sr, sbc)
opXF (0xe4, read_dp, cpx)
opMF (0xe5, read_dp, sbc)
opMF (0xe6, adjust_dp, inc)
opMF (0xe7, read_ildp, sbc)
opXII(0xe8, adjust_imm, regs.x, +1)
opMF (0xe9, read_const, sbc)
opA (0xea, nop)
opA (0xeb, xba)
opXF (0xec, read_addr, cpx)
opMF (0xed, read_addr, sbc)
opMF (0xee, adjust_addr, inc)
opMF (0xef, read_long, sbc)
opAII(0xf0, branch, regs.p.z, 1)
opMF (0xf1, read_idpy, sbc)
opMF (0xf2, read_idp, sbc)
opMF (0xf3, read_isry, sbc)
opE (0xf4, pea)
opMFI(0xf5, read_dpr, sbc, regs.x)
opMF (0xf6, adjust_dpx, inc)
opMF (0xf7, read_ildpy, sbc)
opAII(0xf8, flag, regs.p.d, 1)
opMF (0xf9, read_addry, sbc)
opXI (0xfa, pull, regs.x)
opA (0xfb, xce)
opE (0xfc, jsr_iaddrx)
opMF (0xfd, read_addrx, sbc)
opMF (0xfe, adjust_addrx, inc)
opMF (0xff, read_longx, sbc)
}
#undef opA
#undef opAII
#undef opE
#undef opEI
#undef opEII
#undef opM
#undef opMF
#undef opMFI
#undef opMI
#undef opMII
#undef opX
#undef opXF
#undef opXFI
#undef opXI
#undef opXII
}

View File

@ -1,308 +0,0 @@
void R65816::initialize_opcode_table() {
#define opA( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name;
#define opAII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name<x, y>;
#define opE( id, name ) op_table[table_EM + id] = &R65816::op_##name##_e; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n;
#define opEI( id, name, x ) op_table[table_EM + id] = &R65816::op_##name##_e<x>; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n<x>;
#define opEII(id, name, x, y ) op_table[table_EM + id] = &R65816::op_##name##_e<x, y>; op_table[table_MX + id] = op_table[table_Mx + id] = op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_n<x, y>;
#define opM( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w;
#define opMI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<x>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<x>;
#define opMII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<x, y>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<x, y>;
#define opMF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w>;
#define opMFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_Mx + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b, x>; op_table[table_mX + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w, x>;
#define opX( id, name ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w;
#define opXI( id, name, x ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<x>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<x>;
#define opXII(id, name, x, y ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<x, y>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<x, y>;
#define opXF( id, name, fn ) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w>;
#define opXFI(id, name, fn, x) op_table[table_EM + id] = op_table[table_MX + id] = op_table[table_mX + id] = &R65816::op_##name##_b<&R65816::op_##fn##_b, x>; op_table[table_Mx + id] = op_table[table_mx + id] = &R65816::op_##name##_w<&R65816::op_##fn##_w, x>;
opEII(0x00, interrupt, 0xfffe, 0xffe6)
opMF (0x01, read_idpx, ora)
opEII(0x02, interrupt, 0xfff4, 0xffe4)
opMF (0x03, read_sr, ora)
opMF (0x04, adjust_dp, tsb)
opMF (0x05, read_dp, ora)
opMF (0x06, adjust_dp, asl)
opMF (0x07, read_ildp, ora)
opA (0x08, php)
opMF (0x09, read_const, ora)
opM (0x0a, asl_imm)
opE (0x0b, phd)
opMF (0x0c, adjust_addr, tsb)
opMF (0x0d, read_addr, ora)
opMF (0x0e, adjust_addr, asl)
opMF (0x0f, read_long, ora)
opAII(0x10, branch, 0x80, false)
opMF (0x11, read_idpy, ora)
opMF (0x12, read_idp, ora)
opMF (0x13, read_isry, ora)
opMF (0x14, adjust_dp, trb)
opMFI(0x15, read_dpr, ora, X)
opMF (0x16, adjust_dpx, asl)
opMF (0x17, read_ildpy, ora)
opAII(0x18, flag, 0x01, 0x00)
opMF (0x19, read_addry, ora)
opMII(0x1a, adjust_imm, A, +1)
opE (0x1b, tcs)
opMF (0x1c, adjust_addr, trb)
opMF (0x1d, read_addrx, ora)
opMF (0x1e, adjust_addrx, asl)
opMF (0x1f, read_longx, ora)
opA (0x20, jsr_addr)
opMF (0x21, read_idpx, and)
opE (0x22, jsr_long)
opMF (0x23, read_sr, and)
opMF (0x24, read_dp, bit)
opMF (0x25, read_dp, and)
opMF (0x26, adjust_dp, rol)
opMF (0x27, read_ildp, and)
opE (0x28, plp)
opMF (0x29, read_const, and)
opM (0x2a, rol_imm)
opE (0x2b, pld)
opMF (0x2c, read_addr, bit)
opMF (0x2d, read_addr, and)
opMF (0x2e, adjust_addr, rol)
opMF (0x2f, read_long, and)
opAII(0x30, branch, 0x80, true)
opMF (0x31, read_idpy, and)
opMF (0x32, read_idp, and)
opMF (0x33, read_isry, and)
opMFI(0x34, read_dpr, bit, X)
opMFI(0x35, read_dpr, and, X)
opMF (0x36, adjust_dpx, rol)
opMF (0x37, read_ildpy, and)
opAII(0x38, flag, 0x01, 0x01)
opMF (0x39, read_addry, and)
opMII(0x3a, adjust_imm, A, -1)
opAII(0x3b, transfer_w, S, A)
opMF (0x3c, read_addrx, bit)
opMF (0x3d, read_addrx, and)
opMF (0x3e, adjust_addrx, rol)
opMF (0x3f, read_longx, and)
opE (0x40, rti)
opMF (0x41, read_idpx, eor)
opA (0x42, wdm)
opMF (0x43, read_sr, eor)
opXI (0x44, move, -1)
opMF (0x45, read_dp, eor)
opMF (0x46, adjust_dp, lsr)
opMF (0x47, read_ildp, eor)
opMI (0x48, push, A)
opMF (0x49, read_const, eor)
opM (0x4a, lsr_imm)
opA (0x4b, phk)
opA (0x4c, jmp_addr)
opMF (0x4d, read_addr, eor)
opMF (0x4e, adjust_addr, lsr)
opMF (0x4f, read_long, eor)
opAII(0x50, branch, 0x40, false)
opMF (0x51, read_idpy, eor)
opMF (0x52, read_idp, eor)
opMF (0x53, read_isry, eor)
opXI (0x54, move, +1)
opMFI(0x55, read_dpr, eor, X)
opMF (0x56, adjust_dpx, lsr)
opMF (0x57, read_ildpy, eor)
opAII(0x58, flag, 0x04, 0x00)
opMF (0x59, read_addry, eor)
opXI (0x5a, push, Y)
opAII(0x5b, transfer_w, A, D)
opA (0x5c, jmp_long)
opMF (0x5d, read_addrx, eor)
opMF (0x5e, adjust_addrx, lsr)
opMF (0x5f, read_longx, eor)
opA (0x60, rts)
opMF (0x61, read_idpx, adc)
opE (0x62, per)
opMF (0x63, read_sr, adc)
opMI (0x64, write_dp, Z)
opMF (0x65, read_dp, adc)
opMF (0x66, adjust_dp, ror)
opMF (0x67, read_ildp, adc)
opMI (0x68, pull, A)
opMF (0x69, read_const, adc)
opM (0x6a, ror_imm)
opE (0x6b, rtl)
opA (0x6c, jmp_iaddr)
opMF (0x6d, read_addr, adc)
opMF (0x6e, adjust_addr, ror)
opMF (0x6f, read_long, adc)
opAII(0x70, branch, 0x40, true)
opMF (0x71, read_idpy, adc)
opMF (0x72, read_idp, adc)
opMF (0x73, read_isry, adc)
opMII(0x74, write_dpr, Z, X)
opMFI(0x75, read_dpr, adc, X)
opMF (0x76, adjust_dpx, ror)
opMF (0x77, read_ildpy, adc)
opAII(0x78, flag, 0x04, 0x04)
opMF (0x79, read_addry, adc)
opXI (0x7a, pull, Y)
opAII(0x7b, transfer_w, D, A)
opA (0x7c, jmp_iaddrx)
opMF (0x7d, read_addrx, adc)
opMF (0x7e, adjust_addrx, ror)
opMF (0x7f, read_longx, adc)
opA (0x80, bra)
opM (0x81, sta_idpx)
opA (0x82, brl)
opM (0x83, sta_sr)
opXI (0x84, write_dp, Y)
opMI (0x85, write_dp, A)
opXI (0x86, write_dp, X)
opM (0x87, sta_ildp)
opXII(0x88, adjust_imm, Y, -1)
opM (0x89, read_bit_const)
opMII(0x8a, transfer, X, A)
opA (0x8b, phb)
opXI (0x8c, write_addr, Y)
opMI (0x8d, write_addr, A)
opXI (0x8e, write_addr, X)
opMI (0x8f, write_longr, Z)
opAII(0x90, branch, 0x01, false)
opM (0x91, sta_idpy)
opM (0x92, sta_idp)
opM (0x93, sta_isry)
opXII(0x94, write_dpr, Y, X)
opMII(0x95, write_dpr, A, X)
opXII(0x96, write_dpr, X, Y)
opM (0x97, sta_ildpy)
opMII(0x98, transfer, Y, A)
opMII(0x99, write_addrr, A, Y)
opE (0x9a, txs)
opXII(0x9b, transfer, X, Y)
opMI (0x9c, write_addr, Z)
opMII(0x9d, write_addrr, A, X)
opMII(0x9e, write_addrr, Z, X)
opMI (0x9f, write_longr, X)
opXF (0xa0, read_const, ldy)
opMF (0xa1, read_idpx, lda)
opXF (0xa2, read_const, ldx)
opMF (0xa3, read_sr, lda)
opXF (0xa4, read_dp, ldy)
opMF (0xa5, read_dp, lda)
opXF (0xa6, read_dp, ldx)
opMF (0xa7, read_ildp, lda)
opXII(0xa8, transfer, A, Y)
opMF (0xa9, read_const, lda)
opXII(0xaa, transfer, A, X)
opA (0xab, plb)
opXF (0xac, read_addr, ldy)
opMF (0xad, read_addr, lda)
opXF (0xae, read_addr, ldx)
opMF (0xaf, read_long, lda)
opAII(0xb0, branch, 0x01, true)
opMF (0xb1, read_idpy, lda)
opMF (0xb2, read_idp, lda)
opMF (0xb3, read_isry, lda)
opXFI(0xb4, read_dpr, ldy, X)
opMFI(0xb5, read_dpr, lda, X)
opXFI(0xb6, read_dpr, ldx, Y)
opMF (0xb7, read_ildpy, lda)
opAII(0xb8, flag, 0x40, 0x00)
opMF (0xb9, read_addry, lda)
opX (0xba, tsx)
opXII(0xbb, transfer, Y, X)
opXF (0xbc, read_addrx, ldy)
opMF (0xbd, read_addrx, lda)
opXF (0xbe, read_addry, ldx)
opMF (0xbf, read_longx, lda)
opXF (0xc0, read_const, cpy)
opMF (0xc1, read_idpx, cmp)
opEI (0xc2, pflag, 0)
opMF (0xc3, read_sr, cmp)
opXF (0xc4, read_dp, cpy)
opMF (0xc5, read_dp, cmp)
opMF (0xc6, adjust_dp, dec)
opMF (0xc7, read_ildp, cmp)
opXII(0xc8, adjust_imm, Y, +1)
opMF (0xc9, read_const, cmp)
opXII(0xca, adjust_imm, X, -1)
opA (0xcb, wai)
opXF (0xcc, read_addr, cpy)
opMF (0xcd, read_addr, cmp)
opMF (0xce, adjust_addr, dec)
opMF (0xcf, read_long, cmp)
opAII(0xd0, branch, 0x02, false)
opMF (0xd1, read_idpy, cmp)
opMF (0xd2, read_idp, cmp)
opMF (0xd3, read_isry, cmp)
opE (0xd4, pei)
opMFI(0xd5, read_dpr, cmp, X)
opMF (0xd6, adjust_dpx, dec)
opMF (0xd7, read_ildpy, cmp)
opAII(0xd8, flag, 0x08, 0x00)
opMF (0xd9, read_addry, cmp)
opXI (0xda, push, X)
opA (0xdb, stp)
opA (0xdc, jmp_iladdr)
opMF (0xdd, read_addrx, cmp)
opMF (0xde, adjust_addrx, dec)
opMF (0xdf, read_longx, cmp)
opXF (0xe0, read_const, cpx)
opMF (0xe1, read_idpx, sbc)
opEI (0xe2, pflag, 1)
opMF (0xe3, read_sr, sbc)
opXF (0xe4, read_dp, cpx)
opMF (0xe5, read_dp, sbc)
opMF (0xe6, adjust_dp, inc)
opMF (0xe7, read_ildp, sbc)
opXII(0xe8, adjust_imm, X, +1)
opMF (0xe9, read_const, sbc)
opA (0xea, nop)
opA (0xeb, xba)
opXF (0xec, read_addr, cpx)
opMF (0xed, read_addr, sbc)
opMF (0xee, adjust_addr, inc)
opMF (0xef, read_long, sbc)
opAII(0xf0, branch, 0x02, true)
opMF (0xf1, read_idpy, sbc)
opMF (0xf2, read_idp, sbc)
opMF (0xf3, read_isry, sbc)
opE (0xf4, pea)
opMFI(0xf5, read_dpr, sbc, X)
opMF (0xf6, adjust_dpx, inc)
opMF (0xf7, read_ildpy, sbc)
opAII(0xf8, flag, 0x08, 0x08)
opMF (0xf9, read_addry, sbc)
opXI (0xfa, pull, X)
opA (0xfb, xce)
opE (0xfc, jsr_iaddrx)
opMF (0xfd, read_addrx, sbc)
opMF (0xfe, adjust_addrx, inc)
opMF (0xff, read_longx, sbc)
#undef opA
#undef opAII
#undef opE
#undef opEI
#undef opEII
#undef opM
#undef opMI
#undef opMII
#undef opMF
#undef opMFI
#undef opX
#undef opXI
#undef opXII
#undef opXF
#undef opXFI
}
void R65816::update_table() {
if(regs.e) {
opcode_table = &op_table[table_EM];
} else if(regs.p.m) {
if(regs.p.x) {
opcode_table = &op_table[table_MX];
} else {
opcode_table = &op_table[table_Mx];
}
} else {
if(regs.p.x) {
opcode_table = &op_table[table_mX];
} else {
opcode_table = &op_table[table_mx];
}
}
}

View File

@ -4,9 +4,6 @@
auto CALLBACK RawInputWindowProc(HWND, UINT, WPARAM, LPARAM) -> LRESULT;
struct RawInput {
Input& input;
RawInput(Input& input) : input(input) {}
HANDLE mutex = nullptr;
HWND hwnd = nullptr;
bool ready = false;

View File

@ -12,12 +12,12 @@
#include "mouse/xlib.cpp"
#include "joypad/udev.cpp"
struct InputUdev : input {
struct InputUdev : Input {
InputKeyboardXlib xlibKeyboard;
InputMouseXlib xlibMouse;
InputJoypadUdev udev;
Input() : xlibKeyboard(*this), xlibMouse(*this), udev(*this) {}
~Input() { term(); }
InputUdev() : xlibKeyboard(*this), xlibMouse(*this), udev(*this) {}
~InputUdev() { term(); }
struct Settings {
uintptr_t handle = 0;

View File

@ -103,7 +103,3 @@ struct InputWindows : Input {
if(directinputContext) { directinputContext->Release(); directinputContext = nullptr; }
}
};
DeclareInput(Windows)
}

View File

@ -8,16 +8,16 @@ using namespace ruby;
#undef mkdir
#undef usleep
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#elif defined(PLATFORM_MACOSX)
#elif defined(DISPLAY_QUARTZ)
#define decimal CocoaDecimal
#include <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
#undef decimal
#elif defined(PLATFORM_WINDOWS)
#elif defined(DISPLAY_WINDOWS)
#include <windows.h>
#endif

View File

@ -1,8 +1,4 @@
#if defined(PLATFORM_MACOSX)
static bool OpenGLBind() {
return true;
}
#else
#if defined(DISPLAY_WINDOWS) || defined(DISPLAY_XORG)
PFNGLCREATEPROGRAMPROC glCreateProgram = nullptr;
PFNGLDELETEPROGRAMPROC glDeleteProgram = nullptr;
PFNGLUSEPROGRAMPROC glUseProgram = nullptr;
@ -43,12 +39,17 @@ PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = nullptr;
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = nullptr;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = nullptr;
PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = nullptr;
#endif
#if defined(DISPLAY_WINDOWS)
PFNGLACTIVETEXTUREPROC glActiveTexture = nullptr;
#endif
static bool OpenGLBind() {
#define bind(prototype, function) \
function = (prototype)glGetProcAddress(#function); \
if(function == nullptr) return false
#if defined(DISPLAY_WINDOWS) || defined(DISPLAY_XORG)
bind(PFNGLCREATEPROGRAMPROC, glCreateProgram);
bind(PFNGLDELETEPROGRAMPROC, glDeleteProgram);
bind(PFNGLUSEPROGRAMPROC, glUseProgram);
@ -89,9 +90,12 @@ static bool OpenGLBind() {
bind(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers);
bind(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer);
bind(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D);
#endif
#if defined(DISPLAY_WINDOWS)
bind(PFNGLACTIVETEXTUREPROC, glActiveTexture);
#endif
#undef bind
return true;
}
#endif

View File

@ -1,11 +1,11 @@
#if defined(PLATFORM_XORG)
#if defined(DISPLAY_XORG)
#include <GL/gl.h>
#include <GL/glx.h>
#define glGetProcAddress(name) (*glXGetProcAddress)((const GLubyte*)(name))
#elif defined(PLATFORM_MACOSX)
#elif defined(DISPLAY_QUARTZ)
#include <OpenGL/gl.h>
#include <OpenGL/gl3.h>
#elif defined(PLATFORM_WINDOWS)
#elif defined(DISPLAY_WINDOWS)
#include <GL/gl.h>
#include <GL/glext.h>
#define glGetProcAddress(name) wglGetProcAddress(name)

View File

@ -1,7 +1,7 @@
#ifdef PPU_CPP
unsigned PPU::Screen::get_palette(unsigned color) {
#if defined(ARCH_LSB)
#if defined(ENDIAN_LSB)
return ((uint16*)ppu.cgram)[color];
#else
color <<= 1;

View File

@ -32,7 +32,7 @@ void SA1::enter() {
continue;
}
(this->*opcode_table[op_readpc()])();
op_exec();
}
}
@ -152,7 +152,6 @@ void SA1::reset() {
regs.mdr = 0x00;
regs.wai = false;
regs.vector = 0x0000;
R65816::update_table();
status.tick_counter = 0;

View File

@ -86,7 +86,7 @@ void CPU::enter() {
void CPU::op_step() {
debugger.op_exec(regs.pc.d);
(this->*opcode_table[op_readpc()])();
op_exec();
}
void CPU::enable() {
@ -141,7 +141,6 @@ void CPU::reset() {
regs.mdr = 0x00;
regs.wai = false;
regs.vector = 0xfffc; //reset vector address
update_table();
mmio_reset();
dma_reset();