Guest User

Aconcagua text decompressor

a guest
Feb 20th, 2018
160
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //(WIP) Aconcagua (PSX) text decompressor (and compressor later)
  2. //First argument is input file and second argument is output file
  3.  
  4. #include <stdio.h>
  5.  
  6. #define BUFFER_SIZE 4096
  7.  
  8. void push(char*, char);
  9.  
  10. int main(int argc, char **argv) {
  11.     FILE *input, *output;
  12.     short int i;
  13.     unsigned short int mask = 0;
  14.     unsigned short int offset;
  15.     char buf[BUFFER_SIZE];
  16.     unsigned char newByte, byte1, byte2, length;
  17.     for(i = 0; i < BUFFER_SIZE; i++) {
  18.         buf[i] = 0x0;
  19.     }
  20.    
  21.     if ((input  = fopen(argv[1], "rb")) == NULL) {
  22.         printf("? %s\n", argv[1]);  return 1;
  23.     }
  24.    
  25.     if ((output = fopen(argv[2], "wb")) == NULL) {
  26.         printf("? %s\n", argv[2]);  return 1;
  27.     }
  28.    
  29.     while((byte1 = fgetc(input)) != EOF) {
  30.         if(!(mask & 0x0100)) {
  31.             mask = byte1 | 0xFF00;
  32.         } else if (mask & 0x01) {
  33.             if ((newByte = fgetc(input)) != EOF) byte2 = newByte;
  34.             offset = ((byte2 & 0x0F) << 8) | byte1;
  35.             length = (byte2 >> 4) + 3; //this 3 is the minimum copy length
  36.            
  37.             for(i = 0; i < length; i++) {
  38.                 byte1 = buf[offset];
  39.                 fputc(byte1, output);
  40.                 push(buf, byte1);
  41.             }
  42.            
  43.             mask >>= 1;
  44.         } else {
  45.             fputc(byte1, output);
  46.             push(buf, byte1);
  47.             mask >>= 1;
  48.         }
  49.     }
  50.    
  51.     return 0;
  52. }
  53.  
  54. void push(char *array, char c) {
  55.     int i;
  56.    
  57.     //begin loop in 1 because you can't move [0] to [-1]
  58.     for(i = 1; i < BUFFER_SIZE; i++) {
  59.         array[i - 1] = array[i];
  60.     }
  61.    
  62.     array[BUFFER_SIZE - 1] = c;
  63.    
  64. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×