home *** CD-ROM | disk | FTP | other *** search
/ The Amiga Game Guide / AmigaGameGuide_CD.iso / Amiga / Game-Installer / JST-Installer / Turrican2HD / src / readturr2disk.asm < prev    next >
Encoding:
Assembly Source File  |  1978-01-01  |  1.3 KB  |  61 lines

  1. ; Turrican 2 disk image reader
  2. NO_INCLUDES=1
  3. MESSAGES=1
  4.     include    diskreader.asm
  5.     BUFFER    TRACKBUFFER
  6.  
  7. ; track 0: dos track
  8. ; $60000 loader after bootblock, 2048 bytes
  9.     DOSREAD    #0
  10.     WRITE    #2048,#1024
  11.  
  12. ; track 1: not used
  13.  
  14. ; tracks 2-159:
  15. ; - $9521 MFM sync
  16. ; - unused byte (encoded as 2 bytes MFM)
  17. ; - 6800 bytes of data (stored as 1700 8-byte MFM encoded longwords)
  18. ; - longword checksum, which is XOR of all preceding raw MFM data, then
  19. ;   odd bits masked out (encoded as MFM long)
  20.  
  21.     moveq    #2,d7    ; d7 = tracknumber
  22. .nxttrk    RAWREAD    d7    ; read track
  23.     RESYNC    #$9521    ; resync track
  24.  
  25.     lea    TRACKBUFFER,a0    ; beginning of buffer
  26.     lea    4(a0),a1    ; beginning of data in buffer
  27.  
  28.     move.w    #(6800/4)-1,d0
  29.     moveq    #0,d3        ; accumulated checksum
  30.     move.l    #$55555555,d4    ; 0101010101010...
  31. .decode    movem.l    (a1)+,d1/d2    ; read 8-byte MFM encoded long
  32.     eor.l    d1,d3        ; checksum raw MFM data
  33.     eor.l    d2,d3
  34.     and.l    d4,d1        ; decode MFM long
  35.     and.l    d4,d2
  36.     add.l    d1,d1
  37.     or.l    d2,d1
  38.     move.l    d1,(a0)+    ; write long
  39.     dbra    d0,.decode
  40.  
  41.     movem.l    (a1)+,d1/d2    ; get stored checksum
  42.     and.l    d4,d1        ; decode
  43.     and.l    d4,d2
  44.     add.l    d1,d1
  45.     or.l    d2,d1
  46.     and.l    d4,d3        ; mask odd bits out
  47.     cmp.l    d1,d3        ; verify checksum
  48.     beq.s    .ok
  49.     cmp.b    #159,d7
  50.     beq.s    .ok
  51.     FAILURE    cksum(pc)
  52.  
  53. .ok    WRITE    #6800
  54.  
  55.     addq.w    #1,d7
  56.     cmp.w    #160,d7
  57.     bne.s    .nxttrk
  58.     rts
  59.  
  60. cksum    dc.b    "bad checksum",0
  61.