Skip to content

Commit

Permalink
added load/save, removed cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimKorzh committed Aug 21, 2024
1 parent ff724ee commit 440244b
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions mobile.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
</div>
</div>
<button id="fullscreen" style="width: 100%; height: 150px; background-color: #222222; color: #fff; font-size: 40px;">FULLSCREEN</button>
<button id="load" style="width: 100%; height: 150px; background-color: #222222; color: #fff; font-size: 40px;">LOAD</button>
<button id="save" style="width: 100%; height: 150px; background-color: #222222; color: #fff; font-size: 40px;">SAVE</button>
<textarea id="program" style="width: 100%; height: 150px;"></textarea>
<script src="js/7-segment-display/Segment.js"></script>
<script src="js/7-segment-display/SegmentDisplay.js"></script>
<script src="js/6502_CPU/6502.dev.js"></script>
Expand All @@ -77,7 +80,23 @@
<script src="js/Converter/converter.js"></script>

<script>
// save program
$('#save').on('click', function() {
let from = parseInt(prompt("Enter start address:"));
let to = parseInt(prompt("Enter end address:"));
$('#program').val(RAM.slice(from, to));
});

// load program
$('#load').on('click', function() {
let memory = $('#program').val().split(',');
let start = parseInt(prompt('Enter load address:'));
for (let i = start; i < memory.length+start; i++) RAM[i] = parseInt(memory[i-start]);
});

// is fullscreen
var full = false;

// exit fullscreen
document.addEventListener("webkitfullscreenchange", function() {
if (full) {
Expand All @@ -103,6 +122,11 @@

// hide serial monitor
document.getElementById('serial_monitor').classList.toggle('hideP');

// show load/save
document.getElementById('load').classList.toggle('hideP');
document.getElementById('save').classList.toggle('hideP');
document.getElementById('program').classList.toggle('hideP');
}, 100);
}
});
Expand Down Expand Up @@ -132,35 +156,14 @@

// show serial monitor
document.getElementById('serial_monitor').classList.toggle('hideP');

// hide load/save
document.getElementById('load').classList.toggle('hideP');
document.getElementById('save').classList.toggle('hideP');
document.getElementById('program').classList.toggle('hideP');
}, 100);
});

// delete cookies
function deleteAllCookies() {
var cookies = document.cookie.split(";");

for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}

// update cookie
function setCookie() {
var expires = new Date();
expires.setTime(expires.getTime() + 31536000000); //1 year
document.cookie = 'ram=' + RAM.slice(0, 1500).toString() + ';expires=' + expires.toUTCString();
}

// use cookies to restore session
if (document.cookie) {
memory = document.cookie.split('ram=')[1].split(',');
for (let i = 0; i < memory.length; i++) RAM[i] = memory[i];
resetCPU();
}

// display size
DISPLAY_WIDTH = window.innerWidth;
DISPLAY_HEIGHT = 235;
Expand All @@ -185,18 +188,7 @@

// clear memory
$('#display').on('click', function(e) {
const userConfirmed = window.confirm("Do you want to clear memory?");
if (userConfirmed) {
resetCPU();
for (let i = 0; i < RAM.length; i++) RAM[i] = 0;
alert('Memory has been cleared!');
}
});

// push button
$(":button").on('touchstart', function(e) {
deleteAllCookies();
setCookie();
alert('Load/Save mode');
});

// init display
Expand Down

0 comments on commit 440244b

Please sign in to comment.