src/mame/machine/model1.c
| r10427 | r10428 | |
| 9 | 9 | #include "includes/model1.h" |
| 10 | 10 | |
| 11 | 11 | #define TGP_FUNCTION(name) void name(running_machine *machine) |
| 12 | | typedef void (*tgp_func)(running_machine *machine); |
| 13 | 12 | |
| 14 | 13 | |
| 15 | | enum {FIFO_SIZE = 256}; |
| 16 | | enum {MAT_STACK_SIZE = 32}; |
| 17 | | |
| 18 | | int model1_dump; |
| 19 | | |
| 20 | | static offs_t pushpc; |
| 21 | | |
| 22 | | static int fifoin_rpos, fifoin_wpos; |
| 23 | | static UINT32 fifoin_data[FIFO_SIZE]; |
| 24 | | static int model1_swa; |
| 25 | | |
| 26 | | static int fifoin_cbcount; |
| 27 | | static tgp_func fifoin_cb; |
| 28 | | |
| 29 | | static INT32 fifoout_rpos, fifoout_wpos; |
| 30 | | static UINT32 fifoout_data[FIFO_SIZE]; |
| 31 | | |
| 32 | | static UINT32 list_length; |
| 33 | | |
| 34 | | static float cmat[12], mat_stack[MAT_STACK_SIZE][12], mat_vector[21][12]; |
| 35 | | static INT32 mat_stack_pos; |
| 36 | | static float acc; |
| 37 | | |
| 38 | | static float tgp_vf_xmin, tgp_vf_xmax, tgp_vf_zmin, tgp_vf_zmax, tgp_vf_ygnd, tgp_vf_yflr, tgp_vf_yjmp; |
| 39 | | static float tgp_vr_circx, tgp_vr_circy, tgp_vr_circrad, tgp_vr_cbox[12]; |
| 40 | | static int tgp_vr_select; |
| 41 | | static UINT16 ram_adr, ram_latch[2], ram_scanadr; |
| 42 | | static UINT32 *ram_data; |
| 43 | | static float tgp_vr_base[4]; |
| 44 | | |
| 45 | 14 | static UINT32 fifoout_pop(address_space *space) |
| 46 | 15 | { |
| 16 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 47 | 17 | UINT32 v; |
| 48 | | if(fifoout_wpos == fifoout_rpos) { |
| 18 | if(state->fifoout_wpos == state->fifoout_rpos) { |
| 49 | 19 | fatalerror("TGP FIFOOUT underflow (%x)", cpu_get_pc(space->cpu)); |
| 50 | 20 | } |
| 51 | | v = fifoout_data[fifoout_rpos++]; |
| 52 | | if(fifoout_rpos == FIFO_SIZE) |
| 53 | | fifoout_rpos = 0; |
| 21 | v = state->fifoout_data[state->fifoout_rpos++]; |
| 22 | if(state->fifoout_rpos == FIFO_SIZE) |
| 23 | state->fifoout_rpos = 0; |
| 54 | 24 | return v; |
| 55 | 25 | } |
| 56 | 26 | |
| 57 | | static int puuu = 0; |
| 58 | 27 | |
| 59 | | static void fifoout_push(UINT32 data) |
| 28 | static void fifoout_push(model1_state *state, UINT32 data) |
| 60 | 29 | { |
| 61 | | if(!puuu) |
| 30 | if(!state->puuu) |
| 62 | 31 | logerror("TGP: Push %d\n", data); |
| 63 | 32 | else |
| 64 | | puuu = 0; |
| 65 | | fifoout_data[fifoout_wpos++] = data; |
| 66 | | if(fifoout_wpos == FIFO_SIZE) |
| 67 | | fifoout_wpos = 0; |
| 68 | | if(fifoout_wpos == fifoout_rpos) |
| 33 | state->puuu = 0; |
| 34 | state->fifoout_data[state->fifoout_wpos++] = data; |
| 35 | if(state->fifoout_wpos == FIFO_SIZE) |
| 36 | state->fifoout_wpos = 0; |
| 37 | if(state->fifoout_wpos == state->fifoout_rpos) |
| 69 | 38 | logerror("TGP FIFOOUT overflow\n"); |
| 70 | 39 | } |
| 71 | 40 | |
| 72 | | static void fifoout_push_f(float data) |
| 41 | static void fifoout_push_f(model1_state *state, float data) |
| 73 | 42 | { |
| 74 | | puuu = 1; |
| 43 | state->puuu = 1; |
| 75 | 44 | |
| 76 | 45 | logerror("TGP: Push %f\n", data); |
| 77 | | fifoout_push(f2u(data)); |
| 46 | fifoout_push(state, f2u(data)); |
| 78 | 47 | } |
| 79 | 48 | |
| 80 | | static UINT32 fifoin_pop(void) |
| 49 | static UINT32 fifoin_pop(model1_state *state) |
| 81 | 50 | { |
| 82 | 51 | UINT32 v; |
| 83 | | if(fifoin_wpos == fifoin_rpos) |
| 52 | if(state->fifoin_wpos == state->fifoin_rpos) |
| 84 | 53 | logerror("TGP FIFOIN underflow\n"); |
| 85 | | v = fifoin_data[fifoin_rpos++]; |
| 86 | | if(fifoin_rpos == FIFO_SIZE) |
| 87 | | fifoin_rpos = 0; |
| 54 | v = state->fifoin_data[state->fifoin_rpos++]; |
| 55 | if(state->fifoin_rpos == FIFO_SIZE) |
| 56 | state->fifoin_rpos = 0; |
| 88 | 57 | return v; |
| 89 | 58 | } |
| 90 | 59 | |
| 91 | 60 | static void fifoin_push(address_space *space, UINT32 data) |
| 92 | 61 | { |
| 62 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 93 | 63 | // logerror("TGP FIFOIN write %08x (%x)\n", data, cpu_get_pc(space->cpu)); |
| 94 | | fifoin_data[fifoin_wpos++] = data; |
| 95 | | if(fifoin_wpos == FIFO_SIZE) |
| 96 | | fifoin_wpos = 0; |
| 97 | | if(fifoin_wpos == fifoin_rpos) |
| 64 | state->fifoin_data[state->fifoin_wpos++] = data; |
| 65 | if(state->fifoin_wpos == FIFO_SIZE) |
| 66 | state->fifoin_wpos = 0; |
| 67 | if(state->fifoin_wpos == state->fifoin_rpos) |
| 98 | 68 | logerror("TGP FIFOIN overflow\n"); |
| 99 | | fifoin_cbcount--; |
| 100 | | if(!fifoin_cbcount) |
| 101 | | fifoin_cb(space->machine); |
| 69 | state->fifoin_cbcount--; |
| 70 | if(!state->fifoin_cbcount) |
| 71 | state->fifoin_cb(space->machine); |
| 102 | 72 | } |
| 103 | 73 | |
| 104 | | static float fifoin_pop_f(void) |
| 74 | static float fifoin_pop_f(model1_state *state) |
| 105 | 75 | { |
| 106 | | return u2f(fifoin_pop()); |
| 76 | return u2f(fifoin_pop(state)); |
| 107 | 77 | } |
| 108 | 78 | |
| 109 | 79 | static TGP_FUNCTION( function_get_vf ); |
| 110 | 80 | static TGP_FUNCTION( function_get_swa ); |
| 111 | 81 | |
| 112 | | static void next_fn(void) |
| 82 | static void next_fn(model1_state *state) |
| 113 | 83 | { |
| 114 | | fifoin_cbcount = 1; |
| 115 | | fifoin_cb = model1_swa ? function_get_swa : function_get_vf; |
| 84 | state->fifoin_cbcount = 1; |
| 85 | state->fifoin_cb = state->swa ? function_get_swa : function_get_vf; |
| 116 | 86 | } |
| 117 | 87 | |
| 118 | 88 | static float tcos(INT16 a) |
| r10427 | r10428 | |
| 139 | 109 | return sin(a*(2*M_PI/65536.0)); |
| 140 | 110 | } |
| 141 | 111 | |
| 142 | | static UINT16 ram_get_i(void) |
| 112 | static UINT16 ram_get_i(model1_state *state) |
| 143 | 113 | { |
| 144 | | return ram_data[ram_scanadr++]; |
| 114 | return state->ram_data[state->ram_scanadr++]; |
| 145 | 115 | } |
| 146 | 116 | |
| 147 | | static float ram_get_f(void) |
| 117 | static float ram_get_f(model1_state *state) |
| 148 | 118 | { |
| 149 | | return u2f(ram_data[ram_scanadr++]); |
| 119 | return u2f(state->ram_data[state->ram_scanadr++]); |
| 150 | 120 | } |
| 151 | 121 | |
| 152 | 122 | static TGP_FUNCTION( fadd ) |
| 153 | 123 | { |
| 154 | | float a = fifoin_pop_f(); |
| 155 | | float b = fifoin_pop_f(); |
| 124 | model1_state *state = machine->driver_data<model1_state>(); |
| 125 | float a = fifoin_pop_f(state); |
| 126 | float b = fifoin_pop_f(state); |
| 156 | 127 | float r = a+b; |
| 157 | | logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, pushpc); |
| 158 | | fifoout_push_f(r); |
| 159 | | next_fn(); |
| 128 | logerror("TGP fadd %f+%f=%f (%x)\n", a, b, r, state->pushpc); |
| 129 | fifoout_push_f(state, r); |
| 130 | next_fn(state); |
| 160 | 131 | } |
| 161 | 132 | |
| 162 | 133 | static TGP_FUNCTION( fsub ) |
| 163 | 134 | { |
| 164 | | float a = fifoin_pop_f(); |
| 165 | | float b = fifoin_pop_f(); |
| 135 | model1_state *state = machine->driver_data<model1_state>(); |
| 136 | float a = fifoin_pop_f(state); |
| 137 | float b = fifoin_pop_f(state); |
| 166 | 138 | float r = a-b; |
| 167 | | model1_dump = 1; |
| 168 | | logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, pushpc); |
| 169 | | fifoout_push_f(r); |
| 170 | | next_fn(); |
| 139 | state->dump = 1; |
| 140 | logerror("TGP fsub %f-%f=%f (%x)\n", a, b, r, state->pushpc); |
| 141 | fifoout_push_f(state, r); |
| 142 | next_fn(state); |
| 171 | 143 | } |
| 172 | 144 | |
| 173 | 145 | static TGP_FUNCTION( fmul ) |
| 174 | 146 | { |
| 175 | | float a = fifoin_pop_f(); |
| 176 | | float b = fifoin_pop_f(); |
| 147 | model1_state *state = machine->driver_data<model1_state>(); |
| 148 | float a = fifoin_pop_f(state); |
| 149 | float b = fifoin_pop_f(state); |
| 177 | 150 | float r = a*b; |
| 178 | | logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, pushpc); |
| 179 | | fifoout_push_f(r); |
| 180 | | next_fn(); |
| 151 | logerror("TGP fmul %f*%f=%f (%x)\n", a, b, r, state->pushpc); |
| 152 | fifoout_push_f(state, r); |
| 153 | next_fn(state); |
| 181 | 154 | } |
| 182 | 155 | |
| 183 | 156 | static TGP_FUNCTION( fdiv ) |
| 184 | 157 | { |
| 185 | | float a = fifoin_pop_f(); |
| 186 | | float b = fifoin_pop_f(); |
| 158 | model1_state *state = machine->driver_data<model1_state>(); |
| 159 | float a = fifoin_pop_f(state); |
| 160 | float b = fifoin_pop_f(state); |
| 187 | 161 | // float r = !b ? 1e39 : a/b; |
| 188 | 162 | float r = !b ? 0 : a * (1/b); |
| 189 | | logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, pushpc); |
| 190 | | fifoout_push_f(r); |
| 191 | | next_fn(); |
| 163 | logerror("TGP fdiv %f/%f=%f (%x)\n", a, b, r, state->pushpc); |
| 164 | fifoout_push_f(state, r); |
| 165 | next_fn(state); |
| 192 | 166 | } |
| 193 | 167 | |
| 194 | 168 | static TGP_FUNCTION( matrix_push ) |
| 195 | 169 | { |
| 196 | | if(mat_stack_pos != MAT_STACK_SIZE) { |
| 197 | | memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat)); |
| 198 | | mat_stack_pos++; |
| 170 | model1_state *state = machine->driver_data<model1_state>(); |
| 171 | if(state->mat_stack_pos != MAT_STACK_SIZE) { |
| 172 | memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat)); |
| 173 | state->mat_stack_pos++; |
| 199 | 174 | } |
| 200 | | logerror("TGP matrix_push (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); |
| 201 | | next_fn(); |
| 175 | logerror("TGP matrix_push (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); |
| 176 | next_fn(state); |
| 202 | 177 | } |
| 203 | 178 | |
| 204 | 179 | static TGP_FUNCTION( matrix_pop ) |
| 205 | 180 | { |
| 206 | | if(mat_stack_pos) { |
| 207 | | mat_stack_pos--; |
| 208 | | memcpy(cmat, mat_stack[mat_stack_pos], sizeof(cmat)); |
| 181 | model1_state *state = machine->driver_data<model1_state>(); |
| 182 | if(state->mat_stack_pos) { |
| 183 | state->mat_stack_pos--; |
| 184 | memcpy(state->cmat, state->mat_stack[state->mat_stack_pos], sizeof(state->cmat)); |
| 209 | 185 | } |
| 210 | | logerror("TGP matrix_pop (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); |
| 211 | | next_fn(); |
| 186 | logerror("TGP matrix_pop (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); |
| 187 | next_fn(state); |
| 212 | 188 | } |
| 213 | 189 | |
| 214 | 190 | static TGP_FUNCTION( matrix_write ) |
| 215 | 191 | { |
| 192 | model1_state *state = machine->driver_data<model1_state>(); |
| 216 | 193 | int i; |
| 217 | 194 | for(i=0; i<12; i++) |
| 218 | | cmat[i] = fifoin_pop_f(); |
| 195 | state->cmat[i] = fifoin_pop_f(state); |
| 219 | 196 | logerror("TGP matrix_write %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n", |
| 220 | | cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], |
| 221 | | pushpc); |
| 222 | | next_fn(); |
| 197 | state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11], |
| 198 | state->pushpc); |
| 199 | next_fn(state); |
| 223 | 200 | } |
| 224 | 201 | |
| 225 | 202 | static TGP_FUNCTION( clear_stack ) |
| 226 | 203 | { |
| 227 | | logerror("TGP clear_stack (%x)\n", pushpc); |
| 228 | | mat_stack_pos = 0; |
| 229 | | next_fn(); |
| 204 | model1_state *state = machine->driver_data<model1_state>(); |
| 205 | logerror("TGP clear_stack (%x)\n", state->pushpc); |
| 206 | state->mat_stack_pos = 0; |
| 207 | next_fn(state); |
| 230 | 208 | } |
| 231 | 209 | |
| 232 | 210 | static TGP_FUNCTION( matrix_mul ) |
| 233 | 211 | { |
| 212 | model1_state *state = machine->driver_data<model1_state>(); |
| 234 | 213 | float m[12]; |
| 235 | | float a = fifoin_pop_f(); |
| 236 | | float b = fifoin_pop_f(); |
| 237 | | float c = fifoin_pop_f(); |
| 238 | | float d = fifoin_pop_f(); |
| 239 | | float e = fifoin_pop_f(); |
| 240 | | float f = fifoin_pop_f(); |
| 241 | | float g = fifoin_pop_f(); |
| 242 | | float h = fifoin_pop_f(); |
| 243 | | float i = fifoin_pop_f(); |
| 244 | | float j = fifoin_pop_f(); |
| 245 | | float k = fifoin_pop_f(); |
| 246 | | float l = fifoin_pop_f(); |
| 247 | | logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); |
| 248 | | m[0] = a*cmat[0] + b*cmat[3] + c*cmat[6]; |
| 249 | | m[1] = a*cmat[1] + b*cmat[4] + c*cmat[7]; |
| 250 | | m[2] = a*cmat[2] + b*cmat[5] + c*cmat[8]; |
| 251 | | m[3] = d*cmat[0] + e*cmat[3] + f*cmat[6]; |
| 252 | | m[4] = d*cmat[1] + e*cmat[4] + f*cmat[7]; |
| 253 | | m[5] = d*cmat[2] + e*cmat[5] + f*cmat[8]; |
| 254 | | m[6] = g*cmat[0] + h*cmat[3] + i*cmat[6]; |
| 255 | | m[7] = g*cmat[1] + h*cmat[4] + i*cmat[7]; |
| 256 | | m[8] = g*cmat[2] + h*cmat[5] + i*cmat[8]; |
| 257 | | m[9] = j*cmat[0] + k*cmat[3] + l*cmat[6] + cmat[9]; |
| 258 | | m[10] = j*cmat[1] + k*cmat[4] + l*cmat[7] + cmat[10]; |
| 259 | | m[11] = j*cmat[2] + k*cmat[5] + l*cmat[8] + cmat[11]; |
| 214 | float a = fifoin_pop_f(state); |
| 215 | float b = fifoin_pop_f(state); |
| 216 | float c = fifoin_pop_f(state); |
| 217 | float d = fifoin_pop_f(state); |
| 218 | float e = fifoin_pop_f(state); |
| 219 | float f = fifoin_pop_f(state); |
| 220 | float g = fifoin_pop_f(state); |
| 221 | float h = fifoin_pop_f(state); |
| 222 | float i = fifoin_pop_f(state); |
| 223 | float j = fifoin_pop_f(state); |
| 224 | float k = fifoin_pop_f(state); |
| 225 | float l = fifoin_pop_f(state); |
| 226 | logerror("TGP matrix_mul %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); |
| 227 | m[0] = a*state->cmat[0] + b*state->cmat[3] + c*state->cmat[6]; |
| 228 | m[1] = a*state->cmat[1] + b*state->cmat[4] + c*state->cmat[7]; |
| 229 | m[2] = a*state->cmat[2] + b*state->cmat[5] + c*state->cmat[8]; |
| 230 | m[3] = d*state->cmat[0] + e*state->cmat[3] + f*state->cmat[6]; |
| 231 | m[4] = d*state->cmat[1] + e*state->cmat[4] + f*state->cmat[7]; |
| 232 | m[5] = d*state->cmat[2] + e*state->cmat[5] + f*state->cmat[8]; |
| 233 | m[6] = g*state->cmat[0] + h*state->cmat[3] + i*state->cmat[6]; |
| 234 | m[7] = g*state->cmat[1] + h*state->cmat[4] + i*state->cmat[7]; |
| 235 | m[8] = g*state->cmat[2] + h*state->cmat[5] + i*state->cmat[8]; |
| 236 | m[9] = j*state->cmat[0] + k*state->cmat[3] + l*state->cmat[6] + state->cmat[9]; |
| 237 | m[10] = j*state->cmat[1] + k*state->cmat[4] + l*state->cmat[7] + state->cmat[10]; |
| 238 | m[11] = j*state->cmat[2] + k*state->cmat[5] + l*state->cmat[8] + state->cmat[11]; |
| 260 | 239 | |
| 261 | | memcpy(cmat, m, sizeof(m)); |
| 262 | | next_fn(); |
| 240 | memcpy(state->cmat, m, sizeof(m)); |
| 241 | next_fn(state); |
| 263 | 242 | } |
| 264 | 243 | |
| 265 | 244 | static TGP_FUNCTION( anglev ) |
| 266 | 245 | { |
| 267 | | float a = fifoin_pop_f(); |
| 268 | | float b = fifoin_pop_f(); |
| 269 | | logerror("TGP anglev %f, %f (%x)\n", a, b, pushpc); |
| 246 | model1_state *state = machine->driver_data<model1_state>(); |
| 247 | float a = fifoin_pop_f(state); |
| 248 | float b = fifoin_pop_f(state); |
| 249 | logerror("TGP anglev %f, %f (%x)\n", a, b, state->pushpc); |
| 270 | 250 | if(!b) { |
| 271 | 251 | if(a>=0) |
| 272 | | fifoout_push(0); |
| 252 | fifoout_push(state, 0); |
| 273 | 253 | else |
| 274 | | fifoout_push((UINT32)-32768); |
| 254 | fifoout_push(state, (UINT32)-32768); |
| 275 | 255 | } else if(!a) { |
| 276 | 256 | if(b>=0) |
| 277 | | fifoout_push(16384); |
| 257 | fifoout_push(state, 16384); |
| 278 | 258 | else |
| 279 | | fifoout_push((UINT32)-16384); |
| 259 | fifoout_push(state, (UINT32)-16384); |
| 280 | 260 | } else |
| 281 | | fifoout_push((INT16)(atan2(b, a)*32768/M_PI)); |
| 282 | | next_fn(); |
| 261 | fifoout_push(state, (INT16)(atan2(b, a)*32768/M_PI)); |
| 262 | next_fn(state); |
| 283 | 263 | } |
| 284 | 264 | |
| 285 | 265 | static TGP_FUNCTION( f11 ) |
| 286 | 266 | { |
| 287 | | float a = fifoin_pop_f(); |
| 288 | | float b = fifoin_pop_f(); |
| 289 | | float c = fifoin_pop_f(); |
| 290 | | float d = fifoin_pop_f(); |
| 291 | | float e = fifoin_pop_f(); |
| 292 | | float f = fifoin_pop_f(); |
| 293 | | float g = fifoin_pop_f(); |
| 294 | | float h = fifoin_pop_f(); |
| 295 | | float i = fifoin_pop_f(); |
| 267 | model1_state *state = machine->driver_data<model1_state>(); |
| 268 | float a = fifoin_pop_f(state); |
| 269 | float b = fifoin_pop_f(state); |
| 270 | float c = fifoin_pop_f(state); |
| 271 | float d = fifoin_pop_f(state); |
| 272 | float e = fifoin_pop_f(state); |
| 273 | float f = fifoin_pop_f(state); |
| 274 | float g = fifoin_pop_f(state); |
| 275 | float h = fifoin_pop_f(state); |
| 276 | float i = fifoin_pop_f(state); |
| 296 | 277 | (void)a; |
| 297 | 278 | (void)b; |
| 298 | 279 | (void)c; |
| r10427 | r10428 | |
| 302 | 283 | (void)g; |
| 303 | 284 | (void)h; |
| 304 | 285 | (void)i; |
| 305 | | logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, pushpc); |
| 306 | | fifoout_push_f(0); |
| 307 | | fifoout_push_f(0); |
| 308 | | fifoout_push_f(0); |
| 309 | | next_fn(); |
| 286 | logerror("TGP f11 %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, state->pushpc); |
| 287 | fifoout_push_f(state, 0); |
| 288 | fifoout_push_f(state, 0); |
| 289 | fifoout_push_f(state, 0); |
| 290 | next_fn(state); |
| 310 | 291 | } |
| 311 | 292 | |
| 312 | 293 | static TGP_FUNCTION( normalize ) |
| 313 | 294 | { |
| 314 | | float a = fifoin_pop_f(); |
| 315 | | float b = fifoin_pop_f(); |
| 316 | | float c = fifoin_pop_f(); |
| 295 | model1_state *state = machine->driver_data<model1_state>(); |
| 296 | float a = fifoin_pop_f(state); |
| 297 | float b = fifoin_pop_f(state); |
| 298 | float c = fifoin_pop_f(state); |
| 317 | 299 | float n = (a*a+b*b+c*c) / sqrt(a*a+b*b+c*c); |
| 318 | | logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 319 | | fifoout_push_f(a/n); |
| 320 | | fifoout_push_f(b/n); |
| 321 | | fifoout_push_f(c/n); |
| 322 | | next_fn(); |
| 300 | logerror("TGP normalize %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 301 | fifoout_push_f(state, a/n); |
| 302 | fifoout_push_f(state, b/n); |
| 303 | fifoout_push_f(state, c/n); |
| 304 | next_fn(state); |
| 323 | 305 | } |
| 324 | 306 | |
| 325 | 307 | static TGP_FUNCTION( acc_seti ) |
| 326 | 308 | { |
| 327 | | INT32 a = fifoin_pop(); |
| 328 | | model1_dump = 1; |
| 329 | | logerror("TGP acc_seti %d (%x)\n", a, pushpc); |
| 330 | | acc = a; |
| 331 | | next_fn(); |
| 309 | model1_state *state = machine->driver_data<model1_state>(); |
| 310 | INT32 a = fifoin_pop(state); |
| 311 | state->dump = 1; |
| 312 | logerror("TGP acc_seti %d (%x)\n", a, state->pushpc); |
| 313 | state->acc = a; |
| 314 | next_fn(state); |
| 332 | 315 | } |
| 333 | 316 | |
| 334 | 317 | static TGP_FUNCTION( track_select ) |
| 335 | 318 | { |
| 336 | | INT32 a = fifoin_pop(); |
| 337 | | logerror("TGP track_select %d (%x)\n", a, pushpc); |
| 338 | | tgp_vr_select = a; |
| 339 | | next_fn(); |
| 319 | model1_state *state = machine->driver_data<model1_state>(); |
| 320 | INT32 a = fifoin_pop(state); |
| 321 | logerror("TGP track_select %d (%x)\n", a, state->pushpc); |
| 322 | state->tgp_vr_select = a; |
| 323 | next_fn(state); |
| 340 | 324 | } |
| 341 | 325 | |
| 342 | 326 | static TGP_FUNCTION( f14 ) |
| 343 | 327 | { |
| 344 | | tgp_vr_base[0] = fifoin_pop_f(); |
| 345 | | tgp_vr_base[1] = fifoin_pop_f(); |
| 346 | | tgp_vr_base[2] = fifoin_pop_f(); |
| 347 | | tgp_vr_base[3] = fifoin_pop_f(); |
| 328 | model1_state *state = machine->driver_data<model1_state>(); |
| 329 | state->tgp_vr_base[0] = fifoin_pop_f(state); |
| 330 | state->tgp_vr_base[1] = fifoin_pop_f(state); |
| 331 | state->tgp_vr_base[2] = fifoin_pop_f(state); |
| 332 | state->tgp_vr_base[3] = fifoin_pop_f(state); |
| 348 | 333 | |
| 349 | | next_fn(); |
| 334 | next_fn(state); |
| 350 | 335 | } |
| 351 | 336 | |
| 352 | 337 | static TGP_FUNCTION( f15_swa ) |
| 353 | 338 | { |
| 354 | | logerror("TGP f15_swa (%x)\n", pushpc); |
| 339 | model1_state *state = machine->driver_data<model1_state>(); |
| 340 | logerror("TGP f15_swa (%x)\n", state->pushpc); |
| 355 | 341 | |
| 356 | | next_fn(); |
| 342 | next_fn(state); |
| 357 | 343 | } |
| 358 | 344 | |
| 359 | 345 | static TGP_FUNCTION( anglep ) |
| 360 | 346 | { |
| 361 | | float a = fifoin_pop_f(); |
| 362 | | float b = fifoin_pop_f(); |
| 363 | | float c = fifoin_pop_f(); |
| 364 | | float d = fifoin_pop_f(); |
| 365 | | logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); |
| 347 | model1_state *state = machine->driver_data<model1_state>(); |
| 348 | float a = fifoin_pop_f(state); |
| 349 | float b = fifoin_pop_f(state); |
| 350 | float c = fifoin_pop_f(state); |
| 351 | float d = fifoin_pop_f(state); |
| 352 | logerror("TGP anglep %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); |
| 366 | 353 | c = a - c; |
| 367 | 354 | d = b - d; |
| 368 | 355 | if(!d) { |
| 369 | 356 | if(c>=0) |
| 370 | | fifoout_push(0); |
| 357 | fifoout_push(state, 0); |
| 371 | 358 | else |
| 372 | | fifoout_push((UINT32)-32768); |
| 359 | fifoout_push(state, (UINT32)-32768); |
| 373 | 360 | } else if(!c) { |
| 374 | 361 | if(d>=0) |
| 375 | | fifoout_push(16384); |
| 362 | fifoout_push(state, 16384); |
| 376 | 363 | else |
| 377 | | fifoout_push((UINT32)-16384); |
| 364 | fifoout_push(state, (UINT32)-16384); |
| 378 | 365 | } else |
| 379 | | fifoout_push((INT16)(atan2(d, c)*32768/M_PI)); |
| 380 | | next_fn(); |
| 366 | fifoout_push(state, (INT16)(atan2(d, c)*32768/M_PI)); |
| 367 | next_fn(state); |
| 381 | 368 | } |
| 382 | 369 | |
| 383 | 370 | static TGP_FUNCTION( matrix_ident ) |
| 384 | 371 | { |
| 385 | | logerror("TGP matrix_ident (%x)\n", pushpc); |
| 386 | | memset(cmat, 0, sizeof(cmat)); |
| 387 | | cmat[0] = 1.0; |
| 388 | | cmat[4] = 1.0; |
| 389 | | cmat[8] = 1.0; |
| 390 | | next_fn(); |
| 372 | model1_state *state = machine->driver_data<model1_state>(); |
| 373 | logerror("TGP matrix_ident (%x)\n", state->pushpc); |
| 374 | memset(state->cmat, 0, sizeof(state->cmat)); |
| 375 | state->cmat[0] = 1.0; |
| 376 | state->cmat[4] = 1.0; |
| 377 | state->cmat[8] = 1.0; |
| 378 | next_fn(state); |
| 391 | 379 | } |
| 392 | 380 | |
| 393 | 381 | static TGP_FUNCTION( matrix_read ) |
| 394 | 382 | { |
| 383 | model1_state *state = machine->driver_data<model1_state>(); |
| 395 | 384 | int i; |
| 396 | 385 | logerror("TGP matrix_read (%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f) (%x)\n", |
| 397 | | cmat[0], cmat[1], cmat[2], cmat[3], cmat[4], cmat[5], cmat[6], cmat[7], cmat[8], cmat[9], cmat[10], cmat[11], pushpc); |
| 386 | state->cmat[0], state->cmat[1], state->cmat[2], state->cmat[3], state->cmat[4], state->cmat[5], state->cmat[6], state->cmat[7], state->cmat[8], state->cmat[9], state->cmat[10], state->cmat[11], state->pushpc); |
| 398 | 387 | for(i=0; i<12; i++) |
| 399 | | fifoout_push_f(cmat[i]); |
| 400 | | next_fn(); |
| 388 | fifoout_push_f(state, state->cmat[i]); |
| 389 | next_fn(state); |
| 401 | 390 | } |
| 402 | 391 | |
| 403 | 392 | static TGP_FUNCTION( matrix_trans ) |
| 404 | 393 | { |
| 405 | | float a = fifoin_pop_f(); |
| 406 | | float b = fifoin_pop_f(); |
| 407 | | float c = fifoin_pop_f(); |
| 394 | model1_state *state = machine->driver_data<model1_state>(); |
| 395 | float a = fifoin_pop_f(state); |
| 396 | float b = fifoin_pop_f(state); |
| 397 | float c = fifoin_pop_f(state); |
| 408 | 398 | |
| 409 | | cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; |
| 410 | | cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; |
| 411 | | cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; |
| 412 | | next_fn(); |
| 399 | state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; |
| 400 | state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; |
| 401 | state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; |
| 402 | next_fn(state); |
| 413 | 403 | } |
| 414 | 404 | |
| 415 | 405 | static TGP_FUNCTION( matrix_scale ) |
| 416 | 406 | { |
| 417 | | float a = fifoin_pop_f(); |
| 418 | | float b = fifoin_pop_f(); |
| 419 | | float c = fifoin_pop_f(); |
| 420 | | logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 421 | | cmat[0] *= a; |
| 422 | | cmat[1] *= a; |
| 423 | | cmat[2] *= a; |
| 424 | | cmat[3] *= b; |
| 425 | | cmat[4] *= b; |
| 426 | | cmat[5] *= b; |
| 427 | | cmat[6] *= c; |
| 428 | | cmat[7] *= c; |
| 429 | | cmat[8] *= c; |
| 430 | | next_fn(); |
| 407 | model1_state *state = machine->driver_data<model1_state>(); |
| 408 | float a = fifoin_pop_f(state); |
| 409 | float b = fifoin_pop_f(state); |
| 410 | float c = fifoin_pop_f(state); |
| 411 | logerror("TGP matrix_scale %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 412 | state->cmat[0] *= a; |
| 413 | state->cmat[1] *= a; |
| 414 | state->cmat[2] *= a; |
| 415 | state->cmat[3] *= b; |
| 416 | state->cmat[4] *= b; |
| 417 | state->cmat[5] *= b; |
| 418 | state->cmat[6] *= c; |
| 419 | state->cmat[7] *= c; |
| 420 | state->cmat[8] *= c; |
| 421 | next_fn(state); |
| 431 | 422 | } |
| 432 | 423 | |
| 433 | 424 | static TGP_FUNCTION( matrix_rotx ) |
| 434 | 425 | { |
| 435 | | INT16 a = fifoin_pop(); |
| 426 | model1_state *state = machine->driver_data<model1_state>(); |
| 427 | INT16 a = fifoin_pop(state); |
| 436 | 428 | float s = tsin(a); |
| 437 | 429 | float c = tcos(a); |
| 438 | 430 | float t1, t2; |
| 439 | | logerror("TGP matrix_rotx %d (%x)\n", a, pushpc); |
| 440 | | t1 = cmat[3]; |
| 441 | | t2 = cmat[6]; |
| 442 | | cmat[3] = c*t1-s*t2; |
| 443 | | cmat[6] = s*t1+c*t2; |
| 444 | | t1 = cmat[4]; |
| 445 | | t2 = cmat[7]; |
| 446 | | cmat[4] = c*t1-s*t2; |
| 447 | | cmat[7] = s*t1+c*t2; |
| 448 | | t1 = cmat[5]; |
| 449 | | t2 = cmat[8]; |
| 450 | | cmat[5] = c*t1-s*t2; |
| 451 | | cmat[8] = s*t1+c*t2; |
| 452 | | next_fn(); |
| 431 | logerror("TGP matrix_rotx %d (%x)\n", a, state->pushpc); |
| 432 | t1 = state->cmat[3]; |
| 433 | t2 = state->cmat[6]; |
| 434 | state->cmat[3] = c*t1-s*t2; |
| 435 | state->cmat[6] = s*t1+c*t2; |
| 436 | t1 = state->cmat[4]; |
| 437 | t2 = state->cmat[7]; |
| 438 | state->cmat[4] = c*t1-s*t2; |
| 439 | state->cmat[7] = s*t1+c*t2; |
| 440 | t1 = state->cmat[5]; |
| 441 | t2 = state->cmat[8]; |
| 442 | state->cmat[5] = c*t1-s*t2; |
| 443 | state->cmat[8] = s*t1+c*t2; |
| 444 | next_fn(state); |
| 453 | 445 | } |
| 454 | 446 | |
| 455 | 447 | static TGP_FUNCTION( matrix_roty ) |
| 456 | 448 | { |
| 457 | | INT16 a = fifoin_pop(); |
| 449 | model1_state *state = machine->driver_data<model1_state>(); |
| 450 | INT16 a = fifoin_pop(state); |
| 458 | 451 | float s = tsin(a); |
| 459 | 452 | float c = tcos(a); |
| 460 | 453 | float t1, t2; |
| 461 | 454 | |
| 462 | | logerror("TGP matrix_roty %d (%x)\n", a, pushpc); |
| 463 | | t1 = cmat[6]; |
| 464 | | t2 = cmat[0]; |
| 465 | | cmat[6] = c*t1-s*t2; |
| 466 | | cmat[0] = s*t1+c*t2; |
| 467 | | t1 = cmat[7]; |
| 468 | | t2 = cmat[1]; |
| 469 | | cmat[7] = c*t1-s*t2; |
| 470 | | cmat[1] = s*t1+c*t2; |
| 471 | | t1 = cmat[8]; |
| 472 | | t2 = cmat[2]; |
| 473 | | cmat[8] = c*t1-s*t2; |
| 474 | | cmat[2] = s*t1+c*t2; |
| 475 | | next_fn(); |
| 455 | logerror("TGP matrix_roty %d (%x)\n", a, state->pushpc); |
| 456 | t1 = state->cmat[6]; |
| 457 | t2 = state->cmat[0]; |
| 458 | state->cmat[6] = c*t1-s*t2; |
| 459 | state->cmat[0] = s*t1+c*t2; |
| 460 | t1 = state->cmat[7]; |
| 461 | t2 = state->cmat[1]; |
| 462 | state->cmat[7] = c*t1-s*t2; |
| 463 | state->cmat[1] = s*t1+c*t2; |
| 464 | t1 = state->cmat[8]; |
| 465 | t2 = state->cmat[2]; |
| 466 | state->cmat[8] = c*t1-s*t2; |
| 467 | state->cmat[2] = s*t1+c*t2; |
| 468 | next_fn(state); |
| 476 | 469 | } |
| 477 | 470 | |
| 478 | 471 | static TGP_FUNCTION( matrix_rotz ) |
| 479 | 472 | { |
| 480 | | INT16 a = fifoin_pop(); |
| 473 | model1_state *state = machine->driver_data<model1_state>(); |
| 474 | INT16 a = fifoin_pop(state); |
| 481 | 475 | float s = tsin(a); |
| 482 | 476 | float c = tcos(a); |
| 483 | 477 | float t1, t2; |
| 484 | 478 | |
| 485 | | logerror("TGP matrix_rotz %d (%x)\n", a, pushpc); |
| 486 | | t1 = cmat[0]; |
| 487 | | t2 = cmat[3]; |
| 488 | | cmat[0] = c*t1-s*t2; |
| 489 | | cmat[3] = s*t1+c*t2; |
| 490 | | t1 = cmat[1]; |
| 491 | | t2 = cmat[4]; |
| 492 | | cmat[1] = c*t1-s*t2; |
| 493 | | cmat[4] = s*t1+c*t2; |
| 494 | | t1 = cmat[2]; |
| 495 | | t2 = cmat[5]; |
| 496 | | cmat[2] = c*t1-s*t2; |
| 497 | | cmat[5] = s*t1+c*t2; |
| 498 | | next_fn(); |
| 479 | logerror("TGP matrix_rotz %d (%x)\n", a, state->pushpc); |
| 480 | t1 = state->cmat[0]; |
| 481 | t2 = state->cmat[3]; |
| 482 | state->cmat[0] = c*t1-s*t2; |
| 483 | state->cmat[3] = s*t1+c*t2; |
| 484 | t1 = state->cmat[1]; |
| 485 | t2 = state->cmat[4]; |
| 486 | state->cmat[1] = c*t1-s*t2; |
| 487 | state->cmat[4] = s*t1+c*t2; |
| 488 | t1 = state->cmat[2]; |
| 489 | t2 = state->cmat[5]; |
| 490 | state->cmat[2] = c*t1-s*t2; |
| 491 | state->cmat[5] = s*t1+c*t2; |
| 492 | next_fn(state); |
| 499 | 493 | } |
| 500 | 494 | |
| 501 | 495 | static TGP_FUNCTION( track_read_quad ) |
| 502 | 496 | { |
| 497 | model1_state *state = machine->driver_data<model1_state>(); |
| 503 | 498 | const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); |
| 504 | | UINT32 a = fifoin_pop(); |
| 499 | UINT32 a = fifoin_pop(state); |
| 505 | 500 | int offd; |
| 506 | 501 | |
| 507 | | logerror("TGP track_read_quad %d (%x)\n", a, pushpc); |
| 502 | logerror("TGP track_read_quad %d (%x)\n", a, state->pushpc); |
| 508 | 503 | |
| 509 | | offd = tgp_data[0x20+tgp_vr_select] + 16*a; |
| 510 | | fifoout_push(tgp_data[offd]); |
| 511 | | fifoout_push(tgp_data[offd+1]); |
| 512 | | fifoout_push(tgp_data[offd+2]); |
| 513 | | fifoout_push(tgp_data[offd+3]); |
| 514 | | fifoout_push(tgp_data[offd+4]); |
| 515 | | fifoout_push(tgp_data[offd+5]); |
| 516 | | fifoout_push(tgp_data[offd+6]); |
| 517 | | fifoout_push(tgp_data[offd+7]); |
| 518 | | fifoout_push(tgp_data[offd+8]); |
| 519 | | fifoout_push(tgp_data[offd+9]); |
| 520 | | fifoout_push(tgp_data[offd+10]); |
| 521 | | fifoout_push(tgp_data[offd+11]); |
| 522 | | next_fn(); |
| 504 | offd = tgp_data[0x20+state->tgp_vr_select] + 16*a; |
| 505 | fifoout_push(state, tgp_data[offd]); |
| 506 | fifoout_push(state, tgp_data[offd+1]); |
| 507 | fifoout_push(state, tgp_data[offd+2]); |
| 508 | fifoout_push(state, tgp_data[offd+3]); |
| 509 | fifoout_push(state, tgp_data[offd+4]); |
| 510 | fifoout_push(state, tgp_data[offd+5]); |
| 511 | fifoout_push(state, tgp_data[offd+6]); |
| 512 | fifoout_push(state, tgp_data[offd+7]); |
| 513 | fifoout_push(state, tgp_data[offd+8]); |
| 514 | fifoout_push(state, tgp_data[offd+9]); |
| 515 | fifoout_push(state, tgp_data[offd+10]); |
| 516 | fifoout_push(state, tgp_data[offd+11]); |
| 517 | next_fn(state); |
| 523 | 518 | } |
| 524 | 519 | |
| 525 | 520 | static TGP_FUNCTION( f24_swa ) |
| 526 | 521 | { |
| 527 | | float a = fifoin_pop_f(); |
| 528 | | float b = fifoin_pop_f(); |
| 529 | | float c = fifoin_pop_f(); |
| 530 | | float d = fifoin_pop_f(); |
| 531 | | float e = fifoin_pop_f(); |
| 532 | | float f = fifoin_pop_f(); |
| 533 | | UINT32 g = fifoin_pop(); |
| 522 | model1_state *state = machine->driver_data<model1_state>(); |
| 523 | float a = fifoin_pop_f(state); |
| 524 | float b = fifoin_pop_f(state); |
| 525 | float c = fifoin_pop_f(state); |
| 526 | float d = fifoin_pop_f(state); |
| 527 | float e = fifoin_pop_f(state); |
| 528 | float f = fifoin_pop_f(state); |
| 529 | UINT32 g = fifoin_pop(state); |
| 534 | 530 | (void)a; |
| 535 | 531 | (void)b; |
| 536 | 532 | (void)c; |
| r10427 | r10428 | |
| 538 | 534 | (void)e; |
| 539 | 535 | (void)f; |
| 540 | 536 | (void)g; |
| 541 | | logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, pushpc); |
| 542 | | fifoout_push_f(0); |
| 543 | | next_fn(); |
| 537 | logerror("TGP f24_swa %f, %f, %f, %f, %f, %f, %x (%x)\n", a, b, c, d, e, f, g, state->pushpc); |
| 538 | fifoout_push_f(state, 0); |
| 539 | next_fn(state); |
| 544 | 540 | } |
| 545 | 541 | |
| 546 | 542 | static TGP_FUNCTION( transform_point ) |
| 547 | 543 | { |
| 548 | | float x = fifoin_pop_f(); |
| 549 | | float y = fifoin_pop_f(); |
| 550 | | float z = fifoin_pop_f(); |
| 551 | | logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, pushpc); |
| 544 | model1_state *state = machine->driver_data<model1_state>(); |
| 545 | float x = fifoin_pop_f(state); |
| 546 | float y = fifoin_pop_f(state); |
| 547 | float z = fifoin_pop_f(state); |
| 548 | logerror("TGP transform_point %f, %f, %f (%x)\n", x, y, z, state->pushpc); |
| 552 | 549 | |
| 553 | | fifoout_push_f(cmat[0]*x+cmat[3]*y+cmat[6]*z+cmat[9]); |
| 554 | | fifoout_push_f(cmat[1]*x+cmat[4]*y+cmat[7]*z+cmat[10]); |
| 555 | | fifoout_push_f(cmat[2]*x+cmat[5]*y+cmat[8]*z+cmat[11]); |
| 556 | | next_fn(); |
| 550 | fifoout_push_f(state, state->cmat[0]*x+state->cmat[3]*y+state->cmat[6]*z+state->cmat[9]); |
| 551 | fifoout_push_f(state, state->cmat[1]*x+state->cmat[4]*y+state->cmat[7]*z+state->cmat[10]); |
| 552 | fifoout_push_f(state, state->cmat[2]*x+state->cmat[5]*y+state->cmat[8]*z+state->cmat[11]); |
| 553 | next_fn(state); |
| 557 | 554 | } |
| 558 | 555 | |
| 559 | 556 | static TGP_FUNCTION( fcos_m1 ) |
| 560 | 557 | { |
| 561 | | INT16 a = fifoin_pop(); |
| 562 | | logerror("TGP fcos %d (%x)\n", a, pushpc); |
| 563 | | fifoout_push_f(tcos(a)); |
| 564 | | next_fn(); |
| 558 | model1_state *state = machine->driver_data<model1_state>(); |
| 559 | INT16 a = fifoin_pop(state); |
| 560 | logerror("TGP fcos %d (%x)\n", a, state->pushpc); |
| 561 | fifoout_push_f(state, tcos(a)); |
| 562 | next_fn(state); |
| 565 | 563 | } |
| 566 | 564 | |
| 567 | 565 | static TGP_FUNCTION( fsin_m1 ) |
| 568 | 566 | { |
| 569 | | INT16 a = fifoin_pop(); |
| 570 | | logerror("TGP fsin %d (%x)\n", a, pushpc); |
| 571 | | fifoout_push_f(tsin(a)); |
| 572 | | next_fn(); |
| 567 | model1_state *state = machine->driver_data<model1_state>(); |
| 568 | INT16 a = fifoin_pop(state); |
| 569 | logerror("TGP fsin %d (%x)\n", a, state->pushpc); |
| 570 | fifoout_push_f(state, tsin(a)); |
| 571 | next_fn(state); |
| 573 | 572 | } |
| 574 | 573 | |
| 575 | 574 | static TGP_FUNCTION( fcosm_m1 ) |
| 576 | 575 | { |
| 577 | | INT16 a = fifoin_pop(); |
| 578 | | float b = fifoin_pop_f(); |
| 579 | | logerror("TGP fcosm %d, %f (%x)\n", a, b, pushpc); |
| 580 | | fifoout_push_f(b*tcos(a)); |
| 581 | | next_fn(); |
| 576 | model1_state *state = machine->driver_data<model1_state>(); |
| 577 | INT16 a = fifoin_pop(state); |
| 578 | float b = fifoin_pop_f(state); |
| 579 | logerror("TGP fcosm %d, %f (%x)\n", a, b, state->pushpc); |
| 580 | fifoout_push_f(state, b*tcos(a)); |
| 581 | next_fn(state); |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | static TGP_FUNCTION( fsinm_m1 ) |
| 585 | 585 | { |
| 586 | | INT16 a = fifoin_pop(); |
| 587 | | float b = fifoin_pop_f(); |
| 588 | | model1_dump = 1; |
| 589 | | logerror("TGP fsinm %d, %f (%x)\n", a, b, pushpc); |
| 590 | | fifoout_push_f(b*tsin(a)); |
| 591 | | next_fn(); |
| 586 | model1_state *state = machine->driver_data<model1_state>(); |
| 587 | INT16 a = fifoin_pop(state); |
| 588 | float b = fifoin_pop_f(state); |
| 589 | state->dump = 1; |
| 590 | logerror("TGP fsinm %d, %f (%x)\n", a, b, state->pushpc); |
| 591 | fifoout_push_f(state, b*tsin(a)); |
| 592 | next_fn(state); |
| 592 | 593 | } |
| 593 | 594 | |
| 594 | 595 | static TGP_FUNCTION( distance3 ) |
| 595 | 596 | { |
| 596 | | float a = fifoin_pop_f(); |
| 597 | | float b = fifoin_pop_f(); |
| 598 | | float c = fifoin_pop_f(); |
| 599 | | float d = fifoin_pop_f(); |
| 600 | | float e = fifoin_pop_f(); |
| 601 | | float f = fifoin_pop_f(); |
| 602 | | logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, pushpc); |
| 597 | model1_state *state = machine->driver_data<model1_state>(); |
| 598 | float a = fifoin_pop_f(state); |
| 599 | float b = fifoin_pop_f(state); |
| 600 | float c = fifoin_pop_f(state); |
| 601 | float d = fifoin_pop_f(state); |
| 602 | float e = fifoin_pop_f(state); |
| 603 | float f = fifoin_pop_f(state); |
| 604 | logerror("TGP distance3 (%f, %f, %f), (%f, %f, %f) (%x)\n", a, b, c, d, e, f, state->pushpc); |
| 603 | 605 | a -= d; |
| 604 | 606 | b -= e; |
| 605 | 607 | c -= f; |
| 606 | | fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); |
| 607 | | next_fn(); |
| 608 | fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); |
| 609 | next_fn(state); |
| 608 | 610 | } |
| 609 | 611 | |
| 610 | 612 | static TGP_FUNCTION( ftoi ) |
| 611 | 613 | { |
| 612 | | float a = fifoin_pop_f(); |
| 613 | | logerror("TGP ftoi %f (%x)\n", a, pushpc); |
| 614 | | fifoout_push((int)a); |
| 615 | | next_fn(); |
| 614 | model1_state *state = machine->driver_data<model1_state>(); |
| 615 | float a = fifoin_pop_f(state); |
| 616 | logerror("TGP ftoi %f (%x)\n", a, state->pushpc); |
| 617 | fifoout_push(state, (int)a); |
| 618 | next_fn(state); |
| 616 | 619 | } |
| 617 | 620 | |
| 618 | 621 | static TGP_FUNCTION( itof ) |
| 619 | 622 | { |
| 620 | | INT32 a = fifoin_pop(); |
| 621 | | logerror("TGP itof %d (%x)\n", a, pushpc); |
| 622 | | fifoout_push_f(a); |
| 623 | | next_fn(); |
| 623 | model1_state *state = machine->driver_data<model1_state>(); |
| 624 | INT32 a = fifoin_pop(state); |
| 625 | logerror("TGP itof %d (%x)\n", a, state->pushpc); |
| 626 | fifoout_push_f(state, a); |
| 627 | next_fn(state); |
| 624 | 628 | } |
| 625 | 629 | |
| 626 | 630 | static TGP_FUNCTION( acc_set ) |
| 627 | 631 | { |
| 628 | | float a = fifoin_pop_f(); |
| 629 | | logerror("TGP acc_set %f (%x)\n", a, pushpc); |
| 630 | | acc = a; |
| 631 | | next_fn(); |
| 632 | model1_state *state = machine->driver_data<model1_state>(); |
| 633 | float a = fifoin_pop_f(state); |
| 634 | logerror("TGP acc_set %f (%x)\n", a, state->pushpc); |
| 635 | state->acc = a; |
| 636 | next_fn(state); |
| 632 | 637 | } |
| 633 | 638 | |
| 634 | 639 | static TGP_FUNCTION( acc_get ) |
| 635 | 640 | { |
| 636 | | logerror("TGP acc_get (%x)\n", pushpc); |
| 637 | | fifoout_push_f(acc); |
| 638 | | next_fn(); |
| 641 | model1_state *state = machine->driver_data<model1_state>(); |
| 642 | logerror("TGP acc_get (%x)\n", state->pushpc); |
| 643 | fifoout_push_f(state, state->acc); |
| 644 | next_fn(state); |
| 639 | 645 | } |
| 640 | 646 | |
| 641 | 647 | static TGP_FUNCTION( acc_add ) |
| 642 | 648 | { |
| 643 | | float a = fifoin_pop_f(); |
| 644 | | logerror("TGP acc_add %f (%x)\n", a, pushpc); |
| 645 | | acc += a; |
| 646 | | next_fn(); |
| 649 | model1_state *state = machine->driver_data<model1_state>(); |
| 650 | float a = fifoin_pop_f(state); |
| 651 | logerror("TGP acc_add %f (%x)\n", a, state->pushpc); |
| 652 | state->acc += a; |
| 653 | next_fn(state); |
| 647 | 654 | } |
| 648 | 655 | |
| 649 | 656 | static TGP_FUNCTION( acc_sub ) |
| 650 | 657 | { |
| 651 | | float a = fifoin_pop_f(); |
| 652 | | logerror("TGP acc_sub %f (%x)\n", a, pushpc); |
| 653 | | acc -= a; |
| 654 | | next_fn(); |
| 658 | model1_state *state = machine->driver_data<model1_state>(); |
| 659 | float a = fifoin_pop_f(state); |
| 660 | logerror("TGP acc_sub %f (%x)\n", a, state->pushpc); |
| 661 | state->acc -= a; |
| 662 | next_fn(state); |
| 655 | 663 | } |
| 656 | 664 | |
| 657 | 665 | static TGP_FUNCTION( acc_mul ) |
| 658 | 666 | { |
| 659 | | float a = fifoin_pop_f(); |
| 660 | | logerror("TGP acc_mul %f (%x)\n", a, pushpc); |
| 661 | | acc *= a; |
| 662 | | next_fn(); |
| 667 | model1_state *state = machine->driver_data<model1_state>(); |
| 668 | float a = fifoin_pop_f(state); |
| 669 | logerror("TGP acc_mul %f (%x)\n", a, state->pushpc); |
| 670 | state->acc *= a; |
| 671 | next_fn(state); |
| 663 | 672 | } |
| 664 | 673 | |
| 665 | 674 | static TGP_FUNCTION( acc_div ) |
| 666 | 675 | { |
| 667 | | float a = fifoin_pop_f(); |
| 668 | | logerror("TGP acc_div %f (%x)\n", a, pushpc); |
| 669 | | acc /= a; |
| 670 | | next_fn(); |
| 676 | model1_state *state = machine->driver_data<model1_state>(); |
| 677 | float a = fifoin_pop_f(state); |
| 678 | logerror("TGP acc_div %f (%x)\n", a, state->pushpc); |
| 679 | state->acc /= a; |
| 680 | next_fn(state); |
| 671 | 681 | } |
| 672 | 682 | |
| 673 | 683 | static TGP_FUNCTION( f42 ) |
| 674 | 684 | { |
| 675 | | float a = fifoin_pop_f(); |
| 676 | | float b = fifoin_pop_f(); |
| 677 | | float c = fifoin_pop_f(); |
| 685 | model1_state *state = machine->driver_data<model1_state>(); |
| 686 | float a = fifoin_pop_f(state); |
| 687 | float b = fifoin_pop_f(state); |
| 688 | float c = fifoin_pop_f(state); |
| 678 | 689 | (void)a; |
| 679 | 690 | (void)b; |
| 680 | 691 | (void)c; |
| 681 | | logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 692 | logerror("TGP f42 %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 682 | 693 | // fifoout_push_f((machine->rand() % 1000) - 500); |
| 683 | | fifoout_push_f(0); |
| 684 | | fifoout_push_f(0); |
| 685 | | fifoout_push_f(0); |
| 686 | | fifoout_push_f(0); |
| 687 | | fifoout_push_f(0); |
| 688 | | fifoout_push_f(0); |
| 689 | | next_fn(); |
| 694 | fifoout_push_f(state, 0); |
| 695 | fifoout_push_f(state, 0); |
| 696 | fifoout_push_f(state, 0); |
| 697 | fifoout_push_f(state, 0); |
| 698 | fifoout_push_f(state, 0); |
| 699 | fifoout_push_f(state, 0); |
| 700 | next_fn(state); |
| 690 | 701 | } |
| 691 | 702 | |
| 692 | 703 | |
| r10427 | r10428 | |
| 694 | 705 | |
| 695 | 706 | static TGP_FUNCTION( xyz2rqf ) |
| 696 | 707 | { |
| 697 | | float a = fifoin_pop_f(); |
| 698 | | float b = fifoin_pop_f(); |
| 699 | | float c = fifoin_pop_f(); |
| 708 | model1_state *state = machine->driver_data<model1_state>(); |
| 709 | float a = fifoin_pop_f(state); |
| 710 | float b = fifoin_pop_f(state); |
| 711 | float c = fifoin_pop_f(state); |
| 700 | 712 | float norm; |
| 701 | 713 | (void)a; |
| 702 | 714 | (void)b; |
| 703 | 715 | (void)c; |
| 704 | | logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 705 | | fifoout_push_f((a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); |
| 716 | logerror("TGP xyz2rqf %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 717 | fifoout_push_f(state, (a*a+b*b+c*c)/sqrt(a*a+b*b+c*c)); |
| 706 | 718 | norm = sqrt(a*a+c*c); |
| 707 | 719 | if(!c) { |
| 708 | 720 | if(a>=0) |
| 709 | | fifoout_push(0); |
| 721 | fifoout_push(state, 0); |
| 710 | 722 | else |
| 711 | | fifoout_push((UINT32)-32768); |
| 723 | fifoout_push(state, (UINT32)-32768); |
| 712 | 724 | } else if(!a) { |
| 713 | 725 | if(c>=0) |
| 714 | | fifoout_push(16384); |
| 726 | fifoout_push(state, 16384); |
| 715 | 727 | else |
| 716 | | fifoout_push((UINT32)-16384); |
| 728 | fifoout_push(state, (UINT32)-16384); |
| 717 | 729 | } else |
| 718 | | fifoout_push((INT16)(atan2(c, a)*32768/M_PI)); |
| 730 | fifoout_push(state, (INT16)(atan2(c, a)*32768/M_PI)); |
| 719 | 731 | |
| 720 | 732 | if(!b) |
| 721 | | fifoout_push(0); |
| 733 | fifoout_push(state, 0); |
| 722 | 734 | else if(!norm) { |
| 723 | 735 | if(b>=0) |
| 724 | | fifoout_push(16384); |
| 736 | fifoout_push(state, 16384); |
| 725 | 737 | else |
| 726 | | fifoout_push((UINT32)-16384); |
| 738 | fifoout_push(state, (UINT32)-16384); |
| 727 | 739 | } else |
| 728 | | fifoout_push((INT16)(atan2(b, norm)*32768/M_PI)); |
| 740 | fifoout_push(state, (INT16)(atan2(b, norm)*32768/M_PI)); |
| 729 | 741 | |
| 730 | | next_fn(); |
| 742 | next_fn(state); |
| 731 | 743 | } |
| 732 | 744 | |
| 733 | 745 | static TGP_FUNCTION( f43 ) |
| 734 | 746 | { |
| 735 | | float a = fifoin_pop_f(); |
| 736 | | float b = fifoin_pop_f(); |
| 737 | | float c = fifoin_pop_f(); |
| 738 | | float d = fifoin_pop_f(); |
| 739 | | float e = fifoin_pop_f(); |
| 740 | | float f = fifoin_pop_f(); |
| 747 | model1_state *state = machine->driver_data<model1_state>(); |
| 748 | float a = fifoin_pop_f(state); |
| 749 | float b = fifoin_pop_f(state); |
| 750 | float c = fifoin_pop_f(state); |
| 751 | float d = fifoin_pop_f(state); |
| 752 | float e = fifoin_pop_f(state); |
| 753 | float f = fifoin_pop_f(state); |
| 741 | 754 | (void)a; |
| 742 | 755 | (void)b; |
| 743 | 756 | (void)c; |
| 744 | 757 | (void)d; |
| 745 | 758 | (void)e; |
| 746 | 759 | (void)f; |
| 747 | | logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc); |
| 748 | | fifoout_push_f(0); |
| 749 | | fifoout_push_f(0); |
| 750 | | fifoout_push_f(0); |
| 751 | | fifoout_push_f(0); |
| 752 | | next_fn(); |
| 760 | logerror("TGP f43 %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc); |
| 761 | fifoout_push_f(state, 0); |
| 762 | fifoout_push_f(state, 0); |
| 763 | fifoout_push_f(state, 0); |
| 764 | fifoout_push_f(state, 0); |
| 765 | next_fn(state); |
| 753 | 766 | } |
| 754 | 767 | |
| 755 | 768 | static TGP_FUNCTION( f43_swa ) |
| 756 | 769 | { |
| 757 | | float a = fifoin_pop_f(); |
| 758 | | int b = fifoin_pop(); |
| 759 | | int c = fifoin_pop(); |
| 770 | model1_state *state = machine->driver_data<model1_state>(); |
| 771 | float a = fifoin_pop_f(state); |
| 772 | int b = fifoin_pop(state); |
| 773 | int c = fifoin_pop(state); |
| 760 | 774 | (void)a; |
| 761 | 775 | (void)b; |
| 762 | 776 | (void)c; |
| 763 | | logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, pushpc); |
| 764 | | fifoout_push_f(0); |
| 765 | | fifoout_push_f(0); |
| 766 | | fifoout_push_f(0); |
| 767 | | next_fn(); |
| 777 | logerror("TGP f43_swa %f, %d, %d (%x)\n", a, b, c, state->pushpc); |
| 778 | fifoout_push_f(state, 0); |
| 779 | fifoout_push_f(state, 0); |
| 780 | fifoout_push_f(state, 0); |
| 781 | next_fn(state); |
| 768 | 782 | } |
| 769 | 783 | |
| 770 | 784 | static TGP_FUNCTION( f44 ) |
| 771 | 785 | { |
| 772 | | float a = fifoin_pop_f(); |
| 786 | model1_state *state = machine->driver_data<model1_state>(); |
| 787 | float a = fifoin_pop_f(state); |
| 773 | 788 | (void)a; |
| 774 | | logerror("TGP f44 %f (%x)\n", a, pushpc); |
| 775 | | fifoout_push_f(0); |
| 776 | | fifoout_push_f(0); |
| 777 | | fifoout_push_f(0); |
| 778 | | next_fn(); |
| 789 | logerror("TGP f44 %f (%x)\n", a, state->pushpc); |
| 790 | fifoout_push_f(state, 0); |
| 791 | fifoout_push_f(state, 0); |
| 792 | fifoout_push_f(state, 0); |
| 793 | next_fn(state); |
| 779 | 794 | } |
| 780 | 795 | |
| 781 | 796 | static TGP_FUNCTION( matrix_sdir ) |
| 782 | 797 | { |
| 783 | | float a = fifoin_pop_f(); |
| 784 | | float b = fifoin_pop_f(); |
| 785 | | float c = fifoin_pop_f(); |
| 798 | model1_state *state = machine->driver_data<model1_state>(); |
| 799 | float a = fifoin_pop_f(state); |
| 800 | float b = fifoin_pop_f(state); |
| 801 | float c = fifoin_pop_f(state); |
| 786 | 802 | float norm = sqrt(a*a+b*b+c*c); |
| 787 | 803 | float t[9], m[9]; |
| 788 | | logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 804 | logerror("TGP matrix_sdir %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 789 | 805 | |
| 790 | 806 | memset(t, 0, sizeof(t)); |
| 791 | 807 | |
| r10427 | r10428 | |
| 813 | 829 | t[5] /= norm; |
| 814 | 830 | } |
| 815 | 831 | |
| 816 | | m[0] = t[0]*cmat[0] + t[1]*cmat[3] + t[2]*cmat[6]; |
| 817 | | m[1] = t[0]*cmat[1] + t[1]*cmat[4] + t[2]*cmat[7]; |
| 818 | | m[2] = t[0]*cmat[2] + t[1]*cmat[5] + t[2]*cmat[8]; |
| 819 | | m[3] = t[3]*cmat[0] + t[4]*cmat[3] + t[5]*cmat[6]; |
| 820 | | m[4] = t[3]*cmat[1] + t[4]*cmat[4] + t[5]*cmat[7]; |
| 821 | | m[5] = t[3]*cmat[2] + t[4]*cmat[5] + t[5]*cmat[8]; |
| 822 | | m[6] = t[6]*cmat[0] + t[7]*cmat[3] + t[8]*cmat[6]; |
| 823 | | m[7] = t[6]*cmat[1] + t[7]*cmat[4] + t[8]*cmat[7]; |
| 824 | | m[8] = t[6]*cmat[2] + t[7]*cmat[5] + t[8]*cmat[8]; |
| 832 | m[0] = t[0]*state->cmat[0] + t[1]*state->cmat[3] + t[2]*state->cmat[6]; |
| 833 | m[1] = t[0]*state->cmat[1] + t[1]*state->cmat[4] + t[2]*state->cmat[7]; |
| 834 | m[2] = t[0]*state->cmat[2] + t[1]*state->cmat[5] + t[2]*state->cmat[8]; |
| 835 | m[3] = t[3]*state->cmat[0] + t[4]*state->cmat[3] + t[5]*state->cmat[6]; |
| 836 | m[4] = t[3]*state->cmat[1] + t[4]*state->cmat[4] + t[5]*state->cmat[7]; |
| 837 | m[5] = t[3]*state->cmat[2] + t[4]*state->cmat[5] + t[5]*state->cmat[8]; |
| 838 | m[6] = t[6]*state->cmat[0] + t[7]*state->cmat[3] + t[8]*state->cmat[6]; |
| 839 | m[7] = t[6]*state->cmat[1] + t[7]*state->cmat[4] + t[8]*state->cmat[7]; |
| 840 | m[8] = t[6]*state->cmat[2] + t[7]*state->cmat[5] + t[8]*state->cmat[8]; |
| 825 | 841 | |
| 826 | | memcpy(cmat, m, sizeof(m)); |
| 842 | memcpy(state->cmat, m, sizeof(m)); |
| 827 | 843 | |
| 828 | | next_fn(); |
| 844 | next_fn(state); |
| 829 | 845 | } |
| 830 | 846 | |
| 831 | 847 | static TGP_FUNCTION( f45 ) |
| 832 | 848 | { |
| 833 | | float a = fifoin_pop_f(); |
| 849 | model1_state *state = machine->driver_data<model1_state>(); |
| 850 | float a = fifoin_pop_f(state); |
| 834 | 851 | (void)a; |
| 835 | | logerror("TGP f45 %f (%x)\n", a, pushpc); |
| 836 | | fifoout_push_f(0); |
| 837 | | next_fn(); |
| 852 | logerror("TGP f45 %f (%x)\n", a, state->pushpc); |
| 853 | fifoout_push_f(state, 0); |
| 854 | next_fn(state); |
| 838 | 855 | } |
| 839 | 856 | |
| 840 | 857 | static TGP_FUNCTION( vlength ) |
| 841 | 858 | { |
| 842 | | float a = fifoin_pop_f() - tgp_vr_base[0]; |
| 843 | | float b = fifoin_pop_f() - tgp_vr_base[1]; |
| 844 | | float c = fifoin_pop_f() - tgp_vr_base[2]; |
| 845 | | logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 859 | model1_state *state = machine->driver_data<model1_state>(); |
| 860 | float a = fifoin_pop_f(state) - state->tgp_vr_base[0]; |
| 861 | float b = fifoin_pop_f(state) - state->tgp_vr_base[1]; |
| 862 | float c = fifoin_pop_f(state) - state->tgp_vr_base[2]; |
| 863 | logerror("TGP vlength %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 846 | 864 | |
| 847 | 865 | a = (a*a+b*b+c*c); |
| 848 | 866 | b = 1/sqrt(a); |
| 849 | 867 | c = a * b; |
| 850 | | c -= tgp_vr_base[3]; |
| 851 | | fifoout_push_f(c); |
| 852 | | next_fn(); |
| 868 | c -= state->tgp_vr_base[3]; |
| 869 | fifoout_push_f(state, c); |
| 870 | next_fn(state); |
| 853 | 871 | } |
| 854 | 872 | |
| 855 | 873 | static TGP_FUNCTION( f47 ) |
| 856 | 874 | { |
| 857 | | float a = fifoin_pop_f(); |
| 858 | | float b = fifoin_pop_f(); |
| 859 | | float c = fifoin_pop_f(); |
| 860 | | logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 861 | | fifoout_push_f(a+c); |
| 862 | | fifoout_push_f(b+c); |
| 863 | | next_fn(); |
| 875 | model1_state *state = machine->driver_data<model1_state>(); |
| 876 | float a = fifoin_pop_f(state); |
| 877 | float b = fifoin_pop_f(state); |
| 878 | float c = fifoin_pop_f(state); |
| 879 | logerror("TGP f47 %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 880 | fifoout_push_f(state, a+c); |
| 881 | fifoout_push_f(state, b+c); |
| 882 | next_fn(state); |
| 864 | 883 | } |
| 865 | 884 | |
| 866 | 885 | static TGP_FUNCTION( track_read_info ) |
| 867 | 886 | { |
| 887 | model1_state *state = machine->driver_data<model1_state>(); |
| 868 | 888 | const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); |
| 869 | | UINT16 a = fifoin_pop(); |
| 889 | UINT16 a = fifoin_pop(state); |
| 870 | 890 | int offd; |
| 871 | 891 | |
| 872 | | logerror("TGP track_read_info %d (%x)\n", a, pushpc); |
| 892 | logerror("TGP track_read_info %d (%x)\n", a, state->pushpc); |
| 873 | 893 | |
| 874 | | offd = tgp_data[0x20+tgp_vr_select] + 16*a; |
| 875 | | fifoout_push(tgp_data[offd+15]); |
| 876 | | next_fn(); |
| 894 | offd = tgp_data[0x20+state->tgp_vr_select] + 16*a; |
| 895 | fifoout_push(state, tgp_data[offd+15]); |
| 896 | next_fn(state); |
| 877 | 897 | } |
| 878 | 898 | |
| 879 | 899 | static TGP_FUNCTION( colbox_set ) |
| 880 | 900 | { |
| 881 | | float a = fifoin_pop_f(); |
| 882 | | float b = fifoin_pop_f(); |
| 883 | | float c = fifoin_pop_f(); |
| 884 | | float d = fifoin_pop_f(); |
| 885 | | float e = fifoin_pop_f(); |
| 886 | | float f = fifoin_pop_f(); |
| 887 | | float g = fifoin_pop_f(); |
| 888 | | float h = fifoin_pop_f(); |
| 889 | | float i = fifoin_pop_f(); |
| 890 | | float j = fifoin_pop_f(); |
| 891 | | float k = fifoin_pop_f(); |
| 892 | | float l = fifoin_pop_f(); |
| 893 | | logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); |
| 894 | | tgp_vr_cbox[ 0] = a; |
| 895 | | tgp_vr_cbox[ 1] = b; |
| 896 | | tgp_vr_cbox[ 2] = c; |
| 897 | | tgp_vr_cbox[ 3] = d; |
| 898 | | tgp_vr_cbox[ 4] = e; |
| 899 | | tgp_vr_cbox[ 5] = f; |
| 900 | | tgp_vr_cbox[ 6] = g; |
| 901 | | tgp_vr_cbox[ 7] = h; |
| 902 | | tgp_vr_cbox[ 8] = i; |
| 903 | | tgp_vr_cbox[ 9] = j; |
| 904 | | tgp_vr_cbox[10] = k; |
| 905 | | tgp_vr_cbox[11] = l; |
| 906 | | next_fn(); |
| 901 | model1_state *state = machine->driver_data<model1_state>(); |
| 902 | float a = fifoin_pop_f(state); |
| 903 | float b = fifoin_pop_f(state); |
| 904 | float c = fifoin_pop_f(state); |
| 905 | float d = fifoin_pop_f(state); |
| 906 | float e = fifoin_pop_f(state); |
| 907 | float f = fifoin_pop_f(state); |
| 908 | float g = fifoin_pop_f(state); |
| 909 | float h = fifoin_pop_f(state); |
| 910 | float i = fifoin_pop_f(state); |
| 911 | float j = fifoin_pop_f(state); |
| 912 | float k = fifoin_pop_f(state); |
| 913 | float l = fifoin_pop_f(state); |
| 914 | logerror("TGP colbox_set %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); |
| 915 | state->tgp_vr_cbox[ 0] = a; |
| 916 | state->tgp_vr_cbox[ 1] = b; |
| 917 | state->tgp_vr_cbox[ 2] = c; |
| 918 | state->tgp_vr_cbox[ 3] = d; |
| 919 | state->tgp_vr_cbox[ 4] = e; |
| 920 | state->tgp_vr_cbox[ 5] = f; |
| 921 | state->tgp_vr_cbox[ 6] = g; |
| 922 | state->tgp_vr_cbox[ 7] = h; |
| 923 | state->tgp_vr_cbox[ 8] = i; |
| 924 | state->tgp_vr_cbox[ 9] = j; |
| 925 | state->tgp_vr_cbox[10] = k; |
| 926 | state->tgp_vr_cbox[11] = l; |
| 927 | next_fn(state); |
| 907 | 928 | } |
| 908 | 929 | |
| 909 | 930 | static TGP_FUNCTION( colbox_test ) |
| 910 | 931 | { |
| 911 | | float a = fifoin_pop_f(); |
| 912 | | float b = fifoin_pop_f(); |
| 913 | | float c = fifoin_pop_f(); |
| 932 | model1_state *state = machine->driver_data<model1_state>(); |
| 933 | float a = fifoin_pop_f(state); |
| 934 | float b = fifoin_pop_f(state); |
| 935 | float c = fifoin_pop_f(state); |
| 914 | 936 | (void)a; |
| 915 | 937 | (void)b; |
| 916 | 938 | (void)c; |
| 917 | | logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 939 | logerror("TGP colbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 918 | 940 | |
| 919 | | // #### Wrong, need to check with the tgp_vr_cbox coordinates |
| 941 | // #### Wrong, need to check with the state->tgp_vr_cbox coordinates |
| 920 | 942 | // Game only test sign, negative = collision |
| 921 | | fifoout_push_f(-1); |
| 922 | | next_fn(); |
| 943 | fifoout_push_f(state, -1); |
| 944 | next_fn(state); |
| 923 | 945 | } |
| 924 | 946 | |
| 925 | 947 | static TGP_FUNCTION( f49_swa ) |
| 926 | 948 | { |
| 927 | | float a = fifoin_pop_f(); |
| 928 | | float b = fifoin_pop_f(); |
| 929 | | float c = fifoin_pop_f(); |
| 930 | | float d = fifoin_pop_f(); |
| 931 | | float e = fifoin_pop_f(); |
| 932 | | float f = fifoin_pop_f(); |
| 949 | model1_state *state = machine->driver_data<model1_state>(); |
| 950 | float a = fifoin_pop_f(state); |
| 951 | float b = fifoin_pop_f(state); |
| 952 | float c = fifoin_pop_f(state); |
| 953 | float d = fifoin_pop_f(state); |
| 954 | float e = fifoin_pop_f(state); |
| 955 | float f = fifoin_pop_f(state); |
| 933 | 956 | (void)a; |
| 934 | 957 | (void)b; |
| 935 | 958 | (void)c; |
| 936 | 959 | (void)d; |
| 937 | 960 | (void)e; |
| 938 | 961 | (void)f; |
| 939 | | logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, pushpc); |
| 940 | | next_fn(); |
| 962 | logerror("TGP f49_swa %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, state->pushpc); |
| 963 | next_fn(state); |
| 941 | 964 | } |
| 942 | 965 | |
| 943 | 966 | static TGP_FUNCTION( f50_swa ) |
| 944 | 967 | { |
| 945 | | float a = fifoin_pop_f(); |
| 946 | | float b = fifoin_pop_f(); |
| 947 | | float c = fifoin_pop_f(); |
| 948 | | float d = fifoin_pop_f(); |
| 968 | model1_state *state = machine->driver_data<model1_state>(); |
| 969 | float a = fifoin_pop_f(state); |
| 970 | float b = fifoin_pop_f(state); |
| 971 | float c = fifoin_pop_f(state); |
| 972 | float d = fifoin_pop_f(state); |
| 949 | 973 | (void)a; |
| 950 | 974 | (void)b; |
| 951 | 975 | (void)c; |
| 952 | 976 | (void)d; |
| 953 | | logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); |
| 954 | | fifoout_push_f(d); |
| 955 | | next_fn(); |
| 977 | logerror("TGP f50_swa %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); |
| 978 | fifoout_push_f(state, d); |
| 979 | next_fn(state); |
| 956 | 980 | } |
| 957 | 981 | |
| 958 | 982 | static TGP_FUNCTION( f52 ) |
| 959 | 983 | { |
| 960 | | logerror("TGP f52 (%x)\n", pushpc); |
| 961 | | next_fn(); |
| 984 | model1_state *state = machine->driver_data<model1_state>(); |
| 985 | logerror("TGP f52 (%x)\n", state->pushpc); |
| 986 | next_fn(state); |
| 962 | 987 | } |
| 963 | 988 | |
| 964 | 989 | static TGP_FUNCTION( matrix_rdir ) |
| 965 | 990 | { |
| 966 | | float a = fifoin_pop_f(); |
| 967 | | float b = fifoin_pop_f(); |
| 968 | | float c = fifoin_pop_f(); |
| 991 | model1_state *state = machine->driver_data<model1_state>(); |
| 992 | float a = fifoin_pop_f(state); |
| 993 | float b = fifoin_pop_f(state); |
| 994 | float c = fifoin_pop_f(state); |
| 969 | 995 | float norm = sqrt(a*a+c*c); |
| 970 | 996 | float t1, t2; |
| 971 | 997 | (void)b; |
| 972 | 998 | |
| 973 | | logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 999 | logerror("TGP matrix_rdir %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 974 | 1000 | |
| 975 | 1001 | if(!norm) { |
| 976 | 1002 | c = 1; |
| r10427 | r10428 | |
| 980 | 1006 | a /= norm; |
| 981 | 1007 | } |
| 982 | 1008 | |
| 983 | | t1 = cmat[6]; |
| 984 | | t2 = cmat[0]; |
| 985 | | cmat[6] = c*t1-a*t2; |
| 986 | | cmat[0] = a*t1+c*t2; |
| 987 | | t1 = cmat[7]; |
| 988 | | t2 = cmat[1]; |
| 989 | | cmat[7] = c*t1-a*t2; |
| 990 | | cmat[1] = a*t1+c*t2; |
| 991 | | t1 = cmat[8]; |
| 992 | | t2 = cmat[2]; |
| 993 | | cmat[8] = c*t1-a*t2; |
| 994 | | cmat[2] = a*t1+c*t2; |
| 995 | | next_fn(); |
| 1009 | t1 = state->cmat[6]; |
| 1010 | t2 = state->cmat[0]; |
| 1011 | state->cmat[6] = c*t1-a*t2; |
| 1012 | state->cmat[0] = a*t1+c*t2; |
| 1013 | t1 = state->cmat[7]; |
| 1014 | t2 = state->cmat[1]; |
| 1015 | state->cmat[7] = c*t1-a*t2; |
| 1016 | state->cmat[1] = a*t1+c*t2; |
| 1017 | t1 = state->cmat[8]; |
| 1018 | t2 = state->cmat[2]; |
| 1019 | state->cmat[8] = c*t1-a*t2; |
| 1020 | state->cmat[2] = a*t1+c*t2; |
| 1021 | next_fn(state); |
| 996 | 1022 | } |
| 997 | 1023 | |
| 998 | 1024 | // A+(B-A)*t1 + (C-A)*t2 = P |
| r10427 | r10428 | |
| 1012 | 1038 | |
| 1013 | 1039 | static TGP_FUNCTION( track_lookup ) |
| 1014 | 1040 | { |
| 1041 | model1_state *state = machine->driver_data<model1_state>(); |
| 1015 | 1042 | const UINT32 *tgp_data = (const UINT32 *)machine->region("user2")->base(); |
| 1016 | | float a = fifoin_pop_f(); |
| 1017 | | UINT32 b = fifoin_pop(); |
| 1018 | | float c = fifoin_pop_f(); |
| 1019 | | float d = fifoin_pop_f(); |
| 1043 | float a = fifoin_pop_f(state); |
| 1044 | UINT32 b = fifoin_pop(state); |
| 1045 | float c = fifoin_pop_f(state); |
| 1046 | float d = fifoin_pop_f(state); |
| 1020 | 1047 | int offi, offd, len; |
| 1021 | 1048 | float dist; |
| 1022 | 1049 | int i; |
| 1023 | 1050 | UINT32 behaviour, entry; |
| 1024 | 1051 | float height; |
| 1025 | 1052 | |
| 1026 | | logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, pushpc); |
| 1053 | logerror("TGP track_lookup %f, 0x%x, %f, %f (%x)\n", a, b, c, d, state->pushpc); |
| 1027 | 1054 | |
| 1028 | | offi = tgp_data[0x10+tgp_vr_select] + b; |
| 1029 | | offd = tgp_data[0x20+tgp_vr_select]; |
| 1055 | offi = tgp_data[0x10+state->tgp_vr_select] + b; |
| 1056 | offd = tgp_data[0x20+state->tgp_vr_select]; |
| 1030 | 1057 | |
| 1031 | 1058 | len = tgp_data[offi++]; |
| 1032 | 1059 | |
| r10427 | r10428 | |
| 1061 | 1088 | } |
| 1062 | 1089 | } |
| 1063 | 1090 | |
| 1064 | | ram_data[0x0000] = 0; // non zero = still computing |
| 1065 | | ram_data[0x8001] = f2u(height); |
| 1066 | | ram_data[0x8002] = entry; |
| 1091 | state->ram_data[0x0000] = 0; // non zero = still computing |
| 1092 | state->ram_data[0x8001] = f2u(height); |
| 1093 | state->ram_data[0x8002] = entry; |
| 1067 | 1094 | |
| 1068 | | next_fn(); |
| 1095 | next_fn(state); |
| 1069 | 1096 | } |
| 1070 | 1097 | |
| 1071 | 1098 | static TGP_FUNCTION( f56 ) |
| 1072 | 1099 | { |
| 1073 | | float a = fifoin_pop_f(); |
| 1074 | | float b = fifoin_pop_f(); |
| 1075 | | float c = fifoin_pop_f(); |
| 1076 | | float d = fifoin_pop_f(); |
| 1077 | | float e = fifoin_pop_f(); |
| 1078 | | float f = fifoin_pop_f(); |
| 1079 | | UINT32 g = fifoin_pop(); |
| 1100 | model1_state *state = machine->driver_data<model1_state>(); |
| 1101 | float a = fifoin_pop_f(state); |
| 1102 | float b = fifoin_pop_f(state); |
| 1103 | float c = fifoin_pop_f(state); |
| 1104 | float d = fifoin_pop_f(state); |
| 1105 | float e = fifoin_pop_f(state); |
| 1106 | float f = fifoin_pop_f(state); |
| 1107 | UINT32 g = fifoin_pop(state); |
| 1080 | 1108 | (void)a; |
| 1081 | 1109 | (void)b; |
| 1082 | 1110 | (void)c; |
| r10427 | r10428 | |
| 1085 | 1113 | (void)f; |
| 1086 | 1114 | (void)g; |
| 1087 | 1115 | |
| 1088 | | logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, pushpc); |
| 1089 | | fifoout_push(0); |
| 1090 | | next_fn(); |
| 1116 | logerror("TGP f56 %f, %f, %f, %f, %f, %f, %d (%x)\n", a, b, c, d, e, f, g, state->pushpc); |
| 1117 | fifoout_push(state, 0); |
| 1118 | next_fn(state); |
| 1091 | 1119 | } |
| 1092 | 1120 | |
| 1093 | 1121 | static TGP_FUNCTION( f57 ) |
| 1094 | 1122 | { |
| 1095 | | logerror("TGP f57 (%x)\n", pushpc); |
| 1096 | | fifoout_push_f(0); |
| 1097 | | fifoout_push_f(0); |
| 1098 | | fifoout_push_f(0); |
| 1099 | | next_fn(); |
| 1123 | model1_state *state = machine->driver_data<model1_state>(); |
| 1124 | logerror("TGP f57 (%x)\n", state->pushpc); |
| 1125 | fifoout_push_f(state, 0); |
| 1126 | fifoout_push_f(state, 0); |
| 1127 | fifoout_push_f(state, 0); |
| 1128 | next_fn(state); |
| 1100 | 1129 | } |
| 1101 | 1130 | |
| 1102 | 1131 | static TGP_FUNCTION( matrix_readt ) |
| 1103 | 1132 | { |
| 1104 | | logerror("TGP matrix_readt (%x)\n", pushpc); |
| 1105 | | fifoout_push_f(cmat[9]); |
| 1106 | | fifoout_push_f(cmat[10]); |
| 1107 | | fifoout_push_f(cmat[11]); |
| 1108 | | next_fn(); |
| 1133 | model1_state *state = machine->driver_data<model1_state>(); |
| 1134 | logerror("TGP matrix_readt (%x)\n", state->pushpc); |
| 1135 | fifoout_push_f(state, state->cmat[9]); |
| 1136 | fifoout_push_f(state, state->cmat[10]); |
| 1137 | fifoout_push_f(state, state->cmat[11]); |
| 1138 | next_fn(state); |
| 1109 | 1139 | } |
| 1110 | 1140 | |
| 1111 | 1141 | static TGP_FUNCTION( acc_geti ) |
| 1112 | 1142 | { |
| 1113 | | logerror("TGP acc_geti (%x)\n", pushpc); |
| 1114 | | fifoout_push((int)acc); |
| 1115 | | next_fn(); |
| 1143 | model1_state *state = machine->driver_data<model1_state>(); |
| 1144 | logerror("TGP acc_geti (%x)\n", state->pushpc); |
| 1145 | fifoout_push(state, (int)state->acc); |
| 1146 | next_fn(state); |
| 1116 | 1147 | } |
| 1117 | 1148 | |
| 1118 | 1149 | static TGP_FUNCTION( f60 ) |
| 1119 | 1150 | { |
| 1120 | | logerror("TGP f60 (%x)\n", pushpc); |
| 1121 | | fifoout_push_f(0); |
| 1122 | | fifoout_push_f(0); |
| 1123 | | fifoout_push_f(0); |
| 1124 | | next_fn(); |
| 1151 | model1_state *state = machine->driver_data<model1_state>(); |
| 1152 | logerror("TGP f60 (%x)\n", state->pushpc); |
| 1153 | fifoout_push_f(state, 0); |
| 1154 | fifoout_push_f(state, 0); |
| 1155 | fifoout_push_f(state, 0); |
| 1156 | next_fn(state); |
| 1125 | 1157 | } |
| 1126 | 1158 | |
| 1127 | 1159 | static TGP_FUNCTION( col_setcirc ) |
| 1128 | 1160 | { |
| 1129 | | float a = fifoin_pop_f(); |
| 1130 | | float b = fifoin_pop_f(); |
| 1131 | | float c = fifoin_pop_f(); |
| 1132 | | logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 1133 | | tgp_vr_circx = a; |
| 1134 | | tgp_vr_circy = b; |
| 1135 | | tgp_vr_circrad = c; |
| 1136 | | next_fn(); |
| 1161 | model1_state *state = machine->driver_data<model1_state>(); |
| 1162 | float a = fifoin_pop_f(state); |
| 1163 | float b = fifoin_pop_f(state); |
| 1164 | float c = fifoin_pop_f(state); |
| 1165 | logerror("TGP col_setcirc %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 1166 | state->tgp_vr_circx = a; |
| 1167 | state->tgp_vr_circy = b; |
| 1168 | state->tgp_vr_circrad = c; |
| 1169 | next_fn(state); |
| 1137 | 1170 | } |
| 1138 | 1171 | |
| 1139 | 1172 | static TGP_FUNCTION( col_testpt ) |
| 1140 | 1173 | { |
| 1174 | model1_state *state = machine->driver_data<model1_state>(); |
| 1141 | 1175 | float x, y; |
| 1142 | | float a = fifoin_pop_f(); |
| 1143 | | float b = fifoin_pop_f(); |
| 1144 | | logerror("TGP col_testpt %f, %f (%x)\n", a, b, pushpc); |
| 1145 | | x = a - tgp_vr_circx; |
| 1146 | | y = b - tgp_vr_circy; |
| 1147 | | fifoout_push_f(((x*x+y*y)/sqrt(x*x+y*y)) - tgp_vr_circrad); |
| 1148 | | next_fn(); |
| 1176 | float a = fifoin_pop_f(state); |
| 1177 | float b = fifoin_pop_f(state); |
| 1178 | logerror("TGP col_testpt %f, %f (%x)\n", a, b, state->pushpc); |
| 1179 | x = a - state->tgp_vr_circx; |
| 1180 | y = b - state->tgp_vr_circy; |
| 1181 | fifoout_push_f(state, ((x*x+y*y)/sqrt(x*x+y*y)) - state->tgp_vr_circrad); |
| 1182 | next_fn(state); |
| 1149 | 1183 | } |
| 1150 | 1184 | |
| 1151 | 1185 | static TGP_FUNCTION( push_and_ident ) |
| 1152 | 1186 | { |
| 1153 | | if(mat_stack_pos != MAT_STACK_SIZE) { |
| 1154 | | memcpy(mat_stack[mat_stack_pos], cmat, sizeof(cmat)); |
| 1155 | | mat_stack_pos++; |
| 1187 | model1_state *state = machine->driver_data<model1_state>(); |
| 1188 | if(state->mat_stack_pos != MAT_STACK_SIZE) { |
| 1189 | memcpy(state->mat_stack[state->mat_stack_pos], state->cmat, sizeof(state->cmat)); |
| 1190 | state->mat_stack_pos++; |
| 1156 | 1191 | } |
| 1157 | | logerror("TGP push_and_ident (depth=%d, pc=%x)\n", mat_stack_pos, pushpc); |
| 1158 | | memset(cmat, 0, sizeof(cmat)); |
| 1159 | | cmat[0] = 1.0; |
| 1160 | | cmat[4] = 1.0; |
| 1161 | | cmat[8] = 1.0; |
| 1162 | | next_fn(); |
| 1192 | logerror("TGP push_and_ident (depth=%d, pc=%x)\n", state->mat_stack_pos, state->pushpc); |
| 1193 | memset(state->cmat, 0, sizeof(state->cmat)); |
| 1194 | state->cmat[0] = 1.0; |
| 1195 | state->cmat[4] = 1.0; |
| 1196 | state->cmat[8] = 1.0; |
| 1197 | next_fn(state); |
| 1163 | 1198 | } |
| 1164 | 1199 | |
| 1165 | 1200 | static TGP_FUNCTION( catmull_rom ) |
| 1166 | 1201 | { |
| 1167 | | float a = fifoin_pop_f(); |
| 1168 | | float b = fifoin_pop_f(); |
| 1169 | | float c = fifoin_pop_f(); |
| 1170 | | float d = fifoin_pop_f(); |
| 1171 | | float e = fifoin_pop_f(); |
| 1172 | | float f = fifoin_pop_f(); |
| 1173 | | float g = fifoin_pop_f(); |
| 1174 | | float h = fifoin_pop_f(); |
| 1175 | | float i = fifoin_pop_f(); |
| 1176 | | float j = fifoin_pop_f(); |
| 1177 | | float k = fifoin_pop_f(); |
| 1178 | | float l = fifoin_pop_f(); |
| 1179 | | float m = fifoin_pop_f(); |
| 1202 | model1_state *state = machine->driver_data<model1_state>(); |
| 1203 | float a = fifoin_pop_f(state); |
| 1204 | float b = fifoin_pop_f(state); |
| 1205 | float c = fifoin_pop_f(state); |
| 1206 | float d = fifoin_pop_f(state); |
| 1207 | float e = fifoin_pop_f(state); |
| 1208 | float f = fifoin_pop_f(state); |
| 1209 | float g = fifoin_pop_f(state); |
| 1210 | float h = fifoin_pop_f(state); |
| 1211 | float i = fifoin_pop_f(state); |
| 1212 | float j = fifoin_pop_f(state); |
| 1213 | float k = fifoin_pop_f(state); |
| 1214 | float l = fifoin_pop_f(state); |
| 1215 | float m = fifoin_pop_f(state); |
| 1180 | 1216 | float m2, m3; |
| 1181 | 1217 | float w1, w2, w3, w4; |
| 1182 | 1218 | |
| 1183 | | logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, pushpc); |
| 1219 | logerror("TGP catmull_rom %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, m, state->pushpc); |
| 1184 | 1220 | |
| 1185 | 1221 | m2 = m*m; |
| 1186 | 1222 | m3 = m*m*m; |
| r10427 | r10428 | |
| 1190 | 1226 | w3 = 0.5*(-3*m3+4*m2+m); |
| 1191 | 1227 | w4 = 0.5*(m3-m2); |
| 1192 | 1228 | |
| 1193 | | fifoout_push_f(a*w1+d*w2+g*w3+j*w4); |
| 1194 | | fifoout_push_f(b*w1+e*w2+h*w3+k*w4); |
| 1195 | | fifoout_push_f(c*w1+f*w2+i*w3+l*w4); |
| 1196 | | next_fn(); |
| 1229 | fifoout_push_f(state, a*w1+d*w2+g*w3+j*w4); |
| 1230 | fifoout_push_f(state, b*w1+e*w2+h*w3+k*w4); |
| 1231 | fifoout_push_f(state, c*w1+f*w2+i*w3+l*w4); |
| 1232 | next_fn(state); |
| 1197 | 1233 | } |
| 1198 | 1234 | |
| 1199 | 1235 | static TGP_FUNCTION( distance ) |
| 1200 | 1236 | { |
| 1201 | | float a = fifoin_pop_f(); |
| 1202 | | float b = fifoin_pop_f(); |
| 1203 | | float c = fifoin_pop_f(); |
| 1204 | | float d = fifoin_pop_f(); |
| 1205 | | logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc); |
| 1237 | model1_state *state = machine->driver_data<model1_state>(); |
| 1238 | float a = fifoin_pop_f(state); |
| 1239 | float b = fifoin_pop_f(state); |
| 1240 | float c = fifoin_pop_f(state); |
| 1241 | float d = fifoin_pop_f(state); |
| 1242 | logerror("TGP distance (%f, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc); |
| 1206 | 1243 | c -= a; |
| 1207 | 1244 | d -= b; |
| 1208 | | fifoout_push_f((c*c+d*d)/sqrt(c*c+d*d)); |
| 1209 | | next_fn(); |
| 1245 | fifoout_push_f(state, (c*c+d*d)/sqrt(c*c+d*d)); |
| 1246 | next_fn(state); |
| 1210 | 1247 | } |
| 1211 | 1248 | |
| 1212 | 1249 | static TGP_FUNCTION( car_move ) |
| 1213 | 1250 | { |
| 1214 | | INT16 a = fifoin_pop(); |
| 1215 | | float b = fifoin_pop_f(); |
| 1216 | | float c = fifoin_pop_f(); |
| 1217 | | float d = fifoin_pop_f(); |
| 1251 | model1_state *state = machine->driver_data<model1_state>(); |
| 1252 | INT16 a = fifoin_pop(state); |
| 1253 | float b = fifoin_pop_f(state); |
| 1254 | float c = fifoin_pop_f(state); |
| 1255 | float d = fifoin_pop_f(state); |
| 1218 | 1256 | float dx, dy; |
| 1219 | | logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, pushpc); |
| 1257 | logerror("TGP car_move (%d, %f), (%f, %f) (%x)\n", a, b, c, d, state->pushpc); |
| 1220 | 1258 | |
| 1221 | 1259 | dx = b*tsin(a); |
| 1222 | 1260 | dy = b*tcos(a); |
| 1223 | 1261 | |
| 1224 | | fifoout_push_f(dx); |
| 1225 | | fifoout_push_f(dy); |
| 1226 | | fifoout_push_f(c+dx); |
| 1227 | | fifoout_push_f(d+dy); |
| 1228 | | next_fn(); |
| 1262 | fifoout_push_f(state, dx); |
| 1263 | fifoout_push_f(state, dy); |
| 1264 | fifoout_push_f(state, c+dx); |
| 1265 | fifoout_push_f(state, d+dy); |
| 1266 | next_fn(state); |
| 1229 | 1267 | } |
| 1230 | 1268 | |
| 1231 | 1269 | static TGP_FUNCTION( cpa ) |
| 1232 | 1270 | { |
| 1271 | model1_state *state = machine->driver_data<model1_state>(); |
| 1233 | 1272 | float dv_x, dv_y, dv_z, dv2, dw_x, dw_y, dw_z, dt; |
| 1234 | 1273 | |
| 1235 | | float a = fifoin_pop_f(); |
| 1236 | | float b = fifoin_pop_f(); |
| 1237 | | float c = fifoin_pop_f(); |
| 1238 | | float d = fifoin_pop_f(); |
| 1239 | | float e = fifoin_pop_f(); |
| 1240 | | float f = fifoin_pop_f(); |
| 1241 | | float g = fifoin_pop_f(); |
| 1242 | | float h = fifoin_pop_f(); |
| 1243 | | float i = fifoin_pop_f(); |
| 1244 | | float j = fifoin_pop_f(); |
| 1245 | | float k = fifoin_pop_f(); |
| 1246 | | float l = fifoin_pop_f(); |
| 1247 | | logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, pushpc); |
| 1274 | float a = fifoin_pop_f(state); |
| 1275 | float b = fifoin_pop_f(state); |
| 1276 | float c = fifoin_pop_f(state); |
| 1277 | float d = fifoin_pop_f(state); |
| 1278 | float e = fifoin_pop_f(state); |
| 1279 | float f = fifoin_pop_f(state); |
| 1280 | float g = fifoin_pop_f(state); |
| 1281 | float h = fifoin_pop_f(state); |
| 1282 | float i = fifoin_pop_f(state); |
| 1283 | float j = fifoin_pop_f(state); |
| 1284 | float k = fifoin_pop_f(state); |
| 1285 | float l = fifoin_pop_f(state); |
| 1286 | logerror("TGP cpa %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, h, i, j, k, l, state->pushpc); |
| 1248 | 1287 | |
| 1249 | 1288 | dv_x = (b-a) - (d-c); |
| 1250 | 1289 | dv_y = (f-e) - (h-g); |
| r10427 | r10428 | |
| 1268 | 1307 | dv_z = (i-k)*(1-dt) + (j-l)*dt; |
| 1269 | 1308 | dv2 = dv_x*dv_x + dv_y*dv_y + dv_z*dv_z; |
| 1270 | 1309 | |
| 1271 | | fifoout_push_f(sqrt(dv2)); |
| 1272 | | next_fn(); |
| 1310 | fifoout_push_f(state, sqrt(dv2)); |
| 1311 | next_fn(state); |
| 1273 | 1312 | } |
| 1274 | 1313 | |
| 1275 | 1314 | static TGP_FUNCTION( vmat_store ) |
| 1276 | 1315 | { |
| 1277 | | UINT32 a = fifoin_pop(); |
| 1316 | model1_state *state = machine->driver_data<model1_state>(); |
| 1317 | UINT32 a = fifoin_pop(state); |
| 1278 | 1318 | if(a<21) |
| 1279 | | memcpy(mat_vector[a], cmat, sizeof(cmat)); |
| 1319 | memcpy(state->mat_vector[a], state->cmat, sizeof(state->cmat)); |
| 1280 | 1320 | else |
| 1281 | 1321 | logerror("TGP ERROR bad vector index\n"); |
| 1282 | | logerror("TGP vmat_store %d (%x)\n", a, pushpc); |
| 1283 | | next_fn(); |
| 1322 | logerror("TGP vmat_store %d (%x)\n", a, state->pushpc); |
| 1323 | next_fn(state); |
| 1284 | 1324 | } |
| 1285 | 1325 | |
| 1286 | 1326 | static TGP_FUNCTION( vmat_restore ) |
| 1287 | 1327 | { |
| 1288 | | UINT32 a = fifoin_pop(); |
| 1328 | model1_state *state = machine->driver_data<model1_state>(); |
| 1329 | UINT32 a = fifoin_pop(state); |
| 1289 | 1330 | if(a<21) |
| 1290 | | memcpy(cmat, mat_vector[a], sizeof(cmat)); |
| 1331 | memcpy(state->cmat, state->mat_vector[a], sizeof(state->cmat)); |
| 1291 | 1332 | else |
| 1292 | 1333 | logerror("TGP ERROR bad vector index\n"); |
| 1293 | | logerror("TGP vmat_restore %d (%x)\n", a, pushpc); |
| 1294 | | next_fn(); |
| 1334 | logerror("TGP vmat_restore %d (%x)\n", a, state->pushpc); |
| 1335 | next_fn(state); |
| 1295 | 1336 | } |
| 1296 | 1337 | |
| 1297 | 1338 | static TGP_FUNCTION( vmat_mul ) |
| 1298 | 1339 | { |
| 1299 | | UINT32 a = fifoin_pop(); |
| 1300 | | UINT32 b = fifoin_pop(); |
| 1340 | model1_state *state = machine->driver_data<model1_state>(); |
| 1341 | UINT32 a = fifoin_pop(state); |
| 1342 | UINT32 b = fifoin_pop(state); |
| 1301 | 1343 | if(a<21 && b<21) { |
| 1302 | | mat_vector[b][0] = mat_vector[a][ 0]*cmat[0] + mat_vector[a][ 1]*cmat[3] + mat_vector[a][ 2]*cmat[6]; |
| 1303 | | mat_vector[b][1] = mat_vector[a][ 0]*cmat[1] + mat_vector[a][ 1]*cmat[4] + mat_vector[a][ 2]*cmat[7]; |
| 1304 | | mat_vector[b][2] = mat_vector[a][ 0]*cmat[2] + mat_vector[a][ 1]*cmat[5] + mat_vector[a][ 2]*cmat[8]; |
| 1305 | | mat_vector[b][3] = mat_vector[a][ 3]*cmat[0] + mat_vector[a][ 4]*cmat[3] + mat_vector[a][ 5]*cmat[6]; |
| 1306 | | mat_vector[b][4] = mat_vector[a][ 3]*cmat[1] + mat_vector[a][ 4]*cmat[4] + mat_vector[a][ 5]*cmat[7]; |
| 1307 | | mat_vector[b][5] = mat_vector[a][ 3]*cmat[2] + mat_vector[a][ 4]*cmat[5] + mat_vector[a][ 5]*cmat[8]; |
| 1308 | | mat_vector[b][6] = mat_vector[a][ 6]*cmat[0] + mat_vector[a][ 7]*cmat[3] + mat_vector[a][ 8]*cmat[6]; |
| 1309 | | mat_vector[b][7] = mat_vector[a][ 6]*cmat[1] + mat_vector[a][ 7]*cmat[4] + mat_vector[a][ 8]*cmat[7]; |
| 1310 | | mat_vector[b][8] = mat_vector[a][ 6]*cmat[2] + mat_vector[a][ 7]*cmat[5] + mat_vector[a][ 8]*cmat[8]; |
| 1311 | | mat_vector[b][9] = mat_vector[a][ 9]*cmat[0] + mat_vector[a][10]*cmat[3] + mat_vector[a][11]*cmat[6] + cmat[9]; |
| 1312 | | mat_vector[b][10] = mat_vector[a][ 9]*cmat[1] + mat_vector[a][10]*cmat[4] + mat_vector[a][11]*cmat[7] + cmat[10]; |
| 1313 | | mat_vector[b][11] = mat_vector[a][ 9]*cmat[2] + mat_vector[a][10]*cmat[5] + mat_vector[a][11]*cmat[8] + cmat[11]; |
| 1344 | state->mat_vector[b][0] = state->mat_vector[a][ 0]*state->cmat[0] + state->mat_vector[a][ 1]*state->cmat[3] + state->mat_vector[a][ 2]*state->cmat[6]; |
| 1345 | state->mat_vector[b][1] = state->mat_vector[a][ 0]*state->cmat[1] + state->mat_vector[a][ 1]*state->cmat[4] + state->mat_vector[a][ 2]*state->cmat[7]; |
| 1346 | state->mat_vector[b][2] = state->mat_vector[a][ 0]*state->cmat[2] + state->mat_vector[a][ 1]*state->cmat[5] + state->mat_vector[a][ 2]*state->cmat[8]; |
| 1347 | state->mat_vector[b][3] = state->mat_vector[a][ 3]*state->cmat[0] + state->mat_vector[a][ 4]*state->cmat[3] + state->mat_vector[a][ 5]*state->cmat[6]; |
| 1348 | state->mat_vector[b][4] = state->mat_vector[a][ 3]*state->cmat[1] + state->mat_vector[a][ 4]*state->cmat[4] + state->mat_vector[a][ 5]*state->cmat[7]; |
| 1349 | state->mat_vector[b][5] = state->mat_vector[a][ 3]*state->cmat[2] + state->mat_vector[a][ 4]*state->cmat[5] + state->mat_vector[a][ 5]*state->cmat[8]; |
| 1350 | state->mat_vector[b][6] = state->mat_vector[a][ 6]*state->cmat[0] + state->mat_vector[a][ 7]*state->cmat[3] + state->mat_vector[a][ 8]*state->cmat[6]; |
| 1351 | state->mat_vector[b][7] = state->mat_vector[a][ 6]*state->cmat[1] + state->mat_vector[a][ 7]*state->cmat[4] + state->mat_vector[a][ 8]*state->cmat[7]; |
| 1352 | state->mat_vector[b][8] = state->mat_vector[a][ 6]*state->cmat[2] + state->mat_vector[a][ 7]*state->cmat[5] + state->mat_vector[a][ 8]*state->cmat[8]; |
| 1353 | state->mat_vector[b][9] = state->mat_vector[a][ 9]*state->cmat[0] + state->mat_vector[a][10]*state->cmat[3] + state->mat_vector[a][11]*state->cmat[6] + state->cmat[9]; |
| 1354 | state->mat_vector[b][10] = state->mat_vector[a][ 9]*state->cmat[1] + state->mat_vector[a][10]*state->cmat[4] + state->mat_vector[a][11]*state->cmat[7] + state->cmat[10]; |
| 1355 | state->mat_vector[b][11] = state->mat_vector[a][ 9]*state->cmat[2] + state->mat_vector[a][10]*state->cmat[5] + state->mat_vector[a][11]*state->cmat[8] + state->cmat[11]; |
| 1314 | 1356 | } else |
| 1315 | 1357 | logerror("TGP ERROR bad vector index\n"); |
| 1316 | | logerror("TGP vmat_mul %d, %d (%x)\n", a, b, pushpc); |
| 1317 | | next_fn(); |
| 1358 | logerror("TGP vmat_mul %d, %d (%x)\n", a, b, state->pushpc); |
| 1359 | next_fn(state); |
| 1318 | 1360 | } |
| 1319 | 1361 | |
| 1320 | 1362 | static TGP_FUNCTION( vmat_read ) |
| 1321 | 1363 | { |
| 1322 | | UINT32 a = fifoin_pop(); |
| 1323 | | logerror("TGP vmat_read %d (%x)\n", a, pushpc); |
| 1364 | model1_state *state = machine->driver_data<model1_state>(); |
| 1365 | UINT32 a = fifoin_pop(state); |
| 1366 | logerror("TGP vmat_read %d (%x)\n", a, state->pushpc); |
| 1324 | 1367 | if(a<21) { |
| 1325 | 1368 | int i; |
| 1326 | 1369 | for(i=0; i<12; i++) |
| 1327 | | fifoout_push_f(mat_vector[a][i]); |
| 1370 | fifoout_push_f(state, state->mat_vector[a][i]); |
| 1328 | 1371 | } else { |
| 1329 | 1372 | int i; |
| 1330 | 1373 | logerror("TGP ERROR bad vector index\n"); |
| 1331 | 1374 | for(i=0; i<12; i++) |
| 1332 | | fifoout_push_f(0); |
| 1375 | fifoout_push_f(state, 0); |
| 1333 | 1376 | } |
| 1334 | | next_fn(); |
| 1377 | next_fn(state); |
| 1335 | 1378 | } |
| 1336 | 1379 | |
| 1337 | 1380 | static TGP_FUNCTION( matrix_rtrans ) |
| 1338 | 1381 | { |
| 1339 | | logerror("TGP matrix_rtrans (%x)\n", pushpc); |
| 1340 | | fifoout_push_f(cmat[ 9]); |
| 1341 | | fifoout_push_f(cmat[10]); |
| 1342 | | fifoout_push_f(cmat[11]); |
| 1343 | | next_fn(); |
| 1382 | model1_state *state = machine->driver_data<model1_state>(); |
| 1383 | logerror("TGP matrix_rtrans (%x)\n", state->pushpc); |
| 1384 | fifoout_push_f(state, state->cmat[ 9]); |
| 1385 | fifoout_push_f(state, state->cmat[10]); |
| 1386 | fifoout_push_f(state, state->cmat[11]); |
| 1387 | next_fn(state); |
| 1344 | 1388 | } |
| 1345 | 1389 | |
| 1346 | 1390 | static TGP_FUNCTION( matrix_unrot ) |
| 1347 | 1391 | { |
| 1348 | | logerror("TGP matrix_unrot (%x)\n", pushpc); |
| 1349 | | memset(cmat, 0, 9*sizeof(cmat[0])); |
| 1350 | | cmat[0] = 1.0; |
| 1351 | | cmat[4] = 1.0; |
| 1352 | | cmat[8] = 1.0; |
| 1353 | | next_fn(); |
| 1392 | model1_state *state = machine->driver_data<model1_state>(); |
| 1393 | logerror("TGP matrix_unrot (%x)\n", state->pushpc); |
| 1394 | memset(state->cmat, 0, 9*sizeof(state->cmat[0])); |
| 1395 | state->cmat[0] = 1.0; |
| 1396 | state->cmat[4] = 1.0; |
| 1397 | state->cmat[8] = 1.0; |
| 1398 | next_fn(state); |
| 1354 | 1399 | } |
| 1355 | 1400 | |
| 1356 | 1401 | static TGP_FUNCTION( f80 ) |
| 1357 | 1402 | { |
| 1358 | | logerror("TGP f80 (%x)\n", pushpc); |
| 1359 | | // cmat[9] = cmat[10] = cmat[11] = 0; |
| 1360 | | next_fn(); |
| 1403 | model1_state *state = machine->driver_data<model1_state>(); |
| 1404 | logerror("TGP f80 (%x)\n", state->pushpc); |
| 1405 | // state->cmat[9] = state->cmat[10] = state->cmat[11] = 0; |
| 1406 | next_fn(state); |
| 1361 | 1407 | } |
| 1362 | 1408 | |
| 1363 | 1409 | static TGP_FUNCTION( vmat_save ) |
| 1364 | 1410 | { |
| 1365 | | UINT32 a = fifoin_pop(); |
| 1411 | model1_state *state = machine->driver_data<model1_state>(); |
| 1412 | UINT32 a = fifoin_pop(state); |
| 1366 | 1413 | int i; |
| 1367 | | logerror("TGP vmat_save 0x%x (%x)\n", a, pushpc); |
| 1414 | logerror("TGP vmat_save 0x%x (%x)\n", a, state->pushpc); |
| 1368 | 1415 | for(i=0; i<16; i++) |
| 1369 | | memcpy(ram_data+a+0x10*i, mat_vector[i], sizeof(cmat)); |
| 1370 | | next_fn(); |
| 1416 | memcpy(state->ram_data+a+0x10*i, state->mat_vector[i], sizeof(state->cmat)); |
| 1417 | next_fn(state); |
| 1371 | 1418 | } |
| 1372 | 1419 | |
| 1373 | 1420 | static TGP_FUNCTION( vmat_load ) |
| 1374 | 1421 | { |
| 1375 | | UINT32 a = fifoin_pop(); |
| 1422 | model1_state *state = machine->driver_data<model1_state>(); |
| 1423 | UINT32 a = fifoin_pop(state); |
| 1376 | 1424 | int i; |
| 1377 | | logerror("TGP vmat_load 0x%x (%x)\n", a, pushpc); |
| 1425 | logerror("TGP vmat_load 0x%x (%x)\n", a, state->pushpc); |
| 1378 | 1426 | for(i=0; i<16; i++) |
| 1379 | | memcpy(mat_vector[i], ram_data+a+0x10*i, sizeof(cmat)); |
| 1380 | | next_fn(); |
| 1427 | memcpy(state->mat_vector[i], state->ram_data+a+0x10*i, sizeof(state->cmat)); |
| 1428 | next_fn(state); |
| 1381 | 1429 | } |
| 1382 | 1430 | |
| 1383 | 1431 | static TGP_FUNCTION( ram_setadr ) |
| 1384 | 1432 | { |
| 1385 | | ram_scanadr = fifoin_pop() - 0x8000; |
| 1386 | | logerror("TGP f0 ram_setadr 0x%x (%x)\n", ram_scanadr+0x8000, pushpc); |
| 1387 | | next_fn(); |
| 1433 | model1_state *state = machine->driver_data<model1_state>(); |
| 1434 | state->ram_scanadr = fifoin_pop(state) - 0x8000; |
| 1435 | logerror("TGP f0 ram_setadr 0x%x (%x)\n", state->ram_scanadr+0x8000, state->pushpc); |
| 1436 | next_fn(state); |
| 1388 | 1437 | } |
| 1389 | 1438 | |
| 1390 | 1439 | static TGP_FUNCTION( groundbox_test ) |
| 1391 | 1440 | { |
| 1441 | model1_state *state = machine->driver_data<model1_state>(); |
| 1392 | 1442 | int out_x, out_y, out_z; |
| 1393 | 1443 | float x, /*y,*/ z; |
| 1394 | | float a = fifoin_pop_f(); |
| 1395 | | float b = fifoin_pop_f(); |
| 1396 | | float c = fifoin_pop_f(); |
| 1444 | float a = fifoin_pop_f(state); |
| 1445 | float b = fifoin_pop_f(state); |
| 1446 | float c = fifoin_pop_f(state); |
| 1397 | 1447 | |
| 1398 | | logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, pushpc); |
| 1399 | | x = cmat[0]*a+cmat[3]*b+cmat[6]*c+cmat[9]; |
| 1400 | | //y = cmat[1]*a+cmat[4]*b+cmat[7]*c+cmat[10]; |
| 1401 | | z = cmat[2]*a+cmat[5]*b+cmat[8]*c+cmat[11]; |
| 1448 | logerror("TGP groundbox_test %f, %f, %f (%x)\n", a, b, c, state->pushpc); |
| 1449 | x = state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c+state->cmat[9]; |
| 1450 | //y = state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c+state->cmat[10]; |
| 1451 | z = state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c+state->cmat[11]; |
| 1402 | 1452 | |
| 1403 | | out_x = x < tgp_vf_xmin || x > tgp_vf_xmax; |
| 1404 | | out_z = z < tgp_vf_zmin || z > tgp_vf_zmax; |
| 1453 | out_x = x < state->tgp_vf_xmin || x > state->tgp_vf_xmax; |
| 1454 | out_z = z < state->tgp_vf_zmin || z > state->tgp_vf_zmax; |
| 1405 | 1455 | out_y = 1; // Wrong, but untestable it seems. |
| 1406 | 1456 | |
| 1407 | | fifoout_push(out_x); |
| 1408 | | fifoout_push(out_y); |
| 1409 | | fifoout_push(out_z); |
| 1410 | | next_fn(); |
| 1457 | fifoout_push(state, out_x); |
| 1458 | fifoout_push(state, out_y); |
| 1459 | fifoout_push(state, out_z); |
| 1460 | next_fn(state); |
| 1411 | 1461 | } |
| 1412 | 1462 | |
| 1413 | 1463 | static TGP_FUNCTION( f89 ) |
| 1414 | 1464 | { |
| 1415 | | UINT32 a = fifoin_pop(); |
| 1416 | | UINT32 b = fifoin_pop(); |
| 1417 | | UINT32 c = fifoin_pop(); |
| 1418 | | UINT32 d = fifoin_pop(); |
| 1465 | model1_state *state = machine->driver_data<model1_state>(); |
| 1466 | UINT32 a = fifoin_pop(state); |
| 1467 | UINT32 b = fifoin_pop(state); |
| 1468 | UINT32 c = fifoin_pop(state); |
| 1469 | UINT32 d = fifoin_pop(state); |
| 1419 | 1470 | (void)a; |
| 1420 | 1471 | (void)b; |
| 1421 | 1472 | (void)c; |
| 1422 | | logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, pushpc); |
| 1423 | | list_length = d; |
| 1424 | | next_fn(); |
| 1473 | logerror("TGP list set base 0x%x, 0x%x, %d, length=%d (%x)\n", a, b, c, d, state->pushpc); |
| 1474 | state->list_length = d; |
| 1475 | next_fn(state); |
| 1425 | 1476 | } |
| 1426 | 1477 | |
| 1427 | 1478 | static TGP_FUNCTION( f92 ) |
| 1428 | 1479 | { |
| 1429 | | float a = fifoin_pop_f(); |
| 1430 | | float b = fifoin_pop_f(); |
| 1431 | | float c = fifoin_pop_f(); |
| 1432 | | float d = fifoin_pop_f(); |
| 1480 | model1_state *state = machine->driver_data<model1_state>(); |
| 1481 | float a = fifoin_pop_f(state); |
| 1482 | float b = fifoin_pop_f(state); |
| 1483 | float c = fifoin_pop_f(state); |
| 1484 | float d = fifoin_pop_f(state); |
| 1433 | 1485 | (void)a; |
| 1434 | 1486 | (void)b; |
| 1435 | 1487 | (void)c; |
| 1436 | 1488 | (void)d; |
| 1437 | | logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, pushpc); |
| 1438 | | next_fn(); |
| 1489 | logerror("TGP f92 %f, %f, %f, %f (%x)\n", a, b, c, d, state->pushpc); |
| 1490 | next_fn(state); |
| 1439 | 1491 | } |
| 1440 | 1492 | |
| 1441 | 1493 | static TGP_FUNCTION( f93 ) |
| 1442 | 1494 | { |
| 1443 | | float a = fifoin_pop_f(); |
| 1495 | model1_state *state = machine->driver_data<model1_state>(); |
| 1496 | float a = fifoin_pop_f(state); |
| 1444 | 1497 | (void)a; |
| 1445 | | logerror("TGP f93 %f (%x)\n", a, pushpc); |
| 1446 | | next_fn(); |
| 1498 | logerror("TGP f93 %f (%x)\n", a, state->pushpc); |
| 1499 | next_fn(state); |
| 1447 | 1500 | } |
| 1448 | 1501 | |
| 1449 | 1502 | static TGP_FUNCTION( f94 ) |
| 1450 | 1503 | { |
| 1451 | | UINT32 a = fifoin_pop(); |
| 1504 | model1_state *state = machine->driver_data<model1_state>(); |
| 1505 | UINT32 a = fifoin_pop(state); |
| 1452 | 1506 | (void)a; |
| 1453 | | logerror("TGP f94 %d (%x)\n", a, pushpc); |
| 1454 | | next_fn(); |
| 1507 | logerror("TGP f94 %d (%x)\n", a, state->pushpc); |
| 1508 | next_fn(state); |
| 1455 | 1509 | } |
| 1456 | 1510 | |
| 1457 | 1511 | static TGP_FUNCTION( vmat_flatten ) |
| 1458 | 1512 | { |
| 1513 | model1_state *state = machine->driver_data<model1_state>(); |
| 1459 | 1514 | int i; |
| 1460 | 1515 | float m[12]; |
| 1461 | | logerror("TGP vmat_flatten (%x)\n", pushpc); |
| 1516 | logerror("TGP vmat_flatten (%x)\n", state->pushpc); |
| 1462 | 1517 | |
| 1463 | 1518 | for(i=0; i<16; i++) { |
| 1464 | | memcpy(m, mat_vector[i], sizeof(cmat)); |
| 1519 | memcpy(m, state->mat_vector[i], sizeof(state->cmat)); |
| 1465 | 1520 | m[1] = m[4] = m[7] = m[10] = 0; |
| 1466 | 1521 | |
| 1467 | | mat_vector[i][0] = m[ 0]*cmat[0] + m[ 1]*cmat[3] + m[ 2]*cmat[6]; |
| 1468 | | mat_vector[i][1] = m[ 0]*cmat[1] + m[ 1]*cmat[4] + m[ 2]*cmat[7]; |
| 1469 | | mat_vector[i][2] = m[ 0]*cmat[2] + m[ 1]*cmat[5] + m[ 2]*cmat[8]; |
| 1470 | | mat_vector[i][3] = m[ 3]*cmat[0] + m[ 4]*cmat[3] + m[ 5]*cmat[6]; |
| 1471 | | mat_vector[i][4] = m[ 3]*cmat[1] + m[ 4]*cmat[4] + m[ 5]*cmat[7]; |
| 1472 | | mat_vector[i][5] = m[ 3]*cmat[2] + m[ 4]*cmat[5] + m[ 5]*cmat[8]; |
| 1473 | | mat_vector[i][6] = m[ 6]*cmat[0] + m[ 7]*cmat[3] + m[ 8]*cmat[6]; |
| 1474 | | mat_vector[i][7] = m[ 6]*cmat[1] + m[ 7]*cmat[4] + m[ 8]*cmat[7]; |
| 1475 | | mat_vector[i][8] = m[ 6]*cmat[2] + m[ 7]*cmat[5] + m[ 8]*cmat[8]; |
| 1476 | | mat_vector[i][9] = m[ 9]*cmat[0] + m[10]*cmat[3] + m[11]*cmat[6] + cmat[9]; |
| 1477 | | mat_vector[i][10] = m[ 9]*cmat[1] + m[10]*cmat[4] + m[11]*cmat[7] + cmat[10]; |
| 1478 | | mat_vector[i][11] = m[ 9]*cmat[2] + m[10]*cmat[5] + m[11]*cmat[8] + cmat[11]; |
| 1522 | state->mat_vector[i][0] = m[ 0]*state->cmat[0] + m[ 1]*state->cmat[3] + m[ 2]*state->cmat[6]; |
| 1523 | state->mat_vector[i][1] = m[ 0]*state->cmat[1] + m[ 1]*state->cmat[4] + m[ 2]*state->cmat[7]; |
| 1524 | state->mat_vector[i][2] = m[ 0]*state->cmat[2] + m[ 1]*state->cmat[5] + m[ 2]*state->cmat[8]; |
| 1525 | state->mat_vector[i][3] = m[ 3]*state->cmat[0] + m[ 4]*state->cmat[3] + m[ 5]*state->cmat[6]; |
| 1526 | state->mat_vector[i][4] = m[ 3]*state->cmat[1] + m[ 4]*state->cmat[4] + m[ 5]*state->cmat[7]; |
| 1527 | state->mat_vector[i][5] = m[ 3]*state->cmat[2] + m[ 4]*state->cmat[5] + m[ 5]*state->cmat[8]; |
| 1528 | state->mat_vector[i][6] = m[ 6]*state->cmat[0] + m[ 7]*state->cmat[3] + m[ 8]*state->cmat[6]; |
| 1529 | state->mat_vector[i][7] = m[ 6]*state->cmat[1] + m[ 7]*state->cmat[4] + m[ 8]*state->cmat[7]; |
| 1530 | state->mat_vector[i][8] = m[ 6]*state->cmat[2] + m[ 7]*state->cmat[5] + m[ 8]*state->cmat[8]; |
| 1531 | state->mat_vector[i][9] = m[ 9]*state->cmat[0] + m[10]*state->cmat[3] + m[11]*state->cmat[6] + state->cmat[9]; |
| 1532 | state->mat_vector[i][10] = m[ 9]*state->cmat[1] + m[10]*state->cmat[4] + m[11]*state->cmat[7] + state->cmat[10]; |
| 1533 | state->mat_vector[i][11] = m[ 9]*state->cmat[2] + m[10]*state->cmat[5] + m[11]*state->cmat[8] + state->cmat[11]; |
| 1479 | 1534 | } |
| 1480 | | next_fn(); |
| 1535 | next_fn(state); |
| 1481 | 1536 | } |
| 1482 | 1537 | |
| 1483 | 1538 | static TGP_FUNCTION( vmat_load1 ) |
| 1484 | 1539 | { |
| 1485 | | UINT32 a = fifoin_pop(); |
| 1486 | | logerror("TGP vmat_load1 0x%x (%x)\n", a, pushpc); |
| 1487 | | memcpy(cmat, ram_data+a, sizeof(cmat)); |
| 1488 | | next_fn(); |
| 1540 | model1_state *state = machine->driver_data<model1_state>(); |
| 1541 | UINT32 a = fifoin_pop(state); |
| 1542 | logerror("TGP vmat_load1 0x%x (%x)\n", a, state->pushpc); |
| 1543 | memcpy(state->cmat, state->ram_data+a, sizeof(state->cmat)); |
| 1544 | next_fn(state); |
| 1489 | 1545 | } |
| 1490 | 1546 | |
| 1491 | 1547 | static TGP_FUNCTION( ram_trans ) |
| 1492 | 1548 | { |
| 1493 | | float a = ram_get_f(); |
| 1494 | | float b = ram_get_f(); |
| 1495 | | float c = ram_get_f(); |
| 1496 | | logerror("TGP ram_trans (%x)\n", pushpc); |
| 1497 | | cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; |
| 1498 | | cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; |
| 1499 | | cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; |
| 1500 | | next_fn(); |
| 1549 | model1_state *state = machine->driver_data<model1_state>(); |
| 1550 | float a = ram_get_f(state); |
| 1551 | float b = ram_get_f(state); |
| 1552 | float c = ram_get_f(state); |
| 1553 | logerror("TGP ram_trans (%x)\n", state->pushpc); |
| 1554 | state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; |
| 1555 | state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; |
| 1556 | state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; |
| 1557 | next_fn(state); |
| 1501 | 1558 | } |
| 1502 | 1559 | |
| 1503 | 1560 | static TGP_FUNCTION( f98_load ) |
| 1504 | 1561 | { |
| 1562 | model1_state *state = machine->driver_data<model1_state>(); |
| 1505 | 1563 | int i; |
| 1506 | | for(i=0; i<list_length; i++) { |
| 1507 | | float f = fifoin_pop_f(); |
| 1564 | for(i=0; i<state->list_length; i++) { |
| 1565 | float f = fifoin_pop_f(state); |
| 1508 | 1566 | (void)f; |
| 1509 | | logerror("TGP load list (%2d/%2d) %f (%x)\n", i, list_length, f, pushpc); |
| 1567 | logerror("TGP load list (%2d/%2d) %f (%x)\n", i, state->list_length, f, state->pushpc); |
| 1510 | 1568 | } |
| 1511 | | next_fn(); |
| 1569 | next_fn(state); |
| 1512 | 1570 | } |
| 1513 | 1571 | |
| 1514 | 1572 | static TGP_FUNCTION( f98 ) |
| 1515 | 1573 | { |
| 1516 | | UINT32 a = fifoin_pop(); |
| 1574 | model1_state *state = machine->driver_data<model1_state>(); |
| 1575 | UINT32 a = fifoin_pop(state); |
| 1517 | 1576 | (void)a; |
| 1518 | | logerror("TGP load list start %d (%x)\n", a, pushpc); |
| 1519 | | fifoin_cbcount = list_length; |
| 1520 | | fifoin_cb = f98_load; |
| 1577 | logerror("TGP load list start %d (%x)\n", a, state->pushpc); |
| 1578 | state->fifoin_cbcount = state->list_length; |
| 1579 | state->fifoin_cb = f98_load; |
| 1521 | 1580 | } |
| 1522 | 1581 | |
| 1523 | 1582 | static TGP_FUNCTION( f99 ) |
| 1524 | 1583 | { |
| 1525 | | logerror("TGP f99 (%x)\n", pushpc); |
| 1526 | | next_fn(); |
| 1584 | model1_state *state = machine->driver_data<model1_state>(); |
| 1585 | logerror("TGP f99 (%x)\n", state->pushpc); |
| 1586 | next_fn(state); |
| 1527 | 1587 | } |
| 1528 | 1588 | |
| 1529 | 1589 | static TGP_FUNCTION( f100 ) |
| 1530 | 1590 | { |
| 1591 | model1_state *state = machine->driver_data<model1_state>(); |
| 1531 | 1592 | int i; |
| 1532 | | logerror("TGP f100 get list (%x)\n", pushpc); |
| 1533 | | for(i=0; i<list_length; i++) |
| 1534 | | fifoout_push_f((machine->rand() % 1000)/100.0); |
| 1535 | | next_fn(); |
| 1593 | logerror("TGP f100 get list (%x)\n", state->pushpc); |
| 1594 | for(i=0; i<state->list_length; i++) |
| 1595 | fifoout_push_f(state, (machine->rand() % 1000)/100.0); |
| 1596 | next_fn(state); |
| 1536 | 1597 | } |
| 1537 | 1598 | |
| 1538 | 1599 | static TGP_FUNCTION( groundbox_set ) |
| 1539 | 1600 | { |
| 1540 | | float a = fifoin_pop_f(); |
| 1541 | | float b = fifoin_pop_f(); |
| 1542 | | float c = fifoin_pop_f(); |
| 1543 | | float d = fifoin_pop_f(); |
| 1544 | | float e = fifoin_pop_f(); |
| 1545 | | float f = fifoin_pop_f(); |
| 1546 | | float g = fifoin_pop_f(); |
| 1547 | | logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, pushpc); |
| 1548 | | tgp_vf_xmin = e; |
| 1549 | | tgp_vf_xmax = d; |
| 1550 | | tgp_vf_zmin = g; |
| 1551 | | tgp_vf_zmax = f; |
| 1552 | | tgp_vf_ygnd = b; |
| 1553 | | tgp_vf_yflr = a; |
| 1554 | | tgp_vf_yjmp = c; |
| 1601 | model1_state *state = machine->driver_data<model1_state>(); |
| 1602 | float a = fifoin_pop_f(state); |
| 1603 | float b = fifoin_pop_f(state); |
| 1604 | float c = fifoin_pop_f(state); |
| 1605 | float d = fifoin_pop_f(state); |
| 1606 | float e = fifoin_pop_f(state); |
| 1607 | float f = fifoin_pop_f(state); |
| 1608 | float g = fifoin_pop_f(state); |
| 1609 | logerror("TGP groundbox_set %f, %f, %f, %f, %f, %f, %f (%x)\n", a, b, c, d, e, f, g, state->pushpc); |
| 1610 | state->tgp_vf_xmin = e; |
| 1611 | state->tgp_vf_xmax = d; |
| 1612 | state->tgp_vf_zmin = g; |
| 1613 | state->tgp_vf_zmax = f; |
| 1614 | state->tgp_vf_ygnd = b; |
| 1615 | state->tgp_vf_yflr = a; |
| 1616 | state->tgp_vf_yjmp = c; |
| 1555 | 1617 | |
| 1556 | | next_fn(); |
| 1618 | next_fn(state); |
| 1557 | 1619 | } |
| 1558 | 1620 | |
| 1559 | 1621 | static TGP_FUNCTION( f102 ) |
| 1560 | 1622 | { |
| 1561 | | static int ccount = 0; |
| 1623 | model1_state *state = machine->driver_data<model1_state>(); |
| 1562 | 1624 | float px, py, pz; |
| 1563 | | float a = fifoin_pop_f(); |
| 1564 | | float b = fifoin_pop_f(); |
| 1565 | | float c = fifoin_pop_f(); |
| 1566 | | float d = fifoin_pop_f(); |
| 1567 | | float e = fifoin_pop_f(); |
| 1568 | | UINT32 f = fifoin_pop(); |
| 1569 | | UINT32 g = fifoin_pop(); |
| 1570 | | UINT32 h = fifoin_pop(); |
| 1625 | float a = fifoin_pop_f(state); |
| 1626 | float b = fifoin_pop_f(state); |
| 1627 | float c = fifoin_pop_f(state); |
| 1628 | float d = fifoin_pop_f(state); |
| 1629 | float e = fifoin_pop_f(state); |
| 1630 | UINT32 f = fifoin_pop(state); |
| 1631 | UINT32 g = fifoin_pop(state); |
| 1632 | UINT32 h = fifoin_pop(state); |
| 1571 | 1633 | |
| 1572 | | ccount++; |
| 1634 | state->ccount++; |
| 1573 | 1635 | |
| 1574 | | logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, ccount, pushpc); |
| 1636 | logerror("TGP f0 mve_calc %f, %f, %f, %f, %f, %d, %d, %d (%d) (%x)\n", a, b, c, d, e, f, g, h, state->ccount, state->pushpc); |
| 1575 | 1637 | |
| 1576 | | px = u2f(ram_data[ram_scanadr+0x16]); |
| 1577 | | py = u2f(ram_data[ram_scanadr+0x17]); |
| 1578 | | pz = u2f(ram_data[ram_scanadr+0x18]); |
| 1638 | px = u2f(state->ram_data[state->ram_scanadr+0x16]); |
| 1639 | py = u2f(state->ram_data[state->ram_scanadr+0x17]); |
| 1640 | pz = u2f(state->ram_data[state->ram_scanadr+0x18]); |
| 1579 | 1641 | |
| 1580 | | // memset(cmat, 0, sizeof(cmat)); |
| 1581 | | // cmat[0] = 1.0; |
| 1582 | | // cmat[4] = 1.0; |
| 1583 | | // cmat[8] = 1.0; |
| 1642 | // memset(state->cmat, 0, sizeof(state->cmat)); |
| 1643 | // state->cmat[0] = 1.0; |
| 1644 | // state->cmat[4] = 1.0; |
| 1645 | // state->cmat[8] = 1.0; |
| 1584 | 1646 | |
| 1585 | 1647 | px = c; |
| 1586 | 1648 | py = d; |
| 1587 | 1649 | pz = e; |
| 1588 | 1650 | |
| 1589 | 1651 | #if 1 |
| 1590 | | cmat[ 9] += cmat[0]*a+cmat[3]*b+cmat[6]*c; |
| 1591 | | cmat[10] += cmat[1]*a+cmat[4]*b+cmat[7]*c; |
| 1592 | | cmat[11] += cmat[2]*a+cmat[5]*b+cmat[8]*c; |
| 1652 | state->cmat[ 9] += state->cmat[0]*a+state->cmat[3]*b+state->cmat[6]*c; |
| 1653 | state->cmat[10] += state->cmat[1]*a+state->cmat[4]*b+state->cmat[7]*c; |
| 1654 | state->cmat[11] += state->cmat[2]*a+state->cmat[5]*b+state->cmat[8]*c; |
| 1593 | 1655 | #else |
| 1594 | | cmat[ 9] += px; |
| 1595 | | cmat[10] += py; |
| 1596 | | cmat[11] += pz; |
| 1656 | state->cmat[ 9] += px; |
| 1657 | state->cmat[10] += py; |
| 1658 | state->cmat[11] += pz; |
| 1597 | 1659 | #endif |
| 1598 | 1660 | |
| 1599 | 1661 | logerror(" f0 mve_calc %f, %f, %f\n", px, py, pz); |
| 1600 | 1662 | |
| 1601 | | fifoout_push_f(c); |
| 1602 | | fifoout_push_f(d); |
| 1603 | | fifoout_push_f(e); |
| 1604 | | fifoout_push(f); |
| 1605 | | fifoout_push(g); |
| 1606 | | fifoout_push(h); |
| 1663 | fifoout_push_f(state, c); |
| 1664 | fifoout_push_f(state, d); |
| 1665 | fifoout_push_f(state, e); |
| 1666 | fifoout_push(state, f); |
| 1667 | fifoout_push(state, g); |
| 1668 | fifoout_push(state, h); |
| 1607 | 1669 | |
| 1608 | 1670 | |
| 1609 | | next_fn(); |
| 1671 | next_fn(state); |
| 1610 | 1672 | } |
| 1611 | 1673 | |
| 1612 | 1674 | static TGP_FUNCTION( f103 ) |
| 1613 | 1675 | { |
| 1614 | | ram_scanadr = fifoin_pop() - 0x8000; |
| 1615 | | logerror("TGP f0 mve_setadr 0x%x (%x)\n", ram_scanadr, pushpc); |
| 1616 | | ram_get_i(); |
| 1617 | | next_fn(); |
| 1676 | model1_state *state = machine->driver_data<model1_state>(); |
| 1677 | state->ram_scanadr = fifoin_pop(state) - 0x8000; |
| 1678 | logerror("TGP f0 mve_setadr 0x%x (%x)\n", state->ram_scanadr, state->pushpc); |
| 1679 | ram_get_i(state); |
| 1680 | next_fn(state); |
| 1618 | 1681 | } |
| 1619 | 1682 | |
| 1620 | 1683 | struct function { |
| r10427 | r10428 | |
| 1818 | 1881 | |
| 1819 | 1882 | static TGP_FUNCTION( dump ) |
| 1820 | 1883 | { |
| 1821 | | logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(), pushpc); |
| 1822 | | fifoin_cbcount = 1; |
| 1823 | | fifoin_cb = dump; |
| 1884 | model1_state *state = machine->driver_data<model1_state>(); |
| 1885 | logerror("TGP FIFOIN write %08x (%x)\n", fifoin_pop(state), state->pushpc); |
| 1886 | state->fifoin_cbcount = 1; |
| 1887 | state->fifoin_cb = dump; |
| 1824 | 1888 | } |
| 1825 | 1889 | |
| 1826 | 1890 | static TGP_FUNCTION( function_get_vf ) |
| 1827 | 1891 | { |
| 1828 | | UINT32 f = fifoin_pop() >> 23; |
| 1892 | model1_state *state = machine->driver_data<model1_state>(); |
| 1893 | UINT32 f = fifoin_pop(state) >> 23; |
| 1829 | 1894 | |
| 1830 | | if(fifoout_rpos != fifoout_wpos) { |
| 1831 | | int count = fifoout_wpos - fifoout_rpos; |
| 1895 | if(state->fifoout_rpos != state->fifoout_wpos) { |
| 1896 | int count = state->fifoout_wpos - state->fifoout_rpos; |
| 1832 | 1897 | if(count < 0) |
| 1833 | 1898 | count += FIFO_SIZE; |
| 1834 | 1899 | logerror("TGP function called with sizeout = %d\n", count); |
| 1835 | 1900 | } |
| 1836 | 1901 | if(ARRAY_LENGTH(ftab_vf) > f && NULL != ftab_vf[f].cb) { |
| 1837 | | fifoin_cbcount = ftab_vf[f].count; |
| 1838 | | fifoin_cb = ftab_vf[f].cb; |
| 1839 | | // logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount); |
| 1840 | | if(!fifoin_cbcount) |
| 1841 | | fifoin_cb(machine); |
| 1902 | state->fifoin_cbcount = ftab_vf[f].count; |
| 1903 | state->fifoin_cb = ftab_vf[f].cb; |
| 1904 | // logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount); |
| 1905 | if(!state->fifoin_cbcount) |
| 1906 | state->fifoin_cb(machine); |
| 1842 | 1907 | } else { |
| 1843 | | logerror("TGP function %d unimplemented (%x)\n", f, pushpc); |
| 1844 | | fifoin_cbcount = 1; |
| 1845 | | fifoin_cb = dump; |
| 1908 | logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc); |
| 1909 | state->fifoin_cbcount = 1; |
| 1910 | state->fifoin_cb = dump; |
| 1846 | 1911 | } |
| 1847 | 1912 | } |
| 1848 | 1913 | |
| 1849 | 1914 | static TGP_FUNCTION( function_get_swa ) |
| 1850 | 1915 | { |
| 1851 | | UINT32 f = fifoin_pop(); |
| 1916 | model1_state *state = machine->driver_data<model1_state>(); |
| 1917 | UINT32 f = fifoin_pop(state); |
| 1852 | 1918 | |
| 1853 | | if(fifoout_rpos != fifoout_wpos) { |
| 1854 | | int count = fifoout_wpos - fifoout_rpos; |
| 1919 | if(state->fifoout_rpos != state->fifoout_wpos) { |
| 1920 | int count = state->fifoout_wpos - state->fifoout_rpos; |
| 1855 | 1921 | if(count < 0) |
| 1856 | 1922 | count += FIFO_SIZE; |
| 1857 | 1923 | logerror("TGP function called with sizeout = %d\n", count); |
| 1858 | 1924 | } |
| 1859 | 1925 | if(ARRAY_LENGTH(ftab_swa) > f && NULL != ftab_swa[f].cb) { |
| 1860 | | fifoin_cbcount = ftab_swa[f].count; |
| 1861 | | fifoin_cb = ftab_swa[f].cb; |
| 1862 | | // logerror("TGP function %d request, %d parameters\n", f, fifoin_cbcount); |
| 1863 | | if(!fifoin_cbcount) |
| 1864 | | fifoin_cb(machine); |
| 1926 | state->fifoin_cbcount = ftab_swa[f].count; |
| 1927 | state->fifoin_cb = ftab_swa[f].cb; |
| 1928 | // logerror("TGP function %d request, %d parameters\n", f, state->fifoin_cbcount); |
| 1929 | if(!state->fifoin_cbcount) |
| 1930 | state->fifoin_cb(machine); |
| 1865 | 1931 | } else { |
| 1866 | | logerror("TGP function %d unimplemented (%x)\n", f, pushpc); |
| 1867 | | fifoin_cbcount = 1; |
| 1868 | | fifoin_cb = dump; |
| 1932 | logerror("TGP function %d unimplemented (%x)\n", f, state->pushpc); |
| 1933 | state->fifoin_cbcount = 1; |
| 1934 | state->fifoin_cb = dump; |
| 1869 | 1935 | } |
| 1870 | 1936 | } |
| 1871 | 1937 | |
| 1872 | 1938 | READ16_HANDLER( model1_tgp_copro_r ) |
| 1873 | 1939 | { |
| 1874 | | static UINT32 cur; |
| 1940 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1875 | 1941 | if(!offset) { |
| 1876 | | cur = fifoout_pop(space); |
| 1877 | | return cur; |
| 1942 | state->copro_r = fifoout_pop(space); |
| 1943 | return state->copro_r; |
| 1878 | 1944 | } else |
| 1879 | | return cur >> 16; |
| 1945 | return state->copro_r >> 16; |
| 1880 | 1946 | } |
| 1881 | 1947 | |
| 1882 | 1948 | WRITE16_HANDLER( model1_tgp_copro_w ) |
| 1883 | 1949 | { |
| 1884 | | static UINT32 cur; |
| 1950 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1885 | 1951 | if(offset) { |
| 1886 | | cur = (cur & 0x0000ffff) | (data << 16); |
| 1887 | | pushpc = cpu_get_pc(space->cpu); |
| 1888 | | fifoin_push(space, cur); |
| 1952 | state->copro_w = (state->copro_w & 0x0000ffff) | (data << 16); |
| 1953 | state->pushpc = cpu_get_pc(space->cpu); |
| 1954 | fifoin_push(space, state->copro_w); |
| 1889 | 1955 | } else |
| 1890 | | cur = (cur & 0xffff0000) | data; |
| 1956 | state->copro_w = (state->copro_w & 0xffff0000) | data; |
| 1891 | 1957 | } |
| 1892 | 1958 | |
| 1893 | 1959 | READ16_HANDLER( model1_tgp_copro_adr_r ) |
| 1894 | 1960 | { |
| 1895 | | return ram_adr; |
| 1961 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1962 | return state->ram_adr; |
| 1896 | 1963 | } |
| 1897 | 1964 | |
| 1898 | 1965 | WRITE16_HANDLER( model1_tgp_copro_adr_w ) |
| 1899 | 1966 | { |
| 1900 | | COMBINE_DATA(&ram_adr); |
| 1967 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1968 | COMBINE_DATA(&state->ram_adr); |
| 1901 | 1969 | } |
| 1902 | 1970 | |
| 1903 | 1971 | READ16_HANDLER( model1_tgp_copro_ram_r ) |
| 1904 | 1972 | { |
| 1973 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1905 | 1974 | if(!offset) { |
| 1906 | | logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", ram_adr, ram_data[ram_adr], u2f(ram_data[ram_adr]), cpu_get_pc(space->cpu)); |
| 1907 | | return ram_data[ram_adr]; |
| 1975 | logerror("TGP f0 ram read %04x, %08x (%f) (%x)\n", state->ram_adr, state->ram_data[state->ram_adr], u2f(state->ram_data[state->ram_adr]), cpu_get_pc(space->cpu)); |
| 1976 | return state->ram_data[state->ram_adr]; |
| 1908 | 1977 | } else |
| 1909 | | return ram_data[ram_adr++] >> 16; |
| 1978 | return state->ram_data[state->ram_adr++] >> 16; |
| 1910 | 1979 | } |
| 1911 | 1980 | |
| 1912 | 1981 | WRITE16_HANDLER( model1_tgp_copro_ram_w ) |
| 1913 | 1982 | { |
| 1914 | | COMBINE_DATA(ram_latch+offset); |
| 1983 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1984 | COMBINE_DATA(state->ram_latch+offset); |
| 1915 | 1985 | if(offset) { |
| 1916 | | UINT32 v = ram_latch[0]|(ram_latch[1]<<16); |
| 1917 | | logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", ram_adr, v, u2f(v), cpu_get_pc(space->cpu)); |
| 1918 | | ram_data[ram_adr] = v; |
| 1919 | | ram_adr++; |
| 1986 | UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16); |
| 1987 | logerror("TGP f0 ram write %04x, %08x (%f) (%x)\n", state->ram_adr, v, u2f(v), cpu_get_pc(space->cpu)); |
| 1988 | state->ram_data[state->ram_adr] = v; |
| 1989 | state->ram_adr++; |
| 1920 | 1990 | } |
| 1921 | 1991 | } |
| 1922 | 1992 | |
| 1923 | 1993 | MACHINE_START( model1 ) |
| 1924 | 1994 | { |
| 1925 | | ram_data = auto_alloc_array(machine, UINT32, 0x10000); |
| 1995 | model1_state *state = machine->driver_data<model1_state>(); |
| 1996 | state->ram_data = auto_alloc_array(machine, UINT32, 0x10000); |
| 1926 | 1997 | |
| 1927 | | state_save_register_global_pointer(machine, ram_data, 0x10000); |
| 1928 | | state_save_register_global(machine, ram_adr); |
| 1929 | | state_save_register_global(machine, ram_scanadr); |
| 1930 | | state_save_register_global_array(machine, ram_latch); |
| 1931 | | state_save_register_global(machine, fifoout_rpos); |
| 1932 | | state_save_register_global(machine, fifoout_wpos); |
| 1933 | | state_save_register_global_array(machine, fifoout_data); |
| 1934 | | state_save_register_global(machine, fifoin_rpos); |
| 1935 | | state_save_register_global(machine, fifoin_wpos); |
| 1936 | | state_save_register_global_array(machine, fifoin_data); |
| 1937 | | state_save_register_global_array(machine, cmat); |
| 1938 | | state_save_register_global_2d_array(machine, mat_stack); |
| 1939 | | state_save_register_global_2d_array(machine, mat_vector); |
| 1940 | | state_save_register_global(machine, mat_stack_pos); |
| 1941 | | state_save_register_global(machine, acc); |
| 1942 | | state_save_register_global(machine, list_length); |
| 1998 | state_save_register_global_pointer(machine, state->ram_data, 0x10000); |
| 1999 | state_save_register_global(machine, state->ram_adr); |
| 2000 | state_save_register_global(machine, state->ram_scanadr); |
| 2001 | state_save_register_global_array(machine, state->ram_latch); |
| 2002 | state_save_register_global(machine, state->fifoout_rpos); |
| 2003 | state_save_register_global(machine, state->fifoout_wpos); |
| 2004 | state_save_register_global_array(machine, state->fifoout_data); |
| 2005 | state_save_register_global(machine, state->fifoin_rpos); |
| 2006 | state_save_register_global(machine, state->fifoin_wpos); |
| 2007 | state_save_register_global_array(machine, state->fifoin_data); |
| 2008 | state_save_register_global_array(machine, state->cmat); |
| 2009 | state_save_register_global_2d_array(machine, state->mat_stack); |
| 2010 | state_save_register_global_2d_array(machine, state->mat_vector); |
| 2011 | state_save_register_global(machine, state->mat_stack_pos); |
| 2012 | state_save_register_global(machine, state->acc); |
| 2013 | state_save_register_global(machine, state->list_length); |
| 1943 | 2014 | } |
| 1944 | 2015 | |
| 1945 | 2016 | void model1_tgp_reset(running_machine *machine, int swa) |
| 1946 | 2017 | { |
| 1947 | | ram_adr = 0; |
| 1948 | | memset(ram_data, 0, 0x10000*4); |
| 2018 | model1_state *state = machine->driver_data<model1_state>(); |
| 2019 | state->ram_adr = 0; |
| 2020 | memset(state->ram_data, 0, 0x10000*4); |
| 1949 | 2021 | |
| 1950 | | fifoout_rpos = 0; |
| 1951 | | fifoout_wpos = 0; |
| 1952 | | fifoin_rpos = 0; |
| 1953 | | fifoin_wpos = 0; |
| 2022 | state->fifoout_rpos = 0; |
| 2023 | state->fifoout_wpos = 0; |
| 2024 | state->fifoin_rpos = 0; |
| 2025 | state->fifoin_wpos = 0; |
| 1954 | 2026 | |
| 1955 | | acc = 0; |
| 1956 | | mat_stack_pos = 0; |
| 1957 | | memset(cmat, 0, sizeof(cmat)); |
| 1958 | | cmat[0] = 1.0; |
| 1959 | | cmat[4] = 1.0; |
| 1960 | | cmat[8] = 1.0; |
| 2027 | state->acc = 0; |
| 2028 | state->mat_stack_pos = 0; |
| 2029 | memset(state->cmat, 0, sizeof(state->cmat)); |
| 2030 | state->cmat[0] = 1.0; |
| 2031 | state->cmat[4] = 1.0; |
| 2032 | state->cmat[8] = 1.0; |
| 1961 | 2033 | |
| 1962 | | model1_dump = 0; |
| 1963 | | model1_swa = swa; |
| 1964 | | next_fn(); |
| 2034 | state->dump = 0; |
| 2035 | state->swa = swa; |
| 2036 | next_fn(state); |
| 1965 | 2037 | } |
| 1966 | 2038 | |
| 1967 | 2039 | /*********************************** Virtua Racing ***********************************/ |
| 1968 | 2040 | |
| 1969 | | static int copro_fifoout_rpos, copro_fifoout_wpos; |
| 1970 | | static UINT32 copro_fifoout_data[FIFO_SIZE]; |
| 1971 | | static int copro_fifoout_num; |
| 1972 | | static int copro_fifoin_rpos, copro_fifoin_wpos; |
| 1973 | | static UINT32 copro_fifoin_data[FIFO_SIZE]; |
| 1974 | | static int copro_fifoin_num; |
| 1975 | 2041 | |
| 1976 | 2042 | void model1_vr_tgp_reset( running_machine *machine ) |
| 1977 | 2043 | { |
| 1978 | | ram_adr = 0; |
| 1979 | | memset(ram_data, 0, 0x8000*4); |
| 2044 | model1_state *state = machine->driver_data<model1_state>(); |
| 2045 | state->ram_adr = 0; |
| 2046 | memset(state->ram_data, 0, 0x8000*4); |
| 1980 | 2047 | |
| 1981 | | copro_fifoout_rpos = 0; |
| 1982 | | copro_fifoout_wpos = 0; |
| 1983 | | copro_fifoout_num = 0; |
| 1984 | | copro_fifoin_rpos = 0; |
| 1985 | | copro_fifoin_wpos = 0; |
| 1986 | | copro_fifoin_num = 0; |
| 2048 | state->copro_fifoout_rpos = 0; |
| 2049 | state->copro_fifoout_wpos = 0; |
| 2050 | state->copro_fifoout_num = 0; |
| 2051 | state->copro_fifoin_rpos = 0; |
| 2052 | state->copro_fifoin_wpos = 0; |
| 2053 | state->copro_fifoin_num = 0; |
| 1987 | 2054 | } |
| 1988 | 2055 | |
| 1989 | 2056 | /* FIFO */ |
| 1990 | 2057 | static int copro_fifoin_pop(device_t *device, UINT32 *result) |
| 1991 | 2058 | { |
| 2059 | model1_state *state = device->machine->driver_data<model1_state>(); |
| 1992 | 2060 | UINT32 r; |
| 1993 | 2061 | |
| 1994 | | if (copro_fifoin_num == 0) |
| 2062 | if (state->copro_fifoin_num == 0) |
| 1995 | 2063 | { |
| 1996 | 2064 | return 0; |
| 1997 | 2065 | } |
| 1998 | 2066 | |
| 1999 | | r = copro_fifoin_data[copro_fifoin_rpos++]; |
| 2067 | r = state->copro_fifoin_data[state->copro_fifoin_rpos++]; |
| 2000 | 2068 | |
| 2001 | | if (copro_fifoin_rpos == FIFO_SIZE) |
| 2069 | if (state->copro_fifoin_rpos == FIFO_SIZE) |
| 2002 | 2070 | { |
| 2003 | | copro_fifoin_rpos = 0; |
| 2071 | state->copro_fifoin_rpos = 0; |
| 2004 | 2072 | } |
| 2005 | 2073 | |
| 2006 | | copro_fifoin_num--; |
| 2074 | state->copro_fifoin_num--; |
| 2007 | 2075 | |
| 2008 | 2076 | *result = r; |
| 2009 | 2077 | |
| r10427 | r10428 | |
| 2012 | 2080 | |
| 2013 | 2081 | static void copro_fifoin_push(address_space *space, UINT32 data) |
| 2014 | 2082 | { |
| 2015 | | if (copro_fifoin_num == FIFO_SIZE) |
| 2083 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2084 | if (state->copro_fifoin_num == FIFO_SIZE) |
| 2016 | 2085 | { |
| 2017 | 2086 | fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(space->cpu)); |
| 2018 | 2087 | return; |
| 2019 | 2088 | } |
| 2020 | 2089 | |
| 2021 | | copro_fifoin_data[copro_fifoin_wpos++] = data; |
| 2090 | state->copro_fifoin_data[state->copro_fifoin_wpos++] = data; |
| 2022 | 2091 | |
| 2023 | | if (copro_fifoin_wpos == FIFO_SIZE) |
| 2092 | if (state->copro_fifoin_wpos == FIFO_SIZE) |
| 2024 | 2093 | { |
| 2025 | | copro_fifoin_wpos = 0; |
| 2094 | state->copro_fifoin_wpos = 0; |
| 2026 | 2095 | } |
| 2027 | 2096 | |
| 2028 | | copro_fifoin_num++; |
| 2097 | state->copro_fifoin_num++; |
| 2029 | 2098 | } |
| 2030 | 2099 | |
| 2031 | 2100 | static UINT32 copro_fifoout_pop(address_space *space) |
| 2032 | 2101 | { |
| 2102 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2033 | 2103 | UINT32 r; |
| 2034 | 2104 | |
| 2035 | | if (copro_fifoout_num == 0) |
| 2105 | if (state->copro_fifoout_num == 0) |
| 2036 | 2106 | { |
| 2037 | 2107 | // Reading from empty FIFO causes the v60 to enter wait state |
| 2038 | 2108 | v60_stall(space->machine->device("maincpu")); |
| r10427 | r10428 | |
| 2042 | 2112 | return 0; |
| 2043 | 2113 | } |
| 2044 | 2114 | |
| 2045 | | r = copro_fifoout_data[copro_fifoout_rpos++]; |
| 2115 | r = state->copro_fifoout_data[state->copro_fifoout_rpos++]; |
| 2046 | 2116 | |
| 2047 | | if (copro_fifoout_rpos == FIFO_SIZE) |
| 2117 | if (state->copro_fifoout_rpos == FIFO_SIZE) |
| 2048 | 2118 | { |
| 2049 | | copro_fifoout_rpos = 0; |
| 2119 | state->copro_fifoout_rpos = 0; |
| 2050 | 2120 | } |
| 2051 | 2121 | |
| 2052 | | copro_fifoout_num--; |
| 2122 | state->copro_fifoout_num--; |
| 2053 | 2123 | |
| 2054 | 2124 | return r; |
| 2055 | 2125 | } |
| 2056 | 2126 | |
| 2057 | 2127 | static void copro_fifoout_push(device_t *device, UINT32 data) |
| 2058 | 2128 | { |
| 2059 | | if (copro_fifoout_num == FIFO_SIZE) |
| 2129 | model1_state *state = device->machine->driver_data<model1_state>(); |
| 2130 | if (state->copro_fifoout_num == FIFO_SIZE) |
| 2060 | 2131 | { |
| 2061 | 2132 | fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device)); |
| 2062 | 2133 | return; |
| 2063 | 2134 | } |
| 2064 | 2135 | |
| 2065 | | copro_fifoout_data[copro_fifoout_wpos++] = data; |
| 2136 | state->copro_fifoout_data[state->copro_fifoout_wpos++] = data; |
| 2066 | 2137 | |
| 2067 | | if (copro_fifoout_wpos == FIFO_SIZE) |
| 2138 | if (state->copro_fifoout_wpos == FIFO_SIZE) |
| 2068 | 2139 | { |
| 2069 | | copro_fifoout_wpos = 0; |
| 2140 | state->copro_fifoout_wpos = 0; |
| 2070 | 2141 | } |
| 2071 | 2142 | |
| 2072 | | copro_fifoout_num++; |
| 2143 | state->copro_fifoout_num++; |
| 2073 | 2144 | } |
| 2074 | 2145 | |
| 2075 | 2146 | static READ32_HANDLER(copro_ram_r) |
| 2076 | 2147 | { |
| 2077 | | return ram_data[offset & 0x7fff]; |
| 2148 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2149 | return state->ram_data[offset & 0x7fff]; |
| 2078 | 2150 | } |
| 2079 | 2151 | |
| 2080 | 2152 | static WRITE32_HANDLER(copro_ram_w) |
| 2081 | 2153 | { |
| 2082 | | ram_data[offset&0x7fff] = data; |
| 2154 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2155 | state->ram_data[offset&0x7fff] = data; |
| 2083 | 2156 | } |
| 2084 | 2157 | |
| 2085 | 2158 | READ16_HANDLER( model1_tgp_vr_adr_r ) |
| 2086 | 2159 | { |
| 2087 | | if ( ram_adr == 0 && copro_fifoin_num != 0 ) |
| 2160 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2161 | if ( state->ram_adr == 0 && state->copro_fifoin_num != 0 ) |
| 2088 | 2162 | { |
| 2089 | 2163 | /* spin the main cpu and let the TGP catch up */ |
| 2090 | 2164 | cpu_spinuntil_time(space->cpu, attotime::from_usec(100)); |
| 2091 | 2165 | } |
| 2092 | 2166 | |
| 2093 | | return ram_adr; |
| 2167 | return state->ram_adr; |
| 2094 | 2168 | } |
| 2095 | 2169 | |
| 2096 | 2170 | WRITE16_HANDLER( model1_tgp_vr_adr_w ) |
| 2097 | 2171 | { |
| 2098 | | COMBINE_DATA(&ram_adr); |
| 2172 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2173 | COMBINE_DATA(&state->ram_adr); |
| 2099 | 2174 | } |
| 2100 | 2175 | |
| 2101 | 2176 | READ16_HANDLER( model1_vr_tgp_ram_r ) |
| 2102 | 2177 | { |
| 2178 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2103 | 2179 | UINT16 r; |
| 2104 | 2180 | |
| 2105 | 2181 | if (!offset) |
| 2106 | 2182 | { |
| 2107 | | r = ram_data[ram_adr&0x7fff]; |
| 2183 | r = state->ram_data[state->ram_adr&0x7fff]; |
| 2108 | 2184 | } |
| 2109 | 2185 | else |
| 2110 | 2186 | { |
| 2111 | | r = ram_data[ram_adr&0x7fff] >> 16; |
| 2187 | r = state->ram_data[state->ram_adr&0x7fff] >> 16; |
| 2112 | 2188 | |
| 2113 | | if ( ram_adr == 0 && r == 0xffff ) |
| 2189 | if ( state->ram_adr == 0 && r == 0xffff ) |
| 2114 | 2190 | { |
| 2115 | 2191 | /* if the TGP is busy, spin some more */ |
| 2116 | 2192 | cpu_spinuntil_time(space->cpu, attotime::from_usec(100)); |
| 2117 | 2193 | } |
| 2118 | 2194 | |
| 2119 | | if ( ram_adr & 0x8000 ) |
| 2120 | | ram_adr++; |
| 2195 | if ( state->ram_adr & 0x8000 ) |
| 2196 | state->ram_adr++; |
| 2121 | 2197 | } |
| 2122 | 2198 | |
| 2123 | 2199 | return r; |
| r10427 | r10428 | |
| 2125 | 2201 | |
| 2126 | 2202 | WRITE16_HANDLER( model1_vr_tgp_ram_w ) |
| 2127 | 2203 | { |
| 2128 | | COMBINE_DATA(ram_latch+offset); |
| 2204 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2205 | COMBINE_DATA(state->ram_latch+offset); |
| 2129 | 2206 | |
| 2130 | 2207 | if (offset) |
| 2131 | 2208 | { |
| 2132 | | UINT32 v = ram_latch[0]|(ram_latch[1]<<16); |
| 2133 | | ram_data[ram_adr&0x7fff] = v; |
| 2134 | | if ( ram_adr & 0x8000 ) |
| 2135 | | ram_adr++; |
| 2209 | UINT32 v = state->ram_latch[0]|(state->ram_latch[1]<<16); |
| 2210 | state->ram_data[state->ram_adr&0x7fff] = v; |
| 2211 | if ( state->ram_adr & 0x8000 ) |
| 2212 | state->ram_adr++; |
| 2136 | 2213 | } |
| 2137 | 2214 | } |
| 2138 | 2215 | |
| 2139 | 2216 | READ16_HANDLER( model1_vr_tgp_r ) |
| 2140 | 2217 | { |
| 2141 | | static UINT32 cur; |
| 2142 | | |
| 2218 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2143 | 2219 | if (!offset) |
| 2144 | 2220 | { |
| 2145 | | cur = copro_fifoout_pop(space); |
| 2146 | | return cur; |
| 2221 | state->vr_r = copro_fifoout_pop(space); |
| 2222 | return state->vr_r; |
| 2147 | 2223 | } |
| 2148 | 2224 | else |
| 2149 | | return cur >> 16; |
| 2225 | return state->vr_r >> 16; |
| 2150 | 2226 | } |
| 2151 | 2227 | |
| 2152 | 2228 | WRITE16_HANDLER( model1_vr_tgp_w ) |
| 2153 | 2229 | { |
| 2154 | | static UINT32 cur; |
| 2155 | | |
| 2230 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 2156 | 2231 | if (offset) |
| 2157 | 2232 | { |
| 2158 | | cur = (cur & 0x0000ffff) | (data << 16); |
| 2159 | | copro_fifoin_push(space, cur); |
| 2233 | state->vr_w = (state->vr_w & 0x0000ffff) | (data << 16); |
| 2234 | copro_fifoin_push(space, state->vr_w); |
| 2160 | 2235 | } |
| 2161 | 2236 | else |
| 2162 | | cur = (cur & 0xffff0000) | data; |
| 2237 | state->vr_w = (state->vr_w & 0xffff0000) | data; |
| 2163 | 2238 | } |
| 2164 | 2239 | |
| 2165 | 2240 | /* TGP config */ |
src/mame/video/deco32.c
| r10427 | r10428 | |
| 1 | 1 | #include "emu.h" |
| 2 | 2 | #include "includes/deco32.h" |
| 3 | 3 | |
| 4 | | UINT32 *deco32_pf1_data,*deco32_pf2_data,*deco32_pf3_data,*deco32_pf4_data; |
| 5 | | UINT32 *deco32_pf12_control,*deco32_pf34_control; |
| 6 | | UINT32 *deco32_pf1_rowscroll,*deco32_pf2_rowscroll,*deco32_pf3_rowscroll,*deco32_pf4_rowscroll; |
| 7 | | UINT32 *dragngun_sprite_layout_0_ram, *dragngun_sprite_layout_1_ram; |
| 8 | | UINT32 *dragngun_sprite_lookup_0_ram, *dragngun_sprite_lookup_1_ram; |
| 9 | | UINT32 *deco32_ace_ram; |
| 10 | 4 | |
| 11 | | static UINT8 *dirty_palette; |
| 12 | | static tilemap_t *pf1_tilemap,*pf1a_tilemap,*pf2_tilemap,*pf3_tilemap,*pf4_tilemap; |
| 13 | | static int deco32_pf1_bank,deco32_pf2_bank,deco32_pf3_bank,deco32_pf4_bank; |
| 14 | | static int deco32_pf1_flip,deco32_pf2_flip,deco32_pf3_flip,deco32_pf4_flip; |
| 15 | | static int deco32_pf2_colourbank,deco32_pf4_colourbank,deco32_pri; |
| 16 | | |
| 17 | | static bitmap_t *sprite0_mix_bitmap, *sprite1_mix_bitmap, *tilemap_alpha_bitmap; |
| 18 | | |
| 19 | | static UINT32 dragngun_sprite_ctrl; |
| 20 | | static int deco32_ace_ram_dirty, has_ace_ram; |
| 21 | | |
| 22 | | int deco32_raster_display_position; |
| 23 | | UINT16 *deco32_raster_display_list; |
| 24 | | |
| 25 | 5 | /****************************************************************************** |
| 26 | 6 | |
| 27 | 7 | This sprite_priority_bitmap handling is the same as in deco16ic.c |
| 28 | 8 | |
| 29 | 9 | ******************************************************************************/ |
| 30 | 10 | |
| 31 | | static bitmap_t *sprite_priority_bitmap; |
| 32 | 11 | |
| 33 | | static void deco16_clear_sprite_priority_bitmap(void) |
| 12 | static void deco16_clear_sprite_priority_bitmap(deco32_state *state) |
| 34 | 13 | { |
| 35 | | if (sprite_priority_bitmap) |
| 36 | | bitmap_fill(sprite_priority_bitmap,NULL,0); |
| 14 | if (state->sprite_priority_bitmap) |
| 15 | bitmap_fill(state->sprite_priority_bitmap,NULL,0); |
| 37 | 16 | } |
| 38 | 17 | |
| 39 | 18 | /* A special pdrawgfx z-buffered sprite renderer that is needed to properly draw multiple sprite sources with alpha */ |
| r10427 | r10428 | |
| 42 | 21 | UINT32 code,UINT32 color,int flipx,int flipy,int sx,int sy, |
| 43 | 22 | int transparent_color,UINT32 pri_mask,UINT32 sprite_mask,UINT8 write_pri,UINT8 alpha) |
| 44 | 23 | { |
| 24 | deco32_state *state = gfx->machine->driver_data<deco32_state>(); |
| 45 | 25 | int ox,oy,cx,cy; |
| 46 | 26 | int x_index,y_index,x,y; |
| 47 | 27 | bitmap_t *priority_bitmap = gfx->machine->priority_bitmap; |
| r10427 | r10428 | |
| 69 | 49 | const UINT8 *source = code_base + (y_index * gfx->line_modulo); |
| 70 | 50 | UINT32 *destb = BITMAP_ADDR32(dest, sy, 0); |
| 71 | 51 | UINT8 *pri = BITMAP_ADDR8(priority_bitmap, sy, 0); |
| 72 | | UINT8 *spri = BITMAP_ADDR8(sprite_priority_bitmap, sy, 0); |
| 52 | UINT8 *spri = BITMAP_ADDR8(state->sprite_priority_bitmap, sy, 0); |
| 73 | 53 | |
| 74 | 54 | if (sy >= 0 && sy < 248) |
| 75 | 55 | { |
| r10427 | r10428 | |
| 105 | 85 | |
| 106 | 86 | WRITE32_HANDLER( deco32_pf1_data_w ) |
| 107 | 87 | { |
| 108 | | COMBINE_DATA(&deco32_pf1_data[offset]); |
| 109 | | tilemap_mark_tile_dirty(pf1_tilemap,offset); |
| 110 | | if (pf1a_tilemap && offset<0x400) |
| 111 | | tilemap_mark_tile_dirty(pf1a_tilemap,offset); |
| 88 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 89 | COMBINE_DATA(&state->pf1_data[offset]); |
| 90 | tilemap_mark_tile_dirty(state->pf1_tilemap,offset); |
| 91 | if (state->pf1a_tilemap && offset<0x400) |
| 92 | tilemap_mark_tile_dirty(state->pf1a_tilemap,offset); |
| 112 | 93 | } |
| 113 | 94 | |
| 114 | 95 | WRITE32_HANDLER( deco32_pf2_data_w ) |
| 115 | 96 | { |
| 116 | | COMBINE_DATA(&deco32_pf2_data[offset]); |
| 117 | | tilemap_mark_tile_dirty(pf2_tilemap,offset); |
| 97 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 98 | COMBINE_DATA(&state->pf2_data[offset]); |
| 99 | tilemap_mark_tile_dirty(state->pf2_tilemap,offset); |
| 118 | 100 | } |
| 119 | 101 | |
| 120 | 102 | WRITE32_HANDLER( deco32_pf3_data_w ) |
| 121 | 103 | { |
| 122 | | COMBINE_DATA(&deco32_pf3_data[offset]); |
| 123 | | tilemap_mark_tile_dirty(pf3_tilemap,offset); |
| 104 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 105 | COMBINE_DATA(&state->pf3_data[offset]); |
| 106 | tilemap_mark_tile_dirty(state->pf3_tilemap,offset); |
| 124 | 107 | } |
| 125 | 108 | |
| 126 | 109 | WRITE32_HANDLER( deco32_pf4_data_w ) |
| 127 | 110 | { |
| 128 | | COMBINE_DATA(&deco32_pf4_data[offset]); |
| 129 | | tilemap_mark_tile_dirty(pf4_tilemap,offset); |
| 111 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 112 | COMBINE_DATA(&state->pf4_data[offset]); |
| 113 | tilemap_mark_tile_dirty(state->pf4_tilemap,offset); |
| 130 | 114 | } |
| 131 | 115 | |
| 132 | 116 | /******************************************************************************/ |
| 133 | 117 | |
| 134 | 118 | WRITE32_HANDLER( deco32_pri_w ) |
| 135 | 119 | { |
| 136 | | deco32_pri=data; |
| 120 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 121 | state->pri=data; |
| 137 | 122 | } |
| 138 | 123 | |
| 139 | 124 | WRITE32_HANDLER( dragngun_sprite_control_w ) |
| 140 | 125 | { |
| 141 | | dragngun_sprite_ctrl=data; |
| 126 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 127 | state->dragngun_sprite_ctrl=data; |
| 142 | 128 | } |
| 143 | 129 | |
| 144 | 130 | WRITE32_HANDLER( dragngun_spriteram_dma_w ) |
| r10427 | r10428 | |
| 150 | 136 | |
| 151 | 137 | WRITE32_HANDLER( deco32_ace_ram_w ) |
| 152 | 138 | { |
| 139 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 153 | 140 | /* Some notes pieced together from Tattoo Assassins info: |
| 154 | 141 | |
| 155 | 142 | Bytes 0 to 0x58 - object alpha control? |
| r10427 | r10428 | |
| 181 | 168 | |
| 182 | 169 | 'fadetype' - 1100 for multiplicative fade, 1000 for additive |
| 183 | 170 | */ |
| 184 | | if (offset>=(0x80/4) && (data!=deco32_ace_ram[offset])) |
| 185 | | deco32_ace_ram_dirty=1; |
| 171 | if (offset>=(0x80/4) && (data!=state->ace_ram[offset])) |
| 172 | state->ace_ram_dirty=1; |
| 186 | 173 | |
| 187 | | COMBINE_DATA(&deco32_ace_ram[offset]); |
| 174 | COMBINE_DATA(&state->ace_ram[offset]); |
| 188 | 175 | } |
| 189 | 176 | |
| 190 | 177 | static void updateAceRam(running_machine* machine) |
| 191 | 178 | { |
| 179 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 192 | 180 | int r,g,b,i; |
| 193 | | UINT8 fadeptr=deco32_ace_ram[0x20]; |
| 194 | | UINT8 fadeptg=deco32_ace_ram[0x21]; |
| 195 | | UINT8 fadeptb=deco32_ace_ram[0x22]; |
| 196 | | UINT8 fadepsr=deco32_ace_ram[0x23]; |
| 197 | | UINT8 fadepsg=deco32_ace_ram[0x24]; |
| 198 | | UINT8 fadepsb=deco32_ace_ram[0x25]; |
| 199 | | // UINT8 mode=deco32_ace_ram[0x26]; |
| 181 | UINT8 fadeptr=state->ace_ram[0x20]; |
| 182 | UINT8 fadeptg=state->ace_ram[0x21]; |
| 183 | UINT8 fadeptb=state->ace_ram[0x22]; |
| 184 | UINT8 fadepsr=state->ace_ram[0x23]; |
| 185 | UINT8 fadepsg=state->ace_ram[0x24]; |
| 186 | UINT8 fadepsb=state->ace_ram[0x25]; |
| 187 | // UINT8 mode=state->ace_ram[0x26]; |
| 200 | 188 | |
| 201 | | deco32_ace_ram_dirty=0; |
| 189 | state->ace_ram_dirty=0; |
| 202 | 190 | |
| 203 | 191 | for (i=0; i<2048; i++) |
| 204 | 192 | { |
| r10427 | r10428 | |
| 239 | 227 | |
| 240 | 228 | WRITE32_HANDLER( deco32_buffered_palette_w ) |
| 241 | 229 | { |
| 230 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 242 | 231 | COMBINE_DATA(&space->machine->generic.paletteram.u32[offset]); |
| 243 | | dirty_palette[offset]=1; |
| 232 | state->dirty_palette[offset]=1; |
| 244 | 233 | } |
| 245 | 234 | |
| 246 | 235 | WRITE32_HANDLER( deco32_palette_dma_w ) |
| 247 | 236 | { |
| 237 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 248 | 238 | const int m=space->machine->total_colors(); |
| 249 | 239 | int r,g,b,i; |
| 250 | 240 | |
| 251 | 241 | for (i=0; i<m; i++) { |
| 252 | | if (dirty_palette[i]) { |
| 253 | | dirty_palette[i]=0; |
| 242 | if (state->dirty_palette[i]) { |
| 243 | state->dirty_palette[i]=0; |
| 254 | 244 | |
| 255 | | if (has_ace_ram) |
| 245 | if (state->has_ace_ram) |
| 256 | 246 | { |
| 257 | | deco32_ace_ram_dirty=1; |
| 247 | state->ace_ram_dirty=1; |
| 258 | 248 | } |
| 259 | 249 | else |
| 260 | 250 | { |
| r10427 | r10428 | |
| 753 | 743 | |
| 754 | 744 | static void dragngun_draw_sprites(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect, const UINT32 *spritedata) |
| 755 | 745 | { |
| 746 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 756 | 747 | const UINT32 *layout_ram; |
| 757 | 748 | const UINT32 *lookup_ram; |
| 758 | 749 | int offs; |
| r10427 | r10428 | |
| 803 | 794 | */ |
| 804 | 795 | |
| 805 | 796 | /* Sprite global disable bit */ |
| 806 | | if (dragngun_sprite_ctrl&0x40000000) |
| 797 | if (state->dragngun_sprite_ctrl&0x40000000) |
| 807 | 798 | return; |
| 808 | 799 | |
| 809 | 800 | for (offs = 0;offs < 0x800;offs += 8) |
| r10427 | r10428 | |
| 818 | 809 | continue; |
| 819 | 810 | |
| 820 | 811 | if (spritedata[offs+0]&0x400) |
| 821 | | layout_ram = dragngun_sprite_layout_1_ram + ((spritedata[offs+0]&0x1ff)*4); //CHECK! |
| 812 | layout_ram = state->dragngun_sprite_layout_1_ram + ((spritedata[offs+0]&0x1ff)*4); //CHECK! |
| 822 | 813 | else |
| 823 | | layout_ram = dragngun_sprite_layout_0_ram + ((spritedata[offs+0]&0x1ff)*4); //1ff in drag gun code?? |
| 814 | layout_ram = state->dragngun_sprite_layout_0_ram + ((spritedata[offs+0]&0x1ff)*4); //1ff in drag gun code?? |
| 824 | 815 | h = (layout_ram[1]>>0)&0xf; |
| 825 | 816 | w = (layout_ram[1]>>4)&0xf; |
| 826 | 817 | if (!h || !w) |
| r10427 | r10428 | |
| 847 | 838 | |
| 848 | 839 | // if (spritedata[offs+0]&0x400) |
| 849 | 840 | if (layout_ram[0]&0x2000) |
| 850 | | lookup_ram = dragngun_sprite_lookup_1_ram + (layout_ram[0]&0x1fff); |
| 841 | lookup_ram = state->dragngun_sprite_lookup_1_ram + (layout_ram[0]&0x1fff); |
| 851 | 842 | else |
| 852 | | lookup_ram = dragngun_sprite_lookup_0_ram + (layout_ram[0]&0x1fff); |
| 843 | lookup_ram = state->dragngun_sprite_lookup_0_ram + (layout_ram[0]&0x1fff); |
| 853 | 844 | |
| 854 | 845 | zoomx=scalex * 0x10000 / (w*16); |
| 855 | 846 | zoomy=scaley * 0x10000 / (h*16); |
| r10427 | r10428 | |
| 873 | 864 | /* High bits of the sprite reference into the sprite control bits for banking */ |
| 874 | 865 | switch (sprite&0x3000) { |
| 875 | 866 | default: |
| 876 | | case 0x0000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x000f)<<12); break; |
| 877 | | case 0x1000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x00f0)<< 8); break; |
| 878 | | case 0x2000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0x0f00)<< 4); break; |
| 879 | | case 0x3000: sprite=(sprite&0xfff) | ((dragngun_sprite_ctrl&0xf000)<< 0); break; |
| 867 | case 0x0000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x000f)<<12); break; |
| 868 | case 0x1000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x00f0)<< 8); break; |
| 869 | case 0x2000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0x0f00)<< 4); break; |
| 870 | case 0x3000: sprite=(sprite&0xfff) | ((state->dragngun_sprite_ctrl&0xf000)<< 0); break; |
| 880 | 871 | } |
| 881 | 872 | |
| 882 | 873 | /* Because of the unusual interleaved rom layout, we have to mangle the bank bits |
| r10427 | r10428 | |
| 936 | 927 | |
| 937 | 928 | static TILE_GET_INFO( get_pf1_tile_info ) |
| 938 | 929 | { |
| 939 | | int tile=deco32_pf1_data[tile_index]; |
| 940 | | SET_TILE_INFO(0,(tile&0xfff)|deco32_pf1_bank,(tile>>12)&0xf,0); |
| 930 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 931 | int tile=state->pf1_data[tile_index]; |
| 932 | SET_TILE_INFO(0,(tile&0xfff)|state->pf1_bank,(tile>>12)&0xf,0); |
| 941 | 933 | } |
| 942 | 934 | |
| 943 | 935 | static TILE_GET_INFO( get_pf1a_tile_info ) |
| 944 | 936 | { |
| 937 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 945 | 938 | |
| 946 | | int tile=deco32_pf1_data[tile_index]; |
| 947 | | SET_TILE_INFO(1,(tile&0xfff)|deco32_pf1_bank,(tile>>12)&0xf,0); |
| 939 | int tile=state->pf1_data[tile_index]; |
| 940 | SET_TILE_INFO(1,(tile&0xfff)|state->pf1_bank,(tile>>12)&0xf,0); |
| 948 | 941 | } |
| 949 | 942 | |
| 950 | 943 | static TILE_GET_INFO( get_pf2_tile_info ) |
| 951 | 944 | { |
| 952 | | UINT32 tile=deco32_pf2_data[tile_index]; |
| 945 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 946 | UINT32 tile=state->pf2_data[tile_index]; |
| 953 | 947 | UINT8 colour=(tile>>12)&0xf; |
| 954 | 948 | UINT8 flags=0; |
| 955 | 949 | |
| 956 | 950 | if (tile&0x8000) { |
| 957 | | if ((deco32_pf12_control[6]>>8)&0x01) { |
| 951 | if ((state->pf12_control[6]>>8)&0x01) { |
| 958 | 952 | flags|=TILE_FLIPX; |
| 959 | 953 | colour&=0x7; |
| 960 | 954 | } |
| 961 | | if ((deco32_pf12_control[6]>>8)&0x02) { |
| 955 | if ((state->pf12_control[6]>>8)&0x02) { |
| 962 | 956 | flags|=TILE_FLIPY; |
| 963 | 957 | colour&=0x7; |
| 964 | 958 | } |
| 965 | 959 | } |
| 966 | 960 | |
| 967 | | SET_TILE_INFO(1,(tile&0xfff)|deco32_pf2_bank,colour+deco32_pf2_colourbank,flags); |
| 961 | SET_TILE_INFO(1,(tile&0xfff)|state->pf2_bank,colour+state->pf2_colourbank,flags); |
| 968 | 962 | } |
| 969 | 963 | |
| 970 | 964 | static TILE_GET_INFO( get_pf3_tile_info ) |
| 971 | 965 | { |
| 972 | | UINT32 tile=deco32_pf3_data[tile_index]; |
| 966 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 967 | UINT32 tile=state->pf3_data[tile_index]; |
| 973 | 968 | UINT8 colour=(tile>>12)&0xf; |
| 974 | 969 | UINT8 flags=0; |
| 975 | 970 | |
| 976 | 971 | if (tile&0x8000) { |
| 977 | | if ((deco32_pf34_control[6]>>0)&0x01) { |
| 972 | if ((state->pf34_control[6]>>0)&0x01) { |
| 978 | 973 | flags|=TILE_FLIPX; |
| 979 | 974 | colour&=0x7; |
| 980 | 975 | } |
| 981 | | if ((deco32_pf34_control[6]>>0)&0x02) { |
| 976 | if ((state->pf34_control[6]>>0)&0x02) { |
| 982 | 977 | flags|=TILE_FLIPY; |
| 983 | 978 | colour&=0x7; |
| 984 | 979 | } |
| 985 | 980 | } |
| 986 | 981 | |
| 987 | | SET_TILE_INFO(2,(tile&0xfff)|deco32_pf3_bank,colour,flags); |
| 982 | SET_TILE_INFO(2,(tile&0xfff)|state->pf3_bank,colour,flags); |
| 988 | 983 | } |
| 989 | 984 | |
| 990 | 985 | static TILE_GET_INFO( get_pf4_tile_info ) |
| 991 | 986 | { |
| 992 | | UINT32 tile=deco32_pf4_data[tile_index]; |
| 987 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 988 | UINT32 tile=state->pf4_data[tile_index]; |
| 993 | 989 | UINT8 colour=(tile>>12)&0xf; |
| 994 | 990 | UINT8 flags=0; |
| 995 | 991 | |
| 996 | 992 | if (tile&0x8000) { |
| 997 | | if ((deco32_pf34_control[6]>>8)&0x01) { |
| 993 | if ((state->pf34_control[6]>>8)&0x01) { |
| 998 | 994 | flags|=TILE_FLIPX; |
| 999 | 995 | colour&=0x7; |
| 1000 | 996 | } |
| 1001 | | if ((deco32_pf34_control[6]>>8)&0x02) { |
| 997 | if ((state->pf34_control[6]>>8)&0x02) { |
| 1002 | 998 | flags|=TILE_FLIPY; |
| 1003 | 999 | colour&=0x7; |
| 1004 | 1000 | } |
| 1005 | 1001 | } |
| 1006 | 1002 | |
| 1007 | | SET_TILE_INFO(2,(tile&0xfff)|deco32_pf4_bank,colour+deco32_pf4_colourbank,flags); |
| 1003 | SET_TILE_INFO(2,(tile&0xfff)|state->pf4_bank,colour+state->pf4_colourbank,flags); |
| 1008 | 1004 | } |
| 1009 | 1005 | |
| 1010 | 1006 | /* Captain America tilemap chip 2 has different banking and colour from normal */ |
| 1011 | 1007 | static TILE_GET_INFO( get_ca_pf3_tile_info ) |
| 1012 | 1008 | { |
| 1013 | | int tile=deco32_pf3_data[tile_index]; |
| 1014 | | SET_TILE_INFO(2,(tile&0x3fff)+deco32_pf3_bank,(tile >> 14)&3,0); |
| 1009 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1010 | int tile=state->pf3_data[tile_index]; |
| 1011 | SET_TILE_INFO(2,(tile&0x3fff)+state->pf3_bank,(tile >> 14)&3,0); |
| 1015 | 1012 | } |
| 1016 | 1013 | |
| 1017 | 1014 | static TILE_GET_INFO( get_ll_pf3_tile_info ) |
| 1018 | 1015 | { |
| 1019 | | UINT32 tile=deco32_pf3_data[tile_index]; |
| 1016 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1017 | UINT32 tile=state->pf3_data[tile_index]; |
| 1020 | 1018 | UINT8 flags=0; |
| 1021 | 1019 | |
| 1022 | 1020 | if (tile&0x8000) { |
| 1023 | | if ((deco32_pf34_control[6]>>0)&0x01) |
| 1021 | if ((state->pf34_control[6]>>0)&0x01) |
| 1024 | 1022 | flags|=TILE_FLIPX; |
| 1025 | | if ((deco32_pf34_control[6]>>0)&0x02) |
| 1023 | if ((state->pf34_control[6]>>0)&0x02) |
| 1026 | 1024 | flags|=TILE_FLIPY; |
| 1027 | 1025 | } |
| 1028 | 1026 | |
| 1029 | | SET_TILE_INFO(2,(tile&0x0fff)|deco32_pf3_bank,(tile >> 12)&3,flags); |
| 1027 | SET_TILE_INFO(2,(tile&0x0fff)|state->pf3_bank,(tile >> 12)&3,flags); |
| 1030 | 1028 | } |
| 1031 | 1029 | |
| 1032 | 1030 | static TILE_GET_INFO( get_ll_pf4_tile_info ) |
| 1033 | 1031 | { |
| 1034 | | UINT32 tile=deco32_pf4_data[tile_index]; |
| 1032 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1033 | UINT32 tile=state->pf4_data[tile_index]; |
| 1035 | 1034 | UINT8 flags=0; |
| 1036 | 1035 | |
| 1037 | 1036 | if (tile&0x8000) { |
| 1038 | | if ((deco32_pf34_control[6]>>8)&0x01) |
| 1037 | if ((state->pf34_control[6]>>8)&0x01) |
| 1039 | 1038 | flags|=TILE_FLIPX; |
| 1040 | | if ((deco32_pf34_control[6]>>8)&0x02) |
| 1039 | if ((state->pf34_control[6]>>8)&0x02) |
| 1041 | 1040 | flags|=TILE_FLIPY; |
| 1042 | 1041 | } |
| 1043 | 1042 | |
| 1044 | | SET_TILE_INFO(2,(tile&0x0fff)|deco32_pf4_bank,(tile >> 12)&3,flags); |
| 1043 | SET_TILE_INFO(2,(tile&0x0fff)|state->pf4_bank,(tile >> 12)&3,flags); |
| 1045 | 1044 | } |
| 1046 | 1045 | |
| 1047 | 1046 | VIDEO_START( captaven ) |
| 1048 | 1047 | { |
| 1049 | | pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1050 | | pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1051 | | pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1052 | | pf3_tilemap = tilemap_create(machine, get_ca_pf3_tile_info, tilemap_scan_rows,16,16,32,32); |
| 1048 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1049 | state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1050 | state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1051 | state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1052 | state->pf3_tilemap = tilemap_create(machine, get_ca_pf3_tile_info, tilemap_scan_rows,16,16,32,32); |
| 1053 | 1053 | |
| 1054 | | tilemap_set_transparent_pen(pf1_tilemap,0); |
| 1055 | | tilemap_set_transparent_pen(pf1a_tilemap,0); |
| 1056 | | tilemap_set_transparent_pen(pf2_tilemap,0); |
| 1057 | | tilemap_set_transparent_pen(pf3_tilemap,0); |
| 1054 | tilemap_set_transparent_pen(state->pf1_tilemap,0); |
| 1055 | tilemap_set_transparent_pen(state->pf1a_tilemap,0); |
| 1056 | tilemap_set_transparent_pen(state->pf2_tilemap,0); |
| 1057 | tilemap_set_transparent_pen(state->pf3_tilemap,0); |
| 1058 | 1058 | |
| 1059 | | deco32_pf2_colourbank=16; |
| 1060 | | deco32_pf4_colourbank=0; |
| 1061 | | has_ace_ram=0; |
| 1059 | state->pf2_colourbank=16; |
| 1060 | state->pf4_colourbank=0; |
| 1061 | state->has_ace_ram=0; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | 1064 | VIDEO_START( fghthist ) |
| 1065 | 1065 | { |
| 1066 | | pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1067 | | pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1068 | | pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1069 | | pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1070 | | pf1a_tilemap =0; |
| 1071 | | dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1066 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1067 | state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1068 | state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1069 | state->pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1070 | state->pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1071 | state->pf1a_tilemap =0; |
| 1072 | state->dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1072 | 1073 | |
| 1073 | 1074 | /* Allow sprite bitmap */ |
| 1074 | 1075 | int width = machine->primary_screen->width(); |
| 1075 | 1076 | int height = machine->primary_screen->height(); |
| 1076 | | sprite_priority_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1077 | state->sprite_priority_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1077 | 1078 | |
| 1078 | | tilemap_set_transparent_pen(pf1_tilemap,0); |
| 1079 | | tilemap_set_transparent_pen(pf2_tilemap,0); |
| 1080 | | tilemap_set_transparent_pen(pf3_tilemap,0); |
| 1079 | tilemap_set_transparent_pen(state->pf1_tilemap,0); |
| 1080 | tilemap_set_transparent_pen(state->pf2_tilemap,0); |
| 1081 | tilemap_set_transparent_pen(state->pf3_tilemap,0); |
| 1081 | 1082 | |
| 1082 | | deco32_pf2_colourbank=deco32_pf4_colourbank=0; |
| 1083 | | has_ace_ram=0; |
| 1083 | state->pf2_colourbank=state->pf4_colourbank=0; |
| 1084 | state->has_ace_ram=0; |
| 1084 | 1085 | } |
| 1085 | 1086 | |
| 1086 | 1087 | VIDEO_START( dragngun ) |
| 1087 | 1088 | { |
| 1088 | | pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1089 | | pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1090 | | pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,64,32); |
| 1091 | | pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1092 | | pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1093 | | dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1094 | | deco32_raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2); |
| 1089 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1090 | state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1091 | state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1092 | state->pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,64,32); |
| 1093 | state->pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1094 | state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1095 | state->dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1096 | state->raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2); |
| 1095 | 1097 | |
| 1096 | | tilemap_set_transparent_pen(pf1_tilemap,0); |
| 1097 | | tilemap_set_transparent_pen(pf2_tilemap,0); |
| 1098 | | tilemap_set_transparent_pen(pf3_tilemap,0); |
| 1099 | | tilemap_set_transparent_pen(pf1a_tilemap,0); |
| 1100 | | memset(dirty_palette,0,4096); |
| 1098 | tilemap_set_transparent_pen(state->pf1_tilemap,0); |
| 1099 | tilemap_set_transparent_pen(state->pf2_tilemap,0); |
| 1100 | tilemap_set_transparent_pen(state->pf3_tilemap,0); |
| 1101 | tilemap_set_transparent_pen(state->pf1a_tilemap,0); |
| 1102 | memset(state->dirty_palette,0,4096); |
| 1101 | 1103 | |
| 1102 | | deco32_pf2_colourbank=deco32_pf4_colourbank=0; |
| 1104 | state->pf2_colourbank=state->pf4_colourbank=0; |
| 1103 | 1105 | |
| 1104 | | state_save_register_global(machine, dragngun_sprite_ctrl); |
| 1105 | | has_ace_ram=0; |
| 1106 | state_save_register_global(machine, state->dragngun_sprite_ctrl); |
| 1107 | state->has_ace_ram=0; |
| 1106 | 1108 | } |
| 1107 | 1109 | |
| 1108 | 1110 | VIDEO_START( lockload ) |
| 1109 | 1111 | { |
| 1110 | | pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1111 | | pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1112 | | pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,32,32); |
| 1113 | | pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows, 16,16,32,32); |
| 1114 | | pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1115 | | dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1116 | | deco32_raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2); |
| 1117 | | memset(deco32_raster_display_list, 0, 10 * 256); |
| 1112 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1113 | state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1114 | state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1115 | state->pf3_tilemap = tilemap_create(machine, get_ll_pf3_tile_info, deco16_scan_rows,16,16,32,32); |
| 1116 | state->pf4_tilemap = tilemap_create(machine, get_ll_pf4_tile_info, deco16_scan_rows, 16,16,32,32); |
| 1117 | state->pf1a_tilemap =tilemap_create(machine, get_pf1a_tile_info, deco16_scan_rows,16,16,64,32); |
| 1118 | state->dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1119 | state->raster_display_list = auto_alloc_array(machine, UINT16, 10 * 256 / 2); |
| 1120 | memset(state->raster_display_list, 0, 10 * 256); |
| 1118 | 1121 | |
| 1119 | | tilemap_set_transparent_pen(pf1_tilemap,0); |
| 1120 | | tilemap_set_transparent_pen(pf2_tilemap,0); |
| 1121 | | tilemap_set_transparent_pen(pf3_tilemap,0); |
| 1122 | | tilemap_set_transparent_pen(pf1a_tilemap,0); |
| 1123 | | memset(dirty_palette,0,4096); |
| 1122 | tilemap_set_transparent_pen(state->pf1_tilemap,0); |
| 1123 | tilemap_set_transparent_pen(state->pf2_tilemap,0); |
| 1124 | tilemap_set_transparent_pen(state->pf3_tilemap,0); |
| 1125 | tilemap_set_transparent_pen(state->pf1a_tilemap,0); |
| 1126 | memset(state->dirty_palette,0,4096); |
| 1124 | 1127 | |
| 1125 | | deco32_pf2_colourbank=deco32_pf4_colourbank=0; |
| 1128 | state->pf2_colourbank=state->pf4_colourbank=0; |
| 1126 | 1129 | |
| 1127 | | state_save_register_global(machine, dragngun_sprite_ctrl); |
| 1128 | | has_ace_ram=0; |
| 1130 | state_save_register_global(machine, state->dragngun_sprite_ctrl); |
| 1131 | state->has_ace_ram=0; |
| 1129 | 1132 | } |
| 1130 | 1133 | |
| 1131 | 1134 | VIDEO_START( nslasher ) |
| 1132 | 1135 | { |
| 1136 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1133 | 1137 | int width, height; |
| 1134 | 1138 | |
| 1135 | | pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1136 | | pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1137 | | pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows,16,16,64,32); |
| 1138 | | pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1139 | | pf1a_tilemap =0; |
| 1140 | | dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1139 | state->pf1_tilemap = tilemap_create(machine, get_pf1_tile_info, tilemap_scan_rows, 8, 8,64,32); |
| 1140 | state->pf2_tilemap = tilemap_create(machine, get_pf2_tile_info, deco16_scan_rows,16,16,64,32); |
| 1141 | state->pf3_tilemap = tilemap_create(machine, get_pf3_tile_info, deco16_scan_rows,16,16,64,32); |
| 1142 | state->pf4_tilemap = tilemap_create(machine, get_pf4_tile_info, deco16_scan_rows, 16,16,64,32); |
| 1143 | state->pf1a_tilemap =0; |
| 1144 | state->dirty_palette = auto_alloc_array(machine, UINT8, 4096); |
| 1141 | 1145 | |
| 1142 | 1146 | width = machine->primary_screen->width(); |
| 1143 | 1147 | height = machine->primary_screen->height(); |
| 1144 | | sprite0_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1145 | | sprite1_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1146 | | tilemap_alpha_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1148 | state->sprite0_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1149 | state->sprite1_mix_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1150 | state->tilemap_alpha_bitmap=auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED16 ); |
| 1147 | 1151 | |
| 1148 | | tilemap_set_transparent_pen(pf1_tilemap,0); |
| 1149 | | tilemap_set_transparent_pen(pf2_tilemap,0); |
| 1150 | | tilemap_set_transparent_pen(pf3_tilemap,0); |
| 1151 | | memset(dirty_palette,0,4096); |
| 1152 | tilemap_set_transparent_pen(state->pf1_tilemap,0); |
| 1153 | tilemap_set_transparent_pen(state->pf2_tilemap,0); |
| 1154 | tilemap_set_transparent_pen(state->pf3_tilemap,0); |
| 1155 | memset(state->dirty_palette,0,4096); |
| 1152 | 1156 | |
| 1153 | | deco32_pf2_colourbank=16; |
| 1154 | | deco32_pf4_colourbank=16; |
| 1155 | | state_save_register_global(machine, deco32_pri); |
| 1156 | | has_ace_ram=1; |
| 1157 | state->pf2_colourbank=16; |
| 1158 | state->pf4_colourbank=16; |
| 1159 | state_save_register_global(machine, state->pri); |
| 1160 | state->has_ace_ram=1; |
| 1157 | 1161 | } |
| 1158 | 1162 | |
| 1159 | 1163 | /******************************************************************************/ |
| r10427 | r10428 | |
| 1165 | 1169 | |
| 1166 | 1170 | VIDEO_EOF( dragngun ) |
| 1167 | 1171 | { |
| 1168 | | deco32_raster_display_position=0; |
| 1172 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1173 | state->raster_display_position=0; |
| 1169 | 1174 | } |
| 1170 | 1175 | |
| 1171 | 1176 | #if 0 |
| 1172 | 1177 | static void print_debug_info(bitmap_t *bitmap) |
| 1173 | 1178 | { |
| 1179 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1174 | 1180 | int j; |
| 1175 | 1181 | char buf[64*5]; |
| 1176 | 1182 | char *bufptr = buf; |
| 1177 | 1183 | |
| 1178 | | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf12_control[0]&0xffff,deco32_pf12_control[1]&0xffff,deco32_pf12_control[2]&0xffff,deco32_pf12_control[3]&0xffff); |
| 1179 | | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf12_control[4]&0xffff,deco32_pf12_control[5]&0xffff,deco32_pf12_control[6]&0xffff,deco32_pf12_control[7]&0xffff); |
| 1184 | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf12_control[0]&0xffff,state->pf12_control[1]&0xffff,state->pf12_control[2]&0xffff,state->pf12_control[3]&0xffff); |
| 1185 | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf12_control[4]&0xffff,state->pf12_control[5]&0xffff,state->pf12_control[6]&0xffff,state->pf12_control[7]&0xffff); |
| 1180 | 1186 | |
| 1181 | | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf34_control[0]&0xffff,deco32_pf34_control[1]&0xffff,deco32_pf34_control[2]&0xffff,deco32_pf34_control[3]&0xffff); |
| 1182 | | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",deco32_pf34_control[4]&0xffff,deco32_pf34_control[5]&0xffff,deco32_pf34_control[6]&0xffff,deco32_pf34_control[7]&0xffff); |
| 1183 | | bufptr += sprintf(bufptr,"%04X\n",deco32_pri); |
| 1187 | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf34_control[0]&0xffff,state->pf34_control[1]&0xffff,state->pf34_control[2]&0xffff,state->pf34_control[3]&0xffff); |
| 1188 | bufptr += sprintf(bufptr,"%04X %04X %04X %04X\n",state->pf34_control[4]&0xffff,state->pf34_control[5]&0xffff,state->pf34_control[6]&0xffff,state->pf34_control[7]&0xffff); |
| 1189 | bufptr += sprintf(bufptr,"%04X\n",state->pri); |
| 1184 | 1190 | |
| 1185 | 1191 | ui_draw_text(buf,60,40); |
| 1186 | 1192 | } |
| r10427 | r10428 | |
| 1232 | 1238 | |
| 1233 | 1239 | static void combined_tilemap_draw(running_machine* machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 1234 | 1240 | { |
| 1235 | | const bitmap_t *bitmap0 = tilemap_get_pixmap(pf3_tilemap); |
| 1236 | | const bitmap_t *bitmap1 = tilemap_get_pixmap(pf4_tilemap); |
| 1241 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1242 | const bitmap_t *bitmap0 = tilemap_get_pixmap(state->pf3_tilemap); |
| 1243 | const bitmap_t *bitmap1 = tilemap_get_pixmap(state->pf4_tilemap); |
| 1237 | 1244 | int x,y,p; |
| 1238 | 1245 | |
| 1239 | 1246 | const UINT16 width_mask=0x3ff; |
| 1240 | 1247 | const UINT16 height_mask=0x1ff; |
| 1241 | | const UINT16 y_src=deco32_pf34_control[2]; |
| 1242 | | // const UINT32 *rows=deco32_pf3_rowscroll; |
| 1248 | const UINT16 y_src=state->pf34_control[2]; |
| 1249 | // const UINT32 *rows=state->pf3_rowscroll; |
| 1243 | 1250 | |
| 1244 | 1251 | const UINT16 *bitmap0_y; |
| 1245 | 1252 | const UINT16 *bitmap1_y; |
| r10427 | r10428 | |
| 1255 | 1262 | bitmap2_y=BITMAP_ADDR32(bitmap, y, 0); |
| 1256 | 1263 | |
| 1257 | 1264 | /* Todo: Should add row enable, and col scroll, but never used as far as I can see */ |
| 1258 | | x_src=(deco32_pf34_control[1] + deco32_pf3_rowscroll[py])&width_mask; |
| 1265 | x_src=(state->pf34_control[1] + state->pf3_rowscroll[py])&width_mask; |
| 1259 | 1266 | |
| 1260 | 1267 | for (x=0; x<320; x++) { |
| 1261 | 1268 | |
| r10427 | r10428 | |
| 1275 | 1282 | |
| 1276 | 1283 | VIDEO_UPDATE( captaven ) |
| 1277 | 1284 | { |
| 1285 | deco32_state *state = screen->machine->driver_data<deco32_state>(); |
| 1278 | 1286 | int pf1_enable,pf2_enable,pf3_enable; |
| 1279 | | static int last_pf3_bank; |
| 1280 | 1287 | |
| 1281 | | flip_screen_set(screen->machine, deco32_pf12_control[0]&0x80); |
| 1288 | flip_screen_set(screen->machine, state->pf12_control[0]&0x80); |
| 1282 | 1289 | tilemap_set_flip_all(screen->machine,flip_screen_get(screen->machine) ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0); |
| 1283 | 1290 | |
| 1284 | | deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1285 | | deco32_setup_scroll(pf1a_tilemap,512,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1286 | | deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200); |
| 1287 | | deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200); |
| 1291 | deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1292 | deco32_setup_scroll(state->pf1a_tilemap,512,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1293 | deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200); |
| 1294 | deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf3_rowscroll,state->pf3_rowscroll+0x200); |
| 1288 | 1295 | |
| 1289 | 1296 | /* PF1 & PF2 only have enough roms for 1 bank */ |
| 1290 | | deco32_pf1_bank=0;//(deco32_pf12_control[7]>> 4)&0xf; |
| 1291 | | deco32_pf2_bank=0;//(deco32_pf12_control[7]>>12)&0xf; |
| 1292 | | deco32_pf3_bank=(deco32_pf34_control[7]>> 4)&0xf; |
| 1297 | state->pf1_bank=0;//(state->pf12_control[7]>> 4)&0xf; |
| 1298 | state->pf2_bank=0;//(state->pf12_control[7]>>12)&0xf; |
| 1299 | state->pf3_bank=(state->pf34_control[7]>> 4)&0xf; |
| 1293 | 1300 | |
| 1294 | | if (deco32_pf34_control[7]&0x0020) deco32_pf3_bank=0x4000; else deco32_pf3_bank=0; |
| 1295 | | if (deco32_pf3_bank!=last_pf3_bank) tilemap_mark_all_tiles_dirty(pf3_tilemap); |
| 1296 | | last_pf3_bank=deco32_pf3_bank; |
| 1301 | if (state->pf34_control[7]&0x0020) state->pf3_bank=0x4000; else state->pf3_bank=0; |
| 1302 | if (state->pf3_bank!=state->last_pf3_bank) tilemap_mark_all_tiles_dirty(state->pf3_tilemap); |
| 1303 | state->last_pf3_bank=state->pf3_bank; |
| 1297 | 1304 | |
| 1298 | | pf1_enable=deco32_pf12_control[5]&0x0080; |
| 1299 | | pf2_enable=deco32_pf12_control[5]&0x8000; |
| 1300 | | pf3_enable=deco32_pf34_control[5]&0x0080; |
| 1305 | pf1_enable=state->pf12_control[5]&0x0080; |
| 1306 | pf2_enable=state->pf12_control[5]&0x8000; |
| 1307 | pf3_enable=state->pf34_control[5]&0x0080; |
| 1301 | 1308 | |
| 1302 | | tilemap_set_enable(pf1_tilemap,pf1_enable); |
| 1303 | | tilemap_set_enable(pf1a_tilemap,pf1_enable); |
| 1304 | | tilemap_set_enable(pf2_tilemap,pf2_enable); |
| 1305 | | tilemap_set_enable(pf3_tilemap,pf3_enable); |
| 1309 | tilemap_set_enable(state->pf1_tilemap,pf1_enable); |
| 1310 | tilemap_set_enable(state->pf1a_tilemap,pf1_enable); |
| 1311 | tilemap_set_enable(state->pf2_tilemap,pf2_enable); |
| 1312 | tilemap_set_enable(state->pf3_tilemap,pf3_enable); |
| 1306 | 1313 | |
| 1307 | 1314 | bitmap_fill(screen->machine->priority_bitmap,cliprect,0); |
| 1308 | | if ((deco32_pri&1)==0) { |
| 1315 | if ((state->pri&1)==0) { |
| 1309 | 1316 | if (pf3_enable) |
| 1310 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,TILEMAP_DRAW_OPAQUE,1); |
| 1317 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,TILEMAP_DRAW_OPAQUE,1); |
| 1311 | 1318 | else |
| 1312 | 1319 | bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine)); |
| 1313 | 1320 | |
| 1314 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2); |
| 1321 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2); |
| 1315 | 1322 | } else { |
| 1316 | 1323 | if (pf2_enable) { |
| 1317 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,1); |
| 1324 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,1); |
| 1318 | 1325 | } |
| 1319 | 1326 | else |
| 1320 | 1327 | bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine)); |
| 1321 | 1328 | |
| 1322 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2); |
| 1329 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2); |
| 1323 | 1330 | } |
| 1324 | 1331 | |
| 1325 | 1332 | /* PF1 can be in 8x8 mode or 16x16 mode */ |
| 1326 | | if (deco32_pf12_control[6]&0x80) |
| 1327 | | tilemap_draw(bitmap,cliprect,pf1_tilemap,0,4); |
| 1333 | if (state->pf12_control[6]&0x80) |
| 1334 | tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,4); |
| 1328 | 1335 | else |
| 1329 | | tilemap_draw(bitmap,cliprect,pf1a_tilemap,0,4); |
| 1336 | tilemap_draw(bitmap,cliprect,state->pf1a_tilemap,0,4); |
| 1330 | 1337 | |
| 1331 | 1338 | captaven_draw_sprites(screen->machine,bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3); |
| 1332 | 1339 | |
| r10427 | r10428 | |
| 1335 | 1342 | |
| 1336 | 1343 | VIDEO_UPDATE( dragngun ) |
| 1337 | 1344 | { |
| 1345 | deco32_state *state = screen->machine->driver_data<deco32_state>(); |
| 1338 | 1346 | /* Tilemap graphics banking */ |
| 1339 | | if ((((deco32_pf12_control[7]>> 4)&0x7)<<12)!=deco32_pf1_bank || deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3)) { |
| 1340 | | tilemap_mark_all_tiles_dirty(pf1_tilemap); |
| 1341 | | tilemap_mark_all_tiles_dirty(pf1a_tilemap); |
| 1347 | if ((((state->pf12_control[7]>> 4)&0x7)<<12)!=state->pf1_bank || state->pf1_flip!=((state->pf12_control[6]>>0)&0x3)) { |
| 1348 | tilemap_mark_all_tiles_dirty(state->pf1_tilemap); |
| 1349 | tilemap_mark_all_tiles_dirty(state->pf1a_tilemap); |
| 1342 | 1350 | } |
| 1343 | | if ((((deco32_pf12_control[7]>>12)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3)) |
| 1344 | | tilemap_mark_all_tiles_dirty(pf2_tilemap); |
| 1345 | | if ((((deco32_pf34_control[7]>> 5)&0x7)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3)) |
| 1346 | | tilemap_mark_all_tiles_dirty(pf3_tilemap); |
| 1347 | | if ((((deco32_pf34_control[7]>>13)&0x7)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3)) |
| 1348 | | tilemap_mark_all_tiles_dirty(pf4_tilemap); |
| 1349 | | deco32_pf1_bank=((deco32_pf12_control[7]>> 5)&0x7)<<12; |
| 1350 | | deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x7)<<12; |
| 1351 | | deco32_pf3_bank=((deco32_pf34_control[7]>> 5)&0x7)<<12; |
| 1352 | | deco32_pf4_bank=((deco32_pf34_control[7]>>13)&0x7)<<12; |
| 1351 | if ((((state->pf12_control[7]>>12)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3)) |
| 1352 | tilemap_mark_all_tiles_dirty(state->pf2_tilemap); |
| 1353 | if ((((state->pf34_control[7]>> 5)&0x7)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3)) |
| 1354 | tilemap_mark_all_tiles_dirty(state->pf3_tilemap); |
| 1355 | if ((((state->pf34_control[7]>>13)&0x7)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3)) |
| 1356 | tilemap_mark_all_tiles_dirty(state->pf4_tilemap); |
| 1357 | state->pf1_bank=((state->pf12_control[7]>> 5)&0x7)<<12; |
| 1358 | state->pf2_bank=((state->pf12_control[7]>>12)&0x7)<<12; |
| 1359 | state->pf3_bank=((state->pf34_control[7]>> 5)&0x7)<<12; |
| 1360 | state->pf4_bank=((state->pf34_control[7]>>13)&0x7)<<12; |
| 1353 | 1361 | |
| 1354 | | deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3; |
| 1355 | | deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3; |
| 1356 | | deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3; |
| 1357 | | deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3; |
| 1362 | state->pf1_flip=(state->pf12_control[6]>>0)&0x3; |
| 1363 | state->pf2_flip=(state->pf12_control[6]>>8)&0x3; |
| 1364 | state->pf3_flip=(state->pf34_control[6]>>0)&0x3; |
| 1365 | state->pf4_flip=(state->pf34_control[6]>>8)&0x3; |
| 1358 | 1366 | |
| 1359 | | deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1360 | | deco32_setup_scroll(pf1a_tilemap,512,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1361 | | deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200); |
| 1362 | | deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200); |
| 1363 | | deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200); |
| 1367 | deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1368 | deco32_setup_scroll(state->pf1a_tilemap,512,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1369 | deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200); |
| 1370 | deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200); |
| 1371 | deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200); |
| 1364 | 1372 | |
| 1365 | | tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080); |
| 1366 | | tilemap_set_enable(pf1a_tilemap,deco32_pf12_control[5]&0x0080); |
| 1367 | | tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000); |
| 1368 | | tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080); |
| 1369 | | tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000); |
| 1373 | tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080); |
| 1374 | tilemap_set_enable(state->pf1a_tilemap,state->pf12_control[5]&0x0080); |
| 1375 | tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000); |
| 1376 | tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080); |
| 1377 | tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000); |
| 1370 | 1378 | |
| 1371 | | if ((deco32_pf34_control[5]&0x8000)==0) |
| 1379 | if ((state->pf34_control[5]&0x8000)==0) |
| 1372 | 1380 | bitmap_fill(bitmap,cliprect,get_black_pen(screen->machine)); |
| 1373 | 1381 | |
| 1374 | | tilemap_draw(bitmap,cliprect,pf4_tilemap,0,0); |
| 1375 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,0); |
| 1382 | tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,0); |
| 1383 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,0); |
| 1376 | 1384 | |
| 1377 | 1385 | /* Raster update */ |
| 1378 | | if (deco32_raster_display_position) { |
| 1386 | if (state->raster_display_position) { |
| 1379 | 1387 | int ptr=0,start,end=0; |
| 1380 | 1388 | rectangle clip; |
| 1381 | | int overflow=deco32_raster_display_position; |
| 1389 | int overflow=state->raster_display_position; |
| 1382 | 1390 | |
| 1383 | 1391 | clip.min_x = cliprect->min_x; |
| 1384 | 1392 | clip.max_x = cliprect->max_x; |
| 1385 | 1393 | |
| 1386 | 1394 | /* Finish list up to end of visible display */ |
| 1387 | | deco32_raster_display_list[overflow++]=255; |
| 1388 | | deco32_raster_display_list[overflow++]=deco32_pf12_control[1]; |
| 1389 | | deco32_raster_display_list[overflow++]=deco32_pf12_control[2]; |
| 1390 | | deco32_raster_display_list[overflow++]=deco32_pf12_control[3]; |
| 1391 | | deco32_raster_display_list[overflow++]=deco32_pf12_control[4]; |
| 1395 | state->raster_display_list[overflow++]=255; |
| 1396 | state->raster_display_list[overflow++]=state->pf12_control[1]; |
| 1397 | state->raster_display_list[overflow++]=state->pf12_control[2]; |
| 1398 | state->raster_display_list[overflow++]=state->pf12_control[3]; |
| 1399 | state->raster_display_list[overflow++]=state->pf12_control[4]; |
| 1392 | 1400 | |
| 1393 | 1401 | while (ptr<overflow) { |
| 1394 | 1402 | start=end; |
| 1395 | | end=deco32_raster_display_list[ptr++]; |
| 1396 | | deco32_pf12_control[1]=deco32_raster_display_list[ptr++]; |
| 1397 | | deco32_pf12_control[2]=deco32_raster_display_list[ptr++]; |
| 1398 | | deco32_pf12_control[3]=deco32_raster_display_list[ptr++]; |
| 1399 | | deco32_pf12_control[4]=deco32_raster_display_list[ptr++]; |
| 1403 | end=state->raster_display_list[ptr++]; |
| 1404 | state->pf12_control[1]=state->raster_display_list[ptr++]; |
| 1405 | state->pf12_control[2]=state->raster_display_list[ptr++]; |
| 1406 | state->pf12_control[3]=state->raster_display_list[ptr++]; |
| 1407 | state->pf12_control[4]=state->raster_display_list[ptr++]; |
| 1400 | 1408 | |
| 1401 | 1409 | clip.min_y = start; |
| 1402 | 1410 | clip.max_y = end; |
| 1403 | 1411 | |
| 1404 | | deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200); |
| 1405 | | tilemap_draw(bitmap,&clip,pf2_tilemap,0,0); |
| 1412 | deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200); |
| 1413 | tilemap_draw(bitmap,&clip,state->pf2_tilemap,0,0); |
| 1406 | 1414 | } |
| 1407 | 1415 | } else { |
| 1408 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0); |
| 1416 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0); |
| 1409 | 1417 | } |
| 1410 | 1418 | |
| 1411 | 1419 | dragngun_draw_sprites(screen->machine,bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32); |
| 1412 | 1420 | |
| 1413 | 1421 | /* PF1 can be in 8x8 mode or 16x16 mode */ |
| 1414 | | if (deco32_pf12_control[6]&0x80) |
| 1415 | | tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0); |
| 1422 | if (state->pf12_control[6]&0x80) |
| 1423 | tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0); |
| 1416 | 1424 | else |
| 1417 | | tilemap_draw(bitmap,cliprect,pf1a_tilemap,0,0); |
| 1425 | tilemap_draw(bitmap,cliprect,state->pf1a_tilemap,0,0); |
| 1418 | 1426 | return 0; |
| 1419 | 1427 | } |
| 1420 | 1428 | |
| 1421 | 1429 | VIDEO_UPDATE( fghthist ) |
| 1422 | 1430 | { |
| 1431 | deco32_state *state = screen->machine->driver_data<deco32_state>(); |
| 1423 | 1432 | /* Dirty tilemaps if any globals change */ |
| 1424 | | if (deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3)) |
| 1425 | | tilemap_mark_all_tiles_dirty(pf1_tilemap); |
| 1426 | | if (deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3)) |
| 1427 | | tilemap_mark_all_tiles_dirty(pf2_tilemap); |
| 1433 | if (state->pf1_flip!=((state->pf12_control[6]>>0)&0x3)) |
| 1434 | tilemap_mark_all_tiles_dirty(state->pf1_tilemap); |
| 1435 | if (state->pf2_flip!=((state->pf12_control[6]>>8)&0x3)) |
| 1436 | tilemap_mark_all_tiles_dirty(state->pf2_tilemap); |
| 1428 | 1437 | |
| 1429 | | if ((((deco32_pf12_control[7]>>13)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3)) |
| 1430 | | tilemap_mark_all_tiles_dirty(pf2_tilemap); |
| 1431 | | if ((((deco32_pf34_control[7]>> 5)&0x7)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3)) |
| 1432 | | tilemap_mark_all_tiles_dirty(pf3_tilemap); |
| 1433 | | if ((((deco32_pf34_control[7]>>13)&0x7)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3)) |
| 1434 | | tilemap_mark_all_tiles_dirty(pf4_tilemap); |
| 1438 | if ((((state->pf12_control[7]>>13)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3)) |
| 1439 | tilemap_mark_all_tiles_dirty(state->pf2_tilemap); |
| 1440 | if ((((state->pf34_control[7]>> 5)&0x7)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3)) |
| 1441 | tilemap_mark_all_tiles_dirty(state->pf3_tilemap); |
| 1442 | if ((((state->pf34_control[7]>>13)&0x7)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3)) |
| 1443 | tilemap_mark_all_tiles_dirty(state->pf4_tilemap); |
| 1435 | 1444 | |
| 1436 | | deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x3)<<12; |
| 1437 | | deco32_pf3_bank=((deco32_pf34_control[7]>> 5)&0x3)<<12; //WRONG WRONG WRONG check masks |
| 1438 | | deco32_pf4_bank=((deco32_pf34_control[7]>>12)&0x3)<<12; |
| 1439 | | deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3; |
| 1440 | | deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3; |
| 1441 | | deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3; |
| 1442 | | deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3; |
| 1445 | state->pf2_bank=((state->pf12_control[7]>>12)&0x3)<<12; |
| 1446 | state->pf3_bank=((state->pf34_control[7]>> 5)&0x3)<<12; //WRONG WRONG WRONG check masks |
| 1447 | state->pf4_bank=((state->pf34_control[7]>>12)&0x3)<<12; |
| 1448 | state->pf1_flip=(state->pf12_control[6]>>0)&0x3; |
| 1449 | state->pf2_flip=(state->pf12_control[6]>>8)&0x3; |
| 1450 | state->pf3_flip=(state->pf34_control[6]>>0)&0x3; |
| 1451 | state->pf4_flip=(state->pf34_control[6]>>8)&0x3; |
| 1443 | 1452 | |
| 1444 | 1453 | /* Enable registers */ |
| 1445 | | tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080); |
| 1446 | | tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000); |
| 1447 | | tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080); |
| 1448 | | tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000); |
| 1454 | tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080); |
| 1455 | tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000); |
| 1456 | tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080); |
| 1457 | tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000); |
| 1449 | 1458 | |
| 1450 | 1459 | /* Setup scroll registers */ |
| 1451 | | deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1452 | | deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200); |
| 1453 | | deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200); |
| 1454 | | deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200); |
| 1460 | deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1461 | deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200); |
| 1462 | deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200); |
| 1463 | deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200); |
| 1455 | 1464 | |
| 1456 | 1465 | /* Draw screen */ |
| 1457 | | deco16_clear_sprite_priority_bitmap(); |
| 1466 | deco16_clear_sprite_priority_bitmap(state); |
| 1458 | 1467 | bitmap_fill(screen->machine->priority_bitmap,cliprect,0); |
| 1459 | 1468 | bitmap_fill(bitmap,cliprect,screen->machine->pens[0x000]); // Palette index not confirmed |
| 1460 | | tilemap_draw(bitmap,cliprect,pf4_tilemap,0,0); |
| 1461 | | if(deco32_pri&1) |
| 1469 | tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,0); |
| 1470 | if(state->pri&1) |
| 1462 | 1471 | { |
| 1463 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,0); |
| 1464 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2); |
| 1472 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,0); |
| 1473 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2); |
| 1465 | 1474 | } |
| 1466 | 1475 | else |
| 1467 | 1476 | { |
| 1468 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,0); |
| 1469 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2); |
| 1477 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,0); |
| 1478 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2); |
| 1470 | 1479 | } |
| 1471 | 1480 | fghthist_draw_sprites(screen->machine, bitmap, cliprect, screen->machine->generic.buffered_spriteram.u32,3,0, 0xf); |
| 1472 | | tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0); |
| 1481 | tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0); |
| 1473 | 1482 | return 0; |
| 1474 | 1483 | } |
| 1475 | 1484 | |
| r10427 | r10428 | |
| 1483 | 1492 | */ |
| 1484 | 1493 | static void mixDualAlphaSprites(bitmap_t *bitmap, const rectangle *cliprect, const gfx_element *gfx0, const gfx_element *gfx1, int mixAlphaTilemap) |
| 1485 | 1494 | { |
| 1495 | deco32_state *state = gfx0->machine->driver_data<deco32_state>(); |
| 1486 | 1496 | running_machine *machine = gfx0->machine; |
| 1487 | 1497 | const pen_t *pens = machine->pens; |
| 1488 | 1498 | const pen_t *pal0 = &pens[gfx0->color_base]; |
| 1489 | 1499 | const pen_t *pal1 = &pens[gfx1->color_base]; |
| 1490 | | const pen_t *pal2 = &pens[machine->gfx[(deco32_pri&1) ? 1 : 2]->color_base]; |
| 1500 | const pen_t *pal2 = &pens[machine->gfx[(state->pri&1) ? 1 : 2]->color_base]; |
| 1491 | 1501 | int x,y; |
| 1492 | 1502 | |
| 1493 | 1503 | /* Mix sprites into main bitmap, based on priority & alpha */ |
| 1494 | 1504 | for (y=8; y<248; y++) { |
| 1495 | 1505 | UINT8* tilemapPri=BITMAP_ADDR8(machine->priority_bitmap, y, 0); |
| 1496 | | UINT16* sprite0=BITMAP_ADDR16(sprite0_mix_bitmap, y, 0); |
| 1497 | | UINT16* sprite1=BITMAP_ADDR16(sprite1_mix_bitmap, y, 0); |
| 1506 | UINT16* sprite0=BITMAP_ADDR16(state->sprite0_mix_bitmap, y, 0); |
| 1507 | UINT16* sprite1=BITMAP_ADDR16(state->sprite1_mix_bitmap, y, 0); |
| 1498 | 1508 | UINT32* destLine=BITMAP_ADDR32(bitmap, y, 0); |
| 1499 | | UINT16* alphaTilemap=BITMAP_ADDR16(tilemap_alpha_bitmap, y, 0); |
| 1509 | UINT16* alphaTilemap=BITMAP_ADDR16(state->tilemap_alpha_bitmap, y, 0); |
| 1500 | 1510 | |
| 1501 | 1511 | for (x=0; x<320; x++) { |
| 1502 | 1512 | UINT16 priColAlphaPal0=sprite0[x]; |
| r10427 | r10428 | |
| 1550 | 1560 | */ |
| 1551 | 1561 | |
| 1552 | 1562 | /* Alpha values are tied to ACE ram... */ |
| 1553 | | //int alpha=((deco32_ace_ram[0x0 + (((priColAlphaPal1&0xf0)>>4)/2)]) * 8)-1; |
| 1563 | //int alpha=((state->ace_ram[0x0 + (((priColAlphaPal1&0xf0)>>4)/2)]) * 8)-1; |
| 1554 | 1564 | //if (alpha<0) |
| 1555 | 1565 | // alpha=0; |
| 1556 | 1566 | |
| r10427 | r10428 | |
| 1559 | 1569 | |
| 1560 | 1570 | if (pri1==0 && (((priColAlphaPal0&0xff)==0 || ((pri0&0x3)!=0 && (pri0&0x3)!=1 && (pri0&0x3)!=2)))) |
| 1561 | 1571 | { |
| 1562 | | if ((deco32_pri&1)==0 || ((deco32_pri&1)==1 && tilemapPri[x]<4) || ((deco32_pri&1)==1 && mixAlphaTilemap)) |
| 1572 | if ((state->pri&1)==0 || ((state->pri&1)==1 && tilemapPri[x]<4) || ((state->pri&1)==1 && mixAlphaTilemap)) |
| 1563 | 1573 | destLine[x]=alpha_blend_r32(destLine[x], pal1[(priColAlphaPal1&0xff) + (gfx1->color_granularity * col1)], 0x80); |
| 1564 | 1574 | } |
| 1565 | 1575 | else if (pri1==1 && ((priColAlphaPal0&0xff)==0 || ((pri0&0x3)!=0 && (pri0&0x3)!=1 && (pri0&0x3)!=2))) |
| r10427 | r10428 | |
| 1598 | 1608 | && ((priColAlphaPal1&0xff)==0 || (pri1&0x3)==2 || (pri1&0x3)==3 || alpha1)) |
| 1599 | 1609 | { |
| 1600 | 1610 | /* Alpha values are tied to ACE ram */ |
| 1601 | | int alpha=((deco32_ace_ram[0x17 + (((p&0xf0)>>4)/2)]) * 8)-1; |
| 1611 | int alpha=((state->ace_ram[0x17 + (((p&0xf0)>>4)/2)]) * 8)-1; |
| 1602 | 1612 | if (alpha<0) |
| 1603 | 1613 | alpha=0; |
| 1604 | 1614 | |
| r10427 | r10428 | |
| 1612 | 1622 | |
| 1613 | 1623 | VIDEO_UPDATE( nslasher ) |
| 1614 | 1624 | { |
| 1625 | deco32_state *state = screen->machine->driver_data<deco32_state>(); |
| 1615 | 1626 | int alphaTilemap=0; |
| 1616 | 1627 | |
| 1617 | 1628 | /* Dirty tilemaps if any globals change */ |
| 1618 | | if (deco32_pf1_flip!=((deco32_pf12_control[6]>>0)&0x3)) |
| 1619 | | tilemap_mark_all_tiles_dirty(pf1_tilemap); |
| 1620 | | if (deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3)) |
| 1621 | | tilemap_mark_all_tiles_dirty(pf2_tilemap); |
| 1622 | | if ((((deco32_pf12_control[7]>>12)&0x7)<<12)!=deco32_pf2_bank || deco32_pf2_flip!=((deco32_pf12_control[6]>>8)&0x3)) |
| 1623 | | tilemap_mark_all_tiles_dirty(pf2_tilemap); |
| 1624 | | if ((((deco32_pf34_control[7]>> 4)&0x3)<<12)!=deco32_pf3_bank || deco32_pf3_flip!=((deco32_pf34_control[6]>>0)&0x3)) |
| 1625 | | tilemap_mark_all_tiles_dirty(pf3_tilemap); |
| 1626 | | if ((((deco32_pf34_control[7]>>12)&0x3)<<12)!=deco32_pf4_bank || deco32_pf4_flip!=((deco32_pf34_control[6]>>8)&0x3)) |
| 1627 | | tilemap_mark_all_tiles_dirty(pf4_tilemap); |
| 1629 | if (state->pf1_flip!=((state->pf12_control[6]>>0)&0x3)) |
| 1630 | tilemap_mark_all_tiles_dirty(state->pf1_tilemap); |
| 1631 | if (state->pf2_flip!=((state->pf12_control[6]>>8)&0x3)) |
| 1632 | tilemap_mark_all_tiles_dirty(state->pf2_tilemap); |
| 1633 | if ((((state->pf12_control[7]>>12)&0x7)<<12)!=state->pf2_bank || state->pf2_flip!=((state->pf12_control[6]>>8)&0x3)) |
| 1634 | tilemap_mark_all_tiles_dirty(state->pf2_tilemap); |
| 1635 | if ((((state->pf34_control[7]>> 4)&0x3)<<12)!=state->pf3_bank || state->pf3_flip!=((state->pf34_control[6]>>0)&0x3)) |
| 1636 | tilemap_mark_all_tiles_dirty(state->pf3_tilemap); |
| 1637 | if ((((state->pf34_control[7]>>12)&0x3)<<12)!=state->pf4_bank || state->pf4_flip!=((state->pf34_control[6]>>8)&0x3)) |
| 1638 | tilemap_mark_all_tiles_dirty(state->pf4_tilemap); |
| 1628 | 1639 | |
| 1629 | | deco32_pf2_bank=((deco32_pf12_control[7]>>12)&0x3)<<12; |
| 1630 | | deco32_pf3_bank=((deco32_pf34_control[7]>> 4)&0x3)<<12; |
| 1631 | | deco32_pf4_bank=((deco32_pf34_control[7]>>12)&0x3)<<12; |
| 1632 | | deco32_pf1_flip=(deco32_pf12_control[6]>>0)&0x3; |
| 1633 | | deco32_pf2_flip=(deco32_pf12_control[6]>>8)&0x3; |
| 1634 | | deco32_pf3_flip=(deco32_pf34_control[6]>>0)&0x3; |
| 1635 | | deco32_pf4_flip=(deco32_pf34_control[6]>>8)&0x3; |
| 1640 | state->pf2_bank=((state->pf12_control[7]>>12)&0x3)<<12; |
| 1641 | state->pf3_bank=((state->pf34_control[7]>> 4)&0x3)<<12; |
| 1642 | state->pf4_bank=((state->pf34_control[7]>>12)&0x3)<<12; |
| 1643 | state->pf1_flip=(state->pf12_control[6]>>0)&0x3; |
| 1644 | state->pf2_flip=(state->pf12_control[6]>>8)&0x3; |
| 1645 | state->pf3_flip=(state->pf34_control[6]>>0)&0x3; |
| 1646 | state->pf4_flip=(state->pf34_control[6]>>8)&0x3; |
| 1636 | 1647 | |
| 1637 | 1648 | /* Setup scroll registers */ |
| 1638 | | deco32_setup_scroll(pf1_tilemap, 256,(deco32_pf12_control[5]>>0)&0xff,(deco32_pf12_control[6]>>0)&0xff,deco32_pf12_control[2],deco32_pf12_control[1],deco32_pf1_rowscroll,deco32_pf1_rowscroll+0x200); |
| 1639 | | deco32_setup_scroll(pf2_tilemap, 512,(deco32_pf12_control[5]>>8)&0xff,(deco32_pf12_control[6]>>8)&0xff,deco32_pf12_control[4],deco32_pf12_control[3],deco32_pf2_rowscroll,deco32_pf2_rowscroll+0x200); |
| 1640 | | deco32_setup_scroll(pf3_tilemap, 512,(deco32_pf34_control[5]>>0)&0xff,(deco32_pf34_control[6]>>0)&0xff,deco32_pf34_control[2],deco32_pf34_control[1],deco32_pf3_rowscroll,deco32_pf3_rowscroll+0x200); |
| 1641 | | deco32_setup_scroll(pf4_tilemap, 512,(deco32_pf34_control[5]>>8)&0xff,(deco32_pf34_control[6]>>8)&0xff,deco32_pf34_control[4],deco32_pf34_control[3],deco32_pf4_rowscroll,deco32_pf4_rowscroll+0x200); |
| 1649 | deco32_setup_scroll(state->pf1_tilemap, 256,(state->pf12_control[5]>>0)&0xff,(state->pf12_control[6]>>0)&0xff,state->pf12_control[2],state->pf12_control[1],state->pf1_rowscroll,state->pf1_rowscroll+0x200); |
| 1650 | deco32_setup_scroll(state->pf2_tilemap, 512,(state->pf12_control[5]>>8)&0xff,(state->pf12_control[6]>>8)&0xff,state->pf12_control[4],state->pf12_control[3],state->pf2_rowscroll,state->pf2_rowscroll+0x200); |
| 1651 | deco32_setup_scroll(state->pf3_tilemap, 512,(state->pf34_control[5]>>0)&0xff,(state->pf34_control[6]>>0)&0xff,state->pf34_control[2],state->pf34_control[1],state->pf3_rowscroll,state->pf3_rowscroll+0x200); |
| 1652 | deco32_setup_scroll(state->pf4_tilemap, 512,(state->pf34_control[5]>>8)&0xff,(state->pf34_control[6]>>8)&0xff,state->pf34_control[4],state->pf34_control[3],state->pf4_rowscroll,state->pf4_rowscroll+0x200); |
| 1642 | 1653 | |
| 1643 | 1654 | /* Enable registers */ |
| 1644 | | tilemap_set_enable(pf1_tilemap, deco32_pf12_control[5]&0x0080); |
| 1645 | | tilemap_set_enable(pf2_tilemap, deco32_pf12_control[5]&0x8000); |
| 1646 | | tilemap_set_enable(pf3_tilemap, deco32_pf34_control[5]&0x0080); |
| 1647 | | tilemap_set_enable(pf4_tilemap, deco32_pf34_control[5]&0x8000); |
| 1655 | tilemap_set_enable(state->pf1_tilemap, state->pf12_control[5]&0x0080); |
| 1656 | tilemap_set_enable(state->pf2_tilemap, state->pf12_control[5]&0x8000); |
| 1657 | tilemap_set_enable(state->pf3_tilemap, state->pf34_control[5]&0x0080); |
| 1658 | tilemap_set_enable(state->pf4_tilemap, state->pf34_control[5]&0x8000); |
| 1648 | 1659 | |
| 1649 | 1660 | /* This is not a conclusive test for deciding if tilemap needs alpha blending */ |
| 1650 | | if (deco32_ace_ram[0x17]!=0x0 && deco32_pri) |
| 1661 | if (state->ace_ram[0x17]!=0x0 && state->pri) |
| 1651 | 1662 | alphaTilemap=1; |
| 1652 | 1663 | |
| 1653 | | if (deco32_ace_ram_dirty) |
| 1664 | if (state->ace_ram_dirty) |
| 1654 | 1665 | updateAceRam(screen->machine); |
| 1655 | 1666 | |
| 1656 | | bitmap_fill(sprite0_mix_bitmap,cliprect,0); |
| 1657 | | bitmap_fill(sprite1_mix_bitmap,cliprect,0); |
| 1667 | bitmap_fill(state->sprite0_mix_bitmap,cliprect,0); |
| 1668 | bitmap_fill(state->sprite1_mix_bitmap,cliprect,0); |
| 1658 | 1669 | bitmap_fill(screen->machine->priority_bitmap,cliprect,0); |
| 1659 | | if ((deco32_pf34_control[5]&0x8000)==0) |
| 1670 | if ((state->pf34_control[5]&0x8000)==0) |
| 1660 | 1671 | bitmap_fill(bitmap,cliprect,screen->machine->pens[0x200]); |
| 1661 | 1672 | |
| 1662 | 1673 | /* Draw sprites to temporary bitmaps, saving alpha & priority info for later mixing */ |
| 1663 | | nslasher_draw_sprites(screen->machine,sprite0_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3); |
| 1664 | | nslasher_draw_sprites(screen->machine,sprite1_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram2.u32,4); |
| 1674 | nslasher_draw_sprites(screen->machine,state->sprite0_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram.u32,3); |
| 1675 | nslasher_draw_sprites(screen->machine,state->sprite1_mix_bitmap,cliprect,screen->machine->generic.buffered_spriteram2.u32,4); |
| 1665 | 1676 | |
| 1666 | 1677 | /* Render alpha-blended tilemap to seperate buffer for proper mixing */ |
| 1667 | | bitmap_fill(tilemap_alpha_bitmap,cliprect,0); |
| 1678 | bitmap_fill(state->tilemap_alpha_bitmap,cliprect,0); |
| 1668 | 1679 | |
| 1669 | 1680 | /* Draw playfields & sprites */ |
| 1670 | | if (deco32_pri&2) |
| 1681 | if (state->pri&2) |
| 1671 | 1682 | { |
| 1672 | 1683 | combined_tilemap_draw(screen->machine,bitmap,cliprect); |
| 1673 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,4); |
| 1684 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,4); |
| 1674 | 1685 | } |
| 1675 | 1686 | else |
| 1676 | 1687 | { |
| 1677 | | tilemap_draw(bitmap,cliprect,pf4_tilemap,0,1); |
| 1678 | | if (deco32_pri&1) |
| 1688 | tilemap_draw(bitmap,cliprect,state->pf4_tilemap,0,1); |
| 1689 | if (state->pri&1) |
| 1679 | 1690 | { |
| 1680 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,2); |
| 1691 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,2); |
| 1681 | 1692 | if (alphaTilemap) |
| 1682 | | tilemap_draw(tilemap_alpha_bitmap,cliprect,pf3_tilemap,0,4); |
| 1693 | tilemap_draw(state->tilemap_alpha_bitmap,cliprect,state->pf3_tilemap,0,4); |
| 1683 | 1694 | else |
| 1684 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,4); |
| 1695 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,4); |
| 1685 | 1696 | } |
| 1686 | 1697 | else |
| 1687 | 1698 | { |
| 1688 | | tilemap_draw(bitmap,cliprect,pf3_tilemap,0,2); |
| 1699 | tilemap_draw(bitmap,cliprect,state->pf3_tilemap,0,2); |
| 1689 | 1700 | if (alphaTilemap) |
| 1690 | | tilemap_draw(tilemap_alpha_bitmap,cliprect,pf2_tilemap,0,4); |
| 1701 | tilemap_draw(state->tilemap_alpha_bitmap,cliprect,state->pf2_tilemap,0,4); |
| 1691 | 1702 | else |
| 1692 | | tilemap_draw(bitmap,cliprect,pf2_tilemap,0,4); |
| 1703 | tilemap_draw(bitmap,cliprect,state->pf2_tilemap,0,4); |
| 1693 | 1704 | } |
| 1694 | 1705 | } |
| 1695 | 1706 | |
| 1696 | 1707 | mixDualAlphaSprites(bitmap, cliprect, screen->machine->gfx[3], screen->machine->gfx[4], alphaTilemap); |
| 1697 | 1708 | |
| 1698 | | tilemap_draw(bitmap,cliprect,pf1_tilemap,0,0); |
| 1709 | tilemap_draw(bitmap,cliprect,state->pf1_tilemap,0,0); |
| 1699 | 1710 | return 0; |
| 1700 | 1711 | } |
src/mame/video/model1.c
| r10427 | r10428 | |
| 7 | 7 | |
| 8 | 8 | #define LOG_TGP(x) do { if (LOG_TGP_VIDEO) logerror x; } while (0) |
| 9 | 9 | |
| 10 | | UINT16 *model1_display_list0, *model1_display_list1; |
| 11 | | UINT16 *model1_color_xlat; |
| 12 | | static UINT16 listctl[2]; |
| 13 | | static UINT16 *glist; |
| 14 | 10 | |
| 15 | 11 | // Model 1 geometrizer TGP and rasterizer simulation |
| 16 | 12 | enum { FRAC_SHIFT = 16 }; |
| 13 | enum { MOIRE = 0x00010000 }; |
| 17 | 14 | |
| 18 | | static int render_done; |
| 19 | | static UINT16 *tgp_ram; |
| 20 | | static float trans_mat[12]; |
| 21 | | static UINT16 *paletteram16; |
| 22 | 15 | |
| 23 | | static float vxx, vyy, vzz, ayy, ayyc, ayys; |
| 24 | 16 | |
| 25 | 17 | struct vector { |
| 26 | 18 | float x, y, z; |
| 27 | 19 | }; |
| 28 | 20 | |
| 29 | | static struct { |
| 21 | struct lightparam { |
| 22 | float a; |
| 23 | float d; |
| 24 | float s; |
| 25 | int p; |
| 26 | }; |
| 27 | |
| 28 | struct view { |
| 30 | 29 | int xc, yc, x1, y1, x2, y2; |
| 31 | 30 | float zoomx, zoomy, transx, transy; |
| 32 | 31 | float a_bottom, a_top, a_left, a_right; |
| 32 | float vxx, vyy, vzz, ayy, ayyc, ayys; |
| 33 | float trans_mat[12]; |
| 33 | 34 | struct vector light; |
| 34 | | } view; |
| 35 | struct lightparam lightparams[32]; |
| 36 | }; |
| 35 | 37 | |
| 36 | 38 | struct spoint { |
| 37 | 39 | INT32 x, y; |
| r10427 | r10428 | |
| 43 | 45 | struct spoint s; |
| 44 | 46 | }; |
| 45 | 47 | |
| 46 | | static struct lightparam |
| 47 | | { |
| 48 | | float a; |
| 49 | | float d; |
| 50 | | float s; |
| 51 | | int p; |
| 52 | | } lightparams[32]; |
| 53 | 48 | |
| 54 | | enum { MOIRE = 0x00010000 }; |
| 55 | | |
| 56 | 49 | struct quad_m1 { |
| 57 | 50 | struct point *p[4]; |
| 58 | 51 | float z; |
| 59 | 52 | int col; |
| 60 | 53 | }; |
| 61 | 54 | |
| 62 | | static struct point *pointdb, *pointpt; |
| 63 | | static struct quad_m1 *quaddb, *quadpt; |
| 64 | | static struct quad_m1 **quadind; |
| 65 | 55 | |
| 66 | | static UINT32 *poly_rom,*poly_ram; |
| 67 | 56 | |
| 68 | 57 | static UINT32 readi(const UINT16 *adr) |
| 69 | 58 | { |
| r10427 | r10428 | |
| 80 | 69 | return u2f(readi(adr)); |
| 81 | 70 | } |
| 82 | 71 | |
| 83 | | static void transform_point(struct point *p) |
| 72 | static void transform_point(struct view *view, struct point *p) |
| 84 | 73 | { |
| 85 | 74 | struct point q = *p; |
| 75 | float *trans = view->trans_mat; |
| 86 | 76 | float xx, zz; |
| 87 | | xx = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z+trans_mat[9]+vxx; |
| 88 | | p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z+trans_mat[10]+vyy; |
| 89 | | zz = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z+trans_mat[11]+vzz; |
| 90 | | p->x = ayyc*xx-ayys*zz; |
| 91 | | p->z = ayys*xx+ayyc*zz; |
| 77 | xx = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z+trans[9]+view->vxx; |
| 78 | p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z+trans[10]+view->vyy; |
| 79 | zz = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z+trans[11]+view->vzz; |
| 80 | p->x = view->ayyc*xx-view->ayys*zz; |
| 81 | p->z = view->ayys*xx+view->ayyc*zz; |
| 92 | 82 | } |
| 93 | 83 | |
| 94 | | static void transform_vector(struct vector *p) |
| 84 | static void transform_vector(struct view *view, struct vector *p) |
| 95 | 85 | { |
| 96 | 86 | struct vector q = *p; |
| 97 | | p->x = trans_mat[0]*q.x+trans_mat[3]*q.y+trans_mat[6]*q.z; |
| 98 | | p->y = trans_mat[1]*q.x+trans_mat[4]*q.y+trans_mat[7]*q.z; |
| 99 | | p->z = trans_mat[2]*q.x+trans_mat[5]*q.y+trans_mat[8]*q.z; |
| 87 | float *trans = view->trans_mat; |
| 88 | p->x = trans[0]*q.x+trans[3]*q.y+trans[6]*q.z; |
| 89 | p->y = trans[1]*q.x+trans[4]*q.y+trans[7]*q.z; |
| 90 | p->z = trans[2]*q.x+trans[5]*q.y+trans[8]*q.z; |
| 100 | 91 | } |
| 101 | 92 | |
| 102 | 93 | static void normalize_vector(struct vector *p) |
| r10427 | r10428 | |
| 127 | 118 | } |
| 128 | 119 | |
| 129 | 120 | |
| 130 | | static void project_point(struct point *p) |
| 121 | static void project_point(struct view *view, struct point *p) |
| 131 | 122 | { |
| 132 | 123 | p->xx = p->x / p->z; |
| 133 | 124 | p->yy = p->y / p->z; |
| 134 | | p->s.x = view.xc+(p->xx*view.zoomx+view.transx); |
| 135 | | p->s.y = view.yc-(p->yy*view.zoomy+view.transy); |
| 125 | p->s.x = view->xc+(p->xx*view->zoomx+view->transx); |
| 126 | p->s.y = view->yc-(p->yy*view->zoomy+view->transy); |
| 136 | 127 | } |
| 137 | 128 | |
| 138 | | static void project_point_direct(struct point *p) |
| 129 | static void project_point_direct(struct view *view, struct point *p) |
| 139 | 130 | { |
| 140 | 131 | p->xx = p->x /*/ p->z*/; |
| 141 | 132 | p->yy = p->y /*/ p->z*/; |
| 142 | | p->s.x = view.xc+(p->xx); |
| 143 | | p->s.y = view.yc-(p->yy); |
| 133 | p->s.x = view->xc+(p->xx); |
| 134 | p->s.y = view->yc-(p->yy); |
| 144 | 135 | } |
| 145 | 136 | |
| 146 | 137 | |
| r10427 | r10428 | |
| 163 | 154 | } |
| 164 | 155 | } |
| 165 | 156 | |
| 166 | | static void fill_slope(bitmap_t *bitmap, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) |
| 157 | static void fill_slope(bitmap_t *bitmap, struct view *view, int color, INT32 x1, INT32 x2, INT32 sl1, INT32 sl2, INT32 y1, INT32 y2, INT32 *nx1, INT32 *nx2) |
| 167 | 158 | { |
| 168 | | if(y1 > view.y2) |
| 159 | if(y1 > view->y2) |
| 169 | 160 | return; |
| 170 | 161 | |
| 171 | | if(y2 <= view.y1) { |
| 162 | if(y2 <= view->y1) { |
| 172 | 163 | int delta = y2-y1; |
| 173 | 164 | *nx1 = x1+delta*sl1; |
| 174 | 165 | *nx2 = x2+delta*sl2; |
| 175 | 166 | return; |
| 176 | 167 | } |
| 177 | 168 | |
| 178 | | if(y2 > view.y2) |
| 179 | | y2 = view.y2+1; |
| 169 | if(y2 > view->y2) |
| 170 | y2 = view->y2+1; |
| 180 | 171 | |
| 181 | | if(y1 < view.y1) { |
| 182 | | int delta = view.y1 - y1; |
| 172 | if(y1 < view->y1) { |
| 173 | int delta = view->y1 - y1; |
| 183 | 174 | x1 += delta*sl1; |
| 184 | 175 | x2 += delta*sl2; |
| 185 | | y1 = view.y1; |
| 176 | y1 = view->y1; |
| 186 | 177 | } |
| 187 | 178 | |
| 188 | 179 | if(x1 > x2 || (x1==x2 && sl1 > sl2)) { |
| r10427 | r10428 | |
| 199 | 190 | } |
| 200 | 191 | |
| 201 | 192 | while(y1 < y2) { |
| 202 | | if(y1 >= view.y1) { |
| 193 | if(y1 >= view->y1) { |
| 203 | 194 | int xx1 = x1>>FRAC_SHIFT; |
| 204 | 195 | int xx2 = x2>>FRAC_SHIFT; |
| 205 | | if(xx1 <= view.x2 || xx2 >= view.x1) { |
| 206 | | if(xx1 < view.x1) |
| 207 | | xx1 = view.x1; |
| 208 | | if(xx2 > view.x2) |
| 209 | | xx2 = view.x2; |
| 196 | if(xx1 <= view->x2 || xx2 >= view->x1) { |
| 197 | if(xx1 < view->x1) |
| 198 | xx1 = view->x1; |
| 199 | if(xx2 > view->x2) |
| 200 | xx2 = view->x2; |
| 210 | 201 | |
| 211 | 202 | if(color & MOIRE) |
| 212 | 203 | draw_hline_moired(bitmap, xx1, xx2, y1, color); |
| r10427 | r10428 | |
| 223 | 214 | *nx2 = x2; |
| 224 | 215 | } |
| 225 | 216 | |
| 226 | | static void fill_line(bitmap_t *bitmap, int color, INT32 y, INT32 x1, INT32 x2) |
| 217 | static void fill_line(bitmap_t *bitmap, struct view *view, int color, INT32 y, INT32 x1, INT32 x2) |
| 227 | 218 | { |
| 228 | 219 | int xx1 = x1>>FRAC_SHIFT; |
| 229 | 220 | int xx2 = x2>>FRAC_SHIFT; |
| 230 | 221 | |
| 231 | | if(y > view.y2 || y < view.y1) |
| 222 | if(y > view->y2 || y < view->y1) |
| 232 | 223 | return; |
| 233 | 224 | |
| 234 | | if(xx1 <= view.x2 || xx2 >= view.x1) { |
| 235 | | if(xx1 < view.x1) |
| 236 | | xx1 = view.x1; |
| 237 | | if(xx2 > view.x2) |
| 238 | | xx2 = view.x2; |
| 225 | if(xx1 <= view->x2 || xx2 >= view->x1) { |
| 226 | if(xx1 < view->x1) |
| 227 | xx1 = view->x1; |
| 228 | if(xx2 > view->x2) |
| 229 | xx2 = view->x2; |
| 239 | 230 | |
| 240 | 231 | if(color & MOIRE) |
| 241 | 232 | draw_hline_moired(bitmap, xx1, xx2, y, color); |
| r10427 | r10428 | |
| 244 | 235 | } |
| 245 | 236 | } |
| 246 | 237 | |
| 247 | | static void fill_quad(bitmap_t *bitmap, const struct quad_m1 *q) |
| 238 | static void fill_quad(bitmap_t *bitmap, struct view *view, const struct quad_m1 *q) |
| 248 | 239 | { |
| 249 | 240 | INT32 sl1, sl2, cury, limy, x1, x2; |
| 250 | 241 | int pmin, pmax, i, ps1, ps2; |
| r10427 | r10428 | |
| 284 | 275 | if(p[i].x > x2) |
| 285 | 276 | x2 = p[i].x; |
| 286 | 277 | } |
| 287 | | fill_line(bitmap, color, cury, x1, x2); |
| 278 | fill_line(bitmap, view, color, cury, x1, x2); |
| 288 | 279 | return; |
| 289 | 280 | } |
| 290 | 281 | |
| 291 | | if(cury > view.y2) |
| 282 | if(cury > view->y2) |
| 292 | 283 | return; |
| 293 | | if(limy <= view.y1) |
| 284 | if(limy <= view->y1) |
| 294 | 285 | return; |
| 295 | 286 | |
| 296 | | if(limy > view.y2) |
| 297 | | limy = view.y2; |
| 287 | if(limy > view->y2) |
| 288 | limy = view->y2; |
| 298 | 289 | |
| 299 | 290 | ps1 = pmin+4; |
| 300 | 291 | ps2 = pmin; |
| r10427 | r10428 | |
| 303 | 294 | |
| 304 | 295 | for(;;) { |
| 305 | 296 | if(p[ps1-1].y == p[ps2+1].y) { |
| 306 | | fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); |
| 297 | fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); |
| 307 | 298 | cury = p[ps1-1].y; |
| 308 | 299 | if(cury >= limy) |
| 309 | 300 | break; |
| r10427 | r10428 | |
| 320 | 311 | sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y); |
| 321 | 312 | sl2 = (x2-p[ps2+1].x)/(cury-p[ps2+1].y); |
| 322 | 313 | } else if(p[ps1-1].y < p[ps2+1].y) { |
| 323 | | fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); |
| 314 | fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps1-1].y, &x1, &x2); |
| 324 | 315 | cury = p[ps1-1].y; |
| 325 | 316 | if(cury >= limy) |
| 326 | 317 | break; |
| r10427 | r10428 | |
| 330 | 321 | x1 = p[ps1].x; |
| 331 | 322 | sl1 = (x1-p[ps1-1].x)/(cury-p[ps1-1].y); |
| 332 | 323 | } else { |
| 333 | | fill_slope(bitmap, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2); |
| 324 | fill_slope(bitmap, view, color, x1, x2, sl1, sl2, cury, p[ps2+1].y, &x1, &x2); |
| 334 | 325 | cury = p[ps2+1].y; |
| 335 | 326 | if(cury >= limy) |
| 336 | 327 | break; |
| r10427 | r10428 | |
| 342 | 333 | } |
| 343 | 334 | } |
| 344 | 335 | if(cury == limy) |
| 345 | | fill_line(bitmap, color, cury, x1, x2); |
| 336 | fill_line(bitmap, view, color, cury, x1, x2); |
| 346 | 337 | } |
| 347 | 338 | #if 0 |
| 348 | | static void draw_line(bitmap_t *bitmap, int color, int x1, int y1, int x2, int y2) |
| 339 | static void draw_line(bitmap_t *bitmap, struct view *view, int color, int x1, int y1, int x2, int y2) |
| 349 | 340 | { |
| 350 | 341 | int s1x, s1y, s2x, s2y; |
| 351 | 342 | int d1, d2; |
| 352 | 343 | int cur; |
| 353 | 344 | int x, y; |
| 354 | 345 | |
| 355 | | if((x1 < view.x1 && x2 < view.x1) || |
| 356 | | (x1 > view.x2 && x2 > view.x2) || |
| 357 | | (y1 < view.y1 && y2 < view.y1) || |
| 358 | | (y1 > view.y2 && y2 > view.y2)) |
| 346 | if((x1 < view->x1 && x2 < view->x1) || |
| 347 | (x1 > view->x2 && x2 > view->x2) || |
| 348 | (y1 < view->y1 && y2 < view->y1) || |
| 349 | (y1 > view->y2 && y2 > view->y2)) |
| 359 | 350 | return; |
| 360 | 351 | |
| 361 | 352 | x = x1; |
| r10427 | r10428 | |
| 393 | 384 | |
| 394 | 385 | cur = 0; |
| 395 | 386 | while(x != x2 || y != y2) { |
| 396 | | if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2) |
| 387 | if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2) |
| 397 | 388 | *BITMAP_ADDR16(bitmap, y, x) = color; |
| 398 | 389 | x += s1x; |
| 399 | 390 | y += s1y; |
| r10427 | r10428 | |
| 404 | 395 | y += s2y; |
| 405 | 396 | } |
| 406 | 397 | } |
| 407 | | if(x>=view.x1 && x<=view.x2 && y>=view.y1 && y<=view.y2) |
| 398 | if(x>=view->x1 && x<=view->x2 && y>=view->y1 && y<=view->y2) |
| 408 | 399 | *BITMAP_ADDR16(bitmap, y, x) = color; |
| 409 | 400 | } |
| 410 | 401 | #endif |
| r10427 | r10428 | |
| 418 | 409 | if(z1>z2) |
| 419 | 410 | return -1; |
| 420 | 411 | |
| 421 | | if (*(const struct quad_m1 **)q1 - quaddb < *(const struct quad_m1 **)q2 - quaddb) |
| 412 | if (*(const struct quad_m1 **)q1 - *(const struct quad_m1 **)q2 < 0) |
| 422 | 413 | return -1; |
| 423 | 414 | |
| 424 | 415 | return +1; |
| 425 | 416 | } |
| 426 | 417 | |
| 427 | | static void sort_quads(void) |
| 418 | static void sort_quads(model1_state *state) |
| 428 | 419 | { |
| 429 | | int count = quadpt - quaddb; |
| 420 | int count = state->quadpt - state->quaddb; |
| 430 | 421 | int i; |
| 431 | 422 | for(i=0; i<count; i++) |
| 432 | | quadind[i] = quaddb+i; |
| 433 | | qsort(quadind, count, sizeof(struct quad_m1 *), comp_quads); |
| 423 | state->quadind[i] = state->quaddb+i; |
| 424 | qsort(state->quadind, count, sizeof(struct quad_m1 *), comp_quads); |
| 434 | 425 | } |
| 435 | 426 | |
| 436 | | static void unsort_quads(void) |
| 427 | static void unsort_quads(model1_state *state) |
| 437 | 428 | { |
| 438 | | int count = quadpt - quaddb; |
| 429 | int count = state->quadpt - state->quaddb; |
| 439 | 430 | int i; |
| 440 | 431 | for(i=0; i<count; i++) |
| 441 | | quadind[i] = quaddb+i; |
| 432 | state->quadind[i] = state->quaddb+i; |
| 442 | 433 | } |
| 443 | 434 | |
| 444 | 435 | |
| 445 | | static void draw_quads(bitmap_t *bitmap, const rectangle *cliprect) |
| 436 | static void draw_quads(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect) |
| 446 | 437 | { |
| 447 | | int count = quadpt - quaddb; |
| 438 | struct view *view = state->view; |
| 439 | int count = state->quadpt - state->quaddb; |
| 448 | 440 | int i; |
| 449 | 441 | |
| 450 | 442 | /* clip to the cliprect */ |
| 451 | | int save_x1 = view.x1; |
| 452 | | int save_x2 = view.x2; |
| 453 | | int save_y1 = view.y1; |
| 454 | | int save_y2 = view.y2; |
| 455 | | view.x1 = MAX(view.x1, cliprect->min_x); |
| 456 | | view.x2 = MIN(view.x2, cliprect->max_x); |
| 457 | | view.y1 = MAX(view.y1, cliprect->min_y); |
| 458 | | view.y2 = MIN(view.y2, cliprect->max_y); |
| 443 | int save_x1 = view->x1; |
| 444 | int save_x2 = view->x2; |
| 445 | int save_y1 = view->y1; |
| 446 | int save_y2 = view->y2; |
| 447 | view->x1 = MAX(view->x1, cliprect->min_x); |
| 448 | view->x2 = MIN(view->x2, cliprect->max_x); |
| 449 | view->y1 = MAX(view->y1, cliprect->min_y); |
| 450 | view->y2 = MIN(view->y2, cliprect->max_y); |
| 459 | 451 | |
| 460 | 452 | for(i=0; i<count; i++) { |
| 461 | | struct quad_m1 *q = quadind[i]; |
| 453 | struct quad_m1 *q = state->quadind[i]; |
| 462 | 454 | |
| 463 | | fill_quad(bitmap, q); |
| 455 | fill_quad(bitmap, view, q); |
| 464 | 456 | #if 0 |
| 465 | 457 | draw_line(bitmap, get_black_pen(screen->machine), q->p[0]->s.x, q->p[0]->s.y, q->p[1]->s.x, q->p[1]->s.y); |
| 466 | 458 | draw_line(bitmap, get_black_pen(screen->machine), q->p[1]->s.x, q->p[1]->s.y, q->p[2]->s.x, q->p[2]->s.y); |
| r10427 | r10428 | |
| 469 | 461 | #endif |
| 470 | 462 | } |
| 471 | 463 | |
| 472 | | view.x1 = save_x1; |
| 473 | | view.x2 = save_x2; |
| 474 | | view.y1 = save_y1; |
| 475 | | view.y2 = save_y2; |
| 464 | view->x1 = save_x1; |
| 465 | view->x2 = save_x2; |
| 466 | view->y1 = save_y1; |
| 467 | view->y2 = save_y2; |
| 476 | 468 | } |
| 477 | 469 | #if 0 |
| 478 | 470 | static UINT16 scale_color(UINT16 color, float level) |
| r10427 | r10428 | |
| 500 | 492 | // => t*(x1-x2+a*(z2-z1) = -x2+a*z2 |
| 501 | 493 | // => t = (z2*a-x2)/((z2-z1)*a-(x2-x1)) |
| 502 | 494 | |
| 503 | | static void recompute_frustrum(void) |
| 495 | static void recompute_frustrum(struct view *view) |
| 504 | 496 | { |
| 505 | | view.a_left = ( view.x1-view.xc-view.transx)/view.zoomx; |
| 506 | | view.a_right = ( view.x2-view.xc-view.transx)/view.zoomx; |
| 507 | | view.a_bottom = (-view.y1+view.yc-view.transy)/view.zoomy; |
| 508 | | view.a_top = (-view.y2+view.yc-view.transy)/view.zoomy; |
| 497 | view->a_left = ( view->x1-view->xc-view->transx)/view->zoomx; |
| 498 | view->a_right = ( view->x2-view->xc-view->transx)/view->zoomx; |
| 499 | view->a_bottom = (-view->y1+view->yc-view->transy)/view->zoomy; |
| 500 | view->a_top = (-view->y2+view->yc-view->transy)/view->zoomy; |
| 509 | 501 | } |
| 510 | 502 | |
| 511 | | static int fclip_isc_bottom(struct point *p) |
| 503 | static int fclip_isc_bottom(struct view *view, struct point *p) |
| 512 | 504 | { |
| 513 | | return p->y > p->z*view.a_bottom; |
| 505 | return p->y > p->z*view->a_bottom; |
| 514 | 506 | } |
| 515 | 507 | |
| 516 | | static struct point *fclip_clip_bottom(struct point *p1, struct point *p2) |
| 508 | static void fclip_clip_bottom(struct view *view, struct point *pt, struct point *p1, struct point *p2) |
| 517 | 509 | { |
| 518 | | float t = (p2->z*view.a_bottom-p2->y)/((p2->z-p1->z)*view.a_bottom-(p2->y-p1->y)); |
| 519 | | pointpt->x = p1->x*t + p2->x*(1-t); |
| 520 | | pointpt->y = p1->y*t + p2->y*(1-t); |
| 521 | | pointpt->z = p1->z*t + p2->z*(1-t); |
| 522 | | project_point(pointpt); |
| 523 | | return pointpt++; |
| 510 | float t = (p2->z*view->a_bottom-p2->y)/((p2->z-p1->z)*view->a_bottom-(p2->y-p1->y)); |
| 511 | pt->x = p1->x*t + p2->x*(1-t); |
| 512 | pt->y = p1->y*t + p2->y*(1-t); |
| 513 | pt->z = p1->z*t + p2->z*(1-t); |
| 514 | project_point(view, pt); |
| 524 | 515 | } |
| 525 | 516 | |
| 526 | | static int fclip_isc_top(struct point *p) |
| 517 | static int fclip_isc_top(struct view *view, struct point *p) |
| 527 | 518 | { |
| 528 | | return p->y < p->z*view.a_top; |
| 519 | return p->y < p->z*view->a_top; |
| 529 | 520 | } |
| 530 | 521 | |
| 531 | | static struct point *fclip_clip_top(struct point *p1, struct point *p2) |
| 522 | static void fclip_clip_top(struct view *view, struct point *pt, struct point *p1, struct point *p2) |
| 532 | 523 | { |
| 533 | | float t = (p2->z*view.a_top-p2->y)/((p2->z-p1->z)*view.a_top-(p2->y-p1->y)); |
| 534 | | pointpt->x = p1->x*t + p2->x*(1-t); |
| 535 | | pointpt->y = p1->y*t + p2->y*(1-t); |
| 536 | | pointpt->z = p1->z*t + p2->z*(1-t); |
| 537 | | project_point(pointpt); |
| 538 | | return pointpt++; |
| 524 | float t = (p2->z*view->a_top-p2->y)/((p2->z-p1->z)*view->a_top-(p2->y-p1->y)); |
| 525 | pt->x = p1->x*t + p2->x*(1-t); |
| 526 | pt->y = p1->y*t + p2->y*(1-t); |
| 527 | pt->z = p1->z*t + p2->z*(1-t); |
| 528 | project_point(view, pt); |
| 539 | 529 | } |
| 540 | 530 | |
| 541 | | static int fclip_isc_left(struct point *p) |
| 531 | static int fclip_isc_left(struct view *view, struct point *p) |
| 542 | 532 | { |
| 543 | | return p->x < p->z*view.a_left; |
| 533 | return p->x < p->z*view->a_left; |
| 544 | 534 | } |
| 545 | 535 | |
| 546 | | static struct point *fclip_clip_left(struct point *p1, struct point *p2) |
| 536 | static void fclip_clip_left(struct view *view, struct point *pt, struct point *p1, struct point *p2) |
| 547 | 537 | { |
| 548 | | float t = (p2->z*view.a_left-p2->x)/((p2->z-p1->z)*view.a_left-(p2->x-p1->x)); |
| 549 | | pointpt->x = p1->x*t + p2->x*(1-t); |
| 550 | | pointpt->y = p1->y*t + p2->y*(1-t); |
| 551 | | pointpt->z = p1->z*t + p2->z*(1-t); |
| 552 | | project_point(pointpt); |
| 553 | | return pointpt++; |
| 538 | float t = (p2->z*view->a_left-p2->x)/((p2->z-p1->z)*view->a_left-(p2->x-p1->x)); |
| 539 | pt->x = p1->x*t + p2->x*(1-t); |
| 540 | pt->y = p1->y*t + p2->y*(1-t); |
| 541 | pt->z = p1->z*t + p2->z*(1-t); |
| 542 | project_point(view, pt); |
| 554 | 543 | } |
| 555 | 544 | |
| 556 | | static int fclip_isc_right(struct point *p) |
| 545 | static int fclip_isc_right(struct view *view, struct point *p) |
| 557 | 546 | { |
| 558 | | return p->x > p->z*view.a_right; |
| 547 | return p->x > p->z*view->a_right; |
| 559 | 548 | } |
| 560 | 549 | |
| 561 | | static struct point *fclip_clip_right(struct point *p1, struct point *p2) |
| 550 | static void fclip_clip_right(struct view *view, struct point *pt, struct point *p1, struct point *p2) |
| 562 | 551 | { |
| 563 | | float t = (p2->z*view.a_right-p2->x)/((p2->z-p1->z)*view.a_right-(p2->x-p1->x)); |
| 564 | | pointpt->x = p1->x*t + p2->x*(1-t); |
| 565 | | pointpt->y = p1->y*t + p2->y*(1-t); |
| 566 | | pointpt->z = p1->z*t + p2->z*(1-t); |
| 567 | | project_point(pointpt); |
| 568 | | return pointpt++; |
| 552 | float t = (p2->z*view->a_right-p2->x)/((p2->z-p1->z)*view->a_right-(p2->x-p1->x)); |
| 553 | pt->x = p1->x*t + p2->x*(1-t); |
| 554 | pt->y = p1->y*t + p2->y*(1-t); |
| 555 | pt->z = p1->z*t + p2->z*(1-t); |
| 556 | project_point(view, pt); |
| 569 | 557 | } |
| 570 | 558 | |
| 571 | 559 | static const struct { |
| 572 | | int (*isclipped)(struct point *p); |
| 573 | | struct point *(*clip)(struct point *p1, struct point *p2); |
| 560 | int (*isclipped)(struct view *view, struct point *p); |
| 561 | void (*clip)(struct view *view, struct point *pt, struct point *p1, struct point *p2); |
| 574 | 562 | } clipfn[4] = { |
| 575 | 563 | { fclip_isc_bottom, fclip_clip_bottom }, |
| 576 | 564 | { fclip_isc_top, fclip_clip_top }, |
| r10427 | r10428 | |
| 578 | 566 | { fclip_isc_right, fclip_clip_right }, |
| 579 | 567 | }; |
| 580 | 568 | |
| 581 | | static void fclip_push_quad(int level, struct quad_m1 *q); |
| 569 | static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q); |
| 582 | 570 | |
| 583 | | static void fclip_push_quad_next(int level, struct quad_m1 *q, |
| 571 | static void fclip_push_quad_next(model1_state *state, int level, struct quad_m1 *q, |
| 584 | 572 | struct point *p1, struct point *p2, struct point *p3, struct point *p4) |
| 585 | 573 | { |
| 586 | 574 | struct quad_m1 q2; |
| r10427 | r10428 | |
| 591 | 579 | q2.p[2] = p3; |
| 592 | 580 | q2.p[3] = p4; |
| 593 | 581 | |
| 594 | | fclip_push_quad(level+1, &q2); |
| 582 | fclip_push_quad(state, level+1, &q2); |
| 595 | 583 | } |
| 596 | 584 | |
| 597 | | static void fclip_push_quad(int level, struct quad_m1 *q) |
| 585 | static void fclip_push_quad(model1_state *state, int level, struct quad_m1 *q) |
| 598 | 586 | { |
| 587 | struct view *view = state->view; |
| 599 | 588 | int i, j; |
| 600 | 589 | struct point *pt[4], *pi1, *pi2; |
| 601 | 590 | int is_out[4], is_out2[4]; |
| 602 | | struct point *(*fclip_point)(struct point *p1, struct point *p2); |
| 591 | void (*fclip_point)(struct view *view, struct point *pt, struct point *p1, struct point *p2); |
| 603 | 592 | |
| 604 | 593 | if(level == 4) { |
| 605 | 594 | LOG_TGP(("VIDEOCQ %d", level)); |
| 606 | 595 | for(i=0; i<4; i++) |
| 607 | 596 | LOG_TGP((" (%f, %f, %f)", q->p[i]->x, q->p[i]->y, q->p[i]->z)); |
| 608 | 597 | LOG_TGP(("\n")); |
| 609 | | *quadpt = *q; |
| 610 | | quadpt++; |
| 598 | *state->quadpt = *q; |
| 599 | state->quadpt++; |
| 611 | 600 | return; |
| 612 | 601 | } |
| 613 | 602 | |
| 614 | 603 | for(i=0; i<4; i++) |
| 615 | | is_out[i] = clipfn[level].isclipped(q->p[i]); |
| 604 | is_out[i] = clipfn[level].isclipped(view, q->p[i]); |
| 616 | 605 | |
| 617 | 606 | LOG_TGP(("VIDEOCQ %d", level)); |
| 618 | 607 | for(i=0; i<4; i++) |
| r10427 | r10428 | |
| 621 | 610 | |
| 622 | 611 | // No clipping |
| 623 | 612 | if(!is_out[0] && !is_out[1] && !is_out[2] && !is_out[3]) { |
| 624 | | fclip_push_quad(level+1, q); |
| 613 | fclip_push_quad(state, level+1, q); |
| 625 | 614 | return; |
| 626 | 615 | } |
| 627 | 616 | |
| r10427 | r10428 | |
| 645 | 634 | if(is_out2[1]) |
| 646 | 635 | if(is_out2[2]) { |
| 647 | 636 | // pt 0,1,2 clipped out, one triangle left |
| 648 | | pi1 = fclip_point(pt[2], pt[3]); |
| 649 | | pi2 = fclip_point(pt[3], pt[0]); |
| 650 | | fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2); |
| 637 | fclip_point(view, state->pointpt, pt[2], pt[3]); |
| 638 | pi1 = state->pointpt++; |
| 639 | fclip_point(view, state->pointpt, pt[3], pt[0]); |
| 640 | pi2 = state->pointpt++; |
| 641 | fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2); |
| 651 | 642 | } else { |
| 652 | 643 | // pt 0,1 clipped out, one quad left |
| 653 | | pi1 = fclip_point(pt[1], pt[2]); |
| 654 | | pi2 = fclip_point(pt[3], pt[0]); |
| 655 | | fclip_push_quad_next(level, q, pi1, pt[2], pt[3], pi2); |
| 644 | fclip_point(view, state->pointpt, pt[1], pt[2]); |
| 645 | pi1 = state->pointpt++; |
| 646 | fclip_point(view, state->pointpt, pt[3], pt[0]); |
| 647 | pi2 = state->pointpt++; |
| 648 | fclip_push_quad_next(state, level, q, pi1, pt[2], pt[3], pi2); |
| 656 | 649 | } |
| 657 | 650 | else |
| 658 | 651 | if(is_out2[2]) { |
| 659 | 652 | // pt 0,2 clipped out, shouldn't happen, two triangles |
| 660 | | pi1 = fclip_point(pt[0], pt[1]); |
| 661 | | pi2 = fclip_point(pt[1], pt[2]); |
| 662 | | fclip_push_quad_next(level, q, pi1, pt[1], pi2, pi2); |
| 663 | | pi1 = fclip_point(pt[2], pt[3]); |
| 664 | | pi2 = fclip_point(pt[3], pt[0]); |
| 665 | | fclip_push_quad_next(level, q, pi1, pt[3], pi2, pi2); |
| 653 | fclip_point(view, state->pointpt, pt[0], pt[1]); |
| 654 | pi1 = state->pointpt++; |
| 655 | fclip_point(view, state->pointpt, pt[1], pt[2]); |
| 656 | pi2 = state->pointpt++; |
| 657 | fclip_push_quad_next(state, level, q, pi1, pt[1], pi2, pi2); |
| 658 | fclip_point(view, state->pointpt, pt[2], pt[3]); |
| 659 | pi1 = state->pointpt++; |
| 660 | fclip_point(view, state->pointpt, pt[3], pt[0]); |
| 661 | pi2 = state->pointpt++; |
| 662 | fclip_push_quad_next(state, level, q, pi1, pt[3], pi2, pi2); |
| 666 | 663 | } else { |
| 667 | 664 | // pt 0 clipped out, one decagon left, split in quad+tri |
| 668 | | pi1 = fclip_point(pt[0], pt[1]); |
| 669 | | pi2 = fclip_point(pt[3], pt[0]); |
| 670 | | fclip_push_quad_next(level, q, pi1, pt[1], pt[2], pt[3]); |
| 671 | | fclip_push_quad_next(level, q, pt[3], pi2, pi1, pi1); |
| 665 | fclip_point(view, state->pointpt, pt[0], pt[1]); |
| 666 | pi1 = state->pointpt++; |
| 667 | fclip_point(view, state->pointpt, pt[3], pt[0]); |
| 668 | pi2 = state->pointpt++; |
| 669 | fclip_push_quad_next(state, level, q, pi1, pt[1], pt[2], pt[3]); |
| 670 | fclip_push_quad_next(state, level, q, pt[3], pi2, pi1, pi1); |
| 672 | 671 | } |
| 673 | 672 | } |
| 674 | 673 | |
| r10427 | r10428 | |
| 703 | 702 | { |
| 704 | 703 | #if 0 |
| 705 | 704 | float s; |
| 706 | | int p=lightparams[lmode].p&7; |
| 705 | int p=view->lightparams[lmode].p&7; |
| 707 | 706 | int i; |
| 708 | | float sv=lightparams[lmode].s; |
| 707 | float sv=view->lightparams[lmode].s; |
| 709 | 708 | |
| 710 | 709 | //This is how it should be according to model2 geo program, but doesn't work fine |
| 711 | 710 | s=2*(diffuse*normal->z-light->z); |
| r10427 | r10428 | |
| 727 | 726 | |
| 728 | 727 | static void push_object(running_machine *machine, UINT32 tex_adr, UINT32 poly_adr, UINT32 size) |
| 729 | 728 | { |
| 729 | model1_state *state = machine->driver_data<model1_state>(); |
| 730 | struct view *view = state->view; |
| 730 | 731 | int i; |
| 731 | 732 | UINT32 flags; |
| 732 | 733 | struct point *old_p0, *old_p1, *p0, *p1; |
| r10427 | r10428 | |
| 741 | 742 | float *poly_data; |
| 742 | 743 | |
| 743 | 744 | if(poly_adr & 0x800000) |
| 744 | | poly_data=(float *) poly_ram; |
| 745 | poly_data=(float *) state->poly_ram; |
| 745 | 746 | else |
| 746 | | poly_data=(float *) poly_rom; |
| 747 | poly_data=(float *) state->poly_rom; |
| 747 | 748 | |
| 748 | 749 | poly_adr &= 0x7fffff; |
| 749 | 750 | #if 0 |
| r10427 | r10428 | |
| 772 | 773 | if(!size) |
| 773 | 774 | size = 0xffffffff; |
| 774 | 775 | |
| 775 | | old_p0 = pointpt++; |
| 776 | | old_p1 = pointpt++; |
| 776 | old_p0 = state->pointpt++; |
| 777 | old_p1 = state->pointpt++; |
| 777 | 778 | |
| 778 | 779 | old_p0->x = poly_data[poly_adr+0]; |
| 779 | 780 | old_p0->y = poly_data[poly_adr+1]; |
| r10427 | r10428 | |
| 781 | 782 | old_p1->x = poly_data[poly_adr+3]; |
| 782 | 783 | old_p1->y = poly_data[poly_adr+4]; |
| 783 | 784 | old_p1->z = poly_data[poly_adr+5]; |
| 784 | | transform_point(old_p0); |
| 785 | | transform_point(old_p1); |
| 785 | transform_point(view, old_p0); |
| 786 | transform_point(view, old_p1); |
| 786 | 787 | if(old_p0->z > 0) |
| 787 | | project_point(old_p0); |
| 788 | project_point(view, old_p0); |
| 788 | 789 | else |
| 789 | 790 | old_p0->s.x = old_p0->s.y = 0; |
| 790 | 791 | if(old_p1->z > 0) |
| 791 | | project_point(old_p1); |
| 792 | project_point(view, old_p1); |
| 792 | 793 | else |
| 793 | 794 | old_p1->s.x = old_p1->s.y = 0; |
| 794 | 795 | |
| r10427 | r10428 | |
| 814 | 815 | tex_adr ++; |
| 815 | 816 | lightmode=(flags>>17)&15; |
| 816 | 817 | |
| 817 | | p0 = pointpt++; |
| 818 | | p1 = pointpt++; |
| 818 | p0 = state->pointpt++; |
| 819 | p1 = state->pointpt++; |
| 819 | 820 | |
| 820 | 821 | vn.x = poly_data[poly_adr+1]; |
| 821 | 822 | vn.y = poly_data[poly_adr+2]; |
| r10427 | r10428 | |
| 829 | 830 | |
| 830 | 831 | link = (flags >> 8) & 3; |
| 831 | 832 | |
| 832 | | transform_vector(&vn); |
| 833 | transform_vector(view, &vn); |
| 833 | 834 | |
| 834 | | transform_point(p0); |
| 835 | | transform_point(p1); |
| 835 | transform_point(view, p0); |
| 836 | transform_point(view, p1); |
| 836 | 837 | if(p0->z > 0) |
| 837 | | project_point(p0); |
| 838 | project_point(view, p0); |
| 838 | 839 | else |
| 839 | 840 | p0->s.x = p0->s.y = 0; |
| 840 | 841 | if(p1->z > 0) |
| 841 | | project_point(p1); |
| 842 | project_point(view, p1); |
| 842 | 843 | else |
| 843 | 844 | p1->s.x = p1->s.y = 0; |
| 844 | 845 | |
| r10427 | r10428 | |
| 892 | 893 | } |
| 893 | 894 | |
| 894 | 895 | { |
| 895 | | /*float dif=mult_vector(&vn, &view.light); |
| 896 | | float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif); |
| 897 | | cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); |
| 898 | | cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); |
| 899 | | */ |
| 900 | | float dif=mult_vector(&vn, &view.light); |
| 901 | | float spec=compute_specular(&vn,&view.light,dif,lightmode); |
| 902 | | float ln=lightparams[lightmode].a + lightparams[lightmode].d*MAX(0.0,dif) + spec; |
| 896 | #if 0 |
| 897 | float dif=mult_vector(&vn, &view->light); |
| 898 | float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif); |
| 899 | cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); |
| 900 | cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)], MIN(1.0,ln)); |
| 901 | #endif |
| 902 | float dif=mult_vector(&vn, &view->light); |
| 903 | float spec=compute_specular(&vn,&view->light,dif,lightmode); |
| 904 | float ln=view->lightparams[lightmode].a + view->lightparams[lightmode].d*MAX(0.0,dif) + spec; |
| 903 | 905 | int lumval=255.0*MIN(1.0,ln); |
| 904 | | int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)]; |
| 906 | int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)]; |
| 905 | 907 | int r=(color>>0x0)&0x1f; |
| 906 | 908 | int g=(color>>0x5)&0x1f; |
| 907 | 909 | int b=(color>>0xA)&0x1f; |
| 908 | 910 | lumval>>=2; //there must be a luma translation table somewhere |
| 909 | 911 | if(lumval>0x3f) lumval=0x3f; |
| 910 | 912 | else if(lumval<0) lumval=0; |
| 911 | | r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; |
| 912 | | g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; |
| 913 | | b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; |
| 913 | r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; |
| 914 | g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; |
| 915 | b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; |
| 914 | 916 | cquad.col=(r<<10)|(g<<5)|(b<<0); |
| 915 | 917 | } |
| 916 | 918 | |
| 917 | 919 | if(flags & 0x00002000) |
| 918 | 920 | cquad.col |= MOIRE; |
| 919 | 921 | |
| 920 | | fclip_push_quad(0, &cquad); |
| 922 | fclip_push_quad(state, 0, &cquad); |
| 921 | 923 | |
| 922 | 924 | next: |
| 923 | 925 | poly_adr += 10; |
| r10427 | r10428 | |
| 937 | 939 | } |
| 938 | 940 | } |
| 939 | 941 | |
| 940 | | static UINT16 *push_direct(UINT16 *list) |
| 942 | static UINT16 *push_direct(model1_state *state, UINT16 *list) |
| 941 | 943 | { |
| 944 | struct view *view = state->view; |
| 942 | 945 | UINT32 flags; |
| 943 | 946 | UINT32 tex_adr, lum, v1, v2; |
| 944 | 947 | struct point *old_p0, *old_p1, *p0, *p1; |
| r10427 | r10428 | |
| 950 | 953 | v1 = readi(list+2); |
| 951 | 954 | v2 = readi(list+10); |
| 952 | 955 | |
| 953 | | old_p0 = pointpt++; |
| 954 | | old_p1 = pointpt++; |
| 956 | old_p0 = state->pointpt++; |
| 957 | old_p1 = state->pointpt++; |
| 955 | 958 | |
| 956 | 959 | old_p0->x = readf(list+4); |
| 957 | 960 | old_p0->y = readf(list+6); |
| r10427 | r10428 | |
| 965 | 968 | old_p0->x, old_p0->y, old_p0->z, |
| 966 | 969 | old_p1->x, old_p1->y, old_p1->z)); |
| 967 | 970 | |
| 968 | | // transform_point(old_p0); |
| 969 | | // transform_point(old_p1); |
| 971 | //transform_point(view, old_p0); |
| 972 | //transform_point(view, old_p1); |
| 970 | 973 | if(old_p0->z > 0) |
| 971 | | project_point_direct(old_p0); |
| 974 | project_point_direct(view, old_p0); |
| 972 | 975 | else |
| 973 | 976 | old_p0->s.x = old_p0->s.y = 0; |
| 974 | 977 | if(old_p1->z > 0) |
| 975 | | project_point_direct(old_p1); |
| 978 | project_point_direct(view, old_p1); |
| 976 | 979 | else |
| 977 | 980 | old_p1->s.x = old_p1->s.y = 0; |
| 978 | 981 | |
| r10427 | r10428 | |
| 992 | 995 | // list+4 is 0? |
| 993 | 996 | // list+12 is z? |
| 994 | 997 | |
| 995 | | p0 = pointpt++; |
| 996 | | p1 = pointpt++; |
| 998 | p0 = state->pointpt++; |
| 999 | p1 = state->pointpt++; |
| 997 | 1000 | |
| 998 | 1001 | lum = readi(list+2); |
| 999 | 1002 | v1 = readi(list+4); |
| r10427 | r10428 | |
| 1025 | 1028 | |
| 1026 | 1029 | link = (flags >> 8) & 3; |
| 1027 | 1030 | |
| 1028 | | // transform_point(p0); |
| 1029 | | // transform_point(p1); |
| 1031 | //transform_point(view, p0); |
| 1032 | //transform_point(view, p1); |
| 1030 | 1033 | if(p0->z > 0) |
| 1031 | | project_point_direct(p0); |
| 1034 | project_point_direct(view, p0); |
| 1032 | 1035 | if(p1->z > 0) |
| 1033 | | project_point_direct(p1); |
| 1036 | project_point_direct(view, p1); |
| 1034 | 1037 | |
| 1035 | 1038 | #if 1 |
| 1036 | 1039 | if(old_p0 && old_p1) |
| r10427 | r10428 | |
| 1058 | 1061 | cquad.z = z; |
| 1059 | 1062 | { |
| 1060 | 1063 | int lumval=((float) (lum>>24)) * 2.0; |
| 1061 | | int color=paletteram16[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)]; |
| 1064 | int color=state->paletteram16[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)]; |
| 1062 | 1065 | int r=(color>>0x0)&0x1f; |
| 1063 | 1066 | int g=(color>>0x5)&0x1f; |
| 1064 | 1067 | int b=(color>>0xA)&0x1f; |
| 1065 | 1068 | lumval>>=2; //there must be a luma translation table somewhere |
| 1066 | 1069 | if(lumval>0x3f) lumval=0x3f; |
| 1067 | 1070 | else if(lumval<0) lumval=0; |
| 1068 | | r=(model1_color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; |
| 1069 | | g=(model1_color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; |
| 1070 | | b=(model1_color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; |
| 1071 | r=(state->color_xlat[(r<<8)|lumval|0x0]>>3)&0x1f; |
| 1072 | g=(state->color_xlat[(g<<8)|lumval|0x2000]>>3)&0x1f; |
| 1073 | b=(state->color_xlat[(b<<8)|lumval|0x4000]>>3)&0x1f; |
| 1071 | 1074 | cquad.col=(r<<10)|(g<<5)|(b<<0); |
| 1072 | 1075 | } |
| 1073 | | //cquad.col = scale_color(machine->pens[0x1000|(tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0); |
| 1076 | //cquad.col = scale_color(machine->pens[0x1000|(state->tgp_ram[tex_adr-0x40000] & 0x3ff)],((float) (lum>>24)) / 128.0); |
| 1074 | 1077 | if(flags & 0x00002000) |
| 1075 | 1078 | cquad.col |= MOIRE; |
| 1076 | 1079 | |
| 1077 | | fclip_push_quad(0, &cquad); |
| 1080 | fclip_push_quad(state, 0, &cquad); |
| 1078 | 1081 | |
| 1079 | 1082 | next: |
| 1080 | 1083 | switch(link) { |
| r10427 | r10428 | |
| 1116 | 1119 | return list+2; |
| 1117 | 1120 | } |
| 1118 | 1121 | |
| 1119 | | static void draw_objects(bitmap_t *bitmap, const rectangle *cliprect) |
| 1122 | static void draw_objects(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect) |
| 1120 | 1123 | { |
| 1121 | | if(quadpt != quaddb) { |
| 1124 | if(state->quadpt != state->quaddb) { |
| 1122 | 1125 | LOG_TGP(("VIDEO: sort&draw\n")); |
| 1123 | | sort_quads(); |
| 1124 | | draw_quads(bitmap, cliprect); |
| 1126 | sort_quads(state); |
| 1127 | draw_quads(state, bitmap, cliprect); |
| 1125 | 1128 | } |
| 1126 | 1129 | |
| 1127 | | quadpt = quaddb; |
| 1128 | | pointpt = pointdb; |
| 1130 | state->quadpt = state->quaddb; |
| 1131 | state->pointpt = state->pointdb; |
| 1129 | 1132 | } |
| 1130 | 1133 | |
| 1131 | | static UINT16 *draw_direct(UINT16 *list, bitmap_t *bitmap, const rectangle *cliprect) |
| 1134 | static UINT16 *draw_direct(model1_state *state, bitmap_t *bitmap, const rectangle *cliprect, UINT16 *list) |
| 1132 | 1135 | { |
| 1133 | 1136 | UINT16 *res; |
| 1134 | 1137 | |
| 1135 | 1138 | LOG_TGP(("VIDEO: draw direct %x\n", readi(list))); |
| 1136 | 1139 | |
| 1137 | | draw_objects(bitmap, cliprect); |
| 1138 | | res = push_direct(list); |
| 1139 | | unsort_quads(); |
| 1140 | | draw_quads(bitmap, cliprect); |
| 1140 | draw_objects(state, bitmap, cliprect); |
| 1141 | res = push_direct(state, list); |
| 1142 | unsort_quads(state); |
| 1143 | draw_quads(state, bitmap, cliprect); |
| 1141 | 1144 | |
| 1142 | | quadpt = quaddb; |
| 1143 | | pointpt = pointdb; |
| 1145 | state->quadpt = state->quaddb; |
| 1146 | state->pointpt = state->pointdb; |
| 1144 | 1147 | return res; |
| 1145 | 1148 | } |
| 1146 | 1149 | |
| 1147 | | static UINT16 *get_list(void) |
| 1150 | static UINT16 *get_list(model1_state *state) |
| 1148 | 1151 | { |
| 1149 | | if(!(listctl[0] & 4)) |
| 1150 | | listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0); |
| 1151 | | return listctl[0] & 0x40 ? model1_display_list1 : model1_display_list0; |
| 1152 | if(!(state->listctl[0] & 4)) |
| 1153 | state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0); |
| 1154 | return state->listctl[0] & 0x40 ? state->display_list1 : state->display_list0; |
| 1152 | 1155 | } |
| 1153 | 1156 | |
| 1154 | | static int get_list_number(void) |
| 1157 | static int get_list_number(model1_state *state) |
| 1155 | 1158 | { |
| 1156 | | if(!(listctl[0] & 4)) |
| 1157 | | listctl[0] = (listctl[0] & ~0x40) | (listctl[0] & 8 ? 0x40 : 0); |
| 1158 | | return listctl[0] & 0x40 ? 0 : 1; |
| 1159 | if(!(state->listctl[0] & 4)) |
| 1160 | state->listctl[0] = (state->listctl[0] & ~0x40) | (state->listctl[0] & 8 ? 0x40 : 0); |
| 1161 | return state->listctl[0] & 0x40 ? 0 : 1; |
| 1159 | 1162 | } |
| 1160 | 1163 | |
| 1161 | 1164 | static void end_frame(running_machine *machine) |
| 1162 | 1165 | { |
| 1163 | | if((listctl[0] & 4) && (machine->primary_screen->frame_number() & 1)) |
| 1164 | | listctl[0] ^= 0x40; |
| 1166 | model1_state *state = machine->driver_data<model1_state>(); |
| 1167 | if((state->listctl[0] & 4) && (machine->primary_screen->frame_number() & 1)) |
| 1168 | state->listctl[0] ^= 0x40; |
| 1165 | 1169 | } |
| 1166 | 1170 | |
| 1167 | 1171 | READ16_HANDLER( model1_listctl_r ) |
| 1168 | 1172 | { |
| 1173 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1169 | 1174 | if(!offset) |
| 1170 | | return listctl[0] | 0x30; |
| 1175 | return state->listctl[0] | 0x30; |
| 1171 | 1176 | else |
| 1172 | | return listctl[1]; |
| 1177 | return state->listctl[1]; |
| 1173 | 1178 | } |
| 1174 | 1179 | |
| 1175 | 1180 | WRITE16_HANDLER( model1_listctl_w ) |
| 1176 | 1181 | { |
| 1177 | | COMBINE_DATA(listctl+offset); |
| 1178 | | LOG_TGP(("VIDEO: control=%08x\n", (listctl[1]<<16)|listctl[0])); |
| 1182 | model1_state *state = space->machine->driver_data<model1_state>(); |
| 1183 | COMBINE_DATA(state->listctl+offset); |
| 1184 | LOG_TGP(("VIDEO: control=%08x\n", (state->listctl[1]<<16)|state->listctl[0])); |
| 1179 | 1185 | } |
| 1180 | 1186 | |
| 1181 | 1187 | static void tgp_render(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 1182 | 1188 | { |
| 1183 | | render_done = 1; |
| 1184 | | if((listctl[1] & 0x1f) == 0x1f) { |
| 1185 | | UINT16 *list = get_list(); |
| 1189 | model1_state *state = machine->driver_data<model1_state>(); |
| 1190 | struct view *view = state->view; |
| 1191 | state->render_done = 1; |
| 1192 | if((state->listctl[1] & 0x1f) == 0x1f) { |
| 1193 | UINT16 *list = get_list(state); |
| 1186 | 1194 | int zz = 0; |
| 1187 | | LOG_TGP(("VIDEO: render list %d\n", get_list_number())); |
| 1195 | LOG_TGP(("VIDEO: render list %d\n", get_list_number(state))); |
| 1188 | 1196 | |
| 1189 | | memset(trans_mat, 0, sizeof(trans_mat)); |
| 1190 | | trans_mat[0] = 1.0; |
| 1191 | | trans_mat[4] = 1.0; |
| 1192 | | trans_mat[8] = 1.0; |
| 1197 | memset(view->trans_mat, 0, sizeof(view->trans_mat)); |
| 1198 | view->trans_mat[0] = 1.0; |
| 1199 | view->trans_mat[4] = 1.0; |
| 1200 | view->trans_mat[8] = 1.0; |
| 1193 | 1201 | |
| 1194 | 1202 | for(;;) { |
| 1195 | 1203 | int type = (list[1]<<16)|list[0]; |
| 1196 | | glist=list; |
| 1204 | state->glist=list; |
| 1197 | 1205 | switch(type & 15) { |
| 1198 | 1206 | case 0: |
| 1199 | 1207 | list += 2; |
| r10427 | r10428 | |
| 1211 | 1219 | list += 8; |
| 1212 | 1220 | break; |
| 1213 | 1221 | case 2: |
| 1214 | | list = draw_direct(list+2, bitmap, cliprect); |
| 1222 | list = draw_direct(state, bitmap, cliprect, list+2); |
| 1215 | 1223 | break; |
| 1216 | 1224 | case 3: |
| 1217 | 1225 | LOG_TGP(("VIDEO: viewport (%d, %d, %d, %d, %d, %d, %d)\n", |
| r10427 | r10428 | |
| 1219 | 1227 | readi16(list+4), readi16(list+6), readi16(list+8), |
| 1220 | 1228 | readi16(list+10), readi16(list+12), readi16(list+14))); |
| 1221 | 1229 | |
| 1222 | | draw_objects(bitmap, cliprect); |
| 1230 | draw_objects(state, bitmap, cliprect); |
| 1223 | 1231 | |
| 1224 | | view.xc = readi16(list+4); |
| 1225 | | view.yc = 383-(readi16(list+6)-39); |
| 1226 | | view.x1 = readi16(list+8); |
| 1227 | | view.y2 = 383-(readi16(list+10)-39); |
| 1228 | | view.x2 = readi16(list+12); |
| 1229 | | view.y1 = 383-(readi16(list+14)-39); |
| 1232 | view->xc = readi16(list+4); |
| 1233 | view->yc = 383-(readi16(list+6)-39); |
| 1234 | view->x1 = readi16(list+8); |
| 1235 | view->y2 = 383-(readi16(list+10)-39); |
| 1236 | view->x2 = readi16(list+12); |
| 1237 | view->y1 = 383-(readi16(list+14)-39); |
| 1230 | 1238 | |
| 1231 | | recompute_frustrum(); |
| 1239 | recompute_frustrum(view); |
| 1232 | 1240 | |
| 1233 | 1241 | list += 16; |
| 1234 | 1242 | break; |
| r10427 | r10428 | |
| 1238 | 1246 | int i; |
| 1239 | 1247 | LOG_TGP(("ZVIDEO: color write, adr=%x, len=%x\n", adr, len)); |
| 1240 | 1248 | for(i=0; i<len; i++) |
| 1241 | | tgp_ram[adr-0x40000+i] = list[6+2*i]; |
| 1249 | state->tgp_ram[adr-0x40000+i] = list[6+2*i]; |
| 1242 | 1250 | list += 6+len*2; |
| 1243 | 1251 | break; |
| 1244 | 1252 | } |
| r10427 | r10428 | |
| 1249 | 1257 | int i; |
| 1250 | 1258 | for(i=0;i<len;++i) |
| 1251 | 1259 | { |
| 1252 | | poly_ram[adr-0x800000+i]=readi(list+2*i+6); |
| 1260 | state->poly_ram[adr-0x800000+i]=readi(list+2*i+6); |
| 1253 | 1261 | } |
| 1254 | 1262 | list+=6+len*2; |
| 1255 | 1263 | } |
| r10427 | r10428 | |
| 1262 | 1270 | for(i=0;i<len;++i) |
| 1263 | 1271 | { |
| 1264 | 1272 | int v=readi(list+6+i*2); |
| 1265 | | lightparams[i+adr].d=((float) (v&0xff))/255.0; |
| 1266 | | lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; |
| 1267 | | lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; |
| 1268 | | lightparams[i+adr].p=(v>>24)&0xff; |
| 1273 | view->lightparams[i+adr].d=((float) (v&0xff))/255.0; |
| 1274 | view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; |
| 1275 | view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; |
| 1276 | view->lightparams[i+adr].p=(v>>24)&0xff; |
| 1269 | 1277 | } |
| 1270 | 1278 | list += 6+len*2; |
| 1271 | 1279 | break; |
| r10427 | r10428 | |
| 1281 | 1289 | break; |
| 1282 | 1290 | case 9: |
| 1283 | 1291 | LOG_TGP(("VIDEO: zoom (%f, %f)\n", readf(list+2), readf(list+4))); |
| 1284 | | view.zoomx = readf(list+2)*4; |
| 1285 | | view.zoomy = readf(list+4)*4; |
| 1292 | view->zoomx = readf(list+2)*4; |
| 1293 | view->zoomy = readf(list+4)*4; |
| 1286 | 1294 | |
| 1287 | | recompute_frustrum(); |
| 1295 | recompute_frustrum(view); |
| 1288 | 1296 | |
| 1289 | 1297 | list += 6; |
| 1290 | 1298 | break; |
| 1291 | 1299 | case 0xa: |
| 1292 | 1300 | LOG_TGP(("VIDEO: light vector (%f, %f, %f)\n", readf(list+2), readf(list+4), readf(list+6))); |
| 1293 | | view.light.x = readf(list+2); |
| 1294 | | view.light.y = readf(list+4); |
| 1295 | | view.light.z = readf(list+6); |
| 1296 | | normalize_vector(&view.light); |
| 1301 | view->light.x = readf(list+2); |
| 1302 | view->light.y = readf(list+4); |
| 1303 | view->light.z = readf(list+6); |
| 1304 | normalize_vector(&view->light); |
| 1297 | 1305 | list += 8; |
| 1298 | 1306 | break; |
| 1299 | 1307 | case 0xb: { |
| r10427 | r10428 | |
| 1304 | 1312 | readf(list+14), readf(list+16), readf(list+18), |
| 1305 | 1313 | readf(list+20), readf(list+22), readf(list+24))); |
| 1306 | 1314 | for(i=0; i<12; i++) |
| 1307 | | trans_mat[i] = readf(list+2+2*i); |
| 1315 | view->trans_mat[i] = readf(list+2+2*i); |
| 1308 | 1316 | list += 26; |
| 1309 | 1317 | break; |
| 1310 | 1318 | } |
| 1311 | 1319 | case 0xc: |
| 1312 | 1320 | LOG_TGP(("VIDEO: trans (%f, %f)\n", readf(list+2), readf(list+4))); |
| 1313 | | view.transx = readf(list+2); |
| 1314 | | view.transy = readf(list+4); |
| 1321 | view->transx = readf(list+2); |
| 1322 | view->transy = readf(list+4); |
| 1315 | 1323 | |
| 1316 | | recompute_frustrum(); |
| 1324 | recompute_frustrum(view); |
| 1317 | 1325 | |
| 1318 | 1326 | list += 6; |
| 1319 | 1327 | break; |
| r10427 | r10428 | |
| 1326 | 1334 | } |
| 1327 | 1335 | } |
| 1328 | 1336 | end: |
| 1329 | | draw_objects(bitmap, cliprect); |
| 1337 | draw_objects(state, bitmap, cliprect); |
| 1330 | 1338 | } |
| 1331 | 1339 | } |
| 1332 | 1340 | |
| 1333 | | static void tgp_scan(void) |
| 1341 | static void tgp_scan(running_machine *machine) |
| 1334 | 1342 | { |
| 1343 | model1_state *state = machine->driver_data<model1_state>(); |
| 1344 | struct view *view = state->view; |
| 1335 | 1345 | #if 0 |
| 1336 | 1346 | if (input_code_pressed_once(machine, KEYCODE_F)) |
| 1337 | 1347 | { |
| 1338 | | FILE *fp; |
| 1339 | | fp=fopen("tgp-ram.bin", "w+b"); |
| 1340 | | if (fp) |
| 1348 | FILE *fp; |
| 1349 | fp=fopen("tgp-ram.bin", "w+b"); |
| 1350 | if (fp) |
| 1341 | 1351 | { |
| 1342 | | fwrite(tgp_ram, (0x100000-0x40000)*2, 1, fp); |
| 1343 | | fclose(fp); |
| 1352 | fwrite(state->tgp_ram, (0x100000-0x40000)*2, 1, fp); |
| 1353 | fclose(fp); |
| 1344 | 1354 | } |
| 1345 | | exit(0); |
| 1355 | exit(0); |
| 1346 | 1356 | } |
| 1347 | 1357 | #endif |
| 1348 | | if(!render_done && (listctl[1] & 0x1f) == 0x1f) { |
| 1349 | | UINT16 *list = get_list(); |
| 1358 | if(!state->render_done && (state->listctl[1] & 0x1f) == 0x1f) { |
| 1359 | UINT16 *list = get_list(state); |
| 1350 | 1360 | // Skip everything but the data uploads |
| 1351 | | LOG_TGP(("VIDEO: scan list %d\n", get_list_number())); |
| 1361 | LOG_TGP(("VIDEO: scan list %d\n", get_list_number(state))); |
| 1352 | 1362 | for(;;) { |
| 1353 | 1363 | int type = (list[1]<<16)|list[0]; |
| 1354 | 1364 | switch(type) { |
| r10427 | r10428 | |
| 1370 | 1380 | int i; |
| 1371 | 1381 | LOG_TGP(("ZVIDEO: scan color write, adr=%x, len=%x\n", adr, len)); |
| 1372 | 1382 | for(i=0; i<len; i++) |
| 1373 | | tgp_ram[adr-0x40000+i] = list[6+2*i]; |
| 1383 | state->tgp_ram[adr-0x40000+i] = list[6+2*i]; |
| 1374 | 1384 | list += 6+len*2; |
| 1375 | 1385 | break; |
| 1376 | 1386 | } |
| r10427 | r10428 | |
| 1381 | 1391 | int i; |
| 1382 | 1392 | for(i=0;i<len;++i) |
| 1383 | 1393 | { |
| 1384 | | poly_ram[adr-0x800000+i]=readi(list+2*i+6); |
| 1394 | state->poly_ram[adr-0x800000+i]=readi(list+2*i+6); |
| 1385 | 1395 | } |
| 1386 | 1396 | list+=6+len*2; |
| 1387 | 1397 | } |
| r10427 | r10428 | |
| 1394 | 1404 | for(i=0;i<len;++i) |
| 1395 | 1405 | { |
| 1396 | 1406 | int v=readi(list+6+i*2); |
| 1397 | | lightparams[i+adr].d=((float) (v&0xff))/255.0; |
| 1398 | | lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; |
| 1399 | | lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; |
| 1400 | | lightparams[i+adr].p=(v>>24)&0xff; |
| 1407 | view->lightparams[i+adr].d=((float) (v&0xff))/255.0; |
| 1408 | view->lightparams[i+adr].a=((float) ((v>>8)&0xff))/255.0; |
| 1409 | view->lightparams[i+adr].s=((float) ((v>>16)&0xff))/255.0; |
| 1410 | view->lightparams[i+adr].p=(v>>24)&0xff; |
| 1401 | 1411 | //LOG_TGP((" %02X\n",v)); |
| 1402 | 1412 | } |
| 1403 | 1413 | list += 6+len*2; |
| r10427 | r10428 | |
| 1432 | 1442 | end: |
| 1433 | 1443 | ; |
| 1434 | 1444 | } |
| 1435 | | render_done = 0; |
| 1445 | state->render_done = 0; |
| 1436 | 1446 | } |
| 1437 | 1447 | |
| 1438 | 1448 | VIDEO_START(model1) |
| 1439 | 1449 | { |
| 1440 | | paletteram16 = machine->generic.paletteram.u16; |
| 1450 | model1_state *state = machine->driver_data<model1_state>(); |
| 1451 | state->paletteram16 = machine->generic.paletteram.u16; |
| 1441 | 1452 | |
| 1442 | | vxx=vyy=vzz=0; |
| 1443 | | ayy = 0; |
| 1453 | state->view = auto_alloc_clear(machine, struct view); |
| 1444 | 1454 | |
| 1445 | 1455 | sys24_tile_vh_start(machine, 0x3fff); |
| 1446 | 1456 | |
| 1447 | | poly_rom = (UINT32 *)machine->region("user1")->base(); |
| 1448 | | poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000); |
| 1449 | | tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000); |
| 1450 | | pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2); |
| 1451 | | quaddb = auto_alloc_array_clear(machine, struct quad_m1, 1000000); |
| 1452 | | quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000); |
| 1457 | state->poly_rom = (UINT32 *)machine->region("user1")->base(); |
| 1458 | state->poly_ram = auto_alloc_array_clear(machine, UINT32, 0x400000); |
| 1459 | state->tgp_ram = auto_alloc_array_clear(machine, UINT16, 0x100000-0x40000); |
| 1460 | state->pointdb = auto_alloc_array_clear(machine, struct point, 1000000*2); |
| 1461 | state->quaddb = auto_alloc_array_clear(machine, struct quad_m1, 1000000); |
| 1462 | state->quadind = auto_alloc_array_clear(machine, struct quad_m1 *, 1000000); |
| 1453 | 1463 | |
| 1454 | | pointpt = pointdb; |
| 1455 | | quadpt = quaddb; |
| 1456 | | listctl[0] = listctl[1] = 0; |
| 1464 | state->pointpt = state->pointdb; |
| 1465 | state->quadpt = state->quaddb; |
| 1466 | state->listctl[0] = state->listctl[1] = 0; |
| 1457 | 1467 | |
| 1458 | | state_save_register_global_pointer(machine, tgp_ram, 0x100000-0x40000); |
| 1459 | | state_save_register_global_pointer(machine, poly_ram, 0x40000); |
| 1460 | | state_save_register_global_array(machine, listctl); |
| 1468 | state_save_register_global_pointer(machine, state->tgp_ram, 0x100000-0x40000); |
| 1469 | state_save_register_global_pointer(machine, state->poly_ram, 0x40000); |
| 1470 | state_save_register_global_array(machine, state->listctl); |
| 1461 | 1471 | } |
| 1462 | 1472 | |
| 1463 | 1473 | VIDEO_UPDATE(model1) |
| 1464 | 1474 | { |
| 1475 | model1_state *state = screen->machine->driver_data<model1_state>(); |
| 1476 | struct view *view = state->view; |
| 1465 | 1477 | #if 0 |
| 1466 | 1478 | { |
| 1467 | 1479 | int mod = 0; |
| r10427 | r10428 | |
| 1470 | 1482 | |
| 1471 | 1483 | if(input_code_pressed(screen->machine, KEYCODE_F)) { |
| 1472 | 1484 | mod = 1; |
| 1473 | | vxx -= delta; |
| 1485 | view->vxx -= delta; |
| 1474 | 1486 | } |
| 1475 | 1487 | if(input_code_pressed(screen->machine, KEYCODE_G)) { |
| 1476 | 1488 | mod = 1; |
| 1477 | | vxx += delta; |
| 1489 | view->vxx += delta; |
| 1478 | 1490 | } |
| 1479 | 1491 | if(input_code_pressed(screen->machine, KEYCODE_H)) { |
| 1480 | 1492 | mod = 1; |
| 1481 | | vyy -= delta; |
| 1493 | view->vyy -= delta; |
| 1482 | 1494 | } |
| 1483 | 1495 | if(input_code_pressed(screen->machine, KEYCODE_J)) { |
| 1484 | 1496 | mod = 1; |
| 1485 | | vyy += delta; |
| 1497 | view->vyy += delta; |
| 1486 | 1498 | } |
| 1487 | 1499 | if(input_code_pressed(screen->machine, KEYCODE_K)) { |
| 1488 | 1500 | mod = 1; |
| 1489 | | vzz -= delta; |
| 1501 | view->vzz -= delta; |
| 1490 | 1502 | } |
| 1491 | 1503 | if(input_code_pressed(screen->machine, KEYCODE_L)) { |
| 1492 | 1504 | mod = 1; |
| 1493 | | vzz += delta; |
| 1505 | view->vzz += delta; |
| 1494 | 1506 | } |
| 1495 | 1507 | if(input_code_pressed(screen->machine, KEYCODE_U)) { |
| 1496 | 1508 | mod = 1; |
| 1497 | | ayy -= 0.05; |
| 1509 | view->ayy -= 0.05; |
| 1498 | 1510 | } |
| 1499 | 1511 | if(input_code_pressed(screen->machine, KEYCODE_I)) { |
| 1500 | 1512 | mod = 1; |
| 1501 | | ayy += 0.05; |
| 1513 | view->ayy += 0.05; |
| 1502 | 1514 | } |
| 1503 | 1515 | if(mod) |
| 1504 | | popmessage("%g,%g,%g:%g", vxx, vyy, vzz, ayy); |
| 1516 | popmessage("%g,%g,%g:%g", view->vxx, view->vyy, view->vzz, view->ayy); |
| 1505 | 1517 | } |
| 1506 | 1518 | #endif |
| 1507 | 1519 | |
| 1508 | | ayyc = cos(ayy); |
| 1509 | | ayys = sin(ayy); |
| 1520 | view->ayyc = cos(view->ayy); |
| 1521 | view->ayys = sin(view->ayy); |
| 1510 | 1522 | |
| 1511 | 1523 | bitmap_fill(screen->machine->priority_bitmap, NULL, 0); |
| 1512 | 1524 | bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); |
| r10427 | r10428 | |
| 1528 | 1540 | |
| 1529 | 1541 | VIDEO_EOF(model1) |
| 1530 | 1542 | { |
| 1531 | | tgp_scan(); |
| 1543 | tgp_scan(machine); |
| 1532 | 1544 | end_frame(machine); |
| 1533 | 1545 | LOG_TGP(("TGP: vsync\n")); |
| 1534 | 1546 | } |
src/mame/video/model2.c
| r10427 | r10428 | |
| 92 | 92 | |
| 93 | 93 | #define DEBUG 0 |
| 94 | 94 | |
| 95 | | static poly_manager *poly; |
| 96 | 95 | |
| 97 | 96 | #define pz p[0] |
| 98 | 97 | #define pu p[1] |
| r10427 | r10428 | |
| 141 | 140 | typedef struct _poly_extra_data poly_extra_data; |
| 142 | 141 | struct _poly_extra_data |
| 143 | 142 | { |
| 143 | model2_state * state; |
| 144 | 144 | UINT32 lumabase; |
| 145 | 145 | UINT32 colorbase; |
| 146 | 146 | UINT32 * texsheet; |
| r10427 | r10428 | |
| 292 | 292 | |
| 293 | 293 | /******************************************* |
| 294 | 294 | * |
| 295 | | * Hardware 3D Rasterizer Interal State |
| 295 | * Hardware 3D Rasterizer Internal State |
| 296 | 296 | * |
| 297 | 297 | *******************************************/ |
| 298 | 298 | |
| 299 | 299 | #define MAX_TRIANGLES 32768 |
| 300 | 300 | |
| 301 | | typedef struct |
| 301 | struct _raster_state |
| 302 | 302 | { |
| 303 | 303 | UINT32 mode; /* bit 0 = Test Mode, bit 2 = Switch 60Hz(1)/30Hz(0) operation */ |
| 304 | 304 | UINT16 * texture_rom; /* Texture ROM pointer */ |
| 305 | | UINT16 * texture_ram; /* Texture RAM pointer */ |
| 306 | | UINT8 * log_ram; /* Log RAM pointer */ |
| 307 | 305 | INT16 viewport[4]; /* View port (startx,starty,endx,endy) */ |
| 308 | 306 | INT16 center[4][2]; /* Centers (eye 0[x,y],1[x,y],2[x,y],3[x,y]) */ |
| 309 | 307 | UINT16 center_sel; /* Selected center */ |
| r10427 | r10428 | |
| 314 | 312 | UINT32 cur_command; /* Current command */ |
| 315 | 313 | UINT32 command_buffer[32]; /* Command buffer */ |
| 316 | 314 | UINT32 command_index; /* Command buffer index */ |
| 317 | | triangle * tri_list; /* Triangle list */ |
| 315 | triangle tri_list[MAX_TRIANGLES]; /* Triangle list */ |
| 318 | 316 | UINT32 tri_list_index; /* Triangle list index */ |
| 319 | | triangle ** tri_sorted_list; /* Sorted Triangle list */ |
| 317 | triangle * tri_sorted_list[0x10000]; /* Sorted Triangle list */ |
| 320 | 318 | UINT16 min_z; /* Minimum sortable Z value */ |
| 321 | 319 | UINT16 max_z; /* Maximum sortable Z value */ |
| 320 | UINT16 texture_ram[0x10000]; /* Texture RAM pointer */ |
| 321 | UINT8 log_ram[0x40000]; /* Log RAM pointer */ |
| 322 | }; |
| 322 | 323 | |
| 323 | | } raster_state; |
| 324 | 324 | |
| 325 | | static raster_state raster; |
| 326 | | |
| 327 | 325 | /******************************************* |
| 328 | 326 | * |
| 329 | 327 | * Hardware 3D Rasterizer Initialization |
| r10427 | r10428 | |
| 332 | 330 | |
| 333 | 331 | static void model2_3d_init( running_machine *machine, UINT16 *texture_rom ) |
| 334 | 332 | { |
| 335 | | memset( &raster, 0, sizeof( raster_state ) ); |
| 333 | model2_state *state = machine->driver_data<model2_state>(); |
| 336 | 334 | |
| 337 | | raster.texture_rom = texture_rom; |
| 338 | | raster.texture_ram = auto_alloc_array(machine, UINT16, 0x10000); |
| 339 | | raster.log_ram = auto_alloc_array(machine, UINT8, 0x40000); |
| 340 | | raster.tri_list = auto_alloc_array(machine, triangle, MAX_TRIANGLES); |
| 341 | | raster.tri_sorted_list = auto_alloc_array(machine, triangle *, 0x10000); |
| 335 | state->raster = auto_alloc_clear( machine, raster_state ); |
| 336 | |
| 337 | state->raster->texture_rom = texture_rom; |
| 342 | 338 | } |
| 343 | 339 | |
| 344 | 340 | /******************************************* |
| r10427 | r10428 | |
| 347 | 343 | * |
| 348 | 344 | *******************************************/ |
| 349 | 345 | |
| 350 | | void model2_3d_set_zclip( UINT8 clip ) |
| 346 | void model2_3d_set_zclip( running_machine *machine, UINT8 clip ) |
| 351 | 347 | { |
| 352 | | raster.master_z_clip = clip; |
| 348 | model2_state *state = machine->driver_data<model2_state>(); |
| 349 | state->raster->master_z_clip = clip; |
| 353 | 350 | } |
| 354 | 351 | |
| 355 | 352 | /******************************************* |
| r10427 | r10428 | |
| 358 | 355 | * |
| 359 | 356 | *******************************************/ |
| 360 | 357 | |
| 361 | | static void model2_3d_process_quad( UINT32 attr ) |
| 358 | static void model2_3d_process_quad( raster_state *raster, UINT32 attr ) |
| 362 | 359 | { |
| 363 | 360 | _quad_m2 object; |
| 364 | 361 | UINT16 *th, *tp; |
| r10427 | r10428 | |
| 368 | 365 | float min_z, max_z; |
| 369 | 366 | |
| 370 | 367 | /* extract P0(n-1) */ |
| 371 | | object.v[1].x = u2f( raster.command_buffer[2] << 8 ); |
| 372 | | object.v[1].y = u2f( raster.command_buffer[3] << 8 ); |
| 373 | | object.v[1].pz = u2f( raster.command_buffer[4] << 8 ); |
| 368 | object.v[1].x = u2f( raster->command_buffer[2] << 8 ); |
| 369 | object.v[1].y = u2f( raster->command_buffer[3] << 8 ); |
| 370 | object.v[1].pz = u2f( raster->command_buffer[4] << 8 ); |
| 374 | 371 | |
| 375 | 372 | /* extract P1(n-1) */ |
| 376 | | object.v[0].x = u2f( raster.command_buffer[5] << 8 ); |
| 377 | | object.v[0].y = u2f( raster.command_buffer[6] << 8 ); |
| 378 | | object.v[0].pz = u2f( raster.command_buffer[7] << 8 ); |
| 373 | object.v[0].x = u2f( raster->command_buffer[5] << 8 ); |
| 374 | object.v[0].y = u2f( raster->command_buffer[6] << 8 ); |
| 375 | object.v[0].pz = u2f( raster->command_buffer[7] << 8 ); |
| 379 | 376 | |
| 380 | 377 | /* extract P0(n) */ |
| 381 | | object.v[2].x = u2f( raster.command_buffer[11] << 8 ); |
| 382 | | object.v[2].y = u2f( raster.command_buffer[12] << 8 ); |
| 383 | | object.v[2].pz = u2f( raster.command_buffer[13] << 8 ); |
| 378 | object.v[2].x = u2f( raster->command_buffer[11] << 8 ); |
| 379 | object.v[2].y = u2f( raster->command_buffer[12] << 8 ); |
| 380 | object.v[2].pz = u2f( raster->command_buffer[13] << 8 ); |
| 384 | 381 | |
| 385 | 382 | /* extract P1(n) */ |
| 386 | | object.v[3].x = u2f( raster.command_buffer[14] << 8 ); |
| 387 | | object.v[3].y = u2f( raster.command_buffer[15] << 8 ); |
| 388 | | object.v[3].pz = u2f( raster.command_buffer[16] << 8 ); |
| 383 | object.v[3].x = u2f( raster->command_buffer[14] << 8 ); |
| 384 | object.v[3].y = u2f( raster->command_buffer[15] << 8 ); |
| 385 | object.v[3].pz = u2f( raster->command_buffer[16] << 8 ); |
| 389 | 386 | |
| 390 | 387 | /* always calculate the min z and max z value */ |
| 391 | 388 | min_z = object.v[0].pz; |
| r10427 | r10428 | |
| 401 | 398 | /* read in the texture information */ |
| 402 | 399 | |
| 403 | 400 | /* texture point data */ |
| 404 | | if ( raster.command_buffer[0] & 0x800000 ) |
| 405 | | tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF]; |
| 401 | if ( raster->command_buffer[0] & 0x800000 ) |
| 402 | tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF]; |
| 406 | 403 | else |
| 407 | | tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF]; |
| 404 | tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF]; |
| 408 | 405 | |
| 409 | 406 | object.v[0].pv = *tp++; |
| 410 | 407 | object.v[0].pu = *tp++; |
| r10427 | r10428 | |
| 416 | 413 | object.v[3].pu = *tp++; |
| 417 | 414 | |
| 418 | 415 | /* update the address */ |
| 419 | | raster.command_buffer[0] += 8; |
| 416 | raster->command_buffer[0] += 8; |
| 420 | 417 | |
| 421 | 418 | /* texture header data */ |
| 422 | | if ( raster.command_buffer[1] & 0x800000 ) |
| 423 | | th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF]; |
| 419 | if ( raster->command_buffer[1] & 0x800000 ) |
| 420 | th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF]; |
| 424 | 421 | else |
| 425 | | th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF]; |
| 422 | th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF]; |
| 426 | 423 | |
| 427 | 424 | object.texheader[0] = *th++; |
| 428 | 425 | object.texheader[1] = *th++; |
| r10427 | r10428 | |
| 437 | 434 | tho |= -16; |
| 438 | 435 | |
| 439 | 436 | /* update the address */ |
| 440 | | raster.command_buffer[1] += tho * 4; |
| 437 | raster->command_buffer[1] += tho * 4; |
| 441 | 438 | |
| 442 | 439 | /* set the luma value of this quad */ |
| 443 | | object.luma = (raster.command_buffer[9] >> 15) & 0xFF; |
| 440 | object.luma = (raster->command_buffer[9] >> 15) & 0xFF; |
| 444 | 441 | |
| 445 | 442 | /* determine wether we can cull this quad */ |
| 446 | 443 | cull = 0; |
| r10427 | r10428 | |
| 449 | 446 | if ( ((attr >> 17) & 1) == 0 ) |
| 450 | 447 | { |
| 451 | 448 | /* if it's the backface, cull it */ |
| 452 | | if ( raster.command_buffer[9] & 0x00800000 ) |
| 449 | if ( raster->command_buffer[9] & 0x00800000 ) |
| 453 | 450 | cull = 1; |
| 454 | 451 | } |
| 455 | 452 | |
| r10427 | r10428 | |
| 458 | 455 | cull = 1; |
| 459 | 456 | |
| 460 | 457 | /* if the minimum z value is bigger than the master z clip value, don't render */ |
| 461 | | if ( (INT32)(1.0/min_z) > raster.master_z_clip ) |
| 458 | if ( (INT32)(1.0/min_z) > raster->master_z_clip ) |
| 462 | 459 | cull = 1; |
| 463 | 460 | |
| 464 | 461 | /* if the maximum z value is < 0 then we can safely clip the entire polygon */ |
| r10427 | r10428 | |
| 466 | 463 | cull = 1; |
| 467 | 464 | |
| 468 | 465 | /* set the object's z value */ |
| 469 | | zvalue = raster.triangle_z; |
| 466 | zvalue = raster->triangle_z; |
| 470 | 467 | |
| 471 | 468 | /* see if we need to recompute min/max z */ |
| 472 | 469 | if ( (attr >> 10) & 3 ) |
| r10427 | r10428 | |
| 480 | 477 | zvalue = max_z; |
| 481 | 478 | } |
| 482 | 479 | |
| 483 | | raster.triangle_z = zvalue; |
| 480 | raster->triangle_z = zvalue; |
| 484 | 481 | } |
| 485 | 482 | |
| 486 | 483 | if ( cull == 0 ) |
| r10427 | r10428 | |
| 502 | 499 | triangle *ztri; |
| 503 | 500 | |
| 504 | 501 | /* adjust and set the object z-sort value */ |
| 505 | | object.z = float_to_zval( zvalue + raster.z_adjust ); |
| 502 | object.z = float_to_zval( zvalue + raster->z_adjust ); |
| 506 | 503 | |
| 507 | 504 | /* get our list read to add the triangles */ |
| 508 | | ztri = raster.tri_sorted_list[object.z]; |
| 505 | ztri = raster->tri_sorted_list[object.z]; |
| 509 | 506 | |
| 510 | 507 | if ( ztri != NULL ) |
| 511 | 508 | { |
| r10427 | r10428 | |
| 518 | 515 | { |
| 519 | 516 | triangle *tri; |
| 520 | 517 | |
| 521 | | tri = &raster.tri_list[raster.tri_list_index++]; |
| 518 | tri = &raster->tri_list[raster->tri_list_index++]; |
| 522 | 519 | |
| 523 | | if ( raster.tri_list_index >= MAX_TRIANGLES ) |
| 520 | if ( raster->tri_list_index >= MAX_TRIANGLES ) |
| 524 | 521 | { |
| 525 | 522 | fatalerror( "SEGA 3D: Max triangle limit exceeded\n" ); |
| 526 | 523 | } |
| r10427 | r10428 | |
| 534 | 531 | tri->luma = object.luma; |
| 535 | 532 | |
| 536 | 533 | /* set the viewport */ |
| 537 | | tri->viewport[0] = raster.viewport[0]; |
| 538 | | tri->viewport[1] = raster.viewport[1]; |
| 539 | | tri->viewport[2] = raster.viewport[2]; |
| 540 | | tri->viewport[3] = raster.viewport[3]; |
| 534 | tri->viewport[0] = raster->viewport[0]; |
| 535 | tri->viewport[1] = raster->viewport[1]; |
| 536 | tri->viewport[2] = raster->viewport[2]; |
| 537 | tri->viewport[3] = raster->viewport[3]; |
| 541 | 538 | |
| 542 | 539 | /* set the center */ |
| 543 | | tri->center[0] = raster.center[raster.center_sel][0]; |
| 544 | | tri->center[1] = raster.center[raster.center_sel][1]; |
| 540 | tri->center[0] = raster->center[raster->center_sel][0]; |
| 541 | tri->center[1] = raster->center[raster->center_sel][1]; |
| 545 | 542 | |
| 546 | 543 | memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) ); |
| 547 | 544 | memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) ); |
| r10427 | r10428 | |
| 552 | 549 | |
| 553 | 550 | if ( ztri == NULL ) |
| 554 | 551 | { |
| 555 | | raster.tri_sorted_list[object.z] = tri; |
| 552 | raster->tri_sorted_list[object.z] = tri; |
| 556 | 553 | } |
| 557 | 554 | else |
| 558 | 555 | { |
| r10427 | r10428 | |
| 563 | 560 | } |
| 564 | 561 | |
| 565 | 562 | /* keep around the min and max z values for this frame */ |
| 566 | | if ( object.z < raster.min_z ) raster.min_z = object.z; |
| 567 | | if ( object.z > raster.max_z ) raster.max_z = object.z; |
| 563 | if ( object.z < raster->min_z ) raster->min_z = object.z; |
| 564 | if ( object.z > raster->max_z ) raster->max_z = object.z; |
| 568 | 565 | } |
| 569 | 566 | } |
| 570 | 567 | |
| r10427 | r10428 | |
| 576 | 573 | { |
| 577 | 574 | /* reuse P0(n) and P1(n) */ |
| 578 | 575 | for( i = 0; i < 6; i++ ) /* P0(n) -> P0(n-1) */ |
| 579 | | raster.command_buffer[2+i] = raster.command_buffer[11+i]; /* P1(n) -> P1(n-1) */ |
| 576 | raster->command_buffer[2+i] = raster->command_buffer[11+i]; /* P1(n) -> P1(n-1) */ |
| 580 | 577 | } |
| 581 | 578 | break; |
| 582 | 579 | |
| r10427 | r10428 | |
| 584 | 581 | { |
| 585 | 582 | /* reuse P0(n-1) and P0(n) */ |
| 586 | 583 | for( i = 0; i < 3; i++ ) |
| 587 | | raster.command_buffer[5+i] = raster.command_buffer[11+i]; /* P0(n) -> P1(n-1) */ |
| 584 | raster->command_buffer[5+i] = raster->command_buffer[11+i]; /* P0(n) -> P1(n-1) */ |
| 588 | 585 | } |
| 589 | 586 | break; |
| 590 | 587 | |
| r10427 | r10428 | |
| 592 | 589 | { |
| 593 | 590 | /* reuse P1(n-1) and P1(n) */ |
| 594 | 591 | for( i = 0; i < 3; i++ ) |
| 595 | | raster.command_buffer[2+i] = raster.command_buffer[14+i]; /* P1(n) -> P1(n-1) */ |
| 592 | raster->command_buffer[2+i] = raster->command_buffer[14+i]; /* P1(n) -> P1(n-1) */ |
| 596 | 593 | } |
| 597 | 594 | break; |
| 598 | 595 | } |
| 599 | 596 | } |
| 600 | 597 | |
| 601 | | static void model2_3d_process_triangle( UINT32 attr ) |
| 598 | static void model2_3d_process_triangle( raster_state *raster, UINT32 attr ) |
| 602 | 599 | { |
| 603 | 600 | triangle object; |
| 604 | 601 | UINT16 *th, *tp; |
| r10427 | r10428 | |
| 608 | 605 | float min_z, max_z; |
| 609 | 606 | |
| 610 | 607 | /* extract P0(n-1) */ |
| 611 | | object.v[1].x = u2f( raster.command_buffer[2] << 8 ); |
| 612 | | object.v[1].y = u2f( raster.command_buffer[3] << 8 ); |
| 613 | | object.v[1].pz = u2f( raster.command_buffer[4] << 8 ); |
| 608 | object.v[1].x = u2f( raster->command_buffer[2] << 8 ); |
| 609 | object.v[1].y = u2f( raster->command_buffer[3] << 8 ); |
| 610 | object.v[1].pz = u2f( raster->command_buffer[4] << 8 ); |
| 614 | 611 | |
| 615 | 612 | /* extract P1(n-1) */ |
| 616 | | object.v[0].x = u2f( raster.command_buffer[5] << 8 ); |
| 617 | | object.v[0].y = u2f( raster.command_buffer[6] << 8 ); |
| 618 | | object.v[0].pz = u2f( raster.command_buffer[7] << 8 ); |
| 613 | object.v[0].x = u2f( raster->command_buffer[5] << 8 ); |
| 614 | object.v[0].y = u2f( raster->command_buffer[6] << 8 ); |
| 615 | object.v[0].pz = u2f( raster->command_buffer[7] << 8 ); |
| 619 | 616 | |
| 620 | 617 | /* extract P0(n) */ |
| 621 | | object.v[2].x = u2f( raster.command_buffer[11] << 8 ); |
| 622 | | object.v[2].y = u2f( raster.command_buffer[12] << 8 ); |
| 623 | | object.v[2].pz = u2f( raster.command_buffer[13] << 8 ); |
| 618 | object.v[2].x = u2f( raster->command_buffer[11] << 8 ); |
| 619 | object.v[2].y = u2f( raster->command_buffer[12] << 8 ); |
| 620 | object.v[2].pz = u2f( raster->command_buffer[13] << 8 ); |
| 624 | 621 | |
| 625 | 622 | /* for triangles, the rope of P1(n) is achieved by P0(n-1) (linktype 3) */ |
| 626 | | raster.command_buffer[14] = raster.command_buffer[11]; |
| 627 | | raster.command_buffer[15] = raster.command_buffer[12]; |
| 628 | | raster.command_buffer[16] = raster.command_buffer[13]; |
| 623 | raster->command_buffer[14] = raster->command_buffer[11]; |
| 624 | raster->command_buffer[15] = raster->command_buffer[12]; |
| 625 | raster->command_buffer[16] = raster->command_buffer[13]; |
| 629 | 626 | |
| 630 | 627 | /* always calculate the min z and max z values */ |
| 631 | 628 | min_z = object.v[0].pz; |
| r10427 | r10428 | |
| 639 | 636 | /* read in the texture information */ |
| 640 | 637 | |
| 641 | 638 | /* texture point data */ |
| 642 | | if ( raster.command_buffer[0] & 0x800000 ) |
| 643 | | tp = &raster.texture_ram[raster.command_buffer[0] & 0xFFFF]; |
| 639 | if ( raster->command_buffer[0] & 0x800000 ) |
| 640 | tp = &raster->texture_ram[raster->command_buffer[0] & 0xFFFF]; |
| 644 | 641 | else |
| 645 | | tp = &raster.texture_rom[raster.command_buffer[0] & 0x7FFFFF]; |
| 642 | tp = &raster->texture_rom[raster->command_buffer[0] & 0x7FFFFF]; |
| 646 | 643 | |
| 647 | 644 | object.v[0].pv = *tp++; |
| 648 | 645 | object.v[0].pu = *tp++; |
| r10427 | r10428 | |
| 652 | 649 | object.v[2].pu = *tp++; |
| 653 | 650 | |
| 654 | 651 | /* update the address */ |
| 655 | | raster.command_buffer[0] += 6; |
| 652 | raster->command_buffer[0] += 6; |
| 656 | 653 | |
| 657 | 654 | /* texture header data */ |
| 658 | | if ( raster.command_buffer[1] & 0x800000 ) |
| 659 | | th = &raster.texture_ram[raster.command_buffer[1] & 0xFFFF]; |
| 655 | if ( raster->command_buffer[1] & 0x800000 ) |
| 656 | th = &raster->texture_ram[raster->command_buffer[1] & 0xFFFF]; |
| 660 | 657 | else |
| 661 | | th = &raster.texture_rom[raster.command_buffer[1] & 0x7FFFFF]; |
| 658 | th = &raster->texture_rom[raster->command_buffer[1] & 0x7FFFFF]; |
| 662 | 659 | |
| 663 | 660 | object.texheader[0] = *th++; |
| 664 | 661 | object.texheader[1] = *th++; |
| r10427 | r10428 | |
| 673 | 670 | tho |= -16; |
| 674 | 671 | |
| 675 | 672 | /* update the address */ |
| 676 | | raster.command_buffer[1] += tho * 4; |
| 673 | raster->command_buffer[1] += tho * 4; |
| 677 | 674 | |
| 678 | 675 | /* set the luma value of this quad */ |
| 679 | | object.luma = (raster.command_buffer[9] >> 15) & 0xFF; |
| 676 | object.luma = (raster->command_buffer[9] >> 15) & 0xFF; |
| 680 | 677 | |
| 681 | 678 | /* determine wether we can cull this quad */ |
| 682 | 679 | cull = 0; |
| r10427 | r10428 | |
| 685 | 682 | if ( ((attr >> 17) & 1) == 0 ) |
| 686 | 683 | { |
| 687 | 684 | /* if it's the backface, cull it */ |
| 688 | | if ( raster.command_buffer[9] & 0x00800000 ) |
| 685 | if ( raster->command_buffer[9] & 0x00800000 ) |
| 689 | 686 | cull = 1; |
| 690 | 687 | } |
| 691 | 688 | |
| r10427 | r10428 | |
| 694 | 691 | cull = 1; |
| 695 | 692 | |
| 696 | 693 | /* if the minimum z value is bigger than the master z clip value, don't render */ |
| 697 | | if ( (INT32)(1.0/min_z) > raster.master_z_clip ) |
| 694 | if ( (INT32)(1.0/min_z) > raster->master_z_clip ) |
| 698 | 695 | cull = 1; |
| 699 | 696 | |
| 700 | 697 | /* if the maximum z value is < 0 then we can safely clip the entire polygon */ |
| r10427 | r10428 | |
| 702 | 699 | cull = 1; |
| 703 | 700 | |
| 704 | 701 | /* set the object's z value */ |
| 705 | | zvalue = raster.triangle_z; |
| 702 | zvalue = raster->triangle_z; |
| 706 | 703 | |
| 707 | 704 | /* see if we need to recompute min/max z */ |
| 708 | 705 | if ( (attr >> 10) & 3 ) |
| r10427 | r10428 | |
| 716 | 713 | zvalue = max_z; |
| 717 | 714 | } |
| 718 | 715 | |
| 719 | | raster.triangle_z = zvalue; |
| 716 | raster->triangle_z = zvalue; |
| 720 | 717 | } |
| 721 | 718 | |
| 722 | 719 | /* if we're not culling, do z-clip and add to out triangle list */ |
| r10427 | r10428 | |
| 739 | 736 | triangle *ztri; |
| 740 | 737 | |
| 741 | 738 | /* adjust and set the object z-sort value */ |
| 742 | | object.z = float_to_zval( zvalue + raster.z_adjust ); |
| 739 | object.z = float_to_zval( zvalue + raster->z_adjust ); |
| 743 | 740 | |
| 744 | 741 | /* get our list read to add the triangles */ |
| 745 | | ztri = raster.tri_sorted_list[object.z]; |
| 742 | ztri = raster->tri_sorted_list[object.z]; |
| 746 | 743 | |
| 747 | 744 | if ( ztri != NULL ) |
| 748 | 745 | { |
| r10427 | r10428 | |
| 755 | 752 | { |
| 756 | 753 | triangle *tri; |
| 757 | 754 | |
| 758 | | tri = &raster.tri_list[raster.tri_list_index++]; |
| 755 | tri = &raster->tri_list[raster->tri_list_index++]; |
| 759 | 756 | |
| 760 | | if ( raster.tri_list_index >= MAX_TRIANGLES ) |
| 757 | if ( raster->tri_list_index >= MAX_TRIANGLES ) |
| 761 | 758 | { |
| 762 | 759 | fatalerror( "SEGA 3D: Max triangle limit exceeded\n" ); |
| 763 | 760 | } |
| r10427 | r10428 | |
| 771 | 768 | tri->luma = object.luma; |
| 772 | 769 | |
| 773 | 770 | /* set the viewport */ |
| 774 | | tri->viewport[0] = raster.viewport[0]; |
| 775 | | tri->viewport[1] = raster.viewport[1]; |
| 776 | | tri->viewport[2] = raster.viewport[2]; |
| 777 | | tri->viewport[3] = raster.viewport[3]; |
| 771 | tri->viewport[0] = raster->viewport[0]; |
| 772 | tri->viewport[1] = raster->viewport[1]; |
| 773 | tri->viewport[2] = raster->viewport[2]; |
| 774 | tri->viewport[3] = raster->viewport[3]; |
| 778 | 775 | |
| 779 | 776 | /* set the center */ |
| 780 | | tri->center[0] = raster.center[raster.center_sel][0]; |
| 781 | | tri->center[1] = raster.center[raster.center_sel][1]; |
| 777 | tri->center[0] = raster->center[raster->center_sel][0]; |
| 778 | tri->center[1] = raster->center[raster->center_sel][1]; |
| 782 | 779 | |
| 783 | 780 | memcpy( &tri->v[0], &verts[0], sizeof( poly_vertex ) ); |
| 784 | 781 | memcpy( &tri->v[1], &verts[i-1], sizeof( poly_vertex ) ); |
| r10427 | r10428 | |
| 789 | 786 | |
| 790 | 787 | if ( ztri == NULL ) |
| 791 | 788 | { |
| 792 | | raster.tri_sorted_list[object.z] = tri; |
| 789 | raster->tri_sorted_list[object.z] = tri; |
| 793 | 790 | } |
| 794 | 791 | else |
| 795 | 792 | { |
| r10427 | r10428 | |
| 800 | 797 | } |
| 801 | 798 | |
| 802 | 799 | /* keep around the min and max z values for this frame */ |
| 803 | | if ( object.z < raster.min_z ) raster.min_z = object.z; |
| 804 | | if ( object.z > raster.max_z ) raster.max_z = object.z; |
| 800 | if ( object.z < raster->min_z ) raster->min_z = object.z; |
| 801 | if ( object.z > raster->max_z ) raster->max_z = object.z; |
| 805 | 802 | } |
| 806 | 803 | } |
| 807 | 804 | |
| r10427 | r10428 | |
| 813 | 810 | { |
| 814 | 811 | /* reuse P0(n) and P1(n) */ |
| 815 | 812 | for( i = 0; i < 6; i++ ) /* P0(n) -> P0(n-1) */ |
| 816 | | raster.command_buffer[2+i] = raster.command_buffer[11+i]; /* P1(n) -> P1(n-1) */ |
| 813 | raster->command_buffer[2+i] = raster->command_buffer[11+i]; /* P1(n) -> P1(n-1) */ |
| 817 | 814 | } |
| 818 | 815 | break; |
| 819 | 816 | |
| r10427 | r10428 | |
| 821 | 818 | { |
| 822 | 819 | /* reuse P0(n-1) and P0(n) */ |
| 823 | 820 | for( i = 0; i < 3; i++ ) |
| 824 | | raster.command_buffer[5+i] = raster.command_buffer[11+i]; /* P0(n) -> P1(n-1) */ |
| 821 | raster->command_buffer[5+i] = raster->command_buffer[11+i]; /* P0(n) -> P1(n-1) */ |
| 825 | 822 | } |
| 826 | 823 | break; |
| 827 | 824 | |
| r10427 | r10428 | |
| 829 | 826 | { |
| 830 | 827 | /* reuse P1(n-1) and P1(n) */ |
| 831 | 828 | for( i = 0; i < 3; i++ ) |
| 832 | | raster.command_buffer[2+i] = raster.command_buffer[14+i]; /* P1(n) -> P1(n-1) */ |
| 829 | raster->command_buffer[2+i] = raster->command_buffer[14+i]; /* P1(n) -> P1(n-1) */ |
| 833 | 830 | } |
| 834 | 831 | break; |
| 835 | 832 | } |
| r10427 | r10428 | |
| 926 | 923 | model2_3d_render_7 /* checker = 1, textured = 1, translucent = 1 */ |
| 927 | 924 | }; |
| 928 | 925 | |
| 929 | | static void model2_3d_render( bitmap_t *bitmap, triangle *tri, const rectangle *cliprect ) |
| 926 | static void model2_3d_render( model2_state *state, bitmap_t *bitmap, triangle *tri, const rectangle *cliprect ) |
| 930 | 927 | { |
| 928 | poly_manager *poly = state->poly; |
| 931 | 929 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 932 | 930 | UINT8 renderer; |
| 933 | 931 | rectangle vp; |
| r10427 | r10428 | |
| 946 | 944 | if ( vp.min_y < cliprect->min_y ) vp.min_y = cliprect->min_y; |
| 947 | 945 | if ( vp.max_y > cliprect->max_y ) vp.max_y = cliprect->max_y; |
| 948 | 946 | |
| 947 | extra->state = state; |
| 949 | 948 | extra->lumabase = ((tri->texheader[1] & 0xFF) << 7) + ((tri->luma >> 5) ^ 0x7); |
| 950 | 949 | extra->colorbase = (tri->texheader[3] >> 6) & 0x3FF; |
| 951 | 950 | |
| r10427 | r10428 | |
| 957 | 956 | extra->texy = 32 * (((tri->texheader[2] >> 6) & 0x1f) + ( tri->texheader[2] & 0x20 )); |
| 958 | 957 | extra->texmirrorx = (tri->texheader[0] >> 9) & 1; |
| 959 | 958 | extra->texmirrory = (tri->texheader[0] >> 8) & 1; |
| 960 | | extra->texsheet = (tri->texheader[2] & 0x1000) ? model2_textureram1 : model2_textureram0; |
| 959 | extra->texsheet = (tri->texheader[2] & 0x1000) ? state->textureram1 : state->textureram0; |
| 961 | 960 | |
| 962 | 961 | tri->v[0].pz = 1.0f / (1.0f + tri->v[0].pz); |
| 963 | 962 | tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * (1.0f / 8.0f); |
| r10427 | r10428 | |
| 1008 | 1007 | } |
| 1009 | 1008 | |
| 1010 | 1009 | /* 3D Rasterizer frame start: Resets frame variables */ |
| 1011 | | static void model2_3d_frame_start( void ) |
| 1010 | static void model2_3d_frame_start( model2_state *state ) |
| 1012 | 1011 | { |
| 1012 | raster_state *raster = state->raster; |
| 1013 | |
| 1013 | 1014 | /* reset the triangle list index */ |
| 1014 | | raster.tri_list_index = 0; |
| 1015 | raster->tri_list_index = 0; |
| 1015 | 1016 | |
| 1016 | 1017 | /* reset the sorted z list */ |
| 1017 | | memset( raster.tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) ); |
| 1018 | memset( raster->tri_sorted_list, 0, 0x10000 * sizeof( triangle * ) ); |
| 1018 | 1019 | |
| 1019 | 1020 | /* reset the min-max sortable Z values */ |
| 1020 | | raster.min_z = 0xFFFF; |
| 1021 | | raster.max_z = 0; |
| 1021 | raster->min_z = 0xFFFF; |
| 1022 | raster->max_z = 0; |
| 1022 | 1023 | } |
| 1023 | 1024 | |
| 1024 | | static void model2_3d_frame_end( bitmap_t *bitmap, const rectangle *cliprect ) |
| 1025 | static void model2_3d_frame_end( model2_state *state, bitmap_t *bitmap, const rectangle *cliprect ) |
| 1025 | 1026 | { |
| 1027 | raster_state *raster = state->raster; |
| 1026 | 1028 | INT32 z; |
| 1027 | 1029 | |
| 1028 | 1030 | /* if we have nothing to render, bail */ |
| 1029 | | if ( raster.tri_list_index == 0 ) |
| 1031 | if ( raster->tri_list_index == 0 ) |
| 1030 | 1032 | return; |
| 1031 | 1033 | |
| 1032 | 1034 | #if DEBUG |
| r10427 | r10428 | |
| 1038 | 1040 | |
| 1039 | 1041 | if ( f ) |
| 1040 | 1042 | { |
| 1041 | | for( i = 0; i < raster.tri_list_index; i++ ) |
| 1043 | for( i = 0; i < raster->tri_list_index; i++ ) |
| 1042 | 1044 | { |
| 1043 | 1045 | |
| 1044 | 1046 | fprintf( f, "index: %d\n", i ); |
| 1045 | | fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster.tri_list[i].v[0].x, raster.tri_list[i].v[0].y, raster.tri_list[i].v[0].pz ); |
| 1046 | | fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster.tri_list[i].v[1].x, raster.tri_list[i].v[1].y, raster.tri_list[i].v[1].pz ); |
| 1047 | | fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster.tri_list[i].v[2].x, raster.tri_list[i].v[2].y, raster.tri_list[i].v[2].pz ); |
| 1047 | fprintf( f, "v0.x = %f, v0.y = %f, v0.z = %f\n", raster->tri_list[i].v[0].x, raster->tri_list[i].v[0].y, raster->tri_list[i].v[0].pz ); |
| 1048 | fprintf( f, "v1.x = %f, v1.y = %f, v1.z = %f\n", raster->tri_list[i].v[1].x, raster->tri_list[i].v[1].y, raster->tri_list[i].v[1].pz ); |
| 1049 | fprintf( f, "v2.x = %f, v2.y = %f, v2.z = %f\n", raster->tri_list[i].v[2].x, raster->tri_list[i].v[2].y, raster->tri_list[i].v[2].pz ); |
| 1048 | 1050 | |
| 1049 | | fprintf( f, "tri z: %04x\n", raster.tri_list[i].pz ); |
| 1050 | | fprintf( f, "texheader - 0: %04x\n", raster.tri_list[i].texheader[0] ); |
| 1051 | | fprintf( f, "texheader - 1: %04x\n", raster.tri_list[i].texheader[1] ); |
| 1052 | | fprintf( f, "texheader - 2: %04x\n", raster.tri_list[i].texheader[2] ); |
| 1053 | | fprintf( f, "texheader - 3: %04x\n", raster.tri_list[i].texheader[3] ); |
| 1054 | | fprintf( f, "luma: %02x\n", raster.tri_list[i].luma ); |
| 1055 | | fprintf( f, "vp.sx: %04x\n", raster.tri_list[i].viewport[0] ); |
| 1056 | | fprintf( f, "vp.sy: %04x\n", raster.tri_list[i].viewport[1] ); |
| 1057 | | fprintf( f, "vp.ex: %04x\n", raster.tri_list[i].viewport[2] ); |
| 1058 | | fprintf( f, "vp.ey: %04x\n", raster.tri_list[i].viewport[3] ); |
| 1059 | | fprintf( f, "vp.swx: %04x\n", raster.tri_list[i].center[0] ); |
| 1060 | | fprintf( f, "vp.swy: %04x\n", raster.tri_list[i].center[1] ); |
| 1051 | fprintf( f, "tri z: %04x\n", raster->tri_list[i].pz ); |
| 1052 | fprintf( f, "texheader - 0: %04x\n", raster->tri_list[i].texheader[0] ); |
| 1053 | fprintf( f, "texheader - 1: %04x\n", raster->tri_list[i].texheader[1] ); |
| 1054 | fprintf( f, "texheader - 2: %04x\n", raster->tri_list[i].texheader[2] ); |
| 1055 | fprintf( f, "texheader - 3: %04x\n", raster->tri_list[i].texheader[3] ); |
| 1056 | fprintf( f, "luma: %02x\n", raster->tri_list[i].luma ); |
| 1057 | fprintf( f, "vp.sx: %04x\n", raster->tri_list[i].viewport[0] ); |
| 1058 | fprintf( f, "vp.sy: %04x\n", raster->tri_list[i].viewport[1] ); |
| 1059 | fprintf( f, "vp.ex: %04x\n", raster->tri_list[i].viewport[2] ); |
| 1060 | fprintf( f, "vp.ey: %04x\n", raster->tri_list[i].viewport[3] ); |
| 1061 | fprintf( f, "vp.swx: %04x\n", raster->tri_list[i].center[0] ); |
| 1062 | fprintf( f, "vp.swy: %04x\n", raster->tri_list[i].center[1] ); |
| 1061 | 1063 | fprintf( f, "\n---\n\n" ); |
| 1062 | 1064 | } |
| 1063 | 1065 | |
| 1064 | | fprintf( f, "min_z = %04x, max_z = %04x\n", raster.min_z, raster.max_z ); |
| 1066 | fprintf( f, "min_z = %04x, max_z = %04x\n", raster->min_z, raster->max_z ); |
| 1065 | 1067 | |
| 1066 | 1068 | fclose( f ); |
| 1067 | 1069 | } |
| r10427 | r10428 | |
| 1069 | 1071 | #endif |
| 1070 | 1072 | |
| 1071 | 1073 | /* go through the Z levels, and render each bucket */ |
| 1072 | | for( z = raster.max_z; z >= raster.min_z; z-- ) |
| 1074 | for( z = raster->max_z; z >= raster->min_z; z-- ) |
| 1073 | 1075 | { |
| 1074 | 1076 | /* see if we have items at this z level */ |
| 1075 | | if ( raster.tri_sorted_list[z] != NULL ) |
| 1077 | if ( raster->tri_sorted_list[z] != NULL ) |
| 1076 | 1078 | { |
| 1077 | 1079 | /* get a pointer to the first triangle */ |
| 1078 | | triangle *tri = raster.tri_sorted_list[z]; |
| 1080 | triangle *tri = raster->tri_sorted_list[z]; |
| 1079 | 1081 | |
| 1080 | 1082 | /* and loop clipping and rendering each triangle */ |
| 1081 | 1083 | while( tri != NULL ) |
| 1082 | 1084 | { |
| 1083 | 1085 | /* project and render */ |
| 1084 | 1086 | model2_3d_project( tri ); |
| 1085 | | model2_3d_render( bitmap, tri, cliprect ); |
| 1087 | model2_3d_render( state, bitmap, tri, cliprect ); |
| 1086 | 1088 | |
| 1087 | 1089 | tri = (triangle *)tri->next; |
| 1088 | 1090 | } |
| 1089 | 1091 | } |
| 1090 | 1092 | } |
| 1091 | | poly_wait(poly, "End of frame"); |
| 1093 | poly_wait(state->poly, "End of frame"); |
| 1092 | 1094 | } |
| 1093 | 1095 | |
| 1094 | 1096 | /* 3D Rasterizer main data input port */ |
| 1095 | | static void model2_3d_push( UINT32 input ) |
| 1097 | static void model2_3d_push( raster_state *raster, UINT32 input ) |
| 1096 | 1098 | { |
| 1097 | 1099 | /* see if we have a command in progress */ |
| 1098 | | if ( raster.cur_command != 0 ) |
| 1100 | if ( raster->cur_command != 0 ) |
| 1099 | 1101 | { |
| 1100 | | raster.command_buffer[raster.command_index++] = input; |
| 1102 | raster->command_buffer[raster->command_index++] = input; |
| 1101 | 1103 | |
| 1102 | | switch( raster.cur_command ) |
| 1104 | switch( raster->cur_command ) |
| 1103 | 1105 | { |
| 1104 | 1106 | case 0x00: /* NOP */ |
| 1105 | 1107 | break; |
| r10427 | r10428 | |
| 1109 | 1111 | UINT32 attr; |
| 1110 | 1112 | |
| 1111 | 1113 | /* start by looking if we have the basic input data */ |
| 1112 | | if ( raster.command_index < 9 ) |
| 1114 | if ( raster->command_index < 9 ) |
| 1113 | 1115 | return; |
| 1114 | 1116 | |
| 1115 | 1117 | /* get the attributes */ |
| 1116 | | attr = raster.command_buffer[8]; |
| 1118 | attr = raster->command_buffer[8]; |
| 1117 | 1119 | |
| 1118 | 1120 | /* see if we're done */ |
| 1119 | 1121 | if ( (attr & 3) == 0 ) |
| 1120 | 1122 | { |
| 1121 | | raster.cur_command = 0; |
| 1123 | raster->cur_command = 0; |
| 1122 | 1124 | return; |
| 1123 | 1125 | } |
| 1124 | 1126 | |
| r10427 | r10428 | |
| 1126 | 1128 | if ( attr & 1 ) |
| 1127 | 1129 | { |
| 1128 | 1130 | /* it's a quad, wait for the rest of the points */ |
| 1129 | | if ( raster.command_index < 17 ) |
| 1131 | if ( raster->command_index < 17 ) |
| 1130 | 1132 | return; |
| 1131 | 1133 | |
| 1132 | 1134 | /* we have a full quad info, fill up our quad structure */ |
| 1133 | | model2_3d_process_quad( attr ); |
| 1135 | model2_3d_process_quad( raster, attr ); |
| 1134 | 1136 | |
| 1135 | 1137 | /* back up and wait for more data */ |
| 1136 | | raster.command_index = 8; |
| 1138 | raster->command_index = 8; |
| 1137 | 1139 | } |
| 1138 | 1140 | else |
| 1139 | 1141 | { |
| 1140 | 1142 | /* it's a triangle, wait for the rest of the point */ |
| 1141 | | if ( raster.command_index < 14 ) |
| 1143 | if ( raster->command_index < 14 ) |
| 1142 | 1144 | return; |
| 1143 | 1145 | |
| 1144 | 1146 | /* we have a full quad info, fill up our quad structure */ |
| 1145 | | model2_3d_process_triangle( attr ); |
| 1147 | model2_3d_process_triangle( raster, attr ); |
| 1146 | 1148 | |
| 1147 | 1149 | /* back up and wait for more data */ |
| 1148 | | raster.command_index = 8; |
| 1150 | raster->command_index = 8; |
| 1149 | 1151 | } |
| 1150 | 1152 | } |
| 1151 | 1153 | break; |
| r10427 | r10428 | |
| 1155 | 1157 | UINT32 i; |
| 1156 | 1158 | |
| 1157 | 1159 | /* make sure we have all the data */ |
| 1158 | | if ( raster.command_index < 6 ) |
| 1160 | if ( raster->command_index < 6 ) |
| 1159 | 1161 | return; |
| 1160 | 1162 | |
| 1161 | 1163 | /* coordinates are 12 bit signed */ |
| 1162 | 1164 | |
| 1163 | 1165 | /* extract the viewport start x */ |
| 1164 | | raster.viewport[0] = (raster.command_buffer[0] >> 12) & 0xFFF; |
| 1166 | raster->viewport[0] = (raster->command_buffer[0] >> 12) & 0xFFF; |
| 1165 | 1167 | |
| 1166 | | if ( raster.viewport[0] & 0x800 ) |
| 1167 | | raster.viewport[0] = -( 0x800 - (raster.viewport[0] & 0x7FF) ); |
| 1168 | if ( raster->viewport[0] & 0x800 ) |
| 1169 | raster->viewport[0] = -( 0x800 - (raster->viewport[0] & 0x7FF) ); |
| 1168 | 1170 | |
| 1169 | 1171 | /* extract the viewport start y */ |
| 1170 | | raster.viewport[1] = raster.command_buffer[0] & 0xFFF; |
| 1172 | raster->viewport[1] = raster->command_buffer[0] & 0xFFF; |
| 1171 | 1173 | |
| 1172 | | if ( raster.viewport[1] & 0x800 ) |
| 1173 | | raster.viewport[1] = -( 0x800 - (raster.viewport[1] & 0x7FF) ); |
| 1174 | if ( raster->viewport[1] & 0x800 ) |
| 1175 | raster->viewport[1] = -( 0x800 - (raster->viewport[1] & 0x7FF) ); |
| 1174 | 1176 | |
| 1175 | 1177 | /* extract the viewport end x */ |
| 1176 | | raster.viewport[2] = (raster.command_buffer[1] >> 12) & 0xFFF; |
| 1178 | raster->viewport[2] = (raster->command_buffer[1] >> 12) & 0xFFF; |
| 1177 | 1179 | |
| 1178 | | if ( raster.viewport[2] & 0x800 ) |
| 1179 | | raster.viewport[2] = -( 0x800 - (raster.viewport[2] & 0x7FF) ); |
| 1180 | if ( raster->viewport[2] & 0x800 ) |
| 1181 | raster->viewport[2] = -( 0x800 - (raster->viewport[2] & 0x7FF) ); |
| 1180 | 1182 | |
| 1181 | 1183 | /* extract the viewport end y */ |
| 1182 | | raster.viewport[3] = raster.command_buffer[1] & 0xFFF; |
| 1184 | raster->viewport[3] = raster->command_buffer[1] & 0xFFF; |
| 1183 | 1185 | |
| 1184 | | if ( raster.viewport[3] & 0x800 ) |
| 1185 | | raster.viewport[3] = -( 0x800 - (raster.viewport[3] & 0x7FF) ); |
| 1186 | if ( raster->viewport[3] & 0x800 ) |
| 1187 | raster->viewport[3] = -( 0x800 - (raster->viewport[3] & 0x7FF) ); |
| 1186 | 1188 | |
| 1187 | 1189 | /* extract the centers */ |
| 1188 | 1190 | for( i = 0; i < 4; i++ ) |
| 1189 | 1191 | { |
| 1190 | 1192 | /* center x */ |
| 1191 | | raster.center[i][0] = (raster.command_buffer[2+i] >> 12) & 0xFFF; |
| 1193 | raster->center[i][0] = (raster->command_buffer[2+i] >> 12) & 0xFFF; |
| 1192 | 1194 | |
| 1193 | | if ( raster.center[i][0] & 0x800 ) |
| 1194 | | raster.center[i][0] = -( 0x800 - (raster.center[i][0] & 0x7FF) ); |
| 1195 | if ( raster->center[i][0] & 0x800 ) |
| 1196 | raster->center[i][0] = -( 0x800 - (raster->center[i][0] & 0x7FF) ); |
| 1195 | 1197 | |
| 1196 | 1198 | /* center y */ |
| 1197 | | raster.center[i][1] = raster.command_buffer[2+i] & 0xFFF; |
| 1199 | raster->center[i][1] = raster->command_buffer[2+i] & 0xFFF; |
| 1198 | 1200 | |
| 1199 | | if ( raster.center[i][1] & 0x800 ) |
| 1200 | | raster.center[i][1] = -( 0x800 - (raster.center[i][1] & 0x7FF) ); |
| 1201 | if ( raster->center[i][1] & 0x800 ) |
| 1202 | raster->center[i][1] = -( 0x800 - (raster->center[i][1] & 0x7FF) ); |
| 1201 | 1203 | } |
| 1202 | 1204 | |
| 1203 | 1205 | /* done with this command */ |
| 1204 | | raster.cur_command = 0; |
| 1206 | raster->cur_command = 0; |
| 1205 | 1207 | } |
| 1206 | 1208 | break; |
| 1207 | 1209 | |
| 1208 | 1210 | case 0x04: /* Texture/Log Data write */ |
| 1209 | 1211 | { |
| 1210 | 1212 | /* make sure we have enough data */ |
| 1211 | | if ( raster.command_index < 2 ) |
| 1213 | if ( raster->command_index < 2 ) |
| 1212 | 1214 | return; |
| 1213 | 1215 | |
| 1214 | 1216 | /* see if the count is non-zero */ |
| 1215 | | if ( raster.command_buffer[1] > 0 ) |
| 1217 | if ( raster->command_buffer[1] > 0 ) |
| 1216 | 1218 | { |
| 1217 | 1219 | /* see if we have data available */ |
| 1218 | | if ( raster.command_index >= 3 ) |
| 1220 | if ( raster->command_index >= 3 ) |
| 1219 | 1221 | { |
| 1220 | 1222 | /* get the address */ |
| 1221 | | UINT32 address = raster.command_buffer[0]; |
| 1223 | UINT32 address = raster->command_buffer[0]; |
| 1222 | 1224 | |
| 1223 | 1225 | /* do the write */ |
| 1224 | 1226 | if ( address & 0x800000 ) |
| 1225 | | raster.texture_ram[address&0xFFFF] = raster.command_buffer[2]; |
| 1227 | raster->texture_ram[address&0xFFFF] = raster->command_buffer[2]; |
| 1226 | 1228 | else |
| 1227 | | raster.log_ram[address&0xFFFF] = raster.command_buffer[2]; |
| 1229 | raster->log_ram[address&0xFFFF] = raster->command_buffer[2]; |
| 1228 | 1230 | |
| 1229 | 1231 | /* increment the address and decrease the count */ |
| 1230 | | raster.command_buffer[0]++; |
| 1231 | | raster.command_buffer[1]--; |
| 1232 | raster->command_buffer[0]++; |
| 1233 | raster->command_buffer[1]--; |
| 1232 | 1234 | |
| 1233 | 1235 | /* decrease the index, so we keep placing data in the same slot */ |
| 1234 | | raster.command_index--; |
| 1236 | raster->command_index--; |
| 1235 | 1237 | } |
| 1236 | 1238 | } |
| 1237 | 1239 | |
| 1238 | 1240 | /* see if we're done with this command */ |
| 1239 | | if ( raster.command_buffer[1] == 0 ) |
| 1240 | | raster.cur_command = 0; |
| 1241 | if ( raster->command_buffer[1] == 0 ) |
| 1242 | raster->cur_command = 0; |
| 1241 | 1243 | } |
| 1242 | 1244 | break; |
| 1243 | 1245 | |
| 1244 | 1246 | case 0x08: /* ZSort mode */ |
| 1245 | 1247 | { |
| 1246 | 1248 | /* save the zsort mode value */ |
| 1247 | | raster.z_adjust = u2f( raster.command_buffer[0] << 8 ); |
| 1249 | raster->z_adjust = u2f( raster->command_buffer[0] << 8 ); |
| 1248 | 1250 | |
| 1249 | 1251 | /* done with this command */ |
| 1250 | | raster.cur_command = 0; |
| 1252 | raster->cur_command = 0; |
| 1251 | 1253 | } |
| 1252 | 1254 | break; |
| 1253 | 1255 | |
| 1254 | 1256 | default: |
| 1255 | 1257 | { |
| 1256 | | fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster.cur_command ); |
| 1258 | fatalerror( "SEGA 3D: Unknown rasterizer command %08x\n", raster->cur_command ); |
| 1257 | 1259 | } |
| 1258 | 1260 | break; |
| 1259 | 1261 | } |
| r10427 | r10428 | |
| 1261 | 1263 | else |
| 1262 | 1264 | { |
| 1263 | 1265 | /* new command */ |
| 1264 | | raster.cur_command = input & 0x0F; |
| 1265 | | raster.command_index = 0; |
| 1266 | raster->cur_command = input & 0x0F; |
| 1267 | raster->command_index = 0; |
| 1266 | 1268 | |
| 1267 | 1269 | /* see if it's object data */ |
| 1268 | | if ( raster.cur_command == 1 ) |
| 1270 | if ( raster->cur_command == 1 ) |
| 1269 | 1271 | { |
| 1270 | 1272 | /* extract reverse bit */ |
| 1271 | | raster.reverse = (input >> 4) & 1; |
| 1273 | raster->reverse = (input >> 4) & 1; |
| 1272 | 1274 | |
| 1273 | 1275 | /* extract center select */ |
| 1274 | | raster.center_sel = ( input >> 6 ) & 3; |
| 1276 | raster->center_sel = ( input >> 6 ) & 3; |
| 1275 | 1277 | |
| 1276 | 1278 | /* reset the triangle z value */ |
| 1277 | | raster.triangle_z = 0; |
| 1279 | raster->triangle_z = 0; |
| 1278 | 1280 | } |
| 1279 | 1281 | } |
| 1280 | 1282 | } |
| r10427 | r10428 | |
| 1289 | 1291 | * |
| 1290 | 1292 | *******************************************/ |
| 1291 | 1293 | |
| 1292 | | typedef struct |
| 1294 | struct _geo_state |
| 1293 | 1295 | { |
| 1296 | raster_state * raster; |
| 1294 | 1297 | UINT32 mode; /* bit 0 = Enable Specular, bit 1 = Calculate Normals */ |
| 1295 | 1298 | UINT32 * polygon_rom; /* Polygon ROM pointer */ |
| 1296 | | UINT32 * polygon_ram0; /* Fast Polygon RAM pointer */ |
| 1297 | | UINT32 * polygon_ram1; /* Slow Polygon RAM pointer */ |
| 1298 | 1299 | float matrix[12]; /* Current Transformation Matrix */ |
| 1299 | 1300 | poly_vertex focus; /* Focus (x,y) */ |
| 1300 | 1301 | poly_vertex light; /* Light Vector */ |
| 1301 | 1302 | float lod; /* LOD */ |
| 1302 | 1303 | float coef_table[32]; /* Distane Coefficient table */ |
| 1303 | 1304 | texture_parameter texture_parameters[32]; /* Texture parameters */ |
| 1304 | | } geo_state; |
| 1305 | UINT32 polygon_ram0[0x8000]; /* Fast Polygon RAM pointer */ |
| 1306 | UINT32 polygon_ram1[0x8000]; /* Slow Polygon RAM pointer */ |
| 1307 | }; |
| 1305 | 1308 | |
| 1306 | | static geo_state geo; |
| 1307 | 1309 | |
| 1308 | 1310 | /******************************************* |
| 1309 | 1311 | * |
| r10427 | r10428 | |
| 1313 | 1315 | |
| 1314 | 1316 | static void geo_init( running_machine *machine, UINT32 *polygon_rom ) |
| 1315 | 1317 | { |
| 1316 | | memset( &geo, 0, sizeof( geo_state ) ); |
| 1318 | model2_state *state = machine->driver_data<model2_state>(); |
| 1319 | state->geo = auto_alloc_clear(machine, geo_state); |
| 1317 | 1320 | |
| 1318 | | geo.polygon_rom = polygon_rom; |
| 1319 | | geo.polygon_ram0 = auto_alloc_array(machine, UINT32, 0x8000); |
| 1320 | | geo.polygon_ram1 = auto_alloc_array(machine, UINT32, 0x8000); |
| 1321 | state->geo->raster = state->raster; |
| 1322 | state->geo->polygon_rom = polygon_rom; |
| 1321 | 1323 | } |
| 1322 | 1324 | |
| 1323 | 1325 | /******************************************* |
| r10427 | r10428 | |
| 1327 | 1329 | *******************************************/ |
| 1328 | 1330 | |
| 1329 | 1331 | /* Parse Polygons: Normals Present, No Specular case */ |
| 1330 | | static void geo_parse_np_ns( UINT32 *input, UINT32 count ) |
| 1332 | static void geo_parse_np_ns( geo_state *geo, UINT32 *input, UINT32 count ) |
| 1331 | 1333 | { |
| 1334 | raster_state *raster = geo->raster; |
| 1332 | 1335 | poly_vertex point, normal; |
| 1333 | 1336 | UINT32 attr, i; |
| 1334 | 1337 | |
| r10427 | r10428 | |
| 1338 | 1341 | point.pz = u2f( *input++ ); |
| 1339 | 1342 | |
| 1340 | 1343 | /* transform with the current matrix */ |
| 1341 | | transform_point( &point, geo.matrix ); |
| 1344 | transform_point( &point, geo->matrix ); |
| 1342 | 1345 | |
| 1343 | 1346 | /* apply focus */ |
| 1344 | | point.x *= geo.focus.x; |
| 1345 | | point.y *= geo.focus.y; |
| 1347 | point.x *= geo->focus.x; |
| 1348 | point.y *= geo->focus.y; |
| 1346 | 1349 | |
| 1347 | 1350 | /* push it to the 3d rasterizer */ |
| 1348 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1349 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1350 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1351 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1352 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1353 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1351 | 1354 | |
| 1352 | 1355 | /* read the 2nd point */ |
| 1353 | 1356 | point.x = u2f( *input++ ); |
| r10427 | r10428 | |
| 1355 | 1358 | point.pz = u2f( *input++ ); |
| 1356 | 1359 | |
| 1357 | 1360 | /* transform with the current matrix */ |
| 1358 | | transform_point( &point, geo.matrix ); |
| 1361 | transform_point( &point, geo->matrix ); |
| 1359 | 1362 | |
| 1360 | 1363 | /* apply focus */ |
| 1361 | | point.x *= geo.focus.x; |
| 1362 | | point.y *= geo.focus.y; |
| 1364 | point.x *= geo->focus.x; |
| 1365 | point.y *= geo->focus.y; |
| 1363 | 1366 | |
| 1364 | 1367 | /* push it to the 3d rasterizer */ |
| 1365 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1366 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1367 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1368 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1369 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1370 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1368 | 1371 | |
| 1369 | 1372 | /* loop through the following links */ |
| 1370 | 1373 | for( i = 0; i < count; i++ ) |
| r10427 | r10428 | |
| 1373 | 1376 | attr = *input++; |
| 1374 | 1377 | |
| 1375 | 1378 | /* push to the 3d rasterizer */ |
| 1376 | | model2_3d_push( attr & 0x0003FFFF ); |
| 1379 | model2_3d_push( raster, attr & 0x0003FFFF ); |
| 1377 | 1380 | |
| 1378 | 1381 | /* read in the normal */ |
| 1379 | 1382 | normal.x = u2f(*input++); |
| r10427 | r10428 | |
| 1381 | 1384 | normal.pz = u2f(*input++); |
| 1382 | 1385 | |
| 1383 | 1386 | /* transform with the current matrix */ |
| 1384 | | transform_vector( &normal, geo.matrix ); |
| 1387 | transform_vector( &normal, geo->matrix ); |
| 1385 | 1388 | |
| 1386 | 1389 | if ( (attr & 3) != 0 ) /* quad or triangle */ |
| 1387 | 1390 | { |
| r10427 | r10428 | |
| 1396 | 1399 | point.pz = u2f( *input++ ); |
| 1397 | 1400 | |
| 1398 | 1401 | /* transform with the current matrix */ |
| 1399 | | transform_point( &point, geo.matrix ); |
| 1402 | transform_point( &point, geo->matrix ); |
| 1400 | 1403 | |
| 1401 | 1404 | /* calculate the dot product of the normal and the light vector */ |
| 1402 | | dotl = dot_product( &normal, &geo.light ); |
| 1405 | dotl = dot_product( &normal, &geo->light ); |
| 1403 | 1406 | |
| 1404 | 1407 | /* calculate the dot product of the normal and the point */ |
| 1405 | 1408 | dotp = dot_product( &normal, &point ); |
| 1406 | 1409 | |
| 1407 | 1410 | /* apply focus */ |
| 1408 | | point.x *= geo.focus.x; |
| 1409 | | point.y *= geo.focus.y; |
| 1411 | point.x *= geo->focus.x; |
| 1412 | point.y *= geo->focus.y; |
| 1410 | 1413 | |
| 1411 | 1414 | /* determine wether this is the front or the back of the polygon */ |
| 1412 | 1415 | face = 0x100; /* rear */ |
| 1413 | 1416 | if ( dotp >= 0 ) face = 0; /* front */ |
| 1414 | 1417 | |
| 1415 | 1418 | /* get the texture parameters */ |
| 1416 | | texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; |
| 1419 | texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; |
| 1417 | 1420 | |
| 1418 | 1421 | /* calculate luminance */ |
| 1419 | 1422 | if ( (dotl * dotp) < 0 ) luminance = 0; |
| r10427 | r10428 | |
| 1429 | 1432 | luma += face; |
| 1430 | 1433 | |
| 1431 | 1434 | /* extract distance coefficient */ |
| 1432 | | coef = geo.coef_table[attr>>27]; |
| 1435 | coef = geo->coef_table[attr>>27]; |
| 1433 | 1436 | |
| 1434 | 1437 | /* calculate texture level of detail */ |
| 1435 | | distance = coef * fabs( dotp ) * geo.lod; |
| 1438 | distance = coef * fabs( dotp ) * geo->lod; |
| 1436 | 1439 | |
| 1437 | 1440 | /* push to the 3d rasterizer */ |
| 1438 | | model2_3d_push( luma << 15 ); |
| 1439 | | model2_3d_push( f2u(distance) >> 8 ); |
| 1440 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1441 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1442 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1441 | model2_3d_push( raster, luma << 15 ); |
| 1442 | model2_3d_push( raster, f2u(distance) >> 8 ); |
| 1443 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1444 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1445 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1443 | 1446 | |
| 1444 | 1447 | /* if it's a quad, push one more point */ |
| 1445 | 1448 | if ( attr & 1 ) |
| r10427 | r10428 | |
| 1450 | 1453 | point.pz = u2f( *input++ ); |
| 1451 | 1454 | |
| 1452 | 1455 | /* transform with the current matrix */ |
| 1453 | | transform_point( &point, geo.matrix ); |
| 1456 | transform_point( &point, geo->matrix ); |
| 1454 | 1457 | |
| 1455 | 1458 | /* apply focus */ |
| 1456 | | point.x *= geo.focus.x; |
| 1457 | | point.y *= geo.focus.y; |
| 1459 | point.x *= geo->focus.x; |
| 1460 | point.y *= geo->focus.y; |
| 1458 | 1461 | |
| 1459 | 1462 | /* push to the 3d rasterizer */ |
| 1460 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1461 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1462 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1463 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1464 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1465 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1463 | 1466 | } |
| 1464 | 1467 | else /* triangle */ |
| 1465 | 1468 | { |
| r10427 | r10428 | |
| 1474 | 1477 | } |
| 1475 | 1478 | |
| 1476 | 1479 | /* notify the 3d rasterizer we're done */ |
| 1477 | | model2_3d_push( 0 ); |
| 1480 | model2_3d_push( raster, 0 ); |
| 1478 | 1481 | } |
| 1479 | 1482 | |
| 1480 | 1483 | /* Parse Polygons: Normals Present, Specular case */ |
| 1481 | | static void geo_parse_np_s( UINT32 *input, UINT32 count ) |
| 1484 | static void geo_parse_np_s( geo_state *geo, UINT32 *input, UINT32 count ) |
| 1482 | 1485 | { |
| 1486 | raster_state *raster = geo->raster; |
| 1483 | 1487 | poly_vertex point, normal; |
| 1484 | 1488 | UINT32 attr, i; |
| 1485 | 1489 | |
| r10427 | r10428 | |
| 1489 | 1493 | point.pz = u2f( *input++ ); |
| 1490 | 1494 | |
| 1491 | 1495 | /* transform with the current matrix */ |
| 1492 | | transform_point( &point, geo.matrix ); |
| 1496 | transform_point( &point, geo->matrix ); |
| 1493 | 1497 | |
| 1494 | 1498 | /* apply focus */ |
| 1495 | | point.x *= geo.focus.x; |
| 1496 | | point.y *= geo.focus.y; |
| 1499 | point.x *= geo->focus.x; |
| 1500 | point.y *= geo->focus.y; |
| 1497 | 1501 | |
| 1498 | 1502 | /* push it to the 3d rasterizer */ |
| 1499 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1500 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1501 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1503 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1504 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1505 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1502 | 1506 | |
| 1503 | 1507 | /* read the 2nd point */ |
| 1504 | 1508 | point.x = u2f( *input++ ); |
| r10427 | r10428 | |
| 1506 | 1510 | point.pz = u2f( *input++ ); |
| 1507 | 1511 | |
| 1508 | 1512 | /* transform with the current matrix */ |
| 1509 | | transform_point( &point, geo.matrix ); |
| 1513 | transform_point( &point, geo->matrix ); |
| 1510 | 1514 | |
| 1511 | 1515 | /* apply focus */ |
| 1512 | | point.x *= geo.focus.x; |
| 1513 | | point.y *= geo.focus.y; |
| 1516 | point.x *= geo->focus.x; |
| 1517 | point.y *= geo->focus.y; |
| 1514 | 1518 | |
| 1515 | 1519 | /* push it to the 3d rasterizer */ |
| 1516 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1517 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1518 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1520 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1521 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1522 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1519 | 1523 | |
| 1520 | 1524 | /* loop through the following links */ |
| 1521 | 1525 | for( i = 0; i < count; i++ ) |
| r10427 | r10428 | |
| 1524 | 1528 | attr = *input++; |
| 1525 | 1529 | |
| 1526 | 1530 | /* push to the 3d rasterizer */ |
| 1527 | | model2_3d_push( attr & 0x0003FFFF ); |
| 1531 | model2_3d_push( raster, attr & 0x0003FFFF ); |
| 1528 | 1532 | |
| 1529 | 1533 | /* read in the normal */ |
| 1530 | 1534 | normal.x = u2f(*input++); |
| r10427 | r10428 | |
| 1532 | 1536 | normal.pz = u2f(*input++); |
| 1533 | 1537 | |
| 1534 | 1538 | /* transform with the current matrix */ |
| 1535 | | transform_vector( &normal, geo.matrix ); |
| 1539 | transform_vector( &normal, geo->matrix ); |
| 1536 | 1540 | |
| 1537 | 1541 | if ( (attr & 3) != 0 ) /* quad or triangle */ |
| 1538 | 1542 | { |
| r10427 | r10428 | |
| 1547 | 1551 | point.pz = u2f( *input++ ); |
| 1548 | 1552 | |
| 1549 | 1553 | /* transform with the current matrix */ |
| 1550 | | transform_point( &point, geo.matrix ); |
| 1554 | transform_point( &point, geo->matrix ); |
| 1551 | 1555 | |
| 1552 | 1556 | /* calculate the dot product of the normal and the light vector */ |
| 1553 | | dotl = dot_product( &normal, &geo.light ); |
| 1557 | dotl = dot_product( &normal, &geo->light ); |
| 1554 | 1558 | |
| 1555 | 1559 | /* calculate the dot product of the normal and the point */ |
| 1556 | 1560 | dotp = dot_product( &normal, &point ); |
| 1557 | 1561 | |
| 1558 | 1562 | /* apply focus */ |
| 1559 | | point.x *= geo.focus.x; |
| 1560 | | point.y *= geo.focus.y; |
| 1563 | point.x *= geo->focus.x; |
| 1564 | point.y *= geo->focus.y; |
| 1561 | 1565 | |
| 1562 | 1566 | /* determine wether this is the front or the back of the polygon */ |
| 1563 | 1567 | face = 0x100; /* rear */ |
| 1564 | 1568 | if ( dotp >= 0 ) face = 0; /* front */ |
| 1565 | 1569 | |
| 1566 | 1570 | /* get the texture parameters */ |
| 1567 | | texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; |
| 1571 | texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; |
| 1568 | 1572 | |
| 1569 | 1573 | /* calculate luminance and specular */ |
| 1570 | 1574 | if ( (dotl * dotp) < 0 ) luminance = 0; |
| 1571 | 1575 | else luminance = fabs( dotl ); |
| 1572 | 1576 | |
| 1573 | | specular = ((2*dotl) * normal.pz) - geo.light.pz; |
| 1577 | specular = ((2*dotl) * normal.pz) - geo->light.pz; |
| 1574 | 1578 | if ( specular < 0 ) specular = 0; |
| 1575 | 1579 | if ( texparam->specular_control == 0 ) specular = 0; |
| 1576 | 1580 | if ( (texparam->specular_control >> 1) != 0 ) specular *= specular; |
| r10427 | r10428 | |
| 1589 | 1593 | luma += face; |
| 1590 | 1594 | |
| 1591 | 1595 | /* extract distance coefficient */ |
| 1592 | | coef = geo.coef_table[attr>>27]; |
| 1596 | coef = geo->coef_table[attr>>27]; |
| 1593 | 1597 | |
| 1594 | 1598 | /* calculate texture level of detail */ |
| 1595 | | distance = coef * fabs( dotp ) * geo.lod; |
| 1599 | distance = coef * fabs( dotp ) * geo->lod; |
| 1596 | 1600 | |
| 1597 | 1601 | /* push to the 3d rasterizer */ |
| 1598 | | model2_3d_push( luma << 15 ); |
| 1599 | | model2_3d_push( f2u(distance) >> 8 ); |
| 1600 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1601 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1602 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1602 | model2_3d_push( raster, luma << 15 ); |
| 1603 | model2_3d_push( raster, f2u(distance) >> 8 ); |
| 1604 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1605 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1606 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1603 | 1607 | |
| 1604 | 1608 | /* if it's a quad, push one more point */ |
| 1605 | 1609 | if ( attr & 1 ) |
| r10427 | r10428 | |
| 1610 | 1614 | point.pz = u2f( *input++ ); |
| 1611 | 1615 | |
| 1612 | 1616 | /* transform with the current matrix */ |
| 1613 | | transform_point( &point, geo.matrix ); |
| 1617 | transform_point( &point, geo->matrix ); |
| 1614 | 1618 | |
| 1615 | 1619 | /* apply focus */ |
| 1616 | | point.x *= geo.focus.x; |
| 1617 | | point.y *= geo.focus.y; |
| 1620 | point.x *= geo->focus.x; |
| 1621 | point.y *= geo->focus.y; |
| 1618 | 1622 | |
| 1619 | 1623 | /* push to the 3d rasterizer */ |
| 1620 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1621 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1622 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1624 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1625 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1626 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1623 | 1627 | } |
| 1624 | 1628 | else /* triangle */ |
| 1625 | 1629 | { |
| r10427 | r10428 | |
| 1634 | 1638 | } |
| 1635 | 1639 | |
| 1636 | 1640 | /* notify the 3d rasterizer we're done */ |
| 1637 | | model2_3d_push( 0 ); |
| 1641 | model2_3d_push( raster, 0 ); |
| 1638 | 1642 | } |
| 1639 | 1643 | |
| 1640 | 1644 | /* Parse Polygons: No Normals, No Specular case */ |
| 1641 | | static void geo_parse_nn_ns( UINT32 *input, UINT32 count ) |
| 1645 | static void geo_parse_nn_ns( geo_state *geo, UINT32 *input, UINT32 count ) |
| 1642 | 1646 | { |
| 1647 | raster_state *raster = geo->raster; |
| 1643 | 1648 | poly_vertex point, normal, p0, p1, p2, p3; |
| 1644 | 1649 | UINT32 attr, i; |
| 1645 | 1650 | |
| r10427 | r10428 | |
| 1649 | 1654 | point.pz = u2f( *input++ ); |
| 1650 | 1655 | |
| 1651 | 1656 | /* transform with the current matrix */ |
| 1652 | | transform_point( &point, geo.matrix ); |
| 1657 | transform_point( &point, geo->matrix ); |
| 1653 | 1658 | |
| 1654 | 1659 | /* save for normal calculation */ |
| 1655 | 1660 | p0.x = point.x; p0.y = point.y; p0.pz = point.pz; |
| 1656 | 1661 | |
| 1657 | 1662 | /* apply focus */ |
| 1658 | | point.x *= geo.focus.x; |
| 1659 | | point.y *= geo.focus.y; |
| 1663 | point.x *= geo->focus.x; |
| 1664 | point.y *= geo->focus.y; |
| 1660 | 1665 | |
| 1661 | 1666 | /* push it to the 3d rasterizer */ |
| 1662 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1663 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1664 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1667 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1668 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1669 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1665 | 1670 | |
| 1666 | 1671 | /* read the 2nd point */ |
| 1667 | 1672 | point.x = u2f( *input++ ); |
| r10427 | r10428 | |
| 1669 | 1674 | point.pz = u2f( *input++ ); |
| 1670 | 1675 | |
| 1671 | 1676 | /* transform with the current matrix */ |
| 1672 | | transform_point( &point, geo.matrix ); |
| 1677 | transform_point( &point, geo->matrix ); |
| 1673 | 1678 | |
| 1674 | 1679 | /* save for normal calculation */ |
| 1675 | 1680 | p1.x = point.x; p1.y = point.y; p1.pz = point.pz; |
| 1676 | 1681 | |
| 1677 | 1682 | /* apply focus */ |
| 1678 | | point.x *= geo.focus.x; |
| 1679 | | point.y *= geo.focus.y; |
| 1683 | point.x *= geo->focus.x; |
| 1684 | point.y *= geo->focus.y; |
| 1680 | 1685 | |
| 1681 | 1686 | /* push it to the 3d rasterizer */ |
| 1682 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1683 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1684 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1687 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1688 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1689 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1685 | 1690 | |
| 1686 | 1691 | /* skip 4 */ |
| 1687 | 1692 | input += 4; |
| r10427 | r10428 | |
| 1693 | 1698 | attr = *input++; |
| 1694 | 1699 | |
| 1695 | 1700 | /* push to the 3d rasterizer */ |
| 1696 | | model2_3d_push( attr & 0x0003FFFF ); |
| 1701 | model2_3d_push( raster, attr & 0x0003FFFF ); |
| 1697 | 1702 | |
| 1698 | 1703 | if ( (attr & 3) != 0 ) /* quad or triangle */ |
| 1699 | 1704 | { |
| r10427 | r10428 | |
| 1708 | 1713 | point.pz = u2f( *input++ ); |
| 1709 | 1714 | |
| 1710 | 1715 | /* transform with the current matrix */ |
| 1711 | | transform_point( &point, geo.matrix ); |
| 1716 | transform_point( &point, geo->matrix ); |
| 1712 | 1717 | |
| 1713 | 1718 | /* save for normal calculation */ |
| 1714 | 1719 | p2.x = point.x; p2.y = point.y; p2.pz = point.pz; |
| r10427 | r10428 | |
| 1720 | 1725 | normalize_vector( &normal ); |
| 1721 | 1726 | |
| 1722 | 1727 | /* calculate the dot product of the normal and the light vector */ |
| 1723 | | dotl = dot_product( &normal, &geo.light ); |
| 1728 | dotl = dot_product( &normal, &geo->light ); |
| 1724 | 1729 | |
| 1725 | 1730 | /* calculate the dot product of the normal and the point */ |
| 1726 | 1731 | dotp = dot_product( &normal, &point ); |
| 1727 | 1732 | |
| 1728 | 1733 | /* apply focus */ |
| 1729 | | point.x *= geo.focus.x; |
| 1730 | | point.y *= geo.focus.y; |
| 1734 | point.x *= geo->focus.x; |
| 1735 | point.y *= geo->focus.y; |
| 1731 | 1736 | |
| 1732 | 1737 | /* determine wether this is the front or the back of the polygon */ |
| 1733 | 1738 | face = 0x100; /* rear */ |
| 1734 | 1739 | if ( dotp >= 0 ) face = 0; /* front */ |
| 1735 | 1740 | |
| 1736 | 1741 | /* get the texture parameters */ |
| 1737 | | texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; |
| 1742 | texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; |
| 1738 | 1743 | |
| 1739 | 1744 | /* calculate luminance */ |
| 1740 | 1745 | if ( (dotl * dotp) < 0 ) luminance = 0; |
| r10427 | r10428 | |
| 1750 | 1755 | luma += face; |
| 1751 | 1756 | |
| 1752 | 1757 | /* extract distance coefficient */ |
| 1753 | | coef = geo.coef_table[attr>>27]; |
| 1758 | coef = geo->coef_table[attr>>27]; |
| 1754 | 1759 | |
| 1755 | 1760 | /* calculate texture level of detail */ |
| 1756 | | distance = coef * fabs( dotp ) * geo.lod; |
| 1761 | distance = coef * fabs( dotp ) * geo->lod; |
| 1757 | 1762 | |
| 1758 | 1763 | /* push to the 3d rasterizer */ |
| 1759 | | model2_3d_push( luma << 15 ); |
| 1760 | | model2_3d_push( f2u(distance) >> 8 ); |
| 1761 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1762 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1763 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1764 | model2_3d_push( raster, luma << 15 ); |
| 1765 | model2_3d_push( raster, f2u(distance) >> 8 ); |
| 1766 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1767 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1768 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1764 | 1769 | |
| 1765 | 1770 | /* if it's a quad, push one more point */ |
| 1766 | 1771 | if ( attr & 1 ) |
| r10427 | r10428 | |
| 1771 | 1776 | point.pz = u2f( *input++ ); |
| 1772 | 1777 | |
| 1773 | 1778 | /* transform with the current matrix */ |
| 1774 | | transform_point( &point, geo.matrix ); |
| 1779 | transform_point( &point, geo->matrix ); |
| 1775 | 1780 | |
| 1776 | 1781 | /* save for normal calculation */ |
| 1777 | 1782 | p3.x = point.x; p3.y = point.y; p3.pz = point.pz; |
| 1778 | 1783 | |
| 1779 | 1784 | /* apply focus */ |
| 1780 | | point.x *= geo.focus.x; |
| 1781 | | point.y *= geo.focus.y; |
| 1785 | point.x *= geo->focus.x; |
| 1786 | point.y *= geo->focus.y; |
| 1782 | 1787 | |
| 1783 | 1788 | /* push to the 3d rasterizer */ |
| 1784 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1785 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1786 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1789 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1790 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1791 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1787 | 1792 | } |
| 1788 | 1793 | else |
| 1789 | 1794 | { |
| r10427 | r10428 | |
| 1828 | 1833 | } |
| 1829 | 1834 | |
| 1830 | 1835 | /* notify the 3d rasterizer we're done */ |
| 1831 | | model2_3d_push( 0 ); |
| 1836 | model2_3d_push( raster, 0 ); |
| 1832 | 1837 | } |
| 1833 | 1838 | |
| 1834 | 1839 | /* Parse Polygons: No Normals, Specular case */ |
| 1835 | | static void geo_parse_nn_s( UINT32 *input, UINT32 count ) |
| 1840 | static void geo_parse_nn_s( geo_state *geo, UINT32 *input, UINT32 count ) |
| 1836 | 1841 | { |
| 1842 | raster_state *raster = geo->raster; |
| 1837 | 1843 | poly_vertex point, normal, p0, p1, p2, p3; |
| 1838 | 1844 | UINT32 attr, i; |
| 1839 | 1845 | |
| r10427 | r10428 | |
| 1843 | 1849 | point.pz = u2f( *input++ ); |
| 1844 | 1850 | |
| 1845 | 1851 | /* transform with the current matrix */ |
| 1846 | | transform_point( &point, geo.matrix ); |
| 1852 | transform_point( &point, geo->matrix ); |
| 1847 | 1853 | |
| 1848 | 1854 | /* save for normal calculation */ |
| 1849 | 1855 | p0.x = point.x; p0.y = point.y; p0.pz = point.pz; |
| 1850 | 1856 | |
| 1851 | 1857 | /* apply focus */ |
| 1852 | | point.x *= geo.focus.x; |
| 1853 | | point.y *= geo.focus.y; |
| 1858 | point.x *= geo->focus.x; |
| 1859 | point.y *= geo->focus.y; |
| 1854 | 1860 | |
| 1855 | 1861 | /* push it to the 3d rasterizer */ |
| 1856 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1857 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1858 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1862 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1863 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1864 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1859 | 1865 | |
| 1860 | 1866 | /* read the 2nd point */ |
| 1861 | 1867 | point.x = u2f( *input++ ); |
| r10427 | r10428 | |
| 1863 | 1869 | point.pz = u2f( *input++ ); |
| 1864 | 1870 | |
| 1865 | 1871 | /* transform with the current matrix */ |
| 1866 | | transform_point( &point, geo.matrix ); |
| 1872 | transform_point( &point, geo->matrix ); |
| 1867 | 1873 | |
| 1868 | 1874 | /* save for normal calculation */ |
| 1869 | 1875 | p1.x = point.x; p1.y = point.y; p1.pz = point.pz; |
| 1870 | 1876 | |
| 1871 | 1877 | /* apply focus */ |
| 1872 | | point.x *= geo.focus.x; |
| 1873 | | point.y *= geo.focus.y; |
| 1878 | point.x *= geo->focus.x; |
| 1879 | point.y *= geo->focus.y; |
| 1874 | 1880 | |
| 1875 | 1881 | /* push it to the 3d rasterizer */ |
| 1876 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1877 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1878 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1882 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1883 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1884 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1879 | 1885 | |
| 1880 | 1886 | /* skip 4 */ |
| 1881 | 1887 | input += 4; |
| r10427 | r10428 | |
| 1887 | 1893 | attr = *input++; |
| 1888 | 1894 | |
| 1889 | 1895 | /* push to the 3d rasterizer */ |
| 1890 | | model2_3d_push( attr & 0x0003FFFF ); |
| 1896 | model2_3d_push( raster, attr & 0x0003FFFF ); |
| 1891 | 1897 | |
| 1892 | 1898 | if ( (attr & 3) != 0 ) /* quad or triangle */ |
| 1893 | 1899 | { |
| r10427 | r10428 | |
| 1902 | 1908 | point.pz = u2f( *input++ ); |
| 1903 | 1909 | |
| 1904 | 1910 | /* transform with the current matrix */ |
| 1905 | | transform_point( &point, geo.matrix ); |
| 1911 | transform_point( &point, geo->matrix ); |
| 1906 | 1912 | |
| 1907 | 1913 | /* save for normal calculation */ |
| 1908 | 1914 | p2.x = point.x; p2.y = point.y; p2.pz = point.pz; |
| r10427 | r10428 | |
| 1914 | 1920 | normalize_vector( &normal ); |
| 1915 | 1921 | |
| 1916 | 1922 | /* calculate the dot product of the normal and the light vector */ |
| 1917 | | dotl = dot_product( &normal, &geo.light ); |
| 1923 | dotl = dot_product( &normal, &geo->light ); |
| 1918 | 1924 | |
| 1919 | 1925 | /* calculate the dot product of the normal and the point */ |
| 1920 | 1926 | dotp = dot_product( &normal, &point ); |
| 1921 | 1927 | |
| 1922 | 1928 | /* apply focus */ |
| 1923 | | point.x *= geo.focus.x; |
| 1924 | | point.y *= geo.focus.y; |
| 1929 | point.x *= geo->focus.x; |
| 1930 | point.y *= geo->focus.y; |
| 1925 | 1931 | |
| 1926 | 1932 | /* determine wether this is the front or the back of the polygon */ |
| 1927 | 1933 | face = 0x100; /* rear */ |
| 1928 | 1934 | if ( dotp >= 0 ) face = 0; /* front */ |
| 1929 | 1935 | |
| 1930 | 1936 | /* get the texture parameters */ |
| 1931 | | texparam = &geo.texture_parameters[(attr>>18) & 0x1f]; |
| 1937 | texparam = &geo->texture_parameters[(attr>>18) & 0x1f]; |
| 1932 | 1938 | |
| 1933 | 1939 | /* calculate luminance and specular */ |
| 1934 | 1940 | if ( (dotl * dotp) < 0 ) luminance = 0; |
| 1935 | 1941 | else luminance = fabs( dotl ); |
| 1936 | 1942 | |
| 1937 | | specular = ((2*dotl) * normal.pz) - geo.light.pz; |
| 1943 | specular = ((2*dotl) * normal.pz) - geo->light.pz; |
| 1938 | 1944 | if ( specular < 0 ) specular = 0; |
| 1939 | 1945 | if ( texparam->specular_control == 0 ) specular = 0; |
| 1940 | 1946 | if ( (texparam->specular_control >> 1) != 0 ) specular *= specular; |
| r10427 | r10428 | |
| 1953 | 1959 | luma += face; |
| 1954 | 1960 | |
| 1955 | 1961 | /* extract distance coefficient */ |
| 1956 | | coef = geo.coef_table[attr>>27]; |
| 1962 | coef = geo->coef_table[attr>>27]; |
| 1957 | 1963 | |
| 1958 | 1964 | /* calculate texture level of detail */ |
| 1959 | | distance = coef * fabs( dotp ) * geo.lod; |
| 1965 | distance = coef * fabs( dotp ) * geo->lod; |
| 1960 | 1966 | |
| 1961 | 1967 | /* push to the 3d rasterizer */ |
| 1962 | | model2_3d_push( luma << 15 ); |
| 1963 | | model2_3d_push( f2u(distance) >> 8 ); |
| 1964 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1965 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1966 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1968 | model2_3d_push( raster, luma << 15 ); |
| 1969 | model2_3d_push( raster, f2u(distance) >> 8 ); |
| 1970 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1971 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1972 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1967 | 1973 | |
| 1968 | 1974 | /* if it's a quad, push one more point */ |
| 1969 | 1975 | if ( attr & 1 ) |
| r10427 | r10428 | |
| 1974 | 1980 | point.pz = u2f( *input++ ); |
| 1975 | 1981 | |
| 1976 | 1982 | /* transform with the current matrix */ |
| 1977 | | transform_point( &point, geo.matrix ); |
| 1983 | transform_point( &point, geo->matrix ); |
| 1978 | 1984 | |
| 1979 | 1985 | /* save for normal calculation */ |
| 1980 | 1986 | p3.x = point.x; p3.y = point.y; p3.pz = point.pz; |
| 1981 | 1987 | |
| 1982 | 1988 | /* apply focus */ |
| 1983 | | point.x *= geo.focus.x; |
| 1984 | | point.y *= geo.focus.y; |
| 1989 | point.x *= geo->focus.x; |
| 1990 | point.y *= geo->focus.y; |
| 1985 | 1991 | |
| 1986 | 1992 | /* push to the 3d rasterizer */ |
| 1987 | | model2_3d_push( f2u(point.x) >> 8 ); |
| 1988 | | model2_3d_push( f2u(point.y) >> 8 ); |
| 1989 | | model2_3d_push( f2u(point.pz) >> 8 ); |
| 1993 | model2_3d_push( raster, f2u(point.x) >> 8 ); |
| 1994 | model2_3d_push( raster, f2u(point.y) >> 8 ); |
| 1995 | model2_3d_push( raster, f2u(point.pz) >> 8 ); |
| 1990 | 1996 | } |
| 1991 | 1997 | else |
| 1992 | 1998 | { |
| r10427 | r10428 | |
| 2031 | 2037 | } |
| 2032 | 2038 | |
| 2033 | 2039 | /* notify the 3d rasterizer we're done */ |
| 2034 | | model2_3d_push( 0 ); |
| 2040 | model2_3d_push( raster, 0 ); |
| 2035 | 2041 | } |
| 2036 | 2042 | |
| 2037 | 2043 | /******************************************* |
| r10427 | r10428 | |
| 2041 | 2047 | *******************************************/ |
| 2042 | 2048 | |
| 2043 | 2049 | /* Command 00: NOP */ |
| 2044 | | static UINT32 * geo_nop( UINT32 opcode, UINT32 *input ) |
| 2050 | static UINT32 * geo_nop( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2045 | 2051 | { |
| 2052 | raster_state *raster = geo->raster; |
| 2053 | |
| 2046 | 2054 | /* push the opcode to the 3d rasterizer */ |
| 2047 | | model2_3d_push( opcode >> 23 ); |
| 2055 | model2_3d_push( raster, opcode >> 23 ); |
| 2048 | 2056 | |
| 2049 | 2057 | return input; |
| 2050 | 2058 | } |
| 2051 | 2059 | |
| 2052 | 2060 | /* Command 01: Object Data */ |
| 2053 | | static UINT32 * geo_object_data( UINT32 opcode, UINT32 *input ) |
| 2061 | static UINT32 * geo_object_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2054 | 2062 | { |
| 2063 | raster_state *raster = geo->raster; |
| 2055 | 2064 | UINT32 tpa = *input++; /* Texture Point Address */ |
| 2056 | 2065 | UINT32 tha = *input++; /* Texture Header Address */ |
| 2057 | 2066 | UINT32 oba = *input++; /* Object Address */ |
| r10427 | r10428 | |
| 2060 | 2069 | UINT32 *obp; /* Object Pointer */ |
| 2061 | 2070 | |
| 2062 | 2071 | /* push the initial set of data to the 3d rasterizer */ |
| 2063 | | model2_3d_push( opcode >> 23 ); |
| 2064 | | model2_3d_push( tpa ); |
| 2065 | | model2_3d_push( tha ); |
| 2072 | model2_3d_push( raster, opcode >> 23 ); |
| 2073 | model2_3d_push( raster, tpa ); |
| 2074 | model2_3d_push( raster, tha ); |
| 2066 | 2075 | |
| 2067 | 2076 | /* select where we're reading polygon information from */ |
| 2068 | 2077 | if ( oba & 0x01000000 ) |
| 2069 | 2078 | { |
| 2070 | 2079 | /* Fast polygon RAM */ |
| 2071 | | obp = &geo.polygon_ram0[oba & 0x7FFF]; |
| 2080 | obp = &geo->polygon_ram0[oba & 0x7FFF]; |
| 2072 | 2081 | } |
| 2073 | 2082 | else if ( oba & 0x00800000 ) |
| 2074 | 2083 | { |
| 2075 | 2084 | /* Polygon ROM */ |
| 2076 | | obp = &geo.polygon_rom[oba & 0x7FFFFF]; |
| 2085 | obp = &geo->polygon_rom[oba & 0x7FFFFF]; |
| 2077 | 2086 | } |
| 2078 | 2087 | else |
| 2079 | 2088 | { |
| 2080 | 2089 | /* Slow Polygon RAM */ |
| 2081 | | obp = &geo.polygon_ram1[oba & 0x7FFF]; |
| 2090 | obp = &geo->polygon_ram1[oba & 0x7FFF]; |
| 2082 | 2091 | } |
| 2083 | 2092 | |
| 2084 | | switch( geo.mode & 3 ) |
| 2093 | switch( geo->mode & 3 ) |
| 2085 | 2094 | { |
| 2086 | 2095 | /* Normals present, No Specular */ |
| 2087 | | case 0: geo_parse_np_ns( obp, obc ); break; |
| 2096 | case 0: geo_parse_np_ns( geo, obp, obc ); break; |
| 2088 | 2097 | |
| 2089 | 2098 | /* Normals present, Specular */ |
| 2090 | | case 1: geo_parse_np_s( obp, obc ); break; |
| 2099 | case 1: geo_parse_np_s( geo, obp, obc ); break; |
| 2091 | 2100 | |
| 2092 | 2101 | /* No Normals present, No Specular */ |
| 2093 | | case 2: geo_parse_nn_ns( obp, obc ); break; |
| 2102 | case 2: geo_parse_nn_ns( geo, obp, obc ); break; |
| 2094 | 2103 | |
| 2095 | 2104 | /* No Normals present, Specular */ |
| 2096 | | case 3: geo_parse_nn_s( obp, obc ); break; |
| 2105 | case 3: geo_parse_nn_s( geo, obp, obc ); break; |
| 2097 | 2106 | } |
| 2098 | 2107 | |
| 2099 | 2108 | /* move by 4 parameters */ |
| r10427 | r10428 | |
| 2101 | 2110 | } |
| 2102 | 2111 | |
| 2103 | 2112 | /* Command 02: Direct Data */ |
| 2104 | | static UINT32 * geo_direct_data( UINT32 opcode, UINT32 *input ) |
| 2113 | static UINT32 * geo_direct_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2105 | 2114 | { |
| 2115 | raster_state *raster = geo->raster; |
| 2106 | 2116 | UINT32 tpa = *input++; /* Texture Point Address */ |
| 2107 | 2117 | UINT32 tha = *input++; /* Texture Header Address */ |
| 2108 | 2118 | UINT32 attr; |
| 2109 | 2119 | |
| 2110 | 2120 | /* push the initial set of data to the 3d rasterizer */ |
| 2111 | | model2_3d_push( (opcode >> 23) - 1 ); |
| 2112 | | model2_3d_push( tpa ); |
| 2113 | | model2_3d_push( tha ); |
| 2121 | model2_3d_push( raster, (opcode >> 23) - 1 ); |
| 2122 | model2_3d_push( raster, tpa ); |
| 2123 | model2_3d_push( raster, tha ); |
| 2114 | 2124 | |
| 2115 | 2125 | /* push the initial points */ |
| 2116 | | model2_3d_push( (*input++) >> 8 ); /* x */ |
| 2117 | | model2_3d_push( (*input++) >> 8 ); /* y */ |
| 2118 | | model2_3d_push( (*input++) >> 8 ); /* z */ |
| 2126 | model2_3d_push( raster, (*input++) >> 8 ); /* x */ |
| 2127 | model2_3d_push( raster, (*input++) >> 8 ); /* y */ |
| 2128 | model2_3d_push( raster, (*input++) >> 8 ); /* z */ |
| 2119 | 2129 | |
| 2120 | | model2_3d_push( (*input++) >> 8 ); /* x */ |
| 2121 | | model2_3d_push( (*input++) >> 8 ); /* y */ |
| 2122 | | model2_3d_push( (*input++) >> 8 ); /* z */ |
| 2130 | model2_3d_push( raster, (*input++) >> 8 ); /* x */ |
| 2131 | model2_3d_push( raster, (*input++) >> 8 ); /* y */ |
| 2132 | model2_3d_push( raster, (*input++) >> 8 ); /* z */ |
| 2123 | 2133 | |
| 2124 | 2134 | do |
| 2125 | 2135 | { |
| r10427 | r10428 | |
| 2130 | 2140 | break; |
| 2131 | 2141 | |
| 2132 | 2142 | /* push attributes */ |
| 2133 | | model2_3d_push( attr & 0x00FFFFFF ); |
| 2143 | model2_3d_push( raster, attr & 0x00FFFFFF ); |
| 2134 | 2144 | |
| 2135 | 2145 | /* push luma */ |
| 2136 | | model2_3d_push( (*input++) >> 8 ); |
| 2146 | model2_3d_push( raster, (*input++) >> 8 ); |
| 2137 | 2147 | |
| 2138 | 2148 | /* push distance */ |
| 2139 | | model2_3d_push( (*input++) >> 8 ); |
| 2149 | model2_3d_push( raster, (*input++) >> 8 ); |
| 2140 | 2150 | |
| 2141 | 2151 | /* push the next point */ |
| 2142 | | model2_3d_push( (*input++) >> 8 ); /* x */ |
| 2143 | | model2_3d_push( (*input++) >> 8 ); /* y */ |
| 2144 | | model2_3d_push( (*input++) >> 8 ); /* z */ |
| 2152 | model2_3d_push( raster, (*input++) >> 8 ); /* x */ |
| 2153 | model2_3d_push( raster, (*input++) >> 8 ); /* y */ |
| 2154 | model2_3d_push( raster, (*input++) >> 8 ); /* z */ |
| 2145 | 2155 | |
| 2146 | 2156 | /* if it's a quad, output another point */ |
| 2147 | 2157 | if ( attr & 1 ) |
| 2148 | 2158 | { |
| 2149 | | model2_3d_push( (*input++) >> 8 ); /* x */ |
| 2150 | | model2_3d_push( (*input++) >> 8 ); /* y */ |
| 2151 | | model2_3d_push( (*input++) >> 8 ); /* z */ |
| 2159 | model2_3d_push( raster, (*input++) >> 8 ); /* x */ |
| 2160 | model2_3d_push( raster, (*input++) >> 8 ); /* y */ |
| 2161 | model2_3d_push( raster, (*input++) >> 8 ); /* z */ |
| 2152 | 2162 | } |
| 2153 | 2163 | } while( 1 ); |
| 2154 | 2164 | |
| 2155 | 2165 | /* we're done */ |
| 2156 | | model2_3d_push( 0 ); |
| 2166 | model2_3d_push( raster, 0 ); |
| 2157 | 2167 | |
| 2158 | 2168 | return input; |
| 2159 | 2169 | } |
| 2160 | 2170 | |
| 2161 | 2171 | /* Command 03: Window Data */ |
| 2162 | | static UINT32 * geo_window_data( UINT32 opcode, UINT32 *input ) |
| 2172 | static UINT32 * geo_window_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2163 | 2173 | { |
| 2174 | raster_state *raster = geo->raster; |
| 2164 | 2175 | UINT32 x, y, i; |
| 2165 | 2176 | |
| 2166 | 2177 | /* start by pushing the opcode */ |
| 2167 | | model2_3d_push( opcode >> 23 ); |
| 2178 | model2_3d_push( raster, opcode >> 23 ); |
| 2168 | 2179 | |
| 2169 | 2180 | /* |
| 2170 | 2181 | we're going to move 6 coordinates to the 3d rasterizer: |
| r10427 | r10428 | |
| 2186 | 2197 | y &= 0xFFF; |
| 2187 | 2198 | |
| 2188 | 2199 | /* push it */ |
| 2189 | | model2_3d_push( x | y ); |
| 2200 | model2_3d_push( raster, x | y ); |
| 2190 | 2201 | } |
| 2191 | 2202 | |
| 2192 | 2203 | return input; |
| 2193 | 2204 | } |
| 2194 | 2205 | |
| 2195 | 2206 | /* Command 04: Texture Data Write */ |
| 2196 | | static UINT32 * geo_texture_data( UINT32 opcode, UINT32 *input ) |
| 2207 | static UINT32 * geo_texture_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2197 | 2208 | { |
| 2209 | raster_state *raster = geo->raster; |
| 2198 | 2210 | UINT32 i, count; |
| 2199 | 2211 | |
| 2200 | 2212 | /* start by pushing the opcode */ |
| 2201 | | model2_3d_push( opcode >> 23 ); |
| 2213 | model2_3d_push( raster, opcode >> 23 ); |
| 2202 | 2214 | |
| 2203 | 2215 | /* push the starting address/dsp id */ |
| 2204 | | model2_3d_push( *input++ ); |
| 2216 | model2_3d_push( raster, *input++ ); |
| 2205 | 2217 | |
| 2206 | 2218 | /* get the count */ |
| 2207 | 2219 | count = *input++; |
| 2208 | 2220 | |
| 2209 | 2221 | /* push the count */ |
| 2210 | | model2_3d_push( count ); |
| 2222 | model2_3d_push( raster, count ); |
| 2211 | 2223 | |
| 2212 | 2224 | /* loop and send the data */ |
| 2213 | 2225 | for( i = 0; i < count; i++ ) |
| 2214 | | model2_3d_push( *input++ ); |
| 2226 | model2_3d_push( raster, *input++ ); |
| 2215 | 2227 | |
| 2216 | 2228 | return input; |
| 2217 | 2229 | } |
| 2218 | 2230 | |
| 2219 | 2231 | /* Command 05: Polygon Data */ |
| 2220 | | static UINT32 * geo_polygon_data( UINT32 opcode, UINT32 *input ) |
| 2232 | static UINT32 * geo_polygon_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2221 | 2233 | { |
| 2222 | 2234 | UINT32 address, count, i; |
| 2223 | 2235 | UINT32 *p; |
| r10427 | r10428 | |
| 2231 | 2243 | if ( address & 0x01000000 ) |
| 2232 | 2244 | { |
| 2233 | 2245 | /* Fast polygon RAM */ |
| 2234 | | p = &geo.polygon_ram0[address & 0x7FFF]; |
| 2246 | p = &geo->polygon_ram0[address & 0x7FFF]; |
| 2235 | 2247 | } |
| 2236 | 2248 | else |
| 2237 | 2249 | { |
| 2238 | 2250 | /* Slow Polygon RAM */ |
| 2239 | | p = &geo.polygon_ram1[address & 0x7FFF]; |
| 2251 | p = &geo->polygon_ram1[address & 0x7FFF]; |
| 2240 | 2252 | } |
| 2241 | 2253 | |
| 2242 | 2254 | /* read the count */ |
| r10427 | r10428 | |
| 2250 | 2262 | } |
| 2251 | 2263 | |
| 2252 | 2264 | /* Command 06: Texture Parameters */ |
| 2253 | | static UINT32 * geo_texture_parameters( UINT32 opcode, UINT32 *input ) |
| 2265 | static UINT32 * geo_texture_parameters( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2254 | 2266 | { |
| 2255 | 2267 | UINT32 index, count, i, param; |
| 2256 | 2268 | |
| r10427 | r10428 | |
| 2267 | 2279 | /* read in the texture parameters */ |
| 2268 | 2280 | param = *input++; |
| 2269 | 2281 | |
| 2270 | | geo.texture_parameters[index].diffuse = (float)( param & 0xFF ); |
| 2271 | | geo.texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF ); |
| 2272 | | geo.texture_parameters[index].specular_control = (param >> 24) & 0xFF; |
| 2273 | | geo.texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF ); |
| 2282 | geo->texture_parameters[index].diffuse = (float)( param & 0xFF ); |
| 2283 | geo->texture_parameters[index].ambient = (float)( (param >> 8) & 0xFF ); |
| 2284 | geo->texture_parameters[index].specular_control = (param >> 24) & 0xFF; |
| 2285 | geo->texture_parameters[index].specular_scale = (float)( (param >> 16) & 0xFF ); |
| 2274 | 2286 | |
| 2275 | 2287 | /* read in the distance coefficient */ |
| 2276 | | geo.coef_table[index] = u2f(*input++); |
| 2288 | geo->coef_table[index] = u2f(*input++); |
| 2277 | 2289 | |
| 2278 | 2290 | index = (index + 1) & 0x1F; |
| 2279 | 2291 | } |
| r10427 | r10428 | |
| 2282 | 2294 | } |
| 2283 | 2295 | |
| 2284 | 2296 | /* Command 07: Geo Mode */ |
| 2285 | | static UINT32 * geo_mode( UINT32 opcode, UINT32 *input ) |
| 2297 | static UINT32 * geo_mode( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2286 | 2298 | { |
| 2287 | 2299 | (void)opcode; |
| 2288 | 2300 | |
| 2289 | 2301 | /* read in the mode */ |
| 2290 | | geo.mode = *input++; |
| 2302 | geo->mode = *input++; |
| 2291 | 2303 | |
| 2292 | 2304 | return input; |
| 2293 | 2305 | } |
| 2294 | 2306 | |
| 2295 | 2307 | /* Command 08: ZSort Mode */ |
| 2296 | | static UINT32 * geo_zsort_mode( UINT32 opcode, UINT32 *input ) |
| 2308 | static UINT32 * geo_zsort_mode( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2297 | 2309 | { |
| 2310 | raster_state *raster = geo->raster; |
| 2311 | |
| 2298 | 2312 | /* push the opcode */ |
| 2299 | | model2_3d_push( opcode >> 23 ); |
| 2313 | model2_3d_push( raster, opcode >> 23 ); |
| 2300 | 2314 | |
| 2301 | 2315 | /* push the mode */ |
| 2302 | | model2_3d_push( (*input++) >> 8 ); |
| 2316 | model2_3d_push( raster, (*input++) >> 8 ); |
| 2303 | 2317 | |
| 2304 | 2318 | return input; |
| 2305 | 2319 | } |
| 2306 | 2320 | |
| 2307 | 2321 | /* Command 09: Focal Distance */ |
| 2308 | | static UINT32 * geo_focal_distance( UINT32 opcode, UINT32 *input ) |
| 2322 | static UINT32 * geo_focal_distance( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2309 | 2323 | { |
| 2310 | 2324 | (void)opcode; |
| 2311 | 2325 | |
| 2312 | 2326 | /* read the x focus value */ |
| 2313 | | geo.focus.x = u2f( *input++ ); |
| 2327 | geo->focus.x = u2f( *input++ ); |
| 2314 | 2328 | |
| 2315 | 2329 | /* read the y focus value */ |
| 2316 | | geo.focus.y = u2f( *input++ ); |
| 2330 | geo->focus.y = u2f( *input++ ); |
| 2317 | 2331 | |
| 2318 | 2332 | return input; |
| 2319 | 2333 | } |
| 2320 | 2334 | |
| 2321 | 2335 | /* Command 0A: Light Source Vector Write */ |
| 2322 | | static UINT32 * geo_light_source( UINT32 opcode, UINT32 *input ) |
| 2336 | static UINT32 * geo_light_source( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2323 | 2337 | { |
| 2324 | 2338 | (void)opcode; |
| 2325 | 2339 | |
| 2326 | 2340 | /* read the x light value */ |
| 2327 | | geo.light.x = u2f( *input++ ); |
| 2341 | geo->light.x = u2f( *input++ ); |
| 2328 | 2342 | |
| 2329 | 2343 | /* read the y light value */ |
| 2330 | | geo.light.y = u2f( *input++ ); |
| 2344 | geo->light.y = u2f( *input++ ); |
| 2331 | 2345 | |
| 2332 | 2346 | /* read the z light value */ |
| 2333 | | geo.light.pz = u2f( *input++ ); |
| 2347 | geo->light.pz = u2f( *input++ ); |
| 2334 | 2348 | |
| 2335 | 2349 | return input; |
| 2336 | 2350 | } |
| 2337 | 2351 | |
| 2338 | 2352 | /* Command 0B: Transformation Matrix Write */ |
| 2339 | | static UINT32 * geo_matrix_write( UINT32 opcode, UINT32 *input ) |
| 2353 | static UINT32 * geo_matrix_write( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2340 | 2354 | { |
| 2341 | 2355 | UINT32 i; |
| 2342 | 2356 | |
| r10427 | r10428 | |
| 2344 | 2358 | |
| 2345 | 2359 | /* read in the transformation matrix */ |
| 2346 | 2360 | for( i = 0; i < 12; i++ ) |
| 2347 | | geo.matrix[i] = u2f( *input++ ); |
| 2361 | geo->matrix[i] = u2f( *input++ ); |
| 2348 | 2362 | |
| 2349 | 2363 | return input; |
| 2350 | 2364 | } |
| 2351 | 2365 | |
| 2352 | 2366 | /* Command 0C: Parallel Transfer Vector Write */ |
| 2353 | | static UINT32 * geo_translate_write( UINT32 opcode, UINT32 *input ) |
| 2367 | static UINT32 * geo_translate_write( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2354 | 2368 | { |
| 2355 | 2369 | UINT32 i; |
| 2356 | 2370 | |
| r10427 | r10428 | |
| 2358 | 2372 | |
| 2359 | 2373 | /* read in the translation vector */ |
| 2360 | 2374 | for( i = 0; i < 3; i++ ) |
| 2361 | | geo.matrix[i+9] = u2f( *input++ ); |
| 2375 | geo->matrix[i+9] = u2f( *input++ ); |
| 2362 | 2376 | |
| 2363 | 2377 | return input; |
| 2364 | 2378 | } |
| 2365 | 2379 | |
| 2366 | 2380 | /* Command 0D: Geo Data Memory Push (undocumented, unsupported) */ |
| 2367 | | static UINT32 * geo_data_mem_push( UINT32 opcode, UINT32 *input ) |
| 2381 | static UINT32 * geo_data_mem_push( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2368 | 2382 | { |
| 2369 | 2383 | UINT32 address, count, i; |
| 2370 | 2384 | |
| r10427 | r10428 | |
| 2401 | 2415 | } |
| 2402 | 2416 | |
| 2403 | 2417 | /* Command 0E: Geo Test */ |
| 2404 | | static UINT32 * geo_test( UINT32 opcode, UINT32 *input ) |
| 2418 | static UINT32 * geo_test( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2405 | 2419 | { |
| 2406 | 2420 | UINT32 data, blocks, address, count, checksum, i; |
| 2407 | 2421 | |
| r10427 | r10428 | |
| 2443 | 2457 | |
| 2444 | 2458 | for( j = 0; j < count; j++ ) |
| 2445 | 2459 | { |
| 2446 | | data = geo.polygon_rom[address++]; |
| 2460 | data = geo->polygon_rom[address++]; |
| 2447 | 2461 | |
| 2448 | 2462 | address &= 0x7FFFFF; |
| 2449 | 2463 | |
| r10427 | r10428 | |
| 2471 | 2485 | } |
| 2472 | 2486 | |
| 2473 | 2487 | /* Command 0F: End */ |
| 2474 | | static UINT32 * geo_end( UINT32 opcode, UINT32 *input ) |
| 2488 | static UINT32 * geo_end( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2475 | 2489 | { |
| 2490 | raster_state *raster = geo->raster; |
| 2491 | |
| 2476 | 2492 | (void)opcode; |
| 2477 | 2493 | |
| 2478 | 2494 | /* signal the end of this data block the rasterizer */ |
| 2479 | | model2_3d_push( 0xFF000000 ); |
| 2495 | model2_3d_push( raster, 0xFF000000 ); |
| 2480 | 2496 | |
| 2481 | 2497 | /* signal end by returning NULL */ |
| 2482 | 2498 | return NULL; |
| 2483 | 2499 | } |
| 2484 | 2500 | |
| 2485 | 2501 | /* Command 10: Dummy */ |
| 2486 | | static UINT32 * geo_dummy( UINT32 opcode, UINT32 *input ) |
| 2502 | static UINT32 * geo_dummy( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2487 | 2503 | { |
| 2488 | 2504 | UINT32 data; |
| 2489 | 2505 | (void)opcode; |
| r10427 | r10428 | |
| 2495 | 2511 | } |
| 2496 | 2512 | |
| 2497 | 2513 | /* Command 14: Log Data Write */ |
| 2498 | | static UINT32 * geo_log_data( UINT32 opcode, UINT32 *input ) |
| 2514 | static UINT32 * geo_log_data( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2499 | 2515 | { |
| 2516 | raster_state *raster = geo->raster; |
| 2500 | 2517 | UINT32 i, count; |
| 2501 | 2518 | |
| 2502 | 2519 | /* start by pushing the opcode */ |
| 2503 | | model2_3d_push( opcode >> 23 ); |
| 2520 | model2_3d_push( raster, opcode >> 23 ); |
| 2504 | 2521 | |
| 2505 | 2522 | /* push the starting address/dsp id */ |
| 2506 | | model2_3d_push( *input++ ); |
| 2523 | model2_3d_push( raster, *input++ ); |
| 2507 | 2524 | |
| 2508 | 2525 | /* get the count */ |
| 2509 | 2526 | count = *input++; |
| 2510 | 2527 | |
| 2511 | 2528 | /* push the count */ |
| 2512 | | model2_3d_push( count << 2 ); |
| 2529 | model2_3d_push( raster, count << 2 ); |
| 2513 | 2530 | |
| 2514 | 2531 | /* loop and send the data */ |
| 2515 | 2532 | for( i = 0; i < count; i++ ) |
| 2516 | 2533 | { |
| 2517 | 2534 | UINT32 data = *input++; |
| 2518 | 2535 | |
| 2519 | | model2_3d_push( data & 0xff ); |
| 2520 | | model2_3d_push( (data >> 8) & 0xff ); |
| 2521 | | model2_3d_push( (data >> 16) & 0xff ); |
| 2522 | | model2_3d_push( (data >> 24) & 0xff ); |
| 2536 | model2_3d_push( raster, data & 0xff ); |
| 2537 | model2_3d_push( raster, (data >> 8) & 0xff ); |
| 2538 | model2_3d_push( raster, (data >> 16) & 0xff ); |
| 2539 | model2_3d_push( raster, (data >> 24) & 0xff ); |
| 2523 | 2540 | } |
| 2524 | 2541 | |
| 2525 | 2542 | return input; |
| 2526 | 2543 | } |
| 2527 | 2544 | |
| 2528 | 2545 | /* Command 16: LOD */ |
| 2529 | | static UINT32 * geo_lod( UINT32 opcode, UINT32 *input ) |
| 2546 | static UINT32 * geo_lod( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2530 | 2547 | { |
| 2531 | 2548 | (void)opcode; |
| 2532 | 2549 | |
| 2533 | 2550 | /* read in the LOD */ |
| 2534 | | geo.lod = u2f(*input++); |
| 2551 | geo->lod = u2f(*input++); |
| 2535 | 2552 | |
| 2536 | 2553 | return input; |
| 2537 | 2554 | } |
| 2538 | 2555 | |
| 2539 | 2556 | /* Command 1D: Code Upload (undocumented, unsupported) */ |
| 2540 | | static UINT32 * geo_code_upload( UINT32 opcode, UINT32 *input ) |
| 2557 | static UINT32 * geo_code_upload( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2541 | 2558 | { |
| 2542 | 2559 | UINT32 flags, count, i; |
| 2543 | 2560 | |
| r10427 | r10428 | |
| 2585 | 2602 | } |
| 2586 | 2603 | |
| 2587 | 2604 | /* Command 1E: Code Jump (undocumented, unsupported) */ |
| 2588 | | static UINT32 * geo_code_jump( UINT32 opcode, UINT32 *input ) |
| 2605 | static UINT32 * geo_code_jump( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2589 | 2606 | { |
| 2590 | 2607 | UINT32 address; |
| 2591 | 2608 | |
| r10427 | r10428 | |
| 2609 | 2626 | return input; |
| 2610 | 2627 | } |
| 2611 | 2628 | |
| 2612 | | static UINT32 * geo_process_command( UINT32 opcode, UINT32 *input ) |
| 2629 | static UINT32 * geo_process_command( geo_state *geo, UINT32 opcode, UINT32 *input ) |
| 2613 | 2630 | { |
| 2614 | 2631 | switch( opcode >> 23 ) |
| 2615 | 2632 | { |
| 2616 | | case 0x00: input = geo_nop( opcode, input ); break; |
| 2617 | | case 0x01: input = geo_object_data( opcode, input ); break; |
| 2618 | | case 0x02: input = geo_direct_data( opcode, input ); break; |
| 2619 | | case 0x03: input = geo_window_data( opcode, input ); break; |
| 2620 | | case 0x04: input = geo_texture_data( opcode, input ); break; |
| 2621 | | case 0x05: input = geo_polygon_data( opcode, input ); break; |
| 2622 | | case 0x06: input = geo_texture_parameters( opcode, input ); break; |
| 2623 | | case 0x07: input = geo_mode( opcode, input ); break; |
| 2624 | | case 0x08: input = geo_zsort_mode( opcode, input ); break; |
| 2625 | | case 0x09: input = geo_focal_distance( opcode, input ); break; |
| 2626 | | case 0x0A: input = geo_light_source( opcode, input ); break; |
| 2627 | | case 0x0B: input = geo_matrix_write( opcode, input ); break; |
| 2628 | | case 0x0C: input = geo_translate_write( opcode, input ); break; |
| 2629 | | case 0x0D: input = geo_data_mem_push( opcode, input ); break; |
| 2630 | | case 0x0E: input = geo_test( opcode, input ); break; |
| 2631 | | case 0x0F: input = geo_end( opcode, input ); break; |
| 2632 | | case 0x10: input = geo_dummy( opcode, input ); break; |
| 2633 | | case 0x11: input = geo_object_data( opcode, input ); break; |
| 2634 | | case 0x12: input = geo_direct_data( opcode, input ); break; |
| 2635 | | case 0x13: input = geo_window_data( opcode, input ); break; |
| 2636 | | case 0x14: input = geo_log_data( opcode, input ); break; |
| 2637 | | case 0x15: input = geo_polygon_data( opcode, input ); break; |
| 2638 | | case 0x16: input = geo_lod( opcode, input ); break; |
| 2639 | | case 0x17: input = geo_mode( opcode, input ); break; |
| 2640 | | case 0x18: input = geo_zsort_mode( opcode, input ); break; |
| 2641 | | case 0x19: input = geo_focal_distance( opcode, input ); break; |
| 2642 | | case 0x1A: input = geo_light_source( opcode, input ); break; |
| 2643 | | case 0x1B: input = geo_matrix_write( opcode, input ); break; |
| 2644 | | case 0x1C: input = geo_translate_write( opcode, input ); break; |
| 2645 | | case 0x1D: input = geo_code_upload( opcode, input ); break; |
| 2646 | | case 0x1E: input = geo_code_jump( opcode, input ); break; |
| 2647 | | case 0x1F: input = geo_end( opcode, input ); break; |
| 2633 | case 0x00: input = geo_nop( geo, opcode, input ); break; |
| 2634 | case 0x01: input = geo_object_data( geo, opcode, input ); break; |
| 2635 | case 0x02: input = geo_direct_data( geo, opcode, input ); break; |
| 2636 | case 0x03: input = geo_window_data( geo, opcode, input ); break; |
| 2637 | case 0x04: input = geo_texture_data( geo, opcode, input ); break; |
| 2638 | case 0x05: input = geo_polygon_data( geo, opcode, input ); break; |
| 2639 | case 0x06: input = geo_texture_parameters( geo, opcode, input ); break; |
| 2640 | case 0x07: input = geo_mode( geo, opcode, input ); break; |
| 2641 | case 0x08: input = geo_zsort_mode( geo, opcode, input ); break; |
| 2642 | case 0x09: input = geo_focal_distance( geo, opcode, input ); break; |
| 2643 | case 0x0A: input = geo_light_source( geo, opcode, input ); break; |
| 2644 | case 0x0B: input = geo_matrix_write( geo, opcode, input ); break; |
| 2645 | case 0x0C: input = geo_translate_write( geo, opcode, input ); break; |
| 2646 | case 0x0D: input = geo_data_mem_push( geo, opcode, input ); break; |
| 2647 | case 0x0E: input = geo_test( geo, opcode, input ); break; |
| 2648 | case 0x0F: input = geo_end( geo, opcode, input ); break; |
| 2649 | case 0x10: input = geo_dummy( geo, opcode, input ); break; |
| 2650 | case 0x11: input = geo_object_data( geo, opcode, input ); break; |
| 2651 | case 0x12: input = geo_direct_data( geo, opcode, input ); break; |
| 2652 | case 0x13: input = geo_window_data( geo, opcode, input ); break; |
| 2653 | case 0x14: input = geo_log_data( geo, opcode, input ); break; |
| 2654 | case 0x15: input = geo_polygon_data( geo, opcode, input ); break; |
| 2655 | case 0x16: input = geo_lod( geo, opcode, input ); break; |
| 2656 | case 0x17: input = geo_mode( geo, opcode, input ); break; |
| 2657 | case 0x18: input = geo_zsort_mode( geo, opcode, input ); break; |
| 2658 | case 0x19: input = geo_focal_distance( geo, opcode, input ); break; |
| 2659 | case 0x1A: input = geo_light_source( geo, opcode, input ); break; |
| 2660 | case 0x1B: input = geo_matrix_write( geo, opcode, input ); break; |
| 2661 | case 0x1C: input = geo_translate_write( geo, opcode, input ); break; |
| 2662 | case 0x1D: input = geo_code_upload( geo, opcode, input ); break; |
| 2663 | case 0x1E: input = geo_code_jump( geo, opcode, input ); break; |
| 2664 | case 0x1F: input = geo_end( geo, opcode, input ); break; |
| 2648 | 2665 | } |
| 2649 | 2666 | |
| 2650 | 2667 | return input; |
| 2651 | 2668 | } |
| 2652 | 2669 | |
| 2653 | | static void geo_parse( void ) |
| 2670 | static void geo_parse( model2_state *state ) |
| 2654 | 2671 | { |
| 2655 | | UINT32 address = (geo_read_start_address/4); |
| 2656 | | UINT32 *input = &model2_bufferram[address]; |
| 2672 | UINT32 address = (state->geo_read_start_address/4); |
| 2673 | UINT32 *input = &state->bufferram[address]; |
| 2657 | 2674 | UINT32 opcode; |
| 2658 | 2675 | |
| 2659 | | while( input != NULL && (input - model2_bufferram) < 0x20000 ) |
| 2676 | while( input != NULL && (input - state->bufferram) < 0x20000 ) |
| 2660 | 2677 | { |
| 2661 | 2678 | /* read in the opcode */ |
| 2662 | 2679 | opcode = *input++; |
| r10427 | r10428 | |
| 2668 | 2685 | address = (opcode & 0x7FFFF) / 4; |
| 2669 | 2686 | |
| 2670 | 2687 | /* update our pointer */ |
| 2671 | | input = &model2_bufferram[address]; |
| 2688 | input = &state->bufferram[address]; |
| 2672 | 2689 | |
| 2673 | 2690 | /* go again */ |
| 2674 | 2691 | continue; |
| 2675 | 2692 | } |
| 2676 | 2693 | |
| 2677 | 2694 | /* process it */ |
| 2678 | | input = geo_process_command( opcode, input ); |
| 2695 | input = geo_process_command( state->geo, opcode, input ); |
| 2679 | 2696 | } |
| 2680 | 2697 | } |
| 2681 | 2698 | |
| 2682 | 2699 | /***********************************************************************************************/ |
| 2683 | 2700 | |
| 2684 | | static bitmap_t *sys24_bitmap = NULL; |
| 2685 | 2701 | |
| 2686 | 2702 | static void model2_exit(running_machine &machine) |
| 2687 | 2703 | { |
| 2688 | | poly_free(poly); |
| 2704 | model2_state *state = machine.driver_data<model2_state>(); |
| 2705 | poly_free(state->poly); |
| 2689 | 2706 | } |
| 2690 | 2707 | |
| 2691 | 2708 | VIDEO_START(model2) |
| 2692 | 2709 | { |
| 2710 | model2_state *state = machine->driver_data<model2_state>(); |
| 2693 | 2711 | const rectangle &visarea = machine->primary_screen->visible_area(); |
| 2694 | 2712 | int width = visarea.max_x - visarea.min_x; |
| 2695 | 2713 | int height = visarea.max_y - visarea.min_y; |
| 2696 | 2714 | |
| 2697 | 2715 | sys24_tile_vh_start(machine, 0x3fff); |
| 2698 | | sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16)); |
| 2716 | state->sys24_bitmap = auto_alloc(machine, bitmap_t(width, height+4, BITMAP_FORMAT_INDEXED16)); |
| 2699 | 2717 | |
| 2700 | | poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); |
| 2718 | state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); |
| 2701 | 2719 | machine->add_notifier(MACHINE_NOTIFY_EXIT, model2_exit); |
| 2702 | 2720 | |
| 2721 | /* initialize the hardware rasterizer */ |
| 2722 | model2_3d_init( machine, (UINT16*)machine->region("user3")->base() ); |
| 2723 | |
| 2703 | 2724 | /* initialize the geometry engine */ |
| 2704 | 2725 | geo_init( machine, (UINT32*)machine->region("user2")->base() ); |
| 2705 | | |
| 2706 | | /* initialize the hardware rasterizer */ |
| 2707 | | model2_3d_init( machine, (UINT16*)machine->region("user3")->base() ); |
| 2708 | 2726 | } |
| 2709 | 2727 | |
| 2710 | 2728 | static void convert_bitmap( running_machine *machine, bitmap_t *dst, bitmap_t *src, const rectangle *rect ) |
| r10427 | r10428 | |
| 2726 | 2744 | |
| 2727 | 2745 | VIDEO_UPDATE(model2) |
| 2728 | 2746 | { |
| 2747 | model2_state *state = screen->machine->driver_data<model2_state>(); |
| 2729 | 2748 | logerror("--- frame ---\n"); |
| 2730 | 2749 | |
| 2731 | 2750 | bitmap_fill(bitmap, cliprect, screen->machine->pens[0]); |
| 2732 | | bitmap_fill(sys24_bitmap, cliprect, 0); |
| 2751 | bitmap_fill(state->sys24_bitmap, cliprect, 0); |
| 2733 | 2752 | |
| 2734 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 7, 0, 0); |
| 2735 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 6, 0, 0); |
| 2736 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 5, 0, 0); |
| 2737 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 4, 0, 0); |
| 2753 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 7, 0, 0); |
| 2754 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 6, 0, 0); |
| 2755 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 5, 0, 0); |
| 2756 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 4, 0, 0); |
| 2738 | 2757 | |
| 2739 | | convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect); |
| 2758 | convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect); |
| 2740 | 2759 | |
| 2741 | 2760 | /* tell the rasterizer we're starting a frame */ |
| 2742 | | model2_3d_frame_start(); |
| 2761 | model2_3d_frame_start(state); |
| 2743 | 2762 | |
| 2744 | 2763 | /* let the geometry engine do it's thing */ |
| 2745 | | geo_parse(); |
| 2764 | geo_parse(state); |
| 2746 | 2765 | |
| 2747 | 2766 | /* have the rasterizer output the frame */ |
| 2748 | | model2_3d_frame_end( bitmap, cliprect ); |
| 2767 | model2_3d_frame_end( state, bitmap, cliprect ); |
| 2749 | 2768 | |
| 2750 | | bitmap_fill(sys24_bitmap, cliprect, 0); |
| 2751 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 3, 0, 0); |
| 2752 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 2, 0, 0); |
| 2753 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 1, 0, 0); |
| 2754 | | sys24_tile_draw(screen->machine, sys24_bitmap, cliprect, 0, 0, 0); |
| 2769 | bitmap_fill(state->sys24_bitmap, cliprect, 0); |
| 2770 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 3, 0, 0); |
| 2771 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 2, 0, 0); |
| 2772 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 1, 0, 0); |
| 2773 | sys24_tile_draw(screen->machine, state->sys24_bitmap, cliprect, 0, 0, 0); |
| 2755 | 2774 | |
| 2756 | | convert_bitmap(screen->machine, bitmap, sys24_bitmap, cliprect); |
| 2775 | convert_bitmap(screen->machine, bitmap, state->sys24_bitmap, cliprect); |
| 2757 | 2776 | |
| 2758 | 2777 | return 0; |
| 2759 | 2778 | } |
src/mame/video/model3.c
| r10427 | r10428 | |
| 10 | 10 | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | | typedef float MATRIX[4][4]; |
| 14 | | typedef float VECTOR[4]; |
| 15 | | typedef float VECTOR3[3]; |
| 16 | 13 | |
| 17 | | typedef struct { |
| 18 | | float x,y,z,d; |
| 19 | | } PLANE; |
| 20 | 14 | |
| 21 | 15 | typedef struct |
| 22 | 16 | { |
| r10427 | r10428 | |
| 29 | 23 | UINT32 color; |
| 30 | 24 | } TRIANGLE; |
| 31 | 25 | |
| 32 | | typedef struct _cached_texture cached_texture; |
| 33 | 26 | struct _cached_texture |
| 34 | 27 | { |
| 35 | 28 | cached_texture *next; |
| r10427 | r10428 | |
| 44 | 37 | struct _poly_extra_data |
| 45 | 38 | { |
| 46 | 39 | cached_texture *texture; |
| 40 | bitmap_t *zbuffer; |
| 47 | 41 | UINT32 color; |
| 48 | 42 | UINT8 texture_param; |
| 49 | 43 | int polygon_transparency; |
| r10427 | r10428 | |
| 62 | 56 | /* forward declarations */ |
| 63 | 57 | static void real3d_traverse_display_list(running_machine *machine); |
| 64 | 58 | static void draw_model(running_machine *machine, UINT32 addr); |
| 65 | | static void init_matrix_stack(void); |
| 66 | | static void get_top_matrix(MATRIX *out); |
| 67 | | static void push_matrix_stack(void); |
| 68 | | static void pop_matrix_stack(void); |
| 69 | | static void multiply_matrix_stack(MATRIX matrix); |
| 70 | | static void translate_matrix_stack(float x, float y, float z); |
| 59 | static void init_matrix_stack(running_machine *machine); |
| 60 | static void get_top_matrix(model3_state *state, MATRIX *out); |
| 61 | static void push_matrix_stack(model3_state *state); |
| 62 | static void pop_matrix_stack(model3_state *state); |
| 63 | static void multiply_matrix_stack(model3_state *state, MATRIX matrix); |
| 64 | static void translate_matrix_stack(model3_state *state, float x, float y, float z); |
| 71 | 65 | static void traverse_list(running_machine *machine, UINT32 address); |
| 72 | 66 | static void draw_block(running_machine *machine, UINT32 address); |
| 73 | 67 | static void draw_viewport(running_machine *machine, int pri, UINT32 address); |
| r10427 | r10428 | |
| 75 | 69 | |
| 76 | 70 | /*****************************************************************************/ |
| 77 | 71 | |
| 78 | | UINT64 *paletteram64; |
| 79 | 72 | |
| 80 | | static UINT8 model3_layer_enable = 0; |
| 81 | | static UINT32 layer_modulate_r; |
| 82 | | static UINT32 layer_modulate_g; |
| 83 | | static UINT32 layer_modulate_b; |
| 84 | | static UINT32 model3_layer_modulate1; |
| 85 | | static UINT32 model3_layer_modulate2; |
| 86 | | static UINT64 layer_scroll[2]; |
| 87 | 73 | |
| 88 | | static UINT64 *m3_char_ram; |
| 89 | | static UINT64 *m3_tile_ram; |
| 90 | 74 | |
| 91 | | static UINT32 *texture_fifo; |
| 92 | | static int texture_fifo_pos = 0; |
| 93 | 75 | |
| 94 | | static UINT16 *texture_ram[2]; |
| 95 | | static UINT32 *display_list_ram; |
| 96 | | static UINT32 *culling_ram; |
| 97 | | static UINT32 *polygon_ram; |
| 98 | 76 | |
| 99 | | static UINT16 *pal_lookup; |
| 100 | 77 | |
| 101 | | static int real3d_display_list = 0; |
| 102 | 78 | |
| 103 | | static bitmap_t *bitmap3d; |
| 104 | | static bitmap_t *zbuffer; |
| 105 | | static rectangle clip3d; |
| 106 | | static rectangle *screen_clip; |
| 107 | 79 | |
| 108 | 80 | |
| 109 | | static VECTOR3 parallel_light; |
| 110 | | static float parallel_light_intensity; |
| 111 | | static float ambient_light_intensity; |
| 112 | 81 | |
| 113 | | static poly_manager *poly; |
| 114 | | static cached_texture *texcache[2][1024/32][2048/32]; |
| 115 | 82 | |
| 116 | 83 | |
| 117 | | static int list_depth = 0; |
| 118 | 84 | |
| 119 | 85 | |
| 120 | | static int tick = 0; |
| 121 | | static int debug_layer_disable = 0; |
| 122 | 86 | |
| 123 | 87 | |
| 124 | | static UINT64 vid_reg0; |
| 125 | 88 | |
| 126 | 89 | /* matrix stack */ |
| 127 | 90 | #define MATRIX_STACK_SIZE 256 |
| 128 | 91 | |
| 129 | | static int matrix_stack_ptr = 0; |
| 130 | | static MATRIX matrix_stack[MATRIX_STACK_SIZE]; |
| 131 | 92 | |
| 132 | 93 | #ifdef UNUSED_DEFINITION |
| 133 | 94 | static const int num_bits[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; |
| 134 | 95 | #endif |
| 135 | 96 | |
| 136 | | static MATRIX coordinate_system; |
| 137 | | static float viewport_focal_length; |
| 138 | | static int viewport_region_x; |
| 139 | | static int viewport_region_y; |
| 140 | | static int viewport_region_width; |
| 141 | | static int viewport_region_height; |
| 142 | 97 | |
| 143 | | static PLANE clip_plane[5]; |
| 144 | 98 | |
| 145 | | static UINT32 matrix_base_address; |
| 146 | 99 | |
| 147 | 100 | |
| 148 | 101 | #define BYTE_REVERSE32(x) (((x >> 24) & 0xff) | \ |
| r10427 | r10428 | |
| 155 | 108 | |
| 156 | 109 | static void model3_exit(running_machine &machine) |
| 157 | 110 | { |
| 111 | model3_state *state = machine.driver_data<model3_state>(); |
| 158 | 112 | invalidate_texture(&machine, 0, 0, 0, 6, 5); |
| 159 | 113 | invalidate_texture(&machine, 1, 0, 0, 6, 5); |
| 160 | | poly_free(poly); |
| 114 | poly_free(state->poly); |
| 161 | 115 | } |
| 162 | 116 | |
| 163 | 117 | VIDEO_START( model3 ) |
| 164 | 118 | { |
| 119 | model3_state *state = machine->driver_data<model3_state>(); |
| 165 | 120 | int width, height; |
| 166 | 121 | |
| 167 | | poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); |
| 122 | state->poly = poly_alloc(machine, 4000, sizeof(poly_extra_data), 0); |
| 168 | 123 | machine->add_notifier(MACHINE_NOTIFY_EXIT, model3_exit); |
| 169 | 124 | |
| 170 | 125 | width = machine->primary_screen->width(); |
| 171 | 126 | height = machine->primary_screen->height(); |
| 172 | | bitmap3d = machine->primary_screen->alloc_compatible_bitmap(); |
| 173 | | zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 127 | state->bitmap3d = machine->primary_screen->alloc_compatible_bitmap(); |
| 128 | state->zbuffer = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 174 | 129 | |
| 175 | | m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8); |
| 176 | | m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8); |
| 130 | state->m3_char_ram = auto_alloc_array_clear(machine, UINT64, 0x100000/8); |
| 131 | state->m3_tile_ram = auto_alloc_array_clear(machine, UINT64, 0x8000/8); |
| 177 | 132 | |
| 178 | | pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536); |
| 133 | state->pal_lookup = auto_alloc_array_clear(machine, UINT16, 65536); |
| 179 | 134 | |
| 180 | | texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4); |
| 135 | state->texture_fifo = auto_alloc_array_clear(machine, UINT32, 0x100000/4); |
| 181 | 136 | |
| 182 | 137 | /* 2x 4MB texture sheets */ |
| 183 | | texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2); |
| 184 | | texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2); |
| 138 | state->texture_ram[0] = auto_alloc_array(machine, UINT16, 0x400000/2); |
| 139 | state->texture_ram[1] = auto_alloc_array(machine, UINT16, 0x400000/2); |
| 185 | 140 | |
| 186 | 141 | /* 1MB Display List RAM */ |
| 187 | | display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4); |
| 142 | state->display_list_ram = auto_alloc_array_clear(machine, UINT32, 0x100000/4); |
| 188 | 143 | /* 4MB for nodes (< Step 2.0 have only 2MB) */ |
| 189 | | culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); |
| 144 | state->culling_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); |
| 190 | 145 | /* 4MB Polygon RAM */ |
| 191 | | polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); |
| 146 | state->polygon_ram = auto_alloc_array_clear(machine, UINT32, 0x400000/4); |
| 192 | 147 | |
| 193 | | tick = 0; |
| 194 | | debug_layer_disable = 0; |
| 195 | | vid_reg0 = 0; |
| 148 | state->tick = 0; |
| 149 | state->debug_layer_disable = 0; |
| 150 | state->vid_reg0 = 0; |
| 196 | 151 | |
| 197 | | viewport_focal_length = 300.; |
| 198 | | viewport_region_x = 0; |
| 199 | | viewport_region_y = 0; |
| 200 | | viewport_region_width = 496; |
| 201 | | viewport_region_height = 384; |
| 152 | state->viewport_focal_length = 300.; |
| 153 | state->viewport_region_x = 0; |
| 154 | state->viewport_region_y = 0; |
| 155 | state->viewport_region_width = 496; |
| 156 | state->viewport_region_height = 384; |
| 202 | 157 | |
| 203 | | init_matrix_stack(); |
| 158 | init_matrix_stack(machine); |
| 204 | 159 | } |
| 205 | 160 | |
| 206 | | static void draw_tile_4bit(bitmap_t *bitmap, int tx, int ty, int tilenum) |
| 161 | static void draw_tile_4bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum) |
| 207 | 162 | { |
| 163 | model3_state *state = machine->driver_data<model3_state>(); |
| 208 | 164 | int x, y; |
| 209 | | UINT8 *tile_base = (UINT8*)m3_char_ram; |
| 165 | UINT8 *tile_base = (UINT8*)state->m3_char_ram; |
| 210 | 166 | UINT8 *tile; |
| 211 | 167 | |
| 212 | 168 | int data = (BYTE_REVERSE16(tilenum)); |
| r10427 | r10428 | |
| 223 | 179 | UINT16 pix0, pix1; |
| 224 | 180 | tile0 = *tile >> 4; |
| 225 | 181 | tile1 = *tile & 0xf; |
| 226 | | pix0 = pal_lookup[c + tile0]; |
| 227 | | pix1 = pal_lookup[c + tile1]; |
| 182 | pix0 = state->pal_lookup[c + tile0]; |
| 183 | pix1 = state->pal_lookup[c + tile1]; |
| 228 | 184 | if((pix0 & 0x8000) == 0) |
| 229 | 185 | { |
| 230 | 186 | d[x+0] = pix0; |
| r10427 | r10428 | |
| 238 | 194 | } |
| 239 | 195 | } |
| 240 | 196 | |
| 241 | | static void draw_tile_8bit(bitmap_t *bitmap, int tx, int ty, int tilenum) |
| 197 | static void draw_tile_8bit(running_machine *machine, bitmap_t *bitmap, int tx, int ty, int tilenum) |
| 242 | 198 | { |
| 199 | model3_state *state = machine->driver_data<model3_state>(); |
| 243 | 200 | int x, y; |
| 244 | | UINT8 *tile_base = (UINT8*)m3_char_ram; |
| 201 | UINT8 *tile_base = (UINT8*)state->m3_char_ram; |
| 245 | 202 | UINT8 *tile; |
| 246 | 203 | |
| 247 | 204 | int data = (BYTE_REVERSE16(tilenum)); |
| r10427 | r10428 | |
| 258 | 215 | UINT8 tile0; |
| 259 | 216 | UINT16 pix; |
| 260 | 217 | tile0 = tile[xx^4]; |
| 261 | | pix = pal_lookup[c + tile0]; |
| 218 | pix = state->pal_lookup[c + tile0]; |
| 262 | 219 | if((pix & 0x8000) == 0) |
| 263 | 220 | { |
| 264 | 221 | d[x] = pix; |
| r10427 | r10428 | |
| 269 | 226 | } |
| 270 | 227 | } |
| 271 | 228 | #ifdef UNUSED_FUNCTION |
| 272 | | static void draw_texture_sheet(bitmap_t *bitmap, const rectangle *cliprect) |
| 229 | static void draw_texture_sheet(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 273 | 230 | { |
| 231 | model3_state *state = machine->driver_data<model3_state>(); |
| 274 | 232 | int x,y; |
| 275 | 233 | for(y = cliprect->min_y; y <= cliprect->max_y; y++) |
| 276 | 234 | { |
| 277 | 235 | UINT16 *d = BITMAP_ADDR16(bitmap, y, 0); |
| 278 | 236 | int index = (y*2)*2048; |
| 279 | 237 | for(x = cliprect->min_x; x <= cliprect->max_x; x++) { |
| 280 | | UINT16 pix = texture_ram[0][index]; |
| 238 | UINT16 pix = state->texture_ram[0][index]; |
| 281 | 239 | index+=4; |
| 282 | 240 | if(pix != 0) { |
| 283 | 241 | d[x] = pix; |
| r10427 | r10428 | |
| 287 | 245 | } |
| 288 | 246 | #endif |
| 289 | 247 | |
| 290 | | static void draw_layer(bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth) |
| 248 | static void draw_layer(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int layer, int bitdepth) |
| 291 | 249 | { |
| 250 | model3_state *state = machine->driver_data<model3_state>(); |
| 292 | 251 | int x, y; |
| 293 | 252 | int tile_index = 0; |
| 294 | | UINT16 *tiles = (UINT16*)&m3_tile_ram[layer * 0x400]; |
| 253 | UINT16 *tiles = (UINT16*)&state->m3_tile_ram[layer * 0x400]; |
| 295 | 254 | |
| 296 | 255 | //logerror("Layer %d: X: %d, Y: %d\n", layer, x1, y1); |
| 297 | 256 | |
| 298 | 257 | if(layer > 1) { |
| 299 | | int modr = (model3_layer_modulate2 >> 8) & 0xff; |
| 300 | | int modg = (model3_layer_modulate2 >> 16) & 0xff; |
| 301 | | int modb = (model3_layer_modulate2 >> 24) & 0xff; |
| 258 | int modr = (state->layer_modulate2 >> 8) & 0xff; |
| 259 | int modg = (state->layer_modulate2 >> 16) & 0xff; |
| 260 | int modb = (state->layer_modulate2 >> 24) & 0xff; |
| 302 | 261 | if(modr & 0x80) { |
| 303 | | layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 262 | state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 304 | 263 | } else { |
| 305 | | layer_modulate_r = (modr & 0x7f) << 10; |
| 264 | state->layer_modulate_r = (modr & 0x7f) << 10; |
| 306 | 265 | } |
| 307 | 266 | if(modg & 0x80) { |
| 308 | | layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 267 | state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 309 | 268 | } else { |
| 310 | | layer_modulate_g = (modr & 0x7f) << 5; |
| 269 | state->layer_modulate_g = (modr & 0x7f) << 5; |
| 311 | 270 | } |
| 312 | 271 | if(modb & 0x80) { |
| 313 | | layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 272 | state->layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 314 | 273 | } else { |
| 315 | | layer_modulate_b = (modr & 0x7f); |
| 274 | state->layer_modulate_b = (modr & 0x7f); |
| 316 | 275 | } |
| 317 | 276 | } else { |
| 318 | | int modr = (model3_layer_modulate1 >> 8) & 0xff; |
| 319 | | int modg = (model3_layer_modulate1 >> 16) & 0xff; |
| 320 | | int modb = (model3_layer_modulate1 >> 24) & 0xff; |
| 277 | int modr = (state->layer_modulate1 >> 8) & 0xff; |
| 278 | int modg = (state->layer_modulate1 >> 16) & 0xff; |
| 279 | int modb = (state->layer_modulate1 >> 24) & 0xff; |
| 321 | 280 | if(modr & 0x80) { |
| 322 | | layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 281 | state->layer_modulate_r = -(0x7f - (modr & 0x7f)) << 10; |
| 323 | 282 | } else { |
| 324 | | layer_modulate_r = (modr & 0x7f) << 10; |
| 283 | state->layer_modulate_r = (modr & 0x7f) << 10; |
| 325 | 284 | } |
| 326 | 285 | if(modg & 0x80) { |
| 327 | | layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 286 | state->layer_modulate_g = -(0x7f - (modr & 0x7f)) << 5; |
| 328 | 287 | } else { |
| 329 | | layer_modulate_g = (modr & 0x7f) << 5; |
| 288 | state->layer_modulate_g = (modr & 0x7f) << 5; |
| 330 | 289 | } |
| 331 | 290 | if(modb & 0x80) { |
| 332 | | layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 291 | state->layer_modulate_b = -(0x7f - (modr & 0x7f)); |
| 333 | 292 | } else { |
| 334 | | layer_modulate_b = (modr & 0x7f); |
| 293 | state->layer_modulate_b = (modr & 0x7f); |
| 335 | 294 | } |
| 336 | 295 | } |
| 337 | 296 | |
| r10427 | r10428 | |
| 342 | 301 | tile_index = ((y/8) * 64); |
| 343 | 302 | for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) { |
| 344 | 303 | UINT16 tile = tiles[tile_index ^ 0x2]; |
| 345 | | draw_tile_4bit(bitmap, x, y, tile); |
| 304 | draw_tile_4bit(machine, bitmap, x, y, tile); |
| 346 | 305 | ++tile_index; |
| 347 | 306 | } |
| 348 | 307 | } |
| r10427 | r10428 | |
| 354 | 313 | tile_index = ((y/8) * 64); |
| 355 | 314 | for (x = cliprect->min_x; x <= cliprect->max_x; x+=8) { |
| 356 | 315 | UINT16 tile = tiles[tile_index ^ 0x2]; |
| 357 | | draw_tile_8bit(bitmap, x, y, tile); |
| 316 | draw_tile_8bit(machine, bitmap, x, y, tile); |
| 358 | 317 | ++tile_index; |
| 359 | 318 | } |
| 360 | 319 | } |
| r10427 | r10428 | |
| 362 | 321 | } |
| 363 | 322 | |
| 364 | 323 | #ifdef UNUSED_FUNCTION |
| 365 | | static void copy_screen(bitmap_t *bitmap, const rectangle *cliprect) |
| 324 | static void copy_screen(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 366 | 325 | { |
| 326 | model3_state *state = machine->driver_data<model3_state>(); |
| 367 | 327 | int x,y; |
| 368 | 328 | for(y=cliprect->min_y; y <= cliprect->max_y; y++) { |
| 369 | 329 | UINT16 *d = BITMAP_ADDR16(bitmap, y, 0); |
| 370 | | UINT16 *s = BITMAP_ADDR16(bitmap3d, y, 0); |
| 330 | UINT16 *s = BITMAP_ADDR16(state->bitmap3d, y, 0); |
| 371 | 331 | for(x=cliprect->min_x; x <= cliprect->max_x; x++) { |
| 372 | 332 | UINT16 pix = s[x]; |
| 373 | 333 | if(!(pix & 0x8000)) { |
| r10427 | r10428 | |
| 380 | 340 | |
| 381 | 341 | VIDEO_UPDATE( model3 ) |
| 382 | 342 | { |
| 383 | | /* |
| 384 | | int layer_scroll_x[4], layer_scroll_y[4]; |
| 385 | | UINT32 layer_data[4]; |
| 343 | model3_state *state = screen->machine->driver_data<model3_state>(); |
| 344 | #if 0 |
| 345 | int layer_scroll_x[4], layer_scroll_y[4]; |
| 346 | UINT32 layer_data[4]; |
| 386 | 347 | |
| 387 | | layer_data[0] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 32)); |
| 388 | | layer_data[1] = BYTE_REVERSE32((UINT32)(layer_scroll[0] >> 0)); |
| 389 | | layer_data[2] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 32)); |
| 390 | | layer_data[3] = BYTE_REVERSE32((UINT32)(layer_scroll[1] >> 0)); |
| 391 | | layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); |
| 392 | | layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); |
| 393 | | layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); |
| 394 | | layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); |
| 395 | | layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); |
| 396 | | layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); |
| 397 | | layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); |
| 398 | | layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); |
| 399 | | */ |
| 400 | | screen_clip = (rectangle*)cliprect; |
| 348 | layer_data[0] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 32)); |
| 349 | layer_data[1] = BYTE_REVERSE32((UINT32)(state->layer_scroll[0] >> 0)); |
| 350 | layer_data[2] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 32)); |
| 351 | layer_data[3] = BYTE_REVERSE32((UINT32)(state->layer_scroll[1] >> 0)); |
| 352 | layer_scroll_x[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); |
| 353 | layer_scroll_y[0] = (layer_data[0] & 0x8000) ? (layer_data[0] & 0x1ff) : -(layer_data[0] & 0x1ff); |
| 354 | layer_scroll_x[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); |
| 355 | layer_scroll_y[1] = (layer_data[1] & 0x8000) ? (layer_data[1] & 0x1ff) : -(layer_data[1] & 0x1ff); |
| 356 | layer_scroll_x[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); |
| 357 | layer_scroll_y[2] = (layer_data[2] & 0x8000) ? (layer_data[2] & 0x1ff) : -(layer_data[2] & 0x1ff); |
| 358 | layer_scroll_x[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); |
| 359 | layer_scroll_y[3] = (layer_data[3] & 0x8000) ? (layer_data[3] & 0x1ff) : -(layer_data[3] & 0x1ff); |
| 360 | #endif |
| 361 | state->screen_clip = (rectangle*)cliprect; |
| 401 | 362 | |
| 402 | | clip3d.min_x = cliprect->min_x; |
| 403 | | clip3d.max_x = cliprect->max_x; |
| 404 | | clip3d.min_y = cliprect->min_y; |
| 405 | | clip3d.max_y = cliprect->max_y; |
| 363 | state->clip3d.min_x = cliprect->min_x; |
| 364 | state->clip3d.max_x = cliprect->max_x; |
| 365 | state->clip3d.min_y = cliprect->min_y; |
| 366 | state->clip3d.max_y = cliprect->max_y; |
| 406 | 367 | |
| 407 | 368 | /* layer disable debug keys */ |
| 408 | | tick++; |
| 409 | | if( tick >= 5 ) { |
| 410 | | tick = 0; |
| 369 | state->tick++; |
| 370 | if( state->tick >= 5 ) { |
| 371 | state->tick = 0; |
| 411 | 372 | |
| 412 | 373 | if( input_code_pressed(screen->machine, KEYCODE_Y) ) |
| 413 | | debug_layer_disable ^= 0x1; |
| 374 | state->debug_layer_disable ^= 0x1; |
| 414 | 375 | if( input_code_pressed(screen->machine, KEYCODE_U) ) |
| 415 | | debug_layer_disable ^= 0x2; |
| 376 | state->debug_layer_disable ^= 0x2; |
| 416 | 377 | if( input_code_pressed(screen->machine, KEYCODE_I) ) |
| 417 | | debug_layer_disable ^= 0x4; |
| 378 | state->debug_layer_disable ^= 0x4; |
| 418 | 379 | if( input_code_pressed(screen->machine, KEYCODE_O) ) |
| 419 | | debug_layer_disable ^= 0x8; |
| 380 | state->debug_layer_disable ^= 0x8; |
| 420 | 381 | if( input_code_pressed(screen->machine, KEYCODE_T) ) |
| 421 | | debug_layer_disable ^= 0x10; |
| 382 | state->debug_layer_disable ^= 0x10; |
| 422 | 383 | } |
| 423 | 384 | |
| 424 | 385 | bitmap_fill(bitmap, cliprect, 0); |
| 425 | 386 | |
| 426 | | if (!(debug_layer_disable & 0x8)) |
| 427 | | draw_layer(bitmap, cliprect, 3, (model3_layer_enable >> 3) & 0x1); |
| 387 | if (!(state->debug_layer_disable & 0x8)) |
| 388 | draw_layer(screen->machine, bitmap, cliprect, 3, (state->layer_enable >> 3) & 0x1); |
| 428 | 389 | |
| 429 | | if (!(debug_layer_disable & 0x4)) |
| 430 | | draw_layer(bitmap, cliprect, 2, (model3_layer_enable >> 2) & 0x1); |
| 390 | if (!(state->debug_layer_disable & 0x4)) |
| 391 | draw_layer(screen->machine, bitmap, cliprect, 2, (state->layer_enable >> 2) & 0x1); |
| 431 | 392 | |
| 432 | | if( !(debug_layer_disable & 0x10) ) |
| 393 | if( !(state->debug_layer_disable & 0x10) ) |
| 433 | 394 | { |
| 434 | | // if(real3d_display_list) { |
| 435 | | // bitmap_fill(zbuffer, cliprect, 0); |
| 436 | | // bitmap_fill(bitmap3d, cliprect, 0x8000); |
| 437 | | // real3d_traverse_display_list(screen->machine); |
| 438 | | // } |
| 439 | | copybitmap_trans(bitmap, bitmap3d, 0, 0, 0, 0, cliprect, 0x8000); |
| 395 | #if 0 |
| 396 | if(state->real3d_display_list) { |
| 397 | bitmap_fill(state->zbuffer, cliprect, 0); |
| 398 | bitmap_fill(state->bitmap3d, cliprect, 0x8000); |
| 399 | real3d_traverse_display_list(screen->machine); |
| 400 | } |
| 401 | #endif |
| 402 | copybitmap_trans(bitmap, state->bitmap3d, 0, 0, 0, 0, cliprect, 0x8000); |
| 440 | 403 | } |
| 441 | 404 | |
| 442 | | if (!(debug_layer_disable & 0x2)) |
| 443 | | draw_layer(bitmap, cliprect, 1, (model3_layer_enable >> 1) & 0x1); |
| 405 | if (!(state->debug_layer_disable & 0x2)) |
| 406 | draw_layer(screen->machine, bitmap, cliprect, 1, (state->layer_enable >> 1) & 0x1); |
| 444 | 407 | |
| 445 | | if (!(debug_layer_disable & 0x1)) |
| 446 | | draw_layer(bitmap, cliprect, 0, (model3_layer_enable >> 0) & 0x1); |
| 408 | if (!(state->debug_layer_disable & 0x1)) |
| 409 | draw_layer(screen->machine, bitmap, cliprect, 0, (state->layer_enable >> 0) & 0x1); |
| 447 | 410 | |
| 448 | 411 | //copy_screen(bitmap, cliprect); |
| 449 | 412 | |
| 450 | 413 | //draw_texture_sheet(bitmap, cliprect); |
| 451 | 414 | |
| 452 | | real3d_display_list = 0; |
| 415 | state->real3d_display_list = 0; |
| 453 | 416 | return 0; |
| 454 | 417 | } |
| 455 | 418 | |
| r10427 | r10428 | |
| 457 | 420 | |
| 458 | 421 | READ64_HANDLER(model3_char_r) |
| 459 | 422 | { |
| 460 | | return m3_char_ram[offset]; |
| 423 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 424 | return state->m3_char_ram[offset]; |
| 461 | 425 | } |
| 462 | 426 | |
| 463 | 427 | WRITE64_HANDLER(model3_char_w) |
| 464 | 428 | { |
| 465 | | COMBINE_DATA(&m3_char_ram[offset]); |
| 429 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 430 | COMBINE_DATA(&state->m3_char_ram[offset]); |
| 466 | 431 | } |
| 467 | 432 | |
| 468 | 433 | READ64_HANDLER(model3_tile_r) |
| 469 | 434 | { |
| 470 | | return m3_tile_ram[offset]; |
| 435 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 436 | return state->m3_tile_ram[offset]; |
| 471 | 437 | } |
| 472 | 438 | |
| 473 | 439 | WRITE64_HANDLER(model3_tile_w) |
| 474 | 440 | { |
| 475 | | COMBINE_DATA(&m3_tile_ram[offset]); |
| 441 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 442 | COMBINE_DATA(&state->m3_tile_ram[offset]); |
| 476 | 443 | } |
| 477 | 444 | |
| 478 | 445 | READ64_HANDLER(model3_vid_reg_r) |
| 479 | 446 | { |
| 447 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 480 | 448 | switch(offset) |
| 481 | 449 | { |
| 482 | | case 0x00/8: return vid_reg0; |
| 450 | case 0x00/8: return state->vid_reg0; |
| 483 | 451 | case 0x08/8: return U64(0xffffffffffffffff); /* ??? */ |
| 484 | | case 0x20/8: return (UINT64)model3_layer_enable << 52; |
| 485 | | case 0x40/8: return ((UINT64)model3_layer_modulate1 << 32) | (UINT64)model3_layer_modulate2; |
| 452 | case 0x20/8: return (UINT64)state->layer_enable << 52; |
| 453 | case 0x40/8: return ((UINT64)state->layer_modulate1 << 32) | (UINT64)state->layer_modulate2; |
| 486 | 454 | default: logerror("read reg %02X\n", offset);break; |
| 487 | 455 | } |
| 488 | 456 | return 0; |
| r10427 | r10428 | |
| 490 | 458 | |
| 491 | 459 | WRITE64_HANDLER(model3_vid_reg_w) |
| 492 | 460 | { |
| 461 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 493 | 462 | switch(offset) |
| 494 | 463 | { |
| 495 | | case 0x00/8: logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); vid_reg0 = data; break; |
| 464 | case 0x00/8: logerror("vid_reg0: %08X%08X\n", (UINT32)(data>>32),(UINT32)(data)); state->vid_reg0 = data; break; |
| 496 | 465 | case 0x08/8: break; /* ??? */ |
| 497 | 466 | case 0x10/8: model3_set_irq_line(space->machine, (data >> 56) & 0x0f, CLEAR_LINE); break; /* VBL IRQ Ack */ |
| 498 | 467 | |
| 499 | | case 0x20/8: model3_layer_enable = (data >> 52); break; |
| 468 | case 0x20/8: state->layer_enable = (data >> 52); break; |
| 500 | 469 | |
| 501 | | case 0x40/8: model3_layer_modulate1 = (UINT32)(data >> 32); |
| 502 | | model3_layer_modulate2 = (UINT32)(data); |
| 470 | case 0x40/8: state->layer_modulate1 = (UINT32)(data >> 32); |
| 471 | state->layer_modulate2 = (UINT32)(data); |
| 503 | 472 | break; |
| 504 | | case 0x60/8: COMBINE_DATA(&layer_scroll[0]); break; |
| 505 | | case 0x68/8: COMBINE_DATA(&layer_scroll[1]); break; |
| 473 | case 0x60/8: COMBINE_DATA(&state->layer_scroll[0]); break; |
| 474 | case 0x68/8: COMBINE_DATA(&state->layer_scroll[1]); break; |
| 506 | 475 | default: logerror("model3_vid_reg_w: %02X, %08X%08X\n", offset, (UINT32)(data >> 32), (UINT32)(data)); break; |
| 507 | 476 | } |
| 508 | 477 | } |
| 509 | 478 | |
| 510 | 479 | WRITE64_HANDLER( model3_palette_w ) |
| 511 | 480 | { |
| 481 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 512 | 482 | int r1,g1,b1,r2,g2,b2; |
| 513 | 483 | UINT32 data1,data2; |
| 514 | 484 | |
| 515 | | COMBINE_DATA(&paletteram64[offset]); |
| 516 | | data1 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 32)); |
| 517 | | data2 = BYTE_REVERSE32((UINT32)(paletteram64[offset] >> 0)); |
| 485 | COMBINE_DATA(&state->paletteram64[offset]); |
| 486 | data1 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 32)); |
| 487 | data2 = BYTE_REVERSE32((UINT32)(state->paletteram64[offset] >> 0)); |
| 518 | 488 | |
| 519 | 489 | r1 = ((data1 >> 0) & 0x1f); |
| 520 | 490 | g1 = ((data1 >> 5) & 0x1f); |
| r10427 | r10428 | |
| 523 | 493 | g2 = ((data2 >> 5) & 0x1f); |
| 524 | 494 | b2 = ((data2 >> 10) & 0x1f); |
| 525 | 495 | |
| 526 | | pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1; |
| 527 | | pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2; |
| 496 | state->pal_lookup[(offset*2)+0] = (data1 & 0x8000) | (r1 << 10) | (g1 << 5) | b1; |
| 497 | state->pal_lookup[(offset*2)+1] = (data2 & 0x8000) | (r2 << 10) | (g2 << 5) | b2; |
| 528 | 498 | } |
| 529 | 499 | |
| 530 | 500 | READ64_HANDLER( model3_palette_r ) |
| 531 | 501 | { |
| 532 | | return paletteram64[offset]; |
| 502 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 503 | return state->paletteram64[offset]; |
| 533 | 504 | } |
| 534 | 505 | |
| 535 | 506 | |
| r10427 | r10428 | |
| 545 | 516 | */ |
| 546 | 517 | static void invalidate_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight) |
| 547 | 518 | { |
| 519 | model3_state *state = machine->driver_data<model3_state>(); |
| 548 | 520 | int wtiles = 1 << texwidth; |
| 549 | 521 | int htiles = 1 << texheight; |
| 550 | 522 | int x, y; |
| 551 | 523 | |
| 552 | 524 | for (y = 0; y < htiles; y++) |
| 553 | 525 | for (x = 0; x < wtiles; x++) |
| 554 | | while (texcache[page][texy + y][texx + x] != NULL) |
| 526 | while (state->texcache[page][texy + y][texx + x] != NULL) |
| 555 | 527 | { |
| 556 | | cached_texture *freeme = texcache[page][texy + y][texx + x]; |
| 557 | | texcache[page][texy + y][texx + x] = freeme->next; |
| 528 | cached_texture *freeme = state->texcache[page][texy + y][texx + x]; |
| 529 | state->texcache[page][texy + y][texx + x] = freeme->next; |
| 558 | 530 | auto_free(machine, freeme); |
| 559 | 531 | } |
| 560 | 532 | } |
| 561 | 533 | |
| 562 | 534 | static cached_texture *get_texture(running_machine *machine, int page, int texx, int texy, int texwidth, int texheight, int format) |
| 563 | 535 | { |
| 564 | | cached_texture *tex = texcache[page][texy][texx]; |
| 536 | model3_state *state = machine->driver_data<model3_state>(); |
| 537 | cached_texture *tex = state->texcache[page][texy][texx]; |
| 565 | 538 | int pixheight = 32 << texheight; |
| 566 | 539 | int pixwidth = 32 << texwidth; |
| 567 | 540 | UINT32 alpha = ~0; |
| 568 | 541 | int x, y; |
| 569 | 542 | |
| 570 | 543 | /* if we have one already, validate it */ |
| 571 | | for (tex = texcache[page][texy][texx]; tex != NULL; tex = tex->next) |
| 544 | for (tex = state->texcache[page][texy][texx]; tex != NULL; tex = tex->next) |
| 572 | 545 | if (tex->width == texwidth && tex->height == texheight && tex->format == format) |
| 573 | 546 | return tex; |
| 574 | 547 | |
| r10427 | r10428 | |
| 579 | 552 | tex->format = format; |
| 580 | 553 | |
| 581 | 554 | /* set the new texture */ |
| 582 | | tex->next = texcache[page][texy][texx]; |
| 583 | | texcache[page][texy][texx] = tex; |
| 555 | tex->next = state->texcache[page][texy][texx]; |
| 556 | state->texcache[page][texy][texx] = tex; |
| 584 | 557 | |
| 585 | 558 | /* decode it */ |
| 586 | 559 | for (y = 0; y < pixheight; y++) |
| 587 | 560 | { |
| 588 | | const UINT16 *texsrc = &texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; |
| 561 | const UINT16 *texsrc = &state->texture_ram[page][(texy * 32 + y) * 2048 + texx * 32]; |
| 589 | 562 | rgb_t *dest = tex->data + 2 * pixwidth * y; |
| 590 | 563 | |
| 591 | 564 | switch (format) |
| r10427 | r10428 | |
| 677 | 650 | |
| 678 | 651 | WRITE64_HANDLER( real3d_display_list_w ) |
| 679 | 652 | { |
| 653 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 680 | 654 | if(ACCESSING_BITS_32_63) { |
| 681 | | display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); |
| 655 | state->display_list_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); |
| 682 | 656 | } |
| 683 | 657 | if(ACCESSING_BITS_0_31) { |
| 684 | | display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); |
| 658 | state->display_list_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); |
| 685 | 659 | } |
| 686 | 660 | } |
| 687 | 661 | |
| 688 | 662 | WRITE64_HANDLER( real3d_polygon_ram_w ) |
| 689 | 663 | { |
| 664 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 690 | 665 | if(ACCESSING_BITS_32_63) { |
| 691 | | polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); |
| 666 | state->polygon_ram[offset*2] = BYTE_REVERSE32((UINT32)(data >> 32)); |
| 692 | 667 | } |
| 693 | 668 | if(ACCESSING_BITS_0_31) { |
| 694 | | polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); |
| 669 | state->polygon_ram[(offset*2)+1] = BYTE_REVERSE32((UINT32)(data)); |
| 695 | 670 | } |
| 696 | 671 | } |
| 697 | 672 | |
| r10427 | r10428 | |
| 707 | 682 | 50, 51, 54, 55, 58, 59, 62, 63 |
| 708 | 683 | }; |
| 709 | 684 | |
| 710 | | INLINE void write_texture16(int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 685 | INLINE void write_texture16(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 711 | 686 | { |
| 712 | 687 | int x,y,i,j; |
| 713 | 688 | |
| r10427 | r10428 | |
| 715 | 690 | { |
| 716 | 691 | for(x=xpos; x < xpos+width; x+=8) |
| 717 | 692 | { |
| 718 | | UINT16 *texture = &texture_ram[page][y*2048+x]; |
| 693 | UINT16 *texture = &state->texture_ram[page][y*2048+x]; |
| 719 | 694 | int b = 0; |
| 720 | 695 | for(j=y; j < y+8; j++) { |
| 721 | 696 | for(i=x; i < x+8; i++) { |
| r10427 | r10428 | |
| 730 | 705 | } |
| 731 | 706 | |
| 732 | 707 | #ifdef UNUSED_FUNCTION |
| 733 | | INLINE void write_texture8(int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 708 | INLINE void write_texture8(model3_state *state, int xpos, int ypos, int width, int height, int page, UINT16 *data) |
| 734 | 709 | { |
| 735 | 710 | int x,y,i,j; |
| 736 | 711 | UINT16 color = 0x7c00; |
| r10427 | r10428 | |
| 739 | 714 | { |
| 740 | 715 | for(x=xpos; x < xpos+width; x+=8) |
| 741 | 716 | { |
| 742 | | UINT16 *texture = &texture_ram[page][y*2048+x]; |
| 717 | UINT16 *texture = &state->texture_ram[page][y*2048+x]; |
| 743 | 718 | for(j=y; j < y+4; j++) { |
| 744 | 719 | for(i=x; i < x+8; i++) { |
| 745 | 720 | *texture = color; |
| r10427 | r10428 | |
| 754 | 729 | |
| 755 | 730 | static void real3d_upload_texture(running_machine *machine, UINT32 header, UINT32 *data) |
| 756 | 731 | { |
| 732 | model3_state *state = machine->driver_data<model3_state>(); |
| 757 | 733 | int width = 32 << ((header >> 14) & 0x7); |
| 758 | 734 | int height = 32 << ((header >> 17) & 0x7); |
| 759 | 735 | int xpos = (header & 0x3f) * 32; |
| 760 | 736 | int ypos = ((header >> 7) & 0x1f) * 32; |
| 761 | 737 | int page = (header >> 20) & 0x1; |
| 762 | | // int bitdepth = (header >> 23) & 0x1; |
| 738 | //int bitdepth = (header >> 23) & 0x1; |
| 763 | 739 | |
| 764 | 740 | switch(header >> 24) |
| 765 | 741 | { |
| 766 | 742 | case 0x00: /* Texture with mipmaps */ |
| 767 | | // if(bitdepth) { |
| 768 | | write_texture16(xpos, ypos, width, height, page, (UINT16*)data); |
| 743 | //if(bitdepth) { |
| 744 | write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); |
| 769 | 745 | invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 770 | | // } else { |
| 746 | //} else { |
| 771 | 747 | /* TODO: 8-bit textures are weird. need to figure out some additional bits */ |
| 772 | 748 | //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); |
| 773 | 749 | //write_texture8(xpos, ypos, width, height, page, (UINT16*)data); |
| 774 | | // } |
| 750 | //} |
| 775 | 751 | break; |
| 776 | 752 | case 0x01: /* Texture without mipmaps */ |
| 777 | | // if(bitdepth) { |
| 778 | | write_texture16(xpos, ypos, width, height, page, (UINT16*)data); |
| 753 | //if(bitdepth) { |
| 754 | write_texture16(state, xpos, ypos, width, height, page, (UINT16*)data); |
| 779 | 755 | invalidate_texture(machine, page, header & 0x3f, (header >> 7) & 0x1f, (header >> 14) & 0x7, (header >> 17) & 0x7); |
| 780 | | // } else { |
| 756 | //} else { |
| 781 | 757 | /* TODO: 8-bit textures are weird. need to figure out some additional bits */ |
| 782 | 758 | //logerror("W: %d, H: %d, X: %d, Y: %d, P: %d, Bit: %d, : %08X, %08X\n", width, height, xpos, ypos, page, bitdepth, header & 0x00681040, header); |
| 783 | 759 | //write_texture8(xpos, ypos, width, height, page, (UINT16*)data); |
| 784 | | // } |
| 760 | //} |
| 785 | 761 | break; |
| 786 | 762 | case 0x02: /* Only mipmaps */ |
| 787 | 763 | break; |
| r10427 | r10428 | |
| 795 | 771 | |
| 796 | 772 | void real3d_display_list_end(running_machine *machine) |
| 797 | 773 | { |
| 774 | model3_state *state = machine->driver_data<model3_state>(); |
| 798 | 775 | /* upload textures if there are any in the FIFO */ |
| 799 | | if (texture_fifo_pos > 0) |
| 776 | if (state->texture_fifo_pos > 0) |
| 800 | 777 | { |
| 801 | 778 | int i = 0; |
| 802 | | while(i < texture_fifo_pos) |
| 779 | while(i < state->texture_fifo_pos) |
| 803 | 780 | { |
| 804 | | int length = (texture_fifo[i] / 2) + 2; |
| 805 | | UINT32 header = texture_fifo[i+1]; |
| 806 | | real3d_upload_texture(machine, header, &texture_fifo[i+2]); |
| 781 | int length = (state->texture_fifo[i] / 2) + 2; |
| 782 | UINT32 header = state->texture_fifo[i+1]; |
| 783 | real3d_upload_texture(machine, header, &state->texture_fifo[i+2]); |
| 807 | 784 | i += length; |
| 808 | 785 | }; |
| 809 | 786 | } |
| 810 | | texture_fifo_pos = 0; |
| 811 | | bitmap_fill(zbuffer, NULL, 0); |
| 812 | | bitmap_fill(bitmap3d, NULL, 0x8000); |
| 787 | state->texture_fifo_pos = 0; |
| 788 | bitmap_fill(state->zbuffer, NULL, 0); |
| 789 | bitmap_fill(state->bitmap3d, NULL, 0x8000); |
| 813 | 790 | real3d_traverse_display_list(machine); |
| 814 | | // real3d_display_list = 1; |
| 791 | //state->real3d_display_list = 1; |
| 815 | 792 | } |
| 816 | 793 | |
| 817 | 794 | void real3d_display_list1_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) |
| 818 | 795 | { |
| 796 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 819 | 797 | int i; |
| 820 | 798 | int d = (dst & 0xffffff) / 4; |
| 821 | 799 | for(i=0; i < length; i+=4) { |
| r10427 | r10428 | |
| 825 | 803 | } else { |
| 826 | 804 | w = space->read_dword(src); |
| 827 | 805 | } |
| 828 | | display_list_ram[d++] = w; |
| 806 | state->display_list_ram[d++] = w; |
| 829 | 807 | src += 4; |
| 830 | 808 | } |
| 831 | 809 | } |
| 832 | 810 | |
| 833 | 811 | void real3d_display_list2_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) |
| 834 | 812 | { |
| 813 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 835 | 814 | int i; |
| 836 | 815 | int d = (dst & 0xffffff) / 4; |
| 837 | 816 | for(i=0; i < length; i+=4) { |
| r10427 | r10428 | |
| 841 | 820 | } else { |
| 842 | 821 | w = space->read_dword(src); |
| 843 | 822 | } |
| 844 | | culling_ram[d++] = w; |
| 823 | state->culling_ram[d++] = w; |
| 845 | 824 | src += 4; |
| 846 | 825 | } |
| 847 | 826 | } |
| 848 | 827 | |
| 849 | 828 | void real3d_vrom_texture_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) |
| 850 | 829 | { |
| 830 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 851 | 831 | if((dst & 0xff) == 0) { |
| 852 | 832 | |
| 853 | 833 | UINT32 address, header; |
| r10427 | r10428 | |
| 859 | 839 | address = space->read_dword((src+0)); |
| 860 | 840 | header = space->read_dword((src+4)); |
| 861 | 841 | } |
| 862 | | real3d_upload_texture(space->machine, header, (UINT32*)&model3_vrom[address]); |
| 842 | real3d_upload_texture(space->machine, header, (UINT32*)&state->vrom[address]); |
| 863 | 843 | } |
| 864 | 844 | } |
| 865 | 845 | |
| 866 | 846 | void real3d_texture_fifo_dma(address_space *space, UINT32 src, int length, int byteswap) |
| 867 | 847 | { |
| 848 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 868 | 849 | int i; |
| 869 | 850 | for(i=0; i < length; i+=4) { |
| 870 | 851 | UINT32 w; |
| r10427 | r10428 | |
| 873 | 854 | } else { |
| 874 | 855 | w = space->read_dword(src); |
| 875 | 856 | } |
| 876 | | texture_fifo[texture_fifo_pos] = w; |
| 877 | | texture_fifo_pos++; |
| 857 | state->texture_fifo[state->texture_fifo_pos] = w; |
| 858 | state->texture_fifo_pos++; |
| 878 | 859 | src += 4; |
| 879 | 860 | } |
| 880 | 861 | } |
| 881 | 862 | |
| 882 | 863 | void real3d_polygon_ram_dma(address_space *space, UINT32 src, UINT32 dst, int length, int byteswap) |
| 883 | 864 | { |
| 865 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 884 | 866 | int i; |
| 885 | 867 | int d = (dst & 0xffffff) / 4; |
| 886 | 868 | for(i=0; i < length; i+=4) { |
| r10427 | r10428 | |
| 890 | 872 | } else { |
| 891 | 873 | w = space->read_dword(src); |
| 892 | 874 | } |
| 893 | | polygon_ram[d++] = w; |
| 875 | state->polygon_ram[d++] = w; |
| 894 | 876 | src += 4; |
| 895 | 877 | } |
| 896 | 878 | } |
| r10427 | r10428 | |
| 939 | 921 | memcpy(out, &tmp, sizeof(MATRIX)); |
| 940 | 922 | } |
| 941 | 923 | |
| 942 | | static void init_matrix_stack(void) |
| 924 | static void init_matrix_stack(running_machine *machine) |
| 943 | 925 | { |
| 926 | model3_state *state = machine->driver_data<model3_state>(); |
| 927 | MATRIX *matrix_stack; |
| 928 | matrix_stack = state->matrix_stack = auto_alloc_array_clear(machine, MATRIX, MATRIX_STACK_SIZE); |
| 929 | |
| 944 | 930 | /* initialize the first matrix as identity */ |
| 945 | 931 | matrix_stack[0][0][0] = 1.0f; |
| 946 | 932 | matrix_stack[0][0][1] = 0.0f; |
| r10427 | r10428 | |
| 959 | 945 | matrix_stack[0][3][2] = 0.0f; |
| 960 | 946 | matrix_stack[0][3][3] = 1.0f; |
| 961 | 947 | |
| 962 | | matrix_stack_ptr = 0; |
| 948 | state->matrix_stack_ptr = 0; |
| 963 | 949 | } |
| 964 | 950 | |
| 965 | | static void get_top_matrix(MATRIX *out) |
| 951 | static void get_top_matrix(model3_state *state, MATRIX *out) |
| 966 | 952 | { |
| 967 | | memcpy( out, &matrix_stack[matrix_stack_ptr], sizeof(MATRIX)); |
| 953 | memcpy( out, &state->matrix_stack[state->matrix_stack_ptr], sizeof(MATRIX)); |
| 968 | 954 | } |
| 969 | 955 | |
| 970 | | static void push_matrix_stack(void) |
| 956 | static void push_matrix_stack(model3_state *state) |
| 971 | 957 | { |
| 972 | | matrix_stack_ptr++; |
| 973 | | if (matrix_stack_ptr >= MATRIX_STACK_SIZE) |
| 958 | state->matrix_stack_ptr++; |
| 959 | if (state->matrix_stack_ptr >= MATRIX_STACK_SIZE) |
| 974 | 960 | fatalerror("push_matrix_stack: matrix stack overflow"); |
| 975 | 961 | |
| 976 | | memcpy( &matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr-1], sizeof(MATRIX)); |
| 962 | memcpy( &state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr-1], sizeof(MATRIX)); |
| 977 | 963 | } |
| 978 | 964 | |
| 979 | | static void pop_matrix_stack(void) |
| 965 | static void pop_matrix_stack(model3_state *state) |
| 980 | 966 | { |
| 981 | | matrix_stack_ptr--; |
| 982 | | if (matrix_stack_ptr < 0) |
| 967 | state->matrix_stack_ptr--; |
| 968 | if (state->matrix_stack_ptr < 0) |
| 983 | 969 | fatalerror("pop_matrix_stack: matrix stack underflow"); |
| 984 | 970 | } |
| 985 | 971 | |
| 986 | | static void multiply_matrix_stack(MATRIX matrix) |
| 972 | static void multiply_matrix_stack(model3_state *state, MATRIX matrix) |
| 987 | 973 | { |
| 988 | | matrix_multiply(matrix, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]); |
| 974 | matrix_multiply(matrix, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]); |
| 989 | 975 | } |
| 990 | 976 | |
| 991 | | static void translate_matrix_stack(float x, float y, float z) |
| 977 | static void translate_matrix_stack(model3_state *state, float x, float y, float z) |
| 992 | 978 | { |
| 993 | 979 | MATRIX tm; |
| 994 | 980 | |
| r10427 | r10428 | |
| 997 | 983 | tm[2][0] = 0.0f; tm[2][1] = 0.0f; tm[2][2] = 1.0f; tm[2][3] = 0.0f; |
| 998 | 984 | tm[3][0] = x; tm[3][1] = y; tm[3][2] = z; tm[3][3] = 1.0f; |
| 999 | 985 | |
| 1000 | | matrix_multiply(tm, matrix_stack[matrix_stack_ptr], &matrix_stack[matrix_stack_ptr]); |
| 986 | matrix_multiply(tm, state->matrix_stack[state->matrix_stack_ptr], &state->matrix_stack[state->matrix_stack_ptr]); |
| 1001 | 987 | } |
| 1002 | 988 | |
| 1003 | 989 | /*****************************************************************************/ |
| r10427 | r10428 | |
| 1077 | 1063 | |
| 1078 | 1064 | static void render_one(running_machine *machine, TRIANGLE *tri) |
| 1079 | 1065 | { |
| 1080 | | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(poly); |
| 1066 | model3_state *state = machine->driver_data<model3_state>(); |
| 1067 | poly_extra_data *extra = (poly_extra_data *)poly_get_extra_data(state->poly); |
| 1081 | 1068 | poly_draw_scanline_func callback = NULL; |
| 1082 | 1069 | |
| 1083 | 1070 | tri->v[0].pz = 1.0f / tri->v[0].pz; |
| 1084 | 1071 | tri->v[1].pz = 1.0f / tri->v[1].pz; |
| 1085 | 1072 | tri->v[2].pz = 1.0f / tri->v[2].pz; |
| 1086 | 1073 | |
| 1074 | extra->zbuffer = state->zbuffer; |
| 1087 | 1075 | if (tri->param & TRI_PARAM_TEXTURE_ENABLE) |
| 1088 | 1076 | { |
| 1089 | 1077 | tri->v[0].pu = tri->v[0].pu * tri->v[0].pz * 256.0f; |
| r10427 | r10428 | |
| 1104 | 1092 | callback = (tri->transparency >= 32) ? draw_scanline_normal : draw_scanline_trans; |
| 1105 | 1093 | else |
| 1106 | 1094 | callback = draw_scanline_alpha; |
| 1107 | | poly_render_triangle(poly, bitmap3d, &clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1095 | poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, callback, 3, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1108 | 1096 | } |
| 1109 | 1097 | else |
| 1110 | 1098 | { |
| r10427 | r10428 | |
| 1112 | 1100 | extra->polygon_intensity = tri->intensity; |
| 1113 | 1101 | extra->color = tri->color; |
| 1114 | 1102 | |
| 1115 | | poly_render_triangle(poly, bitmap3d, &clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1103 | poly_render_triangle(state->poly, state->bitmap3d, &state->clip3d, draw_scanline_color, 1, &tri->v[0], &tri->v[1], &tri->v[2]); |
| 1116 | 1104 | } |
| 1117 | 1105 | } |
| 1118 | 1106 | |
| 1119 | 1107 | static void draw_model(running_machine *machine, UINT32 addr) |
| 1120 | 1108 | { |
| 1121 | | UINT32 *model = (addr >= 0x100000) ? &model3_vrom[addr] : &polygon_ram[addr]; |
| 1109 | model3_state *state = machine->driver_data<model3_state>(); |
| 1110 | UINT32 *model = (addr >= 0x100000) ? &state->vrom[addr] : &state->polygon_ram[addr]; |
| 1122 | 1111 | UINT32 header[7]; |
| 1123 | 1112 | int index = 0; |
| 1124 | 1113 | int last_polygon = FALSE, back_face = FALSE; |
| r10427 | r10428 | |
| 1132 | 1121 | MATRIX transform_matrix; |
| 1133 | 1122 | float center_x, center_y; |
| 1134 | 1123 | |
| 1135 | | if(model3_step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ |
| 1124 | if(state->step < 0x15) { /* position coordinates are 17.15 fixed-point in Step 1.0 */ |
| 1136 | 1125 | fixed_point_fraction = 1.0f / 32768.0f; |
| 1137 | 1126 | } else { /* 13.19 fixed-point in other Steps */ |
| 1138 | 1127 | fixed_point_fraction = 1.0f / 524288.0f; |
| 1139 | 1128 | } |
| 1140 | 1129 | |
| 1141 | | get_top_matrix(&transform_matrix); |
| 1130 | get_top_matrix(state, &transform_matrix); |
| 1142 | 1131 | |
| 1143 | 1132 | /* current viewport center coordinates on screen */ |
| 1144 | | center_x = (float)(viewport_region_x + (viewport_region_width / 2)); |
| 1145 | | center_y = (float)(viewport_region_y + (viewport_region_height / 2)); |
| 1133 | center_x = (float)(state->viewport_region_x + (state->viewport_region_width / 2)); |
| 1134 | center_y = (float)(state->viewport_region_y + (state->viewport_region_height / 2)); |
| 1146 | 1135 | |
| 1147 | 1136 | memset(prev_vertex, 0, sizeof(prev_vertex)); |
| 1148 | 1137 | |
| r10427 | r10428 | |
| 1210 | 1199 | (normal[1] * transform_matrix[1][2]) + |
| 1211 | 1200 | (normal[2] * transform_matrix[2][2]); |
| 1212 | 1201 | |
| 1213 | | sn[0] *= coordinate_system[0][1]; |
| 1214 | | sn[1] *= coordinate_system[1][2]; |
| 1215 | | sn[2] *= coordinate_system[2][0]; |
| 1202 | sn[0] *= state->coordinate_system[0][1]; |
| 1203 | sn[1] *= state->coordinate_system[1][2]; |
| 1204 | sn[2] *= state->coordinate_system[2][0]; |
| 1216 | 1205 | |
| 1217 | 1206 | /* TODO: depth bias */ |
| 1218 | 1207 | /* transform vertices */ |
| r10427 | r10428 | |
| 1229 | 1218 | matrix_multiply_vector(transform_matrix, vect, &p[i]); |
| 1230 | 1219 | |
| 1231 | 1220 | /* apply coordinate system */ |
| 1232 | | clip_vert[i].x = p[i][0] * coordinate_system[0][1]; |
| 1233 | | clip_vert[i].y = p[i][1] * coordinate_system[1][2]; |
| 1234 | | clip_vert[i].pz = p[i][2] * coordinate_system[2][0]; |
| 1221 | clip_vert[i].x = p[i][0] * state->coordinate_system[0][1]; |
| 1222 | clip_vert[i].y = p[i][1] * state->coordinate_system[1][2]; |
| 1223 | clip_vert[i].pz = p[i][2] * state->coordinate_system[2][0]; |
| 1235 | 1224 | clip_vert[i].pu = vertex[i].pu * texture_coord_scale; |
| 1236 | 1225 | clip_vert[i].pv = vertex[i].pv * texture_coord_scale; |
| 1237 | 1226 | } |
| 1238 | 1227 | |
| 1239 | 1228 | /* clip against view frustum */ |
| 1240 | | num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[0], clip_vert); |
| 1241 | | num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[1], clip_vert); |
| 1242 | | num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[2], clip_vert); |
| 1243 | | num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[3], clip_vert); |
| 1244 | | num_vertices = clip_polygon(clip_vert, num_vertices, clip_plane[4], clip_vert); |
| 1229 | num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[0], clip_vert); |
| 1230 | num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[1], clip_vert); |
| 1231 | num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[2], clip_vert); |
| 1232 | num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[3], clip_vert); |
| 1233 | num_vertices = clip_polygon(clip_vert, num_vertices, state->clip_plane[4], clip_vert); |
| 1245 | 1234 | |
| 1246 | 1235 | /* backface culling */ |
| 1247 | 1236 | if( (header[6] & 0x800000) && (!(header[1] & 0x0010)) ) { |
| r10427 | r10428 | |
| 1257 | 1246 | /* homogeneous Z-divide, screen-space transformation */ |
| 1258 | 1247 | for(i=0; i < num_vertices; i++) { |
| 1259 | 1248 | float ooz = 1.0f / clip_vert[i].pz; |
| 1260 | | clip_vert[i].x = ((clip_vert[i].x * ooz) * viewport_focal_length) + center_x; |
| 1261 | | clip_vert[i].y = ((clip_vert[i].y * ooz) * viewport_focal_length) + center_y; |
| 1249 | clip_vert[i].x = ((clip_vert[i].x * ooz) * state->viewport_focal_length) + center_x; |
| 1250 | clip_vert[i].y = ((clip_vert[i].y * ooz) * state->viewport_focal_length) + center_y; |
| 1262 | 1251 | } |
| 1263 | 1252 | |
| 1264 | 1253 | // lighting |
| 1265 | 1254 | if ((header[6] & 0x10000) == 0) |
| 1266 | 1255 | { |
| 1267 | | dot = dot_product3(sn, parallel_light); |
| 1268 | | intensity = ((dot * parallel_light_intensity) + ambient_light_intensity) * 256.0f; |
| 1256 | dot = dot_product3(sn, state->parallel_light); |
| 1257 | intensity = ((dot * state->parallel_light_intensity) + state->ambient_light_intensity) * 256.0f; |
| 1269 | 1258 | if (intensity > 256) |
| 1270 | 1259 | { |
| 1271 | 1260 | intensity = 256; |
| r10427 | r10428 | |
| 1312 | 1301 | /*****************************************************************************/ |
| 1313 | 1302 | /* display list parser */ |
| 1314 | 1303 | |
| 1315 | | static UINT32 *get_memory_pointer(UINT32 address) |
| 1304 | static UINT32 *get_memory_pointer(model3_state *state, UINT32 address) |
| 1316 | 1305 | { |
| 1317 | 1306 | if (address & 0x800000) |
| 1318 | 1307 | { |
| 1319 | 1308 | if (address >= 0x840000) { |
| 1320 | 1309 | fatalerror("get_memory_pointer: invalid display list memory address %08X", address); |
| 1321 | 1310 | } |
| 1322 | | return &display_list_ram[address & 0x7fffff]; |
| 1311 | return &state->display_list_ram[address & 0x7fffff]; |
| 1323 | 1312 | } |
| 1324 | 1313 | else |
| 1325 | 1314 | { |
| 1326 | 1315 | if (address >= 0x100000) { |
| 1327 | 1316 | fatalerror("get_memory_pointer: invalid node ram address %08X", address); |
| 1328 | 1317 | } |
| 1329 | | return &culling_ram[address]; |
| 1318 | return &state->culling_ram[address]; |
| 1330 | 1319 | } |
| 1331 | 1320 | } |
| 1332 | 1321 | |
| 1333 | | static void load_matrix(int matrix_num, MATRIX *out) |
| 1322 | static void load_matrix(model3_state *state, int matrix_num, MATRIX *out) |
| 1334 | 1323 | { |
| 1335 | | float *matrix = (float *)get_memory_pointer(matrix_base_address + matrix_num * 12); |
| 1324 | float *matrix = (float *)get_memory_pointer(state, state->matrix_base_address + matrix_num * 12); |
| 1336 | 1325 | |
| 1337 | 1326 | (*out)[0][0] = matrix[3]; (*out)[0][1] = matrix[6]; (*out)[0][2] = matrix[9]; (*out)[0][3] = 0.0f; |
| 1338 | 1327 | (*out)[1][0] = matrix[4]; (*out)[1][1] = matrix[7]; (*out)[1][2] = matrix[10]; (*out)[1][3] = 0.0f; |
| r10427 | r10428 | |
| 1342 | 1331 | |
| 1343 | 1332 | static void traverse_list4(running_machine *machine, int lod_num, UINT32 address) |
| 1344 | 1333 | { |
| 1334 | model3_state *state = machine->driver_data<model3_state>(); |
| 1335 | |
| 1345 | 1336 | /* does something with the LOD selection */ |
| 1346 | | UINT32 *list = get_memory_pointer(address); |
| 1337 | UINT32 *list = get_memory_pointer(state, address); |
| 1347 | 1338 | UINT32 link = list[0]; |
| 1348 | 1339 | |
| 1349 | 1340 | draw_model(machine, link & 0xffffff); |
| r10427 | r10428 | |
| 1351 | 1342 | |
| 1352 | 1343 | static void traverse_list(running_machine *machine, UINT32 address) |
| 1353 | 1344 | { |
| 1354 | | UINT32 *list = get_memory_pointer(address); |
| 1345 | model3_state *state = machine->driver_data<model3_state>(); |
| 1346 | UINT32 *list = get_memory_pointer(state, address); |
| 1355 | 1347 | int list_ptr = 0; |
| 1356 | 1348 | |
| 1357 | | if (list_depth > 2) |
| 1349 | if (state->list_depth > 2) |
| 1358 | 1350 | return; |
| 1359 | 1351 | |
| 1360 | | list_depth++; |
| 1352 | state->list_depth++; |
| 1361 | 1353 | |
| 1362 | 1354 | /* find the end of the list */ |
| 1363 | 1355 | while (1) |
| r10427 | r10428 | |
| 1377 | 1369 | { |
| 1378 | 1370 | address = list[--list_ptr] & 0xffffff; |
| 1379 | 1371 | if (address != 0 && address != 0x800800) |
| 1380 | | // if (address != 0) |
| 1372 | //if (address != 0) |
| 1381 | 1373 | draw_block(machine, address); |
| 1382 | 1374 | } |
| 1383 | 1375 | |
| 1384 | | list_depth--; |
| 1376 | state->list_depth--; |
| 1385 | 1377 | } |
| 1386 | 1378 | |
| 1387 | 1379 | INLINE void process_link(running_machine *machine, UINT32 address, UINT32 link) |
| r10427 | r10428 | |
| 1412 | 1404 | |
| 1413 | 1405 | static void draw_block(running_machine *machine, UINT32 address) |
| 1414 | 1406 | { |
| 1415 | | const UINT32 *node = get_memory_pointer(address); |
| 1407 | model3_state *state = machine->driver_data<model3_state>(); |
| 1408 | const UINT32 *node = get_memory_pointer(state, address); |
| 1416 | 1409 | UINT32 link; |
| 1417 | 1410 | int node_matrix; |
| 1418 | 1411 | float x, y, z; |
| 1419 | 1412 | MATRIX matrix; |
| 1420 | 1413 | int offset; |
| 1421 | 1414 | |
| 1422 | | offset = (model3_step < 0x15) ? 2 : 0; |
| 1415 | offset = (state->step < 0x15) ? 2 : 0; |
| 1423 | 1416 | link = node[7 - offset]; |
| 1424 | 1417 | |
| 1425 | 1418 | /* apply matrix and translation */ |
| 1426 | 1419 | node_matrix = node[3 - offset] & 0xfff; |
| 1427 | | load_matrix(node_matrix, &matrix); |
| 1420 | load_matrix(state, node_matrix, &matrix); |
| 1428 | 1421 | |
| 1429 | | push_matrix_stack(); |
| 1422 | push_matrix_stack(state); |
| 1430 | 1423 | |
| 1431 | 1424 | if (node[0] & 0x10) |
| 1432 | 1425 | { |
| 1433 | 1426 | x = *(float *)&node[4 - offset]; |
| 1434 | 1427 | y = *(float *)&node[5 - offset]; |
| 1435 | 1428 | z = *(float *)&node[6 - offset]; |
| 1436 | | translate_matrix_stack(x, y, z); |
| 1429 | translate_matrix_stack(state, x, y, z); |
| 1437 | 1430 | } |
| 1438 | 1431 | else if (node_matrix != 0) |
| 1439 | | multiply_matrix_stack(matrix); |
| 1432 | multiply_matrix_stack(state, matrix); |
| 1440 | 1433 | |
| 1441 | 1434 | /* bit 0x08 of word 0 indicates a pointer list */ |
| 1442 | 1435 | if (node[0] & 0x08) |
| r10427 | r10428 | |
| 1444 | 1437 | else |
| 1445 | 1438 | process_link(machine, address, link); |
| 1446 | 1439 | |
| 1447 | | pop_matrix_stack(); |
| 1440 | pop_matrix_stack(state); |
| 1448 | 1441 | |
| 1449 | 1442 | /* handle the second link */ |
| 1450 | 1443 | link = node[8 - offset]; |
| r10427 | r10428 | |
| 1453 | 1446 | |
| 1454 | 1447 | static void draw_viewport(running_machine *machine, int pri, UINT32 address) |
| 1455 | 1448 | { |
| 1456 | | const UINT32 *node = get_memory_pointer(address); |
| 1449 | model3_state *state = machine->driver_data<model3_state>(); |
| 1450 | const UINT32 *node = get_memory_pointer(state, address); |
| 1457 | 1451 | UINT32 link_address; |
| 1458 | 1452 | float /*viewport_left, viewport_right, */viewport_top, viewport_bottom; |
| 1459 | 1453 | float /*fov_x,*/ fov_y; |
| r10427 | r10428 | |
| 1472 | 1466 | return; |
| 1473 | 1467 | |
| 1474 | 1468 | /* set viewport parameters */ |
| 1475 | | viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ |
| 1476 | | viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; |
| 1477 | | viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ |
| 1478 | | viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; |
| 1469 | state->viewport_region_x = (node[26] & 0xffff) >> 4; /* 12.4 fixed point */ |
| 1470 | state->viewport_region_y = ((node[26] >> 16) & 0xffff) >> 4; |
| 1471 | state->viewport_region_width = (node[20] & 0xffff) >> 2; /* 14.2 fixed point */ |
| 1472 | state->viewport_region_height = ((node[20] >> 16) & 0xffff) >> 2; |
| 1479 | 1473 | |
| 1480 | 1474 | /* frustum plane angles */ |
| 1481 | 1475 | //viewport_left = RADIAN_TO_DEGREE(asin(*(float *)&node[12])); |
| r10427 | r10428 | |
| 1484 | 1478 | viewport_bottom = RADIAN_TO_DEGREE(asin(*(float *)&node[18])); |
| 1485 | 1479 | |
| 1486 | 1480 | /* build clipping planes */ |
| 1487 | | clip_plane[0].x = *(float *)&node[13]; clip_plane[0].y = 0.0f; clip_plane[0].z = *(float *)&node[12]; clip_plane[0].d = 0.0f; |
| 1488 | | clip_plane[1].x = *(float *)&node[17]; clip_plane[1].y = 0.0f; clip_plane[1].z = *(float *)&node[16]; clip_plane[1].d = 0.0f; |
| 1489 | | clip_plane[2].x = 0.0f; clip_plane[2].y = *(float *)&node[15]; clip_plane[2].z = *(float *)&node[14]; clip_plane[2].d = 0.0f; |
| 1490 | | clip_plane[3].x = 0.0f; clip_plane[3].y = *(float *)&node[19]; clip_plane[3].z = *(float *)&node[18]; clip_plane[3].d = 0.0f; |
| 1491 | | clip_plane[4].x = 0.0f; clip_plane[4].y = 0.0f; clip_plane[4].z = 1.0f; clip_plane[4].d = 1.0f; |
| 1481 | state->clip_plane[0].x = *(float *)&node[13]; state->clip_plane[0].y = 0.0f; state->clip_plane[0].z = *(float *)&node[12]; state->clip_plane[0].d = 0.0f; |
| 1482 | state->clip_plane[1].x = *(float *)&node[17]; state->clip_plane[1].y = 0.0f; state->clip_plane[1].z = *(float *)&node[16]; state->clip_plane[1].d = 0.0f; |
| 1483 | state->clip_plane[2].x = 0.0f; state->clip_plane[2].y = *(float *)&node[15]; state->clip_plane[2].z = *(float *)&node[14]; state->clip_plane[2].d = 0.0f; |
| 1484 | state->clip_plane[3].x = 0.0f; state->clip_plane[3].y = *(float *)&node[19]; state->clip_plane[3].z = *(float *)&node[18]; state->clip_plane[3].d = 0.0f; |
| 1485 | state->clip_plane[4].x = 0.0f; state->clip_plane[4].y = 0.0f; state->clip_plane[4].z = 1.0f; state->clip_plane[4].d = 1.0f; |
| 1492 | 1486 | |
| 1493 | 1487 | /* compute field of view */ |
| 1494 | 1488 | //fov_x = viewport_left + viewport_right; |
| 1495 | 1489 | fov_y = viewport_top + viewport_bottom; |
| 1496 | | viewport_focal_length = (viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); |
| 1490 | state->viewport_focal_length = (state->viewport_region_height / 2) / tan( (fov_y * M_PI / 180.0f) / 2.0f ); |
| 1497 | 1491 | |
| 1498 | | matrix_base_address = node[22]; |
| 1492 | state->matrix_base_address = node[22]; |
| 1499 | 1493 | /* TODO: where does node[23] point to ? LOD table ? */ |
| 1500 | 1494 | |
| 1501 | 1495 | /* set lighting parameters */ |
| 1502 | | parallel_light[0] = -*(float *)&node[5]; |
| 1503 | | parallel_light[1] = *(float *)&node[6]; |
| 1504 | | parallel_light[2] = *(float *)&node[4]; |
| 1505 | | parallel_light_intensity = *(float *)&node[7]; |
| 1506 | | ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; |
| 1496 | state->parallel_light[0] = -*(float *)&node[5]; |
| 1497 | state->parallel_light[1] = *(float *)&node[6]; |
| 1498 | state->parallel_light[2] = *(float *)&node[4]; |
| 1499 | state->parallel_light_intensity = *(float *)&node[7]; |
| 1500 | state->ambient_light_intensity = (UINT8)(node[36] >> 8) / 256.0f; |
| 1507 | 1501 | |
| 1508 | 1502 | /* set coordinate system matrix */ |
| 1509 | | load_matrix(0, &coordinate_system); |
| 1503 | load_matrix(state, 0, &state->coordinate_system); |
| 1510 | 1504 | |
| 1511 | 1505 | /* process a link */ |
| 1512 | 1506 | process_link(machine, link_address, node[2]); |
| r10427 | r10428 | |
| 1515 | 1509 | |
| 1516 | 1510 | static void real3d_traverse_display_list(running_machine *machine) |
| 1517 | 1511 | { |
| 1512 | model3_state *state = machine->driver_data<model3_state>(); |
| 1518 | 1513 | int pri; |
| 1519 | 1514 | |
| 1520 | | init_matrix_stack(); |
| 1515 | init_matrix_stack(machine); |
| 1521 | 1516 | |
| 1522 | 1517 | for (pri = 0; pri < 4; pri++) |
| 1523 | 1518 | draw_viewport(machine, pri, 0x800000); |
| 1524 | 1519 | |
| 1525 | | poly_wait(poly, "real3d_traverse_display_list"); |
| 1520 | poly_wait(state->poly, "real3d_traverse_display_list"); |
| 1526 | 1521 | } |
| 1527 | 1522 | |
src/mame/video/wecleman.c
| r10427 | r10428 | |
| 37 | 37 | int shadow_mode, flags; |
| 38 | 38 | }; |
| 39 | 39 | |
| 40 | | /* Variables that driver has acces to: */ |
| 41 | | UINT16 *wecleman_videostatus; |
| 42 | | UINT16 *wecleman_pageram, *wecleman_txtram, *wecleman_roadram; |
| 43 | | size_t wecleman_roadram_size; |
| 44 | | static int wecleman_bgpage[4], wecleman_fgpage[4]; |
| 45 | | static const int *wecleman_gfx_bank; |
| 46 | 40 | |
| 47 | | /* Variables only used here: */ |
| 48 | | static tilemap_t *bg_tilemap, *fg_tilemap, *txt_tilemap; |
| 49 | | |
| 50 | | static struct sprite *sprite_list; |
| 51 | | static struct sprite **spr_ptr_list; |
| 52 | | static int *spr_idx_list, *spr_pri_list, *t32x32pm; |
| 53 | | static int gameid, spr_offsx, spr_offsy, spr_count; |
| 54 | | static UINT16 *rgb_half; |
| 55 | | |
| 56 | | static int cloud_blend, cloud_ds, cloud_visible; |
| 57 | | static pen_t black_pen; |
| 58 | | |
| 59 | | |
| 60 | 41 | /*************************************************************************** |
| 61 | 42 | |
| 62 | 43 | Sprite Description and Routines |
| r10427 | r10428 | |
| 94 | 75 | |
| 95 | 76 | static void get_sprite_info(running_machine *machine) |
| 96 | 77 | { |
| 78 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 97 | 79 | const pen_t *base_pal = machine->pens; |
| 98 | 80 | UINT8 *base_gfx = machine->region("gfx1")->base(); |
| 99 | 81 | int gfx_max = machine->region("gfx1")->bytes(); |
| 100 | 82 | |
| 101 | 83 | UINT16 *source = machine->generic.spriteram.u16; |
| 102 | 84 | |
| 103 | | struct sprite *sprite = sprite_list; |
| 104 | | struct sprite *finish = sprite_list + NUM_SPRITES; |
| 85 | struct sprite *sprite = state->sprite_list; |
| 86 | struct sprite *finish = state->sprite_list + NUM_SPRITES; |
| 105 | 87 | |
| 106 | 88 | int bank, code, gfx, zoom; |
| 107 | 89 | |
| 108 | | for (spr_count=0; sprite<finish; source+=0x10/2, sprite++) |
| 90 | for (state->spr_count=0; sprite<finish; source+=0x10/2, sprite++) |
| 109 | 91 | { |
| 110 | 92 | if (source[0x00/2] == 0xffff) break; |
| 111 | 93 | |
| r10427 | r10428 | |
| 128 | 110 | sprite->pal_base = (source[0x0e/2] & 0xff) << 4; |
| 129 | 111 | sprite->pal_data = base_pal + sprite->pal_base; |
| 130 | 112 | |
| 131 | | gfx = (wecleman_gfx_bank[bank] << 15) + (code & 0x7fff); |
| 113 | gfx = (state->gfx_bank[bank] << 15) + (code & 0x7fff); |
| 132 | 114 | |
| 133 | 115 | sprite->flags = 0; |
| 134 | 116 | if (code & 0x8000) { sprite->flags |= SPRITE_FLIPX; gfx += 1-sprite->tile_width; } |
| r10427 | r10428 | |
| 144 | 126 | sprite->line_offset = sprite->tile_width; |
| 145 | 127 | sprite->total_width = sprite->tile_width - (sprite->tile_width * (zoom & 0xff)) / 0x80; |
| 146 | 128 | sprite->total_height += 1; |
| 147 | | sprite->x += spr_offsx; |
| 148 | | sprite->y += spr_offsy; |
| 129 | sprite->x += state->spr_offsx; |
| 130 | sprite->y += state->spr_offsy; |
| 149 | 131 | |
| 150 | | if (gameid == 0) |
| 132 | if (state->gameid == 0) |
| 151 | 133 | { |
| 152 | | spr_idx_list[spr_count] = spr_count; |
| 153 | | spr_pri_list[spr_count] = source[0x0e/2] >> 8; |
| 134 | state->spr_idx_list[state->spr_count] = state->spr_count; |
| 135 | state->spr_pri_list[state->spr_count] = source[0x0e/2] >> 8; |
| 154 | 136 | } |
| 155 | 137 | |
| 156 | | spr_ptr_list[spr_count] = sprite; |
| 157 | | spr_count++; |
| 138 | state->spr_ptr_list[state->spr_count] = sprite; |
| 139 | state->spr_count++; |
| 158 | 140 | } |
| 159 | 141 | } |
| 160 | 142 | |
| r10427 | r10428 | |
| 187 | 169 | } |
| 188 | 170 | |
| 189 | 171 | // draws a 8bpp palette sprites on a 16bpp direct RGB target (sub-par implementation) |
| 190 | | static void do_blit_zoom32(bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite) |
| 172 | static void do_blit_zoom32(wecleman_state *state, bitmap_t *bitmap, const rectangle *cliprect, struct sprite *sprite) |
| 191 | 173 | { |
| 192 | 174 | #define PRECISION_X 20 |
| 193 | 175 | #define PRECISION_Y 20 |
| r10427 | r10428 | |
| 335 | 317 | dst_ptr[sx] = base + pix; |
| 336 | 318 | else |
| 337 | 319 | { |
| 338 | | if (dst_ptr[sx] != black_pen) |
| 320 | if (dst_ptr[sx] != state->black_pen) |
| 339 | 321 | dst_ptr[sx] |= 0x800; |
| 340 | 322 | } |
| 341 | 323 | } |
| r10427 | r10428 | |
| 348 | 330 | } |
| 349 | 331 | } |
| 350 | 332 | |
| 351 | | static void sprite_draw(bitmap_t *bitmap, const rectangle *cliprect) |
| 333 | static void sprite_draw(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 352 | 334 | { |
| 335 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 353 | 336 | int i; |
| 354 | 337 | |
| 355 | | if (gameid == 0) // Wec Le Mans |
| 338 | if (state->gameid == 0) // Wec Le Mans |
| 356 | 339 | { |
| 357 | | sortsprite(spr_idx_list, spr_pri_list, spr_count); |
| 340 | sortsprite(state->spr_idx_list, state->spr_pri_list, state->spr_count); |
| 358 | 341 | |
| 359 | | for (i=0; i<spr_count; i++) do_blit_zoom32(bitmap, cliprect, spr_ptr_list[spr_idx_list[i]]); |
| 342 | for (i=0; i<state->spr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[state->spr_idx_list[i]]); |
| 360 | 343 | } |
| 361 | 344 | else // Hot Chase |
| 362 | 345 | { |
| 363 | | for (i=0; i<spr_count; i++) do_blit_zoom32(bitmap, cliprect, spr_ptr_list[i]); |
| 346 | for (i=0; i<state->spr_count; i++) do_blit_zoom32(state, bitmap, cliprect, state->spr_ptr_list[i]); |
| 364 | 347 | } |
| 365 | 348 | } |
| 366 | 349 | |
| r10427 | r10428 | |
| 436 | 419 | |
| 437 | 420 | static TILE_GET_INFO( wecleman_get_txt_tile_info ) |
| 438 | 421 | { |
| 439 | | int code = wecleman_txtram[tile_index]; |
| 422 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 423 | int code = state->txtram[tile_index]; |
| 440 | 424 | SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); |
| 441 | 425 | } |
| 442 | 426 | |
| 443 | 427 | WRITE16_HANDLER( wecleman_txtram_w ) |
| 444 | 428 | { |
| 445 | | UINT16 old_data = wecleman_txtram[offset]; |
| 446 | | UINT16 new_data = COMBINE_DATA(&wecleman_txtram[offset]); |
| 429 | wecleman_state *state = space->machine->driver_data<wecleman_state>(); |
| 430 | UINT16 old_data = state->txtram[offset]; |
| 431 | UINT16 new_data = COMBINE_DATA(&state->txtram[offset]); |
| 447 | 432 | |
| 448 | 433 | if ( old_data != new_data ) |
| 449 | 434 | { |
| r10427 | r10428 | |
| 452 | 437 | /* pages selector for the background */ |
| 453 | 438 | if (offset == 0xEFE/2) |
| 454 | 439 | { |
| 455 | | wecleman_bgpage[0] = (new_data >> 0x4) & 3; |
| 456 | | wecleman_bgpage[1] = (new_data >> 0x0) & 3; |
| 457 | | wecleman_bgpage[2] = (new_data >> 0xc) & 3; |
| 458 | | wecleman_bgpage[3] = (new_data >> 0x8) & 3; |
| 459 | | tilemap_mark_all_tiles_dirty(bg_tilemap); |
| 440 | state->bgpage[0] = (new_data >> 0x4) & 3; |
| 441 | state->bgpage[1] = (new_data >> 0x0) & 3; |
| 442 | state->bgpage[2] = (new_data >> 0xc) & 3; |
| 443 | state->bgpage[3] = (new_data >> 0x8) & 3; |
| 444 | tilemap_mark_all_tiles_dirty(state->bg_tilemap); |
| 460 | 445 | } |
| 461 | 446 | |
| 462 | 447 | /* pages selector for the foreground */ |
| 463 | 448 | if (offset == 0xEFC/2) |
| 464 | 449 | { |
| 465 | | wecleman_fgpage[0] = (new_data >> 0x4) & 3; |
| 466 | | wecleman_fgpage[1] = (new_data >> 0x0) & 3; |
| 467 | | wecleman_fgpage[2] = (new_data >> 0xc) & 3; |
| 468 | | wecleman_fgpage[3] = (new_data >> 0x8) & 3; |
| 469 | | tilemap_mark_all_tiles_dirty(fg_tilemap); |
| 450 | state->fgpage[0] = (new_data >> 0x4) & 3; |
| 451 | state->fgpage[1] = (new_data >> 0x0) & 3; |
| 452 | state->fgpage[2] = (new_data >> 0xc) & 3; |
| 453 | state->fgpage[3] = (new_data >> 0x8) & 3; |
| 454 | tilemap_mark_all_tiles_dirty(state->fg_tilemap); |
| 470 | 455 | } |
| 471 | 456 | |
| 472 | 457 | /* Parallactic horizontal scroll registers follow */ |
| 473 | 458 | } |
| 474 | 459 | else |
| 475 | | tilemap_mark_tile_dirty(txt_tilemap, offset); |
| 460 | tilemap_mark_tile_dirty(state->txt_tilemap, offset); |
| 476 | 461 | } |
| 477 | 462 | } |
| 478 | 463 | |
| r10427 | r10428 | |
| 482 | 467 | |
| 483 | 468 | static TILE_GET_INFO( wecleman_get_bg_tile_info ) |
| 484 | 469 | { |
| 485 | | int page = wecleman_bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; |
| 486 | | int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; |
| 470 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 471 | int page = state->bgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; |
| 472 | int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; |
| 487 | 473 | |
| 488 | 474 | SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); |
| 489 | 475 | } |
| r10427 | r10428 | |
| 494 | 480 | |
| 495 | 481 | static TILE_GET_INFO( wecleman_get_fg_tile_info ) |
| 496 | 482 | { |
| 497 | | int page = wecleman_fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; |
| 498 | | int code = wecleman_pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; |
| 483 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 484 | int page = state->fgpage[((tile_index&0x7f)>>6) + ((tile_index>>12)<<1)]; |
| 485 | int code = state->pageram[(tile_index&0x3f) + ((tile_index>>7&0x1f)<<6) + (page<<11)]; |
| 499 | 486 | |
| 500 | 487 | if (!code || code==0xffff) code = 0x20; |
| 501 | 488 | SET_TILE_INFO(PAGE_GFX, code&0xfff, (code>>5&0x78)+(code>>12), 0); |
| r10427 | r10428 | |
| 508 | 495 | /* Pages that compose both the background and the foreground */ |
| 509 | 496 | WRITE16_HANDLER( wecleman_pageram_w ) |
| 510 | 497 | { |
| 511 | | COMBINE_DATA(&wecleman_pageram[offset]); |
| 498 | wecleman_state *state = space->machine->driver_data<wecleman_state>(); |
| 499 | COMBINE_DATA(&state->pageram[offset]); |
| 512 | 500 | |
| 513 | 501 | { |
| 514 | 502 | int page,col,row; |
| r10427 | r10428 | |
| 518 | 506 | row = ( offset / PAGE_NX ) % PAGE_NY; |
| 519 | 507 | |
| 520 | 508 | /* background */ |
| 521 | | if (wecleman_bgpage[0] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 522 | | if (wecleman_bgpage[1] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 523 | | if (wecleman_bgpage[2] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 524 | | if (wecleman_bgpage[3] == page) tilemap_mark_tile_dirty(bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 509 | if (state->bgpage[0] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 510 | if (state->bgpage[1] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 511 | if (state->bgpage[2] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 512 | if (state->bgpage[3] == page) tilemap_mark_tile_dirty(state->bg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 525 | 513 | |
| 526 | 514 | /* foreground */ |
| 527 | | if (wecleman_fgpage[0] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 528 | | if (wecleman_fgpage[1] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 529 | | if (wecleman_fgpage[2] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 530 | | if (wecleman_fgpage[3] == page) tilemap_mark_tile_dirty(fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 515 | if (state->fgpage[0] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 516 | if (state->fgpage[1] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*0)*PAGE_NX*2 ); |
| 517 | if (state->fgpage[2] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*0) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 518 | if (state->fgpage[3] == page) tilemap_mark_tile_dirty(state->fg_tilemap, (col+PAGE_NX*1) + (row+PAGE_NY*1)*PAGE_NX*2 ); |
| 531 | 519 | } |
| 532 | 520 | } |
| 533 | 521 | |
| r10427 | r10428 | |
| 553 | 541 | |
| 554 | 542 | static void wecleman_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int priority) |
| 555 | 543 | { |
| 544 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 556 | 545 | // must be powers of 2 |
| 557 | 546 | #define XSIZE 512 |
| 558 | 547 | #define YSIZE 256 |
| r10427 | r10428 | |
| 593 | 582 | UINT32 pix; |
| 594 | 583 | UINT16 road; |
| 595 | 584 | |
| 596 | | road = wecleman_roadram[sy]; |
| 585 | road = state->roadram[sy]; |
| 597 | 586 | if ((road>>8) != 0x02) continue; |
| 598 | 587 | |
| 599 | | pix = rgb_ptr[(wecleman_roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0]; |
| 588 | pix = rgb_ptr[(state->roadram[sy+(YSIZE*2)] & 0xf) + 0x7f0]; |
| 600 | 589 | |
| 601 | 590 | for (sx = 0; sx < DST_WIDTH; sx++) |
| 602 | 591 | dst[sx] = pix; |
| r10427 | r10428 | |
| 619 | 608 | UINT32 pix; |
| 620 | 609 | UINT16 road; |
| 621 | 610 | |
| 622 | | road = wecleman_roadram[sy]; |
| 611 | road = state->roadram[sy]; |
| 623 | 612 | if ((road>>8) != 0x04) continue; |
| 624 | 613 | road &= YMASK; |
| 625 | 614 | |
| r10427 | r10428 | |
| 634 | 623 | mdy = ((road * MIDCURB_DY) >> 8) * bitmap->rowpixels; |
| 635 | 624 | tdy = ((road * TOPCURB_DY) >> 8) * bitmap->rowpixels; |
| 636 | 625 | |
| 637 | | scrollx = wecleman_roadram[sy+YSIZE] + (0x18 - 0xe00); |
| 626 | scrollx = state->roadram[sy+YSIZE] + (0x18 - 0xe00); |
| 638 | 627 | |
| 639 | | pal_ptr = road_rgb + ((wecleman_roadram[sy+(YSIZE*2)]<<3) & 8); |
| 628 | pal_ptr = road_rgb + ((state->roadram[sy+(YSIZE*2)]<<3) & 8); |
| 640 | 629 | |
| 641 | 630 | for (sx = 0; sx < DST_WIDTH; sx++, scrollx++) |
| 642 | 631 | { |
| r10427 | r10428 | |
| 677 | 666 | int tmw_l2, int tmh_l2, // tilemap width and height in log(2) |
| 678 | 667 | int alpha, int pal_offset ) // alpha(0-3f), # of color codes to shift |
| 679 | 668 | { |
| 669 | wecleman_state *state = gfx->machine->driver_data<wecleman_state>(); |
| 680 | 670 | const UINT8 *src_ptr; |
| 681 | 671 | UINT16 *tmap_ptr; |
| 682 | 672 | UINT32 *dst_base, *dst_ptr; |
| r10427 | r10428 | |
| 749 | 739 | dg = (dstrgb >> 11) & 0x1f; |
| 750 | 740 | db = (dstrgb >> 19) & 0x1f; |
| 751 | 741 | |
| 752 | | dr = (t32x32pm[dr - sr + alpha] >> 5) + dr; |
| 753 | | dg = (t32x32pm[dg - sg + alpha] >> 5) + dg; |
| 754 | | db = (t32x32pm[db - sb + alpha] >> 5) + db; |
| 742 | dr = (state->t32x32pm[dr - sr + alpha] >> 5) + dr; |
| 743 | dg = (state->t32x32pm[dg - sg + alpha] >> 5) + dg; |
| 744 | db = (state->t32x32pm[db - sb + alpha] >> 5) + db; |
| 755 | 745 | |
| 756 | 746 | dst_ptr[tx] = MAKE_RGB(pal5bit(db), pal5bit(dg), pal5bit(dr)); |
| 757 | 747 | } |
| r10427 | r10428 | |
| 804 | 794 | |
| 805 | 795 | static void hotchase_draw_road(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect) |
| 806 | 796 | { |
| 797 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 807 | 798 | /* Referred to what's in the ROMs */ |
| 808 | 799 | #define XSIZE 512 |
| 809 | 800 | #define YSIZE 512 |
| r10427 | r10428 | |
| 814 | 805 | /* Let's draw from the top to the bottom of the visible screen */ |
| 815 | 806 | for (sy = visarea.min_y;sy <= visarea.max_y;sy++) |
| 816 | 807 | { |
| 817 | | int code = wecleman_roadram[sy*4/2+2/2] + (wecleman_roadram[sy*4/2+0/2] << 16); |
| 808 | int code = state->roadram[sy*4/2+2/2] + (state->roadram[sy*4/2+0/2] << 16); |
| 818 | 809 | int color = ((code & 0x00f00000) >> 20) + 0x70; |
| 819 | 810 | int scrollx = ((code & 0x0007fc00) >> 10) * 2; |
| 820 | 811 | |
| r10427 | r10428 | |
| 845 | 836 | // new video and palette code |
| 846 | 837 | WRITE16_HANDLER( wecleman_videostatus_w ) |
| 847 | 838 | { |
| 848 | | COMBINE_DATA(wecleman_videostatus); |
| 839 | wecleman_state *state = space->machine->driver_data<wecleman_state>(); |
| 840 | COMBINE_DATA(state->videostatus); |
| 849 | 841 | |
| 850 | 842 | // bit0-6: background transition, 0=off, 1=on |
| 851 | 843 | // bit7: palette being changed, 0=no, 1=yes |
| 852 | 844 | if (ACCESSING_BITS_0_7) |
| 853 | 845 | { |
| 854 | | if ((data & 0x7f) == 0 && !cloud_ds) |
| 855 | | cloud_ds = BLEND_INC; |
| 846 | if ((data & 0x7f) == 0 && !state->cloud_ds) |
| 847 | state->cloud_ds = BLEND_INC; |
| 856 | 848 | else |
| 857 | | if ((data & 0x7f) == 1 && !cloud_visible) |
| 849 | if ((data & 0x7f) == 1 && !state->cloud_visible) |
| 858 | 850 | { |
| 859 | 851 | data ^= 1; |
| 860 | | cloud_ds = BLEND_DEC; |
| 861 | | cloud_visible = 1; |
| 852 | state->cloud_ds = BLEND_DEC; |
| 853 | state->cloud_visible = 1; |
| 862 | 854 | } |
| 863 | 855 | } |
| 864 | 856 | } |
| r10427 | r10428 | |
| 894 | 886 | |
| 895 | 887 | VIDEO_START( wecleman ) |
| 896 | 888 | { |
| 889 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 897 | 890 | /* |
| 898 | 891 | Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes) |
| 899 | 892 | This game has ROMs for 16 banks |
| r10427 | r10428 | |
| 912 | 905 | assert(machine->primary_screen->format() == BITMAP_FORMAT_RGB32); |
| 913 | 906 | buffer = auto_alloc_array(machine, UINT8, 0x12c00); // working buffer for sprite operations |
| 914 | 907 | |
| 915 | | gameid = 0; |
| 916 | | wecleman_gfx_bank = bank; |
| 917 | | spr_offsx = -0xbc + BMP_PAD; |
| 918 | | spr_offsy = 1 + BMP_PAD; |
| 919 | | cloud_blend = BLEND_MAX; |
| 920 | | cloud_ds = 0; |
| 921 | | cloud_visible = 0; |
| 922 | | black_pen = get_black_pen(machine); |
| 908 | state->gameid = 0; |
| 909 | state->gfx_bank = bank; |
| 910 | state->spr_offsx = -0xbc + BMP_PAD; |
| 911 | state->spr_offsy = 1 + BMP_PAD; |
| 912 | state->cloud_blend = BLEND_MAX; |
| 913 | state->cloud_ds = 0; |
| 914 | state->cloud_visible = 0; |
| 915 | state->black_pen = get_black_pen(machine); |
| 923 | 916 | |
| 924 | | rgb_half = (UINT16*)(buffer + 0x00000); |
| 925 | | t32x32pm = (int*)(buffer + 0x10020); |
| 926 | | spr_ptr_list = (struct sprite **)(buffer + 0x12000); |
| 927 | | spr_idx_list = (int *)(buffer + 0x12400); |
| 928 | | spr_pri_list = (int *)(buffer + 0x12800); |
| 917 | state->rgb_half = (UINT16*)(buffer + 0x00000); |
| 918 | state->t32x32pm = (int*)(buffer + 0x10020); |
| 919 | state->spr_ptr_list = (struct sprite **)(buffer + 0x12000); |
| 920 | state->spr_idx_list = (int *)(buffer + 0x12400); |
| 921 | state->spr_pri_list = (int *)(buffer + 0x12800); |
| 929 | 922 | |
| 930 | 923 | for (i=0; i<0x8000; i++) |
| 931 | 924 | { |
| 932 | 925 | j = i>>1; |
| 933 | | rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00); |
| 926 | state->rgb_half[i] = (j&0xf) | (j&0x1e0) | (j&0x3c00); |
| 934 | 927 | } |
| 935 | 928 | |
| 936 | 929 | for (j=0; j<0x20; j++) |
| 937 | 930 | { |
| 938 | 931 | for (i=-0x1f; i<0x20; i++) |
| 939 | 932 | { |
| 940 | | *(t32x32pm + (j<<6) + i) = i * j; |
| 933 | *(state->t32x32pm + (j<<6) + i) = i * j; |
| 941 | 934 | } |
| 942 | 935 | } |
| 943 | 936 | |
| 944 | | sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); |
| 937 | state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); |
| 945 | 938 | |
| 946 | | bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info, |
| 939 | state->bg_tilemap = tilemap_create(machine, wecleman_get_bg_tile_info, |
| 947 | 940 | tilemap_scan_rows, |
| 948 | 941 | /* We draw part of the road below */ |
| 949 | 942 | 8,8, |
| 950 | 943 | PAGE_NX * 2, PAGE_NY * 2 ); |
| 951 | 944 | |
| 952 | | fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info, |
| 945 | state->fg_tilemap = tilemap_create(machine, wecleman_get_fg_tile_info, |
| 953 | 946 | tilemap_scan_rows, |
| 954 | 947 | |
| 955 | 948 | 8,8, |
| 956 | 949 | PAGE_NX * 2, PAGE_NY * 2); |
| 957 | 950 | |
| 958 | | txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info, |
| 951 | state->txt_tilemap = tilemap_create(machine, wecleman_get_txt_tile_info, |
| 959 | 952 | tilemap_scan_rows, |
| 960 | 953 | |
| 961 | 954 | 8,8, |
| 962 | 955 | PAGE_NX * 1, PAGE_NY * 1); |
| 963 | 956 | |
| 964 | | tilemap_set_scroll_rows(bg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ |
| 965 | | tilemap_set_scroll_cols(bg_tilemap, 1); |
| 966 | | tilemap_set_transparent_pen(bg_tilemap,0); |
| 957 | tilemap_set_scroll_rows(state->bg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ |
| 958 | tilemap_set_scroll_cols(state->bg_tilemap, 1); |
| 959 | tilemap_set_transparent_pen(state->bg_tilemap,0); |
| 967 | 960 | |
| 968 | | tilemap_set_scroll_rows(fg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ |
| 969 | | tilemap_set_scroll_cols(fg_tilemap, 1); |
| 970 | | tilemap_set_transparent_pen(fg_tilemap,0); |
| 961 | tilemap_set_scroll_rows(state->fg_tilemap, TILEMAP_DIMY); /* Screen-wise scrolling */ |
| 962 | tilemap_set_scroll_cols(state->fg_tilemap, 1); |
| 963 | tilemap_set_transparent_pen(state->fg_tilemap,0); |
| 971 | 964 | |
| 972 | | tilemap_set_scroll_rows(txt_tilemap, 1); |
| 973 | | tilemap_set_scroll_cols(txt_tilemap, 1); |
| 974 | | tilemap_set_transparent_pen(txt_tilemap,0); |
| 965 | tilemap_set_scroll_rows(state->txt_tilemap, 1); |
| 966 | tilemap_set_scroll_cols(state->txt_tilemap, 1); |
| 967 | tilemap_set_transparent_pen(state->txt_tilemap,0); |
| 975 | 968 | |
| 976 | | tilemap_set_scrollx(txt_tilemap, 0, 512-320-16 -BMP_PAD); |
| 977 | | tilemap_set_scrolly(txt_tilemap, 0, -BMP_PAD ); |
| 969 | tilemap_set_scrollx(state->txt_tilemap, 0, 512-320-16 -BMP_PAD); |
| 970 | tilemap_set_scrolly(state->txt_tilemap, 0, -BMP_PAD ); |
| 978 | 971 | |
| 979 | 972 | // patches out a mysterious pixel floating in the sky (tile decoding bug?) |
| 980 | 973 | *(machine->gfx[0]->gfxdata + (machine->gfx[0]->char_modulo*0xaca+7)) = 0; |
| r10427 | r10428 | |
| 996 | 989 | |
| 997 | 990 | VIDEO_START( hotchase ) |
| 998 | 991 | { |
| 992 | wecleman_state *state = machine->driver_data<wecleman_state>(); |
| 999 | 993 | /* |
| 1000 | 994 | Sprite banking - each bank is 0x20000 bytes (we support 0x40 bank codes) |
| 1001 | 995 | This game has ROMs for 0x30 banks |
| r10427 | r10428 | |
| 1012 | 1006 | |
| 1013 | 1007 | buffer = auto_alloc_array(machine, UINT8, 0x400); // reserve 1k for sprite list |
| 1014 | 1008 | |
| 1015 | | gameid = 1; |
| 1016 | | wecleman_gfx_bank = bank; |
| 1017 | | spr_offsx = -0xc0; |
| 1018 | | spr_offsy = 0; |
| 1019 | | black_pen = get_black_pen(machine); |
| 1009 | state->gameid = 1; |
| 1010 | state->gfx_bank = bank; |
| 1011 | state->spr_offsx = -0xc0; |
| 1012 | state->spr_offsy = 0; |
| 1013 | state->black_pen = get_black_pen(machine); |
| 1020 | 1014 | |
| 1021 | | spr_ptr_list = (struct sprite **)buffer; |
| 1015 | state->spr_ptr_list = (struct sprite **)buffer; |
| 1022 | 1016 | |
| 1023 | | sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); |
| 1017 | state->sprite_list = auto_alloc_array_clear(machine, struct sprite, NUM_SPRITES); |
| 1024 | 1018 | } |
| 1025 | 1019 | |
| 1026 | 1020 | |
| r10427 | r10428 | |
| 1030 | 1024 | |
| 1031 | 1025 | VIDEO_UPDATE ( wecleman ) |
| 1032 | 1026 | { |
| 1027 | wecleman_state *state = screen->machine->driver_data<wecleman_state>(); |
| 1033 | 1028 | const pen_t *mrct; |
| 1034 | 1029 | int video_on; |
| 1035 | 1030 | int fg_x, bg_x, fg_y, bg_y; |
| r10427 | r10428 | |
| 1038 | 1033 | |
| 1039 | 1034 | mrct = screen->machine->pens; |
| 1040 | 1035 | |
| 1041 | | video_on = wecleman_irqctrl & 0x40; |
| 1036 | video_on = state->irqctrl & 0x40; |
| 1042 | 1037 | |
| 1043 | | set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04); // Start lamp |
| 1038 | set_led_status(screen->machine, 0, state->selected_ip & 0x04); // Start lamp |
| 1044 | 1039 | |
| 1045 | | fg_y = (wecleman_txtram[0x0f24>>1] & (TILEMAP_DIMY - 1)); |
| 1046 | | bg_y = (wecleman_txtram[0x0f26>>1] & (TILEMAP_DIMY - 1)); |
| 1040 | fg_y = (state->txtram[0x0f24>>1] & (TILEMAP_DIMY - 1)); |
| 1041 | bg_y = (state->txtram[0x0f26>>1] & (TILEMAP_DIMY - 1)); |
| 1047 | 1042 | |
| 1048 | | cloud_sx = wecleman_txtram[0xfee>>1] + 0xb0; |
| 1043 | cloud_sx = state->txtram[0xfee>>1] + 0xb0; |
| 1049 | 1044 | cloud_sy = bg_y; |
| 1050 | 1045 | |
| 1051 | | tilemap_set_scrolly(bg_tilemap, 0, bg_y -BMP_PAD); |
| 1052 | | tilemap_set_scrolly(fg_tilemap, 0, fg_y -BMP_PAD); |
| 1046 | tilemap_set_scrolly(state->bg_tilemap, 0, bg_y -BMP_PAD); |
| 1047 | tilemap_set_scrolly(state->fg_tilemap, 0, fg_y -BMP_PAD); |
| 1053 | 1048 | |
| 1054 | 1049 | for (i=0; i<(28<<2); i+=4) |
| 1055 | 1050 | { |
| 1056 | | fg_x = wecleman_txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD); |
| 1057 | | bg_x = wecleman_txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD); |
| 1051 | fg_x = state->txtram[(i+0xf80)>>1] + (0xb0 -BMP_PAD); |
| 1052 | bg_x = state->txtram[(i+0xf82)>>1] + (0xb0 -BMP_PAD); |
| 1058 | 1053 | |
| 1059 | 1054 | k = i<<1; |
| 1060 | 1055 | for (j=0; j<8; j++) |
| 1061 | 1056 | { |
| 1062 | | tilemap_set_scrollx(fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x); |
| 1063 | | tilemap_set_scrollx(bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x); |
| 1057 | tilemap_set_scrollx(state->fg_tilemap, (fg_y + k + j) & (TILEMAP_DIMY - 1), fg_x); |
| 1058 | tilemap_set_scrollx(state->bg_tilemap, (bg_y + k + j) & (TILEMAP_DIMY - 1), bg_x); |
| 1064 | 1059 | } |
| 1065 | 1060 | } |
| 1066 | 1061 | |
| r10427 | r10428 | |
| 1070 | 1065 | |
| 1071 | 1066 | get_sprite_info(screen->machine); |
| 1072 | 1067 | |
| 1073 | | bitmap_fill(bitmap, cliprect, black_pen); |
| 1068 | bitmap_fill(bitmap, cliprect, state->black_pen); |
| 1074 | 1069 | |
| 1075 | 1070 | /* Draw the road (lines which have priority 0x02) */ |
| 1076 | 1071 | if (video_on) wecleman_draw_road(screen->machine, bitmap, cliprect, 0x02); |
| 1077 | 1072 | |
| 1078 | 1073 | /* Draw the background */ |
| 1079 | | if (video_on) tilemap_draw(bitmap,cliprect, bg_tilemap, 0, 0); |
| 1074 | if (video_on) tilemap_draw(bitmap,cliprect, state->bg_tilemap, 0, 0); |
| 1080 | 1075 | |
| 1081 | 1076 | // draws the cloud layer; needs work |
| 1082 | | if (cloud_visible) |
| 1077 | if (state->cloud_visible) |
| 1083 | 1078 | { |
| 1084 | 1079 | /* palette hacks! */ |
| 1085 | 1080 | ((pen_t *)mrct)[0] = ((pen_t *)mrct)[0x40] = ((pen_t *)mrct)[0x200] = ((pen_t *)mrct)[0x205]; |
| r10427 | r10428 | |
| 1088 | 1083 | draw_cloud( |
| 1089 | 1084 | bitmap, |
| 1090 | 1085 | screen->machine->gfx[0], |
| 1091 | | wecleman_pageram+0x1800, |
| 1086 | state->pageram+0x1800, |
| 1092 | 1087 | BMP_PAD, BMP_PAD, |
| 1093 | 1088 | 41, 20, |
| 1094 | 1089 | cloud_sx, cloud_sy, |
| 1095 | 1090 | 6, 5, |
| 1096 | | cloud_blend/BLEND_STEPS, 0); |
| 1091 | state->cloud_blend/BLEND_STEPS, 0); |
| 1097 | 1092 | |
| 1098 | | cloud_blend += cloud_ds; |
| 1093 | state->cloud_blend += state->cloud_ds; |
| 1099 | 1094 | |
| 1100 | | if (cloud_blend < BLEND_MIN) |
| 1101 | | { cloud_blend = BLEND_MIN; cloud_ds = 0; *wecleman_videostatus |= 1; } |
| 1102 | | else if (cloud_blend > BLEND_MAX) |
| 1103 | | { cloud_blend = BLEND_MAX; cloud_ds = 0; cloud_visible = 0; } |
| 1095 | if (state->cloud_blend < BLEND_MIN) |
| 1096 | { state->cloud_blend = BLEND_MIN; state->cloud_ds = 0; *state->videostatus |= 1; } |
| 1097 | else if (state->cloud_blend > BLEND_MAX) |
| 1098 | { state->cloud_blend = BLEND_MAX; state->cloud_ds = 0; state->cloud_visible = 0; } |
| 1104 | 1099 | } |
| 1105 | 1100 | |
| 1106 | 1101 | /* Draw the foreground */ |
| 1107 | | if (video_on) tilemap_draw(bitmap,cliprect, fg_tilemap, 0, 0); |
| 1102 | if (video_on) tilemap_draw(bitmap,cliprect, state->fg_tilemap, 0, 0); |
| 1108 | 1103 | |
| 1109 | 1104 | /* Draw the road (lines which have priority 0x04) */ |
| 1110 | 1105 | if (video_on) wecleman_draw_road(screen->machine, bitmap,cliprect, 0x04); |
| 1111 | 1106 | |
| 1112 | 1107 | /* Draw the sprites */ |
| 1113 | | if (video_on) sprite_draw(bitmap,cliprect); |
| 1108 | if (video_on) sprite_draw(screen->machine, bitmap,cliprect); |
| 1114 | 1109 | |
| 1115 | 1110 | /* Draw the text layer */ |
| 1116 | | if (video_on) tilemap_draw(bitmap,cliprect, txt_tilemap, 0, 0); |
| 1111 | if (video_on) tilemap_draw(bitmap,cliprect, state->txt_tilemap, 0, 0); |
| 1117 | 1112 | return 0; |
| 1118 | 1113 | } |
| 1119 | 1114 | |
| r10427 | r10428 | |
| 1123 | 1118 | |
| 1124 | 1119 | VIDEO_UPDATE( hotchase ) |
| 1125 | 1120 | { |
| 1121 | wecleman_state *state = screen->machine->driver_data<wecleman_state>(); |
| 1126 | 1122 | device_t *k051316_1 = screen->machine->device("k051316_1"); |
| 1127 | 1123 | device_t *k051316_2 = screen->machine->device("k051316_2"); |
| 1128 | 1124 | int video_on; |
| 1129 | 1125 | |
| 1130 | | video_on = wecleman_irqctrl & 0x40; |
| 1126 | video_on = state->irqctrl & 0x40; |
| 1131 | 1127 | |
| 1132 | | set_led_status(screen->machine, 0, wecleman_selected_ip & 0x04); // Start lamp |
| 1128 | set_led_status(screen->machine, 0, state->selected_ip & 0x04); // Start lamp |
| 1133 | 1129 | |
| 1134 | 1130 | get_sprite_info(screen->machine); |
| 1135 | 1131 | |
| 1136 | | bitmap_fill(bitmap, cliprect, black_pen); |
| 1132 | bitmap_fill(bitmap, cliprect, state->black_pen); |
| 1137 | 1133 | |
| 1138 | 1134 | /* Draw the background */ |
| 1139 | 1135 | if (video_on) |
| r10427 | r10428 | |
| 1145 | 1141 | |
| 1146 | 1142 | /* Draw the sprites */ |
| 1147 | 1143 | if (video_on) |
| 1148 | | sprite_draw(bitmap,cliprect); |
| 1144 | sprite_draw(screen->machine, bitmap,cliprect); |
| 1149 | 1145 | |
| 1150 | 1146 | /* Draw the foreground (text) */ |
| 1151 | 1147 | if (video_on) |
src/mame/video/dec0.c
| r10427 | r10428 | |
| 97 | 97 | #include "emu.h" |
| 98 | 98 | #include "includes/dec0.h" |
| 99 | 99 | |
| 100 | | static tilemap_t *pf1_tilemap_0,*pf1_tilemap_1,*pf1_tilemap_2; |
| 101 | | static tilemap_t *pf2_tilemap_0,*pf2_tilemap_1,*pf2_tilemap_2; |
| 102 | | static tilemap_t *pf3_tilemap_0,*pf3_tilemap_1,*pf3_tilemap_2; |
| 103 | 100 | |
| 104 | | UINT16 *dec0_pf1_data,*dec0_pf2_data,*dec0_pf3_data; |
| 105 | | UINT16 *dec0_pf1_rowscroll,*dec0_pf2_rowscroll,*dec0_pf3_rowscroll; |
| 106 | | UINT16 *dec0_pf1_colscroll,*dec0_pf2_colscroll,*dec0_pf3_colscroll; |
| 107 | | static UINT16 dec0_pf1_control_0[4]; |
| 108 | | static UINT16 dec0_pf1_control_1[4]; |
| 109 | | static UINT16 dec0_pf2_control_0[4]; |
| 110 | | static UINT16 dec0_pf2_control_1[4]; |
| 111 | | static UINT16 dec0_pf3_control_0[4]; |
| 112 | | static UINT16 dec0_pf3_control_1[4]; |
| 113 | | static UINT16 *dec0_spriteram; |
| 114 | | static UINT16 dec0_pri; |
| 115 | 101 | |
| 116 | 102 | /******************************************************************************/ |
| 117 | 103 | |
| 118 | 104 | WRITE16_HANDLER( dec0_update_sprites_w ) |
| 119 | 105 | { |
| 120 | | memcpy(dec0_spriteram,space->machine->generic.spriteram.u16,0x800); |
| 106 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 107 | memcpy(state->spriteram,space->machine->generic.spriteram.u16,0x800); |
| 121 | 108 | } |
| 122 | 109 | |
| 123 | 110 | /******************************************************************************/ |
| r10427 | r10428 | |
| 149 | 136 | |
| 150 | 137 | static void draw_sprites(running_machine* machine, bitmap_t *bitmap,const rectangle *cliprect,int pri_mask,int pri_val) |
| 151 | 138 | { |
| 139 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 152 | 140 | int offs; |
| 153 | 141 | |
| 154 | 142 | for (offs = 0;offs < 0x400;offs += 4) |
| 155 | 143 | { |
| 156 | 144 | int x,y,sprite,colour,multi,fx,fy,inc,flash,mult; |
| 157 | 145 | |
| 158 | | y = dec0_spriteram[offs]; |
| 146 | y = state->spriteram[offs]; |
| 159 | 147 | if ((y&0x8000) == 0) continue; |
| 160 | 148 | |
| 161 | | x = dec0_spriteram[offs+2]; |
| 149 | x = state->spriteram[offs+2]; |
| 162 | 150 | colour = x >> 12; |
| 163 | 151 | if ((colour & pri_mask) != pri_val) continue; |
| 164 | 152 | |
| r10427 | r10428 | |
| 170 | 158 | multi = (1 << ((y & 0x1800) >> 11)) - 1; /* 1x, 2x, 4x, 8x height */ |
| 171 | 159 | /* multi = 0 1 3 7 */ |
| 172 | 160 | |
| 173 | | sprite = dec0_spriteram[offs+1] & 0x0fff; |
| 161 | sprite = state->spriteram[offs+1] & 0x0fff; |
| 174 | 162 | |
| 175 | 163 | x = x & 0x01ff; |
| 176 | 164 | y = y & 0x01ff; |
| r10427 | r10428 | |
| 299 | 287 | |
| 300 | 288 | static void dec0_pf1_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags) |
| 301 | 289 | { |
| 302 | | switch (dec0_pf1_control_0[3]&0x3) { |
| 290 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 291 | switch (state->pf1_control_0[3]&0x3) { |
| 303 | 292 | case 0: /* 4x1 */ |
| 304 | | custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_0,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags); |
| 293 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_0,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags); |
| 305 | 294 | break; |
| 306 | 295 | case 1: /* 2x2 */ |
| 307 | 296 | default: |
| 308 | | custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_1,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags); |
| 297 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_1,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags); |
| 309 | 298 | break; |
| 310 | 299 | case 2: /* 1x4 */ |
| 311 | | custom_tilemap_draw(machine,bitmap,cliprect,pf1_tilemap_2,dec0_pf1_rowscroll,dec0_pf1_colscroll,dec0_pf1_control_0,dec0_pf1_control_1,flags); |
| 300 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf1_tilemap_2,state->pf1_rowscroll,state->pf1_colscroll,state->pf1_control_0,state->pf1_control_1,flags); |
| 312 | 301 | break; |
| 313 | 302 | }; |
| 314 | 303 | } |
| 315 | 304 | |
| 316 | 305 | static void dec0_pf2_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags) |
| 317 | 306 | { |
| 318 | | switch (dec0_pf2_control_0[3]&0x3) { |
| 307 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 308 | switch (state->pf2_control_0[3]&0x3) { |
| 319 | 309 | case 0: /* 4x1 */ |
| 320 | | custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_0,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags); |
| 310 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_0,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags); |
| 321 | 311 | break; |
| 322 | 312 | case 1: /* 2x2 */ |
| 323 | 313 | default: |
| 324 | | custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_1,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags); |
| 314 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_1,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags); |
| 325 | 315 | break; |
| 326 | 316 | case 2: /* 1x4 */ |
| 327 | | custom_tilemap_draw(machine,bitmap,cliprect,pf2_tilemap_2,dec0_pf2_rowscroll,dec0_pf2_colscroll,dec0_pf2_control_0,dec0_pf2_control_1,flags); |
| 317 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf2_tilemap_2,state->pf2_rowscroll,state->pf2_colscroll,state->pf2_control_0,state->pf2_control_1,flags); |
| 328 | 318 | break; |
| 329 | 319 | }; |
| 330 | 320 | } |
| 331 | 321 | |
| 332 | 322 | static void dec0_pf3_draw(running_machine *machine,bitmap_t *bitmap,const rectangle *cliprect,int flags) |
| 333 | 323 | { |
| 334 | | switch (dec0_pf3_control_0[3]&0x3) { |
| 324 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 325 | switch (state->pf3_control_0[3]&0x3) { |
| 335 | 326 | case 0: /* 4x1 */ |
| 336 | | custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_0,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags); |
| 327 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_0,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags); |
| 337 | 328 | break; |
| 338 | 329 | case 1: /* 2x2 */ |
| 339 | 330 | default: |
| 340 | | custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_1,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags); |
| 331 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_1,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags); |
| 341 | 332 | break; |
| 342 | 333 | case 2: /* 1x4 */ |
| 343 | | custom_tilemap_draw(machine,bitmap,cliprect,pf3_tilemap_2,dec0_pf3_rowscroll,dec0_pf3_colscroll,dec0_pf3_control_0,dec0_pf3_control_1,flags); |
| 334 | custom_tilemap_draw(machine,bitmap,cliprect,state->pf3_tilemap_2,state->pf3_rowscroll,state->pf3_colscroll,state->pf3_control_0,state->pf3_control_1,flags); |
| 344 | 335 | break; |
| 345 | 336 | }; |
| 346 | 337 | } |
| r10427 | r10428 | |
| 349 | 340 | |
| 350 | 341 | VIDEO_UPDATE( hbarrel ) |
| 351 | 342 | { |
| 352 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 343 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 344 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 353 | 345 | |
| 354 | 346 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 355 | 347 | draw_sprites(screen->machine,bitmap,cliprect,0x08,0x08); |
| r10427 | r10428 | |
| 366 | 358 | |
| 367 | 359 | VIDEO_UPDATE( baddudes ) |
| 368 | 360 | { |
| 369 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 361 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 362 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 370 | 363 | |
| 371 | 364 | /* WARNING: inverted wrt Midnight Resistance */ |
| 372 | | if ((dec0_pri & 0x01) == 0) |
| 365 | if ((state->pri & 0x01) == 0) |
| 373 | 366 | { |
| 374 | 367 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 375 | 368 | dec0_pf3_draw(screen->machine,bitmap,cliprect,0); |
| 376 | 369 | |
| 377 | | if (dec0_pri & 2) |
| 370 | if (state->pri & 2) |
| 378 | 371 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */ |
| 379 | 372 | |
| 380 | 373 | draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); |
| 381 | 374 | |
| 382 | | if (dec0_pri & 4) |
| 375 | if (state->pri & 4) |
| 383 | 376 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */ |
| 384 | 377 | } |
| 385 | 378 | else |
| r10427 | r10428 | |
| 387 | 380 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 388 | 381 | dec0_pf2_draw(screen->machine,bitmap,cliprect,0); |
| 389 | 382 | |
| 390 | | if (dec0_pri & 2) |
| 383 | if (state->pri & 2) |
| 391 | 384 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */ |
| 392 | 385 | |
| 393 | 386 | draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); |
| 394 | 387 | |
| 395 | | if (dec0_pri & 4) |
| 388 | if (state->pri & 4) |
| 396 | 389 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); /* Foreground pens only */ |
| 397 | 390 | } |
| 398 | 391 | |
| r10427 | r10428 | |
| 404 | 397 | |
| 405 | 398 | VIDEO_UPDATE( robocop ) |
| 406 | 399 | { |
| 400 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 407 | 401 | int trans; |
| 408 | 402 | |
| 409 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 403 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 410 | 404 | |
| 411 | | if (dec0_pri & 0x04) |
| 405 | if (state->pri & 0x04) |
| 412 | 406 | trans = 0x08; |
| 413 | 407 | else |
| 414 | 408 | trans = 0x00; |
| 415 | 409 | |
| 416 | | if (dec0_pri & 0x01) |
| 410 | if (state->pri & 0x01) |
| 417 | 411 | { |
| 418 | 412 | /* WARNING: inverted wrt Midnight Resistance */ |
| 419 | 413 | /* Robocop uses it only for the title screen, so this might be just */ |
| r10427 | r10428 | |
| 421 | 415 | /* something (they are 0x80 in midres, 0x00 here) */ |
| 422 | 416 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER1|TILEMAP_DRAW_OPAQUE); |
| 423 | 417 | |
| 424 | | if (dec0_pri & 0x02) |
| 418 | if (state->pri & 0x02) |
| 425 | 419 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans); |
| 426 | 420 | |
| 427 | 421 | dec0_pf3_draw(screen->machine,bitmap,cliprect,0); |
| r10427 | r10428 | |
| 430 | 424 | { |
| 431 | 425 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 432 | 426 | |
| 433 | | if (dec0_pri & 0x02) |
| 427 | if (state->pri & 0x02) |
| 434 | 428 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans); |
| 435 | 429 | |
| 436 | 430 | dec0_pf2_draw(screen->machine,bitmap,cliprect,0); |
| 437 | 431 | } |
| 438 | 432 | |
| 439 | | if (dec0_pri & 0x02) |
| 433 | if (state->pri & 0x02) |
| 440 | 434 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans ^ 0x08); |
| 441 | 435 | else |
| 442 | 436 | draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); |
| r10427 | r10428 | |
| 449 | 443 | |
| 450 | 444 | VIDEO_UPDATE( birdtry ) |
| 451 | 445 | { |
| 452 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 446 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 447 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 453 | 448 | |
| 454 | 449 | /* This game doesn't have the extra playfield chip on the game board, but |
| 455 | 450 | the palette does show through. */ |
| r10427 | r10428 | |
| 464 | 459 | |
| 465 | 460 | VIDEO_UPDATE( hippodrm ) |
| 466 | 461 | { |
| 467 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 462 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 463 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 468 | 464 | |
| 469 | | if (dec0_pri & 0x01) |
| 465 | if (state->pri & 0x01) |
| 470 | 466 | { |
| 471 | 467 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 472 | 468 | dec0_pf3_draw(screen->machine,bitmap,cliprect,0); |
| r10427 | r10428 | |
| 486 | 482 | |
| 487 | 483 | VIDEO_UPDATE( slyspy ) |
| 488 | 484 | { |
| 489 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 485 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 486 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 490 | 487 | |
| 491 | 488 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 492 | 489 | dec0_pf2_draw(screen->machine,bitmap,cliprect,0); |
| r10427 | r10428 | |
| 494 | 491 | draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); |
| 495 | 492 | |
| 496 | 493 | /* Redraw top 8 pens of top 8 palettes over sprites */ |
| 497 | | if (dec0_pri&0x80) |
| 494 | if (state->pri&0x80) |
| 498 | 495 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_LAYER0); |
| 499 | 496 | |
| 500 | 497 | dec0_pf1_draw(screen->machine,bitmap,cliprect,0); |
| r10427 | r10428 | |
| 505 | 502 | |
| 506 | 503 | VIDEO_UPDATE( midres ) |
| 507 | 504 | { |
| 505 | dec0_state *state = screen->machine->driver_data<dec0_state>(); |
| 508 | 506 | int trans; |
| 509 | 507 | |
| 510 | | flip_screen_set(screen->machine, dec0_pf1_control_0[0]&0x80); |
| 508 | flip_screen_set(screen->machine, state->pf1_control_0[0]&0x80); |
| 511 | 509 | |
| 512 | | if (dec0_pri & 0x04) |
| 510 | if (state->pri & 0x04) |
| 513 | 511 | trans = 0x00; |
| 514 | 512 | else trans = 0x08; |
| 515 | 513 | |
| 516 | | if (dec0_pri & 0x01) |
| 514 | if (state->pri & 0x01) |
| 517 | 515 | { |
| 518 | 516 | dec0_pf2_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 519 | 517 | |
| 520 | | if (dec0_pri & 0x02) |
| 518 | if (state->pri & 0x02) |
| 521 | 519 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans); |
| 522 | 520 | |
| 523 | 521 | dec0_pf3_draw(screen->machine,bitmap,cliprect,0); |
| r10427 | r10428 | |
| 526 | 524 | { |
| 527 | 525 | dec0_pf3_draw(screen->machine,bitmap,cliprect,TILEMAP_DRAW_OPAQUE); |
| 528 | 526 | |
| 529 | | if (dec0_pri & 0x02) |
| 527 | if (state->pri & 0x02) |
| 530 | 528 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans); |
| 531 | 529 | |
| 532 | 530 | dec0_pf2_draw(screen->machine,bitmap,cliprect,0); |
| 533 | 531 | } |
| 534 | 532 | |
| 535 | | if (dec0_pri & 0x02) |
| 533 | if (state->pri & 0x02) |
| 536 | 534 | draw_sprites(screen->machine,bitmap,cliprect,0x08,trans ^ 0x08); |
| 537 | 535 | else |
| 538 | 536 | draw_sprites(screen->machine,bitmap,cliprect,0x00,0x00); |
| r10427 | r10428 | |
| 545 | 543 | |
| 546 | 544 | WRITE16_HANDLER( dec0_pf1_control_0_w ) |
| 547 | 545 | { |
| 548 | | COMBINE_DATA(&dec0_pf1_control_0[offset]); |
| 546 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 547 | COMBINE_DATA(&state->pf1_control_0[offset]); |
| 549 | 548 | } |
| 550 | 549 | |
| 551 | 550 | WRITE16_HANDLER( dec0_pf1_control_1_w ) |
| 552 | 551 | { |
| 553 | | COMBINE_DATA(&dec0_pf1_control_1[offset]); |
| 552 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 553 | COMBINE_DATA(&state->pf1_control_1[offset]); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | WRITE16_HANDLER( dec0_pf1_data_w ) |
| 557 | 557 | { |
| 558 | | COMBINE_DATA(&dec0_pf1_data[offset]); |
| 559 | | tilemap_mark_tile_dirty(pf1_tilemap_0,offset); |
| 560 | | tilemap_mark_tile_dirty(pf1_tilemap_1,offset); |
| 561 | | tilemap_mark_tile_dirty(pf1_tilemap_2,offset); |
| 558 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 559 | COMBINE_DATA(&state->pf1_data[offset]); |
| 560 | tilemap_mark_tile_dirty(state->pf1_tilemap_0,offset); |
| 561 | tilemap_mark_tile_dirty(state->pf1_tilemap_1,offset); |
| 562 | tilemap_mark_tile_dirty(state->pf1_tilemap_2,offset); |
| 562 | 563 | } |
| 563 | 564 | |
| 564 | 565 | WRITE16_HANDLER( dec0_pf2_control_0_w ) |
| 565 | 566 | { |
| 566 | | COMBINE_DATA(&dec0_pf2_control_0[offset]); |
| 567 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 568 | COMBINE_DATA(&state->pf2_control_0[offset]); |
| 567 | 569 | } |
| 568 | 570 | |
| 569 | 571 | WRITE16_HANDLER( dec0_pf2_control_1_w ) |
| 570 | 572 | { |
| 571 | | COMBINE_DATA(&dec0_pf2_control_1[offset]); |
| 573 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 574 | COMBINE_DATA(&state->pf2_control_1[offset]); |
| 572 | 575 | } |
| 573 | 576 | |
| 574 | 577 | WRITE16_HANDLER( dec0_pf2_data_w ) |
| 575 | 578 | { |
| 576 | | COMBINE_DATA(&dec0_pf2_data[offset]); |
| 577 | | tilemap_mark_tile_dirty(pf2_tilemap_0,offset); |
| 578 | | tilemap_mark_tile_dirty(pf2_tilemap_1,offset); |
| 579 | | tilemap_mark_tile_dirty(pf2_tilemap_2,offset); |
| 579 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 580 | COMBINE_DATA(&state->pf2_data[offset]); |
| 581 | tilemap_mark_tile_dirty(state->pf2_tilemap_0,offset); |
| 582 | tilemap_mark_tile_dirty(state->pf2_tilemap_1,offset); |
| 583 | tilemap_mark_tile_dirty(state->pf2_tilemap_2,offset); |
| 580 | 584 | } |
| 581 | 585 | |
| 582 | 586 | WRITE16_HANDLER( dec0_pf3_control_0_w ) |
| 583 | 587 | { |
| 584 | | COMBINE_DATA(&dec0_pf3_control_0[offset]); |
| 588 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 589 | COMBINE_DATA(&state->pf3_control_0[offset]); |
| 585 | 590 | } |
| 586 | 591 | |
| 587 | 592 | WRITE16_HANDLER( dec0_pf3_control_1_w ) |
| 588 | 593 | { |
| 589 | | COMBINE_DATA(&dec0_pf3_control_1[offset]); |
| 594 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 595 | COMBINE_DATA(&state->pf3_control_1[offset]); |
| 590 | 596 | } |
| 591 | 597 | |
| 592 | 598 | WRITE16_HANDLER( dec0_pf3_data_w ) |
| 593 | 599 | { |
| 594 | | COMBINE_DATA(&dec0_pf3_data[offset]); |
| 595 | | tilemap_mark_tile_dirty(pf3_tilemap_0,offset); |
| 596 | | tilemap_mark_tile_dirty(pf3_tilemap_1,offset); |
| 597 | | tilemap_mark_tile_dirty(pf3_tilemap_2,offset); |
| 600 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 601 | COMBINE_DATA(&state->pf3_data[offset]); |
| 602 | tilemap_mark_tile_dirty(state->pf3_tilemap_0,offset); |
| 603 | tilemap_mark_tile_dirty(state->pf3_tilemap_1,offset); |
| 604 | tilemap_mark_tile_dirty(state->pf3_tilemap_2,offset); |
| 598 | 605 | } |
| 599 | 606 | |
| 600 | 607 | WRITE16_HANDLER( dec0_priority_w ) |
| 601 | 608 | { |
| 602 | | COMBINE_DATA(&dec0_pri); |
| 609 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 610 | COMBINE_DATA(&state->pri); |
| 603 | 611 | } |
| 604 | 612 | |
| 605 | 613 | WRITE8_HANDLER( dec0_pf3_control_8bit_w ) |
| 606 | 614 | { |
| 607 | | static int buffer[0x20]; |
| 615 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 608 | 616 | UINT16 myword; |
| 609 | 617 | |
| 610 | | buffer[offset]=data; |
| 618 | state->buffer[offset]=data; |
| 611 | 619 | |
| 612 | 620 | /* Rearrange little endian bytes from H6280 into big endian words for 68k */ |
| 613 | 621 | offset&=0xffe; |
| 614 | | myword=buffer[offset] + (buffer[offset+1]<<8); |
| 622 | myword=state->buffer[offset] + (state->buffer[offset+1]<<8); |
| 615 | 623 | |
| 616 | 624 | if (offset<0x10) dec0_pf3_control_0_w(space,offset/2,myword,0xffff); |
| 617 | 625 | else dec0_pf3_control_1_w(space,(offset-0x10)/2,myword,0xffff); |
| r10427 | r10428 | |
| 619 | 627 | |
| 620 | 628 | WRITE8_HANDLER( dec0_pf3_data_8bit_w ) |
| 621 | 629 | { |
| 630 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 622 | 631 | if (offset&1) { /* MSB has changed */ |
| 623 | | UINT16 lsb=dec0_pf3_data[offset>>1]; |
| 632 | UINT16 lsb=state->pf3_data[offset>>1]; |
| 624 | 633 | UINT16 newword=(lsb&0xff) | (data<<8); |
| 625 | | dec0_pf3_data[offset>>1]=newword; |
| 634 | state->pf3_data[offset>>1]=newword; |
| 626 | 635 | } |
| 627 | 636 | else { /* LSB has changed */ |
| 628 | | UINT16 msb=dec0_pf3_data[offset>>1]; |
| 637 | UINT16 msb=state->pf3_data[offset>>1]; |
| 629 | 638 | UINT16 newword=(msb&0xff00) | data; |
| 630 | | dec0_pf3_data[offset>>1]=newword; |
| 639 | state->pf3_data[offset>>1]=newword; |
| 631 | 640 | } |
| 632 | | tilemap_mark_tile_dirty(pf3_tilemap_0,offset>>1); |
| 633 | | tilemap_mark_tile_dirty(pf3_tilemap_1,offset>>1); |
| 634 | | tilemap_mark_tile_dirty(pf3_tilemap_2,offset>>1); |
| 641 | tilemap_mark_tile_dirty(state->pf3_tilemap_0,offset>>1); |
| 642 | tilemap_mark_tile_dirty(state->pf3_tilemap_1,offset>>1); |
| 643 | tilemap_mark_tile_dirty(state->pf3_tilemap_2,offset>>1); |
| 635 | 644 | } |
| 636 | 645 | |
| 637 | 646 | READ8_HANDLER( dec0_pf3_data_8bit_r ) |
| 638 | 647 | { |
| 648 | dec0_state *state = space->machine->driver_data<dec0_state>(); |
| 639 | 649 | if (offset&1) /* MSB */ |
| 640 | | return dec0_pf3_data[offset>>1]>>8; |
| 650 | return state->pf3_data[offset>>1]>>8; |
| 641 | 651 | |
| 642 | | return dec0_pf3_data[offset>>1]&0xff; |
| 652 | return state->pf3_data[offset>>1]&0xff; |
| 643 | 653 | } |
| 644 | 654 | |
| 645 | 655 | /******************************************************************************/ |
| r10427 | r10428 | |
| 676 | 686 | |
| 677 | 687 | static TILE_GET_INFO( get_pf1_tile_info ) |
| 678 | 688 | { |
| 679 | | int tile=dec0_pf1_data[tile_index]; |
| 689 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 690 | int tile=state->pf1_data[tile_index]; |
| 680 | 691 | SET_TILE_INFO(0,tile&0xfff,tile>>12,0); |
| 681 | 692 | } |
| 682 | 693 | |
| 683 | 694 | static TILE_GET_INFO( get_pf2_tile_info ) |
| 684 | 695 | { |
| 685 | | int tile=dec0_pf2_data[tile_index]; |
| 696 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 697 | int tile=state->pf2_data[tile_index]; |
| 686 | 698 | int pri=((tile>>12)>7); |
| 687 | 699 | SET_TILE_INFO(1,tile&0xfff,tile>>12,0); |
| 688 | 700 | tileinfo->group = pri; |
| r10427 | r10428 | |
| 690 | 702 | |
| 691 | 703 | static TILE_GET_INFO( get_pf3_tile_info ) |
| 692 | 704 | { |
| 693 | | int tile=dec0_pf3_data[tile_index]; |
| 705 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 706 | int tile=state->pf3_data[tile_index]; |
| 694 | 707 | int pri=((tile>>12)>7); |
| 695 | 708 | SET_TILE_INFO(2,tile&0xfff,tile>>12,0); |
| 696 | 709 | tileinfo->group = pri; |
| r10427 | r10428 | |
| 698 | 711 | |
| 699 | 712 | VIDEO_START( dec0_nodma ) |
| 700 | 713 | { |
| 701 | | pf1_tilemap_0 = tilemap_create(machine, get_pf1_tile_info,tile_shape0_8x8_scan, 8, 8,128, 32); |
| 702 | | pf1_tilemap_1 = tilemap_create(machine, get_pf1_tile_info,tile_shape1_8x8_scan, 8, 8, 64, 64); |
| 703 | | pf1_tilemap_2 = tilemap_create(machine, get_pf1_tile_info,tile_shape2_8x8_scan, 8, 8, 32,128); |
| 704 | | pf2_tilemap_0 = tilemap_create(machine, get_pf2_tile_info,tile_shape0_scan, 16,16, 64, 16); |
| 705 | | pf2_tilemap_1 = tilemap_create(machine, get_pf2_tile_info,tile_shape1_scan, 16,16, 32, 32); |
| 706 | | pf2_tilemap_2 = tilemap_create(machine, get_pf2_tile_info,tile_shape2_scan, 16,16, 16, 64); |
| 707 | | pf3_tilemap_0 = tilemap_create(machine, get_pf3_tile_info,tile_shape0_scan, 16,16, 64, 16); |
| 708 | | pf3_tilemap_1 = tilemap_create(machine, get_pf3_tile_info,tile_shape1_scan, 16,16, 32, 32); |
| 709 | | pf3_tilemap_2 = tilemap_create(machine, get_pf3_tile_info,tile_shape2_scan, 16,16, 16, 64); |
| 714 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 715 | state->pf1_tilemap_0 = tilemap_create(machine, get_pf1_tile_info,tile_shape0_8x8_scan, 8, 8,128, 32); |
| 716 | state->pf1_tilemap_1 = tilemap_create(machine, get_pf1_tile_info,tile_shape1_8x8_scan, 8, 8, 64, 64); |
| 717 | state->pf1_tilemap_2 = tilemap_create(machine, get_pf1_tile_info,tile_shape2_8x8_scan, 8, 8, 32,128); |
| 718 | state->pf2_tilemap_0 = tilemap_create(machine, get_pf2_tile_info,tile_shape0_scan, 16,16, 64, 16); |
| 719 | state->pf2_tilemap_1 = tilemap_create(machine, get_pf2_tile_info,tile_shape1_scan, 16,16, 32, 32); |
| 720 | state->pf2_tilemap_2 = tilemap_create(machine, get_pf2_tile_info,tile_shape2_scan, 16,16, 16, 64); |
| 721 | state->pf3_tilemap_0 = tilemap_create(machine, get_pf3_tile_info,tile_shape0_scan, 16,16, 64, 16); |
| 722 | state->pf3_tilemap_1 = tilemap_create(machine, get_pf3_tile_info,tile_shape1_scan, 16,16, 32, 32); |
| 723 | state->pf3_tilemap_2 = tilemap_create(machine, get_pf3_tile_info,tile_shape2_scan, 16,16, 16, 64); |
| 710 | 724 | |
| 711 | | dec0_spriteram=machine->generic.spriteram.u16; |
| 725 | state->spriteram=machine->generic.spriteram.u16; |
| 712 | 726 | } |
| 713 | 727 | |
| 714 | 728 | VIDEO_START( dec0 ) |
| 715 | 729 | { |
| 730 | dec0_state *state = machine->driver_data<dec0_state>(); |
| 716 | 731 | VIDEO_START_CALL(dec0_nodma); |
| 717 | | dec0_spriteram=auto_alloc_array(machine, UINT16, 0x800/2); |
| 732 | state->spriteram=auto_alloc_array(machine, UINT16, 0x800/2); |
| 718 | 733 | } |
| 719 | 734 | |
| 720 | 735 | /******************************************************************************/ |
src/mame/video/segas32.c
| r10427 | r10428 | |
| 199 | 199 | * |
| 200 | 200 | *************************************/ |
| 201 | 201 | |
| 202 | | struct layer_info |
| 203 | | { |
| 204 | | bitmap_t * bitmap; |
| 205 | | UINT8 * transparent; |
| 206 | | }; |
| 207 | | |
| 208 | | |
| 209 | 202 | struct extents_list |
| 210 | 203 | { |
| 211 | 204 | UINT8 scan_extent[256]; |
| r10427 | r10428 | |
| 225 | 218 | |
| 226 | 219 | /************************************* |
| 227 | 220 | * |
| 228 | | * Globals |
| 229 | | * |
| 230 | | *************************************/ |
| 231 | | |
| 232 | | UINT16 *system32_videoram; |
| 233 | | UINT16 *system32_spriteram; |
| 234 | | UINT16 *system32_paletteram[2]; |
| 235 | | UINT16 system32_displayenable[2]; |
| 236 | | UINT16 system32_tilebank_external; |
| 237 | | |
| 238 | | |
| 239 | | |
| 240 | | /************************************* |
| 241 | | * |
| 242 | | * Statics |
| 243 | | * |
| 244 | | *************************************/ |
| 245 | | |
| 246 | | static UINT8 is_multi32; |
| 247 | | |
| 248 | | /* tilemap cache */ |
| 249 | | static struct cache_entry *cache_head; |
| 250 | | |
| 251 | | /* mixer data */ |
| 252 | | static struct layer_info layer_data[11]; |
| 253 | | static UINT16 mixer_control[2][0x40]; |
| 254 | | static UINT16 *solid_0000; |
| 255 | | static UINT16 *solid_ffff; |
| 256 | | |
| 257 | | /* sprite data */ |
| 258 | | static UINT8 sprite_render_count; |
| 259 | | static UINT8 sprite_control_latched[8]; |
| 260 | | static UINT8 sprite_control[8]; |
| 261 | | static UINT32 *spriteram_32bit; |
| 262 | | |
| 263 | | |
| 264 | | |
| 265 | | /************************************* |
| 266 | | * |
| 267 | 221 | * Prototypes |
| 268 | 222 | * |
| 269 | 223 | *************************************/ |
| 270 | 224 | |
| 271 | 225 | static TILE_GET_INFO( get_tile_info ); |
| 272 | | static void sprite_erase_buffer(void); |
| 273 | | static void sprite_swap_buffers(void); |
| 226 | static void sprite_erase_buffer(segas32_state *state); |
| 227 | static void sprite_swap_buffers(segas32_state *state); |
| 274 | 228 | static void sprite_render_list(running_machine *machine); |
| 275 | 229 | |
| 276 | 230 | |
| r10427 | r10428 | |
| 284 | 238 | |
| 285 | 239 | static void common_start(running_machine *machine, int multi32) |
| 286 | 240 | { |
| 241 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 287 | 242 | int tmap; |
| 288 | 243 | |
| 289 | 244 | /* remember whether or not we are multi32 */ |
| 290 | | is_multi32 = multi32; |
| 245 | state->is_multi32 = multi32; |
| 291 | 246 | |
| 292 | 247 | /* allocate a copy of spriteram in 32-bit format */ |
| 293 | | spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4); |
| 248 | state->spriteram_32bit = auto_alloc_array(machine, UINT32, 0x20000/4); |
| 294 | 249 | |
| 295 | 250 | /* allocate the tilemap cache */ |
| 296 | | cache_head = NULL; |
| 251 | state->cache_head = NULL; |
| 297 | 252 | for (tmap = 0; tmap < TILEMAP_CACHE_SIZE; tmap++) |
| 298 | 253 | { |
| 299 | 254 | struct cache_entry *entry = auto_alloc(machine, struct cache_entry); |
| r10427 | r10428 | |
| 301 | 256 | entry->tmap = tilemap_create(machine, get_tile_info, tilemap_scan_rows, 16,16, 32,16); |
| 302 | 257 | entry->page = 0xff; |
| 303 | 258 | entry->bank = 0; |
| 304 | | entry->next = cache_head; |
| 259 | entry->next = state->cache_head; |
| 305 | 260 | tilemap_set_user_data(entry->tmap, entry); |
| 306 | 261 | |
| 307 | | cache_head = entry; |
| 262 | state->cache_head = entry; |
| 308 | 263 | } |
| 309 | 264 | |
| 310 | 265 | /* allocate the bitmaps (a few extra for multi32) */ |
| 311 | 266 | for (tmap = 0; tmap < 9 + 2 * multi32; tmap++) |
| 312 | 267 | { |
| 313 | | layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16); |
| 314 | | layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256); |
| 268 | state->layer_data[tmap].bitmap = auto_bitmap_alloc(machine, 416, 224, BITMAP_FORMAT_INDEXED16); |
| 269 | state->layer_data[tmap].transparent = auto_alloc_array_clear(machine, UINT8, 256); |
| 315 | 270 | } |
| 316 | 271 | |
| 317 | 272 | /* allocate pre-rendered solid lines of 0's and ffff's */ |
| 318 | | solid_0000 = auto_alloc_array(machine, UINT16, 512); |
| 319 | | memset(solid_0000, 0x00, sizeof(solid_0000[0]) * 512); |
| 320 | | solid_ffff = auto_alloc_array(machine, UINT16, 512); |
| 321 | | memset(solid_ffff, 0xff, sizeof(solid_ffff[0]) * 512); |
| 273 | state->solid_0000 = auto_alloc_array(machine, UINT16, 512); |
| 274 | memset(state->solid_0000, 0x00, sizeof(state->solid_0000[0]) * 512); |
| 275 | state->solid_ffff = auto_alloc_array(machine, UINT16, 512); |
| 276 | memset(state->solid_ffff, 0xff, sizeof(state->solid_ffff[0]) * 512); |
| 322 | 277 | |
| 323 | 278 | /* initialize videoram */ |
| 324 | | system32_videoram[0x1ff00/2] = 0x8000; |
| 279 | state->system32_videoram[0x1ff00/2] = 0x8000; |
| 325 | 280 | } |
| 326 | 281 | |
| 327 | 282 | |
| r10427 | r10428 | |
| 346 | 301 | |
| 347 | 302 | static TIMER_CALLBACK( update_sprites ) |
| 348 | 303 | { |
| 304 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 349 | 305 | /* if automatic mode is selected, do it every frame (0) or every other frame (1) */ |
| 350 | | if (!(sprite_control[3] & 2)) |
| 306 | if (!(state->sprite_control[3] & 2)) |
| 351 | 307 | { |
| 352 | 308 | /* if we count down to the start, process the automatic swapping, but only after a short delay */ |
| 353 | | if (sprite_render_count-- == 0) |
| 309 | if (state->sprite_render_count-- == 0) |
| 354 | 310 | { |
| 355 | | sprite_control[0] = 3; |
| 356 | | sprite_render_count = sprite_control[3] & 1; |
| 311 | state->sprite_control[0] = 3; |
| 312 | state->sprite_render_count = state->sprite_control[3] & 1; |
| 357 | 313 | } |
| 358 | 314 | } |
| 359 | 315 | |
| 360 | 316 | /* look for pending commands */ |
| 361 | | if (sprite_control[0] & 2) |
| 362 | | sprite_erase_buffer(); |
| 363 | | if (sprite_control[0] & 1) |
| 317 | if (state->sprite_control[0] & 2) |
| 318 | sprite_erase_buffer(state); |
| 319 | if (state->sprite_control[0] & 1) |
| 364 | 320 | { |
| 365 | | sprite_swap_buffers(); |
| 321 | sprite_swap_buffers(state); |
| 366 | 322 | sprite_render_list(machine); |
| 367 | 323 | } |
| 368 | | sprite_control[0] = 0; |
| 324 | state->sprite_control[0] = 0; |
| 369 | 325 | } |
| 370 | 326 | |
| 371 | 327 | |
| r10427 | r10428 | |
| 415 | 371 | } |
| 416 | 372 | |
| 417 | 373 | |
| 418 | | INLINE UINT16 common_paletteram_r(int which, offs_t offset) |
| 374 | INLINE UINT16 common_paletteram_r(address_space *space, int which, offs_t offset) |
| 419 | 375 | { |
| 376 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 420 | 377 | int convert; |
| 421 | 378 | |
| 422 | 379 | /* the lower half of palette RAM is formatted xBBBBBGGGGGRRRRR */ |
| r10427 | r10428 | |
| 427 | 384 | offset &= 0x3fff; |
| 428 | 385 | |
| 429 | 386 | if (!convert) |
| 430 | | return system32_paletteram[which][offset]; |
| 387 | return state->system32_paletteram[which][offset]; |
| 431 | 388 | else |
| 432 | | return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(system32_paletteram[which][offset]); |
| 389 | return xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(state->system32_paletteram[which][offset]); |
| 433 | 390 | } |
| 434 | 391 | |
| 435 | 392 | |
| 436 | 393 | static void common_paletteram_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 437 | 394 | { |
| 395 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 438 | 396 | UINT16 value; |
| 439 | 397 | int convert; |
| 440 | 398 | |
| r10427 | r10428 | |
| 446 | 404 | offset &= 0x3fff; |
| 447 | 405 | |
| 448 | 406 | /* read, modify, and write the new value, updating the palette */ |
| 449 | | value = system32_paletteram[which][offset]; |
| 407 | value = state->system32_paletteram[which][offset]; |
| 450 | 408 | if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value); |
| 451 | 409 | COMBINE_DATA(&value); |
| 452 | 410 | if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value); |
| 453 | | system32_paletteram[which][offset] = value; |
| 411 | state->system32_paletteram[which][offset] = value; |
| 454 | 412 | update_color(space->machine, 0x4000*which + offset, value); |
| 455 | 413 | |
| 456 | 414 | /* if blending is enabled, writes go to both halves of palette RAM */ |
| 457 | | if (mixer_control[which][0x4e/2] & 0x0880) |
| 415 | if (state->mixer_control[which][0x4e/2] & 0x0880) |
| 458 | 416 | { |
| 459 | 417 | offset ^= 0x2000; |
| 460 | 418 | |
| 461 | 419 | /* read, modify, and write the new value, updating the palette */ |
| 462 | | value = system32_paletteram[which][offset]; |
| 420 | value = state->system32_paletteram[which][offset]; |
| 463 | 421 | if (convert) value = xBBBBBGGGGGRRRRR_to_xBGRBBBBGGGGRRRR(value); |
| 464 | 422 | COMBINE_DATA(&value); |
| 465 | 423 | if (convert) value = xBGRBBBBGGGGRRRR_to_xBBBBBGGGGGRRRRR(value); |
| 466 | | system32_paletteram[which][offset] = value; |
| 424 | state->system32_paletteram[which][offset] = value; |
| 467 | 425 | update_color(space->machine, 0x4000*which + offset, value); |
| 468 | 426 | } |
| 469 | 427 | } |
| r10427 | r10428 | |
| 478 | 436 | |
| 479 | 437 | READ16_HANDLER( system32_paletteram_r ) |
| 480 | 438 | { |
| 481 | | return common_paletteram_r(0, offset); |
| 439 | return common_paletteram_r(space, 0, offset); |
| 482 | 440 | } |
| 483 | 441 | |
| 484 | 442 | |
| r10427 | r10428 | |
| 490 | 448 | |
| 491 | 449 | READ32_HANDLER( multi32_paletteram_0_r ) |
| 492 | 450 | { |
| 493 | | return common_paletteram_r(0, offset*2+0) | |
| 494 | | (common_paletteram_r(0, offset*2+1) << 16); |
| 451 | return common_paletteram_r(space, 0, offset*2+0) | |
| 452 | (common_paletteram_r(space, 0, offset*2+1) << 16); |
| 495 | 453 | } |
| 496 | 454 | |
| 497 | 455 | |
| r10427 | r10428 | |
| 506 | 464 | |
| 507 | 465 | READ32_HANDLER( multi32_paletteram_1_r ) |
| 508 | 466 | { |
| 509 | | return common_paletteram_r(1, offset*2+0) | |
| 510 | | (common_paletteram_r(1, offset*2+1) << 16); |
| 467 | return common_paletteram_r(space, 1, offset*2+0) | |
| 468 | (common_paletteram_r(space, 1, offset*2+1) << 16); |
| 511 | 469 | } |
| 512 | 470 | |
| 513 | 471 | |
| r10427 | r10428 | |
| 529 | 487 | |
| 530 | 488 | READ16_HANDLER( system32_videoram_r ) |
| 531 | 489 | { |
| 532 | | return system32_videoram[offset]; |
| 490 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 491 | return state->system32_videoram[offset]; |
| 533 | 492 | } |
| 534 | 493 | |
| 535 | 494 | |
| 536 | 495 | WRITE16_HANDLER( system32_videoram_w ) |
| 537 | 496 | { |
| 538 | | COMBINE_DATA(&system32_videoram[offset]); |
| 497 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 498 | COMBINE_DATA(&state->system32_videoram[offset]); |
| 539 | 499 | |
| 540 | 500 | /* if we are not in the control area, just update any affected tilemaps */ |
| 541 | 501 | if (offset < 0x1ff00/2) |
| r10427 | r10428 | |
| 545 | 505 | offset %= 0x200; |
| 546 | 506 | |
| 547 | 507 | /* scan the cache for a matching pages */ |
| 548 | | for (entry = cache_head; entry != NULL; entry = entry->next) |
| 508 | for (entry = state->cache_head; entry != NULL; entry = entry->next) |
| 549 | 509 | if (entry->page == page) |
| 550 | 510 | tilemap_mark_tile_dirty(entry->tmap, offset); |
| 551 | 511 | } |
| r10427 | r10428 | |
| 554 | 514 | |
| 555 | 515 | READ32_HANDLER( multi32_videoram_r ) |
| 556 | 516 | { |
| 557 | | return system32_videoram[offset*2+0] | |
| 558 | | (system32_videoram[offset*2+1] << 16); |
| 517 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 518 | return state->system32_videoram[offset*2+0] | |
| 519 | (state->system32_videoram[offset*2+1] << 16); |
| 559 | 520 | } |
| 560 | 521 | |
| 561 | 522 | |
| r10427 | r10428 | |
| 577 | 538 | |
| 578 | 539 | READ16_HANDLER( system32_sprite_control_r ) |
| 579 | 540 | { |
| 541 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 580 | 542 | switch (offset) |
| 581 | 543 | { |
| 582 | 544 | case 0: |
| 583 | 545 | /* D1 : Seems to be '1' only during an erase in progress, this |
| 584 | 546 | occurs very briefly though. |
| 585 | 547 | D0 : Selected frame buffer (0= A, 1= B) */ |
| 586 | | return 0xfffc | (int)(layer_data[MIXER_LAYER_SPRITES].bitmap < layer_data[MIXER_LAYER_SPRITES_2].bitmap); |
| 548 | return 0xfffc | (int)(state->layer_data[MIXER_LAYER_SPRITES].bitmap < state->layer_data[MIXER_LAYER_SPRITES_2].bitmap); |
| 587 | 549 | |
| 588 | 550 | case 1: |
| 589 | 551 | /* D1 : ? |
| r10427 | r10428 | |
| 602 | 564 | case 2: |
| 603 | 565 | /* D1 : 1= Vertical flip, 0= Normal orientation |
| 604 | 566 | D0 : 1= Horizontal flip, 0= Normal orientation */ |
| 605 | | return 0xfffc | sprite_control_latched[2]; |
| 567 | return 0xfffc | state->sprite_control_latched[2]; |
| 606 | 568 | |
| 607 | 569 | case 3: |
| 608 | 570 | /* D1 : 1= Manual mode, 0= Automatic mode |
| 609 | 571 | D0 : 1= 30 Hz update, 0= 60 Hz update (automatic mode only) */ |
| 610 | | return 0xfffc | sprite_control_latched[3]; |
| 572 | return 0xfffc | state->sprite_control_latched[3]; |
| 611 | 573 | |
| 612 | 574 | case 4: |
| 613 | 575 | /* D1 : ? |
| 614 | 576 | D0 : ? */ |
| 615 | | return 0xfffc | sprite_control_latched[4]; |
| 577 | return 0xfffc | state->sprite_control_latched[4]; |
| 616 | 578 | |
| 617 | 579 | case 5: |
| 618 | 580 | /* D1 : ? |
| 619 | 581 | D0 : ? */ |
| 620 | | return 0xfffc | sprite_control_latched[5]; |
| 582 | return 0xfffc | state->sprite_control_latched[5]; |
| 621 | 583 | |
| 622 | 584 | case 6: |
| 623 | 585 | /* D0 : 1= 416 pixels |
| 624 | 586 | 0= 320 pixels */ |
| 625 | | return 0xfffc | (sprite_control_latched[6] & 1); |
| 587 | return 0xfffc | (state->sprite_control_latched[6] & 1); |
| 626 | 588 | |
| 627 | 589 | case 7: |
| 628 | 590 | /* D1 : ? |
| r10427 | r10428 | |
| 635 | 597 | |
| 636 | 598 | WRITE16_HANDLER( system32_sprite_control_w ) |
| 637 | 599 | { |
| 600 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 638 | 601 | if (ACCESSING_BITS_0_7) |
| 639 | | sprite_control[offset & 7] = data; |
| 602 | state->sprite_control[offset & 7] = data; |
| 640 | 603 | } |
| 641 | 604 | |
| 642 | 605 | |
| r10427 | r10428 | |
| 665 | 628 | |
| 666 | 629 | READ16_HANDLER( system32_spriteram_r ) |
| 667 | 630 | { |
| 668 | | return system32_spriteram[offset]; |
| 631 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 632 | return state->system32_spriteram[offset]; |
| 669 | 633 | } |
| 670 | 634 | |
| 671 | 635 | |
| 672 | 636 | WRITE16_HANDLER( system32_spriteram_w ) |
| 673 | 637 | { |
| 674 | | COMBINE_DATA(&system32_spriteram[offset]); |
| 675 | | spriteram_32bit[offset/2] = |
| 676 | | ((system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | |
| 677 | | ((system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | |
| 678 | | ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | |
| 679 | | ((system32_spriteram[offset & ~1] << 24) & 0xff000000); |
| 638 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 639 | COMBINE_DATA(&state->system32_spriteram[offset]); |
| 640 | state->spriteram_32bit[offset/2] = |
| 641 | ((state->system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | |
| 642 | ((state->system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | |
| 643 | ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | |
| 644 | ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000); |
| 680 | 645 | } |
| 681 | 646 | |
| 682 | 647 | |
| 683 | 648 | READ32_HANDLER( multi32_spriteram_r ) |
| 684 | 649 | { |
| 685 | | return system32_spriteram[offset*2+0] | |
| 686 | | (system32_spriteram[offset*2+1] << 16); |
| 650 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 651 | return state->system32_spriteram[offset*2+0] | |
| 652 | (state->system32_spriteram[offset*2+1] << 16); |
| 687 | 653 | } |
| 688 | 654 | |
| 689 | 655 | |
| 690 | 656 | WRITE32_HANDLER( multi32_spriteram_w ) |
| 691 | 657 | { |
| 658 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 692 | 659 | data = SWAP_HALVES(data); |
| 693 | 660 | mem_mask = SWAP_HALVES(mem_mask); |
| 694 | | COMBINE_DATA((UINT32 *)&system32_spriteram[offset*2]); |
| 695 | | spriteram_32bit[offset/2] = |
| 696 | | ((system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | |
| 697 | | ((system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | |
| 698 | | ((system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | |
| 699 | | ((system32_spriteram[offset & ~1] << 24) & 0xff000000); |
| 661 | COMBINE_DATA((UINT32 *)&state->system32_spriteram[offset*2]); |
| 662 | state->spriteram_32bit[offset/2] = |
| 663 | ((state->system32_spriteram[offset | 1] >> 8 ) & 0x000000ff) | |
| 664 | ((state->system32_spriteram[offset | 1] << 8 ) & 0x0000ff00) | |
| 665 | ((state->system32_spriteram[offset & ~1] << 8 ) & 0x00ff0000) | |
| 666 | ((state->system32_spriteram[offset & ~1] << 24) & 0xff000000); |
| 700 | 667 | } |
| 701 | 668 | |
| 702 | 669 | |
| r10427 | r10428 | |
| 709 | 676 | |
| 710 | 677 | READ16_HANDLER( system32_mixer_r ) |
| 711 | 678 | { |
| 712 | | return mixer_control[0][offset]; |
| 679 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 680 | return state->mixer_control[0][offset]; |
| 713 | 681 | } |
| 714 | 682 | |
| 715 | 683 | WRITE16_HANDLER( system32_mixer_w ) |
| 716 | 684 | { |
| 717 | | COMBINE_DATA(&mixer_control[0][offset]); |
| 685 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 686 | COMBINE_DATA(&state->mixer_control[0][offset]); |
| 718 | 687 | } |
| 719 | 688 | |
| 720 | 689 | |
| 721 | 690 | WRITE32_HANDLER( multi32_mixer_0_w ) |
| 722 | 691 | { |
| 692 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 723 | 693 | data = SWAP_HALVES(data); |
| 724 | 694 | mem_mask = SWAP_HALVES(mem_mask); |
| 725 | | COMBINE_DATA((UINT32 *)&mixer_control[0][offset*2]); |
| 695 | COMBINE_DATA((UINT32 *)&state->mixer_control[0][offset*2]); |
| 726 | 696 | } |
| 727 | 697 | |
| 728 | 698 | |
| 729 | 699 | WRITE32_HANDLER( multi32_mixer_1_w ) |
| 730 | 700 | { |
| 701 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 731 | 702 | data = SWAP_HALVES(data); |
| 732 | 703 | mem_mask = SWAP_HALVES(mem_mask); |
| 733 | | COMBINE_DATA((UINT32 *)&mixer_control[1][offset*2]); |
| 704 | COMBINE_DATA((UINT32 *)&state->mixer_control[1][offset*2]); |
| 734 | 705 | } |
| 735 | 706 | |
| 736 | 707 | |
| r10427 | r10428 | |
| 741 | 712 | * |
| 742 | 713 | *************************************/ |
| 743 | 714 | |
| 744 | | static tilemap_t *find_cache_entry(int page, int bank) |
| 715 | static tilemap_t *find_cache_entry(segas32_state *state, int page, int bank) |
| 745 | 716 | { |
| 746 | 717 | struct cache_entry *entry, *prev; |
| 747 | 718 | |
| 748 | 719 | /* scan the list for a matching entry */ |
| 749 | 720 | prev = NULL; |
| 750 | | entry = cache_head; |
| 721 | entry = state->cache_head; |
| 751 | 722 | while (1) |
| 752 | 723 | { |
| 753 | 724 | if (entry->page == page && entry->bank == bank) |
| r10427 | r10428 | |
| 756 | 727 | if (prev) |
| 757 | 728 | { |
| 758 | 729 | prev->next = entry->next; |
| 759 | | entry->next = cache_head; |
| 760 | | cache_head = entry; |
| 730 | entry->next = state->cache_head; |
| 731 | state->cache_head = entry; |
| 761 | 732 | } |
| 762 | 733 | return entry->tmap; |
| 763 | 734 | } |
| r10427 | r10428 | |
| 776 | 747 | |
| 777 | 748 | /* move it to the head */ |
| 778 | 749 | prev->next = entry->next; |
| 779 | | entry->next = cache_head; |
| 780 | | cache_head = entry; |
| 750 | entry->next = state->cache_head; |
| 751 | state->cache_head = entry; |
| 781 | 752 | |
| 782 | 753 | return entry->tmap; |
| 783 | 754 | } |
| r10427 | r10428 | |
| 792 | 763 | |
| 793 | 764 | static TILE_GET_INFO( get_tile_info ) |
| 794 | 765 | { |
| 766 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 795 | 767 | struct cache_entry *entry = (struct cache_entry *)param; |
| 796 | | UINT16 data = system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index]; |
| 768 | UINT16 data = state->system32_videoram[(entry->page & 0x7f) * 0x200 + tile_index]; |
| 797 | 769 | SET_TILE_INFO(0, (entry->bank << 13) + (data & 0x1fff), (data >> 4) & 0x1ff, (data >> 14) & 3); |
| 798 | 770 | } |
| 799 | 771 | |
| r10427 | r10428 | |
| 807 | 779 | |
| 808 | 780 | static int compute_clipping_extents(screen_device &screen, int enable, int clipout, int clipmask, const rectangle *cliprect, struct extents_list *list) |
| 809 | 781 | { |
| 810 | | int flip = (system32_videoram[0x1ff00/2] >> 9) & 1; |
| 782 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 783 | int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; |
| 811 | 784 | rectangle tempclip; |
| 812 | 785 | rectangle clips[5]; |
| 813 | 786 | int sorted[5]; |
| r10427 | r10428 | |
| 834 | 807 | { |
| 835 | 808 | if (!flip) |
| 836 | 809 | { |
| 837 | | clips[i].min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; |
| 838 | | clips[i].min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; |
| 839 | | clips[i].max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; |
| 840 | | clips[i].max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; |
| 810 | clips[i].min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; |
| 811 | clips[i].min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; |
| 812 | clips[i].max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; |
| 813 | clips[i].max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; |
| 841 | 814 | } |
| 842 | 815 | else |
| 843 | 816 | { |
| 844 | 817 | const rectangle &visarea = screen.visible_area(); |
| 845 | 818 | |
| 846 | | clips[i].max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); |
| 847 | | clips[i].max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); |
| 848 | | clips[i].min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); |
| 849 | | clips[i].min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); |
| 819 | clips[i].max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); |
| 820 | clips[i].max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); |
| 821 | clips[i].min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); |
| 822 | clips[i].min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); |
| 850 | 823 | } |
| 851 | 824 | sect_rect(&clips[i], &tempclip); |
| 852 | 825 | sorted[i] = i; |
| r10427 | r10428 | |
| 914 | 887 | * |
| 915 | 888 | *************************************/ |
| 916 | 889 | |
| 917 | | INLINE void get_tilemaps(int bgnum, tilemap_t **tilemaps) |
| 890 | INLINE void get_tilemaps(segas32_state *state, int bgnum, tilemap_t **tilemaps) |
| 918 | 891 | { |
| 919 | 892 | int tilebank, page; |
| 920 | 893 | |
| 921 | 894 | /* determine the current tilebank */ |
| 922 | | if (is_multi32) |
| 923 | | tilebank = (system32_tilebank_external >> (2*bgnum)) & 3; |
| 895 | if (state->is_multi32) |
| 896 | tilebank = (state->system32_tilebank_external >> (2*bgnum)) & 3; |
| 924 | 897 | else |
| 925 | | tilebank = ((system32_tilebank_external & 1) << 1) | ((system32_videoram[0x1ff00/2] & 0x400) >> 10); |
| 898 | tilebank = ((state->system32_tilebank_external & 1) << 1) | ((state->system32_videoram[0x1ff00/2] & 0x400) >> 10); |
| 926 | 899 | |
| 927 | 900 | /* find the cache entries */ |
| 928 | | page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f; |
| 929 | | tilemaps[0] = find_cache_entry(page, tilebank); |
| 930 | | page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f; |
| 931 | | tilemaps[1] = find_cache_entry(page, tilebank); |
| 932 | | page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f; |
| 933 | | tilemaps[2] = find_cache_entry(page, tilebank); |
| 934 | | page = (system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f; |
| 935 | | tilemaps[3] = find_cache_entry(page, tilebank); |
| 901 | page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 0) & 0x7f; |
| 902 | tilemaps[0] = find_cache_entry(state, page, tilebank); |
| 903 | page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 0] >> 8) & 0x7f; |
| 904 | tilemaps[1] = find_cache_entry(state, page, tilebank); |
| 905 | page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 0) & 0x7f; |
| 906 | tilemaps[2] = find_cache_entry(state, page, tilebank); |
| 907 | page = (state->system32_videoram[0x1ff40/2 + 2 * bgnum + 1] >> 8) & 0x7f; |
| 908 | tilemaps[3] = find_cache_entry(state, page, tilebank); |
| 936 | 909 | } |
| 937 | 910 | |
| 938 | 911 | |
| 939 | 912 | static void update_tilemap_zoom(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum) |
| 940 | 913 | { |
| 914 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 941 | 915 | int clipenable, clipout, clips, clipdraw_start; |
| 942 | 916 | bitmap_t *bitmap = layer->bitmap; |
| 943 | 917 | struct extents_list clip_extents; |
| r10427 | r10428 | |
| 949 | 923 | int x, y; |
| 950 | 924 | |
| 951 | 925 | /* get the tilemaps */ |
| 952 | | get_tilemaps(bgnum, tilemaps); |
| 926 | get_tilemaps(state, bgnum, tilemaps); |
| 953 | 927 | |
| 954 | 928 | /* configure the layer */ |
| 955 | 929 | opaque = 0; |
| 956 | | //opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; |
| 930 | //opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; |
| 957 | 931 | //if (input_code_pressed(screen.machine, KEYCODE_Z) && bgnum == 0) opaque = 1; |
| 958 | 932 | //if (input_code_pressed(screen.machine, KEYCODE_X) && bgnum == 1) opaque = 1; |
| 959 | 933 | |
| 960 | 934 | /* determine if we're flipped */ |
| 961 | | flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1; |
| 935 | flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1; |
| 962 | 936 | |
| 963 | 937 | /* determine the clipping */ |
| 964 | | clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; |
| 965 | | clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; |
| 966 | | clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; |
| 938 | clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; |
| 939 | clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; |
| 940 | clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; |
| 967 | 941 | clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); |
| 968 | 942 | |
| 969 | 943 | /* extract the X/Y step values (these are in destination space!) */ |
| 970 | | dstxstep = system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff; |
| 971 | | if (system32_videoram[0x1ff00/2] & 0x4000) |
| 972 | | dstystep = system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff; |
| 944 | dstxstep = state->system32_videoram[0x1ff50/2 + 2 * bgnum] & 0xfff; |
| 945 | if (state->system32_videoram[0x1ff00/2] & 0x4000) |
| 946 | dstystep = state->system32_videoram[0x1ff52/2 + 2 * bgnum] & 0xfff; |
| 973 | 947 | else |
| 974 | 948 | dstystep = dstxstep; |
| 975 | 949 | |
| r10427 | r10428 | |
| 984 | 958 | srcystep = (0x200 << 20) / dstystep; |
| 985 | 959 | |
| 986 | 960 | /* start with the fractional scroll offsets, in source coordinates */ |
| 987 | | srcx_start = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20; |
| 988 | | srcx_start += (system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4; |
| 989 | | srcy = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20; |
| 990 | | srcy += (system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4; |
| 961 | srcx_start = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) << 20; |
| 962 | srcx_start += (state->system32_videoram[0x1ff10/2 + 4 * bgnum] & 0xff00) << 4; |
| 963 | srcy = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff) << 20; |
| 964 | srcy += (state->system32_videoram[0x1ff14/2 + 4 * bgnum] & 0xfe00) << 4; |
| 991 | 965 | |
| 992 | 966 | /* then account for the destination center coordinates */ |
| 993 | | srcx_start -= ((INT16)(system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep; |
| 994 | | srcy -= ((INT16)(system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep; |
| 967 | srcx_start -= ((INT16)(state->system32_videoram[0x1ff30/2 + 2 * bgnum] << 6) >> 6) * srcxstep; |
| 968 | srcy -= ((INT16)(state->system32_videoram[0x1ff32/2 + 2 * bgnum] << 7) >> 7) * srcystep; |
| 995 | 969 | |
| 996 | 970 | /* finally, account for destination top,left coordinates */ |
| 997 | 971 | srcx_start += cliprect->min_x * srcxstep; |
| r10427 | r10428 | |
| 1076 | 1050 | #if 0 |
| 1077 | 1051 | if (dstxstep != 0x200 || dstystep != 0x200) |
| 1078 | 1052 | popmessage("Zoom=%03X,%03X Cent=%03X,%03X", dstxstep, dstystep, |
| 1079 | | system32_videoram[0x1ff30/2 + 2 * bgnum], |
| 1080 | | system32_videoram[0x1ff32/2 + 2 * bgnum]); |
| 1053 | state->system32_videoram[0x1ff30/2 + 2 * bgnum], |
| 1054 | state->system32_videoram[0x1ff32/2 + 2 * bgnum]); |
| 1081 | 1055 | #endif |
| 1082 | 1056 | } |
| 1083 | 1057 | |
| r10427 | r10428 | |
| 1091 | 1065 | |
| 1092 | 1066 | static void update_tilemap_rowscroll(screen_device &screen, struct layer_info *layer, const rectangle *cliprect, int bgnum) |
| 1093 | 1067 | { |
| 1068 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 1094 | 1069 | int clipenable, clipout, clips, clipdraw_start; |
| 1095 | 1070 | bitmap_t *bitmap = layer->bitmap; |
| 1096 | 1071 | struct extents_list clip_extents; |
| r10427 | r10428 | |
| 1103 | 1078 | int x, y; |
| 1104 | 1079 | |
| 1105 | 1080 | /* get the tilemaps */ |
| 1106 | | get_tilemaps(bgnum, tilemaps); |
| 1081 | get_tilemaps(state, bgnum, tilemaps); |
| 1107 | 1082 | |
| 1108 | 1083 | /* configure the layer */ |
| 1109 | 1084 | opaque = 0; |
| 1110 | | //opaque = (system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; |
| 1085 | //opaque = (state->system32_videoram[0x1ff8e/2] >> (8 + bgnum)) & 1; |
| 1111 | 1086 | //if (input_code_pressed(screen.machine, KEYCODE_C) && bgnum == 2) opaque = 1; |
| 1112 | 1087 | //if (input_code_pressed(screen.machine, KEYCODE_V) && bgnum == 3) opaque = 1; |
| 1113 | 1088 | |
| 1114 | 1089 | /* determine if we're flipped */ |
| 1115 | | flip = ((system32_videoram[0x1ff00/2] >> 9) ^ (system32_videoram[0x1ff00/2] >> bgnum)) & 1; |
| 1090 | flip = ((state->system32_videoram[0x1ff00/2] >> 9) ^ (state->system32_videoram[0x1ff00/2] >> bgnum)) & 1; |
| 1116 | 1091 | |
| 1117 | 1092 | /* determine the clipping */ |
| 1118 | | clipenable = (system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; |
| 1119 | | clipout = (system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; |
| 1120 | | clips = (system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; |
| 1093 | clipenable = (state->system32_videoram[0x1ff02/2] >> (11 + bgnum)) & 1; |
| 1094 | clipout = (state->system32_videoram[0x1ff02/2] >> (6 + bgnum)) & 1; |
| 1095 | clips = (state->system32_videoram[0x1ff06/2] >> (4 * bgnum)) & 0x0f; |
| 1121 | 1096 | clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); |
| 1122 | 1097 | |
| 1123 | 1098 | /* determine if row scroll and/or row select is enabled */ |
| 1124 | | rowscroll = (system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1; |
| 1125 | | rowselect = (system32_videoram[0x1ff04/2] >> bgnum) & 1; |
| 1126 | | if ((system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1) |
| 1099 | rowscroll = (state->system32_videoram[0x1ff04/2] >> (bgnum - 2)) & 1; |
| 1100 | rowselect = (state->system32_videoram[0x1ff04/2] >> bgnum) & 1; |
| 1101 | if ((state->system32_videoram[0x1ff04/2] >> (bgnum + 2)) & 1) |
| 1127 | 1102 | rowscroll = rowselect = 0; |
| 1128 | 1103 | |
| 1129 | 1104 | /* get a pointer to the table */ |
| 1130 | | table = &system32_videoram[(system32_videoram[0x1ff04/2] >> 10) * 0x400]; |
| 1105 | table = &state->system32_videoram[(state->system32_videoram[0x1ff04/2] >> 10) * 0x400]; |
| 1131 | 1106 | |
| 1132 | 1107 | /* start with screen-wide X and Y scrolls */ |
| 1133 | | xscroll = (system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff); |
| 1134 | | yscroll = (system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff); |
| 1108 | xscroll = (state->system32_videoram[0x1ff12/2 + 4 * bgnum] & 0x3ff) - (state->system32_videoram[0x1ff30/2 + 2 * bgnum] & 0x1ff); |
| 1109 | yscroll = (state->system32_videoram[0x1ff16/2 + 4 * bgnum] & 0x1ff); |
| 1135 | 1110 | |
| 1136 | 1111 | /* render the tilemap into its bitmap */ |
| 1137 | 1112 | for (y = cliprect->min_y; y <= cliprect->max_y; y++) |
| r10427 | r10428 | |
| 1229 | 1204 | #if 0 |
| 1230 | 1205 | if (rowscroll || rowselect) |
| 1231 | 1206 | popmessage("Scroll=%d Select=%d Table@%06X", |
| 1232 | | rowscroll, rowselect, (system32_videoram[0x1ff04/2] >> 10) * 0x800); |
| 1207 | rowscroll, rowselect, (state->system32_videoram[0x1ff04/2] >> 10) * 0x800); |
| 1233 | 1208 | #endif |
| 1234 | 1209 | } |
| 1235 | 1210 | |
| r10427 | r10428 | |
| 1243 | 1218 | |
| 1244 | 1219 | static void update_tilemap_text(screen_device &screen, struct layer_info *layer, const rectangle *cliprect) |
| 1245 | 1220 | { |
| 1221 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 1246 | 1222 | bitmap_t *bitmap = layer->bitmap; |
| 1247 | 1223 | UINT16 *tilebase; |
| 1248 | 1224 | UINT16 *gfxbase; |
| r10427 | r10428 | |
| 1252 | 1228 | int flip; |
| 1253 | 1229 | |
| 1254 | 1230 | /* determine if we're flipped */ |
| 1255 | | flip = (system32_videoram[0x1ff00/2] >> 9) & 1; |
| 1231 | flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; |
| 1256 | 1232 | |
| 1257 | 1233 | /* determine the base of the tilemap and graphics data */ |
| 1258 | | tilebase = &system32_videoram[((system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800]; |
| 1259 | | gfxbase = &system32_videoram[(system32_videoram[0x1ff5c/2] & 7) * 0x2000]; |
| 1234 | tilebase = &state->system32_videoram[((state->system32_videoram[0x1ff5c/2] >> 4) & 0x1f) * 0x800]; |
| 1235 | gfxbase = &state->system32_videoram[(state->system32_videoram[0x1ff5c/2] & 7) * 0x2000]; |
| 1260 | 1236 | |
| 1261 | 1237 | /* compute start/end tile numbers */ |
| 1262 | 1238 | startx = cliprect->min_x / 8; |
| r10427 | r10428 | |
| 1402 | 1378 | |
| 1403 | 1379 | static void update_bitmap(screen_device &screen, struct layer_info *layer, const rectangle *cliprect) |
| 1404 | 1380 | { |
| 1381 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 1405 | 1382 | int clipenable, clipout, clips, clipdraw_start; |
| 1406 | 1383 | bitmap_t *bitmap = layer->bitmap; |
| 1407 | 1384 | struct extents_list clip_extents; |
| r10427 | r10428 | |
| 1411 | 1388 | int bpp; |
| 1412 | 1389 | |
| 1413 | 1390 | /* configure the layer */ |
| 1414 | | bpp = (system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4; |
| 1391 | bpp = (state->system32_videoram[0x1ff00/2] & 0x0800) ? 8 : 4; |
| 1415 | 1392 | |
| 1416 | 1393 | /* determine the clipping */ |
| 1417 | | clipenable = (system32_videoram[0x1ff02/2] >> 15) & 1; |
| 1418 | | clipout = (system32_videoram[0x1ff02/2] >> 10) & 1; |
| 1394 | clipenable = (state->system32_videoram[0x1ff02/2] >> 15) & 1; |
| 1395 | clipout = (state->system32_videoram[0x1ff02/2] >> 10) & 1; |
| 1419 | 1396 | clips = 0x10; |
| 1420 | 1397 | clipdraw_start = compute_clipping_extents(screen, clipenable, clipout, clips, cliprect, &clip_extents); |
| 1421 | 1398 | |
| 1422 | 1399 | /* determine x/y scroll */ |
| 1423 | | xscroll = system32_videoram[0x1ff88/2] & 0x1ff; |
| 1424 | | yscroll = system32_videoram[0x1ff8a/2] & 0x1ff; |
| 1425 | | color = (system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1); |
| 1400 | xscroll = state->system32_videoram[0x1ff88/2] & 0x1ff; |
| 1401 | yscroll = state->system32_videoram[0x1ff8a/2] & 0x1ff; |
| 1402 | color = (state->system32_videoram[0x1ff8c/2] << 4) & 0x1fff0 & ~((1 << bpp) - 1); |
| 1426 | 1403 | |
| 1427 | 1404 | /* loop over target rows */ |
| 1428 | 1405 | for (y = cliprect->min_y; y <= cliprect->max_y; y++) |
| r10427 | r10428 | |
| 1445 | 1422 | /* 8bpp mode case */ |
| 1446 | 1423 | if (bpp == 8) |
| 1447 | 1424 | { |
| 1448 | | UINT8 *src = (UINT8 *)&system32_videoram[512/2 * ((y + yscroll) & 0xff)]; |
| 1425 | UINT8 *src = (UINT8 *)&state->system32_videoram[512/2 * ((y + yscroll) & 0xff)]; |
| 1449 | 1426 | for (x = extents[0]; x < extents[1]; x++) |
| 1450 | 1427 | { |
| 1451 | 1428 | int effx = (x + xscroll) & 0x1ff; |
| r10427 | r10428 | |
| 1459 | 1436 | /* 4bpp mode case */ |
| 1460 | 1437 | else |
| 1461 | 1438 | { |
| 1462 | | UINT16 *src = &system32_videoram[512/4 * ((y + yscroll) & 0x1ff)]; |
| 1439 | UINT16 *src = &state->system32_videoram[512/4 * ((y + yscroll) & 0x1ff)]; |
| 1463 | 1440 | for (x = extents[0]; x < extents[1]; x++) |
| 1464 | 1441 | { |
| 1465 | 1442 | int effx = (x + xscroll) & 0x1ff; |
| r10427 | r10428 | |
| 1503 | 1480 | * |
| 1504 | 1481 | *************************************/ |
| 1505 | 1482 | |
| 1506 | | static void update_background(struct layer_info *layer, const rectangle *cliprect) |
| 1483 | static void update_background(segas32_state *state, struct layer_info *layer, const rectangle *cliprect) |
| 1507 | 1484 | { |
| 1508 | 1485 | bitmap_t *bitmap = layer->bitmap; |
| 1509 | 1486 | int x, y; |
| r10427 | r10428 | |
| 1514 | 1491 | int color; |
| 1515 | 1492 | |
| 1516 | 1493 | /* determine the color */ |
| 1517 | | if (system32_videoram[0x1ff5e/2] & 0x8000) |
| 1518 | | color = (system32_videoram[0x1ff5e/2] & 0x1fff) + y; |
| 1494 | if (state->system32_videoram[0x1ff5e/2] & 0x8000) |
| 1495 | color = (state->system32_videoram[0x1ff5e/2] & 0x1fff) + y; |
| 1519 | 1496 | else |
| 1520 | | color = system32_videoram[0x1ff5e/2] & 0x1e00; |
| 1497 | color = state->system32_videoram[0x1ff5e/2] & 0x1e00; |
| 1521 | 1498 | |
| 1522 | 1499 | /* if the color doesn't match, fill */ |
| 1523 | 1500 | if (dst[cliprect->min_x] != color) |
| r10427 | r10428 | |
| 1529 | 1506 | |
| 1530 | 1507 | static UINT8 update_tilemaps(screen_device &screen, const rectangle *cliprect) |
| 1531 | 1508 | { |
| 1532 | | int enable0 = !(system32_videoram[0x1ff02/2] & 0x0001) && !(system32_videoram[0x1ff8e/2] & 0x0002); |
| 1533 | | int enable1 = !(system32_videoram[0x1ff02/2] & 0x0002) && !(system32_videoram[0x1ff8e/2] & 0x0004); |
| 1534 | | int enable2 = !(system32_videoram[0x1ff02/2] & 0x0004) && !(system32_videoram[0x1ff8e/2] & 0x0008) && !(system32_videoram[0x1ff00/2] & 0x1000); |
| 1535 | | int enable3 = !(system32_videoram[0x1ff02/2] & 0x0008) && !(system32_videoram[0x1ff8e/2] & 0x0010) && !(system32_videoram[0x1ff00/2] & 0x2000); |
| 1536 | | int enablet = !(system32_videoram[0x1ff02/2] & 0x0010) && !(system32_videoram[0x1ff8e/2] & 0x0001); |
| 1537 | | int enableb = !(system32_videoram[0x1ff02/2] & 0x0020) && !(system32_videoram[0x1ff8e/2] & 0x0020); |
| 1509 | segas32_state *state = screen.machine->driver_data<segas32_state>(); |
| 1510 | int enable0 = !(state->system32_videoram[0x1ff02/2] & 0x0001) && !(state->system32_videoram[0x1ff8e/2] & 0x0002); |
| 1511 | int enable1 = !(state->system32_videoram[0x1ff02/2] & 0x0002) && !(state->system32_videoram[0x1ff8e/2] & 0x0004); |
| 1512 | int enable2 = !(state->system32_videoram[0x1ff02/2] & 0x0004) && !(state->system32_videoram[0x1ff8e/2] & 0x0008) && !(state->system32_videoram[0x1ff00/2] & 0x1000); |
| 1513 | int enable3 = !(state->system32_videoram[0x1ff02/2] & 0x0008) && !(state->system32_videoram[0x1ff8e/2] & 0x0010) && !(state->system32_videoram[0x1ff00/2] & 0x2000); |
| 1514 | int enablet = !(state->system32_videoram[0x1ff02/2] & 0x0010) && !(state->system32_videoram[0x1ff8e/2] & 0x0001); |
| 1515 | int enableb = !(state->system32_videoram[0x1ff02/2] & 0x0020) && !(state->system32_videoram[0x1ff8e/2] & 0x0020); |
| 1538 | 1516 | |
| 1539 | 1517 | /* update any tilemaps */ |
| 1540 | 1518 | if (enable0) |
| 1541 | | update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG0], cliprect, 0); |
| 1519 | update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG0], cliprect, 0); |
| 1542 | 1520 | if (enable1) |
| 1543 | | update_tilemap_zoom(screen, &layer_data[MIXER_LAYER_NBG1], cliprect, 1); |
| 1521 | update_tilemap_zoom(screen, &state->layer_data[MIXER_LAYER_NBG1], cliprect, 1); |
| 1544 | 1522 | if (enable2) |
| 1545 | | update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG2], cliprect, 2); |
| 1523 | update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG2], cliprect, 2); |
| 1546 | 1524 | if (enable3) |
| 1547 | | update_tilemap_rowscroll(screen, &layer_data[MIXER_LAYER_NBG3], cliprect, 3); |
| 1525 | update_tilemap_rowscroll(screen, &state->layer_data[MIXER_LAYER_NBG3], cliprect, 3); |
| 1548 | 1526 | if (enablet) |
| 1549 | | update_tilemap_text(screen, &layer_data[MIXER_LAYER_TEXT], cliprect); |
| 1527 | update_tilemap_text(screen, &state->layer_data[MIXER_LAYER_TEXT], cliprect); |
| 1550 | 1528 | if (enableb) |
| 1551 | | update_bitmap(screen, &layer_data[MIXER_LAYER_BITMAP], cliprect); |
| 1552 | | update_background(&layer_data[MIXER_LAYER_BACKGROUND], cliprect); |
| 1529 | update_bitmap(screen, &state->layer_data[MIXER_LAYER_BITMAP], cliprect); |
| 1530 | update_background(state, &state->layer_data[MIXER_LAYER_BACKGROUND], cliprect); |
| 1553 | 1531 | |
| 1554 | 1532 | return (enablet << 0) | (enable0 << 1) | (enable1 << 2) | (enable2 << 3) | (enable3 << 4) | (enableb << 5); |
| 1555 | 1533 | } |
| r10427 | r10428 | |
| 1562 | 1540 | * |
| 1563 | 1541 | *************************************/ |
| 1564 | 1542 | |
| 1565 | | static void sprite_erase_buffer(void) |
| 1543 | static void sprite_erase_buffer(segas32_state *state) |
| 1566 | 1544 | { |
| 1567 | 1545 | /* erase the visible sprite buffer and clear the checksums */ |
| 1568 | | bitmap_fill(layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff); |
| 1546 | bitmap_fill(state->layer_data[MIXER_LAYER_SPRITES].bitmap, NULL, 0xffff); |
| 1569 | 1547 | |
| 1570 | 1548 | /* for multi32, erase the other buffer as well */ |
| 1571 | | if (is_multi32) |
| 1572 | | bitmap_fill(layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff); |
| 1549 | if (state->is_multi32) |
| 1550 | bitmap_fill(state->layer_data[MIXER_LAYER_MULTISPR].bitmap, NULL, 0xffff); |
| 1573 | 1551 | } |
| 1574 | 1552 | |
| 1575 | 1553 | |
| 1576 | | static void sprite_swap_buffers(void) |
| 1554 | static void sprite_swap_buffers(segas32_state *state) |
| 1577 | 1555 | { |
| 1578 | 1556 | /* swap between the two sprite buffers */ |
| 1579 | 1557 | struct layer_info temp; |
| 1580 | | temp = layer_data[MIXER_LAYER_SPRITES]; |
| 1581 | | layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_SPRITES_2]; |
| 1582 | | layer_data[MIXER_LAYER_SPRITES_2] = temp; |
| 1558 | temp = state->layer_data[MIXER_LAYER_SPRITES]; |
| 1559 | state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_SPRITES_2]; |
| 1560 | state->layer_data[MIXER_LAYER_SPRITES_2] = temp; |
| 1583 | 1561 | |
| 1584 | 1562 | /* for multi32, swap the other buffer as well */ |
| 1585 | | if (is_multi32) |
| 1563 | if (state->is_multi32) |
| 1586 | 1564 | { |
| 1587 | | temp = layer_data[MIXER_LAYER_MULTISPR]; |
| 1588 | | layer_data[MIXER_LAYER_MULTISPR] = layer_data[MIXER_LAYER_MULTISPR_2]; |
| 1589 | | layer_data[MIXER_LAYER_MULTISPR_2] = temp; |
| 1565 | temp = state->layer_data[MIXER_LAYER_MULTISPR]; |
| 1566 | state->layer_data[MIXER_LAYER_MULTISPR] = state->layer_data[MIXER_LAYER_MULTISPR_2]; |
| 1567 | state->layer_data[MIXER_LAYER_MULTISPR_2] = temp; |
| 1590 | 1568 | } |
| 1591 | 1569 | |
| 1592 | 1570 | /* latch any pending info */ |
| 1593 | | memcpy(sprite_control_latched, sprite_control, sizeof(sprite_control_latched)); |
| 1571 | memcpy(state->sprite_control_latched, state->sprite_control, sizeof(state->sprite_control_latched)); |
| 1594 | 1572 | } |
| 1595 | 1573 | |
| 1596 | 1574 | |
| r10427 | r10428 | |
| 1693 | 1671 | |
| 1694 | 1672 | static int draw_one_sprite(running_machine *machine, UINT16 *data, int xoffs, int yoffs, const rectangle *clipin, const rectangle *clipout) |
| 1695 | 1673 | { |
| 1674 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 1696 | 1675 | static const int transparency_masks[4][4] = |
| 1697 | 1676 | { |
| 1698 | 1677 | { 0x7fff, 0x3fff, 0x1fff, 0x0fff }, |
| r10427 | r10428 | |
| 1701 | 1680 | { 0x1fff, 0x0fff, 0x07ff, 0x03ff } |
| 1702 | 1681 | }; |
| 1703 | 1682 | |
| 1704 | | bitmap_t *bitmap = layer_data[(!is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap; |
| 1683 | bitmap_t *bitmap = state->layer_data[(!state->is_multi32 || !(data[3] & 0x0800)) ? MIXER_LAYER_SPRITES_2 : MIXER_LAYER_MULTISPR_2].bitmap; |
| 1705 | 1684 | UINT8 numbanks = machine->region("gfx2")->bytes() / 0x400000; |
| 1706 | 1685 | const UINT32 *spritebase = (const UINT32 *)machine->region("gfx2")->base(); |
| 1707 | 1686 | |
| 1708 | 1687 | int indirect = data[0] & 0x2000; |
| 1709 | 1688 | int indlocal = data[0] & 0x1000; |
| 1710 | | int shadow = (data[0] & 0x0800) && (sprite_control_latched[0x0a/2] & 1); |
| 1689 | int shadow = (data[0] & 0x0800) && (state->sprite_control_latched[0x0a/2] & 1); |
| 1711 | 1690 | int fromram = data[0] & 0x0400; |
| 1712 | 1691 | int bpp8 = data[0] & 0x0200; |
| 1713 | 1692 | int transp = (data[0] & 0x0100) ? 0 : (bpp8 ? 0xff : 0x0f); |
| r10427 | r10428 | |
| 1719 | 1698 | int adjustx = (data[0] >> 0) & 3; |
| 1720 | 1699 | int srch = (data[1] >> 8); |
| 1721 | 1700 | int srcw = bpp8 ? (data[1] & 0x3f) : ((data[1] >> 1) & 0x3f); |
| 1722 | | int bank = is_multi32 ? |
| 1701 | int bank = state->is_multi32 ? |
| 1723 | 1702 | ((data[3] & 0x2000) >> 13) | ((data[3] & 0x8000) >> 14) : |
| 1724 | 1703 | ((data[3] & 0x0800) >> 11) | ((data[3] & 0x4000) >> 13); |
| 1725 | 1704 | int dsth = data[2] & 0x3ff; |
| r10427 | r10428 | |
| 1740 | 1719 | goto bail; |
| 1741 | 1720 | |
| 1742 | 1721 | /* determine the transparency mask for pixels */ |
| 1743 | | transmask = transparency_masks[sprite_control_latched[0x08/2] & 3][sprite_control_latched[0x0a/2] & 3]; |
| 1722 | transmask = transparency_masks[state->sprite_control_latched[0x08/2] & 3][state->sprite_control_latched[0x0a/2] & 3]; |
| 1744 | 1723 | if (bpp8) |
| 1745 | 1724 | transmask &= 0xfff0; |
| 1746 | 1725 | |
| 1747 | 1726 | /* create the local palette for the indirect case */ |
| 1748 | 1727 | if (indirect) |
| 1749 | 1728 | { |
| 1750 | | UINT16 *src = indlocal ? &data[8] : &system32_spriteram[8 * (data[7] & 0x1fff)]; |
| 1729 | UINT16 *src = indlocal ? &data[8] : &state->system32_spriteram[8 * (data[7] & 0x1fff)]; |
| 1751 | 1730 | for (x = 0; x < 16; x++) |
| 1752 | | indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000); |
| 1731 | indtable[x] = (src[x] & (bpp8 ? 0xfff0 : 0xffff)) | ((state->sprite_control_latched[0x0a/2] & 1) ? 0x8000 : 0x0000); |
| 1753 | 1732 | } |
| 1754 | 1733 | |
| 1755 | 1734 | /* clamp to within the memory region size */ |
| 1756 | 1735 | if (fromram) |
| 1757 | 1736 | { |
| 1758 | | spritedata = spriteram_32bit; |
| 1737 | spritedata = state->spriteram_32bit; |
| 1759 | 1738 | addrmask = (0x20000 / 4) - 1; |
| 1760 | 1739 | } |
| 1761 | 1740 | else |
| r10427 | r10428 | |
| 1894 | 1873 | |
| 1895 | 1874 | static void sprite_render_list(running_machine *machine) |
| 1896 | 1875 | { |
| 1876 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 1897 | 1877 | rectangle outerclip, clipin, clipout; |
| 1898 | 1878 | int xoffs = 0, yoffs = 0; |
| 1899 | 1879 | int numentries = 0; |
| r10427 | r10428 | |
| 1906 | 1886 | |
| 1907 | 1887 | /* compute the outer clip */ |
| 1908 | 1888 | outerclip.min_x = outerclip.min_y = 0; |
| 1909 | | outerclip.max_x = (sprite_control_latched[0x0c/2] & 1) ? 415 : 319; |
| 1889 | outerclip.max_x = (state->sprite_control_latched[0x0c/2] & 1) ? 415 : 319; |
| 1910 | 1890 | outerclip.max_y = 223; |
| 1911 | 1891 | |
| 1912 | 1892 | /* initialize the cliprects */ |
| r10427 | r10428 | |
| 1918 | 1898 | while (numentries++ < 0x20000/16) |
| 1919 | 1899 | { |
| 1920 | 1900 | /* top two bits are a command */ |
| 1921 | | sprite = &system32_spriteram[8 * (spritenum & 0x1fff)]; |
| 1901 | sprite = &state->system32_spriteram[8 * (spritenum & 0x1fff)]; |
| 1922 | 1902 | switch (sprite[0] >> 14) |
| 1923 | 1903 | { |
| 1924 | 1904 | /* command 0 = draw sprite */ |
| r10427 | r10428 | |
| 1982 | 1962 | * |
| 1983 | 1963 | *************************************/ |
| 1984 | 1964 | |
| 1985 | | INLINE UINT8 compute_color_offsets(int which, int layerbit, int layerflag) |
| 1965 | INLINE UINT8 compute_color_offsets(segas32_state *state,int which, int layerbit, int layerflag) |
| 1986 | 1966 | { |
| 1987 | | int mode = ((mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1); |
| 1967 | int mode = ((state->mixer_control[which][0x3e/2] & 0x8000) >> 14) | (layerbit & 1); |
| 1988 | 1968 | |
| 1989 | 1969 | switch (mode) |
| 1990 | 1970 | { |
| r10427 | r10428 | |
| 2023 | 2003 | } |
| 2024 | 2004 | } |
| 2025 | 2005 | |
| 2026 | | INLINE UINT16 *get_layer_scanline(int layer, int scanline) |
| 2006 | INLINE UINT16 *get_layer_scanline(segas32_state *state, int layer, int scanline) |
| 2027 | 2007 | { |
| 2028 | | if (layer_data[layer].transparent[scanline]) |
| 2029 | | return (layer == MIXER_LAYER_SPRITES) ? solid_ffff : solid_0000; |
| 2030 | | return BITMAP_ADDR16(layer_data[layer].bitmap, scanline, 0); |
| 2008 | if (state->layer_data[layer].transparent[scanline]) |
| 2009 | return (layer == MIXER_LAYER_SPRITES) ? state->solid_ffff : state->solid_0000; |
| 2010 | return BITMAP_ADDR16(state->layer_data[layer].bitmap, scanline, 0); |
| 2031 | 2011 | } |
| 2032 | 2012 | |
| 2033 | | static void mix_all_layers(int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask) |
| 2013 | static void mix_all_layers(segas32_state *state, int which, int xoffs, bitmap_t *bitmap, const rectangle *cliprect, UINT8 enablemask) |
| 2034 | 2014 | { |
| 2035 | | int blendenable = mixer_control[which][0x4e/2] & 0x0800; |
| 2036 | | int blendfactor = (mixer_control[which][0x4e/2] >> 8) & 7; |
| 2015 | int blendenable = state->mixer_control[which][0x4e/2] & 0x0800; |
| 2016 | int blendfactor = (state->mixer_control[which][0x4e/2] >> 8) & 7; |
| 2037 | 2017 | struct mixer_layer_info |
| 2038 | 2018 | { |
| 2039 | 2019 | UINT16 palbase; /* palette base from control reg */ |
| r10427 | r10428 | |
| 2057 | 2037 | /* if we are the second monitor on multi32, swap in the proper sprite bank */ |
| 2058 | 2038 | if (which == 1) |
| 2059 | 2039 | { |
| 2060 | | temp_sprite_save = layer_data[MIXER_LAYER_SPRITES]; |
| 2061 | | layer_data[MIXER_LAYER_SPRITES] = layer_data[MIXER_LAYER_MULTISPR]; |
| 2040 | temp_sprite_save = state->layer_data[MIXER_LAYER_SPRITES]; |
| 2041 | state->layer_data[MIXER_LAYER_SPRITES] = state->layer_data[MIXER_LAYER_MULTISPR]; |
| 2062 | 2042 | } |
| 2063 | 2043 | |
| 2064 | 2044 | /* extract the RGB offsets */ |
| 2065 | | rgboffs[0][0] = (INT8)(mixer_control[which][0x40/2] << 2) >> 2; |
| 2066 | | rgboffs[0][1] = (INT8)(mixer_control[which][0x42/2] << 2) >> 2; |
| 2067 | | rgboffs[0][2] = (INT8)(mixer_control[which][0x44/2] << 2) >> 2; |
| 2068 | | rgboffs[1][0] = (INT8)(mixer_control[which][0x46/2] << 2) >> 2; |
| 2069 | | rgboffs[1][1] = (INT8)(mixer_control[which][0x48/2] << 2) >> 2; |
| 2070 | | rgboffs[1][2] = (INT8)(mixer_control[which][0x4a/2] << 2) >> 2; |
| 2045 | rgboffs[0][0] = (INT8)(state->mixer_control[which][0x40/2] << 2) >> 2; |
| 2046 | rgboffs[0][1] = (INT8)(state->mixer_control[which][0x42/2] << 2) >> 2; |
| 2047 | rgboffs[0][2] = (INT8)(state->mixer_control[which][0x44/2] << 2) >> 2; |
| 2048 | rgboffs[1][0] = (INT8)(state->mixer_control[which][0x46/2] << 2) >> 2; |
| 2049 | rgboffs[1][1] = (INT8)(state->mixer_control[which][0x48/2] << 2) >> 2; |
| 2050 | rgboffs[1][2] = (INT8)(state->mixer_control[which][0x4a/2] << 2) >> 2; |
| 2071 | 2051 | rgboffs[2][0] = 0; |
| 2072 | 2052 | rgboffs[2][1] = 0; |
| 2073 | 2053 | rgboffs[2][2] = 0; |
| 2074 | 2054 | |
| 2075 | 2055 | /* determine the sprite grouping parameters first */ |
| 2076 | | switch (mixer_control[which][0x4c/2] & 0x0f) |
| 2056 | switch (state->mixer_control[which][0x4c/2] & 0x0f) |
| 2077 | 2057 | { |
| 2078 | 2058 | default: |
| 2079 | 2059 | case 0x0: sprgroup_shift = 14; sprgroup_mask = 0x00; sprgroup_or = 0x01; break; |
| r10427 | r10428 | |
| 2096 | 2076 | case 0xe: sprgroup_shift = 11; sprgroup_mask = 0x07; sprgroup_or = 0x00; break; |
| 2097 | 2077 | case 0xf: sprgroup_shift = 10; sprgroup_mask = 0x0f; sprgroup_or = 0x00; break; |
| 2098 | 2078 | } |
| 2099 | | sprshadowmask = (mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000; |
| 2079 | sprshadowmask = (state->mixer_control[which][0x4c/2] & 0x04) ? 0x8000 : 0x0000; |
| 2100 | 2080 | sprpixmask = ((1 << sprgroup_shift) - 1) & 0x3fff; |
| 2101 | 2081 | sprshadow = 0x7ffe & sprpixmask; |
| 2102 | 2082 | |
| r10427 | r10428 | |
| 2104 | 2084 | numlayers = 0; |
| 2105 | 2085 | for (laynum = MIXER_LAYER_TEXT; laynum <= MIXER_LAYER_BITMAP; laynum++) |
| 2106 | 2086 | { |
| 2107 | | int priority = mixer_control[which][0x20/2 + laynum] & 0x0f; |
| 2087 | int priority = state->mixer_control[which][0x20/2 + laynum] & 0x0f; |
| 2108 | 2088 | if ((enablemask & (1 << laynum)) && priority != 0) |
| 2109 | 2089 | { |
| 2110 | 2090 | layersort[numlayers].index = laynum; |
| 2111 | 2091 | layersort[numlayers].effpri = (priority << 3) | (6 - laynum); |
| 2112 | | layersort[numlayers].palbase = (mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6; |
| 2113 | | layersort[numlayers].mixshift = (mixer_control[which][0x20/2 + laynum] >> 8) & 3; |
| 2114 | | layersort[numlayers].blendmask = blendenable ? ((mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0; |
| 2115 | | layersort[numlayers].sprblendmask = compute_sprite_blend(mixer_control[which][0x30/2 + laynum] & 0x3f); |
| 2116 | | layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> laynum) & 1, (mixer_control[which][0x30/2 + laynum] >> 14) & 1); |
| 2092 | layersort[numlayers].palbase = (state->mixer_control[which][0x20/2 + laynum] & 0x00f0) << 6; |
| 2093 | layersort[numlayers].mixshift = (state->mixer_control[which][0x20/2 + laynum] >> 8) & 3; |
| 2094 | layersort[numlayers].blendmask = blendenable ? ((state->mixer_control[which][0x30/2 + laynum] >> 6) & 0xff) : 0; |
| 2095 | layersort[numlayers].sprblendmask = compute_sprite_blend(state->mixer_control[which][0x30/2 + laynum] & 0x3f); |
| 2096 | layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> laynum) & 1, (state->mixer_control[which][0x30/2 + laynum] >> 14) & 1); |
| 2117 | 2097 | numlayers++; |
| 2118 | 2098 | } |
| 2119 | 2099 | } |
| r10427 | r10428 | |
| 2121 | 2101 | /* extract info about the BACKGROUND layer */ |
| 2122 | 2102 | layersort[numlayers].index = MIXER_LAYER_BACKGROUND; |
| 2123 | 2103 | layersort[numlayers].effpri = (1 << 3) | 0; |
| 2124 | | layersort[numlayers].palbase = (mixer_control[which][0x2c/2] & 0x00f0) << 6; |
| 2125 | | layersort[numlayers].mixshift = (mixer_control[which][0x2c/2] >> 8) & 3; |
| 2104 | layersort[numlayers].palbase = (state->mixer_control[which][0x2c/2] & 0x00f0) << 6; |
| 2105 | layersort[numlayers].mixshift = (state->mixer_control[which][0x2c/2] >> 8) & 3; |
| 2126 | 2106 | layersort[numlayers].blendmask = 0; |
| 2127 | 2107 | layersort[numlayers].sprblendmask = 0; |
| 2128 | | layersort[numlayers].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 8) & 1, (mixer_control[which][0x3e/2] >> 14) & 1); |
| 2108 | layersort[numlayers].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 8) & 1, (state->mixer_control[which][0x3e/2] >> 14) & 1); |
| 2129 | 2109 | numlayers++; |
| 2130 | 2110 | |
| 2131 | 2111 | /* now bubble sort the list by effective priority */ |
| r10427 | r10428 | |
| 2142 | 2122 | for (groupnum = 0; groupnum <= sprgroup_mask; groupnum++) |
| 2143 | 2123 | { |
| 2144 | 2124 | int effgroup = sprgroup_or | groupnum; |
| 2145 | | int priority = mixer_control[which][0x00/2 + effgroup] & 0x0f; |
| 2125 | int priority = state->mixer_control[which][0x00/2 + effgroup] & 0x0f; |
| 2146 | 2126 | int effpri = (priority << 3) | 7; |
| 2147 | 2127 | int sprindex = numlayers; |
| 2148 | 2128 | int dstnum = 0; |
| r10427 | r10428 | |
| 2158 | 2138 | /* build the sprite entry */ |
| 2159 | 2139 | layerorder[groupnum][sprindex].index = MIXER_LAYER_SPRITES; |
| 2160 | 2140 | layerorder[groupnum][sprindex].effpri = effpri; |
| 2161 | | if ((mixer_control[which][0x4c/2] & 3) != 3) |
| 2162 | | layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6; |
| 2141 | if ((state->mixer_control[which][0x4c/2] & 3) != 3) |
| 2142 | layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x00/2 + effgroup] & 0x00f0) << 6; |
| 2163 | 2143 | else |
| 2164 | | layerorder[groupnum][sprindex].palbase = (mixer_control[which][0x4c/2] & 0x00f0) << 6; |
| 2165 | | layerorder[groupnum][sprindex].mixshift = (mixer_control[which][0x00/2 + effgroup] >> 8) & 3; |
| 2144 | layerorder[groupnum][sprindex].palbase = (state->mixer_control[which][0x4c/2] & 0x00f0) << 6; |
| 2145 | layerorder[groupnum][sprindex].mixshift = (state->mixer_control[which][0x00/2 + effgroup] >> 8) & 3; |
| 2166 | 2146 | layerorder[groupnum][sprindex].blendmask = 0; |
| 2167 | 2147 | layerorder[groupnum][sprindex].sprblendmask = 0; |
| 2168 | | layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(which, (mixer_control[which][0x3e/2] >> 6) & 1, (mixer_control[which][0x4c/2] >> 15) & 1); |
| 2148 | layerorder[groupnum][sprindex].coloroffs = compute_color_offsets(state, which, (state->mixer_control[which][0x3e/2] >> 6) & 1, (state->mixer_control[which][0x4c/2] >> 15) & 1); |
| 2169 | 2149 | } |
| 2170 | 2150 | /* |
| 2171 | 2151 | { |
| r10427 | r10428 | |
| 2181 | 2161 | |
| 2182 | 2162 | /* based on the sprite controller flip bits, the data is scanned to us in different */ |
| 2183 | 2163 | /* directions; account for this */ |
| 2184 | | if (sprite_control_latched[0x04/2] & 1) |
| 2164 | if (state->sprite_control_latched[0x04/2] & 1) |
| 2185 | 2165 | { |
| 2186 | 2166 | sprx_start = cliprect->max_x; |
| 2187 | 2167 | sprdx = -1; |
| r10427 | r10428 | |
| 2192 | 2172 | sprdx = 1; |
| 2193 | 2173 | } |
| 2194 | 2174 | |
| 2195 | | if (sprite_control_latched[0x04/2] & 2) |
| 2175 | if (state->sprite_control_latched[0x04/2] & 2) |
| 2196 | 2176 | { |
| 2197 | 2177 | spry = cliprect->max_y; |
| 2198 | 2178 | sprdy = -1; |
| r10427 | r10428 | |
| 2210 | 2190 | UINT16 *layerbase[8]; |
| 2211 | 2191 | |
| 2212 | 2192 | /* get the starting address for each layer */ |
| 2213 | | layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(MIXER_LAYER_TEXT, y); |
| 2214 | | layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(MIXER_LAYER_NBG0, y); |
| 2215 | | layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(MIXER_LAYER_NBG1, y); |
| 2216 | | layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(MIXER_LAYER_NBG2, y); |
| 2217 | | layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(MIXER_LAYER_NBG3, y); |
| 2218 | | layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(MIXER_LAYER_BITMAP, y); |
| 2219 | | layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(MIXER_LAYER_SPRITES, spry); |
| 2220 | | layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(MIXER_LAYER_BACKGROUND, y); |
| 2193 | layerbase[MIXER_LAYER_TEXT] = get_layer_scanline(state, MIXER_LAYER_TEXT, y); |
| 2194 | layerbase[MIXER_LAYER_NBG0] = get_layer_scanline(state, MIXER_LAYER_NBG0, y); |
| 2195 | layerbase[MIXER_LAYER_NBG1] = get_layer_scanline(state, MIXER_LAYER_NBG1, y); |
| 2196 | layerbase[MIXER_LAYER_NBG2] = get_layer_scanline(state, MIXER_LAYER_NBG2, y); |
| 2197 | layerbase[MIXER_LAYER_NBG3] = get_layer_scanline(state, MIXER_LAYER_NBG3, y); |
| 2198 | layerbase[MIXER_LAYER_BITMAP] = get_layer_scanline(state, MIXER_LAYER_BITMAP, y); |
| 2199 | layerbase[MIXER_LAYER_SPRITES] = get_layer_scanline(state, MIXER_LAYER_SPRITES, spry); |
| 2200 | layerbase[MIXER_LAYER_BACKGROUND] = get_layer_scanline(state, MIXER_LAYER_BACKGROUND, y); |
| 2221 | 2201 | |
| 2222 | 2202 | /* loop over columns */ |
| 2223 | 2203 | for (x = cliprect->min_x, sprx = sprx_start; x <= cliprect->max_x; x++, sprx += sprdx) |
| r10427 | r10428 | |
| 2262 | 2242 | } |
| 2263 | 2243 | |
| 2264 | 2244 | /* adjust the first pixel */ |
| 2265 | | firstpix = system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff]; |
| 2245 | firstpix = state->system32_paletteram[which][(first->palbase + ((firstpix >> first->mixshift) & 0xfff0) + (firstpix & 0x0f)) & 0x3fff]; |
| 2266 | 2246 | |
| 2267 | 2247 | /* compute R, G, B */ |
| 2268 | 2248 | rgbdelta = &rgboffs[first->coloroffs][0]; |
| r10427 | r10428 | |
| 2309 | 2289 | (laynum != MIXER_LAYER_SPRITES || (first->sprblendmask & (1 << sprgroup)))) |
| 2310 | 2290 | { |
| 2311 | 2291 | /* adjust the second pixel */ |
| 2312 | | secondpix = system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff]; |
| 2292 | secondpix = state->system32_paletteram[which][(second->palbase + ((secondpix >> second->mixshift) & 0xfff0) + (secondpix & 0x0f)) & 0x3fff]; |
| 2313 | 2293 | |
| 2314 | 2294 | /* compute first RGB */ |
| 2315 | 2295 | r *= 7 - blendfactor; |
| r10427 | r10428 | |
| 2360 | 2340 | |
| 2361 | 2341 | /* if we are the second monitor on multi32, swap back the sprite layer */ |
| 2362 | 2342 | if (which == 1) |
| 2363 | | layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save; |
| 2343 | state->layer_data[MIXER_LAYER_SPRITES] = temp_sprite_save; |
| 2364 | 2344 | } |
| 2365 | 2345 | |
| 2366 | 2346 | |
| r10427 | r10428 | |
| 2371 | 2351 | * |
| 2372 | 2352 | *************************************/ |
| 2373 | 2353 | |
| 2374 | | static void print_mixer_data(int which) |
| 2354 | static void print_mixer_data(segas32_state *state, int which) |
| 2375 | 2355 | { |
| 2376 | 2356 | static int count = 0; |
| 2377 | 2357 | if (++count > 60 * 5) |
| 2378 | 2358 | { |
| 2379 | 2359 | mame_printf_debug("\n"); |
| 2380 | | mame_printf_debug("OP: %04X\n", system32_videoram[0x1ff8e/2]); |
| 2360 | mame_printf_debug("OP: %04X\n", state->system32_videoram[0x1ff8e/2]); |
| 2381 | 2361 | mame_printf_debug("SC: %04X %04X %04X %04X - %04X %04X %04X %04X\n", |
| 2382 | | sprite_control_latched[0x00], |
| 2383 | | sprite_control_latched[0x01], |
| 2384 | | sprite_control_latched[0x02], |
| 2385 | | sprite_control_latched[0x03], |
| 2386 | | sprite_control_latched[0x04], |
| 2387 | | sprite_control_latched[0x05], |
| 2388 | | sprite_control_latched[0x06], |
| 2389 | | sprite_control_latched[0x07]); |
| 2362 | state->sprite_control_latched[0x00], |
| 2363 | state->sprite_control_latched[0x01], |
| 2364 | state->sprite_control_latched[0x02], |
| 2365 | state->sprite_control_latched[0x03], |
| 2366 | state->sprite_control_latched[0x04], |
| 2367 | state->sprite_control_latched[0x05], |
| 2368 | state->sprite_control_latched[0x06], |
| 2369 | state->sprite_control_latched[0x07]); |
| 2390 | 2370 | mame_printf_debug("00: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", |
| 2391 | | mixer_control[which][0x00], |
| 2392 | | mixer_control[which][0x01], |
| 2393 | | mixer_control[which][0x02], |
| 2394 | | mixer_control[which][0x03], |
| 2395 | | mixer_control[which][0x04], |
| 2396 | | mixer_control[which][0x05], |
| 2397 | | mixer_control[which][0x06], |
| 2398 | | mixer_control[which][0x07], |
| 2399 | | mixer_control[which][0x08], |
| 2400 | | mixer_control[which][0x09], |
| 2401 | | mixer_control[which][0x0a], |
| 2402 | | mixer_control[which][0x0b], |
| 2403 | | mixer_control[which][0x0c], |
| 2404 | | mixer_control[which][0x0d], |
| 2405 | | mixer_control[which][0x0e], |
| 2406 | | mixer_control[which][0x0f]); |
| 2371 | state->mixer_control[which][0x00], |
| 2372 | state->mixer_control[which][0x01], |
| 2373 | state->mixer_control[which][0x02], |
| 2374 | state->mixer_control[which][0x03], |
| 2375 | state->mixer_control[which][0x04], |
| 2376 | state->mixer_control[which][0x05], |
| 2377 | state->mixer_control[which][0x06], |
| 2378 | state->mixer_control[which][0x07], |
| 2379 | state->mixer_control[which][0x08], |
| 2380 | state->mixer_control[which][0x09], |
| 2381 | state->mixer_control[which][0x0a], |
| 2382 | state->mixer_control[which][0x0b], |
| 2383 | state->mixer_control[which][0x0c], |
| 2384 | state->mixer_control[which][0x0d], |
| 2385 | state->mixer_control[which][0x0e], |
| 2386 | state->mixer_control[which][0x0f]); |
| 2407 | 2387 | mame_printf_debug("20: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", |
| 2408 | | mixer_control[which][0x10], |
| 2409 | | mixer_control[which][0x11], |
| 2410 | | mixer_control[which][0x12], |
| 2411 | | mixer_control[which][0x13], |
| 2412 | | mixer_control[which][0x14], |
| 2413 | | mixer_control[which][0x15], |
| 2414 | | mixer_control[which][0x16], |
| 2415 | | mixer_control[which][0x17], |
| 2416 | | mixer_control[which][0x18], |
| 2417 | | mixer_control[which][0x19], |
| 2418 | | mixer_control[which][0x1a], |
| 2419 | | mixer_control[which][0x1b], |
| 2420 | | mixer_control[which][0x1c], |
| 2421 | | mixer_control[which][0x1d], |
| 2422 | | mixer_control[which][0x1e], |
| 2423 | | mixer_control[which][0x1f]); |
| 2388 | state->mixer_control[which][0x10], |
| 2389 | state->mixer_control[which][0x11], |
| 2390 | state->mixer_control[which][0x12], |
| 2391 | state->mixer_control[which][0x13], |
| 2392 | state->mixer_control[which][0x14], |
| 2393 | state->mixer_control[which][0x15], |
| 2394 | state->mixer_control[which][0x16], |
| 2395 | state->mixer_control[which][0x17], |
| 2396 | state->mixer_control[which][0x18], |
| 2397 | state->mixer_control[which][0x19], |
| 2398 | state->mixer_control[which][0x1a], |
| 2399 | state->mixer_control[which][0x1b], |
| 2400 | state->mixer_control[which][0x1c], |
| 2401 | state->mixer_control[which][0x1d], |
| 2402 | state->mixer_control[which][0x1e], |
| 2403 | state->mixer_control[which][0x1f]); |
| 2424 | 2404 | mame_printf_debug("40: %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X - %04X %04X %04X %04X\n", |
| 2425 | | mixer_control[which][0x20], |
| 2426 | | mixer_control[which][0x21], |
| 2427 | | mixer_control[which][0x22], |
| 2428 | | mixer_control[which][0x23], |
| 2429 | | mixer_control[which][0x24], |
| 2430 | | mixer_control[which][0x25], |
| 2431 | | mixer_control[which][0x26], |
| 2432 | | mixer_control[which][0x27], |
| 2433 | | mixer_control[which][0x28], |
| 2434 | | mixer_control[which][0x29], |
| 2435 | | mixer_control[which][0x2a], |
| 2436 | | mixer_control[which][0x2b], |
| 2437 | | mixer_control[which][0x2c], |
| 2438 | | mixer_control[which][0x2d], |
| 2439 | | mixer_control[which][0x2e], |
| 2440 | | mixer_control[which][0x2f]); |
| 2405 | state->mixer_control[which][0x20], |
| 2406 | state->mixer_control[which][0x21], |
| 2407 | state->mixer_control[which][0x22], |
| 2408 | state->mixer_control[which][0x23], |
| 2409 | state->mixer_control[which][0x24], |
| 2410 | state->mixer_control[which][0x25], |
| 2411 | state->mixer_control[which][0x26], |
| 2412 | state->mixer_control[which][0x27], |
| 2413 | state->mixer_control[which][0x28], |
| 2414 | state->mixer_control[which][0x29], |
| 2415 | state->mixer_control[which][0x2a], |
| 2416 | state->mixer_control[which][0x2b], |
| 2417 | state->mixer_control[which][0x2c], |
| 2418 | state->mixer_control[which][0x2d], |
| 2419 | state->mixer_control[which][0x2e], |
| 2420 | state->mixer_control[which][0x2f]); |
| 2441 | 2421 | count = 0; |
| 2442 | 2422 | } |
| 2443 | 2423 | } |
| 2444 | 2424 | |
| 2445 | 2425 | VIDEO_UPDATE( system32 ) |
| 2446 | 2426 | { |
| 2427 | segas32_state *state = screen->machine->driver_data<segas32_state>(); |
| 2447 | 2428 | UINT8 enablemask; |
| 2448 | 2429 | |
| 2449 | 2430 | /* update the visible area */ |
| 2450 | | if (system32_videoram[0x1ff00/2] & 0x8000) |
| 2431 | if (state->system32_videoram[0x1ff00/2] & 0x8000) |
| 2451 | 2432 | screen->set_visible_area(0, 52*8-1, 0, 28*8-1); |
| 2452 | 2433 | else |
| 2453 | 2434 | screen->set_visible_area(0, 40*8-1, 0, 28*8-1); |
| 2454 | 2435 | |
| 2455 | 2436 | /* if the display is off, punt */ |
| 2456 | | if (!system32_displayenable[0]) |
| 2437 | if (!state->system32_displayenable[0]) |
| 2457 | 2438 | { |
| 2458 | 2439 | bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); |
| 2459 | 2440 | return 0; |
| r10427 | r10428 | |
| 2476 | 2457 | |
| 2477 | 2458 | /* do the mixing */ |
| 2478 | 2459 | g_profiler.start(PROFILER_USER3); |
| 2479 | | mix_all_layers(0, 0, bitmap, cliprect, enablemask); |
| 2460 | mix_all_layers(state, 0, 0, bitmap, cliprect, enablemask); |
| 2480 | 2461 | g_profiler.stop(); |
| 2481 | 2462 | |
| 2482 | 2463 | if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L)) |
| r10427 | r10428 | |
| 2487 | 2468 | |
| 2488 | 2469 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2489 | 2470 | { |
| 2490 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y); |
| 2471 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y); |
| 2491 | 2472 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2492 | 2473 | fprintf(f, "%04X ", *src++); |
| 2493 | 2474 | fprintf(f, "\n"); |
| r10427 | r10428 | |
| 2497 | 2478 | f = fopen("nbg0.txt", "w"); |
| 2498 | 2479 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2499 | 2480 | { |
| 2500 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG0, y); |
| 2481 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG0, y); |
| 2501 | 2482 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2502 | 2483 | fprintf(f, "%04X ", *src++); |
| 2503 | 2484 | fprintf(f, "\n"); |
| r10427 | r10428 | |
| 2507 | 2488 | f = fopen("nbg1.txt", "w"); |
| 2508 | 2489 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2509 | 2490 | { |
| 2510 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG1, y); |
| 2491 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG1, y); |
| 2511 | 2492 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2512 | 2493 | fprintf(f, "%04X ", *src++); |
| 2513 | 2494 | fprintf(f, "\n"); |
| r10427 | r10428 | |
| 2517 | 2498 | f = fopen("nbg2.txt", "w"); |
| 2518 | 2499 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2519 | 2500 | { |
| 2520 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG2, y); |
| 2501 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG2, y); |
| 2521 | 2502 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2522 | 2503 | fprintf(f, "%04X ", *src++); |
| 2523 | 2504 | fprintf(f, "\n"); |
| r10427 | r10428 | |
| 2527 | 2508 | f = fopen("nbg3.txt", "w"); |
| 2528 | 2509 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2529 | 2510 | { |
| 2530 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_NBG3, y); |
| 2511 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_NBG3, y); |
| 2531 | 2512 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2532 | 2513 | fprintf(f, "%04X ", *src++); |
| 2533 | 2514 | fprintf(f, "\n"); |
| r10427 | r10428 | |
| 2540 | 2521 | static const char *const layername[] = { "TEXT ", "NBG0 ", "NBG1 ", "NBG2 ", "NBG3 ", "BITMAP " }; |
| 2541 | 2522 | char temp[100]; |
| 2542 | 2523 | int count = 0, i; |
| 2543 | | sprintf(temp, "ALPHA(%d):", (mixer_control[which][0x4e/2] >> 8) & 7); |
| 2524 | sprintf(temp, "ALPHA(%d):", (state->mixer_control[which][0x4e/2] >> 8) & 7); |
| 2544 | 2525 | for (i = 0; i < 6; i++) |
| 2545 | 2526 | if (enablemask & (1 << i)) |
| 2546 | | if ((mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010) |
| 2527 | if ((state->mixer_control[which][0x30/2 + i] & 0x1010) == 0x1010) |
| 2547 | 2528 | { |
| 2548 | 2529 | count++; |
| 2549 | 2530 | strcat(temp, layername[i]); |
| r10427 | r10428 | |
| 2568 | 2549 | // if (showclip != -1) |
| 2569 | 2550 | for (showclip = 0; showclip < 4; showclip++) |
| 2570 | 2551 | { |
| 2571 | | int flip = (system32_videoram[0x1ff00/2] >> 9) & 1; |
| 2572 | | int clips = (system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f; |
| 2573 | | if (((system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips) |
| 2552 | int flip = (state->system32_videoram[0x1ff00/2] >> 9) & 1; |
| 2553 | int clips = (state->system32_videoram[0x1ff06/2] >> (4 * showclip)) & 0x0f; |
| 2554 | if (((state->system32_videoram[0x1ff02/2] >> (11 + showclip)) & 1) && clips) |
| 2574 | 2555 | { |
| 2575 | 2556 | int i, x, y; |
| 2576 | 2557 | for (i = 0; i < 4; i++) |
| r10427 | r10428 | |
| 2582 | 2563 | pen_t white = get_white_pen(screen->machine); |
| 2583 | 2564 | if (!flip) |
| 2584 | 2565 | { |
| 2585 | | rect.min_x = system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; |
| 2586 | | rect.min_y = system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; |
| 2587 | | rect.max_x = (system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; |
| 2588 | | rect.max_y = (system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; |
| 2566 | rect.min_x = state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff; |
| 2567 | rect.min_y = state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff; |
| 2568 | rect.max_x = (state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1; |
| 2569 | rect.max_y = (state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1; |
| 2589 | 2570 | } |
| 2590 | 2571 | else |
| 2591 | 2572 | { |
| 2592 | | rect.max_x = (visarea.max_x + 1) - (system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); |
| 2593 | | rect.max_y = (visarea.max_y + 1) - (system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); |
| 2594 | | rect.min_x = (visarea.max_x + 1) - ((system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); |
| 2595 | | rect.min_y = (visarea.max_y + 1) - ((system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); |
| 2573 | rect.max_x = (visarea.max_x + 1) - (state->system32_videoram[0x1ff60/2 + i * 4] & 0x1ff); |
| 2574 | rect.max_y = (visarea.max_y + 1) - (state->system32_videoram[0x1ff62/2 + i * 4] & 0x0ff); |
| 2575 | rect.min_x = (visarea.max_x + 1) - ((state->system32_videoram[0x1ff64/2 + i * 4] & 0x1ff) + 1); |
| 2576 | rect.min_y = (visarea.max_y + 1) - ((state->system32_videoram[0x1ff66/2 + i * 4] & 0x0ff) + 1); |
| 2596 | 2577 | } |
| 2597 | 2578 | sect_rect(&rect, &screen->visible_area()); |
| 2598 | 2579 | |
| r10427 | r10428 | |
| 2615 | 2596 | } |
| 2616 | 2597 | #endif |
| 2617 | 2598 | |
| 2618 | | if (PRINTF_MIXER_DATA) print_mixer_data(0); |
| 2599 | if (PRINTF_MIXER_DATA) print_mixer_data(state, 0); |
| 2619 | 2600 | return 0; |
| 2620 | 2601 | } |
| 2621 | 2602 | |
| 2622 | 2603 | |
| 2623 | 2604 | VIDEO_UPDATE( multi32 ) |
| 2624 | 2605 | { |
| 2606 | segas32_state *state = screen->machine->driver_data<segas32_state>(); |
| 2625 | 2607 | UINT8 enablemask; |
| 2626 | 2608 | |
| 2627 | 2609 | device_t *left_screen = screen->machine->device("lscreen"); |
| 2628 | 2610 | |
| 2629 | 2611 | /* update the visible area */ |
| 2630 | | if (system32_videoram[0x1ff00/2] & 0x8000) |
| 2612 | if (state->system32_videoram[0x1ff00/2] & 0x8000) |
| 2631 | 2613 | screen->set_visible_area(0, 52*8-1, 0, 28*8-1); |
| 2632 | 2614 | else |
| 2633 | 2615 | screen->set_visible_area(0, 40*8-1, 0, 28*8-1); |
| 2634 | 2616 | |
| 2635 | 2617 | /* if the display is off, punt */ |
| 2636 | | if (!system32_displayenable[(screen == left_screen) ? 0 : 1]) |
| 2618 | if (!state->system32_displayenable[(screen == left_screen) ? 0 : 1]) |
| 2637 | 2619 | { |
| 2638 | 2620 | bitmap_fill(bitmap, cliprect, get_black_pen(screen->machine)); |
| 2639 | 2621 | return 0; |
| r10427 | r10428 | |
| 2656 | 2638 | |
| 2657 | 2639 | /* do the mixing */ |
| 2658 | 2640 | g_profiler.start(PROFILER_USER3); |
| 2659 | | mix_all_layers(((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask); |
| 2641 | mix_all_layers(state, ((screen == left_screen) ? 0 : 1), 0, bitmap, cliprect, enablemask); |
| 2660 | 2642 | g_profiler.stop(); |
| 2661 | 2643 | |
| 2662 | 2644 | if (PRINTF_MIXER_DATA) |
| 2663 | 2645 | { |
| 2664 | | if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(0); |
| 2665 | | else print_mixer_data(1); |
| 2646 | if (!input_code_pressed(screen->machine, KEYCODE_M)) print_mixer_data(state, 0); |
| 2647 | else print_mixer_data(state, 1); |
| 2666 | 2648 | } |
| 2667 | 2649 | if (LOG_SPRITES && input_code_pressed(screen->machine, KEYCODE_L)) |
| 2668 | 2650 | { |
| r10427 | r10428 | |
| 2672 | 2654 | |
| 2673 | 2655 | for (y = visarea.min_y; y <= visarea.max_y; y++) |
| 2674 | 2656 | { |
| 2675 | | UINT16 *src = get_layer_scanline(MIXER_LAYER_SPRITES, y); |
| 2657 | UINT16 *src = get_layer_scanline(state, MIXER_LAYER_SPRITES, y); |
| 2676 | 2658 | for (x = visarea.min_x; x <= visarea.max_x; x++) |
| 2677 | 2659 | fprintf(f, "%04X ", *src++); |
| 2678 | 2660 | fprintf(f, "\n"); |
src/mame/drivers/deco32.c
| r10427 | r10428 | |
| 237 | 237 | #include "sound/okim6295.h" |
| 238 | 238 | #include "sound/bsmt2000.h" |
| 239 | 239 | |
| 240 | | static UINT32 *deco32_ram; |
| 241 | | static int raster_enable; |
| 242 | | static timer_device *raster_irq_timer; |
| 243 | | static UINT8 nslasher_sound_irq; |
| 244 | 240 | |
| 245 | 241 | /**********************************************************************************/ |
| 246 | 242 | |
| 247 | 243 | |
| 248 | 244 | static WRITE32_HANDLER( deco32_pf12_control_w ) |
| 249 | 245 | { |
| 250 | | COMBINE_DATA(&deco32_pf12_control[offset]); |
| 246 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 247 | COMBINE_DATA(&state->pf12_control[offset]); |
| 251 | 248 | space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos()); |
| 252 | 249 | } |
| 253 | 250 | |
| 254 | 251 | |
| 255 | 252 | static WRITE32_HANDLER( deco32_pf34_control_w ) |
| 256 | 253 | { |
| 257 | | COMBINE_DATA(&deco32_pf34_control[offset]); |
| 254 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 255 | COMBINE_DATA(&state->pf34_control[offset]); |
| 258 | 256 | space->machine->primary_screen->update_partial(space->machine->primary_screen->vpos()); |
| 259 | 257 | } |
| 260 | 258 | |
| r10427 | r10428 | |
| 303 | 301 | |
| 304 | 302 | static WRITE32_HANDLER( deco32_irq_controller_w ) |
| 305 | 303 | { |
| 304 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 306 | 305 | int scanline; |
| 307 | 306 | |
| 308 | 307 | switch (offset) { |
| 309 | 308 | case 0: /* IRQ enable - probably an irq mask, but only values used are 0xc8 and 0xca */ |
| 310 | 309 | // logerror("%08x: IRQ write %d %08x\n",cpu_get_pc(space->cpu),offset,data); |
| 311 | | raster_enable=(data&0xff)==0xc8; /* 0xca seems to be off */ |
| 310 | state->raster_enable=(data&0xff)==0xc8; /* 0xca seems to be off */ |
| 312 | 311 | break; |
| 313 | 312 | |
| 314 | 313 | case 1: /* Raster IRQ scanline position, only valid for values between 1 & 239 (0 and 240-256 do NOT generate IRQ's) */ |
| 315 | 314 | scanline=(data&0xff); |
| 316 | | if (raster_enable && scanline>0 && scanline<240) |
| 315 | if (state->raster_enable && scanline>0 && scanline<240) |
| 317 | 316 | { |
| 318 | 317 | // needs +16 for the raster to align on captaven intro? (might just be our screen size / visible area / layer offsets need adjusting instead) |
| 319 | | raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(scanline+16, 320)); |
| 318 | state->raster_irq_timer->adjust(space->machine->primary_screen->time_until_pos(scanline+16, 320)); |
| 320 | 319 | } |
| 321 | 320 | else |
| 322 | | raster_irq_timer->reset(); |
| 321 | state->raster_irq_timer->reset(); |
| 323 | 322 | break; |
| 324 | 323 | case 2: /* VBL irq ack */ |
| 325 | 324 | break; |
| r10427 | r10428 | |
| 404 | 403 | |
| 405 | 404 | static READ32_HANDLER( dragngun_prot_r ) |
| 406 | 405 | { |
| 406 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 407 | 407 | // logerror("%08x:Read prot %08x (%08x)\n",cpu_get_pc(space->cpu),offset<<1,mem_mask); |
| 408 | 408 | |
| 409 | | static int strobe=0; |
| 410 | | if (!strobe) strobe=8; |
| 411 | | else strobe=0; |
| 409 | if (!state->strobe) state->strobe=8; |
| 410 | else state->strobe=0; |
| 412 | 411 | |
| 413 | 412 | //definitely vblank in locked load |
| 414 | 413 | |
| 415 | 414 | switch (offset<<1) { |
| 416 | 415 | case 0x140/2: return 0xffff0000 | input_port_read(space->machine, "IN0"); /* IN0 */ |
| 417 | | case 0xadc/2: return 0xffff0000 | input_port_read(space->machine, "IN1") | strobe; /* IN1 */ |
| 416 | case 0xadc/2: return 0xffff0000 | input_port_read(space->machine, "IN1") | state->strobe; /* IN1 */ |
| 418 | 417 | case 0x6a0/2: return 0xffff0000 | input_port_read(space->machine, "DSW"); /* IN2 (Dip switch) */ |
| 419 | 418 | } |
| 420 | 419 | return 0xffffffff; |
| 421 | 420 | } |
| 422 | 421 | |
| 423 | | static int dragngun_lightgun_port; |
| 424 | 422 | |
| 425 | 423 | static READ32_HANDLER( dragngun_lightgun_r ) |
| 426 | 424 | { |
| 425 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 427 | 426 | /* Ports 0-3 are read, but seem unused */ |
| 428 | | switch (dragngun_lightgun_port) { |
| 427 | switch (state->dragngun_lightgun_port) { |
| 429 | 428 | case 4: return input_port_read(space->machine, "LIGHT0_X"); |
| 430 | 429 | case 5: return input_port_read(space->machine, "LIGHT1_X"); |
| 431 | 430 | case 6: return input_port_read(space->machine, "LIGHT0_Y"); |
| 432 | 431 | case 7: return input_port_read(space->machine, "LIGHT1_Y"); |
| 433 | 432 | } |
| 434 | 433 | |
| 435 | | // logerror("Illegal lightgun port %d read \n",dragngun_lightgun_port); |
| 434 | // logerror("Illegal lightgun port %d read \n",state->dragngun_lightgun_port); |
| 436 | 435 | return 0; |
| 437 | 436 | } |
| 438 | 437 | |
| 439 | 438 | static WRITE32_HANDLER( dragngun_lightgun_w ) |
| 440 | 439 | { |
| 441 | | // logerror("Lightgun port %d\n",dragngun_lightgun_port); |
| 442 | | dragngun_lightgun_port=offset; |
| 440 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 441 | // logerror("Lightgun port %d\n",state->dragngun_lightgun_port); |
| 442 | state->dragngun_lightgun_port=offset; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | static READ32_DEVICE_HANDLER( dragngun_eeprom_r ) |
| r10427 | r10428 | |
| 460 | 460 | |
| 461 | 461 | /**********************************************************************************/ |
| 462 | 462 | |
| 463 | | static int tattass_eprom_bit; |
| 464 | 463 | |
| 465 | 464 | static READ32_HANDLER( tattass_prot_r ) |
| 466 | 465 | { |
| 466 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 467 | 467 | switch (offset<<1) { |
| 468 | 468 | case 0x280: return input_port_read(space->machine, "IN0") << 16; |
| 469 | 469 | case 0x4c4: return input_port_read(space->machine, "IN1") << 16; |
| 470 | | case 0x35a: return tattass_eprom_bit << 16; |
| 470 | case 0x35a: return state->tattass_eprom_bit << 16; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | logerror("%08x:Read prot %08x (%08x)\n",cpu_get_pc(space->cpu),offset<<1,mem_mask); |
| r10427 | r10428 | |
| 488 | 488 | |
| 489 | 489 | static WRITE32_HANDLER( tattass_control_w ) |
| 490 | 490 | { |
| 491 | | static int lastClock=0; |
| 492 | | static char buffer[32]; |
| 493 | | static int bufPtr=0; |
| 494 | | static int pendingCommand=0; /* 1 = read, 2 = write */ |
| 495 | | static int readBitCount=0; |
| 496 | | static int byteAddr=0; |
| 491 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 497 | 492 | eeprom_device *eeprom = space->machine->device<eeprom_device>("eeprom"); |
| 498 | 493 | address_space *eeprom_space = eeprom->space(); |
| 499 | 494 | |
| r10427 | r10428 | |
| 520 | 515 | |
| 521 | 516 | */ |
| 522 | 517 | if ((data&0x40)==0) { |
| 523 | | if (bufPtr) { |
| 518 | if (state->bufPtr) { |
| 524 | 519 | int i; |
| 525 | | logerror("Eprom reset (bit count %d): ",readBitCount); |
| 526 | | for (i=0; i<bufPtr; i++) |
| 527 | | logerror("%s",buffer[i] ? "1" : "0"); |
| 520 | logerror("Eprom reset (bit count %d): ",state->readBitCount); |
| 521 | for (i=0; i<state->bufPtr; i++) |
| 522 | logerror("%s",state->buffer[i] ? "1" : "0"); |
| 528 | 523 | logerror("\n"); |
| 529 | 524 | |
| 530 | 525 | } |
| 531 | | bufPtr=0; |
| 532 | | pendingCommand=0; |
| 533 | | readBitCount=0; |
| 526 | state->bufPtr=0; |
| 527 | state->pendingCommand=0; |
| 528 | state->readBitCount=0; |
| 534 | 529 | } |
| 535 | 530 | |
| 536 | 531 | /* Eprom has been clocked */ |
| 537 | | if (lastClock==0 && data&0x20 && data&0x40) { |
| 538 | | if (bufPtr>=32) { |
| 532 | if (state->lastClock==0 && data&0x20 && data&0x40) { |
| 533 | if (state->bufPtr>=32) { |
| 539 | 534 | logerror("Eprom overflow!"); |
| 540 | | bufPtr=0; |
| 535 | state->bufPtr=0; |
| 541 | 536 | } |
| 542 | 537 | |
| 543 | 538 | /* Handle pending read */ |
| 544 | | if (pendingCommand==1) { |
| 545 | | int d=readBitCount/8; |
| 546 | | int m=7-(readBitCount%8); |
| 547 | | int a=(byteAddr+d)%1024; |
| 539 | if (state->pendingCommand==1) { |
| 540 | int d=state->readBitCount/8; |
| 541 | int m=7-(state->readBitCount%8); |
| 542 | int a=(state->byteAddr+d)%1024; |
| 548 | 543 | int b=eeprom_space->read_byte(a); |
| 549 | 544 | |
| 550 | | tattass_eprom_bit=(b>>m)&1; |
| 545 | state->tattass_eprom_bit=(b>>m)&1; |
| 551 | 546 | |
| 552 | | readBitCount++; |
| 553 | | lastClock=data&0x20; |
| 547 | state->readBitCount++; |
| 548 | state->lastClock=data&0x20; |
| 554 | 549 | return; |
| 555 | 550 | } |
| 556 | 551 | |
| 557 | 552 | /* Handle pending write */ |
| 558 | | if (pendingCommand==2) { |
| 559 | | buffer[bufPtr++]=(data&0x10)>>4; |
| 553 | if (state->pendingCommand==2) { |
| 554 | state->buffer[state->bufPtr++]=(data&0x10)>>4; |
| 560 | 555 | |
| 561 | | if (bufPtr==32) { |
| 562 | | int b=(buffer[24]<<7)|(buffer[25]<<6)|(buffer[26]<<5)|(buffer[27]<<4) |
| 563 | | |(buffer[28]<<3)|(buffer[29]<<2)|(buffer[30]<<1)|(buffer[31]<<0); |
| 556 | if (state->bufPtr==32) { |
| 557 | int b=(state->buffer[24]<<7)|(state->buffer[25]<<6)|(state->buffer[26]<<5)|(state->buffer[27]<<4) |
| 558 | |(state->buffer[28]<<3)|(state->buffer[29]<<2)|(state->buffer[30]<<1)|(state->buffer[31]<<0); |
| 564 | 559 | |
| 565 | | eeprom_space->write_byte(byteAddr, b); |
| 560 | eeprom_space->write_byte(state->byteAddr, b); |
| 566 | 561 | } |
| 567 | | lastClock=data&0x20; |
| 562 | state->lastClock=data&0x20; |
| 568 | 563 | return; |
| 569 | 564 | } |
| 570 | 565 | |
| 571 | | buffer[bufPtr++]=(data&0x10)>>4; |
| 572 | | if (bufPtr==24) { |
| 566 | state->buffer[state->bufPtr++]=(data&0x10)>>4; |
| 567 | if (state->bufPtr==24) { |
| 573 | 568 | /* Decode addr */ |
| 574 | | byteAddr=(buffer[3]<<9)|(buffer[4]<<8) |
| 575 | | |(buffer[16]<<7)|(buffer[17]<<6)|(buffer[18]<<5)|(buffer[19]<<4) |
| 576 | | |(buffer[20]<<3)|(buffer[21]<<2)|(buffer[22]<<1)|(buffer[23]<<0); |
| 569 | state->byteAddr=(state->buffer[3]<<9)|(state->buffer[4]<<8) |
| 570 | |(state->buffer[16]<<7)|(state->buffer[17]<<6)|(state->buffer[18]<<5)|(state->buffer[19]<<4) |
| 571 | |(state->buffer[20]<<3)|(state->buffer[21]<<2)|(state->buffer[22]<<1)|(state->buffer[23]<<0); |
| 577 | 572 | |
| 578 | 573 | /* Check for read command */ |
| 579 | | if (buffer[0] && buffer[1]) { |
| 580 | | tattass_eprom_bit=(eeprom_space->read_byte(byteAddr)>>7)&1; |
| 581 | | readBitCount=1; |
| 582 | | pendingCommand=1; |
| 574 | if (state->buffer[0] && state->buffer[1]) { |
| 575 | state->tattass_eprom_bit=(eeprom_space->read_byte(state->byteAddr)>>7)&1; |
| 576 | state->readBitCount=1; |
| 577 | state->pendingCommand=1; |
| 583 | 578 | } |
| 584 | 579 | |
| 585 | 580 | /* Check for write command */ |
| 586 | | else if (buffer[0]==0x0 && buffer[1]==0x0) { |
| 587 | | pendingCommand=2; |
| 581 | else if (state->buffer[0]==0x0 && state->buffer[1]==0x0) { |
| 582 | state->pendingCommand=2; |
| 588 | 583 | } |
| 589 | 584 | else { |
| 590 | 585 | logerror("Detected unknown eprom command\n"); |
| r10427 | r10428 | |
| 594 | 589 | } else { |
| 595 | 590 | if (!(data&0x40)) { |
| 596 | 591 | logerror("Cs set low\n"); |
| 597 | | bufPtr=0; |
| 592 | state->bufPtr=0; |
| 598 | 593 | } |
| 599 | 594 | } |
| 600 | 595 | |
| 601 | | lastClock=data&0x20; |
| 596 | state->lastClock=data&0x20; |
| 602 | 597 | return; |
| 603 | 598 | } |
| 604 | 599 | |
| r10427 | r10428 | |
| 655 | 650 | |
| 656 | 651 | static WRITE32_HANDLER( nslasher_prot_w ) |
| 657 | 652 | { |
| 653 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 658 | 654 | //logerror("%08x:write prot %08x (%08x) %08x\n",cpu_get_pc(space->cpu),offset<<1,mem_mask,data); |
| 659 | 655 | |
| 660 | 656 | /* Only sound port of chip is used - no protection */ |
| r10427 | r10428 | |
| 662 | 658 | |
| 663 | 659 | /* bit 1 of nslasher_sound_irq specifies IRQ command writes */ |
| 664 | 660 | soundlatch_w(space,0,(data>>16)&0xff); |
| 665 | | nslasher_sound_irq |= 0x02; |
| 666 | | cputag_set_input_line(space->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 661 | state->nslasher_sound_irq |= 0x02; |
| 662 | cputag_set_input_line(space->machine, "audiocpu", 0, (state->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 667 | 663 | } |
| 668 | 664 | } |
| 669 | 665 | |
| r10427 | r10428 | |
| 676 | 672 | AM_RANGE(0x100000, 0x100003) AM_WRITE(buffer_spriteram32_w) |
| 677 | 673 | AM_RANGE(0x108000, 0x108003) AM_WRITENOP /* ? */ |
| 678 | 674 | AM_RANGE(0x110000, 0x110fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Sprites */ |
| 679 | | AM_RANGE(0x120000, 0x127fff) AM_RAM AM_BASE(&deco32_ram) /* Main RAM */ |
| 675 | AM_RANGE(0x120000, 0x127fff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) /* Main RAM */ |
| 680 | 676 | AM_RANGE(0x128000, 0x128fff) AM_READ(captaven_prot_r) |
| 681 | 677 | AM_RANGE(0x1280c8, 0x1280cb) AM_WRITE(deco32_sound_w) |
| 682 | 678 | AM_RANGE(0x130000, 0x131fff) AM_RAM_WRITE(deco32_nonbuffered_palette_w) AM_BASE_GENERIC(paletteram) /* Palette RAM */ |
| r10427 | r10428 | |
| 686 | 682 | |
| 687 | 683 | AM_RANGE(0x178000, 0x178003) AM_WRITE(deco32_pri_w) |
| 688 | 684 | |
| 689 | | AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 690 | | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 685 | AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 686 | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 691 | 687 | AM_RANGE(0x192000, 0x193fff) AM_WRITE(deco32_pf1_data_w) /* Mirror address - bug in program code */ |
| 692 | | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 693 | | AM_RANGE(0x1a0000, 0x1a1fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 694 | | AM_RANGE(0x1a4000, 0x1a5fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 688 | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 689 | AM_RANGE(0x1a0000, 0x1a1fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 690 | AM_RANGE(0x1a4000, 0x1a5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 695 | 691 | |
| 696 | | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 697 | | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 698 | | AM_RANGE(0x1e0000, 0x1e1fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 692 | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 693 | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 694 | AM_RANGE(0x1e0000, 0x1e1fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 699 | 695 | ADDRESS_MAP_END |
| 700 | 696 | |
| 701 | 697 | static ADDRESS_MAP_START( fghthist_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 702 | 698 | AM_RANGE(0x000000, 0x001fff) AM_ROM AM_WRITE(deco32_pf1_data_w) |
| 703 | 699 | AM_RANGE(0x000000, 0x0fffff) AM_ROM |
| 704 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 700 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 705 | 701 | AM_RANGE(0x120020, 0x12002f) AM_READ(fghthist_control_r) |
| 706 | 702 | AM_RANGE(0x12002c, 0x12002f) AM_WRITE(fghthist_eeprom_w) |
| 707 | 703 | AM_RANGE(0x1201fc, 0x1201ff) AM_WRITE(deco32_sound_w) |
| r10427 | r10428 | |
| 715 | 711 | AM_RANGE(0x179000, 0x179fff) AM_RAM AM_BASE_GENERIC(spriteram2) // ? |
| 716 | 712 | AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_w) |
| 717 | 713 | |
| 718 | | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 719 | | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 720 | | AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 721 | | AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 722 | | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 714 | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 715 | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 716 | AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 717 | AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 718 | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 723 | 719 | |
| 724 | | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 725 | | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 726 | | AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 727 | | AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 728 | | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 720 | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 721 | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 722 | AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 723 | AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 724 | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 729 | 725 | |
| 730 | 726 | AM_RANGE(0x16c000, 0x16c01f) AM_READNOP |
| 731 | 727 | AM_RANGE(0x17c000, 0x17c03f) AM_READNOP |
| r10427 | r10428 | |
| 736 | 732 | |
| 737 | 733 | static ADDRESS_MAP_START( fghthsta_memmap, ADDRESS_SPACE_PROGRAM, 32 ) |
| 738 | 734 | AM_RANGE(0x000000, 0x0fffff) AM_ROM |
| 739 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 735 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 740 | 736 | AM_RANGE(0x140000, 0x140003) AM_WRITENOP /* VBL irq ack */ |
| 741 | 737 | AM_RANGE(0x150000, 0x150003) AM_WRITE(fghthist_eeprom_w) /* Volume port/Eprom */ |
| 742 | 738 | |
| r10427 | r10428 | |
| 748 | 744 | AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_w) |
| 749 | 745 | AM_RANGE(0x17c020, 0x17c023) AM_READNOP |
| 750 | 746 | |
| 751 | | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 752 | | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 753 | | AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 754 | | AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 755 | | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 747 | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 748 | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 749 | AM_RANGE(0x192000, 0x192fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 750 | AM_RANGE(0x194000, 0x194fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 751 | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 756 | 752 | |
| 757 | | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 758 | | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 759 | | AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 760 | | AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 761 | | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 753 | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 754 | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 755 | AM_RANGE(0x1d2000, 0x1d2fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 756 | AM_RANGE(0x1d4000, 0x1d4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 757 | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 762 | 758 | |
| 763 | 759 | AM_RANGE(0x200000, 0x200fff) AM_READWRITE(deco16_146_fghthist_prot_r, deco16_146_fghthist_prot_w) AM_BASE(&deco32_prot_ram) |
| 764 | 760 | ADDRESS_MAP_END |
| r10427 | r10428 | |
| 767 | 763 | // raster effects appear to need some work on it anyway? |
| 768 | 764 | static ADDRESS_MAP_START( dragngun_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 769 | 765 | AM_RANGE(0x000000, 0x0fffff) AM_ROM |
| 770 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 766 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 771 | 767 | AM_RANGE(0x120000, 0x120fff) AM_READ(dragngun_prot_r) |
| 772 | 768 | AM_RANGE(0x1204c0, 0x1204c3) AM_WRITE(deco32_sound_w) |
| 773 | 769 | AM_RANGE(0x128000, 0x12800f) AM_READWRITE(deco32_irq_controller_r, deco32_irq_controller_w) |
| r10427 | r10428 | |
| 775 | 771 | AM_RANGE(0x138000, 0x138003) AM_NOP /* Palette dma complete in bit 0x8? ack? return 0 else tight loop */ |
| 776 | 772 | AM_RANGE(0x138008, 0x13800b) AM_WRITE(deco32_palette_dma_w) |
| 777 | 773 | |
| 778 | | // AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 779 | | AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE(&deco32_pf12_control) |
| 780 | | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 781 | | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 782 | | AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 783 | | AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 774 | // AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 775 | AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf12_control) |
| 776 | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 777 | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 778 | AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 779 | AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 784 | 780 | |
| 785 | | // AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 786 | | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE(&deco32_pf34_control) |
| 787 | | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 788 | | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 789 | | AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 790 | | AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 781 | // AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 782 | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf34_control) |
| 783 | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 784 | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 785 | AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 786 | AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 791 | 787 | |
| 792 | 788 | AM_RANGE(0x204800, 0x204fff) AM_RAM // ace? 0x10 byte increments only // 13f ff stuff |
| 793 | 789 | |
| 794 | 790 | |
| 795 | | AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE(&dragngun_sprite_layout_0_ram) |
| 796 | | AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE(&dragngun_sprite_layout_1_ram) |
| 797 | | AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE(&dragngun_sprite_lookup_0_ram) |
| 798 | | AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE(&dragngun_sprite_lookup_1_ram) |
| 791 | AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_0_ram) |
| 792 | AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_1_ram) |
| 793 | AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_0_ram) |
| 794 | AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_1_ram) |
| 799 | 795 | AM_RANGE(0x220000, 0x221fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Main spriteram */ |
| 800 | 796 | |
| 801 | 797 | AM_RANGE(0x228000, 0x2283ff) AM_RAM //0x10 byte increments only |
| r10427 | r10428 | |
| 816 | 812 | |
| 817 | 813 | static ADDRESS_MAP_START( lockload_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 818 | 814 | AM_RANGE(0x000000, 0x0fffff) AM_ROM |
| 819 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 815 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 820 | 816 | AM_RANGE(0x120000, 0x120fff) AM_READ(dragngun_prot_r) |
| 821 | 817 | AM_RANGE(0x1204c0, 0x1204c3) AM_WRITE(deco32_sound_w) |
| 822 | 818 | AM_RANGE(0x128000, 0x12800f) AM_READWRITE(deco32_irq_controller_r, deco32_irq_controller_w) |
| r10427 | r10428 | |
| 828 | 824 | AM_RANGE(0x170000, 0x170007) AM_READ(lockload_gun_mirror_r) /* Not on Dragongun */ |
| 829 | 825 | AM_RANGE(0x178008, 0x17800f) AM_WRITENOP /* Gun read ACK's */ |
| 830 | 826 | |
| 831 | | // AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 832 | | AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE(&deco32_pf12_control) |
| 833 | | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 834 | | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 835 | | AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 836 | | AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 827 | // AM_RANGE(0x180000, 0x18001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 828 | AM_RANGE(0x180000, 0x18001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf12_control) |
| 829 | AM_RANGE(0x190000, 0x191fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 830 | AM_RANGE(0x194000, 0x195fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 831 | AM_RANGE(0x1a0000, 0x1a0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 832 | AM_RANGE(0x1a4000, 0x1a4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 837 | 833 | |
| 838 | | // AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 839 | | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE(&deco32_pf34_control) |
| 840 | | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 841 | | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 842 | | AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 843 | | AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 834 | // AM_RANGE(0x1c0000, 0x1c001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 835 | AM_RANGE(0x1c0000, 0x1c001f) AM_RAM AM_BASE_MEMBER(deco32_state, pf34_control) |
| 836 | AM_RANGE(0x1d0000, 0x1d1fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 837 | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 838 | AM_RANGE(0x1e0000, 0x1e0fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 839 | AM_RANGE(0x1e4000, 0x1e4fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 844 | 840 | |
| 845 | 841 | AM_RANGE(0x204800, 0x204fff) AM_RAM //0x10 byte increments only |
| 846 | | AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE(&dragngun_sprite_layout_0_ram) |
| 847 | | AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE(&dragngun_sprite_layout_1_ram) |
| 848 | | AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE(&dragngun_sprite_lookup_0_ram) |
| 849 | | AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE(&dragngun_sprite_lookup_1_ram) |
| 842 | AM_RANGE(0x208000, 0x208fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_0_ram) |
| 843 | AM_RANGE(0x20c000, 0x20cfff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_layout_1_ram) |
| 844 | AM_RANGE(0x210000, 0x217fff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_0_ram) |
| 845 | AM_RANGE(0x218000, 0x21ffff) AM_RAM AM_BASE_MEMBER(deco32_state, dragngun_sprite_lookup_1_ram) |
| 850 | 846 | AM_RANGE(0x220000, 0x221fff) AM_RAM AM_BASE_SIZE_GENERIC(spriteram) /* Main spriteram */ |
| 851 | 847 | |
| 852 | 848 | AM_RANGE(0x228000, 0x2283ff) AM_RAM //0x10 byte increments only |
| r10427 | r10428 | |
| 866 | 862 | |
| 867 | 863 | AM_RANGE(0x000000, 0x0f7fff) AM_ROM |
| 868 | 864 | AM_RANGE(0x0f8000, 0x0fffff) AM_ROM AM_WRITENOP |
| 869 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 865 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 870 | 866 | AM_RANGE(0x120000, 0x120003) AM_NOP /* ACIA (unused) */ |
| 871 | 867 | AM_RANGE(0x130000, 0x130003) AM_WRITENOP /* Coin port (unused?) */ |
| 872 | 868 | AM_RANGE(0x140000, 0x140003) AM_WRITENOP /* Vblank ack */ |
| 873 | 869 | AM_RANGE(0x150000, 0x150003) AM_WRITE(tattass_control_w) /* Volume port/Eprom/Priority */ |
| 874 | 870 | |
| 875 | 871 | AM_RANGE(0x162000, 0x162fff) AM_RAM /* 'Jack' RAM!? */ |
| 876 | | AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE(&deco32_ace_ram) |
| 872 | AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE_MEMBER(deco32_state, ace_ram) |
| 877 | 873 | AM_RANGE(0x164000, 0x164003) AM_WRITENOP /* Palette control BG2/3 ($1a constant) */ |
| 878 | 874 | AM_RANGE(0x164004, 0x164007) AM_WRITENOP /* Palette control Obj1 ($6 constant) */ |
| 879 | 875 | AM_RANGE(0x164008, 0x16400b) AM_WRITENOP /* Palette control Obj2 ($5 constant) */ |
| r10427 | r10428 | |
| 892 | 888 | AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_2_w) |
| 893 | 889 | AM_RANGE(0x17c018, 0x17c01b) AM_WRITENOP /* Sprite 'CPU' (unused) */ |
| 894 | 890 | |
| 895 | | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 896 | | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 897 | | AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 898 | | AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 899 | | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 891 | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 892 | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 893 | AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 894 | AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 895 | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 900 | 896 | |
| 901 | | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 902 | | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 903 | | AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 904 | | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 905 | | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 897 | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 898 | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 899 | AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 900 | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 901 | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 906 | 902 | |
| 907 | 903 | AM_RANGE(0x200000, 0x200fff) AM_READWRITE(tattass_prot_r, tattass_prot_w) AM_BASE(&deco32_prot_ram) |
| 908 | 904 | ADDRESS_MAP_END |
| 909 | 905 | |
| 910 | 906 | static ADDRESS_MAP_START( nslasher_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 911 | 907 | AM_RANGE(0x000000, 0x0fffff) AM_ROM |
| 912 | | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE(&deco32_ram) |
| 908 | AM_RANGE(0x100000, 0x11ffff) AM_RAM AM_BASE_MEMBER(deco32_state, ram) |
| 913 | 909 | AM_RANGE(0x120000, 0x1200ff) AM_NOP /* ACIA (unused) */ |
| 914 | 910 | AM_RANGE(0x140000, 0x140003) AM_WRITENOP /* Vblank ack */ |
| 915 | 911 | AM_RANGE(0x150000, 0x150003) AM_WRITE(nslasher_eeprom_w) /* Volume port/Eprom/Priority */ |
| 916 | 912 | |
| 917 | | AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE(&deco32_ace_ram) /* 'Ace' RAM!? */ |
| 913 | AM_RANGE(0x163000, 0x16309f) AM_RAM_WRITE(deco32_ace_ram_w) AM_BASE_MEMBER(deco32_state, ace_ram) /* 'Ace' RAM!? */ |
| 918 | 914 | AM_RANGE(0x164000, 0x164003) AM_WRITENOP /* Palette control BG2/3 ($1a constant) */ |
| 919 | 915 | AM_RANGE(0x164004, 0x164007) AM_WRITENOP /* Palette control Obj1 ($4 constant) */ |
| 920 | 916 | AM_RANGE(0x164008, 0x16400b) AM_WRITENOP /* Palette control Obj2 ($6 constant) */ |
| r10427 | r10428 | |
| 932 | 928 | AM_RANGE(0x17c010, 0x17c013) AM_WRITE(buffer_spriteram32_2_w) |
| 933 | 929 | AM_RANGE(0x17c018, 0x17c01b) AM_WRITENOP /* Sprite 'CPU' (unused) */ |
| 934 | 930 | |
| 935 | | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE(&deco32_pf1_data) |
| 936 | | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE(&deco32_pf2_data) |
| 937 | | AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE(&deco32_pf1_rowscroll) |
| 938 | | AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE(&deco32_pf2_rowscroll) |
| 939 | | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE(&deco32_pf12_control) |
| 931 | AM_RANGE(0x182000, 0x183fff) AM_RAM_WRITE(deco32_pf1_data_w) AM_BASE_MEMBER(deco32_state, pf1_data) |
| 932 | AM_RANGE(0x184000, 0x185fff) AM_RAM_WRITE(deco32_pf2_data_w) AM_BASE_MEMBER(deco32_state, pf2_data) |
| 933 | AM_RANGE(0x192000, 0x193fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf1_rowscroll) |
| 934 | AM_RANGE(0x194000, 0x195fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf2_rowscroll) |
| 935 | AM_RANGE(0x1a0000, 0x1a001f) AM_RAM_WRITE(deco32_pf12_control_w) AM_BASE_MEMBER(deco32_state, pf12_control) |
| 940 | 936 | |
| 941 | | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE(&deco32_pf3_data) |
| 942 | | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE(&deco32_pf4_data) |
| 943 | | AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE(&deco32_pf3_rowscroll) |
| 944 | | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE(&deco32_pf4_rowscroll) |
| 945 | | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE(&deco32_pf34_control) |
| 937 | AM_RANGE(0x1c2000, 0x1c3fff) AM_RAM_WRITE(deco32_pf3_data_w) AM_BASE_MEMBER(deco32_state, pf3_data) |
| 938 | AM_RANGE(0x1c4000, 0x1c5fff) AM_RAM_WRITE(deco32_pf4_data_w) AM_BASE_MEMBER(deco32_state, pf4_data) |
| 939 | AM_RANGE(0x1d2000, 0x1d3fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf3_rowscroll) |
| 940 | AM_RANGE(0x1d4000, 0x1d5fff) AM_RAM AM_BASE_MEMBER(deco32_state, pf4_rowscroll) |
| 941 | AM_RANGE(0x1e0000, 0x1e001f) AM_RAM_WRITE(deco32_pf34_control_w) AM_BASE_MEMBER(deco32_state, pf34_control) |
| 946 | 942 | |
| 947 | 943 | AM_RANGE(0x200000, 0x200fff) AM_READWRITE(nslasher_prot_r, nslasher_prot_w) AM_BASE(&deco32_prot_ram) |
| 948 | 944 | ADDRESS_MAP_END |
| 949 | 945 | |
| 950 | 946 | /******************************************************************************/ |
| 951 | 947 | |
| 952 | | static UINT8 bsmt_latch; |
| 953 | | static UINT8 bsmt_reset; |
| 954 | 948 | |
| 955 | 949 | static WRITE8_HANDLER(deco32_bsmt_reset_w) |
| 956 | 950 | { |
| 957 | | UINT8 diff = data ^ bsmt_reset; |
| 958 | | bsmt_reset = data; |
| 951 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 952 | UINT8 diff = data ^ state->bsmt_reset; |
| 953 | state->bsmt_reset = data; |
| 959 | 954 | if ((diff & 0x80) && !(data & 0x80)) |
| 960 | 955 | devtag_reset(space->machine, "bsmt"); |
| 961 | 956 | } |
| 962 | 957 | |
| 963 | 958 | static WRITE8_HANDLER(deco32_bsmt0_w) |
| 964 | 959 | { |
| 965 | | bsmt_latch = data; |
| 960 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 961 | state->bsmt_latch = data; |
| 966 | 962 | } |
| 967 | 963 | |
| 968 | 964 | static void bsmt_ready_callback(bsmt2000_device &device) |
| r10427 | r10428 | |
| 972 | 968 | |
| 973 | 969 | static WRITE8_HANDLER(deco32_bsmt1_w) |
| 974 | 970 | { |
| 971 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 975 | 972 | bsmt2000_device *bsmt = space->machine->device<bsmt2000_device>("bsmt"); |
| 976 | 973 | bsmt->write_reg(offset ^ 0xff); |
| 977 | | bsmt->write_data((bsmt_latch << 8) | data); |
| 974 | bsmt->write_data((state->bsmt_latch << 8) | data); |
| 978 | 975 | cputag_set_input_line(space->machine, "audiocpu", M6809_IRQ_LINE, CLEAR_LINE); /* BSMT is not ready */ |
| 979 | 976 | } |
| 980 | 977 | |
| r10427 | r10428 | |
| 1007 | 1004 | |
| 1008 | 1005 | static READ8_HANDLER(latch_r) |
| 1009 | 1006 | { |
| 1007 | deco32_state *state = space->machine->driver_data<deco32_state>(); |
| 1010 | 1008 | /* bit 1 of nslasher_sound_irq specifies IRQ command writes */ |
| 1011 | | nslasher_sound_irq &= ~0x02; |
| 1012 | | cputag_set_input_line(space->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 1009 | state->nslasher_sound_irq &= ~0x02; |
| 1010 | cputag_set_input_line(space->machine, "audiocpu", 0, (state->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 1013 | 1011 | return soundlatch_r(space,0); |
| 1014 | 1012 | } |
| 1015 | 1013 | |
| r10427 | r10428 | |
| 1612 | 1610 | |
| 1613 | 1611 | static void sound_irq_nslasher(device_t *device, int state) |
| 1614 | 1612 | { |
| 1613 | deco32_state *drvstate = device->machine->driver_data<deco32_state>(); |
| 1615 | 1614 | /* bit 0 of nslasher_sound_irq specifies IRQ from sound chip */ |
| 1616 | 1615 | if (state) |
| 1617 | | nslasher_sound_irq |= 0x01; |
| 1616 | drvstate->nslasher_sound_irq |= 0x01; |
| 1618 | 1617 | else |
| 1619 | | nslasher_sound_irq &= ~0x01; |
| 1620 | | cputag_set_input_line(device->machine, "audiocpu", 0, (nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 1618 | drvstate->nslasher_sound_irq &= ~0x01; |
| 1619 | cputag_set_input_line(device->machine, "audiocpu", 0, (drvstate->nslasher_sound_irq != 0) ? ASSERT_LINE : CLEAR_LINE); |
| 1621 | 1620 | } |
| 1622 | 1621 | |
| 1623 | 1622 | static WRITE8_DEVICE_HANDLER( sound_bankswitch_w ) |
| r10427 | r10428 | |
| 1650 | 1649 | |
| 1651 | 1650 | static MACHINE_RESET( deco32 ) |
| 1652 | 1651 | { |
| 1653 | | raster_irq_timer = machine->device<timer_device>("int_timer"); |
| 1652 | deco32_state *state = machine->driver_data<deco32_state>(); |
| 1653 | state->raster_irq_timer = machine->device<timer_device>("int_timer"); |
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | static INTERRUPT_GEN( deco32_vbl_interrupt ) |
| r10427 | r10428 | |
| 1663 | 1663 | cpu_set_input_line(device, M6809_FIRQ_LINE, HOLD_LINE); |
| 1664 | 1664 | } |
| 1665 | 1665 | |
| 1666 | | static MACHINE_CONFIG_START( captaven, driver_device ) |
| 1666 | static MACHINE_CONFIG_START( captaven, deco32_state ) |
| 1667 | 1667 | |
| 1668 | 1668 | /* basic machine hardware */ |
| 1669 | 1669 | MCFG_CPU_ADD("maincpu", ARM, XTAL_28MHz/4) /* verified on pcb (Data East 101 custom)*/ |
| r10427 | r10428 | |
| 1710 | 1710 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35) |
| 1711 | 1711 | MACHINE_CONFIG_END |
| 1712 | 1712 | |
| 1713 | | static MACHINE_CONFIG_START( fghthist, driver_device ) |
| 1713 | static MACHINE_CONFIG_START( fghthist, deco32_state ) |
| 1714 | 1714 | |
| 1715 | 1715 | /* basic machine hardware */ |
| 1716 | 1716 | MCFG_CPU_ADD("maincpu", ARM, 28000000/4) |
| r10427 | r10428 | |
| 1754 | 1754 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35) |
| 1755 | 1755 | MACHINE_CONFIG_END |
| 1756 | 1756 | |
| 1757 | | static MACHINE_CONFIG_START( fghthsta, driver_device ) |
| 1757 | static MACHINE_CONFIG_START( fghthsta, deco32_state ) |
| 1758 | 1758 | |
| 1759 | 1759 | /* basic machine hardware */ |
| 1760 | 1760 | MCFG_CPU_ADD("maincpu", ARM, 28000000/4) |
| r10427 | r10428 | |
| 1798 | 1798 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.35) |
| 1799 | 1799 | MACHINE_CONFIG_END |
| 1800 | 1800 | |
| 1801 | | static MACHINE_CONFIG_START( dragngun, driver_device ) |
| 1801 | static MACHINE_CONFIG_START( dragngun, deco32_state ) |
| 1802 | 1802 | |
| 1803 | 1803 | /* basic machine hardware */ |
| 1804 | 1804 | MCFG_CPU_ADD("maincpu", ARM, 28000000/4) |
| r10427 | r10428 | |
| 1850 | 1850 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0) |
| 1851 | 1851 | MACHINE_CONFIG_END |
| 1852 | 1852 | |
| 1853 | | static MACHINE_CONFIG_START( lockload, driver_device ) |
| 1853 | static MACHINE_CONFIG_START( lockload, deco32_state ) |
| 1854 | 1854 | |
| 1855 | 1855 | /* basic machine hardware */ |
| 1856 | 1856 | MCFG_CPU_ADD("maincpu", ARM, 28000000/4) |
| r10427 | r10428 | |
| 1902 | 1902 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0) |
| 1903 | 1903 | MACHINE_CONFIG_END |
| 1904 | 1904 | |
| 1905 | | static MACHINE_CONFIG_START( tattass, driver_device ) |
| 1905 | static MACHINE_CONFIG_START( tattass, deco32_state ) |
| 1906 | 1906 | |
| 1907 | 1907 | /* basic machine hardware */ |
| 1908 | 1908 | MCFG_CPU_ADD("maincpu", ARM, 28000000/4) /* Unconfirmed */ |
| r10427 | r10428 | |
| 1939 | 1939 | MCFG_SOUND_ROUTE(1, "rspeaker", 1.0) |
| 1940 | 1940 | MACHINE_CONFIG_END |
| 1941 | 1941 | |
| 1942 | | static MACHINE_CONFIG_START( nslasher, driver_device ) |
| 1942 | static MACHINE_CONFIG_START( nslasher, deco32_state ) |
| 1943 | 1943 | |
| 1944 | 1944 | /* basic machine hardware */ |
| 1945 | 1945 | MCFG_CPU_ADD("maincpu", ARM, 28322000/4) |
src/mame/drivers/model2.c
| r10427 | r10428 | |
| 101 | 101 | #include "sound/2612intf.h" |
| 102 | 102 | #include "includes/model2.h" |
| 103 | 103 | |
| 104 | | UINT32 *model2_bufferram, *model2_colorxlat; |
| 105 | | static UINT32 *model2_workram; |
| 106 | | UINT32 *model2_textureram0, *model2_textureram1, *model2_lumaram; |
| 107 | | UINT32 *model2_paletteram32; |
| 108 | | static UINT32 model2_intreq; |
| 109 | | static UINT32 model2_intena; |
| 110 | | static UINT32 model2_coproctl, model2_coprocnt, model2_geoctl, model2_geocnt; |
| 111 | | static UINT16 *model2_soundram = NULL; |
| 112 | 104 | |
| 113 | | static UINT32 model2_timervals[4], model2_timerorig[4]; |
| 114 | | static int model2_timerrun[4]; |
| 115 | | static timer_device *model2_timers[4]; |
| 116 | | static int model2_ctrlmode; |
| 117 | | static int analog_channel; |
| 118 | | |
| 119 | | static UINT32 *tgp_program; |
| 120 | | |
| 121 | 105 | enum { |
| 122 | 106 | DSP_TYPE_TGP = 1, |
| 123 | 107 | DSP_TYPE_SHARC = 2, |
| 124 | 108 | DSP_TYPE_TGPX4 = 3, |
| 125 | 109 | }; |
| 126 | 110 | |
| 127 | | static int dsp_type; |
| 128 | 111 | |
| 129 | | |
| 130 | | |
| 131 | 112 | #define COPRO_FIFOIN_SIZE 32000 |
| 132 | | static int copro_fifoin_rpos, copro_fifoin_wpos; |
| 133 | | static UINT32 copro_fifoin_data[COPRO_FIFOIN_SIZE]; |
| 134 | | static int copro_fifoin_num = 0; |
| 135 | 113 | static int copro_fifoin_pop(device_t *device, UINT32 *result) |
| 136 | 114 | { |
| 115 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 137 | 116 | UINT32 r; |
| 138 | 117 | |
| 139 | | if (copro_fifoin_num == 0) |
| 118 | if (state->copro_fifoin_num == 0) |
| 140 | 119 | { |
| 141 | | if (dsp_type == DSP_TYPE_TGP) |
| 120 | if (state->dsp_type == DSP_TYPE_TGP) |
| 142 | 121 | return 0; |
| 143 | 122 | |
| 144 | 123 | fatalerror("Copro FIFOIN underflow (at %08X)", cpu_get_pc(device)); |
| 145 | 124 | return 0; |
| 146 | 125 | } |
| 147 | 126 | |
| 148 | | r = copro_fifoin_data[copro_fifoin_rpos++]; |
| 127 | r = state->copro_fifoin_data[state->copro_fifoin_rpos++]; |
| 149 | 128 | |
| 150 | | if (copro_fifoin_rpos == COPRO_FIFOIN_SIZE) |
| 129 | if (state->copro_fifoin_rpos == COPRO_FIFOIN_SIZE) |
| 151 | 130 | { |
| 152 | | copro_fifoin_rpos = 0; |
| 131 | state->copro_fifoin_rpos = 0; |
| 153 | 132 | } |
| 154 | 133 | |
| 155 | | copro_fifoin_num--; |
| 156 | | if (dsp_type == DSP_TYPE_SHARC) |
| 134 | state->copro_fifoin_num--; |
| 135 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 157 | 136 | { |
| 158 | | if (copro_fifoin_num == 0) |
| 137 | if (state->copro_fifoin_num == 0) |
| 159 | 138 | { |
| 160 | 139 | sharc_set_flag_input(device, 0, ASSERT_LINE); |
| 161 | 140 | } |
| r10427 | r10428 | |
| 172 | 151 | |
| 173 | 152 | static void copro_fifoin_push(device_t *device, UINT32 data) |
| 174 | 153 | { |
| 175 | | if (copro_fifoin_num == COPRO_FIFOIN_SIZE) |
| 154 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 155 | if (state->copro_fifoin_num == COPRO_FIFOIN_SIZE) |
| 176 | 156 | { |
| 177 | 157 | fatalerror("Copro FIFOIN overflow (at %08X)", cpu_get_pc(device)); |
| 178 | 158 | return; |
| r10427 | r10428 | |
| 180 | 160 | |
| 181 | 161 | //mame_printf_debug("COPRO FIFOIN at %08X, %08X, %f\n", cpu_get_pc(device), data, *(float*)&data); |
| 182 | 162 | |
| 183 | | copro_fifoin_data[copro_fifoin_wpos++] = data; |
| 184 | | if (copro_fifoin_wpos == COPRO_FIFOIN_SIZE) |
| 163 | state->copro_fifoin_data[state->copro_fifoin_wpos++] = data; |
| 164 | if (state->copro_fifoin_wpos == COPRO_FIFOIN_SIZE) |
| 185 | 165 | { |
| 186 | | copro_fifoin_wpos = 0; |
| 166 | state->copro_fifoin_wpos = 0; |
| 187 | 167 | } |
| 188 | 168 | |
| 189 | | copro_fifoin_num++; |
| 169 | state->copro_fifoin_num++; |
| 190 | 170 | |
| 191 | 171 | // clear FIFO empty flag on SHARC |
| 192 | | if (dsp_type == DSP_TYPE_SHARC) |
| 172 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 193 | 173 | { |
| 194 | 174 | sharc_set_flag_input(device, 0, CLEAR_LINE); |
| 195 | 175 | } |
| r10427 | r10428 | |
| 197 | 177 | |
| 198 | 178 | |
| 199 | 179 | #define COPRO_FIFOOUT_SIZE 32000 |
| 200 | | static int copro_fifoout_rpos, copro_fifoout_wpos; |
| 201 | | static UINT32 copro_fifoout_data[COPRO_FIFOOUT_SIZE]; |
| 202 | | static int copro_fifoout_num = 0; |
| 203 | 180 | static UINT32 copro_fifoout_pop(address_space *space) |
| 204 | 181 | { |
| 182 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 205 | 183 | UINT32 r; |
| 206 | 184 | |
| 207 | | if (copro_fifoout_num == 0) |
| 185 | if (state->copro_fifoout_num == 0) |
| 208 | 186 | { |
| 209 | 187 | /* Reading from empty FIFO causes the i960 to enter wait state */ |
| 210 | 188 | i960_stall(space->cpu); |
| r10427 | r10428 | |
| 215 | 193 | return 0; |
| 216 | 194 | } |
| 217 | 195 | |
| 218 | | r = copro_fifoout_data[copro_fifoout_rpos++]; |
| 196 | r = state->copro_fifoout_data[state->copro_fifoout_rpos++]; |
| 219 | 197 | |
| 220 | | if (copro_fifoout_rpos == COPRO_FIFOOUT_SIZE) |
| 198 | if (state->copro_fifoout_rpos == COPRO_FIFOOUT_SIZE) |
| 221 | 199 | { |
| 222 | | copro_fifoout_rpos = 0; |
| 200 | state->copro_fifoout_rpos = 0; |
| 223 | 201 | } |
| 224 | 202 | |
| 225 | | copro_fifoout_num--; |
| 203 | state->copro_fifoout_num--; |
| 226 | 204 | |
| 227 | | // logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,copro_fifoout_num); |
| 205 | // logerror("COPRO FIFOOUT POP %08X, %f, %d\n", r, *(float*)&r,state->copro_fifoout_num); |
| 228 | 206 | |
| 229 | 207 | // set SHARC flag 1: 0 if space available, 1 if FIFO full |
| 230 | | if (dsp_type == DSP_TYPE_SHARC) |
| 208 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 231 | 209 | { |
| 232 | | if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 210 | if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 233 | 211 | { |
| 234 | 212 | sharc_set_flag_input(space->machine->device("dsp"), 1, ASSERT_LINE); |
| 235 | 213 | } |
| r10427 | r10428 | |
| 244 | 222 | |
| 245 | 223 | static void copro_fifoout_push(device_t *device, UINT32 data) |
| 246 | 224 | { |
| 247 | | //if (copro_fifoout_wpos == copro_fifoout_rpos) |
| 248 | | if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 225 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 226 | //if (state->copro_fifoout_wpos == state->copro_fifoout_rpos) |
| 227 | if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 249 | 228 | { |
| 250 | 229 | fatalerror("Copro FIFOOUT overflow (at %08X)", cpu_get_pc(device)); |
| 251 | 230 | return; |
| 252 | 231 | } |
| 253 | 232 | |
| 254 | | // logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,copro_fifoout_num); |
| 233 | // logerror("COPRO FIFOOUT PUSH %08X, %f, %d\n", data, *(float*)&data,state->copro_fifoout_num); |
| 255 | 234 | |
| 256 | | copro_fifoout_data[copro_fifoout_wpos++] = data; |
| 257 | | if (copro_fifoout_wpos == COPRO_FIFOOUT_SIZE) |
| 235 | state->copro_fifoout_data[state->copro_fifoout_wpos++] = data; |
| 236 | if (state->copro_fifoout_wpos == COPRO_FIFOOUT_SIZE) |
| 258 | 237 | { |
| 259 | | copro_fifoout_wpos = 0; |
| 238 | state->copro_fifoout_wpos = 0; |
| 260 | 239 | } |
| 261 | 240 | |
| 262 | | copro_fifoout_num++; |
| 241 | state->copro_fifoout_num++; |
| 263 | 242 | |
| 264 | 243 | // set SHARC flag 1: 0 if space available, 1 if FIFO full |
| 265 | | if (dsp_type == DSP_TYPE_SHARC) |
| 244 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 266 | 245 | { |
| 267 | | if (copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 246 | if (state->copro_fifoout_num == COPRO_FIFOOUT_SIZE) |
| 268 | 247 | { |
| 269 | 248 | sharc_set_flag_input(device, 1, ASSERT_LINE); |
| 270 | 249 | |
| r10427 | r10428 | |
| 282 | 261 | /* Timers - these count down at 25 MHz and pull IRQ2 when they hit 0 */ |
| 283 | 262 | static READ32_HANDLER( timers_r ) |
| 284 | 263 | { |
| 264 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 285 | 265 | i960_noburst(space->cpu); |
| 286 | 266 | |
| 287 | 267 | // if timer is running, calculate current value |
| 288 | | if (model2_timerrun[offset]) |
| 268 | if (state->timerrun[offset]) |
| 289 | 269 | { |
| 290 | 270 | // get elapsed time, convert to units of 25 MHz |
| 291 | | UINT32 cur = (model2_timers[offset]->time_elapsed() * 25000000).as_double(); |
| 271 | UINT32 cur = (state->timers[offset]->time_elapsed() * 25000000).as_double(); |
| 292 | 272 | |
| 293 | 273 | // subtract units from starting value |
| 294 | | model2_timervals[offset] = model2_timerorig[offset] - cur; |
| 274 | state->timervals[offset] = state->timerorig[offset] - cur; |
| 295 | 275 | } |
| 296 | 276 | |
| 297 | | return model2_timervals[offset]; |
| 277 | return state->timervals[offset]; |
| 298 | 278 | } |
| 299 | 279 | |
| 300 | 280 | static WRITE32_HANDLER( timers_w ) |
| 301 | 281 | { |
| 282 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 302 | 283 | attotime period; |
| 303 | 284 | |
| 304 | 285 | i960_noburst(space->cpu); |
| 305 | | COMBINE_DATA(&model2_timervals[offset]); |
| 286 | COMBINE_DATA(&state->timervals[offset]); |
| 306 | 287 | |
| 307 | | model2_timerorig[offset] = model2_timervals[offset]; |
| 308 | | period = attotime::from_hz(25000000) * model2_timerorig[offset]; |
| 309 | | model2_timers[offset]->adjust(period); |
| 310 | | model2_timerrun[offset] = 1; |
| 288 | state->timerorig[offset] = state->timervals[offset]; |
| 289 | period = attotime::from_hz(25000000) * state->timerorig[offset]; |
| 290 | state->timers[offset]->adjust(period); |
| 291 | state->timerrun[offset] = 1; |
| 311 | 292 | } |
| 312 | 293 | |
| 313 | 294 | static TIMER_DEVICE_CALLBACK( model2_timer_cb ) |
| 314 | 295 | { |
| 296 | model2_state *state = timer.machine->driver_data<model2_state>(); |
| 315 | 297 | int tnum = (int)(FPTR)ptr; |
| 316 | 298 | int bit = tnum + 2; |
| 317 | 299 | |
| 318 | | model2_timers[tnum]->reset(); |
| 300 | state->timers[tnum]->reset(); |
| 319 | 301 | |
| 320 | | model2_intreq |= (1<<bit); |
| 321 | | if (model2_intena & (1<<bit)) |
| 302 | state->intreq |= (1<<bit); |
| 303 | if (state->intena & (1<<bit)) |
| 322 | 304 | { |
| 323 | 305 | cputag_set_input_line(timer.machine, "maincpu", I960_IRQ2, ASSERT_LINE); |
| 324 | 306 | } |
| 325 | 307 | |
| 326 | | model2_timervals[tnum] = 0; |
| 327 | | model2_timerrun[tnum] = 0; |
| 308 | state->timervals[tnum] = 0; |
| 309 | state->timerrun[tnum] = 0; |
| 328 | 310 | } |
| 329 | 311 | |
| 312 | static MACHINE_START(model2) |
| 313 | { |
| 314 | model2_state *state = machine->driver_data<model2_state>(); |
| 315 | state->copro_fifoin_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOIN_SIZE); |
| 316 | state->copro_fifoout_data = auto_alloc_array_clear(machine, UINT32, COPRO_FIFOOUT_SIZE); |
| 317 | } |
| 318 | |
| 330 | 319 | static MACHINE_RESET(model2_common) |
| 331 | 320 | { |
| 321 | model2_state *state = machine->driver_data<model2_state>(); |
| 332 | 322 | int i; |
| 333 | 323 | |
| 334 | | model2_intreq = 0; |
| 335 | | model2_intena = 0; |
| 336 | | model2_coproctl = 0; |
| 337 | | model2_coprocnt = 0; |
| 338 | | model2_geoctl = 0; |
| 339 | | model2_geocnt = 0; |
| 340 | | model2_ctrlmode = 0; |
| 341 | | analog_channel = 0; |
| 324 | state->intreq = 0; |
| 325 | state->intena = 0; |
| 326 | state->coproctl = 0; |
| 327 | state->coprocnt = 0; |
| 328 | state->geoctl = 0; |
| 329 | state->geocnt = 0; |
| 330 | state->ctrlmode = 0; |
| 331 | state->analog_channel = 0; |
| 342 | 332 | |
| 343 | | model2_timervals[0] = 0xfffff; |
| 344 | | model2_timervals[1] = 0xfffff; |
| 345 | | model2_timervals[2] = 0xfffff; |
| 346 | | model2_timervals[3] = 0xfffff; |
| 333 | state->timervals[0] = 0xfffff; |
| 334 | state->timervals[1] = 0xfffff; |
| 335 | state->timervals[2] = 0xfffff; |
| 336 | state->timervals[3] = 0xfffff; |
| 347 | 337 | |
| 348 | | model2_timerrun[0] = model2_timerrun[1] = model2_timerrun[2] = model2_timerrun[3] = 0; |
| 338 | state->timerrun[0] = state->timerrun[1] = state->timerrun[2] = state->timerrun[3] = 0; |
| 349 | 339 | |
| 350 | | model2_timers[0] = machine->device<timer_device>("timer0"); |
| 351 | | model2_timers[1] = machine->device<timer_device>("timer1"); |
| 352 | | model2_timers[2] = machine->device<timer_device>("timer2"); |
| 353 | | model2_timers[3] = machine->device<timer_device>("timer3"); |
| 340 | state->timers[0] = machine->device<timer_device>("timer0"); |
| 341 | state->timers[1] = machine->device<timer_device>("timer1"); |
| 342 | state->timers[2] = machine->device<timer_device>("timer2"); |
| 343 | state->timers[3] = machine->device<timer_device>("timer3"); |
| 354 | 344 | for (i=0; i<4; i++) |
| 355 | | model2_timers[i]->reset(); |
| 345 | state->timers[i]->reset(); |
| 356 | 346 | } |
| 357 | 347 | |
| 358 | 348 | static MACHINE_RESET(model2o) |
| 359 | 349 | { |
| 350 | model2_state *state = machine->driver_data<model2_state>(); |
| 360 | 351 | MACHINE_RESET_CALL(model2_common); |
| 361 | 352 | |
| 362 | 353 | // hold TGP in halt until we have code |
| 363 | 354 | cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE); |
| 364 | 355 | |
| 365 | | dsp_type = DSP_TYPE_TGP; |
| 356 | state->dsp_type = DSP_TYPE_TGP; |
| 366 | 357 | } |
| 367 | 358 | |
| 368 | 359 | static MACHINE_RESET(model2_scsp) |
| 369 | 360 | { |
| 361 | model2_state *state = machine->driver_data<model2_state>(); |
| 370 | 362 | memory_set_bankptr(machine, "bank4", machine->region("scsp")->base() + 0x200000); |
| 371 | 363 | memory_set_bankptr(machine, "bank5", machine->region("scsp")->base() + 0x600000); |
| 372 | 364 | |
| 373 | 365 | // copy the 68k vector table into RAM |
| 374 | | memcpy(model2_soundram, machine->region("audiocpu")->base() + 0x80000, 16); |
| 366 | memcpy(state->soundram, machine->region("audiocpu")->base() + 0x80000, 16); |
| 375 | 367 | machine->device("audiocpu")->reset(); |
| 376 | 368 | } |
| 377 | 369 | |
| 378 | 370 | static MACHINE_RESET(model2) |
| 379 | 371 | { |
| 372 | model2_state *state = machine->driver_data<model2_state>(); |
| 380 | 373 | MACHINE_RESET_CALL(model2_common); |
| 381 | 374 | MACHINE_RESET_CALL(model2_scsp); |
| 382 | 375 | |
| 383 | 376 | // hold TGP in halt until we have code |
| 384 | 377 | cputag_set_input_line(machine, "tgp", INPUT_LINE_HALT, ASSERT_LINE); |
| 385 | 378 | |
| 386 | | dsp_type = DSP_TYPE_TGP; |
| 379 | state->dsp_type = DSP_TYPE_TGP; |
| 387 | 380 | } |
| 388 | 381 | |
| 389 | 382 | static MACHINE_RESET(model2b) |
| 390 | 383 | { |
| 384 | model2_state *state = machine->driver_data<model2_state>(); |
| 391 | 385 | MACHINE_RESET_CALL(model2_common); |
| 392 | 386 | MACHINE_RESET_CALL(model2_scsp); |
| 393 | 387 | |
| r10427 | r10428 | |
| 398 | 392 | // clear FIFOOUT buffer full flag on SHARC |
| 399 | 393 | cputag_set_input_line(machine, "dsp", SHARC_INPUT_FLAG1, CLEAR_LINE); |
| 400 | 394 | |
| 401 | | dsp_type = DSP_TYPE_SHARC; |
| 395 | state->dsp_type = DSP_TYPE_SHARC; |
| 402 | 396 | } |
| 403 | 397 | |
| 404 | 398 | static MACHINE_RESET(model2c) |
| 405 | 399 | { |
| 400 | model2_state *state = machine->driver_data<model2_state>(); |
| 406 | 401 | MACHINE_RESET_CALL(model2_common); |
| 407 | 402 | MACHINE_RESET_CALL(model2_scsp); |
| 408 | 403 | |
| 409 | | dsp_type = DSP_TYPE_TGPX4; |
| 404 | state->dsp_type = DSP_TYPE_TGPX4; |
| 410 | 405 | } |
| 411 | 406 | |
| 412 | 407 | static void chcolor(running_machine *machine, pen_t color, UINT16 data) |
| r10427 | r10428 | |
| 416 | 411 | |
| 417 | 412 | static WRITE32_HANDLER( pal32_w ) |
| 418 | 413 | { |
| 419 | | COMBINE_DATA(model2_paletteram32 + offset); |
| 414 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 415 | COMBINE_DATA(state->paletteram32 + offset); |
| 420 | 416 | if(ACCESSING_BITS_0_15) |
| 421 | | chcolor(space->machine, offset * 2, model2_paletteram32[offset]); |
| 417 | chcolor(space->machine, offset * 2, state->paletteram32[offset]); |
| 422 | 418 | if(ACCESSING_BITS_16_31) |
| 423 | | chcolor(space->machine, offset * 2 + 1, model2_paletteram32[offset] >> 16); |
| 419 | chcolor(space->machine, offset * 2 + 1, state->paletteram32[offset] >> 16); |
| 424 | 420 | } |
| 425 | 421 | |
| 426 | 422 | static WRITE32_HANDLER( ctrl0_w ) |
| 427 | 423 | { |
| 424 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 428 | 425 | if(ACCESSING_BITS_0_7) |
| 429 | 426 | { |
| 430 | 427 | eeprom_device *device = space->machine->device<eeprom_device>("eeprom"); |
| 431 | | model2_ctrlmode = data & 0x01; |
| 428 | state->ctrlmode = data & 0x01; |
| 432 | 429 | eeprom_write_bit(device, data & 0x20); |
| 433 | 430 | eeprom_set_clock_line(device, (data & 0x80) ? ASSERT_LINE : CLEAR_LINE); |
| 434 | 431 | eeprom_set_cs_line(device, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE); |
| r10427 | r10428 | |
| 437 | 434 | |
| 438 | 435 | static WRITE32_HANDLER( analog_2b_w ) |
| 439 | 436 | { |
| 440 | | analog_channel = (data >> 16) & 0x07; |
| 437 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 438 | state->analog_channel = (data >> 16) & 0x07; |
| 441 | 439 | } |
| 442 | 440 | |
| 443 | 441 | |
| 444 | 442 | static READ32_HANDLER( fifoctl_r ) |
| 445 | 443 | { |
| 444 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 446 | 445 | UINT32 r = 0; |
| 447 | 446 | |
| 448 | | if (copro_fifoout_num == 0) |
| 447 | if (state->copro_fifoout_num == 0) |
| 449 | 448 | { |
| 450 | 449 | r |= 1; |
| 451 | 450 | } |
| r10427 | r10428 | |
| 461 | 460 | |
| 462 | 461 | static CUSTOM_INPUT( _1c00000_r ) |
| 463 | 462 | { |
| 463 | model2_state *state = field->port->machine->driver_data<model2_state>(); |
| 464 | 464 | UINT32 ret = input_port_read(field->port->machine, "IN0"); |
| 465 | 465 | |
| 466 | | if(model2_ctrlmode == 0) |
| 466 | if(state->ctrlmode == 0) |
| 467 | 467 | { |
| 468 | 468 | return ret; |
| 469 | 469 | } |
| r10427 | r10428 | |
| 476 | 476 | |
| 477 | 477 | static CUSTOM_INPUT( _1c0001c_r ) |
| 478 | 478 | { |
| 479 | model2_state *state = field->port->machine->driver_data<model2_state>(); |
| 479 | 480 | UINT32 iptval = 0x00ff; |
| 480 | | if(analog_channel < 4) |
| 481 | if(state->analog_channel < 4) |
| 481 | 482 | { |
| 482 | 483 | static const char *const ports[] = { "ANA0", "ANA1", "ANA2", "ANA3" }; |
| 483 | | iptval = input_port_read_safe(field->port->machine, ports[analog_channel], 0); |
| 484 | | ++analog_channel; |
| 484 | iptval = input_port_read_safe(field->port->machine, ports[state->analog_channel], 0); |
| 485 | ++state->analog_channel; |
| 485 | 486 | } |
| 486 | 487 | return iptval; |
| 487 | 488 | } |
| r10427 | r10428 | |
| 555 | 556 | |
| 556 | 557 | */ |
| 557 | 558 | |
| 558 | | static UINT16 cmd_data; |
| 559 | 559 | |
| 560 | 560 | static CUSTOM_INPUT( rchase2_devices_r ) |
| 561 | 561 | { |
| r10427 | r10428 | |
| 564 | 564 | |
| 565 | 565 | static WRITE32_HANDLER( rchase2_devices_w ) |
| 566 | 566 | { |
| 567 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 567 | 568 | /* |
| 568 | 569 | 0x00040000 start 1 lamp |
| 569 | 570 | 0x00080000 start 2 lamp |
| 570 | 571 | */ |
| 571 | 572 | |
| 572 | 573 | if(mem_mask == 0x0000ffff) |
| 573 | | cmd_data = data; |
| 574 | state->cmd_data = data; |
| 574 | 575 | } |
| 575 | 576 | |
| 576 | | static UINT8 driveio_comm_data; |
| 577 | 577 | |
| 578 | 578 | static WRITE32_HANDLER( srallyc_devices_w ) |
| 579 | 579 | { |
| 580 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 580 | 581 | /* |
| 581 | 582 | 0x00040000 start 1 lamp |
| 582 | 583 | 0x00200000 vr lamp |
| r10427 | r10428 | |
| 585 | 586 | |
| 586 | 587 | if(mem_mask == 0x000000ff || mem_mask == 0x0000ffff) |
| 587 | 588 | { |
| 588 | | driveio_comm_data = data & 0xff; |
| 589 | state->driveio_comm_data = data & 0xff; |
| 589 | 590 | cputag_set_input_line(space->machine, "drivecpu", 0, HOLD_LINE); |
| 590 | 591 | } |
| 591 | 592 | } |
| r10427 | r10428 | |
| 601 | 602 | |
| 602 | 603 | static WRITE32_HANDLER(copro_prg_w) |
| 603 | 604 | { |
| 604 | | if (model2_coproctl & 0x80000000) |
| 605 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 606 | if (state->coproctl & 0x80000000) |
| 605 | 607 | { |
| 606 | | logerror("copro_prg_w: %08X: %08X\n", model2_coprocnt, data); |
| 607 | | model2_coprocnt++; |
| 608 | logerror("copro_prg_w: %08X: %08X\n", state->coprocnt, data); |
| 609 | state->coprocnt++; |
| 608 | 610 | } |
| 609 | 611 | else |
| 610 | 612 | { |
| r10427 | r10428 | |
| 614 | 616 | |
| 615 | 617 | static WRITE32_HANDLER( copro_ctl1_w ) |
| 616 | 618 | { |
| 619 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 617 | 620 | // did hi bit change? |
| 618 | | if ((data ^ model2_coproctl) == 0x80000000) |
| 621 | if ((data ^ state->coproctl) == 0x80000000) |
| 619 | 622 | { |
| 620 | 623 | if (data & 0x80000000) |
| 621 | 624 | { |
| 622 | 625 | logerror("Start copro upload\n"); |
| 623 | | model2_coprocnt = 0; |
| 626 | state->coprocnt = 0; |
| 624 | 627 | } |
| 625 | 628 | else |
| 626 | 629 | { |
| 627 | | logerror("Boot copro, %d dwords\n", model2_coprocnt); |
| 628 | | if (dsp_type != DSP_TYPE_TGPX4) |
| 630 | logerror("Boot copro, %d dwords\n", state->coprocnt); |
| 631 | if (state->dsp_type != DSP_TYPE_TGPX4) |
| 629 | 632 | { |
| 630 | | if (dsp_type == DSP_TYPE_SHARC) |
| 633 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 631 | 634 | cputag_set_input_line(space->machine, "dsp", INPUT_LINE_HALT, CLEAR_LINE); |
| 632 | 635 | else |
| 633 | 636 | cputag_set_input_line(space->machine, "tgp", INPUT_LINE_HALT, CLEAR_LINE); |
| r10427 | r10428 | |
| 635 | 638 | } |
| 636 | 639 | } |
| 637 | 640 | |
| 638 | | model2_coproctl = data; |
| 641 | state->coproctl = data; |
| 639 | 642 | } |
| 640 | 643 | |
| 641 | 644 | static WRITE32_HANDLER(copro_function_port_w) |
| 642 | 645 | { |
| 646 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 643 | 647 | UINT32 d = data & 0x800fffff; |
| 644 | 648 | UINT32 a = (offset >> 2) & 0xff; |
| 645 | 649 | d |= a << 23; |
| 646 | 650 | |
| 647 | 651 | //logerror("copro_function_port_w: %08X, %08X, %08X\n", data, offset, mem_mask); |
| 648 | | if (dsp_type == DSP_TYPE_SHARC) |
| 652 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 649 | 653 | copro_fifoin_push(space->machine->device("dsp"), d); |
| 650 | 654 | else |
| 651 | 655 | copro_fifoin_push(space->machine->device("tgp"), d); |
| r10427 | r10428 | |
| 659 | 663 | |
| 660 | 664 | static WRITE32_HANDLER(copro_fifo_w) |
| 661 | 665 | { |
| 662 | | if (model2_coproctl & 0x80000000) |
| 666 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 667 | if (state->coproctl & 0x80000000) |
| 663 | 668 | { |
| 664 | | if (dsp_type == DSP_TYPE_SHARC) |
| 669 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 665 | 670 | { |
| 666 | | sharc_external_dma_write(space->machine->device("dsp"), model2_coprocnt, data & 0xffff); |
| 671 | sharc_external_dma_write(space->machine->device("dsp"), state->coprocnt, data & 0xffff); |
| 667 | 672 | } |
| 668 | | else if (dsp_type == DSP_TYPE_TGP) |
| 673 | else if (state->dsp_type == DSP_TYPE_TGP) |
| 669 | 674 | { |
| 670 | | tgp_program[model2_coprocnt] = data; |
| 675 | state->tgp_program[state->coprocnt] = data; |
| 671 | 676 | } |
| 672 | 677 | |
| 673 | | model2_coprocnt++; |
| 678 | state->coprocnt++; |
| 674 | 679 | } |
| 675 | 680 | else |
| 676 | 681 | { |
| 677 | 682 | //mame_printf_debug("copro_fifo_w: %08X, %08X, %08X at %08X\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); |
| 678 | | if (dsp_type == DSP_TYPE_SHARC) |
| 683 | if (state->dsp_type == DSP_TYPE_SHARC) |
| 679 | 684 | copro_fifoin_push(space->machine->device("dsp"), data); |
| 680 | 685 | else |
| 681 | 686 | copro_fifoin_push(space->machine->device("tgp"), data); |
| 682 | 687 | } |
| 683 | 688 | } |
| 684 | 689 | |
| 685 | | static int iop_write_num = 0; |
| 686 | | static UINT32 iop_data = 0; |
| 687 | 690 | static WRITE32_HANDLER(copro_sharc_iop_w) |
| 688 | 691 | { |
| 692 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 689 | 693 | /* FIXME: clean this up */ |
| 690 | 694 | if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0) || |
| 691 | 695 | (strcmp(space->machine->gamedrv->name, "sfight" ) == 0) || |
| r10427 | r10428 | |
| 701 | 705 | } |
| 702 | 706 | else |
| 703 | 707 | { |
| 704 | | if ((iop_write_num & 1) == 0) |
| 708 | if ((state->iop_write_num & 1) == 0) |
| 705 | 709 | { |
| 706 | | iop_data = data & 0xffff; |
| 710 | state->iop_data = data & 0xffff; |
| 707 | 711 | } |
| 708 | 712 | else |
| 709 | 713 | { |
| 710 | | iop_data |= (data & 0xffff) << 16; |
| 711 | | sharc_external_iop_write(space->machine->device("dsp"), offset, iop_data); |
| 714 | state->iop_data |= (data & 0xffff) << 16; |
| 715 | sharc_external_iop_write(space->machine->device("dsp"), offset, state->iop_data); |
| 712 | 716 | } |
| 713 | | iop_write_num++; |
| 717 | state->iop_write_num++; |
| 714 | 718 | } |
| 715 | 719 | } |
| 716 | 720 | |
| r10427 | r10428 | |
| 721 | 725 | /*****************************************************************************/ |
| 722 | 726 | /* GEO */ |
| 723 | 727 | |
| 724 | | UINT32 geo_read_start_address = 0; |
| 725 | | UINT32 geo_write_start_address = 0; |
| 726 | 728 | |
| 727 | 729 | static WRITE32_HANDLER( geo_ctl1_w ) |
| 728 | 730 | { |
| 731 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 729 | 732 | // did hi bit change? |
| 730 | | if ((data ^ model2_geoctl) == 0x80000000) |
| 733 | if ((data ^ state->geoctl) == 0x80000000) |
| 731 | 734 | { |
| 732 | 735 | if (data & 0x80000000) |
| 733 | 736 | { |
| 734 | | logerror("Start geo upload\n"); |
| 735 | | model2_geocnt = 0; |
| 737 | logerror("Start state->geo upload\n"); |
| 738 | state->geocnt = 0; |
| 736 | 739 | } |
| 737 | 740 | else |
| 738 | 741 | { |
| 739 | | logerror("Boot geo, %d dwords\n", model2_geocnt); |
| 742 | logerror("Boot state->geo, %d dwords\n", state->geocnt); |
| 740 | 743 | } |
| 741 | 744 | } |
| 742 | 745 | |
| 743 | | model2_geoctl = data; |
| 746 | state->geoctl = data; |
| 744 | 747 | } |
| 745 | 748 | |
| 746 | 749 | |
| 747 | 750 | #ifdef UNUSED_FUNCTION |
| 748 | 751 | static WRITE32_HANDLER( geo_sharc_ctl1_w ) |
| 749 | 752 | { |
| 753 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 750 | 754 | // did hi bit change? |
| 751 | | if ((data ^ model2_geoctl) == 0x80000000) |
| 755 | if ((data ^ state->geoctl) == 0x80000000) |
| 752 | 756 | { |
| 753 | 757 | if (data & 0x80000000) |
| 754 | 758 | { |
| 755 | | logerror("Start geo upload\n"); |
| 756 | | model2_geocnt = 0; |
| 759 | logerror("Start state->geo upload\n"); |
| 760 | state->geocnt = 0; |
| 757 | 761 | } |
| 758 | 762 | else |
| 759 | 763 | { |
| 760 | | logerror("Boot geo, %d dwords\n", model2_geocnt); |
| 764 | logerror("Boot state->geo, %d dwords\n", state->geocnt); |
| 761 | 765 | cputag_set_input_line(space->machine, "dsp2", INPUT_LINE_HALT, CLEAR_LINE); |
| 762 | 766 | //cpu_spinuntil_time(space->cpu, attotime::from_usec(1000)); // Give the SHARC enough time to boot itself |
| 763 | 767 | } |
| 764 | 768 | } |
| 765 | 769 | |
| 766 | | model2_geoctl = data; |
| 770 | state->geoctl = data; |
| 767 | 771 | } |
| 768 | 772 | |
| 769 | 773 | static READ32_HANDLER(geo_sharc_fifo_r) |
| r10427 | r10428 | |
| 781 | 785 | |
| 782 | 786 | static WRITE32_HANDLER(geo_sharc_fifo_w) |
| 783 | 787 | { |
| 784 | | if (model2_geoctl & 0x80000000) |
| 788 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 789 | if (state->geoctl & 0x80000000) |
| 785 | 790 | { |
| 786 | | sharc_external_dma_write(space->machine->device("dsp2"), model2_geocnt, data & 0xffff); |
| 791 | sharc_external_dma_write(space->machine->device("dsp2"), state->geocnt, data & 0xffff); |
| 787 | 792 | |
| 788 | | model2_geocnt++; |
| 793 | state->geocnt++; |
| 789 | 794 | } |
| 790 | 795 | else |
| 791 | 796 | { |
| r10427 | r10428 | |
| 793 | 798 | } |
| 794 | 799 | } |
| 795 | 800 | |
| 796 | | static int geo_iop_write_num = 0; |
| 797 | | static UINT32 geo_iop_data = 0; |
| 798 | 801 | static WRITE32_HANDLER(geo_sharc_iop_w) |
| 799 | 802 | { |
| 803 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 800 | 804 | if ((strcmp(space->machine->gamedrv->name, "schamp" ) == 0)) |
| 801 | 805 | { |
| 802 | 806 | sharc_external_iop_write(space->machine->device("dsp2"), offset, data); |
| 803 | 807 | } |
| 804 | 808 | else |
| 805 | 809 | { |
| 806 | | if ((geo_iop_write_num & 1) == 0) |
| 810 | if ((state->geo_iop_write_num & 1) == 0) |
| 807 | 811 | { |
| 808 | | geo_iop_data = data & 0xffff; |
| 812 | state->geo_iop_data = data & 0xffff; |
| 809 | 813 | } |
| 810 | 814 | else |
| 811 | 815 | { |
| 812 | | geo_iop_data |= (data & 0xffff) << 16; |
| 813 | | sharc_external_iop_write(space->machine->device("dsp2"), offset, geo_iop_data); |
| 816 | state->geo_iop_data |= (data & 0xffff) << 16; |
| 817 | sharc_external_iop_write(space->machine->device("dsp2"), offset, state->geo_iop_data); |
| 814 | 818 | } |
| 815 | | geo_iop_write_num++; |
| 819 | state->geo_iop_write_num++; |
| 816 | 820 | } |
| 817 | 821 | } |
| 818 | 822 | #endif |
| 819 | 823 | |
| 820 | 824 | |
| 821 | | static void push_geo_data(UINT32 data) |
| 825 | static void push_geo_data(model2_state *state, UINT32 data) |
| 822 | 826 | { |
| 823 | | //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+geo_write_start_address, data); |
| 824 | | model2_bufferram[geo_write_start_address/4] = data; |
| 825 | | geo_write_start_address += 4; |
| 827 | //mame_printf_debug("push_geo_data: %08X: %08X\n", 0x900000+state->geo_write_start_address, data); |
| 828 | state->bufferram[state->geo_write_start_address/4] = data; |
| 829 | state->geo_write_start_address += 4; |
| 826 | 830 | } |
| 827 | 831 | |
| 828 | 832 | static READ32_HANDLER(geo_prg_r) |
| r10427 | r10428 | |
| 832 | 836 | |
| 833 | 837 | static WRITE32_HANDLER(geo_prg_w) |
| 834 | 838 | { |
| 835 | | if (model2_geoctl & 0x80000000) |
| 839 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 840 | if (state->geoctl & 0x80000000) |
| 836 | 841 | { |
| 837 | | //logerror("geo_prg_w: %08X: %08X\n", model2_geocnt, data); |
| 838 | | model2_geocnt++; |
| 842 | //logerror("geo_prg_w: %08X: %08X\n", state->geocnt, data); |
| 843 | state->geocnt++; |
| 839 | 844 | } |
| 840 | 845 | else |
| 841 | 846 | { |
| 842 | | //mame_printf_debug("GEO: %08X: push %08X\n", geo_write_start_address, data); |
| 843 | | push_geo_data(data); |
| 847 | //mame_printf_debug("GEO: %08X: push %08X\n", state->geo_write_start_address, data); |
| 848 | push_geo_data(state, data); |
| 844 | 849 | } |
| 845 | 850 | } |
| 846 | 851 | |
| 847 | 852 | static READ32_HANDLER( geo_r ) |
| 848 | 853 | { |
| 854 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 849 | 855 | int address = offset * 4; |
| 850 | 856 | if (address == 0x2008) |
| 851 | 857 | { |
| 852 | | return geo_write_start_address; |
| 858 | return state->geo_write_start_address; |
| 853 | 859 | } |
| 854 | 860 | else if (address == 0x3008) |
| 855 | 861 | { |
| 856 | | return geo_read_start_address; |
| 862 | return state->geo_read_start_address; |
| 857 | 863 | } |
| 858 | 864 | |
| 859 | 865 | // fatalerror("geo_r: %08X, %08X\n", address, mem_mask); |
| r10427 | r10428 | |
| 864 | 870 | |
| 865 | 871 | static WRITE32_HANDLER( geo_w ) |
| 866 | 872 | { |
| 873 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 867 | 874 | int address = offset * 4; |
| 868 | 875 | |
| 869 | 876 | if (address < 0x1000) |
| r10427 | r10428 | |
| 877 | 884 | for (i=0; i < 4; i++) |
| 878 | 885 | { |
| 879 | 886 | mame_printf_debug(" %08X: %08X %08X %08X %08X\n", 0x900000+(a*4)+(i*16), |
| 880 | | model2_bufferram[a+(i*4)+0], model2_bufferram[a+(i*4)+1], model2_bufferram[a+(i*4)+2], model2_bufferram[a+(i*4)+3]); |
| 887 | state->bufferram[a+(i*4)+0], state->bufferram[a+(i*4)+1], state->bufferram[a+(i*4)+2], state->bufferram[a+(i*4)+3]); |
| 881 | 888 | } |
| 882 | 889 | } |
| 883 | 890 | else |
| r10427 | r10428 | |
| 901 | 908 | UINT32 r = 0; |
| 902 | 909 | r |= data & 0x800fffff; |
| 903 | 910 | r |= ((address >> 4) & 0x3f) << 23; |
| 904 | | push_geo_data(r); |
| 911 | push_geo_data(state, r); |
| 905 | 912 | } |
| 906 | 913 | else |
| 907 | 914 | { |
| r10427 | r10428 | |
| 910 | 917 | UINT32 r = 0; |
| 911 | 918 | r |= data & 0x000fffff; |
| 912 | 919 | r |= ((address >> 4) & 0x3f) << 23; |
| 913 | | push_geo_data(r); |
| 920 | push_geo_data(state, r); |
| 914 | 921 | } |
| 915 | 922 | } |
| 916 | 923 | } |
| 917 | 924 | else if (address == 0x1008) |
| 918 | 925 | { |
| 919 | 926 | //mame_printf_debug("GEO: Write Start Address: %08X\n", data); |
| 920 | | geo_write_start_address = data & 0xfffff; |
| 927 | state->geo_write_start_address = data & 0xfffff; |
| 921 | 928 | } |
| 922 | 929 | else if (address == 0x3008) |
| 923 | 930 | { |
| 924 | 931 | //mame_printf_debug("GEO: Read Start Address: %08X\n", data); |
| 925 | | geo_read_start_address = data & 0xfffff; |
| 932 | state->geo_read_start_address = data & 0xfffff; |
| 926 | 933 | } |
| 927 | 934 | else |
| 928 | 935 | { |
| r10427 | r10428 | |
| 960 | 967 | |
| 961 | 968 | static READ32_HANDLER(model2_irq_r) |
| 962 | 969 | { |
| 970 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 963 | 971 | i960_noburst(space->cpu); |
| 964 | 972 | |
| 965 | 973 | if (offset) |
| 966 | 974 | { |
| 967 | | return model2_intena; |
| 975 | return state->intena; |
| 968 | 976 | } |
| 969 | 977 | |
| 970 | | return model2_intreq; |
| 978 | return state->intreq; |
| 971 | 979 | } |
| 972 | 980 | |
| 973 | 981 | static WRITE32_HANDLER(model2_irq_w) |
| 974 | 982 | { |
| 983 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 975 | 984 | i960_noburst(space->cpu); |
| 976 | 985 | |
| 977 | 986 | if (offset) |
| 978 | 987 | { |
| 979 | | COMBINE_DATA(&model2_intena); |
| 988 | COMBINE_DATA(&state->intena); |
| 980 | 989 | return; |
| 981 | 990 | } |
| 982 | 991 | |
| 983 | | model2_intreq &= data; |
| 992 | state->intreq &= data; |
| 984 | 993 | } |
| 985 | 994 | |
| 986 | | static int to_68k; |
| 987 | 995 | |
| 988 | 996 | static int snd_68k_ready_r(address_space *space) |
| 989 | 997 | { |
| r10427 | r10428 | |
| 1000 | 1008 | |
| 1001 | 1009 | static void snd_latch_to_68k_w(address_space *space, int data) |
| 1002 | 1010 | { |
| 1011 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1003 | 1012 | if (!snd_68k_ready_r(space)) |
| 1004 | 1013 | { |
| 1005 | 1014 | cpu_spinuntil_time(space->cpu, attotime::from_usec(40)); |
| 1006 | 1015 | } |
| 1007 | 1016 | |
| 1008 | | to_68k = data; |
| 1017 | state->to_68k = data; |
| 1009 | 1018 | |
| 1010 | 1019 | cputag_set_input_line(space->machine, "audiocpu", 2, HOLD_LINE); |
| 1011 | 1020 | |
| r10427 | r10428 | |
| 1059 | 1068 | { |
| 1060 | 1069 | 0x43,0x66,0x54,0x11,0x99,0xfe,0xcc,0x8e,0xdd,0x87,0x11,0x89,0x22,0xdf,0x44,0x09 |
| 1061 | 1070 | }; |
| 1062 | | static int protstate, protpos; |
| 1063 | | static UINT8 protram[256]; |
| 1064 | 1071 | |
| 1065 | 1072 | static READ32_HANDLER( model2_prot_r ) |
| 1066 | 1073 | { |
| 1067 | | static int a = 0; |
| 1074 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1068 | 1075 | UINT32 retval = 0; |
| 1069 | 1076 | |
| 1070 | 1077 | if (offset == 0x10000/4) |
| r10427 | r10428 | |
| 1074 | 1081 | } |
| 1075 | 1082 | else if (offset == 0x1000e/4) |
| 1076 | 1083 | { |
| 1077 | | retval = protram[protstate+1] | protram[protstate]<<8; |
| 1084 | retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8; |
| 1078 | 1085 | retval <<= 16; |
| 1079 | | protstate+=2; |
| 1086 | state->protstate+=2; |
| 1080 | 1087 | } |
| 1081 | 1088 | else if (offset == 0x7ff8/4) |
| 1082 | 1089 | { |
| 1083 | | retval = protram[protstate+1] | protram[protstate]<<8; |
| 1084 | | protstate+=2; |
| 1090 | retval = state->protram[state->protstate+1] | state->protram[state->protstate]<<8; |
| 1091 | state->protstate+=2; |
| 1085 | 1092 | } |
| 1086 | 1093 | else if (offset == 0x400c/4) |
| 1087 | 1094 | { |
| 1088 | | a = !a; |
| 1089 | | if (a) |
| 1095 | state->prot_a = !state->prot_a; |
| 1096 | if (state->prot_a) |
| 1090 | 1097 | return 0xffff; |
| 1091 | 1098 | else |
| 1092 | 1099 | return 0xfff0; |
| r10427 | r10428 | |
| 1098 | 1105 | |
| 1099 | 1106 | static WRITE32_HANDLER( model2_prot_w ) |
| 1100 | 1107 | { |
| 1108 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1101 | 1109 | if (mem_mask == 0xffff0000) |
| 1102 | 1110 | { |
| 1103 | 1111 | data >>= 16; |
| r10427 | r10428 | |
| 1105 | 1113 | |
| 1106 | 1114 | if (offset == 0x10008/4) |
| 1107 | 1115 | { |
| 1108 | | protpos = data; |
| 1116 | state->protpos = data; |
| 1109 | 1117 | } |
| 1110 | 1118 | else if (offset == 0x1000c/4) |
| 1111 | 1119 | { |
| r10427 | r10428 | |
| 1113 | 1121 | { |
| 1114 | 1122 | // dynamcop |
| 1115 | 1123 | case 0x7700: |
| 1116 | | strcpy((char *)protram+2, "UCHIDA MOMOKA "); |
| 1124 | strcpy((char *)state->protram+2, "UCHIDA MOMOKA "); |
| 1117 | 1125 | break; |
| 1118 | 1126 | |
| 1119 | 1127 | // dynamcop |
| 1120 | 1128 | case 0x1326: |
| 1121 | | protstate = 0; |
| 1122 | | memcpy(protram+2, DCOPKey1326, sizeof(DCOPKey1326)); |
| 1129 | state->protstate = 0; |
| 1130 | memcpy(state->protram+2, DCOPKey1326, sizeof(DCOPKey1326)); |
| 1123 | 1131 | break; |
| 1124 | 1132 | |
| 1125 | 1133 | // zerogun |
| r10427 | r10428 | |
| 1138 | 1146 | case 0x98CC: |
| 1139 | 1147 | case 0x3422: |
| 1140 | 1148 | case 0x10: |
| 1141 | | protstate = 0; |
| 1142 | | memcpy(protram+2, ZGUNProt+((2*protpos)/12)*8, sizeof(ZGUNProt)); |
| 1149 | state->protstate = 0; |
| 1150 | memcpy(state->protram+2, ZGUNProt+((2*state->protpos)/12)*8, sizeof(ZGUNProt)); |
| 1143 | 1151 | break; |
| 1144 | 1152 | |
| 1145 | 1153 | // pltkids |
| 1146 | 1154 | case 0x7140: |
| 1147 | | protstate = 0; |
| 1148 | | strcpy((char *)protram+2, "98-PILOT "); |
| 1155 | state->protstate = 0; |
| 1156 | strcpy((char *)state->protram+2, "98-PILOT "); |
| 1149 | 1157 | break; |
| 1150 | 1158 | |
| 1151 | 1159 | default: |
| 1152 | | protstate = 0; |
| 1160 | state->protstate = 0; |
| 1153 | 1161 | break; |
| 1154 | 1162 | } |
| 1155 | 1163 | } |
| r10427 | r10428 | |
| 1157 | 1165 | { |
| 1158 | 1166 | if (data == 0) |
| 1159 | 1167 | { |
| 1160 | | protstate = 0; |
| 1161 | | strcpy((char *)protram, " TECMO LTD. DEAD OR ALIVE 1996.10.22 VER. 1.00"); |
| 1168 | state->protstate = 0; |
| 1169 | strcpy((char *)state->protram, " TECMO LTD. DEAD OR ALIVE 1996.10.22 VER. 1.00"); |
| 1162 | 1170 | } |
| 1163 | 1171 | } |
| 1164 | 1172 | else logerror("Unhandled Protection WRITE %x @ %x mask %x (PC=%x)\n", data, offset, mem_mask, cpu_get_pc(space->cpu)); |
| r10427 | r10428 | |
| 1167 | 1175 | |
| 1168 | 1176 | /* Daytona "To The MAXX" PIC protection simulation */ |
| 1169 | 1177 | |
| 1170 | | static int model2_maxxstate = 0; |
| 1171 | 1178 | |
| 1172 | 1179 | static READ32_HANDLER( maxx_r ) |
| 1173 | 1180 | { |
| 1181 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1174 | 1182 | UINT32 *ROM = (UINT32 *)space->machine->region("maincpu")->base(); |
| 1175 | 1183 | |
| 1176 | 1184 | if (offset <= 0x1f/4) |
| r10427 | r10428 | |
| 1179 | 1187 | if (mem_mask == 0xffff0000) |
| 1180 | 1188 | { |
| 1181 | 1189 | // 16-bit protection reads |
| 1182 | | model2_maxxstate++; |
| 1183 | | model2_maxxstate &= 0xf; |
| 1184 | | if (!model2_maxxstate) |
| 1190 | state->maxxstate++; |
| 1191 | state->maxxstate &= 0xf; |
| 1192 | if (!state->maxxstate) |
| 1185 | 1193 | { |
| 1186 | 1194 | return 0x00070000; |
| 1187 | 1195 | } |
| 1188 | 1196 | else |
| 1189 | 1197 | { |
| 1190 | | if (model2_maxxstate & 0x2) |
| 1198 | if (state->maxxstate & 0x2) |
| 1191 | 1199 | { |
| 1192 | 1200 | return 0; |
| 1193 | 1201 | } |
| r10427 | r10428 | |
| 1212 | 1220 | |
| 1213 | 1221 | /* Network board emulation */ |
| 1214 | 1222 | |
| 1215 | | static UINT32 model2_netram[0x8000/4]; |
| 1216 | 1223 | |
| 1217 | | static int zflagi, zflag, sysres; |
| 1218 | 1224 | |
| 1219 | 1225 | static READ32_HANDLER( network_r ) |
| 1220 | 1226 | { |
| 1227 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1221 | 1228 | if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000)) |
| 1222 | 1229 | { |
| 1223 | 1230 | return 0xffffffff; |
| r10427 | r10428 | |
| 1225 | 1232 | |
| 1226 | 1233 | if (offset < 0x4000/4) |
| 1227 | 1234 | { |
| 1228 | | return model2_netram[offset]; |
| 1235 | return state->netram[offset]; |
| 1229 | 1236 | } |
| 1230 | 1237 | |
| 1231 | 1238 | if (mem_mask == 0x00ff0000) |
| 1232 | 1239 | { |
| 1233 | | return sysres<<16; |
| 1240 | return state->sysres<<16; |
| 1234 | 1241 | } |
| 1235 | 1242 | else if (mem_mask == 0x000000ff) |
| 1236 | 1243 | { |
| 1237 | | return zflagi; |
| 1244 | return state->zflagi; |
| 1238 | 1245 | } |
| 1239 | 1246 | |
| 1240 | 1247 | return 0xffffffff; |
| r10427 | r10428 | |
| 1242 | 1249 | |
| 1243 | 1250 | static WRITE32_HANDLER( network_w ) |
| 1244 | 1251 | { |
| 1252 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1245 | 1253 | if ((mem_mask == 0xffffffff) || (mem_mask == 0x0000ffff) || (mem_mask == 0xffff0000)) |
| 1246 | 1254 | { |
| 1247 | | COMBINE_DATA(&model2_netram[offset+0x4000/4]); |
| 1255 | COMBINE_DATA(&state->netram[offset+0x4000/4]); |
| 1248 | 1256 | return; |
| 1249 | 1257 | } |
| 1250 | 1258 | |
| 1251 | 1259 | if (offset < 0x4000/4) |
| 1252 | 1260 | { |
| 1253 | | COMBINE_DATA(&model2_netram[offset]); |
| 1261 | COMBINE_DATA(&state->netram[offset]); |
| 1254 | 1262 | return; |
| 1255 | 1263 | } |
| 1256 | 1264 | |
| 1257 | 1265 | if (mem_mask == 0x00ff0000) |
| 1258 | 1266 | { |
| 1259 | | sysres = data>>16; |
| 1267 | state->sysres = data>>16; |
| 1260 | 1268 | } |
| 1261 | 1269 | else if (mem_mask == 0x000000ff) |
| 1262 | 1270 | { |
| 1263 | | zflagi = data; |
| 1264 | | zflag = 0; |
| 1265 | | if (data & 0x01) zflag |= 0x80; |
| 1266 | | if (data & 0x80) zflag |= 0x01; |
| 1271 | state->zflagi = data; |
| 1272 | state->zflag = 0; |
| 1273 | if (data & 0x01) state->zflag |= 0x80; |
| 1274 | if (data & 0x80) state->zflag |= 0x01; |
| 1267 | 1275 | } |
| 1268 | 1276 | } |
| 1269 | 1277 | |
| r10427 | r10428 | |
| 1294 | 1302 | |
| 1295 | 1303 | static WRITE32_HANDLER(model2o_tex_w0) |
| 1296 | 1304 | { |
| 1305 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1297 | 1306 | if ( (offset & 1) == 0 ) |
| 1298 | 1307 | { |
| 1299 | | model2_textureram0[offset>>1] &= 0xffff0000; |
| 1300 | | model2_textureram0[offset>>1] |= data & 0xffff; |
| 1308 | state->textureram0[offset>>1] &= 0xffff0000; |
| 1309 | state->textureram0[offset>>1] |= data & 0xffff; |
| 1301 | 1310 | } |
| 1302 | 1311 | else |
| 1303 | 1312 | { |
| 1304 | | model2_textureram0[offset>>1] &= 0x0000ffff; |
| 1305 | | model2_textureram0[offset>>1] |= (data & 0xffff) << 16; |
| 1313 | state->textureram0[offset>>1] &= 0x0000ffff; |
| 1314 | state->textureram0[offset>>1] |= (data & 0xffff) << 16; |
| 1306 | 1315 | } |
| 1307 | 1316 | } |
| 1308 | 1317 | |
| 1309 | 1318 | static WRITE32_HANDLER(model2o_tex_w1) |
| 1310 | 1319 | { |
| 1320 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1311 | 1321 | if ( (offset & 1) == 0 ) |
| 1312 | 1322 | { |
| 1313 | | model2_textureram1[offset>>1] &= 0xffff0000; |
| 1314 | | model2_textureram1[offset>>1] |= data & 0xffff; |
| 1323 | state->textureram1[offset>>1] &= 0xffff0000; |
| 1324 | state->textureram1[offset>>1] |= data & 0xffff; |
| 1315 | 1325 | } |
| 1316 | 1326 | else |
| 1317 | 1327 | { |
| 1318 | | model2_textureram1[offset>>1] &= 0x0000ffff; |
| 1319 | | model2_textureram1[offset>>1] |= (data & 0xffff) << 16; |
| 1328 | state->textureram1[offset>>1] &= 0x0000ffff; |
| 1329 | state->textureram1[offset>>1] |= (data & 0xffff) << 16; |
| 1320 | 1330 | } |
| 1321 | 1331 | } |
| 1322 | 1332 | |
| 1323 | 1333 | static WRITE32_HANDLER(model2o_luma_w) |
| 1324 | 1334 | { |
| 1335 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1325 | 1336 | if ( (offset & 1) == 0 ) |
| 1326 | 1337 | { |
| 1327 | | model2_lumaram[offset>>1] &= 0xffff0000; |
| 1328 | | model2_lumaram[offset>>1] |= data & 0xffff; |
| 1338 | state->lumaram[offset>>1] &= 0xffff0000; |
| 1339 | state->lumaram[offset>>1] |= data & 0xffff; |
| 1329 | 1340 | } |
| 1330 | 1341 | else |
| 1331 | 1342 | { |
| 1332 | | model2_lumaram[offset>>1] &= 0x0000ffff; |
| 1333 | | model2_lumaram[offset>>1] |= (data & 0xffff) << 16; |
| 1343 | state->lumaram[offset>>1] &= 0x0000ffff; |
| 1344 | state->lumaram[offset>>1] |= (data & 0xffff) << 16; |
| 1334 | 1345 | } |
| 1335 | 1346 | } |
| 1336 | 1347 | |
| 1337 | 1348 | static WRITE32_HANDLER(model2_3d_zclip_w) |
| 1338 | 1349 | { |
| 1339 | | model2_3d_set_zclip( data & 0xFF ); |
| 1350 | model2_3d_set_zclip( space->machine, data & 0xFF ); |
| 1340 | 1351 | } |
| 1341 | 1352 | |
| 1342 | 1353 | /* common map for all Model 2 versions */ |
| 1343 | 1354 | static ADDRESS_MAP_START( model2_base_mem, ADDRESS_SPACE_PROGRAM, 32 ) |
| 1344 | 1355 | AM_RANGE(0x00000000, 0x001fffff) AM_ROM AM_WRITENOP |
| 1345 | 1356 | |
| 1346 | | AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE(&model2_workram) |
| 1357 | AM_RANGE(0x00500000, 0x005fffff) AM_RAM AM_BASE_MEMBER(model2_state, workram) |
| 1347 | 1358 | |
| 1348 | 1359 | AM_RANGE(0x00800000, 0x00803fff) AM_READWRITE(geo_r, geo_w) |
| 1349 | 1360 | //AM_RANGE(0x00800010, 0x00800013) AM_WRITENOP |
| r10427 | r10428 | |
| 1352 | 1363 | |
| 1353 | 1364 | //AM_RANGE(0x00880000, 0x00883fff) AM_WRITE(copro_w) |
| 1354 | 1365 | |
| 1355 | | AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE(&model2_bufferram) |
| 1366 | AM_RANGE(0x00900000, 0x0097ffff) AM_RAM AM_BASE_MEMBER(model2_state, bufferram) |
| 1356 | 1367 | |
| 1357 | 1368 | |
| 1358 | 1369 | AM_RANGE(0x00980004, 0x00980007) AM_READ(fifoctl_r) |
| r10427 | r10428 | |
| 1371 | 1382 | AM_RANGE(0x01100000, 0x0110ffff) AM_READWRITE(sys24_tile32_r, sys24_tile32_w) AM_MIRROR(0x10000) |
| 1372 | 1383 | AM_RANGE(0x01180000, 0x011fffff) AM_READWRITE(sys24_char32_r, sys24_char32_w) AM_MIRROR(0x100000) |
| 1373 | 1384 | |
| 1374 | | AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE(&model2_paletteram32) |
| 1375 | | AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE(&model2_colorxlat) |
| 1385 | AM_RANGE(0x01800000, 0x01803fff) AM_RAM_WRITE(pal32_w) AM_BASE_MEMBER(model2_state, paletteram32) |
| 1386 | AM_RANGE(0x01810000, 0x0181bfff) AM_RAM AM_BASE_MEMBER(model2_state, colorxlat) |
| 1376 | 1387 | AM_RANGE(0x0181c000, 0x0181c003) AM_WRITE(model2_3d_zclip_w) |
| 1377 | 1388 | AM_RANGE(0x01a10000, 0x01a1ffff) AM_READWRITE(network_r, network_w) |
| 1378 | 1389 | AM_RANGE(0x01d00000, 0x01d03fff) AM_RAM AM_SHARE("backup1") // Backup sram |
| r10427 | r10428 | |
| 1402 | 1413 | AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) |
| 1403 | 1414 | AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2o_serial_w ) |
| 1404 | 1415 | |
| 1405 | | AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0) // texture RAM 0 |
| 1406 | | AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1) // texture RAM 1 |
| 1407 | | AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM |
| 1416 | AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 |
| 1417 | AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 |
| 1418 | AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM |
| 1408 | 1419 | |
| 1409 | 1420 | AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") |
| 1410 | 1421 | AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") |
| r10427 | r10428 | |
| 1432 | 1443 | AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) |
| 1433 | 1444 | AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) |
| 1434 | 1445 | |
| 1435 | | AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE(&model2_textureram0) // texture RAM 0 |
| 1436 | | AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE(&model2_textureram1) // texture RAM 1 |
| 1437 | | AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE(&model2_lumaram) // polygon "luma" RAM |
| 1446 | AM_RANGE(0x12000000, 0x121fffff) AM_RAM_WRITE(model2o_tex_w0) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 |
| 1447 | AM_RANGE(0x12400000, 0x125fffff) AM_RAM_WRITE(model2o_tex_w1) AM_MIRROR(0x200000) AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 |
| 1448 | AM_RANGE(0x12800000, 0x1281ffff) AM_RAM_WRITE(model2o_luma_w) AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM |
| 1438 | 1449 | |
| 1439 | 1450 | AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) |
| 1440 | 1451 | AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") |
| r10427 | r10428 | |
| 1466 | 1477 | |
| 1467 | 1478 | AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) |
| 1468 | 1479 | |
| 1469 | | AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE(&model2_textureram0) // texture RAM 0 (2b/2c) |
| 1470 | | AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE(&model2_textureram1) // texture RAM 1 (2b/2c) |
| 1471 | | AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE(&model2_lumaram) // polygon "luma" RAM (2b/2c) |
| 1480 | AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 (2b/2c) |
| 1481 | AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 (2b/2c) |
| 1482 | AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM (2b/2c) |
| 1472 | 1483 | |
| 1473 | 1484 | |
| 1474 | 1485 | AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) |
| r10427 | r10428 | |
| 1493 | 1504 | AM_RANGE(0x00980008, 0x0098000b) AM_WRITE( geo_ctl1_w ) |
| 1494 | 1505 | AM_RANGE(0x009c0000, 0x009cffff) AM_READWRITE( model2_serial_r, model2_serial_w ) |
| 1495 | 1506 | |
| 1496 | | AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE(&model2_textureram0) // texture RAM 0 (2b/2c) |
| 1497 | | AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE(&model2_textureram1) // texture RAM 1 (2b/2c) |
| 1498 | | AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE(&model2_lumaram) // polygon "luma" RAM (2b/2c) |
| 1507 | AM_RANGE(0x11000000, 0x111fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram0) // texture RAM 0 (2b/2c) |
| 1508 | AM_RANGE(0x11200000, 0x113fffff) AM_RAM AM_BASE_MEMBER(model2_state, textureram1) // texture RAM 1 (2b/2c) |
| 1509 | AM_RANGE(0x11400000, 0x1140ffff) AM_RAM AM_BASE_MEMBER(model2_state, lumaram) // polygon "luma" RAM (2b/2c) |
| 1499 | 1510 | |
| 1500 | 1511 | AM_RANGE(0x01c00000, 0x01c00003) AM_READ_PORT("1c00000") AM_WRITE( ctrl0_w ) |
| 1501 | 1512 | AM_RANGE(0x01c00004, 0x01c00007) AM_READ_PORT("1c00004") |
| r10427 | r10428 | |
| 1777 | 1788 | |
| 1778 | 1789 | static INTERRUPT_GEN(model2_interrupt) |
| 1779 | 1790 | { |
| 1791 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 1780 | 1792 | switch (cpu_getiloops(device)) |
| 1781 | 1793 | { |
| 1782 | 1794 | case 0: |
| 1783 | | model2_intreq |= (1<<10); |
| 1784 | | if (model2_intena & (1<<10)) |
| 1795 | state->intreq |= (1<<10); |
| 1796 | if (state->intena & (1<<10)) |
| 1785 | 1797 | { |
| 1786 | 1798 | cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE); |
| 1787 | 1799 | } |
| 1788 | 1800 | break; |
| 1789 | 1801 | case 1: |
| 1790 | | model2_intreq |= (1<<0); |
| 1791 | | if (model2_intena & (1<<0)) |
| 1802 | state->intreq |= (1<<0); |
| 1803 | if (state->intena & (1<<0)) |
| 1792 | 1804 | { |
| 1793 | 1805 | cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE); |
| 1794 | 1806 | } |
| r10427 | r10428 | |
| 1798 | 1810 | |
| 1799 | 1811 | static INTERRUPT_GEN(model2c_interrupt) |
| 1800 | 1812 | { |
| 1813 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 1801 | 1814 | switch (cpu_getiloops(device)) |
| 1802 | 1815 | { |
| 1803 | 1816 | case 0: |
| 1804 | | model2_intreq |= (1<<10); |
| 1805 | | if (model2_intena & (1<<10)) |
| 1817 | state->intreq |= (1<<10); |
| 1818 | if (state->intena & (1<<10)) |
| 1806 | 1819 | cpu_set_input_line(device, I960_IRQ3, ASSERT_LINE); |
| 1807 | 1820 | break; |
| 1808 | 1821 | case 1: |
| 1809 | | model2_intreq |= (1<<2); |
| 1810 | | if (model2_intena & (1<<2)) |
| 1822 | state->intreq |= (1<<2); |
| 1823 | if (state->intena & (1<<2)) |
| 1811 | 1824 | cpu_set_input_line(device, I960_IRQ2, ASSERT_LINE); |
| 1812 | 1825 | |
| 1813 | 1826 | break; |
| 1814 | 1827 | case 2: |
| 1815 | | model2_intreq |= (1<<0); |
| 1816 | | if (model2_intena & (1<<0)) |
| 1828 | state->intreq |= (1<<0); |
| 1829 | if (state->intena & (1<<0)) |
| 1817 | 1830 | cpu_set_input_line(device, I960_IRQ0, ASSERT_LINE); |
| 1818 | 1831 | break; |
| 1819 | 1832 | } |
| r10427 | r10428 | |
| 1823 | 1836 | |
| 1824 | 1837 | static READ16_HANDLER( m1_snd_68k_latch_r ) |
| 1825 | 1838 | { |
| 1826 | | return to_68k; |
| 1839 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1840 | return state->to_68k; |
| 1827 | 1841 | } |
| 1828 | 1842 | |
| 1829 | 1843 | static READ16_HANDLER( m1_snd_v60_ready_r ) |
| r10427 | r10428 | |
| 1880 | 1894 | } |
| 1881 | 1895 | |
| 1882 | 1896 | static ADDRESS_MAP_START( model2_snd, ADDRESS_SPACE_PROGRAM, 16 ) |
| 1883 | | AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE(&model2_soundram) |
| 1897 | AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("audiocpu", 0) AM_BASE_MEMBER(model2_state, soundram) |
| 1884 | 1898 | AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp", scsp_r, scsp_w) |
| 1885 | 1899 | AM_RANGE(0x400000, 0x400001) AM_WRITE(model2snd_ctrl) |
| 1886 | 1900 | AM_RANGE(0x600000, 0x67ffff) AM_ROM AM_REGION("audiocpu", 0x80000) |
| r10427 | r10428 | |
| 1889 | 1903 | AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5") |
| 1890 | 1904 | ADDRESS_MAP_END |
| 1891 | 1905 | |
| 1892 | | static int scsp_last_line = 0; |
| 1893 | 1906 | |
| 1894 | 1907 | static void scsp_irq(device_t *device, int irq) |
| 1895 | 1908 | { |
| 1909 | model2_state *state = device->machine->driver_data<model2_state>(); |
| 1896 | 1910 | if (irq > 0) |
| 1897 | 1911 | { |
| 1898 | | scsp_last_line = irq; |
| 1912 | state->scsp_last_line = irq; |
| 1899 | 1913 | cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE); |
| 1900 | 1914 | } |
| 1901 | 1915 | else |
| r10427 | r10428 | |
| 1930 | 1944 | |
| 1931 | 1945 | static READ32_HANDLER(copro_sharc_buffer_r) |
| 1932 | 1946 | { |
| 1933 | | return model2_bufferram[offset & 0x7fff]; |
| 1947 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1948 | return state->bufferram[offset & 0x7fff]; |
| 1934 | 1949 | } |
| 1935 | 1950 | |
| 1936 | 1951 | static WRITE32_HANDLER(copro_sharc_buffer_w) |
| 1937 | 1952 | { |
| 1953 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1938 | 1954 | //mame_printf_debug("sharc_buffer_w: %08X at %08X, %08X, %f\n", offset, cpu_get_pc(space->cpu), data, *(float*)&data); |
| 1939 | | model2_bufferram[offset & 0x7fff] = data; |
| 1955 | state->bufferram[offset & 0x7fff] = data; |
| 1940 | 1956 | } |
| 1941 | 1957 | |
| 1942 | 1958 | static ADDRESS_MAP_START( copro_sharc_map, ADDRESS_SPACE_DATA, 32 ) |
| r10427 | r10428 | |
| 1956 | 1972 | |
| 1957 | 1973 | static READ32_HANDLER(copro_tgp_buffer_r) |
| 1958 | 1974 | { |
| 1959 | | return model2_bufferram[offset & 0x7fff]; |
| 1975 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1976 | return state->bufferram[offset & 0x7fff]; |
| 1960 | 1977 | } |
| 1961 | 1978 | |
| 1962 | 1979 | static WRITE32_HANDLER(copro_tgp_buffer_w) |
| 1963 | 1980 | { |
| 1964 | | model2_bufferram[offset&0x7fff] = data; |
| 1981 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 1982 | state->bufferram[offset&0x7fff] = data; |
| 1965 | 1983 | } |
| 1966 | 1984 | |
| 1967 | 1985 | static ADDRESS_MAP_START( copro_tgp_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 1968 | | AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE(&tgp_program) |
| 1986 | AM_RANGE(0x00000000, 0x00007fff) AM_RAM AM_BASE_MEMBER(model2_state, tgp_program) |
| 1969 | 1987 | AM_RANGE(0x00400000, 0x00407fff) AM_READWRITE(copro_tgp_buffer_r, copro_tgp_buffer_w) |
| 1970 | 1988 | AM_RANGE(0xff800000, 0xff9fffff) AM_ROM AM_REGION("tgp", 0) |
| 1971 | 1989 | ADDRESS_MAP_END |
| r10427 | r10428 | |
| 1982 | 2000 | |
| 1983 | 2001 | |
| 1984 | 2002 | /* original Model 2 */ |
| 1985 | | static MACHINE_CONFIG_START( model2o, driver_device ) |
| 2003 | static MACHINE_CONFIG_START( model2o, model2_state ) |
| 1986 | 2004 | MCFG_CPU_ADD("maincpu", I960, 25000000) |
| 1987 | 2005 | MCFG_CPU_PROGRAM_MAP(model2o_mem) |
| 1988 | 2006 | MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) |
| r10427 | r10428 | |
| 1994 | 2012 | MCFG_CPU_CONFIG(tgp_config) |
| 1995 | 2013 | MCFG_CPU_PROGRAM_MAP(copro_tgp_map) |
| 1996 | 2014 | |
| 2015 | MCFG_MACHINE_START(model2) |
| 1997 | 2016 | MCFG_MACHINE_RESET(model2o) |
| 1998 | 2017 | |
| 1999 | 2018 | MCFG_EEPROM_93C46_ADD("eeprom") |
| r10427 | r10428 | |
| 2039 | 2058 | MACHINE_CONFIG_END |
| 2040 | 2059 | |
| 2041 | 2060 | /* 2A-CRX */ |
| 2042 | | static MACHINE_CONFIG_START( model2a, driver_device ) |
| 2061 | static MACHINE_CONFIG_START( model2a, model2_state ) |
| 2043 | 2062 | MCFG_CPU_ADD("maincpu", I960, 25000000) |
| 2044 | 2063 | MCFG_CPU_PROGRAM_MAP(model2a_crx_mem) |
| 2045 | 2064 | MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) |
| r10427 | r10428 | |
| 2051 | 2070 | MCFG_CPU_CONFIG(tgp_config) |
| 2052 | 2071 | MCFG_CPU_PROGRAM_MAP(copro_tgp_map) |
| 2053 | 2072 | |
| 2073 | MCFG_MACHINE_START(model2) |
| 2054 | 2074 | MCFG_MACHINE_RESET(model2) |
| 2055 | 2075 | |
| 2056 | 2076 | MCFG_EEPROM_93C46_ADD("eeprom") |
| r10427 | r10428 | |
| 2089 | 2109 | |
| 2090 | 2110 | static READ8_HANDLER( driveio_port_r ) |
| 2091 | 2111 | { |
| 2092 | | return driveio_comm_data; |
| 2112 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 2113 | return state->driveio_comm_data; |
| 2093 | 2114 | } |
| 2094 | 2115 | |
| 2095 | 2116 | static WRITE8_HANDLER( driveio_port_w ) |
| r10427 | r10428 | |
| 2134 | 2155 | }; |
| 2135 | 2156 | |
| 2136 | 2157 | /* 2B-CRX */ |
| 2137 | | static MACHINE_CONFIG_START( model2b, driver_device ) |
| 2158 | static MACHINE_CONFIG_START( model2b, model2_state ) |
| 2138 | 2159 | MCFG_CPU_ADD("maincpu", I960, 25000000) |
| 2139 | 2160 | MCFG_CPU_PROGRAM_MAP(model2b_crx_mem) |
| 2140 | 2161 | MCFG_CPU_VBLANK_INT_HACK(model2_interrupt,2) |
| r10427 | r10428 | |
| 2152 | 2173 | |
| 2153 | 2174 | MCFG_QUANTUM_TIME(attotime::from_hz(18000)) |
| 2154 | 2175 | |
| 2176 | MCFG_MACHINE_START(model2) |
| 2155 | 2177 | MCFG_MACHINE_RESET(model2b) |
| 2156 | 2178 | |
| 2157 | 2179 | MCFG_EEPROM_93C46_ADD("eeprom") |
| r10427 | r10428 | |
| 2189 | 2211 | MACHINE_CONFIG_END |
| 2190 | 2212 | |
| 2191 | 2213 | /* 2C-CRX */ |
| 2192 | | static MACHINE_CONFIG_START( model2c, driver_device ) |
| 2214 | static MACHINE_CONFIG_START( model2c, model2_state ) |
| 2193 | 2215 | MCFG_CPU_ADD("maincpu", I960, 25000000) |
| 2194 | 2216 | MCFG_CPU_PROGRAM_MAP(model2c_crx_mem) |
| 2195 | 2217 | MCFG_CPU_VBLANK_INT_HACK(model2c_interrupt,3) |
| r10427 | r10428 | |
| 2197 | 2219 | MCFG_CPU_ADD("audiocpu", M68000, 12000000) |
| 2198 | 2220 | MCFG_CPU_PROGRAM_MAP(model2_snd) |
| 2199 | 2221 | |
| 2222 | MCFG_MACHINE_START(model2) |
| 2200 | 2223 | MCFG_MACHINE_RESET(model2c) |
| 2201 | 2224 | |
| 2202 | 2225 | MCFG_EEPROM_93C46_ADD("eeprom") |
| r10427 | r10428 | |
| 4971 | 4994 | |
| 4972 | 4995 | static DRIVER_INIT( genprot ) |
| 4973 | 4996 | { |
| 4997 | model2_state *state = machine->driver_data<model2_state>(); |
| 4974 | 4998 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); |
| 4975 | | protstate = protpos = 0; |
| 4999 | state->protstate = state->protpos = 0; |
| 4976 | 5000 | } |
| 4977 | 5001 | |
| 4978 | 5002 | static DRIVER_INIT( pltkids ) |
| 4979 | 5003 | { |
| 5004 | model2_state *state = machine->driver_data<model2_state>(); |
| 4980 | 5005 | UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); |
| 4981 | 5006 | |
| 4982 | 5007 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); |
| 4983 | | protstate = protpos = 0; |
| 5008 | state->protstate = state->protpos = 0; |
| 4984 | 5009 | |
| 4985 | 5010 | // fix bug in program: it destroys the interrupt table and never fixes it |
| 4986 | 5011 | ROM[0x730/4] = 0x08000004; |
| r10427 | r10428 | |
| 4988 | 5013 | |
| 4989 | 5014 | static DRIVER_INIT( zerogun ) |
| 4990 | 5015 | { |
| 5016 | model2_state *state = machine->driver_data<model2_state>(); |
| 4991 | 5017 | UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); |
| 4992 | 5018 | |
| 4993 | 5019 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); |
| 4994 | | protstate = protpos = 0; |
| 5020 | state->protstate = state->protpos = 0; |
| 4995 | 5021 | |
| 4996 | 5022 | // fix bug in program: it destroys the interrupt table and never fixes it |
| 4997 | 5023 | ROM[0x700/4] = 0x08000004; |
| r10427 | r10428 | |
| 5003 | 5029 | } |
| 5004 | 5030 | |
| 5005 | 5031 | /* very crude support for let the game set itself into stand-alone mode */ |
| 5006 | | static int jnet_time_out; |
| 5007 | 5032 | |
| 5008 | 5033 | static READ32_HANDLER( jaleco_network_r ) |
| 5009 | 5034 | { |
| 5035 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 5010 | 5036 | if(offset == 0x4000/4) |
| 5011 | 5037 | { |
| 5012 | | if(model2_netram[offset] == 0x00000000) |
| 5013 | | jnet_time_out = 0; |
| 5038 | if(state->netram[offset] == 0x00000000) |
| 5039 | state->jnet_time_out = 0; |
| 5014 | 5040 | |
| 5015 | | if((model2_netram[offset] & 0xffff) == 0x0001) |
| 5016 | | jnet_time_out++; |
| 5041 | if((state->netram[offset] & 0xffff) == 0x0001) |
| 5042 | state->jnet_time_out++; |
| 5017 | 5043 | |
| 5018 | | if(jnet_time_out > 0x80) |
| 5019 | | model2_netram[offset]|= 0x00800000; |
| 5044 | if(state->jnet_time_out > 0x80) |
| 5045 | state->netram[offset]|= 0x00800000; |
| 5020 | 5046 | |
| 5021 | | return model2_netram[offset]; |
| 5047 | return state->netram[offset]; |
| 5022 | 5048 | } |
| 5023 | 5049 | |
| 5024 | | return model2_netram[offset]; |
| 5050 | return state->netram[offset]; |
| 5025 | 5051 | } |
| 5026 | 5052 | |
| 5027 | 5053 | static WRITE32_HANDLER( jaleco_network_w ) |
| 5028 | 5054 | { |
| 5029 | | COMBINE_DATA(&model2_netram[offset]); |
| 5055 | model2_state *state = space->machine->driver_data<model2_state>(); |
| 5056 | COMBINE_DATA(&state->netram[offset]); |
| 5030 | 5057 | } |
| 5031 | 5058 | |
| 5032 | 5059 | static DRIVER_INIT( sgt24h ) |
| 5033 | 5060 | { |
| 5061 | model2_state *state = machine->driver_data<model2_state>(); |
| 5034 | 5062 | UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); |
| 5035 | 5063 | |
| 5036 | 5064 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); |
| 5037 | 5065 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01a10000, 0x01a1ffff, 0, 0, jaleco_network_r, jaleco_network_w); |
| 5038 | 5066 | |
| 5039 | | protstate = protpos = 0; |
| 5067 | state->protstate = state->protpos = 0; |
| 5040 | 5068 | |
| 5041 | 5069 | ROM[0x56578/4] = 0x08000004; |
| 5042 | 5070 | ROM[0x5b3e8/4] = 0x08000004; |
| r10427 | r10428 | |
| 5052 | 5080 | |
| 5053 | 5081 | static DRIVER_INIT( doa ) |
| 5054 | 5082 | { |
| 5083 | model2_state *state = machine->driver_data<model2_state>(); |
| 5055 | 5084 | UINT32 *ROM = (UINT32 *)machine->region("maincpu")->base(); |
| 5056 | 5085 | |
| 5057 | 5086 | memory_install_readwrite32_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x01d80000, 0x01dfffff, 0, 0, model2_prot_r, model2_prot_w); |
| 5058 | | protstate = protpos = 0; |
| 5087 | state->protstate = state->protpos = 0; |
| 5059 | 5088 | |
| 5060 | 5089 | ROM[0x630/4] = 0x08000004; |
| 5061 | 5090 | ROM[0x808/4] = 0x08000004; |
src/mame/drivers/segas32.c
| r10427 | r10428 | |
| 373 | 373 | * |
| 374 | 374 | *************************************/ |
| 375 | 375 | |
| 376 | | UINT8 *ga2_dpram; |
| 377 | | UINT16 *system32_workram; |
| 378 | | UINT16 *system32_protram; |
| 379 | 376 | |
| 380 | 377 | |
| 381 | 378 | |
| r10427 | r10428 | |
| 385 | 382 | * |
| 386 | 383 | *************************************/ |
| 387 | 384 | |
| 388 | | static UINT8 *z80_shared_ram; |
| 389 | 385 | |
| 390 | 386 | /* V60 interrupt controller */ |
| 391 | | static UINT8 v60_irq_control[0x10]; |
| 392 | | static timer_device *v60_irq_timer[2]; |
| 393 | 387 | |
| 394 | 388 | /* sound interrupt controller */ |
| 395 | | static UINT8 sound_irq_control[4]; |
| 396 | | static UINT8 sound_irq_input; |
| 397 | | static UINT8 sound_dummy_value; |
| 398 | | static UINT16 sound_bank; |
| 399 | 389 | |
| 400 | 390 | |
| 401 | 391 | /* I/O chips and custom I/O */ |
| 402 | | static UINT8 misc_io_data[2][0x10]; |
| 403 | | static read16_space_func custom_io_r[2]; |
| 404 | | static write16_space_func custom_io_w[2]; |
| 405 | | static UINT8 analog_bank; |
| 406 | | static UINT8 analog_value[4]; |
| 407 | | static UINT8 sonic_last[6]; |
| 408 | 392 | |
| 409 | 393 | /* callbacks to handle output */ |
| 410 | | typedef void (*sys32_output_callback)(int which, UINT16 data); |
| 411 | | static sys32_output_callback segas32_sw1_output, segas32_sw2_output, segas32_sw3_output; |
| 412 | | |
| 413 | 394 | static void (*system32_prot_vblank)(device_t *device); |
| 414 | 395 | |
| 415 | 396 | |
| r10427 | r10428 | |
| 432 | 413 | |
| 433 | 414 | static MACHINE_RESET( system32 ) |
| 434 | 415 | { |
| 416 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 435 | 417 | /* initialize the interrupt controller */ |
| 436 | | memset(v60_irq_control, 0xff, sizeof(v60_irq_control)); |
| 418 | memset(state->v60_irq_control, 0xff, sizeof(state->v60_irq_control)); |
| 437 | 419 | |
| 438 | 420 | /* allocate timers */ |
| 439 | | v60_irq_timer[0] = machine->device<timer_device>("v60_irq0"); |
| 440 | | v60_irq_timer[1] = machine->device<timer_device>("v60_irq1"); |
| 421 | state->v60_irq_timer[0] = machine->device<timer_device>("v60_irq0"); |
| 422 | state->v60_irq_timer[1] = machine->device<timer_device>("v60_irq1"); |
| 441 | 423 | |
| 442 | 424 | /* clear IRQ lines */ |
| 443 | 425 | cputag_set_input_line(machine, "maincpu", 0, CLEAR_LINE); |
| r10427 | r10428 | |
| 453 | 435 | |
| 454 | 436 | static void update_irq_state(running_machine *machine) |
| 455 | 437 | { |
| 456 | | UINT8 effirq = v60_irq_control[7] & ~v60_irq_control[6] & 0x1f; |
| 438 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 439 | UINT8 effirq = state->v60_irq_control[7] & ~state->v60_irq_control[6] & 0x1f; |
| 457 | 440 | int vector; |
| 458 | 441 | |
| 459 | 442 | /* loop over interrupt vectors, finding the highest priority one with */ |
| r10427 | r10428 | |
| 473 | 456 | |
| 474 | 457 | static void signal_v60_irq(running_machine *machine, int which) |
| 475 | 458 | { |
| 459 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 476 | 460 | int i; |
| 477 | 461 | |
| 478 | 462 | /* see if this interrupt input is mapped to any vectors; if so, mark them */ |
| 479 | 463 | for (i = 0; i < 5; i++) |
| 480 | | if (v60_irq_control[i] == which) |
| 481 | | v60_irq_control[7] |= 1 << i; |
| 464 | if (state->v60_irq_control[i] == which) |
| 465 | state->v60_irq_control[7] |= 1 << i; |
| 482 | 466 | update_irq_state(machine); |
| 483 | 467 | } |
| 484 | 468 | |
| r10427 | r10428 | |
| 491 | 475 | |
| 492 | 476 | static void int_control_w(address_space *space, int offset, UINT8 data) |
| 493 | 477 | { |
| 478 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 494 | 479 | int duration; |
| 495 | 480 | |
| 496 | 481 | // logerror("%06X:int_control_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data); |
| r10427 | r10428 | |
| 501 | 486 | case 2: |
| 502 | 487 | case 3: |
| 503 | 488 | case 4: /* vectors */ |
| 504 | | v60_irq_control[offset] = data; |
| 489 | state->v60_irq_control[offset] = data; |
| 505 | 490 | break; |
| 506 | 491 | |
| 507 | 492 | case 5: /* unknown */ |
| 508 | | v60_irq_control[offset] = data; |
| 493 | state->v60_irq_control[offset] = data; |
| 509 | 494 | break; |
| 510 | 495 | |
| 511 | 496 | case 6: /* mask */ |
| 512 | | v60_irq_control[offset] = data; |
| 497 | state->v60_irq_control[offset] = data; |
| 513 | 498 | update_irq_state(space->machine); |
| 514 | 499 | break; |
| 515 | 500 | |
| 516 | 501 | case 7: /* acknowledge */ |
| 517 | | v60_irq_control[offset] &= data; |
| 502 | state->v60_irq_control[offset] &= data; |
| 518 | 503 | update_irq_state(space->machine); |
| 519 | 504 | break; |
| 520 | 505 | |
| 521 | 506 | case 8: |
| 522 | 507 | case 9: /* timer 0 count */ |
| 523 | | v60_irq_control[offset] = data; |
| 524 | | duration = v60_irq_control[8] + ((v60_irq_control[9] << 8) & 0xf00); |
| 508 | state->v60_irq_control[offset] = data; |
| 509 | duration = state->v60_irq_control[8] + ((state->v60_irq_control[9] << 8) & 0xf00); |
| 525 | 510 | if (duration) |
| 526 | 511 | { |
| 527 | 512 | attotime period = attotime::from_hz(TIMER_0_CLOCK) * duration; |
| 528 | | v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0); |
| 513 | state->v60_irq_timer[0]->adjust(period, MAIN_IRQ_TIMER0); |
| 529 | 514 | } |
| 530 | 515 | break; |
| 531 | 516 | |
| 532 | 517 | case 10: |
| 533 | 518 | case 11: /* timer 1 count */ |
| 534 | | v60_irq_control[offset] = data; |
| 535 | | duration = v60_irq_control[10] + ((v60_irq_control[11] << 8) & 0xf00); |
| 519 | state->v60_irq_control[offset] = data; |
| 520 | duration = state->v60_irq_control[10] + ((state->v60_irq_control[11] << 8) & 0xf00); |
| 536 | 521 | if (duration) |
| 537 | 522 | { |
| 538 | 523 | attotime period = attotime::from_hz(TIMER_1_CLOCK) * duration; |
| 539 | | v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1); |
| 524 | state->v60_irq_timer[1]->adjust(period, MAIN_IRQ_TIMER1); |
| 540 | 525 | } |
| 541 | 526 | break; |
| 542 | 527 | |
| r10427 | r10428 | |
| 630 | 615 | |
| 631 | 616 | static UINT16 common_io_chip_r(address_space *space, int which, offs_t offset, UINT16 mem_mask) |
| 632 | 617 | { |
| 618 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 633 | 619 | static const char *const portnames[2][8] = |
| 634 | 620 | { |
| 635 | 621 | { "P1_A", "P2_A", "PORTC_A", "PORTD_A", "SERVICE12_A", "SERVICE34_A", "PORTG_A", "PORTH_A" }, |
| r10427 | r10428 | |
| 649 | 635 | case 0x0c/2: |
| 650 | 636 | case 0x0e/2: |
| 651 | 637 | /* if the port is configured as an output, return the last thing written */ |
| 652 | | if (misc_io_data[which][0x1e/2] & (1 << offset)) |
| 653 | | return misc_io_data[which][offset]; |
| 638 | if (state->misc_io_data[which][0x1e/2] & (1 << offset)) |
| 639 | return state->misc_io_data[which][offset]; |
| 654 | 640 | |
| 655 | 641 | /* otherwise, return an input port */ |
| 656 | 642 | return input_port_read_safe(space->machine, portnames[which][offset], 0xffff); |
| r10427 | r10428 | |
| 668 | 654 | /* CNT register & mirror */ |
| 669 | 655 | case 0x18/2: |
| 670 | 656 | case 0x1c/2: |
| 671 | | return misc_io_data[which][0x1c/2]; |
| 657 | return state->misc_io_data[which][0x1c/2]; |
| 672 | 658 | |
| 673 | 659 | /* port direction register & mirror */ |
| 674 | 660 | case 0x1a/2: |
| 675 | 661 | case 0x1e/2: |
| 676 | | return misc_io_data[which][0x1e/2]; |
| 662 | return state->misc_io_data[which][0x1e/2]; |
| 677 | 663 | } |
| 678 | 664 | return 0xffff; |
| 679 | 665 | } |
| r10427 | r10428 | |
| 681 | 667 | |
| 682 | 668 | static void common_io_chip_w(address_space *space, int which, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 683 | 669 | { |
| 670 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 684 | 671 | UINT8 old; |
| 685 | 672 | |
| 686 | 673 | /* only LSB matters */ |
| r10427 | r10428 | |
| 689 | 676 | |
| 690 | 677 | /* generic implementation */ |
| 691 | 678 | offset &= 0x1f/2; |
| 692 | | old = misc_io_data[which][offset]; |
| 693 | | misc_io_data[which][offset] = data; |
| 679 | old = state->misc_io_data[which][offset]; |
| 680 | state->misc_io_data[which][offset] = data; |
| 694 | 681 | |
| 695 | 682 | switch (offset) |
| 696 | 683 | { |
| r10427 | r10428 | |
| 701 | 688 | case 0x08/2: |
| 702 | 689 | case 0x0a/2: |
| 703 | 690 | case 0x0c/2: |
| 704 | | if (segas32_sw2_output) |
| 705 | | segas32_sw2_output(which, data); |
| 691 | if (state->sw2_output) |
| 692 | state->sw2_output(which, data); |
| 706 | 693 | break; |
| 707 | 694 | |
| 708 | 695 | /* miscellaneous output */ |
| 709 | 696 | case 0x06/2: |
| 710 | | if (segas32_sw1_output) |
| 711 | | segas32_sw1_output(which, data); |
| 697 | if (state->sw1_output) |
| 698 | state->sw1_output(which, data); |
| 712 | 699 | |
| 713 | 700 | if (which == 0) |
| 714 | 701 | { |
| r10427 | r10428 | |
| 726 | 713 | /* tile banking */ |
| 727 | 714 | case 0x0e/2: |
| 728 | 715 | if (which == 0) |
| 729 | | system32_tilebank_external = data; |
| 716 | state->system32_tilebank_external = data; |
| 730 | 717 | else |
| 731 | 718 | { |
| 732 | 719 | /* multi-32 EEPROM access */ |
| r10427 | r10428 | |
| 739 | 726 | |
| 740 | 727 | /* CNT register */ |
| 741 | 728 | case 0x1c/2: |
| 742 | | system32_displayenable[which] = (data & 0x02); |
| 729 | state->system32_displayenable[which] = (data & 0x02); |
| 743 | 730 | if (which == 0) |
| 744 | 731 | cputag_set_input_line(space->machine, "soundcpu", INPUT_LINE_RESET, (data & 0x04) ? CLEAR_LINE : ASSERT_LINE); |
| 745 | 732 | break; |
| r10427 | r10428 | |
| 800 | 787 | |
| 801 | 788 | static READ16_HANDLER( io_expansion_r ) |
| 802 | 789 | { |
| 803 | | if (custom_io_r[0]) |
| 804 | | return (*custom_io_r[0])(space, offset, mem_mask); |
| 790 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 791 | if (state->custom_io_r[0]) |
| 792 | return (*state->custom_io_r[0])(space, offset, mem_mask); |
| 805 | 793 | else |
| 806 | 794 | logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); |
| 807 | 795 | return 0xffff; |
| r10427 | r10428 | |
| 810 | 798 | |
| 811 | 799 | static WRITE16_HANDLER( io_expansion_w ) |
| 812 | 800 | { |
| 801 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 813 | 802 | /* only LSB matters */ |
| 814 | 803 | if (!ACCESSING_BITS_0_7) |
| 815 | 804 | return; |
| 816 | 805 | |
| 817 | | if (custom_io_w[0]) |
| 818 | | (*custom_io_w[0])(space, offset, data, mem_mask); |
| 806 | if (state->custom_io_w[0]) |
| 807 | (*state->custom_io_w[0])(space, offset, data, mem_mask); |
| 819 | 808 | else |
| 820 | 809 | logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); |
| 821 | 810 | } |
| r10427 | r10428 | |
| 823 | 812 | |
| 824 | 813 | static READ32_HANDLER( io_expansion_0_r ) |
| 825 | 814 | { |
| 826 | | if (custom_io_r[0]) |
| 827 | | return (*custom_io_r[0])(space, offset*2+0, mem_mask) | |
| 828 | | ((*custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16); |
| 815 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 816 | if (state->custom_io_r[0]) |
| 817 | return (*state->custom_io_r[0])(space, offset*2+0, mem_mask) | |
| 818 | ((*state->custom_io_r[0])(space, offset*2+1, mem_mask >> 16) << 16); |
| 829 | 819 | else |
| 830 | 820 | logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); |
| 831 | 821 | return 0xffffffff; |
| r10427 | r10428 | |
| 834 | 824 | |
| 835 | 825 | static WRITE32_HANDLER( io_expansion_0_w ) |
| 836 | 826 | { |
| 827 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 837 | 828 | /* only LSB matters */ |
| 838 | 829 | |
| 839 | 830 | |
| 840 | 831 | if (ACCESSING_BITS_0_7) |
| 841 | 832 | { |
| 842 | 833 | /* harddunk uses bits 4,5 for output lamps */ |
| 843 | | if (segas32_sw3_output) |
| 844 | | segas32_sw3_output(0, data & 0xff); |
| 834 | if (state->sw3_output) |
| 835 | state->sw3_output(0, data & 0xff); |
| 845 | 836 | |
| 846 | | if (custom_io_w[0]) |
| 847 | | (*custom_io_w[0])(space, offset*2+0, data, mem_mask); |
| 837 | if (state->custom_io_w[0]) |
| 838 | (*state->custom_io_w[0])(space, offset*2+0, data, mem_mask); |
| 848 | 839 | else |
| 849 | 840 | logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); |
| 850 | 841 | |
| 851 | 842 | } |
| 852 | 843 | if (ACCESSING_BITS_16_23) |
| 853 | 844 | { |
| 854 | | if (custom_io_w[0]) |
| 855 | | (*custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16); |
| 845 | if (state->custom_io_w[0]) |
| 846 | (*state->custom_io_w[0])(space, offset*2+1, data >> 16, mem_mask >> 16); |
| 856 | 847 | else |
| 857 | 848 | logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); |
| 858 | 849 | } |
| r10427 | r10428 | |
| 861 | 852 | |
| 862 | 853 | static READ32_HANDLER( io_expansion_1_r ) |
| 863 | 854 | { |
| 864 | | if (custom_io_r[1]) |
| 865 | | return (*custom_io_r[1])(space, offset*2+0, mem_mask) | |
| 866 | | ((*custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16); |
| 855 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 856 | if (state->custom_io_r[1]) |
| 857 | return (*state->custom_io_r[1])(space, offset*2+0, mem_mask) | |
| 858 | ((*state->custom_io_r[1])(space, offset*2+1, mem_mask >> 16) << 16); |
| 867 | 859 | else |
| 868 | 860 | logerror("%06X:io_expansion_r(%X)\n", cpu_get_pc(space->cpu), offset); |
| 869 | 861 | return 0xffffffff; |
| r10427 | r10428 | |
| 872 | 864 | |
| 873 | 865 | static WRITE32_HANDLER( io_expansion_1_w ) |
| 874 | 866 | { |
| 867 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 875 | 868 | /* only LSB matters */ |
| 876 | 869 | if (ACCESSING_BITS_0_7) |
| 877 | 870 | { |
| 878 | | if (custom_io_w[1]) |
| 879 | | (*custom_io_w[1])(space, offset*2+0, data, mem_mask); |
| 871 | if (state->custom_io_w[1]) |
| 872 | (*state->custom_io_w[1])(space, offset*2+0, data, mem_mask); |
| 880 | 873 | else |
| 881 | 874 | logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); |
| 882 | 875 | } |
| 883 | 876 | if (ACCESSING_BITS_16_23) |
| 884 | 877 | { |
| 885 | | if (custom_io_w[1]) |
| 886 | | (*custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16); |
| 878 | if (state->custom_io_w[1]) |
| 879 | (*state->custom_io_w[1])(space, offset*2+1, data >> 16, mem_mask >> 16); |
| 887 | 880 | else |
| 888 | 881 | logerror("%06X:io_expansion_w(%X) = %02X\n", cpu_get_pc(space->cpu), offset, data & 0xff); |
| 889 | 882 | } |
| r10427 | r10428 | |
| 899 | 892 | |
| 900 | 893 | static READ16_HANDLER( analog_custom_io_r ) |
| 901 | 894 | { |
| 895 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 902 | 896 | UINT16 result; |
| 903 | 897 | switch (offset) |
| 904 | 898 | { |
| r10427 | r10428 | |
| 906 | 900 | case 0x12/2: |
| 907 | 901 | case 0x14/2: |
| 908 | 902 | case 0x16/2: |
| 909 | | result = analog_value[offset & 3] | 0x7f; |
| 910 | | analog_value[offset & 3] <<= 1; |
| 903 | result = state->analog_value[offset & 3] | 0x7f; |
| 904 | state->analog_value[offset & 3] <<= 1; |
| 911 | 905 | return result; |
| 912 | 906 | } |
| 913 | 907 | logerror("%06X:unknown analog_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask); |
| r10427 | r10428 | |
| 917 | 911 | |
| 918 | 912 | static WRITE16_HANDLER( analog_custom_io_w ) |
| 919 | 913 | { |
| 914 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 920 | 915 | static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4" }; |
| 921 | 916 | switch (offset) |
| 922 | 917 | { |
| r10427 | r10428 | |
| 924 | 919 | case 0x12/2: |
| 925 | 920 | case 0x14/2: |
| 926 | 921 | case 0x16/2: |
| 927 | | analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0); |
| 922 | state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[offset & 3], 0); |
| 928 | 923 | return; |
| 929 | 924 | } |
| 930 | 925 | logerror("%06X:unknown analog_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask); |
| r10427 | r10428 | |
| 950 | 945 | |
| 951 | 946 | static WRITE16_HANDLER( orunners_custom_io_w ) |
| 952 | 947 | { |
| 948 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 953 | 949 | static const char *const names[] = { "ANALOG1", "ANALOG2", "ANALOG3", "ANALOG4", "ANALOG5", "ANALOG6", "ANALOG7", "ANALOG8" }; |
| 954 | 950 | switch (offset) |
| 955 | 951 | { |
| r10427 | r10428 | |
| 957 | 953 | case 0x12/2: |
| 958 | 954 | case 0x14/2: |
| 959 | 955 | case 0x16/2: |
| 960 | | analog_value[offset & 3] = input_port_read_safe(space->machine, names[analog_bank * 4 + (offset & 3)], 0); |
| 956 | state->analog_value[offset & 3] = input_port_read_safe(space->machine, names[state->analog_bank * 4 + (offset & 3)], 0); |
| 961 | 957 | return; |
| 962 | 958 | |
| 963 | 959 | case 0x20/2: |
| 964 | | analog_bank = data & 1; |
| 960 | state->analog_bank = data & 1; |
| 965 | 961 | return; |
| 966 | 962 | } |
| 967 | 963 | logerror("%06X:unknown orunners_custom_io_w(%X) = %04X & %04X\n", cpu_get_pc(space->cpu), offset*2, data, mem_mask); |
| r10427 | r10428 | |
| 970 | 966 | |
| 971 | 967 | static READ16_HANDLER( sonic_custom_io_r ) |
| 972 | 968 | { |
| 969 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 973 | 970 | static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" }; |
| 974 | 971 | |
| 975 | 972 | switch (offset) |
| r10427 | r10428 | |
| 980 | 977 | case 0x0c/2: |
| 981 | 978 | case 0x10/2: |
| 982 | 979 | case 0x14/2: |
| 983 | | return (UINT8)(input_port_read(space->machine, names[offset/2]) - sonic_last[offset/2]); |
| 980 | return (UINT8)(input_port_read(space->machine, names[offset/2]) - state->sonic_last[offset/2]); |
| 984 | 981 | } |
| 985 | 982 | |
| 986 | 983 | logerror("%06X:unknown sonic_custom_io_r(%X) & %04X\n", cpu_get_pc(space->cpu), offset*2, mem_mask); |
| r10427 | r10428 | |
| 990 | 987 | |
| 991 | 988 | static WRITE16_HANDLER( sonic_custom_io_w ) |
| 992 | 989 | { |
| 990 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 993 | 991 | static const char *const names[] = { "TRACKX1", "TRACKY1", "TRACKX2", "TRACKY2", "TRACKX3", "TRACKY3" }; |
| 994 | 992 | |
| 995 | 993 | switch (offset) |
| r10427 | r10428 | |
| 997 | 995 | case 0x00/2: |
| 998 | 996 | case 0x08/2: |
| 999 | 997 | case 0x10/2: |
| 1000 | | sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]); |
| 1001 | | sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]); |
| 998 | state->sonic_last[offset/2 + 0] = input_port_read(space->machine, names[offset/2 + 0]); |
| 999 | state->sonic_last[offset/2 + 1] = input_port_read(space->machine, names[offset/2 + 1]); |
| 1002 | 1000 | return; |
| 1003 | 1001 | } |
| 1004 | 1002 | |
| r10427 | r10428 | |
| 1043 | 1041 | |
| 1044 | 1042 | static READ16_HANDLER( shared_ram_16_r ) |
| 1045 | 1043 | { |
| 1046 | | return z80_shared_ram[offset*2+0] | (z80_shared_ram[offset*2+1] << 8); |
| 1044 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1045 | return state->z80_shared_ram[offset*2+0] | (state->z80_shared_ram[offset*2+1] << 8); |
| 1047 | 1046 | } |
| 1048 | 1047 | |
| 1049 | 1048 | |
| 1050 | 1049 | static WRITE16_HANDLER( shared_ram_16_w ) |
| 1051 | 1050 | { |
| 1051 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1052 | 1052 | if (ACCESSING_BITS_0_7) |
| 1053 | | z80_shared_ram[offset*2+0] = data; |
| 1053 | state->z80_shared_ram[offset*2+0] = data; |
| 1054 | 1054 | if (ACCESSING_BITS_8_15) |
| 1055 | | z80_shared_ram[offset*2+1] = data >> 8; |
| 1055 | state->z80_shared_ram[offset*2+1] = data >> 8; |
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | |
| 1059 | 1059 | static READ32_HANDLER( shared_ram_32_r ) |
| 1060 | 1060 | { |
| 1061 | | return z80_shared_ram[offset*4+0] | (z80_shared_ram[offset*4+1] << 8) | |
| 1062 | | (z80_shared_ram[offset*4+2] << 16) | (z80_shared_ram[offset*4+3] << 24); |
| 1061 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1062 | return state->z80_shared_ram[offset*4+0] | (state->z80_shared_ram[offset*4+1] << 8) | |
| 1063 | (state->z80_shared_ram[offset*4+2] << 16) | (state->z80_shared_ram[offset*4+3] << 24); |
| 1063 | 1064 | } |
| 1064 | 1065 | |
| 1065 | 1066 | |
| 1066 | 1067 | static WRITE32_HANDLER( shared_ram_32_w ) |
| 1067 | 1068 | { |
| 1069 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1068 | 1070 | if (ACCESSING_BITS_0_7) |
| 1069 | | z80_shared_ram[offset*4+0] = data; |
| 1071 | state->z80_shared_ram[offset*4+0] = data; |
| 1070 | 1072 | if (ACCESSING_BITS_8_15) |
| 1071 | | z80_shared_ram[offset*4+1] = data >> 8; |
| 1073 | state->z80_shared_ram[offset*4+1] = data >> 8; |
| 1072 | 1074 | if (ACCESSING_BITS_16_23) |
| 1073 | | z80_shared_ram[offset*4+2] = data >> 16; |
| 1075 | state->z80_shared_ram[offset*4+2] = data >> 16; |
| 1074 | 1076 | if (ACCESSING_BITS_24_31) |
| 1075 | | z80_shared_ram[offset*4+3] = data >> 24; |
| 1077 | state->z80_shared_ram[offset*4+3] = data >> 24; |
| 1076 | 1078 | } |
| 1077 | 1079 | |
| 1078 | 1080 | |
| r10427 | r10428 | |
| 1085 | 1087 | |
| 1086 | 1088 | static void update_sound_irq_state(running_machine *machine) |
| 1087 | 1089 | { |
| 1088 | | UINT8 effirq = sound_irq_input & ~sound_irq_control[3] & 0x07; |
| 1090 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 1091 | UINT8 effirq = state->sound_irq_input & ~state->sound_irq_control[3] & 0x07; |
| 1089 | 1092 | int vector; |
| 1090 | 1093 | |
| 1091 | 1094 | /* loop over interrupt vectors, finding the highest priority one with */ |
| r10427 | r10428 | |
| 1105 | 1108 | |
| 1106 | 1109 | static void signal_sound_irq(running_machine *machine, int which) |
| 1107 | 1110 | { |
| 1111 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 1108 | 1112 | int i; |
| 1109 | 1113 | |
| 1110 | 1114 | /* see if this interrupt input is mapped to any vectors; if so, mark them */ |
| 1111 | 1115 | for (i = 0; i < 3; i++) |
| 1112 | | if (sound_irq_control[i] == which) |
| 1113 | | sound_irq_input |= 1 << i; |
| 1116 | if (state->sound_irq_control[i] == which) |
| 1117 | state->sound_irq_input |= 1 << i; |
| 1114 | 1118 | update_sound_irq_state(machine); |
| 1115 | 1119 | } |
| 1116 | 1120 | |
| 1117 | 1121 | |
| 1118 | 1122 | static void clear_sound_irq(running_machine *machine, int which) |
| 1119 | 1123 | { |
| 1124 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 1120 | 1125 | int i; |
| 1121 | 1126 | for (i = 0; i < 3; i++) |
| 1122 | | if (sound_irq_control[i] == which) |
| 1123 | | sound_irq_input &= ~(1 << i); |
| 1127 | if (state->sound_irq_control[i] == which) |
| 1128 | state->sound_irq_input &= ~(1 << i); |
| 1124 | 1129 | update_sound_irq_state(machine); |
| 1125 | 1130 | } |
| 1126 | 1131 | |
| 1127 | 1132 | |
| 1128 | 1133 | static WRITE8_HANDLER( sound_int_control_lo_w ) |
| 1129 | 1134 | { |
| 1135 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1130 | 1136 | /* odd offsets are interrupt acks */ |
| 1131 | 1137 | if (offset & 1) |
| 1132 | 1138 | { |
| 1133 | | sound_irq_input &= data; |
| 1139 | state->sound_irq_input &= data; |
| 1134 | 1140 | update_sound_irq_state(space->machine); |
| 1135 | 1141 | } |
| 1136 | 1142 | |
| r10427 | r10428 | |
| 1142 | 1148 | |
| 1143 | 1149 | static WRITE8_HANDLER( sound_int_control_hi_w ) |
| 1144 | 1150 | { |
| 1145 | | sound_irq_control[offset] = data; |
| 1151 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1152 | state->sound_irq_control[offset] = data; |
| 1146 | 1153 | update_sound_irq_state(space->machine); |
| 1147 | 1154 | } |
| 1148 | 1155 | |
| r10427 | r10428 | |
| 1165 | 1172 | |
| 1166 | 1173 | static WRITE8_HANDLER( sound_bank_lo_w ) |
| 1167 | 1174 | { |
| 1168 | | sound_bank = (sound_bank & ~0x3f) | (data & 0x3f); |
| 1169 | | memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank); |
| 1175 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1176 | state->sound_bank = (state->sound_bank & ~0x3f) | (data & 0x3f); |
| 1177 | memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank); |
| 1170 | 1178 | } |
| 1171 | 1179 | |
| 1172 | 1180 | |
| 1173 | 1181 | static WRITE8_HANDLER( sound_bank_hi_w ) |
| 1174 | 1182 | { |
| 1175 | | sound_bank = (sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7); |
| 1176 | | memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * sound_bank); |
| 1183 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1184 | state->sound_bank = (state->sound_bank & 0x3f) | ((data & 0x04) << 4) | ((data & 0x03) << 7); |
| 1185 | memory_set_bankptr(space->machine, "bank1", space->machine->region("soundcpu")->base() + 0x100000 + 0x2000 * state->sound_bank); |
| 1177 | 1186 | } |
| 1178 | 1187 | |
| 1179 | 1188 | |
| r10427 | r10428 | |
| 1198 | 1207 | |
| 1199 | 1208 | static READ8_HANDLER( sound_dummy_r ) |
| 1200 | 1209 | { |
| 1201 | | return sound_dummy_value; |
| 1210 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1211 | return state->sound_dummy_value; |
| 1202 | 1212 | } |
| 1203 | 1213 | |
| 1204 | 1214 | |
| 1205 | 1215 | static WRITE8_HANDLER( sound_dummy_w ) |
| 1206 | 1216 | { |
| 1207 | | sound_dummy_value = data; |
| 1217 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 1218 | state->sound_dummy_value = data; |
| 1208 | 1219 | } |
| 1209 | 1220 | |
| 1210 | 1221 | |
| r10427 | r10428 | |
| 1218 | 1229 | static ADDRESS_MAP_START( system32_map, ADDRESS_SPACE_PROGRAM, 16 ) |
| 1219 | 1230 | ADDRESS_MAP_UNMAP_HIGH |
| 1220 | 1231 | AM_RANGE(0x000000, 0x1fffff) AM_ROM |
| 1221 | | AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE(&system32_workram) |
| 1222 | | AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE(&system32_videoram) |
| 1223 | | AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE(&system32_spriteram) |
| 1232 | AM_RANGE(0x200000, 0x20ffff) AM_MIRROR(0x0f0000) AM_RAM AM_BASE_MEMBER(segas32_state, system32_workram) |
| 1233 | AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_videoram_r, system32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram) |
| 1234 | AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_spriteram_r, system32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram) |
| 1224 | 1235 | AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(system32_sprite_control_r, system32_sprite_control_w) |
| 1225 | | AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE(&system32_paletteram[0]) |
| 1236 | AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x0e0000) AM_READWRITE(system32_paletteram_r, system32_paletteram_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0]) |
| 1226 | 1237 | AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x0eff80) AM_READWRITE(system32_mixer_r, system32_mixer_w) |
| 1227 | 1238 | AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_16_r, shared_ram_16_w) |
| 1228 | 1239 | AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x0fff80) AM_READWRITE(io_chip_r, io_chip_w) |
| r10427 | r10428 | |
| 1238 | 1249 | ADDRESS_MAP_GLOBAL_MASK(0xffffff) |
| 1239 | 1250 | AM_RANGE(0x000000, 0x1fffff) AM_ROM |
| 1240 | 1251 | AM_RANGE(0x200000, 0x21ffff) AM_MIRROR(0x0e0000) AM_RAM |
| 1241 | | AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE((UINT32 **)&system32_videoram) |
| 1242 | | AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE((UINT32 **)&system32_spriteram) |
| 1252 | AM_RANGE(0x300000, 0x31ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_videoram_r, multi32_videoram_w) AM_BASE_MEMBER(segas32_state, system32_videoram) |
| 1253 | AM_RANGE(0x400000, 0x41ffff) AM_MIRROR(0x0e0000) AM_READWRITE(multi32_spriteram_r, multi32_spriteram_w) AM_BASE_MEMBER(segas32_state, system32_spriteram) |
| 1243 | 1254 | AM_RANGE(0x500000, 0x50000f) AM_MIRROR(0x0ffff0) AM_READWRITE(multi32_sprite_control_r, multi32_sprite_control_w) |
| 1244 | | AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE((UINT32 **)&system32_paletteram[0]) |
| 1255 | AM_RANGE(0x600000, 0x60ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_0_r, multi32_paletteram_0_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[0]) |
| 1245 | 1256 | AM_RANGE(0x610000, 0x61007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_0_w) |
| 1246 | | AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE((UINT32 **)&system32_paletteram[1]) |
| 1257 | AM_RANGE(0x680000, 0x68ffff) AM_MIRROR(0x060000) AM_READWRITE(multi32_paletteram_1_r, multi32_paletteram_1_w) AM_BASE_MEMBER(segas32_state, system32_paletteram[1]) |
| 1247 | 1258 | AM_RANGE(0x690000, 0x69007f) AM_MIRROR(0x06ff80) AM_WRITE(multi32_mixer_1_w) |
| 1248 | 1259 | AM_RANGE(0x700000, 0x701fff) AM_MIRROR(0x0fe000) AM_READWRITE(shared_ram_32_r, shared_ram_32_w) |
| 1249 | 1260 | AM_RANGE(0xc00000, 0xc0001f) AM_MIRROR(0x07ff80) AM_READWRITE(io_chip_0_r, io_chip_0_w) |
| r10427 | r10428 | |
| 1268 | 1279 | AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1") |
| 1269 | 1280 | AM_RANGE(0xc000, 0xc00f) AM_MIRROR(0x0ff0) AM_DEVWRITE("rfsnd", rf5c68_w) |
| 1270 | 1281 | AM_RANGE(0xd000, 0xdfff) AM_DEVREADWRITE("rfsnd", rf5c68_mem_r, rf5c68_mem_w) |
| 1271 | | AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram) |
| 1282 | AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram) |
| 1272 | 1283 | ADDRESS_MAP_END |
| 1273 | 1284 | |
| 1274 | 1285 | static ADDRESS_MAP_START( system32_sound_portmap, ADDRESS_SPACE_IO, 8 ) |
| r10427 | r10428 | |
| 1288 | 1299 | AM_RANGE(0x0000, 0x9fff) AM_ROM AM_REGION("soundcpu", 0x100000) |
| 1289 | 1300 | AM_RANGE(0xa000, 0xbfff) AM_ROMBANK("bank1") |
| 1290 | 1301 | AM_RANGE(0xc000, 0xdfff) AM_DEVREADWRITE("sega", multipcm_r, multipcm_w) |
| 1291 | | AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE(&z80_shared_ram) |
| 1302 | AM_RANGE(0xe000, 0xffff) AM_RAM AM_BASE_MEMBER(segas32_state, z80_shared_ram) |
| 1292 | 1303 | ADDRESS_MAP_END |
| 1293 | 1304 | |
| 1294 | 1305 | static ADDRESS_MAP_START( multi32_sound_portmap, ADDRESS_SPACE_IO, 8 ) |
| r10427 | r10428 | |
| 1312 | 1323 | |
| 1313 | 1324 | static ADDRESS_MAP_START( ga2_v25_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 1314 | 1325 | AM_RANGE(0x00000, 0x0ffff) AM_ROM AM_REGION("mcu", 0) |
| 1315 | | AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE(&ga2_dpram) |
| 1326 | AM_RANGE(0x10000, 0x1ffff) AM_RAM AM_BASE_MEMBER(segas32_state, ga2_dpram) |
| 1316 | 1327 | AM_RANGE(0xf0000, 0xfffff) AM_ROM AM_REGION("mcu", 0) |
| 1317 | 1328 | ADDRESS_MAP_END |
| 1318 | 1329 | |
| r10427 | r10428 | |
| 2153 | 2164 | |
| 2154 | 2165 | // Both arescue and f1en appear to use an identical shared RAM system. |
| 2155 | 2166 | |
| 2156 | | static UINT16* dual_pcb_comms; |
| 2157 | 2167 | |
| 2158 | 2168 | static WRITE16_HANDLER( dual_pcb_comms_w ) |
| 2159 | 2169 | { |
| 2160 | | COMBINE_DATA(&dual_pcb_comms[offset]); |
| 2170 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 2171 | COMBINE_DATA(&state->dual_pcb_comms[offset]); |
| 2161 | 2172 | } |
| 2162 | 2173 | |
| 2163 | 2174 | static READ16_HANDLER( dual_pcb_comms_r ) |
| 2164 | 2175 | { |
| 2165 | | return dual_pcb_comms[offset]; |
| 2176 | segas32_state *state = space->machine->driver_data<segas32_state>(); |
| 2177 | return state->dual_pcb_comms[offset]; |
| 2166 | 2178 | } |
| 2167 | 2179 | |
| 2168 | 2180 | |
| r10427 | r10428 | |
| 2183 | 2195 | * |
| 2184 | 2196 | *************************************/ |
| 2185 | 2197 | |
| 2186 | | static MACHINE_CONFIG_START( system32, driver_device ) |
| 2198 | static MACHINE_CONFIG_START( system32, segas32_state ) |
| 2187 | 2199 | |
| 2188 | 2200 | /* basic machine hardware */ |
| 2189 | 2201 | MCFG_CPU_ADD("maincpu", V60, MASTER_CLOCK/2) |
| r10427 | r10428 | |
| 2243 | 2255 | MACHINE_CONFIG_END |
| 2244 | 2256 | |
| 2245 | 2257 | |
| 2246 | | static MACHINE_CONFIG_START( multi32, driver_device ) |
| 2258 | static MACHINE_CONFIG_START( multi32, segas32_state ) |
| 2247 | 2259 | |
| 2248 | 2260 | /* basic machine hardware */ |
| 2249 | 2261 | MCFG_CPU_ADD("maincpu", V70, MULTI32_CLOCK/2) |
| r10427 | r10428 | |
| 3807 | 3819 | * |
| 3808 | 3820 | *************************************/ |
| 3809 | 3821 | |
| 3810 | | static void segas32_common_init(read16_space_func custom_r, write16_space_func custom_w) |
| 3822 | static void segas32_common_init(running_machine *machine, read16_space_func custom_r, write16_space_func custom_w) |
| 3811 | 3823 | { |
| 3824 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 3812 | 3825 | /* reset the custom handlers and other pointers */ |
| 3813 | | custom_io_r[0] = custom_r; |
| 3814 | | custom_io_w[0] = custom_w; |
| 3826 | state->custom_io_r[0] = custom_r; |
| 3827 | state->custom_io_w[0] = custom_w; |
| 3815 | 3828 | system32_prot_vblank = NULL; |
| 3816 | | segas32_sw1_output = NULL; |
| 3817 | | segas32_sw2_output = NULL; |
| 3818 | | segas32_sw3_output = NULL; |
| 3829 | state->sw1_output = NULL; |
| 3830 | state->sw2_output = NULL; |
| 3831 | state->sw3_output = NULL; |
| 3819 | 3832 | } |
| 3820 | 3833 | |
| 3821 | 3834 | |
| r10427 | r10428 | |
| 4003 | 4016 | |
| 4004 | 4017 | static DRIVER_INIT( alien3 ) |
| 4005 | 4018 | { |
| 4006 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4007 | | segas32_sw1_output = alien3_sw1_output; |
| 4019 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4020 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4021 | state->sw1_output = alien3_sw1_output; |
| 4008 | 4022 | } |
| 4009 | 4023 | |
| 4010 | 4024 | static READ16_HANDLER( arescue_handshake_r ) |
| r10427 | r10428 | |
| 4019 | 4033 | |
| 4020 | 4034 | static DRIVER_INIT( arescue ) |
| 4021 | 4035 | { |
| 4022 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4036 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4037 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4023 | 4038 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00007, 0, 0, arescue_dsp_r, arescue_dsp_w); |
| 4024 | 4039 | |
| 4025 | | dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4040 | state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4026 | 4041 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w); |
| 4027 | 4042 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave); |
| 4028 | 4043 | |
| 4029 | 4044 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810001, 0, 0, arescue_handshake_r); |
| 4030 | 4045 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x81000e, 0x81000f, 0, 0, arescue_slavebusy_r); |
| 4031 | 4046 | |
| 4032 | | segas32_sw1_output = arescue_sw1_output; |
| 4047 | state->sw1_output = arescue_sw1_output; |
| 4033 | 4048 | } |
| 4034 | 4049 | |
| 4035 | 4050 | |
| 4036 | 4051 | static DRIVER_INIT( arabfgt ) |
| 4037 | 4052 | { |
| 4038 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4053 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4039 | 4054 | |
| 4040 | 4055 | /* install protection handlers */ |
| 4041 | 4056 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00100, 0xa0011f, 0, 0, arf_wakeup_protection_r); |
| r10427 | r10428 | |
| 4045 | 4060 | |
| 4046 | 4061 | static DRIVER_INIT( brival ) |
| 4047 | 4062 | { |
| 4048 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4063 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4064 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4049 | 4065 | |
| 4050 | 4066 | /* install protection handlers */ |
| 4051 | | system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4067 | state->system32_protram = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4052 | 4068 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20ba00, 0x20ba07, 0, 0, brival_protection_r); |
| 4053 | 4069 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, brival_protection_w); |
| 4054 | 4070 | } |
| r10427 | r10428 | |
| 4056 | 4072 | |
| 4057 | 4073 | static DRIVER_INIT( darkedge ) |
| 4058 | 4074 | { |
| 4059 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4075 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4060 | 4076 | |
| 4061 | 4077 | /* install protection handlers */ |
| 4062 | 4078 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, darkedge_protection_r, darkedge_protection_w); |
| r10427 | r10428 | |
| 4065 | 4081 | |
| 4066 | 4082 | static DRIVER_INIT( dbzvrvs ) |
| 4067 | 4083 | { |
| 4068 | | segas32_common_init(NULL, NULL); |
| 4084 | segas32_common_init(machine, NULL, NULL); |
| 4069 | 4085 | |
| 4070 | 4086 | /* install protection handlers */ |
| 4071 | 4087 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa7ffff, 0, 0, dbzvrvs_protection_r, dbzvrvs_protection_w); |
| r10427 | r10428 | |
| 4080 | 4096 | |
| 4081 | 4097 | static DRIVER_INIT( f1en ) |
| 4082 | 4098 | { |
| 4083 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4099 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4100 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4084 | 4101 | |
| 4085 | | dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4102 | state->dual_pcb_comms = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 4086 | 4103 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810000, 0x810fff, 0, 0, dual_pcb_comms_r, dual_pcb_comms_w); |
| 4087 | 4104 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x818000, 0x818003, 0, 0, dual_pcb_masterslave); |
| 4088 | 4105 | |
| 4089 | 4106 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x810048, 0x810049, 0, 0, f1en_comms_echo_w); |
| 4090 | 4107 | |
| 4091 | | segas32_sw1_output = radm_sw1_output; |
| 4108 | state->sw1_output = radm_sw1_output; |
| 4092 | 4109 | } |
| 4093 | 4110 | |
| 4094 | 4111 | |
| 4095 | 4112 | static DRIVER_INIT( f1lap ) |
| 4096 | 4113 | { |
| 4097 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4098 | | segas32_sw1_output = f1lap_sw1_output; |
| 4114 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4115 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4116 | state->sw1_output = f1lap_sw1_output; |
| 4099 | 4117 | } |
| 4100 | 4118 | |
| 4101 | 4119 | |
| 4102 | 4120 | static DRIVER_INIT( ga2 ) |
| 4103 | 4121 | { |
| 4104 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4122 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4105 | 4123 | |
| 4106 | 4124 | decrypt_ga2_protrom(machine); |
| 4107 | 4125 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa00000, 0xa00fff, 0, 0, ga2_dpram_r, ga2_dpram_w); |
| r10427 | r10428 | |
| 4110 | 4128 | |
| 4111 | 4129 | static DRIVER_INIT( harddunk ) |
| 4112 | 4130 | { |
| 4113 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4114 | | segas32_sw1_output = harddunk_sw1_output; |
| 4115 | | segas32_sw2_output = harddunk_sw2_output; |
| 4116 | | segas32_sw3_output = harddunk_sw3_output; |
| 4131 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4132 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4133 | state->sw1_output = harddunk_sw1_output; |
| 4134 | state->sw2_output = harddunk_sw2_output; |
| 4135 | state->sw3_output = harddunk_sw3_output; |
| 4117 | 4136 | } |
| 4118 | 4137 | |
| 4119 | 4138 | |
| 4120 | 4139 | static DRIVER_INIT( holo ) |
| 4121 | 4140 | { |
| 4122 | | segas32_common_init(NULL, NULL); |
| 4141 | segas32_common_init(machine, NULL, NULL); |
| 4123 | 4142 | } |
| 4124 | 4143 | |
| 4125 | 4144 | |
| 4126 | 4145 | static DRIVER_INIT( jpark ) |
| 4127 | 4146 | { |
| 4147 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4128 | 4148 | /* Temp. Patch until we emulate the 'Drive Board', thanks to Malice */ |
| 4129 | 4149 | UINT16 *pROM = (UINT16 *)machine->region("maincpu")->base(); |
| 4130 | 4150 | |
| 4131 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4151 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4132 | 4152 | |
| 4133 | 4153 | pROM[0xC15A8/2] = 0xCD70; |
| 4134 | 4154 | pROM[0xC15AA/2] = 0xD8CD; |
| 4135 | 4155 | |
| 4136 | | segas32_sw1_output = jpark_sw1_output; |
| 4156 | state->sw1_output = jpark_sw1_output; |
| 4137 | 4157 | } |
| 4138 | 4158 | |
| 4139 | 4159 | |
| 4140 | 4160 | static DRIVER_INIT( orunners ) |
| 4141 | 4161 | { |
| 4142 | | segas32_common_init(analog_custom_io_r, orunners_custom_io_w); |
| 4143 | | segas32_sw1_output = orunners_sw1_output; |
| 4144 | | segas32_sw2_output = orunners_sw2_output; |
| 4162 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4163 | segas32_common_init(machine, analog_custom_io_r, orunners_custom_io_w); |
| 4164 | state->sw1_output = orunners_sw1_output; |
| 4165 | state->sw2_output = orunners_sw2_output; |
| 4145 | 4166 | } |
| 4146 | 4167 | |
| 4147 | 4168 | |
| 4148 | 4169 | static DRIVER_INIT( radm ) |
| 4149 | 4170 | { |
| 4150 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4151 | | segas32_sw1_output = radm_sw1_output; |
| 4152 | | segas32_sw2_output = radm_sw2_output; |
| 4171 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4172 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4173 | state->sw1_output = radm_sw1_output; |
| 4174 | state->sw2_output = radm_sw2_output; |
| 4153 | 4175 | } |
| 4154 | 4176 | |
| 4155 | 4177 | |
| 4156 | 4178 | static DRIVER_INIT( radr ) |
| 4157 | 4179 | { |
| 4158 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4159 | | segas32_sw1_output = radm_sw1_output; |
| 4160 | | segas32_sw2_output = radr_sw2_output; |
| 4180 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4181 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4182 | state->sw1_output = radm_sw1_output; |
| 4183 | state->sw2_output = radr_sw2_output; |
| 4161 | 4184 | } |
| 4162 | 4185 | |
| 4163 | 4186 | |
| 4164 | 4187 | static DRIVER_INIT( scross ) |
| 4165 | 4188 | { |
| 4189 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4166 | 4190 | multipcm_device *multipcm = machine->device<multipcm_device>("sega"); |
| 4167 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4191 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4168 | 4192 | memory_install_write8_device_handler(cputag_get_address_space(machine, "soundcpu", ADDRESS_SPACE_PROGRAM), multipcm, 0xb0, 0xbf, 0, 0, scross_bank_w); |
| 4169 | 4193 | |
| 4170 | | segas32_sw1_output = scross_sw1_output; |
| 4171 | | segas32_sw2_output = scross_sw2_output; |
| 4194 | state->sw1_output = scross_sw1_output; |
| 4195 | state->sw2_output = scross_sw2_output; |
| 4172 | 4196 | } |
| 4173 | 4197 | |
| 4174 | 4198 | |
| 4175 | 4199 | static DRIVER_INIT( slipstrm ) |
| 4176 | 4200 | { |
| 4177 | | segas32_common_init(analog_custom_io_r, analog_custom_io_w); |
| 4201 | segas32_common_init(machine, analog_custom_io_r, analog_custom_io_w); |
| 4178 | 4202 | } |
| 4179 | 4203 | |
| 4180 | 4204 | |
| 4181 | 4205 | static DRIVER_INIT( sonic ) |
| 4182 | 4206 | { |
| 4183 | | segas32_common_init(sonic_custom_io_r, sonic_custom_io_w); |
| 4207 | segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w); |
| 4184 | 4208 | |
| 4185 | 4209 | /* install protection handlers */ |
| 4186 | 4210 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20E5C4, 0x20E5C5, 0, 0, sonic_level_load_protection); |
| r10427 | r10428 | |
| 4189 | 4213 | |
| 4190 | 4214 | static DRIVER_INIT( sonicp ) |
| 4191 | 4215 | { |
| 4192 | | segas32_common_init(sonic_custom_io_r, sonic_custom_io_w); |
| 4216 | segas32_common_init(machine, sonic_custom_io_r, sonic_custom_io_w); |
| 4193 | 4217 | } |
| 4194 | 4218 | |
| 4195 | 4219 | |
| 4196 | 4220 | static DRIVER_INIT( spidman ) |
| 4197 | 4221 | { |
| 4198 | | segas32_common_init(extra_custom_io_r, NULL); |
| 4222 | segas32_common_init(machine, extra_custom_io_r, NULL); |
| 4199 | 4223 | } |
| 4200 | 4224 | |
| 4201 | 4225 | |
| 4202 | 4226 | static DRIVER_INIT( svf ) |
| 4203 | 4227 | { |
| 4204 | | segas32_common_init(NULL, NULL); |
| 4228 | segas32_common_init(machine, NULL, NULL); |
| 4205 | 4229 | } |
| 4206 | 4230 | |
| 4207 | 4231 | |
| 4208 | 4232 | static DRIVER_INIT( jleague ) |
| 4209 | 4233 | { |
| 4210 | | segas32_common_init(NULL, NULL); |
| 4234 | segas32_common_init(machine, NULL, NULL); |
| 4211 | 4235 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x20F700, 0x20F705, 0, 0, jleague_protection_w); |
| 4212 | 4236 | } |
| 4213 | 4237 | |
| 4214 | 4238 | |
| 4215 | 4239 | static DRIVER_INIT( titlef ) |
| 4216 | 4240 | { |
| 4217 | | segas32_common_init(NULL, NULL); |
| 4218 | | segas32_sw1_output = titlef_sw1_output; |
| 4219 | | segas32_sw2_output = titlef_sw2_output; |
| 4241 | segas32_state *state = machine->driver_data<segas32_state>(); |
| 4242 | segas32_common_init(machine, NULL, NULL); |
| 4243 | state->sw1_output = titlef_sw1_output; |
| 4244 | state->sw2_output = titlef_sw2_output; |
| 4220 | 4245 | } |
| 4221 | 4246 | |
| 4222 | 4247 | |
src/mame/drivers/bfm_sc2.c
| r10427 | r10428 | |
| 163 | 163 | #include "sltblgtk.lh" |
| 164 | 164 | #include "slots.lh" |
| 165 | 165 | |
| 166 | class bfm_sc2_state : public driver_device |
| 167 | { |
| 168 | public: |
| 169 | bfm_sc2_state(running_machine &machine, const driver_device_config_base &config) |
| 170 | : driver_device(machine, config) { } |
| 171 | |
| 172 | int sc2gui_update_mmtr; |
| 173 | UINT8 *nvram; |
| 174 | UINT8 key[16]; |
| 175 | UINT8 e2ram[1024]; |
| 176 | int mmtr_latch; |
| 177 | int triac_latch; |
| 178 | int vfd1_latch; |
| 179 | int vfd2_latch; |
| 180 | int irq_status; |
| 181 | int optic_pattern; |
| 182 | int uart1_data; |
| 183 | int uart2_data; |
| 184 | int data_to_uart1; |
| 185 | int data_to_uart2; |
| 186 | int locked; |
| 187 | int is_timer_enabled; |
| 188 | int reel_changed; |
| 189 | int coin_inhibits; |
| 190 | int irq_timer_stat; |
| 191 | int expansion_latch; |
| 192 | int global_volume; |
| 193 | int volume_override; |
| 194 | int sc2_show_door; |
| 195 | int sc2_door_state; |
| 196 | int reel12_latch; |
| 197 | int reel34_latch; |
| 198 | int reel56_latch; |
| 199 | int pay_latch; |
| 200 | int slide_states[6]; |
| 201 | int slide_pay_sensor[6]; |
| 202 | int has_hopper; |
| 203 | int triac_select; |
| 204 | int hopper_running; |
| 205 | int hopper_coin_sense; |
| 206 | int timercnt; |
| 207 | int watchdog_cnt; |
| 208 | int watchdog_kicked; |
| 209 | UINT8 Lamps[256]; |
| 210 | UINT8 sc2_Inputs[64]; |
| 211 | UINT8 input_override[64]; |
| 212 | int e2reg; |
| 213 | int e2state; |
| 214 | int e2cnt; |
| 215 | int e2data; |
| 216 | int e2address; |
| 217 | int e2rw; |
| 218 | int e2data_pin; |
| 219 | int e2dummywrite; |
| 220 | int e2data_to_read; |
| 221 | UINT8 codec_data[256]; |
| 222 | }; |
| 223 | |
| 224 | |
| 166 | 225 | #ifdef MAME_DEBUG |
| 167 | 226 | #define VERBOSE 1 |
| 168 | 227 | #else |
| r10427 | r10428 | |
| 178 | 237 | |
| 179 | 238 | // local prototypes /////////////////////////////////////////////////////// |
| 180 | 239 | |
| 181 | | static int get_scorpion2_uart_status(void); // retrieve status of uart on scorpion2 board |
| 240 | static int read_e2ram(running_machine *machine); |
| 241 | static void e2ram_reset(running_machine *machine); |
| 182 | 242 | |
| 183 | | static int read_e2ram(void); |
| 184 | | static void e2ram_reset(void); |
| 243 | // global vars //////////////////////////////////////////////////////////// |
| 185 | 244 | |
| 245 | |
| 186 | 246 | // local vars ///////////////////////////////////////////////////////////// |
| 187 | 247 | |
| 188 | | static UINT8 key[16]; // security device on gamecard (video games only) |
| 189 | 248 | |
| 190 | | static UINT8 e2ram[1024]; // x24C08 e2ram |
| 191 | 249 | |
| 192 | | static int mmtr_latch; // mechanical meter latch |
| 193 | | static int triac_latch; // payslide triac latch |
| 194 | | static int vfd1_latch; // vfd1 latch |
| 195 | | static int vfd2_latch; // vfd2 latch |
| 196 | | static int irq_status; // custom chip IRQ status |
| 197 | | static int optic_pattern; // reel optics |
| 198 | | static int uart1_data; |
| 199 | | static int uart2_data; |
| 200 | | static int data_to_uart1; |
| 201 | | static int data_to_uart2; |
| 202 | | static int locked; // hardware lock/unlock status (0=unlocked) |
| 203 | | static int is_timer_enabled; |
| 204 | | static int reel_changed; |
| 205 | | static int coin_inhibits; |
| 206 | | static int irq_timer_stat; |
| 207 | | static int expansion_latch; |
| 208 | | static int global_volume; // 0-31 |
| 209 | | static int volume_override; // 0 / 1 |
| 210 | 250 | |
| 211 | | static int sc2_show_door; // flag <>0, show door state |
| 212 | | static int sc2_door_state; // door switch strobe/data |
| 213 | 251 | |
| 214 | | static int reel12_latch; |
| 215 | | static int reel34_latch; |
| 216 | | static int reel56_latch; |
| 217 | | static int pay_latch; |
| 218 | 252 | |
| 219 | | static int slide_states[6]; |
| 220 | | static int slide_pay_sensor[6]; |
| 221 | 253 | |
| 222 | | static int has_hopper; // flag <>0, scorpion2 board has hopper connected |
| 223 | 254 | |
| 224 | | static int triac_select; |
| 225 | 255 | |
| 226 | | static int hopper_running; // flag <>0, hopper is running used in some scorpion2 videogames |
| 227 | | static int hopper_coin_sense; |
| 228 | | static int timercnt; // timer counts up every IRQ (=1000 times a second) |
| 229 | 256 | |
| 230 | | static int watchdog_cnt; |
| 231 | | static int watchdog_kicked; |
| 232 | 257 | |
| 233 | 258 | // user interface stuff /////////////////////////////////////////////////// |
| 234 | 259 | |
| 235 | | static UINT8 Lamps[256]; |
| 236 | | static UINT8 sc2_Inputs[64]; |
| 237 | 260 | |
| 238 | | static UINT8 input_override[64];// bit pattern, bit set means this input is overriden and cannot be changed with switches |
| 239 | 261 | |
| 240 | 262 | /* INPUTS layout |
| 241 | 263 | |
| r10427 | r10428 | |
| 281 | 303 | |
| 282 | 304 | /////////////////////////////////////////////////////////////////////////// |
| 283 | 305 | |
| 284 | | static int get_scorpion2_uart_status(void) |
| 306 | static int get_scorpion2_uart_status(running_machine *machine) |
| 285 | 307 | { |
| 286 | 308 | int status = 0; |
| 287 | 309 | |
| r10427 | r10428 | |
| 297 | 319 | |
| 298 | 320 | static void on_scorpion2_reset(running_machine *machine) |
| 299 | 321 | { |
| 300 | | vfd1_latch = 0; |
| 301 | | vfd2_latch = 0; |
| 302 | | mmtr_latch = 0; |
| 303 | | triac_latch = 0; |
| 304 | | irq_status = 0; |
| 305 | | is_timer_enabled = 1; |
| 306 | | coin_inhibits = 0; |
| 307 | | irq_timer_stat = 0; |
| 308 | | expansion_latch = 0; |
| 309 | | global_volume = 0; |
| 310 | | volume_override = 0; |
| 311 | | triac_select = 0; |
| 312 | | pay_latch = 0; |
| 322 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 323 | state->vfd1_latch = 0; |
| 324 | state->vfd2_latch = 0; |
| 325 | state->mmtr_latch = 0; |
| 326 | state->triac_latch = 0; |
| 327 | state->irq_status = 0; |
| 328 | state->is_timer_enabled = 1; |
| 329 | state->coin_inhibits = 0; |
| 330 | state->irq_timer_stat = 0; |
| 331 | state->expansion_latch = 0; |
| 332 | state->global_volume = 0; |
| 333 | state->volume_override = 0; |
| 334 | state->triac_select = 0; |
| 335 | state->pay_latch = 0; |
| 313 | 336 | |
| 314 | | reel12_latch = 0; |
| 315 | | reel34_latch = 0; |
| 316 | | reel56_latch = 0; |
| 337 | state->reel12_latch = 0; |
| 338 | state->reel34_latch = 0; |
| 339 | state->reel56_latch = 0; |
| 317 | 340 | |
| 318 | | hopper_running = 0; // for video games |
| 319 | | hopper_coin_sense = 0; |
| 341 | state->hopper_running = 0; // for video games |
| 342 | state->hopper_coin_sense = 0; |
| 320 | 343 | |
| 321 | | slide_states[0] = 0; |
| 322 | | slide_states[1] = 0; |
| 323 | | slide_states[2] = 0; |
| 324 | | slide_states[3] = 0; |
| 325 | | slide_states[4] = 0; |
| 326 | | slide_states[5] = 0; |
| 344 | state->slide_states[0] = 0; |
| 345 | state->slide_states[1] = 0; |
| 346 | state->slide_states[2] = 0; |
| 347 | state->slide_states[3] = 0; |
| 348 | state->slide_states[4] = 0; |
| 349 | state->slide_states[5] = 0; |
| 327 | 350 | |
| 328 | | watchdog_cnt = 0; |
| 329 | | watchdog_kicked = 0; |
| 351 | state->watchdog_cnt = 0; |
| 352 | state->watchdog_kicked = 0; |
| 330 | 353 | |
| 331 | 354 | |
| 332 | 355 | BFM_BD1_reset(0); // reset display1 |
| 333 | 356 | BFM_BD1_reset(1); // reset display2 |
| 334 | 357 | |
| 335 | | e2ram_reset(); |
| 358 | e2ram_reset(machine); |
| 336 | 359 | |
| 337 | 360 | devtag_reset(machine, "ymsnd"); |
| 338 | 361 | |
| r10427 | r10428 | |
| 350 | 373 | if ( stepper_optic_state(i) ) pattern |= 1<<i; |
| 351 | 374 | } |
| 352 | 375 | |
| 353 | | optic_pattern = pattern; |
| 376 | state->optic_pattern = pattern; |
| 354 | 377 | |
| 355 | 378 | } |
| 356 | 379 | |
| 357 | | locked = 0; |
| 380 | state->locked = 0; |
| 358 | 381 | |
| 359 | 382 | // make sure no inputs are overidden //////////////////////////////////// |
| 360 | | memset(input_override, 0, sizeof(input_override)); |
| 383 | memset(state->input_override, 0, sizeof(state->input_override)); |
| 361 | 384 | |
| 362 | 385 | // init rom bank //////////////////////////////////////////////////////// |
| 363 | 386 | |
| r10427 | r10428 | |
| 373 | 396 | |
| 374 | 397 | /////////////////////////////////////////////////////////////////////////// |
| 375 | 398 | |
| 376 | | void Scorpion2_SetSwitchState(int strobe, int data, int state) |
| 399 | void Scorpion2_SetSwitchState(running_machine *machine, int strobe, int data, int state) |
| 377 | 400 | { |
| 401 | bfm_sc2_state *drvstate = machine->driver_data<bfm_sc2_state>(); |
| 378 | 402 | if ( strobe < 11 && data < 8 ) |
| 379 | 403 | { |
| 380 | 404 | if ( strobe < 8 ) |
| 381 | 405 | { |
| 382 | | input_override[strobe] |= (1<<data); |
| 406 | drvstate->input_override[strobe] |= (1<<data); |
| 383 | 407 | |
| 384 | | if ( state ) sc2_Inputs[strobe] |= (1<<data); |
| 385 | | else sc2_Inputs[strobe] &= ~(1<<data); |
| 408 | if ( state ) drvstate->sc2_Inputs[strobe] |= (1<<data); |
| 409 | else drvstate->sc2_Inputs[strobe] &= ~(1<<data); |
| 386 | 410 | } |
| 387 | 411 | else |
| 388 | 412 | { |
| 389 | 413 | if ( data > 2 ) |
| 390 | 414 | { |
| 391 | | input_override[strobe-8+4] |= (1<<(data+2)); |
| 415 | drvstate->input_override[strobe-8+4] |= (1<<(data+2)); |
| 392 | 416 | |
| 393 | | if ( state ) sc2_Inputs[strobe-8+4] |= (1<<(data+2)); |
| 394 | | else sc2_Inputs[strobe-8+4] &= ~(1<<(data+2)); |
| 417 | if ( state ) drvstate->sc2_Inputs[strobe-8+4] |= (1<<(data+2)); |
| 418 | else drvstate->sc2_Inputs[strobe-8+4] &= ~(1<<(data+2)); |
| 395 | 419 | } |
| 396 | 420 | else |
| 397 | 421 | { |
| 398 | | input_override[strobe-8] |= (1<<(data+5)); |
| 422 | drvstate->input_override[strobe-8] |= (1<<(data+5)); |
| 399 | 423 | |
| 400 | | if ( state ) sc2_Inputs[strobe-8] |= (1 << (data+5)); |
| 401 | | else sc2_Inputs[strobe-8] &= ~(1 << (data+5)); |
| 424 | if ( state ) drvstate->sc2_Inputs[strobe-8] |= (1 << (data+5)); |
| 425 | else drvstate->sc2_Inputs[strobe-8] &= ~(1 << (data+5)); |
| 402 | 426 | } |
| 403 | 427 | } |
| 404 | 428 | } |
| r10427 | r10428 | |
| 406 | 430 | |
| 407 | 431 | /////////////////////////////////////////////////////////////////////////// |
| 408 | 432 | |
| 409 | | int Scorpion2_GetSwitchState(int strobe, int data) |
| 433 | int Scorpion2_GetSwitchState(running_machine *machine, int strobe, int data) |
| 410 | 434 | { |
| 435 | bfm_sc2_state *drvstate = machine->driver_data<bfm_sc2_state>(); |
| 411 | 436 | int state = 0; |
| 412 | 437 | |
| 413 | 438 | if ( strobe < 11 && data < 8 ) |
| 414 | 439 | { |
| 415 | 440 | if ( strobe < 8 ) |
| 416 | 441 | { |
| 417 | | state = (sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0; |
| 442 | state = (drvstate->sc2_Inputs[strobe] & (1<<data) ) ? 1 : 0; |
| 418 | 443 | } |
| 419 | 444 | else |
| 420 | 445 | { |
| 421 | 446 | if ( data > 2 ) |
| 422 | 447 | { |
| 423 | | state = (sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0; |
| 448 | state = (drvstate->sc2_Inputs[strobe-8+4] & (1<<(data+2)) ) ? 1 : 0; |
| 424 | 449 | } |
| 425 | 450 | else |
| 426 | 451 | { |
| 427 | | state = (sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0; |
| 452 | state = (drvstate->sc2_Inputs[strobe-8] & (1 << (data+5)) ) ? 1 : 0; |
| 428 | 453 | } |
| 429 | 454 | } |
| 430 | 455 | } |
| r10427 | r10428 | |
| 435 | 460 | |
| 436 | 461 | static NVRAM_HANDLER( bfm_sc2 ) |
| 437 | 462 | { |
| 463 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 438 | 464 | static const UINT8 init_e2ram[10] = { 1, 4, 10, 20, 0, 1, 1, 4, 10, 20 }; |
| 439 | 465 | if ( read_or_write ) |
| 440 | 466 | { // writing |
| 441 | | file->write(e2ram,sizeof(e2ram)); |
| 467 | file->write(state->e2ram,sizeof(state->e2ram)); |
| 442 | 468 | } |
| 443 | 469 | else |
| 444 | 470 | { // reading |
| 445 | 471 | if ( file ) |
| 446 | 472 | { |
| 447 | | file->read(e2ram,sizeof(e2ram)); |
| 473 | file->read(state->e2ram,sizeof(state->e2ram)); |
| 448 | 474 | } |
| 449 | 475 | else |
| 450 | 476 | { |
| 451 | | memset(e2ram,0x00,sizeof(e2ram)); |
| 452 | | memcpy(e2ram,init_e2ram,sizeof(init_e2ram)); |
| 477 | memset(state->e2ram,0x00,sizeof(state->e2ram)); |
| 478 | memcpy(state->e2ram,init_e2ram,sizeof(init_e2ram)); |
| 453 | 479 | } |
| 454 | 480 | } |
| 455 | 481 | } |
| r10427 | r10428 | |
| 458 | 484 | |
| 459 | 485 | static WRITE8_HANDLER( watchdog_w ) |
| 460 | 486 | { |
| 461 | | watchdog_kicked = 1; |
| 487 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 488 | state->watchdog_kicked = 1; |
| 462 | 489 | } |
| 463 | 490 | |
| 464 | 491 | /////////////////////////////////////////////////////////////////////////// |
| r10427 | r10428 | |
| 472 | 499 | |
| 473 | 500 | static INTERRUPT_GEN( timer_irq ) |
| 474 | 501 | { |
| 475 | | timercnt++; |
| 502 | bfm_sc2_state *state = device->machine->driver_data<bfm_sc2_state>(); |
| 503 | state->timercnt++; |
| 476 | 504 | |
| 477 | | if ( watchdog_kicked ) |
| 505 | if ( state->watchdog_kicked ) |
| 478 | 506 | { |
| 479 | | watchdog_cnt = 0; |
| 480 | | watchdog_kicked = 0; |
| 507 | state->watchdog_cnt = 0; |
| 508 | state->watchdog_kicked = 0; |
| 481 | 509 | } |
| 482 | 510 | else |
| 483 | 511 | { |
| 484 | | watchdog_cnt++; |
| 485 | | if ( watchdog_cnt > 2 ) // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine |
| 512 | state->watchdog_cnt++; |
| 513 | if ( state->watchdog_cnt > 2 ) // this is a hack, i don't know what the watchdog timeout is, 3 IRQ's works fine |
| 486 | 514 | { // reset board |
| 487 | 515 | device->machine->schedule_soft_reset(); // reset entire machine. CPU 0 should be enough, but that doesn't seem to work !! |
| 488 | 516 | on_scorpion2_reset(device->machine); |
| r10427 | r10428 | |
| 490 | 518 | } |
| 491 | 519 | } |
| 492 | 520 | |
| 493 | | if ( is_timer_enabled ) |
| 521 | if ( state->is_timer_enabled ) |
| 494 | 522 | { |
| 495 | | irq_timer_stat = 0x01; |
| 496 | | irq_status = 0x02; |
| 523 | state->irq_timer_stat = 0x01; |
| 524 | state->irq_status = 0x02; |
| 497 | 525 | |
| 498 | 526 | generic_pulse_irq_line(device, M6809_IRQ_LINE); |
| 499 | 527 | } |
| r10427 | r10428 | |
| 503 | 531 | |
| 504 | 532 | static WRITE8_HANDLER( reel12_vid_w ) // in a video cabinet this is used to drive a hopper |
| 505 | 533 | { |
| 506 | | reel12_latch = data; |
| 534 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 535 | state->reel12_latch = data; |
| 507 | 536 | |
| 508 | | if ( has_hopper ) |
| 537 | if ( state->has_hopper ) |
| 509 | 538 | { |
| 510 | | int oldhop = hopper_running; |
| 539 | int oldhop = state->hopper_running; |
| 511 | 540 | |
| 512 | 541 | if ( data & 0x01 ) |
| 513 | 542 | { // hopper power |
| 514 | 543 | if ( data & 0x02 ) |
| 515 | 544 | { |
| 516 | | hopper_running = 1; |
| 545 | state->hopper_running = 1; |
| 517 | 546 | } |
| 518 | 547 | else |
| 519 | 548 | { |
| 520 | | hopper_running = 0; |
| 549 | state->hopper_running = 0; |
| 521 | 550 | } |
| 522 | 551 | } |
| 523 | 552 | else |
| 524 | 553 | { |
| 525 | | //hopper_coin_sense = 0; |
| 526 | | hopper_running = 0; |
| 554 | //state->hopper_coin_sense = 0; |
| 555 | state->hopper_running = 0; |
| 527 | 556 | } |
| 528 | 557 | |
| 529 | | if ( oldhop != hopper_running ) |
| 558 | if ( oldhop != state->hopper_running ) |
| 530 | 559 | { |
| 531 | | hopper_coin_sense = 0; |
| 532 | | oldhop = hopper_running; |
| 560 | state->hopper_coin_sense = 0; |
| 561 | oldhop = state->hopper_running; |
| 533 | 562 | } |
| 534 | 563 | } |
| 535 | 564 | } |
| r10427 | r10428 | |
| 538 | 567 | |
| 539 | 568 | static WRITE8_HANDLER( reel34_w ) |
| 540 | 569 | { |
| 541 | | reel34_latch = data; |
| 570 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 571 | state->reel34_latch = data; |
| 542 | 572 | |
| 543 | | if ( stepper_update(2, data ) ) reel_changed |= 0x04; |
| 544 | | if ( stepper_update(3, data>>4) ) reel_changed |= 0x08; |
| 573 | if ( stepper_update(2, data ) ) state->reel_changed |= 0x04; |
| 574 | if ( stepper_update(3, data>>4) ) state->reel_changed |= 0x08; |
| 545 | 575 | |
| 546 | | if ( stepper_optic_state(2) ) optic_pattern |= 0x04; |
| 547 | | else optic_pattern &= ~0x04; |
| 548 | | if ( stepper_optic_state(3) ) optic_pattern |= 0x08; |
| 549 | | else optic_pattern &= ~0x08; |
| 576 | if ( stepper_optic_state(2) ) state->optic_pattern |= 0x04; |
| 577 | else state->optic_pattern &= ~0x04; |
| 578 | if ( stepper_optic_state(3) ) state->optic_pattern |= 0x08; |
| 579 | else state->optic_pattern &= ~0x08; |
| 550 | 580 | |
| 551 | 581 | awp_draw_reel(2); |
| 552 | 582 | awp_draw_reel(3); |
| r10427 | r10428 | |
| 556 | 586 | |
| 557 | 587 | static WRITE8_HANDLER( reel56_w ) |
| 558 | 588 | { |
| 559 | | reel56_latch = data; |
| 589 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 590 | state->reel56_latch = data; |
| 560 | 591 | |
| 561 | | if ( stepper_update(4, data ) ) reel_changed |= 0x10; |
| 562 | | if ( stepper_update(5, data>>4) ) reel_changed |= 0x20; |
| 592 | if ( stepper_update(4, data ) ) state->reel_changed |= 0x10; |
| 593 | if ( stepper_update(5, data>>4) ) state->reel_changed |= 0x20; |
| 563 | 594 | |
| 564 | | if ( stepper_optic_state(4) ) optic_pattern |= 0x10; |
| 565 | | else optic_pattern &= ~0x10; |
| 566 | | if ( stepper_optic_state(5) ) optic_pattern |= 0x20; |
| 567 | | else optic_pattern &= ~0x20; |
| 595 | if ( stepper_optic_state(4) ) state->optic_pattern |= 0x10; |
| 596 | else state->optic_pattern &= ~0x10; |
| 597 | if ( stepper_optic_state(5) ) state->optic_pattern |= 0x20; |
| 598 | else state->optic_pattern &= ~0x20; |
| 568 | 599 | |
| 569 | 600 | awp_draw_reel(4); |
| 570 | 601 | awp_draw_reel(5); |
| r10427 | r10428 | |
| 576 | 607 | |
| 577 | 608 | static WRITE8_HANDLER( mmtr_w ) |
| 578 | 609 | { |
| 610 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 579 | 611 | int i; |
| 580 | | int changed = mmtr_latch ^ data; |
| 612 | int changed = state->mmtr_latch ^ data; |
| 581 | 613 | |
| 582 | | mmtr_latch = data; |
| 614 | state->mmtr_latch = data; |
| 583 | 615 | |
| 584 | 616 | for (i = 0; i<8; i++) |
| 585 | 617 | { |
| r10427 | r10428 | |
| 595 | 627 | |
| 596 | 628 | static WRITE8_HANDLER( mux_output_w ) |
| 597 | 629 | { |
| 630 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 598 | 631 | int i; |
| 599 | 632 | int off = offset<<3; |
| 600 | 633 | |
| 601 | 634 | for (i=0; i<8; i++) |
| 602 | 635 | { |
| 603 | | Lamps[ off+i ] = (data & (1 << i)) != 0; |
| 636 | state->Lamps[ off+i ] = (data & (1 << i)) != 0; |
| 604 | 637 | } |
| 605 | 638 | if (offset == 0) // update all lamps after strobe 0 has been updated (HACK) |
| 606 | 639 | { |
| 607 | 640 | for ( i = 0; i < 256; i++ ) |
| 608 | 641 | { |
| 609 | | output_set_lamp_value(i, Lamps[i]); |
| 642 | output_set_lamp_value(i, state->Lamps[i]); |
| 610 | 643 | } |
| 611 | 644 | } |
| 612 | 645 | } |
| r10427 | r10428 | |
| 615 | 648 | |
| 616 | 649 | static READ8_HANDLER( mux_input_r ) |
| 617 | 650 | { |
| 651 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 618 | 652 | int result = 0xFF,t1,t2; |
| 619 | 653 | static const char *const port[] = { "STROBE0", "STROBE1", "STROBE2", "STROBE3", "STROBE4", "STROBE5", "STROBE6", "STROBE7", "STROBE8", "STROBE9", "STROBE10", "STROBE11" }; |
| 620 | 654 | |
| 621 | 655 | if (offset < 8) |
| 622 | 656 | { |
| 623 | 657 | int idx = (offset & 4) ? 4 : 8; |
| 624 | | t1 = input_override[offset]; // strobe 0-7 data 0-4 |
| 625 | | t2 = input_override[offset+idx]; // strobe 8-B data 0-4 |
| 658 | t1 = state->input_override[offset]; // strobe 0-7 data 0-4 |
| 659 | t2 = state->input_override[offset+idx]; // strobe 8-B data 0-4 |
| 626 | 660 | |
| 627 | | t1 = (sc2_Inputs[offset] & t1) | ( ( input_port_read(space->machine, port[offset]) & ~t1) & 0x1F); |
| 661 | t1 = (state->sc2_Inputs[offset] & t1) | ( ( input_port_read(space->machine, port[offset]) & ~t1) & 0x1F); |
| 628 | 662 | if (idx == 8) |
| 629 | | t2 = (sc2_Inputs[offset+8] & t2) | ( ( input_port_read(space->machine, port[offset+8]) & ~t2) << 5); |
| 663 | t2 = (state->sc2_Inputs[offset+8] & t2) | ( ( input_port_read(space->machine, port[offset+8]) & ~t2) << 5); |
| 630 | 664 | else |
| 631 | | t2 = (sc2_Inputs[offset+4] & t2) | ( ( ( input_port_read(space->machine, port[offset+4]) & ~t2) << 2) & 0x60); |
| 665 | t2 = (state->sc2_Inputs[offset+4] & t2) | ( ( ( input_port_read(space->machine, port[offset+4]) & ~t2) << 2) & 0x60); |
| 632 | 666 | |
| 633 | | sc2_Inputs[offset] = (sc2_Inputs[offset] & ~0x1F) | t1; |
| 634 | | sc2_Inputs[offset+idx] = (sc2_Inputs[offset+idx] & ~0x60) | t2; |
| 667 | state->sc2_Inputs[offset] = (state->sc2_Inputs[offset] & ~0x1F) | t1; |
| 668 | state->sc2_Inputs[offset+idx] = (state->sc2_Inputs[offset+idx] & ~0x60) | t2; |
| 635 | 669 | result = t1 | t2; |
| 636 | 670 | } |
| 637 | 671 | |
| r10427 | r10428 | |
| 666 | 700 | |
| 667 | 701 | static WRITE8_HANDLER( volume_override_w ) |
| 668 | 702 | { |
| 669 | | int old = volume_override; |
| 703 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 704 | int old = state->volume_override; |
| 670 | 705 | |
| 671 | | volume_override = data?1:0; |
| 706 | state->volume_override = data?1:0; |
| 672 | 707 | |
| 673 | | if ( old != volume_override ) |
| 708 | if ( old != state->volume_override ) |
| 674 | 709 | { |
| 675 | 710 | ym2413_device *ym = space->machine->device<ym2413_device>("ymsnd"); |
| 676 | 711 | upd7759_device *upd = space->machine->device<upd7759_device>("upd"); |
| 677 | | float percent = volume_override? 1.0f : (32-global_volume)/32.0f; |
| 712 | float percent = state->volume_override? 1.0f : (32-state->global_volume)/32.0f; |
| 678 | 713 | |
| 679 | 714 | ym->set_output_gain(0, percent); |
| 680 | 715 | ym->set_output_gain(1, percent); |
| r10427 | r10428 | |
| 694 | 729 | |
| 695 | 730 | static WRITE8_DEVICE_HANDLER( nec_latch_w ) |
| 696 | 731 | { |
| 732 | bfm_sc2_state *state = device->machine->driver_data<bfm_sc2_state>(); |
| 697 | 733 | int bank = 0; |
| 698 | 734 | |
| 699 | 735 | if ( data & 0x80 ) bank |= 0x01; |
| 700 | | if ( expansion_latch & 2 ) bank |= 0x02; |
| 736 | if ( state->expansion_latch & 2 ) bank |= 0x02; |
| 701 | 737 | |
| 702 | 738 | upd7759_set_bank_base(device, bank*0x20000); |
| 703 | 739 | |
| r10427 | r10428 | |
| 710 | 746 | |
| 711 | 747 | static READ8_HANDLER( vfd_status_hop_r ) // on video games, hopper inputs are connected to this |
| 712 | 748 | { |
| 749 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 713 | 750 | // b7 = NEC busy |
| 714 | 751 | // b6 = alpha busy (also matrix board) |
| 715 | 752 | // b5 - b0 = reel optics |
| 716 | 753 | |
| 717 | 754 | int result = 0; |
| 718 | 755 | |
| 719 | | if ( has_hopper ) |
| 756 | if ( state->has_hopper ) |
| 720 | 757 | { |
| 721 | 758 | result |= 0x04; // hopper high level |
| 722 | 759 | result |= 0x08; // hopper low level |
| 723 | 760 | |
| 724 | 761 | result |= 0x01|0x02; |
| 725 | 762 | |
| 726 | | if ( hopper_running ) |
| 763 | if ( state->hopper_running ) |
| 727 | 764 | { |
| 728 | 765 | result &= ~0x01; // set motor running input |
| 729 | 766 | |
| 730 | | if ( timercnt & 0x04 ) hopper_coin_sense ^= 1; // toggle coin seen |
| 767 | if ( state->timercnt & 0x04 ) state->hopper_coin_sense ^= 1; // toggle coin seen |
| 731 | 768 | |
| 732 | | if ( hopper_coin_sense ) result &= ~0x02; // update coin seen input |
| 769 | if ( state->hopper_coin_sense ) result &= ~0x02; // update coin seen input |
| 733 | 770 | } |
| 734 | 771 | } |
| 735 | 772 | |
| r10427 | r10428 | |
| 742 | 779 | |
| 743 | 780 | static WRITE8_HANDLER( expansion_latch_w ) |
| 744 | 781 | { |
| 745 | | int changed = expansion_latch^data; |
| 782 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 783 | int changed = state->expansion_latch^data; |
| 746 | 784 | |
| 747 | | expansion_latch = data; |
| 785 | state->expansion_latch = data; |
| 748 | 786 | |
| 749 | 787 | // bit0, 1 = lamp mux disabled, 0 = lamp mux enabled |
| 750 | 788 | // bit1, ? used in Del's millions |
| r10427 | r10428 | |
| 761 | 799 | { // changed from high to low, |
| 762 | 800 | if ( !(data & 0x08) ) |
| 763 | 801 | { |
| 764 | | if ( global_volume < 31 ) global_volume++; //0-31 expressed as 1-32 |
| 802 | if ( state->global_volume < 31 ) state->global_volume++; //0-31 expressed as 1-32 |
| 765 | 803 | } |
| 766 | 804 | else |
| 767 | 805 | { |
| 768 | | if ( global_volume > 0 ) global_volume--; |
| 806 | if ( state->global_volume > 0 ) state->global_volume--; |
| 769 | 807 | } |
| 770 | 808 | |
| 771 | 809 | { |
| 772 | 810 | ym2413_device *ym = space->machine->device<ym2413_device>("ymsnd"); |
| 773 | 811 | upd7759_device *upd = space->machine->device<upd7759_device>("upd"); |
| 774 | | float percent = volume_override ? 1.0f : (32-global_volume)/32.0f; |
| 812 | float percent = state->volume_override ? 1.0f : (32-state->global_volume)/32.0f; |
| 775 | 813 | |
| 776 | 814 | ym->set_output_gain(0, percent); |
| 777 | 815 | ym->set_output_gain(1, percent); |
| r10427 | r10428 | |
| 798 | 836 | |
| 799 | 837 | static WRITE8_HANDLER( timerirq_w ) |
| 800 | 838 | { |
| 801 | | is_timer_enabled = data & 1; |
| 839 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 840 | state->is_timer_enabled = data & 1; |
| 802 | 841 | } |
| 803 | 842 | |
| 804 | 843 | /////////////////////////////////////////////////////////////////////////// |
| 805 | 844 | |
| 806 | 845 | static READ8_HANDLER( timerirqclr_r ) |
| 807 | 846 | { |
| 808 | | irq_timer_stat = 0; |
| 809 | | irq_status = 0; |
| 847 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 848 | state->irq_timer_stat = 0; |
| 849 | state->irq_status = 0; |
| 810 | 850 | |
| 811 | 851 | return 0; |
| 812 | 852 | } |
| r10427 | r10428 | |
| 815 | 855 | |
| 816 | 856 | static READ8_HANDLER( irqstatus_r ) |
| 817 | 857 | { |
| 818 | | int result = irq_status | irq_timer_stat | 0x80; // 0x80 = ~MUXERROR |
| 858 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 859 | int result = state->irq_status | state->irq_timer_stat | 0x80; // 0x80 = ~MUXERROR |
| 819 | 860 | |
| 820 | | irq_timer_stat = 0; |
| 861 | state->irq_timer_stat = 0; |
| 821 | 862 | |
| 822 | 863 | return result; |
| 823 | 864 | } |
| r10427 | r10428 | |
| 826 | 867 | |
| 827 | 868 | static WRITE8_HANDLER( coininhib_w ) |
| 828 | 869 | { |
| 829 | | int changed = coin_inhibits^data,i,p; |
| 870 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 871 | int changed = state->coin_inhibits^data,i,p; |
| 830 | 872 | |
| 831 | | coin_inhibits = data; |
| 873 | state->coin_inhibits = data; |
| 832 | 874 | |
| 833 | 875 | p = 0x01; |
| 834 | 876 | i = 0; |
| r10427 | r10428 | |
| 857 | 899 | |
| 858 | 900 | static WRITE8_HANDLER( payout_latch_w ) |
| 859 | 901 | { |
| 860 | | pay_latch = data; |
| 902 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 903 | state->pay_latch = data; |
| 861 | 904 | } |
| 862 | 905 | |
| 863 | 906 | /////////////////////////////////////////////////////////////////////////// |
| 864 | 907 | |
| 865 | 908 | static WRITE8_HANDLER( payout_triac_w ) |
| 866 | 909 | { |
| 867 | | if ( triac_select == 0x57 ) |
| 910 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 911 | if ( state->triac_select == 0x57 ) |
| 868 | 912 | { |
| 869 | 913 | int slide = 0; |
| 870 | 914 | |
| 871 | | switch ( pay_latch ) |
| 915 | switch ( state->pay_latch ) |
| 872 | 916 | { |
| 873 | 917 | case 0x01: slide = 1; |
| 874 | 918 | break; |
| r10427 | r10428 | |
| 893 | 937 | { |
| 894 | 938 | if ( data == 0x4D ) |
| 895 | 939 | { |
| 896 | | if ( !slide_states[slide] ) |
| 940 | if ( !state->slide_states[slide] ) |
| 897 | 941 | { |
| 898 | | if ( slide_pay_sensor[slide] ) |
| 942 | if ( state->slide_pay_sensor[slide] ) |
| 899 | 943 | { |
| 900 | | int strobe = slide_pay_sensor[slide]>>4, data = slide_pay_sensor[slide]&0x0F; |
| 944 | int strobe = state->slide_pay_sensor[slide]>>4, data = state->slide_pay_sensor[slide]&0x0F; |
| 901 | 945 | |
| 902 | | Scorpion2_SetSwitchState(strobe, data, 0); |
| 946 | Scorpion2_SetSwitchState(space->machine, strobe, data, 0); |
| 903 | 947 | } |
| 904 | | slide_states[slide] = 1; |
| 948 | state->slide_states[slide] = 1; |
| 905 | 949 | } |
| 906 | 950 | } |
| 907 | 951 | else |
| 908 | 952 | { |
| 909 | | if ( slide_states[slide] ) |
| 953 | if ( state->slide_states[slide] ) |
| 910 | 954 | { |
| 911 | | if ( slide_pay_sensor[slide] ) |
| 955 | if ( state->slide_pay_sensor[slide] ) |
| 912 | 956 | { |
| 913 | | int strobe = slide_pay_sensor[slide]>>4, data = slide_pay_sensor[slide]&0x0F; |
| 957 | int strobe = state->slide_pay_sensor[slide]>>4, data = state->slide_pay_sensor[slide]&0x0F; |
| 914 | 958 | |
| 915 | | Scorpion2_SetSwitchState(strobe, data, 1); |
| 959 | Scorpion2_SetSwitchState(space->machine, strobe, data, 1); |
| 916 | 960 | } |
| 917 | | slide_states[slide] = 0; |
| 961 | state->slide_states[slide] = 0; |
| 918 | 962 | } |
| 919 | 963 | } |
| 920 | 964 | } |
| r10427 | r10428 | |
| 925 | 969 | |
| 926 | 970 | static WRITE8_HANDLER( payout_select_w ) |
| 927 | 971 | { |
| 928 | | triac_select = data; |
| 972 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 973 | state->triac_select = data; |
| 929 | 974 | } |
| 930 | 975 | |
| 931 | 976 | /////////////////////////////////////////////////////////////////////////// |
| 932 | 977 | |
| 933 | 978 | static WRITE8_HANDLER( vfd1_data_w ) |
| 934 | 979 | { |
| 935 | | vfd1_latch = data; |
| 980 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 981 | state->vfd1_latch = data; |
| 936 | 982 | BFM_BD1_newdata(0, data); |
| 937 | 983 | BFM_BD1_draw(0); |
| 938 | 984 | } |
| r10427 | r10428 | |
| 941 | 987 | |
| 942 | 988 | static WRITE8_HANDLER( vfd2_data_w ) |
| 943 | 989 | { |
| 944 | | vfd2_latch = data; |
| 990 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 991 | state->vfd2_latch = data; |
| 945 | 992 | BFM_BD1_newdata(1, data); |
| 946 | 993 | BFM_BD1_draw(1); |
| 947 | 994 | } |
| r10427 | r10428 | |
| 962 | 1009 | |
| 963 | 1010 | static READ8_HANDLER( uart1stat_r ) |
| 964 | 1011 | { |
| 1012 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 965 | 1013 | int status = 0x06; |
| 966 | 1014 | |
| 967 | | if ( data_to_uart1 ) status |= 0x01; |
| 968 | | if ( !data_to_uart2 ) status |= 0x02; |
| 1015 | if ( state->data_to_uart1 ) status |= 0x01; |
| 1016 | if ( !state->data_to_uart2 ) status |= 0x02; |
| 969 | 1017 | |
| 970 | 1018 | return status; |
| 971 | 1019 | } |
| r10427 | r10428 | |
| 973 | 1021 | |
| 974 | 1022 | static READ8_HANDLER( uart1data_r ) |
| 975 | 1023 | { |
| 976 | | return uart1_data; |
| 1024 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 1025 | return state->uart1_data; |
| 977 | 1026 | } |
| 978 | 1027 | |
| 979 | 1028 | ////////////////////////////////////////////////////////////////////////// |
| r10427 | r10428 | |
| 986 | 1035 | |
| 987 | 1036 | static WRITE8_HANDLER( uart1data_w ) |
| 988 | 1037 | { |
| 989 | | data_to_uart2 = 1; |
| 990 | | uart1_data = data; |
| 1038 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 1039 | state->data_to_uart2 = 1; |
| 1040 | state->uart1_data = data; |
| 991 | 1041 | UART_LOG(("uart1:%x\n", data)); |
| 992 | 1042 | } |
| 993 | 1043 | /////////////////////////////////////////////////////////////////////////// |
| 994 | 1044 | |
| 995 | 1045 | static READ8_HANDLER( uart2stat_r ) |
| 996 | 1046 | { |
| 1047 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 997 | 1048 | int status = 0x06; |
| 998 | 1049 | |
| 999 | | if ( data_to_uart2 ) status |= 0x01; |
| 1000 | | if ( !data_to_uart1 ) status |= 0x02; |
| 1050 | if ( state->data_to_uart2 ) status |= 0x01; |
| 1051 | if ( !state->data_to_uart1 ) status |= 0x02; |
| 1001 | 1052 | |
| 1002 | 1053 | return status; |
| 1003 | 1054 | } |
| r10427 | r10428 | |
| 1005 | 1056 | |
| 1006 | 1057 | static READ8_HANDLER( uart2data_r ) |
| 1007 | 1058 | { |
| 1008 | | return uart2_data; |
| 1059 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 1060 | return state->uart2_data; |
| 1009 | 1061 | } |
| 1010 | 1062 | |
| 1011 | 1063 | /////////////////////////////////////////////////////////////////////////// |
| r10427 | r10428 | |
| 1019 | 1071 | |
| 1020 | 1072 | static WRITE8_HANDLER( uart2data_w ) |
| 1021 | 1073 | { |
| 1022 | | data_to_uart1 = 1; |
| 1023 | | uart2_data = data; |
| 1074 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 1075 | state->data_to_uart1 = 1; |
| 1076 | state->uart2_data = data; |
| 1024 | 1077 | UART_LOG(("uart2:%x\n", data)); |
| 1025 | 1078 | } |
| 1026 | 1079 | |
| r10427 | r10428 | |
| 1048 | 1101 | |
| 1049 | 1102 | static READ8_HANDLER( vid_uart_ctrl_r ) |
| 1050 | 1103 | { |
| 1051 | | return get_scorpion2_uart_status(); |
| 1104 | return get_scorpion2_uart_status(space->machine); |
| 1052 | 1105 | } |
| 1053 | 1106 | |
| 1054 | 1107 | /////////////////////////////////////////////////////////////////////////// |
| 1055 | 1108 | |
| 1056 | 1109 | static READ8_HANDLER( key_r ) |
| 1057 | 1110 | { |
| 1058 | | int result = key[ offset ]; |
| 1111 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 1112 | int result = state->key[ offset ]; |
| 1059 | 1113 | |
| 1060 | 1114 | if ( offset == 7 ) |
| 1061 | 1115 | { |
| 1062 | | result = (result & 0xFE) | read_e2ram(); |
| 1116 | result = (result & 0xFE) | read_e2ram(space->machine); |
| 1063 | 1117 | } |
| 1064 | 1118 | |
| 1065 | 1119 | return result; |
| r10427 | r10428 | |
| 1076 | 1130 | */ |
| 1077 | 1131 | |
| 1078 | 1132 | |
| 1079 | | static int e2reg; |
| 1080 | | static int e2state; |
| 1081 | | static int e2cnt; |
| 1082 | | static int e2data; |
| 1083 | | static int e2address; |
| 1084 | | static int e2rw; |
| 1085 | | static int e2data_pin; |
| 1086 | | static int e2dummywrite; |
| 1087 | 1133 | |
| 1088 | | static int e2data_to_read; |
| 1089 | 1134 | |
| 1090 | 1135 | #define SCL 0x01 //SCL pin (clock) |
| 1091 | 1136 | #define SDA 0x02 //SDA pin (data) |
| 1092 | 1137 | |
| 1093 | 1138 | |
| 1094 | | static void e2ram_reset(void) |
| 1139 | static void e2ram_reset(running_machine *machine) |
| 1095 | 1140 | { |
| 1096 | | e2reg = 0; |
| 1097 | | e2state = 0; |
| 1098 | | e2address = 0; |
| 1099 | | e2rw = 0; |
| 1100 | | e2data_pin = 0; |
| 1101 | | e2data = (SDA|SCL); |
| 1102 | | e2dummywrite = 0; |
| 1103 | | e2data_to_read = 0; |
| 1141 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 1142 | state->e2reg = 0; |
| 1143 | state->e2state = 0; |
| 1144 | state->e2address = 0; |
| 1145 | state->e2rw = 0; |
| 1146 | state->e2data_pin = 0; |
| 1147 | state->e2data = (SDA|SCL); |
| 1148 | state->e2dummywrite = 0; |
| 1149 | state->e2data_to_read = 0; |
| 1104 | 1150 | } |
| 1105 | 1151 | |
| 1106 | | static int recdata(int changed, int data) |
| 1152 | static int recdata(bfm_sc2_state *state, int changed, int data) |
| 1107 | 1153 | { |
| 1108 | 1154 | int res = 1; |
| 1109 | 1155 | |
| 1110 | | if ( e2cnt < 8 ) |
| 1156 | if ( state->e2cnt < 8 ) |
| 1111 | 1157 | { |
| 1112 | 1158 | res = 0; |
| 1113 | 1159 | |
| 1114 | 1160 | if ( (changed & SCL) && (data & SCL) ) |
| 1115 | 1161 | { // clocked in new data |
| 1116 | | int pattern = 1 << (7-e2cnt); |
| 1162 | int pattern = 1 << (7-state->e2cnt); |
| 1117 | 1163 | |
| 1118 | | if ( data & SDA ) e2data |= pattern; |
| 1119 | | else e2data &= ~pattern; |
| 1164 | if ( data & SDA ) state->e2data |= pattern; |
| 1165 | else state->e2data &= ~pattern; |
| 1120 | 1166 | |
| 1121 | | e2data_pin = e2data_to_read & 0x80 ? 1 : 0; |
| 1167 | state->e2data_pin = state->e2data_to_read & 0x80 ? 1 : 0; |
| 1122 | 1168 | |
| 1123 | | e2data_to_read <<= 1; |
| 1169 | state->e2data_to_read <<= 1; |
| 1124 | 1170 | |
| 1125 | | LOG(("e2d pin= %d\n", e2data_pin)); |
| 1171 | LOG(("e2d pin= %d\n", state->e2data_pin)); |
| 1126 | 1172 | |
| 1127 | | e2cnt++; |
| 1128 | | if ( e2cnt >= 8 ) |
| 1173 | state->e2cnt++; |
| 1174 | if ( state->e2cnt >= 8 ) |
| 1129 | 1175 | { |
| 1130 | 1176 | res++; |
| 1131 | 1177 | } |
| r10427 | r10428 | |
| 1155 | 1201 | |
| 1156 | 1202 | // |
| 1157 | 1203 | static WRITE8_HANDLER( e2ram_w ) |
| 1158 | | { // b0 = clock b1 = data |
| 1204 | { |
| 1205 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); // b0 = clock b1 = data |
| 1159 | 1206 | |
| 1160 | 1207 | int changed, ack; |
| 1161 | 1208 | |
| 1162 | 1209 | data ^= (SDA|SCL); // invert signals |
| 1163 | 1210 | |
| 1164 | | changed = (e2reg^data) & 0x03; |
| 1211 | changed = (state->e2reg^data) & 0x03; |
| 1165 | 1212 | |
| 1166 | | e2reg = data; |
| 1213 | state->e2reg = data; |
| 1167 | 1214 | |
| 1168 | 1215 | if ( changed ) |
| 1169 | 1216 | { |
| r10427 | r10428 | |
| 1173 | 1220 | ( !(changed & SCL) && (data & SCL) ) // SCL=1 and not changed |
| 1174 | 1221 | ) |
| 1175 | 1222 | { // X24C08 Start condition (1->0 on SDA while SCL=1) |
| 1176 | | e2dummywrite = ( e2state == 5 ); |
| 1223 | state->e2dummywrite = ( state->e2state == 5 ); |
| 1177 | 1224 | |
| 1178 | | LOG(("e2ram: c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, e2dummywrite )); |
| 1225 | LOG(("e2ram: c:%d d:%d Start condition dummywrite=%d\n", (data & SCL)?1:0, (data&SDA)?1:0, state->e2dummywrite )); |
| 1179 | 1226 | |
| 1180 | | e2state = 1; // ready for commands |
| 1181 | | e2cnt = 0; |
| 1182 | | e2data = 0; |
| 1227 | state->e2state = 1; // ready for commands |
| 1228 | state->e2cnt = 0; |
| 1229 | state->e2data = 0; |
| 1183 | 1230 | break; |
| 1184 | 1231 | } |
| 1185 | 1232 | |
| r10427 | r10428 | |
| 1188 | 1235 | ) |
| 1189 | 1236 | { // X24C08 Stop condition (0->1 on SDA while SCL=1) |
| 1190 | 1237 | LOG(("e2ram: c:%d d:%d Stop condition\n", (data & SCL)?1:0, (data&SDA)?1:0 )); |
| 1191 | | e2state = 0; |
| 1192 | | e2data = 0; |
| 1238 | state->e2state = 0; |
| 1239 | state->e2data = 0; |
| 1193 | 1240 | break; |
| 1194 | 1241 | } |
| 1195 | 1242 | |
| 1196 | | switch ( e2state ) |
| 1243 | switch ( state->e2state ) |
| 1197 | 1244 | { |
| 1198 | 1245 | case 1: // Receiving address + R/W bit |
| 1199 | 1246 | |
| 1200 | | if ( recdata(changed, data) ) |
| 1247 | if ( recdata(state, changed, data) ) |
| 1201 | 1248 | { |
| 1202 | | e2address = (e2address & 0x00FF) | ((e2data>>1) & 0x03) << 8; |
| 1203 | | e2cnt = 0; |
| 1204 | | e2rw = e2data & 1; |
| 1249 | state->e2address = (state->e2address & 0x00FF) | ((state->e2data>>1) & 0x03) << 8; |
| 1250 | state->e2cnt = 0; |
| 1251 | state->e2rw = state->e2data & 1; |
| 1205 | 1252 | |
| 1206 | 1253 | LOG(("e2ram: Slave address received !! device id=%01X device adr=%01d high order adr %0X RW=%d) %02X\n", |
| 1207 | | e2data>>4, (e2data & 0x08)?1:0, (e2data>>1) & 0x03, e2rw , e2data )); |
| 1254 | state->e2data>>4, (state->e2data & 0x08)?1:0, (state->e2data>>1) & 0x03, state->e2rw , state->e2data )); |
| 1208 | 1255 | |
| 1209 | | e2state = 2; |
| 1256 | state->e2state = 2; |
| 1210 | 1257 | } |
| 1211 | 1258 | break; |
| 1212 | 1259 | |
| r10427 | r10428 | |
| 1215 | 1262 | ack = recAck(changed,data); |
| 1216 | 1263 | if ( ack ) |
| 1217 | 1264 | { |
| 1218 | | e2data_pin = 0; |
| 1265 | state->e2data_pin = 0; |
| 1219 | 1266 | |
| 1220 | 1267 | if ( ack < 0 ) |
| 1221 | 1268 | { |
| 1222 | 1269 | LOG(("ACK = 0\n")); |
| 1223 | | e2state = 0; |
| 1270 | state->e2state = 0; |
| 1224 | 1271 | } |
| 1225 | 1272 | else |
| 1226 | 1273 | { |
| 1227 | 1274 | LOG(("ACK = 1\n")); |
| 1228 | | if ( e2dummywrite ) |
| 1275 | if ( state->e2dummywrite ) |
| 1229 | 1276 | { |
| 1230 | | e2dummywrite = 0; |
| 1277 | state->e2dummywrite = 0; |
| 1231 | 1278 | |
| 1232 | | e2data_to_read = e2ram[e2address]; |
| 1279 | state->e2data_to_read = state->e2ram[state->e2address]; |
| 1233 | 1280 | |
| 1234 | | if ( e2rw & 1 ) e2state = 7; // read data |
| 1235 | | else e2state = 0; //?not sure |
| 1281 | if ( state->e2rw & 1 ) state->e2state = 7; // read data |
| 1282 | else state->e2state = 0; //?not sure |
| 1236 | 1283 | } |
| 1237 | 1284 | else |
| 1238 | 1285 | { |
| 1239 | | if ( e2rw & 1 ) e2state = 7; // reading |
| 1240 | | else e2state = 3; // writing |
| 1286 | if ( state->e2rw & 1 ) state->e2state = 7; // reading |
| 1287 | else state->e2state = 3; // writing |
| 1241 | 1288 | } |
| 1242 | | switch ( e2state ) |
| 1289 | switch ( state->e2state ) |
| 1243 | 1290 | { |
| 1244 | 1291 | case 7: |
| 1245 | | LOG(("read address %04X\n",e2address)); |
| 1246 | | e2data_to_read = e2ram[e2address]; |
| 1292 | LOG(("read address %04X\n",state->e2address)); |
| 1293 | state->e2data_to_read = state->e2ram[state->e2address]; |
| 1247 | 1294 | break; |
| 1248 | 1295 | case 3: |
| 1249 | 1296 | LOG(("write, awaiting address\n")); |
| 1250 | 1297 | break; |
| 1251 | 1298 | default: |
| 1252 | | LOG(("?unknow action %04X\n",e2address)); |
| 1299 | LOG(("?unknow action %04X\n",state->e2address)); |
| 1253 | 1300 | break; |
| 1254 | 1301 | } |
| 1255 | 1302 | } |
| 1256 | | e2data = 0; |
| 1303 | state->e2data = 0; |
| 1257 | 1304 | } |
| 1258 | 1305 | break; |
| 1259 | 1306 | |
| 1260 | 1307 | case 3: // writing data, receiving address |
| 1261 | 1308 | |
| 1262 | | if ( recdata(changed, data) ) |
| 1309 | if ( recdata(state, changed, data) ) |
| 1263 | 1310 | { |
| 1264 | | e2data_pin = 0; |
| 1265 | | e2address = (e2address & 0xFF00) | e2data; |
| 1311 | state->e2data_pin = 0; |
| 1312 | state->e2address = (state->e2address & 0xFF00) | state->e2data; |
| 1266 | 1313 | |
| 1267 | | LOG(("write address = %04X waiting for ACK\n", e2address)); |
| 1268 | | e2state = 4; |
| 1269 | | e2cnt = 0; |
| 1270 | | e2data = 0; |
| 1314 | LOG(("write address = %04X waiting for ACK\n", state->e2address)); |
| 1315 | state->e2state = 4; |
| 1316 | state->e2cnt = 0; |
| 1317 | state->e2data = 0; |
| 1271 | 1318 | } |
| 1272 | 1319 | break; |
| 1273 | 1320 | |
| r10427 | r10428 | |
| 1276 | 1323 | ack = recAck(changed,data); |
| 1277 | 1324 | if ( ack ) |
| 1278 | 1325 | { |
| 1279 | | e2data_pin = 0; // pin=0, no error !! |
| 1326 | state->e2data_pin = 0; // pin=0, no error !! |
| 1280 | 1327 | |
| 1281 | 1328 | if ( ack < 0 ) |
| 1282 | 1329 | { |
| 1283 | | e2state = 0; |
| 1330 | state->e2state = 0; |
| 1284 | 1331 | LOG(("ACK = 0, cancel write\n" )); |
| 1285 | 1332 | } |
| 1286 | 1333 | else |
| 1287 | 1334 | { |
| 1288 | | e2state = 5; |
| 1335 | state->e2state = 5; |
| 1289 | 1336 | LOG(("ACK = 1, awaiting data to write\n" )); |
| 1290 | 1337 | } |
| 1291 | 1338 | } |
| 1292 | 1339 | break; |
| 1293 | 1340 | |
| 1294 | 1341 | case 5: // receive data to write |
| 1295 | | if ( recdata(changed, data) ) |
| 1342 | if ( recdata(state, changed, data) ) |
| 1296 | 1343 | { |
| 1297 | | LOG(("write data = %02X received, awaiting ACK\n", e2data)); |
| 1298 | | e2cnt = 0; |
| 1299 | | e2state = 6; // wait ack |
| 1344 | LOG(("write data = %02X received, awaiting ACK\n", state->e2data)); |
| 1345 | state->e2cnt = 0; |
| 1346 | state->e2state = 6; // wait ack |
| 1300 | 1347 | } |
| 1301 | 1348 | break; |
| 1302 | 1349 | |
| r10427 | r10428 | |
| 1307 | 1354 | { |
| 1308 | 1355 | if ( ack < 0 ) |
| 1309 | 1356 | { |
| 1310 | | e2state = 0; |
| 1357 | state->e2state = 0; |
| 1311 | 1358 | LOG(("ACK=0, write canceled\n")); |
| 1312 | 1359 | } |
| 1313 | 1360 | else |
| 1314 | 1361 | { |
| 1315 | | LOG(("ACK=1, writing %02X to %04X\n", e2data, e2address)); |
| 1362 | LOG(("ACK=1, writing %02X to %04X\n", state->e2data, state->e2address)); |
| 1316 | 1363 | |
| 1317 | | e2ram[e2address] = e2data; |
| 1364 | state->e2ram[state->e2address] = state->e2data; |
| 1318 | 1365 | |
| 1319 | | e2address = (e2address & ~0x000F) | ((e2address+1)&0x0F); |
| 1366 | state->e2address = (state->e2address & ~0x000F) | ((state->e2address+1)&0x0F); |
| 1320 | 1367 | |
| 1321 | | e2state = 5; // write next address |
| 1368 | state->e2state = 5; // write next address |
| 1322 | 1369 | } |
| 1323 | 1370 | } |
| 1324 | 1371 | break; |
| 1325 | 1372 | |
| 1326 | 1373 | case 7: // receive address from read |
| 1327 | 1374 | |
| 1328 | | if ( recdata(changed, data) ) |
| 1375 | if ( recdata(state, changed, data) ) |
| 1329 | 1376 | { |
| 1330 | | //e2data_pin = 0; |
| 1377 | //state->e2data_pin = 0; |
| 1331 | 1378 | |
| 1332 | | LOG(("address read, data = %02X waiting for ACK\n", e2data )); |
| 1379 | LOG(("address read, data = %02X waiting for ACK\n", state->e2data )); |
| 1333 | 1380 | |
| 1334 | | e2state = 8; |
| 1381 | state->e2state = 8; |
| 1335 | 1382 | } |
| 1336 | 1383 | break; |
| 1337 | 1384 | |
| r10427 | r10428 | |
| 1339 | 1386 | |
| 1340 | 1387 | if ( recAck(changed, data) ) |
| 1341 | 1388 | { |
| 1342 | | e2state = 7; |
| 1389 | state->e2state = 7; |
| 1343 | 1390 | |
| 1344 | | e2address = (e2address & ~0x0F) | ((e2address+1)&0x0F); // lower 4 bits wrap around |
| 1391 | state->e2address = (state->e2address & ~0x0F) | ((state->e2address+1)&0x0F); // lower 4 bits wrap around |
| 1345 | 1392 | |
| 1346 | | e2data_to_read = e2ram[e2address]; |
| 1393 | state->e2data_to_read = state->e2ram[state->e2address]; |
| 1347 | 1394 | |
| 1348 | | LOG(("ready for next address %04X\n", e2address)); |
| 1395 | LOG(("ready for next address %04X\n", state->e2address)); |
| 1349 | 1396 | |
| 1350 | | e2cnt = 0; |
| 1351 | | e2data = 0; |
| 1397 | state->e2cnt = 0; |
| 1398 | state->e2data = 0; |
| 1352 | 1399 | } |
| 1353 | 1400 | break; |
| 1354 | 1401 | |
| r10427 | r10428 | |
| 1362 | 1409 | } |
| 1363 | 1410 | } |
| 1364 | 1411 | |
| 1365 | | static int read_e2ram(void) |
| 1412 | static int read_e2ram(running_machine *machine) |
| 1366 | 1413 | { |
| 1367 | | LOG(("e2ram: r %d (%02X) \n", e2data_pin, e2data_to_read )); |
| 1414 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 1415 | LOG(("e2ram: r %d (%02X) \n", state->e2data_pin, state->e2data_to_read )); |
| 1368 | 1416 | |
| 1369 | | return e2data_pin; |
| 1417 | return state->e2data_pin; |
| 1370 | 1418 | } |
| 1371 | 1419 | |
| 1372 | 1420 | static const UINT16 AddressDecode[]= |
| r10427 | r10428 | |
| 1382 | 1430 | 0 |
| 1383 | 1431 | }; |
| 1384 | 1432 | |
| 1385 | | static UINT8 codec_data[256]; |
| 1386 | 1433 | |
| 1387 | 1434 | /////////////////////////////////////////////////////////////////////////// |
| 1388 | 1435 | static void decode_mainrom(running_machine *machine, const char *rom_region) |
| 1389 | 1436 | { |
| 1437 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 1390 | 1438 | UINT8 *tmp, *rom; |
| 1391 | 1439 | |
| 1392 | 1440 | rom = machine->region(rom_region)->base(); |
| r10427 | r10428 | |
| 1413 | 1461 | pattern <<= 1; |
| 1414 | 1462 | } while ( *(++tab) ); |
| 1415 | 1463 | |
| 1416 | | codec_data[i] = newdata; |
| 1464 | state->codec_data[i] = newdata; |
| 1417 | 1465 | } |
| 1418 | 1466 | |
| 1419 | 1467 | for ( address = 0; address < 0x10000; address++) |
| r10427 | r10428 | |
| 1430 | 1478 | pattern <<= 1; |
| 1431 | 1479 | } while ( *(++tab) ); |
| 1432 | 1480 | |
| 1433 | | rom[newaddress] = codec_data[ tmp[address] ]; |
| 1481 | rom[newaddress] = state->codec_data[ tmp[address] ]; |
| 1434 | 1482 | } |
| 1435 | 1483 | auto_free(machine, tmp); |
| 1436 | 1484 | } |
| r10427 | r10428 | |
| 1448 | 1496 | on_scorpion2_reset(machine); |
| 1449 | 1497 | BFM_BD1_init(0); |
| 1450 | 1498 | BFM_BD1_init(1); |
| 1451 | | //BFM_dm01_reset(); No known video based game has a Matrix board |
| 1499 | //BFM_dm01_reset(machine); No known video based game has a Matrix board |
| 1452 | 1500 | } |
| 1453 | 1501 | |
| 1454 | 1502 | static VIDEO_UPDATE( addersc2 ) |
| 1455 | 1503 | { |
| 1456 | | if ( sc2_show_door ) |
| 1504 | bfm_sc2_state *state = screen->machine->driver_data<bfm_sc2_state>(); |
| 1505 | if ( state->sc2_show_door ) |
| 1457 | 1506 | { |
| 1458 | | output_set_value("door",( Scorpion2_GetSwitchState(sc2_door_state>>4, sc2_door_state & 0x0F) ) ); |
| 1507 | output_set_value("door",( Scorpion2_GetSwitchState(screen->machine,state->sc2_door_state>>4, state->sc2_door_state & 0x0F) ) ); |
| 1459 | 1508 | } |
| 1460 | 1509 | |
| 1461 | 1510 | return VIDEO_UPDATE_CALL(adder2); |
| r10427 | r10428 | |
| 2173 | 2222 | // machine driver for scorpion2 board + adder2 expansion ////////////////// |
| 2174 | 2223 | /////////////////////////////////////////////////////////////////////////// |
| 2175 | 2224 | |
| 2176 | | static MACHINE_CONFIG_START( scorpion2_vid, driver_device ) |
| 2225 | static MACHINE_CONFIG_START( scorpion2_vid, bfm_sc2_state ) |
| 2177 | 2226 | MCFG_MACHINE_RESET( init ) // main scorpion2 board initialisation |
| 2178 | 2227 | MCFG_QUANTUM_TIME(attotime::from_hz(960)) // needed for serial communication !! |
| 2179 | 2228 | MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 ) // 6809 CPU at 2 Mhz |
| r10427 | r10428 | |
| 2212 | 2261 | |
| 2213 | 2262 | static void sc2_common_init(running_machine *machine, int decrypt) |
| 2214 | 2263 | { |
| 2264 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2215 | 2265 | UINT8 *rom; |
| 2216 | 2266 | |
| 2217 | 2267 | if (decrypt) decode_mainrom(machine, "maincpu"); // decode main rom |
| r10427 | r10428 | |
| 2222 | 2272 | memcpy(&rom[0x10000], &rom[0x00000], 0x2000); |
| 2223 | 2273 | } |
| 2224 | 2274 | |
| 2225 | | memset(sc2_Inputs, 0, sizeof(sc2_Inputs)); // clear all inputs |
| 2275 | memset(state->sc2_Inputs, 0, sizeof(state->sc2_Inputs)); // clear all inputs |
| 2226 | 2276 | } |
| 2227 | 2277 | |
| 2228 | 2278 | static void adder2_common_init(running_machine *machine) |
| 2229 | 2279 | { |
| 2280 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2230 | 2281 | UINT8 *pal; |
| 2231 | 2282 | |
| 2232 | 2283 | pal = machine->region("proms")->base(); |
| 2233 | 2284 | if ( pal ) |
| 2234 | 2285 | { |
| 2235 | | memcpy(key, pal, 8); |
| 2286 | memcpy(state->key, pal, 8); |
| 2236 | 2287 | } |
| 2237 | 2288 | } |
| 2238 | 2289 | |
| r10427 | r10428 | |
| 2240 | 2291 | |
| 2241 | 2292 | static DRIVER_INIT (quintoon) |
| 2242 | 2293 | { |
| 2294 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2243 | 2295 | sc2_common_init(machine, 1); |
| 2244 | 2296 | adder2_decode_char_roms(machine); |
| 2245 | 2297 | MechMtr_config(machine,8); // setup mech meters |
| 2246 | 2298 | |
| 2247 | | has_hopper = 0; |
| 2299 | state->has_hopper = 0; |
| 2248 | 2300 | |
| 2249 | | Scorpion2_SetSwitchState(3,0,1); // tube1 level switch |
| 2250 | | Scorpion2_SetSwitchState(3,1,1); // tube2 level switch |
| 2251 | | Scorpion2_SetSwitchState(3,2,1); // tube3 level switch |
| 2301 | Scorpion2_SetSwitchState(machine,3,0,1); // tube1 level switch |
| 2302 | Scorpion2_SetSwitchState(machine,3,1,1); // tube2 level switch |
| 2303 | Scorpion2_SetSwitchState(machine,3,2,1); // tube3 level switch |
| 2252 | 2304 | |
| 2253 | | Scorpion2_SetSwitchState(5,2,1); |
| 2254 | | Scorpion2_SetSwitchState(6,4,1); |
| 2305 | Scorpion2_SetSwitchState(machine,5,2,1); |
| 2306 | Scorpion2_SetSwitchState(machine,6,4,1); |
| 2255 | 2307 | |
| 2256 | | sc2_show_door = 1; |
| 2257 | | sc2_door_state = 0x41; |
| 2308 | state->sc2_show_door = 1; |
| 2309 | state->sc2_door_state = 0x41; |
| 2258 | 2310 | } |
| 2259 | 2311 | |
| 2260 | 2312 | // dutch pyramid intialisation ////////////////////////////////////////////// |
| 2261 | 2313 | |
| 2262 | 2314 | static DRIVER_INIT( pyramid ) |
| 2263 | 2315 | { |
| 2316 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2264 | 2317 | sc2_common_init(machine, 1); |
| 2265 | 2318 | adder2_decode_char_roms(machine); // decode GFX roms |
| 2266 | 2319 | adder2_common_init(machine); |
| 2267 | 2320 | |
| 2268 | | has_hopper = 1; |
| 2321 | state->has_hopper = 1; |
| 2269 | 2322 | |
| 2270 | | Scorpion2_SetSwitchState(3,0,1); // tube1 level switch |
| 2271 | | Scorpion2_SetSwitchState(3,1,1); // tube2 level switch |
| 2272 | | Scorpion2_SetSwitchState(3,2,1); // tube3 level switch |
| 2323 | Scorpion2_SetSwitchState(machine,3,0,1); // tube1 level switch |
| 2324 | Scorpion2_SetSwitchState(machine,3,1,1); // tube2 level switch |
| 2325 | Scorpion2_SetSwitchState(machine,3,2,1); // tube3 level switch |
| 2273 | 2326 | |
| 2274 | | sc2_show_door = 1; |
| 2275 | | sc2_door_state = 0x41; |
| 2327 | state->sc2_show_door = 1; |
| 2328 | state->sc2_door_state = 0x41; |
| 2276 | 2329 | } |
| 2277 | 2330 | // belgian slots initialisation ///////////////////////////////////////////// |
| 2278 | 2331 | |
| 2279 | 2332 | static DRIVER_INIT( sltsbelg ) |
| 2280 | 2333 | { |
| 2334 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2281 | 2335 | sc2_common_init(machine, 1); |
| 2282 | 2336 | adder2_decode_char_roms(machine); // decode GFX roms |
| 2283 | 2337 | adder2_common_init(machine); |
| 2284 | 2338 | |
| 2285 | | has_hopper = 1; |
| 2339 | state->has_hopper = 1; |
| 2286 | 2340 | |
| 2287 | | sc2_show_door = 1; |
| 2288 | | sc2_door_state = 0x41; |
| 2341 | state->sc2_show_door = 1; |
| 2342 | state->sc2_door_state = 0x41; |
| 2289 | 2343 | } |
| 2290 | 2344 | |
| 2291 | 2345 | // other dutch adder games //////////////////////////////////////////////// |
| 2292 | 2346 | |
| 2293 | 2347 | static DRIVER_INIT( adder_dutch ) |
| 2294 | 2348 | { |
| 2349 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2295 | 2350 | sc2_common_init(machine, 1); |
| 2296 | 2351 | adder2_decode_char_roms(machine); // decode GFX roms |
| 2297 | 2352 | adder2_common_init(machine); |
| 2298 | 2353 | |
| 2299 | | has_hopper = 0; |
| 2354 | state->has_hopper = 0; |
| 2300 | 2355 | |
| 2301 | | Scorpion2_SetSwitchState(3,0,1); // tube1 level switch |
| 2302 | | Scorpion2_SetSwitchState(3,1,1); // tube2 level switch |
| 2303 | | Scorpion2_SetSwitchState(3,2,1); // tube3 level switch |
| 2356 | Scorpion2_SetSwitchState(machine,3,0,1); // tube1 level switch |
| 2357 | Scorpion2_SetSwitchState(machine,3,1,1); // tube2 level switch |
| 2358 | Scorpion2_SetSwitchState(machine,3,2,1); // tube3 level switch |
| 2304 | 2359 | |
| 2305 | | sc2_show_door = 1; |
| 2306 | | sc2_door_state = 0x41; |
| 2360 | state->sc2_show_door = 1; |
| 2361 | state->sc2_door_state = 0x41; |
| 2307 | 2362 | } |
| 2308 | 2363 | |
| 2309 | 2364 | // golden crown ////////////////////////////////////////////////////////// |
| 2310 | 2365 | |
| 2311 | 2366 | static DRIVER_INIT( gldncrwn ) |
| 2312 | 2367 | { |
| 2368 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 2313 | 2369 | sc2_common_init(machine, 1); |
| 2314 | 2370 | adder2_decode_char_roms(machine); // decode GFX roms |
| 2315 | 2371 | adder2_common_init(machine); |
| 2316 | 2372 | |
| 2317 | | has_hopper = 0; |
| 2373 | state->has_hopper = 0; |
| 2318 | 2374 | |
| 2319 | | Scorpion2_SetSwitchState(3,0,1); // tube1 level switch |
| 2320 | | Scorpion2_SetSwitchState(3,1,1); // tube2 level switch |
| 2321 | | Scorpion2_SetSwitchState(3,2,1); // tube3 level switch |
| 2375 | Scorpion2_SetSwitchState(machine,3,0,1); // tube1 level switch |
| 2376 | Scorpion2_SetSwitchState(machine,3,1,1); // tube2 level switch |
| 2377 | Scorpion2_SetSwitchState(machine,3,2,1); // tube3 level switch |
| 2322 | 2378 | |
| 2323 | | sc2_show_door = 0; |
| 2324 | | sc2_door_state = 0x41; |
| 2379 | state->sc2_show_door = 0; |
| 2380 | state->sc2_door_state = 0x41; |
| 2325 | 2381 | } |
| 2326 | 2382 | |
| 2327 | 2383 | // ROM definition UK Quintoon //////////////////////////////////////////// |
| r10427 | r10428 | |
| 2597 | 2653 | #include "awpvid14.lh" |
| 2598 | 2654 | #include "awpvid16.lh" |
| 2599 | 2655 | |
| 2656 | |
| 2600 | 2657 | /* Reels 1 and 2 */ |
| 2601 | 2658 | static WRITE8_HANDLER( reel12_w ) |
| 2602 | 2659 | { |
| 2603 | | reel12_latch = data; |
| 2660 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 2661 | state->reel12_latch = data; |
| 2604 | 2662 | |
| 2605 | | if ( stepper_update(0, data ) ) reel_changed |= 0x01; |
| 2606 | | if ( stepper_update(1, data>>4) ) reel_changed |= 0x02; |
| 2663 | if ( stepper_update(0, data ) ) state->reel_changed |= 0x01; |
| 2664 | if ( stepper_update(1, data>>4) ) state->reel_changed |= 0x02; |
| 2607 | 2665 | |
| 2608 | | if ( stepper_optic_state(0) ) optic_pattern |= 0x01; |
| 2609 | | else optic_pattern &= ~0x01; |
| 2610 | | if ( stepper_optic_state(1) ) optic_pattern |= 0x02; |
| 2611 | | else optic_pattern &= ~0x02; |
| 2666 | if ( stepper_optic_state(0) ) state->optic_pattern |= 0x01; |
| 2667 | else state->optic_pattern &= ~0x01; |
| 2668 | if ( stepper_optic_state(1) ) state->optic_pattern |= 0x02; |
| 2669 | else state->optic_pattern &= ~0x02; |
| 2612 | 2670 | |
| 2613 | 2671 | awp_draw_reel(0); |
| 2614 | 2672 | awp_draw_reel(1); |
| r10427 | r10428 | |
| 2618 | 2676 | /* VFD Status */ |
| 2619 | 2677 | static READ8_HANDLER( vfd_status_r ) |
| 2620 | 2678 | { |
| 2679 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 2621 | 2680 | /* b7 = NEC busy */ |
| 2622 | 2681 | /* b6 = alpha busy (also matrix board) */ |
| 2623 | 2682 | /* b5 - b0 = reel optics */ |
| 2624 | 2683 | |
| 2625 | | int result = optic_pattern; |
| 2684 | int result = state->optic_pattern; |
| 2626 | 2685 | |
| 2627 | 2686 | if ( !upd7759_busy_r(space->machine->device("upd")) ) result |= 0x80; |
| 2628 | 2687 | |
| r10427 | r10428 | |
| 2632 | 2691 | /* VFD Status and data */ |
| 2633 | 2692 | static READ8_HANDLER( vfd_status_dm01_r ) |
| 2634 | 2693 | { |
| 2694 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 2635 | 2695 | /* b7 = NEC busy */ |
| 2636 | 2696 | /* b6 = alpha busy (also matrix board) */ |
| 2637 | 2697 | /* b5 - b0 = reel optics */ |
| 2638 | 2698 | |
| 2639 | | int result = optic_pattern; |
| 2699 | int result = state->optic_pattern; |
| 2640 | 2700 | |
| 2641 | 2701 | if ( !upd7759_busy_r(space->machine->device("upd")) ) result |= 0x80; |
| 2642 | 2702 | |
| r10427 | r10428 | |
| 2648 | 2708 | |
| 2649 | 2709 | static WRITE8_HANDLER( vfd1_data_dm01_w ) |
| 2650 | 2710 | { |
| 2651 | | vfd1_latch = data; |
| 2711 | bfm_sc2_state *state = space->machine->driver_data<bfm_sc2_state>(); |
| 2712 | state->vfd1_latch = data; |
| 2652 | 2713 | BFM_dm01_writedata(space->machine,data); |
| 2653 | 2714 | } |
| 2654 | 2715 | |
| r10427 | r10428 | |
| 2701 | 2762 | static MACHINE_RESET( dm01_init ) |
| 2702 | 2763 | { |
| 2703 | 2764 | on_scorpion2_reset(machine); |
| 2704 | | BFM_dm01_reset(); |
| 2765 | BFM_dm01_reset(machine); |
| 2705 | 2766 | } |
| 2706 | 2767 | |
| 2707 | 2768 | |
| r10427 | r10428 | |
| 2755 | 2816 | |
| 2756 | 2817 | /* memory map for scorpion3 board */ |
| 2757 | 2818 | static ADDRESS_MAP_START( sc3_memmap, ADDRESS_SPACE_PROGRAM, 8 ) |
| 2758 | | AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram")//8k |
| 2819 | AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram") //8k |
| 2759 | 2820 | AM_RANGE(0x2000, 0x2000) AM_READ(vfd_status_r) |
| 2760 | 2821 | AM_RANGE(0x2000, 0x20FF) AM_WRITE(reel12_w) |
| 2761 | 2822 | AM_RANGE(0x2100, 0x21FF) AM_WRITE(reel34_w) |
| r10427 | r10428 | |
| 2804 | 2865 | |
| 2805 | 2866 | /* memory map for scorpion2 board + dm01 dot matrix board */ |
| 2806 | 2867 | static ADDRESS_MAP_START( memmap_sc2_dm01, ADDRESS_SPACE_PROGRAM, 8 ) |
| 2807 | | AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram")//8k |
| 2868 | AM_RANGE(0x0000, 0x1fff) AM_RAM AM_SHARE("nvram") //8k |
| 2808 | 2869 | AM_RANGE(0x2000, 0x2000) AM_READ(vfd_status_dm01_r) |
| 2809 | 2870 | AM_RANGE(0x2000, 0x20FF) AM_WRITE(reel12_w) |
| 2810 | 2871 | AM_RANGE(0x2100, 0x21FF) AM_WRITE(reel34_w) |
| r10427 | r10428 | |
| 3925 | 3986 | |
| 3926 | 3987 | /* machine driver for scorpion2 board */ |
| 3927 | 3988 | |
| 3928 | | static MACHINE_CONFIG_START( scorpion2, driver_device ) |
| 3989 | static MACHINE_CONFIG_START( scorpion2, bfm_sc2_state ) |
| 3929 | 3990 | MCFG_MACHINE_RESET(awp_init) |
| 3930 | 3991 | MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 ) |
| 3931 | 3992 | MCFG_CPU_PROGRAM_MAP(sc2_memmap) |
| r10427 | r10428 | |
| 3954 | 4015 | |
| 3955 | 4016 | |
| 3956 | 4017 | /* machine driver for scorpion2 board + matrix board */ |
| 3957 | | static MACHINE_CONFIG_START( scorpion2_dm01, driver_device ) |
| 4018 | static MACHINE_CONFIG_START( scorpion2_dm01, bfm_sc2_state ) |
| 3958 | 4019 | MCFG_MACHINE_RESET(dm01_init) |
| 3959 | 4020 | MCFG_QUANTUM_TIME(attotime::from_hz(960)) // needed for serial communication !! |
| 3960 | 4021 | MCFG_CPU_ADD("maincpu", M6809, MASTER_CLOCK/4 ) |
| r10427 | r10428 | |
| 3995 | 4056 | |
| 3996 | 4057 | static DRIVER_INIT (bbrkfst) |
| 3997 | 4058 | { |
| 4059 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 3998 | 4060 | sc2awp_common_init(machine,5, 1); |
| 3999 | 4061 | MechMtr_config(machine,8); |
| 4000 | 4062 | |
| 4001 | 4063 | BFM_BD1_init(0); |
| 4002 | 4064 | BFM_BD1_init(1); |
| 4003 | 4065 | |
| 4004 | | has_hopper = 0; |
| 4066 | state->has_hopper = 0; |
| 4005 | 4067 | |
| 4006 | | Scorpion2_SetSwitchState(4,0, 1); /* GBP1 Low Level Switch */ |
| 4007 | | Scorpion2_SetSwitchState(4,1, 1); /* 20p Low Level Switch */ |
| 4008 | | Scorpion2_SetSwitchState(4,2, 1); /* Token Front Low Level Switch */ |
| 4009 | | Scorpion2_SetSwitchState(4,3, 1); /* Token Rear Low Level Switch */ |
| 4010 | | Scorpion2_SetSwitchState(4,4, 1); |
| 4011 | | Scorpion2_SetSwitchState(6,0, 0); |
| 4012 | | Scorpion2_SetSwitchState(6,1, 1); |
| 4013 | | Scorpion2_SetSwitchState(6,2, 0); |
| 4014 | | Scorpion2_SetSwitchState(6,3, 1); |
| 4068 | Scorpion2_SetSwitchState(machine,4,0, 1); /* GBP1 Low Level Switch */ |
| 4069 | Scorpion2_SetSwitchState(machine,4,1, 1); /* 20p Low Level Switch */ |
| 4070 | Scorpion2_SetSwitchState(machine,4,2, 1); /* Token Front Low Level Switch */ |
| 4071 | Scorpion2_SetSwitchState(machine,4,3, 1); /* Token Rear Low Level Switch */ |
| 4072 | Scorpion2_SetSwitchState(machine,4,4, 1); |
| 4073 | Scorpion2_SetSwitchState(machine,6,0, 0); |
| 4074 | Scorpion2_SetSwitchState(machine,6,1, 1); |
| 4075 | Scorpion2_SetSwitchState(machine,6,2, 0); |
| 4076 | Scorpion2_SetSwitchState(machine,6,3, 1); |
| 4015 | 4077 | |
| 4016 | 4078 | } |
| 4017 | 4079 | |
| 4018 | 4080 | static DRIVER_INIT (drwho) |
| 4019 | 4081 | { |
| 4082 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 4020 | 4083 | sc2awp_common_init(machine,4, 1); |
| 4021 | 4084 | MechMtr_config(machine,8); |
| 4022 | 4085 | |
| 4023 | 4086 | BFM_BD1_init(0); |
| 4024 | 4087 | BFM_BD1_init(1); |
| 4025 | 4088 | |
| 4026 | | has_hopper = 0; |
| 4089 | state->has_hopper = 0; |
| 4027 | 4090 | |
| 4028 | | Scorpion2_SetSwitchState(4,0, 0); /* GBP1 Low Level Switch */ |
| 4029 | | Scorpion2_SetSwitchState(4,1, 0); /* 20p Low Level Switch */ |
| 4030 | | Scorpion2_SetSwitchState(4,2, 0); /* Token Front Low Level Switch */ |
| 4031 | | Scorpion2_SetSwitchState(4,3, 0); /* Token Rear Low Level Switch */ |
| 4032 | | Scorpion2_SetSwitchState(7,0, 0); /* GBP1 High Level Switch */ |
| 4033 | | Scorpion2_SetSwitchState(7,1, 0); /* 20P High Level Switch */ |
| 4034 | | Scorpion2_SetSwitchState(7,2, 0); /* Token Front High Level Switch */ |
| 4035 | | Scorpion2_SetSwitchState(7,3, 0); /* Token Rear High Level Switch */ |
| 4091 | Scorpion2_SetSwitchState(machine,4,0, 0); /* GBP1 Low Level Switch */ |
| 4092 | Scorpion2_SetSwitchState(machine,4,1, 0); /* 20p Low Level Switch */ |
| 4093 | Scorpion2_SetSwitchState(machine,4,2, 0); /* Token Front Low Level Switch */ |
| 4094 | Scorpion2_SetSwitchState(machine,4,3, 0); /* Token Rear Low Level Switch */ |
| 4095 | Scorpion2_SetSwitchState(machine,7,0, 0); /* GBP1 High Level Switch */ |
| 4096 | Scorpion2_SetSwitchState(machine,7,1, 0); /* 20P High Level Switch */ |
| 4097 | Scorpion2_SetSwitchState(machine,7,2, 0); /* Token Front High Level Switch */ |
| 4098 | Scorpion2_SetSwitchState(machine,7,3, 0); /* Token Rear High Level Switch */ |
| 4036 | 4099 | } |
| 4037 | 4100 | |
| 4038 | 4101 | static DRIVER_INIT (drwhon) |
| 4039 | 4102 | { |
| 4103 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 4040 | 4104 | sc2awp_common_init(machine,4, 0); |
| 4041 | 4105 | MechMtr_config(machine,8); |
| 4042 | 4106 | |
| 4043 | 4107 | BFM_BD1_init(0); |
| 4044 | 4108 | BFM_BD1_init(1); |
| 4045 | 4109 | |
| 4046 | | has_hopper = 0; |
| 4110 | state->has_hopper = 0; |
| 4047 | 4111 | |
| 4048 | | Scorpion2_SetSwitchState(4,0, 0); /* GBP1 Low Level Switch */ |
| 4049 | | Scorpion2_SetSwitchState(4,1, 0); /* 20p Low Level Switch */ |
| 4050 | | Scorpion2_SetSwitchState(4,2, 0); /* Token Front Low Level Switch */ |
| 4051 | | Scorpion2_SetSwitchState(4,3, 0); /* Token Rear Low Level Switch */ |
| 4052 | | Scorpion2_SetSwitchState(7,0, 0); /* GBP1 High Level Switch */ |
| 4053 | | Scorpion2_SetSwitchState(7,1, 0); /* 20P High Level Switch */ |
| 4054 | | Scorpion2_SetSwitchState(7,2, 0); /* Token Front High Level Switch */ |
| 4055 | | Scorpion2_SetSwitchState(7,3, 0); /* Token Rear High Level Switch */ |
| 4112 | Scorpion2_SetSwitchState(machine,4,0, 0); /* GBP1 Low Level Switch */ |
| 4113 | Scorpion2_SetSwitchState(machine,4,1, 0); /* 20p Low Level Switch */ |
| 4114 | Scorpion2_SetSwitchState(machine,4,2, 0); /* Token Front Low Level Switch */ |
| 4115 | Scorpion2_SetSwitchState(machine,4,3, 0); /* Token Rear Low Level Switch */ |
| 4116 | Scorpion2_SetSwitchState(machine,7,0, 0); /* GBP1 High Level Switch */ |
| 4117 | Scorpion2_SetSwitchState(machine,7,1, 0); /* 20P High Level Switch */ |
| 4118 | Scorpion2_SetSwitchState(machine,7,2, 0); /* Token Front High Level Switch */ |
| 4119 | Scorpion2_SetSwitchState(machine,7,3, 0); /* Token Rear High Level Switch */ |
| 4056 | 4120 | } |
| 4057 | 4121 | |
| 4058 | 4122 | |
| r10427 | r10428 | |
| 4066 | 4130 | |
| 4067 | 4131 | static DRIVER_INIT (cpeno1) |
| 4068 | 4132 | { |
| 4133 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 4069 | 4134 | sc2awp_common_init(machine,6, 1); |
| 4070 | 4135 | |
| 4071 | 4136 | MechMtr_config(machine,5); |
| 4072 | 4137 | |
| 4073 | | Scorpion2_SetSwitchState(3,3,1); /* 5p play */ |
| 4074 | | Scorpion2_SetSwitchState(3,4,1); /* 20p play */ |
| 4138 | Scorpion2_SetSwitchState(machine,3,3,1); /* 5p play */ |
| 4139 | Scorpion2_SetSwitchState(machine,3,4,1); /* 20p play */ |
| 4075 | 4140 | |
| 4076 | | Scorpion2_SetSwitchState(4,0,1); /* pay tube low (1 pound front) */ |
| 4077 | | Scorpion2_SetSwitchState(4,1,1); /* pay tube low (20p) */ |
| 4078 | | Scorpion2_SetSwitchState(4,2,1); /* pay tube low (?1 right) */ |
| 4079 | | Scorpion2_SetSwitchState(4,3,1); /* pay tube low (?1 left) */ |
| 4141 | Scorpion2_SetSwitchState(machine,4,0,1); /* pay tube low (1 pound front) */ |
| 4142 | Scorpion2_SetSwitchState(machine,4,1,1); /* pay tube low (20p) */ |
| 4143 | Scorpion2_SetSwitchState(machine,4,2,1); /* pay tube low (?1 right) */ |
| 4144 | Scorpion2_SetSwitchState(machine,4,3,1); /* pay tube low (?1 left) */ |
| 4080 | 4145 | |
| 4081 | | Scorpion2_SetSwitchState(5,0,1); /* pay sensor (GBP1 front) */ |
| 4082 | | Scorpion2_SetSwitchState(5,1,1); /* pay sensor (20 p) */ |
| 4083 | | Scorpion2_SetSwitchState(5,2,1); /* pay sensor (1 right) */ |
| 4084 | | Scorpion2_SetSwitchState(5,3,1); /* pay sensor (?1 left) */ |
| 4085 | | Scorpion2_SetSwitchState(5,4,1); /* payout unit present */ |
| 4146 | Scorpion2_SetSwitchState(machine,5,0,1); /* pay sensor (GBP1 front) */ |
| 4147 | Scorpion2_SetSwitchState(machine,5,1,1); /* pay sensor (20 p) */ |
| 4148 | Scorpion2_SetSwitchState(machine,5,2,1); /* pay sensor (1 right) */ |
| 4149 | Scorpion2_SetSwitchState(machine,5,3,1); /* pay sensor (?1 left) */ |
| 4150 | Scorpion2_SetSwitchState(machine,5,4,1); /* payout unit present */ |
| 4086 | 4151 | |
| 4087 | | slide_pay_sensor[0] = 0x50; |
| 4088 | | slide_pay_sensor[1] = 0x51; |
| 4089 | | slide_pay_sensor[2] = 0x52; |
| 4090 | | slide_pay_sensor[3] = 0x53; |
| 4091 | | slide_pay_sensor[4] = 0; |
| 4092 | | slide_pay_sensor[5] = 0; |
| 4152 | state->slide_pay_sensor[0] = 0x50; |
| 4153 | state->slide_pay_sensor[1] = 0x51; |
| 4154 | state->slide_pay_sensor[2] = 0x52; |
| 4155 | state->slide_pay_sensor[3] = 0x53; |
| 4156 | state->slide_pay_sensor[4] = 0; |
| 4157 | state->slide_pay_sensor[5] = 0; |
| 4093 | 4158 | |
| 4094 | | Scorpion2_SetSwitchState(6,0,1); /* ? percentage key */ |
| 4095 | | Scorpion2_SetSwitchState(6,1,1); |
| 4096 | | Scorpion2_SetSwitchState(6,2,1); |
| 4097 | | Scorpion2_SetSwitchState(6,3,1); |
| 4098 | | Scorpion2_SetSwitchState(6,4,1); |
| 4159 | Scorpion2_SetSwitchState(machine,6,0,1); /* ? percentage key */ |
| 4160 | Scorpion2_SetSwitchState(machine,6,1,1); |
| 4161 | Scorpion2_SetSwitchState(machine,6,2,1); |
| 4162 | Scorpion2_SetSwitchState(machine,6,3,1); |
| 4163 | Scorpion2_SetSwitchState(machine,6,4,1); |
| 4099 | 4164 | |
| 4100 | | Scorpion2_SetSwitchState(7,0,0); /* GBP1 High Level Switch */ |
| 4101 | | Scorpion2_SetSwitchState(7,1,0); /* 20P High Level Switch */ |
| 4102 | | Scorpion2_SetSwitchState(7,2,0); /* Token Front High Level Switch */ |
| 4103 | | Scorpion2_SetSwitchState(7,3,0); /* Token Rear High Level Switch */ |
| 4165 | Scorpion2_SetSwitchState(machine,7,0,0); /* GBP1 High Level Switch */ |
| 4166 | Scorpion2_SetSwitchState(machine,7,1,0); /* 20P High Level Switch */ |
| 4167 | Scorpion2_SetSwitchState(machine,7,2,0); /* Token Front High Level Switch */ |
| 4168 | Scorpion2_SetSwitchState(machine,7,3,0); /* Token Rear High Level Switch */ |
| 4104 | 4169 | |
| 4105 | | sc2_show_door = 1; |
| 4106 | | sc2_door_state = 0x31; |
| 4170 | state->sc2_show_door = 1; |
| 4171 | state->sc2_door_state = 0x31; |
| 4107 | 4172 | |
| 4108 | | has_hopper = 0; |
| 4173 | state->has_hopper = 0; |
| 4109 | 4174 | } |
| 4110 | 4175 | |
| 4111 | 4176 | static DRIVER_INIT (bfmcgslm) |
| 4112 | 4177 | { |
| 4178 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 4113 | 4179 | sc2awp_common_init(machine,6, 1); |
| 4114 | 4180 | MechMtr_config(machine,8); |
| 4115 | 4181 | BFM_BD1_init(0); |
| 4116 | | has_hopper = 0; |
| 4182 | state->has_hopper = 0; |
| 4117 | 4183 | } |
| 4118 | 4184 | |
| 4119 | 4185 | static DRIVER_INIT (luvjub) |
| 4120 | 4186 | { |
| 4187 | bfm_sc2_state *state = machine->driver_data<bfm_sc2_state>(); |
| 4121 | 4188 | sc2awp_common_init(machine,6, 1); |
| 4122 | 4189 | MechMtr_config(machine,8); |
| 4123 | | has_hopper = 0; |
| 4190 | state->has_hopper = 0; |
| 4124 | 4191 | |
| 4125 | | Scorpion2_SetSwitchState(3,0,1); |
| 4126 | | Scorpion2_SetSwitchState(3,1,1); |
| 4192 | Scorpion2_SetSwitchState(machine,3,0,1); |
| 4193 | Scorpion2_SetSwitchState(machine,3,1,1); |
| 4127 | 4194 | |
| 4128 | | Scorpion2_SetSwitchState(4,0,1); |
| 4129 | | Scorpion2_SetSwitchState(4,1,1); |
| 4130 | | Scorpion2_SetSwitchState(4,2,1); |
| 4131 | | Scorpion2_SetSwitchState(4,3,1); |
| 4195 | Scorpion2_SetSwitchState(machine,4,0,1); |
| 4196 | Scorpion2_SetSwitchState(machine,4,1,1); |
| 4197 | Scorpion2_SetSwitchState(machine,4,2,1); |
| 4198 | Scorpion2_SetSwitchState(machine,4,3,1); |
| 4132 | 4199 | |
| 4133 | | Scorpion2_SetSwitchState(6,0,1); |
| 4134 | | Scorpion2_SetSwitchState(6,1,1); |
| 4135 | | Scorpion2_SetSwitchState(6,2,1); |
| 4136 | | Scorpion2_SetSwitchState(6,3,0); |
| 4200 | Scorpion2_SetSwitchState(machine,6,0,1); |
| 4201 | Scorpion2_SetSwitchState(machine,6,1,1); |
| 4202 | Scorpion2_SetSwitchState(machine,6,2,1); |
| 4203 | Scorpion2_SetSwitchState(machine,6,3,0); |
| 4137 | 4204 | |
| 4138 | | Scorpion2_SetSwitchState(7,0,0); |
| 4139 | | Scorpion2_SetSwitchState(7,1,0); |
| 4140 | | Scorpion2_SetSwitchState(7,2,0); |
| 4141 | | Scorpion2_SetSwitchState(7,3,0); |
| 4205 | Scorpion2_SetSwitchState(machine,7,0,0); |
| 4206 | Scorpion2_SetSwitchState(machine,7,1,0); |
| 4207 | Scorpion2_SetSwitchState(machine,7,2,0); |
| 4208 | Scorpion2_SetSwitchState(machine,7,3,0); |
| 4142 | 4209 | } |
| 4143 | 4210 | |
| 4144 | 4211 | /********************************************* |
src/mame/drivers/sigmab98.c
| r10427 | r10428 | |
| 74 | 74 | to "coin" (it probably changes the number of reads from port $C0). |
| 75 | 75 | I guess the reset_delay mechanism should be implemented with a timer in eeprom.c. |
| 76 | 76 | |
| 77 | Notes: |
| 78 | |
| 79 | - "BACKUP RAM NG" error: in test mode, choose "SET MODE" -> "RAM CLEAR" and keep the button pressed for long. |
| 80 | |
| 77 | 81 | *************************************************************************************************************/ |
| 78 | 82 | |
| 79 | 83 | #include "emu.h" |
| 80 | 84 | #include "deprecat.h" |
| 81 | 85 | #include "cpu/z80/z80.h" |
| 86 | #include "sound/okim9810.h" |
| 82 | 87 | #include "sound/ymz280b.h" |
| 83 | 88 | #include "machine/eeprom.h" |
| 89 | #include "machine/nvram.h" |
| 84 | 90 | #include "machine/ticket.h" |
| 85 | | #include "machine/nvram.h" |
| 86 | 91 | |
| 87 | 92 | /*************************************************************************** |
| 88 | 93 | |
| r10427 | r10428 | |
| 102 | 107 | -6-- ---- 256 Color Sprite |
| 103 | 108 | --5- ---- |
| 104 | 109 | ---4 ---- Flip X |
| 105 | | ---- 3--- |
| 110 | ---- 3--- Flip Y |
| 106 | 111 | ---- -2-- Draw Sprite |
| 107 | 112 | ---- --10 Priority (0 = Front .. 3 = Back) |
| 108 | 113 | 2 Tile Code (High) |
| r10427 | r10428 | |
| 168 | 173 | dx = (dx & 0x1ff) - (dx & 0x200); |
| 169 | 174 | dy = (dy & 0x1ff) - (dy & 0x200); |
| 170 | 175 | |
| 171 | | // Add shift |
| 172 | | sx += dx; |
| 173 | | sy += dy; |
| 176 | // Add shift (negated, as it seems more correct in haekaka) |
| 177 | sx -= dx; |
| 178 | sy -= dy; |
| 174 | 179 | |
| 175 | 180 | // Use fixed point values (16.16), for accuracy |
| 176 | 181 | sx <<= 16; |
| r10427 | r10428 | |
| 185 | 190 | if (scale & 0xffff) scale += (1<<16) / 0x10; |
| 186 | 191 | |
| 187 | 192 | flipx = s[ 0x01 ] & 0x10; |
| 188 | | flipy = 0; // ? |
| 193 | flipy = s[ 0x01 ] & 0x08; |
| 189 | 194 | |
| 190 | 195 | if ( flipx ) { x0 = nx - 1; x1 = -1; dx = -1; } |
| 191 | 196 | else { x0 = 0; x1 = nx; dx = +1; } |
| r10427 | r10428 | |
| 340 | 345 | static void show_outputs() |
| 341 | 346 | { |
| 342 | 347 | #ifdef MAME_DEBUG |
| 343 | | popmessage("0: %02X 4: %02X 6: %02X 8: %02X",c0,c4,c6,c8); |
| 348 | // popmessage("0: %02X 4: %02X 6: %02X 8: %02X",c0,c4,c6,c8); |
| 344 | 349 | #endif |
| 345 | 350 | } |
| 346 | 351 | |
| r10427 | r10428 | |
| 593 | 598 | static void show_3_outputs() |
| 594 | 599 | { |
| 595 | 600 | #ifdef MAME_DEBUG |
| 596 | | popmessage("COIN: %02X LED: %02X HOP: %02X", out[0], out[1], out[2]); |
| 601 | // popmessage("COIN: %02X LED: %02X HOP: %02X", out[0], out[1], out[2]); |
| 597 | 602 | #endif |
| 598 | 603 | } |
| 599 | 604 | // Port 31 |
| r10427 | r10428 | |
| 603 | 608 | coin_counter_w(space->machine, 1, data & 0x02 ); // coin2 in |
| 604 | 609 | coin_counter_w(space->machine, 2, data & 0x04 ); // medal in |
| 605 | 610 | |
| 606 | | coin_lockout_w(space->machine, 1, (~data) & 0x08 ); // coin2 lockout? |
| 607 | | coin_lockout_w(space->machine, 0, (~data) & 0x10 ); // coin1 lockout |
| 608 | | coin_lockout_w(space->machine, 2, (~data) & 0x20 ); // medal lockout? |
| 611 | // coin_lockout_w(space->machine, 1, (~data) & 0x08 ); // coin2 lockout? |
| 612 | // coin_lockout_w(space->machine, 0, (~data) & 0x10 ); // coin1 lockout |
| 613 | // coin_lockout_w(space->machine, 2, (~data) & 0x20 ); // medal lockout? |
| 609 | 614 | |
| 610 | 615 | out[0] = data; |
| 611 | 616 | show_3_outputs(); |
| r10427 | r10428 | |
| 631 | 636 | show_3_outputs(); |
| 632 | 637 | } |
| 633 | 638 | |
| 634 | | static WRITE8_HANDLER( sammymdl_sound_w ) |
| 635 | | { |
| 636 | | } |
| 637 | | |
| 638 | 639 | static READ8_HANDLER( sammymdl_coin_hopper_r ) |
| 639 | 640 | { |
| 640 | 641 | UINT8 ret = input_port_read(space->machine, "COIN"); |
| r10427 | r10428 | |
| 645 | 646 | return ret; |
| 646 | 647 | } |
| 647 | 648 | |
| 649 | // Sound |
| 650 | static WRITE8_DEVICE_HANDLER( sammymdl_sound_w ) |
| 651 | { |
| 652 | if (offset) |
| 653 | downcast<okim9810_device *>(device)->write_TMP_register(data); |
| 654 | else |
| 655 | downcast<okim9810_device *>(device)->write_command(data); |
| 656 | } |
| 657 | static READ8_DEVICE_HANDLER( sammymdl_sound_r ) |
| 658 | { |
| 659 | // Needed for haekaka (Oki read status is not implemented yet) |
| 660 | return device->machine->rand(); |
| 661 | } |
| 662 | |
| 648 | 663 | static UINT8 *nvram; |
| 649 | 664 | static ADDRESS_MAP_START( animalc_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 650 | 665 | AM_RANGE( 0x0000, 0x3fff ) AM_ROM |
| r10427 | r10428 | |
| 656 | 671 | AM_RANGE( 0xb000, 0xbfff ) AM_RAMBANK("sprbank") |
| 657 | 672 | |
| 658 | 673 | AM_RANGE( 0xd000, 0xd1ff ) AM_RAM_WRITE( paletteram_xRRRRRGGGGGBBBBB_be_w ) AM_BASE_GENERIC( paletteram ) |
| 659 | | AM_RANGE( 0xd800, 0xd87f ) AM_RAM // ? |
| 674 | AM_RANGE( 0xd800, 0xd87f ) AM_RAM // table? |
| 660 | 675 | |
| 661 | 676 | AM_RANGE( 0xe011, 0xe011 ) AM_WRITENOP // IRQ Enable? Screen disable? |
| 662 | 677 | AM_RANGE( 0xe013, 0xe013 ) AM_READWRITE( vblank_r, vblank_w ) // IRQ Ack? |
| r10427 | r10428 | |
| 675 | 690 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 676 | 691 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w ) |
| 677 | 692 | AM_RANGE( 0x34, 0x34 ) AM_READ( unk_34_r ) |
| 678 | | AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w ) |
| 693 | AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w ) |
| 694 | AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r ) |
| 679 | 695 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 680 | 696 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 681 | 697 | ADDRESS_MAP_END |
| 682 | 698 | |
| 683 | 699 | /*************************************************************************** |
| 700 | Hae Hae Ka Ka Ka |
| 701 | ***************************************************************************/ |
| 702 | |
| 703 | // rombank |
| 704 | static WRITE8_HANDLER( haekaka_rombank_w ) |
| 705 | { |
| 706 | if (offset == 0) |
| 707 | { |
| 708 | reg = data; |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | switch ( reg ) |
| 713 | { |
| 714 | case 0x2b: |
| 715 | rombank = data; |
| 716 | switch (data) |
| 717 | { |
| 718 | case 0x10: // ROM |
| 719 | case 0x11: |
| 720 | case 0x12: |
| 721 | case 0x13: |
| 722 | case 0x14: |
| 723 | case 0x15: |
| 724 | case 0x16: |
| 725 | case 0x17: |
| 726 | case 0x18: |
| 727 | case 0x19: |
| 728 | case 0x1a: |
| 729 | case 0x1b: |
| 730 | case 0x1c: |
| 731 | case 0x1d: |
| 732 | case 0x1e: |
| 733 | case 0x1f: |
| 734 | |
| 735 | case 0x65: // SPRITERAM |
| 736 | case 0x67: // PALETTE RAM + TABLE + REGS |
| 737 | break; |
| 738 | |
| 739 | default: |
| 740 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 741 | } |
| 742 | break; |
| 743 | |
| 744 | default: |
| 745 | logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data); |
| 746 | } |
| 747 | } |
| 748 | static READ8_HANDLER( haekaka_rombank_r ) |
| 749 | { |
| 750 | if (offset == 0) |
| 751 | return reg; |
| 752 | |
| 753 | switch ( reg ) |
| 754 | { |
| 755 | case 0x2b: |
| 756 | return rombank; |
| 757 | |
| 758 | default: |
| 759 | logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg); |
| 760 | return 0x00; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | // rambank |
| 765 | static WRITE8_HANDLER( haekaka_rambank_w ) |
| 766 | { |
| 767 | if (offset == 0) |
| 768 | { |
| 769 | reg2 = data; |
| 770 | return; |
| 771 | } |
| 772 | |
| 773 | switch ( reg2 ) |
| 774 | { |
| 775 | case 0x33: |
| 776 | rambank = data; |
| 777 | switch (data) |
| 778 | { |
| 779 | case 0x53: |
| 780 | break; |
| 781 | |
| 782 | default: |
| 783 | logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2); |
| 784 | } |
| 785 | break; |
| 786 | |
| 787 | default: |
| 788 | logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data); |
| 789 | } |
| 790 | } |
| 791 | static READ8_HANDLER( haekaka_rambank_r ) |
| 792 | { |
| 793 | if (offset == 0) |
| 794 | return reg2; |
| 795 | |
| 796 | switch ( reg2 ) |
| 797 | { |
| 798 | case 0x33: |
| 799 | return rambank; |
| 800 | |
| 801 | default: |
| 802 | logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2); |
| 803 | return 0x00; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | static READ8_HANDLER( haekaka_vblank_r ) |
| 808 | { |
| 809 | return space->machine->primary_screen->vblank() ? 0 : 0x1c; |
| 810 | } |
| 811 | |
| 812 | static READ8_HANDLER( haekaka_b000_r ) |
| 813 | { |
| 814 | switch (rombank) |
| 815 | { |
| 816 | case 0x10: // ROM |
| 817 | case 0x11: |
| 818 | case 0x12: |
| 819 | case 0x13: |
| 820 | case 0x14: |
| 821 | case 0x15: |
| 822 | case 0x16: |
| 823 | case 0x17: |
| 824 | case 0x18: |
| 825 | case 0x19: |
| 826 | case 0x1a: |
| 827 | case 0x1b: |
| 828 | case 0x1c: |
| 829 | case 0x1d: |
| 830 | case 0x1e: |
| 831 | case 0x1f: |
| 832 | return space->machine->region("maincpu")->base()[offset + 0xb400 + 0x1000 * (rombank-0x10)]; |
| 833 | |
| 834 | case 0x65: // SPRITERAM |
| 835 | if (offset < 0x1000) |
| 836 | return space->machine->generic.spriteram.u8[offset]; |
| 837 | |
| 838 | case 0x67: // PALETTERAM + TABLE? + REGS |
| 839 | if (offset < 0x200) |
| 840 | return space->machine->generic.paletteram.u8[offset]; |
| 841 | else if (offset == (0xc013-0xb000)) |
| 842 | return haekaka_vblank_r(space, offset); |
| 843 | break; |
| 844 | } |
| 845 | |
| 846 | logerror("%s: unknown read from %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xb000, rombank); |
| 847 | return 0x00; |
| 848 | } |
| 849 | |
| 850 | static WRITE8_HANDLER( haekaka_b000_w ) |
| 851 | { |
| 852 | switch (rombank) |
| 853 | { |
| 854 | case 0x65: // SPRITERAM |
| 855 | if (offset < 0x1000) |
| 856 | { |
| 857 | space->machine->generic.spriteram.u8[offset] = data; |
| 858 | return; |
| 859 | } |
| 860 | break; |
| 861 | |
| 862 | case 0x67: // PALETTERAM + TABLE? + REGS |
| 863 | if (offset < 0x200) |
| 864 | { |
| 865 | paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data); |
| 866 | // space->machine->generic.paletteram.u8[offset] = data; |
| 867 | return; |
| 868 | } |
| 869 | else if ((offset >= 0x800) && (offset < 0x880)) |
| 870 | { |
| 871 | // table? |
| 872 | return; |
| 873 | } |
| 874 | break; |
| 875 | } |
| 876 | |
| 877 | logerror("%s: unknown write to %02x = %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xb000, data, rombank); |
| 878 | } |
| 879 | |
| 880 | static WRITE8_HANDLER( haekaka_leds_w ) |
| 881 | { |
| 882 | // All used |
| 883 | set_led_status(space->machine, 0, data & 0x01); |
| 884 | set_led_status(space->machine, 1, data & 0x02); |
| 885 | set_led_status(space->machine, 2, data & 0x04); |
| 886 | set_led_status(space->machine, 3, data & 0x08); |
| 887 | set_led_status(space->machine, 4, data & 0x10); |
| 888 | set_led_status(space->machine, 5, data & 0x20); |
| 889 | set_led_status(space->machine, 6, data & 0x40); |
| 890 | set_led_status(space->machine, 7, data & 0x80); |
| 891 | |
| 892 | out[1] = data; |
| 893 | show_3_outputs(); |
| 894 | } |
| 895 | |
| 896 | static WRITE8_HANDLER( haekaka_coin_w ) |
| 897 | { |
| 898 | coin_counter_w(space->machine, 0, data & 0x01 ); // medal out |
| 899 | // data & 0x02 ? |
| 900 | // data & 0x04 ? |
| 901 | // data & 0x10 ? |
| 902 | |
| 903 | out[0] = data; |
| 904 | show_3_outputs(); |
| 905 | } |
| 906 | |
| 907 | static ADDRESS_MAP_START( haekaka_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 908 | AM_RANGE( 0x0000, 0x7fff ) AM_ROM |
| 909 | AM_RANGE( 0xb000, 0xcfff ) AM_READWRITE( haekaka_b000_r, haekaka_b000_w ) |
| 910 | AM_RANGE( 0xd000, 0xefff ) AM_RAM AM_SHARE( "nvram" ) AM_BASE( &nvram ) |
| 911 | AM_RANGE( 0xfe00, 0xffff ) AM_RAM |
| 912 | ADDRESS_MAP_END |
| 913 | |
| 914 | static ADDRESS_MAP_START( haekaka_io, ADDRESS_SPACE_IO, 8 ) |
| 915 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 916 | AM_RANGE( 0x02, 0x03 ) AM_READWRITE( haekaka_rombank_r, haekaka_rombank_w ) |
| 917 | AM_RANGE( 0x04, 0x05 ) AM_READWRITE( haekaka_rambank_r, haekaka_rambank_w ) |
| 918 | |
| 919 | AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w ) |
| 920 | AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r ) |
| 921 | AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" ) |
| 922 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( haekaka_coin_w ) |
| 923 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( haekaka_leds_w ) |
| 924 | AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w ) |
| 925 | AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r ) |
| 926 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 927 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 928 | ADDRESS_MAP_END |
| 929 | |
| 930 | /*************************************************************************** |
| 684 | 931 | Itazura Monkey |
| 685 | 932 | ***************************************************************************/ |
| 686 | 933 | |
| r10427 | r10428 | |
| 892 | 1139 | AM_RANGE( 0x4800, 0x57ff ) AM_READ_BANK( "rombank1" ) AM_WRITE_BANK( "sprbank1" ) |
| 893 | 1140 | |
| 894 | 1141 | AM_RANGE( 0x5800, 0x59ff ) AM_READWRITE( itazuram_palette_r, itazuram_palette_w ) |
| 895 | | AM_RANGE( 0x6000, 0x607f ) AM_RAM // ? |
| 1142 | AM_RANGE( 0x6000, 0x607f ) AM_RAM // table? |
| 896 | 1143 | |
| 897 | 1144 | AM_RANGE( 0x6811, 0x6811 ) AM_WRITENOP // IRQ Enable? Screen disable? |
| 898 | 1145 | AM_RANGE( 0x6813, 0x6813 ) AM_WRITENOP // IRQ Ack? |
| r10427 | r10428 | |
| 911 | 1158 | AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" ) |
| 912 | 1159 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 913 | 1160 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w ) |
| 914 | | AM_RANGE( 0x90, 0x91 ) AM_WRITE( sammymdl_sound_w ) // sound |
| 1161 | AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w ) |
| 1162 | AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r ) |
| 915 | 1163 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 916 | 1164 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 917 | 1165 | ADDRESS_MAP_END |
| 918 | 1166 | |
| 919 | 1167 | /*************************************************************************** |
| 1168 | Pye-nage Taikai |
| 1169 | ***************************************************************************/ |
| 920 | 1170 | |
| 1171 | static ADDRESS_MAP_START( pyenaget_io, ADDRESS_SPACE_IO, 8 ) |
| 1172 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 1173 | AM_IMPORT_FROM( haekaka_io ) |
| 1174 | ADDRESS_MAP_END |
| 1175 | |
| 1176 | /*************************************************************************** |
| 1177 | Taihou de Doboon |
| 1178 | ***************************************************************************/ |
| 1179 | |
| 1180 | // rombank |
| 1181 | static WRITE8_HANDLER( tdoboon_rombank_w ) |
| 1182 | { |
| 1183 | if (offset == 0) |
| 1184 | { |
| 1185 | reg = data; |
| 1186 | return; |
| 1187 | } |
| 1188 | |
| 1189 | switch ( reg ) |
| 1190 | { |
| 1191 | case 0x2f: |
| 1192 | rombank = data; |
| 1193 | switch (data) |
| 1194 | { |
| 1195 | case 0x10: // ROM |
| 1196 | case 0x11: |
| 1197 | case 0x12: |
| 1198 | case 0x13: |
| 1199 | case 0x14: |
| 1200 | case 0x15: |
| 1201 | case 0x16: |
| 1202 | case 0x17: |
| 1203 | case 0x18: |
| 1204 | case 0x19: |
| 1205 | case 0x1a: |
| 1206 | case 0x1b: |
| 1207 | case 0x1c: |
| 1208 | case 0x1d: |
| 1209 | case 0x1e: |
| 1210 | case 0x1f: |
| 1211 | |
| 1212 | case 0x64: // SPRITERAM |
| 1213 | case 0x66: // PALETTE RAM + TABLE |
| 1214 | case 0x67: // REGS |
| 1215 | break; |
| 1216 | |
| 1217 | default: |
| 1218 | logerror("%s: unknown rom bank = %02x, reg = %02x\n", space->machine->describe_context(), data, reg); |
| 1219 | } |
| 1220 | break; |
| 1221 | |
| 1222 | default: |
| 1223 | logerror("%s: unknown reg written: %02x = %02x\n", space->machine->describe_context(), reg, data); |
| 1224 | } |
| 1225 | } |
| 1226 | static READ8_HANDLER( tdoboon_rombank_r ) |
| 1227 | { |
| 1228 | if (offset == 0) |
| 1229 | return reg; |
| 1230 | |
| 1231 | switch ( reg ) |
| 1232 | { |
| 1233 | case 0x2f: |
| 1234 | return rombank; |
| 1235 | |
| 1236 | default: |
| 1237 | logerror("%s: unknown reg read: %02x\n", space->machine->describe_context(), reg); |
| 1238 | return 0x00; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | // rambank |
| 1243 | static WRITE8_HANDLER( tdoboon_rambank_w ) |
| 1244 | { |
| 1245 | if (offset == 0) |
| 1246 | { |
| 1247 | reg2 = data; |
| 1248 | return; |
| 1249 | } |
| 1250 | |
| 1251 | switch ( reg2 ) |
| 1252 | { |
| 1253 | case 0x33: |
| 1254 | rambank = data; |
| 1255 | switch (data) |
| 1256 | { |
| 1257 | case 0x53: |
| 1258 | break; |
| 1259 | |
| 1260 | default: |
| 1261 | logerror("%s: unknown ram bank = %02x, reg2 = %02x\n", space->machine->describe_context(), data, reg2); |
| 1262 | } |
| 1263 | break; |
| 1264 | |
| 1265 | default: |
| 1266 | logerror("%s: unknown reg2 written: %02x = %02x\n", space->machine->describe_context(), reg2, data); |
| 1267 | } |
| 1268 | } |
| 1269 | static READ8_HANDLER( tdoboon_rambank_r ) |
| 1270 | { |
| 1271 | if (offset == 0) |
| 1272 | return reg2; |
| 1273 | |
| 1274 | switch ( reg2 ) |
| 1275 | { |
| 1276 | case 0x33: |
| 1277 | return rambank; |
| 1278 | |
| 1279 | default: |
| 1280 | logerror("%s: unknown reg2 read: %02x\n", space->machine->describe_context(), reg2); |
| 1281 | return 0x00; |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | static READ8_HANDLER( tdoboon_c000_r ) |
| 1286 | { |
| 1287 | switch (rombank) |
| 1288 | { |
| 1289 | case 0x10: // ROM |
| 1290 | case 0x11: |
| 1291 | case 0x12: |
| 1292 | case 0x13: |
| 1293 | case 0x14: |
| 1294 | case 0x15: |
| 1295 | case 0x16: |
| 1296 | case 0x17: |
| 1297 | case 0x18: |
| 1298 | case 0x19: |
| 1299 | case 0x1a: |
| 1300 | case 0x1b: |
| 1301 | case 0x1c: |
| 1302 | case 0x1d: |
| 1303 | case 0x1e: |
| 1304 | case 0x1f: |
| 1305 | return space->machine->region("maincpu")->base()[offset + 0xc400 + 0x1000 * (rombank-0x10)]; |
| 1306 | |
| 1307 | case 0x64: // SPRITERAM |
| 1308 | if (offset < 0x1000) |
| 1309 | return space->machine->generic.spriteram.u8[offset]; |
| 1310 | break; |
| 1311 | |
| 1312 | case 0x66: // PALETTERAM + TABLE? |
| 1313 | if (offset < 0x200) |
| 1314 | return space->machine->generic.paletteram.u8[offset]; |
| 1315 | break; |
| 1316 | |
| 1317 | case 0x67: // REGS |
| 1318 | if (offset == (0xc013-0xc000)) |
| 1319 | return haekaka_vblank_r(space, offset); |
| 1320 | break; |
| 1321 | } |
| 1322 | |
| 1323 | logerror("%s: unknown read from %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xc000, rombank); |
| 1324 | return 0x00; |
| 1325 | } |
| 1326 | |
| 1327 | static WRITE8_HANDLER( tdoboon_c000_w ) |
| 1328 | { |
| 1329 | switch (rombank) |
| 1330 | { |
| 1331 | case 0x64: // SPRITERAM |
| 1332 | if (offset < 0x1000) |
| 1333 | { |
| 1334 | space->machine->generic.spriteram.u8[offset] = data; |
| 1335 | return; |
| 1336 | } |
| 1337 | break; |
| 1338 | |
| 1339 | case 0x66: // PALETTERAM + TABLE? |
| 1340 | if (offset < 0x200) |
| 1341 | { |
| 1342 | paletteram_xRRRRRGGGGGBBBBB_be_w(space, offset, data); |
| 1343 | // space->machine->generic.paletteram.u8[offset] = data; |
| 1344 | return; |
| 1345 | } |
| 1346 | else if ((offset >= 0x800) && (offset < 0x880)) |
| 1347 | { |
| 1348 | // table? |
| 1349 | return; |
| 1350 | } |
| 1351 | break; |
| 1352 | } |
| 1353 | |
| 1354 | logerror("%s: unknown write to %02x = %02x with rombank = %02x\n", space->machine->describe_context(), offset+0xc000, data, rombank); |
| 1355 | } |
| 1356 | |
| 1357 | static ADDRESS_MAP_START( tdoboon_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 1358 | AM_RANGE( 0x0000, 0xbfff ) AM_ROM |
| 1359 | AM_RANGE( 0xc000, 0xcfff ) AM_READWRITE( tdoboon_c000_r, tdoboon_c000_w ) |
| 1360 | AM_RANGE( 0xd000, 0xefff ) AM_RAM AM_SHARE( "nvram" ) AM_BASE( &nvram ) |
| 1361 | AM_RANGE( 0xfe00, 0xffff ) AM_RAM |
| 1362 | ADDRESS_MAP_END |
| 1363 | |
| 1364 | static ADDRESS_MAP_START( tdoboon_io, ADDRESS_SPACE_IO, 8 ) |
| 1365 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 1366 | AM_RANGE( 0x02, 0x03 ) AM_READWRITE( tdoboon_rombank_r, tdoboon_rombank_w ) |
| 1367 | AM_RANGE( 0x04, 0x05 ) AM_READWRITE( tdoboon_rambank_r, tdoboon_rambank_w ) |
| 1368 | |
| 1369 | AM_RANGE( 0x2c, 0x2c ) AM_DEVREADWRITE( "eeprom", sammymdl_eeprom_r, sammymdl_eeprom_w ) |
| 1370 | AM_RANGE( 0x2e, 0x2e ) AM_READ( sammymdl_coin_hopper_r ) |
| 1371 | AM_RANGE( 0x30, 0x30 ) AM_READ_PORT( "BUTTON" ) |
| 1372 | AM_RANGE( 0x31, 0x31 ) AM_WRITE( sammymdl_coin_w ) |
| 1373 | AM_RANGE( 0x32, 0x32 ) AM_WRITE( sammymdl_leds_w ) |
| 1374 | AM_RANGE( 0x90, 0x91 ) AM_DEVWRITE("oki", sammymdl_sound_w ) |
| 1375 | AM_RANGE( 0x92, 0x92 ) AM_DEVWRITE("oki", sammymdl_sound_r ) |
| 1376 | AM_RANGE( 0xb0, 0xb0 ) AM_WRITE( sammymdl_hopper_w ) |
| 1377 | AM_RANGE( 0xc0, 0xc0 ) AM_WRITE( watchdog_reset_w ) // 1 |
| 1378 | ADDRESS_MAP_END |
| 1379 | |
| 1380 | |
| 1381 | /*************************************************************************** |
| 1382 | |
| 921 | 1383 | Graphics Layout |
| 922 | 1384 | |
| 923 | 1385 | ***************************************************************************/ |
| r10427 | r10428 | |
| 974 | 1436 | |
| 975 | 1437 | PORT_START("IN1") |
| 976 | 1438 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(5) // ? (coin error, pulses mask 4 of port c6) |
| 977 | | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(5) // coin/medal in (coin error) |
| 1439 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(5) PORT_NAME("Medal") // coin/medal in (coin error) |
| 978 | 1440 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r) |
| 979 | 1441 | PORT_SERVICE( 0x08, IP_ACTIVE_LOW ) |
| 980 | 1442 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("Bet") // bet / select in test menu |
| r10427 | r10428 | |
| 1012 | 1474 | PORT_START("COIN") |
| 1013 | 1475 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(5) // coin1 in |
| 1014 | 1476 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) PORT_IMPULSE(5) // coin2 in |
| 1015 | | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_IMPULSE(5) // medal in |
| 1477 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 ) PORT_IMPULSE(5) PORT_NAME("Medal") // medal in |
| 1016 | 1478 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE ) // test sw |
| 1017 | 1479 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1018 | 1480 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r) |
| r10427 | r10428 | |
| 1020 | 1482 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1021 | 1483 | INPUT_PORTS_END |
| 1022 | 1484 | |
| 1485 | static INPUT_PORTS_START( haekaka ) |
| 1486 | PORT_START("BUTTON") |
| 1487 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) PORT_IMPULSE(5) PORT_NAME( "Medal" ) // medal in ("chacker") |
| 1488 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1489 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1490 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1491 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1492 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1493 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1494 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1023 | 1495 | |
| 1496 | PORT_START("COIN") |
| 1497 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1498 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1499 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1500 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE ) // test sw |
| 1501 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) // button |
| 1502 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_SPECIAL ) PORT_READ_LINE_DEVICE("hopper", ticket_dispenser_line_r) |
| 1503 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE1 ) // service coin / set in test mode |
| 1504 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 1505 | INPUT_PORTS_END |
| 1506 | |
| 1507 | |
| 1024 | 1508 | /*************************************************************************** |
| 1025 | 1509 | |
| 1026 | 1510 | Machine Drivers |
| r10427 | r10428 | |
| 1081 | 1565 | MACHINE_CONFIG_END |
| 1082 | 1566 | |
| 1083 | 1567 | /*************************************************************************** |
| 1084 | | Animal Catch |
| 1568 | Sammy Medal Games |
| 1085 | 1569 | ***************************************************************************/ |
| 1086 | 1570 | |
| 1087 | 1571 | static const eeprom_interface eeprom_interface_93C46_8bit = |
| r10427 | r10428 | |
| 1104 | 1588 | cpu_set_reg(machine->device("maincpu"), Z80_PC, 0x400); // code starts at 400 ??? (000 = cart header) |
| 1105 | 1589 | } |
| 1106 | 1590 | |
| 1591 | // Everything here is a guess: |
| 1592 | static MACHINE_CONFIG_START( sammymdl, driver_device ) |
| 1593 | MCFG_CPU_ADD("maincpu", Z80, 8000000) // ??? |
| 1594 | |
| 1595 | MCFG_MACHINE_RESET( sammymdl ) |
| 1596 | |
| 1597 | MCFG_NVRAM_ADD_0FILL("nvram") // battery |
| 1598 | MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) |
| 1599 | |
| 1600 | MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW ) |
| 1601 | |
| 1602 | // video hardware |
| 1603 | MCFG_SCREEN_ADD("screen", RASTER) |
| 1604 | MCFG_SCREEN_REFRESH_RATE(60) |
| 1605 | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1606 | MCFG_SCREEN_SIZE(0x140, 0x100) |
| 1607 | MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1) |
| 1608 | |
| 1609 | MCFG_GFXDECODE(sigmab98) |
| 1610 | MCFG_PALETTE_LENGTH(0x100) |
| 1611 | |
| 1612 | MCFG_VIDEO_UPDATE(sigmab98) |
| 1613 | MCFG_VIDEO_EOF(sammymdl) |
| 1614 | |
| 1615 | // sound hardware |
| 1616 | MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 1617 | |
| 1618 | MCFG_OKIM9810_ADD("oki", 16000) // OKI MSM981x? Clock? |
| 1619 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.80) |
| 1620 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.80) |
| 1621 | MACHINE_CONFIG_END |
| 1622 | |
| 1623 | |
| 1624 | /*************************************************************************** |
| 1625 | Animal Catch |
| 1626 | ***************************************************************************/ |
| 1627 | |
| 1107 | 1628 | static INTERRUPT_GEN( animalc ) |
| 1108 | 1629 | { |
| 1109 | 1630 | switch (cpu_getiloops(device)) |
| r10427 | r10428 | |
| 1122 | 1643 | } |
| 1123 | 1644 | } |
| 1124 | 1645 | |
| 1125 | | // Everything here is a guess: |
| 1126 | | static MACHINE_CONFIG_START( animalc, driver_device ) |
| 1127 | | MCFG_CPU_ADD("maincpu", Z80, 8000000) // ??? |
| 1646 | static MACHINE_CONFIG_DERIVED( animalc, sammymdl ) |
| 1647 | MCFG_CPU_MODIFY("maincpu") |
| 1128 | 1648 | MCFG_CPU_PROGRAM_MAP( animalc_map ) |
| 1129 | 1649 | MCFG_CPU_IO_MAP( animalc_io ) |
| 1130 | 1650 | MCFG_CPU_VBLANK_INT_HACK(animalc, 3) // IM 2 needs a vector on the data bus |
| 1651 | MACHINE_CONFIG_END |
| 1131 | 1652 | |
| 1132 | | MCFG_MACHINE_RESET( sammymdl ) |
| 1653 | /*************************************************************************** |
| 1654 | Hae Hae Ka Ka Ka |
| 1655 | ***************************************************************************/ |
| 1133 | 1656 | |
| 1134 | | MCFG_NVRAM_ADD_0FILL("nvram") // battery |
| 1135 | | MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) |
| 1657 | static INTERRUPT_GEN( haekaka ) |
| 1658 | { |
| 1659 | switch (cpu_getiloops(device)) |
| 1660 | { |
| 1661 | case 0: |
| 1662 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x04); |
| 1663 | break; |
| 1136 | 1664 | |
| 1137 | | MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW ) |
| 1665 | case 1: |
| 1666 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1a); |
| 1667 | break; |
| 1138 | 1668 | |
| 1139 | | // video hardware |
| 1140 | | MCFG_SCREEN_ADD("screen", RASTER) |
| 1141 | | MCFG_SCREEN_REFRESH_RATE(60) |
| 1142 | | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1143 | | MCFG_SCREEN_SIZE(0x140, 0x100) |
| 1144 | | MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1) |
| 1669 | case 2: |
| 1670 | cpu_set_input_line_and_vector(device, 0, HOLD_LINE, 0x1c); |
| 1671 | break; |
| 1672 | } |
| 1673 | } |
| 1145 | 1674 | |
| 1146 | | MCFG_GFXDECODE(sigmab98) |
| 1147 | | MCFG_PALETTE_LENGTH(0x100) |
| 1148 | | |
| 1149 | | MCFG_VIDEO_UPDATE(sigmab98) |
| 1150 | | MCFG_VIDEO_EOF(sammymdl) |
| 1151 | | |
| 1152 | | // sound hardware |
| 1153 | | // OKI MSM981x ? |
| 1675 | static MACHINE_CONFIG_DERIVED( haekaka, sammymdl ) |
| 1676 | MCFG_CPU_MODIFY("maincpu") |
| 1677 | MCFG_CPU_PROGRAM_MAP( haekaka_map ) |
| 1678 | MCFG_CPU_IO_MAP( haekaka_io ) |
| 1679 | MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus |
| 1154 | 1680 | MACHINE_CONFIG_END |
| 1155 | 1681 | |
| 1156 | 1682 | /*************************************************************************** |
| r10427 | r10428 | |
| 1175 | 1701 | } |
| 1176 | 1702 | } |
| 1177 | 1703 | |
| 1178 | | // Everything here is a guess: |
| 1179 | | static MACHINE_CONFIG_START( itazuram, driver_device ) |
| 1180 | | MCFG_CPU_ADD("maincpu", Z80, 8000000) // ??? |
| 1704 | static MACHINE_CONFIG_DERIVED( itazuram, sammymdl ) |
| 1705 | MCFG_CPU_MODIFY("maincpu") |
| 1181 | 1706 | MCFG_CPU_PROGRAM_MAP( itazuram_map ) |
| 1182 | 1707 | MCFG_CPU_IO_MAP( itazuram_io ) |
| 1183 | 1708 | MCFG_CPU_VBLANK_INT_HACK(itazuram, 3) // IM 2 needs a vector on the data bus |
| 1709 | MACHINE_CONFIG_END |
| 1184 | 1710 | |
| 1185 | | MCFG_MACHINE_RESET( sammymdl ) |
| 1711 | /*************************************************************************** |
| 1712 | Pye-nage Taikai |
| 1713 | ***************************************************************************/ |
| 1186 | 1714 | |
| 1187 | | MCFG_NVRAM_ADD_0FILL("nvram") // battery |
| 1188 | | MCFG_EEPROM_ADD("eeprom", eeprom_interface_93C46_8bit) |
| 1715 | static MACHINE_CONFIG_DERIVED( pyenaget, sammymdl ) |
| 1716 | MCFG_CPU_MODIFY("maincpu") |
| 1717 | MCFG_CPU_PROGRAM_MAP( haekaka_map ) |
| 1718 | MCFG_CPU_IO_MAP( pyenaget_io ) |
| 1719 | MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus |
| 1720 | MACHINE_CONFIG_END |
| 1189 | 1721 | |
| 1190 | | MCFG_TICKET_DISPENSER_ADD("hopper", 200, TICKET_MOTOR_ACTIVE_LOW, TICKET_STATUS_ACTIVE_LOW ) |
| 1722 | /*************************************************************************** |
| 1723 | Taihou de Doboon |
| 1724 | ***************************************************************************/ |
| 1191 | 1725 | |
| 1192 | | // video hardware |
| 1193 | | MCFG_SCREEN_ADD("screen", RASTER) |
| 1194 | | MCFG_SCREEN_REFRESH_RATE(60) |
| 1195 | | MCFG_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 1196 | | MCFG_SCREEN_SIZE(0x140, 0x100) |
| 1197 | | MCFG_SCREEN_VISIBLE_AREA(0, 0x140-1, 0, 0xf0-1) |
| 1726 | static MACHINE_CONFIG_DERIVED( tdoboon, sammymdl ) |
| 1727 | MCFG_CPU_MODIFY("maincpu") |
| 1728 | MCFG_CPU_PROGRAM_MAP( tdoboon_map ) |
| 1729 | MCFG_CPU_IO_MAP( tdoboon_io ) |
| 1730 | MCFG_CPU_VBLANK_INT_HACK(haekaka, 3) // IM 2 needs a vector on the data bus |
| 1198 | 1731 | |
| 1199 | | MCFG_GFXDECODE(sigmab98) |
| 1200 | | MCFG_PALETTE_LENGTH(0x100) |
| 1201 | | |
| 1202 | | MCFG_VIDEO_UPDATE(sigmab98) |
| 1203 | | // MCFG_VIDEO_EOF(sammymdl) |
| 1204 | | |
| 1205 | | // sound hardware |
| 1206 | | // OKI MSM981x ? |
| 1732 | MCFG_SCREEN_MODIFY("screen") |
| 1733 | MCFG_SCREEN_VISIBLE_AREA(0,0x140-1, 0+4,0xf0+4-1) |
| 1207 | 1734 | MACHINE_CONFIG_END |
| 1208 | 1735 | |
| 1209 | 1736 | |
| r10427 | r10428 | |
| 1298 | 1825 | ***************************************************************************/ |
| 1299 | 1826 | |
| 1300 | 1827 | ROM_START( animalc ) |
| 1301 | | ROM_REGION( 0x200000, "samples", 0 ) |
| 1828 | ROM_REGION( 0x1000000, "oki", 0 ) |
| 1302 | 1829 | ROM_LOAD( "vx2302l01.u021", 0x00000, 0x200000, CRC(84cf123b) SHA1(d8b425c93ff1a560e3f92c70d7eb93a05c3581af) ) |
| 1303 | 1830 | |
| 1304 | 1831 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1305 | | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1832 | ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 ) |
| 1306 | 1833 | |
| 1307 | 1834 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1308 | 1835 | ROM_LOAD( "vx2301l01.u016", 0x00000, 0x200000, CRC(4ae14ff9) SHA1(1273d15ea642452fecacff572655cd3ab47a5884) ) // 1xxxxxxxxxxxxxxxxxxxx = 0x00 |
| r10427 | r10428 | |
| 1333 | 1860 | ***************************************************************************/ |
| 1334 | 1861 | |
| 1335 | 1862 | ROM_START( itazuram ) |
| 1336 | | ROM_REGION( 0x200000, "samples", 0 ) |
| 1863 | ROM_REGION( 0x1000000, "oki", 0 ) |
| 1337 | 1864 | ROM_LOAD( "vx2002l01.u021", 0x00000, 0x200000, CRC(ddbdd2f3) SHA1(91f67a938929be0261442e066e3d2c03b5e9f06a) ) |
| 1338 | 1865 | |
| 1339 | 1866 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1340 | | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1867 | ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 ) |
| 1341 | 1868 | |
| 1342 | 1869 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1343 | 1870 | ROM_LOAD( "vx2001l01.u016", 0x00000, 0x200000, CRC(9ee95222) SHA1(7154d43ef312a48a882207ca37e1c61e8b215a9b) ) |
| r10427 | r10428 | |
| 1388 | 1915 | ***************************************************************************/ |
| 1389 | 1916 | |
| 1390 | 1917 | ROM_START( tdoboon ) |
| 1391 | | ROM_REGION( 0x200000, "samples", 0 ) |
| 1918 | ROM_REGION( 0x1000000, "oki", 0 ) |
| 1392 | 1919 | ROM_LOAD( "em4210l01.u021.bin", 0x00000, 0x200000, CRC(3523e314) SHA1(d07c5d17d3f285be4cde810547f427e84f98968f) ) |
| 1393 | 1920 | |
| 1394 | 1921 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1395 | | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1922 | ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 ) |
| 1396 | 1923 | |
| 1397 | 1924 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1398 | 1925 | ROM_LOAD( "em4209l01.u016.bin", 0x00000, 0x200000, CRC(aca220fa) SHA1(7db441add16af554700e597fd9926b6ccd19d628) ) // 1xxxxxxxxxxxxxxxxxxxx = 0xFF |
| r10427 | r10428 | |
| 1408 | 1935 | ***************************************************************************/ |
| 1409 | 1936 | |
| 1410 | 1937 | ROM_START( pyenaget ) |
| 1411 | | ROM_REGION( 0x200000, "samples", 0 ) |
| 1938 | ROM_REGION( 0x1000000, "oki", 0 ) |
| 1412 | 1939 | ROM_LOAD( "vx1802l01.u021", 0x00000, 0x200000, CRC(7a22a657) SHA1(2a98085862fd958209253c5401e41eae4f7c06ea) ) |
| 1413 | 1940 | |
| 1414 | 1941 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1415 | | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1942 | ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 ) |
| 1416 | 1943 | |
| 1417 | 1944 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1418 | 1945 | ROM_LOAD( "vx1801l01.u016", 0x00000, 0x200000, CRC(c4607403) SHA1(f4f4699442afccc5ed4354447f91b1bee36ae3e5) ) |
| r10427 | r10428 | |
| 1442 | 1969 | ***************************************************************************/ |
| 1443 | 1970 | |
| 1444 | 1971 | ROM_START( haekaka ) |
| 1445 | | ROM_REGION( 0x200000, "samples", 0 ) |
| 1972 | ROM_REGION( 0x1000000, "oki", 0 ) |
| 1446 | 1973 | ROM_LOAD( "em4208l01.u021.bin", 0x00000, 0x200000, CRC(d23bb748) SHA1(38d5b6c4b2cd470b3a68574aeca3f9fa9032245e) ) |
| 1447 | 1974 | |
| 1448 | 1975 | ROM_REGION( 0x40000, "maincpu", 0 ) |
| 1449 | | ROM_COPY( "samples", 0x1c0000, 0x00000, 0x40000 ) |
| 1976 | ROM_COPY( "oki", 0x1c0000, 0x00000, 0x40000 ) |
| 1450 | 1977 | |
| 1451 | 1978 | ROM_REGION( 0x200000, "sprites", 0 ) |
| 1452 | 1979 | ROM_LOAD( "em4207l01.u016.bin", 0x00000, 0x200000, CRC(3876961c) SHA1(3d842c1f63ea5aa7e799967928b86c5fabb4e65e) ) |
| 1453 | 1980 | ROM_END |
| 1454 | 1981 | |
| 1982 | static DRIVER_INIT( haekaka ) |
| 1983 | { |
| 1984 | // RAM banks |
| 1985 | machine->generic.paletteram.u8 = auto_alloc_array(machine, UINT8, 0x200); |
| 1986 | memset(machine->generic.paletteram.u8, 0, 0x200); |
| 1987 | |
| 1988 | machine->generic.spriteram.u8 = auto_alloc_array(machine, UINT8, 0x1000); |
| 1989 | memset(machine->generic.spriteram.u8, 0, 0x1000); |
| 1990 | machine->generic.spriteram_size = 0x1000; |
| 1991 | |
| 1992 | rombank = 0x65; |
| 1993 | rambank = 0x53; |
| 1994 | } |
| 1995 | |
| 1996 | |
| 1455 | 1997 | /*************************************************************************** |
| 1456 | 1998 | |
| 1457 | 1999 | Game Drivers |
| 1458 | 2000 | |
| 1459 | 2001 | ***************************************************************************/ |
| 1460 | 2002 | |
| 1461 | | GAME( 1997, gegege, 0, gegege, gegege, gegege, ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0 ) |
| 2003 | GAME( 1997, gegege, 0, gegege, gegege, gegege, ROT0, "Banpresto / Sigma", "GeGeGe no Kitarou Youkai Slot", 0 ) |
| 1462 | 2004 | // Sammy Medal Games: |
| 1463 | | GAME( 2000, animalc, 0, animalc, sammymdl, animalc, ROT0, "Sammy", "Animal Catch", GAME_NO_SOUND ) |
| 1464 | | GAME( 2000, itazuram, 0, itazuram, sammymdl, itazuram, ROT0, "Sammy", "Itazura Monkey", GAME_NO_SOUND ) |
| 1465 | | GAME( 2000, pyenaget, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Pye-nage Taikai", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 1466 | | GAME( 2002, haekaka, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Hae Hae Ka Ka Ka", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 1467 | | GAME( 2002, tdoboon, 0, animalc, sammymdl, 0, ROT0, "Sammy", "Taihou de Doboon", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 2005 | GAME( 2000, animalc, 0, animalc, sammymdl, animalc, ROT0, "Sammy", "Animal Catch", GAME_IMPERFECT_SOUND ) |
| 2006 | GAME( 2000, itazuram, 0, itazuram, sammymdl, itazuram, ROT0, "Sammy", "Itazura Monkey", GAME_IMPERFECT_SOUND ) |
| 2007 | GAME( 2000, pyenaget, 0, pyenaget, sammymdl, haekaka, ROT0, "Sammy", "Pye-nage Taikai", GAME_IMPERFECT_SOUND ) |
| 2008 | GAME( 2000, tdoboon, 0, tdoboon, haekaka, haekaka, ROT0, "Sammy", "Taihou de Doboon", GAME_IMPERFECT_SOUND ) |
| 2009 | GAME( 2001, haekaka, 0, haekaka, haekaka, haekaka, ROT0, "Sammy", "Hae Hae Ka Ka Ka", GAME_IMPERFECT_SOUND ) |
src/mame/drivers/model3.c
| r10427 | r10428 | |
| 607 | 607 | #include "sound/scsp.h" |
| 608 | 608 | #include "includes/model3.h" |
| 609 | 609 | |
| 610 | | static UINT8 irq_enable; |
| 611 | | static UINT8 irq_state; |
| 612 | | static UINT8 scsi_irq_state; |
| 613 | 610 | |
| 614 | | int model3_step; |
| 615 | | UINT32 *model3_vrom; |
| 616 | | |
| 617 | | static UINT64 *work_ram; |
| 618 | | static int model3_crom_bank = 0; |
| 619 | | static int model3_controls_bank; |
| 620 | | static UINT32 real3d_device_id; |
| 621 | | |
| 622 | 611 | static void real3d_dma_callback(running_machine *machine, UINT32 src, UINT32 dst, int length, int byteswap); |
| 623 | 612 | |
| 624 | | static UINT16 *model3_soundram; |
| 625 | 613 | |
| 626 | 614 | |
| 627 | 615 | static void update_irq_state(running_machine *machine) |
| 628 | 616 | { |
| 629 | | if ((irq_enable & irq_state) || scsi_irq_state) |
| 617 | model3_state *state = machine->driver_data<model3_state>(); |
| 618 | if ((state->irq_enable & state->irq_state) || state->scsi_irq_state) |
| 630 | 619 | { |
| 631 | | // printf("IRQ set: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state); |
| 620 | // printf("IRQ set: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state); |
| 632 | 621 | cputag_set_input_line(machine, "maincpu", PPC_IRQ, ASSERT_LINE); |
| 633 | | scsi_irq_state = 0; |
| 622 | state->scsi_irq_state = 0; |
| 634 | 623 | } |
| 635 | 624 | else |
| 636 | 625 | { |
| 637 | | // printf("IRQ clear: state %x enable %x scsi %x\n", irq_state, irq_enable, scsi_irq_state); |
| 626 | // printf("IRQ clear: state %x enable %x scsi %x\n", state->irq_state, state->irq_enable, state->scsi_irq_state); |
| 638 | 627 | cputag_set_input_line(machine, "maincpu", PPC_IRQ, CLEAR_LINE); |
| 639 | 628 | } |
| 640 | 629 | } |
| 641 | 630 | |
| 642 | | void model3_set_irq_line(running_machine *machine, UINT8 bit, int state) |
| 631 | void model3_set_irq_line(running_machine *machine, UINT8 bit, int line) |
| 643 | 632 | { |
| 644 | | if (state != CLEAR_LINE) |
| 645 | | irq_state |= bit; |
| 633 | model3_state *state = machine->driver_data<model3_state>(); |
| 634 | if (line != CLEAR_LINE) |
| 635 | state->irq_state |= bit; |
| 646 | 636 | else |
| 647 | | irq_state &= ~bit; |
| 637 | state->irq_state &= ~bit; |
| 648 | 638 | update_irq_state(machine); |
| 649 | 639 | } |
| 650 | 640 | |
| 651 | 641 | |
| 652 | | static UINT32 pci_device_get_reg(int device, int reg) |
| 642 | /*****************************************************************************/ |
| 643 | /* Motorola MPC105 PCI Bridge/Memory Controller */ |
| 644 | |
| 645 | |
| 646 | static UINT32 pci_device_get_reg(model3_state *state) |
| 653 | 647 | { |
| 648 | int device = state->pci_device; |
| 649 | int reg = state->pci_reg; |
| 650 | |
| 654 | 651 | switch(device) |
| 655 | 652 | { |
| 656 | 653 | case 11: /* ??? */ |
| r10427 | r10428 | |
| 665 | 662 | case 13: /* Real3D Controller chip */ |
| 666 | 663 | switch(reg) |
| 667 | 664 | { |
| 668 | | case 0: return real3d_device_id; /* PCI Vendor ID & Device ID */ |
| 665 | case 0: return state->real3d_device_id; /* PCI Vendor ID & Device ID */ |
| 669 | 666 | default: |
| 670 | 667 | logerror("pci_device_get_reg: Real3D controller, unknown reg %02X", reg); |
| 671 | 668 | break; |
| r10427 | r10428 | |
| 699 | 696 | return 0; |
| 700 | 697 | } |
| 701 | 698 | |
| 702 | | static void pci_device_set_reg(int device, int reg, UINT32 value) |
| 699 | static void pci_device_set_reg(model3_state *state, UINT32 value) |
| 703 | 700 | { |
| 701 | int device = state->pci_device; |
| 702 | int reg = state->pci_reg; |
| 703 | |
| 704 | 704 | switch(device) |
| 705 | 705 | { |
| 706 | 706 | case 11: /* Unknown device for now !!! */ |
| r10427 | r10428 | |
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | | /*****************************************************************************/ |
| 773 | | /* Motorola MPC105 PCI Bridge/Memory Controller */ |
| 774 | | |
| 775 | | static UINT32 mpc105_regs[0x40]; |
| 776 | | static UINT32 mpc105_addr; |
| 777 | | static int pci_bus; |
| 778 | | static int pci_device; |
| 779 | | static int pci_function; |
| 780 | | static int pci_reg; |
| 781 | | |
| 782 | 772 | static READ64_HANDLER( mpc105_addr_r ) |
| 783 | 773 | { |
| 774 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 784 | 775 | if (ACCESSING_BITS_32_63) |
| 785 | 776 | { |
| 786 | | return (UINT64)mpc105_addr << 32; |
| 777 | return (UINT64)state->mpc105_addr << 32; |
| 787 | 778 | } |
| 788 | 779 | return 0; |
| 789 | 780 | } |
| 790 | 781 | |
| 791 | 782 | static WRITE64_HANDLER( mpc105_addr_w ) |
| 792 | 783 | { |
| 784 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 793 | 785 | if (ACCESSING_BITS_32_63) |
| 794 | 786 | { |
| 795 | 787 | UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 796 | | mpc105_addr = data >> 32; |
| 788 | state->mpc105_addr = data >> 32; |
| 797 | 789 | |
| 798 | | pci_bus = (d >> 16) & 0xff; |
| 799 | | pci_device = (d >> 11) & 0x1f; |
| 800 | | pci_function = (d >> 8) & 0x7; |
| 801 | | pci_reg = (d >> 2) & 0x3f; |
| 790 | state->pci_bus = (d >> 16) & 0xff; |
| 791 | state->pci_device = (d >> 11) & 0x1f; |
| 792 | state->pci_function = (d >> 8) & 0x7; |
| 793 | state->pci_reg = (d >> 2) & 0x3f; |
| 802 | 794 | } |
| 803 | 795 | } |
| 804 | 796 | |
| 805 | 797 | static READ64_HANDLER( mpc105_data_r ) |
| 806 | 798 | { |
| 807 | | if(pci_device == 0) { |
| 808 | | return ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+1])) << 32) | |
| 809 | | ((UINT64)(FLIPENDIAN_INT32(mpc105_regs[(pci_reg/2)+0]))); |
| 799 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 800 | if(state->pci_device == 0) { |
| 801 | return ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+1])) << 32) | |
| 802 | ((UINT64)(FLIPENDIAN_INT32(state->mpc105_regs[(state->pci_reg/2)+0]))); |
| 810 | 803 | } |
| 811 | | return FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg)); |
| 804 | return FLIPENDIAN_INT32(pci_device_get_reg(state)); |
| 812 | 805 | } |
| 813 | 806 | |
| 814 | 807 | static WRITE64_HANDLER( mpc105_data_w ) |
| 815 | 808 | { |
| 816 | | if(pci_device == 0) { |
| 817 | | mpc105_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 818 | | mpc105_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); |
| 809 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 810 | if(state->pci_device == 0) { |
| 811 | state->mpc105_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 812 | state->mpc105_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); |
| 819 | 813 | return; |
| 820 | 814 | } |
| 821 | 815 | if (ACCESSING_BITS_0_31) |
| 822 | 816 | { |
| 823 | | pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data)); |
| 817 | pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data)); |
| 824 | 818 | } |
| 825 | 819 | } |
| 826 | 820 | |
| 827 | 821 | static READ64_HANDLER( mpc105_reg_r ) |
| 828 | 822 | { |
| 829 | | return ((UINT64)(mpc105_regs[(offset*2)+0]) << 32) | |
| 830 | | (UINT64)(mpc105_regs[(offset*2)+1]); |
| 823 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 824 | return ((UINT64)(state->mpc105_regs[(offset*2)+0]) << 32) | |
| 825 | (UINT64)(state->mpc105_regs[(offset*2)+1]); |
| 831 | 826 | } |
| 832 | 827 | |
| 833 | 828 | static WRITE64_HANDLER( mpc105_reg_w ) |
| 834 | 829 | { |
| 835 | | mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32); |
| 836 | | mpc105_regs[(offset*2)+1] = (UINT32)data; |
| 830 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 831 | state->mpc105_regs[(offset*2)+0] = (UINT32)(data >> 32); |
| 832 | state->mpc105_regs[(offset*2)+1] = (UINT32)data; |
| 837 | 833 | } |
| 838 | 834 | |
| 839 | | static void mpc105_init(void) |
| 835 | static void mpc105_init(running_machine *machine) |
| 840 | 836 | { |
| 837 | model3_state *state = machine->driver_data<model3_state>(); |
| 841 | 838 | /* set reset values */ |
| 842 | | memset(mpc105_regs, 0, sizeof(mpc105_regs)); |
| 843 | | mpc105_regs[0x00/4] = 0x00011057; /* Vendor ID & Device ID */ |
| 844 | | mpc105_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ |
| 845 | | mpc105_regs[0x08/4] = 0x00060000; /* Class code */ |
| 846 | | mpc105_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ |
| 847 | | mpc105_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ |
| 848 | | mpc105_regs[0xb8/4] = 0x04000000; |
| 849 | | mpc105_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ |
| 850 | | mpc105_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ |
| 851 | | mpc105_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ |
| 839 | memset(state->mpc105_regs, 0, sizeof(state->mpc105_regs)); |
| 840 | state->mpc105_regs[0x00/4] = 0x00011057; /* Vendor ID & Device ID */ |
| 841 | state->mpc105_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ |
| 842 | state->mpc105_regs[0x08/4] = 0x00060000; /* Class code */ |
| 843 | state->mpc105_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ |
| 844 | state->mpc105_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ |
| 845 | state->mpc105_regs[0xb8/4] = 0x04000000; |
| 846 | state->mpc105_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ |
| 847 | state->mpc105_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ |
| 848 | state->mpc105_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ |
| 852 | 849 | } |
| 853 | 850 | |
| 854 | 851 | /*****************************************************************************/ |
| 855 | 852 | /* Motorola MPC106 PCI Bridge/Memory Controller */ |
| 856 | 853 | |
| 857 | | static UINT32 mpc106_regs[0x40]; |
| 858 | | static UINT32 mpc106_addr; |
| 859 | 854 | |
| 860 | 855 | static READ64_HANDLER( mpc106_addr_r ) |
| 861 | 856 | { |
| 857 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 862 | 858 | if (ACCESSING_BITS_32_63) |
| 863 | 859 | { |
| 864 | | return (UINT64)mpc106_addr << 32; |
| 860 | return (UINT64)state->mpc106_addr << 32; |
| 865 | 861 | } |
| 866 | 862 | return 0; |
| 867 | 863 | } |
| 868 | 864 | |
| 869 | 865 | static WRITE64_HANDLER( mpc106_addr_w ) |
| 870 | 866 | { |
| 867 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 871 | 868 | if (ACCESSING_BITS_32_63) |
| 872 | 869 | { |
| 873 | 870 | UINT32 d = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 874 | 871 | |
| 875 | 872 | if (((d >> 8) & 0xffffff) == 0x800000) |
| 876 | 873 | { |
| 877 | | mpc106_addr = d & 0xff; |
| 874 | state->mpc106_addr = d & 0xff; |
| 878 | 875 | } |
| 879 | 876 | else |
| 880 | 877 | { |
| 881 | | mpc106_addr = data >> 32; |
| 878 | state->mpc106_addr = data >> 32; |
| 882 | 879 | |
| 883 | | pci_bus = (d >> 16) & 0xff; |
| 884 | | pci_device = (d >> 11) & 0x1f; |
| 885 | | pci_function = (d >> 8) & 0x7; |
| 886 | | pci_reg = (d >> 2) & 0x3f; |
| 880 | state->pci_bus = (d >> 16) & 0xff; |
| 881 | state->pci_device = (d >> 11) & 0x1f; |
| 882 | state->pci_function = (d >> 8) & 0x7; |
| 883 | state->pci_reg = (d >> 2) & 0x3f; |
| 887 | 884 | } |
| 888 | 885 | } |
| 889 | 886 | } |
| 890 | 887 | |
| 891 | 888 | static READ64_HANDLER( mpc106_data_r ) |
| 892 | 889 | { |
| 893 | | if(pci_device == 0) { |
| 894 | | return ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+1])) << 32) | |
| 895 | | ((UINT64)(FLIPENDIAN_INT32(mpc106_regs[(pci_reg/2)+0]))); |
| 890 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 891 | if(state->pci_device == 0) { |
| 892 | return ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+1])) << 32) | |
| 893 | ((UINT64)(FLIPENDIAN_INT32(state->mpc106_regs[(state->pci_reg/2)+0]))); |
| 896 | 894 | } |
| 897 | 895 | if (ACCESSING_BITS_32_63) |
| 898 | 896 | { |
| 899 | | return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg))) << 32; |
| 897 | return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state))) << 32; |
| 900 | 898 | } |
| 901 | 899 | else |
| 902 | 900 | { |
| 903 | | return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(pci_device, pci_reg))); |
| 901 | return (UINT64)(FLIPENDIAN_INT32(pci_device_get_reg(state))); |
| 904 | 902 | } |
| 905 | 903 | } |
| 906 | 904 | |
| 907 | 905 | static WRITE64_HANDLER( mpc106_data_w ) |
| 908 | 906 | { |
| 909 | | if(pci_device == 0) { |
| 910 | | mpc106_regs[(pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 911 | | mpc106_regs[(pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); |
| 907 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 908 | if(state->pci_device == 0) { |
| 909 | state->mpc106_regs[(state->pci_reg/2)+1] = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 910 | state->mpc106_regs[(state->pci_reg/2)+0] = FLIPENDIAN_INT32((UINT32)(data)); |
| 912 | 911 | return; |
| 913 | 912 | } |
| 914 | 913 | if (ACCESSING_BITS_0_31) |
| 915 | 914 | { |
| 916 | | pci_device_set_reg(pci_device, pci_reg, FLIPENDIAN_INT32((UINT32)data)); |
| 915 | pci_device_set_reg(state, FLIPENDIAN_INT32((UINT32)data)); |
| 917 | 916 | } |
| 918 | 917 | } |
| 919 | 918 | |
| 920 | 919 | static READ64_HANDLER( mpc106_reg_r ) |
| 921 | 920 | { |
| 922 | | return ((UINT64)(mpc106_regs[(offset*2)+0]) << 32) | |
| 923 | | (UINT64)(mpc106_regs[(offset*2)+1]); |
| 921 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 922 | return ((UINT64)(state->mpc106_regs[(offset*2)+0]) << 32) | |
| 923 | (UINT64)(state->mpc106_regs[(offset*2)+1]); |
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | static WRITE64_HANDLER( mpc106_reg_w ) |
| 927 | 927 | { |
| 928 | | mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32); |
| 929 | | mpc106_regs[(offset*2)+1] = (UINT32)data; |
| 928 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 929 | state->mpc106_regs[(offset*2)+0] = (UINT32)(data >> 32); |
| 930 | state->mpc106_regs[(offset*2)+1] = (UINT32)data; |
| 930 | 931 | } |
| 931 | 932 | |
| 932 | | static void mpc106_init(void) |
| 933 | static void mpc106_init(running_machine *machine) |
| 933 | 934 | { |
| 935 | model3_state *state = machine->driver_data<model3_state>(); |
| 934 | 936 | /* set reset values */ |
| 935 | | memset(mpc106_regs, 0, sizeof(mpc106_regs)); |
| 936 | | mpc106_regs[0x00/4] = 0x00021057; /* Vendor ID & Device ID */ |
| 937 | | mpc106_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ |
| 938 | | mpc106_regs[0x08/4] = 0x00060000; /* Class code */ |
| 939 | | mpc106_regs[0x0c/4] = 0x00000800; /* Cache line size */ |
| 940 | | mpc106_regs[0x70/4] = 0x00cd0000; /* Output driver control */ |
| 941 | | mpc106_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ |
| 942 | | mpc106_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ |
| 943 | | mpc106_regs[0xb8/4] = 0x04000000; |
| 944 | | mpc106_regs[0xc0/4] = 0x00000100; /* Error enabling 1 */ |
| 945 | | mpc106_regs[0xe0/4] = 0x00420fff; /* Emulation support configuration 1 */ |
| 946 | | mpc106_regs[0xe8/4] = 0x00200000; /* Emulation support configuration 2 */ |
| 947 | | mpc106_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ |
| 948 | | mpc106_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ |
| 949 | | mpc106_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ |
| 937 | memset(state->mpc106_regs, 0, sizeof(state->mpc106_regs)); |
| 938 | state->mpc106_regs[0x00/4] = 0x00021057; /* Vendor ID & Device ID */ |
| 939 | state->mpc106_regs[0x04/4] = 0x00800006; /* PCI Command & PCI Status */ |
| 940 | state->mpc106_regs[0x08/4] = 0x00060000; /* Class code */ |
| 941 | state->mpc106_regs[0x0c/4] = 0x00000800; /* Cache line size */ |
| 942 | state->mpc106_regs[0x70/4] = 0x00cd0000; /* Output driver control */ |
| 943 | state->mpc106_regs[0xa8/4] = 0x0010ff00; /* Processor interface configuration 1 */ |
| 944 | state->mpc106_regs[0xac/4] = 0x060c000c; /* Processor interface configuration 2 */ |
| 945 | state->mpc106_regs[0xb8/4] = 0x04000000; |
| 946 | state->mpc106_regs[0xc0/4] = 0x00000100; /* Error enabling 1 */ |
| 947 | state->mpc106_regs[0xe0/4] = 0x00420fff; /* Emulation support configuration 1 */ |
| 948 | state->mpc106_regs[0xe8/4] = 0x00200000; /* Emulation support configuration 2 */ |
| 949 | state->mpc106_regs[0xf0/4] = 0x0000ff02; /* Memory control configuration 1 */ |
| 950 | state->mpc106_regs[0xf4/4] = 0x00030000; /* Memory control configuration 2 */ |
| 951 | state->mpc106_regs[0xfc/4] = 0x00000010; /* Memory control configuration 4 */ |
| 950 | 952 | } |
| 951 | 953 | |
| 952 | 954 | /*****************************************************************************/ |
| r10427 | r10428 | |
| 1022 | 1024 | |
| 1023 | 1025 | static void scsi_irq_callback(running_machine *machine, int state) |
| 1024 | 1026 | { |
| 1025 | | scsi_irq_state = state; |
| 1027 | model3_state *drvstate = machine->driver_data<model3_state>(); |
| 1028 | drvstate->scsi_irq_state = state; |
| 1026 | 1029 | update_irq_state(machine); |
| 1027 | 1030 | } |
| 1028 | 1031 | |
| 1029 | 1032 | /*****************************************************************************/ |
| 1030 | 1033 | /* Real3D DMA */ |
| 1031 | 1034 | |
| 1032 | | static UINT32 dma_data; |
| 1033 | | static UINT32 dma_status; |
| 1034 | | static UINT32 dma_source; |
| 1035 | | static UINT32 dma_dest; |
| 1036 | | static UINT32 dma_endian; |
| 1037 | | static UINT32 dma_irq; |
| 1038 | 1035 | |
| 1039 | 1036 | static READ64_HANDLER( real3d_dma_r ) |
| 1040 | 1037 | { |
| 1038 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1041 | 1039 | switch(offset) |
| 1042 | 1040 | { |
| 1043 | 1041 | case 1: |
| 1044 | | return (dma_irq << 24) | (dma_endian << 8); |
| 1042 | return (state->dma_irq << 24) | (state->dma_endian << 8); |
| 1045 | 1043 | case 2: |
| 1046 | 1044 | if(ACCESSING_BITS_0_31) { |
| 1047 | | return dma_data; |
| 1045 | return state->dma_data; |
| 1048 | 1046 | } |
| 1049 | 1047 | break; |
| 1050 | 1048 | } |
| r10427 | r10428 | |
| 1054 | 1052 | |
| 1055 | 1053 | static WRITE64_HANDLER( real3d_dma_w ) |
| 1056 | 1054 | { |
| 1055 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1057 | 1056 | switch(offset) |
| 1058 | 1057 | { |
| 1059 | 1058 | case 0: |
| 1060 | 1059 | if(ACCESSING_BITS_32_63) { /* DMA source address */ |
| 1061 | | dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 1060 | state->dma_source = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 1062 | 1061 | return; |
| 1063 | 1062 | } |
| 1064 | 1063 | if(ACCESSING_BITS_0_31) { /* DMA destination address */ |
| 1065 | | dma_dest = FLIPENDIAN_INT32((UINT32)(data)); |
| 1064 | state->dma_dest = FLIPENDIAN_INT32((UINT32)(data)); |
| 1066 | 1065 | return; |
| 1067 | 1066 | } |
| 1068 | 1067 | break; |
| r10427 | r10428 | |
| 1070 | 1069 | if(ACCESSING_BITS_32_63) /* DMA length */ |
| 1071 | 1070 | { |
| 1072 | 1071 | int length = FLIPENDIAN_INT32((UINT32)(data >> 32)) * 4; |
| 1073 | | if (dma_endian & 0x80) |
| 1072 | if (state->dma_endian & 0x80) |
| 1074 | 1073 | { |
| 1075 | | real3d_dma_callback(space->machine, dma_source, dma_dest, length, 0); |
| 1074 | real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 0); |
| 1076 | 1075 | } |
| 1077 | 1076 | else |
| 1078 | 1077 | { |
| 1079 | | real3d_dma_callback(space->machine, dma_source, dma_dest, length, 1); |
| 1078 | real3d_dma_callback(space->machine, state->dma_source, state->dma_dest, length, 1); |
| 1080 | 1079 | } |
| 1081 | | dma_irq |= 0x01; |
| 1080 | state->dma_irq |= 0x01; |
| 1082 | 1081 | scsi_irq_callback(space->machine, 1); |
| 1083 | 1082 | return; |
| 1084 | 1083 | } |
| 1085 | 1084 | else if(ACCESSING_BITS_16_23) |
| 1086 | 1085 | { |
| 1087 | 1086 | if(data & 0x10000) { |
| 1088 | | dma_irq &= ~0x1; |
| 1087 | state->dma_irq &= ~0x1; |
| 1089 | 1088 | scsi_irq_callback(space->machine, 0); |
| 1090 | 1089 | } |
| 1091 | 1090 | return; |
| 1092 | 1091 | } |
| 1093 | 1092 | else if(ACCESSING_BITS_8_15) |
| 1094 | 1093 | { |
| 1095 | | dma_endian = (data >> 8) & 0xff; |
| 1094 | state->dma_endian = (data >> 8) & 0xff; |
| 1096 | 1095 | return; |
| 1097 | 1096 | } |
| 1098 | 1097 | break; |
| r10427 | r10428 | |
| 1100 | 1099 | if(ACCESSING_BITS_32_63) { /* DMA command */ |
| 1101 | 1100 | UINT32 cmd = FLIPENDIAN_INT32((UINT32)(data >> 32)); |
| 1102 | 1101 | if(cmd & 0x20000000) { |
| 1103 | | dma_data = FLIPENDIAN_INT32(real3d_device_id); /* (PCI Vendor & Device ID) */ |
| 1102 | state->dma_data = FLIPENDIAN_INT32(state->real3d_device_id); /* (PCI Vendor & Device ID) */ |
| 1104 | 1103 | } |
| 1105 | 1104 | else if(cmd & 0x80000000) { |
| 1106 | | dma_status ^= 0xffffffff; |
| 1107 | | dma_data = dma_status; |
| 1105 | state->dma_status ^= 0xffffffff; |
| 1106 | state->dma_data = state->dma_status; |
| 1108 | 1107 | } |
| 1109 | 1108 | return; |
| 1110 | 1109 | } |
| 1111 | 1110 | if(ACCESSING_BITS_0_31) { /* ??? */ |
| 1112 | | dma_data = 0xffffffff; |
| 1111 | state->dma_data = 0xffffffff; |
| 1113 | 1112 | return; |
| 1114 | 1113 | } |
| 1115 | 1114 | return; |
| r10427 | r10428 | |
| 1187 | 1186 | |
| 1188 | 1187 | static void configure_fast_ram(running_machine *machine) |
| 1189 | 1188 | { |
| 1189 | model3_state *state = machine->driver_data<model3_state>(); |
| 1190 | 1190 | /* set conservative DRC options */ |
| 1191 | 1191 | ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS - PPCDRC_ACCURATE_SINGLES); |
| 1192 | 1192 | |
| 1193 | 1193 | /* configure fast RAM regions for DRC */ |
| 1194 | | ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, work_ram); |
| 1194 | ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x007fffff, FALSE, state->work_ram); |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | static MACHINE_START(model3_10) |
| r10427 | r10428 | |
| 1217 | 1217 | |
| 1218 | 1218 | static void model3_init(running_machine *machine, int step) |
| 1219 | 1219 | { |
| 1220 | | model3_step = step; |
| 1220 | model3_state *state = machine->driver_data<model3_state>(); |
| 1221 | state->step = step; |
| 1221 | 1222 | memory_set_bankptr(machine, "bank1", machine->region( "user1" )->base() + 0x800000 ); /* banked CROM */ |
| 1222 | 1223 | |
| 1223 | 1224 | memory_set_bankptr(machine, "bank4", machine->region("samples")->base() + 0x200000); |
| 1224 | 1225 | memory_set_bankptr(machine, "bank5", machine->region("samples")->base() + 0x600000); |
| 1225 | 1226 | |
| 1226 | 1227 | // copy the 68k vector table into RAM |
| 1227 | | memcpy(model3_soundram, machine->region("audiocpu")->base()+0x80000, 16); |
| 1228 | memcpy(state->soundram, machine->region("audiocpu")->base()+0x80000, 16); |
| 1228 | 1229 | machine->device("audiocpu")->reset(); |
| 1229 | 1230 | |
| 1230 | | model3_machine_init(step); // step 1.5 |
| 1231 | | model3_tap_reset(); |
| 1231 | model3_machine_init(machine, step); // step 1.5 |
| 1232 | model3_tap_reset(machine); |
| 1232 | 1233 | |
| 1233 | 1234 | if(step < 0x20) { |
| 1234 | 1235 | if( mame_stricmp(machine->gamedrv->name, "vs215") == 0 || |
| 1235 | 1236 | mame_stricmp(machine->gamedrv->name, "vs29815") == 0 || |
| 1236 | 1237 | mame_stricmp(machine->gamedrv->name, "bass") == 0 ) |
| 1237 | 1238 | { |
| 1238 | | mpc106_init(); |
| 1239 | mpc106_init(machine); |
| 1239 | 1240 | } |
| 1240 | 1241 | else |
| 1241 | 1242 | { |
| 1242 | | mpc105_init(); |
| 1243 | mpc105_init(machine); |
| 1243 | 1244 | } |
| 1244 | | real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ |
| 1245 | state->real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ |
| 1245 | 1246 | } |
| 1246 | 1247 | else { |
| 1247 | | mpc106_init(); |
| 1248 | mpc106_init(machine); |
| 1248 | 1249 | // some step 2+ games need the older PCI ID (obvious symptom: |
| 1249 | 1250 | // vbl is enabled briefly then disabled so the game hangs) |
| 1250 | 1251 | if (mame_stricmp(machine->gamedrv->name, "magtruck") == 0 || |
| 1251 | 1252 | mame_stricmp(machine->gamedrv->name, "von254g") == 0) |
| 1252 | 1253 | { |
| 1253 | | real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ |
| 1254 | state->real3d_device_id = 0x16c311db; /* PCI Vendor ID (11db = SEGA), Device ID (16c3 = 315-5827) */ |
| 1254 | 1255 | } |
| 1255 | 1256 | else |
| 1256 | 1257 | { |
| 1257 | | real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */ |
| 1258 | state->real3d_device_id = 0x178611db; /* PCI Vendor ID (11db = SEGA), Device ID (1786 = 315-6022) */ |
| 1258 | 1259 | } |
| 1259 | 1260 | } |
| 1260 | 1261 | } |
| r10427 | r10428 | |
| 1264 | 1265 | static MACHINE_RESET(model3_20) { model3_init(machine, 0x20); } |
| 1265 | 1266 | static MACHINE_RESET(model3_21) { model3_init(machine, 0x21); } |
| 1266 | 1267 | |
| 1267 | | static UINT64 controls_2; |
| 1268 | | static UINT64 controls_3; |
| 1269 | | static UINT8 model3_serial_fifo1; |
| 1270 | | static UINT8 model3_serial_fifo2; |
| 1271 | | static int lightgun_reg_sel; |
| 1272 | | static int adc_channel; |
| 1273 | 1268 | |
| 1274 | 1269 | static READ64_HANDLER( model3_ctrl_r ) |
| 1275 | 1270 | { |
| 1271 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1276 | 1272 | switch( offset ) |
| 1277 | 1273 | { |
| 1278 | 1274 | case 0: |
| 1279 | 1275 | if (ACCESSING_BITS_56_63) |
| 1280 | 1276 | { |
| 1281 | | return (UINT64)model3_controls_bank << 56; |
| 1277 | return (UINT64)state->controls_bank << 56; |
| 1282 | 1278 | } |
| 1283 | 1279 | else if (ACCESSING_BITS_24_31) |
| 1284 | 1280 | { |
| 1285 | | if(model3_controls_bank & 0x1) |
| 1281 | if(state->controls_bank & 0x1) |
| 1286 | 1282 | { |
| 1287 | 1283 | return (input_port_read(space->machine, "IN1")) << 24; |
| 1288 | 1284 | } |
| r10427 | r10428 | |
| 1316 | 1312 | case 5: |
| 1317 | 1313 | if (ACCESSING_BITS_24_31) /* Serial comm RX FIFO 1 */ |
| 1318 | 1314 | { |
| 1319 | | return (UINT64)model3_serial_fifo1 << 24; |
| 1315 | return (UINT64)state->serial_fifo1 << 24; |
| 1320 | 1316 | } |
| 1321 | 1317 | break; |
| 1322 | 1318 | |
| 1323 | 1319 | case 6: |
| 1324 | 1320 | if (ACCESSING_BITS_56_63) /* Serial comm RX FIFO 2 */ |
| 1325 | 1321 | { |
| 1326 | | return (UINT64)model3_serial_fifo2 << 56; |
| 1322 | return (UINT64)state->serial_fifo2 << 56; |
| 1327 | 1323 | } |
| 1328 | 1324 | else if (ACCESSING_BITS_24_31) /* Serial comm full/empty flags */ |
| 1329 | 1325 | { |
| r10427 | r10428 | |
| 1335 | 1331 | if (ACCESSING_BITS_24_31) /* ADC Data read */ |
| 1336 | 1332 | { |
| 1337 | 1333 | static const char *const adcnames[] = { "AN0", "AN1", "AN2", "AN3", "AN4", "AN5", "AN6", "AN7" }; |
| 1338 | | UINT8 adc_data = input_port_read_safe(space->machine, adcnames[adc_channel], 0); |
| 1339 | | adc_channel++; |
| 1340 | | adc_channel &= 0x7; |
| 1334 | UINT8 adc_data = input_port_read_safe(space->machine, adcnames[state->adc_channel], 0); |
| 1335 | state->adc_channel++; |
| 1336 | state->adc_channel &= 0x7; |
| 1341 | 1337 | return (UINT64)adc_data << 24; |
| 1342 | 1338 | } |
| 1343 | 1339 | break; |
| r10427 | r10428 | |
| 1349 | 1345 | |
| 1350 | 1346 | static WRITE64_HANDLER( model3_ctrl_w ) |
| 1351 | 1347 | { |
| 1348 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1352 | 1349 | switch(offset) |
| 1353 | 1350 | { |
| 1354 | 1351 | case 0: |
| r10427 | r10428 | |
| 1359 | 1356 | eeprom_write_bit(device, (reg & 0x20) ? 1 : 0); |
| 1360 | 1357 | eeprom_set_clock_line(device, (reg & 0x80) ? ASSERT_LINE : CLEAR_LINE); |
| 1361 | 1358 | eeprom_set_cs_line(device, (reg & 0x40) ? CLEAR_LINE : ASSERT_LINE); |
| 1362 | | model3_controls_bank = reg & 0xff; |
| 1359 | state->controls_bank = reg & 0xff; |
| 1363 | 1360 | } |
| 1364 | 1361 | return; |
| 1365 | 1362 | |
| 1366 | 1363 | case 2: |
| 1367 | | COMBINE_DATA(&controls_2); |
| 1364 | COMBINE_DATA(&state->controls_2); |
| 1368 | 1365 | return; |
| 1369 | 1366 | |
| 1370 | 1367 | case 3: |
| 1371 | | COMBINE_DATA(&controls_3); |
| 1368 | COMBINE_DATA(&state->controls_3); |
| 1372 | 1369 | return; |
| 1373 | 1370 | |
| 1374 | 1371 | case 4: |
| r10427 | r10428 | |
| 1381 | 1378 | switch(data >> 24) |
| 1382 | 1379 | { |
| 1383 | 1380 | case 0x00: |
| 1384 | | lightgun_reg_sel = model3_serial_fifo2; |
| 1381 | state->lightgun_reg_sel = state->serial_fifo2; |
| 1385 | 1382 | break; |
| 1386 | 1383 | case 0x87: |
| 1387 | | model3_serial_fifo1 = 0; |
| 1388 | | switch(lightgun_reg_sel) /* read lightrun register */ |
| 1384 | state->serial_fifo1 = 0; |
| 1385 | switch(state->lightgun_reg_sel) /* read lightrun register */ |
| 1389 | 1386 | { |
| 1390 | 1387 | case 0: /* player 1 gun X-position, lower 8-bits */ |
| 1391 | | model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff; |
| 1388 | state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_Y") & 0xff; |
| 1392 | 1389 | break; |
| 1393 | 1390 | case 1: /* player 1 gun X-position, upper 2-bits */ |
| 1394 | | model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3; |
| 1391 | state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_Y") >> 8) & 0x3; |
| 1395 | 1392 | break; |
| 1396 | 1393 | case 2: /* player 1 gun Y-position, lower 8-bits */ |
| 1397 | | model3_serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff; |
| 1394 | state->serial_fifo2 = input_port_read(space->machine, "LIGHT0_X") & 0xff; |
| 1398 | 1395 | break; |
| 1399 | 1396 | case 3: /* player 1 gun Y-position, upper 2-bits */ |
| 1400 | | model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3; |
| 1397 | state->serial_fifo2 = (input_port_read(space->machine, "LIGHT0_X") >> 8) & 0x3; |
| 1401 | 1398 | break; |
| 1402 | 1399 | case 4: /* player 2 gun X-position, lower 8-bits */ |
| 1403 | | model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff; |
| 1400 | state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_Y") & 0xff; |
| 1404 | 1401 | break; |
| 1405 | 1402 | case 5: /* player 2 gun X-position, upper 2-bits */ |
| 1406 | | model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3; |
| 1403 | state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_Y") >> 8) & 0x3; |
| 1407 | 1404 | break; |
| 1408 | 1405 | case 6: /* player 2 gun Y-position, lower 8-bits */ |
| 1409 | | model3_serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff; |
| 1406 | state->serial_fifo2 = input_port_read(space->machine, "LIGHT1_X") & 0xff; |
| 1410 | 1407 | break; |
| 1411 | 1408 | case 7: /* player 2 gun Y-position, upper 2-bits */ |
| 1412 | | model3_serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3; |
| 1409 | state->serial_fifo2 = (input_port_read(space->machine, "LIGHT1_X") >> 8) & 0x3; |
| 1413 | 1410 | break; |
| 1414 | 1411 | case 8: /* gun offscreen (bit set = gun offscreen, bit clear = gun on screen) */ |
| 1415 | | model3_serial_fifo2 = 0; /* bit 0 = player 1, bit 1 = player 2 */ |
| 1412 | state->serial_fifo2 = 0; /* bit 0 = player 1, bit 1 = player 2 */ |
| 1416 | 1413 | if(input_port_read(space->machine, "OFFSCREEN") & 0x1) { |
| 1417 | | model3_serial_fifo2 |= 0x01; |
| 1414 | state->serial_fifo2 |= 0x01; |
| 1418 | 1415 | } |
| 1419 | 1416 | break; |
| 1420 | 1417 | } |
| r10427 | r10428 | |
| 1429 | 1426 | case 5: |
| 1430 | 1427 | if (ACCESSING_BITS_56_63) /* Serial comm TX FIFO 2 */ |
| 1431 | 1428 | { |
| 1432 | | model3_serial_fifo2 = data >> 56; |
| 1429 | state->serial_fifo2 = data >> 56; |
| 1433 | 1430 | return; |
| 1434 | 1431 | } |
| 1435 | 1432 | break; |
| r10427 | r10428 | |
| 1437 | 1434 | case 7: |
| 1438 | 1435 | if (ACCESSING_BITS_24_31) /* ADC Channel selection */ |
| 1439 | 1436 | { |
| 1440 | | adc_channel = (data >> 24) & 0xf; |
| 1437 | state->adc_channel = (data >> 24) & 0xf; |
| 1441 | 1438 | } |
| 1442 | 1439 | return; |
| 1443 | 1440 | } |
| r10427 | r10428 | |
| 1447 | 1444 | |
| 1448 | 1445 | static READ64_HANDLER( model3_sys_r ) |
| 1449 | 1446 | { |
| 1447 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1450 | 1448 | // printf("model3_sys_r: mask %llx @ %x (PC %x)\n", mem_mask, offset, cpu_get_pc(space->cpu)); |
| 1451 | 1449 | |
| 1452 | 1450 | switch (offset) |
| r10427 | r10428 | |
| 1454 | 1452 | case 0x08/8: |
| 1455 | 1453 | if (ACCESSING_BITS_56_63) |
| 1456 | 1454 | { |
| 1457 | | return ((UINT64)model3_crom_bank << 56); |
| 1455 | return ((UINT64)state->crom_bank << 56); |
| 1458 | 1456 | } |
| 1459 | 1457 | break; |
| 1460 | 1458 | |
| 1461 | 1459 | case 0x10/8: |
| 1462 | 1460 | if (ACCESSING_BITS_56_63) |
| 1463 | 1461 | { |
| 1464 | | UINT64 res = model3_tap_read(); |
| 1462 | UINT64 res = model3_tap_read(space->machine); |
| 1465 | 1463 | |
| 1466 | 1464 | return res<<61; |
| 1467 | 1465 | } |
| 1468 | 1466 | else if (ACCESSING_BITS_24_31) |
| 1469 | 1467 | { |
| 1470 | | return (irq_enable<<24); |
| 1468 | return (state->irq_enable<<24); |
| 1471 | 1469 | } |
| 1472 | 1470 | else logerror("m3_sys: Unk sys_r @ 0x10: mask = %x\n", (UINT32)mem_mask); |
| 1473 | 1471 | break; |
| 1474 | 1472 | case 0x18/8: |
| 1475 | | // printf("read irq_state %x (PC %x)\n", irq_state, cpu_get_pc(space->cpu)); |
| 1476 | | return (UINT64)irq_state<<56 | 0xff000000; |
| 1473 | // printf("read state->irq_state %x (PC %x)\n", state->irq_state, cpu_get_pc(space->cpu)); |
| 1474 | return (UINT64)state->irq_state<<56 | 0xff000000; |
| 1477 | 1475 | break; |
| 1478 | 1476 | } |
| 1479 | 1477 | |
| r10427 | r10428 | |
| 1483 | 1481 | |
| 1484 | 1482 | static WRITE64_HANDLER( model3_sys_w ) |
| 1485 | 1483 | { |
| 1484 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1486 | 1485 | // printf("model3_sys_w: %llx to %x mask %llx\n", data, offset, mem_mask); |
| 1487 | 1486 | |
| 1488 | 1487 | switch (offset) |
| r10427 | r10428 | |
| 1490 | 1489 | case 0x10/8: |
| 1491 | 1490 | if (ACCESSING_BITS_24_31) |
| 1492 | 1491 | { |
| 1493 | | irq_enable = (data>>24)&0xff; |
| 1492 | state->irq_enable = (data>>24)&0xff; |
| 1494 | 1493 | } |
| 1495 | 1494 | else logerror("m3_sys: unknown mask on IRQen write\n"); |
| 1496 | 1495 | break; |
| 1497 | 1496 | case 0x18/8: |
| 1498 | 1497 | if ((mem_mask & 0xff000000) == 0xff000000) // int ACK with bits in REVERSE ORDER from the other registers (Seeeee-gaaaa!) |
| 1499 | 1498 | { // may also be a secondary enable based on behavior of e.g. magtruck VBL handler |
| 1500 | | // UINT32 old_irq = irq_state; |
| 1499 | // UINT32 old_irq = state->irq_state; |
| 1501 | 1500 | UINT8 ack = (data>>24)&0xff, realack; |
| 1502 | 1501 | int i; |
| 1503 | 1502 | |
| r10427 | r10428 | |
| 1519 | 1518 | |
| 1520 | 1519 | // printf("%x to ack (realack %x)\n", ack, realack); |
| 1521 | 1520 | |
| 1522 | | irq_state &= realack; |
| 1521 | state->irq_state &= realack; |
| 1523 | 1522 | break; |
| 1524 | 1523 | } |
| 1525 | 1524 | } |
| r10427 | r10428 | |
| 1531 | 1530 | case 0x08/8: |
| 1532 | 1531 | if (ACCESSING_BITS_56_63) |
| 1533 | 1532 | { |
| 1534 | | model3_crom_bank = data >> 56; |
| 1533 | state->crom_bank = data >> 56; |
| 1535 | 1534 | |
| 1536 | 1535 | data >>= 56; |
| 1537 | 1536 | data = (~data) & 0x7; |
| r10427 | r10428 | |
| 1541 | 1540 | if (ACCESSING_BITS_24_31) |
| 1542 | 1541 | { |
| 1543 | 1542 | data >>= 24; |
| 1544 | | model3_tap_write( |
| 1543 | model3_tap_write(space->machine, |
| 1545 | 1544 | (data >> 6) & 1,// TCK |
| 1546 | 1545 | (data >> 2) & 1,// TMS |
| 1547 | 1546 | (data >> 5) & 1,// TDI |
| r10427 | r10428 | |
| 1574 | 1573 | } |
| 1575 | 1574 | } |
| 1576 | 1575 | |
| 1577 | | static UINT64 real3d_status = 0; |
| 1578 | 1576 | static READ64_HANDLER(real3d_status_r) |
| 1579 | 1577 | { |
| 1580 | | real3d_status ^= U64(0xffffffffffffffff); |
| 1578 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1579 | state->real3d_status ^= U64(0xffffffffffffffff); |
| 1581 | 1580 | if (offset == 0) |
| 1582 | 1581 | { |
| 1583 | 1582 | /* pretty sure this is VBLANK */ |
| 1584 | | real3d_status &= ~U64(0x0000000200000000); |
| 1583 | state->real3d_status &= ~U64(0x0000000200000000); |
| 1585 | 1584 | if (space->machine->primary_screen->vblank()) |
| 1586 | | real3d_status |= U64(0x0000000200000000); |
| 1587 | | return real3d_status; |
| 1585 | state->real3d_status |= U64(0x0000000200000000); |
| 1586 | return state->real3d_status; |
| 1588 | 1587 | } |
| 1589 | | return real3d_status; |
| 1588 | return state->real3d_status; |
| 1590 | 1589 | } |
| 1591 | 1590 | |
| 1592 | 1591 | /* SCSP interface */ |
| r10427 | r10428 | |
| 1614 | 1613 | |
| 1615 | 1614 | |
| 1616 | 1615 | |
| 1617 | | static UINT64 network_ram[0x10000]; |
| 1618 | 1616 | static READ64_HANDLER(network_r) |
| 1619 | 1617 | { |
| 1618 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1620 | 1619 | mame_printf_debug("network_r: %02X at %08X\n", offset, cpu_get_pc(space->cpu)); |
| 1621 | | return network_ram[offset]; |
| 1620 | return state->network_ram[offset]; |
| 1622 | 1621 | } |
| 1623 | 1622 | |
| 1624 | 1623 | static WRITE64_HANDLER(network_w) |
| 1625 | 1624 | { |
| 1626 | | COMBINE_DATA(network_ram + offset); |
| 1625 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1626 | COMBINE_DATA(state->network_ram + offset); |
| 1627 | 1627 | mame_printf_debug("network_w: %02X, %08X%08X at %08X\n", offset, (UINT32)(data >> 32), (UINT32)(data), cpu_get_pc(space->cpu)); |
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | | static int prot_data_ptr = 0; |
| 1631 | 1630 | |
| 1632 | 1631 | static const UINT16 vs299_prot_data[] = |
| 1633 | 1632 | { |
| r10427 | r10428 | |
| 1701 | 1700 | |
| 1702 | 1701 | static READ64_HANDLER(model3_security_r) |
| 1703 | 1702 | { |
| 1703 | model3_state *state = space->machine->driver_data<model3_state>(); |
| 1704 | 1704 | switch(offset) |
| 1705 | 1705 | { |
| 1706 | 1706 | case 0x00/8: return 0; /* status */ |
| r10427 | r10428 | |
| 1709 | 1709 | if (mame_stricmp(space->machine->gamedrv->name, "vs299") == 0 || |
| 1710 | 1710 | mame_stricmp(space->machine->gamedrv->name, "vs2v991") == 0) |
| 1711 | 1711 | { |
| 1712 | | return (UINT64)vs299_prot_data[prot_data_ptr++] << 48; |
| 1712 | return (UINT64)vs299_prot_data[state->prot_data_ptr++] << 48; |
| 1713 | 1713 | } |
| 1714 | 1714 | else if (mame_stricmp(space->machine->gamedrv->name, "swtrilgy") == 0 || |
| 1715 | 1715 | mame_stricmp(space->machine->gamedrv->name, "swtrilgya") == 0) |
| 1716 | 1716 | { |
| 1717 | | UINT64 data = (UINT64)swt_prot_data[prot_data_ptr++] << 16; |
| 1718 | | if (prot_data_ptr > 0x38) |
| 1717 | UINT64 data = (UINT64)swt_prot_data[state->prot_data_ptr++] << 16; |
| 1718 | if (state->prot_data_ptr > 0x38) |
| 1719 | 1719 | { |
| 1720 | | prot_data_ptr = 0; |
| 1720 | state->prot_data_ptr = 0; |
| 1721 | 1721 | } |
| 1722 | 1722 | return data; |
| 1723 | 1723 | } |
| 1724 | 1724 | else if (mame_stricmp(space->machine->gamedrv->name, "fvipers2") == 0) |
| 1725 | 1725 | { |
| 1726 | | UINT64 data = (UINT64)fvipers2_prot_data[prot_data_ptr++] << 16; |
| 1727 | | if (prot_data_ptr >= 0x41) |
| 1726 | UINT64 data = (UINT64)fvipers2_prot_data[state->prot_data_ptr++] << 16; |
| 1727 | if (state->prot_data_ptr >= 0x41) |
| 1728 | 1728 | { |
| 1729 | | prot_data_ptr = 0; |
| 1729 | state->prot_data_ptr = 0; |
| 1730 | 1730 | } |
| 1731 | 1731 | return data; |
| 1732 | 1732 | } |
| 1733 | 1733 | else if (mame_stricmp(space->machine->gamedrv->name, "spikeout") == 0 || |
| 1734 | 1734 | mame_stricmp(space->machine->gamedrv->name, "spikeofe") == 0) |
| 1735 | 1735 | { |
| 1736 | | UINT64 data = (UINT64)spikeout_prot_data[prot_data_ptr++] << 16; |
| 1737 | | if (prot_data_ptr >= 0x55) |
| 1736 | UINT64 data = (UINT64)spikeout_prot_data[state->prot_data_ptr++] << 16; |
| 1737 | if (state->prot_data_ptr >= 0x55) |
| 1738 | 1738 | { |
| 1739 | | prot_data_ptr = 0; |
| 1739 | state->prot_data_ptr = 0; |
| 1740 | 1740 | } |
| 1741 | 1741 | return data; |
| 1742 | 1742 | } |
| 1743 | 1743 | else if (mame_stricmp(space->machine->gamedrv->name, "eca") == 0 || |
| 1744 | 1744 | mame_stricmp(space->machine->gamedrv->name, "ecax") == 0) |
| 1745 | 1745 | { |
| 1746 | | UINT64 data = (UINT64)eca_prot_data[prot_data_ptr++] << 16; |
| 1747 | | if (prot_data_ptr >= 0x31) |
| 1746 | UINT64 data = (UINT64)eca_prot_data[state->prot_data_ptr++] << 16; |
| 1747 | if (state->prot_data_ptr >= 0x31) |
| 1748 | 1748 | { |
| 1749 | | prot_data_ptr = 0; |
| 1749 | state->prot_data_ptr = 0; |
| 1750 | 1750 | } |
| 1751 | 1751 | return data; |
| 1752 | 1752 | } |
| r10427 | r10428 | |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | 1773 | static ADDRESS_MAP_START( model3_mem, ADDRESS_SPACE_PROGRAM, 64) |
| 1774 | | AM_RANGE(0x00000000, 0x007fffff) AM_RAM AM_BASE(&work_ram) /* work RAM */ |
| 1774 | AM_RANGE(0x00000000, 0x007fffff) AM_RAM AM_BASE_MEMBER(model3_state, work_ram) /* work RAM */ |
| 1775 | 1775 | |
| 1776 | 1776 | AM_RANGE(0x84000000, 0x8400003f) AM_READ( real3d_status_r ) |
| 1777 | 1777 | AM_RANGE(0x88000000, 0x88000007) AM_WRITE( real3d_cmd_w ) |
| r10427 | r10428 | |
| 1788 | 1788 | |
| 1789 | 1789 | AM_RANGE(0xf1000000, 0xf10f7fff) AM_READWRITE( model3_char_r, model3_char_w ) /* character RAM */ |
| 1790 | 1790 | AM_RANGE(0xf10f8000, 0xf10fffff) AM_READWRITE( model3_tile_r, model3_tile_w ) /* tilemaps */ |
| 1791 | | AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE(&paletteram64) /* palette */ |
| 1791 | AM_RANGE(0xf1100000, 0xf111ffff) AM_READWRITE( model3_palette_r, model3_palette_w ) AM_BASE_MEMBER(model3_state, paletteram64) /* palette */ |
| 1792 | 1792 | AM_RANGE(0xf1180000, 0xf11800ff) AM_READWRITE( model3_vid_reg_r, model3_vid_reg_w ) |
| 1793 | 1793 | |
| 1794 | 1794 | AM_RANGE(0xff800000, 0xffffffff) AM_ROM AM_REGION("user1", 0) |
| r10427 | r10428 | |
| 4891 | 4891 | } |
| 4892 | 4892 | |
| 4893 | 4893 | static ADDRESS_MAP_START( model3_snd, ADDRESS_SPACE_PROGRAM, 16 ) |
| 4894 | | AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE(&model3_soundram) |
| 4894 | AM_RANGE(0x000000, 0x07ffff) AM_RAM AM_REGION("scsp1", 0) AM_BASE_MEMBER(model3_state, soundram) |
| 4895 | 4895 | AM_RANGE(0x100000, 0x100fff) AM_DEVREADWRITE("scsp1", scsp_r, scsp_w) |
| 4896 | 4896 | AM_RANGE(0x200000, 0x27ffff) AM_RAM AM_REGION("scsp2", 0) |
| 4897 | 4897 | AM_RANGE(0x300000, 0x300fff) AM_DEVREADWRITE("scsp2", scsp_r, scsp_w) |
| r10427 | r10428 | |
| 4902 | 4902 | AM_RANGE(0xe00000, 0xffffff) AM_ROMBANK("bank5") |
| 4903 | 4903 | ADDRESS_MAP_END |
| 4904 | 4904 | |
| 4905 | | static int scsp_last_line = 0; |
| 4906 | 4905 | |
| 4907 | 4906 | static void scsp_irq(device_t *device, int irq) |
| 4908 | 4907 | { |
| 4908 | model3_state *state = device->machine->driver_data<model3_state>(); |
| 4909 | 4909 | if (irq > 0) |
| 4910 | 4910 | { |
| 4911 | | scsp_last_line = irq; |
| 4911 | state->scsp_last_line = irq; |
| 4912 | 4912 | cputag_set_input_line(device->machine, "audiocpu", irq, ASSERT_LINE); |
| 4913 | 4913 | } |
| 4914 | 4914 | else |
| r10427 | r10428 | |
| 4938 | 4938 | 0x02: Video (VBLANK start?) |
| 4939 | 4939 | 0x01: Video (unused?) |
| 4940 | 4940 | */ |
| 4941 | | static int model3_vblank = 0; |
| 4942 | 4941 | static INTERRUPT_GEN(model3_interrupt) |
| 4943 | 4942 | { |
| 4944 | | if (model3_vblank == 0) { |
| 4943 | model3_state *state = device->machine->driver_data<model3_state>(); |
| 4944 | if (state->vblank == 0) { |
| 4945 | 4945 | model3_set_irq_line(device->machine, 0x02, ASSERT_LINE); |
| 4946 | 4946 | } else { |
| 4947 | 4947 | model3_set_irq_line(device->machine, 0x0d, ASSERT_LINE); |
| 4948 | 4948 | } |
| 4949 | 4949 | |
| 4950 | | model3_vblank++; |
| 4951 | | model3_vblank &= 1; |
| 4950 | state->vblank++; |
| 4951 | state->vblank &= 1; |
| 4952 | 4952 | } |
| 4953 | 4953 | |
| 4954 | 4954 | static const powerpc_config model3_10 = |
| r10427 | r10428 | |
| 4969 | 4969 | 66000000 /* Multiplier 2.5, Bus = 66MHz, Core = 166MHz */ |
| 4970 | 4970 | }; |
| 4971 | 4971 | |
| 4972 | | static MACHINE_CONFIG_START( model3_10, driver_device ) |
| 4972 | static MACHINE_CONFIG_START( model3_10, model3_state ) |
| 4973 | 4973 | MCFG_CPU_ADD("maincpu", PPC603E, 66000000) |
| 4974 | 4974 | MCFG_CPU_CONFIG(model3_10) |
| 4975 | 4975 | MCFG_CPU_PROGRAM_MAP(model3_mem) |
| r10427 | r10428 | |
| 5011 | 5011 | MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) |
| 5012 | 5012 | MACHINE_CONFIG_END |
| 5013 | 5013 | |
| 5014 | | static MACHINE_CONFIG_START( model3_15, driver_device ) |
| 5014 | static MACHINE_CONFIG_START( model3_15, model3_state ) |
| 5015 | 5015 | MCFG_CPU_ADD("maincpu", PPC603E, 100000000) |
| 5016 | 5016 | MCFG_CPU_CONFIG(model3_15) |
| 5017 | 5017 | MCFG_CPU_PROGRAM_MAP(model3_mem) |
| r10427 | r10428 | |
| 5051 | 5051 | MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) |
| 5052 | 5052 | MACHINE_CONFIG_END |
| 5053 | 5053 | |
| 5054 | | static MACHINE_CONFIG_START( model3_20, driver_device ) |
| 5054 | static MACHINE_CONFIG_START( model3_20, model3_state ) |
| 5055 | 5055 | MCFG_CPU_ADD("maincpu", PPC603R, 166000000) |
| 5056 | 5056 | MCFG_CPU_CONFIG(model3_2x) |
| 5057 | 5057 | MCFG_CPU_PROGRAM_MAP(model3_mem) |
| r10427 | r10428 | |
| 5091 | 5091 | MCFG_SOUND_ROUTE(0, "rspeaker", 2.0) |
| 5092 | 5092 | MACHINE_CONFIG_END |
| 5093 | 5093 | |
| 5094 | | static MACHINE_CONFIG_START( model3_21, driver_device ) |
| 5094 | static MACHINE_CONFIG_START( model3_21, model3_state ) |
| 5095 | 5095 | MCFG_CPU_ADD("maincpu", PPC603R, 166000000) |
| 5096 | 5096 | MCFG_CPU_CONFIG(model3_2x) |
| 5097 | 5097 | MCFG_CPU_PROGRAM_MAP(model3_mem) |
| r10427 | r10428 | |
| 5134 | 5134 | |
| 5135 | 5135 | static void interleave_vroms(running_machine *machine) |
| 5136 | 5136 | { |
| 5137 | model3_state *state = machine->driver_data<model3_state>(); |
| 5137 | 5138 | int start; |
| 5138 | 5139 | int i,j,x; |
| 5139 | 5140 | UINT16 *vrom1 = (UINT16*)machine->region("user3")->base(); |
| r10427 | r10428 | |
| 5141 | 5142 | int vrom_length = machine->region("user3")->bytes(); |
| 5142 | 5143 | UINT16 *vrom; |
| 5143 | 5144 | |
| 5144 | | model3_vrom = auto_alloc_array(machine, UINT32, 0x4000000/4); |
| 5145 | | vrom = (UINT16 *)model3_vrom; |
| 5145 | state->vrom = auto_alloc_array(machine, UINT32, 0x4000000/4); |
| 5146 | vrom = (UINT16 *)state->vrom; |
| 5146 | 5147 | |
| 5147 | 5148 | if( vrom_length <= 0x1000000 ) { |
| 5148 | 5149 | start = 0x1000000; |
| r10427 | r10428 | |
| 5397 | 5398 | |
| 5398 | 5399 | static DRIVER_INIT( harley ) |
| 5399 | 5400 | { |
| 5401 | model3_state *state = machine->driver_data<model3_state>(); |
| 5400 | 5402 | UINT32 *rom = (UINT32*)machine->region("user1")->base(); |
| 5401 | 5403 | DRIVER_INIT_CALL(model3_20); |
| 5402 | 5404 | |
| 5405 | state->network_ram = auto_alloc_array_clear(machine, UINT64, 0x10000); |
| 5403 | 5406 | memory_install_readwrite64_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xc0000000, 0xc00fffff, 0, 0, network_r, network_w ); |
| 5404 | 5407 | |
| 5405 | 5408 | rom[(0x50e8d4^4)/4] = 0x60000000; |
src/mame/drivers/cps3.c
| r10427 | r10428 | |
| 337 | 337 | |
| 338 | 338 | #define DMA_XOR(a) ((a) ^ NATIVE_ENDIAN_VALUE_LE_BE(1,2)) |
| 339 | 339 | |
| 340 | | |
| 341 | | static fujitsu_29f016a_device *simm[7][8]; |
| 342 | | |
| 343 | | static UINT32* decrypted_bios; |
| 344 | | |
| 345 | | static UINT32* decrypted_gamerom; |
| 346 | | static UINT32 cram_gfxflash_bank; |
| 347 | | static UINT32* cps3_nops; |
| 348 | | |
| 349 | | static UINT32* tilemap20_regs_base; |
| 350 | | static UINT32* tilemap30_regs_base; |
| 351 | | static UINT32* tilemap40_regs_base; |
| 352 | | static UINT32* tilemap50_regs_base; |
| 353 | | |
| 354 | | static UINT32* cps3_0xc0000000_ram; |
| 355 | | static UINT32* cps3_0xc0000000_ram_decrypted; |
| 356 | | |
| 357 | | static UINT32* cps3_char_ram; |
| 358 | | |
| 359 | | static UINT32* cps3_spriteram; |
| 360 | | static UINT32* cps3_eeprom; |
| 361 | | static UINT32* cps3_fullscreenzoom; |
| 362 | | |
| 363 | | static UINT32 cps3_ss_pal_base = 0; |
| 364 | | static UINT32* cps3_colourram; |
| 365 | | static UINT32 cps3_unk_vidregs[0x20/4]; |
| 366 | | static UINT32 cps3_ss_bank_base = 0; |
| 367 | | |
| 368 | | static UINT32 cps3_screenwidth; |
| 369 | | //cdrom_file* cps3_cd; |
| 370 | | |
| 371 | | static UINT32* cps3_mame_colours;//[0x20000]; // actual values to write to 32-bit bitmap |
| 372 | | |
| 373 | | static bitmap_t *renderbuffer_bitmap; |
| 374 | | static rectangle renderbuffer_clip; |
| 375 | | |
| 376 | | static UINT8* cps3_user4region; |
| 377 | | UINT8* cps3_user5region; |
| 378 | 340 | #define USER4REGION_LENGTH 0x800000*2 |
| 379 | 341 | #define USER5REGION_LENGTH 0x800000*10 |
| 380 | 342 | |
| r10427 | r10428 | |
| 390 | 352 | int transparency,int transparent_color, |
| 391 | 353 | int scalex, int scaley,bitmap_t *pri_buffer,UINT32 pri_mask) |
| 392 | 354 | { |
| 355 | cps3_state *state = gfx->machine->driver_data<cps3_state>(); |
| 393 | 356 | rectangle myclip; |
| 394 | 357 | |
| 395 | 358 | // UINT8 al; |
| r10427 | r10428 | |
| 436 | 399 | { |
| 437 | 400 | // const pen_t *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; |
| 438 | 401 | UINT32 palbase = (gfx->color_granularity * color) & 0x1ffff; |
| 439 | | const pen_t *pal = &cps3_mame_colours[palbase]; |
| 402 | const pen_t *pal = &state->mame_colours[palbase]; |
| 440 | 403 | const UINT8 *source_base = gfx_element_get_data(gfx, code % gfx->total_elements); |
| 441 | 404 | |
| 442 | 405 | int sprite_screen_height = (scaley*gfx->height+0x8000)>>16; |
| r10427 | r10428 | |
| 616 | 579 | |
| 617 | 580 | /* Encryption */ |
| 618 | 581 | |
| 619 | | static UINT32 cps3_key1, cps3_key2; |
| 620 | | static int cps3_altEncryption; // sfiii2 has different encryption, data isn't encrypted outside of the bios |
| 621 | 582 | |
| 622 | 583 | static UINT16 rotate_left(UINT16 value, int n) |
| 623 | 584 | { |
| r10427 | r10428 | |
| 657 | 618 | |
| 658 | 619 | static void cps3_decrypt_bios(running_machine *machine) |
| 659 | 620 | { |
| 621 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 660 | 622 | int i; |
| 661 | 623 | UINT32 *coderegion = (UINT32*)machine->region("user1")->base(); |
| 662 | 624 | |
| 663 | | decrypted_bios = (UINT32*)machine->region("user1")->base(); |
| 625 | state->decrypted_bios = (UINT32*)machine->region("user1")->base(); |
| 664 | 626 | |
| 665 | 627 | for (i=0;i<0x80000;i+=4) |
| 666 | 628 | { |
| 667 | 629 | UINT32 dword = coderegion[i/4]; |
| 668 | | UINT32 xormask = cps3_mask(i, cps3_key1, cps3_key2); |
| 669 | | decrypted_bios[i/4] = dword ^ xormask; |
| 630 | UINT32 xormask = cps3_mask(i, state->key1, state->key2); |
| 631 | state->decrypted_bios[i/4] = dword ^ xormask; |
| 670 | 632 | } |
| 671 | 633 | #if 0 |
| 672 | 634 | /* Dump to file */ |
| r10427 | r10428 | |
| 679 | 641 | fp=fopen(filename, "w+b"); |
| 680 | 642 | if (fp) |
| 681 | 643 | { |
| 682 | | fwrite(decrypted_bios, 0x080000, 1, fp); |
| 644 | fwrite(state->decrypted_bios, 0x080000, 1, fp); |
| 683 | 645 | fclose(fp); |
| 684 | 646 | } |
| 685 | 647 | } |
| r10427 | r10428 | |
| 687 | 649 | } |
| 688 | 650 | |
| 689 | 651 | |
| 690 | | static DRIVER_INIT( cps3 ) |
| 652 | static void init_common(running_machine *machine, UINT32 key1, UINT32 key2, int altEncryption) |
| 691 | 653 | { |
| 654 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 655 | |
| 656 | state->key1 = key1; |
| 657 | state->key2 = key2; |
| 658 | state->altEncryption = altEncryption; |
| 659 | |
| 692 | 660 | // cache pointers to regions |
| 693 | | cps3_user4region = machine->region("user4")->base(); |
| 694 | | cps3_user5region = machine->region("user5")->base(); |
| 661 | state->user4region = machine->region("user4")->base(); |
| 662 | state->user5region = machine->region("user5")->base(); |
| 695 | 663 | |
| 696 | | if (!cps3_user4region) cps3_user4region = auto_alloc_array(machine, UINT8, USER4REGION_LENGTH); |
| 697 | | if (!cps3_user5region) cps3_user5region = auto_alloc_array(machine, UINT8, USER5REGION_LENGTH); |
| 664 | if (!state->user4region) state->user4region = auto_alloc_array(machine, UINT8, USER4REGION_LENGTH); |
| 665 | if (!state->user5region) state->user5region = auto_alloc_array(machine, UINT8, USER5REGION_LENGTH); |
| 698 | 666 | |
| 699 | 667 | // set strict verify |
| 700 | 668 | sh2drc_set_options(machine->device("maincpu"), SH2DRC_STRICT_VERIFY); |
| 701 | 669 | |
| 702 | 670 | cps3_decrypt_bios(machine); |
| 703 | | decrypted_gamerom = auto_alloc_array(machine, UINT32, 0x1000000/4); |
| 671 | state->decrypted_gamerom = auto_alloc_array(machine, UINT32, 0x1000000/4); |
| 704 | 672 | |
| 705 | 673 | /* just some NOPs for the game to execute if it crashes and starts executing unmapped addresses |
| 706 | 674 | - this prevents MAME from crashing */ |
| 707 | | cps3_nops = auto_alloc(machine, UINT32); |
| 708 | | cps3_nops[0] = 0x00090009; |
| 675 | state->nops = auto_alloc(machine, UINT32); |
| 676 | state->nops[0] = 0x00090009; |
| 709 | 677 | |
| 710 | 678 | |
| 711 | | cps3_0xc0000000_ram_decrypted = auto_alloc_array(machine, UINT32, 0x400/4); |
| 679 | state->_0xc0000000_ram_decrypted = auto_alloc_array(machine, UINT32, 0x400/4); |
| 712 | 680 | |
| 713 | 681 | address_space *main = machine->device<sh2_device>("maincpu")->space(AS_PROGRAM); |
| 714 | 682 | main->set_direct_update_handler(direct_update_delegate_create_static(cps3_direct_handler, *machine)); |
| r10427 | r10428 | |
| 717 | 685 | astring tempstr; |
| 718 | 686 | for (int simmnum = 0; simmnum < 7; simmnum++) |
| 719 | 687 | for (int chipnum = 0; chipnum < 8; chipnum++) |
| 720 | | simm[simmnum][chipnum] = machine->device<fujitsu_29f016a_device>(tempstr.format("simm%d.%d", simmnum + 1, chipnum)); |
| 688 | state->simm[simmnum][chipnum] = machine->device<fujitsu_29f016a_device>(tempstr.format("simm%d.%d", simmnum + 1, chipnum)); |
| 721 | 689 | |
| 722 | | cps3_eeprom = auto_alloc_array(machine, UINT32, 0x400/4); |
| 723 | | machine->device<nvram_device>("eeprom")->set_base(cps3_eeprom, 0x400); |
| 690 | state->eeprom = auto_alloc_array(machine, UINT32, 0x400/4); |
| 691 | machine->device<nvram_device>("eeprom")->set_base(state->eeprom, 0x400); |
| 724 | 692 | } |
| 725 | 693 | |
| 726 | | static DRIVER_INIT( jojo ) { cps3_key1 = 0x02203ee3; cps3_key2 = 0x01301972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } |
| 727 | | static DRIVER_INIT( jojoba ) { cps3_key1 = 0x23323ee3; cps3_key2 = 0x03021972; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } |
| 728 | | static DRIVER_INIT( sfiii ) { cps3_key1 = 0xb5fe053e; cps3_key2 = 0xfc03925a; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } |
| 729 | | static DRIVER_INIT( sfiii2 ) { cps3_key1 = 0x00000000; cps3_key2 = 0x00000000; cps3_altEncryption = 1; DRIVER_INIT_CALL(cps3); } |
| 730 | | static DRIVER_INIT( sfiii3 ) { cps3_key1 = 0xa55432b4; cps3_key2 = 0x0c129981; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } |
| 731 | | static DRIVER_INIT( redearth ){ cps3_key1 = 0x9e300ab1; cps3_key2 = 0xa175b82c; cps3_altEncryption = 0; DRIVER_INIT_CALL(cps3); } |
| 694 | static DRIVER_INIT( jojo ) { init_common(machine, 0x02203ee3, 0x01301972, 0); } |
| 695 | static DRIVER_INIT( jojoba ) { init_common(machine, 0x23323ee3, 0x03021972, 0); } |
| 696 | static DRIVER_INIT( sfiii ) { init_common(machine, 0xb5fe053e, 0xfc03925a, 0); } |
| 697 | static DRIVER_INIT( sfiii2 ) { init_common(machine, 0x00000000, 0x00000000, 1); } |
| 698 | static DRIVER_INIT( sfiii3 ) { init_common(machine, 0xa55432b4, 0x0c129981, 0); } |
| 699 | static DRIVER_INIT( redearth ){ init_common(machine, 0x9e300ab1, 0xa175b82c, 0); } |
| 732 | 700 | |
| 733 | 701 | |
| 734 | 702 | /* GFX decodes */ |
| r10427 | r10428 | |
| 760 | 728 | 64*8 |
| 761 | 729 | }; |
| 762 | 730 | |
| 763 | | static UINT32* cps3_ss_ram; |
| 764 | 731 | |
| 765 | | static void cps3_set_mame_colours(running_machine *machine, int colournum, UINT16 data, UINT32 fadeval ) |
| 732 | static void cps3_set_mame_colours(running_machine *machine, int colournum, UINT16 data, UINT32 fadeval) |
| 766 | 733 | { |
| 734 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 767 | 735 | int r,g,b; |
| 768 | | UINT16* dst = (UINT16*)cps3_colourram; |
| 736 | UINT16* dst = (UINT16*)state->colourram; |
| 769 | 737 | |
| 770 | 738 | |
| 771 | 739 | r = (data >> 0) & 0x1f; |
| r10427 | r10428 | |
| 795 | 763 | |
| 796 | 764 | dst[colournum] = data; |
| 797 | 765 | |
| 798 | | cps3_mame_colours[colournum] = (r << (16+3)) | (g << (8+3)) | (b << (0+3)); |
| 766 | state->mame_colours[colournum] = (r << (16+3)) | (g << (8+3)) | (b << (0+3)); |
| 799 | 767 | |
| 800 | | if (colournum<0x10000) palette_set_color(machine,colournum,cps3_mame_colours[colournum]/* MAKE_RGB(r<<3,g<<3,b<<3)*/);//cps3_mame_colours[colournum]); |
| 768 | if (colournum<0x10000) palette_set_color(machine,colournum,state->mame_colours[colournum]/* MAKE_RGB(r<<3,g<<3,b<<3)*/);//state->mame_colours[colournum]); |
| 801 | 769 | } |
| 802 | 770 | |
| 803 | 771 | |
| 804 | 772 | static VIDEO_START(cps3) |
| 805 | 773 | { |
| 806 | | cps3_ss_ram = auto_alloc_array(machine, UINT32, 0x10000/4); |
| 807 | | memset(cps3_ss_ram, 0x00, 0x10000); |
| 808 | | state_save_register_global_pointer(machine, cps3_ss_ram, 0x10000/4); |
| 774 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 775 | state->ss_ram = auto_alloc_array(machine, UINT32, 0x10000/4); |
| 776 | memset(state->ss_ram, 0x00, 0x10000); |
| 777 | state_save_register_global_pointer(machine, state->ss_ram, 0x10000/4); |
| 809 | 778 | |
| 810 | | cps3_char_ram = auto_alloc_array(machine, UINT32, 0x800000/4); |
| 811 | | memset(cps3_char_ram, 0x00, 0x800000); |
| 812 | | state_save_register_global_pointer(machine, cps3_char_ram, 0x800000 /4); |
| 779 | state->char_ram = auto_alloc_array(machine, UINT32, 0x800000/4); |
| 780 | memset(state->char_ram, 0x00, 0x800000); |
| 781 | state_save_register_global_pointer(machine, state->char_ram, 0x800000 /4); |
| 813 | 782 | |
| 814 | 783 | /* create the char set (gfx will then be updated dynamically from RAM) */ |
| 815 | | machine->gfx[0] = gfx_element_alloc(machine, &cps3_tiles8x8_layout, (UINT8 *)cps3_ss_ram, machine->total_colors() / 16, 0); |
| 784 | machine->gfx[0] = gfx_element_alloc(machine, &cps3_tiles8x8_layout, (UINT8 *)state->ss_ram, machine->total_colors() / 16, 0); |
| 816 | 785 | |
| 817 | 786 | //decode_ssram(); |
| 818 | 787 | |
| 819 | 788 | /* create the char set (gfx will then be updated dynamically from RAM) */ |
| 820 | | machine->gfx[1] = gfx_element_alloc(machine, &cps3_tiles16x16_layout, (UINT8 *)cps3_char_ram, machine->total_colors() / 64, 0); |
| 789 | machine->gfx[1] = gfx_element_alloc(machine, &cps3_tiles16x16_layout, (UINT8 *)state->char_ram, machine->total_colors() / 64, 0); |
| 821 | 790 | machine->gfx[1]->color_granularity = 64; |
| 822 | 791 | |
| 823 | 792 | //decode_charram(); |
| 824 | 793 | |
| 825 | | cps3_mame_colours = auto_alloc_array(machine, UINT32, 0x80000/4); |
| 826 | | memset(cps3_mame_colours, 0x00, 0x80000); |
| 794 | state->mame_colours = auto_alloc_array(machine, UINT32, 0x80000/4); |
| 795 | memset(state->mame_colours, 0x00, 0x80000); |
| 827 | 796 | |
| 828 | | cps3_screenwidth = 384; |
| 797 | state->screenwidth = 384; |
| 829 | 798 | |
| 830 | 799 | // the renderbuffer can be twice the size of the screen, this allows us to handle framebuffer zoom values |
| 831 | 800 | // between 0x00 and 0x80 (0x40 is normal, 0x80 would be 'view twice as much', 0x20 is 'view half as much') |
| 832 | | renderbuffer_bitmap = auto_bitmap_alloc(machine,512*2,224*2,machine->primary_screen->format()); |
| 801 | state->renderbuffer_bitmap = auto_bitmap_alloc(machine,512*2,224*2,machine->primary_screen->format()); |
| 833 | 802 | |
| 834 | | renderbuffer_clip.min_x = 0; |
| 835 | | renderbuffer_clip.max_x = cps3_screenwidth-1; |
| 836 | | renderbuffer_clip.min_y = 0; |
| 837 | | renderbuffer_clip.max_y = 224-1; |
| 803 | state->renderbuffer_clip.min_x = 0; |
| 804 | state->renderbuffer_clip.max_x = state->screenwidth-1; |
| 805 | state->renderbuffer_clip.min_y = 0; |
| 806 | state->renderbuffer_clip.max_y = 224-1; |
| 838 | 807 | |
| 839 | | bitmap_fill(renderbuffer_bitmap,&renderbuffer_clip,0x3f); |
| 808 | bitmap_fill(state->renderbuffer_bitmap,&state->renderbuffer_clip,0x3f); |
| 840 | 809 | |
| 841 | 810 | } |
| 842 | 811 | |
| r10427 | r10428 | |
| 844 | 813 | |
| 845 | 814 | static void cps3_draw_tilemapsprite_line(running_machine *machine, int tmnum, int drawline, bitmap_t *bitmap, const rectangle *cliprect ) |
| 846 | 815 | { |
| 847 | | UINT32* tmapregs[4] = { tilemap20_regs_base, tilemap30_regs_base, tilemap40_regs_base, tilemap50_regs_base }; |
| 816 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 817 | UINT32* tmapregs[4] = { state->tilemap20_regs_base, state->tilemap30_regs_base, state->tilemap40_regs_base, state->tilemap50_regs_base }; |
| 848 | 818 | UINT32* regs; |
| 849 | 819 | int line; |
| 850 | 820 | int scrolly; |
| r10427 | r10428 | |
| 885 | 855 | // printf("linebase %08x\n", linebase); |
| 886 | 856 | |
| 887 | 857 | scrollx = (regs[0]&0xffff0000)>>16; |
| 888 | | scrollx+= (cps3_spriteram[linebase+((line+16-4)&0x3ff)]>>16)&0x3ff; |
| 858 | scrollx+= (state->spriteram[linebase+((line+16-4)&0x3ff)]>>16)&0x3ff; |
| 889 | 859 | |
| 890 | 860 | } |
| 891 | 861 | |
| r10427 | r10428 | |
| 909 | 879 | int bpp; |
| 910 | 880 | int xflip,yflip; |
| 911 | 881 | |
| 912 | | dat = cps3_spriteram[mapbase+((tileline&63)*64)+((x+scrollx/16)&63)]; |
| 882 | dat = state->spriteram[mapbase+((tileline&63)*64)+((x+scrollx/16)&63)]; |
| 913 | 883 | tileno = (dat & 0xffff0000)>>17; |
| 914 | 884 | colour = (dat & 0x000001ff)>>0; |
| 915 | 885 | bpp = (dat & 0x0000200)>>9; |
| r10427 | r10428 | |
| 926 | 896 | |
| 927 | 897 | static VIDEO_UPDATE(cps3) |
| 928 | 898 | { |
| 899 | cps3_state *state = screen->machine->driver_data<cps3_state>(); |
| 929 | 900 | int y,x, count; |
| 930 | 901 | attoseconds_t period = screen->frame_period().attoseconds; |
| 931 | 902 | rectangle visarea = screen->visible_area(); |
| r10427 | r10428 | |
| 941 | 912 | /* registers are normally 002a006f 01ef01c6 |
| 942 | 913 | widescreen mode = 00230076 026501c6 |
| 943 | 914 | only SFIII2 uses widescreen, I don't know exactly which register controls it */ |
| 944 | | if (((cps3_fullscreenzoom[1]&0xffff0000)>>16)==0x0265) |
| 915 | if (((state->fullscreenzoom[1]&0xffff0000)>>16)==0x0265) |
| 945 | 916 | { |
| 946 | | if (cps3_screenwidth!=496) |
| 917 | if (state->screenwidth!=496) |
| 947 | 918 | { |
| 948 | | cps3_screenwidth = 496; |
| 919 | state->screenwidth = 496; |
| 949 | 920 | visarea.min_x = 0; visarea.max_x = 496-1; |
| 950 | 921 | visarea.min_y = 0; visarea.max_y = 224-1; |
| 951 | 922 | screen->configure(496, 224, visarea, period); |
| r10427 | r10428 | |
| 953 | 924 | } |
| 954 | 925 | else |
| 955 | 926 | { |
| 956 | | if (cps3_screenwidth!=384) |
| 927 | if (state->screenwidth!=384) |
| 957 | 928 | { |
| 958 | | cps3_screenwidth = 384; |
| 929 | state->screenwidth = 384; |
| 959 | 930 | visarea.min_x = 0; visarea.max_x = 384-1; |
| 960 | 931 | visarea.min_y = 0; visarea.max_y = 224-1; |
| 961 | 932 | screen->configure(384, 224, visarea, period); |
| 962 | 933 | } |
| 963 | 934 | } |
| 964 | 935 | |
| 965 | | fullscreenzoomx = cps3_fullscreenzoom[3] & 0x000000ff; |
| 966 | | fullscreenzoomy = cps3_fullscreenzoom[3] & 0x000000ff; |
| 936 | fullscreenzoomx = state->fullscreenzoom[3] & 0x000000ff; |
| 937 | fullscreenzoomy = state->fullscreenzoom[3] & 0x000000ff; |
| 967 | 938 | /* clamp at 0x80, I don't know if this is accurate */ |
| 968 | 939 | if (fullscreenzoomx>0x80) fullscreenzoomx = 0x80; |
| 969 | 940 | if (fullscreenzoomy>0x80) fullscreenzoomy = 0x80; |
| r10427 | r10428 | |
| 971 | 942 | fszx = (fullscreenzoomx<<16)/0x40; |
| 972 | 943 | fszy = (fullscreenzoomy<<16)/0x40; |
| 973 | 944 | |
| 974 | | renderbuffer_clip.min_x = 0; |
| 975 | | renderbuffer_clip.max_x = ((cps3_screenwidth*fszx)>>16)-1; |
| 976 | | renderbuffer_clip.min_y = 0; |
| 977 | | renderbuffer_clip.max_y = ((224*fszx)>>16)-1; |
| 945 | state->renderbuffer_clip.min_x = 0; |
| 946 | state->renderbuffer_clip.max_x = ((state->screenwidth*fszx)>>16)-1; |
| 947 | state->renderbuffer_clip.min_y = 0; |
| 948 | state->renderbuffer_clip.max_y = ((224*fszx)>>16)-1; |
| 978 | 949 | |
| 979 | | bitmap_fill(renderbuffer_bitmap,&renderbuffer_clip,0); |
| 950 | bitmap_fill(state->renderbuffer_bitmap,&state->renderbuffer_clip,0); |
| 980 | 951 | |
| 981 | 952 | /* Sprites */ |
| 982 | 953 | { |
| r10427 | r10428 | |
| 985 | 956 | //printf("Spritelist start:\n"); |
| 986 | 957 | for (i=0x00000/4;i<0x2000/4;i+=4) |
| 987 | 958 | { |
| 988 | | int xpos = (cps3_spriteram[i+1]&0x03ff0000)>>16; |
| 989 | | int ypos = cps3_spriteram[i+1]&0x000003ff; |
| 959 | int xpos = (state->spriteram[i+1]&0x03ff0000)>>16; |
| 960 | int ypos = state->spriteram[i+1]&0x000003ff; |
| 990 | 961 | int j; |
| 991 | | int gscroll = (cps3_spriteram[i+0]&0x70000000)>>28; |
| 992 | | int length = (cps3_spriteram[i+0]&0x01ff0000)>>16; // how many entries in the sprite table |
| 993 | | UINT32 start = (cps3_spriteram[i+0]&0x00007ff0)>>4; |
| 962 | int gscroll = (state->spriteram[i+0]&0x70000000)>>28; |
| 963 | int length = (state->spriteram[i+0]&0x01ff0000)>>16; // how many entries in the sprite table |
| 964 | UINT32 start = (state->spriteram[i+0]&0x00007ff0)>>4; |
| 994 | 965 | |
| 995 | | int whichbpp = (cps3_spriteram[i+2]&0x40000000)>>30; // not 100% sure if this is right, jojo title / characters |
| 996 | | int whichpal = (cps3_spriteram[i+2]&0x20000000)>>29; |
| 997 | | int global_xflip = (cps3_spriteram[i+2]&0x10000000)>>28; |
| 998 | | int global_yflip = (cps3_spriteram[i+2]&0x08000000)>>27; |
| 999 | | int global_alpha = (cps3_spriteram[i+2]&0x04000000)>>26; // alpha / shadow? set on sfiii2 shadows, and big black image in jojo intro |
| 1000 | | int global_bpp = (cps3_spriteram[i+2]&0x02000000)>>25; |
| 1001 | | int global_pal = (cps3_spriteram[i+2]&0x01ff0000)>>16; |
| 966 | int whichbpp = (state->spriteram[i+2]&0x40000000)>>30; // not 100% sure if this is right, jojo title / characters |
| 967 | int whichpal = (state->spriteram[i+2]&0x20000000)>>29; |
| 968 | int global_xflip = (state->spriteram[i+2]&0x10000000)>>28; |
| 969 | int global_yflip = (state->spriteram[i+2]&0x08000000)>>27; |
| 970 | int global_alpha = (state->spriteram[i+2]&0x04000000)>>26; // alpha / shadow? set on sfiii2 shadows, and big black image in jojo intro |
| 971 | int global_bpp = (state->spriteram[i+2]&0x02000000)>>25; |
| 972 | int global_pal = (state->spriteram[i+2]&0x01ff0000)>>16; |
| 1002 | 973 | |
| 1003 | | int gscrollx = (cps3_unk_vidregs[gscroll]&0x03ff0000)>>16; |
| 1004 | | int gscrolly = (cps3_unk_vidregs[gscroll]&0x000003ff)>>0; |
| 974 | int gscrollx = (state->unk_vidregs[gscroll]&0x03ff0000)>>16; |
| 975 | int gscrolly = (state->unk_vidregs[gscroll]&0x000003ff)>>0; |
| 1005 | 976 | start = (start * 0x100) >> 2; |
| 1006 | 977 | |
| 1007 | | if ((cps3_spriteram[i+0]&0xf0000000) == 0x80000000) |
| 978 | if ((state->spriteram[i+0]&0xf0000000) == 0x80000000) |
| 1008 | 979 | break; |
| 1009 | 980 | |
| 1010 | 981 | for (j=0;j<(length)*4;j+=4) |
| 1011 | 982 | { |
| 1012 | 983 | |
| 1013 | | UINT32 value1 = (cps3_spriteram[start+j+0]); |
| 1014 | | UINT32 value2 = (cps3_spriteram[start+j+1]); |
| 1015 | | UINT32 value3 = (cps3_spriteram[start+j+2]); |
| 984 | UINT32 value1 = (state->spriteram[start+j+0]); |
| 985 | UINT32 value2 = (state->spriteram[start+j+1]); |
| 986 | UINT32 value3 = (state->spriteram[start+j+2]); |
| 1016 | 987 | |
| 1017 | 988 | |
| 1018 | | //UINT8* srcdata = (UINT8*)cps3_char_ram; |
| 989 | //UINT8* srcdata = (UINT8*)state->char_ram; |
| 1019 | 990 | //UINT32 sourceoffset = (value1 >>14)&0x7fffff; |
| 1020 | 991 | int count; |
| 1021 | 992 | |
| r10427 | r10428 | |
| 1053 | 1024 | //int endline; |
| 1054 | 1025 | //int height = (value3 & 0x7f000000)>>24; |
| 1055 | 1026 | int uu; |
| 1056 | | UINT32* tmapregs[4] = { tilemap20_regs_base, tilemap30_regs_base, tilemap40_regs_base, tilemap50_regs_base }; |
| 1027 | UINT32* tmapregs[4] = { state->tilemap20_regs_base, state->tilemap30_regs_base, state->tilemap40_regs_base, state->tilemap50_regs_base }; |
| 1057 | 1028 | UINT32* regs; |
| 1058 | 1029 | regs = tmapregs[tilemapnum]; |
| 1059 | 1030 | //endline = value2; |
| r10427 | r10428 | |
| 1075 | 1046 | { |
| 1076 | 1047 | for (uu=0;uu<1023;uu++) |
| 1077 | 1048 | { |
| 1078 | | cps3_draw_tilemapsprite_line(screen->machine, tilemapnum, uu, renderbuffer_bitmap, &renderbuffer_clip ); |
| 1049 | cps3_draw_tilemapsprite_line(screen->machine, tilemapnum, uu, state->renderbuffer_bitmap, &state->renderbuffer_clip ); |
| 1079 | 1050 | } |
| 1080 | 1051 | } |
| 1081 | 1052 | bg_drawn[tilemapnum] = 1; |
| r10427 | r10428 | |
| 1162 | 1133 | |
| 1163 | 1134 | if (global_alpha || alpha) |
| 1164 | 1135 | { |
| 1165 | | cps3_drawgfxzoom(renderbuffer_bitmap,&renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX_BLEND,0,xinc,yinc, NULL, 0); |
| 1136 | cps3_drawgfxzoom(state->renderbuffer_bitmap,&state->renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX_BLEND,0,xinc,yinc, NULL, 0); |
| 1166 | 1137 | } |
| 1167 | 1138 | else |
| 1168 | 1139 | { |
| 1169 | | cps3_drawgfxzoom(renderbuffer_bitmap,&renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX,0,xinc,yinc, NULL, 0); |
| 1140 | cps3_drawgfxzoom(state->renderbuffer_bitmap,&state->renderbuffer_clip,screen->machine->gfx[1],realtileno,actualpal,0^flipx,0^flipy,current_xpos,current_ypos,CPS3_TRANSPARENCY_PEN_INDEX,0,xinc,yinc, NULL, 0); |
| 1170 | 1141 | } |
| 1171 | 1142 | count++; |
| 1172 | 1143 | } |
| r10427 | r10428 | |
| 1193 | 1164 | for (rendery=0;rendery<224;rendery++) |
| 1194 | 1165 | { |
| 1195 | 1166 | dstbitmap = BITMAP_ADDR32(bitmap, rendery, 0); |
| 1196 | | srcbitmap = BITMAP_ADDR32(renderbuffer_bitmap, srcy>>16, 0); |
| 1167 | srcbitmap = BITMAP_ADDR32(state->renderbuffer_bitmap, srcy>>16, 0); |
| 1197 | 1168 | srcx=0; |
| 1198 | 1169 | |
| 1199 | | for (renderx=0;renderx<cps3_screenwidth;renderx++) |
| 1170 | for (renderx=0;renderx<state->screenwidth;renderx++) |
| 1200 | 1171 | { |
| 1201 | | dstbitmap[renderx] = cps3_mame_colours[srcbitmap[srcx>>16]&0x1ffff]; |
| 1172 | dstbitmap[renderx] = state->mame_colours[srcbitmap[srcx>>16]&0x1ffff]; |
| 1202 | 1173 | srcx += fszx; |
| 1203 | 1174 | } |
| 1204 | 1175 | |
| r10427 | r10428 | |
| 1210 | 1181 | /* Copy the first 0x800 colours to be used for fg layer rendering */ |
| 1211 | 1182 | // for (offset=0;offset<0x200;offset++) |
| 1212 | 1183 | // { |
| 1213 | | // int palreadbase = (cps3_ss_pal_base << 9); |
| 1214 | | // palette_set_color(machine,offset,cps3_mame_colours[palreadbase+offset]); |
| 1184 | // int palreadbase = (state->ss_pal_base << 9); |
| 1185 | // palette_set_color(machine,offset,state->mame_colours[palreadbase+offset]); |
| 1215 | 1186 | // } |
| 1216 | 1187 | |
| 1217 | 1188 | // fg layer |
| 1218 | 1189 | { |
| 1219 | 1190 | // bank select? (sfiii2 intro) |
| 1220 | | if (cps3_ss_bank_base & 0x01000000) count = 0x000; |
| 1191 | if (state->ss_bank_base & 0x01000000) count = 0x000; |
| 1221 | 1192 | else count = 0x800; |
| 1222 | 1193 | |
| 1223 | 1194 | for (y=0;y<32;y++) |
| 1224 | 1195 | { |
| 1225 | 1196 | for (x=0;x<64;x++) |
| 1226 | 1197 | { |
| 1227 | | UINT32 data = cps3_ss_ram[count]; // +0x800 = 2nd bank, used on sfiii2 intro.. |
| 1198 | UINT32 data = state->ss_ram[count]; // +0x800 = 2nd bank, used on sfiii2 intro.. |
| 1228 | 1199 | UINT32 tile = (data >> 16) & 0x1ff; |
| 1229 | 1200 | int pal = (data&0x003f) >> 1; |
| 1230 | 1201 | int flipx = (data & 0x0080) >> 7; |
| 1231 | 1202 | int flipy = (data & 0x0040) >> 6; |
| 1232 | | pal += cps3_ss_pal_base << 5; |
| 1203 | pal += state->ss_pal_base << 5; |
| 1233 | 1204 | tile+=0x200; |
| 1234 | 1205 | |
| 1235 | 1206 | cps3_drawgfxzoom(bitmap, cliprect, screen->machine->gfx[0],tile,pal,flipx,flipy,x*8,y*8,CPS3_TRANSPARENCY_PEN,0,0x10000,0x10000,NULL,0); |
| r10427 | r10428 | |
| 1242 | 1213 | |
| 1243 | 1214 | static READ32_HANDLER( cps3_ssram_r ) |
| 1244 | 1215 | { |
| 1216 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1245 | 1217 | if (offset>0x8000/4) |
| 1246 | | return LITTLE_ENDIANIZE_INT32(cps3_ss_ram[offset]); |
| 1218 | return LITTLE_ENDIANIZE_INT32(state->ss_ram[offset]); |
| 1247 | 1219 | else |
| 1248 | | return cps3_ss_ram[offset]; |
| 1220 | return state->ss_ram[offset]; |
| 1249 | 1221 | } |
| 1250 | 1222 | |
| 1251 | 1223 | static WRITE32_HANDLER( cps3_ssram_w ) |
| 1252 | 1224 | { |
| 1225 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1253 | 1226 | if (offset>0x8000/4) |
| 1254 | 1227 | { |
| 1255 | 1228 | // we only want to endian-flip the character data, the tilemap info is fine |
| r10427 | r10428 | |
| 1258 | 1231 | gfx_element_mark_dirty(space->machine->gfx[0], offset/16); |
| 1259 | 1232 | } |
| 1260 | 1233 | |
| 1261 | | COMBINE_DATA(&cps3_ss_ram[offset]); |
| 1234 | COMBINE_DATA(&state->ss_ram[offset]); |
| 1262 | 1235 | } |
| 1263 | 1236 | |
| 1264 | 1237 | static WRITE32_HANDLER( cps3_0xc0000000_ram_w ) |
| 1265 | 1238 | { |
| 1266 | | COMBINE_DATA( &cps3_0xc0000000_ram[offset] ); |
| 1239 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1240 | COMBINE_DATA( &state->_0xc0000000_ram[offset] ); |
| 1267 | 1241 | // store a decrypted copy |
| 1268 | | cps3_0xc0000000_ram_decrypted[offset] = cps3_0xc0000000_ram[offset]^cps3_mask(offset*4+0xc0000000, cps3_key1, cps3_key2); |
| 1242 | state->_0xc0000000_ram_decrypted[offset] = state->_0xc0000000_ram[offset]^cps3_mask(offset*4+0xc0000000, state->key1, state->key2); |
| 1269 | 1243 | } |
| 1270 | 1244 | |
| 1271 | 1245 | |
| 1272 | 1246 | |
| 1273 | 1247 | DIRECT_UPDATE_HANDLER( cps3_direct_handler ) |
| 1274 | 1248 | { |
| 1249 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1275 | 1250 | // if(DEBUG_PRINTF) printf("address %04x\n",address); |
| 1276 | 1251 | |
| 1277 | 1252 | /* BIOS ROM */ |
| r10427 | r10428 | |
| 1283 | 1258 | /* RAM */ |
| 1284 | 1259 | else if (address >= 0x06000000 && address <= 0x06ffffff) |
| 1285 | 1260 | { |
| 1286 | | UINT8 *decrypted = (UINT8*)decrypted_gamerom; |
| 1261 | UINT8 *decrypted = (UINT8*)state->decrypted_gamerom; |
| 1287 | 1262 | UINT8 *raw = decrypted; |
| 1288 | 1263 | |
| 1289 | | if (cps3_altEncryption) raw = (UINT8*) cps3_user4region; |
| 1264 | if (state->altEncryption) raw = (UINT8*) state->user4region; |
| 1290 | 1265 | |
| 1291 | 1266 | direct.explicit_configure(0x06000000, 0x06ffffff, 0x00ffffff, raw, decrypted); |
| 1292 | 1267 | |
| r10427 | r10428 | |
| 1294 | 1269 | } |
| 1295 | 1270 | else if (address >= 0xc0000000 && address <= 0xc00003ff) |
| 1296 | 1271 | { |
| 1297 | | //direct->decrypted = (void*)cps3_0xc0000000_ram_decrypted; |
| 1298 | | direct.explicit_configure(0xc0000000, 0xc00003ff, 0x3ff, (UINT8*)cps3_0xc0000000_ram, (UINT8*)cps3_0xc0000000_ram_decrypted); |
| 1272 | //direct->decrypted = (void*)state->_0xc0000000_ram_decrypted; |
| 1273 | direct.explicit_configure(0xc0000000, 0xc00003ff, 0x3ff, (UINT8*)state->_0xc0000000_ram, (UINT8*)state->_0xc0000000_ram_decrypted); |
| 1299 | 1274 | return ~0; |
| 1300 | 1275 | } |
| 1301 | 1276 | |
| 1302 | 1277 | /* anything else falls through to NOPs */ |
| 1303 | | direct.explicit_configure(address, address, 0, (UINT8*)cps3_nops, (UINT8*)cps3_nops); |
| 1278 | direct.explicit_configure(address, address, 0, (UINT8*)state->nops, (UINT8*)state->nops); |
| 1304 | 1279 | return ~0; |
| 1305 | 1280 | } |
| 1306 | 1281 | |
| 1307 | | static UINT32 cram_bank = 0; |
| 1308 | 1282 | |
| 1309 | 1283 | static WRITE32_HANDLER( cram_bank_w ) |
| 1310 | 1284 | { |
| 1285 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1311 | 1286 | if (ACCESSING_BITS_0_7) |
| 1312 | 1287 | { |
| 1313 | 1288 | // this seems to be related to accesses to the 0x04100000 region |
| 1314 | | if (cram_bank != data) |
| 1289 | if (state->cram_bank != data) |
| 1315 | 1290 | { |
| 1316 | | cram_bank = data; |
| 1291 | state->cram_bank = data; |
| 1317 | 1292 | //if(data&0xfffffff0) |
| 1318 | 1293 | //bank_w 00000000, ffff0000 |
| 1319 | 1294 | //bank_w 00000001, ffff0000 |
| r10427 | r10428 | |
| 1337 | 1312 | |
| 1338 | 1313 | static READ32_HANDLER( cram_data_r ) |
| 1339 | 1314 | { |
| 1340 | | UINT32 fulloffset = (((cram_bank&0x7)*0x100000)/4) + offset; |
| 1315 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1316 | UINT32 fulloffset = (((state->cram_bank&0x7)*0x100000)/4) + offset; |
| 1341 | 1317 | |
| 1342 | | return LITTLE_ENDIANIZE_INT32(cps3_char_ram[fulloffset]); |
| 1318 | return LITTLE_ENDIANIZE_INT32(state->char_ram[fulloffset]); |
| 1343 | 1319 | } |
| 1344 | 1320 | |
| 1345 | 1321 | static WRITE32_HANDLER( cram_data_w ) |
| 1346 | 1322 | { |
| 1347 | | UINT32 fulloffset = (((cram_bank&0x7)*0x100000)/4) + offset; |
| 1323 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1324 | UINT32 fulloffset = (((state->cram_bank&0x7)*0x100000)/4) + offset; |
| 1348 | 1325 | mem_mask = LITTLE_ENDIANIZE_INT32(mem_mask); |
| 1349 | 1326 | data = LITTLE_ENDIANIZE_INT32(data); |
| 1350 | | COMBINE_DATA(&cps3_char_ram[fulloffset]); |
| 1327 | COMBINE_DATA(&state->char_ram[fulloffset]); |
| 1351 | 1328 | gfx_element_mark_dirty(space->machine->gfx[1], fulloffset/0x40); |
| 1352 | 1329 | } |
| 1353 | 1330 | |
| r10427 | r10428 | |
| 1355 | 1332 | |
| 1356 | 1333 | static READ32_HANDLER( cps3_gfxflash_r ) |
| 1357 | 1334 | { |
| 1335 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1358 | 1336 | UINT32 result = 0; |
| 1359 | | if (cram_gfxflash_bank&1) offset += 0x200000/4; |
| 1337 | if (state->cram_gfxflash_bank&1) offset += 0x200000/4; |
| 1360 | 1338 | |
| 1361 | | fujitsu_29f016a_device *chip0 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) & ~1]; |
| 1362 | | fujitsu_29f016a_device *chip1 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) | 1]; |
| 1339 | fujitsu_29f016a_device *chip0 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) & ~1]; |
| 1340 | fujitsu_29f016a_device *chip1 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) | 1]; |
| 1363 | 1341 | if (chip0 == NULL || chip1 == NULL) |
| 1364 | 1342 | return 0xffffffff; |
| 1365 | 1343 | |
| r10427 | r10428 | |
| 1386 | 1364 | result |= chip1->read( (offset<<1)+0x1 ) << 0; |
| 1387 | 1365 | } |
| 1388 | 1366 | |
| 1389 | | //printf("read GFX flash chips addr %02x returning %08x mem_mask %08x crambank %08x gfxbank %08x\n", offset*2, result,mem_mask, cram_bank, cram_gfxflash_bank ); |
| 1367 | //printf("read GFX flash chips addr %02x returning %08x mem_mask %08x crambank %08x gfxbank %08x\n", offset*2, result,mem_mask, state->cram_bank, state->cram_gfxflash_bank ); |
| 1390 | 1368 | |
| 1391 | 1369 | return result; |
| 1392 | 1370 | } |
| 1393 | 1371 | |
| 1394 | 1372 | static WRITE32_HANDLER( cps3_gfxflash_w ) |
| 1395 | 1373 | { |
| 1374 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1396 | 1375 | int command; |
| 1397 | | if (cram_gfxflash_bank&1) offset += 0x200000/4; |
| 1376 | if (state->cram_gfxflash_bank&1) offset += 0x200000/4; |
| 1398 | 1377 | |
| 1399 | | fujitsu_29f016a_device *chip0 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) & ~1]; |
| 1400 | | fujitsu_29f016a_device *chip1 = simm[2 + cram_gfxflash_bank/8][(cram_gfxflash_bank % 8) | 1]; |
| 1378 | fujitsu_29f016a_device *chip0 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) & ~1]; |
| 1379 | fujitsu_29f016a_device *chip1 = state->simm[2 + state->cram_gfxflash_bank/8][(state->cram_gfxflash_bank % 8) | 1]; |
| 1401 | 1380 | if (chip0 == NULL || chip1 == NULL) |
| 1402 | 1381 | return; |
| 1403 | 1382 | |
| r10427 | r10428 | |
| 1431 | 1410 | |
| 1432 | 1411 | /* make a copy in the linear memory region we actually use for drawing etc. having it stored in interleaved flash roms isnt' very useful */ |
| 1433 | 1412 | { |
| 1434 | | UINT32* romdata = (UINT32*)cps3_user5region; |
| 1413 | UINT32* romdata = (UINT32*)state->user5region; |
| 1435 | 1414 | int real_offset = 0; |
| 1436 | 1415 | UINT32 newdata; |
| 1437 | 1416 | |
| 1438 | | real_offset = ((cram_gfxflash_bank&0x3e) * 0x200000) + offset*4; |
| 1417 | real_offset = ((state->cram_gfxflash_bank&0x3e) * 0x200000) + offset*4; |
| 1439 | 1418 | |
| 1440 | 1419 | newdata =((chip0->read_raw(((offset*2)&0xfffffffe)+0)<<8) | |
| 1441 | 1420 | (chip0->read_raw(((offset*2)&0xfffffffe)+1)<<24) | |
| r10427 | r10428 | |
| 1449 | 1428 | |
| 1450 | 1429 | |
| 1451 | 1430 | |
| 1452 | | static UINT32 cps3_flashmain_r(int which, UINT32 offset, UINT32 mem_mask) |
| 1431 | static UINT32 cps3_flashmain_r(address_space *space, int which, UINT32 offset, UINT32 mem_mask) |
| 1453 | 1432 | { |
| 1433 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1454 | 1434 | UINT32 result = 0; |
| 1455 | 1435 | |
| 1456 | | if (simm[which][0] == NULL || simm[which][1] == NULL || simm[which][2] == NULL || simm[which][3] == NULL) |
| 1436 | if (state->simm[which][0] == NULL || state->simm[which][1] == NULL || state->simm[which][2] == NULL || state->simm[which][3] == NULL) |
| 1457 | 1437 | return 0xffffffff; |
| 1458 | 1438 | |
| 1459 | 1439 | if (ACCESSING_BITS_24_31) // Flash 1 |
| 1460 | 1440 | { |
| 1461 | 1441 | // logerror("read flash chip %d addr %02x\n", base+0, offset*4 ); |
| 1462 | | result |= (simm[which][0]->read(offset)<<24); |
| 1442 | result |= (state->simm[which][0]->read(offset)<<24); |
| 1463 | 1443 | } |
| 1464 | 1444 | if (ACCESSING_BITS_16_23) // Flash 1 |
| 1465 | 1445 | { |
| 1466 | 1446 | // logerror("read flash chip %d addr %02x\n", base+1, offset*4 ); |
| 1467 | | result |= (simm[which][1]->read(offset)<<16); |
| 1447 | result |= (state->simm[which][1]->read(offset)<<16); |
| 1468 | 1448 | } |
| 1469 | 1449 | if (ACCESSING_BITS_8_15) // Flash 1 |
| 1470 | 1450 | { |
| 1471 | 1451 | // logerror("read flash chip %d addr %02x\n", base+2, offset*4 ); |
| 1472 | | result |= (simm[which][2]->read(offset)<<8); |
| 1452 | result |= (state->simm[which][2]->read(offset)<<8); |
| 1473 | 1453 | } |
| 1474 | 1454 | if (ACCESSING_BITS_0_7) // Flash 1 |
| 1475 | 1455 | { |
| 1476 | 1456 | // logerror("read flash chip %d addr %02x\n", base+3, offset*4 ); |
| 1477 | | result |= (simm[which][3]->read(offset)<<0); |
| 1457 | result |= (state->simm[which][3]->read(offset)<<0); |
| 1478 | 1458 | } |
| 1479 | 1459 | |
| 1480 | 1460 | // if (base==4) logerror("read flash chips addr %02x returning %08x\n", offset*4, result ); |
| r10427 | r10428 | |
| 1486 | 1466 | |
| 1487 | 1467 | static READ32_HANDLER( cps3_flash1_r ) |
| 1488 | 1468 | { |
| 1489 | | UINT32 retvalue = cps3_flashmain_r(0, offset,mem_mask); |
| 1469 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1470 | UINT32 retvalue = cps3_flashmain_r(space, 0, offset,mem_mask); |
| 1490 | 1471 | |
| 1491 | | if (cps3_altEncryption) return retvalue; |
| 1472 | if (state->altEncryption) return retvalue; |
| 1492 | 1473 | |
| 1493 | | retvalue = retvalue ^ cps3_mask(0x6000000+offset*4, cps3_key1, cps3_key2); |
| 1474 | retvalue = retvalue ^ cps3_mask(0x6000000+offset*4, state->key1, state->key2); |
| 1494 | 1475 | return retvalue; |
| 1495 | 1476 | } |
| 1496 | 1477 | |
| 1497 | 1478 | static READ32_HANDLER( cps3_flash2_r ) |
| 1498 | 1479 | { |
| 1499 | | UINT32 retvalue = cps3_flashmain_r(1, offset,mem_mask); |
| 1480 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1481 | UINT32 retvalue = cps3_flashmain_r(space, 1, offset,mem_mask); |
| 1500 | 1482 | |
| 1501 | | if (cps3_altEncryption) return retvalue; |
| 1483 | if (state->altEncryption) return retvalue; |
| 1502 | 1484 | |
| 1503 | | retvalue = retvalue ^ cps3_mask(0x6800000+offset*4, cps3_key1, cps3_key2); |
| 1485 | retvalue = retvalue ^ cps3_mask(0x6800000+offset*4, state->key1, state->key2); |
| 1504 | 1486 | return retvalue; |
| 1505 | 1487 | } |
| 1506 | 1488 | |
| 1507 | 1489 | static void cps3_flashmain_w(running_machine *machine, int which, UINT32 offset, UINT32 data, UINT32 mem_mask) |
| 1508 | 1490 | { |
| 1491 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1509 | 1492 | int command; |
| 1510 | 1493 | |
| 1511 | | if (simm[which][0] == NULL || simm[which][1] == NULL || simm[which][2] == NULL || simm[which][3] == NULL) |
| 1494 | if (state->simm[which][0] == NULL || state->simm[which][1] == NULL || state->simm[which][2] == NULL || state->simm[which][3] == NULL) |
| 1512 | 1495 | return; |
| 1513 | 1496 | |
| 1514 | 1497 | if (ACCESSING_BITS_24_31) // Flash 1 |
| 1515 | 1498 | { |
| 1516 | 1499 | command = (data >> 24) & 0xff; |
| 1517 | | logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][0]->tag(), offset, command); |
| 1518 | | simm[which][0]->write(offset, command); |
| 1500 | logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][0]->tag(), offset, command); |
| 1501 | state->simm[which][0]->write(offset, command); |
| 1519 | 1502 | } |
| 1520 | 1503 | if (ACCESSING_BITS_16_23) // Flash 2 |
| 1521 | 1504 | { |
| 1522 | 1505 | command = (data >> 16) & 0xff; |
| 1523 | | logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][1]->tag(), offset, command); |
| 1524 | | simm[which][1]->write(offset, command); |
| 1506 | logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][1]->tag(), offset, command); |
| 1507 | state->simm[which][1]->write(offset, command); |
| 1525 | 1508 | } |
| 1526 | 1509 | if (ACCESSING_BITS_8_15) // Flash 2 |
| 1527 | 1510 | { |
| 1528 | 1511 | command = (data >> 8) & 0xff; |
| 1529 | | logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][2]->tag(), offset, command); |
| 1530 | | simm[which][2]->write(offset, command); |
| 1512 | logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][2]->tag(), offset, command); |
| 1513 | state->simm[which][2]->write(offset, command); |
| 1531 | 1514 | } |
| 1532 | 1515 | if (ACCESSING_BITS_0_7) // Flash 2 |
| 1533 | 1516 | { |
| 1534 | 1517 | command = (data >> 0) & 0xff; |
| 1535 | | logerror("write to flash chip %s addr %02x cmd %02x\n", simm[which][3]->tag(), offset, command); |
| 1536 | | simm[which][3]->write(offset, command); |
| 1518 | logerror("write to flash chip %s addr %02x cmd %02x\n", state->simm[which][3]->tag(), offset, command); |
| 1519 | state->simm[which][3]->write(offset, command); |
| 1537 | 1520 | } |
| 1538 | 1521 | |
| 1539 | 1522 | /* copy data into regions to execute from */ |
| 1540 | 1523 | { |
| 1541 | | UINT32* romdata = (UINT32*)cps3_user4region; |
| 1542 | | UINT32* romdata2 = (UINT32*)decrypted_gamerom; |
| 1524 | UINT32* romdata = (UINT32*)state->user4region; |
| 1525 | UINT32* romdata2 = (UINT32*)state->decrypted_gamerom; |
| 1543 | 1526 | int real_offset = 0; |
| 1544 | 1527 | UINT32 newdata; |
| 1545 | 1528 | |
| r10427 | r10428 | |
| 1552 | 1535 | real_offset += 0x800000; |
| 1553 | 1536 | } |
| 1554 | 1537 | |
| 1555 | | newdata = (simm[which][0]->read_raw(offset)<<24) | |
| 1556 | | (simm[which][1]->read_raw(offset)<<16) | |
| 1557 | | (simm[which][2]->read_raw(offset)<<8) | |
| 1558 | | (simm[which][3]->read_raw(offset)<<0); |
| 1538 | newdata = (state->simm[which][0]->read_raw(offset)<<24) | |
| 1539 | (state->simm[which][1]->read_raw(offset)<<16) | |
| 1540 | (state->simm[which][2]->read_raw(offset)<<8) | |
| 1541 | (state->simm[which][3]->read_raw(offset)<<0); |
| 1559 | 1542 | |
| 1560 | | //printf("%08x %08x %08x %08x %08x\n",offset, romdata2[offset], romdata[offset], newdata, newdata^cps3_mask(0x6000000+real_offset, cps3_key1, cps3_key2) ); |
| 1543 | //printf("%08x %08x %08x %08x %08x\n",offset, romdata2[offset], romdata[offset], newdata, newdata^cps3_mask(0x6000000+real_offset, state->key1, state->key2) ); |
| 1561 | 1544 | |
| 1562 | 1545 | romdata[offset] = newdata; |
| 1563 | | romdata2[offset] = newdata^cps3_mask(0x6000000+real_offset, cps3_key1, cps3_key2); |
| 1546 | romdata2[offset] = newdata^cps3_mask(0x6000000+real_offset, state->key1, state->key2); |
| 1564 | 1547 | } |
| 1565 | 1548 | } |
| 1566 | 1549 | |
| r10427 | r10428 | |
| 1576 | 1559 | |
| 1577 | 1560 | static WRITE32_HANDLER( cram_gfxflash_bank_w ) |
| 1578 | 1561 | { |
| 1562 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1579 | 1563 | if (ACCESSING_BITS_24_31) |
| 1580 | 1564 | { |
| 1581 | 1565 | //printf("cram_gfxflash_bank_w MSB32 %08x\n",data); |
| r10427 | r10428 | |
| 1619 | 1603 | SIMM 7 (Rom 70/71) ** NOT USED (would follow on in sequence tho) |
| 1620 | 1604 | |
| 1621 | 1605 | */ |
| 1622 | | cram_gfxflash_bank = (data & 0xffff0000) >> 16; |
| 1623 | | cram_gfxflash_bank-= 0x0002;// as with sound access etc. first 4 meg is 'special' and skipped |
| 1606 | state->cram_gfxflash_bank = (data & 0xffff0000) >> 16; |
| 1607 | state->cram_gfxflash_bank-= 0x0002;// as with sound access etc. first 4 meg is 'special' and skipped |
| 1624 | 1608 | } |
| 1625 | 1609 | |
| 1626 | 1610 | if (ACCESSING_BITS_0_7) |
| r10427 | r10428 | |
| 1653 | 1637 | |
| 1654 | 1638 | /* EEPROM access is a little odd, I think it accesses eeprom through some kind of |
| 1655 | 1639 | additional interface, as these writes aren't normal for the type of eeprom we have */ |
| 1656 | | static UINT16 cps3_current_eeprom_read; |
| 1657 | 1640 | |
| 1658 | 1641 | static READ32_HANDLER( cps3_eeprom_r ) |
| 1659 | 1642 | { |
| 1643 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1660 | 1644 | int addr = offset*4; |
| 1661 | 1645 | |
| 1662 | 1646 | if (addr>=0x100 && addr<=0x17f) |
| 1663 | 1647 | { |
| 1664 | | if (ACCESSING_BITS_24_31) cps3_current_eeprom_read = (cps3_eeprom[offset-0x100/4] & 0xffff0000)>>16; |
| 1665 | | else cps3_current_eeprom_read = (cps3_eeprom[offset-0x100/4] & 0x0000ffff)>>0; |
| 1648 | if (ACCESSING_BITS_24_31) state->current_eeprom_read = (state->eeprom[offset-0x100/4] & 0xffff0000)>>16; |
| 1649 | else state->current_eeprom_read = (state->eeprom[offset-0x100/4] & 0x0000ffff)>>0; |
| 1666 | 1650 | // read word to latch... |
| 1667 | 1651 | return 0x00000000; |
| 1668 | 1652 | } |
| r10427 | r10428 | |
| 1672 | 1656 | if (ACCESSING_BITS_24_31) return 0; |
| 1673 | 1657 | else |
| 1674 | 1658 | { |
| 1675 | | //if(DEBUG_PRINTF) printf("reading %04x from eeprom\n", cps3_current_eeprom_read); |
| 1676 | | return cps3_current_eeprom_read; |
| 1659 | //if(DEBUG_PRINTF) printf("reading %04x from eeprom\n", state->current_eeprom_read); |
| 1660 | return state->current_eeprom_read; |
| 1677 | 1661 | } |
| 1678 | 1662 | } |
| 1679 | 1663 | else |
| r10427 | r10428 | |
| 1686 | 1670 | |
| 1687 | 1671 | static WRITE32_HANDLER( cps3_eeprom_w ) |
| 1688 | 1672 | { |
| 1673 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1689 | 1674 | int addr = offset*4; |
| 1690 | 1675 | |
| 1691 | 1676 | if (addr>=0x080 && addr<=0x0ff) |
| 1692 | 1677 | { |
| 1693 | 1678 | offset -= 0x80/4; |
| 1694 | | COMBINE_DATA(&cps3_eeprom[offset]); |
| 1679 | COMBINE_DATA(&state->eeprom[offset]); |
| 1695 | 1680 | // write word to storage |
| 1696 | 1681 | |
| 1697 | 1682 | } |
| r10427 | r10428 | |
| 1738 | 1723 | |
| 1739 | 1724 | static WRITE32_HANDLER( cps3_ss_bank_base_w ) |
| 1740 | 1725 | { |
| 1726 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1741 | 1727 | // might be scroll registers or something else.. |
| 1742 | 1728 | // used to display bank with 'insert coin' on during sfiii2 attract intro |
| 1743 | | COMBINE_DATA(&cps3_ss_bank_base); |
| 1729 | COMBINE_DATA(&state->ss_bank_base); |
| 1744 | 1730 | |
| 1745 | 1731 | // printf("cps3_ss_bank_base_w %08x %08x\n", data, mem_mask); |
| 1746 | 1732 | } |
| 1747 | 1733 | |
| 1748 | 1734 | static WRITE32_HANDLER( cps3_ss_pal_base_w ) |
| 1749 | 1735 | { |
| 1736 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1750 | 1737 | if(DEBUG_PRINTF) printf ("cps3_ss_pal_base_w %08x %08x\n", data, mem_mask); |
| 1751 | 1738 | |
| 1752 | 1739 | if(ACCESSING_BITS_24_31) |
| 1753 | 1740 | { |
| 1754 | | cps3_ss_pal_base = (data & 0x00ff0000)>>16; |
| 1741 | state->ss_pal_base = (data & 0x00ff0000)>>16; |
| 1755 | 1742 | |
| 1756 | | if (data & 0xff000000) printf("cps3_ss_pal_base MSB32 upper bits used %04x \n", data); |
| 1743 | if (data & 0xff000000) printf("ss_pal_base MSB32 upper bits used %04x \n", data); |
| 1757 | 1744 | } |
| 1758 | 1745 | else |
| 1759 | 1746 | { |
| 1760 | | // printf("cps3_ss_pal_base LSB32 used %04x \n", data); |
| 1747 | // printf("ss_pal_base LSB32 used %04x \n", data); |
| 1761 | 1748 | } |
| 1762 | 1749 | } |
| 1763 | 1750 | |
| 1764 | 1751 | //<ElSemi> +0 X +2 Y +4 unknown +6 enable (&0x8000) +8 low part tilemap base, high part linescroll base |
| 1765 | 1752 | //<ElSemi> (a word each) |
| 1766 | 1753 | |
| 1767 | | static UINT32 paldma_source; |
| 1768 | | static UINT32 paldma_realsource; |
| 1769 | | static UINT32 paldma_dest; |
| 1770 | | static UINT32 paldma_fade; |
| 1771 | | static UINT32 paldma_other2; |
| 1772 | | static UINT32 paldma_length; |
| 1773 | 1754 | |
| 1774 | 1755 | static WRITE32_HANDLER( cps3_palettedma_w ) |
| 1775 | 1756 | { |
| 1757 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 1776 | 1758 | if (offset==0) |
| 1777 | 1759 | { |
| 1778 | | COMBINE_DATA(&paldma_source); |
| 1779 | | paldma_realsource = (paldma_source<<1)-0x400000; |
| 1760 | COMBINE_DATA(&state->paldma_source); |
| 1761 | state->paldma_realsource = (state->paldma_source<<1)-0x400000; |
| 1780 | 1762 | } |
| 1781 | 1763 | else if (offset==1) |
| 1782 | 1764 | { |
| 1783 | | COMBINE_DATA(&paldma_dest); |
| 1765 | COMBINE_DATA(&state->paldma_dest); |
| 1784 | 1766 | } |
| 1785 | 1767 | else if (offset==2) |
| 1786 | 1768 | { |
| 1787 | | COMBINE_DATA(&paldma_fade); |
| 1769 | COMBINE_DATA(&state->paldma_fade); |
| 1788 | 1770 | } |
| 1789 | 1771 | else if (offset==3) |
| 1790 | 1772 | { |
| 1791 | | COMBINE_DATA(&paldma_other2); |
| 1773 | COMBINE_DATA(&state->paldma_other2); |
| 1792 | 1774 | |
| 1793 | 1775 | if (ACCESSING_BITS_24_31) |
| 1794 | 1776 | { |
| 1795 | | paldma_length = (data & 0xffff0000)>>16; |
| 1777 | state->paldma_length = (data & 0xffff0000)>>16; |
| 1796 | 1778 | } |
| 1797 | 1779 | if (ACCESSING_BITS_0_7) |
| 1798 | 1780 | { |
| 1799 | 1781 | if (data & 0x0002) |
| 1800 | 1782 | { |
| 1801 | 1783 | int i; |
| 1802 | | UINT16* src = (UINT16*)cps3_user5region; |
| 1803 | | // if(DEBUG_PRINTF) printf("CPS3 pal dma start %08x (real: %08x) dest %08x fade %08x other2 %08x (length %04x)\n", paldma_source, paldma_realsource, paldma_dest, paldma_fade, paldma_other2, paldma_length); |
| 1784 | UINT16* src = (UINT16*)state->user5region; |
| 1785 | // if(DEBUG_PRINTF) printf("CPS3 pal dma start %08x (real: %08x) dest %08x fade %08x other2 %08x (length %04x)\n", state->paldma_source, state->paldma_realsource, state->paldma_dest, state->paldma_fade, state->paldma_other2, state->paldma_length); |
| 1804 | 1786 | |
| 1805 | | for (i=0;i<paldma_length;i++) |
| 1787 | for (i=0;i<state->paldma_length;i++) |
| 1806 | 1788 | { |
| 1807 | | UINT16 coldata = src[BYTE_XOR_BE(((paldma_realsource>>1)+i))]; |
| 1789 | UINT16 coldata = src[BYTE_XOR_BE(((state->paldma_realsource>>1)+i))]; |
| 1808 | 1790 | |
| 1809 | | //if (paldma_fade!=0) printf("%08x\n",paldma_fade); |
| 1791 | //if (state->paldma_fade!=0) printf("%08x\n",state->paldma_fade); |
| 1810 | 1792 | |
| 1811 | | cps3_set_mame_colours(space->machine, (paldma_dest+i)^1, coldata, paldma_fade); |
| 1793 | cps3_set_mame_colours(space->machine, (state->paldma_dest+i)^1, coldata, state->paldma_fade); |
| 1812 | 1794 | } |
| 1813 | 1795 | |
| 1814 | 1796 | |
| r10427 | r10428 | |
| 1821 | 1803 | |
| 1822 | 1804 | } |
| 1823 | 1805 | |
| 1824 | | static UINT32 chardma_source; |
| 1825 | | static UINT32 chardma_other; |
| 1826 | 1806 | |
| 1827 | 1807 | //static UINT8* current_table; |
| 1828 | | static UINT32 current_table_address; |
| 1829 | 1808 | |
| 1830 | | static int cps3_rle_length = 0; |
| 1831 | 1809 | |
| 1832 | | static int last_normal_byte = 0; |
| 1833 | 1810 | |
| 1834 | 1811 | |
| 1835 | 1812 | static UINT32 process_byte( running_machine *machine, UINT8 real_byte, UINT32 destination, int max_length ) |
| 1836 | 1813 | { |
| 1837 | | UINT8* dest = (UINT8*)cps3_char_ram; |
| 1814 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1815 | UINT8* dest = (UINT8*)state->char_ram; |
| 1838 | 1816 | |
| 1839 | 1817 | //printf("process byte for destination %08x\n", destination); |
| 1840 | 1818 | |
| r10427 | r10428 | |
| 1845 | 1823 | int tranfercount = 0; |
| 1846 | 1824 | |
| 1847 | 1825 | //printf("Set RLE Mode\n"); |
| 1848 | | cps3_rle_length = (real_byte&0x3f)+1; |
| 1826 | state->rle_length = (real_byte&0x3f)+1; |
| 1849 | 1827 | |
| 1850 | | //printf("RLE Operation (length %08x\n", cps3_rle_length ); |
| 1828 | //printf("RLE Operation (length %08x\n", state->rle_length ); |
| 1851 | 1829 | |
| 1852 | | while (cps3_rle_length) |
| 1830 | while (state->rle_length) |
| 1853 | 1831 | { |
| 1854 | | dest[((destination+tranfercount)&0x7fffff)^3] = (last_normal_byte&0x3f); |
| 1832 | dest[((destination+tranfercount)&0x7fffff)^3] = (state->last_normal_byte&0x3f); |
| 1855 | 1833 | gfx_element_mark_dirty(machine->gfx[1], ((destination+tranfercount)&0x7fffff)/0x100); |
| 1856 | 1834 | //printf("RLE WRite Byte %08x, %02x\n", destination+tranfercount, real_byte); |
| 1857 | 1835 | |
| 1858 | 1836 | tranfercount++; |
| 1859 | | cps3_rle_length--; |
| 1837 | state->rle_length--; |
| 1860 | 1838 | max_length--; |
| 1861 | 1839 | |
| 1862 | 1840 | if ((destination+tranfercount) > 0x7fffff) return max_length; |
| r10427 | r10428 | |
| 1870 | 1848 | { |
| 1871 | 1849 | //printf("Write Normal Data\n"); |
| 1872 | 1850 | dest[(destination&0x7fffff)^3] = real_byte; |
| 1873 | | last_normal_byte = real_byte; |
| 1851 | state->last_normal_byte = real_byte; |
| 1874 | 1852 | gfx_element_mark_dirty(machine->gfx[1], (destination&0x7fffff)/0x100); |
| 1875 | 1853 | return 1; |
| 1876 | 1854 | } |
| r10427 | r10428 | |
| 1878 | 1856 | |
| 1879 | 1857 | static void cps3_do_char_dma( running_machine *machine, UINT32 real_source, UINT32 real_destination, UINT32 real_length ) |
| 1880 | 1858 | { |
| 1881 | | UINT8* sourcedata = (UINT8*)cps3_user5region; |
| 1859 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1860 | UINT8* sourcedata = (UINT8*)state->user5region; |
| 1882 | 1861 | int length_remaining; |
| 1883 | 1862 | |
| 1884 | | last_normal_byte = 0; |
| 1885 | | cps3_rle_length = 0; |
| 1863 | state->last_normal_byte = 0; |
| 1864 | state->rle_length = 0; |
| 1886 | 1865 | length_remaining = real_length; |
| 1887 | 1866 | while (length_remaining) |
| 1888 | 1867 | { |
| r10427 | r10428 | |
| 1897 | 1876 | UINT32 length_processed; |
| 1898 | 1877 | current_byte &= 0x7f; |
| 1899 | 1878 | |
| 1900 | | real_byte = sourcedata[DMA_XOR((current_table_address+current_byte*2+0))]; |
| 1879 | real_byte = sourcedata[DMA_XOR((state->current_table_address+current_byte*2+0))]; |
| 1901 | 1880 | //if (real_byte&0x80) return; |
| 1902 | 1881 | length_processed = process_byte( machine, real_byte, real_destination, length_remaining ); |
| 1903 | 1882 | length_remaining-=length_processed; // subtract the number of bytes the operation has taken |
| r10427 | r10428 | |
| 1905 | 1884 | if (real_destination>0x7fffff) return; |
| 1906 | 1885 | if (length_remaining<=0) return; // if we've expired, exit |
| 1907 | 1886 | |
| 1908 | | real_byte = sourcedata[DMA_XOR((current_table_address+current_byte*2+1))]; |
| 1887 | real_byte = sourcedata[DMA_XOR((state->current_table_address+current_byte*2+1))]; |
| 1909 | 1888 | //if (real_byte&0x80) return; |
| 1910 | 1889 | length_processed = process_byte( machine, real_byte, real_destination, length_remaining ); |
| 1911 | 1890 | length_remaining-=length_processed; // subtract the number of bytes the operation has taken |
| r10427 | r10428 | |
| 1927 | 1906 | } |
| 1928 | 1907 | } |
| 1929 | 1908 | |
| 1930 | | static unsigned short lastb; |
| 1931 | | static unsigned short lastb2; |
| 1932 | 1909 | static UINT32 ProcessByte8(running_machine *machine,UINT8 b,UINT32 dst_offset) |
| 1933 | 1910 | { |
| 1934 | | UINT8* destRAM = (UINT8*)cps3_char_ram; |
| 1911 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1912 | UINT8* destRAM = (UINT8*)state->char_ram; |
| 1935 | 1913 | int l=0; |
| 1936 | 1914 | |
| 1937 | | if(lastb==lastb2) //rle |
| 1915 | if(state->lastb==state->lastb2) //rle |
| 1938 | 1916 | { |
| 1939 | 1917 | int i; |
| 1940 | 1918 | int rle=(b+1)&0xff; |
| 1941 | 1919 | |
| 1942 | 1920 | for(i=0;i<rle;++i) |
| 1943 | 1921 | { |
| 1944 | | destRAM[(dst_offset&0x7fffff)^3] = lastb; |
| 1922 | destRAM[(dst_offset&0x7fffff)^3] = state->lastb; |
| 1945 | 1923 | gfx_element_mark_dirty(machine->gfx[1], (dst_offset&0x7fffff)/0x100); |
| 1946 | 1924 | |
| 1947 | 1925 | dst_offset++; |
| 1948 | 1926 | ++l; |
| 1949 | 1927 | } |
| 1950 | | lastb2=0xffff; |
| 1928 | state->lastb2=0xffff; |
| 1951 | 1929 | |
| 1952 | 1930 | return l; |
| 1953 | 1931 | } |
| 1954 | 1932 | else |
| 1955 | 1933 | { |
| 1956 | | lastb2=lastb; |
| 1957 | | lastb=b; |
| 1934 | state->lastb2=state->lastb; |
| 1935 | state->lastb=b; |
| 1958 | 1936 | destRAM[(dst_offset&0x7fffff)^3] = b; |
| 1959 | 1937 | gfx_element_mark_dirty(machine->gfx[1], (dst_offset&0x7fffff)/0x100); |
| 1960 | 1938 | return 1; |
| r10427 | r10428 | |
| 1963 | 1941 | |
| 1964 | 1942 | static void cps3_do_alt_char_dma( running_machine *machine, UINT32 src, UINT32 real_dest, UINT32 real_length ) |
| 1965 | 1943 | { |
| 1966 | | UINT8* px = (UINT8*)cps3_user5region; |
| 1944 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 1945 | UINT8* px = (UINT8*)state->user5region; |
| 1967 | 1946 | UINT32 start = real_dest; |
| 1968 | 1947 | UINT32 ds = real_dest; |
| 1969 | 1948 | |
| 1970 | | lastb=0xfffe; |
| 1971 | | lastb2=0xffff; |
| 1949 | state->lastb=0xfffe; |
| 1950 | state->lastb2=0xffff; |
| 1972 | 1951 | |
| 1973 | 1952 | while(1) |
| 1974 | 1953 | { |
| r10427 | r10428 | |
| 1984 | 1963 | { |
| 1985 | 1964 | UINT8 real_byte; |
| 1986 | 1965 | p&=0x7f; |
| 1987 | | real_byte = px[DMA_XOR((current_table_address+p*2+0))]; |
| 1966 | real_byte = px[DMA_XOR((state->current_table_address+p*2+0))]; |
| 1988 | 1967 | ds+=ProcessByte8(machine,real_byte,ds); |
| 1989 | | real_byte = px[DMA_XOR((current_table_address+p*2+1))]; |
| 1968 | real_byte = px[DMA_XOR((state->current_table_address+p*2+1))]; |
| 1990 | 1969 | ds+=ProcessByte8(machine,real_byte,ds); |
| 1991 | 1970 | } |
| 1992 | 1971 | else |
| r10427 | r10428 | |
| 2004 | 1983 | |
| 2005 | 1984 | static void cps3_process_character_dma(running_machine *machine, UINT32 address) |
| 2006 | 1985 | { |
| 1986 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 2007 | 1987 | int i; |
| 2008 | 1988 | |
| 2009 | 1989 | //printf("charDMA start:\n"); |
| 2010 | 1990 | |
| 2011 | 1991 | for (i = 0; i < 0x1000; i += 3) |
| 2012 | 1992 | { |
| 2013 | | UINT32 dat1 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 0 + (address)]); |
| 2014 | | UINT32 dat2 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 1 + (address)]); |
| 2015 | | UINT32 dat3 = LITTLE_ENDIANIZE_INT32(cps3_char_ram[i + 2 + (address)]); |
| 1993 | UINT32 dat1 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 0 + (address)]); |
| 1994 | UINT32 dat2 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 1 + (address)]); |
| 1995 | UINT32 dat3 = LITTLE_ENDIANIZE_INT32(state->char_ram[i + 2 + (address)]); |
| 2016 | 1996 | UINT32 real_source = (dat3 << 1) - 0x400000; |
| 2017 | 1997 | UINT32 real_destination = dat2 << 3; |
| 2018 | 1998 | UINT32 real_length = (((dat1 & 0x001fffff) + 1) << 3); |
| r10427 | r10428 | |
| 2027 | 2007 | /* Sets a table used by the decompression routines */ |
| 2028 | 2008 | { |
| 2029 | 2009 | /* We should probably copy this, but a pointer to it is fine for our purposes as the data doesn't change */ |
| 2030 | | current_table_address = real_source; |
| 2010 | state->current_table_address = real_source; |
| 2031 | 2011 | } |
| 2032 | 2012 | cputag_set_input_line(machine, "maincpu", 10, ASSERT_LINE); |
| 2033 | 2013 | } |
| r10427 | r10428 | |
| 2056 | 2036 | |
| 2057 | 2037 | static WRITE32_HANDLER( cps3_characterdma_w ) |
| 2058 | 2038 | { |
| 2039 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 2059 | 2040 | if(DEBUG_PRINTF) printf("chardma_w %08x %08x %08x\n", offset, data, mem_mask); |
| 2060 | 2041 | |
| 2061 | 2042 | if (offset==0) |
| 2062 | 2043 | { |
| 2063 | | //COMBINE_DATA(&chardma_source); |
| 2044 | //COMBINE_DATA(&state->chardma_source); |
| 2064 | 2045 | if (ACCESSING_BITS_0_7) |
| 2065 | 2046 | { |
| 2066 | | chardma_source = data & 0x0000ffff; |
| 2047 | state->chardma_source = data & 0x0000ffff; |
| 2067 | 2048 | } |
| 2068 | 2049 | if (ACCESSING_BITS_24_31) |
| 2069 | 2050 | { |
| r10427 | r10428 | |
| 2072 | 2053 | } |
| 2073 | 2054 | else if (offset==1) |
| 2074 | 2055 | { |
| 2075 | | COMBINE_DATA(&chardma_other); |
| 2056 | COMBINE_DATA(&state->chardma_other); |
| 2076 | 2057 | |
| 2077 | 2058 | if (ACCESSING_BITS_24_31) |
| 2078 | 2059 | { |
| 2079 | 2060 | if ((data>>16) & 0x0040) |
| 2080 | 2061 | { |
| 2081 | 2062 | UINT32 list_address; |
| 2082 | | list_address = (chardma_source | ((chardma_other&0x003f0000))); |
| 2063 | list_address = (state->chardma_source | ((state->chardma_other&0x003f0000))); |
| 2083 | 2064 | |
| 2084 | | //printf("chardma_w activated %08x %08x (address = cram %08x)\n", chardma_source, chardma_other, list_address*4 ); |
| 2065 | //printf("chardma_w activated %08x %08x (address = cram %08x)\n", state->chardma_source, state->chardma_other, list_address*4 ); |
| 2085 | 2066 | cps3_process_character_dma(space->machine, list_address); |
| 2086 | 2067 | } |
| 2087 | 2068 | else |
| 2088 | 2069 | { |
| 2089 | | if(DEBUG_PRINTF) printf("chardma_w NOT activated %08x %08x\n", chardma_source, chardma_other ); |
| 2070 | if(DEBUG_PRINTF) printf("chardma_w NOT activated %08x %08x\n", state->chardma_source, state->chardma_other ); |
| 2090 | 2071 | } |
| 2091 | 2072 | |
| 2092 | 2073 | if ((data>>16) & 0xff80) |
| 2093 | | if(DEBUG_PRINTF) printf("chardma_w unknown bits in activate command %08x %08x\n", chardma_source, chardma_other ); |
| 2074 | if(DEBUG_PRINTF) printf("chardma_w unknown bits in activate command %08x %08x\n", state->chardma_source, state->chardma_other ); |
| 2094 | 2075 | } |
| 2095 | 2076 | else |
| 2096 | 2077 | { |
| 2097 | | if(DEBUG_PRINTF) printf("chardma_w LSB32 write to activate command %08x %08x\n", chardma_source, chardma_other ); |
| 2078 | if(DEBUG_PRINTF) printf("chardma_w LSB32 write to activate command %08x %08x\n", state->chardma_source, state->chardma_other ); |
| 2098 | 2079 | } |
| 2099 | 2080 | } |
| 2100 | 2081 | } |
| r10427 | r10428 | |
| 2111 | 2092 | |
| 2112 | 2093 | static WRITE32_HANDLER( cps3_unk_vidregs_w ) |
| 2113 | 2094 | { |
| 2114 | | COMBINE_DATA(&cps3_unk_vidregs[offset]); |
| 2095 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 2096 | COMBINE_DATA(&state->unk_vidregs[offset]); |
| 2115 | 2097 | } |
| 2116 | 2098 | |
| 2117 | 2099 | static READ32_HANDLER( cps3_colourram_r ) |
| 2118 | 2100 | { |
| 2119 | | UINT16* src = (UINT16*)cps3_colourram; |
| 2101 | cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 2102 | UINT16* src = (UINT16*)state->colourram; |
| 2120 | 2103 | |
| 2121 | 2104 | return src[offset*2+1] | (src[offset*2+0]<<16); |
| 2122 | 2105 | } |
| 2123 | 2106 | |
| 2124 | 2107 | static WRITE32_HANDLER( cps3_colourram_w ) |
| 2125 | 2108 | { |
| 2126 | | // COMBINE_DATA(&cps3_colourram[offset]); |
| 2109 | //cps3_state *state = space->machine->driver_data<cps3_state>(); |
| 2110 | // COMBINE_DATA(&state->colourram[offset]); |
| 2127 | 2111 | |
| 2128 | 2112 | if (ACCESSING_BITS_24_31) |
| 2129 | 2113 | { |
| r10427 | r10428 | |
| 2136 | 2120 | } |
| 2137 | 2121 | } |
| 2138 | 2122 | |
| 2139 | | static UINT32* cps3_mainram; |
| 2140 | 2123 | |
| 2141 | 2124 | /* there are more unknown writes, but you get the idea */ |
| 2142 | 2125 | static ADDRESS_MAP_START( cps3_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 2143 | 2126 | AM_RANGE(0x00000000, 0x0007ffff) AM_ROM AM_REGION("user1", 0) // Bios ROM |
| 2144 | | AM_RANGE(0x02000000, 0x0207ffff) AM_RAM AM_BASE(&cps3_mainram) // Main RAM |
| 2127 | AM_RANGE(0x02000000, 0x0207ffff) AM_RAM AM_BASE_MEMBER(cps3_state, mainram) // Main RAM |
| 2145 | 2128 | |
| 2146 | 2129 | AM_RANGE(0x03000000, 0x030003ff) AM_RAM // 'FRAM' (SFIII memory test mode ONLY) |
| 2147 | 2130 | |
| 2148 | | // AM_RANGE(0x04000000, 0x0407dfff) AM_RAM AM_BASE(&cps3_spriteram)//AM_WRITEONLY // Sprite RAM (jojoba tests this size) |
| 2149 | | AM_RANGE(0x04000000, 0x0407ffff) AM_RAM AM_BASE(&cps3_spriteram)//AM_WRITEONLY // Sprite RAM |
| 2131 | // AM_RANGE(0x04000000, 0x0407dfff) AM_RAM AM_BASE_MEMBER(cps3_state, spriteram)//AM_WRITEONLY // Sprite RAM (jojoba tests this size) |
| 2132 | AM_RANGE(0x04000000, 0x0407ffff) AM_RAM AM_BASE_MEMBER(cps3_state, spriteram)//AM_WRITEONLY // Sprite RAM |
| 2150 | 2133 | |
| 2151 | | AM_RANGE(0x04080000, 0x040bffff) AM_READWRITE(cps3_colourram_r, cps3_colourram_w) AM_BASE(&cps3_colourram) // Colour RAM (jojoba tests this size) 0x20000 colours?! |
| 2134 | AM_RANGE(0x04080000, 0x040bffff) AM_READWRITE(cps3_colourram_r, cps3_colourram_w) AM_BASE_MEMBER(cps3_state, colourram) // Colour RAM (jojoba tests this size) 0x20000 colours?! |
| 2152 | 2135 | |
| 2153 | 2136 | // video registers of some kind probably |
| 2154 | 2137 | AM_RANGE(0x040C0000, 0x040C0003) AM_READ(cps3_40C0000_r)//?? every frame |
| r10427 | r10428 | |
| 2157 | 2140 | AM_RANGE(0x040C000c, 0x040C000f) AM_READ(cps3_vbl_r)// AM_WRITENOP/ |
| 2158 | 2141 | |
| 2159 | 2142 | AM_RANGE(0x040C0000, 0x040C001f) AM_WRITE(cps3_unk_vidregs_w) |
| 2160 | | AM_RANGE(0x040C0020, 0x040C002b) AM_WRITEONLY AM_BASE(&tilemap20_regs_base) |
| 2161 | | AM_RANGE(0x040C0030, 0x040C003b) AM_WRITEONLY AM_BASE(&tilemap30_regs_base) |
| 2162 | | AM_RANGE(0x040C0040, 0x040C004b) AM_WRITEONLY AM_BASE(&tilemap40_regs_base) |
| 2163 | | AM_RANGE(0x040C0050, 0x040C005b) AM_WRITEONLY AM_BASE(&tilemap50_regs_base) |
| 2143 | AM_RANGE(0x040C0020, 0x040C002b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap20_regs_base) |
| 2144 | AM_RANGE(0x040C0030, 0x040C003b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap30_regs_base) |
| 2145 | AM_RANGE(0x040C0040, 0x040C004b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap40_regs_base) |
| 2146 | AM_RANGE(0x040C0050, 0x040C005b) AM_WRITEONLY AM_BASE_MEMBER(cps3_state, tilemap50_regs_base) |
| 2164 | 2147 | |
| 2165 | | AM_RANGE(0x040C0060, 0x040C007f) AM_RAM AM_BASE(&cps3_fullscreenzoom) |
| 2148 | AM_RANGE(0x040C0060, 0x040C007f) AM_RAM AM_BASE_MEMBER(cps3_state, fullscreenzoom) |
| 2166 | 2149 | |
| 2167 | 2150 | |
| 2168 | 2151 | AM_RANGE(0x040C0094, 0x040C009b) AM_WRITE(cps3_characterdma_w) |
| r10427 | r10428 | |
| 2201 | 2184 | AM_RANGE(0x06000000, 0x067fffff) AM_READWRITE( cps3_flash1_r, cps3_flash1_w ) /* Flash ROMs simm 1 */ |
| 2202 | 2185 | AM_RANGE(0x06800000, 0x06ffffff) AM_READWRITE( cps3_flash2_r, cps3_flash2_w ) /* Flash ROMs simm 2 */ |
| 2203 | 2186 | |
| 2204 | | AM_RANGE(0xc0000000, 0xc00003ff) AM_RAM_WRITE( cps3_0xc0000000_ram_w ) AM_BASE(&cps3_0xc0000000_ram) /* Executes code from here */ |
| 2187 | AM_RANGE(0xc0000000, 0xc00003ff) AM_RAM_WRITE( cps3_0xc0000000_ram_w ) AM_BASE_MEMBER(cps3_state, _0xc0000000_ram) /* Executes code from here */ |
| 2205 | 2188 | ADDRESS_MAP_END |
| 2206 | 2189 | |
| 2207 | 2190 | |
| r10427 | r10428 | |
| 2260 | 2243 | } |
| 2261 | 2244 | |
| 2262 | 2245 | |
| 2263 | | //static sh2_cpu_core sh2cp_conf_slave = { 1 }; |
| 2246 | //static sh2_cpu_core sh2cp_conf_slave = { 1, NULL }; |
| 2264 | 2247 | |
| 2265 | 2248 | |
| 2266 | 2249 | static const SCSIConfigTable dev_table = |
| r10427 | r10428 | |
| 2288 | 2271 | |
| 2289 | 2272 | static MACHINE_RESET( cps3 ) |
| 2290 | 2273 | { |
| 2291 | | current_table_address = -1; |
| 2274 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 2275 | state->current_table_address = -1; |
| 2292 | 2276 | |
| 2293 | 2277 | // copy data from flashroms back into user regions + decrypt into regions we execute/draw from. |
| 2294 | 2278 | copy_from_nvram(machine); |
| r10427 | r10428 | |
| 2299 | 2283 | // make a copy in the regions we execute code / draw gfx from |
| 2300 | 2284 | static void copy_from_nvram(running_machine *machine) |
| 2301 | 2285 | { |
| 2302 | | UINT32* romdata = (UINT32*)cps3_user4region; |
| 2303 | | UINT32* romdata2 = (UINT32*)decrypted_gamerom; |
| 2286 | cps3_state *state = machine->driver_data<cps3_state>(); |
| 2287 | UINT32* romdata = (UINT32*)state->user4region; |
| 2288 | UINT32* romdata2 = (UINT32*)state->decrypted_gamerom; |
| 2304 | 2289 | int i; |
| 2305 | 2290 | /* copy + decrypt program roms which have been loaded from flashroms/nvram */ |
| 2306 | 2291 | for (i=0;i<0x800000;i+=4) |
| 2307 | 2292 | { |
| 2308 | 2293 | UINT32 data; |
| 2309 | 2294 | |
| 2310 | | data = ((simm[0][0]->read_raw(i/4)<<24) | (simm[0][1]->read_raw(i/4)<<16) | (simm[0][2]->read_raw(i/4)<<8) | (simm[0][3]->read_raw(i/4)<<0)); |
| 2295 | data = ((state->simm[0][0]->read_raw(i/4)<<24) | (state->simm[0][1]->read_raw(i/4)<<16) | (state->simm[0][2]->read_raw(i/4)<<8) | (state->simm[0][3]->read_raw(i/4)<<0)); |
| 2311 | 2296 | |
| 2312 | | // printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6000000, cps3_key1, cps3_key2)); |
| 2297 | // printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6000000, state->key1, state->key2)); |
| 2313 | 2298 | romdata[i/4] = data; |
| 2314 | | romdata2[i/4] = data ^ cps3_mask(i+0x6000000, cps3_key1, cps3_key2); |
| 2299 | romdata2[i/4] = data ^ cps3_mask(i+0x6000000, state->key1, state->key2); |
| 2315 | 2300 | |
| 2316 | 2301 | } |
| 2317 | 2302 | |
| 2318 | 2303 | romdata += 0x800000/4; |
| 2319 | 2304 | romdata2 += 0x800000/4; |
| 2320 | 2305 | |
| 2321 | | if (simm[1][0] != NULL) |
| 2306 | if (state->simm[1][0] != NULL) |
| 2322 | 2307 | for (i=0;i<0x800000;i+=4) |
| 2323 | 2308 | { |
| 2324 | 2309 | UINT32 data; |
| 2325 | 2310 | |
| 2326 | | data = ((simm[1][0]->read_raw(i/4)<<24) | (simm[1][1]->read_raw(i/4)<<16) | (simm[1][2]->read_raw(i/4)<<8) | (simm[1][3]->read_raw(i/4)<<0)); |
| 2311 | data = ((state->simm[1][0]->read_raw(i/4)<<24) | (state->simm[1][1]->read_raw(i/4)<<16) | (state->simm[1][2]->read_raw(i/4)<<8) | (state->simm[1][3]->read_raw(i/4)<<0)); |
| 2327 | 2312 | |
| 2328 | | // printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6800000, cps3_key1, cps3_key2) ); |
| 2313 | // printf("%08x %08x %08x %08x\n",romdata[i/4],data, romdata2[i/4], data ^ cps3_mask(i+0x6800000, state->key1, state->key2) ); |
| 2329 | 2314 | romdata[i/4] = data; |
| 2330 | | romdata2[i/4] = data ^ cps3_mask(i+0x6800000, cps3_key1, cps3_key2); |
| 2315 | romdata2[i/4] = data ^ cps3_mask(i+0x6800000, state->key1, state->key2); |
| 2331 | 2316 | } |
| 2332 | 2317 | |
| 2333 | 2318 | /* copy gfx from loaded flashroms to user reigon 5, where it's used */ |
| r10427 | r10428 | |
| 2336 | 2321 | int flashnum = 0; |
| 2337 | 2322 | int countoffset = 0; |
| 2338 | 2323 | |
| 2339 | | romdata = (UINT32*)cps3_user5region; |
| 2324 | romdata = (UINT32*)state->user5region; |
| 2340 | 2325 | for (thebase = 0;thebase < len/2; thebase+=0x200000) |
| 2341 | 2326 | { |
| 2342 | 2327 | // printf("flashnums %d. %d\n",flashnum, flashnum+1); |
| 2343 | 2328 | |
| 2344 | | fujitsu_29f016a_device *flash0 = simm[2 + flashnum/8][flashnum % 8 + 0]; |
| 2345 | | fujitsu_29f016a_device *flash1 = simm[2 + flashnum/8][flashnum % 8 + 1]; |
| 2329 | fujitsu_29f016a_device *flash0 = state->simm[2 + flashnum/8][flashnum % 8 + 0]; |
| 2330 | fujitsu_29f016a_device *flash1 = state->simm[2 + flashnum/8][flashnum % 8 + 1]; |
| 2346 | 2331 | if (flash0 == NULL || flash1 == NULL) |
| 2347 | 2332 | continue; |
| 2348 | 2333 | if (flash0 != NULL && flash1 != NULL) |
| r10427 | r10428 | |
| 2384 | 2369 | } |
| 2385 | 2370 | |
| 2386 | 2371 | |
| 2387 | | static int cps3_dma_callback(UINT32 src, UINT32 dst, UINT32 data, int size) |
| 2372 | static int cps3_dma_callback(device_t *device, UINT32 src, UINT32 dst, UINT32 data, int size) |
| 2388 | 2373 | { |
| 2374 | cps3_state *state = device->machine->driver_data<cps3_state>(); |
| 2389 | 2375 | /* |
| 2390 | 2376 | on the actual CPS3 hardware the SH2 DMA bypasses the encryption. |
| 2391 | 2377 | |
| r10427 | r10428 | |
| 2408 | 2394 | if (src<0x80000) |
| 2409 | 2395 | { |
| 2410 | 2396 | int offs = (src&0x07ffff)>>2; |
| 2411 | | data = data ^ cps3_mask(offs*4, cps3_key1, cps3_key2); |
| 2397 | data = data ^ cps3_mask(offs*4, state->key1, state->key2); |
| 2412 | 2398 | } |
| 2413 | 2399 | else if (src>=0x6000000 && src<0x6800000) |
| 2414 | 2400 | { |
| 2415 | 2401 | int offs = (src&0x07fffff)>>2; |
| 2416 | | if (!cps3_altEncryption) data = data ^ cps3_mask(0x6000000+offs*4, cps3_key1, cps3_key2); |
| 2402 | if (!state->altEncryption) data = data ^ cps3_mask(0x6000000+offs*4, state->key1, state->key2); |
| 2417 | 2403 | } |
| 2418 | 2404 | else if (src>=0x6800000 && src<0x7000000) |
| 2419 | 2405 | { |
| 2420 | 2406 | int offs = (src&0x07fffff)>>2; |
| 2421 | | if (!cps3_altEncryption) data = data ^ cps3_mask(0x6800000+offs*4, cps3_key1, cps3_key2); |
| 2407 | if (!state->altEncryption) data = data ^ cps3_mask(0x6800000+offs*4, state->key1, state->key2); |
| 2422 | 2408 | } |
| 2423 | 2409 | else |
| 2424 | 2410 | { |
| r10427 | r10428 | |
| 2509 | 2495 | MCFG_FUJITSU_29F016A_ADD("simm6.7") |
| 2510 | 2496 | MACHINE_CONFIG_END |
| 2511 | 2497 | |
| 2512 | | static MACHINE_CONFIG_START( cps3, driver_device ) |
| 2498 | static MACHINE_CONFIG_START( cps3, cps3_state ) |
| 2513 | 2499 | /* basic machine hardware */ |
| 2514 | 2500 | MCFG_CPU_ADD("maincpu", SH2, 6250000*4) // external clock is 6.25 Mhz, it sets the intenral multiplier to 4x (this should probably be handled in the core..) |
| 2515 | 2501 | MCFG_CPU_PROGRAM_MAP(cps3_map) |
src/mame/drivers/firebeat.c
| r10427 | r10428 | |
| 121 | 121 | #include "firebeat.lh" |
| 122 | 122 | |
| 123 | 123 | |
| 124 | | |
| 125 | 124 | typedef struct |
| 126 | 125 | { |
| 127 | 126 | UINT32 *vram; |
| r10427 | r10428 | |
| 130 | 129 | UINT32 visible_area; |
| 131 | 130 | } GCU_REGS; |
| 132 | 131 | |
| 133 | | static UINT8 extend_board_irq_enable; |
| 134 | | static UINT8 extend_board_irq_active; |
| 132 | typedef struct |
| 133 | { |
| 134 | UINT8 identifier[8]; |
| 135 | UINT8 password[8]; |
| 136 | UINT8 data[0x30]; |
| 137 | } IBUTTON_SUBKEY; |
| 135 | 138 | |
| 136 | | static emu_timer *keyboard_timer; |
| 139 | typedef struct |
| 140 | { |
| 141 | IBUTTON_SUBKEY subkey[3]; |
| 142 | } IBUTTON; |
| 137 | 143 | |
| 138 | | static fujitsu_29f016a_device *flash[3]; |
| 139 | 144 | |
| 140 | | static GCU_REGS gcu[2]; |
| 141 | 145 | |
| 146 | class firebeat_state : public driver_device |
| 147 | { |
| 148 | public: |
| 149 | firebeat_state(running_machine &machine, const driver_device_config_base &config) |
| 150 | : driver_device(machine, config) { } |
| 151 | |
| 152 | UINT8 extend_board_irq_enable; |
| 153 | UINT8 extend_board_irq_active; |
| 154 | emu_timer *keyboard_timer; |
| 155 | fujitsu_29f016a_device *flash[3]; |
| 156 | GCU_REGS gcu[2]; |
| 157 | int tick; |
| 158 | int layer; |
| 159 | UINT8 atapi_regs[16]; |
| 160 | SCSIInstance *atapi_device_data[2]; |
| 161 | UINT16 atapi_data[32*1024]; |
| 162 | UINT8 atapi_scsi_packet[32*1024]; |
| 163 | int atapi_data_ptr; |
| 164 | int atapi_xferlen; |
| 165 | int atapi_xfermod; |
| 166 | int atapi_cdata_wait; |
| 167 | int atapi_drivesel; |
| 168 | UINT8 temp_data[64*1024]; |
| 169 | int cab_data_ptr; |
| 170 | const int * cur_cab_data; |
| 171 | int keyboard_state[2]; |
| 172 | UINT8 spu_shared_ram[0x400]; |
| 173 | UINT32 *work_ram; |
| 174 | IBUTTON ibutton; |
| 175 | int ibutton_state; |
| 176 | int ibutton_read_subkey_ptr; |
| 177 | UINT8 ibutton_subkey_data[0x40]; |
| 178 | }; |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 142 | 185 | static VIDEO_START(firebeat) |
| 143 | 186 | { |
| 144 | | gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); |
| 145 | | gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); |
| 146 | | memset(gcu[0].vram, 0, 0x2000000); |
| 147 | | memset(gcu[1].vram, 0, 0x2000000); |
| 187 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 188 | state->gcu[0].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); |
| 189 | state->gcu[1].vram = auto_alloc_array(machine, UINT32, 0x2000000/4); |
| 190 | memset(state->gcu[0].vram, 0, 0x2000000); |
| 191 | memset(state->gcu[1].vram, 0, 0x2000000); |
| 148 | 192 | } |
| 149 | 193 | |
| 150 | 194 | |
| 151 | | static void gcu_draw_object(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd) |
| 195 | static void gcu_draw_object(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd) |
| 152 | 196 | { |
| 197 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 153 | 198 | // 0x00: xxx----- -------- -------- -------- command type |
| 154 | 199 | // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx object data address in vram |
| 155 | 200 | |
| r10427 | r10428 | |
| 179 | 224 | |
| 180 | 225 | int i, j; |
| 181 | 226 | int u, v; |
| 182 | | UINT16 *vr = (UINT16*)gcu[chip].vram; |
| 227 | UINT16 *vr = (UINT16*)state->gcu[chip].vram; |
| 183 | 228 | |
| 184 | 229 | if (xscale == 0 || yscale == 0) |
| 185 | 230 | { |
| r10427 | r10428 | |
| 348 | 393 | } |
| 349 | 394 | } |
| 350 | 395 | |
| 351 | | static void gcu_draw_character(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 *cmd) |
| 396 | static void gcu_draw_character(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 *cmd) |
| 352 | 397 | { |
| 398 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 353 | 399 | // 0x00: xxx----- -------- -------- -------- command type |
| 354 | 400 | // 0x00: -------- xxxxxxxx xxxxxxxx xxxxxxxx character data address in vram |
| 355 | 401 | |
| r10427 | r10428 | |
| 368 | 414 | UINT32 address = cmd[0] & 0xffffff; |
| 369 | 415 | UINT16 color[4]; |
| 370 | 416 | |
| 371 | | UINT16 *vr = (UINT16*)gcu[chip].vram; |
| 417 | UINT16 *vr = (UINT16*)state->gcu[chip].vram; |
| 372 | 418 | |
| 373 | 419 | color[0] = (cmd[2] >> 16) & 0xffff; |
| 374 | 420 | color[1] = (cmd[2] >> 0) & 0xffff; |
| r10427 | r10428 | |
| 396 | 442 | } |
| 397 | 443 | } |
| 398 | 444 | |
| 399 | | static void gcu_exec_display_list(int chip, bitmap_t *bitmap, const rectangle *cliprect, UINT32 address) |
| 445 | static void gcu_exec_display_list(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int chip, UINT32 address) |
| 400 | 446 | { |
| 447 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 401 | 448 | int counter = 0; |
| 402 | 449 | int end = 0; |
| 403 | 450 | |
| r10427 | r10428 | |
| 407 | 454 | { |
| 408 | 455 | int command; |
| 409 | 456 | UINT32 cmd[4]; |
| 410 | | cmd[0] = gcu[chip].vram[i+0]; |
| 411 | | cmd[1] = gcu[chip].vram[i+1]; |
| 412 | | cmd[2] = gcu[chip].vram[i+2]; |
| 413 | | cmd[3] = gcu[chip].vram[i+3]; |
| 457 | cmd[0] = state->gcu[chip].vram[i+0]; |
| 458 | cmd[1] = state->gcu[chip].vram[i+1]; |
| 459 | cmd[2] = state->gcu[chip].vram[i+2]; |
| 460 | cmd[3] = state->gcu[chip].vram[i+3]; |
| 414 | 461 | |
| 415 | 462 | command = (cmd[0] >> 29) & 0x7; |
| 416 | 463 | |
| r10427 | r10428 | |
| 423 | 470 | |
| 424 | 471 | case 0x1: // Branch |
| 425 | 472 | { |
| 426 | | gcu_exec_display_list(chip, bitmap, cliprect, cmd[0] & 0xffffff); |
| 473 | gcu_exec_display_list(machine, bitmap, cliprect, chip, cmd[0] & 0xffffff); |
| 427 | 474 | break; |
| 428 | 475 | } |
| 429 | 476 | |
| r10427 | r10428 | |
| 446 | 493 | |
| 447 | 494 | case 0x5: // Draw object |
| 448 | 495 | { |
| 449 | | gcu_draw_object(chip, bitmap, cliprect, cmd); |
| 496 | gcu_draw_object(machine, bitmap, cliprect, chip, cmd); |
| 450 | 497 | break; |
| 451 | 498 | } |
| 452 | 499 | |
| 453 | 500 | case 0x7: // Draw 8x8 Character (2-bits per pixel) |
| 454 | 501 | { |
| 455 | | gcu_draw_character(chip, bitmap, cliprect, cmd); |
| 502 | gcu_draw_character(machine, bitmap, cliprect, chip, cmd); |
| 456 | 503 | break; |
| 457 | 504 | } |
| 458 | 505 | |
| r10427 | r10428 | |
| 466 | 513 | }; |
| 467 | 514 | } |
| 468 | 515 | |
| 469 | | static int tick = 0; |
| 470 | | static int layer = 0; |
| 471 | 516 | static VIDEO_UPDATE(firebeat) |
| 472 | 517 | { |
| 518 | firebeat_state *state = screen->machine->driver_data<firebeat_state>(); |
| 473 | 519 | int chip; |
| 474 | 520 | |
| 475 | 521 | if (screen == screen->machine->m_devicelist.find(SCREEN, 0)) |
| r10427 | r10428 | |
| 481 | 527 | |
| 482 | 528 | if (mame_stricmp(screen->machine->gamedrv->name, "popn7") == 0) |
| 483 | 529 | { |
| 484 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x1f80000); |
| 530 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1f80000); |
| 485 | 531 | } |
| 486 | 532 | else |
| 487 | 533 | { |
| 488 | | if (layer >= 2) |
| 534 | if (state->layer >= 2) |
| 489 | 535 | { |
| 490 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x8000); |
| 491 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x0000); |
| 492 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x10000); |
| 536 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x8000); |
| 537 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x0000); |
| 538 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x10000); |
| 493 | 539 | } |
| 494 | | else if (layer == 0) |
| 540 | else if (state->layer == 0) |
| 495 | 541 | { |
| 496 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x200000); |
| 542 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x200000); |
| 497 | 543 | |
| 498 | | //gcu_exec_display_list(chip, bitmap, cliprect, 0x186040); |
| 544 | //gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x186040); |
| 499 | 545 | } |
| 500 | | else if (layer == 1) |
| 546 | else if (state->layer == 1) |
| 501 | 547 | { |
| 502 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x1d0800); |
| 548 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1d0800); |
| 503 | 549 | |
| 504 | | gcu_exec_display_list(chip, bitmap, cliprect, 0x1a9440); |
| 550 | gcu_exec_display_list(screen->machine, bitmap, cliprect, chip, 0x1a9440); |
| 505 | 551 | } |
| 506 | 552 | } |
| 507 | 553 | |
| 508 | | tick++; |
| 509 | | if (tick >= 5) |
| 554 | state->tick++; |
| 555 | if (state->tick >= 5) |
| 510 | 556 | { |
| 511 | | tick = 0; |
| 557 | state->tick = 0; |
| 512 | 558 | if (input_code_pressed(screen->machine, KEYCODE_0)) |
| 513 | 559 | { |
| 514 | | layer++; |
| 515 | | if (layer > 2) |
| 560 | state->layer++; |
| 561 | if (state->layer > 2) |
| 516 | 562 | { |
| 517 | | layer = 0; |
| 563 | state->layer = 0; |
| 518 | 564 | } |
| 519 | 565 | } |
| 520 | 566 | |
| r10427 | r10428 | |
| 526 | 572 | |
| 527 | 573 | for (i=0; i < 0x2000000/4; i++) |
| 528 | 574 | { |
| 529 | | fputc((gcu[0].vram[i] >> 24) & 0xff, file); |
| 530 | | fputc((gcu[0].vram[i] >> 16) & 0xff, file); |
| 531 | | fputc((gcu[0].vram[i] >> 8) & 0xff, file); |
| 532 | | fputc((gcu[0].vram[i] >> 0) & 0xff, file); |
| 575 | fputc((state->gcu[0].vram[i] >> 24) & 0xff, file); |
| 576 | fputc((state->gcu[0].vram[i] >> 16) & 0xff, file); |
| 577 | fputc((state->gcu[0].vram[i] >> 8) & 0xff, file); |
| 578 | fputc((state->gcu[0].vram[i] >> 0) & 0xff, file); |
| 533 | 579 | } |
| 534 | 580 | |
| 535 | 581 | fclose(file); |
| r10427 | r10428 | |
| 537 | 583 | |
| 538 | 584 | for (i=0; i < 0x2000000/4; i++) |
| 539 | 585 | { |
| 540 | | fputc((gcu[1].vram[i] >> 24) & 0xff, file); |
| 541 | | fputc((gcu[1].vram[i] >> 16) & 0xff, file); |
| 542 | | fputc((gcu[1].vram[i] >> 8) & 0xff, file); |
| 543 | | fputc((gcu[1].vram[i] >> 0) & 0xff, file); |
| 586 | fputc((state->gcu[1].vram[i] >> 24) & 0xff, file); |
| 587 | fputc((state->gcu[1].vram[i] >> 16) & 0xff, file); |
| 588 | fputc((state->gcu[1].vram[i] >> 8) & 0xff, file); |
| 589 | fputc((state->gcu[1].vram[i] >> 0) & 0xff, file); |
| 544 | 590 | } |
| 545 | 591 | |
| 546 | 592 | fclose(file); |
| r10427 | r10428 | |
| 551 | 597 | return 0; |
| 552 | 598 | } |
| 553 | 599 | |
| 554 | | static UINT32 GCU_r(int chip, UINT32 offset, UINT32 mem_mask) |
| 600 | static UINT32 GCU_r(running_machine *machine, int chip, UINT32 offset, UINT32 mem_mask) |
| 555 | 601 | { |
| 602 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 556 | 603 | int reg = offset * 4; |
| 557 | 604 | |
| 558 | 605 | /* VRAM Read */ |
| 559 | 606 | if (reg >= 0x80 && reg < 0x100) |
| 560 | 607 | { |
| 561 | | return gcu[chip].vram[gcu[chip].vram_read_address + ((reg/4) - 0x20)]; |
| 608 | return state->gcu[chip].vram[state->gcu[chip].vram_read_address + ((reg/4) - 0x20)]; |
| 562 | 609 | } |
| 563 | 610 | |
| 564 | 611 | switch(reg) |
| r10427 | r10428 | |
| 576 | 623 | |
| 577 | 624 | static void GCU_w(running_machine *machine, int chip, UINT32 offset, UINT32 data, UINT32 mem_mask) |
| 578 | 625 | { |
| 626 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 579 | 627 | int reg = offset * 4; |
| 580 | 628 | |
| 581 | 629 | if (reg != 0x70 && chip == 0) |
| 582 | 630 | { |
| 583 | | //printf("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask); |
| 584 | | //logerror("%s:gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask); |
| 631 | //printf("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", machine->describe_context(), chip, data, offset, mem_mask); |
| 632 | //logerror("%s:state->gcu%d_w: %08X, %08X, %08X at %08X\n", cmachine->describe_context(), hip, data, offset, mem_mask); |
| 585 | 633 | } |
| 586 | 634 | |
| 587 | 635 | switch(reg) |
| r10427 | r10428 | |
| 598 | 646 | //case 0x38: |
| 599 | 647 | //case 0x3c: |
| 600 | 648 | { |
| 601 | | COMBINE_DATA( &gcu[chip].visible_area ); |
| 649 | COMBINE_DATA( &state->gcu[chip].visible_area ); |
| 602 | 650 | if (ACCESSING_BITS_0_15) |
| 603 | 651 | { |
| 604 | 652 | screen_device *screen = downcast<screen_device *>(machine->m_devicelist.find(SCREEN, chip)); |
| r10427 | r10428 | |
| 608 | 656 | rectangle visarea = screen->visible_area(); |
| 609 | 657 | int width, height; |
| 610 | 658 | |
| 611 | | width = (gcu[chip].visible_area & 0xffff); |
| 612 | | height = (gcu[chip].visible_area >> 16) & 0xffff; |
| 659 | width = (state->gcu[chip].visible_area & 0xffff); |
| 660 | height = (state->gcu[chip].visible_area >> 16) & 0xffff; |
| 613 | 661 | |
| 614 | 662 | visarea.max_x = width-1; |
| 615 | 663 | visarea.max_y = height-1; |
| r10427 | r10428 | |
| 627 | 675 | // break; |
| 628 | 676 | |
| 629 | 677 | case 0x5c: /* VRAM Read Address */ |
| 630 | | gcu[chip].vram_read_address = (data & 0xffffff) / 2; |
| 678 | state->gcu[chip].vram_read_address = (data & 0xffffff) / 2; |
| 631 | 679 | break; |
| 632 | 680 | |
| 633 | 681 | case 0x60: /* VRAM FIFO Write Address */ |
| 634 | | gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2; |
| 682 | state->gcu[chip].vram_write_fifo_address = (data & 0xffffff) / 2; |
| 635 | 683 | |
| 636 | 684 | // printf("gcu%d_w: %08X, %08X, %08X\n", chip, data, offset, mem_mask); |
| 637 | 685 | break; |
| r10427 | r10428 | |
| 642 | 690 | } |
| 643 | 691 | |
| 644 | 692 | case 0x70: /* VRAM FIFO Write */ |
| 645 | | gcu[chip].vram[gcu[chip].vram_write_fifo_address] = data; |
| 646 | | gcu[chip].vram_write_fifo_address++; |
| 693 | state->gcu[chip].vram[state->gcu[chip].vram_write_fifo_address] = data; |
| 694 | state->gcu[chip].vram_write_fifo_address++; |
| 647 | 695 | break; |
| 648 | 696 | |
| 649 | 697 | default: |
| r10427 | r10428 | |
| 654 | 702 | |
| 655 | 703 | static READ32_HANDLER(gcu0_r) |
| 656 | 704 | { |
| 657 | | return GCU_r(0, offset, mem_mask); |
| 705 | return GCU_r(space->machine, 0, offset, mem_mask); |
| 658 | 706 | } |
| 659 | 707 | |
| 660 | 708 | static WRITE32_HANDLER(gcu0_w) |
| r10427 | r10428 | |
| 664 | 712 | |
| 665 | 713 | static READ32_HANDLER(gcu1_r) |
| 666 | 714 | { |
| 667 | | return GCU_r(1, offset, mem_mask); |
| 715 | return GCU_r(space->machine, 1, offset, mem_mask); |
| 668 | 716 | } |
| 669 | 717 | |
| 670 | 718 | static WRITE32_HANDLER(gcu1_w) |
| r10427 | r10428 | |
| 708 | 756 | |
| 709 | 757 | static READ32_HANDLER(flashram_r) |
| 710 | 758 | { |
| 759 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 711 | 760 | UINT32 r = 0; |
| 712 | 761 | if (ACCESSING_BITS_24_31) |
| 713 | 762 | { |
| 714 | | r |= (flash[0]->read((offset*4)+0) & 0xff) << 24; |
| 763 | r |= (state->flash[0]->read((offset*4)+0) & 0xff) << 24; |
| 715 | 764 | } |
| 716 | 765 | if (ACCESSING_BITS_16_23) |
| 717 | 766 | { |
| 718 | | r |= (flash[0]->read((offset*4)+1) & 0xff) << 16; |
| 767 | r |= (state->flash[0]->read((offset*4)+1) & 0xff) << 16; |
| 719 | 768 | } |
| 720 | 769 | if (ACCESSING_BITS_8_15) |
| 721 | 770 | { |
| 722 | | r |= (flash[0]->read((offset*4)+2) & 0xff) << 8; |
| 771 | r |= (state->flash[0]->read((offset*4)+2) & 0xff) << 8; |
| 723 | 772 | } |
| 724 | 773 | if (ACCESSING_BITS_0_7) |
| 725 | 774 | { |
| 726 | | r |= (flash[0]->read((offset*4)+3) & 0xff) << 0; |
| 775 | r |= (state->flash[0]->read((offset*4)+3) & 0xff) << 0; |
| 727 | 776 | } |
| 728 | 777 | return r; |
| 729 | 778 | } |
| 730 | 779 | |
| 731 | 780 | static WRITE32_HANDLER(flashram_w) |
| 732 | 781 | { |
| 782 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 733 | 783 | if (ACCESSING_BITS_24_31) |
| 734 | 784 | { |
| 735 | | flash[0]->write((offset*4)+0, (data >> 24) & 0xff); |
| 785 | state->flash[0]->write((offset*4)+0, (data >> 24) & 0xff); |
| 736 | 786 | } |
| 737 | 787 | if (ACCESSING_BITS_16_23) |
| 738 | 788 | { |
| 739 | | flash[0]->write((offset*4)+1, (data >> 16) & 0xff); |
| 789 | state->flash[0]->write((offset*4)+1, (data >> 16) & 0xff); |
| 740 | 790 | } |
| 741 | 791 | if (ACCESSING_BITS_8_15) |
| 742 | 792 | { |
| 743 | | flash[0]->write((offset*4)+2, (data >> 8) & 0xff); |
| 793 | state->flash[0]->write((offset*4)+2, (data >> 8) & 0xff); |
| 744 | 794 | } |
| 745 | 795 | if (ACCESSING_BITS_0_7) |
| 746 | 796 | { |
| 747 | | flash[0]->write((offset*4)+3, (data >> 0) & 0xff); |
| 797 | state->flash[0]->write((offset*4)+3, (data >> 0) & 0xff); |
| 748 | 798 | } |
| 749 | 799 | } |
| 750 | 800 | |
| 751 | 801 | static READ32_HANDLER(soundflash_r) |
| 752 | 802 | { |
| 803 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 753 | 804 | UINT32 r = 0; |
| 754 | 805 | fujitsu_29f016a_device *chip; |
| 755 | 806 | if (offset >= 0 && offset < 0x200000/4) |
| 756 | 807 | { |
| 757 | | chip = flash[1]; |
| 808 | chip = state->flash[1]; |
| 758 | 809 | } |
| 759 | 810 | else |
| 760 | 811 | { |
| 761 | | chip = flash[2]; |
| 812 | chip = state->flash[2]; |
| 762 | 813 | } |
| 763 | 814 | |
| 764 | 815 | offset &= 0x7ffff; |
| r10427 | r10428 | |
| 784 | 835 | |
| 785 | 836 | static WRITE32_HANDLER(soundflash_w) |
| 786 | 837 | { |
| 838 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 787 | 839 | fujitsu_29f016a_device *chip; |
| 788 | 840 | if (offset >= 0 && offset < 0x200000/4) |
| 789 | 841 | { |
| 790 | | chip = flash[1]; |
| 842 | chip = state->flash[1]; |
| 791 | 843 | } |
| 792 | 844 | else |
| 793 | 845 | { |
| 794 | | chip = flash[2]; |
| 846 | chip = state->flash[2]; |
| 795 | 847 | } |
| 796 | 848 | |
| 797 | 849 | offset &= 0x7ffff; |
| r10427 | r10428 | |
| 827 | 879 | |
| 828 | 880 | #define ATAPI_CYCLES_PER_SECTOR (32000) // plenty of time to allow DMA setup etc. BIOS requires this be at least 2000, individual games may vary. |
| 829 | 881 | |
| 830 | | static UINT8 atapi_regs[16]; |
| 831 | | static SCSIInstance *atapi_device_data[2]; |
| 832 | 882 | |
| 833 | 883 | #define ATAPI_STAT_BSY 0x80 |
| 834 | 884 | #define ATAPI_STAT_DRDY 0x40 |
| r10427 | r10428 | |
| 851 | 901 | #define ATAPI_REG_DRIVESEL 6 |
| 852 | 902 | #define ATAPI_REG_CMDSTATUS 7 |
| 853 | 903 | |
| 854 | | static UINT16 atapi_data[32*1024]; |
| 855 | | static UINT8 atapi_scsi_packet[32*1024]; |
| 856 | | static int atapi_data_ptr, atapi_xferlen, atapi_xfermod, atapi_cdata_wait; |
| 857 | | static int atapi_drivesel; |
| 858 | 904 | |
| 859 | 905 | static void atapi_cause_irq(running_machine *machine) |
| 860 | 906 | { |
| r10427 | r10428 | |
| 868 | 914 | |
| 869 | 915 | static void atapi_exit(running_machine& machine) |
| 870 | 916 | { |
| 871 | | SCSIDeleteInstance(atapi_device_data[1]); |
| 872 | | SCSIDeleteInstance(atapi_device_data[0]); |
| 917 | firebeat_state *state = machine.driver_data<firebeat_state>(); |
| 918 | SCSIDeleteInstance(state->atapi_device_data[1]); |
| 919 | SCSIDeleteInstance(state->atapi_device_data[0]); |
| 873 | 920 | } |
| 874 | 921 | |
| 875 | 922 | static void atapi_init(running_machine *machine) |
| 876 | 923 | { |
| 877 | | memset(atapi_regs, 0, sizeof(atapi_regs)); |
| 924 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 925 | memset(state->atapi_regs, 0, sizeof(state->atapi_regs)); |
| 878 | 926 | |
| 879 | | atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 880 | | atapi_regs[ATAPI_REG_ERRFEAT] = 1; |
| 881 | | atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; |
| 882 | | atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; |
| 927 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 928 | state->atapi_regs[ATAPI_REG_ERRFEAT] = 1; |
| 929 | state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; |
| 930 | state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; |
| 883 | 931 | |
| 884 | | atapi_data_ptr = 0; |
| 885 | | atapi_cdata_wait = 0; |
| 932 | state->atapi_data_ptr = 0; |
| 933 | state->atapi_cdata_wait = 0; |
| 886 | 934 | |
| 887 | 935 | // allocate two SCSI CD-ROM devices |
| 888 | | SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[0], "scsi0" ); |
| 936 | SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[0], "scsi0" ); |
| 889 | 937 | // TODO: the slave drive can be either CD-ROM, DVD-ROM or HDD |
| 890 | | SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &atapi_device_data[1], "scsi1" ); |
| 938 | SCSIAllocInstance( machine, SCSI_DEVICE_CDROM, &state->atapi_device_data[1], "scsi1" ); |
| 891 | 939 | machine->add_notifier(MACHINE_NOTIFY_EXIT, atapi_exit); |
| 892 | 940 | } |
| 893 | 941 | |
| 894 | | static void atapi_reset(void) |
| 942 | static void atapi_reset(running_machine *machine) |
| 895 | 943 | { |
| 944 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 896 | 945 | logerror("ATAPI reset\n"); |
| 897 | 946 | |
| 898 | | atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 899 | | atapi_regs[ATAPI_REG_ERRFEAT] = 1; |
| 900 | | atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; |
| 901 | | atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; |
| 947 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 948 | state->atapi_regs[ATAPI_REG_ERRFEAT] = 1; |
| 949 | state->atapi_regs[ATAPI_REG_COUNTLOW] = 0x14; |
| 950 | state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0xeb; |
| 902 | 951 | |
| 903 | | atapi_data_ptr = 0; |
| 904 | | atapi_cdata_wait = 0; |
| 952 | state->atapi_data_ptr = 0; |
| 953 | state->atapi_cdata_wait = 0; |
| 905 | 954 | } |
| 906 | 955 | |
| 907 | 956 | |
| 908 | 957 | |
| 909 | 958 | static UINT16 atapi_command_reg_r(running_machine *machine, int reg) |
| 910 | 959 | { |
| 960 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 911 | 961 | int i, data; |
| 912 | | static UINT8 temp_data[64*1024]; |
| 913 | 962 | |
| 914 | 963 | // printf("ATAPI: Command reg read %d\n", reg); |
| 915 | 964 | |
| 916 | 965 | if (reg == ATAPI_REG_DATA) |
| 917 | 966 | { |
| 918 | 967 | // assert IRQ and drop DRQ |
| 919 | | if (atapi_data_ptr == 0) |
| 968 | if (state->atapi_data_ptr == 0) |
| 920 | 969 | { |
| 921 | 970 | //printf("ATAPI: dropping DRQ\n"); |
| 922 | 971 | atapi_cause_irq(machine); |
| 923 | | atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 972 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 924 | 973 | |
| 925 | 974 | // get the data from the device |
| 926 | | SCSIReadData( atapi_device_data[atapi_drivesel], temp_data, atapi_xferlen ); |
| 975 | SCSIReadData( state->atapi_device_data[state->atapi_drivesel], state->temp_data, state->atapi_xferlen ); |
| 927 | 976 | |
| 928 | 977 | // fix it up in an endian-safe way |
| 929 | | for (i = 0; i < atapi_xferlen; i += 2) |
| 978 | for (i = 0; i < state->atapi_xferlen; i += 2) |
| 930 | 979 | { |
| 931 | | atapi_data[i/2] = temp_data[i+0] | temp_data[i+1]<<8; |
| 980 | state->atapi_data[i/2] = state->temp_data[i+0] | state->temp_data[i+1]<<8; |
| 932 | 981 | } |
| 933 | 982 | } |
| 934 | 983 | |
| 935 | | data = atapi_data[atapi_data_ptr]; |
| 936 | | // printf("ATAPI: %d, packet read = %04x\n", atapi_data_ptr, atapi_data[atapi_data_ptr]); |
| 937 | | atapi_data_ptr++; |
| 984 | data = state->atapi_data[state->atapi_data_ptr]; |
| 985 | // printf("ATAPI: %d, packet read = %04x\n", state->atapi_data_ptr, state->atapi_data[state->atapi_data_ptr]); |
| 986 | state->atapi_data_ptr++; |
| 938 | 987 | |
| 939 | | if (atapi_xfermod && atapi_data_ptr == (atapi_xferlen/2)) |
| 988 | if (state->atapi_xfermod && state->atapi_data_ptr == (state->atapi_xferlen/2)) |
| 940 | 989 | { |
| 941 | 990 | //printf("ATAPI: DRQ interrupt\n"); |
| 942 | 991 | atapi_cause_irq(machine); |
| 943 | | atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ; |
| 944 | | atapi_data_ptr = 0; |
| 992 | state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_DRQ; |
| 993 | state->atapi_data_ptr = 0; |
| 945 | 994 | |
| 946 | | if (atapi_xfermod > 63488) |
| 995 | if (state->atapi_xfermod > 63488) |
| 947 | 996 | { |
| 948 | | atapi_xfermod = atapi_xfermod - 63488; |
| 949 | | atapi_xferlen = 63488; |
| 997 | state->atapi_xfermod = state->atapi_xfermod - 63488; |
| 998 | state->atapi_xferlen = 63488; |
| 950 | 999 | } |
| 951 | 1000 | else |
| 952 | 1001 | { |
| 953 | | atapi_xferlen = atapi_xfermod; |
| 954 | | atapi_xfermod = 0; |
| 1002 | state->atapi_xferlen = state->atapi_xfermod; |
| 1003 | state->atapi_xfermod = 0; |
| 955 | 1004 | } |
| 956 | 1005 | |
| 957 | | //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, atapi_xfermod, atapi_xferlen); |
| 1006 | //printf("ATAPI Transfer: %d, %d, %d\n", atapi_transfer_length, state->atapi_xfermod, state->atapi_xferlen); |
| 958 | 1007 | |
| 959 | | atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; |
| 960 | | atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; |
| 1008 | state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; |
| 1009 | state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; |
| 961 | 1010 | } |
| 962 | 1011 | return data; |
| 963 | 1012 | } |
| r10427 | r10428 | |
| 965 | 1014 | { |
| 966 | 1015 | if (reg == ATAPI_REG_CMDSTATUS) |
| 967 | 1016 | atapi_clear_irq(machine); |
| 968 | | return atapi_regs[reg]; |
| 1017 | return state->atapi_regs[reg]; |
| 969 | 1018 | } |
| 970 | 1019 | } |
| 971 | 1020 | |
| 972 | 1021 | static void atapi_command_reg_w(running_machine *machine, int reg, UINT16 data) |
| 973 | 1022 | { |
| 1023 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 974 | 1024 | int i; |
| 975 | 1025 | |
| 976 | 1026 | if (reg == ATAPI_REG_DATA) |
| 977 | 1027 | { |
| 978 | 1028 | // printf("%s:ATAPI: packet write %04x\n", device->machine->describe_context(), data); |
| 979 | | atapi_data[atapi_data_ptr] = data; |
| 980 | | atapi_data_ptr++; |
| 1029 | state->atapi_data[state->atapi_data_ptr] = data; |
| 1030 | state->atapi_data_ptr++; |
| 981 | 1031 | |
| 982 | | if (atapi_cdata_wait) |
| 1032 | if (state->atapi_cdata_wait) |
| 983 | 1033 | { |
| 984 | | // printf("ATAPI: waiting, ptr %d wait %d\n", atapi_data_ptr, atapi_cdata_wait); |
| 985 | | if (atapi_data_ptr == atapi_cdata_wait) |
| 1034 | // printf("ATAPI: waiting, ptr %d wait %d\n", state->atapi_data_ptr, state->atapi_cdata_wait); |
| 1035 | if (state->atapi_data_ptr == state->atapi_cdata_wait) |
| 986 | 1036 | { |
| 987 | 1037 | // decompose SCSI packet into proper byte order |
| 988 | | for (i = 0; i < atapi_cdata_wait; i += 2) |
| 1038 | for (i = 0; i < state->atapi_cdata_wait; i += 2) |
| 989 | 1039 | { |
| 990 | | atapi_scsi_packet[i] = atapi_data[i/2]&0xff; |
| 991 | | atapi_scsi_packet[i+1] = atapi_data[i/2]>>8; |
| 1040 | state->atapi_scsi_packet[i] = state->atapi_data[i/2]&0xff; |
| 1041 | state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8; |
| 992 | 1042 | } |
| 993 | 1043 | |
| 994 | 1044 | // send it to the device |
| 995 | | SCSIWriteData( atapi_device_data[atapi_drivesel], atapi_scsi_packet, atapi_cdata_wait ); |
| 1045 | SCSIWriteData( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, state->atapi_cdata_wait ); |
| 996 | 1046 | |
| 997 | 1047 | // assert IRQ |
| 998 | 1048 | atapi_cause_irq(machine); |
| 999 | 1049 | |
| 1000 | 1050 | // not sure here, but clear DRQ at least? |
| 1001 | | atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 1051 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 1002 | 1052 | } |
| 1003 | 1053 | } |
| 1004 | 1054 | |
| 1005 | | if ((!atapi_cdata_wait) && (atapi_data_ptr == 6)) |
| 1055 | if ((!state->atapi_cdata_wait) && (state->atapi_data_ptr == 6)) |
| 1006 | 1056 | { |
| 1007 | 1057 | int phase; |
| 1008 | 1058 | |
| 1009 | 1059 | // reset data pointer for reading SCSI results |
| 1010 | | atapi_data_ptr = 0; |
| 1060 | state->atapi_data_ptr = 0; |
| 1011 | 1061 | |
| 1012 | | atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY; |
| 1062 | state->atapi_regs[ATAPI_REG_CMDSTATUS] |= ATAPI_STAT_BSY; |
| 1013 | 1063 | |
| 1014 | 1064 | // assert IRQ |
| 1015 | 1065 | atapi_cause_irq(machine); |
| r10427 | r10428 | |
| 1017 | 1067 | // decompose SCSI packet into proper byte order |
| 1018 | 1068 | for (i = 0; i < 16; i += 2) |
| 1019 | 1069 | { |
| 1020 | | atapi_scsi_packet[i+0] = atapi_data[i/2]&0xff; |
| 1021 | | atapi_scsi_packet[i+1] = atapi_data[i/2]>>8; |
| 1070 | state->atapi_scsi_packet[i+0] = state->atapi_data[i/2]&0xff; |
| 1071 | state->atapi_scsi_packet[i+1] = state->atapi_data[i/2]>>8; |
| 1022 | 1072 | } |
| 1023 | 1073 | |
| 1024 | 1074 | // send it to the SCSI device |
| 1025 | | SCSISetCommand( atapi_device_data[atapi_drivesel], atapi_scsi_packet, 12 ); |
| 1026 | | SCSIExecCommand( atapi_device_data[atapi_drivesel], &atapi_xferlen ); |
| 1027 | | SCSIGetPhase( atapi_device_data[atapi_drivesel], &phase ); |
| 1075 | SCSISetCommand( state->atapi_device_data[state->atapi_drivesel], state->atapi_scsi_packet, 12 ); |
| 1076 | SCSIExecCommand( state->atapi_device_data[state->atapi_drivesel], &state->atapi_xferlen ); |
| 1077 | SCSIGetPhase( state->atapi_device_data[state->atapi_drivesel], &phase ); |
| 1028 | 1078 | |
| 1029 | | if (atapi_xferlen != -1) |
| 1079 | if (state->atapi_xferlen != -1) |
| 1030 | 1080 | { |
| 1031 | | logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", atapi_data[0]&0xff, atapi_xferlen); |
| 1081 | logerror("ATAPI: SCSI command %02x returned %d bytes from the device\n", state->atapi_data[0]&0xff, state->atapi_xferlen); |
| 1032 | 1082 | |
| 1033 | 1083 | // store the returned command length in the ATAPI regs, splitting into |
| 1034 | 1084 | // multiple transfers if necessary |
| 1035 | 1085 | |
| 1036 | | atapi_xfermod = 0; |
| 1037 | | if (atapi_xferlen > 63488) |
| 1086 | state->atapi_xfermod = 0; |
| 1087 | if (state->atapi_xferlen > 63488) |
| 1038 | 1088 | { |
| 1039 | | atapi_xfermod = atapi_xferlen - 63488; |
| 1040 | | atapi_xferlen = 63488; |
| 1089 | state->atapi_xfermod = state->atapi_xferlen - 63488; |
| 1090 | state->atapi_xferlen = 63488; |
| 1041 | 1091 | } |
| 1042 | 1092 | |
| 1043 | | // printf("ATAPI Transfer: %d, %d\n", atapi_xfermod, atapi_xferlen); |
| 1093 | // printf("ATAPI Transfer: %d, %d\n", state->atapi_xfermod, state->atapi_xferlen); |
| 1044 | 1094 | |
| 1045 | | atapi_regs[ATAPI_REG_COUNTLOW] = atapi_xferlen & 0xff; |
| 1046 | | atapi_regs[ATAPI_REG_COUNTHIGH] = (atapi_xferlen>>8)&0xff; |
| 1095 | state->atapi_regs[ATAPI_REG_COUNTLOW] = state->atapi_xferlen & 0xff; |
| 1096 | state->atapi_regs[ATAPI_REG_COUNTHIGH] = (state->atapi_xferlen>>8)&0xff; |
| 1047 | 1097 | |
| 1048 | 1098 | switch( phase ) |
| 1049 | 1099 | { |
| 1050 | 1100 | case SCSI_PHASE_DATAOUT: |
| 1051 | | atapi_data_ptr = 0; |
| 1052 | | atapi_cdata_wait = atapi_xferlen; |
| 1053 | | logerror("ATAPI: Waiting for %x bytes of data\n", atapi_cdata_wait); |
| 1101 | state->atapi_data_ptr = 0; |
| 1102 | state->atapi_cdata_wait = state->atapi_xferlen; |
| 1103 | logerror("ATAPI: Waiting for %x bytes of data\n", state->atapi_cdata_wait); |
| 1054 | 1104 | break; |
| 1055 | 1105 | } |
| 1056 | 1106 | |
| 1057 | 1107 | // perform special ATAPI processing of certain commands |
| 1058 | | switch (atapi_data[0]&0xff) |
| 1108 | switch (state->atapi_data[0]&0xff) |
| 1059 | 1109 | { |
| 1060 | 1110 | case 0xa8: // READ (12) |
| 1061 | 1111 | // indicate data ready: set DRQ and DMA ready, and IO in INTREASON |
| 1062 | | atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC; |
| 1063 | | atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; |
| 1112 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_SERVDSC; |
| 1113 | state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_IO; |
| 1064 | 1114 | |
| 1065 | 1115 | fatalerror("ATAPI: DMA read command attempted\n"); |
| 1066 | 1116 | break; |
| r10427 | r10428 | |
| 1070 | 1120 | case 0xa5: // PLAY AUDIO |
| 1071 | 1121 | case 0x1b: |
| 1072 | 1122 | case 0x4e: |
| 1073 | | atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 1123 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = 0; |
| 1074 | 1124 | break; |
| 1075 | 1125 | } |
| 1076 | 1126 | } |
| r10427 | r10428 | |
| 1078 | 1128 | { |
| 1079 | 1129 | // printf("ATAPI: SCSI device returned error!\n"); |
| 1080 | 1130 | |
| 1081 | | atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK; |
| 1082 | | atapi_regs[ATAPI_REG_ERRFEAT] = 0x50; // sense key = ILLEGAL REQUEST |
| 1083 | | atapi_regs[ATAPI_REG_COUNTLOW] = 0; |
| 1084 | | atapi_regs[ATAPI_REG_COUNTHIGH] = 0; |
| 1131 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_DRQ | ATAPI_STAT_CHECK; |
| 1132 | state->atapi_regs[ATAPI_REG_ERRFEAT] = 0x50; // sense key = ILLEGAL REQUEST |
| 1133 | state->atapi_regs[ATAPI_REG_COUNTLOW] = 0; |
| 1134 | state->atapi_regs[ATAPI_REG_COUNTHIGH] = 0; |
| 1085 | 1135 | } |
| 1086 | 1136 | } |
| 1087 | 1137 | } |
| 1088 | 1138 | else |
| 1089 | 1139 | { |
| 1090 | 1140 | data &= 0xff; |
| 1091 | | atapi_regs[reg] = data; |
| 1141 | state->atapi_regs[reg] = data; |
| 1092 | 1142 | // printf("ATAPI: Command reg %d = %02X\n", reg, data); |
| 1093 | 1143 | |
| 1094 | 1144 | switch(reg) |
| 1095 | 1145 | { |
| 1096 | 1146 | case ATAPI_REG_DRIVESEL: |
| 1097 | | atapi_drivesel = (data >> 4) & 0x1; |
| 1147 | state->atapi_drivesel = (data >> 4) & 0x1; |
| 1098 | 1148 | break; |
| 1099 | 1149 | |
| 1100 | 1150 | case ATAPI_REG_CMDSTATUS: |
| r10427 | r10428 | |
| 1106 | 1156 | break; |
| 1107 | 1157 | |
| 1108 | 1158 | case 0x08: /* ATAPI Soft Reset */ |
| 1109 | | atapi_reset(); |
| 1159 | atapi_reset(machine); |
| 1110 | 1160 | break; |
| 1111 | 1161 | |
| 1112 | 1162 | case 0xa0: /* ATAPI Packet */ |
| 1113 | | atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ; |
| 1114 | | atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND; |
| 1163 | state->atapi_regs[ATAPI_REG_CMDSTATUS] = ATAPI_STAT_BSY | ATAPI_STAT_DRQ; |
| 1164 | state->atapi_regs[ATAPI_REG_INTREASON] = ATAPI_INTREASON_COMMAND; |
| 1115 | 1165 | |
| 1116 | | atapi_data_ptr = 0; |
| 1117 | | atapi_cdata_wait = 0; |
| 1166 | state->atapi_data_ptr = 0; |
| 1167 | state->atapi_cdata_wait = 0; |
| 1118 | 1168 | break; |
| 1119 | 1169 | |
| 1120 | 1170 | default: |
| r10427 | r10428 | |
| 1125 | 1175 | } |
| 1126 | 1176 | } |
| 1127 | 1177 | |
| 1128 | | static UINT16 atapi_control_reg_r(int reg) |
| 1178 | static UINT16 atapi_control_reg_r(running_machine *machine, int reg) |
| 1129 | 1179 | { |
| 1180 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 1130 | 1181 | UINT16 value; |
| 1131 | 1182 | switch(reg) |
| 1132 | 1183 | { |
| 1133 | 1184 | case 0x6: |
| 1134 | 1185 | { |
| 1135 | | value = atapi_regs[ATAPI_REG_CMDSTATUS]; |
| 1136 | | if (atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY) |
| 1186 | value = state->atapi_regs[ATAPI_REG_CMDSTATUS]; |
| 1187 | if (state->atapi_regs[ATAPI_REG_CMDSTATUS] & ATAPI_STAT_BSY) |
| 1137 | 1188 | { |
| 1138 | | atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY; |
| 1189 | state->atapi_regs[ATAPI_REG_CMDSTATUS] ^= ATAPI_STAT_BSY; |
| 1139 | 1190 | } |
| 1140 | 1191 | return value; |
| 1141 | 1192 | } |
| r10427 | r10428 | |
| 1148 | 1199 | return 0; |
| 1149 | 1200 | } |
| 1150 | 1201 | |
| 1151 | | static void atapi_control_reg_w(int reg, UINT16 data) |
| 1202 | static void atapi_control_reg_w(running_machine *machine, int reg, UINT16 data) |
| 1152 | 1203 | { |
| 1153 | 1204 | switch(reg) |
| 1154 | 1205 | { |
| r10427 | r10428 | |
| 1156 | 1207 | { |
| 1157 | 1208 | if (data & 0x4) |
| 1158 | 1209 | { |
| 1159 | | atapi_reset(); |
| 1210 | atapi_reset(machine); |
| 1160 | 1211 | } |
| 1161 | 1212 | break; |
| 1162 | 1213 | } |
| r10427 | r10428 | |
| 1206 | 1257 | |
| 1207 | 1258 | if (ACCESSING_BITS_16_31) |
| 1208 | 1259 | { |
| 1209 | | r = atapi_control_reg_r(offset*2); |
| 1260 | r = atapi_control_reg_r(space->machine, offset*2); |
| 1210 | 1261 | return ATAPI_ENDIAN(r) << 16; |
| 1211 | 1262 | } |
| 1212 | 1263 | else |
| 1213 | 1264 | { |
| 1214 | | r = atapi_control_reg_r((offset*2) + 1); |
| 1265 | r = atapi_control_reg_r(space->machine, (offset*2) + 1); |
| 1215 | 1266 | return ATAPI_ENDIAN(r) << 0; |
| 1216 | 1267 | } |
| 1217 | 1268 | } |
| r10427 | r10428 | |
| 1220 | 1271 | { |
| 1221 | 1272 | if (ACCESSING_BITS_16_31) |
| 1222 | 1273 | { |
| 1223 | | atapi_control_reg_w(offset*2, ATAPI_ENDIAN(data >> 16) & 0xff); |
| 1274 | atapi_control_reg_w(space->machine, offset*2, ATAPI_ENDIAN(data >> 16) & 0xff); |
| 1224 | 1275 | } |
| 1225 | 1276 | else |
| 1226 | 1277 | { |
| 1227 | | atapi_control_reg_w((offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff); |
| 1278 | atapi_control_reg_w(space->machine, (offset*2) + 1, ATAPI_ENDIAN(data >> 0) & 0xff); |
| 1228 | 1279 | } |
| 1229 | 1280 | } |
| 1230 | 1281 | |
| r10427 | r10428 | |
| 1286 | 1337 | static const int cab_data[2] = { 0x0, 0x8 }; |
| 1287 | 1338 | static const int kbm_cab_data[2] = { 0x2, 0x8 }; |
| 1288 | 1339 | static const int ppd_cab_data[2] = { 0x1, 0x9 }; |
| 1289 | | static int cab_data_ptr = 0; |
| 1290 | | static const int * cur_cab_data; |
| 1291 | 1340 | |
| 1292 | 1341 | static READ32_HANDLER( cabinet_r ) |
| 1293 | 1342 | { |
| 1343 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1294 | 1344 | UINT32 r = 0; |
| 1295 | 1345 | |
| 1296 | 1346 | // printf("cabinet_r: %08X, %08X\n", offset, mem_mask); |
| r10427 | r10428 | |
| 1299 | 1349 | { |
| 1300 | 1350 | case 0: |
| 1301 | 1351 | { |
| 1302 | | r = cur_cab_data[cab_data_ptr & 1] << 28; |
| 1303 | | cab_data_ptr++; |
| 1352 | r = state->cur_cab_data[state->cab_data_ptr & 1] << 28; |
| 1353 | state->cab_data_ptr++; |
| 1304 | 1354 | return r; |
| 1305 | 1355 | } |
| 1306 | 1356 | case 2: return 0x00000000; |
| r10427 | r10428 | |
| 1348 | 1398 | |
| 1349 | 1399 | static void midi_uart_irq_callback(running_machine *machine, int channel, int value) |
| 1350 | 1400 | { |
| 1401 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 1351 | 1402 | if (channel == 0) |
| 1352 | 1403 | { |
| 1353 | | if ((extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE) |
| 1404 | if ((state->extend_board_irq_enable & 0x02) == 0 && value != CLEAR_LINE) |
| 1354 | 1405 | { |
| 1355 | | extend_board_irq_active |= 0x02; |
| 1406 | state->extend_board_irq_active |= 0x02; |
| 1356 | 1407 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE); |
| 1357 | 1408 | } |
| 1358 | 1409 | else |
| r10427 | r10428 | |
| 1360 | 1411 | } |
| 1361 | 1412 | else |
| 1362 | 1413 | { |
| 1363 | | if ((extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE) |
| 1414 | if ((state->extend_board_irq_enable & 0x01) == 0 && value != CLEAR_LINE) |
| 1364 | 1415 | { |
| 1365 | | extend_board_irq_active |= 0x01; |
| 1416 | state->extend_board_irq_active |= 0x01; |
| 1366 | 1417 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_IRQ1, ASSERT_LINE); |
| 1367 | 1418 | } |
| 1368 | 1419 | else |
| r10427 | r10428 | |
| 1370 | 1421 | } |
| 1371 | 1422 | } |
| 1372 | 1423 | |
| 1373 | | static int keyboard_state[2] = { 0, 0 }; |
| 1374 | 1424 | |
| 1375 | 1425 | static const int keyboard_notes[24] = |
| 1376 | 1426 | { |
| r10427 | r10428 | |
| 1402 | 1452 | |
| 1403 | 1453 | static TIMER_CALLBACK( keyboard_timer_callback ) |
| 1404 | 1454 | { |
| 1455 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 1405 | 1456 | static const int kb_uart_channel[2] = { 1, 0 }; |
| 1406 | 1457 | static const char *const keynames[] = { "KEYBOARD_P1", "KEYBOARD_P2" }; |
| 1407 | 1458 | int keyboard; |
| r10427 | r10428 | |
| 1412 | 1463 | UINT32 kbstate = input_port_read(machine, keynames[keyboard]); |
| 1413 | 1464 | int uart_channel = kb_uart_channel[keyboard]; |
| 1414 | 1465 | |
| 1415 | | if (kbstate != keyboard_state[keyboard]) |
| 1466 | if (kbstate != state->keyboard_state[keyboard]) |
| 1416 | 1467 | { |
| 1417 | 1468 | for (i=0; i < 24; i++) |
| 1418 | 1469 | { |
| 1419 | 1470 | int kbnote = keyboard_notes[i]; |
| 1420 | 1471 | |
| 1421 | | if ((keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) |
| 1472 | if ((state->keyboard_state[keyboard] & (1 << i)) != 0 && (kbstate & (1 << i)) == 0) |
| 1422 | 1473 | { |
| 1423 | 1474 | // key was on, now off -> send Note Off message |
| 1424 | 1475 | pc16552d_rx_data(machine, 1, uart_channel, 0x80); |
| 1425 | 1476 | pc16552d_rx_data(machine, 1, uart_channel, kbnote); |
| 1426 | 1477 | pc16552d_rx_data(machine, 1, uart_channel, 0x7f); |
| 1427 | 1478 | } |
| 1428 | | else if ((keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) |
| 1479 | else if ((state->keyboard_state[keyboard] & (1 << i)) == 0 && (kbstate & (1 << i)) != 0) |
| 1429 | 1480 | { |
| 1430 | 1481 | // key was off, now on -> send Note On message |
| 1431 | 1482 | pc16552d_rx_data(machine, 1, uart_channel, 0x90); |
| r10427 | r10428 | |
| 1440 | 1491 | pc16552d_rx_data(machine, 1, uart_channel, 0xfe); |
| 1441 | 1492 | } |
| 1442 | 1493 | |
| 1443 | | keyboard_state[keyboard] = kbstate; |
| 1494 | state->keyboard_state[keyboard] = kbstate; |
| 1444 | 1495 | } |
| 1445 | 1496 | } |
| 1446 | 1497 | |
| r10427 | r10428 | |
| 1454 | 1505 | |
| 1455 | 1506 | static READ32_HANDLER( extend_board_irq_r) |
| 1456 | 1507 | { |
| 1508 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1457 | 1509 | UINT32 r = 0; |
| 1458 | 1510 | |
| 1459 | 1511 | if (ACCESSING_BITS_24_31) |
| 1460 | 1512 | { |
| 1461 | | r |= (~extend_board_irq_active) << 24; |
| 1513 | r |= (~state->extend_board_irq_active) << 24; |
| 1462 | 1514 | } |
| 1463 | 1515 | |
| 1464 | 1516 | return r; |
| r10427 | r10428 | |
| 1466 | 1518 | |
| 1467 | 1519 | static WRITE32_HANDLER( extend_board_irq_w ) |
| 1468 | 1520 | { |
| 1521 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1469 | 1522 | // printf("extend_board_irq_w: %08X, %08X, %08X\n", data, offset, mem_mask); |
| 1470 | 1523 | |
| 1471 | 1524 | if (ACCESSING_BITS_24_31) |
| 1472 | 1525 | { |
| 1473 | | extend_board_irq_active &= ~((data >> 24) & 0xff); |
| 1526 | state->extend_board_irq_active &= ~((data >> 24) & 0xff); |
| 1474 | 1527 | |
| 1475 | | extend_board_irq_enable = (data >> 24) & 0xff; |
| 1528 | state->extend_board_irq_enable = (data >> 24) & 0xff; |
| 1476 | 1529 | } |
| 1477 | 1530 | } |
| 1478 | 1531 | |
| r10427 | r10428 | |
| 1616 | 1669 | |
| 1617 | 1670 | /*****************************************************************************/ |
| 1618 | 1671 | |
| 1619 | | static UINT8 spu_shared_ram[0x400]; |
| 1620 | 1672 | |
| 1621 | 1673 | static READ32_HANDLER(ppc_spu_share_r) |
| 1622 | 1674 | { |
| 1675 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1623 | 1676 | UINT32 r = 0; |
| 1624 | 1677 | |
| 1625 | 1678 | if (ACCESSING_BITS_24_31) |
| 1626 | 1679 | { |
| 1627 | | r |= spu_shared_ram[(offset * 4) + 0] << 24; |
| 1680 | r |= state->spu_shared_ram[(offset * 4) + 0] << 24; |
| 1628 | 1681 | } |
| 1629 | 1682 | if (ACCESSING_BITS_16_23) |
| 1630 | 1683 | { |
| 1631 | | r |= spu_shared_ram[(offset * 4) + 1] << 16; |
| 1684 | r |= state->spu_shared_ram[(offset * 4) + 1] << 16; |
| 1632 | 1685 | } |
| 1633 | 1686 | if (ACCESSING_BITS_8_15) |
| 1634 | 1687 | { |
| 1635 | | r |= spu_shared_ram[(offset * 4) + 2] << 8; |
| 1688 | r |= state->spu_shared_ram[(offset * 4) + 2] << 8; |
| 1636 | 1689 | } |
| 1637 | 1690 | if (ACCESSING_BITS_0_7) |
| 1638 | 1691 | { |
| 1639 | | r |= spu_shared_ram[(offset * 4) + 3] << 0; |
| 1692 | r |= state->spu_shared_ram[(offset * 4) + 3] << 0; |
| 1640 | 1693 | } |
| 1641 | 1694 | |
| 1642 | 1695 | return r; |
| r10427 | r10428 | |
| 1644 | 1697 | |
| 1645 | 1698 | static WRITE32_HANDLER(ppc_spu_share_w) |
| 1646 | 1699 | { |
| 1700 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1647 | 1701 | if (ACCESSING_BITS_24_31) |
| 1648 | 1702 | { |
| 1649 | | spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff; |
| 1703 | state->spu_shared_ram[(offset * 4) + 0] = (data >> 24) & 0xff; |
| 1650 | 1704 | } |
| 1651 | 1705 | if (ACCESSING_BITS_16_23) |
| 1652 | 1706 | { |
| 1653 | | spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff; |
| 1707 | state->spu_shared_ram[(offset * 4) + 1] = (data >> 16) & 0xff; |
| 1654 | 1708 | } |
| 1655 | 1709 | if (ACCESSING_BITS_8_15) |
| 1656 | 1710 | { |
| 1657 | | spu_shared_ram[(offset * 4) + 2] = (data >> 8) & 0xff; |
| 1711 | state->spu_shared_ram[(offset * 4) + 2] = (data >> 8) & 0xff; |
| 1658 | 1712 | } |
| 1659 | 1713 | if (ACCESSING_BITS_0_7) |
| 1660 | 1714 | { |
| 1661 | | spu_shared_ram[(offset * 4) + 3] = (data >> 0) & 0xff; |
| 1715 | state->spu_shared_ram[(offset * 4) + 3] = (data >> 0) & 0xff; |
| 1662 | 1716 | } |
| 1663 | 1717 | } |
| 1664 | 1718 | |
| 1665 | 1719 | #ifdef UNUSED_FUNCTION |
| 1666 | 1720 | static READ16_HANDLER(m68k_spu_share_r) |
| 1667 | 1721 | { |
| 1668 | | return spu_shared_ram[offset] << 8; |
| 1722 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1723 | return state->spu_shared_ram[offset] << 8; |
| 1669 | 1724 | } |
| 1670 | 1725 | |
| 1671 | 1726 | static WRITE16_HANDLER(m68k_spu_share_w) |
| 1672 | 1727 | { |
| 1673 | | spu_shared_ram[offset] = (data >> 8) & 0xff; |
| 1728 | firebeat_state *state = space->machine->driver_data<firebeat_state>(); |
| 1729 | state->spu_shared_ram[offset] = (data >> 8) & 0xff; |
| 1674 | 1730 | } |
| 1675 | 1731 | #endif |
| 1676 | 1732 | |
| r10427 | r10428 | |
| 1681 | 1737 | |
| 1682 | 1738 | /*****************************************************************************/ |
| 1683 | 1739 | |
| 1684 | | static UINT32 *work_ram; |
| 1685 | 1740 | static MACHINE_START( firebeat ) |
| 1686 | 1741 | { |
| 1742 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 1687 | 1743 | /* set conservative DRC options */ |
| 1688 | 1744 | ppcdrc_set_options(machine->device("maincpu"), PPCDRC_COMPATIBLE_OPTIONS); |
| 1689 | 1745 | |
| 1690 | 1746 | /* configure fast RAM regions for DRC */ |
| 1691 | | ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, work_ram); |
| 1747 | ppcdrc_add_fastram(machine->device("maincpu"), 0x00000000, 0x01ffffff, FALSE, state->work_ram); |
| 1692 | 1748 | |
| 1693 | | flash[0] = machine->device<fujitsu_29f016a_device>("flash0"); |
| 1694 | | flash[1] = machine->device<fujitsu_29f016a_device>("flash1"); |
| 1695 | | flash[2] = machine->device<fujitsu_29f016a_device>("flash2"); |
| 1749 | state->flash[0] = machine->device<fujitsu_29f016a_device>("flash0"); |
| 1750 | state->flash[1] = machine->device<fujitsu_29f016a_device>("flash1"); |
| 1751 | state->flash[2] = machine->device<fujitsu_29f016a_device>("flash2"); |
| 1696 | 1752 | } |
| 1697 | 1753 | |
| 1698 | 1754 | static ADDRESS_MAP_START( firebeat_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| 1699 | | AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE(&work_ram) |
| 1755 | AM_RANGE(0x00000000, 0x01ffffff) AM_RAM AM_BASE_MEMBER(firebeat_state, work_ram) |
| 1700 | 1756 | AM_RANGE(0x70000000, 0x70000fff) AM_READWRITE(midi_uart_r, midi_uart_w) |
| 1701 | 1757 | AM_RANGE(0x70006000, 0x70006003) AM_WRITE(extend_board_irq_w) |
| 1702 | 1758 | AM_RANGE(0x70008000, 0x7000800f) AM_READ(keyboard_wheel_r) |
| r10427 | r10428 | |
| 1728 | 1784 | |
| 1729 | 1785 | static READ8_DEVICE_HANDLER( soundram_r ) |
| 1730 | 1786 | { |
| 1787 | firebeat_state *state = device->machine->driver_data<firebeat_state>(); |
| 1731 | 1788 | if (offset >= 0 && offset < 0x200000) |
| 1732 | 1789 | { |
| 1733 | | return flash[1]->read(offset & 0x1fffff); |
| 1790 | return state->flash[1]->read(offset & 0x1fffff); |
| 1734 | 1791 | } |
| 1735 | 1792 | else if (offset >= 0x200000 && offset < 0x400000) |
| 1736 | 1793 | { |
| 1737 | | return flash[2]->read(offset & 0x1fffff); |
| 1794 | return state->flash[2]->read(offset & 0x1fffff); |
| 1738 | 1795 | } |
| 1739 | 1796 | return 0; |
| 1740 | 1797 | } |
| r10427 | r10428 | |
| 1897 | 1954 | |
| 1898 | 1955 | static MACHINE_RESET( firebeat ) |
| 1899 | 1956 | { |
| 1957 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 1900 | 1958 | void *cd; |
| 1901 | 1959 | int i; |
| 1902 | 1960 | UINT8 *sound = machine->region("ymz")->base(); |
| 1903 | 1961 | |
| 1904 | 1962 | for (i=0; i < 0x200000; i++) |
| 1905 | 1963 | { |
| 1906 | | sound[i] = flash[1]->read(i); |
| 1907 | | sound[i+0x200000] = flash[2]->read(i); |
| 1964 | sound[i] = state->flash[1]->read(i); |
| 1965 | sound[i+0x200000] = state->flash[2]->read(i); |
| 1908 | 1966 | } |
| 1909 | 1967 | |
| 1910 | | SCSIGetDevice( atapi_device_data[1], &cd ); |
| 1968 | SCSIGetDevice( state->atapi_device_data[1], &cd ); |
| 1911 | 1969 | cdda_set_cdrom(machine->device("cdda"), cd); |
| 1912 | 1970 | } |
| 1913 | 1971 | |
| 1914 | | static MACHINE_CONFIG_START( firebeat, driver_device ) |
| 1972 | static MACHINE_CONFIG_START( firebeat, firebeat_state ) |
| 1915 | 1973 | |
| 1916 | 1974 | /* basic machine hardware */ |
| 1917 | 1975 | MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000) |
| r10427 | r10428 | |
| 1955 | 2013 | |
| 1956 | 2014 | MACHINE_CONFIG_END |
| 1957 | 2015 | |
| 1958 | | static MACHINE_CONFIG_START( firebeat2, driver_device ) |
| 2016 | static MACHINE_CONFIG_START( firebeat2, firebeat_state ) |
| 1959 | 2017 | |
| 1960 | 2018 | /* basic machine hardware */ |
| 1961 | 2019 | MCFG_CPU_ADD("maincpu", PPC403GCX, 66000000) |
| r10427 | r10428 | |
| 2015 | 2073 | /*****************************************************************************/ |
| 2016 | 2074 | /* Security dongle is a Dallas DS1411 RS232 Adapter with a DS1991 Multikey iButton */ |
| 2017 | 2075 | |
| 2018 | | typedef struct |
| 2019 | | { |
| 2020 | | UINT8 identifier[8]; |
| 2021 | | UINT8 password[8]; |
| 2022 | | UINT8 data[0x30]; |
| 2023 | | } IBUTTON_SUBKEY; |
| 2024 | | |
| 2025 | | typedef struct |
| 2026 | | { |
| 2027 | | IBUTTON_SUBKEY subkey[3]; |
| 2028 | | } IBUTTON; |
| 2029 | | |
| 2030 | 2076 | enum |
| 2031 | 2077 | { |
| 2032 | 2078 | DS1991_STATE_NORMAL, |
| 2033 | 2079 | DS1991_STATE_READ_SUBKEY, |
| 2034 | 2080 | }; |
| 2035 | 2081 | |
| 2036 | | static IBUTTON ibutton; |
| 2037 | 2082 | |
| 2038 | | static int ibutton_state = DS1991_STATE_NORMAL; |
| 2039 | | static int ibutton_read_subkey_ptr = 0; |
| 2040 | 2083 | |
| 2041 | | static UINT8 ibutton_subkey_data[0x40]; |
| 2042 | 2084 | |
| 2043 | | static void set_ibutton(UINT8 *data) |
| 2085 | static void set_ibutton(firebeat_state *state, UINT8 *data) |
| 2044 | 2086 | { |
| 2045 | 2087 | int i, j; |
| 2046 | 2088 | |
| r10427 | r10428 | |
| 2049 | 2091 | // identifier |
| 2050 | 2092 | for (j=0; j < 8; j++) |
| 2051 | 2093 | { |
| 2052 | | ibutton.subkey[i].identifier[j] = *data++; |
| 2094 | state->ibutton.subkey[i].identifier[j] = *data++; |
| 2053 | 2095 | } |
| 2054 | 2096 | |
| 2055 | 2097 | // password |
| 2056 | 2098 | for (j=0; j < 8; j++) |
| 2057 | 2099 | { |
| 2058 | | ibutton.subkey[i].password[j] = *data++; |
| 2100 | state->ibutton.subkey[i].password[j] = *data++; |
| 2059 | 2101 | } |
| 2060 | 2102 | |
| 2061 | 2103 | // data |
| 2062 | 2104 | for (j=0; j < 48; j++) |
| 2063 | 2105 | { |
| 2064 | | ibutton.subkey[i].data[j] = *data++; |
| 2106 | state->ibutton.subkey[i].data[j] = *data++; |
| 2065 | 2107 | } |
| 2066 | 2108 | } |
| 2067 | 2109 | } |
| 2068 | 2110 | |
| 2069 | | static int ibutton_w(UINT8 data) |
| 2111 | static int ibutton_w(running_machine *machine, UINT8 data) |
| 2070 | 2112 | { |
| 2113 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 2071 | 2114 | int r = -1; |
| 2072 | 2115 | |
| 2073 | | switch (ibutton_state) |
| 2116 | switch (state->ibutton_state) |
| 2074 | 2117 | { |
| 2075 | 2118 | case DS1991_STATE_NORMAL: |
| 2076 | 2119 | { |
| r10427 | r10428 | |
| 2099 | 2142 | case 0x66: // DS1991 Read SubKey |
| 2100 | 2143 | { |
| 2101 | 2144 | r = 0x66; |
| 2102 | | ibutton_state = DS1991_STATE_READ_SUBKEY; |
| 2103 | | ibutton_read_subkey_ptr = 0; |
| 2145 | state->ibutton_state = DS1991_STATE_READ_SUBKEY; |
| 2146 | state->ibutton_read_subkey_ptr = 0; |
| 2104 | 2147 | break; |
| 2105 | 2148 | } |
| 2106 | 2149 | case 0xcc: // DS1991 skip rom |
| 2107 | 2150 | { |
| 2108 | 2151 | r = 0xcc; |
| 2109 | | ibutton_state = DS1991_STATE_NORMAL; |
| 2152 | state->ibutton_state = DS1991_STATE_NORMAL; |
| 2110 | 2153 | break; |
| 2111 | 2154 | } |
| 2112 | 2155 | default: |
| r10427 | r10428 | |
| 2120 | 2163 | |
| 2121 | 2164 | case DS1991_STATE_READ_SUBKEY: |
| 2122 | 2165 | { |
| 2123 | | if (ibutton_read_subkey_ptr == 0) // Read SubKey, 2nd command byte |
| 2166 | if (state->ibutton_read_subkey_ptr == 0) // Read SubKey, 2nd command byte |
| 2124 | 2167 | { |
| 2125 | 2168 | int subkey = (data >> 6) & 0x3; |
| 2126 | 2169 | // printf("iButton SubKey %d\n", subkey); |
| r10427 | r10428 | |
| 2128 | 2171 | |
| 2129 | 2172 | if (subkey < 3) |
| 2130 | 2173 | { |
| 2131 | | memcpy(&ibutton_subkey_data[0], ibutton.subkey[subkey].identifier, 8); |
| 2132 | | memcpy(&ibutton_subkey_data[8], ibutton.subkey[subkey].password, 8); |
| 2133 | | memcpy(&ibutton_subkey_data[16], ibutton.subkey[subkey].data, 0x30); |
| 2174 | memcpy(&state->ibutton_subkey_data[0], state->ibutton.subkey[subkey].identifier, 8); |
| 2175 | memcpy(&state->ibutton_subkey_data[8], state->ibutton.subkey[subkey].password, 8); |
| 2176 | memcpy(&state->ibutton_subkey_data[16], state->ibutton.subkey[subkey].data, 0x30); |
| 2134 | 2177 | } |
| 2135 | 2178 | else |
| 2136 | 2179 | { |
| 2137 | | memset(&ibutton_subkey_data[0], 0, 0x40); |
| 2180 | memset(&state->ibutton_subkey_data[0], 0, 0x40); |
| 2138 | 2181 | } |
| 2139 | 2182 | } |
| 2140 | | else if (ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte |
| 2183 | else if (state->ibutton_read_subkey_ptr == 1) // Read SubKey, 3rd command byte |
| 2141 | 2184 | { |
| 2142 | 2185 | r = data; |
| 2143 | 2186 | } |
| 2144 | 2187 | else |
| 2145 | 2188 | { |
| 2146 | | r = ibutton_subkey_data[ibutton_read_subkey_ptr-2]; |
| 2189 | r = state->ibutton_subkey_data[state->ibutton_read_subkey_ptr-2]; |
| 2147 | 2190 | } |
| 2148 | | ibutton_read_subkey_ptr++; |
| 2149 | | if (ibutton_read_subkey_ptr >= 0x42) |
| 2191 | state->ibutton_read_subkey_ptr++; |
| 2192 | if (state->ibutton_read_subkey_ptr >= 0x42) |
| 2150 | 2193 | { |
| 2151 | | ibutton_state = DS1991_STATE_NORMAL; |
| 2194 | state->ibutton_state = DS1991_STATE_NORMAL; |
| 2152 | 2195 | } |
| 2153 | 2196 | break; |
| 2154 | 2197 | } |
| r10427 | r10428 | |
| 2159 | 2202 | |
| 2160 | 2203 | static void security_w(device_t *device, UINT8 data) |
| 2161 | 2204 | { |
| 2162 | | int r = ibutton_w(data); |
| 2205 | int r = ibutton_w(device->machine, data); |
| 2163 | 2206 | if (r >= 0) |
| 2164 | 2207 | ppc4xx_spu_receive_byte(device->machine->device("maincpu"), r); |
| 2165 | 2208 | } |
| r10427 | r10428 | |
| 2179 | 2222 | |
| 2180 | 2223 | static void init_firebeat(running_machine *machine) |
| 2181 | 2224 | { |
| 2225 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 2182 | 2226 | UINT8 *rom = machine->region("user2")->base(); |
| 2183 | 2227 | |
| 2184 | 2228 | atapi_init(machine); |
| r10427 | r10428 | |
| 2186 | 2230 | pc16552d_init(machine, 0, 19660800, comm_uart_irq_callback, 0); // Network UART |
| 2187 | 2231 | pc16552d_init(machine, 1, 24000000, midi_uart_irq_callback, 0); // MIDI UART |
| 2188 | 2232 | |
| 2189 | | extend_board_irq_enable = 0x3f; |
| 2190 | | extend_board_irq_active = 0x00; |
| 2233 | state->extend_board_irq_enable = 0x3f; |
| 2234 | state->extend_board_irq_active = 0x00; |
| 2191 | 2235 | |
| 2192 | | cur_cab_data = cab_data; |
| 2236 | state->cur_cab_data = cab_data; |
| 2193 | 2237 | |
| 2194 | 2238 | ppc4xx_spu_set_tx_handler(machine->device("maincpu"), security_w); |
| 2195 | 2239 | |
| 2196 | | set_ibutton(rom); |
| 2240 | set_ibutton(state, rom); |
| 2197 | 2241 | |
| 2198 | 2242 | init_lights(machine, NULL, NULL, NULL); |
| 2199 | 2243 | } |
| r10427 | r10428 | |
| 2206 | 2250 | |
| 2207 | 2251 | static DRIVER_INIT(ppd) |
| 2208 | 2252 | { |
| 2253 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 2209 | 2254 | init_firebeat(machine); |
| 2210 | 2255 | init_lights(machine, lamp_output_ppp_w, lamp_output2_ppp_w, lamp_output3_ppp_w); |
| 2211 | 2256 | |
| 2212 | | cur_cab_data = ppd_cab_data; |
| 2257 | state->cur_cab_data = ppd_cab_data; |
| 2213 | 2258 | } |
| 2214 | 2259 | |
| 2215 | 2260 | static void init_keyboard(running_machine *machine) |
| 2216 | 2261 | { |
| 2262 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 2217 | 2263 | // set keyboard timer |
| 2218 | | keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback)); |
| 2219 | | keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); |
| 2264 | state->keyboard_timer = machine->scheduler().timer_alloc(FUNC(keyboard_timer_callback)); |
| 2265 | state->keyboard_timer->adjust(attotime::from_msec(10), 0, attotime::from_msec(10)); |
| 2220 | 2266 | } |
| 2221 | 2267 | |
| 2222 | 2268 | static DRIVER_INIT(kbm) |
| 2223 | 2269 | { |
| 2270 | firebeat_state *state = machine->driver_data<firebeat_state>(); |
| 2224 | 2271 | init_firebeat(machine); |
| 2225 | 2272 | init_lights(machine, lamp_output_kbm_w, NULL, NULL); |
| 2226 | 2273 | |
| 2227 | 2274 | init_keyboard(machine); |
| 2228 | 2275 | |
| 2229 | | cur_cab_data = kbm_cab_data; |
| 2276 | state->cur_cab_data = kbm_cab_data; |
| 2230 | 2277 | } |
| 2231 | 2278 | |
| 2232 | 2279 | |
src/mame/drivers/konamim2.c
| r10427 | r10428 | |
| 190 | 190 | #include "cdrom.h" |
| 191 | 191 | #include "cpu/powerpc/ppc.h" |
| 192 | 192 | |
| 193 | | static UINT64 *main_ram; |
| 194 | 193 | |
| 195 | | static UINT32 vdl0_address; |
| 196 | | static UINT32 vdl1_address; |
| 194 | typedef struct |
| 195 | { |
| 196 | UINT32 dst_addr; |
| 197 | int length; |
| 198 | UINT32 next_dst_addr; |
| 199 | int next_length; |
| 200 | int dma_done; |
| 201 | } CDE_DMA; |
| 197 | 202 | |
| 198 | | static UINT32 irq_enable; |
| 199 | | static UINT32 irq_active; |
| 203 | class konamim2_state : public driver_device |
| 204 | { |
| 205 | public: |
| 206 | konamim2_state(running_machine &machine, const driver_device_config_base &config) |
| 207 | : driver_device(machine, config) { } |
| 200 | 208 | |
| 209 | UINT64 *main_ram; |
| 210 | UINT32 vdl0_address; |
| 211 | UINT32 vdl1_address; |
| 212 | UINT32 irq_enable; |
| 213 | UINT32 irq_active; |
| 214 | UINT64 unk3; |
| 215 | UINT32 unk20004; |
| 216 | int counter1; |
| 217 | int cde_num_status_bytes; |
| 218 | UINT32 cde_status_bytes[16]; |
| 219 | int cde_status_byte_ptr; |
| 220 | UINT32 cde_command_bytes[16]; |
| 221 | int cde_command_byte_ptr; |
| 222 | int cde_response; |
| 223 | int cde_drive_state; |
| 224 | int cde_enable_qchannel_reports; |
| 225 | int cde_enable_seek_reports; |
| 226 | int cde_qchannel_offset; |
| 227 | cdrom_toc cde_toc; |
| 228 | CDE_DMA cde_dma[2]; |
| 229 | }; |
| 230 | |
| 231 | |
| 201 | 232 | static VIDEO_START( m2 ) |
| 202 | 233 | { |
| 203 | 234 | } |
| 204 | 235 | |
| 205 | 236 | static VIDEO_UPDATE( m2 ) |
| 206 | 237 | { |
| 238 | konamim2_state *state = screen->machine->driver_data<konamim2_state>(); |
| 207 | 239 | int i, j; |
| 208 | 240 | |
| 209 | 241 | UINT32 fb_start = 0xffffffff; |
| 210 | | if (vdl0_address != 0) |
| 242 | if (state->vdl0_address != 0) |
| 211 | 243 | { |
| 212 | | fb_start = *(UINT32*)&main_ram[(vdl0_address - 0x40000000) / 8] - 0x40000000; |
| 244 | fb_start = *(UINT32*)&state->main_ram[(state->vdl0_address - 0x40000000) / 8] - 0x40000000; |
| 213 | 245 | } |
| 214 | 246 | |
| 215 | 247 | if (fb_start <= 0x800000) |
| 216 | 248 | { |
| 217 | | UINT16 *frame = (UINT16*)&main_ram[fb_start/8]; |
| 249 | UINT16 *frame = (UINT16*)&state->main_ram[fb_start/8]; |
| 218 | 250 | for (j=0; j < 384; j++) |
| 219 | 251 | { |
| 220 | 252 | UINT16 *fb = &frame[(j*512)]; |
| r10427 | r10428 | |
| 234 | 266 | |
| 235 | 267 | static READ64_HANDLER(irq_enable_r) |
| 236 | 268 | { |
| 269 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 237 | 270 | UINT64 r = 0; |
| 238 | 271 | |
| 239 | 272 | if (ACCESSING_BITS_32_63) |
| 240 | 273 | { |
| 241 | | r |= (UINT64)(irq_enable) << 32; |
| 274 | r |= (UINT64)(state->irq_enable) << 32; |
| 242 | 275 | } |
| 243 | 276 | |
| 244 | 277 | return r; |
| r10427 | r10428 | |
| 246 | 279 | |
| 247 | 280 | static WRITE64_HANDLER(irq_enable_w) |
| 248 | 281 | { |
| 282 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 249 | 283 | if (ACCESSING_BITS_32_63) |
| 250 | 284 | { |
| 251 | | irq_enable |= (UINT32)(data >> 32); |
| 285 | state->irq_enable |= (UINT32)(data >> 32); |
| 252 | 286 | } |
| 253 | 287 | } |
| 254 | 288 | |
| 255 | 289 | static READ64_HANDLER(irq_active_r) |
| 256 | 290 | { |
| 291 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 257 | 292 | UINT64 r = 0; |
| 258 | 293 | |
| 259 | 294 | if (ACCESSING_BITS_32_63) |
| 260 | 295 | { |
| 261 | | r |= (UINT64)(irq_active) << 32; |
| 296 | r |= (UINT64)(state->irq_active) << 32; |
| 262 | 297 | } |
| 263 | 298 | |
| 264 | 299 | return r; |
| r10427 | r10428 | |
| 283 | 318 | } |
| 284 | 319 | #endif |
| 285 | 320 | |
| 286 | | static UINT64 unk3; |
| 287 | 321 | static READ64_HANDLER(unk3_r) |
| 288 | 322 | { |
| 323 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 289 | 324 | //return U64(0xffffffffffffffff); |
| 290 | | return unk3; |
| 325 | return state->unk3; |
| 291 | 326 | } |
| 292 | 327 | |
| 293 | | static UINT32 unk20004 = 0; |
| 294 | 328 | static READ64_HANDLER(unk4_r) |
| 295 | 329 | { |
| 330 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 296 | 331 | UINT64 r = 0; |
| 297 | 332 | // logerror("unk4_r: %08X, %08X%08X at %08X\n", offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu)); |
| 298 | 333 | |
| r10427 | r10428 | |
| 303 | 338 | } |
| 304 | 339 | if (ACCESSING_BITS_0_31) |
| 305 | 340 | { |
| 306 | | r |= unk20004 & ~0x800000; |
| 341 | r |= state->unk20004 & ~0x800000; |
| 307 | 342 | } |
| 308 | 343 | return r; |
| 309 | 344 | } |
| 310 | 345 | |
| 311 | 346 | static WRITE64_HANDLER(unk4_w) |
| 312 | 347 | { |
| 348 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 313 | 349 | // logerror("unk4_w: %08X%08X, %08X, %08X%08X at %08X\n", (UINT32)(data >> 32), (UINT32)(data), |
| 314 | 350 | // offset, (UINT32)(mem_mask>>32), (UINT32)(mem_mask), cpu_get_pc(space->cpu)); |
| 315 | 351 | |
| r10427 | r10428 | |
| 321 | 357 | cputag_set_input_line(space->machine, "sub", INPUT_LINE_IRQ0, ASSERT_LINE); |
| 322 | 358 | } |
| 323 | 359 | |
| 324 | | unk20004 = (UINT32)(data); |
| 360 | state->unk20004 = (UINT32)(data); |
| 325 | 361 | return; |
| 326 | 362 | } |
| 327 | 363 | } |
| 328 | 364 | |
| 329 | | static int counter1 = 0; |
| 330 | 365 | static READ64_HANDLER(unk30000_r) |
| 331 | 366 | { |
| 332 | | counter1++; |
| 333 | | return (UINT64)(counter1 & 0x7f) << 32; |
| 367 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 368 | state->counter1++; |
| 369 | return (UINT64)(state->counter1 & 0x7f) << 32; |
| 334 | 370 | } |
| 335 | 371 | |
| 336 | 372 | static READ64_HANDLER(unk30030_r) |
| r10427 | r10428 | |
| 344 | 380 | |
| 345 | 381 | static WRITE64_HANDLER(video_w) |
| 346 | 382 | { |
| 383 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 347 | 384 | if (ACCESSING_BITS_32_63) |
| 348 | 385 | { |
| 349 | | vdl0_address = (UINT32)(data >> 32); |
| 386 | state->vdl0_address = (UINT32)(data >> 32); |
| 350 | 387 | } |
| 351 | 388 | if (ACCESSING_BITS_0_31) |
| 352 | 389 | { |
| 353 | | vdl1_address = (UINT32)(data); |
| 390 | state->vdl1_address = (UINT32)(data); |
| 354 | 391 | } |
| 355 | 392 | } |
| 356 | 393 | |
| 357 | 394 | static WRITE64_HANDLER(video_irq_ack_w) |
| 358 | 395 | { |
| 396 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 359 | 397 | if (ACCESSING_BITS_32_63) |
| 360 | 398 | { |
| 361 | 399 | if ((data >> 32) & 0x8000) |
| 362 | 400 | { |
| 363 | | irq_active &= ~0x800000; |
| 401 | state->irq_active &= ~0x800000; |
| 364 | 402 | } |
| 365 | 403 | } |
| 366 | 404 | } |
| r10427 | r10428 | |
| 409 | 447 | |
| 410 | 448 | static WRITE64_HANDLER(reset_w) |
| 411 | 449 | { |
| 450 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 412 | 451 | if (ACCESSING_BITS_32_63) |
| 413 | 452 | { |
| 414 | 453 | if (data & U64(0x100000000)) |
| 415 | 454 | { |
| 416 | 455 | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_RESET, PULSE_LINE); |
| 417 | | unk3 = 0; |
| 456 | state->unk3 = 0; |
| 418 | 457 | } |
| 419 | 458 | } |
| 420 | 459 | } |
| r10427 | r10428 | |
| 423 | 462 | /*****************************************************************************/ |
| 424 | 463 | /* CDE */ |
| 425 | 464 | |
| 426 | | typedef struct |
| 427 | | { |
| 428 | | UINT32 dst_addr; |
| 429 | | int length; |
| 430 | | UINT32 next_dst_addr; |
| 431 | | int next_length; |
| 432 | | int dma_done; |
| 433 | | } CDE_DMA; |
| 434 | | |
| 435 | 465 | #define CDE_DRIVE_STATE_PAUSED 0x02 |
| 436 | 466 | #define CDE_DRIVE_STATE_SEEK_DONE 0x03 |
| 437 | 467 | |
| 438 | | static int cde_num_status_bytes = 0; |
| 439 | | static UINT32 cde_status_bytes[16]; |
| 440 | | static int cde_status_byte_ptr = 0; |
| 441 | 468 | |
| 442 | | static UINT32 cde_command_bytes[16]; |
| 443 | | static int cde_command_byte_ptr = 0; |
| 444 | 469 | |
| 445 | | static int cde_response = 0; |
| 446 | | static int cde_drive_state = 0; |
| 447 | 470 | |
| 448 | | static int cde_enable_qchannel_reports = 0; |
| 449 | | static int cde_enable_seek_reports = 0; |
| 450 | 471 | |
| 451 | | static int cde_qchannel_offset = 0; |
| 452 | 472 | |
| 453 | | static cdrom_toc cde_toc; |
| 454 | 473 | |
| 455 | | static CDE_DMA cde_dma[2]; |
| 456 | 474 | |
| 457 | 475 | |
| 458 | 476 | static void cde_init(running_machine *machine) |
| 459 | 477 | { |
| 478 | konamim2_state *state = machine->driver_data<konamim2_state>(); |
| 460 | 479 | cdrom_file *cd = cdrom_open(get_disk_handle(machine, "cdrom")); |
| 461 | 480 | const cdrom_toc *toc = cdrom_get_toc(cd); |
| 462 | 481 | |
| 463 | 482 | if (cd) |
| 464 | 483 | { |
| 465 | | memcpy(&cde_toc, toc, sizeof(cdrom_toc)); |
| 484 | memcpy(&state->cde_toc, toc, sizeof(cdrom_toc)); |
| 466 | 485 | } |
| 467 | 486 | |
| 468 | 487 | /* |
| r10427 | r10428 | |
| 480 | 499 | cdrom_close(cd); |
| 481 | 500 | } |
| 482 | 501 | |
| 483 | | cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 502 | state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 484 | 503 | |
| 485 | | cde_num_status_bytes = 0; |
| 486 | | cde_status_byte_ptr = 0; |
| 487 | | cde_command_byte_ptr = 0; |
| 504 | state->cde_num_status_bytes = 0; |
| 505 | state->cde_status_byte_ptr = 0; |
| 506 | state->cde_command_byte_ptr = 0; |
| 488 | 507 | |
| 489 | | cde_response = 0; |
| 508 | state->cde_response = 0; |
| 490 | 509 | |
| 491 | | cde_enable_qchannel_reports = 0; |
| 492 | | cde_enable_seek_reports = 0; |
| 510 | state->cde_enable_qchannel_reports = 0; |
| 511 | state->cde_enable_seek_reports = 0; |
| 493 | 512 | |
| 494 | | cde_qchannel_offset = 0; |
| 513 | state->cde_qchannel_offset = 0; |
| 495 | 514 | } |
| 496 | 515 | |
| 497 | | static void cde_handle_command(void) |
| 516 | static void cde_handle_command(running_machine *machine) |
| 498 | 517 | { |
| 499 | | switch (cde_command_bytes[0]) |
| 518 | konamim2_state *state = machine->driver_data<konamim2_state>(); |
| 519 | switch (state->cde_command_bytes[0]) |
| 500 | 520 | { |
| 501 | 521 | case 0x04: // Set Speed |
| 502 | 522 | { |
| 503 | | cde_num_status_bytes = 1; |
| 523 | state->cde_num_status_bytes = 1; |
| 504 | 524 | |
| 505 | | cde_status_bytes[0] = 0x04; |
| 506 | | cde_status_byte_ptr = 0; |
| 525 | state->cde_status_bytes[0] = 0x04; |
| 526 | state->cde_status_byte_ptr = 0; |
| 507 | 527 | |
| 508 | | mame_printf_debug("CDE: SET SPEED %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2]); |
| 528 | mame_printf_debug("CDE: SET SPEED %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2]); |
| 509 | 529 | break; |
| 510 | 530 | } |
| 511 | 531 | case 0x06: // Audio Format / Data Format |
| 512 | 532 | { |
| 513 | | cde_num_status_bytes = 1; |
| 533 | state->cde_num_status_bytes = 1; |
| 514 | 534 | |
| 515 | | cde_status_bytes[0] = 0x06; |
| 516 | | cde_status_byte_ptr = 0; |
| 535 | state->cde_status_bytes[0] = 0x06; |
| 536 | state->cde_status_byte_ptr = 0; |
| 517 | 537 | |
| 518 | | if (cde_command_bytes[1] == 0x00) // Audio Format |
| 538 | if (state->cde_command_bytes[1] == 0x00) // Audio Format |
| 519 | 539 | { |
| 520 | 540 | mame_printf_debug("CDE: AUDIO FORMAT\n"); |
| 521 | 541 | } |
| 522 | | else if (cde_command_bytes[1] == 0x78) // Data Format |
| 542 | else if (state->cde_command_bytes[1] == 0x78) // Data Format |
| 523 | 543 | { |
| 524 | 544 | mame_printf_debug("CDE: DATA FORMAT\n"); |
| 525 | 545 | } |
| 526 | 546 | else |
| 527 | 547 | { |
| 528 | | fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]); |
| 548 | fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]); |
| 529 | 549 | } |
| 530 | 550 | break; |
| 531 | 551 | } |
| 532 | 552 | case 0x08: // Pause / Eject / Play |
| 533 | 553 | { |
| 534 | | cde_num_status_bytes = 1; |
| 554 | state->cde_num_status_bytes = 1; |
| 535 | 555 | |
| 536 | | cde_status_bytes[0] = 0x08; |
| 537 | | cde_status_byte_ptr = 0; |
| 556 | state->cde_status_bytes[0] = 0x08; |
| 557 | state->cde_status_byte_ptr = 0; |
| 538 | 558 | |
| 539 | | if (cde_command_bytes[1] == 0x00) // Eject |
| 559 | if (state->cde_command_bytes[1] == 0x00) // Eject |
| 540 | 560 | { |
| 541 | 561 | mame_printf_debug("CDE: EJECT command\n"); |
| 542 | 562 | } |
| 543 | | else if (cde_command_bytes[1] == 0x02) // Pause |
| 563 | else if (state->cde_command_bytes[1] == 0x02) // Pause |
| 544 | 564 | { |
| 545 | 565 | mame_printf_debug("CDE: PAUSE command\n"); |
| 546 | | cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 566 | state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 547 | 567 | } |
| 548 | | else if (cde_command_bytes[1] == 0x03) // Play |
| 568 | else if (state->cde_command_bytes[1] == 0x03) // Play |
| 549 | 569 | { |
| 550 | 570 | mame_printf_debug("CDE: PLAY command\n"); |
| 551 | 571 | } |
| 552 | 572 | else |
| 553 | 573 | { |
| 554 | | fatalerror("CDE: unknown command %02X, %02X\n", cde_command_bytes[0], cde_command_bytes[1]); |
| 574 | fatalerror("CDE: unknown command %02X, %02X\n", state->cde_command_bytes[0], state->cde_command_bytes[1]); |
| 555 | 575 | } |
| 556 | 576 | break; |
| 557 | 577 | } |
| 558 | 578 | case 0x09: // Seek |
| 559 | 579 | { |
| 560 | | cde_num_status_bytes = 1; |
| 580 | state->cde_num_status_bytes = 1; |
| 561 | 581 | |
| 562 | | cde_status_bytes[0] = 0x1b; |
| 563 | | cde_status_byte_ptr = 0; |
| 582 | state->cde_status_bytes[0] = 0x1b; |
| 583 | state->cde_status_byte_ptr = 0; |
| 564 | 584 | |
| 565 | | cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE; |
| 585 | state->cde_drive_state = CDE_DRIVE_STATE_SEEK_DONE; |
| 566 | 586 | |
| 567 | | mame_printf_debug("CDE: SEEK %08X\n", (cde_command_bytes[1] << 16) | (cde_command_bytes[2] << 8) | (cde_command_bytes[3])); |
| 587 | mame_printf_debug("CDE: SEEK %08X\n", (state->cde_command_bytes[1] << 16) | (state->cde_command_bytes[2] << 8) | (state->cde_command_bytes[3])); |
| 568 | 588 | break; |
| 569 | 589 | } |
| 570 | 590 | case 0x0b: // Get Drive State |
| 571 | 591 | { |
| 572 | | cde_num_status_bytes = 0x3; |
| 592 | state->cde_num_status_bytes = 0x3; |
| 573 | 593 | |
| 574 | | cde_status_bytes[0] = 0x0b; |
| 575 | | cde_status_bytes[1] = 0x1b; |
| 576 | | cde_status_bytes[2] = cde_drive_state; |
| 577 | | cde_status_byte_ptr = 0; |
| 594 | state->cde_status_bytes[0] = 0x0b; |
| 595 | state->cde_status_bytes[1] = 0x1b; |
| 596 | state->cde_status_bytes[2] = state->cde_drive_state; |
| 597 | state->cde_status_byte_ptr = 0; |
| 578 | 598 | |
| 579 | | if (cde_command_bytes[1] & 0x02) |
| 599 | if (state->cde_command_bytes[1] & 0x02) |
| 580 | 600 | { |
| 581 | | cde_enable_seek_reports = 1; |
| 601 | state->cde_enable_seek_reports = 1; |
| 582 | 602 | } |
| 583 | 603 | else |
| 584 | 604 | { |
| 585 | | cde_enable_seek_reports = 0; |
| 605 | state->cde_enable_seek_reports = 0; |
| 586 | 606 | } |
| 587 | 607 | |
| 588 | | mame_printf_debug("CDE: GET DRIVE STATE %02X\n", cde_command_bytes[1]); |
| 608 | mame_printf_debug("CDE: GET DRIVE STATE %02X\n", state->cde_command_bytes[1]); |
| 589 | 609 | break; |
| 590 | 610 | } |
| 591 | 611 | case 0x0c: // ? |
| 592 | 612 | { |
| 593 | | cde_num_status_bytes = 1; |
| 613 | state->cde_num_status_bytes = 1; |
| 594 | 614 | |
| 595 | | cde_status_bytes[0] = 0x0c; |
| 596 | | cde_status_byte_ptr = 0; |
| 615 | state->cde_status_bytes[0] = 0x0c; |
| 616 | state->cde_status_byte_ptr = 0; |
| 597 | 617 | |
| 598 | | if (cde_command_bytes[1] == 0x02) |
| 618 | if (state->cde_command_bytes[1] == 0x02) |
| 599 | 619 | { |
| 600 | | cde_enable_qchannel_reports = 1; |
| 601 | | cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 620 | state->cde_enable_qchannel_reports = 1; |
| 621 | state->cde_drive_state = CDE_DRIVE_STATE_PAUSED; |
| 602 | 622 | } |
| 603 | | else if (cde_command_bytes[0] == 0x00) |
| 623 | else if (state->cde_command_bytes[0] == 0x00) |
| 604 | 624 | { |
| 605 | | cde_enable_qchannel_reports = 0; |
| 625 | state->cde_enable_qchannel_reports = 0; |
| 606 | 626 | } |
| 607 | 627 | |
| 608 | | mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", cde_command_bytes[1]); |
| 628 | mame_printf_debug("CDE: UNKNOWN CMD 0x0c %02X\n", state->cde_command_bytes[1]); |
| 609 | 629 | break; |
| 610 | 630 | } |
| 611 | 631 | case 0x0d: // Get Switch State |
| 612 | 632 | { |
| 613 | | cde_num_status_bytes = 0x4; |
| 633 | state->cde_num_status_bytes = 0x4; |
| 614 | 634 | |
| 615 | | cde_status_bytes[0] = 0x0d; |
| 616 | | cde_status_bytes[1] = 0x1d; |
| 617 | | cde_status_bytes[2] = 0x02; |
| 618 | | cde_status_byte_ptr = 0; |
| 635 | state->cde_status_bytes[0] = 0x0d; |
| 636 | state->cde_status_bytes[1] = 0x1d; |
| 637 | state->cde_status_bytes[2] = 0x02; |
| 638 | state->cde_status_byte_ptr = 0; |
| 619 | 639 | |
| 620 | | mame_printf_debug("CDE: GET SWITCH STATE %02X\n", cde_command_bytes[1]); |
| 640 | mame_printf_debug("CDE: GET SWITCH STATE %02X\n", state->cde_command_bytes[1]); |
| 621 | 641 | break; |
| 622 | 642 | } |
| 623 | 643 | case 0x21: // Mech type |
| 624 | 644 | { |
| 625 | | cde_num_status_bytes = 0x8; |
| 645 | state->cde_num_status_bytes = 0x8; |
| 626 | 646 | |
| 627 | | cde_status_bytes[0] = 0x21; |
| 628 | | cde_status_bytes[1] = 0xff; |
| 629 | | cde_status_bytes[2] = 0x08; // Max Speed |
| 630 | | cde_status_bytes[3] = 0xff; |
| 631 | | cde_status_bytes[4] = 0xff; |
| 632 | | cde_status_bytes[5] = 0xff; |
| 633 | | cde_status_bytes[6] = 0xff; |
| 634 | | cde_status_bytes[7] = 0xff; |
| 647 | state->cde_status_bytes[0] = 0x21; |
| 648 | state->cde_status_bytes[1] = 0xff; |
| 649 | state->cde_status_bytes[2] = 0x08; // Max Speed |
| 650 | state->cde_status_bytes[3] = 0xff; |
| 651 | state->cde_status_bytes[4] = 0xff; |
| 652 | state->cde_status_bytes[5] = 0xff; |
| 653 | state->cde_status_bytes[6] = 0xff; |
| 654 | state->cde_status_bytes[7] = 0xff; |
| 635 | 655 | |
| 636 | | cde_status_byte_ptr = 0; |
| 656 | state->cde_status_byte_ptr = 0; |
| 637 | 657 | |
| 638 | | mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", cde_command_bytes[1], cde_command_bytes[2], cde_command_bytes[3]); |
| 658 | mame_printf_debug("CDE: MECH TYPE %02X, %02X, %02X\n", state->cde_command_bytes[1], state->cde_command_bytes[2], state->cde_command_bytes[3]); |
| 639 | 659 | break; |
| 640 | 660 | } |
| 641 | 661 | case 0x83: // Read ID |
| 642 | 662 | { |
| 643 | | cde_num_status_bytes = 0xc; |
| 663 | state->cde_num_status_bytes = 0xc; |
| 644 | 664 | |
| 645 | | cde_status_bytes[0] = 0x03; |
| 646 | | cde_status_bytes[1] = 0xff; |
| 647 | | cde_status_bytes[2] = 0xff; |
| 648 | | cde_status_bytes[3] = 0xff; |
| 649 | | cde_status_bytes[4] = 0xff; |
| 650 | | cde_status_bytes[5] = 0xff; |
| 651 | | cde_status_bytes[6] = 0xff; |
| 652 | | cde_status_bytes[7] = 0xff; |
| 653 | | cde_status_bytes[8] = 0xff; |
| 654 | | cde_status_bytes[9] = 0xff; |
| 655 | | cde_status_bytes[10] = 0xff; |
| 656 | | cde_status_bytes[11] = 0xff; |
| 665 | state->cde_status_bytes[0] = 0x03; |
| 666 | state->cde_status_bytes[1] = 0xff; |
| 667 | state->cde_status_bytes[2] = 0xff; |
| 668 | state->cde_status_bytes[3] = 0xff; |
| 669 | state->cde_status_bytes[4] = 0xff; |
| 670 | state->cde_status_bytes[5] = 0xff; |
| 671 | state->cde_status_bytes[6] = 0xff; |
| 672 | state->cde_status_bytes[7] = 0xff; |
| 673 | state->cde_status_bytes[8] = 0xff; |
| 674 | state->cde_status_bytes[9] = 0xff; |
| 675 | state->cde_status_bytes[10] = 0xff; |
| 676 | state->cde_status_bytes[11] = 0xff; |
| 657 | 677 | |
| 658 | | cde_status_byte_ptr = 0; |
| 678 | state->cde_status_byte_ptr = 0; |
| 659 | 679 | |
| 660 | 680 | mame_printf_debug("CDE: READ ID\n"); |
| 661 | 681 | break; |
| 662 | 682 | } |
| 663 | 683 | default: |
| 664 | 684 | { |
| 665 | | fatalerror("CDE: unknown command %08X\n", cde_command_bytes[0]); |
| 685 | fatalerror("CDE: unknown command %08X\n", state->cde_command_bytes[0]); |
| 666 | 686 | break; |
| 667 | 687 | } |
| 668 | 688 | } |
| 669 | 689 | } |
| 670 | 690 | |
| 671 | | static void cde_handle_reports(void) |
| 691 | static void cde_handle_reports(running_machine *machine) |
| 672 | 692 | { |
| 673 | | switch (cde_command_bytes[0]) |
| 693 | konamim2_state *state = machine->driver_data<konamim2_state>(); |
| 694 | switch (state->cde_command_bytes[0]) |
| 674 | 695 | { |
| 675 | 696 | case 0x09: |
| 676 | 697 | { |
| 677 | | if (cde_enable_seek_reports) |
| 698 | if (state->cde_enable_seek_reports) |
| 678 | 699 | { |
| 679 | | cde_num_status_bytes = 0x2; |
| 680 | | cde_status_bytes[0] = 0x02; |
| 700 | state->cde_num_status_bytes = 0x2; |
| 701 | state->cde_status_bytes[0] = 0x02; |
| 681 | 702 | |
| 682 | | cde_status_byte_ptr = 0; |
| 703 | state->cde_status_byte_ptr = 0; |
| 683 | 704 | |
| 684 | | cde_command_bytes[0] = 0x0c; |
| 705 | state->cde_command_bytes[0] = 0x0c; |
| 685 | 706 | |
| 686 | 707 | mame_printf_debug("CDE: SEEK REPORT\n"); |
| 687 | 708 | } |
| r10427 | r10428 | |
| 690 | 711 | |
| 691 | 712 | case 0x0b: |
| 692 | 713 | { |
| 693 | | if (cde_enable_qchannel_reports) |
| 714 | if (state->cde_enable_qchannel_reports) |
| 694 | 715 | { |
| 695 | 716 | int track, num_tracks; |
| 696 | 717 | |
| 697 | | num_tracks = cde_toc.numtrks; |
| 698 | | track = cde_qchannel_offset % (num_tracks+3); |
| 718 | num_tracks = state->cde_toc.numtrks; |
| 719 | track = state->cde_qchannel_offset % (num_tracks+3); |
| 699 | 720 | |
| 700 | | cde_num_status_bytes = 0xb; |
| 701 | | cde_status_bytes[0] = 0x1c; |
| 721 | state->cde_num_status_bytes = 0xb; |
| 722 | state->cde_status_bytes[0] = 0x1c; |
| 702 | 723 | |
| 703 | 724 | /* |
| 704 | | cde_status_bytes[1] = 0x0; // q-Mode |
| 705 | | cde_status_bytes[2] = 0x0; // TNO |
| 706 | | cde_status_bytes[3] = 0x0; // Index / Pointer |
| 707 | | cde_status_bytes[4] = 0x0; // Min |
| 708 | | cde_status_bytes[5] = 0x0; // Sec |
| 709 | | cde_status_bytes[6] = 0x0; // Frac |
| 710 | | cde_status_bytes[7] = 0x0; // Zero |
| 711 | | cde_status_bytes[8] = 0x0; // A-Min |
| 712 | | cde_status_bytes[9] = 0x0; // A-Sec |
| 713 | | cde_status_bytes[10] = 0x0; // A-Frac |
| 725 | state->cde_status_bytes[1] = 0x0; // q-Mode |
| 726 | state->cde_status_bytes[2] = 0x0; // TNO |
| 727 | state->cde_status_bytes[3] = 0x0; // Index / Pointer |
| 728 | state->cde_status_bytes[4] = 0x0; // Min |
| 729 | state->cde_status_bytes[5] = 0x0; // Sec |
| 730 | state->cde_status_bytes[6] = 0x0; // Frac |
| 731 | state->cde_status_bytes[7] = 0x0; // Zero |
| 732 | state->cde_status_bytes[8] = 0x0; // A-Min |
| 733 | state->cde_status_bytes[9] = 0x0; // A-Sec |
| 734 | state->cde_status_bytes[10] = 0x0; // A-Frac |
| 714 | 735 | */ |
| 715 | 736 | |
| 716 | 737 | if (track < num_tracks) |
| 717 | 738 | { |
| 718 | | int time = lba_to_msf(cde_toc.tracks[track].physframeofs); |
| 739 | int time = lba_to_msf(state->cde_toc.tracks[track].physframeofs); |
| 719 | 740 | |
| 720 | | cde_status_bytes[1] = 0x41; // q-Mode |
| 721 | | cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 722 | | cde_status_bytes[3] = track+1; // Pointer |
| 723 | | cde_status_bytes[4] = 0x0; // Min |
| 724 | | cde_status_bytes[5] = 0x0; // Sec |
| 725 | | cde_status_bytes[6] = 0x0; // Frac |
| 726 | | cde_status_bytes[7] = 0x0; // Zero |
| 727 | | cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min |
| 728 | | cde_status_bytes[9] = (time >> 8) & 0xff; // P-Sec |
| 729 | | cde_status_bytes[10] = time & 0xff; // P-Frac |
| 741 | state->cde_status_bytes[1] = 0x41; // q-Mode |
| 742 | state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 743 | state->cde_status_bytes[3] = track+1; // Pointer |
| 744 | state->cde_status_bytes[4] = 0x0; // Min |
| 745 | state->cde_status_bytes[5] = 0x0; // Sec |
| 746 | state->cde_status_bytes[6] = 0x0; // Frac |
| 747 | state->cde_status_bytes[7] = 0x0; // Zero |
| 748 | state->cde_status_bytes[8] = (time >> 16) & 0xff; // P-Min |
| 749 | state->cde_status_bytes[9] = (time >> 8) & 0xff; // P-Sec |
| 750 | state->cde_status_bytes[10] = time & 0xff; // P-Frac |
| 730 | 751 | } |
| 731 | 752 | else |
| 732 | 753 | { |
| 733 | 754 | if (track == num_tracks+0) |
| 734 | 755 | { |
| 735 | | cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 736 | | cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 737 | | cde_status_bytes[3] = 0xa0; // Pointer |
| 738 | | cde_status_bytes[4] = 0x0; // Min |
| 739 | | cde_status_bytes[5] = 0x0; // Sec |
| 740 | | cde_status_bytes[6] = 0x0; // Frac |
| 741 | | cde_status_bytes[7] = 0x0; // Zero |
| 742 | | cde_status_bytes[8] = 1; // P-Min |
| 743 | | cde_status_bytes[9] = 0x0; // P-Sec |
| 744 | | cde_status_bytes[10] = 0x0; // P-Frac |
| 756 | state->cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 757 | state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 758 | state->cde_status_bytes[3] = 0xa0; // Pointer |
| 759 | state->cde_status_bytes[4] = 0x0; // Min |
| 760 | state->cde_status_bytes[5] = 0x0; // Sec |
| 761 | state->cde_status_bytes[6] = 0x0; // Frac |
| 762 | state->cde_status_bytes[7] = 0x0; // Zero |
| 763 | state->cde_status_bytes[8] = 1; // P-Min |
| 764 | state->cde_status_bytes[9] = 0x0; // P-Sec |
| 765 | state->cde_status_bytes[10] = 0x0; // P-Frac |
| 745 | 766 | } |
| 746 | 767 | else if (track == num_tracks+1) |
| 747 | 768 | { |
| 748 | | cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 749 | | cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 750 | | cde_status_bytes[3] = 0xa1; // Pointer |
| 751 | | cde_status_bytes[4] = 0x0; // Min |
| 752 | | cde_status_bytes[5] = 0x0; // Sec |
| 753 | | cde_status_bytes[6] = 0x0; // Frac |
| 754 | | cde_status_bytes[7] = 0x0; // Zero |
| 755 | | cde_status_bytes[8] = num_tracks; // P-Min |
| 756 | | cde_status_bytes[9] = 0x0; // P-Sec |
| 757 | | cde_status_bytes[10] = 0x0; // P-Frac |
| 769 | state->cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 770 | state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 771 | state->cde_status_bytes[3] = 0xa1; // Pointer |
| 772 | state->cde_status_bytes[4] = 0x0; // Min |
| 773 | state->cde_status_bytes[5] = 0x0; // Sec |
| 774 | state->cde_status_bytes[6] = 0x0; // Frac |
| 775 | state->cde_status_bytes[7] = 0x0; // Zero |
| 776 | state->cde_status_bytes[8] = num_tracks; // P-Min |
| 777 | state->cde_status_bytes[9] = 0x0; // P-Sec |
| 778 | state->cde_status_bytes[10] = 0x0; // P-Frac |
| 758 | 779 | } |
| 759 | 780 | else |
| 760 | 781 | { |
| 761 | | int leadout_lba = cde_toc.tracks[num_tracks-1].physframeofs + cde_toc.tracks[num_tracks-1].frames; |
| 782 | int leadout_lba = state->cde_toc.tracks[num_tracks-1].physframeofs + state->cde_toc.tracks[num_tracks-1].frames; |
| 762 | 783 | int leadout_time = lba_to_msf(leadout_lba); |
| 763 | 784 | |
| 764 | | cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 765 | | cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 766 | | cde_status_bytes[3] = 0xa2; // Pointer |
| 767 | | cde_status_bytes[4] = 0x0; // Min |
| 768 | | cde_status_bytes[5] = 0x0; // Sec |
| 769 | | cde_status_bytes[6] = 0x0; // Frac |
| 770 | | cde_status_bytes[7] = 0x0; // Zero |
| 771 | | cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min |
| 772 | | cde_status_bytes[9] = (leadout_time >> 8) & 0xff; // P-Sec |
| 773 | | cde_status_bytes[10] = leadout_time & 0xff; // P-Frac |
| 785 | state->cde_status_bytes[1] = 0x41; // q-Mode / Control |
| 786 | state->cde_status_bytes[2] = 0x0; // TNO (Lead-in track) |
| 787 | state->cde_status_bytes[3] = 0xa2; // Pointer |
| 788 | state->cde_status_bytes[4] = 0x0; // Min |
| 789 | state->cde_status_bytes[5] = 0x0; // Sec |
| 790 | state->cde_status_bytes[6] = 0x0; // Frac |
| 791 | state->cde_status_bytes[7] = 0x0; // Zero |
| 792 | state->cde_status_bytes[8] = (leadout_time >> 16) & 0xff; // P-Min |
| 793 | state->cde_status_bytes[9] = (leadout_time >> 8) & 0xff; // P-Sec |
| 794 | state->cde_status_bytes[10] = leadout_time & 0xff; // P-Frac |
| 774 | 795 | } |
| 775 | 796 | } |
| 776 | 797 | |
| 777 | | cde_qchannel_offset++; |
| 798 | state->cde_qchannel_offset++; |
| 778 | 799 | |
| 779 | | cde_status_byte_ptr = 0; |
| 780 | | cde_command_bytes[0] = 0x0c; |
| 800 | state->cde_status_byte_ptr = 0; |
| 801 | state->cde_command_bytes[0] = 0x0c; |
| 781 | 802 | |
| 782 | 803 | mame_printf_debug("CDE: QCHANNEL REPORT\n"); |
| 783 | 804 | break; |
| r10427 | r10428 | |
| 788 | 809 | |
| 789 | 810 | static void cde_dma_transfer(address_space *space, int channel, int next) |
| 790 | 811 | { |
| 812 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 791 | 813 | UINT32 address; |
| 792 | 814 | //int length; |
| 793 | 815 | int i; |
| 794 | 816 | |
| 795 | 817 | if (next) |
| 796 | 818 | { |
| 797 | | address = cde_dma[channel].next_dst_addr; |
| 798 | | //length = cde_dma[channel].next_length; |
| 819 | address = state->cde_dma[channel].next_dst_addr; |
| 820 | //length = state->cde_dma[channel].next_length; |
| 799 | 821 | } |
| 800 | 822 | else |
| 801 | 823 | { |
| 802 | | address = cde_dma[channel].dst_addr; |
| 803 | | //length = cde_dma[channel].length; |
| 824 | address = state->cde_dma[channel].dst_addr; |
| 825 | //length = state->cde_dma[channel].length; |
| 804 | 826 | } |
| 805 | 827 | |
| 806 | | for (i=0; i < cde_dma[channel].next_length; i++) |
| 828 | for (i=0; i < state->cde_dma[channel].next_length; i++) |
| 807 | 829 | { |
| 808 | 830 | space->write_byte(address, 0xff); // TODO: do the real transfer... |
| 809 | 831 | address++; |
| r10427 | r10428 | |
| 812 | 834 | |
| 813 | 835 | static READ64_HANDLER(cde_r) |
| 814 | 836 | { |
| 837 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 815 | 838 | UINT32 r = 0; |
| 816 | 839 | int reg = offset * 2; |
| 817 | 840 | |
| r10427 | r10428 | |
| 829 | 852 | { |
| 830 | 853 | r = 0x100038; |
| 831 | 854 | |
| 832 | | r |= cde_dma[0].dma_done ? 0x400 : 0; |
| 833 | | r |= cde_dma[1].dma_done ? 0x800 : 0; |
| 855 | r |= state->cde_dma[0].dma_done ? 0x400 : 0; |
| 856 | r |= state->cde_dma[1].dma_done ? 0x800 : 0; |
| 834 | 857 | break; |
| 835 | 858 | } |
| 836 | 859 | case 0x02c/4: |
| 837 | 860 | { |
| 838 | | r = cde_status_bytes[cde_status_byte_ptr++]; |
| 861 | r = state->cde_status_bytes[state->cde_status_byte_ptr++]; |
| 839 | 862 | |
| 840 | | if (cde_status_byte_ptr <= cde_num_status_bytes) |
| 863 | if (state->cde_status_byte_ptr <= state->cde_num_status_bytes) |
| 841 | 864 | { |
| 842 | 865 | r |= 0x100; |
| 843 | 866 | } |
| 844 | 867 | else |
| 845 | 868 | { |
| 846 | 869 | //if (cde_enable_reports && |
| 847 | | // !cde_response && |
| 848 | | // cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff)) |
| 870 | // !state->cde_response && |
| 871 | // state->cde_command_bytes[0] != ((cde_report_type >> 8) & 0xff)) |
| 849 | 872 | |
| 850 | | if (!cde_response) |
| 873 | if (!state->cde_response) |
| 851 | 874 | { |
| 852 | | cde_handle_reports(); |
| 875 | cde_handle_reports(space->machine); |
| 853 | 876 | |
| 854 | | // cde_command_byte_ptr = 0; |
| 855 | | // cde_command_bytes[cde_command_byte_ptr++] = 0x1c; |
| 877 | // state->cde_command_byte_ptr = 0; |
| 878 | // state->cde_command_bytes[state->cde_command_byte_ptr++] = 0x1c; |
| 856 | 879 | |
| 857 | | // cde_response = 1; |
| 880 | // state->cde_response = 1; |
| 858 | 881 | } |
| 859 | 882 | } |
| 860 | 883 | |
| 861 | | // printf("status byte %d\n", cde_status_byte_ptr); |
| 884 | // printf("status byte %d\n", state->cde_status_byte_ptr); |
| 862 | 885 | break; |
| 863 | 886 | } |
| 864 | 887 | |
| r10427 | r10428 | |
| 887 | 910 | |
| 888 | 911 | static WRITE64_HANDLER(cde_w) |
| 889 | 912 | { |
| 913 | konamim2_state *state = space->machine->driver_data<konamim2_state>(); |
| 890 | 914 | int reg = offset * 2; |
| 891 | 915 | UINT32 d; |
| 892 | 916 | |
| r10427 | r10428 | |
| 908 | 932 | |
| 909 | 933 | if (d == 0x0180) |
| 910 | 934 | { |
| 911 | | if (cde_response) |
| 935 | if (state->cde_response) |
| 912 | 936 | { |
| 913 | | cde_handle_command(); |
| 937 | cde_handle_command(space->machine); |
| 914 | 938 | |
| 915 | | cde_response = 0; |
| 939 | state->cde_response = 0; |
| 916 | 940 | } |
| 917 | 941 | |
| 918 | | cde_command_byte_ptr = 0; |
| 942 | state->cde_command_byte_ptr = 0; |
| 919 | 943 | } |
| 920 | | else if (cde_command_byte_ptr == 0) |
| 944 | else if (state->cde_command_byte_ptr == 0) |
| 921 | 945 | { |
| 922 | | cde_num_status_bytes = 1; |
| 946 | state->cde_num_status_bytes = 1; |
| 923 | 947 | |
| 924 | | cde_status_bytes[0] = d & 0xff; |
| 925 | | cde_status_byte_ptr = 0; |
| 948 | state->cde_status_bytes[0] = d & 0xff; |
| 949 | state->cde_status_byte_ptr = 0; |
| 926 | 950 | |
| 927 | | cde_response = 1; |
| 951 | state->cde_response = 1; |
| 928 | 952 | } |
| 929 | 953 | |
| 930 | 954 | if (d != 0x180) |
| 931 | 955 | { |
| 932 | | cde_command_bytes[cde_command_byte_ptr++] = d; |
| 956 | state->cde_command_bytes[state->cde_command_byte_ptr++] = d; |
| 933 | 957 | } |
| 934 | 958 | |
| 935 | 959 | break; |
| r10427 | r10428 | |
| 941 | 965 | |
| 942 | 966 | if (d & 0x20) |
| 943 | 967 | { |
| 944 | | cde_dma[0].dma_done = 1; |
| 968 | state->cde_dma[0].dma_done = 1; |
| 945 | 969 | |
| 946 | 970 | cde_dma_transfer(space, 0, 0); |
| 947 | 971 | } |
| 948 | 972 | if (d & 0x40) |
| 949 | 973 | { |
| 950 | | cde_dma[0].dma_done = 1; |
| 974 | state->cde_dma[0].dma_done = 1; |
| 951 | 975 | |
| 952 | 976 | cde_dma_transfer(space, 0, 1); |
| 953 | 977 | } |
| r10427 | r10428 | |
| 957 | 981 | { |
| 958 | 982 | mame_printf_debug("CDE: DMA0 dst addr %08X\n", d); |
| 959 | 983 | |
| 960 | | cde_dma[0].dst_addr = d; |
| 984 | state->cde_dma[0].dst_addr = d; |
| 961 | 985 | break; |
| 962 | 986 | } |
| 963 | 987 | case 0x30c/4: // DMA Channel 0 length? |
| 964 | 988 | { |
| 965 | 989 | mame_printf_debug("CDE: DMA0 length %08X\n", d); |
| 966 | 990 | |
| 967 | | cde_dma[0].length = d; |
| 991 | state->cde_dma[0].length = d; |
| 968 | 992 | break; |
| 969 | 993 | } |
| 970 | 994 | case 0x318/4: // DMA Channel 0 next destination address |
| 971 | 995 | { |
| 972 | 996 | mame_printf_debug("CDE: DMA0 next dst addr %08X\n", d); |
| 973 | 997 | |
| 974 | | cde_dma[0].next_dst_addr = d; |
| 998 | state->cde_dma[0].next_dst_addr = d; |
| 975 | 999 | break; |
| 976 | 1000 | } |
| 977 | 1001 | case 0x31c/4: // DMA Channel 0 next length? |
| 978 | 1002 | { |
| 979 | 1003 | mame_printf_debug("CDE: DMA0 next length %08X\n", d); |
| 980 | 1004 | |
| 981 | | cde_dma[0].next_length = d; |
| 1005 | state->cde_dma[0].next_length = d; |
| 982 | 1006 | break; |
| 983 | 1007 | } |
| 984 | 1008 | |
| r10427 | r10428 | |
| 991 | 1015 | { |
| 992 | 1016 | mame_printf_debug("CDE: DMA1 dst addr %08X\n", d); |
| 993 | 1017 | |
| 994 | | cde_dma[1].dst_addr = d; |
| 1018 | state->cde_dma[1].dst_addr = d; |
| 995 | 1019 | break; |
| 996 | 1020 | } |
| 997 | 1021 | case 0x32c/4: // DMA Channel 1 length? |
| 998 | 1022 | { |
| 999 | 1023 | mame_printf_debug("CDE: DMA1 length %08X\n", d); |
| 1000 | 1024 | |
| 1001 | | cde_dma[1].length = d; |
| 1025 | state->cde_dma[1].length = d; |
| 1002 | 1026 | break; |
| 1003 | 1027 | } |
| 1004 | 1028 | case 0x338/4: // DMA Channel 1 next destination address |
| 1005 | 1029 | { |
| 1006 | 1030 | mame_printf_debug("CDE: DMA1 next dst addr %08X\n", d); |
| 1007 | 1031 | |
| 1008 | | cde_dma[1].next_dst_addr = d; |
| 1032 | state->cde_dma[1].next_dst_addr = d; |
| 1009 | 1033 | break; |
| 1010 | 1034 | } |
| 1011 | 1035 | case 0x33c/4: // DMA Channel 1 next length? |
| 1012 | 1036 | { |
| 1013 | 1037 | mame_printf_debug("CDE: DMA1 next length %08X\n", d); |
| 1014 | 1038 | |
| 1015 | | cde_dma[1].next_length = d; |
| 1039 | state->cde_dma[1].next_length = d; |
| 1016 | 1040 | break; |
| 1017 | 1041 | } |
| 1018 | 1042 | |
| r10427 | r10428 | |
| 1020 | 1044 | { |
| 1021 | 1045 | if (d & 0x80000000) |
| 1022 | 1046 | { |
| 1023 | | irq_active &= ~0x8; |
| 1047 | state->irq_active &= ~0x8; |
| 1024 | 1048 | } |
| 1025 | 1049 | if (d & 0x60000000) |
| 1026 | 1050 | { |
| 1027 | | cde_dma[0].dma_done = 0; |
| 1028 | | cde_dma[1].dma_done = 0; |
| 1051 | state->cde_dma[0].dma_done = 0; |
| 1052 | state->cde_dma[1].dma_done = 0; |
| 1029 | 1053 | } |
| 1030 | 1054 | break; |
| 1031 | 1055 | } |
| r10427 | r10428 | |
| 1102 | 1126 | AM_RANGE(0x10000000, 0x10000007) AM_READ(cpu_r) |
| 1103 | 1127 | AM_RANGE(0x10000008, 0x10001007) AM_NOP // ??? |
| 1104 | 1128 | AM_RANGE(0x20000000, 0x201fffff) AM_ROM AM_SHARE("share2") |
| 1105 | | AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE(&main_ram) |
| 1129 | AM_RANGE(0x40000000, 0x407fffff) AM_RAM AM_SHARE("share3") AM_BASE_MEMBER(konamim2_state, main_ram) |
| 1106 | 1130 | AM_RANGE(0xfff00000, 0xffffffff) AM_ROM AM_REGION("boot", 0) AM_SHARE("share2") |
| 1107 | 1131 | ADDRESS_MAP_END |
| 1108 | 1132 | |
| r10427 | r10428 | |
| 1117 | 1141 | |
| 1118 | 1142 | static INTERRUPT_GEN(m2) |
| 1119 | 1143 | { |
| 1120 | | if (irq_enable & 0x800000) |
| 1144 | konamim2_state *state = device->machine->driver_data<konamim2_state>(); |
| 1145 | if (state->irq_enable & 0x800000) |
| 1121 | 1146 | { |
| 1122 | | irq_active |= 0x800000; |
| 1147 | state->irq_active |= 0x800000; |
| 1123 | 1148 | } |
| 1124 | 1149 | |
| 1125 | | /*if (irq_enable & 0x8) |
| 1150 | /*if (state->irq_enable & 0x8) |
| 1126 | 1151 | { |
| 1127 | | irq_active |= 0x8; |
| 1152 | state->irq_active |= 0x8; |
| 1128 | 1153 | }*/ |
| 1129 | 1154 | |
| 1130 | 1155 | cpu_set_input_line(device, INPUT_LINE_IRQ0, ASSERT_LINE); |
| 1131 | 1156 | } |
| 1132 | 1157 | |
| 1133 | | static MACHINE_CONFIG_START( m2, driver_device ) |
| 1158 | static MACHINE_CONFIG_START( m2, konamim2_state ) |
| 1134 | 1159 | |
| 1135 | 1160 | /* basic machine hardware */ |
| 1136 | 1161 | MCFG_CPU_ADD("maincpu", PPC602, 33000000) /* actually PPC602, 66MHz */ |
| r10427 | r10428 | |
| 1257 | 1282 | |
| 1258 | 1283 | static DRIVER_INIT( m2 ) |
| 1259 | 1284 | { |
| 1260 | | unk3 = U64(0xffffffffffffffff); |
| 1261 | | unk20004 = 0; |
| 1285 | konamim2_state *state = machine->driver_data<konamim2_state>(); |
| 1286 | state->unk3 = U64(0xffffffffffffffff); |
| 1287 | state->unk20004 = 0; |
| 1262 | 1288 | cde_init(machine); |
| 1263 | 1289 | } |
| 1264 | 1290 | |
src/emu/hash.c
| r10427 | r10428 | |
| 1 | | /********************************************************************* |
| 1 | /*************************************************************************** |
| 2 | 2 | |
| 3 | 3 | hash.c |
| 4 | 4 | |
| 5 | 5 | Function to handle hash functions (checksums) |
| 6 | 6 | |
| 7 | | Copyright Nicola Salmoria and the MAME Team. |
| 8 | | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | Based on original idea by Farfetch'd |
| 9 | 8 | |
| 10 | | Started by Farfetch'd |
| 9 | **************************************************************************** |
| 11 | 10 | |
| 12 | | *********************************************************************/ |
| 11 | Copyright Aaron Giles |
| 12 | All rights reserved. |
| 13 | 13 | |
| 14 | | /* |
| 15 | | * Changelog: |
| 16 | | * |
| 17 | | * 20030314: Farfetch'd |
| 18 | | * First release |
| 19 | | * |
| 20 | | */ |
| 14 | Redistribution and use in source and binary forms, with or without |
| 15 | modification, are permitted provided that the following conditions are |
| 16 | met: |
| 21 | 17 | |
| 22 | | /* |
| 23 | | * DONE: |
| 24 | | * |
| 25 | | * hash.c/h: New files, implement the new hashing engine with flexible |
| 26 | | * support for more functions (for now, CRC, SHA1 and MD5). |
| 27 | | * |
| 28 | | * common.h: transparently support the new RomModule structure through |
| 29 | | * ROM_* macros, so that old the legacy code still work |
| 30 | | * |
| 31 | | * common.c: updated ROM loading engine to support the new hash engine, |
| 32 | | * using it to verify ROM integrity at load-time. Updated printromlist() |
| 33 | | * (-listroms) to dump all the available checksums, and if a ROM is |
| 34 | | * known to be bad or not. |
| 35 | | * |
| 36 | | * info.c: -listinfo now supports any hashing function correctly |
| 37 | | * (both text and XML mode). Notice that XML header should be |
| 38 | | * rewritten to automatically define the new tags when new |
| 39 | | * functions are added, but I couldn't be bothered for now. |
| 40 | | * It also displays informations about baddump/nodump |
| 41 | | * |
| 42 | | * audit.c/h: Updated audit engine (-verifyroms) to use the new |
| 43 | | * hash functions. |
| 44 | | * |
| 45 | | * fileio.c/h: Updated file engine to use the new hash functions. |
| 46 | | * It is now possible to load by any specified checksum (in case |
| 47 | | * later we support other archivers with SHA1 signatures or |
| 48 | | * equivalent). If the file is open with flag VERIFY_ONLY and |
| 49 | | * the file is within an archive (zip), only the checksums |
| 50 | | * available in the archive header are used. |
| 51 | | * |
| 52 | | * windows/fronthlp.c: Updated -identrom to the new hash engine, now |
| 53 | | * support any hash function available. |
| 54 | | * Added -listsha1 and -listmd5. It would be possible to add |
| 55 | | * also a -listbad now, to list bad dumps (ROMS we need a |
| 56 | | * redump for) |
| 57 | | * Updated -listdupcrc to check for all the available checksums. |
| 58 | | * The output is also a bit more useful and readable, even if it |
| 59 | | * is still not optimal. |
| 60 | | * Update -listwrongmerge to check for all the available checksums. |
| 61 | | * |
| 62 | | * windows/fileio.c: Removed check for FILE_TYPE_NOCRC (does not exist |
| 63 | | * anymore). |
| 64 | | * |
| 65 | | * |
| 66 | | * |
| 67 | | * Technical details: |
| 68 | | * |
| 69 | | * Checksum informations are now stored inside a string. They are |
| 70 | | * stored in "printable hex format", which means that they use |
| 71 | | * more memory than before (since a CRC needs 8 characters to |
| 72 | | * be printed, instead of 4 bytes of raw information). In the |
| 73 | | * driver, they are defined with handy macros which rely on |
| 74 | | * automatic string pasting. |
| 75 | | * |
| 76 | | * Additional flags can also be stored in the string: for now we |
| 77 | | * support NO_DUMP and BAD_DUMP, which replace, respectively, |
| 78 | | * a CRC of 0 and a bit-inverted CRC. |
| 79 | | * |
| 80 | | * All the code that handles hash data is in hash.c. The rest of |
| 81 | | * the core treats the data as an 'opaque type', so that the |
| 82 | | * pointers are just passed along through functions but no |
| 83 | | * operation is performed on the data outside hash.c. This |
| 84 | | * is important in case we want to change the string |
| 85 | | * representation later in the future. |
| 86 | | * |
| 87 | | * When loading a ROM, MAME will calculate and compare the |
| 88 | | * checksum using any function for which the driver has declared |
| 89 | | * an expected checksum. This happens because it would be useless |
| 90 | | * to calculate a checksum if we cannot verify its correctness. |
| 91 | | * For developers, it also means that MAME will not compute the |
| 92 | | * SHA1 for you unless you specify a bogus one in the driver |
| 93 | | * (like SHA1(0)). |
| 94 | | * |
| 95 | | * When verifying a ROM, MAME will use only the checksums available |
| 96 | | * in the archive header (if zip, CRC). This is by design because |
| 97 | | * -verifyroms has always been very fast. It is feasible to add |
| 98 | | * a -fullverifyroms at a later moment, which will decompress the |
| 99 | | * files and compute every checksum that has been declared in the |
| 100 | | * driver. |
| 101 | | * |
| 102 | | * I have also prepared a little tool (SHA1Merger) which takes care |
| 103 | | * of the following tasks: |
| 104 | | * |
| 105 | | * - Given an existing driver in old syntax (0.66 compatible), it will |
| 106 | | * convert all the existing ROM_LOAD entries in the new format, and |
| 107 | | * it will automatically compute and add SHA1 checksum for you if |
| 108 | | * it can find the romset. |
| 109 | | * |
| 110 | | * - Given a romset (ZIP file), it will prepare a ROM definition |
| 111 | | * skeleton for a driver, containing already rom names, lengths, and |
| 112 | | * checksums (both CRC and SHA1). |
| 113 | | * |
| 114 | | * The tool is available on www.mame.net as platform-independent source code |
| 115 | | * (in Python), or win32 standalone executable. |
| 116 | | * |
| 117 | | */ |
| 18 | * Redistributions of source code must retain the above copyright |
| 19 | notice, this list of conditions and the following disclaimer. |
| 20 | * Redistributions in binary form must reproduce the above copyright |
| 21 | notice, this list of conditions and the following disclaimer in |
| 22 | the documentation and/or other materials provided with the |
| 23 | distribution. |
| 24 | * Neither the name 'MAME' nor the names of its contributors may be |
| 25 | used to endorse or promote products derived from this software |
| 26 | without specific prior written permission. |
| 118 | 27 | |
| 28 | THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR |
| 29 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 30 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 31 | DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT, |
| 32 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 33 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 35 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 36 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 37 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 38 | POSSIBILITY OF SUCH DAMAGE. |
| 39 | |
| 40 | ***************************************************************************/ |
| 41 | |
| 119 | 42 | #include "emu.h" |
| 120 | | #include "hash.h" |
| 43 | #include "zlib.h" |
| 121 | 44 | #include "md5.h" |
| 122 | 45 | #include "sha1.h" |
| 123 | | |
| 124 | 46 | #include <ctype.h> |
| 125 | | #include <zlib.h> |
| 126 | 47 | |
| 127 | | #define ASSERT(x) |
| 128 | 48 | |
| 129 | | #ifndef TRUE |
| 130 | | #define TRUE 1 |
| 131 | | #endif |
| 49 | //************************************************************************** |
| 50 | // TYPE DEFINITIONS |
| 51 | //************************************************************************** |
| 132 | 52 | |
| 133 | | #ifndef FALSE |
| 134 | | #define FALSE 0 |
| 135 | | #endif |
| 53 | // ======================> hash_crc |
| 136 | 54 | |
| 137 | | struct _hash_function_desc |
| 55 | // CRC-32 hash implementation |
| 56 | class hash_crc : public hash_base |
| 138 | 57 | { |
| 139 | | const char* name; // human-readable name |
| 140 | | char code; // single-char code used within the hash string |
| 141 | | unsigned int size; // checksum size in bytes |
| 58 | public: |
| 59 | // construction/destruction |
| 60 | hash_crc(); |
| 142 | 61 | |
| 143 | | // Functions used to calculate the hash of a memory block |
| 144 | | void (*calculate_begin)(void); |
| 145 | | void (*calculate_buffer)(const void* mem, unsigned long len); |
| 146 | | void (*calculate_end)(UINT8* bin_chksum); |
| 62 | // operators |
| 63 | operator UINT32() const { return (m_buffer[0] << 24) | (m_buffer[1] << 16) | (m_buffer[2] << 8) | m_buffer[3]; } |
| 147 | 64 | |
| 65 | // creation |
| 66 | virtual void begin(); |
| 67 | virtual void buffer(const UINT8 *data, UINT32 length); |
| 68 | virtual void end(); |
| 69 | |
| 70 | private: |
| 71 | // internal state |
| 72 | UINT8 m_buffer[4]; |
| 148 | 73 | }; |
| 149 | | typedef struct _hash_function_desc hash_function_desc; |
| 150 | 74 | |
| 151 | | static void h_crc_begin(void); |
| 152 | | static void h_crc_buffer(const void* mem, unsigned long len); |
| 153 | | static void h_crc_end(UINT8* chksum); |
| 154 | 75 | |
| 155 | | static void h_sha1_begin(void); |
| 156 | | static void h_sha1_buffer(const void* mem, unsigned long len); |
| 157 | | static void h_sha1_end(UINT8* chksum); |
| 76 | // ======================> hash_md5 |
| 158 | 77 | |
| 159 | | static void h_md5_begin(void); |
| 160 | | static void h_md5_buffer(const void* mem, unsigned long len); |
| 161 | | static void h_md5_end(UINT8* chksum); |
| 162 | | |
| 163 | | static const hash_function_desc hash_descs[HASH_NUM_FUNCTIONS] = |
| 78 | // MD5 hash implementation |
| 79 | class hash_md5 : public hash_base |
| 164 | 80 | { |
| 165 | | { |
| 166 | | "crc", 'c', 4, |
| 167 | | h_crc_begin, |
| 168 | | h_crc_buffer, |
| 169 | | h_crc_end |
| 170 | | }, |
| 81 | public: |
| 82 | // construction/destruction |
| 83 | hash_md5(); |
| 171 | 84 | |
| 172 | | { |
| 173 | | "sha1", 's', 20, |
| 174 | | h_sha1_begin, |
| 175 | | h_sha1_buffer, |
| 176 | | h_sha1_end |
| 177 | | }, |
| 85 | // creation |
| 86 | virtual void begin(); |
| 87 | virtual void buffer(const UINT8 *data, UINT32 length); |
| 88 | virtual void end(); |
| 178 | 89 | |
| 179 | | { |
| 180 | | "md5", 'm', 16, |
| 181 | | h_md5_begin, |
| 182 | | h_md5_buffer, |
| 183 | | h_md5_end |
| 184 | | }, |
| 90 | private: |
| 91 | // internal state |
| 92 | UINT8 m_buffer[16]; |
| 93 | struct MD5Context m_context; |
| 185 | 94 | }; |
| 186 | 95 | |
| 187 | | static const char *const info_strings[] = |
| 96 | |
| 97 | // ======================> hash_sha1 |
| 98 | |
| 99 | // SHA1 hash implementation |
| 100 | class hash_sha1 : public hash_base |
| 188 | 101 | { |
| 189 | | "$ND$", // No dump |
| 190 | | "$BD$" // Bad dump |
| 102 | public: |
| 103 | // construction/destruction |
| 104 | hash_sha1(); |
| 105 | |
| 106 | // creation |
| 107 | virtual void begin(); |
| 108 | virtual void buffer(const UINT8 *data, UINT32 length); |
| 109 | virtual void end(); |
| 110 | |
| 111 | private: |
| 112 | // internal state |
| 113 | UINT8 m_buffer[20]; |
| 114 | struct sha1_ctx m_context; |
| 191 | 115 | }; |
| 192 | 116 | |
| 193 | | static const char binToStr[] = "0123456789abcdef"; |
| 194 | 117 | |
| 195 | 118 | |
| 196 | | static const hash_function_desc* hash_get_function_desc(unsigned int function) |
| 197 | | { |
| 198 | | unsigned int idx = 0; |
| 119 | //************************************************************************** |
| 120 | // GLOBAL VARIABLES |
| 121 | //************************************************************************** |
| 199 | 122 | |
| 200 | | // Calling with zero in here is mostly an internal error |
| 201 | | ASSERT(function != 0); |
| 123 | const char *hash_collection::HASH_TYPES_CRC = "R"; |
| 124 | const char *hash_collection::HASH_TYPES_CRC_SHA1 = "RS"; |
| 125 | const char *hash_collection::HASH_TYPES_ALL = "RSM"; |
| 202 | 126 | |
| 203 | | // Compute the index of only one function |
| 204 | | while (!(function & 1)) |
| 205 | | { |
| 206 | | idx++; |
| 207 | | function >>= 1; |
| 208 | | } |
| 209 | 127 | |
| 210 | | // Specify only one bit or die |
| 211 | | ASSERT(function == 1); |
| 212 | 128 | |
| 213 | | return &hash_descs[idx]; |
| 129 | //************************************************************************** |
| 130 | // HASH BASE |
| 131 | //************************************************************************** |
| 132 | |
| 133 | //------------------------------------------------- |
| 134 | // hash_base - constructor |
| 135 | //------------------------------------------------- |
| 136 | |
| 137 | hash_base::hash_base(char id, const char *name, UINT8 length, UINT8 *bufptr) |
| 138 | : m_next(NULL), |
| 139 | m_name(name), |
| 140 | m_in_progress(false), |
| 141 | m_parse_error(false), |
| 142 | m_id(id), |
| 143 | m_length(length), |
| 144 | m_bufptr(bufptr) |
| 145 | { |
| 146 | memset(m_bufptr, 0, length); |
| 214 | 147 | } |
| 215 | 148 | |
| 216 | | const char* hash_function_name(unsigned int function) |
| 149 | |
| 150 | //------------------------------------------------- |
| 151 | // fromhex - convert a character to a hex value |
| 152 | //------------------------------------------------- |
| 153 | |
| 154 | int hash_base::fromhex(char c) |
| 217 | 155 | { |
| 218 | | const hash_function_desc* info = hash_get_function_desc(function); |
| 219 | | |
| 220 | | return info->name; |
| 156 | if (c >= '0' && c <= '9') |
| 157 | return c - '0'; |
| 158 | else if (c >= 'A' && c <= 'F') |
| 159 | return c - 'A' + 10; |
| 160 | else if (c >= 'a' && c <= 'f') |
| 161 | return (c - 'a' + 10); |
| 162 | else |
| 163 | return -1; |
| 221 | 164 | } |
| 222 | 165 | |
| 223 | | int hash_data_has_checksum(const char* data, unsigned int function) |
| 166 | |
| 167 | //------------------------------------------------- |
| 168 | // from_buffer - copy a raw buffer into the |
| 169 | // current hash |
| 170 | //------------------------------------------------- |
| 171 | |
| 172 | bool hash_base::from_buffer(const UINT8 *buffer, int buflen) |
| 224 | 173 | { |
| 225 | | const hash_function_desc* info = hash_get_function_desc(function); |
| 226 | | char str[3]; |
| 227 | | const char* res; |
| 174 | // fail if we're too small |
| 175 | if (buflen < m_length) |
| 176 | return false; |
| 177 | memcpy(m_bufptr, buffer, m_length); |
| 178 | return true; |
| 179 | } |
| 228 | 180 | |
| 229 | | str[0] = info->code; |
| 230 | | str[1] = ':'; |
| 231 | | str[2] = '\0'; |
| 232 | 181 | |
| 233 | | // Check if the specified hash function is used within this data |
| 234 | | res = strstr(data, str); |
| 182 | //------------------------------------------------- |
| 183 | // string - output a string for the current hash |
| 184 | //------------------------------------------------- |
| 235 | 185 | |
| 236 | | if (!res) |
| 237 | | return 0; |
| 238 | | |
| 239 | | // Return the offset within the string where the checksum begins |
| 240 | | return (res - data + 2); |
| 186 | const char *hash_base::string(astring &buffer) |
| 187 | { |
| 188 | buffer.reset(); |
| 189 | for (int index = 0; index < m_length; index++) |
| 190 | buffer.catprintf("%02x", m_bufptr[index]); |
| 191 | return buffer; |
| 241 | 192 | } |
| 242 | 193 | |
| 243 | | static int hash_data_add_binary_checksum(char* d, unsigned int function, const UINT8* checksum) |
| 194 | |
| 195 | //------------------------------------------------- |
| 196 | // from_string - parse a string into the current |
| 197 | // hash |
| 198 | //------------------------------------------------- |
| 199 | |
| 200 | bool hash_base::from_string(const char *&string, int length) |
| 244 | 201 | { |
| 245 | | const hash_function_desc* desc = hash_get_function_desc(function); |
| 246 | | char* start = d; |
| 247 | | unsigned i; |
| 202 | // fail if we're too short |
| 203 | if (length < 2 * m_length) |
| 204 | return false; |
| 248 | 205 | |
| 249 | | *d++ = desc->code; |
| 250 | | *d++ = ':'; |
| 251 | | |
| 252 | | for (i=0;i<desc->size;i++) |
| 206 | // loop over bytes |
| 207 | m_parse_error = false; |
| 208 | for (int index = 0; index < m_length; index++) |
| 253 | 209 | { |
| 254 | | UINT8 c = *checksum++; |
| 210 | // parse the upper digit |
| 211 | int upper = fromhex(string[0]); |
| 212 | if (upper == -1) |
| 213 | { |
| 214 | m_parse_error = true; |
| 215 | memset(m_bufptr, 0, m_length); |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | // parse the lower digit |
| 220 | int lower = fromhex(string[1]); |
| 221 | if (lower == -1) |
| 222 | { |
| 223 | m_parse_error = true; |
| 224 | memset(m_bufptr, 0, m_length); |
| 225 | return false; |
| 226 | } |
| 255 | 227 | |
| 256 | | *d++ = binToStr[(c >> 4) & 0xF]; |
| 257 | | *d++ = binToStr[(c >> 0) & 0xF]; |
| 228 | // set the byte and advance |
| 229 | m_bufptr[index] = (upper << 4) | lower; |
| 230 | string += 2; |
| 258 | 231 | } |
| 232 | return true; |
| 233 | } |
| 259 | 234 | |
| 260 | | *d++ = '#'; |
| 235 | |
| 261 | 236 | |
| 262 | | // Return the number of written bytes |
| 263 | | return (d - start); |
| 264 | | } |
| 237 | //************************************************************************** |
| 238 | // HASH CRC |
| 239 | //************************************************************************** |
| 265 | 240 | |
| 241 | //------------------------------------------------- |
| 242 | // hash_crc - constructor |
| 243 | //------------------------------------------------- |
| 266 | 244 | |
| 267 | | static int hash_compare_checksum(const char* chk1, const char* chk2, int length) |
| 245 | hash_crc::hash_crc() |
| 246 | : hash_base(hash_collection::HASH_CRC, "crc", sizeof(m_buffer), m_buffer) |
| 268 | 247 | { |
| 269 | | char c1, c2; |
| 248 | } |
| 270 | 249 | |
| 271 | | // The printable format is twice as longer |
| 272 | | length *= 2; |
| 273 | 250 | |
| 274 | | // This is basically a case-insensitive string compare |
| 275 | | while (length--) |
| 276 | | { |
| 277 | | c1 = *chk1++; |
| 278 | | c2 = *chk2++; |
| 251 | //------------------------------------------------- |
| 252 | // begin - initialize state for hash computation |
| 253 | //------------------------------------------------- |
| 279 | 254 | |
| 280 | | if (tolower((UINT8)c1) != tolower((UINT8)c2)) |
| 281 | | return 0; |
| 282 | | if (!c1) |
| 283 | | return 0; |
| 284 | | } |
| 285 | | |
| 286 | | return 1; |
| 255 | void hash_crc::begin() |
| 256 | { |
| 257 | m_in_progress = true; |
| 258 | memset(m_buffer, 0, sizeof(m_buffer)); |
| 287 | 259 | } |
| 288 | 260 | |
| 289 | 261 | |
| 290 | | // Compare two hashdata |
| 291 | | int hash_data_is_equal(const char* d1, const char* d2, unsigned int functions) |
| 262 | //------------------------------------------------- |
| 263 | // buffer - hash a buffer's worth of data |
| 264 | //------------------------------------------------- |
| 265 | |
| 266 | void hash_crc::buffer(const UINT8 *data, UINT32 length) |
| 292 | 267 | { |
| 293 | | int i; |
| 294 | | char incomplete = 0; |
| 295 | | char ok = 0; |
| 268 | UINT32 crc = crc32(*this, data, length); |
| 269 | m_buffer[0] = crc >> 24; |
| 270 | m_buffer[1] = crc >> 16; |
| 271 | m_buffer[2] = crc >> 8; |
| 272 | m_buffer[3] = crc >> 0; |
| 273 | } |
| 296 | 274 | |
| 297 | | // If no function is specified, it means we need to check for all |
| 298 | | // of them |
| 299 | | if (!functions) |
| 300 | | functions = ~functions; |
| 301 | 275 | |
| 302 | | for (i=1; i != (1<<HASH_NUM_FUNCTIONS); i<<=1) |
| 303 | | if (functions & i) |
| 304 | | { |
| 305 | | int offs1, offs2; |
| 276 | //------------------------------------------------- |
| 277 | // end - finish hash computation |
| 278 | //------------------------------------------------- |
| 306 | 279 | |
| 307 | | // Check if both hashdata contain the current function's checksum |
| 308 | | offs1 = hash_data_has_checksum(d1, i); |
| 309 | | offs2 = hash_data_has_checksum(d2, i); |
| 280 | void hash_crc::end() |
| 281 | { |
| 282 | m_in_progress = false; |
| 283 | } |
| 310 | 284 | |
| 311 | | if (offs1 && offs2) |
| 312 | | { |
| 313 | | const hash_function_desc* info = hash_get_function_desc(i); |
| 314 | 285 | |
| 315 | | if (!hash_compare_checksum(d1+offs1, d2+offs2, info->size)) |
| 316 | | return 0; |
| 317 | 286 | |
| 318 | | ok = 1; |
| 319 | | } |
| 320 | | // If the function was contained only in one, remember that our comparison |
| 321 | | // is incomplete |
| 322 | | else if (offs1 || offs2) |
| 323 | | { |
| 324 | | incomplete = 1; |
| 325 | | } |
| 326 | | } |
| 287 | //************************************************************************** |
| 288 | // HASH MD5 |
| 289 | //************************************************************************** |
| 327 | 290 | |
| 328 | | // If we could not compare any function, return error |
| 329 | | if (!ok) |
| 330 | | return 0; |
| 291 | //------------------------------------------------- |
| 292 | // hash_md5 - constructor |
| 293 | //------------------------------------------------- |
| 331 | 294 | |
| 332 | | // Return success code |
| 333 | | return (incomplete ? 2 : 1); |
| 295 | hash_md5::hash_md5() |
| 296 | : hash_base(hash_collection::HASH_MD5, "md5", sizeof(m_buffer), m_buffer) |
| 297 | { |
| 334 | 298 | } |
| 335 | 299 | |
| 336 | 300 | |
| 337 | | int hash_data_extract_printable_checksum(const char* data, unsigned int function, char* checksum) |
| 301 | //------------------------------------------------- |
| 302 | // begin - initialize state for hash computation |
| 303 | //------------------------------------------------- |
| 304 | |
| 305 | void hash_md5::begin() |
| 338 | 306 | { |
| 339 | | unsigned int i; |
| 340 | | const hash_function_desc* info; |
| 341 | | int offs; |
| 307 | m_in_progress = true; |
| 308 | MD5Init(&m_context); |
| 309 | } |
| 342 | 310 | |
| 343 | | // Check if the hashdata contains the requested function |
| 344 | | offs = hash_data_has_checksum(data, function); |
| 345 | 311 | |
| 346 | | if (!offs) |
| 347 | | return 0; |
| 312 | //------------------------------------------------- |
| 313 | // buffer - hash a buffer's worth of data |
| 314 | //------------------------------------------------- |
| 348 | 315 | |
| 349 | | // Move to the beginning of the checksum |
| 350 | | data += offs; |
| 316 | void hash_md5::buffer(const UINT8 *data, UINT32 length) |
| 317 | { |
| 318 | MD5Update(&m_context, (md5byte *)data, length); |
| 319 | } |
| 351 | 320 | |
| 352 | | info = hash_get_function_desc(function); |
| 353 | 321 | |
| 354 | | // Return the number of required bytes |
| 355 | | if (!checksum) |
| 356 | | return info->size*2+1; |
| 322 | //------------------------------------------------- |
| 323 | // end - finish hash computation |
| 324 | //------------------------------------------------- |
| 357 | 325 | |
| 358 | | // If the terminator is not found at the right position, |
| 359 | | // return a full-zero checksum and warn about it. This is mainly |
| 360 | | // for developers putting checksums of '0' or '1' to ask MAME |
| 361 | | // to compute the correct values for them. |
| 362 | | if (data[info->size*2] != '#') |
| 363 | | { |
| 364 | | memset(checksum, '0', info->size*2); |
| 365 | | checksum[info->size*2] = '\0'; |
| 366 | | return 2; |
| 367 | | } |
| 326 | void hash_md5::end() |
| 327 | { |
| 328 | MD5Final(m_buffer, &m_context); |
| 329 | m_in_progress = false; |
| 330 | } |
| 368 | 331 | |
| 369 | | // If it contains invalid hexadecimal characters, |
| 370 | | // treat the checksum as zero and return warning |
| 371 | | for (i=0;i<info->size*2;i++) |
| 372 | | if (!(data[i]>='0' && data[i]<='9') && |
| 373 | | !(data[i]>='a' && data[i]<='f') && |
| 374 | | !(data[i]>='A' && data[i]<='F')) |
| 375 | | { |
| 376 | | memset(checksum, '0', info->size*2); |
| 377 | | checksum[info->size*2] = '\0'; |
| 378 | | return 2; |
| 379 | | } |
| 380 | 332 | |
| 381 | | // Copy the checksum (and make it lowercase) |
| 382 | | for (i=0;i<info->size*2;i++) |
| 383 | | checksum[i] = tolower((UINT8)data[i]); |
| 384 | 333 | |
| 385 | | checksum[info->size*2] = '\0'; |
| 334 | //************************************************************************** |
| 335 | // HASH SHA1 |
| 336 | //************************************************************************** |
| 386 | 337 | |
| 387 | | return 1; |
| 388 | | } |
| 338 | //------------------------------------------------- |
| 339 | // hash_sha1 - constructor |
| 340 | //------------------------------------------------- |
| 389 | 341 | |
| 390 | | static int hex_string_to_binary(unsigned char* binary, const char* data, int size) |
| 342 | hash_sha1::hash_sha1() |
| 343 | : hash_base(hash_collection::HASH_SHA1, "sha1", sizeof(m_buffer), m_buffer) |
| 391 | 344 | { |
| 392 | | unsigned int i; |
| 393 | | char c; |
| 345 | } |
| 394 | 346 | |
| 395 | | for (i = 0; i < size * 2; i++) |
| 396 | | { |
| 397 | | c = tolower((UINT8)*data++); |
| 398 | 347 | |
| 399 | | if (c >= '0' && c <= '9') |
| 400 | | c -= '0'; |
| 401 | | else if (c >= 'a' && c <= 'f') |
| 402 | | c -= 'a' - 10; |
| 403 | | else |
| 404 | | return 1; |
| 348 | //------------------------------------------------- |
| 349 | // begin - initialize state for hash computation |
| 350 | //------------------------------------------------- |
| 405 | 351 | |
| 406 | | if (i % 2 == 0) |
| 407 | | binary[i / 2] = c * 16; |
| 408 | | else |
| 409 | | binary[i / 2] += c; |
| 410 | | } |
| 411 | | return 0; |
| 352 | void hash_sha1::begin() |
| 353 | { |
| 354 | m_in_progress = true; |
| 355 | sha1_init(&m_context); |
| 412 | 356 | } |
| 413 | 357 | |
| 414 | | int hash_data_extract_binary_checksum(const char* data, unsigned int function, unsigned char* checksum) |
| 415 | | { |
| 416 | | const hash_function_desc* info; |
| 417 | | int offs; |
| 418 | 358 | |
| 419 | | // Check if the hashdata contains the requested function |
| 420 | | offs = hash_data_has_checksum(data, function); |
| 359 | //------------------------------------------------- |
| 360 | // buffer - hash a buffer's worth of data |
| 361 | //------------------------------------------------- |
| 421 | 362 | |
| 422 | | if (!offs) |
| 423 | | return 0; |
| 363 | void hash_sha1::buffer(const UINT8 *data, UINT32 length) |
| 364 | { |
| 365 | sha1_update(&m_context, length, data); |
| 366 | } |
| 424 | 367 | |
| 425 | | // Move to the beginning of the checksum |
| 426 | | data += offs; |
| 427 | 368 | |
| 428 | | info = hash_get_function_desc(function); |
| 369 | //------------------------------------------------- |
| 370 | // end - finish hash computation |
| 371 | //------------------------------------------------- |
| 429 | 372 | |
| 430 | | // Return the number of required bytes |
| 431 | | if (!checksum) |
| 432 | | return info->size; |
| 373 | void hash_sha1::end() |
| 374 | { |
| 375 | sha1_final(&m_context); |
| 376 | sha1_digest(&m_context, sizeof(m_buffer), m_buffer); |
| 377 | m_in_progress = false; |
| 378 | } |
| 433 | 379 | |
| 434 | | // Clear the checksum array |
| 435 | | memset(checksum, 0, info->size); |
| 436 | 380 | |
| 437 | | // If the terminator is not found at the right position, |
| 438 | | // return a full-zero checksum and warn about it. This is mainly |
| 439 | | // for developers putting checksums of '0' or '1' to ask MAME |
| 440 | | // to compute the correct values for them. |
| 441 | | if (data[info->size*2] != '#') |
| 442 | | { |
| 443 | | memset(checksum, '\0', info->size); |
| 444 | | return 2; |
| 445 | | } |
| 446 | 381 | |
| 447 | | // Convert hex string into binary |
| 448 | | if (hex_string_to_binary(checksum, data, info->size)) |
| 449 | | { |
| 450 | | // Invalid character: the checksum is treated as zero, |
| 451 | | // and a warning is returned |
| 452 | | memset(checksum, '\0', info->size); |
| 453 | | return 2; |
| 454 | | } |
| 382 | //************************************************************************** |
| 383 | // HASH COLLECTION |
| 384 | //************************************************************************** |
| 455 | 385 | |
| 456 | | return 1; |
| 457 | | } |
| 386 | //------------------------------------------------- |
| 387 | // hash_collection - constructor |
| 388 | //------------------------------------------------- |
| 458 | 389 | |
| 459 | | int hash_data_has_info(const char* data, unsigned int info) |
| 390 | hash_collection::hash_collection() |
| 460 | 391 | { |
| 461 | | char* res = (char*)strstr(data, info_strings[info]); |
| 392 | } |
| 462 | 393 | |
| 463 | | if (!res) |
| 464 | | return 0; |
| 465 | 394 | |
| 466 | | return 1; |
| 395 | hash_collection::hash_collection(const char *string) |
| 396 | { |
| 397 | from_internal_string(string); |
| 467 | 398 | } |
| 468 | 399 | |
| 469 | | void hash_data_copy(char* dst, const char* src) |
| 400 | |
| 401 | hash_collection::hash_collection(const hash_collection &src) |
| 470 | 402 | { |
| 471 | | // Copying string is enough |
| 472 | | strcpy(dst, src); |
| 403 | copyfrom(src); |
| 473 | 404 | } |
| 474 | 405 | |
| 475 | | void hash_data_clear(char* dst) |
| 406 | |
| 407 | //------------------------------------------------- |
| 408 | // ~hash_collection - destructor |
| 409 | //------------------------------------------------- |
| 410 | |
| 411 | hash_collection::~hash_collection() |
| 476 | 412 | { |
| 477 | | // Clear the buffer |
| 478 | | memset(dst, 0, HASH_BUF_SIZE); |
| 479 | 413 | } |
| 480 | 414 | |
| 481 | | unsigned int hash_data_used_functions(const char* data) |
| 415 | |
| 416 | //------------------------------------------------- |
| 417 | // operator= - assignment operator |
| 418 | //------------------------------------------------- |
| 419 | |
| 420 | hash_collection &hash_collection::operator=(const hash_collection &src) |
| 482 | 421 | { |
| 483 | | int i; |
| 484 | | unsigned int res = 0; |
| 422 | // ignore self-assignment |
| 423 | if (this != &src) |
| 424 | copyfrom(src); |
| 425 | return *this; |
| 426 | } |
| 485 | 427 | |
| 486 | | if (!data) |
| 487 | | return 0; |
| 488 | 428 | |
| 489 | | for (i=0;i<HASH_NUM_FUNCTIONS;i++) |
| 490 | | if (hash_data_has_checksum(data, 1<<i)) |
| 491 | | res |= 1<<i; |
| 429 | //------------------------------------------------- |
| 430 | // operator== - test for equality |
| 431 | //------------------------------------------------- |
| 492 | 432 | |
| 493 | | return res; |
| 494 | | } |
| 495 | | |
| 496 | | int hash_data_insert_printable_checksum(char* d, unsigned int function, const char* checksum) |
| 433 | bool hash_collection::operator==(const hash_collection &rhs) const |
| 497 | 434 | { |
| 498 | | const hash_function_desc* desc; |
| 499 | | UINT8 binary_checksum[20]; |
| 435 | // look for a mismatch in any hash; do not fail if one is missing |
| 436 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 437 | { |
| 438 | hash_base *rhs_hash = rhs.hash(hash->id()); |
| 439 | if (hash != NULL && rhs_hash != NULL && *hash != *rhs_hash) |
| 440 | return false; |
| 441 | } |
| 500 | 442 | |
| 501 | | desc = hash_get_function_desc(function); |
| 443 | // if all shared hashes match, return true |
| 444 | return true; |
| 445 | } |
| 502 | 446 | |
| 503 | | ASSERT(desc->size <= sizeof(binary_checksum)); |
| 504 | 447 | |
| 505 | | if (hex_string_to_binary(binary_checksum, checksum, desc->size)) |
| 506 | | return 2; |
| 448 | //------------------------------------------------- |
| 449 | // hash - return a hash of the given type |
| 450 | //------------------------------------------------- |
| 507 | 451 | |
| 508 | | return hash_data_insert_binary_checksum(d, function, binary_checksum); |
| 452 | hash_base *hash_collection::hash(char type) const |
| 453 | { |
| 454 | // look for a mismatch in any hash; do not fail if one is missing |
| 455 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 456 | if (hash->id() == type) |
| 457 | return hash; |
| 458 | return NULL; |
| 509 | 459 | } |
| 510 | 460 | |
| 511 | | int hash_data_insert_binary_checksum(char* d, unsigned int function, const UINT8* checksum) |
| 512 | | { |
| 513 | | int offset; |
| 514 | 461 | |
| 515 | | offset = hash_data_has_checksum(d, function); |
| 462 | //------------------------------------------------- |
| 463 | // hash_types - return a list of hash types as |
| 464 | // a string |
| 465 | //------------------------------------------------- |
| 516 | 466 | |
| 517 | | if (!offset) |
| 518 | | { |
| 519 | | d += strlen(d); |
| 520 | | d += hash_data_add_binary_checksum(d, function, checksum); |
| 521 | | *d = '\0'; |
| 467 | const char *hash_collection::hash_types(astring &buffer) const |
| 468 | { |
| 469 | buffer.reset(); |
| 470 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 471 | buffer.cat(hash->id()); |
| 472 | return buffer; |
| 473 | } |
| 522 | 474 | |
| 523 | | return 1; |
| 524 | | } |
| 525 | | else |
| 526 | | { |
| 527 | | // Move to the start of the whole checksum signature, not only to the checksum |
| 528 | | // itself |
| 529 | | d += offset - 2; |
| 530 | 475 | |
| 531 | | // Overwrite previous checksum with new one |
| 532 | | hash_data_add_binary_checksum(d, function, checksum); |
| 476 | //------------------------------------------------- |
| 477 | // reset - reset the hash collection to an empty |
| 478 | // set of hashes and flags |
| 479 | //------------------------------------------------- |
| 533 | 480 | |
| 534 | | return 2; |
| 535 | | } |
| 481 | bool hash_collection::parse_errors() const |
| 482 | { |
| 483 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 484 | if (hash->parse_error()) |
| 485 | return true; |
| 486 | return false; |
| 536 | 487 | } |
| 537 | 488 | |
| 538 | | void hash_compute(char* dst, const unsigned char* data, unsigned long length, unsigned int functions) |
| 539 | | { |
| 540 | | int i; |
| 541 | 489 | |
| 542 | | hash_data_clear(dst); |
| 490 | //------------------------------------------------- |
| 491 | // reset - reset the hash collection to an empty |
| 492 | // set of hashes and flags |
| 493 | //------------------------------------------------- |
| 543 | 494 | |
| 544 | | // Zero means use all the functions |
| 545 | | if (functions == 0) |
| 546 | | functions = ~functions; |
| 495 | void hash_collection::reset() |
| 496 | { |
| 497 | m_hashlist.reset(); |
| 498 | m_flags.reset(); |
| 499 | } |
| 547 | 500 | |
| 548 | | for (i=0;i<HASH_NUM_FUNCTIONS;i++) |
| 549 | | { |
| 550 | | unsigned func = 1 << i; |
| 551 | 501 | |
| 552 | | if (functions & func) |
| 553 | | { |
| 554 | | const hash_function_desc* desc = hash_get_function_desc(func); |
| 555 | | UINT8 chksum[256]; |
| 502 | //------------------------------------------------- |
| 503 | // add_from_buffer - add a new hash, importing |
| 504 | // from a buffer |
| 505 | //------------------------------------------------- |
| 556 | 506 | |
| 557 | | desc->calculate_begin(); |
| 558 | | desc->calculate_buffer(data, length); |
| 559 | | desc->calculate_end(chksum); |
| 507 | hash_base *hash_collection::add_from_buffer(char type, const UINT8 *buffer, int bufflen) |
| 508 | { |
| 509 | // nuke any existing hash with the same ID |
| 510 | hash_base *existing = hash(type); |
| 511 | if (existing != NULL) |
| 512 | m_hashlist.remove(*existing); |
| 560 | 513 | |
| 561 | | dst += hash_data_add_binary_checksum(dst, func, chksum); |
| 562 | | } |
| 514 | // first allocate by ID |
| 515 | hash_base *newhash = alloc_by_id(type); |
| 516 | if (newhash == NULL) |
| 517 | return NULL; |
| 518 | |
| 519 | // then import |
| 520 | if (!newhash->from_buffer(buffer, bufflen)) |
| 521 | { |
| 522 | global_free(newhash); |
| 523 | return NULL; |
| 563 | 524 | } |
| 564 | | |
| 565 | | *dst = '\0'; |
| 525 | |
| 526 | // and append to our list |
| 527 | return &m_hashlist.append(*newhash); |
| 566 | 528 | } |
| 567 | 529 | |
| 568 | | void hash_data_print(const char* data, unsigned int functions, char* buffer) |
| 569 | | { |
| 570 | | int i, j; |
| 571 | | char first = 1; |
| 572 | 530 | |
| 573 | | if (functions == 0) |
| 574 | | functions = ~functions; |
| 531 | //------------------------------------------------- |
| 532 | // add_from_string - add a new hash, importing |
| 533 | // from a string |
| 534 | //------------------------------------------------- |
| 575 | 535 | |
| 576 | | buffer[0] = '\0'; |
| 536 | hash_base *hash_collection::add_from_string(char type, const char *buffer, int length) |
| 537 | { |
| 538 | // nuke any existing hash with the same ID |
| 539 | hash_base *existing = hash(type); |
| 540 | if (existing != NULL) |
| 541 | m_hashlist.remove(*existing); |
| 577 | 542 | |
| 578 | | for (i=0;i<HASH_NUM_FUNCTIONS;i++) |
| 543 | // first allocate by ID |
| 544 | hash_base *newhash = alloc_by_id(type); |
| 545 | if (newhash == NULL) |
| 546 | return NULL; |
| 547 | |
| 548 | // then import |
| 549 | if (!newhash->from_string(buffer, length)) |
| 579 | 550 | { |
| 580 | | unsigned func = 1 << i; |
| 581 | | |
| 582 | | if ((functions & func) && hash_data_has_checksum(data, func)) |
| 583 | | { |
| 584 | | char temp[256]; |
| 585 | | |
| 586 | | if (!first) |
| 587 | | strcat(buffer, " "); |
| 588 | | first = 0; |
| 589 | | |
| 590 | | strcpy(temp, hash_function_name(func)); |
| 591 | | for (j = 0; temp[j]; j++) |
| 592 | | temp[j] = toupper((UINT8)temp[j]); |
| 593 | | strcat(buffer, temp); |
| 594 | | strcat(buffer, "("); |
| 595 | | |
| 596 | | hash_data_extract_printable_checksum(data, func, temp); |
| 597 | | strcat(buffer, temp); |
| 598 | | strcat(buffer, ")"); |
| 599 | | } |
| 551 | global_free(newhash); |
| 552 | return NULL; |
| 600 | 553 | } |
| 554 | |
| 555 | // and append to our list |
| 556 | return &m_hashlist.append(*newhash); |
| 601 | 557 | } |
| 602 | 558 | |
| 603 | | int hash_verify_string(const char *hash) |
| 604 | | { |
| 605 | | int len, i; |
| 606 | 559 | |
| 607 | | if (!hash) |
| 608 | | return FALSE; |
| 560 | //------------------------------------------------- |
| 561 | // remove - remove a hash of the given type |
| 562 | //------------------------------------------------- |
| 609 | 563 | |
| 610 | | while(*hash) |
| 611 | | { |
| 612 | | if (*hash == '$') |
| 564 | bool hash_collection::remove(char type) |
| 565 | { |
| 566 | // scan the list of hashes for a match |
| 567 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 568 | if (hash->id() == type) |
| 613 | 569 | { |
| 614 | | if (memcmp(hash, NO_DUMP, 4) && memcmp(hash, BAD_DUMP, 4)) |
| 615 | | return FALSE; |
| 616 | | hash += 4; |
| 570 | m_hashlist.remove(*hash); |
| 571 | return true; |
| 617 | 572 | } |
| 618 | | else |
| 619 | | { |
| 620 | | /* first make sure that the next char is a colon */ |
| 621 | | if (hash[1] != ':') |
| 622 | | return FALSE; |
| 573 | |
| 574 | // didn't find it |
| 575 | return false; |
| 576 | } |
| 623 | 577 | |
| 624 | | /* search for a hash function for this code */ |
| 625 | | for (i = 0; i < sizeof(hash_descs) / sizeof(hash_descs[0]); i++) |
| 626 | | { |
| 627 | | if (*hash == hash_descs[i].code) |
| 628 | | break; |
| 629 | | } |
| 630 | | if (i >= sizeof(hash_descs) / sizeof(hash_descs[0])) |
| 631 | | return FALSE; |
| 632 | 578 | |
| 633 | | /* we have a proper code */ |
| 634 | | len = hash_descs[i].size * 2; |
| 635 | | hash += 2; |
| 579 | //------------------------------------------------- |
| 580 | // crc - return the CRC hash if present |
| 581 | //------------------------------------------------- |
| 636 | 582 | |
| 637 | | for (i = 0; (hash[i] != '#') && (i < len); i++) |
| 638 | | { |
| 639 | | if (!isxdigit((UINT8)hash[i])) |
| 640 | | return FALSE; |
| 641 | | } |
| 642 | | if (hash[i] != '#') |
| 643 | | return FALSE; |
| 583 | bool hash_collection::crc(UINT32 &result) |
| 584 | { |
| 585 | // attempt to find the CRC hash; if we fail, return false |
| 586 | hash_base *crchash = hash(HASH_CRC); |
| 587 | if (crchash == NULL) |
| 588 | return false; |
| 644 | 589 | |
| 645 | | hash += i+1; |
| 646 | | } |
| 647 | | } |
| 648 | | return TRUE; |
| 590 | // downcast to a hash_crc and convert to a UINT32 |
| 591 | result = *downcast<hash_crc *>(crchash); |
| 592 | return true; |
| 649 | 593 | } |
| 650 | 594 | |
| 651 | 595 | |
| 596 | //------------------------------------------------- |
| 597 | // add_crc - add a CRC hash |
| 598 | //------------------------------------------------- |
| 652 | 599 | |
| 653 | | /********************************************************************* |
| 654 | | Hash functions - Wrappers |
| 655 | | *********************************************************************/ |
| 600 | hash_base *hash_collection::add_crc(UINT32 crc) |
| 601 | { |
| 602 | // expand to a buffer |
| 603 | UINT8 buffer[4]; |
| 604 | buffer[0] = crc >> 24; |
| 605 | buffer[1] = crc >> 16; |
| 606 | buffer[2] = crc >> 8; |
| 607 | buffer[3] = crc >> 0; |
| 608 | |
| 609 | // add it the standard way |
| 610 | return add_from_buffer(HASH_CRC, buffer, sizeof(buffer)); |
| 611 | } |
| 656 | 612 | |
| 657 | | static UINT32 crc; |
| 658 | 613 | |
| 659 | | static void h_crc_begin(void) |
| 614 | //------------------------------------------------- |
| 615 | // internal_string - convert set of hashes and |
| 616 | // flags to a string in our internal compact |
| 617 | // format |
| 618 | //------------------------------------------------- |
| 619 | |
| 620 | const char *hash_collection::internal_string(astring &buffer) const |
| 660 | 621 | { |
| 661 | | crc = 0; |
| 622 | astring temp; |
| 623 | |
| 624 | // output hashes first |
| 625 | buffer.reset(); |
| 626 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 627 | buffer.cat(hash->id()).cat(hash->string(temp)); |
| 628 | |
| 629 | // append flags |
| 630 | buffer.cat(m_flags); |
| 631 | return buffer; |
| 662 | 632 | } |
| 663 | 633 | |
| 664 | | static void h_crc_buffer(const void* mem, unsigned long len) |
| 634 | |
| 635 | //------------------------------------------------- |
| 636 | // macro_string - convert set of hashes and |
| 637 | // flags to a string in the macroized format |
| 638 | //------------------------------------------------- |
| 639 | |
| 640 | const char *hash_collection::macro_string(astring &buffer) const |
| 665 | 641 | { |
| 666 | | crc = crc32(crc, (UINT8*)mem, len); |
| 667 | | } |
| 642 | astring temp; |
| 668 | 643 | |
| 669 | | static void h_crc_end(UINT8* bin_chksum) |
| 670 | | { |
| 671 | | bin_chksum[0] = (UINT8)(crc >> 24); |
| 672 | | bin_chksum[1] = (UINT8)(crc >> 16); |
| 673 | | bin_chksum[2] = (UINT8)(crc >> 8); |
| 674 | | bin_chksum[3] = (UINT8)(crc >> 0); |
| 644 | // output hashes first |
| 645 | buffer.reset(); |
| 646 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 647 | { |
| 648 | buffer.cat(temp.cpy(hash->name()).toupper()); |
| 649 | buffer.cat("(").cat(hash->string(temp)).cat(") "); |
| 650 | } |
| 651 | |
| 652 | // append flags |
| 653 | if (flag(FLAG_NO_DUMP)) |
| 654 | buffer.cat("NO_DUMP "); |
| 655 | if (flag(FLAG_BAD_DUMP)) |
| 656 | buffer.cat("BAD_DUMP "); |
| 657 | return buffer.trimspace(); |
| 675 | 658 | } |
| 676 | 659 | |
| 677 | 660 | |
| 678 | | static struct sha1_ctx sha1ctx; |
| 661 | //------------------------------------------------- |
| 662 | // from_internal_string - convert an internal |
| 663 | // compact string to set of hashes and flags |
| 664 | //------------------------------------------------- |
| 679 | 665 | |
| 680 | | static void h_sha1_begin(void) |
| 666 | bool hash_collection::from_internal_string(const char *string) |
| 681 | 667 | { |
| 682 | | sha1_init(&sha1ctx); |
| 668 | // start fresh |
| 669 | reset(); |
| 670 | |
| 671 | // determine the end of the string |
| 672 | const char *stringend = string + strlen(string); |
| 673 | const char *ptr = string; |
| 674 | |
| 675 | // loop until we hit it |
| 676 | bool errors = false; |
| 677 | while (ptr < stringend) |
| 678 | { |
| 679 | char c = *ptr++; |
| 680 | char lc = tolower(c); |
| 681 | |
| 682 | // non-hex alpha values specify a hash type |
| 683 | if (lc >= 'g' && lc <= 'z') |
| 684 | { |
| 685 | hash_base *hash = alloc_by_id(c); |
| 686 | if (hash != NULL) |
| 687 | { |
| 688 | if (!hash->from_string(ptr, stringend - ptr)) |
| 689 | errors = true; |
| 690 | m_hashlist.append(*hash); |
| 691 | } |
| 692 | else |
| 693 | errors = true; |
| 694 | } |
| 695 | |
| 696 | // hex values are ignored, though unexpected |
| 697 | else if ((lc >= '0' && lc <= '9') || (lc >= 'a' && lc <= 'f')) |
| 698 | errors = true; |
| 699 | |
| 700 | // anything else is a flag |
| 701 | else |
| 702 | m_flags.cat(c); |
| 703 | } |
| 704 | return !errors; |
| 683 | 705 | } |
| 684 | 706 | |
| 685 | | static void h_sha1_buffer(const void* mem, unsigned long len) |
| 707 | |
| 708 | //------------------------------------------------- |
| 709 | // begin - begin hashing |
| 710 | //------------------------------------------------- |
| 711 | |
| 712 | void hash_collection::begin(const char *types) |
| 686 | 713 | { |
| 687 | | sha1_update(&sha1ctx, len, (UINT8*)mem); |
| 714 | // by default use all types |
| 715 | if (types == NULL) |
| 716 | { |
| 717 | m_hashlist.append(*alloc_by_id(HASH_CRC)).begin(); |
| 718 | m_hashlist.append(*alloc_by_id(HASH_MD5)).begin(); |
| 719 | m_hashlist.append(*alloc_by_id(HASH_SHA1)).begin(); |
| 720 | } |
| 721 | |
| 722 | // otherwise, just allocate the ones that are specified |
| 723 | else |
| 724 | { |
| 725 | for (const char *scan = types; *scan != 0; scan++) |
| 726 | { |
| 727 | // nuke any existing hash of this type |
| 728 | hash_base *existing = hash(*scan); |
| 729 | if (existing != NULL) |
| 730 | m_hashlist.remove(*existing); |
| 731 | |
| 732 | // append a new one |
| 733 | m_hashlist.append(*alloc_by_id(*scan)).begin(); |
| 734 | } |
| 735 | } |
| 688 | 736 | } |
| 689 | 737 | |
| 690 | | static void h_sha1_end(UINT8* bin_chksum) |
| 738 | |
| 739 | //------------------------------------------------- |
| 740 | // buffer - add the given buffer to the hash |
| 741 | //------------------------------------------------- |
| 742 | |
| 743 | void hash_collection::buffer(const UINT8 *data, UINT32 length) |
| 691 | 744 | { |
| 692 | | sha1_final(&sha1ctx); |
| 693 | | sha1_digest(&sha1ctx, 20, bin_chksum); |
| 745 | // buffer each hash appropriately |
| 746 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 747 | if (hash->in_progress()) |
| 748 | hash->buffer(data, length); |
| 694 | 749 | } |
| 695 | 750 | |
| 696 | 751 | |
| 697 | | static struct MD5Context md5_ctx; |
| 752 | //------------------------------------------------- |
| 753 | // end - stop hashing |
| 754 | //------------------------------------------------- |
| 698 | 755 | |
| 699 | | static void h_md5_begin(void) |
| 756 | void hash_collection::end() |
| 700 | 757 | { |
| 701 | | MD5Init(&md5_ctx); |
| 758 | // end each hash |
| 759 | for (hash_base *hash = m_hashlist.first(); hash != NULL; hash = hash->next()) |
| 760 | if (hash->in_progress()) |
| 761 | hash->end(); |
| 702 | 762 | } |
| 703 | 763 | |
| 704 | | static void h_md5_buffer(const void* mem, unsigned long len) |
| 764 | |
| 765 | //------------------------------------------------- |
| 766 | // alloc_by_id - based on the ID character, |
| 767 | // allocate a new hash |
| 768 | //------------------------------------------------- |
| 769 | |
| 770 | hash_base *hash_collection::alloc_by_id(char id) |
| 705 | 771 | { |
| 706 | | MD5Update(&md5_ctx, (md5byte*)mem, len); |
| 772 | switch (id) |
| 773 | { |
| 774 | case HASH_CRC: return global_alloc(hash_crc); |
| 775 | case HASH_MD5: return global_alloc(hash_md5); |
| 776 | case HASH_SHA1: return global_alloc(hash_sha1); |
| 777 | default: return NULL; |
| 778 | } |
| 707 | 779 | } |
| 708 | 780 | |
| 709 | | static void h_md5_end(UINT8* bin_chksum) |
| 781 | |
| 782 | //------------------------------------------------- |
| 783 | // copyfrom - copy everything from another |
| 784 | // collection |
| 785 | //------------------------------------------------- |
| 786 | |
| 787 | void hash_collection::copyfrom(const hash_collection &src) |
| 710 | 788 | { |
| 711 | | MD5Final(bin_chksum, &md5_ctx); |
| 789 | // copy flags directly |
| 790 | m_flags = src.m_flags; |
| 791 | |
| 792 | // rebuild the hashlist by copying from the source |
| 793 | m_hashlist.reset(); |
| 794 | for (hash_base *hash = src.first(); hash != NULL; hash = hash->next()) |
| 795 | add_from_buffer(hash->id(), hash->buffer(), hash->length()); |
| 712 | 796 | } |