In diesem Artikel möchte ich das interne GerĂ€t des legendĂ€ren Spiels Sonic the Hedgehog fĂŒr den Sega Mega Drive zerlegen sowie Möglichkeiten, es zu modifizieren oder, wie sie sagen, zu hacken. Dieses Spiel hat ungefĂ€hr hundert Hacks , einschlieĂlich wirklich wĂŒrdiger Arbeit (wie Pana Der Hejhog oder Sonic Remastered ) und seltsam und sogar gruselig (wie An Ordinary Sonic ROM Hack ). Um zu verstehen, wie man sie erstellt, mĂŒssen Sie herausfinden, wie man in der Assembler-Sprache Motorola 68K schreibt (normalerweise wurden Spiele fĂŒr Konsolen jener Zeit in Assembler geschrieben), wo man die zerlegte Version des Spiels erhĂ€lt und welche Architektur ihre Engine hat.

Die Demontage von ROM-Dateien fĂŒr Sega erfolgt mit dem kommerziellen Disassembler und dem IDA Pro- Debugger . Dann gibt es einen sorgfĂ€ltigen Prozess des Markierens, Strukturierens und KĂ€mmens des rohen Assembler-Codes unter Verwendung des Debuggers (und des Einfallsreichtums). Dieser Prozess erfordert ein gutes VerstĂ€ndnis der technischen Funktionen der Sega Mega Drive-Plattform und der Spiele dafĂŒr.
GlĂŒcklicherweise hat GitHub bereits Versionen aller Spiele der Sonic the Hedgehog-Reihe zerlegt und markiert, die von Enthusiasten mit UnterstĂŒtzung von Sonic Retro erstellt wurden . Der Quellcode des allerersten Spiels der Serie ist am besten markiert und strukturiert. Diese Version des Codes befindet sich im Repository sonicretro / s1disasm und wird im Artikel analysiert.
Das Eintauchen in die innere Struktur des Spielzeugs beginnt mit der Theorie.

Sega Mega Drive ( Sega Genesis) 32- Motorola MC68000 ( Motorola 68K) Zilog Z80 ( Z80 ). (RAM) â 64K. ( ) â 320x224 .
Motorola 68K . , . Motorola 68K Apple Macintosh.
Mega Drive Yamaha YM7101 80 . ; Sega Mega Drive " Sega Mega Drive: Video Display Processor".
AS. 82 . : ResearchGate Intel Core i7 338 .
32- : D0âD7. . A0âA7. - . A7 SP.
. .l (long) 32- . .w (word) .b (byte) 16- 8- .
Motorola 68K.
move â .
:
move.l #48, d4 â 48 d4.move.w d5, d6 â 16 d5 d6.move.w #$12FF, obStatus(a0) â 12FF , obStatus , a0.
, #. #$.
:
move.l #5, (a0) â 5 , a0.move.l (a1), d2 â , a1, d2.
(a*).
add â .sub â .mulu â ; muls â .divu â ; divs â .
:
add.b #$08, d0 â 08 d0.sub.w (v_screenposx).w, d1 â d1 v_screenposx ( 16- ).mulu.w #10, d0 â d0 10 ( d0 ).divs.w #$68, d2 â d2 68 ( d2 ).
jmp, bra â .jsr, bsr â , rts â ( call ret x86).
:
jmp .foo
nop
.foo:
SubRoutine:
nop
rts
bsr SubRoutine
68K CCR (Condition Code Register). cmp, tst btst () , beq, bne, bge, ble .
cmp â .tst â .btst â .beq/bne â , / .bge/ble â , / .
:
cmp.w #32,d0
bge.s .foo
btst #0,d0
bne.s .foo
Motorola 68K ( ) , .
s1disasm Python-, . Sonic the Hedgehog "Kosinski compression", ( ).
, , git- AS (git checkout AS) :
./build.py
ROM- s1built.bin. Sega Mega Drive. macOS, , OpenEmu.
â sonic.asm. : Zilog Z80 (WaitForZ80), (VDPSetupGame) . GameInit MainGameLoop, .
, Variables.asm. RAM, .
v_gamemode. :
- 00 â "Sega",
- 01 â ,
- 08 â ,
- 0C â ,
- 10 â special stage,
- 14 â "Continue",
- 18 â ,
- 1C â ,
- 8C â .
move.b #id_Sega,(v_gamemode).w GameInit v_gamemode , . id_Sega id_Title ./build.py, , "Sega" , .
v_gamemode , . , id_Title GM_Title, id_Level â GM_Level.
, Variables.asm . v_sonspeedmax, v_sonspeedacc v_sonspeeddec.
, Sonic_Main, : , , :
move.w #$600,(v_sonspeedmax).w
move.w #$C,(v_sonspeedacc).w
move.w #$80,(v_sonspeeddec).w
, 256. , 0xC / 256 = 0.046875, â 0x80 / 256 = 0.5 ( ).
Mega Drive Sega 315â5313 (Video Display Processor, VDP). VDP , vdp_data_port vdp_control_port. VDPSetupGame, VDPSetupArray. , , . , GM_Level. VDP Sega Retro.
Low Color ( Mode Register 1 ):
Video Display Processor â background ( B) foreground ( A), , . 8x8 . ; â 4x4 . , 32x32 .
(LoadTilesAsYouMove, DrawChunks) (BuildSprites) , :
, LoadTilesAsYouMove . Sonic the Hedgehog 64x32 512x256 .
foreground- Green Hill Zone, GIF-, 5 : , , . , . , 3D- . Sonic the Hedgehog.
8192 RAM . v_objspace. , . : , , , , , . DisplaySprite.

64 . , , Constants.asm. a0. , :
ObX(a0), ObY(a0) â .ObVelX(a0), ObVelX(a1) â 1/256 .obHeight(a0), obWidth(a0) â .obSubtype(a0) â (: ).obStatus(a0) â .obRoutine(a0) â .
, X , Y, .
ExecuteObjects . , . Object Pointers.asm. _incObj.
, (, , , "" ). , , obRoutine.
SpeedToPos. , .
: no-ring challenge
, : no-ring challenge. . , ( ).
"" â Ring_Main (bra) :
Ring_Main:
bra.w Ring_Delete
lea (v_objstate).w,a2
moveq #0,d0
move.b obRespawnNo(a0),d0
. "" 26 Monitor.asm. obSubtype 1 . , 6. cmp beq , :
Mon_Main:
cmp.b #6,obSubtype(a0)
beq DeleteObject
addq.b #2,obRoutine(a0)
move.b #$E,obHeight(a0)
, ROM' , . GitHub. , - , .
:
, . Sonic the Hedgehog 3 â .
Sonic the Hedgehog 3
, , Sonic Retro. , , , 64 , . . 0.1875 , . , 0.75.
, , , , , "" .
"", 25 & 37 Rings.asm. :
Ring_Index:
ptr_Ring_Main: dc.w Ring_Main-Ring_Index
ptr_Ring_Animate: dc.w Ring_Animate-Ring_Index
ptr_Ring_Collect: dc.w Ring_Collect-Ring_Index
ptr_Ring_Sparkle: dc.w Ring_Sparkle-Ring_Index
ptr_Ring_Delete: dc.w Ring_Delete-Ring_Index
: Main â ; Animate â ; Collect â ; Sparkle â ; Delete â . , , ptr_Ring_Animate.
obStatus. , . obStatus ( ) . bset, , â btst.
Ring_Animate , , , 64 :
Ring_Animate:
tst.b (v_shield).w
beq.s .animate
.dist_from_sonic:
move.w (v_player+obX).w,d0
sub.w obX(a0),d0
move.w (v_player+obY).w,d1
sub.w obY(a0),d1
.check_magnetised:
btst #0,obStatus(a0)
bne.s .attract
.check_near_x:
cmp.w #64,d0
bge.s .animate
cmp.w #-64,d0
ble.s .animate
.check_near_y:
cmp.w #64,d1
bge.s .animate
cmp.w #-64,d1
ble.s .animate
bset #0,obStatus(a0)
.attract:
.animate:
, , . :
if sign(obVelX) == sign(distX):
, ( Motorola 68K) , 0 , 1 â . "" â XOR (eor Motorola 68K).
, ( ) , (0.1875 0.75) 256 ( 48 192 ).
:
.attract:
move.w #48,d4
move.w obVelX(a0),d3
eor.w d0, d3
btst #$F,d3
beq.s .x_towards
move.w #192,d4
.x_towards:
cmp.w #0,d0
bge.s .attract_x
neg d4
.attract_x:
add.w d4,obVelX(a0)
move.w #48,d4
move.w obVelY(a0),d3
eor.w d1,d3
btst #$F,d3
beq.s .y_towards
move.w #192,d4
.y_towards:
cmp.w #0,d1
bge.s .attract_y
neg d4
.attract_y:
add.w d4,obVelY(a0)
.animate:
, , SpeedToPos:
.animate:
jsr (SpeedToPos).l
ROM , â â Sonic 3 Sonic 1!
GitHub , .
. (SonED2, Chaos), , . / Motorola 68K EASy68K, , Sega.
, , . , - , , .