Skip to content

Commit

Permalink
Documenting level select plane map-building code, and S3 differences
Browse files Browse the repository at this point in the history
  • Loading branch information
Clownacy committed Aug 1, 2015
1 parent 3b4c9c9 commit 2bdbbac
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 57 deletions.
156 changes: 99 additions & 57 deletions sonic3k.asm
Expand Up @@ -9392,55 +9392,95 @@ loc_7AD2:
moveq #$27,d1
moveq #$1B,d2
jsr (Plane_Map_To_VRAM).l
lea (RAM_start).l,a3
move.w #$45F,d1

loc_7B2C:
move.w #0,(a3)+
dbf d1,loc_7B2C
; Begin level select code

; S3 loaded S2's level select plane map here, for the level icon emblem
;lea (RAM_start).l,a1
;lea (MapEng_LevSel).l,a0
;move.w #0,d0
;bsr.w Eni_Decomp

; Remember that plane map we just decompressed? Yeah, we're deleting that
lea (RAM_start).l,a3
lea (LevelSelectText).l,a1
lea (word_80C4).l,a5
moveq #0,d0
move.w #$10,d1
; S3 only cleared 1600 bytes, to preserve the level icon emblem
move.w #bytesToWcnt(2240),d1 ; This is the size of your usual decompressed plane map
; loc_7B2C:
.clearloop:
move.w #0,(a3)+
dbf d1,.clearloop

loc_7B4C:
move.w (a5)+,d3
lea (a3,d3.w),a2
moveq #0,d2
move.b (a1)+,d2
move.w d2,d3
; S3 would remove the one zone name that wasn't cleared; Oil Ocean
;lea (RAM_start+$696planeLocH28(3,$15)).l,a3
;move.w #$F,d1

loc_7B58:
move.b (a1)+,d0
move.w d0,(a2)+
dbf d2,loc_7B58
move.w #$D,d2
sub.w d3,d2
bcs.s loc_7B70
;- ;move.w #0,(a3)+
;dbf d1,-

loc_7B68:
move.w #0,(a2)+
dbf d2,loc_7B68
; Build new plane map from LevelSelectText and LevSel_MappingOffsets
save
codepage LEVELSELECT ; This is here so we can use '*' instead of '$1A'

loc_7B70:
move.w #$11,(a2)
lea $50(a2),a2
move.w #$12,(a2)
dbf d1,loc_7B4C
move.w #0,(a2)
lea -$50(a2),a2
move.w #$1A,(a2)
move.w #$13,($FFFF018A).l
move.w #$14,($FFFF01DA).l
lea (RAM_start).l,a3
lea (LevelSelectText).l,a1
lea (LevSel_MappingOffsets).l,a5
moveq #0,d0
move.w #$10,d1 ; This is how many entries there are in LevelSelectText
; loc_7B4C:
.writezone:
move.w (a5)+,d3 ; Get relative address in plane map to write to
lea (a3,d3.w),a2 ; Get absolute address
moveq #0,d2
move.b (a1)+,d2 ; Get length of string
move.w d2,d3 ; Store it
; loc_7B58:
.writeletter:
move.b (a1)+,d0 ; Get character from string
move.w d0,(a2)+ ; Send it to plane map
dbf d2,.writeletter ; Loop for entire string

move.w #$D,d2 ; Maximum length of string
sub.w d3,d2 ; Get remaining space in string
bcs.s .stringfull ; If there is none, skip ahead
; loc_7B68:
.blankloop:
move.w #' ',(a2)+ ; Full the remaining space with blank characters
dbf d2,.blankloop
; loc_7B70:
.stringfull:
move.w #'1',(a2) ; Write (act) '1'
lea $50(a2),a2 ; Next line
move.w #'2',(a2) ; Write (act) '2'
dbf d1,.writezone

; Assuming the last line was the sound test...
move.w #' ',(a2) ; Get rid of (act) '2'
lea -$50(a2),a2 ; Go back to (act) '1'
move.w #'*',(a2) ; Replace that with '*'

; Overwrite duplicate LAVA REEF 1/2 with 3/4 (obviously, S3 didn't do this)
move.w #'3',(RAM_start+planeLocH28($25,4)).l
move.w #'4',(RAM_start+planeLocH28($25,5)).l

restore

; Send our built plane map to VRAM
lea (RAM_start).l,a1
move.l #$40000003,d0
moveq #$27,d1
moveq #$1B,d2
jsr (Plane_Map_To_VRAM).l

moveq #0,d3
bsr.w LevelSelect_DrawSoundNumber
; There was some code here for the zone icons, but it was removed in S&K

; in S3, there was some code here for the zone icons, but it was removed in S&K
;lea (RAM_start+$8C0).l,a1 ; 2240; after the plane map
;lea (MapEng_LevSelIcon).l,a0
;move.w #$90,d0
;bsr.w Eni_Decomp
;bsr.w LevelSelect_DrawIcon

clr.w (Player_mode).w
clr.w ($FFFFFF02).w
clr.b (Level_started_flag).w
Expand Down Expand Up @@ -9493,7 +9533,8 @@ LevelSelect_Main: ; routine running during level select
bsr.w LevSelControls
move.w #$6000,d3
bsr.w LevelSelect_MarkFields
; There was a branch to some zone icon code here
; In S3, there was a branch to some zone icon code here
;bsr.w LevelSelect_DrawIcon
move #$2300,sr
lea (AniPLC_SONICMILES).l,a2
jsr (AnimateTiles_DoAniPLC).l
Expand All @@ -9520,7 +9561,7 @@ loc_7CA0:
add.w d0,d0
move.w (a1,d0.w),d0
bmi.w LevelSelect_Return ; sound test
cmpi.w #$5555,d0 ; ??? (This might have been used in Sonic 3 for the S&K zones...)
cmpi.w #$5555,d0 ; This was used in Sonic 3 for the S&K zones
beq.w LevelSelect_Main ; If entry is $5555, don't do anything
move.b #3,(Life_count).w
move.b #0,(SK_special_stage_flag).w
Expand Down Expand Up @@ -9926,7 +9967,7 @@ loc_8036: ; +
rts
; End of function LevelSelect_DrawSoundNumber

; LevelSelect_DrawIcon used to be here
; LevelSelect_DrawIcon and LevSel_IconTable used to be here

; ---------------------------------------------------------------------------
; byte_8040:
Expand Down Expand Up @@ -9967,24 +10008,25 @@ LevSel_MarkTable: ; 4 bytes per level select entry
dc.b $13,$2C,$14,$4A
dc.b $16,$2C,$16,$4A ;$20

word_80C4: dc.w $56

dc.w $146
dc.w $236
dc.w $326
dc.w $416
dc.w $506
dc.w $5F6
dc.w $6E6
dc.w $7D6
dc.w $7C
dc.w $16C
dc.w $25C
dc.w $34C
dc.w $43C
dc.w $52C
dc.w $61C
dc.w $70C
; word_80C4:
LevSel_MappingOffsets:
dc.w planeLocH28(3,1)
dc.w planeLocH28(3,4)
dc.w planeLocH28(3,7)
dc.w planeLocH28(3,$A)
dc.w planeLocH28(3,$D)
dc.w planeLocH28(3,$10)
dc.w planeLocH28(3,$13)
dc.w planeLocH28(3,$16)
dc.w planeLocH28(3,$19)
dc.w planeLocH28($16,1)
dc.w planeLocH28($16,4)
dc.w planeLocH28($16,7)
dc.w planeLocH28($16,$A)
dc.w planeLocH28($16,$D)
dc.w planeLocH28($16,$10)
dc.w planeLocH28($16,$13)
dc.w planeLocH28($16,$16)

LevelSelectText:
levselstr "ANGEL ISLAND"
Expand Down
3 changes: 3 additions & 0 deletions sonic3k.macros.asm
Expand Up @@ -98,6 +98,9 @@ rom_ptr_z80 macro addr
make_art_tile function addr,pal,pri,((pri&1)<<15)|((pal&3)<<13)|(addr&tile_mask)
tiles_to_bytes function addr,((addr&$7FF)<<5)

; function to calculate the location of a tile in plane mappings with a width of 40 cells
planeLocH28 function col,line,(($50 * line) + (2 * col))

; macro for generating level select strings
levselstr macro str
save
Expand Down

0 comments on commit 2bdbbac

Please sign in to comment.