mirror of https://github.com/bsnes-emu/bsnes.git
Update to v076 release.
byuu says: Most notable in this release is that sound support has been added to my own Super Game Boy emulation. The GUI toolkit, phoenix, has also received a complete rewrite; with the most visible change there being that windows are now resizable. Changelog (since v075): * added sound emulation to Game Boy core * fixed Super Game Boy save state * support added HexEdit widget to Windows and Qt targets; debugger can now be compiled on all platforms * entering fullscreen now auto-hides mouse; and mouse capture is toggled otherwise by F12 key * fullscreen command and geometry caching works much better on GTK+ and Qt targets * phoenix rewritten from scratch; now supports resizable layout containers * phoenix/Windows no longer relies on buggy SetParent API to reparent widgets
This commit is contained in:
parent
017f9926fc
commit
64072325c4
|
@ -1,7 +1,7 @@
|
|||
include nall/Makefile
|
||||
snes := snes
|
||||
gameboy := gameboy
|
||||
profile := compatibility
|
||||
profile := accuracy
|
||||
ui := ui
|
||||
|
||||
# compiler
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,7 +30,8 @@
|
|||
Geometry pOS::availableGeometry() {
|
||||
//TODO: is there a GTK+ function for this?
|
||||
//should return desktopGeometry() sans panels, toolbars, docks, etc.
|
||||
return desktopGeometry();
|
||||
Geometry geometry = desktopGeometry();
|
||||
return { geometry.x + 64, geometry.y + 64, geometry.width - 128, geometry.height - 128 };
|
||||
}
|
||||
|
||||
Geometry pOS::desktopGeometry() {
|
||||
|
|
|
@ -3,6 +3,8 @@ struct Settings : public configuration {
|
|||
unsigned frameGeometryY;
|
||||
unsigned frameGeometryWidth;
|
||||
unsigned frameGeometryHeight;
|
||||
unsigned menuGeometryHeight;
|
||||
unsigned statusGeometryHeight;
|
||||
|
||||
void load();
|
||||
void save();
|
||||
|
@ -89,7 +91,8 @@ struct pWindow : public pObject {
|
|||
|
||||
pWindow(Window &window) : window(window) {}
|
||||
void constructor();
|
||||
void updateFrameGeometry();
|
||||
unsigned menuHeight();
|
||||
unsigned statusHeight();
|
||||
};
|
||||
|
||||
struct pAction : public pObject {
|
||||
|
|
|
@ -15,8 +15,10 @@ void Settings::save() {
|
|||
}
|
||||
|
||||
Settings::Settings() {
|
||||
attach(frameGeometryX = 0, "frameGeometryX");
|
||||
attach(frameGeometryY = 0, "frameGeometryY");
|
||||
attach(frameGeometryWidth = 0, "frameGeometryWidth");
|
||||
attach(frameGeometryHeight = 0, "frameGeometryHeight");
|
||||
attach(frameGeometryX = 4, "frameGeometryX");
|
||||
attach(frameGeometryY = 24, "frameGeometryY");
|
||||
attach(frameGeometryWidth = 8, "frameGeometryWidth");
|
||||
attach(frameGeometryHeight = 28, "frameGeometryHeight");
|
||||
attach(menuGeometryHeight = 20, "menuGeometryHeight");
|
||||
attach(statusGeometryHeight = 20, "statusGeometryHeight");
|
||||
}
|
||||
|
|
|
@ -7,13 +7,39 @@ static gint Window_close(Window *window) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static gboolean Window_configure(GtkWindow *widget, GdkEvent *event, Window *window) {
|
||||
static gboolean Window_configure(Window *window) {
|
||||
if(gtk_widget_get_realized(window->p.widget) == false) return false;
|
||||
window->p.updateFrameGeometry();
|
||||
|
||||
signed eventX = event->configure.x, eventY = event->configure.y;
|
||||
unsigned eventWidth = event->configure.width, eventHeight = event->configure.height;
|
||||
//update geometry settings
|
||||
Display *display = XOpenDisplay(0);
|
||||
XWindowAttributes attributes, parentAttributes;
|
||||
XGetWindowAttributes(display, GDK_WINDOW_XID(window->p.widget->window), &attributes);
|
||||
X11Window rootWindow, parentWindow, *childWindow = 0;
|
||||
unsigned int childCount;
|
||||
XQueryTree(display, GDK_WINDOW_XID(window->p.widget->window), &rootWindow, &parentWindow, &childWindow, &childCount);
|
||||
XGetWindowAttributes(display, parentWindow, &parentAttributes);
|
||||
if(childWindow) XFree(childWindow);
|
||||
XCloseDisplay(display);
|
||||
|
||||
settings.frameGeometryX = attributes.x;
|
||||
settings.frameGeometryY = attributes.y;
|
||||
settings.frameGeometryWidth = parentAttributes.width - attributes.width;
|
||||
settings.frameGeometryHeight = parentAttributes.height - attributes.height;
|
||||
|
||||
GtkAllocation menuAllocation, statusAllocation;
|
||||
gtk_widget_get_allocation(window->p.menu, &menuAllocation);
|
||||
gtk_widget_get_allocation(window->p.status, &statusAllocation);
|
||||
|
||||
if(menuAllocation.height > 1) settings.menuGeometryHeight = menuAllocation.height;
|
||||
if(statusAllocation.height > 1) settings.statusGeometryHeight = statusAllocation.height;
|
||||
|
||||
//calculate current window position
|
||||
signed eventX = parentAttributes.x + attributes.x;
|
||||
signed eventY = parentAttributes.y + attributes.y + window->p.menuHeight();
|
||||
unsigned eventWidth = attributes.width;
|
||||
unsigned eventHeight = attributes.height - window->p.menuHeight() - window->p.statusHeight();
|
||||
|
||||
//move
|
||||
if(window->p.locked == false && window->state.fullScreen == false) {
|
||||
if(window->state.geometry.x != eventX || window->state.geometry.y != eventY) {
|
||||
window->state.geometry.x = eventX;
|
||||
|
@ -23,9 +49,7 @@ static gboolean Window_configure(GtkWindow *widget, GdkEvent *event, Window *win
|
|||
|
||||
if(window->onMove) window->onMove();
|
||||
|
||||
eventHeight -= window->state.menuVisible ? window->p.menu->allocation.height : 0;
|
||||
eventHeight -= window->state.statusVisible ? window->p.status->allocation.height : 0;
|
||||
|
||||
//size
|
||||
if(window->p.locked == false && window->state.fullScreen == false) {
|
||||
if(window->state.geometry.width != eventWidth || window->state.geometry.height != eventHeight) {
|
||||
window->state.geometry.width = eventWidth;
|
||||
|
@ -40,6 +64,7 @@ static gboolean Window_configure(GtkWindow *widget, GdkEvent *event, Window *win
|
|||
}
|
||||
|
||||
if(window->onSize) window->onSize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -66,14 +91,12 @@ void pWindow::append(Widget &widget) {
|
|||
}
|
||||
|
||||
Geometry pWindow::frameMargin() {
|
||||
unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0;
|
||||
unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0;
|
||||
if(window.state.fullScreen) return { 0, menuHeight, 0, menuHeight + statusHeight };
|
||||
if(window.state.fullScreen) return { 0, menuHeight(), 0, menuHeight() + statusHeight() };
|
||||
return {
|
||||
settings.frameGeometryX,
|
||||
settings.frameGeometryY + menuHeight,
|
||||
settings.frameGeometryY + menuHeight(),
|
||||
settings.frameGeometryWidth,
|
||||
settings.frameGeometryHeight + menuHeight + statusHeight
|
||||
settings.frameGeometryHeight + menuHeight() + statusHeight()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -83,9 +106,7 @@ bool pWindow::focused() {
|
|||
|
||||
Geometry pWindow::geometry() {
|
||||
if(window.state.fullScreen == true) {
|
||||
unsigned menuHeight = window.state.menuVisible ? menu->allocation.height : 0;
|
||||
unsigned statusHeight = window.state.statusVisible ? status->allocation.height : 0;
|
||||
return { 0, menuHeight, OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight - statusHeight };
|
||||
return { 0, menuHeight(), OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight() - statusHeight() };
|
||||
};
|
||||
return window.state.geometry;
|
||||
}
|
||||
|
@ -204,24 +225,13 @@ void pWindow::constructor() {
|
|||
setGeometry(window.state.geometry);
|
||||
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window);
|
||||
g_signal_connect(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window);
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window);
|
||||
}
|
||||
|
||||
void pWindow::updateFrameGeometry() {
|
||||
#if defined(PLATFORM_X)
|
||||
Display *display = XOpenDisplay(0);
|
||||
XWindowAttributes attributes, parentAttributes;
|
||||
XGetWindowAttributes(display, GDK_WINDOW_XID(widget->window), &attributes);
|
||||
X11Window rootWindow, parentWindow, *childWindow = 0;
|
||||
unsigned int childCount;
|
||||
XQueryTree(display, GDK_WINDOW_XID(widget->window), &rootWindow, &parentWindow, &childWindow, &childCount);
|
||||
XGetWindowAttributes(display, parentWindow, &parentAttributes);
|
||||
if(childWindow) XFree(childWindow);
|
||||
XCloseDIsplay(display);
|
||||
|
||||
settings.frameGeometryX = attributes.x;
|
||||
settings.frameGeometryY = attributes.y;
|
||||
settings.frameGeometryWidth = parentAttributes.width - attributes.width;
|
||||
settings.frameGeometryHeight = parentAttributes.height - attributes.height;
|
||||
#endif
|
||||
unsigned pWindow::menuHeight() {
|
||||
return window.state.menuVisible ? settings.menuGeometryHeight : 0;
|
||||
}
|
||||
|
||||
unsigned pWindow::statusHeight() {
|
||||
return window.state.statusVisible ? settings.statusGeometryHeight : 0;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ void pComboBox::constructor() {
|
|||
|
||||
void pComboBox::setGeometry(const Geometry &geometry) {
|
||||
SetWindowPos(hwnd, NULL, geometry.x, geometry.y, geometry.width, 1, SWP_NOZORDER);
|
||||
//RECT rc;
|
||||
//GetWindowRect(hwnd, &rc);
|
||||
//unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
|
||||
//SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
|
||||
RECT rc;
|
||||
GetWindowRect(hwnd, &rc);
|
||||
unsigned adjustedHeight = geometry.height - ((rc.bottom - rc.top) - SendMessage(hwnd, CB_GETITEMHEIGHT, (WPARAM)-1, 0));
|
||||
SendMessage(hwnd, CB_SETITEMHEIGHT, (WPARAM)-1, adjustedHeight);
|
||||
}
|
||||
|
||||
void pComboBox::setParent(Window &parent) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
static const unsigned FixedStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER;
|
||||
static const unsigned ResizableStyle = WS_CLIPCHILDREN | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
|
||||
static const unsigned FixedStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_BORDER;
|
||||
static const unsigned ResizableStyle = WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
|
||||
|
||||
void pWindow::append(Layout &layout) {
|
||||
layout.setParent(window);
|
||||
|
|
|
@ -180,7 +180,7 @@ void pOS::initialize() {
|
|||
wc.lpfnWndProc = OS_windowProc;
|
||||
wc.lpszClassName = L"phoenix_window";
|
||||
wc.lpszMenuName = 0;
|
||||
wc.style = 0;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
RegisterClass(&wc);
|
||||
|
||||
wc.cbClsExtra = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace SNES {
|
||||
namespace Info {
|
||||
static const char Name[] = "bsnes";
|
||||
static const char Version[] = "075.16";
|
||||
static const char Version[] = "076";
|
||||
static const unsigned SerializerVersion = 18;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ include nall/Makefile
|
|||
|
||||
c := $(compiler) -std=gnu99
|
||||
cpp := $(subst cc,++,$(compiler)) -std=gnu++0x
|
||||
flags := -O3 -I. -Iobj -fomit-frame-pointer -fPIC
|
||||
flags := -O3 -I. -Iobj -fomit-frame-pointer
|
||||
link := -s
|
||||
objects :=
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c phoenix/phoenix.cpp `pkg-config --cflags gtk+-2.0` -DPHOENIX_GTK
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c snespurify.cpp -DPHOENIX_GTK
|
||||
g++-4.5 -s -o snespurify snespurify.o phoenix.o `pkg-config --libs gtk+-2.0`
|
||||
g++-4.5 -s -o snespurify snespurify.o phoenix.o `pkg-config --libs gtk+-2.0` -lX11
|
||||
rm *.o
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
moc -i -o phoenix/qt/qt.moc phoenix/qt/qt.moc.hpp
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c phoenix/phoenix.cpp `pkg-config --cflags QtCore QtGui` -DPHOENIX_QT
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c snespurify.cpp -DPHOENIX_QT
|
||||
g++-4.5 -s -o snespurify snespurify.o phoenix.o `pkg-config --libs QtCore QtGui`
|
||||
rm *.o
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
namespace nall {
|
||||
template<int bits> inline unsigned uclamp(const unsigned x) {
|
||||
enum { y = (1U << bits) - 1 };
|
||||
enum { y = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
|
||||
return y + ((x - y) & -(x < y)); //min(x, y);
|
||||
}
|
||||
|
||||
template<int bits> inline unsigned uclip(const unsigned x) {
|
||||
enum { m = (1U << bits) - 1 };
|
||||
enum { m = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
|
||||
return (x & m);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace nall {
|
|||
void set(string s) {
|
||||
switch(type) {
|
||||
case boolean_t: *(bool*)data = (s == "true"); break;
|
||||
case signed_t: *(signed*)data = strsigned(s); break;
|
||||
case unsigned_t: *(unsigned*)data = strunsigned(s); break;
|
||||
case double_t: *(double*)data = strdouble(s); break;
|
||||
case signed_t: *(signed*)data = integer(s); break;
|
||||
case unsigned_t: *(unsigned*)data = decimal(s); break;
|
||||
case double_t: *(double*)data = fp(s); break;
|
||||
case string_t: s.trim("\""); *(string*)data = s; break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace nall {
|
|||
struct library {
|
||||
bool opened() const { return handle; }
|
||||
bool open(const char*, const char* = "");
|
||||
bool open_absolute(const char*);
|
||||
void* sym(const char*);
|
||||
void close();
|
||||
|
||||
|
@ -40,6 +41,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(name, RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return dlsym((void*)handle, name);
|
||||
|
@ -58,6 +65,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(name, RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return dlsym((void*)handle, name);
|
||||
|
@ -76,6 +89,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)LoadLibraryW(utf16_t(name));
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return (void*)GetProcAddress((HMODULE)handle, name);
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
#include <nall/concept.hpp>
|
||||
|
||||
#undef foreach
|
||||
#define foreach(iter, object) \
|
||||
|
||||
#define foreach2(iter, object) foreach3(iter, object, foreach_counter)
|
||||
#define foreach3(iter, object, foreach_counter) \
|
||||
for(unsigned foreach_counter = 0, foreach_limit = container_size(object), foreach_once = 0, foreach_broken = 0; foreach_counter < foreach_limit && foreach_broken == 0; foreach_counter++, foreach_once = 0) \
|
||||
for(auto &iter = object[foreach_counter]; foreach_once == 0 && (foreach_broken = 1); foreach_once++, foreach_broken = 0)
|
||||
|
||||
#define foreach_impl(...) foreach_decl(__VA_ARGS__, foreach3(__VA_ARGS__), foreach2(__VA_ARGS__), foreach_too_few_arguments)
|
||||
#define foreach_decl(_1, _2, _3, N, ...) N
|
||||
#define foreach(...) foreach_impl(__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace nall {
|
|||
};
|
||||
|
||||
template<typename L> struct lambda : container {
|
||||
L object;
|
||||
mutable L object;
|
||||
R operator()(P... p) const { return object(std::forward<P>(p)...); }
|
||||
container* copy() const { return new lambda(object); }
|
||||
lambda(const L& object) : object(object) {}
|
||||
|
@ -46,7 +46,7 @@ namespace nall {
|
|||
return *this;
|
||||
}
|
||||
|
||||
function(const function &source) { operator=(source); }
|
||||
function(const function &source) : callback(0) { operator=(source); }
|
||||
function() : callback(0) {}
|
||||
function(void *function) : callback(0) { if(function) callback = new global((R (*)(P...))function); }
|
||||
function(R (*function)(P...)) { callback = new global(function); }
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
#ifndef NALL_GAMEBOY_CARTRIDGE_HPP
|
||||
#define NALL_GAMEBOY_CARTRIDGE_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
class GameBoyCartridge {
|
||||
public:
|
||||
string xml;
|
||||
inline GameBoyCartridge(const uint8_t *data, unsigned size);
|
||||
|
||||
//private:
|
||||
struct Information {
|
||||
string mapper;
|
||||
bool ram;
|
||||
bool battery;
|
||||
bool rtc;
|
||||
bool rumble;
|
||||
|
||||
unsigned romsize;
|
||||
unsigned ramsize;
|
||||
} info;
|
||||
};
|
||||
|
||||
GameBoyCartridge::GameBoyCartridge(const uint8_t *romdata, unsigned romsize) {
|
||||
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
if(romsize < 0x4000) return;
|
||||
|
||||
info.mapper = "unknown";
|
||||
info.ram = false;
|
||||
info.battery = false;
|
||||
info.rtc = false;
|
||||
info.rumble = false;
|
||||
|
||||
info.romsize = 0;
|
||||
info.ramsize = 0;
|
||||
|
||||
switch(romdata[0x0147]) {
|
||||
case 0x00: info.mapper = "none"; break;
|
||||
case 0x01: info.mapper = "MBC1"; break;
|
||||
case 0x02: info.mapper = "MBC1"; info.ram = true; break;
|
||||
case 0x03: info.mapper = "MBC1"; info.ram = true; info.battery = true; break;
|
||||
case 0x05: info.mapper = "MBC2"; info.ram = true; break;
|
||||
case 0x06: info.mapper = "MBC2"; info.ram = true; info.battery = true; break;
|
||||
case 0x08: info.mapper = "none"; info.ram = true; break;
|
||||
case 0x09: info.mapper = "MBC0"; info.ram = true; info.battery = true; break;
|
||||
case 0x0b: info.mapper = "MMM01"; break;
|
||||
case 0x0c: info.mapper = "MMM01"; info.ram = true; break;
|
||||
case 0x0d: info.mapper = "MMM01"; info.ram = true; info.battery = true; break;
|
||||
case 0x0f: info.mapper = "MBC3"; info.rtc = true; info.battery = true; break;
|
||||
case 0x10: info.mapper = "MBC3"; info.rtc = true; info.ram = true; info.battery = true; break;
|
||||
case 0x11: info.mapper = "MBC3"; break;
|
||||
case 0x12: info.mapper = "MBC3"; info.ram = true; break;
|
||||
case 0x13: info.mapper = "MBC3"; info.ram = true; info.battery = true; break;
|
||||
case 0x19: info.mapper = "MBC5"; break;
|
||||
case 0x1a: info.mapper = "MBC5"; info.ram = true; break;
|
||||
case 0x1b: info.mapper = "MBC5"; info.ram = true; info.battery = true; break;
|
||||
case 0x1c: info.mapper = "MBC5"; info.rumble = true; break;
|
||||
case 0x1d: info.mapper = "MBC5"; info.rumble = true; info.ram = true; break;
|
||||
case 0x1e: info.mapper = "MBC5"; info.rumble = true; info.ram = true; info.battery = true; break;
|
||||
case 0xfc: break; //Pocket Camera
|
||||
case 0xfd: break; //Bandai TAMA5
|
||||
case 0xfe: info.mapper = "HuC3"; break;
|
||||
case 0xff: info.mapper = "HuC1"; info.ram = true; info.battery = true; break;
|
||||
}
|
||||
|
||||
switch(romdata[0x0148]) { default:
|
||||
case 0x00: info.romsize = 2 * 16 * 1024; break;
|
||||
case 0x01: info.romsize = 4 * 16 * 1024; break;
|
||||
case 0x02: info.romsize = 8 * 16 * 1024; break;
|
||||
case 0x03: info.romsize = 16 * 16 * 1024; break;
|
||||
case 0x04: info.romsize = 32 * 16 * 1024; break;
|
||||
case 0x05: info.romsize = 64 * 16 * 1024; break;
|
||||
case 0x06: info.romsize = 128 * 16 * 1024; break;
|
||||
case 0x07: info.romsize = 256 * 16 * 1024; break;
|
||||
case 0x52: info.romsize = 72 * 16 * 1024; break;
|
||||
case 0x53: info.romsize = 80 * 16 * 1024; break;
|
||||
case 0x54: info.romsize = 96 * 16 * 1024; break;
|
||||
}
|
||||
|
||||
switch(romdata[0x0149]) { default:
|
||||
case 0x00: info.ramsize = 0 * 1024; break;
|
||||
case 0x01: info.ramsize = 2 * 1024; break;
|
||||
case 0x02: info.ramsize = 8 * 1024; break;
|
||||
case 0x03: info.ramsize = 32 * 1024; break;
|
||||
}
|
||||
|
||||
if(info.mapper == "MBC2") info.ramsize = 512; //512 x 4-bit
|
||||
|
||||
xml << "<cartridge mapper='" << info.mapper << "'";
|
||||
if(info.rtc) xml << " rtc='true'";
|
||||
if(info.rumble) xml << " rumble='true'";
|
||||
xml << ">\n";
|
||||
|
||||
xml << " <rom size='" << hex(romsize) << "'/>\n"; //TODO: trust/check info.romsize?
|
||||
|
||||
if(info.ramsize > 0)
|
||||
xml << " <ram size='" << hex(info.ramsize) << "' battery='" << info.battery << "'/>\n";
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -92,7 +92,7 @@ struct Keyboard {
|
|||
string s(name);
|
||||
if(!strbegin(name, "KB")) return 0;
|
||||
s.ltrim("KB");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
@ -189,7 +189,7 @@ struct Mouse {
|
|||
string s(name);
|
||||
if(!strbegin(name, "MS")) return 0;
|
||||
s.ltrim("MS");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
@ -313,7 +313,7 @@ struct Joypad {
|
|||
string s(name);
|
||||
if(!strbegin(name, "JP")) return 0;
|
||||
s.ltrim("JP");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef NALL_PUBLIC_CAST_HPP
|
||||
#define NALL_PUBLIC_CAST_HPP
|
||||
|
||||
//this is a proof-of-concept-*only* C++ access-privilege elevation exploit.
|
||||
//this code is 100% legal C++, per C++98 section 14.7.2 paragraph 8:
|
||||
//"access checking rules do not apply to names in explicit instantiations."
|
||||
//usage example:
|
||||
|
||||
//struct N { typedef void (Class::*)(); };
|
||||
//template class public_cast<N, &Class::Reference>;
|
||||
//(class.*public_cast<N>::value);
|
||||
|
||||
//Class::Reference may be public, protected or private
|
||||
//Class::Reference may be a function, object or variable
|
||||
|
||||
namespace nall {
|
||||
template<typename T, typename T::type... P> struct public_cast;
|
||||
|
||||
template<typename T> struct public_cast<T> {
|
||||
static typename T::type value;
|
||||
};
|
||||
|
||||
template<typename T> typename T::type public_cast<T>::value;
|
||||
|
||||
template<typename T, typename T::type P> struct public_cast<T, P> {
|
||||
static typename T::type value;
|
||||
};
|
||||
|
||||
template<typename T, typename T::type P> typename T::type public_cast<T, P>::value = public_cast<T>::value = P;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef NALL_REFERENCE_ARRAY_HPP
|
||||
#define NALL_REFERENCE_ARRAY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <nall/bit.hpp>
|
||||
#include <nall/concept.hpp>
|
||||
|
||||
namespace nall {
|
||||
template<typename T> struct reference_array {
|
||||
protected:
|
||||
typedef typename std::remove_reference<T>::type *Tptr;
|
||||
Tptr *pool;
|
||||
unsigned poolsize, buffersize;
|
||||
|
||||
public:
|
||||
unsigned size() const { return buffersize; }
|
||||
unsigned capacity() const { return poolsize; }
|
||||
|
||||
void reset() {
|
||||
if(pool) free(pool);
|
||||
pool = 0;
|
||||
poolsize = 0;
|
||||
buffersize = 0;
|
||||
}
|
||||
|
||||
void reserve(unsigned newsize) {
|
||||
if(newsize == poolsize) return;
|
||||
|
||||
pool = (Tptr*)realloc(pool, newsize * sizeof(T));
|
||||
poolsize = newsize;
|
||||
buffersize = min(buffersize, newsize);
|
||||
}
|
||||
|
||||
void resize(unsigned newsize) {
|
||||
if(newsize > poolsize) reserve(bit::round(newsize));
|
||||
buffersize = newsize;
|
||||
}
|
||||
|
||||
void append(const T data) {
|
||||
unsigned index = buffersize++;
|
||||
if(index >= poolsize) resize(index + 1);
|
||||
pool[index] = &data;
|
||||
}
|
||||
|
||||
template<typename... Args> reference_array(Args&... args) : pool(0), poolsize(0), buffersize(0) {
|
||||
construct(args...);
|
||||
}
|
||||
|
||||
~reference_array() {
|
||||
reset();
|
||||
}
|
||||
|
||||
reference_array& operator=(const reference_array &source) {
|
||||
if(pool) free(pool);
|
||||
buffersize = source.buffersize;
|
||||
poolsize = source.poolsize;
|
||||
pool = (Tptr*)malloc(sizeof(T) * poolsize);
|
||||
memcpy(pool, source.pool, sizeof(T) * buffersize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference_array& operator=(const reference_array &&source) {
|
||||
if(pool) free(pool);
|
||||
pool = source.pool;
|
||||
poolsize = source.poolsize;
|
||||
buffersize = source.buffersize;
|
||||
source.pool = 0;
|
||||
source.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline T operator[](unsigned index) {
|
||||
if(index >= buffersize) throw "reference_array[] out of bounds";
|
||||
return *pool[index];
|
||||
}
|
||||
|
||||
inline const T operator[](unsigned index) const {
|
||||
if(index >= buffersize) throw "reference_array[] out of bounds";
|
||||
return *pool[index];
|
||||
}
|
||||
|
||||
private:
|
||||
void construct() {
|
||||
}
|
||||
|
||||
void construct(const reference_array &source) {
|
||||
operator=(source);
|
||||
}
|
||||
|
||||
void construct(const reference_array &&source) {
|
||||
operator=(std::move(source));
|
||||
}
|
||||
|
||||
template<typename... Args> void construct(T data, Args&... args) {
|
||||
append(data);
|
||||
construct(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct has_size<reference_array<T>> { enum { value = true }; };
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef NALL_SNES_INFO_HPP
|
||||
#define NALL_SNES_INFO_HPP
|
||||
#ifndef NALL_SNES_CARTRIDGE_HPP
|
||||
#define NALL_SNES_CARTRIDGE_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
class snes_information {
|
||||
class SNESCartridge {
|
||||
public:
|
||||
string xml_memory_map;
|
||||
|
||||
inline snes_information(const uint8_t *data, unsigned size);
|
||||
string xmlMemoryMap;
|
||||
inline SNESCartridge(const uint8_t *data, unsigned size);
|
||||
|
||||
//private:
|
||||
inline void read_header(const uint8_t *data, unsigned size);
|
||||
|
@ -106,30 +105,30 @@ public:
|
|||
bool has_st018;
|
||||
};
|
||||
|
||||
snes_information::snes_information(const uint8_t *data, unsigned size) {
|
||||
SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
read_header(data, size);
|
||||
|
||||
string xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
|
||||
if(type == TypeBsx) {
|
||||
xml << "<cartridge/>";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TypeSufamiTurbo) {
|
||||
xml << "<cartridge/>";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TypeGameBoy) {
|
||||
xml << "<cartridge rtc='" << gameboy_has_rtc(data, size) << "'>\n";
|
||||
if(gameboy_ram_size(data, size) > 0) {
|
||||
xml << " <ram size='" << strhex(gameboy_ram_size(data, size)) << "'/>\n";
|
||||
xml << " <ram size='" << hex(gameboy_ram_size(data, size)) << "'/>\n";
|
||||
}
|
||||
xml << "</cartridge>\n";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -146,23 +145,19 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='00-7f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-ff:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <supergameboy revision='1'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <icd2 revision='1'>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </supergameboy>\n";
|
||||
xml << " </icd2>\n";
|
||||
} else if(type == TypeSuperGameBoy2Bios) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-7f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-ff:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <supergameboy revision='2'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <icd2 revision='2'>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </supergameboy>\n";
|
||||
xml << " </icd2>\n";
|
||||
} else if(has_spc7110) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='shadow' address='00-0f:8000-ffff'/>\n";
|
||||
|
@ -172,9 +167,9 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
xml << " <spc7110>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <map address='d0-ff:0000-ffff' offset='100000' size='" << strhex(size - 0x100000) << "'/>\n";
|
||||
xml << " <map address='d0-ff:0000-ffff' offset='100000' size='" << hex(size - 0x100000) << "'/>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='30:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -199,7 +194,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -220,7 +215,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -238,7 +233,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='70-7f:0000-7fff'/>\n";
|
||||
|
@ -253,7 +248,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -271,7 +266,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-df:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:6000-7fff' size='2000'/>\n";
|
||||
xml << " <map mode='linear' address='60-7f:0000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:6000-7fff' size='2000'/>\n";
|
||||
|
@ -284,19 +279,23 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </superfx>\n";
|
||||
} else if(mapper == SA1ROM) {
|
||||
xml << " <sa1>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram>\n";
|
||||
xml << " <map mode='direct' address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='direct' address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <iram size='800'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:3000-37ff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:3000-37ff'/>\n";
|
||||
xml << " </iram>\n";
|
||||
xml << " <bwram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <bwram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='40-4f:0000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </bwram>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:2200-23ff'/>\n";
|
||||
|
@ -310,7 +309,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='80-9f:8000-ffff' offset='200000'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:8000-ffff' offset='100000'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='70-7f:0000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='f0-ff:0000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -326,7 +325,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='shadow' address='80-9f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-df:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -339,11 +338,14 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </slot>\n";
|
||||
xml << " </bsx>\n";
|
||||
} else if(mapper == BSXROM) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <bsx>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <map address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map address='40-7f:0000-ffff'/>\n";
|
||||
xml << " <map address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " <map address='20-3f:6000-7fff'/>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:5000-5fff'/>\n";
|
||||
xml << " <map address='80-bf:5000-5fff'/>\n";
|
||||
|
@ -380,10 +382,8 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_srtc) {
|
||||
xml << " <srtc>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:2800-2801'/>\n";
|
||||
xml << " <map address='80-bf:2800-2801'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </srtc>\n";
|
||||
}
|
||||
|
||||
|
@ -401,15 +401,13 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_cx4) {
|
||||
xml << " <cx4>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </cx4>\n";
|
||||
}
|
||||
|
||||
if(has_dsp1) {
|
||||
xml << " <necdsp program='DSP-1B'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp1b.bin' sha256='4d42db0f36faef263d6b93f508e8c1c4ae8fc2605fd35e3390ecc02905cd420c'>\n";
|
||||
if(dsp1_mapper == DSP1LoROM1MB) {
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
|
@ -442,7 +440,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp2) {
|
||||
xml << " <necdsp program='DSP-2'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp2.bin' sha256='5efbdf96ed0652790855225964f3e90e6a4d466cfa64df25b110933c6cf94ea1'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
|
@ -455,7 +453,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp3) {
|
||||
xml << " <necdsp program='DSP-3'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp3.bin' sha256='2e635f72e4d4681148bc35429421c9b946e4f407590e74e31b93b8987b63ba90'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
|
@ -468,7 +466,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp4) {
|
||||
xml << " <necdsp program='DSP-4'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp4.bin' sha256='63ede17322541c191ed1fdf683872554a0a57306496afc43c59de7c01a6e764a'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='30-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='b0-bf:8000-bfff'/>\n";
|
||||
|
@ -482,46 +480,57 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_obc1) {
|
||||
xml << " <obc1>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </obc1>\n";
|
||||
}
|
||||
|
||||
if(has_st010) {
|
||||
xml << " <setadsp program='ST-0010'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <necdsp revision='upd96050' frequency='10000000' program='st0010.bin' sha256='55c697e864562445621cdf8a7bf6e84ae91361e393d382a3704e9aa55559041e'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='60:0000'/>\n";
|
||||
xml << " <map address='e0:0000'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='60:0001'/>\n";
|
||||
xml << " <map address='e0:0001'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " <dp>\n";
|
||||
xml << " <map address='68-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e8-ef:0000-0fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setadsp>\n";
|
||||
xml << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_st011) {
|
||||
//ST-0011 addresses not verified; chip is unsupported
|
||||
xml << " <setadsp program='ST-0011'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <necdsp revision='upd96050' frequency='15000000' program='st0011.bin' sha256='651b82a1e26c4fa8dd549e91e7f923012ed2ca54c1d9fd858655ab30679c2f0e'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='60:0000'/>\n";
|
||||
xml << " <map address='e0:0000'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='60:0001'/>\n";
|
||||
xml << " <map address='e0:0001'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " <dp>\n";
|
||||
xml << " <map address='68-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e8-ef:0000-0fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setadsp>\n";
|
||||
xml << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_st018) {
|
||||
xml << " <setarisc program='ST-0018'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:3800-38ff'/>\n";
|
||||
xml << " <map address='80-bf:3800-38ff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setarisc>\n";
|
||||
}
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
void snes_information::read_header(const uint8_t *data, unsigned size) {
|
||||
void SNESCartridge::read_header(const uint8_t *data, unsigned size) {
|
||||
type = TypeUnknown;
|
||||
mapper = LoROM;
|
||||
dsp1_mapper = DSP1Unmapped;
|
||||
|
@ -749,7 +758,7 @@ void snes_information::read_header(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned snes_information::find_header(const uint8_t *data, unsigned size) {
|
||||
unsigned SNESCartridge::find_header(const uint8_t *data, unsigned size) {
|
||||
unsigned score_lo = score_header(data, size, 0x007fc0);
|
||||
unsigned score_hi = score_header(data, size, 0x00ffc0);
|
||||
unsigned score_ex = score_header(data, size, 0x40ffc0);
|
||||
|
@ -764,7 +773,7 @@ unsigned snes_information::find_header(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned snes_information::score_header(const uint8_t *data, unsigned size, unsigned addr) {
|
||||
unsigned SNESCartridge::score_header(const uint8_t *data, unsigned size, unsigned addr) {
|
||||
if(size < addr + 64) return 0; //image too small to contain header at this location?
|
||||
int score = 0;
|
||||
|
||||
|
@ -845,7 +854,7 @@ unsigned snes_information::score_header(const uint8_t *data, unsigned size, unsi
|
|||
return score;
|
||||
}
|
||||
|
||||
unsigned snes_information::gameboy_ram_size(const uint8_t *data, unsigned size) {
|
||||
unsigned SNESCartridge::gameboy_ram_size(const uint8_t *data, unsigned size) {
|
||||
if(size < 512) return 0;
|
||||
switch(data[0x0149]) {
|
||||
case 0x00: return 0 * 1024;
|
||||
|
@ -858,7 +867,7 @@ unsigned snes_information::gameboy_ram_size(const uint8_t *data, unsigned size)
|
|||
}
|
||||
}
|
||||
|
||||
bool snes_information::gameboy_has_rtc(const uint8_t *data, unsigned size) {
|
||||
bool SNESCartridge::gameboy_has_rtc(const uint8_t *data, unsigned size) {
|
||||
if(size < 512) return false;
|
||||
if(data[0x0147] == 0x0f ||data[0x0147] == 0x10) return true;
|
||||
return false;
|
|
@ -0,0 +1,458 @@
|
|||
#ifndef NALL_SNES_CPU_HPP
|
||||
#define NALL_SNES_CPU_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct SNESCPU {
|
||||
enum : unsigned {
|
||||
Implied, //
|
||||
Constant, //#$00
|
||||
AccumConstant, //#$00
|
||||
IndexConstant, //#$00
|
||||
Direct, //$00
|
||||
DirectX, //$00,x
|
||||
DirectY, //$00,y
|
||||
IDirect, //($00)
|
||||
IDirectX, //($00,x)
|
||||
IDirectY, //($00),y
|
||||
ILDirect, //[$00]
|
||||
ILDirectY, //[$00],y
|
||||
Address, //$0000
|
||||
AddressX, //$0000,x
|
||||
AddressY, //$0000,y
|
||||
IAddressX, //($0000,x)
|
||||
ILAddress, //[$0000]
|
||||
PAddress, //PBR:$0000
|
||||
PIAddress, //PBR:($0000)
|
||||
Long, //$000000
|
||||
LongX, //$000000,x
|
||||
Stack, //$00,s
|
||||
IStackY, //($00,s),y
|
||||
BlockMove, //$00,$00
|
||||
RelativeShort, //+/- $00
|
||||
RelativeLong, //+/- $0000
|
||||
};
|
||||
|
||||
struct OpcodeInfo {
|
||||
char name[4];
|
||||
unsigned mode;
|
||||
};
|
||||
|
||||
static const OpcodeInfo opcodeInfo[256];
|
||||
|
||||
static unsigned getOpcodeLength(bool accum, bool index, uint8_t opcode);
|
||||
static string disassemble(unsigned pc, bool accum, bool index, uint8_t opcode, uint8_t pl, uint8_t ph, uint8_t pb);
|
||||
};
|
||||
|
||||
const SNESCPU::OpcodeInfo SNESCPU::opcodeInfo[256] = {
|
||||
//0x00 - 0x0f
|
||||
{ "brk", Constant },
|
||||
{ "ora", IDirectX },
|
||||
{ "cop", Constant },
|
||||
{ "ora", Stack },
|
||||
|
||||
{ "tsb", Direct },
|
||||
{ "ora", Direct },
|
||||
{ "asl", Direct },
|
||||
{ "ora", ILDirect },
|
||||
|
||||
{ "php", Implied },
|
||||
{ "ora", AccumConstant },
|
||||
{ "asl", Implied },
|
||||
{ "phd", Implied },
|
||||
|
||||
{ "tsb", Address },
|
||||
{ "ora", Address },
|
||||
{ "asl", Address },
|
||||
{ "ora", Long },
|
||||
|
||||
//0x10 - 0x1f
|
||||
{ "bpl", RelativeShort },
|
||||
{ "ora", IDirectY },
|
||||
{ "ora", IDirect },
|
||||
{ "ora", IStackY },
|
||||
|
||||
{ "trb", Direct },
|
||||
{ "ora", DirectX },
|
||||
{ "asl", DirectX },
|
||||
{ "ora", ILDirectY },
|
||||
|
||||
{ "clc", Implied },
|
||||
{ "ora", AddressY },
|
||||
{ "inc", Implied },
|
||||
{ "tcs", Implied },
|
||||
|
||||
{ "trb", Address },
|
||||
{ "ora", AddressX },
|
||||
{ "asl", AddressX },
|
||||
{ "ora", LongX },
|
||||
|
||||
//0x20 - 0x2f
|
||||
{ "jsr", Address },
|
||||
{ "and", IDirectX },
|
||||
{ "jsl", Long },
|
||||
{ "and", Stack },
|
||||
|
||||
{ "bit", Direct },
|
||||
{ "and", Direct },
|
||||
{ "rol", Direct },
|
||||
{ "and", ILDirect },
|
||||
|
||||
{ "plp", Implied },
|
||||
{ "and", AccumConstant },
|
||||
{ "rol", Implied },
|
||||
{ "pld", Implied },
|
||||
|
||||
{ "bit", Address },
|
||||
{ "and", Address },
|
||||
{ "rol", Address },
|
||||
{ "and", Long },
|
||||
|
||||
//0x30 - 0x3f
|
||||
{ "bmi", RelativeShort },
|
||||
{ "and", IDirectY },
|
||||
{ "and", IDirect },
|
||||
{ "and", IStackY },
|
||||
|
||||
{ "bit", DirectX },
|
||||
{ "and", DirectX },
|
||||
{ "rol", DirectX },
|
||||
{ "and", ILDirectY },
|
||||
|
||||
{ "sec", Implied },
|
||||
{ "and", AddressY },
|
||||
{ "dec", Implied },
|
||||
{ "tsc", Implied },
|
||||
|
||||
{ "bit", AddressX },
|
||||
{ "and", AddressX },
|
||||
{ "rol", AddressX },
|
||||
{ "and", LongX },
|
||||
|
||||
//0x40 - 0x4f
|
||||
{ "rti", Implied },
|
||||
{ "eor", IDirectX },
|
||||
{ "wdm", Constant },
|
||||
{ "eor", Stack },
|
||||
|
||||
{ "mvp", BlockMove },
|
||||
{ "eor", Direct },
|
||||
{ "lsr", Direct },
|
||||
{ "eor", ILDirect },
|
||||
|
||||
{ "pha", Implied },
|
||||
{ "eor", AccumConstant },
|
||||
{ "lsr", Implied },
|
||||
{ "phk", Implied },
|
||||
|
||||
{ "jmp", PAddress },
|
||||
{ "eor", Address },
|
||||
{ "lsr", Address },
|
||||
{ "eor", Long },
|
||||
|
||||
//0x50 - 0x5f
|
||||
{ "bvc", RelativeShort },
|
||||
{ "eor", IDirectY },
|
||||
{ "eor", IDirect },
|
||||
{ "eor", IStackY },
|
||||
|
||||
{ "mvn", BlockMove },
|
||||
{ "eor", DirectX },
|
||||
{ "lsr", DirectX },
|
||||
{ "eor", ILDirectY },
|
||||
|
||||
{ "cli", Implied },
|
||||
{ "eor", AddressY },
|
||||
{ "phy", Implied },
|
||||
{ "tcd", Implied },
|
||||
|
||||
{ "jml", Long },
|
||||
{ "eor", AddressX },
|
||||
{ "lsr", AddressX },
|
||||
{ "eor", LongX },
|
||||
|
||||
//0x60 - 0x6f
|
||||
{ "rts", Implied },
|
||||
{ "adc", IDirectX },
|
||||
{ "per", Address },
|
||||
{ "adc", Stack },
|
||||
|
||||
{ "stz", Direct },
|
||||
{ "adc", Direct },
|
||||
{ "ror", Direct },
|
||||
{ "adc", ILDirect },
|
||||
|
||||
{ "pla", Implied },
|
||||
{ "adc", AccumConstant },
|
||||
{ "ror", Implied },
|
||||
{ "rtl", Implied },
|
||||
|
||||
{ "jmp", PIAddress },
|
||||
{ "adc", Address },
|
||||
{ "ror", Address },
|
||||
{ "adc", Long },
|
||||
|
||||
//0x70 - 0x7f
|
||||
{ "bvs", RelativeShort },
|
||||
{ "adc", IDirectY },
|
||||
{ "adc", IDirect },
|
||||
{ "adc", IStackY },
|
||||
|
||||
{ "stz", DirectX },
|
||||
{ "adc", DirectX },
|
||||
{ "ror", DirectX },
|
||||
{ "adc", ILDirectY },
|
||||
|
||||
{ "sei", Implied },
|
||||
{ "adc", AddressY },
|
||||
{ "ply", Implied },
|
||||
{ "tdc", Implied },
|
||||
|
||||
{ "jmp", IAddressX },
|
||||
{ "adc", AddressX },
|
||||
{ "ror", AddressX },
|
||||
{ "adc", LongX },
|
||||
|
||||
//0x80 - 0x8f
|
||||
{ "bra", RelativeShort },
|
||||
{ "sta", IDirectX },
|
||||
{ "brl", RelativeLong },
|
||||
{ "sta", Stack },
|
||||
|
||||
{ "sty", Direct },
|
||||
{ "sta", Direct },
|
||||
{ "stx", Direct },
|
||||
{ "sta", ILDirect },
|
||||
|
||||
{ "dey", Implied },
|
||||
{ "bit", AccumConstant },
|
||||
{ "txa", Implied },
|
||||
{ "phb", Implied },
|
||||
|
||||
{ "sty", Address },
|
||||
{ "sta", Address },
|
||||
{ "stx", Address },
|
||||
{ "sta", Long },
|
||||
|
||||
//0x90 - 0x9f
|
||||
{ "bcc", RelativeShort },
|
||||
{ "sta", IDirectY },
|
||||
{ "sta", IDirect },
|
||||
{ "sta", IStackY },
|
||||
|
||||
{ "sty", DirectX },
|
||||
{ "sta", DirectX },
|
||||
{ "stx", DirectY },
|
||||
{ "sta", ILDirectY },
|
||||
|
||||
{ "tya", Implied },
|
||||
{ "sta", AddressY },
|
||||
{ "txs", Implied },
|
||||
{ "txy", Implied },
|
||||
|
||||
{ "stz", Address },
|
||||
{ "sta", AddressX },
|
||||
{ "stz", AddressX },
|
||||
{ "sta", LongX },
|
||||
|
||||
//0xa0 - 0xaf
|
||||
{ "ldy", IndexConstant },
|
||||
{ "lda", IDirectX },
|
||||
{ "ldx", IndexConstant },
|
||||
{ "lda", Stack },
|
||||
|
||||
{ "ldy", Direct },
|
||||
{ "lda", Direct },
|
||||
{ "ldx", Direct },
|
||||
{ "lda", ILDirect },
|
||||
|
||||
{ "tay", Implied },
|
||||
{ "lda", AccumConstant },
|
||||
{ "tax", Implied },
|
||||
{ "plb", Implied },
|
||||
|
||||
{ "ldy", Address },
|
||||
{ "lda", Address },
|
||||
{ "ldx", Address },
|
||||
{ "lda", Long },
|
||||
|
||||
//0xb0 - 0xbf
|
||||
{ "bcs", RelativeShort },
|
||||
{ "lda", IDirectY },
|
||||
{ "lda", IDirect },
|
||||
{ "lda", IStackY },
|
||||
|
||||
{ "ldy", DirectX },
|
||||
{ "lda", DirectX },
|
||||
{ "ldx", DirectY },
|
||||
{ "lda", ILDirectY },
|
||||
|
||||
{ "clv", Implied },
|
||||
{ "lda", AddressY },
|
||||
{ "tsx", Implied },
|
||||
{ "tyx", Implied },
|
||||
|
||||
{ "ldy", AddressX },
|
||||
{ "lda", AddressX },
|
||||
{ "ldx", AddressY },
|
||||
{ "lda", LongX },
|
||||
|
||||
//0xc0 - 0xcf
|
||||
{ "cpy", IndexConstant },
|
||||
{ "cmp", IDirectX },
|
||||
{ "rep", Constant },
|
||||
{ "cmp", Stack },
|
||||
|
||||
{ "cpy", Direct },
|
||||
{ "cmp", Direct },
|
||||
{ "dec", Direct },
|
||||
{ "cmp", ILDirect },
|
||||
|
||||
{ "iny", Implied },
|
||||
{ "cmp", AccumConstant },
|
||||
{ "dex", Implied },
|
||||
{ "wai", Implied },
|
||||
|
||||
{ "cpy", Address },
|
||||
{ "cmp", Address },
|
||||
{ "dec", Address },
|
||||
{ "cmp", Long },
|
||||
|
||||
//0xd0 - 0xdf
|
||||
{ "bne", RelativeShort },
|
||||
{ "cmp", IDirectY },
|
||||
{ "cmp", IDirect },
|
||||
{ "cmp", IStackY },
|
||||
|
||||
{ "pei", IDirect },
|
||||
{ "cmp", DirectX },
|
||||
{ "dec", DirectX },
|
||||
{ "cmp", ILDirectY },
|
||||
|
||||
{ "cld", Implied },
|
||||
{ "cmp", AddressY },
|
||||
{ "phx", Implied },
|
||||
{ "stp", Implied },
|
||||
|
||||
{ "jmp", ILAddress },
|
||||
{ "cmp", AddressX },
|
||||
{ "dec", AddressX },
|
||||
{ "cmp", LongX },
|
||||
|
||||
//0xe0 - 0xef
|
||||
{ "cpx", IndexConstant },
|
||||
{ "sbc", IDirectX },
|
||||
{ "sep", Constant },
|
||||
{ "sbc", Stack },
|
||||
|
||||
{ "cpx", Direct },
|
||||
{ "sbc", Direct },
|
||||
{ "inc", Direct },
|
||||
{ "sbc", ILDirect },
|
||||
|
||||
{ "inx", Implied },
|
||||
{ "sbc", AccumConstant },
|
||||
{ "nop", Implied },
|
||||
{ "xba", Implied },
|
||||
|
||||
{ "cpx", Address },
|
||||
{ "sbc", Address },
|
||||
{ "inc", Address },
|
||||
{ "sbc", Long },
|
||||
|
||||
//0xf0 - 0xff
|
||||
{ "beq", RelativeShort },
|
||||
{ "sbc", IDirectY },
|
||||
{ "sbc", IDirect },
|
||||
{ "sbc", IStackY },
|
||||
|
||||
{ "pea", Address },
|
||||
{ "sbc", DirectX },
|
||||
{ "inc", DirectX },
|
||||
{ "sbc", ILDirectY },
|
||||
|
||||
{ "sed", Implied },
|
||||
{ "sbc", AddressY },
|
||||
{ "plx", Implied },
|
||||
{ "xce", Implied },
|
||||
|
||||
{ "jsr", IAddressX },
|
||||
{ "sbc", AddressX },
|
||||
{ "inc", AddressX },
|
||||
{ "sbc", LongX },
|
||||
};
|
||||
|
||||
inline unsigned SNESCPU::getOpcodeLength(bool accum, bool index, uint8_t opcode) {
|
||||
switch(opcodeInfo[opcode].mode) { default:
|
||||
case Implied: return 1;
|
||||
case Constant: return 2;
|
||||
case AccumConstant: return 3 - accum;
|
||||
case IndexConstant: return 3 - index;
|
||||
case Direct: return 2;
|
||||
case DirectX: return 2;
|
||||
case DirectY: return 2;
|
||||
case IDirect: return 2;
|
||||
case IDirectX: return 2;
|
||||
case IDirectY: return 2;
|
||||
case ILDirect: return 2;
|
||||
case ILDirectY: return 2;
|
||||
case Address: return 3;
|
||||
case AddressX: return 3;
|
||||
case AddressY: return 3;
|
||||
case IAddressX: return 3;
|
||||
case ILAddress: return 3;
|
||||
case PAddress: return 3;
|
||||
case PIAddress: return 3;
|
||||
case Long: return 4;
|
||||
case LongX: return 4;
|
||||
case Stack: return 2;
|
||||
case IStackY: return 2;
|
||||
case BlockMove: return 3;
|
||||
case RelativeShort: return 2;
|
||||
case RelativeLong: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
inline string SNESCPU::disassemble(unsigned pc, bool accum, bool index, uint8_t opcode, uint8_t pl, uint8_t ph, uint8_t pb) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == Constant) return { name, " #$", hex<2>(pl) };
|
||||
if(mode == AccumConstant) return { name, " #$", accum ? "" : hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == IndexConstant) return { name, " #$", index ? "" : hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == Direct) return { name, " $", hex<2>(pl) };
|
||||
if(mode == DirectX) return { name, " $", hex<2>(pl), ",x" };
|
||||
if(mode == DirectY) return { name, " $", hex<2>(pl), ",y" };
|
||||
if(mode == IDirect) return { name, " ($", hex<2>(pl), ")" };
|
||||
if(mode == IDirectX) return { name, " ($", hex<2>(pl), ",x)" };
|
||||
if(mode == IDirectY) return { name, " ($", hex<2>(pl), "),y" };
|
||||
if(mode == ILDirect) return { name, " [$", hex<2>(pl), "]" };
|
||||
if(mode == ILDirectY) return { name, " [$", hex<2>(pl), "],y" };
|
||||
if(mode == Address) return { name, " $", hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == AddressX) return { name, " $", hex<2>(ph), hex<2>(pl), ",x" };
|
||||
if(mode == AddressY) return { name, " $", hex<2>(ph), hex<2>(pl), ",y" };
|
||||
if(mode == IAddressX) return { name, " ($", hex<2>(ph), hex<2>(pl), ",x)" };
|
||||
if(mode == ILAddress) return { name, " [$", hex<2>(ph), hex<2>(pl), "]" };
|
||||
if(mode == PAddress) return { name, " $", hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == PIAddress) return { name, " ($", hex<2>(ph), hex<2>(pl), ")" };
|
||||
if(mode == Long) return { name, " $", hex<2>(pb), hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == LongX) return { name, " $", hex<2>(pb), hex<2>(ph), hex<2>(pl), ",x" };
|
||||
if(mode == Stack) return { name, " $", hex<2>(pl), ",s" };
|
||||
if(mode == IStackY) return { name, " ($", hex<2>(pl), ",s),y" };
|
||||
if(mode == BlockMove) return { name, " $", hex<2>(ph), ",$", hex<2>(pl) };
|
||||
if(mode == RelativeShort) {
|
||||
unsigned addr = (pc + 2) + (int8_t)(pl << 0);
|
||||
return { name, " $", hex<4>(addr) };
|
||||
}
|
||||
if(mode == RelativeLong) {
|
||||
unsigned addr = (pc + 3) + (int16_t)((ph << 8) + (pl << 0));
|
||||
return { name, " $", hex<4>(addr) };
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,639 @@
|
|||
#ifndef NALL_SNES_SMP_HPP
|
||||
#define NALL_SNES_SMP_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct SNESSMP {
|
||||
enum : unsigned {
|
||||
Implied, //
|
||||
TVector, //0
|
||||
Direct, //$00
|
||||
DirectRelative, //$00,+/-$00
|
||||
ADirect, //a,$00
|
||||
AAbsolute, //a,$0000
|
||||
AIX, //a,(x)
|
||||
AIDirectX, //a,($00+x)
|
||||
AConstant, //a,#$00
|
||||
DirectDirect, //$00,$00
|
||||
CAbsoluteBit, //c,$0000:0
|
||||
Absolute, //$0000
|
||||
P, //p
|
||||
AbsoluteA, //$0000,a
|
||||
Relative, //+/-$00
|
||||
ADirectX, //a,$00+x
|
||||
AAbsoluteX, //a,$0000+x
|
||||
AAbsoluteY, //a,$0000+y
|
||||
AIDirectY, //a,($00)+y
|
||||
DirectConstant, //$00,#$00
|
||||
IXIY, //(x),(y)
|
||||
DirectX, //$00+x
|
||||
A, //a
|
||||
X, //x
|
||||
XAbsolute, //x,$0000
|
||||
IAbsoluteX, //($0000+x)
|
||||
CNAbsoluteBit, //c,!$0000:0
|
||||
XDirect, //x,$00
|
||||
PVector, //$ff00
|
||||
YaDirect, //ya,$00
|
||||
XA, //x,a
|
||||
YAbsolute, //y,$0000
|
||||
Y, //y
|
||||
AX, //a,x
|
||||
YDirect, //y,$00
|
||||
YConstant, //y,#$00
|
||||
XSp, //x,sp
|
||||
YaX, //ya,x
|
||||
IXPA, //(x)+,a
|
||||
SpX, //sp,x
|
||||
AIXP, //a,(x)+
|
||||
DirectA, //$00,a
|
||||
IXA, //(x),a
|
||||
IDirectXA, //($00+x),a
|
||||
XConstant, //x,#$00
|
||||
AbsoluteX, //$0000,x
|
||||
AbsoluteBitC, //$0000:0,c
|
||||
DirectY, //$00,y
|
||||
AbsoluteY, //$0000,y
|
||||
Ya, //ya
|
||||
DirectXA, //$00+x,a
|
||||
AbsoluteXA, //$0000+x,a
|
||||
AbsoluteYA, //$0000+y,a
|
||||
IDirectYA, //($00)+y,a
|
||||
DirectYX, //$00+y,x
|
||||
DirectYa, //$00,ya
|
||||
DirectXY, //$00+x,y
|
||||
AY, //a,y
|
||||
DirectXRelative, //$00+x,+/-$00
|
||||
XDirectY, //x,$00+y
|
||||
YDirectX, //y,$00+x
|
||||
YA, //y,a
|
||||
YRelative, //y,+/-$00
|
||||
};
|
||||
|
||||
struct OpcodeInfo {
|
||||
char name[6];
|
||||
unsigned mode;
|
||||
};
|
||||
|
||||
static const OpcodeInfo opcodeInfo[256];
|
||||
|
||||
static unsigned getOpcodeLength(uint8_t opcode);
|
||||
static string disassemble(uint16_t pc, uint8_t opcode, uint8_t pl, uint8_t ph);
|
||||
static string disassemble(uint16_t pc, bool p, uint8_t opcode, uint8_t pl, uint8_t ph);
|
||||
};
|
||||
|
||||
const SNESSMP::OpcodeInfo SNESSMP::opcodeInfo[256] = {
|
||||
//0x00 - 0x0f
|
||||
{ "nop ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set0 ", Direct },
|
||||
{ "bbs0 ", DirectRelative },
|
||||
|
||||
{ "or ", ADirect },
|
||||
{ "or ", AAbsolute },
|
||||
{ "or ", AIX },
|
||||
{ "or ", AIDirectX },
|
||||
|
||||
{ "or ", AConstant },
|
||||
{ "or ", DirectDirect },
|
||||
{ "or1 ", CAbsoluteBit },
|
||||
{ "asl ", Direct },
|
||||
|
||||
{ "asl ", Absolute },
|
||||
{ "push ", P },
|
||||
{ "tset ", AbsoluteA },
|
||||
{ "brk ", Implied },
|
||||
|
||||
//0x10 - 0x1f
|
||||
{ "bpl ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr0 ", Direct },
|
||||
{ "bbc0 ", DirectRelative },
|
||||
|
||||
{ "or ", ADirectX },
|
||||
{ "or ", AAbsoluteX },
|
||||
{ "or ", AAbsoluteY },
|
||||
{ "or ", AIDirectY },
|
||||
|
||||
{ "or ", DirectConstant },
|
||||
{ "or ", IXIY },
|
||||
{ "decw ", Direct },
|
||||
{ "asl ", DirectX },
|
||||
|
||||
{ "asl ", A },
|
||||
{ "dec ", X },
|
||||
{ "cmp ", XAbsolute },
|
||||
{ "jmp ", IAbsoluteX },
|
||||
|
||||
//0x20 - 0x2f
|
||||
{ "clrp ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set1 ", Direct },
|
||||
{ "bbs1 ", DirectRelative },
|
||||
|
||||
{ "and ", ADirect },
|
||||
{ "and ", AAbsolute },
|
||||
{ "and ", AIX },
|
||||
{ "and ", AIDirectX },
|
||||
|
||||
{ "and ", AConstant },
|
||||
{ "and ", DirectDirect },
|
||||
{ "or1 ", CNAbsoluteBit },
|
||||
{ "rol ", Direct },
|
||||
|
||||
{ "rol ", Absolute },
|
||||
{ "push ", A },
|
||||
{ "cbne ", DirectRelative },
|
||||
{ "bra ", Relative },
|
||||
|
||||
//0x30 - 0x3f
|
||||
{ "bmi ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr1 ", Direct },
|
||||
{ "bbc1 ", DirectRelative },
|
||||
|
||||
{ "and ", ADirectX },
|
||||
{ "and ", AAbsoluteX },
|
||||
{ "and ", AAbsoluteY },
|
||||
{ "and ", AIDirectY },
|
||||
|
||||
{ "and ", DirectConstant },
|
||||
{ "and ", IXIY },
|
||||
{ "incw ", Direct },
|
||||
{ "rol ", DirectX },
|
||||
|
||||
{ "rol ", A },
|
||||
{ "inc ", X },
|
||||
{ "cmp ", XDirect },
|
||||
{ "call ", Absolute },
|
||||
|
||||
//0x40 - 0x4f
|
||||
{ "setp ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set2 ", Direct },
|
||||
{ "bbs2 ", DirectRelative },
|
||||
|
||||
{ "eor ", ADirect },
|
||||
{ "eor ", AAbsolute },
|
||||
{ "eor ", AIX },
|
||||
{ "eor ", AIDirectX },
|
||||
|
||||
{ "eor ", AConstant },
|
||||
{ "eor ", DirectDirect },
|
||||
{ "and1 ", CAbsoluteBit },
|
||||
{ "lsr ", Direct },
|
||||
|
||||
{ "lsr ", Absolute },
|
||||
{ "push ", X },
|
||||
{ "tclr ", AbsoluteA },
|
||||
{ "pcall", PVector },
|
||||
|
||||
//0x50 - 0x5f
|
||||
{ "bvc ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr2 ", Direct },
|
||||
{ "bbc2 ", DirectRelative },
|
||||
|
||||
{ "eor ", ADirectX },
|
||||
{ "eor ", AAbsoluteX },
|
||||
{ "eor ", AAbsoluteY },
|
||||
{ "eor ", AIDirectY },
|
||||
|
||||
{ "eor ", DirectConstant },
|
||||
{ "eor ", IXIY },
|
||||
{ "cmpw ", YaDirect },
|
||||
{ "lsr ", DirectX },
|
||||
|
||||
{ "lsr ", A },
|
||||
{ "mov ", XA },
|
||||
{ "cmp ", YAbsolute },
|
||||
{ "jmp ", Absolute },
|
||||
|
||||
//0x60 - 0x6f
|
||||
{ "clrc ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set3 ", Direct },
|
||||
{ "bbs3 ", DirectRelative },
|
||||
|
||||
{ "cmp ", ADirect },
|
||||
{ "cmp ", AAbsolute },
|
||||
{ "cmp ", AIX },
|
||||
{ "cmp ", AIDirectX },
|
||||
|
||||
{ "cmp ", AConstant },
|
||||
{ "cmp ", DirectDirect },
|
||||
{ "and1 ", CNAbsoluteBit },
|
||||
{ "ror ", Direct },
|
||||
|
||||
{ "ror ", Absolute },
|
||||
{ "push ", Y },
|
||||
{ "dbnz ", DirectRelative },
|
||||
{ "ret ", Implied },
|
||||
|
||||
//0x70 - 0x7f
|
||||
{ "bvs ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr3 ", Direct },
|
||||
{ "bbc3 ", DirectRelative },
|
||||
|
||||
{ "cmp ", ADirectX },
|
||||
{ "cmp ", AAbsoluteX },
|
||||
{ "cmp ", AAbsoluteY },
|
||||
{ "cmp ", AIDirectY },
|
||||
|
||||
{ "cmp ", DirectConstant },
|
||||
{ "cmp ", IXIY },
|
||||
{ "addw ", YaDirect },
|
||||
{ "ror ", DirectX },
|
||||
|
||||
{ "ror ", A },
|
||||
{ "mov ", AX },
|
||||
{ "cmp ", YDirect },
|
||||
{ "reti ", Implied },
|
||||
|
||||
//0x80 - 0x8f
|
||||
{ "setc ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set4 ", Direct },
|
||||
{ "bbs4 ", DirectRelative },
|
||||
|
||||
{ "adc ", ADirect },
|
||||
{ "adc ", AAbsolute },
|
||||
{ "adc ", AIX },
|
||||
{ "adc ", AIDirectX },
|
||||
|
||||
{ "adc ", AConstant },
|
||||
{ "adc ", DirectDirect },
|
||||
{ "eor1 ", CAbsoluteBit },
|
||||
{ "dec ", Direct },
|
||||
|
||||
{ "dec ", Absolute },
|
||||
{ "mov ", YConstant },
|
||||
{ "pop ", P },
|
||||
{ "mov ", DirectConstant },
|
||||
|
||||
//0x90 - 0x9f
|
||||
{ "bcc ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr4 ", Direct },
|
||||
{ "bbc4 ", DirectRelative },
|
||||
|
||||
{ "adc ", ADirectX },
|
||||
{ "adc ", AAbsoluteX },
|
||||
{ "adc ", AAbsoluteY },
|
||||
{ "adc ", AIDirectY },
|
||||
|
||||
{ "adc ", DirectRelative },
|
||||
{ "adc ", IXIY },
|
||||
{ "subw ", YaDirect },
|
||||
{ "dec ", DirectX },
|
||||
|
||||
{ "dec ", A },
|
||||
{ "mov ", XSp },
|
||||
{ "div ", YaX },
|
||||
{ "xcn ", A },
|
||||
|
||||
//0xa0 - 0xaf
|
||||
{ "ei ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set5 ", Direct },
|
||||
{ "bbs5 ", DirectRelative },
|
||||
|
||||
{ "sbc ", ADirect },
|
||||
{ "sbc ", AAbsolute },
|
||||
{ "sbc ", AIX },
|
||||
{ "sbc ", AIDirectX },
|
||||
|
||||
{ "sbc ", AConstant },
|
||||
{ "sbc ", DirectDirect },
|
||||
{ "mov1 ", CAbsoluteBit },
|
||||
{ "inc ", Direct },
|
||||
|
||||
{ "inc ", Absolute },
|
||||
{ "cmp ", YConstant },
|
||||
{ "pop ", A },
|
||||
{ "mov ", IXPA },
|
||||
|
||||
//0xb0 - 0xbf
|
||||
{ "bcs ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr5 ", Direct },
|
||||
{ "bbc5 ", DirectRelative },
|
||||
|
||||
{ "sbc ", ADirectX },
|
||||
{ "sbc ", AAbsoluteX },
|
||||
{ "sbc ", AAbsoluteY },
|
||||
{ "sbc ", AIDirectY },
|
||||
|
||||
{ "sbc ", DirectConstant },
|
||||
{ "sbc ", IXIY },
|
||||
{ "movw ", YaDirect },
|
||||
{ "inc ", DirectX },
|
||||
|
||||
{ "inc ", A },
|
||||
{ "mov ", SpX },
|
||||
{ "das ", A },
|
||||
{ "mov ", AIXP },
|
||||
|
||||
//0xc0 - 0xcf
|
||||
{ "di ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set6 ", Direct },
|
||||
{ "bbs6 ", DirectRelative },
|
||||
|
||||
{ "mov ", DirectA },
|
||||
{ "mov ", AbsoluteA },
|
||||
{ "mov ", IXA },
|
||||
{ "mov ", IDirectXA },
|
||||
|
||||
{ "cmp ", XConstant },
|
||||
{ "mov ", AbsoluteX },
|
||||
{ "mov1 ", AbsoluteBitC },
|
||||
{ "mov ", DirectY },
|
||||
|
||||
{ "mov ", AbsoluteY },
|
||||
{ "mov ", XConstant },
|
||||
{ "pop ", X },
|
||||
{ "mul ", Ya },
|
||||
|
||||
//0xd0 - 0xdf
|
||||
{ "bne ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr6 ", Relative },
|
||||
{ "bbc6 ", DirectRelative },
|
||||
|
||||
{ "mov ", DirectXA },
|
||||
{ "mov ", AbsoluteXA },
|
||||
{ "mov ", AbsoluteYA },
|
||||
{ "mov ", IDirectYA },
|
||||
|
||||
{ "mov ", DirectX },
|
||||
{ "mov ", DirectYX },
|
||||
{ "movw ", DirectYa },
|
||||
{ "mov ", DirectXY },
|
||||
|
||||
{ "dec ", Y },
|
||||
{ "mov ", AY },
|
||||
{ "cbne ", DirectXRelative },
|
||||
{ "daa ", A },
|
||||
|
||||
//0xe0 - 0xef
|
||||
{ "clrv ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set7 ", Direct },
|
||||
{ "bbs7 ", DirectRelative },
|
||||
|
||||
{ "mov ", ADirect },
|
||||
{ "mov ", AAbsolute },
|
||||
{ "mov ", AIX },
|
||||
{ "mov ", AIDirectX },
|
||||
|
||||
{ "mov ", AConstant },
|
||||
{ "mov ", XAbsolute },
|
||||
{ "not1 ", CAbsoluteBit },
|
||||
{ "mov ", YDirect },
|
||||
|
||||
{ "mov ", YAbsolute },
|
||||
{ "notc ", Implied },
|
||||
{ "pop ", Y },
|
||||
{ "sleep", Implied },
|
||||
|
||||
//0xf0 - 0xff
|
||||
{ "beq ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr7 ", Direct },
|
||||
{ "bbc7 ", DirectRelative },
|
||||
|
||||
{ "mov ", ADirectX },
|
||||
{ "mov ", AAbsoluteX },
|
||||
{ "mov ", AAbsoluteY },
|
||||
{ "mov ", AIDirectY },
|
||||
|
||||
{ "mov ", XDirect },
|
||||
{ "mov ", XDirectY },
|
||||
{ "mov ", DirectDirect },
|
||||
{ "mov ", YDirectX },
|
||||
|
||||
{ "inc ", Y },
|
||||
{ "mov ", YA },
|
||||
{ "dbz ", YRelative },
|
||||
{ "stop ", Implied },
|
||||
};
|
||||
|
||||
inline unsigned SNESSMP::getOpcodeLength(uint8_t opcode) {
|
||||
switch(opcodeInfo[opcode].mode) { default:
|
||||
case Implied: return 1; //
|
||||
case TVector: return 1; //0
|
||||
case Direct: return 2; //$00
|
||||
case DirectRelative: return 3; //$00,+/-$00
|
||||
case ADirect: return 2; //a,$00
|
||||
case AAbsolute: return 3; //a,$0000
|
||||
case AIX: return 1; //a,(x)
|
||||
case AIDirectX: return 2; //a,($00+x)
|
||||
case AConstant: return 2; //a,#$00
|
||||
case DirectDirect: return 3; //$00,$00
|
||||
case CAbsoluteBit: return 3; //c,$0000:0
|
||||
case Absolute: return 3; //$0000
|
||||
case P: return 1; //p
|
||||
case AbsoluteA: return 3; //$0000,a
|
||||
case Relative: return 2; //+/-$00
|
||||
case ADirectX: return 2; //a,$00+x
|
||||
case AAbsoluteX: return 3; //a,$0000+x
|
||||
case AAbsoluteY: return 3; //a,$0000+y
|
||||
case AIDirectY: return 2; //a,($00)+y
|
||||
case DirectConstant: return 3; //$00,#$00
|
||||
case IXIY: return 1; //(x),(y)
|
||||
case DirectX: return 2; //$00+x
|
||||
case A: return 1; //a
|
||||
case X: return 1; //x
|
||||
case XAbsolute: return 3; //x,$0000
|
||||
case IAbsoluteX: return 3; //($0000+x)
|
||||
case CNAbsoluteBit: return 3; //c,!$0000:0
|
||||
case XDirect: return 2; //x,$00
|
||||
case PVector: return 2; //$ff00
|
||||
case YaDirect: return 2; //ya,$00
|
||||
case XA: return 1; //x,a
|
||||
case YAbsolute: return 3; //y,$0000
|
||||
case Y: return 1; //y
|
||||
case AX: return 1; //a,x
|
||||
case YDirect: return 2; //y,$00
|
||||
case YConstant: return 2; //y,#$00
|
||||
case XSp: return 1; //x,sp
|
||||
case YaX: return 1; //ya,x
|
||||
case IXPA: return 1; //(x)+,a
|
||||
case SpX: return 1; //sp,x
|
||||
case AIXP: return 1; //a,(x)+
|
||||
case DirectA: return 2; //$00,a
|
||||
case IXA: return 1; //(x),a
|
||||
case IDirectXA: return 2; //($00+x),a
|
||||
case XConstant: return 2; //x,#$00
|
||||
case AbsoluteX: return 3; //$0000,x
|
||||
case AbsoluteBitC: return 3; //$0000:0,c
|
||||
case DirectY: return 2; //$00,y
|
||||
case AbsoluteY: return 3; //$0000,y
|
||||
case Ya: return 1; //ya
|
||||
case DirectXA: return 2; //$00+x,a
|
||||
case AbsoluteXA: return 3; //$0000+x,a
|
||||
case AbsoluteYA: return 3; //$0000+y,a
|
||||
case IDirectYA: return 2; //($00)+y,a
|
||||
case DirectYX: return 2; //$00+y,x
|
||||
case DirectYa: return 2; //$00,ya
|
||||
case DirectXY: return 2; //$00+x,y
|
||||
case AY: return 1; //a,y
|
||||
case DirectXRelative: return 3; //$00+x,+/-$00
|
||||
case XDirectY: return 2; //x,$00+y
|
||||
case YDirectX: return 2; //y,$00+x
|
||||
case YA: return 1; //y,a
|
||||
case YRelative: return 2; //y,+/-$00
|
||||
}
|
||||
}
|
||||
|
||||
inline string SNESSMP::disassemble(uint16_t pc, uint8_t opcode, uint8_t pl, uint8_t ph) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
unsigned pa = (ph << 8) + pl;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == TVector) return { name, " ", opcode >> 4 };
|
||||
if(mode == Direct) return { name, " $", hex<2>(pl) };
|
||||
if(mode == DirectRelative) return { name, " $", hex<2>(pl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == ADirect) return { name, " a,$", hex<2>(pl) };
|
||||
if(mode == AAbsolute) return { name, " a,$", hex<4>(pa) };
|
||||
if(mode == AIX) return { name, "a,(x)" };
|
||||
if(mode == AIDirectX) return { name, " a,($", hex<2>(pl), "+x)" };
|
||||
if(mode == AConstant) return { name, " a,#$", hex<2>(pl) };
|
||||
if(mode == DirectDirect) return { name, " $", hex<2>(ph), ",$", hex<2>(pl) };
|
||||
if(mode == CAbsoluteBit) return { name, " c,$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == Absolute) return { name, " $", hex<4>(pa) };
|
||||
if(mode == P) return { name, " p" };
|
||||
if(mode == AbsoluteA) return { name, " $", hex<4>(pa), ",a" };
|
||||
if(mode == Relative) return { name, " $", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
if(mode == ADirectX) return { name, " a,$", hex<2>(pl), "+x" };
|
||||
if(mode == AAbsoluteX) return { name, " a,$", hex<4>(pa), "+x" };
|
||||
if(mode == AAbsoluteY) return { name, " a,$", hex<4>(pa), "+y" };
|
||||
if(mode == AIDirectY) return { name, " a,($", hex<2>(pl), ")+y" };
|
||||
if(mode == DirectConstant) return { name, " $", hex<2>(ph), ",#$", hex<2>(pl) };
|
||||
if(mode == IXIY) return { name, " (x),(y)" };
|
||||
if(mode == DirectX) return { name, " $", hex<2>(pl), "+x" };
|
||||
if(mode == A) return { name, " a" };
|
||||
if(mode == X) return { name, " x" };
|
||||
if(mode == XAbsolute) return { name, " x,$", hex<4>(pa) };
|
||||
if(mode == IAbsoluteX) return { name, " ($", hex<4>(pa), "+x)" };
|
||||
if(mode == CNAbsoluteBit) return { name, " c,!$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == XDirect) return { name, " x,$", hex<2>(pl) };
|
||||
if(mode == PVector) return { name, " $ff", hex<2>(pl) };
|
||||
if(mode == YaDirect) return { name, " ya,$", hex<2>(pl) };
|
||||
if(mode == XA) return { name, " x,a" };
|
||||
if(mode == YAbsolute) return { name, " y,$", hex<4>(pa) };
|
||||
if(mode == Y) return { name, " y" };
|
||||
if(mode == AX) return { name, " a,x" };
|
||||
if(mode == YDirect) return { name, " y,$", hex<2>(pl) };
|
||||
if(mode == YConstant) return { name, " y,#$", hex<2>(pl) };
|
||||
if(mode == XSp) return { name, " x,sp" };
|
||||
if(mode == YaX) return { name, " ya,x" };
|
||||
if(mode == IXPA) return { name, " (x)+,a" };
|
||||
if(mode == SpX) return { name, " sp,x" };
|
||||
if(mode == AIXP) return { name, " a,(x)+" };
|
||||
if(mode == DirectA) return { name, " $", hex<2>(pl), ",a" };
|
||||
if(mode == IXA) return { name, " (x),a" };
|
||||
if(mode == IDirectXA) return { name, " ($", hex<2>(pl), "+x),a" };
|
||||
if(mode == XConstant) return { name, " x,#$", hex<2>(pl) };
|
||||
if(mode == AbsoluteX) return { name, " $", hex<4>(pa), ",x" };
|
||||
if(mode == AbsoluteBitC) return { name, " $", hex<4>(pa & 0x1fff), ":", pa >> 13, ",c" };
|
||||
if(mode == DirectY) return { name, " $", hex<2>(pl), ",y" };
|
||||
if(mode == AbsoluteY) return { name, " $", hex<4>(pa), ",y" };
|
||||
if(mode == Ya) return { name, " ya" };
|
||||
if(mode == DirectXA) return { name, " $", hex<2>(pl), "+x,a" };
|
||||
if(mode == AbsoluteXA) return { name, " $", hex<4>(pa), "+x,a" };
|
||||
if(mode == AbsoluteYA) return { name, " $", hex<4>(pa), "+y,a" };
|
||||
if(mode == IDirectYA) return { name, " ($", hex<2>(pl), ")+y,a" };
|
||||
if(mode == DirectYX) return { name, " $", hex<2>(pl), "+y,x" };
|
||||
if(mode == DirectYa) return { name, " $", hex<2>(pl), ",ya" };
|
||||
if(mode == DirectXY) return { name, " $", hex<2>(pl), "+x,y" };
|
||||
if(mode == AY) return { name, " a,y" };
|
||||
if(mode == DirectXRelative) return { name, " $", hex<2>(pl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == XDirectY) return { name, " x,$", hex<2>(pl), "+y" };
|
||||
if(mode == YDirectX) return { name, " y,$", hex<2>(pl), "+x" };
|
||||
if(mode == YA) return { name, " y,a" };
|
||||
if(mode == YRelative) return { name, " y,$", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
inline string SNESSMP::disassemble(uint16_t pc, bool p, uint8_t opcode, uint8_t pl, uint8_t ph) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
unsigned pdl = (p << 8) + pl;
|
||||
unsigned pdh = (p << 8) + ph;
|
||||
unsigned pa = (ph << 8) + pl;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == TVector) return { name, " ", opcode >> 4 };
|
||||
if(mode == Direct) return { name, " $", hex<3>(pdl) };
|
||||
if(mode == DirectRelative) return { name, " $", hex<3>(pdl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == ADirect) return { name, " a,$", hex<3>(pdl) };
|
||||
if(mode == AAbsolute) return { name, " a,$", hex<4>(pa) };
|
||||
if(mode == AIX) return { name, "a,(x)" };
|
||||
if(mode == AIDirectX) return { name, " a,($", hex<3>(pdl), "+x)" };
|
||||
if(mode == AConstant) return { name, " a,#$", hex<2>(pl) };
|
||||
if(mode == DirectDirect) return { name, " $", hex<3>(pdh), ",$", hex<3>(pdl) };
|
||||
if(mode == CAbsoluteBit) return { name, " c,$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == Absolute) return { name, " $", hex<4>(pa) };
|
||||
if(mode == P) return { name, " p" };
|
||||
if(mode == AbsoluteA) return { name, " $", hex<4>(pa), ",a" };
|
||||
if(mode == Relative) return { name, " $", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
if(mode == ADirectX) return { name, " a,$", hex<3>(pdl), "+x" };
|
||||
if(mode == AAbsoluteX) return { name, " a,$", hex<4>(pa), "+x" };
|
||||
if(mode == AAbsoluteY) return { name, " a,$", hex<4>(pa), "+y" };
|
||||
if(mode == AIDirectY) return { name, " a,($", hex<3>(pdl), ")+y" };
|
||||
if(mode == DirectConstant) return { name, " $", hex<3>(pdh), ",#$", hex<2>(pl) };
|
||||
if(mode == IXIY) return { name, " (x),(y)" };
|
||||
if(mode == DirectX) return { name, " $", hex<3>(pdl), "+x" };
|
||||
if(mode == A) return { name, " a" };
|
||||
if(mode == X) return { name, " x" };
|
||||
if(mode == XAbsolute) return { name, " x,$", hex<4>(pa) };
|
||||
if(mode == IAbsoluteX) return { name, " ($", hex<4>(pa), "+x)" };
|
||||
if(mode == CNAbsoluteBit) return { name, " c,!$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == XDirect) return { name, " x,$", hex<3>(pdl) };
|
||||
if(mode == PVector) return { name, " $ff", hex<2>(pl) };
|
||||
if(mode == YaDirect) return { name, " ya,$", hex<3>(pdl) };
|
||||
if(mode == XA) return { name, " x,a" };
|
||||
if(mode == YAbsolute) return { name, " y,$", hex<4>(pa) };
|
||||
if(mode == Y) return { name, " y" };
|
||||
if(mode == AX) return { name, " a,x" };
|
||||
if(mode == YDirect) return { name, " y,$", hex<3>(pdl) };
|
||||
if(mode == YConstant) return { name, " y,#$", hex<2>(pl) };
|
||||
if(mode == XSp) return { name, " x,sp" };
|
||||
if(mode == YaX) return { name, " ya,x" };
|
||||
if(mode == IXPA) return { name, " (x)+,a" };
|
||||
if(mode == SpX) return { name, " sp,x" };
|
||||
if(mode == AIXP) return { name, " a,(x)+" };
|
||||
if(mode == DirectA) return { name, " $", hex<3>(pdl), ",a" };
|
||||
if(mode == IXA) return { name, " (x),a" };
|
||||
if(mode == IDirectXA) return { name, " ($", hex<3>(pdl), "+x),a" };
|
||||
if(mode == XConstant) return { name, " x,#$", hex<2>(pl) };
|
||||
if(mode == AbsoluteX) return { name, " $", hex<4>(pa), ",x" };
|
||||
if(mode == AbsoluteBitC) return { name, " $", hex<4>(pa & 0x1fff), ":", pa >> 13, ",c" };
|
||||
if(mode == DirectY) return { name, " $", hex<3>(pdl), ",y" };
|
||||
if(mode == AbsoluteY) return { name, " $", hex<4>(pa), ",y" };
|
||||
if(mode == Ya) return { name, " ya" };
|
||||
if(mode == DirectXA) return { name, " $", hex<3>(pdl), "+x,a" };
|
||||
if(mode == AbsoluteXA) return { name, " $", hex<4>(pa), "+x,a" };
|
||||
if(mode == AbsoluteYA) return { name, " $", hex<4>(pa), "+y,a" };
|
||||
if(mode == IDirectYA) return { name, " ($", hex<3>(pdl), ")+y,a" };
|
||||
if(mode == DirectYX) return { name, " $", hex<3>(pdl), "+y,x" };
|
||||
if(mode == DirectYa) return { name, " $", hex<3>(pdl), ",ya" };
|
||||
if(mode == DirectXY) return { name, " $", hex<3>(pdl), "+x,y" };
|
||||
if(mode == AY) return { name, " a,y" };
|
||||
if(mode == DirectXRelative) return { name, " $", hex<3>(pdl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == XDirectY) return { name, " x,$", hex<3>(pdl), "+y" };
|
||||
if(mode == YDirectX) return { name, " y,$", hex<3>(pdl), "+x" };
|
||||
if(mode == YA) return { name, " y,a" };
|
||||
if(mode == YRelative) return { name, " y,$", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,7 +25,7 @@ namespace nall {
|
|||
inline string& append(unsigned int value);
|
||||
inline string& append(double value);
|
||||
|
||||
inline bool readfile(const char*);
|
||||
inline bool readfile(const string&);
|
||||
|
||||
inline string& replace (const char*, const char*);
|
||||
inline string& qreplace(const char*, const char*);
|
||||
|
@ -113,11 +113,11 @@ namespace nall {
|
|||
inline char* strlower(char *str);
|
||||
inline char* strupper(char *str);
|
||||
inline char* strtr(char *dest, const char *before, const char *after);
|
||||
inline uintmax_t strhex (const char *str);
|
||||
inline intmax_t strsigned (const char *str);
|
||||
inline uintmax_t strunsigned(const char *str);
|
||||
inline uintmax_t strbin (const char *str);
|
||||
inline double strdouble (const char *str);
|
||||
inline uintmax_t hex (const char *str);
|
||||
inline intmax_t integer(const char *str);
|
||||
inline uintmax_t decimal(const char *str);
|
||||
inline uintmax_t binary (const char *str);
|
||||
inline double fp (const char *str);
|
||||
|
||||
//math.hpp
|
||||
inline bool strint (const char *str, int &result);
|
||||
|
@ -145,12 +145,17 @@ namespace nall {
|
|||
inline unsigned strlcpy(string &dest, const char *src, unsigned length);
|
||||
inline unsigned strlcat(string &dest, const char *src, unsigned length);
|
||||
inline string substr(const char *src, unsigned start = 0, unsigned length = 0);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strhex(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strsigned(intmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strunsigned(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strbin(uintmax_t value);
|
||||
inline unsigned strdouble(char *str, double value);
|
||||
inline string strdouble(double value);
|
||||
|
||||
inline string integer(intmax_t value);
|
||||
template<unsigned length = 0> inline string linteger(intmax_t value);
|
||||
template<unsigned length = 0> inline string rinteger(intmax_t value);
|
||||
inline string decimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string ldecimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string rdecimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string hex(uintmax_t value);
|
||||
template<unsigned length = 0> inline string binary(uintmax_t value);
|
||||
inline unsigned fp(char *str, double value);
|
||||
inline string fp(double value);
|
||||
|
||||
//variadic.hpp
|
||||
template<typename... Args> inline void print(Args&&... args);
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace nall {
|
|||
|
||||
//this is needed, as C++0x does not support explicit template specialization inside classes
|
||||
template<> inline string to_string<bool> (bool v) { return v ? "true" : "false"; }
|
||||
template<> inline string to_string<signed int> (signed int v) { return strsigned(v); }
|
||||
template<> inline string to_string<unsigned int> (unsigned int v) { return strunsigned(v); }
|
||||
template<> inline string to_string<double> (double v) { return strdouble(v); }
|
||||
template<> inline string to_string<signed int> (signed int v) { return integer(v); }
|
||||
template<> inline string to_string<unsigned int> (unsigned int v) { return decimal(v); }
|
||||
template<> inline string to_string<double> (double v) { return fp(v); }
|
||||
template<> inline string to_string<char*> (char *v) { return v; }
|
||||
template<> inline string to_string<const char*> (const char *v) { return v; }
|
||||
template<> inline string to_string<string> (string v) { return v; }
|
||||
|
|
|
@ -40,7 +40,7 @@ char* strtr(char *dest, const char *before, const char *after) {
|
|||
return dest;
|
||||
}
|
||||
|
||||
uintmax_t strhex(const char *str) {
|
||||
uintmax_t hex(const char *str) {
|
||||
if(!str) return 0;
|
||||
uintmax_t result = 0;
|
||||
|
||||
|
@ -60,13 +60,16 @@ uintmax_t strhex(const char *str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
intmax_t strsigned(const char *str) {
|
||||
intmax_t integer(const char *str) {
|
||||
if(!str) return 0;
|
||||
intmax_t result = 0;
|
||||
bool negate = false;
|
||||
|
||||
//check for negation
|
||||
if(*str == '-') {
|
||||
//check for sign
|
||||
if(*str == '+') {
|
||||
negate = false;
|
||||
str++;
|
||||
} else if(*str == '-') {
|
||||
negate = true;
|
||||
str++;
|
||||
}
|
||||
|
@ -81,7 +84,7 @@ intmax_t strsigned(const char *str) {
|
|||
return !negate ? result : -result;
|
||||
}
|
||||
|
||||
uintmax_t strunsigned(const char *str) {
|
||||
uintmax_t decimal(const char *str) {
|
||||
if(!str) return 0;
|
||||
uintmax_t result = 0;
|
||||
|
||||
|
@ -95,7 +98,7 @@ uintmax_t strunsigned(const char *str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
uintmax_t strbin(const char *str) {
|
||||
uintmax_t binary(const char *str) {
|
||||
if(!str) return 0;
|
||||
uintmax_t result = 0;
|
||||
|
||||
|
@ -113,7 +116,7 @@ uintmax_t strbin(const char *str) {
|
|||
return result;
|
||||
}
|
||||
|
||||
double strdouble(const char *str) {
|
||||
double fp(const char *str) {
|
||||
if(!str) return 0.0;
|
||||
bool negate = false;
|
||||
|
||||
|
|
|
@ -26,9 +26,9 @@ string& string::append(const char *s) {
|
|||
}
|
||||
|
||||
string& string::append(bool value) { append(value ? "true" : "false"); return *this; }
|
||||
string& string::append(signed int value) { append(strsigned(value)); return *this; }
|
||||
string& string::append(unsigned int value) { append(strunsigned(value)); return *this; }
|
||||
string& string::append(double value) { append(strdouble(value)); return *this; }
|
||||
string& string::append(signed int value) { append(integer(value)); return *this; }
|
||||
string& string::append(unsigned int value) { append(decimal(value)); return *this; }
|
||||
string& string::append(double value) { append(fp(value)); return *this; }
|
||||
|
||||
string::operator const char*() const {
|
||||
return data;
|
||||
|
@ -95,7 +95,7 @@ string::~string() {
|
|||
if(data) free(data);
|
||||
}
|
||||
|
||||
bool string::readfile(const char *filename) {
|
||||
bool string::readfile(const string &filename) {
|
||||
assign("");
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
|
|
@ -27,104 +27,202 @@ string substr(const char *src, unsigned start, unsigned length) {
|
|||
|
||||
/* arithmetic <> string */
|
||||
|
||||
template<unsigned length, char padding> string strhex(uintmax_t value) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
|
||||
//render string backwards, as we do not know its length yet
|
||||
do {
|
||||
unsigned n = value & 15;
|
||||
output[offset++] = n < 10 ? '0' + n : 'a' + n - 10;
|
||||
value >>= 4;
|
||||
} while(value);
|
||||
|
||||
while(offset < length) output[offset++] = padding;
|
||||
output[offset--] = 0;
|
||||
|
||||
//reverse the string in-place
|
||||
for(unsigned i = 0; i < (offset + 1) >> 1; i++) {
|
||||
char temp = output[i];
|
||||
output[i] = output[offset - i];
|
||||
output[offset - i] = temp;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
template<unsigned length, char padding> string strsigned(intmax_t value) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
|
||||
string integer(intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = abs(value);
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
output[offset++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
|
||||
while(offset < length) output[offset++] = padding;
|
||||
if(negative) output[offset++] = '-';
|
||||
output[offset--] = 0;
|
||||
|
||||
for(unsigned i = 0; i < (offset + 1) >> 1; i++) {
|
||||
char temp = output[i];
|
||||
output[i] = output[offset - i];
|
||||
output[offset - i] = temp;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
template<unsigned length, char padding> string strunsigned(uintmax_t value) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
output[offset++] = '0' + n;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size++] = negative ? '-' : '+';
|
||||
buffer[size] = 0;
|
||||
|
||||
while(offset < length) output[offset++] = padding;
|
||||
output[offset--] = 0;
|
||||
char result[size + 1];
|
||||
memset(result, '0', size);
|
||||
result[size] = 0;
|
||||
|
||||
for(unsigned i = 0; i < (offset + 1) >> 1; i++) {
|
||||
char temp = output[i];
|
||||
output[i] = output[offset - i];
|
||||
output[offset - i] = temp;
|
||||
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return output;
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length, char padding> string strbin(uintmax_t value) {
|
||||
string output;
|
||||
unsigned offset = 0;
|
||||
template<unsigned length_> string linteger(intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = abs(value);
|
||||
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size++] = negative ? '-' : '+';
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, ' ', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_> string rinteger(intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = abs(value);
|
||||
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size++] = negative ? '-' : '+';
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, ' ', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
string decimal(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size] = 0;
|
||||
|
||||
char result[size + 1];
|
||||
memset(result, '0', size);
|
||||
result[size] = 0;
|
||||
|
||||
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_> string ldecimal(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, ' ', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = 0, y = size - 1; x < length && y >= 0; x++, y--) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_> string rdecimal(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
buffer[size] = 0;
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, ' ', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_> string hex(uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value & 15;
|
||||
buffer[size++] = n < 10 ? '0' + n : 'a' + n - 10;
|
||||
value >>= 4;
|
||||
} while(value);
|
||||
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, '0', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
template<unsigned length_> string binary(uintmax_t value) {
|
||||
char buffer[256];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value & 1;
|
||||
output[offset++] = '0' + n;
|
||||
buffer[size++] = '0' + n;
|
||||
value >>= 1;
|
||||
} while(value);
|
||||
|
||||
while(offset < length) output[offset++] = padding;
|
||||
output[offset--] = 0;
|
||||
unsigned length = (length_ == 0 ? size : length_);
|
||||
char result[length + 1];
|
||||
memset(result, '0', length);
|
||||
result[length] = 0;
|
||||
|
||||
for(unsigned i = 0; i < (offset + 1) >> 1; i++) {
|
||||
char temp = output[i];
|
||||
output[i] = output[offset - i];
|
||||
output[offset - i] = temp;
|
||||
for(signed x = length - 1, y = 0; x >= 0 && y < size; x--, y++) {
|
||||
result[x] = buffer[y];
|
||||
}
|
||||
|
||||
return output;
|
||||
return (const char*)result;
|
||||
}
|
||||
|
||||
//using sprintf is certainly not the most ideal method to convert
|
||||
//a double to a string ... but attempting to parse a double by
|
||||
//hand, digit-by-digit, results in subtle rounding errors.
|
||||
unsigned strdouble(char *str, double value) {
|
||||
unsigned fp(char *str, double value) {
|
||||
char buffer[256];
|
||||
sprintf(buffer, "%f", value);
|
||||
|
||||
|
@ -145,10 +243,10 @@ unsigned strdouble(char *str, double value) {
|
|||
return length + 1;
|
||||
}
|
||||
|
||||
string strdouble(double value) {
|
||||
string fp(double value) {
|
||||
string temp;
|
||||
temp.reserve(strdouble(0, value));
|
||||
strdouble(temp(), value);
|
||||
temp.reserve(fp(0, value));
|
||||
fp(temp(), value);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,84 +8,110 @@
|
|||
namespace nall {
|
||||
template<unsigned bits> class uint_t {
|
||||
private:
|
||||
enum { bytes = (bits + 7) >> 3 }; //minimum number of bytes needed to store value
|
||||
typedef typename static_if<
|
||||
sizeof(int) >= bytes,
|
||||
unsigned int,
|
||||
typename static_if<
|
||||
sizeof(long) >= bytes,
|
||||
unsigned long,
|
||||
typename static_if<
|
||||
sizeof(long long) >= bytes,
|
||||
unsigned long long,
|
||||
void
|
||||
>::type
|
||||
>::type
|
||||
>::type T;
|
||||
static_assert(!std::is_same<T, void>::value, "");
|
||||
T data;
|
||||
unsigned data;
|
||||
|
||||
public:
|
||||
inline operator T() const { return data; }
|
||||
inline T operator ++(int) { T r = data; data = uclip<bits>(data + 1); return r; }
|
||||
inline T operator --(int) { T r = data; data = uclip<bits>(data - 1); return r; }
|
||||
inline T operator ++() { return data = uclip<bits>(data + 1); }
|
||||
inline T operator --() { return data = uclip<bits>(data - 1); }
|
||||
inline T operator =(const T i) { return data = uclip<bits>(i); }
|
||||
inline T operator |=(const T i) { return data = uclip<bits>(data | i); }
|
||||
inline T operator ^=(const T i) { return data = uclip<bits>(data ^ i); }
|
||||
inline T operator &=(const T i) { return data = uclip<bits>(data & i); }
|
||||
inline T operator<<=(const T i) { return data = uclip<bits>(data << i); }
|
||||
inline T operator>>=(const T i) { return data = uclip<bits>(data >> i); }
|
||||
inline T operator +=(const T i) { return data = uclip<bits>(data + i); }
|
||||
inline T operator -=(const T i) { return data = uclip<bits>(data - i); }
|
||||
inline T operator *=(const T i) { return data = uclip<bits>(data * i); }
|
||||
inline T operator /=(const T i) { return data = uclip<bits>(data / i); }
|
||||
inline T operator %=(const T i) { return data = uclip<bits>(data % i); }
|
||||
inline operator unsigned() const { return data; }
|
||||
inline unsigned operator ++(int) { unsigned r = data; data = uclip<bits>(data + 1); return r; }
|
||||
inline unsigned operator --(int) { unsigned r = data; data = uclip<bits>(data - 1); return r; }
|
||||
inline unsigned operator ++() { return data = uclip<bits>(data + 1); }
|
||||
inline unsigned operator --() { return data = uclip<bits>(data - 1); }
|
||||
inline unsigned operator =(const unsigned i) { return data = uclip<bits>(i); }
|
||||
inline unsigned operator |=(const unsigned i) { return data = uclip<bits>(data | i); }
|
||||
inline unsigned operator ^=(const unsigned i) { return data = uclip<bits>(data ^ i); }
|
||||
inline unsigned operator &=(const unsigned i) { return data = uclip<bits>(data & i); }
|
||||
inline unsigned operator<<=(const unsigned i) { return data = uclip<bits>(data << i); }
|
||||
inline unsigned operator>>=(const unsigned i) { return data = uclip<bits>(data >> i); }
|
||||
inline unsigned operator +=(const unsigned i) { return data = uclip<bits>(data + i); }
|
||||
inline unsigned operator -=(const unsigned i) { return data = uclip<bits>(data - i); }
|
||||
inline unsigned operator *=(const unsigned i) { return data = uclip<bits>(data * i); }
|
||||
inline unsigned operator /=(const unsigned i) { return data = uclip<bits>(data / i); }
|
||||
inline unsigned operator %=(const unsigned i) { return data = uclip<bits>(data % i); }
|
||||
|
||||
inline uint_t() : data(0) {}
|
||||
inline uint_t(const T i) : data(uclip<bits>(i)) {}
|
||||
inline uint_t(const unsigned i) : data(uclip<bits>(i)) {}
|
||||
};
|
||||
|
||||
template<unsigned bits> class int_t {
|
||||
private:
|
||||
enum { bytes = (bits + 7) >> 3 }; //minimum number of bytes needed to store value
|
||||
typedef typename static_if<
|
||||
sizeof(int) >= bytes,
|
||||
signed int,
|
||||
typename static_if<
|
||||
sizeof(long) >= bytes,
|
||||
signed long,
|
||||
typename static_if<
|
||||
sizeof(long long) >= bytes,
|
||||
signed long long,
|
||||
void
|
||||
>::type
|
||||
>::type
|
||||
>::type T;
|
||||
static_assert(!std::is_same<T, void>::value, "");
|
||||
T data;
|
||||
signed data;
|
||||
|
||||
public:
|
||||
inline operator T() const { return data; }
|
||||
inline T operator ++(int) { T r = data; data = sclip<bits>(data + 1); return r; }
|
||||
inline T operator --(int) { T r = data; data = sclip<bits>(data - 1); return r; }
|
||||
inline T operator ++() { return data = sclip<bits>(data + 1); }
|
||||
inline T operator --() { return data = sclip<bits>(data - 1); }
|
||||
inline T operator =(const T i) { return data = sclip<bits>(i); }
|
||||
inline T operator |=(const T i) { return data = sclip<bits>(data | i); }
|
||||
inline T operator ^=(const T i) { return data = sclip<bits>(data ^ i); }
|
||||
inline T operator &=(const T i) { return data = sclip<bits>(data & i); }
|
||||
inline T operator<<=(const T i) { return data = sclip<bits>(data << i); }
|
||||
inline T operator>>=(const T i) { return data = sclip<bits>(data >> i); }
|
||||
inline T operator +=(const T i) { return data = sclip<bits>(data + i); }
|
||||
inline T operator -=(const T i) { return data = sclip<bits>(data - i); }
|
||||
inline T operator *=(const T i) { return data = sclip<bits>(data * i); }
|
||||
inline T operator /=(const T i) { return data = sclip<bits>(data / i); }
|
||||
inline T operator %=(const T i) { return data = sclip<bits>(data % i); }
|
||||
inline operator signed() const { return data; }
|
||||
inline signed operator ++(int) { signed r = data; data = sclip<bits>(data + 1); return r; }
|
||||
inline signed operator --(int) { signed r = data; data = sclip<bits>(data - 1); return r; }
|
||||
inline signed operator ++() { return data = sclip<bits>(data + 1); }
|
||||
inline signed operator --() { return data = sclip<bits>(data - 1); }
|
||||
inline signed operator =(const signed i) { return data = sclip<bits>(i); }
|
||||
inline signed operator |=(const signed i) { return data = sclip<bits>(data | i); }
|
||||
inline signed operator ^=(const signed i) { return data = sclip<bits>(data ^ i); }
|
||||
inline signed operator &=(const signed i) { return data = sclip<bits>(data & i); }
|
||||
inline signed operator<<=(const signed i) { return data = sclip<bits>(data << i); }
|
||||
inline signed operator>>=(const signed i) { return data = sclip<bits>(data >> i); }
|
||||
inline signed operator +=(const signed i) { return data = sclip<bits>(data + i); }
|
||||
inline signed operator -=(const signed i) { return data = sclip<bits>(data - i); }
|
||||
inline signed operator *=(const signed i) { return data = sclip<bits>(data * i); }
|
||||
inline signed operator /=(const signed i) { return data = sclip<bits>(data / i); }
|
||||
inline signed operator %=(const signed i) { return data = sclip<bits>(data % i); }
|
||||
|
||||
inline int_t() : data(0) {}
|
||||
inline int_t(const T i) : data(sclip<bits>(i)) {}
|
||||
inline int_t(const signed i) : data(sclip<bits>(i)) {}
|
||||
};
|
||||
|
||||
class varuint_t {
|
||||
private:
|
||||
unsigned data;
|
||||
unsigned mask;
|
||||
|
||||
public:
|
||||
inline operator unsigned() const { return data; }
|
||||
inline unsigned operator ++(int) { unsigned r = data; data = (data + 1) & mask; return r; }
|
||||
inline unsigned operator --(int) { unsigned r = data; data = (data - 1) & mask; return r; }
|
||||
inline unsigned operator ++() { return data = (data + 1) & mask; }
|
||||
inline unsigned operator --() { return data = (data - 1) & mask; }
|
||||
inline unsigned operator =(const unsigned i) { return data = (i) & mask; }
|
||||
inline unsigned operator |=(const unsigned i) { return data = (data | i) & mask; }
|
||||
inline unsigned operator ^=(const unsigned i) { return data = (data ^ i) & mask; }
|
||||
inline unsigned operator &=(const unsigned i) { return data = (data & i) & mask; }
|
||||
inline unsigned operator<<=(const unsigned i) { return data = (data << i) & mask; }
|
||||
inline unsigned operator>>=(const unsigned i) { return data = (data >> i) & mask; }
|
||||
inline unsigned operator +=(const unsigned i) { return data = (data + i) & mask; }
|
||||
inline unsigned operator -=(const unsigned i) { return data = (data - i) & mask; }
|
||||
inline unsigned operator *=(const unsigned i) { return data = (data * i) & mask; }
|
||||
inline unsigned operator /=(const unsigned i) { return data = (data / i) & mask; }
|
||||
inline unsigned operator %=(const unsigned i) { return data = (data % i) & mask; }
|
||||
|
||||
inline void bits(unsigned bits) { mask = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1); data &= mask; }
|
||||
inline varuint_t() : data(0), mask(~0U) {}
|
||||
inline varuint_t(const unsigned i) : data(i), mask(~0U) {}
|
||||
};
|
||||
|
||||
class varuintmax_t {
|
||||
private:
|
||||
uintmax_t data;
|
||||
uintmax_t mask;
|
||||
|
||||
public:
|
||||
inline operator uintmax_t() const { return data; }
|
||||
inline uintmax_t operator ++(int) { uintmax_t r = data; data = (data + 1) & mask; return r; }
|
||||
inline uintmax_t operator --(int) { uintmax_t r = data; data = (data - 1) & mask; return r; }
|
||||
inline uintmax_t operator ++() { return data = (data + 1) & mask; }
|
||||
inline uintmax_t operator --() { return data = (data - 1) & mask; }
|
||||
inline uintmax_t operator =(const uintmax_t i) { return data = (i) & mask; }
|
||||
inline uintmax_t operator |=(const uintmax_t i) { return data = (data | i) & mask; }
|
||||
inline uintmax_t operator ^=(const uintmax_t i) { return data = (data ^ i) & mask; }
|
||||
inline uintmax_t operator &=(const uintmax_t i) { return data = (data & i) & mask; }
|
||||
inline uintmax_t operator<<=(const uintmax_t i) { return data = (data << i) & mask; }
|
||||
inline uintmax_t operator>>=(const uintmax_t i) { return data = (data >> i) & mask; }
|
||||
inline uintmax_t operator +=(const uintmax_t i) { return data = (data + i) & mask; }
|
||||
inline uintmax_t operator -=(const uintmax_t i) { return data = (data - i) & mask; }
|
||||
inline uintmax_t operator *=(const uintmax_t i) { return data = (data * i) & mask; }
|
||||
inline uintmax_t operator /=(const uintmax_t i) { return data = (data / i) & mask; }
|
||||
inline uintmax_t operator %=(const uintmax_t i) { return data = (data % i) & mask; }
|
||||
|
||||
inline void bits(unsigned bits) { mask = (1ULL << (bits - 1)) + ((1ULL << (bits - 1)) - 1); data &= mask; }
|
||||
inline varuintmax_t() : data(0), mask(~0ULL) {}
|
||||
inline varuintmax_t(const uintmax_t i) : data(i), mask(~0ULL) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace nall {
|
|||
void reserve(unsigned newsize) {
|
||||
newsize = bit::round(newsize); //round to nearest power of two (for amortized growth)
|
||||
|
||||
T *poolcopy = (T*)malloc(newsize * sizeof(T));
|
||||
T *poolcopy = (T*)calloc(newsize, sizeof(T));
|
||||
for(unsigned i = 0; i < min(objectsize, newsize); i++) new(poolcopy + i) T(pool[i]);
|
||||
for(unsigned i = 0; i < objectsize; i++) pool[i].~T();
|
||||
free(pool);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c phoenix.cpp `pkg-config --cflags gtk+-2.0` -DPHOENIX_GTK
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c test.cpp -DPHOENIX_GTK
|
||||
g++-4.5 -s -o test-gtk test.o phoenix.o `pkg-config --libs gtk+-2.0`
|
||||
rm *.o
|
|
@ -1,6 +0,0 @@
|
|||
moc -i -o qt/qt.moc qt/qt.moc.hpp
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c phoenix.cpp `pkg-config --cflags QtCore QtGui` -DPHOENIX_QT
|
||||
g++-4.5 -std=gnu++0x -I. -O3 -fomit-frame-pointer -c test.cpp -DPHOENIX_QT
|
||||
g++-4.5 -s -o test-qt test.o phoenix.o `pkg-config --libs QtCore QtGui`
|
||||
rm *.o
|
||||
#rm qt/qt.moc
|
|
@ -1,6 +0,0 @@
|
|||
windres windows/phoenix.rc phoenix-resource.o
|
||||
g++ -std=gnu++0x -I. -O3 -fomit-frame-pointer -c phoenix.cpp -DPHOENIX_WINDOWS
|
||||
g++ -std=gnu++0x -I. -O3 -fomit-frame-pointer -c test.cpp -DPHOENIX_WINDOWS
|
||||
g++ -mconsole -s -o test-windows test.o phoenix.o phoenix-resource.o -lkernel32 -luser32 -lgdi32 -ladvapi32 -lcomctl32 -lcomdlg32 -lshell32 -lole32
|
||||
@pause
|
||||
@del *.o
|
|
@ -0,0 +1,170 @@
|
|||
#include "state.hpp"
|
||||
#include "layout/fixed-layout.cpp"
|
||||
#include "layout/horizontal-layout.cpp"
|
||||
#include "layout/vertical-layout.cpp"
|
||||
|
||||
#if defined(PHOENIX_WINDOWS)
|
||||
#include "../windows/windows.cpp"
|
||||
#elif defined(PHOENIX_QT)
|
||||
#include "../qt/qt.cpp"
|
||||
#elif defined(PHOENIX_GTK)
|
||||
#include "../gtk/gtk.cpp"
|
||||
#elif defined(PHOENIX_REFERENCE)
|
||||
#include "../reference/reference.cpp"
|
||||
#endif
|
||||
|
||||
Object::Object() { OS::initialize(); }
|
||||
|
||||
Geometry OS::availableGeometry() { return pOS::availableGeometry(); }
|
||||
Geometry OS::desktopGeometry() { return pOS::desktopGeometry(); }
|
||||
string OS::fileLoad_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileLoad(parent, path, filter); }
|
||||
string OS::fileSave_(Window &parent, const string &path, const lstring &filter_) { auto filter = filter_; if(filter.size() == 0) filter.append("All files (*)"); return pOS::fileSave(parent, path, filter); }
|
||||
string OS::folderSelect(Window &parent, const string &path) { return pOS::folderSelect(parent, path); }
|
||||
void OS::main() { return pOS::main(); }
|
||||
bool OS::pendingEvents() { return pOS::pendingEvents(); }
|
||||
void OS::processEvents() { return pOS::processEvents(); }
|
||||
void OS::quit() { return pOS::quit(); }
|
||||
void OS::initialize() { static bool initialized = false; if(initialized == false) { initialized = true; return pOS::initialize(); } }
|
||||
|
||||
void Font::setBold(bool bold) { state.bold = bold; return p.setBold(bold); }
|
||||
void Font::setFamily(const string &family) { state.family = family; return p.setFamily(family); }
|
||||
void Font::setItalic(bool italic) { state.italic = italic; return p.setItalic(italic); }
|
||||
void Font::setSize(unsigned size) { state.size = size; return p.setSize(size); }
|
||||
void Font::setUnderline(bool underline) { state.underline = underline; return p.setUnderline(underline); }
|
||||
Font::Font() : state(*new State), p(*new pFont(*this)) { p.constructor(); }
|
||||
|
||||
MessageWindow::Response MessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) { return pMessageWindow::information(parent, text, buttons); }
|
||||
MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) { return pMessageWindow::question(parent, text, buttons); }
|
||||
MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) { return pMessageWindow::warning(parent, text, buttons); }
|
||||
MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) { return pMessageWindow::critical(parent, text, buttons); }
|
||||
|
||||
Window Window::None;
|
||||
void Window::append(Layout &layout) { state.layout.append(layout); return p.append(layout); }
|
||||
void Window::append(Menu &menu) { state.menu.append(menu); ((Action&)menu).state.parent = this; return p.append(menu); }
|
||||
void Window::append(Widget &widget) { state.widget.append(widget); return p.append(widget); }
|
||||
Geometry Window::frameGeometry() { Geometry geometry = p.geometry(), margin = p.frameMargin(); return { geometry.x - margin.x, geometry.y - margin.y, geometry.width + margin.width, geometry.height + margin.height }; }
|
||||
Geometry Window::frameMargin() { return p.frameMargin(); }
|
||||
bool Window::focused() { return p.focused(); }
|
||||
Geometry Window::geometry() { return p.geometry(); }
|
||||
void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) { state.backgroundColor = true; state.backgroundColorRed = red; state.backgroundColorGreen = green; state.backgroundColorBlue = blue; return p.setBackgroundColor(red, green, blue); }
|
||||
void Window::setFrameGeometry(const Geometry &geometry) { Geometry margin = p.frameMargin(); return setGeometry({ geometry.x + margin.x, geometry.y + margin.y, geometry.width - margin.width, geometry.height - margin.height }); }
|
||||
void Window::setFocused() { return p.setFocused(); }
|
||||
void Window::setFullScreen(bool fullScreen) { state.fullScreen = fullScreen; return p.setFullScreen(fullScreen); }
|
||||
void Window::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); }
|
||||
void Window::setMenuFont(Font &font) { state.menuFont = &font; return p.setMenuFont(font); }
|
||||
void Window::setMenuVisible(bool visible) { state.menuVisible = visible; return p.setMenuVisible(visible); }
|
||||
void Window::setResizable(bool resizable) { state.resizable = resizable; return p.setResizable(resizable); }
|
||||
void Window::setStatusFont(Font &font) { state.statusFont = &font; return p.setStatusFont(font); }
|
||||
void Window::setStatusText(const string &text) { state.statusText = text; return p.setStatusText(text); }
|
||||
void Window::setStatusVisible(bool visible) { state.statusVisible = visible; return p.setStatusVisible(visible); }
|
||||
void Window::setTitle(const string &text) { state.title = text; return p.setTitle(text); }
|
||||
void Window::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); }
|
||||
void Window::setWidgetFont(Font &font) { state.widgetFont = &font; return p.setWidgetFont(font); }
|
||||
Window::Window() : state(*new State), p(*new pWindow(*this)) { p.constructor(); }
|
||||
|
||||
void Action::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); }
|
||||
void Action::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); }
|
||||
Action::Action(pAction &p) : state(*new State), p(p) { p.constructor(); }
|
||||
|
||||
void Menu::append(Action &action) { state.action.append(action); return p.append(action); }
|
||||
void Menu::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
Menu::Menu() : state(*new State), base_from_member<pMenu&>(*new pMenu(*this)), Action(base_from_member<pMenu&>::value), p(base_from_member<pMenu&>::value) { p.constructor(); }
|
||||
|
||||
Separator::Separator() : base_from_member<pSeparator&>(*new pSeparator(*this)), Action(base_from_member<pSeparator&>::value), p(base_from_member<pSeparator&>::value) { p.constructor(); }
|
||||
|
||||
void Item::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
Item::Item() : state(*new State), base_from_member<pItem&>(*new pItem(*this)), Action(base_from_member<pItem&>::value), p(base_from_member<pItem&>::value) { p.constructor(); }
|
||||
|
||||
bool CheckItem::checked() { return p.checked(); }
|
||||
void CheckItem::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); }
|
||||
void CheckItem::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
CheckItem::CheckItem() : state(*new State), base_from_member<pCheckItem&>(*new pCheckItem(*this)), Action(base_from_member<pCheckItem&>::value), p(base_from_member<pCheckItem&>::value) { p.constructor(); }
|
||||
|
||||
void RadioItem::group_(const reference_array<RadioItem&> &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); }
|
||||
bool RadioItem::checked() { return p.checked(); }
|
||||
void RadioItem::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); }
|
||||
void RadioItem::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
RadioItem::RadioItem() : state(*new State), base_from_member<pRadioItem&>(*new pRadioItem(*this)), Action(base_from_member<pRadioItem&>::value), p(base_from_member<pRadioItem&>::value) { p.constructor(); }
|
||||
|
||||
bool Widget::enabled() { return state.enabled; }
|
||||
void Widget::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); }
|
||||
void Widget::setFocused() { return p.setFocused(); }
|
||||
void Widget::setFont(Font &font) { state.font = &font; return p.setFont(font); }
|
||||
void Widget::setGeometry(const Geometry &geometry) { state.geometry = geometry; return p.setGeometry(geometry); }
|
||||
void Widget::setVisible(bool visible) { state.visible = visible; return p.setVisible(visible); }
|
||||
bool Widget::visible() { return state.visible; }
|
||||
Widget::Widget() : state(*new State), p(*new pWidget(*this)) { state.abstract = true; p.constructor(); }
|
||||
Widget::Widget(pWidget &p) : state(*new State), p(p) { p.constructor(); }
|
||||
|
||||
void Button::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
Button::Button() : state(*new State), base_from_member<pButton&>(*new pButton(*this)), Widget(base_from_member<pButton&>::value), p(base_from_member<pButton&>::value) { p.constructor(); }
|
||||
|
||||
bool CheckBox::checked() { return p.checked(); }
|
||||
void CheckBox::setChecked(bool checked) { state.checked = checked; return p.setChecked(checked); }
|
||||
void CheckBox::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
CheckBox::CheckBox() : state(*new State), base_from_member<pCheckBox&>(*new pCheckBox(*this)), Widget(base_from_member<pCheckBox&>::value), p(base_from_member<pCheckBox&>::value) { p.constructor(); }
|
||||
|
||||
void ComboBox::append(const string &text) { state.text.append(text); return p.append(text); }
|
||||
void ComboBox::reset() { state.selection = 0; state.text.reset(); return p.reset(); }
|
||||
unsigned ComboBox::selection() { return p.selection(); }
|
||||
void ComboBox::setSelection(unsigned row) { state.selection = row; return p.setSelection(row); }
|
||||
ComboBox::ComboBox() : state(*new State), base_from_member<pComboBox&>(*new pComboBox(*this)), Widget(base_from_member<pComboBox&>::value), p(base_from_member<pComboBox&>::value) { p.constructor(); }
|
||||
|
||||
void HexEdit::setColumns(unsigned columns) { state.columns = columns; return p.setColumns(columns); }
|
||||
void HexEdit::setLength(unsigned length) { state.length = length; return p.setLength(length); }
|
||||
void HexEdit::setOffset(unsigned offset) { state.offset = offset; return p.setOffset(offset); }
|
||||
void HexEdit::setRows(unsigned rows) { state.rows = rows; return p.setRows(rows); }
|
||||
void HexEdit::update() { return p.update(); }
|
||||
HexEdit::HexEdit() : state(*new State), base_from_member<pHexEdit&>(*new pHexEdit(*this)), Widget(base_from_member<pHexEdit&>::value), p(base_from_member<pHexEdit&>::value) { p.constructor(); }
|
||||
|
||||
unsigned HorizontalSlider::position() { return p.position(); }
|
||||
void HorizontalSlider::setLength(unsigned length) { state.length = length; return p.setLength(length); }
|
||||
void HorizontalSlider::setPosition(unsigned position) { state.position = position; return p.setPosition(position); }
|
||||
HorizontalSlider::HorizontalSlider() : state(*new State), base_from_member<pHorizontalSlider&>(*new pHorizontalSlider(*this)), Widget(base_from_member<pHorizontalSlider&>::value), p(base_from_member<pHorizontalSlider&>::value) { p.constructor(); }
|
||||
|
||||
void Label::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
Label::Label() : state(*new State), base_from_member<pLabel&>(*new pLabel(*this)), Widget(base_from_member<pLabel&>::value), p(base_from_member<pLabel&>::value) { p.constructor(); }
|
||||
|
||||
void LineEdit::setEditable(bool editable) { state.editable = editable; return p.setEditable(editable); }
|
||||
void LineEdit::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
string LineEdit::text() { return p.text(); }
|
||||
LineEdit::LineEdit() : state(*new State), base_from_member<pLineEdit&>(*new pLineEdit(*this)), Widget(base_from_member<pLineEdit&>::value), p(base_from_member<pLineEdit&>::value) { p.constructor(); }
|
||||
|
||||
void ListView::append_(const lstring &text) { state.checked.append(false); state.text.append(text); return p.append(text); }
|
||||
void ListView::autoSizeColumns() { return p.autoSizeColumns(); }
|
||||
bool ListView::checked(unsigned row) { return p.checked(row); }
|
||||
void ListView::modify_(unsigned row, const lstring &text) { state.text[row] = text; return p.modify(row, text); }
|
||||
void ListView::reset() { state.checked.reset(); state.text.reset(); return p.reset(); }
|
||||
bool ListView::selected() { return p.selected(); }
|
||||
unsigned ListView::selection() { return p.selection(); }
|
||||
void ListView::setCheckable(bool checkable) { state.checkable = checkable; return p.setCheckable(checkable); }
|
||||
void ListView::setChecked(unsigned row, bool checked) { state.checked[row] = checked; return p.setChecked(row, checked); }
|
||||
void ListView::setHeaderText_(const lstring &text) { state.headerText = text; return p.setHeaderText(text); }
|
||||
void ListView::setHeaderVisible(bool visible) { state.headerVisible = visible; return p.setHeaderVisible(visible); }
|
||||
void ListView::setSelected(bool selected) { state.selected = selected; return p.setSelected(selected); }
|
||||
void ListView::setSelection(unsigned row) { state.selected = true; state.selection = row; return p.setSelection(row); }
|
||||
ListView::ListView() : state(*new State), base_from_member<pListView&>(*new pListView(*this)), Widget(base_from_member<pListView&>::value), p(base_from_member<pListView&>::value) { p.constructor(); }
|
||||
|
||||
void ProgressBar::setPosition(unsigned position) { state.position = position; return p.setPosition(position); }
|
||||
ProgressBar::ProgressBar() : state(*new State), base_from_member<pProgressBar&>(*new pProgressBar(*this)), Widget(base_from_member<pProgressBar&>::value), p(base_from_member<pProgressBar&>::value) { p.constructor(); }
|
||||
|
||||
void RadioBox::group_(const reference_array<RadioBox&> &list) { foreach(item, list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); }
|
||||
bool RadioBox::checked() { return p.checked(); }
|
||||
void RadioBox::setChecked() { foreach(item, state.group) item.state.checked = false; state.checked = true; return p.setChecked(); }
|
||||
void RadioBox::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
RadioBox::RadioBox() : state(*new State), base_from_member<pRadioBox&>(*new pRadioBox(*this)), Widget(base_from_member<pRadioBox&>::value), p(base_from_member<pRadioBox&>::value) { p.constructor(); }
|
||||
|
||||
void TextEdit::setCursorPosition(unsigned position) { state.cursorPosition = position; return p.setCursorPosition(position); }
|
||||
void TextEdit::setEditable(bool editable) { state.editable = editable; return p.setEditable(editable); }
|
||||
void TextEdit::setText(const string &text) { state.text = text; return p.setText(text); }
|
||||
void TextEdit::setWordWrap(bool wordWrap) { state.wordWrap = wordWrap; return p.setWordWrap(wordWrap); }
|
||||
string TextEdit::text() { return p.text(); }
|
||||
TextEdit::TextEdit() : state(*new State), base_from_member<pTextEdit&>(*new pTextEdit(*this)), Widget(base_from_member<pTextEdit&>::value), p(base_from_member<pTextEdit&>::value) { p.constructor(); }
|
||||
|
||||
unsigned VerticalSlider::position() { return p.position(); }
|
||||
void VerticalSlider::setLength(unsigned length) { state.length = length; return p.setLength(length); }
|
||||
void VerticalSlider::setPosition(unsigned position) { state.position = position; return p.setPosition(position); }
|
||||
VerticalSlider::VerticalSlider() : state(*new State), base_from_member<pVerticalSlider&>(*new pVerticalSlider(*this)), Widget(base_from_member<pVerticalSlider&>::value), p(base_from_member<pVerticalSlider&>::value) { p.constructor(); }
|
||||
|
||||
uintptr_t Viewport::handle() { return p.handle(); }
|
||||
Viewport::Viewport() : base_from_member<pViewport&>(*new pViewport(*this)), Widget(base_from_member<pViewport&>::value), p(base_from_member<pViewport&>::value) { p.constructor(); }
|
|
@ -0,0 +1,405 @@
|
|||
struct Font;
|
||||
struct Window;
|
||||
struct Menu;
|
||||
struct Layout;
|
||||
struct Widget;
|
||||
|
||||
struct pOS;
|
||||
struct pFont;
|
||||
struct pWindow;
|
||||
struct pAction;
|
||||
struct pMenu;
|
||||
struct pSeparator;
|
||||
struct pItem;
|
||||
struct pCheckItem;
|
||||
struct pRadioItem;
|
||||
struct pLayout;
|
||||
struct pWidget;
|
||||
struct pButton;
|
||||
struct pCheckBox;
|
||||
struct pComboBox;
|
||||
struct pHexEdit;
|
||||
struct pHorizontalSlider;
|
||||
struct pLabel;
|
||||
struct pLineEdit;
|
||||
struct pListView;
|
||||
struct pProgressBar;
|
||||
struct pRadioBox;
|
||||
struct pTextEdit;
|
||||
struct pVerticalSlider;
|
||||
struct pViewport;
|
||||
|
||||
struct Geometry {
|
||||
signed x, y;
|
||||
unsigned width, height;
|
||||
inline Geometry() : x(0), y(0), width(0), height(0) {}
|
||||
inline Geometry(signed x, signed y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {}
|
||||
};
|
||||
|
||||
struct Object {
|
||||
Object();
|
||||
Object& operator=(const Object&) = delete;
|
||||
Object(const Object&) = delete;
|
||||
virtual void unused() {} //allows dynamic_cast<> on Object
|
||||
};
|
||||
|
||||
struct OS : Object {
|
||||
static Geometry availableGeometry();
|
||||
static Geometry desktopGeometry();
|
||||
template<typename... Args> static nall::string fileLoad(Window &parent, const nall::string &path, const Args&... args) { return fileLoad_(parent, path, { args... }); }
|
||||
template<typename... Args> static nall::string fileSave(Window &parent, const nall::string &path, const Args&... args) { return fileSave_(parent, path, { args... }); }
|
||||
static nall::string folderSelect(Window &parent, const nall::string &path);
|
||||
static void main();
|
||||
static bool pendingEvents();
|
||||
static void processEvents();
|
||||
static void quit();
|
||||
|
||||
OS();
|
||||
static void initialize();
|
||||
|
||||
private:
|
||||
static nall::string fileLoad_(Window &parent, const nall::string &path, const nall::lstring& filter);
|
||||
static nall::string fileSave_(Window &parent, const nall::string &path, const nall::lstring& filter);
|
||||
};
|
||||
|
||||
struct Font : Object {
|
||||
void setBold(bool bold = true);
|
||||
void setFamily(const nall::string &family);
|
||||
void setItalic(bool italic = true);
|
||||
void setSize(unsigned size);
|
||||
void setUnderline(bool underline = true);
|
||||
|
||||
Font();
|
||||
struct State;
|
||||
State &state;
|
||||
pFont &p;
|
||||
};
|
||||
|
||||
struct MessageWindow : Object {
|
||||
enum class Buttons : unsigned {
|
||||
Ok,
|
||||
OkCancel,
|
||||
YesNo,
|
||||
};
|
||||
|
||||
enum class Response : unsigned {
|
||||
Ok,
|
||||
Cancel,
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
|
||||
static Response information(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
static Response question(Window &parent, const nall::string &text, Buttons = Buttons::YesNo);
|
||||
static Response warning(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
};
|
||||
|
||||
struct Window : Object {
|
||||
static Window None;
|
||||
nall::function<void ()> onClose;
|
||||
nall::function<void ()> onMove;
|
||||
nall::function<void ()> onSize;
|
||||
|
||||
void append(Layout &layout);
|
||||
void append(Menu &menu);
|
||||
void append(Widget &widget);
|
||||
Geometry frameGeometry();
|
||||
Geometry frameMargin();
|
||||
bool focused();
|
||||
Geometry geometry();
|
||||
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void setFrameGeometry(const Geometry &geometry);
|
||||
void setFocused();
|
||||
void setFullScreen(bool fullScreen = true);
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setMenuFont(Font &font);
|
||||
void setMenuVisible(bool visible = true);
|
||||
void setResizable(bool resizable = true);
|
||||
void setStatusFont(Font &font);
|
||||
void setStatusText(const nall::string &text);
|
||||
void setStatusVisible(bool visible = true);
|
||||
void setTitle(const nall::string &text);
|
||||
void setVisible(bool visible = true);
|
||||
void setWidgetFont(Font &font);
|
||||
|
||||
Window();
|
||||
struct State;
|
||||
State &state;
|
||||
pWindow &p;
|
||||
};
|
||||
|
||||
struct Action : Object {
|
||||
void setEnabled(bool enabled = true);
|
||||
void setVisible(bool visible = true);
|
||||
|
||||
Action(pAction &p);
|
||||
struct State;
|
||||
State &state;
|
||||
pAction &p;
|
||||
};
|
||||
|
||||
struct Menu : private nall::base_from_member<pMenu&>, Action {
|
||||
void append(Action &action);
|
||||
void setText(const nall::string &text);
|
||||
|
||||
Menu();
|
||||
struct State;
|
||||
State &state;
|
||||
pMenu &p;
|
||||
};
|
||||
|
||||
struct Separator : private nall::base_from_member<pSeparator&>, Action {
|
||||
Separator();
|
||||
pSeparator &p;
|
||||
};
|
||||
|
||||
struct Item : private nall::base_from_member<pItem&>, Action {
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
void setText(const nall::string &text);
|
||||
|
||||
Item();
|
||||
struct State;
|
||||
State &state;
|
||||
pItem &p;
|
||||
};
|
||||
|
||||
struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
void setText(const nall::string &text);
|
||||
|
||||
CheckItem();
|
||||
struct State;
|
||||
State &state;
|
||||
pCheckItem &p;
|
||||
};
|
||||
|
||||
struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
|
||||
template<typename... Args> static void group(Args&... args) { group_({ args... }); }
|
||||
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string &text);
|
||||
|
||||
RadioItem();
|
||||
struct State;
|
||||
State &state;
|
||||
pRadioItem &p;
|
||||
|
||||
private:
|
||||
static void group_(const nall::reference_array<RadioItem&> &list);
|
||||
};
|
||||
|
||||
struct Layout : Object {
|
||||
virtual void setGeometry(Geometry &geometry) = 0;
|
||||
virtual void setParent(Window &parent) = 0;
|
||||
virtual void setVisible(bool visible = true) = 0;
|
||||
};
|
||||
|
||||
struct Widget : Object {
|
||||
bool enabled();
|
||||
void setEnabled(bool enabled = true);
|
||||
void setFocused();
|
||||
void setFont(Font &font);
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setVisible(bool visible = true);
|
||||
bool visible();
|
||||
|
||||
Widget();
|
||||
Widget(pWidget &p);
|
||||
struct State;
|
||||
State &state;
|
||||
pWidget &p;
|
||||
};
|
||||
|
||||
struct Button : private nall::base_from_member<pButton&>, Widget {
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
void setText(const nall::string &text);
|
||||
|
||||
Button();
|
||||
struct State;
|
||||
State &state;
|
||||
pButton &p;
|
||||
};
|
||||
|
||||
struct CheckBox : private nall::base_from_member<pCheckBox&>, Widget {
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
void setText(const nall::string &text);
|
||||
|
||||
CheckBox();
|
||||
struct State;
|
||||
State &state;
|
||||
pCheckBox &p;
|
||||
};
|
||||
|
||||
struct ComboBox : private nall::base_from_member<pComboBox&>, Widget {
|
||||
nall::function<void ()> onChange;
|
||||
|
||||
void append(const nall::string &text);
|
||||
void reset();
|
||||
unsigned selection();
|
||||
void setSelection(unsigned row);
|
||||
|
||||
ComboBox();
|
||||
struct State;
|
||||
State &state;
|
||||
pComboBox &p;
|
||||
};
|
||||
|
||||
struct HexEdit : private nall::base_from_member<pHexEdit&>, Widget {
|
||||
nall::function<uint8_t (unsigned)> onRead;
|
||||
nall::function<void (unsigned, uint8_t)> onWrite;
|
||||
|
||||
void setColumns(unsigned columns);
|
||||
void setLength(unsigned length);
|
||||
void setOffset(unsigned offset);
|
||||
void setRows(unsigned rows);
|
||||
void update();
|
||||
|
||||
HexEdit();
|
||||
struct State;
|
||||
State &state;
|
||||
pHexEdit &p;
|
||||
};
|
||||
|
||||
struct HorizontalSlider : private nall::base_from_member<pHorizontalSlider&>, Widget {
|
||||
nall::function<void ()> onChange;
|
||||
|
||||
unsigned position();
|
||||
void setLength(unsigned length);
|
||||
void setPosition(unsigned position);
|
||||
|
||||
HorizontalSlider();
|
||||
struct State;
|
||||
State &state;
|
||||
pHorizontalSlider &p;
|
||||
};
|
||||
|
||||
struct Label : private nall::base_from_member<pLabel&>, Widget {
|
||||
void setText(const nall::string &text);
|
||||
|
||||
Label();
|
||||
struct State;
|
||||
State &state;
|
||||
pLabel &p;
|
||||
};
|
||||
|
||||
struct LineEdit : private nall::base_from_member<pLineEdit&>, Widget {
|
||||
nall::function<void ()> onActivate;
|
||||
nall::function<void ()> onChange;
|
||||
|
||||
void setEditable(bool editable = true);
|
||||
void setText(const nall::string &text);
|
||||
nall::string text();
|
||||
|
||||
LineEdit();
|
||||
struct State;
|
||||
State &state;
|
||||
pLineEdit &p;
|
||||
};
|
||||
|
||||
struct ListView : private nall::base_from_member<pListView&>, Widget {
|
||||
nall::function<void ()> onActivate;
|
||||
nall::function<void ()> onChange;
|
||||
nall::function<void (unsigned)> onTick;
|
||||
|
||||
template<typename... Args> void append(const Args&... args) { append_({ args... }); }
|
||||
void autoSizeColumns();
|
||||
bool checked(unsigned row);
|
||||
template<typename... Args> void modify(unsigned row, const Args&... args) { modify_(row, { args... }); }
|
||||
void reset();
|
||||
bool selected();
|
||||
unsigned selection();
|
||||
void setCheckable(bool checkable = true);
|
||||
void setChecked(unsigned row, bool checked = true);
|
||||
template<typename... Args> void setHeaderText(const Args&... args) { setHeaderText_({ args... }); }
|
||||
void setHeaderVisible(bool visible = true);
|
||||
void setSelected(bool selected = true);
|
||||
void setSelection(unsigned row);
|
||||
|
||||
ListView();
|
||||
struct State;
|
||||
State &state;
|
||||
pListView &p;
|
||||
|
||||
private:
|
||||
void append_(const nall::lstring &list);
|
||||
void modify_(unsigned row, const nall::lstring &list);
|
||||
void setHeaderText_(const nall::lstring &list);
|
||||
};
|
||||
|
||||
struct ProgressBar : private nall::base_from_member<pProgressBar&>, Widget {
|
||||
void setPosition(unsigned position);
|
||||
|
||||
ProgressBar();
|
||||
struct State;
|
||||
State &state;
|
||||
pProgressBar &p;
|
||||
};
|
||||
|
||||
struct RadioBox : private nall::base_from_member<pRadioBox&>, Widget {
|
||||
template<typename... Args> static void group(Args&... args) { group_({ args... }); }
|
||||
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string &text);
|
||||
|
||||
RadioBox();
|
||||
struct State;
|
||||
State &state;
|
||||
pRadioBox &p;
|
||||
|
||||
private:
|
||||
static void group_(const nall::reference_array<RadioBox&> &list);
|
||||
};
|
||||
|
||||
struct TextEdit : private nall::base_from_member<pTextEdit&>, Widget {
|
||||
nall::function<void ()> onChange;
|
||||
|
||||
void setCursorPosition(unsigned position);
|
||||
void setEditable(bool editable = true);
|
||||
void setText(const nall::string &text);
|
||||
void setWordWrap(bool wordWrap = true);
|
||||
nall::string text();
|
||||
|
||||
TextEdit();
|
||||
struct State;
|
||||
State &state;
|
||||
pTextEdit &p;
|
||||
};
|
||||
|
||||
struct VerticalSlider : private nall::base_from_member<pVerticalSlider&>, Widget {
|
||||
nall::function<void ()> onChange;
|
||||
|
||||
unsigned position();
|
||||
void setLength(unsigned length);
|
||||
void setPosition(unsigned position);
|
||||
|
||||
VerticalSlider();
|
||||
struct State;
|
||||
State &state;
|
||||
pVerticalSlider &p;
|
||||
};
|
||||
|
||||
struct Viewport : private nall::base_from_member<pViewport&>, Widget {
|
||||
uintptr_t handle();
|
||||
|
||||
Viewport();
|
||||
pViewport &p;
|
||||
};
|
||||
|
||||
#include "layout/fixed-layout.hpp"
|
||||
#include "layout/horizontal-layout.hpp"
|
||||
#include "layout/vertical-layout.hpp"
|
|
@ -0,0 +1,20 @@
|
|||
void FixedLayout::setParent(Window &parent) {
|
||||
foreach(child, children) {
|
||||
parent.append(*child.widget);
|
||||
child.widget->setGeometry(child.geometry);
|
||||
}
|
||||
}
|
||||
|
||||
void FixedLayout::append(Widget &widget, const Geometry &geometry) {
|
||||
children.append({ &widget, geometry });
|
||||
}
|
||||
|
||||
void FixedLayout::setGeometry(Geometry &geometry) {
|
||||
}
|
||||
|
||||
void FixedLayout::setVisible(bool visible) {
|
||||
foreach(child, children) child.widget->setVisible(visible);
|
||||
}
|
||||
|
||||
FixedLayout::FixedLayout() {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
struct FixedLayout : Layout {
|
||||
void append(Widget &widget, const Geometry &geometry);
|
||||
void setGeometry(Geometry &geometry);
|
||||
void setParent(Window &parent);
|
||||
void setVisible(bool visible);
|
||||
FixedLayout();
|
||||
|
||||
//private:
|
||||
Window *parent;
|
||||
struct Children {
|
||||
Widget *widget;
|
||||
Geometry geometry;
|
||||
};
|
||||
nall::linear_vector<Children> children;
|
||||
};
|
|
@ -0,0 +1,88 @@
|
|||
void HorizontalLayout::setParent(Window &parent) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setParent(parent);
|
||||
if(child.widget) parent.append(*child.widget);
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::append(VerticalLayout &layout, unsigned width, unsigned height, unsigned spacing) {
|
||||
layout.width = width;
|
||||
layout.height = height;
|
||||
children.append({ &layout, 0, width, height, spacing });
|
||||
}
|
||||
|
||||
void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
|
||||
children.append({ 0, &widget, width, height, spacing });
|
||||
}
|
||||
|
||||
void HorizontalLayout::setGeometry(Geometry &geometry) {
|
||||
geometry.x += margin;
|
||||
geometry.y += margin;
|
||||
geometry.width -= margin * 2;
|
||||
geometry.height -= margin * 2;
|
||||
|
||||
unsigned geometryWidth = width ? width : geometry.width;
|
||||
unsigned geometryHeight = height ? height : geometry.height;
|
||||
|
||||
Geometry baseGeometry = geometry;
|
||||
linear_vector<HorizontalLayout::Children> children = this->children;
|
||||
|
||||
unsigned minimumWidth = 0;
|
||||
foreach(child, children) minimumWidth += child.width + child.spacing;
|
||||
|
||||
unsigned autosizeWidgets = 0;
|
||||
foreach(child, children) {
|
||||
if(child.width == 0) autosizeWidgets++;
|
||||
}
|
||||
foreach(child, children) {
|
||||
if(child.width == 0) child.width = (geometryWidth - minimumWidth) / autosizeWidgets;
|
||||
if(child.height == 0) child.height = geometryHeight;
|
||||
}
|
||||
|
||||
unsigned maxHeight = 0;
|
||||
foreach(child, children) {
|
||||
maxHeight = max(maxHeight, child.height);
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.layout) {
|
||||
child.layout->setGeometry(geometry);
|
||||
geometry.x += child.spacing;
|
||||
geometry.width -= child.spacing;
|
||||
geometry.y = baseGeometry.y;
|
||||
geometry.height = baseGeometry.height;
|
||||
}
|
||||
|
||||
if(child.widget) {
|
||||
child.widget->setGeometry({ geometry.x, geometry.y, child.width, child.height });
|
||||
geometry.x += child.width + child.spacing;
|
||||
geometry.width -= child.width + child.spacing;
|
||||
}
|
||||
}
|
||||
|
||||
geometry.y += maxHeight;
|
||||
geometry.height -= maxHeight;
|
||||
}
|
||||
|
||||
void HorizontalLayout::setMargin(unsigned margin_) {
|
||||
margin = margin_;
|
||||
}
|
||||
|
||||
unsigned HorizontalLayout::minimumWidth() {
|
||||
unsigned width = margin * 2;
|
||||
foreach(child, children) width += child.width + child.spacing;
|
||||
return width;
|
||||
}
|
||||
|
||||
void HorizontalLayout::setVisible(bool visible) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setVisible(visible);
|
||||
if(child.widget) child.widget->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout::HorizontalLayout() {
|
||||
margin = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
struct VerticalLayout;
|
||||
|
||||
struct HorizontalLayout : public Layout {
|
||||
void append(VerticalLayout &layout, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
unsigned minimumWidth();
|
||||
void setGeometry(Geometry &geometry);
|
||||
void setMargin(unsigned margin);
|
||||
void setParent(Window &parent);
|
||||
void setVisible(bool visible);
|
||||
HorizontalLayout();
|
||||
|
||||
//private:
|
||||
unsigned margin;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
struct Children {
|
||||
VerticalLayout *layout;
|
||||
Widget *widget;
|
||||
unsigned width, height, spacing;
|
||||
};
|
||||
nall::linear_vector<Children> children;
|
||||
};
|
|
@ -0,0 +1,88 @@
|
|||
void VerticalLayout::setParent(Window &parent) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setParent(parent);
|
||||
if(child.widget) parent.append(*child.widget);
|
||||
}
|
||||
}
|
||||
|
||||
void VerticalLayout::append(HorizontalLayout &layout, unsigned width, unsigned height, unsigned spacing) {
|
||||
layout.width = width;
|
||||
layout.height = height;
|
||||
children.append({ &layout, 0, width, height, spacing });
|
||||
}
|
||||
|
||||
void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
|
||||
children.append({ 0, &widget, width, height, spacing });
|
||||
}
|
||||
|
||||
void VerticalLayout::setGeometry(Geometry &geometry) {
|
||||
geometry.x += margin;
|
||||
geometry.y += margin;
|
||||
geometry.width -= margin * 2;
|
||||
geometry.height -= margin * 2;
|
||||
|
||||
unsigned geometryWidth = width ? width : geometry.width;
|
||||
unsigned geometryHeight = height ? height : geometry.height;
|
||||
|
||||
Geometry baseGeometry = geometry;
|
||||
linear_vector<VerticalLayout::Children> children = this->children;
|
||||
|
||||
unsigned minimumHeight = 0;
|
||||
foreach(child, children) minimumHeight += child.height + child.spacing;
|
||||
|
||||
unsigned autosizeWidgets = 0;
|
||||
foreach(child, children) {
|
||||
if(child.height == 0) autosizeWidgets++;
|
||||
}
|
||||
foreach(child, children) {
|
||||
if(child.width == 0) child.width = geometryWidth;
|
||||
if(child.height == 0) child.height = (geometryHeight - minimumHeight) / autosizeWidgets;
|
||||
}
|
||||
|
||||
unsigned maxWidth = 0;
|
||||
foreach(child, children) {
|
||||
maxWidth = max(maxWidth, child.width);
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.layout) {
|
||||
child.layout->setGeometry(geometry);
|
||||
geometry.x = baseGeometry.x;
|
||||
geometry.width = baseGeometry.width;
|
||||
geometry.y += child.spacing;
|
||||
geometry.height -= child.spacing;
|
||||
}
|
||||
|
||||
if(child.widget) {
|
||||
child.widget->setGeometry({ geometry.x, geometry.y, child.width, child.height });
|
||||
geometry.y += child.height + child.spacing;
|
||||
geometry.height -= child.height + child.spacing;
|
||||
}
|
||||
}
|
||||
|
||||
geometry.x += maxWidth;
|
||||
geometry.width -= maxWidth;
|
||||
}
|
||||
|
||||
void VerticalLayout::setMargin(unsigned margin_) {
|
||||
margin = margin_;
|
||||
}
|
||||
|
||||
unsigned VerticalLayout::minimumHeight() {
|
||||
unsigned height = margin * 2;
|
||||
foreach(child, children) height += child.height + child.spacing;
|
||||
return height;
|
||||
}
|
||||
|
||||
void VerticalLayout::setVisible(bool visible) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setVisible(visible);
|
||||
if(child.widget) child.widget->setVisible(visible);
|
||||
}
|
||||
}
|
||||
|
||||
VerticalLayout::VerticalLayout() {
|
||||
margin = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
struct HorizontalLayout;
|
||||
|
||||
struct VerticalLayout : public Layout {
|
||||
void append(HorizontalLayout &layout, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
unsigned minimumHeight();
|
||||
void setGeometry(Geometry &geometry);
|
||||
void setMargin(unsigned margin);
|
||||
void setParent(Window &parent);
|
||||
void setVisible(bool visible);
|
||||
VerticalLayout();
|
||||
|
||||
//private:
|
||||
unsigned margin;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
struct Children {
|
||||
HorizontalLayout *layout;
|
||||
Widget *widget;
|
||||
unsigned width, height, spacing;
|
||||
};
|
||||
nall::linear_vector<Children> children;
|
||||
};
|
|
@ -0,0 +1,224 @@
|
|||
struct Font::State {
|
||||
bool bold;
|
||||
string family;
|
||||
bool italic;
|
||||
unsigned size;
|
||||
bool underline;
|
||||
|
||||
State() {
|
||||
bold = false;
|
||||
italic = false;
|
||||
size = 8;
|
||||
underline = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct Window::State {
|
||||
bool backgroundColor;
|
||||
unsigned backgroundColorRed, backgroundColorGreen, backgroundColorBlue;
|
||||
bool fullScreen;
|
||||
Geometry geometry;
|
||||
reference_array<Layout&> layout;
|
||||
reference_array<Menu&> menu;
|
||||
Font *menuFont;
|
||||
bool menuVisible;
|
||||
bool resizable;
|
||||
Font *statusFont;
|
||||
string statusText;
|
||||
bool statusVisible;
|
||||
string title;
|
||||
bool visible;
|
||||
reference_array<Widget&> widget;
|
||||
Font *widgetFont;
|
||||
|
||||
State() {
|
||||
backgroundColor = false;
|
||||
backgroundColorRed = 0;
|
||||
backgroundColorGreen = 0;
|
||||
backgroundColorBlue = 0;
|
||||
fullScreen = false;
|
||||
geometry = { 128, 128, 256, 256 };
|
||||
menuFont = 0;
|
||||
menuVisible = false;
|
||||
resizable = true;
|
||||
statusVisible = false;
|
||||
visible = false;
|
||||
widgetFont = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct Action::State {
|
||||
bool enabled;
|
||||
Window *parent;
|
||||
bool visible;
|
||||
|
||||
State() {
|
||||
enabled = true;
|
||||
parent = 0;
|
||||
visible = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Menu::State {
|
||||
reference_array<Action&> action;
|
||||
string text;
|
||||
};
|
||||
|
||||
struct Item::State {
|
||||
string text;
|
||||
};
|
||||
|
||||
struct CheckItem::State {
|
||||
bool checked;
|
||||
string text;
|
||||
|
||||
State() {
|
||||
checked = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct RadioItem::State {
|
||||
bool checked;
|
||||
reference_array<RadioItem&> group;
|
||||
string text;
|
||||
|
||||
State() {
|
||||
checked = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Widget::State {
|
||||
bool abstract;
|
||||
bool enabled;
|
||||
Font *font;
|
||||
Geometry geometry;
|
||||
bool visible;
|
||||
|
||||
State() {
|
||||
abstract = false;
|
||||
enabled = true;
|
||||
font = 0;
|
||||
geometry = { 0, 0, 0, 0 };
|
||||
visible = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct Button::State {
|
||||
string text;
|
||||
|
||||
State() {
|
||||
}
|
||||
};
|
||||
|
||||
struct CheckBox::State {
|
||||
bool checked;
|
||||
string text;
|
||||
|
||||
State() {
|
||||
checked = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct ComboBox::State {
|
||||
unsigned selection;
|
||||
linear_vector<string> text;
|
||||
|
||||
State() {
|
||||
selection = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct HexEdit::State {
|
||||
unsigned columns;
|
||||
unsigned length;
|
||||
unsigned offset;
|
||||
unsigned rows;
|
||||
|
||||
State() {
|
||||
columns = 16;
|
||||
length = 0;
|
||||
offset = 0;
|
||||
rows = 16;
|
||||
}
|
||||
};
|
||||
|
||||
struct HorizontalSlider::State {
|
||||
unsigned length;
|
||||
unsigned position;
|
||||
|
||||
State() {
|
||||
length = 101;
|
||||
position = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct Label::State {
|
||||
string text;
|
||||
};
|
||||
|
||||
struct LineEdit::State {
|
||||
bool editable;
|
||||
string text;
|
||||
|
||||
State() {
|
||||
editable = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct ListView::State {
|
||||
bool checkable;
|
||||
array<bool> checked;
|
||||
lstring headerText;
|
||||
bool headerVisible;
|
||||
bool selected;
|
||||
unsigned selection;
|
||||
linear_vector<lstring> text;
|
||||
|
||||
State() {
|
||||
checkable = false;
|
||||
headerVisible = false;
|
||||
selected = false;
|
||||
selection = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct ProgressBar::State {
|
||||
unsigned position;
|
||||
|
||||
State() {
|
||||
position = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct RadioBox::State {
|
||||
bool checked;
|
||||
reference_array<RadioBox&> group;
|
||||
string text;
|
||||
|
||||
State() {
|
||||
checked = true;
|
||||
}
|
||||
};
|
||||
|
||||
struct TextEdit::State {
|
||||
unsigned cursorPosition;
|
||||
bool editable;
|
||||
string text;
|
||||
bool wordWrap;
|
||||
|
||||
State() {
|
||||
cursorPosition = 0;
|
||||
editable = true;
|
||||
wordWrap = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct VerticalSlider::State {
|
||||
unsigned length;
|
||||
unsigned position;
|
||||
|
||||
State() {
|
||||
length = 101;
|
||||
position = 0;
|
||||
}
|
||||
};
|
|
@ -0,0 +1,22 @@
|
|||
static void Action_setFont(GtkWidget *widget, gpointer font) {
|
||||
if(font == 0) return;
|
||||
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
|
||||
if(GTK_IS_CONTAINER(widget)) {
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Action_setFont, (PangoFontDescription*)font);
|
||||
}
|
||||
}
|
||||
|
||||
void pAction::setEnabled(bool enabled) {
|
||||
gtk_widget_set_sensitive(widget, enabled);
|
||||
}
|
||||
|
||||
void pAction::setFont(Font &font) {
|
||||
Action_setFont(widget, font.p.gtkFont);
|
||||
}
|
||||
|
||||
void pAction::setVisible(bool visible) {
|
||||
gtk_widget_set_visible(widget, visible);
|
||||
}
|
||||
|
||||
void pAction::constructor() {
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
static void CheckItem_tick(CheckItem *self) {
|
||||
if(self->p.locked == false && self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
bool pCheckItem::checked() {
|
||||
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
|
||||
}
|
||||
|
||||
void pCheckItem::setChecked(bool checked) {
|
||||
locked = true;
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), checked);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pCheckItem::setText(const string &text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
|
||||
}
|
||||
|
||||
void pCheckItem::constructor() {
|
||||
widget = gtk_check_menu_item_new_with_label("");
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(CheckItem_tick), (gpointer)&checkItem);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
static void Item_tick(Item *self) {
|
||||
if(self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
void pItem::setText(const string &text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
|
||||
}
|
||||
|
||||
void pItem::constructor() {
|
||||
widget = gtk_menu_item_new_with_label("");
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "activate", G_CALLBACK(Item_tick), (gpointer)&item);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
void pMenu::append(Action &action) {
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), action.p.widget);
|
||||
gtk_widget_show(action.p.widget);
|
||||
}
|
||||
|
||||
void pMenu::setFont(Font &font) {
|
||||
pAction::setFont(font);
|
||||
foreach(item, menu.state.action) item.p.setFont(font);
|
||||
}
|
||||
|
||||
void pMenu::setText(const string &text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
|
||||
}
|
||||
|
||||
void pMenu::constructor() {
|
||||
submenu = gtk_menu_new();
|
||||
widget = gtk_menu_item_new_with_label("");
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), submenu);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
static void RadioItem_tick(RadioItem *self) {
|
||||
if(self->p.locked == false && self->checked() && self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
bool pRadioItem::checked() {
|
||||
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget));
|
||||
}
|
||||
|
||||
void pRadioItem::setChecked() {
|
||||
locked = true;
|
||||
foreach(item, radioItem.state.group) gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item.p.widget), false);
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(widget), true);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pRadioItem::setGroup(const reference_array<RadioItem&> &group) {
|
||||
foreach(item, group, n) {
|
||||
if(n == 0) continue;
|
||||
GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget));
|
||||
if(currentGroup != gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item.p.widget))) {
|
||||
gtk_radio_menu_item_set_group(GTK_RADIO_MENU_ITEM(item.p.widget), currentGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pRadioItem::setText(const string &text) {
|
||||
gtk_menu_item_set_label(GTK_MENU_ITEM(widget), text);
|
||||
}
|
||||
|
||||
void pRadioItem::constructor() {
|
||||
widget = gtk_radio_menu_item_new_with_label(0, "");
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "toggled", G_CALLBACK(RadioItem_tick), (gpointer)&radioItem);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
void pSeparator::constructor() {
|
||||
widget = gtk_separator_menu_item_new();
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
static void Button_tick(Button *self) {
|
||||
if(self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
void Button::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_button_new_with_label(text);
|
||||
widget->parent = &parent;
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "clicked", G_CALLBACK(Button_tick), (gpointer)this);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
static void Canvas_expose(Canvas *self) {
|
||||
uint32_t *rgb = self->canvas->bufferRGB;
|
||||
uint32_t *bgr = self->canvas->bufferBGR;
|
||||
for(unsigned y = self->object->widget->allocation.height; y; y--) {
|
||||
for(unsigned x = self->object->widget->allocation.width; x; x--) {
|
||||
uint32_t pixel = *rgb++;
|
||||
*bgr++ = ((pixel << 16) & 0xff0000) | (pixel & 0x00ff00) | ((pixel >> 16) & 0x0000ff);
|
||||
}
|
||||
}
|
||||
|
||||
gdk_draw_rgb_32_image(
|
||||
self->object->widget->window,
|
||||
self->object->widget->style->fg_gc[GTK_WIDGET_STATE(self->object->widget)],
|
||||
0, 0, self->object->widget->allocation.width, self->object->widget->allocation.height,
|
||||
GDK_RGB_DITHER_NONE, (guchar*)self->canvas->bufferBGR, self->canvas->pitch
|
||||
);
|
||||
}
|
||||
|
||||
void Canvas::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
canvas->bufferRGB = new uint32_t[width * height]();
|
||||
canvas->bufferBGR = new uint32_t[width * height]();
|
||||
canvas->pitch = width * sizeof(uint32_t);
|
||||
|
||||
object->widget = gtk_drawing_area_new();
|
||||
widget->parent = &parent;
|
||||
GdkColor color;
|
||||
color.pixel = color.red = color.green = color.blue = 0;
|
||||
gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color);
|
||||
gtk_widget_set_double_buffered(object->widget, false);
|
||||
gtk_widget_add_events(object->widget, GDK_EXPOSURE_MASK);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "expose_event", G_CALLBACK(Canvas_expose), (gpointer)this);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
uint32_t* Canvas::buffer() {
|
||||
return canvas->bufferRGB;
|
||||
}
|
||||
|
||||
void Canvas::redraw() {
|
||||
GdkRectangle rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.width = object->widget->allocation.width;
|
||||
rect.height = object->widget->allocation.height;
|
||||
gdk_window_invalidate_rect(object->widget->window, &rect, true);
|
||||
}
|
||||
|
||||
Canvas::Canvas() {
|
||||
canvas = new Canvas::Data;
|
||||
canvas->bufferRGB = 0;
|
||||
canvas->bufferBGR = 0;
|
||||
}
|
||||
|
||||
Canvas::~Canvas() {
|
||||
if(canvas->bufferRGB) delete[] canvas->bufferRGB;
|
||||
if(canvas->bufferBGR) delete[] canvas->bufferBGR;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
static void CheckBox_tick(CheckBox *self) {
|
||||
if(self->onTick && self->object->locked == false) self->onTick();
|
||||
}
|
||||
|
||||
void CheckBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_check_button_new_with_label(text);
|
||||
widget->parent = &parent;
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(CheckBox_tick), (gpointer)this);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
bool CheckBox::checked() {
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object->widget));
|
||||
}
|
||||
|
||||
void CheckBox::setChecked(bool checked) {
|
||||
object->locked = true;
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object->widget), checked);
|
||||
object->locked = false;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
void ComboBox_change(ComboBox *self) {
|
||||
if(self->object->locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void ComboBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_combo_box_new_text();
|
||||
widget->parent = &parent;
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(ComboBox_change), (gpointer)this);
|
||||
|
||||
if(*text) {
|
||||
lstring list;
|
||||
list.split("\n", text);
|
||||
foreach(item, list) addItem(item);
|
||||
}
|
||||
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void ComboBox::reset() {
|
||||
object->locked = true;
|
||||
for(signed i = counter - 1; i >= 0; i--) {
|
||||
gtk_combo_box_remove_text(GTK_COMBO_BOX(object->widget), i);
|
||||
}
|
||||
object->locked = false;
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
void ComboBox::addItem(const string &text) {
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(object->widget), text);
|
||||
if(counter++ == 0) setSelection(0);
|
||||
}
|
||||
|
||||
unsigned ComboBox::selection() {
|
||||
return gtk_combo_box_get_active(GTK_COMBO_BOX(object->widget));
|
||||
}
|
||||
|
||||
void ComboBox::setSelection(unsigned item) {
|
||||
object->locked = true;
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(object->widget), item);
|
||||
object->locked = false;
|
||||
}
|
||||
|
||||
ComboBox::ComboBox() {
|
||||
counter = 0;
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
static void EditBox_change(EditBox *self) {
|
||||
if(self->object->locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void EditBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_scrolled_window_new(0, 0);
|
||||
widget->parent = &parent;
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
object->subWidget = gtk_text_view_new();
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(object->subWidget), GTK_WRAP_WORD_CHAR);
|
||||
gtk_container_add(GTK_CONTAINER(object->widget), object->subWidget);
|
||||
object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(object->subWidget));
|
||||
gtk_text_buffer_set_text(object->textBuffer, text, -1);
|
||||
g_signal_connect_swapped(G_OBJECT(object->textBuffer), "changed", G_CALLBACK(EditBox_change), (gpointer)this);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->subWidget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void EditBox::setFocused() {
|
||||
gtk_widget_grab_focus(object->subWidget);
|
||||
}
|
||||
|
||||
void EditBox::setEditable(bool editable) {
|
||||
gtk_text_view_set_editable(GTK_TEXT_VIEW(object->subWidget), editable);
|
||||
}
|
||||
|
||||
void EditBox::setWordWrap(bool wordWrap) {
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(object->subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE);
|
||||
}
|
||||
|
||||
string EditBox::text() {
|
||||
GtkTextIter start, end;
|
||||
gtk_text_buffer_get_start_iter(object->textBuffer, &start);
|
||||
gtk_text_buffer_get_end_iter(object->textBuffer, &end);
|
||||
char *temp = gtk_text_buffer_get_text(object->textBuffer, &start, &end, true);
|
||||
string text = temp;
|
||||
g_free(temp);
|
||||
return text;
|
||||
}
|
||||
|
||||
void EditBox::setText(const string &text) {
|
||||
object->locked = true;
|
||||
gtk_text_buffer_set_text(object->textBuffer, text, -1);
|
||||
object->locked = false;
|
||||
}
|
|
@ -1,18 +1,22 @@
|
|||
bool Font::create(const string &name, unsigned size, Font::Style style) {
|
||||
font->font = pango_font_description_new();
|
||||
pango_font_description_set_family(font->font, name);
|
||||
pango_font_description_set_size(font->font, size * PANGO_SCALE);
|
||||
pango_font_description_set_style(font->font, (style & Style::Italic) == Style::Italic ? PANGO_STYLE_OBLIQUE : PANGO_STYLE_NORMAL);
|
||||
pango_font_description_set_weight(font->font, (style & Style::Bold) == Style::Bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
|
||||
return true;
|
||||
void pFont::setBold(bool bold) {
|
||||
pango_font_description_set_weight(gtkFont, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
|
||||
}
|
||||
|
||||
Font::Font() {
|
||||
font = new Font::Data;
|
||||
font->font = 0;
|
||||
void pFont::setFamily(const string &family) {
|
||||
pango_font_description_set_family(gtkFont, family);
|
||||
}
|
||||
|
||||
Font::~Font() {
|
||||
if(font->font) pango_font_description_free(font->font);
|
||||
delete font;
|
||||
void pFont::setItalic(bool italic) {
|
||||
pango_font_description_set_style(gtkFont, italic ? PANGO_STYLE_OBLIQUE : PANGO_STYLE_NORMAL);
|
||||
}
|
||||
|
||||
void pFont::setSize(unsigned size) {
|
||||
pango_font_description_set_size(gtkFont, size * PANGO_SCALE);
|
||||
}
|
||||
|
||||
void pFont::setUnderline(bool underline) {
|
||||
}
|
||||
|
||||
void pFont::constructor() {
|
||||
gtkFont = pango_font_description_new();
|
||||
}
|
||||
|
|
|
@ -1,48 +1,136 @@
|
|||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "gtk.hpp"
|
||||
|
||||
#define None X11None
|
||||
#define Window X11Window
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
#include <cairo.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#undef None
|
||||
#undef Window
|
||||
|
||||
using namespace nall;
|
||||
|
||||
namespace phoenix {
|
||||
|
||||
#include "object.cpp"
|
||||
#include "settings.cpp"
|
||||
#include "font.cpp"
|
||||
#include "menu.cpp"
|
||||
#include "widget.cpp"
|
||||
#include "message-window.cpp"
|
||||
#include "window.cpp"
|
||||
#include "button.cpp"
|
||||
#include "canvas.cpp"
|
||||
#include "checkbox.cpp"
|
||||
#include "combobox.cpp"
|
||||
#include "editbox.cpp"
|
||||
#include "horizontalslider.cpp"
|
||||
#include "label.cpp"
|
||||
#include "listbox.cpp"
|
||||
#include "progressbar.cpp"
|
||||
#include "radiobox.cpp"
|
||||
#include "textbox.cpp"
|
||||
#include "verticalslider.cpp"
|
||||
#include "viewport.cpp"
|
||||
#include "messagewindow.cpp"
|
||||
|
||||
Window Window::None;
|
||||
#include "action/action.cpp"
|
||||
#include "action/menu.cpp"
|
||||
#include "action/separator.cpp"
|
||||
#include "action/item.cpp"
|
||||
#include "action/check-item.cpp"
|
||||
#include "action/radio-item.cpp"
|
||||
|
||||
void OS::initialize() {
|
||||
static bool initialized = false;
|
||||
if(initialized == true) return;
|
||||
initialized = true;
|
||||
#include "widget/widget.cpp"
|
||||
#include "widget/button.cpp"
|
||||
#include "widget/check-box.cpp"
|
||||
#include "widget/combo-box.cpp"
|
||||
#include "widget/hex-edit.cpp"
|
||||
#include "widget/horizontal-slider.cpp"
|
||||
#include "widget/label.cpp"
|
||||
#include "widget/line-edit.cpp"
|
||||
#include "widget/list-view.cpp"
|
||||
#include "widget/progress-bar.cpp"
|
||||
#include "widget/radio-box.cpp"
|
||||
#include "widget/text-edit.cpp"
|
||||
#include "widget/vertical-slider.cpp"
|
||||
#include "widget/viewport.cpp"
|
||||
|
||||
Geometry pOS::availableGeometry() {
|
||||
//TODO: is there a GTK+ function for this?
|
||||
//should return desktopGeometry() sans panels, toolbars, docks, etc.
|
||||
Geometry geometry = desktopGeometry();
|
||||
return { geometry.x + 64, geometry.y + 64, geometry.width - 128, geometry.height - 128 };
|
||||
}
|
||||
|
||||
Geometry pOS::desktopGeometry() {
|
||||
return {
|
||||
0, 0,
|
||||
gdk_screen_get_width(gdk_screen_get_default()),
|
||||
gdk_screen_get_height(gdk_screen_get_default())
|
||||
};
|
||||
}
|
||||
|
||||
static string pOS_fileDialog(bool save, Window &parent, const string &path, const lstring &filter) {
|
||||
string name;
|
||||
|
||||
GtkWidget *dialog = gtk_file_chooser_dialog_new(
|
||||
save == 0 ? "Load File" : "Save File",
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
save == 0 ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
(const gchar*)0
|
||||
);
|
||||
|
||||
if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
|
||||
|
||||
foreach(filterItem, filter) {
|
||||
GtkFileFilter *gtkFilter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(gtkFilter, filterItem);
|
||||
lstring part;
|
||||
part.split("(", filterItem);
|
||||
part[1].rtrim<1>(")");
|
||||
lstring list;
|
||||
list.split(",", part[1]);
|
||||
foreach(pattern, list) gtk_file_filter_add_pattern(gtkFilter, pattern);
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), gtkFilter);
|
||||
}
|
||||
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
name = temp;
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
return name;
|
||||
}
|
||||
|
||||
string pOS::fileLoad(Window &parent, const string &path, const lstring &filter) {
|
||||
return pOS_fileDialog(0, parent, path, filter);
|
||||
}
|
||||
|
||||
string pOS::fileSave(Window &parent, const string &path, const lstring &filter) {
|
||||
return pOS_fileDialog(1, parent, path, filter);
|
||||
}
|
||||
|
||||
string pOS::folderSelect(Window &parent, const string &path) {
|
||||
string name;
|
||||
|
||||
GtkWidget *dialog = gtk_file_chooser_dialog_new(
|
||||
"Select Folder",
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
(const gchar*)0
|
||||
);
|
||||
|
||||
if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
|
||||
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
name = temp;
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
if(name == "") return "";
|
||||
if(name.endswith("/") == false) name.append("/");
|
||||
return name;
|
||||
}
|
||||
|
||||
void pOS::main() {
|
||||
gtk_main();
|
||||
}
|
||||
|
||||
bool pOS::pendingEvents() {
|
||||
return gtk_events_pending();
|
||||
}
|
||||
|
||||
void pOS::processEvents() {
|
||||
while(pendingEvents()) gtk_main_iteration_do(false);
|
||||
}
|
||||
|
||||
void pOS::quit() {
|
||||
settings.save();
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
void pOS::initialize() {
|
||||
settings.load();
|
||||
|
||||
int argc = 1;
|
||||
char *argv[2];
|
||||
|
@ -62,128 +150,3 @@ void OS::initialize() {
|
|||
"class \"GtkTreeView\" style \"phoenix-gtk\"\n"
|
||||
);
|
||||
}
|
||||
|
||||
bool OS::pending() {
|
||||
return gtk_events_pending();
|
||||
}
|
||||
|
||||
void OS::run() {
|
||||
while(pending()) gtk_main_iteration_do(false);
|
||||
}
|
||||
|
||||
void OS::main() {
|
||||
gtk_main();
|
||||
}
|
||||
|
||||
void OS::quit() {
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
unsigned OS::desktopWidth() {
|
||||
return gdk_screen_get_width(gdk_screen_get_default());
|
||||
}
|
||||
|
||||
unsigned OS::desktopHeight() {
|
||||
return gdk_screen_get_height(gdk_screen_get_default());
|
||||
}
|
||||
|
||||
string OS::folderSelect(Window &parent, const string &path) {
|
||||
string name;
|
||||
|
||||
GtkWidget *dialog = gtk_file_chooser_dialog_new(
|
||||
"Select Folder",
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
(const gchar*)0
|
||||
);
|
||||
|
||||
if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
|
||||
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
name = temp;
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
if(name.endswith("/") == false) name.append("/");
|
||||
return name;
|
||||
}
|
||||
|
||||
string OS::fileOpen(Window &parent, const string &filter, const string &path) {
|
||||
string name;
|
||||
|
||||
GtkWidget *dialog = gtk_file_chooser_dialog_new(
|
||||
"Open File",
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
(const gchar*)0
|
||||
);
|
||||
|
||||
if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
|
||||
|
||||
lstring list;
|
||||
list.split("\n", filter);
|
||||
foreach(item, list) {
|
||||
lstring part;
|
||||
part.split("\t", item);
|
||||
GtkFileFilter *filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter, string(part[0], " (", part[1], ")"));
|
||||
lstring patterns;
|
||||
patterns.split(",", part[1]);
|
||||
foreach(pattern, patterns) gtk_file_filter_add_pattern(filter, pattern);
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||
}
|
||||
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
name = temp;
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
return name;
|
||||
}
|
||||
|
||||
string OS::fileSave(Window &parent, const string &filter, const string &path) {
|
||||
string name;
|
||||
|
||||
GtkWidget *dialog = gtk_file_chooser_dialog_new(
|
||||
"Save File",
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
|
||||
(const gchar*)0
|
||||
);
|
||||
|
||||
if(path) gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path);
|
||||
|
||||
lstring list;
|
||||
list.split("\n", filter);
|
||||
foreach(item, list) {
|
||||
lstring part;
|
||||
part.split("\t", item);
|
||||
GtkFileFilter *filter = gtk_file_filter_new();
|
||||
gtk_file_filter_set_name(filter, string(part[0], " (", part[1], ")"));
|
||||
lstring patterns;
|
||||
patterns.split(",", part[1]);
|
||||
foreach(pattern, patterns) gtk_file_filter_add_pattern(filter, pattern);
|
||||
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
|
||||
}
|
||||
|
||||
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||
char *temp = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||
name = temp;
|
||||
g_free(temp);
|
||||
}
|
||||
|
||||
gtk_widget_destroy(dialog);
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,265 +1,351 @@
|
|||
namespace phoenix {
|
||||
struct Settings : public configuration {
|
||||
unsigned frameGeometryX;
|
||||
unsigned frameGeometryY;
|
||||
unsigned frameGeometryWidth;
|
||||
unsigned frameGeometryHeight;
|
||||
unsigned menuGeometryHeight;
|
||||
unsigned statusGeometryHeight;
|
||||
|
||||
struct Window;
|
||||
|
||||
struct Object {
|
||||
Object();
|
||||
Object& operator=(const Object&) = delete;
|
||||
Object(const Object&) = delete;
|
||||
//private:
|
||||
virtual void unused();
|
||||
struct Data;
|
||||
Data *object;
|
||||
void load();
|
||||
void save();
|
||||
Settings();
|
||||
};
|
||||
|
||||
struct Geometry {
|
||||
unsigned x, y;
|
||||
unsigned width, height;
|
||||
inline Geometry() : x(0), y(0), width(0), height(0) {}
|
||||
inline Geometry(unsigned x, unsigned y, unsigned width, unsigned height) : x(x), y(y), width(width), height(height) {}
|
||||
struct pFont;
|
||||
struct pWindow;
|
||||
struct pMenu;
|
||||
struct pLayout;
|
||||
struct pWidget;
|
||||
|
||||
struct pObject {
|
||||
bool locked;
|
||||
|
||||
pObject() {
|
||||
locked = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct Font : Object {
|
||||
enum class Style : unsigned {
|
||||
None = 0,
|
||||
Bold = 1,
|
||||
Italic = 2,
|
||||
};
|
||||
bool create(const nall::string &name, unsigned size, Font::Style style = Style::None);
|
||||
Font();
|
||||
~Font();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *font;
|
||||
};
|
||||
|
||||
inline Font::Style operator|(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a | (unsigned)b); }
|
||||
inline Font::Style operator&(Font::Style a, Font::Style b) { return (Font::Style)((unsigned)a & (unsigned)b); }
|
||||
|
||||
struct Action : Object {
|
||||
bool visible();
|
||||
void setVisible(bool visible = true);
|
||||
bool enabled();
|
||||
void setEnabled(bool enabled = true);
|
||||
Action();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *action;
|
||||
};
|
||||
|
||||
struct Menu : Action {
|
||||
void create(Window &parent, const nall::string &text);
|
||||
void create(Menu &parent, const nall::string &text);
|
||||
};
|
||||
|
||||
struct MenuSeparator : Action {
|
||||
void create(Menu &parent);
|
||||
};
|
||||
|
||||
struct MenuItem : Action {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Menu &parent, const nall::string &text);
|
||||
};
|
||||
|
||||
struct MenuCheckItem : Action {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Menu &parent, const nall::string &text);
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
};
|
||||
|
||||
struct MenuRadioItem : Action {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Menu &parent, const nall::string &text);
|
||||
void create(MenuRadioItem &parent, const nall::string &text);
|
||||
bool checked();
|
||||
void setChecked();
|
||||
private:
|
||||
MenuRadioItem *first;
|
||||
};
|
||||
|
||||
struct Widget : Object {
|
||||
virtual void setFont(Font &font);
|
||||
bool visible();
|
||||
void setVisible(bool visible = true);
|
||||
bool enabled();
|
||||
void setEnabled(bool enabled = true);
|
||||
virtual bool focused();
|
||||
virtual void setFocused();
|
||||
virtual void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
Widget();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *widget;
|
||||
};
|
||||
|
||||
struct Window : Widget {
|
||||
nall::function<bool ()> onClose;
|
||||
void create(unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
bool focused();
|
||||
void setFocused();
|
||||
Geometry geometry();
|
||||
void setGeometry(unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
void setDefaultFont(Font &font);
|
||||
void setFont(Font &font);
|
||||
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void setTitle(const nall::string &text);
|
||||
void setStatusText(const nall::string &text);
|
||||
void setMenuVisible(bool visible = true);
|
||||
void setStatusVisible(bool visible = true);
|
||||
Window();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *window;
|
||||
static Window None;
|
||||
};
|
||||
|
||||
struct Button : Widget {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
};
|
||||
|
||||
struct Canvas : Widget {
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
uint32_t* buffer();
|
||||
void redraw();
|
||||
Canvas();
|
||||
~Canvas();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *canvas;
|
||||
};
|
||||
|
||||
struct CheckBox : Widget {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
bool checked();
|
||||
void setChecked(bool checked = true);
|
||||
};
|
||||
|
||||
struct ComboBox : Widget {
|
||||
nall::function<void ()> onChange;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void reset();
|
||||
void addItem(const nall::string &text);
|
||||
unsigned selection();
|
||||
void setSelection(unsigned item);
|
||||
ComboBox();
|
||||
private:
|
||||
unsigned counter;
|
||||
};
|
||||
|
||||
struct EditBox : Widget {
|
||||
nall::function<void ()> onChange;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void setFocused();
|
||||
void setEditable(bool editable = true);
|
||||
void setWordWrap(bool wordWrap = true);
|
||||
nall::string text();
|
||||
void setText(const nall::string &text);
|
||||
};
|
||||
|
||||
struct HorizontalSlider : Widget {
|
||||
nall::function<void ()> onChange;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length);
|
||||
unsigned position();
|
||||
void setPosition(unsigned position);
|
||||
};
|
||||
|
||||
struct Label : Widget {
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void setText(const nall::string &text);
|
||||
};
|
||||
|
||||
struct ListBox : Widget {
|
||||
nall::function<void ()> onActivate;
|
||||
nall::function<void ()> onChange;
|
||||
nall::function<void (unsigned)> onTick;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void setFocused();
|
||||
void setHeaderVisible(bool headerVisible = true);
|
||||
void setCheckable(bool checkable = true);
|
||||
void setFont(Font &font);
|
||||
void reset();
|
||||
void resizeColumnsToContent();
|
||||
void addItem(const nall::string &text);
|
||||
void setItem(unsigned row, const nall::string &text);
|
||||
bool checked(unsigned row);
|
||||
void setChecked(unsigned row, bool checked = true);
|
||||
nall::optional<unsigned> selection();
|
||||
void setSelection(unsigned row);
|
||||
ListBox();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *listBox;
|
||||
};
|
||||
|
||||
struct ProgressBar : Widget {
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
void setPosition(unsigned position);
|
||||
};
|
||||
|
||||
struct RadioBox : Widget {
|
||||
nall::function<void ()> onTick;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void create(RadioBox &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
bool checked();
|
||||
void setChecked();
|
||||
private:
|
||||
RadioBox *first;
|
||||
};
|
||||
|
||||
struct TextBox : Widget {
|
||||
nall::function<void ()> onActivate;
|
||||
nall::function<void ()> onChange;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const nall::string &text = "");
|
||||
void setEditable(bool editable = true);
|
||||
nall::string text();
|
||||
void setText(const nall::string &text);
|
||||
};
|
||||
|
||||
struct VerticalSlider : Widget {
|
||||
nall::function<void ()> onChange;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length);
|
||||
unsigned position();
|
||||
void setPosition(unsigned position);
|
||||
};
|
||||
|
||||
struct Viewport : Widget {
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
uintptr_t handle();
|
||||
};
|
||||
|
||||
struct MessageWindow : Object {
|
||||
enum class Buttons : unsigned {
|
||||
Ok,
|
||||
OkCancel,
|
||||
YesNo,
|
||||
};
|
||||
enum class Response : unsigned {
|
||||
Ok,
|
||||
Cancel,
|
||||
Yes,
|
||||
No,
|
||||
};
|
||||
static Response information(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
static Response question(Window &parent, const nall::string &text, Buttons = Buttons::YesNo);
|
||||
static Response warning(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
static Response critical(Window &parent, const nall::string &text, Buttons = Buttons::Ok);
|
||||
};
|
||||
|
||||
struct OS : Object {
|
||||
static bool pending();
|
||||
static void run();
|
||||
struct pOS : public pObject {
|
||||
static Geometry availableGeometry();
|
||||
static Geometry desktopGeometry();
|
||||
static string fileLoad(Window &parent, const string &path, const lstring &filter);
|
||||
static string fileSave(Window &parent, const string &path, const lstring &filter);
|
||||
static string folderSelect(Window &parent, const string &path);
|
||||
static void main();
|
||||
static bool pendingEvents();
|
||||
static void processEvents();
|
||||
static void quit();
|
||||
static unsigned desktopWidth();
|
||||
static unsigned desktopHeight();
|
||||
static nall::string folderSelect(Window &parent, const nall::string &path = "");
|
||||
static nall::string fileOpen(Window &parent, const nall::string &filter, const nall::string &path = "");
|
||||
static nall::string fileSave(Window &parent, const nall::string &filter, const nall::string &path = "");
|
||||
//private:
|
||||
|
||||
static void initialize();
|
||||
};
|
||||
|
||||
}
|
||||
struct pFont : public pObject {
|
||||
Font &font;
|
||||
PangoFontDescription *gtkFont;
|
||||
|
||||
void setBold(bool bold);
|
||||
void setFamily(const string &family);
|
||||
void setItalic(bool italic);
|
||||
void setSize(unsigned size);
|
||||
void setUnderline(bool underline);
|
||||
|
||||
pFont(Font &font) : font(font) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pMessageWindow : public pObject {
|
||||
static MessageWindow::Response information(Window &parent, const string &text, MessageWindow::Buttons buttons);
|
||||
static MessageWindow::Response question(Window &parent, const string &text, MessageWindow::Buttons buttons);
|
||||
static MessageWindow::Response warning(Window &parent, const string &text, MessageWindow::Buttons buttons);
|
||||
static MessageWindow::Response critical(Window &parent, const string &text, MessageWindow::Buttons buttons);
|
||||
};
|
||||
|
||||
struct pWindow : public pObject {
|
||||
Window &window;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *menuContainer;
|
||||
GtkWidget *formContainer;
|
||||
GtkWidget *statusContainer;
|
||||
GtkWidget *menu;
|
||||
GtkWidget *status;
|
||||
|
||||
void append(Layout &layout);
|
||||
void append(Menu &menu);
|
||||
void append(Widget &widget);
|
||||
bool focused();
|
||||
Geometry frameMargin();
|
||||
Geometry geometry();
|
||||
void setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void setFocused();
|
||||
void setFullScreen(bool fullScreen);
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setMenuFont(Font &font);
|
||||
void setMenuVisible(bool visible);
|
||||
void setResizable(bool resizable);
|
||||
void setStatusFont(Font &font);
|
||||
void setStatusText(const string &text);
|
||||
void setStatusVisible(bool visible);
|
||||
void setTitle(const string &text);
|
||||
void setVisible(bool visible);
|
||||
void setWidgetFont(Font &font);
|
||||
|
||||
pWindow(Window &window) : window(window) {}
|
||||
void constructor();
|
||||
unsigned menuHeight();
|
||||
unsigned statusHeight();
|
||||
};
|
||||
|
||||
struct pAction : public pObject {
|
||||
Action &action;
|
||||
GtkWidget *widget;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
void setVisible(bool visible);
|
||||
|
||||
pAction(Action &action) : action(action) {}
|
||||
void constructor();
|
||||
virtual void setFont(Font &font);
|
||||
};
|
||||
|
||||
struct pMenu : public pAction {
|
||||
Menu &menu;
|
||||
GtkWidget *submenu;
|
||||
|
||||
void append(Action &action);
|
||||
void setText(const string &text);
|
||||
|
||||
pMenu(Menu &menu) : pAction(menu), menu(menu) {}
|
||||
void constructor();
|
||||
void setFont(Font &font);
|
||||
};
|
||||
|
||||
struct pSeparator : public pAction {
|
||||
Separator &separator;
|
||||
|
||||
pSeparator(Separator &separator) : pAction(separator), separator(separator) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pItem : public pAction {
|
||||
Item &item;
|
||||
|
||||
void setText(const string &text);
|
||||
|
||||
pItem(Item &item) : pAction(item), item(item) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pCheckItem : public pAction {
|
||||
CheckItem &checkItem;
|
||||
|
||||
bool checked();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string &text);
|
||||
|
||||
pCheckItem(CheckItem &checkItem) : pAction(checkItem), checkItem(checkItem) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pRadioItem : public pAction {
|
||||
RadioItem &radioItem;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setGroup(const reference_array<RadioItem&> &group);
|
||||
void setText(const string &text);
|
||||
|
||||
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pWidget : public pObject {
|
||||
Widget &widget;
|
||||
GtkWidget *gtkWidget;
|
||||
pWindow *parentWindow;
|
||||
|
||||
bool enabled();
|
||||
void setEnabled(bool enabled);
|
||||
virtual void setFocused();
|
||||
virtual void setFont(Font &font);
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setVisible(bool visible);
|
||||
|
||||
pWidget(Widget &widget) : widget(widget) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pButton : public pWidget {
|
||||
Button &button;
|
||||
|
||||
void setText(const string &text);
|
||||
|
||||
pButton(Button &button) : pWidget(button), button(button) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pCheckBox : public pWidget {
|
||||
CheckBox &checkBox;
|
||||
|
||||
bool checked();
|
||||
void setChecked(bool checked);
|
||||
void setText(const string &text);
|
||||
|
||||
pCheckBox(CheckBox &checkBox) : pWidget(checkBox), checkBox(checkBox) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pComboBox : public pWidget {
|
||||
ComboBox &comboBox;
|
||||
unsigned itemCounter;
|
||||
|
||||
void append(const string &text);
|
||||
void reset();
|
||||
unsigned selection();
|
||||
void setSelection(unsigned row);
|
||||
|
||||
pComboBox(ComboBox &comboBox) : pWidget(comboBox), comboBox(comboBox) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pHexEdit : public pWidget {
|
||||
HexEdit &hexEdit;
|
||||
GtkWidget *container;
|
||||
GtkWidget *subWidget;
|
||||
GtkWidget *scrollBar;
|
||||
GtkTextBuffer *textBuffer;
|
||||
GtkTextMark *textCursor;
|
||||
|
||||
void setColumns(unsigned columns);
|
||||
void setLength(unsigned length);
|
||||
void setOffset(unsigned offset);
|
||||
void setRows(unsigned rows);
|
||||
void update();
|
||||
|
||||
pHexEdit(HexEdit &hexEdit) : pWidget(hexEdit), hexEdit(hexEdit) {}
|
||||
void constructor();
|
||||
unsigned cursorPosition();
|
||||
bool keyPress(unsigned scancode);
|
||||
void scroll(unsigned position);
|
||||
void setCursorPosition(unsigned position);
|
||||
void setScroll();
|
||||
void updateScroll();
|
||||
};
|
||||
|
||||
struct pHorizontalSlider : public pWidget {
|
||||
HorizontalSlider &horizontalSlider;
|
||||
|
||||
unsigned position();
|
||||
void setLength(unsigned length);
|
||||
void setPosition(unsigned position);
|
||||
|
||||
pHorizontalSlider(HorizontalSlider &horizontalSlider) : pWidget(horizontalSlider), horizontalSlider(horizontalSlider) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pLabel : public pWidget {
|
||||
Label &label;
|
||||
|
||||
void setText(const string &text);
|
||||
|
||||
pLabel(Label &label) : pWidget(label), label(label) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pLineEdit : public pWidget {
|
||||
LineEdit &lineEdit;
|
||||
|
||||
void setEditable(bool editable);
|
||||
void setText(const string &text);
|
||||
string text();
|
||||
|
||||
pLineEdit(LineEdit &lineEdit) : pWidget(lineEdit), lineEdit(lineEdit) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pListView : public pWidget {
|
||||
ListView &listView;
|
||||
GtkWidget *subWidget;
|
||||
GtkListStore *store;
|
||||
struct GtkColumn {
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkWidget *label;
|
||||
};
|
||||
linear_vector<GtkColumn> column;
|
||||
|
||||
void append(const lstring &text);
|
||||
void autoSizeColumns();
|
||||
bool checked(unsigned row);
|
||||
void modify(unsigned row, const lstring &text);
|
||||
void reset();
|
||||
bool selected();
|
||||
unsigned selection();
|
||||
void setCheckable(bool checkable);
|
||||
void setChecked(unsigned row, bool checked);
|
||||
void setHeaderText(const lstring &text);
|
||||
void setHeaderVisible(bool visible);
|
||||
void setSelected(bool selected);
|
||||
void setSelection(unsigned row);
|
||||
|
||||
pListView(ListView &listView) : pWidget(listView), listView(listView) {}
|
||||
void constructor();
|
||||
void create();
|
||||
void setFocused();
|
||||
void setFont(Font &font);
|
||||
};
|
||||
|
||||
struct pProgressBar : public pWidget {
|
||||
ProgressBar &progressBar;
|
||||
|
||||
void setPosition(unsigned position);
|
||||
|
||||
pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pRadioBox : public pWidget {
|
||||
RadioBox &radioBox;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setGroup(const reference_array<RadioBox&> &group);
|
||||
void setText(const string &text);
|
||||
|
||||
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pTextEdit : public pWidget {
|
||||
TextEdit &textEdit;
|
||||
GtkWidget *subWidget;
|
||||
GtkTextBuffer *textBuffer;
|
||||
|
||||
void setCursorPosition(unsigned position);
|
||||
void setEditable(bool editable);
|
||||
void setText(const string &text);
|
||||
void setWordWrap(bool wordWrap);
|
||||
string text();
|
||||
|
||||
pTextEdit(TextEdit &textEdit) : pWidget(textEdit), textEdit(textEdit) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pVerticalSlider : public pWidget {
|
||||
VerticalSlider &verticalSlider;
|
||||
|
||||
unsigned position();
|
||||
void setLength(unsigned length);
|
||||
void setPosition(unsigned position);
|
||||
|
||||
pVerticalSlider(VerticalSlider &verticalSlider) : pWidget(verticalSlider), verticalSlider(verticalSlider) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pViewport : public pWidget {
|
||||
Viewport &viewport;
|
||||
|
||||
uintptr_t handle();
|
||||
|
||||
pViewport(Viewport &viewport) : pWidget(viewport), viewport(viewport) {}
|
||||
void constructor();
|
||||
};
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
static void HorizontalSlider_change(HorizontalSlider *self) {
|
||||
if(self->object->position == self->position()) return;
|
||||
self->object->position = self->position();
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void HorizontalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) {
|
||||
object->position = 0;
|
||||
length += (length == 0);
|
||||
object->widget = gtk_hscale_new_with_range(0, length - 1, 1);
|
||||
widget->parent = &parent;
|
||||
gtk_scale_set_draw_value(GTK_SCALE(object->widget), false);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)this);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
unsigned HorizontalSlider::position() {
|
||||
return (unsigned)gtk_range_get_value(GTK_RANGE(object->widget));
|
||||
}
|
||||
|
||||
void HorizontalSlider::setPosition(unsigned position) {
|
||||
gtk_range_set_value(GTK_RANGE(object->widget), position);
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
void Label::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_label_new(text);
|
||||
widget->parent = &parent;
|
||||
gtk_misc_set_alignment(GTK_MISC(object->widget), 0.0, 0.5);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void Label::setText(const string &text) {
|
||||
gtk_label_set_text(GTK_LABEL(object->widget), text);
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
static void ListBox_activate(ListBox *self) {
|
||||
signed selection = -1;
|
||||
if(auto position = self->selection()) selection = position();
|
||||
self->listBox->selection = selection;
|
||||
if(self->onActivate) self->onActivate();
|
||||
}
|
||||
|
||||
static void ListBox_change(ListBox *self) {
|
||||
signed selection = -1;
|
||||
if(auto position = self->selection()) selection = position();
|
||||
if(selection == self->listBox->selection) return;
|
||||
self->listBox->selection = selection;
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
static void ListBox_tick(GtkCellRendererToggle *cell, gchar *path_string, ListBox *self) {
|
||||
unsigned index = strunsigned(path_string);
|
||||
self->setChecked(index, !self->checked(index));
|
||||
if(self->onTick) self->onTick(index);
|
||||
}
|
||||
|
||||
void ListBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
listBox->selection = -1;
|
||||
object->widget = gtk_scrolled_window_new(0, 0);
|
||||
widget->parent = &parent;
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(object->widget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(object->widget), GTK_SHADOW_ETCHED_IN);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
|
||||
lstring list;
|
||||
list.split("\t", string("\t", text));
|
||||
|
||||
GType *v = (GType*)malloc(list.size() * sizeof(GType));
|
||||
for(unsigned i = 0; i < list.size(); i++) v[i] = (i == 0 ? G_TYPE_BOOLEAN : G_TYPE_STRING);
|
||||
listBox->store = gtk_list_store_newv(list.size(), v);
|
||||
free(v);
|
||||
|
||||
object->subWidget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(listBox->store));
|
||||
gtk_container_add(GTK_CONTAINER(object->widget), object->subWidget);
|
||||
g_object_unref(G_OBJECT(listBox->store));
|
||||
|
||||
for(unsigned i = 0; i < list.size(); i++) {
|
||||
if(i == 0) {
|
||||
listBox->column[i].renderer = gtk_cell_renderer_toggle_new();
|
||||
listBox->column[i].column = gtk_tree_view_column_new_with_attributes(
|
||||
"", listBox->column[i].renderer, "active", i, (void*)0
|
||||
);
|
||||
gtk_tree_view_column_set_resizable(listBox->column[i].column, false);
|
||||
gtk_tree_view_column_set_visible(listBox->column[i].column, listBox->checkable);
|
||||
g_signal_connect(listBox->column[i].renderer, "toggled", G_CALLBACK(ListBox_tick), (gpointer)this);
|
||||
} else {
|
||||
listBox->column[i].renderer = gtk_cell_renderer_text_new();
|
||||
listBox->column[i].column = gtk_tree_view_column_new_with_attributes(
|
||||
"", listBox->column[i].renderer, "text", i, (void*)0
|
||||
);
|
||||
gtk_tree_view_column_set_resizable(listBox->column[i].column, true);
|
||||
}
|
||||
listBox->column[i].label = gtk_label_new(list[i]);
|
||||
gtk_tree_view_column_set_widget(GTK_TREE_VIEW_COLUMN(listBox->column[i].column), listBox->column[i].label);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(object->subWidget), listBox->column[i].column);
|
||||
gtk_widget_show(listBox->column[i].label);
|
||||
}
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(object->subWidget), false);
|
||||
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(object->subWidget), list.size() >= 3); //>= 2 + one for the checkbox column
|
||||
gtk_tree_view_set_search_column(GTK_TREE_VIEW(object->subWidget), 1);
|
||||
|
||||
g_signal_connect_swapped(G_OBJECT(object->subWidget), "cursor-changed", G_CALLBACK(ListBox_change), (gpointer)this);
|
||||
g_signal_connect_swapped(G_OBJECT(object->subWidget), "row-activated", G_CALLBACK(ListBox_activate), (gpointer)this);
|
||||
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->subWidget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void ListBox::setFocused() {
|
||||
gtk_widget_grab_focus(object->subWidget);
|
||||
}
|
||||
|
||||
void ListBox::setHeaderVisible(bool visible) {
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(object->subWidget), visible);
|
||||
}
|
||||
|
||||
void ListBox::setCheckable(bool checkable) {
|
||||
listBox->checkable = checkable;
|
||||
if(object->subWidget) gtk_tree_view_column_set_visible(listBox->column[0].column, checkable);
|
||||
}
|
||||
|
||||
void ListBox::setFont(Font &font) {
|
||||
Widget::setFont(font);
|
||||
unsigned columns = 1;
|
||||
while(true) {
|
||||
if(gtk_tree_view_get_column(GTK_TREE_VIEW(object->subWidget), columns) == 0) break;
|
||||
columns++;
|
||||
}
|
||||
for(unsigned i = 0; i < columns; i++) {
|
||||
gtk_widget_modify_font(listBox->column[i].label, font.font->font);
|
||||
}
|
||||
}
|
||||
|
||||
void ListBox::reset() {
|
||||
listBox->selection = -1;
|
||||
gtk_list_store_clear(GTK_LIST_STORE(listBox->store));
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(object->subWidget), GTK_TREE_MODEL(listBox->store));
|
||||
//reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListBox is now empty
|
||||
gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(object->widget), 0);
|
||||
gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(object->widget), 0);
|
||||
}
|
||||
|
||||
void ListBox::resizeColumnsToContent() {
|
||||
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(object->subWidget));
|
||||
}
|
||||
|
||||
void ListBox::addItem(const string &text) {
|
||||
lstring list;
|
||||
list.split("\t", text);
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append(listBox->store, &iter);
|
||||
unsigned index = 1;
|
||||
foreach(item, list) gtk_list_store_set(listBox->store, &iter, index++, (const char*)item, -1);
|
||||
}
|
||||
|
||||
void ListBox::setItem(unsigned row, const string &text) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreeIter iter;
|
||||
for(unsigned i = 0; i <= row; i++) {
|
||||
if(i == 0) gtk_tree_model_get_iter_first(model, &iter);
|
||||
else gtk_tree_model_iter_next(model, &iter);
|
||||
}
|
||||
|
||||
lstring list;
|
||||
list.split("\t", text);
|
||||
unsigned index = 1;
|
||||
foreach(item, list) gtk_list_store_set(listBox->store, &iter, index++, (const char*)item, -1);
|
||||
}
|
||||
|
||||
bool ListBox::checked(unsigned row) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string(string(row));
|
||||
GtkTreeIter iter;
|
||||
bool state;
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &state, -1);
|
||||
gtk_tree_path_free(path);
|
||||
return state;
|
||||
}
|
||||
|
||||
void ListBox::setChecked(unsigned row, bool checked) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string(string(row));
|
||||
GtkTreeIter iter;
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, checked, -1);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
optional<unsigned> ListBox::selection() {
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreeIter iter;
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) return { false, 0 };
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, 0 };
|
||||
for(unsigned i = 1;; i++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) return { false, 0 };
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return { true, i };
|
||||
}
|
||||
return { false, 0 };
|
||||
}
|
||||
|
||||
void ListBox::setSelection(unsigned row) {
|
||||
signed current = -1;
|
||||
if(auto position = selection()) current = position();
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(object->subWidget));
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(object->subWidget));
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
|
||||
GtkTreeIter iter;
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) return;
|
||||
if(row == 0) {
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
return;
|
||||
}
|
||||
for(unsigned i = 1;; i++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) return;
|
||||
if(row == i) {
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListBox::ListBox() {
|
||||
listBox = new ListBox::Data;
|
||||
listBox->checkable = false;
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
static void Action_setFont(GtkWidget *widget, gpointer font) {
|
||||
if(font) {
|
||||
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
|
||||
if(GTK_IS_CONTAINER(widget)) {
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Action_setFont, (PangoFontDescription*)font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Action::visible() {
|
||||
return gtk_widget_get_visible(object->widget);
|
||||
}
|
||||
|
||||
void Action::setVisible(bool visible) {
|
||||
gtk_widget_set_visible(object->widget, visible);
|
||||
}
|
||||
|
||||
bool Action::enabled() {
|
||||
return gtk_widget_get_sensitive(object->widget);
|
||||
}
|
||||
|
||||
void Action::setEnabled(bool enabled) {
|
||||
gtk_widget_set_sensitive(object->widget, enabled);
|
||||
}
|
||||
|
||||
Action::Action() {
|
||||
action = new Action::Data;
|
||||
action->font = 0;
|
||||
}
|
||||
|
||||
void Menu::create(Window &parent, const string &text) {
|
||||
action->font = parent.window->defaultFont;
|
||||
object->menu = gtk_menu_new();
|
||||
object->widget = gtk_menu_item_new_with_label(text);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(object->widget), object->menu);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_bar_append(parent.object->menu, object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void Menu::create(Menu &parent, const string &text) {
|
||||
action->font = parent.action->font;
|
||||
object->menu = gtk_menu_new();
|
||||
object->widget = gtk_menu_item_new_with_label(text);
|
||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(object->widget), object->menu);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void MenuSeparator::create(Menu &parent) {
|
||||
action->font = parent.action->font;
|
||||
object->widget = gtk_separator_menu_item_new();
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
static void MenuItem_tick(MenuItem *self) {
|
||||
if(self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
void MenuItem::create(Menu &parent, const string &text) {
|
||||
action->font = parent.action->font;
|
||||
object->widget = gtk_menu_item_new_with_label(text);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(MenuItem_tick), (gpointer)this);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
static void MenuCheckItem_tick(MenuCheckItem *self) {
|
||||
if(self->onTick && self->object->locked == false) self->onTick();
|
||||
}
|
||||
|
||||
void MenuCheckItem::create(Menu &parent, const string &text) {
|
||||
action->font = parent.action->font;
|
||||
object->widget = gtk_check_menu_item_new_with_label(text);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuCheckItem_tick), (gpointer)this);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
bool MenuCheckItem::checked() {
|
||||
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget));
|
||||
}
|
||||
|
||||
void MenuCheckItem::setChecked(bool state) {
|
||||
object->locked = true;
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), state);
|
||||
object->locked = false;
|
||||
}
|
||||
|
||||
static void MenuRadioItem_tick(MenuRadioItem *self) {
|
||||
if(self->onTick && self->checked() && self->object->locked == false) self->onTick();
|
||||
}
|
||||
|
||||
void MenuRadioItem::create(Menu &parent, const string &text) {
|
||||
first = this;
|
||||
action->font = parent.action->font;
|
||||
object->parentMenu = &parent;
|
||||
object->widget = gtk_radio_menu_item_new_with_label(0, text);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)this);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent.object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void MenuRadioItem::create(MenuRadioItem &parent, const string &text) {
|
||||
first = parent.first;
|
||||
action->font = parent.action->font;
|
||||
object->parentMenu = parent.object->parentMenu;
|
||||
object->widget = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(first->object->widget), text);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(MenuRadioItem_tick), (gpointer)this);
|
||||
if(action->font) Action_setFont(object->widget, action->font->font->font);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(object->parentMenu->object->menu), object->widget);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
bool MenuRadioItem::checked() {
|
||||
return gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(object->widget));
|
||||
}
|
||||
|
||||
void MenuRadioItem::setChecked() {
|
||||
object->locked = true;
|
||||
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(object->widget), true);
|
||||
object->locked = false;
|
||||
}
|
|
@ -8,13 +8,12 @@ static MessageWindow::Response MessageWindow_response(MessageWindow::Buttons but
|
|||
return MessageWindow::Response::Ok;
|
||||
}
|
||||
|
||||
MessageWindow::Response MessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
MessageWindow::Response pMessageWindow::information(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
GtkButtonsType buttonsType = GTK_BUTTONS_OK;
|
||||
if(buttons == Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
|
||||
if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
GtkWidget *dialog = gtk_message_dialog_new(
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, buttonsType, "%s", (const char*)text
|
||||
);
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
@ -22,13 +21,12 @@ MessageWindow::Response MessageWindow::information(Window &parent, const string
|
|||
return MessageWindow_response(buttons, response);
|
||||
}
|
||||
|
||||
MessageWindow::Response MessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
MessageWindow::Response pMessageWindow::question(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
GtkButtonsType buttonsType = GTK_BUTTONS_OK;
|
||||
if(buttons == Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
|
||||
if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
GtkWidget *dialog = gtk_message_dialog_new(
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, buttonsType, "%s", (const char*)text
|
||||
);
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
@ -36,13 +34,12 @@ MessageWindow::Response MessageWindow::question(Window &parent, const string &te
|
|||
return MessageWindow_response(buttons, response);
|
||||
}
|
||||
|
||||
MessageWindow::Response MessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
MessageWindow::Response pMessageWindow::warning(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
GtkButtonsType buttonsType = GTK_BUTTONS_OK;
|
||||
if(buttons == Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
|
||||
if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
GtkWidget *dialog = gtk_message_dialog_new(
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, buttonsType, "%s", (const char*)text
|
||||
);
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
@ -50,13 +47,12 @@ MessageWindow::Response MessageWindow::warning(Window &parent, const string &tex
|
|||
return MessageWindow_response(buttons, response);
|
||||
}
|
||||
|
||||
MessageWindow::Response MessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
MessageWindow::Response pMessageWindow::critical(Window &parent, const string &text, MessageWindow::Buttons buttons) {
|
||||
GtkButtonsType buttonsType = GTK_BUTTONS_OK;
|
||||
if(buttons == Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
|
||||
if(buttons == MessageWindow::Buttons::OkCancel) buttonsType = GTK_BUTTONS_OK_CANCEL;
|
||||
if(buttons == MessageWindow::Buttons::YesNo) buttonsType = GTK_BUTTONS_YES_NO;
|
||||
GtkWidget *dialog = gtk_message_dialog_new(
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.object->widget) : (GtkWindow*)0,
|
||||
&parent != &Window::None ? GTK_WINDOW(parent.p.widget) : (GtkWindow*)0,
|
||||
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, buttonsType, "%s", (const char*)text
|
||||
);
|
||||
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
@ -1,57 +0,0 @@
|
|||
struct Object::Data {
|
||||
bool locked;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *subWidget;
|
||||
GtkWidget *menuContainer;
|
||||
GtkWidget *formContainer;
|
||||
GtkWidget *statusContainer;
|
||||
GtkWidget *menu;
|
||||
GtkWidget *status;
|
||||
Menu *parentMenu;
|
||||
Window *parentWindow;
|
||||
GtkTextBuffer *textBuffer;
|
||||
unsigned position;
|
||||
};
|
||||
|
||||
struct Font::Data {
|
||||
PangoFontDescription *font;
|
||||
};
|
||||
|
||||
struct Action::Data {
|
||||
Font *font;
|
||||
};
|
||||
|
||||
struct Widget::Data {
|
||||
Window *parent;
|
||||
};
|
||||
|
||||
struct Window::Data {
|
||||
Font *defaultFont;
|
||||
};
|
||||
|
||||
struct Canvas::Data {
|
||||
uint32_t *bufferRGB;
|
||||
uint32_t *bufferBGR;
|
||||
unsigned pitch;
|
||||
};
|
||||
|
||||
struct ListBox::Data {
|
||||
GtkListStore *store;
|
||||
struct GtkColumn {
|
||||
GtkCellRenderer *renderer;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkWidget *label;
|
||||
};
|
||||
linear_vector<GtkColumn> column;
|
||||
bool checkable;
|
||||
signed selection;
|
||||
};
|
||||
|
||||
void Object::unused() {
|
||||
}
|
||||
|
||||
Object::Object() {
|
||||
OS::initialize();
|
||||
object = new Object::Data;
|
||||
object->locked = false;
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
void ProgressBar::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
object->widget = gtk_progress_bar_new();
|
||||
widget->parent = &parent;
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void ProgressBar::setPosition(unsigned position) {
|
||||
position = position <= 100 ? position : 0;
|
||||
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(object->widget), (double)position / 100.0);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
static void RadioBox_tick(RadioBox *self) {
|
||||
if(self->onTick && self->checked() && self->object->locked == false) self->onTick();
|
||||
}
|
||||
|
||||
void RadioBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
first = this;
|
||||
object->parentWindow = &parent;
|
||||
object->widget = gtk_radio_button_new_with_label(0, text);
|
||||
widget->parent = &parent;
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)this);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void RadioBox::create(RadioBox &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
first = parent.first;
|
||||
object->parentWindow = parent.object->parentWindow;
|
||||
object->widget = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(parent.object->widget), text);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)this);
|
||||
if(object->parentWindow->window->defaultFont) setFont(*object->parentWindow->window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(object->parentWindow->object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
bool RadioBox::checked() {
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(object->widget));
|
||||
}
|
||||
|
||||
void RadioBox::setChecked() {
|
||||
object->locked = true;
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object->widget), true);
|
||||
object->locked = false;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
static Settings settings;
|
||||
|
||||
void Settings::load() {
|
||||
string path = { userpath(), ".config/phoenix/gtk.cfg" };
|
||||
configuration::load(path);
|
||||
}
|
||||
|
||||
void Settings::save() {
|
||||
string path = { userpath(), ".config/" };
|
||||
mkdir(path, 0755);
|
||||
path.append("phoenix/");
|
||||
mkdir(path, 0755);
|
||||
path.append("gtk.cfg");
|
||||
configuration::save(path);
|
||||
}
|
||||
|
||||
Settings::Settings() {
|
||||
attach(frameGeometryX = 4, "frameGeometryX");
|
||||
attach(frameGeometryY = 24, "frameGeometryY");
|
||||
attach(frameGeometryWidth = 8, "frameGeometryWidth");
|
||||
attach(frameGeometryHeight = 28, "frameGeometryHeight");
|
||||
attach(menuGeometryHeight = 20, "menuGeometryHeight");
|
||||
attach(statusGeometryHeight = 20, "statusGeometryHeight");
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
static void TextBox_activate(TextBox *self) {
|
||||
if(self->onActivate) self->onActivate();
|
||||
}
|
||||
|
||||
static void TextBox_change(TextBox *self) {
|
||||
if(self->object->locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void TextBox::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_entry_new();
|
||||
widget->parent = &parent;
|
||||
gtk_entry_set_text(GTK_ENTRY(object->widget), text);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "activate", G_CALLBACK(TextBox_activate), (gpointer)this);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "changed", G_CALLBACK(TextBox_change), (gpointer)this);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void TextBox::setEditable(bool editable) {
|
||||
gtk_entry_set_editable(GTK_ENTRY(object->widget), editable);
|
||||
}
|
||||
|
||||
string TextBox::text() {
|
||||
return gtk_entry_get_text(GTK_ENTRY(object->widget));
|
||||
}
|
||||
|
||||
void TextBox::setText(const string &text) {
|
||||
object->locked = true;
|
||||
gtk_entry_set_text(GTK_ENTRY(object->widget), text);
|
||||
object->locked = false;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
static void VerticalSlider_change(VerticalSlider *self) {
|
||||
if(self->object->position == self->position()) return;
|
||||
self->object->position = self->position();
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void VerticalSlider::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height, unsigned length) {
|
||||
object->position = 0;
|
||||
length += (length == 0);
|
||||
object->widget = gtk_vscale_new_with_range(0, length - 1, 1);
|
||||
widget->parent = &parent;
|
||||
gtk_scale_set_draw_value(GTK_SCALE(object->widget), false);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)this);
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
unsigned VerticalSlider::position() {
|
||||
return (unsigned)gtk_range_get_value(GTK_RANGE(object->widget));
|
||||
}
|
||||
|
||||
void VerticalSlider::setPosition(unsigned position) {
|
||||
gtk_range_set_value(GTK_RANGE(object->widget), position);
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
void Viewport::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
object->widget = gtk_drawing_area_new();
|
||||
widget->parent = &parent;
|
||||
//gtk_widget_set_double_buffered(object->widget, false);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
|
||||
GdkColor color;
|
||||
color.pixel = 0;
|
||||
color.red = 0;
|
||||
color.green = 0;
|
||||
color.blue = 0;
|
||||
gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color);
|
||||
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
uintptr_t Viewport::handle() {
|
||||
return GDK_WINDOW_XID(object->widget->window);
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
static void Widget_setFont(GtkWidget *widget, gpointer font) {
|
||||
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
|
||||
if(GTK_IS_CONTAINER(widget)) {
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Widget_setFont, font);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::setFont(Font &font) {
|
||||
Widget_setFont(object->widget, font.font->font);
|
||||
}
|
||||
|
||||
bool Widget::visible() {
|
||||
return gtk_widget_get_visible(object->widget);
|
||||
}
|
||||
|
||||
void Widget::setVisible(bool visible) {
|
||||
if(visible) gtk_widget_show(object->widget);
|
||||
else gtk_widget_hide(object->widget);
|
||||
}
|
||||
|
||||
bool Widget::enabled() {
|
||||
return gtk_widget_get_sensitive(object->widget);
|
||||
}
|
||||
|
||||
void Widget::setEnabled(bool enabled) {
|
||||
gtk_widget_set_sensitive(object->widget, enabled);
|
||||
}
|
||||
|
||||
bool Widget::focused() {
|
||||
return gtk_widget_is_focus(object->widget);
|
||||
}
|
||||
|
||||
void Widget::setFocused() {
|
||||
if(visible() == false) setVisible(true);
|
||||
gtk_widget_grab_focus(object->widget);
|
||||
}
|
||||
|
||||
void Widget::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
if(widget->parent == 0) return;
|
||||
gtk_fixed_move(GTK_FIXED(widget->parent->object->formContainer), object->widget, x, y);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
}
|
||||
|
||||
Widget::Widget() {
|
||||
widget = new Widget::Data;
|
||||
widget->parent = 0;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
static void Button_tick(Button *self) {
|
||||
if(self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
void pButton::setText(const string &text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
}
|
||||
|
||||
void pButton::constructor() {
|
||||
gtkWidget = gtk_button_new();
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "clicked", G_CALLBACK(Button_tick), (gpointer)&button);
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
static void CheckBox_tick(CheckBox *self) {
|
||||
if(self->p.locked == false && self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
bool pCheckBox::checked() {
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget));
|
||||
}
|
||||
|
||||
void pCheckBox::setChecked(bool checked) {
|
||||
locked = true;
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), checked);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pCheckBox::setText(const string &text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
}
|
||||
|
||||
void pCheckBox::constructor() {
|
||||
gtkWidget = gtk_check_button_new_with_label("");
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(CheckBox_tick), (gpointer)&checkBox);
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
static void ComboBox_change(ComboBox *self) {
|
||||
if(self->p.locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void pComboBox::append(const string &text) {
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(gtkWidget), text);
|
||||
if(itemCounter++ == 0) setSelection(0);
|
||||
}
|
||||
|
||||
void pComboBox::reset() {
|
||||
locked = true;
|
||||
for(signed n = itemCounter - 1; n >= 0; n--) {
|
||||
gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkWidget), n);
|
||||
}
|
||||
itemCounter = 0;
|
||||
locked = false;
|
||||
}
|
||||
|
||||
unsigned pComboBox::selection() {
|
||||
return gtk_combo_box_get_active(GTK_COMBO_BOX(gtkWidget));
|
||||
}
|
||||
|
||||
void pComboBox::setSelection(unsigned row) {
|
||||
locked = true;
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(gtkWidget), row);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pComboBox::constructor() {
|
||||
itemCounter = 0;
|
||||
gtkWidget = gtk_combo_box_new_text();
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(ComboBox_change), (gpointer)&comboBox);
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
static bool HexEdit_keyPress(GtkWidget *widget, GdkEventKey *event, HexEdit *self) {
|
||||
return self->p.keyPress(event->keyval);
|
||||
}
|
||||
|
||||
static bool HexEdit_scroll(GtkRange *range, GtkScrollType scroll, gdouble value, HexEdit *self) {
|
||||
self->p.scroll((unsigned)value);
|
||||
return false;
|
||||
}
|
||||
|
||||
void pHexEdit::setColumns(unsigned columns) {
|
||||
setScroll();
|
||||
update();
|
||||
}
|
||||
|
||||
void pHexEdit::setLength(unsigned length) {
|
||||
setScroll();
|
||||
update();
|
||||
}
|
||||
|
||||
void pHexEdit::setOffset(unsigned offset) {
|
||||
setScroll();
|
||||
updateScroll();
|
||||
update();
|
||||
}
|
||||
|
||||
void pHexEdit::setRows(unsigned rows) {
|
||||
setScroll();
|
||||
update();
|
||||
}
|
||||
|
||||
void pHexEdit::update() {
|
||||
if(!hexEdit.onRead) {
|
||||
gtk_text_buffer_set_text(textBuffer, "", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned position = cursorPosition();
|
||||
|
||||
string output;
|
||||
unsigned offset = hexEdit.state.offset;
|
||||
for(unsigned row = 0; row < hexEdit.state.rows; row++) {
|
||||
output.append(hex<8>(offset));
|
||||
output.append(" ");
|
||||
|
||||
string hexdata;
|
||||
string ansidata = " ";
|
||||
for(unsigned column = 0; column < hexEdit.state.columns; column++) {
|
||||
if(offset < hexEdit.state.length) {
|
||||
uint8_t data = hexEdit.onRead(offset++);
|
||||
hexdata.append(hex<2>(data));
|
||||
hexdata.append(" ");
|
||||
char buffer[2] = { data >= 0x20 && data <= 0x7e ? (char)data : '.', 0 };
|
||||
ansidata.append(buffer);
|
||||
} else {
|
||||
hexdata.append(" ");
|
||||
ansidata.append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
output.append(hexdata);
|
||||
output.append(ansidata);
|
||||
if(offset >= hexEdit.state.length) break;
|
||||
if(row != hexEdit.state.rows - 1) output.append("\n");
|
||||
}
|
||||
|
||||
gtk_text_buffer_set_text(textBuffer, output, -1);
|
||||
if(position == 0) position = 10; //start at first position where hex values can be entered
|
||||
setCursorPosition(position);
|
||||
}
|
||||
|
||||
void pHexEdit::constructor() {
|
||||
gtkWidget = gtk_hbox_new(false, 0);
|
||||
|
||||
container = gtk_scrolled_window_new(0, 0);
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(container), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(container), GTK_SHADOW_ETCHED_IN);
|
||||
|
||||
subWidget = gtk_text_view_new();
|
||||
gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), false);
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_NONE);
|
||||
gtk_container_add(GTK_CONTAINER(container), subWidget);
|
||||
g_signal_connect(G_OBJECT(subWidget), "key-press-event", G_CALLBACK(HexEdit_keyPress), (gpointer)&hexEdit);
|
||||
|
||||
scrollBar = gtk_vscrollbar_new((GtkAdjustment*)0);
|
||||
gtk_range_set_range(GTK_RANGE(scrollBar), 0, 255);
|
||||
gtk_range_set_increments(GTK_RANGE(scrollBar), 1, 16);
|
||||
gtk_widget_set_sensitive(scrollBar, false);
|
||||
g_signal_connect(G_OBJECT(scrollBar), "change-value", G_CALLBACK(HexEdit_scroll), (gpointer)&hexEdit);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(gtkWidget), container, true, true, 0);
|
||||
gtk_box_pack_start(GTK_BOX(gtkWidget), scrollBar, false, false, 1);
|
||||
|
||||
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget));
|
||||
textCursor = gtk_text_buffer_get_mark(textBuffer, "insert");
|
||||
|
||||
gtk_widget_show(scrollBar);
|
||||
gtk_widget_show(subWidget);
|
||||
gtk_widget_show(container);
|
||||
}
|
||||
|
||||
unsigned pHexEdit::cursorPosition() {
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor);
|
||||
return gtk_text_iter_get_offset(&iter);
|
||||
}
|
||||
|
||||
bool pHexEdit::keyPress(unsigned scancode) {
|
||||
if(!hexEdit.onRead) return false;
|
||||
|
||||
unsigned position = cursorPosition();
|
||||
unsigned lineWidth = 10 + (hexEdit.state.columns * 3) + 1 + hexEdit.state.columns + 1;
|
||||
unsigned cursorY = position / lineWidth;
|
||||
unsigned cursorX = position % lineWidth;
|
||||
|
||||
if(scancode == GDK_Home) {
|
||||
setCursorPosition(cursorY * lineWidth + 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_End) {
|
||||
setCursorPosition(cursorY * lineWidth + 10 + (hexEdit.state.columns * 3 - 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Up) {
|
||||
if(cursorY != 0) return false;
|
||||
|
||||
signed newOffset = hexEdit.state.offset - hexEdit.state.columns;
|
||||
if(newOffset >= 0) {
|
||||
hexEdit.setOffset(newOffset);
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Down) {
|
||||
if(cursorY != hexEdit.state.rows - 1) return false;
|
||||
|
||||
signed newOffset = hexEdit.state.offset + hexEdit.state.columns;
|
||||
if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) {
|
||||
hexEdit.setOffset(newOffset);
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Page_Up) {
|
||||
signed newOffset = hexEdit.state.offset - hexEdit.state.columns * hexEdit.state.rows;
|
||||
if(newOffset >= 0) {
|
||||
hexEdit.setOffset(newOffset);
|
||||
} else {
|
||||
hexEdit.setOffset(0);
|
||||
}
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Page_Down) {
|
||||
signed newOffset = hexEdit.state.offset + hexEdit.state.columns * hexEdit.state.rows;
|
||||
for(unsigned n = 0; n < hexEdit.state.rows; n++) {
|
||||
if(newOffset + hexEdit.state.columns * hexEdit.state.rows - (hexEdit.state.columns - 1) <= hexEdit.state.length) {
|
||||
hexEdit.setOffset(newOffset);
|
||||
update();
|
||||
break;
|
||||
}
|
||||
newOffset -= hexEdit.state.columns;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//convert scancode to hex nibble
|
||||
if(scancode >= '0' && scancode <= '9') scancode = scancode - '0';
|
||||
else if(scancode >= 'A' && scancode <= 'F') scancode = scancode - 'A' + 10;
|
||||
else if(scancode >= 'a' && scancode <= 'f') scancode = scancode - 'a' + 10;
|
||||
else return false; //not a valid hex value
|
||||
|
||||
if(cursorX >= 10) {
|
||||
//not on an offset
|
||||
cursorX -= 10;
|
||||
if((cursorX % 3) != 2) {
|
||||
//not on a space
|
||||
bool cursorNibble = (cursorX % 3) == 1; //0 = high, 1 = low
|
||||
cursorX /= 3;
|
||||
if(cursorX < hexEdit.state.columns) {
|
||||
//not in ANSI region
|
||||
unsigned offset = hexEdit.state.offset + (cursorY * hexEdit.state.columns + cursorX);
|
||||
|
||||
if(offset >= hexEdit.state.length) return false; //do not edit past end of data
|
||||
uint8_t data = hexEdit.onRead(offset);
|
||||
|
||||
//write modified value
|
||||
if(cursorNibble == 1) {
|
||||
data = (data & 0xf0) | (scancode << 0);
|
||||
} else {
|
||||
data = (data & 0x0f) | (scancode << 4);
|
||||
}
|
||||
if(hexEdit.onWrite) hexEdit.onWrite(offset, data);
|
||||
|
||||
//auto-advance cursor to next nibble/byte
|
||||
position++;
|
||||
if(cursorNibble && cursorX != hexEdit.state.columns - 1) position++;
|
||||
setCursorPosition(position);
|
||||
|
||||
//refresh output to reflect modified data
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pHexEdit::scroll(unsigned position) {
|
||||
unsigned rows = hexEdit.state.length / hexEdit.state.columns;
|
||||
if(position >= rows) position = rows - 1;
|
||||
hexEdit.setOffset(position * hexEdit.state.columns);
|
||||
}
|
||||
|
||||
void pHexEdit::setCursorPosition(unsigned position) {
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_iter_at_mark(textBuffer, &iter, textCursor);
|
||||
|
||||
//GTK+ will throw many errors to the terminal if you set iterator past end of buffer
|
||||
GtkTextIter endIter;
|
||||
gtk_text_buffer_get_end_iter(textBuffer, &iter);
|
||||
unsigned endPosition = gtk_text_iter_get_offset(&iter);
|
||||
|
||||
gtk_text_iter_set_offset(&iter, min(position, endPosition));
|
||||
gtk_text_buffer_place_cursor(textBuffer, &iter);
|
||||
}
|
||||
|
||||
void pHexEdit::setScroll() {
|
||||
unsigned rows = hexEdit.state.length / hexEdit.state.columns;
|
||||
if(rows) rows--;
|
||||
if(rows) {
|
||||
gtk_range_set_range(GTK_RANGE(scrollBar), 0, rows);
|
||||
gtk_widget_set_sensitive(scrollBar, true);
|
||||
} else {
|
||||
gtk_widget_set_sensitive(scrollBar, false);
|
||||
}
|
||||
}
|
||||
|
||||
void pHexEdit::updateScroll() {
|
||||
unsigned row = hexEdit.state.offset / hexEdit.state.columns;
|
||||
gtk_range_set_value(GTK_RANGE(scrollBar), row);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
static void HorizontalSlider_change(HorizontalSlider *self) {
|
||||
if(self->state.position == self->position()) return;
|
||||
self->state.position = self->position();
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
unsigned pHorizontalSlider::position() {
|
||||
return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget));
|
||||
}
|
||||
|
||||
void pHorizontalSlider::setLength(unsigned length) {
|
||||
length += length == 0;
|
||||
gtk_range_set_range(GTK_RANGE(gtkWidget), 0, length - 1);
|
||||
}
|
||||
|
||||
void pHorizontalSlider::setPosition(unsigned position) {
|
||||
gtk_range_set_value(GTK_RANGE(gtkWidget), position);
|
||||
}
|
||||
|
||||
void pHorizontalSlider::constructor() {
|
||||
gtkWidget = gtk_hscale_new_with_range(0, 100, 1);
|
||||
gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(HorizontalSlider_change), (gpointer)&horizontalSlider);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
void pLabel::setText(const string &text) {
|
||||
gtk_label_set_text(GTK_LABEL(gtkWidget), text);
|
||||
}
|
||||
|
||||
void pLabel::constructor() {
|
||||
gtkWidget = gtk_label_new("");
|
||||
gtk_misc_set_alignment(GTK_MISC(gtkWidget), 0.0, 0.5);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
static void LineEdit_activate(LineEdit *self) {
|
||||
if(self->onActivate) self->onActivate();
|
||||
}
|
||||
|
||||
static void LineEdit_change(LineEdit *self) {
|
||||
if(self->p.locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void pLineEdit::setEditable(bool editable) {
|
||||
gtk_entry_set_editable(GTK_ENTRY(gtkWidget), editable);
|
||||
}
|
||||
|
||||
void pLineEdit::setText(const string &text) {
|
||||
locked = true;
|
||||
gtk_entry_set_text(GTK_ENTRY(gtkWidget), text);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
string pLineEdit::text() {
|
||||
return gtk_entry_get_text(GTK_ENTRY(gtkWidget));
|
||||
}
|
||||
|
||||
void pLineEdit::constructor() {
|
||||
gtkWidget = gtk_entry_new();
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "activate", G_CALLBACK(LineEdit_activate), (gpointer)&lineEdit);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "changed", G_CALLBACK(LineEdit_change), (gpointer)&lineEdit);
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
static void ListView_activate(ListView *self) {
|
||||
if(self->onActivate) self->onActivate();
|
||||
}
|
||||
|
||||
static void ListView_change(ListView *self) {
|
||||
if(self->state.selected == false || self->state.selection != self->selection()) {
|
||||
self->state.selected = true;
|
||||
self->state.selection = self->selection();
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
}
|
||||
|
||||
static void ListView_tick(GtkCellRendererToggle *cell, gchar *path_string, ListView *self) {
|
||||
unsigned row = decimal(path_string);
|
||||
self->setChecked(row, !self->checked(row));
|
||||
if(self->onTick) self->onTick(row);
|
||||
}
|
||||
|
||||
void pListView::append(const lstring &text) {
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append(store, &iter);
|
||||
foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1);
|
||||
}
|
||||
|
||||
void pListView::autoSizeColumns() {
|
||||
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(subWidget));
|
||||
}
|
||||
|
||||
bool pListView::checked(unsigned row) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string(string(row));
|
||||
GtkTreeIter iter;
|
||||
bool state;
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(model, &iter, 0, &state, -1);
|
||||
gtk_tree_path_free(path);
|
||||
return state;
|
||||
}
|
||||
|
||||
void pListView::modify(unsigned row, const lstring &text) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeIter iter;
|
||||
for(unsigned i = 0; i <= row; i++) {
|
||||
if(i == 0) gtk_tree_model_get_iter_first(model, &iter);
|
||||
else gtk_tree_model_iter_next(model, &iter);
|
||||
}
|
||||
foreach(item, text, n) gtk_list_store_set(store, &iter, 1 + n, (const char*)item, -1);
|
||||
}
|
||||
|
||||
void pListView::reset() {
|
||||
listView.state.selected = false;
|
||||
listView.state.selection = 0;
|
||||
gtk_list_store_clear(GTK_LIST_STORE(store));
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(subWidget), GTK_TREE_MODEL(store));
|
||||
//reset gtk_scrolled_window scrollbar position to 0,0 (top-left), as ListView is now empty
|
||||
gtk_scrolled_window_set_hadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0);
|
||||
gtk_scrolled_window_set_vadjustment(GTK_SCROLLED_WINDOW(gtkWidget), 0);
|
||||
}
|
||||
|
||||
bool pListView::selected() {
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeIter iter;
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) return false;
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true;
|
||||
for(unsigned n = 1;; n++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) return false;
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned pListView::selection() {
|
||||
if(selected() == false) return listView.state.selection;
|
||||
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeIter iter;
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) return 0;
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return 0;
|
||||
for(unsigned n = 1;; n++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) return 0;
|
||||
if(gtk_tree_selection_iter_is_selected(selection, &iter) == true) return n;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void pListView::setCheckable(bool checkable) {
|
||||
gtk_tree_view_column_set_visible(column[0].column, checkable);
|
||||
}
|
||||
|
||||
void pListView::setChecked(unsigned row, bool checked) {
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string(string(row));
|
||||
GtkTreeIter iter;
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, checked, -1);
|
||||
gtk_tree_path_free(path);
|
||||
}
|
||||
|
||||
void pListView::setHeaderText(const lstring &text) {
|
||||
create();
|
||||
}
|
||||
|
||||
void pListView::setHeaderVisible(bool visible) {
|
||||
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(subWidget), visible);
|
||||
}
|
||||
|
||||
void pListView::setSelected(bool selected) {
|
||||
if(selected == false) {
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
} else {
|
||||
setSelection(listView.state.selection);
|
||||
}
|
||||
}
|
||||
|
||||
void pListView::setSelection(unsigned row) {
|
||||
signed current = -1;
|
||||
if(selected()) current = selection();
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(subWidget));
|
||||
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(subWidget));
|
||||
gtk_tree_selection_unselect_all(selection);
|
||||
|
||||
GtkTreeIter iter;
|
||||
if(gtk_tree_model_get_iter_first(model, &iter) == false) return;
|
||||
if(row == 0) {
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
return;
|
||||
}
|
||||
for(unsigned n = 1;; n++) {
|
||||
if(gtk_tree_model_iter_next(model, &iter) == false) return;
|
||||
if(row == n) {
|
||||
gtk_tree_selection_select_iter(selection, &iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pListView::constructor() {
|
||||
gtkWidget = 0;
|
||||
subWidget = 0;
|
||||
create();
|
||||
}
|
||||
|
||||
void pListView::create() {
|
||||
if(subWidget) gtk_widget_destroy(subWidget);
|
||||
if(gtkWidget) gtk_widget_destroy(gtkWidget);
|
||||
|
||||
gtkWidget = gtk_scrolled_window_new(0, 0);
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN);
|
||||
|
||||
lstring headerText;
|
||||
headerText.append(""); //checkbox column
|
||||
foreach(headerItem, listView.state.headerText) headerText.append(headerItem);
|
||||
if(headerText.size() == 1) headerText.append("");
|
||||
|
||||
GType *v = (GType*)malloc(headerText.size() * sizeof(GType));
|
||||
foreach(header, headerText, n) v[n] = (n == 0 ? G_TYPE_BOOLEAN : G_TYPE_STRING);
|
||||
store = gtk_list_store_newv(headerText.size(), v);
|
||||
free(v);
|
||||
|
||||
subWidget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
|
||||
gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget);
|
||||
g_object_unref(G_OBJECT(store));
|
||||
|
||||
foreach(header, headerText, n) {
|
||||
if(n == 0) {
|
||||
column[n].renderer = gtk_cell_renderer_toggle_new();
|
||||
column[n].column = gtk_tree_view_column_new_with_attributes("", column[n].renderer, "active", n, (void*)0);
|
||||
gtk_tree_view_column_set_resizable(column[n].column, false);
|
||||
gtk_tree_view_column_set_visible(column[n].column, false);
|
||||
g_signal_connect(column[n].renderer, "toggled", G_CALLBACK(ListView_tick), (gpointer)&listView);
|
||||
} else {
|
||||
column[n].renderer = gtk_cell_renderer_text_new();
|
||||
column[n].column = gtk_tree_view_column_new_with_attributes("", column[n].renderer, "text", n, (void*)0);
|
||||
gtk_tree_view_column_set_resizable(column[n].column, true);
|
||||
}
|
||||
column[n].label = gtk_label_new(header);
|
||||
gtk_tree_view_column_set_widget(GTK_TREE_VIEW_COLUMN(column[n].column), column[n].label);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(subWidget), column[n].column);
|
||||
gtk_widget_show(column[n].label);
|
||||
}
|
||||
|
||||
gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(subWidget), headerText.size() >= 3); //two or more columns + checkbox column
|
||||
gtk_tree_view_set_search_column(GTK_TREE_VIEW(subWidget), 1);
|
||||
|
||||
g_signal_connect_swapped(G_OBJECT(subWidget), "cursor-changed", G_CALLBACK(ListView_change), (gpointer)&listView);
|
||||
g_signal_connect_swapped(G_OBJECT(subWidget), "row-activated", G_CALLBACK(ListView_activate), (gpointer)&listView);
|
||||
|
||||
setHeaderVisible(listView.state.headerVisible);
|
||||
setCheckable(listView.state.checkable);
|
||||
foreach(text, listView.state.text) append(text);
|
||||
foreach(checked, listView.state.checked, n) setChecked(n, checked);
|
||||
if(listView.state.selected) setSelection(listView.state.selection);
|
||||
autoSizeColumns();
|
||||
|
||||
gtk_widget_show(subWidget);
|
||||
}
|
||||
|
||||
void pListView::setFocused() {
|
||||
gtk_widget_grab_focus(subWidget);
|
||||
}
|
||||
|
||||
void pListView::setFont(Font &font) {
|
||||
pWidget::setFont(font);
|
||||
for(unsigned n = 0; n < 1 + listView.state.headerText.size(); n++) {
|
||||
gtk_widget_modify_font(column[n].label, font.p.gtkFont);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
void pProgressBar::setPosition(unsigned position) {
|
||||
position = position <= 100 ? position : 0;
|
||||
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(gtkWidget), (double)position / 100.0);
|
||||
}
|
||||
|
||||
void pProgressBar::constructor() {
|
||||
gtkWidget = gtk_progress_bar_new();
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
static void RadioBox_tick(RadioBox *self) {
|
||||
if(self->p.locked == false && self->checked() && self->onTick) self->onTick();
|
||||
}
|
||||
|
||||
bool pRadioBox::checked() {
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(gtkWidget));
|
||||
}
|
||||
|
||||
void pRadioBox::setChecked() {
|
||||
locked = true;
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gtkWidget), true);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pRadioBox::setGroup(const reference_array<RadioBox&> &group) {
|
||||
foreach(item, group, n) {
|
||||
if(n == 0) continue;
|
||||
GSList *currentGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(group[0].p.gtkWidget));
|
||||
if(currentGroup != gtk_radio_button_get_group(GTK_RADIO_BUTTON(gtkWidget))) {
|
||||
gtk_radio_button_set_group(GTK_RADIO_BUTTON(gtkWidget), currentGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pRadioBox::setText(const string &text) {
|
||||
gtk_button_set_label(GTK_BUTTON(gtkWidget), text);
|
||||
}
|
||||
|
||||
void pRadioBox::constructor() {
|
||||
gtkWidget = gtk_radio_button_new_with_label(0, "");
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "toggled", G_CALLBACK(RadioBox_tick), (gpointer)&radioBox);
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
static void TextEdit_change(TextEdit *self) {
|
||||
if(self->p.locked == false && self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
void pTextEdit::setCursorPosition(unsigned position) {
|
||||
GtkTextMark *mark = gtk_text_buffer_get_mark(textBuffer, "insert");
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_end_iter(textBuffer, &iter);
|
||||
gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter)));
|
||||
gtk_text_buffer_place_cursor(textBuffer, &iter);
|
||||
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(subWidget), mark);
|
||||
}
|
||||
|
||||
void pTextEdit::setEditable(bool editable) {
|
||||
gtk_text_view_set_editable(GTK_TEXT_VIEW(subWidget), editable);
|
||||
}
|
||||
|
||||
void pTextEdit::setText(const string &text) {
|
||||
locked = true;
|
||||
gtk_text_buffer_set_text(textBuffer, text, -1);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void pTextEdit::setWordWrap(bool wordWrap) {
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), wordWrap ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE);
|
||||
}
|
||||
|
||||
string pTextEdit::text() {
|
||||
GtkTextIter start, end;
|
||||
gtk_text_buffer_get_start_iter(textBuffer, &start);
|
||||
gtk_text_buffer_get_end_iter(textBuffer, &end);
|
||||
char *temp = gtk_text_buffer_get_text(textBuffer, &start, &end, true);
|
||||
string text = temp;
|
||||
g_free(temp);
|
||||
return text;
|
||||
}
|
||||
|
||||
void pTextEdit::constructor() {
|
||||
gtkWidget = gtk_scrolled_window_new(0, 0);
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(gtkWidget), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(gtkWidget), GTK_SHADOW_ETCHED_IN);
|
||||
subWidget = gtk_text_view_new();
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(subWidget), GTK_WRAP_WORD_CHAR);
|
||||
gtk_container_add(GTK_CONTAINER(gtkWidget), subWidget);
|
||||
textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(subWidget));
|
||||
g_signal_connect_swapped(G_OBJECT(textBuffer), "changed", G_CALLBACK(TextEdit_change), (gpointer)&textEdit);
|
||||
gtk_widget_show(subWidget);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
static void VerticalSlider_change(VerticalSlider *self) {
|
||||
if(self->state.position == self->position()) return;
|
||||
self->state.position = self->position();
|
||||
if(self->onChange) self->onChange();
|
||||
}
|
||||
|
||||
unsigned pVerticalSlider::position() {
|
||||
return (unsigned)gtk_range_get_value(GTK_RANGE(gtkWidget));
|
||||
}
|
||||
|
||||
void pVerticalSlider::setLength(unsigned length) {
|
||||
length += length == 0;
|
||||
gtk_range_set_range(GTK_RANGE(gtkWidget), 0, length - 1);
|
||||
}
|
||||
|
||||
void pVerticalSlider::setPosition(unsigned position) {
|
||||
gtk_range_set_value(GTK_RANGE(gtkWidget), position);
|
||||
}
|
||||
|
||||
void pVerticalSlider::constructor() {
|
||||
gtkWidget = gtk_vscale_new_with_range(0, 100, 1);
|
||||
gtk_scale_set_draw_value(GTK_SCALE(gtkWidget), false);
|
||||
g_signal_connect_swapped(G_OBJECT(gtkWidget), "value-changed", G_CALLBACK(VerticalSlider_change), (gpointer)&verticalSlider);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
uintptr_t pViewport::handle() {
|
||||
return GDK_WINDOW_XID(gtkWidget->window);
|
||||
}
|
||||
|
||||
void pViewport::constructor() {
|
||||
gtkWidget = gtk_drawing_area_new();
|
||||
//gtk_widget_set_double_buffered(gtkWidget, false);
|
||||
|
||||
GdkColor color;
|
||||
color.pixel = 0;
|
||||
color.red = 0;
|
||||
color.green = 0;
|
||||
color.blue = 0;
|
||||
gtk_widget_modify_bg(gtkWidget, GTK_STATE_NORMAL, &color);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
static void Widget_setFont(GtkWidget *widget, gpointer font) {
|
||||
if(font == 0) return;
|
||||
gtk_widget_modify_font(widget, (PangoFontDescription*)font);
|
||||
if(GTK_IS_CONTAINER(widget)) {
|
||||
gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)Widget_setFont, font);
|
||||
}
|
||||
}
|
||||
|
||||
bool pWidget::enabled() {
|
||||
return gtk_widget_get_sensitive(gtkWidget);
|
||||
}
|
||||
|
||||
void pWidget::setEnabled(bool enabled) {
|
||||
gtk_widget_set_sensitive(gtkWidget, enabled);
|
||||
}
|
||||
|
||||
void pWidget::setFocused() {
|
||||
gtk_widget_grab_focus(gtkWidget);
|
||||
}
|
||||
|
||||
void pWidget::setFont(Font &font) {
|
||||
Widget_setFont(gtkWidget, font.p.gtkFont);
|
||||
}
|
||||
|
||||
void pWidget::setGeometry(const Geometry &geometry) {
|
||||
if(parentWindow) gtk_fixed_move(GTK_FIXED(parentWindow->formContainer), gtkWidget, geometry.x, geometry.y);
|
||||
unsigned width = (signed)geometry.width <= 0 ? 1U : geometry.width;
|
||||
unsigned height = (signed)geometry.height <= 0 ? 1U : geometry.height;
|
||||
gtk_widget_set_size_request(gtkWidget, width, height);
|
||||
}
|
||||
|
||||
void pWidget::setVisible(bool visible) {
|
||||
if(widget.state.abstract) visible = false;
|
||||
gtk_widget_set_visible(gtkWidget, visible);
|
||||
}
|
||||
|
||||
void pWidget::constructor() {
|
||||
parentWindow = 0;
|
||||
if(widget.state.abstract) gtkWidget = gtk_label_new("");
|
||||
}
|
|
@ -1,99 +1,237 @@
|
|||
static void Action_setFont(GtkWidget *widget, gpointer font);
|
||||
static void Widget_setFont(GtkWidget *widget, gpointer font);
|
||||
|
||||
static gint Window_close(Window *window) {
|
||||
if(window->onClose) {
|
||||
if(window->onClose()) window->setVisible(false);
|
||||
return true;
|
||||
}
|
||||
if(window->onClose) window->onClose();
|
||||
window->setVisible(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::create(unsigned x, unsigned y, unsigned width, unsigned height, const string &text) {
|
||||
object->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_move(GTK_WINDOW(object->widget), x, y);
|
||||
static gboolean Window_configure(Window *window) {
|
||||
if(gtk_widget_get_realized(window->p.widget) == false) return false;
|
||||
|
||||
gtk_window_set_title(GTK_WINDOW(object->widget), text);
|
||||
gtk_window_set_resizable(GTK_WINDOW(object->widget), false);
|
||||
gtk_widget_set_app_paintable(object->widget, true);
|
||||
//update geometry settings
|
||||
Display *display = XOpenDisplay(0);
|
||||
XWindowAttributes attributes, parentAttributes;
|
||||
XGetWindowAttributes(display, GDK_WINDOW_XID(window->p.widget->window), &attributes);
|
||||
X11Window rootWindow, parentWindow, *childWindow = 0;
|
||||
unsigned int childCount;
|
||||
XQueryTree(display, GDK_WINDOW_XID(window->p.widget->window), &rootWindow, &parentWindow, &childWindow, &childCount);
|
||||
XGetWindowAttributes(display, parentWindow, &parentAttributes);
|
||||
if(childWindow) XFree(childWindow);
|
||||
XCloseDisplay(display);
|
||||
|
||||
g_signal_connect_swapped(G_OBJECT(object->widget), "delete_event", G_CALLBACK(Window_close), (gpointer)this);
|
||||
settings.frameGeometryX = attributes.x;
|
||||
settings.frameGeometryY = attributes.y;
|
||||
settings.frameGeometryWidth = parentAttributes.width - attributes.width;
|
||||
settings.frameGeometryHeight = parentAttributes.height - attributes.height;
|
||||
|
||||
object->menuContainer = gtk_vbox_new(false, 0);
|
||||
gtk_container_add(GTK_CONTAINER(object->widget), object->menuContainer);
|
||||
gtk_widget_show(object->menuContainer);
|
||||
GtkAllocation menuAllocation, statusAllocation;
|
||||
gtk_widget_get_allocation(window->p.menu, &menuAllocation);
|
||||
gtk_widget_get_allocation(window->p.status, &statusAllocation);
|
||||
|
||||
object->menu = gtk_menu_bar_new();
|
||||
gtk_box_pack_start(GTK_BOX(object->menuContainer), object->menu, false, false, 0);
|
||||
if(menuAllocation.height > 1) settings.menuGeometryHeight = menuAllocation.height;
|
||||
if(statusAllocation.height > 1) settings.statusGeometryHeight = statusAllocation.height;
|
||||
|
||||
object->formContainer = gtk_fixed_new();
|
||||
gtk_widget_set_size_request(object->formContainer, width, height);
|
||||
gtk_box_pack_start(GTK_BOX(object->menuContainer), object->formContainer, true, true, 0);
|
||||
gtk_widget_show(object->formContainer);
|
||||
//calculate current window position
|
||||
signed eventX = parentAttributes.x + attributes.x;
|
||||
signed eventY = parentAttributes.y + attributes.y + window->p.menuHeight();
|
||||
unsigned eventWidth = attributes.width;
|
||||
unsigned eventHeight = attributes.height - window->p.menuHeight() - window->p.statusHeight();
|
||||
|
||||
object->statusContainer = gtk_event_box_new();
|
||||
object->status = gtk_statusbar_new();
|
||||
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(object->status), false);
|
||||
gtk_container_add(GTK_CONTAINER(object->statusContainer), object->status);
|
||||
gtk_box_pack_start(GTK_BOX(object->menuContainer), object->statusContainer, false, false, 0);
|
||||
gtk_widget_show(object->statusContainer);
|
||||
//move
|
||||
if(window->p.locked == false && window->state.fullScreen == false) {
|
||||
if(window->state.geometry.x != eventX || window->state.geometry.y != eventY) {
|
||||
window->state.geometry.x = eventX;
|
||||
window->state.geometry.y = eventY;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_realize(object->widget);
|
||||
if(window->onMove) window->onMove();
|
||||
|
||||
//size
|
||||
if(window->p.locked == false && window->state.fullScreen == false) {
|
||||
if(window->state.geometry.width != eventWidth || window->state.geometry.height != eventHeight) {
|
||||
window->state.geometry.width = eventWidth;
|
||||
window->state.geometry.height = eventHeight;
|
||||
}
|
||||
}
|
||||
|
||||
foreach(layout, window->state.layout) {
|
||||
Geometry geometry = window->geometry();
|
||||
geometry.x = geometry.y = 0;
|
||||
layout.setGeometry(geometry);
|
||||
}
|
||||
|
||||
if(window->onSize) window->onSize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Window::focused() {
|
||||
return gtk_window_is_active(GTK_WINDOW(object->widget));
|
||||
void pWindow::append(Layout &layout) {
|
||||
layout.setParent(window);
|
||||
Geometry geometry = this->geometry();
|
||||
geometry.x = geometry.y = 0;
|
||||
layout.setGeometry(geometry);
|
||||
}
|
||||
|
||||
void Window::setFocused() {
|
||||
gtk_window_present(GTK_WINDOW(object->widget));
|
||||
void pWindow::append(Menu &subMenu) {
|
||||
if(window.state.menuFont) subMenu.p.setFont(*window.state.menuFont);
|
||||
gtk_menu_bar_append(menu, subMenu.p.widget);
|
||||
gtk_widget_show(subMenu.p.widget);
|
||||
}
|
||||
|
||||
Geometry Window::geometry() {
|
||||
gint x, y, width, height;
|
||||
gtk_window_get_position(GTK_WINDOW(object->widget), &x, &y);
|
||||
gtk_widget_get_size_request(object->formContainer, &width, &height);
|
||||
return Geometry(x, y, width, height);
|
||||
void pWindow::append(Widget &widget) {
|
||||
widget.p.parentWindow = this;
|
||||
if(!widget.state.font && window.state.widgetFont) {
|
||||
widget.setFont(*window.state.widgetFont);
|
||||
}
|
||||
gtk_fixed_put(GTK_FIXED(formContainer), widget.p.gtkWidget, 0, 0);
|
||||
widget.setVisible();
|
||||
}
|
||||
|
||||
void Window::setGeometry(unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
gtk_window_move(GTK_WINDOW(object->widget), x, y);
|
||||
gtk_widget_set_size_request(object->formContainer, width, height);
|
||||
Geometry pWindow::frameMargin() {
|
||||
if(window.state.fullScreen) return { 0, menuHeight(), 0, menuHeight() + statusHeight() };
|
||||
return {
|
||||
settings.frameGeometryX,
|
||||
settings.frameGeometryY + menuHeight(),
|
||||
settings.frameGeometryWidth,
|
||||
settings.frameGeometryHeight + menuHeight() + statusHeight()
|
||||
};
|
||||
}
|
||||
|
||||
void Window::setDefaultFont(Font &font) {
|
||||
window->defaultFont = &font;
|
||||
bool pWindow::focused() {
|
||||
return gtk_window_is_active(GTK_WINDOW(widget));
|
||||
}
|
||||
|
||||
void Window::setFont(Font &font) {
|
||||
Widget_setFont(object->status, font.font->font);
|
||||
Geometry pWindow::geometry() {
|
||||
if(window.state.fullScreen == true) {
|
||||
return { 0, menuHeight(), OS::desktopGeometry().width, OS::desktopGeometry().height - menuHeight() - statusHeight() };
|
||||
};
|
||||
return window.state.geometry;
|
||||
}
|
||||
|
||||
void Window::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
void pWindow::setBackgroundColor(uint8_t red, uint8_t green, uint8_t blue) {
|
||||
GdkColor color;
|
||||
color.pixel = (red << 16) | (green << 8) | (blue << 0);
|
||||
color.red = (red << 8) | (red << 0);
|
||||
color.green = (green << 8) | (green << 0);
|
||||
color.blue = (blue << 8) | (blue << 0);
|
||||
gtk_widget_modify_bg(object->widget, GTK_STATE_NORMAL, &color);
|
||||
gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
|
||||
}
|
||||
|
||||
void Window::setTitle(const string &text) {
|
||||
gtk_window_set_title(GTK_WINDOW(object->widget), text);
|
||||
void pWindow::setFocused() {
|
||||
gtk_window_present(GTK_WINDOW(widget));
|
||||
}
|
||||
|
||||
void Window::setStatusText(const string &text) {
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(object->status), 1);
|
||||
gtk_statusbar_push(GTK_STATUSBAR(object->status), 1, text);
|
||||
void pWindow::setFullScreen(bool fullScreen) {
|
||||
if(fullScreen == false) {
|
||||
gtk_window_unfullscreen(GTK_WINDOW(widget));
|
||||
gtk_window_set_resizable(GTK_WINDOW(widget), window.state.resizable);
|
||||
gtk_window_set_decorated(GTK_WINDOW(widget), true);
|
||||
locked = true;
|
||||
for(unsigned n = 0; n < 4; n++) {
|
||||
setGeometry(window.state.geometry);
|
||||
gtk_widget_set_size_request(widget, -1, -1);
|
||||
OS::processEvents();
|
||||
usleep(2000);
|
||||
}
|
||||
locked = false;
|
||||
} else {
|
||||
gtk_window_fullscreen(GTK_WINDOW(widget));
|
||||
gtk_window_set_decorated(GTK_WINDOW(widget), false);
|
||||
gtk_widget_set_size_request(widget, OS::desktopGeometry().width, OS::desktopGeometry().height);
|
||||
gtk_window_set_resizable(GTK_WINDOW(widget), false);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setMenuVisible(bool visible) {
|
||||
gtk_widget_set_visible(object->menu, visible);
|
||||
void pWindow::setGeometry(const Geometry &geometry) {
|
||||
Geometry margin = frameMargin();
|
||||
gtk_window_move(GTK_WINDOW(widget), geometry.x - margin.x, geometry.y - margin.y);
|
||||
gtk_window_resize(GTK_WINDOW(widget), 1, 1);
|
||||
gtk_widget_set_size_request(formContainer, geometry.width, geometry.height);
|
||||
foreach(layout, window.state.layout) {
|
||||
Geometry geometry = this->geometry();
|
||||
geometry.x = geometry.y = 0;
|
||||
layout.setGeometry(geometry);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::setStatusVisible(bool visible) {
|
||||
gtk_widget_set_visible(object->status, visible);
|
||||
void pWindow::setMenuFont(Font &font) {
|
||||
foreach(item, window.state.menu) item.p.setFont(font);
|
||||
}
|
||||
|
||||
Window::Window() {
|
||||
window = new Window::Data;
|
||||
window->defaultFont = 0;
|
||||
void pWindow::setMenuVisible(bool visible) {
|
||||
gtk_widget_set_visible(menu, visible);
|
||||
}
|
||||
|
||||
void pWindow::setResizable(bool resizable) {
|
||||
gtk_window_set_resizable(GTK_WINDOW(widget), resizable);
|
||||
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), resizable);
|
||||
}
|
||||
|
||||
void pWindow::setStatusFont(Font &font) {
|
||||
Widget_setFont(status, (gpointer)font.p.gtkFont);
|
||||
}
|
||||
|
||||
void pWindow::setStatusText(const string &text) {
|
||||
gtk_statusbar_pop(GTK_STATUSBAR(status), 1);
|
||||
gtk_statusbar_push(GTK_STATUSBAR(status), 1, text);
|
||||
}
|
||||
|
||||
void pWindow::setStatusVisible(bool visible) {
|
||||
gtk_widget_set_visible(status, visible);
|
||||
}
|
||||
|
||||
void pWindow::setTitle(const string &text) {
|
||||
gtk_window_set_title(GTK_WINDOW(widget), text);
|
||||
}
|
||||
|
||||
void pWindow::setVisible(bool visible) {
|
||||
gtk_widget_set_visible(widget, visible);
|
||||
}
|
||||
|
||||
void pWindow::setWidgetFont(Font &font) {
|
||||
foreach(item, window.state.widget) {
|
||||
if(!item.state.font) item.setFont(font);
|
||||
}
|
||||
}
|
||||
|
||||
void pWindow::constructor() {
|
||||
widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_resizable(GTK_WINDOW(widget), true);
|
||||
gtk_widget_set_app_paintable(widget, true);
|
||||
gtk_widget_add_events(widget, GDK_CONFIGURE);
|
||||
|
||||
menuContainer = gtk_vbox_new(false, 0);
|
||||
gtk_container_add(GTK_CONTAINER(widget), menuContainer);
|
||||
gtk_widget_show(menuContainer);
|
||||
|
||||
menu = gtk_menu_bar_new();
|
||||
gtk_box_pack_start(GTK_BOX(menuContainer), menu, false, false, 0);
|
||||
|
||||
formContainer = gtk_fixed_new();
|
||||
gtk_box_pack_start(GTK_BOX(menuContainer), formContainer, true, true, 0);
|
||||
gtk_widget_show(formContainer);
|
||||
|
||||
statusContainer = gtk_event_box_new();
|
||||
status = gtk_statusbar_new();
|
||||
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(status), true);
|
||||
gtk_container_add(GTK_CONTAINER(statusContainer), status);
|
||||
gtk_box_pack_start(GTK_BOX(menuContainer), statusContainer, false, false, 0);
|
||||
gtk_widget_show(statusContainer);
|
||||
|
||||
setTitle("");
|
||||
setGeometry(window.state.geometry);
|
||||
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "delete-event", G_CALLBACK(Window_close), (gpointer)&window);
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "configure-event", G_CALLBACK(Window_configure), (gpointer)&window);
|
||||
}
|
||||
|
||||
unsigned pWindow::menuHeight() {
|
||||
return window.state.menuVisible ? settings.menuGeometryHeight : 0;
|
||||
}
|
||||
|
||||
unsigned pWindow::statusHeight() {
|
||||
return window.state.statusVisible ? settings.statusGeometryHeight : 0;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
namespace nall {
|
||||
template<int bits> inline unsigned uclamp(const unsigned x) {
|
||||
enum { y = (1U << bits) - 1 };
|
||||
enum { y = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
|
||||
return y + ((x - y) & -(x < y)); //min(x, y);
|
||||
}
|
||||
|
||||
template<int bits> inline unsigned uclip(const unsigned x) {
|
||||
enum { m = (1U << bits) - 1 };
|
||||
enum { m = (1U << (bits - 1)) + ((1U << (bits - 1)) - 1) };
|
||||
return (x & m);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,9 +46,9 @@ namespace nall {
|
|||
void set(string s) {
|
||||
switch(type) {
|
||||
case boolean_t: *(bool*)data = (s == "true"); break;
|
||||
case signed_t: *(signed*)data = strsigned(s); break;
|
||||
case unsigned_t: *(unsigned*)data = strunsigned(s); break;
|
||||
case double_t: *(double*)data = strdouble(s); break;
|
||||
case signed_t: *(signed*)data = integer(s); break;
|
||||
case unsigned_t: *(unsigned*)data = decimal(s); break;
|
||||
case double_t: *(double*)data = fp(s); break;
|
||||
case string_t: s.trim("\""); *(string*)data = s; break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace nall {
|
|||
struct library {
|
||||
bool opened() const { return handle; }
|
||||
bool open(const char*, const char* = "");
|
||||
bool open_absolute(const char*);
|
||||
void* sym(const char*);
|
||||
void close();
|
||||
|
||||
|
@ -40,6 +41,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(name, RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return dlsym((void*)handle, name);
|
||||
|
@ -58,6 +65,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(name, RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return dlsym((void*)handle, name);
|
||||
|
@ -76,6 +89,12 @@ namespace nall {
|
|||
return handle;
|
||||
}
|
||||
|
||||
inline bool library::open_absolute(const char *name) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)LoadLibraryW(utf16_t(name));
|
||||
return handle;
|
||||
}
|
||||
|
||||
inline void* library::sym(const char *name) {
|
||||
if(!handle) return 0;
|
||||
return (void*)GetProcAddress((HMODULE)handle, name);
|
||||
|
|
|
@ -5,8 +5,14 @@
|
|||
#include <nall/concept.hpp>
|
||||
|
||||
#undef foreach
|
||||
#define foreach(iter, object) \
|
||||
|
||||
#define foreach2(iter, object) foreach3(iter, object, foreach_counter)
|
||||
#define foreach3(iter, object, foreach_counter) \
|
||||
for(unsigned foreach_counter = 0, foreach_limit = container_size(object), foreach_once = 0, foreach_broken = 0; foreach_counter < foreach_limit && foreach_broken == 0; foreach_counter++, foreach_once = 0) \
|
||||
for(auto &iter = object[foreach_counter]; foreach_once == 0 && (foreach_broken = 1); foreach_once++, foreach_broken = 0)
|
||||
|
||||
#define foreach_impl(...) foreach_decl(__VA_ARGS__, foreach3(__VA_ARGS__), foreach2(__VA_ARGS__), foreach_too_few_arguments)
|
||||
#define foreach_decl(_1, _2, _3, N, ...) N
|
||||
#define foreach(...) foreach_impl(__VA_ARGS__)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace nall {
|
|||
};
|
||||
|
||||
template<typename L> struct lambda : container {
|
||||
L object;
|
||||
mutable L object;
|
||||
R operator()(P... p) const { return object(std::forward<P>(p)...); }
|
||||
container* copy() const { return new lambda(object); }
|
||||
lambda(const L& object) : object(object) {}
|
||||
|
@ -46,7 +46,7 @@ namespace nall {
|
|||
return *this;
|
||||
}
|
||||
|
||||
function(const function &source) { operator=(source); }
|
||||
function(const function &source) : callback(0) { operator=(source); }
|
||||
function() : callback(0) {}
|
||||
function(void *function) : callback(0) { if(function) callback = new global((R (*)(P...))function); }
|
||||
function(R (*function)(P...)) { callback = new global(function); }
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
#ifndef NALL_GAMEBOY_CARTRIDGE_HPP
|
||||
#define NALL_GAMEBOY_CARTRIDGE_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
class GameBoyCartridge {
|
||||
public:
|
||||
string xml;
|
||||
inline GameBoyCartridge(const uint8_t *data, unsigned size);
|
||||
|
||||
//private:
|
||||
struct Information {
|
||||
string mapper;
|
||||
bool ram;
|
||||
bool battery;
|
||||
bool rtc;
|
||||
bool rumble;
|
||||
|
||||
unsigned romsize;
|
||||
unsigned ramsize;
|
||||
} info;
|
||||
};
|
||||
|
||||
GameBoyCartridge::GameBoyCartridge(const uint8_t *romdata, unsigned romsize) {
|
||||
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
if(romsize < 0x4000) return;
|
||||
|
||||
info.mapper = "unknown";
|
||||
info.ram = false;
|
||||
info.battery = false;
|
||||
info.rtc = false;
|
||||
info.rumble = false;
|
||||
|
||||
info.romsize = 0;
|
||||
info.ramsize = 0;
|
||||
|
||||
switch(romdata[0x0147]) {
|
||||
case 0x00: info.mapper = "none"; break;
|
||||
case 0x01: info.mapper = "MBC1"; break;
|
||||
case 0x02: info.mapper = "MBC1"; info.ram = true; break;
|
||||
case 0x03: info.mapper = "MBC1"; info.ram = true; info.battery = true; break;
|
||||
case 0x05: info.mapper = "MBC2"; info.ram = true; break;
|
||||
case 0x06: info.mapper = "MBC2"; info.ram = true; info.battery = true; break;
|
||||
case 0x08: info.mapper = "none"; info.ram = true; break;
|
||||
case 0x09: info.mapper = "MBC0"; info.ram = true; info.battery = true; break;
|
||||
case 0x0b: info.mapper = "MMM01"; break;
|
||||
case 0x0c: info.mapper = "MMM01"; info.ram = true; break;
|
||||
case 0x0d: info.mapper = "MMM01"; info.ram = true; info.battery = true; break;
|
||||
case 0x0f: info.mapper = "MBC3"; info.rtc = true; info.battery = true; break;
|
||||
case 0x10: info.mapper = "MBC3"; info.rtc = true; info.ram = true; info.battery = true; break;
|
||||
case 0x11: info.mapper = "MBC3"; break;
|
||||
case 0x12: info.mapper = "MBC3"; info.ram = true; break;
|
||||
case 0x13: info.mapper = "MBC3"; info.ram = true; info.battery = true; break;
|
||||
case 0x19: info.mapper = "MBC5"; break;
|
||||
case 0x1a: info.mapper = "MBC5"; info.ram = true; break;
|
||||
case 0x1b: info.mapper = "MBC5"; info.ram = true; info.battery = true; break;
|
||||
case 0x1c: info.mapper = "MBC5"; info.rumble = true; break;
|
||||
case 0x1d: info.mapper = "MBC5"; info.rumble = true; info.ram = true; break;
|
||||
case 0x1e: info.mapper = "MBC5"; info.rumble = true; info.ram = true; info.battery = true; break;
|
||||
case 0xfc: break; //Pocket Camera
|
||||
case 0xfd: break; //Bandai TAMA5
|
||||
case 0xfe: info.mapper = "HuC3"; break;
|
||||
case 0xff: info.mapper = "HuC1"; info.ram = true; info.battery = true; break;
|
||||
}
|
||||
|
||||
switch(romdata[0x0148]) { default:
|
||||
case 0x00: info.romsize = 2 * 16 * 1024; break;
|
||||
case 0x01: info.romsize = 4 * 16 * 1024; break;
|
||||
case 0x02: info.romsize = 8 * 16 * 1024; break;
|
||||
case 0x03: info.romsize = 16 * 16 * 1024; break;
|
||||
case 0x04: info.romsize = 32 * 16 * 1024; break;
|
||||
case 0x05: info.romsize = 64 * 16 * 1024; break;
|
||||
case 0x06: info.romsize = 128 * 16 * 1024; break;
|
||||
case 0x07: info.romsize = 256 * 16 * 1024; break;
|
||||
case 0x52: info.romsize = 72 * 16 * 1024; break;
|
||||
case 0x53: info.romsize = 80 * 16 * 1024; break;
|
||||
case 0x54: info.romsize = 96 * 16 * 1024; break;
|
||||
}
|
||||
|
||||
switch(romdata[0x0149]) { default:
|
||||
case 0x00: info.ramsize = 0 * 1024; break;
|
||||
case 0x01: info.ramsize = 2 * 1024; break;
|
||||
case 0x02: info.ramsize = 8 * 1024; break;
|
||||
case 0x03: info.ramsize = 32 * 1024; break;
|
||||
}
|
||||
|
||||
if(info.mapper == "MBC2") info.ramsize = 512; //512 x 4-bit
|
||||
|
||||
xml << "<cartridge mapper='" << info.mapper << "'";
|
||||
if(info.rtc) xml << " rtc='true'";
|
||||
if(info.rumble) xml << " rumble='true'";
|
||||
xml << ">\n";
|
||||
|
||||
xml << " <rom size='" << hex(romsize) << "'/>\n"; //TODO: trust/check info.romsize?
|
||||
|
||||
if(info.ramsize > 0)
|
||||
xml << " <ram size='" << hex(info.ramsize) << "' battery='" << info.battery << "'/>\n";
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -92,7 +92,7 @@ struct Keyboard {
|
|||
string s(name);
|
||||
if(!strbegin(name, "KB")) return 0;
|
||||
s.ltrim("KB");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
@ -189,7 +189,7 @@ struct Mouse {
|
|||
string s(name);
|
||||
if(!strbegin(name, "MS")) return 0;
|
||||
s.ltrim("MS");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
@ -313,7 +313,7 @@ struct Joypad {
|
|||
string s(name);
|
||||
if(!strbegin(name, "JP")) return 0;
|
||||
s.ltrim("JP");
|
||||
unsigned id = strunsigned(s);
|
||||
unsigned id = decimal(s);
|
||||
auto pos = strpos(s, "::");
|
||||
if(!pos) return 0;
|
||||
s = substr(s, pos() + 2);
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef NALL_PUBLIC_CAST_HPP
|
||||
#define NALL_PUBLIC_CAST_HPP
|
||||
|
||||
//this is a proof-of-concept-*only* C++ access-privilege elevation exploit.
|
||||
//this code is 100% legal C++, per C++98 section 14.7.2 paragraph 8:
|
||||
//"access checking rules do not apply to names in explicit instantiations."
|
||||
//usage example:
|
||||
|
||||
//struct N { typedef void (Class::*)(); };
|
||||
//template class public_cast<N, &Class::Reference>;
|
||||
//(class.*public_cast<N>::value);
|
||||
|
||||
//Class::Reference may be public, protected or private
|
||||
//Class::Reference may be a function, object or variable
|
||||
|
||||
namespace nall {
|
||||
template<typename T, typename T::type... P> struct public_cast;
|
||||
|
||||
template<typename T> struct public_cast<T> {
|
||||
static typename T::type value;
|
||||
};
|
||||
|
||||
template<typename T> typename T::type public_cast<T>::value;
|
||||
|
||||
template<typename T, typename T::type P> struct public_cast<T, P> {
|
||||
static typename T::type value;
|
||||
};
|
||||
|
||||
template<typename T, typename T::type P> typename T::type public_cast<T, P>::value = public_cast<T>::value = P;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,103 @@
|
|||
#ifndef NALL_REFERENCE_ARRAY_HPP
|
||||
#define NALL_REFERENCE_ARRAY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <nall/bit.hpp>
|
||||
#include <nall/concept.hpp>
|
||||
|
||||
namespace nall {
|
||||
template<typename T> struct reference_array {
|
||||
protected:
|
||||
typedef typename std::remove_reference<T>::type *Tptr;
|
||||
Tptr *pool;
|
||||
unsigned poolsize, buffersize;
|
||||
|
||||
public:
|
||||
unsigned size() const { return buffersize; }
|
||||
unsigned capacity() const { return poolsize; }
|
||||
|
||||
void reset() {
|
||||
if(pool) free(pool);
|
||||
pool = 0;
|
||||
poolsize = 0;
|
||||
buffersize = 0;
|
||||
}
|
||||
|
||||
void reserve(unsigned newsize) {
|
||||
if(newsize == poolsize) return;
|
||||
|
||||
pool = (Tptr*)realloc(pool, newsize * sizeof(T));
|
||||
poolsize = newsize;
|
||||
buffersize = min(buffersize, newsize);
|
||||
}
|
||||
|
||||
void resize(unsigned newsize) {
|
||||
if(newsize > poolsize) reserve(bit::round(newsize));
|
||||
buffersize = newsize;
|
||||
}
|
||||
|
||||
void append(const T data) {
|
||||
unsigned index = buffersize++;
|
||||
if(index >= poolsize) resize(index + 1);
|
||||
pool[index] = &data;
|
||||
}
|
||||
|
||||
template<typename... Args> reference_array(Args&... args) : pool(0), poolsize(0), buffersize(0) {
|
||||
construct(args...);
|
||||
}
|
||||
|
||||
~reference_array() {
|
||||
reset();
|
||||
}
|
||||
|
||||
reference_array& operator=(const reference_array &source) {
|
||||
if(pool) free(pool);
|
||||
buffersize = source.buffersize;
|
||||
poolsize = source.poolsize;
|
||||
pool = (Tptr*)malloc(sizeof(T) * poolsize);
|
||||
memcpy(pool, source.pool, sizeof(T) * buffersize);
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference_array& operator=(const reference_array &&source) {
|
||||
if(pool) free(pool);
|
||||
pool = source.pool;
|
||||
poolsize = source.poolsize;
|
||||
buffersize = source.buffersize;
|
||||
source.pool = 0;
|
||||
source.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline T operator[](unsigned index) {
|
||||
if(index >= buffersize) throw "reference_array[] out of bounds";
|
||||
return *pool[index];
|
||||
}
|
||||
|
||||
inline const T operator[](unsigned index) const {
|
||||
if(index >= buffersize) throw "reference_array[] out of bounds";
|
||||
return *pool[index];
|
||||
}
|
||||
|
||||
private:
|
||||
void construct() {
|
||||
}
|
||||
|
||||
void construct(const reference_array &source) {
|
||||
operator=(source);
|
||||
}
|
||||
|
||||
void construct(const reference_array &&source) {
|
||||
operator=(std::move(source));
|
||||
}
|
||||
|
||||
template<typename... Args> void construct(T data, Args&... args) {
|
||||
append(data);
|
||||
construct(args...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> struct has_size<reference_array<T>> { enum { value = true }; };
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,13 +1,12 @@
|
|||
#ifndef NALL_SNES_INFO_HPP
|
||||
#define NALL_SNES_INFO_HPP
|
||||
#ifndef NALL_SNES_CARTRIDGE_HPP
|
||||
#define NALL_SNES_CARTRIDGE_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
class snes_information {
|
||||
class SNESCartridge {
|
||||
public:
|
||||
string xml_memory_map;
|
||||
|
||||
inline snes_information(const uint8_t *data, unsigned size);
|
||||
string xmlMemoryMap;
|
||||
inline SNESCartridge(const uint8_t *data, unsigned size);
|
||||
|
||||
//private:
|
||||
inline void read_header(const uint8_t *data, unsigned size);
|
||||
|
@ -106,30 +105,30 @@ public:
|
|||
bool has_st018;
|
||||
};
|
||||
|
||||
snes_information::snes_information(const uint8_t *data, unsigned size) {
|
||||
SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
read_header(data, size);
|
||||
|
||||
string xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
|
||||
if(type == TypeBsx) {
|
||||
xml << "<cartridge/>";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TypeSufamiTurbo) {
|
||||
xml << "<cartridge/>";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TypeGameBoy) {
|
||||
xml << "<cartridge rtc='" << gameboy_has_rtc(data, size) << "'>\n";
|
||||
if(gameboy_ram_size(data, size) > 0) {
|
||||
xml << " <ram size='" << strhex(gameboy_ram_size(data, size)) << "'/>\n";
|
||||
xml << " <ram size='" << hex(gameboy_ram_size(data, size)) << "'/>\n";
|
||||
}
|
||||
xml << "</cartridge>\n";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -146,23 +145,19 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='00-7f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-ff:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <supergameboy revision='1'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <icd2 revision='1'>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </supergameboy>\n";
|
||||
xml << " </icd2>\n";
|
||||
} else if(type == TypeSuperGameBoy2Bios) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-7f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-ff:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <supergameboy revision='2'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <icd2 revision='2'>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </supergameboy>\n";
|
||||
xml << " </icd2>\n";
|
||||
} else if(has_spc7110) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='shadow' address='00-0f:8000-ffff'/>\n";
|
||||
|
@ -172,9 +167,9 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
xml << " <spc7110>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <map address='d0-ff:0000-ffff' offset='100000' size='" << strhex(size - 0x100000) << "'/>\n";
|
||||
xml << " <map address='d0-ff:0000-ffff' offset='100000' size='" << hex(size - 0x100000) << "'/>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='30:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -199,7 +194,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -220,7 +215,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -238,7 +233,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='70-7f:0000-7fff'/>\n";
|
||||
|
@ -253,7 +248,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </rom>\n";
|
||||
|
||||
if(ram_size > 0) {
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
if((rom_size > 0x200000) || (ram_size > 32 * 1024)) {
|
||||
|
@ -271,7 +266,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-df:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:6000-7fff' size='2000'/>\n";
|
||||
xml << " <map mode='linear' address='60-7f:0000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:6000-7fff' size='2000'/>\n";
|
||||
|
@ -284,19 +279,23 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </superfx>\n";
|
||||
} else if(mapper == SA1ROM) {
|
||||
xml << " <sa1>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map mode='direct' address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram>\n";
|
||||
xml << " <map mode='direct' address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='direct' address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <iram size='800'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:3000-37ff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:3000-37ff'/>\n";
|
||||
xml << " </iram>\n";
|
||||
xml << " <bwram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <bwram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='40-4f:0000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </bwram>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:2200-23ff'/>\n";
|
||||
|
@ -310,7 +309,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='linear' address='80-9f:8000-ffff' offset='200000'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:8000-ffff' offset='100000'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='70-7f:0000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='f0-ff:0000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -326,7 +325,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " <map mode='shadow' address='80-9f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-df:0000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram size='" << strhex(ram_size) << "'>\n";
|
||||
xml << " <ram size='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='20-3f:6000-7fff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:6000-7fff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
|
@ -339,11 +338,14 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
xml << " </slot>\n";
|
||||
xml << " </bsx>\n";
|
||||
} else if(mapper == BSXROM) {
|
||||
xml << " <rom>\n";
|
||||
xml << " <map mode='linear' address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='80-bf:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <bsx>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <map address='00-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='80-bf:8000-ffff'/>\n";
|
||||
xml << " <map address='40-7f:0000-ffff'/>\n";
|
||||
xml << " <map address='c0-ff:0000-ffff'/>\n";
|
||||
xml << " <map address='20-3f:6000-7fff'/>\n";
|
||||
xml << " </mcu>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:5000-5fff'/>\n";
|
||||
xml << " <map address='80-bf:5000-5fff'/>\n";
|
||||
|
@ -380,10 +382,8 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_srtc) {
|
||||
xml << " <srtc>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:2800-2801'/>\n";
|
||||
xml << " <map address='80-bf:2800-2801'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </srtc>\n";
|
||||
}
|
||||
|
||||
|
@ -401,15 +401,13 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_cx4) {
|
||||
xml << " <cx4>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </cx4>\n";
|
||||
}
|
||||
|
||||
if(has_dsp1) {
|
||||
xml << " <necdsp program='DSP-1B'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp1b.bin' sha256='4d42db0f36faef263d6b93f508e8c1c4ae8fc2605fd35e3390ecc02905cd420c'>\n";
|
||||
if(dsp1_mapper == DSP1LoROM1MB) {
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
|
@ -442,7 +440,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp2) {
|
||||
xml << " <necdsp program='DSP-2'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp2.bin' sha256='5efbdf96ed0652790855225964f3e90e6a4d466cfa64df25b110933c6cf94ea1'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
|
@ -455,7 +453,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp3) {
|
||||
xml << " <necdsp program='DSP-3'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp3.bin' sha256='2e635f72e4d4681148bc35429421c9b946e4f407590e74e31b93b8987b63ba90'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
|
@ -468,7 +466,7 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
|
||||
if(has_dsp4) {
|
||||
xml << " <necdsp program='DSP-4'>\n";
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp4.bin' sha256='63ede17322541c191ed1fdf683872554a0a57306496afc43c59de7c01a6e764a'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='30-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='b0-bf:8000-bfff'/>\n";
|
||||
|
@ -482,46 +480,57 @@ snes_information::snes_information(const uint8_t *data, unsigned size) {
|
|||
|
||||
if(has_obc1) {
|
||||
xml << " <obc1>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-bf:6000-7fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </obc1>\n";
|
||||
}
|
||||
|
||||
if(has_st010) {
|
||||
xml << " <setadsp program='ST-0010'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <necdsp revision='upd96050' frequency='10000000' program='st0010.bin' sha256='55c697e864562445621cdf8a7bf6e84ae91361e393d382a3704e9aa55559041e'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='60:0000'/>\n";
|
||||
xml << " <map address='e0:0000'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='60:0001'/>\n";
|
||||
xml << " <map address='e0:0001'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " <dp>\n";
|
||||
xml << " <map address='68-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e8-ef:0000-0fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setadsp>\n";
|
||||
xml << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_st011) {
|
||||
//ST-0011 addresses not verified; chip is unsupported
|
||||
xml << " <setadsp program='ST-0011'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <necdsp revision='upd96050' frequency='15000000' program='st0011.bin' sha256='651b82a1e26c4fa8dd549e91e7f923012ed2ca54c1d9fd858655ab30679c2f0e'>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='60:0000'/>\n";
|
||||
xml << " <map address='e0:0000'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='60:0001'/>\n";
|
||||
xml << " <map address='e0:0001'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " <dp>\n";
|
||||
xml << " <map address='68-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e8-ef:0000-0fff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setadsp>\n";
|
||||
xml << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_st018) {
|
||||
xml << " <setarisc program='ST-0018'>\n";
|
||||
xml << " <mmio>\n";
|
||||
xml << " <map address='00-3f:3800-38ff'/>\n";
|
||||
xml << " <map address='80-bf:3800-38ff'/>\n";
|
||||
xml << " </mmio>\n";
|
||||
xml << " </setarisc>\n";
|
||||
}
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xml_memory_map = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
void snes_information::read_header(const uint8_t *data, unsigned size) {
|
||||
void SNESCartridge::read_header(const uint8_t *data, unsigned size) {
|
||||
type = TypeUnknown;
|
||||
mapper = LoROM;
|
||||
dsp1_mapper = DSP1Unmapped;
|
||||
|
@ -558,6 +567,11 @@ void snes_information::read_header(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
}
|
||||
|
||||
if(size < 32768) {
|
||||
type = TypeUnknown;
|
||||
return;
|
||||
}
|
||||
|
||||
const unsigned index = find_header(data, size);
|
||||
const uint8_t mapperid = data[index + Mapper];
|
||||
const uint8_t rom_type = data[index + RomType];
|
||||
|
@ -744,7 +758,7 @@ void snes_information::read_header(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned snes_information::find_header(const uint8_t *data, unsigned size) {
|
||||
unsigned SNESCartridge::find_header(const uint8_t *data, unsigned size) {
|
||||
unsigned score_lo = score_header(data, size, 0x007fc0);
|
||||
unsigned score_hi = score_header(data, size, 0x00ffc0);
|
||||
unsigned score_ex = score_header(data, size, 0x40ffc0);
|
||||
|
@ -759,7 +773,7 @@ unsigned snes_information::find_header(const uint8_t *data, unsigned size) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned snes_information::score_header(const uint8_t *data, unsigned size, unsigned addr) {
|
||||
unsigned SNESCartridge::score_header(const uint8_t *data, unsigned size, unsigned addr) {
|
||||
if(size < addr + 64) return 0; //image too small to contain header at this location?
|
||||
int score = 0;
|
||||
|
||||
|
@ -840,7 +854,7 @@ unsigned snes_information::score_header(const uint8_t *data, unsigned size, unsi
|
|||
return score;
|
||||
}
|
||||
|
||||
unsigned snes_information::gameboy_ram_size(const uint8_t *data, unsigned size) {
|
||||
unsigned SNESCartridge::gameboy_ram_size(const uint8_t *data, unsigned size) {
|
||||
if(size < 512) return 0;
|
||||
switch(data[0x0149]) {
|
||||
case 0x00: return 0 * 1024;
|
||||
|
@ -853,7 +867,7 @@ unsigned snes_information::gameboy_ram_size(const uint8_t *data, unsigned size)
|
|||
}
|
||||
}
|
||||
|
||||
bool snes_information::gameboy_has_rtc(const uint8_t *data, unsigned size) {
|
||||
bool SNESCartridge::gameboy_has_rtc(const uint8_t *data, unsigned size) {
|
||||
if(size < 512) return false;
|
||||
if(data[0x0147] == 0x0f ||data[0x0147] == 0x10) return true;
|
||||
return false;
|
|
@ -0,0 +1,458 @@
|
|||
#ifndef NALL_SNES_CPU_HPP
|
||||
#define NALL_SNES_CPU_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct SNESCPU {
|
||||
enum : unsigned {
|
||||
Implied, //
|
||||
Constant, //#$00
|
||||
AccumConstant, //#$00
|
||||
IndexConstant, //#$00
|
||||
Direct, //$00
|
||||
DirectX, //$00,x
|
||||
DirectY, //$00,y
|
||||
IDirect, //($00)
|
||||
IDirectX, //($00,x)
|
||||
IDirectY, //($00),y
|
||||
ILDirect, //[$00]
|
||||
ILDirectY, //[$00],y
|
||||
Address, //$0000
|
||||
AddressX, //$0000,x
|
||||
AddressY, //$0000,y
|
||||
IAddressX, //($0000,x)
|
||||
ILAddress, //[$0000]
|
||||
PAddress, //PBR:$0000
|
||||
PIAddress, //PBR:($0000)
|
||||
Long, //$000000
|
||||
LongX, //$000000,x
|
||||
Stack, //$00,s
|
||||
IStackY, //($00,s),y
|
||||
BlockMove, //$00,$00
|
||||
RelativeShort, //+/- $00
|
||||
RelativeLong, //+/- $0000
|
||||
};
|
||||
|
||||
struct OpcodeInfo {
|
||||
char name[4];
|
||||
unsigned mode;
|
||||
};
|
||||
|
||||
static const OpcodeInfo opcodeInfo[256];
|
||||
|
||||
static unsigned getOpcodeLength(bool accum, bool index, uint8_t opcode);
|
||||
static string disassemble(unsigned pc, bool accum, bool index, uint8_t opcode, uint8_t pl, uint8_t ph, uint8_t pb);
|
||||
};
|
||||
|
||||
const SNESCPU::OpcodeInfo SNESCPU::opcodeInfo[256] = {
|
||||
//0x00 - 0x0f
|
||||
{ "brk", Constant },
|
||||
{ "ora", IDirectX },
|
||||
{ "cop", Constant },
|
||||
{ "ora", Stack },
|
||||
|
||||
{ "tsb", Direct },
|
||||
{ "ora", Direct },
|
||||
{ "asl", Direct },
|
||||
{ "ora", ILDirect },
|
||||
|
||||
{ "php", Implied },
|
||||
{ "ora", AccumConstant },
|
||||
{ "asl", Implied },
|
||||
{ "phd", Implied },
|
||||
|
||||
{ "tsb", Address },
|
||||
{ "ora", Address },
|
||||
{ "asl", Address },
|
||||
{ "ora", Long },
|
||||
|
||||
//0x10 - 0x1f
|
||||
{ "bpl", RelativeShort },
|
||||
{ "ora", IDirectY },
|
||||
{ "ora", IDirect },
|
||||
{ "ora", IStackY },
|
||||
|
||||
{ "trb", Direct },
|
||||
{ "ora", DirectX },
|
||||
{ "asl", DirectX },
|
||||
{ "ora", ILDirectY },
|
||||
|
||||
{ "clc", Implied },
|
||||
{ "ora", AddressY },
|
||||
{ "inc", Implied },
|
||||
{ "tcs", Implied },
|
||||
|
||||
{ "trb", Address },
|
||||
{ "ora", AddressX },
|
||||
{ "asl", AddressX },
|
||||
{ "ora", LongX },
|
||||
|
||||
//0x20 - 0x2f
|
||||
{ "jsr", Address },
|
||||
{ "and", IDirectX },
|
||||
{ "jsl", Long },
|
||||
{ "and", Stack },
|
||||
|
||||
{ "bit", Direct },
|
||||
{ "and", Direct },
|
||||
{ "rol", Direct },
|
||||
{ "and", ILDirect },
|
||||
|
||||
{ "plp", Implied },
|
||||
{ "and", AccumConstant },
|
||||
{ "rol", Implied },
|
||||
{ "pld", Implied },
|
||||
|
||||
{ "bit", Address },
|
||||
{ "and", Address },
|
||||
{ "rol", Address },
|
||||
{ "and", Long },
|
||||
|
||||
//0x30 - 0x3f
|
||||
{ "bmi", RelativeShort },
|
||||
{ "and", IDirectY },
|
||||
{ "and", IDirect },
|
||||
{ "and", IStackY },
|
||||
|
||||
{ "bit", DirectX },
|
||||
{ "and", DirectX },
|
||||
{ "rol", DirectX },
|
||||
{ "and", ILDirectY },
|
||||
|
||||
{ "sec", Implied },
|
||||
{ "and", AddressY },
|
||||
{ "dec", Implied },
|
||||
{ "tsc", Implied },
|
||||
|
||||
{ "bit", AddressX },
|
||||
{ "and", AddressX },
|
||||
{ "rol", AddressX },
|
||||
{ "and", LongX },
|
||||
|
||||
//0x40 - 0x4f
|
||||
{ "rti", Implied },
|
||||
{ "eor", IDirectX },
|
||||
{ "wdm", Constant },
|
||||
{ "eor", Stack },
|
||||
|
||||
{ "mvp", BlockMove },
|
||||
{ "eor", Direct },
|
||||
{ "lsr", Direct },
|
||||
{ "eor", ILDirect },
|
||||
|
||||
{ "pha", Implied },
|
||||
{ "eor", AccumConstant },
|
||||
{ "lsr", Implied },
|
||||
{ "phk", Implied },
|
||||
|
||||
{ "jmp", PAddress },
|
||||
{ "eor", Address },
|
||||
{ "lsr", Address },
|
||||
{ "eor", Long },
|
||||
|
||||
//0x50 - 0x5f
|
||||
{ "bvc", RelativeShort },
|
||||
{ "eor", IDirectY },
|
||||
{ "eor", IDirect },
|
||||
{ "eor", IStackY },
|
||||
|
||||
{ "mvn", BlockMove },
|
||||
{ "eor", DirectX },
|
||||
{ "lsr", DirectX },
|
||||
{ "eor", ILDirectY },
|
||||
|
||||
{ "cli", Implied },
|
||||
{ "eor", AddressY },
|
||||
{ "phy", Implied },
|
||||
{ "tcd", Implied },
|
||||
|
||||
{ "jml", Long },
|
||||
{ "eor", AddressX },
|
||||
{ "lsr", AddressX },
|
||||
{ "eor", LongX },
|
||||
|
||||
//0x60 - 0x6f
|
||||
{ "rts", Implied },
|
||||
{ "adc", IDirectX },
|
||||
{ "per", Address },
|
||||
{ "adc", Stack },
|
||||
|
||||
{ "stz", Direct },
|
||||
{ "adc", Direct },
|
||||
{ "ror", Direct },
|
||||
{ "adc", ILDirect },
|
||||
|
||||
{ "pla", Implied },
|
||||
{ "adc", AccumConstant },
|
||||
{ "ror", Implied },
|
||||
{ "rtl", Implied },
|
||||
|
||||
{ "jmp", PIAddress },
|
||||
{ "adc", Address },
|
||||
{ "ror", Address },
|
||||
{ "adc", Long },
|
||||
|
||||
//0x70 - 0x7f
|
||||
{ "bvs", RelativeShort },
|
||||
{ "adc", IDirectY },
|
||||
{ "adc", IDirect },
|
||||
{ "adc", IStackY },
|
||||
|
||||
{ "stz", DirectX },
|
||||
{ "adc", DirectX },
|
||||
{ "ror", DirectX },
|
||||
{ "adc", ILDirectY },
|
||||
|
||||
{ "sei", Implied },
|
||||
{ "adc", AddressY },
|
||||
{ "ply", Implied },
|
||||
{ "tdc", Implied },
|
||||
|
||||
{ "jmp", IAddressX },
|
||||
{ "adc", AddressX },
|
||||
{ "ror", AddressX },
|
||||
{ "adc", LongX },
|
||||
|
||||
//0x80 - 0x8f
|
||||
{ "bra", RelativeShort },
|
||||
{ "sta", IDirectX },
|
||||
{ "brl", RelativeLong },
|
||||
{ "sta", Stack },
|
||||
|
||||
{ "sty", Direct },
|
||||
{ "sta", Direct },
|
||||
{ "stx", Direct },
|
||||
{ "sta", ILDirect },
|
||||
|
||||
{ "dey", Implied },
|
||||
{ "bit", AccumConstant },
|
||||
{ "txa", Implied },
|
||||
{ "phb", Implied },
|
||||
|
||||
{ "sty", Address },
|
||||
{ "sta", Address },
|
||||
{ "stx", Address },
|
||||
{ "sta", Long },
|
||||
|
||||
//0x90 - 0x9f
|
||||
{ "bcc", RelativeShort },
|
||||
{ "sta", IDirectY },
|
||||
{ "sta", IDirect },
|
||||
{ "sta", IStackY },
|
||||
|
||||
{ "sty", DirectX },
|
||||
{ "sta", DirectX },
|
||||
{ "stx", DirectY },
|
||||
{ "sta", ILDirectY },
|
||||
|
||||
{ "tya", Implied },
|
||||
{ "sta", AddressY },
|
||||
{ "txs", Implied },
|
||||
{ "txy", Implied },
|
||||
|
||||
{ "stz", Address },
|
||||
{ "sta", AddressX },
|
||||
{ "stz", AddressX },
|
||||
{ "sta", LongX },
|
||||
|
||||
//0xa0 - 0xaf
|
||||
{ "ldy", IndexConstant },
|
||||
{ "lda", IDirectX },
|
||||
{ "ldx", IndexConstant },
|
||||
{ "lda", Stack },
|
||||
|
||||
{ "ldy", Direct },
|
||||
{ "lda", Direct },
|
||||
{ "ldx", Direct },
|
||||
{ "lda", ILDirect },
|
||||
|
||||
{ "tay", Implied },
|
||||
{ "lda", AccumConstant },
|
||||
{ "tax", Implied },
|
||||
{ "plb", Implied },
|
||||
|
||||
{ "ldy", Address },
|
||||
{ "lda", Address },
|
||||
{ "ldx", Address },
|
||||
{ "lda", Long },
|
||||
|
||||
//0xb0 - 0xbf
|
||||
{ "bcs", RelativeShort },
|
||||
{ "lda", IDirectY },
|
||||
{ "lda", IDirect },
|
||||
{ "lda", IStackY },
|
||||
|
||||
{ "ldy", DirectX },
|
||||
{ "lda", DirectX },
|
||||
{ "ldx", DirectY },
|
||||
{ "lda", ILDirectY },
|
||||
|
||||
{ "clv", Implied },
|
||||
{ "lda", AddressY },
|
||||
{ "tsx", Implied },
|
||||
{ "tyx", Implied },
|
||||
|
||||
{ "ldy", AddressX },
|
||||
{ "lda", AddressX },
|
||||
{ "ldx", AddressY },
|
||||
{ "lda", LongX },
|
||||
|
||||
//0xc0 - 0xcf
|
||||
{ "cpy", IndexConstant },
|
||||
{ "cmp", IDirectX },
|
||||
{ "rep", Constant },
|
||||
{ "cmp", Stack },
|
||||
|
||||
{ "cpy", Direct },
|
||||
{ "cmp", Direct },
|
||||
{ "dec", Direct },
|
||||
{ "cmp", ILDirect },
|
||||
|
||||
{ "iny", Implied },
|
||||
{ "cmp", AccumConstant },
|
||||
{ "dex", Implied },
|
||||
{ "wai", Implied },
|
||||
|
||||
{ "cpy", Address },
|
||||
{ "cmp", Address },
|
||||
{ "dec", Address },
|
||||
{ "cmp", Long },
|
||||
|
||||
//0xd0 - 0xdf
|
||||
{ "bne", RelativeShort },
|
||||
{ "cmp", IDirectY },
|
||||
{ "cmp", IDirect },
|
||||
{ "cmp", IStackY },
|
||||
|
||||
{ "pei", IDirect },
|
||||
{ "cmp", DirectX },
|
||||
{ "dec", DirectX },
|
||||
{ "cmp", ILDirectY },
|
||||
|
||||
{ "cld", Implied },
|
||||
{ "cmp", AddressY },
|
||||
{ "phx", Implied },
|
||||
{ "stp", Implied },
|
||||
|
||||
{ "jmp", ILAddress },
|
||||
{ "cmp", AddressX },
|
||||
{ "dec", AddressX },
|
||||
{ "cmp", LongX },
|
||||
|
||||
//0xe0 - 0xef
|
||||
{ "cpx", IndexConstant },
|
||||
{ "sbc", IDirectX },
|
||||
{ "sep", Constant },
|
||||
{ "sbc", Stack },
|
||||
|
||||
{ "cpx", Direct },
|
||||
{ "sbc", Direct },
|
||||
{ "inc", Direct },
|
||||
{ "sbc", ILDirect },
|
||||
|
||||
{ "inx", Implied },
|
||||
{ "sbc", AccumConstant },
|
||||
{ "nop", Implied },
|
||||
{ "xba", Implied },
|
||||
|
||||
{ "cpx", Address },
|
||||
{ "sbc", Address },
|
||||
{ "inc", Address },
|
||||
{ "sbc", Long },
|
||||
|
||||
//0xf0 - 0xff
|
||||
{ "beq", RelativeShort },
|
||||
{ "sbc", IDirectY },
|
||||
{ "sbc", IDirect },
|
||||
{ "sbc", IStackY },
|
||||
|
||||
{ "pea", Address },
|
||||
{ "sbc", DirectX },
|
||||
{ "inc", DirectX },
|
||||
{ "sbc", ILDirectY },
|
||||
|
||||
{ "sed", Implied },
|
||||
{ "sbc", AddressY },
|
||||
{ "plx", Implied },
|
||||
{ "xce", Implied },
|
||||
|
||||
{ "jsr", IAddressX },
|
||||
{ "sbc", AddressX },
|
||||
{ "inc", AddressX },
|
||||
{ "sbc", LongX },
|
||||
};
|
||||
|
||||
inline unsigned SNESCPU::getOpcodeLength(bool accum, bool index, uint8_t opcode) {
|
||||
switch(opcodeInfo[opcode].mode) { default:
|
||||
case Implied: return 1;
|
||||
case Constant: return 2;
|
||||
case AccumConstant: return 3 - accum;
|
||||
case IndexConstant: return 3 - index;
|
||||
case Direct: return 2;
|
||||
case DirectX: return 2;
|
||||
case DirectY: return 2;
|
||||
case IDirect: return 2;
|
||||
case IDirectX: return 2;
|
||||
case IDirectY: return 2;
|
||||
case ILDirect: return 2;
|
||||
case ILDirectY: return 2;
|
||||
case Address: return 3;
|
||||
case AddressX: return 3;
|
||||
case AddressY: return 3;
|
||||
case IAddressX: return 3;
|
||||
case ILAddress: return 3;
|
||||
case PAddress: return 3;
|
||||
case PIAddress: return 3;
|
||||
case Long: return 4;
|
||||
case LongX: return 4;
|
||||
case Stack: return 2;
|
||||
case IStackY: return 2;
|
||||
case BlockMove: return 3;
|
||||
case RelativeShort: return 2;
|
||||
case RelativeLong: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
inline string SNESCPU::disassemble(unsigned pc, bool accum, bool index, uint8_t opcode, uint8_t pl, uint8_t ph, uint8_t pb) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == Constant) return { name, " #$", hex<2>(pl) };
|
||||
if(mode == AccumConstant) return { name, " #$", accum ? "" : hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == IndexConstant) return { name, " #$", index ? "" : hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == Direct) return { name, " $", hex<2>(pl) };
|
||||
if(mode == DirectX) return { name, " $", hex<2>(pl), ",x" };
|
||||
if(mode == DirectY) return { name, " $", hex<2>(pl), ",y" };
|
||||
if(mode == IDirect) return { name, " ($", hex<2>(pl), ")" };
|
||||
if(mode == IDirectX) return { name, " ($", hex<2>(pl), ",x)" };
|
||||
if(mode == IDirectY) return { name, " ($", hex<2>(pl), "),y" };
|
||||
if(mode == ILDirect) return { name, " [$", hex<2>(pl), "]" };
|
||||
if(mode == ILDirectY) return { name, " [$", hex<2>(pl), "],y" };
|
||||
if(mode == Address) return { name, " $", hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == AddressX) return { name, " $", hex<2>(ph), hex<2>(pl), ",x" };
|
||||
if(mode == AddressY) return { name, " $", hex<2>(ph), hex<2>(pl), ",y" };
|
||||
if(mode == IAddressX) return { name, " ($", hex<2>(ph), hex<2>(pl), ",x)" };
|
||||
if(mode == ILAddress) return { name, " [$", hex<2>(ph), hex<2>(pl), "]" };
|
||||
if(mode == PAddress) return { name, " $", hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == PIAddress) return { name, " ($", hex<2>(ph), hex<2>(pl), ")" };
|
||||
if(mode == Long) return { name, " $", hex<2>(pb), hex<2>(ph), hex<2>(pl) };
|
||||
if(mode == LongX) return { name, " $", hex<2>(pb), hex<2>(ph), hex<2>(pl), ",x" };
|
||||
if(mode == Stack) return { name, " $", hex<2>(pl), ",s" };
|
||||
if(mode == IStackY) return { name, " ($", hex<2>(pl), ",s),y" };
|
||||
if(mode == BlockMove) return { name, " $", hex<2>(ph), ",$", hex<2>(pl) };
|
||||
if(mode == RelativeShort) {
|
||||
unsigned addr = (pc + 2) + (int8_t)(pl << 0);
|
||||
return { name, " $", hex<4>(addr) };
|
||||
}
|
||||
if(mode == RelativeLong) {
|
||||
unsigned addr = (pc + 3) + (int16_t)((ph << 8) + (pl << 0));
|
||||
return { name, " $", hex<4>(addr) };
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,639 @@
|
|||
#ifndef NALL_SNES_SMP_HPP
|
||||
#define NALL_SNES_SMP_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
struct SNESSMP {
|
||||
enum : unsigned {
|
||||
Implied, //
|
||||
TVector, //0
|
||||
Direct, //$00
|
||||
DirectRelative, //$00,+/-$00
|
||||
ADirect, //a,$00
|
||||
AAbsolute, //a,$0000
|
||||
AIX, //a,(x)
|
||||
AIDirectX, //a,($00+x)
|
||||
AConstant, //a,#$00
|
||||
DirectDirect, //$00,$00
|
||||
CAbsoluteBit, //c,$0000:0
|
||||
Absolute, //$0000
|
||||
P, //p
|
||||
AbsoluteA, //$0000,a
|
||||
Relative, //+/-$00
|
||||
ADirectX, //a,$00+x
|
||||
AAbsoluteX, //a,$0000+x
|
||||
AAbsoluteY, //a,$0000+y
|
||||
AIDirectY, //a,($00)+y
|
||||
DirectConstant, //$00,#$00
|
||||
IXIY, //(x),(y)
|
||||
DirectX, //$00+x
|
||||
A, //a
|
||||
X, //x
|
||||
XAbsolute, //x,$0000
|
||||
IAbsoluteX, //($0000+x)
|
||||
CNAbsoluteBit, //c,!$0000:0
|
||||
XDirect, //x,$00
|
||||
PVector, //$ff00
|
||||
YaDirect, //ya,$00
|
||||
XA, //x,a
|
||||
YAbsolute, //y,$0000
|
||||
Y, //y
|
||||
AX, //a,x
|
||||
YDirect, //y,$00
|
||||
YConstant, //y,#$00
|
||||
XSp, //x,sp
|
||||
YaX, //ya,x
|
||||
IXPA, //(x)+,a
|
||||
SpX, //sp,x
|
||||
AIXP, //a,(x)+
|
||||
DirectA, //$00,a
|
||||
IXA, //(x),a
|
||||
IDirectXA, //($00+x),a
|
||||
XConstant, //x,#$00
|
||||
AbsoluteX, //$0000,x
|
||||
AbsoluteBitC, //$0000:0,c
|
||||
DirectY, //$00,y
|
||||
AbsoluteY, //$0000,y
|
||||
Ya, //ya
|
||||
DirectXA, //$00+x,a
|
||||
AbsoluteXA, //$0000+x,a
|
||||
AbsoluteYA, //$0000+y,a
|
||||
IDirectYA, //($00)+y,a
|
||||
DirectYX, //$00+y,x
|
||||
DirectYa, //$00,ya
|
||||
DirectXY, //$00+x,y
|
||||
AY, //a,y
|
||||
DirectXRelative, //$00+x,+/-$00
|
||||
XDirectY, //x,$00+y
|
||||
YDirectX, //y,$00+x
|
||||
YA, //y,a
|
||||
YRelative, //y,+/-$00
|
||||
};
|
||||
|
||||
struct OpcodeInfo {
|
||||
char name[6];
|
||||
unsigned mode;
|
||||
};
|
||||
|
||||
static const OpcodeInfo opcodeInfo[256];
|
||||
|
||||
static unsigned getOpcodeLength(uint8_t opcode);
|
||||
static string disassemble(uint16_t pc, uint8_t opcode, uint8_t pl, uint8_t ph);
|
||||
static string disassemble(uint16_t pc, bool p, uint8_t opcode, uint8_t pl, uint8_t ph);
|
||||
};
|
||||
|
||||
const SNESSMP::OpcodeInfo SNESSMP::opcodeInfo[256] = {
|
||||
//0x00 - 0x0f
|
||||
{ "nop ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set0 ", Direct },
|
||||
{ "bbs0 ", DirectRelative },
|
||||
|
||||
{ "or ", ADirect },
|
||||
{ "or ", AAbsolute },
|
||||
{ "or ", AIX },
|
||||
{ "or ", AIDirectX },
|
||||
|
||||
{ "or ", AConstant },
|
||||
{ "or ", DirectDirect },
|
||||
{ "or1 ", CAbsoluteBit },
|
||||
{ "asl ", Direct },
|
||||
|
||||
{ "asl ", Absolute },
|
||||
{ "push ", P },
|
||||
{ "tset ", AbsoluteA },
|
||||
{ "brk ", Implied },
|
||||
|
||||
//0x10 - 0x1f
|
||||
{ "bpl ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr0 ", Direct },
|
||||
{ "bbc0 ", DirectRelative },
|
||||
|
||||
{ "or ", ADirectX },
|
||||
{ "or ", AAbsoluteX },
|
||||
{ "or ", AAbsoluteY },
|
||||
{ "or ", AIDirectY },
|
||||
|
||||
{ "or ", DirectConstant },
|
||||
{ "or ", IXIY },
|
||||
{ "decw ", Direct },
|
||||
{ "asl ", DirectX },
|
||||
|
||||
{ "asl ", A },
|
||||
{ "dec ", X },
|
||||
{ "cmp ", XAbsolute },
|
||||
{ "jmp ", IAbsoluteX },
|
||||
|
||||
//0x20 - 0x2f
|
||||
{ "clrp ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set1 ", Direct },
|
||||
{ "bbs1 ", DirectRelative },
|
||||
|
||||
{ "and ", ADirect },
|
||||
{ "and ", AAbsolute },
|
||||
{ "and ", AIX },
|
||||
{ "and ", AIDirectX },
|
||||
|
||||
{ "and ", AConstant },
|
||||
{ "and ", DirectDirect },
|
||||
{ "or1 ", CNAbsoluteBit },
|
||||
{ "rol ", Direct },
|
||||
|
||||
{ "rol ", Absolute },
|
||||
{ "push ", A },
|
||||
{ "cbne ", DirectRelative },
|
||||
{ "bra ", Relative },
|
||||
|
||||
//0x30 - 0x3f
|
||||
{ "bmi ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr1 ", Direct },
|
||||
{ "bbc1 ", DirectRelative },
|
||||
|
||||
{ "and ", ADirectX },
|
||||
{ "and ", AAbsoluteX },
|
||||
{ "and ", AAbsoluteY },
|
||||
{ "and ", AIDirectY },
|
||||
|
||||
{ "and ", DirectConstant },
|
||||
{ "and ", IXIY },
|
||||
{ "incw ", Direct },
|
||||
{ "rol ", DirectX },
|
||||
|
||||
{ "rol ", A },
|
||||
{ "inc ", X },
|
||||
{ "cmp ", XDirect },
|
||||
{ "call ", Absolute },
|
||||
|
||||
//0x40 - 0x4f
|
||||
{ "setp ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set2 ", Direct },
|
||||
{ "bbs2 ", DirectRelative },
|
||||
|
||||
{ "eor ", ADirect },
|
||||
{ "eor ", AAbsolute },
|
||||
{ "eor ", AIX },
|
||||
{ "eor ", AIDirectX },
|
||||
|
||||
{ "eor ", AConstant },
|
||||
{ "eor ", DirectDirect },
|
||||
{ "and1 ", CAbsoluteBit },
|
||||
{ "lsr ", Direct },
|
||||
|
||||
{ "lsr ", Absolute },
|
||||
{ "push ", X },
|
||||
{ "tclr ", AbsoluteA },
|
||||
{ "pcall", PVector },
|
||||
|
||||
//0x50 - 0x5f
|
||||
{ "bvc ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr2 ", Direct },
|
||||
{ "bbc2 ", DirectRelative },
|
||||
|
||||
{ "eor ", ADirectX },
|
||||
{ "eor ", AAbsoluteX },
|
||||
{ "eor ", AAbsoluteY },
|
||||
{ "eor ", AIDirectY },
|
||||
|
||||
{ "eor ", DirectConstant },
|
||||
{ "eor ", IXIY },
|
||||
{ "cmpw ", YaDirect },
|
||||
{ "lsr ", DirectX },
|
||||
|
||||
{ "lsr ", A },
|
||||
{ "mov ", XA },
|
||||
{ "cmp ", YAbsolute },
|
||||
{ "jmp ", Absolute },
|
||||
|
||||
//0x60 - 0x6f
|
||||
{ "clrc ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set3 ", Direct },
|
||||
{ "bbs3 ", DirectRelative },
|
||||
|
||||
{ "cmp ", ADirect },
|
||||
{ "cmp ", AAbsolute },
|
||||
{ "cmp ", AIX },
|
||||
{ "cmp ", AIDirectX },
|
||||
|
||||
{ "cmp ", AConstant },
|
||||
{ "cmp ", DirectDirect },
|
||||
{ "and1 ", CNAbsoluteBit },
|
||||
{ "ror ", Direct },
|
||||
|
||||
{ "ror ", Absolute },
|
||||
{ "push ", Y },
|
||||
{ "dbnz ", DirectRelative },
|
||||
{ "ret ", Implied },
|
||||
|
||||
//0x70 - 0x7f
|
||||
{ "bvs ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr3 ", Direct },
|
||||
{ "bbc3 ", DirectRelative },
|
||||
|
||||
{ "cmp ", ADirectX },
|
||||
{ "cmp ", AAbsoluteX },
|
||||
{ "cmp ", AAbsoluteY },
|
||||
{ "cmp ", AIDirectY },
|
||||
|
||||
{ "cmp ", DirectConstant },
|
||||
{ "cmp ", IXIY },
|
||||
{ "addw ", YaDirect },
|
||||
{ "ror ", DirectX },
|
||||
|
||||
{ "ror ", A },
|
||||
{ "mov ", AX },
|
||||
{ "cmp ", YDirect },
|
||||
{ "reti ", Implied },
|
||||
|
||||
//0x80 - 0x8f
|
||||
{ "setc ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set4 ", Direct },
|
||||
{ "bbs4 ", DirectRelative },
|
||||
|
||||
{ "adc ", ADirect },
|
||||
{ "adc ", AAbsolute },
|
||||
{ "adc ", AIX },
|
||||
{ "adc ", AIDirectX },
|
||||
|
||||
{ "adc ", AConstant },
|
||||
{ "adc ", DirectDirect },
|
||||
{ "eor1 ", CAbsoluteBit },
|
||||
{ "dec ", Direct },
|
||||
|
||||
{ "dec ", Absolute },
|
||||
{ "mov ", YConstant },
|
||||
{ "pop ", P },
|
||||
{ "mov ", DirectConstant },
|
||||
|
||||
//0x90 - 0x9f
|
||||
{ "bcc ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr4 ", Direct },
|
||||
{ "bbc4 ", DirectRelative },
|
||||
|
||||
{ "adc ", ADirectX },
|
||||
{ "adc ", AAbsoluteX },
|
||||
{ "adc ", AAbsoluteY },
|
||||
{ "adc ", AIDirectY },
|
||||
|
||||
{ "adc ", DirectRelative },
|
||||
{ "adc ", IXIY },
|
||||
{ "subw ", YaDirect },
|
||||
{ "dec ", DirectX },
|
||||
|
||||
{ "dec ", A },
|
||||
{ "mov ", XSp },
|
||||
{ "div ", YaX },
|
||||
{ "xcn ", A },
|
||||
|
||||
//0xa0 - 0xaf
|
||||
{ "ei ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set5 ", Direct },
|
||||
{ "bbs5 ", DirectRelative },
|
||||
|
||||
{ "sbc ", ADirect },
|
||||
{ "sbc ", AAbsolute },
|
||||
{ "sbc ", AIX },
|
||||
{ "sbc ", AIDirectX },
|
||||
|
||||
{ "sbc ", AConstant },
|
||||
{ "sbc ", DirectDirect },
|
||||
{ "mov1 ", CAbsoluteBit },
|
||||
{ "inc ", Direct },
|
||||
|
||||
{ "inc ", Absolute },
|
||||
{ "cmp ", YConstant },
|
||||
{ "pop ", A },
|
||||
{ "mov ", IXPA },
|
||||
|
||||
//0xb0 - 0xbf
|
||||
{ "bcs ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr5 ", Direct },
|
||||
{ "bbc5 ", DirectRelative },
|
||||
|
||||
{ "sbc ", ADirectX },
|
||||
{ "sbc ", AAbsoluteX },
|
||||
{ "sbc ", AAbsoluteY },
|
||||
{ "sbc ", AIDirectY },
|
||||
|
||||
{ "sbc ", DirectConstant },
|
||||
{ "sbc ", IXIY },
|
||||
{ "movw ", YaDirect },
|
||||
{ "inc ", DirectX },
|
||||
|
||||
{ "inc ", A },
|
||||
{ "mov ", SpX },
|
||||
{ "das ", A },
|
||||
{ "mov ", AIXP },
|
||||
|
||||
//0xc0 - 0xcf
|
||||
{ "di ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set6 ", Direct },
|
||||
{ "bbs6 ", DirectRelative },
|
||||
|
||||
{ "mov ", DirectA },
|
||||
{ "mov ", AbsoluteA },
|
||||
{ "mov ", IXA },
|
||||
{ "mov ", IDirectXA },
|
||||
|
||||
{ "cmp ", XConstant },
|
||||
{ "mov ", AbsoluteX },
|
||||
{ "mov1 ", AbsoluteBitC },
|
||||
{ "mov ", DirectY },
|
||||
|
||||
{ "mov ", AbsoluteY },
|
||||
{ "mov ", XConstant },
|
||||
{ "pop ", X },
|
||||
{ "mul ", Ya },
|
||||
|
||||
//0xd0 - 0xdf
|
||||
{ "bne ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr6 ", Relative },
|
||||
{ "bbc6 ", DirectRelative },
|
||||
|
||||
{ "mov ", DirectXA },
|
||||
{ "mov ", AbsoluteXA },
|
||||
{ "mov ", AbsoluteYA },
|
||||
{ "mov ", IDirectYA },
|
||||
|
||||
{ "mov ", DirectX },
|
||||
{ "mov ", DirectYX },
|
||||
{ "movw ", DirectYa },
|
||||
{ "mov ", DirectXY },
|
||||
|
||||
{ "dec ", Y },
|
||||
{ "mov ", AY },
|
||||
{ "cbne ", DirectXRelative },
|
||||
{ "daa ", A },
|
||||
|
||||
//0xe0 - 0xef
|
||||
{ "clrv ", Implied },
|
||||
{ "tcall", TVector },
|
||||
{ "set7 ", Direct },
|
||||
{ "bbs7 ", DirectRelative },
|
||||
|
||||
{ "mov ", ADirect },
|
||||
{ "mov ", AAbsolute },
|
||||
{ "mov ", AIX },
|
||||
{ "mov ", AIDirectX },
|
||||
|
||||
{ "mov ", AConstant },
|
||||
{ "mov ", XAbsolute },
|
||||
{ "not1 ", CAbsoluteBit },
|
||||
{ "mov ", YDirect },
|
||||
|
||||
{ "mov ", YAbsolute },
|
||||
{ "notc ", Implied },
|
||||
{ "pop ", Y },
|
||||
{ "sleep", Implied },
|
||||
|
||||
//0xf0 - 0xff
|
||||
{ "beq ", Relative },
|
||||
{ "tcall", TVector },
|
||||
{ "clr7 ", Direct },
|
||||
{ "bbc7 ", DirectRelative },
|
||||
|
||||
{ "mov ", ADirectX },
|
||||
{ "mov ", AAbsoluteX },
|
||||
{ "mov ", AAbsoluteY },
|
||||
{ "mov ", AIDirectY },
|
||||
|
||||
{ "mov ", XDirect },
|
||||
{ "mov ", XDirectY },
|
||||
{ "mov ", DirectDirect },
|
||||
{ "mov ", YDirectX },
|
||||
|
||||
{ "inc ", Y },
|
||||
{ "mov ", YA },
|
||||
{ "dbz ", YRelative },
|
||||
{ "stop ", Implied },
|
||||
};
|
||||
|
||||
inline unsigned SNESSMP::getOpcodeLength(uint8_t opcode) {
|
||||
switch(opcodeInfo[opcode].mode) { default:
|
||||
case Implied: return 1; //
|
||||
case TVector: return 1; //0
|
||||
case Direct: return 2; //$00
|
||||
case DirectRelative: return 3; //$00,+/-$00
|
||||
case ADirect: return 2; //a,$00
|
||||
case AAbsolute: return 3; //a,$0000
|
||||
case AIX: return 1; //a,(x)
|
||||
case AIDirectX: return 2; //a,($00+x)
|
||||
case AConstant: return 2; //a,#$00
|
||||
case DirectDirect: return 3; //$00,$00
|
||||
case CAbsoluteBit: return 3; //c,$0000:0
|
||||
case Absolute: return 3; //$0000
|
||||
case P: return 1; //p
|
||||
case AbsoluteA: return 3; //$0000,a
|
||||
case Relative: return 2; //+/-$00
|
||||
case ADirectX: return 2; //a,$00+x
|
||||
case AAbsoluteX: return 3; //a,$0000+x
|
||||
case AAbsoluteY: return 3; //a,$0000+y
|
||||
case AIDirectY: return 2; //a,($00)+y
|
||||
case DirectConstant: return 3; //$00,#$00
|
||||
case IXIY: return 1; //(x),(y)
|
||||
case DirectX: return 2; //$00+x
|
||||
case A: return 1; //a
|
||||
case X: return 1; //x
|
||||
case XAbsolute: return 3; //x,$0000
|
||||
case IAbsoluteX: return 3; //($0000+x)
|
||||
case CNAbsoluteBit: return 3; //c,!$0000:0
|
||||
case XDirect: return 2; //x,$00
|
||||
case PVector: return 2; //$ff00
|
||||
case YaDirect: return 2; //ya,$00
|
||||
case XA: return 1; //x,a
|
||||
case YAbsolute: return 3; //y,$0000
|
||||
case Y: return 1; //y
|
||||
case AX: return 1; //a,x
|
||||
case YDirect: return 2; //y,$00
|
||||
case YConstant: return 2; //y,#$00
|
||||
case XSp: return 1; //x,sp
|
||||
case YaX: return 1; //ya,x
|
||||
case IXPA: return 1; //(x)+,a
|
||||
case SpX: return 1; //sp,x
|
||||
case AIXP: return 1; //a,(x)+
|
||||
case DirectA: return 2; //$00,a
|
||||
case IXA: return 1; //(x),a
|
||||
case IDirectXA: return 2; //($00+x),a
|
||||
case XConstant: return 2; //x,#$00
|
||||
case AbsoluteX: return 3; //$0000,x
|
||||
case AbsoluteBitC: return 3; //$0000:0,c
|
||||
case DirectY: return 2; //$00,y
|
||||
case AbsoluteY: return 3; //$0000,y
|
||||
case Ya: return 1; //ya
|
||||
case DirectXA: return 2; //$00+x,a
|
||||
case AbsoluteXA: return 3; //$0000+x,a
|
||||
case AbsoluteYA: return 3; //$0000+y,a
|
||||
case IDirectYA: return 2; //($00)+y,a
|
||||
case DirectYX: return 2; //$00+y,x
|
||||
case DirectYa: return 2; //$00,ya
|
||||
case DirectXY: return 2; //$00+x,y
|
||||
case AY: return 1; //a,y
|
||||
case DirectXRelative: return 3; //$00+x,+/-$00
|
||||
case XDirectY: return 2; //x,$00+y
|
||||
case YDirectX: return 2; //y,$00+x
|
||||
case YA: return 1; //y,a
|
||||
case YRelative: return 2; //y,+/-$00
|
||||
}
|
||||
}
|
||||
|
||||
inline string SNESSMP::disassemble(uint16_t pc, uint8_t opcode, uint8_t pl, uint8_t ph) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
unsigned pa = (ph << 8) + pl;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == TVector) return { name, " ", opcode >> 4 };
|
||||
if(mode == Direct) return { name, " $", hex<2>(pl) };
|
||||
if(mode == DirectRelative) return { name, " $", hex<2>(pl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == ADirect) return { name, " a,$", hex<2>(pl) };
|
||||
if(mode == AAbsolute) return { name, " a,$", hex<4>(pa) };
|
||||
if(mode == AIX) return { name, "a,(x)" };
|
||||
if(mode == AIDirectX) return { name, " a,($", hex<2>(pl), "+x)" };
|
||||
if(mode == AConstant) return { name, " a,#$", hex<2>(pl) };
|
||||
if(mode == DirectDirect) return { name, " $", hex<2>(ph), ",$", hex<2>(pl) };
|
||||
if(mode == CAbsoluteBit) return { name, " c,$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == Absolute) return { name, " $", hex<4>(pa) };
|
||||
if(mode == P) return { name, " p" };
|
||||
if(mode == AbsoluteA) return { name, " $", hex<4>(pa), ",a" };
|
||||
if(mode == Relative) return { name, " $", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
if(mode == ADirectX) return { name, " a,$", hex<2>(pl), "+x" };
|
||||
if(mode == AAbsoluteX) return { name, " a,$", hex<4>(pa), "+x" };
|
||||
if(mode == AAbsoluteY) return { name, " a,$", hex<4>(pa), "+y" };
|
||||
if(mode == AIDirectY) return { name, " a,($", hex<2>(pl), ")+y" };
|
||||
if(mode == DirectConstant) return { name, " $", hex<2>(ph), ",#$", hex<2>(pl) };
|
||||
if(mode == IXIY) return { name, " (x),(y)" };
|
||||
if(mode == DirectX) return { name, " $", hex<2>(pl), "+x" };
|
||||
if(mode == A) return { name, " a" };
|
||||
if(mode == X) return { name, " x" };
|
||||
if(mode == XAbsolute) return { name, " x,$", hex<4>(pa) };
|
||||
if(mode == IAbsoluteX) return { name, " ($", hex<4>(pa), "+x)" };
|
||||
if(mode == CNAbsoluteBit) return { name, " c,!$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == XDirect) return { name, " x,$", hex<2>(pl) };
|
||||
if(mode == PVector) return { name, " $ff", hex<2>(pl) };
|
||||
if(mode == YaDirect) return { name, " ya,$", hex<2>(pl) };
|
||||
if(mode == XA) return { name, " x,a" };
|
||||
if(mode == YAbsolute) return { name, " y,$", hex<4>(pa) };
|
||||
if(mode == Y) return { name, " y" };
|
||||
if(mode == AX) return { name, " a,x" };
|
||||
if(mode == YDirect) return { name, " y,$", hex<2>(pl) };
|
||||
if(mode == YConstant) return { name, " y,#$", hex<2>(pl) };
|
||||
if(mode == XSp) return { name, " x,sp" };
|
||||
if(mode == YaX) return { name, " ya,x" };
|
||||
if(mode == IXPA) return { name, " (x)+,a" };
|
||||
if(mode == SpX) return { name, " sp,x" };
|
||||
if(mode == AIXP) return { name, " a,(x)+" };
|
||||
if(mode == DirectA) return { name, " $", hex<2>(pl), ",a" };
|
||||
if(mode == IXA) return { name, " (x),a" };
|
||||
if(mode == IDirectXA) return { name, " ($", hex<2>(pl), "+x),a" };
|
||||
if(mode == XConstant) return { name, " x,#$", hex<2>(pl) };
|
||||
if(mode == AbsoluteX) return { name, " $", hex<4>(pa), ",x" };
|
||||
if(mode == AbsoluteBitC) return { name, " $", hex<4>(pa & 0x1fff), ":", pa >> 13, ",c" };
|
||||
if(mode == DirectY) return { name, " $", hex<2>(pl), ",y" };
|
||||
if(mode == AbsoluteY) return { name, " $", hex<4>(pa), ",y" };
|
||||
if(mode == Ya) return { name, " ya" };
|
||||
if(mode == DirectXA) return { name, " $", hex<2>(pl), "+x,a" };
|
||||
if(mode == AbsoluteXA) return { name, " $", hex<4>(pa), "+x,a" };
|
||||
if(mode == AbsoluteYA) return { name, " $", hex<4>(pa), "+y,a" };
|
||||
if(mode == IDirectYA) return { name, " ($", hex<2>(pl), ")+y,a" };
|
||||
if(mode == DirectYX) return { name, " $", hex<2>(pl), "+y,x" };
|
||||
if(mode == DirectYa) return { name, " $", hex<2>(pl), ",ya" };
|
||||
if(mode == DirectXY) return { name, " $", hex<2>(pl), "+x,y" };
|
||||
if(mode == AY) return { name, " a,y" };
|
||||
if(mode == DirectXRelative) return { name, " $", hex<2>(pl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == XDirectY) return { name, " x,$", hex<2>(pl), "+y" };
|
||||
if(mode == YDirectX) return { name, " y,$", hex<2>(pl), "+x" };
|
||||
if(mode == YA) return { name, " y,a" };
|
||||
if(mode == YRelative) return { name, " y,$", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
inline string SNESSMP::disassemble(uint16_t pc, bool p, uint8_t opcode, uint8_t pl, uint8_t ph) {
|
||||
string name = opcodeInfo[opcode].name;
|
||||
unsigned mode = opcodeInfo[opcode].mode;
|
||||
unsigned pdl = (p << 8) + pl;
|
||||
unsigned pdh = (p << 8) + ph;
|
||||
unsigned pa = (ph << 8) + pl;
|
||||
|
||||
if(mode == Implied) return name;
|
||||
if(mode == TVector) return { name, " ", opcode >> 4 };
|
||||
if(mode == Direct) return { name, " $", hex<3>(pdl) };
|
||||
if(mode == DirectRelative) return { name, " $", hex<3>(pdl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == ADirect) return { name, " a,$", hex<3>(pdl) };
|
||||
if(mode == AAbsolute) return { name, " a,$", hex<4>(pa) };
|
||||
if(mode == AIX) return { name, "a,(x)" };
|
||||
if(mode == AIDirectX) return { name, " a,($", hex<3>(pdl), "+x)" };
|
||||
if(mode == AConstant) return { name, " a,#$", hex<2>(pl) };
|
||||
if(mode == DirectDirect) return { name, " $", hex<3>(pdh), ",$", hex<3>(pdl) };
|
||||
if(mode == CAbsoluteBit) return { name, " c,$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == Absolute) return { name, " $", hex<4>(pa) };
|
||||
if(mode == P) return { name, " p" };
|
||||
if(mode == AbsoluteA) return { name, " $", hex<4>(pa), ",a" };
|
||||
if(mode == Relative) return { name, " $", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
if(mode == ADirectX) return { name, " a,$", hex<3>(pdl), "+x" };
|
||||
if(mode == AAbsoluteX) return { name, " a,$", hex<4>(pa), "+x" };
|
||||
if(mode == AAbsoluteY) return { name, " a,$", hex<4>(pa), "+y" };
|
||||
if(mode == AIDirectY) return { name, " a,($", hex<3>(pdl), ")+y" };
|
||||
if(mode == DirectConstant) return { name, " $", hex<3>(pdh), ",#$", hex<2>(pl) };
|
||||
if(mode == IXIY) return { name, " (x),(y)" };
|
||||
if(mode == DirectX) return { name, " $", hex<3>(pdl), "+x" };
|
||||
if(mode == A) return { name, " a" };
|
||||
if(mode == X) return { name, " x" };
|
||||
if(mode == XAbsolute) return { name, " x,$", hex<4>(pa) };
|
||||
if(mode == IAbsoluteX) return { name, " ($", hex<4>(pa), "+x)" };
|
||||
if(mode == CNAbsoluteBit) return { name, " c,!$", hex<4>(pa & 0x1fff), ":", pa >> 13 };
|
||||
if(mode == XDirect) return { name, " x,$", hex<3>(pdl) };
|
||||
if(mode == PVector) return { name, " $ff", hex<2>(pl) };
|
||||
if(mode == YaDirect) return { name, " ya,$", hex<3>(pdl) };
|
||||
if(mode == XA) return { name, " x,a" };
|
||||
if(mode == YAbsolute) return { name, " y,$", hex<4>(pa) };
|
||||
if(mode == Y) return { name, " y" };
|
||||
if(mode == AX) return { name, " a,x" };
|
||||
if(mode == YDirect) return { name, " y,$", hex<3>(pdl) };
|
||||
if(mode == YConstant) return { name, " y,#$", hex<2>(pl) };
|
||||
if(mode == XSp) return { name, " x,sp" };
|
||||
if(mode == YaX) return { name, " ya,x" };
|
||||
if(mode == IXPA) return { name, " (x)+,a" };
|
||||
if(mode == SpX) return { name, " sp,x" };
|
||||
if(mode == AIXP) return { name, " a,(x)+" };
|
||||
if(mode == DirectA) return { name, " $", hex<3>(pdl), ",a" };
|
||||
if(mode == IXA) return { name, " (x),a" };
|
||||
if(mode == IDirectXA) return { name, " ($", hex<3>(pdl), "+x),a" };
|
||||
if(mode == XConstant) return { name, " x,#$", hex<2>(pl) };
|
||||
if(mode == AbsoluteX) return { name, " $", hex<4>(pa), ",x" };
|
||||
if(mode == AbsoluteBitC) return { name, " $", hex<4>(pa & 0x1fff), ":", pa >> 13, ",c" };
|
||||
if(mode == DirectY) return { name, " $", hex<3>(pdl), ",y" };
|
||||
if(mode == AbsoluteY) return { name, " $", hex<4>(pa), ",y" };
|
||||
if(mode == Ya) return { name, " ya" };
|
||||
if(mode == DirectXA) return { name, " $", hex<3>(pdl), "+x,a" };
|
||||
if(mode == AbsoluteXA) return { name, " $", hex<4>(pa), "+x,a" };
|
||||
if(mode == AbsoluteYA) return { name, " $", hex<4>(pa), "+y,a" };
|
||||
if(mode == IDirectYA) return { name, " ($", hex<3>(pdl), ")+y,a" };
|
||||
if(mode == DirectYX) return { name, " $", hex<3>(pdl), "+y,x" };
|
||||
if(mode == DirectYa) return { name, " $", hex<3>(pdl), ",ya" };
|
||||
if(mode == DirectXY) return { name, " $", hex<3>(pdl), "+x,y" };
|
||||
if(mode == AY) return { name, " a,y" };
|
||||
if(mode == DirectXRelative) return { name, " $", hex<3>(pdl), ",$", hex<4>(pc + 3 + (int8_t)ph) };
|
||||
if(mode == XDirectY) return { name, " x,$", hex<3>(pdl), "+y" };
|
||||
if(mode == YDirectX) return { name, " y,$", hex<3>(pdl), "+x" };
|
||||
if(mode == YA) return { name, " y,a" };
|
||||
if(mode == YRelative) return { name, " y,$", hex<4>(pc + 2 + (int8_t)pl) };
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -25,7 +25,7 @@ namespace nall {
|
|||
inline string& append(unsigned int value);
|
||||
inline string& append(double value);
|
||||
|
||||
inline bool readfile(const char*);
|
||||
inline bool readfile(const string&);
|
||||
|
||||
inline string& replace (const char*, const char*);
|
||||
inline string& qreplace(const char*, const char*);
|
||||
|
@ -113,11 +113,11 @@ namespace nall {
|
|||
inline char* strlower(char *str);
|
||||
inline char* strupper(char *str);
|
||||
inline char* strtr(char *dest, const char *before, const char *after);
|
||||
inline uintmax_t strhex (const char *str);
|
||||
inline intmax_t strsigned (const char *str);
|
||||
inline uintmax_t strunsigned(const char *str);
|
||||
inline uintmax_t strbin (const char *str);
|
||||
inline double strdouble (const char *str);
|
||||
inline uintmax_t hex (const char *str);
|
||||
inline intmax_t integer(const char *str);
|
||||
inline uintmax_t decimal(const char *str);
|
||||
inline uintmax_t binary (const char *str);
|
||||
inline double fp (const char *str);
|
||||
|
||||
//math.hpp
|
||||
inline bool strint (const char *str, int &result);
|
||||
|
@ -145,12 +145,17 @@ namespace nall {
|
|||
inline unsigned strlcpy(string &dest, const char *src, unsigned length);
|
||||
inline unsigned strlcat(string &dest, const char *src, unsigned length);
|
||||
inline string substr(const char *src, unsigned start = 0, unsigned length = 0);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strhex(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strsigned(intmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strunsigned(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string strbin(uintmax_t value);
|
||||
inline unsigned strdouble(char *str, double value);
|
||||
inline string strdouble(double value);
|
||||
|
||||
inline string integer(intmax_t value);
|
||||
template<unsigned length = 0> inline string linteger(intmax_t value);
|
||||
template<unsigned length = 0> inline string rinteger(intmax_t value);
|
||||
inline string decimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string ldecimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string rdecimal(uintmax_t value);
|
||||
template<unsigned length = 0> inline string hex(uintmax_t value);
|
||||
template<unsigned length = 0> inline string binary(uintmax_t value);
|
||||
inline unsigned fp(char *str, double value);
|
||||
inline string fp(double value);
|
||||
|
||||
//variadic.hpp
|
||||
template<typename... Args> inline void print(Args&&... args);
|
||||
|
|
|
@ -5,9 +5,9 @@ namespace nall {
|
|||
|
||||
//this is needed, as C++0x does not support explicit template specialization inside classes
|
||||
template<> inline string to_string<bool> (bool v) { return v ? "true" : "false"; }
|
||||
template<> inline string to_string<signed int> (signed int v) { return strsigned(v); }
|
||||
template<> inline string to_string<unsigned int> (unsigned int v) { return strunsigned(v); }
|
||||
template<> inline string to_string<double> (double v) { return strdouble(v); }
|
||||
template<> inline string to_string<signed int> (signed int v) { return integer(v); }
|
||||
template<> inline string to_string<unsigned int> (unsigned int v) { return decimal(v); }
|
||||
template<> inline string to_string<double> (double v) { return fp(v); }
|
||||
template<> inline string to_string<char*> (char *v) { return v; }
|
||||
template<> inline string to_string<const char*> (const char *v) { return v; }
|
||||
template<> inline string to_string<string> (string v) { return v; }
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue