home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Basic / SDA30.ZIP / BASSCR.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-08-26  |  12.2 KB  |  478 lines

  1.  TITLE    BASSCR    - Screen Design    Aid - Support Module
  2.  SUBTTL    Version    1.0 - January 1983
  3.  PAGE    81,132
  4.  COMMENT \
  5. *******************************************************************************
  6. *         Copyright 1983    - DD Systems - Springdale, AR              *
  7. *******************************************************************************
  8. *                                          *
  9. *    The utilities required to service a screen under BASIC              *
  10. *                                          *
  11. *   Calls:    DISP - to display primary screen                  *
  12. *   *-Local    FLDOUT - to output a string to a field                  *
  13. *        FLDINP - to input from a field                      *
  14. *        FLDCLR - to clear a field                      *
  15. *        FLDPOS - to position to    a field                      *
  16. *                                          *
  17. *   Data (Ext):    Compressed image    Data (Loc):    IMGCNT - Count of screens     *
  18. *                        IMGTAB - Pointer to screens   *
  19. *                        IMGPTR - Offset    of current    *
  20. *                             compressed image     *
  21. *                        IMGFLG - hardware line length *
  22. *                                          *
  23. *    The primary entry point    simply determines which    function is being     *
  24. *    invoked, and transfers control to that function.  All registers          *
  25. *    are saved and restored.     Interface with    the BASIC data area is          *
  26. *    also performed.                                  *
  27. *                                          *
  28. ******************************************************************************\
  29. ;;
  30. ;;    Console    output - Normal    - P1 or    the content of the DL register is
  31. ;;                  output to the    current    cursor position.
  32. ;;
  33. $COUT    MACRO    P1
  34.     IFNB    <P1>
  35.     MOV    DL,P1
  36.     ENDIF
  37.     MOV    AH,2
  38.     INT    21H
  39.     ENDM
  40. ;;
  41. ;;    Console    Input -    No Echo    - Wait - Character is returned in AL
  42. ;;
  43. $CINE    MACRO
  44.     MOV    AH,8
  45.     INT    21H
  46.     ENDM
  47. ;
  48. ;  The following structure defines the stack content on    entry.
  49. ;
  50. PARMS    STRUC
  51. ;
  52. SAVEBP    DW    ?
  53. SAVOFF    DW    ?
  54. SAVSEG    DW    ?
  55. PARM3    DW    ?
  56. PARM2    DW    ?
  57. PARM1    DW    ?
  58. ;
  59. PARMS    ENDS
  60. ;
  61. PLENG    EQU    6
  62. ;
  63. CODE    SEGMENT    BYTE PUBLIC 'CODE'
  64.     ASSUME    CS:CODE,DS:CODE
  65. ;
  66.     EXTRN    BASMEN:BYTE        ;Expects an external stack of screens
  67. ;
  68. IMGCNT    DW    -1            ;Set for initialization
  69. IMGTAB    DW    10 DUP (?)        ;Up to 10 screens
  70. IMGPTR    DW    0            ;Current compressed image pointer
  71. IMGFLG    DB    0            ;Length    flag for image 0=80,1=40
  72. IMGLEN    DB    0            ;Length    of hardware line
  73. ;
  74. SAVSS    DW    0            ;Stack seg save    area
  75. SAVSP    DW    0            ;Stack pointer save area
  76. SAVSI    DW    0            ;String    pointer    save area
  77. PRM2    DW    0            ;Pointer to second parameter
  78. ;
  79. SBUF    DB    81 DUP (?)        ;Work buffer
  80. ;
  81.     DB    10 DUP ('STACK ')    ;Internal stack    area
  82. ENDSTK    EQU    $
  83. ;
  84.     PUBLIC    BASSCR
  85. ;
  86. BASSCR    PROC    FAR
  87.     PUSH    BP
  88.     MOV    BP,SP            ;Get stack reference
  89.     MOV    SI,[BP].PARM1        ;Get ptr to first parm
  90.     MOV    AX,WORD    PTR [SI]    ;Get first parm
  91.     MOV    SI,[BP].PARM2        ;Get ptr to second parm
  92.     MOV    DI,SI            ;Save it for return of data
  93.     MOV    BX,WORD    PTR [SI]    ;Get second parm
  94.     MOV    SI,[BP].PARM3        ;Get ptr to string vector
  95.     MOV    CX,CS            ;Now we    can blow DS
  96.     MOV    DS,CX            ;Addressability    to 'code' segment
  97.     MOV    PRM2,DI            ;Save 2nd parm pointer
  98.     MOV    SAVSS,SS        ;Save old stack    segment
  99.     MOV    SAVSP,SP        ;   and    pointer
  100.     MOV    SAVSI,SI        ;Also string vector address
  101.     MOV    SS,CX            ;Set to    new stack
  102.     MOV    SP,OFFSET ENDSTK
  103.     PUSH    ES            ;Now save ES
  104.     OR    AX,AX            ;Check command
  105.     JZ    DISP            ;Standard display screen
  106.     DEC    AX
  107.     JNZ    A1
  108.     JMP    FLDOUT            ;Field output request
  109. A1:    DEC    AX
  110.     JNZ    A2
  111.     JMP    FLDINP            ;Field input request
  112. A2:    DEC    AX
  113.     DEC    AX
  114.     JNZ    A3
  115.     JMP    FLDCLR            ;Field clear request
  116. A3:    DEC    AX
  117.     JNZ    RESRET
  118.     JMP    FLDPOS            ;Field position    request
  119. RESRET:    MOV    SS,SAVSS        ;Restore stack segment
  120.     MOV    SP,SAVSP        ;  and pointer
  121.     MOV    AX,SS
  122.     MOV    ES,AX
  123.     MOV    DS,AX
  124.     POP    BP
  125.     RET    PLENG            ;Do a "far" return
  126. ;
  127. ;    Display    Menu - Expects BX to contain the number    of the
  128. ;            compressed image to be displayed.  This    reference
  129. ;            is saved for field handling calls.
  130. ;
  131. DISP:    MOV    AX,IMGCNT        ;Check count for initial value
  132.     INC    AX
  133.     JNZ    IMGINT            ;Already initialized
  134.     CALL    SETAB            ;Set up    image table
  135. IMGINT:    DEC    BX            ;Image number -    1
  136.     SHL    BX,1            ;  times two
  137.     MOV    DX,IMGTAB[BX]        ;Get pointer to    image
  138.     MOV    IMGPTR,DX        ;   and    save for field calls
  139.     CALL    SETES            ;Set ES    to proper regen    buffer
  140.     XOR    CX,CX
  141.     MOV    DI,CX            ;Initialize regen pointer
  142.     CLD                ;Assure    direction
  143.     MOV    SI,DX            ;Point to image
  144.     LODSW                ;Load field count
  145.     ADD    AX,AX
  146.     ADD    AX,AX            ;AX contains size of field table
  147.     ADD    SI,AX            ;So step over it
  148.     LODSW                ;Load size of compressed image
  149.     MOV    IMGFLG,0
  150.     TEST    AH,80H            ;Establish image size flag
  151.     JZ    SIMG1
  152.     MOV    IMGFLG,1        ;Forty character image
  153.     AND    AH,7FH
  154. SIMG1:    MOV    BX,SI
  155.     ADD    BX,AX            ;BX points one cell beyond image
  156.     MOV    AH,7            ;Initial attribute
  157. LODLP:    CMP    SI,BX            ;See if    out of screen
  158.     JAE    LODDNE            ;Out, so display complete
  159.     LODSB                ;Get image byte
  160.     INC    AL            ;Check for attribute flag
  161.     JNZ    LOD1            ;Not attribute flag
  162.     LODSB                ;Load attribute
  163.     MOV    AH,AL            ;   and    save
  164.     JMP    LODLP
  165. LOD1:    INC    CX            ;Set loop count    to 1
  166.     DEC    AL            ;Test for repeat count flag
  167.     JNZ    LOD2            ;No
  168.     LODSB                ;Load repeat count
  169.     MOV    CL,AL            ;   and    set loop count
  170.     LODSB                ;Load character    to be repeated
  171. LOD2:    REP    STOSW            ;Store character and attribute in regen
  172.     JMP    LODLP
  173. LODDNE:    CMP    IMGLEN,160        ;Check for hardware LL
  174.     JZ    LD80
  175.     TEST    IMGFLG,1
  176.     JZ    LDFIX
  177.     MOV    IMGFLG,0        ;40/40,    so no adjustment
  178.     JMP    SHORT LODOUT
  179. LD80:    TEST    IMGFLG,1
  180.     JZ    LODOUT            ;80/80,    so no adjustment
  181. LDFIX:    PUSH    DS
  182.     PUSH    ES
  183.     POP    DS
  184.     TEST    CS:IMGFLG,1
  185.     JZ    LDTRNC            ;Truncate screen
  186.     STD                ;Center    screen
  187.     MOV    SI,7CEH            ;Point to end of image
  188.     MOV    DI,0F9EH        ;Point to end of screen
  189.     MOV    DL,25            ;Do 25 lines
  190. XLP2:    MOV    CX,20
  191.     MOV    AX,720H            ;Clear 20 columns
  192.     REP    STOSW
  193.     MOV    CX,40            ;Move 40 columns
  194.     REP    MOVSW
  195.     MOV    CX,20
  196.     MOV    AX,720H            ;Clear 20 columns
  197.     REP    STOSW
  198.     DEC    DL
  199.     JNZ    XLP2            ;Loop through 25 lines
  200.     CLD
  201.     JMP    SHORT LODPOP
  202. LDTRNC:    XOR    SI,SI            ;Truncate image
  203.     MOV    DI,SI
  204.     MOV    DL,25
  205. XLP1:    MOV    CX,40            ;Move 40 columns
  206.     REP    MOVSW
  207.     ADD    SI,80            ;Skip 40 columns
  208.     DEC    DL
  209.     JNZ    XLP1            ;Loop through 25 lines
  210. LODPOP:    POP    DS
  211. LODOUT:    JMP    RESRET            ;Restore registers
  212. ;
  213. ;    Field Output - Expects DX to point to string for output
  214. ;
  215. FLDOUT:    MOV    CX,WORD    PTR ES:[SI]    ;Get length of string
  216.     CMP    CX,80
  217.     JBE    LENOK
  218.     MOV    CX,80            ;Force to 80 as    max
  219. LENOK:    MOV    SI,WORD    PTR ES:[SI+2]    ;Now point to string
  220.     XOR    DI,DI
  221. OLP1:    MOV    AL,BYTE    PTR ES:[SI]    ;Get Basic's string
  222.     MOV    SBUF[DI],AL        ;  and put in work buffer
  223.     INC    SI
  224.     INC    DI
  225.     LOOP    OLP1            ;Loop till string in buffer
  226.     MOV    SBUF[DI],0        ;Put on    terminator
  227.     MOV    SI,OFFSET SBUF        ;String    pointer    to SI
  228.     MOV    AX,BX            ;Put field number in AL
  229.     CALL    FNDFLD            ;Set for field requested
  230.     CALL    SETES            ;Set ES    for regen buffer
  231.     ADD    DL,CL            ;Make col end of field plus 1
  232. FO1:    LODSB                ;Get string byte
  233.     OR    AL,AL            ;Check for terminator
  234.     JZ    FO3            ;String    shorter    than field
  235.     STOSW                ;Save string byte and attribute
  236.     LOOP    FO1            ;Loop till end of field
  237. FO2:    CALL    SETCUR            ;Position cursor
  238.     JMP    RESRET            ;  and return
  239. FO3:    MOV    AL,' '
  240.     REP    STOSW            ;Clear remainder of field
  241.     JMP    FO2
  242. ;
  243. ;    Clear requested    field to field attribute
  244. ;
  245. FLDCLR:    CALL    DOCLR
  246.     JMP    RESRET
  247. ;
  248. ;    Position cursor    to start of field
  249. ;
  250. FLDPOS:    MOV    AX,BX
  251.     CALL    SETRCL            ;Get row/col
  252.     CALL    SETCUR            ;  and set cursor
  253.     JMP    RESRET
  254. ;
  255. ;    Field Input
  256. ;
  257. FLDINP:    MOV    AX,BX
  258.     PUSH    AX            ;Save field number
  259.     TEST    AL,80H
  260.     JNZ    NOCLR            ;Don't clear before input
  261.     AND    AL,7FH
  262.     CALL    DOCLR            ;Clear the field in AL
  263. NOCLR:    POP    AX
  264.     AND    AL,7FH            ;Clear flag bit, if any
  265.     CALL    SETES
  266.     CALL    FNDFLD            ;Set for field data
  267.     MOV    BL,AH            ;Save attribute
  268.     INC    CL            ;Make field one    count longer
  269.     MOV    SI,OFFSET SBUF        ;Use internal buffer
  270.     JMP    SHORT SETC        ;  and enter read loop
  271. ;
  272. ILP:    DEC    CL            ;Decrement characters remaining
  273.     JZ    BEEP            ;Out of    field
  274.     MOV    BYTE PTR [SI],AL    ;Save current input byte
  275.     INC    SI            ;   and    setp to    next buffer locn
  276.     INC    DL            ;Step cursor position
  277.     INC    CH            ;Step string (read) length
  278.     MOV    AH,BL            ;Restore attribute
  279.     STOSW                ;  and put char    and attrb to screen
  280. SETC:    CALL    SETCUR            ;Advance cursor
  281. FIINP:    $CINE                ;Read next character
  282.     OR    AL,AL
  283.     JZ    SCODE            ;Scan code character coming
  284.     CMP    AL,13
  285.     JZ    CR            ;Carriage return input
  286.     CMP    AL,1BH
  287.     JZ    ESC            ;Escape    input
  288.     CMP    AL,9
  289.     JZ    TABR            ;Tab right input
  290.     CMP    AL,8
  291.     JZ    BS            ;Back space input
  292.     CMP    AL,7FH
  293.     JZ    BS            ;Delete    input
  294.     CMP    AL,' '
  295.     JB    FIINP            ;Don't take anything less than blank
  296.     JMP    ILP            ;Go save character
  297. ;
  298. BEEP:    PUSH    DX
  299.     $COUT    7            ;Out of    field, so "beep" at him
  300.     POP    DX
  301.     INC    CL
  302.     JMP    FIINP
  303. ;
  304. CR:    XOR    AH,AH            ;Set flag register
  305. COM:    MOV    BYTE PTR[SI],0        ;Set nul at end    of string
  306.     MOV    AL,AH
  307.     CBW
  308.     MOV    DI,PRM2
  309.     POP    ES
  310.     STOSW                ;Save return code
  311.     MOV    AL,CH
  312.     CBW
  313.     MOV    CX,AX            ;Set CX    to input string    length
  314.     MOV    SI,SAVSI        ;Get string vector pointer
  315.     CMP    CX,WORD    PTR ES:[SI]
  316.     JBE    INLOK            ;Less than or equal to string
  317.     MOV    CX,WORD    PTR ES:[SI]       ;Don't move more than field length
  318. INLOK:    PUSH    CX
  319.     MOV    DI,WORD    PTR ES:[SI+2]       ;Get    pointer    to string
  320.     MOV    SI,OFFSET SBUF
  321.     REP    MOVSB            ;Move string to    BASIC
  322.     MOV    SI,SAVSI        ;Get pointer again
  323.     MOV    CX,WORD    PTR ES:[SI]       ;Compute difference in length
  324.     POP    AX
  325.     SUB    CX,AX
  326.     JZ    INDNE
  327.     MOV    AL,' '
  328.     REP    STOSB            ;Clear remainder of string
  329. INDNE:    JMP    RESRET
  330. ;
  331. SCODE:    $CINE                ;Get next character after nul
  332.     MOV    AH,8
  333.     CMP    AL,15
  334.     JNZ    SCN1
  335.     MOV    AH,2            ;Set Tab left flag
  336. SCN1:    OR    AL,80H            ;Set scan code zone
  337.     MOV    BYTE PTR [SI],AL    ;  and save character
  338.     INC    SI
  339.     INC    CH            ;Step pointer and length of string
  340. CARRY:    STC                ;Set flag
  341.     JMP    COM
  342. ;
  343. TABR:    MOV    AH,1            ;Set tab right flag
  344.     JMP    CARRY
  345. ;
  346. ESC:    MOV    AH,4            ;Escape    flag
  347.     JMP    CARRY
  348. ;
  349. BS:    OR    CH,CH            ;See if    at start
  350.     JNZ    BS1
  351.     JMP    FIINP            ;Yes, so ignore    BS
  352. BS1:    DEC    CH            ;Decrement string length
  353.     INC    CL            ;  and add back    to field length
  354.     DEC    SI            ;Step back buffer pointer
  355.     MOV    AH,BL            ;Restore attribute
  356.     MOV    AL,' '
  357.     SUB    DI,2            ;Move screen pointer back
  358.     STOSW                ;Blank last character on screen
  359.     SUB    DI,2
  360.     DEC    DL            ;Step cursor back
  361.     JMP    SETC
  362. ;
  363. BASSCR    ENDP
  364. ;
  365. ;    Sets ES    to proper segment for equipment    "installed"
  366. ;
  367. SETES    PROC    NEAR
  368.     PUSH    AX
  369.     INT    11H            ;Get equipment word
  370.     AND    AL,30H
  371.     XOR    AL,30H            ;Mask for display type
  372.     JNZ    ES1            ;Not a Mono
  373.     MOV    AX,0B000H        ;Monochrome Adapter
  374.     JMP    ES2
  375. ES1:    MOV    AX,0B800H        ;Color/graphics    Adapter
  376. ES2:    MOV    ES,AX            ;Set ES    for regen buffer
  377.     MOV    AH,15
  378.     INT    10H            ;Check DOS mode
  379.     SHL    AH,1
  380.     MOV    IMGLEN,AH        ;Save hardware line length
  381.     POP    AX
  382.     RET
  383. SETES    ENDP
  384. ;
  385. ;    Find field - Sets DI to    regen offset for field
  386. ;              DX to    row/col    for field
  387. ;              CX to    length of field
  388. ;              AH to    attribute of field
  389. ;
  390. FNDFLD    PROC    NEAR
  391.     CALL    SETRCL            ;Get row/col and length
  392.     MOV    AL,DH            ;Row to    accumulator
  393.     MOV    AH,IMGLEN        ;Multiplier for    one row
  394.     MUL    AH
  395.     MOV    DI,AX            ;Move to regen pointer
  396.     MOV    AL,DL            ;Column    to accumulator
  397.     XOR    AH,AH
  398.     ADD    AX,AX            ;Double    column for word    offset
  399.     ADD    DI,AX            ;DI now    points to field    in regen
  400.     MOV    AH,CH            ;Attribute to AH
  401.     XOR    CH,CH            ;Leave length in CX
  402.     RET
  403. FNDFLD    ENDP
  404. ;
  405. ;    Set row/col/length/attribute
  406. ;
  407. SETRCL    PROC    NEAR
  408.     CBW
  409.     DEC    AX
  410.     MOV    CX,2
  411.     SHL    AX,CL
  412.     ADD    AX,CX
  413.     MOV    BX,IMGPTR        ;Get pointer to    compressed image
  414.     ADD    BX,AX            ;And set offset
  415.     MOV    DX,WORD    PTR [BX]    ;Load row/col
  416.     XCHG    DH,DL            ;DH=Row, DL=Col
  417.     TEST    IMGFLG,1        ;See if    screen to be centered
  418.     JZ    FF1
  419.     ADD    DL,20            ;It was
  420. FF1:    MOV    CX,WORD    PTR [BX+2]    ;  and attrb/length
  421.     RET
  422. SETRCL    ENDP
  423. ;
  424. ;    Position cursor    to row/col in DX
  425. ;
  426. SETCUR    PROC    NEAR
  427.     PUSH    CX
  428.     MOV    AH,1
  429.     MOV    CX,0607H
  430.     INT    10H            ;Turn cursor on    (BASIC does
  431.     MOV    AH,2            ;  funny things)
  432.     MOV    BH,0            ;Page 0
  433.     INT    10H            ;Set cursor
  434.     POP    CX
  435.     RET
  436. SETCUR    ENDP
  437. ;
  438. SETAB    PROC    NEAR
  439.     XOR    DX,DX
  440.     MOV    DI,DX
  441.     MOV    CX,DX
  442.     INC    CX
  443.     INC    CX
  444.     MOV    SI,OFFSET BASMEN    ;External screen stack
  445. STBLP:    MOV    AX,WORD    PTR [SI]    ;Get "field table" count
  446.     INC    AX
  447.     JZ    ATEND            ;At end    of screens
  448.     MOV    IMGTAB[DI],SI        ;Save pointer to start of screen
  449.     ADD    DI,CX            ;Step to next entry
  450.     INC    DX            ;  and count screen
  451.     DEC    AX
  452.     SHL    AX,CL            ;Size of field table
  453.     ADD    AX,CX            ;  plus    count word
  454.     ADD    SI,AX            ;SI now    points to image    length word
  455.     MOV    AX,WORD    PTR [SI]
  456.     AND    AH,7FH            ;Clear flag, if    any
  457.     ADD    SI,AX            ;SI points to "next" screen
  458.     JMP    STBLP
  459. ATEND:    MOV    IMGCNT,DX        ;Save count of screens
  460.     RET
  461. SETAB    ENDP
  462. ;
  463. ;    Clear requested    field
  464. ;
  465. DOCLR    PROC    NEAR
  466.     CALL    SETES            ;Set to    regen buffer
  467.     MOV    AX,BX
  468.     CALL    FNDFLD            ;Get pointer to    regen and attribute
  469.     MOV    AL,' '            ;Clear to blanks
  470.     REP    STOSW            ;Stores    blank plus attribute
  471.     CALL    SETCUR            ;Position cursor to start of field
  472.     RET
  473. DOCLR    ENDP
  474. ;
  475. CODE    ENDS
  476. ;
  477.     END
  478.