diff --git a/README.markdown b/README.markdown index dbd4655..53988a5 100644 --- a/README.markdown +++ b/README.markdown @@ -463,22 +463,22 @@ We cannot absolute-indexed a word. | } ? indexed access of non-table -> We cannot absolute acess a word. -> -> | assign word screen 1024 -> | routine main { -> | lda screen -> | } -> ? absolute access of non-byte-based address -> -> Instead, we have to do this. -> -> | assign word screen 1024 -> | routine main { -> | lda | lda >screen -> | } -> = True +We cannot absolute access a word. + + | assign word screen 1024 + | routine main { + | lda screen + | } + ? absolute access of non-byte-based address + +Instead, we have to do this. + + | assign word screen 1024 + | routine main { + | lda screen + | } + = True -> Tests for functionality "Emit ASM for SixtyPical program" @@ -495,6 +495,8 @@ We cannot absolute-indexed a word. | lda screen, x | lda screen, y | lda (screen), y + | lda score | inc screen | tax | inx @@ -541,6 +543,8 @@ We cannot absolute-indexed a word. = lda screen, x = lda screen, y = lda (screen), y + = lda score + = lda score+1 = inc screen = tax = inx diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index 608d3a7..e9e49c0 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -49,6 +49,9 @@ emitInstr p r (COPY (NamedLocation st label) A) = "lda " ++ label emitInstr p r (COPY (NamedLocation st label) X) = "ldx " ++ label emitInstr p r (COPY (NamedLocation st label) Y) = "ldy " ++ label +emitInstr p r (COPY (LowByteOf (NamedLocation st label)) A) = "lda " ++ label +emitInstr p r (COPY (HighByteOf (NamedLocation st label)) A) = "lda " ++ label ++ "+1" + 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 a9f76e0..3398db1 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -39,6 +39,8 @@ data StorageLocation = A | Indexed StorageLocation StorageLocation | IndirectIndexed StorageLocation StorageLocation | NamedLocation (Maybe StorageType) LocationName + | LowByteOf StorageLocation + | HighByteOf StorageLocation deriving (Show, Ord, Eq) -- this is bunk, man. if a location does not appear in an analysis diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 981c3cb..8be2c0d 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -122,10 +122,24 @@ index = do "y" -> Y data AddressingModality = Directly LocationName + | HighBytely LocationName + | LowBytely LocationName | Indirectly LocationName | Immediately DataValue deriving (Ord, Show, Eq) +low_byte_of_absolute :: Parser AddressingModality +low_byte_of_absolute = do + string "<" + l <- locationName + return $ LowBytely l + +high_byte_of_absolute :: Parser AddressingModality +high_byte_of_absolute = do + string ">" + l <- locationName + return $ HighBytely l + indirect_location :: Parser AddressingModality indirect_location = do string "(" @@ -148,7 +162,9 @@ immediate = do addressing_mode :: (AddressingModality -> [StorageLocation] -> Instruction) -> Parser Instruction addressing_mode f = do - d <- ((try immediate) <|> (try indirect_location) <|> direct_location) + d <- ((try immediate) <|> (try high_byte_of_absolute) <|> + (try low_byte_of_absolute) <|> (try indirect_location) <|> + direct_location) indexes <- many index return $ f d indexes @@ -319,6 +335,8 @@ lda = do addressing_mode gen where gen (Immediately v) [] = COPY (Immediate v) A + gen (LowBytely l) [] = COPY (LowByteOf (NamedLocation Nothing l)) A + gen (HighBytely l) [] = COPY (HighByteOf (NamedLocation Nothing l)) A gen (Directly l) [] = COPY (NamedLocation Nothing l) A gen (Directly l) [reg] = COPY (Indexed (NamedLocation Nothing l) reg) A gen (Indirectly l) [reg] = COPY (IndirectIndexed (NamedLocation Nothing l) reg) A