/* * MP3Player version 1.3 * Last updated: 04-Nov-2004, 17:00 */ #define LCD_LINES 4 #define LCD_CHARS 20 #define LCD_SET_DDRAM 0x80 #define SONG_OFFSET 2 #define PP_OFFSET 6 #define RND_OFFSET 3 #define RPT_OFFSET 12 #define CH_CURSOR '>' #define CH_SPACE ' ' #define MSG_WLC1 " T2NG - NOT ANOTHER" #define MSG_WLC2 " IPOD CLONE !" #define MSG_NOMMC1 " THANH!! " #define MSG_NOMMC2 " Where's My Card? " #define MSG_PLAY "Playing:" #define MSG_PAUSE "[Paused]" #define MSG_RND "" #define MSG_RPT "" #define MSG_BLANK " " #define MP3_PI19 0x01 #define MP3_I2CD 0x02 #define MP3_I2CC 0x04 #define MP3_PR 0x08 #define MP3_PCS 0x10 #define MP3_POR 0x20 #define MP3_SID 0x40 #define MP3_SIC 0x80 #define MMC_CS 0x01 #define MMC_SECTOR_SIZE 512 #define FN_RECORD_LENGTH 13 #define DIR_RECORD_LENGTH 32 #define FAT_ENTRY_LENGTH 2 #define FILENAME_RECORDS 8 #define MAX_FILES 100 #define FAT_ATTR_OFFSET 11 #define FAT_SEQ_OFFSET 0 #define FAT_READONLY 0x01 #define FAT_HIDDEN 0x02 #define FAT_SYSTEM 0x04 #define FAT_VOLUME 0x08 #define FAT_DIRECTORY 0x10 #define FAT_ARCHIVE 0x20 #define FAT_LFN 0x0F #define FAT_HSVD 0x1E #define FAT_LFN_ERASED 0x80 #define FAT_SFN_ERASED 0xE5 #define FAT_LFN_SEQNUM 0x3F #define FAT_EOF 0x00 #define PB_UP 0x01 #define PB_DOWN 0x02 #define PB_LEFT 0x04 #define PB_RIGHT 0x08 #define PB_STOP 0x10 #define PB_PLAY 0x20 #define PB_ALL 0x3F #define PB_DELAY 100000 #define MP3_DELAY 100000 #define MMC_TIMEOUT 80 #define PREV_LIMIT 24 enum MMCResp { MMC_OK, MMC_OKDATA }; enum LCDRegSel { LCD_IR = 0x00, LCD_DR = 0x02 }; enum SongBreak { NO_BREAK, PLAY_THIS, PLAY_NEXT }; enum PlayState { PAUSE, PLAY }; typedef unsigned char byte; volatile byte *MMCPort = (byte *) (0x40000000); volatile byte *MMCControl = (byte *) (0x40000001); volatile byte *Buttons = (byte *) (0x40000004); volatile byte *ButtonsControl = (byte *) (0x40000005); volatile byte *MP3Port = (byte *) (0x40000006); volatile byte *MP3Control = (byte *) (0x40000007); volatile byte *MP3Data = (byte *) (0x40000004); const byte LCD_LINE_ADR[LCD_LINES] = {0x00, 0x40, 0x14, 0x54}; struct BootRecord { byte JumpCommand[3]; char OEMName[8]; int BytesPerSector; int SectorsPerCluster; int ReservedSectors; int NumberOfFATs; int NumberOfRootEntries; int NumberOfMediaSectors; byte Media; int SectorsPerFAT; int SectorsPerTrack; int NumberOfHeads; int NumberOfHiddenSectors; int NumberOfTotalSectors; byte DriveNumber; byte Reserved; byte ExtendedSignature; byte VolumeID[4]; char VolumeLabel[11]; char FileSystem[8]; // Don't need Program Code. Waste of memory; byte Signature1; byte Signature2; }; struct FileRecord { char FileName[FILENAME_RECORDS * FN_RECORD_LENGTH + 1]; int FirstCluster; int Played; }; void initboard(void); void initlcd(void); void initmp3(void); void initmmc(void); void readboot(void); void readfilenames(void); void welcome(void); void userinterface(void); int getnextcluster(int thiscluster); int play(int song); void mp3write(byte data); int randomsong(unsigned int seed, int repeat); int mod(int op1, int op2); void sendcmd(byte command, unsigned int argument, byte crc); void displaysongs(int topsong); void displaycursor(int line); void cls(void); void lcdwritemsg(char *msg, int line, int charoffset); void lcdwrite(byte data, enum LCDRegSel RS); void waitfor(enum MMCResp resp); void readslack(int numbytes); int readnumber(int numbytes); extern byte mmcrw(byte writebyte); extern void lcdwait(void); extern void lcdwritedata(byte data); extern void lcdwritectrl(byte data); extern void delay(int cycles);