-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules.txt
277 lines (225 loc) · 7.31 KB
/
modules.txt
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
*** Regsistered Modules ***
-------------------------------
-------------------------------------------------------------------------------
Created by: Sinan Islekdemir
2022
-------------------------------------------------------------------------------
Modules are accessed through certain memory addresses and SYS calls.
Usually @10 is used as a command address and @20 is used as the data
address.
Example:
SET 10l <value>
SET 20l <value>
SYS <number>
Modules return back values using addresses, usually 20 as the data
address.
IMPORTANT NOTE: If your code is using modules, make sure that you do not
store important data in command and data areas defined by
the module. Usually try to use memory areas above 256 or
512. Otherwise, the module can overwrite your data while
processing.
-------------------------------------------------------------------------------
(1) File System
Filesystem can be accessed through SYS 1
DISK ACCESS COMMAND ADDRESS 10
DISK ACCESS DATA ADDRESS 20
Commands:
1: Open directory
Arguments:
10: 1
20: Path to open
Return type : Number
Return address: 20
Description : Number of files in the path.
Response: Number of files found in the directory. At this point, you
need to keep it in mind to loop. So better store it.
2: Get file details.
Arguments:
10: 2
20: File Index
Return type : Number
Return address: 20
Description : 1 if it is a directory. 0 for regular files.
Return type : String
Return address: 30
Description : File name [256 chars]
3: Close directory
Arguments:
10: 3
Return : None
-----------------------------------------------------------------
Examples:
main:
DATA 1000 "Directory lister"
# 1 -- Open Dir
DATA 1030 1
# 2 -- Get file information
DATA 1040 2
# 3 -- Close Dir
DATA 1050 3
# File counter
DATA 1060 0
DATA 2000 "."
SPRINTLN 1000s
SET 20s 2000s
SET 10l 1030l
SYS 1
SET 1080l 20l
CALL 1
loop_files:
SET 10l 1040l
SET 20l 1060l
SYS 1
SPRINTLN 30s
INC 1060l
CMP 1060l 1080l
JE 2
GOTO 0
exit:
HALT
-----------------------------------------------------------------
4: Open file for reading
Arguments:
10: 4
20: Filename
Return type : Number
Return address: 20
Description : eXLang has 16 file pointers you can use,
file open returns the used pointer index
Return type : Number
Return address: 30
Description : File size in bytes
5: Open file for writing
Arguments:
10: 5
20: Filename
Return type : Number
Return address: 20
Description : eXLang has 16 file pointers you can use,
file open returns the used pointer index
Return type : Number
Return address: 30
Description : File size in bytes
6: Set file cursor location (aka fseek)
Arguments:
10: 6
20: File index
30: Cursor location
Return : None
7: Read from file
Arguments:
10: 7
20: File index
30: Size in bytes
Return type : Number
Return address: 20
Description : EOF (0 if cursor has reached the end of the file)
Return type : String|Byte array
Return address: 30
Description : Data buffer
8: Write into file
Arguments:
10: 8
20: File index
30: Size in bytes
40: Data
Return : None
9: Close file
Arguments:
10: 9
20: File index
Return : None
-----------------------------------------------------------------
Example:
main:
DATA 980 1
DATA 990 0x0a
DATA 1000 "Hello world"
# Number of lines to write
DATA 1020 10
# Counter
DATA 1030 0
# Open read
DATA 1040 4
# Open write
DATA 1050 5
# Set cursor location
DATA 1060 6
# Read file
DATA 1070 7
# Write file
DATA 1080 8
# Close file
DATA 1090 9
# Filename
DATA 1110 "hello.txt"
# Data size
DATA 1130 11
DATA 1140 "Writing file"
DATA 1160 "Reading file"
DATA 1180 "Done"
DATA 1200 "Unknown error"
DATA 1220 512
DATA 1230 0
CALL 1
write_file:
SPRINTLN 1140s
DEL 10s 1220l
SET 10l 1050l
SET 20s 1110s
SYS 1
# Store file pointer
SET 1250l 20l
# Write into file
DEL 10s 1220l
SET 10l 1080l
SET 20l 1250l
SET 30l 1130l
SET 40s 1000s
SYS 1
DEL 10s 1220l
SET 10l 1080l
SET 20l 1250l
SET 30l 980l
SET 40s 990s
SYS 1
INC 1030l
CMP 1030l 1020l
JE 2
GOTO 6
cf_before_read:
SPRINTLN 1180s
DEL 10s 1220l
SET 10l 1090l
SET 20l 1250l
SYS 1
CALL 3
read_file:
SPRINTLN 1160s
DEL 10s 1220l
SET 10l 1040l
SET 20s 1110s
SYS 1
SET 1250l 20l
INC 1030l
# Read file
DEL 10s 1220l
SET 10l 1070l
SET 20l 1250l
SET 30l 1130l
SYS 1
SPRINT 30s
CMP 20l 1230l
JE 4
GOTO 7
exit:
SPRINTLN 1180s
SET 10l 1090l
SET 20l 1250l
SYS 1
HALT
on_exception:
SPRINTLN 1200s
HALT
-------------------------------------------------------------------------------