Add some more tests
This commit is contained in:
@@ -2,10 +2,13 @@ import cocotb
|
||||
from cocotb.handle import Immediate
|
||||
|
||||
from cocotb.clock import Clock
|
||||
from cocotb.triggers import Timer, RisingEdge
|
||||
from cocotb.triggers import Timer, RisingEdge, FallingEdge
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
import struct
|
||||
import random
|
||||
|
||||
CLK_PERIOD = 5
|
||||
|
||||
memory = defaultdict(int)
|
||||
@@ -471,3 +474,79 @@ async def test_indirect_indexed(dut):
|
||||
]
|
||||
|
||||
await check_instruction_sequence(dut, expected_cpu_outputs)
|
||||
|
||||
@cocotb.test
|
||||
async def test_adc(dut):
|
||||
cocotb.start_soon(Clock(dut.clk, CLK_PERIOD, unit="ns").start())
|
||||
cocotb.start_soon(handle_memory(dut))
|
||||
|
||||
write_dword(0xfffffff4, 0x200)
|
||||
|
||||
|
||||
def zp_indirect():
|
||||
value = random.randint(0,255)
|
||||
address = random.randint(0x300, 0xffffffff)
|
||||
|
||||
address_le = struct.pack("<I", address)
|
||||
|
||||
# lda #$0
|
||||
# adc ($00)
|
||||
# wai
|
||||
write_bytes(0x200, [0xa9, 0x00, 0x72, 0x00, 0xcb])
|
||||
|
||||
write_bytes(0x00, address_le)
|
||||
write_byte(address, value)
|
||||
|
||||
return value
|
||||
|
||||
def absolute():
|
||||
value = random.randint(0,255)
|
||||
address = random.randint(0x300, 0xffffffff)
|
||||
|
||||
address_le = struct.pack("<I", address)
|
||||
|
||||
# lda $#0
|
||||
# adc $address
|
||||
# wai
|
||||
|
||||
write_bytes(0x200, [0xa9, 0x00, 0x6d])
|
||||
write_bytes(0x203, address_le)
|
||||
write_bytes(0x207, [0xcb])
|
||||
|
||||
write_byte(address, value)
|
||||
|
||||
return value
|
||||
|
||||
def indirect_x():
|
||||
value = random.randint(0,255)
|
||||
address = random.randint(0x300, 0xffffff00)
|
||||
x_offset = random.randint(0,250)
|
||||
|
||||
address_le = struct.pack("<I", address)
|
||||
|
||||
# lda #$0
|
||||
# ldx #x_offset
|
||||
# adc ($00,x)
|
||||
# wai
|
||||
|
||||
write_bytes(0x200, [0xa9, 0x00, 0xa2, x_offset, 0x61, 0x00, 0xcb])
|
||||
write_bytes(x_offset, address_le)
|
||||
write_byte(address, value)
|
||||
|
||||
return value
|
||||
|
||||
tests = [zp_indirect, absolute, indirect_x]
|
||||
|
||||
for test in tests:
|
||||
value = test()
|
||||
|
||||
dut.RDY.value = Immediate(1)
|
||||
|
||||
dut.reset.value = Immediate(1)
|
||||
for _ in range(10):
|
||||
await RisingEdge(dut.clk)
|
||||
dut.reset.value = 0
|
||||
|
||||
await FallingEdge(dut.RDY_O)
|
||||
|
||||
assert value == int(dut.A.value)
|
||||
Reference in New Issue
Block a user