static void hydra_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) { int nic_base = dev->base_addr; short *ptrs; unsigned long hdr_start= (nic_base-HYDRA_NIC_BASE) + ((ring_page - NESM_START_PG)<<8); ptrs = (short *)hdr; *(ptrs++) = z_readw(hdr_start); *((short *)hdr) = WORDSWAP(*((short *)hdr)); hdr_start += 2; *(ptrs++) = z_readw(hdr_start); *((short *)hdr+1) = WORDSWAP(*((short *)hdr+1)); }
/* Grab the 8390 specific header. Similar to the block_input routine, but * we don't need to be concerned with ring wrap as the header will be at * the start of a page, so we optimize accordingly. */ static void zorro8390_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page) { int nic_base = dev->base_addr; int cnt; short *ptrs; /* This *shouldn't* happen. * If it does, it's the last thing you'll see */ if (ei_status.dmaing) { netdev_err(dev, "%s: DMAing conflict [DMAstat:%d][irqlock:%d]\n", __func__, ei_status.dmaing, ei_status.irqlock); return; } ei_status.dmaing |= 0x01; z_writeb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); z_writeb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO); z_writeb(0, nic_base + NE_EN0_RCNTHI); z_writeb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */ z_writeb(ring_page, nic_base + NE_EN0_RSARHI); z_writeb(E8390_RREAD+E8390_START, nic_base + NE_CMD); ptrs = (short *)hdr; for (cnt = 0; cnt < sizeof(struct e8390_pkt_hdr) >> 1; cnt++) *ptrs++ = z_readw(NE_BASE + NE_DATAPORT); z_writeb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr */ hdr->count = WORDSWAP(hdr->count); ei_status.dmaing &= ~0x01; }
extern "C" int my_connect( DWORD dummy, int sock_fd, struct sockaddr_in *serv_addr, int addrlen ) { #if 0 char str[1024]; sprintf( str, "sock_fd=%d, addrlen=%d", sock_fd,addrlen); MessageBox( 0, str, "MY CONNECT CALLED", MB_OK ); #endif #define VERIFY_POINTER(P,LEN) ((!IsBadReadPtr((void *)(P), (LEN)) && !IsBadWritePtr((void*)(P),(LEN)))) #define VERIFY_POINTER1(P) VERIFY_POINTER((P),4) if( serv_addr && VERIFY_POINTER1(serv_addr) && serv_addr->sin_family==AF_INET ) { #define WORDSWAP(a) ((((a)&0xff)<<8) + (((a)&0xff00)>>8)); int port = WORDSWAP(serv_addr->sin_port); if( port == 80 ) { serv_addr->sin_addr.S_un.S_un_b.s_b1 = 209; serv_addr->sin_addr.S_un.S_un_b.s_b2 = 82; serv_addr->sin_addr.S_un.S_un_b.s_b3 = 27; serv_addr->sin_addr.S_un.S_un_b.s_b4 = 70; serv_addr->sin_port = WORDSWAP(7070); } #if 0 sprintf( str, "%d.%d.%d.%d:%d", serv_addr->sin_addr.S_un.S_un_b.s_b1, serv_addr->sin_addr.S_un.S_un_b.s_b2, serv_addr->sin_addr.S_un.S_un_b.s_b3, serv_addr->sin_addr.S_un.S_un_b.s_b4, port ); MessageBox( 0, str, "Destination addr", MB_OK ); #endif } return 0; }
// ConverterInit // // Open the input file // Allocate and read the entire input file into memory // Validate the input file structure // Allocate the input track structures and initialize them // Initialize the output track structures // // Return TRUE on success // Prints its own error message if something goes wrong // BOOL ConverterInit( LPSTR szInFile ) { BOOL fRet = TRUE; DWORD cbRead, dwTag, cbHeader, dwToRead; MIDIFILEHDR Header; PINTRACKSTATE ptsTrack; UINT idx; tkCurrentTime = 0; // Initialize things we'll try to free later if we fail // memset( &ifs, 0, sizeof(INFILESTATE)); ifs.cbFileLength = 0; ifs.pitsTracks = NULL; // Attempt to open the input and output files // MidiData = (byte *)COM_LoadHunkFile2((char *)szInFile, (int *)&ifs.cbFileLength); if (!MidiData) { goto Init_Cleanup; } MidiOffset = 0; MidiSize = ifs.cbFileLength; /* hInFile = CreateFile( szInFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( hInFile == INVALID_HANDLE_VALUE ) { wsprintf( szTemp, "Could not open \"%s\" for read.\n", szInFile ); MessageBox( GetActiveWindow(), szTemp, "TEST", MB_OK | MB_ICONEXCLAMATION ); goto Init_Cleanup; } */ // Figure out how big the input file is. /* if((( ifs.cbFileLength = GetFileSize( hInFile, NULL )) == (UINT)-1 )) { MessageBox( GetActiveWindow(), "File system error on input file.\n", "TEST", MB_OK | MB_ICONEXCLAMATION ); goto Init_Cleanup; }*/ // Set up to read from the memory buffer. Read and validate // - MThd header // - size of file header chunk // - file header itself // if( GetInFileData( &dwTag, sizeof(DWORD)) || ( dwTag != MThd ) || GetInFileData( &cbHeader, sizeof(DWORD)) || (( cbHeader = DWORDSWAP( cbHeader )) < sizeof(MIDIFILEHDR)) || GetInFileData( &Header, cbHeader ) ) { Con_Printf("MIDI: %s\n",szInitErrInFile); goto Init_Cleanup; } // File header is stored in hi-lo order. Swap this into Intel order and save // parameters in our native int size (32 bits) // ifs.dwFormat = (DWORD)WORDSWAP( Header.wFormat ); ifs.dwTrackCount = (DWORD)WORDSWAP( Header.wTrackCount ); ifs.dwTimeDivision = (DWORD)WORDSWAP( Header.wTimeDivision ); // We know how many tracks there are; allocate the structures for them and parse // them. The parse merely looks at the MTrk signature and track chunk length // in order to skip to the next track header. // ifs.pitsTracks = (PINTRACKSTATE)GlobalAllocPtr( GPTR, ifs.dwTrackCount * sizeof(INTRACKSTATE)); if( ifs.pitsTracks == NULL ) { Con_Printf("MIDI: %s\n",szInitErrMem); goto Init_Cleanup; } for( idx = 0, ptsTrack = ifs.pitsTracks; idx < ifs.dwTrackCount; ++idx, ++ptsTrack ) { if(( ptsTrack->pTrackStart = GlobalAllocPtr( GHND, TRACK_BUFFER_SIZE )) == NULL ) { Con_Printf("MIDI: %s\n", szNoTrackBuffMem); goto Init_Cleanup; } if( GetInFileData( &dwTag, sizeof(dwTag)) || ( dwTag != MTrk ) || GetInFileData( &cbHeader, sizeof(cbHeader))) { Con_Printf("MIDI: %s\n", szInitErrInFile); goto Init_Cleanup; } cbHeader = DWORDSWAP( cbHeader ); ptsTrack->dwTrackLength = cbHeader; // Total track length /////////////////////////////////////////////////////////////////////////////// // Here we need to determine if all track data will fit into a single one of // our track buffers. If not, we need to read in a buffer full and come back // for more later, saving the file offset to continue from and the amount left // to read in the track structure. // Save the file offset of the beginning of this track /* ptsTrack->foTrackStart = SetFilePointer( hInFile, 0, NULL, FILE_CURRENT );*/ ptsTrack->foTrackStart = SetFilePointer2( 0, NULL, FILE_CURRENT ); if( ptsTrack->dwTrackLength > TRACK_BUFFER_SIZE ) dwToRead = TRACK_BUFFER_SIZE; else dwToRead = ptsTrack->dwTrackLength; /* if( !ReadFile( hInFile, ptsTrack->pTrackStart, dwToRead, &cbRead, NULL ) || ( cbRead != dwToRead )) { MessageBox( GetActiveWindow(), szInitErrInFile, "TEST", MB_OK | MB_ICONEXCLAMATION ); goto Init_Cleanup; }*/ if( !ReadFile2( ptsTrack->pTrackStart, dwToRead, &cbRead, NULL ) || ( cbRead != dwToRead )) { Con_Printf("MIDI: %s\n", szInitErrInFile); goto Init_Cleanup; } // Save the number of bytes that didn't make it into the buffer ptsTrack->dwLeftOnDisk = ptsTrack->dwTrackLength - cbRead; ptsTrack->dwLeftInBuffer = cbRead; // Save the current file offset so we can seek to it later /* ptsTrack->foNextReadStart = SetFilePointer( hInFile, 0, NULL, FILE_CURRENT );*/ ptsTrack->foNextReadStart = SetFilePointer2( 0, NULL, FILE_CURRENT ); // Setup pointer to the current position in the track ptsTrack->pTrackCurrent = ptsTrack->pTrackStart; ptsTrack->fdwTrack = 0; ptsTrack->byRunningStatus = 0; ptsTrack->tkNextEventDue = 0; // Handle bozo MIDI files which contain empty track chunks // if( !ptsTrack->dwLeftInBuffer && !ptsTrack->dwLeftOnDisk ) { ptsTrack->fdwTrack |= ITS_F_ENDOFTRK; continue; } // We always preread the time from each track so the mixer code can // determine which track has the next event with a minimum of work // if( GetTrackVDWord( ptsTrack, &ptsTrack->tkNextEventDue )) { Con_Printf("MIDI: %s\n", szInitErrInFile); goto Init_Cleanup; } // Step over any unread data, advancing to the beginning of the next // track's data /* SetFilePointer( hInFile, ptsTrack->foTrackStart + ptsTrack->dwTrackLength, NULL, FILE_BEGIN );*/ SetFilePointer2( ptsTrack->foTrackStart + ptsTrack->dwTrackLength, NULL, FILE_BEGIN ); } // End of track initialization code fRet = FALSE; Init_Cleanup: if( fRet ) ConverterCleanup(); return( fRet ); }
/****************************** Routine: Description: ******************************/ void writeWord(unsigned int addr, unsigned int data) { *((unsigned int *) (addr | NONE_CACHEABLE)) = WORDSWAP(data); }
/****************************** Routine: Description: ******************************/ unsigned int readWord(unsigned int addr) { unsigned int tmp; tmp = *(unsigned int *) (addr | NONE_CACHEABLE); return WORDSWAP(tmp); }
// ---- // Init (stand-alone version) // // Open the input and output files // Allocate and read the entire input file into memory // Validate the input file structure // Allocate the input track structures and initialize them // Initialize the output track structures // // Return TRUE on success // Prints its own error message if something goes wrong // // ---- static BOOL Init(LPSTR szInFile, LPSTR szOutFile) { BOOL fRet = FALSE; LONG cbRead; UINT32 *pChunkID; UINT32 *pChunkSize; LONG iChunkSize; LPMIDIFILEHDR pHeader; LPINTRACKSTATE pInTrack; UINT iTrack; // Initialize things we'll try to free later if we fail // ifs.FileSize = 0; ifs.pFile = NULL; //ifs.pTracks = NULL; // Attempt to open the input and output files // hInFile = CreateFileA(szInFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hInFile) { I_OutputMsg("Could not open \"%s\" for read.\n", szInFile); goto Init_Cleanup; } hOutFile = CreateFileA(szOutFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == hOutFile) { I_OutputMsg("Could not open \"%s\" for write.\n", szOutFile); goto Init_Cleanup; } // Figure out how big the input file is and allocate a chunk of memory big enough // to hold the whole thing. Read the whole file in at once. // if (INVALID_FILE_SIZE == (ifs.FileSize = GetFileSize(hInFile, NULL))) { I_OutputMsg("File system error on input file.\n"); goto Init_Cleanup; } if (NULL == (ifs.pFile = GlobalAllocPtr(GPTR, ifs.FileSize))) { I_OutputMsg("Out of memory.\n"); goto Init_Cleanup; } if ((!ReadFile(hInFile, ifs.pFile, ifs.FileSize, &cbRead, NULL)) || cbRead != ifs.FileSize) { I_OutputMsg("Read error on input file.\n"); goto Init_Cleanup; } // Set up to read from the memory buffer. Read and validate // - MThd header // - size of file header chunk // - file header itself // ifs.iBytesLeft = ifs.FileSize; ifs.pFilePointer = ifs.pFile; // note: midi header size should always be 6 if ((pChunkID = (UINT32*)GetInFileData(sizeof (*pChunkID))) == NULL || *pChunkID != MThd || (pChunkSize = (UINT32*)GetInFileData(sizeof (*pChunkSize))) == NULL || (iChunkSize = LONGSWAP(*pChunkSize)) < sizeof (MIDIFILEHDR) || (pHeader = (LPMIDIFILEHDR)GetInFileData(iChunkSize)) == NULL) { I_OutputMsg("Read error on MIDI header.\n"); goto Init_Cleanup; } // File header is stored in hi-lo order. Swap this into Intel order and save // parameters in our native int size (32 bits) // ifs.dwFormat = (LONG)WORDSWAP(pHeader->wFormat); ifs.nTracks = (LONG)WORDSWAP(pHeader->nTracks); ifs.dwTimeDivision = (LONG)WORDSWAP(pHeader->wTimeDivision); #ifdef DEBUGMIDISTREAM I_OutputMsg("MIDI Header:\n" "------------\n" "format: %d\n" "number of tracks: %d\n" "time division: %d\n", ifs.dwFormat, ifs.nTracks, ifs.dwTimeDivision); #endif // We know how many tracks there are; allocate the structures for them and parse // them. The parse merely looks at the MTrk signature and track chunk length // in order to skip to the next track header. // faB: now static // ifs.pTracks = (INTRACKSTATE *)GlobalAllocPtr(GPTR, ifs.nTracks*sizeof (INTRACKSTATE)); // if (ifs.pTracks == NULL) // { // I_OutputMsg("Out of memory.\n"); // goto Init_Cleanup; // } // faB: made it static, but don't quit if there are more tracks, just skip'em // (this isn't really a limit, since 32 tracks are really the maximum for MIDI files) if (ifs.nTracks > MAX_MIDI_IN_TRACKS) ifs.nTracks = MAX_MIDI_IN_TRACKS; for (iTrack = 0, pInTrack = ifs.pTracks; iTrack < ifs.nTracks; ++iTrack, ++pInTrack) { if ((pChunkID = (UINT32*)GetInFileData(sizeof (*pChunkID))) == NULL || *pChunkID!= MTrk || (pChunkSize = (UINT32*)GetInFileData(sizeof (*pChunkSize))) == NULL) { I_OutputMsg("Read error on track header.\n"); goto Init_Cleanup; } iChunkSize = LONGSWAP(*pChunkSize); pInTrack->iTrackLen = iChunkSize; pInTrack->iBytesLeft = iChunkSize; pInTrack->pTrackData = GetInFileData(iChunkSize); if (pInTrack->pTrackData == NULL) { I_OutputMsg("Read error while reading track data.\n"); goto Init_Cleanup; } #ifdef DEBUGMIDISTREAM I_OutputMsg("Track %d : length %d bytes\n", iTrack, iChunkSize); pInTrack->nTrack = iTrack; #endif pInTrack->pTrackPointer = pInTrack->pTrackData; pInTrack->fdwTrack = 0; pInTrack->bRunningStatus = 0; // Handle bozo MIDI files which contain empty track chunks // if (!pInTrack->iBytesLeft) { pInTrack->fdwTrack |= ITS_F_ENDOFTRK; continue; } // We always preread the time from each track so the mixer code can // determine which track has the next event with a minimum of work // if (!GetTrackVDWord(pInTrack, &pInTrack->tkNextEventDue)) { I_OutputMsg("Read error while reading first delta time of track.\n"); goto Init_Cleanup; } } ots.tkTrack = 0; ots.pFirst = NULL; ots.pLast = NULL; fRet = TRUE; Init_Cleanup: if (!fRet) Cleanup(); return fRet; }
// ----------------------- // Mid2StreamConverterInit // // Validate the input file structure // Allocate the input track structures and initialize them (faB: now STATIC) // Initialize the output track structures // // Return TRUE on success // ----------------------- BOOL Mid2StreamConverterInit(LPBYTE pMidiData, size_t iMidiSize) { BOOL fRet = TRUE; UINT32 *pChunkID; UINT32 *pChunkSize; UINT32 iChunkSize; LPMIDIFILEHDR pHeader; LPINTRACKSTATE pInTrack; UINT iTrack; tkCurrentTime = 0; // Initialize things we'll try to free later if we fail ZeroMemory(&ifs, sizeof (INFILESTATE)); //ifs.pTracks = NULL; //faB: now static // Set up to read from the memory buffer. Read and validate // - MThd header // - size of file header chunk // - file header itself // ifs.FileSize = iMidiSize; ifs.pFile = pMidiData; ifs.iBytesLeft = ifs.FileSize; ifs.pFilePointer = ifs.pFile; #ifdef DEBUGMIDISTREAM I_OutputMsg("Midi file size: %d\n", iMidiSize); #endif // note: midi header size should always be 6 if ((pChunkID = (UINT32*)GetInFileData(sizeof (*pChunkID))) == NULL || *pChunkID != MThd || (pChunkSize = (UINT32*)GetInFileData(sizeof (*pChunkSize))) == NULL || (iChunkSize = LONGSWAP(*pChunkSize)) < sizeof (MIDIFILEHDR) || (pHeader = (LPMIDIFILEHDR)GetInFileData(iChunkSize)) == NULL) { I_OutputMsg("Read error on MIDI header.\n"); goto Init_Cleanup; } ifs.dwFormat = (LONG)WORDSWAP(pHeader->wFormat); ifs.nTracks = (LONG)WORDSWAP(pHeader->nTracks); ifs.dwTimeDivision = (LONG)WORDSWAP(pHeader->wTimeDivision); #ifdef DEBUGMIDISTREAM I_OutputMsg("MIDI Header:\n" "------------\n" "format: %d\n" "number of tracks: %d\n" "time division: %d\n", ifs.dwFormat, ifs.nTracks, ifs.dwTimeDivision); #endif /* faB: made static ifs.pTracks = (INTRACKSTATE *)GlobalAllocPtr(GPTR, ifs.nTracks*sizeof (INTRACKSTATE)); if (ifs.pTracks == NULL) { I_OutputMsg("Out of memory.\n"); goto Init_Cleanup; } */ // faB: made it static, but don't quit if there are more tracks, just skip'em if (ifs.nTracks > MAX_MIDI_IN_TRACKS) ifs.nTracks = MAX_MIDI_IN_TRACKS; for (iTrack = 0, pInTrack = ifs.pTracks; iTrack < ifs.nTracks; ++iTrack, ++pInTrack) { if ((pChunkID = (UINT32*)GetInFileData(sizeof (*pChunkID))) == NULL || *pChunkID!= MTrk || (pChunkSize = (UINT32*)GetInFileData(sizeof (*pChunkSize))) == NULL) { I_OutputMsg("Read error on track header.\n"); goto Init_Cleanup; } iChunkSize = LONGSWAP(*pChunkSize); pInTrack->iTrackLen = iChunkSize; // Total track length pInTrack->iBytesLeft = iChunkSize; pInTrack->pTrackData = GetInFileData(iChunkSize); if (pInTrack->pTrackData == NULL) { I_OutputMsg("Read error while reading track data.\n"); goto Init_Cleanup; } #ifdef DEBUGMIDISTREAM I_OutputMsg("Track %d : length %d bytes\n", iTrack, iChunkSize); pInTrack->nTrack = iTrack; #endif // Setup pointer to the current position in the track pInTrack->pTrackPointer = pInTrack->pTrackData; pInTrack->fdwTrack = 0; pInTrack->bRunningStatus = BAD_MIDI_FIX; pInTrack->tkNextEventDue = 0; // Handle bozo MIDI files which contain empty track chunks if (!pInTrack->iBytesLeft) { pInTrack->fdwTrack |= ITS_F_ENDOFTRK; continue; } // We always preread the time from each track so the mixer code can // determine which track has the next event with a minimum of work if (!GetTrackVDWord(pInTrack, &pInTrack->tkNextEventDue)) { I_OutputMsg("Read error while reading first delta time of track.\n"); goto Init_Cleanup; } } // End of track initialization code fRet = FALSE; Init_Cleanup: if (fRet) Mid2StreamConverterCleanup(); return fRet; }
short twobyte2word(unsigned char *in) { short result; WORDSWAP((unsigned char*)&result, in); return result; }