Author Topic: CHRONO CROSS ROOM SCRIPT INVESTIGATION THREAD (formerly event script thread)  (Read 23738 times)

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
I quickly looked at the assembly and it seemed to match. I didn't dig in much details.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
Here is a decompilation of CC room 0 (the title screen room). It's still hard to read, but it gives a few ideas about how it works.



[attachment deleted by admin]
« Last Edit: January 18, 2009, 04:07:44 pm by yaz0r »

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
To update the opcode list:

0x00 OP_STOPThis actualy stops the script, it doesn't return to the calling function (if there was one)
0x01 OP_JUMP(Imm16)Jump to offset
0x02 OP_IF_JUMP(Imm16,Imm16,Imm8,Imm16)Conditional jump, as described before
0x05 OP_CALL(Imm16)Call a sub routine. Max stack depth is 4
0x0D OP_RETURNReturn from sub routine
0x10 OP_SET_VAR(Imm16, SVar16, SignBits)Set variable to value
0x11 OP_SET_VAR_TRUE(Imm16)Set variable to 1
0x12 OP_SET_VAR_FLASE(Imm16)Set variable to 0
0x13 OP_VAR_ADD(Imm16, SVar16, SignBits)Add value to variable
0x14 OP_VAR_SUB(Imm16, SVar16, SignBits)Sub value from variable
0x15 OP_VAR_OR_BIT(Imm16, SVar16, SignBits)Or variable with nth bit
0x16 OP_VAR_XOR_BIT(Imm16, SVar16, SignBits)Xor variable with nth bit
0x17 OP_VAR_INC(Imm16)Increment variable by 1
0x18 OP_VAR_DEC(Imm16)Decrement variable by 1
0x19 OP_VAR_AND(Imm16, SVar16, SignBits)And variable with value
0x1A OP_VAR_OR(Imm16, SVar16, SignBits)Or variable with value
0x1B OP_VAR_XOR(Imm16, SVar16, SignBits)Xor variable with value
0x1C OP_VAR_SHIFT_LEFT(Imm16, SVar16, SignBits)Shift left variable by value
0x1D OP_VAR_SHIFT_RIGHT(Imm16, SVar16, SignBits)Shift right variable by value
0x1E OP_VAR_RAND(Imm16)Set variable to random value
0x1F OP_VAR_RAND_MUL(Imm16, UVar16)Set variable to random mul value
0x20 OP_VAR_MUL(Imm16, SVar16, SignBits)Mul variable by value
0x21 OP_VAR_DIV(Imm16, SVar16, SignBits)Div variable by value
0x22 OP_VAR_SIN(?)Compute sin (haven't looked the args yet)
0x23 OP_VAR_COS(?)Compute cos (haven't looked the args yet)
0x24 OP_VAR_TAN(?)Compute tan (haven't looked the args yet)

ZeaLitY

  • Entity
  • End of Timer (+10000)
  • *
  • Posts: 10795
  • Spring Breeze Dancin'
    • View Profile
    • My Compendium Staff Profile
Thanks a ton.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
I'll post my new findings soon, including the decompiled script of Kid from the programmers ending.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
Here is the decompiled script for the room 1745 of CD2 (the programmer room with Kid). Kid is entity 13 in the script.
I've also included the source for the decompiler.

The interesting part:

---------------------------
| Entity 13 script 1
---------------------------
0x0241: var[0x0400] = rand()%6
0x0246: IF_JUMP(var[0x0400] == 0x0000, 0x025F)
0x024E: op42(0x00, -642, -99, var[0x00C0])
0x0257: op42(0x01)
0x0259: WAIT(60)
0x025C: JUMP(0x02C9)
0x025F: IF_JUMP(var[0x0400] == 0x0001, 0x0278)
0x0267: op42(0x00, -627, -99, var[0x00C0])
0x0270: op42(0x01)
0x0272: WAIT(40)
0x0275: JUMP(0x02C9)
0x0278: IF_JUMP(var[0x0400] == 0x0002, 0x0291)
0x0280: op42(0x00, -607, -99, var[0x00C0])
0x0289: op42(0x01)
0x028B: WAIT(60)
0x028E: JUMP(0x02C9)
0x0291: IF_JUMP(var[0x0400] == 0x0003, 0x029F)
0x0299: WAIT(60)
0x029C: JUMP(0x02C9)
0x029F: IF_JUMP(var[0x0400] == 0x0004, 0x02AD)
0x02A7: SET_ANIMATION(9)
0x02AA: JUMP(0x02C9)
0x02AD: IF_JUMP(var[0x0400] == 0x0005, 0x02BB)
0x02B5: WAIT(90)
0x02B8: JUMP(0x02C9)
0x02BB: IF_JUMP(var[0x0400] == 0x0006, 0x02C9)
0x02C3: SET_ANIMATION(1)
0x02C6: JUMP(0x02C9)
0x02C9: STOP()

Basicaly, the code means:

var[0x0400] = rand() % 6
switch(var[0x0400])
{
case 0:
op42(0x00, -642, -99, var[0x00C0])
op42(0x01)
wait(60)
break;

case 1:
op42(0x00, -627, -99, var[0x00C0])
op42(0x01)
WAIT(40)
break;

case 2:
op42(0x00, -607, -99, var[0x00C0])
op42(0x01)
WAIT(60)
break;

case 3:
WAIT(60)
break;

case 4:
SET_ANIMATION(9)
break;

case 5:
WAIT(90)
break;

case 6:
SET_ANIMATION(1)
break;
}



[attachment deleted by admin]
« Last Edit: January 22, 2009, 08:17:42 pm by yaz0r »

MDenham

  • CC:DBT Dream Team
  • Chronopolitan (+300)
  • *
  • Posts: 330
  • Glowsticks are not a weapon.
    • View Profile
    • Java IRC - konata.echoes-online.com
So, hang on, is the IF_JUMP one taking an address to jump to if the result is false?

If not, you've got your comparisons backwards and they should be != instead.


Disregard, read back through things and either it is a case of massive confusion (read: the list given back on page 3 has all of the comparisons backwards, and it is a jump when true) or the jump is when false.  Either one gives the same result, BTW (jumping if "x>y" is false is the same as jumping if "x<=y" is true).
« Last Edit: January 22, 2009, 10:30:12 pm by MDenham »

Vehek

  • Errare Explorer (+1500)
  • *
  • Posts: 1756
    • View Profile
I was trying some things with the script decompiler (after adding some opcodes to the program) and I noticed it messed up when the byte after a STOP wasn't the next script. (I was testing with Chief's Meadow, Home)
« Last Edit: January 23, 2009, 04:18:40 am by Vehek »

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
Disregard, read back through things and either it is a case of massive confusion (read: the list given back on page 3 has all of the comparisons backwards, and it is a jump when true) or the jump is when false.  Either one gives the same result, BTW (jumping if "x>y" is false is the same as jumping if "x<=y" is true).

the IF_JUMP opcode come directly from what was posted on page 3, maybe there is some differences.

I was trying some things with the script decompiler (after adding some opcodes to the program) and I noticed it messed up when the byte after a STOP wasn't the next script. (I was testing with Chief's Meadow, Home)

Sometime there is some barbage bytes at the start of the fieldScript, but I've never seen any garbage bytes between two scripts. I'll look into that.

MDenham

  • CC:DBT Dream Team
  • Chronopolitan (+300)
  • *
  • Posts: 330
  • Glowsticks are not a weapon.
    • View Profile
    • Java IRC - konata.echoes-online.com
Disregard, read back through things and either it is a case of massive confusion (read: the list given back on page 3 has all of the comparisons backwards, and it is a jump when true) or the jump is when false.  Either one gives the same result, BTW (jumping if "x>y" is false is the same as jumping if "x<=y" is true).

the IF_JUMP opcode come directly from what was posted on page 3, maybe there is some differences.
The main thing that was confusing me is that every processor with a conditional jump that I know of performs the conditional jump when that condition is true.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
The main thing that was confusing me is that every processor with a conditional jump that I know of performs the conditional jump when that condition is true.

Well, they could have used a reversed logic for the script engine, there is nothing against it. I'll check that for sure later.
« Last Edit: January 23, 2009, 09:10:50 am by yaz0r »

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
Also, in case you're wondering, script 0 is the init script, script 1 is ran every frame, script 2 is used when interacting with the entity and script 3 is used when colisioning with the entity (mostly used for entity that trigger room change). Also Entity 0 is always the director, and the last is the debug entity present in nearly every room (entity 15 in my exemple).
This is all guess work, but it seems to fit.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
I was trying some things with the script decompiler (after adding some opcodes to the program) and I noticed it messed up when the byte after a STOP wasn't the next script. (I was testing with Chief's Meadow, Home)

For me, Chief's Meadow home (d0455) output the script:

---------------------------
| Entity 0 script 0
---------------------------
0x0009: SET_SHADING_PALETTE(0x0034)
0x000C: op64(-100)
0x0010: Unk opcode 0x83

and stops there because opcode 0x83 isn't handled by the decompiler yet.

Vehek

  • Errare Explorer (+1500)
  • *
  • Posts: 1756
    • View Profile
As I mentioned, I added some opcodes to the decompiler code.


0x005E: STOP()
0x005F: ENABLE_BACKGROUND_LAYER(128)
0x0062: STOP()
0x0063: if (scriptVar3 && 0x5050) == 0 jump 0xE00
0x0068: Unk opcode 0xFD

Entity 1's first script is supposed to start at 0x67.

yaz0r

  • Architect of Kajar
  • Porrean (+50)
  • *
  • Posts: 65
    • View Profile
Okay. It's quite probable that an opcode before 0x5E is wrongly decoded. There can only by 31 background layers (according to the code), so the ENABLE_BACKGROUND_LAYER is wrong as well.