; frames.asm ; Waiting for the screen, which is the only regular beat this machine has. ; Written by Anachronaut ; ; ---- There is no clock ---- ; ; Nothing on a SplitBit can tell you how long a second is. Every program that wanted to ; happen at a certain speed has counted instructions and hoped - which is why Snake's pause ; quietly halved the day a cycle stopped being an instruction and became a memory access. ; The program was right; the thing it was counting had changed underneath it. ; ; A screen finishes drawing sixty times a second, and that is a real beat. It is counted in ; the machine's own cycles rather than the host's, so this program sees sixty frames a second ; whether the emulator is running at its proper rate or as fast as it possibly can. ; ; ---- Waiting rather than spinning ---- ; ; WAIT stops the machine until something interrupts it. That is not the same as looping until ; a flag goes up, even though both take the same time and print the same thing: a machine in ; WAIT is not using memory, so its cycles are counted as idle rather than as bus. Run this ; and the last line says so - nearly every cycle it spent, it spent asleep. ; ; Which is the whole argument for having a frame to wait for. On real hardware that is a ; machine that could be doing something else, or nothing at all and drawing less current. #Program start: SETD.0 Frames RSTA STA.0 ; Ask the screen to interrupt at each frame, then let interrupts in. The screen does not do ; this unless it is asked: an interrupt with nothing installed to catch it is a fault, so a ; machine that started interrupting on its own would take down every program that had never ; heard of frames. INIA 0x01 OUTA 0x35 SIF everyFrame: ; A dot a frame, so there is something to watch. INIA 0d46 OUTA 0x00 ; And nothing at all until the next one. WAIT SETD.0 Frames LDA.0 INIB 0d60 ; One second of them CCF SUB BNQ everyFrame ; Put the screen back the way it was found, and stop asking to be interrupted before ; taking away the thing that would catch it. CIF RSTA OUTA 0x35 SETD.0 Done RCAL say HALT ; ---- Called sixty times a second ---- ; ; A handler runs between two instructions of whatever was going on, so it saves everything it ; touches - which for an interrupt the machine does itself. RETI puts it all back. frame: SETD.0 Frames LDA.0 INCA STA.0 RETI say: LDA.0 BRA sayDone OUTA 0x00 INCD.0 BRI say sayDone: RRET #Data Frames: 0x00 Done: " that was a second " #Vectors Boot start Device 0x30 frame