Fixed hscroll issue (vscroll and hscroll were backwards)

This commit is contained in:
transistor 2021-12-26 19:45:45 -08:00
parent 10ca0c7995
commit ac9ec8840c
2 changed files with 22 additions and 21 deletions

View File

@ -216,7 +216,12 @@ before 2021-10-25
- so far I'm suspecting the DIV followed by the EXTW at 0xc62a might be doing something incorrect, - so far I'm suspecting the DIV followed by the EXTW at 0xc62a might be doing something incorrect,
and then when it adds the result in %d0 to %d3 before using that as the scroll value, it's adding and then when it adds the result in %d0 to %d3 before using that as the scroll value, it's adding
too large a value (that should have been cut off to a word) too large a value (that should have been cut off to a word)
- there was indeed a problem with the div. It's a signed div but the division was unsigned. Now
the scroll values look about right, but the black glitches are still there
- turns out it was that the scroll values were inverted. The hscroll values are supposed to be the
offset *per line*, so you use the same hscroll value for every line. It's the vscroll value that
has to be looked up for ever column, so swapping the vscroll and hscroll between the inner and
outer loops fixed the issue perfectly. Kind of odd that it wasn't more broken when inverted

View File

@ -321,7 +321,7 @@ impl Ym7101State {
PatternIterator::new(&self, pattern_addr as u32, pattern_palette, h_rev, v_rev, line) PatternIterator::new(&self, pattern_addr as u32, pattern_palette, h_rev, v_rev, line)
} }
pub fn get_hscroll(&self, hcell: usize, column: usize) -> (u32, u32) { pub fn get_hscroll(&self, hcell: usize, line: usize) -> (u32, u32) {
let base_addr = match self.mode_3 & MODE3_BF_H_SCROLL_MODE { let base_addr = match self.mode_3 & MODE3_BF_H_SCROLL_MODE {
0 => self.hscroll_addr, 0 => self.hscroll_addr,
2 => self.hscroll_addr + (hcell << 4), 2 => self.hscroll_addr + (hcell << 4),
@ -329,7 +329,7 @@ impl Ym7101State {
_ => panic!("Unsupported horizontal scroll mode"), _ => panic!("Unsupported horizontal scroll mode"),
}; };
let scroll_addr = base_addr + (column * 2 * 2); let scroll_addr = base_addr + (line * 2 * 2);
let scroll_a = read_beu16(&self.vram[scroll_addr..]) as u32 & 0x3FF; let scroll_a = read_beu16(&self.vram[scroll_addr..]) as u32 & 0x3FF;
let scroll_b = read_beu16(&self.vram[scroll_addr + 2..]) as u32 & 0x3FF; let scroll_b = read_beu16(&self.vram[scroll_addr + 2..]) as u32 & 0x3FF;
(scroll_a, scroll_b) (scroll_a, scroll_b)
@ -402,9 +402,9 @@ impl Ym7101State {
let (cells_h, cells_v) = self.screen_size; let (cells_h, cells_v) = self.screen_size;
for cell_y in 0..cells_v { for cell_y in 0..cells_v {
let (vscrolling_a, vscrolling_b) = self.get_vscroll(cell_y); let (hscrolling_a, hscrolling_b) = self.get_hscroll(cell_y, 0);
for cell_x in 0..cells_h { for cell_x in 0..cells_h {
let (hscrolling_a, hscrolling_b) = self.get_hscroll(cell_x, 0); let (vscrolling_a, vscrolling_b) = self.get_vscroll(cell_x);
let pattern_b = self.get_scroll_b_pattern(cell_x, cell_y, hscrolling_b as usize, vscrolling_b as usize); let pattern_b = self.get_scroll_b_pattern(cell_x, cell_y, hscrolling_b as usize, vscrolling_b as usize);
let pattern_a = self.get_scroll_a_pattern(cell_x, cell_y, hscrolling_a as usize, vscrolling_a as usize); let pattern_a = self.get_scroll_a_pattern(cell_x, cell_y, hscrolling_a as usize, vscrolling_a as usize);
@ -420,29 +420,25 @@ impl Ym7101State {
let (cells_h, cells_v) = self.screen_size; let (cells_h, cells_v) = self.screen_size;
for cell_y in 0..cells_v { for cell_y in 0..cells_v {
let (vscrolling_a, vscrolling_b) = self.get_vscroll(cell_y); for line in 0..8 {
let (_, hscrolling_b) = self.get_hscroll(cell_y, line as usize);
for cell_x in 0..cells_h { for cell_x in 0..cells_h {
let (hscrolling_a, hscrolling_b) = self.get_hscroll(cell_x, 0); let (_, vscrolling_b) = self.get_vscroll(cell_x);
let pattern_b = self.get_scroll_b_pattern(cell_x, cell_y, hscrolling_b as usize, vscrolling_b as usize); let pattern_b = self.get_scroll_b_pattern(cell_x, cell_y, hscrolling_b as usize, vscrolling_b as usize);
self.draw_pattern_line(frame, pattern_b, (cell_x << 3) as u32 + (hscrolling_b % 8), (cell_y << 3) as u32 + line as u32 - (vscrolling_b % 8), line);
for line in 0..8 {
let (_, offset_b) = self.get_hscroll(cell_x, line as usize);
self.draw_pattern_line(frame, pattern_b, (cell_x << 3) as u32 + (offset_b % 8), (cell_y << 3) as u32 + line as u32 - (vscrolling_b % 8), line);
} }
} }
} }
for cell_y in 0..cells_v { for cell_y in 0..cells_v {
let (vscrolling_a, vscrolling_b) = self.get_vscroll(cell_y); for line in 0..8 {
let (hscrolling_a, _) = self.get_hscroll(cell_y, line as usize);
for cell_x in 0..cells_h { for cell_x in 0..cells_h {
let (hscrolling_a, hscrolling_b) = self.get_hscroll(cell_x, 0); let (vscrolling_a, _) = self.get_vscroll(cell_x);
let pattern_a = self.get_scroll_a_pattern(cell_x, cell_y, hscrolling_a as usize, vscrolling_a as usize); let pattern_a = self.get_scroll_a_pattern(cell_x, cell_y, hscrolling_a as usize, vscrolling_a as usize);
self.draw_pattern_line(frame, pattern_a, (cell_x << 3) as u32 + (hscrolling_a % 8), (cell_y << 3) as u32 + line as u32 - (vscrolling_a % 8), line);
for line in 0..8 {
let (offset_a, _) = self.get_hscroll(cell_x, line as usize);
self.draw_pattern_line(frame, pattern_a, (cell_x << 3) as u32 + (offset_a % 8), (cell_y << 3) as u32 + line as u32 - (vscrolling_a % 8), line);
} }
} }
} }