$LARGE
C
C     PROGRAM CHKSUM64
C
C     PURPOSE PREPARE A BINARY (.COM) FILE TO BE BURNED IN A PAIR OF
C             EPROMS FOR USE IN AN IBM AT OR COMPATIBLE COMPUTER
C
C     AUTHOR  DON GENTRY
C             183 BELLEGROVE CIRCLE
C             BRANDON, MS   39042
C             601 992 0577
C
C     USE     THE BINARY FILE MUST BE CREATED BY THE ASSEMBLER,
C             LINKAGE EDITOR, AND EXE2BIN. THE FILE WILL BE LESS
C             THAN 64K (THE SIZE OF 2 27256'S) UNLESS YOU ARE
C             MUCH MORE AMBITIOUS IN YOUR CODING EFFORTS THAN ME.
C             ONCE THIS FILE IS PREPARED, RUN CHKSUM64. YOU WILL
C             BE PROMPTED FOR THE NAME OF THE ROM IMAGE FILE YOU
C             HAVE PREPARED AND A FILE NAME FOR THE FILE TO CONTAIN
C             THE EVEN BYTES AND ANOTHER FOR THE ODD BYTES.
C
C             THE PROGRAM WILL READ YOUR BINARY FILE, CALCULATE THE
C             PROPER CHECKSUM AND THEN PRODUCE TWO OUTPUT FILES
C             CONTAINING THE EVEN BYTES AND THE ODD BYTES TO BE BURNED
C             INTO TWO 27256 EPROMS. THE ORIGINAL FILE IS EXPANDED
C             TO 64K AND THE CHECKSUM INSERTED.
C
C
C        Copyright  1986 Don Gentry
C
C        A limited license is granted to all users of this program,
C        to make copies of this program, and distribute them to
C        other users, on the following conditions:
C
C        1. The notice on this page is not to be removed or altered
C
C        2. No fee is to be charged for copying or distributing
C           the program.
C
C        3. No warranty of any kind is offered. This program is offered
C           on an "AS IS" basis. Each user should verify that it meets
C           his needs and verify correct operation.
C
C        4. No further restrictions on redristribution of any kind may
C           be required. This includes, but is not limited to,
C           COMPUSERVE or other program distribution services,
C           by electronic or other means. Free distribution MUST be
C           be preserved!
C
C        FOR HELP OR SUGGESTIONS WRITE:
C
C        DON GENTRY
C        183 BELLEGROVE CIRCLE
C        BRANDON, MS  39042
C
C        OR CALL (601) 992-0577
C
C
      CHARACTER*1 EPROM(65536),EVEN(32768),ODD(32768)
      INTEGER*2   EDATA(32768)
      CHARACTER*1 EWORK1(2)
      CHARACTER*64 FROM, FEVEN, FODD
      INTEGER*2   EWORK2, CHKSUM
      EQUIVALENCE(EWORK2,EWORK1)
      EQUIVALENCE(EPROM,EDATA)
      DATA EDATA/32768*-1/
      WRITE (*,1)
1     FORMAT('0 ENTER ROM IMAGE FILE ID')
      READ(*,2) FROM
2     FORMAT(A64)
      WRITE (*,3)
3     FORMAT('0 ENTER EVEN BYTE IMAGE FILE ID')
      READ(*,2) FEVEN
      WRITE (*,4)
4     FORMAT('0 ENTER ODD BYTE IMAGE FILE ID')
      READ(*,2) FODD
      CHKSUM = 0
      OPEN (5,FILE=FROM,STATUS='OLD',FORM='BINARY')
      OPEN (8,FILE=FEVEN,STATUS='NEW',FORM='BINARY')
      OPEN (9,FILE=FODD,STATUS='NEW',FORM='BINARY')
      READ (5,END=90) EPROM
90    CONTINUE
      DO 100 I = 1 , 65535
      EWORK2 = 0
      EWORK1(1) = EPROM(I)
      CHKSUM = CHKSUM + EWORK2
      IF (CHKSUM .GT. 255) CHKSUM = CHKSUM - 256
100   CONTINUE
      EWORK2 = 256 - CHKSUM
      EPROM(65536) = EWORK1(1)
      REWIND 5
      WRITE (5) EPROM
      K=1
      DO 200 I=1,32768
      EVEN(I)=EPROM(K)
      K=K+1
      ODD(I)= EPROM(K)
      K=K+1
200   CONTINUE
      WRITE(8) EVEN
      WRITE(9) ODD
      STOP
      END
