#11 Article 177 Posted at 1987/06/11 04:48:34 by NOZOMU (MAP041) [PRG.NL2]

Subject: NEDI for 98+MASM ソノ3

div     bx
        loop    wait0
        mov     ah,09h                  ;Display string
        mov     dx,offset cls
        int     21h
        mov     ax,0ffffh

exit_read:
        pop     si
        pop     di
        pop     dx
        pop     cx
        pop     bx

        pop     bp

        ret     4

read    endp

;--------------------------------------
;
;       write(file_name,logial_page)
;
;       char    *file_name,*logical_page
;
;--------------------------------------
public  write

write   proc    near

        push    bp
        mov     bp,sp

        push    bx
        push    cx
        push    dx
        push    di
        push    si

        mov     ah,65                   ;Prohibit to display graphic
        int     24

        mov     ah,3ch                  ;file create
        mov     cx,20h                  ;normal file
        mov     dx,[bp].fn
        int     21h
        jnb     create_succeed
        jmp     error2

create_succeed:
        mov     si,[bp].lp
        mov     di,offset write_buffer
        mov     bx,ax                   ;file handle
        mov     length_,0
        mov     xw,0
        mov     yw,0

        mov     ax,[bp].lp
        push    ax
        push    yw
        push    xw
        call    point

        shl     ax,1
        shl     ax,1
        shl     ax,1
        mov     colour,ax

        mov     ax,[bp].lp
        push    ax
        inc     yw
        push    yw
        push    xw
        call    point

        inc     yw
        add     colour,ax

loop_write_1:
        mov     counter,1

loop_write_0:
        cmp     yw,96
        jb      not_bottom
        mov     yw,0
        inc     xw
        cmp     xw,160
        jae     write_end

not_bottom:
        mov     ax,[bp].lp
        push    ax
        push    yw
        push    xw
        call    point

        shl     ax,1
        shl     ax,1
        shl     ax,1
        mov     next_colour,ax

        mov     ax,[bp].lp
        push    ax
        inc     yw
        push    yw
        push    xw
        call    point

        inc     yw
        add     ax,next_colour
        mov     next_colour,ax

        cmp     ax,colour
        jne     write_end

        cmp     counter,161
        jae     write_end
        inc     counter
        jmp     short loop_write_0

write_end:
        cmp     counter,1
        jne     write_2byte

        mov     ax,colour
        add     al,20h
        cmp     al,80h
        jb      not_adjust
        add     al,20h
not_adjust:
        mov     [di],al
        inc     di
        inc     length_
        jmp     short not_press2

write_2byte:
        mov     ax,colour
        or      al,01000000b
        add     al,20h
        cmp     al,80h
        jb      not_adjust2
        add     al,20h
not_adjust2:
        mov     [di],al
        inc     di
        mov     ax,counter
        dec     ax
        dec     ax
        add     al,20h
        cmp     al,80h
        jb      not_adjust3
        add     al,20h
not_adjust3:
        mov     [di],al
        inc     di
        inc     length_
        inc     length_

not_press2:
        cmp     length_,78
        jb      not_cr
        mov     length_,0
        mov     ax,0a0dh
        mov     [di],ax
        inc     di
        inc     di

not_cr:
        cmp     xw,160
        jae     write_file
        mov     ax,next_colour
        mov     colour,ax
        jmp     loop_write_1

write_file:
        mov     byte ptr [di],1ah
        inc     di
        mov     ah,40h          ;write to file
        ;       bx = file handle
        mov     cx,di
        sub     cx,offset write_buffer  ;data length
        mov     dx,offset write_buffer  ;buffer address
        int     21h

        mov     ah,3eh                  ;Close file
        int     21h

        mov     ax,0
        jmp     short exit_write

error2:
        mov     ah,09h                  ;Display string
        mov     dx,offset cls
        int     21h
        mov     ah,09h                  ;Display string
        mov     dx,offset error_message
        int     21h
        mov     cx,0ffffh
wait1:  mov     ax,0001h
        mov     dx,0000h
        mov     bx,1
        div     bx
        loop    wait1
        mov     ah,09h                  ;Display string
        mov     dx,offset cls
        int     21h
        mov     ax,0ffffh

exit_write:
        pop     si
        pop     di
        pop     dx
        pop     cx
        pop     bx

        pop     bp

        ret     4

write   endp