!pr1
Practical Application of CRC....................Don Rindsberg

When I read Bob S-C's article on CRC in the February 1986 AAL, I said, "Very interesting, but who needs it".  Well, it wasn't long before I ran into a real need myself!

I bought a used IBM PC-Jr and wanted to put my own routines in an auto-start ROM cartridge.  After some sleuthing, I found that the power-up routine checks for signature bytes.  If they are present, the routine checks the ROM's CRC, which must be $0000 or the machine locks up.

Not knowing the 65802 opcodes that Bob used, and being quite familiar with the 8088 language, I decided to translate the PC-Jr's CRC routine from "8088 dis-assembly language" to "plain vanilla 6502-ese".  I simulated the 8088's registers with Apple RAM, and wrote subroutines for some of the 16-bit 8088 instructions.

Now here's what I think is strange about CRC's.  If you pass all bytes of a set of data through the CRC generator and then the two CRC bytes themselves, the total CRC result is $0000!  The PC-Jr add-on ROMs have the program in all except the last two bytes and the CRC of the program in those last two, so the total CRC for the entire ROM is $0000.

My 6502 code requires you to enter the start in Apple RAM and the length of the ROM data.  For example, for a program starting at $2000 in Apple RAM, destined to be blown into a 2716 EPROM (2048 bytes), you would enter an address of $2000 and a length of $0800.  These two values go into the first four bytes of the Apple zero page, so you can use a monitor instruction from inside the S-C Assembler like this:

       :$00:00 20 00 08

My program runs a CRC calculation on all but the last two bytes, and then prints out what the resulting CRC code is.  If you store the CRC value in the last two bytes of the ROM image, add two to the length, and re-run my program, the result should be 0000.  In a particular example with a 2716, it might look like this:

       :$00:00 20 00 08      (set up address & length )
       :$800G                (run CRC calculation     )
       82DF                  (value of CRC computed   )
       :$20FE:82 DF          (store CRC in EPROM image)
       :$02:02               (increase length by two  )
       :$800G                (run CRC calcualtion     )
       0000                  (it worked!              )

My routines will not win the speed or elegance contests, but they give me the data!

If you want another check on your coding, run a CRC calculation on the Applesoft $D000 ROM with length $0800.  You should get $D01E if you have an Apple II+ or original //e version.  The enhanced //e gives a CRC of $3BD4 because of some small changes Apple made.

By the way, I use my Apple to generate assembly language code for the IBM PC line.  I created an 8086/8088 cross assembler based on the S-C Assembler for the purpose.  Contact me if you need a tool like this:  Don Rindsberg, The Bit Stop, 5958 S. Shenandoah, Mobile, Alabama 36608.  Or call at (205) 342-1653.
