Tue, 28 Dec 2010 17:31:28 +0000
add state initialisation for expansion RAM
src/main.c | file | annotate | diff | revisions | |
src/state.c | file | annotate | diff | revisions | |
src/state.h | file | annotate | diff | revisions |
1.1 --- a/src/main.c Tue Dec 28 17:25:46 2010 +0000 1.2 +++ b/src/main.c Tue Dec 28 17:31:28 2010 +0000 1.3 @@ -165,7 +165,7 @@ 1.4 // set up system state 1.5 // 512K of RAM 1.6 int i; 1.7 - if ((i = state_init(512*1024)) != STATE_E_OK) { 1.8 + if ((i = state_init(512*1024, 0)) != STATE_E_OK) { 1.9 fprintf(stderr, "ERROR: Emulator initialisation failed. Error code %d.\n", i); 1.10 return i; 1.11 }
2.1 --- a/src/state.c Tue Dec 28 17:25:46 2010 +0000 2.2 +++ b/src/state.c Tue Dec 28 17:31:28 2010 +0000 2.3 @@ -5,23 +5,34 @@ 2.4 #include "wd279x.h" 2.5 #include "state.h" 2.6 2.7 -int state_init(size_t ramsize) 2.8 +int state_init(size_t base_ram_size, size_t exp_ram_size) 2.9 { 2.10 // Free RAM if it's allocated 2.11 if (state.base_ram != NULL) 2.12 free(state.base_ram); 2.13 + if (state.exp_ram != NULL) 2.14 + free(state.exp_ram); 2.15 2.16 // Initialise hardware registers 2.17 state.romlmap = false; 2.18 2.19 - // Allocate RAM, making sure the user has specified a valid RAM amount first 2.20 - // Basically: 512KiB minimum, 4MiB maximum, in increments of 512KiB. 2.21 - if ((ramsize < 512*1024) || ((ramsize % (512*1024)) != 0)) 2.22 + // Allocate Base RAM, making sure the user has specified a valid RAM amount first 2.23 + // Basically: 512KiB minimum, 2MiB maximum, in increments of 512KiB. 2.24 + if ((base_ram_size < 512*1024) || (base_ram_size > 2048*1024) || ((base_ram_size % (512*1024)) != 0)) 2.25 return -1; 2.26 - state.base_ram = malloc(ramsize); 2.27 + state.base_ram = malloc(base_ram_size); 2.28 if (state.base_ram == NULL) 2.29 return -2; 2.30 - state.base_ram_size = ramsize; 2.31 + state.base_ram_size = base_ram_size; 2.32 + 2.33 + // Now allocate expansion RAM 2.34 + // The difference here is that we can have zero bytes of Expansion RAM; we're not limited to having a minimum of 512KiB. 2.35 + if ((exp_ram_size > 2048*1024) || ((exp_ram_size % (512*1024)) != 0)) 2.36 + return -1; 2.37 + state.exp_ram = malloc(exp_ram_size); 2.38 + if (state.exp_ram == NULL) 2.39 + return -2; 2.40 + state.exp_ram_size = exp_ram_size; 2.41 2.42 // Load ROMs 2.43 FILE *r14c, *r15c; 2.44 @@ -85,7 +96,12 @@ 2.45 free(state.base_ram); 2.46 state.base_ram = NULL; 2.47 } 2.48 - 2.49 + 2.50 + if (state.exp_ram != NULL) { 2.51 + free(state.exp_ram); 2.52 + state.exp_ram = NULL; 2.53 + } 2.54 + 2.55 // Deinitialise the disc controller 2.56 wd2797_done(&state.fdc_ctx); 2.57 }
3.1 --- a/src/state.h Tue Dec 28 17:25:46 2010 +0000 3.2 +++ b/src/state.h Tue Dec 28 17:31:28 2010 +0000 3.3 @@ -31,6 +31,8 @@ 3.4 //// Main system RAM 3.5 uint8_t *base_ram; ///< Base RAM data buffer 3.6 size_t base_ram_size; ///< Size of Base RAM buffer in bytes 3.7 + uint8_t *exp_ram; ///< Expansion RAM data buffer 3.8 + size_t exp_ram_size; ///< Size of Expansion RAM buffer in bytes 3.9 3.10 /// Video RAM 3.11 uint8_t vram[0x8000]; 3.12 @@ -81,11 +83,12 @@ 3.13 /** 3.14 * @brief Initialise system state 3.15 * 3.16 - * @param ramsize RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 4MiB. 3.17 + * @param base_ram_size Base RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 2MiB. 3.18 + * @param exp_ram_size Expansion RAM size in bytes -- must be a multiple of 512KiB, min 0, max 2MiB. 3.19 * 3.20 * Initialises the emulator's internal state. 3.21 */ 3.22 -int state_init(size_t ramsize); 3.23 +int state_init(size_t base_ram_size, size_t exp_ram_size); 3.24 3.25 /** 3.26 * @brief Deinitialise system state