Should almost work with real drive...?

This commit is contained in:
Casey 2023-10-20 02:16:46 +03:00
parent 086b8374ad
commit 3543ef9595
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 33 additions and 14 deletions

View File

@ -43,6 +43,27 @@ local function read32(fp)
return v
end
local drive = peripheral.find("disk_drive")
if not drive then
printError("No drive found, starting in dummy mode")
drive = {
_pos = 0,
seek = function(howMuch)
drive._pos = math.min(drive.getSize(), math.max(0, drive._pos + howMuch))
end,
getPosition = function()
return drive._pos
end,
getSize = function()
return 360000 * 64
end,
_tick = function()
drive._pos = drive._pos + 600
end
}
os.sleep(1)
end
local help = {}
for line in ([[# Movement:
@ -175,7 +196,8 @@ local mplayer = {
elseif key == keys.pageUp then
self.screens[2].handleScroll(self, -(th - 3))
elseif key == keys.enter then
self.pos = self.songs[self.screens[2].cursor].offset
drive.seek(-drive.getSize())
drive.seek(self.songs[self.screens[2].cursor].offset)
self.currentSong = self.screens[2].cursor
end
end,
@ -226,9 +248,6 @@ local mplayer = {
}
},
songs = {},
pos = 0,
size = 360000 * 64,
state = "PLAYING",
currentSong = 0,
statusLineScroll = 0,
currentScreen = 2,
@ -279,10 +298,10 @@ function()
term.setBackgroundColor(mplayer.colors.bg)
local title, time, duration = "Whatever is on the tape", mplayer.pos / 6000, mplayer.size / 6000
local title, time, duration = "Whatever is on the tape", drive.getPosition() / 6000, drive.getSize() / 6000
if mplayer.currentSong ~= 0 then
local song = mplayer.songs[mplayer.currentSong]
time = (mplayer.pos - song.offset) / 6000
time = (drive.getPosition() - song.offset) / 6000
duration = song.length / 6000
title = song.title
end
@ -343,9 +362,9 @@ function()
elseif ev == "key" and (evd[1] == keys.three or evd[1] == keys.f3) then
mplayer.currentScreen = 3
elseif ev == "key" and evd[1] == keys.f then
mplayer.pos = mplayer.pos + 3000
drive.seek(3000)
elseif ev == "key" and evd[1] == keys.b then
mplayer.pos = mplayer.pos - 3000
drive.seek(-3000)
elseif ev == "key" and evd[1] == keys.tab then
local dir = ((mplayer.heldKeys[keys.leftShift] ~= nil) or (mplayer.heldKeys[keys.rightShift] ~= nil)) and -1 or 1
mplayer.currentScreen = ((mplayer.currentScreen - 1 + #mplayer.screens + dir)) % #mplayer.screens + 1
@ -359,10 +378,11 @@ function()
elseif (ev == "mouse_click" or ev == "mouse_drag") and evd[3] == th - 1 then
local p = (evd[2] - 1) / tw
local song = mplayer.songs[mplayer.currentSong]
drive.seek(-drive.getSize())
if song ~= nil then
mplayer.pos = song.offset + math.floor(song.length * p)
drive.seek(song.offset + math.floor(song.length * p))
else
mplayer.pos = math.floor(p * mplayer.size)
drive.seek(math.floor(p * drive.getSize()))
end
elseif (ev == "mouse_click" or ev == "mouse_drag") and evd[3] == 1 then
local cx, x = 1, evd[2]
@ -394,12 +414,11 @@ end,
function()
local oldSong = nil
while true do
if mplayer.pos < mplayer.size then
mplayer.pos = mplayer.pos + 600
end
mplayer.currentSong = 0
if drive._tick then drive._tick() end
local pos = drive.getPosition()
for i, song in ipairs(mplayer.songs) do
if mplayer.pos >= song.offset and mplayer.pos < (song.offset + song.length) then
if pos >= song.offset and pos < (song.offset + song.length) then
mplayer.currentSong = i
end
end