Misc. Cleanup and fixes

This commit is contained in:
Will Scullin 2014-06-26 06:46:01 -07:00
parent 79e7dbe1e1
commit a6f454f845
9 changed files with 136 additions and 115 deletions

View File

@ -59,7 +59,8 @@
<script type="text/javascript" src="js/ramfactor.js"></script>
<script type="text/javascript" src="js/thunderclock.js"></script>
<script type="text/javascript" src="js/cpu6502.js"></script>
<script type="text/javascript" src="js/base64.js"></script>
<script type="text/javascript" src="js/base64.js"></script><
<script type="text/javascript" src="js/ui/audio.js"></script>
<script type="text/javascript" src="js/ui/keyboard2e.js"></script>
<script type="text/javascript" src="js/ui/gamepad.js"></script>
<script type="text/javascript" src="js/ui/printer.js"></script>

View File

@ -1,5 +1,6 @@
/* -*- mode: JavaScript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*global bytify:false */
/*exported Apple2eEnhancedROM */
function Apple2eEnhancedROM()
@ -2054,14 +2055,8 @@ function Apple2eEnhancedROM()
0x83,0x7f,0x5d,0xcc,0xb5,0xfc,0x17,0x17,
0xf5,0x03,0xfb,0x03,0x62,0xfa,0xfa,0xc3
];
var mem = [];
for (var page = 0x00; page < 0x40; page++) {
mem[page] = [];
for (var off = 0; off < 256; off++) {
mem[page ][off] = rom[page * 256 + off];
}
}
rom = bytify(rom);
return {
start: function apple2e_start() {
@ -2079,4 +2074,3 @@ function Apple2eEnhancedROM()
setState: function() {}
};
}

View File

@ -1,5 +1,5 @@
/* -*- mode: JavaScript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*global bytify:false */
/*exported Apple2eROM*/
function Apple2eROM()
@ -2056,14 +2056,8 @@ function Apple2eROM()
0x83,0x7f,0x5d,0xcc,0xb5,0xfc,0x17,0x17,
0xf5,0x03,0xfb,0x03,0x62,0xfa,0x40,0xfa
];
var mem = [];
for (var page = 0x00; page < 0x40; page++) {
mem[page] = [];
for (var off = 0; off < 256; off++) {
mem[page ][off] = rom[page << 8 | off];
}
}
rom = bytify(rom);
return {
start: function apple2e_start() {

View File

@ -51,41 +51,22 @@ function LoresPage(page)
var _green = [0x00,0xff,0x80];
var _colors = [
[0x00,0x00,0x00], // 0 Black 0000 0 0
[0x90,0x17,0x40], // 1 Red 0001 8 1
[0x3c,0x22,0xa5], // 2 Dark Blue 1000 1
[0xd0,0x43,0xe5], // 3 Purple 1001 9
[0x00,0x69,0x40], // 4 Dark Green 0100 4
[0xb0,0xb0,0xb0], // 5 Gray 1 0101 5
[0x2f,0x95,0xe5], // 6 Medium Blue 1100 12
[0xbf,0xab,0xff], // 7 Light Blue 1101 13
[0x40,0x54,0x00], // 8 Brown 0010 2
[0xd0,0x6a,0x1a], // 9 Orange 0011 3
[0x40,0x40,0x40], // 10 Gray 2 1010 10
[0xff,0x96,0xbf], // 11 Pink 1011 11
[0x2f,0xbc,0x1a], // 12 Light Green 0110 6
[0xbf,0xd3,0x5a], // 13 Yellow 0111 7
[0x6f,0xe8,0xbf], // 14 Aqua 1110 14
[0xff,0xff,0xff] // 15 White 1111 15
/* Alternate from http://mrob.com/pub/xapple2/colors.html
[ 0, 0, 0], // 0 Black
[227, 30, 96], // 1 Red
[ 96, 78,189], // 2 Dark Blue
[255, 68,253], // 3 Purple
[ 0,163, 96], // 4 Dark Green
[156,156,156], // 5 Grey
[ 20,207,253], // 6 Med Blue
[208,195,255], // 7 Light Blue
[ 96,114, 3], // 8 Brown
[255,106, 60], // 9 Orange
[156,156,156], // 10 Grey
[255,160,208], // 11 Pink
[ 20,245, 60], // 12 Light Green
[208,221,141], // 13 Yellow
[114,255,208], // 14 Aqua
[255,255,255] // 15 White
*/
[0x00,0x00,0x00], // black
[0xdd,0x00,0x33], // 0x1 deep red
[0x00,0x00,0x99], // 0x2 dark blue
[0xdd,0x00,0xdd], // 0x3 purple
[0x00,0x77,0x00], // 0x4 dark green
[0x55,0x55,0x55], // 0x5 dark gray
[0x23,0x22,0xff], // 0x6 medium blue
[0x66,0xaa,0xff], // 0x7 light blue
[0x88,0x55,0x22], // 0x8 brown
[0xff,0x66,0x00], // 0x9 orange
[0xaa,0xaa,0xaa], // 0xa light gray
[0xff,0x99,0x88], // 0xb pink
[0x00,0xdd,0x00], // 0xc green
[0xff,0xff,0x00], // 0xd yellow
[0x00,0xff,0x99], // 0xe aquamarine
[0xff,0xff,0xff] // 0xf white
];
function _init() {

View File

@ -11,7 +11,7 @@
*/
/*jshint browser:true */
/*globals allocMemPages: false, charset: false, base64_encode: false, base64_decode: false */
/*globals allocMemPages: false, charset: false, base64_encode: false, base64_decode: false, enhanced: false */
/*exported LoresPage, HiresPage, VideoModes */
@ -34,6 +34,8 @@ var scanlines = false;
function LoresPage(page)
{
"use strict";
// $00-$3F inverse
// $40-$7F flashing
// $80-$FF normal
@ -49,22 +51,22 @@ function LoresPage(page)
var _green = [0x00,0xff,0x80];
var _colors = [
[0x00,0x00,0x00], // 0 Black 0000 0 0
[0x90,0x17,0x40], // 1 Red 0001 8 1
[0x3c,0x22,0xa5], // 2 Dark Blue 1000 1
[0xd0,0x43,0xe5], // 3 Purple 1001 9
[0x00,0x69,0x40], // 4 Dark Green 0100 4
[0xb0,0xb0,0xb0], // 5 Gray 1 0101 5
[0x2f,0x95,0xe5], // 6 Medium Blue 1100 12
[0xbf,0xab,0xff], // 7 Light Blue 1101 13
[0x40,0x54,0x00], // 8 Brown 0010 2
[0xd0,0x6a,0x1a], // 9 Orange 0011 3
[0x40,0x40,0x40], // 10 Gray 2 1010 10
[0xff,0x96,0xbf], // 11 Pink 1011 11
[0x2f,0xbc,0x1a], // 12 Light Green 0110 6
[0xb9,0xd0,0x60], // 13 Yellow 0111 7
[0x6f,0xe8,0xbf], // 14 Aqua 1110 14
[0xff,0xff,0xff] // 15 White 1111 15
[0x00,0x00,0x00], // black
[0xdd,0x00,0x33], // 0x1 deep red
[0x00,0x00,0x99], // 0x2 dark blue
[0xdd,0x00,0xdd], // 0x3 purple
[0x00,0x77,0x00], // 0x4 dark green
[0x55,0x55,0x55], // 0x5 dark gray
[0x23,0x22,0xff], // 0x6 medium blue
[0x66,0xaa,0xff], // 0x7 light blue
[0x88,0x55,0x22], // 0x8 brown
[0xff,0x66,0x00], // 0x9 orange
[0xaa,0xaa,0xaa], // 0xa light gray
[0xff,0x99,0x88], // 0xb pink
[0x00,0xdd,0x00], // 0xc green
[0xff,0xff,0x00], // 0xd yellow
[0x00,0xff,0x99], // 0xe aquamarine
[0xff,0xff,0xff] // 0xf white
];
function _init() {
@ -198,9 +200,11 @@ function LoresPage(page)
var flash = ((val & 0xc0) == 0x40) &&
_blink && !_80colMode && !altCharMode;
fore = flash ? _black : (_greenMode ? _green : _white);
back = flash ? _white : _black;
back = flash ? (_greenMode ? _green : _white) : _black;
if (!altCharMode && !_80colMode) {
if (!enhanced) {
val = (val >= 0x40 && val < 0x60) ? val - 0x40 : val;
} else if (!altCharMode) {
val = (val >= 0x40 && val < 0x80) ? val - 0x40 : val;
}
@ -237,7 +241,7 @@ function LoresPage(page)
fore = _green;
back = _black;
for (jdx = 0; jdx < 8; jdx++) {
b = (jdx < 4) ? (val & 0x0f) : (val >> 4);
b = (jdx < 8) ? (val & 0x0f) : (val >> 4);
b |= (b << 4);
if (bank & 0x1) {
b <<= 1;
@ -248,9 +252,12 @@ function LoresPage(page)
b <<= 1;
off += 4;
}
off += 546 * 4;
off += 553 * 4 + 560 * 4;
}
} else {
if (bank & 0x1) {
val = ((val & 0x77) << 1) | ((val & 0x88) >> 3);
}
for (jdx = 0; jdx < 8; jdx++) {
color = _colors[(jdx < 4) ?
(val & 0x0f) : (val >> 4)];
@ -258,7 +265,7 @@ function LoresPage(page)
_drawHalfPixel(data, off, color);
off += 4;
}
off += 553 * 4;
off += 553 * 4 + 560 * 4;
}
}
} else {
@ -355,6 +362,8 @@ function LoresPage(page)
function HiresPage(page)
{
"use strict";
var _page = page;
var r4 = [0, // Black
@ -378,22 +387,22 @@ function HiresPage(page)
15]; // White
var dcolors = [
[0x00,0x00,0x00], // 0 Black 0000 0 0
[0x90,0x17,0x40], // 1 Red 0001 8 1
[0x3c,0x22,0xa5], // 2 Dark Blue 1000 1
[0xd0,0x43,0xe5], // 3 Purple 1001 9
[0x00,0x69,0x40], // 4 Dark Green 0100 4
[0xb0,0xb0,0xb0], // 5 Gray 1 0101 5
[0x2f,0x95,0xe5], // 6 Medium Blue 1100 12
[0xbf,0xab,0xff], // 7 Light Blue 1101 13
[0x40,0x54,0x00], // 8 Brown 0010 2
[0xd0,0x6a,0x1a], // 9 Orange 0011 3
[0x40,0x40,0x40], // 10 Gray 2 1010 10
[0xff,0x96,0xbf], // 11 Pink 1011 11
[0x2f,0xbc,0x1a], // 12 Light Green 0110 6
[0xb9,0xd0,0x60], // 13 Yellow 0111 7
[0x6f,0xe8,0xbf], // 14 Aqua 1110 14
[0xff,0xff,0xff] // 15 White 1111 15
[0x00,0x00,0x00], // black
[0xdd,0x00,0x33], // 0x1 deep red
[0x00,0x00,0x99], // 0x2 dark blue
[0xdd,0x00,0xdd], // 0x3 purple
[0x00,0x77,0x00], // 0x4 dark green
[0x55,0x55,0x55], // 0x5 dark gray
[0x23,0x22,0xff], // 0x6 medium blue
[0x66,0xaa,0xff], // 0x7 light blue
[0x88,0x55,0x22], // 0x8 brown
[0xff,0x66,0x00], // 0x9 orange
[0xaa,0xaa,0xaa], // 0xa light gray
[0xff,0x99,0x88], // 0xb pink
[0x00,0xdd,0x00], // 0xc green
[0xff,0xff,0x00], // 0xd yellow
[0x00,0xff,0x99], // 0xe aquamarine
[0xff,0xff,0xff] // 0xf white
];
// hires colors

View File

@ -16,6 +16,8 @@
function CPU6502(options)
{
"use strict";
options = options || {};
var is65C02 = options['65C02'] ? true : false;
@ -96,6 +98,7 @@ function CPU6502(options)
var resetHandlers = [];
var inCallback = false;
var cycles = 0;
var sync = false;
var blankPage = {
read: function() { return 0; },
@ -400,7 +403,7 @@ function CPU6502(options)
function brk(readFn) {
readFn();
pushWord(pc);
pushByte(sr | flags.B);
php();
if (is65C02) {
setFlag(flags.D, false);
}
@ -689,7 +692,7 @@ function CPU6502(options)
/* Return from Subroutine */
function rti() {
sr = pullByte() & 0xef;
sr = pullByte() & ~flags.B;
pc = pullWord();
}
@ -1033,6 +1036,9 @@ function CPU6502(options)
if (is65C02) {
for (var key in cops) {
if (key in ops) {
debug('overriding opcode ' + toHex(key));
}
ops[key] = cops[key];
}
}
@ -1131,7 +1137,9 @@ function CPU6502(options)
return {
step: function cpu_step(cb) {
sync = true;
var op = opary[readBytePC()];
sync = false;
op[1](op[2]);
cycles += op[4];
@ -1147,7 +1155,9 @@ function CPU6502(options)
var op, idx;
for (idx = 0; idx < n; idx++) {
sync = true;
op = opary[readBytePC()];
sync = false;
op[1](op[2]);
cycles += op[4];
}
@ -1157,7 +1167,9 @@ function CPU6502(options)
var op, end = cycles + c;
while (cycles < end) {
sync = true;
op = opary[readBytePC()];
sync = false;
op[1](op[2]);
cycles += op[4];
}
@ -1171,7 +1183,9 @@ function CPU6502(options)
return;
while (cycles < end) {
sync = true;
op = opary[readBytePC()];
sync = false;
op[1](op[2]);
cycles += op[4];
@ -1185,7 +1199,6 @@ function CPU6502(options)
addPageHandler: function(pho) {
for (var idx = pho.start(); idx <= pho.end(); idx++) {
writePages[idx] = pho;
if (pho.read)
readPages[idx] = pho;
if (pho.write)
@ -1210,6 +1223,32 @@ function CPU6502(options)
}
},
/* IRQ - Interupt Request */
irq: function cpu_irq()
{
if (!(sr & flags.I)) {
pushWord(pc);
pushByte(sr & ~flags.B);
if (is65C02) {
setFlag(flags.D, false);
}
setFlag(flags.I, true);
pc = readWord(loc.BRK);
}
},
/* NMI Non-maskable Interrupt */
nmi: function cpu_nmi()
{
pushWord(pc);
pushByte(sr & ~flags.B);
if (is65C02) {
setFlag(flags.D, false);
}
setFlag(flags.I, true);
pc = readWord(loc.NMI);
},
setPC: function(_pc) {
pc = _pc;
},
@ -1291,6 +1330,10 @@ function CPU6502(options)
}
return results;
},
sync: function() {
return sync;
},
cycles: function() {
return cycles;
@ -1340,6 +1383,10 @@ function CPU6502(options)
(sr & flags.C ? "C" : "-");
},
read: function(page, off) {
return readPages[page].read(page, off, false);
},
write: function(page, off, val) {
writePages[page].write(page, off, val);
}

View File

@ -11,11 +11,13 @@
*/
/*jshint browser: true */
/*globals extend: false, base64_encode: false, base64_decode: false, each: false */
/*globals extend: false, bytify: false, base64_encode: false, base64_decode: false, each: false */
/*exported DiskII */
function DiskII(io, callbacks, slot)
{
"use strict";
slot = slot || 6;
var _drives = [
{ // Drive 1
@ -247,14 +249,6 @@ function DiskII(io, callbacks, slot)
pretty ? " " : null);
}
function _compactArray(ary) {
var result = ary;
if (window.Uint8Array) {
result = new Uint8Array(ary);
}
return result;
}
function _json_decode(drive, data) {
var _cur = _drives[drive - 1];
var tracks = [];
@ -267,7 +261,7 @@ function DiskII(io, callbacks, slot)
var d = base64_decode(json.data[t][_s]);
extend(track, _explodeSector(v, t, _DO[_s], d));
}
tracks[t] = _compactArray(track);
tracks[t] = bytify(track);
}
_cur.volume = v;
_cur.format = json.type;
@ -702,7 +696,7 @@ function DiskII(io, callbacks, slot)
}
}
}
tracks[t] = _compactArray(track);
tracks[t] = bytify(track);
}
cur.tracks = tracks;
_updateDirty(_drive, false);

View File

@ -1,5 +1,5 @@
/* -*- mode: JavaScript; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*global bytify:false */
/*exported Apple2ROM */
function Apple2ROM()
{
@ -1542,14 +1542,7 @@ function Apple2ROM()
0xf5,0x03,0xfb,0x03,0x62,0xfa,0x59,0xff
];
var mem = [];
for (var page = 0x00; page < 0x30; page++) {
mem[page] = [];
for (var off = 0; off < 256; off++) {
mem[page ][off] = rom[page * 256 + off];
}
}
rom = bytify(rom);
return {
start: function() {
@ -1559,7 +1552,7 @@ function Apple2ROM()
return 0xff;
},
read: function(page, off) {
return mem[page - 0xd0][off];
return rom[(page - 0xd0) << 8 | off];
},
write: function() {},

View File

@ -11,7 +11,7 @@
*/
/*jshint rhino:true, browser: true, devel: true */
/*exported allocMem, allocMemPages, debug, toHex, toBinary, extend, gup, hup, each */
/*exported allocMem, allocMemPages, bytify, debug, toHex, toBinary, extend, gup, hup, each */
if (!Date.now) {
Date.now = function now() {
@ -36,6 +36,14 @@ function allocMemPages(pages) {
return allocMem(pages * 0x100);
}
function bytify(ary) {
var result = ary;
if (window.Uint8Array) {
result = new Uint8Array(ary);
}
return result;
}
function extend(ary1, ary2) {
ary2.forEach(function(val) {
ary1.push(val);