diff --git a/amiga_bin/mt32-pi-ctl b/amiga_bin/mt32-pi-ctl index d7c1476..a340949 100755 Binary files a/amiga_bin/mt32-pi-ctl and b/amiga_bin/mt32-pi-ctl differ diff --git a/atari_bin/MT32-PI.TTP b/atari_bin/MT32-PI.TTP index 91fd7dc..d7b006d 100755 Binary files a/atari_bin/MT32-PI.TTP and b/atari_bin/MT32-PI.TTP differ diff --git a/common_src/mt32-pi.c b/common_src/mt32-pi.c index 253e08f..6706b70 100644 --- a/common_src/mt32-pi.c +++ b/common_src/mt32-pi.c @@ -34,7 +34,6 @@ #include "midi_dev.h" #include "getopt.h" #include "delay.h" -#include "file_io.h" #include "miniwift.h" #ifndef PROGRAM_NAME @@ -364,15 +363,13 @@ int main(int argc, char *argv[]) { // -Y/--syx FILE.SYX if(syx_fname[0] != '\0') { unsigned char fbuf[512]; - struct file_t fh; - int ret; - + FILE *fh; if(verbose) fprintf(stderr, "Sending %s.\n", syx_fname); - - - ret = fio_open(&fh, syx_fname, FIO_OPEN_RD); - if(ret!=0) { + + + fh = fopen(syx_fname, "rb"); + if(fh == NULL) { fprintf(stderr, "ERROR: Can't open %s.\n", syx_fname); mididev_deinit(); return EXIT_FAILURE; @@ -382,8 +379,8 @@ int main(int argc, char *argv[]) { while(1) { int i, found_start, found_end, start_index, end_index; int n; - long int read_start = fh.curpos; - n = fio_read(&fh, fbuf, 512); + long int read_start = ftell(fh); + n = fread(fbuf, 1, 512, fh); found_start = 0; found_end = 0; @@ -421,11 +418,11 @@ int main(int argc, char *argv[]) { mididev_send_bytes(fbuf+start_index, end_index - start_index+1); // Wait grace period delay_ms(100); - if(read_start + end_index+1 == fh.curpos) + if(read_start + end_index+1 == ftell(fh)) break; - fio_seek(&fh, FIO_SEEK_START, read_start + end_index+1); + fseek(fh, read_start + end_index+1, SEEK_SET); } - fio_close(&fh); + fclose(fh); } mididev_deinit(); @@ -475,38 +472,54 @@ static void bmp_to_sysex_disp_sc55(unsigned char *sysexbuf, const char *fname, i const unsigned char prefix[7] = { 0xF0, 0x41, 0x10, 0x45, 0x12, 0x10, 0x01 }; int i; unsigned char fbuf[64]; - struct file_t fh; - int ret; + FILE *fh; + int flen; unsigned char pix_offset; memset(sysexbuf, '\0', 74); /* Copy SysEx start and display cmd into msg */ memcpy(sysexbuf, prefix, 7); - ret = fio_open(&fh, fname, FIO_OPEN_RD); - if(ret!=0) { + fh = fopen(fname, "rb"); + if(fh == NULL) { fprintf(stderr, "ERROR: Can't open %s.\n", fname); abort(); } // check if this is a BMP - fio_read(&fh, fbuf, 2); + if(!fread(fbuf, 1, 2, fh)) { + fprintf(stderr, "Error reading %s.\n", sc55_bmp_fname); + fclose(fh); + abort(); + } if(!(fbuf[0]=='B' && fbuf[1]=='M')) { fprintf(stderr, "ERROR: %s is not a valid BMP file.\n", sc55_bmp_fname); - fio_close(&fh); + fclose(fh); abort(); } // check offset of pixel array - fio_seek(&fh, FIO_SEEK_START, 0xA); - fio_read(&fh, &pix_offset, 1); - - if(fh.flen - pix_offset < 64) { + fseek(fh, 0xA, SEEK_SET); + if(!fread(&pix_offset, 1, 1, fh)) { + fprintf(stderr, "Error reading %s.\n", sc55_bmp_fname); + fclose(fh); + abort(); + } + + + fseek(fh, 0, SEEK_END); + flen = ftell(fh); + if(flen - pix_offset < 64) { fprintf(stderr, "ERROR: %s seems to be too small in size.\n", sc55_bmp_fname); - fio_close(&fh); + fclose(fh); abort(); } // read pixel array - fio_seek(&fh, FIO_SEEK_START, pix_offset); - fio_read(&fh, fbuf, 64); - fio_close(&fh); + fseek(fh, pix_offset, SEEK_SET); + if(!fread(fbuf, 1, 64, fh)) { + fprintf(stderr, "Error reading %s.\n", sc55_bmp_fname); + fclose(fh); + abort(); + } + + fclose(fh); // Perform bit-manipulation magic to // build the SysEx diff --git a/dos_bin/MT32-PI.EXE b/dos_bin/MT32-PI.EXE index 018c06f..e6805fd 100644 Binary files a/dos_bin/MT32-PI.EXE and b/dos_bin/MT32-PI.EXE differ diff --git a/dos_src/FIO.C b/dos_src/FIO.C deleted file mode 100644 index ac05fbc..0000000 --- a/dos_src/FIO.C +++ /dev/null @@ -1,177 +0,0 @@ -/* - * File I/O, based on the DOSMID source code - * http://dosmid.sourceforge.net - * - * Copyright (C) 2018 Mateusz Viste - * with modifications - * Copyright (C) 2021 Andreas Zdziarstek - */ - -#include /* REGS */ -#include /* _fmemcpy() */ - -#include "file_io.h" - -#define FIO_FLAG_SEEKSYNC 1 - -static void fio_seek_sync(struct file_t *f) { -/* DOS 2+ - LSEEK - SET CURRENT FILE POSITION - AH = 42h - AL = origin of move - 00h start of file - 01h current file position - 02h end of file - BX = file handle - CX:DX = (signed) offset from origin of new file position - Return on success: - CF clear - DX:AX = new file position in bytes from start of file - Return on error: - CF set - AX = error code */ - union REGS regs; - unsigned short *off; - long offset; - if ((f->flags & FIO_FLAG_SEEKSYNC) == 0) return; - offset = f->curpos; - off = (unsigned short *)(&offset); - regs.x.ax = 0x4200u; - regs.x.bx = f->fh; - regs.x.cx = off[1]; - regs.x.dx = off[0]; - int86(0x21, ®s, ®s); - f->flags &= ~FIO_FLAG_SEEKSYNC; - /* if (regs.x.cflag != 0) return(0 - regs.x.ax); - return(((long)regs.x.dx << 16) | regs.x.ax); */ -} - -/* seek to offset position of file pointed at by fhandle. returns current file position on success, a negative error otherwise */ -signed long fio_seek(struct file_t *f, unsigned short origin, signed long offset) { - switch (origin) { - case FIO_SEEK_START: - if (offset < 1) { - f->curpos = 0; - } else { - f->curpos = offset; - } - break; - case FIO_SEEK_END: - f->curpos = f->flen; - case FIO_SEEK_CUR: - f->curpos += offset; - break; - } - f->flags |= FIO_FLAG_SEEKSYNC; - return(f->curpos); -} - -static void loadcache(struct file_t *f) { - union REGS regs; - struct SREGS sregs; - fio_seek_sync(f); - f->flags |= FIO_FLAG_SEEKSYNC; - f->bufoffs = f->curpos; - regs.h.ah = 0x3f; - regs.x.bx = f->fh; - regs.x.cx = FIO_CACHE; - sregs.ds = FP_SEG(f->buff); - regs.x.dx = FP_OFF(f->buff); - int86x(0x21, ®s, ®s, &sregs); -} - -/* open file fname and set fhandle with the associated file handle. returns 0 on success, non-zero otherwise */ -int fio_open(struct file_t *f, const char *fname, int mode) { - /* DOS 2+ - OPEN - OPEN EXISTING FILE - AH = 3Dh - AL = access and sharing modes - DS:DX -> ASCIZ filename - CL = attribute mask of files to look for (server call only) - Return: - CF clear if successful - AX = file handle or error code - CF set on error */ - union REGS regs; - struct SREGS sregs; - /* */ - regs.h.ah = 0x3d; - regs.h.al = mode; - sregs.ds = FP_SEG(fname); - regs.x.dx = FP_OFF(fname); - int86x(0x21, ®s, ®s, &sregs); - f->fh = regs.x.ax; - if (regs.x.cflag != 0) return(-1); - /* */ - f->curpos = 0; - loadcache(f); - /* fseek to end so I know the file length */ - regs.x.ax = 0x4202u; - regs.x.bx = f->fh; - regs.x.cx = 0; - regs.x.dx = 0; - int86(0x21, ®s, ®s); - f->flen = (((long)regs.x.dx << 16) | regs.x.ax); - /* fseek to start */ - regs.x.ax = 0x4200u; - regs.x.bx = f->fh; - regs.x.cx = 0; - regs.x.dx = 0; - int86(0x21, ®s, ®s); - /* */ - f->flags = FIO_FLAG_SEEKSYNC; - return(0); -} - -/* reads count bytes from file pointed at by fhandle, and writes the data into buff. returns the number of bytes actually read, or a negative number on error */ -int fio_read(struct file_t *f, void *buff, int count) { -/* DOS 2+ - READ - READ FROM FILE OR DEVICE - * AH = 3Fh - * BX = file handle - * CX = number of bytes to read - * DS:DX -> buffer for data - * Return: - * CF clear if successful - * AX = number of bytes actually read (0 if at EOF before call) - * CF set on error - * AX = error code (05h,06h) (see #01680 at AH=59h/BX=0000h) */ - union REGS regs; - struct SREGS sregs; - if (f->curpos + count > f->flen) count = f->flen - f->curpos; - if (count == 0) return(0); - if (count <= FIO_CACHE) { - if ((f->curpos < f->bufoffs) || (f->curpos + count > f->bufoffs + FIO_CACHE)) { - loadcache(f); - } - _fmemcpy(buff, f->buff + (f->curpos - f->bufoffs), count); - f->curpos += count; - return(count); - } - fio_seek_sync(f); - regs.h.ah = 0x3f; - regs.x.bx = f->fh; - regs.x.cx = count; - sregs.ds = FP_SEG(buff); - regs.x.dx = FP_OFF(buff); - int86x(0x21, ®s, ®s, &sregs); - if (regs.x.cflag != 0) return(0 - regs.x.ax); - f->curpos += regs.x.ax; - return(regs.x.ax); -} - -/* close file handle. returns 0 on success, non-zero otherwise */ -int fio_close(struct file_t *f) { - /* DOS 2+ - CLOSE - CLOSE FILE - AH = 3Eh - BX = file handle - Return on success: - CF clear - AX destroyed - On error: - CF set - AX = error code */ - union REGS regs; - regs.h.ah = 0x3e; - regs.x.bx = f->fh; - int86(0x21, ®s, ®s); - if (regs.x.cflag != 0) return(0 - regs.x.ax); - return(0); -} diff --git a/dos_src/MAKEFILE b/dos_src/MAKEFILE index f5b4373..73da0f5 100644 --- a/dos_src/MAKEFILE +++ b/dos_src/MAKEFILE @@ -17,7 +17,7 @@ MODE = s all: mt32-pi.exe mt32-pi.exe: ..\COMMON~1\mt32-pi.c mpu401.c midi_dev.c ..\COMMON~1\getopt.c - *wcl -i=..\COMMON~1\ -zp2 -lr -we -d0 -y -0 -s -m$(MODE) -wx -dUSE_CUSTOM_FILE_IO -dUSE_CUSTOM_DELAY -dREPLACE_GETOPT -fe=mt32-pi.exe -fm=mt32-pi.map *.c ..\COMMON~1\*.c + *wcl -i=..\COMMON~1\ -zp2 -lr -we -d0 -y -0 -s -m$(MODE) -wx -dUSE_CUSTOM_DELAY -dREPLACE_GETOPT -fe=mt32-pi.exe -fm=mt32-pi.map *.c ..\COMMON~1\*.c dist: mt32-pi.exe .symbolic UPXCOMP.BAT diff --git a/linux_src/Makefile b/linux_src/Makefile index f53f699..d59e9f7 100644 --- a/linux_src/Makefile +++ b/linux_src/Makefile @@ -35,6 +35,6 @@ clean : .PHONY: dist dist: $(PROGRAM_NAME) - cp -v $(PROGRAM_NAME) ../amiga_bin/ - cp -v *.bmp ../amiga_bin/ + cp -v $(PROGRAM_NAME) ../linux_bin/ + cp -v *.bmp ../linux_bin/ diff --git a/linux_src/mt32pi.bmp b/linux_src/mt32pi.bmp new file mode 100644 index 0000000..f522e07 Binary files /dev/null and b/linux_src/mt32pi.bmp differ diff --git a/win32_bin/mt32-pi-ctl.exe b/win32_bin/mt32-pi-ctl.exe new file mode 100755 index 0000000..99b1b94 Binary files /dev/null and b/win32_bin/mt32-pi-ctl.exe differ diff --git a/win32_bin/mt32pi.bmp b/win32_bin/mt32pi.bmp new file mode 100644 index 0000000..f522e07 Binary files /dev/null and b/win32_bin/mt32pi.bmp differ diff --git a/win32_src/Makefile b/win32_src/Makefile index be9da81..450bf4d 100644 --- a/win32_src/Makefile +++ b/win32_src/Makefile @@ -35,6 +35,6 @@ clean : .PHONY: dist dist: $(PROGRAM_NAME) - cp -v $(PROGRAM_NAME) ../amiga_bin/ - cp -v *.bmp ../amiga_bin/ + cp -v $(PROGRAM_NAME) ../win32_bin/ + cp -v *.bmp ../win32_bin/