diff --git a/LibMultiSpacc/Examples/Common.mk b/LibMultiSpacc/Examples/Common.mk index c74d49c..a943dd9 100644 --- a/LibMultiSpacc/Examples/Common.mk +++ b/LibMultiSpacc/Examples/Common.mk @@ -1,44 +1,60 @@ AppName = $(notdir ${CURDIR}) Sources = $(wildcard *.c ../../LibMultiSpacc/*.c) -CFlags = -O2 -CC = gcc $(Defines) +CFlags = -O2 -Wpedantic -Werror ifndef Target - Target = PC + ifeq ($(shell uname --operating-system), Msys) + Target = WindowsPC + else + Target = LinuxPC + endif endif ifdef Target - ifeq ($(Target), PC) + ifeq ($(Target), LinuxPC) ExeSuffix = .run - Defines = -DTarget_PC + Defines += -DTarget_LinuxPC MultiSpacc_Target = SDL20 + else ifeq ($(Target), WindowsPC) + ExeSuffix = .exe + Defines += -DTarget_WindowsPC + MultiSpacc_Target = SDL20 + else ifeq ($(Target), NDS) + Defines += -DTarget_NDS + MultiSpacc_Target = NDS endif endif ifeq ($(MultiSpacc_Target), SDL12) Defines += -DMultiSpacc_Target_SDL12 - LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf + CFlags += $(shell sdl-config --cflags) + LdFlags += $(shell sdl-config --libs) -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL12/*.c) else ifeq ($(MultiSpacc_Target), SDL20) Defines += -DMultiSpacc_Target_SDL20 - LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf + CFlags += $(shell sdl2-config --cflags) + LdFlags += $(shell sdl2-config --libs) -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL20/*.c) +else ifeq ($(MultiSpacc_Target), NDS) + #include $(DEVKITARM)/ds_rules + Defines += -DMultiSpacc_Target_NDS + CFlags += -I$(DEVKITPRO)/libnds/include -DARM9 + Sources += $(wildcard ../../LibMultiSpacc/NDS/*.c) + ToolsPrefix = $(DEVKITARM)/bin/arm-none-eabi- endif +CC = $(ToolsPrefix)gcc $(CFlags) $(Defines) Objects = $(Sources:.c=.o) -All: $(AppName) +All all: $(AppName) $(AppName): $(Objects) - $(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix) + $(CC) $^ $(LdFlags) -o $(AppName)$(ExeSuffix) -Run: All +Run run: All ./$(AppName)$(ExeSuffix) -Clean: +Clean clean: find -L . -name "*.o" -type f -delete + find -L ../../LibMultiSpacc -name "*.o" -type f -delete rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix) - -all: All -run: Run -clean: Clean diff --git a/LibMultiSpacc/Examples/HelloWorld/HelloWorld b/LibMultiSpacc/Examples/HelloWorld/HelloWorld new file mode 100644 index 0000000..24c2a6d Binary files /dev/null and b/LibMultiSpacc/Examples/HelloWorld/HelloWorld differ diff --git a/LibMultiSpacc/Examples/HelloWorld/HelloWorld.c b/LibMultiSpacc/Examples/HelloWorld/HelloWorld.c index d536fad..bfccabe 100644 --- a/LibMultiSpacc/Examples/HelloWorld/HelloWorld.c +++ b/LibMultiSpacc/Examples/HelloWorld/HelloWorld.c @@ -1,18 +1,16 @@ #include "../../LibMultiSpacc/MultiSpacc.h" #define AppName "Hello World" -#define ScreenWidth 320 -#define ScreenHeight 240 -#define ScreenBits 16 int main( int argc, char *args[] ) { - MultiSpacc_Window *Window = MultiSpacc_SetWindow( ScreenWidth, ScreenHeight, ScreenBits, 0 ); + MultiSpacc_SurfaceConfig WindowConfig = { .Width = 320, .Height = 240, .Bits = 16 }; + MultiSpacc_Window *Window = MultiSpacc_SetWindow( WindowConfig ); MultiSpacc_Surface *Screen = MultiSpacc_GetWindowSurface( Window ); if( Screen == NULL ) { - printf("[E] Error initializing Video System.\n"); + printf("[E] Error Initializing Video System.\n"); return -1; }; @@ -22,28 +20,14 @@ int main( int argc, char *args[] ) // Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT) MultiSpacc_Surface *TilesImg = MultiSpacc_LoadImage( "Tiles.png", Screen, NULL ); - /*char Text[] = "Hello, World!"; - for(int i = 0; i < sizeof( Text ); i++){ - MultiSpacc_Rect Offset = { - .x = (8 * i) + (ScreenWidth / sizeof( Text )), - .y = ScreenHeight / 3, - }; - MultiSpacc_Rect Clip = { - .x = 8 * (Text[i] % 16), - .y = 8 * (Text[i] / 16), - .w = 8, - .h = 8, - }; - SDL_BlitSurface( TilesImg, &Clip, Screen, &Offset ); - };*/ - MultiSpacc_PrintString( "Hello, World!", Screen, ScreenWidth, ScreenHeight, 4, 4, TilesImg ); + MultiSpacc_PrintText( "Hello, World!", Screen, WindowConfig.Width, WindowConfig.Height, 4, 4, TilesImg ); if( MultiSpacc_UpdateWindowSurface( Window ) != 0 ) { - printf("[E] Error updating Screen.\n"); + printf("[E] Error Updating Screen.\n"); return -1; }; MultiSpacc_Sleep( 3000 ); return 0; -}; +} diff --git a/LibMultiSpacc/LibMultiSpacc/MultiSpacc.h b/LibMultiSpacc/LibMultiSpacc/MultiSpacc.h index 3729343..f4e40f7 100644 --- a/LibMultiSpacc/LibMultiSpacc/MultiSpacc.h +++ b/LibMultiSpacc/LibMultiSpacc/MultiSpacc.h @@ -1,6 +1,8 @@ #pragma once #include #include +#include +#include #ifdef MultiSpacc_Target_SDL12 #include "SDL12/SDL.h" @@ -12,7 +14,18 @@ #include "SDLCom/SDL.h" #endif -MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ); +#ifdef MultiSpacc_Target_NDS + #include "NDS/NDS.h" +#endif + +typedef struct MultiSpacc_SurfaceConfig { + int Width; + int Height; + int Bits; + Uint32 Flags; +} MultiSpacc_SurfaceConfig; + +MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ); MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ); void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ); @@ -23,4 +36,4 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) int MultiSpacc_PollEvent( MultiSpacc_Event *Event ); -void MultiSpacc_PrintString( char Text[], MultiSpacc_Surface *Surface, int ScreenWidth, int ScreenHeight, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ); // WIP +void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, int ScreenWidth, int ScreenHeight, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ); // WIP diff --git a/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c b/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c new file mode 100644 index 0000000..4f59263 --- /dev/null +++ b/LibMultiSpacc/LibMultiSpacc/NDS/NDS.c @@ -0,0 +1,25 @@ +#include "../MultiSpacc.h" + +MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) +{ + MultiSpacc_Window *wip; + return wip; +} + +MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) +{ + MultiSpacc_Surface *wip; + return wip; +} + +void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ){} + +int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ) +{ + return 0; +} + +void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, int ScreenWidth, int ScreenHeight, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) +{ + +} \ No newline at end of file diff --git a/LibMultiSpacc/LibMultiSpacc/NDS/NDS.h b/LibMultiSpacc/LibMultiSpacc/NDS/NDS.h new file mode 100644 index 0000000..1bbb809 --- /dev/null +++ b/LibMultiSpacc/LibMultiSpacc/NDS/NDS.h @@ -0,0 +1,19 @@ +#pragma once + +#ifndef MultiSpacc_Target_NDS + #define MultiSpacc_Target_NDS +#endif + +#include "../MultiSpacc.h" +#include + +#define Uint32 int32 +#define MultiSpacc_Window PrintConsole +#define MultiSpacc_Surface PrintConsole +#define MultiSpacc_Sleep {} + +typedef struct MultiSpacc_Event { + int Keys; +} MultiSpacc_Event; + +int MultiSpacc_UpdateWindowSurface( MultiSpacc_Window *Window ); diff --git a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c index a2eaefd..12c9820 100644 --- a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c +++ b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.c @@ -5,8 +5,8 @@ #include "SDL/SDL_ttf.h" #include "../SDLCom/SDL.h" -MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) { - return SDL_SetVideoMode( Width, Height, Bits, Flags ); +MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { + return SDL_SetVideoMode( WindowConfig.Width, WindowConfig.Height, WindowConfig.Bits, WindowConfig.Flags ); } MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { return Window; @@ -24,4 +24,4 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) return SDL_SetColorKey( Surface, SDL_SRCCOLORKEY, Key ); else return SDL_SetColorKey( Surface, 0, Key ); -}; +} diff --git a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h index 0f15a7f..0fe8865 100644 --- a/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h +++ b/LibMultiSpacc/LibMultiSpacc/SDL12/SDL.h @@ -5,15 +5,15 @@ #endif #include "../MultiSpacc.h" -#include "SDL/SDL.h" -#include "SDL/SDL_image.h" -#include "SDL/SDL_mixer.h" -#include "SDL/SDL_ttf.h" +#include +#include +#include +#include #define MultiSpacc_Window SDL_Surface #define MultiSpacc_UpdateWindowSurface SDL_Flip typedef struct MultiSpacc_Event { - Uint32 Type; - SDLKey Key; + Uint32 Type; + SDLKey Key; } MultiSpacc_Event; diff --git a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c index 13d14e6..294b7a8 100644 --- a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c +++ b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.c @@ -5,8 +5,8 @@ #include "SDL2/SDL_ttf.h" #include "../SDLCom/SDL.h" -MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) { - return SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Width, Height, Flags); +MultiSpacc_Window *MultiSpacc_SetWindow( MultiSpacc_SurfaceConfig WindowConfig ) { + return SDL_CreateWindow( NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WindowConfig.Width, WindowConfig.Height, WindowConfig.Flags ); } MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) { return SDL_GetWindowSurface( Window ); @@ -24,4 +24,4 @@ int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) return SDL_SetColorKey( Surface, SDL_TRUE, Key ); else return SDL_SetColorKey( Surface, SDL_FALSE, Key ); -}; +} diff --git a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h index 342db05..898b52b 100644 --- a/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h +++ b/LibMultiSpacc/LibMultiSpacc/SDL20/SDL.h @@ -5,10 +5,10 @@ #endif #include "../MultiSpacc.h" -#include "SDL2/SDL.h" -#include "SDL2/SDL_image.h" -#include "SDL2/SDL_mixer.h" -#include "SDL2/SDL_ttf.h" +#include +#include +#include +#include #define MultiSpacc_Window SDL_Window #define MultiSpacc_UpdateWindowSurface SDL_UpdateWindowSurface diff --git a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c b/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c index 45e5749..72a5207 100644 --- a/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c +++ b/LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c @@ -9,7 +9,7 @@ int MultiSpacc_PollEvent( MultiSpacc_Event *Event ) .Key = FromEvent.key.keysym.sym, }; return Result; -}; +} MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey ) { @@ -30,12 +30,11 @@ MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *S }; }; return Final; -}; +} -void MultiSpacc_PrintString( char Text[], MultiSpacc_Surface *Surface, int ScreenWidth, int ScreenHeight, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) +void MultiSpacc_PrintText( char Text[], MultiSpacc_Surface *Surface, int ScreenWidth, int ScreenHeight, int x, int y, MultiSpacc_Surface *Tiles /*, int FontSize, int Color */ ) { - for(int i = 0; i < strlen( Text ); i++) - //while(*(Text++)) + for( int i = 0; i < strlen( Text ); i++ ) { MultiSpacc_Rect Offset = { .x = (x * 8) + (8 * i), @@ -49,4 +48,4 @@ void MultiSpacc_PrintString( char Text[], MultiSpacc_Surface *Surface, int Scree }; SDL_BlitSurface( Tiles, &Clip, Surface, &Offset ); }; -}; +}