-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1bb344
commit e47abd7
Showing
3 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from argparse import ArgumentParser | ||
from importlib import import_module | ||
from typing import Tuple | ||
|
||
|
||
def parse_size(value: str) -> Tuple[int, int]: | ||
width, height = value.split('x') | ||
return int(width), int(height) | ||
|
||
|
||
parser = ArgumentParser( | ||
prog='pychip8', | ||
description='Chip-8 emulator written in Python', | ||
) | ||
parser.add_argument( | ||
'file', | ||
type=lambda x: open(x, 'rb'), # noqa: SIM115 | ||
help='path of the ROM to be executed', | ||
) | ||
parser.add_argument( | ||
'-c', | ||
'--clock', | ||
type=int, | ||
default=960, | ||
help='clock of CPU in Hertz (default: 960)', | ||
) | ||
parser.add_argument( | ||
'-i', | ||
'--instructions_per_update', | ||
type=int, | ||
default=16, | ||
help='number of instructions executed in an update (default: 16)', | ||
) | ||
parser.add_argument( | ||
'--interface', | ||
metavar='INTERFACE', | ||
choices=['ncurses', 'sdl'], | ||
default='ncurses', | ||
help='select interface (default: ncurses)', | ||
) | ||
parser.add_argument( | ||
'--ncurses', | ||
dest='interface', | ||
action='store_const', | ||
const='ncurses', | ||
help='use ncurses interface', | ||
) | ||
parser.add_argument( | ||
'--sdl', | ||
dest='interface', | ||
action='store_const', | ||
const='sdl', | ||
help='use SDL interface', | ||
) | ||
parser.add_argument( | ||
'-s', | ||
'--size', | ||
type=parse_size, | ||
default=(800, 400), | ||
help='size for GUI window (default: 800x400)', | ||
) | ||
|
||
|
||
def main() -> None: | ||
try: | ||
args = parser.parse_args() | ||
import_module(f'.{args.interface}', 'pychip8.interface').main( | ||
program=args.file, | ||
instructions_per_update=args.instructions_per_update, | ||
clock=args.clock, | ||
size=args.size, | ||
) | ||
except KeyboardInterrupt: | ||
... | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters