Skip to content

Commit 7793e91

Browse files
authored
Alvin G. support (#27)
1 parent 65bef7f commit 7793e91

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Since not any consumer (especially the Raspberry Pi) can act as an SPI slave thi
1818
* Stern SPIKE 1 -> 128x32
1919
* Capcom -> 128x32
2020
* Gottlieb/Premier -> 128x32
21+
* Alvin G. & Co -> 128x32
2122

2223
## Reading data
2324

src/dmd_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "dmd_interface_sam.pio.h"
99
#include "dmd_interface_spike.pio.h"
1010
#endif
11+
#include "dmd_interface_alving.pio.h"
1112
#include "dmd_interface_capcom.pio.h"
1213
#include "dmd_interface_capcom_hd.pio.h"
1314
#include "dmd_interface_desega.pio.h"

src/dmd_interface_alving.pio

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.define DE 7
2+
.define RDATA 6
3+
.define RCLK 5
4+
.define COLLAT 4
5+
.define DOTCLK 3
6+
.define SDATA 2
7+
.define FRAME_START_IRQ 5
8+
9+
.program dmd_reader_alving
10+
; initialize y with 16383, number of pixels (128x32x4) - 1 because counting starts at 0.
11+
set x, 31 ; x = 31 (max 5-bit value)
12+
in x, 5 ; shift in 5 bits, isr = 31
13+
set x, 31 ; x = 31
14+
in x, 5 ; shift in 5 bits, isr = 1023
15+
set x, 15 ; x = 15
16+
in x, 4 ; shift in 4 bits, isr = 16383
17+
mov y, isr ; y = 16383
18+
19+
.wrap_target
20+
mov x, y ; load number of pixels
21+
mov isr, null ; clear ISR and reset shift counter
22+
23+
irq clear FRAME_START_IRQ
24+
wait irq FRAME_START_IRQ
25+
26+
dotloop:
27+
wait 0 gpio DOTCLK ; falling edge
28+
in null, 3 ; left padding with 3 zeros
29+
wait 1 gpio DOTCLK ; raising edge
30+
in pins 1 ; read pin data
31+
jmp x-- dotloop
32+
.wrap
33+
34+
; Frame detection program runs in parallel to the reader program and signals the start of a new frame using an IRQ.
35+
.program dmd_framedetect_alving
36+
wait 0 gpio RDATA
37+
wait 1 gpio RDATA
38+
; When RDATA turned HIGH, we already missed the start of the first row, so we skip 32 end of rows before sending the first IRQ.
39+
; Alvin G needs to skip 3 COLLAT edges right after for a correct starting point.
40+
.wrap_target
41+
set x, 31 ; 32 rows
42+
set y, 2 ; 3 COLLAT edges
43+
44+
rclk_loop:
45+
wait 0 gpio RCLK
46+
wait 1 gpio RCLK
47+
jmp x-- rclk_loop
48+
49+
collat_loop:
50+
wait 0 gpio COLLAT
51+
wait 1 gpio COLLAT
52+
jmp y-- collat_loop
53+
54+
irq FRAME_START_IRQ
55+
.wrap
56+

src/dmdreader.cpp

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ enum DmdType {
7676
DMD_DESEGA,
7777
DMD_SEGA_HD,
7878
DMD_GOTTLIEB,
79+
DMD_ALVING,
7980
// CAPCOM need to be the last entries:
8081
DMD_CAPCOM,
8182
DMD_CAPCOM_HD,
@@ -375,6 +376,11 @@ DmdType detect_dmd() {
375376
(de < 13100) && (rdata > 370) && (rdata < 410)) {
376377
return DMD_GOTTLIEB;
377378

379+
// Alvin G -> DOTCLK: 1192000 | DE: 9400 | RDATA: 73
380+
} else if ((dotclk > 1150000) && (dotclk < 1250000) && (de > 9200) &&
381+
(de < 9600) && (rdata > 65) && (rdata < 80)) {
382+
return DMD_ALVING;
383+
378384
// Capcom -> DOTCLK: 4168000 | DE: 16280 | RDATA: 510
379385
} else if ((dotclk > 4000000) && (dotclk < 4300000) && (de > 16000) &&
380386
(de < 16500) && (rdata > 490) && (rdata < 530)) {
@@ -628,17 +634,32 @@ void dmd_dma_handler() {
628634
src4 = src3 + source_dwordsperline;
629635
uint32_t v;
630636

631-
for (int l = 0; l < source_height; l++) {
632-
for (int w = 0; w < source_dwordsperline; w++) {
633-
// On SAM line order is really messed up :-(
634-
v = src4[w] * 8 + src3[w] * 1 + src2[w] * 4 + src1[w] * 2;
635-
dst[w] = v;
637+
if (dmd_type == DMD_SAM) {
638+
for (int l = 0; l < source_height; l++) {
639+
for (int w = 0; w < source_dwordsperline; w++) {
640+
// On SAM line order is really messed up :-(
641+
v = src4[w] * 8 + src3[w] * 1 + src2[w] * 4 + src1[w] * 2;
642+
dst[w] = v;
643+
}
644+
src1 += source_dwordsperline * 4; // source skips 4 lines forward
645+
src2 += source_dwordsperline * 4;
646+
src3 += source_dwordsperline * 4;
647+
src4 += source_dwordsperline * 4;
648+
dst += source_dwordsperline; // destination skips only one line
649+
}
650+
} else { // Alvin G
651+
for (int l = 0; l < source_height; l++) {
652+
for (int w = 0; w < source_dwordsperline; w++) {
653+
// First row captured counts as intensity level 3 <--
654+
v = src4[w] * 4 + src3[w] * 4 + src2[w] * 4 + src1[w] * 3;
655+
dst[w] = v;
656+
}
657+
src1 += source_dwordsperline * 4; // source skips 4 lines forward
658+
src2 += source_dwordsperline * 4;
659+
src3 += source_dwordsperline * 4;
660+
src4 += source_dwordsperline * 4;
661+
dst += source_dwordsperline; // destination skips only one line
636662
}
637-
src1 += source_dwordsperline * 4; // source skips 4 lines forward
638-
src2 += source_dwordsperline * 4;
639-
src3 += source_dwordsperline * 4;
640-
src4 += source_dwordsperline * 4;
641-
dst += source_dwordsperline; // destination skips only one line
642663
}
643664
}
644665
}
@@ -849,13 +870,32 @@ void dmdreader_init() {
849870
break;
850871
}
851872

873+
case DMD_ALVING: {
874+
uint input_pins[] = {RDATA, RCLK, COLLAT};
875+
dmdreader_programs_init(
876+
&dmd_reader_alving_program,
877+
dmd_reader_alving_program_get_default_config,
878+
&dmd_framedetect_alving_program,
879+
dmd_framedetect_alving_program_get_default_config, input_pins, 2, 0);
880+
881+
source_width = 128;
882+
source_height = 32;
883+
source_bitsperpixel = 4;
884+
target_bitsperpixel = 4;
885+
source_planesperframe = 1; // in Alvin G there is one plane
886+
// with 4x line oversampling
887+
source_lineoversampling = LINEOVERSAMPLING_4X;
888+
source_mergeplanes = MERGEPLANES_NONE;
889+
break;
890+
}
891+
852892
case DMD_CAPCOM: {
853893
uint input_pins[] = {RDATA, RCLK};
854894
dmdreader_programs_init(&dmd_reader_capcom_program,
855895
dmd_reader_capcom_program_get_default_config,
856896
&dmd_framedetect_capcom_program,
857897
dmd_framedetect_capcom_program_get_default_config,
858-
input_pins, 2, 0);
898+
input_pins, 3, 0);
859899

860900
source_width = 128;
861901
source_height = 32;

0 commit comments

Comments
 (0)