prog8/python/tinyvm/main.py

33 lines
878 B
Python
Raw Normal View History

2018-03-04 16:03:49 +00:00
"""
Simplistic 8/16 bit Virtual Machine to execute a stack based instruction language.
Main entry point to launch a VM to execute the given programs.
Written by Irmen de Jong (irmen@razorvine.net) - license: GNU GPL 3.0
"""
2018-02-25 15:43:00 +00:00
import sys
from .parse import Parser
from .vm import VM
2018-03-03 11:13:25 +00:00
mainprogram = None
timerprogram = None
2018-02-25 15:43:00 +00:00
2018-03-03 11:13:25 +00:00
if len(sys.argv) >= 2:
source = open(sys.argv[1]).read()
parser = Parser(source)
mainprogram = parser.parse()
if len(sys.argv) == 3:
source = open(sys.argv[2]).read()
parser = Parser(source)
timerprogram = parser.parse()
if len(sys.argv) not in (2, 3):
raise SystemExit("provide 1 or 2 program file names as arguments")
2018-02-25 15:43:00 +00:00
# ZeroPage and hardware stack of a 6502 cpu are off limits for now
2018-03-04 16:03:49 +00:00
VM.readonly_mem_ranges = [(0x00, 0xff), (0x100, 0x1ff)]
2018-03-03 11:13:25 +00:00
vm = VM(mainprogram, timerprogram)
vm.enable_charscreen(0x0400, 40, 25)
2018-02-25 15:43:00 +00:00
vm.run()