#!/usr/bin/env python3
# testBoot.py - boot a Modem Wars disk in VICE with a SwiftLink cartridge attached and photograph
# the options menu.
#
#   python3 testBoot.py <disk.d64> <shotPrefix>
import os
import sys
import time

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from viceHarness import ViceSession, aciaArgs, ACIA_BASE, SCRATCH

SHOTS = os.path.join(os.path.dirname(os.path.abspath(__file__)), "shots")


def main():
    disk = os.path.abspath(sys.argv[1])
    prefix = sys.argv[2]
    os.makedirs(SHOTS, exist_ok=True)
    session = ViceSession(disk, f"{SCRATCH}/{prefix}.vice.log", aciaArgs(), label=prefix)
    try:
        session.connect()
        session.bootPastLoader()
        session.findWindow()
        time.sleep(12)
        session.shot(f"{SHOTS}/{prefix}Menu.png")
        # what is actually sitting at $E000, and is the ACIA responding?
        session.enterMonitor()
        session.mon("m e000 e017")
        session.mon("m e540 e56f")
        session.mon(f"m {ACIA_BASE:04x} {ACIA_BASE + 3:04x}")
        session.sock.sendall(b"x\n")
        session.recv(3)
    finally:
        session.close()


main()
