[comp.sys.atari.st] Megamax patches, and version 1.1

braner@batcomputer.tn.cornell.edu (braner) (12/09/86)

[]

I sent my original disks to Megamax, and about 3 weeks later I now have
version 1.1.  This is a very preliminary report on the new version:

The lengths of most of the files on the 2 disks have been changed.
The floating-point comparision bug is fixed.  Mmcc now lets you compile
several files from one command line.  But: I/O redirection from inside
MY COPY of micro-C-Shell still doesn't work!!  Also, the old note about
"Merge, Abandon, Flatten and Load not yet implemented" in MMRCP is still
there (I havn't actually tried MMRCP yet).

The fix for I/O redirection is still the same:

Make MM use other characters instead of '<' and '>' - characters that
MCS ignores.  I chose '_' for input, '^' for output.
This way you gain I/O redirection for YOUR programs from inside MCS -
and it also still works from the desktop - but you have to remember to use
"_infile ^outfile" in BOTH cases.  Akward, since you still have to use
the angle brackets when redirecting MCS programs (as in "ls > file").
But better than nothing! 

The patch (for MM v1.0 and also for v1.1):

Extract initargcv.o from syslib, using "mmlib X syslib initargcv.o".
Use your favorite debugger or whatever (e.g. bth/htb) to change the
following 3 bytes in the file initargc.o (all these places have a
CMP.W #xx,D0, and we change the xx):

	offset	old	new		notes

	 $1AB	$3C	$5F	'<' --> '_'	(input)
	 $1C3	$3E	$5E	'>' --> '^'	(output)
	 $1D5	$3E	$5E	'>' --> '^'	(append with ^^)

Delete initargcv.o from syslib:    "mmlib D syslib initargcv.o".
Put the new version inside syslib: "mmlib R syslib initargc.o".

(The 'D' step MAY be necessary since the TOS filename is shorter
than the original internal name inside syslib - how did they do it?)

Mmdis.ttp has been modified, it needs a new patch:
To fix mmdis.ttp for I/O redirection using '_' and '^':

	offset (1.0)	offset (1.1)		new value

	389D		38A5			5F
	38B1		38B9			5E
	38C1		38C9			5E

It is common to read auxillary data files from a program when it is invoked.
I don't like that, I'd rather have the data inside the program file itself.
One thing that is implemented rather inefficiently in the Megamax C compiler,
though, is INITIALIZED arrays: a separate line of code is compiled to poke
each element's value into the array, instead of having the data as a table
and compiling a loop to read and poke.  (The data could even be left in the
table itself, which would serve as the array, saving memory, but that is
considered gross and dirty by the "authorities": you might want to put some
program some day in ROM, and then it won't work for VARIABLE arrays, so
you have to do it the kinky way ALL the time!)

So, as usual, we have to do it ourselves:
You can put the data inside an asm{} section, in DC.x statements!
You can leave it there as an initialized array:
/*
 * Table of stuff:
 */
extern stuff();
asm {
	DC.W	1,235,678,43,7,0,123,567,123
	etc.
}
	...
	x = ((int *)(&stuff()))[i];
	...
Or, you can read it like a file:
/*
 * Implement a built-in file efficiently.
 *
 *  This function returns consecutive chars
 *   from the built-in file, or ERROR.
 */
int
getb() {
	static int fpos=(-1);
	static int fend=LENGTH;

	if (++fpos >= fend)
		return (ERROR);
asm {
	CLR.W	D0
	LEA	mydata(PC),A0
	ADDA.W	fpos(A4),A0
	MOVE.B	(A0),D0
	UNLK	A6
	RTS
/*
 * The "built-in file" data:
 */
mydata:
	DC.B 0x47,0x40,0x40,0x40,0x40,0x40,0x00,0x40
	DC.B 0x76,0x00,0x28,0x7C,0x28,0x7C,0x28,0x38
	etc.
}		/* end of asm{}		*/
}		/* end of built_in()	*/

WARNING:
++++++++
The number of bytes in the DC.B statements MUST be even
(or you can use DC.W or DC.L - which saves typing too...)!!!
Otherwise the following code will be compiled on an odd address!
(That's right, the compiler (linker?) is rather stupid...)
(Also, most assemblers have a pseudo-opcode such as "EVEN", or ".EVEN",
that you can put at the end so that you won't have to count your bytes.
If there is such a pseudo-code in the Megamax asm{}, I don't know its syntax!
There is no documentation for the asm{} syntax at all!)

- Moshe Braner