From 128fbcf5319604dd8cd9d0dacb06b7f3d2036dfd Mon Sep 17 00:00:00 2001 From: Cat's Eye Technologies Date: Tue, 1 Apr 2014 23:47:10 +0100 Subject: [PATCH] lda screen, x --- README.markdown | 6 +++++- src/SixtyPical/Emitter.hs | 3 +++ src/SixtyPical/Parser.hs | 23 ++++++++++++++--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/README.markdown b/README.markdown index 4cb7557..c0a6797 100644 --- a/README.markdown +++ b/README.markdown @@ -202,6 +202,7 @@ In these, `absolute` must be a `reserve`d or `locate`d address. lda #immediate lda absolute + lda absolute, x ldx #immediate ldx absolute @@ -237,6 +238,7 @@ In these, `absolute` must be a `reserve`d or `locate`d address. X sei { block } sta absolute + sta absolute, x stx absolute @@ -258,7 +260,7 @@ TODO ---- * Parse HEX values like $40A3 -* Tables +* Initial values for reserved, incl. tables * Character tables ("strings" to everybody else) * External routines * Work out the analyses again and document them @@ -416,6 +418,7 @@ We cannot absolute-indexed a word. | ldx #0 | ldy #255 | lda screen + | lda screen, x | inc screen | tax | inx @@ -456,6 +459,7 @@ We cannot absolute-indexed a word. = ldx #0 = ldy #255 = lda screen + = lda screen, x = inc screen = tax = inx diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index 30fc01a..e3708ca 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -61,6 +61,9 @@ 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 (NamedLocation label) A X) = "lda " ++ label ++ ", x" +emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", x" + 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 diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 846787e..c583961 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -213,12 +213,20 @@ index = do spaces return X +absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction +absolute_indexed f = do + l <- locationName + indexes <- many index + return $ f l indexes + lda :: Parser Instruction lda = do string "lda" spaces - (try $ immediate (\v -> PUT A v) <|> - absolute (\l -> COPY (NamedLocation l) A)) + (try $ immediate (\v -> PUT A v) <|> absolute_indexed gen) + where + gen l [] = COPY (NamedLocation l) A + gen l [X] = COPYINDEXED (NamedLocation l) A X ldx :: Parser Instruction ldx = do @@ -238,13 +246,10 @@ sta :: Parser Instruction sta = do string "sta" spaces - l <- locationName - indexes <- many index - return $ case indexes of - [] -> - COPY A (NamedLocation l) - [X] -> - COPYINDEXED A (NamedLocation l) X + absolute_indexed gen + where + gen l [] = COPY A (NamedLocation l) + gen l [X] = COPYINDEXED A (NamedLocation l) X stx :: Parser Instruction stx = do