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

  1.     page    66,132
  2. ;******************************** CRT7.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.     EXTRN    POSN_TO_ADR:NEAR
  14.     EXTRN    MEM_ALLOCATE:FAR
  15.     EXTRN    MEM_PUT:FAR
  16.     EXTRN    MEM_GET:FAR
  17.     EXTRN    MEM_RELEASE:FAR
  18.     EXTRN    LIB_INFO:BYTE
  19. comment 
  20. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  21. save_window - save area of display in memory buffer
  22. ;
  23. ; inputs: dx=box left corner (dh=row,dl=column)
  24. ;         bh=rows in window
  25. ;      bl=columns in window
  26. ;      
  27. ; output: carry set if error
  28. ; processing: save up to three window areas which can be restored
  29. ;           with restore_window.  The memory manager is called
  30. ;           to allocate room to store windows saved.
  31. ;* * * * * * * * * * * * * *
  32. 
  33. sav_struc    struc
  34.  sw_handle        dw    ?    ;seg of allocated memory
  35.  sw_di_sav    dw    ?    ;display starting offset
  36.  sw_bx_sav    dw    ?    ;bh=rows bl=columns
  37. sav_struc    ends
  38.  
  39. sw_saved_cnt    dw    0    ;number of windows saved
  40.  
  41. sw_sav1        sav_struc<>
  42.         sav_struc<>
  43.         sav_struc<>
  44.         sav_struc<>
  45. ;--------------------------
  46.     public    save_window
  47. save_window    proc    far
  48.     apush    ax,bx,cx,dx,si,di,ds,es
  49.     call    posn_to_adr            ;compute display location
  50.     push    bx                ;save box rows/columns
  51.     mov    ax,bx
  52.     mul    ah                ;ax= # bytes in box
  53.     shl    ax,1                ;add in size of attributes
  54.     sub    dx,dx                ;setup for mem allocation
  55.     mov    bx,0                ;normal allocation
  56.     call    mem_allocate
  57.     mov    ax,bx                ;move handle to -ax-
  58.     jc    sw_exit                ;jmp if error
  59. ;
  60. ; compute location to store allocated seg
  61. ;
  62. sw_cont:
  63.     pop    bx                ;restore box rows & column cnt
  64.     mov    cx,cs:sw_saved_cnt
  65.     mov    si,offset sw_sav1
  66. sw_lookup:
  67.     jcxz    sw_skip                ;jmp if first entry
  68.     add    si,size sav_struc
  69.     loop    sw_lookup
  70. sw_skip:mov    word ptr cs:[si.sw_handle],ax    ;save segment allocated
  71.     mov    word ptr cs:[si.sw_bx_sav],bx    ;save box rows(bh) columns(bl)
  72.     mov    word ptr cs:[si.sw_di_sav],di    ;save display offset
  73.  
  74.     inc    cs:sw_saved_cnt
  75. ;
  76. ; es:di = display address   ax=allocated mem seg  bh=rows  bl=columns
  77. ;
  78.     sub    ax,ax
  79.     mov    al,cs:lib_info.crt_columns
  80.     shl    ax,1
  81.     
  82.     mov    dx,bx            ;dh=rows to save  dl=columns per row
  83.     mov    bp,es            ;bp=from seg (display)
  84.     mov    bx,cs:[si.sw_handle]    ;get to handle
  85.     mov    si,di            ;si=from offset (display)
  86.     mov    di,0            ;di=to index (offset)
  87. ;
  88. ; bp:si=from(display) di=to(index) cx=words  bx=handle
  89. ;
  90. sw_sav_lp:
  91.     sub    cx,cx
  92.     mov    cl,dl
  93.     call    mem_put
  94.     add    si,ax            ;move to next crt line
  95.     mov    cl,dl
  96.     shl    cx,1
  97.     add    di,cx            ;update -to- ptr
  98.     dec    dh
  99.     jnz    sw_sav_lp
  100.     clc
  101. sw_exit:apop    es,ds,di,si,dx,cx,bx,ax
  102.     retf
  103. save_window    endp
  104. comment 
  105. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -( DISPLAY )
  106. restore_window - restore a previously saved area of display
  107. ;
  108. ; inputs: none
  109. ; output: carry set if error
  110. ;         all registers are saved
  111. ; processing: restore uses information in save_window to restore the last
  112. ;           window saved.  Up to three windows can be saved and then
  113. ;           restored in reverse order.
  114. ;* * * * * * * * * * * * * *
  115. 
  116.     public    restore_window
  117. restore_window    proc    far
  118.     apush    ax,bx,cx,dx,si,di,ds,es
  119. ;
  120. ; compute location to restore from data saved by save_window
  121. ;
  122.     mov    cx,cs:sw_saved_cnt
  123.     jcxz    rw_abort            ;jmp if no windows saved
  124.     mov    si,offset sw_sav1
  125. rw_lookup:
  126.     add    si,size sav_struc
  127.     loop    rw_lookup
  128.     sub    si,size sav_struc
  129.     mov    dx,word ptr cs:[si.sw_bx_sav]    ;get box rows(bh) columns(bl)
  130.     mov    di,word ptr cs:[si.sw_di_sav]    ;get display offset
  131.     mov    bp,cs:lib_info.crt_seg
  132.     mov    bx,word ptr cs:[si.sw_handle]    ;get segment allocated
  133.     mov    si,0
  134.  
  135. ;
  136. ; bp:di = display address   si=index bx=handle   dh=rows  dl=columns
  137. ;
  138.     sub    ax,ax
  139.     mov    al,cs:lib_info.crt_columns
  140.     shl    ax,1                ;compute bytes on one crt row
  141. rw_sav_lp:
  142.     sub    cx,cx
  143.     mov    cl,dl
  144.     call    mem_get                ;restore window
  145.     add    di,ax                ;move to next crt line
  146.     mov    cl,dl
  147.     shl    cx,1
  148.     add    si,cx                ;move to next buffer index
  149.     dec    dh
  150.     jnz    rw_sav_lp
  151.  
  152.     call    mem_release
  153.  
  154. rw_cont:dec    cs:sw_saved_cnt
  155.     clc
  156.     jmp    rw_exit
  157. rw_abort:
  158.     stc
  159. rw_exit:        
  160.     apop    es,ds,di,si,dx,cx,bx,ax
  161.     retf
  162. restore_window    endp
  163. ;
  164.  
  165. LIBSEG    ENDS
  166.     end
  167.