Skip to content

Commit f797d15

Browse files
committed
first time rendering images and stuff. # this is not optimal. lol.
1 parent 24f378e commit f797d15

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎lib/mimey/emulator.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Mimey
44
class Emulator
55
attr_accessor :debug_mode, :step_by_step, :step_counter
66
attr_reader :screen
7+
attr_reader :gpu # delete this later
78

89
def initialize(cpu_options = {})
910
cpu_options = CPU::DEFAULTS.merge(cpu_options)

‎lib/mimey/gpu.rb‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Mimey
33
class GPU
44
attr_reader :vram
55
attr_accessor :cpu
6+
attr_reader :scrn # delete this later
67

78
def initialize(screen)
89
@screen = screen
@@ -306,7 +307,8 @@ def new_renderscan
306307
tilerow = @tilemap[tile][y]
307308
160.downto(1).each do |w|
308309
@scanrow[160 - x] = tilerow[x]
309-
@scrn[linebase + 3] = @palette[:bg][tilerow[x]]
310+
# by some reason we have to divide this by 4. don't ask me why.
311+
@scrn[(linebase + 3)/4] = @palette[:bg][tilerow[x]]
310312
x += 1
311313
if x == 8 then
312314
t = (t + 1) & 31
@@ -323,7 +325,8 @@ def new_renderscan
323325
tilerow = @tilemap[@vram[mapbase + t]][y]
324326
160.downto(1).each do |w|
325327
@scanrow[160 - x] = tilerow[x]
326-
@scrn[linebase + 3] = @palette[:bg][tilerow[x]]
328+
# by some reason we have to divide this by 4. don't ask me why.
329+
@scrn[(linebase + 3)/4] = @palette[:bg][tilerow[x]]
327330
x += 1
328331
if x == 8 then
329332
t = (t + 1) & 31

‎lib/mimey/lcd_screen.rb‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class LcdScreen
1111
0 => 3
1212
}
1313

14+
attr_accessor :screen
15+
1416
def initialize
1517
@screen = (WIDTH * HEIGHT).times.map { 0 }
1618
end
@@ -25,8 +27,8 @@ def render
2527

2628
def []=(coords, color)
2729
return unless color
28-
color_index = COLOR_MAPPINGS[color]
29-
@screen[coords] = COLORS[color_index]
30+
# i want to do it this way so I can set @screen to @scrn
31+
@screen[coords] = color
3032
# x, y = coords
3133
# if x < WIDTH and y < HEIGHT
3234
# @screen[y * WIDTH + x] = color_code
@@ -37,8 +39,8 @@ def []=(coords, color)
3739
# https://github.com/fazibear/colorize/blob/master/lib/colorize.rb
3840
# http://misc.flogisoft.com/bash/tip_colors_and_formatting
3941
def print_pixel(color)
40-
# code = COLORS[color]
41-
code = color
42+
# this is not optimal. lol.
43+
code = COLORS[COLOR_MAPPINGS[color]]
4244
print "\e[49m\e[#{code}m \e[49m"
4345
end
4446
end

‎test_emulator.rb‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,18 @@ def reference_hash
106106
else
107107
puts "ran #{step_counter.steps.length} steps"
108108
puts "OMG I couldn't find any errors!"
109-
puts step_counter.steps.last.gpu_r.scrn.inspect
110-
# emulator.screen.render
109+
screen = Mimey::LcdScreen.new
110+
scrn = emulator.gpu.scrn
111+
if scrn.compact.length != scrn.length then
112+
puts "warning, the screen has some nils"
113+
puts scrn.length
114+
puts scrn.compact.length
115+
puts scrn[0..100].inspect
116+
puts scrn[0..100].compact.inspect
117+
end
118+
119+
screen.screen = scrn
120+
screen.render
111121
end
112122

113123
# emulator.debug

0 commit comments

Comments
 (0)