Update src/funcs.c
This commit is contained in:
75
src/funcs.c
Normal file
75
src/funcs.c
Normal file
@@ -0,0 +1,75 @@
|
||||
// this code is licenced under Wrathmark licence
|
||||
// © 2026 wullie wulliestudio.com
|
||||
// please see attached licence for full usage and rights
|
||||
|
||||
#include "stdWullie.h"
|
||||
|
||||
// syscall1
|
||||
long syscall1(long number, long arg1){
|
||||
long result;
|
||||
|
||||
// asm for a system call with one arg
|
||||
__asm__ __volatile(
|
||||
"syscall"
|
||||
: "=a"(result)
|
||||
: "a"(number), "D"(arg1)
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// syscall3
|
||||
long syscall3(long number, long arg1, long arg2, long arg3){
|
||||
|
||||
long result;
|
||||
|
||||
// asm for a system call with 3 args
|
||||
__asm__ __volatile(
|
||||
"syscall"
|
||||
: "=a"(result)
|
||||
: "a"(number), "D"(arg1), "S"(arg2), "d"(arg3)
|
||||
: "rcx", "r11", "memory"
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// our own exit LINUX ONLY
|
||||
void exit(int code){
|
||||
|
||||
syscall1(SYS_exit, code);
|
||||
for(;;){}
|
||||
}
|
||||
|
||||
|
||||
// handles the length of a string for print
|
||||
long unsigned strlen(char *string){
|
||||
char *cursor = string;
|
||||
while(*cursor){
|
||||
cursor++;
|
||||
}
|
||||
long unsigned result = cursor - string;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// print
|
||||
void print(char *string){
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
}
|
||||
|
||||
// it can do everythig print can but better
|
||||
void ColorPrint(char *string, const char *color){
|
||||
syscall3(SYS_write, 1, (long)color, strlen(color));
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
|
||||
// instead of changing the foreground it changes the background
|
||||
void BackgroundPrint(char *string, const char *Bcolor){
|
||||
syscall3(SYS_write, 1, (long)Bcolor, strlen(Bcolor));
|
||||
syscall3(SYS_write, 1, (long)string, strlen(string));
|
||||
syscall3(SYS_write, 1, (long)NORMAL, sizeof(NORMAL)-1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user