Simple little tests

This commit is contained in:
Aearnus 2018-05-26 01:54:52 -07:00
parent 6553bbd7e3
commit 18266f7806
2 changed files with 51 additions and 10 deletions

View File

@ -3,17 +3,54 @@ module Main where
import SixtyFiveOhTwo.Instruction
import Control.Monad.State
import qualified Data.ByteString as B
import Data.Int
accumulatorLoadNStore :: Instruction
accumulatorLoadNStore = do
test1 :: Instruction
test1 = do
lda (Immediate 0xFF)
sta (ZeroPage 0x00)
lda (Immediate 0x00)
adc (Immediate 0x01)
cmp (ZeroPage 0x00)
bne (Relative (-0x03 :: Int8))
test2f :: Instruction
test2f = do
lda (Immediate 0x10)
sta (Absolute 0x0200)
rts (Implied)
myProgram :: Instruction
myProgram = do
define "accumulatorLoadNStore" accumulatorLoadNStore
test2 :: Instruction
test2 = do
define "accumulatorLoadNStore" test2f
call "accumulatorLoadNStore"
test3f2 :: Instruction
test3f2 = replicateM_ 10 (inc (Accumulator))
test3f1 :: Instruction
test3f1 = do
lda (Immediate 0x02)
define "addIt" test3f2
test3 :: Instruction
test3 = do
define "loadIt" test3f1
call "loadIt"
call "addIt"
main :: IO ()
main = B.putStr $ runInstructions myProgram
main = do
putStrLn "test one: simple program"
putStrLn "========================"
print $ execState test1 emptyState
putStrLn ""
putStrLn "test two: simple function"
putStrLn "========================="
print $ execState test2 emptyState
putStrLn ""
putStrLn "test two: nested function"
putStrLn "========================="
print $ execState test3 emptyState
putStrLn ""

View File

@ -7,6 +7,7 @@ import qualified Data.ByteString as B
import qualified Data.Map.Strict as M
import Control.Lens
import Data.Word
import Data.Int
import Data.Bits
data InstructionState = InstructionState {
@ -30,8 +31,8 @@ data AddressingMode =
Implied |
Accumulator |
Immediate Word8 |
Relative Word8 | -- Signed
ZeroPageRelative Word8 | -- Signed
Relative Int8 | -- Signed
ZeroPageRelative Int8 | -- Signed
Absolute Word16 |
AbsoluteX Word16 |
AbsoluteY Word16 |
@ -63,8 +64,11 @@ genericNoByteOp :: Word8 -> Instruction
genericNoByteOp op = modify $ appendBytes [op]
-- This function allows you to define an instruction opcode that takes a one byte argument
genericOp :: Word8 -> Word8 -> Instruction
genericOp op arg = modify $ appendBytes [op, arg]
-- This is polymorphic to support Int8 OR Word8
genericOp :: (FiniteBits a, Integral a) => Word8 -> a -> Instruction
-- fromIntegral from an IntN to a WordN does _not_ preserve value, only structure
-- Thus, this is valid code.
genericOp op arg = modify $ appendBytes [op, fromIntegral arg]
-- This function allows you to define an instruction opcode that takes a two byte argument
genericTwoByteOp :: Word8 -> Word16 -> Instruction