Friday, 14 October 2022

Thousands of lines down, thousands more to go...

Today was a day of waiting around and fortunately I had my laptop with me so I got quite a bit of work done on Xevious. Still churning through the code and slowly discovering not only new things, but old mistakes/assumptions I had made. But progress has been good.

My understanding of the function of the various object tables is firming up as I complete the handlers for more and more objects. There is some AI (difficulty) logic that has revealed itself as well. Quite a few "objects" in the SUB CPU table are in fact placeholders for AI/difficulty parameters that change as you progress through the levels. Pretty clever way to do it, and easy to tweak during development. More on this in a later blog.

Oh and the placement of the bonus flags is (in theory) pseudo-random, but it is designed not to appear too close to the Solvalou. So I'd imagine the trend for each of them to appear on one side or the other is probably related to the pattern of (ground-based) enemies leading up to them!?!

The (active) object table is divided into sections and dictates limitations on the number of various elements of the game. These limits include; 14 ground-based enemies (note that some take multiple object entries, eg. Boza Logram (Dome Array) takes 5), 16 Bacura (indestructible rotating shields), 3 Solvalou shots, 19 enemy bullets and (only) 6 airborne enemies.

The game also only uses half the number of available hardware sprites (64/128)!

The amount of code to comment in the MAIN CPU is a bit daunting when I look at what I've done, and what else needs to be done. Not surprisingly the bulk of the code is handling the various objects in the game; I think I've commented the rest of it already. Last time I checked the listing was some 21,000 lines, but that still contains a lot of single-byte data storage that I haven't compacted yet.

EDIT: I've just checked and there's about 11,000 lines in the listing that is ROM code/data.

I've only got a few ground-based enemies left to RE, including what I think will be the most interesting (and complicated) - the Domogram (Slider). I'm keen to know if the movements are pre-programmed (as I suspect), or follow the background map...

The code for airborne enemies still eludes me, though that's because their appearance in the game is driven by AI logic (and probably some randomness) rather than appearing on a map. That code is going to be the most challenging I fear.

Onwards!

Tuesday, 11 October 2022

Tedium and how Easter Eggs are made.

Plenty of code commented in the last few days!

It's all pretty tedious atm actually; numerous routines to handle the various objects which all reference the same table locations over and over again. There's a ridiculous number of different Grobda (tanks) in the code for example (I think some of them are unused) and some of them seem to be exact copies of others.

I recall being at this stage during the RE of Knight Lore. Very productive for a while, but tedious.

I've managed to identify a few of the other objects purely from their sprite codes. And I can confirm that some 'objects' in the SUB CPU ROM object table are actually place-holders for parameters, such as the firing frequency for subsequent Lograms for example.

I haven't tried to estimate what percentage of the object handler code I've commented so far, but there's still at least a few days more to do. Some of it, like the Andor Gensis (mothership), looks even more tedious. Some objects have fixed positions in the object table, and are referenced directly from other object handlers; the player's Solvalou a prime example. And one or two parameters in the object table still elude my understanding. But still lots to do before I hit any walls.

Some trivia. The Easter Egg is implemented as an object with an invisible sprite. By moving to the right and holding down the bomb button at the start of the game, you're guaranteed to hit it because you're basically bombing every row. But if you know where it is, you can trigger it with a single shot. I patched the code to show the position with a Solvalou sprite instead - here's where it is located:

The Easter Egg, patched with a Solvalou sprite

Onwards with the RE'ing...

Saturday, 8 October 2022

SUB CPU 90% complete

Very brief update.

I've made quite a bit of progress in the last 48hrs. The main data structures are more-or-less complete which has opened up quite a bit of code in the MAIN CPU for commenting. That will probably keep me going for a few more sessions before I need to stop and think too much again.

The SUB CPU is around 90% complete now. Much of the remaining code is concerned with adding objects that I haven't identified to the object table. I'm beginning to suspect that some of these 'objects' aren't in fact physical objects, but flags/placeholders for logic/events.

I've also had some insight into a small portion of the AI logic for the game; after recently reading on the Namco Wiki about how destroying the Zolbak (Detector Dome) will reduce the amount of enemies that appear, I came across that logic in the code.

There's a decent number of discrete variables in the code that will be more difficult to RE. That's not unusual for this type of exercise. I recall the last few variables in Knight Lore were stubbornly refusing to reveal their purpose!

Thursday, 6 October 2022

Code and data structures starting to take shape

Now that the "secrets" map is complete I've returned to RE'ing the code.

The architecture of the code and data structures in memory are slowly starting to take shape. I won't go into any detail at this point - mainly because it's early days and I could have made some wrong assumptions - but there are some interesting aspects to it. And some puzzling ones too. But as I said, early days yet. I will say it's similar to a few other arcade games I've RE'd recently, yet more complex.

It's becoming clear that the SUB (graphics) CPU does little more than set up map and graphics-related data for the MAIN CPU. It doesn't seem to handle any of the game logic at all. There are sections of it that I still need to understand but, if I'm not mistaken, I've RE'd the majority of the functionality.

[I'm wondering now whether it was used - unchanged - on Super Xevious? I should check that.]

There's a fair bit of RAM shared between the CPUs, but very little in the way of communication between them. I haven't found any mechanism for passing or queuing of any messages, for example. I suspect there's a handful of interlock/semaphore bytes, but that's probably about it.

I have actually identified how/where the MAIN CPU handles each of the objects now. I'm still fleshing out my understanding of it but I have, for example, identified a few routines for certain objects from the map. It's interesting how it's done, and probably worth a blog entry on its own.

For now there's still plenty of work to be done in this area, so I'll forge ahead.

Tuesday, 4 October 2022

Now with bonus Bonus Flags!

Very quick update. A slight tweak to the sprite positions for the objects on the map, removed the Sol Tower in area 6 that doesn't appear in the game to avoid confusion, and added the bonus flags.

All secrets that appear in-game


Those pesky Sol Towers!

 More eye candy, and another mystery!

First something I mentioned in a few entries back; namely not understanding how two (2) banks of background tiles were selected. Turns out that bit 0 of the attribute byte (in bg_colorram) selects the tile bank. Easy explanation in the end.

And although I haven't exactly wrapped my head around it, it would appear that the two ROMs that handle the address mapping for the 3rd map ROM do indeed implement some sort of meta/macro tile mechanism. Now that I say that out aloud, it's not that surprising. Given that it provides both a tile code and colour/attribute byte for 32K tiles (ie. 64KB) in just 16kB of ROM, it's not a bad compression ratio.

Onto the eye candy and the mystery then.

I've done a little more decoding of the object table, and identified a few more ground-based objects, some of which aren't stationary. It's worth mentioning that this encoding also differentiates between the Grobda (tanks) with different behaviours; those that are stationary, those that stop when fired upon, and those that dart forward, for example.

As well as decoding more of the table, I've updated the map tool to indicate the location of the Sol Towers using the actual sprites. As well as producing a BMP file for each area, it also merges them onto a single BMP for easier reference. It's rather large, but looks very pretty. Here is the PNG version:

All 16 areas showing the Sol Tower locations

And it's pretty obvious now that towers don't appear in the same locations of the global map in areas that have overlapping global map space. At some point I'll update the tool to indicate locations of all the objects. And probably produce the iconic global map as well.

And finally, the mystery. Last entry I mentioned a 46th Sol Tower that hadn't been documented yet. There's a good reason for that; it doesn't actually appear in the game! Why not? I have no definite answer - I can step through the code and see the tower being read from the object table and handled just like every other tower. But the end result is, well, nothing!?!

It could be a bug related to the fact that there is a Logram (Sphere Station) on the same row - I've yet to determine if any other towers have other non-tower objects on the same row. As an experiment I patched the object table to move the tower one row later - and it appears - which suggests I could be right!?!

The missing Sol Tower in-game in Area 6 - one row above where it should appear

So now that I have finally done what I've wanted to do for a very, very long time, I will return to RE'ing the rest of the code. I am intending the next task be working out how the objects are handled once they're copied from the object table; that'll be very interesting, and will open up a lot of the code I'm thinking (and as a result be very time consuming).

Monday, 3 October 2022

The Xevious Map starts to reveal its secrets!

A little more RE'ing and a lot more eye candy to come in the next few sessions!

More work on decoding the area object tables; I can (syntax) parse the complete tables even though I have only identified (I think) the EVEZOO Easter Egg, ground-based objects and the bonus flags. And for the abovementioned ground-based objects I know the x-coordinate of the sprite now.

Between some dynamic analysis and the MAME source, I've managed to create a new tool to extract each of the area maps from the ROMs and save them as bitmap files. And as the maps are generated row-by-row, I now parse the object tables. It should be trivial to (also) produce the global map.

With a quick 'n' dirty hack I can show the location of the Sol Towers with a red square.


Area 6 with Sol Tower locations in red.

This will get built on as I further RE the tables and ultimately I should be able to show all the objects. I'll update the tool to show the correct sprites for the currently-identified objects, then return to the task of RE'ing the rest of the code.

Some game trivia; there are a total of 46 Sol Towers in the game, many more than were originally documented in the StrategyWiki Walkthough, and even one more than documented in SPM's comprehensive Xevious Secrets YouTube video (in area 6, as shown above!) I knew most of them when I played back in the day, but looking at the video/maps now, I'm sure there's a few that I didn't in fact know about!