home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPCRT2.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  12.8 KB  |  498 lines

  1. ;******************************************************
  2. ;            TPCRT2.ASM 5.07
  3. ;        Secondary level    routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10.  
  11.     INCLUDE    TPCOMMON.ASM
  12.  
  13. ;******************************************************    Data
  14.  
  15. DATA    SEGMENT    BYTE PUBLIC
  16.  
  17.     ;Pascal    variables
  18.  
  19.     EXTRN    CheckBreak : BYTE        ;Check for ^Break?
  20.     EXTRN    CheckEof : BYTE            ;Check for ^Z on Read/Ln?
  21.     EXTRN    DirectVideo : BYTE        ;If false, use BIOS
  22.     EXTRN    WindMin    : WORD            ;Min. XY coordinates
  23.     EXTRN    WindMax    : WORD            ;Max. XY coordinates
  24.     EXTRN    LastMode : WORD            ;Current video mode
  25.     EXTRN    CurrentMode : BYTE        ;Current video mode
  26.     EXTRN    CurrentPage : BYTE        ;Current video page
  27.     EXTRN    ScreenWidth : BYTE        ;Current width of display
  28.     EXTRN    ScreenHeight : BYTE        ;Current height    of display
  29.     EXTRN    CurrentDisplay : BYTE        ;Current display type
  30.     EXTRN    EnhancedDisplay    : BYTE        ;Type of enhanced display
  31.                         ;installed, if any
  32.     EXTRN    InTextMode : BYTE        ;False if in graphics mode
  33.     EXTRN    TextAttr : BYTE            ;Current video attribute
  34.     EXTRN    NormalAttr : BYTE;        ;Attribute for NormVideo
  35.     EXTRN    CheckSnow : BYTE        ;If true, check    for retrace
  36.     EXTRN    CtrlBreakFlag :    BYTE        ;True if ^Break    pressed
  37.     EXTRN    VideoSegment : WORD        ;Segment of Video Memory
  38.     EXTRN    VirtualSegment : WORD        ;Segment of Video Memory--alt
  39.     EXTRN    BufLen : WORD            ;Max length of string for Read
  40.     EXTRN    ExitProc : DWORD        ;Turbo's ExitProc pointer
  41.     EXTRN    SaveInt1B : DWORD        ;Previous INT 1Bh handler
  42.     EXTRN    DetectMultitasking : BYTE    ;If True, automatically    checks
  43.                         ;  for multitasker
  44.     EXTRN    MultitaskingOn : BYTE        ;True if running under
  45.                         ;  multitasker
  46.     EXTRN    IsCompaq : BYTE            ;True if system    is a COMPAQ
  47.     EXTRN    BiosScroll : BYTE        ;If False, use special scroll
  48.                         ;  routine
  49.     EXTRN    NextChar : BYTE            ;Used by KeyPressed/ReadKey
  50.     EXTRN    OneMS :    WORD            ;Loop count for    1 ms delay
  51.  
  52. DATA    ENDS
  53.  
  54. ;******************************************************    Code
  55.  
  56. CODE    SEGMENT    BYTE PUBLIC
  57.  
  58.     ASSUME    CS:CODE, DS:DATA
  59.  
  60.     ;standard CRT unit routines
  61.  
  62.     PUBLIC    TextColor, TextBackground, LowVideo, HighVideo,    NormVideo
  63.     PUBLIC    Delay, KeyPressed, GotoXY, WhereX, WhereY, TextMode, Window
  64.     PUBLIC    ClrScr
  65.  
  66.     ;extensions
  67.  
  68.     PUBLIC    ReadKeyWord, GotoXYabs,    GetCrtMode
  69.     PUBLIC    Font8x8Selected, SelectFont8x8
  70.  
  71.     ;routines in TPCRT.ASM
  72.  
  73.     EXTRN    ReadCursorPrim : NEAR
  74.     EXTRN    SetCursorPrim :    NEAR
  75.     EXTRN    GetCursorPrim :    NEAR
  76.     EXTRN    GetCrtModePrim : NEAR
  77.     EXTRN    ScrollUpPrim : NEAR
  78.     EXTRN    ScrollDownPrim : NEAR
  79.     EXTRN    AdapterCheck : NEAR
  80.     EXTRN    DelayMS    : NEAR
  81.     EXTRN    GetCharAttr : NEAR
  82.     EXTRN    SetWindowPrim :    NEAR
  83.     EXTRN    FullWindow : NEAR
  84.     EXTRN    GetAttribute : NEAR
  85.  
  86.     ;routines in TPCRT.PAS
  87.  
  88.     EXTRN    CrtTest    : NEAR
  89.  
  90. ;******************************************************    LowVideo
  91.  
  92. ;procedure LowVideo;
  93. ;Select    low intensity
  94.  
  95. LowVideo    PROC FAR
  96.  
  97.     AND    TextAttr,01110111b    ;Intensity bit off, blink bit off
  98.     RET
  99.  
  100. LowVideo    ENDP
  101.  
  102. ;******************************************************    HighVideo
  103.  
  104. ;procedure HighVideo;
  105. ;Select    high intensity
  106.  
  107. HighVideo    PROC FAR
  108.  
  109.     OR    TextAttr,00001000b    ;Intensity bit on
  110.     RET
  111.  
  112. HighVideo    ENDP
  113.  
  114. ;******************************************************    NormVideo
  115.  
  116. ;procedure NormVideo;
  117. ;Select    video attribute    used at    start of program
  118.  
  119. NormVideo    PROC FAR
  120.  
  121.     MOV    AL,NormalAttr        ;AL = Normal attribute
  122.     MOV    TextAttr,AL        ;Current attribute = Normal attribute
  123.     RET
  124.  
  125. NormVideo    ENDP
  126.  
  127. ;******************************************************    TextColor
  128.  
  129. ;procedure TextColor(Color : Byte);
  130. ;Set foreground    color for screen writes
  131.  
  132. NewColor    EQU    BYTE PTR SS:[BX+4]
  133.  
  134. TextColor    PROC FAR
  135.  
  136.     StackFrame
  137.     MOV    AL,NewColor        ;New foreground    color into AL
  138.     TEST    AL,11110000b        ;See if    blink requested
  139.     JZ    SkipBlink        ;If not, don't set blink bit
  140.     AND    AL,00001111b        ;Only blink and    foreground bits
  141.     OR    AL,Blink        ;Set blink bit
  142.  
  143. SkipBlink:
  144.     AND    TextAttr,01110000b    ;Retain    current    background color
  145.     OR    TextAttr,AL        ;Merge in new foreground color
  146.     CALL    CrtTest            ;test for presence of CRT unit
  147.     RET    2
  148.  
  149. TextColor    ENDP
  150.  
  151. ;******************************************************    TextBackground
  152.  
  153. ;procedure TextBackground(Color    : Byte);
  154. ;Set background    color for screen writes
  155.  
  156. TextBackground    PROC FAR
  157.  
  158.     StackFrame
  159.     MOV    AL,NewColor        ;New foreground    color into AL
  160.     AND    AL,00000111b        ;Only bottom three bits    are significant
  161.     MOV    CL,4            ;Move bottom 4 bits into top 4 bits
  162.     SHL    AL,CL
  163.     AND    TextAttr,10001111b    ;Retain    current    blink/foreground
  164.     OR    TextAttr,AL        ;Merge in new background color
  165.     CALL    CrtTest            ;test for presence of CRT unit
  166.     RET    2
  167.  
  168. TextBackground    ENDP
  169.  
  170. ;******************************************************    KeyPressed
  171.  
  172. ;function KeyPressed : Boolean;
  173. ;Return    true if    a key has been pressed
  174.  
  175. KeyPressed    PROC FAR
  176.  
  177.     CMP    NextChar,0        ;See if    a character is waiting
  178.     JA    KeyFound        ;If so,    we're done
  179.     KbdCall    1            ;Character ready service
  180.     MOV    AL,False        ;Assume    false
  181.     JZ    KeyExit            ;No keypress if    zero flag is set
  182.  
  183. KeyFound:
  184.     MOV    AL,True            ;AL = True
  185.  
  186. KeyExit:
  187.     RET
  188.  
  189. KeyPressed    ENDP
  190.  
  191. ;******************************************************    ReadKeyWord
  192.  
  193. ;function ReadKeyWord :    Word;
  194. ;Waits for keypress, then returns scan and character codes together in AX
  195.  
  196. ReadKeyWord    PROC FAR
  197.  
  198. ReadKeyWordStart:
  199.     INT    28h            ;Help keep popups from locking out
  200.                     ;other TSR's
  201.     KbdCall    1            ;Key pressed function
  202.     JZ    ReadKeyWordStart    ;If no keypress, loop
  203.  
  204.     KbdCall    0            ;Read next character service
  205.     RET
  206.  
  207. ReadKeyWord    ENDP
  208.  
  209. ;******************************************************    GotoXY
  210.  
  211. ;procedure GotoXY(X, Y : Byte);
  212. ;Move cursor to    column X, row Y, relative to Window
  213.  
  214. XGoto    EQU    BYTE PTR SS:[BX+6]
  215. YGoto    EQU    BYTE PTR SS:[BX+4]
  216.  
  217. GotoXY    PROC FAR
  218.  
  219.     StackFrame
  220.     MOV    DH,YGoto        ;DH = new row
  221.     DEC    DH            ;Now in    0..24 format
  222.     ADD    DH,WindMin.YLow        ;Account for window
  223.     JB    ExitXY            ;Exit if number    is negative
  224.     CMP    DH,WindMax.YHigh    ;out of    window?
  225.     JA    ExitXY            ;If so,    exit
  226.     MOV    DL,XGoto        ;DL = new column
  227.     DEC    DL            ;Now in    0..79 format
  228.     ADD    DL,WindMin.XLow        ;Account for window
  229.     JB    ExitXY            ;Exit if number    is negative
  230.     CMP    DL,WindMax.XHigh    ;out of    window?
  231.     JA    ExitXY            ;If so,    exit
  232.     CALL    SetCursorPrim        ;Primitive routine to move the cursor
  233. ExitXY:
  234.     CALL    CrtTest            ;test for presence of CRT unit
  235.     RET    4
  236.  
  237. GotoXY    ENDP
  238.  
  239. ;******************************************************    GotoXYAbs
  240.  
  241. ;procedure GotoXYAbs(X,    Y : Byte);
  242. ;Move cursor to    column X, row Y. No error checking done.
  243.  
  244. GotoXYAbs    PROC FAR
  245.  
  246.     StackFrame
  247.     MOV    DH,YGoto        ;DH = new row
  248.     DEC    DH            ;Now in    0..24 format
  249.     MOV    DL,XGoto        ;DL = new column
  250.     DEC    DL            ;Now in    0..79 format
  251.     CALL    SetCursorPrim        ;Primitive routine to move the cursor
  252.     RET    4
  253.  
  254. GotoXYAbs    ENDP
  255.  
  256. ;******************************************************    WhereX
  257.  
  258. ;function WhereX : Byte;
  259. ;Return    column coordinate of cursor, relative to Window
  260.  
  261. WhereX    PROC FAR
  262.  
  263.     CALL    GetCursorPrim        ;Get current column into DL
  264.     SUB    DL,WindMin.XLow        ;Subtract XLow
  265.     INC    DL            ;Adjust    for 1..80 format
  266.     SetZero    AH            ;Clear AH
  267.     MOV    AL,DL            ;Result    into AL
  268.     RET
  269.  
  270. WhereX    ENDP
  271.  
  272. ;******************************************************    WhereY
  273.  
  274. ;function WhereY : Byte;
  275. ;Return    row coordinate of cursor, relative to Window
  276.  
  277. WhereY    PROC FAR
  278.  
  279.     CALL    GetCursorPrim        ;Get current row into DH
  280.     SUB    DH,WindMin.YLow        ;Subtract YLow
  281.     INC    DH            ;Adjust    for 1..25 format
  282.     SetZero    AH            ;Clear AH
  283.     MOV    AL,DH            ;Result    into AL
  284.     RET
  285.  
  286. WhereY    ENDP
  287.  
  288. ;******************************************************    Font8x8Selected
  289.  
  290. ;function Font8x8Selected : Boolean;
  291. ;Return    True if    EGA or VGA is active and in 8x8    font (43-line /    50-line    mode)
  292.  
  293. Font8x8Selected    PROC FAR
  294.  
  295.     CALL    GetCrtModePrim        ;Get current video mode
  296.     CALL    AdapterCheck        ;Get adapter type
  297.     SetZero    AX            ;Assume    false
  298.     TEST    LastMode,Font8x8    ;8x8 font bit set?
  299.     JZ    FSexit            ;if not, exit
  300.     INC    AX            ;AX = 1
  301. FSExit:    RET
  302.  
  303. Font8x8Selected    ENDP
  304.  
  305. ;******************************************************    SelectFont8x8
  306.  
  307. ;procedure SelectFont8x8(On : Boolean);
  308. ;Toggle    8x8 font on or off. Does not reset Window() or clear the screen!
  309.  
  310. FontOn        EQU    BYTE PTR SS:[BX+4]
  311. EmulationFlag    EQU    BYTE PTR ES:[DI]
  312.  
  313. SelectFont8x8    PROC FAR
  314.  
  315.     CALL    AdapterCheck        ;Check display type
  316.     StackFrame            ;Set up    stack frame
  317.     MOV    CH,FontOn        ;CH = FontOn
  318.     MOV    CL,CurrentDisplay    ;CL = CurrentDisplay
  319.     CMP    CL,EGA            ;EGA or    VGA?
  320.     JB    SFDone            ;Done if not
  321.     MOV    AX,1112h        ;AX = $1112 (turns it on for EGA or VGA)
  322.     CMP    CH,True            ;Turn it on?
  323.     JE    SFGo            ;if so,    go
  324.     DEC    AX            ;AX = $1111 (turns it off on EGA)
  325.     CMP    CL,EGA            ;is it an EGA?
  326.     JE    SFGo            ;if so,    go
  327.     MOV    AX,1114h        ;else, AX = $1114 (turns it off    on VGA)
  328. SFGo:
  329.     SetZero    BL            ;BL = 0
  330.     VideoPrim            ;Call BIOS
  331.  
  332.     ;turn cursor emulation on or off
  333.     MOV    AX,40h            ;AX = $40
  334.     MOV    ES,AX            ;ES = $40
  335.     MOV    DI,87h            ;ES:DI => Emulation flag
  336.     SHR    CH,1            ;Turning Font on?
  337.     JC    EmulationOff        ;If so,    turn emulation off
  338.     AND    EmulationFlag,0FEh    ;turns emulation on
  339.     MOV    CX,0607h        ;cursor    scan lines
  340.     JMP    SHORT SFSetCursor    ;reset the cursor
  341.  
  342. EmulationOff:
  343.     OR    EmulationFlag,1        ;turns emulation off
  344.     MOV    CX,0507h        ;cursor    scan lines
  345.  
  346. SFSetCursor:
  347.     CMP    CurrentMode,7        ;In mono mode?
  348.     JE    SFCheck            ;Exit if so, else...
  349.     VideoCall    1        ;Set cursor scan lines
  350.  
  351. SFCheck:
  352.     CALL    AdapterCheck        ;Call primitive    routine    to reset vars
  353.     MOV    AH,12h            ;select    alternate print    screen routine
  354.     MOV    BL,20h
  355.     VideoPrim
  356. SFDone:    RET    2
  357.  
  358. SelectFont8x8    ENDP
  359.  
  360. ;******************************************************    GetCrtMode
  361.  
  362. ;procedure GetCrtMode :    Byte;
  363. ;Return    the current video mode in AX
  364.  
  365. GetCrtMode    PROC FAR
  366.  
  367.     CALL    GetCrtModePrim        ;Call primitive    routine
  368.     SetZero    AH            ;AH = 0, result    in AL
  369.     RET
  370.  
  371. GetCrtMode    ENDP
  372.  
  373. ;******************************************************    TextMode
  374.  
  375. ;procedure TextMode(Mode : Word);
  376. ;Set the current video mode
  377.  
  378. TModeW    EQU    WORD PTR SS:[BX+4]
  379.  
  380. TextMode    PROC FAR
  381.  
  382.     StackFrame
  383.     MOV    AX,40h            ;AX = $40
  384.     MOV    ES,AX            ;ES = $40
  385.     AND    BYTE PTR ES:[87h],0FEh    ;turn cursor emulation on
  386.     MOV    AX,TModeW        ;AX = Mode
  387.     PUSH    AX            ;Save mode
  388.     VideoCall    0        ;Set video mode    service
  389.     POP    AX            ;Reload    AH
  390.     TEST    AX,Font8x8        ;Is Font8x8 requested?
  391.     JZ    TMnoFont        ;No font change    if it isn't
  392.     MOV    AL,True            ;AL = True
  393.     PUSH    AX            ;Pass True as the parameter
  394.     CALL    SelectFont8x8        ;Call the font change routine
  395. TMnoFont:
  396.     CALL    GetCrtModePrim        ;Make sure variables are up-to-date
  397.     CALL    AdapterCheck        ;In case we switched in/out of 8x8 mode
  398.     CALL    FullWindow        ;set window coordinates
  399.     CMP    InTextMode,False    ;are we    still in text mode?
  400.     JNE    TMexit            ;if not, we're finished
  401.     CALL    GetAttribute        ;re-initialize attribute variables
  402. TMexit:
  403.     RET    2
  404.  
  405. TextMode    ENDP
  406.  
  407. ;******************************************************    Window
  408.  
  409. ;procedure Window(XLow,    YLow, XHigh, YHigh : Byte);
  410. ;Set current window coordinates
  411.  
  412. WXLow    EQU    BYTE PTR SS:[BX+10]
  413. WYLow    EQU    BYTE PTR SS:[BX+8]
  414. WXHigh    EQU    BYTE PTR SS:[BX+6]
  415. WYHigh    EQU    BYTE PTR SS:[BX+4]
  416.  
  417. Window    PROC FAR
  418.  
  419.     CALL    CrtTest            ;test for presence of CRT unit
  420.     StackFrame
  421.     MOV    DL,WXLow        ;DL = XLow
  422.     MOV    DH,WXHigh        ;DH = XHigh
  423.     MOV    CL,WYLow        ;CL = YLow
  424.     MOV    CH,WYHigh        ;CH = YHigh
  425.     DEC    DL            ;Convert all to    BIOS format
  426.     DEC    DH
  427.     DEC    CL
  428.     DEC    CH
  429.     CMP    CL,CH            ;YLow >    YHigh?
  430.     JA    WinExit            ;If so,    exit
  431.     CMP    DL,DH            ;XLow >    XHigh?
  432.     JA    WinExit            ;If so,    exit
  433.     CMP    DH,BYTE    PTR ScreenWidth    ;XHigh >= screen width?
  434.     JAE    WinExit            ;If so,    exit
  435.     CMP    CH,ScreenHeight        ;YHigh >= screen height?
  436.     JAE    WinExit            ;If so,    exit
  437.     CALL    SetWindowPrim        ;Call primitive    routine
  438.     MOV    DX,WindMin        ;Load XLow and YLow into DX
  439.     CALL    SetCursorPrim        ;Move cursor into window
  440. WinExit:
  441.     RET    8
  442.  
  443. Window    ENDP
  444.  
  445. ;******************************************************    ClrScr
  446.  
  447. ;procedure ClrScr;
  448. ;Clear the current window
  449.  
  450. ClrScr    PROC FAR
  451.  
  452.     MOV    BH,TextAttr        ;BH = current attribute
  453.     MOV    CX,WindMin        ;CX has    XLow,YLow
  454.     MOV    DX,WindMax        ;DX has    XHigh,YHigh
  455.  
  456.     SetZero    AL            ;AL = 0
  457.     CALL    ScrollUpPrim        ;Call scroll window up primitive
  458.     MOV    DX,WindMin        ;DX has    coordinates of top left    corner
  459.     CALL    SetCursorPrim        ;Call routine to set cursor
  460.     CALL    CrtTest            ;test for presence of CRT unit
  461.     RET
  462.  
  463. ClrScr    ENDP
  464.  
  465. ;******************************************************    Delay
  466.  
  467. ;procedure Delay(MS: Word);
  468. ;Delay for MS milliseconds
  469.  
  470. MSecs    EQU    WORD PTR SS:[BX+4]
  471.  
  472. Delay    PROC FAR
  473.  
  474.     StackFrame
  475.     MOV    DX,MSecs        ;DX = MS
  476.     OR    DX,DX            ;Do nothing if MS = 0
  477.     JZ    DelayExit
  478.     XOR    DI,DI            ;ES:DI points to dummy address
  479.     MOV    ES,DI            ; which    won't change
  480.     MOV    AL,ES:[DI]        ;AL has    the value there
  481.     MOV    BX,OneMS        ;BX has    loop count for one MS
  482.  
  483. DelayLoop:
  484.     MOV    CX,BX            ;loop count into CX
  485.     CALL    DelayMS            ;delay for one MS
  486.     DEC    DX            ;decrement counter
  487.     JNZ    DelayLoop        ;repeat    if not 0
  488.  
  489. DelayExit:
  490.     RET    2
  491.  
  492. Delay    ENDP
  493.  
  494.  
  495. CODE    ENDS
  496.  
  497.     END
  498.