Skip to content

Commit

Permalink
first time rendering images and stuff. # this is not optimal. lol.
Browse files Browse the repository at this point in the history
  • Loading branch information
eljojo committed Jul 27, 2014
1 parent 24f378e commit f797d15
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/mimey/emulator.rb
Expand Up @@ -4,6 +4,7 @@ module Mimey
class Emulator class Emulator
attr_accessor :debug_mode, :step_by_step, :step_counter attr_accessor :debug_mode, :step_by_step, :step_counter
attr_reader :screen attr_reader :screen
attr_reader :gpu # delete this later


def initialize(cpu_options = {}) def initialize(cpu_options = {})
cpu_options = CPU::DEFAULTS.merge(cpu_options) cpu_options = CPU::DEFAULTS.merge(cpu_options)
Expand Down
7 changes: 5 additions & 2 deletions lib/mimey/gpu.rb
Expand Up @@ -3,6 +3,7 @@ module Mimey
class GPU class GPU
attr_reader :vram attr_reader :vram
attr_accessor :cpu attr_accessor :cpu
attr_reader :scrn # delete this later


def initialize(screen) def initialize(screen)
@screen = screen @screen = screen
Expand Down Expand Up @@ -306,7 +307,8 @@ def new_renderscan
tilerow = @tilemap[tile][y] tilerow = @tilemap[tile][y]
160.downto(1).each do |w| 160.downto(1).each do |w|
@scanrow[160 - x] = tilerow[x] @scanrow[160 - x] = tilerow[x]
@scrn[linebase + 3] = @palette[:bg][tilerow[x]] # by some reason we have to divide this by 4. don't ask me why.
@scrn[(linebase + 3)/4] = @palette[:bg][tilerow[x]]
x += 1 x += 1
if x == 8 then if x == 8 then
t = (t + 1) & 31 t = (t + 1) & 31
Expand All @@ -323,7 +325,8 @@ def new_renderscan
tilerow = @tilemap[@vram[mapbase + t]][y] tilerow = @tilemap[@vram[mapbase + t]][y]
160.downto(1).each do |w| 160.downto(1).each do |w|
@scanrow[160 - x] = tilerow[x] @scanrow[160 - x] = tilerow[x]
@scrn[linebase + 3] = @palette[:bg][tilerow[x]] # by some reason we have to divide this by 4. don't ask me why.
@scrn[(linebase + 3)/4] = @palette[:bg][tilerow[x]]
x += 1 x += 1
if x == 8 then if x == 8 then
t = (t + 1) & 31 t = (t + 1) & 31
Expand Down
10 changes: 6 additions & 4 deletions lib/mimey/lcd_screen.rb
Expand Up @@ -11,6 +11,8 @@ class LcdScreen
0 => 3 0 => 3
} }


attr_accessor :screen

def initialize def initialize
@screen = (WIDTH * HEIGHT).times.map { 0 } @screen = (WIDTH * HEIGHT).times.map { 0 }
end end
Expand All @@ -25,8 +27,8 @@ def render


def []=(coords, color) def []=(coords, color)
return unless color return unless color
color_index = COLOR_MAPPINGS[color] # i want to do it this way so I can set @screen to @scrn
@screen[coords] = COLORS[color_index] @screen[coords] = color
# x, y = coords # x, y = coords
# if x < WIDTH and y < HEIGHT # if x < WIDTH and y < HEIGHT
# @screen[y * WIDTH + x] = color_code # @screen[y * WIDTH + x] = color_code
Expand All @@ -37,8 +39,8 @@ def []=(coords, color)
# https://github.com/fazibear/colorize/blob/master/lib/colorize.rb # https://github.com/fazibear/colorize/blob/master/lib/colorize.rb
# http://misc.flogisoft.com/bash/tip_colors_and_formatting # http://misc.flogisoft.com/bash/tip_colors_and_formatting
def print_pixel(color) def print_pixel(color)
# code = COLORS[color] # this is not optimal. lol.
code = color code = COLORS[COLOR_MAPPINGS[color]]
print "\e[49m\e[#{code}m \e[49m" print "\e[49m\e[#{code}m \e[49m"
end end
end end
Expand Down
14 changes: 12 additions & 2 deletions test_emulator.rb
Expand Up @@ -106,8 +106,18 @@ def reference_hash
else else
puts "ran #{step_counter.steps.length} steps" puts "ran #{step_counter.steps.length} steps"
puts "OMG I couldn't find any errors!" puts "OMG I couldn't find any errors!"
puts step_counter.steps.last.gpu_r.scrn.inspect screen = Mimey::LcdScreen.new
# emulator.screen.render scrn = emulator.gpu.scrn
if scrn.compact.length != scrn.length then
puts "warning, the screen has some nils"
puts scrn.length
puts scrn.compact.length
puts scrn[0..100].inspect
puts scrn[0..100].compact.inspect
end

screen.screen = scrn
screen.render
end end


# emulator.debug # emulator.debug

0 comments on commit f797d15

Please sign in to comment.