00001
00196
#include "board.h"
00197
#include "lcd.h"
00198
#include "filesys.h"
00199
#include "vs10xx.h"
00200
#include "storage.h"
00201
#include "display.h"
00202
#include "string.h"
00203
#include "ui.h"
00204
#include "mmc.h"
00205
#include "record.h"
00206
00207
00209 #define u_int8 code unsigned char
00210
00211 #define u_int16 code unsigned int
00212
00213
00214
#ifdef VS1003
00215
#include "spec_rew.c"
00216
#else
00217
#include "loud_sa.c"
00218
#endif
00219
00220
00221
00223 #define UI_RETURN_DELAY 150
00224
00226 xdata
playingstatetype playingState =
PS_NORMAL;
00227
00229 unsigned char intlevel = 0;
00230
00233 xdata
unsigned char userInterfaceDelayElapsed = 0;
00234
00236 xdata
uimodetype uiMode =
UI_SPEC;
00237
00238 xdata
unsigned char SPMax=0;
00239
00240
00241
00246 void timer0_interrupt(
void) interrupt 1{
00247
static char displayDelay;
00248
userInterfaceDelayElapsed = 1;
00249
if (++displayDelay==12){
00250 displayDelay = 0;
00251
displayPosition++;
00252
if (
displayPosition>
displayLength+7){
00253
displayPosition = -7;
00254 }
00255 }
00256
if (SP>
SPMax)
SPMax = SP;
00257
00258
00259 }
00260
00261
00262
00263
00265 void LoadPatch(){
00266 ConsoleWrite (
"Loading patch.\r");
00267
for (
temp.
i=0;
temp.
i <
CODELEN;
temp.
i++) {
00268
Mp3WriteRegister(
atab[
temp.
i],
dtab[
temp.
i]>>8,
dtab[
temp.
i]&0xff);
00269 }
00270
Delay(10);
00271 }
00272
00274 void StartPatch()
00275 {
00276
00277
#ifdef VS1003
00278
00279
#else
00280
00281
00282
00283
#endif
00284
}
00285
00286
00287
00288
00290 void ScreenSetPlayTime(){
00291
unsigned int playTime;
00292
unsigned char minutes, seconds;
00293
00294 playTime =
Mp3ReadRegister(
SPI_DECODE_TIME);
00295 minutes = playTime/60;
00296 seconds = playTime%60;
00297
displayTitle[0]=(
'0'+minutes/10);
00298
displayTitle[1]=(
'0'+minutes%10);
00299
displayTitle[2]=(
':');
00300
displayTitle[3]=(
'0'+seconds/10);
00301
displayTitle[4]=(
'0'+seconds%10);
00302
displayTitle[5]=(
' ');
00303
displayTitle[6]=(
' ');
00304
displayTitle[7]=(
' ');
00305
00306
if (seconds&1){
00307
if (
playingState ==
PS_RECORDING){
00308
displayTitle[6]=
'o';
00309 }
else{
00310
displayTitle[6]='\x7e';
00311 }
00312
00313 }
00314
00315
if ((
playingState !=
PS_NORMAL)&&(
playingState !=
PS_RECORDING)){
00316
displayTitle[6]='\xdb';
00317 }
00318
00319
00320
00321 }
00322
00323
00324
00325
00326
00327
00328
00332 void AvailableProcessorTime(){
00333
00337
static xdata
unsigned char volume = 20;
00338
00340
static xdata
unsigned char bass = 0;
00341
00343
static xdata
unsigned char treble = 64;
00344
00346
static xdata
unsigned char reclevel = 50;
00347
00348
unsigned int i;
00349
00350
static bit bassUpdateNeeded;
00351
00355
static unsigned char uiReturnDelay=0;
00356
00357
00358
#if 0
00359
00360
00361
00362
if (RI) {
00363 RI = 0;
00364
00365 i = SBUF;
00366
00367
if (i==
'N'){
00368
playingState =
PS_NEXT_SONG;
00369 }
00370
if (i==
'P'){
00371
playingState =
PS_PREVIOUS_SONG;
00372 }
00373 }
00374
#endif
00375
00376
00377
00378
00379
if (!
userInterfaceDelayElapsed){
00380
return;
00381 }
00382
00383
userInterfaceDelayElapsed = 0;
00384
00385
00386
00387
00388
00389
if (uiReturnDelay == 0){
00390
if ((
uiMode !=
UI_SPEC)&&(
uiMode !=
UI_CUE))
00391
uiMode =
UI_TITLE;
00392
else{
00393 }
00394 }
else{
00395 uiReturnDelay--;
00396 }
00397
00398
00399
00400
#ifndef VS1003
00401
if (
uiMode==
UI_SPEC)
00402
uiMode++;
00403
if (
uiMode==
UI_RECLEVEL)
00404
uiMode++;
00405
#endif
00406
00407
00408
00409
00410
if (
uiMode==
UI_INFO)
00411
uiMode++;
00412
if (
uiMode==
UI_STOP)
00413
uiMode++;
00414
00415
00416
switch(
uiMode){
00417
00418
case UI_TITLE:
00419
00420
displayStyle =
DS_TEXT;
00421
ScreenSetPlayTime();
00422
00423
if (
playingState==
PS_RECORDING){
00424
displayStyle =
DS_PERCENTAGE;
00425 }
00426
00427
break;
00428
00429
case UI_STOP:
00430
displayStyle =
DS_NO_YES;
00431 strcpy (
displayTitle,
"Stop? ");
00432
break;
00433
00434
case UI_CUE:
00435
displayStyle =
DS_RAWTEXT;
00436 strcpy (
displayTitle,
"REW/CUE <- ->");
00437
00438
00439
00440
00441
00442
00443
00444
break;
00445
00446
case UI_VOLUME:
00447
LcdSelectFont(
lcdFont_barchars);
00448
displayStyle =
DS_PERCENTAGE;
00449 strcpy(
displayTitle,
"Volume: ");
00450
displayValue = (100-(volume>>1));
00451
if (
displayValue<0)
displayValue = 0;
00452
break;
00453
00454
case UI_BASS:
00455
LcdSelectFont(
lcdFont_barchars);
00456
displayStyle =
DS_PERCENTAGE;
00457 strcpy(
displayTitle,
"Bass: ");
00458
displayValue = (bass/5)*4;
00459
if (
displayValue<1)
displayValue = 1;
00460
break;
00461
00462
case UI_TREBLE:
00463
LcdSelectFont(
lcdFont_barchars);
00464
displayStyle =
DS_PERCENTAGE;
00465 strcpy(
displayTitle,
"Treble: ");
00466
displayValue = (treble/5)*4;
00467
if (
displayValue<1)
displayValue = 1;
00468
break;
00469
00470
case UI_RECLEVEL:
00471
00472
if (
playingState==
PS_RECORDING){
00473
LcdSelectFont(
lcdFont_barchars);
00474
displayStyle =
DS_PERCENTAGE;
00475 strcpy(
displayTitle,
"RecLevel");
00476
displayValue = (reclevel);
00477
if (reclevel==0){
00478 strcpy(
displayTitle,
"RecLevel <Auto> ");
00479
displayStyle =
DS_RAWTEXT;
00480 }
00481 }
else{
00482
00483
displayStyle =
DS_NO_YES;
00484 strcpy (
displayTitle,
"Record? ");
00485 }
00486
break;
00487
00488
00489
case UI_SPEC:
00490
00491
if (
playingState ==
PS_RECORDING){
00492
uiMode++;
00493 }
00494
00495
LcdSelectFont(
lcdFont_vertical_barchars);
00496
displayStyle =
DS_RAWTEXT;
00497
ScreenSetPlayTime();
00498
00499
00500
Mp3WriteRegister(7, 0x18, 0x04);
00501
00502
00503 {
00504
for (i=0;i<8;i++) {
00505
signed char thisband =
Mp3ReadRegister(6);
00506
00507
00508
00509
00510
00511
00512 thisband &= 63;
00513 thisband >>= 1;
00514 thisband -= 3;
00515
if (i==0) thisband -= 2;
00516
if (i==6) thisband += 1;
00517
if (i==7) thisband += 1;
00518
if (thisband>7) thisband = 7;
00519
if (thisband<0) thisband =
' ';
00520
00521
displayTitle[i+8] = thisband;
00522
00523 }
00524 }
00525
break;
00526
00527 }
00528
00529
00530
00531
00532
if ((
KEY_BUTTON) && (uiReturnDelay <
UI_RETURN_DELAY-20)){
00533
LcdReset();
00534
uiMode++;
00535 uiReturnDelay =
UI_RETURN_DELAY;
00536 }
00537
00538
switch(
uiMode){
00539
00540
case UI_TITLE:
00541
case UI_SPEC:
00542
00543
if (
KEY_FARRIGHT){
00544
playingState =
PS_NEXT_SONG;
00545 }
00546
if (
KEY_FARLEFT){
00547
playingState =
PS_PREVIOUS_SONG;
00548 }
00549
break;
00550
00551
00552
case UI_VOLUME:
00553
00554
if (
KEY_FARLEFT){
00555 uiReturnDelay =
UI_RETURN_DELAY;
00556
if (volume++ == 254) volume = 254;
00557
Mp3SetVolume(volume,volume);
00558 }
00559
00560
if (
KEY_FARRIGHT){
00561 uiReturnDelay =
UI_RETURN_DELAY;
00562
if (volume-- == 0) volume = 0;
00563
Mp3SetVolume(volume,volume);
00564 }
00565
break;
00566
00567
case UI_BASS:
00568
case UI_TREBLE:
00569 bassUpdateNeeded = 0;
00570
00571
00572
00573
if (
uiMode==
UI_BASS){
00574
00575
if (
KEY_FARLEFT){
00576 bassUpdateNeeded = 1;
00577
if (bass-- == 0) bass = 0;
00578 }
00579
if (
KEY_FARRIGHT){
00580 bassUpdateNeeded = 1;
00581
if (bass++ == 127) bass = 127;
00582 }
00583
00584 }
else{
00585
00586
if (
KEY_FARLEFT){
00587 bassUpdateNeeded = 1;
00588
if (treble-- == 0) treble = 0;
00589 }
00590
if (
KEY_FARRIGHT){
00591 bassUpdateNeeded = 1;
00592
if (treble++ == 127) treble = 127;
00593 }
00594
00595 }
00596
00597
00598
if (bassUpdateNeeded){
00599
unsigned int newBassRegister;
00600
00601
00602
00603
00619
00620
00621 newBassRegister = (bass + 23) / 10;
00622
00623
00624
00625 newBassRegister |= (bass>>3)<<4;
00626
00627
00628
00629 newBassRegister |= (((148-treble)>>3)+2)<<8;
00630
00631
00632
00633 newBassRegister |= ((treble>>3)-8)<<12;
00634
00635
00636 uiReturnDelay =
UI_RETURN_DELAY;
00637
00638
if (
Mp3ReadRegister(
SPI_BASS)!=newBassRegister){
00639
Mp3WriteRegister(
SPI_BASS,newBassRegister>>8,newBassRegister&0xff);
00640 }
00641
00642
00643
00644
00645
00646
00647
00648
00649 }
00650
00651
break;
00652
00653
00654
case UI_RECLEVEL:
00655
00656
if (
playingState==
PS_RECORDING){
00657
if (
KEY_FARRIGHT){
00658 uiReturnDelay =
UI_RETURN_DELAY;
00659
if (reclevel++ == 100){
00660 reclevel = 100;
00661 }
00662
Mp3WriteRegister(
SPI_AICTRL1,
00663 ((
int)reclevel*32)>>8,((
int)reclevel*32)&0xff);
00664
SPIPutChar(0);
SPIWait();
00665 }
00666
00667
if (
KEY_FARLEFT){
00668 uiReturnDelay =
UI_RETURN_DELAY;
00669
if (reclevel-- == 0){
00670 reclevel = 0;
00671 }
00672
Mp3WriteRegister(
SPI_AICTRL1,
00673 ((
int)reclevel*32)>>8,((
int)reclevel*32)&0xff);
00674
SPIPutChar(0);
SPIWait();
00675 }
00676 }
else{
00677
00678
if (
KEY_FARRIGHT){
00679
00680
playingState=
PS_RECORDING;
00681 }
00682 }
00683
break;
00684
00685
case UI_STOP:
00686
00687
if (
KEY_FARRIGHT){
00688
playingState =
PS_END_OF_SONG;
00689 }
00690
break;
00691
00692
case UI_CUE:
00693
00694
if (
playingState ==
PS_NORMAL){
00695
if (
KEY_FARRIGHT){
00696 uiReturnDelay =
UI_RETURN_DELAY;
00697
playingState =
PS_CUE;
00698 }
00699
if (
KEY_FARLEFT){
00700 uiReturnDelay =
UI_RETURN_DELAY;
00701
playingState =
PS_REWIND;
00702 }
00703 }
00704
00705
break;
00706
00707
case UI_END_OF_MODES:
00708
uiMode =
UI_TITLE;
00709
break;
00710
00711
00712 }
00713
00714
00715
00716
UpdateDisplay();
00717 }
00718
00719
00720
00724 void PlayCurrentFile(){
00725 xdata
char c, nFragments;
00726
00727
playingState =
PS_NORMAL;
00728
00729
00730
LcdLocateHome();
00731
LcdPutConstantString(
"Opening ");
00732
00733 ConsoleWrite (
"Building file fragment table...");
00734 nFragments =
BuildFragmentTable();
00735 ConsoleWrite(
"\rFragments: ");
00736 ConsolePutUInt(nFragments);
00737
00738
LcdLocateHome();
00739
LcdPutConstantString(
"Playing ");
00740
00741
for (c=0; c<nFragments; c++){
00742
sectorAddress.
l =
fragment[c].
start;
00743 ConsoleWrite (
"\rPlayer: Playing from sector ");
00744 ConsolePutUInt (
sectorAddress.
l);
00745
if (
PlayDiskSectors(
fragment[c].length)!=0){
00746
Mp3WriteRegister(
SPI_MODE,0,
SM_OUTOFWAV);
00747
SendZerosToVS10xx();
00748
return;
00749 }
00750 }
00751
SendZerosToVS10xx();
00752
00753
00754
playingState =
PS_NEXT_SONG;
00755
00756 }
00757
00758
00759
00765 void main(){
00766
00767
unsigned int currentFile;
00768
00769
InitBoard();
00770
00771
00772 ET0 = 1;
00773 EA = 1;
00774 TR0 = 1;
00775
00776
00777
InitDisplay (
DS_STATIC,
" ",
" ",0);
00778
00779 ConsoleWrite (
"\rVLSIPlayer\rStarting up.\r\r");
00780
00781
LcdReset();
00782
LcdPutConstantString (
"Filesys ");
00783
LcdLocateLine2();
00784
LcdPrintGenericResult (
InitFileSystem());
00785
00786
Mp3Reset();
00787
LoadPatch();
00788
StartPatch();
00789
00790
00791
if (
KEY_FARLEFT){
00792
while(
KEY_LEFT)
00793 ;
00794
Record();
00795 }
00796
00797
00798
#ifdef VS1003
00799
uiMode =
UI_SPEC;
00800
#else
00801
uiMode =
UI_TITLE;
00802
#endif
00803
00804
playingState =
PS_NEXT_SONG;
00805 currentFile = 1;
00806
00807
while (1){
00808 ConsoleWrite(
"SPMax: ");ConsolePutHex8(
SPMax);
00809 ConsoleWrite(
"PlayingState: ");ConsolePutHex8(
playingState);
00810
00811
00812
if (
playingState ==
PS_RECORDING){
00813
uiMode =
UI_TITLE;
00814
playingState =
Record();
00815
while (
KEY_BUTTON)
00816 ;
00817 ConsoleWrite(
"\rFinished recording.\r");
00818 currentFile = 1;
00819
playingState ==
PS_NEXT_SONG;
00820 }
00821
00822
if (
OpenFile(currentFile)){
00823 currentFile = 1;
00824
if (
OpenFile(currentFile)){
00825
LcdReset();
00826
LcdPutConstantString(
"No files.");
00827
while(1);
00828 }
00829 }
00830
00831
LcdReset();
00832
LcdPutConstantString(
"File ");
00833
LcdPutUInt(currentFile);
00834
LcdLocateLine2();
00835
for (
temp.
c=0;
temp.
c<8;
temp.
c++){
00836
LcdPutChar(
currentFileName[
temp.
c]);
00837 }
00838
00839
00840
while ((
KEY_BUTTON)||(
KEY_FARLEFT)||(
KEY_FARRIGHT)||
00841 (
KEY_LEFT)||(
KEY_RIGHT))
00842 ;
00843
00844
while (((!
KEY_BUTTON)&&(!
KEY_FARLEFT)&&(!
KEY_FARRIGHT))
00845 &&(
playingState ==
PS_NORMAL))
00846 ;
00847
00848
00849
00850
if (
KEY_FARLEFT) currentFile--;
00851
if (
KEY_FARRIGHT) currentFile++;
00852
if (currentFile==0) currentFile = 1;
00853
00854
if (
KEY_BUTTON ||
00855 (
playingState==
PS_NEXT_SONG) ||
00856 (
playingState==
PS_PREVIOUS_SONG)){
00857
while (
KEY_BUTTON)
00858 ;
00859
00860
PlayCurrentFile();
00861 ConsoleWrite (
"Playing state after playing is: ");
00862 ConsolePutUInt (
playingState);
00863
00864
if (
playingState ==
PS_PREVIOUS_SONG) currentFile--;
00865
if (
playingState ==
PS_NEXT_SONG) currentFile++;
00866
if (currentFile==0) currentFile = 1;
00867
if (
playingState ==
PS_END_OF_SONG)
playingState =
PS_NORMAL;
00868
00869
00870
Mp3SoftReset();
00871
LoadPatch();
00872
StartPatch();
00873
00874
00875
while ((
KEY_BUTTON)||(
KEY_FARLEFT)||(
KEY_FARRIGHT)||
00876 (
KEY_LEFT)||(
KEY_RIGHT))
00877 ;
00878 }
00879
00880
00881 }
00882
00883
00884 }
00885
00886