-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathizhora.lisp
78 lines (73 loc) · 2.62 KB
/
izhora.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(in-package :cl-izhora)
(ql:quickload "lispbuilder-sdl")
(ql:quickload "bordeaux-threads") ; Bordeaux threads are not used yet
;;; The main structure: state of an Izhora machine
;;; Temporary registers of the actual cellular automation not stored
;;; Additional features of the future machines already defined
(defstruct izhora
;; Default machine model is 2 for Izhora 1b (0 for Izhora 1, 1 for 1a)
(model 2 :type fixnum)
(code (make-array (expt 2 16) :element-type 'fixnum)) ; RAM
(pc 0 :type fixnum) ; PC
(i0 0 :type fixnum) ; Future interrupt vector 0
(i1 0 :type fixnum) ; Future interrupt vector 1
(l 0 :type fixnum) ; Future interrupt level
;; Accumulator and future extra registers
(a 0 :type fixnum)
(b 0 :type fixnum)
(c 0 :type fixnum)
(rp 0 :type fixnum) ; Future return stack pointer
(sp 0 :type fixnum) ; Future data stack pointer
(sc 0 :type fixnum) ; Scancode of the last pressed key
;; External storage for future models
(extmem
(make-array (expt 2 16) :element-type 'fixnum :adjustable t))
(ct 0)) ; Counter
(defun risc (machine opcode op)
)
(defun step-program (machine &optional (steps 1))
(declare (optimize (speed 3) (safety 0) (debug 0)))
(let ((pc 0) (a 0) (code 0) (jmp 0) (op 0)
(model (izhora-model machine)))
(declare (type fixnum a code pc jmp op model))
(if (> model 2)
;; For future RISC models
(loop for x from 1 to steps do
(setf
pc (izhora-pc machine)
a (izhora-a machine)
code (aref (izhora-code machine) pc)
jmp (ash code -16)
op (logand code #xffff))
(if (>= jmp #xfff0)
;; RISC features not implemented yet
(risc machine (logand jmp #xf) op)
(progn
(setf (izhora-a machine)
(logand (- (aref (izhora-code machine) op) a) #xffffffff)
(aref (izhora-code machine) op) (izhora-a machine))
(if (or (zerop (izhora-a machine))
(> (izhora-a machine) #x7fffffff))
(setf (izhora-pc machine)
jmp)
(setf (izhora-pc machine)
(logand (1+ pc) #xffff)))))
(setf (izhora-ct machine) (1+ (izhora-ct machine))))
;; For basic SUBLEQ models
(loop for x from 1 to steps do
(setf
pc (izhora-pc machine)
a (izhora-a machine)
code (aref (izhora-code machine) pc)
jmp (ash code -16)
op (logand code #xffff))
(setf (izhora-a machine)
(logand (- (aref (izhora-code machine) op) a) #xffffffff)
(aref (izhora-code machine) op) (izhora-a machine))
(if (or (zerop (izhora-a machine))
(> (izhora-a machine) #x7fffffff))
(setf (izhora-pc machine)
jmp)
(setf (izhora-pc machine)
(logand (1+ pc) #xffff)))
(setf (izhora-ct machine) (1+ (izhora-ct machine)))))))