Ends the question about Memory available for application development, default is now 16KB

This commit is contained in:
Jeremiah Orians 2017-05-06 20:46:22 -04:00
parent f7810bbf80
commit b61b90641b
No known key found for this signature in database
GPG Key ID: 7457821534D2ACCD
3 changed files with 59 additions and 8 deletions

View File

@ -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()

27
vm.c
View File

@ -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);

View File

@ -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;
}