Port Sonic 2's Level Art Loader to Sonic 1
From Sonic Retro
(Original guide by Clownacy)
Fancy giving your loading screens a speed boost? Sonic 1's Nemesis-compressed art adds quite the chunk to the loading times, and you'll find yourself staring at that blue oval more than you would that blue screen in Sonic 2. Porting Sonic 2's level art loading process cuts down a significant amount of waiting time, and how?
Sonic 1's level art is loaded as part of the Zone-Specific PLC's, forcing it to be Nemesis-compressed. Because of this, we'll need to remove this feature and then introduce Sonic 2's equivalent, which is separate, and, by default, uses a faster compression.
Contents
Preperation
Grab yourself a KENS compressor. You can find some here (KENS) and here (KENSC). Get familiar with them. Also, you'll want to have ported QueueDMATransfer.
Recompression
First, we'll want to recompress our art from Nemesis to Kosinski, Sonic 2's standard level art compression.
Inside your 'artnem' folder, take the following files and place them in a separate folder. However, keep a copy of '8x8 - GHZ1.bin' in artnem, and rename it to "8x8 - Title.bin"
- 8x8 - GHZ1.bin
- 8x8 - GHZ2.bin
- 8x8 - LZ.bin
- 8x8 - MZ.bin
- 8x8 - SBZ.bin
- 8x8 - SLZ.bin
- 8x8 - SYZ.bin
Inside the new folder, decompress all of these files, then delete the Nemesis originals. Open both '8x8 - GHZ1.bin' and '8x8 - GHZ2.bin' in a hex editor, and append the latter to the end of the former, save the result as "8x8 - GHZ.bin". Delete '8x8 - GHZ1.bin' and '8x8 - GHZ2.bin'. Now compress all of the files in Kosinski and move them to the 'artkos' folder.
Changing the pointers
Inside sonic.asm, change this: <asm>Nem_GHZ_1st: incbin "artnem\8x8 - GH1.bin" ; GHZ primary patterns even Nem_GHZ_2nd: incbin "artnem\8x8 - GHZ2.bin" ; GHZ secondary patterns even</asm>
to this <asm>Nem_Title: incbin "artnem\8x8 - Title.bin" ; Title patterns even Kos_GHZ: incbin "artkos\8x8 - GHZ.bin" ; GHZ primary patterns even</asm>
Follow this theme with the rest of the level art inbins: change the "Nem_" prefix to "Kos_", and change "artnem" to "artkos".
Now find this: <asm> lea (Nem_GHZ_1st).l,a0 ; load GHZ patterns bsr.w NemDec</asm>
and change it to this: <asm> lea (Nem_Title).l,a0 ; load Title patterns bsr.w NemDec</asm>
This is simply correcting the title screen's pointer. Like in Sonic 2, the title art is still Nemesis.
Inside the "_inc" folder, find and open Pattern Load Cues.asm and LevelHeaders.asm.
In LevelHeaders.asm, you can see entries for the level art, but, like the music entries, they are unused. As seen above, the level art is actually chosen by the pattern load cues. Sonic 2 would go on to actually use these entries, and, after the completion of this guide, your hack will too. But first, let's correct them to match our new labels.
- Nem_GHZ_2nd → Kos_GHZ
- Nem_LZ → Kos_LZ
- Nem_MZ → Kos_MZ
- Nem_SLZ → Kos_SLZ
- Nem_SYZ → Kos_SYZ
- Nem_SBZ → Kos_SBZ
Go to Pattern Load Cues.asm and comment out the entries for the level art. GHZ and the ending have two, the other levels have only the one.
Porting the level art loading process
Above LevelDataLoad, paste this:
<asm>LoadZoneTiles: moveq #0,d0 move.b (v_zone).w,d0 lsl.w #4,d0 lea (LevelHeaders).l,a2 lea (a2,d0.w),a2 move.l (a2)+,d0 andi.l #$FFFFFF,d0 ; 8x8 tile pointer movea.l d0,a0 lea (v_256x256).l,a1 bsr.w KosDec move.w a1,d3 move.w d3,d7 andi.w #$FFF,d3 lsr.w #1,d3 rol.w #4,d7 andi.w #$F,d7
@loop: move.w d7,d2 lsl.w #7,d2 lsl.w #5,d2 move.l #$FFFFFF,d1 move.w d2,d1 jsr (QueueDMATransfer).l move.w d7,-(sp) move.b #$C,(v_vbla_routine).w bsr.w WaitForVBla bsr.w RunPLC move.w (sp)+,d7 move.w #$800,d3 dbf d7,@loop
rts
- End of function LoadZoneTiles</asm>
This is Sonic 2's LoadZoneTiles, modified to match Sonic 1's LevelHeaders block size ($10 over Sonic 2's $12).
Now to add some branches to this code.
Go to Level_SkipTtlCard and, above this: <asm> bsr.w LevelDataLoad ; load block mappings and palettes</asm>
Add this: <asm> bsr.w LoadZoneTiles ; load level art</asm>
Do the same at End_LoadData.
And with that, we're done, a short guide for shorter loading times! Save and build.
(Optional) Improvements
As mentioned before, this can be taken even further: Go grab the improved KosDec and NemDec, along with CompDec. By using the improved KosDec, or switching to Comper compression, you can achieve even better load times.
If you wish to stick to Kosinski, then simply replacing KosDec will do. If, however, you want to switch to Comper...
Use a KENSC compressor to recompress your art to Comper, then add CompDec to your disassembly. Lastly, go to LoadZoneTiles and replace this: <asm> bsr.w KosDec</asm>
with this <asm> bsr.w CompDec</asm>
That's all. Enjoy your faster loading times!