-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdisktoo.js
87 lines (77 loc) · 2.92 KB
/
disktoo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* AppleToo Disk object for Dos 3.3 disk consisting of:
* 35 tracks per side
* 16 sectors per track
* 256 bytes per sector
*
* 4 phase stepper motor, 0-3
* 0xc080 sm phase 0 off
* 0xc081 sm phase 0 on
* 0xc082 sm phase 1 off
* 0xc083 sm phase 1 on
* 0xc084 sm phase 2 off
* 0xc085 sm phase 2 off
* 0xc086 sm phase 3 off
* 0xc087 sm phase 3 on
* 0xc088 turn motor off
* 0xc089 turn motor on
* 0xc08a engage drive 1
* 0xc08b engage drive 2
* 0xc08c strobe data latch for i/o
* 0xc08d load data latch
* 0xc08e prepare latch for input
* 0xc08f prepare latch for output
*
* 0xc08e with 0xc08c Read
* 0xc08e with 0xc08d Sense Write Protect
* 0xc08f with 0xc08c Write
* 0xc08f with 0xc08d Load Write Latch
*/
var DiskToo = function(appleToo, numDrives) {
this.appleToo = appleToo;
this.drives = [];
this.currentDrive = 0;
this.latch = 0;
for (var i = 0; i < numDrives.length; i++) {
this.drives.push({phase: 0});
}
};
DiskToo.prototype.readDisk = function(diskData) {
var buffer = [];
diskData = diskData.replace(/\s+/g,"");
for (var i=0; i < diskData.length; i += 2) {
buffer[i] = parseInt(diskData.substr(i, 2), 16);
}
};
var Disk = function() {
this.track = 0;
this.sector = 0;
};
function encode44(byte) {
var evenByte = (byte | 0xAA),
oddByte = (byte >> 1 | 0xAA);
return [oddByte, evenByte];
}
function decode44(byteArray) {
var evenByte = byteArray[1],
oddByte = byteArray[0],
byte = (evenByte & ((oddByte << 1) | 0x01));
return byte;
}
var conversionTable63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