Metropoli BBS
VIEWER: ed_2.asm MODE: TEXT (CP437)
;+--------------+
;| Edit Part II |
;+--------------+
public    display_,ins_line,del_line,put_buff,get_buff,find_ptr
public    load_act,newing,save_act,print_act,help_win,write_act,chg_drive
public    p_ptr,q_ptr,r_ptr,free_top,free_ptr,line_buf,block_top,block_end
extrn     info_win:near
extrn     refresh_:near
extrn     here_dir:near
extrn     new_act:near
extrn     read_line:near
extrn     show_name:near
extrn     new_end:word
extrn     top_:byte
extrn     bottom_:byte
extrn     total_l:word
extrn     monitor:word
extrn     y_table:word
extrn     cursor_y:word
extrn     file_top:word
extrn     file_ptr:word
extrn     file_name:byte
extrn     handle_:word
extrn     psp_start:word
extrn     this_dir:byte

buf_max   equ      2048

NEW_      MACRO                         ;AX register save the Segment
          LOCAL    over_z,exist_
          push     es
          push     bx
          cmp      free_top,0
          jne      exist_

          add      new_end,2
          mov      ax,new_end
          jmp      over_z

  exist_: mov      ax,free_top
          mov      es,ax
          mov      bx,es:[0]
          mov      free_top,bx
  over_z: pop      bx
          pop      es
          ENDM

FREE_     MACRO    _ptr
          LOCAL    n_empt,free_z
          push     es
          pushf
          mov      ax,_ptr
          cmp      free_top,0
          jne      n_empt
          mov      free_top,ax
          jmp      free_z

  n_empt: mov      es,free_ptr
          mov      es:[0],ax
  free_z: mov      free_ptr,ax
          mov      es,ax
          mov      word ptr es:[0],0
          popf
          pop      es
          ENDM

CURSOR_1  MACRO
          push     cx
          mov      ch,0bh
          mov      cl,0ch
          mov      ah,1
          int      10h
          pop      cx
          ENDM

CURSOR_0  MACRO
          push     cx
          mov      ch,1ch
          mov      cl,1bh
          mov      ah,1
          int      10h
          pop      cx
          ENDM

data      segment  public
p_ptr     dw ?                          ;Here Pointer
q_ptr     dw ?
r_ptr     dw ?                          ;Front Pointer
p_lin     dw ?                          ;Line Here
q_lin     dw ?                          ;
free_top  dw ?
free_ptr  dw ?
local_y   dw ?
block_top dw ?
block_end dw ?
attr_line db ?
eol_flag  db ?
dir_      db '*.*',0
total_f   dw ?
total_d   dw ?
file_y    dw ?
line_buf  db 258 dup(0)
msg_      db '██████▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒░░░░░░░░░░░░ ERR'
          db 'OR! ░░░░░░░░░░░░▒▒▒▒▒▒▒▒▒▒▓▓▓▓▓▓▓▓██████'
load_fun  db 30
          db '┌─Load File──────────────────╖'
          db '│                            ║'
          db '├────────────────────────────╢'
          db '│   │                    │   ║'
          db '╘════════════════════════════╝'
write_fun db 33
          db '┌────────── Write to ───────────╖'
          db '│                               ║'
          db '╘═══════════════════════════════╝'
wrt_file  db 30 dup(0)
drive_fun db 37
          db '┌───────────────────────────────────╖'
          db '│ Change Disk-Drive From [ ] to [ ] ║'
          db '╘═══════════════════════════════════╝'
win_help  db 59,15
          db '┌────────────────────────── Help ─────────────────────────╖'
          db '├────────────────────────────────┬────────────────────────╢'
          db '│        ■ Define Key ■          │    ■ Introduction ■    ║'
          db '├────────────────────────────────┼────────────────────────╢'
          db '│ Shift-Ctrl-N = Insert 1 line   │ Author: Chen Jean-Yean ║'
          db '│ Shift-Ctrl-Y = Delete 1 line   │ Number: 790854         ║'
          db '│ ────────────────────────────── │ Dept. : MIS            ║'
          db '│ Shift-Ctrl-B = Set Block Begin │ Class : 2A             ║'
          db '│ Shift-Ctrl-K = Set Block End   │                        ║'
          db '│ Shift-Ctrl-M = Move Block      │ ██▄  ██ ▄█▀▀▀▀ ██  ▐█▌ ║'
          db '│ Shift-Ctrl-D = Delete Block    │ ██ ▀▄██ ██     ██  ▐█▌ ║'
          db '│ Shift-Ctrl-O = Copy Block      │ ▀▀   ▀▀  ▀▀▀▀▀  ▀▀▀▀▀  ║'
          db '│ Shift-Ctrl-P = Print Block     │ National Central Univ. ║'
          db '│ Shift-Ctrl-H = Hide Block      │                        ║'
          db '╘════════════════════════════════╧════════════════════════╝'
buffer_   db 2048 dup(0)
data      ends

code      segment  public
          assume   cs:code,ds:data

display_  proc     near                 ;Stack Put Start_line
          push     bp                   ;Stack Put Start_Col
          mov      bp,sp
          push     ax
          push     bx
          push     cx
          push     dx

          mov      local_y,0
          mov      bx,[bp+6]
          mov      dx,[bp+4]
          push     bx
          call     find_ptr              ;Result put in p_ptr
          mov      cx,total_l
          sub      cx,bx
          add      cx,2
          cmp      cx,21
          jb       less

          mov      cx,21                ;Screen Full
  mor_21: inc      local_y
          call     disp_line
          inc      bx
          push     bx
          call     find_ptr
          loop     mor_21
          jmp      dis_f

  less:   push     cx
  low_21: inc      local_y
          call     disp_line
          inc      bx
          push     bx
          call     find_ptr
          loop     low_21

          pop      cx
          mov      ch,cl
          mov      al,0                 ;Clear Screen
          add      ch,2
          mov      cl,0
          mov      dh,22
          mov      dl,79
          mov      bh,07
          mov      ah,6
          int      10h
  dis_f:
          pop      ax
          pop      dx
          pop      cx
          pop      bx
          pop      bp
          ret      4
display_  endp

find_ptr  proc     near                 ;Stack Put Which No. be Finded
          push     bp
          mov      bp,sp
          push     ax
          push     cx
          push     es
          pushf
          mov      p_ptr,seg top_
          mov      ax,p_ptr
          mov      r_ptr,ax
          mov      cx,[bp+4]
          cmp      cx,0
          je       fnd_ok
  find_n: mov      es,p_ptr
          mov      r_ptr,es             ;r_ptr:=p_ptr
          mov      ax,es:[0]            ;p_ptr:=p_ptr^.next
          mov      p_ptr,ax
          loop     find_n

  fnd_ok: popf
          pop      es
          pop      cx
          pop      ax
          pop      bp
          ret      2
find_ptr  endp

disp_line proc     near                 ;DX register Put Start_Col
          push     ax
          push     bx
          push     cx
          push     di
          push     si
          push     es
          pushf

          mov      attr_line,07h
          cmp      bx,block_top
          jb       no_rev
          cmp      bx,block_end
          jae      no_rev
          mov      attr_line,70h

  no_rev: mov      ah,attr_line
          mov      bx,local_y
          inc      bx
          shl      bx,1
          call     put_buff
          mov      es,monitor
          xor      cx,cx
          mov      cl,line_buf
          cmp      cx,dx
          jb       over_d
          sub      cx,dx
          inc      cx
          push     cx
          cmp      cx,80
          jbe      legal
          mov      cx,80
  legal:  mov      di,dx
          mov      si,y_table[bx]
  rep_c:  mov      al,line_buf[di]
          mov      es:[si],al
          mov      es:[si+1],ah
          add      si,2
          inc      di
          loop     rep_c
          pop      cx
          cmp      cx,80
          jae      l_e
          neg      cx
          add      cx,80
  _80:    mov      byte ptr es:[si],' '
          mov      es:[si+1],ah
          add      si,2
          loop     _80
          jmp      l_e

  over_d: mov      cx,80
          mov      di,y_table[bx]
  n80:    mov      byte ptr es:[di],' '
          mov      es:[di+1],ah
          add      di,2
          loop     n80

  l_e:    popf
          pop      es
          pop      si
          pop      di
          pop      cx
          pop      bx
          pop      ax
          ret
disp_line endp

put_buff  proc     near
          push     ax
          push     cx
          push     es
          push     di
          push     si
          mov      es,word ptr p_ptr
          mov      cx,28
          mov      di,2
          mov      si,0

  b_1:    mov      al,es:[di]           ;Part 1
          mov      line_buf[si],al
          inc      si
          inc      di
          loop     b_1
          cmp      word ptr es:[30],0
          je       out_

  mor_b:  mov      ax,es:[30]
          mov      es,ax
          mov      cx,30
          mov      di,0
  b_n:    mov      al,es:[di]
          mov      byte ptr line_buf[si],al
          inc      si
          inc      di
          loop     b_n
          cmp      word ptr es:[30],0
          jne      mor_b

  out_:   pop      si
          pop      di
          pop      es
          pop      cx
          pop      ax
          ret
put_buff  endp

get_buff  proc     near
          push     es
          push     di
          push     si
          push     ax
          push     bx
          push     cx
          pushf

          mov      es,p_ptr
          mov      p_lin,es
          mov      q_lin,es
          xor      ax,ax
          mov      al,es:[2]            ;No. Chars in Linked List
          add      ax,2
          mov      cl,30
          div      cl
          xor      ah,ah
          push     ax
          mov      cx,ax
          cmp      cx,0
          je       buf_s
  nxt_bl: mov      es,p_lin             ;P_lin = Last Cluster of This Line
          mov      ax,es:[30]
          mov      p_lin,ax
          loop     nxt_bl

  buf_s:  xor      ax,ax
          mov      al,line_buf          ;No. Chars in Line Buffer
          add      ax,2
          mov      cl,30
          div      cl

          pop      cx                   ;Compare Linked-List and Line_buf
          xor      ah,ah
          push     ax
          cmp      al,cl
          jae      can_n
          sub      cl,al
          FREE_    p_lin
          mov      word ptr es:[30],0
          jmp      fill_d

  can_n:  sub      al,cl
          cmp      al,0
          je       fill_d

          xor      cx,cx
          mov      cl,al
  new_1:  NEW_
          mov      es,p_lin
          mov      es:[30],ax
          mov      p_lin,ax
          mov      es,ax
          mov      word ptr es:[30],0
          loop     new_1

  fill_d: cld
          mov      ax,p_ptr
          mov      p_lin,ax
          mov      es,ax
          mov      di,2
          mov      si,offset line_buf
          mov      cx,28                ;Part 1
  rep     movsb
          pop      cx
          cmp      cx,0
          je       g_end
  r_fill: push     cx
          pushf
          cld
          mov      di,0
          mov      ax,es:[30]
          mov      p_lin,ax             ;P_line:=P_line^.next
          mov      es,ax
          mov      cx,30
  rep     movsb
          popf
          pop      cx
          loop     r_fill

  g_end:  popf
          pop      cx
          pop      bx
          pop      ax
          pop      si
          pop      di
          pop      es
          ret
get_buff  endp

ins_line  proc     near
          push     ax
          push     es
          mov      ax,cursor_y
          cmp      ax,block_top
          jb       bk_1i
          cmp      ax,block_end
          jb       bk_2i
          jmp      bk_zi
  bk_1i:  inc      block_top
  bk_2i:  inc      block_end
  bk_zi:  push     ax
          call     find_ptr
          NEW_
          mov      es,r_ptr             ;R_ptr^.next:=NEW_ptr
          mov      es:[0],ax
          mov      es,ax
          mov      ax,p_ptr             ;NEW_ptr^.next:=P_ptr
          mov      es:[0],ax
          mov      byte ptr es:[2],0
          mov      word ptr es:[30],0
          inc      total_l
          call     info_win
          call     refresh_
          pop      es
          pop      ax
          ret
ins_line  endp

del_line  proc     near
          push     ax
          push     cx
          push     es
          mov      ax,cursor_y
          push     ax
          call     find_ptr
          cmp      total_l,ax
          je       no_del

          mov      es,p_ptr
          push     es
          mov      ax,es:[0]
          mov      es,r_ptr
          mov      es:[0],ax
          pop      es
          xor      cx,cx
          mov      cl,es:[2]
          FREE_    p_ptr
          cmp      cx,0
          je       del_z

  dis_m:  mov      ax,es:[30]
          mov      es,ax
          FREE_    ax
          loop     dis_m

  del_z:  dec      total_l
          call     info_win
          call     refresh_

  no_del: pop      es
          pop      cx
          pop      ax
          ret
del_line  endp

load_act  proc     near
          push     es
          push     di
          push     si
          push     bx
          push     dx
          CURSOR_0

  dir_fu: mov      es,monitor
          mov      di,y_table[4]
          add      di,96
          mov      si,offset load_fun+1
          mov      al,1eh
          mov      cx,3
          xor      bx,bx
          mov      bl,load_fun[0]
  dw_ld1: push     cx
          pushf
          mov      cx,bx
  f_ld1:  movsb
          stosb
          loop     f_ld1
          add      di,160
          sub      di,bx
          sub      di,bx
          popf
          pop      cx
          loop     dw_ld1
          mov      cx,16
  dw_ld2: push     cx
          pushf
          mov      cx,bx
  f_ld2:  movsb
          stosb
          loop     f_ld2
          add      di,160
          sub      di,bx
          sub      di,bx
          sub      si,bx
          popf
          pop      cx
          loop     dw_ld2

          add      si,bx
          mov      cx,bx
  z_ld:   movsb
          stosb
          loop     z_ld

          mov      byte ptr es:[580],'*'       ;*
          mov      byte ptr es:[582],'.'       ;.
          mov      byte ptr es:[584],'*'       ;*
                                        ;UPPER Draw Load Table
          mov      total_f,0
          mov      total_d,0
          mov      file_y,1
          mov      local_y,1
          mov      file_top,0
          mov      file_ptr,0

          mov      dx,offset dir_
          mov      cx,07h               ;All Kind Of File
          mov      ah,4eh
          int      21h
          jnc      ff_1st
          jmp      d_dir
  ff_1st: NEW_
          inc      total_f
          mov      file_top,ax
          mov      file_ptr,ax
          mov      es,ax
          mov      di,2
          mov      si,9eh               ;DTA (DS:009E) Put Filename Table
          mov      cx,13
          push     ds
          mov      ds,psp_start
          cld
  rep     movsb
          pop      ds

  r_r_f:  mov      ah,4fh
          int      21h
          jc       f_f1
          NEW_
          inc      total_f
          mov      es:[0],ax
          mov      es,ax
          mov      file_ptr,ax
          mov      di,2
          mov      si,9eh               ;DTA (DS:009E) Put Filename Table
          mov      cx,13
          push     ds
          mov      ds,psp_start
          cld
  rep     movsb
          pop      ds
          jmp      r_r_f
  f_f1:   mov      word ptr es:[0],0

  d_dir:  mov      dx,offset dir_       ;<<<<<<<< This Area Find SubDir
          mov      cx,1fh               ;Directory
          mov      ah,4eh
          int      21h
          jnc      dd_1st
          jmp      ff_dd0
  dd_1st: push     es
          mov      es,psp_start
          mov      al,es:[95h]
          pop      es
          and      al,10h
          cmp      al,10h
          jne      r_r_d
          NEW_
          inc      total_d
          mov      bx,es
          cmp      bx,file_ptr
          je       ff_ex
          mov      file_top,ax
          jmp      dd_ex
  ff_ex:  mov      es:[0],ax
  dd_ex:  mov      es,ax
          mov      byte ptr es:[2],16
          mov      di,3
          mov      si,9eh               ;DTA (DS:009E) Put Directory Table
          mov      cx,13
          push     ds
          mov      ds,psp_start
          cld
  rep     movsb
          pop      ds

  r_r_d:  mov      ah,4fh
          int      21h
          jc       d_d1
          push     es
          mov      es,psp_start
          mov      al,es:[95h]
          pop      es
          and      al,10h
          cmp      al,10h
          jne      r_r_d
          NEW_
          inc      total_d
          mov      es:[0],ax
          mov      es,ax
          mov      byte ptr es:[2],16
          mov      di,3
          mov      si,9eh               ;DTA (DS:009E) Put Directory Table
          mov      cx,13
          push     ds
          mov      ds,psp_start
          cld
  rep     movsb
          pop      ds
          jmp      r_r_d
  d_d1:   mov      word ptr es:[0],0    ; This Area Find SubDir >>>>>>>>

  ff_dd0: mov      dx,total_f           ;DX register put TOTAL file/dir
          add      dx,total_d
          cmp      dx,0
          je       ff_dd

          mov      cx,dx
          mov      es,file_top
  _nn_:   push     cx
          mov      cx,20
          mov      eol_flag,0  ;Borrow Eol_flag....
          mov      di,2
  _ll_:   cmp      eol_flag,1
          jne      fnd_00
          mov      byte ptr es:[di],0
  fnd_00: cmp      byte ptr es:[di],0
          jne      r_scan
          mov      eol_flag,1
  r_scan: inc      di
          loop     _ll_
          pop      cx
          mov      es,es:[0]
          loop     _nn_

  ff_dd:  cmp      dx,0
          je       rr_kk
          call     show_dir
  rr_kk:  mov      ah,0
          int      16h
          cmp      ah,72    ;<UP>
          jne      kk_1
          cmp      dx,0
          je       rr_kk
          cmp      file_y,1
          je       rr_kk
          dec      file_y
          cmp      local_y,1
          je       ff_dd
          dec      local_y
          jmp      ff_dd

  kk_1:   cmp      ah,80    ;<Down>
          jne      kk_2
          cmp      dx,0
          je       rr_kk
          cmp      file_y,dx
          je       rr_kk
          inc      file_y
          cmp      local_y,16
          je       ff_dd
          inc      local_y
          jmp      ff_dd

  kk_2:   cmp      ah,28    ;<Enter>
          jne      kk_3
          cmp      dx,0
          jne      ex_01f
          jmp      ex_0f
  ex_01f: mov      ax,total_f
          cmp      file_y,ax
          jbe      open_f
          push     ds
          mov      ds,file_ptr
          mov      dx,3
          mov      ah,3bh
          int      21h
          pop      ds
          call     free_dir
          jmp      dir_fu

  open_f: call     loading
          jmp      ex_ld

  kk_3:   cmp      ah,1     ;<ESC>
          jne      kk_4
          cmp      dx,0
          je       ex_00f
          jmp      ex_ld
  ex_00f: jmp      ex_0f

  kk_4:   cmp      ah,73    ;<Page Up>
          jne      kk_5
          mov      ax,file_y    ;File No.
          mov      cx,local_y
          sub      ax,cx
          cmp      ax,15
          ja       sub_15
          cmp      file_y,15
          ja       su__15
          mov      local_y,1
          mov      file_y,1
          jmp      p_up

  su__15: add      cx,ax
          sub      cx,15
          mov      local_y,cx
  sub_15: sub      file_y,15
  p_up:   jmp      ff_dd

  kk_5:   cmp      ah,81    ;<Page Down>
          jne      kk_6
          cmp      dx,16
          ja       m_16_f
          mov      local_y,dx
          mov      file_y,dx
          jmp      ff_dd
  m_16_f: mov      bx,dx    ;BX = Total Files
          mov      cx,local_y
          neg      cx
          add      cx,17       ;Backward
          mov      ax,file_y   ;AX = File No.
          sub      bx,ax
          inc      bx          ;BX = Backward File No.
          mov      ax,bx
          sub      ax,cx
          cmp      ax,15
          ja       add_15
          cmp      bx,15
          ja       ad__15
          mov      local_y,16
          mov      file_y,dx
          jmp      p_dn

  ad__15: add      cx,ax
          neg      cx
          add      cx,32
          mov      local_y,cx
  add_15: add      file_y,15
  p_dn:   jmp      ff_dd

  kk_6:   jmp      rr_kk

  ex_ld:  call     free_dir

  ex_0f:  CURSOR_1
          pop      dx
          pop      bx
          pop      si
          pop      di
          pop      es
          ret
load_act  endp

show_dir  proc     near
          mov      cx,file_y
          sub      cx,local_y
          mov      es,file_top
          cmp      cx,0
          je       _ptr_f
  f_ptr_: mov      es,es:[0]
          loop     f_ptr_

  _ptr_f: mov      p_lin,es
          mov      cx,local_y
          dec      cx
          cmp      cx,0
          je       this_
  now__:  mov      es,es:[0]
          loop     now__

  this_:  mov      file_ptr,es

          mov      cx,dx                ;DX register record TOTAL file/dir
          cmp      cx,16
          jbe      t_file
          mov      cx,16
  t_file:
          mov      es,monitor
          mov      di,y_table[10]
          add      di,108
  sh_f_n: mov      si,2
          mov      byte ptr es:[di-2],20h
          mov      byte ptr es:[di-1],1eh
          mov      al,1eh
          push     cx
          mov      cx,19
          push     ds
          mov      ds,p_lin
          mov      bx,ds:[0]
  fff:    movsb
          stosb
          loop     fff
          pop      ds
          mov      p_lin,bx
          add      di,122
          cmp      bx,0
          pop      cx
          loop     sh_f_n

          cmp      local_y,0
          je       _0_f_d
          mov      bx,local_y
          shl      bx,1
          add      bx,8
          mov      di,y_table[bx]
          add      di,107
          mov      cx,20
  re_fd:  mov      byte ptr es:[di],70h
          add      di,2
          loop     re_fd
  _0_f_d: ret
show_dir  endp

free_dir  proc     near
          mov      es,file_top
  r_free: mov      bx,es:[0]
          FREE_    es
          mov      es,bx
          cmp      bx,0
          jne      r_free
          ret
free_dir  endp

loading   proc     near
          push     ds
          mov      ds,file_ptr
          mov      dx,2
          mov      al,00000000b         ;Read Only Mode
          mov      ah,3dh               ;File_Name be Opened
          int      21h
          pop      ds
          jnc      con_r
          call     error_msg
          jmp      no_rd
  con_r:  mov      handle_,ax
          call     new_act
          mov      di,offset line_buf+1
          mov      line_buf,0
          mov      total_l,1
          mov      eol_flag,0

  r_read: mov      bx,handle_
          mov      dx,offset buffer_
          mov      cx,buf_max
          mov      ah,3fh
          int      21h
                                        ;Should Check ERROR ???
          mov      cx,ax
          cmp      ax,0
          jne      read_1
          jmp      read_z
  read_1: mov      si,offset buffer_
  loopr2: cld
          mov      ax,seg line_buf
          mov      es,ax
  loopr1: cmp      byte ptr [si],1ah    ;End Of File
          jne      eol_1
          dec      cx
          jmp      nx_lr1
  eol_1:  cmp      byte ptr [si],0dh    ;End of Line (Part I)
          jne      eol_2
          mov      eol_flag,1
          inc      si
          jmp      eol_4

  eol_2:  cmp      byte ptr [si],0ah    ;End of Line (Part II)
          jne      eol_3
          cmp      eol_flag,1
          jne      eol_3
          jmp      nx_lr1

  eol_3:  cmp      line_buf,255
          je       nx_lr1
          inc      line_buf
          movsb
          mov      eol_flag,0
  eol_4:  loop     loopr1

  nx_lr1: call     get_buff             ;Linked-List = Line_Buf
          cmp      cx,0
          je       read_3
          mov      es,p_ptr
          mov      bx,es:[0]            ;P_ptr^.next = BX
          NEW_
          mov      es:[0],ax            ;P_ptr^.next = NEW_ptr
          mov      p_ptr,ax             ;P_ptr = NEW_ptr
          mov      es,ax
          mov      es:[0],bx            ;NEW_ptr^.next = BX
          mov      byte ptr es:[2],0
          mov      word ptr es:[30],0
          inc      total_l
          mov      di,offset line_buf+1
          mov      line_buf,0
          dec      cx
          inc      si
  no_n_l: cmp      cx,0
          je       read_3
          jmp      loopr2
  read_3: jmp      r_read

  read_z: mov      bx,handle_
          mov      ah,3eh               ;File_Name be Closed
          int      21h

          mov      cx,13
          mov      si,2
          mov      di,offset file_name
          mov      ax,seg file_name
          mov      es,ax
          push     ds
          mov      ds,file_ptr
  rep     movsb
          pop  ds
          call     here_dir
  no_rd:  ret
loading   endp

newing    proc     near
          mov      ax,1
          push     ax
          call     find_ptr
          mov      es,p_ptr
  lin_1_: mov      ax,es:[30]
          cmp      ax,0
          je       free_a
          mov      es,ax
          FREE_    ax
          jmp      lin_1_

  free_a: mov      cx,total_l
          dec      cx
          cmp      cx,0
          jne      free_b
          jmp      new_z_

  free_b: mov      es,p_ptr             ;P_ptr = P_ptr^.next
          mov      ax,es:[0]            ;^^^^^ 1st = 2nd
          mov      p_ptr,ax
          mov      es,p_ptr

  free_c: mov      ax,es:[30]
          cmp      ax,0
          je       free_d
          mov      es,ax
          FREE_    ax
          jmp      free_c

  free_d: mov      es,p_ptr             ;P_ptr = P_ptr^.next
          mov      ax,es:[0]
          mov      p_ptr,ax
          FREE_    es
          mov      es,p_ptr
          loop     free_c

  new_z_: mov      es,r_ptr
          mov      es,es:[0]
          mov      p_ptr,es
          mov      byte ptr es:[2],0
          mov      word ptr es:[30],0
          mov      ax,seg top_
          add      ax,2
          mov      es:[0],ax
          ret
newing    endp

save_act  proc     near                 ;Stack Put File name address
          push     bp
          mov      bp,sp
          mov      dx,[bp+4]

          mov      cx,00
          mov      ah,3ch
          int      21h
          jnc      save_y
          call     error_msg
          mov      cl,0                 ;Fail
          jmp      out_sa
  save_y: mov      handle_,ax
          mov      ax,seg top_
          mov      es,ax
          mov      cx,total_l

  save_r: push     cx
          mov      ax,es:[0]
          mov      p_ptr,ax
          call     put_buff
          mov      es,ax
          mov      dx,offset line_buf+1
          xor      bx,bx
          mov      bl,line_buf
          cmp      cx,1
          jne      not_z
          mov      cx,0
          jmp      last_l
  not_z:  mov      line_buf[bx+1],0dh
          mov      line_buf[bx+2],0ah
          mov      cx,2
  last_l: add      cx,bx
          mov      bx,handle_
          mov      ah,40h
          int      21h
          pop      cx
          jnc      save_l
          call     error_msg
          jmp      save_z

  save_l: loop     save_r

  save_z: mov      bx,handle_
          mov      ah,3eh               ;File_Name be Closed
          int      21h
          mov      cl,1

  out_sa: pop      bp
          ret      2
save_act  endp

write_act proc     near
          mov      es,monitor
          mov      bx,5
          shl      bx,1
          mov      si,offset write_fun+1
          mov      al,0ah
          mov      cx,3
  wrt_f1: push     cx
          mov      di,y_table[bx]
          add      di,10
          add      bx,2
          mov      cl,write_fun[0]
  wrt_f2: movsb
          stosb
          loop     wrt_f2
          pop      cx
          loop     wrt_f1
          mov      dl,8                 ;X-axis
          mov      dh,7                 ;Y-axis
          mov      ax,offset wrt_file
          push     ax
          call     read_line
          cmp      cl,0
          je       no_w
          inc      ax
          push     ax
          call     save_act
          cmp      cl,0
          je       no_w
          mov      cl,wrt_file[0]
          xor      ch,ch
          add      cx,2
          mov      ax,ds
          mov      es,ax
          mov      si,offset wrt_file
          mov      di,offset this_dir
  rep     movsb
          call     show_name
  no_w:   ret
write_act endp

print_act proc     near                 ;Stack Put Start Line
          push     bp                   ;Stack Put Print Line's Numbers
          push     dx
          mov      bp,sp
          mov      dx,0
          mov      ah,2
          int      17h
          and      ah,08h
          cmp      ah,08h
          jne      prn_on
          call     error_msg
          jmp      out_pn

  prn_on: mov      ax,[bp+8]
          push     ax
          call     find_ptr
          mov      cx,[bp+6]

  prn_r:  push     cx
          call     put_buff
          mov      es,p_ptr
          mov      ax,es:[0]
          mov      p_ptr,ax
          mov      dx,offset line_buf+1
          xor      bx,bx
          mov      bl,line_buf
          mov      line_buf[bx+1],0dh
          mov      line_buf[bx+2],0ah
          mov      cx,2
          add      cx,bx
          mov      bx,4h
          mov      ah,40h
          int      21h
          pop      cx
          jnc      prn_l
          call     error_msg
          jmp      out_pn

  prn_l:  loop      prn_r

  out_pn: pop       dx
          pop       bp
          ret       4
print_act endp

error_msg proc     near
          push     cx
          CURSOR_0
          mov      es,monitor
          mov      di,1600
          mov      si,offset msg_
          mov      cx,80
          mov      al,0ch
  m_g_:   movsb
          stosb
          loop     m_g_
          mov      ah,0
          int      16h
          CURSOR_1
          pop      cx
          ret
error_msg endp

help_win  proc     near
          push     cx
          mov      es,monitor
          mov      bx,4
          shl      bx,1
          mov      si,offset win_help+2
          xor      ch,ch
          mov      cl,win_help[1]
  h_g1:   push     cx
          mov      di,y_table[bx]
          add      di,20
          add      bx,2
          mov      cl,win_help[0]
          mov      al,2eh
  h_g2:   movsb
          stosb
          loop     h_g2
          pop      cx
          loop     h_g1

          mov      ah,0
          int      16h
          pop      cx
          ret
help_win  endp

chg_drive proc     near
          mov      ah,19h
          int      21h
          add      al,65
          mov      drive_fun[64],al
          mov      es,monitor
          mov      si,offset drive_fun+1
          mov      bx,4
          shl      bx,1
          mov      cx,3
  l_drv:  push     cx
          mov      di,y_table[bx]
          add      di,46
          mov      cl,drive_fun
          mov      al,0bh
  drv_f:  movsb
          stosb
          loop     drv_f
          add      bx,2
          pop      cx
          loop     l_drv

          mov      dl,56
          mov      dh,5
          mov      bx,0
          mov      ah,2
          int      10h

  re_drv: mov      ah,0
          int      16h
          cmp      al,27
          je       drv_z
          cmp      al,90
          jbe      try_d
          sub      al,32
  try_d:  sub      al,65
          mov      dl,al
          mov      ah,0eh
          int      21h
          jc       re_drv
  drv_z:  ret
chg_drive endp

code      ends
          end

[ RETURN TO DIRECTORY ]