src/mess/machine/kc.c
| r15431 | r15432 | |
| 350 | 350 | /* BASIC takes next priority */ |
| 351 | 351 | LOG(("BASIC rom 0x0c000\n")); |
| 352 | 352 | |
| 353 | | membank("bank4")->set_base(machine().root_device().memregion("basic")->base()); |
| 353 | membank("bank4")->set_base(memregion("basic")->base()); |
| 354 | 354 | space->install_read_bank(0xc000, 0xdfff, "bank4"); |
| 355 | 355 | space->unmap_write(0xc000, 0xdfff); |
| 356 | 356 | } |
| r15431 | r15432 | |
| 373 | 373 | /* enable CAOS rom in memory range 0x0e000-0x0ffff */ |
| 374 | 374 | LOG(("CAOS rom 0x0e000\n")); |
| 375 | 375 | /* read will access the rom */ |
| 376 | | membank("bank5")->set_base(machine().root_device().memregion("caos")->base() + 0x2000); |
| 376 | membank("bank5")->set_base(memregion("caos")->base() + 0x2000); |
| 377 | 377 | space->install_read_bank(0xe000, 0xffff, "bank5"); |
| 378 | 378 | space->unmap_write(0xe000, 0xffff); |
| 379 | 379 | } |
| r15431 | r15432 | |
| 397 | 397 | /* IRM enabled */ |
| 398 | 398 | LOG(("IRM enabled\n")); |
| 399 | 399 | |
| 400 | | membank("bank3")->set_base(m_ram_base + 0x4000); |
| 400 | membank("bank3")->set_base(m_video_ram); |
| 401 | 401 | space->install_readwrite_bank(0x8000, 0xbfff, "bank3"); |
| 402 | 402 | } |
| 403 | 403 | else |
| r15431 | r15432 | |
| 462 | 462 | /* CAOS rom takes priority */ |
| 463 | 463 | LOG(("CAOS rom 0x0c000\n")); |
| 464 | 464 | |
| 465 | | membank("bank4")->set_base(machine().root_device().memregion("caos")->base()); |
| 465 | membank("bank4")->set_base(memregion("caos")->base()); |
| 466 | 466 | space->install_read_bank(0xc000, 0xdfff, "bank4"); |
| 467 | 467 | space->unmap_write(0xc000, 0xdfff); |
| 468 | 468 | } |
| r15431 | r15432 | |
| 475 | 475 | |
| 476 | 476 | int bank = memregion("basic")->bytes() == 0x8000 ? (m_port_86_data>>5) & 0x03 : 0; |
| 477 | 477 | |
| 478 | | membank("bank4")->set_base(machine().root_device().memregion("basic")->base() + (bank << 13)); |
| 478 | membank("bank4")->set_base(memregion("basic")->base() + (bank << 13)); |
| 479 | 479 | space->install_read_bank(0xc000, 0xdfff, "bank4"); |
| 480 | 480 | space->unmap_write(0xc000, 0xdfff); |
| 481 | 481 | } |
| r15431 | r15432 | |
| 498 | 498 | /* IRM enabled - has priority over RAM8 enabled */ |
| 499 | 499 | LOG(("IRM enabled\n")); |
| 500 | 500 | |
| 501 | | UINT8* ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), (m_port_84_data & 0x04), (m_port_84_data & 0x02)); |
| 501 | UINT8* ram_page = m_video_ram + ((BIT(m_port_84_data, 2)<<15) | (BIT(m_port_84_data, 1)<<14)); |
| 502 | 502 | |
| 503 | 503 | membank("bank3")->set_base(ram_page); |
| 504 | 504 | space->install_readwrite_bank(0x8000, 0xa7ff, "bank3"); |
| 505 | 505 | |
| 506 | | ram_page = (UINT8*)kc85_4_get_video_ram_base(machine(), 0, 0); |
| 507 | | |
| 508 | | membank("bank6")->set_base(ram_page + 0x2800); |
| 506 | membank("bank6")->set_base(m_video_ram + 0x2800); |
| 509 | 507 | space->install_readwrite_bank(0xa800, 0xbfff, "bank6"); |
| 510 | 508 | } |
| 511 | 509 | else if (m_pio_data[1] & (1<<5)) |
| r15431 | r15432 | |
| 645 | 643 | |
| 646 | 644 | m_port_84_data = data; |
| 647 | 645 | |
| 648 | | kc85_4_video_ram_select_bank(machine(), data & 0x01); |
| 646 | video_control_w(data); |
| 649 | 647 | |
| 650 | | m_high_resolution = (data & 0x08) ? 0 : 1; |
| 651 | | |
| 652 | 648 | update_0x08000(); |
| 653 | 649 | } |
| 654 | 650 | |
| r15431 | r15432 | |
| 724 | 720 | |
| 725 | 721 | } |
| 726 | 722 | |
| 727 | | static TIMER_CALLBACK(kc85_15khz_timer_callback ) |
| 723 | TIMER_DEVICE_CALLBACK( kc_scanline ) |
| 728 | 724 | { |
| 729 | | kc_state *state = machine.driver_data<kc_state>(); |
| 725 | kc_state *state = timer.machine().driver_data<kc_state>(); |
| 726 | int scanline = (int)param; |
| 730 | 727 | |
| 731 | | /* toggle state of square wave */ |
| 732 | | state->m_kc85_15khz_state^=1; |
| 728 | /* set clock input for channel 0 and 1 to ctc */ |
| 729 | z80ctc_trg0_w(state->m_z80ctc, 1); |
| 730 | z80ctc_trg0_w(state->m_z80ctc, 0); |
| 731 | z80ctc_trg1_w(state->m_z80ctc, 1); |
| 732 | z80ctc_trg1_w(state->m_z80ctc, 0); |
| 733 | 733 | |
| 734 | | /* set clock input for channel 2 and 3 to ctc */ |
| 735 | | z80ctc_trg0_w(state->m_z80ctc, state->m_kc85_15khz_state); |
| 736 | | z80ctc_trg1_w(state->m_z80ctc, state->m_kc85_15khz_state); |
| 737 | | } |
| 738 | | |
| 739 | | static TIMER_CALLBACK(kc85_50hz_timer_callback) |
| 740 | | { |
| 741 | | kc_state *state = machine.driver_data<kc_state>(); |
| 742 | | |
| 743 | | /* toggle state of square wave */ |
| 744 | | state->m_kc85_50hz_state^=1; |
| 745 | | |
| 746 | | /* set clock input for channel 2 and 3 to ctc */ |
| 747 | | z80ctc_trg2_w(state->m_z80ctc, state->m_kc85_50hz_state); |
| 748 | | z80ctc_trg3_w(state->m_z80ctc, state->m_kc85_50hz_state); |
| 749 | | } |
| 750 | | |
| 751 | | /* video blink */ |
| 752 | | WRITE_LINE_MEMBER( kc_state::ctc_zc2_callback ) |
| 753 | | { |
| 754 | | /* is blink enabled? */ |
| 755 | | if (m_pio_data[1] & (1<<7)) |
| 734 | if (scanline == 256) |
| 756 | 735 | { |
| 757 | | /* yes */ |
| 758 | | /* toggle state of blink to video hardware */ |
| 759 | | kc85_video_set_blink_state(machine(), state); |
| 736 | /* set clock input for channel 2 and 3 to ctc */ |
| 737 | z80ctc_trg2_w(state->m_z80ctc, 1); |
| 738 | z80ctc_trg2_w(state->m_z80ctc, 0); |
| 739 | z80ctc_trg3_w(state->m_z80ctc, 1); |
| 740 | z80ctc_trg3_w(state->m_z80ctc, 0); |
| 760 | 741 | } |
| 761 | 742 | } |
| 762 | 743 | |
| r15431 | r15432 | |
| 781 | 762 | m_cassette_timer = machine().scheduler().timer_alloc(FUNC(kc_cassette_timer_callback)); |
| 782 | 763 | m_cassette_oneshot_timer = machine().scheduler().timer_alloc(FUNC(kc_cassette_oneshot_timer)); |
| 783 | 764 | |
| 784 | | // kc85 has a 50 Hz input to the ctc channel 2 and 3 |
| 785 | | // channel 2 this controls the video colour flash |
| 786 | | // kc85 has a 15 kHz (?) input to the ctc channel 0 and 1 |
| 787 | | // channel 0 and channel 1 are used for cassette write |
| 788 | | machine().scheduler().timer_pulse(attotime::from_hz(50), FUNC(kc85_50hz_timer_callback), 0, NULL); |
| 789 | | machine().scheduler().timer_pulse(attotime::from_hz(15625), FUNC(kc85_15khz_timer_callback), 0, NULL); |
| 790 | | |
| 791 | 765 | m_ram_base = m_ram->pointer(); |
| 792 | 766 | |
| 793 | 767 | m_expansions[0] = machine().device<kcexp_slot_device>("m8"); |
| r15431 | r15432 | |
| 806 | 780 | update_0x0c000(); |
| 807 | 781 | update_0x0e000(); |
| 808 | 782 | |
| 809 | | m_kc85_50hz_state = 0; |
| 810 | | m_kc85_15khz_state = 0; |
| 811 | | |
| 812 | 783 | // set low resolution at reset |
| 813 | 784 | m_high_resolution = 0; |
| 814 | 785 | |
src/mess/video/kc.c
| r15431 | r15432 | |
| 9 | 9 | #include "emu.h" |
| 10 | 10 | #include "includes/kc.h" |
| 11 | 11 | |
| 12 | | /* KC85/4 and KC85/3 common graphics hardware */ |
| 13 | | |
| 14 | | static const unsigned short kc85_colour_table[KC85_PALETTE_SIZE] = |
| 12 | // 3 bit colour value. bit 2->green, bit 1->red, bit 0->blue |
| 13 | static const UINT8 kc85_palette[KC85_PALETTE_SIZE * 3] = |
| 15 | 14 | { |
| 16 | | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
| 17 | | 16, 17, 18, 19, 20, 21, 22, 23 |
| 18 | | }; |
| 15 | // foreground colours, "full" of each component |
| 16 | 0x00, 0x00, 0x00, // black |
| 17 | 0x00, 0x00, 0xd0, // blue |
| 18 | 0xd0, 0x00, 0x00, // red |
| 19 | 0xd0, 0x00, 0xd0, // magenta |
| 20 | 0x00, 0xd0, 0x00, // green |
| 21 | 0x00, 0xd0, 0xd0, // cyan |
| 22 | 0xd0, 0xd0, 0x00, // yellow |
| 23 | 0xd0, 0xd0, 0xd0, // white |
| 19 | 24 | |
| 20 | | /* |
| 21 | | foreground: |
| 25 | // full of each component + half of another component |
| 26 | 0x00, 0x00, 0x00, // black |
| 27 | 0x60, 0x00, 0xa0, // violet |
| 28 | 0xa0, 0x60, 0x00, // brown |
| 29 | 0xa0, 0x00, 0x60, // red/purple |
| 30 | 0x00, 0xa0, 0x60, // pastel green |
| 31 | 0x00, 0x60, 0xa0, // sky blue |
| 32 | 0xa0, 0xa0, 0x60, // yellow/green |
| 33 | 0xd0, 0xd0, 0xd0, // white |
| 22 | 34 | |
| 23 | | "full" of each component |
| 24 | | |
| 25 | | black, |
| 26 | | blue, |
| 27 | | red, |
| 28 | | magenta, |
| 29 | | green, |
| 30 | | cyan |
| 31 | | yellow |
| 32 | | white |
| 33 | | |
| 34 | | "full of each component + half of another component" |
| 35 | | black |
| 36 | | violet |
| 37 | | red/purple |
| 38 | | pastel green |
| 39 | | sky blue |
| 40 | | yellow/green |
| 41 | | white |
| 42 | | |
| 43 | | background: |
| 44 | | "half" of each component |
| 45 | | black |
| 46 | | dark blue |
| 47 | | dark red |
| 48 | | dark magenta |
| 49 | | dark green |
| 50 | | dark cyan |
| 51 | | dark yellow |
| 52 | | dark white (grey) |
| 53 | | |
| 54 | | */ |
| 55 | | |
| 56 | | |
| 57 | | static const unsigned char kc85_palette[KC85_PALETTE_SIZE * 3] = |
| 58 | | { |
| 59 | | /* 3 bit colour value. bit 2->green, bit 1->red, bit 0->blue */ |
| 60 | | |
| 61 | | /* foreground colours */ |
| 62 | | 0x00, 0x00, 0x00, |
| 63 | | 0x00, 0x00, 0xd0, |
| 64 | | 0xd0, 0x00, 0x00, |
| 65 | | 0xd0, 0x00, 0xd0, |
| 66 | | 0x00, 0xd0, 0x00, |
| 67 | | 0x00, 0xd0, 0xd0, |
| 68 | | 0xd0, 0xd0, 0x00, |
| 69 | | 0xd0, 0xd0, 0xd0, |
| 70 | | |
| 71 | | 0x00, 0x00, 0x00, |
| 72 | | 0x60, 0x00, 0xa0, |
| 73 | | 0xa0, 0x60, 0x00, |
| 74 | | 0xa0, 0x00, 0x60, |
| 75 | | 0x00, 0xa0, 0x60, |
| 76 | | 0x00, 0x60, 0xa0, |
| 77 | | 0xa0, 0xa0, 0x60, |
| 78 | | 0xd0, 0xd0, 0xd0, |
| 79 | | |
| 80 | | /* background colours are slightly darker than foreground colours */ |
| 81 | | 0x00, 0x00, 0x00, |
| 82 | | 0x00, 0x00, 0xa0, |
| 83 | | 0xa0, 0x00, 0x00, |
| 84 | | 0xa0, 0x00, 0xa0, |
| 85 | | 0x00, 0xa0, 0x00, |
| 86 | | 0x00, 0xa0, 0xa0, |
| 87 | | 0xa0, 0xa0, 0x00, |
| 88 | | 0xa0, 0xa0, 0xa0 |
| 89 | | |
| 35 | // background colours are slightly darker than foreground colours |
| 36 | 0x00, 0x00, 0x00, // black |
| 37 | 0x00, 0x00, 0xa0, // dark blue |
| 38 | 0xa0, 0x00, 0x00, // dark red |
| 39 | 0xa0, 0x00, 0xa0, // dark magenta |
| 40 | 0x00, 0xa0, 0x00, // dark green |
| 41 | 0x00, 0xa0, 0xa0, // dark cyan |
| 42 | 0xa0, 0xa0, 0x00, // dark yellow |
| 43 | 0xa0, 0xa0, 0xa0 // dark white (grey) |
| 90 | 44 | }; |
| 91 | 45 | |
| 92 | 46 | |
| 93 | 47 | /* Initialise the palette */ |
| 94 | 48 | PALETTE_INIT( kc85 ) |
| 95 | 49 | { |
| 96 | | int i; |
| 97 | | |
| 98 | | for ( i = 0; i < sizeof(kc85_palette) / 3; i++ ) { |
| 50 | for (int i = 0; i < sizeof(kc85_palette) / 3; i++ ) |
| 99 | 51 | palette_set_color_rgb(machine, i, kc85_palette[i*3], kc85_palette[i*3+1], kc85_palette[i*3+2]); |
| 100 | | } |
| 101 | 52 | } |
| 102 | 53 | |
| 103 | | |
| 104 | | enum |
| 54 | /* set new blink state */ |
| 55 | WRITE_LINE_MEMBER( kc_state::video_toggle_blink_state ) |
| 105 | 56 | { |
| 106 | | KC85_VIDEO_EVENT_SET_BLINK_STATE |
| 107 | | }; |
| 57 | if (state) |
| 58 | { |
| 59 | machine().primary_screen->update_partial(machine().primary_screen->vpos()); |
| 108 | 60 | |
| 109 | | /* set new blink state - record blink state in event list */ |
| 110 | | void kc85_video_set_blink_state(running_machine &machine, int data) |
| 111 | | { |
| 112 | | //spectrum_EventList_AddItemOffset(machine, KC85_VIDEO_EVENT_SET_BLINK_STATE, ((data & 0x01)<<7), machine.firstcpu->attotime_to_cycles(machine.primary_screen->scan_period() * machine.primary_screen->vpos())); |
| 61 | m_kc85_blink_state = !m_kc85_blink_state; |
| 62 | } |
| 113 | 63 | } |
| 114 | 64 | |
| 115 | 65 | |
| 116 | 66 | /* draw 8 pixels */ |
| 117 | | static void kc85_draw_8_pixels(kc_state *state, bitmap_ind16 &bitmap,int x,int y, unsigned char colour_byte, unsigned char gfx_byte) |
| 67 | void kc_state::video_draw_8_pixels(bitmap_ind16 &bitmap, int x, int y, UINT8 colour_byte, UINT8 gfx_byte) |
| 118 | 68 | { |
| 119 | | int background_pen; |
| 120 | | int foreground_pen; |
| 121 | 69 | int pens[4]; |
| 122 | 70 | int px; |
| 123 | 71 | |
| 124 | | if (state->m_high_resolution) |
| 72 | if (m_high_resolution) |
| 125 | 73 | { |
| 126 | 74 | /* High resolution: 4 colors for block */ |
| 127 | 75 | |
| r15431 | r15432 | |
| 162 | 110 | /* bit 1: background colour -> Red */ |
| 163 | 111 | /* bit 0: background colour -> Blue */ |
| 164 | 112 | |
| 165 | | background_pen = (colour_byte&7) + 16; |
| 166 | | foreground_pen = ((colour_byte>>3) & 0x0f); |
| 113 | int background_pen = (colour_byte&7) + 16; |
| 114 | int foreground_pen = ((colour_byte>>3) & 0x0f); |
| 167 | 115 | |
| 168 | | if (colour_byte & state->m_kc85_blink_state) |
| 116 | if ((colour_byte & 0x80) && m_kc85_blink_state && (m_pio_data[1] & 0x80)) |
| 169 | 117 | { |
| 170 | 118 | foreground_pen = background_pen; |
| 171 | 119 | } |
| r15431 | r15432 | |
| 190 | 138 | } |
| 191 | 139 | |
| 192 | 140 | |
| 193 | | /* height of screen in lines */ |
| 194 | | #define KC85_SCREEN_HEIGHT 256 |
| 195 | | /* width of display in pixels */ |
| 196 | | #define KC85_SCREEN_WIDTH 320 |
| 197 | | /* height of top border in lines */ |
| 198 | | #define KC85_TOP_BORDER_SIZE 8 |
| 199 | | /* height of bottom border in lines */ |
| 200 | | #define KC85_BOTTOM_BORDER_SIZE 8 |
| 201 | | /* total number of lines in whole frame */ |
| 202 | | #define KC85_FRAME_NUM_LINES 312 |
| 203 | | /* width of whole line in pixels */ |
| 204 | | #define KC85_LINE_SIZE 512 |
| 205 | | /* width of left border in pixels */ |
| 206 | | #define KC85_LEFT_BORDER_SIZE 8 |
| 207 | | /* width of right border in pixels */ |
| 208 | | #define KC85_RIGHT_BORDER_SIZE 8 |
| 209 | | /* width of horizontal retrace in pixels */ |
| 210 | | #define KC85_RETRACE_SIZE (KC85_LINE_SIZE - KC85_LEFT_BORDER_SIZE - KC85_RIGHT_BORDER_SIZE - KC85_SCREEN_WIDTH) |
| 211 | | /* number of lines in vertical retrace */ |
| 212 | | #define KC85_NUM_RETRACE_LINES (KC85_FRAME_NUM_LINES - KC85_TOP_BORDER_SIZE - KC85_BOTTOM_BORDER_SIZE - KC85_SCREEN_HEIGHT) |
| 213 | | |
| 214 | | |
| 215 | | #define KC85_CYCLES_PER_FRAME 1750000.0f/50.0f |
| 216 | | #define KC85_CYCLES_PER_LINE (KC85_CYCLES_PER_FRAME/KC85_FRAME_NUM_LINES) |
| 217 | | #define KC85_CYCLES_PER_PIXEL (KC85_CYCLES_PER_LINE/KC85_LINE_SIZE) |
| 218 | | |
| 219 | | /* |
| 220 | | |
| 221 | | - 1750000 cpu cycles per second |
| 222 | | - 35000 cpu cycles per frame |
| 223 | | - 35000/312 = 112.179 cycles per line |
| 224 | | - 112.179/(512/8) = 1.752 cycles per 8-pixels |
| 225 | | */ |
| 226 | | |
| 227 | | /* Operation: |
| 228 | | |
| 229 | | - Vertical and horizontal dimensions are split into states. |
| 230 | | - Horizontal states take a multiple of horizontal cycles, and vertical states take a multiple of lines. |
| 231 | | - The horizontal states comprise left border, main display, right border and horizontal retrace timing. |
| 232 | | - The vertical states comprise top border, main display, bottom border and vertical retrace timing. |
| 233 | | |
| 234 | | |
| 235 | | - if frame rate is 50Hz, and there are 312 lines, then the line rate is 15600Hz. |
| 236 | | - Each frame takes 0.02 seconds, and each line takes 0.0000064 seconds - approx 64microseconds per line |
| 237 | | |
| 238 | | - the event list is based on cpu time |
| 239 | | |
| 240 | | */ |
| 241 | | |
| 242 | | static const int horizontal_next_state_table[]= |
| 243 | | { |
| 244 | | 1,2,3,0 |
| 245 | | }; |
| 246 | | |
| 247 | | /* number of cycles for each state */ |
| 248 | | static const int horizontal_graphics_state_cycles[]= |
| 249 | | { |
| 250 | | /* left border */ |
| 251 | | (KC85_LEFT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL), |
| 252 | | /* main display */ |
| 253 | | (KC85_SCREEN_WIDTH*KC85_CYCLES_PER_PIXEL), |
| 254 | | /* right border */ |
| 255 | | (KC85_RIGHT_BORDER_SIZE*KC85_CYCLES_PER_PIXEL), |
| 256 | | /* horizontal retrace */ |
| 257 | | (KC85_RETRACE_SIZE*KC85_CYCLES_PER_PIXEL) |
| 258 | | }; |
| 259 | | |
| 260 | | static const int vertical_next_state_table[]= |
| 261 | | { |
| 262 | | 1,2,3,0 |
| 263 | | }; |
| 264 | | |
| 265 | | /* number of lines for each state */ |
| 266 | | static const int vertical_graphics_state_lines[]= |
| 267 | | { |
| 268 | | /* top border */ |
| 269 | | KC85_TOP_BORDER_SIZE*KC85_CYCLES_PER_LINE, |
| 270 | | /* main display */ |
| 271 | | KC85_SCREEN_HEIGHT*KC85_CYCLES_PER_LINE, |
| 272 | | /* bottom display */ |
| 273 | | KC85_BOTTOM_BORDER_SIZE*KC85_CYCLES_PER_LINE, |
| 274 | | /* vertical retrace */ |
| 275 | | KC85_NUM_RETRACE_LINES*KC85_CYCLES_PER_LINE |
| 276 | | }; |
| 277 | | |
| 278 | | struct video_state |
| 279 | | { |
| 280 | | /* current state */ |
| 281 | | int state; |
| 282 | | /* number of cycles remaining in this state */ |
| 283 | | int cycles_remaining_in_state; |
| 284 | | /* number of cycles remaining (starts at total of all states) */ |
| 285 | | int cycles_remaining; |
| 286 | | }; |
| 287 | | |
| 288 | | struct grab_info |
| 289 | | { |
| 290 | | unsigned char *pixel_ram; |
| 291 | | unsigned char *colour_ram; |
| 292 | | }; |
| 293 | | |
| 294 | | struct video_update_state |
| 295 | | { |
| 296 | | /* bitmap to render to */ |
| 297 | | bitmap_ind16 *bitmap; |
| 298 | | /* grab colour and pixel information for 8-pixels referenced by x,y coordinate */ |
| 299 | | void (*pixel_grab_callback)(struct grab_info *,int x,int y, unsigned char *colour_ptr, unsigned char *pixel_ptr); |
| 300 | | /* current coords */ |
| 301 | | int x,y; |
| 302 | | /* render coordinates */ |
| 303 | | int render_x,render_y; |
| 304 | | |
| 305 | | struct video_state horizontal; |
| 306 | | struct video_state vertical; |
| 307 | | struct grab_info grab_data; |
| 308 | | }; |
| 309 | | |
| 310 | | |
| 311 | | /* process visible cycles within a line */ |
| 312 | | /* the cycles will never span over the end of a line */ |
| 313 | | static void kc85_common_process_cycles(kc_state *state, struct video_update_state *video_update, int cycles) |
| 314 | | { |
| 315 | | while (cycles!=0) |
| 316 | | { |
| 317 | | int cycles_to_do; |
| 318 | | |
| 319 | | /* do as many cycles up to end of current state */ |
| 320 | | cycles_to_do = MIN(video_update->horizontal.cycles_remaining_in_state, cycles); |
| 321 | | |
| 322 | | //logerror("process cycles: cycles_to_do %d\n",cycles_to_do); |
| 323 | | |
| 324 | | /* update screen based on current state */ |
| 325 | | switch (video_update->horizontal.state) |
| 326 | | { |
| 327 | | /* border */ |
| 328 | | case 0: |
| 329 | | { |
| 330 | | // video_update->render_x+=(cycles_to_do)*8; |
| 331 | | } |
| 332 | | break; |
| 333 | | |
| 334 | | /* pixels */ |
| 335 | | case 1: |
| 336 | | { |
| 337 | | int i; |
| 338 | | |
| 339 | | for (i=0; i<cycles_to_do; i++) |
| 340 | | { |
| 341 | | unsigned char colour_byte; |
| 342 | | unsigned char gfx_byte; |
| 343 | | |
| 344 | | /* grab colour and pixel information */ |
| 345 | | video_update->pixel_grab_callback(&video_update->grab_data,video_update->x,video_update->y,&colour_byte, &gfx_byte); |
| 346 | | /* draw to screen */ |
| 347 | | kc85_draw_8_pixels(state, *video_update->bitmap, video_update->render_x, video_update->render_y,colour_byte, gfx_byte); |
| 348 | | /* update render coordinate */ |
| 349 | | video_update->render_x+=8; |
| 350 | | video_update->x++; |
| 351 | | |
| 352 | | if (video_update->x>=(320/8)) |
| 353 | | { |
| 354 | | video_update->x = (320/8)-1; |
| 355 | | } |
| 356 | | |
| 357 | | if (video_update->render_x>=320) |
| 358 | | { |
| 359 | | video_update->render_x = 319; |
| 360 | | } |
| 361 | | |
| 362 | | |
| 363 | | } |
| 364 | | } |
| 365 | | break; |
| 366 | | |
| 367 | | /* border */ |
| 368 | | case 2: |
| 369 | | { |
| 370 | | // video_update->render_x+=(cycles_to_do)*8; |
| 371 | | } |
| 372 | | break; |
| 373 | | |
| 374 | | /* invisible/retrace */ |
| 375 | | case 3: |
| 376 | | { |
| 377 | | |
| 378 | | |
| 379 | | } |
| 380 | | break; |
| 381 | | } |
| 382 | | |
| 383 | | video_update->horizontal.cycles_remaining_in_state -=cycles_to_do; |
| 384 | | |
| 385 | | /* is state over? */ |
| 386 | | if (video_update->horizontal.cycles_remaining_in_state<=0) |
| 387 | | { |
| 388 | | /* update state */ |
| 389 | | video_update->horizontal.state = horizontal_next_state_table[video_update->horizontal.state]; |
| 390 | | video_update->horizontal.cycles_remaining_in_state+=horizontal_graphics_state_cycles[video_update->horizontal.state]; |
| 391 | | } |
| 392 | | |
| 393 | | cycles-=cycles_to_do; |
| 394 | | } |
| 395 | | } |
| 396 | | |
| 397 | | /* process a whole visible line */ |
| 398 | | static int kc85_common_vh_process_line(kc_state *state, struct video_update_state *video_update, int cycles) |
| 399 | | { |
| 400 | | int cycles_to_do; |
| 401 | | |
| 402 | | /* do cycles in line */ |
| 403 | | while ((video_update->horizontal.cycles_remaining!=0) && (cycles!=0)) |
| 404 | | { |
| 405 | | /* do as many cycles as will fit onto the line */ |
| 406 | | cycles_to_do = MIN(cycles,video_update->horizontal.cycles_remaining); |
| 407 | | |
| 408 | | //logerror("process line: cycles_to_do: %d\n",cycles_to_do); |
| 409 | | |
| 410 | | /* do the cycles - draw them */ |
| 411 | | kc85_common_process_cycles(state, video_update, cycles_to_do); |
| 412 | | |
| 413 | | video_update->horizontal.cycles_remaining -= cycles_to_do; |
| 414 | | cycles -=cycles_to_do; |
| 415 | | } |
| 416 | | |
| 417 | | /* line over */ |
| 418 | | |
| 419 | | if (video_update->horizontal.cycles_remaining==0) |
| 420 | | { |
| 421 | | /* reset */ |
| 422 | | video_update->horizontal.cycles_remaining+=KC85_CYCLES_PER_LINE; |
| 423 | | /* update x,y fetch pos */ |
| 424 | | video_update->x = 0; |
| 425 | | video_update->y++; |
| 426 | | |
| 427 | | /* update x,y render pos */ |
| 428 | | video_update->render_x = 0; |
| 429 | | video_update->render_y++; |
| 430 | | |
| 431 | | if (video_update->y>=256) |
| 432 | | { |
| 433 | | video_update->y = 255; |
| 434 | | } |
| 435 | | |
| 436 | | if (video_update->render_y>=256) |
| 437 | | { |
| 438 | | video_update->render_y = 255; |
| 439 | | } |
| 440 | | |
| 441 | | |
| 442 | | } |
| 443 | | |
| 444 | | /* cycles remaining */ |
| 445 | | return cycles; |
| 446 | | } |
| 447 | | |
| 448 | | static void kc85_common_vh_process_lines(kc_state *state, struct video_update_state *video_update, int cycles) |
| 449 | | { |
| 450 | | while (cycles!=0) |
| 451 | | { |
| 452 | | int cycles_to_do; |
| 453 | | int cycles_done; |
| 454 | | |
| 455 | | cycles_to_do = MIN(cycles, KC85_CYCLES_PER_LINE); |
| 456 | | cycles_done = cycles_to_do; |
| 457 | | |
| 458 | | //logerror("process lines: cycles_to_do: %d\n",cycles_to_do); |
| 459 | | |
| 460 | | |
| 461 | | switch (video_update->vertical.state) |
| 462 | | { |
| 463 | | /* border */ |
| 464 | | case 0: |
| 465 | | { |
| 466 | | // cycles_done = cycles_to_do; |
| 467 | | } |
| 468 | | break; |
| 469 | | |
| 470 | | /* graphics */ |
| 471 | | case 1: |
| 472 | | { |
| 473 | | int cycles_remaining; |
| 474 | | |
| 475 | | /* update cycles with number of cycles not processed */ |
| 476 | | cycles_remaining = kc85_common_vh_process_line(state, video_update, cycles_to_do); |
| 477 | | |
| 478 | | cycles_done = cycles_to_do - cycles_remaining; |
| 479 | | |
| 480 | | } |
| 481 | | break; |
| 482 | | |
| 483 | | /* border */ |
| 484 | | case 2: |
| 485 | | { |
| 486 | | // cycles_done = cycles_to_do; |
| 487 | | } |
| 488 | | break; |
| 489 | | |
| 490 | | /* not visible */ |
| 491 | | case 3: |
| 492 | | { |
| 493 | | // cycles_done = cycles_to_do; |
| 494 | | } |
| 495 | | break; |
| 496 | | } |
| 497 | | |
| 498 | | |
| 499 | | //logerror("cycles done: %d\n",cycles_done); |
| 500 | | video_update->vertical.cycles_remaining_in_state -=cycles_done; |
| 501 | | |
| 502 | | /* is state over? */ |
| 503 | | if (video_update->vertical.cycles_remaining_in_state<=0) |
| 504 | | { |
| 505 | | /* update state */ |
| 506 | | video_update->vertical.state = vertical_next_state_table[video_update->vertical.state]; |
| 507 | | video_update->vertical.cycles_remaining_in_state+=vertical_graphics_state_lines[video_update->vertical.state]; |
| 508 | | } |
| 509 | | cycles-=cycles_done; |
| 510 | | } |
| 511 | | } |
| 512 | | |
| 513 | | |
| 514 | | |
| 515 | | /* the kc85 screen is 320 pixels wide and 256 pixels tall */ |
| 516 | | /* if we assume a 50Hz display, there are 312 lines for the complete frame, leaving 56 lines not visible */ |
| 517 | | static void kc85_common_process_frame(running_machine &machine, bitmap_ind16 &bitmap, void (*pixel_grab_callback)(struct grab_info *,int x,int y,unsigned char *, unsigned char *),struct grab_info *grab_data) |
| 518 | | { |
| 519 | | kc_state *state = machine.driver_data<kc_state>(); |
| 520 | | int cycles_remaining_in_frame = KC85_CYCLES_PER_FRAME; |
| 521 | | |
| 522 | | // EVENT_LIST_ITEM *pItem; |
| 523 | | // int NumItems; |
| 524 | | |
| 525 | | struct video_update_state video_update; |
| 526 | | // int cycles_offset = 0; |
| 527 | | |
| 528 | | video_update.render_x = 0; |
| 529 | | video_update.render_y = 0; |
| 530 | | video_update.x = 0; |
| 531 | | video_update.y = 0; |
| 532 | | memcpy(&video_update.grab_data, grab_data, sizeof(struct grab_info)); |
| 533 | | video_update.bitmap = &bitmap; |
| 534 | | video_update.pixel_grab_callback = pixel_grab_callback; |
| 535 | | video_update.horizontal.state = 0; |
| 536 | | video_update.horizontal.cycles_remaining_in_state = horizontal_graphics_state_cycles[video_update.horizontal.state]; |
| 537 | | video_update.horizontal.cycles_remaining = KC85_CYCLES_PER_LINE; |
| 538 | | video_update.vertical.state = 0; |
| 539 | | video_update.vertical.cycles_remaining_in_state = vertical_graphics_state_lines[video_update.vertical.state]; |
| 540 | | video_update.vertical.cycles_remaining = KC85_CYCLES_PER_FRAME; |
| 541 | | |
| 542 | | #if 0 |
| 543 | | /* first item in list */ |
| 544 | | pItem = spectrum_EventList_GetFirstItem(machine); |
| 545 | | /* number of items remaining */ |
| 546 | | NumItems = spectrum_EventList_NumEvents(machine); |
| 547 | | |
| 548 | | while (NumItems) |
| 549 | | { |
| 550 | | int delta_cycles; |
| 551 | | |
| 552 | | /* number of cycles until event will trigger */ |
| 553 | | delta_cycles = pItem->Event_Time - cycles_offset; |
| 554 | | |
| 555 | | //logerror("cycles between this event and next: %d\n",delta_cycles); |
| 556 | | kc85_common_vh_process_lines(&video_update, delta_cycles); |
| 557 | | |
| 558 | | /* update number of cycles remaining in frame */ |
| 559 | | cycles_remaining_in_frame -= delta_cycles; |
| 560 | | /* set new blink state */ |
| 561 | | state->m_kc85_blink_state = pItem->Event_Data; |
| 562 | | |
| 563 | | /* set new cycles into frame */ |
| 564 | | cycles_offset = pItem->Event_Time; |
| 565 | | /* next event */ |
| 566 | | pItem++; |
| 567 | | /* update number of events remaining */ |
| 568 | | NumItems--; |
| 569 | | } |
| 570 | | #endif |
| 571 | | |
| 572 | | /* process remainder */ |
| 573 | | kc85_common_vh_process_lines(state, &video_update, cycles_remaining_in_frame); |
| 574 | | //spectrum_EventList_Reset(machine); |
| 575 | | //spectrum_EventList_SetOffsetStartTime ( machine, machine.firstcpu->attotime_to_cycles(machine.primary_screen->scan_period() * machine.primary_screen->vpos()) ); |
| 576 | | } |
| 577 | | |
| 578 | | |
| 579 | | |
| 580 | 141 | /*************************************************************************** |
| 581 | 142 | KC85/4 video hardware |
| 582 | 143 | ***************************************************************************/ |
| 583 | | static void kc85_common_vh_start(running_machine &machine) |
| 584 | | { |
| 585 | | kc_state *state = machine.driver_data<kc_state>(); |
| 586 | | state->m_kc85_blink_state = 0; |
| 587 | | //spectrum_EventList_Initialise(machine, 30000); |
| 588 | | } |
| 589 | 144 | |
| 590 | | |
| 591 | | |
| 592 | 145 | void kc85_4_state::video_start() |
| 593 | 146 | { |
| 594 | | kc85_common_vh_start(machine()); |
| 595 | | |
| 596 | | m_video_ram = auto_alloc_array(machine(), UINT8, |
| 597 | | (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) + |
| 598 | | (KC85_4_SCREEN_PIXEL_RAM_SIZE*2)); |
| 599 | | |
| 147 | m_video_ram = machine().memory().region_alloc("videoram", (KC85_4_SCREEN_COLOUR_RAM_SIZE*2) + (KC85_4_SCREEN_PIXEL_RAM_SIZE*2), 1, ENDIANNESS_LITTLE)->base(); |
| 600 | 148 | m_display_video_ram = m_video_ram; |
| 149 | |
| 150 | m_kc85_blink_state = 0; |
| 601 | 151 | } |
| 602 | 152 | |
| 603 | | void kc85_4_video_ram_select_bank(running_machine &machine, int bank) |
| 153 | void kc85_4_state::video_control_w(int data) |
| 604 | 154 | { |
| 605 | | kc85_4_state *state = machine.driver_data<kc85_4_state>(); |
| 606 | 155 | /* calculate address of video ram to display */ |
| 607 | | unsigned char *video_ram; |
| 156 | if (data & 1) |
| 157 | m_display_video_ram = m_video_ram + (KC85_4_SCREEN_PIXEL_RAM_SIZE + KC85_4_SCREEN_COLOUR_RAM_SIZE); |
| 158 | else |
| 159 | m_display_video_ram = m_video_ram; |
| 608 | 160 | |
| 609 | | video_ram = state->m_video_ram; |
| 610 | | |
| 611 | | if (bank!=0) |
| 612 | | { |
| 613 | | video_ram += |
| 614 | | (KC85_4_SCREEN_PIXEL_RAM_SIZE + |
| 615 | | KC85_4_SCREEN_COLOUR_RAM_SIZE); |
| 616 | | } |
| 617 | | |
| 618 | | state->m_display_video_ram = video_ram; |
| 161 | m_high_resolution = (data & 0x08) ? 0 : 1; |
| 619 | 162 | } |
| 620 | 163 | |
| 621 | | unsigned char *kc85_4_get_video_ram_base(running_machine &machine, int bank, int colour) |
| 622 | | { |
| 623 | | kc85_4_state *state = machine.driver_data<kc85_4_state>(); |
| 624 | | /* base address: screen 0 pixel data */ |
| 625 | | unsigned char *addr = state->m_video_ram; |
| 626 | 164 | |
| 627 | | if (bank!=0) |
| 628 | | { |
| 629 | | /* access screen 1 */ |
| 630 | | addr += KC85_4_SCREEN_PIXEL_RAM_SIZE + |
| 631 | | KC85_4_SCREEN_COLOUR_RAM_SIZE; |
| 632 | | } |
| 633 | | |
| 634 | | if (colour!=0) |
| 635 | | { |
| 636 | | /* access colour information of selected screen */ |
| 637 | | addr += KC85_4_SCREEN_PIXEL_RAM_SIZE; |
| 638 | | } |
| 639 | | |
| 640 | | return addr; |
| 641 | | } |
| 642 | | |
| 643 | | static void kc85_4_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx) |
| 165 | UINT32 kc85_4_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 644 | 166 | { |
| 645 | | int offset; |
| 167 | UINT8 *pixel_ram = m_display_video_ram; |
| 168 | UINT8 *colour_ram = pixel_ram + 0x04000; |
| 646 | 169 | |
| 647 | | offset = (y & 0xff) | ((x & 0x0ff)<<8); |
| 648 | | |
| 649 | | *colour = grab_data->colour_ram[offset]; |
| 650 | | *gfx = grab_data->pixel_ram[offset]; |
| 651 | | |
| 652 | | } |
| 653 | | |
| 654 | | |
| 655 | | /*************************************************************************** |
| 656 | | Draw the game screen in the given bitmap_ind16. |
| 657 | | Do NOT call osd_update_display() from this function, |
| 658 | | it will be called by the main emulation engine. |
| 659 | | ***************************************************************************/ |
| 660 | | SCREEN_UPDATE_IND16( kc85_4 ) |
| 661 | | { |
| 662 | | kc85_4_state *state = screen.machine().driver_data<kc85_4_state>(); |
| 663 | | #if 0 |
| 664 | | unsigned char *pixel_ram = state->m_display_video_ram; |
| 665 | | unsigned char *colour_ram = pixel_ram + 0x04000; |
| 666 | | |
| 667 | | int x,y; |
| 668 | | |
| 669 | | for (y=0; y<KC85_SCREEN_HEIGHT; y++) |
| 170 | for (int y=cliprect.min_y; y<=cliprect.max_y; y++) |
| 670 | 171 | { |
| 671 | | for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++) |
| 172 | for (int x=0; x<(KC85_SCREEN_WIDTH>>3); x++) |
| 672 | 173 | { |
| 673 | | unsigned char colour_byte, gfx_byte; |
| 674 | | int offset; |
| 174 | UINT16 offset = y | (x<<8); |
| 675 | 175 | |
| 676 | | offset = y | (x<<8); |
| 176 | UINT8 colour_byte = colour_ram[offset]; |
| 177 | UINT8 gfx_byte = pixel_ram[offset]; |
| 677 | 178 | |
| 678 | | colour_byte = colour_ram[offset]; |
| 679 | | gfx_byte = pixel_ram[offset]; |
| 680 | | |
| 681 | | kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte); |
| 682 | | |
| 179 | video_draw_8_pixels(bitmap, (x<<3), y, colour_byte, gfx_byte); |
| 683 | 180 | } |
| 684 | 181 | } |
| 685 | | #endif |
| 686 | | struct grab_info grab_data; |
| 687 | 182 | |
| 688 | | grab_data.pixel_ram = state->m_display_video_ram; |
| 689 | | grab_data.colour_ram = state->m_display_video_ram + 0x04000; |
| 690 | | |
| 691 | | kc85_common_process_frame(screen.machine(), bitmap, kc85_4_pixel_grab_callback,&grab_data); |
| 692 | | |
| 693 | 183 | return 0; |
| 694 | 184 | } |
| 695 | 185 | |
| r15431 | r15432 | |
| 699 | 189 | |
| 700 | 190 | void kc_state::video_start() |
| 701 | 191 | { |
| 702 | | kc85_common_vh_start(machine()); |
| 703 | | } |
| 192 | m_video_ram = machine().memory().region_alloc("videoram", 0x4000, 1, ENDIANNESS_LITTLE)->base(); |
| 704 | 193 | |
| 705 | | |
| 706 | | static void kc85_3_pixel_grab_callback(struct grab_info *grab_data,int x,int y, unsigned char *colour, unsigned char *gfx) |
| 707 | | { |
| 708 | | int pixel_offset,colour_offset; |
| 709 | | |
| 710 | | /* this has got to be speeded up!!! */ |
| 711 | | if ((x & 0x020)==0) |
| 712 | | { |
| 713 | | pixel_offset = (x & 0x01f) | (((y>>2) & 0x03)<<5) | |
| 714 | | ((y & 0x03)<<7) | (((y>>4) & 0x0f)<<9); |
| 715 | | |
| 716 | | colour_offset = (x & 0x01f) | (((y>>2) & 0x03f)<<5); |
| 717 | | } |
| 718 | | else |
| 719 | | { |
| 720 | | /* 1 0 1 0 0 V7 V6 V1 V0 V3 V2 V5 V4 H2 H1 H0 */ |
| 721 | | /* 1 0 1 1 0 0 0 V7 V6 V3 V2 V5 V4 H2 H1 H0 */ |
| 722 | | |
| 723 | | pixel_offset = 0x02000+((x & 0x07) | (((y>>4) & 0x03)<<3) | |
| 724 | | (((y>>2) & 0x03)<<5) | ((y & 0x03)<<7) | ((y>>6) & 0x03)<<9); |
| 725 | | |
| 726 | | colour_offset = 0x0800+((x & 0x07) | (((y>>4) & 0x03)<<3) | |
| 727 | | (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7); |
| 728 | | } |
| 729 | | |
| 730 | | *colour = grab_data->colour_ram[colour_offset]; |
| 731 | | *gfx = grab_data->pixel_ram[pixel_offset]; |
| 732 | | |
| 194 | m_kc85_blink_state = 0; |
| 733 | 195 | } |
| 734 | 196 | |
| 735 | | /*************************************************************************** |
| 736 | | Draw the game screen in the given bitmap_ind16. |
| 737 | | Do NOT call osd_update_display() from this function, |
| 738 | | it will be called by the main emulation engine. |
| 739 | | ***************************************************************************/ |
| 740 | | SCREEN_UPDATE_IND16( kc85_3 ) |
| 197 | UINT32 kc_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 741 | 198 | { |
| 742 | | kc_state *state = screen.machine().driver_data<kc_state>(); |
| 743 | | |
| 744 | | #if 0 |
| 745 | 199 | /* colour ram takes up 0x02800 bytes */ |
| 746 | | unsigned char *pixel_ram = machine.device<ram_device>(RAM_TAG)->pointer()+0x08000; |
| 747 | | unsigned char *colour_ram = pixel_ram + 0x02800; |
| 200 | UINT8 *pixel_ram = m_video_ram; |
| 201 | UINT8 *colour_ram = m_video_ram + 0x02800; |
| 748 | 202 | |
| 749 | | int x,y; |
| 750 | | |
| 751 | | for (y=0; y<KC85_SCREEN_HEIGHT; y++) |
| 203 | for (int y=cliprect.min_y; y<=cliprect.max_y; y++) |
| 752 | 204 | { |
| 753 | | for (x=0; x<(KC85_SCREEN_WIDTH>>3); x++) |
| 205 | for (int x=0; x<(KC85_SCREEN_WIDTH>>3); x++) |
| 754 | 206 | { |
| 755 | | unsigned char colour_byte, gfx_byte; |
| 756 | 207 | int pixel_offset,colour_offset; |
| 757 | 208 | |
| 758 | 209 | if ((x & 0x020)==0) |
| r15431 | r15432 | |
| 774 | 225 | (((y>>2) & 0x03)<<5) | ((y>>6) & 0x03)<<7); |
| 775 | 226 | } |
| 776 | 227 | |
| 777 | | colour_byte = colour_ram[colour_offset]; |
| 778 | | gfx_byte = pixel_ram[pixel_offset]; |
| 228 | UINT8 colour_byte = colour_ram[colour_offset]; |
| 229 | UINT8 gfx_byte = pixel_ram[pixel_offset]; |
| 779 | 230 | |
| 780 | | kc85_draw_8_pixels(state, bitmap,(x<<3),y, colour_byte, gfx_byte); |
| 231 | video_draw_8_pixels(bitmap,(x<<3),y, colour_byte, gfx_byte); |
| 781 | 232 | } |
| 782 | 233 | } |
| 783 | | #endif |
| 784 | 234 | |
| 785 | | struct grab_info grab_data; |
| 786 | | |
| 787 | | grab_data.pixel_ram = state->m_ram_base + 0x04000; |
| 788 | | grab_data.colour_ram = state->m_ram_base + 0x04000 + 0x02800; |
| 789 | | |
| 790 | | kc85_common_process_frame(screen.machine(), bitmap, kc85_3_pixel_grab_callback,&grab_data); |
| 791 | | |
| 792 | 235 | return 0; |
| 793 | 236 | } |