-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileio.asm
More file actions
73 lines (68 loc) · 2.38 KB
/
fileio.asm
File metadata and controls
73 lines (68 loc) · 2.38 KB
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
; fileio.asm - wrappers to allow IntyBASIC to call EmuLink
; Copyright (C) 2019 Patrick Pelletier <code@funwithsoftware.org>
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program. If not, see <https://www.gnu.org/licenses/>.
include "emu_link.mac"
include "el_fileio.mac"
;; #emu = usr inty_emu_detect
INTY_EMU_DETECT: proc
begin
EL_EMU_DETECT
bnc @@done
mvii #$ffff, r0 ; return -1 if no emulator
@@done:
return
endp
;; #fd = usr inty_open(varptr filename(0), flags)
INTY_OPEN: proc
begin
movr r0, r2 ; pointer to ASCIIZ filename
movr r1, r3 ; flags
ELFI_OPEN R2, R3
bc @@fail
movr r2, r0 ; return file descriptor on success
return
@@fail:
mvo r0, var_&ERRNO
mvii #$ffff, r0 ; return -1 on error
return
endp
;; #ret = usr inty_close(#fd)
INTY_CLOSE: proc
begin
movr r0, r2 ; file descriptor
ELFI_CLOSE
bc @@fail
mvii #0, r0 ; return 0 on success
return
@@fail:
mvo r0, var_&ERRNO
mvii #$ffff, r0 ; return -1 on error
return
endp
;; #ret = usr inty_write(#fd, varptr buf(0), len)
INTY_WRITE: proc
begin
movr r2, r4 ; number of bytes to write
movr r1, r3 ; pointer to buffer
movr r0, r2 ; file descriptor
ELFI_WRITE R3, R4
bc @@fail
movr r1, r0 ; return number of bytes written on success
return
@@fail:
mvo r0, var_&ERRNO
mvii #$ffff, r0 ; return -1 on error
return
endp