1 ; vim
: set filetype
=fasm foldmethod
=marker commentstring
=;
%s colorcolumn
=101 :
2 motorway
: namespace motorway
5 ; rsi
= offset of the way in the tile db
6 ; rdx
= node_p of the one provoking this very tile addition
, only used if initing required
10 define rbx_save rsp
+ 8 * 0
11 define r12_save rsp
+ 8 * 1
12 define r13_save rsp
+ 8 * 2
13 define motorway_of rsp
+ 8 * 3
15 and rsp
, not 0xf ; align stack for external calls
19 mov
[motorway_of
], rsi
21 bt qword
[tile_p
+ tile_t.flags
], tile_t.flags.motorways_inited
23 mov rdi
, qword
[tile_p
+ tile_t.features.motorways.
fd]
25 ; write the offset into the array of the ways in the tile motorways
------------------------
26 lea rsi
, [motorway_of
]
30 cmp rax
, linux.errno.last
31 jae err_write_motorway_of_failed
34 mov rbx
, qword
[rbx_save
]
37 ;
-------------------------------------------------------------------------------------------
38 ; we presume created directories
39 define node_p
r12 ;
r12 due te re-using tile init code
40 define path_finish
r13 ;
r13 due to re-using tile init code
42 ; build the path re-using tile init code
---------------------------------------------------
46 call tile.init.xy_to_str ; we share
r12 and r13
47 call tile.init.path_tile_dir_do ; we share
r12 and r13
48 mov
r12, qword
[r12_save
]
51 mov qword
[path_finish
], rax
53 mov dword
[path_finish
+ 8], eax ;
0 terminator added
54 mov
r13, qword
[r13_save
]
56 ; get
a fd ---------------------------------------------------------------------------------
58 mov rdi
, [rax
+ ctx_t.tile_db_dir.
fd]
59 lea rsi
, [tile.init.path
]
60 mov rdx
, linux.O_CREAT
or linux.O_TRUNC
or linux.O_WRONLY
61 mov
r10, 110110110b ; RW for all but umask
64 cmp rax
, linux.errno.last
65 jae err_motorways_openat_failed
66 mov
[tile_p
+ tile_t.features.motorways.
fd], rax
67 mov rdi
, rax ; caller expect the
fd being in rdi as well
69 or qword
[tile_p
+ tile_t.flags
], 1 shl tile_t.flags.motorways_inited
71 ;
-------------------------------------------------------------------------------------------
72 err_motorways_openat_failed
:
74 lea rsi
, [msg.err_motorways_openat_failed
]
76 lea rcx
, [tile.init.path
]
77 call qword
[libc.dprintf
]
80 err_write_motorway_of_failed
:
82 lea rsi
, [msg.err_write_motorway_of_failed
]
84 call qword
[libc.dprintf
]
92 end namespace ; motorways