Skip to content

Commit 88180c5

Browse files
committed
First cut at a Video Audio Player example.
1 parent 10722be commit 88180c5

File tree

14 files changed

+724
-0
lines changed

14 files changed

+724
-0
lines changed
Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
/*
2+
Gadget Factory
3+
Example for Alvaro's ZPUino VGA Adapter
4+
To learn more about using DesignLab please visit http://learn.gadgetfactory.net
5+
6+
Related library documentation:
7+
Use the Adafruit GFX library to program this VGA adapter.
8+
https://learn.adafruit.com/adafruit-gfx-graphics-library/overview
9+
10+
created 2015
11+
by Alvaro Lopes
12+
http://www.gadgetfactory.net
13+
14+
This example code is in the public domain.
15+
*/
16+
17+
#define circuit Computing_Shield2
18+
19+
#include "Adafruit_GFX.h"
20+
#include "ZPUino_GFX.h"
21+
#include "PLL.h"
22+
#include "menus.h"
23+
#include "SID.h"
24+
#include "YM2149.h"
25+
#include "ymplayer.h"
26+
#include "sidplayer.h"
27+
#include <Timer.h>
28+
#include "SmallFS.h"
29+
#include <SD.h>
30+
#include <SPI.h>
31+
#include "ramFS.h"
32+
#include "cbuffer.h"
33+
#include <Timer.h>
34+
35+
YM2149 ym2149;
36+
YMPLAYER ymplayer;
37+
//SID sid;
38+
SIDPLAYER sidplayer;
39+
40+
ZPUino_GFX gfx;
41+
static bool menuVisible = true;
42+
static bool sidState = false;
43+
static bool ymState = false;
44+
45+
#define TIMEOUTMAX 10000 //Timeout for joystick
46+
47+
//Joystick
48+
#define JSELECT 19
49+
#define JDOWN 18
50+
#define JUP 20
51+
#define JRIGHT 17
52+
#define JLEFT 21
53+
54+
enum kButtonDirection {
55+
Left = 0,
56+
Right = 1,
57+
Up = 2,
58+
Down = 3,
59+
Select = 4,
60+
None = 5
61+
};
62+
63+
unsigned long timeout;
64+
int sidplayercounter = 0;
65+
kButtonDirection buttonPressed;
66+
67+
void exitMenus(void *a)
68+
{
69+
menuExit();
70+
menuVisible=false;
71+
gfx.fillScreen( 0 );
72+
}
73+
74+
75+
void showMenu()
76+
{
77+
menuReset();
78+
menuVisible=true;
79+
menuShowTop();
80+
}
81+
82+
static void sidStop(void*)
83+
{
84+
sidplayer.play(false);
85+
}
86+
static void ymStop(void*)
87+
{
88+
ymplayer.play(false);
89+
}
90+
static void sidStart(void*)
91+
{
92+
sidplayer.play(true);
93+
}
94+
static void ymStart(void*)
95+
{
96+
ymplayer.play(true);
97+
}
98+
99+
static void createMenus()
100+
{
101+
subMenu *config = new subMenu("Options");
102+
103+
// subMenu *sid = new subMenu("SID Audio");
104+
// config->appendChild(sid);
105+
// sid->setParent(config);
106+
config->appendChild( new menuItem("SID Pause", &sidStop) );
107+
config->appendChild( new menuItem("YM Pause", &ymStop) );
108+
109+
config->appendChild( new menuItem("SID Play", &sidStart) );
110+
config->appendChild( new menuItem("YM Play", &ymStart) );
111+
112+
// modo->appendChild( new menuItem("Video", &onVideo) );
113+
// modo->appendChild( new menuItem("Bricks", &onBricks)) ;
114+
// modo->appendChild( new menuItem("SoundPuddle",&onVideo) ) ;
115+
// modo->appendChild( new menuItem("< Back",(void(*)(void*))&menuSwitchTo, config) ) ;
116+
117+
// subMenu *ym = new subMenu("YM Audio");
118+
// config->appendChild(ym);
119+
// ym->setParent(config);
120+
//controle->appendChild( new menuItem("< Back",(void(*)(void*))&menuSwitchTo, config) ) ;
121+
122+
config->appendChild( new menuItem("Exit",(void(*)(void*))&exitMenus) ) ;
123+
124+
menuSetTop(config);
125+
}
126+
127+
bool timer(void*)
128+
{
129+
sidplayercounter++;
130+
//modplayer.zpu_interrupt();
131+
ymplayer.zpu_interrupt();
132+
if (sidplayercounter == 340) {
133+
sidplayer.zpu_interrupt();
134+
sidplayercounter = 1;
135+
}
136+
//retrocade.setTimeout();
137+
return true;
138+
}
139+
140+
void setup()
141+
{
142+
//delay(3000);
143+
Serial.begin(115200);
144+
Serial.println("Starting");
145+
gfx.begin(MODE_640x480);
146+
//gfx.begin( &modeline_640x480_60 );
147+
createMenus();
148+
//menuInit(128,128);
149+
menuInit(300,300);
150+
menusSetRenderer(&gfx);
151+
152+
153+
//Set Wishbone slots for audio chips
154+
//sid.setup(14);
155+
//ym2149.setup(13);
156+
157+
ymplayer.setup(&ym2149,6);
158+
sidplayer.setup(8);
159+
160+
///Give some volume
161+
ym2149.V1.setVolume(11);
162+
ym2149.V2.setVolume(11);
163+
ym2149.V3.setVolume(11);
164+
//sid.setVolume(15);
165+
166+
sidplayer.loadFile("track1.sid");
167+
sidplayer.play(true);
168+
169+
ymplayer.loadFile("track1.ymd");
170+
ymplayer.play(true);
171+
172+
//Setup timer for YM and mod players, this generates an interrupt at 1700hz
173+
Timers.begin();
174+
int r = Timers.periodicHz(17000, timer, 0, 1);
175+
if (r<0) {
176+
Serial.println("Fatal error!");
177+
}
178+
179+
//Setup Joystick
180+
pinMode(JSELECT, INPUT);
181+
pinMode(JUP, INPUT);
182+
pinMode(JDOWN, INPUT);
183+
pinMode(JLEFT, INPUT);
184+
pinMode(JRIGHT, INPUT);
185+
186+
timeout=TIMEOUTMAX;
187+
showMenu();
188+
}
189+
190+
void loop()
191+
{
192+
if (sidplayer.getPlaying() == 1)
193+
sidplayer.audiofill();
194+
195+
if (ymplayer.getPlaying() == 1)
196+
ymplayer.audiofill();
197+
198+
timeout--;
199+
if (timeout==0) {
200+
timeout = TIMEOUTMAX;
201+
//Serial.println("timeout");
202+
if (digitalRead(JUP)) {
203+
timeout = TIMEOUTMAX;
204+
buttonPressed = Up;
205+
Serial.println("up");
206+
} else if (digitalRead(JDOWN)) {
207+
timeout = TIMEOUTMAX;
208+
buttonPressed = Down;
209+
Serial.println("down");
210+
} else if (digitalRead(JRIGHT)) {
211+
timeout = TIMEOUTMAX;
212+
buttonPressed = Right;
213+
Serial.println("right");
214+
} else if (digitalRead(JLEFT)) {
215+
timeout = TIMEOUTMAX;
216+
buttonPressed = Left;
217+
Serial.println("left");
218+
} else if (digitalRead(JSELECT)) {
219+
timeout = TIMEOUTMAX;
220+
buttonPressed = Select;
221+
Serial.println("select");
222+
}
223+
}
224+
225+
226+
227+
if (buttonPressed < 5) {
228+
//char s = (char)Serial.read();
229+
if (menuVisible) {
230+
if (buttonPressed == Up) {
231+
Serial.println("up");
232+
moveMenuUp();
233+
}
234+
if (buttonPressed == Down) {
235+
Serial.println("down");
236+
moveMenuDown();
237+
}
238+
if (buttonPressed == Right) {
239+
//Serial.println("action");
240+
menuAction();
241+
}
242+
if (buttonPressed == Left) {
243+
exitMenus(0);
244+
}
245+
} else {
246+
if (buttonPressed == Select) {
247+
Serial.println("show");
248+
showMenu();
249+
}
250+
}
251+
buttonPressed = None;
252+
}
253+
}
37.5 KB
Binary file not shown.
10.9 KB
Binary file not shown.
32 KB
Binary file not shown.
5.68 KB
Binary file not shown.
11.1 KB
Binary file not shown.
5.02 KB
Binary file not shown.
5.68 KB
Binary file not shown.
3.58 KB
Binary file not shown.
6 KB
Binary file not shown.

0 commit comments

Comments
 (0)