May need to brew install libsdl2-dev
brew install sbcl # or apt-get if you nasty playa
curl -O https://beta.quicklisp.org/quicklisp.lisp > quicklisp.lisp
sbcl --load quicklisp.lisp # and follow the prompts
git clone git@github.com:kingcons/clones.git ~/quicklisp/local-projects/clones.git
Start rlwrap sbcl
and ...
(ql:quickload :clones)
(in-package :clones)
(change-game "roms/commercial/dk.nes") ;; this path is relative to the clones installation folder/git checkout
(step-frames 4)
Make sure to do this on the mezzanine branch...
(ql:quickload :cl-json)
(defvar *nt* (clones.ppu::ppu-nametable (memory-ppu (cpu-memory *nes*))))
(cl-json:encode-json *nt*)
Make sure to brew install libpng
first and use my fork of cl-png...
git clone git@github.com:kingcons/cl-png.git ~/quicklisp/local-projects/cl-png
Then ...
(ql:quickload '(:zpng :clones))
(in-package :clones)
(change-game "roms/commercial/smb.nes")
(step-frames 30)
(defvar *image* (make-instance 'zpng:pixel-streamed-png :color-type :truecolor :width 256 :height 240))
(with-open-file (out "test.png" :element-type '(unsigned-byte 8) :direction :output
:if-does-not-exist :create :if-exists :supersede)
(zpng:start-png *image* out)
(dotimes (i (* 256 240))
(let ((pixel (list (aref clones.ppu:*framebuffer* (+ (* i 3) 0))
(aref clones.ppu:*framebuffer* (+ (* i 3) 1))
(aref clones.ppu:*framebuffer* (+ (* i 3) 2)))))
(zpng:write-pixel pixel *image*)))
(zpng:finish-png *image*))
Looks like nametables are identical at frame 45 and I feel confident assuming pattern tables and palette are also identical. We could be handling palette transparency incorrectly. Or for some reason our background logic is off. ... 🤔
The lines in the background we're getting appear clearly at x: 115, y: 70 of Mario's title in the scaled canvas. So that should be x: 57 and y: 35 in the unscaled data. They appear to alternate scanlines so inspecting the values of our pattern/tile at y: 35 and y: 36 for x: 57 . should reveal the issue.
(5 minutes later...) Yep, odd scanlines are finding the wrong background tiles, blank ones, which leads to the sprites showing through.
(10 minutes later...) This looks like a ScrollInfo bug! Apparently we're flipping the nametable index when I don't think we should be. It's alternating between 1 and 0. Even on a single scanline, apparently. I thought I tested this carefully based on what I saw on Nesdev but the data is pretty clear. I'll dig into this more after lunch. NT index 0 background is transparent. We should be reading from NT index 1. Does the scroll need to take mirroring into account somehow? 🤔