New features; First Hello World example with Makefile

This commit is contained in:
2023-07-20 00:51:16 +02:00
parent 293bf55b7d
commit 280db9a8d5
13 changed files with 163 additions and 20 deletions

View File

@ -0,0 +1,44 @@
AppName = $(notdir ${CURDIR})
Sources = $(wildcard *.c ../../LibMultiSpacc/*.c)
CFlags = -O2
CC = gcc $(Defines)
ifndef Target
Target = PC
endif
ifdef Target
ifeq ($(Target), PC)
ExeSuffix = .run
Defines = -DTarget_PC
MultiSpacc_Target = SDL20
endif
endif
ifeq ($(MultiSpacc_Target), SDL12)
Defines += -DMultiSpacc_Target_SDL12
LdFlags += -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
Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL20/*.c)
endif
Objects = $(Sources:.c=.o)
All: $(AppName)
$(AppName): $(Objects)
$(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix)
Run: All
./$(AppName)$(ExeSuffix)
Clean:
find -L . -name "*.o" -type f -delete
rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix)
all: All
run: Run
clean: Clean

View File

@ -0,0 +1,46 @@
#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_Surface *Screen = MultiSpacc_GetWindowSurface( Window );
if( Screen == NULL )
{
printf("[E] Error initializing Video System.\n");
return -1;
};
MultiSpacc_SetAppTitle( Window, AppName );
// Bitmap font borrowed from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
// Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
MultiSpacc_Surface *TilesImg = MultiSpacc_LoadImage( "Tiles.png", Screen, NULL );
const char Text[] = "Hello, World!";
for(int i = 0; i < sizeof(Text); i++){
SDL_Rect Offset = {
.x = (8 * i) + (ScreenWidth / sizeof(Text)),
.y = ScreenHeight / 3,
};
SDL_Rect Clip = {
.x = 8 * ((int)Text[i] % 16),
.y = 8 * ((int)Text[i] / 16),
.w = 8,
.h = 8,
};
SDL_BlitSurface( TilesImg, &Clip, Screen, &Offset );
};
if( MultiSpacc_UpdateWindowSurface( Window ) != 0 ) {
printf("[E] Error updating Screen.\n");
};
MultiSpacc_Sleep( 3000 );
return 0;
};

Binary file not shown.

View File

@ -0,0 +1 @@
include ../Common.mk

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB