diff options
author | Alexis211 <alexis211@gmail.com> | 2009-11-13 18:05:27 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-11-13 18:05:27 +0100 |
commit | 2b9e97b8635c20c5a2b87789b1014489863d1994 (patch) | |
tree | 58fa9f2fa82ac9477819193b6731b8b927187224 /Source/Library | |
parent | 7e3ecd80af5ddcedbfa3d849284400ed6568f516 (diff) | |
download | Melon-2b9e97b8635c20c5a2b87789b1014489863d1994.tar.gz Melon-2b9e97b8635c20c5a2b87789b1014489863d1994.zip |
Added a game of life simulator demo
Diffstat (limited to 'Source/Library')
-rw-r--r-- | Source/Library/Common/Mutex.class.cpp | 2 | ||||
-rw-r--r-- | Source/Library/Common/Rand.ns.cpp | 2 | ||||
-rw-r--r-- | Source/Library/Common/cppsupport.wtf.cpp | 54 | ||||
-rw-r--r-- | Source/Library/Interface/Kbd.iface.h | 98 | ||||
-rw-r--r-- | Source/Library/Interface/VirtualTerminal.iface.h | 5 | ||||
-rw-r--r-- | Source/Library/Makefile | 4 | ||||
-rw-r--r-- | Source/Library/Userland/Binding/VirtualTerminal.class.h | 17 | ||||
-rw-r--r-- | Source/Library/Userland/Start.cpp | 4 |
8 files changed, 179 insertions, 7 deletions
diff --git a/Source/Library/Common/Mutex.class.cpp b/Source/Library/Common/Mutex.class.cpp index 2e9a63c..d7d7ead 100644 --- a/Source/Library/Common/Mutex.class.cpp +++ b/Source/Library/Common/Mutex.class.cpp @@ -41,5 +41,5 @@ void Mutex::unlock() { } bool Mutex::locked() { - return m_locked; + return m_locked == MUTEX_TRUE; } diff --git a/Source/Library/Common/Rand.ns.cpp b/Source/Library/Common/Rand.ns.cpp index e568678..6323ccc 100644 --- a/Source/Library/Common/Rand.ns.cpp +++ b/Source/Library/Common/Rand.ns.cpp @@ -7,7 +7,7 @@ u64int current = RANDOM_SEED; u64int rand() { current = (u32int)(a*current + b); - while (current > m) current -= m; + if (current > m) current = current % m; return current; } diff --git a/Source/Library/Common/cppsupport.wtf.cpp b/Source/Library/Common/cppsupport.wtf.cpp new file mode 100644 index 0000000..06ef1b9 --- /dev/null +++ b/Source/Library/Common/cppsupport.wtf.cpp @@ -0,0 +1,54 @@ +//This file just contains a few methods required for some C++ things to work +#include <types.h> + +namespace CMem { + u8int* memcpy(u8int*, const u8int*, int); +}; + +using namespace CMem; + +extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes + +void *__dso_handle; //Required when using global objects +extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } + +extern "C" void * memmove(void* dst, const void* src, size_t len) { + memcpy((u8int*)dst, (const u8int*)src, len); + return dst; +} + +//Functions for quad divisions/modulo. Taken and arranged from klibc include/asm/div64.h +//These only work with 32-bit divisors and only return 32-bit remainder. +//TODO : think of some correct quad div/mod algorithms +inline u64int doDiv(u64int dividend, u32int divisor, u32int *remainder) { + union { + u64int v64; + u32int v32[2]; + } d = { dividend }; + u32int upper; + + upper = d.v32[1]; + d.v32[1] = 0; + if (upper >= divisor) { + d.v32[1] = upper / divisor; + upper %= divisor; + } + asm ("divl %2" : "=a" (d.v32[0]), "=d" (*remainder) : + "rm" (divisor), "0" (d.v32[0]), "1" (upper)); + return d.v64; +} + +extern "C" { +u64int __udivdi3(u64int dividend, u64int b) { + u32int divisor, remainder; + divisor = b; + return doDiv(dividend, divisor, &remainder); +} + +u64int __umoddi3(u64int dividend, u64int b) { + u32int divisor, remainder; + divisor = b; + doDiv(dividend, divisor, &remainder); + return remainder; +} +} diff --git a/Source/Library/Interface/Kbd.iface.h b/Source/Library/Interface/Kbd.iface.h new file mode 100644 index 0000000..5627605 --- /dev/null +++ b/Source/Library/Interface/Kbd.iface.h @@ -0,0 +1,98 @@ +#ifndef DEF_KBD_IFACE_H +#define DEF_KBD_IFACE_H + +#include <WChar.class.h> + +/* + * Some of these values are used internally by the kernel, just take whatever you need. + */ + +//Used by variable kbdstatus +#define STATUS_SCRL 0x40 +#define STATUS_NUM 0x20 +#define STATUS_CAPS 0x10 +#define STATUS_SHIFT 0x08 +#define STATUS_CTRL 0x04 +#define STATUS_ALT 0x02 +#define STATUS_ALTGR 0x01 + +//Used in control keys keymap. The ones > 100 are modifiers and are not supposed to be sent to applications. +#define KBDC_LEFTCTRL 101 +#define KBDC_RIGHTCTRL 102 +#define KBDC_ALT 103 +#define KBDC_ALTGR 104 +#define KBDC_LEFTSUP 5 //Super = windows +#define KBDC_RIGHTSUP 6 +#define KBDC_MENU 7 +#define KBDC_LEFTSHIFT 108 +#define KBDC_RIGHTSHIFT 109 +#define KBDC_CAPSLOCK 110 +#define KBDC_TAB 11 +#define KBDC_ENTER 12 +#define KBDC_BACKSPACE 13 + +#define KBDC_KPINSERT 14 //Key 0/insert +#define KBDC_KPEND 15 //Key 1/end +#define KBDC_KPDOWN 16 //Key 2/down +#define KBDC_KPPGDOWN 17 //Key 3/pgdown +#define KBDC_KPLEFT 18 //Key 4/left +#define KBDC_KP5 19 //Key 5 this is sent to receiving application, but must be ignored +#define KBDC_KPRIGHT 20 //Key 6/right +#define KBDC_KPHOME 21 //Key 7/home +#define KBDC_KPUP 22 //Key 8/up +#define KBDC_KPPGUP 23 //Key 9/pgup +#define KBDC_KPDEL 24 //Key ./del + +#define KBDC_HOME 25 +#define KBDC_END 26 +#define KBDC_INSERT 27 +#define KBDC_DEL 28 +#define KBDC_PGUP 29 +#define KBDC_PGDOWN 30 +#define KBDC_UP 31 +#define KBDC_DOWN 32 +#define KBDC_LEFT 33 +#define KBDC_RIGHT 34 + +#define KBDC_NUMLOCK 135 +#define KBDC_SCRLLOCK 136 +#define KBDC_PRTSCN 37 //Print screen +#define KBDC_SYSREQ 38 + +#define KBDC_ESCAPE 40 +#define KBDC_F1 41 +#define KBDC_F2 42 +#define KBDC_F3 43 +#define KBDC_F4 44 +#define KBDC_F5 45 +#define KBDC_F6 46 +#define KBDC_F7 47 +#define KBDC_F8 48 +#define KBDC_F9 49 +#define KBDC_F10 50 +#define KBDC_F11 51 +#define KBDC_F12 52 + +//This is a special case. Keycode is escaped, Keyboard:: will send a 0xB5 keycode, that must not be mixed up with 0x35 +#define KBDC_KPSLASH 53 + +/* + * This type defines a keypress event. + */ + +//== Possible cases for keypress_t : +// - hascmd && !haschar : this is a command key press/release (all grey keys except alt/ctrl/altgr/shift) +// - haschar && !hascmd : this is a character key press/release. Modifiers can haz STATUS_SHIFT or STATUS_ALTGR +// - haschar && hascmd : this is a character key press, but with ctrl and/or alt. See that in modifiers. +// - !haschar && !hascmd : invalid keypress +struct keypress_t { + bool pressed; + bool hascmd; + bool haschar; + u8int modifiers; + u8int command; + WChar character; //is 0 if !haschar + keypress_t() : hascmd(false), haschar(false), command(0), character('\0') {}; +}; + +#endif diff --git a/Source/Library/Interface/VirtualTerminal.iface.h b/Source/Library/Interface/VirtualTerminal.iface.h index c6388e6..c7e75e8 100644 --- a/Source/Library/Interface/VirtualTerminal.iface.h +++ b/Source/Library/Interface/VirtualTerminal.iface.h @@ -13,10 +13,15 @@ #define VTIF_WRITE 0x04 #define VTIF_READLINE 0x05 +#define VTIF_GETKEYPRESS 0x06 //Takes two flags : 1<<0 = show, 1<<1 = block #define VTIF_SETCOLOR 0x10 #define VTIF_SETCSRLINE 0x11 #define VTIF_SETCSRCOL 0x12 #define VTIF_ISBOXED 0x13 +#define VTIF_GETHEIGHT 0x1A +#define VTIF_GETWIDTH 0x1B +#define VTIF_LOCATE 0x1C //Takes line, col and sets cursor position + #endif diff --git a/Source/Library/Makefile b/Source/Library/Makefile index 5a7a039..5c77c84 100644 --- a/Source/Library/Makefile +++ b/Source/Library/Makefile @@ -1,7 +1,7 @@ .PHONY: clean, mrproper CXX = g++ -CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I Common -I Userland -I Interface -D THIS_IS_MELON_USERLAND +CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I Common -I Userland -I Interface -D THIS_IS_MELON_USERLAND -D RANDOM_SEED=1`date +%N`LL ASM = nasm ASMFLAGS = -f elf @@ -18,6 +18,8 @@ Objects = Common/WChar.class.uo \ Common/String.class.uo \ Common/TextFile.class.uo \ Common/ByteArray.class.uo \ + Common/Rand.ns.uo \ + Common/cppsupport.wtf.uo \ Userland/Syscall/Syscall.wtf.uo \ Userland/Syscall/RessourceCaller.class.uo \ Userland/Start.uo diff --git a/Source/Library/Userland/Binding/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h index 5fd9733..c8a4123 100644 --- a/Source/Library/Userland/Binding/VirtualTerminal.class.h +++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h @@ -4,6 +4,7 @@ #include <Syscall/RessourceCaller.class.h> #include <VirtualTerminal.iface.h> +#include <Kbd.iface.h> #include <String.class.h> #include <WChar.class.h> @@ -29,6 +30,10 @@ class VirtualTerminal : public RessourceCaller { void write(String s) { doCall(VTIF_WRITE, (u32int)&s); } + keypress_t getKeypress(bool show = true, bool block = true) { + keypress_t* ptr = (keypress_t*)doCall(VTIF_GETKEYPRESS, (show ? 1 : 0) | (block ? 2 : 0)); + return *ptr; + } String readLine(bool show = true) { return String::unserialize(doCall(VTIF_READLINE, (show ? 1 : 0))); } @@ -44,9 +49,21 @@ class VirtualTerminal : public RessourceCaller { bool isBoxed() { return doCall(VTIF_ISBOXED) != 0; } + u8int height() { + return doCall(VTIF_GETHEIGHT); + } + u8int width() { + return doCall(VTIF_GETWIDTH); + } void put(WChar c) { doCall(VTIF_PUT, c); } + void moveCursor(u8int line, u8int col) { + doCall(VTIF_LOCATE, line, col); + } + void put(u8int line, u8int col, WChar c) { + moveCursor(line, col); put(c); + } inline VirtualTerminal& operator<<(const String& s) { write(s); return *this; } inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; } diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index 032450d..0c25491 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -4,10 +4,6 @@ #include <Heap.class.h> -extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes -void *__dso_handle; //Required when using global objects -extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; } - extern u32int start_ctors, end_ctors, start_dtors, end_dtors; Heap heap; |