Skip to content

v0.6.0 — "Open House"

Latest

Choose a tag to compare

@sp00nznet sp00nznet released this 21 Nov 03:05

WTF goes from its title screen, through the Job Share menu, into a game of
Lumberjack and its paycheck screen. A second microgame, Pendemonium, plays
too: a lit 3D factory scene where you cap pens. Ten pull requests from two
people: andy, still on LocoRoco, and a new contributor bringing DJMAX Portable
up, who made long guest loops stop eating the host stack and let a PRX be
lifted at the address it really loads at.

From contributors

  • A j to an address its own body owns is a goto, even at a function
    entry.
    A loop whose back edge jumped to its own entry was a tail call
    through the wrapper, and MSVC does not promise to make that a jump. On DJMAX
    Portable a song's playback thread overflowed a 1 MiB stack after about 90
    seconds; 472 bodies did this —
    @nworkers (#35)
  • --base <addr> and relocate: lift a PRX where it loads. Applies the
    module's own relocations (R_MIPS_32, R_MIPS_26, HI16/LO16 pairs) at
    a chosen base, so a host can keep the real memory layout. Without --base
    nothing changes. Pointer seeds now honour a relocation's segment indices.
    The relocated DJMAX image matches an independent loader word for word —
    @nworkers (#36)
  • -DPSPRECOMP_LOOP_HOOK: a safe point in every guest loop. Every backward
    branch can call psp_loop_hook(), where a host scheduler can preempt. Off by
    default, and then the output is unchanged. On DJMAX the latest resume of the
    sound thread went from 1000 ms to 6.7 ms —
    @nworkers (#38)
  • A linking jalr at the end of a body carries on after its slot. It was
    treated as terminal, so a callee's normal return skipped the caller's
    epilogue and left $sp 16 bytes low —
    @andyst-dev (#31)
  • Guest call frames live in the runtime, not in emitted bodies.
    psp_call_guest_fn/psp_call_guest_addr own the return-site frame, so a
    body that calls and then transfers in tail position no longer keeps a host
    frame per iteration (959,952 bytes over 20,000 iterations before). Re-emit
    to pick it up —
    @andyst-dev (#32)
  • emit --hints <path>: force labels for computed jumps. A per-title TOML
    file whose [[label]] addresses become entries of the body that owns them.
    The first kind of hint; see HINTS.md. Partly answers #15 —
    @andyst-dev (#34)
  • sceIoGetstat fills its buffer from the host file (type, mode, 64-bit
    size, timestamps). It used to return success and write nothing —
    @andyst-dev (#29)
  • sceIoOpen rejects a null or empty filename instead of opening the
    disc directory, or reading a module at address 0 as a name —
    @andyst-dev (#28)
  • sceCtrlReadLatch/sceCtrlPeekLatch: make, break, press and release
    masks accumulated across samples, consumed on read —
    @andyst-dev (#30)
  • Several watch sites at once. psp_trace_watch_add and
    psp_trace_watch_label_add take up to eight each and say when the table is
    full, so an unwatched address can't pass for an unreached one —
    @andyst-dev (#33)

Emitter

  • A jump that leaves runs its delay slot even when another body owns it.
    j and jr now emit a copy of a foreign slot before they go, as branches
    already did. Pendemonium builds the struct offset 0x44AF0 with
    lui/ori, which discovery took for a code address; it landed on the slot
    of a jr $ra whose addiu $sp, $sp, 16 was then dropped, and every call
    leaked 16 bytes of stack.
  • A branch-and-link is a conditional call. bgezal/bltzal and the
    likely forms call their target and carry on after the delay slot, and link
    $ra whether or not they are taken. The taken path used to be a tail
    transfer, so the caller's frame was abandoned. Reported, with the analysis,
    by @Tzeentchnet (#16).
  • jr $ra follows the guest's calls, not C's. Every call pushes the return
    site it expects onto a shadow stack on the host stack. A jr $ra to that
    site is a return; to an outer call's site it unwinds to that call; to anywhere
    else it is a jump through dispatch. WTF's decompressor uses $ra as a
    continuation and returns from helpers by branching to its own epilogue, and
    leaked an 896-byte frame per call into the heap. Every call's return site is
    now a label.

Hosting a game

  • psprecomp/window.h: a window to play in. Shows the front buffer
    scaled with whole-pixel nearest sampling, letterboxed, and feeds the
    keyboard and the first XInput controller to sceCtrl, on a host thread of
    its own. Windows (Win32, GDI, XInput: no dependencies); elsewhere it
    reports that it cannot open, until an SDL2 backend like ps3recomp's.
  • psprecomp/module.h: load and start a module. Places the image, reads
    module_start from the ELF header and $gp from the module info, finds the
    constructor table, and starts the module the way the loader would. What a
    bring-up harness used to hard-code per game.
  • psp_display_read() gives the front buffer as pixels; the capture uses it.
  • Constructor discovery stops a run at a zero word: a module linked at 0 has
    zeros that read as pointers to its first byte.

VFPU

  • Operand prefixes are applied, not trapped. vpfxs/vpfxt swizzle,
    negate, take absolute values and substitute constants on each source lane;
    vpfxd saturates and masks the destination. WTF broadcasts a lane before a
    clamp, builds box corners with them, and compares against |x|. The matrix
    ops still trap on a pending prefix.
  • mfv/mtv and mfvc/mtvc, the integer packing ops (vi2uc, vi2c,
    vi2us, vi2s, vuc2i, vc2i, vus2i, vs2i), vocp, vsgn, vsge,
    vslt, vscmp, vhdp, vcrs, vcrsp/vqmul, vdet, vrot, the
    vcmp conditions 8-15 and vnop/vsync/vflush. WTF's colour helper
    ends vi2uc; mfv; unimplemented, it returned whatever $v0 held, so every
    menu glyph was drawn in the display-list pointer's "colour", alpha 9.
  • vidt writes the identity column its register names (vidt.q C730 is
    (0, 0, 0, 1)). It used bits 6-7 instead. WTF keeps s733 = 1 that way for its
    quaternion-to-matrix code, so every animated node had a zero 3x3 and the
    microgames' title cards were drawn at a point: an invisible screen that
    looked like a 25-second load.

Renderer

  • Lighting: four lights (directional, point, spot; ambient, diffuse,
    specular, powered diffuse), material colours with CMAT, per vertex in world
    space.
  • Depth: a 16-bit depth buffer in VRAM, ZTEST/ZMSK, ZSCALE/ZPOS, and depth
    clears.
  • DXT1/3/5 textures, in the PSP's block layout (indices first).
  • Indexed drawing, and PRIM leaves VADDR/IADDR after what it used, so the
    next PRIM continues from there. WTF draws runs of PRIMs with one VADDR;
    they had all re-read the first vertices.
  • Attributes are sampled at the pixel centre. At the corner, a row of a
    1:1 texture landed on the texel edge and float error floored it to the row
    before; WTF's LED panels lost whole rows of dots.
  • Triangles with a vertex behind the eye are dropped one by one, not the
    whole 256-vertex batch they arrived in.

Runtime and HLE

  • A new thread starts with its creator's $gp. Under real threads it
    started at 0, and Pendemonium, whose globals are $gp-relative, read its
    own code as data.
  • An unbounded wait does not time out while another thread could end it.
    WTF's sound thread waits forever on a request queue and does not check the
    result; a fake timeout made it open a file named NULL. A waiter with no other
    live thread still reports and gives up.
  • Blocking audio output models the hardware queue on the host clock, and
    sceAudioSetChannelDataLen is implemented. WTF's audio ran at about a
    tenth of real time, so its title jingle, which it waits for, never finished.
  • SAS voices honour the ADPCM block loop flags. A loop end without the
    repeat bit stops the voice even in loop mode. The title jingle had looped
    forever.
  • Windows timer resolution is raised to 1 ms under real threads, and
    deadlines use the performance counter. Each scheduler tick had cost 15.6 ms.
  • psp_call_from_host() runs guest code from thread entries, callbacks,
    interrupt handlers and constructors.

Rendering

  • Textures. 565/5551/4444/8888 and CLUT 4/8/16/32-bit, linear or
    swizzled, with the CLUT captured at CLOAD as the hardware does. Texture
    functions modulate, decal, blend, replace and add. Alpha test, blending
    (every factor and equation), clear mode with its colour/alpha flags, scissor,
    16-bit framebuffers, and vertices with no colour take the material colour.
    DXT is drawn magenta and counted.

  • Transformed geometry. World, view and projection matrices, viewport and
    offset, UV scale and offset, and normalised 8/16-bit vertex formats. A
    primitive with a vertex behind the eye is dropped and counted, since there is
    no clipping yet.

  • psp_ge_dump_stats() lists every undecoded GE command by opcode, with
    its last argument, instead of printing the first 64 to stderr.

  • A finished display list frees its queue slot. Slots were never
    released, so the ninth sceGeListEnQueue failed and every frame after it was
    dropped. WTF ran its loop at full speed and drew 15 lists in 60 seconds; it
    now draws all of them. Stall updates on a finished list succeed.

Instruments

  • PSPRECOMP_TRACE_GE=<frame> logs every command, primitive and its first
    vertices during one frame.
  • The write watch prints the guest calls in flight, not just the last
    function entered.
  • psp_hle_dump_counts() prints call counts per firmware function,
    busiest first, with unimplemented NIDs counted individually.
  • psp_mem_watch_read() names each function that reads an address.
  • PSPRECOMP_TRACE_IO=1 logs every file open and its result, and
    PSPRECOMP_TRACE_SAS=1 logs SAS voice setup and audio channel sizes.

Tests

  • test_hle's five-argument helper put the fifth argument on the stack, as o32
    does; the PSP passes it in $t0, so every fifth argument arrived as 0.

VFPU

  • vmmul transposes its first operand. vmmul.q M000, E100, M200 is
    M100 * M200. That is how WTF multiplies its matrices, and without the
    transpose its projection matrix reached the GE transposed. The orientation was
    flagged as unverified in the source; it is now pinned by a hand-worked test.

Runtime and HLE

  • The GE framebuffer address is VRAM-relative. FBP 0x88000 drew into
    main RAM at 0x00088000, which for a vaddr-0 module is its own code. On WTF
    Lumberjack every clear overwrote a jump table and the screen stayed empty.
  • sceAudioOutputBlocking/sceAudioOutputPannedBlocking block for one
    buffer's play time, through a new psp_threadman_delay(). Returning at once
    let a mixer thread spin and starve every other thread under real threads.

Known open

  • emit --trampoline (#37) waits on a rebase over #32's call helpers.
  • Jump-table operands traced to their definitions (#19) is in review.

Contributors: @andyst-dev (#28, #29, #30, #31, #32, #33, #34) and, for the first time, @nworkers (#35, #36, #38). Full credit in CONTRIBUTORS.md.