/programs/develop/libraries/newlib_example/Tupfile.lua |
---|
0,0 → 1,6 |
if tup.getconfig("NO_GCC") ~= "" or tup.getconfig("NO_FASM") ~= "" then return end |
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../.." or tup.getconfig("HELPERDIR") |
tup.include(HELPERDIR .. "/use_gcc.lua") |
tup.include(HELPERDIR .. "/use_newlib.lua") |
compile_gcc{"main.c"} |
link_gcc("binclock") |
/programs/develop/libraries/newlib_example/main.c |
---|
0,0 → 1,87 |
#include <kos32sys.h> |
#define B_SZ 10 |
static char * Title="BinClock"; |
static void draw_small_box(int x,int y,int is_on) |
{ |
draw_bar(x,y,B_SZ,B_SZ,is_on ? 0xFF0000 : 0x103000); |
} |
static void draw_box_group(int x,int y,int num) |
{ |
int i,j; |
char buf[2]; |
buf[0]=(num&(1+2+4+8))+'0'; |
buf[1]='\0'; |
for(i=0;i<4;i++) |
{ |
j=(B_SZ+2)*i; |
draw_small_box(x,y+((B_SZ+2)*i),num & (1<<(3-i)) ? 1 : 0); |
} |
draw_bar(x,y+((B_SZ+2)*4),B_SZ,B_SZ,0x800000); |
draw_text_sys(buf,x+2,y+((B_SZ+2)*4)+3,1,0xFFFFFF); |
} |
static void draw_bcd_num(int x,int y,int num) |
{ |
int v1,v2; |
v1=(num>>4)&(1+2+4+8); |
v2=num & (1+2+4+8); |
draw_box_group(x,y,v1); |
draw_box_group(x+B_SZ+2,y,v2); |
} |
static void draw_hms(int x,int y) |
{ |
unsigned t; |
int h,m,s; |
__asm__ __volatile__("int $0x40" : "=a"(t) : "a"(3)); |
s=(t & 0x00FF0000)>>16; |
m=(t & 0x0000FF00)>>8; |
h=(t & 0x000000FF); |
draw_bcd_num(x,y,h); |
x+=((B_SZ+2)<<1)+2; |
draw_bcd_num(x,y,m); |
x+=((B_SZ+2)<<1)+2; |
draw_bcd_num(x,y,s); |
} |
static void draw_h(void) |
{ |
draw_hms(22,28); |
} |
static void paint(void) |
{ |
BeginDraw(); |
DrawWindow(100,100,40+((B_SZ+2)*6)+4,30+((B_SZ+2)*4)+16,Title,0x80,0x13); |
draw_bar(20,26,((B_SZ+2)*6)+4+2,4+((B_SZ+1)*4)+2,0); |
draw_h(); |
EndDraw(); |
} |
int main(void) |
{ |
int i; |
paint(); |
for(;;) |
{ |
i=wait_for_event(20); |
draw_h(); |
switch(i) |
{ |
case 1: |
paint(); |
continue; |
case 2: |
get_key(); |
continue; |
case 3: |
if(get_os_button()==1) return 0; |
continue; |
} |
} |
} |
/programs/use_gcc.lua |
---|
1,4 → 1,12 |
CFLAGS = "-Os -fno-ident -fomit-frame-pointer -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -mpreferred-stack-boundary=2 -fno-exceptions -fno-asynchronous-unwind-tables -ffast-math -mno-ms-bitfields -march=pentium-mmx" |
CFLAGS_GENERIC = "-fno-ident -fomit-frame-pointer -fno-stack-check -fno-stack-protector -mno-stack-arg-probe -fno-exceptions -fno-asynchronous-unwind-tables -ffast-math -mno-ms-bitfields -march=pentium-mmx" |
CFLAGS_OPTIMIZE_SIZE = "-Os -mpreferred-stack-boundary=2 " .. CFLAGS_GENERIC |
CFLAGS_OPTIMIZE_SPEED = "-O2 -mpush-args -mno-accumulate-outgoing-args " .. CFLAGS_GENERIC |
-- The following could in specific cases be marginally faster CFLAGS_OPTIMIZE_SPEED, |
-- and in all cases gives a notable overhead in size. |
CFLAGS_OPTIMIZE_SPEED_INSANE = "-O2 " .. CFLAGS_GENERIC |
-- Default is optimizing by size. Override on per-project or per-file basis. |
CFLAGS = CFLAGS_OPTIMIZE_SIZE |
CFLAGS_c = "" -- extra flags for *.c |
CFLAGS_cpp = " -fno-rtti" -- extra flags for *.cpp |
LDFLAGS = "-nostdlib -n --file-alignment=16 --section-alignment=16" |
/programs/use_newlib.lua |
---|
0,0 → 1,16 |
NEWLIB_BASE = tup.getcwd() .. "/../contrib/sdk/sources/newlib" |
NEWLIB_LIB = tup.getcwd() .. "/../contrib/sdk/lib" |
TOOLCHAIN_LIBPATH = tup.getconfig("TOOLCHAIN_LIBPATH") |
-- if not given explicitly in config, try to guess |
if TOOLCHAIN_LIBPATH == "" then |
if tup.getconfig("TUP_PLATFORM") == "win32" |
then TOOLCHAIN_LIBPATH="C:\\MinGW\\msys\\1.0\\home\\autobuild\\tools\\win32\\mingw32\\lib" |
else TOOLCHAIN_LIBPATH="/home/autobuild/tools/win32/mingw32/lib" |
end |
end |
INCLUDES = INCLUDES .. " -I" .. NEWLIB_BASE .. "/libc/include" |
LDFLAGS = LDFLAGS .. " -T$(NEWLIB_BASE)/app.lds -L$(NEWLIB_LIB) -L$(TOOLCHAIN_LIBPATH) --image-base 0" |
tup.append_table(LIBDEPS, {NEWLIB_LIB .. "/<libapp.a>", NEWLIB_LIB .. "/<libc.dll.a>"}) |
LIBS = LIBS .. "-lgcc -lapp -lc.dll" |