News:

Herr Otto Partz says you're all nothing but pipsqueaks!

Main Menu

Color changing of the needle

Started by Ryoma, August 22, 2021, 06:46:18 PM

Previous topic - Next topic

Ryoma

While working on the Delta, I made a mistake with inm1 and succeed to change color of needle.

I try again with the Musa and it works only when turning wheel.

See enclosed pictures.

Daniel3D

I think that is because that mask is only active when the wheel is turned.
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Ryoma

Yes in order to priority of display : insX and inmX and after dasX. And inm2 does not exist anymore.

So this solution is not the way to go. I made a lot of tests.

Daniel3D

O don't think that changing the color of the needle is possible.
The car files contain the graphics and the needle position.
But no information about the animation of the needle.
Therefore, I think that the needle is drawn by the main game engine.
That is where the color is given. If the color can be changed, then it will be for all cars.
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Ryoma

Red for all cars will be cool!!!!

Daniel3D

#5
I had a quick look in the source and found this.

https://bitbucket.org/dreadnaut/restunts/src/master/src/restunts/asm/seg005.asm#lines-2710

meter_needle_color


loc_23456:
    cmp     [bp+var_6], 0
    jnz     short loc_23485
    mov     ax, si
    shl     ax, 1
    mov     [bp+var_20], ax
    push    meter_needle_color
    mov     bx, ax
    mov     al, (simd_player.spdpoints+1)[bx]
    sub     ah, ah
    push    ax
    mov     al, simd_player.spdpoints[bx]
    push    ax
    push    simd_player.spdcenter.y2
    push    simd_player.spdcenter.x2
    call    preRender_line
    add     sp, 0Ah
loc_23485:
    mov     ax, di
    shl     ax, 1
    mov     [bp+var_20], ax
    push    meter_needle_color
    mov     bx, ax
    mov     al, (simd_player.revpoints+1)[bx]
    sub     ah, ah
    push    ax
    mov     al, simd_player.revpoints[bx]
    push    ax
    push    simd_player.revcenter.y2
    push    simd_player.revcenter.x2
    call    preRender_line
    add     sp, 0Ah
    mov     al, [bp+var_2]
    cbw
    or      ax, ax
    jz      short loc_234BE
    cmp     ax, 2           ; st. whl. position flag
    jz      short loc_234EC
    jmp     short loc_234DE
    ; align 2
    db 144


After tracing the meter_needle_color back it is loaded without value, it seems to be tied to the font color.
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Cas

Tweaking the code a little bit, it could be possible to get this value loaded from a byte in "simd" instead of that variable. This would make the needle colour configurable. Just loading it this way maybe can be done without changing the opcode length, but there are a few catches.

I think the best candidate in "simd" for this is the byte right after the number of gears. That is, the number of gears is being stored as a word, but only the lower byte is interpreted, so the high byte is normally zero, but if you change it, it has no effect. Of course, 0 is black, so doing this would make the needle of all previously created cars to be black. With some additional code, this byte could be, for example, XORed against 0Fh or ADDed 0Fh to, in order to make white the default.

I'll be researching on that, although I have a ton of other things to do and not much time.
Earth is my country. Science is my religion.

Cas

#7
Adding something here...

My idea is that the line that says:
push    meter_needle_color
is actually pushing from a memory location in Stunts data, something like push [3215h]. This position is fixed relative to Stunts data segment.

Unless Stunts uses more than one data segment for its configuration data, the current car parameters must also be located at some other point within the same segment. Now, I don't know if all the resources are loaded at fixed positions, but it would make sense if they were. If the whole CAR*.RES file is loaded as one thing, then it's going to be more complicated and will require recompilation. But let's say that "simd" is always loaded at the same offset relative to DS. Then, there exists another offset that we can place at that push, maintaining the same binary length, that points to an unused parameter from the car.

The simplest way to get this done then would be to pick what CarWorks calls the "red#5 mysterious parameter" because this one appears to be 16 for all cars by default and 16 happens to be white in Stunts palette. Then, every already existing car would still keep a white needle, but it would only take a simple edit with CarWorks to make a car use any other colour from the palette.

Notice that this does not change the value of the variable "meter_needle_color". What it does is pass another variable as a parameter instead. If we were instead to change the former, then the needle colour would change, but would be the same for all cars.

EDIT: I found it... If I am not mistaken, that single line of code should be changed to:
push simd_player.field_A6+4
Of course, to know the new value, we would have to assemble Restunts anyway, but once we do, if it works, we'll be able to spot the single word that has changed in the binary file and from then on, we only need a tiny patch. This... if I'm right about my assumptions.
Earth is my country. Science is my religion.

Daniel3D

If I read the source correctly the needle is loaded after the dashboard images. So taking a parameter from the car should work.

Following the trail of parameters leads to the color of the text.
So if we would have changed the text color of the menus at one point the needle would have changed as well.
Pointing to the car files sounds really good.

You will have to update carworks, and the unused byte you want to use has to initial be set to default white for all cars. (The current value would result in black I believe)
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Cas

I chose Red#5 because it defaults to 16, which is white in Stunts. I was thinking that the line to be replaced appears twice in the code and I think this is because the parameter is passed to the function twice: once for each instrument. If so, then we could actually issue different parameters and therefore, allow for different colours for the needles, but there isn't another parameter that defaults to a value that's white in Stunts palette, so if we do that, original cars will change the colour of one of their needles and we would have to touch their RES files. Not something I would like to do. Anyway, it'd be very interesting to test if that works, because it'd give us an idea of what we can do for future modifications.

If, instead of a patch, we really do reassemble Restunts, then we can simply add more lines and have the two needle colours be read from the same word parameter as two bytes and default to white when the values are the same that we find in original cars.

I have never compiled/assembled Restunts. I can do my tricks to patch this via binary research, but if anybody can hint me on the best way to do this, I'll appreciate it. I'm reading the code and there's this makefile, but while I know what it is for, I really don't know the format very well. Besides, I should compile this in DOSBox, so I'm not sure if I would have to use this file.
Earth is my country. Science is my religion.

Daniel3D

Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Cas

So yes!  We did it! :D

Basically, what we have achieved after some work with Daniël was the following:

  • You can change a field previously unused in the CAR*.RES file of your car to select any needle colour from the 256 palette colours Stunts uses
  • Both needles will change to that colour for your car
  • All cars already in existence will continue to display white needles, which is the default

We also tried to achieve more, but have been having some problems so far:

  • Tried to make the colours separately configurable without breaking the white default. This broke the code
  • We can easily make the colours separate, but one of them would not default to white
  • We'll be researching to see why the code breaks. I suspect that Stunts assumes some code lengths
Earth is my country. Science is my religion.

Daniel3D

#12
The file is attached. It's compatible with Stunts 1.1 and the new Stunts 1.1 Mod 1.0.
This change will only be for the MCGA graphics versions.

With CarWorks, currently, you can change it by going to the "mysterious" parameters and changing Red#5.

But a better way will be available when CAS updates it, Because it is not "mysterious" anymore.
The GTON attached is the GTO with the needle color changed, we used it for testing.

The value can be changed in stressed by changing the same byte.
Red#5 is marked in the picture below.
The number 16 (decimal) is default, and that is white in the stunts palet.(second row first)

In stressed it is 10 (hexadecimal) the pallet starts at 0.
1st row = 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F (in hexadeximal)
each row has the next starting number. Below a lookup table to quickly translate dec to hex.
https://www.javatpoint.com/hexadecimal-numbers-list

So 07 is grey, and 27 is bright red.

EDIT Dec 18th: added a reference picture with the hex numbers filled in to attachments.
Edison once said,
"I have not failed 10,000 times,
I've successfully found 10,000 ways that will not work."
---------
Currently running over 20 separate instances of Stunts
---------
Check out the STUNTS resources on my Mega (globe icon)

Cas

Yep!  I'll update CarWorks for this, but I would like to see if we can solve the differentiation problem between the needles first, so I just make one change in CarWorks instead of two. In preparation for that, I advise to try this new feature this way: when you make a new car or edit your custom car, set the myterious red #5 field to your desired needle colour value from 0 to 255 according to Stunts palette. This field is a word. Make sure to keep its high byte zero. In other words, don't set it to anything greater than 255 or else, this will break your car look in the future if we add separate colours for the needles. My idea is to make it so that the high byte will be an offset between the needle colours. Thus, the current default (zero) will result in both needles being the same colour. A value of one would make the RPM meter needle the following colour from that of the speed-o-meter and so on.

Following these rules, not only will original cars continue to look the same in the modded version, but new cars will also look the closest to normal in the original Stunts and besides, you'll always know what that look will be, so you can take that into account.
Earth is my country. Science is my religion.

Ryoma

Good news well done guys...a lot of modification will come.