Sega Master System / Mark III / Game Gear|
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew
strange code in Alex Kidd - The Lost StarsPosted: Mon Aug 05, 2019 10:51 pm
I'm currently looking at some disassembly of "Alex Kidd - The Lost Stars". During the initialization some strange things happen:
The code I'd like to discuss starts at address 0352h. 3 register pairs get initialized:
ld de, $0515
ld hl, $C000
ld bc, $0020
That seems absolutely normal so far :-). Then it goes on:
ex de, hl
Why exchange DE with HL and not initialize it correctly in the first place? My confusion goes on:
ld d, $C0
D is already C0h here...
ld a, e
add a, $1C
First, A is set 0 (because E is 0), just to add 1Ch afterwards. Why not just "ld a, $1C"? But as we see below, A get's overwritten anyway.
ld e, a ; E = 1Ch
ld b, c ; B = 20h
ld c, $80 ; C = 80h
Again some useless (?) juggling around...
ld a, (hl)
Frome here everything seems quite reasonable, but everything above could have been replaced with:
ld de, $C01C
ld hl, $0515
ld bc, $2080
Can somebody explain this code to me? What I can imagine:
A) some code generation took place which produced a not very well optimized code
B) same as A, but with a compiler
C) I missed an important point here
I very much favour C) ;-).
Thanks in advance for your help!
||Posted: Mon Aug 05, 2019 11:39 pm|
|My guess is that the constants weren't always these values so it made more sense at the time, and the values got poked in after assembly.|