why doesnt it work :(((

This commit is contained in:
PoliEcho 2025-08-12 22:52:56 +02:00
parent c8a714e684
commit 1b0f312834
9 changed files with 78 additions and 25 deletions

View File

@ -16,7 +16,7 @@
DevicePathLib|edk2/MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiBootServicesTableLib|edk2/MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
UefiRuntimeServicesTableLib|edk2/MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
DebugLib|edk2/MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
DebugLib|edk2/MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
PrintLib|edk2/MdePkg/Library/BasePrintLib/BasePrintLib.inf
PcdLib|edk2/MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
RegisterFilterLib|edk2/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNull.inf

View File

@ -24,7 +24,8 @@ RegisterFilterLib|edk2/MdePkg/Library/RegisterFilterLibNull/RegisterFilterLibNul
StackCheckLib|edk2/MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
TimerLib|edk2/MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
IoLib|edk2/MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
RngLib|edk2/MdePkg/Library/BaseRngLib/BaseRngLib.inf
SerialPortLib|edk2/MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
[Components]

View File

@ -1,5 +1,9 @@
#!/bin/bash
export PACKAGES_PATH=$PWD:$PWD/edk2
build -a X64 -t GCC5 -p UEFI_fireworks.dsc
if [ "$1" == "debug" ]; then
build -a X64 -t GCC5 -p UEFI_fireworks.dsc -b DEBUG
else
build -a X64 -t GCC5 -p UEFI_fireworks.dsc
fi
mkdir -p build
cp edk2/Build/UEFI_fireworks/DEBUG_GCC5/X64/UEFI_fireworks.efi build/

View File

@ -25,9 +25,11 @@
DebugLib
PrintLib
TimerLib
RngLib
SerialPortLib
[Protocols]
gEfiRngProtocolGuid
[Guids]
[Pcd]

View File

@ -1,3 +1,4 @@
#include "Library/UefiApplicationEntryPoint.h"
#include "ProcessorBind.h"
#include "drawing.h"
#include "global.h"
@ -5,7 +6,10 @@
#include "types.h"
#include <Base.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/RngLib.h>
#include <Library/SerialPortLib.h>
#include <Library/TimerLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
@ -38,20 +42,58 @@ EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE imgHandle,
clear_screen(GraphicsOutput);
struct firework_instance firework = {500,
500,
100,
{0, 0, 0},
{COLOR_FROM_HEX(0xff0000),
COLOR_FROM_HEX(0x00ff00),
COLOR_FROM_HEX(0x0000ff)},
0};
while (step_firework(&firework)) {
MicroSecondDelay(50000);
}
LIST_ENTRY firework_list;
InitializeListHead(&firework_list);
if (SerialPortInitialize() == RETURN_SUCCESS) {
SERIAL_PRINT("Serial initialized");
} else {
Print(L"Failed to initialize Serial");
Exit(RETURN_DEVICE_ERROR);
}
while (TRUE) {
UINT32 random;
GetRandomNumber32(&random);
if (random % 6 == 0) {
// spawn new firework
firework_node *new_firework_node =
AllocateZeroPool(sizeof(firework_node));
if (new_firework_node == NULL) {
return EFI_OUT_OF_RESOURCES;
}
new_firework_node->Signature = FIREWORK_NODE_SIGNATURE;
GetRandomNumber32(&random);
new_firework_node->Firework.max_r =
random % 501; // so max number can be 500
for (UINT8 i = 0; i < ARRAY_SIZE(new_firework_node->Firework.color);
i++) {
GetRandomNumber32(
(UINT32 *)&new_firework_node->Firework.color[i]); // belive
new_firework_node->Firework.r[i] = 0;
}
new_firework_node->Firework.cleanup_r = 0;
GetRandomNumber32(&random);
new_firework_node->Firework.x =
random % GraphicsOutput->Mode->Info->HorizontalResolution + 1;
GetRandomNumber32(&random);
new_firework_node->Firework.y =
random % GraphicsOutput->Mode->Info->VerticalResolution + 1;
InsertTailList(&firework_list, &new_firework_node->Link);
}
firework_node *current_node = NULL;
for (LIST_ENTRY *node = GetFirstNode(&firework_list);
!IsNodeAtEnd(&firework_list, node);
node = GetNextNode(&firework_list, node)) {
// Print(L"Processing firework\r\n");
current_node = CR(node, firework_node, Link, FIREWORK_NODE_SIGNATURE);
if (!step_firework(&current_node->Firework)) {
RemoveEntryList(node); // remove if firework ended
}
}
MicroSecondDelay(500000);
}
return EFI_SUCCESS;
}

View File

@ -11,12 +11,10 @@ void draw_pixel(const UINT32 x, const UINT32 y,
const EFI_GRAPHICS_OUTPUT_BLT_PIXEL pixel) {
UINTN framebuffer_offset =
(y * GraphicsOutput->Mode->Info->PixelsPerScanLine) + x;
if (framebuffer_offset >= GraphicsOutput->Mode->FrameBufferSize) {
Print(L"Atepted out of bounds write to framebuffer\r\n");
Exit(RETURN_WARN_BUFFER_TOO_SMALL);
if (framebuffer_offset <
GraphicsOutput->Mode->FrameBufferSize) { // ignre when out of bounds
framebuffer[framebuffer_offset] = pixel;
}
framebuffer[framebuffer_offset] = pixel;
}
// uses Mid-Point Circle Drawing Algorithm
@ -87,7 +85,7 @@ void clear_screen() {
BOOLEAN step_firework(struct firework_instance *firework) {
for (UINT8 i = 0; i < ARRAY_SIZE(firework->r); i++) {
if (firework->r[i] < firework->max_r) {
if (i == 0 || (firework->max_r / 3) * i <= firework->r[i - 1]) {
if (i == 0 || (firework->max_r / 3.5) * i <= firework->r[i - 1]) {
draw_circle(firework->x, firework->y, firework->r[i],
firework->color[i]);
firework->r[i]++;

View File

@ -4,3 +4,5 @@
.Green = ((hex) >> 8) & 0xFF, \
.Red = ((hex) >> 16) & 0xFF, \
.Reserved = 0}
#define SERIAL_PRINT(str) SerialPortWrite((UINT8 *)str, AsciiStrLen(str))

View File

@ -11,9 +11,9 @@ struct firework_instance {
UINT16 cleanup_r;
};
struct firework_node {
typedef struct {
UINTN Signature;
struct firework_instance Firework;
LIST_ENTRY Link;
};
} firework_node;
#define FIREWORK_NODE_SIGNATURE SIGNATURE_32('f', 'w', 'r', 'k')

View File

@ -6,5 +6,9 @@ qemu-system-x86_64 \
-machine type=q35,accel=kvm \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
-drive if=pflash,format=raw,file=./my_ovmf_vars.fd \
-hda fat:rw:$(dirname build/UEFI_fireworks.efi)
-hda fat:rw:$(dirname build/UEFI_fireworks.efi) \
-smp 4 \
-s \
-serial mon:stdio
rm ./my_ovmf_vars.fd