CHIP-8 in Common Lisp
stevelosh.com
CHIP-8 in Common Lisp
1–10 of 21 posts
Re: CHIP-8 in Common Lisp
#2If I understand correctly, that's because 0-1FF was ROM (including the interpreter itself) on the original machine, and you typed CHIP-8 programs into RAM.
Re: CHIP-8 in Common Lisp
#3 (defun-inline (setf vref) (new-value chip x y)
(setf (aref (chip-video chip) (+ (* +screen-width+ y) x))
new-value))Re: CHIP-8 in Common Lisp
#4Very interesting read! But could somebody explain why the following piece of code is needed? And why is it defined inline? (defun-inline (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
Normally function must be accessed trough the symbol and it can be redefined on the fly.
Re: CHIP-8 in Common Lisp
#5Very interesting read! But could somebody explain why the following piece of code is needed? And why is it defined inline? (defun-inline (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
vref and (setf vref) define getter and setter functions for manipulating pixel arrays. Since these functions are used a lot, it makes sense to allow compiler to inline them for maximum speed. Normally function must be accessed trough the symbol and it can be redefined on the fly.
Re: CHIP-8 in Common Lisp
#6Very interesting read! But could somebody explain why the following piece of code is needed? And why is it defined inline? (defun-inline (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
vref and (setf vref) define getter and setter functions for manipulating pixel arrays. Since these functions are used a lot, it makes sense to allow compiler to inline them for maximum speed. Normally function must be accessed trough the symbol and it can be redefined on the fly.
I would also think that lexical functions are not called via symbols...
Re: CHIP-8 in Common Lisp
#7Very interesting read! But could somebody explain why the following piece of code is needed? And why is it defined inline? (defun-inline (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
(declaim (inline (setf vref)))
(defun (setf vref) (new-value chip x y)
(setf (aref (chip-video chip) (+ (* +screen-width+ y) x))
new-value))Re: CHIP-8 in Common Lisp
#8> Also note that the program counter starts at address #x200, because that’s where the ROM data eventually gets loaded into the CHIP-8 memory. If I understand correctly, that's because 0-1FF was ROM (including the interpreter itself) on the original machine, and you typed CHIP-8 programs into RAM.
Re: CHIP-8 in Common Lisp
#9Very interesting read! But could somebody explain why the following piece of code is needed? And why is it defined inline? (defun-inline (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
Why is DEFUN-INLINE used over: (declaim (inline (setf vref))) (defun (setf vref) (new-value chip x y) (setf (aref (chip-video chip) (+ (* +screen-width+ y) x)) new-value))
Re: CHIP-8 in Common Lisp
#10> Also note that the program counter starts at address #x200, because that’s where the ROM data eventually gets loaded into the CHIP-8 memory. If I understand correctly, that's because 0-1FF was ROM (including the interpreter itself) on the original machine, and you typed CHIP-8 programs into RAM.
Yes, traditionally the interpreter was located there. However, there is no "original machine". CHIP-8 was originally designed as a virtual machine for portability, similar to Java. https://en.wikipedia.org/wiki/CHIP-8