aboutsummaryrefslogtreecommitdiff
path: root/game/starfield.asm
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-11 20:57:55 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-11 20:57:55 +0100
commit681ba9adf948ebdc909b08979c76251053af7a9e (patch)
tree36ed6a598c808df7237f8bf65383e878f0fd3266 /game/starfield.asm
parent871062265cdfb565ba64834cfd85f079f387317e (diff)
downloadtr8vm-681ba9adf948ebdc909b08979c76251053af7a9e.tar.gz
tr8vm-681ba9adf948ebdc909b08979c76251053af7a9e.zip
Add starfield effect
Diffstat (limited to 'game/starfield.asm')
-rw-r--r--game/starfield.asm70
1 files changed, 70 insertions, 0 deletions
diff --git a/game/starfield.asm b/game/starfield.asm
new file mode 100644
index 0000000..e8b8ed1
--- /dev/null
+++ b/game/starfield.asm
@@ -0,0 +1,70 @@
+;
+; Simple starfield effect
+;
+stars_update:
+ ld x, <stars
+ ld a, >stars
+
+stars_update_loop:
+ ld y, [a : x]
+ inc x
+ bo
+ inc a
+ ld b, [a : x]
+ ; is the end of list?
+ cmp b, 0xff
+ bz
+ ret
+
+ push a
+ push x
+
+ ; erase old
+ ld x, 0
+ ld [b : y], x
+ ld x, [sp + 0]
+
+ ; update address
+ inc x
+ bo
+ inc a
+ push x
+ ld x, [a : x]
+stars_update_addr:
+ add y, 128
+ bo
+ inc b
+ cmp b, 0xfe
+ bnz
+ jmp stars_no_wrap
+ cmp y, 0x80
+ bc
+ ld b, 0xbf
+stars_no_wrap:
+ dec x
+ bnz
+ jmp stars_update_addr
+ pop x
+
+ ; draw new: color
+ inc x
+ bo
+ inc a
+ ld x, [a : x]
+ ld [b : y], x
+
+ pop x
+ pop a
+
+ ; save new address
+ ld [a : x], b
+ dec x
+ bo
+ dec a
+ ld [a : x], y
+
+ ; next star
+ add x, 4
+ bo
+ inc a
+ jmp stars_update_loop