Guys! I come with a request, which is unusual for me, but it's something that would more than likely take a lot of effort for me to achieve while being extremely simple for someone else to do. This could describe a lot of requests, I suppose, but whatever.
First, the tl;dr part, since this is going to take some explaining. Basically, I need a program - in whichever high-level language you like - that takes a file, and makes a new file based on the amount of bytes between important bytes. Based on that information, it makes a new binary file.
If this sounds a bit abstract, it is: I'm going to explain the whole thing below. But I just wrote that so that anyone who thinks they can do it can continue reading for details, while others can ignore the fluff.
So, now the long explanation. I'm quite big on game preservation, and recently my friend discovered in his collection a game for a computer I'd never even heard of. The computer was the Colour Genie, and the game was a computer version of Monopoly written in BASIC. I'm very much aware that yet another computer Monopoly on a system nobody has heard of - and in BASIC no less - is probably the least interesting thing you could imagine, but as far as I'm aware, it's not been dumped to a tape file to play in an emulator and thus is unpreserved. Yes, there is an emulator, and yes, the computer uses cassette tapes.
Anyway, my friend tried recording it as a WAV file and using a program designed for converting WAVs to tape files, but it just produced a load of gibberish. I knew the principle behind games on cassette was to use pulses to make binary information, ones and zeroes. So I opened the WAV in Wavosaur and zoomed in to see if I could figure it out. I noticed that sometimes the 'line' on the screen crossed the centre once, and sometimes twice, within the same length of time.
There are quite a few working tape files out there, so I was able to see what it's supposed to look like. It didn't take me long to figure out that one pulse is 0 while two pulses means 1. So by literally counting by hand on the screen - "zero, zero, one, one..." and typing that into a hex editor, I discovered, to my amazement, that I was, bit by bit (literally), recreating a BASIC program.
Of course I could do this incredibly tedious process until the end of the game, but I don't think my sanity would hold up. So, I decided to figure out a way I could get a computer to do it for me. I figured that a WAV is still just a simple binary file at heart, and I was right. My friend recorded it in 96khz 8-bit mono, which resulted in a very simple and predictable file: $80 is the centre of the wave (silence) and each sample goes above or below $80, and this constant up-and-down produces sound.
It occurred to me that all I need to know is whether a certain amount of bytes have passed before crossing that centre $80 line. If it came quickly, it must be a 1, and if it took longer, it must be a 0, but eventually it would cross that line. Now, I have no idea how to program in high-level languages, but I do know a thing or two about coding in assembly for 8-bit CPUs, so I know that this would be an incredibly simple procedure. I've decided to explain the logic that the computer will follow:
0 reset counter
1 increment counter
2 load byte
3 is it >= $80?
4 if yes, continue; if no, go to 1
5 load check byte
6 is it zero?
7 if yes, continue; if no, go to B
8 load counter
9 is it >= $48?
A if yes, write 0 bit and continue; if no, write 1 bit, set check byte, continue
B reset counter
C increment counter
D load byte
E is it <= $80?
F if yes, continue; if no, go to C
G load check byte
H is it zero?
I if yes, continue; if no, go to 0
J load counter
K is it >= $48?
L if yes, write 0 bit and go to 0; if no, write 1 bit, set check byte, go to 0
A few explainers: the counter is to count how many bytes have been checked; the check byte is a byte of RAM that is either 1 or 0 to signify that the next crossing of the line is to be ignored (because it's a 1). Everything else should be understandable to anyone who's written routines for the 6502 or similar.
So, put simply, I just want a program that can do this exact thing: go through that routine and make a new file from it. I'd love to do it myself, but I figure I'll need to do quite a bit of basic learning in a high-level language before I can even get there, whereas I could write this in 6502 assembly already - which doesn't really help me.
Sorry for the long explanation. I hope this all makes sense to someone, and I know that there are people active on the forum who could probably knock this kind of thing up in under an hour, although there are advancements that could be made, such as reading the WAV header to determine the frequency and adjust values accordingly, and telling where the program actually starts and ends. But for me, this will do for now. Perhaps someone could point me to a modern programming language I could learn to do it myself - a tutorial that assumes you know how assembly works, for example.
Anyway, I've talked enough. Any help is appreciated!