home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 1 / FREEWARE.BIN / ms_dos / esc98 / esc98.asm next >
Assembly Source File  |  1989-10-17  |  17KB  |  949 lines

  1.         page    60,80
  2.         .286c
  3.         .sall
  4. ;
  5. ;    PC98ESCシーケンスシミュレータ
  6. ;
  7. ;    esc98    ver 0.15    1989.05.02
  8. ;
  9. ;    by とくさん
  10. ;
  11. ;
  12. MODE        equ    1
  13. DISP        equ    1
  14. ON        equ    1
  15. SYSTEM        equ    20h
  16. LINES        equ    40h
  17. CURSOR        equ    80h
  18. GR_MODE        equ    80h
  19. FM_MODE        equ    10h
  20. CHECK        equ    01h
  21. DOS        equ    21h
  22. CR        equ    0dh
  23. LF        equ    0ah
  24. ;
  25. ;       メモリコントロールブロック定義
  26. mcb_stru        struc
  27. mcb_id          db      ?
  28. psp_seg         dw      ?
  29. mcb_len         dw      ?
  30. mcb_stru        ends
  31. ;
  32. code        segment
  33.         assume    cs:code,ds:code,es:code,ss:code
  34.  
  35.         org    80h
  36.  
  37. int29        dd    ?
  38. intff        dd    ?    ; for DEBUG
  39. save_sp        dw    ?
  40. save_ss        dw    ?
  41. attribute_area    db    ?
  42. attribute    db    ?
  43. color        dw    ?
  44. flag_lo        db    0
  45. flag_hi        db    0
  46. skip        db    0
  47.         db    0
  48. len        dw    0
  49. buffer        db    ?
  50.  
  51.         org    100h
  52. start:
  53. jmp        main
  54.  
  55. xcolor_tab    db    0,2,4,6,1,3,5,7
  56. xcolor_tab2    db    0,2,1,3,4,6,5,7
  57. xattr_tab    db    0,20h,4,2,80h,10h,1,8,40h
  58. jump_tab    dw    _1st,_2nd,_3rd,_4th,_5th,above_5th
  59.  
  60. int29_entry:
  61.         push    ds
  62.         push    cs
  63.         pop    ds
  64.         mov    save_sp,sp
  65.         mov    save_ss,ss
  66.         push    cs
  67.         pop    ss
  68.         mov    sp,offset stack
  69.         mov    bp,sp
  70.         pusha
  71.         sti
  72.         dec    bp
  73.         dec    bp        ; ss:[bp] = AX
  74.         test    flag_hi,CHECK
  75.         jnz    test_mode
  76.         mov    bx,len
  77.         cmp    bx,6
  78.         jb    int29_entry1
  79.         mov    bx,5
  80. int29_entry1:
  81.         shl    bx,1
  82.         add    bx,offset jump_tab
  83.         jmp    word ptr [bx]
  84. ;
  85. ;    テストモード
  86. ;
  87. test_mode:
  88.         and    flag_hi,not CHECK
  89.         jmp    int29_ret
  90. ;
  91. ;    バッファに格納
  92. ;
  93. put_buffer:
  94.         cmp    byte ptr len,128
  95.         ja    out_buffer
  96. put_buffer1:
  97.         mov    di,offset buffer
  98.         mov    bx,len
  99.         mov    [di+bx],al
  100.         inc    byte ptr len
  101. ;
  102. ;    復帰
  103. ;
  104. int29_ret:
  105.         popa
  106.         mov    ss,save_ss
  107.         mov    sp,save_sp
  108.         pop    ds
  109.         iret
  110. ;
  111. ;    バッファクリアにして復帰
  112. ;
  113. int29_ret0:
  114.         mov    len,0
  115.         jmp    int29_ret
  116. ;
  117. ;    バッファの文字列出力
  118. ;
  119. out_buffer:
  120.         mov    flag_lo,0
  121.         mov    cx,len
  122.         jcxz    int29_quit
  123.         mov    si,offset buffer
  124. out_buffer_loop:
  125.         cld
  126.         lodsb
  127.         pushf
  128.         cli
  129.         call    dword ptr [int29]
  130.         loop    out_buffer_loop
  131.         mov    len,cx
  132. int29_quit:
  133.         cli
  134.         popa
  135.         mov    ss,save_ss
  136.         mov    sp,save_sp
  137.         pop    ds
  138.         jmp    dword ptr cs:[int29]
  139. ;
  140. ;    1文字目(ESCのチェック)
  141. ;
  142. _1st:
  143.         cmp    skip,0
  144.         jz    chk_ESC
  145.         dec    skip
  146.         jmp    int29_quit
  147. chk_ESC:
  148.         cmp    al,1bh
  149.         je    put_buffer
  150.         cmp    al,' '
  151.         ja    chk_graph
  152.         call    is_ctrl
  153.         jmp    int29_quit
  154. chk_graph:
  155.         call    is_kanji
  156.         jmp    int29_quit
  157. ;
  158. ;    2文字目のチェック
  159. ;    D / E / M …代替シーケンス出力(0→len)
  160. ;    G / .     …skip 設定(0→len)
  161. ;    )         …モードフラグセット(len++)
  162. ;    ]         …継続(len++)
  163. ;
  164. _2nd:
  165.         cmp    al,'.'
  166.         jne    chk_G
  167.         mov    skip,2
  168.         jmp    out_buffer
  169. chk_G:
  170.         cmp    al,'G'
  171.         jne    chk_D
  172.         mov    skip,1
  173.         jmp    out_buffer
  174. chk_D:
  175.         cmp    al,'D'
  176.         jne    chk_M
  177.         mov    al,1fh            ; ↓
  178.         jmp    short _2nd_quit
  179. chk_M:
  180.         cmp    al,'M'
  181.         jne    chk_E
  182.         mov    al,1eh            ; ↑
  183.         jmp    short _2nd_quit
  184. chk_E:
  185.         cmp    al,'E'
  186.         jne    chk_MODE
  187.         test    flag_hi,FM_MODE
  188.         jnz    out_buffer
  189.         mov    al,0dh
  190.         pushf
  191.         cli
  192.         call    dword ptr [int29]
  193.         mov    al,1fh
  194. _2nd_quit:
  195.         mov    len,0
  196.         mov    [bp],ax
  197.         jmp    int29_quit
  198. ;
  199. chk_MODE:
  200.         cmp    al,')'
  201.         jne    chk_continue
  202.         or    flag_lo,MODE
  203. _2nd_quit1:
  204.         jmp    put_buffer
  205. chk_continue:
  206.         cmp    al,'['
  207.         je    _2nd_quit1
  208.         cmp    al,1bh
  209.         jne    chk_continue1
  210.         test    flag_hi,FM_MODE
  211.         jnz    chk_continue1
  212.         jmp    int29_ret0
  213. chk_continue1:
  214.         jmp    out_buffer
  215. ;
  216. ;    3文字目のチェック
  217. ;    MODE & '0'~'9'…モード設定(0→len)
  218. ;    >           …モードフラグセット(len++)
  219. ;    '0'~'9'       …継続(len++)
  220. ;
  221. _3rd:
  222.         test    flag_lo,MODE
  223.         jz    chk_DISP
  224.         mov    flag_lo,0
  225.         cmp    al,'3'
  226.         jne    set_MODE
  227.         or    flag_hi,GR_MODE
  228.         jmp    int29_ret0
  229. set_MODE:
  230.         cmp    al,'0'
  231.         jne    _3rd_quit
  232.         and    flag_hi,not GR_MODE
  233. set_MODE1:
  234.         jmp    int29_ret0
  235. chk_DISP:
  236.         call    is_numeric1
  237.         jnc    chk_DISP0
  238.         cmp    al,'>'
  239.         jne    chk_DISP1
  240.         or    flag_lo,DISP
  241. chk_DISP0:
  242.         jmp    put_buffer
  243. chk_DISP1:
  244.         call    move_line
  245.         jnc    set_MODE1
  246. chk_DISP3:
  247.         cmp    al,';'
  248.         jne    _3rd_quit
  249.         test    flag_hi,FM_MODE
  250.         jz    chk_DISP0
  251. _3rd_quit:
  252.         jmp    out_buffer
  253. ;
  254. ;    4文字のチェック
  255. ;    '0'~'9' & DISP …該当フラグセット
  256. ;    '0'~'9' / ';'  …継続
  257. ;    'm'        …属性の変更
  258. ;
  259. _4th:
  260.         test    flag_lo,DISP
  261.         jz    chk_attr
  262.         mov    flag_lo,0
  263.         cmp    al,'1'
  264.         jne    chk_width
  265.         or    flag_lo,SYSTEM
  266.         jmp    short chk_disp_quit
  267. chk_width:
  268.         cmp    al,'3'
  269.         jne    chk_cursor
  270.         or    flag_lo,LINES
  271.         jmp    short chk_disp_quit
  272. chk_cursor:
  273.         cmp    al,'5'
  274.         jne    _3rd_quit
  275.         or    flag_lo,CURSOR
  276. chk_disp_quit:
  277.         jmp    put_buffer
  278. chk_attr:
  279.         call    is_numeric1
  280.         jnc    chk_disp_quit
  281. chk_disp_error:
  282.         cmp    al,';'
  283.         jne    chk_disp_error1
  284.         test    flag_hi,FM_MODE
  285.         jnz    _3rd_quit
  286. chk_disp_error1:
  287.         call    move_line
  288.         jc    _3rd_quit
  289.         jmp    int29_ret0
  290. ;
  291. ;    5文字目のチェック
  292. ;    (SYSTEM | LINES | CURSOR) & ('h' | 'l')…各種設定
  293. ;    'm'    …属性変更
  294. ;    '0'~'9' | ';' …継続
  295. ;
  296. _5th:
  297.         test    flag_lo,SYSTEM or LINES or CURSOR
  298.         jz    above_5th
  299.         cmp    al,'h'
  300.         je    set_SYSTEM
  301.         cmp    al,'l'
  302.         jne    chk_disp_error
  303.         or    flag_lo,ON
  304. set_SYSTEM:
  305.         test    flag_lo,SYSTEM
  306.         jz    set_WIDTH
  307.         mov    ax,1bc2h
  308.         test    flag_lo,ON
  309.         jnz    set_SYSTEM1
  310.         mov    al,082h
  311. set_SYSTEM1:
  312.         int    91h
  313. set_DISP_quit:
  314.         mov    flag_lo,0
  315.         jmp    int29_ret0
  316. set_WIDTH:
  317.         test    flag_lo,LINES
  318.         jz    set_CURSOR
  319.         mov    dx,25*256+80
  320.         test    flag_lo,ON
  321.         jz    set_width1
  322.         mov    dh,20
  323. set_width1:
  324.         mov    ah,03h
  325.         int    91h
  326.         jmp    set_DISP_quit
  327. set_CURSOR:
  328.         mov    ax,0b01h
  329.         test    flag_lo,ON
  330.         jz    set_cursor1
  331.         xor    al,al
  332. set_cursor1:
  333.         int    91h
  334.         jmp    set_DISP_quit
  335. ;
  336. ;    6文字目以降のチェック
  337. ;    '0'~'9' | ';'  …継続
  338. ;    'm'        …属性変更
  339. ;
  340. above_5th:
  341.         call    is_numeric
  342.         jc    chk_line
  343.         jmp    put_buffer
  344. chk_line:
  345.         call    move_line
  346.         jc    chk_m
  347.         jmp    int29_ret0
  348. chk_m:
  349.         cmp    al,'m'
  350.         je    set_attribute
  351.         jmp    out_buffer
  352. ;
  353. ;
  354. set_attribute:
  355.         mov    si,offset buffer
  356.         mov    di,offset attribute
  357.         mov    bx,len
  358.         xor    dx,dx
  359.         mov    [si+bx],dx
  360.         inc    si
  361.         inc    si
  362.         mov    byte ptr [di],dl
  363.         mov    word ptr [di+1],7
  364.         cld
  365. set_attr_loop1:
  366.         xor    bx,bx
  367.         cmp    [si],bl
  368.         jz    set_attr_quit
  369. set_attr_loop2:
  370.         lodsb
  371.         call    is_numeric1
  372.         jc    set_attr_0
  373.         sub    al,'0'
  374.         shl    bl,1
  375.         mov    bh,bl
  376.         shl    bl,2
  377.         add    bl,bh
  378.         add    bl,al
  379.         jmp    set_attr_loop2
  380. set_attr_0:
  381.         mov    al,bl
  382.         cmp    al,16
  383.         jb    set_attr6
  384.         cmp    al,40
  385.         jb    set_attr1
  386.         cmp    al,47
  387.         ja    set_attr_loop1
  388.         or    dl,08h        ; Reverse
  389.         sub    al,40
  390.         jmp    short set_attr2_0
  391. set_attr1:
  392.         cmp    al,30
  393.         jae    set_attr2
  394.         sub    al,10h
  395.         mov    bx,offset xcolor_tab2
  396.         jmp    short set_attr2_1
  397. set_attr2:
  398.         sub    al,30
  399. set_attr2_0:
  400.         mov    bx,offset xcolor_tab
  401. set_attr2_1:
  402.         cmp    al,7
  403.         ja    set_attr_loop1
  404.         xlat
  405.         mov    dh,al
  406. set_attr3:
  407.         jmp    set_attr_loop1
  408. set_attr6:
  409.         mov    bx,offset xattr_tab
  410.         cmp    al,8
  411.         ja    set_attr8
  412.         xlat
  413.         or    al,al
  414.         jz    set_attr7
  415.         or    dl,al
  416.         jmp    set_attr_loop1
  417. set_attr7:
  418.         xor    dl,dl
  419. set_attr8:
  420.         jmp    set_attr_loop1
  421. set_attr_quit:
  422.         mov    flag_lo,bl
  423.         mov    word ptr [di],dx
  424.         dec    di
  425.         mov    ah,11h
  426.         int    91h
  427.         jmp    int29_ret0
  428. ;
  429. ;    行削除/行挿入シーケンス
  430. ;
  431. move_line    proc    near
  432.  
  433.         cmp    al,'L'
  434.         je    ins_line
  435.         cmp    al,'M'
  436.         je    del_line
  437.         stc
  438.         ret
  439. ins_line:
  440.         mov    byte ptr flag_lo,1
  441.         jmp    short count_line
  442. del_line:
  443.         mov    byte ptr flag_lo,0
  444. count_line:
  445.         mov    si,offset buffer+2
  446.         mov    cx,word ptr len
  447.         sub    cx,2
  448.         xor    bx,bx
  449.         jcxz    check_zero1
  450. count_line_loop:
  451.         lodsb
  452.         call    is_numeric1
  453.         jnc    count_line1
  454.         ret
  455. count_line1:
  456.         sub    al,'0'
  457.         shl    bl,1
  458.         mov    ah,bl
  459.         shl    bl,2
  460.         add    bl,ah
  461.         add    bl,al
  462.         loop    count_line_loop
  463. check_zero:
  464.         or    bl,bl
  465.         jnz    check_zero2
  466. check_zero1:
  467.         mov    bl,1
  468. check_zero2:
  469.         mov    ah,0eh
  470.         int    91h
  471.         mov    dl,1
  472.         mov    cx,bx
  473.         mov    bx,24*256+80
  474.         mov    al,flag_lo
  475.         mov    ah,1ah
  476.         int    91h
  477.         mov    flag_lo,0
  478.         clc
  479.         ret
  480.  
  481. move_line    endp
  482. ;
  483. ;    パラメータのチェック
  484. ;
  485. is_numeric    proc    near
  486.  
  487.         cmp    al,';'
  488.         je    numeric_ok
  489. is_numeric1:
  490.         cmp    al,'0'
  491.         jb    numeric_no
  492.         cmp    al,'9'
  493.         ja    numeric_no
  494. numeric_ok:
  495.         clc
  496.         ret
  497. numeric_no:
  498.         stc
  499.         ret
  500.  
  501. is_numeric    endp
  502. ;
  503. ;    グラフィックキャラクタのチェック
  504. ;
  505. is_kanji    proc    near
  506.  
  507.         cmp    al,080h
  508.         jb    kanji_no
  509.         cmp    al,0a0h
  510.         jb    kanji_yes
  511.         cmp    al,0e0h
  512.         jb    kanji_no
  513. kanji_yes:
  514.         test    flag_hi,GR_MODE
  515.         jz    kanji_no
  516.         mov    al,1bh
  517.         pushf
  518.         call    dword ptr [int29]
  519. kanji_no:
  520.         ret
  521.  
  522. is_kanji    endp
  523. ;
  524. ;    コントロールキャラクタの変換
  525. ;
  526. is_ctrl        proc    near
  527.  
  528.         cmp    al,1ah
  529.         jne    is_ctrl1
  530.         mov    al,0ch
  531.         jmp    short is_ctrl_ret
  532. is_ctrl1:
  533.         test    flag_hi,FM_MODE
  534.         jnz    is_ctrl_ret
  535.         cmp    al,0bh
  536.         jne    is_ctrl2
  537.         mov    al,1eh
  538.         jmp    short is_ctrl_ret
  539. is_ctrl2:
  540.         cmp    al,0ch
  541.         jne    is_ctrl3
  542.         mov    al,1ch
  543.         jmp    short is_ctrl_ret
  544. is_ctrl3:
  545.         cmp    al,1eh
  546.         jne    is_ctrl_ret1
  547.         mov    al,0bh
  548. is_ctrl_ret:
  549.         mov    [bp],ax
  550. is_ctrl_ret1:
  551.         ret
  552.  
  553. is_ctrl        endp
  554.  
  555. int29_end    label    byte
  556.  
  557.         db    126 dup (?)
  558. stack        dw    ?
  559.  
  560. int29_ofs    dw    ?
  561. int29_seg    dw    ?
  562. intff_ofs    dw    ?
  563. intff_seg    dw    ?
  564. save_ds        dw    ?
  565. flag1        db    0
  566. flag2        db    0
  567. EXIST        equ    1
  568. REMOVE        equ    10h
  569. FM        equ    20h
  570. opening_msg        db    'PC9801 ',1bh,'[32mESC ',1bh,'[msequence Simulater for FM16β/FMR  - Version 0.15 -  by tokusan 1989',CR,LF,LF,'$'
  571. mcb_error_msg        db    9,'MCB error!!',CR,LF,'$'
  572. title_release        db    'Release>>$'
  573. release_error_msg1    db    2,7,'ESC98 is not resident!!',CR,LF,'$'
  574. release_error_msg2    db    3,7,'Memory deallocation error!!',CR,LF,'$'
  575. release_error_msg4    db    5,7,'INT29 vector is re-re-hooked ... can''t remove!!',CR,LF,'$'
  576. release_msg        db    0,'ESC98 is active ... Release.',CR,LF,'$'
  577. release_msg2        db    0,'ESC98 is not active ... Release.',CR,LF,'$'
  578. release_msg3        db    7,'INT29 vector is re-hooked.  Sure?(Y/N) > $'
  579. title_install        db    'Install>>$'
  580. install_error_msg1    db    0,'ESC98 is active ... Change mode.',CR,LF,'$'
  581. install_error_msg2    db    0,'ESC98 is not active ... Reinstall.',CR,LF,'$'
  582. install_msg        db    0,'ESC98 is not resident ... Install.',CR,LF,'$'
  583. install_mode_msg    db    'Set ESC sequence mode to $'
  584. nec_msg            db    1bh,'[32mNEC',1bh,'[m',CR,LF,'$'
  585. fm_msg            db    1bh,'[32mFUJITSU',1bh,'[m',CR,LF,'$'
  586. yes_msg            db    1bh,'[32mYes',1bh,'[m',CR,LF,'$'
  587. no_msg          db    0,1bh,'[32mNo',1bh,'[m',CR,LF,'$'
  588. usage            db    1,7,'Usage : esc98 [f|r]',CR,LF
  589.              db    '=========== ==============================',CR,LF
  590.              db    '  nothing    install  or  change mode  or',CR,LF
  591.              db      '             reinstall  in  NEC  mode',CR,LF
  592.              db    '----------- ------------------------------',CR,LF
  593.              db    '  f          install  or  change mode  or',CR,LF
  594.              db    '             reinstall in FUJITSU mode',CR,LF
  595.              db    '----------- ------------------------------',CR,LF
  596.              db    '  r          remove memory-resident ESC98',CR,LF
  597.              db    '             from memory',CR,LF
  598.              db    '=========== ==============================',CR,LF,'$'
  599.  
  600. main:
  601.         cld
  602.         mov    dx,offset opening_msg
  603.         call    print
  604.         call    chk_exist
  605. check_param:
  606.         mov    si,80h
  607.         lodsb
  608.         or    al,al
  609.         jz    install_program
  610.         call    chk_param
  611.         test    flag1,REMOVE
  612.         jz    install_program
  613.         call    release_program
  614. quit:
  615.         mov    bx,dx
  616.         inc    dx
  617.         mov    ah,09h
  618.         int    DOS
  619.         mov    al,[bx]
  620.         mov    ah,4ch
  621.         int    DOS
  622. install_program:
  623.         mov    dx,offset title_install
  624.         call    print
  625.         mov    dx,offset install_mode_msg
  626.         call    print
  627.         mov    dx,offset nec_msg
  628.         test    flag1,FM
  629.         jz    install0
  630.         mov    dx,offset fm_msg
  631. install0:
  632.         call    print
  633.         test    flag1,EXIST
  634.         jz    stay_program
  635. install_program1:
  636.         test    flag1,ACTIVE
  637.         jnz    change_mode
  638.         call    reinstall
  639.         jmp    quit
  640. change_mode:
  641.         call    change
  642.         jmp    quit
  643. stay_program:
  644.         mov    di,80h
  645.         mov    cx,64
  646.         push    ds
  647.         pop    es
  648.         xor    ax,ax
  649.         rep stosw
  650.         test    flag1,FM
  651.         jz    stay1
  652.         mov    flag_hi,FM_MODE
  653. stay1:
  654.         les    ax,dword ptr int29_ofs
  655.         mov    word ptr int29,ax
  656.         mov    word ptr int29+2,es
  657.         mov    es,word ptr ds:[02ch]
  658.         mov    ah,49h
  659.         int    DOS
  660.         mov    dx,offset install_msg
  661.         call    print
  662.         mov    dx,offset int29_entry
  663.         mov    ax,2529h
  664.         int    DOS
  665.         mov    ax,offset stack
  666.         add    ax,0fh
  667.         shr    ax,4
  668.         mov    dx,ax
  669.         mov    ax,3100h
  670.         int    DOS
  671. stay_error:
  672.         mov    dx,offset install_error_msg1
  673.         jmp    quit
  674. ;
  675. ;    常駐しているESC98の削除及びメモリの解放
  676. ;
  677. release_program proc    near
  678.  
  679.         mov    dx,offset title_release
  680.         call    print
  681.         test    flag1,EXIST
  682.         jnz    release1
  683.         mov    dx,offset release_error_msg1
  684.         ret
  685. release1:
  686.         mov    es,save_ds
  687.         mov    dx,offset release_msg2
  688.         test    flag1,ACTIVE
  689.         jz    release3
  690.         test    flag1,RELEASE
  691.         jnz    release2
  692.         call    remove_rehooked
  693.         jz    release3
  694.         ret
  695. release2:
  696.         lds    dx,es:[int29]
  697.         mov    ax,2529h
  698.         int    DOS
  699.         push    cs
  700.         pop    ds
  701.         mov    dx,offset release_msg
  702. release3:
  703.         mov    ah,49h
  704.         int    DOS
  705.         jc    release_error2
  706.         ret
  707. release_error2:
  708.         mov    dx,offset release_error_msg2
  709.         ret
  710.  
  711. release_program endp
  712. ;
  713. ;    ジャンプアドレスの書き換え
  714. ;
  715.         public    remove_rehooked,found
  716. remove_rehooked    proc    near
  717.  
  718.         mov    dx,offset release_msg3
  719.         call    print
  720.         mov    ah,7
  721.         int    DOS
  722.         and    al,0dfh
  723.         mov    dx,offset no_msg
  724.         cmp    al,'Y'
  725.         jne    remove_rehooked_quit
  726.         mov    dx,offset yes_msg
  727.         call    print
  728.         mov    es,save_ds
  729.         les    ax,es:[int29]
  730.         mov    intff_ofs,ax
  731.         mov    intff_seg,es
  732.         mov    bx,word ptr [int29_seg]
  733.         dec    bx
  734.         mov    es,bx
  735.         mov    cx,es:[mcb_len]
  736.         mov    dx,cx
  737.         shr    dx,12
  738.         shl    cx,4
  739.         inc    bx
  740.         mov    es,bx
  741.         mov    bx,save_ds
  742.         mov    ax,offset int29_entry
  743. search_loop:
  744.         xor    di,di
  745. search_loop1:
  746.         repne scasb
  747.         jne    search_next
  748.         cmp    ah,es:[di]
  749.         jne    search_loop1
  750.         cmp    bx,es:[di+1]
  751.         jne    search_loop1
  752.         dec    di
  753.         mov    si,offset intff_ofs
  754.         cli
  755.         movsw
  756.         movsw
  757.         sti
  758.         jmp    short found
  759. search_next:
  760.         dec    dx
  761.         jns    search_loop
  762.         mov    dx,offset release_error_msg4
  763.         jmp    short remove_rehooked_quit
  764. found:
  765.         cmp    al,al
  766.         mov    es,save_ds
  767.         mov    dx,offset release_msg
  768. remove_rehooked_quit:
  769.         ret
  770.  
  771. remove_rehooked    endp
  772. ;
  773. ;       常駐チェック
  774. ;
  775. MCB_EXIST    equ    1
  776. ACTIVE        equ    2
  777. RELEASE        equ    4
  778. INT29_EQ_ESC98    equ    10h
  779. INT29_EQ_PSP    equ    20h
  780. INT29_NE_SAVE    equ    40h
  781. ;
  782.                 public  chk_exist
  783. chk_exist       proc    near
  784.  
  785.         mov    ax,3529h
  786.         int    DOS
  787.         mov    int29_ofs,bx
  788.         mov    int29_seg,es
  789.                 mov     save_ds,ds
  790.                 mov     ah,52h
  791.                 int     DOS
  792.                 dec     bx
  793.                 dec     bx
  794.                 mov     ax,es:[bx]
  795.                 mov     es,ax
  796.                 mov     bx,ds
  797. check_search:
  798.                 cmp     byte ptr es:[mcb_id],'Z'
  799.                 je      check_exist_on
  800.                 cmp     byte ptr es:[mcb_id],'M'
  801.                 jne     check_error
  802.                 mov     dx,word ptr es:[psp_seg]
  803.                 or    dx,dx
  804.                 jz    check_next
  805.                 cmp     bx,dx                   ; 自分自身か?
  806.                 je      check_next              ; 自分より後に常駐してるかも
  807.                 cmp    dx,int29_seg
  808.                 jne    check_search1
  809.         or    flag2,INT29_EQ_PSP
  810. check_search1:
  811.                 mov     es,dx
  812.                 mov     cx,offset int29_end - offset int29_entry
  813.                 mov     di,offset int29_entry
  814.                 mov     si,di
  815.                 repe    cmpsb                   ; キーワードのチェック
  816.                 jne    check_next
  817.                 mov    save_ds,es
  818.                 or    flag1,MCB_EXIST
  819.                 test    flag1,INT29_EQ_PSP
  820.                 jnz    check_exist_on1
  821. check_next:
  822.                 mov     es,ax
  823.                 add     ax,word ptr es:[mcb_len]
  824.                 inc     ax
  825.                 mov     es,ax
  826.                 jmp    check_search
  827. check_error:
  828.                 mov     dx,offset mcb_error_msg
  829.                 jmp     quit
  830. check_exist_on:
  831.                 test    flag1,MCB_EXIST
  832.                 jz    check_not_exist
  833.                 test    flag2,INT29_EQ_PSP
  834.                 jz    check_not_exist
  835. check_exist_on1:
  836.         mov    es,save_ds
  837.         mov    bx,int29_seg
  838.                 cmp    bx,word ptr es:[int29+2]
  839.                 je    check_not_exist
  840.                 cmp    bx,save_ds
  841.                 jne    check_exit_on2
  842.                 or    flag1,RELEASE
  843. check_exit_on2:
  844.         or    byte ptr es:[flag_hi],CHECK
  845.         xor    ax,ax
  846.         int    29h
  847.         test    byte ptr es:[flag_hi],CHECK
  848.         jnz    check_not_exist
  849.         or    flag1,ACTIVE
  850. check_not_exist:
  851.                 push    ds
  852.                 pop     es
  853.  
  854. check_exist_exit:
  855.                 ret
  856.  
  857. chk_exist       endp
  858. ;
  859. ;
  860. ;
  861. chk_param    proc    near
  862.  
  863. chk_param_loop:
  864.         call    skip_space
  865.         cmp    al,CR
  866.         je    chk_param3
  867.         and    al,0dfh
  868.         cmp    al,'R'
  869.         jne    chk_param1
  870.         or    flag1,REMOVE
  871.         jmp    short chk_param3
  872. chk_param1:
  873.         cmp    al,'F'
  874.         je    chk_param2
  875. chk_param_error:
  876.         mov    dx,offset usage
  877.         jmp    quit
  878. chk_param2:
  879.         or    flag1,FM
  880. chk_param3:
  881.         ret
  882.  
  883. chk_param    endp
  884. ;
  885. ;
  886. ;
  887. reinstall    proc    near
  888.  
  889.         mov    es,save_ds
  890.         mov    di,offset int29
  891.         mov    si,offset int29_ofs
  892.         movsw
  893.         movsw
  894.         mov    dx,offset int29_entry
  895.         push    es
  896.         pop    ds
  897.         mov    ax,2529h
  898.         int    DOS
  899.         push    cs
  900.         pop    ds
  901.         mov    dx,offset install_error_msg2
  902.         jmp    short change1
  903.  
  904. reinstall    endp
  905. ;
  906. ;    モード変更
  907. ;
  908. change        proc    near
  909.  
  910.         mov    dx,offset install_error_msg1
  911. change1:
  912.         mov    es,save_ds
  913.         test    flag1,FM
  914.         jnz    set_FM_MODE
  915.         and    es:flag_hi,not FM_MODE
  916.         jmp    short change_mode_quit
  917. set_FM_MODE:
  918.         or    es:flag_hi,FM_MODE
  919. change_mode_quit:
  920.         ret
  921.  
  922. change        endp
  923. ;
  924. ;
  925. ;
  926. print        proc    near
  927.  
  928.         mov    ah,9
  929.         int    DOS
  930.         ret
  931.  
  932. print        endp
  933.  
  934. skip_space    proc    near
  935.  
  936.         lodsb
  937.         cmp    al,' '
  938.         je    skip_space
  939.         cmp    al,09h
  940.         je    skip_space
  941.         ret
  942.  
  943. skip_space    endp
  944.  
  945. code        ends
  946.  
  947.         end    start
  948.