Merge pull request #761 from water111/w/decomp-decomp

[decomp] decomp
This commit is contained in:
water111 2021-08-15 14:25:17 -04:00 committed by GitHub
commit 3e2aa06a56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 3885 additions and 1830 deletions

View file

@ -20,7 +20,7 @@ const bool allowed_local_gprs[Reg::MAX_GPR] = {
true /*S0*/, true /*S1*/, true /*S2*/, true /*S3*/,
true /*S4*/, true /*S5*/, false /*S6*/, false /*S7*/,
true /*T8*/, true /*T9*/, false /*K0*/, false /*K1*/,
true /*GP*/, true /*SP*/, false /*FP*/, false /*RA*/
true /*GP*/, true /*SP*/, false /*FP*/, true /*RA*/
};
// clang-format on
} // namespace Reg

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);
}
}
@ -1622,6 +1659,10 @@ bool ControlFlowGraph::find_cond_w_else(const CondWithElseLengthHack& hack) {
return true;
}
if (b0->end_branch.asm_branch) {
return true;
}
// printf("cwe try %s %s\n", c0->to_string().c_str(), b0->to_string().c_str());
// first condition should have the _option_ to fall through to first body
@ -1985,6 +2026,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

View file

@ -261,10 +261,8 @@ TP_Type get_stack_type_at_constant_offset(int offset,
if (offset == structure.hint.stack_offset) {
// special case just getting the variable
if (structure.hint.container_type == StackStructureHint::ContainerType::NONE ||
structure.hint.container_type == StackStructureHint::ContainerType::INLINE_ARRAY) {
return TP_Type::make_from_ts(coerce_to_reg_type(structure.ref_type));
}
return TP_Type::make_from_ts(coerce_to_reg_type(structure.ref_type));
}
// Note: GOAL doesn't seem to constant propagate memory access on the stack, so the code

View file

@ -563,6 +563,14 @@ void Env::set_stack_structure_hints(const std::vector<StackStructureHint>& hints
type_info->get_in_memory_alignment());
}
} break;
case StackStructureHint::ContainerType::ARRAY: {
TypeSpec base_typespec = dts->parse_type_spec(hint.element_type);
entry.ref_type = TypeSpec("pointer", {TypeSpec(base_typespec)});
entry.size = 1; // we assume that there is no constant propagation into this array and
// make this only trigger in get_stack_type if we hit exactly.
break;
}
default:
assert(false);
}

View file

@ -2621,6 +2621,10 @@ goos::Object StackStructureDefElement::to_form_internal(const Env&) const {
return pretty_print::build_list(fmt::format("new 'stack-no-clear 'inline-array '{} {}",
m_entry.ref_type.get_single_arg().print(),
m_entry.hint.container_size));
case StackStructureHint::ContainerType::ARRAY:
return pretty_print::build_list(fmt::format("new 'stack-no-clear 'array '{} {}",
m_entry.ref_type.get_single_arg().print(),
m_entry.hint.container_size));
default:
assert(false);
}

View file

@ -2140,6 +2140,23 @@ void SetFormFormElement::push_to_stack(const Env& env, FormPool& pool, FormStack
fmt::print("invalid bf set: {}\n", src_as_bf_set->to_string(env));
}
// setting a bitfield to zero is wonky.
auto bfa = dynamic_cast<BitfieldAccessElement*>(m_src->try_as_single_element());
if (bfa) {
auto zero_set = bfa->get_set_field_0(env.dts->ts);
if (zero_set) {
auto field_token = DerefToken::make_field_name(zero_set->name());
auto loc_elt = pool.alloc_element<DerefElement>(m_dst, false, field_token);
loc_elt->inline_nested();
auto loc = pool.alloc_single_form(nullptr, loc_elt);
loc->parent_element = this;
m_dst = loc;
auto zero = SimpleAtom::make_int_constant(0);
auto zero_form = pool.alloc_single_element_form<SimpleAtomElement>(nullptr, zero);
m_src = zero_form;
}
}
const std::pair<FixedOperatorKind, FixedOperatorKind> in_place_ops[] = {
{FixedOperatorKind::ADDITION, FixedOperatorKind::ADDITION_IN_PLACE},
{FixedOperatorKind::ADDITION_PTR, FixedOperatorKind::ADDITION_PTR_IN_PLACE},

View file

@ -379,6 +379,32 @@ std::string BitfieldAccessElement::debug_print(const Env& env) const {
return result;
}
std::optional<BitField> BitfieldAccessElement::get_set_field_0(const TypeSystem& ts) const {
if (m_got_pcpyud) {
return {};
}
if (m_steps.size() != 1) {
return {};
}
auto& step = m_steps.at(0);
if (step.kind != BitfieldManip::Kind::LOGAND_WITH_CONSTANT_INT) {
return {};
}
u64 mask = step.amount;
auto type = ts.lookup_type(m_type);
auto as_bitfield = dynamic_cast<BitFieldType*>(type);
assert(as_bitfield);
// use the mask to figure out the field.
auto field = find_field_from_mask(ts, as_bitfield, ~mask, m_got_pcpyud);
if (field) {
return field;
} else {
return {};
}
}
/*!
* Add a step to the bitfield access. If this completes the access, returns a form representing the
* access

View file

@ -103,6 +103,8 @@ class BitfieldAccessElement : public FormElement {
void push_pcpyud(const TypeSystem& ts, FormPool& pool, const Env& env);
std::string debug_print(const Env& env) const;
bool has_pcpyud() const { return m_got_pcpyud; }
const std::vector<BitfieldManip>& steps() const { return m_steps; }
std::optional<BitField> get_set_field_0(const TypeSystem& ts) const;
private:
bool m_got_pcpyud = false;

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;

View file

@ -3477,9 +3477,9 @@
;; - Functions
(define-extern dma-buffer-add-buckets (function dma-buffer int dma-bucket))
(define-extern dma-buffer-patch-buckets (function dma-bucket int dma-bucket))
(define-extern dma-bucket-insert-tag (function dma-bucket bucket-id pointer (pointer dma-tag) pointer))
(define-extern dma-buffer-add-buckets (function dma-buffer int (inline-array dma-bucket)))
(define-extern dma-buffer-patch-buckets (function (inline-array dma-bucket) int (inline-array dma-bucket)))
(define-extern dma-bucket-insert-tag (function (inline-array dma-bucket) bucket-id pointer (pointer dma-tag) pointer))
;; ----------------------
@ -4284,7 +4284,7 @@
(vu1-buf dma-buffer :offset 8)
(debug-buf dma-buffer :offset 36)
(global-buf dma-buffer :offset 40)
(bucket-group dma-bucket :offset 44)
(bucket-group (inline-array dma-bucket) :offset 44)
(buffer dma-buffer 11 :offset 4)
(profile-bar profile-bar 2 :offset 48)
(run-time uint64 :offset 56)
@ -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)
@ -7569,7 +7574,7 @@
:size-assert #x14
:flag-assert #xd00000014
(:methods
(dummy-9 (_type_) _type_ 9)
(login (_type_) _type_ 9)
(dummy-10 (_type_ string type) art-element 10)
(dummy-11 (_type_ string type) int 11)
(dummy-12 (_type_) symbol 12)
@ -7582,7 +7587,6 @@
:size-assert #x20
:flag-assert #xd00000020
(:methods
(dummy-9 (_type_) _type_ 9)
(dummy-10 (_type_ string type) art-element 10)
(dummy-11 (_type_ string type) int 11)
(dummy-12 (_type_) symbol 12)
@ -7604,6 +7608,7 @@
(artist-step float :offset 28)
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
(blerc-data (pointer uint8) :offset 40) ;; todo, this is probably something else
(frames pointer :offset 44) ;; this structure doesn't exist? it's a structure with an array of joint-anim-compressed-hdr starting at offset 12
(data joint-anim-compressed :dynamic :offset-assert 48)
)
@ -7614,7 +7619,7 @@
(deftype art-group (art)
((info file-info :offset 4)
(data art-element :dynamic :offset 32)
(data art-element :dynamic :offset 32) ;; might just be art?
)
:method-count-assert 15
:size-assert #x20
@ -7849,7 +7854,7 @@
:size-assert #x18
:flag-assert #xa00000018
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -7890,6 +7895,7 @@
((matrix-number uint8 :offset-assert 0)
(matrix-dest uint8 :offset-assert 1)
)
:pack-me
:method-count-assert 9
:size-assert #x2
:flag-assert #x900000002
@ -7900,7 +7906,7 @@
(lump-four-count uint8 :offset-assert 1)
(fp-qwc uint8 :offset-assert 2)
(mat-xfer-count uint8 :offset-assert 3)
(mat-dest-data uint8 :dynamic :offset-assert 4)
(mat-dest-data merc-mat-dest :inline :dynamic :offset-assert 4)
)
:method-count-assert 9
:size-assert #x4
@ -7965,6 +7971,9 @@
:flag-assert #x900000010
)
;;effect-bits:
;; 1 - swap with last effect.
(deftype merc-effect (structure)
((frag-geo merc-fragment :offset-assert 0)
(frag-ctrl merc-fragment-control :offset-assert 4)
@ -7979,12 +7988,15 @@
(dummy1 uint8 :offset-assert 26)
(envmap-usage uint8 :offset-assert 27)
(extra-info merc-extra-info :offset-assert 28)
;; added
(data uint64 4 :offset 0)
)
:method-count-assert 10
:size-assert #x20
:flag-assert #xa00000020
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -8033,7 +8045,7 @@
(st-vif-add uint32 :offset-assert 16)
(st-int-off uint16 :offset-assert 20)
(st-int-scale uint16 :offset-assert 22)
(effect-count uint32 :offset-assert 24)
(effect-count uint32 :offset-assert 24) ;; number of effects in merc-ctrl effect
(blend-target-count uint32 :offset-assert 28)
(fragment-count uint16 :offset-assert 32)
(tri-count uint16 :offset-assert 34)
@ -8084,8 +8096,8 @@
)
(deftype merc-vu1-low-mem (structure)
((tri-strip-gif qword :inline :offset-assert 0)
(ad-gif qword :inline :offset-assert 16)
((tri-strip-gif gs-gif-tag :inline :offset-assert 0) ;; was qword
(ad-gif gs-gif-tag :inline :offset-assert 16) ;; was qword
(hvdf-offset vector :inline :offset-assert 32)
(perspective uint128 4 :offset-assert 48)
(fog vector :inline :offset-assert 112)
@ -8144,7 +8156,7 @@
;; - Functions
(define-extern merc-fragment-fp-data (function merc-fragment pointer))
(define-extern merc-fragment-fp-data (function merc-fragment merc-fp-header))
;; ----------------------
@ -15236,22 +15248,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,32 +15279,32 @@
: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 setup-blerc-chains (function merc-ctrl (pointer int16) dma-buffer none))
(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)
(define-extern merc-dma-chain-to-spr function)
(define-extern blerc-execute (function none))
(define-extern merc-blend-shape function)
(define-extern merc-blend-shape (function process-drawable object))
;; - 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)
;; ----------------------
@ -15303,18 +15315,18 @@
;; - Functions
(define-extern merc-vu1-init-buffer function)
(define-extern merc-vu1-initialize-chain function)
(define-extern merc-vu1-add-vu-function function)
(define-extern get-eye-block function)
(define-extern merc-stats-display function)
(define-extern merc-stats function)
(define-extern merc-edge-stats function)
(define-extern merc-vu1-init-buffer (function bucket-id gs-test int none))
(define-extern merc-vu1-initialize-chain (function dma-gif-packet none))
(define-extern merc-vu1-add-vu-function (function dma-packet vu-function int dma-gif-packet))
(define-extern get-eye-block (function int int int))
(define-extern merc-stats-display (function merc-ctrl none))
(define-extern merc-stats (function none))
(define-extern merc-edge-stats (function none))
(define-extern merc-vu1-init-buffers (function none))
;; - Unknowns
;;(define-extern *merc-ctrl-header* object) ;; unknown type
(define-extern *merc-ctrl-header* merc-ctrl-header)
;; ----------------------
@ -15801,8 +15813,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))
;; ----------------------
@ -15835,7 +15847,7 @@
;; - Unknowns
;;(define-extern background-vu0-block object) ;; unknown type
(define-extern background-vu0-block vu-function)
;; ----------------------

View file

@ -118,7 +118,6 @@
// merc-blend-shape
"setup-blerc-chains-for-one-fragment", // F: asm branching
"blerc-execute", // F: asm branching
"merc-dma-chain-to-spr", // F: asm branching
"blerc-a-fragment",
@ -189,11 +188,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 +513,11 @@
"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],
"blerc-execute":[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]
}
}

View file

@ -1684,6 +1684,20 @@
["L393", "rgba", true]
],
"merc-blend-shape": [
["L62", "(pointer int16)", true, 32]
],
"merc": [
["L50", "uint64", true],
["L51", "uint64", true],
["L52", "uint64", true],
["L54", "uint64", true],
["L53", "uint64", true],
["L55", "uint64", true],
["L56", "uint64", true]
],
// please do not add things after this entry! git is dumb.
"object-file-that-doesnt-actually-exist-and-i-just-put-this-here-to-prevent-merge-conflicts-with-this-file": []
}

View file

@ -1023,5 +1023,9 @@
[16, "vector"]
],
"merc-blend-shape": [
[16, ["array", "int16", 128]]
],
"placeholder-do-not-add-below!": []
}

View file

@ -152,12 +152,13 @@
],
"dma-buffer-patch-buckets": [
[7, "a0", "pointer"],
[14, "a0", "pointer"],
[3, "a0", "dma-bucket"],
[11, "a0", "dma-bucket"],
[13, "a0", "dma-bucket"],
[19, "a0", "dma-bucket"]
[7, "a0", "(inline-array dma-bucket)"],
[8, "a3", "pointer"],
[14, "a0", "(inline-array dma-bucket)"],
[3, "a0", "(inline-array dma-bucket)"],
[11, "a0", "(inline-array dma-bucket)"],
[13, "a0", "(inline-array dma-bucket)"],
[19, "a0", "(inline-array dma-bucket)"]
],
"dma-bucket-insert-tag": [
@ -2153,5 +2154,62 @@
[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)"]
],
"(method 9 merc-fragment)": [
[[13,161], "s3", "adgif-shader"]
],
"(method 9 merc-effect)": [
[49, "s4", "pointer"],
[50, "s5", "pointer"],
[[0, 49], "s4", "merc-fragment"],
[[0, 50], "s5", "merc-fragment-control"]
],
"merc-vu1-initialize-chain": [
[[19, 47], "s5", "merc-vu1-low-mem"],
[58, "gp", "(inline-array dma-packet)"],
[[12, 18], "gp", "(pointer vif-tag)"]
],
"merc-vu1-init-buffer":[
[[27, 31], "a0", "dma-packet"],
[[37, 40], "a0", "gs-gif-tag"],
[44, "a0", "(pointer gs-test)"],
[46, "a0", "(pointer gs-reg64)"],
[[55, 58], "v1", "dma-packet"]
],
"(method 8 merc-ctrl)": [
[46, "s2", "pointer"], // was merc-fragment-control
[[22, 45], "s2", "merc-fragment-control"],
[[89, 93], "a1", "merc-blend-ctrl"],
[103, "a1", "pointer"]
],
"merc-edge-stats": [
[[33, 35], "v1", "merc-ctrl"]
],
"placeholder-do-not-add-below": []
}

View file

@ -3130,5 +3130,103 @@
"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"
}
},
"(method 9 merc-fragment)": {
"vars":{
"s5-0":"fp-data",
"s4-0":"eye-ctrl",
"s3-0":"shader",
"v1-7":"eye-tex-block",
"v1-34":"eye-tex-block-2",
"v1-57":"tex",
"a0-36":"seg"
}
},
"(method 9 merc-effect)": {
"vars":{
"v1-0":"data",
"v1-1":"tex",
"a0-8":"seg",
"s3-0":"frag-idx",
"s2-0":"ctrl-size",
"s1-0":"geo-size",
"s4-0":["geo", "merc-fragment"],
"s5-0":["ctrl", "merc-fragment-control"]
}
},
"merc-vu1-add-vu-function": {
"args":["dma", "func", "flush-mode"],
"vars": {
"v1-0":"func-data",
"a3-0":"qwc",
"a1-1":"dst",
"t0-1":"qwc-this-time"
}
},
"(method 8 merc-ctrl)": {
"vars": {
"s4-0":"ctrl-mem",
"s3-0":"effect-idx",
"s2-0":["fctrl", "merc-fragment-control"],
"s1-0":"frag-idx",
"v1-35":"effect-mem",
"a0-15":"effect-idx2",
"a1-9":["bctrl", "merc-blend-ctrl"],
"a2-1":"blend-frag-idx"
}
},
"(method 9 merc-ctrl)": {
"vars":{
"v1-3":"seg",
"s5-0":"effect-idx",
"a0-4":"idx-with-bit1",
"a0-7":"this-effect",
"a1-5":"last-effect",
"a2-6":"copy-idx"
}
},
"merc-vu1-init-buffer": {
"args":["dma-bucket", "test"],
"vars": {
"gp-0":"bucket",
"s4-0":"dma-buf"
}
},
"aaaaaaaaaaaaaaaaaaaaaaa": {}
}

View file

@ -1043,7 +1043,7 @@ goos::Object decompile_pair_elt(const LinkedWord& word,
} else if (word.kind == LinkedWord::EMPTY_PTR) {
return pretty_print::to_symbol("'()");
} else if (word.kind == LinkedWord::PLAIN_DATA && (word.data & 0b111) == 0) {
return pretty_print::to_symbol(fmt::format("(the binteger {})", word.data >> 3));
return pretty_print::to_symbol(fmt::format("(the binteger {})", ((s32)word.data) >> 3));
} else {
throw std::runtime_error(fmt::format("Pair elt did not have a good word kind"));
}

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?))

View file

@ -128,7 +128,7 @@
:size-assert #x14
:flag-assert #xd00000014
(:methods
(dummy-9 (_type_) _type_ 9)
(login (_type_) _type_ 9)
(dummy-10 (_type_ string type) art-element 10)
(dummy-11 (_type_ string type) int 11)
(dummy-12 (_type_) symbol 12)
@ -141,7 +141,6 @@
:size-assert #x20
:flag-assert #xd00000020
(:methods
(dummy-9 (_type_) _type_ 9)
(dummy-10 (_type_ string type) art-element 10)
(dummy-11 (_type_ string type) int 11)
(dummy-12 (_type_) symbol 12)
@ -163,6 +162,7 @@
(artist-step float :offset 28)
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
(blerc-data (pointer uint8) :offset 40) ;; todo, this is probably something else
(frames pointer :offset 44)
(data joint-anim-compressed :dynamic)
)

View file

@ -54,31 +54,30 @@
)
;; update base ptr of dma-buffer to point after the buckets.
(set! (-> dma-buf base) (the-as pointer current-bucket))
initial-bucket
(the (inline-array dma-bucket) initial-bucket)
)
)
(defun dma-buffer-patch-buckets ((bucket dma-bucket) (count int))
(defun dma-buffer-patch-buckets ((bucket (inline-array dma-bucket)) (count int))
"After adding all data to buckets, call this to stitch together the chains for
count consecutive buckets"
count consecutive buckets"
(when (nonzero? bucket)
(dotimes (i count)
;; set last tag's address to the next bucket.
(set! (-> bucket last 0 addr) (the-as int (&+ (the-as pointer bucket) 16)))
(set! (-> bucket 0 last 0 addr) (the-as int (the-as pointer (-> bucket 1))))
;; clear last pointer.
(set! (-> bucket last) (the-as (pointer dma-tag) 0))
(set! (-> bucket 0 last) (the-as (pointer dma-tag) 0))
;; next bucket
(set! bucket (&+ bucket 16))
(set! bucket (the-as (inline-array dma-bucket) (-> bucket 1)))
)
)
bucket
)
(defun dma-bucket-insert-tag ((base dma-bucket) (idx bucket-id) (tag-start pointer) (tag-end (pointer dma-tag)))
"Add a dma chain to the idx bucket"
(defun dma-bucket-insert-tag ((base (inline-array dma-bucket)) (idx bucket-id) (tag-start pointer) (tag-end (pointer dma-tag)))
"Add a DMA chain to the bucket"
;; find the bucket
(let ((bucket (the-as dma-bucket (&+ base (the-as uint (shl idx 4))))))
(let ((bucket (-> base idx)))
;; update our last bucket to point to this one.
;; this is abusing the dma-bucket type to set the "addr" field of the dma-tag.
(set! (-> (the-as dma-bucket (-> bucket last)) next) (the-as uint tag-start))
@ -87,3 +86,4 @@
)
tag-start
)

View file

@ -232,9 +232,7 @@
)
;; add the buckets
(set! (-> new-frame bucket-group)
(the-as dma-bucket (dma-buffer-add-buckets (-> new-frame calc-buf) 69))
)
(set! (-> new-frame bucket-group)(dma-buffer-add-buckets (-> new-frame calc-buf) 69))
)
;; initialize the debug bucket

View file

@ -66,3 +66,5 @@
(set! (-> *eye-control-array* data v1-5 random-time) (the-as uint 60))
(set! (-> *eye-control-array* data v1-5 blink) 0.0)
)
(define-extern get-eye-block (function int int int))

File diff suppressed because it is too large Load diff

View file

@ -74,7 +74,7 @@
(vu1-buf dma-buffer :offset 8)
(debug-buf dma-buffer :offset 36)
(global-buf dma-buffer :offset 40)
(bucket-group dma-bucket :offset 44)
(bucket-group (inline-array dma-bucket) :offset 44)
(buffer dma-buffer 11 :offset 4)
(profile-bar profile-bar 2 :offset 48)
(run-time uint64 :offset 56)

View file

@ -8,8 +8,8 @@
;; VU1 renderers are enabled/disabled with a bitmask.
;; I believe this is renderers which can be enabled/disabled in the debug menu?
(define *vu1-enable-user-menu*
#x1FFFF8)
;; 1024 = merc
(define *vu1-enable-user-menu* #x1FFFF8)
;; by default, all off.
;; the menu renderers get copied to this on each frame

View file

@ -5,3 +5,118 @@
;; name in dgo: merc-blend-shape
;; dgos: GAME, ENGINE
;; The merc-blend-shape renderer does face animations.
;; This is missing most functions right now, but just has the types that we need for
;; looking into merc.
(define *stats-blerc* #f)
(deftype blerc-block-header (structure)
((tag generic-merc-tag :inline :offset-assert 0)
(vtx-count uint32 :offset-assert 16)
(overlap uint32 :offset-assert 20)
(lump-dest uint32 :offset-assert 24)
(lump-qwc uint32 :offset-assert 28)
)
:method-count-assert 9
:size-assert #x20
:flag-assert #x900000020
)
(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 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)
(next uint32 :offset-assert 4)
(min-val int16 :offset-assert 8)
(max-val int16 :offset-assert 10)
(fragment-count int32 :offset-assert 12)
(vtx-count int32 :offset-assert 16)
(target-vtx-count int32 :offset-assert 20)
)
:method-count-assert 9
:size-assert #x18
:flag-assert #x900000018
)
(define *blerc-globals* (new 'global 'blerc-globals))
(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
)
(defun-debug blerc-stats-init ()
(when *stats-blerc*
(when (nonzero? (-> *blerc-globals* fragment-count))
(format *stdcon* "~%BLERC (merc blend target) STATS~%")
(format *stdcon* " ~D fragments, ~D vertices~%"
(-> *blerc-globals* fragment-count)
(-> *blerc-globals* vtx-count)
)
(format *stdcon* " ~D blend target computations (~F average)~%"
(-> *blerc-globals* target-vtx-count)
(/ (the float (-> *blerc-globals* target-vtx-count))
(the float (-> *blerc-globals* vtx-count))
)
)
(if (< (-> *blerc-globals* min-val) 0)
(format *stdcon* "MINIMUM OUT OF RANGE: ~D~%" (-> *blerc-globals* min-val))
)
(if (< 255 (-> *blerc-globals* max-val))
(format *stdcon* "MAXIMUM OUT OF RANGE: ~D~%" (-> *blerc-globals* max-val))
)
)
(let ((a0-7 *blerc-globals*))
(set! (-> a0-7 min-val) 255)
(set! (-> a0-7 max-val) 0)
(set! (-> a0-7 fragment-count) 0)
(set! (-> a0-7 vtx-count) 0)
(set! (-> a0-7 target-vtx-count) 0)
)
)
0
(none)
)
(defun blerc-init ()
(blerc-stats-init)
(let ((v1-0 *blerc-globals*))
(set! (-> v1-0 first) (the-as uint 0))
(set! (-> v1-0 next) (the-as uint 0))
)
0
(none)
)
;; todo blerc-a-fragment (unused)
;; todo dma-from-spr (unused)
;; todo merc-dma-chain-to-spr (unused)
;; todo blerc-execute
;; todo merc-blend-shape
;; todo setup-blerc-chains

View file

@ -19,6 +19,7 @@
(set! (-> ripple-merc-query heap-base) 16)
;; header to fragments uploaded to VU.
(deftype merc-byte-header (structure)
((srcdest-off uint8 :offset-assert 0)
(rgba-off uint8 :offset-assert 1)
@ -40,6 +41,12 @@
:flag-assert #x900000017
)
;; merc VU fragment.
;; The mm-quadword-size includes the header.
;; The data itself is split into two parts:
;; - ??
;; - fp data, containing a merc-fp-data then "fp" data.
;; the merc-fragment-fp-data function will get a pointer to fp data.
(deftype merc-fragment (structure)
((header merc-byte-header :inline :offset-assert 0)
(rest uint8 1 :offset-assert 23)
@ -48,7 +55,7 @@
:size-assert #x18
:flag-assert #xa00000018
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -71,11 +78,13 @@
:flag-assert #x90000000c
)
;; header for fp data within a fragment. Is included in fp data.
;; adgifs come right after the header
(deftype merc-fp-header (structure)
((x-add float :offset-assert 0)
(y-add float :offset-assert 4)
(z-add float :offset-assert 8)
(shader-cnt uint8 :offset-assert 12)
(shader-cnt uint8 :offset-assert 12) ;; number of adgifs
(kick-info-offset uint8 :offset-assert 13)
(kick-info-step uint8 :offset-assert 14)
(hword-cnt uint8 :offset-assert 15)
@ -87,24 +96,27 @@
(defun merc-fragment-fp-data ((arg0 merc-fragment))
"Get the floating-point data of a merc-fragment"
(the pointer (&+ arg0 (the-as uint (shl (-> arg0 header mm-quadword-fp-off) 4))))
(the merc-fp-header (&+ arg0 (the-as uint (shl (-> arg0 header mm-quadword-fp-off) 4))))
)
(deftype merc-mat-dest (structure)
((matrix-number uint8 :offset-assert 0)
(matrix-dest uint8 :offset-assert 1)
)
:pack-me
:method-count-assert 9
:size-assert #x2
:flag-assert #x900000002
)
;; some info about a merc fragment that will stay on the EE.
;; the merc-effect contains a ref to one of these
(deftype merc-fragment-control (structure)
((unsigned-four-count uint8 :offset-assert 0)
(lump-four-count uint8 :offset-assert 1)
(fp-qwc uint8 :offset-assert 2)
(mat-xfer-count uint8 :offset-assert 3)
(mat-dest-data uint8 :dynamic :offset-assert 4)
(mat-dest-data merc-mat-dest :inline :dynamic :offset-assert 4)
)
:method-count-assert 9
:size-assert #x4
@ -188,12 +200,15 @@
(dummy1 uint8 :offset-assert 26)
(envmap-usage uint8 :offset-assert 27)
(extra-info merc-extra-info :offset-assert 28)
;; added
(data uint64 4 :offset 0)
)
:method-count-assert 10
:size-assert #x20
:flag-assert #xa00000020
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -234,6 +249,8 @@
:flag-assert #x900000008
)
;; metadata for merc art
(deftype merc-ctrl-header (structure)
((xyz-scale float :offset-assert 0)
(st-magic uint32 :offset-assert 4)
@ -282,6 +299,7 @@
;; field xyz-scale is a float printed as hex?
)
;; the actual merc art object.
(deftype merc-ctrl (art-element)
((num-joints int32 :offset 20)
(header merc-ctrl-header :inline :offset-assert 32)
@ -293,8 +311,8 @@
)
(deftype merc-vu1-low-mem (structure)
((tri-strip-gif qword :inline :offset-assert 0)
(ad-gif qword :inline :offset-assert 16)
((tri-strip-gif gs-gif-tag :inline :offset-assert 0) ;; was qword
(ad-gif gs-gif-tag :inline :offset-assert 16) ;; was qword
(hvdf-offset vector :inline :offset-assert 32)
(perspective uint128 4 :offset-assert 48)
(fog vector :inline :offset-assert 112)

View file

@ -6,3 +6,5 @@
;; dgos: GAME, ENGINE
;; all this contains is the merc-vu1-block
(define merc-vu1-block (the vu-function 0))

View file

@ -5,6 +5,683 @@
;; name in dgo: merc
;; dgos: GAME, ENGINE
(defun merc-vu1-init-buffers ()
;; TODO stub
;; This file contains the EE code for MERC
;; The merc renderer is used to draw characters and other dynamic things.
;; It supports a number of effects and can interact with other renderers.
;; It's the most complicated renderer in the game and its code uses almost the entire VU1 code memory.
;; The interface with the rest of the art world is merc-ctrl, which is an art-element.
;; It contains a merc-ctrl-header which has the metadata.
;; It also has an array of merc-effects which contain the actual data.
;; contains the header for the currently logging-in thing.
(define *merc-ctrl-header* (the-as merc-ctrl-header #f))
(defmethod asize-of merc-fragment ((obj merc-fragment))
"Get the size in memory of a merc-fragment"
(the-as int (* (-> obj header mm-quadword-size) 16))
)
(defmethod login-adgifs merc-fragment ((obj merc-fragment))
"Set up a merc-fragment. Does adgifs and eye stuff"
(let* ((fp-data (merc-fragment-fp-data obj))
(eye-ctrl
(the-as merc-eye-ctrl (if (nonzero? (-> *merc-ctrl-header* eye-ctrl))
(-> *merc-ctrl-header* eye-ctrl)
(the-as merc-eye-ctrl #f)
)
)
)
(shader (the-as adgif-shader (&+ fp-data 16)))
)
(dotimes (s2-0 (the-as int (-> fp-data shader-cnt)))
(cond
((and eye-ctrl (= (logand -256 (-> shader texture-id)) #x1cf06f00))
;; eye slot 0
(adgif-shader-login shader)
(let ((eye-tex-block (get-eye-block (-> eye-ctrl eye-slot) 0)))
(set! (-> shader tex0 tbp0) eye-tex-block)
)
(set! (-> shader tex0 tw) 5)
(set! (-> shader tex0 th) 5)
(set! (-> shader tex0 tcc) 1)
(set! (-> shader tex0 tbw) 1)
(set! (-> shader tex0 psm) 0)
(set! (-> shader tex1 mxl) 0)
(set! (-> shader clamp)
(new 'static 'gs-clamp
:wms (gs-tex-wrap-mode clamp)
:wmt (gs-tex-wrap-mode clamp)
:maxu #x1f
:maxv #x1f
)
)
)
((and eye-ctrl (= (logand -256 (-> shader texture-id)) #x1cf07000))
;; eye slot 1
(adgif-shader-login shader)
(let ((eye-tex-block-2 (get-eye-block (-> eye-ctrl eye-slot) 1)))
(set! (-> shader tex0 tbp0) eye-tex-block-2)
)
(set! (-> shader tex0 tw) 5)
(set! (-> shader tex0 th) 5)
(set! (-> shader tex0 tcc) 1)
(set! (-> shader tex0 tbw) 1)
(set! (-> shader tex0 psm) 0)
(set! (-> shader tex1 mxl) 0)
(set! (-> shader clamp)
(new 'static 'gs-clamp
:wms (gs-tex-wrap-mode clamp)
:wmt (gs-tex-wrap-mode clamp)
:maxu #x1f
:maxv #x1f
)
)
)
(else
;; normal. just login and set tex masks.
(let ((tex (adgif-shader-login shader)))
(when tex
(dotimes (seg 3)
(logior! (-> *merc-ctrl-header* masks seg) (-> tex masks seg))
)
)
)
)
)
(&+! shader 80)
)
)
(none)
)
(defmethod inspect merc-fragment-control ((obj merc-fragment-control))
"Debug print a merc-fragment-control"
(format #t "[~8x] ~A~%" obj 'merc-fragment-control)
(format #t "~Tunsigned-four-count: ~D~%" (-> obj unsigned-four-count))
(format #t "~Tlump-four-count: ~D~%" (-> obj lump-four-count))
(format #t "~Tfp-qwc: ~D~%" (-> obj fp-qwc))
(format #t "~Tmat-xfer-count: ~D~%" (-> obj mat-xfer-count))
(dotimes (s5-0 (the-as int (-> obj mat-xfer-count)))
(format #t "~Tmat-dest-data[~d]:~%" s5-0)
(format #t "~T~Tmatrix-number: ~D~%"(-> obj mat-dest-data s5-0 matrix-number))
(format #t "~T~Tmatrix-dest: ~D~%" (-> obj mat-dest-data s5-0 matrix-dest))
)
obj
)
(defmethod login-adgifs merc-effect ((obj merc-effect))
"Login everything for this merc-effect."
;; login adgifs, if we have them.
(let ((data (-> obj extra-info)))
(when (nonzero? data)
(when (nonzero? (-> data shader-offset))
(let ((tex (adgif-shader-login
(the-as
adgif-shader
(+ (the-as uint data) (* (-> data shader-offset) 16))
)
)
)
)
(when tex
(dotimes (seg 3)
(logior! (-> *merc-ctrl-header* masks seg) (-> tex masks seg))
)
)
)
)
)
)
;; login fragment geometry and control. ctrls don't need logins
(let ((ctrl (-> obj frag-ctrl))
(geo (-> obj frag-geo))
)
(dotimes (frag-idx (the-as int (-> obj frag-count)))
(let ((ctrl-size (asize-of ctrl)))
(let ((geo-size (asize-of geo)))
(login-adgifs geo)
(set! geo (the-as merc-fragment (&+ (the-as pointer geo) geo-size)))
)
(set! ctrl (the-as merc-fragment-control (&+ (the-as pointer ctrl) ctrl-size)))
)
)
)
(none)
)
(defmethod inspect merc-ctrl ((obj merc-ctrl))
"Print a merc-ctrl"
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tname: ~A~%" (-> obj name))
(format #t "~Tlength: ~D~%" (-> obj length))
(format #t "~Tnum-joints: ~D~%" (-> obj num-joints))
(format #t "~Textra: ~A~%" (-> obj extra))
(inspect (-> obj header))
(dotimes (s5-0 (the-as int (-> obj header effect-count)))
(inspect (-> obj effect s5-0))
)
obj
)
(defmethod mem-usage merc-ctrl ((obj merc-ctrl) (arg0 memory-usage-block) (arg1 int))
"Compute memory usage stats for a merc-ctrl"
;; do extra
(if (-> obj extra)
(mem-usage (-> obj extra) arg0 arg1)
)
;; do merc ctrls in each effect:
(let ((ctrl-mem (+ 32 80 (* (-> obj header effect-count) 32))))
(dotimes (effect-idx (the-as int (-> obj header effect-count)))
(let ((fctrl (-> obj effect effect-idx frag-ctrl)))
(dotimes (frag-idx (the-as int (-> obj effect effect-idx frag-count)))
(set! ctrl-mem (+ ctrl-mem
(* (shr (+ (-> fctrl unsigned-four-count) 3) 2) 16)
(* (shr (+ (-> fctrl lump-four-count) 3) 2) 16)
(* (-> fctrl fp-qwc) 16)
(asize-of fctrl)
)
)
(set! fctrl (the-as merc-fragment-control (&+ (the-as pointer fctrl) (asize-of fctrl))))
)
)
)
(set! (-> arg0 length) (max 76 (-> arg0 length)))
(set! (-> arg0 data 75 name) "merc-ctrl")
(+! (-> arg0 data 75 count) 1)
(+! (-> arg0 data 75 used) ctrl-mem)
(+! (-> arg0 data 75 total) (logand -16 (+ ctrl-mem 15)))
)
;; do effect blend shapes
(let ((effect-mem 0))
(dotimes (effect-idx2 (the-as int (-> obj header effect-count)))
(when (nonzero? (-> obj effect effect-idx2 blend-frag-count))
(let ((bctrl (-> obj effect effect-idx2 blend-ctrl)))
(dotimes (blend-frag-idx (the-as int (-> obj effect effect-idx2 blend-frag-count)) )
(let ((v1-36 (+ effect-mem
(* (+ (-> bctrl nonzero-index-count) 1)
(the-as uint (logand (+ (* (the-as uint 6) (-> bctrl blend-vtx-count)) 15) #xfff0))
)
)
)
)
(set! effect-mem (the-as int (+ (-> obj header blend-target-count) 2 v1-36)))
)
(set! bctrl (the-as merc-blend-ctrl (&+ (the-as pointer bctrl) (+ (-> obj header blend-target-count) 2))))
)
)
)
)
(when (nonzero? effect-mem)
(set! (-> arg0 length) (max 78 (-> arg0 length)))
(set! (-> arg0 data 77 name) "blend-shape")
(+! (-> arg0 data 77 count) 1)
(+! (-> arg0 data 77 used) effect-mem)
(+! (-> arg0 data 77 total) (logand -16 (+ effect-mem 15)))
)
)
;; do eyes.
(when (nonzero? (-> obj header eye-ctrl))
(let ((a0-28 (-> obj header eye-ctrl)))
(set! (-> arg0 length) (max 109 (-> arg0 length)))
(set! (-> arg0 data 108 name) "eye-anim")
(+! (-> arg0 data 108 count) 1)
(let ((v1-47 (asize-of a0-28)))
(+! (-> arg0 data 108 used) v1-47)
(+! (-> arg0 data 108 total) (logand -16 (+ v1-47 15)))
)
)
)
obj
)
(defmethod login merc-ctrl ((obj merc-ctrl))
"Log in a merc-ctrl."
;; so we can find it
(set! *merc-ctrl-header* (-> obj header))
;; clear masks. logging in will set these for textures we need.
(dotimes (v1-1 3)
(set! (-> *merc-ctrl-header* masks v1-1) (the-as uint 0))
)
;; login the effects
(dotimes (effect-idx (the-as int (-> obj header effect-count)))
(login-adgifs (-> obj effect effect-idx))
)
;; some weird hack to swap two effects.
(let ((idx-with-bit1 -1)
(a1-1 (-> obj header effect-count))
)
(dotimes (v1-11 (the-as int a1-1))
(if (logtest? (-> obj effect v1-11 effect-bits) 2)
(set! idx-with-bit1 v1-11)
)
)
(when (!= idx-with-bit1 -1)
(let ((v1-16 4)
(this-effect (-> obj effect idx-with-bit1))
(last-effect (-> obj effect (+ a1-1 -1)))
)
(dotimes (copy-idx v1-16)
(let ((a3-2 (-> this-effect data copy-idx)))
(set! (-> this-effect data copy-idx) (-> last-effect data copy-idx))
(set! (-> last-effect data copy-idx) a3-2)
)
)
)
)
)
;; login eye.
(cond
((zero? (logand -65536 (the-as int (-> obj header eye-ctrl))))
;; no idea what this is for.
(set! (-> obj header eye-ctrl) (the-as merc-eye-ctrl 0))
0
)
(else
(let ((s5-1 (-> obj header eye-ctrl)))
;; login and set masks
(dotimes (s4-0 3)
(let ((v1-25 (adgif-shader-login (-> s5-1 shader s4-0))))
(when v1-25
(dotimes (a0-11 3)
(logior! (-> *merc-ctrl-header* masks a0-11) (-> v1-25 masks a0-11))
)
)
)
)
)
)
)
obj
)
(defun-debug merc-stats-display ((arg0 merc-ctrl))
"Print debug stats to #t."
(format #t "~30s:" (-> arg0 name))
(let ((s5-0 (-> arg0 header st-int-scale))
(s4-0 (ash 1 (- 12 (the-as int (-> arg0 header st-int-scale)))))
)
(format #t " ST ~3D, " s4-0)
(cond
((>= s5-0 (the-as uint 5))
(format #t "RANGE ~D+," (/ 128 s4-0))
)
((= s5-0 4)
(format #t "RANGE 0.5+,")
)
)
)
(dotimes (s5-1 (the-as int (-> arg0 header effect-count)))
(let ((s3-0 (-> arg0 effect s5-1)))
(if (nonzero? s5-1)
(format #t "~48s " " ")
)
(let ((a2-4 (-> s3-0 frag-count))
(s4-1 (-> s3-0 tri-count))
(f30-0 (the float (-> s3-0 frag-count)))
(f28-0 (the float (-> s3-0 dvert-count)))
(f26-0 (the float (-> s3-0 tri-count)))
)
(if (>= (/ (+ 50.0 f28-0) f30-0) 50.0)
(format #t "~3D frags, ~2,,1f dverts/frag " a2-4 (/ f28-0 f30-0))
(format #t "~3D frags, ~2,,1f ******/**** " a2-4 (/ f28-0 f30-0))
)
(format #t "(~4D tris, striplen ~2,,2f, ~2,,1f tris/frag)~%"
s4-1
(/ (* 2.0 f26-0) (- f28-0 f26-0))
(/ f26-0 f30-0)
)
)
)
)
(none)
)
(defun-debug merc-stats ()
"Iterate through all merc-ctrls and print."
(dotimes (gp-0 3) ;; levels
(let ((s5-0 (-> *level* level gp-0 art-group)))
(when (nonzero? s5-0)
(dotimes (s4-0 (-> s5-0 art-group-array length)) ;; art-groups
(let ((s3-0 (-> s5-0 art-group-array s4-0)))
(dotimes (s2-0 (-> s3-0 length)) ;; arts
(let* ((s1-0 (-> s3-0 data s2-0))
(a0-3 (if (and (nonzero? s1-0) (type-type? (-> s1-0 type) merc-ctrl))
s1-0
)
)
)
(if a0-3
(merc-stats-display (the-as merc-ctrl a0-3))
)
)
)
)
)
)
)
)
0
(none)
)
(defun-debug merc-edge-stats ()
"Print the longest edges in each."
(dotimes (gp-0 3)
(let ((s5-0 (-> *level* level gp-0 art-group)))
(when (nonzero? s5-0)
(dotimes (s4-0 (-> s5-0 art-group-array length))
(let ((s3-0 (-> s5-0 art-group-array s4-0)))
(dotimes (s2-0 (-> s3-0 length))
(let* ((s1-0 (-> s3-0 data s2-0))
(v1-10
(if (and (nonzero? s1-0) (type-type? (-> s1-0 type) merc-ctrl))
s1-0
)
)
)
(if v1-10
(format
#t
"~30s: ~f~%"
(-> (the-as merc-ctrl v1-10) name)
(-> (the-as merc-ctrl v1-10) header longest-edge)
)
)
)
)
)
)
)
)
)
0
(none)
)
(defun merc-vu1-add-vu-function ((dma dma-packet) (func vu-function) (flush-mode int))
"Add a function to a dma chain. Return pointer to chain after the upload data."
(let ((func-data (&-> func data 4))
(qwc (-> func qlength))
(dst (-> func origin))
)
(while (> qwc 0)
(let ((qwc-this-time (min 127 qwc))) ;; only 127 at a time
(set! (-> dma dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:qwc qwc-this-time
:addr (the-as int func-data)
)
)
(set! (-> dma vif0) (new 'static 'vif-tag :cmd (if (zero? flush-mode) (vif-cmd flushe) (vif-cmd flusha))))
(set! (-> dma vif1)
(new 'static 'vif-tag
:cmd (vif-cmd mpg)
:num (* qwc-this-time 2)
:imm dst
)
)
(&+! dma 16)
(&+! func-data (* qwc-this-time 16))
(set! qwc (- qwc qwc-this-time))
(+! dst (* qwc-this-time 2))
)
)
)
(the-as dma-gif-packet dma)
)
(defun merc-vu1-initialize-chain ((arg0 dma-gif-packet))
"Initialize a merc chain."
;; upload the function.
(let ((gp-0 (the-as object (merc-vu1-add-vu-function (the-as dma-packet arg0) merc-vu1-block 1))))
;; now set up the VIF.
(set! (-> (the-as dma-gif-packet gp-0) dma-vif dma) (new 'static 'dma-tag :qwc #xa :id (dma-tag-id cnt)))
(set! (-> (the-as dma-gif-packet gp-0) dma-vif vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl)))
(set! (-> (the-as dma-gif-packet gp-0) dma-vif vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod)))
(set! (-> (the-as (pointer vif-tag) gp-0) 4) (new 'static 'vif-tag :imm #x1ba :cmd (vif-cmd base)))
(set! (-> (the-as (pointer vif-tag) gp-0) 5) (new 'static 'vif-tag :imm #xfe46 :cmd (vif-cmd offset)))
(set! (-> (the-as (pointer vif-tag) gp-0) 6) (new 'static 'vif-tag))
;; upload VU low memory
(set! (-> (the-as (pointer vif-tag) gp-0) 7) (new 'static 'vif-tag :num #x8 :cmd (vif-cmd unpack-v4-32)))
;; template:
(let ((s5-0 (the-as merc-vu1-low-mem (&+ (the-as dma-gif-packet gp-0) 32))))
(set! (-> s5-0 tri-strip-gif tag)
(new 'static 'gif-tag64
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
:nreg #x3
)
)
(set! (-> s5-0 tri-strip-gif regs)
(new 'static 'gif-tag-regs
:regs0 (gif-reg-id st)
:regs1 (gif-reg-id rgbaq)
:regs2 (gif-reg-id xyzf2)
)
)
;; what is this, they snuck something in here...
(set! (-> s5-0 tri-strip-gif word 3)
(shr (make-u128 0 (shl #x303e4000 32)) 32)
)
(set! (-> s5-0 ad-gif tag) (new 'static 'gif-tag64 :nloop #x5 :nreg #x1))
(set! (-> s5-0 ad-gif regs) (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)))
(set! (-> s5-0 hvdf-offset quad) (-> *math-camera* hvdf-off quad))
(quad-copy! (-> s5-0 perspective) (the-as pointer (-> *math-camera* perspective)) 4)
(set-vector!
(-> s5-0 fog)
(-> *math-camera* pfog0)
(-> *math-camera* fog-min)
(-> *math-camera* fog-max)
0.0
)
)
;; end.
(let ((v1-20 (-> (the-as (inline-array dma-packet) gp-0) 10)))
(set! (-> v1-20 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
(set! (-> v1-20 vif0) (new 'static 'vif-tag))
(set! (-> v1-20 vif1) (new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #x0))
(&+ v1-20 16)
)
)
(none)
)
(defun merc-vu1-init-buffer ((dma-bucket bucket-id) (test gs-test) (arg2 int))
"Setup merc DMA buffer."
;; This function works differently from most and splices to the beginning of the bucket, as
;; drawing has already put stuff in buckets.
;; The advantage of this is that we can check if nothing was drawn, then skip this.
;; NOTE: This runs as part of display-frame-finish, so after previous DMA is synced.
;; grab out bucket directly.
(let ((bucket (-> *display* frames (-> *display* on-screen) frame bucket-group dma-bucket)))
;; only if we draw anything.
(when (!= bucket (-> bucket last))
(let* ((dma-buf (-> *display* frames (-> *display* on-screen) frame global-buf))
(draw-data-start (-> dma-buf base)) ;; remember old beginning
)
;; set the beginning to be the merc init stuff.
(set! (-> dma-buf base)
(the-as pointer (merc-vu1-initialize-chain (the-as dma-gif-packet (-> dma-buf base))) )
)
;; some other merc setup for the GS.
(let* ((v1-8 dma-buf)
(a0-6 (the-as object (-> v1-8 base)))
)
(set! (-> (the-as dma-packet a0-6) dma) (new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt)))
(set! (-> (the-as dma-packet a0-6) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet a0-6) vif1)
(new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)
)
(set! (-> v1-8 base) (&+ (the-as pointer a0-6) 16))
)
(let* ((v1-9 dma-buf)
(a0-8 (the-as object (-> v1-9 base)))
)
(set! (-> (the-as gs-gif-tag a0-8) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1))
(set! (-> (the-as gs-gif-tag a0-8) regs)
(new 'static 'gif-tag-regs
:regs0 (gif-reg-id a+d)
:regs1 (gif-reg-id a+d)
:regs2 (gif-reg-id a+d)
:regs3 (gif-reg-id a+d)
:regs4 (gif-reg-id a+d)
:regs5 (gif-reg-id a+d)
:regs6 (gif-reg-id a+d)
:regs7 (gif-reg-id a+d)
:regs8 (gif-reg-id a+d)
:regs9 (gif-reg-id a+d)
:regs10 (gif-reg-id a+d)
:regs11 (gif-reg-id a+d)
:regs12 (gif-reg-id a+d)
:regs13 (gif-reg-id a+d)
:regs14 (gif-reg-id a+d)
:regs15 (gif-reg-id a+d)
)
)
(set! (-> v1-9 base) (&+ (the-as pointer a0-8) 16))
)
(let* ((v1-10 dma-buf)
(a0-10 (-> v1-10 base))
)
(set! (-> (the-as (pointer gs-test) a0-10) 0) test)
(set! (-> (the-as (pointer gs-reg64) a0-10) 1) (gs-reg64 test-1))
(set! (-> v1-10 base) (&+ a0-10 16))
)
;; terminate as normal
(let ((v1-11 (the-as object (-> dma-buf base))))
(set! (-> (the-as dma-packet v1-11) dma)
(new 'static 'dma-tag :id (dma-tag-id next) :addr (-> bucket next))
)
(set! (-> (the-as dma-packet v1-11) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet v1-11) vif1) (new 'static 'vif-tag))
(set! (-> dma-buf base) (&+ (the-as pointer v1-11) 16))
)
;; but splice the existing chain.
(set! (-> bucket next) (the-as uint draw-data-start))
)
)
)
0
(none)
)
(defun merc-vu1-init-buffers ()
"Setup merc DMA buffers. Call this _after_ drawing."
(when (logtest? *vu1-enable-user* 1024)
(merc-vu1-init-buffer
(bucket-id bucket-10)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-49)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-17)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-52)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-45)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-55)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-58)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x80
:afail #x1
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-61)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x80
:afail #x1
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
)
0
(none)
)

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)

View file

@ -573,7 +573,7 @@
(let ((v1-39 (- (the-as uint current-login-pos) (the-as uint (-> level-drawable-trees length)))))
(when (< (the-as int v1-39) (-> loaded-level art-group art-group-array length))
(let ((s2-2 (-> loaded-level art-group art-group-array v1-39)))
(dummy-9 s2-2)
(login s2-2)
(if (dummy-12 s2-2)
(link-art! s2-2)
)

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
)
)
)
)

View file

@ -134,7 +134,7 @@
)|#
(let ((s5-0 (the-as art (loado arg0 arg1))))
(if (type-type? (-> s5-0 type) art)
(dummy-9 s5-0)
(login s5-0)
(the-as art #f)
)
)
@ -164,7 +164,7 @@
(the-as art-group #f)
)
(else
(dummy-9 s3-1)
(login s3-1)
)
)
)
@ -462,7 +462,7 @@
(set! (-> obj status) 'error)
)
(else
(dummy-9 s4-0)
(login s4-0)
(set! (-> obj status) 'locked) ;; make file ready to be used
)
)

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)))
)

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?))

View file

@ -228,7 +228,7 @@
:size-assert #x14
:flag-assert #xd00000014
(:methods
(dummy-9 (_type_) _type_ 9)
(login (_type_) _type_ 9)
(dummy-10 (_type_ string type) art-element 10)
(dummy-11 (_type_ string type) int 11)
(dummy-12 (_type_) symbol 12)
@ -279,6 +279,7 @@
(artist-step float :offset 28)
(master-art-group-name string :offset 32)
(master-art-group-index int32 :offset 36)
(blerc-data (pointer uint8) :offset 40)
(frames pointer :offset 44)
(data joint-anim-compressed :dynamic :offset-assert 48)
)

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)

View file

@ -2,7 +2,7 @@
(in-package goal)
;; definition for function dma-buffer-add-buckets
;; INFO: Return type mismatch pointer vs dma-bucket.
;; INFO: Return type mismatch pointer vs (inline-array dma-bucket).
(defun dma-buffer-add-buckets ((dma-buf dma-buffer) (count int))
(let ((v0-0 (-> dma-buf base)))
(let ((current-bucket (the-as dma-bucket v0-0)))
@ -22,17 +22,17 @@
)
(set! (-> dma-buf base) (the-as pointer current-bucket))
)
(the-as dma-bucket v0-0)
(the-as (inline-array dma-bucket) v0-0)
)
)
;; definition for function dma-buffer-patch-buckets
(defun dma-buffer-patch-buckets ((bucket dma-bucket) (count int))
(defun dma-buffer-patch-buckets ((bucket (inline-array dma-bucket)) (count int))
(when (nonzero? bucket)
(dotimes (i count)
(set! (-> bucket last 0 addr) (the-as int (&+ (the-as pointer bucket) 16)))
(set! (-> bucket last) (the-as (pointer dma-tag) 0))
(set! bucket (the-as dma-bucket (&+ (the-as pointer bucket) 16)))
(set! (-> bucket 0 last 0 addr) (the-as int (the-as pointer (-> bucket 1))))
(set! (-> bucket 0 last) (the-as (pointer dma-tag) 0))
(set! bucket (the-as (inline-array dma-bucket) (-> bucket 1)))
)
)
bucket
@ -41,12 +41,12 @@
;; definition for function dma-bucket-insert-tag
(defun
dma-bucket-insert-tag
((base dma-bucket)
((base (inline-array dma-bucket))
(idx bucket-id)
(tag-start pointer)
(tag-end (pointer dma-tag))
)
(let ((bucket (the-as dma-bucket (+ (the-as uint base) (* idx 16)))))
(let ((bucket (-> base idx)))
(set! (-> (the-as dma-bucket (-> bucket last)) next) (the-as uint tag-start))
(set! (-> bucket last) tag-end)
)

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!)

View file

@ -85,14 +85,14 @@
;; definition of type display-frame
(deftype display-frame (basic)
((calc-buf dma-buffer :offset 8)
(vu1-buf dma-buffer :offset 8)
(debug-buf dma-buffer :offset 36)
(global-buf dma-buffer :offset 40)
(bucket-group dma-bucket :offset 44)
(buffer dma-buffer 11 :offset 4)
(profile-bar profile-bar 2 :offset 48)
(run-time uint64 :offset 56)
((calc-buf dma-buffer :offset 8)
(vu1-buf dma-buffer :offset 8)
(debug-buf dma-buffer :offset 36)
(global-buf dma-buffer :offset 40)
(bucket-group (inline-array dma-bucket) :offset 44)
(buffer dma-buffer 11 :offset 4)
(profile-bar profile-bar 2 :offset 48)
(run-time uint64 :offset 56)
)
:method-count-assert 9
:size-assert #x40

View file

@ -81,7 +81,7 @@
:size-assert #x18
:flag-assert #xa00000018
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -160,10 +160,10 @@
)
;; definition for function merc-fragment-fp-data
;; INFO: Return type mismatch int vs pointer.
;; INFO: Return type mismatch int vs merc-fp-header.
(defun merc-fragment-fp-data ((arg0 merc-fragment))
(the-as
pointer
merc-fp-header
(+ (the-as uint arg0) (* (-> arg0 header mm-quadword-fp-off) 16))
)
)
@ -173,6 +173,7 @@
((matrix-number uint8 :offset-assert 0)
(matrix-dest uint8 :offset-assert 1)
)
:pack-me
:method-count-assert 9
:size-assert #x2
:flag-assert #x900000002
@ -188,11 +189,11 @@
;; definition of type merc-fragment-control
(deftype merc-fragment-control (structure)
((unsigned-four-count uint8 :offset-assert 0)
(lump-four-count uint8 :offset-assert 1)
(fp-qwc uint8 :offset-assert 2)
(mat-xfer-count uint8 :offset-assert 3)
(mat-dest-data uint8 :dynamic :offset-assert 4)
((unsigned-four-count uint8 :offset-assert 0)
(lump-four-count uint8 :offset-assert 1)
(fp-qwc uint8 :offset-assert 2)
(mat-xfer-count uint8 :offset-assert 3)
(mat-dest-data merc-mat-dest :inline :dynamic :offset-assert 4)
)
:method-count-assert 9
:size-assert #x4
@ -200,6 +201,7 @@
)
;; definition for method 3 of type merc-fragment-control
;; INFO: this function exists in multiple non-identical object files
(defmethod inspect merc-fragment-control ((obj merc-fragment-control))
(format #t "[~8x] ~A~%" obj 'merc-fragment-control)
(format #t "~Tunsigned-four-count: ~D~%" (-> obj unsigned-four-count))
@ -344,25 +346,26 @@
;; definition of type merc-effect
(deftype merc-effect (structure)
((frag-geo merc-fragment :offset-assert 0)
(frag-ctrl merc-fragment-control :offset-assert 4)
(blend-data merc-blend-data :offset-assert 8)
(blend-ctrl merc-blend-ctrl :offset-assert 12)
(dummy0 uint8 :offset-assert 16)
(effect-bits uint8 :offset-assert 17)
(frag-count uint16 :offset-assert 18)
(blend-frag-count uint16 :offset-assert 20)
(tri-count uint16 :offset-assert 22)
(dvert-count uint16 :offset-assert 24)
(dummy1 uint8 :offset-assert 26)
(envmap-usage uint8 :offset-assert 27)
(extra-info merc-extra-info :offset-assert 28)
((frag-geo merc-fragment :offset-assert 0)
(frag-ctrl merc-fragment-control :offset-assert 4)
(blend-data merc-blend-data :offset-assert 8)
(blend-ctrl merc-blend-ctrl :offset-assert 12)
(dummy0 uint8 :offset-assert 16)
(effect-bits uint8 :offset-assert 17)
(frag-count uint16 :offset-assert 18)
(blend-frag-count uint16 :offset-assert 20)
(tri-count uint16 :offset-assert 22)
(dvert-count uint16 :offset-assert 24)
(dummy1 uint8 :offset-assert 26)
(envmap-usage uint8 :offset-assert 27)
(extra-info merc-extra-info :offset-assert 28)
(data uint64 4 :offset 0)
)
:method-count-assert 10
:size-assert #x20
:flag-assert #xa00000020
(:methods
(dummy-9 () none 9)
(login-adgifs (_type_) none 9)
)
)
@ -569,6 +572,7 @@
)
;; definition for method 3 of type merc-ctrl
;; INFO: this function exists in multiple non-identical object files
(defmethod inspect merc-ctrl ((obj merc-ctrl))
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tname: ~A~%" (-> obj name))
@ -582,11 +586,11 @@
;; definition of type merc-vu1-low-mem
(deftype merc-vu1-low-mem (structure)
((tri-strip-gif qword :inline :offset-assert 0)
(ad-gif qword :inline :offset-assert 16)
(hvdf-offset vector :inline :offset-assert 32)
(perspective uint128 4 :offset-assert 48)
(fog vector :inline :offset-assert 112)
((tri-strip-gif gs-gif-tag :inline :offset-assert 0)
(ad-gif gs-gif-tag :inline :offset-assert 16)
(hvdf-offset vector :inline :offset-assert 32)
(perspective uint128 4 :offset-assert 48)
(fog vector :inline :offset-assert 112)
)
:method-count-assert 9
:size-assert #x80

View file

@ -0,0 +1,758 @@
;;-*-Lisp-*-
(in-package goal)
;; definition for symbol *merc-ctrl-header*, type merc-ctrl-header
(define *merc-ctrl-header* (the-as merc-ctrl-header #f))
;; definition for method 5 of type merc-fragment
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of merc-fragment ((obj merc-fragment))
(the-as int (* (-> obj header mm-quadword-size) 16))
)
;; definition for method 9 of type merc-fragment
;; INFO: Return type mismatch merc-fragment vs none.
(defmethod login-adgifs merc-fragment ((obj merc-fragment))
(let* ((fp-data (merc-fragment-fp-data obj))
(eye-ctrl
(the-as merc-eye-ctrl (if (nonzero? (-> *merc-ctrl-header* eye-ctrl))
(-> *merc-ctrl-header* eye-ctrl)
(the-as merc-eye-ctrl #f)
)
)
)
(shader (the-as adgif-shader (&+ fp-data 16)))
)
(dotimes (s2-0 (the-as int (-> fp-data shader-cnt)))
(cond
((and eye-ctrl (= (logand -256 (-> shader texture-id)) #x1cf06f00))
(adgif-shader-login shader)
(let ((eye-tex-block (get-eye-block (-> eye-ctrl eye-slot) 0)))
(set! (-> shader tex0 tbp0) eye-tex-block)
)
(set! (-> shader tex0 tw) 5)
(set! (-> shader tex0 th) 5)
(set! (-> shader tex0 tcc) 1)
(set! (-> shader tex0 tbw) 1)
(set! (-> shader tex0 psm) 0)
(set! (-> shader tex1 mxl) 0)
(set!
(-> shader clamp)
(new 'static 'gs-clamp
:wms (gs-tex-wrap-mode clamp)
:wmt (gs-tex-wrap-mode clamp)
:maxu #x1f
:maxv #x1f
)
)
)
((and eye-ctrl (= (logand -256 (-> shader texture-id)) #x1cf07000))
(adgif-shader-login shader)
(let ((eye-tex-block-2 (get-eye-block (-> eye-ctrl eye-slot) 1)))
(set! (-> shader tex0 tbp0) eye-tex-block-2)
)
(set! (-> shader tex0 tw) 5)
(set! (-> shader tex0 th) 5)
(set! (-> shader tex0 tcc) 1)
(set! (-> shader tex0 tbw) 1)
(set! (-> shader tex0 psm) 0)
(set! (-> shader tex1 mxl) 0)
(set!
(-> shader clamp)
(new 'static 'gs-clamp
:wms (gs-tex-wrap-mode clamp)
:wmt (gs-tex-wrap-mode clamp)
:maxu #x1f
:maxv #x1f
)
)
)
(else
(let ((tex (adgif-shader-login shader)))
(when tex
(dotimes (seg 3)
(logior! (-> *merc-ctrl-header* masks seg) (-> tex masks seg))
)
)
)
)
)
(&+! shader 80)
)
)
(none)
)
;; definition for method 5 of type merc-fragment-control
;; INFO: Return type mismatch uint vs int.
(defmethod asize-of merc-fragment-control ((obj merc-fragment-control))
(the-as int (+ (* (-> obj mat-xfer-count) 2) 4))
)
;; definition for method 3 of type merc-fragment-control
;; INFO: this function exists in multiple non-identical object files
(defmethod inspect merc-fragment-control ((obj merc-fragment-control))
(format #t "[~8x] ~A~%" obj 'merc-fragment-control)
(format #t "~Tunsigned-four-count: ~D~%" (-> obj unsigned-four-count))
(format #t "~Tlump-four-count: ~D~%" (-> obj lump-four-count))
(format #t "~Tfp-qwc: ~D~%" (-> obj fp-qwc))
(format #t "~Tmat-xfer-count: ~D~%" (-> obj mat-xfer-count))
(dotimes (s5-0 (the-as int (-> obj mat-xfer-count)))
(format #t "~Tmat-dest-data[~d]:~%" s5-0)
(format
#t
"~T~Tmatrix-number: ~D~%"
(-> obj mat-dest-data s5-0 matrix-number)
)
(format #t "~T~Tmatrix-dest: ~D~%" (-> obj mat-dest-data s5-0 matrix-dest))
)
obj
)
;; definition for method 9 of type merc-effect
;; INFO: Return type mismatch merc-effect vs none.
(defmethod login-adgifs merc-effect ((obj merc-effect))
(let ((data (-> obj extra-info)))
(when (nonzero? data)
(when (nonzero? (-> data shader-offset))
(let
((tex
(adgif-shader-login
(the-as
adgif-shader
(+ (the-as uint data) (* (-> data shader-offset) 16))
)
)
)
)
(when tex
(dotimes (seg 3)
(logior! (-> *merc-ctrl-header* masks seg) (-> tex masks seg))
)
)
)
)
)
)
(let ((ctrl (-> obj frag-ctrl))
(geo (-> obj frag-geo))
)
(dotimes (frag-idx (the-as int (-> obj frag-count)))
(let ((ctrl-size (asize-of ctrl)))
(let ((geo-size (asize-of geo)))
(login-adgifs geo)
(set! geo (the-as merc-fragment (&+ (the-as pointer geo) geo-size)))
)
(set!
ctrl
(the-as merc-fragment-control (&+ (the-as pointer ctrl) ctrl-size))
)
)
)
)
(none)
)
;; definition for method 3 of type merc-ctrl
;; INFO: this function exists in multiple non-identical object files
(defmethod inspect merc-ctrl ((obj merc-ctrl))
(format #t "[~8x] ~A~%" obj (-> obj type))
(format #t "~Tname: ~A~%" (-> obj name))
(format #t "~Tlength: ~D~%" (-> obj length))
(format #t "~Tnum-joints: ~D~%" (-> obj num-joints))
(format #t "~Textra: ~A~%" (-> obj extra))
(inspect (-> obj header))
(dotimes (s5-0 (the-as int (-> obj header effect-count)))
(inspect (-> obj effect s5-0))
)
obj
)
;; definition for method 8 of type merc-ctrl
(defmethod
mem-usage
merc-ctrl
((obj merc-ctrl) (arg0 memory-usage-block) (arg1 int))
(if (-> obj extra)
(mem-usage (-> obj extra) arg0 arg1)
)
(let ((ctrl-mem (+ 32 80 (* (-> obj header effect-count) 32))))
(dotimes (effect-idx (the-as int (-> obj header effect-count)))
(let ((fctrl (-> obj effect effect-idx frag-ctrl)))
(dotimes (frag-idx (the-as int (-> obj effect effect-idx frag-count)))
(set!
ctrl-mem
(+
ctrl-mem
(* (shr (+ (-> fctrl unsigned-four-count) 3) 2) 16)
(* (shr (+ (-> fctrl lump-four-count) 3) 2) 16)
(* (-> fctrl fp-qwc) 16)
(asize-of fctrl)
)
)
(set!
fctrl
(the-as
merc-fragment-control
(&+ (the-as pointer fctrl) (asize-of fctrl))
)
)
)
)
)
(set! (-> arg0 length) (max 76 (-> arg0 length)))
(set! (-> arg0 data 75 name) "merc-ctrl")
(+! (-> arg0 data 75 count) 1)
(+! (-> arg0 data 75 used) ctrl-mem)
(+! (-> arg0 data 75 total) (logand -16 (+ ctrl-mem 15)))
)
(let ((effect-mem 0))
(dotimes (effect-idx2 (the-as int (-> obj header effect-count)))
(when (nonzero? (-> obj effect effect-idx2 blend-frag-count))
(let ((bctrl (-> obj effect effect-idx2 blend-ctrl)))
(dotimes
(blend-frag-idx
(the-as int (-> obj effect effect-idx2 blend-frag-count))
)
(let
((v1-36
(+
effect-mem
(*
(+ (-> bctrl nonzero-index-count) 1)
(the-as
uint
(logand
(+ (* (the-as uint 6) (-> bctrl blend-vtx-count)) 15)
#xfff0
)
)
)
)
)
)
(set!
effect-mem
(the-as int (+ (-> obj header blend-target-count) 2 v1-36))
)
)
(set!
bctrl
(the-as
merc-blend-ctrl
(&+ (the-as pointer bctrl) (+ (-> obj header blend-target-count) 2))
)
)
)
)
)
)
(when (nonzero? effect-mem)
(set! (-> arg0 length) (max 78 (-> arg0 length)))
(set! (-> arg0 data 77 name) "blend-shape")
(+! (-> arg0 data 77 count) 1)
(+! (-> arg0 data 77 used) effect-mem)
(+! (-> arg0 data 77 total) (logand -16 (+ effect-mem 15)))
)
)
(when (nonzero? (-> obj header eye-ctrl))
(let ((a0-28 (-> obj header eye-ctrl)))
(set! (-> arg0 length) (max 109 (-> arg0 length)))
(set! (-> arg0 data 108 name) "eye-anim")
(+! (-> arg0 data 108 count) 1)
(let ((v1-47 (asize-of a0-28)))
(+! (-> arg0 data 108 used) v1-47)
(+! (-> arg0 data 108 total) (logand -16 (+ v1-47 15)))
)
)
)
obj
)
;; definition for method 9 of type merc-ctrl
(defmethod login merc-ctrl ((obj merc-ctrl))
(set! *merc-ctrl-header* (-> obj header))
(dotimes (v1-1 3)
(set! (-> *merc-ctrl-header* masks v1-1) (the-as uint 0))
)
(dotimes (effect-idx (the-as int (-> obj header effect-count)))
(login-adgifs (-> obj effect effect-idx))
)
(let ((idx-with-bit1 -1)
(a1-1 (-> obj header effect-count))
)
(dotimes (v1-11 (the-as int a1-1))
(if (logtest? (-> obj effect v1-11 effect-bits) 2)
(set! idx-with-bit1 v1-11)
)
)
(when (!= idx-with-bit1 -1)
(let ((v1-16 4)
(this-effect (-> obj effect idx-with-bit1))
(last-effect (-> obj effect (+ a1-1 -1)))
)
(dotimes (copy-idx v1-16)
(let ((a3-2 (-> this-effect data copy-idx)))
(set! (-> this-effect data copy-idx) (-> last-effect data copy-idx))
(set! (-> last-effect data copy-idx) a3-2)
)
)
)
)
)
(cond
((zero? (logand -65536 (the-as int (-> obj header eye-ctrl))))
(set! (-> obj header eye-ctrl) (the-as merc-eye-ctrl 0))
0
)
(else
(let ((s5-1 (-> obj header eye-ctrl)))
(dotimes (s4-0 3)
(let ((v1-25 (adgif-shader-login (-> s5-1 shader s4-0))))
(when v1-25
(dotimes (a0-11 3)
(logior! (-> *merc-ctrl-header* masks a0-11) (-> v1-25 masks a0-11))
)
)
)
)
)
)
)
obj
)
;; definition (debug) for function merc-stats-display
;; INFO: Return type mismatch symbol vs none.
(defun-debug merc-stats-display ((arg0 merc-ctrl))
(format #t "~30s:" (-> arg0 name))
(let ((s5-0 (-> arg0 header st-int-scale))
(s4-0 (ash 1 (- 12 (the-as int (-> arg0 header st-int-scale)))))
)
(format #t " ST ~3D, " s4-0)
(cond
((>= s5-0 (the-as uint 5))
(format #t "RANGE ~D+," (/ 128 s4-0))
)
((= s5-0 4)
(format #t "RANGE 0.5+,")
)
)
)
(dotimes (s5-1 (the-as int (-> arg0 header effect-count)))
(let ((s3-0 (-> arg0 effect s5-1)))
(if (nonzero? s5-1)
(format #t "~48s " " ")
)
(let ((a2-4 (-> s3-0 frag-count))
(s4-1 (-> s3-0 tri-count))
(f30-0 (the float (-> s3-0 frag-count)))
(f28-0 (the float (-> s3-0 dvert-count)))
(f26-0 (the float (-> s3-0 tri-count)))
)
(if (>= (/ (+ 50.0 f28-0) f30-0) 50.0)
(format #t "~3D frags, ~2,,1f dverts/frag " a2-4 (/ f28-0 f30-0))
(format #t "~3D frags, ~2,,1f ******/**** " a2-4 (/ f28-0 f30-0))
)
(format
#t
"(~4D tris, striplen ~2,,2f, ~2,,1f tris/frag)~%"
s4-1
(/ (* 2.0 f26-0) (- f28-0 f26-0))
(/ f26-0 f30-0)
)
)
)
)
(none)
)
;; definition (debug) for function merc-stats
;; INFO: Return type mismatch int vs none.
(defun-debug merc-stats ()
(dotimes (gp-0 3)
(let ((s5-0 (-> *level* level gp-0 art-group)))
(when (nonzero? s5-0)
(dotimes (s4-0 (-> s5-0 art-group-array length))
(let ((s3-0 (-> s5-0 art-group-array s4-0)))
(dotimes (s2-0 (-> s3-0 length))
(let* ((s1-0 (-> s3-0 data s2-0))
(a0-3
(if (and (nonzero? s1-0) (type-type? (-> s1-0 type) merc-ctrl))
s1-0
)
)
)
(if a0-3
(merc-stats-display (the-as merc-ctrl a0-3))
)
)
)
)
)
)
)
)
0
(none)
)
;; definition (debug) for function merc-edge-stats
;; INFO: Return type mismatch int vs none.
(defun-debug merc-edge-stats ()
(dotimes (gp-0 3)
(let ((s5-0 (-> *level* level gp-0 art-group)))
(when (nonzero? s5-0)
(dotimes (s4-0 (-> s5-0 art-group-array length))
(let ((s3-0 (-> s5-0 art-group-array s4-0)))
(dotimes (s2-0 (-> s3-0 length))
(let* ((s1-0 (-> s3-0 data s2-0))
(v1-10
(if (and (nonzero? s1-0) (type-type? (-> s1-0 type) merc-ctrl))
s1-0
)
)
)
(if v1-10
(format
#t
"~30s: ~f~%"
(-> (the-as merc-ctrl v1-10) name)
(-> (the-as merc-ctrl v1-10) header longest-edge)
)
)
)
)
)
)
)
)
)
0
(none)
)
;; definition for function merc-vu1-add-vu-function
;; INFO: Return type mismatch dma-packet vs dma-gif-packet.
(defun
merc-vu1-add-vu-function
((dma dma-packet) (func vu-function) (flush-mode int))
(let ((func-data (&-> func data 4))
(qwc (-> func qlength))
(dst (-> func origin))
)
(while (> qwc 0)
(let ((qwc-this-time (min 127 qwc)))
(set!
(-> dma dma)
(new 'static 'dma-tag
:id (dma-tag-id ref)
:qwc qwc-this-time
:addr (the-as int func-data)
)
)
(set!
(-> dma vif0)
(new 'static 'vif-tag :cmd (if (zero? flush-mode) 16 19))
)
(set!
(-> dma vif1)
(new 'static 'vif-tag
:cmd (vif-cmd mpg)
:num (* qwc-this-time 2)
:imm dst
)
)
(&+! dma 16)
(&+! func-data (* qwc-this-time 16))
(set! qwc (- qwc qwc-this-time))
(+! dst (* qwc-this-time 2))
)
)
)
(the-as dma-gif-packet dma)
)
;; definition for function merc-vu1-initialize-chain
;; INFO: Return type mismatch dma-packet vs none.
;; Used lq/sq
(defun merc-vu1-initialize-chain ((arg0 dma-gif-packet))
(let
((gp-0
(the-as
object
(merc-vu1-add-vu-function (the-as dma-packet arg0) merc-vu1-block 1)
)
)
)
(set!
(-> (the-as dma-gif-packet gp-0) dma-vif dma)
(new 'static 'dma-tag :qwc #xa :id (dma-tag-id cnt))
)
(set!
(-> (the-as dma-gif-packet gp-0) dma-vif vif0)
(new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))
)
(set!
(-> (the-as dma-gif-packet gp-0) dma-vif vif1)
(new 'static 'vif-tag :cmd (vif-cmd stmod))
)
(set!
(-> (the-as (pointer vif-tag) gp-0) 4)
(new 'static 'vif-tag :imm #x1ba :cmd (vif-cmd base))
)
(set!
(-> (the-as (pointer vif-tag) gp-0) 5)
(new 'static 'vif-tag :imm #xfe46 :cmd (vif-cmd offset))
)
(set! (-> (the-as (pointer vif-tag) gp-0) 6) (new 'static 'vif-tag))
(set!
(-> (the-as (pointer vif-tag) gp-0) 7)
(new 'static 'vif-tag :num #x8 :cmd (vif-cmd unpack-v4-32))
)
(let ((s5-0 (the-as merc-vu1-low-mem (&+ (the-as dma-gif-packet gp-0) 32))))
(set!
(-> s5-0 tri-strip-gif tag)
(new 'static 'gif-tag64
:pre #x1
:prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1 :fge #x1)
:nreg #x3
)
)
(set!
(-> s5-0 tri-strip-gif regs)
(new 'static 'gif-tag-regs
:regs0 (gif-reg-id st)
:regs1 (gif-reg-id rgbaq)
:regs2 (gif-reg-id xyzf2)
)
)
(set!
(-> s5-0 tri-strip-gif word 3)
(shr (make-u128 0 (shl #x303e4000 32)) 32)
)
(set! (-> s5-0 ad-gif tag) (new 'static 'gif-tag64 :nloop #x5 :nreg #x1))
(set!
(-> s5-0 ad-gif regs)
(new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d))
)
(set! (-> s5-0 hvdf-offset quad) (-> *math-camera* hvdf-off quad))
(quad-copy!
(-> s5-0 perspective)
(the-as pointer (-> *math-camera* perspective))
4
)
(set-vector!
(-> s5-0 fog)
(-> *math-camera* pfog0)
(-> *math-camera* fog-min)
(-> *math-camera* fog-max)
0.0
)
)
(let ((v1-20 (-> (the-as (inline-array dma-packet) gp-0) 10)))
(set! (-> v1-20 dma) (new 'static 'dma-tag :id (dma-tag-id cnt)))
(set! (-> v1-20 vif0) (new 'static 'vif-tag))
(set!
(-> v1-20 vif1)
(new 'static 'vif-tag :cmd (vif-cmd mscal) :msk #x1 :imm #x0)
)
(&+ v1-20 16)
)
)
(none)
)
;; definition for function merc-vu1-init-buffer
;; INFO: Return type mismatch int vs none.
(defun merc-vu1-init-buffer ((dma-bucket bucket-id) (test gs-test) (arg2 int))
(let
((bucket
(->
*display*
frames
(-> *display* on-screen)
frame
bucket-group
dma-bucket
)
)
)
(when (!= bucket (-> bucket last))
(let*
((dma-buf (-> *display* frames (-> *display* on-screen) frame global-buf))
(s3-1 (-> dma-buf base))
)
(set!
(-> dma-buf base)
(the-as
pointer
(merc-vu1-initialize-chain (the-as dma-gif-packet (-> dma-buf base)))
)
)
(let* ((v1-8 dma-buf)
(a0-6 (the-as object (-> v1-8 base)))
)
(set!
(-> (the-as dma-packet a0-6) dma)
(new 'static 'dma-tag :qwc #x2 :id (dma-tag-id cnt))
)
(set! (-> (the-as dma-packet a0-6) vif0) (new 'static 'vif-tag))
(set!
(-> (the-as dma-packet a0-6) vif1)
(new 'static 'vif-tag :imm #x2 :cmd (vif-cmd direct) :msk #x1)
)
(set! (-> v1-8 base) (&+ (the-as pointer a0-6) 16))
)
(let* ((v1-9 dma-buf)
(a0-8 (the-as object (-> v1-9 base)))
)
(set!
(-> (the-as gs-gif-tag a0-8) tag)
(new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x1)
)
(set!
(-> (the-as gs-gif-tag a0-8) regs)
(new 'static 'gif-tag-regs
:regs0 (gif-reg-id a+d)
:regs1 (gif-reg-id a+d)
:regs2 (gif-reg-id a+d)
:regs3 (gif-reg-id a+d)
:regs4 (gif-reg-id a+d)
:regs5 (gif-reg-id a+d)
:regs6 (gif-reg-id a+d)
:regs7 (gif-reg-id a+d)
:regs8 (gif-reg-id a+d)
:regs9 (gif-reg-id a+d)
:regs10 (gif-reg-id a+d)
:regs11 (gif-reg-id a+d)
:regs12 (gif-reg-id a+d)
:regs13 (gif-reg-id a+d)
:regs14 (gif-reg-id a+d)
:regs15 (gif-reg-id a+d)
)
)
(set! (-> v1-9 base) (&+ (the-as pointer a0-8) 16))
)
(let* ((v1-10 dma-buf)
(a0-10 (-> v1-10 base))
)
(set! (-> (the-as (pointer gs-test) a0-10) 0) test)
(set! (-> (the-as (pointer gs-reg64) a0-10) 1) (gs-reg64 test-1))
(set! (-> v1-10 base) (&+ a0-10 16))
)
(let ((v1-11 (the-as object (-> dma-buf base))))
(set!
(-> (the-as dma-packet v1-11) dma)
(new 'static 'dma-tag :id (dma-tag-id next) :addr (-> bucket next))
)
(set! (-> (the-as dma-packet v1-11) vif0) (new 'static 'vif-tag))
(set! (-> (the-as dma-packet v1-11) vif1) (new 'static 'vif-tag))
(set! (-> dma-buf base) (&+ (the-as pointer v1-11) 16))
)
(set! (-> bucket next) (the-as uint s3-1))
)
)
)
0
(none)
)
;; definition for function merc-vu1-init-buffers
;; INFO: Return type mismatch int vs none.
(defun merc-vu1-init-buffers ()
(when (logtest? *vu1-enable-user* 1024)
(merc-vu1-init-buffer
(bucket-id bucket-10)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-49)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-17)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-52)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-45)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-55)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x26
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-58)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x80
:afail #x1
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
(merc-vu1-init-buffer
(bucket-id bucket-61)
(new 'static 'gs-test
:ate #x1
:atst (gs-atest greater-equal)
:aref #x80
:afail #x1
:zte #x1
:ztst (gs-ztest greater-equal)
)
0
)
)
0
(none)
)

View file

@ -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)
)
)

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))

View file

@ -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)

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!

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)

View file

@ -0,0 +1,334 @@
;;-*-Lisp-*-
(in-package goal)
;; definition for function unpack-comp-rle
;; INFO: Return type mismatch int vs none.
(defun unpack-comp-rle ((out (pointer int8)) (in (pointer int8)))
(local-vars (current-input int) (copy-length int))
(nop!)
(while #t
(while #t
(set! current-input (-> in 0))
(set! in (&-> in 1))
(b! (<= current-input 0) cfg-5 :delay (nop!))
(let ((repeated-value (-> in 0)))
(set! in (&-> in 1))
(label cfg-3)
(nop!)
(nop!)
(nop!)
(nop!)
(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)
(b! (zero? current-input) cfg-8 :delay (set! copy-length (- current-input)))
(label cfg-6)
(let ((src-val (-> in 0)))
(set! in (&-> in 1))
(nop!)
(nop!)
(set! (-> out 0) src-val)
)
(+! copy-length -1)
(b! (> copy-length 0) cfg-6 :delay (set! out (&-> out 1)))
)
(label cfg-8)
0
(none)
)
;; definition of type huf-dictionary-node
(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
)
;; definition for method 3 of type huf-dictionary-node
(defmethod inspect huf-dictionary-node ((obj huf-dictionary-node))
(format #t "[~8x] ~A~%" obj 'huf-dictionary-node)
(format #t "~Tzero: ~D~%" (-> obj zero))
(format #t "~Tone: ~D~%" (-> obj one))
obj
)
;; definition for function unpack-comp-huf
;; INFO: Return type mismatch int vs none.
;; WARN: Unsupported inline assembly instruction kind - [sra v1, v1, 1]
(defun
unpack-comp-huf
((arg0 (pointer uint8))
(arg1 (pointer uint8))
(arg2 uint)
(arg3 huf-dictionary-node)
)
(local-vars (t1-1 uint) (t3-2 object))
(nop!)
(let ((t1-0 (-> arg3 zero))
(a2-1 (+ arg2 -1028))
(t2-0 (-> arg3 one))
)
(nop!)
(label cfg-1)
(let ((v1-4 128))
(nop!)
(let ((t0-0 (-> arg1 0)))
(set! arg1 (&-> arg1 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! (-> arg0 0) t1-1)
(set! arg0 (&-> arg0 1))
(nop!)
(set! t1-0 (-> arg3 zero))
(b! (nonzero? v1-4) cfg-2 :delay (set! t2-0 (-> arg3 one)))
)
)
(b! #t cfg-1 :delay (nop!))
(label cfg-10)
(nop!)
(nop!)
0
(none)
)
;; definition for method 16 of type level
;; WARN: Unsupported inline assembly instruction kind - [sra s2, s2, 3]
;; Used lq/sq
(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))
(curr-vis-str (-> vis-info current-vis-string))
(desired-vis-str (-> vis-info vis-string cam-leaf-idx))
)
0
(+ 16 #x70000000)
(+ 2064 #x70000000)
(when (= curr-vis-str desired-vis-str)
(b!
(zero? (logand #x40000000 (-> vis-info flags)))
cfg-6
:delay
(empty-form)
)
(if (check-busy *ramdisk-rpc*)
(return #f)
)
(set! (-> vis-info flags) (logand -1073741825 (-> vis-info flags)))
(set! vis-buffer (-> obj vis-buffer))
(b! #t cfg-27 :delay (nop!))
(label cfg-6)
(return #t)
)
(when (logtest? #x40000000 (-> vis-info flags))
(if (check-busy *ramdisk-rpc*)
(return #f)
)
(set! (-> vis-info flags) (logand -1073741825 (-> vis-info flags)))
)
(set! (-> vis-info current-vis-string) desired-vis-str)
(b! (logtest? #x20000000 (-> vis-info flags)) cfg-15 :delay (empty-form))
(set! vis-buffer (+ arg2 desired-vis-str))
(b! #t cfg-27 :delay (nop!))
(label cfg-15)
(let ((vis-load-result (vis-load obj)))
(b! (nonzero? vis-load-result) cfg-21 :delay (empty-form))
(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 #x40000000 (-> vis-info flags)))
(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!))
(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 uint 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)
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 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 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~%"
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 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
)
)
)
)

View file

@ -140,7 +140,7 @@
)
(let ((s5-0 (loado arg0 arg1)))
(the-as art (if (type-type? (-> (the-as art s5-0) type) art)
(dummy-9 (the-as art s5-0))
(login (the-as art s5-0))
(the-as art #f)
)
)
@ -190,7 +190,7 @@
(the-as art-group #f)
)
(else
(dummy-9 s3-1)
(login s3-1)
)
)
)
@ -545,7 +545,7 @@
(set! (-> obj status) 'error)
)
(else
(dummy-9 s4-0)
(login s4-0)
(set! (-> obj status) 'locked)
)
)