Login
You're viewing the code4lib.social public feed.
  • Nov 24, 2026, 6:18 PM

    this is not a problem in practice, since apparently the joypad interrupt is rarely used in commercial ROMs (bc of bounce issues!). BUT in my plans to make a GB SoC-based home computer, I'd been thinking about repurposing the joypad inputs/interrupt as a way for peripherals to trigger interrupts (each could have its own input, or i could multiplex 16 onto the four inputs). but the need to pull the input low for four cycles to reliably trigger the interrupt complicates that plan

    💬 1🔄 0⭐ 0

Replies

  • Nov 24, 2026, 6:22 PM

    (also interrupt handling on the SM83 CPU is already pretty slow, requiring six cycles or so to actually run the handler, and usually more than that, since from a practical standpoint, you almost always want to push registers onto the stack, which takes even more cycles. the extra four cycles to trigger the joypad interrupt could make it impractical to use interrupts for high speed peripherals? i dunno)

    💬 1🔄 0⭐ 0
  • Nov 24, 2026, 9:15 PM

    oh wow I just tested this behavior in the simulator and... it works exactly like i thought it would. so weird! p10–p15 are the i/o pins; i made a little loop in the simulator setup that "pushes" the buttons in either a 1010 pattern or a 1001 pattern at 1MHz. "jp_ticker" is the state of the four flipflops i mentioned earlier, and int_jp going high triggers the joypad interrupt. first image is 1010, and no interrupt happens; second image is 1001, and voila, the interrupt

    gtkwave screenshot, as described in post text: green horizontal lines indicating high or low values, sometimes superimposed with numbers (jp_ticker=1010)
    gtkwave screenshot, as described in post text: green horizontal lines indicating high or low values, sometimes superimposed with numbers (jp_ticker=1001)
    💬 2🔄 0⭐ 0
  • Nov 28, 2026, 4:07 AM

    so blargg's cpu test rom was showing weird 8px lines in a few tests. it took a bit but i tracked down the problem: the "ld sp, hl" instruction tucks the value of the hl register on the cpu address bus for one cycle—so when the test for "ld sp, hl" runs, with $8000 in hl, my code to check whether VRAM should be readable says "no" ($8000 is a VRAM address, and the cpu can't access VRAM during rendering). so in that one cycle the PPU reads $ff off the vram bus

    game boy emulator screenshot. text at the bottom: "cpu_instrs / 01:ok 02:ok 03." there are two errant 8px horizontal lines in the lower third of the screen
    game boy emulator screenshot. text at the bottom: "cpu_instrs / 01:ok 02:ok 03." there are two errant 8px horizontal lines in the upper third of the screen
    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 4:15 AM

    the fix: change the code for determining whether or not vram is readable, so that vram access is blocked only if the CPU is specifically trying to *read* from an address in vram, not just if there is an address in vram on the cpu address bus. that way, the ppu renderer can keep accessing vram whenever it needs to. this is actually how it works in the silicon, i just didn't read the schematic right, whoops. to be fair, the schematic for vram cs/rd/wr is a mess

    low res screenshot of a schematic with a lot of gates and wires going around in different directions, some with mysterious input names like "TACU" and "SP_BP_CYS"
    💬 1🔄 0⭐ 0
  • Nov 28, 2026, 10:33 PM

    and only seven months after starting to work on this game boy emulator, i can at last present... the tetris copyright screen

    game boy emulator screenshot, showing the tetris copyright screen (blocky text reading "TM AND (C)1987 ELORG, TETRIS LICENSED TO BULLET-PROOF SOFTWARE..."
    💬 1🔄 4⭐ 0
  • 💬 0🔄 0⭐ 0
  • 💬 0🔄 0⭐ 1
  • 💬 0🔄 0⭐ 0
  • Nov 28, 2026, 10:53 PM

    @scott it does eventually time out to the title screen (though it takes a long time because my emulator is still very slow). apparently my joypad emulation is not perfect yet 🙃

    💬 0🔄 0⭐ 0