Compare commits
13 Commits
bf351b39e2
...
f715585867
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | f715585867 | |
Rekai Nyangadzayi Musuka | cab40efc59 | |
Rekai Nyangadzayi Musuka | a17300a8e0 | |
Rekai Nyangadzayi Musuka | 2ebe1c0b0e | |
Rekai Nyangadzayi Musuka | 6db70638fe | |
Rekai Nyangadzayi Musuka | bc5ab5810a | |
Rekai Nyangadzayi Musuka | decf2a01c9 | |
Rekai Nyangadzayi Musuka | 4b8ed3cebb | |
Rekai Nyangadzayi Musuka | 928ce674d9 | |
Rekai Nyangadzayi Musuka | 945dbec013 | |
Rekai Nyangadzayi Musuka | dd98066a34 | |
Rekai Nyangadzayi Musuka | a2868dfe9e | |
Rekai Nyangadzayi Musuka | 22979d9450 |
|
@ -169,7 +169,7 @@ fn openBus(self: *const Self, comptime T: type, address: u32) T {
|
|||
}
|
||||
};
|
||||
|
||||
return @truncate(T, rotr(u32, word, 8 * (address & 3)));
|
||||
return @truncate(T, word);
|
||||
}
|
||||
|
||||
pub fn read(self: *Self, comptime T: type, address: u32) T {
|
||||
|
|
|
@ -19,7 +19,7 @@ pub fn read(self: *Self, comptime T: type, r15: u32, addr: u32) T {
|
|||
}
|
||||
|
||||
log.debug("Rejected read since r15=0x{X:0>8}", .{r15});
|
||||
return @truncate(T, self._read(T, self.addr_latch + 8));
|
||||
return @truncate(T, self._read(T, self.addr_latch));
|
||||
}
|
||||
|
||||
pub fn dbgRead(self: *const Self, comptime T: type, r15: u32, addr: u32) T {
|
||||
|
|
|
@ -11,6 +11,8 @@ const log = std.log.scoped(.DmaTransfer);
|
|||
const setHi = util.setHi;
|
||||
const setLo = util.setLo;
|
||||
|
||||
const rotr = @import("../../util.zig").rotr;
|
||||
|
||||
pub fn create() DmaTuple {
|
||||
return .{ DmaController(0).init(), DmaController(1).init(), DmaController(2).init(), DmaController(3).init() };
|
||||
}
|
||||
|
@ -99,6 +101,7 @@ fn DmaController(comptime id: u2) type {
|
|||
|
||||
const sad_mask: u32 = if (id == 0) 0x07FF_FFFF else 0x0FFF_FFFF;
|
||||
const dad_mask: u32 = if (id != 3) 0x07FF_FFFF else 0x0FFF_FFFF;
|
||||
const WordCount = if (id == 3) u16 else u14;
|
||||
|
||||
/// Write-only. The first address in a DMA transfer. (DMASAD)
|
||||
/// Note: use writeSrc instead of manipulating src_addr directly
|
||||
|
@ -107,17 +110,19 @@ fn DmaController(comptime id: u2) type {
|
|||
/// Note: Use writeDst instead of manipulatig dst_addr directly
|
||||
dad: u32,
|
||||
/// Write-only. The Word Count for the DMA Transfer (DMACNT_L)
|
||||
word_count: if (id == 3) u16 else u14,
|
||||
word_count: WordCount,
|
||||
/// Read / Write. DMACNT_H
|
||||
/// Note: Use writeControl instead of manipulating cnt directly.
|
||||
cnt: DmaControl,
|
||||
|
||||
/// Internal. The last successfully read value
|
||||
data_latch: u32,
|
||||
/// Internal. Currrent Source Address
|
||||
sad_latch: u32,
|
||||
/// Internal. Current Destination Address
|
||||
dad_latch: u32,
|
||||
/// Internal. Word Count
|
||||
_word_count: if (id == 3) u16 else u14,
|
||||
_word_count: WordCount,
|
||||
|
||||
/// Some DMA Transfers are enabled during Hblank / VBlank and / or
|
||||
/// have delays. Thefore bit 15 of DMACNT isn't actually something
|
||||
|
@ -134,6 +139,8 @@ fn DmaController(comptime id: u2) type {
|
|||
// Internals
|
||||
.sad_latch = 0,
|
||||
.dad_latch = 0,
|
||||
.data_latch = 0,
|
||||
|
||||
._word_count = 0,
|
||||
.in_progress = false,
|
||||
};
|
||||
|
@ -158,7 +165,7 @@ fn DmaController(comptime id: u2) type {
|
|||
// Reload Internals on Rising Edge.
|
||||
self.sad_latch = self.sad;
|
||||
self.dad_latch = self.dad;
|
||||
self._word_count = if (self.word_count == 0) std.math.maxInt(@TypeOf(self._word_count)) else self.word_count;
|
||||
self._word_count = if (self.word_count == 0) std.math.maxInt(WordCount) else self.word_count;
|
||||
|
||||
// Only a Start Timing of 00 has a DMA Transfer immediately begin
|
||||
self.in_progress = new.start_timing.read() == 0b00;
|
||||
|
@ -181,11 +188,19 @@ fn DmaController(comptime id: u2) type {
|
|||
const offset: u32 = if (transfer_type) @sizeOf(u32) else @sizeOf(u16);
|
||||
|
||||
const mask = if (transfer_type) ~@as(u32, 3) else ~@as(u32, 1);
|
||||
const sad_addr = self.sad_latch & mask;
|
||||
const dad_addr = self.dad_latch & mask;
|
||||
|
||||
if (transfer_type) {
|
||||
cpu.bus.write(u32, self.dad_latch & mask, cpu.bus.read(u32, self.sad_latch & mask));
|
||||
if (sad_addr >= 0x0200_0000) self.data_latch = cpu.bus.read(u32, sad_addr);
|
||||
cpu.bus.write(u32, dad_addr, self.data_latch);
|
||||
} else {
|
||||
cpu.bus.write(u16, self.dad_latch & mask, cpu.bus.read(u16, self.sad_latch & mask));
|
||||
if (sad_addr >= 0x0200_0000) {
|
||||
const value: u32 = cpu.bus.read(u16, sad_addr);
|
||||
self.data_latch = value << 16 | value;
|
||||
}
|
||||
|
||||
cpu.bus.write(u16, dad_addr, @truncate(u16, rotr(u32, self.data_latch, 8 * (dad_addr & 3))));
|
||||
}
|
||||
|
||||
switch (sad_adj) {
|
||||
|
|
|
@ -11,8 +11,8 @@ const Bus = @import("../Bus.zig");
|
|||
const DmaController = @import("dma.zig").DmaController;
|
||||
const Scheduler = @import("../scheduler.zig").Scheduler;
|
||||
|
||||
const setHi = util.setLo;
|
||||
const setLo = util.setHi;
|
||||
const setHi = util.setHi;
|
||||
const setLo = util.setLo;
|
||||
|
||||
const log = std.log.scoped(.@"I/O");
|
||||
|
||||
|
|
|
@ -35,11 +35,8 @@ pub fn halfAndSignedDataTransfer(comptime P: bool, comptime U: bool, comptime I:
|
|||
},
|
||||
0b11 => {
|
||||
// LDRSH
|
||||
result = if (address & 1 == 1) blk: {
|
||||
break :blk sext(u32, u8, bus.read(u8, address));
|
||||
} else blk: {
|
||||
break :blk sext(u32, u16, bus.read(u16, address));
|
||||
};
|
||||
const value = bus.read(u16, address);
|
||||
result = if (address & 1 == 1) sext(u32, u8, @truncate(u8, value >> 8)) else sext(u32, u16, value);
|
||||
},
|
||||
0b00 => unreachable, // SWP
|
||||
}
|
||||
|
|
|
@ -46,11 +46,8 @@ pub fn fmt78(comptime op: u2, comptime T: bool) InstrFn {
|
|||
},
|
||||
0b11 => {
|
||||
// LDRSH
|
||||
cpu.r[rd] = if (address & 1 == 1) blk: {
|
||||
break :blk sext(u32, u8, bus.read(u8, address));
|
||||
} else blk: {
|
||||
break :blk sext(u32, u16, bus.read(u16, address));
|
||||
};
|
||||
const value = bus.read(u16, address);
|
||||
cpu.r[rd] = if (address & 1 == 1) sext(u32, u8, @truncate(u8, value >> 8)) else sext(u32, u16, value);
|
||||
},
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -276,7 +276,7 @@ pub const audio = struct {
|
|||
};
|
||||
|
||||
/// Sets the high bits of an integer to a value
|
||||
pub inline fn setHi(comptime T: type, left: T, right: HalfInt(T)) T {
|
||||
pub inline fn setLo(comptime T: type, left: T, right: HalfInt(T)) T {
|
||||
return switch (T) {
|
||||
u32 => (left & 0xFFFF_0000) | right,
|
||||
u16 => (left & 0xFF00) | right,
|
||||
|
@ -286,7 +286,7 @@ pub inline fn setHi(comptime T: type, left: T, right: HalfInt(T)) T {
|
|||
}
|
||||
|
||||
/// sets the low bits of an integer to a value
|
||||
pub inline fn setLo(comptime T: type, left: T, right: HalfInt(T)) T {
|
||||
pub inline fn setHi(comptime T: type, left: T, right: HalfInt(T)) T {
|
||||
return switch (T) {
|
||||
u32 => (left & 0x0000_FFFF) | @as(u32, right) << 16,
|
||||
u16 => (left & 0x00FF) | @as(u16, right) << 8,
|
||||
|
|
Loading…
Reference in New Issue