-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdazzler.lua
95 lines (90 loc) · 3.93 KB
/
dazzler.lua
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
90
91
92
93
94
95
local lg = love.graphics
local dazzler = {
on = false,
vram = 0,
resolution_x4 = false,
memory_2k = false,
color = false,
high_intensity = false,
blue = false,
green = false,
red = false,
canvas = lg.newCanvas(8 * 64, 8 * 64)
}
function dazzler:init(bus)
self.bus = bus
end
function dazzler:draw()
lg.setCanvas(self.canvas)
lg.clear() -- ??
if self.on then
if self.resolution_x4 then
local red = self.red and 1 or 0
local green = self.green and 1 or 0
local blue = self.blue and 1 or 0
local intensity = self.high_intensity and 1 or 0.5
lg.setColor(red, green, blue, intensity)
local pixel_size = self.memory_2k and 4 or 8
for quadrant = 0, self.memory_2k and 3 or 0 do
local base_address = self.vram + (quadrant * 512)
for y = 0, 63, 2 do
for x = 0, 63, 4 do
local byte = self.bus[base_address + (y * 16) + math.floor(x / 2)]
for bit = 0, 7 do
local pixel = bit.band(byte, 0x01)
byte = bit.rshift(byte, 1)
local x_pos = (x + (quadrant % 2) * 64) * pixel_size
local y_pos = (y + (math.floor(quadrant / 2) * 64)) * pixel_size
-- TODO The following code is very ugly and must be refactored
if bit == 1 then
x_pos = x_pos + pixel_size
elseif bit == 2 then
y_pos = y_pos + pixel_size
elseif bit == 3 then
x_pos = x_pos + pixel_size
y_pos = y_pos + pixel_size
elseif bit == 4 then
x_pos = x_pos + (2 * pixel_size)
elseif bit == 5 then
x_pos = x_pos + (3 * pixel_size)
elseif bit == 6 then
x_pos = x_pos + (2 * pixel_size)
y_pos = y_pos + pixel_size
elseif bit == 7 then
x_pos = x_pos + (3 * pixel_size)
y_pos = y_pos + pixel_size
end
if pixel ~= 0 then
lg.rectangle("fill", x_pos, y_pos, pixel_size, pixel_size)
end
end
end
end
end
else
local pixel_size = self.memory_2k and 8 or 16
for quadrant = 0, self.memory_2k and 3 or 0 do
local base_address = self.vram + (quadrant * 512)
for y = 0, 31 do
for x = 0, 31, 2 do
local byte = self.bus[base_address + (y * 16) + math.floor(x / 2)]
for nybble = 0, 1 do
byte = bit.lshift(byte, 4 * nybble)
local red = bit.band(bit.rshift(byte, 7), 1)
local green = bit.band(bit.rshift(byte, 6), 1)
local blue = bit.band(bit.rshift(byte, 5), 1)
local intensity = math.max(bit.band(bit.rshift(byte, 4), 1), 0.5)
lg.setColor(red, green, blue, intensity)
local x_pos = (x + (nybble * 1) + (quadrant % 2) * 32) * pixel_size
local y_pos = (y + (math.floor(quadrant / 2) * 32)) * pixel_size
lg.rectangle("fill", x_pos, y_pos, pixel_size, pixel_size)
end
end
end
end
end
end
lg.setColor(1, 1, 1, 1)
lg.setCanvas()
end
return dazzler