.model  tiny
.386
.code
org     100h

code_begin      label   near
        mov     ah, 9
        mov     dx, offset message
        int     21h
        mov     ah, 4ah
        mov     bx, ((offset code_end - offset code_begin) + 20fh) shr 4
        mov     sp, ((offset code_end - offset code_begin) + 1ffh) and -2
        int     21h
        mov     ax, 352eh
        int     21h
        push    es
        push    bx
        pop     dword ptr ds:[offset jfar_2eh + 1]
        mov     ah, 25h
        mov     dx, offset new_2eh
        int     21h
        mov     ax, 3521h
        int     21h
        push    es
        push    bx
        pop     ebx
        mov     dword ptr ds:[offset jfar_n21h + 1], ebx
        mov     dword ptr ds:[offset jfar_o21h + 1], ebx
        mov     ah, 25h
        mov     dx, offset new_21h
        int     21h
        push    ds
        pop     es
        mov     bx, offset exec_block
        mov     word ptr ds:[bx + 4], cs
        mov     word ptr ds:[bx + 8], cs
        mov     word ptr ds:[bx + 0ch], cs
        mov     dword ptr ds:[bx + 0fh], "  c/"
        mov     ax, 4b00h
        mov     dx, offset pcliga_com
        int     21h
        mov     ax, 2521h
        lds     dx, dword ptr ds:[offset jfar_o21h + 1]
        pushf
        push    cs
        call    jfar_o21h
        mov     al, 2eh
        lds     dx, dword ptr cs:[offset jfar_2eh + 1]
        int     21h
        mov     ah, 4ch
        int     21h

new_2eh         proc    near
        push    ds
        push    es
        pusha
        push    cs
        pop     es
        mov     bx, offset exec_block
        mov     si, dx
        lea     di, word ptr [bx + 0eh]
        mov     word ptr cs:[bx + 2], di
        lodsb
        cbw
        mov     cx, ax
        add     al, 4
        stosb
        scasd
        rep     movsb
        push    cs
        pop     ds
        mov     ax, 4b00h
        mov     dx, offset command_com
        int     21h
        popa
        pop     es
        pop     ds
        iret

jfar_2eh        db      0eah, 'P', 'F', 'P', 'F'
new_2eh         endp

new_21h         proc    near
        cmp     ax, 3521h
        je      fake_21h
        cmp     ax, 2521h
        je      hook_21h
        cmp     ah, 4ch
        jne     jfar_n21h
        cmp     sp, 3fah
        je      jfar_o21h

jfar_n21h       label   near
                db      0eah, 'P', 'F', 'P', 'F'

jfar_o21h       label   near
                db      0eah, 'P', 'F', 'P', 'F'

fake_21h        label   near
        les     bx, dword ptr cs:[offset jfar_o21h + 1]
        iret

hook_21h        label   near
        push    ds
        push    dx
        pop     dword ptr cs:[offset jfar_n21h + 1]
        iret
new_21h         endp

pcliga_com      db      "pcliga.com", 0
command_com     db      "z:\command.com", 0
exec_block      dw      0, 80h, 0, 5ch, 0, 6ch, 0

message         db "DOSBox fix for PC Liga", 0dh, 0ah
                db "by Peter Ferrie (peter_ferrie@hotmail.com)", 0dh, 0ah, "$"

                db 80h - (offset $ - offset message) dup (?)
code_end        label   near
end             code_begin
