annotate decoder.c @ 186:fb1b6c1c3d2c src

Comment update.
author jcdutton
date Tue, 29 Apr 2003 22:11:46 +0000
parents 36777e6346c5
children 6b1bfe8f5283
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
1 /*
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
2 * Copyright (C) 2000, 2001 Martin Norbäck, Håkan Hjort
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
3 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
4 * This file is part of libdvdnav, a DVD navigation library. It is modified
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
5 * from a file originally part of the Ogle DVD player.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
6 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
7 * libdvdnav is free software; you can redistribute it and/or modify
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
10 * (at your option) any later version.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
11 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
12 * libdvdnav is distributed in the hope that it will be useful,
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
15 * GNU General Public License for more details.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
16 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
20 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
21 * $Id$
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
22 *
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
23 */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
24
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
25 #ifdef HAVE_CONFIG_H
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
26 #include "config.h"
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
27 #endif
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
28
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
29 #include <stdio.h>
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
30 #include <stdlib.h>
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
31 #include <inttypes.h>
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
32 #include <string.h> /* For memset */
169
90b1f6f0520e Modified libdvdnav to do without libdvdread.
jcdutton
parents: 166
diff changeset
33 #include "ifo_types.h" /* vm_cmd_t */
6
5f319e02e333 Some cleaning up.
jcdutton
parents: 0
diff changeset
34 #include <assert.h>
185
36777e6346c5 First update for Win32/msvc support
tchamp
parents: 169
diff changeset
35
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
36 #include "dvdnav_internal.h"
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
37
154
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
38 uint32_t vm_getbits(command_t *command, int start, int count) {
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
39 uint64_t result = 0;
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 156
diff changeset
40 uint64_t bit_mask = 0;
154
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
41 uint64_t examining = 0;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
42 int32_t bits;
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 156
diff changeset
43
154
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
44 if (count == 0) return 0;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
45
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
46 if ( ((start - count) < -1) ||
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
47 (count > 32) ||
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
48 (start > 63) ||
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
49 (count < 0) ||
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
50 (start < 0) ) {
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
51 fprintf(MSG_OUT, "libdvdnav: Bad call to vm_getbits. Parameter out of range\n");
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
52 assert(0);
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
53 }
166
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 156
diff changeset
54 /* all ones, please */
3bfaec0c1288 * fix warnings with gcc 3.3
mroi
parents: 156
diff changeset
55 bit_mask = ~bit_mask;
154
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
56 bit_mask >>= 63 - start;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
57 bits = start + 1 - count;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
58 examining = ((bit_mask >> bits) << bits );
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
59 command->examined |= examining;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
60 result = (command->instruction & bit_mask) >> bits;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
61 return (uint32_t) result;
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
62 }
3492d41dc247 vm_getbits should be in decoder.c, because
mroi
parents: 153
diff changeset
63
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
64 static uint16_t get_GPRM(registers_t* registers, uint8_t reg) {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
65 if (registers->GPRM_mode[reg] & 0x01) {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
66 struct timeval current_time, time_offset;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
67 uint16_t result;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
68 /* Counter mode */
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
69 /* fprintf(MSG_OUT, "libdvdnav: Getting counter %d\n",reg);*/
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
70 gettimeofday(&current_time, NULL);
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
71 time_offset.tv_sec = current_time.tv_sec - registers->GPRM_time[reg].tv_sec;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
72 time_offset.tv_usec = current_time.tv_usec - registers->GPRM_time[reg].tv_usec;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
73 if (time_offset.tv_usec < 0) {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
74 time_offset.tv_sec--;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
75 time_offset.tv_usec += 1000000;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
76 }
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
77 result = (uint16_t) (time_offset.tv_sec & 0xffff);
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
78 registers->GPRM[reg]=result;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
79 return result;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
80
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
81 } else {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
82 /* Register mode */
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
83 return registers->GPRM[reg];
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
84 }
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
85
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
86 }
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
87
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
88 static void set_GPRM(registers_t* registers, uint8_t reg, uint16_t value) {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
89 if (registers->GPRM_mode[reg] & 0x01) {
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
90 struct timeval current_time;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
91 /* Counter mode */
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
92 /* fprintf(MSG_OUT, "libdvdnav: Setting counter %d\n",reg); */
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
93 gettimeofday(&current_time, NULL);
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
94 registers->GPRM_time[reg] = current_time;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
95 registers->GPRM_time[reg].tv_sec -= value;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
96 }
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
97 registers->GPRM[reg] = value;
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
98 }
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
99
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
100 /* Eval register code, can either be system or general register.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
101 SXXX_XXXX, where S is 1 if it is system register. */
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
102 static uint16_t eval_reg(command_t* command, uint8_t reg) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
103 if(reg & 0x80) {
18
e6ac0a8d9c14 Display DVD disk region setting.
jcdutton
parents: 15
diff changeset
104 if ((reg & 0x1f) == 20) {
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
105 fprintf(MSG_OUT, "libdvdnav: Suspected RCE Region Protection!!!");
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
106 }
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
107 return command->registers->SPRM[reg & 0x1f]; /* FIXME max 24 not 32 */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
108 } else {
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
109 return get_GPRM(command->registers, reg & 0x0f) ;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
110 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
111 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
112
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
113 /* Eval register or immediate data.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
114 AAAA_AAAA BBBB_BBBB, if immediate use all 16 bits for data else use
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
115 lower eight bits for the system or general purpose register. */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
116 static uint16_t eval_reg_or_data(command_t* command, int32_t imm, int32_t start) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
117 if(imm) { /* immediate */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
118 return vm_getbits(command, start, 16);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
119 } else {
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
120 return eval_reg(command, vm_getbits(command, (start - 8), 8));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
121 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
122 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
123
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
124 /* Eval register or immediate data.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
125 xBBB_BBBB, if immediate use all 7 bits for data else use
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
126 lower four bits for the general purpose register number. */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
127 /* Evaluates gprm or data depending on bit, data is in byte n */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
128 uint16_t eval_reg_or_data_2(command_t* command, int32_t imm, int32_t start) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
129 if(imm) /* immediate */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
130 return vm_getbits(command, (start - 1), 7);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
131 else
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
132 return get_GPRM(command->registers, (vm_getbits(command, (start - 4), 4)) );
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
133 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
134
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
135
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
136 /* Compare data using operation, return result from comparison.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
137 Helper function for the different if functions. */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
138 static int32_t eval_compare(uint8_t operation, uint16_t data1, uint16_t data2) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
139 switch(operation) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
140 case 1:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
141 return data1 & data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
142 case 2:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
143 return data1 == data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
144 case 3:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
145 return data1 != data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
146 case 4:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
147 return data1 >= data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
148 case 5:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
149 return data1 > data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
150 case 6:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
151 return data1 <= data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
152 case 7:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
153 return data1 < data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
154 }
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
155 fprintf(MSG_OUT, "libdvdnav: eval_compare: Invalid comparison code\n");
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
156 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
157 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
158
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
159
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
160 /* Evaluate if version 1.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
161 Has comparison data in byte 3 and 4-5 (immediate or register) */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
162 static int32_t eval_if_version_1(command_t* command) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
163 uint8_t op = vm_getbits(command, 54, 3);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
164 if(op) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
165 return eval_compare(op, eval_reg(command, vm_getbits(command, 39, 8)),
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
166 eval_reg_or_data(command, vm_getbits(command, 55, 1), 31));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
167 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
168 return 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
169 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
170
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
171 /* Evaluate if version 2.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
172 This version only compares register which are in byte 6 and 7 */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
173 static int32_t eval_if_version_2(command_t* command) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
174 uint8_t op = vm_getbits(command, 54, 3);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
175 if(op) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
176 return eval_compare(op, eval_reg(command, vm_getbits(command, 15, 8)),
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
177 eval_reg(command, vm_getbits(command, 7, 8)));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
178 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
179 return 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
180 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
181
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
182 /* Evaluate if version 3.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
183 Has comparison data in byte 2 and 6-7 (immediate or register) */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
184 static int32_t eval_if_version_3(command_t* command) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
185 uint8_t op = vm_getbits(command, 54, 3);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
186 if(op) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
187 return eval_compare(op, eval_reg(command, vm_getbits(command, 47, 8)),
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
188 eval_reg_or_data(command, vm_getbits(command, 55, 1), 15));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
189 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
190 return 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
191 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
192
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
193 /* Evaluate if version 4.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
194 Has comparison data in byte 1 and 4-5 (immediate or register)
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
195 The register in byte 1 is only the lowe nibble (4 bits) */
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
196 static int32_t eval_if_version_4(command_t* command) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
197 uint8_t op = vm_getbits(command, 54, 3);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
198 if(op) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
199 return eval_compare(op, eval_reg(command, vm_getbits(command, 51, 4)),
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
200 eval_reg_or_data(command, vm_getbits(command, 55, 1), 31));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
201 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
202 return 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
203 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
204
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
205 /* Evaluate special instruction.... returns the new row/line number,
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
206 0 if no new row and 256 if Break. */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
207 static int32_t eval_special_instruction(command_t* command, int32_t cond) {
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
208 int32_t line, level;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
209
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
210 switch(vm_getbits(command, 51, 4)) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
211 case 0: /* NOP */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
212 line = 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
213 return cond ? line : 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
214 case 1: /* Goto line */
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
215 line = vm_getbits(command, 7, 8);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
216 return cond ? line : 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
217 case 2: /* Break */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
218 /* max number of rows < 256, so we will end this set */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
219 line = 256;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
220 return cond ? 256 : 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
221 case 3: /* Set temporary parental level and goto */
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
222 line = vm_getbits(command, 7, 8);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
223 level = vm_getbits(command, 11, 4);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
224 if(cond) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
225 /* This always succeeds now, if we want real parental protection */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
226 /* we need to ask the user and have passwords and stuff. */
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
227 command->registers->SPRM[13] = level;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
228 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
229 return cond ? line : 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
230 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
231 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
232 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
233
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
234 /* Evaluate link by subinstruction.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
235 Return 1 if link, or 0 if no link
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
236 Actual link instruction is in return_values parameter */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
237 static int32_t eval_link_subins(command_t* command, int32_t cond, link_t *return_values) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
238 uint16_t button = vm_getbits(command, 15, 6);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
239 uint8_t linkop = vm_getbits(command, 4, 5);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
240
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
241 if(linkop > 0x10)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
242 return 0; /* Unknown Link by Sub-Instruction command */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
243
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
244 /* Assumes that the link_cmd_t enum has the same values as the LinkSIns codes */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
245 return_values->command = linkop;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
246 return_values->data1 = button;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
247 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
248 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
249
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
250
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
251 /* Evaluate link instruction.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
252 Return 1 if link, or 0 if no link
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
253 Actual link instruction is in return_values parameter */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
254 static int32_t eval_link_instruction(command_t* command, int32_t cond, link_t *return_values) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
255 uint8_t op = vm_getbits(command, 51, 4);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
256
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
257 switch(op) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
258 case 1:
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
259 return eval_link_subins(command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
260 case 4:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
261 return_values->command = LinkPGCN;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
262 return_values->data1 = vm_getbits(command, 14, 15);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
263 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
264 case 5:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
265 return_values->command = LinkPTTN;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
266 return_values->data1 = vm_getbits(command, 9, 10);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
267 return_values->data2 = vm_getbits(command, 15, 6);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
268 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
269 case 6:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
270 return_values->command = LinkPGN;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
271 return_values->data1 = vm_getbits(command, 6, 7);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
272 return_values->data2 = vm_getbits(command, 15, 6);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
273 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
274 case 7:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
275 return_values->command = LinkCN;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
276 return_values->data1 = vm_getbits(command, 7, 8);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
277 return_values->data2 = vm_getbits(command, 15, 6);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
278 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
279 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
280 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
281 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
282
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
283
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
284 /* Evaluate a jump instruction.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
285 returns 1 if jump or 0 if no jump
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
286 actual jump instruction is in return_values parameter */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
287 static int32_t eval_jump_instruction(command_t* command, int32_t cond, link_t *return_values) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
288
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
289 switch(vm_getbits(command, 51, 4)) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
290 case 1:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
291 return_values->command = Exit;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
292 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
293 case 2:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
294 return_values->command = JumpTT;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
295 return_values->data1 = vm_getbits(command, 22, 7);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
296 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
297 case 3:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
298 return_values->command = JumpVTS_TT;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
299 return_values->data1 = vm_getbits(command, 22, 7);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
300 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
301 case 5:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
302 return_values->command = JumpVTS_PTT;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
303 return_values->data1 = vm_getbits(command, 22, 7);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
304 return_values->data2 = vm_getbits(command, 41, 10);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
305 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
306 case 6:
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
307 switch(vm_getbits(command, 23, 2)) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
308 case 0:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
309 return_values->command = JumpSS_FP;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
310 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
311 case 1:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
312 return_values->command = JumpSS_VMGM_MENU;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
313 return_values->data1 = vm_getbits(command, 19, 4);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
314 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
315 case 2:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
316 return_values->command = JumpSS_VTSM;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
317 return_values->data1 = vm_getbits(command, 31, 8);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
318 return_values->data2 = vm_getbits(command, 39, 8);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
319 return_values->data3 = vm_getbits(command, 19, 4);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
320 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
321 case 3:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
322 return_values->command = JumpSS_VMGM_PGC;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
323 return_values->data1 = vm_getbits(command, 46, 15);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
324 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
325 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
326 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
327 case 8:
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
328 switch(vm_getbits(command, 23, 2)) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
329 case 0:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
330 return_values->command = CallSS_FP;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
331 return_values->data1 = vm_getbits(command, 31, 8);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
332 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
333 case 1:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
334 return_values->command = CallSS_VMGM_MENU;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
335 return_values->data1 = vm_getbits(command, 19, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
336 return_values->data2 = vm_getbits(command, 31, 8);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
337 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
338 case 2:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
339 return_values->command = CallSS_VTSM;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
340 return_values->data1 = vm_getbits(command, 19, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
341 return_values->data2 = vm_getbits(command, 31, 8);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
342 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
343 case 3:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
344 return_values->command = CallSS_VMGM_PGC;
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
345 return_values->data1 = vm_getbits(command, 46, 15);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
346 return_values->data2 = vm_getbits(command, 31, 8);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
347 return cond;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
348 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
349 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
350 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
351 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
352 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
353
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
354 /* Evaluate a set sytem register instruction
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
355 May contain a link so return the same as eval_link */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
356 static int32_t eval_system_set(command_t* command, int32_t cond, link_t *return_values) {
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
357 int32_t i;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
358 uint16_t data, data2;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
359
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
360 switch(vm_getbits(command, 59, 4)) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
361 case 1: /* Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
362 for(i = 1; i <= 3; i++) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
363 if(vm_getbits(command, 63 - ((2 + i)*8), 1)) {
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
364 data = eval_reg_or_data_2(command, vm_getbits(command, 60, 1), (47 - (i*8)));
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
365 if(cond) {
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
366 command->registers->SPRM[i] = data;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
367 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
368 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
369 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
370 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
371 case 2: /* Set system reg 9 & 10 (Navigation timer, Title PGC number) */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
372 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
373 data2 = vm_getbits(command, 23, 8); /* ?? size */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
374 if(cond) {
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
375 command->registers->SPRM[9] = data; /* time */
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
376 command->registers->SPRM[10] = data2; /* pgcN */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
377 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
378 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
379 case 3: /* Mode: Counter / Register + Set */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
380 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
381 data2 = vm_getbits(command, 19, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
382 if(vm_getbits(command, 23, 1)) {
18
e6ac0a8d9c14 Display DVD disk region setting.
jcdutton
parents: 15
diff changeset
383 command->registers->GPRM_mode[data2] |= 1; /* Set bit 0 */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
384 } else {
18
e6ac0a8d9c14 Display DVD disk region setting.
jcdutton
parents: 15
diff changeset
385 command->registers->GPRM_mode[data2] &= ~ 0x01; /* Reset bit 0 */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
386 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
387 if(cond) {
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
388 set_GPRM(command->registers, data2, data);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
389 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
390 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
391 case 6: /* Set system reg 8 (Highlighted button) */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
392 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 31); /* Not system reg!! */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
393 if(cond) {
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
394 command->registers->SPRM[8] = data;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
395 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
396 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
397 }
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
398 if(vm_getbits(command, 51, 4)) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
399 return eval_link_instruction(command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
400 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
401 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
402 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
403
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
404
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
405 /* Evaluate set operation
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
406 Sets the register given to the value indicated by op and data.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
407 For the swap case the contents of reg is stored in reg2.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
408 */
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
409 static void eval_set_op(command_t* command, int32_t op, int32_t reg, int32_t reg2, int32_t data) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
410 const int32_t shortmax = 0xffff;
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
411 int32_t tmp;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
412 switch(op) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
413 case 1:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
414 set_GPRM(command->registers, reg, data);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
415 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
416 case 2: /* SPECIAL CASE - SWAP! */
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
417 set_GPRM(command->registers, reg2, get_GPRM(command->registers, reg));
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
418 set_GPRM(command->registers, reg, data);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
419 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
420 case 3:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
421 tmp = get_GPRM(command->registers, reg) + data;
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
422 if(tmp > shortmax) tmp = shortmax;
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
423 set_GPRM(command->registers, reg, (uint16_t)tmp);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
424 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
425 case 4:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
426 tmp = get_GPRM(command->registers, reg) - data;
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
427 if(tmp < 0) tmp = 0;
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
428 set_GPRM(command->registers, reg, (uint16_t)tmp);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
429 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
430 case 5:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
431 tmp = get_GPRM(command->registers, reg) * data;
156
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
432 if(tmp > shortmax) tmp = shortmax;
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
433 set_GPRM(command->registers, reg, (uint16_t)tmp);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
434 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
435 case 6:
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
436 if (data != 0) {
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
437 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) / data) );
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
438 } else {
156
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
439 set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
440 }
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
441 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
442 case 7:
156
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
443 if (data != 0) {
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
444 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) % data) );
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
445 } else {
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
446 set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
447 }
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
448 break;
156
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
449 case 8: /* SPECIAL CASE - RND! Return numbers between 1 and data. */
a68751e6e84f Use more common sense values for div 0. I.E. As close to infinity as a 16 bit number can get!
jcdutton
parents: 154
diff changeset
450 set_GPRM(command->registers, reg, 1 + ((uint16_t) ((float) data * rand()/(RAND_MAX+1.0))) );
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
451 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
452 case 9:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
453 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) & data) );
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
454 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
455 case 10:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
456 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) | data) );
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
457 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
458 case 11:
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
459 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) ^ data) );
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
460 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
461 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
462 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
463
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
464 /* Evaluate set instruction, combined with either Link or Compare. */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
465 static void eval_set_version_1(command_t* command, int32_t cond) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
466 uint8_t op = vm_getbits(command, 59, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
467 uint8_t reg = vm_getbits(command, 35, 4); /* FIXME: This is different from vmcmd.c!!! */
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
468 uint8_t reg2 = vm_getbits(command, 19, 4);
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
469 uint16_t data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 31);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
470
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
471 if(cond) {
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
472 eval_set_op(command, op, reg, reg2, data);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
473 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
474 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
475
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
476
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
477 /* Evaluate set instruction, combined with both Link and Compare. */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
478 static void eval_set_version_2(command_t* command, int32_t cond) {
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
479 uint8_t op = vm_getbits(command, 59, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
480 uint8_t reg = vm_getbits(command, 51, 4);
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
481 uint8_t reg2 = vm_getbits(command, 35, 4); /* FIXME: This is different from vmcmd.c!!! */
152
3a1659f4a6c3 Remove byte references. Convert them to bit references.
jcdutton
parents: 149
diff changeset
482 uint16_t data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
483
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
484 if(cond) {
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
485 eval_set_op(command, op, reg, reg2, data);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
486 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
487 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
488
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
489
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
490 /* Evaluate a command
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
491 returns row number of goto, 0 if no goto, -1 if link.
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
492 Link command in return_values */
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
493 static int32_t eval_command(uint8_t *bytes, registers_t* registers, link_t *return_values) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
494 int32_t cond, res = 0;
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
495 command_t command;
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
496 command.instruction =( (uint64_t) bytes[0] << 56 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
497 ( (uint64_t) bytes[1] << 48 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
498 ( (uint64_t) bytes[2] << 40 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
499 ( (uint64_t) bytes[3] << 32 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
500 ( (uint64_t) bytes[4] << 24 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
501 ( (uint64_t) bytes[5] << 16 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
502 ( (uint64_t) bytes[6] << 8 ) |
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
503 (uint64_t) bytes[7] ;
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
504 command.examined = 0;
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
505 command.registers = registers;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
506 memset(return_values, 0, sizeof(link_t));
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
507
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
508 switch(vm_getbits(&command, 63, 3)) { /* three first old_bits */
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
509 case 0: /* Special instructions */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
510 cond = eval_if_version_1(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
511 res = eval_special_instruction(&command, cond);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
512 if(res == -1) {
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
513 fprintf(MSG_OUT, "libdvdnav: Unknown Instruction!\n");
6
5f319e02e333 Some cleaning up.
jcdutton
parents: 0
diff changeset
514 assert(0);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
515 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
516 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
517 case 1: /* Link/jump instructions */
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
518 if(vm_getbits(&command, 60, 1)) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
519 cond = eval_if_version_2(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
520 res = eval_jump_instruction(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
521 } else {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
522 cond = eval_if_version_1(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
523 res = eval_link_instruction(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
524 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
525 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
526 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
527 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
528 case 2: /* System set instructions */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
529 cond = eval_if_version_2(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
530 res = eval_system_set(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
531 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
532 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
533 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
534 case 3: /* Set instructions, either Compare or Link may be used */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
535 cond = eval_if_version_3(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
536 eval_set_version_1(&command, cond);
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
537 if(vm_getbits(&command, 51, 4)) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
538 res = eval_link_instruction(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
539 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
540 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
541 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
542 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
543 case 4: /* Set, Compare -> Link Sub-Instruction */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
544 eval_set_version_2(&command, /*True*/ 1);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
545 cond = eval_if_version_4(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
546 res = eval_link_subins(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
547 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
548 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
549 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
550 case 5: /* Compare -> (Set and Link Sub-Instruction) */
149
c16cb952319a Add some FIXMEs.
jcdutton
parents: 148
diff changeset
551 /* FIXME: These are wrong. Need to be updated from vmcmd.c */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
552 cond = eval_if_version_4(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
553 eval_set_version_2(&command, cond);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
554 res = eval_link_subins(&command, cond, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
555 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
556 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
557 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
558 case 6: /* Compare -> Set, allways Link Sub-Instruction */
149
c16cb952319a Add some FIXMEs.
jcdutton
parents: 148
diff changeset
559 /* FIXME: These are wrong. Need to be updated from vmcmd.c */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
560 cond = eval_if_version_4(&command);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
561 eval_set_version_2(&command, cond);
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
562 res = eval_link_subins(&command, /*True*/ 1, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
563 if(res)
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
564 res = -1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
565 break;
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
566 default: /* Unknown command */
148
5ddb33e104a8 Fix getbits to be more sensible.
jcdutton
parents: 136
diff changeset
567 fprintf(MSG_OUT, "libdvdnav: WARNING: Unknown Command=%x\n", vm_getbits(&command, 63, 3));
31
8b08ee66cbff Quiet please!!!
jcdutton
parents: 19
diff changeset
568 assert(0);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
569 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
570 /* Check if there are bits not yet examined */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
571
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
572 if(command.instruction & ~ command.examined) {
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
573 fprintf(MSG_OUT, "libdvdnav: decoder.c: [WARNING, unknown bits:");
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
574 fprintf(MSG_OUT, " %08llx", (command.instruction & ~ command.examined) );
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
575 fprintf(MSG_OUT, "]\n");
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
576 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
577
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
578 return res;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
579 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
580
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
581 /* Evaluate a set of commands in the given register set (which is modified) */
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
582 int32_t vmEval_CMD(vm_cmd_t commands[], int32_t num_commands,
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
583 registers_t *registers, link_t *return_values) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
584 int32_t i = 0;
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
585 int32_t total = 0;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
586
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
587 #ifdef TRACE
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
588 /* DEBUG */
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
589 fprintf(MSG_OUT, "libdvdnav: Registers before transaction\n");
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
590 vm_print_registers( registers );
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
591 fprintf(MSG_OUT, "libdvdnav: Full list of commands to execute\n");
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
592 for(i = 0; i < num_commands; i++)
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
593 vm_print_cmd(i, &commands[i]);
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
594 fprintf(MSG_OUT, "libdvdnav: --------------------------------------------\n");
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
595 fprintf(MSG_OUT, "libdvdnav: Single stepping commands\n");
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
596 #endif
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
597
79
96707bfb63d7 Fix bug whereby libdvdnav would totally fail if run with #define TRACE enabled.
jcdutton
parents: 78
diff changeset
598 i = 0;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
599 while(i < num_commands && total < 100000) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
600 int32_t line;
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
601
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
602 #ifdef TRACE
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
603 vm_print_cmd(i, &commands[i]);
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
604 #endif
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
605
13
de00f8362634 Removed another global.
jcdutton
parents: 12
diff changeset
606 line = eval_command(&commands[i].bytes[0], registers, return_values);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
607
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
608 if (line < 0) { /* Link command */
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
609 #ifdef TRACE
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
610 fprintf(MSG_OUT, "libdvdnav: Registers after transaction\n");
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
611 vm_print_registers( registers );
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
612 fprintf(MSG_OUT, "libdvdnav: eval: Doing Link/Jump/Call\n");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
613 #endif
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
614 return 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
615 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
616
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
617 if (line > 0) /* Goto command */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
618 i = line - 1;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
619 else /* Just continue on the next line */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
620 i++;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
621
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
622 total++;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
623 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
624
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
625 memset(return_values, 0, sizeof(link_t));
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
626 #ifdef TRACE
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
627 fprintf(MSG_OUT, "libdvdnav: Registers after transaction\n");
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
628 vm_print_registers( registers );
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
629 #endif
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
630 return 0;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
631 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
632
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
633 #ifdef TRACE
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
634
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
635 static char *linkcmd2str(link_cmd_t cmd) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
636 switch(cmd) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
637 case LinkNoLink:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
638 return "LinkNoLink";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
639 case LinkTopC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
640 return "LinkTopC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
641 case LinkNextC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
642 return "LinkNextC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
643 case LinkPrevC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
644 return "LinkPrevC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
645 case LinkTopPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
646 return "LinkTopPG";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
647 case LinkNextPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
648 return "LinkNextPG";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
649 case LinkPrevPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
650 return "LinkPrevPG";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
651 case LinkTopPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
652 return "LinkTopPGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
653 case LinkNextPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
654 return "LinkNextPGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
655 case LinkPrevPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
656 return "LinkPrevPGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
657 case LinkGoUpPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
658 return "LinkGoUpPGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
659 case LinkTailPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
660 return "LinkTailPGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
661 case LinkRSM:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
662 return "LinkRSM";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
663 case LinkPGCN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
664 return "LinkPGCN";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
665 case LinkPTTN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
666 return "LinkPTTN";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
667 case LinkPGN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
668 return "LinkPGN";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
669 case LinkCN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
670 return "LinkCN";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
671 case Exit:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
672 return "Exit";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
673 case JumpTT:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
674 return "JumpTT";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
675 case JumpVTS_TT:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
676 return "JumpVTS_TT";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
677 case JumpVTS_PTT:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
678 return "JumpVTS_PTT";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
679 case JumpSS_FP:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
680 return "JumpSS_FP";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
681 case JumpSS_VMGM_MENU:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
682 return "JumpSS_VMGM_MENU";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
683 case JumpSS_VTSM:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
684 return "JumpSS_VTSM";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
685 case JumpSS_VMGM_PGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
686 return "JumpSS_VMGM_PGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
687 case CallSS_FP:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
688 return "CallSS_FP";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
689 case CallSS_VMGM_MENU:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
690 return "CallSS_VMGM_MENU";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
691 case CallSS_VTSM:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
692 return "CallSS_VTSM";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
693 case CallSS_VMGM_PGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
694 return "CallSS_VMGM_PGC";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
695 case PlayThis:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
696 return "PlayThis";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
697 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
698 return "*** (bug)";
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
699 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
700
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
701 void vm_print_link(link_t value) {
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
702 char *cmd = linkcmd2str(value.command);
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
703
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
704 switch(value.command) {
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
705 case LinkNoLink:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
706 case LinkTopC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
707 case LinkNextC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
708 case LinkPrevC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
709 case LinkTopPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
710 case LinkNextPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
711 case LinkPrevPG:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
712 case LinkTopPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
713 case LinkNextPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
714 case LinkPrevPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
715 case LinkGoUpPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
716 case LinkTailPGC:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
717 case LinkRSM:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
718 fprintf(MSG_OUT, "libdvdnav: %s (button %d)\n", cmd, value.data1);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
719 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
720 case LinkPGCN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
721 case JumpTT:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
722 case JumpVTS_TT:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
723 case JumpSS_VMGM_MENU: /* == 2 -> Title Menu */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
724 case JumpSS_VMGM_PGC:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
725 fprintf(MSG_OUT, "libdvdnav: %s %d\n", cmd, value.data1);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
726 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
727 case LinkPTTN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
728 case LinkPGN:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
729 case LinkCN:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
730 fprintf(MSG_OUT, "libdvdnav: %s %d (button %d)\n", cmd, value.data1, value.data2);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
731 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
732 case Exit:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
733 case JumpSS_FP:
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
734 case PlayThis: /* Humm.. should we have this at all.. */
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
735 fprintf(MSG_OUT, "libdvdnav: %s\n", cmd);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
736 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
737 case JumpVTS_PTT:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
738 fprintf(MSG_OUT, "libdvdnav: %s %d:%d\n", cmd, value.data1, value.data2);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
739 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
740 case JumpSS_VTSM:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
741 fprintf(MSG_OUT, "libdvdnav: %s vts %d title %d menu %d\n",
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
742 cmd, value.data1, value.data2, value.data3);
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
743 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
744 case CallSS_FP:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
745 fprintf(MSG_OUT, "libdvdnav: %s resume cell %d\n", cmd, value.data1);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
746 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
747 case CallSS_VMGM_MENU: /* == 2 -> Title Menu */
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
748 case CallSS_VTSM:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
749 fprintf(MSG_OUT, "libdvdnav: %s %d resume cell %d\n", cmd, value.data1, value.data2);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
750 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
751 case CallSS_VMGM_PGC:
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
752 fprintf(MSG_OUT, "libdvdnav: %s %d resume cell %d\n", cmd, value.data1, value.data2);
0
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
753 break;
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
754 }
3ddf0eaece51 Initial revision
richwareham
parents:
diff changeset
755 }
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
756
153
175d5fef21e4 Minor changes.
jcdutton
parents: 152
diff changeset
757 void vm_print_registers( registers_t *registers ) {
12
1a214a94a80d Removed some static variables from decoder.c
jcdutton
parents: 10
diff changeset
758 int32_t i;
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
759 fprintf(MSG_OUT, "libdvdnav: # ");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
760 for(i = 0; i < 24; i++)
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
761 fprintf(MSG_OUT, " %2d |", i);
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
762 fprintf(MSG_OUT, "\nlibdvdnav: SRPMS: ");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
763 for(i = 0; i < 24; i++)
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
764 fprintf(MSG_OUT, "%04x|", registers->SPRM[i]);
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
765 fprintf(MSG_OUT, "\nlibdvdnav: GRPMS: ");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
766 for(i = 0; i < 16; i++)
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
767 fprintf(MSG_OUT, "%04x|", get_GPRM(registers, i) );
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
768 fprintf(MSG_OUT, "\nlibdvdnav: Gmode: ");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
769 for(i = 0; i < 16; i++)
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
770 fprintf(MSG_OUT, "%04x|", registers->GPRM_mode[i]);
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
771 fprintf(MSG_OUT, "\nlibdvdnav: Gtime: ");
19
7e8628911b4f Implement General Register Counters or GPRM counters.
jcdutton
parents: 18
diff changeset
772 for(i = 0; i < 16; i++)
76
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
773 fprintf(MSG_OUT, "%04lx|", registers->GPRM_time[i].tv_sec & 0xffff);
0e2abe7083de more consistent console output
mroi
parents: 31
diff changeset
774 fprintf(MSG_OUT, "\n");
10
6f0fb88d1463 Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents: 6
diff changeset
775 }
114
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
776
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
777 #endif
b6834e6359cf big libdvdnav cleanup, quoting the ChangeLog:
mroi
parents: 79
diff changeset
778