mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-05-20 05:10:21 -04:00
calculate rgb on write instead of every frame
This commit is contained in:
parent
b7fa538218
commit
a734488a5f
|
@ -112,7 +112,7 @@ impl Gfx {
|
|||
|
||||
for (x, px) in (&pixels[start..end]).iter().enumerate() {
|
||||
if *px != 0 {
|
||||
let (r, g, b) = emu.core.mem.vdp.color(palette, *px as _);
|
||||
let (r, g, b) = emu.core.mem.vdp.cram_rgb[*px as usize + (palette * 0x10)];
|
||||
let offset = (screen_x + x) * 3;
|
||||
(*target)[offset] = r;
|
||||
(*target)[offset + 1] = g;
|
||||
|
@ -161,7 +161,7 @@ impl Gfx {
|
|||
let px = if sprite_base_x & 1 == 0 { px >> 4 } else { px & 0xF };
|
||||
|
||||
if px != 0 {
|
||||
let (r, g, b) = emu.core.mem.vdp.color(sprite.palette, px as _);
|
||||
let (r, g, b) = emu.core.mem.vdp.cram_rgb[px as usize + (sprite.palette * 0x10)];
|
||||
let offset = x_offset as usize * 3;
|
||||
|
||||
if offset + 2 <= target.len() {
|
||||
|
@ -231,7 +231,7 @@ impl Gfx {
|
|||
|
||||
if px != 0 {
|
||||
let screen_x = if hflip { cursor ^ 7 } else { cursor } + x;
|
||||
let (r, g, b) = emu.core.mem.vdp.color(palette, px as _);
|
||||
let (r, g, b) = emu.core.mem.vdp.cram_rgb[px as usize + (palette * 0x10)];
|
||||
let offset = screen_x * 3;
|
||||
(*target)[offset] = r;
|
||||
(*target)[offset + 1] = g;
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct VDP {
|
|||
pub control_address: u32,
|
||||
pub control_pending: bool,
|
||||
pub dma_pending: bool,
|
||||
pub cram_rgb: [(u8, u8, u8); 0x40],
|
||||
}
|
||||
|
||||
pub const VBLANK_MASK: u32 = 8;
|
||||
|
@ -71,27 +72,15 @@ impl VDP {
|
|||
control_address: 0,
|
||||
control_pending: false,
|
||||
dma_pending: false,
|
||||
cram_rgb: [(0, 0, 0); 0x40],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn color(&self, line: usize, index: usize) -> (u8, u8, u8) {
|
||||
cram_to_rgb(self.CRAM[index + (line * 0x10)])
|
||||
}
|
||||
|
||||
pub fn bg_color(&self) -> (u8, u8, u8) {
|
||||
let vdp_bg = self.registers[7];
|
||||
let index = vdp_bg & 0xF;
|
||||
let line = (vdp_bg >> 4) & 3;
|
||||
self.color(line as _, index as _)
|
||||
}
|
||||
|
||||
// used in debugger
|
||||
pub fn cram_rgb(&self) -> [(u8, u8, u8); 64] {
|
||||
let mut rgb = [(0, 0, 0); 64];
|
||||
for (i, color) in self.CRAM.iter().enumerate() {
|
||||
rgb[i] = cram_to_rgb(*color);
|
||||
}
|
||||
rgb
|
||||
cram_to_rgb(self.CRAM[index as usize + (line as usize * 0x10)])
|
||||
}
|
||||
|
||||
pub fn screen_width(&self) -> usize {
|
||||
|
@ -253,7 +242,9 @@ impl VDP {
|
|||
self.VRAM[self.control_address as usize + 1] = (value & 0xff) as _;
|
||||
},
|
||||
VDPType::CRAM => {
|
||||
self.CRAM[((self.control_address & 0x7f) >> 1) as usize] = value as _;
|
||||
let address = ((self.control_address & 0x7f) >> 1) as usize;
|
||||
self.CRAM[address] = value as _;
|
||||
self.cram_rgb[address] = cram_to_rgb(value as _);
|
||||
},
|
||||
VDPType::VSRAM => {
|
||||
self.VSRAM[((self.control_address & 0x7f) >> 1) as usize] = value as _;
|
||||
|
|
|
@ -160,7 +160,7 @@ impl eframe::App for Frontend {
|
|||
|
||||
egui::Window::new("palette")
|
||||
.show(ctx, |ui| {
|
||||
let pixels = self.emu.core.mem.vdp.cram_rgb().iter()
|
||||
let pixels = self.emu.core.mem.vdp.cram_rgb.iter()
|
||||
.map(|&(r, g, b)| egui::Color32::from_rgb(r, g, b))
|
||||
.collect();
|
||||
let texture: &egui::TextureHandle = &ui.ctx().load_texture(
|
||||
|
@ -178,26 +178,26 @@ impl eframe::App for Frontend {
|
|||
|
||||
egui::Window::new("vram")
|
||||
.show(ctx, |ui| {
|
||||
let mut pixels = vec![];
|
||||
for duxel in &self.emu.core.mem.vdp.VRAM[0..64] {
|
||||
let pixel = (*duxel & 0xF0) >> 4;
|
||||
let color = self.emu.core.mem.vdp.color(0, pixel as _);
|
||||
pixels.push(egui::Color32::from_rgb(color.0, color.1, color.2));
|
||||
let pixel = *duxel & 0xF;
|
||||
let color = self.emu.core.mem.vdp.color(0, pixel as _);
|
||||
pixels.push(egui::Color32::from_rgb(color.0, color.1, color.2));
|
||||
}
|
||||
let texture: &egui::TextureHandle = &ui.ctx().load_texture(
|
||||
"palette",
|
||||
egui::ColorImage {
|
||||
size: [8, 8* 2],
|
||||
pixels,
|
||||
},
|
||||
egui::TextureFilter::Nearest
|
||||
);
|
||||
let img = egui::Image::new(texture, texture.size_vec2() * 20.);
|
||||
// let mut pixels = vec![];
|
||||
// for duxel in &self.emu.core.mem.vdp.VRAM[0..64] {
|
||||
// let pixel = (*duxel & 0xF0) >> 4;
|
||||
// let color = self.emu.core.mem.vdp.color(0, pixel as _);
|
||||
// pixels.push(egui::Color32::from_rgb(color.0, color.1, color.2));
|
||||
// let pixel = *duxel & 0xF;
|
||||
// let color = self.emu.core.mem.vdp.color(0, pixel as _);
|
||||
// pixels.push(egui::Color32::from_rgb(color.0, color.1, color.2));
|
||||
// }
|
||||
// let texture: &egui::TextureHandle = &ui.ctx().load_texture(
|
||||
// "palette",
|
||||
// egui::ColorImage {
|
||||
// size: [8, 8* 2],
|
||||
// pixels,
|
||||
// },
|
||||
// egui::TextureFilter::Nearest
|
||||
// );
|
||||
// let img = egui::Image::new(texture, texture.size_vec2() * 20.);
|
||||
|
||||
ui.add(img);
|
||||
// ui.add(img);
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
|
|
Loading…
Reference in a new issue