85 lines
1.6 KiB
C++
85 lines
1.6 KiB
C++
// vim: set noet ts=4 sw=4:
|
|
|
|
#include "../libsys/stub.h"
|
|
#include "../libsys/string.h"
|
|
|
|
char* itoh(unsigned int value, char* buffer) {
|
|
char* ptr = &buffer[11];
|
|
*ptr = '\0'; // Nullterminator am Ende setzen
|
|
|
|
if (value == 0) {
|
|
*--ptr = '0';
|
|
return ptr;
|
|
}
|
|
|
|
do {
|
|
ptr--;
|
|
*ptr = '0' + (value % 16);
|
|
if(*ptr >= 0x3A)
|
|
*ptr+=7;
|
|
value /= 16;
|
|
} while (value != 0);
|
|
|
|
return ptr;
|
|
}
|
|
char* itoa(unsigned int value, char* buffer) {
|
|
char* ptr = &buffer[11];
|
|
*ptr = '\0'; // Nullterminator am Ende setzen
|
|
|
|
if (value == 0) {
|
|
*--ptr = '0';
|
|
return ptr;
|
|
}
|
|
|
|
do {
|
|
ptr--;
|
|
*ptr = '0' + (value % 10);
|
|
value /= 10;
|
|
} while (value != 0);
|
|
|
|
return ptr;
|
|
}
|
|
|
|
extern "C" void main() {
|
|
// Thread 1 may be an auxiliary thread
|
|
|
|
//sys_test(1,2,3,4,5);
|
|
|
|
unsigned id = sys_getpid();
|
|
char text[] = "appX";
|
|
text[3] = 0x30+id;
|
|
|
|
write(1, text, sizeof(text), 0, (int)id);
|
|
|
|
uint8_t cnt = 0;
|
|
for (unsigned i = 1;; ++i) {
|
|
if(id == 2){
|
|
send(4, text, strlen(text), text, 5);
|
|
write(1, text, strlen(text), 25, (int)id);
|
|
}
|
|
if(id == 4){
|
|
char blubb[10];
|
|
receive(blubb, 10);
|
|
write(1, blubb, strlen(blubb), 25, (int)id);
|
|
reply("toast", 5);
|
|
}
|
|
|
|
//counter to see app running
|
|
cnt=(cnt+1)%100;
|
|
char buf[12];
|
|
char* msg = itoa(cnt,buf);
|
|
write(1, msg, strlen(msg), 6, (int)id);
|
|
|
|
// test map/unmap and print ptr
|
|
void* ptr= map(4096);
|
|
uint16_t* val = ((uint16_t*)ptr);
|
|
*val = 0x1337;
|
|
|
|
msg = itoh((uintptr_t)ptr,buf);
|
|
write(1, msg, strlen(msg), 12, (int)id);
|
|
unmap(ptr, 4096);
|
|
|
|
sleep(100);
|
|
}
|
|
}
|