diff --git a/_includes/samples/sdl2/main.c b/_includes/samples/sdl2/main.c
index e705689..fc7b6f4 100644
--- a/_includes/samples/sdl2/main.c
+++ b/_includes/samples/sdl2/main.c
@@ -20,17 +20,22 @@ int main(int argc, char *argv[])
int running = 1;
SDL_Event event;
while (running) {
+ // Process input
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
+ // End the loop if the programs is being closed
running = 0;
break;
case SDL_CONTROLLERDEVICEADDED:
+ // Connect a controller when it is connected
SDL_GameControllerOpen(event.cdevice.which);
break;
case SDL_CONTROLLERBUTTONDOWN:
- if(event.cbutton.button == SDL_CONTROLLER_BUTTON_START)
+ if(event.cbutton.button == SDL_CONTROLLER_BUTTON_START) {
+ // Close the program if start is pressed
running = 0;
+ }
break;
}
}
@@ -46,6 +51,9 @@ int main(int argc, char *argv[])
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderPresent(renderer);
}
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
return 0;
}
\ No newline at end of file
diff --git a/_includes/samples/shape/main.c b/_includes/samples/shape/main.c
index e5f3687..9660340 100644
--- a/_includes/samples/shape/main.c
+++ b/_includes/samples/shape/main.c
@@ -12,6 +12,25 @@ PSP_MAIN_THREAD_ATTR(THREAD_ATTR_VFPU | THREAD_ATTR_USER);
char list[0x20000] __attribute__((aligned(64)));
+int exit_callback(int arg1, int arg2, void *common) {
+ sceKernelExitGame();
+ return 0;
+}
+
+int callback_thread(SceSize args, void *argp) {
+ int cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
+ sceKernelRegisterExitCallback(cbid);
+ sceKernelSleepThreadCB();
+ return 0;
+}
+
+int setup_callbacks(void) {
+ int thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);
+ if(thid >= 0)
+ sceKernelStartThread(thid, 0, 0);
+ return thid;
+}
+
void initGu(){
sceGuInit();
@@ -67,8 +86,8 @@ void drawRect(float x, float y, float w, float h) {
vertices[0].x = x;
vertices[0].y = y;
- vertices[1].x = y + w;
- vertices[1].y = x + h;
+ vertices[1].x = x + w;
+ vertices[1].y = y + h;
sceGuColor(0xFF0000FF); // Red, colors are ABGR
sceGuDrawArray(GU_SPRITES, GU_TEXTURE_16BIT | GU_VERTEX_16BIT | GU_TRANSFORM_2D, 2, 0, vertices);
@@ -76,12 +95,17 @@ void drawRect(float x, float y, float w, float h) {
int main() {
+ // Make exiting with the home button possible
+ setup_callbacks();
+
+ // Setup the library used for rendering
initGu();
+
int running = 1;
while(running){
startFrame();
- drawRect(32, 32, 64, 64);
+ drawRect(216, 96, 34, 64);
endFrame();
}
diff --git a/basic_programs.md b/basic_programs.md
index 88e6216..2dfdfca 100644
--- a/basic_programs.md
+++ b/basic_programs.md
@@ -12,7 +12,7 @@ nav_order: 3
![](images/hello.png)
-> This is a simple Hello World program for the PSP.
+This is a simple Hello World program for the PSP.
Click on view source below to see the code and how to build it.
@@ -50,7 +50,7 @@ This will result in an EBOOT.PBP file in the build directory. Put it in a direct
![](images/shape.png)
-> This is a simple square drawn on the PSP. It uses the native libgu library.
+This is a simple square drawn on the PSP. It uses the native libgu library.
Click on view source below to see the code and how to build it.
@@ -89,7 +89,7 @@ More libgu examples can be found SDL2 is a library which handles system specific things like input, audio and window management for you. It can also be used to render shapes and images, just like the native libgu. This will be slower, but will result in code that can be run more easily on multiple platforms.
+Despite this example adding an option to close by pressing the start button, the code is much shorter. It can even be build for Linux without any further modifications.
Click on view source below for the to see the code and how to build it.
@@ -212,7 +214,7 @@ More documentation on SDL can be found