Skip to content

Commit

Permalink
Using RAM constants to define more clearRAM lengths, and pointing out…
Browse files Browse the repository at this point in the history
… errors with them
  • Loading branch information
Clownacy committed Aug 2, 2015
1 parent 19c75ce commit 0341065
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
48 changes: 27 additions & 21 deletions s2.asm
Expand Up @@ -1279,8 +1279,9 @@ ClearScreen:
clr.l (Vscroll_Factor).w
clr.l (unk_F61A).w

clearRAM Sprite_Table,$284
clearRAM Horiz_Scroll_Buf,$404
; These '+4's shouldn't be here; clearRAM accidentally clears an additional 4 bytes
clearRAM Sprite_Table,(Sprite_Table_End-Sprite_Table)+4
clearRAM Horiz_Scroll_Buf,(Horiz_Scroll_Buf_End-Horiz_Scroll_Buf)+4

startZ80
rts
Expand Down Expand Up @@ -4252,12 +4253,13 @@ Level:
bsr.w LoadPLC
; loc_3F48:
Level_ClrRam:
clearRAM Sprite_Table_Input,$400
clearRAM Sprite_Table_Input,(Sprite_Table_Input_End-Sprite_Table_Input)
clearRAM Object_RAM,(LevelOnly_Object_RAM_End-Object_RAM) ; clear object RAM
clearRAM MiscLevelVariables,(MiscLevelVariables_End-MiscLevelVariables)
clearRAM Misc_Variables,(Misc_Variables_End-Misc_Variables)
clearRAM Oscillating_Data,(Oscillating_variables_End-Oscillating_variables)
clearRAM CNZ_saucer_data,$100
; The '+C0' shouldn't be here; CNZ_saucer_data is only $40 bytes large
clearRAM CNZ_saucer_data,(CNZ_saucer_data_End-CNZ_saucer_data)+$C0

cmpi.w #chemical_plant_zone_act_2,(Current_ZoneAndAct).w ; CPZ 2
beq.s Level_InitWater
Expand Down Expand Up @@ -4376,7 +4378,7 @@ Level_TtlCard:
clr.w (Vscroll_Factor_FG).w
move.w #-$E0,(Vscroll_Factor_P2_FG).w

clearRAM Horiz_Scroll_Buf,$400
clearRAM Horiz_Scroll_Buf,(Horiz_Scroll_Buf_End-Horiz_Scroll_Buf)

bsr.w LoadZoneTiles
jsrto (loadZoneBlockMaps).l, JmpTo_loadZoneBlockMaps
Expand Down Expand Up @@ -5971,10 +5973,11 @@ SpecialStage:
; | Now we clear out some regions in main RAM where we want to store some |
; | of our data structures. |
; \------------------------------------------------------------------------/
clearRAM SS_Sprite_Table,$284 ; Sprite attribute table buffer
clearRAM SS_Horiz_Scroll_Buf_1,$404 ; H scroll table buffer, $404 bytes
clearRAM PNT_Buffer,$C04 ; PNT buffer
clearRAM SS_Sprite_Table_Input,$400
; These '+4's shouldn't be here; clearRAM accidentally clears an additional 4 bytes
clearRAM SS_Sprite_Table,(SS_Sprite_Table_End-SS_Sprite_Table)+4
clearRAM SS_Horiz_Scroll_Buf_1,(SS_Horiz_Scroll_Buf_1_End-SS_Horiz_Scroll_Buf_1)+4
clearRAM SS_Misc_Variables,(SS_Misc_Variables_End-SS_Misc_Variables)+4
clearRAM SS_Sprite_Table_Input,(SS_Sprite_Table_Input_End-SS_Sprite_Table_Input)
clearRAM SS_Object_RAM,(SS_Object_RAM_End-SS_Object_RAM)

move #$2300,sr
Expand Down Expand Up @@ -6158,7 +6161,7 @@ SpecialStage:
move.w #MusID_EndLevel,d0
jsr (PlaySound).l

clearRAM SS_Sprite_Table_Input,$400
clearRAM SS_Sprite_Table_Input,(SS_Sprite_Table_Input_End-SS_Sprite_Table_Input)
clearRAM SS_Object_RAM,(SS_Object_RAM_End-SS_Object_RAM)

move.b #ObjID_SSResults,(SpecialStageResults+id).w ; load Obj6F (special stage results) at $FFFFB800
Expand Down Expand Up @@ -10024,7 +10027,7 @@ TwoPlayerResults:
move.w #$8C81,(a6) ; H res 40 cells, no interlace, S/H disabled
move.w #$9001,(a6) ; Scroll table size: 64x32

clearRAM Sprite_Table_Input,$400
clearRAM Sprite_Table_Input,(Sprite_Table_Input_End-Sprite_Table_Input)
clearRAM VSRslts_Object_RAM,(VSRslts_Object_RAM_End-VSRslts_Object_RAM)

move.l #vdpComm(tiles_to_bytes(ArtTile_ArtNem_FontStuff),VRAM,WRITE),(VDP_control_port).l
Expand Down Expand Up @@ -11046,7 +11049,7 @@ MenuScreen:
move.w #$8C81,(a6) ; H res 40 cells, no interlace, S/H disabled
move.w #$9001,(a6) ; Scroll table size: 64x32

clearRAM Sprite_Table_Input,$400
clearRAM Sprite_Table_Input,(Sprite_Table_Input_End-Sprite_Table_Input)
clearRAM Menus_Object_RAM,(Menus_Object_RAM_End-Menus_Object_RAM)

; load background + graphics of font/LevSelPics
Expand Down Expand Up @@ -12323,7 +12326,8 @@ EndingSequence:
move.w d0,(Ending_VInt_Subrout).w
move.w d0,(Credits_Trigger).w

clearRAM Horiz_Scroll_Buf,$404
; The '+4' shouldn't be here; clearRAM accidentally clears an additional 4 bytes
clearRAM Horiz_Scroll_Buf,(Horiz_Scroll_Buf_End-Horiz_Scroll_Buf)+4

move.w #$7FFF,(PalCycle_Timer).w
lea (CutScene).w,a1
Expand Down Expand Up @@ -12398,7 +12402,8 @@ EndgameCredits:
move.w d0,(Ending_VInt_Subrout).w
move.w d0,(Credits_Trigger).w

clearRAM Horiz_Scroll_Buf,$404
; The '+4' shouldn't be here; clearRAM accidentally clears an additional 4 bytes
clearRAM Horiz_Scroll_Buf,(Horiz_Scroll_Buf_End-Horiz_Scroll_Buf)+4

moveq #MusID_Credits,d0
jsrto (PlaySound).l, JmpTo2_PlaySound
Expand Down Expand Up @@ -24805,7 +24810,7 @@ Obj34_Init:
clr.w (Vscroll_Factor_FG).w
move.w #-$E0,(Vscroll_Factor_P2_FG).w

clearRAM Horiz_Scroll_Buf,$400
clearRAM Horiz_Scroll_Buf,(Horiz_Scroll_Buf_End-Horiz_Scroll_Buf)

rts
; ===========================================================================
Expand Down Expand Up @@ -29251,12 +29256,12 @@ SpriteSizes_2P_3:

; loc_172A4:
RingsManager_Setup:
clearRAM Ring_Positions,$600
clearRAM Ring_Positions,(Ring_Positions_End-Ring_Positions)
; d0 = 0
lea (Ring_consumption_table).w,a1

move.w #bytesToLcnt($40),d1 ; coding error, should be $80 not $40
- move.l d0,(a1)+
move.w #bytesToLcnt(Ring_consumption_table_End-Ring_consumption_table-$40),d1 ; coding error, that '-$40' shouldn't be there
- move.l d0,(a1)+ ; only half of Ring_consumption_table is cleared
dbf d1,-

moveq #0,d5
Expand Down Expand Up @@ -56862,7 +56867,7 @@ loc_2C806:
move.b #4,routine(a0)
lea (CNZ_saucer_data).w,a1
move.b subtype(a0),d1
andi.w #$3F,d1
andi.w #$3F,d1 ; This means CNZ_saucer_data is only $40 bytes large
lea (a1,d1.w),a1
addq.b #1,(a1)
cmpi.b #3,(a1)
Expand Down Expand Up @@ -68461,7 +68466,8 @@ loc_361D8:
move.l d1,(a1)+
dbf d0,loc_361D8

clearRAM Sprite_Table,$284
; The '+4' shouldn't be here; clearRAM accidentally clears an additional 4 bytes
clearRAM Sprite_Table,(Sprite_Table_End-Sprite_Table)+4

rts
; ===========================================================================
Expand Down Expand Up @@ -74308,7 +74314,7 @@ loc_3A346:
bchg #0,status(a0)

; This clears a lot more than the horizontal scroll buffer, which is $400 bytes (960 bytes according to docs)
clearRAM Horiz_Scroll_Buf,$1004
clearRAM Horiz_Scroll_Buf,$1000+4 ; That '+4' shouldn't be there; accidentally clears an additional 4 bytes

; Initialize streak horizontal offsets for Sonic going right.
; 9 full lines (8 pixels) + 7 pixels, 2-byte interleaved entries for PNT A and PNT B
Expand Down
10 changes: 10 additions & 0 deletions s2.constants.asm
Expand Up @@ -1031,12 +1031,15 @@ VDP_Command_Buffer_Slot: ds.l 1 ; stores the address of the next open slot for a

Sprite_Table_2: ds.b $300 ; Sprite attribute table buffer for the bottom split screen in 2-player mode
Horiz_Scroll_Buf: ds.b $400
Horiz_Scroll_Buf_End:
Sonic_Stat_Record_Buf: ds.b $100
Sonic_Pos_Record_Buf: ds.b $100
Tails_Pos_Record_Buf: ds.b $100
CNZ_saucer_data: ds.b $40 ; the number of saucer bumpers in a group which have been destroyed. Used to decide when to give 500 points instead of 10
CNZ_saucer_data_End:
ds.b $C0 ; $FFFFE740-$FFFFE7FF ; unused as far as I can tell
Ring_Positions: ds.b $600
Ring_Positions_End:

Camera_RAM:
Camera_X_pos: ds.l 1
Expand Down Expand Up @@ -1134,6 +1137,7 @@ Camera_RAM_End:

Block_cache: ds.b $80
Ring_consumption_table: ds.b $80 ; contains RAM addresses of rings currently being consumed
Ring_consumption_table_End:

Underwater_palette_2: ds.w palette_line_size ; not sure what it's used for but it's only used when there's water
Underwater_palette_2_line2: ds.w palette_line_size
Expand Down Expand Up @@ -1359,6 +1363,7 @@ Anim_Counters: ds.b $10 ; $FFFFF7F0-$FFFFF7FF
Misc_Variables_End:

Sprite_Table: ds.b $280 ; Sprite attribute table buffer
Sprite_Table_End:
ds.b $80 ; unused, but SAT buffer can spill over into this area when there are too many sprites on-screen

Normal_palette: ds.w palette_line_size
Expand Down Expand Up @@ -1731,6 +1736,7 @@ SS_Object_RAM_End:

; The special stage mode also uses the rest of the RAM for
; different purposes.
SS_Misc_Variables:
PNT_Buffer: ds.b $700
PNT_Buffer_End:
SS_Horiz_Scroll_Buf_2: ds.b $400
Expand Down Expand Up @@ -1797,9 +1803,12 @@ SS_NoRingsTogoLifetime: ds.w 1
SS_RingsToGoBCD: ds.w 1
SS_HideRingsToGo: ds.b 1
SS_TriggerRingsToGo: ds.b 1
ds.b $58 ; unused
SS_Misc_Variables_End:

phase ramaddr(Horiz_Scroll_Buf) ; Still in SS RAM
SS_Horiz_Scroll_Buf_1: ds.b $400
SS_Horiz_Scroll_Buf_1_End:

phase ramaddr($FFFFF73E) ; Still in SS RAM
SS_Offset_X: ds.w 1
Expand All @@ -1808,6 +1817,7 @@ SS_Swap_Positions_Flag: ds.b 1

phase ramaddr(Sprite_Table) ; Still in SS RAM
SS_Sprite_Table: ds.b $280 ; Sprite attribute table buffer
SS_Sprite_Table_End:
ds.b $80 ; unused, but SAT buffer can spill over into this area when there are too many sprites on-screen


Expand Down

0 comments on commit 0341065

Please sign in to comment.