Skip to content

Commit af3d8d5

Browse files
committed
Add simple debugger breakpoints (still needs UI)
1 parent 7535d4e commit af3d8d5

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/emulator.lisp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
(paused nil :type boolean)
8989
(take-step nil :type boolean)
9090
(print-needed nil :type boolean)
91-
(callbacks-arrived nil :type list))
91+
(callbacks-arrived nil :type list)
92+
(breakpoints nil :type list))
9293

9394
(defstruct chip
9495
(running t :type boolean)
@@ -248,9 +249,6 @@
248249

249250

250251
;;;; Debugger -----------------------------------------------------------------
251-
(declaim
252-
(ftype (function (debugger) boolean) debugger-should-wait-p))
253-
254252
(defun debugger-pause (debugger)
255253
(with-debugger (debugger)
256254
(setf paused t print-needed t)))
@@ -286,16 +284,31 @@
286284
(defun debugger-paused-p (debugger)
287285
(debugger-paused debugger))
288286

289-
(defun debugger-should-wait-p (debugger)
287+
(defun debugger-check-breakpoints (debugger address)
288+
(let ((result (member address (debugger-breakpoints debugger))))
289+
(if result
290+
(progn (debugger-pause debugger)
291+
t)
292+
nil)))
293+
294+
(defun debugger-should-wait-p (debugger address)
290295
(with-debugger (debugger)
291-
(if (not paused) ; if we're not paused, we never need to wait
292-
nil
296+
(if (not paused)
297+
;; If we're not paused, we just need to check for breakpoints
298+
(debugger-check-breakpoints debugger address)
299+
;; Otherwise we're paused
293300
(if take-step
294301
(progn (setf take-step nil ; if we're paused, but are ready to step, go
295302
print-needed t)
296303
nil)
297304
t)))) ; otherwise we're fully paused -- wait
298305

306+
(defun debugger-add-breakpoint (debugger address)
307+
(pushnew address (debugger-breakpoints debugger)))
308+
309+
(defun debugger-remove-breakpoint (debugger address)
310+
(removef (debugger-breakpoints debugger) address))
311+
299312
(defun debugger-add-callback-arrived (debugger function)
300313
(push function (debugger-callbacks-arrived debugger))
301314
t)
@@ -694,7 +707,7 @@
694707
(defun emulate-cycle (chip)
695708
(with-chip (chip)
696709
(debugger-print debugger chip)
697-
(if (debugger-should-wait-p debugger)
710+
(if (debugger-should-wait-p debugger program-counter)
698711
(sleep 10/1000)
699712
(let ((instruction (cat-bytes (aref memory program-counter)
700713
(aref memory (1+ program-counter)))))

vendor/make-quickutils.lisp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
:once-only
1313
:rcurry
1414
:read-file-into-byte-vector
15+
:removef
1516
:symb
1617
:with-gensyms
1718
:xor

vendor/quickutils.lisp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
;;;; See http://quickutil.org for details.
33

44
;;;; To regenerate:
5-
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:COMPOSE :CURRY :ENSURE-BOOLEAN :ENSURE-GETHASH :ENSURE-LIST :ONCE-ONLY :RCURRY :READ-FILE-INTO-BYTE-VECTOR :SYMB :WITH-GENSYMS :XOR) :ensure-package T :package "CHIP8.QUICKUTILS")
5+
;;;; (qtlc:save-utils-as "quickutils.lisp" :utilities '(:COMPOSE :CURRY :ENSURE-BOOLEAN :ENSURE-GETHASH :ENSURE-LIST :ONCE-ONLY :RCURRY :READ-FILE-INTO-BYTE-VECTOR :REMOVEF :SYMB :WITH-GENSYMS :XOR) :ensure-package T :package "CHIP8.QUICKUTILS")
66

77
(eval-when (:compile-toplevel :load-toplevel :execute)
88
(unless (find-package "CHIP8.QUICKUTILS")
@@ -18,9 +18,9 @@
1818
:ENSURE-GETHASH :ENSURE-LIST
1919
:ONCE-ONLY :RCURRY :WITH-OPEN-FILE*
2020
:WITH-INPUT-FROM-FILE
21-
:READ-FILE-INTO-BYTE-VECTOR :MKSTR
22-
:SYMB :STRING-DESIGNATOR :WITH-GENSYMS
23-
:XOR))))
21+
:READ-FILE-INTO-BYTE-VECTOR :REMOVEF
22+
:MKSTR :SYMB :STRING-DESIGNATOR
23+
:WITH-GENSYMS :XOR))))
2424
(eval-when (:compile-toplevel :load-toplevel :execute)
2525
(defun make-gensym-list (length &optional (x "G"))
2626
"Returns a list of `length` gensyms, each generated as if with a call to `make-gensym`,
@@ -211,6 +211,16 @@ which is only sent to `with-open-file` when it's not `nil`."
211211
result))))
212212

213213

214+
(declaim (inline remove/swapped-arguments))
215+
(defun remove/swapped-arguments (sequence item &rest keyword-arguments)
216+
(apply #'remove item sequence keyword-arguments))
217+
218+
(define-modify-macro removef (item &rest remove-keywords)
219+
remove/swapped-arguments
220+
"Modify-macro for `remove`. Sets place designated by the first argument to
221+
the result of calling `remove` with `item`, place, and the `keyword-arguments`.")
222+
223+
214224
(defun mkstr (&rest args)
215225
"Receives any number of objects (string, symbol, keyword, char, number), extracts all printed representations, and concatenates them all into one string.
216226
@@ -293,7 +303,7 @@ value."
293303

294304
(eval-when (:compile-toplevel :load-toplevel :execute)
295305
(export '(compose curry ensure-boolean ensure-gethash ensure-list once-only
296-
rcurry read-file-into-byte-vector symb with-gensyms
306+
rcurry read-file-into-byte-vector removef symb with-gensyms
297307
with-unique-names xor)))
298308

299309
;;;; END OF quickutils.lisp ;;;;

0 commit comments

Comments
 (0)