mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-22 19:26:46 +08:00
working
This commit is contained in:
parent
e394b9c34d
commit
6dccefe395
2 changed files with 87 additions and 6 deletions
5
projects/snow/.vscode/settings.json
vendored
Normal file
5
projects/snow/.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"estorm"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -49,6 +49,11 @@ main: stp x29, x30, [sp, -16]!
|
||||||
10: bl Erase
|
10: bl Erase
|
||||||
bl StepAll
|
bl StepAll
|
||||||
bl RenderAll
|
bl RenderAll
|
||||||
|
mov w0, 1
|
||||||
|
mov w1, 1
|
||||||
|
bl Move
|
||||||
|
ldr x0, =nl
|
||||||
|
bl printf
|
||||||
bl Delay
|
bl Delay
|
||||||
b 10b
|
b 10b
|
||||||
|
|
||||||
|
|
@ -82,19 +87,89 @@ Erase: stp x20, x30, [sp, -16]!
|
||||||
ldp x20, x30, [sp], 16
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* Address of flake to render comes to us in x0.
|
||||||
|
*/
|
||||||
RenderOne:
|
RenderOne:
|
||||||
|
str x30, [sp, -16]!
|
||||||
|
ldr w1, [x0]
|
||||||
|
ldr w2, [x0, 4]
|
||||||
|
|
||||||
|
// Ensure 1 <= w1 <= MAX_LINE
|
||||||
|
mov w3, 1
|
||||||
|
mov w4, MAX_LINE
|
||||||
|
mov w5, MAX_COLUMN
|
||||||
|
cmp w3, w1
|
||||||
|
bgt 99f
|
||||||
|
cmp w4, w1
|
||||||
|
blt 99f
|
||||||
|
|
||||||
|
// Ensure 1 <= w2 <= MAX_COLUMN
|
||||||
|
cmp w3, w2
|
||||||
|
bgt 99f
|
||||||
|
cmp w5, w2
|
||||||
|
blt 99f
|
||||||
|
|
||||||
|
ldr x0, =move_str
|
||||||
|
bl printf
|
||||||
|
ldr x0, =char_str
|
||||||
|
bl printf
|
||||||
|
99: ldr x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* Iterate through the storm rendering each particle
|
||||||
|
*/
|
||||||
RenderAll:
|
RenderAll:
|
||||||
|
stp x20, x30, [sp, -16]!
|
||||||
|
mov x20, storm
|
||||||
|
1: mov x0, x20
|
||||||
|
bl RenderOne
|
||||||
|
add x20, x20, Flake.size
|
||||||
|
cmp estorm, x20
|
||||||
|
bgt 1b
|
||||||
|
|
||||||
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
Delay:
|
Delay:
|
||||||
|
str x30, [sp, -16]!
|
||||||
|
mov x0, 1
|
||||||
|
lsl x0, x0, 17
|
||||||
|
bl usleep
|
||||||
|
ldr x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
/* Address of flake to step arrives in x0.
|
||||||
|
*/
|
||||||
StepOne:
|
StepOne:
|
||||||
|
stp x20, x30, [sp, -16]!
|
||||||
|
mov x20, x0
|
||||||
|
ldr w1, [x0]
|
||||||
|
add w1, w1, 1
|
||||||
|
str w1, [x0]
|
||||||
|
mov w2, MAX_LINE
|
||||||
|
cmp w2, w1
|
||||||
|
bge 1f
|
||||||
|
bl ResetFlake
|
||||||
|
1: bl rand
|
||||||
|
mov w1, 3
|
||||||
|
bl mod
|
||||||
|
sub x0, x0, 1
|
||||||
|
ldr w1, [x20, 4]
|
||||||
|
add w0, w0, w1
|
||||||
|
str w0, [x20, 4]
|
||||||
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
StepAll:
|
StepAll:
|
||||||
|
stp x20, x30, [sp, -16]!
|
||||||
|
mov x20, storm
|
||||||
|
1: mov x0, x20
|
||||||
|
bl StepOne
|
||||||
|
add x20, x20, Flake.size
|
||||||
|
cmp estorm, x20
|
||||||
|
bgt 1b
|
||||||
|
|
||||||
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
||||||
InitializeStorm:
|
InitializeStorm:
|
||||||
|
|
@ -122,17 +197,17 @@ ResetFlake:
|
||||||
bl rand
|
bl rand
|
||||||
mov x1, MAX_COLUMN
|
mov x1, MAX_COLUMN
|
||||||
bl mod
|
bl mod
|
||||||
add w1, w1, 1
|
add w0, w0, 1
|
||||||
str w1, [x20, 4]
|
str w0, [x20, 4]
|
||||||
|
|
||||||
// Initialize Line --- -(1 <= random value <= 48)
|
// Initialize Line --- -(1 <= random value <= 48)
|
||||||
|
|
||||||
bl rand
|
bl rand
|
||||||
mov x1, MAX_LINE_X2
|
mov x1, MAX_LINE_X2
|
||||||
bl mod
|
bl mod
|
||||||
add w1, w1, 1
|
add w0, w0, 1
|
||||||
neg w1, w1
|
neg w0, w0
|
||||||
str w1, [x20]
|
str w0, [x20]
|
||||||
|
|
||||||
ldp x20, x30, [sp], 16
|
ldp x20, x30, [sp], 16
|
||||||
ret
|
ret
|
||||||
|
|
@ -156,11 +231,12 @@ mod: sdiv x2, x0, x1 // x2 gets a // b
|
||||||
msub x0, x2, x1, x0 // x0 gets a - a // b * b
|
msub x0, x2, x1, x0 // x0 gets a - a // b * b
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
.data
|
.data
|
||||||
bad_malloc: .asciz "Allocation of flakes has failed"
|
bad_malloc: .asciz "Allocation of flakes has failed"
|
||||||
move_str: .asciz "\033[%d;%dH"
|
move_str: .asciz "\033[%d;%dH"
|
||||||
erase_str: .asciz "\033[2J"
|
erase_str: .asciz "\033[2J"
|
||||||
|
char_str: .asciz "*"
|
||||||
|
nl: .asciz "\n"
|
||||||
|
|
||||||
.section Flake
|
.section Flake
|
||||||
.struct 0
|
.struct 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue