Upd. Makefile and CI, add keypad reading to example, improve lib internals

This commit is contained in:
2023-11-06 23:23:22 +01:00
parent 2026d954ee
commit 014f3eabab
11 changed files with 246 additions and 151 deletions

View File

@ -10,11 +10,13 @@ typedef struct MainArgs {
MultiSpacc_SurfaceConfig *WindowConfig;
MultiSpacc_Window *Window;
MultiSpacc_Surface *Screen;
MultiSpacc_Surface *Background;
MultiSpacc_Surface *Foreground;
MultiSpacc_Surface *TilesImg;
} MainArgs;
/*{pal:"nes",layout:"nes"}*/
const char PALETTE[32] = {
const char palette[32] = {
0x03, // screen
0x11,0x30,0x27,0x00, // background 0
0x1c,0x20,0x2c,0x00, // background 1
@ -33,6 +35,7 @@ bool MainLoop( void *args )
MainArgs *margs = (MainArgs*)args;
MultiSpacc_Sprite( 0, margs->spriteX, margs->spriteY, 1, margs->TilesImg, margs->Screen );
// ... this must go on Foreground
//scroll(spriteX,0);
margs->spriteX += margs->accelX;
@ -42,21 +45,25 @@ bool MainLoop( void *args )
{
margs->spriteX = 0;
}
if( margs->spriteY == 0 || margs->spriteY == ( margs->WindowConfig->Height - 8 ) )
{
margs->accelY *= -1;
}
// check keys
// if ESC pressed exit
// ...
/* TODO: listen for OS terminate signal */
if( MultiSpacc_CheckKey( MultiSpacc_Key_Pause, 0 ) )
{
return false;
}
if( !MultiSpacc_WaitUpdateDisplay( margs->Window, &nextTick ) )
{
MultiSpacc_PrintDebug("[E] Error Updating Screen.\n");
return false;
};
}
// apply Background and then Foreground on Screen
// ...
return true;
}
@ -73,12 +80,11 @@ int main( int argc, char *argv[] )
WindowConfig.Width = 320;
WindowConfig.Height = 240;
WindowConfig.Bits = 16;
memcpy( WindowConfig.Palette, PALETTE, 32 );
memcpy( WindowConfig.Palette, palette, 32 );
//WindowConfig.Frequency = 50;
margs.Window = MultiSpacc_SetWindow( &WindowConfig );
margs.Screen = MultiSpacc_GetWindowSurface( margs.Window );
if( margs.Screen == NULL )
{
MultiSpacc_PrintDebug("[E] Error Initializing Video System.\n");
@ -91,7 +97,13 @@ int main( int argc, char *argv[] )
// Bitmap font borrowed from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
// Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
margs.TilesImg = MultiSpacc_LoadImage( "CHARS.png", margs.Screen, NULL );
if( margs.TilesImg == NULL )
{
return -1;
}
MultiSpacc_PrintText( "Hello, World!", margs.Screen, &WindowConfig, 2, 2, margs.TilesImg );
// ... this must print on Background
return MultiSpacc_SetMainLoop( MainLoop, &margs );
}