larry@JPL-VLSI.ARPA (08/27/86)
[99 lines]
Contrary to a statement made in this forum a couple of weeks ago, Microsoft
C 3.0 does have a small code/large memory model. You simply compile with
option -Asfd. All data references will then be 32-bit. You must then link
in the large-memory library (LLIBC, etc.).
That seemed wasteful to me, since the only 32-bit references microEmacs
needs are to lines. Also, version 3.7 is nearing the 64K mark which would
require large-code as well as large-data compilation, which would be even
more wasteful and slow. So I did the following (which would probably be
necessary in MSC 4.0 as well).
In estruct.h
------------
Added the following as the last configuration option
#define MIXMEM 1 /* For MS C only, 32-bit LINE pointers */
Added the following just after #define TAB 0x09
#if MIXMEM
#define LINE struct line far /* Must use defines; MSC 3.0 */
#define CHAR char far /* misinterprets far typedefs. */
#define MALLOC _fmalloc /* Long-pntr routines available */
#define FREE _ffree /* under small-memory model. */
/* Small-mem strncpy won't work */
#define STRNCPY(d, s, n) {register unsigned int i; \
for (i=0; i<(n); i++) \
(d)[i] = (s)[i]; \
}
#else
#define LINE struct line
#define CHAR char
#define MALLOC malloc
#define FREE free
#define STRNCPY(dest, src, n) strncpy(dest, src, n)
#endif
Replaced the typedef of LINE with the following.
struct line {
LINE *l_fp; /* Link to the next line */
LINE *l_bp; /* Link to the previous line */
short l_size; /* Allocated size */
short l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
};
Notice that I replaced the "struct LINE" declarations with "LINE" in two
places here. I also did that everywhere else: in estruct.h in the typedefs
of WINDOW, BUFFER, and REGION; in exec.c on line 81. File edef.h has to be
changed to match the new estruct.h.
edef.h
------
Added the following right after the declaration char *malloc();
void free();
#if MIXMEM
CHAR *_fmalloc(); /* Long-pntr routines available */
void _ffree(); /* under small-memory model. */
#endif
At this point all references to LINE will now be far pointers. A number of
references to "char *" "free" and "malloc" also have to be changed to "CHAR*"
"FREE" and "MALLOC" (line numbers are shown in square brackets).
buffer.c
--------
[129] FREE((CHAR *) bp->b_linep); /* Release header line. */
fileio.c
--------
[71]CHAR *buf;
line.c
------
[33] CHAR *MALLOC();
[38] if ((lp = (LINE *) MALLOC(sizeof(LINE)+size)) == NULL) {
[89] FREE((CHAR *) lp);
[138] register CHAR *cp1;
[139] register CHAR *cp2;
[184] FREE((CHAR *) lp1);
[224] register CHAR *cp1;
[225] register CHAR *cp2;
[283] register CHAR *cp1;
[284] register CHAR *cp2;
[352] register CHAR *cp1;
[353] register CHAR *cp2;
[390] FREE((CHAR *) lp2);
[424] FREE((CHAR *) lp1);
[425] FREE((CHAR *) lp2);
random.c
--------
[240] register CHAR *cptr; /* string pointer into text to copy */
The last thing to do is change "strncpy" to "STRNCPY" in two places in
exec.c and you're ready to recompile and relink.
Larry @ jpl-vlsi.arpa