Ejemplo n.º 1
0
 void MapReader::onEndEntity(const size_t startLine, const size_t lineCount) {
     if (m_currentNode != NULL)
         setFilePosition(m_currentNode, startLine, lineCount);
     else
         onWorldspawnFilePosition(startLine, lineCount);
     m_currentNode = NULL;
     m_brushParent = NULL;
 }
Ejemplo n.º 2
0
void ICQTransfer::sendPacket0x03()
{
    Packet packet;
    packet << (unsigned char)0x03
           << fileProgress
           << (unsigned int)0x00
           << speed;

    setFilePosition();

    T("[tcp] send packet 0x03\n");
    socket.sendPacket(packet);
}
Ejemplo n.º 3
0
        void MapReader::createBrush(const size_t startLine, const size_t lineCount, const ExtraAttributes& extraAttributes) {
            try {
                // sort the faces by the weight of their plane normals like QBSP does
                Model::BrushFace::sortFaces(m_faces);
                
                Model::Brush* brush = m_factory->createBrush(m_worldBounds, m_faces);
                setFilePosition(brush, startLine, lineCount);
                setExtraAttributes(brush, extraAttributes);
                
                onBrush(m_brushParent, brush);
                m_faces.clear();
            } catch (GeometryException& e) {
                if (logger() != NULL)
                    logger()->error("Error parsing brush at line %u: %s", startLine, e.what());
                m_faces.clear(); // the faces will have been deleted by the brush's constructor
            }

        }
Ejemplo n.º 4
0
void ICQTransfer::processTcpPacket(Packet &packet)
{
    unsigned int /*i,*/ status, junkLong;
    //unsigned short junkShort;
    unsigned char cmd/*, junkChar*/;
    char *name = NULL, *directoryName = NULL;

    packet >> cmd;
    switch (cmd)
    {
    case 0x00:
        T("[tcp] recieve initialising file transfer\n");
        packet >> junkLong
               >> count
               >> totalSize
               >> speed
               >> name;

        files = new char*[count + 1];
        ZeroMemory(files, (count+1)*sizeof(char*));

        ack(ACKRESULT_INITIALISING);
        sendPacket0x01();
        break;

    case 0x01:
        T("[tcp] ack initialising\n");
        packet >> speed
               >> name;

        ack(ACKRESULT_INITIALISING);
        sendPacket0x02();
        break;

    case 0x02:
        T("[tcp] recieve next file\n");
        packet >> directory
               >> files[++current]
               >> directoryName
               >> fileSize
               >> fileDate
               >> speed;

        if (directoryName[0])
        {
            char *fullName = new char[mir_strlen(directoryName) + mir_strlen(files[current]) + 2];
            sprintf(fullName, "%s\\%s", directoryName, files[current]);
            delete [] files[current];
            files[current] = fullName;
        }

        if (directory) createDirectory();
        else openFile();
        ack(ACKRESULT_NEXTFILE);

        if (fileProgress) ack(ACKRESULT_FILERESUME);
        else sendPacket0x03();
        break;

    case 0x03:
        T("[tcp] ack next file\n");
        packet >> fileProgress
               >> status
               >> speed;

        totalProgress += fileProgress;
        setFilePosition();
        ack(ACKRESULT_NEXTFILE);

        if (status != 0)
        {
            totalProgress += fileSize - fileProgress;
            fileProgress = fileSize;
            closeFile();
            ack(ACKRESULT_DATA);
        }

        process();
        break;

    case 0x04:
        T("[tcp] recieve stop file\n");
        packet >> junkLong;

        totalProgress += fileSize - fileProgress;
        fileProgress = fileSize;
        closeFile();
        ack(ACKRESULT_DATA);
        break;

    case 0x05:
        T("[tcp] recieve new speed\n");
        packet >> speed;
        break;

    case 0x06:
        unsigned long result;

        WriteFile(hFile, packet.data(), packet.dataSize(), &result, NULL);

        fileProgress += result;
        totalProgress += result;

        if (fileProgress >= fileSize) closeFile();
        ack(ACKRESULT_DATA);
        break;

    default:
        T("[tcp] unknown packet:\n%s", packet.print());
        packet.reset();
    }

    delete [] directoryName;
    delete [] name;
}
Ejemplo n.º 5
0
 void WD177x::writeCommandRegister(uint8_t n)
 {
   if ((statusRegister & 0x01) != 0 && (n & 0xF0) != 0xD0) {
     // ignore command if wd177x is busy, and the command is not
     // force interrupt
     return;
   }
   if ((statusRegister & 0x01) == 0)   // store new command
     commandRegister = n;
   if ((n & 0x80) == 0) {              // ---- Type I commands ----
     uint8_t r = n & 3;                // step rate (ignored)
     bool    v = ((n & 0x04) != 0);    // verify flag
     bool    h = ((n & 0x08) != 0);    // disable spin-up (ignored)
     bool    u = ((n & 0x10) != 0);    // update flag
     (void) r;
     (void) h;
     // set busy flag; reset CRC, seek error, data request, and IRQ
     dataRequestFlag = false;
     statusRegister = 0x21;
     if (interruptRequestFlag) {
       interruptRequestFlag = false;
       clearInterruptRequest();
     }
     if ((n & 0xF0) == 0) {            // RESTORE
       trackRegister = currentTrack;
       dataRegister = 0;
       if (dataRegister < trackRegister) {
         steppingIn = false;
         do {
           doStep(true);
         } while (trackRegister != dataRegister);
       }
     }
     else if ((n & 0xF0) == 0x10) {    // SEEK
       if (dataRegister > trackRegister) {
         steppingIn = true;
         do {
           doStep(true);
         } while (trackRegister != dataRegister);
       }
       else {
         steppingIn = false;
         do {
           doStep(true);
         } while (trackRegister != dataRegister);
       }
     }
     else {                            // STEP
       if ((n & 0xE0) == 0x40)         // STEP IN
         steppingIn = true;
       else if ((n & 0xE0) == 0x60)    // STEP OUT
         steppingIn = false;
       doStep(u);
     }
     // command done: update flags and trigger interrupt
     if (writeProtectFlag)
       statusRegister = statusRegister | 0x40;
     if (v && (imageFile == (std::FILE *) 0 ||
               currentTrack >= nTracks || currentTrack != trackRegister))
       statusRegister = statusRegister | 0x10; // seek error
     if (imageFile) {
       if (currentTrack == 0)
         statusRegister = statusRegister | 0x04;
       statusRegister = statusRegister | 0x02; // index pulse
     }
     statusRegister = statusRegister & 0xFE;   // clear busy flag
     if (!interruptRequestFlag) {
       interruptRequestFlag = true;
       interruptRequest();
     }
   }
   else if ((n & 0xC0) == 0x80) {      // ---- Type II commands ----
     bool    a0 = ((n & 0x01) != 0);   // write deleted data mark (ignored)
     bool    pc = ((n & 0x02) != 0);   // disable write precompensation
                                       // / enable side compare
     bool    e = ((n & 0x04) != 0);    // settling delay (ignored)
     bool    hs = ((n & 0x08) != 0);   // disable spin-up / side select
     bool    m = ((n & 0x10) != 0);    // multiple sectors
     (void) a0;
     (void) e;
     (void) m;
     // set busy flag; reset data request, lost data, record not found,
     // and interrupt request
     dataRequestFlag = false;
     statusRegister = 0x01;
     if (interruptRequestFlag) {
       interruptRequestFlag = false;
       clearInterruptRequest();
     }
     // select side (if enabled)
     if (isWD1773) {
       if (pc)
         currentSide = uint8_t(hs ? 1 : 0);
     }
     bufPos = 512;
     if ((n & 0x20) == 0) {            // READ SECTOR
       if (!setFilePosition())
         statusRegister = statusRegister | 0x10;   // record not found
       else if (std::fread(&(buf[0]), 1, 512, imageFile) != 512)
         statusRegister = statusRegister | 0x08;   // CRC error
       else {
         dataRequestFlag = true;
         statusRegister = statusRegister | 0x02;
         bufPos = 0;
       }
     }
     else {                            // WRITE SECTOR
       if (writeProtectFlag)
         statusRegister = statusRegister | 0x40;   // disk is write protected
       else if (!setFilePosition())
         statusRegister = statusRegister | 0x10;   // record not found
       else {
         dataRequestFlag = true;
         statusRegister = statusRegister | 0x02;
         bufPos = 0;
       }
     }
     if (bufPos >= 512) {
       // on error: clear busy flag, and trigger interrupt
       statusRegister = statusRegister & 0xFE;
       if (!interruptRequestFlag) {
         interruptRequestFlag = true;
         interruptRequest();
       }
     }
   }
   else if ((n & 0xF0) != 0xD0) {      // ---- Type III commands ----
     bool    p = ((n & 0x02) != 0);    // disable write precompensation
     bool    e = ((n & 0x04) != 0);    // settling delay (ignored)
     bool    h = ((n & 0x08) != 0);    // disable spin-up (ignored)
     (void) p;
     (void) e;
     (void) h;
     // set busy flag; reset data request, lost data, record not found,
     // and interrupt request
     dataRequestFlag = false;
     statusRegister = 0x01;
     if (interruptRequestFlag) {
       interruptRequestFlag = false;
       clearInterruptRequest();
     }
     bufPos = 512;
     if ((n & 0x20) == 0) {            // READ ADDRESS
       if (imageFile != (std::FILE *) 0 &&
           currentTrack < nTracks &&
           currentSide < nSides) {
         buf[506] = currentTrack;
         buf[507] = currentSide;
         buf[508] = 0x01;          // assume first sector of track
         buf[509] = 0x02;          // 512 bytes per sector
         uint16_t  tmp = calculateCRC(&(buf[506]), 4, 0xB230);
         buf[510] = uint8_t(tmp >> 8);         // CRC high byte
         buf[511] = uint8_t(tmp & 0xFF);       // CRC low byte
         bufPos = 506;
         dataRequestFlag = true;
         statusRegister = statusRegister | 0x02;
       }
       else