ac6502 1.13.0 → 1.15.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 +8 -1
- package/dist/components/IO/RTC.d.ts +8 -0
- package/dist/components/IO/RTC.js +28 -0
- package/dist/components/IO/RTC.js.map +1 -1
- package/dist/components/IO/Storage.d.ts +7 -5
- package/dist/components/IO/Storage.js +47 -38
- package/dist/components/IO/Storage.js.map +1 -1
- package/dist/index.js +29 -3
- package/dist/index.js.map +1 -1
- package/dist/tests/IO/RTC.test.js +58 -0
- package/dist/tests/IO/RTC.test.js.map +1 -1
- package/dist/tests/IO/Storage.test.js +8 -8
- package/dist/tests/IO/Storage.test.js.map +1 -1
- package/package.json +1 -1
- package/src/components/IO/RTC.ts +30 -0
- package/src/components/IO/Storage.ts +51 -37
- package/src/index.ts +39 -4
- package/src/tests/IO/RTC.test.ts +77 -0
- package/src/tests/IO/Storage.test.ts +8 -8
package/src/tests/IO/RTC.test.ts
CHANGED
|
@@ -202,4 +202,81 @@ describe('RTC', () => {
|
|
|
202
202
|
expect(rtc.read(0x0f) & 0x02).toBe(0)
|
|
203
203
|
})
|
|
204
204
|
})
|
|
205
|
+
|
|
206
|
+
describe('NVRAM Persistence', () => {
|
|
207
|
+
it('should export NVRAM data via getNVRAM', () => {
|
|
208
|
+
rtc.write(0x10, 0x00)
|
|
209
|
+
rtc.write(0x0f, 0x20) // Enable auto-increment
|
|
210
|
+
for (let i = 0; i < 256; i++) {
|
|
211
|
+
rtc.write(0x13, i & 0xFF)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const data = rtc.getNVRAM()
|
|
215
|
+
expect(data).toBeInstanceOf(Uint8Array)
|
|
216
|
+
expect(data.length).toBe(256)
|
|
217
|
+
for (let i = 0; i < 256; i++) {
|
|
218
|
+
expect(data[i]).toBe(i & 0xFF)
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('should restore NVRAM data via loadNVRAM', () => {
|
|
223
|
+
const nvram = new Uint8Array(256)
|
|
224
|
+
for (let i = 0; i < 256; i++) {
|
|
225
|
+
nvram[i] = (255 - i) & 0xFF
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
rtc.loadNVRAM(nvram)
|
|
229
|
+
|
|
230
|
+
rtc.write(0x10, 0x00)
|
|
231
|
+
rtc.write(0x0f, 0x20) // Enable auto-increment
|
|
232
|
+
for (let i = 0; i < 256; i++) {
|
|
233
|
+
expect(rtc.read(0x13)).toBe((255 - i) & 0xFF)
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
it('should return a copy from getNVRAM, not a reference', () => {
|
|
238
|
+
rtc.write(0x10, 0x00)
|
|
239
|
+
rtc.write(0x13, 0xAB)
|
|
240
|
+
|
|
241
|
+
const data = rtc.getNVRAM()
|
|
242
|
+
data[0] = 0x00 // Mutate the copy
|
|
243
|
+
|
|
244
|
+
rtc.write(0x10, 0x00)
|
|
245
|
+
expect(rtc.read(0x13)).toBe(0xAB) // Original unchanged
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
it('should reject NVRAM data of wrong size', () => {
|
|
249
|
+
const warnSpy = jest.spyOn(console, 'warn').mockImplementation()
|
|
250
|
+
|
|
251
|
+
rtc.write(0x10, 0x00)
|
|
252
|
+
rtc.write(0x13, 0x42)
|
|
253
|
+
|
|
254
|
+
rtc.loadNVRAM(new Uint8Array(128))
|
|
255
|
+
|
|
256
|
+
rtc.write(0x10, 0x00)
|
|
257
|
+
expect(rtc.read(0x13)).toBe(0x42) // Unchanged
|
|
258
|
+
|
|
259
|
+
warnSpy.mockRestore()
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
it('should ignore null input to loadNVRAM', () => {
|
|
263
|
+
rtc.write(0x10, 0x05)
|
|
264
|
+
rtc.write(0x13, 0x99)
|
|
265
|
+
|
|
266
|
+
rtc.loadNVRAM(null)
|
|
267
|
+
|
|
268
|
+
rtc.write(0x10, 0x05)
|
|
269
|
+
expect(rtc.read(0x13)).toBe(0x99)
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('should preserve NVRAM across warm reset', () => {
|
|
273
|
+
rtc.write(0x10, 0x00)
|
|
274
|
+
rtc.write(0x13, 0xDE)
|
|
275
|
+
|
|
276
|
+
rtc.reset(false)
|
|
277
|
+
|
|
278
|
+
rtc.write(0x10, 0x00)
|
|
279
|
+
expect(rtc.read(0x13)).toBe(0xDE)
|
|
280
|
+
})
|
|
281
|
+
})
|
|
205
282
|
})
|
|
@@ -586,9 +586,9 @@ describe('Storage (Compact Flash in IDE Mode)', () => {
|
|
|
586
586
|
// Verify file exists
|
|
587
587
|
expect(existsSync(testFile)).toBe(true)
|
|
588
588
|
|
|
589
|
-
// Verify file size is
|
|
589
|
+
// Verify file size is 32MB
|
|
590
590
|
const fileData = await readFile(testFile)
|
|
591
|
-
expect(fileData.length).toBe(
|
|
591
|
+
expect(fileData.length).toBe(32 * 1024 * 1024)
|
|
592
592
|
})
|
|
593
593
|
|
|
594
594
|
it('should save complete storage contents', async () => {
|
|
@@ -624,7 +624,7 @@ describe('Storage (Compact Flash in IDE Mode)', () => {
|
|
|
624
624
|
describe('loadFromFile', () => {
|
|
625
625
|
it('should load storage data from an existing file', async () => {
|
|
626
626
|
// Create a test file with known data
|
|
627
|
-
const testData = Buffer.alloc(
|
|
627
|
+
const testData = Buffer.alloc(32 * 1024 * 1024, 0x00)
|
|
628
628
|
|
|
629
629
|
// Fill first sector with pattern
|
|
630
630
|
for (let i = 0; i < 512; i++) {
|
|
@@ -661,10 +661,10 @@ describe('Storage (Compact Flash in IDE Mode)', () => {
|
|
|
661
661
|
}
|
|
662
662
|
})
|
|
663
663
|
|
|
664
|
-
it('should reject file with
|
|
665
|
-
// Create a file that's
|
|
666
|
-
const
|
|
667
|
-
await writeFile(invalidSizeFile,
|
|
664
|
+
it('should reject file with non-sector-aligned size', async () => {
|
|
665
|
+
// Create a file that's not a multiple of 512 bytes
|
|
666
|
+
const badData = Buffer.alloc(1023, 0xFF)
|
|
667
|
+
await writeFile(invalidSizeFile, badData)
|
|
668
668
|
|
|
669
669
|
const fileData = await readFile(invalidSizeFile)
|
|
670
670
|
storageCard.loadData(new Uint8Array(fileData))
|
|
@@ -680,7 +680,7 @@ describe('Storage (Compact Flash in IDE Mode)', () => {
|
|
|
680
680
|
})
|
|
681
681
|
|
|
682
682
|
it('should load multiple sectors correctly', async () => {
|
|
683
|
-
const testData = Buffer.alloc(
|
|
683
|
+
const testData = Buffer.alloc(32 * 1024 * 1024, 0x00)
|
|
684
684
|
|
|
685
685
|
// Fill sectors with different patterns
|
|
686
686
|
for (let sector = 0; sector < 10; sector++) {
|