home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 344_01 / litebar.asm < prev    next >
Assembly Source File  |  1989-10-29  |  6KB  |  253 lines

  1.  
  2.         TITLE   LITEBAR
  3.         PAGE    60,132
  4.  
  5.         ;LITEBAR.ASM
  6.  
  7.     COMMENT     @
  8.  
  9.     This sub-routine inserts the attribute bytes in video ram that
  10.     control colors in text modes. It first checks for Mono text mode,
  11.     then whether a VGA or EGA is currently active. If neither is the
  12.     case it defaults to CGA.  Works only in Text Modes.
  13.  
  14.  
  15.  
  16.     ;extern void far pascal LITEBAR(
  17.         int atr, int row, int col, int page, int len, int dir
  18.         );
  19.  
  20.     @       Modified    **  10/29/89  **     Michael Kelly
  21.  
  22.  
  23.     ;Since we don't mess with a Data Segment this module can
  24.     ;be linked to any memory model except tiny.
  25.     ;I debugged this in Turbo Pascal 4.0, can be used there too.
  26.  
  27.     VMODE           EQU     BYTE PTR ES:[0049h]
  28.     VCOLS           EQU     WORD PTR ES:[004Ah]
  29.     VPAGE_SIZE      EQU     WORD PTR ES:[004Ch]
  30.     VROWS           EQU     BYTE PTR ES:[0084h]
  31.     INFO_BYTE       EQU     BYTE PTR ES:[0087h]
  32.  
  33.     BYTES_PER_ROW   EQU     WORD PTR [BP-2]     ;local variables
  34.     IS_CGA_ADAPT    EQU     WORD PTR [BP-4]
  35.  
  36.     ATR_PARAM       EQU     [BP+16]    ;proc arguments
  37.     ROW_PARAM       EQU     [BP+14]
  38.     COL_PARAM       EQU     [BP+12]
  39.     PAGE_PARAM      EQU     [BP+10]
  40.     LEN_PARAM       EQU     [BP+8]
  41.     DIR_PARAM       EQU     [BP+6]
  42.  
  43.     CSEG    SEGMENT BYTE    PUBLIC  'CODE'
  44.         ASSUME  CS:CSEG
  45.         PUBLIC  LITEBAR
  46. LITEBAR         PROC    FAR
  47.     START:  PUSH    BP
  48.         MOV     BP,SP
  49.         SUB     SP,4
  50.         PUSH    DS
  51.         PUSH    SI
  52.         PUSH    ES
  53.         PUSH    DI
  54.         PUSHF
  55.         CLD
  56.         XOR     CX,CX               ;check the video hardware
  57.         MOV     IS_CGA_ADAPT,0
  58.         MOV     DX,0B000h           ;assume mono video segment
  59.         XOR     DI,DI               ;and memory ofset of 0 for now.
  60.         MOV     AX,40h
  61.         MOV     ES,AX
  62.         MOV     AL,VMODE            ;check video mode
  63.         CMP     AL,7
  64.         JE      LITE_02
  65.         MOV     DX,0B800h
  66.         CMP     AL,3
  67.         JBE     LITE_01
  68.         JMP     EXIT                    ;exit if not in text mode.
  69.  
  70.     LITE_01:
  71.         MOV     AX,1A00h                ;Test for Vga Bios support.
  72.         INT     10h
  73.         CMP     AL,1Ah
  74.         JNE     LITE_011
  75.         CMP     BL,2
  76.         JNE     LITE_02
  77.         MOV     IS_CGA_ADAPT,1
  78.         JMP     SHORT LITE_02
  79.     LITE_011:
  80.         MOV     AH,12h                      ;Ega Bios support?
  81.         MOV     BL,10h
  82.         INT     10h
  83.         CMP     BL,10h
  84.         JNE     LITE_012
  85.         MOV     IS_CGA_ADAPT,1              ;Default to Cga.
  86.         JMP     SHORT LITE_02
  87.     LITE_012:
  88.         MOV     AX,40h
  89.         MOV     ES,AX
  90.         TEST    INFO_BYTE,8
  91.         JZ      LITE_02                 ;If bit 3 = 0, Ega is active
  92.         MOV     IS_CGA_ADAPT,1          ;else using Cga.
  93.  
  94.  
  95.     LITE_02:    MOV     AX,40h
  96.         MOV     ES,AX
  97.         MOV     AX,VCOLS
  98.         SHL     AX,1
  99.         MOV     BYTES_PER_ROW,AX
  100.  
  101.         MOV     BX,PAGE_PARAM       ;Calc offset of video page
  102.         CMP     BX,0                ;using shifts and adds.
  103.         JE      LITE_03
  104.         MOV     AX,VPAGE_SIZE
  105.         OR      BX,BX
  106.         JZ      LITE_03
  107.         CMP     BX,7
  108.         JBE     LITE_021
  109.         JMP     EXIT                ;Assume Max page # is 7
  110.     LITE_021:   CMP     BX,1
  111.         JA      LITE_022
  112.         MOV     DI,AX
  113.         JMP     SHORT LITE_03
  114.     LITE_022:   CMP     BX,2
  115.         JA      LITE_023
  116.         SHL     AX,1
  117.         MOV     DI,AX
  118.         JMP     SHORT LITE_03
  119.     LITE_023:   CMP     BX,3
  120.         JA      LITE_024
  121.         MOV     DI,AX
  122.         SHL     AX,1
  123.         ADD     DI,AX
  124.         JMP     SHORT LITE_03
  125.     LITE_024:   CMP     BX,4
  126.         JA      LITE_025
  127.         SHL     AX,1
  128.         SHL     AX,1
  129.         MOV     DI,AX
  130.         JMP     SHORT LITE_03
  131.     LITE_025:   CMP     BX,5
  132.         JA      LITE_026
  133.         MOV     DI,AX
  134.         SHL     AX,1
  135.         SHL     AX,1
  136.         ADD     DI,AX
  137.         JMP     SHORT LITE_03
  138.     LITE_026:   CMP     BX,6
  139.         JA      LITE_027
  140.         SHL     AX,1
  141.         MOV     DI,AX
  142.         SHL     AX,1
  143.         ADD     DI,AX
  144.         JMP     SHORT LITE_03
  145.     LITE_027:   PUSH    AX
  146.         SHL     AX,1
  147.         MOV     DI,AX
  148.         SHL     AX,1
  149.         ADD     DI,AX
  150.         POP     AX
  151.         ADD     DI,AX
  152.  
  153.     LITE_03:
  154.         MOV     AX,ROW_PARAM        ;get video row param
  155.         DEC     AX                  ;rows numberred from 1 so
  156.         JZ      LITE_04             ;subtract one for mem offset.
  157.         MOV     BX,BYTES_PER_ROW
  158.         MUL     BL
  159.  
  160.     LITE_04:
  161.         MOV     BX,COL_PARAM        ;do same with video column.
  162.         XOR     BH,BH
  163.         DEC     BX
  164.         SHL     BX,1                ;mult by 2 for char/attr pair.
  165.  
  166.  
  167.         ADD     AX,BX
  168.         ADD     DI,AX
  169.         MOV     ES,DX
  170.         MOV     AX,ATR_PARAM        ;get color or attr.
  171.         MOV     CX,LEN_PARAM        ;num of chars to color.
  172.         OR      CX,CX
  173.         JNZ     LITE_05
  174.         JMP     EXIT
  175.  
  176.     LITE_05:
  177.         CMP     IS_CGA_ADAPT,0  ;jump to hardware hassle if Cga
  178.         JNE     LITE_09         ;otherwise just stuff video memory.
  179.  
  180.         OR      BYTE PTR DIR_PARAM,0
  181.         JNZ     LITE_07
  182.  
  183.     LITE_06:    INC     DI                  ;stuff memory horizontally
  184.         STOSB
  185.         LOOP    LITE_06
  186.         JMP     EXIT
  187.  
  188.                     ;or vertically depending on dir param.
  189.     LITE_07:    INC     DI
  190.     LITE_08:    MOV     BYTE PTR ES:[DI],AL
  191.         ADD     DI,BYTES_PER_ROW
  192.         LOOP    LITE_08
  193.         JMP     EXIT
  194.  
  195.     LITE_09:    MOV     DX,03DAh             ;Crt status reg for sync timing
  196.         OR      BYTE PTR DIR_PARAM,0    ;to avoid "snow" on screen.
  197.         JNZ     LITE_13
  198.  
  199.     LITE_10:    INC     DI
  200.         MOV     BX,AX
  201.         CLI                 ;turn off interrupts and wait
  202.     LITE_11:    IN      AL,DX       ;for horiz sync start to avoid snow.
  203.         AND     AL,1
  204.         JNZ     LITE_11
  205.  
  206.     LITE_12:    IN      AL,DX
  207.         AND     AL,1        ;if bit 0 = 1 sync has begun
  208.         JZ      LITE_12
  209.  
  210.         XCHG    AX,BX       ;so stuff one word in memory.
  211.         STOSB
  212.         STI
  213.         LOOP    LITE_10     ;repeat until len param satisfied.
  214.         JMP     EXIT
  215.  
  216.     LITE_13:    ADD     DI,2        ;same as above but in vertacal dir
  217.     LITE_14:    DEC     DI
  218.         DEC     DI
  219.     LITE_15:    MOV     BX,AX
  220.         CLI
  221.     LITE_16:    IN      AL,DX
  222.         AND     AL,1
  223.         JNZ     LITE_16
  224.  
  225.     LITE_17:    IN      AL,DX
  226.         AND     AL,1
  227.         JZ      LITE_17
  228.         XCHG    AX,BX
  229.         STOSB
  230.         STI
  231.         ADD     DI,BYTES_PER_ROW
  232.         LOOP    LITE_14
  233.  
  234.  
  235.     EXIT:
  236.         POPF              ;restore flags & regs
  237.         POP     DI
  238.         POP     ES
  239.         POP     SI
  240.         POP     DS
  241.         MOV     SP,BP
  242.         POP     BP
  243.         RET     12              ;discard params & return
  244. LITEBAR         ENDP
  245.  
  246.     CSEG    ENDS
  247.  
  248.         END     START
  249.  
  250.  
  251.  
  252.  
  253.