std::string en::GetNoun(Noun* NounObj,bool ObjCase) { #ifdef DEBUG std::cout << "[EN] GetNoun(noun* NounObj)" <<std::endl; #endif std::ifstream is(DICTIONARY EN_FOLDER "nouns"); if (GotoLine(is,NounObj->ID)) return ""; int Typ = is.get(); if (Typ == 'd') { int GetID = 1; if (ObjCase && NounObj->IsReflexive) GetID = 4; else if (ObjCase) GetID = 2; if (GotoSegment(is,GetID)) return ""; return GetSegment(is); } else if (Typ == 'n' || Typ == 'm' || Typ == 'f') { if (GotoSegment(is,1)) return ""; std::string Base = GetSegment(is); if (NounObj->IsPlural) Base += "s"; return Base; } else if (Typ == 'o') { int GetID = 1; if (NounObj->IsPlural) GetID = 2; if (GotoSegment(is,GetID)) return ""; return GetSegment(is); } return ""; }
std::string en::GetVerbPreAdd(int VerbNum) { std::ifstream is (DICTIONARY EN_EN_FOLDER "verb_present"); if (GotoLine(is,VerbNum)) return ""; int Data = is.get(); if (Data == '1') { if (GotoSegment(is,2)) return ""; std::string Segment = GetSegment(is); is.close(); return Segment; } else if (Data == '0') { if (GotoSegment(is,11)) return ""; std::string Segment = GetSegment(is); is.close(); return Segment; } else { if (GotoSegment(is,1)) return ""; std::string Segment = GetSegment(is); is.close(); //Now follow all the english spelling rules //http://www.oxforddictionaries.com/words/verb-tenses-adding-ed-and-ing //http://www.grammar.cl/Notes/Spelling_ING.htm int u = Segment.length(); if (Segment[u-1] == 'e' && Segment[u-2] == 'i') { //Turn 'ie' into y Segment = Segment.substr(0,u-2); Segment += "y"; } else if (Segment[u-1] == 'e' && ( Segment[u-2] != 'e' && Segment[u-2] != 'y' && Segment[u-2] != 'o' )) { //Drop final e, if e is not before y,e or o //make -> mak ( + {ed,ing} ) Segment = Segment.substr(0,u-1); } else if (Segment[u-1] == 'c') { //Add a k after a c //picnic -> picnick ( + {ed,ing} ) Segment += "k"; } else if (!IsVowel(Segment[u-3]) && IsVowel(Segment[u-2]) && !IsVowel(Segment[u-1]) && Segment[u-1]!='x' && Segment[u-1]!='y' && Segment[u-1]!='z' && Segment[u-1]!='w') { //Double consonant after consonant-vowel-consonant cluster. //Provided that final consonant is not w,x,y or z //Travel -> Travell ( + {ed,ing} ) Segment += Segment[u-1]; } return Segment; } return ""; }
std::string en::GetVerbPastSimple(int VerbForm, int VerbNum, std::string Mid, bool Perfect, bool IgnoreMid, bool HelperVerb) { std::ifstream is(DICTIONARY EN_EN_FOLDER "verb_past"); GotoLine(is,VerbNum); int Data = is.get(); if (Data == '2' || Data == '3') { is.close(); if (!IgnoreMid && Mid.compare("")!=0) { return GetVerbPastSimple(VerbForm,68,"",Perfect,true) + " " + Mid + " " + GetVerbPresentSimple(0,VerbNum,"",true,false); } std::string V = GetVerbPreAdd(VerbNum); if (Data == '3') V += "e"; V += "d"; return V; } else if (Data == '1') { if (!IgnoreMid && Mid.compare("")!=0) { is.close(); return GetVerbPastSimple(VerbForm,68,"",Perfect,true,true) + " " + Mid + " " + GetVerbPresentSimple(0,VerbNum,"",true); } if(GotoSegment(is,Perfect?2:1)) { is.close(); return ""; } std::string Verb = GetSegment(is); is.close(); return Verb; } else if (Data == '0') { if (Perfect) VerbForm = 0; if (GotoSegment(is,VerbForm+1)) { is.close(); return ""; } std::string Verb = GetSegment(is); is.close(); if (!IgnoreMid && (VerbNum == 1 || HelperVerb) && Mid.compare("")!=0 ) Verb += " " + Mid; else if (!IgnoreMid && Mid.compare("")!=0) { return GetVerbPastSimple(VerbForm,68,"",Perfect,true,true) + " " + Mid + " " + GetVerbPresentSimple(0,VerbNum,"",true); } return Verb; } return ""; }
void AdvancePlayer(Matrix *matrix, Player player, Point p) { /* go from last to first so the identifier is always unique */ Point p_tmp, p_tail = GetSegment(matrix, GetSize(matrix, player) * player); int segment = GetSize(matrix, player) * player; while (TRUE) { p_tmp = GetSegment(matrix, segment); (*matrix)[p_tmp.y][p_tmp.x] += player; segment -= player; if (segment == 0) break; } (*matrix)[p_tail.y][p_tail.x] = EMPTY; (*matrix)[p.y][p.x] = player; }
Point GetInputLoc(Matrix *matrix, Player player, Direction dir) { Point p; if (dir != UP && dir != DOWN && dir != LEFT && dir != RIGHT) { p.x = -1; p.y = -1; return p; } p = GetSegment(matrix, player); //gets the point of the player's head switch (dir) { case UP: --p.y; break; case DOWN: ++p.y; break; case LEFT: --p.x; break; case RIGHT: ++p.x; break; } return p; }
int HexDoc::GetSerializedLength(THSIZE nOffset, THSIZE nSize) { int sSize = sizeof(SerialDataHeader); std::vector<DataSource*> sources; std::vector<DataSource*>::const_iterator iter; THSIZE segStart; Segment *ts = GetSegment(nOffset, &segStart); THSIZE segOffset = nOffset - segStart; while (ts != NULL && segStart < nOffset + nSize) { int nSource = 0; if (ts->pDS) { iter = std::find(sources.begin(), sources.end(), ts->pDS); if (iter == sources.end()) { sources.push_back(ts->pDS); sSize += ts->pDS->GetSerializedLength(); } } THSIZE copySize = min(nSize, ts->size - segOffset); sSize += ts->GetSerializedLength(segOffset, copySize); segStart += ts->size; segOffset = 0; ts = ts->next; } return sSize; }
//-------------------------------------------------------------------------------- void CHL7Message::TraceDump() { if(! GetIO()->IsDisplayed(IOMASK_9)) return; for(int i = 0; i < GetSegmentCount(); i++) GetIO()->Output(IOMASK_9|IOMASK_CONST, (CString) *GetSegment(i)); }
std::string en::GetVerbPresentSimple(int VerbForm, int VerbNum, std::string Mid, bool IgnoreMid, bool HelperVerb) { std::ifstream is(DICTIONARY EN_EN_FOLDER "verb_present"); if (GotoLine(is,VerbNum)) return ""; int Data = is.get(); if (Data == '0') { if (GotoSegment(is,VerbForm+1)) return ""; std::string Segment = GetSegment(is); is.close(); if (!IgnoreMid && (VerbNum == 1 || HelperVerb) && Mid.compare("")!=0 ) Segment += " " + Mid; else if (!IgnoreMid && Mid.compare("")!=0) { return GetVerbPresentSimple(VerbForm,68,"",true) + " " + Mid + " " + GetVerbPresentSimple(0,VerbNum,"",true); } return Segment; } else { if (!IgnoreMid && Mid.compare("")!=0 && Data != '3') { is.close(); return GetVerbPresentSimple(VerbForm,68,"",true) + " " + Mid + " " + GetVerbPresentSimple(0,VerbNum,"",true); } if (GotoSegment(is,1)) return ""; std::string Segment = GetSegment(is); if (Data != '3') { if (VerbForm > 2 && VerbForm < 6) { //Need to add 's' conjugation int u = Segment.length(); if (Segment[u-1]=='o' || (Segment[u-1]=='s' && Segment[u-2]=='s') || (Segment[u-1]=='h' && Segment[u-2]=='s') || (Segment[u-1]=='h' && Segment[u-2]=='c') || (Segment[u-1]=='z' && Segment[u-2]=='z') || Segment[u-1]=='x') { Segment +="e"; } Segment += "s"; } } else if (!IgnoreMid && Mid.compare("")!=0) Segment+= " " + Mid; is.close(); return Segment; } is.close(); return ""; }
std::string en::GetConjunction(int ConjunctionNum) { if (ConjunctionNum < 0) return ""; std::ifstream is(DICTIONARY EN_EN_FOLDER "conjunctions"); if(GotoLine(is,ConjunctionNum)) return ""; std::string Conjunction = GetSegment(is); is.close(); return Conjunction; }
void GScreen::RemoveSegment(int iNumber) { GSegment* oSegment = GetSegment(iNumber); if(oSegment != NULL) { m_oSegments->remove(iNumber); delete oSegment; } }
void SubtitleFile::SegmentList::Lookup(float at, CAtlList<SegmentItem>& sis) { sis.RemoveAll(); size_t k; if(Lookup(at, k)) { sis.AddTailList(GetSegment(k)); } }
bool HexDoc::Load(uint64 nIndex) { if (nIndex >= size) return NULL; if (IsByteLoaded(nIndex)) return true; m_curSeg = GetSegment(nIndex, &m_iCurSegOffset); return (m_curSeg != NULL); }
int CConfigFile::PerformParse(char * pFileName) { if (!ReadFileToMem(pFileName)) { return 0; } GetSegment(); return 1; }
std::string en::GetAdjective(int AdjectiveNum) { if (AdjectiveNum <= 0 ) return ""; #ifdef DEBUG std::cout << "[EN] GetAdjective(int AdjectiveNum = " << AdjectiveNum << " )" << std::endl; #endif std::ifstream is(DICTIONARY EN_EN_FOLDER "adjectives"); if (GotoLine(is,AdjectiveNum)) return ""; std::string Adjective = GetSegment(is); is.close(); return Adjective; }
string Speech::ToString() { std::ostringstream oss; oss << "<Speech NbOfSegments='" << NbOfSegments() << "'>"; for(size_t i = 0; i < NbOfSegments(); ++i) { Segment *seg = GetSegment(i); oss << seg->ToString() << endl; } oss << "</Speech>"; return oss.str(); }
int GetSize(Matrix *matrix, Player player) { /* check one by one the size */ Point p, next_p; int segment = 0; while (TRUE) { next_p = GetSegment(matrix, segment += player); if (next_p.x == -1) break; p = next_p; } return (*matrix)[p.y][p.x] * player; }
int Speech::GetMaxTokensTime() { int MaxTime = -1; for(size_t spj=0; spj<NbOfSegments(); ++spj) { int tmpmax = GetSegment(spj)->GetMaxTokensTime(); if ( (MaxTime == -1) || (tmpmax > MaxTime) ) MaxTime = tmpmax; } return MaxTime; }
int Speech::GetMinTokensTime() { int MinTime = -1; for(size_t spj=0; spj<NbOfSegments(); ++spj) { int tmpmin = GetSegment(spj)->GetMinTokensTime(); if ( (MinTime == -1) || (tmpmin < MinTime) ) MinTime = tmpmin; } return MinTime; }
Point GetInputLoc(Matrix *matrix, Player player, char move) { Direction dir = move-'0'; Point p; p = GetSegment(matrix, player); switch (dir) { case UP: --p.y; break; case DOWN: ++p.y; break; case LEFT: --p.x; break; case RIGHT: ++p.x; break; } return p; }
bool HexDoc::ReplaceAt(uint64 ToReplaceIndex, uint32 ToReplaceLength, const uint8 *pReplaceWith, uint32 ReplaceWithLength) { if (!CanReplaceAt(ToReplaceIndex, ToReplaceLength, ReplaceWithLength)) return false; if (ToReplaceLength > ReplaceWithLength) { //! is this a good idea? RemoveAt(ToReplaceIndex + ReplaceWithLength, ToReplaceLength - ReplaceWithLength, SUPPRESS_UPDATE); ToReplaceLength = ReplaceWithLength; } // Quick optimization: // If affected range is entirely inside one writeable Segment and size doesn't change, // just write data. //! is this a good idea? uint64 segmentStart; Segment *ts = GetSegment(ToReplaceIndex, &segmentStart); if (ts && ts->type == Segment::MEM && ToReplaceLength == ReplaceWithLength) { if (ts->contains(ToReplaceIndex, ToReplaceLength, segmentStart)) { memcpy(&ts->pData[ToReplaceIndex - segmentStart], pReplaceWith, ToReplaceLength); return true; } } if (!RemoveAt(ToReplaceIndex, ToReplaceLength, SUPPRESS_UPDATE)) return false; if (!InsertAt(ToReplaceIndex, pReplaceWith, ReplaceWithLength, 1, SUPPRESS_UPDATE)) return false; /* THSIZE lengthDiff = (THSIZE)ToReplaceLength - (THSIZE)ReplaceWithLength; // overflow doesn't matter for (size_t n = FindModified(ToReplaceIndex, true); n < modRanges.size(); n++) { ByteRange& tr = modRanges[n]; if (tr.start > ToReplaceIndex) tr.start += lengthDiff; tr.end += lengthDiff; }*/ m_iChangeIndex++; if (hw) hw->OnDataChange(ToReplaceIndex, ToReplaceLength, ReplaceWithLength); return true; }
void HexDoc::Serialize(THSIZE nOffset, THSIZE nSize, uint8 *target) { SerialDataHeader &hdr = *(SerialDataHeader*)target; int sOffset = sizeof(hdr); hdr.endianMode = NATIVE_ENDIAN_MODE; hdr.nSegments = 0; hdr.nSources = 0; std::vector<DataSource*> sources; std::vector<DataSource*>::const_iterator iter; THSIZE segStart; Segment *ts = GetSegment(nOffset, &segStart); THSIZE segOffset = nOffset - segStart; while (ts != NULL && segStart < nOffset + nSize) { hdr.nSegments++; int nSource = 0; if (ts->pDS) { iter = std::find(sources.begin(), sources.end(), ts->pDS); if (iter == sources.end()) { sources.push_back(ts->pDS); hdr.nSources++; } } THSIZE copySize = min(nOffset + nSize, segStart + ts->size) - (segStart + segOffset); int sSize = ts->GetSerializedLength(segOffset, copySize); ts->Serialize(segOffset, copySize, nSource, target + sOffset); sOffset += sSize; segStart += ts->size; segOffset = 0; ts = ts->next; } for (iter = sources.begin(); iter < sources.end(); iter++) { DataSource *pDS = *iter; int sSize = pDS->GetSerializedLength(); pDS->Serialize(target + sOffset); sOffset += sSize; } }
std::string de::GetSubClause() { if (Conjunction < 0) return ""; std::ifstream is(DICTIONARY DE_FOLDER "conjunctions.txt"); if (GotoLine(is,Conjunction)) return ""; int Data = is.get(); if (GotoSegment(is,1)) return ""; std::string ConjunctionString = GetSegment(is); is.get(); if (Data == '0') SubClause->IsClause = true; else if (Data == '2') SubClause->Data |= 1; SubClause->Punctuation = 0; SubClause->Capital = false; std::string ClauseString = SubClause->createSentence(); return ", " + ConjunctionString + " " + ClauseString; }
void SerialData::Init(const uint8* data, int len) { this->data = data; this->len = len; loaded = false; this->offset = 0; if (!Read(&hdr, sizeof(hdr))) { Clear(); return; // invalid serial data } if (hdr.endianMode != NATIVE_ENDIAN_MODE) { reverse(&hdr.nSegments); reverse(&hdr.nSources); } m_nTotalSize = 0; for (int i = 0; i < hdr.nSegments; i++) { SerialDataSegment seg; if (!GetSegment(i, seg)) { Clear(); return; } m_nTotalSize += seg.size; } m_nSourceOffset = offset; for (int i = 0; i < hdr.nSources; i++) { SerialDataSource sds; if (!GetSource(i, sds)) { Clear(); return; } } loaded = true; }
// Read through all the notes in all the note tracks on the given node // Check the contents of each node for a name like "walk@start", i.e. <string>@[start | end] // For each match, open a segment specification and p SegmentMap * GetAnimSegmentMap(Animatable *anim, plErrorMsg *pErrMsg) { if (!anim->HasNoteTracks()) return nil; SegmentMap *segMap = new SegmentMap(); int numTracks = anim->NumNoteTracks(); for (int i = 0; i < numTracks; i++) { DefNoteTrack * track = (DefNoteTrack *)anim->GetNoteTrack(i); int numKeys = track->keys.Count(); for (int j = 0; j < numKeys; j++) { char *note = track->keys[j]->note; float time = TimeValueToGameTime(track->keys[j]->time); GetSegment(note, time, segMap, pErrMsg); } } return segMap; }
Section* ReadSection (FILE* F, ObjData* O) /* Read a section from a file */ { unsigned Name; unsigned Size; unsigned long Alignment; unsigned char Type; unsigned FragCount; Segment* S; Section* Sec; /* Read the segment data */ (void) Read32 (F); /* File size of data */ Name = MakeGlobalStringId (O, ReadVar (F)); /* Segment name */ ReadVar (F); /* Segment flags (currently unused) */ Size = ReadVar (F); /* Size of data */ Alignment = ReadVar (F); /* Alignment */ Type = Read8 (F); /* Segment type */ FragCount = ReadVar (F); /* Number of fragments */ /* Print some data */ Print (stdout, 2, "Module '%s': Found segment '%s', size = %u, alignment = %lu, type = %u\n", GetObjFileName (O), GetString (Name), Size, Alignment, Type); /* Get the segment for this section */ S = GetSegment (Name, Type, GetObjFileName (O)); /* Allocate the section we will return later */ Sec = NewSection (S, Alignment, Type); /* Remember the object file this section was from */ Sec->Obj = O; /* Set up the combined segment alignment */ if (Sec->Alignment > 1) { Alignment = LeastCommonMultiple (S->Alignment, Sec->Alignment); if (Alignment > MAX_ALIGNMENT) { Error ("Combined alignment for segment '%s' is %lu which exceeds " "%lu. Last module requiring alignment was '%s'.", GetString (Name), Alignment, MAX_ALIGNMENT, GetObjFileName (O)); } else if (Alignment >= LARGE_ALIGNMENT) { Warning ("Combined alignment for segment '%s' is suspiciously " "large (%lu). Last module requiring alignment was '%s'.", GetString (Name), Alignment, GetObjFileName (O)); } S->Alignment = Alignment; } /* Start reading fragments from the file and insert them into the section . */ while (FragCount--) { Fragment* Frag; /* Read the fragment type */ unsigned char Type = Read8 (F); /* Extract the check mask from the type */ unsigned char Bytes = Type & FRAG_BYTEMASK; Type &= FRAG_TYPEMASK; /* Handle the different fragment types */ switch (Type) { case FRAG_LITERAL: Frag = NewFragment (Type, ReadVar (F), Sec); ReadData (F, Frag->LitBuf, Frag->Size); break; case FRAG_EXPR: case FRAG_SEXPR: Frag = NewFragment (Type, Bytes, Sec); Frag->Expr = ReadExpr (F, O); break; case FRAG_FILL: /* Will allocate memory, but we don't care... */ Frag = NewFragment (Type, ReadVar (F), Sec); break; default: Error ("Unknown fragment type in module '%s', segment '%s': %02X", GetObjFileName (O), GetString (S->Name), Type); /* NOTREACHED */ return 0; } /* Read the line infos into the list of the fragment */ ReadLineInfoList (F, O, &Frag->LineInfos); /* Remember the module we had this fragment from */ Frag->Obj = O; } /* Return the section */ return Sec; }
void ZoomInteractor::UpdateRubberBand(int aX, int aY, int lX, int lY,int nX,int nY) { if (nX == lX && nY == lY) { // // No update necessary. // return; } #if defined(__APPLE__) || defined(_WIN32) // This code assumes that the lines will be drawn at the same time // in an overlay window that the rubber-band mapper will create. vtkViewport *ren = proxy.GetBackground(); vtkPoints *pts = rubberBand->GetPoints(); pts->SetPoint(0, (double) aX, (double) aY, 0.); pts->SetPoint(1, (double) nX, (double) aY, 0.); pts->SetPoint(2, (double) nX, (double) nY, 0.); pts->SetPoint(3, (double) aX, (double) nY, 0.); rubberBandMapper->RenderOverlay(ren, rubberBandActor); #else // This code assumes that the line segments will be drawn individually // with XOR. // // Crossing over the anchor gives us a big problem. Break up this case. // if ((nX-aX)*(lX-aX) < 0 || (nY-aY)*(lY-aY) < 0) { UpdateRubberBand(aX, aY, lX, lY, aX, aY); UpdateRubberBand(aX, aY, aX, aY, nX, nY); return; } // // Handle the line that is vertical and has the new corner as one of its // vertices. // if (nX == lX) { // // The box moved up in the y-direction, so extend what we had there // before. // int lastY, newY; GetSegment(aY, lY, nY, lastY, newY); DrawRubberBandLine(lX, lastY, lX, newY); } else { // // Add the new line and erase the old one. // DrawRubberBandLine(nX, aY, nX, nY); DrawRubberBandLine(lX, aY, lX, lY); } // // Handle the line that is horizontal and has the new corner as one of its // vertices. // if (nY == lY) { // // The box moved over in the x-direction, so extend what we had there // before. // int lastX, newX; GetSegment(aX, lX, nX, lastX, newX); DrawRubberBandLine(lastX, lY, newX, lY); } else { // // Add the new line and erase the old one. // DrawRubberBandLine(aX, nY, nX, nY); DrawRubberBandLine(aX, lY, lX, lY); } // // Handle the line that is vertical and has the anchor as one of its // vertices. // if (nY != lY) { int lastY, newY; GetSegment(aY, lY, nY, lastY, newY); DrawRubberBandLine(aX, lastY, aX, newY); } // // Handle the line that is horizontal and has the anchor as one of its // vertices. // if (nX != lX) { int lastX, newX; GetSegment(aX, lX, nX, lastX, newX); DrawRubberBandLine(lastX, aY, newX, aY); } #endif }
void LoadTable() { FILE *stream; TCHAR szStr[1200] = {0}; TCHAR szTabFileName[MAX_PATH << 1]={ 0}; LPTSTR lpTabFileName = szTabFileName; lpTabFileName += GetSystemDirectory(szTabFileName, MAX_PATH); if (*(lpTabFileName - 1) != _T('\\')) { *lpTabFileName++ = _T('\\'); } *lpTabFileName = 0; _tcscpy_s(lpTabFileName, MAX_PATH, TABFILENAME); if(EINVAL == _tfopen_s(&stream, szTabFileName, TEXT("r")) || !stream) { TRACE(TEXT("%s can not found"), szTabFileName); exit(1); } while( !feof( stream )) { GetStr(stream,szStr); switch( GetSegment(szStr)) { case 1: //END_SEGMENT break; case 2: //COMMENT break; case 3: //PUNCTUATION if( feof( stream ) ) { goto my_exit; } GetStr(stream,szStr); while(GetSegment(szStr) != 1) { if( GetSegment(szStr) != 2) { LoadPunct( szStr ); } if( feof( stream ) ) { goto my_exit; } GetStr(stream,szStr); } break; case 4: //DICTIONARY if( feof( stream ) ) { goto my_exit; } GetStr(stream,szStr); while(GetSegment(szStr) != 1) { if( GetSegment(szStr) != 2) { LoadHZDictionary( szStr ); } if( feof( stream ) ) { goto my_exit; } GetStr(stream,szStr); } break; default: break; } } my_exit: fclose(stream); return; }
// Returns the circumference of the segment "segmentIndex" at a given eta double CCPACSFuselage::GetCircumference(const int segmentIndex, const double eta) { return ((CCPACSFuselageSegment &) GetSegment(segmentIndex)).GetCircumference(eta); }
FadeMetro::EnumTickPos FadeMetro::GetTickPos() const { return GetTickPosForSegment( GetSegment() ); }
unsigned int InitAudio(unsigned int Rate,unsigned int Latency) { static const int PagePort[8] = { 0x87,0x83,0x81,0x82,-1,0x8B,0x89,0x8A }; int J,TotalBuf; char *P; /* Disable audio if was initialized */ TrashAudio(); /* If turning audio off, drop out */ if(!Rate) return(1); /* If Rate is out of range, fall out */ if((Rate<8192)||(Rate>44100)) return(0); /* Default values */ SBPort = 0x220; SBIRQ = 7; SBDMA = 1; SBIRQBusy = 0; SBWrite = 0; SBRead = 0; /* Get SoundBlaster Port#,IRQ#,DMA# */ if(P=getenv("BLASTER")) while(*P) switch(toupper(*P++)) { case 'A': SBPort=strtol(P,0,16);break; case 'D': SBDMA=strtol(P,0,16);break; case 'I': SBIRQ=strtol(P,0,16);break; } /* IRQ# = 0,1,2,3,4,5,6,7, DMA# = 0,1,2,3 */ if((SBIRQ>7)||(SBDMA>3)) return(0); /* Reset DSP */ outp(SBPort+0x06,0x01); /* Set the reset flag */ delay(100); /* Wait for 100ms */ outp(SBPort+0x06,0x00); /* Clear the reset flag */ /* Wait for READY status */ for(J=100;J&&!(inp(SBPort+0x0E)&0x80);J--); if(!J) return(0); for(J=100;J&&(ReadDSP()!=0xAA);J--); if(!J) return(0); /* Allocate low memory for DMA buffer */ TotalBuf=(Rate*Latency/1000/SND_BUFSIZE)*SND_BUFSIZE; if(TotalBuf<SND_BUFSIZE) TotalBuf=SND_BUFSIZE; SBBuffers=TotalBuf/SND_BUFSIZE; SBSegment=GetSegment(TotalBuf*sizeof(sample)*2/16+4); if(!SBSegment) return(0); J=SBSegment*16; SBBuffer=(unsigned char *)J; if((J>>16)!=((J+TotalBuf-1)>>16)) SBBuffer+=TotalBuf; memset(SBBuffer,0,TotalBuf*sizeof(sample)); /* Interrupts off */ _disable(); /* Save old interrupt vector */ IRQ5Old=(void (interrupt *)())_dos_getvect(SBIRQ+8); /* Install new interrupt vector */ _dos_setvect(SBIRQ+8,IRQ5Handler); /* Enable the SoundBlaster IRQ */ outp(0x21,inp(0x21)&~(1<<SBIRQ)); /* Disable DMA channel */ outp(0x0A,SBDMA|0x04); /* Clear byte pointer flip-flop */ outp(0x0C,0x00); /* Auto-initialized playback mode */ outp(0x0B,SBDMA|0x58); /* Write DMA offset and transfer length */ J=SBDMA<<1; outp(J,(int)SBBuffer&0xFF); outp(J,((int)SBBuffer>>8)&0xFF); outp(J+1,(TotalBuf-1)&0xFF); outp(J+1,((TotalBuf-1)>>8)&0xFF); /* Write DMA page */ outp(PagePort[SBDMA],((int)SBBuffer>>16)&0xFF); /* Enable DMA channel */ outp(0x0A,SBDMA); /* Enable interrupts */ _enable(); /* Set sampling rate */ WriteDSP(0x40); WriteDSP((65536L-(256000000L/Rate))/256); /* Set DMA transfer size */ WriteDSP(0x48); WriteDSP((SND_BUFSIZE-1)&0xFF); WriteDSP((SND_BUFSIZE-1)>>8); /* Run auto-initialized 8bit DMA */ WriteDSP(0x90); /* Speaker enabled */ WriteDSP(0xD1); /* Done */ return(SndRate=Rate); }