anchor.diff:  ;;;; banks mid-frame.  It also incorporates an NSF file to provide
   ;;;; some crude music.
   
  -;;;; I'm no demo coder. Expect no 6502 wizardry here.
  -
   ;;;; It targets a basic NROM board (32KB program, 8KB character). I
   ;;;; haven't had a chance to test on real hardware yet.
   
  -;;;; Somewhat embarrassingly, this demo reveals a bug in my own NES
  +;;;; I'm neither a demo coder nor particularly experienced at 6502
  +;;;; assembly language, so expect nothing clever here.
  +
  +;;;; (Somewhat embarrassingly, this demo reveals a bug in my own NES
   ;;;; emulator which I've yet to fix, where the frame timing is
  -;;;; apparently off by one scanline. Oops.
  +;;;; apparently off by one scanline. Oops.)
   
   (defpackage :dollhouse-demo
     (:use :common-lisp :6502 :6502-modes :asm6502 :asm6502-utility :asm6502-nes))
  
positive.code:     (as/until :negative (bita (mem +ppu-status+))) ; PPU warmup interval
      (as/until :negative (bita (mem +ppu-status+))) ; (two frames)
  
      ;; Fill nametable.
      (ppuaddr #x2000)
      (jsr 'fill-nametable)
      (ppuaddr #x2400)
      (jsr 'fill-nametable)
  
      ;; Fill attribute table.
      (ppuaddr #x23C0)
      (ldy (imm 0))
      (lda (imm #b01010101))
  
negative.code:       (adc (imm (lsb (label 'wave-offsets))))
        (sta wt-lsb)
  
        (emit-delay 47)                   ; Realign with hblank
        (bita (zp 0))
        (nop)
  
        (macrolet ((reporting-timing (&body body)
                     `(print (list :kernel-cycles
                                   (counting-cycles ,@body)))))
  
          (ldy (imm num-wavy-lines))      ; Decremented within scanline kernel.
  
          (loop repeat (/ num-wavy-lines 3) do
                (reporting-timing (kernel) (dey))
                (loop repeat 14 do (inc (zp 0)))
                (reporting-timing (kernel) (dey))
                (nop)
                (loop repeat 14 do (inc (zp 0)))
                (reporting-timing (kernel) (dey))
                (loop repeat 14 do (inc (zp 0))))))
  
      ;; Shut the screen off. Need a few extra scanlines here to update
      ;; the sprite tables, and if I didn't shut it off, you'd notice
  