src/mess/video/odyssey2.c
| r1810 | r1811 | |
| 11 | 11 | #include "cpu/i8039/i8039.h" |
| 12 | 12 | #include "includes/odyssey2.h" |
| 13 | 13 | |
| 14 | |
| 15 | #define COLLISION_SPRITE_0 0x01 |
| 16 | #define COLLISION_SPRITE_1 0x02 |
| 17 | #define COLLISION_SPRITE_2 0x04 |
| 18 | #define COLLISION_SPRITE_3 0x08 |
| 19 | #define COLLISION_VERTICAL_GRID 0x10 |
| 20 | #define COLLISION_HORIZ_GRID_DOTS 0x20 |
| 21 | #define COLLISION_EXTERNAL_UNUSED 0x40 |
| 22 | #define COLLISION_CHARACTERS 0x80 |
| 23 | |
| 14 | 24 | /* character sprite colors |
| 15 | 25 | dark grey, red, green, orange, blue, violet, light grey, white |
| 16 | 26 | dark back / grid colors |
| r1810 | r1811 | |
| 150 | 160 | } s; |
| 151 | 161 | } o2_vdc= { { 0 } }; |
| 152 | 162 | |
| 153 | | static UINT8 collision[8]; /* only 7 used but easier to index */ |
| 154 | | static int line; |
| 155 | | static attotime line_time; |
| 156 | | static UINT32 o2_snd_shift[2]; |
| 157 | | static UINT8 x_beam_pos; |
| 158 | | static UINT8 y_beam_pos; |
| 163 | static UINT32 o2_snd_shift[2]; |
| 164 | static UINT8 x_beam_pos; |
| 165 | static UINT8 y_beam_pos; |
| 166 | static UINT8 control_status; |
| 167 | static UINT8 collision_status; |
| 168 | static int iff; |
| 169 | static emu_timer *i824x_line_timer; |
| 170 | static emu_timer *i824x_hblank_timer; |
| 171 | static bitmap_t *tmp_bitmap; |
| 172 | static int start_vpos; |
| 173 | static int start_vblank; |
| 159 | 174 | |
| 160 | | /*************************************************************************** |
| 161 | 175 | |
| 162 | | Start the video hardware emulation. |
| 163 | | |
| 164 | | ***************************************************************************/ |
| 165 | | |
| 166 | | VIDEO_START( odyssey2 ) |
| 167 | | { |
| 168 | | o2_snd_shift[0] = machine->sample_rate / 983; |
| 169 | | o2_snd_shift[1] = machine->sample_rate / 3933; |
| 170 | | |
| 171 | | odyssey2_vh_hpos = 0; |
| 172 | | odyssey2_display = (UINT8 *) auto_malloc(8 * 8 * 256); |
| 173 | | memset(odyssey2_display, 0, 8 * 8 * 256); |
| 174 | | } |
| 175 | | |
| 176 | | INLINE int get_horiz_clock_beam_pos( void ) |
| 177 | | { |
| 178 | | int h; |
| 179 | | h = attotime_mul(attotime_sub(timer_get_time(), line_time), cpunum_get_clock(0) * 8).seconds; |
| 180 | | |
| 181 | | return h; |
| 182 | | } |
| 183 | | |
| 184 | | INLINE int get_horiz_clock( void ) |
| 185 | | { |
| 186 | | int h; |
| 187 | | h = attotime_mul(attotime_sub(timer_get_time(), line_time), cpunum_get_clock(0)).seconds; |
| 188 | | |
| 189 | | return h; |
| 190 | | } |
| 191 | | |
| 192 | | INLINE int horiz_scan_active( void ) |
| 193 | | { |
| 194 | | int h; |
| 195 | | h = get_horiz_clock(); |
| 196 | | |
| 197 | | if ( h > 15 ) |
| 198 | | return 1; |
| 199 | | |
| 200 | | return 0; |
| 201 | | } |
| 202 | | |
| 203 | | INLINE int in_vblank( void ) |
| 204 | | { |
| 205 | | if ((line > 239) && (line < 262)) |
| 206 | | return 1; |
| 207 | | |
| 208 | | return 0; |
| 209 | | } |
| 210 | | |
| 211 | 176 | PALETTE_INIT( odyssey2 ) |
| 212 | 177 | { |
| 213 | 178 | palette_set_colors_rgb(machine, 0, odyssey2_colors, sizeof(odyssey2_colors) / 3); |
| 214 | 179 | } |
| 215 | 180 | |
| 216 | | extern READ8_HANDLER( odyssey2_video_r ) |
| 181 | READ8_HANDLER( odyssey2_video_r ) |
| 217 | 182 | { |
| 218 | 183 | UINT8 data = 0; |
| 219 | | int bit, i; |
| 220 | 184 | |
| 221 | 185 | switch (offset) |
| 222 | 186 | { |
| 223 | 187 | case 0xa1: |
| 188 | data = control_status; |
| 189 | iff = 0; |
| 190 | cpunum_set_input_line(Machine, 0, 0, CLEAR_LINE); |
| 191 | control_status &= ~ 0x08; |
| 192 | if ( video_screen_get_hpos( 0 ) < I824X_START_ACTIVE_SCAN || video_screen_get_hpos( 0 ) > I824X_END_ACTIVE_SCAN ) { |
| 193 | data |= 1; |
| 194 | } |
| 224 | 195 | |
| 225 | | if (horiz_scan_active()) |
| 226 | | data |= 1; |
| 227 | | |
| 228 | | if (in_vblank()) |
| 229 | | data |= 8; |
| 230 | | |
| 231 | 196 | break; |
| 232 | 197 | |
| 233 | 198 | case 0xa2: |
| 199 | data = collision_status; |
| 200 | collision_status = 0; |
| 234 | 201 | |
| 235 | | bit = 0x01; |
| 236 | | |
| 237 | | for (i = 0; i < 8; i++) |
| 238 | | { |
| 239 | | /* o2_vdc.s.collision at this point has the requested bit(s) |
| 240 | | * to test the current collisions against. TODO: Sometimes |
| 241 | | * $A2 has more than one bit set. What are the correct semantics |
| 242 | | * of that when reading back? For now having an entire byte |
| 243 | | * for each graphics object that can collide is working. |
| 244 | | */ |
| 245 | | |
| 246 | | if (bit & o2_vdc.s.collision) |
| 247 | | data |= (collision[i] & ~bit); |
| 248 | | |
| 249 | | bit <<= 1; |
| 250 | | } |
| 251 | | |
| 252 | 202 | break; |
| 253 | 203 | |
| 254 | 204 | case 0xa4: |
| 255 | 205 | |
| 256 | 206 | if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 257 | | y_beam_pos = line; |
| 207 | y_beam_pos = video_screen_get_vpos( 0 ) - start_vpos; |
| 258 | 208 | |
| 259 | 209 | data = y_beam_pos; |
| 260 | 210 | |
| r1810 | r1811 | |
| 263 | 213 | |
| 264 | 214 | case 0xa5: |
| 265 | 215 | |
| 266 | | if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) |
| 267 | | x_beam_pos = get_horiz_clock_beam_pos(); |
| 216 | if ((o2_vdc.s.control & VDC_CONTROL_REG_STROBE_XY)) { |
| 217 | x_beam_pos = video_screen_get_hpos( 0 ); |
| 218 | if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) { |
| 219 | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + I824X_LINE_CLOCKS; |
| 220 | } else { |
| 221 | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 222 | } |
| 223 | } |
| 268 | 224 | |
| 269 | 225 | data = x_beam_pos; |
| 270 | 226 | |
| r1810 | r1811 | |
| 277 | 233 | return data; |
| 278 | 234 | } |
| 279 | 235 | |
| 280 | | extern WRITE8_HANDLER( odyssey2_video_w ) |
| 236 | WRITE8_HANDLER( odyssey2_video_w ) |
| 281 | 237 | { |
| 282 | 238 | /* Update the sound */ |
| 283 | 239 | if( offset >= 0xa7 && offset <= 0xaa ) |
| r1810 | r1811 | |
| 289 | 245 | && !(data & VDC_CONTROL_REG_STROBE_XY)) |
| 290 | 246 | { |
| 291 | 247 | /* Toggling strobe bit, tuck away values */ |
| 292 | | x_beam_pos = get_horiz_clock_beam_pos(); |
| 293 | | y_beam_pos = line; |
| 248 | x_beam_pos = video_screen_get_hpos( 0 ); |
| 249 | if ( x_beam_pos < I824X_START_ACTIVE_SCAN ) { |
| 250 | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN + 228; |
| 251 | } else { |
| 252 | x_beam_pos = x_beam_pos - I824X_START_ACTIVE_SCAN; |
| 253 | } |
| 294 | 254 | |
| 255 | y_beam_pos = video_screen_get_vpos( 0 ) - start_vpos; |
| 256 | |
| 295 | 257 | /* This is wrong but more games work with it, TODO: Figure |
| 296 | 258 | * out correct change. Maybe update the screen here?? |
| 297 | 259 | * It seems what happens is 0x0 is written to $A0 just before |
| r1810 | r1811 | |
| 305 | 267 | o2_vdc.reg[offset] = data; |
| 306 | 268 | } |
| 307 | 269 | |
| 308 | | extern READ8_HANDLER( odyssey2_t1_r ) |
| 270 | READ8_HANDLER( odyssey2_t1_r ) |
| 309 | 271 | { |
| 310 | | static int t = FALSE; |
| 311 | | |
| 312 | | t = !t; |
| 313 | | return t; |
| 272 | if ( video_screen_get_vpos( 0 ) > start_vpos && video_screen_get_vpos( 0 ) < start_vblank ) { |
| 273 | if ( video_screen_get_hpos( 0 ) >= I824X_START_ACTIVE_SCAN && video_screen_get_hpos( 0 ) < I824X_END_ACTIVE_SCAN ) { |
| 274 | return 1; |
| 275 | } |
| 276 | } |
| 277 | return 0; |
| 314 | 278 | } |
| 315 | 279 | |
| 316 | | INTERRUPT_GEN( odyssey2_line ) |
| 317 | | { |
| 318 | | line_time = timer_get_time(); |
| 319 | | line = (line + 1) % 262; |
| 280 | static TIMER_CALLBACK( i824x_scanline_callback ) { |
| 281 | UINT8 collision_map[160]; |
| 282 | int vpos = video_screen_get_vpos( 0 ); |
| 320 | 283 | |
| 321 | | switch (line) |
| 322 | | { |
| 323 | | case 252: |
| 324 | | cpunum_set_input_line(machine, 0, 0, ASSERT_LINE); /* vsync?? */ |
| 325 | | break; |
| 326 | | case 253: |
| 327 | | cpunum_set_input_line(machine, 0, 0, CLEAR_LINE); /* vsync?? */ |
| 328 | | break; |
| 329 | | } |
| 330 | | } |
| 284 | if ( vpos < start_vpos ) |
| 285 | return; |
| 331 | 286 | |
| 332 | | INLINE void odyssey2_draw_box(UINT8 bg[][320], int x, int y, int width, int height, UINT8 collision_id) |
| 333 | | { |
| 334 | | int x1,y1; |
| 335 | | for (y1 = 0; y1 < height; y1++) |
| 336 | | { |
| 337 | | for (x1 = 0; x1 < width; x1++) |
| 338 | | bg[y+y1][x+x1] |= collision_id; |
| 339 | | } |
| 340 | | } |
| 287 | if ( vpos == start_vpos ) { |
| 288 | control_status &= ~0x08; |
| 289 | } |
| 341 | 290 | |
| 342 | | INLINE void odyssey2_draw(bitmap_t *bitmap, UINT8 bg[][320], UINT8 code, int x, int y, int scale_x, int scale_y, UINT8 collision_id, UINT32 col) |
| 343 | | { |
| 344 | | int m,x1,y1; |
| 345 | | for (m=0x80; m>0; m>>=1, x+=scale_x) |
| 346 | | { |
| 347 | | if (code & m) |
| 348 | | { |
| 349 | | for (y1=0; y1<scale_y; y1++) |
| 350 | | { |
| 351 | | for (x1 = 0; x1 < scale_x; x1++) |
| 352 | | { |
| 353 | | bg[y+y1][x+x1] |= collision_id; |
| 354 | | *BITMAP_ADDR16(bitmap, y+y1, x+x1) = col; |
| 291 | if ( vpos < start_vblank ) { |
| 292 | rectangle rect; |
| 293 | int sprite_width[4] = { 8, 8, 8, 8 }; |
| 294 | int i; |
| 295 | |
| 296 | control_status &= ~ 0x01; |
| 297 | |
| 298 | /* Draw a line */ |
| 299 | rect.min_y = rect.max_y = vpos; |
| 300 | rect.min_x = I824X_START_ACTIVE_SCAN; |
| 301 | rect.max_x = I824X_END_ACTIVE_SCAN - 1; |
| 302 | fillbitmap( tmp_bitmap, machine->pens[(o2_vdc.s.color >> 3) & 0x7], &rect ); |
| 303 | |
| 304 | /* Clear collision map */ |
| 305 | memset( collision_map, 0, sizeof( collision_map ) ); |
| 306 | |
| 307 | /* Display grid if enabled */ |
| 308 | if ( o2_vdc.s.control & 0x08 ) { |
| 309 | UINT16 color = machine->pens[ ( o2_vdc.s.color & 7 ) | ( ( o2_vdc.s.color >> 3 ) & 0x08 ) ]; |
| 310 | int x_grid_offset = 8; |
| 311 | int y_grid_offset = 24; |
| 312 | int width = 16; |
| 313 | int height = 24; |
| 314 | int w = ( o2_vdc.s.control & 0x80 ) ? width : 2; |
| 315 | int j, k, y; |
| 316 | |
| 317 | /* Draw horizontal part of grid */ |
| 318 | for ( j = 1, y = 0; y < 9; y++, j <<= 1 ) { |
| 319 | if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + y * height + 3 ) { |
| 320 | for ( i = 0; i < 9; i++ ) { |
| 321 | if ( ( o2_vdc.s.hgrid[0][i] & j ) || ( o2_vdc.s.hgrid[1][i] & ( j >> 8 ) ) ) { |
| 322 | for ( k = 0; k < width + 2; k++ ) { |
| 323 | int px = x_grid_offset + i * width + k; |
| 324 | collision_map[ px ] |= COLLISION_HORIZ_GRID_DOTS; |
| 325 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 326 | } |
| 327 | } |
| 328 | } |
| 355 | 329 | } |
| 356 | 330 | } |
| 357 | | } |
| 358 | | } |
| 359 | | } |
| 360 | 331 | |
| 361 | | // different bit ordering, maybe I should change rom |
| 362 | | INLINE void odyssey2_draw_sprite(bitmap_t *bitmap, UINT8 bg[][320], UINT8 code, int x, int y, int scale_x, int scale_y, UINT8 collision_id, UINT32 col) |
| 363 | | { |
| 364 | | int m,x1,y1; |
| 332 | /* Draw vertical part of grid */ |
| 333 | for( j = 1, y = 0; y < 8; y++, j <<= 1 ) { |
| 334 | if ( y_grid_offset + y * height <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y_grid_offset + ( y + 1 ) * height ) { |
| 335 | for ( i = 0; i < 10; i++ ) { |
| 336 | if ( o2_vdc.s.vgrid[i] & j ) { |
| 337 | for ( k = 0; k < w; k++ ) { |
| 338 | int px = x_grid_offset + i * width + k; |
| 365 | 339 | |
| 366 | | for (m=1; m<=0x80; m<<=1, x+=scale_x) |
| 367 | | { |
| 368 | | if (code & m) |
| 369 | | { |
| 370 | | for (y1=0; y1<scale_y; y1++) |
| 371 | | { |
| 372 | | for (x1 = 0; x1 < scale_x; x1++) |
| 373 | | { |
| 374 | | bg[y+y1][x+x1] |= collision_id; |
| 375 | | *BITMAP_ADDR16(bitmap, y+y1, x+x1) = col; |
| 340 | /* Check if we collide with an already drawn source object */ |
| 341 | if ( collision_map[ px ] & o2_vdc.s.collision ) { |
| 342 | collision_status |= COLLISION_VERTICAL_GRID; |
| 343 | } |
| 344 | /* Check if an already drawn object would collide with us */ |
| 345 | if ( COLLISION_VERTICAL_GRID & o2_vdc.s.collision && collision_map[ px ] ) { |
| 346 | collision_status |= collision_map[ px ]; |
| 347 | } |
| 348 | collision_map[ px ] |= COLLISION_VERTICAL_GRID; |
| 349 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + px ) = color; |
| 350 | } |
| 351 | } |
| 352 | } |
| 376 | 353 | } |
| 377 | 354 | } |
| 378 | 355 | } |
| 379 | | } |
| 380 | | } |
| 381 | 356 | |
| 382 | | INLINE void odyssey2_draw_grid( bitmap_t* bitmap, UINT8 bg[][320] ) |
| 383 | | { |
| 384 | | int width = 16; |
| 385 | | int height = 24; |
| 386 | | int i, j, x, y; |
| 387 | | int color; |
| 388 | | int w = 2; |
| 389 | | int x_grid_offset = 8; |
| 390 | | int y_grid_offset = 24; |
| 357 | /* Display objects if enabled */ |
| 358 | if ( o2_vdc.s.control & 0x20 ) { |
| 359 | /* Regular foreground objects */ |
| 360 | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.foreground ); i++ ) { |
| 361 | int y = o2_vdc.s.foreground[i].y; |
| 362 | int height = 8; |
| 391 | 363 | |
| 392 | | color = o2_vdc.s.color & 7; |
| 393 | | color |= (o2_vdc.s.color >> 3) & 8; |
| 364 | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) { |
| 365 | UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.foreground[i].color & 0x0E ) >> 1 ) ]; |
| 366 | int offset = ( o2_vdc.s.foreground[i].ptr | ( ( o2_vdc.s.foreground[i].color & 0x01 ) << 8 ) ) + ( ( vpos - start_vpos ) >> 1 ); |
| 367 | UINT8 chr = ((char*)o2_shape)[ offset & 0x1FF ]; |
| 368 | int x = o2_vdc.s.foreground[i].x; |
| 369 | UINT8 m; |
| 394 | 370 | |
| 395 | | for (i=0, x=0; x<9; x++, i++) |
| 396 | | { |
| 397 | | for (j=1, y=0; y<9; y++, j<<=1) |
| 398 | | { |
| 399 | | if ( ((j<=0x80)&&(o2_vdc.s.hgrid[0][i]&j)) |
| 400 | | ||((j>0x80)&&(o2_vdc.s.hgrid[1][i]&1)) ) |
| 401 | | { |
| 402 | | odyssey2_draw_box(bg, x_grid_offset + x * width, y_grid_offset + y * height, width + 2, 3, COLLISION_HORIZ_GRID_DOTS); |
| 403 | | plot_box(bitmap, x_grid_offset + x * width, y_grid_offset + y * height, width + 2, 3, Machine->pens[color]); |
| 404 | | } |
| 405 | | } |
| 406 | | } |
| 371 | for ( m = 0x80; m > 0; m >>= 1, x++ ) { |
| 372 | if ( chr & m ) { |
| 373 | if ( x >= 0 && x < 160 ) { |
| 374 | /* Check if we collide with an already drawn source object */ |
| 375 | if ( collision_map[ x ] & o2_vdc.s.collision ) { |
| 376 | collision_status |= COLLISION_CHARACTERS; |
| 377 | } |
| 378 | /* Check if an already drawn object would collide with us */ |
| 379 | if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) { |
| 380 | collision_status |= collision_map[ x ]; |
| 381 | } |
| 382 | collision_map[ x ] |= COLLISION_CHARACTERS; |
| 383 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | } |
| 407 | 389 | |
| 408 | | if (o2_vdc.s.control & 0x80) /* fill solid to end of next vert line */ |
| 409 | | w=width; |
| 390 | /* Quad objects */ |
| 391 | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.quad ); i++ ) { |
| 392 | int y = o2_vdc.s.quad[i].single[0].y; |
| 393 | int height = 8; |
| 410 | 394 | |
| 411 | | for (i=0, x=0; x<10; x++, i++) |
| 412 | | { |
| 413 | | for (j=1, y=0; y<8; y++, j<<=1) |
| 414 | | { |
| 415 | | if (o2_vdc.s.vgrid[i] & j) |
| 416 | | { |
| 417 | | odyssey2_draw_box(bg, x_grid_offset + x * width, y_grid_offset + y * height, w, height, COLLISION_VERTICAL_GRID); |
| 418 | | plot_box(bitmap, x_grid_offset + x * width, y_grid_offset + y * height, w, height, Machine->pens[color]); |
| 419 | | } |
| 420 | | } |
| 421 | | } |
| 422 | | } |
| 395 | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) { |
| 396 | int x = o2_vdc.s.quad[i].single[0].x; |
| 397 | int j; |
| 423 | 398 | |
| 424 | | INLINE void odyssey2_draw_char(bitmap_t *bitmap, UINT8 bg[][320], int x, int y, int ptr, int color) |
| 425 | | { |
| 426 | | int n, i; |
| 427 | | int offset = ptr | ((color & 1) << 8); |
| 428 | | UINT32 col = Machine->pens[16 + ( ( color & 0xe ) >> 1 )]; |
| 399 | for ( j = 0; j < ARRAY_LENGTH( o2_vdc.s.quad[0].single ); j++, x += 8 ) { |
| 400 | UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.quad[i].single[j].color & 0x0E ) >> 1 ) ]; |
| 401 | int offset = ( o2_vdc.s.quad[i].single[j].ptr | ( ( o2_vdc.s.quad[i].single[j].color & 0x01 ) << 8 ) ) + ( ( vpos - start_vpos ) >> 1 ); |
| 402 | UINT8 chr = ((char*)o2_shape)[ offset & 0x1FF ]; |
| 403 | UINT8 m; |
| 429 | 404 | |
| 430 | | offset=(offset + (y >> 1)) & 0x1ff; |
| 405 | for ( m = 0x80; m > 0; m >>= 1, x++ ) { |
| 406 | if ( chr & m ) { |
| 407 | if ( x >= 0 && x < 160 ) { |
| 408 | /* Check if we collide with an already drawn source object */ |
| 409 | if ( collision_map[ x ] & o2_vdc.s.collision ) { |
| 410 | collision_status |= COLLISION_CHARACTERS; |
| 411 | } |
| 412 | /* Check if an already drawn object would collide with us */ |
| 413 | if ( COLLISION_CHARACTERS & o2_vdc.s.collision && collision_map[ x ] ) { |
| 414 | collision_status |= collision_map[ x ]; |
| 415 | } |
| 416 | collision_map[ x ] |= COLLISION_CHARACTERS; |
| 417 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | } |
| 431 | 424 | |
| 432 | | // don't ask me about the technical background, but also this height thingy is needed |
| 433 | | // invaders aliens (!) and shoot (-) |
| 434 | | n = 8 - (ptr & 7) - ((y >> 1) & 7); |
| 425 | /* Sprites */ |
| 426 | for ( i = 0; i < ARRAY_LENGTH( o2_vdc.s.sprites ); i++ ) { |
| 427 | int y = o2_vdc.s.sprites[i].y; |
| 428 | int height = 8; |
| 429 | if ( o2_vdc.s.sprites[i].color & 4 ) { |
| 430 | /* Zoomed sprite */ |
| 431 | sprite_width[i] = 16; |
| 432 | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 4 ) { |
| 433 | UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ) ]; |
| 434 | UINT8 chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 2 ) ]; |
| 435 | int x = o2_vdc.s.sprites[i].x; |
| 436 | UINT8 m; |
| 435 | 437 | |
| 436 | | if (n < 3) |
| 437 | | n += 7; |
| 438 | for ( m = 0x01; m > 0; m <<= 1, x += 2 ) { |
| 439 | if ( chr & m ) { |
| 440 | if ( x >= 0 && x < 160 ) { |
| 441 | /* Check if we collide with an already drawn source object */ |
| 442 | if ( collision_map[ x ] & o2_vdc.s.collision ) { |
| 443 | collision_status |= ( 1 << i ); |
| 444 | } |
| 445 | /* Check if an already drawn object would collide with us */ |
| 446 | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) { |
| 447 | collision_status |= collision_map[ x ]; |
| 448 | } |
| 449 | collision_map[ x ] |= ( 1 << i ); |
| 450 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 451 | } |
| 452 | if ( x >= -1 && x < 159 ) { |
| 453 | /* Check if we collide with an already drawn source object */ |
| 454 | if ( collision_map[ x ] & o2_vdc.s.collision ) { |
| 455 | collision_status |= ( 1 << i ); |
| 456 | } |
| 457 | /* Check if an already drawn object would collide with us */ |
| 458 | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) { |
| 459 | collision_status |= collision_map[ x ]; |
| 460 | } |
| 461 | collision_map[ x ] |= ( 1 << i ); |
| 462 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x + 1 ) = color; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | } else { |
| 468 | /* Regular sprite */ |
| 469 | if ( y <= ( vpos - start_vpos ) && ( vpos - start_vpos ) < y + height * 2 ) { |
| 470 | UINT16 color = machine->pens[ 16 + ( ( o2_vdc.s.sprites[i].color >> 3 ) & 0x07 ) ]; |
| 471 | UINT8 chr = o2_vdc.s.shape[i][ ( ( vpos - start_vpos - y ) >> 1 ) ]; |
| 472 | int x = o2_vdc.s.sprites[i].x; |
| 473 | UINT8 m; |
| 438 | 474 | |
| 439 | | for (i=0; i<n; i++) |
| 440 | | { |
| 441 | | if (y + i * 2 >= bitmap->height ) |
| 442 | | break; |
| 475 | for ( m = 0x01; m > 0; m <<= 1, x++ ) { |
| 476 | if ( chr & m ) { |
| 477 | if ( x >= 0 && x < 160 ) { |
| 478 | /* Check if we collide with an already drawn source object */ |
| 479 | if ( collision_map[ x ] & o2_vdc.s.collision ) { |
| 480 | collision_status |= ( 1 << i ); |
| 481 | } |
| 482 | /* Check if an already drawn object would collide with us */ |
| 483 | if ( ( 1 << i ) & o2_vdc.s.collision && collision_map[ x ] ) { |
| 484 | collision_status |= collision_map[ x ]; |
| 485 | } |
| 486 | collision_map[ x ] |= ( 1 << i ); |
| 487 | *BITMAP_ADDR16( tmp_bitmap, vpos, I824X_START_ACTIVE_SCAN + x ) = color; |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 443 | 496 | |
| 444 | | odyssey2_draw(bitmap, bg, ((char*)o2_shape)[offset], x, y+i*2, 1, 2, COLLISION_CHARACTERS, col); |
| 445 | | offset=(offset+1) & 0x1ff; |
| 446 | | } |
| 497 | /* Check for start of VBlank */ |
| 498 | if ( vpos == start_vblank ) { |
| 499 | control_status |= 0x08; |
| 500 | if ( ! iff ) { |
| 501 | cpunum_set_input_line(machine, 0, 0, ASSERT_LINE); |
| 502 | iff = 1; |
| 503 | } |
| 504 | } |
| 447 | 505 | } |
| 448 | 506 | |
| 507 | static TIMER_CALLBACK( i824x_hblank_callback ) { |
| 508 | int vpos = video_screen_get_vpos( 0 ); |
| 509 | |
| 510 | if ( vpos < start_vpos - 1 ) |
| 511 | return; |
| 512 | |
| 513 | if ( vpos < start_vblank - 1 ) { |
| 514 | control_status |= 0x01; |
| 515 | } |
| 516 | } |
| 517 | |
| 449 | 518 | /*************************************************************************** |
| 450 | 519 | |
| 451 | | Refresh the video screen |
| 520 | Start the video hardware emulation. |
| 452 | 521 | |
| 453 | 522 | ***************************************************************************/ |
| 454 | 523 | |
| 455 | | VIDEO_UPDATE( odyssey2 ) |
| 524 | VIDEO_START( odyssey2 ) |
| 456 | 525 | { |
| 457 | | int i, j, x, y; |
| 458 | | UINT8 bg[313][320]= { { 0 } }; |
| 526 | o2_snd_shift[0] = machine->sample_rate / 983; |
| 527 | o2_snd_shift[1] = machine->sample_rate / 3933; |
| 459 | 528 | |
| 460 | | assert(bitmap->width<=ARRAY_LENGTH(bg[0]) && bitmap->height<=ARRAY_LENGTH(bg)); |
| 529 | odyssey2_vh_hpos = 0; |
| 530 | odyssey2_display = (UINT8 *) auto_malloc(8 * 8 * 256); |
| 531 | memset(odyssey2_display, 0, 8 * 8 * 256); |
| 461 | 532 | |
| 462 | | plot_box( bitmap, 0, 0, bitmap->width, bitmap->height, machine->pens[(o2_vdc.s.color >> 3) & 0x7] ); |
| 533 | start_vpos = I824X_START_Y; |
| 534 | start_vblank = I824X_START_Y + I824X_SCREEN_HEIGHT; |
| 535 | control_status = 0; |
| 536 | iff = 0; |
| 463 | 537 | |
| 464 | | if (o2_vdc.s.control & 0x08) /* show grid */ |
| 465 | | odyssey2_draw_grid(bitmap, bg); |
| 538 | tmp_bitmap = auto_bitmap_alloc( machine->screen[0].width, machine->screen[0].height, machine->screen[0].format ); |
| 466 | 539 | |
| 467 | | if (o2_vdc.s.control & 0x20) /* show foreground objects */ |
| 468 | | { |
| 469 | | for (i=0; i<ARRAY_LENGTH(o2_vdc.s.foreground); i++) |
| 470 | | { |
| 471 | | odyssey2_draw_char(bitmap, bg, |
| 472 | | o2_vdc.s.foreground[i].x, o2_vdc.s.foreground[i].y, |
| 473 | | o2_vdc.s.foreground[i].ptr, o2_vdc.s.foreground[i].color); |
| 474 | | } |
| 540 | i824x_line_timer = timer_alloc( i824x_scanline_callback, NULL ); |
| 541 | timer_adjust_periodic( i824x_line_timer, video_screen_get_time_until_pos( 0, 1, I824X_START_ACTIVE_SCAN ), 0, video_screen_get_scan_period( 0 ) ); |
| 475 | 542 | |
| 476 | | for (i=0; i<ARRAY_LENGTH(o2_vdc.s.quad); i++) |
| 477 | | { |
| 478 | | x=o2_vdc.s.quad[i].single[0].x; |
| 479 | | for (j=0; j<ARRAY_LENGTH(o2_vdc.s.quad[0].single); j++, x+=2*8) |
| 480 | | { |
| 481 | | odyssey2_draw_char(bitmap, bg, |
| 482 | | x, y=o2_vdc.s.quad[i].single[0].y, |
| 483 | | o2_vdc.s.quad[i].single[j].ptr, o2_vdc.s.quad[i].single[j].color); |
| 484 | | } |
| 485 | | } |
| 543 | i824x_hblank_timer = timer_alloc( i824x_hblank_callback, NULL ); |
| 544 | timer_adjust_periodic( i824x_hblank_timer, video_screen_get_time_until_pos( 0, 1, I824X_END_ACTIVE_SCAN + 18 ), 0, video_screen_get_scan_period( 0 ) ); |
| 545 | } |
| 486 | 546 | |
| 487 | | for (i=0; i<ARRAY_LENGTH(o2_vdc.s.sprites); i++) |
| 488 | | { |
| 489 | | UINT32 col = machine->pens[16+((o2_vdc.s.sprites[i].color>>3)&7)]; |
| 547 | /*************************************************************************** |
| 490 | 548 | |
| 491 | | y=o2_vdc.s.sprites[i].y; |
| 492 | | x=o2_vdc.s.sprites[i].x; |
| 549 | Refresh the video screen |
| 493 | 550 | |
| 494 | | for (j=0; j<8; j++) |
| 495 | | { |
| 496 | | if (o2_vdc.s.sprites[i].color & 4) |
| 497 | | { |
| 498 | | if (y+4*j>=bitmap->height) |
| 499 | | break; |
| 500 | | odyssey2_draw_sprite(bitmap, bg, o2_vdc.s.shape[i][j], x, y+j*4, 2, 4, 1<<i, col); /* 1 << i is sprite collision index */ |
| 501 | | } |
| 551 | ***************************************************************************/ |
| 502 | 552 | |
| 503 | | else |
| 504 | | { |
| 505 | | if (y+j*2>=bitmap->height) |
| 506 | | break; |
| 507 | | odyssey2_draw_sprite(bitmap, bg, o2_vdc.s.shape[i][j], x, y+j*2, 1, 2, 1<<i, col); /* 1 << i is sprite collision index */ |
| 508 | | } |
| 509 | | } |
| 510 | | } |
| 511 | | } |
| 553 | VIDEO_UPDATE( odyssey2 ) |
| 554 | { |
| 555 | copybitmap( bitmap, tmp_bitmap, 0, 0, 0, 0, cliprect ); |
| 512 | 556 | |
| 513 | | memset( collision, 0, sizeof( collision ) ); |
| 514 | | |
| 515 | | for (y=0; y<300; y++) |
| 516 | | { |
| 517 | | for (x=0; x<320; x++) |
| 518 | | { |
| 519 | | switch (bg[y][x]) |
| 520 | | { |
| 521 | | case 0: case 1: case 2: case 4: case 8: |
| 522 | | case 0x10: case 0x20: case 0x80: |
| 523 | | /* Only one collidable entity in this spot, no collision to mark */ |
| 524 | | break; |
| 525 | | |
| 526 | | default: |
| 527 | | { |
| 528 | | int bit = 0x01; |
| 529 | | for (i = 0; i < 8; i++) |
| 530 | | { |
| 531 | | if (bit & o2_vdc.s.collision && bit & bg[y][x]) |
| 532 | | collision[i] |= bg[y][x] & ~bit; |
| 533 | | |
| 534 | | bit <<= 1; |
| 535 | | } |
| 536 | | break; |
| 537 | | } |
| 538 | | } |
| 539 | | } |
| 540 | | } |
| 541 | | |
| 542 | 557 | return 0; |
| 543 | 558 | } |
| 544 | 559 | |
| r1810 | r1811 | |
| 590 | 605 | *buffer = 0; |
| 591 | 606 | } |
| 592 | 607 | } |
| 608 | |
| 609 | /* |
| 610 | Thomson EF9340/EF9341 extra chips in the g7400 |
| 611 | */ |
| 612 | |
| 613 | static struct { |
| 614 | UINT8 X; |
| 615 | UINT8 Y; |
| 616 | UINT8 Y0; |
| 617 | UINT8 R; |
| 618 | UINT8 M; |
| 619 | UINT8 TA; |
| 620 | UINT8 TB; |
| 621 | UINT8 busy; |
| 622 | UINT8 ram[1024]; |
| 623 | } ef9341; |
| 624 | |
| 625 | INLINE UINT16 ef9341_get_c_addr( void ) { |
| 626 | if ( ( ef9341.Y & 0x0C ) == 0x0C ) { |
| 627 | return 0x318 | ( ( ef9341.X & 0x38 ) << 2 ) | ( ef9341.X & 0x07 ); |
| 628 | } |
| 629 | if ( ef9341.X & 0x20 ) { |
| 630 | return 0x300 | ( ( ef9341.Y & 0x07 ) << 5 ) | ( ef9341.Y & 0x18 ) | ( ef9341.X & 0x07 ); |
| 631 | } |
| 632 | return ( ef9341.Y << 5 ) | ef9341.X; |
| 633 | } |
| 634 | |
| 635 | INLINE void ef9341_inc_c( void ) { |
| 636 | ef9341.X++; |
| 637 | if ( ef9341.X >= 40 ) { |
| 638 | ef9341.Y = ( ef9341.Y + 1 ) % 24; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | void ef9341_w( int command, int b, UINT8 data ) { |
| 643 | logerror("ef9341 %s write, t%s, data %02X\n", command ? "command" : "data", b ? "B" : "A", data ); |
| 644 | |
| 645 | if ( command ) { |
| 646 | if ( b ) { |
| 647 | ef9341.TB = data; |
| 648 | ef9341.busy = 0x80; |
| 649 | switch( ef9341.TB & 0xE0 ) { |
| 650 | case 0x00: /* Begin row */ |
| 651 | ef9341.X = 0; |
| 652 | ef9341.Y = ef9341.TA & 0x1F; |
| 653 | break; |
| 654 | case 0x20: /* Load Y */ |
| 655 | ef9341.Y = ef9341.TA & 0x1F; |
| 656 | break; |
| 657 | case 0x40: /* Load X */ |
| 658 | ef9341.X = ef9341.TA & 0x3F; |
| 659 | break; |
| 660 | case 0x60: /* INC C */ |
| 661 | ef9341_inc_c(); |
| 662 | break; |
| 663 | case 0x80: /* Load M */ |
| 664 | ef9341.M = ef9341.TA; |
| 665 | break; |
| 666 | case 0xA0: /* Load R */ |
| 667 | ef9341.R = ef9341.TA; |
| 668 | break; |
| 669 | case 0xC0: /* Load Y0 */ |
| 670 | ef9341.Y0 = ef9341.TA & 0x3F; |
| 671 | break; |
| 672 | } |
| 673 | ef9341.busy = 0; |
| 674 | } else { |
| 675 | ef9341.TA = data; |
| 676 | } |
| 677 | } else { |
| 678 | if ( b ) { |
| 679 | ef9341.TB = data; |
| 680 | ef9341.busy = 0x80; |
| 681 | switch ( ef9341.M & 0xE0 ) { |
| 682 | case 0x00: /* Write */ |
| 683 | ef9341.ram[ ef9341_get_c_addr() ] = ef9341.TB; |
| 684 | ef9341_inc_c(); |
| 685 | break; |
| 686 | case 0x20: /* Read */ |
| 687 | logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 ); |
| 688 | ef9341_inc_c(); |
| 689 | break; |
| 690 | case 0x40: /* Write without increment */ |
| 691 | case 0x60: /* Read without increment */ |
| 692 | case 0x80: /* Write slice */ |
| 693 | case 0xA0: /* Read slice */ |
| 694 | logerror("ef9341 unimplemented data action %02X\n", ef9341.M & 0xE0 ); |
| 695 | break; |
| 696 | } |
| 697 | ef9341.busy = 0; |
| 698 | } else { |
| 699 | ef9341.TA = data; |
| 700 | } |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | UINT8 ef9341_r( int command, int b ) { |
| 705 | UINT8 data = 0xFF; |
| 706 | |
| 707 | logerror("ef9341 %s read, t%s\n", command ? "command" : "data", b ? "B" : "A" ); |
| 708 | if ( command ) { |
| 709 | if ( b ) { |
| 710 | data = 0xFF; |
| 711 | } else { |
| 712 | data = ef9341.busy; |
| 713 | } |
| 714 | } else { |
| 715 | if ( b ) { |
| 716 | data = ef9341.TB; |
| 717 | ef9341.busy = 0x80; |
| 718 | } else { |
| 719 | data = ef9341.TA; |
| 720 | } |
| 721 | } |
| 722 | return data; |
| 723 | } |
| 724 | |