
; Copyright 2004-2005 Christopher Evans
; email:   tekno1911@yahoo.com
; Website: http://nxdos.sourceforge.net/
;                                                                           ;
;       This program is copyrighted, but may be freely distributed          ;
;       under the terms of the Free Software Foundation's GNU General       ;
;       Public License v2 (or later.)  See the file COPYING for the         ;
;       legalities.  If you did not receive a copy of COPYING, you          ;
;       may request one from the Free Software Foundation, Inc.,            ;
;       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           ;
;       ABSOLUTELY NO WARRANTY -- use it at your own risk!                  ;
;                                                                           ;

code            segment byte public
                assume  cs:code, ds:code
		org	100h
chksum          proc    far

start:          jmp     initialize
include         \nxdos\src\toolbox.asm
include         \nxdos\src\crclib.asm
include         \nxdos\src\kernel\dma.asm
include         \nxdos\src\kernel\floppy.asm

                _compile
initialize:
           _print program, 1
           _echo 'F'
           _echo 'i'
           _echo 'l'
           _echo 'e'
           _echo ':'
           _echo ' '
           mov  di, offset filename
           mov cx, 13
           call getdata
           _newline

           _fopen filename, 0, 1, 0
           cmp  ax, 0
           jne  openfile
           ret
openfile:
           mov  fhandle, ax
readmore:
           mov  di, offset filebuf
           mov  cx, 512
           mov  bl, 0
           call fillarray
           _fread  fhandle, filebuf, 512
           jc  done
           mov  fileind, ax
       ;    push cs
       ;    pop  es
       ;    mov  si, offset filebuf
       ;    mov  cx, 512
       ;    call debugdump
           push cs
           pop  ds
           mov  si, offset filebuf
           mov  cx, 512
           call crc16
           mov  ax, dx
           mov  bx, ax
           mov  ax, fchk
           add  ax, bx
           mov  fchk, ax
           mov  ax, fileind
           cmp ax, 0
           je  done
           jmp  readmore

done:
           _print theansweris, 1
           mov  ax, fchk
           call put_hex
           _newline
           _fclose fhandle

exitptr:        call dosexit
                int 20h      

chksum          endp
program  db 'CHKSUM - Binary check summing tool by Chris Evans.',0ffh
         db '         Use it to verify file integity... ',00ffh,0
theansweris db 'File checksum is ',0
fhandle  dw 0
fchk     dw 0
fileind  dw 0
filename db 13 dup (0), 0
filebuf  db 512 dup(0),0


code            ends

ProgramEnd      EQU $-01h

		end	start
