mirror of
https://github.com/whscullin/apple1js.git
synced 2024-12-01 17:50:00 +00:00
58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
|
/* -*- mode: JavaScript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||
|
/* Copyright 2010-2019Will Scullin <scullin@scullinsteel.com>
|
||
|
*
|
||
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
||
|
* documentation for any purpose is hereby granted without fee, provided that
|
||
|
* the above copyright notice appear in all copies and that both that
|
||
|
* copyright notice and this permission notice appear in supporting
|
||
|
* documentation. No representations are made about the suitability of this
|
||
|
* software for any purpose. It is provided "as is" without express or
|
||
|
* implied warranty.
|
||
|
*/
|
||
|
|
||
|
import { base64_decode, base64_encode } from './base64';
|
||
|
import { allocMemPages } from './util';
|
||
|
|
||
|
export default function RAM(sp, ep) {
|
||
|
var mem;
|
||
|
var start_page = sp;
|
||
|
var end_page = ep;
|
||
|
|
||
|
mem = allocMemPages(ep - sp + 1);
|
||
|
|
||
|
for (var page = 0; page <= ep; page++) {
|
||
|
for (var off = 0; off < 0x100; off++) {
|
||
|
mem[page * 0x100 + off] = 0; // Math.floor(Math.random()*256);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
start: function() {
|
||
|
return start_page;
|
||
|
},
|
||
|
end: function() {
|
||
|
return end_page;
|
||
|
},
|
||
|
read: function(page, off) {
|
||
|
return mem[(page - start_page) * 0x100 + off];
|
||
|
},
|
||
|
write: function(page, off, val) {
|
||
|
mem[(page - start_page) * 0x100 + off] = val;
|
||
|
},
|
||
|
|
||
|
getState: function() {
|
||
|
return {
|
||
|
start: start_page,
|
||
|
end: end_page,
|
||
|
mem: base64_encode(mem)
|
||
|
};
|
||
|
},
|
||
|
|
||
|
setState: function(state) {
|
||
|
start_page = state.start;
|
||
|
end_page = state.end;
|
||
|
mem = base64_decode(state.mem);
|
||
|
}
|
||
|
};
|
||
|
}
|