1 ;;; ez.el --- Emacs Z-machine
3 ;; Copyright (C) 2021 Tim Vaughan
5 ;; Author: Tim Vaughan <timv@ughan.xyz>
6 ;; Created: 13 Oct 2021
9 ;; Homepage: http://thelambdalab.xyz/ez
10 ;; Package-Requires: ((emacs "26"))
12 ;; This file is not part of GNU Emacs.
14 ;; This program is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
19 ;; This program is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with this file. If not, see <http://www.gnu.org/licenses/>.
33 (defun ez-decode-signed-bits (n nbits)
34 (if (= 0 (lsh n (- 1 nbits)))
38 (defun ez-decode-signed-byte (b)
39 (ez-decode-signed-bits b 8))
41 (defun ez-decode-signed-word (w)
42 (ez-decode-signed-bits w 16))
44 (defun ez-decode-signed-operand (operand operand-type)
45 (if (eq operand-type 'b)
46 (ez-decode-signed-byte operand)
47 (ez-decode-signed-word operand)))
49 (defun binformat (n &optional s)
53 (new-s (concat (number-to-string (mod n 2)) s)))
56 (binformat d new-s))))
61 "Memory of z-machine.")
63 (defvar ez-version nil)
65 (defvar ez-start-pc nil)
66 (defvar ez-himem-base nil)
67 (defvar ez-dict-addr nil)
68 (defvar ez-objtab-addr nil)
69 (defvar ez-abbrevtab-addr nil)
70 (defvar ez-globalvartab-addr nil)
72 (defun ez-mem-ref-byte (addr)
73 (aref ez-memory addr))
75 (defun ez-mem-set-byte (addr val)
76 (aset ez-memory addr val))
78 (defun ez-mem-ref-word (addr)
79 (+ (* 256 (aref ez-memory addr))
80 (aref ez-memory (+ addr 1))))
82 (defun ez-mem-set-word (addr val)
83 (let ((byte-high (/ val 256))
84 (byte-low (mod val 256)))
85 (aset ez-memory addr byte-high)
86 (aset ez-memory (+ addr 1) byte-low)))
88 (defun ez-parse-header ()
89 (setq ez-version (ez-mem-ref-byte #x0))
90 (setq ez-himem-addr (ez-mem-ref-word #x4))
91 (setq ez-start-pc (ez-mem-ref-word #x6))
92 (setq ez-dict-base (ez-mem-ref-word #x8))
93 (setq ez-objtab-addr (ez-mem-ref-word #xA))
94 (setq ez-globalvartab-addr (ez-mem-ref-word #xC))
95 (setq ez-abbrevtab-addr (ez-mem-ref-word #x18)))
97 (defun ez-load-file (filename)
98 "Load story file into memory."
100 (insert-file-contents-literally filename)
101 (setq ez-memory (encode-coding-string (buffer-string) 'raw-text)))
106 (defun ez-get-global-var (gvar)
108 (error "Invalid global variable %d" gvar))
109 (ez-mem-ref-word (+ (* 2 gvar) ez-globalvartab-addr)))
111 (defun ez-set-global-var (gvar val)
112 (ez-mem-set-word (+ (* 2 gvar) ez-globalvartab-addr) val))
116 (defvar ez-property-defaults nil)
118 (defun ez-load-property-defaults ()
119 (setq ez-property-defaults (make-vector 31 0))
121 (aset ez-property-defaults i (aref ez-memory (+ ez-objtab-addr (* 2 i))))))
123 (defun ez-get-obj-addr (obj-id)
124 (+ ez-objtab-addr (* 2 31) (* 9 (- obj-id 1))))
126 (defun ez-get-obj-parent (obj-id)
127 (let ((addr (ez-get-obj-addr obj-id)))
128 (ez-mem-ref-byte (+ addr 4))))
130 (defun ez-get-obj-sibling (obj-id)
131 (let ((addr (ez-get-obj-addr obj-id)))
132 (ez-mem-ref-byte (+ addr 5))))
134 (defun ez-get-obj-child (obj-id)
135 (let ((addr (ez-get-obj-addr obj-id)))
136 (ez-mem-ref-byte (+ addr 6))))
138 (defun ez-get-obj-plist-addr (obj-id)
139 (let ((addr (ez-get-obj-addr obj-id)))
140 (ez-mem-ref-word (+ addr 7))))
142 (defun ez-get-obj-name (obj-id)
143 (let ((plist-addr (ez-get-obj-plist-addr obj-id)))
144 (if (> (ez-mem-ref-byte plist-addr) 0)
145 (ez-get-zstring (+ 1 (ez-get-obj-plist-addr obj-id)))
148 (defun ez-get-obj (obj-id)
149 (let ((addr (+ ez-objtab-addr
151 (* 9 (- obj-id 1)))))
154 (ez-mem-ref-byte (+ addr 4))
155 (ez-mem-ref-byte (+ addr 5))
156 (ez-mem-ref-byte (+ addr 6))
157 (ez-mem-ref-word (+ addr 7))
158 (let ((plist-addr (ez-mem-ref-word (+ addr 7))))
159 (if (> (ez-mem-ref-byte plist-addr) 0)
160 (ez-get-zstring (+ 1 plist-addr))
163 (defun ez-get-prop-default (prop)
164 (ez-mem-ref-word (+ ez-objtab-addr (* 2 (+ 1 prop)))))
166 (defun ez-get-prop-len (prop-size-byte)
167 (lsh prop-size-byte -5))
169 (defun ez-get-prop-num (prop-size-byte)
170 (logand #b00011111 prop-size-byte))
172 (defun ez-get-obj-prop-addr (obj prop)
173 (let* ((plist-addr (ez-get-obj-plist-addr obj))
174 (prop-addr (+ plist-addr 1 (* 2 (ez-mem-ref-byte plist-addr))))
175 (size-byte (ez-mem-ref-byte prop-addr)))
176 (while (not (or (= size-byte 0)
177 (= prop (ez-get-prop-num size-byte))))
178 (setq prop-addr (+ prop-addr (ez-get-prop-len size-byte) 2)
179 size-byte (ez-mem-ref-byte prop-addr)))
182 (defun ez-get-obj-prop (obj prop)
183 (let* ((prop-addr (ez-get-obj-prop-addr obj prop))
184 (size-byte (ez-mem-ref-byte prop-addr)))
186 (ez-get-prop-default prop)
187 (let ((prop-len (ez-get-prop-len size-byte))
188 (data-addr (+ prop-addr 1)))
191 (ez-mem-ref-byte data-addr))
193 (ez-mem-ref-word data-addr)))))))
195 (defun ez-set-obj-prop (obj prop value)
196 (let* ((prop-addr (ez-get-obj-prop-addr obj prop))
197 (size-byte (ez-mem-ref-byte prop-addr)))
200 (error "Tried to set non-existant property"))
201 ((= (ez-get-prop-len size-byte) 1)
202 (ez-mem-set-byte (+ prop-addr 1) value))
204 (ez-mem-set-word (+ prop-addr 1) value)))))
206 (defun ez-get-obj-attr (obj attr)
207 (let* ((byte-num (/ attr 8))
208 (bit-num (mod attr 8))
209 (bit-mask (lsh 1 (- 7 bit-num))))
210 (if (> (logand bit-mask (ez-mem-ref-byte (+ (ez-get-obj-addr obj) byte-num))) 0)
214 (defun ez-set-obj-attr (obj attr val)
215 (let* ((byte-num (/ attr 8))
216 (bit-num (mod attr 8))
217 (bit-mask (lsh 1 (- 7 bit-num)))
218 (byte-addr (+ (ez-get-obj-addr obj) byte-num))
219 (byte (ez-mem-ref-byte byte-addr))
220 (current-set (> (logand bit-mask byte) 0)))
221 (if (or (and current-set (= val 0))
222 (and (not current-set) (> val 0)))
223 (ez-mem-set-byte byte-addr (logxor byte bit-mask)))))
227 (defvar ez-zstring-alphabets
230 (list " abcdefghijklmnopqrstuvwxyz"
231 " ABCDEFGHIJKLMNOPQRSTUVWXYZ"
232 " \n0123456789.,!?_#'\"/\\-:()")
233 "Alphabets used by V3")
235 (defun ez-parse-zstring-word (word)
237 (logand (lsh word -10) #b11111)
238 (logand (lsh word -5) #b11111)
239 (logand word #b11111)))
241 (defun ez-get-zstring-chars (base-addr)
242 (let ((addr base-addr)
247 (let ((components (ez-parse-zstring-word (ez-mem-ref-word addr))))
248 (setq chars (append chars (cdr components)))
249 (setq addr (+ addr 2))
250 (setq word-count (+ word-count 1))
251 (when (= (car components) 1)
252 (setq not-done nil))))
253 (cons word-count chars)))
255 (defun ez-get-zstring (base-addr)
256 (let* ((word-count-and-chars (ez-get-zstring-chars base-addr))
257 (word-count (car word-count-and-chars))
258 (chars (cdr word-count-and-chars))
267 (* 2 (ez-mem-ref-word (+ ez-abbrevtab-addr
268 (* 2 (+ (* (- abbrev-char 1) 32) char)))))))
269 (setq s (concat s (cdr (ez-get-zstring abbrev-addr)))))
270 (setq abbrev-char nil))
271 ((memq char '(1 2 3)) ;Abbreviation
272 (setq abbrev-char char))
274 (setq cur (mod (+ cur 1) 3)))
276 (setq cur (mod (+ 3 (- cur 1)) 3)))
278 (setq s (concat s (substring (elt ez-zstring-alphabets cur)
281 (cons word-count s)))
286 (defvar ez-call-stack nil)
288 (defun ez-make-call-stack-frame (pc &optional call-method)
294 (defun ez-add-call-stack-frame (pc &optional call-method)
295 (push (ez-make-call-stack-frame pc call-method) ez-call-stack))
297 (defun ez-pop-call-stack-frame ()
300 (defun ez-routine-stack ()
301 (elt (car ez-call-stack) 1))
303 (defun ez-routine-stack-push (val)
304 (let ((frame (car ez-call-stack)))
305 (setf (elt frame 1) (cons val (elt frame 1)))))
307 (defun ez-routine-stack-pop ()
308 (let* ((frame (car ez-call-stack))
309 (rs-head (car (elt frame 1))))
310 (setf (elt frame 1) (cdr (elt frame 1)))
313 (defun ez-get-local-var (lvar)
314 (let ((frame (car ez-call-stack)))
315 (aref (elt frame 2) (- lvar 1))))
317 (defun ez-set-local-var (lvar val)
318 (let ((frame (car ez-call-stack)))
319 (aset (elt frame 2) (- lvar 1) val)))
322 (caar ez-call-stack))
324 (defun ez-set-pc (new-pc)
325 (setf (car (car ez-call-stack)) new-pc))
327 (defun ez-increment-pc (inc)
328 (ez-set-pc (+ (ez-get-pc) inc)))
330 (defun ez-read-pc-byte-and-inc ()
331 (let ((res (ez-mem-ref-byte (ez-get-pc))))
335 (defun ez-read-pc-word-and-inc ()
336 (let ((res (ez-mem-ref-word (ez-get-pc))))
340 ;; Instruction execution
342 (defun ez-get-var (var)
345 (ez-routine-stack-pop))
347 (ez-get-local-var var))
349 (ez-get-global-var (- var 16)))))
351 (defun ez-set-var (var val)
354 (ez-routine-stack-push val))
356 (ez-set-local-var var val))
358 (ez-set-global-var (- var 16) val))))
360 (defun ez-read-pc-var-and-inc ()
361 (ez-get-var (ez-read-pc-byte-and-inc)))
363 (defun ez-execute-instr ()
364 (let ((instr-pc (ez-get-pc))
365 (opbyte (ez-read-pc-byte-and-inc))
366 (optype) (opcode) (operands))
368 ((<= #x0 opbyte #x1f)
371 operands (list (ez-read-pc-byte-and-inc)
372 (ez-read-pc-byte-and-inc))
373 operand-types '(b b)))
374 ((<= #x20 opbyte #x3F)
376 opcode (- opbyte #x20)
377 operands (list (ez-read-pc-byte-and-inc)
378 (ez-read-pc-var-and-inc))
379 operand-types '(b w)))
380 ((<= #x40 opbyte #x5F)
382 opcode (- opbyte #x40)
383 operands (list (ez-read-pc-var-and-inc)
384 (ez-read-pc-byte-and-inc))
385 operand-types '(w b)))
386 ((<= #x60 opbyte #x7F)
388 opcode (- opbyte #x60)
389 operands (list (ez-read-pc-var-and-inc)
390 (ez-read-pc-var-and-inc))
391 operand-types '(w w)))
392 ((<= #x80 opbyte #x8F)
394 opcode (- opbyte #x80)
395 operands (list (ez-read-pc-word-and-inc))
397 ((<= #x90 opbyte #x9F)
399 opcode (- opbyte #x90)
400 operands (list (ez-read-pc-byte-and-inc))
402 ((<= #xA0 opbyte #xAF)
404 opcode (- opbyte #xa0)
405 operands (list (ez-read-pc-var-and-inc))
407 ((<= #xB0 opbyte #xBF)
409 opcode (- opbyte #xb0)
412 ((<= #xC0 opbyte #xDF)
414 opcode (- opbyte #xc0))
415 (let ((operands-and-types (ez-read-var-operands-and-inc)))
416 (setq operands (car operands-and-types)
417 operand-types (cdr operands-and-types))))
418 ((<= #xE0 opbyte #xFF)
420 opcode (- opbyte #xe0))
421 (let ((operands-and-types (ez-read-var-operands-and-inc)))
422 (setq operands (car operands-and-types)
423 operand-types (cdr operands-and-types)))))
424 (let ((table-row (assoc (list optype opcode) ez-op-table)))
426 (error "Unsupported op PC:%x Optype:%s Opcode:%x Operands:%s Operand-types:%s"
427 instr-pc optype opcode operands operand-types))
428 (let ((mnemonic (elt table-row 1)))
429 (message "PC:%x Optype:%s Opcode:%x Mnemonic:%s Operands:%s Operand-types:%s"
430 instr-pc optype opcode mnemonic operands operand-types))
431 (funcall (elt table-row 2) operands operand-types))))
433 (defun ez-read-var-operands-and-inc ()
434 (let* ((type-byte (ez-read-pc-byte-and-inc))
435 (types (let ((type1 (lsh type-byte -6)))
439 (let ((type2 (lsh (logand #b110000 type-byte) -4)))
443 (let ((type3 (lsh (logand #b1100 type-byte) -2)))
447 (let ((type4 (logand #b11)))
450 (list type4))))))))))))))
455 ((= type 0) (ez-read-pc-word-and-inc))
456 ((= type 1) (ez-read-pc-byte-and-inc))
457 ((= type 2) (ez-read-pc-var-and-inc))))
468 (defun ez-do-branch (branch)
469 (let* ((branch-byte (ez-read-pc-byte-and-inc))
470 (invert (= 0 (logand branch-byte #b10000000)))
471 (single-byte (> (logand branch-byte #b01000000) 0))
474 (logand branch-byte #b00111111)
475 (let ((pos (= (logand branch-byte #b00100000) 0))
476 (val (+ (* 256 (logand branch-byte #b00011111))
477 (ez-read-pc-byte-and-inc))))
481 (if (or (and branch (not invert))
482 (and (not branch) invert))
489 (ez-set-pc (+ (ez-get-pc) offset -2)))))))
494 '(((0op #x00) rtrue ez-op-rtrue)
495 ((0op #x01) rfalse ez-op-rfalse)
496 ((1op #x00) jz ez-op-jz)
497 ((1op #x05) inc ez-op-inc)
498 ((1op #x06) dec ez-op-dec)
499 ((1op #x0B) ret ez-op-ret)
500 ((1op #x0C) jump ez-op-jump)
501 ((2op #x05) inc_jg ez-op-inc-jg)
502 ((2op #x04) dec_jg ez-op-dec-jg)
503 ((2op #x0D) store ez-op-store)
504 ((1op #x0E) load ez-op-load)
505 ((var #x01) storew ez-op-storew)
506 ((2op #x0F) loadw ez-op-loadw)
507 ((2op #x01) je ez-op-je)
508 ((2op #x08) or ez-op-or)
509 ((2op #x09) and ez-op-and)
510 ((2op #x14) add ez-op-add)
511 ((2op #x15) sub ez-op-sub)
512 ((2op #x16) mul ez-op-mul)
513 ((2op #x17) div ez-op-div)
514 ((2op #x18) mod ez-op-mod)
515 ((var #x00) call_fv ez-op-callf)
516 ((1op #x01) get_sibling ez-op-get-sibling)
517 ((1op #x02) get_child ez-op-get-child)
518 ((1op #x03) get_parent ez-op-get-parent)
519 ((2op #x0A) test_attr ez-op-test-attr)
520 ((var #x03) put_prop ez-op-put-prop)
521 ((0op #x02) print ez-op-print)
522 ((0op #x0B) new_line ez-op-new-line)
523 ((var #x06) print_num ez-op-print-num)))
525 (defun ez-op-ret (operands &optional operand-types)
526 (let ((retval (car operands)))
527 (ez-pop-call-stack-frame)
528 (ez-set-var (ez-read-pc-byte-and-inc) retval))
531 (defun ez-op-rtrue (&optional operands operand-types)
535 (defun ez-op-rfalse (&optional operands operand-types)
539 (defun ez-op-jz (operands operand-types)
540 (ez-do-branch (= (car operands) 0))
543 (defun ez-op-je (operands operand-types)
544 (ez-do-branch (memq (car operands) (cdr operands)))
547 (defun ez-op-jg (operands operand-types)
548 (let ((s1 (ez-decode-signed-operand (car operands) (car operand-types)))
549 (s2 (ez-decode-signed-operand (cadr operands) (cadr operand-types))))
550 (ez-do-branch (> s1 s2)))
553 (defun ez-op-jl (operands operand-types)
554 (let ((s1 (ez-decode-signed-operand (car operands) (car operand-types)))
555 (s2 (ez-decode-signed-operand (cadr operands) (cadr operand-types))))
556 (ez-do-branch (< s1 s2)))
559 (defun ez-op-inc-jg (operands operand-types)
560 (let ((var (car operands)))
561 (ez-op-inc (list var))
562 (ez-op-jg (cons (ez-get-var var) (cdr operands)) (cons 'w (cdr operand-types))))
565 (defun ez-op-dec-jl (operands operand-types)
566 (let ((var (car operands)))
567 (ez-op-dec (list var))
568 (ez-op-jl (cons (ez-get-var var) (cdr operands)) (cons 'w (cdr operand-types))))
572 (defun ez-op-jump (operands operand-types)
573 (let ((offset (if (eq (car operand-types) 'b)
574 (ez-decode-signed-byte (car operands))
575 (ez-decode-signed-word (car operands)))))
576 (ez-set-pc (+ (ez-get-pc) offset -2)))
579 (defun ez-op-inc (operands &optional operand-types)
580 (let ((var (car operands)))
581 (ez-set-var var (mod (+ 1 (ez-get-var var)) #x10000)))
584 (defun ez-op-dec (operands &optional operand-types)
585 (let ((var (car operands)))
586 (ez-set-var var (mod (+ (ez-get-var var) 1) #x10000)))
589 (defun ez-op-store (operands operand-types)
590 (let ((var (car operands))
595 (defun ez-op-load (operands operand-types)
596 (let ((var (car operands)))
597 (ez-set-var (ez-read-pc-byte-and-inc) (ez-get-var var)))
600 (defun ez-op-storew (operands operand-types)
601 (let ((baddr (car operands))
603 (a (caddr operands)))
604 (ez-mem-set-word (+ baddr (* 2 n)) a))
607 (defun ez-op-loadw (operands operand-types)
608 (let ((baddr (car operands))
610 (ez-set-var (ez-read-pc-byte-and-inc) (ez-mem-ref-word (+ baddr (* 2 n)))))
613 (defun ez-op-and (operands operand-types)
614 (let ((a (car operands))
616 (ez-set-var (ez-read-pc-byte-and-inc) (logand a b)))
619 (defun ez-op-or (operands operand-types)
620 (let ((a (car operands))
622 (ez-set-var (ez-read-pc-byte-and-inc) (logior a b)))
625 (defun ez-op-add (operands operand-types)
626 (let ((a (car operands))
628 (ez-set-var (ez-read-pc-byte-and-inc) (mod (+ a b) #x10000)))
631 (defun ez-op-sub (operands operand-types)
632 (let ((a (car operands))
634 (ez-set-var (ez-read-pc-byte-and-inc) (mod (+ (- a b) #x10000) #x10000)))
637 (defun ez-op-mul (a b)
638 (let ((a (car operands))
640 (ez-set-var (ez-read-pc-byte-and-inc) (mod (* a b) #x10000)))
643 (defun ez-op-div (a b)
644 (error "Not implemented"))
646 (defun ez-op-mod (a b)
647 (error "Not implemented"))
649 (defun ez-op-callf (operands operand-types)
650 (let* ((raddr (car operands))
651 (call-operands (cdr operands))
653 (L (ez-mem-ref-byte r))
654 (n (length call-operands))
655 (new-pc (+ r 1 (* L 2))))
656 (ez-add-call-stack-frame new-pc)
659 (ez-set-local-var (+ i 1) (elt call-operands i))
660 (ez-set-local-var (+ i 1) (ez-mem-ref-word (+ r 1 (* 2 i)))))))
663 (defun ez-op-test-attr (operands operand-types)
664 (let ((obj (car operands))
665 (attr (cadr operands)))
666 (ez-do-branch (= 1 (ez-get-obj-attr obj attr)))
669 (defun ez-op-get-sibling (operands operand-types)
670 (let ((sib (ez-get-obj-sibling (car operands))))
671 (ez-set-var (ez-read-pc-byte-and-inc) sib)
672 (ez-do-branch (> sib 0))
675 (defun ez-op-get-child (operands operand-types)
676 (let ((child (ez-get-obj-child (car operands))))
677 (ez-set-var (ez-read-pc-byte-and-inc) child)
678 (ez-do-branch (> child 0))
681 (defun ez-op-get-parent (operands operand-types)
682 (let ((parent (ez-get-obj-parent (car operands))))
683 (ez-set-var (ez-read-pc-byte-and-inc) parent)
684 (ez-do-branch (> parent 0))
687 (defun ez-op-put-prop (operands operand-types)
688 (let* ((obj (car operands))
689 (prop (cadr operands))
690 (a (caddr operands)))
691 (ez-set-obj-prop obj prop a)
694 (defun ez-op-print (operands operand-types)
695 (let* ((word-count-and-string (ez-get-zstring (ez-get-pc)))
696 (word-count (car word-count-and-string))
697 (string (cdr word-count-and-string)))
699 (ez-increment-pc (* 2 word-count)))
702 (defun ez-op-new-line (operands operand-types)
706 (defun ez-op-print-num (operands operand-types)
707 (let ((s (ez-decode-signed-operand (car operands) (car operand-types))))
708 (ez-print (number-to-string s)))
714 (defun ez-run (filename)
715 (ez-load-file filename)
717 (setq ez-call-stack (list (ez-make-call-stack-frame ez-start-pc)))
719 (while (ez-execute-instr)))
725 (defun ez-render-prompt ()
726 (with-current-buffer "*ez*"
727 (let ((update-point (= ez-input-marker (point)))
728 (update-window-points (mapcar (lambda (w)
729 (list (= (window-point w) ez-input-marker)
731 (get-buffer-window-list nil nil t))))
733 (set-marker-insertion-type ez-prompt-marker nil)
734 (set-marker-insertion-type ez-input-marker t)
735 (let ((inhibit-read-only t))
736 (delete-region ez-prompt-marker ez-input-marker)
737 (goto-char ez-prompt-marker)
740 (propertize " " ; Need this to be separate to mark it as rear-nonsticky
743 (set-marker-insertion-type ez-input-marker nil))
744 (goto-char ez-input-marker))))
746 (defvar ez-prompt-marker nil
747 "Marker for prompt position in buffer.")
749 (defvar ez-input-marker nil
750 "Marker for prompt position in buffer.")
752 (defun ez-setup-buffer ()
753 (with-current-buffer (get-buffer-create "*ez*")
754 (let ((inhibit-read-only t))
755 (delete-region (point-min) (point-max)))
756 (setq-local scroll-conservatively 1)
757 (if (markerp ez-prompt-marker)
758 (set-marker ez-prompt-marker (point-max))
759 (setq ez-prompt-marker (point-max-marker)))
760 (if (markerp ez-input-marker)
761 (set-marker ez-input-marker (point-max))
762 (setq ez-input-marker (point-max-marker)))
763 (goto-char (point-max))
767 (defun ez-print (string)
768 (with-current-buffer "*ez*"
770 (goto-char ez-prompt-marker)
771 (insert-before-markers string))))
776 (let ((map (make-sparse-keymap)))
777 (define-key map (kbd "RET") 'ez-enter)
780 (define-derived-mode ez-mode text-mode "ez"
781 "Major mode for EZ.")
783 (when (fboundp 'evil-set-initial-state)
784 (evil-set-initial-state 'ez-mode 'insert))
787 (interactive "fEnter name of z3 story file: ")
788 (if (get-buffer "*ez*")
789 (switch-to-buffer "*ez*")
790 (switch-to-buffer "*ez*")
798 (switch-to-buffer "*ez*")