Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. //botscript parser - writeheader
  2. void BUFFER_WriteHeader( LONG lHeader )
  3. {
  4.     LONG    lSize;
  5.  
  6.     lSize = sizeof( LONG );
  7.     if (( lSize + g_ulBufferSize ) >= DEFAULT_OBJECT_SIZE )
  8.         ERROR_Error( "Object file size exceeds %d!\n", DEFAULT_OBJECT_SIZE );
  9.  
  10.     if ( lHeader >= NUM_DATAHEADERS )
  11.         ERROR_Error( "Invalid header, %d!\n", lHeader );
  12.  
  13.     MAIN_DebugMessage( "%02d: %06d = %s\n", lSize, g_pBufferPtr - g_pBuffer, g_pszHeaders[lHeader] );
  14.  
  15.     // Copy the data to the current position in the object buffer.
  16.     memcpy( g_pBufferPtr, (void *)&lHeader, lSize );
  17.  
  18.     // Move the buffer pointer and increased the object file size.
  19.     g_ulBufferSize += lSize;
  20.     g_pBufferPtr += lSize;
  21. }
  22.  
  23. //acc parser - pc_appendcmd
  24. void PC_AppendCmd(pcd_t command)
  25. {
  26.     if (ImportMode != IMPORT_Importing)
  27.     {
  28.         pc_LastAppendedCommand = command;
  29.         if (pc_NoShrink)
  30.         {
  31.             MS_Message(MSG_DEBUG, "AC> %06d = #%d:%s\n", pc_Address,
  32.                 command, PCDNames[command]);
  33.             command = MS_LittleUINT(command);
  34.             Append(&command, sizeof(U_INT));
  35.         }
  36.         else
  37.         {
  38.             U_BYTE cmd;
  39.             if (command != PCD_PUSHBYTE && PushByteAddr)
  40.             { // Maybe shrink a PCD_PUSHBYTE sequence into PCD_PUSHBYTES
  41.                 int runlen = (pc_Address - PushByteAddr) / 2;
  42.                 int i;
  43.  
  44.                 if (runlen > 5)
  45.                 {
  46.                     pc_Buffer[PushByteAddr] = PCD_PUSHBYTES;
  47.                     for (i = 0; i < runlen; i++)
  48.                     {
  49.                         pc_Buffer[PushByteAddr+i+2] = pc_Buffer[PushByteAddr+i*2+1];
  50.                     }
  51.                     pc_Buffer[PushByteAddr+1] = runlen;
  52.                     pc_Address = PushByteAddr + runlen + 2;
  53.                     pc_BufferPtr = pc_Buffer + pc_Address;
  54.                     MS_Message (MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSHBYTES\n",
  55.                         runlen, PCD_PUSHBYTES);
  56.                 }
  57.                 else if (runlen > 1)
  58.                 {
  59.                     pc_Buffer[PushByteAddr] = PCD_PUSH2BYTES + runlen - 2;
  60.                     for (i = 1; i < runlen; i++)
  61.                     {
  62.                         pc_Buffer[PushByteAddr+1+i] = pc_Buffer[PushByteAddr+1+i*2];
  63.                     }
  64.                     pc_Address = PushByteAddr + runlen + 1;
  65.                     pc_BufferPtr = pc_Buffer + pc_Address;
  66.                     MS_Message (MSG_DEBUG, "AC> Last %d PCD_PUSHBYTEs changed to #%d:PCD_PUSH%dBYTES\n",
  67.                         runlen, PCD_PUSH2BYTES+runlen-2, runlen);
  68.                 }
  69.                 PushByteAddr = 0;
  70.             }
  71.             else if (command == PCD_PUSHBYTE && PushByteAddr == 0)
  72.             { // Remember the first PCD_PUSHBYTE, in case there are more
  73.                 PushByteAddr = pc_Address;
  74.             }
  75.             MS_Message(MSG_DEBUG, "AC> %06d = #%d:%s\n", pc_Address,
  76.                 command, PCDNames[command]);
  77.  
  78.             if (command < 256-16)
  79.             {
  80.                 cmd = command;
  81.                 Append(&cmd, sizeof(U_BYTE));
  82.             }
  83.             else
  84.             {
  85.                 // Room for expansion: The top 16 pcodes in the [0,255]
  86.                 // range select a set of pcodes, and the next byte is
  87.                 // the pcode in that set.
  88.                 cmd = ((command - (256-16)) >> 8) + (256-16);
  89.                 Append(&cmd, sizeof(U_BYTE));
  90.                 cmd = (command - (256-16)) & 255;
  91.                 Append(&cmd, sizeof(U_BYTE));
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement