decomp decomp

This commit is contained in:
water
2021-08-14 16:49:45 -04:00
parent 76419f8d85
commit 72340811e5
19 changed files with 1673 additions and 1714 deletions
+42 -1
View File
@@ -477,6 +477,10 @@ bool ControlFlowGraph::is_while_loop(CfgVtx* b0, CfgVtx* b1, CfgVtx* b2) {
if (!b0 || !b1 || !b2)
return false;
if (b0->end_branch.asm_branch || b1->end_branch.asm_branch) {
return false;
}
// check next and prev
if (b0->next != b1)
return false;
@@ -1243,6 +1247,10 @@ bool ControlFlowGraph::clean_up_asm_branches() {
}
// build new sequence
replaced = true;
if (!b0->succ_branch) {
fmt::print("asm missing branch in block {}\n", b0->to_string());
assert(false);
}
m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true;
auto* new_seq = alloc<SequenceVtx>();
@@ -1410,7 +1418,36 @@ bool ControlFlowGraph::clean_up_asm_branches() {
old_seq->parent_claim(seq);
return false;
} else {
} else if (!b0_seq && b1_seq) {
replaced = true;
if (!b0->succ_branch) {
fmt::print("bad: {}\n", b0->to_string());
}
m_blocks.at(b0->succ_branch->get_first_block_id())->needs_label = true;
auto* old_seq = dynamic_cast<SequenceVtx*>(b1);
assert(old_seq);
if (b0->succ_branch) {
if (debug_asm_branch) {
fmt::print(" sbp: {}\n", !!b0->succ_branch->parent);
fmt::print(" sb: {}\n", b0->succ_branch->to_string());
}
b0->succ_branch->replace_preds_with_and_check({b0}, nullptr);
}
for (auto* p : b0->pred) {
p->replace_succ_and_check(b0, old_seq);
}
old_seq->pred = b0->pred;
old_seq->prev = b0->prev;
if (old_seq->prev) {
old_seq->prev->next = old_seq;
}
old_seq->seq.insert(old_seq->seq.begin(), b0);
b0->parent_claim(old_seq);
}
else {
lg::error("unhandled sequences in clean_up_asm_branches seq: {} {}", !!b0_seq, !!b1_seq);
}
}
@@ -1985,6 +2022,10 @@ bool ControlFlowGraph::find_cond_n_else() {
return true;
}
if (b0->end_branch.asm_branch) {
return true;
}
// printf("cne: c0 %s b0 %s\n", c0->to_string().c_str(), b0->to_string().c_str());
// first condition should have the _option_ to fall through to first body
+31 -15
View File
@@ -417,10 +417,11 @@ std::unique_ptr<AtomicOp> make_branch(const IR2_Condition& condition,
const Instruction& delay,
bool likely,
int dest_label,
int my_idx) {
int my_idx,
bool force_asm) {
assert(!likely);
auto branch_delay = get_branch_delay(delay, my_idx);
if (branch_delay.is_known()) {
if (!force_asm && branch_delay.is_known()) {
return std::make_unique<BranchOp>(likely, condition, dest_label, branch_delay, my_idx);
} else {
auto delay_op = std::shared_ptr<AtomicOp>(convert_1_allow_asm(delay, my_idx));
@@ -989,7 +990,8 @@ std::unique_ptr<AtomicOp> convert_jalr_2(const Instruction& i0, const Instructio
std::unique_ptr<AtomicOp> convert_bne_2(const Instruction& i0,
const Instruction& i1,
int idx,
bool likely) {
bool likely,
bool force_asm) {
auto s0 = i0.get_src(0).get_reg();
auto s1 = i0.get_src(1).get_reg();
auto dest = i0.get_src(2).get_label();
@@ -1007,13 +1009,14 @@ std::unique_ptr<AtomicOp> convert_bne_2(const Instruction& i0,
make_src_atom(s1, idx));
condition.make_flipped();
}
return make_branch(condition, i1, likely, dest, idx);
return make_branch(condition, i1, likely, dest, idx, force_asm);
}
std::unique_ptr<AtomicOp> convert_beq_2(const Instruction& i0,
const Instruction& i1,
int idx,
bool likely) {
bool likely,
bool force_asm) {
auto s0 = i0.get_src(0).get_reg();
auto s1 = i0.get_src(1).get_reg();
auto dest = i0.get_src(2).get_label();
@@ -1038,7 +1041,7 @@ std::unique_ptr<AtomicOp> convert_beq_2(const Instruction& i0,
IR2_Condition(IR2_Condition::Kind::EQUAL, make_src_atom(s0, idx), make_src_atom(s1, idx));
condition.make_flipped();
}
return make_branch(condition, i1, likely, dest, idx);
return make_branch(condition, i1, likely, dest, idx, force_asm);
}
std::unique_ptr<AtomicOp> convert_daddiu_2(const Instruction& i0, const Instruction& i1, int idx) {
@@ -1144,6 +1147,14 @@ std::unique_ptr<AtomicOp> convert_bgez_2(const Instruction& i0, const Instructio
i1, false, dest, idx);
}
std::unique_ptr<AtomicOp> convert_blez_2(const Instruction& i0, const Instruction& i1, int idx) {
// blez is never emitted outside of inline asm.
auto dest = i0.get_src(1).get_label();
return make_asm_branch(IR2_Condition(IR2_Condition::Kind::LEQ_ZERO_SIGNED,
make_src_atom(i0.get_src(0).get_reg(), idx)),
i1, false, dest, idx);
}
std::unique_ptr<AtomicOp> convert_bgtz_2(const Instruction& i0, const Instruction& i1, int idx) {
// bgtz is never emitted outside of inline asm.
auto dest = i0.get_src(1).get_label();
@@ -1152,7 +1163,10 @@ std::unique_ptr<AtomicOp> convert_bgtz_2(const Instruction& i0, const Instructio
i1, false, dest, idx);
}
std::unique_ptr<AtomicOp> convert_2(const Instruction& i0, const Instruction& i1, int idx) {
std::unique_ptr<AtomicOp> convert_2(const Instruction& i0,
const Instruction& i1,
int idx,
bool force_asm_branch) {
switch (i0.kind) {
case InstructionKind::DIV:
return convert_division_2(i0, i1, idx, true);
@@ -1161,9 +1175,9 @@ std::unique_ptr<AtomicOp> convert_2(const Instruction& i0, const Instruction& i1
case InstructionKind::JALR:
return convert_jalr_2(i0, i1, idx);
case InstructionKind::BNE:
return convert_bne_2(i0, i1, idx, false);
return convert_bne_2(i0, i1, idx, false, force_asm_branch);
case InstructionKind::BEQ:
return convert_beq_2(i0, i1, idx, false);
return convert_beq_2(i0, i1, idx, false, force_asm_branch);
case InstructionKind::DADDIU:
return convert_daddiu_2(i0, i1, idx);
case InstructionKind::LUI:
@@ -1180,6 +1194,8 @@ std::unique_ptr<AtomicOp> convert_2(const Instruction& i0, const Instruction& i1
return convert_bgez_2(i0, i1, idx);
case InstructionKind::BGTZ:
return convert_bgtz_2(i0, i1, idx);
case InstructionKind::BLEZ:
return convert_blez_2(i0, i1, idx);
default:
return nullptr;
}
@@ -1326,7 +1342,7 @@ std::unique_ptr<AtomicOp> convert_slt_3(const Instruction& i0,
if (i1.kind == InstructionKind::BEQ) {
condition.invert();
}
result = make_branch(condition, i2, false, dest, idx);
result = make_branch(condition, i2, false, dest, idx, false);
add_clobber_if_unwritten(*result, temp);
return result;
} else if (i1.kind == InstructionKind::DADDIU &&
@@ -1391,7 +1407,7 @@ std::unique_ptr<AtomicOp> convert_slti_3(const Instruction& i0,
if (i1.kind == InstructionKind::BEQ) {
condition.invert();
}
result = make_branch(condition, i2, false, dest, idx);
result = make_branch(condition, i2, false, dest, idx, false);
add_clobber_if_unwritten(*result, temp);
return result;
} else if (i1.kind == InstructionKind::DADDIU &&
@@ -1434,7 +1450,7 @@ std::unique_ptr<AtomicOp> convert_fp_branch(const Instruction& i0,
if (i1.kind == InstructionKind::BC1F) {
condition.invert();
}
return make_branch(condition, i2, false, i1.get_src(0).get_label(), idx);
return make_branch(condition, i2, false, i1.get_src(0).get_label(), idx, false);
}
return nullptr;
}
@@ -1496,7 +1512,7 @@ std::unique_ptr<AtomicOp> convert_dsll32_4(const Instruction& i0,
assert(i2.get_src(1).is_reg(rr0()));
IR2_Condition condition(IR2_Condition::Kind::IS_NOT_PAIR, make_src_atom(arg, idx));
auto result = make_branch(condition, i3, false, i2.get_src(2).get_label(), idx);
auto result = make_branch(condition, i3, false, i2.get_src(2).get_label(), idx, false);
result->add_clobber_reg(temp);
return result;
}
@@ -1518,7 +1534,7 @@ std::unique_ptr<AtomicOp> convert_fp_branch_with_nop(const Instruction& i0,
if (i2.kind == InstructionKind::BC1F) {
condition.invert();
}
return make_branch(condition, i3, false, i2.get_src(0).get_label(), idx);
return make_branch(condition, i3, false, i2.get_src(0).get_label(), idx, false);
}
return nullptr;
}
@@ -1959,7 +1975,7 @@ int convert_block_to_atomic_ops(int begin_idx,
if (!converted && n_instr >= 2) {
// try 2 instructions
op = convert_2(instr[0], instr[1], op_idx);
op = convert_2(instr[0], instr[1], op_idx, block_ends_in_asm_branch);
if (op) {
converted = true;
length = 2;
+36 -31
View File
@@ -4838,6 +4838,11 @@
;; - Types
(defenum vis-info-flag
:bitfield #t
:type uint32
(waiting-for-load 30)
)
(declare-type bsp-header basic)
(deftype level-vis-info (basic)
((level symbol :offset-assert 4)
@@ -4852,7 +4857,7 @@
(ramdisk uint32 :offset-assert 40)
(vis-bits pointer :offset-assert 44)
(current-vis-string uint32 :offset-assert 48)
(vis-string uint8 :dynamic :offset-assert 52)
(vis-string uint32 :dynamic :offset-assert 52)
)
:method-count-assert 9
:size-assert #x34
@@ -4967,7 +4972,7 @@
(bsp-name (_type_) symbol 13)
(dummy-14 (_type_ object) memory-usage-block 14)
(dummy-15 (_type_ vector) symbol 15)
(dummy-16 (_type_ uint uint) none 16)
(update-vis! (_type_ level-vis-info uint uint) symbol 16)
(load-continue (_type_) _type_ 17)
(load-begin (_type_) _type_ 18)
(login (_type_) _type_ 19)
@@ -15236,22 +15241,22 @@
:flag-assert #x900000020
)
; (deftype blerc-block (structure)
; ((output UNKNOWN 848 :offset-assert 0)
; (header blerc-block-header :inline :offset-assert 848)
; )
; :method-count-assert 9
; :size-assert #x370
; :flag-assert #x900000370
; )
(deftype blerc-block (structure)
((output uint8 848 :offset-assert 0)
(header blerc-block-header :inline :offset-assert 848)
)
:method-count-assert 9
:size-assert #x370
:flag-assert #x900000370
)
; (deftype blerc-dcache (structure)
; ((repl-mult UNKNOWN 40 :offset-assert 0)
; )
; :method-count-assert 9
; :size-assert #x280
; :flag-assert #x900000280
; )
(deftype blerc-dcache (structure)
((repl-mult vector 40 :inline :offset-assert 0)
)
:method-count-assert 9
:size-assert #x280
:flag-assert #x900000280
)
(deftype blerc-globals (structure)
((first uint32 :offset-assert 0)
@@ -15267,21 +15272,21 @@
:flag-assert #x900000018
)
; (deftype blerc-context (structure)
; ((block-a blerc-block :inline :offset-assert 0)
; (dummy UNKNOWN 7312 :offset-assert 880)
; (block-b blerc-block :inline :offset-assert 8192)
; )
; :method-count-assert 9
; :size-assert #x2370
; :flag-assert #x900002370
; )
(deftype blerc-context (structure)
((block-a blerc-block :inline :offset-assert 0)
(dummy uint8 7312 :offset-assert 880)
(block-b blerc-block :inline :offset-assert 8192)
)
:method-count-assert 9
:size-assert #x2370
:flag-assert #x900002370
)
;; - Functions
(define-extern setup-blerc-chains-for-one-fragment function)
(define-extern setup-blerc-chains function)
(define-extern blerc-stats-init function)
(define-extern blerc-stats-init (function none))
(define-extern blerc-init (function none))
(define-extern blerc-a-fragment function)
(define-extern dma-from-spr function)
@@ -15291,8 +15296,8 @@
;; - Unknowns
;;(define-extern *blerc-globals* object) ;; unknown type
;;(define-extern *stats-blerc* object) ;; unknown type
(define-extern *blerc-globals* blerc-globals)
(define-extern *stats-blerc* symbol)
;; ----------------------
@@ -15801,8 +15806,8 @@
;; - Functions
(define-extern unpack-comp-rle function)
(define-extern unpack-comp-huf function)
(define-extern unpack-comp-rle (function (pointer int8) (pointer int8) none))
(define-extern unpack-comp-huf (function (pointer uint8) (pointer uint8) uint huf-dictionary-node none))
;; ----------------------
@@ -189,11 +189,6 @@
"shadow-scissor-edges",
"shadow-calc-dual-verts",
// decomp
//"(method 16 level)", // BUG: cfg fails
"unpack-comp-huf",
"unpack-comp-rle",
// background
"upload-vis-bits",
"background-upload-vu0",
@@ -519,6 +514,10 @@
"end-perf-stat-collection": [0],
"sprite-draw-distorters": [4, 5],
"draw-string":[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189],
"get-string-length":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]
"get-string-length":[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50],
"unpack-comp-rle":[1, 3, 5, 6],
"(method 16 level)":[ 1, 5, 13, 14, 15, 19, 26, 53],
"unpack-comp-huf":[2, 4, 5, 6, 7, 8, 9]
}
}
@@ -2153,5 +2153,26 @@
[31, "v1", "int"]
],
"(method 16 level)": [
[252, "v1", "(pointer uint128)"],
[253, "a1", "(pointer uint128)"],
[255, "a0", "(pointer uint128)"],
[208, "s2", "(pointer uint8)"],
[209, "s2", "(pointer uint8)"],
[210, "s1", "(pointer uint8)"],
[217, "s2", "(pointer uint8)"],
[218, "s1", "(pointer uint8)"],
[79, "a0", "(pointer uint128)"],
[80, "v1", "(pointer uint128)"],
[257, "v1", "(pointer uint16)"],
[222, "s2", "(pointer uint8)"],
[161, "s1", "(pointer uint128)"],
[140, "s1", "(pointer uint128)"]
],
"unpack-comp-huf": [
[[21, 23], "t3", "(pointer uint16)"]
],
"placeholder-do-not-add-below": []
}
@@ -3130,5 +3130,37 @@
"add-debug-outline-triangle": {
"args":["enable", "bucket", "p0", "p1", "p2", "color"]
},
"unpack-comp-rle": {
"args":["out", "in"],
"vars":{
"v1-2":"current-input",
"a2-0":"repeated-value",
"v1-3":"copy-length",
"a2-1":"src-val"
}
},
"(method 16 level)": {
"args":["obj", "vis-info"],
"vars":{
"a0-1":"cam-leaf-idx",
"v1-1":"curr-vis-str",
"s4-0":"desired-vis-str",
"s4-1":"vis-buffer",
"s3-1":"vis-load-result",
"v1-28":"dest-bits",
"a1-3":"len",
"a0-19":"bsp-bits",
"a1-5":"len-qw",
"s2-0":"lower-flag-bits",
"s1-0":"spad-start",
"s0-0":"spad-end",
"s3-2":"list-len",
"v1-49":"list-qwc",
"v0-1":"result"
}
},
"aaaaaaaaaaaaaaaaaaaaaaa": {}
}
+16 -28
View File
@@ -187,48 +187,36 @@
(if (!= (-> s5-1 all-visible?) 'loading)
(set! (-> s5-1 all-visible?) #f)
)
(let* ((a0-19 s5-1)
(t9-2 (method-of-object a0-19 dummy-16))
(a1-17 s4-0)
(a2-1 (-> s4-0 ramdisk))
)
(-> s4-0 string-block)
(when (t9-2 a0-19 (the-as uint a1-17) a2-1)
(countdown (v1-40 8)
(let ((a0-22 (-> s5-1 vis-info v1-40)))
(when a0-22
(if (!= a0-22 s4-0)
(set! (-> a0-22 current-vis-string) (the-as uint -1))
)
(when
(update-vis! s5-1 s4-0 (-> s4-0 ramdisk) (-> s4-0 string-block))
(countdown (v1-40 8)
(let ((a0-22 (-> s5-1 vis-info v1-40)))
(when a0-22
(if (!= a0-22 s4-0)
(set! (-> a0-22 current-vis-string) (the-as uint -1))
)
)
)
(set! (-> s5-1 all-visible?) #f)
)
(set! (-> s5-1 all-visible?) #f)
)
)
(a0-16
(if (!= (-> s5-1 all-visible?) 'loading)
(set! (-> s5-1 all-visible?) #f)
)
(let* ((a0-24 s5-1)
(t9-3 (method-of-object a0-24 dummy-16))
(a1-21 s3-0)
(a2-2 (-> s3-0 ramdisk))
)
(-> s3-0 string-block)
(when (t9-3 a0-24 (the-as uint a1-21) a2-2)
(countdown (v1-50 8)
(let ((a0-27 (-> s5-1 vis-info v1-50)))
(when a0-27
(if (!= a0-27 s3-0)
(set! (-> a0-27 current-vis-string) (the-as uint -1))
)
(when
(update-vis! s5-1 s3-0 (-> s3-0 ramdisk) (-> s3-0 string-block))
(countdown (v1-50 8)
(let ((a0-27 (-> s5-1 vis-info v1-50)))
(when a0-27
(if (!= a0-27 s3-0)
(set! (-> a0-27 current-vis-string) (the-as uint -1))
)
)
)
(set! (-> s5-1 all-visible?) #f)
)
(set! (-> s5-1 all-visible?) #f)
)
)
((and (= (-> s5-1 all-visible?) 'loading) (-> *level* play?))
+1131 -1580
View File
File diff suppressed because it is too large Load Diff
+8 -2
View File
@@ -9,6 +9,12 @@
(defconstant LEVEL_COUNT 2) ;; there are two levels in memory!
(defenum vis-info-flag
:bitfield #t
:type uint32
(waiting-for-load 30)
)
;; Information related to visibility data for a level.
;; Unclear why there are 8 of these per level.
;; Perhaps there are up to 8 "chunks" of the visibility loaded at a single time?
@@ -27,7 +33,7 @@
(ramdisk uint32 :offset-assert 40)
(vis-bits pointer :offset-assert 44)
(current-vis-string uint32 :offset-assert 48)
(vis-string uint8 :dynamic :offset-assert 52)
(vis-string uint32 :dynamic :offset-assert 52)
)
:method-count-assert 9
:size-assert #x34
@@ -152,7 +158,7 @@
(bsp-name (_type_) symbol 13)
(dummy-14 (_type_ object) memory-usage-block 14)
(dummy-15 (_type_ vector) symbol 15)
(dummy-16 (_type_ uint uint) none 16)
(update-vis! (_type_ level-vis-info uint uint) symbol 16)
(load-continue (_type_) _type_ 17)
(load-begin (_type_) _type_ 18)
(login (_type_) _type_ 19)
+306
View File
@@ -5,3 +5,309 @@
;; name in dgo: decomp
;; dgos: GAME, ENGINE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; decompression functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun unpack-comp-rle ((out (pointer int8)) (in (pointer int8)))
"Unpack run-length-encoded data. Has sections of repeated values, then normally copied."
(local-vars (current-input int) (copy-length int))
(nop!)
(while #t
(while #t
;; read the input and see what kind it is, based on number.
(set! current-input (-> in 0))
(set! in (&-> in 1))
(b! (<= current-input 0) cfg-5 :delay (nop!))
;; it's a repated value, loop to copy it.
(let ((repeated-value (-> in 0)))
(set! in (&-> in 1))
(label cfg-3)
(set! (-> out 0) repeated-value)
)
(set! out (&-> out 1))
(b! (> current-input 0) cfg-3 :delay (set! current-input (+ current-input -1)))
)
(label cfg-5)
;; check for end
(b! (zero? current-input) cfg-8 :delay (set! copy-length (- current-input)))
;; copy
(label cfg-6)
(let ((src-val (-> in 0)))
(set! in (&-> in 1))
(set! (-> out 0) src-val)
)
(+! copy-length -1)
(b! (> copy-length 0) cfg-6 :delay (set! out (&-> out 1)))
)
(label cfg-8)
0
(none)
)
(deftype huf-dictionary-node (structure)
((zero uint16 :offset-assert 0)
(one uint16 :offset-assert 2)
)
:method-count-assert 9
:size-assert #x4
:flag-assert #x900000004
)
(defun unpack-comp-huf ((dst (pointer uint8)) (src (pointer uint8)) (arg2 uint) (dict huf-dictionary-node))
"Unpack data compressed with huffman encoding."
(local-vars (t1-1 uint) (t3-2 object))
(let ((t1-0 (-> dict zero))
(a2-1 (+ arg2 -1028))
(t2-0 (-> dict one))
)
(nop!)
(label cfg-1)
(let ((v1-4 128))
(nop!)
(let ((t0-0 (-> src 0)))
(set! src (&-> src 1))
(label cfg-2)
(let ((t3-0 (logand t0-0 v1-4)))
(.sra v1-4 v1-4 1)
(b! (zero? t3-0) cfg-4 :delay (set! t1-1 t1-0))
)
)
(nop!)
(set! t1-1 t2-0)
(label cfg-4)
(let ((t2-1 (+ t1-1 -256)))
(let ((t3-1 (* t1-1 4)))
(b! (< (the-as int t2-1) 0) cfg-8 :delay (set! t3-2 (+ t3-1 a2-1)))
)
(b! (zero? t2-1) cfg-10
:delay (set! t1-0 (-> (the-as (pointer uint16) t3-2) 0))
)
)
(b! (nonzero? v1-4) cfg-2
:delay (set! t2-0 (-> (the-as (pointer uint16) t3-2) 1))
)
(b! #t cfg-1 :delay (nop!))
(label cfg-8)
(set! (-> dst 0) t1-1)
(set! dst (&-> dst 1))
(nop!)
(set! t1-0 (-> dict zero))
(b! (nonzero? v1-4) cfg-2 :delay (set! t2-0 (-> dict one)))
)
)
(b! #t cfg-1 :delay (nop!))
(label cfg-10)
(nop!)
(nop!)
0
(none)
)
(defmethod update-vis! level ((obj level) (vis-info level-vis-info) (arg1 uint) (arg2 uint))
(local-vars (t0-3 uint128) (vis-buffer object))
(let* ((cam-leaf-idx (-> vis-info from-bsp current-leaf-idx)) ;; current bsp leaf of camera
(curr-vis-str (-> vis-info current-vis-string)) ;; currently loaded vis-string.
(desired-vis-str (-> vis-info vis-string cam-leaf-idx)) ;; vis-string ptr for what we want.
)
;; oops
0
(+ 16 #x70000000)
(+ 2064 #x70000000)
;; wait on ramdisk load, or do nothing because we already have the right stuff.
(when (= curr-vis-str desired-vis-str)
;; we match. but are we loading?
(cond
((logtest? (vis-info-flag waiting-for-load) (-> vis-info flags))
(if (check-busy *ramdisk-rpc*)
;; loading, and ramdisk not done, return #f, we don't have vis.
(return #f)
)
;; we are done loading. Jump to code that sets it up.
(logclear! (-> vis-info flags) (vis-info-flag waiting-for-load))
(set! vis-buffer (-> obj vis-buffer))
(b! #t cfg-27 :delay (nop!))
)
(else
;; matched, and loaded!
(return #t)
)
)
)
;; wait for any pending load to finish.
(when (logtest? (vis-info-flag waiting-for-load) (-> vis-info flags))
(if (check-busy *ramdisk-rpc*)
(return #f)
)
(logclear! (-> vis-info flags) (vis-info-flag waiting-for-load))
)
;; not sure what this does yet.
(set! (-> vis-info current-vis-string) desired-vis-str)
(b! (logtest? #x20000000 (-> vis-info flags)) cfg-15)
(set! vis-buffer (the-as (pointer uint8) (+ arg2 desired-vis-str)))
(b! #t cfg-27 :delay (nop!))
(label cfg-15)
;; start a ramdisk load.
(let ((vis-load-result (vis-load obj)))
(b! (nonzero? vis-load-result) cfg-21)
(let* ((dest-bits (-> vis-info vis-bits))
(len (-> obj bsp visible-list-length))
(bsp-bits (the-as (pointer uinteger) (-> obj bsp all-visible-list)))
(len-qw (/ (+ len 15) 16))
)
(dotimes (a2-1 len-qw)
(set!
(-> (the-as (pointer uint128) dest-bits) 0)
(-> (the-as (pointer uint128) bsp-bits) 0)
)
(&+! dest-bits 16)
(set! bsp-bits (&-> (the-as (pointer uint16) bsp-bits) 8))
)
)
(let ((result #f))
(b! #t cfg-55 :delay (nop!))
(the-as none 0)
(label cfg-21)
(when (check-busy *ramdisk-rpc*)
(set! (-> vis-info current-vis-string) (the-as uint -1))
(set! (-> obj all-visible?) 'loading)
(if (= *cheat-mode* 'debug)
(format *stdcon* "Ramdisk loading~%")
)
(return #f)
)
(set! (-> vis-info flags) (logior (-> vis-info flags) #x40000000))
(ramdisk-load
(the-as int vis-load-result)
desired-vis-str
(the-as uint 2048)
(-> obj vis-buffer)
)
(set! result #f)
(b! #t cfg-55 :delay (nop!))
;; setup loaded
(label cfg-27)
(let ((lower-flag-bits (the-as int (logand #x1fffffff (-> vis-info flags))))
(spad-start (the-as object (+ 16 #x70000000)))
(spad-end (+ 2064 #x70000000))
(list-len (-> obj bsp visible-list-length))
)
(when (zero? (the-as vis-info-flag lower-flag-bits))
(let ((list-qwc (/ (+ list-len 15) 16)))
(dotimes (a0-28 list-qwc)
(set!
(-> (the-as (pointer uint128) spad-start) a0-28)
(the-as uint128 0)
)
)
)
(mem-copy!
(the-as pointer spad-start)
(the-as pointer vis-buffer)
list-len
)
)
(while (nonzero? lower-flag-bits)
(case (logand lower-flag-bits 7)
((1)
(let ((v1-55 (/ (+ list-len 15) 16)))
(dotimes (a0-32 v1-55)
(set! (-> (the-as (pointer uint128) spad-start) a0-32) (the-as uint128 0))
)
)
(dummy-16
(-> obj bsp drawable-trees)
(the-as int spad-start)
(the-as object vis-buffer)
)
)
((2)
(unpack-comp-rle
(the-as (pointer int8) spad-start)
(the-as (pointer int8) vis-buffer)
)
)
((3)
(unpack-comp-huf
(the-as (pointer uint8) spad-start)
(the-as (pointer uint8) vis-buffer)
(-> vis-info dictionary)
(the-as huf-dictionary-node
(+ (-> vis-info dictionary) (-> vis-info dictionary-length) -4)
)
)
)
)
(set! vis-buffer (the-as (pointer uint8) (the-as int spad-start)))
(set! spad-start spad-end)
(set! spad-end (the-as int vis-buffer))
(.sra lower-flag-bits lower-flag-bits 3)
)
(let ((s2-1 (the-as object vis-buffer))
(s1-1 (the-as (pointer uinteger) (-> obj bsp all-visible-list)))
(v1-67 #f)
)
(dotimes (s0-1 list-len)
(when (!= (logand (-> (the-as (pointer uint8) s2-1) 0)
(-> (the-as (pointer uint8) s1-1) 0)
)
(-> (the-as (pointer uint8) s2-1) 0)
)
(format #t "ERROR: illegal vis bits set [byte ~X] ~X -> ~X~%"
s0-1
(-> (the-as (pointer uint8) s2-1) 0)
(-> (the-as (pointer uint8) s1-1) 0)
)
(set! v1-67 #t)
)
(set! s2-1 (&-> (the-as (pointer uint8) s2-1) 1))
(set! s1-1 (&+ (the-as (pointer uint16) s1-1) 1))
)
(when v1-67
(format #t "src = #x~x dest = #x~x ~s ~s~%"
(the-as object vis-buffer)
(-> vis-info vis-bits)
(-> vis-info level)
(-> vis-info from-level)
)
(format #t "leaf-index = ~d~%" (-> vis-info from-bsp current-leaf-idx))
0
)
)
(let ((v1-71 (the-as object vis-buffer))
(a0-47 (-> vis-info vis-bits))
(a1-22 (the-as (pointer uinteger) (-> obj bsp all-visible-list)))
(a2-11 (/ (+ list-len 15) 16))
)
(dotimes (a3-8 a2-11)
(let ((t0-2 (-> (the-as (pointer uint128) v1-71) 0))
(t1-1 (-> (the-as (pointer uint128) a1-22) 0))
)
(.pand t0-3 t0-2 t1-1)
)
(set! (-> (the-as (pointer uint128) a0-47) 0) t0-3)
(&+! a0-47 16)
(set! v1-71 (&-> (the-as (pointer uint16) v1-71) 8))
(set! a1-22 (&-> (the-as (pointer uint16) a1-22) 8))
)
)
)
(set! result #t)
(label cfg-55)
result
)
)
)
)
+8
View File
@@ -330,3 +330,11 @@
)
)
)
(defmacro sext32 (in)
`(sar (shl ,in 32) 32)
)
(defmacro .sra (result in sa)
`(set! ,result (sext32 (sar (logand #xffffffff (the-as int ,in)) ,sa)))
)
+16 -28
View File
@@ -183,48 +183,36 @@
(if (!= (-> s5-1 all-visible?) 'loading)
(set! (-> s5-1 all-visible?) #f)
)
(let* ((a0-19 s5-1)
(t9-2 (method-of-object a0-19 dummy-16))
(a1-17 s4-0)
(a2-1 (-> s4-0 ramdisk))
)
(-> s4-0 string-block)
(when (t9-2 a0-19 (the-as uint a1-17) a2-1)
(countdown (v1-40 8)
(let ((a0-22 (-> s5-1 vis-info v1-40)))
(when a0-22
(if (!= a0-22 s4-0)
(set! (-> a0-22 current-vis-string) (the-as uint -1))
)
(when
(update-vis! s5-1 s4-0 (-> s4-0 ramdisk) (-> s4-0 string-block))
(countdown (v1-40 8)
(let ((a0-22 (-> s5-1 vis-info v1-40)))
(when a0-22
(if (!= a0-22 s4-0)
(set! (-> a0-22 current-vis-string) (the-as uint -1))
)
)
)
(set! (-> s5-1 all-visible?) #f)
)
(set! (-> s5-1 all-visible?) #f)
)
)
(a0-16
(if (!= (-> s5-1 all-visible?) 'loading)
(set! (-> s5-1 all-visible?) #f)
)
(let* ((a0-24 s5-1)
(t9-3 (method-of-object a0-24 dummy-16))
(a1-21 s3-0)
(a2-2 (-> s3-0 ramdisk))
)
(-> s3-0 string-block)
(when (t9-3 a0-24 (the-as uint a1-21) a2-2)
(countdown (v1-50 8)
(let ((a0-27 (-> s5-1 vis-info v1-50)))
(when a0-27
(if (!= a0-27 s3-0)
(set! (-> a0-27 current-vis-string) (the-as uint -1))
)
(when
(update-vis! s5-1 s3-0 (-> s3-0 ramdisk) (-> s3-0 string-block))
(countdown (v1-50 8)
(let ((a0-27 (-> s5-1 vis-info v1-50)))
(when a0-27
(if (!= a0-27 s3-0)
(set! (-> a0-27 current-vis-string) (the-as uint -1))
)
)
)
(set! (-> s5-1 all-visible?) #f)
)
(set! (-> s5-1 all-visible?) #f)
)
)
((and (= (-> s5-1 all-visible?) 'loading) (-> *level* play?))
+2 -2
View File
@@ -130,7 +130,7 @@
(local-vars (r0-0 none))
(let ((v1-0 (-> obj ctrl)))
(+! (-> obj count) 1)
(b! (zero? v1-0) cfg-2)
(b! (zero? v1-0) cfg-2 :delay (nop!))
(.mtc0 Perf r0-0)
(.sync.l)
(.sync.p)
@@ -156,7 +156,7 @@
;; WARN: Unsupported inline assembly instruction kind - [mfpc v1, pcr1]
(defmethod read! perf-stat ((obj perf-stat))
(local-vars (r0-0 none) (v1-1 int) (v1-3 int))
(b! (zero? (-> obj ctrl)) cfg-2)
(b! (zero? (-> obj ctrl)) cfg-2 :delay (nop!))
(.mtc0 Perf r0-0)
(.sync.l)
(.sync.p)
+5 -5
View File
@@ -823,7 +823,7 @@
)
(goto cfg-24)
(label cfg-17)
(b! (nonzero? v1-10) cfg-22)
(b! (nonzero? v1-10) cfg-22 :delay (nop!))
(let
((f30-1
(vector-segment-distance-point!
@@ -1117,7 +1117,7 @@
(b! (> f1-2 arg2) cfg-4)
(b! (>= arg2 f2-0) cfg-4 :delay (set! v0-0 a2-1))
)
(b! #t cfg-11)
(b! #t cfg-11 :delay (nop!))
(label cfg-4)
(let ((a1-1 arg1)
(a0-1 (+ arg0 1))
@@ -1135,7 +1135,7 @@
(set! v0-0 a2-3)
)
)
(b! (= v0-0 v1-3) cfg-11)
(b! (= v0-0 v1-3) cfg-11 :delay (nop!))
)
(nop!)
(nop!)
@@ -1255,7 +1255,7 @@
(b! (> f1-4 f0-3) cfg-4)
(b! (>= f0-3 f2-3) cfg-4 :delay (set! s3-0 t1-1))
)
(b! #t cfg-11)
(b! #t cfg-11 :delay (nop!))
(label cfg-4)
(let ((a3-2 a3-1)
(a1-2 (+ a1-1 1))
@@ -1273,7 +1273,7 @@
(set! s3-0 t1-3)
)
)
(b! (= s3-0 a0-4) cfg-11)
(b! (= s3-0 a0-4) cfg-11 :delay (nop!))
)
)
(nop!)
@@ -304,7 +304,7 @@
(.mul.vf vf10 vf1 vf8)
(.div.vf Q vf0 vf10 :fsf #b11 :ftf #b11)
(TODO.VCLIP vf10 vf10)
(b! (zero? (-> sv-16 flag)) cfg-21)
(b! (zero? (-> sv-16 flag)) cfg-21 :delay (nop!))
(.wait.vf)
(.mul.vf vf1 vf1 Q :mask #b111)
(.mul.vf vf2 vf2 Q :mask #b111)
@@ -510,7 +510,3 @@
(none)
)
)
+1 -1
View File
@@ -3227,7 +3227,7 @@
(.subu a3-10 t0-0 (the-as int a3-9))
(let ((t0-2 (+ (-> arg1 mip-shift) -1)))
(nop!)
(b! (zero? t0-2) cfg-2)
(b! (zero? t0-2) cfg-2 :delay (nop!))
)
(let* ((t0-3 (+ a3-10 -4))
(a3-11 (* a3-10 16))
@@ -456,7 +456,7 @@
(a0-76 (-> v1-31 0 ctrl))
)
(+! (-> v1-31 0 count) 1)
(b! (zero? a0-76) cfg-28)
(b! (zero? a0-76) cfg-28 :delay (nop!))
(.mtc0 Perf r0-0)
(.sync.l)
(.sync.p)
@@ -484,7 +484,7 @@
(defun-debug end-perf-stat-collection ()
(local-vars (r0-0 none) (a0-1 int) (a0-3 int))
(let ((v1-1 (-> *perf-stats* data)))
(b! (zero? (-> v1-1 0 ctrl)) cfg-2)
(b! (zero? (-> v1-1 0 ctrl)) cfg-2 :delay (nop!))
(.mtc0 Perf r0-0)
(.sync.l)
(.sync.p)
+8 -6
View File
@@ -593,7 +593,12 @@
(table-data-end (&+ table-data-ptr (* table-size 8)))
)
(label cfg-2)
(b! (= (the-as object table-data-start) table-data-end) cfg-8)
(b!
(= (the-as object table-data-start) table-data-end)
cfg-8
:delay
(nop!)
)
(let
((midpoint
(the-as
@@ -616,17 +621,14 @@
(- (-> (the-as (pointer int32) midpoint) 0) (the-as int masked-tex-id))
)
)
(b! (zero? diff) cfg-7)
(b! (zero? diff) cfg-7 :delay (nop!))
(b! (< diff 0) cfg-6 :delay (nop!))
)
(b!
#t
cfg-2
:delay
(set!
table-data-end
(the-as (pointer uint64) (the-as (pointer uint64) midpoint))
)
(set! table-data-end (the-as (pointer uint64) midpoint))
)
(label cfg-6)
(b!
+2 -2
View File
@@ -15,7 +15,7 @@
(ramdisk uint32 :offset-assert 40)
(vis-bits pointer :offset-assert 44)
(current-vis-string uint32 :offset-assert 48)
(vis-string uint8 :dynamic :offset-assert 52)
(vis-string uint32 :dynamic :offset-assert 52)
)
:method-count-assert 9
:size-assert #x34
@@ -192,7 +192,7 @@
(bsp-name (_type_) symbol 13)
(dummy-14 (_type_ object) memory-usage-block 14)
(dummy-15 (_type_ vector) symbol 15)
(dummy-16 (_type_ uint uint) none 16)
(update-vis! (_type_ level-vis-info uint uint) symbol 16)
(load-continue (_type_) _type_ 17)
(load-begin (_type_) _type_ 18)
(login (_type_) _type_ 19)