<commit_before>#!/usr/bin/env python -u

"""py65mon -- interact with a simulated 6502-based system

Usage: %s [options]

Options:
-h, --help             : Show this message
-m, --mpu <device>     : Choose which MPU device (default is 6502)
-l, --load <file>      : Load a file at address 0
-r, --rom <file>       : Load a rom at the top of address space and reset into it
-g, --goto <address>   : Perform a goto command after loading any files
-i, --input <address>  : define location of getc (default $f004)
-o, --output <address> : define location of putc (default $f001)
"""

import cmd
import getopt
import os
import re
import shlex
import sys

from asyncore import compact_traceback
from py65.devices.mpu6502 import MPU as NMOS6502
from py65.devices.mpu65c02 import MPU as CMOS65C02
from py65.devices.mpu65org16 import MPU as V65Org16
from py65.disassembler import Disassembler
from py65.assembler import Assembler
from py65.utils.addressing import AddressParser
from py65.utils import console
from py65.utils.conversions import itoa
from py65.memory import ObservableMemory

try:
    from urllib2 import urlopen
except ImportError: # Python 3
    from urllib.request import urlopen

class Monitor(cmd.Cmd):

    Microprocessors = {'6502': NMOS6502, '65C02': CMOS65C02,
                       '65Org16': V65Org16}

    def __init__(self, mpu_type=NMOS6502, completekey='tab', stdin=None,
                 stdout=None, argv=None):
        self.mpu_type = mpu_type
        self.putc_addr = 0xF001
        self.getc_addr = 0xF004
        if argv is None:
            argv = sys.argv
        self._breakpoints = []
        self._width = 78
        self.prompt = "."
        self._add_shortcuts()
        cmd.Cmd.__init__(self, completekey, stdin, stdout)
        self._parse_args(argv)
        self._reset(self.mpu_type,self.getc_addr,self.putc_addr)

    def _parse_args(self, argv):
        try:
            shortopts = 'hi:o:m:l:r:g:'
            longopts = ['help', 'mpu=', 'input=', 'output=', 'load=', 'rom=', 'goto=']
            options, args = getopt.getopt(argv[1:], shortopts, longopts)
            flag_load  = False
            load_value = ""
            flag_rom   = False
            rom_value  = ""
            flag_goto  = False
            goto_value = ""
            flag_mpu   = False
            mpu_value  = "6502"
        except getopt.GetoptError as exc:
            self._output(exc.args[0])
            self._usage()
            self._exit(1)

        for opt, value in options:

            if opt in ('-i', '--input'):
                self.getc_addr = int(value, 16)

            if opt in ('-o', '--output'):
                self.putc_addr = int(value, 16)

            if opt in ('-l', '--load'):
                flag_load = True
                load_value = value

            if opt in ('-r', '--rom'):
                flag_rom = True
                rom_value = value

            if opt in ('-g', '--goto'):
                flag_goto = True
                goto_value = value

            if opt in ('-m', '--mpu'):
                flag_mpu = True
                mpu_value = value

            elif opt in ("-h", "--help"):
                self._usage()
                self._exit(1)<commit_msg>Move defaults outside of getopt try/except block<commit_after>#!/usr/bin/env python -u

"""py65mon -- interact with a simulated 6502-based system

Usage: %s [options]

Options:
-h, --help             : Show this message
-m, --mpu <device>     : Choose which MPU device (default is 6502)
-l, --load <file>      : Load a file at address 0
-r, --rom <file>       : Load a rom at the top of address space and reset into it
-g, --goto <address>   : Perform a goto command after loading any files
-i, --input <address>  : define location of getc (default $f004)
-o, --output <address> : define location of putc (default $f001)
"""

import cmd
import getopt
import os
import re
import shlex
import sys

from asyncore import compact_traceback
from py65.devices.mpu6502 import MPU as NMOS6502
from py65.devices.mpu65c02 import MPU as CMOS65C02
from py65.devices.mpu65org16 import MPU as V65Org16
from py65.disassembler import Disassembler
from py65.assembler import Assembler
from py65.utils.addressing import AddressParser
from py65.utils import console
from py65.utils.conversions import itoa
from py65.memory import ObservableMemory

try:
    from urllib2 import urlopen
except ImportError: # Python 3
    from urllib.request import urlopen

class Monitor(cmd.Cmd):

    Microprocessors = {'6502': NMOS6502, '65C02': CMOS65C02,
                       '65Org16': V65Org16}

    def __init__(self, mpu_type=NMOS6502, completekey='tab', stdin=None,
                 stdout=None, argv=None):
        self.mpu_type = mpu_type
        self.putc_addr = 0xF001
        self.getc_addr = 0xF004
        if argv is None:
            argv = sys.argv
        self._breakpoints = []
        self._width = 78
        self.prompt = "."
        self._add_shortcuts()
        cmd.Cmd.__init__(self, completekey, stdin, stdout)
        self._parse_args(argv)
        self._reset(self.mpu_type,self.getc_addr,self.putc_addr)

    def _parse_args(self, argv):
        try:
            shortopts = 'hi:o:m:l:r:g:'
            longopts = ['help', 'mpu=', 'input=', 'output=', 'load=', 'rom=', 'goto=']
            options, args = getopt.getopt(argv[1:], shortopts, longopts)
        except getopt.GetoptError as exc:
            self._output(exc.args[0])
            self._usage()
            self._exit(1)

        flag_load  = False
        load_value = ""
        flag_rom   = False
        rom_value  = ""
        flag_goto  = False
        goto_value = ""
        flag_mpu   = False
        mpu_value  = "6502"

        for opt, value in options:
            if opt in ('-i', '--input'):
                self.getc_addr = int(value, 16)

            if opt in ('-o', '--output'):
                self.putc_addr = int(value, 16)

            if opt in ('-l', '--load'):
                flag_load = True
                load_value = value

            if opt in ('-r', '--rom'):
                flag_rom = True
                rom_value = value

            if opt in ('-g', '--goto'):
                flag_goto = True
                goto_value = value

            if opt in ('-m', '--mpu'):
                flag_mpu = True
                mpu_value = value

            elif opt in ("-h", "--help"):
                self._usage()
                self._exit(1)
{'fraction_non_alphanumeric': 0.11025204886346064, 'fraction_numerical': 0.034328127416112575, 'mean_word_length': 1.9346642468239565, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6047305', 'n_tokens_mistral': 2194, 'n_tokens_neox': 2004, 'n_words': 597}