annotate vm/decoder.c @ 290:54b6a000f6da src

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