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