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

  1. ;******************************************************
  2. ;           TPCMISC.ASM 5.07
  3. ;           Miscellaneous CRT 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    CurrentDisplay : BYTE        ;Current display type
  28.     EXTRN    EnhancedDisplay    : BYTE        ;Type of enhanced display
  29.                         ;installed, if any
  30.     EXTRN    InTextMode : BYTE        ;False if in graphics mode
  31.     EXTRN    TextAttr : BYTE            ;Current video attribute
  32.     EXTRN    NormalAttr : BYTE;        ;Attribute for NormVideo
  33.     EXTRN    CheckSnow : BYTE        ;If true, check    for retrace
  34.     EXTRN    CtrlBreakFlag :    BYTE        ;True if ^Break    pressed
  35.     EXTRN    VideoSegment : WORD        ;Segment of Video Memory
  36.     EXTRN    VirtualSegment : WORD        ;Segment of Video Memory--alt
  37.     EXTRN    BufLen : WORD            ;Max length of string for Read
  38.     EXTRN    ExitProc : DWORD        ;Turbo's ExitProc pointer
  39.     EXTRN    SaveInt1B : DWORD        ;Previous INT 1Bh handler
  40.     EXTRN    DetectMultitasking : BYTE    ;If True, automatically    checks
  41.                         ;  for multitasker
  42.     EXTRN    MultitaskingOn : BYTE        ;True if running under
  43.                         ;  multitasker
  44.     EXTRN    IsCompaq : BYTE            ;True if system    is a COMPAQ
  45.     EXTRN    BiosScroll : BYTE        ;If False, use special scroll
  46.                         ;  routine
  47.  
  48. DATA    ENDS
  49.  
  50. ;******************************************************    Code
  51.  
  52. CODE    SEGMENT    BYTE PUBLIC
  53.  
  54.     ASSUME    CS:CODE, DS:DATA
  55.  
  56.     ;standard CRT unit routines
  57.  
  58.     PUBLIC    Sound, NoSound,    ClrEol,    InsLine, DelLine
  59.     PUBLIC    ScrollWindowUp,    ScrollWindowDown
  60.  
  61.     ;extensions
  62.  
  63.     PUBLIC    WhereXAbs, WhereYAbs, WhereXY, SetVisiblePage
  64.     PUBLIC    ReadCharAtCursor, ReadAttrAtCursor
  65.     PUBLIC    SetCursorSize, CursorTypeSL, CursorStartLine, CursorEndLine
  66.     PUBLIC    KbdFlags, CheckKbd
  67.  
  68.     EXTRN    ReadCursorPrim : NEAR
  69.     EXTRN    SetCursorPrim :    NEAR
  70.     EXTRN    GetCursorPrim :    NEAR
  71.     EXTRN    GetCrtModePrim : NEAR
  72.     EXTRN    ScrollUpPrim : NEAR
  73.     EXTRN    ScrollDownPrim : NEAR
  74.     EXTRN    GetCharAttr : NEAR
  75.  
  76. ;******************************************************    SetCursorSize
  77.  
  78. ;procedure SetCursorSize(StartLine, EndLine : Byte);
  79. ;Sets the cursor's starting and ending scan lines.
  80.  
  81. SCStart    EQU    BYTE PTR SS:[BX+6]
  82. SCEnd    EQU    BYTE PTR SS:[BX+4]
  83.  
  84. SetCursorSize    PROC FAR
  85.  
  86.     StackFrame            ;Set up    stack frame
  87.     MOV    CH,SCStart        ;CH = starting scan line
  88.     MOV    CL,SCEnd        ;CL = ending scan line
  89.     VideoCall    1        ;Set cursor size service
  90.     RET    4            ;Return
  91.  
  92. SetCursorSize    ENDP
  93.  
  94. ;******************************************************    CursorTypeSL
  95.  
  96. ;function CursorTypeSL : Word;
  97. ;Returns a word. High byte has starting    scan line, low byte has    ending.
  98.  
  99. CursorTypeSL    PROC FAR
  100.  
  101.     CALL    ReadCursorPrim        ;Call our primitive routine
  102.     RET
  103.  
  104. CursorTypeSL    ENDP
  105.  
  106. ;******************************************************    CursorStartLine
  107.  
  108. ;function CursorStartLine : Byte;
  109. ;Returns the starting scan line    of the cursor
  110.  
  111. CursorStartLine    PROC FAR
  112.  
  113.     CALL    ReadCursorPrim        ;Call our primitive routine
  114.     SetZero    AL            ;AL = 0
  115.     XCHG    AH,AL            ;AL has    result,    AH = 0
  116.     RET
  117.  
  118. CursorStartLine    ENDP
  119.  
  120. ;******************************************************    CursorEndLine
  121.  
  122. ;function CursorEndLine    : Byte;
  123. ;Returns the ending scan line of the cursor.
  124.  
  125. CursorEndLine PROC FAR
  126.  
  127.     CALL    ReadCursorPrim        ;Call our primitive routine
  128.     SetZero    AH            ;AH = 0, AL has    result
  129.     RET
  130.  
  131. CursorEndLine ENDP
  132.  
  133. ;******************************************************    WhereXAbs
  134.  
  135. ;function WhereXAbs : Byte;
  136. ;Return    column coordinate of cursor.
  137.  
  138. WhereXAbs    PROC FAR
  139.  
  140.     CALL    GetCursorPrim        ;Get current column into DL
  141.     INC    DL            ;Adjust    for 1..80 format
  142.     SetZero    AH            ;Clear AH
  143.     MOV    AL,DL            ;Result    into AL
  144.     RET
  145.  
  146. WhereXAbs    ENDP
  147.  
  148. ;******************************************************    WhereYAbs
  149.  
  150. ;function WhereYAbs : Byte;
  151. ;Return    row coordinate of cursor
  152.  
  153. WhereYAbs    PROC FAR
  154.  
  155.     CALL    GetCursorPrim        ;Get current row into DH
  156.     INC    DH            ;Adjust    for 1..25 format
  157.     SetZero    AH            ;Clear AH
  158.     MOV    AL,DH            ;Result    into AL
  159.     RET
  160.  
  161. WhereYAbs    ENDP
  162.  
  163. ;******************************************************    WhereXY
  164.  
  165. ;function WhereXY : Word;
  166. ;Return    absolute row and column    coordinates of cursor.
  167. ;High byte has current row (Y),    low byte has current column (X).
  168.  
  169. WhereXY    PROC FAR
  170.  
  171.     CALL    GetCursorPrim        ;Get current column into DL
  172.     INC    DL            ;Adjust    for 1..80 format
  173.     INC    DH            ;Adjust    for 1..25 format
  174.     MOV    AX,DX            ;Result    into AX
  175.     RET
  176.  
  177. WhereXY    ENDP
  178.  
  179. ;******************************************************    KbdFlags
  180.  
  181. ;function KbdFlags : Byte;
  182. ;Returns keyboard status flags as a bit-coded byte
  183.  
  184. KbdFlags    PROC FAR
  185.  
  186.     KbdCall    2            ;Get shift status service
  187.     SetZero    AH            ;Clear AH -- result in AL
  188.     RET
  189.  
  190. KbdFlags    ENDP
  191.  
  192. ;******************************************************    CheckKbd
  193.  
  194. ;function CheckKbd(var KeyCode : Word) : Boolean;
  195. ;Returns True (and the key codes) if a keystroke is waiting
  196.  
  197. KeyCode    EQU    DWORD PTR SS:[BX+4]
  198. KeyPtr    EQU    WORD PTR ES:[DI]
  199.  
  200. CheckKbd    PROC FAR
  201.  
  202.     StackFrame
  203.     SetZero    DX            ;Assume    false (DX has boolean result)
  204.     KbdCall    1            ;Character ready service
  205.     JZ    CkDone            ;Done if zero flag set
  206.     INC    DX            ;DX = Ord(True)
  207.     GetPtr    KeyCode            ;ES:DI points to KeyCode
  208.     MOV    KeyPtr,AX        ;Character and scan code into KeyCode
  209. CKDone:
  210.     MOV    AX,DX            ;Boolean result    into AX
  211.     RET    4
  212.  
  213. CheckKbd    ENDP
  214.  
  215. ;******************************************************    Sound
  216.  
  217. ;procedure Sound(Hz: Word);
  218. ;Turn on the sound at the designated frequency
  219.  
  220. Hertz    EQU    WORD PTR SS:[BX+4]
  221.  
  222. Sound    PROC FAR
  223.  
  224.     StackFrame
  225.     MOV    BX,Hertz        ;BX = Hz
  226.     MOV    AX,34DCh
  227.     MOV    DX,0012h        ;DX:AX = $1234DC = 1,193,180
  228.     CMP    DX,BX            ;Make sure the division    won't
  229.     JAE    SoundExit        ; produce a divide by zero error
  230.     DIV    BX            ;Count (AX) = $1234DC div Hz
  231.     MOV    BX,AX            ;Save Count in BX
  232.  
  233.     IN    AL,61h            ;Check the value in port $61
  234.     TEST    AL,00000011b        ;Bits 0    and 1 set if speaker is    on
  235.     JNZ    SetCount        ;If they're already on, continue
  236.  
  237.     ;turn on speaker
  238.     OR    AL,00000011b        ;Set bits 0 and    1
  239.     OUT    61h,AL            ;Change    the value
  240.     MOV    AL,182            ;Tell the timer    that the count is coming
  241.     OUT    43h,AL            ;by sending 182    to port    $43
  242.  
  243. SetCount:
  244.     MOV    AL,BL            ;Low byte into AL
  245.     OUT    42h,AL            ;Load low order    byte into port $42
  246.     MOV    AL,BH            ;High byte into    AL
  247.     OUT    42h,AL            ;Load high order byte into port    $42
  248.  
  249. SoundExit:
  250.     RET    2
  251.  
  252. Sound    ENDP
  253.  
  254. ;******************************************************    NoSound
  255.  
  256. ;procedure NoSound;
  257. ;Turn off the sound
  258.  
  259. NoSound    PROC FAR
  260.  
  261.     IN    AL,61h            ;Get current value of port $61
  262.     AND    AL,11111100b        ;Turn off bits 0 and 1
  263.     OUT    61h,AL            ;Reset the port
  264.     RET
  265.  
  266. NoSound    ENDP
  267.  
  268. ;******************************************************    SetVisiblePage
  269.  
  270. ;procedure SetVisiblePage(PageNum : Byte);
  271. ;Set current video page
  272.  
  273. PageNum        EQU    BYTE PTR SS:[BX+4]
  274.  
  275. SetVisiblePage    PROC FAR
  276.  
  277.     StackFrame
  278.     MOV    AL,PageNum        ;AL = PageNum
  279.     VideoCall    5        ;Set active display page service
  280.     CALL    GetCrtModePrim        ;make sure the change was accepted
  281.     RET    2
  282.  
  283. SetVisiblePage    ENDP
  284.  
  285. ;******************************************************    ClrEol
  286.  
  287. ;procedure ClrEol;
  288. ;Clear the remainder of    the current screen line
  289.  
  290. ClrEol    PROC FAR
  291.  
  292.     CALL    GetCursorPrim        ;Get current row,col into DH,DL
  293.     MOV    CX,DX            ;top row = bottom row
  294.                     ;left column = right column
  295.     MOV    DL,WindMax.XHigh    ;right column =    right edge of window
  296.     MOV    BH,TextAttr        ;BH = filler attribute
  297.     SetZero    AL            ;AL = 0    (lines to scroll)
  298.     CALL    ScrollUpPrim        ;Call scroll window up primitive
  299.     RET
  300.  
  301. ClrEol    ENDP
  302.  
  303. ;******************************************************    InsLineSetup
  304.  
  305. ;Setup for InsLine and DelLine
  306.  
  307. InsLineSetup    PROC NEAR
  308.  
  309.     CALL    GetCursorPrim        ;Get current row,col into DH,DL
  310.     MOV    CH,DH            ;top row of window = current row
  311.     MOV    CL,WindMin.XLow        ;left column = XLow
  312.     MOV    DX,WindMax        ;right column =    XHigh
  313.                     ;bottom    row = YHigh
  314.     MOV    BH,TextAttr        ;BH = filler attribute
  315.     MOV    AL,1            ;Scroll    one line
  316.     CMP    CH,DH            ;is it a one-line window?
  317.     JNE    ILSdone            ;if not, we're OK
  318.     SetZero    AL            ;else we need to scroll    0 lines
  319. ILSdone:
  320.     RET
  321.  
  322. InsLineSetup    ENDP
  323.  
  324. ;******************************************************    InsLine
  325.  
  326. ;procedure InsLine;
  327. ;Insert    a new line at the position of the cursor
  328.  
  329. InsLine    PROC FAR
  330.  
  331.     CALL    InsLineSetup        ;Call setup routine
  332.     CALL    ScrollDownPrim        ;Call primitive    scroll routine
  333.     RET
  334.  
  335. InsLine    ENDP
  336.  
  337. ;******************************************************    DelLine
  338.  
  339. ;procedure DelLine;
  340. ;Delete    current    screen line
  341.  
  342. DelLine    PROC FAR
  343.  
  344.     CALL    InsLineSetup        ;Call setup routine
  345.     CALL    ScrollUpPrim        ;Call primitive    scroll routine
  346.     RET
  347.  
  348. DelLine    ENDP
  349.  
  350. ;******************************************************    ScrollSetup
  351.  
  352. SsXLo    EQU    BYTE PTR SS:[BX+14]
  353. SsYLo    EQU    BYTE PTR SS:[BX+12]
  354. SsXHi    EQU    BYTE PTR SS:[BX+10]
  355. SsYHi    EQU    BYTE PTR SS:[BX+8]
  356. SsLines    EQU    BYTE PTR SS:[BX+6]
  357.  
  358. ScrollSetup    PROC NEAR
  359.  
  360.     StackFrame
  361.     MOV    CL,SsXLo        ;left column = X1
  362.     DEC    CL
  363.     MOV    CH,SsYLo        ;top row = Y1
  364.     DEC    CH
  365.     MOV    DL,SsXHi        ;right column =    X2
  366.     DEC    DL
  367.     MOV    DH,SsYHi        ;bottom    row = Y2
  368.     DEC    DH
  369.     MOV    AL,SsLines        ;AL = lines to scroll
  370.     MOV    BH,TextAttr        ;BH = filler attribute
  371.     CMP    CH,DH            ;is it a one-line window?
  372.     JNE    SSdone            ;if not, we're OK
  373.     SetZero    AL            ;else we need to scroll    0 lines
  374. SSDone:    RET
  375.  
  376. ScrollSetup    ENDP
  377.  
  378. ;******************************************************    ScrollWindowUp
  379.  
  380. ;procedure ScrollWindowUp(X1, Y1, X2, Y2, Lines    : Byte);
  381. ;Scrolls the designated    window up the specified    number of lines.
  382.  
  383. ScrollWindowUp    PROC FAR
  384.  
  385.     CALL    ScrollSetup        ;Get parameters, load registers
  386.     CALL    ScrollUpPrim        ;Call primitive    scroll routine
  387.     RET    10
  388.  
  389. ScrollWindowUp    ENDP
  390.  
  391. ;******************************************************    ScrollWindowDown
  392.  
  393. ;procedure ScrollWindowDown(X1,    Y1, X2,    Y2, Lines : Byte);
  394. ;Scrolls the designated    window down the    specified number of lines.
  395.  
  396. ScrollWindowDown    PROC FAR
  397.  
  398.     CALL    ScrollSetup        ;Get parameters, load registers
  399.     CALL    ScrollDownPrim        ;Call primitive    scroll routine
  400.     RET    10
  401.  
  402. ScrollWindowDown    ENDP
  403.  
  404. ;******************************************************    ReadCharAtCursor
  405.  
  406. ;function ReadCharAtCursor : Char;
  407. ;Returns character at the current cursor location on the selected page.
  408.  
  409. ReadCharAtCursor    PROC FAR
  410.  
  411.     CALL    GetCharAttr        ;Get character and attribute
  412.     RET                ;Character is in AL
  413.  
  414. ReadCharAtCursor    ENDP
  415.  
  416. ;******************************************************    ReadAttrAtCursor
  417.  
  418. ;function ReadAttrAtCursor : Byte;
  419. ;Returns attribute at the current cursor location on the selected page.
  420.  
  421. ReadAttrAtCursor    PROC FAR
  422.  
  423.     CALL    GetCharAttr        ;Get character and attribute
  424.     MOV    AL,AH            ;Attribute is in AH
  425.     RET
  426.  
  427. ReadAttrAtCursor    ENDP
  428.  
  429. CODE    ENDS
  430.  
  431.     END
  432.