Advertisement
RealnfernoGear

Slightly Improved S3A SRAM code.

Feb 14th, 2020
2,834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; This code is made to add SRAM enabling and disabling done by S3K to the S3A SRAM routines, therefore making the second
  2. ; half of storage accessible without issues. Hopefully, this also fixes an issue Vladik's code has. However, this does
  3. ; take up more storage on the ROM, so be careful, since the S3A Z80 sound driver hasn't been properly disasm'd yet.
  4. SRAM_Load:
  5.         lea ($200011).l,a0
  6.         lea ($2000BD).l,a1
  7.         lea (Competition_saved_data).w,a2
  8.         moveq   #$29,d0
  9.         move.w  #$4C44,d1
  10.         jsr Get_From_SRAM(pc)
  11.         beq.s   loc_B674
  12.         lea SaveData_GeneralDefault(pc),a0
  13.         lea (Competition_saved_data).w,a1
  14.         moveq   #$28,d0
  15.  
  16. loc_B66A:
  17.         move.w  (a0)+,(a1)+
  18.         dbf d0,loc_B66A
  19.         jsr Write_SaveGeneral(pc)
  20.  
  21. loc_B674:
  22.         lea ($200169).l,a0
  23.         lea ($2001F5).l,a1
  24.         lea (Saved_data).w,a2
  25.         moveq   #$19,d0
  26.         move.w  #$4244,d1
  27.         jsr Get_From_SRAM(pc)
  28.         beq.s   loc_B6A4
  29.         lea SaveData_GameDefault(pc),a0
  30.         lea (Saved_data).w,a1
  31.         moveq   #$18,d0
  32.  
  33. loc_B69A:
  34.         move.w  (a0)+,(a1)+
  35.         dbf d0,loc_B69A
  36.         jsr Write_SaveGame(pc)
  37.  
  38. loc_B6A4:
  39.         clr.w   ($FFFFEF4C).w
  40.         move.b  #1,($FFFFEF4B).w
  41.         rts
  42. ; End of function SRAM_Load
  43.  
  44. ; ---------------------------------------------------------------------------
  45. SaveData_GeneralDefault:
  46.         dc.w  $8000,     0, $8000,     0, $8000,     0,     1,  $200
  47.         dc.w  $8000,     0, $8000,     0, $8000,     0,     1,  $200
  48.         dc.w  $8000,     0, $8000,     0, $8000,     0,     1,  $200
  49.         dc.w  $8000,     0, $8000,     0, $8000,     0,     1,  $200
  50.         dc.w  $8000,     0, $8000,     0, $8000,     0,     1,  $200
  51.         dc.w  $4C44
  52. SaveData_GameDefault:
  53.         dc.w  $8000,     0,     0,     0, $8000,     0,     0,     0
  54.         dc.w  $8000,     0,     0,     0, $8000,     0,     0,     0
  55.         dc.w  $8000,     0,     0,     0, $8000,     0,     0,     0
  56.         dc.w  $4244
  57.  
  58. ; =============== S U B R O U T I N E =======================================
  59.  
  60.  
  61. Get_From_SRAM:
  62.         movea.l a2,a3
  63.         move.w  d0,d2
  64.         bsr.s   Read_SRAM
  65.         beq.s   locret_B744
  66.         movea.l a1,a0
  67.         movea.l a3,a2
  68.         move.w  d2,d0
  69.         bsr.s   Read_SRAM
  70.  
  71. locret_B744:
  72.         rts
  73. ; End of function Get_From_SRAM
  74.  
  75.  
  76. ; =============== S U B R O U T I N E =======================================
  77.  
  78.  
  79. Read_SRAM:
  80.         move.b  #1,(SRAM_access_flag).l ; Moved by S3K, this is so that it only enables when we are reading SRAM or writing to it.
  81.         movea.l a2,a6
  82.         move.w  d0,d6
  83.  
  84. loc_B74A:
  85.         movep.w 0(a0),d3
  86.         move.w  d3,(a2)+
  87.         addq.w  #4,a0
  88.         dbf d0,loc_B74A
  89.         move.b  #0,(SRAM_access_flag).l ; Added by S3K, this makes it so that we no longer access SRAM.
  90.         subq.w  #1,d6
  91.         bsr.s   Create_SRAMChecksum
  92.         cmp.w   (a6),d7
  93.         bne.s   locret_B762
  94.         cmp.w   -2(a6),d1
  95.  
  96. locret_B762:
  97.         rts
  98. ; End of function Read_SRAM
  99.  
  100.  
  101. ; =============== S U B R O U T I N E =======================================
  102.  
  103.  
  104. Create_SRAMChecksum:
  105.         moveq   #0,d7
  106.  
  107. loc_B766:
  108.         move.w  (a6)+,d5
  109.         eor.w   d5,d7
  110.         lsr.w   #1,d7
  111.         bcc.s   loc_B772
  112.         eori.w  #$8810,d7
  113.  
  114. loc_B772:
  115.         dbf d6,loc_B766
  116.         rts
  117. ; End of function Create_SRAMChecksum
  118.  
  119.  
  120. ; =============== S U B R O U T I N E =======================================
  121.  
  122.  
  123. Write_SRAM:
  124.         movea.l a2,a6
  125.         move.w  d0,d6
  126.         subq.w  #1,d6
  127.         bsr.s   Create_SRAMChecksum
  128.         move.w  d7,(a6)
  129.         move.b  #1,(SRAM_access_flag).l ; Added by S3K, this is so that it only enables when we are reading SRAM or writing to it.
  130.         movea.l a2,a3
  131.         move.w  d0,d1
  132.  
  133. loc_B786:
  134.         move.w  (a2)+,d2
  135.         movep.w d2,0(a0)
  136.         addq.w  #4,a0
  137.         dbf d0,loc_B786
  138.  
  139. loc_B792:
  140.         move.w  (a3)+,d2
  141.         movep.w d2,0(a1)
  142.         addq.w  #4,a1
  143.         dbf d1,loc_B792
  144.         move.b  #0,(SRAM_access_flag).l ; Added by S3K, this makes it so that we no longer access SRAM.
  145.         rts
  146. ; End of function Write_SRAM
  147.  
  148.  
  149. ; =============== S U B R O U T I N E =======================================
  150.  
  151.  
  152. Write_SaveGeneral:
  153.         move.l  a0,-(sp)
  154.         move.w  d7,-(sp)
  155.         lea ($200011).l,a0
  156.         lea ($2000BD).l,a1
  157.         lea (Competition_saved_data).w,a2
  158.         moveq   #$29,d0
  159.         bsr.s   Write_SRAM
  160.         move.w  (sp)+,d7
  161.         movea.l (sp)+,a0
  162.         rts
  163. ; End of function Write_SaveGeneral
  164.  
  165.  
  166. ; =============== S U B R O U T I N E =======================================
  167.  
  168.  
  169. Write_SaveGame:
  170.         move.l  a0,-(sp)
  171.         move.w  d7,-(sp)
  172.         lea ($200169).l,a0
  173.         lea ($2001F5).l,a1
  174.         lea (Saved_data).w,a2
  175.         moveq   #$19,d0
  176.         bsr.s   Write_SRAM
  177.         move.w  (sp)+,d7
  178.         movea.l (sp)+,a0
  179.         rts
  180. ; End of function Write_SaveGame
  181.  
  182.  
  183. ; =============== S U B R O U T I N E =======================================
  184.  
  185.  
  186. SaveGame:
  187.         tst.b   (Apparent_act).w
  188.         beq.s   locret_B80E
  189.         move.l  (Save_pointer).w,d0
  190.         beq.s   loc_B80A
  191.         movea.l d0,a1
  192.         cmpi.b  #6,3(a1)
  193.         bhi.s   loc_B80A
  194.         moveq   #0,d0
  195.         move.b  (Apparent_zone).w,d0
  196.         move.b  SaveGame_NextLevel(pc,d0.w),3(a1)
  197.         clr.b   7(a1)
  198.         clr.b   1(a1)
  199.         jsr Write_SaveGame(pc)
  200.  
  201. loc_B80A:
  202.         clr.l   (Collected_special_ring_array).w
  203.  
  204. locret_B80E:
  205.         rts
  206. ; End of function SaveGame
  207.  
  208. ; ---------------------------------------------------------------------------
  209. SaveGame_NextLevel:dc.b    1,   2,   3,   5,   5,   6,   7,   0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement