1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2025-02-21 19:28:58 +00:00

Support branching and looping on the n flag.

This commit is contained in:
Chris Pressey 2018-03-29 14:45:28 +01:00
parent b9fb26320c
commit fa1b0cfae1
5 changed files with 22 additions and 5 deletions

View File

@ -9,10 +9,11 @@ History of SixtyPical
* Added `nop` opcode, which compiles to `NOP` (mainly for timing.) * Added `nop` opcode, which compiles to `NOP` (mainly for timing.)
* Accessing zero-page with `ld` and `st` generates zero-page opcodes. * Accessing zero-page with `ld` and `st` generates zero-page opcodes.
* A `byte` or `word` table can be initialized with a list of constants. * 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 * Specifying multiple SixtyPical source files will produce a single
compiled result from their combination. compiled result from their combination.
* Rudimentary support for Atari 2600 prelude in a 4K cartridge image, * 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 0.14
---- ----

View File

@ -81,7 +81,7 @@ define display_frame routine
repeat { repeat {
st a, WSYNC st a, WSYNC
dec x dec x
} until z // FIXME orig loop used "bpl _wsync_loop" } until n
st a, WSYNC st a, WSYNC
//; //;

View File

@ -15,7 +15,7 @@ from sixtypical.gen6502 import (
CLC, SEC, ADC, SBC, ROL, ROR, CLC, SEC, ADC, SBC, ROL, ROR,
INC, INX, INY, DEC, DEX, DEY, INC, INX, INY, DEC, DEX, DEY,
CMP, CPX, CPY, AND, ORA, EOR, CMP, CPX, CPY, AND, ORA, EOR,
BCC, BCS, BNE, BEQ, BCC, BCS, BNE, BEQ, BPL, BMI,
JMP, JSR, RTS, JMP, JSR, RTS,
SEI, CLI, SEI, CLI,
NOP, NOP,
@ -518,10 +518,12 @@ class Compiler(object):
False: { False: {
'c': BCC, 'c': BCC,
'z': BNE, 'z': BNE,
'n': BPL,
}, },
True: { True: {
'c': BCS, 'c': BCS,
'z': BEQ, 'z': BEQ,
'n': BMI,
}, },
}[instr.inverted].get(instr.src.name) }[instr.inverted].get(instr.src.name)
if cls is None: if cls is None:
@ -548,10 +550,12 @@ class Compiler(object):
False: { False: {
'c': BCC, 'c': BCC,
'z': BNE, 'z': BNE,
'n': BPL,
}, },
True: { True: {
'c': BCS, 'c': BCS,
'z': BEQ, 'z': BEQ,
'n': BMI,
}, },
}[instr.inverted].get(instr.src.name) }[instr.inverted].get(instr.src.name)
if cls is None: if cls is None:

View File

@ -160,6 +160,18 @@ class BNE(Instruction):
} }
class BPL(Instruction):
opcodes = {
Relative: 0x10,
}
class BMI(Instruction):
opcodes = {
Relative: 0x30,
}
class CLC(Instruction): class CLC(Instruction):
opcodes = { opcodes = {
Implied: 0x18 Implied: 0x18

View File

@ -417,13 +417,13 @@ Compiling `repeat ... until not n`.
| routine main | routine main
| trashes a, y, z, n, c | trashes a, y, z, n, c
| { | {
| ld y, 65 | ld y, 199
| repeat { | repeat {
| ld a, y | ld a, y
| inc y | inc y
| } until not n | } until not n
| } | }
= $080D LDY #$41 = $080D LDY #$C7
= $080F TYA = $080F TYA
= $0810 INY = $0810 INY
= $0811 BMI $080F = $0811 BMI $080F