Slimelite BBS

Help!!

Back to R25C

From Bill Birrell · 1996-03-29 22:52 · #75158 in R25C

Hey George,

 > Only to BCOS2 (any version) and then only to certain
 > types of program
 > (only non PM programs).

    I found this for PCC. As you say, non-standard, but it seems to work. I have not tested it beyond the demo program.

;   module:     vlib
;   programmer: Ray L. McVay
;   started:    10 Oct 82
;   version:    2.01, 3 Aug 84
;
;   A library of c bios video functions originally written to
;   replace the int10() function of small-c:PC.

;   history:
;   1.0 small-c:PC version
;   2.0 ported to DeSmet c

;       Calling convention for DeSmet is to push parameters
;       rightmost first then do an intrasegment call to the
;       function.

;       Char's, int's and unsigned's are returned in AX.
;       Long's are returned in DX:AX.

;       CS, DS, SS, SP and BP should be preserved.

CSEG
VIDEO   EQU 16  ;BIOS video interrupt


;   get video mode
; int get_mode();

    PUBLIC  GET_MODE_
GET_MODE_:
    mov ah,15
    int VIDEO
    cbw
    ret


;   set video mode
; set_mode(mode)
; int   mode;

    PUBLIC  SET_MODE_
SET_MODE_:
    push    bp
    mov bp,sp
    mov al,[bp+4]
    mov ah,0
    INT VIDEO
    pop bp
    RET


;   set cursor type
; set_curtyp(start,end)
; int   start,end;
; Note: if start > end then cursor is turned off.

    PUBLIC  SET_CURTYP_
SET_CURTYP_:
    push    bp
    mov bp,sp
    mov ch,[bp+4]   ; top line
    mov cl,[bp+6]   ; bottom line
    mov ah,1
    INT VIDEO
    pop bp
    RET


;   gotoxy - set cursor position
; gotoxy(x, y, page)
; int   x,y,page;

    PUBLIC  GOTOXY_
GOTOXY_:
    push    bp
    mov bp,sp
    mov dl,[bp+4]   ; DL = x = column
    mov dh,[bp+6]   ; DH = y = row
    mov bh,[bp+8]   ; BH = page
    mov ah,2
    INT VIDEO
    pop bp
    RET


;   read cursor position
; getxy(page)
; int   page;
; xpos = getxy(page) & 255;
; ypos = getxy(page) >> 8;

    PUBLIC  GETXY_
GETXY_:
    push    bp
    mov bp,sp
    mov bh,[bp+4]   ;BH = page
    MOV AH,3
    INT VIDEO
    MOV AX,DX       ;return(256*row+column)
    pop bp
    RET


;   get light pen position
; int gltpen(buff)
; int   buff[4];
; Note: Returns 0 if pen was not triggered, 1 if it was.
;   Stores XY values in integer array at buff.

    PUBLIC  GLTPEN_
GLTPEN_:
    push    bp
    mov bp,sp
    MOV AH,4
    INT     VIDEO
    OR  AH,AH       ;check status
    JZ  DOSTAT      ;it was bad
    mov si,[bp+4]   ;get addres of buffer
    MOV [SI],BX     ;buff[0]=X for graphics
    MOV [SI]+2,CH   ;buff[1]=Y
    MOV [SI]+4,DL   ;buff[2]=X for text
    MOV [SI]+6,DH   ;buff[3]=Y for text
    MOV AH,1        ;return OK status
DOSTAT:
    MOV AL,AH
    CBW
    pop bp
    RET


;   select active page
; setpage(page)
; int   page;

    PUBLIC  SETPAGE_
SETPAGE_:
    push    bp
    mov bp,sp
    mov al,[bp+4]   ;page
    MOV AH,5
    INT VIDEO
    pop bp
    RET


;   scroll a window up
; scrlup(window,count,attrib)
; int window[4],count,attrib;
; Note: Window defines the upper-left and lower-right
;   character positions of an area of the text screen.
;   A count of 0 clears the window.
;   The attribute is used on the line(s) blanked.

    PUBLIC  SCRLUP_
SCRLUP_:
    push    bp
    CALL    SCRL1
    MOV AH,6
    INT VIDEO
    pop bp
    RET

SCRL1:  mov bp,sp
    mov bx,[bp+6]   ;get base of window array
    MOV CL,[bx]     ;window[0] = U.L. X
    MOV CH,[bx]+2   ;window[1] = U.L. Y
    MOV DL,[bx]+4   ;window[2] = L.R. X
    MOV DH,[bx]+6   ;window[3] = L.R. Y
    mov al,[bp+8]   ;AL = count
    mov bh,[bp+10]  ;BH = attribute
    RET


;   scroll a window down
; scrldn(window,count,attrib)
; int window[4],count,attrib;

    PUBLIC  SCRLDN_
SCRLDN_:
    push    bp
    CALL    SCRL1
    MOV AH,7
    INT VIDEO
    pop bp
    RET


;   read character & attribute under the cursor
; int vgetc(page)
; int   page;

    PUBLIC  VGETC_
VGETC_:
    push    bp
    mov bp,sp
    MOV BH,[bp+4]
    MOV AH,8
    INT VIDEO
    pop bp
    RET


;   write character & attribute at cursor
; vputca(chr,page,count)
; int   chr,page,count;
; Note: Chr contains attribute in hi byte.
;   Count is the number of times to write the character.
;   (Good for tops and bottoms of windows or boxes.)

    PUBLIC  VPUTCA_
VPUTCA_:
    push    bp
    CALL    VPUT1
    MOV AH,9
    INT VIDEO
    pop bp
    RET

VPUT1:
    mov bp,sp
    mov AX,[bp+6]   ;attrib/char
    mov bh,[bp+8]   ;page
    mov CX,[bp+10]  ;count
    MOV BL,AH       ;attrib to BL
    RET


;   vputc - write character only at cursor
; vputc(chr,page,count)
; int   chr,page,count;
; Note: Same as vputca() except uses existing attributes.

    PUBLIC  VPUTC_
VPUTC_:
    push    bp
    CALL    VPUT1
    MOV AH,10
    INT VIDEO
    pop bp
    RET


;   set background or pallet or alpha border color
; pcolor(id,val)
; int   id,val;
; Note: If id == 0 then val is background color.
;   If id == 1 and mode is graphics then val is pallet.
;   If id == 1 and mode is text then val is border.

    PUBLIC  PCOLOR_
PCOLOR_:
    push    bp
    mov bp,sp
    mov bh,[bp+4]   ;id
    mov bl,[bp+6]   ;val
    MOV AH,11
    INT VIDEO
    pop bp
    RET


;   write a graphics dot
; plot(color,horz,vert)
; int   color,horz,vert;

    PUBLIC  PLOT_
PLOT_:
    push    bp
    CALL    SETDOT
    MOV AH,12
    INT VIDEO
    pop bp
    RET

SETDOT:
    mov bp,sp
    mov AX,[bp+6]   ;color
    mov CX,[bp+8]   ;horiz
    mov DX,[bp+10]  ;vert
    RET


;   read a graphic dot color
; int get_dot(dummy,horz,vert)
; int   dummy,horz,vert;
; Note: the dummy parameter is used so SETDOT can be shared.

    PUBLIC  GET_DOT_
GET_DOT_:
    push    bp
    CALL    SETDOT      ; set up the registers
    MOV AH,13
    INT VIDEO
    cbw
    pop bp
    RET         ; AX = dot color

    END

    And this:-

/*  module:     window.c
 *  programmer: Ray L. McVay
 *  started:    1 Aug 84
 *  version:    1.2, 23 Aug 84
 *
 *  A simple window package based on the article and programs
 *  by Edward Mitchell in the Jan 84 Dr. Dobb's Journal.  This
 *  implementation uses dynamically allocated buffers for the
 *  window control blocks and screen save buffers.
 *
 *  An assembly language support library called VLIB is used to
 *  interface the DeSmet C compiler with the IBM ROM BIOS video
 *  routines.  VLIB will undoubtedly have to be rewritten if the
 *  window package is to be used with other compilers.
 *
 *  History -
 *
 *  1.1 -   Added style member to wcb structure, clr_window() and
 *          use of wn->cx for horizontal scrolling in write_text().
 *
 *  1.2 -   Added oldx, oldy members to wcb structure and use them
 *          in draw_window() and remove_window().
 *
 */

#include    <stdio.h>

typedef struct wcb  /* --- window control block ---     */
{
    int     ulx,    /* upper left corner x coordinate   */
            uly,    /* ditto y coordinate               */
            xsize,  /* line width of inside of window   */
            ysize,  /* number of lines inside of window */
            cx,     /* current cursor offset in window  */
            cy,
            style,  /* attribute to be used in window   */
            *scrnsave,  /* pointer to screen save buffer */
            oldx,   /* cursor position when window was  */
            oldy;   /* opened (used for screen restore) */
} WINDOW, *WINDOWPTR;


/************************************************************************
* putch(), write a character and attribute to a specific XY location on *
*          the screen. The attribute is the high byte of the character. *
************************************************************************/

putch(x, y, c)
int     x, y, c;
{
    gotoxy(x, y, 0);
    vputca(c, 0, 1);
}


/************************************************************************
* getch(), return the character and attribute at screen XY              *
************************************************************************/

getch(x, y)
int     x, y;
{
    gotoxy(x, y, 0);
    return(vgetc(0));
}


/************************************************************************
* draw_row(), output a row of one character/attribute at XY             *
************************************************************************/

draw_row(x, y, count, c)
int     x, y, count,c;
{
    gotoxy(x, y, 0);
    vputca(c, 0, count);
}


/************************************************************************
* draw_window(), open a window of given size with upper left corner at  *
*                XY. Allocates buffers for the window control block and *
*                screen save buffers. Copies overwritten screen to the  *
*                buffer. Draws the blank window. Returns the address of *
*                the window control block or NULL if no buffer space.   *
************************************************************************/

WINDOWPTR draw_window(x, y, width, height, attrib)
int     x, y, width, height, attrib;
{
    WINDOWPTR wn;
    int     tx, ty,
            xend, yend;
    int     *tptr;
    char    *calloc();

    if ((wn = (WINDOWPTR)calloc(1, sizeof(WINDOW))) == NULL)
        return(NULL);
    else if ((wn->scrnsave = (int *)calloc((width+2) * (height+2), sizeof(int))) == NULL)
    {
        free(wn);
        return(NULL);
    }
    else
    {
        /* store parameters in window control block */

        wn->ulx = x;
        wn->uly = y;
        wn->xsize = width;
        wn->ysize = height;
        wn->cx = 1;
        wn->cy = 1;
        wn->style = attrib;
        attrib <<= 8;   /* will make things below go quicker */
        wn->oldx = getxy(0) & 255;
        wn->oldy = getxy(0) >> 8;

        /* Copy existing text where the window will be placed */
        /* to the scrnsave buffer. Obviously, a less portable */
        /* routine could be much faster.                      */

        tptr = wn->scrnsave;
        xend = x + width + 2;
        yend = y + height + 2;

        for (ty = y; ty < yend; ty++)
        {
            for (tx = x; tx < xend; tx++)
                *tptr++ = getch(tx, ty);
        }

        /* draw the window border and clear the text area */

        putch(x, y, 0xda + attrib);                 /* ul corner */
        draw_row(x + 1, y, width, 0xc4 + attrib);   /* horiz bar */
        putch(x + width + 1, y, 0xbf + attrib);     /* ur corner */

        yend = y + height;

        for (ty = y+1; ty <= yend; ty++)
        {
            putch(x, ty, 0xb3 + attrib);            /* draw the sides */
            putch(x+width+1, ty, 0xb3 + attrib);
        }

        putch(x, y + height + 1, 0xc0 + attrib);                /* ll corner */
        draw_row(x + 1, y + height + 1, width, 0xc4 + attrib);  /* horiz bar */
        putch(x + width + 1, y + height + 1, 0xd9 + attrib);    /* lr corner */

        clr_window(wn);

        return(wn);
    }
}


/************************************************************************
* remove_window(), erase the window at the window control block.        *
*                  Must be the "top" window if overlapping windows are  *
*                  used. "Tiled" windows could be removed randomly.     *
************************************************************************/

remove_window(wn)
WINDOWPTR wn;
{
    int     tx, ty,
            xend, yend;
    int     *tptr;

    /* just repaint the saved text at the appropriate location */

    tptr = wn->scrnsave;
    xend = wn->ulx + wn->xsize + 2;
    yend = wn->uly + wn->ysize + 2;

    for (ty = wn->uly; ty < yend; ty++)
    {
        for (tx = wn->ulx; tx < xend; tx++)
            putch(tx, ty, *tptr++);
    }

    /* put cursor back where it was before this rude interruption */

    gotoxy(wn->oldx, wn->oldy, 0);

    /* then release the dynamic storage used */

    free(wn->scrnsave);
    free(wn);
}


/************************************************************************
* write_text(), print a string inside a window using cx, cy in WCB      *
************************************************************************/

write_text(wn, string)
WINDOWPTR wn;
char    *string;
{
    int     tx, ty, xend;

    /* first check to see if we're at the bottom of the window      */
    /* if we are then scroll the contents of the window up          */

    if (wn->cy > wn->ysize)
    {
        delete_row(wn, 1);
        --wn->cy;
    }

    /* Print as much of the string as will fit in the window.       *
     * cx is used for relative left margin. If cx is negative then  *
     * the first cx characters will be removed from the string to   *
     * allow horizontal scrolling in the window.                    *
     * NOTE: This obviously simple-minded technique is usable for   *
     *       displaying predetermined messages but a more general   *
     *       console output intercept should be used for Star-like  *
     *       environments.                                          */

    if (wn->cx > 0)
        tx = wn->ulx + wn->cx;
    else
    {
        if (-wn->cx < strlen(string))
            string -= wn->cx;
        else
            *string = '\0';
        tx = wn->ulx + 1;
    }
    xend = wn->ulx + wn->xsize + 1;
    ty = wn->uly + wn->cy;
    while ((tx < xend) && *string)
    {
        gotoxy(tx++, ty, 0);
        vputc(*string++, 0, 1);
    }
    ++wn->cy;       /* move the internal cursor to the next line */
}


/************************************************************************
* insert_row(), insert a row of blanks by scrolling the lower portion   *
*               of a window down                                        *
************************************************************************/

insert_row(wn, row)
WINDOWPTR wn;
int     row;
{
    int     scrlwn[4];

    /* calculate corners of the scrolling window */

    scrlwn[0] = wn->ulx + 1;            /* ulx */
    scrlwn[1] = wn->uly + row;          /* uly */
    scrlwn[2] = wn->ulx + wn->xsize;    /* lrx */
    scrlwn[3] = wn->uly + wn->ysize;    /* lry */

    scrldn(scrlwn, 1, wn->style);
}


/************************************************************************
* delete_row(), delete a row by scrolling the lower portion of a window *
*               up and inserting a row of blanks at the bottom row      *
************************************************************************/

delete_row(wn, row)
WINDOWPTR wn;
int     row;
{
    int     scrlwn[4];

    /* calculate corners of the scrolling window */

    scrlwn[0] = wn->ulx + 1;            /* ulx */
    scrlwn[1] = wn->uly + row;          /* uly */
    scrlwn[2] = wn->ulx + wn->xsize;    /* lrx */
    scrlwn[3] = wn->uly + wn->ysize;    /* lry */

    scrlup(scrlwn, 1, wn->style);
}


/************************************************************************
* clr_window(), clear the "active" part of a window and "home" internal *
*               text cursor                                             *
************************************************************************/

clr_window(wn)
WINDOWPTR wn;
{
    int     scrlwn[4];

    /* calculate corners of the scrolling window */

    scrlwn[0] = wn->ulx + 1;            /* ulx */
    scrlwn[1] = wn->uly + 1;            /* uly */
    scrlwn[2] = wn->ulx + wn->xsize;    /* lrx */
    scrlwn[3] = wn->uly + wn->ysize;    /* lry */

    scrlup(scrlwn, 0, wn->style);
    wn->cx = 1;
    wn->cy = 1;
}

    You can, of course, download it in zip form.

Regards,
Bill.

---
 * Origin: bill@escan.demon.co.uk (2:2504/200)