-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
322 lines (296 loc) · 11.6 KB
/
main.lua
File metadata and controls
322 lines (296 loc) · 11.6 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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
function file_exist(name)
local f = io.open(name, "r")
if f~=nil then
io.close(f)
return true
else
return false
end
end
require('classes')
locationAmount = 99
locations = {}
for i = 0, locationAmount, 1 do
locations[i] = location.new(i, 0)
end
-- this code was used before the saving and loading was fully made
-- it has no use now but might be use for test at some points idk
--print("Is there a data file?[y,n]")
--
--usrin = io.read()
--
--if usrin == "n" then
-- file = io.open("data.txt", "w")
-- for i = 0, locationAmount, 1 do
-- locations[i].hexName = string.format("%x", locations[i].name)
--
-- if string.len(locations[i].hexName) == 1 then
-- file:write('000')
-- end
-- if string.len(locations[i].hexName) == 2 then
-- file:write('00')
-- end
--
-- file:write(locations[i].hexName..' '..locations[i].data)
--
-- if i == locationAmount then
-- else
-- file:write('\n')
-- end
-- end
-- file:close()
--else end
print("Type help for help\n")
while true do
usrin = io.read()
if usrin == 'help' then
print("+---------------------------------------+")
print("|run - runs all the data from memory|")
print("|write - writes to a location |")
print("|read - reads a location |")
print("|readSec - reads a section of memory |")
print("|readAll - reads all locations |")
print("|save - saves all data to a txt file |")
print("|load - loads data from a txt file |")
print("|clear - clears the console |")
print("|exit - exits the program |")
print("| |")
print("|go to github.com/RusticVoid/LuaComputer|")
print("|for more info |")
print("+---------------------------------------+\n")
end
if usrin == 'run' then
i = 0
print('')
while true do
if locations[i].data == "jmp" then
errori = i+1
i = tonumber(locations[i+1].data)
if type(i) == "number" then
else
io.write("There is an error at ")
io.write('"')
io.write(locations[errori]:displayData())
io.write('"')
print("")
break
end
else
if locations[i].data == "add" then
addLocationOne = tonumber(locations[i+1].data)
addLocationTwo = tonumber(locations[i+2].data)
sumLocation = tonumber(locations[i+3].data)
if tonumber(locations[addLocationOne].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[addLocationOne]:displayData())
io.write('"')
print("")
break
else
if tonumber(locations[addLocationTwo].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[addLocationTwo]:displayData())
io.write('"')
print("")
break
else
sum = tonumber(locations[addLocationOne].data) + tonumber(locations[addLocationTwo].data)
locations[sumLocation].data = sum
end
end
end
if locations[i].data == "sub" then
subLocationOne = tonumber(locations[i+1].data)
subLocationTwo = tonumber(locations[i+2].data)
sumLocation = tonumber(locations[i+3].data)
if tonumber(locations[subLocationOne].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[subLocationOne]:displayData())
io.write('"')
print("")
break
else
if tonumber(locations[subLocationTwo].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[subLocationTwo]:displayData())
io.write('"')
print("")
break
else
sum = tonumber(locations[subLocationOne].data) - tonumber(locations[subLocationTwo].data)
locations[sumLocation].data = sum
end
end
end
if locations[i].data == "mul" then
mulLocationOne = tonumber(locations[i+1].data)
mulLocationTwo = tonumber(locations[i+2].data)
sumLocation = tonumber(locations[i+3].data)
if tonumber(locations[mulLocationOne].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[mulLocationOne]:displayData())
io.write('"')
print("")
break
else
if tonumber(locations[mulLocationTwo].data) == nil then
io.write("There is an error at ")
io.write('"')
io.write(locations[mulLocationTwo]:displayData())
io.write('"')
print("")
break
else
sum = tonumber(locations[mulLocationOne].data) * tonumber(locations[mulLocationTwo].data)
locations[sumLocation].data = sum
end
end
end
if locations[i].data == "print" then
print(locations[i+1].data)
end
if locations[i].data == "break" then
break
end
if i == locationAmount then
break
else
i = i + 1
end
end
end
print('')
end
if usrin == 'write' then
print('write to[0-50]: ')
location = io.read()
if type(tonumber(location)) == "number" then
if tonumber(location) > 55 then
print("ADDRESS OUT OF RANGE!")
else
print('data: ')
data = io.read()
locations[tonumber(location)]:writeData(data)
print('Data writen!\n')
end
else
print("location has to be a number!")
end
end
if usrin == 'read' then
print('Read[0-50]: ')
location = io.read()
if tonumber(location) > 55 then
print("ADDRESS OUT OF RANGE!")
else
locations[tonumber(location)]:displayData()
end
print('')
end
if string.find(usrin, 'readSec') then
line = usrin
startLocation = line:sub(8,10)
endLocation = line:sub(11,-1)
print('')
if tonumber(startLocation) == nil or tonumber(endLocation) == nil then
print("One of the inputs are nil!")
else
if tonumber(startLocation) > 55 then
print("START ADDRESS OUT OF RANGE!")
end
if tonumber(endLocation) > 55 then
print("END ADDRESS OUT OF RANGE!")
else
for i = startLocation, endLocation, 1 do
locations[i]:displayData()
print('')
end
end
end
print('')
end
if usrin == 'readAll' then
print('')
for i = 0, locationAmount, 1 do
locations[i]:displayData()
print('')
end
print('')
end
if usrin == 'save' then
print("File Name: ")
fileName = io.read()
if file_exist(fileName) == true then
print("This Files Exist! do you wish to overwrite it?[y,n]")
answer = io.read()
if answer == "y" then
file = io.open(fileName, "w")
for i = 0, locationAmount, 1 do
locations[i].hexName = string.format("%x", locations[i].name)
if string.len(locations[i].hexName) == 1 then -- this adds 3 zeros at the begging of 1 hex number
file:write('000')
end
if string.len(locations[i].hexName) == 2 then -- this adds 2 zeros at the begging of 2 hex numbers
file:write('00')
end -- these arent need but also are its kinda hard to explain
-- but it just looks nice
file:write(locations[i].hexName..' '..locations[i].data)
if i == locationAmount then -- this stops a space at the end of the file
else -- its not really need though its just being neat
file:write('\n')
end
end
file:close()
print("File Saved!\n")
else
print("NOT SAVED!")
end
else
file = io.open(fileName, "w")
for i = 0, locationAmount, 1 do
locations[i].hexName = string.format("%x", locations[i].name)
if string.len(locations[i].hexName) == 1 then -- this adds 3 zeros at the begging of 1 hex number
file:write('000')
end
if string.len(locations[i].hexName) == 2 then -- this adds 2 zeros at the begging of 2 hex numbers
file:write('00')
end -- these arent need but also are its kinda hard to explain
-- but it just looks nice
file:write(locations[i].hexName..' '..locations[i].data)
if i == locationAmount then -- this stops a space at the end of the file
else -- its not really need though its just being neat
file:write('\n')
end
end
file:close()
print("File Saved!\n")
end
end
if usrin == 'load' then
print("File Name: ")
fileName = io.read()
if file_exist(fileName) == true then
file = io.open(fileName, "r")
for i = 0, locationAmount, 1 do
line = file:read()
locations[tonumber(i)]:writeData(line:sub(6,-1)) -- the line:sub allows you to skip bytes/letters
end
file:close()
print("File Loaded!\n")
else
print("File Not Found!\n")
end
end
if usrin == 'clear' then
os.execute('cls')
end
if usrin == 'exit' then
print('Shutting down...')
break
end
end