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