diff options
| author | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-11 20:16:08 -0500 |
|---|---|---|
| committer | Hunter Kvalevog <hunter@kvog.sh> | 2026-10-11 20:16:08 -0500 |
| commit | 96de86203074cb5edfaa93db2d1b41d47e95759e (patch) | |
| tree | 58ea96c63484d61694d0dc7151fca354097bb20f /microshmup | |
| parent | 95d514d2a9b63d55169b6065641efc14d76350cb (diff) | |
microshmup: initial commitmicroshmup
Diffstat (limited to 'microshmup')
| -rwxr-xr-x | microshmup/build.sh | 3 | ||||
| -rw-r--r-- | microshmup/microshmup.S | 89 |
2 files changed, 92 insertions, 0 deletions
diff --git a/microshmup/build.sh b/microshmup/build.sh new file mode 100755 index 0000000..11677a5 --- /dev/null +++ b/microshmup/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +mkdir -p bin +clang -o bin/microshmup microshmup.S $(pkg-config --libs sdl3) diff --git a/microshmup/microshmup.S b/microshmup/microshmup.S new file mode 100644 index 0000000..fbeb37a --- /dev/null +++ b/microshmup/microshmup.S @@ -0,0 +1,89 @@ +// ================================================================================================ +// Read-only data +// ================================================================================================ +#ifdef __APPLE__ + .section __TEXT,__const +#else + .section .rodata +#endif + +s_microshmup: .asciz "microshmup" +s_microshmup_error: .asciz "microshmup - error" + +// ================================================================================================ +// Mutable data +// ================================================================================================ +#ifdef __APPLE__ + .section __DATA,__bss +#else + .section .bss +#endif + .p2align 3 + +g_rnd: .zero 8 // SDL_Renderer * +g_wnd: .zero 8 // SDL_Window * + +// ================================================================================================ +// Code +// ================================================================================================ + +#ifdef __APPLE__ + .section __TEXT,__text +#else + .section .text +#endif + +#ifdef __APPLE__ +# define SYM(name) _##name +#else +# define SYM(name) name +#endif + +.macro LOADADDR reg, sym +#ifdef __APPLE__ + adrp \reg, \sym\()@PAGE + add \reg, \reg, \sym\()@PAGEOFF +#else + adrp \reg, \sym + add \reg, \reg, :lo12:\sym +#endif +.endm + +.global SYM(main) + +SYM(main): + stp x29, x30, [sp, #-16]! + mov x29, sp + + mov w0, #0x30 // SDL_INIT_VIDEO | SDL_INIT_AUDIO + bl SYM(SDL_Init) + tst w0, #0xFF + b.eq sdl_fail + + LOADADDR x0, s_microshmup + mov w1, #800 + mov w2, #600 + mov x3, #0 + LOADADDR x4, g_wnd + LOADADDR x5, g_rnd + bl SYM(SDL_CreateWindowAndRenderer) + tst w0, #0xFF + b.eq sdl_fail + + mov w0, #0 + ldp x29, x30, [sp], #16 + ret +sdl_fail: + bl SYM(SDL_GetError) + + mov x2, x0 + mov w0, #0x10 + LOADADDR x1, s_microshmup_error + LOADADDR x9, g_wnd + ldr x3, [x9] + bl SYM(SDL_ShowSimpleMessageBox) + + mov w0, #1 + ldp x29, x30, [sp], #16 + ret + |