150 lines
1.9 KiB
ArmAsm
150 lines
1.9 KiB
ArmAsm
|
%include "utils.s"
|
||
|
|
||
|
global _start
|
||
|
[bits 32]
|
||
|
[section .text]
|
||
|
|
||
|
%define FILENAME "input"
|
||
|
;%define FILENAME "input_test"
|
||
|
|
||
|
;%define PRINT
|
||
|
|
||
|
_start:
|
||
|
mov esi, file
|
||
|
mov edi, array+1024*512+512 ; like, the middle idk
|
||
|
mov byte [edi], 1 ; filled!
|
||
|
|
||
|
proc_line:
|
||
|
cmp esi, file.over
|
||
|
jae .done
|
||
|
lodsb ; RDLU
|
||
|
%ifdef PRINT
|
||
|
call print_char
|
||
|
call space
|
||
|
%endif
|
||
|
mov ebx, eax
|
||
|
inc esi ; space
|
||
|
call dec_parse ; count
|
||
|
%ifdef PRINT
|
||
|
call print_dec
|
||
|
call newline
|
||
|
%endif
|
||
|
; skip to next line
|
||
|
add esi, 10
|
||
|
; put in array
|
||
|
cmp bl, 'R'
|
||
|
mov ecx, 1
|
||
|
cmove edx, ecx
|
||
|
cmp bl, 'L'
|
||
|
mov ecx, -1
|
||
|
cmove edx, ecx
|
||
|
cmp bl, 'D'
|
||
|
mov ecx, 1024
|
||
|
cmove edx, ecx
|
||
|
cmp bl, 'U'
|
||
|
mov ecx, -1024
|
||
|
cmove edx, ecx
|
||
|
mov ecx, eax
|
||
|
.draw:
|
||
|
add edi, edx
|
||
|
mov byte [edi], 1
|
||
|
loop .draw
|
||
|
jmp proc_line
|
||
|
.done:
|
||
|
|
||
|
%ifdef PRINT
|
||
|
print_array:
|
||
|
call newline
|
||
|
mov esi, array
|
||
|
xor ecx, ecx
|
||
|
.inner:
|
||
|
mov bl, '.'
|
||
|
lodsb
|
||
|
test al, al
|
||
|
mov dl, '#'
|
||
|
cmovnz bx, dx
|
||
|
mov al, bl
|
||
|
call print_char
|
||
|
inc ecx
|
||
|
cmp ecx, 1024*1024
|
||
|
jae .done
|
||
|
mov ebx, ecx
|
||
|
and ebx, 1023
|
||
|
jnz .inner
|
||
|
call newline
|
||
|
jmp .inner
|
||
|
.done:
|
||
|
call newline
|
||
|
%endif
|
||
|
|
||
|
xor ecx, ecx ; x = 0
|
||
|
xor ebx, ebx ; y = 0
|
||
|
mov ebp, 1024*1024 ; count
|
||
|
call flood_fill
|
||
|
jmp flood_done
|
||
|
|
||
|
flood_fill:
|
||
|
mov eax, ebx
|
||
|
shl eax, 10
|
||
|
cmp byte [array+eax+ecx], 0
|
||
|
je .zero
|
||
|
ret
|
||
|
.zero:
|
||
|
dec ebp
|
||
|
mov byte [array+eax+ecx], 1
|
||
|
sub esp, 8
|
||
|
mov [esp+4], ecx
|
||
|
mov [esp+0], ebx
|
||
|
.t_right:
|
||
|
cmp ecx, 1023
|
||
|
je .t_left
|
||
|
inc ecx
|
||
|
call flood_fill
|
||
|
mov ecx, [esp+4]
|
||
|
.t_left:
|
||
|
cmp ecx, 0
|
||
|
je .t_down
|
||
|
dec ecx
|
||
|
call flood_fill
|
||
|
mov ecx, [esp+4]
|
||
|
.t_down:
|
||
|
cmp ebx, 1023
|
||
|
je .t_up
|
||
|
inc ebx
|
||
|
call flood_fill
|
||
|
mov ebx, [esp+0]
|
||
|
.t_up:
|
||
|
cmp ebx, 0
|
||
|
je .ret
|
||
|
dec ebx
|
||
|
call flood_fill
|
||
|
mov ebx, [esp+0]
|
||
|
.ret:
|
||
|
add esp, 8
|
||
|
ret
|
||
|
|
||
|
flood_done:
|
||
|
mov [final_value], ebp
|
||
|
|
||
|
game_over:
|
||
|
mov eax, [final_value]
|
||
|
call print_dec
|
||
|
call newline
|
||
|
jmp exit
|
||
|
|
||
|
PANIC:
|
||
|
p_string panic_str
|
||
|
jmp exit
|
||
|
|
||
|
[section .data]
|
||
|
final_value: dd 0
|
||
|
file: incbin FILENAME
|
||
|
.over:
|
||
|
|
||
|
[section .bss]
|
||
|
array: resb 1024*1024
|
||
|
|
||
|
[section .rodata]
|
||
|
panic_str: db 10, "AAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!11111111", 10
|
||
|
.over:
|