add virtual rendering to VRAM

This commit is contained in:
kirjavascript 2023-03-08 23:30:55 +00:00
parent 97cc03e3f1
commit 08f37d6641
2 changed files with 43 additions and 39 deletions

View file

@ -5,11 +5,12 @@
# windows
CROSS_CONTAINER_ENGINE=podman
cross build --release --target x86_64-pc-windows-gnu
cross build --release --target i686-pc-windows-gnu
mv ../target/x86_64-pc-windows-gnu/release/frontend_bin.exe
cross clean
# appimage
cargo appimage
# web
sh build.sh
# cross clean

View file

@ -13,9 +13,6 @@ impl Default for VRAM {
impl VRAM {
pub fn render(&mut self, ctx: &egui::Context, emu: &emu::Megadrive) {
egui::Window::new("vram")
.vscroll(true)
// TODO: only show onscreen ram"
// TODO: show_rows
.show(ctx, |ui| {
ui.horizontal(|ui| {
ui.radio_value(&mut self.palette_line, 0, "0");
@ -24,48 +21,54 @@ impl VRAM {
ui.radio_value(&mut self.palette_line, 3, "3");
});
const WIDTH: usize = 16;
const HEIGHT: usize = 128;
const PIXEL_QTY: usize = (WIDTH * 8) * (HEIGHT * 8);
// TODO use retained buffer
let mut pixels: [egui::Color32; PIXEL_QTY] = [ egui::Color32::from_rgb(0, 0, 0); PIXEL_QTY];
const WIDTH: usize = 16; // tiles
const HEIGHT: usize = 128; // tiles
let palette_offset = self.palette_line * 0x10;
for x_tile in 0..WIDTH {
for y_tile in 0..HEIGHT {
let offset = x_tile + (y_tile * WIDTH);
let vram_offset = offset * 32;
let mut view_offset = (x_tile * 8) + (y_tile * 8 * (WIDTH * 8));
egui::ScrollArea::vertical()
.max_height(512.)
.show_rows(ui, 8., HEIGHT, |ui, row_range| {
let std::ops::Range { start, end } = row_range;
let pixel_qty = (WIDTH*8)*((end - start)*8);
let mut pixels = vec![egui::Color32::from_rgb(0, 0, 0); pixel_qty];
for duxel in &emu.core.mem.vdp.VRAM[vram_offset..vram_offset+32] {
let pixel = (*duxel & 0xF0) >> 4;
let palette_offset = self.palette_line * 0x10;
for x_tile in 0..WIDTH {
for y_tile in start..end {
let offset = x_tile + (y_tile * WIDTH);
let vram_offset = offset * 32;
let mut view_offset = (x_tile * 8) + ((y_tile-start) * 8 * (WIDTH * 8));
for duxel in &emu.core.mem.vdp.VRAM[vram_offset..vram_offset+32] {
let pixel = (*duxel & 0xF0) >> 4;
let (r, g, b) = emu.core.mem.vdp.cram_rgb[palette_offset + pixel as usize];
pixels[view_offset] = egui::Color32::from_rgb(r, g, b);
view_offset += 1;
let pixel = *duxel & 0xF;
let (r, g, b) = emu.core.mem.vdp.cram_rgb[palette_offset + pixel as usize];
pixels[view_offset] = egui::Color32::from_rgb(r, g, b);
view_offset += 1;
if view_offset % 8 == 0 {
view_offset += (WIDTH-1) * 8;
}
}
let (r, g, b) = emu.core.mem.vdp.cram_rgb[palette_offset + pixel as usize];
pixels[view_offset] = egui::Color32::from_rgb(r, g, b);
view_offset += 1;
let pixel = *duxel & 0xF;
let (r, g, b) = emu.core.mem.vdp.cram_rgb[palette_offset + pixel as usize];
pixels[view_offset] = egui::Color32::from_rgb(r, g, b);
view_offset += 1;
if view_offset % 8 == 0 {
view_offset += (WIDTH-1) * 8;
}
}
}
}
let texture: &egui::TextureHandle = &ui.ctx().load_texture(
"vram",
egui::ColorImage {
size: [WIDTH*8, (end - start) * 8],
pixels: pixels.to_vec(),
},
egui::TextureOptions::NEAREST
);
let img = egui::Image::new(texture, texture.size_vec2() * 2.);
let texture: &egui::TextureHandle = &ui.ctx().load_texture(
"vram",
egui::ColorImage {
size: [WIDTH*8, HEIGHT*8],
pixels: pixels.to_vec(),
},
egui::TextureOptions::NEAREST
);
let img = egui::Image::new(texture, texture.size_vec2() * 2.);
ui.add(img);
});
ui.add(img);
});
}
}