mirror of
https://github.com/kirjavascript/trueLMAO.git
synced 2024-06-02 19:47:21 -04:00
some screen primitives
This commit is contained in:
parent
e996c1fc4b
commit
b2b708873b
|
@ -37,7 +37,6 @@ fn main() {
|
|||
let mut vrambuf: Vec<u8> = vec![0xFF; (256 * 513 * 3) as usize];
|
||||
|
||||
let mut screen = Frame::new(0, 350, 320, 240, "");
|
||||
let mut screenbuf: Vec<u8> = vec![0xFF; (320 * 240 * 3) as usize];
|
||||
|
||||
wind.end();
|
||||
wind.show();
|
||||
|
@ -45,7 +44,7 @@ fn main() {
|
|||
unsafe {
|
||||
draw::draw_rgb_nocopy(&mut pal, &palbuf);
|
||||
draw::draw_rgb_nocopy(&mut vram, &vrambuf);
|
||||
draw::draw_rgb_nocopy(&mut screen, &screenbuf);
|
||||
draw::draw_rgb_nocopy(&mut screen, &emu.screen);
|
||||
}
|
||||
|
||||
pal.set_size(160,40);
|
||||
|
@ -94,7 +93,6 @@ fn main() {
|
|||
|
||||
if running {
|
||||
emu.frame();
|
||||
|
||||
}
|
||||
let mut debug = String::new();
|
||||
debug.push_str(&format!("PC: {:X}\n\n", emu.core.pc));
|
||||
|
@ -164,18 +162,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
// render screen
|
||||
|
||||
let bg_color = emu.core.mem.vdp.bg_color();
|
||||
|
||||
// clear screen
|
||||
for pixel in screenbuf.chunks_mut(3) {
|
||||
pixel[0] = bg_color.0;
|
||||
pixel[1] = bg_color.1;
|
||||
pixel[2] = bg_color.2;
|
||||
};
|
||||
|
||||
|
||||
wind.redraw();
|
||||
|
||||
app::sleep(0.016);
|
||||
|
|
117
emu/src/lib.rs
117
emu/src/lib.rs
|
@ -9,6 +9,7 @@ mod z80;
|
|||
|
||||
pub struct Megadrive {
|
||||
pub core: ConfiguredCore<AutoInterruptController, mem::Mem>,
|
||||
pub screen: [u8; 320 * 240 * 3],
|
||||
}
|
||||
|
||||
impl Megadrive {
|
||||
|
@ -22,6 +23,7 @@ impl Megadrive {
|
|||
|
||||
Megadrive {
|
||||
core,
|
||||
screen: [0; 320 * 240 * 3],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -31,57 +33,6 @@ impl Megadrive {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn frame(&mut self) {
|
||||
// https://segaretro.org/Sega_Mega_Drive/Technical_specifications#Graphics
|
||||
|
||||
self.core.mem.vdp.unset_status(vdp::VBLANK_MASK);
|
||||
|
||||
self.core.mem.vdp.unset_status(128);
|
||||
|
||||
let screen_height = self.core.mem.vdp.screen_height();
|
||||
let mut hint_counter = self.core.mem.vdp.hint_counter();
|
||||
for _ in 0..screen_height {
|
||||
self.core.execute(2680);
|
||||
|
||||
hint_counter -= 1;
|
||||
if hint_counter < 0 {
|
||||
hint_counter = self.core.mem.vdp.hint_counter();
|
||||
|
||||
if self.core.mem.vdp.registers[0] & 0x10 > 0 {
|
||||
self.core.int_ctrl.request_interrupt(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.core.mem.vdp.set_status(vdp::HBLANK_MASK);
|
||||
self.core.execute(636);
|
||||
self.core.mem.vdp.unset_status(vdp::HBLANK_MASK);
|
||||
|
||||
self.core.execute(104);
|
||||
|
||||
// render
|
||||
}
|
||||
|
||||
self.core.mem.vdp.set_status(vdp::VBLANK_MASK);
|
||||
|
||||
self.core.execute(588);
|
||||
|
||||
self.core.mem.vdp.status |= 0x80;
|
||||
|
||||
self.core.execute(200);
|
||||
|
||||
if self.core.mem.vdp.registers[1] & 0x20 > 0 {
|
||||
self.core.int_ctrl.request_interrupt(6);
|
||||
self.core.mem.vdp.set_status(128);
|
||||
}
|
||||
|
||||
self.core.execute(3420-788);
|
||||
|
||||
for _ in screen_height..262 {
|
||||
self.core.execute(3420);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn disasm(&self) -> Vec<(u32, String)> {
|
||||
use r68k_tools::PC;
|
||||
let mut buffer = Vec::new();
|
||||
|
@ -102,4 +53,68 @@ impl Megadrive {
|
|||
|
||||
opcodes
|
||||
}
|
||||
|
||||
pub fn frame(&mut self) {
|
||||
self.clear_screen();
|
||||
|
||||
self.core.mem.vdp.unset_status(vdp::VBLANK_MASK);
|
||||
|
||||
self.core.mem.vdp.unset_status(128);
|
||||
|
||||
let screen_height = self.core.mem.vdp.screen_height();
|
||||
let mut hint_counter = self.core.mem.vdp.hint_counter();
|
||||
for line in 0..screen_height {
|
||||
self.core.execute(2680);
|
||||
|
||||
hint_counter -= 1;
|
||||
if hint_counter < 0 {
|
||||
hint_counter = self.core.mem.vdp.hint_counter();
|
||||
|
||||
if self.core.mem.vdp.registers[0] & 0x10 > 0 {
|
||||
self.core.int_ctrl.request_interrupt(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
self.core.mem.vdp.set_status(vdp::HBLANK_MASK);
|
||||
self.core.execute(636);
|
||||
self.core.mem.vdp.unset_status(vdp::HBLANK_MASK);
|
||||
|
||||
self.core.execute(104);
|
||||
|
||||
self.render_line(line);
|
||||
}
|
||||
|
||||
self.core.mem.vdp.set_status(vdp::VBLANK_MASK);
|
||||
|
||||
self.core.execute(588);
|
||||
|
||||
self.core.mem.vdp.status |= 0x80;
|
||||
|
||||
self.core.execute(200);
|
||||
|
||||
if self.core.mem.vdp.registers[1] & 0x20 > 0 {
|
||||
self.core.int_ctrl.request_interrupt(6);
|
||||
self.core.mem.vdp.set_status(128);
|
||||
}
|
||||
|
||||
self.core.execute(3420-788);
|
||||
|
||||
for _ in screen_height..262 {
|
||||
self.core.execute(3420);
|
||||
}
|
||||
}
|
||||
|
||||
fn clear_screen(&mut self) {
|
||||
let bg_color = self.core.mem.vdp.bg_color();
|
||||
for pixel in self.screen.chunks_mut(3) {
|
||||
pixel[0] = bg_color.0;
|
||||
pixel[1] = bg_color.1;
|
||||
pixel[2] = bg_color.2;
|
||||
};
|
||||
}
|
||||
|
||||
fn render_line(&mut self, line: usize) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,13 +95,16 @@ impl VDP {
|
|||
|
||||
pub fn plane_size(&self) -> (u8, u8) {
|
||||
let to_cells = |size| 32 + (size * 32);
|
||||
|
||||
(
|
||||
to_cells(self.registers[0x10] & 3),
|
||||
to_cells((self.registers[0x10] >> 4) & 3),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn hscroll_addr(&self) -> usize {
|
||||
(self.registers[0xD] as usize & 0b111111) << 10
|
||||
}
|
||||
|
||||
pub fn read(&self, mut address: u32) -> u32 {
|
||||
address &= 0x1F;
|
||||
|
||||
|
|
Loading…
Reference in a new issue