Ewgeniy

IcePlayer

Sep 7th, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. local component = require("component")
  2. local term = require("term")
  3. local gpu = component.gpu
  4. local computer = require("computer")
  5. local fname = ...
  6. local fp = io.open(fname, "rb")
  7.  
  8. while true do
  9. COLMAP = {}
  10. local i
  11. for i=0,15 do
  12.     local w = i*255/15
  13.     COLMAP[i] = (w<<16)|(w<<8)|w
  14.     gpu.setPaletteColor(i, COLMAP[i])
  15. end
  16. for i=0,240-1 do
  17.     local r = i%6
  18.     local g = (i//6)%8
  19.     local b = (i//(6*8))
  20.  
  21.     r = (r*255+2)//5
  22.     g = (g*255+3)//7
  23.     b = (b*255+2)//4
  24.  
  25.     COLMAP[i+16] = (r<<16)|(g<<8)|b
  26. end
  27.  
  28.  
  29.  
  30. gpu.setResolution(80, 25)
  31. gpu.setBackground(0x000000)
  32. gpu.setForeground(0xFFFFFF)
  33. term.clear()
  34.  
  35. if sysnative then
  36.     tlast = os.clock()
  37. else
  38.     os.sleep(0.05)
  39.     if tape and tape.isReady() then
  40.         tape.play()
  41.         os.sleep(1.0) -- deal to sound latency
  42.     end
  43.     tlast = computer.uptime()
  44. end
  45.  
  46. local delay_acc = 0.0
  47. local function delay(d)
  48.     assert(d >= 0.0)
  49.     delay_acc = delay_acc + d
  50.     local dquo = math.floor(delay_acc / 0.05) * 0.05
  51.     delay_acc = delay_acc - dquo
  52.     os.sleep(dquo)
  53. end
  54.  
  55. while true do
  56.     local s = fp:read(1)
  57.     if s == "" or s == nil then
  58.         break
  59.     end
  60.     local c = s:byte()
  61.  
  62.     if c == 0xFF then
  63.         tnow = computer.uptime()
  64.         tlast = tlast + 0.05
  65.         while tnow < tlast do
  66.             --delay(tlast-tnow)
  67.             os.sleep(tlast-tnow)
  68.             tnow = computer.uptime()
  69.         end
  70.     elseif c == 0x00 then
  71.         local col = COLMAP[fp:read(1):byte()]
  72.         gpu.setBackground(col)
  73.     else
  74.         local by = fp:read(1):byte()
  75.         local bx = fp:read(1):byte()
  76.         local bw = fp:read(1):byte()
  77.         local bh = c & 0x3F
  78.         local type = c & 0x40
  79.         if type == 0x40 then
  80.             gpu.fill(bx, by, bw, bh, " ")
  81.         else
  82.             if bh < bw then
  83.                 for i = 0, bh-1 do
  84.                     gpu.set(bx, by + i, string.rep(" ", bw), false)
  85.                 end
  86.             else
  87.                 for i = 0, bw - 1 do
  88.                     gpu.set(bx + i, by, string.rep(" ", bh), true)
  89.                 end
  90.             end
  91.         end
  92.     end
  93. end
  94.  
  95. gpu.setBackground(0x000000)
  96. gpu.setForeground(0xFFFFFF)
  97. end
  98.  
Add Comment
Please, Sign In to add comment