annotate vm/decoder.c @ 416:4e34a2fce645 src

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