"Load story file into memory."
(with-temp-buffer
(insert-file-contents-literally filename)
- (setq ez-memory (encode-coding-string (buffer-string) 'raw-text))))
+ (setq ez-memory (encode-coding-string (buffer-string) 'raw-text)))
+ 'done)
;; Global variables
(ez-get-zstring (+ 1 plist-addr))
nil)))))
+(defun ez-get-prop-default (prop)
+ (ez-mem-ref-word (+ ez-objtab-addr (* 2 (+ 1 prop)))))
+
+(defun ez-get-prop-len (prop-size-byte)
+ (lsh prop-size-byte -5))
+
+(defun ez-get-prop-num (prop-size-byte)
+ (logand #b00011111 prop-size-byte))
+
+(defun ez-get-obj-prop-addr (obj prop)
+ (let* ((plist-addr (ez-get-obj-plist-addr obj))
+ (prop-addr (+ plist-addr 1 (* 2 (ez-mem-ref-byte plist-addr))))
+ (size-byte (ez-mem-ref-byte prop-addr)))
+ (while (not (or (= size-byte 0)
+ (= prop (ez-get-prop-num size-byte))))
+ (setq prop-addr (+ prop-addr (ez-get-prop-len size-byte) 2)
+ size-byte (ez-mem-ref-byte prop-addr)))
+ prop-addr))
+
+(defun ez-get-obj-prop (obj prop)
+ (let* ((prop-addr (ez-get-obj-prop-addr obj prop))
+ (size-byte (ez-mem-ref-byte prop-addr)))
+ (if (= prop-addr 0)
+ (ez-get-prop-default prop)
+ (let ((prop-len (ez-get-prop-len size-byte))
+ (data-addr (+ prop-addr 1)))
+ (cond
+ ((= prop-len 0)
+ (ez-mem-ref-byte data-addr))
+ ((>= prop-len 1)
+ (ez-mem-ref-word data-addr)))))))
+
+(defun ez-set-obj-prop (obj prop value)
+ (let* ((prop-addr (ez-get-obj-prop-addr obj prop))
+ (size-byte (ez-mem-ref-byte prop-addr)))
+ (cond
+ ((= size-byte 0)
+ (error "Tried to set non-existant property"))
+ ((= (ez-get-prop-len size-byte) 1)
+ (ez-mem-set-byte (+ prop-addr 1) value))
+ (t
+ (ez-mem-set-word (+ prop-addr 1) value)))))
;; Z-strings
(defun ez-read-var-operands-and-inc ()
(let* ((type-byte (ez-read-pc-byte-and-inc))
- (bleh (message (binformat type-byte)))
(types (let ((type1 (lsh type-byte -6)))
(if (= type1 #b11)
nil
((2op #x16) mul ez-op-mul)
((2op #x17) div ez-op-div)
((2op #x18) mod ez-op-mod)
- ((var #x00) call_fv ez-op-callf)))
+ ((var #x00) call_fv ez-op-callf)
+ ((1op #x01) get_sibling ez-op-get-sibling)
+ ((1op #x02) get_child ez-op-get-child)
+ ((1op #x03) get_parent ez-op-get-parent)
+ ((var #x03) put_prop ez-op-put-prop)))
(defun ez-op-ret (operands &optional operand-types)
(let ((retval (car operands)))
(ez-set-local-var (+ i 1) (ez-mem-ref-word (+ r 1 (* 2 i)))))))
t)
+(defun ez-op-get-sibling (operands operand-types)
+ (let ((sib (ez-get-obj-sibling (car operands))))
+ (ez-set-var (ez-read-pc-byte-and-inc) sib)
+ (ez-do-branch (> sib 0))))
+
+(defun ez-op-get-child (operands operand-types)
+ (let ((child (ez-get-obj-child (car operands))))
+ (ez-set-var (ez-read-pc-byte-and-inc) child)
+ (ez-do-branch (> child 0))))
+
+(defun ez-op-get-parent (operands operand-types)
+ (let ((parent (ez-get-obj-parent (car operands))))
+ (ez-set-var (ez-read-pc-byte-and-inc) parent)
+ (ez-do-branch (> parent 0))))
+
+(defun ez-op-put-prop (operands operand-types)
+ (let* ((obj (car operands))
+ (prop (cadr operands))
+ (a (caddr operands)))
+ (ez-set-obj-prop obj prop a)))
+
;; Main
(defun ez-run (filename)
(ez-parse-header)
(setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
- (while (ez-execute-inst)))
+ (while (ez-execute-instr)))
;; Scratch
-(ez-load-file "zork1.z3")
-(ez-parse-header)
-(setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
-(ez-execute-instr)
-
-(while (ez-execute-instr))
-
-(binformat #x97)
-"10010111"
-(ez-get-obj 208)
-(binformat #x57)
-"01010111"
-
-
-
-ez-call-stack
-((28281 nil [33807 0 180 47872 0 0 0 0 0 0 0 0 ...] nil) (22022 nil [33807 65535 0 0 0 0 0 0 0 0 0 0 ...] nil) (20715 nil [0 0 0 0 0 0 0 0 0 0 0 0 ...] nil))
-
-((22049 nil [33807 0 180 47872 0 0 0 0 0 0 0 0 ...] nil) (22022 nil [33807 65535 0 0 0 0 0 0 0 0 0 0 ...] nil) (20715 nil [0 0 0 0 0 0 0 0 0 0 0 0 ...] nil))
-
-
-
-
-
-
-
-
-
-
+;; (ez-load-file "zork1.z3")
+;; (ez-parse-header)
+;; (setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
+;; (while (ez-execute-instr))
+(ez-run "zork1.z3")
;;; ez.el ends here