home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 2
/
CDPD_II_2352.bin
/
scope
/
201-220
/
scopedisk218
/
fastmax3
/
fastmax.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-27
|
7KB
|
190 lines
/*============================================================================*/
/* FastMax.c version 3, written by John O'Leary, 90.5.28 */
/* Must be compiled so that parameters are passed on the stack */
/* and function return values are passed back in D0 */
/* and size of char == byte, short == word, long == longword */
/*============================================================================*/
#include <stdio.h>
#include <stdlib.h>
FILE * F;
char * InFile = "A-Max Startup";
char * BackupFile = "Original A-Max Startup";
char * OutFile = "A-Max Fast Startup";
char * ROMsFile = "Mac ROMs";
unsigned short far Buffer [40000], far ROMs [1 << 16];
extern far ReadFile;
unsigned long (* ReadROM) (unsigned short *, long);
/* ReadROM is a pointer to a function returning an unsigned long value */
unsigned long ROM_ID, ROMSize, FileSize, Start, Finish, I;
void main (int, char * []);
void CleanUp (unsigned short int, char *, char *, char *);
/*============================================================================*/
void main (argc, argv)
int argc;
char * argv [];
{
if (argc > 1 & argv [1] [0] == '?' | argc > 3)
CleanUp (0, "A-Max program patch\nUSAGE: ", argv [0],
" [Original_filename [Backup_filename]]\n");
if (argc > 1) InFile = argv [1];
if (argc > 2) BackupFile = argv [2];
/*------------------------------------------------------------------------------
Read original program file
------------------------------------------------------------------------------*/
if ((F = fopen (InFile, "r")) == 0)
CleanUp (0, "Couldn't open file '", InFile, "' for input\n");
printf ("Reading original program file '%s'... ", InFile);
FileSize = fread ((unsigned char *) Buffer, 2, 40000, F);
fclose (F);
if (FileSize == 0)
CleanUp (0, "error.\n", "", "");
printf ("%ld bytes.\n", FileSize * 2);
/*------------------------------------------------------------------------------
Search for beginning and end of ReadROM routine
------------------------------------------------------------------------------*/
printf ("Searching program for ReadROM routine... ");
for (Start = 0;
Buffer [Start] != 0x48E7 | Buffer [Start+1] != 0x7FFE |
Buffer [Start+2] != 0x7804 | Buffer [Start+3] != 0x206F;
Start ++)
if (Start >= FileSize-100)
CleanUp (0, "not found.\n", "", "");
/* Start is index of first word of ReadROM routine */
for (Finish = Start+10;
Buffer [Finish-3] != 0xE3EB | Buffer [Finish-2] != 0xE7EF |
Buffer [Finish-1] != 0xF3FB | Buffer [Finish] != 0xF7FF;
Finish ++)
if (Finish >= FileSize-1)
CleanUp (0, "not found.\n", "", "");
/* Finish is index of word immediately following ReadROM routine */
/*------------------------------------------------------------------------------
Patch (DiskResource -> dr_Flags) handling in ReadROM routine
of A-Max version 1 for compatibility with SetPatch
------------------------------------------------------------------------------*/
for (I = Start; I < Finish; I ++)
if (Buffer [I] == 0x08E9 & Buffer [I+1] == 0x0007)
Buffer [I] = 0x0829; /* replace BSET with BTST */
printf ("found.\n");
/*------------------------------------------------------------------------------
Call original ReadROM routine with pointer to ROMs buffer and
zero longword (needed by ReadROM of A-Max version > 2.0) on the stack
Amigas with MMUs may not like this!
------------------------------------------------------------------------------*/
printf ("WARNING: Interrupts will be disabled for up to 30 seconds... Press RETURN");
getchar ();
printf ("Looking for Macintosh ROMs... ");
ReadROM = (unsigned long (*) ()) & Buffer [Start];
ROM_ID = ReadROM (ROMs, 0L);
/*------------------------------------------------------------------------------
The ROM ID is returned in D0
High word == 0x69 for 64K ROMs, 0x75 for 128K ROMs
Low word == bit number for drive SEL
------------------------------------------------------------------------------*/
if (ROM_ID >> 16 == 0x69)
ROMSize = 1 << 15 /* 32 Kwords */;
else if (ROM_ID >> 16 == 0x75)
ROMSize = 1 << 16 /* 64 Kwords */;
else
CleanUp (0, "not found.\n", "", "");
printf ("%dK ROMs found in drive number %d\n",
(short) (ROMSize >> 9), (short) ROM_ID - 3);
/*------------------------------------------------------------------------------
Write ROM ID and contents of ROMs to file
------------------------------------------------------------------------------*/
if ((F = fopen (ROMsFile, "w")) == 0)
CleanUp (0, "couldn't open file '", ROMsFile, "' for output\n");
printf ("Writing contents of ROMs to file '%s'... ", ROMsFile);
if (fwrite ((unsigned char *) & ROM_ID, 4, 1, F) != 1)
CleanUp (1, "error.\n", "", "");
if (fwrite ((unsigned char *) ROMs, 2, ROMSize, F) != ROMSize)
CleanUp (1, "error.\n", "", "");
fclose (F);
printf ("done.\n");
/*------------------------------------------------------------------------------
Write new program file, with ReadROM replaced by ReadFile routine
------------------------------------------------------------------------------*/
if ((F = fopen (OutFile, "w")) == 0)
CleanUp (0, "couldn't open file '", OutFile, "' for output\n");
printf ("Writing patched program file '%s'... ", OutFile);
if (fwrite ((unsigned char *) Buffer, 2, Start, F) != Start)
CleanUp (2, "error.\n", "", "");
if (fwrite ((unsigned char *) & ReadFile, 2, Finish - Start, F) != Finish - Start)
CleanUp (2, "error.\n", "", "");
if (fwrite ((unsigned char *) & Buffer [Finish], 2, FileSize - Finish, F) != FileSize - Finish)
CleanUp (2, "error.\n", "", "");
printf ("done.\n");
fclose (F);
/*------------------------------------------------------------------------------
Backup original program file
------------------------------------------------------------------------------*/
printf ("Backing up original '%s' to '%s'... ", InFile, BackupFile);
remove (BackupFile);
if (rename (InFile, BackupFile) != 0)
CleanUp (0, "couldn't rename file.\n", "", "");
printf ("done.\n");
/*------------------------------------------------------------------------------
Rename patched program file
------------------------------------------------------------------------------*/
printf ("Renaming new file '%s' as '%s'... ", OutFile, InFile);
if (rename (OutFile, InFile) != 0)
CleanUp (0, "couldn't rename file.\n", "", "");
printf ("done.\n");
}
/*============================================================================*/
void CleanUp (Level, Message1, Message2, Message3)
unsigned short int Level;
char * Message1, * Message2, * Message3;
{
printf (Message1);
printf (Message2);
printf (Message3);
switch (Level)
{
case (2):
fclose (F);
remove (OutFile);
printf ("%s deleted.\n", OutFile);
break;
case (1):
fclose (F);
remove (ROMsFile);
printf ("%s deleted.\n", ROMsFile);
break;
}
exit (20 + Level);
}