Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintStream;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.Scanner;
- import java.io.FileOutputStream;
- public class Song_Helper {
- public static String toHex(long a) {
- //Laziness, it's easier to write
- //toHex(asdf) than "asdf.whatever"
- String result = Long.toString(a, 16);
- return result.toUpperCase();
- }
- public static void main(String[] args) throws IOException {
- FileInputStream songReader = new FileInputStream(new File("song.gba"));
- FileOutputStream songWriter = new FileOutputStream("song.dmp");
- PrintStream dataWriter = new PrintStream("data.txt");
- Scanner inputScanner = new Scanner(System.in);
- final int TOTAL_LENGTH = songReader.available();
- final int SONG_BEGIN = 0x1B3BB8;
- final int HEADER_CMD = 0x0A;
- final int END_TRACK_CMD = 0xB1;
- //final int LOOP_TRACK_CMD = 0xB2;
- //final int VOLUME_CMD = 0xBC;
- //final int SET_INST_CMD = 0xBD;
- //A lot of the commented code is just leftover. They may
- //be used for an update in the possibly near future.
- songReader.skip(SONG_BEGIN);
- final int SONG_LENGTH = songReader.available();
- int first, second, third, fourth;
- int tracks;
- int tracknum = 1;
- System.out.print("How many tracks? ");
- tracks = inputScanner.nextInt();
- //System.out.print("\nWrite to where? 0x");
- //int writeOffset = inputScanner.nextInt(16);
- //System.out.print("\n Where is the instrument map?");
- dataWriter.println("Track " + tracknum + " is at 0x" + toHex(SONG_BEGIN));
- int trackArray[] = new int[tracks];
- int headerOffset;
- int currentOffset = TOTAL_LENGTH - songReader.available();
- final boolean WORD_ALIGNED = currentOffset%4 == 0;
- //I know this is ugly, but I couldn't think of
- //a better (read: easier for me to find) way
- //to organize all these variables.
- while (tracknum < tracks)
- {
- int single = songReader.read(); //Yeah, yeah, sloppy. It's a failsafe as far as I'm concerned.
- songWriter.write(single);
- int trackOffset = currentOffset + 1;
- currentOffset = TOTAL_LENGTH - songReader.available();
- if(single == END_TRACK_CMD)
- {
- trackArray[tracknum] = currentOffset;
- ++tracknum;
- dataWriter.println("Track " + tracknum + " is at offset 0x" + toHex(trackOffset));
- }
- }
- currentOffset = TOTAL_LENGTH - songReader.available();
- do
- {
- songReader.read();
- currentOffset = TOTAL_LENGTH - songReader.available();
- } while (/*!WORD_ALIGNED*/ songReader.read() != tracks);
- headerOffset = currentOffset;
- dataWriter.println("\nHeader is at offset 0x" + toHex(headerOffset));
- System.out.println("\nDone.\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment