-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwip-util-copy.lua
More file actions
89 lines (73 loc) · 1.88 KB
/
wip-util-copy.lua
File metadata and controls
89 lines (73 loc) · 1.88 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
--WIP, copy functionality between two cassette tapes.--
--NOT FUNCTIONAL, THIS IS A WORK IN PROGRESS--
local tape1, tape2 = peripheral.find("tape_drive") --get both
--display findings
write("Found ")
--tape 1
if tape1.getLabel() ~= nil then
write(tape1.getLabel)
else write("unnamed tape")
end
write(" (" .. tape1.getSize() .. ")")
write(" AND ")
--tape 2
if tape2.getLabel() ~= nil then
write(tape2.getLabel)
else write("unnamed tape")
end
write(" (" .. tape2.getSize() .. ")")
write("\n")
-- Scan in user input
local function userSelectTape()
write("which tape would you like to have the content pasted on (The unselected one will be copied from)?\nEnter '1' or '2'")
local selectedTape = read()
print("You chose: tape ", selectedTape) --weird way of concat.
return selectedTape
end
-- Interpret User Input
local function copyTape(selectedTape)
--rewind both
tape1.seek(-tape1.getSize())
tape2.seek(-tape2.getSize())
-- get smallest
local smallest = nil
if tape1.getSize() > tape2.getSize() then
smallest = tape2.getSize()
else smallest = tape2.getSize
end
local copyContent = nil
if tonumber(selectedTape) == 1 then -- copy from tape 1 to tape 2
for i=1,smallest do
-- copyContent = tape1.read()
-- tape2.write(copyContent)
tape2.write(tape1.read()) --read/write
--seek to next position
tape1.seek(1)
tape2.seek(1)
end
elseif tonumber(selectedTape) == 2 then --copy from tape 2 to tape 1
for i=1,smallest do
tape1.write(tape2.read()) --read/write
--seek to next byte
tape1.seek(1)
tape2.seek(1)
end
else
return error
end
end
--Initilizing:
local function StartCopy()
copyTape(userSelectTape())
end
--[[
ask user which one they want to copy from/to
seek to start of both,
loop
read first byte of one,
copy to write as byte of other,
seek forward 1
end (at end of tape or song?)
Bugs/TODO:
error checking if one tape is larger than other.
]]