From 3543ef95959b35515bb046b1eae8cb5243b730e9 Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 20 Oct 2023 02:16:46 +0300 Subject: [PATCH] Should almost work with real drive...? --- mess/tmpc.lua | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/mess/tmpc.lua b/mess/tmpc.lua index 83b64e9..689c7e2 100644 --- a/mess/tmpc.lua +++ b/mess/tmpc.lua @@ -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