Advertisement
Ocawesome101

font rendering

Sep 30th, 2020 (edited)
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. -- screen I/O --
  2.  
  3. sys.dofile(0, "font.lua")
  4.  
  5. local screen = {}
  6. -- color palette taken from VICE with no CRT emuation filter
  7. local palette = {
  8.   [0] = 0x000000,
  9.   [1] = 0xffffff,
  10.   [2] = 0xb5685e,
  11.   [3] = 0xa9f3ff,
  12.   [4] = 0xcd6fd4,
  13.   [5] = 0x89e581,
  14.   [6] = 0x6953f5,
  15.   [7] = 0xffff7b,
  16.   [8] = 0xc69232,
  17.   [9] = 0x8d7900,
  18.   [10]= 0xf5ab96,
  19.   [11]= 0x818181,
  20.   [12]= 0xb6b6b6,
  21.   [13]= 0xcdffc6,
  22.   [14]= 0xb19eff,
  23.   [15]= 0xe0e0e0
  24. }
  25.  
  26. local function computeXY(index)
  27.   index = index + 1
  28.   local y = math.floor(index / 40)
  29.   local x = index % 40
  30.   return x*4, y*2 -- displayed font is 4x2 chars or 8x8 pixels
  31. end
  32.  
  33. local function drawchar(index, code, color)
  34.   local colsw
  35.   if code > 127 then
  36.     colsw = true
  37.     code = code - 127
  38.   end
  39.   local draw = sys.font[code+1]
  40.   local x, y = computeXY(index)
  41.   local fg, bg = palette[color], palette[sys.ram.get(53281)]
  42.   if colsw then
  43.     fg, bg = bg, fg
  44.   end
  45.   sys.gpu.setForeground(fg)
  46.   sys.gpu.setBackground(bg)
  47. --  component.proxy(component.list("sandbox")()).log(x, y, fg, bg, color, code, draw)
  48.   sys.gpu.set(x-1, y, unicode.sub(draw, 1,4))
  49.   sys.gpu.set(x-1, y, unicode.sub(draw, 5))
  50. end
  51.  
  52. -- TODO: this is probably sloooooooow
  53. function screen.refresh()
  54.   for i=1024, 2023, 1 do
  55.     drawchar(i - 1024, sys.ram.get(i), sys.ram.get(55296 + i - 1024))
  56.   end
  57. end
  58.  
  59. for i=55296, 56295, 1 do
  60.   sys.ram.set(i, 14)
  61. end
  62. sys.ram.set(53281, 6)
  63.  
  64. screen.refresh()
  65. sys.screen = screen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement