mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-18 18:12:48 +02:00
Compare commits
51 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2a90e12999 | ||
|
d129b72ced | ||
|
bc0b86891a | ||
|
52443936e6 | ||
|
6694a1c986 | ||
|
7ffaeb2ac1 | ||
|
67e6a6e742 | ||
|
9a3650c6ab | ||
|
0a3d6e4c53 | ||
|
378b78dad7 | ||
|
721e0b1762 | ||
|
2bf3dbf375 | ||
|
396003e7f6 | ||
|
a92a554d7b | ||
|
9ea35ce569 | ||
|
348bace8ed | ||
|
5cbf5b617b | ||
|
d5cd21eb0c | ||
|
8b7dd89059 | ||
|
6c4e3ec790 | ||
|
8d64f9b155 | ||
|
bc5fd8c53c | ||
|
64072325c4 | ||
|
017f9926fc | ||
|
c31543ea58 | ||
|
7c3aaf12b0 | ||
|
3fad0a0105 | ||
|
72a2967eeb | ||
|
a8ee35633c | ||
|
7dda70baa4 | ||
|
2c61ce2522 | ||
|
266495b475 | ||
|
133d568f76 | ||
|
b433838e9f | ||
|
a3abe8ebaa | ||
|
f88ef9e9a2 | ||
|
a136378a7b | ||
|
012cdd4b14 | ||
|
eecc085e42 | ||
|
6b4104867f | ||
|
53fe43afd8 | ||
|
054bdd4094 | ||
|
ecf96726f9 | ||
|
cab5917806 | ||
|
c833b69087 | ||
|
1a065bafb1 | ||
|
ea077a7d96 | ||
|
a937f9b79b | ||
|
2d73086569 | ||
|
5810e69be3 | ||
|
a198e555dc |
@@ -4,6 +4,9 @@ gameboy := gameboy
|
||||
profile := accuracy
|
||||
ui := ui
|
||||
|
||||
# debugger
|
||||
options :=
|
||||
|
||||
# compiler
|
||||
c := $(compiler) -std=gnu99
|
||||
cpp := $(subst cc,++,$(compiler)) -std=gnu++0x
|
||||
@@ -18,6 +21,8 @@ objects := libco
|
||||
# profile-guided optimization
|
||||
# flags += -fprofile-use
|
||||
|
||||
flags := $(flags) $(foreach o,$(call strupper,$(options)),-D$o)
|
||||
|
||||
# platform
|
||||
ifeq ($(platform),x)
|
||||
link += -s -ldl -lX11 -lXext
|
||||
@@ -48,39 +53,10 @@ all: build;
|
||||
|
||||
obj/libco.o: libco/libco.c libco/*
|
||||
|
||||
include $(snes)/Makefile
|
||||
include $(gameboy)/Makefile
|
||||
include $(ui)/Makefile
|
||||
|
||||
objects := $(patsubst %,obj/%.o,$(objects))
|
||||
|
||||
# targets
|
||||
build: ui_build $(objects)
|
||||
ifeq ($(platform),osx)
|
||||
test -d ../bsnes.app || mkdir -p ../bsnes.app/Contents/MacOS
|
||||
$(strip $(cpp) -o ../bsnes.app/Contents/MacOS/bsnes $(objects) $(link))
|
||||
else
|
||||
$(strip $(cpp) -o out/bsnes $(objects) $(link))
|
||||
endif
|
||||
|
||||
install:
|
||||
ifeq ($(platform),x)
|
||||
install -D -m 755 out/bsnes $(DESTDIR)$(prefix)/bin/bsnes
|
||||
install -D -m 644 data/bsnes.png $(DESTDIR)$(prefix)/share/pixmaps/bsnes.png
|
||||
install -D -m 644 data/bsnes.desktop $(DESTDIR)$(prefix)/share/applications/bsnes.desktop
|
||||
test -d ~/.bsnes || mkdir ~/.bsnes
|
||||
cp data/cheats.xml ~/.bsnes/cheats.xml
|
||||
chmod 777 ~/.bsnes ~/.bsnes/cheats.xml
|
||||
endif
|
||||
|
||||
uninstall:
|
||||
ifeq ($(platform),x)
|
||||
rm $(DESTDIR)$(prefix)/bin/bsnes
|
||||
rm $(DESTDIR)$(prefix)/share/pixmaps/bsnes.png
|
||||
rm $(DESTDIR)$(prefix)/share/applications/bsnes.desktop
|
||||
endif
|
||||
|
||||
clean: ui_clean
|
||||
clean:
|
||||
-@$(call delete,obj/*.o)
|
||||
-@$(call delete,obj/*.a)
|
||||
-@$(call delete,obj/*.so)
|
||||
@@ -94,6 +70,6 @@ clean: ui_clean
|
||||
-@$(call delete,*.manifest)
|
||||
|
||||
archive-all:
|
||||
tar -cjf bsnes.tar.bz2 data gameboy launcher libco nall obj out phoenix ruby snes ui ui-gameboy Makefile cc.bat clean.bat sync.sh
|
||||
tar -cjf bsnes.tar.bz2 data gameboy libco nall obj out phoenix ruby snes ui ui-gameboy ui-libsnes Makefile cc.bat clean.bat sync.sh
|
||||
|
||||
help:;
|
||||
|
@@ -1,2 +1,2 @@
|
||||
@mingw32-make -j 2
|
||||
@mingw32-make -j 8
|
||||
@pause
|
||||
|
114552
bsnes/data/cheats.xml
114552
bsnes/data/cheats.xml
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
gameboy_objects := gameboy-system gameboy-scheduler
|
||||
gameboy_objects += gameboy-memory gameboy-cartridge
|
||||
gameboy_objects += gameboy-cpu gameboy-lcd
|
||||
gameboy_objects += gameboy-cpu gameboy-apu gameboy-lcd
|
||||
objects += $(gameboy_objects)
|
||||
|
||||
obj/gameboy-system.o: $(gameboy)/system/system.cpp $(call rwildcard,$(gameboy)/system/)
|
||||
@@ -8,4 +8,5 @@ obj/gameboy-scheduler.o: $(gameboy)/scheduler/scheduler.cpp $(call rwildcard,$(g
|
||||
obj/gameboy-cartridge.o: $(gameboy)/cartridge/cartridge.cpp $(call rwildcard,$(gameboy)/cartridge/)
|
||||
obj/gameboy-memory.o: $(gameboy)/memory/memory.cpp $(call rwildcard,$(gameboy)/memory/)
|
||||
obj/gameboy-cpu.o: $(gameboy)/cpu/cpu.cpp $(call rwildcard,$(gameboy)/cpu/)
|
||||
obj/gameboy-apu.o: $(gameboy)/apu/apu.cpp $(call rwildcard,$(gameboy)/apu/)
|
||||
obj/gameboy-lcd.o: $(gameboy)/lcd/lcd.cpp $(call rwildcard,$(gameboy)/lcd/)
|
||||
|
105
bsnes/gameboy/apu/apu.cpp
Executable file
105
bsnes/gameboy/apu/apu.cpp
Executable file
@@ -0,0 +1,105 @@
|
||||
#include <gameboy/gameboy.hpp>
|
||||
|
||||
#define APU_CPP
|
||||
namespace GameBoy {
|
||||
|
||||
#include "square1/square1.cpp"
|
||||
#include "square2/square2.cpp"
|
||||
#include "wave/wave.cpp"
|
||||
#include "noise/noise.cpp"
|
||||
#include "master/master.cpp"
|
||||
#include "serialization.cpp"
|
||||
APU apu;
|
||||
|
||||
void APU::Main() {
|
||||
apu.main();
|
||||
}
|
||||
|
||||
void APU::main() {
|
||||
while(true) {
|
||||
if(scheduler.sync == Scheduler::SynchronizeMode::All) {
|
||||
scheduler.exit(Scheduler::ExitReason::SynchronizeEvent);
|
||||
}
|
||||
|
||||
if(sequencer_base == 0) { //512hz
|
||||
if(sequencer_step == 0 || sequencer_step == 2 || sequencer_step == 4 || sequencer_step == 6) { //256hz
|
||||
square1.clock_length();
|
||||
square2.clock_length();
|
||||
wave.clock_length();
|
||||
noise.clock_length();
|
||||
}
|
||||
if(sequencer_step == 2 || sequencer_step == 6) { //128hz
|
||||
square1.clock_sweep();
|
||||
}
|
||||
if(sequencer_step == 7) { //64hz
|
||||
square1.clock_envelope();
|
||||
square2.clock_envelope();
|
||||
noise.clock_envelope();
|
||||
}
|
||||
sequencer_step++;
|
||||
}
|
||||
sequencer_base++;
|
||||
|
||||
square1.run();
|
||||
square2.run();
|
||||
wave.run();
|
||||
noise.run();
|
||||
master.run();
|
||||
|
||||
system.interface->audio_sample(master.center, master.left, master.right);
|
||||
if(++clock >= 0) co_switch(scheduler.active_thread = cpu.thread);
|
||||
}
|
||||
}
|
||||
|
||||
void APU::power() {
|
||||
create(Main, 4194304);
|
||||
for(unsigned n = 0xff10; n <= 0xff3f; n++) bus.mmio[n] = this;
|
||||
|
||||
foreach(n, mmio_data) n = 0x00;
|
||||
sequencer_base = 0;
|
||||
sequencer_step = 0;
|
||||
|
||||
square1.power();
|
||||
square2.power();
|
||||
wave.power();
|
||||
noise.power();
|
||||
master.power();
|
||||
}
|
||||
|
||||
uint8 APU::mmio_read(uint16 addr) {
|
||||
static const uint8 table[48] = {
|
||||
0x80, 0x3f, 0x00, 0xff, 0xbf, //square1
|
||||
0xff, 0x3f, 0x00, 0xff, 0xbf, //square2
|
||||
0x7f, 0xff, 0x9f, 0xff, 0xbf, //wave
|
||||
0xff, 0xff, 0x00, 0x00, 0xbf, //noise
|
||||
0x00, 0x00, 0x70, //master
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //unmapped
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //wave pattern
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //wave pattern
|
||||
};
|
||||
|
||||
if(addr == 0xff26) {
|
||||
uint8 data = master.enable << 7;
|
||||
if(square1.counter && square1.length) data |= 0x01;
|
||||
if(square2.counter && square2.length) data |= 0x02;
|
||||
if( wave.counter && wave.length) data |= 0x04;
|
||||
if( noise.counter && noise.length) data |= 0x08;
|
||||
return data | table[addr - 0xff10];
|
||||
}
|
||||
|
||||
if(addr >= 0xff10 && addr <= 0xff3f) return mmio_data[addr - 0xff10] | table[addr - 0xff10];
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
void APU::mmio_write(uint16 addr, uint8 data) {
|
||||
if(addr >= 0xff10 && addr <= 0xff3f) mmio_data[addr - 0xff10] = data;
|
||||
|
||||
if(addr >= 0xff10 && addr <= 0xff14) return square1.write (addr - 0xff10, data);
|
||||
if(addr >= 0xff15 && addr <= 0xff19) return square2.write (addr - 0xff15, data);
|
||||
if(addr >= 0xff1a && addr <= 0xff1e) return wave.write (addr - 0xff1a, data);
|
||||
if(addr >= 0xff1f && addr <= 0xff23) return noise.write (addr - 0xff1f, data);
|
||||
if(addr >= 0xff24 && addr <= 0xff26) return master.write (addr - 0xff24, data);
|
||||
if(addr >= 0xff30 && addr <= 0xff3f) return wave.write_pattern(addr - 0xff30, data);
|
||||
}
|
||||
|
||||
}
|
28
bsnes/gameboy/apu/apu.hpp
Executable file
28
bsnes/gameboy/apu/apu.hpp
Executable file
@@ -0,0 +1,28 @@
|
||||
struct APU : Processor, MMIO {
|
||||
#include "square1/square1.hpp"
|
||||
#include "square2/square2.hpp"
|
||||
#include "wave/wave.hpp"
|
||||
#include "noise/noise.hpp"
|
||||
#include "master/master.hpp"
|
||||
|
||||
uint8 mmio_data[48];
|
||||
uint13 sequencer_base;
|
||||
uint3 sequencer_step;
|
||||
|
||||
Square1 square1;
|
||||
Square2 square2;
|
||||
Wave wave;
|
||||
Noise noise;
|
||||
Master master;
|
||||
|
||||
static void Main();
|
||||
void main();
|
||||
void power();
|
||||
|
||||
uint8 mmio_read(uint16 addr);
|
||||
void mmio_write(uint16 addr, uint8 data);
|
||||
|
||||
void serialize(serializer&);
|
||||
};
|
||||
|
||||
extern APU apu;
|
132
bsnes/gameboy/apu/master/master.cpp
Executable file
132
bsnes/gameboy/apu/master/master.cpp
Executable file
@@ -0,0 +1,132 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::Master::run() {
|
||||
if(enable == false) {
|
||||
center = 0;
|
||||
left = 0;
|
||||
right = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
signed sample = 0, channels;
|
||||
sample += apu.square1.output;
|
||||
sample += apu.square2.output;
|
||||
sample += apu.wave.output;
|
||||
sample += apu.noise.output;
|
||||
sample >>= 2;
|
||||
center = sclamp<16>(sample);
|
||||
|
||||
if(left_enable == false && right_enable == false) {
|
||||
left = center;
|
||||
right = center;
|
||||
return;
|
||||
}
|
||||
|
||||
sample = 0;
|
||||
channels = 0;
|
||||
if(channel1_left_enable) { sample += apu.square1.output; channels++; }
|
||||
if(channel2_left_enable) { sample += apu.square2.output; channels++; }
|
||||
if(channel3_left_enable) { sample += apu.wave.output; channels++; }
|
||||
if(channel4_left_enable) { sample += apu.noise.output; channels++; }
|
||||
if(channels) sample /= channels;
|
||||
left = sclamp<16>(sample);
|
||||
|
||||
switch(left_volume) {
|
||||
case 0: left >>= 3; break; // 12.5%
|
||||
case 1: left >>= 2; break; // 25.0%
|
||||
case 2: left = (left >> 2) + (left >> 3); break; // 37.5%
|
||||
case 3: left >>= 1; break; // 50.0%
|
||||
case 4: left = (left >> 1) + (left >> 3); break; // 62.5%
|
||||
case 5: left -= (left >> 2); break; // 75.0%
|
||||
case 6: left -= (left >> 3); break; // 87.5%
|
||||
//case 7: break; //100.0%
|
||||
}
|
||||
if(left_enable == false) left = 0;
|
||||
|
||||
sample = 0;
|
||||
channels = 0;
|
||||
if(channel1_right_enable) { sample += apu.square1.output; channels++; }
|
||||
if(channel2_right_enable) { sample += apu.square2.output; channels++; }
|
||||
if(channel3_right_enable) { sample += apu.wave.output; channels++; }
|
||||
if(channel4_right_enable) { sample += apu.noise.output; channels++; }
|
||||
if(channels) sample /= channels;
|
||||
right = sclamp<16>(sample);
|
||||
|
||||
switch(right_volume) {
|
||||
case 0: right >>= 3; break; // 12.5%
|
||||
case 1: right >>= 2; break; // 25.0%
|
||||
case 2: right = (right >> 2) + (right >> 3); break; // 37.5%
|
||||
case 3: right >>= 1; break; // 50.0%
|
||||
case 4: right = (right >> 1) + (right >> 3); break; // 62.5%
|
||||
case 5: right -= (right >> 2); break; // 75.0%
|
||||
case 6: right -= (right >> 3); break; // 87.5%
|
||||
//case 7: break; //100.0%
|
||||
}
|
||||
if(right_enable == false) right = 0;
|
||||
}
|
||||
|
||||
void APU::Master::write(unsigned r, uint8 data) {
|
||||
if(r == 0) {
|
||||
left_enable = data & 0x80;
|
||||
left_volume = (data >> 4) & 7;
|
||||
right_enable = data & 0x08;
|
||||
right_volume = (data >> 0) & 7;
|
||||
}
|
||||
|
||||
if(r == 1) {
|
||||
channel4_left_enable = data & 0x80;
|
||||
channel3_left_enable = data & 0x40;
|
||||
channel2_left_enable = data & 0x20;
|
||||
channel1_left_enable = data & 0x10;
|
||||
channel4_right_enable = data & 0x08;
|
||||
channel3_right_enable = data & 0x04;
|
||||
channel2_right_enable = data & 0x02;
|
||||
channel1_right_enable = data & 0x01;
|
||||
}
|
||||
|
||||
if(r == 2) {
|
||||
enable = data & 0x80;
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Master::power() {
|
||||
left_enable = 0;
|
||||
left_volume = 0;
|
||||
right_enable = 0;
|
||||
right_volume = 0;
|
||||
channel4_left_enable = 0;
|
||||
channel3_left_enable = 0;
|
||||
channel2_left_enable = 0;
|
||||
channel1_left_enable = 0;
|
||||
channel4_right_enable = 0;
|
||||
channel3_right_enable = 0;
|
||||
channel2_right_enable = 0;
|
||||
channel1_right_enable = 0;
|
||||
enable = 0;
|
||||
|
||||
center = 0;
|
||||
left = 0;
|
||||
right = 0;
|
||||
}
|
||||
|
||||
void APU::Master::serialize(serializer &s) {
|
||||
s.integer(left_enable);
|
||||
s.integer(left_volume);
|
||||
s.integer(right_enable);
|
||||
s.integer(right_volume);
|
||||
s.integer(channel4_left_enable);
|
||||
s.integer(channel3_left_enable);
|
||||
s.integer(channel2_left_enable);
|
||||
s.integer(channel1_left_enable);
|
||||
s.integer(channel4_right_enable);
|
||||
s.integer(channel3_right_enable);
|
||||
s.integer(channel2_right_enable);
|
||||
s.integer(channel1_right_enable);
|
||||
s.integer(enable);
|
||||
|
||||
s.integer(center);
|
||||
s.integer(left);
|
||||
s.integer(right);
|
||||
}
|
||||
|
||||
#endif
|
24
bsnes/gameboy/apu/master/master.hpp
Executable file
24
bsnes/gameboy/apu/master/master.hpp
Executable file
@@ -0,0 +1,24 @@
|
||||
struct Master {
|
||||
bool left_enable;
|
||||
unsigned left_volume;
|
||||
bool right_enable;
|
||||
unsigned right_volume;
|
||||
bool channel4_left_enable;
|
||||
bool channel3_left_enable;
|
||||
bool channel2_left_enable;
|
||||
bool channel1_left_enable;
|
||||
bool channel4_right_enable;
|
||||
bool channel3_right_enable;
|
||||
bool channel2_right_enable;
|
||||
bool channel1_right_enable;
|
||||
bool enable;
|
||||
|
||||
int16 center;
|
||||
int16 left;
|
||||
int16 right;
|
||||
|
||||
void run();
|
||||
void write(unsigned r, uint8 data);
|
||||
void power();
|
||||
void serialize(serializer&);
|
||||
};
|
102
bsnes/gameboy/apu/noise/noise.cpp
Executable file
102
bsnes/gameboy/apu/noise/noise.cpp
Executable file
@@ -0,0 +1,102 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::Noise::run() {
|
||||
if(period && --period == 0) {
|
||||
period = divisor << frequency;
|
||||
if(frequency < 14) {
|
||||
bool bit = (lfsr ^ (lfsr >> 1)) & 1;
|
||||
lfsr = (lfsr >> 1) ^ (bit << 14);
|
||||
if(narrow_lfsr) lfsr |= (bit << 6);
|
||||
}
|
||||
}
|
||||
|
||||
uint4 sample = (lfsr & 1) ? 0 : volume;
|
||||
if(counter && length == 0) sample = 0;
|
||||
|
||||
output = (sample * 4369) - 32768;
|
||||
}
|
||||
|
||||
void APU::Noise::clock_length() {
|
||||
if(counter && length) length--;
|
||||
}
|
||||
|
||||
void APU::Noise::clock_envelope() {
|
||||
if(envelope_period && --envelope_period == 0) {
|
||||
envelope_period = envelope_frequency;
|
||||
if(envelope_direction == 0 && volume > 0) volume--;
|
||||
if(envelope_direction == 1 && volume < 15) volume++;
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Noise::write(unsigned r, uint8 data) {
|
||||
if(r == 1) {
|
||||
initial_length = 64 - (data & 0x3f);
|
||||
|
||||
length = initial_length;
|
||||
}
|
||||
|
||||
if(r == 2) {
|
||||
envelope_volume = data >> 4;
|
||||
envelope_direction = data & 0x08;
|
||||
envelope_frequency = data & 0x07;
|
||||
}
|
||||
|
||||
if(r == 3) {
|
||||
frequency = data >> 4;
|
||||
narrow_lfsr = data & 0x08;
|
||||
divisor = (data & 0x07) << 4;
|
||||
if(divisor == 0) divisor = 8;
|
||||
|
||||
period = divisor << frequency;
|
||||
}
|
||||
|
||||
if(r == 4) {
|
||||
bool initialize = data & 0x80;
|
||||
counter = data & 0x40;
|
||||
|
||||
if(initialize) {
|
||||
lfsr = ~0U;
|
||||
length = initial_length;
|
||||
envelope_period = envelope_frequency;
|
||||
volume = envelope_volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Noise::power() {
|
||||
initial_length = 0;
|
||||
envelope_volume = 0;
|
||||
envelope_direction = 0;
|
||||
envelope_frequency = 0;
|
||||
frequency = 0;
|
||||
narrow_lfsr = 0;
|
||||
divisor = 0;
|
||||
counter = 0;
|
||||
|
||||
output = 0;
|
||||
length = 0;
|
||||
envelope_period = 0;
|
||||
volume = 0;
|
||||
period = 0;
|
||||
lfsr = 0;
|
||||
}
|
||||
|
||||
void APU::Noise::serialize(serializer &s) {
|
||||
s.integer(initial_length);
|
||||
s.integer(envelope_volume);
|
||||
s.integer(envelope_direction);
|
||||
s.integer(envelope_frequency);
|
||||
s.integer(frequency);
|
||||
s.integer(narrow_lfsr);
|
||||
s.integer(divisor);
|
||||
s.integer(counter);
|
||||
|
||||
s.integer(output);
|
||||
s.integer(length);
|
||||
s.integer(envelope_period);
|
||||
s.integer(volume);
|
||||
s.integer(period);
|
||||
s.integer(lfsr);
|
||||
}
|
||||
|
||||
#endif
|
24
bsnes/gameboy/apu/noise/noise.hpp
Executable file
24
bsnes/gameboy/apu/noise/noise.hpp
Executable file
@@ -0,0 +1,24 @@
|
||||
struct Noise {
|
||||
unsigned initial_length;
|
||||
unsigned envelope_volume;
|
||||
bool envelope_direction;
|
||||
unsigned envelope_frequency;
|
||||
unsigned frequency;
|
||||
bool narrow_lfsr;
|
||||
unsigned divisor;
|
||||
bool counter;
|
||||
|
||||
int16 output;
|
||||
unsigned length;
|
||||
unsigned envelope_period;
|
||||
unsigned volume;
|
||||
unsigned period;
|
||||
uint15 lfsr;
|
||||
|
||||
void run();
|
||||
void clock_length();
|
||||
void clock_envelope();
|
||||
void write(unsigned r, uint8 data);
|
||||
void power();
|
||||
void serialize(serializer&);
|
||||
};
|
15
bsnes/gameboy/apu/serialization.cpp
Executable file
15
bsnes/gameboy/apu/serialization.cpp
Executable file
@@ -0,0 +1,15 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::serialize(serializer &s) {
|
||||
s.array(mmio_data);
|
||||
s.integer(sequencer_base);
|
||||
s.integer(sequencer_step);
|
||||
|
||||
square1.serialize(s);
|
||||
square2.serialize(s);
|
||||
wave.serialize(s);
|
||||
noise.serialize(s);
|
||||
master.serialize(s);
|
||||
}
|
||||
|
||||
#endif
|
146
bsnes/gameboy/apu/square1/square1.cpp
Executable file
146
bsnes/gameboy/apu/square1/square1.cpp
Executable file
@@ -0,0 +1,146 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::Square1::run() {
|
||||
if(period && --period == 0) {
|
||||
period = 4 * (2048 - frequency);
|
||||
phase = (phase + 1) & 7;
|
||||
switch(duty) {
|
||||
case 0: duty_output = (phase == 6); break; //______-_
|
||||
case 1: duty_output = (phase >= 6); break; //______--
|
||||
case 2: duty_output = (phase >= 4); break; //____----
|
||||
case 3: duty_output = (phase <= 5); break; //------__
|
||||
}
|
||||
}
|
||||
|
||||
uint4 sample = (duty_output ? volume : 0);
|
||||
if(counter && length == 0) sample = 0;
|
||||
|
||||
output = (sample * 4369) - 32768;
|
||||
}
|
||||
|
||||
void APU::Square1::sweep() {
|
||||
if(enable == false) return;
|
||||
|
||||
signed offset = frequency_shadow >> sweep_shift;
|
||||
if(sweep_direction) offset = -offset;
|
||||
frequency_shadow += offset;
|
||||
|
||||
if(frequency_shadow < 0) {
|
||||
frequency_shadow = 0;
|
||||
} else if(frequency_shadow > 2047) {
|
||||
frequency_shadow = 2048;
|
||||
enable = false;
|
||||
}
|
||||
|
||||
if(frequency_shadow <= 2047 && sweep_shift) {
|
||||
frequency = frequency_shadow;
|
||||
period = 4 * (2048 - frequency);
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Square1::clock_length() {
|
||||
if(counter && length) length--;
|
||||
}
|
||||
|
||||
void APU::Square1::clock_sweep() {
|
||||
if(sweep_frequency && sweep_period && --sweep_period == 0) {
|
||||
sweep_period = sweep_frequency;
|
||||
sweep();
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Square1::clock_envelope() {
|
||||
if(envelope_period && --envelope_period == 0) {
|
||||
envelope_period = envelope_frequency;
|
||||
if(envelope_direction == 0 && volume > 0) volume--;
|
||||
if(envelope_direction == 1 && volume < 15) volume++;
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Square1::write(unsigned r, uint8 data) {
|
||||
if(r == 0) {
|
||||
sweep_frequency = (data >> 4) & 7;
|
||||
sweep_direction = data & 0x08;
|
||||
sweep_shift = data & 0x07;
|
||||
}
|
||||
|
||||
if(r == 1) {
|
||||
duty = data >> 6;
|
||||
length = data & 0x3f;
|
||||
}
|
||||
|
||||
if(r == 2) {
|
||||
envelope_volume = data >> 4;
|
||||
envelope_direction = data & 0x08;
|
||||
envelope_frequency = data & 0x07;
|
||||
}
|
||||
|
||||
if(r == 3) {
|
||||
frequency = (frequency & 0x0700) | data;
|
||||
}
|
||||
|
||||
if(r == 4) {
|
||||
bool initialize = data & 0x80;
|
||||
counter = data & 0x40;
|
||||
frequency = ((data & 7) << 8) | (frequency & 0x00ff);
|
||||
|
||||
if(initialize) {
|
||||
envelope_period = envelope_frequency;
|
||||
volume = envelope_volume;
|
||||
frequency_shadow = frequency;
|
||||
sweep_period = sweep_frequency;
|
||||
enable = sweep_period || sweep_shift;
|
||||
if(sweep_shift) sweep();
|
||||
}
|
||||
}
|
||||
|
||||
period = 4 * (2048 - frequency);
|
||||
}
|
||||
|
||||
void APU::Square1::power() {
|
||||
sweep_frequency = 0;
|
||||
sweep_direction = 0;
|
||||
sweep_shift = 0;
|
||||
duty = 0;
|
||||
length = 0;
|
||||
envelope_volume = 0;
|
||||
envelope_direction = 0;
|
||||
envelope_frequency = 0;
|
||||
frequency = 0;
|
||||
counter = 0;
|
||||
|
||||
output = 0;
|
||||
duty_output = 0;
|
||||
phase = 0;
|
||||
period = 0;
|
||||
envelope_period = 0;
|
||||
sweep_period = 0;
|
||||
frequency_shadow = 0;
|
||||
enable = 0;
|
||||
volume = 0;
|
||||
}
|
||||
|
||||
void APU::Square1::serialize(serializer &s) {
|
||||
s.integer(sweep_frequency);
|
||||
s.integer(sweep_direction);
|
||||
s.integer(sweep_shift);
|
||||
s.integer(duty);
|
||||
s.integer(length);
|
||||
s.integer(envelope_volume);
|
||||
s.integer(envelope_direction);
|
||||
s.integer(envelope_frequency);
|
||||
s.integer(frequency);
|
||||
s.integer(counter);
|
||||
|
||||
s.integer(output);
|
||||
s.integer(duty_output);
|
||||
s.integer(phase);
|
||||
s.integer(period);
|
||||
s.integer(envelope_period);
|
||||
s.integer(sweep_period);
|
||||
s.integer(frequency_shadow);
|
||||
s.integer(enable);
|
||||
s.integer(volume);
|
||||
}
|
||||
|
||||
#endif
|
31
bsnes/gameboy/apu/square1/square1.hpp
Executable file
31
bsnes/gameboy/apu/square1/square1.hpp
Executable file
@@ -0,0 +1,31 @@
|
||||
struct Square1 {
|
||||
unsigned sweep_frequency;
|
||||
unsigned sweep_direction;
|
||||
unsigned sweep_shift;
|
||||
unsigned duty;
|
||||
unsigned length;
|
||||
unsigned envelope_volume;
|
||||
unsigned envelope_direction;
|
||||
unsigned envelope_frequency;
|
||||
unsigned frequency;
|
||||
unsigned counter;
|
||||
|
||||
int16 output;
|
||||
bool duty_output;
|
||||
unsigned phase;
|
||||
unsigned period;
|
||||
unsigned envelope_period;
|
||||
unsigned sweep_period;
|
||||
signed frequency_shadow;
|
||||
bool enable;
|
||||
unsigned volume;
|
||||
|
||||
void run();
|
||||
void sweep();
|
||||
void clock_length();
|
||||
void clock_sweep();
|
||||
void clock_envelope();
|
||||
void write(unsigned r, uint8 data);
|
||||
void power();
|
||||
void serialize(serializer&);
|
||||
};
|
97
bsnes/gameboy/apu/square2/square2.cpp
Executable file
97
bsnes/gameboy/apu/square2/square2.cpp
Executable file
@@ -0,0 +1,97 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::Square2::run() {
|
||||
if(period && --period == 0) {
|
||||
period = 4 * (2048 - frequency);
|
||||
phase = (phase + 1) & 7;
|
||||
switch(duty) {
|
||||
case 0: duty_output = (phase == 6); break; //______-_
|
||||
case 1: duty_output = (phase >= 6); break; //______--
|
||||
case 2: duty_output = (phase >= 4); break; //____----
|
||||
case 3: duty_output = (phase <= 5); break; //------__
|
||||
}
|
||||
}
|
||||
|
||||
uint4 sample = (duty_output ? volume : 0);
|
||||
if(counter && length == 0) sample = 0;
|
||||
|
||||
output = (sample * 4369) - 32768;
|
||||
}
|
||||
|
||||
void APU::Square2::clock_length() {
|
||||
if(counter && length) length--;
|
||||
}
|
||||
|
||||
void APU::Square2::clock_envelope() {
|
||||
if(envelope_period && --envelope_period == 0) {
|
||||
envelope_period = envelope_frequency;
|
||||
if(envelope_direction == 0 && volume > 0) volume--;
|
||||
if(envelope_direction == 1 && volume < 15) volume++;
|
||||
}
|
||||
}
|
||||
|
||||
void APU::Square2::write(unsigned r, uint8 data) {
|
||||
if(r == 1) {
|
||||
duty = data >> 6;
|
||||
length = data & 0x3f;
|
||||
}
|
||||
|
||||
if(r == 2) {
|
||||
envelope_volume = data >> 4;
|
||||
envelope_direction = data & 0x08;
|
||||
envelope_frequency = data & 0x07;
|
||||
}
|
||||
|
||||
if(r == 3) {
|
||||
frequency = (frequency & 0x0700) | data;
|
||||
}
|
||||
|
||||
if(r == 4) {
|
||||
bool initialize = data & 0x80;
|
||||
counter = data & 0x40;
|
||||
frequency = ((data & 7) << 8) | (frequency & 0x00ff);
|
||||
|
||||
if(initialize) {
|
||||
envelope_period = envelope_frequency;
|
||||
volume = envelope_volume;
|
||||
}
|
||||
}
|
||||
|
||||
period = 4 * (2048 - frequency);
|
||||
}
|
||||
|
||||
void APU::Square2::power() {
|
||||
duty = 0;
|
||||
length = 0;
|
||||
envelope_volume = 0;
|
||||
envelope_direction = 0;
|
||||
envelope_frequency = 0;
|
||||
frequency = 0;
|
||||
counter = 0;
|
||||
|
||||
output = 0;
|
||||
duty_output = 0;
|
||||
phase = 0;
|
||||
period = 0;
|
||||
envelope_period = 0;
|
||||
volume = 0;
|
||||
}
|
||||
|
||||
void APU::Square2::serialize(serializer &s) {
|
||||
s.integer(duty);
|
||||
s.integer(length);
|
||||
s.integer(envelope_volume);
|
||||
s.integer(envelope_direction);
|
||||
s.integer(envelope_frequency);
|
||||
s.integer(frequency);
|
||||
s.integer(counter);
|
||||
|
||||
s.integer(output);
|
||||
s.integer(duty_output);
|
||||
s.integer(phase);
|
||||
s.integer(period);
|
||||
s.integer(envelope_period);
|
||||
s.integer(volume);
|
||||
}
|
||||
|
||||
#endif
|
23
bsnes/gameboy/apu/square2/square2.hpp
Executable file
23
bsnes/gameboy/apu/square2/square2.hpp
Executable file
@@ -0,0 +1,23 @@
|
||||
struct Square2 {
|
||||
unsigned duty;
|
||||
unsigned length;
|
||||
unsigned envelope_volume;
|
||||
unsigned envelope_direction;
|
||||
unsigned envelope_frequency;
|
||||
unsigned frequency;
|
||||
unsigned counter;
|
||||
|
||||
int16 output;
|
||||
bool duty_output;
|
||||
unsigned phase;
|
||||
unsigned period;
|
||||
unsigned envelope_period;
|
||||
unsigned volume;
|
||||
|
||||
void run();
|
||||
void clock_length();
|
||||
void clock_envelope();
|
||||
void write(unsigned r, uint8 data);
|
||||
void power();
|
||||
void serialize(serializer&);
|
||||
};
|
103
bsnes/gameboy/apu/wave/wave.cpp
Executable file
103
bsnes/gameboy/apu/wave/wave.cpp
Executable file
@@ -0,0 +1,103 @@
|
||||
#ifdef APU_CPP
|
||||
|
||||
void APU::Wave::run() {
|
||||
if(period && --period == 0) {
|
||||
period = 2 * (2048 - frequency);
|
||||
pattern_offset = (pattern_offset + 1) & 31;
|
||||
pattern_sample = pattern[pattern_offset];
|
||||
}
|
||||
|
||||
uint4 sample = pattern_sample;
|
||||
if(counter && length == 0) sample = 0;
|
||||
if(enable == false) sample = 0;
|
||||
|
||||
output = (sample * 4369) - 32768;
|
||||
output >>= volume;
|
||||
}
|
||||
|
||||
void APU::Wave::clock_length() {
|
||||
if(counter && length) length--;
|
||||
}
|
||||
|
||||
void APU::Wave::write(unsigned r, uint8 data) {
|
||||
if(r == 0) {
|
||||
dac_enable = data & 0x80;
|
||||
|
||||
if(dac_enable == false) enable = false;
|
||||
}
|
||||
|
||||
if(r == 1) {
|
||||
initial_length = 256 - data;
|
||||
|
||||
length = initial_length;
|
||||
}
|
||||
|
||||
if(r == 2) {
|
||||
switch((data >> 5) & 3) {
|
||||
case 0: volume = 16; break; // 0%
|
||||
case 1: volume = 0; break; //100%
|
||||
case 2: volume = 1; break; // 50%
|
||||
case 3: volume = 2; break; // 25%
|
||||
}
|
||||
}
|
||||
|
||||
if(r == 3) {
|
||||
frequency = (frequency & 0x0700) | data;
|
||||
}
|
||||
|
||||
if(r == 4) {
|
||||
bool initialize = data & 0x80;
|
||||
counter = data & 0x40;
|
||||
frequency = ((data & 7) << 8) | (frequency & 0x00ff);
|
||||
|
||||
if(initialize && dac_enable) {
|
||||
enable = true;
|
||||
pattern_offset = 0;
|
||||
length = initial_length;
|
||||
}
|
||||
}
|
||||
|
||||
period = 2 * (2048 - frequency);
|
||||
}
|
||||
|
||||
void APU::Wave::write_pattern(unsigned p, uint8 data) {
|
||||
p <<= 1;
|
||||
pattern[p + 0] = (data >> 4) & 15;
|
||||
pattern[p + 1] = (data >> 0) & 15;
|
||||
}
|
||||
|
||||
void APU::Wave::power() {
|
||||
dac_enable = 0;
|
||||
initial_length = 0;
|
||||
volume = 0;
|
||||
frequency = 0;
|
||||
counter = 0;
|
||||
|
||||
random_lfsr r;
|
||||
foreach(n, pattern) n = r() & 15;
|
||||
|
||||
output = 0;
|
||||
enable = 0;
|
||||
length = 0;
|
||||
period = 0;
|
||||
pattern_offset = 0;
|
||||
pattern_sample = 0;
|
||||
}
|
||||
|
||||
void APU::Wave::serialize(serializer &s) {
|
||||
s.integer(dac_enable);
|
||||
s.integer(initial_length);
|
||||
s.integer(volume);
|
||||
s.integer(frequency);
|
||||
s.integer(counter);
|
||||
s.array(pattern);
|
||||
|
||||
s.integer(output);
|
||||
s.integer(enable);
|
||||
s.integer(length);
|
||||
s.integer(period);
|
||||
s.integer(pattern_offset);
|
||||
s.integer(pattern_sample);
|
||||
}
|
||||
|
||||
#endif
|
22
bsnes/gameboy/apu/wave/wave.hpp
Executable file
22
bsnes/gameboy/apu/wave/wave.hpp
Executable file
@@ -0,0 +1,22 @@
|
||||
struct Wave {
|
||||
bool dac_enable;
|
||||
unsigned initial_length;
|
||||
unsigned volume;
|
||||
unsigned frequency;
|
||||
bool counter;
|
||||
uint8 pattern[32];
|
||||
|
||||
int16 output;
|
||||
bool enable;
|
||||
unsigned length;
|
||||
unsigned period;
|
||||
unsigned pattern_offset;
|
||||
unsigned pattern_sample;
|
||||
|
||||
void run();
|
||||
void clock_length();
|
||||
void write(unsigned r, uint8 data);
|
||||
void write_pattern(unsigned p, uint8 data);
|
||||
void power();
|
||||
void serialize(serializer&);
|
||||
};
|
@@ -16,13 +16,14 @@ namespace GameBoy {
|
||||
#include "serialization.cpp"
|
||||
Cartridge cartridge;
|
||||
|
||||
void Cartridge::load(const string &xml, uint8_t *data, unsigned size) {
|
||||
void Cartridge::load(const string &xml, const uint8_t *data, unsigned size) {
|
||||
if(size == 0) size = 32768;
|
||||
romdata = allocate<uint8>(romsize = size, 0xff);
|
||||
if(data) memcpy(romdata, data, size);
|
||||
|
||||
//uint32_t crc = crc32_calculate(data, size);
|
||||
//print("CRC32 = ", hex<4>(crc), "\n");
|
||||
|
||||
romdata = new uint8[romsize = size];
|
||||
memcpy(romdata, data, size);
|
||||
|
||||
info.mapper = Mapper::Unknown;
|
||||
info.ram = false;
|
||||
info.battery = false;
|
||||
@@ -69,7 +70,19 @@ void Cartridge::load(const string &xml, uint8_t *data, unsigned size) {
|
||||
}
|
||||
}
|
||||
|
||||
switch(info.mapper) { default:
|
||||
case Mapper::MBC0: mapper = &mbc0; break;
|
||||
case Mapper::MBC1: mapper = &mbc1; break;
|
||||
case Mapper::MBC2: mapper = &mbc2; break;
|
||||
case Mapper::MBC3: mapper = &mbc3; break;
|
||||
case Mapper::MBC5: mapper = &mbc5; break;
|
||||
case Mapper::MMM01: mapper = &mmm01; break;
|
||||
case Mapper::HuC1: mapper = &huc1; break;
|
||||
case Mapper::HuC3: mapper = &huc3; break;
|
||||
}
|
||||
|
||||
ramdata = new uint8_t[ramsize = info.ramsize]();
|
||||
system.load();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
@@ -103,7 +116,19 @@ void Cartridge::ram_write(unsigned addr, uint8 data) {
|
||||
ramdata[addr] = data;
|
||||
}
|
||||
|
||||
uint8 Cartridge::mmio_read(uint16 addr) {
|
||||
if(bootrom_enable && within<0x0000, 0x00ff>(addr)) return System::BootROM::sgb[addr];
|
||||
return mapper->mmio_read(addr);
|
||||
}
|
||||
|
||||
void Cartridge::mmio_write(uint16 addr, uint8 data) {
|
||||
if(bootrom_enable && addr == 0xff50) bootrom_enable = false;
|
||||
mapper->mmio_write(addr, data);
|
||||
}
|
||||
|
||||
void Cartridge::power() {
|
||||
bootrom_enable = true;
|
||||
|
||||
mbc0.power();
|
||||
mbc1.power();
|
||||
mbc2.power();
|
||||
@@ -112,26 +137,10 @@ void Cartridge::power() {
|
||||
mmm01.power();
|
||||
huc1.power();
|
||||
huc3.power();
|
||||
map();
|
||||
}
|
||||
|
||||
void Cartridge::map() {
|
||||
MMIO *mapper = 0;
|
||||
switch(info.mapper) { default:
|
||||
case Mapper::MBC0: mapper = &mbc0; break;
|
||||
case Mapper::MBC1: mapper = &mbc1; break;
|
||||
case Mapper::MBC2: mapper = &mbc2; break;
|
||||
case Mapper::MBC3: mapper = &mbc3; break;
|
||||
case Mapper::MBC5: mapper = &mbc5; break;
|
||||
case Mapper::MMM01: mapper = &mmm01; break;
|
||||
case Mapper::HuC1: mapper = &huc1; break;
|
||||
case Mapper::HuC3: mapper = &huc3; break;
|
||||
}
|
||||
|
||||
if(mapper) {
|
||||
for(unsigned n = 0x0000; n <= 0x7fff; n++) bus.mmio[n] = mapper;
|
||||
for(unsigned n = 0xa000; n <= 0xbfff; n++) bus.mmio[n] = mapper;
|
||||
}
|
||||
for(unsigned n = 0x0000; n <= 0x7fff; n++) bus.mmio[n] = this;
|
||||
for(unsigned n = 0xa000; n <= 0xbfff; n++) bus.mmio[n] = this;
|
||||
bus.mmio[0xff50] = this;
|
||||
}
|
||||
|
||||
Cartridge::Cartridge() {
|
||||
|
@@ -1,4 +1,4 @@
|
||||
struct Cartridge : property<Cartridge> {
|
||||
struct Cartridge : MMIO, property<Cartridge> {
|
||||
#include "mbc0/mbc0.hpp"
|
||||
#include "mbc1/mbc1.hpp"
|
||||
#include "mbc2/mbc2.hpp"
|
||||
@@ -41,7 +41,10 @@ struct Cartridge : property<Cartridge> {
|
||||
uint8_t *ramdata;
|
||||
unsigned ramsize;
|
||||
|
||||
void load(const string &xml, uint8_t *data, unsigned size);
|
||||
MMIO *mapper;
|
||||
bool bootrom_enable;
|
||||
|
||||
void load(const string &xml, const uint8_t *data, unsigned size);
|
||||
void unload();
|
||||
|
||||
uint8 rom_read(unsigned addr);
|
||||
@@ -49,8 +52,10 @@ struct Cartridge : property<Cartridge> {
|
||||
uint8 ram_read(unsigned addr);
|
||||
void ram_write(unsigned addr, uint8 data);
|
||||
|
||||
uint8 mmio_read(uint16 addr);
|
||||
void mmio_write(uint16 addr, uint8 data);
|
||||
|
||||
void power();
|
||||
void map();
|
||||
|
||||
void serialize(serializer&);
|
||||
Cartridge();
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::HuC1::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) return cartridge.ram_read((ram_select << 13) | (addr & 0x1fff));
|
||||
return 0x00;
|
||||
}
|
||||
@@ -18,27 +18,27 @@ uint8 Cartridge::HuC1::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::HuC1::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x2000) { //2000-3fff
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
rom_select = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
ram_select = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x6000) { //6000-7fff
|
||||
if(within<0x6000, 0x7fff>(addr)) {
|
||||
//unknown purpose
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) cartridge.ram_write((ram_select << 13) | (addr & 0x1fff), data);
|
||||
return;
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::HuC3::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) return cartridge.ram_read((ram_select << 13) | (addr & 0x1fff));
|
||||
return 0x00;
|
||||
}
|
||||
@@ -18,27 +18,27 @@ uint8 Cartridge::HuC3::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::HuC3::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x2000) { //2000-3fff
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
rom_select = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
ram_select = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x6000) { //6000-7fff
|
||||
if(within<0x6000, 0x7fff>(addr)) {
|
||||
//unknown purpose
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) cartridge.ram_write((ram_select << 13) | (addr & 0x1fff), data);
|
||||
return;
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::MBC0::mmio_read(uint16 addr) {
|
||||
if((addr & 0x8000) == 0x0000) { //0000-7fff
|
||||
if(within<0x0000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
return cartridge.ram_read(addr & 0x1fff);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ uint8 Cartridge::MBC0::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MBC0::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
cartridge.ram_write(addr & 0x1fff, data);
|
||||
return;
|
||||
}
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::MBC1::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
if(mode_select == 0) {
|
||||
return cartridge.rom_read((ram_select << 19) | (rom_select << 14) | (addr & 0x3fff));
|
||||
} else {
|
||||
@@ -13,7 +13,7 @@ uint8 Cartridge::MBC1::mmio_read(uint16 addr) {
|
||||
}
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) {
|
||||
if(mode_select == 0) {
|
||||
return cartridge.ram_read(addr & 0x1fff);
|
||||
@@ -28,27 +28,27 @@ uint8 Cartridge::MBC1::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MBC1::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x2000) { //2000-3fff
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
rom_select = (data & 0x1f) + ((data & 0x1f) == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
ram_select = data & 0x03;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x6000) { //6000-7fff
|
||||
if(within<0x6000, 0x7fff>(addr)) {
|
||||
mode_select = data & 0x01;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) {
|
||||
if(mode_select == 0) {
|
||||
cartridge.ram_write(addr & 0x1fff, data);
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::MBC2::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xfe00) == 0xa000) { //a000-a1ff
|
||||
if(within<0xa000, 0xa1ff>(addr)) {
|
||||
if(ram_enable) return cartridge.ram_read(addr & 0x1ff);
|
||||
return 0x00;
|
||||
}
|
||||
@@ -18,17 +18,17 @@ uint8 Cartridge::MBC2::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MBC2::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe100) == 0x0000) { //0000-1fff [d8=0]
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
if(!(addr & 0x0100)) ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe100) == 0x2100) { //2000-3fff [d8=1]
|
||||
rom_select = (data & 0x0f) + ((data & 0x0f) == 0);
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
if( (addr & 0x0100)) rom_select = (data & 0x0f) + ((data & 0x0f) == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xfe00) == 0xa000) { //a000-a1ff
|
||||
if(within<0xa000, 0xa1ff>(addr)) {
|
||||
if(ram_enable) cartridge.ram_write(addr & 0x1ff, data & 0x0f);
|
||||
return;
|
||||
}
|
||||
|
@@ -19,15 +19,15 @@ void Cartridge::MBC3::second() {
|
||||
}
|
||||
|
||||
uint8 Cartridge::MBC3::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) {
|
||||
if(ram_select >= 0x00 && ram_select <= 0x03) {
|
||||
return cartridge.ram_read((ram_select << 13) | (addr & 0x1fff));
|
||||
@@ -45,22 +45,22 @@ uint8 Cartridge::MBC3::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MBC3::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x2000) { //2000-3fff
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
rom_select = (data & 0x7f) + ((data & 0x7f) == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
ram_select = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x6000) { //6000-7fff
|
||||
if(within<0x6000, 0x7fff>(addr)) {
|
||||
if(rtc_latch == 0 && data == 1) {
|
||||
rtc_latch_second = rtc_second;
|
||||
rtc_latch_minute = rtc_minute;
|
||||
@@ -72,7 +72,7 @@ void Cartridge::MBC3::mmio_write(uint16 addr, uint8 data) {
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) {
|
||||
if(ram_select >= 0x00 && ram_select <= 0x03) {
|
||||
cartridge.ram_write((ram_select << 13) | (addr & 0x1fff), data);
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::MBC5::mmio_read(uint16 addr) {
|
||||
if((addr & 0xc000) == 0x0000) { //0000-3fff
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) { //4000-7fff
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read((rom_select << 14) | (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) return cartridge.ram_read((ram_select << 13) | (addr & 0x1fff));
|
||||
return 0x00;
|
||||
}
|
||||
@@ -18,27 +18,27 @@ uint8 Cartridge::MBC5::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MBC5::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
ram_enable = (data & 0x0f) == 0x0a;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xf000) == 0x2000) { //2000-2fff
|
||||
if(within<0x2000, 0x2fff>(addr)) {
|
||||
rom_select = (rom_select & 0x0100) | data;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xf000) == 0x3000) { //3000-3fff
|
||||
if(within<0x3000, 0x3fff>(addr)) {
|
||||
rom_select = ((data & 1) << 8) | (rom_select & 0x00ff);
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
ram_select = data & 0x0f;
|
||||
return;
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) cartridge.ram_write((ram_select << 13) | (addr & 0x1fff), data);
|
||||
return;
|
||||
}
|
||||
|
@@ -1,19 +1,19 @@
|
||||
#ifdef CARTRIDGE_CPP
|
||||
|
||||
uint8 Cartridge::MMM01::mmio_read(uint16 addr) {
|
||||
if((addr & 0x8000) == 0x0000) {
|
||||
if(within<0x0000, 0x7fff>(addr)) {
|
||||
if(rom_mode == 0) return cartridge.rom_read(addr);
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x0000) {
|
||||
if(within<0x0000, 0x3fff>(addr)) {
|
||||
return cartridge.rom_read(0x8000 + (rom_base << 14) + (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xc000) == 0x4000) {
|
||||
if(within<0x4000, 0x7fff>(addr)) {
|
||||
return cartridge.rom_read(0x8000 + (rom_base << 14) + (rom_select << 14) + (addr & 0x3fff));
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) {
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) return cartridge.ram_read((ram_select << 13) + (addr & 0x1fff));
|
||||
return 0x00;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ uint8 Cartridge::MMM01::mmio_read(uint16 addr) {
|
||||
}
|
||||
|
||||
void Cartridge::MMM01::mmio_write(uint16 addr, uint8 data) {
|
||||
if((addr & 0xe000) == 0x0000) { //0000-1fff
|
||||
if(within<0x0000, 0x1fff>(addr)) {
|
||||
if(rom_mode == 0) {
|
||||
rom_mode = 1;
|
||||
} else {
|
||||
@@ -30,7 +30,7 @@ void Cartridge::MMM01::mmio_write(uint16 addr, uint8 data) {
|
||||
}
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x2000) { //2000-3fff
|
||||
if(within<0x2000, 0x3fff>(addr)) {
|
||||
if(rom_mode == 0) {
|
||||
rom_base = data & 0x3f;
|
||||
} else {
|
||||
@@ -38,17 +38,17 @@ void Cartridge::MMM01::mmio_write(uint16 addr, uint8 data) {
|
||||
}
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x4000) { //4000-5fff
|
||||
if(within<0x4000, 0x5fff>(addr)) {
|
||||
if(rom_mode == 1) {
|
||||
ram_select = data;
|
||||
}
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0x6000) { //6000-7fff
|
||||
if(within<0x6000, 0x7fff>(addr)) {
|
||||
//unknown purpose
|
||||
}
|
||||
|
||||
if((addr & 0xe000) == 0xa000) { //a000-bfff
|
||||
if(within<0xa000, 0xbfff>(addr)) {
|
||||
if(ram_enable) cartridge.ram_write((ram_select << 13) + (addr & 0x1fff), data);
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
void Cartridge::serialize(serializer &s) {
|
||||
if(info.battery) s.array(ramdata, ramsize);
|
||||
s.integer(bootrom_enable);
|
||||
|
||||
s.integer(mbc1.ram_enable);
|
||||
s.integer(mbc1.rom_select);
|
||||
|
@@ -28,14 +28,30 @@ void CPU::main() {
|
||||
}
|
||||
|
||||
void CPU::interrupt_raise(CPU::Interrupt id) {
|
||||
switch(id) {
|
||||
case Interrupt::Vblank: status.interrupt_request_vblank = 1; break;
|
||||
case Interrupt::Stat : status.interrupt_request_stat = 1; break;
|
||||
case Interrupt::Timer : status.interrupt_request_timer = 1; break;
|
||||
case Interrupt::Serial: status.interrupt_request_serial = 1; break;
|
||||
case Interrupt::Joypad: status.interrupt_request_joypad = 1; status.stop = false; break;
|
||||
if(id == Interrupt::Vblank) {
|
||||
status.interrupt_request_vblank = 1;
|
||||
if(status.interrupt_enable_vblank) status.halt = false;
|
||||
}
|
||||
|
||||
if(id == Interrupt::Stat) {
|
||||
status.interrupt_request_stat = 1;
|
||||
if(status.interrupt_enable_stat) status.halt = false;
|
||||
}
|
||||
|
||||
if(id == Interrupt::Timer) {
|
||||
status.interrupt_request_timer = 1;
|
||||
if(status.interrupt_enable_timer) status.halt = false;
|
||||
}
|
||||
|
||||
if(id == Interrupt::Serial) {
|
||||
status.interrupt_request_serial = 1;
|
||||
if(status.interrupt_enable_serial) status.halt = false;
|
||||
}
|
||||
|
||||
if(id == Interrupt::Joypad) {
|
||||
status.interrupt_request_joypad = 1;
|
||||
if(status.interrupt_enable_joypad) status.halt = status.stop = false;
|
||||
}
|
||||
status.halt = false;
|
||||
}
|
||||
|
||||
void CPU::interrupt_test() {
|
||||
@@ -78,7 +94,7 @@ void CPU::interrupt_exec(uint16 pc) {
|
||||
}
|
||||
|
||||
void CPU::power() {
|
||||
create(Main, 4 * 1024 * 1024);
|
||||
create(Main, 4194304);
|
||||
|
||||
for(unsigned n = 0xc000; n <= 0xdfff; n++) bus.mmio[n] = this; //WRAM
|
||||
for(unsigned n = 0xe000; n <= 0xfdff; n++) bus.mmio[n] = this; //WRAM (mirror)
|
||||
@@ -98,18 +114,19 @@ void CPU::power() {
|
||||
status.clock = 0;
|
||||
status.halt = false;
|
||||
status.stop = false;
|
||||
|
||||
status.ime = 0;
|
||||
status.timer0 = 0;
|
||||
status.timer1 = 0;
|
||||
status.timer2 = 0;
|
||||
status.timer3 = 0;
|
||||
|
||||
status.p15 = 0;
|
||||
status.p14 = 0;
|
||||
status.joyp = 0;
|
||||
status.mlt_req = 0;
|
||||
|
||||
status.serial_data = 0;
|
||||
status.serial_bits = 0;
|
||||
|
||||
status.serial_transfer = 0;
|
||||
status.serial_clock = 0;
|
||||
|
||||
status.div = 0;
|
||||
|
||||
status.tima = 0;
|
||||
|
@@ -17,12 +17,7 @@ struct CPU : Processor, MMIO {
|
||||
unsigned clock;
|
||||
bool halt;
|
||||
bool stop;
|
||||
|
||||
bool ime;
|
||||
unsigned timer0;
|
||||
unsigned timer1;
|
||||
unsigned timer2;
|
||||
unsigned timer3;
|
||||
|
||||
//$ff00 JOYP
|
||||
bool p15;
|
||||
@@ -30,6 +25,14 @@ struct CPU : Processor, MMIO {
|
||||
uint8 joyp;
|
||||
uint8 mlt_req;
|
||||
|
||||
//$ff01 SB
|
||||
uint8 serial_data;
|
||||
unsigned serial_bits;
|
||||
|
||||
//$ff02 SC
|
||||
bool serial_transfer;
|
||||
bool serial_clock;
|
||||
|
||||
//$ff04 DIV
|
||||
uint8 div;
|
||||
|
||||
@@ -72,4 +75,4 @@ struct CPU : Processor, MMIO {
|
||||
CPU();
|
||||
};
|
||||
|
||||
extern CPU cpu;
|
||||
extern CPU cpu;
|
||||
|
@@ -31,6 +31,15 @@ uint8 CPU::mmio_read(uint16 addr) {
|
||||
| (status.joyp << 0);
|
||||
}
|
||||
|
||||
if(addr == 0xff01) { //SB
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
if(addr == 0xff02) { //SC
|
||||
return (status.serial_transfer << 7)
|
||||
| (status.serial_clock << 0);
|
||||
}
|
||||
|
||||
if(addr == 0xff04) { //DIV
|
||||
return status.div;
|
||||
}
|
||||
@@ -81,10 +90,14 @@ void CPU::mmio_write(uint16 addr, uint8 data) {
|
||||
}
|
||||
|
||||
if(addr == 0xff01) { //SB
|
||||
status.serial_data = data;
|
||||
return;
|
||||
}
|
||||
|
||||
if(addr == 0xff02) { //SC
|
||||
status.serial_transfer = data & 0x80;
|
||||
status.serial_clock = data & 0x01;
|
||||
if(status.serial_transfer) status.serial_bits = 8;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -21,18 +21,19 @@ void CPU::serialize(serializer &s) {
|
||||
s.integer(status.clock);
|
||||
s.integer(status.halt);
|
||||
s.integer(status.stop);
|
||||
|
||||
s.integer(status.ime);
|
||||
s.integer(status.timer0);
|
||||
s.integer(status.timer1);
|
||||
s.integer(status.timer2);
|
||||
s.integer(status.timer3);
|
||||
|
||||
s.integer(status.p15);
|
||||
s.integer(status.p14);
|
||||
s.integer(status.joyp);
|
||||
s.integer(status.mlt_req);
|
||||
|
||||
s.integer(status.serial_data);
|
||||
s.integer(status.serial_bits);
|
||||
|
||||
s.integer(status.serial_transfer);
|
||||
s.integer(status.serial_clock);
|
||||
|
||||
s.integer(status.div);
|
||||
s.integer(status.tima);
|
||||
s.integer(status.tma);
|
||||
|
@@ -1,13 +1,9 @@
|
||||
//4194304hz (4 * 1024 * 1024)
|
||||
|
||||
//70224 clocks/frame
|
||||
// 456 clocks/scanline
|
||||
// 154 scanlines/frame
|
||||
|
||||
//4194304 / 4096 = 1024
|
||||
//4194304 / 262144 = 16
|
||||
//4194304 / 65536 = 64
|
||||
//4394304 / 16384 = 256
|
||||
|
||||
#ifdef CPU_CPP
|
||||
|
||||
#include "opcode.cpp"
|
||||
@@ -17,43 +13,44 @@ void CPU::add_clocks(unsigned clocks) {
|
||||
scheduler.exit(Scheduler::ExitReason::StepEvent);
|
||||
|
||||
status.clock += clocks;
|
||||
if(status.clock >= 4 * 1024 * 1024) {
|
||||
status.clock -= 4 * 1024 * 1024;
|
||||
if(status.clock >= 4194304) {
|
||||
status.clock -= 4194304;
|
||||
cartridge.mbc3.second();
|
||||
}
|
||||
|
||||
status.timer0 += clocks;
|
||||
if(status.timer0 >= 16) timer_stage0();
|
||||
//4194304 / N(hz) - 1 = mask
|
||||
if((status.clock & 15) == 0) timer_262144hz();
|
||||
if((status.clock & 63) == 0) timer_65536hz();
|
||||
if((status.clock & 255) == 0) timer_16384hz();
|
||||
if((status.clock & 511) == 0) timer_8192hz();
|
||||
if((status.clock & 1023) == 0) timer_4096hz();
|
||||
|
||||
cpu.clock += clocks;
|
||||
if(cpu.clock >= 0) co_switch(scheduler.active_thread = lcd.thread);
|
||||
lcd.clock -= clocks;
|
||||
if(lcd.clock <= 0) co_switch(scheduler.active_thread = lcd.thread);
|
||||
|
||||
apu.clock -= clocks;
|
||||
if(apu.clock <= 0) co_switch(scheduler.active_thread = apu.thread);
|
||||
}
|
||||
|
||||
void CPU::timer_stage0() { //262144hz
|
||||
void CPU::timer_262144hz() {
|
||||
if(status.timer_enable && status.timer_clock == 1) {
|
||||
if(++status.tima == 0) {
|
||||
status.tima = status.tma;
|
||||
interrupt_raise(Interrupt::Timer);
|
||||
}
|
||||
}
|
||||
|
||||
status.timer0 -= 16;
|
||||
if(++status.timer1 >= 4) timer_stage1();
|
||||
}
|
||||
|
||||
void CPU::timer_stage1() { // 65536hz
|
||||
void CPU::timer_65536hz() {
|
||||
if(status.timer_enable && status.timer_clock == 2) {
|
||||
if(++status.tima == 0) {
|
||||
status.tima = status.tma;
|
||||
interrupt_raise(Interrupt::Timer);
|
||||
}
|
||||
}
|
||||
|
||||
status.timer1 -= 4;
|
||||
if(++status.timer2 >= 4) timer_stage2();
|
||||
}
|
||||
|
||||
void CPU::timer_stage2() { // 16384hz
|
||||
void CPU::timer_16384hz() {
|
||||
if(status.timer_enable && status.timer_clock == 3) {
|
||||
if(++status.tima == 0) {
|
||||
status.tima = status.tma;
|
||||
@@ -62,20 +59,24 @@ void CPU::timer_stage2() { // 16384hz
|
||||
}
|
||||
|
||||
status.div++;
|
||||
|
||||
status.timer2 -= 4;
|
||||
if(++status.timer3 >= 4) timer_stage3();
|
||||
}
|
||||
|
||||
void CPU::timer_stage3() { // 4096hz
|
||||
void CPU::timer_8192hz() {
|
||||
if(status.serial_transfer && status.serial_clock) {
|
||||
if(--status.serial_bits == 0) {
|
||||
status.serial_transfer = 0;
|
||||
interrupt_raise(Interrupt::Serial);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CPU::timer_4096hz() {
|
||||
if(status.timer_enable && status.timer_clock == 0) {
|
||||
if(++status.tima == 0) {
|
||||
status.tima = status.tma;
|
||||
interrupt_raise(Interrupt::Timer);
|
||||
}
|
||||
}
|
||||
|
||||
status.timer3 -= 4;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -1,8 +1,9 @@
|
||||
void add_clocks(unsigned clocks);
|
||||
void timer_stage0();
|
||||
void timer_stage1();
|
||||
void timer_stage2();
|
||||
void timer_stage3();
|
||||
void timer_262144hz();
|
||||
void timer_65536hz();
|
||||
void timer_16384hz();
|
||||
void timer_8192hz();
|
||||
void timer_4096hz();
|
||||
|
||||
//opcode.cpp
|
||||
void op_io();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
namespace GameBoy {
|
||||
namespace Info {
|
||||
static const char Name[] = "bgameboy";
|
||||
static const char Version[] = "000.11";
|
||||
static const char Version[] = "000.19";
|
||||
static unsigned SerializerVersion = 1;
|
||||
}
|
||||
}
|
||||
@@ -15,22 +15,62 @@ namespace GameBoy {
|
||||
#include <nall/foreach.hpp>
|
||||
#include <nall/platform.hpp>
|
||||
#include <nall/property.hpp>
|
||||
#include <nall/random.hpp>
|
||||
#include <nall/serializer.hpp>
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/string.hpp>
|
||||
#include <nall/varint.hpp>
|
||||
using namespace nall;
|
||||
|
||||
namespace GameBoy {
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
typedef int8_t int8;
|
||||
typedef int16_t int16;
|
||||
typedef int32_t int32;
|
||||
typedef int64_t int64;
|
||||
|
||||
typedef uint8_t uint8;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint64_t uint64;
|
||||
|
||||
typedef uint_t< 1> uint1;
|
||||
typedef uint_t< 2> uint2;
|
||||
typedef uint_t< 3> uint3;
|
||||
typedef uint_t< 4> uint4;
|
||||
typedef uint_t< 5> uint5;
|
||||
typedef uint_t< 6> uint6;
|
||||
typedef uint_t< 7> uint7;
|
||||
|
||||
typedef uint_t< 9> uint9;
|
||||
typedef uint_t<10> uint10;
|
||||
typedef uint_t<11> uint11;
|
||||
typedef uint_t<12> uint12;
|
||||
typedef uint_t<13> uint13;
|
||||
typedef uint_t<14> uint14;
|
||||
typedef uint_t<15> uint15;
|
||||
|
||||
typedef uint_t<17> uint17;
|
||||
typedef uint_t<18> uint18;
|
||||
typedef uint_t<19> uint19;
|
||||
typedef uint_t<20> uint20;
|
||||
typedef uint_t<21> uint21;
|
||||
typedef uint_t<22> uint22;
|
||||
typedef uint_t<23> uint23;
|
||||
typedef uint_t<24> uint24;
|
||||
typedef uint_t<25> uint25;
|
||||
typedef uint_t<26> uint26;
|
||||
typedef uint_t<27> uint27;
|
||||
typedef uint_t<28> uint28;
|
||||
typedef uint_t<29> uint29;
|
||||
typedef uint_t<30> uint30;
|
||||
typedef uint_t<31> uint31;
|
||||
|
||||
template<uint16 lo, uint16 hi>
|
||||
alwaysinline bool within(uint16 addr) {
|
||||
static const uint16 mask = ~(hi ^ lo);
|
||||
return (addr & mask) == lo;
|
||||
}
|
||||
|
||||
struct Processor {
|
||||
cothread_t thread;
|
||||
unsigned frequency;
|
||||
@@ -51,5 +91,6 @@ namespace GameBoy {
|
||||
#include <gameboy/scheduler/scheduler.hpp>
|
||||
#include <gameboy/cartridge/cartridge.hpp>
|
||||
#include <gameboy/cpu/cpu.hpp>
|
||||
#include <gameboy/apu/apu.hpp>
|
||||
#include <gameboy/lcd/lcd.hpp>
|
||||
};
|
||||
|
@@ -1,9 +1,10 @@
|
||||
class Interface {
|
||||
public:
|
||||
virtual void lcd_scanline() {}
|
||||
virtual void joyp_write(bool p15, bool p14) {}
|
||||
|
||||
virtual void video_refresh(const uint8_t *data) {}
|
||||
virtual void audio_sample(signed left, signed right) {}
|
||||
virtual void audio_sample(int16_t center, int16_t left, int16_t right) {}
|
||||
virtual void input_poll() {}
|
||||
virtual bool input_poll(unsigned id) {}
|
||||
|
||||
|
@@ -19,7 +19,11 @@ void LCD::main() {
|
||||
|
||||
add_clocks(4);
|
||||
|
||||
if(status.lx == 320) {
|
||||
if(status.lx == 0) {
|
||||
if(status.interrupt_oam) cpu.interrupt_raise(CPU::Interrupt::Stat);
|
||||
}
|
||||
|
||||
if(status.lx == 252) {
|
||||
if(status.interrupt_hblank) cpu.interrupt_raise(CPU::Interrupt::Stat);
|
||||
}
|
||||
}
|
||||
@@ -29,8 +33,8 @@ void LCD::add_clocks(unsigned clocks) {
|
||||
status.lx += clocks;
|
||||
if(status.lx >= 456) scanline();
|
||||
|
||||
cpu.clock -= clocks;
|
||||
if(cpu.clock <= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) {
|
||||
clock += clocks;
|
||||
if(clock >= 0 && scheduler.sync != Scheduler::SynchronizeMode::All) {
|
||||
co_switch(scheduler.active_thread = cpu.thread);
|
||||
}
|
||||
}
|
||||
@@ -71,6 +75,7 @@ void LCD::render() {
|
||||
|
||||
uint8_t *output = screen + status.ly * 160;
|
||||
for(unsigned n = 0; n < 160; n++) output[n] = (3 - line[n]) * 0x55;
|
||||
system.interface->lcd_scanline();
|
||||
}
|
||||
|
||||
uint16 LCD::read_tile(bool select, unsigned x, unsigned y) {
|
||||
@@ -186,7 +191,7 @@ void LCD::render_obj() {
|
||||
}
|
||||
|
||||
void LCD::power() {
|
||||
create(Main, 4 * 1024 * 1024);
|
||||
create(Main, 4194304);
|
||||
|
||||
for(unsigned n = 0x8000; n <= 0x9fff; n++) bus.mmio[n] = this; //VRAM
|
||||
for(unsigned n = 0xff40; n <= 0xff4b; n++) bus.mmio[n] = this; //MMIO
|
||||
|
@@ -17,9 +17,10 @@ uint8 LCD::mmio_read(uint16 addr) {
|
||||
|
||||
if(addr == 0xff41) { //STAT
|
||||
unsigned mode;
|
||||
if(status.ly >= 144) mode = 1; //Vblank
|
||||
else if(status.lx >= 320) mode = 0; //Hblank
|
||||
else mode = 3; //LCD transfer
|
||||
if(status.ly >= 144) mode = 1; //Vblank
|
||||
else if(status.lx < 80) mode = 2; //OAM
|
||||
else if(status.lx < 252) mode = 3; //LCD
|
||||
else mode = 0; //Hblank
|
||||
|
||||
return (status.interrupt_lyc << 6)
|
||||
| (status.interrupt_oam << 5)
|
||||
|
@@ -50,7 +50,7 @@ void Bus::write(uint16 addr, uint8 data) {
|
||||
}
|
||||
|
||||
void Bus::power() {
|
||||
for(unsigned n = 0; n < 65536; n++) mmio[n] = &unmapped;
|
||||
for(unsigned n = 0x0000; n <= 0xffff; n++) mmio[n] = &unmapped;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -41,6 +41,7 @@ void System::serialize_all(serializer &s) {
|
||||
cartridge.serialize(s);
|
||||
system.serialize(s);
|
||||
cpu.serialize(s);
|
||||
apu.serialize(s);
|
||||
lcd.serialize(s);
|
||||
}
|
||||
|
||||
|
@@ -33,35 +33,23 @@ void System::runthreadtosave() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8 System::mmio_read(uint16 addr) {
|
||||
if((addr & 0xff00) == 0x0000) {
|
||||
return BootROM::sgb[addr];
|
||||
}
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
void System::mmio_write(uint16 addr, uint8 data) {
|
||||
if(addr == 0xff50) {
|
||||
if(data == 0x01) cartridge.map();
|
||||
}
|
||||
}
|
||||
|
||||
void System::init(Interface *interface_) {
|
||||
interface = interface_;
|
||||
}
|
||||
|
||||
void System::load() {
|
||||
serialize_init();
|
||||
}
|
||||
|
||||
void System::power() {
|
||||
bus.power();
|
||||
cartridge.power();
|
||||
cpu.power();
|
||||
apu.power();
|
||||
lcd.power();
|
||||
scheduler.init();
|
||||
|
||||
for(unsigned n = 0x0000; n <= 0x00ff; n++) bus.mmio[n] = this;
|
||||
bus.mmio[0xff50] = this;
|
||||
|
||||
clocks_executed = 0;
|
||||
serialize_init();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ enum class Input : unsigned {
|
||||
Up, Down, Left, Right, B, A, Select, Start,
|
||||
};
|
||||
|
||||
struct System : MMIO {
|
||||
struct System {
|
||||
struct BootROM {
|
||||
static const uint8 dmg[256];
|
||||
static const uint8 sgb[256];
|
||||
@@ -14,10 +14,8 @@ struct System : MMIO {
|
||||
void runtosave();
|
||||
void runthreadtosave();
|
||||
|
||||
uint8 mmio_read(uint16 addr);
|
||||
void mmio_write(uint16 addr, uint8 data);
|
||||
|
||||
void init(Interface*);
|
||||
void load();
|
||||
void power();
|
||||
|
||||
Interface *interface;
|
||||
|
@@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
||||
<assemblyIdentity type="win32" name="bsnes" version="1.0.0.0" processorArchitecture="x86"/>
|
||||
<dependency>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||
</dependentAssembly>
|
||||
</dependency>
|
||||
</assembly>
|
Binary file not shown.
Before Width: | Height: | Size: 22 KiB |
@@ -1,4 +0,0 @@
|
||||
@windres resource.rc resource.o
|
||||
@mingw32-g++ -std=gnu++0x -mwindows -s -O3 -fomit-frame-pointer -I.. -o ../out/bsnes launcher.cpp resource.o
|
||||
@del *.o
|
||||
@pause
|
@@ -1,2 +0,0 @@
|
||||
clear
|
||||
g++ -std=gnu++0x -s -O3 -fomit-frame-pointer -I.. -o ../out/bsnes launcher.cpp
|
@@ -1,54 +0,0 @@
|
||||
#include <nall/config.hpp>
|
||||
#include <nall/detect.hpp>
|
||||
#include <nall/file.hpp>
|
||||
#include <nall/foreach.hpp>
|
||||
#include <nall/platform.hpp>
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/string.hpp>
|
||||
using namespace nall;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char path[PATH_MAX], *unused;
|
||||
#if !defined(PLATFORM_WIN)
|
||||
unused = realpath(argv[0], path);
|
||||
#else
|
||||
wchar_t **argw = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
unused = realpath(nall::utf8_t(argw[0]), path);
|
||||
#endif
|
||||
string realPath = dir(path);
|
||||
string basePath = string(dir(path), "bsnes-qt.cfg");
|
||||
unused = userpath(path);
|
||||
if(!strend(path, "/") && !strend(path, "\\")) strcat(path, "/");
|
||||
string userPath = string(path, ".bsnes/bsnes-qt.cfg");
|
||||
|
||||
configuration config;
|
||||
string profile;
|
||||
config.attach(profile = "", "system.profile");
|
||||
if(config.load(userPath) == false) config.load(basePath);
|
||||
if(profile == "") profile = "compatibility";
|
||||
|
||||
string binaryName = string("bsnes-", profile);
|
||||
#if defined(PLATFORM_WIN)
|
||||
binaryName << ".dll";
|
||||
#endif
|
||||
string fileName = string(realPath, binaryName);
|
||||
|
||||
#if !defined(PLATFORM_WIN)
|
||||
char **args = new char*[argc + 1];
|
||||
args[0] = strdup(binaryName);
|
||||
for(unsigned i = 1; i < argc; i++) args[i] = strdup(argv[i]);
|
||||
args[argc] = 0;
|
||||
execvp(args[0], args);
|
||||
execv(fileName, args);
|
||||
print("[bsnes] Error: unable to locate binary file: ", binaryName, "\n");
|
||||
#else
|
||||
STARTUPINFOW si;
|
||||
PROCESS_INFORMATION pi;
|
||||
memset(&si, 0, sizeof(STARTUPINFOW));
|
||||
if(!CreateProcessW(nall::utf16_t(fileName), GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
|
||||
MessageBoxA(0, string("Error: unable to locate binary file: ", binaryName), "bsnes", MB_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
@@ -1,2 +0,0 @@
|
||||
1 24 "bsnes.Manifest"
|
||||
IDI_ICON1 ICON DISCARDABLE "bsnes.ico"
|
@@ -41,21 +41,22 @@ struct directory {
|
||||
if(handle != INVALID_HANDLE_VALUE) {
|
||||
if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) {
|
||||
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
string name = utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(string(name, "/"));
|
||||
string name = (const char*)utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(name);
|
||||
}
|
||||
}
|
||||
while(FindNextFile(handle, &data) != false) {
|
||||
if(wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..")) {
|
||||
if(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
string name = utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(string(name, "/"));
|
||||
string name = (const char*)utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
FindClose(handle);
|
||||
}
|
||||
if(list.size() > 0) sort(&list[0], list.size());
|
||||
foreach(name, list) name.append("/"); //must append after sorting
|
||||
return list;
|
||||
}
|
||||
|
||||
@@ -70,12 +71,12 @@ struct directory {
|
||||
handle = FindFirstFile(utf16_t(path), &data);
|
||||
if(handle != INVALID_HANDLE_VALUE) {
|
||||
if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
string name = utf8_t(data.cFileName);
|
||||
string name = (const char*)utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(name);
|
||||
}
|
||||
while(FindNextFile(handle, &data) != false) {
|
||||
if((data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
||||
string name = utf8_t(data.cFileName);
|
||||
string name = (const char*)utf8_t(data.cFileName);
|
||||
if(wildcard(name, pattern)) list.append(name);
|
||||
}
|
||||
}
|
||||
@@ -109,14 +110,14 @@ struct directory {
|
||||
if(!strcmp(ep->d_name, ".")) continue;
|
||||
if(!strcmp(ep->d_name, "..")) continue;
|
||||
if(ep->d_type & DT_DIR) {
|
||||
if(wildcard(ep->d_name, pattern)) list.append(string(ep->d_name, "/"));
|
||||
if(wildcard(ep->d_name, pattern)) list.append(ep->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dp);
|
||||
}
|
||||
if(list.size() > 0) sort(&list[0], list.size());
|
||||
foreach(name, list) name.append("/"); //must append after sorting
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
inline lstring directory::files(const string &pathname, const string &pattern) {
|
||||
|
@@ -1,15 +1,7 @@
|
||||
#ifndef NALL_FILE_HPP
|
||||
#define NALL_FILE_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#include <nall/platform.hpp>
|
||||
#include <nall/stdint.hpp>
|
||||
#include <nall/string.hpp>
|
||||
#include <nall/utf8.hpp>
|
||||
@@ -28,6 +20,7 @@ namespace nall {
|
||||
public:
|
||||
enum class mode : unsigned { read, write, readwrite, writeread };
|
||||
enum class index : unsigned { absolute, relative };
|
||||
enum class time : unsigned { create, modify, access };
|
||||
|
||||
uint8_t read() {
|
||||
if(!fp) return 0xff; //file not open
|
||||
@@ -142,52 +135,60 @@ namespace nall {
|
||||
return file_offset >= file_size;
|
||||
}
|
||||
|
||||
static bool exists(const char *fn) {
|
||||
static bool exists(const char *filename) {
|
||||
#if !defined(_WIN32)
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
struct stat64 data;
|
||||
return stat64(filename, &data) == 0;
|
||||
#else
|
||||
FILE *fp = _wfopen(utf16_t(fn), L"rb");
|
||||
struct __stat64 data;
|
||||
return _wstat64(utf16_t(filename), &data) == 0;
|
||||
#endif
|
||||
if(fp) {
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static unsigned size(const char *fn) {
|
||||
static uintmax_t size(const char *filename) {
|
||||
#if !defined(_WIN32)
|
||||
FILE *fp = fopen(fn, "rb");
|
||||
struct stat64 data;
|
||||
stat64(filename, &data);
|
||||
#else
|
||||
FILE *fp = _wfopen(utf16_t(fn), L"rb");
|
||||
struct __stat64 data;
|
||||
_wstat64(utf16_t(filename), &data);
|
||||
#endif
|
||||
unsigned filesize = 0;
|
||||
if(fp) {
|
||||
fseek(fp, 0, SEEK_END);
|
||||
filesize = ftell(fp);
|
||||
fclose(fp);
|
||||
return S_ISREG(data.st_mode) ? data.st_size : 0u;
|
||||
}
|
||||
|
||||
static time_t timestamp(const char *filename, file::time mode = file::time::create) {
|
||||
#if !defined(_WIN32)
|
||||
struct stat64 data;
|
||||
stat64(filename, &data);
|
||||
#else
|
||||
struct __stat64 data;
|
||||
_wstat64(utf16_t(filename), &data);
|
||||
#endif
|
||||
switch(mode) { default:
|
||||
case file::time::create: return data.st_ctime;
|
||||
case file::time::modify: return data.st_mtime;
|
||||
case file::time::access: return data.st_atime;
|
||||
}
|
||||
return filesize;
|
||||
}
|
||||
|
||||
bool open() {
|
||||
return fp;
|
||||
}
|
||||
|
||||
bool open(const char *fn, mode mode_) {
|
||||
bool open(const char *filename, mode mode_) {
|
||||
if(fp) return false;
|
||||
|
||||
switch(file_mode = mode_) {
|
||||
#if !defined(_WIN32)
|
||||
case mode::read: fp = fopen(fn, "rb"); break;
|
||||
case mode::write: fp = fopen(fn, "wb+"); break; //need read permission for buffering
|
||||
case mode::readwrite: fp = fopen(fn, "rb+"); break;
|
||||
case mode::writeread: fp = fopen(fn, "wb+"); break;
|
||||
case mode::read: fp = fopen(filename, "rb" ); break;
|
||||
case mode::write: fp = fopen(filename, "wb+"); break; //need read permission for buffering
|
||||
case mode::readwrite: fp = fopen(filename, "rb+"); break;
|
||||
case mode::writeread: fp = fopen(filename, "wb+"); break;
|
||||
#else
|
||||
case mode::read: fp = _wfopen(utf16_t(fn), L"rb"); break;
|
||||
case mode::write: fp = _wfopen(utf16_t(fn), L"wb+"); break;
|
||||
case mode::readwrite: fp = _wfopen(utf16_t(fn), L"rb+"); break;
|
||||
case mode::writeread: fp = _wfopen(utf16_t(fn), L"wb+"); break;
|
||||
case mode::read: fp = _wfopen(utf16_t(filename), L"rb" ); break;
|
||||
case mode::write: fp = _wfopen(utf16_t(filename), L"wb+"); break;
|
||||
case mode::readwrite: fp = _wfopen(utf16_t(filename), L"rb+"); break;
|
||||
case mode::writeread: fp = _wfopen(utf16_t(filename), L"wb+"); break;
|
||||
#endif
|
||||
}
|
||||
if(!fp) return false;
|
||||
|
@@ -21,7 +21,7 @@ namespace nall {
|
||||
public:
|
||||
enum class mode : unsigned { read, write, readwrite, writeread };
|
||||
|
||||
bool opened() const { return p_opened(); }
|
||||
bool open() const { return p_open(); }
|
||||
bool open(const char *filename, mode mode_) { return p_open(filename, mode_); }
|
||||
void close() { return p_close(); }
|
||||
unsigned size() const { return p_size; }
|
||||
@@ -42,7 +42,7 @@ namespace nall {
|
||||
|
||||
HANDLE p_filehandle, p_maphandle;
|
||||
|
||||
bool p_opened() const {
|
||||
bool p_open() const {
|
||||
return p_handle;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace nall {
|
||||
|
||||
int p_fd;
|
||||
|
||||
bool p_opened() const {
|
||||
bool p_open() const {
|
||||
return p_handle;
|
||||
}
|
||||
|
||||
|
@@ -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); }
|
||||
|
@@ -22,7 +22,7 @@ public:
|
||||
};
|
||||
|
||||
GameBoyCartridge::GameBoyCartridge(const uint8_t *romdata, unsigned romsize) {
|
||||
xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
if(romsize < 0x4000) return;
|
||||
|
||||
info.mapper = "unknown";
|
||||
@@ -97,6 +97,7 @@ GameBoyCartridge::GameBoyCartridge(const uint8_t *romdata, unsigned romsize) {
|
||||
xml << " <ram size='" << hex(info.ramsize) << "' battery='" << info.battery << "'/>\n";
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,12 @@
|
||||
#ifndef NALL_PLATFORM_HPP
|
||||
#define NALL_PLATFORM_HPP
|
||||
|
||||
#if defined(_WIN32)
|
||||
//minimum version needed for _wstat64, etc
|
||||
#undef __MSVCRT_VERSION__
|
||||
#define __MSVCRT_VERSION__ 0x0601
|
||||
#endif
|
||||
|
||||
#include <nall/utf8.hpp>
|
||||
|
||||
//=========================
|
||||
@@ -18,16 +24,19 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#include <direct.h>
|
||||
#include <shlobj.h>
|
||||
#include <wchar.h>
|
||||
#undef interface
|
||||
#define dllexport __declspec(dllexport)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/stat.h>
|
||||
#define dllexport
|
||||
#endif
|
||||
|
||||
@@ -53,11 +62,11 @@
|
||||
#if defined(_WIN32)
|
||||
#define getcwd _getcwd
|
||||
#define ftruncate _chsize
|
||||
#define putenv _putenv
|
||||
#define mkdir(n, m) _wmkdir(nall::utf16_t(n))
|
||||
#define putenv _putenv
|
||||
#define rmdir _rmdir
|
||||
#define vsnprintf _vsnprintf
|
||||
#define usleep(n) Sleep(n / 1000)
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
//================
|
||||
|
32
bsnes/nall/public_cast.hpp
Executable file
32
bsnes/nall/public_cast.hpp
Executable file
@@ -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
|
@@ -8,12 +8,20 @@ namespace nall {
|
||||
return n = (n >> 1) ^ (((n & 1) - 1) & 0xedb88320);
|
||||
}
|
||||
|
||||
struct random_cyclic {
|
||||
unsigned seed;
|
||||
inline unsigned operator()() {
|
||||
return seed = (seed >> 1) ^ (((seed & 1) - 1) & 0xedb88320);
|
||||
struct random_lfsr {
|
||||
inline void seed(unsigned seed__) {
|
||||
seed_ = seed__;
|
||||
}
|
||||
random_cyclic() : seed(0) {}
|
||||
|
||||
inline unsigned operator()() {
|
||||
return seed_ = (seed_ >> 1) ^ (((seed_ & 1) - 1) & 0xedb88320);
|
||||
}
|
||||
|
||||
random_lfsr() : seed_(0) {
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned seed_;
|
||||
};
|
||||
}
|
||||
|
||||
|
103
bsnes/nall/reference_array.hpp
Executable file
103
bsnes/nall/reference_array.hpp
Executable file
@@ -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
|
@@ -112,13 +112,13 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
|
||||
if(type == TypeBsx) {
|
||||
xml << "<cartridge/>";
|
||||
xmlMemoryMap = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
if(type == TypeSufamiTurbo) {
|
||||
xml << "<cartridge/>";
|
||||
xmlMemoryMap = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
xml << " <ram size='" << hex(gameboy_ram_size(data, size)) << "'/>\n";
|
||||
}
|
||||
xml << "</cartridge>\n";
|
||||
xmlMemoryMap = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -279,19 +279,23 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
xml << " </superfx>\n";
|
||||
} else if(mapper == SA1ROM) {
|
||||
xml << " <sa1>\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 << " </rom>\n";
|
||||
xml << " <mcu>\n";
|
||||
xml << " <rom>\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='" << hex(ram_size) << "'>\n";
|
||||
xml << " <map mode='linear' address='00-3f:6000-7fff'/>\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";
|
||||
@@ -334,11 +338,14 @@ SNESCartridge::SNESCartridge(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";
|
||||
@@ -355,7 +362,7 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
xml << " <map mode='linear' address='20-3f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='a0-bf:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram>\n";
|
||||
xml << " <ram size='20000'>\n";
|
||||
xml << " <map mode='linear' address='60-63:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='e0-e3:8000-ffff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
@@ -365,7 +372,7 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
xml << " <map mode='linear' address='40-5f:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='c0-df:8000-ffff'/>\n";
|
||||
xml << " </rom>\n";
|
||||
xml << " <ram>\n";
|
||||
xml << " <ram size='20000'>\n";
|
||||
xml << " <map mode='linear' address='70-73:8000-ffff'/>\n";
|
||||
xml << " <map mode='linear' address='f0-f3:8000-ffff'/>\n";
|
||||
xml << " </ram>\n";
|
||||
@@ -402,48 +409,72 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
if(has_dsp1) {
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp1b.bin' sha256='4d42db0f36faef263d6b93f508e8c1c4ae8fc2605fd35e3390ecc02905cd420c'>\n";
|
||||
if(dsp1_mapper == DSP1LoROM1MB) {
|
||||
xml << " <dr mask='004000' test='000000'/>\n";
|
||||
xml << " <sr mask='004000' test='004000'/>\n";
|
||||
xml << " <map address='20-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-ffff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='20-3f:c000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:c000-ffff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
} else if(dsp1_mapper == DSP1LoROM2MB) {
|
||||
xml << " <dr mask='004000' test='000000'/>\n";
|
||||
xml << " <sr mask='004000' test='004000'/>\n";
|
||||
xml << " <map address='60-6f:0000-7fff'/>\n";
|
||||
xml << " <map address='e0-ef:0000-7fff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='60-6f:0000-3fff'/>\n";
|
||||
xml << " <map address='e0-ef:0000-3fff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='60-6f:4000-7fff'/>\n";
|
||||
xml << " <map address='e0-ef:4000-7fff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
} else if(dsp1_mapper == DSP1HiROM) {
|
||||
xml << " <dr mask='001000' test='000000'/>\n";
|
||||
xml << " <sr mask='001000' test='001000'/>\n";
|
||||
xml << " <map address='00-1f:6000-7fff'/>\n";
|
||||
xml << " <map address='80-9f:6000-7fff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='00-1f:6000-6fff'/>\n";
|
||||
xml << " <map address='80-9f:6000-6fff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='00-1f:7000-7fff'/>\n";
|
||||
xml << " <map address='80-9f:7000-7fff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
}
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_dsp2) {
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp2.bin' sha256='5efbdf96ed0652790855225964f3e90e6a4d466cfa64df25b110933c6cf94ea1'>\n";
|
||||
xml << " <dr mask='004000' test='000000'/>\n";
|
||||
xml << " <sr mask='004000' test='004000'/>\n";
|
||||
xml << " <map address='20-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-ffff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='20-3f:c000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:c000-ffff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_dsp3) {
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp3.bin' sha256='2e635f72e4d4681148bc35429421c9b946e4f407590e74e31b93b8987b63ba90'>\n";
|
||||
xml << " <dr mask='004000' test='000000'/>\n";
|
||||
xml << " <sr mask='004000' test='004000'/>\n";
|
||||
xml << " <map address='20-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-ffff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='20-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='a0-bf:8000-bfff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='20-3f:c000-ffff'/>\n";
|
||||
xml << " <map address='a0-bf:c000-ffff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_dsp4) {
|
||||
xml << " <necdsp revision='upd7725' frequency='8000000' program='dsp4.bin' sha256='63ede17322541c191ed1fdf683872554a0a57306496afc43c59de7c01a6e764a'>\n";
|
||||
xml << " <dr mask='004000' test='000000'/>\n";
|
||||
xml << " <sr mask='004000' test='004000'/>\n";
|
||||
xml << " <map address='30-3f:8000-ffff'/>\n";
|
||||
xml << " <map address='b0-bf:8000-ffff'/>\n";
|
||||
xml << " <dr>\n";
|
||||
xml << " <map address='30-3f:8000-bfff'/>\n";
|
||||
xml << " <map address='b0-bf:8000-bfff'/>\n";
|
||||
xml << " </dr>\n";
|
||||
xml << " <sr>\n";
|
||||
xml << " <map address='30-3f:c000-ffff'/>\n";
|
||||
xml << " <map address='b0-bf:c000-ffff'/>\n";
|
||||
xml << " </sr>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
@@ -456,21 +487,35 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
|
||||
if(has_st010) {
|
||||
xml << " <necdsp revision='upd96050' frequency='10000000' program='st0010.bin' sha256='55c697e864562445621cdf8a7bf6e84ae91361e393d382a3704e9aa55559041e'>\n";
|
||||
xml << " <dr mask='080001' test='000000'/>\n";
|
||||
xml << " <sr mask='080001' test='000001'/>\n";
|
||||
xml << " <dp mask='080000' test='080000'/>\n";
|
||||
xml << " <map address='60-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e0-ef:0000-0fff'/>\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 << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
if(has_st011) {
|
||||
xml << " <necdsp revision='upd96050' frequency='15000000' program='st0011.bin' sha256='b71d71fa5f18ff39b2b3688e914a04d1286b613002ddde827529fdc54650a130'>\n";
|
||||
xml << " <dr mask='080001' test='000000'/>\n";
|
||||
xml << " <sr mask='080001' test='000001'/>\n";
|
||||
xml << " <dp mask='080000' test='080000'/>\n";
|
||||
xml << " <map address='60-6f:0000-0fff'/>\n";
|
||||
xml << " <map address='e0-ef:0000-0fff'/>\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 << " </dp>\n";
|
||||
xml << " </necdsp>\n";
|
||||
}
|
||||
|
||||
@@ -482,7 +527,7 @@ SNESCartridge::SNESCartridge(const uint8_t *data, unsigned size) {
|
||||
}
|
||||
|
||||
xml << "</cartridge>\n";
|
||||
xmlMemoryMap = xml;
|
||||
xmlMemoryMap = xml.transform("'", "\"");
|
||||
}
|
||||
|
||||
void SNESCartridge::read_header(const uint8_t *data, unsigned size) {
|
||||
|
@@ -12,20 +12,18 @@
|
||||
|
||||
namespace nall {
|
||||
class string;
|
||||
template<typename T> inline string to_string(T);
|
||||
template<typename T> inline const char* to_string(T);
|
||||
|
||||
class string {
|
||||
public:
|
||||
inline void reserve(unsigned);
|
||||
|
||||
inline string& assign(const char*);
|
||||
inline string& append(const char*);
|
||||
inline string& append(bool);
|
||||
inline string& append(signed int value);
|
||||
inline string& append(unsigned int value);
|
||||
inline string& append(double value);
|
||||
template<typename... Args> inline string& assign(Args&&... args);
|
||||
template<typename... Args> inline string& append(Args&&... args);
|
||||
inline string& assign_(const char*);
|
||||
inline string& append_(const char*);
|
||||
|
||||
inline bool readfile(const char*);
|
||||
inline bool readfile(const string&);
|
||||
|
||||
inline string& replace (const char*, const char*);
|
||||
inline string& qreplace(const char*, const char*);
|
||||
@@ -145,10 +143,15 @@ 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 hex(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string integer(intmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string decimal(uintmax_t value);
|
||||
template<unsigned length = 0, char padding = '0'> inline string binary(uintmax_t 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);
|
||||
|
||||
|
@@ -4,14 +4,16 @@
|
||||
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 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; }
|
||||
template<> inline string to_string<const string&>(const string &v) { return v; }
|
||||
template<> inline const char* to_string<bool> (bool v) { return v ? "true" : "false"; }
|
||||
template<> inline const char* to_string<signed int> (signed int v) { static char temp[256]; snprintf(temp, 255, "%+d", v); return temp; }
|
||||
template<> inline const char* to_string<unsigned int> (unsigned int v) { static char temp[256]; snprintf(temp, 255, "%u", v); return temp; }
|
||||
template<> inline const char* to_string<intmax_t> (intmax_t v) { static char temp[256]; snprintf(temp, 255, "%+lld", (long long)v); return temp; }
|
||||
template<> inline const char* to_string<uintmax_t> (uintmax_t v) { static char temp[256]; snprintf(temp, 255, "%llu", (unsigned long long)v); return temp; }
|
||||
template<> inline const char* to_string<double> (double v) { static char temp[256]; snprintf(temp, 255, "%f", v); return temp; }
|
||||
template<> inline const char* to_string<char*> (char *v) { return v; }
|
||||
template<> inline const char* to_string<const char*> (const char *v) { return v; }
|
||||
template<> inline const char* to_string<string> (string v) { return v; }
|
||||
template<> inline const char* to_string<const string&>(const string &v) { return v; }
|
||||
|
||||
template<typename T> string& string::operator= (T value) { return assign(to_string<T>(value)); }
|
||||
template<typename T> string& string::operator<<(T value) { return append(to_string<T>(value)); }
|
||||
@@ -22,8 +24,8 @@ template<typename T> lstring& lstring::operator<<(T value) {
|
||||
}
|
||||
|
||||
#if defined(QSTRING_H)
|
||||
template<> inline string to_string<QString>(QString v) { return v.toUtf8().constData(); }
|
||||
template<> inline string to_string<const QString&>(const QString &v) { return v.toUtf8().constData(); }
|
||||
template<> inline const char* to_string<QString>(QString v) { return v.toUtf8().constData(); }
|
||||
template<> inline const char* to_string<const QString&>(const QString &v) { return v.toUtf8().constData(); }
|
||||
string::operator QString() const { return QString::fromUtf8(*this); }
|
||||
#endif
|
||||
|
||||
|
@@ -65,8 +65,11 @@ intmax_t integer(const char *str) {
|
||||
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++;
|
||||
}
|
||||
@@ -114,38 +117,7 @@ uintmax_t binary(const char *str) {
|
||||
}
|
||||
|
||||
double fp(const char *str) {
|
||||
if(!str) return 0.0;
|
||||
bool negate = false;
|
||||
|
||||
//check for negation
|
||||
if(*str == '-') {
|
||||
negate = true;
|
||||
str++;
|
||||
}
|
||||
|
||||
intmax_t result_integral = 0;
|
||||
while(*str) {
|
||||
uint8_t x = *str++;
|
||||
if(x >= '0' && x <= '9') x -= '0';
|
||||
else if(x == '.' || x == ',') break; //break loop and read fractional part
|
||||
else return (double)result_integral; //invalid value, assume no fractional part
|
||||
result_integral = result_integral * 10 + x;
|
||||
}
|
||||
|
||||
intmax_t result_fractional = 0;
|
||||
while(*str) {
|
||||
uint8_t x = *str++;
|
||||
if(x >= '0' && x <= '9') x -= '0';
|
||||
else break; //stop at first invalid character
|
||||
result_fractional = result_fractional * 10 + x;
|
||||
}
|
||||
|
||||
//calculate fractional portion
|
||||
double result = (double)result_fractional;
|
||||
while((uintmax_t)result > 0) result /= 10.0;
|
||||
result += (double)result_integral;
|
||||
|
||||
return !negate ? result : -result;
|
||||
return atof(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,6 +3,15 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
static void istring(string &output) {
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
static void istring(string &output, const T &value, Args&&... args) {
|
||||
output.append_(to_string(value));
|
||||
istring(output, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void string::reserve(unsigned size_) {
|
||||
if(size_ > size) {
|
||||
size = size_;
|
||||
@@ -11,25 +20,31 @@ void string::reserve(unsigned size_) {
|
||||
}
|
||||
}
|
||||
|
||||
string& string::assign(const char *s) {
|
||||
template<typename... Args> string& string::assign(Args&&... args) {
|
||||
*data = 0;
|
||||
istring(*this, std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename... Args> string& string::append(Args&&... args) {
|
||||
istring(*this, std::forward<Args>(args)...);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::assign_(const char *s) {
|
||||
unsigned length = strlen(s);
|
||||
reserve(length);
|
||||
strcpy(data, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::append(const char *s) {
|
||||
string& string::append_(const char *s) {
|
||||
unsigned length = strlen(data) + strlen(s);
|
||||
reserve(length);
|
||||
strcat(data, s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
string& string::append(bool value) { append(value ? "true" : "false"); 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;
|
||||
}
|
||||
@@ -64,15 +79,6 @@ string& string::operator=(string &&source) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
static void istring(string &output) {
|
||||
}
|
||||
|
||||
template<typename T, typename... Args>
|
||||
static void istring(string &output, const T &value, Args&&... args) {
|
||||
output.append(value);
|
||||
istring(output, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<typename... Args> string::string(Args&&... args) {
|
||||
size = 64;
|
||||
data = (char*)malloc(size + 1);
|
||||
@@ -95,7 +101,7 @@ string::~string() {
|
||||
if(data) free(data);
|
||||
}
|
||||
|
||||
bool string::readfile(const char *filename) {
|
||||
bool string::readfile(const string &filename) {
|
||||
assign("");
|
||||
|
||||
#if !defined(_WIN32)
|
||||
|
@@ -3,15 +3,15 @@
|
||||
|
||||
namespace nall {
|
||||
|
||||
string realpath(const char *name) {
|
||||
string currentpath() {
|
||||
char path[PATH_MAX];
|
||||
if(::realpath(name, path)) {
|
||||
if(::getcwd(path)) {
|
||||
string result(path);
|
||||
result.transform("\\", "/");
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
return "./";
|
||||
}
|
||||
|
||||
string userpath() {
|
||||
@@ -22,18 +22,17 @@ string userpath() {
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
return currentpath();
|
||||
}
|
||||
|
||||
string currentpath() {
|
||||
string realpath(const char *name) {
|
||||
char path[PATH_MAX];
|
||||
if(::getcwd(path)) {
|
||||
if(::realpath(name, path)) {
|
||||
string result(path);
|
||||
result.transform("\\", "/");
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
return userpath();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,98 +27,196 @@ string substr(const char *src, unsigned start, unsigned length) {
|
||||
|
||||
/* arithmetic <> string */
|
||||
|
||||
template<unsigned length, char padding> string hex(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 integer(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 decimal(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 binary(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
|
||||
|
@@ -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);
|
||||
|
181
bsnes/phoenix/core/core.cpp
Executable file
181
bsnes/phoenix/core/core.cpp
Executable file
@@ -0,0 +1,181 @@
|
||||
#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(); } }
|
||||
|
||||
Geometry Font::geometry(const string &text) { return p.geometry(text); }
|
||||
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(); }
|
||||
|
||||
void Timer::setEnabled(bool enabled) { state.enabled = enabled; return p.setEnabled(enabled); }
|
||||
void Timer::setInterval(unsigned milliseconds) { state.milliseconds = milliseconds; return p.setInterval(milliseconds); }
|
||||
Timer::Timer() : state(*new State), p(*new pTimer(*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; }
|
||||
Font& Widget::font() { return p.font(); }
|
||||
Geometry Widget::minimumGeometry() { return p.minimumGeometry(); }
|
||||
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(); }
|
||||
|
||||
uint32_t* Canvas::buffer() { return p.buffer(); }
|
||||
void Canvas::update() { return p.update(); }
|
||||
Canvas::Canvas() : base_from_member<pCanvas&>(*new pCanvas(*this)), Widget(base_from_member<pCanvas&>::value), p(base_from_member<pCanvas&>::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(); }
|
431
bsnes/phoenix/core/core.hpp
Executable file
431
bsnes/phoenix/core/core.hpp
Executable file
@@ -0,0 +1,431 @@
|
||||
struct Font;
|
||||
struct Window;
|
||||
struct Menu;
|
||||
struct Layout;
|
||||
struct Widget;
|
||||
|
||||
struct pOS;
|
||||
struct pFont;
|
||||
struct pTimer;
|
||||
struct pWindow;
|
||||
struct pAction;
|
||||
struct pMenu;
|
||||
struct pSeparator;
|
||||
struct pItem;
|
||||
struct pCheckItem;
|
||||
struct pRadioItem;
|
||||
struct pLayout;
|
||||
struct pWidget;
|
||||
struct pButton;
|
||||
struct pCanvas;
|
||||
struct pCheckBox;
|
||||
struct pComboBox;
|
||||
struct pHexEdit;
|
||||
struct pHorizontalSlider;
|
||||
struct pLabel;
|
||||
struct pLineEdit;
|
||||
struct pListView;
|
||||
struct pProgressBar;
|
||||
struct pRadioBox;
|
||||
struct pTextEdit;
|
||||
struct pVerticalSlider;
|
||||
struct pViewport;
|
||||
|
||||
enum : unsigned {
|
||||
MaximumSize = ~0u,
|
||||
MinimumSize = 0u,
|
||||
};
|
||||
|
||||
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 {
|
||||
Geometry geometry(const nall::string &text);
|
||||
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 Timer : Object {
|
||||
nall::function<void ()> onTimeout;
|
||||
|
||||
void setEnabled(bool enabled = true);
|
||||
void setInterval(unsigned milliseconds);
|
||||
|
||||
Timer();
|
||||
struct State;
|
||||
State &state;
|
||||
pTimer &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... }); }
|
||||
static void group(const nall::reference_array<RadioItem&> &list);
|
||||
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string &text);
|
||||
|
||||
RadioItem();
|
||||
struct State;
|
||||
State &state;
|
||||
pRadioItem &p;
|
||||
};
|
||||
|
||||
struct Layout : Object {
|
||||
virtual void setGeometry(const Geometry &geometry) = 0;
|
||||
virtual void setParent(Window &parent) = 0;
|
||||
virtual void setVisible(bool visible = true) = 0;
|
||||
};
|
||||
|
||||
struct Widget : Object {
|
||||
bool enabled();
|
||||
Font& font();
|
||||
Geometry minimumGeometry();
|
||||
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 Canvas : private nall::base_from_member<pCanvas&>, Widget {
|
||||
uint32_t* buffer();
|
||||
void update();
|
||||
|
||||
Canvas();
|
||||
pCanvas &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... }); }
|
||||
static void group(const nall::reference_array<RadioBox&> &list);
|
||||
|
||||
nall::function<void ()> onTick;
|
||||
|
||||
bool checked();
|
||||
void setChecked();
|
||||
void setText(const nall::string &text);
|
||||
|
||||
RadioBox();
|
||||
struct State;
|
||||
State &state;
|
||||
pRadioBox &p;
|
||||
};
|
||||
|
||||
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"
|
20
bsnes/phoenix/core/layout/fixed-layout.cpp
Executable file
20
bsnes/phoenix/core/layout/fixed-layout.cpp
Executable file
@@ -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(const Geometry &geometry) {
|
||||
}
|
||||
|
||||
void FixedLayout::setVisible(bool visible) {
|
||||
foreach(child, children) child.widget->setVisible(visible);
|
||||
}
|
||||
|
||||
FixedLayout::FixedLayout() {
|
||||
}
|
15
bsnes/phoenix/core/layout/fixed-layout.hpp
Executable file
15
bsnes/phoenix/core/layout/fixed-layout.hpp
Executable file
@@ -0,0 +1,15 @@
|
||||
struct FixedLayout : Layout {
|
||||
void append(Widget &widget, const Geometry &geometry);
|
||||
void setGeometry(const 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;
|
||||
};
|
139
bsnes/phoenix/core/layout/horizontal-layout.cpp
Executable file
139
bsnes/phoenix/core/layout/horizontal-layout.cpp
Executable file
@@ -0,0 +1,139 @@
|
||||
void HorizontalLayout::append(VerticalLayout &layout, unsigned spacing) {
|
||||
children.append({ &layout, 0, MinimumSize, MinimumSize, spacing });
|
||||
}
|
||||
|
||||
void HorizontalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
|
||||
children.append({ 0, &widget, width, height, spacing });
|
||||
}
|
||||
|
||||
Geometry HorizontalLayout::minimumGeometry() {
|
||||
unsigned width = 0, height = 0;
|
||||
|
||||
foreach(child, children) {
|
||||
width += child.spacing;
|
||||
if(child.width == MinimumSize || child.width == MaximumSize) {
|
||||
if(child.layout) width += child.layout->minimumGeometry().width;
|
||||
if(child.widget) width += child.widget->minimumGeometry().width;
|
||||
continue;
|
||||
}
|
||||
width += child.width;
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.height == MinimumSize || child.height == MaximumSize) {
|
||||
if(child.layout) height = max(height, child.layout->minimumGeometry().height);
|
||||
if(child.widget) height = max(height, child.widget->minimumGeometry().height);
|
||||
continue;
|
||||
}
|
||||
height = max(height, child.height);
|
||||
}
|
||||
|
||||
return { 0, 0, margin * 2 + width, margin * 2 + height };
|
||||
}
|
||||
|
||||
Geometry HorizontalLayout::minimumLayoutGeometry() {
|
||||
unsigned width = 0, height = 0;
|
||||
bool maximumWidth = false;
|
||||
bool maximumHeight = false;
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.width == MaximumSize) {
|
||||
maximumWidth = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(child.width == MinimumSize) {
|
||||
if(child.layout) width += child.layout->minimumGeometry().width;
|
||||
if(child.widget) width += child.widget->minimumGeometry().width;
|
||||
continue;
|
||||
}
|
||||
|
||||
width += child.width;
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.height == MaximumSize) {
|
||||
maximumHeight = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(child.height == MinimumSize) {
|
||||
if(child.layout) height = max(height, child.layout->minimumGeometry().height);
|
||||
if(child.widget) height = max(height, child.widget->minimumGeometry().height);
|
||||
continue;
|
||||
}
|
||||
|
||||
height = max(height, child.height);
|
||||
}
|
||||
|
||||
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
|
||||
}
|
||||
|
||||
void HorizontalLayout::setGeometry(const Geometry &containerGeometry) {
|
||||
auto children = this->children;
|
||||
foreach(child, children) {
|
||||
if(child.layout) {
|
||||
child.width = child.layout->minimumLayoutGeometry().width;
|
||||
child.height = child.layout->minimumLayoutGeometry().height;
|
||||
}
|
||||
|
||||
if(child.widget) {
|
||||
if(child.width == MinimumSize) child.width = child.widget->minimumGeometry().width;
|
||||
if(child.height == MinimumSize) child.height = child.widget->minimumGeometry().height;
|
||||
}
|
||||
}
|
||||
|
||||
Geometry geometry = containerGeometry;
|
||||
geometry.x += margin;
|
||||
geometry.y += margin;
|
||||
geometry.width -= margin * 2;
|
||||
geometry.height -= margin * 2;
|
||||
|
||||
unsigned minimumWidth = 0, maximumWidthCounter = 0;
|
||||
foreach(child, children) {
|
||||
if(child.width == MaximumSize) maximumWidthCounter++;
|
||||
if(child.width != MaximumSize) minimumWidth += child.width;
|
||||
minimumWidth += child.spacing;
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.width == MaximumSize) child.width = (geometry.width - minimumWidth) / maximumWidthCounter;
|
||||
if(child.height == MaximumSize) child.height = geometry.height;
|
||||
}
|
||||
|
||||
unsigned maximumHeight = 0;
|
||||
foreach(child, children) maximumHeight = max(maximumHeight, child.height);
|
||||
|
||||
foreach(child, children) {
|
||||
unsigned pivot = (maximumHeight - child.height) / 2;
|
||||
Geometry childGeometry = { geometry.x, geometry.y + pivot, child.width, child.height };
|
||||
|
||||
if(child.layout) child.layout->setGeometry(childGeometry);
|
||||
if(child.widget) child.widget->setGeometry(childGeometry);
|
||||
|
||||
geometry.x += child.width + child.spacing;
|
||||
geometry.width -= child.width + child.spacing;
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalLayout::setMargin(unsigned margin) {
|
||||
this->margin = margin;
|
||||
}
|
||||
|
||||
void HorizontalLayout::setParent(Window &parent) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setParent(parent);
|
||||
if(child.widget) parent.append(*child.widget);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
22
bsnes/phoenix/core/layout/horizontal-layout.hpp
Executable file
22
bsnes/phoenix/core/layout/horizontal-layout.hpp
Executable file
@@ -0,0 +1,22 @@
|
||||
struct VerticalLayout;
|
||||
|
||||
struct HorizontalLayout : public Layout {
|
||||
void append(VerticalLayout &layout, unsigned spacing = 0);
|
||||
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
Geometry minimumLayoutGeometry();
|
||||
Geometry minimumGeometry();
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setMargin(unsigned margin);
|
||||
void setParent(Window &parent);
|
||||
void setVisible(bool visible);
|
||||
HorizontalLayout();
|
||||
|
||||
//private:
|
||||
unsigned margin;
|
||||
struct Children {
|
||||
VerticalLayout *layout;
|
||||
Widget *widget;
|
||||
unsigned width, height, spacing;
|
||||
};
|
||||
nall::linear_vector<Children> children;
|
||||
};
|
139
bsnes/phoenix/core/layout/vertical-layout.cpp
Executable file
139
bsnes/phoenix/core/layout/vertical-layout.cpp
Executable file
@@ -0,0 +1,139 @@
|
||||
void VerticalLayout::append(HorizontalLayout &layout, unsigned spacing) {
|
||||
children.append({ &layout, 0, MinimumSize, MinimumSize, spacing });
|
||||
}
|
||||
|
||||
void VerticalLayout::append(Widget &widget, unsigned width, unsigned height, unsigned spacing) {
|
||||
children.append({ 0, &widget, width, height, spacing });
|
||||
}
|
||||
|
||||
Geometry VerticalLayout::minimumGeometry() {
|
||||
unsigned width = 0, height = 0;
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.width == MinimumSize || child.width == MaximumSize) {
|
||||
if(child.layout) width = max(width, child.layout->minimumGeometry().width);
|
||||
if(child.widget) width = max(width, child.widget->minimumGeometry().width);
|
||||
continue;
|
||||
}
|
||||
width = max(width, child.width);
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
height += child.spacing;
|
||||
if(child.height == MinimumSize || child.height == MaximumSize) {
|
||||
if(child.layout) height += child.layout->minimumGeometry().height;
|
||||
if(child.widget) height += child.widget->minimumGeometry().height;
|
||||
continue;
|
||||
}
|
||||
height += child.height;
|
||||
}
|
||||
|
||||
return { 0, 0, margin * 2 + width, margin * 2 + height };
|
||||
}
|
||||
|
||||
Geometry VerticalLayout::minimumLayoutGeometry() {
|
||||
unsigned width = 0, height = 0;
|
||||
bool maximumWidth = false;
|
||||
bool maximumHeight = false;
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.width == MaximumSize) {
|
||||
maximumWidth = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(child.width == MinimumSize) {
|
||||
if(child.layout) width = max(width, child.layout->minimumGeometry().width);
|
||||
if(child.widget) width = max(width, child.widget->minimumGeometry().width);
|
||||
continue;
|
||||
}
|
||||
|
||||
width = max(width, child.width);
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.height == MaximumSize) {
|
||||
maximumHeight = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(child.height == MinimumSize) {
|
||||
if(child.layout) height += child.layout->minimumGeometry().height;
|
||||
if(child.widget) height += child.widget->minimumGeometry().height;
|
||||
continue;
|
||||
}
|
||||
|
||||
height += child.height;
|
||||
}
|
||||
|
||||
return { 0, 0, maximumWidth ? MaximumSize : margin * 2 + width, maximumHeight ? MaximumSize : margin * 2 + height };
|
||||
}
|
||||
|
||||
void VerticalLayout::setGeometry(const Geometry &containerGeometry) {
|
||||
auto children = this->children;
|
||||
foreach(child, children) {
|
||||
if(child.layout) {
|
||||
child.width = child.layout->minimumLayoutGeometry().width;
|
||||
child.height = child.layout->minimumLayoutGeometry().height;
|
||||
}
|
||||
|
||||
if(child.widget) {
|
||||
if(child.width == MinimumSize) child.width = child.widget->minimumGeometry().width;
|
||||
if(child.height == MinimumSize) child.height = child.widget->minimumGeometry().height;
|
||||
}
|
||||
}
|
||||
|
||||
Geometry geometry = containerGeometry;
|
||||
geometry.x += margin;
|
||||
geometry.y += margin;
|
||||
geometry.width -= margin * 2;
|
||||
geometry.height -= margin * 2;
|
||||
|
||||
unsigned minimumHeight = 0, maximumHeightCounter = 0;
|
||||
foreach(child, children) {
|
||||
if(child.height == MaximumSize) maximumHeightCounter++;
|
||||
if(child.height != MaximumSize) minimumHeight += child.height;
|
||||
minimumHeight += child.spacing;
|
||||
}
|
||||
|
||||
foreach(child, children) {
|
||||
if(child.width == MaximumSize) child.width = geometry.width;
|
||||
if(child.height == MaximumSize) child.height = (geometry.height - minimumHeight) / maximumHeightCounter;
|
||||
}
|
||||
|
||||
unsigned maximumWidth = 0;
|
||||
foreach(child, children) maximumWidth = max(maximumWidth, child.width);
|
||||
|
||||
foreach(child, children) {
|
||||
unsigned pivot = 0; //(maximumWidth - child.width) / 2;
|
||||
Geometry childGeometry = { geometry.x + pivot, geometry.y, child.width, child.height };
|
||||
|
||||
if(child.layout) child.layout->setGeometry(childGeometry);
|
||||
if(child.widget) child.widget->setGeometry(childGeometry);
|
||||
|
||||
geometry.y += child.height + child.spacing;
|
||||
geometry.height -= child.height + child.spacing;
|
||||
}
|
||||
}
|
||||
|
||||
void VerticalLayout::setMargin(unsigned margin) {
|
||||
this->margin = margin;
|
||||
}
|
||||
|
||||
void VerticalLayout::setParent(Window &parent) {
|
||||
foreach(child, children) {
|
||||
if(child.layout) child.layout->setParent(parent);
|
||||
if(child.widget) parent.append(*child.widget);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
22
bsnes/phoenix/core/layout/vertical-layout.hpp
Executable file
22
bsnes/phoenix/core/layout/vertical-layout.hpp
Executable file
@@ -0,0 +1,22 @@
|
||||
struct HorizontalLayout;
|
||||
|
||||
struct VerticalLayout : public Layout {
|
||||
void append(HorizontalLayout &layout, unsigned spacing = 0);
|
||||
void append(Widget &widget, unsigned width, unsigned height, unsigned spacing = 0);
|
||||
Geometry minimumGeometry();
|
||||
Geometry minimumLayoutGeometry();
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void setMargin(unsigned margin);
|
||||
void setParent(Window &parent);
|
||||
void setVisible(bool visible);
|
||||
VerticalLayout();
|
||||
|
||||
//private:
|
||||
unsigned margin;
|
||||
struct Children {
|
||||
HorizontalLayout *layout;
|
||||
Widget *widget;
|
||||
unsigned width, height, spacing;
|
||||
};
|
||||
nall::linear_vector<Children> children;
|
||||
};
|
234
bsnes/phoenix/core/state.hpp
Executable file
234
bsnes/phoenix/core/state.hpp
Executable file
@@ -0,0 +1,234 @@
|
||||
struct Font::State {
|
||||
bool bold;
|
||||
string family;
|
||||
bool italic;
|
||||
unsigned size;
|
||||
bool underline;
|
||||
|
||||
State() {
|
||||
bold = false;
|
||||
italic = false;
|
||||
size = 8;
|
||||
underline = false;
|
||||
}
|
||||
};
|
||||
|
||||
struct Timer::State {
|
||||
bool enabled;
|
||||
unsigned milliseconds;
|
||||
|
||||
State() {
|
||||
enabled = false;
|
||||
milliseconds = 0;
|
||||
}
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
22
bsnes/phoenix/gtk/action/action.cpp
Executable file
22
bsnes/phoenix/gtk/action/action.cpp
Executable file
@@ -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() {
|
||||
}
|
22
bsnes/phoenix/gtk/action/check-item.cpp
Executable file
22
bsnes/phoenix/gtk/action/check-item.cpp
Executable file
@@ -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);
|
||||
}
|
12
bsnes/phoenix/gtk/action/item.cpp
Executable file
12
bsnes/phoenix/gtk/action/item.cpp
Executable file
@@ -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);
|
||||
}
|
19
bsnes/phoenix/gtk/action/menu.cpp
Executable file
19
bsnes/phoenix/gtk/action/menu.cpp
Executable file
@@ -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);
|
||||
}
|
33
bsnes/phoenix/gtk/action/radio-item.cpp
Executable file
33
bsnes/phoenix/gtk/action/radio-item.cpp
Executable file
@@ -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);
|
||||
}
|
3
bsnes/phoenix/gtk/action/separator.cpp
Executable file
3
bsnes/phoenix/gtk/action/separator.cpp
Executable file
@@ -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,58 +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;
|
||||
}
|
||||
|
||||
void EditBox::setCursorPosition(unsigned position) {
|
||||
GtkTextMark *mark = gtk_text_buffer_get_mark(object->textBuffer, "insert");
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_end_iter(object->textBuffer, &iter);
|
||||
gtk_text_iter_set_offset(&iter, min(position, gtk_text_iter_get_offset(&iter)));
|
||||
gtk_text_buffer_place_cursor(object->textBuffer, &iter);
|
||||
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(object->subWidget), mark);
|
||||
}
|
@@ -1,18 +1,32 @@
|
||||
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;
|
||||
Geometry pFont::geometry(const string &text) {
|
||||
pango_layout_set_font_description(gtkLayout, gtkFont);
|
||||
pango_layout_set_text(gtkLayout, text, -1);
|
||||
int width = 0, height = 0;
|
||||
pango_layout_get_pixel_size(gtkLayout, &width, &height);
|
||||
return { 0, 0, width, height };
|
||||
}
|
||||
|
||||
Font::Font() {
|
||||
font = new Font::Data;
|
||||
font->font = 0;
|
||||
void pFont::setBold(bool bold) {
|
||||
pango_font_description_set_weight(gtkFont, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
|
||||
}
|
||||
|
||||
Font::~Font() {
|
||||
if(font->font) pango_font_description_free(font->font);
|
||||
delete font;
|
||||
void pFont::setFamily(const string &family) {
|
||||
pango_font_description_set_family(gtkFont, family);
|
||||
}
|
||||
|
||||
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();
|
||||
PangoContext *context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
|
||||
gtkLayout = pango_layout_new(context);
|
||||
}
|
||||
|
@@ -1,49 +1,159 @@
|
||||
#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 "timer.cpp"
|
||||
#include "message-window.cpp"
|
||||
#include "window.cpp"
|
||||
#include "button.cpp"
|
||||
#include "canvas.cpp"
|
||||
#include "checkbox.cpp"
|
||||
#include "combobox.cpp"
|
||||
#include "editbox.cpp"
|
||||
#include "hexeditor.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/canvas.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"
|
||||
|
||||
Font pOS::defaultFont;
|
||||
|
||||
Geometry pOS::availableGeometry() {
|
||||
Display *display = XOpenDisplay(0);
|
||||
int screen = DefaultScreen(display);
|
||||
|
||||
static Atom atom = X11None;
|
||||
if(atom == X11None) atom = XInternAtom(display, "_NET_WORKAREA", True);
|
||||
|
||||
int format;
|
||||
unsigned char *data = 0;
|
||||
unsigned long items, after;
|
||||
Atom returnAtom;
|
||||
|
||||
int result = XGetWindowProperty(
|
||||
display, RootWindow(display, screen), atom, 0, 4, False, XA_CARDINAL, &returnAtom, &format, &items, &after, &data
|
||||
);
|
||||
|
||||
XCloseDisplay(display);
|
||||
|
||||
if(result == Success && returnAtom == XA_CARDINAL && format == 32 && items == 4) {
|
||||
unsigned long *workarea = (unsigned long*)data;
|
||||
return { (signed)workarea[0], (signed)workarea[1], (unsigned)workarea[2], (unsigned)workarea[3] };
|
||||
}
|
||||
|
||||
return desktopGeometry();
|
||||
}
|
||||
|
||||
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];
|
||||
@@ -63,128 +173,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,287 +1,390 @@
|
||||
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;
|
||||
};
|
||||
struct pOS : public pObject {
|
||||
static Font defaultFont;
|
||||
|
||||
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);
|
||||
void setCursorPosition(unsigned position);
|
||||
};
|
||||
|
||||
struct HexEditor : Widget {
|
||||
nall::function<uint8_t (unsigned)> onRead;
|
||||
nall::function<void (unsigned, uint8_t)> onWrite;
|
||||
void create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height);
|
||||
void setSize(unsigned size);
|
||||
void setOffset(unsigned offset);
|
||||
void setColumns(unsigned columns);
|
||||
void setRows(unsigned rows);
|
||||
void update();
|
||||
HexEditor();
|
||||
//private:
|
||||
struct Data;
|
||||
Data *hexEditor;
|
||||
bool keyPress(unsigned scancode);
|
||||
void scroll(unsigned position);
|
||||
void setScroll();
|
||||
void updateScroll();
|
||||
unsigned cursorPosition();
|
||||
void setCursorPosition(unsigned position);
|
||||
};
|
||||
|
||||
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();
|
||||
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;
|
||||
PangoLayout *gtkLayout;
|
||||
|
||||
Geometry geometry(const string &text);
|
||||
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 pTimer : public pObject {
|
||||
Timer &timer;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
void setInterval(unsigned milliseconds);
|
||||
|
||||
pTimer(Timer &timer) : timer(timer) {}
|
||||
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();
|
||||
Font& font();
|
||||
virtual Geometry minimumGeometry();
|
||||
void setEnabled(bool enabled);
|
||||
virtual void setFocused();
|
||||
virtual void setFont(Font &font);
|
||||
virtual void setGeometry(const Geometry &geometry);
|
||||
void setVisible(bool visible);
|
||||
|
||||
pWidget(Widget &widget) : widget(widget) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pButton : public pWidget {
|
||||
Button &button;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
void setText(const string &text);
|
||||
|
||||
pButton(Button &button) : pWidget(button), button(button) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pCanvas : public pWidget {
|
||||
Canvas &canvas;
|
||||
uint32_t *bufferRGB;
|
||||
uint32_t *bufferBGR;
|
||||
|
||||
uint32_t* buffer();
|
||||
void setGeometry(const Geometry &geometry);
|
||||
void update();
|
||||
|
||||
pCanvas(Canvas &canvas) : pWidget(canvas), canvas(canvas) {}
|
||||
void constructor();
|
||||
void redraw();
|
||||
};
|
||||
|
||||
struct pCheckBox : public pWidget {
|
||||
CheckBox &checkBox;
|
||||
|
||||
bool checked();
|
||||
Geometry minimumGeometry();
|
||||
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);
|
||||
Geometry minimumGeometry();
|
||||
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;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
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;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
void setText(const string &text);
|
||||
|
||||
pLabel(Label &label) : pWidget(label), label(label) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pLineEdit : public pWidget {
|
||||
LineEdit &lineEdit;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
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;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
void setPosition(unsigned position);
|
||||
|
||||
pProgressBar(ProgressBar &progressBar) : pWidget(progressBar), progressBar(progressBar) {}
|
||||
void constructor();
|
||||
};
|
||||
|
||||
struct pRadioBox : public pWidget {
|
||||
RadioBox &radioBox;
|
||||
|
||||
bool checked();
|
||||
Geometry minimumGeometry();
|
||||
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;
|
||||
|
||||
Geometry minimumGeometry();
|
||||
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,266 +0,0 @@
|
||||
static bool HexEditor_keyPress(GtkWidget *widget, GdkEventKey *event, HexEditor *self) {
|
||||
return self->keyPress(event->keyval);
|
||||
}
|
||||
|
||||
static bool HexEditor_scroll(GtkRange *range, GtkScrollType scroll, gdouble value, HexEditor *self) {
|
||||
self->scroll((unsigned)value);
|
||||
return false;
|
||||
}
|
||||
|
||||
void HexEditor::create(Window &parent, unsigned x, unsigned y, unsigned width, unsigned height) {
|
||||
widget->parent = &parent;
|
||||
|
||||
hexEditor->size = 0;
|
||||
hexEditor->offset = 0;
|
||||
hexEditor->columns = 16;
|
||||
hexEditor->rows = 16;
|
||||
|
||||
object->widget = gtk_hbox_new(false, 0);
|
||||
gtk_widget_set_size_request(object->widget, width, height);
|
||||
|
||||
hexEditor->container = gtk_scrolled_window_new(0, 0);
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
||||
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(hexEditor->container), GTK_SHADOW_ETCHED_IN);
|
||||
|
||||
hexEditor->widget = gtk_text_view_new();
|
||||
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(hexEditor->widget), GTK_WRAP_NONE);
|
||||
gtk_container_add(GTK_CONTAINER(hexEditor->container), hexEditor->widget);
|
||||
g_signal_connect(G_OBJECT(hexEditor->widget), "key-press-event", G_CALLBACK(HexEditor_keyPress), (gpointer)this);
|
||||
|
||||
hexEditor->scroll = gtk_vscrollbar_new((GtkAdjustment*)0);
|
||||
gtk_range_set_range(GTK_RANGE(hexEditor->scroll), 0, 256);
|
||||
gtk_range_set_increments(GTK_RANGE(hexEditor->scroll), 1, 16);
|
||||
gtk_widget_set_sensitive(hexEditor->scroll, false);
|
||||
g_signal_connect(G_OBJECT(hexEditor->scroll), "change-value", G_CALLBACK(HexEditor_scroll), (gpointer)this);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->container, true, true, 0);
|
||||
gtk_box_pack_start(GTK_BOX(object->widget), hexEditor->scroll, false, false, 1);
|
||||
|
||||
object->textBuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(hexEditor->widget));
|
||||
hexEditor->cursor = gtk_text_buffer_get_mark(object->textBuffer, "insert");
|
||||
|
||||
gtk_fixed_put(GTK_FIXED(parent.object->formContainer), object->widget, x, y);
|
||||
if(parent.window->defaultFont) setFont(*parent.window->defaultFont);
|
||||
|
||||
gtk_widget_show(hexEditor->scroll);
|
||||
gtk_widget_show(hexEditor->widget);
|
||||
gtk_widget_show(hexEditor->container);
|
||||
gtk_widget_show(object->widget);
|
||||
}
|
||||
|
||||
void HexEditor::setSize(unsigned size) {
|
||||
hexEditor->size = size;
|
||||
setScroll();
|
||||
}
|
||||
|
||||
void HexEditor::setOffset(unsigned offset) {
|
||||
hexEditor->offset = offset;
|
||||
setScroll();
|
||||
updateScroll();
|
||||
}
|
||||
|
||||
void HexEditor::setColumns(unsigned columns) {
|
||||
hexEditor->columns = columns;
|
||||
setScroll();
|
||||
}
|
||||
|
||||
void HexEditor::setRows(unsigned rows) {
|
||||
hexEditor->rows = rows;
|
||||
setScroll();
|
||||
}
|
||||
|
||||
void HexEditor::update() {
|
||||
if(!onRead) {
|
||||
gtk_text_buffer_set_text(object->textBuffer, "", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned position = cursorPosition();
|
||||
|
||||
string output;
|
||||
unsigned offset = hexEditor->offset;
|
||||
for(unsigned row = 0; row < hexEditor->rows; row++) {
|
||||
output.append(hex<8>(offset));
|
||||
output.append(" ");
|
||||
|
||||
string hexdata;
|
||||
string ansidata = " ";
|
||||
for(unsigned column = 0; column < hexEditor->columns; column++) {
|
||||
if(offset < hexEditor->size) {
|
||||
uint8_t data = 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 >= hexEditor->size) break;
|
||||
if(row != hexEditor->rows - 1) output.append("\n");
|
||||
}
|
||||
|
||||
gtk_text_buffer_set_text(object->textBuffer, output, -1);
|
||||
if(position == 0) position = 10; //start at first position where hex values can be entered
|
||||
setCursorPosition(position);
|
||||
}
|
||||
|
||||
HexEditor::HexEditor() {
|
||||
hexEditor = new HexEditor::Data;
|
||||
}
|
||||
|
||||
//internal
|
||||
|
||||
bool HexEditor::keyPress(unsigned scancode) {
|
||||
if(!onRead && !onWrite) return false;
|
||||
|
||||
unsigned position = cursorPosition();
|
||||
unsigned lineWidth = 10 + (hexEditor->columns * 3) + 1 + (hexEditor->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 + (hexEditor->columns * 3 - 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Up) {
|
||||
if(cursorY != 0) return false;
|
||||
|
||||
signed newOffset = hexEditor->offset - hexEditor->columns;
|
||||
if(newOffset >= 0) {
|
||||
setOffset(newOffset);
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Down) {
|
||||
if(cursorY != hexEditor->rows - 1) return false;
|
||||
|
||||
signed newOffset = hexEditor->offset + hexEditor->columns;
|
||||
if(newOffset + hexEditor->columns * hexEditor->rows - (hexEditor->columns - 1) <= hexEditor->size) {
|
||||
setOffset(newOffset);
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Page_Up) {
|
||||
signed newOffset = hexEditor->offset - hexEditor->columns * hexEditor->rows;
|
||||
if(newOffset >= 0) {
|
||||
setOffset(newOffset);
|
||||
update();
|
||||
} else {
|
||||
setOffset(0);
|
||||
update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if(scancode == GDK_Page_Down) {
|
||||
signed newOffset = hexEditor->offset + hexEditor->columns * hexEditor->rows;
|
||||
for(unsigned n = 0; n < hexEditor->rows; n++) {
|
||||
if(newOffset + hexEditor->columns * hexEditor->rows - (hexEditor->columns - 1) <= hexEditor->size) {
|
||||
setOffset(newOffset);
|
||||
update();
|
||||
break;
|
||||
}
|
||||
newOffset -= hexEditor->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 < hexEditor->columns) {
|
||||
//not in ANSI region
|
||||
unsigned offset = hexEditor->offset + (cursorY * hexEditor->columns + cursorX);
|
||||
|
||||
if(offset >= hexEditor->size) return false; //do not edit past end of file
|
||||
uint8_t data = onRead(offset);
|
||||
|
||||
//write modified value
|
||||
if(cursorNibble == 1) {
|
||||
data = (data & 0xf0) | (scancode << 0);
|
||||
} else {
|
||||
data = (data & 0x0f) | (scancode << 4);
|
||||
}
|
||||
onWrite(offset, data);
|
||||
|
||||
//auto-advance cursor to next nibble/byte
|
||||
position++;
|
||||
if(cursorNibble && cursorX != hexEditor->columns - 1) position++;
|
||||
setCursorPosition(position);
|
||||
|
||||
//refresh output to reflect modified data
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HexEditor::scroll(unsigned position) {
|
||||
unsigned rows = hexEditor->size / hexEditor->columns;
|
||||
if(position >= rows) position = rows - 1;
|
||||
setOffset(position * hexEditor->columns);
|
||||
update();
|
||||
}
|
||||
|
||||
void HexEditor::setScroll() {
|
||||
unsigned rows = hexEditor->size / hexEditor->columns;
|
||||
if(rows) rows--;
|
||||
if(rows) {
|
||||
gtk_range_set_range(GTK_RANGE(hexEditor->scroll), 0, rows);
|
||||
gtk_widget_set_sensitive(hexEditor->scroll, true);
|
||||
} else {
|
||||
gtk_widget_set_sensitive(hexEditor->scroll, false);
|
||||
}
|
||||
}
|
||||
|
||||
void HexEditor::updateScroll() {
|
||||
unsigned row = hexEditor->offset / hexEditor->columns;
|
||||
gtk_range_set_value(GTK_RANGE(hexEditor->scroll), row);
|
||||
}
|
||||
|
||||
unsigned HexEditor::cursorPosition() {
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_iter_at_mark(object->textBuffer, &iter, hexEditor->cursor);
|
||||
return gtk_text_iter_get_offset(&iter);
|
||||
}
|
||||
|
||||
void HexEditor::setCursorPosition(unsigned position) {
|
||||
GtkTextIter iter;
|
||||
gtk_text_buffer_get_iter_at_mark(object->textBuffer, &iter, hexEditor->cursor);
|
||||
|
||||
//GTK+ will throw a hundred errors on the terminal
|
||||
//if you set an iterator past the end of the text buffer
|
||||
GtkTextIter endIter;
|
||||
gtk_text_buffer_get_end_iter(object->textBuffer, &iter);
|
||||
unsigned endPosition = gtk_text_iter_get_offset(&iter);
|
||||
|
||||
gtk_text_iter_set_offset(&iter, min(position, endPosition));
|
||||
gtk_text_buffer_place_cursor(object->textBuffer, &iter);
|
||||
}
|
@@ -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 = decimal(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,69 +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 HexEditor::Data {
|
||||
GtkWidget *container;
|
||||
GtkWidget *widget;
|
||||
GtkWidget *scroll;
|
||||
|
||||
GtkTextMark *cursor;
|
||||
unsigned size;
|
||||
unsigned offset;
|
||||
unsigned columns;
|
||||
unsigned rows;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
24
bsnes/phoenix/gtk/settings.cpp
Executable file
24
bsnes/phoenix/gtk/settings.cpp
Executable file
@@ -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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user