[comp.sys.cbm] C Power Utility routines

mat@emcard.UUCP (Mat Waites) (06/15/88)

I got this reply to a previous posting of mine from:

ames!pacbell!att!mtgzz!bjh@handies.ucar.edu

and I couldn't get email through to the responder, so I'm posting a
response.

I think the code might be useful to alot of people, anyway.

I told him to:
>ps. just get power C...

And he responded:

Yes, I agree, but tell me a easy automatic way to do code overlay
with Power C.  I kludged something up, but it requires hand linking
of the overlay modules.                 .....BJ


Here is a shar of some code for Power C to do program chaining and
loading of machine language files. I've also included filters for
converting back and forth between "real" ascii and cbm ascii.
Note that these are strictly filters and so you must cat your files
into them and redirect the output.

I got the two loading routines off of the ProLine bbs, and have not
tried them myself.

Good Luck

Mat



#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  asctocbm.c
#	  cbmtoasc.c
#	  chain.c
#	  dosload.c
#
echo "x - extracting asctocbm.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > asctocbm.c &&
X/* asctocbm.c - convert real ascii to cbm ascii */
X
X#include <stdio.h>
X#include <ctype.h>
X
Xmain()
X{
X	int c, a;
X
X	while((c=getchar()) != EOF)
X		{
X		if(c == '\n')
X			{
X			a = '\r';
X			}
X		else if(c >= 'a' && c <= 'z')
X			{
X			a = c - 'a' + 'A';
X			}
X		else if(c >= 'A' && c <= 'Z')
X			{
X			a = c - 'A' + 193;
X			}
X		else if(c == '~')
X			{
X			a = 175;
X			}
X		else if(c == '{')
X			{
X			a = 219;
X			}
X		else if(c == '}')
X			{
X			a = 221;
X			}
X		else if(c == '|')
X			{
X			a = 223;
X			}
X		else if(isprint(c))
X			{
X			a = c;
X			}
X		else if(c == 0)
X			{
X			continue;
X			}
X		else
X			{
X			printf("{{%d}}", c);
X			continue;
X			}
X		putchar(a);
X		}
X}
X
SHAR_EOF
chmod 0660 asctocbm.c || echo "restore of asctocbm.c fails"
echo "x - extracting cbmtoasc.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > cbmtoasc.c &&
X/* cbmtoasc.c - convert cbm ascii to real ascii */
X
X#include <stdio.h>
X#include <ctype.h>
X
Xmain()
X{
X	int c, a;
X
X	while((c=getchar()) != EOF)
X		{
X		if(c == '\r')
X			{
X			a = '\n';
X			}
X		else if(c >= 'A' && c <= 'Z')
X			{
X			a = c - 'A' + 'a';
X			}
X		else if(c >= 193 && c <= 218)
X			{
X			a = c - 193 + 'A';
X			}
X		else if(c == 175)
X			{
X			a = '~';
X			}
X		else if(c == 219)
X			{
X			a = '{';
X			}
X		else if(c == 221)
X			{
X			a = '}';
X			}
X		else if(c == 223)
X			{
X			a = '|';
X			}
X		else if(isprint(c))
X			{
X			a = c;
X			}
X		else if(c == 0)
X			{
X			continue;
X			}
X		else
X			{
X			printf("{{%d}}", c);
X			continue;
X			}
X		putchar(a);
X		}
X}
X
SHAR_EOF
chmod 0660 cbmtoasc.c || echo "restore of cbmtoasc.c fails"
echo "x - extracting chain.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > chain.c &&
X/* chain.c
X * 
X * usage:  chain(s);
X *
X * C-64 Kernel load and run; true chaining.
X *
X * NOTE -> Program to be chained-to should
X *         be linked with the following:
X *
X *         $ link -s 2062<cr>
X *         > [filename].o<cr>
X *         > [uparrow]<cr>
X *
X * Accordingly, this code has been tried ONLY
X * for the C-64 running programs under BASIC.
X * But ... it shouldn't be difficult to
X * clone it into a more generalized tool that
X * will work under the C-Power-C shells, and
X * for the C-128.
X *
X * Note also that this source code HAS NOT
X * been optimized for efficiency.  In fact,
X * the code is quite defensive ... perhaps
X * overly so.  
X *
X *
X * Your comments are solicited!
X *
X * Steve Reisman
X * 50 David Court
X * Dayton, NJ 08810
X * attmail!sreisman
X */
X
Xchain(s)
Xchar s[];
X{
X       char *ptr;
X       int  i;
Xstatic char dmy ={ 0 };
Xstatic char mlchain[] ={
X       169,9,         /* lda #$09 */
X       162,8,         /* ldx #$08 */
X       160,1,         /* ldy #$01 */
X       32,0xba,0xff,  /* jsr SETLFS */
X       169,1,         /* lda #$(filename's length) */
X       162,0xf1,      /* ldx #$(filename's RAM loc lo at relo'd mlchain) */
X       160,0xcf,      /* ldy #$(filename's RAM loc hi at relo'd mlchain) */
X       32,0xbd,0xff,  /* jsr kernel SETNAM */
X       169,0,         /* lda #0 */
X       133,0x0a,      /* sta for VERCK */
X       162,0,         /* ldx #$00  */
X       160,0xc0,      /* ldy #$c0  */
X       32,0xd5,0xff,  /* jsr kernel LOAD */
X       32,0x0e,0x08,  /* jsr PROGRAM START at 2062 */
X       0,             /* brk */
X       0,0,0,0,0,0,0,0, /* file name HERE */
X       0,0,0,0,0,0,0,0  /* null end = BREAK */
X       };
X
X       ptr = &mlchain[0] + 33; /* copy filename for relocation later */
X       for(i=0;s[i] != '\0';i++)
X           *ptr++ = s[i];
X       mlchain[10] = i;
X
X       /* Tuck-away into very high-RAM for
X        * safety from being overlayed.
X        */
X       ptr = 53200;
X       for(i=0;i < sizeof(mlchain); i++)
X           *ptr++ = mlchain[i];
X       sys(53200,&dmy,&dmy,&dmy);
X
X       /*  Code will fall into here
X        *  if file is missing, is wrong
X        *  type, for disk problems, etc.
X        *  Note that no recovery is attempted.
X        */
X       puts("error chaining to: ");
X       for(i=0,ptr=53233;i<8;i++)
X           putchar(*ptr++);
X       exit(0);     /* leave program */
X}
X/* end */
SHAR_EOF
chmod 0664 chain.c || echo "restore of chain.c fails"
echo "x - extracting dosload.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > dosload.c &&
X/* dosload.c
X *
X *     March 21, 1988 
X * by: Steve Reisman
X *     50 David Court
X *     Dayton, NJ 08810
X *     attmail!sreisman
X *
X * Function will execute a self-contained kernal
X * load of any PRG file at load address specified
X * in bytes 3 and 4 of sector 1 of the file.
X *
X * USAGE:
X *        dosload("filename");
X *
X *              or
X *        char s[17];
X *             .
X *             .
X *             .
X *        strcpy(s,"filename"); 
X *             .
X *             .
X *             .
X *        dosload(filename);
X *
X * I find this routine valuable for
X * loading hi-res and multicolor picture
X * files, and I've used it with much
X * success with Doodle and Art Studio
X * files.  I also use the function to
X * load tables and other files.
X *
X * Please note that this has been thouroughly
X * tested on the C-64, and that it has not been
X * tried yet on the C-128.  I suspect though
X * that it will work fine on the C-128.
X *
X * Yes, the functionality could have been
X * achieved using C code, but I ask you
X * this ....
X *
X * ... Why create code that is readily
X * available in the operating system?  Also,
X * consider that using the Kernal results
X * in fewer instructions in your own program.
X * Enough editorializing!
X *
X * Well ... I've donated this to you and to
X * the Public Domain.  In return, all I ask
X * is that you too share what you consider
X * worthwhile, and that you advise me of
X * changes that you make.
X *
X * Be C'ing you soon at this BBS.  I can also
X * be contacted via AT&T Mail; my mail service
X * ID is noted above.
X *
X * Bye.
X *
X */
X
Xdosload(s)
Xchar s[];
X{
X       char *ptr, lth;
X       int  i, j, k;
Xstatic char dmy ={ 0 };
Xstatic char mlload[] ={
X       169,9,         /* lda #$09 */
X       162,8,         /* ldx #$08 */
X       160,1,         /* ldy #$01 */
X       32,0xba,0xff,  /* jsr SETLFS */
X       169,00,        /* lda #$(lth) */
X       162,00,        /* ldx #$(adlo) */
X       160,00,        /* ldy #$(adhi) */
X       32,0xbd,0xff,  /* jsr SETNAM */
X       169,0,         /* lda #0 */
X       133,0x0a,      /* sta VERCK */
X       162,0,         /* ldx #$00  */
X       160,0xc0,      /* ldy #$c0  */
X       32,0xd5,0xff,  /* jsr LOAD */
X       96             /* rts */
X       };
X
X       ptr = &s[0];
X       i = ptr;
X       j = i / 256;
X       k = i - (j * 256);
X       i = strlen(s);
X
X       mlload[10] = i;
X       mlload[12] = k;
X       mlload[14] = j;
X
X       sys(mlload,&dmy,&dmy,&dmy);
X}
X/* end */
SHAR_EOF
chmod 0664 dosload.c || echo "restore of dosload.c fails"
exit 0
-- 
  W Mat Waites                     |  PHONE:  (404) 727-7197
  Emory Univ Cardiac Data Bank     |  UUCP:   ...!gatech!emcard!mat
  Atlanta, GA 30322                |