aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmicroshmup/build.sh2
-rw-r--r--microshmup/microshmup_core.S29
-rw-r--r--microshmup/microshmup_data.S24
-rw-r--r--microshmup/microshmup_main_sdl.S (renamed from microshmup/microshmup.S)106
-rw-r--r--microshmup/microshmup_render.S50
5 files changed, 109 insertions, 102 deletions
diff --git a/microshmup/build.sh b/microshmup/build.sh
index e12ed0b..0c76f6c 100755
--- a/microshmup/build.sh
+++ b/microshmup/build.sh
@@ -1,3 +1,3 @@
#!/bin/sh
mkdir -p bin
-cc -o bin/microshmup microshmup.S $(pkg-config --libs sdl3)
+cc -o bin/microshmup microshmup_main_sdl.S $(pkg-config --libs sdl3)
diff --git a/microshmup/microshmup_core.S b/microshmup/microshmup_core.S
new file mode 100644
index 0000000..cbb8bfb
--- /dev/null
+++ b/microshmup/microshmup_core.S
@@ -0,0 +1,29 @@
+// ================================================================================================
+// Macros
+// ================================================================================================
+
+#ifdef __APPLE__
+# define LBL(name) L ## name
+# define SYM(name) _##name
+# define SECTION_BSS .section __DATA,__bss
+# define SECTION_RODATA .section __TEXT,__const
+# define SECTION_TEXT .section __TEXT,__text
+#else
+# define LBL(name) .L ## name
+# define SYM(name) name
+# define SECTION_BSS .section .bss
+# define SECTION_RODATA .section .rodata
+# define SECTION_TEXT .section .text
+#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
+
+
diff --git a/microshmup/microshmup_data.S b/microshmup/microshmup_data.S
new file mode 100644
index 0000000..3a8728e
--- /dev/null
+++ b/microshmup/microshmup_data.S
@@ -0,0 +1,24 @@
+// ================================================================================================
+// Constants
+// ================================================================================================
+
+.equ VP_W, 800
+.equ VP_H, 600
+
+// ================================================================================================
+// Read-only data
+// ================================================================================================
+SECTION_RODATA
+
+s_microshmup: .asciz "microshmup"
+s_microshmup_error: .asciz "microshmup - error"
+s_software: .asciz "software"
+
+// ================================================================================================
+// Mutable data
+// ================================================================================================
+SECTION_BSS
+.p2align 3
+
+g_fbufmap: .zero 8 // frame buffer data
+g_fstride: .zero 4 // frame buffer stride
diff --git a/microshmup/microshmup.S b/microshmup/microshmup_main_sdl.S
index 69dc68b..0ad7a59 100644
--- a/microshmup/microshmup.S
+++ b/microshmup/microshmup_main_sdl.S
@@ -1,115 +1,20 @@
-// ================================================================================================
-// Constants
-// ================================================================================================
-
-.equ VP_W, 800
-.equ VP_H, 600
-
-// ================================================================================================
-// Read-only data
-// ================================================================================================
-#ifdef __APPLE__
- .section __TEXT,__const
-#else
- .section .rodata
-#endif
-
-s_microshmup: .asciz "microshmup"
-s_microshmup_error: .asciz "microshmup - error"
-s_software: .asciz "software"
+#include "microshmup_core.S"
+#include "microshmup_data.S"
+#include "microshmup_render.S"
// ================================================================================================
// Mutable data
// ================================================================================================
-#ifdef __APPLE__
- .section __DATA,__bss
-#else
- .section .bss
-#endif
- .p2align 3
+SECTION_BSS
g_evt: .zero 128 // SDL_Event
g_rnd: .zero 8 // SDL_Renderer *
g_wnd: .zero 8 // SDL_Window *
-g_fbufmap: .zero 8 // frame buffer data
-g_fstride: .zero 4 // frame buffer stride
-
-// ================================================================================================
-// Code
-// ================================================================================================
-
-#ifdef __APPLE__
- .section __TEXT,__text
-#else
- .section .text
-#endif
-
-#ifdef __APPLE__
-# define LBL(name) L ## name
-# define SYM(name) _##name
-#else
-# define LBL(name) .L ## name
-# 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
-
// ================================================================================================
// Code
// ================================================================================================
-
-// draw solid color rect
-// w0: x (top-left)
-// w1: y (top-left)
-// w2: width
-// w3: height
-// w4: color
-SYM(draw_rect):
- stp x29, x30, [sp, #-16]!
- mov x29, sp
-
- LOADADDR x9, g_fbufmap
- ldr x9, [x9]
-
- LOADADDR x10, g_fstride
- ldr w10, [x10]
-
- // x offset
- mov w11, #4
- mul w11, w11, w0
- add x9, x9, w11, uxtw
-
- // y offset
- mul w11, w10, w1
- add x9, x9, w11, uxtw
-
- mov w12, #0 // y cursor
-LBL(draw_rect_y):
- mov w11, #0 // x cursor
- mov x13, x9 // row
-LBL(draw_rect_x):
- str w4, [x13]
- add x13, x13, #4
- add w11, w11, #1
- cmp w11, w2
- b.lt LBL(draw_rect_x)
-
- add x9, x9, w10, uxtw
- add w12, w12, #1
- cmp w12, w3
- b.lt LBL(draw_rect_y)
-
- ldp x29, x30, [sp], #16
- ret
+SECTION_TEXT
.global SYM(main)
// entry point
@@ -227,4 +132,3 @@ LBL(end):
ldp x19, x20, [sp, #16]
ldp x29, x30, [sp], #48
ret
-
diff --git a/microshmup/microshmup_render.S b/microshmup/microshmup_render.S
new file mode 100644
index 0000000..76af92d
--- /dev/null
+++ b/microshmup/microshmup_render.S
@@ -0,0 +1,50 @@
+// ================================================================================================
+// Code
+// ================================================================================================
+SECTION_TEXT
+
+// draw solid color rect
+// w0: x (top-left)
+// w1: y (top-left)
+// w2: width
+// w3: height
+// w4: color
+SYM(draw_rect):
+ stp x29, x30, [sp, #-16]!
+ mov x29, sp
+
+ LOADADDR x9, g_fbufmap
+ ldr x9, [x9]
+
+ LOADADDR x10, g_fstride
+ ldr w10, [x10]
+
+ // x offset
+ mov w11, #4
+ mul w11, w11, w0
+ add x9, x9, w11, uxtw
+
+ // y offset
+ mul w11, w10, w1
+ add x9, x9, w11, uxtw
+
+ mov w12, #0 // y cursor
+LBL(draw_rect_y):
+ mov w11, #0 // x cursor
+ mov x13, x9 // row
+LBL(draw_rect_x):
+ str w4, [x13]
+ add x13, x13, #4
+ add w11, w11, #1
+ cmp w11, w2
+ b.lt LBL(draw_rect_x)
+
+ add x9, x9, w10, uxtw
+ add w12, w12, #1
+ cmp w12, w3
+ b.lt LBL(draw_rect_y)
+
+ ldp x29, x30, [sp], #16
+ ret
+
+