Skip to content

Commit

Permalink
[graphics] MERC (#1124)
Browse files Browse the repository at this point in the history
* merc dma generation

* wip very early version of merc

* small fixes

* fix

* fix more merc bugs

* derp fixed min

* oops we did need something weird on max

* merc for everything

* program optimization 1

* more optimization

* windows

* windows 2

* clean up

* fix test

* BLERC
  • Loading branch information
water111 authored Feb 4, 2022
1 parent 3d7228e commit 2342b6f
Show file tree
Hide file tree
Showing 41 changed files with 8,810 additions and 110 deletions.
5 changes: 2 additions & 3 deletions common/dma/dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ std::string VifCode::print() {
result = "FLUSHA";
break;
case Kind::MSCAL:
result = "MSCAL";
result = fmt::format("MSCAL 0x{:x}", immediate);
break;
case Kind::MSCNT:
result = "MSCNT";
Expand Down Expand Up @@ -109,10 +109,9 @@ std::string VifCode::print() {

default:
fmt::print("Unhandled vif code {}\n", (int)kind);
assert(false);

result = "???";
// assert(false);
assert(false);
break;
}
// TODO: the rest of the VIF code.
Expand Down
42 changes: 42 additions & 0 deletions common/dma/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,48 @@ struct DmaTag {
std::string print();
};

inline void emulate_dma(const void* source_base, void* dest_base, u32 tadr, u32 dadr) {
const u8* src = (const u8*)source_base;
u8* dst = (u8*)dest_base;

u32 dest_offset = dadr;
while (true) {
u64 tag_data;
memcpy(&tag_data, src + tadr, 8);
DmaTag tag(tag_data);

switch (tag.kind) {
case DmaTag::Kind::CNT:
memcpy(dst + dest_offset, src + tadr, (1 + tag.qwc) * 16);
dest_offset += (1 + tag.qwc) * 16;
tadr += 16 + tag.qwc * 16;
break;
case DmaTag::Kind::REF: {
// tte
memcpy(dst + dest_offset, src + tadr, 16);
dest_offset += 16;

memcpy(dst + dest_offset, src + tag.addr, tag.qwc * 16);
dest_offset += tag.qwc * 16;
tadr += 16;
} break;
case DmaTag::Kind::REFE: {
// tte
memcpy(dst + dest_offset, src + tadr, 16);
dest_offset += 16;

memcpy(dst + dest_offset, src + tag.addr, tag.qwc * 16);
dest_offset += tag.qwc * 16;
tadr += 16;
return;
} break;
default:
printf("bad tag: %d\n", (int)tag.kind);
assert(false);
}
}
}

struct VifCode {
enum class Kind : u8 {
NOP = 0b0,
Expand Down
Loading

0 comments on commit 2342b6f

Please sign in to comment.