diff options
Diffstat (limited to 'Source/Applications')
-rw-r--r-- | Source/Applications/Demos/GOL.cpp | 95 | ||||
-rw-r--r-- | Source/Applications/Demos/Makefile (renamed from Source/Applications/SampleApps/Makefile) | 2 | ||||
-rw-r--r-- | Source/Applications/Demos/asmdemo.asm (renamed from Source/Applications/SampleApps/asmdemo.asm) | 0 | ||||
-rw-r--r-- | Source/Applications/Demos/cxxdemo.cpp (renamed from Source/Applications/SampleApps/cxxdemo.cpp) | 0 | ||||
-rw-r--r-- | Source/Applications/Demos/lib-melonasm.asm (renamed from Source/Applications/SampleApps/lib-melonasm.asm) | 0 |
5 files changed, 96 insertions, 1 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp new file mode 100644 index 0000000..6dd1cdf --- /dev/null +++ b/Source/Applications/Demos/GOL.cpp @@ -0,0 +1,95 @@ +#include <Binding/VirtualTerminal.class.h> +#include <Binding/Thread.class.h> +#include <String.class.h> +#include <Rand.ns.h> + +int main(Vector<String> args) { + if (!outvt.isBoxed()) { + outvt << "Error : cannot display GOL on a non-boxed terminal.\n"; + return 1; + } + + int h = outvt.height() - 1, w = outvt.width(); + + bool *cells = new bool[w * h]; + bool *newcells = new bool[w * h]; + + u32int delay = 100; + + for (u32int x = 0; x < w; x++) { + for (u32int y = 0; y < h; y++) { + cells[x * h + y] = false; + } + } + + while (1) { + //Display cells + outvt.moveCursor(0, 0); + for (u32int y = 0; y < h; y++) { + for (u32int x = 0; x < w; x++) { + if (cells[x * h + y]) { + outvt.setColor(0, 2); + } else { + outvt.setColor(7, 0); + } + outvt << " "; + } + } + outvt << "Press Ctrl+h for help"; + + //Compute next generation + for (u32int y = 0; y < h; y++) { + for (u32int x = 0; x < w; x++) { + u8int n = 0; + for (u32int yy = y - 1; yy <= y + 1; yy++) { + for (u32int xx = x - 1; xx <= x + 2; xx++) { + if (xx < w and yy < h and cells[xx * h + yy]) n++; + } + } + if (cells[x * h + y]) n--; + if ((cells[x * h + y] and n == 2) or n == 3) { + newcells[x * h + y] = true; + } else { + newcells[x * h + y] = false; + } + } + } + for (u32int x = 0; x < w; x++) { + for (u32int y = 0; y < h; y++) { + cells[x * h + y] = newcells[x * h + y]; + } + } + + keypress_t kp = invt.getKeypress(false, false); + if (kp.hascmd && (kp.modifiers & STATUS_CTRL)) { + if (kp.character == WChar("c")) { + break; + } else if (kp.character == WChar("r")) { + for (u32int i = 0; i < 20; i++) { + u64int x = Rand::rand() * w / Rand::max(); + u64int y = Rand::rand() * h / Rand::max(); + cells[x * h + y] = true; + } + } else if (kp.character == WChar("R")) { + for (u32int i = 0; i < h; i++) { + cells[i] = true; + cells[(2 * i) % (h - i)] = true; + cells[(w * i) % (h * w - i)] = true; + } + } else if (kp.character == WChar("h")) { + outvt << "** Melon's demo Game Of Life Simulator help :\n"; + outvt << " - ctrl+c : quit\n"; + outvt << " - ctrl+h : show this\n"; + outvt << " - ctrl+r : add some random cells\n"; + outvt << " - ctrl+R : add more cells, but not random\n"; + outvt << "Press any key to return to simultaor..."; + invt.getKeypress(); + } + } + + Thread::get().sleep(100); + } + + delete cells; + delete newcells; +} diff --git a/Source/Applications/SampleApps/Makefile b/Source/Applications/Demos/Makefile index 05f79b1..e66acce 100644 --- a/Source/Applications/SampleApps/Makefile +++ b/Source/Applications/Demos/Makefile @@ -9,7 +9,7 @@ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I . LD = ld LDFLAGS = -T ../../Library/Link.ld -L ../../Library -Applications = asmdemo cxxdemo +Applications = asmdemo cxxdemo GOL all: $(Applications) echo "* Done with applications : $(Applications)" diff --git a/Source/Applications/SampleApps/asmdemo.asm b/Source/Applications/Demos/asmdemo.asm index d57cc9b..d57cc9b 100644 --- a/Source/Applications/SampleApps/asmdemo.asm +++ b/Source/Applications/Demos/asmdemo.asm diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/Demos/cxxdemo.cpp index 3d452e7..3d452e7 100644 --- a/Source/Applications/SampleApps/cxxdemo.cpp +++ b/Source/Applications/Demos/cxxdemo.cpp diff --git a/Source/Applications/SampleApps/lib-melonasm.asm b/Source/Applications/Demos/lib-melonasm.asm index 0845770..0845770 100644 --- a/Source/Applications/SampleApps/lib-melonasm.asm +++ b/Source/Applications/Demos/lib-melonasm.asm |