From 2076a4a777b919b1ec0e8c185efc349655aa1436 Mon Sep 17 00:00:00 2001 From: turbocat Date: Sun, 26 Sep 2021 17:55:43 +0000 Subject: [PATCH] libc.obj: - Added vsprintf to export - Added sdltest.c example git-svn-id: svn://kolibrios.org@9204 a494cfbc-eb01-0410-851d-a64ba20cac60 --- .../ktcc/trunk/libc.obj/include/stdio.h | 1 + .../ktcc/trunk/libc.obj/samples/Makefile | 7 +- .../ktcc/trunk/libc.obj/samples/build_all.sh | 1 + .../ktcc/trunk/libc.obj/samples/sdltest.c | 79 +++++++++++++++++++ .../trunk/libc.obj/source/stdio/vprintf.c | 5 ++ .../ktcc/trunk/libc.obj/source/symbols.txt | 1 + 6 files changed, 91 insertions(+), 3 deletions(-) create mode 100755 programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c diff --git a/programs/develop/ktcc/trunk/libc.obj/include/stdio.h b/programs/develop/ktcc/trunk/libc.obj/include/stdio.h index 0c2c537341..24383b2602 100644 --- a/programs/develop/ktcc/trunk/libc.obj/include/stdio.h +++ b/programs/develop/ktcc/trunk/libc.obj/include/stdio.h @@ -40,6 +40,7 @@ extern int _FUNC(printf)(const char* format, ...); extern int _FUNC(sprintf)(char* buffer, const char* format, ...); extern int _FUNC(snprintf)(char* buffer, size_t count, const char* format, ...); extern int _FUNC(vsnprintf)(char* buffer, size_t count, const char* format, va_list va); +extern int _FUNC(vsprintf)(char* buffer, const char* format, va_list va); extern int _FUNC(vprintf)(const char* format, va_list va); extern void _FUNC(debug_printf)(const char* format, ...); diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile index 2130a39e82..b0ad39d36e 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/Makefile +++ b/programs/develop/ktcc/trunk/libc.obj/samples/Makefile @@ -2,7 +2,7 @@ KTCC=kos32-tcc FASM= fasm KPACK = kpack -CFLAGS = -I../include +CFLAGS = -I../include -I../../../../../../contrib/sdk/sources/SDL-1.2.2_newlib/include LDFLAGS = -nostdlib -L../../bin/lib ../../bin/lib/crt0.o BIN= stdio_test.kex \ @@ -21,9 +21,10 @@ clayer/libimg.kex \ clayer/dialog.kex \ clayer/msgbox.kex \ clayer/boxlib.kex \ -thread_work.kex +thread_work.kex \ +sdltest.kex -LIBS= -ltcc -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj +LIBS= -lSDL -ltcc -lsound -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj all: $(BIN) diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh index 23e0b039bb..a452e4ff34 100644 --- a/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh +++ b/programs/develop/ktcc/trunk/libc.obj/samples/build_all.sh @@ -17,3 +17,4 @@ cp /kolibrios/develop/tcc/samples/clayer/logo.png /tmp0/1/tcc_samples/logo.png /kolibrios/develop/tcc/tcc clayer/msgbox.c -o /tmp0/1/tcc_samples/msgbox -ltcc -lmsgbox -lc.obj /kolibrios/develop/tcc/tcc clayer/rasterworks.c -o /tmp0/1/tcc_samples/rasterworks -ltcc -lrasterworks -lc.obj /kolibrios/develop/tcc/tcc thread_work.c -o /tmp0/1/tcc_samples/thread_work -ltcc -lc.obj +/kolibrios/develop/tcc/tcc -I/kolibrios/develop/tcc/include/SDL sdltest.c -o /tmp0/1/tcc_samples/sdltest -lSDL -lsound -ltcc -lc.obj diff --git a/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c b/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c new file mode 100755 index 0000000000..c66e601a7c --- /dev/null +++ b/programs/develop/ktcc/trunk/libc.obj/samples/sdltest.c @@ -0,0 +1,79 @@ +#include "SDL.h" +#include + +#define WIDTH 640 +#define HEIGHT 480 +#define BPP 4 +#define DEPTH 32 + +void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b) +{ + Uint32 *pixmem32; + Uint32 colour; + + colour = SDL_MapRGB( screen->format, r, g, b ); + + pixmem32 = (Uint32*) screen->pixels + y + x; + *pixmem32 = colour; +} + + +void DrawScreen(SDL_Surface* screen, int h) +{ + int x, y, ytimesw; + + if(SDL_MUSTLOCK(screen)) + { + if(SDL_LockSurface(screen) < 0) return; + } + + for(y = 0; y < screen->h; y++ ) + { + ytimesw = y*screen->pitch/BPP; + for( x = 0; x < screen->w; x++ ) + { + setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h); + } + } + if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); + + SDL_Flip(screen); +} + + +int main(int argc, char* argv[]) +{ + SDL_Surface *screen; + SDL_Event event; + + int keypress = 0; + int h=0; + + if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; + + if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE))) + { + SDL_Quit(); + return 1; + } + + while(!keypress) + { + DrawScreen(screen,h++); + while(SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + keypress = 1; + break; + case SDL_KEYDOWN: + keypress = 1; + break; + } + } + } + + SDL_Quit(); + return 0; +} diff --git a/programs/develop/ktcc/trunk/libc.obj/source/stdio/vprintf.c b/programs/develop/ktcc/trunk/libc.obj/source/stdio/vprintf.c index 8299b669d8..9af1f74600 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/stdio/vprintf.c +++ b/programs/develop/ktcc/trunk/libc.obj/source/stdio/vprintf.c @@ -10,6 +10,11 @@ #include //#include "format_print.h" +int vsprintf (char * s, const char * format, va_list arg) +{ + return vsnprintf(s, STDIO_MAX_MEM, format, arg); +} + int vprintf ( const char * format, va_list arg ) { int len = 0; diff --git a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt index e5baef06bf..43a24dc64f 100644 --- a/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt +++ b/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt @@ -38,6 +38,7 @@ tmpnam vfscanf vprintf vfscanf +vsprintf vsnprintf vsscanf ungetc