diff --git a/README.markdown b/README.markdown index 314857a..9c749a1 100644 --- a/README.markdown +++ b/README.markdown @@ -177,20 +177,20 @@ In these, `absolute` must be a `reserve`d or `locate`d address. cpy absolute X cpy #immediate - X dec absolute + dec absolute - X dex + dex - X dey + dey X eor #immediate X eor absolute - X inc absolute + inc absolute - X inx + inx - X iny + iny ! jmp @@ -267,6 +267,8 @@ TODO * External routines * Work out the analyses again and document them * parse support immediate loads, compares +* number ifs and repeats +* hello, world sort of program * Addressing modes; rename instructions to match Tests @@ -360,9 +362,14 @@ No duplicate declarations. | assign word screen 4000 | routine main { | lda screen + | inc screen | tax + | inx + | dex | stx score | tay + | iny + | dey | sty score | cmp score | ldx score @@ -372,6 +379,7 @@ No duplicate declarations. | cpy screen | tya | sta screen + | dec screen | } = .org 0 = .word $0801 @@ -382,9 +390,14 @@ No duplicate declarations. = .alias screen 4000 = main: = lda screen + = inc screen = tax + = inx + = dex = stx score = tay + = iny + = dey = sty score = cmp score = ldx score @@ -394,6 +407,7 @@ No duplicate declarations. = cpy screen = tya = sta screen + = dec screen = rts | assign word screen 4000 diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index c3494fa..860428a 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -50,6 +50,13 @@ emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label +emitInstr p r (DELTA X 1) = "inx" +emitInstr p r (DELTA X (-1)) = "dex" +emitInstr p r (DELTA Y 1) = "iny" +emitInstr p r (DELTA Y (-1)) = "dey" +emitInstr p r (DELTA (NamedLocation label) 1) = "inc " ++ label +emitInstr p r (DELTA (NamedLocation label) (-1)) = "dec " ++ label + emitInstr p r (COPY A X) = "tax" emitInstr p r (COPY A Y) = "tay" emitInstr p r (COPY X A) = "txa" diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 6c09655..a531596 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -54,6 +54,7 @@ data Instruction = LOADIMM StorageLocation DataValue | CMP StorageLocation StorageLocation | JSR RoutineName | IF Branch [Instruction] [Instruction] + | DELTA StorageLocation DataValue | NOP deriving (Show, Ord, Eq) diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 36d4c74..4411a70 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -21,6 +21,7 @@ Command := "if" Branch Block "else" Block | "cmp" (LocationName | Immediate) | "cpx" (LocationName | Immediate) | "cpy" (LocationName | Immediate) + | "inx" | "iny" | "dex" | "dey" | "nop". Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs". @@ -80,6 +81,8 @@ command = (try lda) <|> (try ldx) <|> (try ldy) <|> (try sta) <|> (try stx) <|> (try sty) <|> (try txa) <|> (try tax) <|> (try tya) <|> (try tay) <|> (try cmp) <|> (try cpx) <|> (try cpy) <|> + (try inx) <|> (try iny) <|> (try dex) <|> (try dey) <|> + (try inc) <|> (try dec) <|> if_statement <|> nop nop :: Parser Instruction @@ -88,6 +91,44 @@ nop = do spaces return NOP +inx :: Parser Instruction +inx = do + string "inx" + spaces + return $ DELTA X 1 + +iny :: Parser Instruction +iny = do + string "iny" + spaces + return $ DELTA Y 1 + +dex :: Parser Instruction +dex = do + string "dex" + spaces + return $ DELTA X (-1) + +dey :: Parser Instruction +dey = do + string "dey" + spaces + return $ DELTA Y (-1) + +inc :: Parser Instruction +inc = do + string "inc" + spaces + l <- locationName + return (DELTA (NamedLocation l) 1) + +dec :: Parser Instruction +dec = do + string "dec" + spaces + l <- locationName + return (DELTA (NamedLocation l) (-1)) + cmp :: Parser Instruction cmp = do string "cmp"