1.1 --- a/src/state.c Tue Dec 28 17:25:46 2010 +0000 1.2 +++ b/src/state.c Tue Dec 28 17:31:28 2010 +0000 1.3 @@ -5,23 +5,34 @@ 1.4 #include "wd279x.h" 1.5 #include "state.h" 1.6 1.7 -int state_init(size_t ramsize) 1.8 +int state_init(size_t base_ram_size, size_t exp_ram_size) 1.9 { 1.10 // Free RAM if it's allocated 1.11 if (state.base_ram != NULL) 1.12 free(state.base_ram); 1.13 + if (state.exp_ram != NULL) 1.14 + free(state.exp_ram); 1.15 1.16 // Initialise hardware registers 1.17 state.romlmap = false; 1.18 1.19 - // Allocate RAM, making sure the user has specified a valid RAM amount first 1.20 - // Basically: 512KiB minimum, 4MiB maximum, in increments of 512KiB. 1.21 - if ((ramsize < 512*1024) || ((ramsize % (512*1024)) != 0)) 1.22 + // Allocate Base RAM, making sure the user has specified a valid RAM amount first 1.23 + // Basically: 512KiB minimum, 2MiB maximum, in increments of 512KiB. 1.24 + if ((base_ram_size < 512*1024) || (base_ram_size > 2048*1024) || ((base_ram_size % (512*1024)) != 0)) 1.25 return -1; 1.26 - state.base_ram = malloc(ramsize); 1.27 + state.base_ram = malloc(base_ram_size); 1.28 if (state.base_ram == NULL) 1.29 return -2; 1.30 - state.base_ram_size = ramsize; 1.31 + state.base_ram_size = base_ram_size; 1.32 + 1.33 + // Now allocate expansion RAM 1.34 + // The difference here is that we can have zero bytes of Expansion RAM; we're not limited to having a minimum of 512KiB. 1.35 + if ((exp_ram_size > 2048*1024) || ((exp_ram_size % (512*1024)) != 0)) 1.36 + return -1; 1.37 + state.exp_ram = malloc(exp_ram_size); 1.38 + if (state.exp_ram == NULL) 1.39 + return -2; 1.40 + state.exp_ram_size = exp_ram_size; 1.41 1.42 // Load ROMs 1.43 FILE *r14c, *r15c; 1.44 @@ -85,7 +96,12 @@ 1.45 free(state.base_ram); 1.46 state.base_ram = NULL; 1.47 } 1.48 - 1.49 + 1.50 + if (state.exp_ram != NULL) { 1.51 + free(state.exp_ram); 1.52 + state.exp_ram = NULL; 1.53 + } 1.54 + 1.55 // Deinitialise the disc controller 1.56 wd2797_done(&state.fdc_ctx); 1.57 }