Proper handling of memory sizes, fixes #114

This commit is contained in:
Fabian 2016-10-15 02:12:57 +02:00
parent 8605a48e7e
commit e2d68260d5
2 changed files with 19 additions and 7 deletions

View file

@ -545,10 +545,10 @@
{
memory_size = parseInt($("memory_size").value, 10) * MB;
if(memory_size < 16 * MB || memory_size >= 2048 * MB)
if(!memory_size)
{
alert("Invalid memory size - ignored.");
memory_size = 32 * MB;
alert("Invalid memory size - reset to 128MB");
memory_size = 128 * MB;
}
}
@ -558,13 +558,14 @@
{
vga_memory_size = parseInt($("video_memory_size").value, 10) * MB;
if(vga_memory_size <= 64 * 1024 || vga_memory_size >= 2048 * MB)
if(!vga_memory_size)
{
alert("Invalid video memory size - ignored.");
alert("Invalid video memory size - reset to 8MB");
vga_memory_size = 8 * MB;
}
}
/** @const */
var BIOSPATH = "bios/";
if(settings.use_bochs_bios)

View file

@ -558,13 +558,24 @@ CPU.prototype.reset = function()
/** @export */
CPU.prototype.create_memory = function(size)
{
if(size < 1024 * 1024)
{
size = 1024 * 1024;
}
else if((size | 0) < 0)
{
size = Math.pow(2, 31) - MMAP_BLOCK_SIZE;
}
size = ((size - 1) | (MMAP_BLOCK_SIZE - 1)) + 1 | 0;
dbg_assert((size | 0) > 0);
dbg_assert((size & MMAP_BLOCK_SIZE - 1) === 0);
this.memory_size = size;
// use by dynamic translator
//if(OP_TRANSLATION) this.mem_page_infos = new Uint8Array(1 << 20);
dbg_assert((size & MMAP_BLOCK_SIZE - 1) === 0);
var buffer = new ArrayBuffer(size);
this.mem8 = new Uint8Array(buffer);