home *** CD-ROM | disk | FTP | other *** search
- #include "microlib.h" // for pre-compiled headers only
-
- #include <stdio.h>
- #include <dos.h>
- #include "ibmpc.h"
-
- extern VIDEOSTATUS vs;
-
- void _movmem(PSTR t, PSTR s, int len)
- {
- int i;
-
- for (i = 0; i < len; i++)
- t[i] = s[i];
- }
-
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ _kbdhit() │
- │ │ This function reads a character from the keyboard--if one │
- │ │ is ready--using interrupt 0x21. If a character is not ready,│
- │ │ the function returns zero. Characters are not echoed to the │
- │ │ screen. ASCII and extended characters are returned. │
- │ │ NOTE: This version is used if intdos() does not return the │
- │ │ flag register. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ int key code │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 05-10-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- int _kbdhit(void)
- {
- unsigned c,
- flag;
-
- _asm mov c,00h
- _asm mov flag,00h
- loop1:
- _asm mov dl,0FFh /* input requested */
- _asm mov ah,06h /* direct console I/O */
- _asm int 21h
- _asm jz clear /* no character ready */
- _asm or al,al
- _asm jne good /* a character is ready */
- // read an extended code key
- _asm mov dl,0FFh
- _asm mov ah,06h
- _asm int 21h
- _asm mov ah,al
- _asm xor al,al
- _asm mov flag,ax
- return (flag);
-
- clear:
- _asm mov al,00h
- good:
- _asm mov BYTE PTR c, al
-
- okkbd:
- return (int) (c + flag);
- }
-
- void at_say(int col, int row, unsigned char *string, unsigned char attr)
- {
- int offset = (row*80 + col) * 2;
- int x1, y1;
-
- //mouHideCur();
- switch (vs.crtmode) {
- case VMODE_3 :
- case VMODE_7 :
- while (*string) {
- *(vs.segment+offset) = *string++;
- *(vs.segment+offset+1) = attr;
- offset += 2;
- }
- break;
- //case VMODE_16 :
- //case VMODE_18 :
- // #ifdef _TXT_COORDS_
- // x1 = col << 3;
- // y1 = row << 4;
- // #else
- // x1 = col;
- // y1 = row;
- // #endif
- // rectfill(x1, y1, x1 + (strlen(string) << 3), y1+14, BG(attr));
- // while (*string) {
- // llettr(x1, y1, *string, FG(attr));
- // x1 += 8;
- // string++;
- // }
- // //_drawString(x1, y1, *string, FG(attr), _CURRENT_FONT_);
- // break;
- default :
- break;
- }
- //mouShowCur();
- }
-
- PSTR LJ(PSTR LStr, PSTR Buffer, int FWdth)
- {
- int T, LS;
-
- for (LS = 0; LStr[LS]; LS++);
-
- if (LS <= FWdth) {
- FWdth--;
- for (T = 0; LStr[T]; T++)
- Buffer[T] = LStr[T];
- for (; T <= FWdth; T++)
- Buffer[T] = ' ';
- Buffer[T] = 0;
- }
- else {
- FWdth--;
- for (T = 0; T <= FWdth; T++)
- Buffer[T] = LStr[T];
- Buffer[T] = 0;
- }
- return (Buffer);
- }
-
- PSTR RJ(PSTR RStr, PSTR Buffer, int FieldWidth)
- {
- int T, T1, LR;
-
- for (LR = 0; RStr[LR]; LR++);
-
- if (LR <= FieldWidth) {
- T1 = FieldWidth - LR - 1;
- for (T = 0; T <= T1; T++)
- Buffer[T] = ' ';
- for (T1 = 0, FieldWidth--; T <= FieldWidth; T++, T1++)
- Buffer[T] = RStr[T1];
- Buffer[T] = '\0';
- }/* if LR */
- else {
- Buffer[FieldWidth] = '\0';
- for(FieldWidth--, LR-- ; FieldWidth >= 0; FieldWidth--, LR--)
- Buffer[FieldWidth] = RStr[LR];
- }/* if LR else */
- return (Buffer);
- }
-
- PSTR Replace(PSTR Src, PSTR Target, int Position)
- {
- int T, LT;
- for (LT = 0; Target[LT]; LT++);
- if (Position <= LT) {
- Position--;
- for (T = 0; Src[T]; T++, Position++)
- Target[Position] = Src[T];
- LT--;
- if(Position>LT)
- Target[Position] = '\0';
- }
- else {
- Position--;
- for (; LT < Position; LT++)
- Target[LT] = ' ';
- for (T = 0; Src[T]; Position++, T++)
- Target[Position] = Src[T];
- Target[Position] = '\0';
- }
- return(Target);
- }
-
- void vioInit(void)
- {
- char far *vptr = (char far *) 0x00400049;
- int vmode = *vptr;
-
- switch (vmode) {
-
- case VMODE_3 :
- vs.screenwide = 80;
- vs.screendeep = 24;
- vs.txtcols = 80;
- vs.txtrows = 24;
- vs.crtmode = 0x03;
- vs.crtpage = 0x00;
- vs.segment = (char *) 0xb8000000;
- break;
-
- case VMODE_7 :
- vs.screenwide = 80;
- vs.screendeep = 24;
- vs.txtcols = 80;
- vs.txtrows = 24;
- vs.crtmode = 0x07;
- vs.crtpage = 0x00;
- vs.segment = (char *) 0xb0000000;
- break;
-
- case VMODE_16 :
- vs.screenwide = 640;
- vs.screendeep = 350;
- vs.txtcols = 80;
- vs.txtrows = 24;
- vs.crtmode = 0x10;
- vs.crtpage = 0x00;
- vs.segment = (char *) 0xA0000000;
- break;
-
- case VMODE_18 :
- vs.screenwide = 640;
- vs.screendeep = 480;
- vs.txtcols = 80;
- vs.txtrows = 30;
- vs.crtmode = 0x12;
- vs.crtpage = 0x00;
- vs.segment = (char *) 0xA0000000;
- break;
-
- default :
- puts("video mode not supported !!!");
- exit(0);
- break;
- }
-
- vioSetBlinkBit(0);
- }
-
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioSetCurType() │
- │ │ This function sets the cursor characteristics │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int start the starting scan line for the cursor │
- │ │ int end the ending scan line for the cursor │
- │ │ NOTE : │
- │ │ CH bits 0-4 = start line │
- │ │ CH bits 5-6 = blink attribute │
- │ │ ( 00=normal, 01=invisible │
- │ │ 10=slow, 11=fast ) │
- │ │ CL bits 0-4 = end line │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 30-08-93 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioSetCurType(int start, int end, int attr)
- {
- union REGS regs;
-
- regs.h.ah = 0x01;
- regs.h.ch = attr << 4;
- regs.h.ch += start;
- regs.h.cl = end;
- int86(0x10, ®s, ®s);
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioSetCurPos() │
- │ │ This function places the cursor at row-col as given by the │
- │ │ function arguments. │
- │ │ NOTE: For speed reasons, valid row and column numbers are │
- │ │ NOT checked. getvcols() could be used to check valid │
- │ │ columns; rows should not exceed 25. The value 1 is │
- │ │ subtracted from row and column so that the upper left │
- │ │ corner. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int row the row position for the cursor │
- │ │ int col the column position for the cursor │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 10-05-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioSetCurPos(int row, int col)
- {
- union REGS regs;
-
- regs.h.ah = 0x02;
- regs.h.bh = vioGetPage();
- regs.h.dh = row - 1;
- regs.h.dl = col - 1;
- int86(0x10, ®s, ®s);
-
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioGetCurPos() │
- │ │ This function finds the current row and column position of │
- │ │ the cursor, and fills in the two pointers with the approp │ │ values. The value of 1 is added to agree with a home │
- │ │ position of 1,1 rather than 0,0. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int *row the row position for the cursor │
- │ │ int *col the column position for the cursor │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 10-05-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioGetCurPos(int *row, int *col)
- {
- union REGS regs;
-
- regs.h.ah = 0x03;
- regs.h.bh = vioGetPage();
- int86(0x10, ®s, ®s);
-
- *row = (int) regs.h.dh + 1;
- *col = (int) regs.h.dl + 1;
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioGetCurType() │
- │ │ This function retrieves the cursor type │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int *start the starting scan line for the cursor │
- │ │ int *end the ending scan line for the cursor │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 10-05-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioGetCurType(int *start, int *end)
- {
- union REGS regs;
-
- regs.h.ah = 0x03;
- regs.h.bh = vioGetPage();
- int86(0x10, ®s, ®s);
-
- *start = (int) regs.h.ch;
- *end = (int) regs.h.cl;
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioSetPage() │
- │ │ This function set the active page for the video display │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int page the page number │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 18-08-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioSetPage(int page)
- {
- union REGS regs;
-
- regs.h.ah = 0x05;
- regs.h.al = page;
- int86(0x10, ®s, ®s);
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioScroll() │
- │ │ This function scrolls the screen via BIOS. │
- │ │ The value of the variable-named function may be either │
- │ │ 0x06 for an upward scroll or 0x07 for a downward scroll. │
- │ │ The arguments determine how many columns currently are in │
- │ │ use on the screen. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int row the row position for the window │
- │ │ int col the column position for the window │
- │ │ int wide the width of the window │
- │ │ int deep the depth of the window │
- │ │ int lines the number of lines to scroll within │
- │ │ the window (all are scrolled if 0) │
- │ │ int function 0x07 for up scroll, 0x06 for down │
- │ │ int attr attribute to be used │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 10-05-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioScroll(int row, int col, int wide, int deep, int lines, int function, int attr)
- {
- union REGS regs;
-
- //row--;
- //col--;
- regs.h.ah = function;
- regs.h.al = lines;
- regs.h.ch = row;
- regs.h.cl = col;
- regs.h.dh = row + deep - 1;
- regs.h.dl = col + wide;
- regs.h.bh = attr;
- int86(0x10, ®s, ®s);
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioGetPage() │
- │ │ This function gets the active video page. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ int the currently active page │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 10-05-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- int vioGetPage(void)
- {
- union REGS regs;
-
- regs.h.ah = 0x0F;
- int86(0x10, ®s, ®s);
-
- return (regs.h.bh);
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioGetMode() │
- │ │ This function gets the active video mode. │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ int the active video mode │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 07-06-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- int vioGetMode(void)
- {
- union REGS regs;
-
- regs.h.ah = 0x0F; /* Function 0x0f gets video mode */
- int86(0x10, ®s, ®s);
-
- return (regs.h.al);
- }
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioGetCols() │
- │ │ This function returns the columns used by the active display│
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ int the number of columns │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 07-06-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- int vioGetCols(void)
- {
- union REGS regs;
-
- regs.h.ah = 0x0F;
-
- int86(0x10, ®s, ®s);
- if (regs.h.al < 2)
- return 40; /* 40-column mode */
-
- if (regs.h.al > 3 && regs.h.al != 7)
- return 0; /* Return 0 for any graphics mode */
- else
- return 80; /* 80-column mode */
- }
-
- /* ────────┬────────────────────────────────────────────────────────────────┐
- │ FUNCTION │ vioSetBlinkBit() │
- │ │ This function enables/disables the blink/intensity bit │
- │ │ 1 : enable Blink bit │
- │ │ 0 : enable Intensity bit │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ ENTRY │ int the intensity flag (ON/OFF) │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ EXIT │ void │
- ├──────────┼────────────────────────────────────────────────────────────────┤
- │ DLU │ 11-11-92 │
- └──────────┴────────────────────────────────────────────────────────────── */
- void vioSetBlinkBit(char flag)
- {
- union REGS regs;
-
- regs.x.ax = 0x1003;
- regs.h.bl = flag;
- int86(0x10, ®s, ®s);
- }
-