From 645079f03a98ad88c06d84261a64a600185cc5f2 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Sun, 18 Oct 2015 23:15:40 +0100 Subject: [PATCH] Implement 'with interrupts off'. --- src/sixtypical/analyzer.py | 2 ++ src/sixtypical/compiler.py | 5 +++++ src/sixtypical/evaluator.py | 2 ++ src/sixtypical/gen6502.py | 12 ++++++++++++ src/sixtypical/parser.py | 5 +++++ tests/SixtyPical Syntax.md | 4 +++- 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/sixtypical/analyzer.py b/src/sixtypical/analyzer.py index 80197ec..96c88ba 100644 --- a/src/sixtypical/analyzer.py +++ b/src/sixtypical/analyzer.py @@ -232,5 +232,7 @@ def analyze_instr(instr, context, routines): context.set_written(dest) context.set_touched(REG_A, FLAG_Z, FLAG_N) context.set_unmeaningful(REG_A, FLAG_Z, FLAG_N) + elif opcode == 'with-sei': + analyze_block(instr.block, context, routines) else: raise NotImplementedError(opcode) diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index f18c76c..bd5f673 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -16,6 +16,7 @@ from sixtypical.gen6502 import ( CMP, CPX, CPY, AND, ORA, EOR, BCC, BCS, BNE, BEQ, JMP, JSR, RTS, + SEI, CLI, ) @@ -236,5 +237,9 @@ class Compiler(object): if cls is None: raise UnsupportedOpcodeError(instr) self.emitter.emit(cls(Relative(top_label))) + elif opcode == 'with-sei': + self.emitter.emit(SEI()) + self.compile_block(instr.block) + self.emitter.emit(CLI()) else: raise NotImplementedError diff --git a/src/sixtypical/evaluator.py b/src/sixtypical/evaluator.py index e69bbaf..fb14ad9 100644 --- a/src/sixtypical/evaluator.py +++ b/src/sixtypical/evaluator.py @@ -160,5 +160,7 @@ def eval_instr(instr, context, routines): context.set(REG_A, 0) context.set(FLAG_Z, 0) context.set(FLAG_N, 0) + elif opcode == 'with-sei': + eval_block(instr.block) else: raise NotImplementedError diff --git a/src/sixtypical/gen6502.py b/src/sixtypical/gen6502.py index 4538c80..4175d92 100644 --- a/src/sixtypical/gen6502.py +++ b/src/sixtypical/gen6502.py @@ -135,6 +135,12 @@ class CLC(Opcode): } +class CLI(Opcode): + opcodes = { + Implied: 0x58, + } + + class CMP(Opcode): opcodes = { Immediate: 0xc9, @@ -287,6 +293,12 @@ class SEC(Opcode): } +class SEI(Opcode): + opcodes = { + Implied: 0x78, + } + + class STA(Opcode): opcodes = { Absolute: 0x8d, diff --git a/src/sixtypical/parser.py b/src/sixtypical/parser.py index 396a9ed..90c28e6 100644 --- a/src/sixtypical/parser.py +++ b/src/sixtypical/parser.py @@ -257,5 +257,10 @@ class Parser(object): self.scanner.expect(',') dest = self.locexpr() return Instr(opcode=opcode, dest=dest, src=src) + elif self.scanner.consume("with"): + self.scanner.expect("interrupts") + self.scanner.expect("off") + block = self.block() + return Instr(opcode='with-sei', dest=None, src=None, block=block) else: raise ValueError('bad opcode "%s"' % self.scanner.token) diff --git a/tests/SixtyPical Syntax.md b/tests/SixtyPical Syntax.md index 9d2fa67..7fb614d 100644 --- a/tests/SixtyPical Syntax.md +++ b/tests/SixtyPical Syntax.md @@ -205,6 +205,8 @@ Declaring a vector. | ld a, 0 | } | routine main { - | copy foo, cinv + | with interrupts off { + | copy foo, cinv + | } | } = ok