コード例 #1
0
static void bitmode_off(mps_t *mps)
{
    unsigned int i, x;
    int y;
    unsigned int err = 0;

    for (i = 0; i < (unsigned int)mps->repeatn; i++) {
        for (x = 0; x < (unsigned int)mps->bitcnt; x++) {
            if ((mps->pos + x) >= MAX_COL) {
                err = 1;
                break;
            }
            if ((mps->pos - mps->bitcnt + x) >= MAX_COL) {
                err = 1;
                break;
            }
            if ((mps->pos + x) < (unsigned int)mps->bitcnt) {
                err = 1;
                break;
            }
            for (y = 0; y < 7; y++) {
                mps->line[mps->pos + x][y]
                    = mps->line[mps->pos - mps->bitcnt + x][y];
            }
        }
        mps->pos += mps->bitcnt;
    }
    del_mode(mps, MPS_BITMODE);
    if (err) {
        log_error(drv803_log, "Printing beyond limit of %d dots.", MAX_COL);
    }
}
コード例 #2
0
static void print_char(mps_t *mps, unsigned int prnr, const BYTE c)
{
    if (mps->pos >= MAX_COL) {  /* flush buffer*/
        write_line(mps, prnr);
        clear_buffer(mps);
    }
    if (mps->tab) {     /* decode tab-number*/
        mps->tabc[2 - mps->tab] = c;

        if (mps->tab == 1) {
            mps->pos =
                is_mode(mps, MPS_ESC) ?
                mps->tabc[0] << 8 | mps->tabc[1] :
                atoi((char *)mps->tabc) * 6;

            del_mode(mps, MPS_ESC);
        }

        mps->tab--;
        return;
    }

    if (is_mode(mps, MPS_ESC) && (c != 16)) {
        del_mode(mps, MPS_ESC);
    }

    if (is_mode(mps, MPS_REPEAT)) {
        mps->repeatn = c;
        del_mode(mps, MPS_REPEAT);
        return;
    }

    if (is_mode(mps, MPS_BITMODE) && (c & 128)) {
        print_bitmask(mps, c);
        return;
    }

    /* it seems that CR works even in quote mode */
    switch (c) {
        case 13: /* CR*/
            mps->pos = 0;
            if (is_mode(mps, MPS_BUSINESS)) {
                del_mode(mps, MPS_CRSRUP);
            } else {
                set_mode(mps, MPS_CRSRUP);
            }
            /* CR resets Quote mode, revers mode, ... */
            del_mode(mps, MPS_QUOTED);
            del_mode(mps, MPS_REVERSE);
            write_line(mps, prnr);
            clear_buffer(mps);
            return;
    }

    /* in text mode ignore most (?) other control chars when quote mode is active */
    if (!is_mode(mps, MPS_QUOTED) || is_mode(mps, MPS_BITMODE)) {

        switch (c) {
            case 8:
                set_mode(mps, MPS_BITMODE);
                mps->bitcnt = 0;
                return;

            case 10: /* LF*/
                write_line(mps, prnr);
                clear_buffer(mps);
                return;

#ifdef notyet
            /* Not really sure if the MPS803 recognizes this one... */
            case 13 + 128: /* shift CR: CR without LF (from 4023 printer) */
                mps->pos = 0;
                if (is_mode(mps, MPS_BUSINESS)) {
                    del_mode(mps, MPS_CRSRUP);
                } else {
                    set_mode(mps, MPS_CRSRUP);
                }
                /* CR resets Quote mode, revers mode, ... */
                del_mode(mps, MPS_QUOTED);
                del_mode(mps, MPS_REVERSE);
                return;
#endif

            case 14: /* EN on*/
                set_mode(mps, MPS_DBLWDTH);
                if (is_mode(mps, MPS_BITMODE)) {
                    bitmode_off(mps);
                }
                return;

            case 15: /* EN off*/
                del_mode(mps, MPS_DBLWDTH);
                if (is_mode(mps, MPS_BITMODE)) {
                    bitmode_off(mps);
                }
                return;

            case 16: /* POS*/
                mps->tab = 2; /* 2 chars (digits) following, number of first char*/
                return;

            /*
            * By sending the cursor up code [CHR$(145)] to your printer, following
            * characters will be printed in cursor up (graphic) mode until either
            * a carriage return or cursor down code [CHR$(17)] is detected.
            *
            * By sending the cursor down code [CHR$(17)] to your printer,
            * following characters will be printed in business mode until either
            * a carriage return or cursor up code [CHR$(145)] is detected.
            */
            case 17: /* crsr dn, enter businessmode local */
                del_mode(mps, MPS_CRSRUP);
                return;

            case 145: /* CRSR up, enter gfxmode local */
                set_mode(mps, MPS_CRSRUP);
                return;

            case 18:
                set_mode(mps, MPS_REVERSE);
                return;

            case 146: /* 18+128*/
                del_mode(mps, MPS_REVERSE);
                return;

            case 26: /* repeat last chr$(8) c times.*/
                set_mode(mps, MPS_REPEAT);
                mps->repeatn = 0;
                mps->bitcnt = 0;
                return;

            case 27:
                set_mode(mps, MPS_ESC); /* followed by 16, and number MSB, LSB*/
                return;
        }

    }

    if (is_mode(mps, MPS_BITMODE)) {
        return;
    }

   /* 
    * When an odd number of CHR$(34) is detected in a line, the control
    * codes $00-$1F and $80-$9F will be made visible by printing a
    * reverse character for each of these controls. This will continue
    * until an even number of quotes [CHR$(34)] has been received or until
    * end of this line.
    */
    if (c == 34) {
        mps->mode ^= MPS_QUOTED;
    }

    if (is_mode(mps, MPS_QUOTED)) {
        if (c <= 0x1f) {
            set_mode(mps, MPS_REVERSE);
            print_cbm_char(mps, (BYTE)(c + 0x40));
            del_mode(mps, MPS_REVERSE);
            return;
        }
        if ((c >= 0x80) && (c <= 0x9f)) {
            set_mode(mps, MPS_REVERSE);
            print_cbm_char(mps, (BYTE)(c - 0x20));
            del_mode(mps, MPS_REVERSE);
            return;
        }
    }

    print_cbm_char(mps, c);
}
コード例 #3
0
static void print_char(mps_t *mps, unsigned int prnr, const BYTE c)
{
    if (mps->pos >= MAX_COL) {  /* flush buffer*/
        write_line(mps, prnr);
        clear_buffer(mps);
    }
    if (mps->tab) {     /* decode tab-number*/
        mps->tabc[2 - mps->tab] = c;

        if (mps->tab == 1) {
            mps->pos =
                is_mode(mps, MPS_ESC) ?
                mps->tabc[0] << 8 | mps->tabc[1] :
                atoi((char *)mps->tabc) * 6;

            del_mode(mps, MPS_ESC);
        }

        mps->tab--;
        return;
    }

    if (is_mode(mps, MPS_ESC) && c != 16) {
        del_mode(mps, MPS_ESC);
    }

    if (is_mode(mps, MPS_REPEAT)) {
        mps->repeatn = c;
        del_mode(mps, MPS_REPEAT);
        return;
    }

    if (is_mode(mps, MPS_BITMODE) && c & 128) {
        print_bitmask(mps, c);
        return;
    }

    switch (c) {
        case 8:
            set_mode(mps, MPS_BITMODE);
            mps->bitcnt = 0;
            return;

        case 10: /* LF*/
            write_line(mps, prnr);
            clear_buffer(mps);
            return;

        case 13: /* CR*/
            mps->pos = 0;
            del_mode(mps, MPS_CRSRUP);
            write_line(mps, prnr);
            clear_buffer(mps);
            return;

        /*
         * By sending the cursor up code [CHR$(145)] to your printer, folowing
         * characters will be printed in cursor up (graphic) mode until either
         * a carriage return or cursor down code [CHR$(17)] is detected.
         *
         * By sending the cursor down code [CHR$(145)] to your printer,
         * following characters will be printed in business mode until either
         * a carriage return or cursor up code [CHR$(145)] is detected.
         *
         * 1. GRAPHIC MODE Code & Front Table, OMITTED
         * When an old number of CHR$(34) is detected in a line, the control
         * codes $00-$1F and $80-$9F will be made visible by printing a
         * reverse character for each of these controls. This will continue
         * until an even number of quotes [CHR$(34)] has been received or until
         * end of this line.
         *
         * 2. BUSINESS MODE Code & Font Table, OMITTED
         * When an old number of CHR$(34) is detected in a line, the control
         * codes $00-$1F and $80-$9F will be made visible by printing a
         * reverse character for each of these controls. This will continue
         * until an even number of quotes [CHR$(34)] has been received or until
         * end of this line.
         */

        case 14: /* EN on*/
            set_mode(mps, MPS_DBLWDTH);
            if (is_mode(mps, MPS_BITMODE)) {
                bitmode_off(mps);
            }
            return;

        case 15: /* EN off*/
            del_mode(mps, MPS_DBLWDTH);
            if (is_mode(mps, MPS_BITMODE)) {
                bitmode_off(mps);
            }
            return;

        case 16: /* POS*/
            mps->tab = 2; /* 2 chars (digits) following, number of first char*/
            return;

        case 17: /* crsr dn*/
            del_mode(mps, MPS_CRSRUP);
            return;

        case 18:
            set_mode(mps, MPS_REVERSE);
            return;

        case 26: /* repeat last chr$(8) c times.*/
            set_mode(mps, MPS_REPEAT);
            mps->repeatn = 0;
            mps->bitcnt = 0;
            return;

        case 27:
            set_mode(mps, MPS_ESC); /* followed by 16, and number MSB, LSB*/
            return;

        case 145: /* CRSR up*/
            set_mode(mps, MPS_CRSRUP);
            return;

        case 146: /* 18+128*/
            del_mode(mps, MPS_REVERSE);
            return;
    }

    if (is_mode(mps, MPS_BITMODE)) {
        return;
    }

    print_cbm_char(mps, c);
}