Author Topic: Color changing of the needle  (Read 418 times)

Ryoma

  • Skid`s Nightmare
  • **
  • Posts: 716
    • View Profile
    • My méga
Color changing of the needle
« on: August 22, 2021, 06:46:18 PM »
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.
Disappointed having unfairly lost the newbies race zct238.

Daniel3D

  • Master of Opponents
  • ***
  • Posts: 833
    • View Profile
Re: Color changing of the needle
« Reply #1 on: August 22, 2021, 07:23:41 PM »
I think that is because that mask is only active when the wheel is turned.
Ever tried, ever failed. Try again, fail better.

Currently running 19 separate instances of Stunts or 4D Sports Driving.
---------
Stunts resources.
https://mega.nz/folder/JM8HQI5a#mH5ZBNwXC0eEBmockWo50A

Ryoma

  • Skid`s Nightmare
  • **
  • Posts: 716
    • View Profile
    • My méga
Re: Color changing of the needle
« Reply #2 on: August 22, 2021, 07:57:13 PM »
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.
Disappointed having unfairly lost the newbies race zct238.

Daniel3D

  • Master of Opponents
  • ***
  • Posts: 833
    • View Profile
Re: Color changing of the needle
« Reply #3 on: August 22, 2021, 08:45:53 PM »
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.
Ever tried, ever failed. Try again, fail better.

Currently running 19 separate instances of Stunts or 4D Sports Driving.
---------
Stunts resources.
https://mega.nz/folder/JM8HQI5a#mH5ZBNwXC0eEBmockWo50A

Ryoma

  • Skid`s Nightmare
  • **
  • Posts: 716
    • View Profile
    • My méga
Re: Color changing of the needle
« Reply #4 on: August 22, 2021, 09:38:41 PM »
Red for all cars will be cool!!!!
Disappointed having unfairly lost the newbies race zct238.

Daniel3D

  • Master of Opponents
  • ***
  • Posts: 833
    • View Profile
Re: Color changing of the needle
« Reply #5 on: August 22, 2021, 09:57:02 PM »
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

Code: [Select]
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.
« Last Edit: August 22, 2021, 11:33:34 PM by Daniel3D »
Ever tried, ever failed. Try again, fail better.

Currently running 19 separate instances of Stunts or 4D Sports Driving.
---------
Stunts resources.
https://mega.nz/folder/JM8HQI5a#mH5ZBNwXC0eEBmockWo50A

Cas

  • Straight Specialist
  • ***
  • Posts: 1114
  • Think different. That's OK... as long as you think
    • View Profile
    • Dimioca Labs
Re: Color changing of the needle
« Reply #6 on: August 23, 2021, 12:55:34 AM »
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

  • Straight Specialist
  • ***
  • Posts: 1114
  • Think different. That's OK... as long as you think
    • View Profile
    • Dimioca Labs
Re: Color changing of the needle
« Reply #7 on: October 22, 2021, 08:48:39 AM »
Adding something here...

My idea is that the line that says:
Code: [Select]
push    meter_needle_coloris 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:
Code: [Select]
push simd_player.field_A6+4Of 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.
« Last Edit: October 22, 2021, 09:04:32 AM by Cas »
Earth is my country. Science is my religion.

Daniel3D

  • Master of Opponents
  • ***
  • Posts: 833
    • View Profile
Re: Color changing of the needle
« Reply #8 on: October 22, 2021, 09:20:42 AM »
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)
Ever tried, ever failed. Try again, fail better.

Currently running 19 separate instances of Stunts or 4D Sports Driving.
---------
Stunts resources.
https://mega.nz/folder/JM8HQI5a#mH5ZBNwXC0eEBmockWo50A

Cas

  • Straight Specialist
  • ***
  • Posts: 1114
  • Think different. That's OK... as long as you think
    • View Profile
    • Dimioca Labs
Re: Color changing of the needle
« Reply #9 on: October 22, 2021, 09:08:05 PM »
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.