aboutsummaryrefslogtreecommitdiff
path: root/example.asm
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-01 13:50:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-01 13:58:09 +0100
commit8998bd04c94da08dc49ab62007da5604d53895c3 (patch)
tree43a588f7a372ce17d035536a56fd71691fa6a73f /example.asm
downloadtr8vm-8998bd04c94da08dc49ab62007da5604d53895c3.tar.gz
tr8vm-8998bd04c94da08dc49ab62007da5604d53895c3.zip
Initial import
Diffstat (limited to 'example.asm')
-rw-r--r--example.asm125
1 files changed, 125 insertions, 0 deletions
diff --git a/example.asm b/example.asm
new file mode 100644
index 0000000..6d4521e
--- /dev/null
+++ b/example.asm
@@ -0,0 +1,125 @@
+;
+; example.asm for TR8
+;
+.org 0
+
+; ; copy 16K from 0x0000 to 0xbf00
+; ;
+; start:
+; ld a, 0
+; ld b, 0xbf
+; ld x, 0
+; ld y, 0x40
+; loop:
+; push y
+; ld y, [a : x]
+; ld [b : x], y
+; pop y
+; inc x
+; bno
+; jmp loop
+; inc a
+; inc b
+; dec y
+; bnz
+; jmp loop
+;
+ ld b, 15
+ call fill
+
+ halt
+;
+; ; void copy(void *dst, void *src, uint16_t size)
+; ; size = 0x1000
+; ; src = 0
+; ; dst 0xbf00
+; ld a, 0x10
+; push a
+; ld a, 0
+; push a
+; push a
+; push a
+; ld a, 0xbf
+; push a
+; ld a, 0
+; push a
+; call copy
+; pop a
+; pop a
+; pop a
+; pop a
+; pop a
+; pop a
+; halt
+
+ ; fill frame-buffer with a color in reg b
+fill:
+ ld a, 0xbf
+ ld x, 0
+ ld y, 0x40
+fill_loop:
+ ld [a : x], b
+ inc x
+ bno
+ jmp fill_loop
+ inc a
+ dec y
+ bnz
+ jmp fill_loop
+ ret
+
+ ; void copy(void *dst, void *src, uint16_t size)
+ ;
+ ; using C calling convention with the stack
+ ; not used, but return value in a (8-bit), a: x (16-bit)
+; copy:
+; ld x, [sp + 6]
+; ld a, [sp + 7] ; size a:x
+;
+; ; local variable
+; push a
+; push x
+;
+; ld y, [sp + 4]
+; ld b, [sp + 5] ; dst b:y
+; ld x, [sp + 6]
+; ld a, [sp + 7] ; src a:x
+; copy_loop:
+; ; copy byte from a:x to b:y
+; push x
+; ld x, [a : x]
+; ld [b : y], x
+; pop x
+;
+; ; inc a:x
+; inc x
+; bo
+; inc a
+;
+; ; inc b:y
+; inc y
+; bo
+; inc b
+;
+; ; dec local var size
+; push a
+; push x
+; ld x, [sp + 2]
+; ld a, [sp + 3]
+; dec x
+; bo
+; dec a
+; ld [sp + 2], x
+; ld [sp + 3], a
+; or x, a
+; pop x
+; pop a
+;
+; bnz
+; jmp copy_loop
+;
+; pop x
+; pop x ; free local var
+; ret
+;
+;