summaryrefslogtreecommitdiff
path: root/Source/Applications/SampleApps
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Applications/SampleApps')
-rw-r--r--Source/Applications/SampleApps/Makefile37
-rw-r--r--Source/Applications/SampleApps/asmdemo.asm30
-rw-r--r--Source/Applications/SampleApps/cxxdemo.cpp19
-rw-r--r--Source/Applications/SampleApps/lib-melonasm.asm24
4 files changed, 110 insertions, 0 deletions
diff --git a/Source/Applications/SampleApps/Makefile b/Source/Applications/SampleApps/Makefile
new file mode 100644
index 0000000..a632f87
--- /dev/null
+++ b/Source/Applications/SampleApps/Makefile
@@ -0,0 +1,37 @@
+.PHONY: clean, mrproper
+
+ASM = nasm
+ASMFLAGS = -f elf
+
+CXX = g++
+CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND
+
+LD = ld
+LDFLAGS = -T ../../Library/Link.ld
+
+Applications = asmdemo cxxdemo
+
+all: $(Applications)
+ echo "* Done with applications : $(Applications)"
+
+rebuild: mrproper all
+
+%: %.cpp
+ echo "* Compiling $<..."
+ $(CXX) $(CXXFLAGS) -c $< -o $@.o
+ echo "* Linking $@.o..."
+ $(LD) $(LDFLAGS) ../../Library/Melon.o $@.o -o $@
+
+%: %.asm
+ echo "* Compiling $<..."
+ $(ASM) $(ASMFLAGS) -o $@.o $<
+ echo "* Linking $@.o..."
+ $(LD) $(LDFLAGS) $@.o -o $@
+
+clean:
+ echo "* Removing object files..."
+ rm -rf *.o
+
+mrproper: clean
+ echo "* Removing applications..."
+ rm -rf $(Applications)
diff --git a/Source/Applications/SampleApps/asmdemo.asm b/Source/Applications/SampleApps/asmdemo.asm
new file mode 100644
index 0000000..3037897
--- /dev/null
+++ b/Source/Applications/SampleApps/asmdemo.asm
@@ -0,0 +1,30 @@
+%include "lib-melonasm.asm"
+
+start: ; label used for calculating app size
+ mov ecx, [data]
+ mov ebx, ecx
+ mov eax, SC_WHEX
+ int 64
+ mov eax, SC_PUTCH
+ mov ebx, 10
+ int 64
+ loop:
+ inc ecx
+ mov eax, SC_PUTCH ;temporarily defined for writing one char to screen
+ mov ebx, ecx
+ int 64
+ mov eax, SC_SLEEP ;temporary syscall for sleeping
+ mov ebx, 30 ;20ms
+ int 64
+ cmp ecx, 127
+ jnz loop
+ mov eax, 0
+ mov eax, SC_PUTCH
+ mov ebx, 10 ;newline
+ int 64
+ int 66 ;finish task
+
+data:
+dd 0x00000020
+
+end: ; label used for calculating app size
diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp
new file mode 100644
index 0000000..01644a8
--- /dev/null
+++ b/Source/Applications/SampleApps/cxxdemo.cpp
@@ -0,0 +1,19 @@
+#include <Syscall/Syscall.wtf.h>
+#include <WChar.class.h>
+#include <Binding/VirtualTerminal.class.h>
+#include <Binding/Thread.class.h>
+
+int main() {
+ VirtualTerminal x = VirtualTerminal::get();
+ String s = x.readLine();
+ x.write(s);
+ Thread t = Thread::get();
+ for (char c = ' '; c <= 'z'; c++) {
+ t.sleep((u32int)c / 4);
+ x.put(c);
+ }
+ x.put("\n");
+ x.write("Salut les gens ! c'est le progrès !!!\nLe boeuf mort est juste là : ");
+ x.writeHex(0xDEADBEEF);
+ x.put("\n");
+}
diff --git a/Source/Applications/SampleApps/lib-melonasm.asm b/Source/Applications/SampleApps/lib-melonasm.asm
new file mode 100644
index 0000000..0845770
--- /dev/null
+++ b/Source/Applications/SampleApps/lib-melonasm.asm
@@ -0,0 +1,24 @@
+[bits 32]
+
+%ifidn __OUTPUT_FORMAT__, bin
+; create a MelonBinary output
+
+%define MEM_ORIGIN 0x10000000
+
+dd 0xFEEDBEEF ; magic number ^^
+dd end - start
+dd MEM_ORIGIN
+
+; the ($-$$) permits not taking into account the header above
+[org MEM_ORIGIN - ($-$$)]
+
+%elifidn __OUTPUT_FORMAT__, elf
+; create an elf object
+
+[global start]
+
+%endif
+
+%define SC_PUTCH 0xFFFFFF01
+%define SC_SLEEP 0xFFFFFF02
+%define SC_WHEX 0xFFFFFF03