ac6502 1.3.0 → 1.4.1

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.
Files changed (141) hide show
  1. package/README.md +139 -32
  2. package/dist/components/IO/ACIA.d.ts +76 -0
  3. package/dist/components/IO/ACIA.js +282 -0
  4. package/dist/components/IO/ACIA.js.map +1 -0
  5. package/dist/components/IO/Attachments/Attachment.d.ts +112 -0
  6. package/dist/components/IO/Attachments/Attachment.js +71 -0
  7. package/dist/components/IO/Attachments/Attachment.js.map +1 -0
  8. package/dist/components/IO/Attachments/JoystickAttachment.d.ts +53 -0
  9. package/dist/components/IO/Attachments/JoystickAttachment.js +90 -0
  10. package/dist/components/IO/Attachments/JoystickAttachment.js.map +1 -0
  11. package/dist/components/IO/Attachments/KeyboardEncoderAttachment.d.ts +63 -0
  12. package/dist/components/IO/Attachments/KeyboardEncoderAttachment.js +489 -0
  13. package/dist/components/IO/Attachments/KeyboardEncoderAttachment.js.map +1 -0
  14. package/dist/components/IO/Attachments/KeyboardMatrixAttachment.d.ts +44 -0
  15. package/dist/components/IO/Attachments/KeyboardMatrixAttachment.js +274 -0
  16. package/dist/components/IO/Attachments/KeyboardMatrixAttachment.js.map +1 -0
  17. package/dist/components/IO/Attachments/KeypadAttachment.d.ts +47 -0
  18. package/dist/components/IO/Attachments/KeypadAttachment.js +141 -0
  19. package/dist/components/IO/Attachments/KeypadAttachment.js.map +1 -0
  20. package/dist/components/IO/Attachments/LCDAttachment.d.ts +110 -0
  21. package/dist/components/IO/Attachments/LCDAttachment.js +716 -0
  22. package/dist/components/IO/Attachments/LCDAttachment.js.map +1 -0
  23. package/dist/components/IO/Attachments/SNESAttachment.d.ts +85 -0
  24. package/dist/components/IO/Attachments/SNESAttachment.js +184 -0
  25. package/dist/components/IO/Attachments/SNESAttachment.js.map +1 -0
  26. package/dist/components/IO/Empty.d.ts +9 -0
  27. package/dist/components/IO/Empty.js +5 -7
  28. package/dist/components/IO/Empty.js.map +1 -1
  29. package/dist/components/IO/GPIOCard.d.ts +5 -5
  30. package/dist/components/IO/GPIOCard.js.map +1 -1
  31. package/dist/components/IO/RAMBank.d.ts +37 -0
  32. package/dist/components/IO/RAMBank.js +63 -0
  33. package/dist/components/IO/RAMBank.js.map +1 -0
  34. package/dist/components/IO/RTC.d.ts +107 -0
  35. package/dist/components/IO/RTC.js +483 -0
  36. package/dist/components/IO/RTC.js.map +1 -0
  37. package/dist/components/IO/Sound.d.ts +120 -0
  38. package/dist/components/IO/Sound.js +622 -0
  39. package/dist/components/IO/Sound.js.map +1 -0
  40. package/dist/components/IO/Storage.d.ts +74 -0
  41. package/dist/components/IO/Storage.js +409 -0
  42. package/dist/components/IO/Storage.js.map +1 -0
  43. package/dist/components/IO/Terminal.d.ts +19 -0
  44. package/dist/components/IO/Terminal.js +33 -0
  45. package/dist/components/IO/Terminal.js.map +1 -0
  46. package/dist/components/IO/VIA.d.ts +105 -0
  47. package/dist/components/IO/VIA.js +597 -0
  48. package/dist/components/IO/VIA.js.map +1 -0
  49. package/dist/components/IO/Video.d.ts +141 -0
  50. package/dist/components/IO/Video.js +630 -0
  51. package/dist/components/IO/Video.js.map +1 -0
  52. package/dist/components/Machine.d.ts +20 -24
  53. package/dist/components/Machine.js +249 -166
  54. package/dist/components/Machine.js.map +1 -1
  55. package/dist/index.js +28 -14
  56. package/dist/index.js.map +1 -1
  57. package/dist/lib.d.ts +16 -16
  58. package/dist/lib.js +32 -32
  59. package/dist/lib.js.map +1 -1
  60. package/dist/tests/IO/ACIA.test.d.ts +1 -0
  61. package/dist/tests/IO/ACIA.test.js +423 -0
  62. package/dist/tests/IO/ACIA.test.js.map +1 -0
  63. package/dist/tests/IO/Attachments/Attachment.test.d.ts +1 -0
  64. package/dist/tests/IO/Attachments/Attachment.test.js +339 -0
  65. package/dist/tests/IO/Attachments/Attachment.test.js.map +1 -0
  66. package/dist/tests/IO/Attachments/JoystickAttachment.test.d.ts +1 -0
  67. package/dist/tests/IO/Attachments/JoystickAttachment.test.js +126 -0
  68. package/dist/tests/IO/Attachments/JoystickAttachment.test.js.map +1 -0
  69. package/dist/tests/IO/Attachments/KeyboardEncoderAttachment.test.d.ts +1 -0
  70. package/dist/tests/IO/Attachments/KeyboardEncoderAttachment.test.js +779 -0
  71. package/dist/tests/IO/Attachments/KeyboardEncoderAttachment.test.js.map +1 -0
  72. package/dist/tests/IO/Attachments/KeyboardMatrixAttachment.test.d.ts +1 -0
  73. package/dist/tests/IO/Attachments/KeyboardMatrixAttachment.test.js +355 -0
  74. package/dist/tests/IO/Attachments/KeyboardMatrixAttachment.test.js.map +1 -0
  75. package/dist/tests/IO/Attachments/KeypadAttachment.test.d.ts +1 -0
  76. package/dist/tests/IO/Attachments/KeypadAttachment.test.js +323 -0
  77. package/dist/tests/IO/Attachments/KeypadAttachment.test.js.map +1 -0
  78. package/dist/tests/IO/Attachments/LCDAttachment.test.d.ts +1 -0
  79. package/dist/tests/IO/Attachments/LCDAttachment.test.js +627 -0
  80. package/dist/tests/IO/Attachments/LCDAttachment.test.js.map +1 -0
  81. package/dist/tests/IO/Attachments/SNESAttachment.test.d.ts +1 -0
  82. package/dist/tests/IO/Attachments/SNESAttachment.test.js +331 -0
  83. package/dist/tests/IO/Attachments/SNESAttachment.test.js.map +1 -0
  84. package/dist/tests/IO/Empty.test.d.ts +1 -0
  85. package/dist/tests/IO/Empty.test.js +121 -0
  86. package/dist/tests/IO/Empty.test.js.map +1 -0
  87. package/dist/tests/IO/GPIOCard.test.js.map +1 -1
  88. package/dist/tests/IO/RAMBank.test.d.ts +1 -0
  89. package/dist/tests/IO/RAMBank.test.js +229 -0
  90. package/dist/tests/IO/RAMBank.test.js.map +1 -0
  91. package/dist/tests/IO/RTC.test.d.ts +1 -0
  92. package/dist/tests/IO/RTC.test.js +177 -0
  93. package/dist/tests/IO/RTC.test.js.map +1 -0
  94. package/dist/tests/IO/Sound.test.d.ts +1 -0
  95. package/dist/tests/IO/Sound.test.js +528 -0
  96. package/dist/tests/IO/Sound.test.js.map +1 -0
  97. package/dist/tests/IO/Storage.test.d.ts +1 -0
  98. package/dist/tests/IO/Storage.test.js +656 -0
  99. package/dist/tests/IO/Storage.test.js.map +1 -0
  100. package/dist/tests/IO/VIA.test.d.ts +1 -0
  101. package/dist/tests/IO/VIA.test.js +503 -0
  102. package/dist/tests/IO/VIA.test.js.map +1 -0
  103. package/dist/tests/IO/Video.test.d.ts +1 -0
  104. package/dist/tests/IO/Video.test.js +549 -0
  105. package/dist/tests/IO/Video.test.js.map +1 -0
  106. package/dist/tests/Machine.test.js +27 -42
  107. package/dist/tests/Machine.test.js.map +1 -1
  108. package/package.json +1 -1
  109. package/src/components/IO/{SerialCard.ts → ACIA.ts} +2 -2
  110. package/src/components/IO/{GPIOAttachments/GPIOAttachment.ts → Attachments/Attachment.ts} +2 -2
  111. package/src/components/IO/{GPIOAttachments/GPIOJoystickAttachment.ts → Attachments/JoystickAttachment.ts} +3 -3
  112. package/src/components/IO/{GPIOAttachments/GPIOKeyboardEncoderAttachment.ts → Attachments/KeyboardEncoderAttachment.ts} +3 -3
  113. package/src/components/IO/{GPIOAttachments/GPIOKeyboardMatrixAttachment.ts → Attachments/KeyboardMatrixAttachment.ts} +5 -5
  114. package/src/components/IO/{GPIOAttachments/GPIOKeypadAttachment.ts → Attachments/KeypadAttachment.ts} +3 -3
  115. package/src/components/IO/{GPIOAttachments/GPIOLCDAttachment.ts → Attachments/LCDAttachment.ts} +7 -7
  116. package/src/components/IO/{EmptyCard.ts → Empty.ts} +1 -1
  117. package/src/components/IO/{RAMCard.ts → RAMBank.ts} +8 -8
  118. package/src/components/IO/{RTCCard.ts → RTC.ts} +1 -1
  119. package/src/components/IO/{SoundCard.ts → Sound.ts} +2 -2
  120. package/src/components/IO/{StorageCard.ts → Storage.ts} +70 -73
  121. package/src/components/IO/{DevOutputBoard.ts → Terminal.ts} +2 -2
  122. package/src/components/IO/{GPIOCard.ts → VIA.ts} +64 -64
  123. package/src/components/IO/{VideoCard.ts → Video.ts} +1 -1
  124. package/src/components/Machine.ts +276 -176
  125. package/src/index.ts +34 -21
  126. package/src/lib.ts +16 -16
  127. package/src/tests/IO/{SerialCard.test.ts → ACIA.test.ts} +5 -5
  128. package/src/tests/IO/{GPIOAttachments/GPIOAttachment.test.ts → Attachments/Attachment.test.ts} +12 -12
  129. package/src/tests/IO/{GPIOAttachments/GPIOJoystickAttachment.test.ts → Attachments/JoystickAttachment.test.ts} +23 -23
  130. package/src/tests/IO/{GPIOAttachments/GPIOKeyboardEncoderAttachment.test.ts → Attachments/KeyboardEncoderAttachment.test.ts} +4 -4
  131. package/src/tests/IO/{GPIOAttachments/GPIOKeyboardMatrixAttachment.test.ts → Attachments/KeyboardMatrixAttachment.test.ts} +5 -5
  132. package/src/tests/IO/{GPIOAttachments/GPIOKeypadAttachment.test.ts → Attachments/KeypadAttachment.test.ts} +38 -38
  133. package/src/tests/IO/{GPIOAttachments/GPIOLCDAttachment.test.ts → Attachments/LCDAttachment.test.ts} +12 -12
  134. package/src/tests/IO/Empty.test.ts +143 -0
  135. package/src/tests/IO/{RAMCard.test.ts → RAMBank.test.ts} +33 -33
  136. package/src/tests/IO/{RTCCard.test.ts → RTC.test.ts} +6 -6
  137. package/src/tests/IO/{SoundCard.test.ts → Sound.test.ts} +6 -6
  138. package/src/tests/IO/{StorageCard.test.ts → Storage.test.ts} +34 -25
  139. package/src/tests/IO/{GPIOCard.test.ts → VIA.test.ts} +7 -7
  140. package/src/tests/IO/{VideoCard.test.ts → Video.test.ts} +13 -13
  141. package/src/tests/Machine.test.ts +31 -38
@@ -0,0 +1,141 @@
1
+ import { IO } from '../IO';
2
+ /**
3
+ * TMS9918 Video Display Processor Emulation
4
+ *
5
+ * Port mapping (address bit 0):
6
+ * Even address (bit 0 = 0): VRAM data read/write
7
+ * Odd address (bit 0 = 1): Register/address write / status read
8
+ *
9
+ * Display modes:
10
+ * Graphics I - 32x24 tiles, 8x8 patterns, 1-of-8 color groups
11
+ * Graphics II - 32x24 tiles, 8x8 patterns, per-row color
12
+ * Text - 40x24 tiles, 6x8 patterns, no sprites
13
+ * Multicolor - 32x24 blocks, 4x4 colored cells
14
+ *
15
+ * Output: 256x192 active area centered in a 320x240 RGBA buffer
16
+ *
17
+ * Reference: vrEmuTms9918 by Troy Schrapel
18
+ * https://github.com/visrealm/vrEmuTms9918
19
+ */
20
+ export declare enum TmsMode {
21
+ GRAPHICS_I = 0,
22
+ GRAPHICS_II = 1,
23
+ TEXT = 2,
24
+ MULTICOLOR = 3
25
+ }
26
+ export declare enum TmsColor {
27
+ TRANSPARENT = 0,
28
+ BLACK = 1,
29
+ MED_GREEN = 2,
30
+ LT_GREEN = 3,
31
+ DK_BLUE = 4,
32
+ LT_BLUE = 5,
33
+ DK_RED = 6,
34
+ CYAN = 7,
35
+ MED_RED = 8,
36
+ LT_RED = 9,
37
+ DK_YELLOW = 10,
38
+ LT_YELLOW = 11,
39
+ DK_GREEN = 12,
40
+ MAGENTA = 13,
41
+ GREY = 14,
42
+ WHITE = 15
43
+ }
44
+ export declare class Video implements IO {
45
+ raiseIRQ: () => void;
46
+ raiseNMI: () => void;
47
+ /** Eight write-only registers */
48
+ private registers;
49
+ /** Status register (read-only from CPU side) */
50
+ private status;
51
+ /** Current VRAM address for CPU access (auto-increments) */
52
+ private currentAddress;
53
+ /** Address / register write stage (0 or 1) */
54
+ private regWriteStage;
55
+ /** Holds first stage byte written to the control port */
56
+ private regWriteStage0Value;
57
+ /** Read-ahead buffer for VRAM reads */
58
+ private readAheadBuffer;
59
+ /** Current display mode (derived from registers) */
60
+ private mode;
61
+ /** 16 KB Video RAM */
62
+ private vram;
63
+ /** Per-pixel sprite collision mask for the current scanline */
64
+ private rowSpriteBits;
65
+ /** Temporary scanline pixel buffer (color palette indices) */
66
+ private scanlinePixels;
67
+ /** 320 × 240 RGBA output buffer for SDL rendering (front buffer – always a complete frame) */
68
+ buffer: Buffer;
69
+ /** Back buffer where scanlines are rendered progressively */
70
+ private backBuffer;
71
+ /** True when a complete frame has been copied to the front buffer */
72
+ frameReady: boolean;
73
+ /** Cycle accumulator for scanline timing */
74
+ private cycleAccumulator;
75
+ /** Current scanline being processed (0 – 261) */
76
+ private currentScanline;
77
+ read(address: number): number;
78
+ write(address: number, data: number): void;
79
+ tick(frequency: number): void;
80
+ reset(_coldStart: boolean): void;
81
+ /**
82
+ * Write to the control (address / register) port.
83
+ * Two-stage write:
84
+ * Stage 0 – latches the low byte (address LSB or register value)
85
+ * Stage 1 – interprets the high byte:
86
+ * bit 7 set → register write (bits 0-2 = register index)
87
+ * bit 7 clear → address set (bit 6: 0 = read, 1 = write)
88
+ */
89
+ private writeAddr;
90
+ /** Write data to VRAM at the current address (auto-increments) */
91
+ private writeData;
92
+ /**
93
+ * Read the status register.
94
+ * Clears the status flags and resets the write stage.
95
+ */
96
+ private readStatus;
97
+ /** Read data from VRAM via the read-ahead buffer (auto-increments) */
98
+ private readData;
99
+ private updateMode;
100
+ private nameTableAddr;
101
+ private colorTableAddr;
102
+ private patternTableAddr;
103
+ private spriteAttrTableAddr;
104
+ private spritePatternTableAddr;
105
+ /** Backdrop / border color (low nibble of register 7) */
106
+ private mainBgColor;
107
+ /** Text-mode foreground (high nibble of register 7, transparent → backdrop) */
108
+ private mainFgColor;
109
+ /** Foreground from a color byte (high nibble, transparent → backdrop) */
110
+ private fgColor;
111
+ /** Background from a color byte (low nibble, transparent → backdrop) */
112
+ private bgColor;
113
+ private spriteSize;
114
+ private spriteMag;
115
+ private displayEnabled;
116
+ private processScanline;
117
+ private renderScanline;
118
+ private graphicsIScanLine;
119
+ private graphicsIIScanLine;
120
+ private textScanLine;
121
+ private multicolorScanLine;
122
+ private outputSprites;
123
+ /** Fill entire back buffer with the current backdrop color */
124
+ private fillBackground;
125
+ /** Write a rendered scanline into the back buffer at the correct position */
126
+ private writeScanlineToBuffer;
127
+ /** Read a VDP register value */
128
+ getRegister(reg: number): number;
129
+ /** Write a VDP register value directly (bypasses control-port staging) */
130
+ setRegister(reg: number, value: number): void;
131
+ /** Read a VRAM byte directly (does not affect read-ahead buffer) */
132
+ getVramByte(addr: number): number;
133
+ /** Write a VRAM byte directly (does not affect address pointer) */
134
+ setVramByte(addr: number, value: number): void;
135
+ /** Peek at the status register without clearing it */
136
+ getStatus(): number;
137
+ /** Get the current display mode */
138
+ getMode(): TmsMode;
139
+ /** Get the display-enabled state */
140
+ isDisplayEnabled(): boolean;
141
+ }