Compare commits
No commits in common. "fd5006b29d0d749261d4e111c9727395e91eb84f" and "7d79a0bee2a4662cf1e7cd711ff02da69173451d" have entirely different histories.
fd5006b29d
...
7d79a0bee2
|
@ -8,57 +8,48 @@ pub fn blockDataTransfer(comptime P: bool, comptime U: bool, comptime S: bool, c
|
||||||
return struct {
|
return struct {
|
||||||
fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u32) void {
|
fn inner(cpu: *Arm7tdmi, bus: *Bus, opcode: u32) void {
|
||||||
const rn = opcode >> 16 & 0xF;
|
const rn = opcode >> 16 & 0xF;
|
||||||
const base = cpu.r[rn];
|
var base = cpu.r[rn];
|
||||||
|
|
||||||
if (S and opcode >> 15 & 1 == 0) std.debug.panic("[CPU] TODO: STM/LDM with S set but R15 not in transfer list", .{});
|
// TODO: For Performance (?) if U we got from 0 -> 0xF, if !U, 0xF -> 0
|
||||||
|
// we can do this and have it be fast because of comptime, baby!
|
||||||
if (U) {
|
|
||||||
// Increment
|
|
||||||
var address = if (P) base + 4 else base;
|
|
||||||
|
|
||||||
|
if (!U) {
|
||||||
|
var count: u32 = 0;
|
||||||
var i: u5 = 0;
|
var i: u5 = 0;
|
||||||
while (i < 0x10) : (i += 1) {
|
while (i < 0x10) : (i += 1) {
|
||||||
if (opcode >> i & 1 == 1) {
|
count += opcode >> i & 1;
|
||||||
transfer(cpu, bus, i, address);
|
|
||||||
address += 4;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (W and P or !P) cpu.r[rn] = address - 4;
|
base -= count * 4;
|
||||||
} else {
|
|
||||||
// Decrement
|
|
||||||
var address = if (P) base - 4 else base;
|
|
||||||
|
|
||||||
var i: u5 = 0x10;
|
|
||||||
while (i > 0) : (i -= 1) {
|
|
||||||
const reg_idx = i - 1;
|
|
||||||
|
|
||||||
if (opcode >> reg_idx & 1 == 1) {
|
|
||||||
transfer(cpu, bus, reg_idx, address);
|
|
||||||
address -= 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (W and P or !P) cpu.r[rn] = address + 4;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn transfer(cpu: *Arm7tdmi, bus: *Bus, i: u5, address: u32) void {
|
var address = if (@boolToInt(P) ^ @boolToInt(U) == 0) base + 4 else base;
|
||||||
if (L) {
|
if (S and opcode >> 15 & 1 == 0) std.debug.panic("[CPU] TODO: STM/LDM with S set but R15 not in transfer list", .{});
|
||||||
cpu.r[i] = bus.read32(address);
|
|
||||||
if (S and i == 0xF) std.debug.panic("[CPU] TODO: SPSR_<mode> is transferred to CPSR", .{});
|
var i: u5 = 0;
|
||||||
} else {
|
while (i < 0x10) : (i += 1) {
|
||||||
if (i == 0xF) {
|
if (opcode >> i & 1 == 1) {
|
||||||
if (!S) {
|
if (L) {
|
||||||
// TODO: Assure that this is Address of STM instruction + 12
|
cpu.r[i] = bus.read32(address);
|
||||||
bus.write32(address, cpu.r[i] + (12 - 4));
|
if (S and i == 0xF) std.debug.panic("[CPU] TODO: SPSR_<mode> is transferred to CPSR", .{});
|
||||||
} else {
|
} else {
|
||||||
std.debug.panic("[CPU] TODO: STM with S set and R15 in transfer list", .{});
|
if (i == 0xF) {
|
||||||
|
if (!S) {
|
||||||
|
// TODO: Assure that this is Address of STM instruction + 12
|
||||||
|
bus.write32(address, cpu.r[i] + (12 - 4));
|
||||||
|
} else {
|
||||||
|
std.debug.panic("[CPU] TODO: STM with S set and R15 in transfer list", .{});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bus.write32(address, cpu.r[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
bus.write32(address, cpu.r[i]);
|
address += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (W and P or !P) cpu.r[rn] = if (U) address - 4 else base;
|
||||||
}
|
}
|
||||||
}.inner;
|
}.inner;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,16 +53,18 @@ pub const Ppu = struct {
|
||||||
const frame_select = io.dispcnt.frame_select.read();
|
const frame_select = io.dispcnt.frame_select.read();
|
||||||
|
|
||||||
const fb_start = buf_pitch * @as(usize, scanline);
|
const fb_start = buf_pitch * @as(usize, scanline);
|
||||||
const vram_start = fb_start >> 1;
|
const vram_start = width * @as(usize, scanline);
|
||||||
|
|
||||||
const start = if (frame_select) 0xA000 + vram_start else vram_start;
|
const start = if (frame_select) 0xA000 + vram_start else vram_start;
|
||||||
const end = start + width;
|
const end = start + width;
|
||||||
|
|
||||||
for (self.vram.buf[start..end]) |byte, i| {
|
for (self.vram.buf[start..end]) |byte, i| {
|
||||||
const fb_i = i * @sizeOf(u16);
|
const fb_i = i * @sizeOf(u16);
|
||||||
|
const colour = self.palette.buf[byte];
|
||||||
|
var bgr555: u16 = colour & 0x3 | (colour & 0x1C >> 2) << 5 | @as(u16, colour >> 5) << 10;
|
||||||
|
|
||||||
self.frame_buf[fb_start + fb_i + 1] = self.palette.buf[byte + 1];
|
self.frame_buf[fb_start + fb_i + 1] = @truncate(u8, bgr555 >> 8);
|
||||||
self.frame_buf[fb_start + fb_i] = self.palette.buf[byte];
|
self.frame_buf[fb_start + fb_i] = @truncate(u8, bgr555);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}),
|
else => std.debug.panic("[PPU] TODO: Implement BG Mode {}", .{bg_mode}),
|
||||||
|
|
Loading…
Reference in New Issue