[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116157":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":16,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":17,"compositeScore":18,"rankGlobal":9,"rankLanguage":9,"license":19,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":9,"pushedAt":24,"updatedAt":25,"readmeContent":26,"aiSummary":27,"trendingCount":15,"starSnapshotCount":15,"syncStatus":13,"lastSyncTime":28,"discoverSource":29},116157,"mvc2-naomi-dc","gibletto\u002Fmvc2-naomi-dc","gibletto","100% Byte Matching Decompilation and ports of NAOMI Game Marvel Vs. Capcom 2",null,"C",79,6,2,5,0,21,26,65.14,"GNU Affero General Public License v3.0",false,"main",true,[],"2026-11-23 17:41:37","2026-11-23 18:45:24","# Marvel vs. Capcom 2 - NAOMI and Dreamcast program source\n\n**AI Disclosure**:\nYes, this used Claude.\nThe names in here are Capcom's wherever they could be found, so blame them for `shl1a_06.c` etc.\n\n## What this is\n\nThis is the source code of *Marvel vs. Capcom 2: New Age of Heroes*, turned back from the machine code of two\nreleases: the NAOMI arcade cartridge (MAME set `mvsc2`) and the Dreamcast disc. One source tree builds both, and\neach comes out byte for byte as it shipped:\n\n    epr-23085a.ic11   4,194,304 bytes   sha1 f58c31b245fc33fa541f9f074548402a63f7c3d3   the arcade's program ROM\n    1ST_READ.BIN      1,809,817 bytes   sha1 b0c3604e3494b12f751793a74fc9b494ed67a30c   the Dreamcast disc's program\n\nIt is a decompilation: the machine code has been rewritten as C, and as SH-4 assembler where the original was\nassembler (the SH-4 is the CPU of both machines), so people can read it and change it. Most files are the same\nfor both. Where the Dreamcast differs, the file says so with `#ifdef TARGET_DC`.\n\nThe same C also runs elsewhere. `ports\u002F` compiles it into PC, 3DS, PSP and MiSTer versions of the game, which play\nfrom your own ROM set or disc.\n\nFor a tour of how the game itself works (the frame loop, inputs, special moves, hit boxes, damage), read\n`docs\u002FHOW_THE_GAME_WORKS.md`.\n\n## Choose your version\n\nTo build a program that is byte for byte the original:\n\n- the arcade's export cartridge, MAME set `mvsc2`: [Building](#building)\n- the US arcade cartridge, MAME set `mvsc2u`: [The US arcade version](#the-us-arcade-version)\n- the Dreamcast USA disc: [The Dreamcast version](#the-dreamcast-version)\n\nThese need Windows, Hitachi's compiler and Sega's SDK libraries. None of them can be included here, so the\nsections below say where to find them.\n\nTo build a port, which plays the game on another machine:\n\n- PC (Windows): [ports\u002FREADME.md](ports\u002FREADME.md)\n- Nintendo 3DS: [ports\u002F3DS.md](ports\u002F3DS.md). Both versions run at full speed, 60 fps, on every 3DS and 2DS,\n  the original models too.\n- PSP: [ports\u002FPSP.md](ports\u002FPSP.md), the Dreamcast version.\n- MiSTer: [ports\u002FMISTER.md](ports\u002FMISTER.md), both versions, drawn by the Pinedra GPU core, which must be installed\n  first ([Pinedra GPU on Patreon](https:\u002F\u002Fwww.patreon.com\u002Fpinedragpu\u002Fposts\u002Fpinedra-gpu-for-175129847)).\n\nThese need only GCC, CMake, Python 3 and SDL3, or devkitPro for the 3DS, pspdev for the PSP and Docker for the\nMiSTer. The releases have them ready to play.\n\n## Building\n\nThe arcade build uses the original toolchain (Hitachi's SHC 5.1 Release 08, asmsh 4.0, lnk 6.0A and elf2bin)\nand Sega's NAOMI libraries: the compiler turns the C into machine code, the assembler does the same for the\nassembler files, and the linker joins the pieces into one program. Every routine comes out as the arcade's\nexact bytes, and the finished file is the cartridge's program ROM, `epr-23085a.ic11`.\n\nThe ROM holds two programs, the game and the operator's test menu, and the fighting data of the 59 characters\n(moves, hit boxes, the computer's play). All of that is built from this source. The pictures, models and sound\nare in the cartridge's other ROMs and are not part of this.\n\nYou need Windows (the compiler's tools are Win32 programs), Python 3, your own ROM, and two zips from Sega's NAOMI\nSDK. The Internet Archive has the SDK as the item `NaomiSDK`:\n\n- `archive\u002Fhitachi\u002Fpcv51r08.zip` - the compiler, sha1 104e78c75f83a70b023850daa1ea3b729e852ab2\n- `archive\u002Fnaomi\u002Flibwin.zip` - Sega's libraries, sha1 a8723959364f9793d0185a73889d64706108b2d1\n\nThen:\n\n1. Put your `epr-23085a.ic11` (or the whole `mvsc2.zip`) in `rom\u002F`.\n2. Unpack the two zips, and tell the build where they are. `SHC` is the compiler's `bin` folder, and `SDK_LIBS` is\n   four library folders, in this order:\n\n       set SHC=C:\\pcv51r08\\bin\n       set SDK_LIBS=C:\\libwin\\lib\\zero;C:\\libwin\\lib;C:\\libwin\\libsrc\\libjamma\\zero;C:\\pcv51r08\\lib\n\n3. Run `build.bat` (or `make`).\n\nThe build writes `build\u002Fepr-23085a.ic11` and prints whether it has the arcade ROM's SHA-1.\n\nA few things are not in this source, so the build cuts them from your ROM first (`tools\u002Fmvc2rom.py`):\n\n- seven model files that the game never reads\n- 16 KB inside the test program that no build can give: the linker leaves these blocks alone, and the ROM has\n  whatever was on Capcom's disk before, pieces of older builds\n- 8 KB of Z80 code. The NAOMI has a small chip of its own (315-6149) between the game and the cabinet's\n  controls and coin slots, with a Z80 inside. It has no program until the game gives it one, so Sega's library\n  carries the Z80 program as a block of data and sends it to the chip at start-up. It is Sega's, and it is not\n  SH-4 code, so it is not written out here\n\nNo other version of the compiler or the libraries will do. Sega's libraries are part of the program, and most of\ntheir modules are linked straight from `libwin.zip`. The modules that the zip only has in a later version than the\none Capcom linked are built from `src\u002Flib`.\n\n## The US arcade version\n\nThe same source also builds the US cartridge's program ROM (MAME set `mvsc2u`):\n\n    epr-23062a.ic22   4,194,304 bytes   sha1 877ba02c92082567280afcb1ae40b3bbfc8a63e8\n\nThe game is the same. What differs is the cartridge: the US one is Sega's M2 ROM board, and the export one\nabove is the M1 board, which reads its data differently. So the routines that read files from the ROM\n(`src\u002Fam_load.c`, `src\u002Ftex_load.c`), the test menu's ROM board test, and the ROM's head differ, and say so with\n`#if ROM_BOARD == 2`.\n\nPut your `epr-23062a.ic22` (or the whole `mvsc2u.zip`) in `rom\u002F` and run `build.bat us` (or `make us`), with\nthe same `SHC` and `SDK_LIBS` as the arcade build. The build writes `build\u002Fepr-23062a.ic22` and checks its SHA-1.\nAs for the export ROM, it first cuts the same kinds of pieces from your ROM.\n\n## The Dreamcast version\n\nThe same source also builds the Dreamcast version: the USA disc's main program, and the characters' code,\nwhich the disc keeps in files of its own. It is the same game with a home menu around it: options, a training\nmode, a shop that sells the extra characters and colours for points, a memory card save, and a network lobby\nwith a software keyboard. Capcom built it from the arcade's source in the spring of 2000, so most of the files\nare the arcade's own.\n\nA file that differs between the two says so with `#ifdef TARGET_DC`, and where the disc changed between its\nreleases, with the build's date (`#if BUILD_DATE >= 20000412`). The files only the home version has are in\n`src\u002Fdc`, and the Dreamcast's own build of a Sega library module is in `src\u002Fdc\u002Flib`. Every routine comes out as\nthe disc's exact bytes:\n\n    1ST_READ.BIN    1,809,817 bytes   sha1 b0c3604e3494b12f751793a74fc9b494ed67a30c\n\nand so do the 354 character files (`S_PL00A.BIN` and the rest: each character's code, linked for each of the\nsix places a fighter's code can be loaded). `dcovl.sha1` lists them.\n\nTo build it you need the arcade's two zips, and two of Sega's Katana SDKs for the libraries only the Dreamcast\nhas. The Internet Archive item `dc_sdks` has them:\n\n- \"Sega Katana Development Software - Release 10.zip\", sha1 6b063a04e543f851ace49e5aef49488e4d976ce4: `mdmapi.lib`, `modem.lib`,\n  `nt_utl.lib` and `shinobi.lib`\n- \"Sega Katana Development Software - Release 9.zip\", sha1 a8b0d630851bd90b39dceb65cd2957bd13208383: `cri_adxn.lib`\n\nBoth are needed: Release 10 has no `cri_adxn.lib`, and Release 9's Shinobi is another build. Each zip holds a\ndisc image with an installer. Install them, then set `SDK_LIBS` to six folders, in this order (the arcade's,\nwith Release 10's library folder fourth and Release 9's last):\n\n    set SDK_LIBS=C:\\libwin\\lib\\zero;C:\\libwin\\lib;C:\\libwin\\libsrc\\libjamma\\zero;C:\\KATANA\\Lib;C:\\pcv51r08\\lib;C:\\KATANA_R9\\Lib\n\nand run `build.bat dc` (or `make dc`). The build writes `build\u002Fmvc2dc.bin` and the characters' files in\n`build\u002Fovl\u002F`, and checks their SHA-1s. It needs nothing from your disc.\n\nThings that were learned on the way:\n\n- **A module can be more than one file.** The compiler empties its pool of constants at the end of each file.\n  The disc's pools break at five places where one file never would, so the home game's SECRET FACTOR is six\n  files (`src\u002Fdc\u002Fsecret.c` and the rest).\n- **A routine can be too big to optimise.** At about 256 branches in one routine, SHC gives up on it (\"Function\n  not optimized\") and keeps every local in memory. `secret_factor_3_save` is one. Its code only matches with\n  the same number of branches, so it uses a statement that makes no code, `VM_NOP()`, where Capcom's source\n  most likely had a macro that was empty in this build.\n- **Some of the fake matches are the disc's.** A few routines here only match with a statement that never\n  runs (`if( 0 ) ... ;`, marked \"left out of the build\"). The compiler still counts what it reads and writes,\n  so it can change which register a value gets. These are the routines where nothing more natural has been\n  found yet, and they are a good place to start contributing.\n\n## Layout\n\n    src\u002F           game code, a file for each of Capcom's\n    src\u002Flib\u002F       the modules of Sega's libraries that the SDK has no matching version of (see Sega's libraries)\n    src\u002Ftest\u002F      the test menu's own code\n    src\u002Fdc\u002F        the files only the Dreamcast version has (src\u002Fdc\u002Flib: its builds of Sega's modules)\n    data\u002F          the characters' fighting data\n    include\u002F       headers; player.h includes the shared ones (pl_work.h has PLAYER_WORK)\n    docs\u002F          HOW_THE_GAME_WORKS.md: a tour of the game's code\n    mvc2.sub       link order and section addresses (mvc2test.sub for the test menu, mvc2u.sub and\n                   mvc2utest.sub for the US cartridge, mvc2dc.sub for the Dreamcast)\n    dcovl.sha1     the SHA-1s of the Dreamcast's characters' files\n    functions.tsv  every routine of the game program: arcade address, size, name, file\n    tools\u002F         mvc2rom.py: reads your ROM; chrpack.py: packs the characters' data\n    rom\u002F           your ROM goes here\n    symbols.txt    every named address of the arcade's program (symbols_dc.txt: the Dreamcast's)\n    pointers.tsv   the words of the arcade's program that hold addresses, and those addresses\n                   (pointers_dc.tsv: the Dreamcast's), which a port needs to load the program's data\n    ports\u002F         the PC and 3DS ports\n\nA character's code is `src\u002Fs_plXX.c`, where XX is the character's number in hexadecimal (`s_pl00.c` is Ryu). Its\nfireballs and other effects are in `shlXX_YY.c` and `plsXX_YY.c`, and its data in `data\u002F`.\n\n## Names\n\nCapcom left more than the game in the cartridge. The unused space of the ROMs still holds pieces of what was on the\ndevelopers' PC when the images were made: a list of 215 source files, pages of a linker map with 532 symbols, the\ncompiler's options, and scraps of C and assembler source. This text is in every retail cartridge.\n\nThat is where the names here come from. Files named like the ones in that list (`s_pl02.c`, `shl05_00.c`,\n`pl_dmg.c`, `game.c`, `flashing.c`) are Capcom's files. Routines, structures and fields found in the map and the\nscraps (`PLAYER_WORK`, `routine_2`, `pl_char_set`, `Rnd`) are Capcom's too. Everything else is named in the same\nstyle for what it does. A field we don't understand yet is called `unk_` and its offset.\n\n## Compiler\n\nTwo versions of the same compiler can turn the same C into different machine code, and so can two sets of\noptions. The options Capcom used were sitting in the ROM's unused space:\n\n    -round=near -cpu=sh4 -fpu=single -endian=little -macsave=0 -pic=0 -optimize=1 -size -string=const -extra=a=400\n\n`-extra=a=400` is not in the manual. It makes the assembler stage put a `nop` after each `mov Rm,R0`, and the game\ncode has 3,325 of them.\n\nWith these options, the compiler builds all the C here to the exact bytes: the arcade's 18,306 routines in 700 files\n(and the test menu's three files), and the Dreamcast's 18,991 routines in 773 files, 73 of them the home version's\nown. Nothing is patched afterwards. The few assembler files (`.src`) are ones that were assembler to begin with: the\nstart-up, the cache routines, a table, and some of Sega's library modules.\n\nNot every file saw the same headers. The machine code shows how each file thought a routine was declared, and\nfor a few routines the files do not agree: two dozen of them pass `pl_char_set` its animation number as an `int`,\nthe rest as a byte. Most likely a prototype changed during development and those files were not compiled again\nafterwards. Such a file includes a header with the older prototype (`include\u002Fpl_char_old.h` and the other\n`_old.h` files), or sets a switch before `player.h` (`#define PL_HYPER_START_NEW`).\n\n## Sega's libraries\n\nThis part is for anyone taking apart another NAOMI game.\n\nA NAOMI game is not only the game. Sega's libraries are linked into it: Kamui2 (the graphics driver), Shinobi (the\nsystem library the Dreamcast also had), the NAOMI libraries on top of them (`libnaomi`, `libnlobj`, `libspr`,\n`libam`, `libjamma` and others), and the compiler's own run-time library. In this game that is 301 modules.\n\nSega's NAOMI SDK is on the Internet Archive, and its libraries still link with the same linker. So the first thing\nto try is to not decompile them at all: find each library module in the ROM and link Sega's object as it is. Here\n260 of the 301 modules come straight out of `libwin.zip` and the compiler's zip, byte for byte. `mvc2.sub` names\neach one, for example `libkamui2.lib(kmSetVertex_km2vtxlst_lib_)`.\n\nThe catch is the dates. The SDK's NAOMI libraries were built in August 2000. This game was built in February 2000\nwith what Capcom had then, and the libraries print their own build dates, which are still in the ROM:\n\n    NAOMI LIBRARY Ver 0.9 AM R&D          Dec 22 1999\n    NLOBJPUT Ver 0.99                     Dec 17 1999\n    libspr Ver 0.2                        Dec 16 1999\n    nlam Ver 1.00                         Nov 08 1999\n    syChain Ver 1.50am, syHw Ver 1.07am   Nov 09 1999\n    libintr Ver 1.051                     Oct 28 1999\n\nSearch your own ROM for `Build:` and `Ver` and you will know which libraries you have before you start.\n\nWhere the SDK's module is a later version than the ROM's, it does not match, and there is no older SDK to take it\nfrom. Those 41 modules were decompiled like the game was, and are in `src\u002Flib`, one folder for each library. They\nbuild to the ROM's exact bytes too. If your game is from about the same months, they may be the very modules you\nare missing.\n\nThings that were learned on the way, and that should hold for other games:\n\n- **Each library has its own compiler options**, and they are not the game's. Sega built most of the NAOMI\n  libraries with `-round=zero -align16 -division=cpu`, where Capcom used `-round=nearest`. The options are in\n  `src\u002Flib\u002FLIBRARY\u002Foptions`. A few modules inside a library differ again, and have a `MODULE.options` file:\n  `nlmath` and `nlproj` need `-round=nearest`, or constants like `0.001f` come out one bit low.\n- **Shinobi and Kamui2 use their own section names**, `-section=p=PSG,c=CSG,d=DSG,b=BSG`. That is why the\n  linker's map groups them apart from the game's `P`, `C`, `D` and `B`.\n- **Kamui2 was built with `-extra=a=800`**, an option that is not in the manual. It lines code up on 32 bytes and\n  puts each routine's constants on the next 32-byte line. Every Kamui2 object looks like that. Capcom's own\n  `-extra=a=400` is its neighbour. Two of Shinobi's modules (`kdapi_`, `mpapi_`) were built without optimisation,\n  for speed.\n- **Two builds of each library are in the zip**, `lib` and `lib\u002Fzero`. Some modules match from one and some from\n  the other, so the link takes each module from whichever has the ROM's bytes.\n- **Some modules were assembler to begin with.** Seven of `libnlobj`'s (the vertex and model code) are in the\n  objects as assembler, and are `.src` files here. A few C modules have routines written with\n  `#pragma inline_asm` (the `ftrv` matrix code in `nlproj`, the interrupt mask in Shinobi's `syIntCtrl_`). The\n  compiler cannot build those to an object directly: it writes assembler source (`-code=asmcode`) and the\n  assembler finishes the job. The Makefile does it that way.\n- **`#pragma aligndata8( names )`** is another thing the manual leaves out. It puts the named variables on 8-byte\n  lines, as Sega's matrix globals are. There is an `aligndata32` too.\n- **`libjamma` is the one library the SDK has source for** (`libsrc\u002Flibjamma`). The three modules here follow it,\n  changed where the ROM's older version differs.\n\nThe compiler's run-time library (`sh4nlfzn.lib`: division, block moves, `sprintf` and the like) links straight\nfrom the compiler's zip, apart from two small modules.\n\n## Contributing\n\nAs this is an exact byte-match, every contribution must keep the match: build, and check that the SHA-1 line still\nsays the ROM is the arcade's (and, for a file the Dreamcast shares, that `build.bat dc` still matches the disc).\nThe ports build from the same files, and GitHub's Build workflow checks that they still do. Contributions should improve or explain the code: a better name, a field worked out,\na clearer way to write a routine that still compiles to the same bytes.\n\nA \"fake\" match is source that builds the right bytes but is unlikely to be what Capcom wrote: an odd loop, an\nassignment in a strange place, a local that is never used. The compiler is sensitive to such things, and some\nroutines only match with them. Changes should lower their number or explain them, with evidence or better code.\n\n## License\n\nGNU Affero General Public License v3.0 (`LICENSE`). `NOTICE.md` lists what the license does not cover, and\n`ports\u002FNOTICE.md` what the ports take from elsewhere.\n","这是一个对街机基板NAOMI与世嘉Dreamcast平台游戏《Marvel vs. Capcom 2》进行100%字节级匹配反编译的开源项目，将原始机器码精准还原为可读、可修改的C语言源码（含SH-4汇编片段），并支持跨平台移植。核心特点是严格保持原始二进制一致性（SHA1校验通过）、统一源树条件编译（#ifdef TARGET_DC）、以及基于GCC\u002FCMake的多平台端口（PC、3DS、PSP、MiSTer）。适用于游戏逆向研究、经典格斗游戏机制分析、ROM兼容性验证及复古硬件复刻开发。","2026-11-24 04:53:00","CREATED_QUERY"]