diff --git a/HISTORY.md b/HISTORY.md index b4d98c9..b083f05 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,10 +9,11 @@ * Added `nop` opcode, which compiles to `NOP` (mainly for timing.) * Accessing zero-page with `ld` and `st` generates zero-page opcodes. * A `byte` or `word` table can be initialized with a list of constants. +* Branching and repeating on the `n` flag is now supported. * Specifying multiple SixtyPical source files will produce a single compiled result from their combination. * Rudimentary support for Atari 2600 prelude in a 4K cartridge image, - and start of an example program in `eg/atari2600` directory. + and an example program in `eg/atari2600` directory. 0.14 ---- diff --git a/eg/atari2600/smiley.60p b/eg/atari2600/smiley.60p index c66d966..eebf314 100644 --- a/eg/atari2600/smiley.60p +++ b/eg/atari2600/smiley.60p @@ -81,7 +81,7 @@ repeat { st a, WSYNC dec x - } until z // FIXME orig loop used "bpl _wsync_loop" + } until n st a, WSYNC //; diff --git a/src/sixtypical/compiler.py b/src/sixtypical/compiler.py index 7dedbd4..113d8a2 100644 --- a/src/sixtypical/compiler.py +++ b/src/sixtypical/compiler.py @@ -15,7 +15,7 @@ CLC, SEC, ADC, SBC, ROL, ROR, INC, INX, INY, DEC, DEX, DEY, CMP, CPX, CPY, AND, ORA, EOR, - BCC, BCS, BNE, BEQ, + BCC, BCS, BNE, BEQ, BPL, BMI, JMP, JSR, RTS, SEI, CLI, NOP, @@ -518,10 +518,12 @@ False: { 'c': BCC, 'z': BNE, + 'n': BPL, }, True: { 'c': BCS, 'z': BEQ, + 'n': BMI, }, }[instr.inverted].get(instr.src.name) if cls is None: @@ -548,10 +550,12 @@ False: { 'c': BCC, 'z': BNE, + 'n': BPL, }, True: { 'c': BCS, 'z': BEQ, + 'n': BMI, }, }[instr.inverted].get(instr.src.name) if cls is None: diff --git a/src/sixtypical/gen6502.py b/src/sixtypical/gen6502.py index c880e18..f166391 100644 --- a/src/sixtypical/gen6502.py +++ b/src/sixtypical/gen6502.py @@ -157,6 +157,18 @@ class BNE(Instruction): opcodes = { Relative: 0xd0, + } + + +class BPL(Instruction): + opcodes = { + Relative: 0x10, + } + + +class BMI(Instruction): + opcodes = { + Relative: 0x30, } diff --git a/tests/SixtyPical Compilation.md b/tests/SixtyPical Compilation.md index 489bebe..19c7250 100644 --- a/tests/SixtyPical Compilation.md +++ b/tests/SixtyPical Compilation.md @@ -417,13 +417,13 @@ | routine main | trashes a, y, z, n, c | { - | ld y, 65 + | ld y, 199 | repeat { | ld a, y | inc y | } until not n | } - = $080D LDY #$41 + = $080D LDY #$C7 = $080F TYA = $0810 INY = $0811 BMI $080F