Bionic Commando (NES)
=====================
Offset Document
Version 4

By: Matrixz

New stuff:
	* Renamed a few things to make it less confusing
	* Revisited explanations
	* Found enemy data, some asm locations
	* Added MMC1 Bank Labels

Thanks to Dean Tersigni for information
on how the Screen Layout works.

---

All the data type adresses is NES ROM locations with header included.
A Room is a logical room. wich can have many doors.
An Area can have many Rooms used in it (Area 8 is the ultimate example).

--------
Bank 0/1
--------

10-EF: Screen Usage Pointer for each Room
 Each Room is built up of 8x8-structure screens, and there
 are data for where in the rom to load screens for use in each room.
 Each Screen Usage Pointer is 16-bit refering to where to
 start reading Screen Usage Data.
 These 16-bit pointers are in real NES memory space adresses,
 to get the rom adress, subtract $80 from the high byte,
 and add $10 becouse of the NES header.

F0-4B7: 16-bit Screen Usage Data
 In the room's Screen Usage Data, each 2 byte couple points to
 where in the rom to pick Screen Data for each Screen in the Room.
 To get the actual rom adress, do the same as above, subtract $8000 and add $10.
 For the info, if a pointer's value is above $BFFF, the rom will switch
 to 16k bank #1, subtracting $40 from the high byte, and using that as the pointer.
 If youre not into asm, dont worry about it.
 If both bytes are $FF, it means to stop setting up the screen queue.
 Im not sure if there's actually any limit for how many screens you can use in a room.

4B8-60F: ???
 This stuff remains a mystery. It's not asm, it seems more like a piece of
 half-compiled source code, ready to be assembled into nes binary.
 Check it out and feed your imagination.

610-600F: Screen Data
 Readen from based on $F0-4B7. Very simple data.
 Each byte defines wich 32x32-pixel structures used to fill up one Screen.
 Each room has a different set of structures.
 The structure's properties is defined in the Structure Data.

6010-6011: Pointer to "Palette Pointer for Each Room"

6012-60F1: [Tile Load Data] Pointer for Each Room

In this case, subtract 4 from the first nibb and add $10 to get correct adress.

60F2-7199: Tile Load Data

Each structure in a screen is built up of 4 blocks.
A TileBlock is a 16x16 pixel tile that uses 4 tiles in the Pattern Table.
Each tile load data chunk uses 80 bytes. 64 of these dectermines where in a ROM bank to load the 4 tiles for each TileBlock (4 tiles in the Pattern Table), and 16 additional bytes with 4-bit data to select the $4000 byte ROM-bank to load tiles from, and hit bits let's you flip the TileBlock Horizontally.

0-3F: CHR Pointers for each TileBlock

Each byte points to a 4-tile chunk (for a TileBlock) in the ROM bank.

40-5F: 4-bit effect/bank data for each TileBlock
 
 4-bit effect data:
  -HBB
  ||
  |+$4000 BG-CHR Bank 
  +Horizontal Flip Flag

If the Flip Flag is set, the whole TileBlock (as a whole 16x16 tile) is turned Horizontal at load. The two last bits, bit 3 and 4, makes an 2-bit value telling wich $4000 bank in the CHR to load from. So, one can say that the whole CHR Pointer to a TileBlock is 10-bit like this:
DDPPPPPPPP
Where DD is the 2bit CHR Bank and PPPPPPPP is the other CHR Pointer data

Here's a formula to calculate the Tileblock CHR's offset in the ROM:

$ROMAddr = ($10010 + ([BG-CHR Bank] * $4000) + ([CHR_Pointer] * $40))

719A-7279: Palette Pointer for Each Room

Subtract 4 from first nybb and add $10 to get the adress.

727A-790F: Room Palette Data

NOTE: Palette data has both BG and Sprite Palettes for each room. ($20 bytes)
The background color is defined by the 16th byte (first byte of the Sprite Palettes) 

7910-800F: Introduction scene ASM

--------
Bank 2/3
--------

8010-8011: Offset of "Structure Data Pointer for Each Level"

8012-81D1: 4-byte Screen Layout Data for each Room

Each room has 4 bytes of data here. The two first is actually yet
another 16-bit pointer, pointing where to read the rooms Screen Layout.
The other two i'm not sure of, maybe they have something with the rooms
screen size to do.. at least it has something with the layout of screens
to do.

81D2-84D8: Screen Layout Presets

"Screen Usage Data" tells where in the ROM to pick up the Screen Data, this data actually
has the order of those loaded screens. Each screen can be used several times also. One
byte for each screen.

84D9-85B8: Structure Data Pointer for Each Room

85B9-880F: ???

More seemingly unused data.

8810-EC0F: Structure Data

There are 256 structures read for one Room, and each of them has 7 bytes. Structure data is banked with $800 bytes for each Room. This data is laid out in 7 and 7 bytes, so $700 bytes is used, the last $100 bytes is filled with 0.

0: Block0 4-tile start offset
1: Block1 4-tile start offset
2: Block2 4-tile start offset
3: Block3 4-tile start offset
4: Structure Palette Attributes
5: Block 0 and 1 4bit block type
6: Block 2 and 3 4bit block type

EC10: Some ASM

ED7B: Enemy Data Pointer for each Room (Yay! :D)

EE5B: Enemy Data

Enemy Data goes like this for each enemy:
0: Enemy ID 
1: X Position
2: Screen X
3: Y Position
4: Screen Y

If byte 0 is $FF it means end of room's enemy data, else more enemies is initialized.

F6E0: Room Special Event Data pointers

F7C0: Room Special Event Data

This has to be figured out by time.
The first byte seems to alter the frequency of the event, second byte; the event ID.

F8F7: Room Enemy CHR Load Data Pointers

F9DB: Room Enemy CHR Load Data

--------
Bank 2-7
--------

10010-2800F: Game CHR

------
Bank 8
------

28010: Some Object Data Pointers (Ladd's?)
2BB70: Some Code, unknown usage

------
Bank 9
------

2C010: Dialogue Text Pointers

2C136-2E78F: Dialogue Text
  The font goes in a messy total order, so here is
  a table for the text:
      0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
    0    F  0  G  1  H  2  I  3  J  4  K  5  L  6  M
    1 7  N  8  O  9  P  A  Q  B  R  C  S  D  T  E  U
    2 V  +  W     X     Y     Z     ,     '     
    3 .     ?     !     @                       -


2E81D: Room Wierd Data Pointers (messes up screens)

2EF33-2EFA2: Music Track for each Room
  $FF means no music.

2EFA3: More ASM

2F810-2FC0F: Font CHR

------------
Bank 10 ($A)
------------

30010-3400F: Bank with Music Replay Code 

------------
Bank 11 ($B)
------------

34010: ASM

=====================

Room number List:

00: Area 1 entry
01: Area 2 entry (Outside the main part)
02: Area 3 entry
03: Area 4 entry
04: Area 5 entry
05: Area 6 entry
06: Area 7 entry
07: Area 8 entry
08: Area 9 entry
09: Area 10 entry
0A: Area 11 entry
OB: Area 12 entry
0C: Area 13
0D: Area 14
0E: Area 15
0F: Area 16
10: Area 17
11: Area 18
12: Area 19
13: Ground Battle 1
14: Ground Battle 2
15: underground Passage
16: Area 1 Boss
17: Area 2 Boss
18: Area 4 Boss
19: Area 3 Boss
1A: Area 6 Boss
1B: Area 7 Boss
1C: Area 9 Boss
1D: Area 5 Boss
1E: Area 11 Boss
1F: Area 10 Boss
20: Area 8 Boss
21: Area 12 Bionic-arm Miniboss
22: Unused Boss
23: unused Boss (1)
24: Unused Boss (2)
25: unused Boss (3)
26: Area 8 Cannon Passage
27: Area 8 Passage With Soldier
28: Com. Room 1
29: Com. Room 2
2A: Com. Room 3
2B: Com. Room 4
2C: Com. Room 5
2D: Com. Room 6
2E: Com. Room 7
2F: Com. Room 8
30: Com. Room 9
31: Com. Room 10
32: Com. Room 11
33: Com. Room 12
34: Com. Room 13
35: Com. Room 14
36: Com. Room 15
37: Neutral Area Room 13A (1x Bullet)
38: Neutral Area Room 13B (Flares)
39: Neutral Area Room 14A (Blue Comm.)
3A: Neutral Area Room 14B (10x Bullets)
3B: Neutral Area Room 15A (Extra Life)
3C: Neutral Area Room 15B (Orange Comm.)
3D: Neutral Area Room 16A (Green Comm.)
3E: Neutral Area Room 16B (The "Don't be hasty" guy)
3F: Neutral Area Room 17A (Underground Passage guy)
40: Neutral Area Room 17B (Guy in green)
41: Neutral Area Room 18A (Contentless?)
42: Neutral Area Room 18B (Machinegun)
43: Neutral Area Room 19A (4x Bullets)
44: Neutral Area Room 19B (Suicide Soldier)
45: Com. Room ?
46: Com. Room ? (2)
47: Area 1B
48: Area 2B
49: Area 3B
4A: Area 5B
4B: Area 5C
4C: Area 6B
4D: Area 8 Cannon Passage 2
4E: Area 8 Cannon Passage 3
4F: Area 8 Cannon Passage 4
50: Area 8B (Second Big Room)
51: Area 8 Uppstraight passage with Com.Room
52: Area 8 Elevator Passage 1
53: Area 8 Elevator Passage 2 (With Boss-Door)
54: Empty Boss Room
55: Empty Boss Room (2)
56: Com. Room ? (3)
57: Com. Room ? (4)
58: Area 12 Power Source Room 1
59: Area 12 Power Source Room 2
5A: Empty Power Source Room
5B: Empty Power Source Room (2)
5C: Empty Power Source Room (3)
5D: Empty Power Source Room (4)
5E: Area 12 Uppstraight Room 1
5F: Area 12 Uppstraight Room 2
60: Area 12 Chopper Scene
61: Area 12 60-Second Blowup Passage
62: Area 12 Ending
63: Area 12 Killt's Revival Device
64: Area 12B
65: Area 12 The Albatros
66: Intro Scene 2
67: Intro Scene 1
68: Intro Scene 3
69: Ending Scene 1
6A: Ending Scene 2
6B: Credits Scene
6C: Communicator Screen
6D: Ending Scene 3
6E: Unused Room?
6F: Another Unused Room?
=====================

More to come..
