Skip to content

Commit 8b1fb7e

Browse files
committed
Fix imports and work on drawing
1 parent 1605fe3 commit 8b1fb7e

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

examples/box.asm

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@define TEXT_BUFFER 0xF800
12
@define SCREEN_WIDTH 80
23
@define SCREEN_HEIGHT 25
34
@define BOX_WIDTH (SCREEN_WIDTH - 2)
@@ -10,6 +11,7 @@
1011
@define WALL 0xBA
1112
@define DASH 0xCD
1213

14+
@org 0x0000
1315
jmp [_start]
1416

1517
/// math = ./math
@@ -23,8 +25,23 @@ _start:
2325
halt
2426

2527
draw_top:
26-
mv A, 1
28+
mv A, 1 ; A contains the X coordinate
29+
push A, 1, TL_CORNER ; x, y, character
30+
call [draw_character]
31+
halt
32+
mv B, (BOX_WIDTH - 2)
33+
.loop:
34+
inc A
35+
36+
push A, 1, DASH
37+
call [draw_character]
2738

39+
dec B
40+
jnz B, [.loop]
41+
42+
inc A
43+
push A, 1, TR_CORNER
44+
call [draw_character]
2845

2946
ret
3047

@@ -36,3 +53,16 @@ draw_left:
3653

3754
draw_right:
3855
ret
56+
57+
draw_character:
58+
pop C, B, A ; character, y, x
59+
push B, 0, SCREEN_WIDTH, 0
60+
call [mul16] ; get Y offset
61+
pop H, L
62+
63+
add16 H, L, (TEXT_BUFFER >> 8), (TEXT_BUFFER & 0xFF) ; Shift address to text-buffer space
64+
add16 H, L, 0, SCREEN_WIDTH ; add X to address
65+
66+
st C
67+
68+
ret

math/mul.asm

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ifndef MUL_ASM
2+
@define MUL_ASM
3+
4+
/// Multiplies the most recent numbers on the stack, pushing the result back to the stack
5+
mul:
6+
mv A, 0
7+
pop C
8+
pop B
9+
.loop:
10+
add A, C
11+
dec B
12+
jnz B, [.loop]
13+
push A
14+
ret
15+
16+
/// Multiples the top 16-bit integers on the stack, pushing the result back to the stack,
17+
/// with high at the top of the stack
18+
mul16:
19+
mv A, 0
20+
mv B, 0
21+
pop E ; H0
22+
pop F ; L0
23+
pop C ; H1
24+
pop D ; L1
25+
.loop:
26+
add16 A, B, E, F
27+
dec C, D
28+
mv H, C
29+
or H, D
30+
jnz H, [.loop]
31+
push B, A ; LO, HO
32+
33+
ret
34+
35+
@endif

src/assembler/macros.asm

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// All pre-built macros
22

33
@macro push {
4-
; push two registers
5-
(%r0:reg, %r1:reg) {
4+
; push two values
5+
(%r0:reg|imm, %r1:reg|imm) {
66
push %r0
77
push %r1
88
}
9-
; push three registers
10-
(%r0:reg, %r1:reg, %r2:reg) {
9+
; push three values
10+
(%r0:reg|imm, %r1:reg|imm, %r2:reg|imm) {
1111
push %r0
1212
push %r1, %r2
1313
}
14-
; push four registers
15-
(%r0:reg, %r1:reg, %r2:reg, %r3:reg) {
14+
; push four values
15+
(%r0:reg|imm, %r1:reg|imm, %r2:reg|imm, %r3:reg|imm) {
1616
push %r0
1717
push %r1, %r2, %r3
1818
}
19-
; push five registers
20-
(%r0:reg, %r1:reg, %r2:reg, %r3:reg, %r4:reg) {
19+
; push five values
20+
(%r0:reg|imm, %r1:reg|imm, %r2:reg|imm, %r3:reg|imm, %r4:reg|imm) {
2121
push %r0
2222
push %r1, %r2, %r3, %r4
2323
}
24-
; push six registers
25-
(%r0:reg, %r1:reg, %r2:reg, %r3:reg, %r4:reg, %r5:reg) {
24+
; push six values
25+
(%r0:reg|imm, %r1:reg|imm, %r2:reg|imm, %r3:reg|imm, %r4:reg|imm, %r5:reg|imm) {
2626
push %r0
2727
push %r1, %r2, %r3, %r4, %r5
2828
}

0 commit comments

Comments
 (0)