From f797d1576a0c35430befda79bb7053fd1e36b544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Tom=C3=A1s=20Albornoz?= Date: Sun, 27 Jul 2014 19:44:35 +0200 Subject: [PATCH] first time rendering images and stuff. # this is not optimal. lol. --- lib/mimey/emulator.rb | 1 + lib/mimey/gpu.rb | 7 +++++-- lib/mimey/lcd_screen.rb | 10 ++++++---- test_emulator.rb | 14 ++++++++++++-- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/mimey/emulator.rb b/lib/mimey/emulator.rb index 758294b..3657bae 100644 --- a/lib/mimey/emulator.rb +++ b/lib/mimey/emulator.rb @@ -4,6 +4,7 @@ module Mimey class Emulator attr_accessor :debug_mode, :step_by_step, :step_counter attr_reader :screen + attr_reader :gpu # delete this later def initialize(cpu_options = {}) cpu_options = CPU::DEFAULTS.merge(cpu_options) diff --git a/lib/mimey/gpu.rb b/lib/mimey/gpu.rb index 12ae44e..fcfa356 100644 --- a/lib/mimey/gpu.rb +++ b/lib/mimey/gpu.rb @@ -3,6 +3,7 @@ module Mimey class GPU attr_reader :vram attr_accessor :cpu + attr_reader :scrn # delete this later def initialize(screen) @screen = screen @@ -306,7 +307,8 @@ def new_renderscan tilerow = @tilemap[tile][y] 160.downto(1).each do |w| @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 if x == 8 then t = (t + 1) & 31 @@ -323,7 +325,8 @@ def new_renderscan tilerow = @tilemap[@vram[mapbase + t]][y] 160.downto(1).each do |w| @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 if x == 8 then t = (t + 1) & 31 diff --git a/lib/mimey/lcd_screen.rb b/lib/mimey/lcd_screen.rb index 5153869..1a18752 100644 --- a/lib/mimey/lcd_screen.rb +++ b/lib/mimey/lcd_screen.rb @@ -11,6 +11,8 @@ class LcdScreen 0 => 3 } + attr_accessor :screen + def initialize @screen = (WIDTH * HEIGHT).times.map { 0 } end @@ -25,8 +27,8 @@ def render def []=(coords, color) return unless color - color_index = COLOR_MAPPINGS[color] - @screen[coords] = COLORS[color_index] + # i want to do it this way so I can set @screen to @scrn + @screen[coords] = color # x, y = coords # if x < WIDTH and y < HEIGHT # @screen[y * WIDTH + x] = color_code @@ -37,8 +39,8 @@ def []=(coords, color) # https://github.com/fazibear/colorize/blob/master/lib/colorize.rb # http://misc.flogisoft.com/bash/tip_colors_and_formatting def print_pixel(color) - # code = COLORS[color] - code = color + # this is not optimal. lol. + code = COLORS[COLOR_MAPPINGS[color]] print "\e[49m\e[#{code}m \e[49m" end end diff --git a/test_emulator.rb b/test_emulator.rb index 19317b6..104241e 100644 --- a/test_emulator.rb +++ b/test_emulator.rb @@ -106,8 +106,18 @@ def reference_hash else puts "ran #{step_counter.steps.length} steps" puts "OMG I couldn't find any errors!" - puts step_counter.steps.last.gpu_r.scrn.inspect - # emulator.screen.render + screen = Mimey::LcdScreen.new + 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 # emulator.debug