[comp.sources.atari.st] v00i049: mwc:all: GULAMFIX - keyboard mod program for gulam shell

atari-sources-request@daisy.UUCP (12/13/87)

Submitted by: sun!mandrill!pm (Prabhaker Mateti)
comp.sources.atari.st: Volume 0, Issue 49
Archive-name: gulamfix1



~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+
[Editor's Note]
	The documentation is pretty much self explainatory, I compiled
and ran this under both megamax C and MWC. The checksums are:

bytes =    10572(    10925)   cksm = 1861   gulamfix.c

~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+~+
/*

	kmpfix.c -- Utility for Gulam

	copyright (c) 1986, 1987 pm@cwru.edu

	Some users have complained that Gulam maps the keyboard in a
'peculiar' way specific to the USA kbd causing nuisance to the
European fans.  Here is a way to re-map the key board.

	Edit the keymap[] table you see below (all 128*3 entries), and
compile.  Run the resulting program on the gulam.prg you currently
have.  The new version of 'gulam.prg' (with the key mapping you chose)
will be written out as 'gulamnew.prg' in the current directory.

Below we define ST520 keynames; the values are the ascii codes
returned by ST BIOS.  The 'key-to-ascii' mapping set up is given in
keymap[]

The values below are chosen to have certain patterns:

	to SHIFT	add 0040
	F1-10		0201 to 0212
	keypad 0-9	0260 to 0272 (subtract -0200 to get ascii digits)
	keypad()/ *-+.cr	add 0300 to the ascii ()/ *-+.cr

Other choices may be better, I don't know.  However, I think it is
unwise to use numbers in the range 0000 to 0177, because they are
regular ascii codes.

*/

#define F1	0201
#define F2	0202
#define F3	0203
#define F4	0204
#define F5	0205
#define F6      0206
#define F7	0207
#define F8	0210
#define F9	0211
#define F10	0212

#define HELP    0213
#define UNDO	0214
#define INSERT	0215
#define HOME	0216

#define UPARRO	0273
#define DNARRO	0274
#define LTARRO	0275
#define RTARRO	0276

#define	KLP	0300
#define	KRP	0301
#define	KSTAR	0302
#define	KPLUS	0303
#define	KENTER	0304
#define	KMINUS	0305
#define	KDOT	0306
#define	KSLASH	0307

#define	K0	0260
#define	K1	0261
#define	K2	0262
#define	K3	0263
#define	K4	0264
#define	K5	0265
#define	K6	0266
#define	K7	0267
#define	K8	0270
#define	K9	0271


/* The above are the unshifted values.  Shifted, as well as
'capslocked' (for only these keys) values that I use are these +0040.
*/

#define SHIFTED 0040

/* The distributed beta-version 1.00.00.02 has the following key map.
Edit it to reflect your taste/needs */

	static
char	keymap[128*3] = {
	/* -------scan codes: 0x00-0x0f ---------------------------- */
	'\000' /*nul*/, '\033' /*esc*/, 	
	'\061' /*1*/, '\062' /*2*/, '\063' /*3*/,
	'\064' /*4*/, '\065' /*5*/, '\066' /*6*/, '\067' /*7*/,
	'\070' /*8*/, '\071' /*9*/, '\060' /*0*/, 
	'\055' /*-*/, '\075' /*=*/,
	'\010' /* bs*/, '\011' /* ht*/, 

	/* ------------------ 0x10-0x1f ---------------------------- */
	'\161' /*q*/, '\167' /*w*/, '\145' /*e*/, '\162' /*r*/,
	'\164' /*t*/, '\171' /*y*/, '\165' /*u*/, '\151' /*i*/,
	'\157' /*o*/, '\160' /*p*/,
	'\133' /*[*/, '\135' /*]*/, 
	'\015' /* cr*/, '\000' /*ctrl*/,
	'\141' /*a*/, '\163' /*s*/, 

	/* ------------------ 0x20-0x2f ---------------------------- */
	'\144' /*d*/, '\146' /*f*/, '\147' /*g*/, '\150' /*h*/,
	'\152' /*j*/, '\153' /*k*/, '\154' /*l*/,
	'\073' /*;*/, '\047' /*'*/, '\140' /*`*/,
	'\000' /*lshift*/,
	'\134' /*\*/,
	'\172' /*z*/, '\170' /*x*/, '\143' /*c*/,  '\166' /*v*/,

	/* ------------------ 0x30-0x3f ---------------------------- */
	'\142' /*b*/, '\156' /*n*/, '\155' /*m*/,
	'\054' /*,*/, '\056' /*.*/, '\057' /* / */,
	'\000' /*rshift*/, '\000' /*unused*/, '\000' /*alt*/,
	'\040' /*space*/,
	'\000' /*caps lock*/,
	F1, F2, F3, F4, F5,


	/* ------------------ 0x40-0x4f ---------------------------- */
	F6, F7, F8, F9, F10,
	'\000' /*unused*/, '\000' /*unused*/,
	HOME,	UPARRO,	'\000' /*unused*/,
	KMINUS,	LTARRO,	'\000' /*unused*/,
	RTARRO,	KPLUS,	'\000' /*unused*/,

	/* ------------------ 0x50-0x5f ---------------------------- */
	DNARRO,	'\000' /*unused*/,	INSERT,	'\177' /*del*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,

	/* ------------------ 0x60-0x6f ---------------------------- */
	'\000' /*ISO key*/,
	UNDO,	HELP,	KLP,	KRP,	KSLASH,	KSTAR,
	K7,	K8,	K9,	K4,	K5,	K6,
	K1,	K2,	K3,

	/* ------------------ 0x70-0x72 ---------------------------- */
	K0,	KDOT,	KENTER,

	/* ------------------ 0x73-0x7f  undefined ----------------- */
	'\000','\000','\000','\000','\000','\000','\000','\000',
	'\000','\000','\000','\000','\000',
/**
 };


static
char	shif[128] = {
**/
	/* ------------------ 0x00-0x0f ---------------------------- */
	'\000' /*nul*/, '\033' /*esc*/, 	
	'\041' /*!*/, '\100' /*@*/,  '\043' /*#*/, '\044' /*$*/,
	'\045' /*%*/, '\136' /*^*/, '\046' /*&*/, '\052' /***/,
	'\050' /*(*/, '\051' /*)*/, '\137' /*_*/, '\053' /*+*/,
	'\010' /* bs*/, '\011' /* ht*/, 

	/* ------------------ 0x10-0x1f ---------------------------- */
	'\121' /*Q*/, '\127' /*W*/, '\105' /*E*/, '\122' /*R*/,
	'\124' /*T*/, '\131' /*Y*/, '\125' /*U*/, '\111' /*I*/,
	'\117' /*O*/, '\120' /*P*/,
	'\173' /*{*/, '\175' /*}*/, 
	'\015' /* cr*/, '\000' /*ctrl*/,
	'\101' /*A*/, '\123' /*S*/, 

	/* ------------------ 0x20-0x2f ---------------------------- */
	'\104' /*D*/, '\106' /*F*/, '\107' /*G*/, '\110' /*H*/,
	'\112' /*J*/, '\113' /*K*/, '\114' /*L*/,
	'\072' /*:*/, '\042' /*"*/, '\176' /*~*/,
	'\000' /*lshift*/,
	'\174' /*|*/,
	'\132' /*Z*/, '\130' /*X*/, '\103' /*C*/,  '\126' /*V*/,

	/* ------------------ 0x30-0x3f ---------------------------- */
	'\102' /*B*/, '\116' /*N*/, '\115' /*M*/,
	'\074' /*<*/, '\076' /*.*/, '\077' /* ? */,
	'\000' /*rshift*/, '\000' /*unused*/, '\000' /*alt*/,
	'\040' /*space*/,
	'\000' /*caps lock*/,
	F1+SHIFTED, F2+SHIFTED, F3+SHIFTED, F4+SHIFTED, F5+SHIFTED,


	/* ------------------ 0x40-0x4f ---------------------------- */
	F6+SHIFTED, F7+SHIFTED, F8+SHIFTED, F9+SHIFTED, F10+SHIFTED,
	'\000' /*unused*/, '\000' /*unused*/,
	HOME+SHIFTED,	UPARRO+SHIFTED,	'\000' /*unused*/,
	KMINUS+SHIFTED,LTARRO+SHIFTED,	'\000' /*unused*/,
	RTARRO+SHIFTED,KPLUS+SHIFTED,	'\000' /*unused*/,

	/* ------------------ 0x50-0x5f ---------------------------- */
	DNARRO+SHIFTED,	'\000' /*unused*/,
	INSERT+SHIFTED,	'\177' /*del*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,

	/* ------------------ 0x60-0x6f ---------------------------- */
	'\000' /*ISO key*/,
	UNDO+SHIFTED,	HELP+SHIFTED,	KLP+SHIFTED,
	KRP+SHIFTED,	KSLASH+SHIFTED,KSTAR+SHIFTED,
	K7+SHIFTED,	K8+SHIFTED,	K9+SHIFTED,
	K4+SHIFTED,	K5+SHIFTED,	K6+SHIFTED,
	K1+SHIFTED,	K2+SHIFTED,	K3+SHIFTED,

	/* ------------------ 0x70-0x72 ---------------------------- */
	K0+SHIFTED,	KDOT+SHIFTED,	KENTER+SHIFTED,

	/* ------------------ 0x73-0x7f  undefined ----------------- */
	'\000','\000','\000','\000','\000','\000','\000','\000',
	'\000','\000','\000','\000','\000',
/**
};

static
char	caps[128] = {
**/
	/* ------------------ 0x00-0x0f ---------------------------- */
	'\000' /*nul*/, '\033' /*esc*/, 	
	'\061' /*1*/, '\062' /*2*/, '\063' /*3*/,
	'\064' /*4*/, '\065' /*5*/, '\066' /*6*/, '\067' /*7*/,
	'\070' /*8*/, '\071' /*9*/, '\060' /*0*/, 
	'\055' /*-*/, '\075' /*=*/,
	'\010' /* bs*/, '\011' /* ht*/, 

	/* ------------------ 0x10-0x1f ---------------------------- */
	'\121' /*Q*/, '\127' /*W*/, '\105' /*E*/, '\122' /*R*/,
	'\124' /*T*/, '\131' /*Y*/, '\125' /*U*/, '\111' /*I*/,
	'\117' /*O*/, '\120' /*P*/,
	'\133' /*[*/, '\135' /*]*/, 
	'\015' /* cr*/, '\000' /*ctrl*/,
	'\101' /*A*/, '\123' /*S*/, 

	/* ------------------ 0x20-0x2f ---------------------------- */
	'\104' /*D*/, '\106' /*F*/, '\107' /*G*/, '\110' /*H*/,
	'\112' /*J*/, '\113' /*K*/, '\114' /*L*/,
	'\073' /*;*/, '\047' /*'*/, '\140' /*`*/,
	'\000' /*lshift*/,
	'\134' /*\*/,
	'\132' /*Z*/, '\130' /*X*/, '\103' /*C*/,  '\126' /*V*/,

	/* ------------------ 0x30-0x3f ---------------------------- */
	'\102' /*B*/, '\116' /*N*/, '\115' /*M*/,
	'\054' /*,*/, '\056' /*.*/, '\057' /* / */,
	'\000' /*rshift*/, '\000' /*unused*/, '\000' /*alt*/,
	'\040' /*space*/,
	'\000' /*caps lock*/,
	F1, F2, F3, F4, F5,


	/* ------------------ 0x40-0x4f ---------------------------- */
	F6, F7, F8, F9, F10,
	'\000' /*unused*/, '\000' /*unused*/,
	HOME,	UPARRO,	'\000' /*unused*/,
	KMINUS,	LTARRO,	'\000' /*unused*/,
	RTARRO,	KPLUS,	'\000' /*unused*/,

	/* ------------------ 0x50-0x5f ---------------------------- */
	DNARRO,	'\000' /*unused*/,	INSERT,	'\177' /*del*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,
	'\000' /*unused*/,'\000' /*unused*/,'\000' /*unused*/,

	/* ------------------ 0x60-0x6f ---------------------------- */
	'\000' /*ISO key*/,
	UNDO,	HELP,	KLP,	KRP,	KSLASH,	KSTAR,
	K7,	K8,	K9,	K4,	K5,	K6,
	K1,	K2,	K3,

	/* ------------------ 0x70-0x72 ---------------------------- */
	K0,	KDOT,	KENTER,

	/* ------------------ 0x73-0x7f  undefined ----------------- */
	'\000','\000','\000','\000','\000','\000','\000','\000',
	'\000','\000','\000','\000','\000'

};

#include <osbind.h>

/* Return offset in the binary file gulam.prg where the keymap[] begins.
74844L is this number valid for beta-version 1.00.00.02 */

	char *
kmpbgn(buf, n)
register char	*buf;
register long	n;
{
	/* kmp[] is extracted from Gulam's src; do NOT change it. */
	static char	kmp[16] = {
		/* -------scan codes: 0x00-0x0f --------------- */
		'\000' /*nul*/, '\033' /*esc*/, 	
		'\061' /*1*/, '\062' /*2*/, '\063' /*3*/,
		'\064' /*4*/, '\065' /*5*/, '\066' /*6*/, '\067' /*7*/,
		'\070' /*8*/, '\071' /*9*/, '\060' /*0*/, 
		'\055' /*-*/, '\075' /*=*/,
		'\010' /* bs*/, '\011' /* ht*/
	};

	register long	i;
	register int	j;
	register char	*p, *q;

	for (i = 0L; i < n; i++)
	{	p = &buf[i]; q = kmp;
		for (j = 0; j < 16; j++)
			if (*p++ != *q++) break;
		if (j == 16) goto found;
	}
	printf("key map bgn not found! aborting...\n");
	exit(-1);

	found:	printf("key map begins at byte %ld\r\n", i);
	return	&buf[i];
}


main()
{
	register char	*buf, *p, *q;
	register int	i;
	register long	n, m;
	register unsigned long lsz;

	lsz  = 90000L;
	buf = (char *) Malloc(lsz);	if (buf == 0L) goto error;

	/* read all of gulam.prg into buf */
	i = Fopen("gulam.prg", 0);
	if (i <= 0) {printf("gulam.prg not found\n"); goto error;}
	n =  Fread(i, lsz, buf);	if (n <= 0L) goto error;
        Fclose(i);

	/* fix the 128*3 bytes of keymap[] */
	p = keymap; q = kmpbgn(buf, n);
	for (i=0; i < 128*3; i++) *q++ = *p++;

	/* write the new gulam.prg out */
	i = Fcreate("gulamnew.prg", 0);
	if (i <= 0)
	{error:
		printf("** could not create gulamnew.prg **\n");
		exit(-2);
	}
	printf("new version of gulam is gulamnew.prg ");	
	m =  Fwrite(i, n, buf);	if (m != n) goto error;
        Fclose(i);
	printf("\n");
}

/* -eof- */