next up previous contents
Next: D.7 lfsr.c Up: D C Source Code Previous: D.5 string.c

D.6 capture.c

 

/*****************************************************************
** C A P T U R E . C
** Address Tracing System, Scott Harrington, Spring 94
** Command line options:
**      [-r port]           port #(200,220,240,...,3E0) default 220
**      [-s D|E]            segment (D000 or E000)
**      [-w(ord)]           Use 16 bit reads and writes
*/

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.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};

unsigned char readMem8(void);
unsigned int readMem16(void);

void BullwinkleStatus(void);

unsigned int ioPort = 0x300;
unsigned int bullwinkleReg = 256;
int page_E = 0;
int Use8bit = 1;

void main(int argc, char *argv[])
    {
    int i, ch;
    char *parmstr, *endptr;

    for (i=1; i<argc; i++) {
        if (argv[i][0] == '-' && argv[i][1]) {
            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;
                case 'w':
                    Use8bit = 0;
                    break;
                case 'h':
                default:
                    printf("Usage: %s [-p port] [-s D|E] [-w (16bit)]\n", argv[0]);
                    exit(-1);
                }
            }
        else {
            printf("Usage: %s [-p port] [-s D|E] [-w (16bit)]\n", argv[0]);
            exit(-1);
            }
        }

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

    BullwinkleStatus();

    printf("Bullwinkle: select all modules, enter Acquire mode\n");
    outportb(ioPort + OUT_Remote, 0);
    outportb(ioPort + OUT_StartWrite, 0);
    outportb(ioPort + OUT_SelAll, 0);

    while (!kbhit())
        {
        BullwinkleStatus();

        if (!(bullwinkleReg & STAT_nExtract) && (bullwinkleReg & STAT_Empty1))
            {
            /* We read all the SRAM contents, start acquiring again */
            printf("Bullwinkle: enter Acquire mode\n");
            outportb(ioPort + OUT_StartWrite, 0);
            }
        else if (bullwinkleReg & STAT_SACK)
            {
            /* Bullwinkle has been granted a Stall, dump SRAM contents */
            if (bullwinkleReg & STAT_nExtract)
                {
                printf("Bullwinkle: begin Host Read\n");
                outportb(ioPort + OUT_StartRead, 0);
                }
            else
                {
                if (Use8bit)
                    printf("[%2x] ", readMem8());
                else
                    printf("[%4x] ", readMem16());
                }
            }
        }

    BullwinkleStatus();
    }

void BullwinkleStatus() {
    unsigned int d;

    d = inportb(ioPort);
    if (d != bullwinkleReg) {
        printf("BULLWINKLE: %s %s %s %s Empty:%d%d%d%d\n",
            (d & STAT_SACK) ? "SACK":"sack",
            (d & STAT_nInit) ? "af":"AF",
            (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);
        bullwinkleReg = d;
        }
    }

unsigned int readMem16()
    {
    static unsigned int offset;
    unsigned int far *memptr;

    /* ensure word-alignment */
    if (offset&1)
        offset = 0;

    memptr = MK_FP(page_E ? 0xE000:0xD000, offset);
    offset += 2;        /* 16-bit int causes segment wraparound */

    return *memptr;
    }

unsigned char readMem8()
    {
    static unsigned int offset;
    unsigned char far *memptr;
    memptr = MK_FP(page_E ? 0xE000:0xD000, offset);
    offset++;
    return *memptr;
    }


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