home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Extra / RawDIC17.lha / Examples / Mercenary2save.islave.asm < prev    next >
Assembly Source File  |  1999-03-02  |  4KB  |  151 lines

  1.  
  2.     ; Mercenary 2 - Damocles savegame imager
  3.  
  4.     ; A track contains $1800 bytes of data.
  5.  
  6.     ; The format is singlesided, both sides contain the same data.
  7.  
  8.     ; track format description:
  9.  
  10.     ; sync ($4489)
  11.     ; 4 unused bytes ($12345678)
  12.     ; 1 byte track number
  13.     ; $1800 bytes data
  14.     ; 1 word checksum
  15.  
  16.     ; The checksum is calculated by adding all data bytes to a word variable
  17.     ; which is rotated to the left every step.
  18.  
  19.     ; The MFM decoding is done by skipping all odd bits in the bitstream.
  20.  
  21.     ; Similar formats: All other Novagen games on Amiga
  22.  
  23.         incdir    Includes:
  24.         include    RawDIC.i
  25.  
  26.         SLAVE_HEADER
  27.         dc.b    1    ; Slave version
  28.         dc.b    0    ; Slave flags
  29.         dc.l    DSK_1    ; Pointer to the first disk structure
  30.         dc.l    Text    ; Pointer to the text displayed in the imager window
  31.  
  32.         dc.b    "$VER:"
  33. Text:        dc.b    "Damocles savegame imager V1.0",10,"by John Selck on 02.03.1999",0
  34.         cnop    0,4
  35.  
  36. DSK_1:        dc.l    0        ; Pointer to next disk structure
  37.         dc.w    1        ; Disk structure version
  38.         dc.w    DFLG_SINGLESIDE|DFLG_ERRORS    ; Disk flags
  39.         dc.l    TL_1        ; List of tracks which contain data
  40.         dc.l    0        ; UNUSED, ALWAYS SET TO 0!
  41.         dc.l    FL_NULL        ; List of files to be saved
  42.         dc.l    0        ; Table of certain tracks with CRC values
  43.         dc.l    0        ; Alternative disk structure, if CRC failed
  44.         dc.l    0        ; Called before a disk is read
  45.         dc.l    SaveFiles    ; Called after a disk has been read
  46.  
  47. TL_1:        TLENTRY    2,21,$1800,SYNC_INDEX,DMFM_NovagenSG
  48.         TLEND
  49.  
  50. DMFM_Novagen:    ; Decoder for tracks in Novagens very own format.
  51.  
  52.         moveq    #0,d1
  53.         moveq    #20,d2
  54. .l0        bsr.b    NextByte
  55.         lsl.l    #8,d1
  56.         move.b    d0,d1
  57.         cmp.l    #$12345678,d1
  58.         dbeq    d2,.l0
  59.  
  60.         bsr.b    NextByte    ; skip track number
  61.  
  62.         moveq    #0,d2
  63.         move.w    #$17ff,d1
  64. .l1        bsr.b    NextByte    ; decode data
  65.         add.b    d0,d2
  66.         rol.w    #1,d2
  67.         move.b    d0,(a1)+
  68.         dbra    d1,.l1
  69.  
  70.         bsr.b    NextByte    ; compare checksum on disk
  71.         move.b    d0,d1        ; with calculated sum
  72.         bsr.b    NextByte
  73.         lsl.w    #8,d1
  74.         move.b    d0,d1
  75.         rol.w    #8,d1
  76.         cmp.w    d1,d2
  77.         bne.b    .error
  78.  
  79.         moveq    #IERR_OK,d0    ; no error
  80.         rts
  81. .error        moveq    #IERR_CHECKSUM,d0    ; checksum error
  82.         rts
  83.  
  84. NextByte:    move.w    (a0)+,d0
  85.         BITSKIP_B d0
  86.         rts
  87.  
  88.     ; The sync-signal is $4489, but due to the most likely case
  89.     ; that not all 10 savegame slots are used, the sync may not
  90.     ; be present so DFLG_ERRORS has been set and rawdic_NextMFMword
  91.     ; has been used to allow unformatted tracks.
  92.  
  93. DMFM_NovagenSG:
  94.  
  95.         move.w    d0,d6        ; track number
  96.  
  97.         move.w    #$4489,d0    ; sync signal
  98.         jsr    rawdic_NextMFMword(a5)
  99.         bne.b    .exit
  100.         bsr    DMFM_Novagen
  101.         bne.b    .exit        ; error? no saved game...
  102.  
  103.         subq.w    #2,d6
  104.         move.w    d6,d0
  105.         lsr.w    #1,d0        ; calculate slot number
  106.         lea    SlotFlags(pc),a0
  107.         subq.b    #1,(a0,d0.w)    ; track could be read, decrease SlotFlags
  108.  
  109.         and.w    #1,d6
  110.         bne.b    .exit        ; if track=even then check first 3 words
  111.  
  112.         move.l    -$1800(a1),d6
  113.         cmp.l    #$45631405,d6
  114.         bne.b    .in        ; first 3 words have to be $456314054e75
  115.         move.w    4-$1800(a1),d6
  116.         cmp.w    #$4e75,d6
  117.         beq.b    .exit
  118. .in        addq.b    #1,(a0,d0.w)    ; no saved game!
  119.  
  120. .exit        moveq    #IERR_OK,d0    ; no error
  121.     ; (always ok, because the checksum error may occur due to not used slot)
  122.         rts
  123.  
  124. SaveFiles:
  125.  
  126.         moveq    #9,d2
  127. .l0        lea    SlotFlags(pc),a0
  128.         tst.b    (a0,d2.w)
  129.         bne.b    .s0
  130.         move.b    d2,d0
  131.         or.b    #"0",d0
  132.         move.b    d0,FNum
  133.  
  134.         move.w    d2,d0
  135.         mulu.w    #$1800*2,d0
  136.         move.l    #$1cd8,d1    ; length of a saved game
  137.         lea    FName(pc),a0
  138.         jsr    rawdic_SaveDiskFile(a5)
  139. .s0        dbra    d2,.l0
  140.  
  141.         moveq    #IERR_OK,d0
  142.         rts
  143.  
  144. SlotFlags:    dcb.b    10,2    ; only if both tracks for a saved game
  145.                 ; could be read without errors, the
  146.                 ; SlotFlags value for the slot is 0.
  147.  
  148. FName:        dc.b    "Mercenary2.save"
  149. FNum:        dc.b    "0",0
  150.  
  151.