|
1 | 1 | .proc XOPEN_ROUTINE |
2 | 2 |
|
| 3 | +; $ed31 |
3 | 4 | .out .sprintf("|MODIFY:RES:XOPEN_ROUTINE") |
4 | 5 | .out .sprintf("|MODIFY:RESB:XOPEN_ROUTINE") |
5 | 6 | .out .sprintf("|MODIFY:TR5:XOPEN_ROUTINE") |
6 | | -.out .sprintf("|MODIFY:TR7:XOPEN_ROUTINE") |
| 7 | +.out .sprintf("|MODIFY:TR6:XOPEN_ROUTINE (used by XMALLOC)") |
| 8 | +.out .sprintf("|MODIFY:TR7:XOPEN_ROUTINE (used by XMALLOC)") |
7 | 9 | .out .sprintf("|MODIFY:XOPEN_SAVE:XOPEN_ROUTINE") |
8 | 10 | .out .sprintf("|MODIFY:XOPEN_FLAGS:XOPEN_ROUTINE") |
9 | 11 | .out .sprintf("|MODIFY:XOPEN_RES_SAVE:XOPEN_ROUTINE") |
|
57 | 59 | ; O_CREAT | Yes | open and return FD |
58 | 60 |
|
59 | 61 | sta RES |
60 | | - stx RES+1 |
| 62 | + stx RES + 1 |
61 | 63 | ; Save ptr |
62 | 64 | sta XOPEN_RES_SAVE |
63 | 65 | stx XOPEN_RES_SAVE + 1 |
|
67 | 69 |
|
68 | 70 | ; |
69 | 71 | ; Close current file if we already open a file |
70 | | - lda kernel_process+kernel_process_struct::kernel_fd_opened ; if there is already a file open on ch376 if value <> $FF, if it's equal to $ff, there is no file opened |
| 72 | + lda kernel_process + kernel_process_struct::kernel_fd_opened ; if there is already a file open on ch376 if value <> $FF, if it's equal to $ff, there is no file opened |
71 | 73 | cmp #$FF |
72 | 74 | bne @open_new_file |
73 | 75 |
|
74 | 76 | ; close it |
75 | 77 | jsr _ch376_file_close |
76 | 78 |
|
77 | 79 | @open_new_file: |
78 | | -.ifdef WITH_DEBUG2 |
79 | | - jsr kdebug_save |
80 | | - ldy XOPEN_RES_SAVE + 1 |
81 | | - ldx #XDEBUG_XOPEN_ENTER |
82 | | - jsr xdebug_print_with_ay_string |
83 | | - jsr kdebug_restore |
84 | | -.endif |
85 | 80 |
|
86 | 81 | lda #EOK |
87 | 82 | sta KERNEL_ERRNO |
|
97 | 92 | ldx #$FF |
98 | 93 | txa |
99 | 94 | rts |
100 | | -@L1: |
101 | | - |
102 | 95 |
|
| 96 | +@L1: |
103 | 97 | ldy #$00 |
104 | 98 | lda (RES),y |
105 | 99 | ; |
|
126 | 120 | rts |
127 | 121 |
|
128 | 122 | @not_null_2: |
| 123 | + |
129 | 124 | sta KERNEL_XOPEN_PTR1 |
130 | | - sty KERNEL_XOPEN_PTR1+1 |
| 125 | + sty KERNEL_XOPEN_PTR1 + 1 |
131 | 126 | ; now concat |
132 | 127 | ; reach the end of string in the pointer |
133 | 128 | ldy #_KERNEL_FILE::f_path |
134 | 129 | @L3: |
135 | 130 | lda (KERNEL_XOPEN_PTR1),y |
136 | 131 | beq @end_of_string_found |
137 | 132 | iny |
138 | | - cpy #KERNEL_MAX_PATH_LENGTH+_KERNEL_FILE::f_path |
| 133 | + cpy #KERNEL_MAX_PATH_LENGTH + _KERNEL_FILE::f_path |
139 | 134 | bne @L3 |
140 | 135 |
|
141 | 136 | ; at this step, we cannot detect the end of string : BOF, return null |
142 | 137 | jmp @exit_open_with_null |
143 | 138 |
|
144 | 139 | @end_of_string_found: |
145 | 140 | ; This solution avoid to compute pointer and to create another zp address |
146 | | - cpy #_KERNEL_FILE::f_path+$01 ; is it slash "/",0 ? |
| 141 | + cpy #_KERNEL_FILE::f_path + $01 ; is it slash "/",0 ? |
147 | 142 | beq @don_t_add_slash ; yes |
148 | 143 | ; it's a relative path and we are still in a folder (except /) |
149 | 144 | ; add slash then |
|
172 | 167 | ; Be careful BOF can occurs if |
173 | 168 | iny |
174 | 169 | sty RES |
175 | | - cpy #KERNEL_MAX_PATH_LENGTH+_KERNEL_FILE::f_path |
| 170 | + cpy #KERNEL_MAX_PATH_LENGTH + _KERNEL_FILE::f_path |
176 | 171 |
|
177 | 172 | bne @L4 |
178 | 173 | ; Bof return NULL |
|
189 | 184 | ; Pass arg to createfile_pointer |
190 | 185 |
|
191 | 186 | lda RES |
192 | | - ldy RES+1 |
| 187 | + ldy RES + 1 |
193 | 188 | ; and XOPEN_FLAGS too at this step |
194 | 189 |
|
195 | 190 | jsr _create_file_pointer |
|
203 | 198 |
|
204 | 199 | @not_null_1: |
205 | 200 | sta KERNEL_XOPEN_PTR1 |
206 | | - sty KERNEL_XOPEN_PTR1+1 |
| 201 | + sty KERNEL_XOPEN_PTR1 + 1 |
207 | 202 |
|
208 | 203 | @open_from_device: |
209 | 204 | ; Reset flag to say that end of string is reached |
|
218 | 213 |
|
219 | 214 | jsr send_0_to_ch376_and_open |
220 | 215 |
|
221 | | - ldy #_KERNEL_FILE::f_path+1 ; skip / |
| 216 | + ldy #_KERNEL_FILE::f_path + 1 ; skip / |
222 | 217 |
|
223 | 218 | @next_filename: |
224 | 219 | lda #CH376_SET_FILE_NAME ;$2F |
|
256 | 251 | iny |
257 | 252 | lda (KERNEL_XOPEN_PTR1),y |
258 | 253 | bne @next_filename |
259 | | - cpy #_KERNEL_FILE::f_path+1 |
| 254 | + cpy #_KERNEL_FILE::f_path + 1 |
260 | 255 | beq @open_and_register_fp |
261 | 256 |
|
262 | 257 | bne @next_filename |
|
282 | 277 | beq @exit_open_with_null ; yes, return NULL |
283 | 278 |
|
284 | 279 |
|
| 280 | + ; save KERNEL_XOPEN_PTR1 (modifued by open_full_filename) |
| 281 | + lda KERNEL_XOPEN_PTR1 |
| 282 | + sta TR6 |
| 283 | + lda KERNEL_XOPEN_PTR1 + 1 |
| 284 | + sta TR7 |
| 285 | + |
285 | 286 | ; Le fichier n'a pas été trouvé, |
286 | 287 | ; On va vérifier qu'on avait un fichier ouvert avant |
287 | | - lda kernel_process+kernel_process_struct::kernel_fd_opened ; if there is already a file open on ch376 if value <> $FF, if it's equal to $ff, there is no file opened |
| 288 | + lda kernel_process + kernel_process_struct::kernel_fd_opened ; if there is already a file open on ch376 if value <> $FF, if it's equal to $ff, there is no file opened |
288 | 289 | cmp #$FF |
289 | 290 | beq @exit_open_with_null |
290 | 291 |
|
|
293 | 294 | jsr open_full_filename |
294 | 295 |
|
295 | 296 | @exit_open_with_null: |
296 | | - lda KERNEL_XOPEN_PTR1 |
297 | | - ldy KERNEL_XOPEN_PTR1+1 |
| 297 | + |
| 298 | + lda TR6 ; KERNEL_XOPEN_PTR1 restored |
| 299 | + ldy TR7 ; KERNEL_XOPEN_PTR1 restored |
298 | 300 | jsr XFREE_ROUTINE |
299 | 301 | ; No such file_or_directy |
300 | 302 | lda #ENOENT |
301 | 303 | sta KERNEL_ERRNO |
302 | 304 |
|
303 | | -.ifdef WITH_DEBUG2 |
304 | | - ldx #XDEBUG_XOPEN_FILE_NOT_FOUND |
305 | | - lda #$FF |
306 | | - jsr xdebug_print_with_a |
307 | | -.endif |
308 | 305 |
|
309 | 306 | lda #$FF |
310 | 307 | tax |
|
319 | 316 | @open_and_register_fp: |
320 | 317 | ; Register fp in process struct |
321 | 318 | ; store pointer in process struct |
322 | | - ldx kernel_process+kernel_process_struct::kernel_current_process ; Get current process |
| 319 | + ldx kernel_process + kernel_process_struct::kernel_current_process ; Get current process |
323 | 320 | jsr kernel_get_struct_process_ptr |
324 | 321 | sta RES |
325 | | - sty RES+1 |
| 322 | + sty RES + 1 |
326 | 323 |
|
327 | 324 | ; Fill the address of the fp |
328 | 325 | ; Manage only 1 FP for instance FIXME bug |
329 | 326 | ldx #$00 |
330 | | - ldy #(kernel_one_process_struct::fp_ptr+1) |
331 | | - |
| 327 | + ldy #(kernel_one_process_struct::fp_ptr + 1) |
| 328 | +; $ee53 |
332 | 329 | @try_to_find_a_free_fp_for_current_process: |
333 | 330 | lda (RES),y ; Load high |
334 | 331 | beq @fp_is_not_busy ; If it's equal to $00, it means that it's empty because it's impossible to have a fp registered in zp |
|
339 | 336 | inx |
340 | 337 | cpx #KERNEL_MAX_FP_PER_PROCESS |
341 | 338 | bne @try_to_find_a_free_fp_for_current_process |
| 339 | + ; At this step, we did not have any free fp for the current process |
342 | 340 |
|
343 | 341 | lda #KERNEL_ERRNO_REACH_MAX_FP_FOR_A_PROCESS |
344 | 342 | sta KERNEL_ERRNO |
345 | 343 |
|
346 | | - beq @exit_open_with_null |
| 344 | + jmp @exit_open_with_null |
347 | 345 | ; |
348 | 346 | @fp_is_not_busy: |
349 | | - lda KERNEL_XOPEN_PTR1+1 |
| 347 | + lda KERNEL_XOPEN_PTR1 + 1 |
350 | 348 | sta (RES),y |
351 | 349 | dey |
352 | 350 | lda KERNEL_XOPEN_PTR1 |
|
357 | 355 | ldx #$00 |
358 | 356 |
|
359 | 357 | @init_fp: |
360 | | - lda kernel_process+kernel_process_struct::kernel_fd,x |
| 358 | + lda kernel_process + kernel_process_struct::kernel_fd,x |
361 | 359 | beq @found_fp_slot |
362 | 360 | inx |
363 | 361 | cpx #KERNEL_MAX_FP |
364 | 362 | bne @init_fp |
365 | 363 |
|
366 | 364 | ; No available fd |
367 | 365 | lda KERNEL_XOPEN_PTR1 |
368 | | - ldy KERNEL_XOPEN_PTR1+1 |
| 366 | + ldy KERNEL_XOPEN_PTR1 + 1 |
369 | 367 | jsr XFREE_ROUTINE |
370 | 368 |
|
371 | 369 | lda #EMFILE |
|
377 | 375 |
|
378 | 376 | ; not found |
379 | 377 | @found_fp_slot: |
380 | | - lda kernel_process+kernel_process_struct::kernel_current_process ; Get the current process |
381 | | - sta kernel_process+kernel_process_struct::kernel_fd,x ; and store in fd slot the id of the process |
| 378 | + lda kernel_process + kernel_process_struct::kernel_current_process ; Get the current process |
| 379 | + sta kernel_process + kernel_process_struct::kernel_fd,x ; and store in fd slot the id of the process |
382 | 380 | txa |
383 | 381 | pha ; save Id of the fd |
384 | 382 | asl |
385 | 383 | tax |
386 | 384 |
|
387 | 385 | ; Store fp in main process |
| 386 | + |
| 387 | + |
| 388 | + |
388 | 389 | lda KERNEL_XOPEN_PTR1 |
389 | | - sta kernel_process+kernel_process_struct::fp_ptr,x |
| 390 | + sta kernel_process + kernel_process_struct::fp_ptr,x |
390 | 391 | inx |
391 | | - lda KERNEL_XOPEN_PTR1+1 |
392 | | - sta kernel_process+kernel_process_struct::fp_ptr,x |
| 392 | + lda KERNEL_XOPEN_PTR1 + 1 |
| 393 | + sta kernel_process + kernel_process_struct::fp_ptr,x |
393 | 394 | pla ; restore Id of the fd |
394 | | - sta kernel_process+kernel_process_struct::kernel_fd_opened ; Define that it's the new current fd |
| 395 | + sta kernel_process + kernel_process_struct::kernel_fd_opened ; Define that it's the new current fd |
| 396 | + |
395 | 397 | clc |
396 | 398 | adc #KERNEL_FIRST_FD |
397 | 399 |
|
|
0 commit comments