From 91001e09ba72ee0bd5dfba393879557b04f1fa2b Mon Sep 17 00:00:00 2001 From: PoliEcho Date: Sat, 16 Aug 2025 16:29:37 +0200 Subject: [PATCH] add rockets --- assets/rocket.bmp | Bin 1326 -> 1242 bytes build.sh | 1 + src/UEFI_fireworks/UefiMain.c | 20 +++++++++++-- src/UEFI_fireworks/drawing.c | 52 +++++++++++++++++++++++++++++++++- src/UEFI_fireworks/drawing.h | 4 ++- src/UEFI_fireworks/global.h | 4 ++- src/UEFI_fireworks/types.h | 7 +++++ 7 files changed, 82 insertions(+), 6 deletions(-) diff --git a/assets/rocket.bmp b/assets/rocket.bmp index 915cc45e4f51ffb014b3dd0436d29a72c761d770..e9c991a8cbf2083682b96eaf518b817b0267829a 100644 GIT binary patch literal 1242 zcmdVZJqiLb5Cz~7#KuOju@cnA%2Kwr_X1wV%Xli!VISWlYvL}TIwKx2mzX=unQaiw9@sye%FGFbo2@a-k|$O#yC;u+rE!bR$jtV>RL1uJlqq@K z{@E~7y=nyjWw=q-aHFzr-<=yN6B>1UAsJY=S72SUO^eE~XiaFOOki!DKm9)Z*y`Q+ zw<`1N?}Pf^hM%=zaHb+eDWU;x_p_`R@_Bc1-nm)3D5`Bw4p*14WV@9-Zw99~mM5Imby8d(?=f2CPj$ICfCfgFNo^(qb`AWkS zgTbJ>Frpo&k>NRj$mlqhzc-dewek)Ck+FrU#un0iIP!RQTPQNFP_-5Y9jn%ItZFuC zkr|TGxI&R}tlZ~M-;aIl=6lzf diff --git a/build.sh b/build.sh index b2c639c..57b6f1d 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/bash export PACKAGES_PATH=$PWD:$PWD/edk2 +magick assets/rocket_orig.bmp -type TrueColor -define bmp:format=bmp3 -compress None assets/rocket.bmp xxd -i assets/rocket.bmp > src/UEFI_fireworks/rocket.c if [ "$1" == "debug" ]; then build -a X64 -t GCC5 -p UEFI_fireworks.dsc -b DEBUG diff --git a/src/UEFI_fireworks/UefiMain.c b/src/UEFI_fireworks/UefiMain.c index cd98811..5205d7e 100644 --- a/src/UEFI_fireworks/UefiMain.c +++ b/src/UEFI_fireworks/UefiMain.c @@ -6,7 +6,6 @@ #include "rng.h" #include "time.h" #include "types.h" -#include <../MdeModulePkg/Include/Library/BmpSupportLib.h> #include #include #include @@ -55,6 +54,7 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)GraphicsOutput->Mode->FrameBufferBase; init_rng(); + init_rocket_blt(); if (SerialPortInitialize() == RETURN_SUCCESS) { SERIAL_PRINT("Serial initialized\n"); @@ -74,6 +74,13 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, milisleep(1); clear_screen(); + /*rocket_instance rocket = { + .x = GraphicsOutput->Mode->Info->HorizontalResolution / 2, + .y = GraphicsOutput->Mode->Info->VerticalResolution - 50}; + while (step_rocket(&rocket, 100)) { + milisleep(10); + }*/ + while (TRUE) { UINT8 random; fill_random_bytes(&random, sizeof(random)); @@ -88,7 +95,8 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, *new_firework_instence = create_firework(); for (UINT8 i = 0; i < ARRAY_SIZE(firework_array); i++) { - if (firework_array[i] == NULL || firework_array[i]->status != TRUE) { + if (firework_array[i] == NULL || + firework_array[i]->status == INACTIVE) { if (firework_array[i] != NULL) { FreePool(firework_array[i]); // free firework firework_array[i] = NULL; @@ -106,6 +114,10 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle, if (!step_firework(firework_array[i])) { firework_array[i]->status = INACTIVE; } + } else if (firework_array[i]->status == LAUNCHING) { + if (!step_rocket(&firework_array[i]->rocket, firework_array[i]->y)) { + firework_array[i]->status = ACTIVE; + } } else { FreePool(firework_array[i]); // free firework firework_array[i] = NULL; @@ -138,6 +150,8 @@ firework_instance create_firework() { firework.y = random % GraphicsOutput->Mode->Info->VerticalResolution / 2; // spawn only on upper half of the screen - firework.status = ACTIVE; // TODO set to LAUNCHING when implemented + firework.rocket.x = firework.x + rocket_asset.width / 2; + firework.rocket.y = GraphicsOutput->Mode->Info->VerticalResolution; + firework.status = LAUNCHING; // TODO set to LAUNCHING when implemented return firework; } \ No newline at end of file diff --git a/src/UEFI_fireworks/drawing.c b/src/UEFI_fireworks/drawing.c index 5565b50..8a154bc 100644 --- a/src/UEFI_fireworks/drawing.c +++ b/src/UEFI_fireworks/drawing.c @@ -1,8 +1,11 @@ #include "Base.h" +#include "Library/UefiLib.h" #include "ProcessorBind.h" +#include "bmp.h" #include "const.h" #include "global.h" #include "types.h" +#include <../MdeModulePkg/Include/Library/BmpSupportLib.h> #include #include @@ -104,5 +107,52 @@ BOOLEAN step_firework(firework_instance *firework) { } return TRUE; } +rocket_blt rocket_asset; -BOOLEAN step_rocket(rocket_instance *rocket) {} \ No newline at end of file +EFI_GRAPHICS_OUTPUT_BLT_PIXEL **mask_stack; +BOOLEAN **rocket_alfa_mask; + +void init_rocket_blt() { + EFI_STATUS Status = TranslateBmpToGopBlt( + assets_rocket_bmp, assets_rocket_bmp_len, &rocket_asset.blt, + &rocket_asset.blt_size, &rocket_asset.height, &rocket_asset.width); + if (EFI_ERROR(Status)) { + Print(L"Failed to load rocket asset: %r\n", Status); + Exit(Status); + } +} + +BOOLEAN step_rocket(rocket_instance *rocket, UINT32 max_y) { + GraphicsOutput->Blt(GraphicsOutput, + rocket_asset.blt, // BltBuffer + EfiBltBufferToVideo, // BltOperation + 0, // src X + 0, // src Y + rocket->x, // dst X + rocket->y, // dst Y + rocket_asset.width, rocket_asset.height, + 0 // unused Delta + ); + + if (rocket->y <= max_y) { + GraphicsOutput->Blt( + GraphicsOutput, + &night_sky, // BltBuffer + EfiBltVideoFill, // BltOperation + 0, // SourceX + 0, // SourceY + rocket->x, // DestinationX + rocket->y, // DestinationY + rocket_asset.width, // Width + rocket_asset.height + 1, // Height // remove trail from previous frame + 0 // Delta (not used for fill operations) + ); + return FALSE; + } else { + for (UINT8 i = 0; i < rocket_asset.width; i++) { + draw_pixel(rocket->x + i, rocket->y + rocket_asset.height, night_sky); + } + rocket->y--; + return TRUE; + } +} \ No newline at end of file diff --git a/src/UEFI_fireworks/drawing.h b/src/UEFI_fireworks/drawing.h index e23ba04..cbb8d5d 100644 --- a/src/UEFI_fireworks/drawing.h +++ b/src/UEFI_fireworks/drawing.h @@ -4,4 +4,6 @@ void draw_circle(int xc, int yc, int r, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL color); void clear_screen(); -BOOLEAN step_firework(firework_instance *firework); \ No newline at end of file +BOOLEAN step_firework(firework_instance *firework); +void init_rocket_blt(); +BOOLEAN step_rocket(rocket_instance *rocket, UINT32 max_y); \ No newline at end of file diff --git a/src/UEFI_fireworks/global.h b/src/UEFI_fireworks/global.h index 6e5a18d..68c9c0a 100644 --- a/src/UEFI_fireworks/global.h +++ b/src/UEFI_fireworks/global.h @@ -1,4 +1,6 @@ #pragma once +#include "types.h" #include extern EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; -extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL *framebuffer; \ No newline at end of file +extern EFI_GRAPHICS_OUTPUT_BLT_PIXEL *framebuffer; +extern rocket_blt rocket_asset; \ No newline at end of file diff --git a/src/UEFI_fireworks/types.h b/src/UEFI_fireworks/types.h index 478c0bf..eae1714 100644 --- a/src/UEFI_fireworks/types.h +++ b/src/UEFI_fireworks/types.h @@ -19,3 +19,10 @@ typedef struct { UINT16 cleanup_r; rocket_instance rocket; } firework_instance; + +typedef struct { + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *blt; + UINTN blt_size; + UINTN height; + UINTN width; +} rocket_blt; \ No newline at end of file