diff --git a/User_Interface.py b/User_Interface.py index 7936095..5a8db43 100644 --- a/User_Interface.py +++ b/User_Interface.py @@ -21,6 +21,7 @@ import sys, getopt vm = ctypes.CDLL('./libvm.so') +vm.initialize_lilith.argtype = ctypes.c_uint vm.get_memory.argtype = ctypes.c_uint vm.get_memory.restype = ctypes.c_char_p vm.step_lilith.restype = ctypes.c_uint @@ -28,7 +29,22 @@ vm.set_register.argtype = (ctypes.c_uint, ctypes.c_uint) vm.set_memory.argtype = (ctypes.c_uint, ctypes.c_ubyte) def Reset_lilith(): - vm.initialize_lilith() + global Memory_Size + if 0 <= Memory_Size < 1024: + unit = 'Bytes' + chunks = Memory_Size + elif 1024 <= Memory_Size < (1024 * 1024): + unit = 'KB' + chunks = Memory_Size / 1024 + elif (1024 * 1024) <= Memory_Size < (1024 * 1024 * 1024): + unit = 'MB' + chunks = Memory_Size / (1024 * 1024) + else: + unit = 'GB' + chunks = Memory_Size / (1024 * 1024 * 1024) + + print("Current Memory Size is: " + str(chunks) + unit) + vm.initialize_lilith(Memory_Size) global Current_IP Current_IP = 0 global Watchpoints @@ -199,9 +215,9 @@ def get_footer(): def main(argv): global Debug_Point try: - opts, args = getopt.getopt(argv,"R:D:",["ROM=","DEBUG="]) + opts, args = getopt.getopt(argv,"R:D:W:M:",["ROM=","DEBUG=","WINDOW=", "MEMORY="]) except getopt.GetoptError: - print ('Knight.py ROM=$NAME DEBUG=$NUMBER\n') + print ('Knight.py ROM=$NAME DEBUG=$NUMBER WINDOW=$NUMBER\n') sys.exit(2) for opt, arg in opts: if opt == '-h': @@ -213,13 +229,25 @@ def main(argv): elif opt in ("-D", "--DEBUG"): global Debug_Point Debug_Point = int(arg) + elif opt in ("-W", "--WINDOW"): + global Current_Page + Current_Page = int(arg, 16) + elif opt in ("-M", "--MEMORY"): + global Memory_Size + if arg.endswith('K'): + Memory_Size = (int(arg[:-1]) * 1024) + elif arg.endswith('M'): + Memory_Size = (int(arg[:-1]) * 1024 * 1024) + elif arg.endswith('G'): + Memory_Size = (int(arg[:-1]) * 1024 * 1024 * 1024) subprocess.call("./bin/dis " + ROM_Name + " | sponge z_disassembled", shell=True) + Reset_lilith() Current_IP = 0 +Memory_Size = 16 * 1024 Current_Page = 0 Watchpoints = {0} Count=0 Debug_Point = 0 ROM_Name = "rom" -Reset_lilith() diff --git a/vm.c b/vm.c index de77483..01399bb 100644 --- a/vm.c +++ b/vm.c @@ -54,20 +54,23 @@ void execute_vm(struct lilith* vm) int main(int argc, char **argv) { int c; + int Memory_Size = (16 * 1024); tape_01_name = "tape_01"; tape_02_name = "tape_02"; char* rom_name = NULL; + char class; static struct option long_options[] = { {"rom", required_argument, 0, 'r'}, {"tape_01", required_argument, 0, '1'}, {"tape_02", required_argument, 0, '2'}, + {"memory", required_argument, 0, 'm'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int option_index = 0; - while ((c = getopt_long(argc, argv, "r:h:1:2", long_options, &option_index)) != -1) + while ((c = getopt_long(argc, argv, "r:h:1:2:m", long_options, &option_index)) != -1) { switch (c) { @@ -92,6 +95,26 @@ int main(int argc, char **argv) tape_02_name = optarg; break; } + case 'm': + { + int length = strlen(optarg) - 1; + class = optarg[length]; + optarg[length] = 0; + Memory_Size = atoi(optarg); + if('K' == class) + { + Memory_Size = Memory_Size * 1024; + } + else if('M' == class) + { + Memory_Size = Memory_Size * 1024 * 1024; + } + else if('G' == class) + { + Memory_Size = Memory_Size * 1024 * 1024 * 1024; + } + break; + } default: { exit(EXIT_FAILURE); @@ -107,7 +130,7 @@ int main(int argc, char **argv) /* Perform all the essential stages in order */ struct lilith* vm; - vm = create_vm(1 << 21); + vm = create_vm(Memory_Size); load_program(vm, rom_name); execute_vm(vm); destroy_vm(vm); diff --git a/wrapper.c b/wrapper.c index c50689a..32ee5b2 100644 --- a/wrapper.c +++ b/wrapper.c @@ -51,10 +51,10 @@ void execute_vm(struct lilith* vm) return; } -void initialize_lilith() +void initialize_lilith(unsigned int size) { struct lilith* vm; - vm = create_vm(1 << 21); + vm = create_vm(size); Globalvm = vm; }