Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //(WIP) Aconcagua (PSX) text decompressor (and compressor later)
- //First argument is input file and second argument is output file
- #include <stdio.h>
- #define BUFFER_SIZE 4096
- void push(char*, char);
- int main(int argc, char **argv) {
- FILE *input, *output;
- short int i;
- unsigned short int mask = 0;
- unsigned short int offset;
- char buf[BUFFER_SIZE];
- unsigned char newByte, byte1, byte2, length;
- for(i = 0; i < BUFFER_SIZE; i++) {
- buf[i] = 0x0;
- }
- if ((input = fopen(argv[1], "rb")) == NULL) {
- printf("? %s\n", argv[1]); return 1;
- }
- if ((output = fopen(argv[2], "wb")) == NULL) {
- printf("? %s\n", argv[2]); return 1;
- }
- while((byte1 = fgetc(input)) != EOF) {
- if(!(mask & 0x0100)) {
- mask = byte1 | 0xFF00;
- } else if (mask & 0x01) {
- if ((newByte = fgetc(input)) != EOF) byte2 = newByte;
- offset = ((byte2 & 0x0F) << 8) | byte1;
- length = (byte2 >> 4) + 3; //this 3 is the minimum copy length
- for(i = 0; i < length; i++) {
- byte1 = buf[offset];
- fputc(byte1, output);
- push(buf, byte1);
- }
- mask >>= 1;
- } else {
- fputc(byte1, output);
- push(buf, byte1);
- mask >>= 1;
- }
- }
- return 0;
- }
- void push(char *array, char c) {
- int i;
- //begin loop in 1 because you can't move [0] to [-1]
- for(i = 1; i < BUFFER_SIZE; i++) {
- array[i - 1] = array[i];
- }
- array[BUFFER_SIZE - 1] = c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement