Skip to content

Commit

Permalink
Change: Reduce D0xx usage where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
glx22 committed Apr 21, 2024
1 parent 8843c5e commit 945227b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 79 deletions.
9 changes: 8 additions & 1 deletion nml/actions/action2var.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def __init__(self, action_feature, var_range=0x89):
self.var_list = []
self.var_list_size = 0
self.proc_call_list = []
self.in_store_op = False

def preprocess_binop(self, expr):
"""
Expand Down Expand Up @@ -571,6 +572,9 @@ def parse_binop(self, expr):
if expr.op.act2_num is None:
expr.supported_by_action2(True)

if expr.op == nmlop.STO_TMP:
self.in_store_op = True

if (
isinstance(expr.expr2, (expression.ConstantNumeric, expression.Variable))
or isinstance(expr.expr2, (VarAction2LoadTempVar, VarAction2LoadCallParam))
Expand Down Expand Up @@ -601,6 +605,9 @@ def parse_binop(self, expr):

self.parse(expr2)

if expr.op == nmlop.STO_TMP:
self.in_store_op = False

def parse_constant(self, expr):
var = VarAction2Var(0x1A, 0, expr.value)
self.var_list.append(var)
Expand All @@ -614,7 +621,7 @@ def parse_param(self, expr):
self.var_list_size += var.get_size()

def parse_string(self, expr):
str_id, actions = action4.get_string_action4s(0, 0xD0, expr)
str_id, actions = action4.get_string_action4s(0, 0xDC if self.in_store_op else 0xD0, expr)
self.extra_actions.extend(actions)
self.parse_constant(expression.ConstantNumeric(str_id))

Expand Down
Binary file modified regression/expected/013_train_callback.grf
Binary file not shown.
158 changes: 80 additions & 78 deletions regression/expected/013_train_callback.nfo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Escapes: D= = DR D+ = DF D- = DC Du* = DM D* = DnF Du<< = DnC D<< = DO D& D| Du/ D/ Du% D%
// Format: spritenum imagefile depth xpos ypos xsize ysize xrel yrel zoom flags

0 * 4 \d77
0 * 4 \d78

1 * 54 14 "C" "INFO"
"B" "VRSN" \w4 \dx00000000
Expand All @@ -16,9 +16,11 @@
00
00
2 * 52 08 08 "NML\13" "NML regression test" 00 "A test newgrf testing NML" 00
3 * 28 04 00 FF 02 \wxD000 "NML Test bulk wagon" 00 "\80" 00
3 * 8 04 00 FF 01 \wxD000 "\80" 00

4 * 208 00 08 \b1 32 FF \wx0000
4 * 26 04 00 FF 01 \wxDC00 "NML Test bulk wagon" 00

5 * 208 00 08 \b1 32 FF \wx0000
09 "WDPR" "SCRP" "CMNT" "WOOD" "LVST"
"STEL" "VEHI" "BRCK" "WOOL" "BUBL"
"TOYS" "FZDR" "FRUT" "FRVG" "FOOD"
Expand All @@ -30,111 +32,111 @@
"MAIL" "BATT" "SWET" "RUBR" "FMSP"
"ENSP" "MNSP" "FICR" "PLAS" "PLST"

5 * 28 00 08 \b1 05 FF \wx0000
6 * 28 00 08 \b1 05 FF \wx0000
12 "RAIL" "ELRL" "MONO" "MGLV" "TRPD"

6 * 6 01 00 \b8 FF \wx0004
7 * 6 01 00 \b8 FF \wx0004

7 temperate_railwagons.png 8bpp 0 25 8 24 -3 -12 normal
8 temperate_railwagons.png 8bpp 16 25 22 17 -14 -9 normal
9 temperate_railwagons.png 8bpp 48 25 32 12 -16 -8 normal
10 temperate_railwagons.png 8bpp 96 25 22 17 -6 -9 normal
8 temperate_railwagons.png 8bpp 0 25 8 24 -3 -12 normal
9 temperate_railwagons.png 8bpp 16 25 22 17 -14 -9 normal
10 temperate_railwagons.png 8bpp 48 25 32 12 -16 -8 normal
11 temperate_railwagons.png 8bpp 96 25 22 17 -6 -9 normal

11 temperate_railwagons.png 8bpp 0 250 8 24 -3 -12 normal
12 temperate_railwagons.png 8bpp 16 250 22 17 -14 -9 normal
13 temperate_railwagons.png 8bpp 48 250 32 12 -16 -8 normal
14 temperate_railwagons.png 8bpp 96 250 22 17 -6 -9 normal
12 temperate_railwagons.png 8bpp 0 250 8 24 -3 -12 normal
13 temperate_railwagons.png 8bpp 16 250 22 17 -14 -9 normal
14 temperate_railwagons.png 8bpp 48 250 32 12 -16 -8 normal
15 temperate_railwagons.png 8bpp 96 250 22 17 -6 -9 normal

15 arctic_railwagons.pcx 8bpp 0 25 8 24 -3 -12 normal
16 arctic_railwagons.pcx 8bpp 16 25 22 17 -14 -9 normal
17 arctic_railwagons.pcx 8bpp 48 25 32 12 -16 -8 normal
18 arctic_railwagons.pcx 8bpp 96 25 22 17 -6 -9 normal
16 arctic_railwagons.pcx 8bpp 0 25 8 24 -3 -12 normal
17 arctic_railwagons.pcx 8bpp 16 25 22 17 -14 -9 normal
18 arctic_railwagons.pcx 8bpp 48 25 32 12 -16 -8 normal
19 arctic_railwagons.pcx 8bpp 96 25 22 17 -6 -9 normal

19 arctic_railwagons.pcx 8bpp 0 250 8 24 -3 -12 normal
20 arctic_railwagons.pcx 8bpp 16 250 22 17 -14 -9 normal
21 arctic_railwagons.pcx 8bpp 48 250 32 12 -16 -8 normal
22 arctic_railwagons.pcx 8bpp 96 250 22 17 -6 -9 normal
20 arctic_railwagons.pcx 8bpp 0 250 8 24 -3 -12 normal
21 arctic_railwagons.pcx 8bpp 16 250 22 17 -14 -9 normal
22 arctic_railwagons.pcx 8bpp 48 250 32 12 -16 -8 normal
23 arctic_railwagons.pcx 8bpp 96 250 22 17 -6 -9 normal

23 temperate_railwagons.png 8bpp 0 225 8 24 -3 -12 normal
24 temperate_railwagons.png 8bpp 16 225 22 17 -14 -9 normal
25 temperate_railwagons.png 8bpp 48 225 32 12 -16 -8 normal
26 temperate_railwagons.png 8bpp 96 225 22 17 -6 -9 normal
24 temperate_railwagons.png 8bpp 0 225 8 24 -3 -12 normal
25 temperate_railwagons.png 8bpp 16 225 22 17 -14 -9 normal
26 temperate_railwagons.png 8bpp 48 225 32 12 -16 -8 normal
27 temperate_railwagons.png 8bpp 96 225 22 17 -6 -9 normal

27 temperate_railwagons.png 8bpp 0 350 8 24 -3 -12 normal
28 temperate_railwagons.png 8bpp 16 350 22 17 -14 -9 normal
29 temperate_railwagons.png 8bpp 48 350 32 12 -16 -8 normal
30 temperate_railwagons.png 8bpp 96 350 22 17 -6 -9 normal
28 temperate_railwagons.png 8bpp 0 350 8 24 -3 -12 normal
29 temperate_railwagons.png 8bpp 16 350 22 17 -14 -9 normal
30 temperate_railwagons.png 8bpp 48 350 32 12 -16 -8 normal
31 temperate_railwagons.png 8bpp 96 350 22 17 -6 -9 normal

31 temperate_railwagons.png 8bpp 0 150 8 24 -3 -12 normal
32 temperate_railwagons.png 8bpp 16 150 22 17 -14 -9 normal
33 temperate_railwagons.png 8bpp 48 150 32 12 -16 -8 normal
34 temperate_railwagons.png 8bpp 96 150 22 17 -6 -9 normal
32 temperate_railwagons.png 8bpp 0 150 8 24 -3 -12 normal
33 temperate_railwagons.png 8bpp 16 150 22 17 -14 -9 normal
34 temperate_railwagons.png 8bpp 48 150 32 12 -16 -8 normal
35 temperate_railwagons.png 8bpp 96 150 22 17 -6 -9 normal

35 temperate_railwagons.png 8bpp 0 275 8 24 -3 -12 normal
36 temperate_railwagons.png 8bpp 16 275 22 17 -14 -9 normal
37 temperate_railwagons.png 8bpp 48 275 32 12 -16 -8 normal
38 temperate_railwagons.png 8bpp 96 275 22 17 -6 -9 normal
36 temperate_railwagons.png 8bpp 0 275 8 24 -3 -12 normal
37 temperate_railwagons.png 8bpp 16 275 22 17 -14 -9 normal
38 temperate_railwagons.png 8bpp 48 275 32 12 -16 -8 normal
39 temperate_railwagons.png 8bpp 96 275 22 17 -6 -9 normal

// Name: bulk_wagon_coal_default_group - feature 00
39 * 13 02 00 FF \b2 \b2
40 * 13 02 00 FF \b2 \b2
\w0 \w1
\w0 \w1

// Name: bulk_wagon_coal_arctic_group - feature 00
40 * 13 02 00 FE \b2 \b2
41 * 13 02 00 FE \b2 \b2
\w2 \w3
\w2 \w3

// Name: bulk_wagon_coal2_group - feature 00
41 * 13 02 00 FD \b2 \b2
42 * 13 02 00 FD \b2 \b2
\w4 \w5
\w4 \w5

// Name: bulk_wagon_grain_group - feature 00
42 * 13 02 00 FC \b2 \b2
43 * 13 02 00 FC \b2 \b2
\w6 \w7
\w6 \w7

// Name: bulk_wagon_coal_default_switch
43 * 15 02 00 FD 80 02 \b0 04
44 * 15 02 00 FD 80 02 \b0 04
\wx00FF \wx00FF \wx00FF // (2/3) -> (3/4): bulk_wagon_coal_default_group;
\wx00FD // (1/3) -> (1/4): bulk_wagon_coal2_group;

// param[127] = (param[131] & 255)
44 * 9 0D 7F \D& 83 FF \dx000000FF
45 * 9 0D 7F \D& 83 FF \dx000000FF

45 * 7 06
46 * 7 06
7F 04 FF \wx0006
FF

// Name: bulk_wagon_coal_climate_switch
46 * 23 02 00 FD 89
47 * 23 02 00 FD 89
1A 00 \dx00000000 // param[127]
\b1
\wx00FE \dx00000001 \dx00000001 // 1 .. 1: bulk_wagon_coal_arctic_group;
\wx00FD // default: bulk_wagon_coal_default_switch;

// Name: bulk_wagon_graphics_switch
47 * 23 02 00 FC 89
48 * 23 02 00 FC 89
47 00 \dx000000FF
\b1
\wx00FD \dx00000013 \dx00000013 // 19 .. 19: bulk_wagon_coal_climate_switch;
\wx00FC // default: bulk_wagon_grain_group;

// Name: @CB_FAILED_REAL00
48 * 9 02 00 FD \b1 \b1
49 * 9 02 00 FD \b1 \b1
\w0
\w0

// Name: @CB_FAILED00
49 * 23 02 00 FD 89
50 * 23 02 00 FD 89
0C 00 \dx0000FFFF
\b1
\wx8000 \dx00000000 \dx00000000 // graphics callback -> return 0
\wx00FD // Non-graphics callback, return graphics result

// Name: bulk_wagon_cb_capacity_switch
50 * 83 02 00 FE 89
51 * 83 02 00 FE 89
47 00 \dx000000FF
\b7
\wx8019 \dx0000002F \dx0000002F // 47 .. 47: return 25;
Expand All @@ -147,7 +149,7 @@ FF
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_weight_switch
51 * 53 02 00 FD 89
52 * 53 02 00 FD 89
47 00 \dx000000FF
\b4
\wx8012 \dx00000013 \dx00000013 // 19 .. 19: return 18;
Expand All @@ -157,75 +159,75 @@ FF
\wx00FD // No default specified -> fail callback

// Name: bulk_wagon_cb_name_switch
52 * 30 02 00 FF 89
1A 20 \dx0000D000
53 * 30 02 00 FF 89
1A 20 \dx0000DC00
\2sto 1A 00 \dx00000100
\b1
\wx8000 \dx00000001 \dx00000000 // Bogus range to avoid nvar == 0
\wx8001 // default: return string(STR_JUST_STRING);
\wx8000 // default: return string(STR_JUST_STRING);

// param[125] = (param[1] * 5000)
53 * 9 0D 7D \D* 01 FF \dx00001388
54 * 9 0D 7D \D* 01 FF \dx00001388

// param[126] = (param[125] + 698)
54 * 9 0D 7E \D+ 7D FF \dx000002BA
55 * 9 0D 7E \D+ 7D FF \dx000002BA

// param[127] = (param[126] / 1397)
55 * 9 0D 7F \D/ 7E FF \dx00000575
56 * 9 0D 7F \D/ 7E FF \dx00000575

// param[124] = (param[2] * 12500)
56 * 9 0D 7C \D* 02 FF \dx000030D4
57 * 9 0D 7C \D* 02 FF \dx000030D4

// param[125] = (param[124] + 6286)
57 * 9 0D 7D \D+ 7C FF \dx0000188E
58 * 9 0D 7D \D+ 7C FF \dx0000188E

// param[126] = (param[125] / 12573)
58 * 9 0D 7E \D/ 7D FF \dx0000311D
59 * 9 0D 7E \D/ 7D FF \dx0000311D

// param[123] = (param[3] * 8)
59 * 9 0D 7B \D* 03 FF \dx00000008
60 * 9 0D 7B \D* 03 FF \dx00000008

// param[124] = (param[123] + 2)
60 * 9 0D 7C \D+ 7B FF \dx00000002
61 * 9 0D 7C \D+ 7B FF \dx00000002

// param[125] = (param[124] / 5)
61 * 9 0D 7D \D/ 7C FF \dx00000005
62 * 9 0D 7D \D/ 7C FF \dx00000005

// param[122] = (param[4] * 2965)
62 * 9 0D 7A \D* 04 FF \dx00000B95
63 * 9 0D 7A \D* 04 FF \dx00000B95

// param[123] = (param[122] + 1105)
63 * 9 0D 7B \D+ 7A FF \dx00000451
64 * 9 0D 7B \D+ 7A FF \dx00000451

// param[124] = (param[123] / 2211)
64 * 9 0D 7C \D/ 7B FF \dx000008A3
65 * 9 0D 7C \D/ 7B FF \dx000008A3

65 * 22 06
66 * 22 06
7F 02 FF \wx000B
7E 02 FF \wx000E
7D 02 FF \wx0011
7C 02 FF \wx0014
FF

66 * 22 00 00 \b5 01 FF \wx0074
67 * 22 00 00 \b5 01 FF \wx0074
09 \wx0024
09 \wx0000
09 \wx0000
09 \wx0000
0B \wx0000

// param[127] = (param[1] & 255)
67 * 9 0D 7F \D& 01 FF \dx000000FF
68 * 9 0D 7F \D& 01 FF \dx000000FF

// param[126] = (param[1] << -8)
68 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8
69 * 9 0D 7E \D<< 01 FF \dxFFFFFFF8

69 * 12 06
70 * 12 06
7F 01 FF \wx004D
7E 01 FF \wx004F
FF

70 * 82 00 00 \b26 01 FF \wx0074
71 * 82 00 00 \b26 01 FF \wx0074
06 0F
28 \wx0010
1D \dx00000000
Expand Down Expand Up @@ -254,45 +256,45 @@ FF
24 00
25 00

71 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00
72 * 27 04 00 7F 01 FF \wx0074 "NML Test bulk wagon" 00

72 * 11 00 00 \b2 01 FF \wx0074
73 * 11 00 00 \b2 01 FF \wx0074
1E 08
31 01

// Name: @action3_0
73 * 33 02 00 FD 89
74 * 33 02 00 FD 89
10 00 \dx000000FF
\b2
\wx00FE \dx00000014 \dx00000014 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000016 \dx00000016 // bulk_wagon_cb_weight_switch;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_1
74 * 33 02 00 FB 89
75 * 33 02 00 FB 89
10 00 \dx000000FF
\b2
\wx801E \dx00000014 \dx00000014 // return 30;
\wx8019 \dx00000016 \dx00000016 // return 25;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_2
75 * 33 02 00 FD 89
76 * 33 02 00 FD 89
0C 00 \dx0000FFFF
\b2
\wx00FE \dx00000015 \dx00000015 // bulk_wagon_cb_capacity_switch;
\wx00FD \dx00000036 \dx00000036 // @action3_0;
\wx00FC // bulk_wagon_graphics_switch;

// Name: @action3_3
76 * 33 02 00 FC 89
77 * 33 02 00 FC 89
0C 00 \dx0000FFFF
\b2
\wx00FB \dx00000036 \dx00000036 // @action3_1;
\wx00FF \dx00000161 \dx00000161 // bulk_wagon_cb_name_switch;
\wx00FC // bulk_wagon_graphics_switch;

77 * 12 03 00 01 FF \wx0074 \b1
78 * 12 03 00 01 FF \wx0074 \b1
FF \wx00FC // @action3_3;
\wx00FD // @action3_2;

0 comments on commit 945227b

Please sign in to comment.