summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2017-01-02 12:58:55 +0100
committerYves Fischer <yvesf-git@xapek.org>2017-01-02 12:58:55 +0100
commita0e86733b4ddab6aa886a7cbb8fe9019f99a3459 (patch)
treed2f6fb78372cbb12a4123901383b0fe65795ca20
downloadsharp-mz-a0e86733b4ddab6aa886a7cbb8fe9019f99a3459.tar.gz
sharp-mz-a0e86733b4ddab6aa886a7cbb8fe9019f99a3459.zip
Import from http://www.sharpmz.org/mzf2wav.htm
-rw-r--r--mzf2wav/doc/README.txt11
-rw-r--r--mzf2wav/src/args.c151
-rw-r--r--mzf2wav/src/args.h3
-rw-r--r--mzf2wav/src/linux/Makefile.linux23
-rw-r--r--mzf2wav/src/linux/build.sh8
-rw-r--r--mzf2wav/src/linux/release/mzf2wavbin0 -> 14012 bytes
-rw-r--r--mzf2wav/src/methods.c160
-rw-r--r--mzf2wav/src/methods.h6
-rw-r--r--mzf2wav/src/mzf2wav.c101
-rw-r--r--mzf2wav/src/physical.c160
-rw-r--r--mzf2wav/src/physical.h16
-rw-r--r--mzf2wav/src/wav.c56
-rw-r--r--mzf2wav/src/wav.h30
13 files changed, 725 insertions, 0 deletions
diff --git a/mzf2wav/doc/README.txt b/mzf2wav/doc/README.txt
new file mode 100644
index 0000000..ba2c9b1
--- /dev/null
+++ b/mzf2wav/doc/README.txt
@@ -0,0 +1,11 @@
+Mzf2wav by Jeroen F. J. Laros ( available only at http://www.sharpmz.org ).
+
+This program translates an MZF image to WAV in various ways.
+
+You can find the executable in ../src/release/linux or in ..\src\release\w32.
+
+Run mzf2wav without arguments to get a brief description of its options.
+
+For more information please read mzf2wav.pdf.
+
+There is no permission to copy the files for download services to other servers! \ No newline at end of file
diff --git a/mzf2wav/src/args.c b/mzf2wav/src/args.c
new file mode 100644
index 0000000..0bbf73f
--- /dev/null
+++ b/mzf2wav/src/args.c
@@ -0,0 +1,151 @@
+#include <stdio.h>
+#include <stdlib.h> // Just to remove a warning (exit).
+#include "args.h"
+#include "methods.h"
+
+// Externs.
+extern int speed_1,
+ speed_2,
+ corr_1,
+ corr_2;
+extern char *filename,
+ *outfile;
+extern void (*method)(byte *);
+
+// Private function prototypes.
+int chtoi(char *), // Convert the first char of a string to an integer.
+ stoi(char *); // Convert a string to an integer.
+
+// Private functions.
+// Convert the first char of a string to an integer and check the boundries.
+int chtoi(char *string) {
+ int temp = 0;
+
+ if (!string)
+ return -1;
+ temp = (int)string[0] - 48;
+ if ((temp < 0) || (temp > 4))
+ return -1;
+ return temp;
+}//chtoi
+
+// Convert the a string to an integer and check the boundries.
+int stoi(char *string) {
+ int i = 0,
+ m = 1,
+ temp = 0,
+ ret = 0;
+
+ if (!string)
+ return -100;
+ if (string[0] == '-') {
+ m = -1;
+ i++;
+ }//if
+
+ while (string[i]) {
+ temp = (int)string[i] - 48;
+ if ((temp < 0) || (temp > 9))
+ return -100;
+ ret *= 10;
+ ret += temp;
+ i++;
+ }//while
+ if (ret > 50)
+ return -100;
+ return m * ret;
+}//stoi
+
+// Public functions.
+// Print usage and return an error code.
+void error(int i) {
+ printf("Usage: mzf2wav <-i n> <-t n> <-1 n> <-2 n> <-c> <-s> <-w> in out\n"
+ " -i sets initial speed mode (0, 1, 2, 3 or 4), default = 0.\n"
+ " -t sets turbo speed mode (0, 1, 2, 3 or 4), default = 2.\n"
+ " -1 sets correction for fast initial mode (-50 to 50).\n"
+ " -2 sets correction for fast turbo mode (-50 to 50).\n"
+ " -c sets conventional writing mode.\n"
+ " -s sets fast writing mode (default).\n"
+ " -w sets turbo writing mode.\n"
+ " -p reverse polarity.\n");
+ exit(i);
+}//error
+
+// Set the configuration variables.
+int setvars(int argc, char **argv) {
+ int temp = 0,
+ i = 1;
+
+ while (i < argc) {
+ if (argv[i][0] == '-')
+ switch (argv[i][1]) {
+ case 'i': // Initial write speed.
+ temp = chtoi(argv[i + 1]);
+ if (temp == -1) {
+ printf("No valid initial speed given.\n");
+ error(1);
+ }//if
+ speed_1 = temp;
+ i++;
+ break;
+ case 't': // Turbo write speed.
+ temp = chtoi(argv[i + 1]);
+ if (temp == -1) {
+ printf("No valid turbo speed given.\n");
+ error(1);
+ }//if
+ speed_2 = temp;
+ i++;
+ break;
+ case '1': // Initial fast correction.
+ temp = stoi(argv[i + 1]);
+ if (temp == -100) {
+ printf("No valid fast initial correction given.\n");
+ error(1);
+ }//if
+ corr_1 = temp;
+ i++;
+ break;
+ case '2': // Initial fast correction.
+ temp = stoi(argv[i + 1]);
+ if (temp == -100) {
+ printf("No valid fast turbo correction given.\n");
+ error(1);
+ }//if
+ corr_2 = temp;
+ i++;
+ break;
+ case 'c':
+ method = conv;
+ break;
+ case 's':
+ method = trans;
+ break;
+ case 'w':
+ method = turbo;
+ break;
+ case 'p':
+ reversepol();
+ break;
+ default:
+ printf("Unknown option: %s\n", argv[i]);
+ error(1);
+ }//switch
+ else
+ if (!filename)
+ filename = argv[i];
+ else
+ outfile = argv[i];
+ i++;
+ }//while
+ if (!filename) {
+ printf("No filename given.\n");
+ error(1);
+ }//if
+ if (!outfile) {
+ printf("No output filename given.\n");
+ error(1);
+ }//if
+
+ return 0;
+}//setvars
diff --git a/mzf2wav/src/args.h b/mzf2wav/src/args.h
new file mode 100644
index 0000000..81b7fc9
--- /dev/null
+++ b/mzf2wav/src/args.h
@@ -0,0 +1,3 @@
+// Prototypes.
+int setvars(int, char **); // Set the configuration variables.
+void error(int i); // Print usage and return an error code.
diff --git a/mzf2wav/src/linux/Makefile.linux b/mzf2wav/src/linux/Makefile.linux
new file mode 100644
index 0000000..e744eb1
--- /dev/null
+++ b/mzf2wav/src/linux/Makefile.linux
@@ -0,0 +1,23 @@
+CC = gcc
+CFLAGS = -Wall -O3
+
+EXEC = mzf2wav
+MAIN = mzf2wav.c
+OBJS = physical.o methods.o args.o wav.o
+
+all: $(EXEC)
+
+release: all
+ cp $(EXEC) linux/release
+
+.cc.o:
+ $(CC) $(CFLAGS) -c $<
+
+$(EXEC): $(MAIN) $(OBJS)
+ $(CC) $(CFLAGS) -o $@ $^
+
+clean:
+ rm -f *.o core
+
+realclean: clean
+ rm -f $(EXEC)
diff --git a/mzf2wav/src/linux/build.sh b/mzf2wav/src/linux/build.sh
new file mode 100644
index 0000000..ff3bcf0
--- /dev/null
+++ b/mzf2wav/src/linux/build.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+cp Makefile.linux ../Makefile
+cd ..
+make release
+make realclean
+rm Makefile
+echo If all is well, the executable is in: linux/release
diff --git a/mzf2wav/src/linux/release/mzf2wav b/mzf2wav/src/linux/release/mzf2wav
new file mode 100644
index 0000000..e4c5077
--- /dev/null
+++ b/mzf2wav/src/linux/release/mzf2wav
Binary files differ
diff --git a/mzf2wav/src/methods.c b/mzf2wav/src/methods.c
new file mode 100644
index 0000000..74ffdec
--- /dev/null
+++ b/mzf2wav/src/methods.c
@@ -0,0 +1,160 @@
+#include "methods.h"
+
+// Global variables.
+int speed_2 = 2;
+
+// Defenitions.
+// This is the turbo loader in MZF format.
+byte program[300] = {
+ 0x01, // Program type.
+
+ 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, // Room for the
+ 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, // image name.
+ 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d,
+
+ 0x5a, 0x00, // File size.
+ 0x00, 0xd4, // Load adress.
+ 0x00, 0xd4, // Execution adress.
+ '[', 't', 'u', 'r', 'b', 'o', ']', // The first 7 bytes.
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Room for comment.
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // minus 7 bytes.
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ 0xcd, 0x00, // End Header.
+
+ // Begin Program.
+ 0x3e, 0x08, // D400: LD A, 08h
+ 0xd3, 0xce, // D402: OUT (0ceh), A ; Set video mode?
+
+ 0xe5, // D404: PUSH HL
+
+ 0x21, 0x00, 0x00, // D405: LD HL, 0000h
+ 0xd3, 0xe4, // D408: OUT (0e4h), A ; Bank switch to ROM?
+
+ 0x7e, // D40A: LD A, (HL)
+ 0xd3, 0xe0, // D40B: OUT (0e0h), A ; Bank switch to RAM?
+
+ 0x77, // D40D: LD (HL), A
+ 0x23, // D40E: INC HL
+
+ 0x7c, // D40F: LD A, H
+ 0xfe, 0x10, // D410: CP 10h
+ 0x20, 0xf4, // D412: JR NZ, f4h ; Jump 0xf4 forward if A != 0x10
+
+ 0x3a, 0x4b, 0xd4, // D414: LD A, (d44bh)
+ 0x32, 0x4b, 0x0a, // D417: LD (0a4bh), A ; (0x0a4b) = (0xd44b)
+ 0x3a, 0x4c, 0xd4, // D41A: LD A, (d44ch)
+ 0x32, 0x12, 0x05, // D41D: LD (0512h), A ; (0xd44c) = (0x0512)
+ 0x21, 0x4d, 0xd4, // D420: LD HL, d44dh
+ 0x11, 0x02, 0x11, // D423: LD DE, 1102h
+ 0x01, 0x0d, 0x00, // D426: LD BC, 000dh
+ 0xed, 0xb0, // D429: LDIR ; Copy 0x0d bytes from (HL) to (DE)
+
+ 0xe1, // D42B: POP HL
+
+ 0x7c, // D42C: LD A, H
+ 0xfe, 0xd4, // D42D: CP d4h
+ 0x28, 0x12, // D42F: JR Z, 12h ; Jump to label #1 if A == 0xd4
+
+ 0x2a, 0x04, 0x11, // D431: LD HL, (1104h)
+ 0xd9, // D434: EXX ; BC/DE/HL <-> BC'/DE'/HL'
+ 0x21, 0x00, 0x12, // D435: LD HL, 1200h
+ 0x22, 0x04, 0x11, // D438: LD (1104h), HL
+ 0xcd, 0x2a, 0x00, // D43B: CALL 002ah ; Read data subroutine.
+ 0xd3, 0xe4, // D43E: OUT (0e4h), A ; Bank switch to ROM?
+ 0xc3, 0x9a, 0xe9, // D440: JP e99ah ; Jump to 0xe99a
+
+ 0xcd, 0x2a, 0x00, // D443: CALL (002ah) ; Label #1 (read data sub).
+ 0xd3, 0xe4, // D446: OUT (0e4h), A ; Bank switch to ROM?
+ 0xc3, 0x24, 0x01, // D448: JP (0124h)
+ // End program.
+
+ 0x15, 0x01, // D44B:
+
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Room for the address information
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // + the first 7 bytes of comment.
+};
+
+// Public functions.
+// Transfer file the fast way.
+void trans(byte *image) {
+ word cs = 0x0,
+ fs = getfilesize(image),
+ i = 0x0;
+
+ gap(4000); // Longish gap.
+ tapemark(40); // Long tapemark.
+
+ for (i = 0x0; i < 0x80; i++) // The mzf header.
+ cs += writebyte(image[i]);
+ writecs(cs); // The checksum of the mzf header.
+
+ gap(5000); // Shortish gap.
+ tapemark(20); // Short tapemark.
+
+ cs = 0x0;
+ fs += 0x80;
+ for (i = 0x80; i < fs; i++) // The mzf body.
+ cs += writebyte(image[i]);
+ writecs(cs); // The checksum of the mzf body.
+}//trans
+
+// Transfer the file the conventional way.
+void conv(byte *image) {
+ word cs = 0x0,
+ fs = getfilesize(image),
+ i = 0x0;
+
+ gap(22000); // Long gap.
+ tapemark(40); // Long tapemark.
+
+ for (i = 0x0; i < 0x80; i++) // The mzf header.
+ cs += writebyte(image[i]);
+ writecs(cs); // The checksum of the mzf header.
+
+ gap(256); // 256 short pulses.
+
+ for (i = 0x0; i < 0x80; i++) // The copy of the mzf header.
+ writebyte(image[i]);
+ writecs(cs); // The copy of the checksum of the mzf header.
+
+ gap(11000); // Short gap.
+ tapemark(20); // Short tapemark.
+
+ cs = 0x0;
+ fs += 0x80;
+ for (i = 0x80; i < fs; i++) // The mzf body.
+ cs += writebyte(image[i]);
+ writecs(cs); // The checksum of the body.
+
+ gap(256); // 256 short pulses.
+
+ for (i = 0x80; i < fs; i++) // The copy of the mzf body.
+ writebyte(image[i]);
+ writecs(cs); // The copy of checksum of the body.
+}//conv
+
+// First write a turbo loader, then write the image at high speed.
+void turbo(byte *image) {
+ int j = 0;
+
+ for (j = 0x1; j < 0x12; j++) // Copy the name.
+ program[j] = image[j];
+ for (j = 0x1f; j < 0x80; j++) // Copy the comment.
+ program[j] = image[j];
+ for (j = 0x12; j < 0x1f; j++) // Copy the info.
+ program[j + 0x3b + 0x80] = image[j];
+
+ trans(program);
+ setspeed(speed_2);
+ trans(image);
+}//turbo
diff --git a/mzf2wav/src/methods.h b/mzf2wav/src/methods.h
new file mode 100644
index 0000000..4c8dd82
--- /dev/null
+++ b/mzf2wav/src/methods.h
@@ -0,0 +1,6 @@
+#include "physical.h"
+
+// Prototypes.
+void trans(byte *), // Transfer file fast.
+ conv(byte *), // Transfer file according to conventions.
+ turbo(byte *); // Transfer file in turbo mode.
diff --git a/mzf2wav/src/mzf2wav.c b/mzf2wav/src/mzf2wav.c
new file mode 100644
index 0000000..9440fb5
--- /dev/null
+++ b/mzf2wav/src/mzf2wav.c
@@ -0,0 +1,101 @@
+/*
+ * mzf2wav by: Jeroen F. J. Laros.
+ *
+ * Last change on: Sep 11 2003.
+ *
+ * This program is freeware and may be used without paying any registration
+ * fees. It may be distributed freely provided it is done so using the
+ * original, unmodified version. Usage of parts of the source code is granted,
+ * provided the author is referenced. For private use only. Re-selling or any
+ * commercial use of this program or parts of it is strictly forbidden. The
+ * author is not responsible for any damage or data loss as a result of using
+ * this program.
+ */
+#include <stdio.h>
+#include <stdlib.h> // Just to remove a warning (malloc).
+#include "methods.h"
+#include "args.h"
+
+// Global variables.
+FILE *OUT = NULL;
+int speed_1 = 0;
+char *filename = NULL,
+ *outfile = NULL;
+void (*method)(byte *) = trans;
+
+//Private function prototypes.
+byte *readfile(FILE *); // Read the file into memory.
+
+// Read the file into memory.
+byte *readfile(FILE *IN) {
+ byte *image = (byte *)malloc(2),
+ *temp = NULL;
+ word i = 0,
+ t = 0;
+
+ if (!image)
+ return NULL;
+ while (fread(&image[i], 1, 1, IN)) {
+ temp = (byte *)realloc((byte *)image, i + 2);
+ if (!temp) {
+ free(image);
+ return NULL;
+ }//if
+ image = temp;
+ i++;
+ }//while
+ t = assert(image, i);
+ if (t) {
+ printf("The MZF file size does not match the image size.\n");
+ if (t > 1) {
+ printf("This is not a valid MZF file.\n");
+ free(image);
+ return NULL;
+ }//if
+ }//if
+ return image;
+}//readfile
+
+// Main.
+int main(int argc, char **argv) {
+ FILE *IN = NULL;
+ byte *image = NULL;
+ int i = 0;
+
+ setvars(argc, argv);
+
+ IN = fopen(filename, "rb");
+ if (!IN) {
+ printf("Unable to open file: %s for reading.\n\n", argv[1]);
+ error(2);
+ }//if
+
+ image = readfile(IN);
+ if (!image) {
+ printf("Out of memory or assertion error.\n\n");
+ fclose(IN);
+ error(3);
+ }//if
+ OUT = fopen(outfile, "wb");
+ if (!OUT) {
+ printf("Error: unable to open output file: %s for writing.\n", outfile);
+ free(image);
+ fclose(IN);
+ error(6);
+ }//if
+
+ while (fread(&image[i], 1, 1, IN))
+ i++;
+
+ setspeed(speed_1);
+
+ writewavheader();
+ method(image);
+ setheader();
+
+ fclose(OUT);
+ free(image);
+ fclose(IN);
+
+ return 0;
+}//main
diff --git a/mzf2wav/src/physical.c b/mzf2wav/src/physical.c
new file mode 100644
index 0000000..6224388
--- /dev/null
+++ b/mzf2wav/src/physical.c
@@ -0,0 +1,160 @@
+#include "physical.h"
+
+// Defenitions.
+#define CONTP 0x37a
+extern dword fs;
+
+// Global variables.
+byte ZERO = 0x30,
+ ONE = 0xd0;
+int LONG_UP = 0, // These variables define the long wave.
+ LONG_DOWN = 0,
+ SHORT_UP = 0, // These variables define the short wave.
+ SHORT_DOWN = 0,
+ corr_1 = 0,
+ corr_2 = 0;
+
+// Private function prototypes.
+void lp(void), // Long pulse.
+ sp(void); // Short pulse.
+
+// Private functions.
+// Write a long pulse.
+void lp(void) {
+ int j = 0;
+
+ for (j = 0; j < LONG_UP; j++)
+ outb(ZERO, CONTP);
+ for (j = 0; j < LONG_DOWN; j++)
+ outb(ONE, CONTP);
+ fs += LONG_UP + LONG_DOWN;
+}//lp
+
+// Write a short pulse.
+void sp(void) {
+ int j = 0;
+
+ for (j = 0; j < SHORT_UP; j++)
+ outb(ZERO, CONTP);
+ for (j = 0; j < SHORT_DOWN; j++)
+ outb(ONE, CONTP);
+ fs += SHORT_UP + SHORT_DOWN;
+}//lp
+
+// Public functions.
+// Reverse polarity.
+void reversepol(void) {
+ ZERO = 0xd0;
+ ONE = 0x30;
+}//reversepol
+
+// Write a gap of i short pulses.
+void gap(int i) {
+ int j = 0;
+
+ for (j = 0; j < i; j++)
+ sp();
+}//gap
+
+// Write a tapemark of i long pulses, i short pulses and one long pulse.
+void tapemark(int i) {
+ int j = 0;
+
+ for (j = 0; j < i; j++)
+ lp();
+ for (j = 0; j < i; j++)
+ sp();
+ lp();
+ lp();
+}//tapemark
+
+// Write the checksum.
+void writecs(word cs) {
+ byte i = 0x0;
+ int j = 0;
+
+ cs &= 0xffff;
+ for (j = 0x3; j; j >>= 1) { // for (j = 0; j < 2; j++)
+ for (i = 0xff; i; i >>= 1) { // for (i = 0; i < 8; i++)
+ if (cs & 0x8000) // If the most significant bit is set
+ lp(); // wite a one.
+ else
+ sp(); // Else write a zero.
+ cs <<= 1; // Go to the next bit.
+ }//for
+ lp();
+ }//for
+ lp();
+}//writecs
+
+// Define the waveform to use.
+void setspeed(int i) {
+ switch (i) {
+ case 1: // Fastest in normal mode. Probably unstable...
+ LONG_UP = FAST_LONG_UP + corr_1;
+ LONG_DOWN = FAST_LONG_DOWN + corr_1;
+ SHORT_UP = FAST_SHORT_UP + corr_1;
+ SHORT_DOWN = FAST_SHORT_DOWN + corr_1;
+ break;
+ case 2: // Turbo mode 2x.
+ LONG_UP = TURBO_2_LONG_UP;
+ LONG_DOWN = TURBO_2_LONG_DOWN;
+ SHORT_UP = TURBO_2_SHORT_UP;
+ SHORT_DOWN = TURBO_2_SHORT_DOWN;
+ break;
+ case 3: // Turbo mode 3x.
+ LONG_UP = TURBO_3_LONG_UP;
+ LONG_DOWN = TURBO_3_LONG_DOWN;
+ SHORT_UP = TURBO_3_SHORT_UP;
+ SHORT_DOWN = TURBO_3_SHORT_DOWN;
+ break;
+ case 4: // Fastest in turbo mode. Probably unstable...
+ LONG_UP = TURBO_FAST_LONG_UP;
+ LONG_DOWN = TURBO_FAST_LONG_DOWN + corr_2;
+ SHORT_UP = TURBO_FAST_SHORT_UP;
+ SHORT_DOWN = TURBO_FAST_SHORT_DOWN + corr_2;
+ break;
+ default: // Normal mode.
+ LONG_UP = DEFAULT_LONG_UP;
+ LONG_DOWN = DEFAULT_LONG_DOWN;
+ SHORT_UP = DEFAULT_SHORT_UP;
+ SHORT_DOWN = DEFAULT_SHORT_DOWN;
+ }//switch
+}//setspeed
+
+// Write a byte and count the ones for the checksum.
+word writebyte(byte b) {
+ word cs = 0x0;
+ byte i = 0x0;
+
+ for (i = 0xff; i; i >>= 1) {
+ if (b & 0x80) {
+ lp();
+ cs++;
+ }//if
+ else
+ sp();
+ b <<= 1;
+ }//for
+ lp();
+ return cs;
+}//writebyte
+
+// Get the file size.
+word getfilesize(byte *image) {
+ return image[0x12] | (image[0x13] << 8);
+}//getfilesize
+
+// See if the MZF file is valid.
+int assert(byte *image, word i) {
+ word fs = getfilesize(image);
+
+ if (fs + 0x80 != i) {
+ if (i - fs > 0x200)
+ return 2;
+ if (i < fs)
+ return 2;
+ return 1;
+ }//if
+ return 0;
+}//assert
diff --git a/mzf2wav/src/physical.h b/mzf2wav/src/physical.h
new file mode 100644
index 0000000..c9b6ac9
--- /dev/null
+++ b/mzf2wav/src/physical.h
@@ -0,0 +1,16 @@
+#include "wav.h"
+
+// Defenitions.
+typedef unsigned char byte;
+typedef unsigned short word;
+typedef unsigned int dword;
+
+// Prototypes.
+void reversepol(void), // Reverse polarity.
+ gap(int), // i short pulses.
+ tapemark(int), // i long, i short and two long pulses.
+ writecs(word), // Write the checksum.
+ setspeed(int); // Define the waveform.
+word writebyte(byte), // Write a byte and count the ones.
+ getfilesize(byte *); // Get the file size.
+int assert(byte *, word); // See if the MZF file is valid.
diff --git a/mzf2wav/src/wav.c b/mzf2wav/src/wav.c
new file mode 100644
index 0000000..ba0c3fa
--- /dev/null
+++ b/mzf2wav/src/wav.c
@@ -0,0 +1,56 @@
+#include <stdio.h>
+#include "wav.h"
+#include "physical.h"
+
+// Externs.
+extern FILE *OUT;
+
+// Global variables.
+dword fs = 0;
+// Numbers are little endian.
+byte header[44] = { 'R', 'I', 'F', 'F', // File description header.
+ 0x0, 0x0, 0x0, 0x0, // Filesize - 8.
+ 'W', 'A', 'V', 'E', // "WAVE" Description header.
+ 'f', 'm', 't', ' ', // "fmt " Description header.
+ 0x10, 0x0, 0x0, 0x0, // Size of WAVE section chunck.
+ 0x1, 0x0, // Wave type format.
+ 0x1, 0x0, // Mono or stereo.
+ 0x44, 0xac, 0x0, 0x0, // Sample rate.
+ 0x44, 0xac, 0x0, 0x0, // Bytes per second.
+ 0x1, 0x0, // Block alignment.
+ 0x8, 0x0, // Bits per sample.
+ 'd', 'a', 't', 'a', // "data" Description header.
+ 0x0, 0x0, 0x0, 0x0 }; // Size of data chunk.
+
+
+// Public functions.
+void outb(int value, int port) {
+ fprintf(OUT, "%c", value);
+}//outb
+
+// Write the WAV header.
+void writewavheader(void) {
+ int i = 0;
+
+ for (i = 0; i < 44; i++)
+ fprintf(OUT, "%c", header[i]);
+}//writewavheader
+
+// Set the filesizes in the WAV header.
+void setheader(void) {
+ dword temp = fs;
+ int i = 0;
+
+ fseek(OUT, 4, SEEK_SET);
+ fprintf(OUT, "%c", (temp & 0xff) + 36);
+ fseek(OUT, 40, SEEK_SET);
+ fprintf(OUT, "%c", temp & 0xff);
+ temp >>= 8;
+ for (i = 1; i < 4; i++) {
+ fseek(OUT, 4 + i, SEEK_SET);
+ fprintf(OUT, "%c", temp & 0xff);
+ fseek(OUT, 40 + i, SEEK_SET);
+ fprintf(OUT, "%c", temp & 0xff);
+ temp >>= 8;
+ }//for
+}//setheader
diff --git a/mzf2wav/src/wav.h b/mzf2wav/src/wav.h
new file mode 100644
index 0000000..6d3daa4
--- /dev/null
+++ b/mzf2wav/src/wav.h
@@ -0,0 +1,30 @@
+// Defenitions.
+#define DEFAULT_LONG_UP 21 // Normal mode.
+#define DEFAULT_LONG_DOWN 21
+#define DEFAULT_SHORT_UP 11
+#define DEFAULT_SHORT_DOWN 11
+
+#define FAST_LONG_UP 11 // Fastest in normal mode.
+#define FAST_LONG_DOWN 21
+#define FAST_SHORT_UP 11
+#define FAST_SHORT_DOWN 12
+
+#define TURBO_2_LONG_UP 11 // Turbo 2x.
+#define TURBO_2_LONG_DOWN 11
+#define TURBO_2_SHORT_UP 5
+#define TURBO_2_SHORT_DOWN 6
+
+#define TURBO_3_LONG_UP 7 // Turbo 3x.
+#define TURBO_3_LONG_DOWN 7
+#define TURBO_3_SHORT_UP 3
+#define TURBO_3_SHORT_DOWN 4
+
+#define TURBO_FAST_LONG_UP 3 // Fastest in turbo mode.
+#define TURBO_FAST_LONG_DOWN 7
+#define TURBO_FAST_SHORT_UP 3
+#define TURBO_FAST_SHORT_DOWN 4
+
+// Prototypes.
+void outb(int, int),
+ writewavheader(void),
+ setheader(void);