(define ((make-instr opcode modifier A-mode A-num B-mode B-num name) . args)
(match args
(('copy n) (make-instr opcode modifier A-mode A-num B-mode B-num n))
+ (('copy-from! other n)
+ (set! opcode (other 'opcode))
+ (set! modifier (other 'modifier))
+ (set! A-mode (other 'A-mode))
+ (set! A-num (other 'A-num))
+ (set! B-mode (other 'B-mode))
+ (set! B-num (other 'B-num))
+ (set! name n))
(('opcode) opcode)
(('modifier) modifier)
(('A-mode) A-mode)
(define (make-player name ptr)
(list name ptr))
+(define (player-name player) (car player))
+(define (player-ptrs player) (cdr player))
+
(define (player-set-ptrs! player ptrs)
(set-cdr! prog-queue ptrs))
(let ((player (car players))
(other-players (cdr players))
(ptrs (player-ptrs player)))
- (let ((new-ptrs (execute-instr (car ptrs))))
+ (let ((new-ptrs (execute-instr (car ptrs) (player-name player))))
(if (null? new-ptrs)
(run other-players (+ step 1))
(begin
(player-set-ptrs! (append (cdr ptrs) new-ptrs))
(run (append other-players (list player)) (+ step 1)))))))))
-(define (execute-instr ptr)
+(define (execute-instr ptr name)
(let* ((instr (core-get ptr))
(A-pointer (eval-operand (instr 'A-mode) (instr 'A-num) ptr))
(B-pointer (eval-operand (instr 'B-mode) (instr 'B-num) ptr))
((DAT) '()) ;Game over, man, game over!
((MOV)
(case modifier
- ((A))
- ((B))
- ((AB))
- ((BA))
- ((F))
- ((X))))
+ ((A) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'A-num) name))
+ ((B) ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'B-num) name))
+ ((AB) ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'A-num) name))
+ ((BA) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'B-num) name))
+ ((F) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'A-num) name)
+ ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'B-num) name))
+ ((X) ((core-get B-pointer) 'set-A-num! ((core-get A-pointer) 'B-num) name)
+ ((core-get B-pointer) 'set-B-num! ((core-get A-pointer) 'A-num) name))
+ ((I) ((core-get B-pointer) 'copy-from! (core-get A-pointer) name)))
+ (list (addr+ ptr 1)))
((ADD)
(case modifier
((A))