home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / CRT5.ASM < prev    next >
Assembly Source File  |  1994-11-15  |  10KB  |  381 lines

  1.     page    66,132
  2. ;********************************  CRT5.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     INCLUDE  COMMON.INC
  11. .list
  12. ;----------------------------------------------------------------------------
  13. ;----------------------------------------------------------------------------
  14.     EXTRN    $PUT_CRT_CHR:NEAR
  15.     EXTRN    $REPEAT_PUT_CRT:NEAR
  16.     EXTRN    POSN_TO_ADR:NEAR
  17.     EXTRN    ADR_TO_POSN:NEAR
  18.     EXTRN    $PUT_CRT_BLK:NEAR
  19.     EXTRN    $VERTICAL_REPEAT_CHR:NEAR
  20.     EXTRN    LIB_INFO:BYTE
  21. comment 
  22. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  23. CLEAR_WINDOW - fill area of screen
  24. ;
  25. ; inputs:    dx = window position dh=row  dl=column
  26. ;            bx = window size    bh=rows in window  bl=columns in window
  27. ;            AH = color attribute
  28. ;            AL = fill character
  29. ;            
  30. ;  output:   nothing
  31. ;
  32. ;  notes:  The dx,bx registers define a box on the screen in standard
  33. ;          library format (see DRAW_BOX).
  34. ;* * * * * * * * * * * * * *
  35. 
  36.     PUBLIC    clear_window
  37. clear_window    PROC    FAR
  38.     apush    ax,bx,cx,dx,si,es
  39.     call    box_shrink
  40.     call    posn_to_adr
  41.     sub    cx,cx
  42.     mov    cl,bl            ;cx=columns in box
  43.  
  44.     xchg    bh,bl
  45.     mov    bh,0
  46.     mov    si,bx            ;number of rows in box
  47.  
  48.     mov    bl,lib_info.crt_columns
  49.     shl    bx,1
  50.     mov    es,lib_info.crt_seg
  51. ;
  52. ; ax = char   es:di=display ptr   bx=next row bump  cx=repeat count  si=row cnt
  53. ;
  54.     call    $vertical_repeat_chr
  55.     apop    es,si,dx,cx,bx,ax
  56.     retf
  57. clear_window    ENDP
  58. comment 
  59. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  60. DRAW_BOX -  draw a box on screen
  61. ;
  62. ; inputs:    dx = box address    dh=row    dl=column
  63. ;         bx = box size   dh=rows in box  dl=columns in box
  64. ;            AH = color attribute
  65. ;         AL = box frame type  0=single line
  66. ;                          1=double line
  67. ; output: none
  68. ;
  69. ; notes:  The center of the box is cleared as it is drawn.
  70. ;         Box parameters are not checked for illegal sizes so beware.
  71. ;* * * * * * * * * * * * * *
  72. 
  73. ;-----------------------
  74. box_table0    db    '┌─┐│ │└─┘'
  75. box_table1    db    '╔═╗║ ║╚═╝'
  76. ;-----------------------
  77.     PUBLIC    DRAW_BOX
  78. DRAW_BOX    PROC    FAR
  79.     apush    ax,bx,cx,dx,si,di,ds,es
  80.     push    cs
  81.     pop    ds
  82.     mov    es,cs:lib_info.crt_seg
  83.     mov    si,offset box_table0
  84.     cmp    al,0
  85.     je    db_01            ;jmp if single line box
  86.     mov    si,offset box_table1
  87. db_01:    call    $box_line
  88.     add    si,3            ;move to next char
  89. db_02:    add    dh,1            ;move to next line
  90.     call    $box_line
  91.     dec    bh
  92.     cmp    bh,1
  93.     jne    db_02            ;loop till box center done
  94.  
  95.     add    si,3
  96.     call    $box_line        ;display last line of box
  97.     apop    es,ds,di,si,dx,cx,bx,ax
  98.     retf
  99.         
  100. DRAW_BOX    ENDP
  101. ;---------------------
  102. ; display one line of box using 3 frame characters stored at ds:si
  103. ;
  104. ; inputs:  ds:si = pointer to 3 box frame characters
  105. ;             ah = color
  106. ;             dx = crt address
  107. ;             bl = columns in box center
  108. ;             es = display seg
  109. ;
  110. $box_line:
  111.     push    si
  112.     call    posn_to_adr
  113.     lodsb                ;get box char for left column
  114.     call    $put_crt_chr        ;display left column char
  115.     lodsb
  116.     sub    cx,cx
  117.     mov    cl,bl            ;get column count
  118.     sub    cl,2
  119.     call    $repeat_put_crt
  120.     lodsb
  121.     call    $put_crt_chr
  122.     pop    si
  123.     ret
  124. comment 
  125. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  126. WINDOW_STRING -  display string in window.
  127. ;
  128. ; inputs: DS:[SI] = pointer to the string
  129. ;           dx = starting row(dh)  starting column(dl)
  130. ;           bx = box total rows(bh)  box total columns(bl)
  131. ;              AH = color attribute
  132. ;              
  133. ; outputs:   none
  134. ;
  135. ; notes:  String must be terminated with null character.
  136. ;         Strings will wrap if cr/lf is found or edge of box is encountered.
  137. ;         Any area to right of string is cleared up to edge of box.
  138. ;         String which wrap will try not to split words.
  139. ;* * * * * * * * * * * * * *
  140. 
  141. ;---------------------------
  142. ws_str_ptr    dw    0
  143. ws_wscan_cx    dw    0            ;scan for word break cx save
  144. ws_lp_cnt    db    0
  145. ;---------------------------
  146.     PUBLIC    WINDOW_STRING
  147. WINDOW_STRING    PROC    FAR
  148.     apush    ax,bx,cx,dx,si,di,bp,ds,es
  149.     mov    es,cs:lib_info.crt_seg
  150.     mov    cs:ws_lp_cnt,bh
  151. ;
  152. ; skip over any cr/lf characters at start of this line
  153. ;
  154. ws_10:    mov    cx,0                ;set line length to zero
  155. ws_10a: cmp    byte ptr [si],0
  156.     jne    ws_11                ;jmp if not at end of string
  157.     call    posn_to_adr
  158.     jmp    ws_40                ;go fill line with blanks
  159. ws_11:    cmp    byte ptr [si],0dh
  160.     je    ws_12                ;jmp if carriage-return found
  161.     cmp    byte ptr [si],0ah
  162.     jne    ws_13                ;jmp if no cr/lf chars found
  163. ws_12:    inc    si
  164.     jmp    ws_10a
  165. ;
  166. ; the first character of string has been found, not cr/lf/zero, find line len
  167. ;
  168. ws_13:    mov    cs:ws_str_ptr,si        ;save si
  169.  
  170. ws_20:    cmp    byte ptr [si],0
  171.     je    ws_30                ;jmp if end of line
  172.     cmp    byte ptr [si],0dh
  173.     je    ws_30                ;jmp if end of line
  174.     cmp    byte ptr [si],0ah
  175.     je    ws_30                ;jmp if end of line
  176.     inc    cx                ;count this char
  177.     inc    si
  178.     cmp    cl,bl                ;check if at box right edge
  179.     jne    ws_20                ;jmp if still within box
  180. ;
  181. ; we have filled to the right edge of the box, now scan back for word break
  182. ;
  183.     mov    cs:ws_wscan_cx,cx         ;save ending char. count
  184. ws_22:    dec    si
  185.         cmp     byte ptr [si],' '
  186.     je    ws_30                ;jmp if char break found
  187.     loop    ws_22
  188. ;
  189. ; no word breaks were found, so display line as is
  190. ;
  191.     mov    cx,cs:ws_wscan_cx
  192. ;
  193. ; si =ptr to line end,    cx = length of line
  194. ;
  195. ws_30:    mov    si,cs:ws_str_ptr         ;restore line start ptr
  196.     mov    cs:ws_wscan_cx,cx
  197.     call    posn_to_adr            ;compute starting display offset
  198.     call    $put_crt_blk
  199. ;
  200. ; now check if we need to fill to end of box with blanks
  201. ;
  202.     mov    cx,cs:ws_wscan_cx        ;restore -cx-
  203. ws_40:    sub    cl,bl                ;display count - box size
  204.     neg    cl
  205.     jz    ws_50                ;jmp if no fill needed
  206. ;
  207. ; clear remainder of this line on display
  208. ;
  209.     push    si
  210.     mov    si,1
  211.         mov     al,' '
  212.     call    $vertical_repeat_chr
  213.     pop    si
  214. ;
  215. ; check if last line of box has been filled
  216. ;
  217. ws_50:    inc    dh                ;move to next row on display
  218.     dec    cs:ws_lp_cnt            ;decrement row count
  219.     jnz    ws_10                ;loop till done
  220.  
  221. WS_EXIT:
  222.     apop    es,ds,bp,di,si,dx,cx,bx,ax
  223.     RETF
  224. WINDOW_STRING    ENDP
  225. comment 
  226. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  227. BOX_RIGHT - move box parameters right
  228. ;
  229. ; inputs:  dx = box display address,  dh=row  dl=column
  230. ;          bx = box size,  bh=rows in box  bl=columns in box
  231. ;          
  232. ; output:  dx = box row (dh) and box column (dl) moved one position
  233. ;          bx = box size, number of rows (bh), number of columns (bl)
  234. ;* * * * * * * * * * * * * *
  235. 
  236.     public    box_right
  237. box_right    proc    far
  238.     inc    dl
  239.     cmp    dl,lib_info.crt_columns
  240.     je    box_left            ;jmp if too far to right
  241.     retf
  242. box_right    endp
  243. comment 
  244. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  245. BOX_LEFT -  move box parameters left
  246. ;
  247. ; inputs:  dx = box display address,  dh=row  dl=column
  248. ;          bx = box size,  bh=rows in box  bl=columns in box
  249. ;          
  250. ; output:  dx = box row (dh) and box column (dl) moved one position
  251. ;          bx = box size, number of rows (bh), number of columns (bl)
  252. ;* * * * * * * * * * * * * *
  253. 
  254.     public    box_left
  255. box_left    proc    far
  256.     dec    dl
  257.     cmp    dl,-1
  258.     je    box_right            ;jmp if too far to left
  259.     retf
  260. box_left    endp
  261. comment  
  262. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  263. BOX_UP - move box parameters up one position
  264. ;
  265. ; inputs:  dx = box display address,  dh=row  dl=column
  266. ;          bx = box size,  bh=rows in box  bl=columns in box
  267. ;          
  268. ; output:  dx = box row (dh) and box column (dl) moved one position
  269. ;          bx = box size, number of rows (bh), number of columns (bl)
  270. ;* * * * * * * * * * * * * *
  271. 
  272.     public    box_up
  273. box_up        proc    far
  274.     dec    dh
  275.     cmp    dh,-1
  276.     je    box_down            ;jmp if too high
  277.     retf
  278. box_up        endp
  279. comment 
  280. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  281. BOX_DOWN - move box parameters down one position
  282. ;
  283. ; inputs:  dx = box display address,  dh=row  dl=column
  284. ;          bx = box size,  bh=rows in box  bl=columns in box
  285. ;          
  286. ; output:  dx = box row (dh) and box column (dl) moved one position
  287. ;          bx = box size, number of rows (bh), number of columns (bl)
  288. ;* * * * * * * * * * * * * *
  289. 
  290.     public    box_down
  291. box_down    proc    far
  292.     inc    dh
  293.     cmp    dh,lib_info.crt_rows
  294.     je    box_up                ;jmp if too low
  295.     retf
  296. box_down    endp
  297. comment 
  298. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  299. BOX_EXPAND - expand box one position in all directions
  300. ;
  301. ; inputs:  dx = box display address,  dh=row  dl=column
  302. ;          bx = box size,  bh=rows in box  bl=columns in box
  303. ;          
  304. ; output:  if no carry
  305. ;          dx = box row (dh) and box column (dl) moved one position
  306. ;          bx = box size, number of rows (bh), number of columns (bl)
  307. ;          if carry, then error occured and data invalid
  308. ;* * * * * * * * * * * * * *
  309. 
  310.     public    box_expand
  311. box_expand    proc    far
  312.     dec    dh                ;upper left corner up 1
  313.     cmp    dh,-1
  314.     je    be_code_err
  315.  
  316.     dec    dl                ;upper left corner left 1
  317.     cmp    dl,-1
  318.     je    be_code_err
  319.  
  320.     add    bh,2                ;rows in box +2
  321.     add    bh,dh
  322.     cmp    bh,lib_info.crt_rows
  323.     jae    be_code_err
  324.     sub    bh,dh                ;restore correct row count
  325.  
  326.     add    bl,2                ;columns in box +2
  327.     add    bl,dl
  328.     cmp    bl,lib_info.crt_columns
  329.     jae    be_code_err
  330.     sub    bl,dl
  331.     clc
  332.     jmp    be_exit
  333.  
  334. be_code_err:
  335.     stc
  336. be_exit:
  337.     retf
  338. box_expand    endp
  339. comment 
  340. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  341. BOX_SHRINK - shrink box parameters one position in all directions
  342. ;
  343. ; inputs:  dx = box display address,  dh=row  dl=column
  344. ;          bx = box size,  bh=rows in box  bl=columns in box
  345. ;          
  346. ; output:  if no carry
  347. ;          dx = box row (dh) and box column (dl) moved one position
  348. ;          bx = box size, number of rows (bh), number of columns (bl)
  349. ;          if carry, error occured, data invalid
  350. ;* * * * * * * * * * * * * *
  351. 
  352.     public    box_shrink
  353. box_shrink    proc    far
  354.     inc    dh
  355.     cmp    dh,lib_info.crt_rows
  356.     jae    bs_code_err
  357.  
  358.     inc    dl
  359.     cmp    dl,lib_info.crt_columns
  360.     jae    bs_code_err
  361.  
  362.     cmp    bh,2
  363.     jbe    bs_code_err
  364.     sub    bh,2                ;rows in box
  365.  
  366.     sub    bl,2                ;columns in box
  367.     cmp    bl,2
  368.     ja    bs_exit
  369. bs_code_err:
  370.     stc
  371.     jmp    bs_exit1
  372. bs_exit:
  373.     clc
  374. bs_exit1:
  375.     retf
  376. box_shrink    endp
  377.  
  378.  
  379. LIBSEG    ENDS
  380.     end
  381.