-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.asm
98 lines (81 loc) · 1.3 KB
/
map.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;
;; Title: Wanna be sokoban
;; Copyright: 2013 Damian Ziemba
;; Authors: Damian Ziemba <[email protected]>
;; License: GPL
;;
[bits 64]
global loadMap
extern fopen
extern fgets
extern fprintf
extern fclose
extern feof
extern printf
section .text
; *filename is passed in the RDI
loadMap:
mov RBP, RSP
mov RSI, openMode
call fopen
and RAX, RAX
jz openError
mov RCX, 16
sub RSP, 32
mov [fd], RAX
loop:
lea RAX, [RBP-32]
mov RDI, RAX
mov RSI, 32
mov RDX, [fd]
push RCX
call fgets
call feof
pop RCX
and RAX, RAX
jnz eofError
; cos tu zjebalem... tylko co hm
mov RBX, 16
loop2:
mov RAX, RBX
mul RCX
sub RAX, 32
mov R8, RBP
sub R8, RAX
push RDI
push RSI
mov RDI, fmt
movzx RSI, byte R8
push RCX
push RBX
call printf
pop RBX
pop RCX
pop RSI
pop RDI
dec RBX
and RBX, RBX
jnz loop2
loop loop
mov RAX, 1
add RSP, 32
ret
openError:
;mov RDX, RDI
mov RDI, openErrorFmt
call printf
mov RAX, 0
ret
eofError:
mov RDI, 2
mov RSI, eofErrorFmt
call fprintf
mov RAX, 0
ret
section .data
map: times 16*16 dd -1
openErrorFmt: db "Error: couldn't open map file", 0xA, 0
eofErrorFmt: db "Error: unexpected end of file", 0xA, 0
fd: db 0
fmt: db "Current char: %c", 0xA, 0
openMode: db "r", 0