src/mess/machine/bbc.c
| r11515 | r11516 | |
| 23 | 23 | #include "machine/ctronics.h" |
| 24 | 24 | #include "imagedev/cassette.h" |
| 25 | 25 | |
| 26 | | /* BBC Memory Size */ |
| 27 | | /* this stores the DIP switch setting for the DFS type being used */ |
| 28 | | /* this stores the DIP switch setting for the SWRAM type being used */ |
| 29 | 26 | |
| 30 | | /* if 0 then we are emulating a BBC B style machine |
| 31 | | if 1 then we are emulating a BBC Master style machine */ |
| 32 | | |
| 33 | | |
| 34 | | /**************************** |
| 35 | | IRQ inputs |
| 36 | | *****************************/ |
| 37 | | |
| 38 | | |
| 39 | | /************************ |
| 40 | | Sideways RAM/ROM code |
| 41 | | *************************/ |
| 42 | | |
| 43 | | //This is the latch that holds the sideways ROM bank to read |
| 44 | | |
| 45 | | //This stores the sideways RAM latch type. |
| 46 | | //Acorn and others use the bbc_rombank latch to select the write bank to be used.(type 0) |
| 47 | | //Solidisc use the BBC's userport to select the write bank to be used (type 1) |
| 48 | | |
| 49 | | |
| 50 | | |
| 51 | 27 | /************************* |
| 52 | 28 | Model A memory handling functions |
| 53 | 29 | *************************/ |
| r11515 | r11516 | |
| 63 | 39 | { |
| 64 | 40 | bbc_state *state = space->machine().driver_data<bbc_state>(); |
| 65 | 41 | space->machine().region("maincpu")->base()[offset]=data; |
| 66 | | |
| 67 | | // this array is set so that the video emulator know which addresses to redraw |
| 68 | | state->m_vidmem[offset]=1; |
| 69 | 42 | } |
| 70 | 43 | |
| 71 | 44 | /************************* |
| r11515 | r11516 | |
| 95 | 68 | if (state->m_RAMSize) |
| 96 | 69 | { |
| 97 | 70 | space->machine().region("maincpu")->base()[offset + 0x4000] = data; |
| 98 | | // this array is set so that the video emulator know which addresses to redraw |
| 99 | | state->m_vidmem[offset + 0x4000] = 1; |
| 100 | 71 | } |
| 101 | 72 | else |
| 102 | 73 | { |
| 103 | 74 | space->machine().region("maincpu")->base()[offset] = data; |
| 104 | | state->m_vidmem[offset] = 1; |
| 105 | 75 | } |
| 106 | 76 | |
| 107 | 77 | } |
| r11515 | r11516 | |
| 197 | 167 | { |
| 198 | 168 | bbc_state *state = space->machine().driver_data<bbc_state>(); |
| 199 | 169 | space->machine().region("maincpu")->base()[offset]=data; |
| 200 | | |
| 201 | | // this array is set so that the video emulator know which addresses to redraw |
| 202 | | state->m_vidmem[offset]=1; |
| 203 | 170 | } |
| 204 | 171 | |
| 205 | 172 | |
| 206 | | |
| 207 | | |
| 208 | | |
| 209 | 173 | /* the next two function handle reads and write to the shadow video ram area |
| 210 | 174 | between 0x3000 and 0x7fff |
| 211 | 175 | |
| r11515 | r11516 | |
| 250 | 214 | { |
| 251 | 215 | // not in shadow ram mode so just write to normal ram |
| 252 | 216 | ram[offset + 0x3000] = data; |
| 253 | | state->m_vidmem[offset + 0x3000] = 1; |
| 254 | 217 | } |
| 255 | 218 | else |
| 256 | 219 | { |
| r11515 | r11516 | |
| 258 | 221 | { |
| 259 | 222 | // if VDUDriver set then write to shadow ram |
| 260 | 223 | ram[offset + 0xb000] = data; |
| 261 | | state->m_vidmem[offset + 0xb000] = 1; |
| 262 | 224 | } |
| 263 | 225 | else |
| 264 | 226 | { |
| 265 | 227 | // else write to normal ram |
| 266 | 228 | ram[offset + 0x3000] = data; |
| 267 | | state->m_vidmem[offset + 0x3000] = 1; |
| 268 | 229 | } |
| 269 | 230 | } |
| 270 | 231 | } |
| r11515 | r11516 | |
| 371 | 332 | |
| 372 | 333 | */ |
| 373 | 334 | |
| 374 | | //static int ACCCON_IRR=0; This is defined at the top in the IRQ code |
| 375 | 335 | |
| 376 | 336 | READ8_HANDLER ( bbcm_ACCCON_read ) |
| 377 | 337 | { |
| r11515 | r11516 | |
| 389 | 349 | logerror("ACCCON write %d %d \n",offset,data); |
| 390 | 350 | |
| 391 | 351 | tempIRR=state->m_ACCCON_IRR; |
| 392 | | state->m_ACCCON_IRR=(data>>7)&1; |
| 393 | 352 | |
| 353 | |
| 354 | state->m_ACCCON_IRR=(data>>7)&1; |
| 394 | 355 | state->m_ACCCON_TST=(data>>6)&1; |
| 395 | 356 | state->m_ACCCON_IFJ=(data>>5)&1; |
| 396 | 357 | state->m_ACCCON_ITU=(data>>4)&1; |
| r11515 | r11516 | |
| 473 | 434 | { |
| 474 | 435 | bbc_state *state = space->machine().driver_data<bbc_state>(); |
| 475 | 436 | space->machine().region("maincpu")->base()[offset] = data; |
| 476 | | state->m_vidmem[offset] = 1; |
| 477 | 437 | } |
| 478 | 438 | |
| 479 | 439 | |
| r11515 | r11516 | |
| 508 | 468 | if (state->m_ACCCON_X) |
| 509 | 469 | { |
| 510 | 470 | ram[offset + 0xb000] = data; |
| 511 | | state->m_vidmem[offset + 0xb000] = 1; |
| 512 | 471 | } |
| 513 | 472 | else |
| 514 | 473 | { |
| 515 | 474 | if (state->m_ACCCON_E && bbcm_vdudriverset(space->machine())) |
| 516 | 475 | { |
| 517 | 476 | ram[offset + 0xb000] = data; |
| 518 | | state->m_vidmem[offset + 0xb000] = 1; |
| 519 | 477 | } |
| 520 | 478 | else |
| 521 | 479 | { |
| 522 | 480 | ram[offset + 0x3000] = data; |
| 523 | | state->m_vidmem[offset + 0x3000] = 1; |
| 524 | 481 | } |
| 525 | 482 | } |
| 526 | 483 | } |
| r11515 | r11516 | |
| 786 | 743 | 6 8K &6000 (or &2000) 24K 0 1 |
| 787 | 744 | B6 - Operates the CAPS lock LED (Pin 17 keyboard connector) |
| 788 | 745 | B7 - Operates the SHIFT lock LED (Pin 16 keyboard connector) |
| 789 | | |
| 790 | | |
| 791 | 746 | ******************************************************************************/ |
| 792 | 747 | |
| 793 | 748 | |
| 794 | 749 | |
| 795 | | |
| 796 | | |
| 797 | | |
| 798 | | |
| 799 | | // this is a counter on the keyboard |
| 800 | | |
| 801 | | |
| 802 | 750 | INTERRUPT_GEN( bbcb_keyscan ) |
| 803 | 751 | { |
| 804 | 752 | bbc_state *state = device->machine().driver_data<bbc_state>(); |
| r11515 | r11516 | |
| 1064 | 1012 | if (state->m_b4_video0 == 0) |
| 1065 | 1013 | { |
| 1066 | 1014 | state->m_b4_video0 = 1; |
| 1067 | | bbc_setscreenstart(device->machine(), state->m_b4_video0, state->m_b5_video1); |
| 1068 | 1015 | } |
| 1069 | 1016 | break; |
| 1070 | 1017 | case 5: |
| 1071 | 1018 | if (state->m_b5_video1 == 0) |
| 1072 | 1019 | { |
| 1073 | 1020 | state->m_b5_video1 = 1; |
| 1074 | | bbc_setscreenstart(device->machine(), state->m_b4_video0, state->m_b5_video1); |
| 1075 | 1021 | } |
| 1076 | 1022 | break; |
| 1077 | 1023 | case 6: |
| r11515 | r11516 | |
| 1151 | 1097 | if (state->m_b4_video0 == 1) |
| 1152 | 1098 | { |
| 1153 | 1099 | state->m_b4_video0 = 0; |
| 1154 | | bbc_setscreenstart(device->machine(), state->m_b4_video0, state->m_b5_video1); |
| 1155 | 1100 | } |
| 1156 | 1101 | break; |
| 1157 | 1102 | case 5: |
| 1158 | 1103 | if (state->m_b5_video1 == 1) |
| 1159 | 1104 | { |
| 1160 | 1105 | state->m_b5_video1 = 0; |
| 1161 | | bbc_setscreenstart(device->machine(), state->m_b4_video0, state->m_b5_video1); |
| 1162 | 1106 | } |
| 1163 | 1107 | break; |
| 1164 | 1108 | case 6: |
| r11515 | r11516 | |
| 1359 | 1303 | BBC 2C199 Serial Interface Cassette |
| 1360 | 1304 | ****************************************/ |
| 1361 | 1305 | |
| 1362 | | //static int longbit=0; |
| 1363 | | //static int shortbit = 0; |
| 1364 | 1306 | |
| 1365 | 1307 | |
| 1366 | | |
| 1367 | 1308 | static void MC6850_Receive_Clock(running_machine &machine, int new_clock) |
| 1368 | 1309 | { |
| 1369 | 1310 | bbc_state *state = machine.driver_data<bbc_state>(); |
| r11515 | r11516 | |
| 2116 | 2057 | { |
| 2117 | 2058 | /* 32K Model B */ |
| 2118 | 2059 | memory_set_bankptr(machine, "bank3", ram + 0x4000); |
| 2119 | | bbc_set_video_memory_lookups(machine, 32); |
| 2060 | state->m_memorySize=32; |
| 2120 | 2061 | } |
| 2121 | 2062 | else |
| 2122 | 2063 | { |
| 2123 | 2064 | /* 16K just repeat the lower 16K*/ |
| 2124 | 2065 | memory_set_bankptr(machine, "bank3", ram); |
| 2125 | | bbc_set_video_memory_lookups(machine, 16); |
| 2066 | state->m_memorySize=16; |
| 2126 | 2067 | } |
| 2127 | 2068 | |
| 2128 | 2069 | memory_set_bankptr(machine, "bank4", machine.region("user1")->base()); /* bank 4 is the paged ROMs from 8000 to bfff */ |
src/mess/includes/bbc.h
| r11515 | r11516 | |
| 23 | 23 | public: |
| 24 | 24 | bbc_state(const machine_config &mconfig, device_type type, const char *tag) |
| 25 | 25 | : driver_device(mconfig, type, tag) { } |
| 26 | int m_RAMSize; // BBC Memory Size |
| 27 | int m_DFSType; // this stores the DIP switch setting for the DFS type being used |
| 28 | int m_SWRAMtype; // this stores the DIP switch setting for the SWRAM type being used |
| 29 | int m_Master; // if 0 then we are emulating a BBC B style machine |
| 30 | // if 1 then we are emulating a BBC Master style machine |
| 26 | 31 | |
| 27 | | unsigned char m_vidmem[0x10000]; |
| 28 | | int m_RAMSize; |
| 29 | | int m_DFSType; |
| 30 | | int m_SWRAMtype; |
| 31 | | int m_Master; |
| 32 | | int m_ACCCON_IRR; |
| 33 | | int m_rombank; |
| 34 | | int m_userport; |
| 35 | | int m_pagedRAM; |
| 36 | | int m_vdusel; |
| 32 | int m_ACCCON_IRR; // IRQ inputs |
| 33 | |
| 34 | int m_rombank; // This is the latch that holds the sideways ROM bank to read |
| 35 | |
| 36 | int m_userport; // This stores the sideways RAM latch type. |
| 37 | // Acorn and others use the bbc_rombank latch to select the write bank to be used.(type 0) |
| 38 | // Solidisc use the BBC's userport to select the write bank to be used (type 1) |
| 39 | |
| 40 | int m_pagedRAM; // BBC B+ memory handling |
| 41 | int m_vdusel; // BBC B+ memory handling |
| 42 | |
| 43 | /* |
| 44 | ACCCON |
| 45 | |
| 46 | b7 IRR 1=Causes an IRQ to the processor |
| 47 | b6 TST 1=Selects &FC00-&FEFF read from OS-ROM |
| 48 | b5 IFJ 1=Internal 1 MHz bus |
| 49 | 0=External 1MHz bus |
| 50 | b4 ITU 1=Internal Tube |
| 51 | 0=External Tube |
| 52 | b3 Y 1=Read/Write HAZEL &C000-&DFFF RAM |
| 53 | 0=Read/Write ROM &C000-&DFFF OS-ROM |
| 54 | b2 X 1=Read/Write LYNNE |
| 55 | 0=Read/WRITE main memory &3000-&8000 |
| 56 | b1 E 1=Causes shadow if VDU code |
| 57 | 0=Main all the time |
| 58 | b0 D 1=Display LYNNE as screen |
| 59 | 0=Display main RAM screen |
| 60 | |
| 61 | ACCCON is a read/write register |
| 62 | */ |
| 63 | |
| 37 | 64 | int m_ACCCON; |
| 38 | 65 | int m_ACCCON_TST; |
| 39 | 66 | int m_ACCCON_IFJ; |
| r11515 | r11516 | |
| 42 | 69 | int m_ACCCON_X; |
| 43 | 70 | int m_ACCCON_E; |
| 44 | 71 | int m_ACCCON_D; |
| 72 | |
| 73 | |
| 74 | /* |
| 75 | The addressable latch |
| 76 | This 8 bit addressable latch is operated from port B lines 0-3. |
| 77 | PB0-PB2 are set to the required address of the output bit to be set. |
| 78 | PB3 is set to the value which should be programmed at that bit. |
| 79 | The function of the 8 output bits from this latch are:- |
| 80 | |
| 81 | B0 - Write Enable to the sound generator IC |
| 82 | B1 - READ select on the speech processor |
| 83 | B2 - WRITE select on the speech processor |
| 84 | B3 - Keyboard write enable |
| 85 | B4,B5 - these two outputs define the number to be added to the |
| 86 | start of screen address in hardware to control hardware scrolling:- |
| 87 | Mode Size Start of screen Number to add B5 B4 |
| 88 | 0,1,2 20K &3000 12K 1 1 |
| 89 | 3 16K &4000 16K 0 0 |
| 90 | 4,5 10K &5800 (or &1800) 22K 1 0 |
| 91 | 6 8K &6000 (or &2000) 24K 0 1 |
| 92 | B6 - Operates the CAPS lock LED (Pin 17 keyboard connector) |
| 93 | B7 - Operates the SHIFT lock LED (Pin 16 keyboard connector) |
| 94 | */ |
| 95 | |
| 45 | 96 | int m_b0_sound; |
| 46 | 97 | int m_b1_speech_read; |
| 47 | 98 | int m_b2_speech_write; |
| r11515 | r11516 | |
| 50 | 101 | int m_b5_video1; |
| 51 | 102 | int m_b6_caps_lock_led; |
| 52 | 103 | int m_b7_shift_lock_led; |
| 53 | | int m_MC146818_WR; |
| 54 | | int m_MC146818_DS; |
| 55 | | int m_MC146818_AS; |
| 56 | | int m_MC146818_CE; |
| 104 | |
| 105 | int m_MC146818_WR; // FE30 bit 1 replaces b1_speech_read |
| 106 | int m_MC146818_DS; // FE30 bit 2 replaces b2_speech_write |
| 107 | int m_MC146818_AS; // 6522 port b bit 7 |
| 108 | int m_MC146818_CE; // 6522 port b bit 6 |
| 109 | |
| 57 | 110 | int m_via_system_porta; |
| 58 | | int m_column; |
| 111 | |
| 112 | int m_column; // this is a counter in the keyboard circuit |
| 113 | |
| 114 | |
| 115 | /*************************************** |
| 116 | BBC 2C199 Serial Interface Cassette |
| 117 | ****************************************/ |
| 118 | |
| 59 | 119 | double m_last_dev_val; |
| 60 | 120 | int m_wav_len; |
| 61 | 121 | int m_len0; |
| r11515 | r11516 | |
| 64 | 124 | int m_len3; |
| 65 | 125 | int m_mc6850_clock; |
| 66 | 126 | emu_timer *m_tape_timer; |
| 67 | | int m_previous_i8271_int_state; |
| 127 | |
| 128 | |
| 129 | /************************************** |
| 130 | i8271 disc control |
| 131 | ***************************************/ |
| 132 | |
| 133 | int m_previous_i8271_int_state; // 8271 interupt status |
| 134 | |
| 135 | |
| 136 | |
| 137 | /************************************** |
| 138 | WD1770 disc control |
| 139 | ***************************************/ |
| 68 | 140 | int m_drive_control; |
| 69 | 141 | int m_wd177x_irq_state; |
| 70 | 142 | int m_wd177x_drq_state; |
| 71 | 143 | int m_previous_wd177x_int_state; |
| 72 | 144 | int m_1770_IntEnabled; |
| 145 | |
| 146 | /************************************** |
| 147 | Opus Challenger Disc control |
| 148 | ***************************************/ |
| 73 | 149 | int m_opusbank; |
| 74 | | int m_video_refresh; |
| 150 | |
| 151 | |
| 152 | |
| 153 | /************************************** |
| 154 | Video Code |
| 155 | ***************************************/ |
| 156 | |
| 157 | int m_memorySize; |
| 158 | |
| 159 | |
| 160 | // this is the real location of the start of the BBC's ram in the emulation |
| 161 | // it can be changed if shadow ram is being used to point at the upper 32K of RAM |
| 162 | |
| 163 | // this is the screen memory location of the next pixels to be drawn |
| 164 | |
| 165 | // this is a more global variable to store the bitmap variable passed in in the bbc_vh_screenrefresh function |
| 166 | |
| 167 | // this is the X and Y screen location in emulation pixels of the next pixels to be drawn |
| 168 | |
| 169 | |
| 75 | 170 | unsigned char *m_BBC_Video_RAM; |
| 76 | | unsigned char *m_vidmem_RAM; |
| 77 | 171 | UINT16 *m_BBC_display; |
| 78 | 172 | UINT16 *m_BBC_display_left; |
| 79 | 173 | UINT16 *m_BBC_display_right; |
| 80 | 174 | bitmap_t *m_BBC_bitmap; |
| 81 | 175 | int m_y_screen_pos; |
| 82 | | unsigned int m_video_ram_lookup0[0x4000]; |
| 83 | | unsigned int m_video_ram_lookup1[0x4000]; |
| 84 | | unsigned int m_video_ram_lookup2[0x4000]; |
| 85 | | unsigned int m_video_ram_lookup3[0x4000]; |
| 86 | | unsigned int *m_video_ram_lookup; |
| 87 | 176 | unsigned char m_pixel_bits[256]; |
| 88 | 177 | int m_BBC_HSync; |
| 89 | 178 | int m_BBC_VSync; |
| r11515 | r11516 | |
| 203 | 292 | VIDEO_START( bbcm ); |
| 204 | 293 | SCREEN_UPDATE( bbc ); |
| 205 | 294 | |
| 295 | static void BBC_draw_hi_res(running_machine &machine); |
| 296 | static void BBC_draw_teletext(running_machine &machine); |
| 297 | |
| 206 | 298 | void bbc_draw_RGB_in(device_t *device, int offset, int data); |
| 207 | 299 | void bbc_set_video_memory_lookups(running_machine &machine, int ramsize); |
| 208 | 300 | void bbc_frameclock(running_machine &machine); |
| 209 | 301 | void bbc_setscreenstart(running_machine &machine, int b4, int b5); |
| 210 | 302 | void bbcbp_setvideoshadow(running_machine &machine, int vdusel); |
| 211 | 303 | |
| 304 | |
| 212 | 305 | WRITE8_HANDLER ( bbc_videoULA_w ); |
| 213 | 306 | |
| 214 | 307 | WRITE8_HANDLER ( bbc_6845_w ); |
src/mess/video/bbc.c
| r11515 | r11516 | |
| 14 | 14 | #include "saa505x.h" |
| 15 | 15 | |
| 16 | 16 | |
| 17 | | static void BBC_draw_hi_res(running_machine &machine); |
| 18 | | static void BBC_draw_teletext(running_machine &machine); |
| 19 | 17 | |
| 20 | | /************************************************************************ |
| 21 | | * video_refresh flag is used in optimising the screen redrawing |
| 22 | | * it is set whenever a 6845 or VideoULA registers are change. |
| 23 | | * This will then cause a full screen refresh. |
| 24 | | * The vidmem array is used to optimise the screen redrawing |
| 25 | | * whenever a memory location is written to the same location is set in the vidmem array |
| 26 | | * if none of the video registers have been changed and a full redraw is not needed |
| 27 | | * the video display emulation will only redraw the video memory locations that have been changed. |
| 28 | | ************************************************************************/ |
| 29 | 18 | |
| 30 | | |
| 31 | | // this is the real location of the start of the BBC's ram in the emulation |
| 32 | | // it can be changed if shadow ram is being used to point at the upper 32K of RAM |
| 33 | | |
| 34 | | // this is the real location of the start of the memory changed look up optimisation array |
| 35 | | // it can be changed if shadow ram is being used to point at the upper 32K of the lookup table |
| 36 | | |
| 37 | | // this is the screen memory location of the next pixels to be drawn |
| 38 | | |
| 39 | | |
| 40 | | // this is a more global variable to store the bitmap variable passed in in the bbc_vh_screenrefresh function |
| 41 | | |
| 42 | | // this is the X and Y screen location in emulation pixels of the next pixels to be drawn |
| 43 | | |
| 44 | 19 | /************************************************************************ |
| 45 | 20 | * video memory lookup arrays. |
| 46 | 21 | * this is a set of quick lookup arrays that stores the logic for the following: |
| r11515 | r11516 | |
| 60 | 35 | * the output of S4 is linked out to a 0v supply by link S25 to just access the 16K memory area. |
| 61 | 36 | ************************************************************************/ |
| 62 | 37 | |
| 63 | | |
| 64 | | |
| 65 | | void bbc_set_video_memory_lookups(running_machine &machine, int ramsize) |
| 38 | unsigned int calculate_video_address(bbc_state *state,int ma) |
| 66 | 39 | { |
| 67 | | bbc_state *state = machine.driver_data<bbc_state>(); |
| 40 | // ma = output from IC2 6845 MA address |
| 68 | 41 | |
| 69 | | int ma; // output from IC2 6845 MA address |
| 70 | 42 | |
| 71 | | int c0,c1; // output from IC32 74LS259 bits 4 and 5 |
| 72 | | int ma12; // bit 12 of 6845 MA address |
| 43 | int c0=state->m_b4_video0; // output from IC32 74LS259 bits 4 and 5 |
| 44 | int c1=state->m_b5_video1; |
| 73 | 45 | |
| 74 | | int b1,b2,b3,b4; // 4 bit input B on IC39 74LS283 (4 bit adder) |
| 75 | | int a,b,s; |
| 46 | /* the 4 bit input port b on IC39 are produced by 4 NAND gates. |
| 47 | these NAND gates take their |
| 48 | inputs from c0 and c1 (from IC32) and ma12 (from the 6845) */ |
| 76 | 49 | |
| 77 | | unsigned int m; |
| 50 | /* get bit m12 from the 6845 */ |
| 51 | int ma12=(ma>>12)&1; |
| 78 | 52 | |
| 79 | | for(c1=0;c1<2;c1++) |
| 80 | | { |
| 81 | | for(c0=0;c0<2;c0++) |
| 82 | | { |
| 83 | | if ((c0==0) && (c1==0)) state->m_video_ram_lookup=state->m_video_ram_lookup0; |
| 84 | | if ((c0==1) && (c1==0)) state->m_video_ram_lookup=state->m_video_ram_lookup1; |
| 85 | | if ((c0==0) && (c1==1)) state->m_video_ram_lookup=state->m_video_ram_lookup2; |
| 86 | | if ((c0==1) && (c1==1)) state->m_video_ram_lookup=state->m_video_ram_lookup3; |
| 53 | // 4 bit input B on IC39 74LS283 (4 bit adder) |
| 54 | /* 3 input NAND part of IC 36 */ |
| 55 | int b1=(~(c1&c0&ma12))&1; |
| 56 | /* 2 input NAND part of IC40 (b3 is calculated before b2 and b4 because b3 feed back into b2 and b4) */ |
| 57 | int b3=(~(c0&ma12))&1; |
| 58 | /* 3 input NAND part of IC 36 */ |
| 59 | int b2=(~(c1&b3&ma12))&1; |
| 60 | /* 2 input NAND part of IC 27 */ |
| 61 | int b4=(~(b3&ma12))&1; |
| 87 | 62 | |
| 88 | | for(ma=0;ma<0x4000;ma++) |
| 89 | | { |
| 63 | /* inputs port a to IC39 are MA8 to MA11 from the 6845 */ |
| 64 | int a=(ma>>8)&0xf; |
| 65 | /* inputs port b to IC39 are taken from the NAND gates b1 to b4 */ |
| 66 | int b=(b1<<0)|(b2<<1)|(b3<<2)|(b4<<3); |
| 90 | 67 | |
| 68 | /* IC39 performs the 4 bit add with the carry input set high */ |
| 69 | int s=(a+b+1)&0xf; |
| 91 | 70 | |
| 92 | | /* the 4 bit input port b on IC39 are produced by 4 NAND gates. |
| 93 | | these NAND gates take their |
| 94 | | inputs from c0 and c1 (from IC32) and ma12 (from the 6845) */ |
| 95 | | |
| 96 | | /* get bit m12 from the 6845 */ |
| 97 | | ma12=(ma>>12)&1; |
| 98 | | |
| 99 | | /* 3 input NAND part of IC 36 */ |
| 100 | | b1=(~(c1&c0&ma12))&1; |
| 101 | | /* 2 input NAND part of IC40 (b3 is calculated before b2 and b4 because b3 feed back into b2 and b4) */ |
| 102 | | b3=(~(c0&ma12))&1; |
| 103 | | /* 3 input NAND part of IC 36 */ |
| 104 | | b2=(~(c1&b3&ma12))&1; |
| 105 | | /* 2 input NAND part of IC 27 */ |
| 106 | | b4=(~(b3&ma12))&1; |
| 107 | | |
| 108 | | /* inputs port a to IC39 are MA8 to MA11 from the 6845 */ |
| 109 | | a=(ma>>8)&0xf; |
| 110 | | /* inputs port b to IC39 are taken from the NAND gates b1 to b4 */ |
| 111 | | b=(b1<<0)|(b2<<1)|(b3<<2)|(b4<<3); |
| 112 | | |
| 113 | | /* IC39 performs the 4 bit add with the carry input set high */ |
| 114 | | s=(a+b+1)&0xf; |
| 115 | | |
| 116 | | /* if MA13 (TTXVDU) is low then IC8 and IC9 are used to calculate |
| 117 | | the memory location required for the hi res video. |
| 118 | | if MA13 is hight then IC10 and IC11 are used to calculate the memory location for the teletext chip |
| 119 | | Note: the RA0,RA1,RA2 inputs to IC8 in high res modes will need to be added else where */ |
| 120 | | if ((ma>>13)&1) |
| 121 | | { |
| 122 | | m=((ma&0x3ff)|0x3c00)|((s&0x8)<<11); |
| 123 | | } else { |
| 124 | | m=((ma&0xff)<<3)|(s<<11); |
| 125 | | } |
| 126 | | if (ramsize==16) |
| 127 | | { |
| 128 | | state->m_video_ram_lookup[ma]=m & 0x3fff; |
| 129 | | } else { |
| 130 | | state->m_video_ram_lookup[ma]=m; |
| 131 | | } |
| 132 | | |
| 133 | | } |
| 134 | | } |
| 71 | /* if MA13 (TTXVDU) is low then IC8 and IC9 are used to calculate |
| 72 | the memory location required for the hi res video. |
| 73 | if MA13 is hight then IC10 and IC11 are used to calculate the memory location for the teletext chip |
| 74 | Note: the RA0,RA1,RA2 inputs to IC8 in high res modes will need to be added else where */ |
| 75 | unsigned int m; |
| 76 | if ((ma>>13)&1) |
| 77 | { |
| 78 | m=((ma&0x3ff)|0x3c00)|((s&0x8)<<11); |
| 79 | } else { |
| 80 | m=((ma&0xff)<<3)|(s<<11); |
| 135 | 81 | } |
| 136 | | } |
| 82 | if (state->m_memorySize==16) |
| 83 | return m & 0x3fff; |
| 137 | 84 | |
| 138 | | |
| 139 | | /* called from 6522 system via */ |
| 140 | | void bbc_setscreenstart(running_machine &machine, int c0, int c1) |
| 141 | | { |
| 142 | | bbc_state *state = machine.driver_data<bbc_state>(); |
| 143 | | if ((c0==0) && (c1==0)) state->m_video_ram_lookup=state->m_video_ram_lookup0; |
| 144 | | if ((c0==1) && (c1==0)) state->m_video_ram_lookup=state->m_video_ram_lookup1; |
| 145 | | if ((c0==0) && (c1==1)) state->m_video_ram_lookup=state->m_video_ram_lookup2; |
| 146 | | if ((c0==1) && (c1==1)) state->m_video_ram_lookup=state->m_video_ram_lookup3; |
| 147 | | |
| 148 | | // emulation refresh optimisation |
| 149 | | state->m_video_refresh=1; |
| 85 | return m; |
| 150 | 86 | } |
| 151 | 87 | |
| 152 | 88 | |
| r11515 | r11516 | |
| 198 | 134 | { |
| 199 | 135 | state->m_Teletext_Latch=0; |
| 200 | 136 | } else { |
| 201 | | state->m_Teletext_Latch=(state->m_BBC_Video_RAM[state->m_video_ram_lookup[meml]]&0x7f)|state->m_Teletext_Latch_Input_D7; |
| 137 | state->m_Teletext_Latch=(state->m_BBC_Video_RAM[calculate_video_address(state,meml)]&0x7f)|state->m_Teletext_Latch_Input_D7; |
| 202 | 138 | } |
| 203 | 139 | |
| 204 | 140 | } |
| r11515 | r11516 | |
| 229 | 165 | |
| 230 | 166 | int tpal,tcol,vpos; |
| 231 | 167 | |
| 232 | | |
| 233 | | // emulation refresh optimisation |
| 234 | | state->m_video_refresh=1; |
| 235 | | |
| 236 | 168 | // Make sure vpos is never <0 2008-10-11 PHS. |
| 237 | 169 | vpos=space->machine().primary_screen->vpos(); |
| 238 | 170 | if(vpos==0) |
| r11515 | r11516 | |
| 290 | 222 | break; |
| 291 | 223 | } |
| 292 | 224 | |
| 293 | | // emulation refresh optimisation |
| 294 | | state->m_video_refresh=1; |
| 295 | 225 | } |
| 296 | 226 | |
| 297 | 227 | |
| r11515 | r11516 | |
| 309 | 239 | state->m_VideoULA_CR_counter-=1; |
| 310 | 240 | if (state->m_VideoULA_CR_counter<=0) { |
| 311 | 241 | state->m_VideoULA_CR=0; |
| 312 | | state->m_video_refresh=state->m_video_refresh&0xfb; |
| 313 | 242 | set_cursor(state); |
| 314 | 243 | } |
| 315 | 244 | } |
| r11515 | r11516 | |
| 350 | 279 | { |
| 351 | 280 | |
| 352 | 281 | // read the memory location for the next screen location. |
| 353 | | // the logic for the memory location address is very complicated so it |
| 354 | | // is stored in a number of look up arrays (and is calculated once at the start of the emulator). |
| 355 | | // this is actually does by the latch IC's not the Video ULA |
| 356 | | meml=state->m_video_ram_lookup[m6845_memory_address_r(0)]|(state->m_BBC_Character_Row&0x7); |
| 357 | 282 | |
| 358 | | if (state->m_vidmem_RAM[meml] || state->m_video_refresh ) |
| 359 | | { |
| 360 | | state->m_vidmem_RAM[meml]=0; |
| 361 | | i=state->m_BBC_Video_RAM[meml]; |
| 283 | meml=calculate_video_address(state,m6845_memory_address_r(0))|(state->m_BBC_Character_Row&0x7); |
| 362 | 284 | |
| 363 | | for(sc1=0;sc1<state->m_pixels_per_byte;sc1++) |
| 364 | | { |
| 365 | | BBC_ula_drawpixel(state, state->m_videoULA_pallet_lookup[state->m_pixel_bits[i]], state->m_emulation_pixels_per_real_pixel); |
| 366 | | i=(i<<1)|1; |
| 367 | | } |
| 368 | | } else { |
| 369 | | state->m_BBC_display += state->m_emulation_pixels_per_byte; |
| 370 | | } |
| 371 | | } else { |
| 372 | | if (state->m_video_refresh) |
| 285 | i=state->m_BBC_Video_RAM[meml]; |
| 286 | |
| 287 | for(sc1=0;sc1<state->m_pixels_per_byte;sc1++) |
| 373 | 288 | { |
| 374 | | // if the display is not enable, just draw a blank area. |
| 375 | | BBC_ula_drawpixel(state, 0, state->m_emulation_pixels_per_byte); |
| 376 | | } else { |
| 377 | | state->m_BBC_display += state->m_emulation_pixels_per_byte; |
| 289 | BBC_ula_drawpixel(state, state->m_videoULA_pallet_lookup[state->m_pixel_bits[i]], state->m_emulation_pixels_per_real_pixel); |
| 290 | i=(i<<1)|1; |
| 378 | 291 | } |
| 292 | |
| 293 | } else { |
| 294 | // if the display is not enable, just draw a blank area. |
| 295 | BBC_ula_drawpixel(state, 0, state->m_emulation_pixels_per_byte); |
| 379 | 296 | } |
| 380 | 297 | } |
| 381 | 298 | |
| r11515 | r11516 | |
| 486 | 403 | if (data&2) { |
| 487 | 404 | state->m_VideoULA_CR_counter=state->m_emulation_cursor_size; |
| 488 | 405 | state->m_VideoULA_CR=1; |
| 489 | | // turn on the video refresh for the cursor area |
| 490 | | state->m_video_refresh=state->m_video_refresh|4; |
| 491 | 406 | // set the pallet on |
| 492 | 407 | if (data&1) set_cursor(state); |
| 493 | 408 | } |
| r11515 | r11516 | |
| 526 | 441 | break; |
| 527 | 442 | } |
| 528 | 443 | |
| 529 | | // emulation refresh optimisation |
| 530 | | state->m_video_refresh=1; |
| 531 | 444 | } |
| 532 | 445 | |
| 533 | 446 | READ8_HANDLER (bbc_6845_r) |
| r11515 | r11516 | |
| 558 | 471 | { |
| 559 | 472 | bbc_state *state = screen->machine().driver_data<bbc_state>(); |
| 560 | 473 | long c; |
| 561 | | int full_refresh; |
| 562 | 474 | |
| 563 | 475 | //logerror ("Box %d by %d \n",cliprect->min_y,cliprect->max_y); |
| 564 | 476 | |
| 565 | 477 | c = 0; // this is used to time out the screen redraw, in the case that the 6845 is in some way out state. |
| 566 | | full_refresh = 1; |
| 567 | 478 | |
| 479 | |
| 568 | 480 | state->m_BBC_bitmap=bitmap; |
| 569 | 481 | |
| 570 | 482 | state->m_BBC_display_left=BITMAP_ADDR16(state->m_BBC_bitmap, 0, 0); |
| 571 | 483 | state->m_BBC_display_right=state->m_BBC_display_left; |
| 572 | 484 | state->m_BBC_display=state->m_BBC_display_left; |
| 573 | 485 | |
| 574 | | // state->m_video_refresh is set if any of the 6845 or Video ULA registers are changed |
| 575 | | // this then forces a full screen redraw |
| 576 | | |
| 577 | | if (full_refresh) |
| 578 | | { |
| 579 | | state->m_video_refresh=state->m_video_refresh|2; |
| 580 | | } |
| 581 | | |
| 582 | 486 | // loop until the end of the Vertical Sync pulse |
| 583 | 487 | // or until a timeout (this catches the 6845 with silly register values that would not give a VSYNC signal) |
| 584 | 488 | while((state->m_BBC_VSync)&&(c<60000)) |
| r11515 | r11516 | |
| 603 | 507 | c++; |
| 604 | 508 | } |
| 605 | 509 | |
| 606 | | // redrawn the screen so reset state->m_video_refresh |
| 607 | | state->m_video_refresh=0; |
| 608 | | |
| 609 | 510 | return 0; |
| 610 | 511 | } |
| 611 | 512 | |
| r11515 | r11516 | |
| 622 | 523 | if (vdusel) |
| 623 | 524 | { |
| 624 | 525 | state->m_BBC_Video_RAM= machine.region("maincpu")->base()+0x8000; |
| 625 | | state->m_vidmem_RAM=(state->m_vidmem)+0x8000; |
| 626 | 526 | } else { |
| 627 | 527 | state->m_BBC_Video_RAM= machine.region("maincpu")->base(); |
| 628 | | state->m_vidmem_RAM=state->m_vidmem; |
| 629 | 528 | } |
| 630 | 529 | } |
| 631 | 530 | |
| r11515 | r11516 | |
| 634 | 533 | * Initialize the BBC video emulation |
| 635 | 534 | ************************************************************************/ |
| 636 | 535 | |
| 637 | | static void common_init(running_machine &machine) |
| 536 | static void common_init(running_machine &machine, int memorySize) |
| 638 | 537 | { |
| 639 | 538 | bbc_state *state = machine.driver_data<bbc_state>(); |
| 640 | 539 | state->m_emulation_cursor_size = 1; |
| r11515 | r11516 | |
| 650 | 549 | state->m_saa505x = machine.device("saa505x"); |
| 651 | 550 | |
| 652 | 551 | state->m_BBC_Video_RAM = machine.region("maincpu")->base(); |
| 653 | | state->m_vidmem_RAM = state->m_vidmem; |
| 654 | 552 | state->m_draw_function = *BBC_draw_hi_res; |
| 553 | state->m_memorySize=memorySize; |
| 554 | |
| 655 | 555 | } |
| 656 | 556 | |
| 657 | 557 | VIDEO_START( bbca ) |
| 658 | 558 | { |
| 659 | | common_init(machine); |
| 660 | | bbc_set_video_memory_lookups(machine, 16); |
| 559 | common_init(machine,16); |
| 661 | 560 | } |
| 662 | 561 | |
| 663 | 562 | VIDEO_START( bbcb ) |
| 664 | 563 | { |
| 665 | | common_init(machine); |
| 564 | common_init(machine,32); |
| 666 | 565 | } |
| 667 | 566 | |
| 668 | 567 | VIDEO_START( bbcbp ) |
| 669 | 568 | { |
| 670 | | common_init(machine); |
| 671 | | bbc_set_video_memory_lookups(machine, 32); |
| 569 | common_init(machine,32); |
| 672 | 570 | } |
| 673 | 571 | |
| 674 | 572 | VIDEO_START( bbcm ) |
| 675 | 573 | { |
| 676 | | common_init(machine); |
| 677 | | bbc_set_video_memory_lookups(machine, 32); |
| 574 | common_init(machine,32); |
| 678 | 575 | } |