-
Notifications
You must be signed in to change notification settings - Fork 0
/
emptyx16.txt
4375 lines (3455 loc) · 167 KB
/
emptyx16.txt
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Emptyx16 - X16 Hardware Specs
=============================
Commander X16 hardware specifications
X16 Hardware Specifications
--> X16 Overview
--> X16 I/O Map
--> X16 Memory
--> X16 Versatile Embedded Retro Adapter (VERA)
--> X16 Peripherals
--> X16 I2C Bus
--> X16 Timings
--> X16 Pinouts
--> X16 Hardware History
--> VIA Versatile Interface Adapter
--> YM2151 FM Operator Type-M (OPM)
--> CPU 65C02 Microprocessor
About
--> About/Credits
X16 Overview
============
CPU
CPU WDC 65C02 8-bit CPU, 8.0MHz
Internal Memory
System ROM 512 KiB
Fixed RAM 39.75 KiB
Banked RAM 512 KiB (Installable up to 2 MiB)
VERA RAM 128 KiB
Audio FIFO 4 KiB
RTC NVRAM 64 bytes
Video
Display 640x480 pixels with 4096 colors
BG layers 2 background layers
BG types Tile/map-based or bitmap-based
BG colors 256 colors, or 2/4/16 colors/16 palettes
Spr colors 256 colors, or 16 colors/16 palettes
Spr size 16 types (in range of 8x8 up to 64x64)
Sprs/Screen max. 128 sprites of any size (up to 64x64 each)
Sprs/Line max. 80 sprites of 8x8 size (under best circumstances)
Sound
VERA PSG 16 channels, pulse/saw/triangle/noise
VERA PCM 1 channel, 8/16-bit mono/stereo PCM
YM2151 8 channels, phase-modulated sine
Interface Ports
PS/2 port Separate connector for Keyboard and Mouse
Joypad 2x SNES controller ports
Serial Commodore serial bus
Memory card SPI mode MMC interface
X16 I/O Map
===========
First some bytes
0000h - Current RAM Bank (R/W)
0001h - Current ROM Bank (R/W)
0002h..9EFFh - Fixed RAM
VIA Versatile Interface Adapter (R/W)
9F00h - PRB - Port B Input/Output
9F01h - PRA - Port A Input/Output
9F02h - DDRB - Port B Data Direction
9F03h - DDRA - Port A Data Direction
9F04h - T1L - T1 Counter (low 8 bits)
9F05h - T1H - T1 Counter (high 8 bits)
9F06h - T1LL - T1 Latch (low 8 bits)
9F07h - T1LH - T1 Latch (high 8 bits)
9F08h - T2L - T2 Counter (low 8 bits)
9F09h - T2H - T2 Counter (high 8 bits)
9F0Ah - SR - Shift Register
9F0Bh - ACR - Auxiliary Control Register
9F0Ch - PCR - Peripheral Control Register
9F0Dh - IFR - Interrupt Flags Register
9F0Eh - IER - Interrupt Enable Register
9F0Fh - PRA2 - Port A Input/Output Without Handshaking
VERA Versatile Embedded Retro Adapter (R/W)
Note: The rightmost column shows the initial value on Reset
9F20h - ADDR_L - VRAM Address (lower 8 bits) 00h
9F21h - ADDR_M - VRAM Address (middle 8 bits) 00h
9F22h - ADDR_H - VRAM Address (upper 1 bit) / Increment Mode 00h
9F23h - DATA0 - VRAM Data Port 0 00h
9F24h - DATA1 - VRAM Data Port 1 00h
9F25h - CTRL - Control 00h
9F26h - IEN - Int. Enable / Line Comp. / Num. (upper 1 bit) 00h
9F27h - ISR - Interrupt / Status Register 00h
9F28h - IRQLINE_L - Interrupt Line Compare (lower 8 bits) (W) -
9F28h - SCANLINE_L - Current Line Number (lower 8 bits) (R) 00h
(DCSEL=0)
9F29h - DC_VIDEO - Active Display Control 04h
9F2Ah - DC_HSCALE - Active Display H-Scale 80h
9F2Bh - DC_VSCALE - Active Display V-Scale 80h
9F2Ch - DC_BORDER - Border Color 00h
(DCSEL=1)
9F29h - DC_HSTART - Active Display H-Start 00h
9F2Ah - DC_HSTOP - Active Display H-Stop A0h
9F2Bh - DC_VSTART - Active Display V-Start 00h
9F2Ch - DC_VSTOP - Active Display V-Stop F0h
(DCSEL=2)
9F29h - FX_CTRL - ADDR1 Update Mode / VRAM Data Port Write Mode 00h
9F2Ah - FX_TILEBASE - Affine Transformation Tile Base 00h
9F2Bh - FX_MAPBASE - Affine Transformation Map Base 00h
9F2Ch - FX_MULT - Write Cache Index / Multiply-accumulate Mode 00h
(DCSEL=3)
9F29h - FX_X_INCR_L - X Position Increment (lower 8 bits) 00h
9F2Ah - FX_X_INCR_H - X Position Increment (upper 8 bits) 00h
9F2Bh - FX_Y_INCR_L - Y Position Increment (lower 8 bits) 00h
9F2Ch - FX_Y_INCR_H - Y Position Increment (upper 8 bits) 00h
(DCSEL=4)
9F29h - FX_X_POS_L - Pixel X Position (lower 8 bits) 00h
9F2Ah - FX_X_POS_H - Pixel X Position (upper 3 bits) 00h
9F2Bh - FX_Y_POS_L - Pixel Y Position (lower 8 bits) 00h
9F2Ch - FX_Y_POS_H - Pixel Y Position (upper 3 bits) 00h
(DCSEL=5)
9F29h - FX_X_POS_F - Pixel X Fractional Position (upper 8 bits) 80h
9F2Ah - FX_Y_POS_F - Pixel Y Fractional Position (upper 8 bits) 80h
9F2Bh - FX_POLY_FILL_L- Fill Length (lower 3 bits) 00h
9F2Ch - FX_POLY_FILL_H- Fill Length (upper 7 bits) 00h
(DCSEL=6)
9F29h..9F2Ch FX_CACHE - 32-bit Write Cache Data 00000000h
(DCSEL=63)
9F29h..9F2Ch VERSION - Version Number (R) -
9F2Dh - L0_CONFIG - L0 Mode and Map Size 00h
9F2Eh - L0_MAPBASE - L0 Map Base 00h
9F2Fh - L0_TILEBASE - L0 Tile Base and Tile Size 00h
9F30h - L0_HSCROLL_L - L0 H-Scroll (lower 8 bits) 00h
9F31h - L0_HSCROLL_H - L0 H-Scroll (upper 4 bits) / Bitmap Color 00h
9F32h - L0_VSCROLL_L - L0 V-Scroll (lower 8 bits) 00h
9F33h - L0_VSCROLL_H - L0 V-Scroll (upper 4 bits) 00h
9F34h - L1_CONFIG - L1 Mode and Map Size 00h
9F35h - L1_MAPBASE - L1 Map Base 00h
9F36h - L1_TILEBASE - L1 Tile Base and Tile Size 00h
9F37h - L1_HSCROLL_L - L1 H-Scroll (lower 8 bits) 00h
9F38h - L1_HSCROLL_H - L1 H-Scroll (upper 4 bits) / Bitmap Color 00h
9F39h - L1_VSCROLL_L - L1 V-Scroll (lower 8 bits) 00h
9F3Ah - L1_VSCROLL_H - L1 V-Scroll (upper 4 bits) 00h
9F3Bh - AUDIO_CTRL - Audio FIFO Control 00h
9F3Ch - AUDIO_RATE - Audio FIFO Sample Rate 00h
9F3Dh - AUDIO_DATA - Audio FIFO Data (W) -
9F3Eh - SPI_DATA - SPI Data -
9F3Fh - SPI_CTRL - SPI Control 00h
YM2151 I/O Ports (2MHz Speed)
9F40h - YM2151 Register Address (W)
9F41h - YM2151 Register Data (W)
9F4xh - YM2151 Status (R)
Further Memory
9F10h..9F1Fh - 2nd VIA Expansion
9F42h..9F5Fh - Reserved (2MHz Speed)
9F60h..9F9Fh - Expansion (8MHz Speed)
9FA0h..9FFFh - Expansion (2MHz Speed)
A000h..BFFFh - Banked RAM
C000h..FFFFh - Banked System ROM / Expansion Memory
VERA Registers (internal to VERA, not the Main CPU)
--> X16 VERA Memory and I/O Map (VRAM)
X16 Memory
==========
--> X16 Memory Map
--> X16 Memory Control
--> X16 VERA Access
--> X16 YM2151 Access
--> X16 System ROM Flash Access
System ROM
System ROM is mapped directly to the CPU bus. Only a 16 KiB bank window of it is
mapped at a time. Since the banking area also covers a CPU interrupt vectors
region (FFFAh-FFFFh) and not all System ROM banks has them. It is recommended to
disable interrupts when accessing outside bank 0 of the System ROM.
Expansion Memory
Since only first 32 banks of the system ROM are mapped directly to the CPU bus,
the remaining 224 banks are left unoccupied which allows expansion cartridges to
map its memory here.
Fixed and Banked RAM
Fixed and Banked RAM are both mapped directly to the CPU bus. Fixed RAM has more
capacity on hardware but it was limited by memory mapping to 39.75 KiB. For
Banked RAM, only an 8 KiB bank window of it is mapped at a time.
VERA Memory
All of VERA memory isn't mapped to the CPU bus, and can be accessed only via I/O
ports. Unlike many older consoles that have this kind of access, it can be
accessed in any time, even if VERA is currently rendering to the screen.
--> X16 VERA Memory Access
Audio FIFO buffer
Audio FIFO buffer isn't mapped to either CPU bus or VERA memory, and can be
accessed only via write-only I/O ports. The buffer is 4095 bytes in size (the
last byte is not used to prevent overflow).
--> X16 VERA Audio FIFO
RTC NVRAM
This small 64 bytes memory comes with the on-board Real-Time Clock chip. It is
used to store data that needs to last across power cycles without the usage of
memory card since the System ROM is not writable from software. RTC NVRAM isn't
mapped to the CPU bus, and can be accessed only via I2C bus.
--> X16 I2C Bus Access
X16 Memory Map
--------------
The X16 uses a 16-bit address bus (0000h-FFFFh). In order to access more than 64
KiB, it has two 8-bit transparent latches to hold the current RAM bank and ROM
bank. These combined 24-bit addresses are then used to address banked RAM and
system ROM area in order.
Overall Memory Map
Bank Offset Content
0000h-9EFFh Fixed RAM
9F00h-9FFFh I/O Area
00h-FFh:A000h-BFFFh Banked RAM (max 2 MiB) (256x8K)
00h-1Fh:C000h-FFFFh System ROM (512 KiB) (32x16K)
20h-FFh:C000h-FFFFh Expansion Memory (max 3.5 MiB) (224x16K)
Additional memory, not mapped to CPU address (accessible only via I/O):
VERA Memory (128 KiB)
Audio FIFO (4 KiB)
RTC NVRAM (64 bytes)
For details on separate I/O ports and expansions, see:
--> X16 I/O Map
Default RAM Usage
By default, the addresses at 0080h-03FFh and banked RAM bank 00h are reserved
for CPU Stack, System Interrupt Vectors and Variables. The remaining RAM is free
for whatever use.
X16 Memory Control
------------------
0000h - Current RAM Bank (R/W)
Bit
7-0 Banked RAM bank number
0001h - Current ROM Bank (R/W)
Bit
7-0 System ROM bank number / ROMBx pin output
Note that the actual values of these two registers are external to the RAM and
can have different values on power-up. However, they are written by the system
on boot and become consistent at user program execution.
X16 VERA Memory Access
----------------------
9F20h - ADDR_L - VRAM Address (lower 8 bits) (R/W)
9F21h - ADDR_M - VRAM Address (middle 8 bits) (R/W)
9F22h - ADDR_H - VRAM Address (upper 1 bit) and Increment Mode (R/W)
Bit
7-4 Address Byte Step Size (see below)
3 Address Byte Step Direction (0=Increment, 1=Decrement)
2 Address Nibble Step (0=Increment, 1=Decrement)
1 VRAM Nibble Address
0 Upper 1 bit of VRAM Address
Address Step Size:
0h=0
1h=1
2h=2
3h=4
4h=8
5h=16
6h=32 Bh=40
7h=64 Ch=80
8h=128 Dh=160
9h=256 Eh=320
Ah=512 Fh=640
Sets or reads a 17-bit address for addressing the 128 KiB of VRAM via DATA0 or
DATA1. These registers are multiplexed for each port which is set by ADDRSEL bit
in CTRL. Address register contents are also updated after each step occurred
from reading/writing to their respective data port register. For details about
ADDRSEL bit, see:
--> X16 VERA Control
Nibble address and step only work when address byte step is 0 and are only
relevant in FX-assisted 4-bit bitmap drawing, see:
--> X16 VERA FX Helper
9F23h - DATA0 - VRAM Data Port 0 (R/W)
9F24h - DATA1 - VRAM Data Port 1 (R/W)
Simply reads or writes a byte at the set address in 9F20h-9F22h of their
respective ports, then steps the address once.
CAUTION: When the address is set or DATAx is read or written, the destination
port will automatically read the next data from VRAM into a buffer ready for its
next DATAx read. However, these buffers are not shared across ports which can
lead to inconsistency when both ports are set to the same address. For example,
when both ADDR0 and ADDR1 are the same, writing to DATA0 will *not* update
DATA1's read data and vice versa.
Memory Content
--> X16 VERA Memory and I/O Map (VRAM)
X16 YM2151 Access
-----------------
Due to the chip's large address space for writing and low pin count, its write
address and data pins are multiplexed. Then, an address/data select pin is
provided. X16 connects this pin to the lowest address pin as usual. Providing
I/O ports to the chip's registers.
For more information about this chip and its registers, see:
--> YM2151 FM Operator Type-M (OPM)
9F40h - YM2151 Register Address (W)
Sets the chip's register address.
9F41h - YM2151 Register Data (W)
Writes to the chip at the currently set register address. Writes here will not
do any address auto-steps.
9F4xh - YM2151 Status (R)
Reads from the chip will always return this status byte no matter what the
currently set register address is. Note that the chip ignores the address/data
select pin for this so this byte can be read from either 9F40h or 9F41h.
Bit
7 Busy Flag (1=Busy)
6-2 Not Used
1 Timer B Overflow (0=No Overflow, 1=Overflow)
0 Timer A Overflow (0=No Overflow, 1=Overflow)
Any successful writes to the register data will set a busy flag for 64 clock
cycles (about 144 CPU cycles since the chip runs slower), indicating that any
other writes shouldn't be done during this period. Setting the register address
won't set and isn't affected by this busy flag, however.
YM2151 and 2MHz I/O Access Clock Stretching
Due to timing constraints from a faster CPU, there's an additional circuitry
which temporarily slows down the CPU by 4 times every time its address output is
in 9F40h-9F5Fh and 9FA0h-9FFFh (IO3,6,7,8 pins physically). This is to make sure
reads/writes to the slower I/O interface are always successful. In other words,
reading/writing to it has an extra 3-cycle wait per instruction (6 cycles for
RMW instructions).
X16 System ROM Flash Access
---------------------------
X16's System ROM is a flash memory which can be erased and programmed with a new
data. Providing that the physical write enable jumper to it is connected. This
is used for updating the system firmware and software from an external memory
without powering off the machine. Like any NOR flash memory, a special write
command sequence is needed. The following sub-sections describe possible command
write sequences. Note that addresses are in ROM bank:CPU address format due to
how the ROM is connected - they are internally 5555h and 2AAAh.
Flash Detection
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=90h ; enter software ID mode
X=(00:C000h) ; manufacturer ID
Y=(00:C001h) ; device ID
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=F0h ; exit software ID mode
X and Y values depend on the ROM chip used on the board, possible values are:
X Y Chip
BFh B7h SST39SF040
Erase Entire Chip
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=80h
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=10h
repeat X=(01:D555h) until X==FFh
Erase 4 KiB Sector
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=80h
(01:D555h)=AAh
(00:EAAAh)=55h
(nn:n000h)=30h
repeat X=(nn:n000h) until X==FFh
Program Byte
The 4 KiB sector where the destination address exist must be fully erased before
programming
for i=first to last
(01:D555h)=AAh
(00:EAAAh)=55h
(01:D555h)=A0h
(nnnnnn+i)=data[i]
repeat X=(nnnnnn+i) until X==data[i]
next i
X16 Versatile Embedded Retro Adapter (VERA)
===========================================
--> X16 VERA Control
--> X16 VERA Display Composer
--> X16 VERA Layer Control
--> X16 VERA Interrupts
--> X16 VERA Audio FIFO
--> X16 VERA Memory Card Interface
--> X16 VERA FX Helper
Embedded Memory
--> X16 VERA Memory and I/O Map (VRAM)
--> X16 VERA Programmable Sound Generator (PSG)
--> X16 VERA Color Palette
--> X16 VERA Sprites
VERA memory isn't mapped to the CPU bus, and can be accessed only via I/O ports.
--> X16 VERA Memory Access
Pinouts
--> X16 Audio/Video Connector Pinouts
--> X16 Pinouts VERA Module
--> X16 Pinouts VERA Chips
X16 VERA Control
----------------
9F25h - CTRL - Control (R/W)
Bit
7 Reset Adapter (1=Reset)
6-1 Display Composer Register Select (DCSEL)
0 Address Port Select (ADDRSEL)
Writing reset bit to this register will reset the entire adapter's operation and
initialize all registers. Current video and sound output will be lost. In boards
with a dedicated VERA chip, this operation completely resets the FPGA which can
take milliseconds to reconfigure. A detection for when it is configured can be
done by repeatedly writing a data to a register and reading it back until it
stays.
DCSEL selects which Display Composer register bank to access in location
9F29h-9F2Ch. ADDRSEL selects which port to read/write address when accessing
VERA memory from the CPU. For more information, see their respective entries:
--> X16 VERA Display Composer
--> X16 VERA Memory Access
9F29h..9F2Ch (DCSEL=63) - VERSION - Version Number (R)
Byte 0 Always 56h ('V')
Byte 1 Major Version Number
Byte 2 Minor Version Number
Byte 3 Patch Version Number
Writing 63 to DCSEL will select this read-only register. It contains a version
number information of this VERA hardware. For example, an official r47 FPGA
configuration contains bytes 56h 2Fh 00h 00h in order.
X16 VERA Display Composer
-------------------------
9F29h (DCSEL=0) - DC_VIDEO - Active Display Control (R/W)
Bit
7 Current Interlace Frame (0=Even, 1=Odd Frame) (Read-only)
6 Sprites (0=Disable, 1=Enable)
5 Layer 1 (0=Disable, 1=Enable)
4 Layer 0 (0=Disable, 1=Enable)
3 Interlacing (0=Enable, 1=Disable)
2 Chroma Output (no effect in RGB) (0=Enable, 1=Disable)
1 Sync Generation (0=Separate, 1=Composite)
0 Output Mode (0=Luma/Chroma, 1=RGB)
Notable bits 0-3 combination:
Mode
0 Display off
1 31.5kHz RGB 480p (VGA)
2 15.75kHz Composite 480i Color (NTSC)
3 15.75kHz RGB 480i
6 15.75kHz Composite 480i Monochrome
9 15.75kHz RGB 240p VGA Sync
10 15.75kHz Composite 240p Color
11 15.75kHz RGB 240p Composite Sync
14 15.75kHz Composite 240p Monochrome
VERA natively outputs in a progressive RGB format with a line rate of 31.5kHz.
Which the system also boots in that mode by default. It is also capable of
outputting at half a line rate of 15.75kHz with or without interlacing. However,
it comes with a trade-off that every other lines will not be rendered at all.
Also, these modes have different video timings.
Luma/Chroma output can only be output in 15.75kHz modes. The adapter also has a
hardware to modulate Luma/Chroma signals into NTSC composite video. However,
most NTSC CRT TVs can only display around the middle 592x448 region. So, this
overscan should be taken into account when using composite output.
Even though interlacing is disabled in 15.75kHz modes (240p), the VERA still
alternatively outputs only odd lines and even lines in each frame as if it's
interlacing. This causes adjacent lines to be temporally blended together.
CAUTION: Enabling layers mid-screen can cause a garbage line to be displayed as
the renderer was not active to fill in a data for the current displaying line.
9F2Ah (DCSEL=0) - DC_HSCALE - Active Display H-Scale (R/W)
9F2Bh (DCSEL=0) - DC_VSCALE - Active Display V-Scale (R/W)
Scales the entire rendering output by a factor of 128/x. A value of 80h means no
scaling. This is mainly used for displaying low resolution graphics.
Scaling is done by adding this fractional H-Scale value each drawn pixel and
V-Scale value each drawn line to the virtual screen position. Then the integer
part of this virtual screen position is then used for the rest of composition
logic. This puts the scaling center at the top-left corner of an active display
area.
CAUTION: Virtual screens larger than 640x480 is not possible as the rendering
will stop if the virtual screen position is either above it horizontally or
vertically. Also, setting V-Scale above 1.0 (80h) will skip some pixels while
rendering, potentially causing inaccurate collision detection. Although this is
not a case for setting H-Scale above 1.0 (80h) as the line rendering always runs
at a native horizontal resolution.
9F2Ch (DCSEL=0) - DC_BORDER - Border Color (R/W)
When the drawing pixel is outside the active display area defined by start and
stop registers, it will be set to a solid color at the index of this register's
value in the palette memory. Please note that this is different from a
background color which is always color index 0.
9F29h (DCSEL=1) - DC_HSTART - Active Display H-Start (R/W)
9F2Bh (DCSEL=1) - DC_VSTART - Active Display V-Start (R/W)
Sets the starting point of an active display area in native display coordinates.
Horizontal value is in steps of 4 and vertical value is in steps of 2. The
virtual screen will always start from this point.
9F2Ah (DCSEL=1) - DC_HSTOP - Active Display H-Stop (R/W)
9F2Ch (DCSEL=1) - DC_VSTOP - Active Display V-Stop (R/W)
Sets the stopping point of an active display area in native display coordinates
(they are not scaled to DC_xSCALE values). Horizontal value is in steps of 4 and
vertical value is in steps of 2. The stopping point is not inclusive.
These four register values are analogous to a display window in many consoles.
The width of an active display is (DC_HSTOP-DC_HSTART)*4 pixels and the height
of an active display is (DC_VSTOP-DC_VSTART)*2 pixels. For example, a screen
that starts at (64,50) with an active display size of 320x200 pixels will have
9F29h-9F2Ch values of 10h, 19h, 60h, 7Dh in order.
X16 VERA Layer Control
----------------------
9F2Dh - L0_CONFIG - L0 Mode and Map Size (R/W)
9F34h - L1_CONFIG - L1 Mode and Map Size (R/W)
Bit
7-6 Map Height (0=32, 1=64, 2=128, 3=256 tiles)
5-4 Map Width (0=32, 1=64, 2=128, 3=256 tiles)
3 Tile Mode Color (0=16FG/16BG, 1=256FG/1BG) (1bpp-only)
/ Force Palette Number Bit 7 (other depths)
2 Tile/Bitmap Mode (0=Tile Mode, 1=Bitmap Mode)
1-0 Color Depth (0=1bpp, 1=2bpp, 2=4bpp, 3=8bpp)
Tile Mode Color (bit 3) setting is valid only if the layer is set to 1bpp mode.
For other modes, all layer pixels' palette number bit 7 is ORed with this bit
just before the color lookup. Allowing quick global color changes to layers.
Sprite pixels are not affected by this bit, however.
The map will wrap around if the screen draws beyond its width or height.
9F2Eh - L0_MAPBASE - L0 Map Base (R/W)
9F35h - L1_MAPBASE - L1 Map Base (R/W)
Specifies the map base address in 512-byte steps. In bitmap mode, this has no
effect.
9F2Fh - L0_TILEBASE - L0 Tile Base and Tile Size (R/W)
9F36h - L1_TILEBASE - L1 Tile Base and Tile Size (R/W)
Bit
7-2 Tile / Bitmap Base Address in VRAM (in 2-KiB steps)
1 Tile Height (0=8, 1=16 pixels)
0 Tile Width (0=8, 1=16 pixels) / Bitmap Width (0=320, 1=640 pixels)
9F30h/9F31h - L0_HSCROLL_L/L0_HSCROLL_H - L0 Horizontal Scroll (R/W)
9F37h/9F38h - L1_HSCROLL_L/L1_HSCROLL_H - L1 Horizontal Scroll (R/W)
Bit
15-12 Not Used
11-0 Horizontal Scroll (Tile Mode)
11-8 Palette Number (Bitmap Mode)
In bitmap mode, horizontal scroll has no effect.
9F32h/9F33h - L0_VSCROLL_L/L0_VSCROLL_H - L0 Vertical Scroll (R/W)
9F39h/9F3Ah - L1_VSCROLL_L/L1_VSCROLL_H - L1 Vertical Scroll (R/W)
Bit
15-12 Not Used
11-0 Vertical Scroll
In bitmap mode, this has no effect.
X16 VERA Interrupts
-------------------
9F26h - IEN - Interrupt Enable / Current Line Number (upper 1 bit) / Line Compare (upper 1 bit) (R/W)
Bit
7 Interrupt Line Compare (upper 1 bit) (Write-only)
6 Current Line Number (upper 1 bit) (Read-only)
5-4 Not Used
3 FIFO Low IRQ (0=Disable, 1=Enable)
2 Sprite Collide IRQ (0=Disable, 1=Enable)
1 Line IRQ (0=Disable, 1=Enable)
0 VBlank IRQ (0=Disable, 1=Enable)
For details about Line Compare/Number bits, see IRQLINE_L (9F28h) entry.
9F27h - ISR - Interrupt / Status Register (R/W)
Bit
7-4 Sprite Collisions (Read-only)
3 FIFO Low IRQ Flag (0=None, 1=Interrupt Request) (Read-only)
2 Sprite Collide IRQ Flag (0=None, 1=Interrupt Request)
1 Line IRQ Flag (0=None, 1=Interrupt Request)
0 VBlank IRQ Flag (0=None, 1=Interrupt Request)
FIFO Low IRQ is generated once the buffer is less than 1024 bytes in size and
its flags remain set until the buffer is larger than or equal to 1024 bytes.
Sprite Collide IRQ is generated at VBlank when a sprite collision occurs. Its
flags and Sprite Collisions field remain set until the next VBlank. For details
about sprite collision bits, see:
--> X16 VERA Sprites
Line IRQ is generated at the beginning of the display line that matches the line
compare value. Its flags are not automatically cleared.
VBlank IRQ is generated at the beginning of VBlank period (the line after the
last display line). Its flags are not automatically cleared.
All of the 4 flags get set even if their respective interrupts are disabled.
Writing a bit 1 to one of the bits 0-2 will clear that interrupt status.
9F28h - SCANLINE_L - Current Line Number (lower 8 bits) (R)
9F28h - IRQLINE_L - Interrupt Line Compare (lower 8 bits) (W)
When read, returns the current *display* line number. When write, Specifies the
*display* line number to generate IRQ at. This number is neither scaled with the
DC_VSCALE register nor offset with the DC_VSTART register. In interlaced mode,
bit 0 is fixed to the current odd/even field value when read and is ignored when
write - it will generate IRQ in both two frames even if that line is skipped in
either field of the display. Line comparison is done on every display lines even
during VBlank up to line 511. Display lines further than this are always read
511 and cannot be compared.
CAUTION: Since VERA renders to a line buffer first then read it out to the
screen in the next line, changes made to layer settings and VRAM will not be
visible until the next line. This does not apply to display composer settings
and palette data as they will take effect immediately. Keep this in mind when
doing raster effects.
X16 VERA Audio FIFO
-------------------
9F3Bh - AUDIO_CTRL - Audio FIFO Control (R/W)
Bit
7 FIFO Full (R) / FIFO Reset (1=Reset) (W)
6 FIFO Empty (Read-only)
5 FIFO Sample Size (0=8-bit, 1=16-bit)
4 FIFO Sample Channels (0=Mono, 1=Stereo)
3-0 FIFO Output Volume (0=Silent, 15=Loudest)
Writing reset bit to this register will empty the current buffer. The output
volume is not linear and has the meaning as follows:
0h=0 1h=16 2h=32 3h=48 4h=64 5h=80 6h=96 7h=128
8h=176 9h=224 Ah=384 Bh=368 Ch=480 Dh=608 Eh=784 Fh=1024
NOTE: All values can be approximated as 2.2 dB steps, and are relative to PSG's
output level.
9F3Ch - AUDIO_RATE - Audio FIFO Sample Rate (R/W)
Specifies the playback rate of the FIFO in 25000*n/65536 KHz. A value of 0 will
stop playback. Values higher than the maximum 128 is invalid and effectively
equals to 256-n.
9F3Dh - AUDIO_DATA - Audio FIFO Data (W)
Writes one byte to the FIFO and increases the current buffer size by one. Any
writes will be ignored if the current buffer size is over 4095 bytes (indicated
by bit 7 in AUDIO_CTRL). The data needs to be written depends on the current bit
4-5 setting in AUDIO_CTRL as follows:
AUDIO_CTRL Data Format
8-bit Mono [Signed 7:0]
8-bit Stereo [Signed Left 7:0] [Signed Right 7:0]
16-bit Mono [7:0] [Signed 15:8]
16-bit Stereo [Left 7:0] [Signed Left 15:8] [Right 7:0] [Signed Right 15:8]
When the FIFO is active, it will regularly retrieve the oldest sample in the
buffer as the name implies (First In, First Out), and output at a rate defined
in AUDIO_RATE register. And then decreases the buffer size. Once the buffer size
is lower than 1024 bytes it will generate FIFO Low IRQ if it's enabled and set
its flag until the buffer size is higher than or equal to 1024 bytes. If it is
unable to retrieve a new sample from an empty buffer, the output will be set to
0.
X16 VERA Memory Card Interface
------------------------------
VERA uses an SPI bus, which is a 4-wire serial bus to communicate and transfer
data with the memory card. It uses SPI Mode 0 for clock and data signals. Its
interface is quite bare and can be adapted to any SPI device. This is the only
interface with automatic clocking and transfer in X16.
9F3Eh - SPI_DATA - SPI Data (R/W)
Reads from this register returns the last received byte. Writes to this register
will start transferring one byte of written data to the device and receiving one
byte of data from the device at the same time. The busy flag in SPI_CTRL is set
during the transfer period. Once the transfer completes, the busy flag is
cleared and the new received byte is latched to this register. Since the VERA is
on the controller side and due to how SPI works, it's usually required to write
to this register many times to shift out dummy clocks until the desired data
from the device is received and latched.
9F3Fh - SPI_CTRL - SPI Control (R/W)
Bit
7 Busy Flag (1=Busy) (Read-only)
6-3 Not Used
2 Auto Transfer (0=Off, 1=On)
1 Shift Clock Speed (0=12.5MHz, 1=391KHz)
0 Chip Select (0=Release, 1=Select)
A shift clock speed of 391KHz was implemented because some memory cards require
it to be lower than 400KHz during an initialization process. A chip select is
required in order to activate the memory card.
When Auto Transfer is on, any reads from SPI_DATA will also transfer FFh to the
device and receive one byte of data from it at the same time.
Memory Card Commands
The memory card takes a 6-byte command and arguments as shown below:
Byte 0
Bit 7 Start Bit, always 0
Bit 6 Transmission Bit, always 1
Bit 5-0 Command Index
Byte 1-4 Command Argument
Byte 5
Bit 7-1 CRC-7 (09h Polynomial)
Bit 0 Stop Bit, always 1
NOTE: SPI mode disables all CRCs by default. However, commands 00h and 08h are
of native mode and still requires it.
The below is a partial list of commands that are usually used for basic card
initialization and data transfer, all reserved bits should always be 0:
Command Arguments (Big Endian) Resp. Explanation
00h 31-0 Stuff R1 Reset the memory card to idle state
01h 31-0 Stuff R1 Initialize the memory card (MMC only)
08h 31-12 Reserved R7 Check voltage range (added later in
11-8 Supply Voltage SD v2 spec, used to detect newer cards)
7-0 Check Pattern
0Ch 31-0 Stuff R1b Force the memory card to stop
transmission in Read Multiple Blocks
operation.
0Dh 31-0 Stuff R2 Read the status register
10h 31-0 Block Length R1 Set block length (always fixed to 512
bytes in SDHC/SDXC)
11h 31-0 Data Address* R1 Read a block of data
12h 31-0 Data Address* R1 Read multiple blocks until stop command
18h 31-0 Data Address* R1 Write a block of data
19h 31-0 Data Address* R1 Write multiple blocks until stop token
37h 31-0 Stuff R1 Tell the memory card that the next
command is an application(SD)-specific
command. Used in next two commands:
37h 17h 31-23 Stuff R1 Set the number of write blocks to be
22-0 Number of Blocks pre-erased before writing for faster
Write Multiple Blocks operation
37h 29h 31 Reserved R1 Send host capacity support information
30 Host Capacity (0=SDSC, 1=SDHC/SDXC) and initialize
29-0 Reserved the memory card
3Ah 31-0 Stuff R3 Reads the OCR register (see below)
3Bh 31-1 Stuff
0 CRC (0=Off, 1=On) R1 Turns CRC on or off
* In bytes for MMC/SDSC, in 512-byte blocks for SDHC/SDXC
When a command is sent, after certain delay bytes (write to 9F3Eh until read
isn't FFh), the memory card will send response bits back. The format depends on
the command as described in the above table. Response R1b is response R1 with
optional trailing busy signal where the memory card pulls the data line low
(reads are not FFh like on release). Bytes in all tables below are big endian.
Response R1
Bit
7 Always 0
6 Parameter Error
5 Address Error
4 Erase Sequence Error
3 CRC Error
2 Illegal Command
1 Erase Reset
0 In Idle State
Response R2 (Status Register)
Bit
15-8 Same as R1
7 Out of Range/CSD overwrite
6 Erase Parameter
5 Write Protect Violation
4 Card ECC failed
3 Card Controller Error
2 Generic Error
1 Write Protect Erase Skip/(Un)lock Command Failed
0 Card is Locked
Response R3 (OCR Register)
Bit
39-32 Same as R1
31 Card Power-up Status (0=Powering Up, 1=Normal)
30 Card Capacity Status (0=MMC/SDSC, 1=SDHC/SDXC)
29-24 Reserved
23-0 Voltage Window
Response R7
Bit
39-32 Same as R1
31-28 Command Version
27-12 Reserved
11-8 Voltage Accepted
7-0 Check Pattern Echo
Memory Card Initialization
After power on or memory card insertion, wait for at least 1 ms. Set shift clock
speed to slow speed (bit 1 of 9F3Fh is set). Chip release the memory card then
write at least 10 bytes of data to apply clock pulses. It is now operating in
native mode. To change it to SPI mode or resetting it, chip select it back and
send a command 00h. It is now in SPI mode with idle state.
In idle state, only commands 00h, 01h, 08h, 37h 29h, 3Ah and 3Bh are accepted.
To initialize the card and exit idle state, send a command 08h to detect newer
SD (this command does not exist in older MMC/SDSC) then repeatedly send a
command 37h 29h (or 01h in case of illegal command) until idle state bit in the
response is cleared. Now the memory card is fully initialized and able to run at
full shift clock speed. OCR register can now be read to determine the memory
card's capacity.
Memory Card Data Transfer
The memory card sends and takes a data in packets. The packet consists of a
1-byte token, a data block with a size of the current block length setting and a
2-byte CRC-16-CCITT (1021h Polynomial). There are delays between each data
packets which needs to be clocked.
Single Block Read (Token=FEh)
__ _________ _______________________
Write |_CMD 11h_|
_______________ __ ____ ________ ___
Read |R1| |_Packet_|
Multiple Blocks Read (Token=FEh)
__ _________ _____________________________ __ _________ ________________
Write |_CMD 12h_| / / |_CMD 0Ch_|
_______________ __ ____ ________ ____ ___/ /__ ____ ____ __ __ ___
Read |R1| |_Packet_| |_Pa/ /t_| |_Pac| |R1|_Busy_|
If reading fails, the memory card will send a following 1-byte data error token
instead of a data packet:
Bit
7-4 Always 0
3 Out Of Range
2 Card ECC failed
1 Card Controller Error
0 Generic Error
Single Block Write (Token=FEh)
__ _________ ________ ________ _____________
Write |_CMD 18h_| |_Packet_|
_______________ __ ___________ __ ___
Read |R1| |DR|_Busy_|
-> <- 1+ bytes
Multiple Blocks Write (Token=FCh)
__ _________ ________ ________ ____________ ____ _______________________
Write |_CMD 19h_| |_Packet_| |_Pa/ / |FDh|
_______________ __ ___________ __ ______/ / ______ ___
Read |R1| |DR|_Busy_| / /Busy_| |_Busy_|
-> <- 1+ bytes -> <- 1 byte
Each written packet will make the memory card send a data response token (DR)
back in the next byte, this 1-byte token has a following format:
Bit
7-5 Not Used
4 Always 0
3-1 Status (2=Data Accepted, 5=CRC Error, 6=Write Error)
0 Always 1
VERA Configuration Flash Access
In boards with a dedicated VERA chip, there is a jumper to permanently enable an
accesss to the configuration flash memory during a normal operation. This allows
VERA FPGA's configuration to be reprogrammed in-system through the same SPI
interface. However, SPI flash memory have different commands from memory cards
and the topic of programming it is outside of this document's scope.
X16 VERA FX Helper
------------------
(under construction - see Jeffrey's docs for now)
Starting with V0.3.1, an FX helper was added to the VERA to accelerate bitmap
graphics tasks such as transparent pixel composition, polygon drawing and affine