-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperipherals.lisp
More file actions
23 lines (17 loc) · 827 Bytes
/
peripherals.lisp
File metadata and controls
23 lines (17 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(in-package :z80)
(defclass peripheral () ())
(defgeneric read-from (peripheral)
(:documentation "Read a byte from the peripheral"))
(defgeneric write-to (peripheral value)
(:documentation "Write a byte to the peripheral"))
(defclass simple-io-peripheral (peripheral)
((input-stream :initarg :input-stream :initform nil :accessor input-stream)
(output-stream :initarg :input-stream :initform nil :accessor output-stream))
(:documentation "Simple peripheral that prints chars to the terminal"))
(defmethod write-to ((tpp simple-io-peripheral) (b integer))
(let ((s (or (output-stream tpp) *standard-output*)))
(format s "~C" (code-char b))
(finish-output s)))
(defmethod read-from ((tpp simple-io-peripheral))
(let ((s (or (input-stream tpp) *standard-input*)))
(read-char (input-stream tpp))))