Jump to content
Kurt_Woloch

Fixing Pole Position (and enhanced source code)

Recommended Posts

In the last days, I've been reading Lou's Pseudo 3D page after reading up on how Sega's sprite-scaling and drawing hardware works. Lou has provided some case studies there, as well as a snippet out of the disassembled code of Enduro. There's also a thread here on Atariage where he discusses with the author of Road Blasters and S.T.U.N. Runner on the Lynx (Solidcorp) how the pseudo 3D on those games works. This made me curious how Pole Position works, especially how it stores the track information and how the curve is calculated out of it.

 

So I went do study its sourde code which has been released some years ago. While searching for this, I also found an old thread about road drawing code where I put up an experiment on the PC drawing a road in pseudo 3D in Pole Position style.

 

Well, I made some progress this morning in finding out how it all works, and while doing so, I kept adding additional comments to the source code because while it does contain some comments, it's far from explaining how everything works, so I had to figure out quite a bit.

 

One thing that occured to me while looking through the code was that the curves never seem to extend all the way down to the player, but keep hovering in a distance from it while the road in front of the player is always straight. I tried to find out what causes this behavior and found that it's no technical reason, but must be some kind of oversight, or maybe a trade-off against something else. Specifically, in the source code, you find two tables SHIFT1 and SHIFT2 which start out with a bunch of zeroes each. For the 3D effect to work properly, these have to be populated differently, otherwise the bend of the curve would have to exceed a certain angle in order to become visible, which never happens in the lower half of the displayed road. Since I found this out, I tried to correct the tables, and this is how this hack comes about. I also amended the MULTIPLY table since it seemed like the road always straightened out near the horizon even if you were in a curve.

 

This, however, wasn't done in the source code, but via a hex editor in the binary file. The source code wasn't changed at all, it only contains many additional comments now. So I've attached the hacked binary as well as the enhanced source code for you.

 

Pole Position Hack.zip

 

Just to visualize what's changed, here's two pictures of roughly the same place on the street, in the middle of the first curve, one with the original version and one with the hack...

 

Before:

 

post-8393-0-55319100-1399138098_thumb.png

 

After:

 

post-8393-0-75438500-1399138113_thumb.png

 

There's more that could be done, but probably not without some serious reprogramming.

 

Enjoy!

 

Kurt

Edited by Kurt_Woloch
  • Like 9
  • Thanks 1

Share this post


Link to post
Share on other sites

I highly appreciate your efforts. This is what I love ;-)

Well done and thanks for sharing!

Share this post


Link to post
Share on other sites

Just out of curiousity, is there a way to verify via the programming that 63,260 is the maximum possible score?

Share this post


Link to post
Share on other sites

Well, not easily, but there should be. I didn't look into the details of scoring, just noted that it's tightly coupled to the car's position on the road... the tens digit gets advanced smoothly, and each time it fully reaches a number, the variable CARY, giving the LSB of the position of the car on the road, advances by one, so there's 1024 possible positions. The first lap gives 10,000 points, and the following ones give 10240 points each if I'm correct. The question would be how much the maximum time remaining would be, and the maximum cars passed. I don't know at which rate the cars can be passed and what lap time the maximum speed would give. Then you'd have to factor in some losses in the first lap of the race by accelerating to full speed, which is further complicated by the fact that there's two gears, so you'd have to find out the optimum point for shifting into 2nd gear as well. Once you've done all this, it should be possible, I think. In my tests, it was certainly possible to go through the laps without ever slowing down (which would be impossible in reality! Keep in mind that the track is based on the then-current version of Fuji Speedway, but greatly simplified to fit into the cart).

Share this post


Link to post
Share on other sites

Thanks, I was just curious... as a kid, I had an Atari where the left button didn't work (I've since learned how to repair that on the board and fixed it). This was one of my favorite games simply because you could drive without ever hitting the brake. My brother and I got really good and could complete the entire course without hitting a wall or a car and never hitting the brake. I believe there is more than one layout of cars on the Grand Prix section because sometimes we would get 63,210 and sometimes 63,260. It was always one or the other, so I just assumed 63,260 was the maximum score possible. Thanks for taking a look at it for me.


Share this post


Link to post
Share on other sites

Pretty cool. I'm impressed that this could be done with just hex editing. Thank you for sharing.

 

Here it is your hack in NTSC:

 

While I was at it, I changed the color of the sky from $86 to $96. I figured it might have a nicer hue on most TVs. I also did an optional one with a darker gray for the road.

post-9364-0-07485900-1399532525_thumb.png post-9364-0-03734700-1399532526_thumb.png

Pole Position (Hack).bin

Pole Position (Hack Darker).bin

 

Original Sky Color:

post-9364-0-06855600-1399532758_thumb.png

Pole Position (Hack Original).bin

Share this post


Link to post
Share on other sites

OK, so I haven't had enough... here's another version of the hack. This time, aside from leaving the improved curcve in, I tinkered with the gameplay variables a bit more. While playing the game, it disturbed me somewhat that you can go through the sharpest curves without braking and still stay on track. This is unrealistic because on the original track (Fuji Speedway) you have to slow down a lot in curves, as the implementation of the track in Gran Turismo 4 shows. So I doubled the values for the centripetal force, forcing you to slow down in nearly every curve. To compensate for this, I've increased some timer values, so while it seems to be impossible to beat the first lap in 58,5 seconds now, you're given a bit more points for qualifying at all, and also an extended lap gives you ten seconds more than before (63 / 60 / 58 instead of 53 / 50 / 48). Still I think this version is much more challenging and realistic. I now get lap times around 65 seconds if I make a lap without crashing. For a comparison, the real record lap time on that track configuration of Fuji Speedway (it has changed multiple times) was about 70 seconds, so still a bit slower.

 

A nasty side effect of this is that the scrolling of the mountains got somewhat uneven, which probably could have been corrected by changing some of the code, but I didn't want to do that. Another side effect is that skidding now slows you down much more than before, so you still actually don't need to brake.

 

Will you make it through all four laps with this version?

 

Pole Position Hack 2.zip

  • Like 1

Share this post


Link to post
Share on other sites

Has anyone ever figured out the funky symbol to the left of the bargraph?

It's a known an emulation glitch. On a real 2600 it appears as as zero, for 0-200 mph on the sides of the bar.

  • Like 1

Share this post


Link to post
Share on other sites

Funny you should mention that... I'm actually trying to do just that. At least I'm trying to comment the disassembly. Alas, there isn't the original commented source code around like for 2600 Pole Position, so it's harder to find out what's what. There's also no equates in the disassembly, and I'm not used to programming the 7800, and the game is four times as large (32K vs. 8K), although about half of that is data. I couldn't find the place where the curve gets calculated yet, but I'm trying to figure something out. Anyway, I think the curves on the 7800 are looking a bit more realistic than on the 2600.

Share this post


Link to post
Share on other sites

It's a known an emulation glitch. On a real 2600 it appears as as zero, for 0-200 mph on the sides of the bar.

I was wondering the same thing!

I was thinking it was a symbol for the shifter, dot up=high, dot down=low, but the center dot doesn't move.

Share this post


Link to post
Share on other sites

Has anyone changed the color of the oncoming cars so that they are not all yellow?

+1

Oncoming car color just looks wrong.

Maybe it has to be the same as the center lane dashes?

I'd be okay with black, gray, near-white.

Share this post


Link to post
Share on other sites

+1

Oncoming car color just looks wrong.

Maybe it has to be the same as the center lane dashes?

I'd be okay with black, gray, near-white.

It does. The center line is made from M1, and the enemy car is made out of P1, so the color is shared.

 

 

But you can change that color if you like. It is stored in at $D537 (bank 0), or $0537 if you are using HOM3.

Share this post


Link to post
Share on other sites

It does. The center line is made from M1, and the enemy car is made out of P1, so the color is shared.

 

But you can change that color if you like. It is stored in at $D537 (bank 0), or $0537 if you are using HOM3.

Thanks again Omegamatrix! That's it.

Share this post


Link to post
Share on other sites

This is a color hack of the above KevinMos3 "Pole Position (Hack Darker).bin"

White cars. Couldn't stop there.

Mountains: "green" and "For purple mountain majesties. Above the fruited plain!" (Mostly corn fruit.)

Pole Position Hack 5.bin

 

med_gallery_29575_1164_156949.png

  • Like 1

Share this post


Link to post
Share on other sites

^

How does this look on PAL systems?

 

:)

Share this post


Link to post
Share on other sites

^

How does this look on PAL systems?

 

:)

This first hack by Kurt is PAL.

My hack of a hack of a hack looks like this in PAL:

post-29575-0-83215500-1400333719_thumb.png

Share this post


Link to post
Share on other sites

Thanks for the pic. It seems us PAL players will be racing in the Blue Ridge Mountains. :P

 

I'm looking forward to playing some Pole Position tonight. There are certainly quite a few ROMs for me to mess around with. :)

Share this post


Link to post
Share on other sites

If you want to make a PAL60, use a hex editor to change the following in the NTSC file:

424 is front mountain

430 is back mountain

513 is horizon under mountain, above road

537 is center lines and oncoming car color.

 

Sorry don't know other colors like the road and sky and speed bar colors...

You would probably want to tweak the player car color (too orange), then maybe the speed bar to red/blue, unless you like orange/purple :D

Share this post


Link to post
Share on other sites

I've pushed this a little further. I took Kurt's commented source and converted it to compile with DASM. Next I added in switches so that you could compile both of Kurt's hacks, Kevin's Hacks, and iesposta's hack. I also added in defines for the colors, and put them at the top of the source. It is a lot easier to change the colors now. :) Next I added in some visual graphics beside the graphics bytes (to see them better), and finally my own hack for a Sega Genesis controller.

 

With this source, by changing the switches at the top you can make different combinations of roms. You can also make exact matches for all 3 non-hacked dumps, and of course all the hacks in this thread. Lastly, I compiled some PAL60 roms of Kurt's hacks, and a NTSC rom of Kurt's second hack.

 

 

Kurt if you are reading this then look at the source. There might be an error at $19E7 (or $F9E7 bank 1).

 

 

PolePosition(updated).zip

  • Like 3

Share this post


Link to post
Share on other sites

OK, thank you, Omegamatrix for doing all this stuff. I've looked through the code you supplied, and I did spot some errors which I or someone else may have made...

 

I don't know which line you mean by the address $19E7. I don't have DASM set up so I could readily compile the code myself at the moment, and I don't want to go into this right now since I've got the flu... maybe next week.

 

However, as for the errors:

At the comment "; Omega: I think this 30 value should be 14...", I think you're correct. It was supposed to be exactly double the previous amount, so 14.

 

Then there's an error in the track curves... the code itself is not wrong, but its representation is.

The 3rd line starts out with 34, which is an unusually high number. But the 3rd line has got 26 bytes while the 2nd line has 24.

In the original source code, however, all lines of the MULTIPLY table have got exactly 25 bytes. So the byte 34 at the start of the

third line of my hack should actually be moved to the end of the 2nd line to be represented correctly (which, however, results in the

same code).

 

By the way, I think the tables SHIFT1 and SHIFT2 could be done away with completely by doing the calculations slightly differently (the way they are set up now in my hack). However, I can't figure out how exactly right now since I actually haven't completely figured out how all the adding and comparing when calculating the curve works. Or maybe I had figured it out when I posted the hack, but I forgot about it by now.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...