Metal Gear annotated disassembly published

بواسطة konamiman بتاريخ 05-10-2018, 21:34
المناقشة: Software
اللغات:

Manuel Pazos has been spending a good amount of time reverse-engineering the classic MSX game Metal Gear and publishing some interesting findings about it in his twitter account. The process has finished and Manuel has just published the result of his work as a GitHub respository containing a fully annotated disassembly of the game, for both the Japanese and the English versions. So now we have the opportunity to take a look at the ins and outs of this masterpiece and learn a bit about how Konami developed their masterpieces.

Relevant link: Metal Gear annotated disassembly at GitHub

التعليقات (46)

بواسطة Dustin Pease

Resident (50)

صورة Dustin Pease

06-10-2018, 00:05

Manuel,
You are awesome. Thank you so much for this!

بواسطة Victor

Champion (509)

صورة Victor

06-10-2018, 05:27

What a titanic work...

Thanks for sharing, Manuel!!

بواسطة Pippo

Hero (521)

صورة Pippo

06-10-2018, 07:31

Astonishing work!!! Shocked! Shocked!
You spent very happy hours, didn't you, Master Manuel? Smile2

بواسطة cax

Prophet (3741)

صورة cax

06-10-2018, 07:56

Very impressive. Can you share the insights now - e.g. how many different code styles can you spot, hidden features etc. ?

بواسطة Pippo

Hero (521)

صورة Pippo

06-10-2018, 08:07

Many, many thanks, Master Manuel, for your deep dedication to the Sacred System. Smile Smile

بواسطة Guillian

Prophet (3528)

صورة Guillian

06-10-2018, 09:00

Thanks guys!

@cax: there are at least two different coding styles. In this Twitter thread I posted some oddities (most of them in Spanish). There are a few more commented in the code.

بواسطة KdL

Paragon (1485)

صورة KdL

06-10-2018, 11:35

Congrats Manuel !! Smile

بواسطة Pencioner

Scribe (1609)

صورة Pencioner

06-10-2018, 12:09

Great stuff! Can't imagine how much of efforts has been put on this Big smile

بواسطة ren

Paragon (1942)

صورة ren

06-10-2018, 13:38

Wow.. So I guess we might expect some fan game(s) / 'remixes' based on these sources..? Cool

Would there be other works you're interested in to disassemble? Gradius 2 or Usas perhaps? Hannibal

بواسطة Guillian

Prophet (3528)

صورة Guillian

06-10-2018, 15:14

Thanks!

@ren: I could do the same with other games, but... not really sure if it is worth the effort.

بواسطة sd_snatcher

Prophet (3675)

صورة sd_snatcher

06-10-2018, 15:49

Impressive, Snake! I mean, Manuel! Smile

بواسطة Wolverine_nl

Paragon (1160)

صورة Wolverine_nl

06-10-2018, 16:05

Great job Manuel! Big smile
It is nice to see in the 80's Konami kitchen this way. Your effort was definitly worth it.

بواسطة gdx

Enlighted (6422)

صورة gdx

06-10-2018, 16:11

Thanks for sharing this impressive work.
Which disassembler did you use?

بواسطة lintweaker

Champion (474)

صورة lintweaker

06-10-2018, 16:12

Wow, great job!

بواسطة Giangiacomo Zaffini 2

Champion (300)

صورة Giangiacomo Zaffini 2

06-10-2018, 19:53

Thank Manuel for his gigantic effort.
I cannot even imagine how to revert machine code blob into source assembly modules, functions and variables.
Are You an university resercher or university instructor or professor?

بواسطة Guillian

Prophet (3528)

صورة Guillian

06-10-2018, 21:59

Thanks!

@gdx: I used IDA

@Giangiacomo: I'm not related to univertity or teaching. I'm just a MSX fan (^_^)

بواسطة meits

Scribe (6571)

صورة meits

06-10-2018, 22:54

But... Are there things you can NOT do as well?

بواسطة konamiman

Paragon (1210)

صورة konamiman

07-10-2018, 12:15

Meits wrote:

But... Are there things you can NOT do as well?

He almost can't write README files. Big smile

بواسطة Guillian

Prophet (3528)

صورة Guillian

07-10-2018, 13:02

konamiman wrote:
Meits wrote:

But... Are there things you can NOT do as well?

He almost can't write README files. Big smile

Hahahaha!
That's true!

بواسطة Huey

Prophet (2694)

صورة Huey

08-10-2018, 14:09

Great work!

I've spend already quite some time reading the code and going through the structures.

بواسطة Guillian

Prophet (3528)

صورة Guillian

08-10-2018, 15:51

Thanks, Huey!
I hope you will find it interesting.

بواسطة Giangiacomo Zaffini 2

Champion (300)

صورة Giangiacomo Zaffini 2

08-10-2018, 16:49

I tested it, if I'm not mistaken, sjasm 0.39c compiles codebase but sjasm 0.42c does not compile.

It is quite a feeling having such Metal Gear compiled in a second after enter key smashed. Cool

بواسطة iamweasel2

Paladin (722)

صورة iamweasel2

09-10-2018, 05:41

This is amazing ! Thanks very much for this great work ! Smile

If I may suggest, it would be nice a full dissassembly of a small classic MSX game (16 k). Anyone would do: Hyper Rally, King's valley, Hero, River Raid etc... It would help a lot for people learning asm if they could understand how to code a small msx action game.

بواسطة theNestruo

Champion (429)

صورة theNestruo

09-10-2018, 06:47

Thank you, Manuel!!!
I love reading code to discover different approaches and alternative solutions, and usually to improve my own code.
It's great to study how Konami did some things (such as reading input; much easier than what I was trying to do!).

iamweasel2 wrote:

If I may suggest, it would be nice a full dissassembly of a small classic MSX game (16 k). Anyone would do: Hyper Rally, King's valley, Hero, River Raid etc... It would help a lot for people learning asm if they could understand how to code a small msx action game.

Does Pyramid Warp (T&E, 1983) qualify? https://github.com/theNestruo/msx-pyramidwarpex

بواسطة Guillian

Prophet (3528)

صورة Guillian

09-10-2018, 09:55

@Giangiacomo The sources compile with sjasm 0.39 as explained in the readme. But it is possible to adapt them to work with 0.42 (Fernando García aka Bitvision did it)

@iamweasel2 Perhaps in a future I'll release more sources/disassemblies (King's Valley, Knight Lore, etc.)

@theNestruo It is nice to hear that the sources are helping to improve your game!

بواسطة Manuel

Ascended (19676)

صورة Manuel

09-10-2018, 21:20

Guillian: just wondering: of that 128kB, how much is code, how much is data? And how is the data divided? I guess mostly graphics and map data. Any idea of how much of each?

بواسطة Sandy Brand

Champion (309)

صورة Sandy Brand

10-10-2018, 00:11

Wow! That is some really impressive retro archeology! Smile

بواسطة Guillian

Prophet (3528)

صورة Guillian

10-10-2018, 09:00

Manuel: a rough estimation could be about 36 kB of code, 16 kB of sprites, 8 kB of music/sfx, 6 kB of text, 32 kB of graphics, 10 kB of rooms, 10 kB of metaTiles, 10 kB other data.

بواسطة Manuel

Ascended (19676)

صورة Manuel

10-10-2018, 22:21

Thanks Smile Interesting!

بواسطة Edevaldo

Master (156)

صورة Edevaldo

12-10-2018, 05:14

Quote:

Manuel: a rough estimation could be about 36 kB of code, 16 kB of sprites, 8 kB of music/sfx, 6 kB of text, 32 kB of graphics, 10 kB of rooms, 10 kB of metaTiles, 10 kB other data.

I was very curious about that as well. Thanks!

Could you comment on your disassemble process? I would like to try it on a simpler game.

بواسطة theNestruo

Champion (429)

صورة theNestruo

12-10-2018, 11:41

I'm used to use zero flag (z) for true/false return values, and I can see that carry flag (c) is widely used here.
Is it usual in Z80 assembler to use C for that purpose? Is my BASIC and C background tricking me to think in terms of Z/NZ?

بواسطة Guillian

Prophet (3528)

صورة Guillian

12-10-2018, 14:34

Edevaldo wrote:

Could you comment on your disassemble process? I would like to try it on a simpler game.

Probably it is easier to show it on a video that explain it. It can be done in different ways:

- 1st pass: disassembly, analyze and annotate the flow of the program
- 2nd pass: fix the parts that were wrongly identified

Or:
- 1st pass: Fully disassembly the code
- 2nd pass: Analyze and annotate the code
- 3rd pass: Fixes

theNestruo wrote:

I'm used to use zero flag (z) for true/false return values, and I can see that carry flag (c) is widely used here.
Is it usual in Z80 assembler to use C for that purpose? Is my BASIC and C background tricking me to think in terms of Z/NZ?

It depends on what you need to check. I.e.: checking threshold values, or if a value in within a range, the C and NC are better choices.

بواسطة ren

Paragon (1942)

صورة ren

12-10-2018, 16:39

Guillian wrote:

I could do the same with other games, but... not really sure if it is worth the effort.

May I ask you how long you've been working on this disassemble?

Some n00b questions from me.. Murdoch I now very little (to nothing) about assembly language, but I reckon having it disassembled says (to an extend) nothing about any higher level language the programmers might have used, right? Or are there any conclusion you can draw based on what you've seen/come across?

I wonder to what extend the structure you present the disassemble in, also represents the source structure Konami employed? High probability, or some guesses/own interpretations here & there?

Cheers / thanks for illuminating! Smile

بواسطة iamweasel2

Paladin (722)

صورة iamweasel2

12-10-2018, 16:57

theNestruo wrote:

Thank you, Manuel!!!
I love reading code to discover different approaches and alternative solutions, and usually to improve my own code.
It's great to study how Konami did some things (such as reading input; much easier than what I was trying to do!).

iamweasel2 wrote:

If I may suggest, it would be nice a full dissassembly of a small classic MSX game (16 k). Anyone would do: Hyper Rally, King's valley, Hero, River Raid etc... It would help a lot for people learning asm if they could understand how to code a small msx action game.

Does Pyramid Warp (T&E, 1983) qualify? https://github.com/theNestruo/msx-pyramidwarpex

Of course it qualifies ! :) Thanks very much theNestruo, I'll check it out. :)

بواسطة Guillian

Prophet (3528)

صورة Guillian

12-10-2018, 20:44

ren wrote:

May I ask you how long you've been working on this disassemble?

I disassembled the game and analyzed it in two months one year ago.
Then two months ago I started adding annotations.
So it took me about 4 months in my spare time.

ren wrote:

Some n00b questions from me.. Murdoch I now very little (to nothing) about assembly language, but I reckon having it disassembled says (to an extend) nothing about any higher level language the programmers might have used, right? Or are there any conclusion you can draw based on what you've seen/come across?

I'm almost 100% sure that the game was programmed in assembler.

ren wrote:

I wonder to what extend the structure you present the disassemble in, also represents the source structure Konami employed? High probability, or some guesses/own interpretations here & there?

I have no idea how Konami structured the code. But I know they reused different "modules", that probably they included/imported into different projects (i.e.: the code for the Konami logo, for reading and storing the controls, for calculating the trajectory/speed of a shot, etc.)

The main structure in all Konami games is almost the same, except in some of them that were not really made by Konami (i.e: Contra, or Green Beret)

بواسطة MOA

Champion (293)

صورة MOA

16-10-2018, 00:56

Wow, very well done!

This was definitely written in assembly by the Konami coders; no compiler would generate such code. Code quality is actually very decent; much better than I would expect from a company trying to make money, hehe.

بواسطة Wolverine_nl

Paragon (1160)

صورة Wolverine_nl

16-10-2018, 09:22

MOA wrote:

Wow, very well done!

This was definitely written in assembly by the Konami coders; no compiler would generate such code. Code quality is actually very decent; much better than I would expect from a company trying to make money, hehe.

Unlike some nowadays, that release a game which isn't a 100% finished game yet. And you get an update every other day. oO
The old days, games needed to be 100% working. Smile

بواسطة Grauw

Ascended (10818)

صورة Grauw

16-10-2018, 09:42

theNestruo wrote:

I'm used to use zero flag (z) for true/false return values, and I can see that carry flag (c) is widely used here.
Is it usual in Z80 assembler to use C for that purpose? Is my BASIC and C background tricking me to think in terms of Z/NZ?

I use both as is convenient, but I prefer carry as it's easier to set explicitly (scf/ccf/and a), is modified by less instructions (e.g. inc & bit don't), and is easier to use directly in math (e.g. sbc a,a); with the zero flag you always need to branch.

بواسطة theNestruo

Champion (429)

صورة theNestruo

20-10-2018, 16:29

Grauw wrote:
theNestruo wrote:

I'm used to use zero flag (z) for true/false return values, and I can see that carry flag (c) is widely used here.
Is it usual in Z80 assembler to use C for that purpose? Is my BASIC and C background tricking me to think in terms of Z/NZ?

I use both as is convenient, but I prefer carry as it's easier to set explicitly (scf/ccf/and a), is modified by less instructions (e.g. inc & bit don't), and is easier to use directly in math (e.g. sbc a,a); with the zero flag you always need to branch.

Thanks, Grauw! That makes a lot of sense!
I'll check my code because I'll probably can improve some parts switching from z to c Smile

بواسطة nikodr

Paladin (750)

صورة nikodr

22-10-2018, 00:36

Could a level editor for metal gear be released that would allow us to make new maps or scenarios?now that this difficult -(manuel you are truly a genius)- rom has been dissasembled could that happen?
Also what other tricks could programmers get out of those routines?do you think that those tricks they used back then are suitable for making games on the msx now?

بواسطة Guillian

Prophet (3528)

صورة Guillian

22-10-2018, 09:19

It is possible to modify the map, rooms, items locations, etc. It is, somehow, easy to do it. Probably the difficult part is the design.

About the tricks. Some parts are not optimized, but the sources are a good source of information for learning. E.g.: how to read controls, sprite flickering routine, state machines, actors structures, etc.

بواسطة FiXato

Scribe (1743)

صورة FiXato

23-10-2018, 05:58

Modifying item locations is already possible with Randomizer for Metal Gear 1 objects.

بواسطة nikodr

Paladin (750)

صورة nikodr

26-10-2018, 10:48

I am still amazed by the fact that konami has no main loop actually but everything is done with the dummy loop calling the isr.also the camera logic and testing if enemies can see you while was good in 1987 now in metal gear 2 they changed it.could it change here?so enemies can see you if you in front of them?many times if you go up a wall and enemy is in front of you he doesnt see you.

بواسطة Gregory

Champion (295)

صورة Gregory

05-05-2021, 19:25

I assembled the source files to get metalgear.rom and have 2 questions:
- during the assembly I get a lot of error: 'constants\structures.asm: syntax error
What is the cause of this? I'm using sjasm42c.

- the rom doesn't have any sound, is this normal?

بواسطة Guillian

Prophet (3528)

صورة Guillian

05-05-2021, 20:47

Gregory wrote:

I assembled the source files to get metalgear.rom and have 2 questions:
- during the assembly I get a lot of error: 'constants\structures.asm: syntax error
What is the cause of this? I'm using sjasm42c.

As stated in the "How to assemble" section, you have to use Sjasm 0.39 or compatible assembler.

Gregory wrote:

- the rom doesn't have any sound, is this normal?

It is not. The assembled ROM is exactly the same as the original.

بواسطة Gregory

Champion (295)

صورة Gregory

05-05-2021, 20:57

Guillian wrote:
Gregory wrote:

I assembled the source files to get metalgear.rom and have 2 questions:
- during the assembly I get a lot of error: 'constants\structures.asm: syntax error
What is the cause of this? I'm using sjasm42c.

As stated in the "How to assemble" section, you have to use Sjasm 0.39 or compatible assembler.

Gregory wrote:

- the rom doesn't have any sound, is this normal?

It is not. The assembled ROM is exactly the same as the original.

Thanks, sjasm 0.39 solved both issues, should have read tfm.