<commit_before>(in-package :famiclom)

(defvar *screen* nil
  "A screen object to draw to. Should be 256x240.")

(defgeneric init (backend)
  (:documentation "Initialize *screen* for the given BACKEND."))

(defgeneric next-frame (nes)
  (:documentation "Compute the next frame for the NES."))

(defgeneric draw (frame)
  (:documentation "Draw (i.e. blit) the given FRAME to *screen*."))

;; TODO: Seems to indicate that get-sprite, read-oam, and get-visible-sprites are first targets.
;; Also seems to suggest that functions may be more approriate for get-pattern-color, get-attrib,
;; get-bg-pixel, get-visible-sprites, get-sprite.
(defun optimize-test ()
  (load-rom (app-path "smb.nes"))
  (sdl:with-init (sdl:sdl-init-video sdl:sdl-init-audio)
    (setf *screen* (sdl:window 256 240 :bpp 24 :sw t))
    (with-accessors ((cpu nes-cpu)
                     (ppu nes-ppu)) *nes*
      (time (loop until (> (6502:cpu-cc cpu) +cycles-per-second+)
               do (let ((c-step (6502-step cpu (6502:get-byte (6502:immediate cpu))))
                        (p-step (ppu-step ppu (6502:cpu-cc cpu))))
                    (when (getf p-step :vblank-nmi)
                      (6502:nmi cpu)
                      (setf (getf p-step :vblank-nmi) nil))
                    (when (getf p-step :new-frame)
                      (sdl:update-display *screen*)
                      (setf (getf p-step :new-frame) nil))))))))<commit_msg>Reset optimize-test for repeated trials.<commit_after>(in-package :famiclom)

(defvar *screen* nil
  "A screen object to draw to. Should be 256x240.")

(defgeneric init (backend)
  (:documentation "Initialize *screen* for the given BACKEND."))

(defgeneric next-frame (nes)
  (:documentation "Compute the next frame for the NES."))

(defgeneric draw (frame)
  (:documentation "Draw (i.e. blit) the given FRAME to *screen*."))

;; TODO: Seems to indicate that get-sprite, read-oam, and get-visible-sprites are first targets.
;; Also seems to suggest that functions may be more approriate for get-pattern-color, get-attrib,
;; get-bg-pixel, get-visible-sprites, get-sprite.
(defun optimize-test ()
  (reset *nes*)
  (load-rom (app-path "smb.nes"))
  (sdl:with-init (sdl:sdl-init-video sdl:sdl-init-audio)
    (setf *screen* (sdl:window 256 240 :bpp 24 :sw t))
    (with-accessors ((cpu nes-cpu)
                     (ppu nes-ppu)) *nes*
      (time (loop until (> (6502:cpu-cc cpu) +cycles-per-second+)
               do (let ((c-step (6502-step cpu (6502:get-byte (6502:immediate cpu))))
                        (p-step (ppu-step ppu (6502:cpu-cc cpu))))
                    (when (getf p-step :vblank-nmi)
                      (6502:nmi cpu)
                      (setf (getf p-step :vblank-nmi) nil))
                    (when (getf p-step :new-frame)
                      (sdl:update-display *screen*)
                      (setf (getf p-step :new-frame) nil))))))))
{'fraction_non_alphanumeric': 0.14566793234380393, 'fraction_numerical': 0.02623403520883673, 'mean_word_length': 2.44589774078478, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3052113', 'n_tokens_mistral': 1057, 'n_tokens_neox': 955, 'n_words': 283}