home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / ish / ish200s / ishsub.h < prev    next >
Text File  |  1990-06-14  |  26KB  |  1,238 lines

  1. ;
  2. ;        ish file converter for MS-DOS  Ver 2.00 (90/3/27)
  3. ;
  4. ;
  5. ;        Copyright (c) 1986, 1987, 1989, 1990  by  M. ishizuka
  6. ;        All rights reserved.
  7. ;
  8.  
  9.  
  10.  
  11. ;-----------------------------------------------;
  12. ;                        ;
  13. ;    @@get_hex2                ;
  14. ;                        ;
  15. ;    INPUT :    si (pointer)            ;
  16. ;    OUTPUT:    al (value)            ;
  17. ;        si (next pointer)        ;
  18. ;    ERROR :    error_01            ;
  19. ;    BREAK :    flags, al, cx            ;
  20. ;                        ;
  21. ;                        ;
  22. ;-----------------------------------------------;
  23.  
  24. @@get_hex2    macro
  25.         lodsb
  26.         call    tolower
  27.         cmp    al, 0dh
  28.         jz    error_01
  29.         sub    al, '0'
  30.         jc    get_hex2_4
  31.         cmp    al, 9 + 1
  32.         jc    get_hex2_1
  33.         sub    al, 'a' - '0'
  34.         jc    get_hex2_4
  35.         cmp    al, 'f' - 'a' + 1
  36.         jnc    get_hex2_4
  37.         add    al, 10d
  38. get_hex2_1:    mov    ch, al
  39.         lodsb
  40.         call    tolower
  41.         cmp    al, 0dh
  42.         jz    get_hex2_3
  43.         sub    al, '0'
  44.         jc    get_hex2_3
  45.         cmp    al, 9 + 1
  46.         jc    get_hex2_2
  47.         sub    al, 'a' - '0'
  48.         jc    get_hex2_3
  49.         cmp    al, 'f' - 'a' + 1
  50.         jnc    get_hex2_3
  51.         add    al, 10d
  52. get_hex2_2:    mov    cl, 4
  53.         shl    ch, cl
  54.         add    al, ch
  55.         jmp    get_hex2_ret
  56.  
  57. get_hex2_3:    dec    si
  58.         mov    al, cl
  59.         jmp    get_hex2_ret
  60.  
  61. get_hex2_4:    mov    al, [si-1]
  62. get_hex2_ret:
  63.         endm
  64.  
  65.  
  66.  
  67. ;-----------------------------------------------;
  68. ;                        ;
  69. ;    @@check_stack                ;
  70. ;                        ;
  71. ;    INPUT :    sp                ;
  72. ;    OUTPUT:    flags                ;
  73. ;    ERROR :    error_10            ;
  74. ;    BREAK :    NON                ;
  75. ;                        ;
  76. ;    FUNC:    check stack area        ;
  77. ;        if short memory then error_10    ;
  78. ;                        ;
  79. ;-----------------------------------------------;
  80.  
  81. @@check_stack    macro
  82.         cmp    sp, offset end_of_stack
  83.         jc    error_10
  84.         endm
  85.  
  86.  
  87.  
  88. ;-----------------------------------------------;
  89. ;                        ;
  90. ;    @@allocate_memory_and_set_buffer_seg    ;
  91. ;                        ;
  92. ;    INPUT :    NON                ;
  93. ;    OUTPUT:    NON                ;
  94. ;    ERROR :    error_10, error_19        ;
  95. ;    BREAK : ax, bx, cx, dx, flags        ;
  96. ;                        ;
  97. ;-----------------------------------------------;
  98.  
  99. @@allocate_memory_and_set_buffer_seg    macro
  100.         mov    ah, 4ah
  101.         mov    bx, offset end_of_stack_para + 0fc0h + 0fc0h
  102.         int    21h
  103.         jnc    alloc_mem_0
  104.         cmp    ax, 8
  105.         jnz    error_19
  106.         mov    byte ptr shell_escape, 0
  107. alloc_mem_0:    sub    bx, offset end_of_stack_para
  108.         jc    error_19
  109.         shr    bx, 1
  110.         jz    error_10
  111.         mov    dx, ds
  112.         add    dx, offset end_of_stack_para
  113.         mov    word ptr _read_buffer_seg, dx
  114.         cmp    bx, 40h
  115.         jc    alloc_mem_1
  116.         and    bx, 0ffc0h
  117.         mov    ax, 0fc0h
  118.         cmp    bx, ax
  119.         jnc    alloc_mem_2
  120. alloc_mem_1:    mov    ax, bx
  121. alloc_mem_2:    add    dx, ax
  122.         mov    word ptr _write_buffer_seg_1, dx
  123.         mov    word ptr _write_buffer_seg_2, dx
  124.         mov    cl, 4
  125.         shl    ax, cl
  126.         mov    word ptr _read_buffer_length, ax
  127.         mov    word ptr _write_buffer_length_1, ax
  128.         mov    word ptr _write_buffer_length_2, ax
  129.         mov    word ptr _write_buffer_length_3, ax
  130.         mov    word ptr _write_buffer_length_4, ax
  131.         mov    disk_write_length_left, ax
  132.         endm
  133.  
  134.  
  135.  
  136. ;-----------------------------------------------;
  137. ;                        ;
  138. ;    @@get_dos_version            ;
  139. ;                        ;
  140. ;    INPUT :    NON                ;
  141. ;    OUTPUT:    ax                ;
  142. ;    ERROR :    NON                ;
  143. ;    BREAK : bx, cx                ;
  144. ;                        ;
  145. ;-----------------------------------------------;
  146.  
  147. @@get_dos_version    macro
  148.         mov    ah, 30h
  149.         int    21h            ; get dos version
  150.         mov    byte ptr dos_version, al
  151.         endm
  152.  
  153.  
  154.  
  155. ;-----------------------------------------------;
  156. ;                        ;
  157. ;    @@get_file_name                ;
  158. ;                        ;
  159. ;    INPUT :    NON                ;
  160. ;    OUTPUT:    si(input filename pointer)    ;
  161. ;        dl(switch character)        ;
  162. ;    ERROR :    NON                ;
  163. ;    BREAK : flags, ax            ;
  164. ;                        ;
  165. ;-----------------------------------------------;
  166.  
  167. @@get_file_name    macro
  168.         mov    ax, 3700h
  169.         int    21h            ; get switch character
  170.         mov    byte ptr switch_character, dl
  171.         cld
  172.         mov    si, 81h
  173.         call    skip_space
  174.         endm
  175.  
  176.  
  177.  
  178. ;-----------------------------------------------;
  179. ;                        ;
  180. ;    @@skip_file_name            ;
  181. ;                        ;
  182. ;    INPUT :    si(input filename pointer)    ;
  183. ;        dl(switch character)        ;
  184. ;    OUTPUT:    si(parameter list pointer)    ;
  185. ;    ERROR :    NON                ;
  186. ;    BREAK : flags, al            ;
  187. ;                        ;
  188. ;-----------------------------------------------;
  189.  
  190. @@skip_file_name    macro
  191. skip_fname_1:    lodsb
  192.         cmp    al, dl
  193.         jz    skip_fname_ret
  194.         cmp    al, 0dh
  195.         jnz    skip_fname_1
  196.  
  197. skip_fname_ret:    dec    si
  198.         endm
  199.  
  200.  
  201.  
  202. ;-----------------------------------------------;
  203. ;                        ;
  204. ;    @@get_file_name2            ;
  205. ;                        ;
  206. ;    INPUT :    NON                ;
  207. ;    OUTPUT:    bx(input filename pointer <without path name>)
  208. ;        flags                ;
  209. ;        ( ZR : no more path name )    ;
  210. ;    ERROR :    NON                ;
  211. ;    BREAK : al, si, di            ;
  212. ;                        ;
  213. ;-----------------------------------------------;
  214.  
  215. @@get_file_name2    macro
  216.         mov    di, offset save_input_filename
  217.         mov    si, word ptr save_pathname_2
  218.         call    skip_space
  219.         mov    word ptr save_pathname, si
  220. get_file_name2:    mov    bx, di
  221. get_fname2_1:    lodsb
  222.         cmp    al, byte ptr switch_character
  223.         jz    get_fname2_ret
  224.         cmp    al, 0dh
  225.         jz    get_fname2_ret
  226.         cmp    al, 9h
  227.         jz    get_fname2_ret
  228.         cmp    al, 20h
  229.         jz    get_fname2_ret
  230.         stosb
  231.         cmp    al, '/'
  232.         jz    get_file_name2
  233.         cmp    al, '\'
  234.         jz    get_file_name2
  235.         cmp    al, ':'
  236.         jz    get_file_name2
  237.         cmp    al, 81h
  238.         jc    get_fname2_1
  239.         cmp    al, 0a0h
  240.         jb    get_fname2_2
  241.         cmp    al, 0e0h
  242.         jb    get_fname2_1
  243.         cmp    al, 0fdh
  244.         jnb    get_fname2_1
  245. get_fname2_2:    movsb
  246.         jmp    get_fname2_1
  247.  
  248. get_fname2_ret:    xor    al, al
  249.         stosb
  250.         dec    si
  251.         mov    word ptr save_pathname_2, si
  252.         cmp    si, word ptr save_pathname
  253.         endm
  254.  
  255.  
  256.  
  257. ;-----------------------------------------------;
  258. ;                        ;
  259. ;    @@check_parameter            ;
  260. ;                        ;
  261. ;    INPUT :    NON                ;
  262. ;    OUTPUT:    NON                ;
  263. ;    ERROR :    error_01, error_29, error_30    ;
  264. ;    BREAK : flags, al, bx, cx, dx        ;
  265. ;                        ;
  266. ;-----------------------------------------------;
  267.  
  268. @@check_parameter    macro
  269.         mov    al, mode
  270.         or    al, al
  271.         jnz    skip_mode_default
  272.         mov    al, default_mode
  273.         mov    mode, al
  274. skip_mode_default:
  275.         cmp    al, 'r'
  276.         jz    check_restore_parameter
  277.         cmp    al, 'q'
  278.         jz    check_restore_parameter_0
  279.         mov    al, byte ptr lf_flag
  280.         or    al, byte ptr qu_flag
  281.         or    al, byte ptr it_flag
  282.         jnz    error_01
  283.         or    al, byte ptr stdin
  284.         jnz    error_32
  285.         cmp    word ptr title_length, 0
  286.         jnz    skip_title_default
  287.         mov    word ptr title_length, default_title_length - 1
  288. skip_title_default:
  289.         mov    bx, offset msdos_path
  290.         mov    cx, 7
  291. check_os_1:    cmp    byte ptr [bx], 0
  292.         jz    check_os_2
  293.         cmp    byte ptr os, 0
  294.         jnz    error_01
  295.         mov    os, cl
  296. check_os_2:    add    bx, 129d
  297.         loop    check_os_1
  298.         cmp    byte ptr os, 0
  299.         mov    al, '\'
  300.         jz    set_default_os_store
  301.         jmp    check_parameter_ret
  302. ;
  303. check_restore_parameter_0:
  304.         @@check_stderr
  305. check_restore_parameter:
  306.         mov    ax, word ptr title_length
  307.         or    al, byte ptr n_flag
  308.         or    al, byte ptr prefix_count
  309.         or    ax, mv_num
  310.         jnz    error_01
  311.         cmp    lf_flag, 0
  312.         jnz    do_lf_patch
  313.         mov    al, 5            ; add ax, XXXX
  314.         mov    word ptr lf_flag_patch_1, ax
  315.         mov    byte ptr lf_flag_patch_1[2], al
  316.         jmp    do_lf_patch_1
  317.  
  318. do_lf_patch:    mov    ax, 0c3f8h        ; clc & ret
  319.         mov    word ptr lf_flag_patch_2, ax
  320. do_lf_patch_1:    mov    al, msdos_path
  321.         or    al, cpm_path
  322.         or    al, os9_path
  323.         or    al, unix_path
  324.         or    al, mac_path
  325.         or    al, other_os_path
  326.         or    al, all_os_path
  327.         jnz    check_parameter_ret
  328.         mov    al, '\'
  329.         cmp    mode, 'q'
  330.         jnz    set_default_os_restore
  331.         mov    cpm_path, al
  332.         mov    os9_path, al
  333.         mov    unix_path, al
  334.         mov    mac_path, al
  335.         mov    other_os_path, al
  336. set_default_os_restore:
  337.         mov    all_os_path, al
  338. set_default_os_store:
  339.         mov    msdos_path, al
  340. check_parameter_ret:
  341.         endm
  342.  
  343.  
  344.  
  345. ;-----------------------------------------------;
  346. ;                        ;
  347. ;    @@disp_start_msg            ;
  348. ;                        ;
  349. ;    INPUT :    NON                ;
  350. ;    OUTPUT:    NON                ;
  351. ;    ERROR :    NON                ;
  352. ;    BREAK : flags, ax, dx            ;
  353. ;                        ;
  354. ;-----------------------------------------------;
  355.  
  356. @@disp_start_msg    macro
  357.         @@display    msg_start2
  358.         mov    al, mode
  359.         mov    dx, offset msg_restore
  360.         cmp    al, 'r'
  361.         jz    disp_start_msg_1
  362. ;        mov    dx, offset msg_all
  363. ;        cmp    al, 'a'
  364. ;        jz    disp_start_msg_1
  365.         mov    dx, offset msg_question
  366.         cmp    al, 'q'
  367.         jz    disp_start_msg_1
  368.         mov    dx, offset msg_store_8
  369.         cmp    al, '8'
  370.         jz    disp_start_msg_1
  371.         mov    dx, offset msg_store_8_o
  372.         cmp    al, '8' + 80h
  373.         jz    disp_start_msg_1
  374.         mov    dx, offset msg_store_7
  375.         cmp    al, '7'
  376.         jz    disp_start_msg_1
  377.         mov    dx, offset msg_store_s
  378.         cmp    al, 's'
  379.         jz    disp_start_msg_1
  380.         mov    dx, offset msg_store_s_o
  381.         cmp    al, 's' + 80h
  382.         jz    disp_start_msg_1
  383.         mov    dx, offset msg_store_n
  384.         cmp    al, 'n'
  385.         jz    disp_start_msg_1
  386.         mov    dx, offset msg_old_style
  387. disp_start_msg_1:
  388.         @@display    dx
  389.         cmp    byte ptr msdos_path, 0
  390.         jz    skip_ms_msg
  391.         @@display    m_
  392. skip_ms_msg:    cmp    byte ptr cpm_path, 0
  393.         jz    skip_cpm_msg
  394.         @@display    c_
  395. skip_cpm_msg:    cmp    byte ptr os9_path, 0
  396.         jz    skip_os9_msg
  397.         @@display    os9_
  398. skip_os9_msg:    cmp    byte ptr unix_path, 0
  399.         jz    skip_unix_msg
  400.         @@display    unix_
  401. skip_unix_msg:    cmp    byte ptr mac_path, 0
  402.         jz    skip_mac_msg
  403.         @@display    mac_
  404. skip_mac_msg:    cmp    byte ptr other_os_path, 0
  405.         jz    skip_other_msg
  406.         @@display    question_
  407. skip_other_msg:    cmp    byte ptr all_os_path, 0
  408.         jz    skip_all_msg
  409.         @@display    aster_
  410. skip_all_msg:    @@display    msg_
  411.         endm
  412.  
  413.  
  414.  
  415. ;-----------------------------------------------;
  416. ;                        ;
  417. ;    @@check_prefix                ;
  418. ;                        ;
  419. ;    INPUT :    NON                ;
  420. ;    OUTPUT:    NON                ;
  421. ;    ERROR :    error_20            ;
  422. ;    BREAK : flags, ax, bx, cx, dx, si    ;
  423. ;                        ;
  424. ;-----------------------------------------------;
  425.  
  426. @@check_prefix    macro
  427.         cmp    byte ptr prefix_count, 0
  428.         jz    check_prefix_ret
  429.         xor    ah, ah
  430.         mov    cx, 7
  431.         mov    si, offset prefix_char
  432. check_prefix_1:    lodsb
  433.         mov    bx, ax
  434.         cmp    byte ptr ds:[bx][offset prefix_table], 0
  435.         loopnz    check_prefix_1
  436.         jnz    error_20
  437.         mov    bl, al
  438.         @@display    msg_prefix_1
  439.         mov    byte ptr prefix_count, bl
  440.         @@dispchr    bl
  441.         @@display msg_prefix_2
  442.         mov    si, offset prefix_table
  443.         mov    dl, 0
  444. check_prefix_2:    lodsb
  445.         push    dx
  446.         or    al, al
  447.         jz    check_prefix_4
  448.         cmp    dl, 21h
  449.         jc    make_visible
  450.         cmp    dl, '\'
  451.         jz    make_visible
  452.         cmp    dl, 7fh
  453.         jc    check_prefix_3
  454.         cmp    dl, 0a1h
  455.         jc    make_visible
  456.         cmp    dl, 0e0h
  457.         jc    check_prefix_3
  458. make_visible:    @@hex_disp    dl
  459.         jmp    check_prefix_4
  460.  
  461. check_prefix_3:    @@dispchr    dl
  462. check_prefix_4:    pop    dx
  463.         inc    dl
  464.         jnz    check_prefix_2
  465.         @@display    msg_prefix_3
  466. check_prefix_ret:
  467.         endm
  468.  
  469.  
  470.  
  471. ;-----------------------------------------------;
  472. ;                        ;
  473. ;    @@open_input_file_and_get_file_size    ;
  474. ;                        ;
  475. ;    INPUT :    dx(input filenam)        ;
  476. ;    OUTPUT:    NON                ;
  477. ;    ERROR :    error_03, error_04, error_05,    ;
  478. ;        error_06            ;
  479. ;    BREAK : flags, ax, bx, cx, dx        ;
  480. ;                        ;
  481. ;-----------------------------------------------;
  482.  
  483. @@open_input_file_and_get_file_size    macro
  484.         mov    ax, 3d00h
  485.         int    21h        ; open input_file
  486.         jnc    open_infile_1
  487.         cmp    al, 2
  488.         jnz    error_04
  489.         jmp    error_03
  490.  
  491. open_infile_1:    mov    read_handler, ax
  492.         mov    bx, ax
  493.         mov    ax, 4202h
  494.         xor    cx, cx
  495.         xor    dx, dx
  496.         push    bx
  497.         push    cx
  498.         int    21h        ; get input_file size
  499.         jc    error_05
  500.         pop    cx
  501.         pop    bx
  502.         mov    word ptr work_table[2], ax
  503.         mov    word ptr work_table[4], dx
  504.         or    ax, dx
  505.         jz    error_06
  506.         mov    ax, 4200h
  507.         xor    dx, dx
  508.         int    21h        ; move file pointer (rewind)
  509.         jc    error_05
  510.         endm
  511.  
  512.  
  513.  
  514. ;-----------------------------------------------;
  515. ;                        ;
  516. ;    @@check_cpu_and_patch            ;
  517. ;                        ;
  518. ;    INPUT :    NON                ;
  519. ;    OUTPUT:    NON                ;
  520. ;    ERROR :    NON                ;
  521. ;    BREAK : flags, ax, cx            ;
  522. ;                        ;
  523. ;-----------------------------------------------;
  524.  
  525. @@check_cpu_and_patch    macro
  526.         cmp    not_v30, 0
  527.         jnz    non_v30
  528.         mov    cx, 33d
  529.         mov    ax, 1
  530.         rcr    ax, cl
  531.         jc    non_v30        ; if 80186 or 80286 then non_v30
  532.         xor    cl, cl
  533.         push    cs
  534.             db      0fh, 33h, 0c9h    ; if V30      ext cl, cl
  535.                     ; else if uPD9002 xor cx, cx (?)
  536.                     ; else          pop cs ; xor cx, cx
  537.         dec    cl
  538.         jz    v30
  539. non_v30:    mov    ax, offset emulate_ext_dl_5
  540.         mov    address_emu_ext_dl_5, ax
  541.         mov    ax, offset emulate_ext_dl_6
  542.         mov    address_emu_ext_dl_6, ax
  543.         mov    ax, offset emulate_ext_dl_12
  544.         mov    address_emu_ext_dl_12, ax
  545.         mov    ax, offset emulate_ext_dl_13
  546.         mov    address_emu_ext_dl_13, ax
  547.         mov    ax, offset emulate_ext_dl_14
  548.         mov    address_emu_ext_dl_14, ax
  549.         mov    ax, offset emulate_ins_dl_5
  550.         mov    address_emu_ins_dl_5, ax
  551.         mov    ax, offset emulate_ins_dl_6
  552.         mov    address_emu_ins_dl_6, ax
  553.         mov    ax, offset emulate_ins_dl_12
  554.         mov    address_emu_ins_dl_12, ax
  555.         mov    ax, offset emulate_ins_dl_13
  556.         mov    address_emu_ins_dl_13, ax
  557.         mov    ax, offset emulate_ins_dl_14
  558.         mov    address_emu_ins_dl_14, ax
  559.         mov    ax, 16ffh    ; call [xxxx]
  560.         mov    word ptr ext_dl_5_1, ax
  561.         mov    word ptr ext_dl_5_2, ax
  562.         mov    word ptr ext_dl_5_3, ax
  563.         mov    word ptr ext_dl_6_1, ax
  564.         mov    word ptr ext_dl_6_2, ax
  565.         mov    word ptr ext_dl_6_3, ax
  566.         mov    word ptr ext_dl_6_4, ax
  567.         mov    word ptr ext_dl_6_5, ax
  568.         mov    word ptr ext_dl_12_1, ax
  569.         mov    word ptr ext_dl_12_2, ax
  570.         mov    word ptr ext_dl_13_1, ax
  571.         mov    word ptr ext_dl_14_1, ax
  572.         mov    word ptr ins_dl_5_1, ax
  573.         mov    word ptr ins_dl_5_2, ax
  574.         mov    word ptr ins_dl_5_3, ax
  575.         mov    word ptr ins_dl_6_1, ax
  576.         mov    word ptr ins_dl_6_2, ax
  577.         mov    word ptr ins_dl_6_3, ax
  578.         mov    word ptr ins_dl_6_4, ax
  579.         mov    word ptr ins_dl_6_5, ax
  580.         mov    word ptr ins_dl_12_1, ax
  581.         mov    word ptr ins_dl_12_2, ax
  582.         mov    word ptr ins_dl_13_1, ax
  583.         mov    word ptr ins_dl_13_2, ax
  584.         mov    word ptr ins_dl_14_1, ax
  585.         mov    ax, offset address_emu_ext_dl_5
  586.         mov    word ptr ext_dl_5_1[2], ax
  587.         mov    word ptr ext_dl_5_2[2], ax
  588.         mov    word ptr ext_dl_5_3[2], ax
  589.         mov    ax, offset address_emu_ext_dl_6
  590.         mov    word ptr ext_dl_6_1[2], ax
  591.         mov    word ptr ext_dl_6_2[2], ax
  592.         mov    word ptr ext_dl_6_3[2], ax
  593.         mov    word ptr ext_dl_6_4[2], ax
  594.         mov    word ptr ext_dl_6_5[2], ax
  595.         mov    ax, offset address_emu_ext_dl_12
  596.         mov    word ptr ext_dl_12_1[2], ax
  597.         mov    word ptr ext_dl_12_2[2], ax
  598.         mov    ax, offset address_emu_ext_dl_13
  599.         mov    word ptr ext_dl_13_1[2], ax
  600.         mov    ax, offset address_emu_ext_dl_14
  601.         mov    word ptr ext_dl_14_1[2], ax
  602.         mov    ax, offset address_emu_ins_dl_5
  603.         mov    word ptr ins_dl_5_1[2], ax
  604.         mov    word ptr ins_dl_5_2[2], ax
  605.         mov    word ptr ins_dl_5_3[2], ax
  606.         mov    ax, offset address_emu_ins_dl_6
  607.         mov    word ptr ins_dl_6_1[2], ax
  608.         mov    word ptr ins_dl_6_2[2], ax
  609.         mov    word ptr ins_dl_6_3[2], ax
  610.         mov    word ptr ins_dl_6_4[2], ax
  611.         mov    word ptr ins_dl_6_5[2], ax
  612.         mov    ax, offset address_emu_ins_dl_12
  613.         mov    word ptr ins_dl_12_1[2], ax
  614.         mov    word ptr ins_dl_12_2[2], ax
  615.         mov    ax, offset address_emu_ins_dl_13
  616.         mov    word ptr ins_dl_13_1[2], ax
  617.         mov    word ptr ins_dl_13_2[2], ax
  618.         mov    ax, offset address_emu_ins_dl_14
  619.         mov    word ptr ins_dl_14_1[2], ax
  620. v30:        mov    sp, offset end_of_stack
  621.         endm
  622.  
  623.  
  624.  
  625. ;-----------------------------------------------;
  626. ;                        ;
  627. ;    @@write                    ;
  628. ;                        ;
  629. ;    INPUT :    cx (length)            ;
  630. ;        dx (pointer)            ;
  631. ;    OUTPUT:    ax (length of write)        ;
  632. ;        flags (NC: ok)            ;
  633. ;              (CY: end of file or error);
  634. ;    ERROR :    error_33            ;
  635. ;    BREAK :    flags                ;
  636. ;                        ;
  637. ;-----------------------------------------------;
  638.  
  639. @@write        macro
  640.         xor    ax, ax
  641.         push    es
  642.         push    si
  643.         push    di
  644.         push    dx
  645.         mov    si, 0
  646. _write_buffer_seg_1 equ    $-2
  647.         mov    es, si
  648.         mov    si, dx
  649. _write_1:    push    cx
  650.         cmp    disk_write_length_left, 0
  651.         jnz    _write_3
  652.         push    ax
  653.         push    bx
  654.         xor    dx, dx
  655.         mov    disk_write_ptr, dx
  656.         mov    cx, 1000h
  657. _write_buffer_length_1    equ    $-2
  658.         mov    disk_write_length_left, cx
  659.         mov    bx, write_handler
  660.         mov    ah, 40h
  661.         push    ds
  662.         push    es
  663.         pop    ds
  664.         int    21h
  665.         pop    ds
  666.         jc    _write_2
  667.         cmp    ax, cx
  668.         jnc    _write_2
  669.         cmp    byte ptr error_33_flag, 0
  670.         jnz    error_33
  671.         stc
  672. _write_2:    pop    bx
  673.         pop    ax
  674.         pop    cx
  675.         jc    _write_5
  676.         jmp    _write_1
  677.  
  678. _write_3:    sub    cx, ax
  679.         sub    disk_write_length_left, cx
  680.         jnc    _write_4
  681.         add    cx, disk_write_length_left
  682.         mov    disk_write_length_left, 0
  683. _write_4:    add    ax, cx
  684.         mov    di, disk_write_ptr
  685.         rep    movsb
  686.         mov    disk_write_ptr, di
  687.         pop    cx
  688.         cmp    disk_write_length_left, 0
  689.         jz    _write_1
  690. _write_5:    pop    dx
  691.         pop    di
  692.         pop    si
  693.         pop    es
  694.         endm
  695.  
  696.  
  697.  
  698. ;-----------------------------------------------;
  699. ;                        ;
  700. ;    @@expand_wildcards            ;
  701. ;                        ;
  702. ;    INPUT :    NON                ;
  703. ;    OUTPUT:    flags                ;
  704. ;        ( CY : not found any more )    ;
  705. ;    ERROR :    error_22, error_23        ;
  706. ;    BREAK :    ax, bx, cx, dx, si, di        ;
  707. ;                        ;
  708. ;-----------------------------------------------;
  709.  
  710. @@expand_wildcards    macro
  711.         cmp    byte ptr _dta_id, 1
  712.         jz    expand_wildcards_0
  713.         mov    ah, 1ah
  714.         mov    dx, offset _dta
  715.         int    21h            ; set DTA
  716.         mov    byte ptr _dta_id, 1
  717. expand_wildcards_0:
  718.         cmp    byte ptr wildcards_expand_flag, 0
  719.         jnz    expand_wildcards_3
  720. expand_wildcards_1:
  721.         @@get_file_name2
  722.         jz    expand_wildcards_2
  723.         mov    word ptr save_input_filename_without_path, bx
  724.         mov    ah, 4eh
  725.         mov    dx, offset save_input_filename
  726.         mov    cx, 6            ; system file & hidden file
  727.         int    21h            ; search first file
  728.         jnc    expand_wildcards_4
  729.         call    error_22
  730.         jmp    expand_wildcards_1
  731.  
  732. expand_wildcards_2:
  733.         cmp    byte ptr wildcards_expand_flag, 0
  734.         stc
  735.         jnz    expand_wildcards_ret
  736.         jmp    error_23
  737.  
  738. expand_wildcards_3:
  739.         mov    ah, 4fh
  740.         int    21h            ; search next file
  741.         jc    expand_wildcards_1
  742. expand_wildcards_4:
  743.         mov    byte ptr wildcards_expand_flag, 0ffh
  744.         mov    si, offset _dta[1eh]
  745.         mov    di, word ptr save_input_filename_without_path
  746. expand_wildcards_5:
  747.         lodsb
  748.         call    tolower
  749.         cmp    al, 81h
  750.         jc    expand_wildcards_7
  751.         cmp    al, 0a0h
  752.         jc    expand_wildcards_6
  753.         cmp    al, 0e0h
  754.         jc    expand_wildcards_7
  755.         cmp    al, 0fdh
  756.         jnc    expand_wildcards_7
  757. expand_wildcards_6:
  758.         stosb
  759.         lodsb
  760. expand_wildcards_7:
  761.         stosb
  762.         or    al, al
  763.         jnz    expand_wildcards_5
  764. expand_wildcards_ret:
  765.         endm
  766.  
  767.  
  768.  
  769. ;-----------------------------------------------;
  770. ;                        ;
  771. ;    @@all_close                ;
  772. ;                        ;
  773. ;    INPUT :    NON                ;
  774. ;    OUTPUT:    NON                ;
  775. ;    ERROR :    error_05, error_09        ;
  776. ;    BREAK :    flags, ax, bx            ;
  777. ;                        ;
  778. ;-----------------------------------------------;
  779.  
  780. @@all_close    macro
  781.         mov    bx, read_handler
  782.         or    bx, bx
  783.         jz    skip_close_inputfile
  784.         mov    ah, 3eh
  785.         int    21h
  786.         jc    error_05
  787.         mov    word ptr read_handler, 0
  788. skip_close_inputfile:
  789.         mov    bx, write_handler
  790.         cmp    bx, 2
  791.         jc    skip_close_outputfile
  792.         mov    ah, 3eh
  793.         int    21h
  794.         jc    error_09
  795.         mov    word ptr write_handler, 0
  796. skip_close_outputfile:
  797.         endm
  798.  
  799.  
  800.  
  801. ;-----------------------------------------------;
  802. ;                        ;
  803. ;    @@init_constants2            ;
  804. ;                        ;
  805. ;    INPUT :    NON                ;
  806. ;    OUTPUT:    NON                ;
  807. ;    ERROR :    NON                ;
  808. ;    BREAK :    NON                ;
  809. ;                        ;
  810. ;-----------------------------------------------;
  811.  
  812. @@init_constants2    macro
  813.         mov    word ptr max_division, 0
  814.         mov    word ptr disk_read_length, 0
  815.         endm
  816.  
  817.  
  818.  
  819. ;-----------------------------------------------;
  820. ;                        ;
  821. ;    @@disp_input_fname            ;
  822. ;                        ;
  823. ;    INPUT :    dx (filename)            ;
  824. ;    OUTPUT:    NON                ;
  825. ;    ERROR :    NON                ;
  826. ;    BREAK : flags, ax, si            ;
  827. ;                        ;
  828. ;-----------------------------------------------;
  829.  
  830. @@disp_input_fname    macro
  831.         push    dx
  832.         mov    si, dx
  833.         mov    ah, 0
  834. disp_input_fname_1:
  835.         call    lodsb_tolower_new
  836.         or    al, al
  837.         jz    disp_input_fname_2
  838.         @@dispchr    al
  839.         jmp    disp_input_fname_1
  840.  
  841. disp_input_fname_2:
  842.         @@display    msg_colon2
  843.         pop    dx
  844.         endm
  845.  
  846.  
  847.  
  848. ;-----------------------------------------------;
  849. ;                        ;
  850. ;    @@check_stdin                ;
  851. ;                        ;
  852. ;    INPUT :    NON                ;
  853. ;    OUTPUT:    NON                ;
  854. ;    ERROR :    NON                ;
  855. ;    BREAK : flags, ax, bx, dx        ;
  856. ;                        ;
  857. ;-----------------------------------------------;
  858.  
  859. @@check_stdin    macro
  860.         mov    ax, 4400h
  861.         mov    bx, 0
  862.         int    21h
  863.         jc    error_29
  864.         and    dx, 81h
  865.         cmp    dx, 81h
  866.         jz    error_31
  867.         mov    byte ptr stdin, 0ffh
  868.         endm
  869.  
  870.  
  871.  
  872. ;-----------------------------------------------;
  873. ;                        ;
  874. ;    @@check_stdout                ;
  875. ;                        ;
  876. ;    INPUT :    NON                ;
  877. ;    OUTPUT:    NON                ;
  878. ;    ERROR :    NON                ;
  879. ;    BREAK : flags, ax, bx, dx        ;
  880. ;                        ;
  881. ;-----------------------------------------------;
  882.  
  883. @@check_stdout    macro
  884.         mov    ax, 4400h
  885.         mov    bx, 1
  886.         int    21h
  887.         jc    error_29
  888.         mov    ax, dx
  889.         and    dx, 82h
  890.         cmp    dx, 82h
  891.         jz    check_stdout_1
  892.         mov    byte ptr stdout, 0ffh
  893. check_stdout_1:    test    al, 80h
  894.         jz    check_stdout_2
  895.         test    al, 20h
  896.         jnz    check_stdout_2
  897.         xor    ah, ah
  898.         mov    byte ptr error_33_flag, al
  899. check_stdout_2:
  900.         endm
  901.  
  902.  
  903.  
  904. ;-----------------------------------------------;
  905. ;                        ;
  906. ;    @@check_stderr                ;
  907. ;                        ;
  908. ;    INPUT :    NON                ;
  909. ;    OUTPUT:    NON                ;
  910. ;    ERROR :    NON                ;
  911. ;    BREAK : flags, ax, bx, dx        ;
  912. ;                        ;
  913. ;-----------------------------------------------;
  914.  
  915. @@check_stderr    macro
  916.         mov    ax, 4400h
  917.         mov    bx, 2
  918.         int    21h
  919.         jc    error_29
  920.         and    dx, 83h
  921.         cmp    dx, 83h
  922.         jnz    error_30
  923.         endm
  924.  
  925.  
  926.  
  927. ;-----------------------------------------------;
  928. ;                        ;
  929. ;    @@disp_and_set_stdout            ;
  930. ;                        ;
  931. ;    INPUT :    NON                ;
  932. ;    OUTPUT:    NON                ;
  933. ;    ERROR :    NON                ;
  934. ;    BREAK : flags, ax, bx, dx        ;
  935. ;                        ;
  936. ;-----------------------------------------------;
  937.  
  938. @@disp_and_set_stdout    macro
  939.         cmp    byte ptr stdout, 0
  940.         jz    disp_and_set_stdout_skip
  941.         @@display    msg_stdout
  942.         mov    word ptr write_handler, 1
  943. disp_and_set_stdout_skip:
  944.         endm
  945.  
  946.  
  947.  
  948. ;-----------------------------------------------;
  949. ;                        ;
  950. ;    @@get_ishopt_fname            ;
  951. ;                        ;
  952. ;    INPUT :    NON                ;
  953. ;    OUTPUT:    NON                ;
  954. ;    ERROR :    error_34            ;
  955. ;    BREAK : flags, ax, cx, si, di        ;
  956. ;                        ;
  957. ;-----------------------------------------------;
  958.  
  959. @@get_ishopt_fname    macro
  960.         mov    si, offset ishopt
  961.         call    search_env
  962.         jz    get_ishopt_fname_1
  963.         cmp    byte ptr es:dos_version, 3
  964.         jc    get_ishopt_fname_2
  965.         inc    si
  966.         lodsw
  967.         cmp    ax, 1
  968.         jnz    get_ishopt_fname_2
  969.         call    get_ishopt_fname_sub
  970.         mov    word ptr [di-4], 'po'
  971.         mov    byte ptr [di-2], 't'
  972.         jmp    get_ishopt_fname_2
  973.  
  974. get_ishopt_fname_1:
  975.         call    get_ishopt_fname_sub
  976. get_ishopt_fname_2:
  977.         mov    ax, es
  978.         mov    ds, ax
  979.         endm
  980.  
  981.  
  982.  
  983. ;-----------------------------------------------;
  984. ;                        ;
  985. ;    @@cmp_tag                ;
  986. ;                        ;
  987. ;    INPUT :    bx (handle)            ;
  988. ;    OUTPUT:    flags (ZR: compare OK)        ;
  989. ;              (NZ: compare NG)        ;
  990. ;    ERROR :    error_38            ;
  991. ;    BREAK : flags, ax, cx, dx, si        ;
  992. ;                        ;
  993. ;-----------------------------------------------;
  994.  
  995. @@cmp_tag    macro
  996.         mov    di, offset tag
  997.         cmp    byte ptr [di], 0
  998.         jnz    cmp_tag_1
  999.         mov    di, offset default_tag
  1000.         mov    ah, byte ptr mode
  1001.         or    ah, ah
  1002.         jz    cmp_tag_1
  1003.         mov    byte ptr default_tag_mode, 'r'
  1004.         cmp    ah, 'r'
  1005.         jz    cmp_tag_1
  1006.         cmp    ah, 'q'
  1007.         jz    cmp_tag_1
  1008.         mov    byte ptr default_tag_mode, 's'
  1009. cmp_tag_1:    scasb
  1010.         jnz    cmp_tag_ret
  1011.         cmp    al, ':'
  1012.         jz    cmp_tag_ret
  1013.         call    get_para_char
  1014.         jc    cmp_tag_ret
  1015.         jmp    cmp_tag_1
  1016.  
  1017. cmp_tag_ret:
  1018.         endm
  1019.  
  1020.  
  1021.  
  1022. ;-----------------------------------------------;
  1023. ;                        ;
  1024. ;    @@get_parameter                ;
  1025. ;                        ;
  1026. ;    INPUT :    si(parameter list pointer)    ;
  1027. ;        dl(switch character)        ;
  1028. ;    OUTPUT:    di(input filename end pointer)    ;
  1029. ;    ERROR :    error_01, error_15, error_34,    ;
  1030. ;        error_35, error_36, error_37,    ;
  1031. ;        error_38            ;
  1032. ;    BREAK : flags, ax, bx, cx, si, bp    ;
  1033. ;                        ;
  1034. ;-----------------------------------------------;
  1035.  
  1036. @@get_parameter    macro
  1037.         call    get_parameter
  1038.         push    di
  1039.         cmp    byte ptr tag, ':'
  1040.         jz    get_parameter_ret
  1041.         push    dx
  1042.         @@get_ishopt_fname
  1043.         mov    ax, 3d00h
  1044.         mov    dx, offset ishopt_fname
  1045.         int    21h
  1046.         jc    ishopt_open_error
  1047.         mov    bx, ax
  1048. search_tag:    call    get_para_char
  1049.         jc    tag_not_found
  1050.         cmp    al, ' '+1
  1051.         jc    skip_until_crlf_1
  1052.         cmp    al, '#'
  1053.         jz    skip_until_crlf
  1054.         @@cmp_tag
  1055.         jz    copy_para_to_buffer
  1056. skip_until_crlf:
  1057.         call    get_para_char
  1058.         jc    tag_not_found
  1059. skip_until_crlf_1:
  1060.         cmp    al, 0dh
  1061.         jz    search_tag
  1062.         cmp    al, 0ah
  1063.         jz    search_tag
  1064.         jmp    skip_until_crlf
  1065.  
  1066. ishopt_open_error:
  1067.         cmp    byte ptr tag, 0
  1068.         jnz    error_35
  1069.         jmp    get_parameter_ret_0
  1070.  
  1071. tag_not_found:    cmp    byte ptr tag, 0
  1072.         jnz    error_37
  1073. get_parameter_ret_0:
  1074.         pop    dx
  1075.         jmp    get_parameter_ret
  1076.  
  1077. copy_para_to_buffer:
  1078.         mov    di, offset write_buffer
  1079. copy_para_to_buffer_1:
  1080.         call    get_para_char
  1081.         jc    copy_para_to_buffer_end
  1082.         cmp    al, 0dh
  1083.         jz    copy_para_to_buffer_2
  1084.         cmp    al, 0ah 
  1085.         jz    copy_para_to_buffer_2
  1086.         stosb
  1087.         cmp    di, offset write_buffer + 80d*72d
  1088.         jnc    error_36
  1089.         jmp    copy_para_to_buffer_1
  1090.  
  1091. copy_para_to_buffer_3:
  1092.         call    get_para_char
  1093.         jc    copy_para_to_buffer_end
  1094.         cmp    al, 0dh
  1095.         jz    copy_para_to_buffer_2
  1096.         cmp    al, 0ah
  1097.         jz    copy_para_to_buffer_2
  1098.         jmp    copy_para_to_buffer_3
  1099.  
  1100. copy_para_to_buffer_2:
  1101.         call    get_para_char
  1102.         jc    copy_para_to_buffer_end
  1103.         cmp    al, '#'
  1104.         jz    copy_para_to_buffer_3
  1105.         cmp    al, 0dh
  1106.         jz    copy_para_to_buffer_2
  1107.         cmp    al, 0ah
  1108.         jz    copy_para_to_buffer_2
  1109.         cmp    al, ' '+1
  1110.         jc    copy_para_to_buffer_1
  1111.         jmp    copy_para_to_buffer_end
  1112.  
  1113. copy_para_to_buffer_end:
  1114.         mov    al, 0dh
  1115.         stosb
  1116.         mov    ah, 3eh
  1117.         int    21h
  1118.         jc    ishopt_open_error
  1119.         mov    byte ptr tag, ':'
  1120.         mov    si, offset write_buffer
  1121.         pop    dx
  1122.         call    get_parameter
  1123. get_parameter_ret:
  1124.         pop    di
  1125.         endm
  1126.  
  1127.  
  1128.  
  1129. ;-----------------------------------------------;
  1130. ;                        ;
  1131. ;    @@set_int_23h                ;
  1132. ;                        ;
  1133. ;    INPUT :    NON                ;
  1134. ;    OUTPUT:    NON                ;
  1135. ;    ERROR :    NON                ;
  1136. ;    BREAK : flags, ax, dx            ;
  1137. ;                        ;
  1138. ;-----------------------------------------------;
  1139.  
  1140. @@set_int_23h    macro
  1141.         mov    ax, 2523h
  1142.         mov    dx, offset int_23h_handler
  1143.         int    21h
  1144.         call    set_break_on
  1145.         endm
  1146.  
  1147.  
  1148.  
  1149. ;-----------------------------------------------;
  1150. ;                        ;
  1151. ;    @@int_23h_handler            ;
  1152. ;                        ;
  1153. ;    INPUT :    NON                ;
  1154. ;    OUTPUT:    NON                ;
  1155. ;    ERROR :    abend                ;
  1156. ;    BREAK : NON                ;
  1157. ;                        ;
  1158. ;-----------------------------------------------;
  1159.  
  1160. @@int_23h_handler    macro
  1161. int_23h_handler:
  1162.         cmp    byte ptr cs:abort_flag, 0ffh
  1163.         jz    int_23h_handler_ret
  1164.         mov    ax, cs
  1165.         mov    ds, ax
  1166.         mov    es, ax
  1167.         mov    byte ptr abort_flag, 0ffh
  1168.         mov    ax, 3301h
  1169.         mov    dl, 0
  1170.         int    21h
  1171.         cmp    byte ptr mode, 'r'
  1172.         jz    int_23h_handler_1
  1173.         cmp    byte ptr mode, 'q'
  1174.         jz    int_23h_handler_1
  1175.         jmp    abend
  1176.  
  1177. int_23h_handler_1:
  1178.         cmp    word ptr write_handler, 1
  1179.         jbe    abend
  1180.         call    close_and_delete
  1181.         jmp    abend
  1182.  
  1183. int_23h_handler_ret:
  1184.         iret
  1185.         endm
  1186.  
  1187.  
  1188.  
  1189. ;-----------------------------------------------;
  1190. ;                        ;
  1191. ;    @@set_shell_name            ;
  1192. ;                        ;
  1193. ;    INPUT :    NON                ;
  1194. ;    OUTPUT:    NON                ;
  1195. ;    ERROR :    error_29, error_43        ;
  1196. ;    BREAK : flags, ax, bx, cx, dx, si, di    ;
  1197. ;                        ;
  1198. ;-----------------------------------------------;
  1199.  
  1200. @@set_shell_name    macro
  1201.         cmp    byte ptr shell_escape, 0
  1202.         jz    set_shell_name_ret
  1203.         cmp    byte ptr es:dos_version, 3
  1204.         jc    set_shell_name_3
  1205.         cmp    byte ptr mode, 'q'
  1206.         jnz    set_shell_name_3
  1207.         cmp    byte ptr stdout, 0
  1208.         jnz    set_shell_name_3
  1209.         mov    ax, 4400h
  1210.         mov    bx, 0
  1211.         int    21h
  1212.         jc    error_29
  1213.         and    dx, 81h
  1214.         cmp    dx, 81h
  1215.         jnz    set_shell_name_3
  1216.         mov    si, offset comspec
  1217.         call    search_env
  1218.         jnz    set_shell_name_2
  1219.         mov    cx, 128d
  1220.         mov    di, offset shell
  1221. set_shell_name_1:
  1222.         lodsb
  1223.         stosb
  1224.         cmp    al, 0
  1225.         loopnz    set_shell_name_1
  1226.         mov    ax, es
  1227.         mov    ds, ax
  1228.         jnz    error_43
  1229.         jmp    set_shell_name_ret
  1230.  
  1231. set_shell_name_2:
  1232.         mov    ax, es
  1233.         mov    ds, ax
  1234. set_shell_name_3:
  1235.         mov    byte ptr shell_escape, 0
  1236. set_shell_name_ret:
  1237.         endm
  1238.