next up previous contents
Next: D.6 capture.c Up: D C Source Code Previous: D.4 console.c

D.5 string.c

 

/*****************************************************************
** S T R I N G .C
** Address Tracing System, Scott Harrington, Fall 94
**
** Command line options:
** [-p port]     port #(200,220,240,...,3E0) default 300
** [-s segment]  segment D or E (default D)
*/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dos.h>

#define STAT_Empty0 0x01
#define STAT_Empty1 0x02
#define STAT_Empty2 0x04
#define STAT_Empty3 0x08
#define STAT_nExtract 0x10
#define STAT_nProgram 0x20
#define STAT_nInit 0x40
#define STAT_SACK 0x80

enum {OUT_Config=0, OUT_NOP1, OUT_StartWrite, OUT_StartRead,
    OUT_Remote, OUT_Local, OUT_E000, OUT_D000,
    OUT_Sel0, OUT_Sel1, OUT_Sel2, OUT_Sel3,
    OUT_UnSelAll, OUT_SelAll, OUT_NOP14, OUT_Reset};
int showStatLoop(void);

unsigned int ioPort = 0x300;
int page_E = 0;

void main(int argc, char *argv[])
    {
    int i;
    char ch;
    long c, cw;
    unsigned int val;
    char *parmstr, *endptr;
    char far *buf;

    for (i=1; i<argc; i++) {
        if (argv[i][0] == '-') {
            switch (argv[i][1]) {
            case 'p':
                parmstr = (argv[i][2]) ? &argv[i][2] : argv[++i];
                ioPort = (unsigned int)strtoul(parmstr, &endptr, 0);
                break;
            case 's':
                parmstr = (argv[i][2]) ? &argv[i][2] : argv[++i];
                page_E = (parmstr[0] == 'E' || parmstr[0] == 'e');
                break;
            default:
                printf("Usage: %s [-p port] [-s D000|E000]\n", argv[0]);
                exit(-1);
                }
            }
        }

    if (ioPort & ~0x3E0) {
        printf("Valid ports are 0x200, 220, 240, ..., 3E0.\n");
        exit(-1);
        }

    outportb(ioPort + OUT_SelAll, 0);
    outportb(ioPort + OUT_StartWrite, 0);
    outportb(ioPort + OUT_Local, 0);

    printf("Enter a string to write to Bullwinkle's SRAM using gets():\n");
    buf = (char far *)MK_FP(page_E ? 0xE000:0xD000, 0);
    gets(buf);

    outportb(ioPort + OUT_StartRead, 0);
    printf("Now reading from Bullwinkle's SRAM:\n");
    ch = *buf;
    while ((ch = *buf) != 0)
        putchar(ch);
    printf("\n");
    }

int showStatLoop() {
    unsigned int d, d0=256;
    while (!kbhit()) {
        d = inportb(ioPort);
        if (d != d0) {
            printf("%s %s %s %s   Empty:%d%d%d%d\n",
                (d & STAT_SACK) ? "SACK":"sack",
                (d & STAT_nInit) ? "init":"INIT",
                (d & STAT_nProgram) ? "pgm":"PGM",
                (d & STAT_nExtract) ? "ext":"EXT",
                (d & STAT_Empty0) ? 1:0,
                (d & STAT_Empty1) ? 1:0,
                (d & STAT_Empty2) ? 1:0,
                (d & STAT_Empty3) ? 1:0);
            d0 = d;
            }
        }
    return getch();
    }


Scott E. Harrington
Sat Apr 29 18:56:25 EDT 1995