home *** CD-ROM | disk | FTP | other *** search
- #include "mcdplayer.h"
-
- char *version = "\0$VER: MCDPlayer " VERSION " (" __DATE__ " " __TIME__ ")";
-
- UBYTE *scsi_data = NULL;
- UBYTE *toc_buf = NULL;
-
- UBYTE *scsi_dev = NULL;
- int scsi_id = 1;
-
- UBYTE buffer[LINE_BUF];
-
- int ActStat = 0; /* 0=No Disk; 1=Playing; 2=Stopped; 3=Paused; 4=Datadisk */
- int ActTitle = 0;
- int ActProg = 0; /* -1=No Prog; 0=Default Prog; 1-3=other Progs */
- int ActProgTitle = 0;
-
- char SetNextTitle = 0;
- char InputTitleStat = 0; /* 0: direkte Titelwahl, 1: Zehnerstelle, 2: Einerstelle */
- int InputTitle = 0;
-
- MSGPORT *mp_ptr;
- IOSTDREQ *io_ptr;
- SCSICMD scsi_cmd;
- UBYTE *scsi_sense;
-
- UBYTE TOC_NumTracks = 0;
- UBYTE TOC_Flags[100]; /* 0=Musik, 1=Daten */
- ULONG TOC_Addr[100];
- char *TOC_Title[100];
- char *TOC_CDTitle;
- char *TOC_CDInterpret;
- char TOC_TitleStrs[4000];
- char TOC_CDID[20];
-
- char WndPosition = 0;
-
- char *SongPath = NULL;
-
- struct timerequest *TimerIO = NULL;
- struct MsgPort *TimerMP = NULL;
- struct MsgPort *BrokerMP = NULL;
- struct DiskObject *DObj=NULL;
- struct Library *CxBase= NULL;
-
- CxObj *broker=NULL, *filter[17], *sender[17], *translate[17];
- struct NewBroker newbroker =
- { NB_VERSION,
- "MCDP",
- "MultiCDPlayer, ©1994 Boris Jakubaschk",
- "Player for audio CDs in a CDROM drive",
- NBU_UNIQUE | NBU_NOTIFY,
- NULL,
- 0, 0, 0 };
- ULONG cxsigflag;
-
-
- int TimerInit()
- {
- if (TimerMP = CreatePort(0,0))
- {
- if (TimerIO = (struct timerequest *) CreateExtIO(TimerMP, sizeof(struct timerequest)))
- {
- if (OpenDevice( TIMERNAME, UNIT_VBLANK, (struct IORequest *)TimerIO, 0L)==NULL)
- {
- return( 1 );
- }
- else
- {
- ErrorMsg("Kann Timer.device nicht öffnen");
- }
- }
- else
- {
- ErrorMsg( "CreateExtIO fehlgeschlagen" );
- }
- }
- else
- {
- ErrorMsg("CreatePort fehlgeschlagen");
- }
- return( 0 );
- }
-
- void TimerExit()
- {
- if (TimerIO)
- {
- CloseDevice((struct IORequest *)TimerIO);
- DeleteExtIO((struct IORequest *)TimerIO);
- };
- if (TimerMP)
- {
- DeletePort(TimerMP);
- };
- }
-
- int DoScsiCmd (UBYTE * data, int datasize, UBYTE * cmd, int cmdsize, UBYTE flags)
- {
- io_ptr->io_Length = sizeof (SCSICMD);
- io_ptr->io_Data = (APTR) & scsi_cmd;
- io_ptr->io_Command = HD_SCSICMD;
-
- scsi_cmd.scsi_Data = (APTR) data;
- scsi_cmd.scsi_Length = datasize;
- scsi_cmd.scsi_SenseActual = 0;
- scsi_cmd.scsi_SenseData = scsi_sense;
- scsi_cmd.scsi_SenseLength = SENSE_LEN;
- scsi_cmd.scsi_Command = cmd;
- scsi_cmd.scsi_CmdLength = cmdsize;
- scsi_cmd.scsi_Flags = flags;
-
- (void) DoIO ((struct IORequest *) io_ptr);
-
- return (io_ptr->io_Error);
- }
-
- char SCMD_Inquiry ( void )
- {
- static SCSICMD6 command =
- {
- SCSI_CMD_INQ,
- PAD,
- PAD,
- PAD,
- 0,
- PAD
- };
- static int err;
-
- command.b4 = MAX_DATA_LEN;
-
- if ((err = DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE))) == 0)
- {
- return ((scsi_data[0] & 0x1F)==0x05);
- }
- return( FALSE );
- }
-
- void SCMD_PlayAudio (int starttrack)
- {
- static SCSICMD12 command =
- {
- SCSI_CMD_PLAYAUDIO12,
- PAD,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- PAD,
- PAD,
- };
-
- int i = 1;
- ULONG Addr;
-
- SetNextTitle = 0;
-
- if (ActProg != -1)
- {
- if (Program[0][ActProg]!=0)
- {
- while ( (i<starttrack) && (Program[i-1][ActProg]!=0) ) i++;
- ActProgTitle = i;
- starttrack = Program[i-1][ActProg];
- }
- else ActProg = -1;
- }
-
- DrawPrgmSymb( (ActProg!=-1)?1:0 );
-
- while( (TOC_Flags[starttrack-1]==1)&&(starttrack<TOC_NumTracks) ) starttrack++;
-
- Addr = TOC_Addr[starttrack-1]+1;
-
- command.b2 = (Addr&0xFF000000)>>24;
- command.b3 = (Addr&0x00FF0000)>>16;
- command.b4 = (Addr&0x0000FF00)>>8;
- command.b5 = (Addr&0x000000FF);
-
- if (ActProg == -1)
- {
- Addr = TOC_Addr[TOC_NumTracks]-TOC_Addr[starttrack-1]-1;
- }
- else Addr = TOC_Addr[starttrack]-TOC_Addr[starttrack-1]-1;
-
- command.b6 = (Addr&0xFF000000)>>24;
- command.b7 = (Addr&0x00FF0000)>>16;
- command.b8 = (Addr&0x0000FF00)>>8;
- command.b9 = (Addr&0x000000FF);
-
- DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE));
- };
-
- void SCMD_PauseResume( void )
- {
- static SCSICMD10 command =
- {
- SCSI_CMD_PAUSERESUME,
- PAD,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- PAD,
- };
-
- command.b8 = (ActStat==1)?0x00:0x01;
-
- DoScsiCmd (0, 0,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE));
- DrawPrgmSymb( (ActStat==1)?3:1 );
- }
-
- void SCMD_Eject( void )
- {
- static SCSICMD6 command =
- {
- SCSI_CMD_SSU,
- 0,
- PAD,
- PAD,
- 0,
- PAD,
- };
-
- int err;
-
- command.b4 = 2;
-
- if ((err = DoScsiCmd (0, 0,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE))) != 0)
- {
- return;
- }
- }
-
- void SCMD_Stop( void )
- {
- static SCSICMD6 command =
- {
- SCSI_CMD_SSU,
- 0,
- PAD,
- PAD,
- 0,
- PAD,
- };
-
- command.b4 = 0;
-
- DoScsiCmd (0, 0,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE));
- DrawPrgmSymb( 0 );
- ActProg = -1;
- SetDispStat();
- }
-
- void SCMD_SetVolume (int vol0, int vol1, int vol2, int vol3)
- {
- static int err, i, j;
- static SCSICMD6 modecommand;
- static struct volmodedata
- {
- UBYTE head[4];
- UBYTE page; /* page code 0x0E */
- UBYTE plength; /* page length */
- UBYTE b2; /* bit 2: Immed, bit 1: SOTC */
- UBYTE b3; /* reserved */
- UBYTE b4; /* reserved */
- UBYTE b5; /* bit 7: APRVal, bit 3-0: format of LBAs / Sec. */
- UWORD bps; /* logical blocks per second audio playback */
- UBYTE out0; /* lower 4 bits: output port 0 channel selection */
- UBYTE vol0; /* output port 0 volume */
- UBYTE out1; /* lower 4 bits: output port 1 channel selection */
- UBYTE vol1; /* output port 1 volume */
- UBYTE out2; /* lower 4 bits: output port 2 channel selection */
- UBYTE vol2; /* output port 2 volume */
- UBYTE out3; /* lower 4 bits: output port 3 channel selection */
- UBYTE vol3; /* output port 3 volume */
- } modedata;
-
- for (i = 0; i < 4; i++)
- modedata.head[i] = 0;
-
- modecommand.opcode = SCSI_CMD_MSE;
- modecommand.b1 = 0;
- modecommand.b2 = 0x0E;
- modecommand.b3 = 0;
- modecommand.b4 = MAX_DATA_LEN;
- modecommand.control = 0;
-
- if ((err = DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) &modecommand, sizeof (modecommand),
- (SCSIF_READ | SCSIF_AUTOSENSE))) != 0)
- return;
-
- for (j = (scsi_data[0]+1), i = scsi_data[3] + 4; i < j; i += scsi_data[i+1] + 2)
- {
- memcpy (&modedata.page, &scsi_data[i], 16);
- }
-
- if (vol0 > -1 || vol1 > -1 || vol2 > -1 || vol3 > -1)
- {
- modedata.page = 0x0e;
- modedata.plength = 0x0e;
-
- if (vol0 >= 0)
- modedata.vol0 = vol0;
- if (vol1 >= 0)
- modedata.vol1 = vol1;
- if (vol2 >= 0)
- modedata.vol2 = vol2;
- if (vol3 >= 0)
- modedata.vol3 = vol3;
-
- modecommand.opcode = SCSI_CMD_MSL;
- modecommand.b1 = 0x10;
- modecommand.b2 = 0;
- modecommand.b3 = 0;
- modecommand.b4 = sizeof (modedata);
- modecommand.control = 0;
-
- if ((err = DoScsiCmd ((UBYTE *) &modedata, sizeof(modedata),
- (UBYTE *) &modecommand, sizeof (modecommand),
- (SCSIF_WRITE | SCSIF_AUTOSENSE))) != 0)
- return;
- }
- }
-
- char *GetNextStr( char *a )
- {
- char *b;
-
- b = a;
- while( *b!='\n' ) b++;
- *b = '\0';
- return( b+1 );
- }
-
- void ShowCDTitle( void )
- {
- int slen;
-
- SetAPen( MainWnd->RPort, 1 );
- RectFill( MainWnd->RPort, 25, 38+offy, 258, 64+offy );
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
- Move( MainWnd->RPort, 25, 50+offy );
- slen = strlen(TOC_CDInterpret);
- Text( MainWnd->RPort, TOC_CDInterpret, (slen>29)? 29:slen );
- Move( MainWnd->RPort, 25, 61+offy );
- slen = strlen(TOC_CDTitle);
- Text( MainWnd->RPort, TOC_CDTitle, (slen>29)? 29:slen );
-
- ActTitle = 0;
- }
-
-
- void SCMD_ReadTOC ( void )
- {
- static SCSICMD10 command =
- {
- SCSI_CMD_READTOC,
- 0,
- PAD, PAD, PAD, PAD,
- 0,
- 0x03, 0x24,
- PAD
- };
-
- int err, tocsize;
- int i;
- UBYTE *tocptr;
- char Buffer[130];
- BPTR FH;
- char *a;
-
- if ((err = DoScsiCmd ((UBYTE *) toc_buf, MAX_TOC_LEN,
- (UBYTE *) & command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE))) == 0)
- {
- SetAPen( MainWnd->RPort, 1 );
- RectFill( MainWnd->RPort, 25, 38+offy, 258, 64+offy );
-
- tocsize = (toc_buf[0] << 8) | toc_buf[1]; /* first word encodes length */
-
- /* TOC_NumTracks = toc_buf[3]; */
- TOC_Addr[2] = 0;
- TOC_NumTracks = 0;
- if (tocsize >= 2) /* TOC Data Length - FTN - LTN */
- tocsize -= 2;
- for (tocptr = &toc_buf[4]; tocptr < (&toc_buf[4] + tocsize); tocptr += 8)
- {
- TOC_Addr[TOC_NumTracks] = (tocptr[4] << 24) | (tocptr[5] << 16) | (tocptr[6] << 8) | (tocptr[7]);
- /* printf ("Track number: %d ", tocptr[2]); */
- TOC_Flags[TOC_NumTracks] = (tocptr[1] & 0x04) ? 1 : 0;
- TOC_NumTracks++;
- }
- TOC_NumTracks--;
-
- if (TOC_NumTracks<=20) RectFill( MainWnd->RPort, 165-7*(20-TOC_NumTracks), 65+offy, 190, 72+offy );
-
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
-
- sprintf(Buffer, "%02d", TOC_Addr[TOC_NumTracks]/75/60 );
- Move( MainWnd->RPort, 212, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- sprintf(Buffer, "%02d", (TOC_Addr[TOC_NumTracks]/75)%60 );
- Move( MainWnd->RPort, 231, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- sprintf( TOC_CDID, "ID%02d%06X%06X", TOC_NumTracks, TOC_Addr[2], TOC_Addr[TOC_NumTracks] );
-
- sprintf( Buffer, SongPath );
- AddPart( Buffer, TOC_CDID, 130 );
-
- if (FH = Open( Buffer, MODE_OLDFILE ))
- {
- Read( FH, TOC_TitleStrs, 4000 );
- Close( FH );
- a = TOC_TitleStrs;
- TOC_CDInterpret = a;
- a = GetNextStr( a );
- TOC_CDTitle = a;
- for (i=0; i<TOC_NumTracks; i++)
- {
- a = GetNextStr( a );
- TOC_Title[i] = a;
- };
- a = GetNextStr( a );
- }
- else
- {
- a = TOC_TitleStrs;
- strcpy( a, "<unbekannte CD>" );
- TOC_CDTitle = a;
- a += strlen( a ) + 1;
- strcpy( a, TOC_CDID );
- TOC_CDInterpret = a;
- a += strlen( a ) + 1;
- for (i=0; i<TOC_NumTracks; i++)
- {
- strcpy( a, "<unbekannter Titel>" );
- TOC_Title[i] = a;
- a += strlen( a ) + 1;
- };
- };
- ShowCDTitle();
- GetProgram();
- if (Program[0][0]==0) ActProg = -1;
- }
- }
-
- void SCMD_Jump( int blocks )
- {
- static SCSICMD10 command1 =
- {
- SCSI_CMD_READSUBCHANNEL,
- 0,
- 0x40,
- 0,
- PAD,
- PAD,
- 0,
- 0,0,
- PAD
- };
-
- static SCSICMD12 command2 =
- {
- SCSI_CMD_PLAYAUDIO12,
- PAD,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- PAD,
- PAD,
- };
-
- int err;
- int addr;
-
- command1.b2 = 0x40;
- command1.b3 = 1;
- command1.b6 = 0;
-
- command1.b7 = 255;
- command1.b8 = 255;
-
- if ((err = DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) &command1, sizeof (command1),
- (SCSIF_READ | SCSIF_AUTOSENSE))) == 0)
- {
- addr = (scsi_data[8] << 24) | (scsi_data[9] << 16) | (scsi_data[10] << 8) | (scsi_data[11]);
- addr += blocks;
-
- if ((addr>=TOC_Addr[ActTitle-1])&&(addr<TOC_Addr[ActTitle]))
- {
- command2.b2 = (addr&0xFF000000)>>24;
- command2.b3 = (addr&0x00FF0000)>>16;
- command2.b4 = (addr&0x0000FF00)>>8;
- command2.b5 = (addr&0x000000FF);
-
- if (ActProg == -1)
- {
- addr = TOC_Addr[TOC_NumTracks]-TOC_Addr[ActTitle-1]-1;
- }
- else addr = TOC_Addr[ActTitle]-TOC_Addr[ActTitle-1]-1;
-
- command2.b6 = (addr&0xFF000000)>>24;
- command2.b7 = (addr&0x00FF0000)>>16;
- command2.b8 = (addr&0x0000FF00)>>8;
- command2.b9 = (addr&0x000000FF);
-
- DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) & command2, sizeof (command2),
- (SCSIF_READ | SCSIF_AUTOSENSE));
- }
- }
- }
-
- void SCMD_ReadTitleTime( int settimer )
- {
- static SCSICMD10 command =
- {
- SCSI_CMD_READSUBCHANNEL,
- 0,
- 0x40,
- 0,
- PAD,
- PAD,
- 0,
- 0,0,
- PAD
- };
-
- int err;
- int microsleft = 950000;
- int addr;
- int slen;
- char Buffer[20];
-
- if (SetNextTitle == 1)
- {
- if (Program[ActProgTitle][ActProg]) SCMD_PlayAudio( ActProgTitle+1 );
- SetNextTitle = 0;
- };
-
- command.b2 = 0x40;
- command.b3 = 1;
- command.b6 = 0;
-
- command.b7 = 255;
- command.b8 = 255;
-
- if ((err = DoScsiCmd ((UBYTE *) scsi_data, MAX_DATA_LEN,
- (UBYTE *) &command, sizeof (command),
- (SCSIF_READ | SCSIF_AUTOSENSE))) != 0)
- {
- if (ActStat!=0)
- {
- ActStat=0;
- CleanMainWnd();
- };
- }
- else if ((scsi_data[1] == 0x11) || (scsi_data[1] == 0x12))
- {
- if (ActStat==0)
- {
- SCMD_ReadTOC();
- };
- if (scsi_data[1]==0x11)
- {
- if (ActStat!=1)
- {
- DrawPlaySymb( 1 );
- DrawPrgmSymb( (ActProg!=-1)?1:0 );
- SetDispStat();
- };
- ActStat=1;
- }
- else
- {
- if (ActStat!=3)
- {
- DrawPlaySymb( 3 );
- DrawPrgmSymb( (ActProg!=-1)?1:0 );
- SetDispStat();
- };
- ActStat=3;
- };
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
-
- if (scsi_data[6]!=ActTitle)
- {
- ActTitle = scsi_data[6];
- InputTitleStat = 0;
- if (ActProg==-1) ActProgTitle = ActTitle;
- sprintf(Buffer, "%02d", ActTitle);
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- SetAPen( MainWnd->RPort, 1 );
- RectFill( MainWnd->RPort, 25, 52+offy, 258, 64+offy );
- SetAPen( MainWnd->RPort, 2 );
- Move( MainWnd->RPort, 25, 61+offy );
- slen = strlen(TOC_Title[ActTitle-1]);
- Text( MainWnd->RPort, TOC_Title[ActTitle-1], (slen>29)? 29 : slen );
- SetDispStat();
- SetAPen( MainWnd->RPort, 2 );
- };
-
- sprintf(Buffer, "%02d", scsi_data[7]);
- Move( MainWnd->RPort, 52, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- addr = (scsi_data[12] << 24) | (scsi_data[13] << 16) | (scsi_data[14] << 8) | (scsi_data[15]);
- sprintf(Buffer, "%02d", addr/75/60 );
- Move( MainWnd->RPort, 80, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- sprintf(Buffer, "%02d", (addr/75)%60 );
- Move( MainWnd->RPort, 99, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- microsleft = (ActStat==1)?((75 - addr%75)*13333 + 1000):999000;
-
- addr = (scsi_data[8] << 24) | (scsi_data[9] << 16) | (scsi_data[10] << 8) | (scsi_data[11]);
- sprintf(Buffer, "%02d", addr/75/60 );
- Move( MainWnd->RPort, 168, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- sprintf(Buffer, "%02d", (addr/75)%60 );
- Move( MainWnd->RPort, 187, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- addr = TOC_Addr[scsi_data[6]]-addr;
- if ((addr<80) && (ActProg!=-1))
- {
- microsleft = ((addr<75)?addr:74)*13333 + 100;
- SetNextTitle = 1;
- };
- sprintf(Buffer, "%02d", addr/75/60 );
- Move( MainWnd->RPort, 124, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- sprintf(Buffer, "%02d", (addr/75)%60 );
- Move( MainWnd->RPort, 143, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
- }
- else if (ActStat != 2)
- {
- if (ActStat==0)
- SCMD_ReadTOC();
- if ((ActStat==1)&&(ActProg!=-1)&&(Program[ActProgTitle][ActProg]!=0))
- {
- SCMD_PlayAudio( ActProgTitle+1 );
- }
- else
- {
- ActTitle = 0;
- InputTitleStat = 0;
- ActProgTitle = 0;
- DrawPlaySymb( 0 );
- SetDispStat();
- DrawPrgmSymb( (ActProg!=-1)?1:0 );
- SetBPen( MainWnd->RPort, 1 );
- SetAPen( MainWnd->RPort, 1 );
- RectFill( MainWnd->RPort, 25, 52+offy, 258, 64+offy );
- SetAPen( MainWnd->RPort, 2 );
- Move( MainWnd->RPort, 25, 61+offy );
- slen = strlen(TOC_CDTitle);
- Text( MainWnd->RPort, TOC_CDTitle, (slen>29)?29:slen );
-
- Buffer[0]='0';
- Buffer[1]='0';
-
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 52, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 80, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 99, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 168, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 187, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 124, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
-
- Move( MainWnd->RPort, 143, 37+offy );
- Text( MainWnd->RPort, Buffer, 2 );
- };
- ActStat = 2;
- };
- if (settimer)
- {
- TimerIO->tr_node.io_Command = TR_ADDREQUEST;
- TimerIO->tr_time.tv_secs = 0;
- TimerIO->tr_time.tv_micro = microsleft;
- SendIO((struct IORequest *)TimerIO);
- };
- }
-
- int SetDispStat( void )
- {
- char DispStat[20];
- int i;
-
- for (i=0; i<20; i++) DispStat[i] = 0;
- if (ActProg==-1)
- {
- for (i=ActTitle; (i<=TOC_NumTracks) && (i<20); i++)
- DispStat[i-1] = 1;
- }
- else
- {
- for (i=ActProgTitle; Program[i-1][ActProg]!=0; i++)
- {
- if (Program[i-1][ActProg]<19)
- {
- DispStat[Program[i-1][ActProg]-1] = 1;
- }
- else DispStat[19]=1;
- }
- }
- for (i=0; i<20; i++)
- {
- SetAPen( MainWnd->RPort, 1+DispStat[i]*2 );
- Move( MainWnd->RPort, 25+7*i, 65+offy );
- Draw( MainWnd->RPort, 30+7*i, 65+offy );
- Move( MainWnd->RPort, 25+7*i, 71+offy );
- Draw( MainWnd->RPort, 30+7*i, 71+offy );
- };
- }
-
-
- void SCSI_Exit( void )
- {
- if (io_ptr)
- {
- CloseDevice ((struct IORequest *) io_ptr);
- DeleteStdIO (io_ptr);
- }
- if (mp_ptr)
- DeletePort (mp_ptr);
- if (scsi_sense)
- FreeMem (scsi_sense, SENSE_LEN);
-
- if (toc_buf)
- FreeMem (toc_buf, MAX_TOC_LEN);
-
- if (scsi_data)
- FreeMem (scsi_data, MAX_DATA_LEN);
- }
-
- char SCSI_Init (void)
- {
- if ((scsi_data = (UBYTE *) AllocMem (MAX_DATA_LEN, MEMF_CHIP | MEMF_CLEAR)) == NULL)
- {
- ErrorMsg( "Speicheranforderung fehlgeschlagen" );
- return FALSE;
- }
-
- if ((toc_buf = (UBYTE *) AllocMem (MAX_TOC_LEN, MEMF_CHIP)) == NULL)
- {
- ErrorMsg( "Speicheranforderung fehlgeschlagen" );
- return FALSE;
- }
-
- if ((scsi_sense = (UBYTE *) AllocMem (SENSE_LEN, MEMF_CHIP || MEMF_CLEAR)) == NULL)
- {
- ErrorMsg( "Speicheranforderung fehlgeschlagen" );
- return FALSE;
- }
- if ((mp_ptr = (MSGPORT *) CreatePort (NULL, 0)) == NULL)
- {
- ErrorMsg( "CreatePort fehlgeschlagen" );
- return FALSE;
- }
- if ((io_ptr = (IOSTDREQ *) CreateStdIO (mp_ptr)) == NULL)
- {
- ErrorMsg( "CreateStdIO fehlgeschlagen" );
- return FALSE;
- }
- if (OpenDevice (scsi_dev, scsi_id, (struct IORequest *) io_ptr, 0) != 0)
- {
- ErrorMsg( "Kann SCSI-Device nicht öffnen!\n- Falscher Devicename?\n-Falsche SCSI-ID?" );
- return FALSE;
- }
- return TRUE;
- }
-
- int MakeCxObj( CxObj *broker, int nr, char *FiltStr )
- {
- if (filter[nr] = CxFilter( FiltStr ))
- {
- AttachCxObj(broker, filter[nr]);
- if (sender[nr] = CxSender(BrokerMP, 1L))
- {
- AttachCxObj(filter[nr], sender[nr] );
- if (translate[nr] = CxTranslate(NULL))
- {
- AttachCxObj(filter[nr], translate[nr]);
- return( CxObjError( filter[nr] ) );
- }
- }
- }
- return( 1 );
- }
-
- int GetToolTypes(int argc, char **ttarray)
- {
- int err = 0;
-
- if ( ! ( CxBase = OpenLibrary( "commodities.library", 37L )))
- return( 3L );
-
- scsi_dev = ArgString( ttarray, "SCSI_DEV", "scsi.device" );
- scsi_id = ArgInt( ttarray, "SCSI_ID", 1 );
- SongPath = ArgString( ttarray, "SONGPATH", "" );
- WndPosition = ArgInt( ttarray, "WND_POS", 0 );
- strcpy( FontName, ArgString( ttarray, "FONTNAME", "MCDP_DOT.font" ));
-
- if (BrokerMP = CreateMsgPort())
- {
- newbroker.nb_Port = BrokerMP;
- cxsigflag = 1L << BrokerMP->mp_SigBit;
- newbroker.nb_Pri = (BYTE)ArgInt(ttarray, "CX_PRIORITY", 0);
- /* hotkey = ArgString(ttarray, "CX_POPKEY", "rawkey control lalt <");
- PopUp = ArgString(ttarray, "CX_POPUP", "Yes"); */
- if (broker = CxBroker(&newbroker, NULL))
- {
- err+= MakeCxObj( broker, 0, "control lalt numericpad 0");
- err+= MakeCxObj( broker, 1, "control lalt numericpad 1");
- err+= MakeCxObj( broker, 2, "control lalt numericpad 2");
- err+= MakeCxObj( broker, 3, "control lalt numericpad 3");
- err+= MakeCxObj( broker, 4, "control lalt numericpad 4");
- err+= MakeCxObj( broker, 5, "control lalt numericpad 5");
- err+= MakeCxObj( broker, 6, "control lalt numericpad 6");
- err+= MakeCxObj( broker, 7, "control lalt numericpad 7");
- err+= MakeCxObj( broker, 8, "control lalt numericpad 8");
- err+= MakeCxObj( broker, 9, "control lalt numericpad 9");
- err+= MakeCxObj( broker, 10, "control lalt numericpad .");
- err+= MakeCxObj( broker, 11, "control lalt shift numericpad enter");
- err+= MakeCxObj( broker, 12, "control lalt numericpad /");
- err+= MakeCxObj( broker, 13, "control lalt numericpad *");
- err+= MakeCxObj( broker, 14, "control lalt numericpad -upstroke -");
- err+= MakeCxObj( broker, 15, "control lalt numericpad +");
- err+= MakeCxObj( broker, 16, "control lalt numericpad enter");
- if (err==0)
- {
- ActivateCxObj(broker, 1L);
- return( 0L );
- }
- }
- }
- ErrorMsg( "Couldn't setup Commodity" );
- return( 2L );
- }
-
- void CleanUp( void )
- {
- CxMsg *msg;
-
- if ( DObj ) FreeDiskObject( DObj );
- if ( broker ) DeleteCxObjAll(broker);
- if ( BrokerMP )
- {
- while (msg = (CxMsg *)GetMsg(BrokerMP))
- ReplyMsg((struct Message *)msg);
- DeletePort( BrokerMP );
- };
- if ( CxBase ) CloseLibrary( CxBase );
- }
-
- ProcessCxMsg( CxMsg *msg )
- {
- ULONG msgid, msgtype;
- int nr;
-
- msgid = CxMsgID( msg );
- msgtype = CxMsgType( msg );
-
- switch(msgtype)
- {
- case CXM_IEVENT:
- if (msgid == 1L)
- {
- nr = 0;
- switch (((struct InputEvent *)CxMsgData(msg))->ie_Code)
- {
- case 67:
- if (ActStat!=1) SCMD_PlayAudio( 1 );
- break;
- case 60:
- SCMD_Stop();
- break;
- case 74:
- if (ActStat==1) SCMD_PlayAudio( ActProgTitle-1 );
- break;
- case 94:
- if (ActStat==1) SCMD_PlayAudio( ActProgTitle+1 );
- break;
- case 93:
- ActProg=-1;
- DrawPrgmSymb( 0 );
- InputTitleStat = 1;
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, "__", 2 );
- break;
- case 15:
- nr = 10;
- break;
- case 29:
- nr = 1;
- break;
- case 30:
- nr = 2;
- break;
- case 31:
- nr = 3;
- break;
- case 45:
- nr = 4;
- break;
- case 46:
- nr = 5;
- break;
- case 47:
- nr = 6;
- break;
- case 61:
- nr = 7;
- break;
- case 62:
- nr = 8;
- break;
- case 63:
- nr = 9;
- break;
- case 92:
- SCMD_Eject();
- break;
- }
- if (nr!=0)
- {
- switch( InputTitleStat )
- {
- char a;
- case 0:
- SCMD_PlayAudio( nr );
- break;
- case 1:
- if (nr < 10)
- {
- InputTitle = nr*10;
- }
- else InputTitle = 0;
- a = (InputTitle/10)+48;
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, &a, 1 );
- InputTitleStat = 2;
- break;
- case 2:
- if (nr < 10)
- {
- InputTitle += nr;
- };
- InputTitleStat = 0;
- SCMD_PlayAudio( InputTitle );
- break;
- }
- }
- };
- break;
- case CXM_COMMAND:
- switch(msgid)
- {
- case CXCMD_DISABLE:
- ActivateCxObj(broker, 0L);
- break;
- case CXCMD_ENABLE:
- ActivateCxObj(broker, 1L);
- break;
- case CXCMD_DISAPPEAR:
- break;
- case CXCMD_APPEAR:
- break;
- case CXCMD_UNIQUE:
- break;
- case CXCMD_KILL:
- Wait( 1<<TimerMP->mp_SigBit );
- GetMsg(TimerMP);
- SCSI_Exit();
- TimerExit();
- CleanUp();
- CloseMainWnd();
- exit(0);
- break;
- };
- break;
- };
- ReplyMsg((struct Message *)msg);
- }
-
- wbmain(struct WBStartup *WBS)
- {
- struct WBArg *WA;
- BPTR DL;
- char **tt;
-
- WA = &WBS->sm_ArgList[WBS->sm_NumArgs-1];
- DL = CurrentDir( WA->wa_Lock );
- if (DObj=(struct DiskObject *)GetDiskObject(WA->wa_Name))
- {
- CurrentDir( DL );
- tt = DObj->do_ToolTypes;
- commonmain(0, tt);
- };
- }
-
- main(int argc, char **argv)
- {
- commonmain(argc, argv);
- }
-
- commonmain (int argc, char **argv)
- {
- ULONG GClass;
- USHORT GCode;
- UWORD GQual;
- ULONG GTimeS;
- ULONG GTimeM;
- struct Gadget *GList = 0l;
- WORD GMouseY;
- ULONG Signal;
- struct IntuiMessage *msg;
- CxMsg *cxmsg;
-
- int j = 0, i = 0;
- int returnvalue = 0;
- int RefreshTimer = 8;
-
- GetToolTypes(argc, argv);
-
- if (SCSI_Init() && TimerInit())
- {
- if (OpenMainWnd(WndPosition)==0)
- {
- SCMD_ReadTitleTime(1);
- for(;;)
- {
- Signal = Wait( (1<<MainWnd->UserPort->mp_SigBit)|(1<<TimerMP->mp_SigBit)|cxsigflag );
- if (Signal & (1<<TimerMP->mp_SigBit))
- {
- GetMsg(TimerMP);
- SCMD_ReadTitleTime(1);
- };
- if (Signal & cxsigflag)
- {
- while ( cxmsg = (CxMsg *)GetMsg(BrokerMP))
- ProcessCxMsg( cxmsg );
- };
- if (Signal & (1<<MainWnd->UserPort->mp_SigBit))
- {
- while ( msg = (struct IntuiMessage *) GetMsg( MainWnd->UserPort ) )
- {
- GClass = msg->Class;
- GCode = msg->Code;
- GQual = msg->Qualifier;
- if (GClass & (GADGETDOWN | GADGETUP | MOUSEMOVE) )
- GList = (struct Gadget *) msg->IAddress;
- GMouseY = msg->MouseY;
- GTimeS = msg->Seconds;
- GTimeM = msg->Micros;
- ReplyMsg(msg);
-
- switch (GClass)
- {
- case IDCMP_CLOSEWINDOW :
- Wait( 1<<TimerMP->mp_SigBit );
- GetMsg(TimerMP);
- SCSI_Exit();
- TimerExit();
- CleanUp();
- CloseMainWnd();
- exit(0);
- break;
- case IDCMP_GADGETUP :
- switch (GList->GadgetID)
- {
- case 19: ActProg=-1;
- DrawPrgmSymb( 0 );
- InputTitleStat = 1;
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, "__", 2 );
- break;
- case 20: TitleList();
- ShowCDTitle();
- break;
- case 21: ProgList();
- break;
- case 22: if (ActProg==-1)
- {
- ActProg = 0;
- DrawPrgmSymb( 1 );
- }
- break;
- case 23: if (ActStat==3)
- {
- SCMD_PauseResume();
- }
- else if (ActStat!=1) SCMD_PlayAudio( 1 );
- break;
- case 24: SCMD_PauseResume();
- break;
- case 25: SCMD_Stop();
- break;
- case 26: if (ActStat==1) SCMD_PlayAudio( ActProgTitle-1 );
- break;
- case 27: if (ActStat==1) SCMD_PlayAudio( ActProgTitle+1 );
- break;
- case 28: if (ActStat==1) SCMD_Jump( -750 );
- break;
- case 29: if (ActStat==1) SCMD_Jump( 750 );
- break;
- case 30: SCMD_Eject();
- break;
- default: if ((ActProg==-1)&&(GList->GadgetID < 19))
- {
- switch( InputTitleStat )
- {
- char a;
- case 0:
- SCMD_PlayAudio( GList->GadgetID+1 );
- break;
- case 1:
- if (GList->GadgetID < 9)
- {
- InputTitle = (GList->GadgetID+1)*10;
- }
- else InputTitle = 0;
- a = (InputTitle/10)+48;
- SetAPen( MainWnd->RPort, 2 );
- SetBPen( MainWnd->RPort, 1 );
- Move( MainWnd->RPort, 25, 37+offy );
- Text( MainWnd->RPort, &a, 1 );
- InputTitleStat = 2;
- break;
- case 2:
- if (GList->GadgetID < 9)
- {
- InputTitle += GList->GadgetID+1;
- };
- InputTitleStat = 0;
- SCMD_PlayAudio( InputTitle );
- break;
- }
- }
- else if ((ActProg!=-1)&&(GList->GadgetID < 8))
- {
- ActProg = GList->GadgetID + 1;
- }
- break;
- };
- SCMD_ReadTitleTime(0);
- RefreshTimer = 8;
- break;
- };
- };
- };
- };
- };
- }
- SCSI_Exit();
- TimerExit();
- CleanUp();
- CloseMainWnd();
- exit( 0 );
- }
-