mirror of
https://github.com/pkivolowitz/asm_book.git
synced 2026-06-21 01:56:47 +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
|
||||
bl StepAll
|
||||
bl RenderAll
|
||||
mov w0, 1
|
||||
mov w1, 1
|
||||
bl Move
|
||||
ldr x0, =nl
|
||||
bl printf
|
||||
bl Delay
|
||||
b 10b
|
||||
|
||||
|
|
@ -82,19 +87,89 @@ Erase: stp x20, x30, [sp, -16]!
|
|||
ldp x20, x30, [sp], 16
|
||||
ret
|
||||
|
||||
/* Address of flake to render comes to us in x0.
|
||||
*/
|
||||
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
|
||||
|
||||
/* Iterate through the storm rendering each particle
|
||||
*/
|
||||
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
|
||||
|
||||
Delay:
|
||||
str x30, [sp, -16]!
|
||||
mov x0, 1
|
||||
lsl x0, x0, 17
|
||||
bl usleep
|
||||
ldr x30, [sp], 16
|
||||
ret
|
||||
|
||||
/* Address of flake to step arrives in x0.
|
||||
*/
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
InitializeStorm:
|
||||
|
|
@ -122,17 +197,17 @@ ResetFlake:
|
|||
bl rand
|
||||
mov x1, MAX_COLUMN
|
||||
bl mod
|
||||
add w1, w1, 1
|
||||
str w1, [x20, 4]
|
||||
add w0, w0, 1
|
||||
str w0, [x20, 4]
|
||||
|
||||
// Initialize Line --- -(1 <= random value <= 48)
|
||||
|
||||
bl rand
|
||||
mov x1, MAX_LINE_X2
|
||||
bl mod
|
||||
add w1, w1, 1
|
||||
neg w1, w1
|
||||
str w1, [x20]
|
||||
add w0, w0, 1
|
||||
neg w0, w0
|
||||
str w0, [x20]
|
||||
|
||||
ldp x20, x30, [sp], 16
|
||||
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
|
||||
ret
|
||||
|
||||
|
||||
.data
|
||||
bad_malloc: .asciz "Allocation of flakes has failed"
|
||||
move_str: .asciz "\033[%d;%dH"
|
||||
erase_str: .asciz "\033[2J"
|
||||
char_str: .asciz "*"
|
||||
nl: .asciz "\n"
|
||||
|
||||
.section Flake
|
||||
.struct 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue