Added get/set obj attribute functions.
authorplugd <plugd@thelambdalab.xyz>
Mon, 15 Nov 2021 11:38:02 +0000 (12:38 +0100)
committerplugd <plugd@thelambdalab.xyz>
Mon, 15 Nov 2021 11:38:16 +0000 (12:38 +0100)
ez.el

diff --git a/ez.el b/ez.el
index ac40980..549b8f0 100644 (file)
--- a/ez.el
+++ b/ez.el
      (t
       (ez-mem-set-word (+ prop-addr 1) value)))))
 
      (t
       (ez-mem-set-word (+ prop-addr 1) value)))))
 
+(defun ez-get-obj-attr (obj attr)
+  (let* ((byte-num (/ attr 8))
+         (bit-num (mod attr 8))
+         (bit-mask (lsh 1 (- 7 bit-num))))
+    (if (> (logand bit-mask (ez-mem-ref-byte (+ (ez-get-obj-addr obj) byte-num))) 0)
+        1
+      0)))
+
+(defun ez-set-obj-attr (obj attr val)
+  (let* ((byte-num (/ attr 8))
+         (bit-num (mod attr 8))
+         (bit-mask (lsh 1 (- 7 bit-num)))
+         (byte-addr (+ (ez-get-obj-addr obj) byte-num))
+         (byte (ez-mem-ref-byte byte-addr))
+         (current-set (> (logand bit-mask byte) 0)))
+    (if (or (and current-set (= val 0))
+            (and (not current-set) (> val 0)))
+        (ez-mem-set-byte byte-addr (logxor byte bit-mask)))))
+
 ;; Z-strings
 
 (defvar ez-zstring-alphabets
 ;; Z-strings
 
 (defvar ez-zstring-alphabets
             operand-types '(w)))
      ((<= #xB0 opbyte #xBF)
       (setq optype '0op
             operand-types '(w)))
      ((<= #xB0 opbyte #xBF)
       (setq optype '0op
-            opcode (- opbyte #xb0)))
+            opcode (- opbyte #xb0)
+            operands '()
+            operand-types '()))
      ((<= #xC0 opbyte #xDF)
       (error "Unsupported op %x" opbyte))
      ((<= #xE0 opbyte #xFF)
      ((<= #xC0 opbyte #xDF)
       (error "Unsupported op %x" opbyte))
      ((<= #xE0 opbyte #xFF)
         (error "Unsupported op PC:%x Optype:%s Opcode:%x Operands:%s Operand-types:%s"
                instr-pc optype opcode operands operand-types))
       (let ((mnemonic (elt table-row 1)))
         (error "Unsupported op PC:%x Optype:%s Opcode:%x Operands:%s Operand-types:%s"
                instr-pc optype opcode operands operand-types))
       (let ((mnemonic (elt table-row 1)))
-        (message "PC:%x Optype:%s Opcode:%x Mnemonic:%s Operands:%s"
-                 instr-pc optype opcode mnemonic operands))
+        (message "PC:%x Optype:%s Opcode:%x Mnemonic:%s Operands:%s Operand-types:%s"
+                 instr-pc optype opcode mnemonic operands operand-types))
       (funcall (elt table-row 2) operands operand-types))))
 
 (defun ez-read-var-operands-and-inc ()
       (funcall (elt table-row 2) operands operand-types))))
 
 (defun ez-read-var-operands-and-inc ()
                                               (let ((type4 (logand #b11)))
                                                 (if (= type4 #b11)
                                                     nil
                                               (let ((type4 (logand #b11)))
                                                 (if (= type4 #b11)
                                                     nil
-                                                  (list type4)))))))))))))
-         (operands nil))
+                                                  (list type4))))))))))))))
     (cons
      (mapcar
       (lambda (type)
     (cons
      (mapcar
       (lambda (type)