From 1aea850043427d2fbc40fbcb09f60d283aceac29 Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Wed, 2 Apr 2014 09:05:30 +0100 Subject: [PATCH] lda,y sta,y adc and --- README.markdown | 27 ++++++++++++++++++++++----- src/SixtyPical/Emitter.hs | 10 ++++++++-- src/SixtyPical/Model.hs | 4 ++++ src/SixtyPical/Parser.hs | 25 +++++++++++++++++++++---- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/README.markdown b/README.markdown index c0a6797..6189993 100644 --- a/README.markdown +++ b/README.markdown @@ -137,11 +137,12 @@ Funny syntax indicates use of a special form. In these, `absolute` must be a `reserve`d or `locate`d address. - X adc #immediate - X adc absolute + . + adc #immediate + adc absolute - X and #immediate - X and absolute + and #immediate + and absolute X asl X asl absolute @@ -203,6 +204,7 @@ In these, `absolute` must be a `reserve`d or `locate`d address. lda #immediate lda absolute lda absolute, x + lda absolute, y ldx #immediate ldx absolute @@ -235,10 +237,11 @@ In these, `absolute` must be a `reserve`d or `locate`d address. sed - X sei { block } + sei { block } sta absolute sta absolute, x + sta absolute, y stx absolute @@ -266,6 +269,8 @@ TODO * Work out the analyses again and document them * `repeat jmp` * Addressing modes; rename instructions to match +* Not responsible for BASIC header (cat externally) +* Put data at end, no need for jmp main Tests ----- @@ -419,6 +424,7 @@ We cannot absolute-indexed a word. | ldy #255 | lda screen | lda screen, x + | lda screen, y | inc screen | tax | inx @@ -440,12 +446,17 @@ We cannot absolute-indexed a word. | tya | sta screen | sta screen, x + | sta screen, y | dec screen | clc | cld | clv | sec | sed + | adc #8 + | adc screen + | and #8 + | and screen | } = .org 0 = .word $0801 @@ -460,6 +471,7 @@ We cannot absolute-indexed a word. = ldy #255 = lda screen = lda screen, x + = lda screen, y = inc screen = tax = inx @@ -481,12 +493,17 @@ We cannot absolute-indexed a word. = tya = sta screen = sta screen, x + = sta screen, y = dec screen = clc = cld = clv = sec = sed + = adc #8 + = adc screen + = and #8 + = and screen = rts | assign word screen 1024 diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index e3708ca..ced9117 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -59,10 +59,10 @@ emitInstr p r (COPY X A) = "txa" emitInstr p r (COPY Y A) = "tya" emitInstr p r (COPYINDEXED A (NamedLocation label) X) = "sta " ++ label ++ ", x" -emitInstr p r (COPYINDEXED A (NamedLocation label) Y) = "sta " ++ label ++ ", x" +emitInstr p r (COPYINDEXED A (NamedLocation label) Y) = "sta " ++ label ++ ", y" emitInstr p r (COPYINDEXED (NamedLocation label) A X) = "lda " ++ label ++ ", x" -emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", x" +emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", y" emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label @@ -72,6 +72,12 @@ emitInstr p r (CMPIMM A val) = "cmp #" ++ (show val) emitInstr p r (CMPIMM X val) = "cpx #" ++ (show val) emitInstr p r (CMPIMM Y val) = "cpy #" ++ (show val) +emitInstr p r (ADD A (NamedLocation label)) = "adc " ++ label +emitInstr p r (ADDIMM A val) = "adc #" ++ (show val) + +emitInstr p r (AND A (NamedLocation label)) = "and " ++ label +emitInstr p r (ANDIMM A val) = "and #" ++ (show val) + emitInstr p r (DELTA X 1) = "inx" emitInstr p r (DELTA X (-1)) = "dex" emitInstr p r (DELTA Y 1) = "iny" diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 375359e..adafc0a 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -58,6 +58,10 @@ data Instruction = PUT StorageLocation DataValue | COPYINDEXED StorageLocation StorageLocation StorageLocation | CMPIMM StorageLocation DataValue | CMP StorageLocation StorageLocation + | ADDIMM StorageLocation DataValue + | ADD StorageLocation StorageLocation + | ANDIMM StorageLocation DataValue + | AND StorageLocation StorageLocation | JSR RoutineName -- | JSRVECTOR StorageLocation | JMPVECTOR StorageLocation diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index c583961..41ca191 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -93,6 +93,7 @@ command = (try lda) <|> (try inx) <|> (try iny) <|> (try dex) <|> (try dey) <|> (try inc) <|> (try dec) <|> (try clc) <|> (try cld) <|> (try clv) <|> (try sec) <|> (try sed) <|> + (try adc) <|> (try SixtyPical.Parser.and) <|> (try sei) <|> (try jmp) <|> (try copy_vector_statement) <|> @@ -194,6 +195,20 @@ cpy = do (try $ immediate (\v -> CMPIMM Y v) <|> absolute (\l -> CMP Y (NamedLocation l))) +adc :: Parser Instruction +adc = do + string "adc" + spaces + (try $ immediate (\v -> ADDIMM A v) <|> + absolute (\l -> ADD A (NamedLocation l))) + +and :: Parser Instruction +and = do + string "and" + spaces + (try $ immediate (\v -> ANDIMM A v) <|> + absolute (\l -> AND A (NamedLocation l))) + immediate :: (DataValue -> Instruction) -> Parser Instruction immediate f = do string "#" @@ -209,9 +224,11 @@ index :: Parser StorageLocation index = do string "," spaces - string "x" + c <- (string "x" <|> string "y") spaces - return X + return $ case c of + "x" -> X + "y" -> Y absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction absolute_indexed f = do @@ -226,7 +243,7 @@ lda = do (try $ immediate (\v -> PUT A v) <|> absolute_indexed gen) where gen l [] = COPY (NamedLocation l) A - gen l [X] = COPYINDEXED (NamedLocation l) A X + gen l [reg] = COPYINDEXED (NamedLocation l) A reg ldx :: Parser Instruction ldx = do @@ -249,7 +266,7 @@ sta = do absolute_indexed gen where gen l [] = COPY A (NamedLocation l) - gen l [X] = COPYINDEXED A (NamedLocation l) X + gen l [reg] = COPYINDEXED A (NamedLocation l) reg stx :: Parser Instruction stx = do