@moonbase-machines/c64 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/moonbase-c64.js +4 -4
- package/dist/moonbase-c64.js.map +4 -4
- package/index.js +1 -0
- package/package.json +3 -3
- package/picture.js +33 -0
- package/test/disks.test.js +23 -0
package/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export * as machine from './machine.js';
|
|
|
19
19
|
export * as numbers from './numbers.js';
|
|
20
20
|
export * as paint from './paint.js';
|
|
21
21
|
export * as petscii from './petscii.js';
|
|
22
|
+
export * as picture from './picture.js';
|
|
22
23
|
export * as printer from './printer.js';
|
|
23
24
|
export * as rom from './rom.js';
|
|
24
25
|
export * as saves from './saves.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbase-machines/c64",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A Commodore 64 as far as the games use it: the VIC-II, the SID, a 1541, a printer, and Moonbase's own KERNAL and BASIC in place of Commodore's ROMs.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"./*": "./*"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@moonbase-machines/mos6502": "0.
|
|
14
|
-
"@moonbase-machines/charset": "0.
|
|
13
|
+
"@moonbase-machines/mos6502": "0.6.0",
|
|
14
|
+
"@moonbase-machines/charset": "0.6.0"
|
|
15
15
|
}
|
|
16
16
|
}
|
package/picture.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// A picture of what the VIC-II shows, for a tool: a 64's memory and the chips' registers painted as the VIC-II
|
|
2
|
+
// paints them (paint.js, vic.js), a part of the screen cropped and its colours the 64's own (PALETTE), as rows of
|
|
3
|
+
// [r, g, b] (for @moonbase-machines/files/png.js: png, sheet). The screen's dots: a hi-res dot one pixel, a
|
|
4
|
+
// multicolour dot two wide, as the VIC-II makes them; `scale` repeats each pixel across and down.
|
|
5
|
+
//
|
|
6
|
+
// rows({ mem, chip, chargen, crop: [x, y, width, height], scale })
|
|
7
|
+
// mem the 64K the VIC-II reads (in the bank CIA 2's port gives, chip[0xd00])
|
|
8
|
+
// chip the I/O page from $D000, 4K: the VIC-II's registers at 0 to $3F, colour memory at $800, CIA 2's
|
|
9
|
+
// port A at $D00 (registers.chip() makes one from names)
|
|
10
|
+
// chargen the character ROM, where text in the ROM's own characters is shown; none, zeros
|
|
11
|
+
// crop a part of the 320 by 200 screen, from its top left; the whole of it unless given
|
|
12
|
+
// chip({ registers, color, bank }) an I/O page: registers as { 0x11: 0x1b, ... }, colour memory's bytes from
|
|
13
|
+
// $D800, and the VIC-II's bank ($0000, $4000, $8000 or $C000)
|
|
14
|
+
import { paint } from './paint.js';
|
|
15
|
+
import { PALETTE, LEFT, TOP, WIDTH } from './vic.js';
|
|
16
|
+
|
|
17
|
+
export function chip({ registers = {}, color = [], bank = 0 } = {}) {
|
|
18
|
+
const page = new Uint8Array(0x1000);
|
|
19
|
+
for (const [r, v] of Object.entries(registers)) page[+r] = v;
|
|
20
|
+
page.set(color.slice(0, 0x400), 0x800);
|
|
21
|
+
page[0xd00] = 3 - (bank >> 14); // (CIA 2's port A, its two low bits the bank turned over)
|
|
22
|
+
return page;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function rows({ mem, chip: io, chargen, crop = [0, 0, 320, 200], scale = 1 }) {
|
|
26
|
+
const frame = paint(mem, io, chargen), [cx, cy, w, h] = crop, out = [];
|
|
27
|
+
for (let y = 0; y < h; y++) {
|
|
28
|
+
const row = [];
|
|
29
|
+
for (let x = 0; x < w; x++) { const c = PALETTE[frame[(TOP + cy + y) * WIDTH + LEFT + cx + x]]; for (let s = 0; s < scale; s++) row.push(c); }
|
|
30
|
+
for (let s = 0; s < scale; s++) out.push(row);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
package/test/disks.test.js
CHANGED
|
@@ -33,3 +33,26 @@ test('a BASIC program listed as LIST prints it, in either character set', () =>
|
|
|
33
33
|
assert.equal(listing(Uint8Array.from(bytes)), '10 PRINT"{CLR}HELLO"\n20 GOTO 10\n');
|
|
34
34
|
assert.equal(listing(Uint8Array.from(bytes), { lower: true }), '10 print"{CLR}hello"\n20 goto 10\n');
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
test('what the VIC-II shows as a picture: multicolour and hi-res text, a hi-res bitmap, a sprite', async () => {
|
|
38
|
+
const { rows, chip } = await import('@moonbase-machines/c64/picture.js');
|
|
39
|
+
const { PALETTE } = await import('@moonbase-machines/c64/vic.js');
|
|
40
|
+
const colours = row => row.map(c => PALETTE.findIndex(p => p.join() === c.join()));
|
|
41
|
+
// text: characters at $3000, the screen at $0400 ($D018 $1C); cell 0 multicolour (colour 8 + 5), its top row the
|
|
42
|
+
// pairs 00 01 10 11; cell 1 hi-res in white, its top row one dot at the left
|
|
43
|
+
let mem = new Uint8Array(0x10000);
|
|
44
|
+
mem[0x400] = 0; mem[0x401] = 1; mem[0x3000] = 0b00011011; mem[0x3008] = 0x80;
|
|
45
|
+
let io = chip({ registers: { 0x11: 0x1b, 0x16: 0xd8, 0x18: 0x1c, 0x21: 0, 0x22: 2, 0x23: 7 }, color: [8 | 5, 1] });
|
|
46
|
+
assert.deepEqual(colours(rows({ mem, chip: io, crop: [0, 0, 10, 1] })[0]), [0, 0, 2, 2, 7, 7, 5, 5, 1, 0]);
|
|
47
|
+
// a hi-res bitmap at $2000 ($D018 $18, $D011 $3B): its first byte one dot, the screen's byte $16 (white on blue)
|
|
48
|
+
mem = new Uint8Array(0x10000); mem[0x2000] = 0x80; mem[0x400] = 0x16;
|
|
49
|
+
io = chip({ registers: { 0x11: 0x3b, 0x16: 0xc8, 0x18: 0x18 } });
|
|
50
|
+
assert.deepEqual(colours(rows({ mem, chip: io, crop: [0, 0, 3, 1] })[0]), [1, 6, 6]);
|
|
51
|
+
// sprite 0 at the screen's top left (24, 50), its data at $2000 (pointer $80 at $07F8), its first dot in red
|
|
52
|
+
mem = new Uint8Array(0x10000); mem[0x7f8] = 0x80; mem[0x2000] = 0x80;
|
|
53
|
+
io = chip({ registers: { 0x11: 0x1b, 0x16: 0xc8, 0x18: 0x14, 0x15: 1, 0x00: 24, 0x01: 50, 0x27: 2, 0x21: 0 } });
|
|
54
|
+
assert.deepEqual(colours(rows({ mem, chip: io, crop: [0, 0, 2, 1] })[0]), [2, 0]);
|
|
55
|
+
// twice the size: each pixel twice across and twice down
|
|
56
|
+
const big = rows({ mem, chip: io, crop: [0, 0, 1, 1], scale: 2 });
|
|
57
|
+
assert.equal(big.length, 2); assert.equal(big[0].length, 2);
|
|
58
|
+
});
|