Last active
July 26, 2018 13:55
-
-
Save AXKuhta/afe45b4145099adac446b3938c50cd25 to your computer and use it in GitHub Desktop.
Game of Life for R216K2A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Game of Life for R216K2A | |
; v1 | |
; There is no figures included in the source (Too painful to add them with dw) | |
; So you'll have to add them yourself with the PROP tool after compiling the code | |
; Base position: cell 256 (First cell of line 3 of RAM) | |
; R1 = Current cell position | |
; R2 = Target cell position | |
; R3 = Current line | |
; R4 = Used for counting nearby cells | |
CalculateFrame: | |
mov r1, 256 | |
mov r2, 320 ; Base position (256) + Line length (64) | |
mov r3, 0 | |
.CalculateLine: | |
.LineLoop: | |
xor r4, r4 | |
add r4, [r1 - 129] | |
add r4, [r1 - 128] | |
add r4, [r1 - 127] | |
add r4, [r1 - 1] | |
add r4, [r1 + 1] | |
add r4, [r1 + 127] | |
add r4, [r1 + 128] | |
add r4, [r1 + 129] | |
cmp r4, 2 | |
jne .NotTwoCells | |
cmp [r1], 1 | |
jne .CellIsDead | |
jmp .CellIsAlive | |
.NotTwoCells: | |
cmp r4, 3 | |
jne .CellIsDead | |
.CellIsAlive: | |
mov [r1 + 64], 1 | |
jmp .EvaluateOut | |
.CellIsDead: | |
mov [r1 + 64], 0 | |
.EvaluateOut: | |
add r1, 1 | |
cmp r1, r2 | |
jne .LineLoop | |
add r1, 64 ; Set base position to the next line | |
add r2, 128 ; And set the target position to the (Next line + line length) | |
add r3, 1 ; Add 1 to line count | |
cmp r3, 11 ; Check if current line is 12 (Counting from 0) | |
jne .CalculateLine | |
; WriteBack | |
; R1 = Current cell position | |
; R2 = Target cell position | |
; R3 = Current line | |
; R4 = ""Copying buffer"" | |
mov r1, 320 | |
mov r2, 384 | |
mov r3, 0 | |
WriteBack: | |
.LineLoop: | |
mov r4, [r1] | |
mov [r1 - 64], r4 | |
add r1, 1 | |
cmp r1, r2 | |
jne .LineLoop | |
add r1, 64 ; Set base position to the next line | |
add r2, 128 ; And set the target position to the (Next line + line length) | |
add r3, 1 ; Add 1 to line count | |
cmp r3, 11 ; Check if current line is 12 (Counting from 0) | |
jne WriteBack | |
jmp CalculateFrame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment