src/mess/video/pc_mda.c
| r2058 | r2059 | |
| 5 | 5 | ***************************************************************************/ |
| 6 | 6 | |
| 7 | 7 | #include "driver.h" |
| 8 | | #include "deprecat.h" |
| 9 | 8 | #include "pc_mda.h" |
| 10 | | #include "pc_cga.h" //for the cga palette hack |
| 11 | | #include "includes/crtc6845.h" |
| 9 | #include "pc_video.h" |
| 10 | #include "video/mc6845.h" |
| 12 | 11 | |
| 12 | #define VERBOSE_MDA 0 /* MDA (Monochrome Display Adapter) */ |
| 13 | 13 | |
| 14 | | #define VERBOSE_MDA 0 /* MDA (Monochrome Display Adapter) */ |
| 15 | | |
| 16 | 14 | #define MDA_LOG(N,M,A) \ |
| 17 | 15 | if(VERBOSE_MDA>=N){ if( M )logerror("%11.6f: %-24s",attotime_to_double(timer_get_time()),(char*)M ); logerror A; } |
| 18 | 16 | |
| r2058 | r2059 | |
| 23 | 21 | { 0x00,0xff,0x00 } |
| 24 | 22 | }; |
| 25 | 23 | |
| 26 | | const gfx_layout pc_mda_charlayout = |
| 27 | | { |
| 28 | | 9,32, /* 9 x 32 characters (9 x 15 is the default, but..) */ |
| 29 | | 256, /* 256 characters */ |
| 30 | | 1, /* 1 bits per pixel */ |
| 31 | | { 0 }, /* no bitplanes; 1 bit per pixel */ |
| 32 | | /* x offsets */ |
| 33 | | { 0,1,2,3,4,5,6,7,7 }, /* pixel 7 repeated only for char code 176 to 223 */ |
| 34 | | /* y offsets */ |
| 35 | | { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, |
| 36 | | 16384+0*8, 16384+1*8, 16384+2*8, 16384+3*8, |
| 37 | | 16384+4*8, 16384+5*8, 16384+6*8, 16384+7*8, |
| 38 | | 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8, |
| 39 | | 16384+0*8, 16384+1*8, 16384+2*8, 16384+3*8, |
| 40 | | 16384+4*8, 16384+5*8, 16384+6*8, 16384+7*8 }, |
| 41 | | 8*8 /* every char takes 8 bytes (upper half) */ |
| 42 | | }; |
| 24 | static struct { |
| 25 | UINT8 status; |
| 43 | 26 | |
| 44 | | GFXDECODE_START( pc_mda ) |
| 45 | | GFXDECODE_ENTRY( REGION_GFX1, 0x0000, pc_mda_charlayout, 0, 256 ) |
| 46 | | GFXDECODE_END |
| 27 | int pc_framecnt; |
| 47 | 28 | |
| 48 | | /* to be done: |
| 49 | | only 2 digital color lines to mda/hercules monitor |
| 50 | | (maximal 4 colors) |
| 51 | | PC200 uses different attributes from IBM. |
| 52 | | */ |
| 53 | | const unsigned short mda_colortable[] = |
| 54 | | { |
| 55 | | 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 56 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 57 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 58 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 59 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 60 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 61 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 62 | | 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 63 | | /* nb: This---------------------------------------------^ should refer to a "dim" colour which |
| 64 | | * we don't do yet */ |
| 29 | UINT8 mode_control, configuration_switch; //hercules |
| 65 | 30 | |
| 66 | | /* flashing is done by dirtying the videoram buffer positions with attr bit #7 set |
| 67 | | * These attributes are used for the flashing characters when they're visible. */ |
| 68 | | 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 0, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 69 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 70 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 71 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 72 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 73 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 74 | | 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 75 | | 2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, 0,10, |
| 31 | gfx_element *gfx_char[4]; |
| 76 | 32 | |
| 77 | | /* the two colors for HGC graphics */ |
| 78 | | 0, 10 |
| 79 | | }; |
| 33 | mc6845_update_row_func update_row; |
| 34 | UINT8 *chr_gen; |
| 35 | UINT8 vsync; |
| 36 | UINT8 hsync; |
| 37 | } mda; |
| 80 | 38 | |
| 81 | 39 | /* Initialise the mda palette */ |
| 82 | 40 | PALETTE_INIT( pc_mda ) |
| 83 | 41 | { |
| 84 | 42 | int i; |
| 85 | | for(i = 0; i < (sizeof(cga_palette) / 3); i++) |
| 86 | | palette_set_color_rgb(machine, i, cga_palette[i][0], cga_palette[i][1], cga_palette[i][2]); |
| 43 | for(i = 0; i < (sizeof(mda_palette) / 3); i++) |
| 44 | palette_set_color_rgb(machine, i, mda_palette[i][0], mda_palette[i][1], mda_palette[i][2]); |
| 87 | 45 | } |
| 88 | 46 | |
| 89 | | static struct |
| 90 | | { |
| 91 | | UINT8 status; |
| 47 | static VIDEO_START( pc_mda ); |
| 48 | static VIDEO_UPDATE( mc6845_mda ); |
| 49 | static READ8_HANDLER( pc_MDA_r ); |
| 50 | static WRITE8_HANDLER( pc_MDA_w ); |
| 51 | static MC6845_UPDATE_ROW( mda_update_row ); |
| 52 | static MC6845_ON_HSYNC_CHANGED( mda_hsync_changed ); |
| 53 | static MC6845_ON_VSYNC_CHANGED( mda_vsync_changed ); |
| 92 | 54 | |
| 93 | | int pc_blink; |
| 94 | | int pc_framecnt; |
| 55 | static const mc6845_interface mc6845_mda_intf = { |
| 56 | MDA_SCREEN_NAME, /* screen number */ |
| 57 | 16257000/9 /*?*/, /* clock */ |
| 58 | 9, /* number of pixels per video memory address */ |
| 59 | NULL, /* begin_update */ |
| 60 | mda_update_row, /* update_row */ |
| 61 | NULL, /* end_update */ |
| 62 | NULL, /* on_de_changed */ |
| 63 | mda_hsync_changed, /* on_hsync_changed */ |
| 64 | mda_vsync_changed /* on_vsync_changed */ |
| 65 | }; |
| 95 | 66 | |
| 96 | | UINT8 mode_control, configuration_switch; //hercules |
| 67 | MACHINE_DRIVER_START( pcvideo_mda ) |
| 68 | MDRV_SCREEN_ADD( MDA_SCREEN_NAME, RASTER) |
| 69 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 70 | MDRV_SCREEN_RAW_PARAMS(16257000, 882, 0, 720, 370, 0, 350 ) |
| 71 | MDRV_PALETTE_LENGTH( sizeof(mda_palette) / 3 ) |
| 97 | 72 | |
| 98 | | gfx_element *gfx_char[4]; |
| 99 | | } mda; |
| 73 | MDRV_PALETTE_INIT(pc_mda) |
| 100 | 74 | |
| 75 | MDRV_DEVICE_ADD( MDA_MC6845_NAME, MC6845) |
| 76 | MDRV_DEVICE_CONFIG( mc6845_mda_intf ) |
| 77 | |
| 78 | MDRV_VIDEO_START( pc_mda ) |
| 79 | MDRV_VIDEO_UPDATE( mc6845_mda) |
| 80 | MACHINE_DRIVER_END |
| 81 | |
| 82 | |
| 101 | 83 | /*************************************************************************** |
| 102 | 84 | |
| 103 | 85 | Monochrome Display Adapter (MDA) section |
| 104 | 86 | |
| 105 | 87 | ***************************************************************************/ |
| 106 | 88 | |
| 107 | | /*************************************************************************** |
| 108 | | Mark all text positions with attribute bit 7 set dirty |
| 109 | | ***************************************************************************/ |
| 110 | | static void pc_mda_blink_textcolors(int on) |
| 89 | VIDEO_START( pc_mda ) |
| 111 | 90 | { |
| 112 | | int offs, size; |
| 91 | int buswidth; |
| 113 | 92 | |
| 114 | | if (mda.pc_blink == on) return; |
| 93 | buswidth = cputype_databus_width(machine->config->cpu[0].type, ADDRESS_SPACE_PROGRAM); |
| 94 | switch(buswidth) |
| 95 | { |
| 96 | case 8: |
| 97 | memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xb0fff, 0, 0x07000, SMH_BANK11 ); |
| 98 | memory_install_write8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xb0fff, 0, 0x07000, pc_video_videoram_w ); |
| 99 | memory_install_read8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_MDA_r ); |
| 100 | memory_install_write8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_MDA_w ); |
| 101 | break; |
| 115 | 102 | |
| 116 | | mda.pc_blink = on; |
| 117 | | offs = (mscrtc6845_get_start(mscrtc6845)*2)% videoram_size; |
| 118 | | size = mscrtc6845_get_char_lines(mscrtc6845)*mscrtc6845_get_char_columns(mscrtc6845); |
| 119 | | } |
| 103 | default: |
| 104 | fatalerror("MDA: Bus width %d not supported\n", buswidth); |
| 105 | break; |
| 106 | } |
| 120 | 107 | |
| 121 | | extern void pc_mda_timer(void) |
| 122 | | { |
| 123 | | if( ((++mda.pc_framecnt & 63) == 63) ) { |
| 124 | | pc_mda_blink_textcolors(mda.pc_framecnt&64); |
| 125 | | } |
| 108 | memset( &mda, 0, sizeof(mda)); |
| 109 | mda.update_row = NULL; |
| 110 | mda.chr_gen = memory_region( REGION_GFX1 ); |
| 111 | |
| 112 | videoram_size = 0x1000; /* This is actually 0x1000 in reality */ |
| 113 | videoram = auto_malloc(videoram_size); |
| 114 | memory_set_bankptr(11, videoram); |
| 126 | 115 | } |
| 127 | 116 | |
| 128 | | void pc_mda_cursor(struct mscrtc6845_cursor *cursor) |
| 129 | | { |
| 117 | |
| 118 | static VIDEO_UPDATE( mc6845_mda ) { |
| 119 | device_config *devconf = (device_config *) device_list_find_by_tag(screen->machine->config->devicelist, MC6845, MDA_MC6845_NAME); |
| 120 | mc6845_update( devconf, bitmap, cliprect ); |
| 121 | return 0; |
| 130 | 122 | } |
| 131 | 123 | |
| 132 | | static const struct mscrtc6845_config config= { 14318180 /*?*/, pc_mda_cursor }; |
| 133 | 124 | |
| 125 | /*************************************************************************** |
| 126 | Draw text mode with 80x25 characters (default) and intense background. |
| 127 | The character cell size is 9x15. Column 9 is column 8 repeated for |
| 128 | character codes 176 to 223. |
| 129 | ***************************************************************************/ |
| 134 | 130 | |
| 135 | | /* This code seems to go through hoops to accomodate differing GfxElement |
| 136 | | * layouts. What ugly crap */ |
| 137 | | static void pc_mda_init_video_internal(int gfx_char, int gfx_char_mask) |
| 138 | | { |
| 139 | | int i, y; |
| 131 | static MC6845_UPDATE_ROW( mda_text_inten_update_row ) { |
| 132 | UINT16 *p = BITMAP_ADDR16( bitmap, y, 0 ); |
| 133 | UINT16 chr_base = ( ra & 0x08 ) ? 0x800 | ( ra & 0x07 ) : ra; |
| 134 | int i; |
| 140 | 135 | |
| 141 | | /* Support up to 4 fonts for PC200 */ |
| 142 | | for (i = 0; i < 4; i++) |
| 143 | | { |
| 144 | | mda.gfx_char[i] = Machine->gfx[gfx_char + (i & gfx_char_mask)]; |
| 145 | | } |
| 136 | if ( y == 0 ) logerror("mda_text_inten_update_row\n"); |
| 137 | for ( i = 0; i < x_count; i++ ) { |
| 138 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x0FFF; |
| 139 | UINT8 chr = videoram[ offset ]; |
| 140 | UINT8 attr = videoram[ offset + 1 ]; |
| 141 | UINT8 data = mda.chr_gen[ chr_base + chr * 8 ]; |
| 142 | UINT8 fg = ( attr & 0x08 ) ? 3 : 2; |
| 143 | UINT8 bg = 0; |
| 146 | 144 | |
| 147 | | /* remove pixel column 9 for character codes 0 - 191 and 224 - 255 */ |
| 148 | | for (i = 0; i < 256; i++) |
| 149 | | { |
| 150 | | if (i < 191 || i > 223) |
| 151 | | { |
| 152 | | for (y = 0; y < Machine->gfx[gfx_char]->height; y++) |
| 153 | | Machine->gfx[gfx_char]->gfxdata[(i * Machine->gfx[gfx_char]->height + y) * Machine->gfx[gfx_char]->width + 8] = 0; |
| 145 | if ( ( attr & ~0x88 ) == 0 ) { |
| 146 | data = 0x00; |
| 154 | 147 | } |
| 148 | |
| 149 | switch( attr ) { |
| 150 | case 0x70: |
| 151 | bg = 2; |
| 152 | fg = 0; |
| 153 | break; |
| 154 | case 0x78: |
| 155 | bg = 2; |
| 156 | fg = 1; |
| 157 | break; |
| 158 | case 0xF0: |
| 159 | bg = 3; |
| 160 | fg = 0; |
| 161 | break; |
| 162 | case 0xF8: |
| 163 | bg = 3; |
| 164 | fg = 1; |
| 165 | break; |
| 166 | } |
| 167 | |
| 168 | if ( i == cursor_x || ( attr & 0x07 ) == 0x01 ) { |
| 169 | data = 0xFF; |
| 170 | } |
| 171 | |
| 172 | *p = ( data & 0x80 ) ? fg : bg; p++; |
| 173 | *p = ( data & 0x40 ) ? fg : bg; p++; |
| 174 | *p = ( data & 0x20 ) ? fg : bg; p++; |
| 175 | *p = ( data & 0x10 ) ? fg : bg; p++; |
| 176 | *p = ( data & 0x08 ) ? fg : bg; p++; |
| 177 | *p = ( data & 0x04 ) ? fg : bg; p++; |
| 178 | *p = ( data & 0x02 ) ? fg : bg; p++; |
| 179 | *p = ( data & 0x01 ) ? fg : bg; p++; |
| 180 | if ( ( chr & 0xE0 ) == 0xC0 ) { |
| 181 | *p = ( data & 0x01 ) ? fg : bg; p++; |
| 182 | } else { |
| 183 | *p = bg; p++; |
| 184 | } |
| 155 | 185 | } |
| 156 | 186 | } |
| 157 | 187 | |
| 158 | | void pc_mda_init_video(void) |
| 159 | | { |
| 160 | | pc_mda_init_video_internal(0, 0); |
| 161 | | } |
| 162 | 188 | |
| 163 | | void pc_mda_europc_init(void) |
| 164 | | { |
| 165 | | pc_mda_init_video_internal(4, 3); |
| 166 | | } |
| 189 | /*************************************************************************** |
| 190 | Draw text mode with 80x25 characters (default) and blinking characters. |
| 191 | The character cell size is 9x15. Column 9 is column 8 repeated for |
| 192 | character codes 176 to 223. |
| 193 | ***************************************************************************/ |
| 167 | 194 | |
| 168 | | VIDEO_START( pc_mda ) |
| 169 | | { |
| 170 | | int buswidth; |
| 195 | static MC6845_UPDATE_ROW( mda_text_blink_update_row ) { |
| 196 | UINT16 *p = BITMAP_ADDR16( bitmap, y, 0 ); |
| 197 | UINT16 chr_base = ( ra & 0x08 ) ? 0x800 | ( ra & 0x07 ) : ra; |
| 198 | int i; |
| 171 | 199 | |
| 172 | | buswidth = cputype_databus_width(machine->config->cpu[0].type, ADDRESS_SPACE_PROGRAM); |
| 173 | | switch(buswidth) |
| 174 | | { |
| 175 | | case 8: |
| 176 | | memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xbffff, 0, 0, SMH_BANK11 ); |
| 177 | | memory_install_write8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xbffff, 0, 0, pc_video_videoram_w ); |
| 178 | | memory_install_read8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_MDA_r ); |
| 179 | | memory_install_write8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_MDA_w ); |
| 200 | if ( y == 0 ) logerror("mda_text_blink_update_row\n"); |
| 201 | for ( i = 0; i < x_count; i++ ) { |
| 202 | UINT16 offset = ( ( ma + i ) << 1 ) & 0x0FFF; |
| 203 | UINT8 chr = videoram[ offset ]; |
| 204 | UINT8 attr = videoram[ offset + 1 ]; |
| 205 | UINT8 data = mda.chr_gen[ chr_base + chr * 8 ]; |
| 206 | UINT8 fg = ( attr & 0x08 ) ? 3 : 2; |
| 207 | UINT8 bg = 0; |
| 208 | |
| 209 | if ( ( attr & ~0x88 ) == 0 ) { |
| 210 | data = 0x00; |
| 211 | } |
| 212 | |
| 213 | switch( attr ) { |
| 214 | case 0x70: |
| 215 | case 0xF0: |
| 216 | bg = 2; |
| 217 | fg = 0; |
| 180 | 218 | break; |
| 219 | case 0x78: |
| 220 | case 0xF8: |
| 221 | bg = 2; |
| 222 | fg = 1; |
| 223 | break; |
| 224 | } |
| 181 | 225 | |
| 182 | | default: |
| 183 | | fatalerror("MDA: Bus width %d not supported\n", buswidth); |
| 184 | | break; |
| 226 | if ( i == cursor_x ) { |
| 227 | data = 0xFF; |
| 228 | } else { |
| 229 | if ( ( attr & 0x07 ) == 0x01 ) { |
| 230 | data = 0xFF; |
| 231 | } |
| 232 | if ( ( attr & 0x80 ) && ( mda.pc_framecnt & 0x40 ) ) { |
| 233 | data = 0x00; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | *p = ( data & 0x80 ) ? fg : bg; p++; |
| 238 | *p = ( data & 0x40 ) ? fg : bg; p++; |
| 239 | *p = ( data & 0x20 ) ? fg : bg; p++; |
| 240 | *p = ( data & 0x10 ) ? fg : bg; p++; |
| 241 | *p = ( data & 0x08 ) ? fg : bg; p++; |
| 242 | *p = ( data & 0x04 ) ? fg : bg; p++; |
| 243 | *p = ( data & 0x02 ) ? fg : bg; p++; |
| 244 | *p = ( data & 0x01 ) ? fg : bg; p++; |
| 245 | if ( ( chr & 0xE0 ) == 0xC0 ) { |
| 246 | *p = ( data & 0x01 ) ? fg : bg; p++; |
| 247 | } else { |
| 248 | *p = bg; p++; |
| 249 | } |
| 185 | 250 | } |
| 251 | } |
| 186 | 252 | |
| 187 | 253 | |
| 188 | | videoram_size = 0x10000; |
| 189 | | videoram = auto_malloc(videoram_size); |
| 190 | | memory_set_bankptr(11, videoram); |
| 254 | static MC6845_UPDATE_ROW( mda_update_row ) { |
| 255 | if ( mda.update_row ) { |
| 256 | mda.update_row( device, bitmap, cliprect, ma, ra, y, x_count, cursor_x, param ); |
| 257 | } |
| 258 | } |
| 191 | 259 | |
| 192 | | pc_mda_init_video(); |
| 193 | | pc_video_start(&config, pc_mda_choosevideomode, videoram_size); |
| 260 | |
| 261 | static MC6845_ON_HSYNC_CHANGED( mda_hsync_changed ) { |
| 262 | mda.hsync = hsync ? 1 : 0; |
| 194 | 263 | } |
| 195 | 264 | |
| 265 | |
| 266 | static MC6845_ON_VSYNC_CHANGED( mda_vsync_changed ) { |
| 267 | mda.vsync = vsync ? 0x80 : 0; |
| 268 | if ( vsync ) { |
| 269 | mda.pc_framecnt++; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | |
| 196 | 274 | /* |
| 197 | 275 | * rW MDA mode control register (see #P138) |
| 198 | 276 | */ |
| 199 | | static void hercules_mode_control_w(int data) |
| 277 | static void mda_mode_control_w(int data) |
| 200 | 278 | { |
| 201 | 279 | MDA_LOG(1,"MDA_mode_control_w",("$%02x: colums %d, gfx %d, enable %d, blink %d\n", |
| 202 | 280 | data, (data&1)?80:40, (data>>1)&1, (data>>3)&1, (data>>5)&1)); |
| 203 | 281 | mda.mode_control = data; |
| 282 | |
| 283 | switch( mda.mode_control & 0x2a ) { |
| 284 | case 0x08: |
| 285 | mda.update_row = mda_text_inten_update_row; |
| 286 | break; |
| 287 | case 0x28: |
| 288 | mda.update_row = mda_text_blink_update_row; |
| 289 | break; |
| 290 | default: |
| 291 | mda.update_row = NULL; |
| 292 | } |
| 204 | 293 | } |
| 205 | 294 | |
| 295 | |
| 206 | 296 | /* R- CRT status register (see #P139) |
| 207 | 297 | * (EGA/VGA) input status 1 register |
| 208 | 298 | * 7 HGC vertical sync in progress |
| r2058 | r2059 | |
| 221 | 311 | return data; |
| 222 | 312 | } |
| 223 | 313 | |
| 224 | | static void hercules_config_w(int data) |
| 225 | | { |
| 226 | | MDA_LOG(1,"HGC_config_w",("$%02x\n", data)); |
| 227 | | mda.configuration_switch = data; |
| 228 | | } |
| 229 | 314 | |
| 230 | 315 | /************************************************************************* |
| 231 | 316 | * |
| r2058 | r2059 | |
| 235 | 320 | *************************************************************************/ |
| 236 | 321 | WRITE8_HANDLER ( pc_MDA_w ) |
| 237 | 322 | { |
| 323 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, MDA_MC6845_NAME); |
| 238 | 324 | switch( offset ) |
| 239 | 325 | { |
| 240 | 326 | case 0: case 2: case 4: case 6: |
| 241 | | mscrtc6845_port_w(mscrtc6845, 0, data); |
| 327 | mc6845_address_w( devconf, offset, data ); |
| 242 | 328 | break; |
| 243 | 329 | case 1: case 3: case 5: case 7: |
| 244 | | mscrtc6845_port_w(mscrtc6845, 1, data); |
| 330 | mc6845_register_w( devconf, offset, data ); |
| 245 | 331 | break; |
| 246 | 332 | case 8: |
| 247 | | hercules_mode_control_w(data); |
| 333 | mda_mode_control_w(data); |
| 248 | 334 | break; |
| 249 | | case 15: |
| 250 | | hercules_config_w(data); |
| 251 | | break; |
| 252 | 335 | } |
| 253 | 336 | } |
| 254 | 337 | |
| 255 | 338 | READ8_HANDLER ( pc_MDA_r ) |
| 256 | 339 | { |
| 340 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, MDA_MC6845_NAME); |
| 257 | 341 | int data = 0xff; |
| 258 | 342 | switch( offset ) |
| 259 | 343 | { |
| 260 | 344 | case 0: case 2: case 4: case 6: |
| 261 | | data = mscrtc6845_port_r(mscrtc6845,0); |
| 345 | /* return last written mc6845 address value here? */ |
| 262 | 346 | break; |
| 263 | 347 | case 1: case 3: case 5: case 7: |
| 264 | | data = mscrtc6845_port_r(mscrtc6845,1); |
| 348 | data = mc6845_register_r( devconf, offset ); |
| 265 | 349 | break; |
| 266 | 350 | case 10: |
| 267 | 351 | data = pc_mda_status_r(); |
| r2058 | r2059 | |
| 271 | 355 | return data; |
| 272 | 356 | } |
| 273 | 357 | |
| 358 | |
| 359 | |
| 274 | 360 | /*************************************************************************** |
| 275 | | Draw text mode with 80x25 characters (default) and intense background. |
| 276 | | The character cell size is 9x15. Column 9 is column 8 repeated for |
| 277 | | character codes 176 to 223. |
| 361 | |
| 362 | Hercules Display Adapter section (re-uses parts from the MDA section) |
| 363 | |
| 278 | 364 | ***************************************************************************/ |
| 279 | | static void mda_text_inten(bitmap_t *bitmap, struct mscrtc6845 *crtc) |
| 280 | | { |
| 281 | | int sx, sy; |
| 282 | | int offs = mscrtc6845_get_start(crtc)*2; |
| 283 | | int lines = mscrtc6845_get_char_lines(crtc); |
| 284 | | int height = mscrtc6845_get_char_height(crtc); |
| 285 | | int columns = mscrtc6845_get_char_columns(crtc); |
| 286 | | int char_width; |
| 287 | | rectangle r; |
| 288 | | struct mscrtc6845_cursor cursor; |
| 289 | | UINT8 attr; |
| 290 | | const device_config *screen = video_screen_first(Machine->config); |
| 291 | | int screen_width = video_screen_get_width(screen); |
| 292 | 365 | |
| 293 | | char_width = screen_width / 80; |
| 366 | static VIDEO_START( pc_hercules ); |
| 367 | static VIDEO_UPDATE( mc6845_hercules ); |
| 368 | static READ8_HANDLER( pc_hercules_r ); |
| 369 | static WRITE8_HANDLER( pc_hercules_w ); |
| 294 | 370 | |
| 295 | | mscrtc6845_time(crtc); |
| 296 | | mscrtc6845_get_cursor(crtc, &cursor); |
| 371 | /* |
| 372 | When the Hercules changes to graphics mode, the number of pixels per access and |
| 373 | clock divider should be changed. The currect mc6845 implementation does not |
| 374 | allow this. |
| 297 | 375 | |
| 298 | | for (sy=0, r.min_y=0, r.max_y=height-1; sy<lines; sy++, r.min_y+=height,r.max_y+=height) |
| 299 | | { |
| 300 | | for (sx=0, r.min_x=0, r.max_x = char_width-1; sx<columns; |
| 301 | | sx++, offs=(offs+2)&0x3fff, r.min_x += char_width, r.max_x += char_width) |
| 302 | | { |
| 303 | | attr = videoram[offs+1]; |
| 304 | | drawgfx(bitmap, mda.gfx_char[CGA_FONT], videoram[offs], attr, |
| 305 | | 0,0,r.min_x,r.min_y,&r,TRANSPARENCY_NONE,0); |
| 306 | | /* Underlining */ |
| 307 | | if ((attr & 7) == 1) |
| 308 | | plot_box(bitmap, r.min_x, r.min_y + 12, char_width, |
| 309 | | 1, Machine->pens[2 + (attr & 8)]); |
| 376 | The divder/pixels per 6845 clock is 9 for text mode and 16 for graphics mode. |
| 377 | */ |
| 310 | 378 | |
| 311 | | if (cursor.on&&(mda.pc_framecnt&32)&&(offs==cursor.pos*2)) { |
| 312 | | int k=height-cursor.top; |
| 313 | | rectangle rect2=r; |
| 314 | | rect2.min_y+=cursor.top; |
| 315 | | if (cursor.bottom<height) k=cursor.bottom-cursor.top+1; |
| 379 | static const mc6845_interface mc6845_hercules_intf = { |
| 380 | HERCULES_SCREEN_NAME, /* screen number */ |
| 381 | 16257000/9 /*?*/, /* clock */ |
| 382 | 9, /* number of pixels per video memory address */ |
| 383 | NULL, /* begin_update */ |
| 384 | mda_update_row, /* update_row */ |
| 385 | NULL, /* end_update */ |
| 386 | NULL, /* on_de_changed */ |
| 387 | mda_hsync_changed, /* on_hsync_changed */ |
| 388 | mda_vsync_changed /* on_vsync_changed */ |
| 389 | }; |
| 316 | 390 | |
| 317 | | if (k>0) |
| 318 | | plot_box(bitmap, r.min_x, |
| 319 | | r.min_y+cursor.top, |
| 320 | | char_width, k, Machine->pens[2/*?*/]); |
| 321 | | } |
| 322 | | } |
| 323 | | } |
| 324 | | } |
| 391 | MACHINE_DRIVER_START( pcvideo_hercules ) |
| 392 | MDRV_SCREEN_ADD( HERCULES_SCREEN_NAME, RASTER) |
| 393 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 394 | MDRV_SCREEN_RAW_PARAMS(16257000, 882, 0, 720, 370, 0, 350 ) |
| 395 | MDRV_PALETTE_LENGTH( sizeof(mda_palette) / 3 ) |
| 325 | 396 | |
| 397 | MDRV_PALETTE_INIT(pc_mda) |
| 326 | 398 | |
| 327 | | /*************************************************************************** |
| 328 | | Draw text mode with 80x25 characters (default) and blinking characters. |
| 329 | | The character cell size is 9x15. Column 9 is column 8 repeated for |
| 330 | | character codes 176 to 223. |
| 331 | | ***************************************************************************/ |
| 332 | | static void mda_text_blink(bitmap_t *bitmap, struct mscrtc6845 *crtc) |
| 333 | | { |
| 334 | | int sx, sy; |
| 335 | | int offs = mscrtc6845_get_start(crtc)*2; |
| 336 | | int lines = mscrtc6845_get_char_lines(crtc); |
| 337 | | int height = mscrtc6845_get_char_height(crtc); |
| 338 | | int columns = mscrtc6845_get_char_columns(crtc); |
| 339 | | rectangle r; |
| 340 | | struct mscrtc6845_cursor cursor; |
| 341 | | int char_width; |
| 342 | | const device_config *screen = video_screen_first(Machine->config); |
| 343 | | int screen_width = video_screen_get_width(screen); |
| 399 | MDRV_DEVICE_ADD( HERCULES_MC6845_NAME, MC6845) |
| 400 | MDRV_DEVICE_CONFIG( mc6845_hercules_intf ) |
| 344 | 401 | |
| 345 | | char_width = screen_width / 80; |
| 402 | MDRV_VIDEO_START( pc_hercules ) |
| 403 | MDRV_VIDEO_UPDATE( mc6845_hercules ) |
| 404 | MACHINE_DRIVER_END |
| 346 | 405 | |
| 347 | | mscrtc6845_time(crtc); |
| 348 | | mscrtc6845_get_cursor(crtc, &cursor); |
| 349 | 406 | |
| 350 | | for (sy=0, r.min_y=0, r.max_y=height-1; sy<lines; sy++, r.min_y+=height,r.max_y+=height) |
| 407 | static VIDEO_START( pc_hercules ) { |
| 408 | int buswidth; |
| 409 | |
| 410 | buswidth = cputype_databus_width(machine->config->cpu[0].type, ADDRESS_SPACE_PROGRAM); |
| 411 | switch(buswidth) |
| 351 | 412 | { |
| 352 | | for (sx=0, r.min_x=0, r.max_x = char_width-1; sx<columns; |
| 353 | | sx++, offs=(offs+2)&0x3fff, r.min_x += char_width, r.max_x += char_width) |
| 354 | | { |
| 355 | | int attr = videoram[offs+1]; |
| 356 | | if (attr & 0x80) /* blinking ? */ |
| 357 | | { |
| 358 | | if (mda.pc_blink) attr = 0; |
| 359 | | } |
| 413 | case 8: |
| 414 | memory_install_read8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xbffff, 0, 0, SMH_BANK11 ); |
| 415 | memory_install_write8_handler(0, ADDRESS_SPACE_PROGRAM, 0xb0000, 0xbffff, 0, 0, pc_video_videoram_w ); |
| 416 | memory_install_read8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_hercules_r ); |
| 417 | memory_install_write8_handler(0, ADDRESS_SPACE_IO, 0x3b0, 0x3bf, 0, 0, pc_hercules_w ); |
| 418 | break; |
| 360 | 419 | |
| 361 | | drawgfx(bitmap, mda.gfx_char[CGA_FONT], videoram[offs], attr, |
| 362 | | 0,0,r.min_x,r.min_y,&r,TRANSPARENCY_NONE,0); |
| 363 | | /* Underlining */ |
| 364 | | if ((attr & 7) == 1) |
| 365 | | plot_box(bitmap, r.min_x, r.min_y + 12, char_width, |
| 366 | | 1, Machine->pens[2 + (attr & 8)]); |
| 420 | default: |
| 421 | fatalerror("Hercules: Bus width %d not supported\n", buswidth); |
| 422 | break; |
| 423 | } |
| 367 | 424 | |
| 368 | | // if ((cursor.on)&&(offs==cursor.pos*2)) { |
| 369 | | if (cursor.on&&(mda.pc_framecnt&32)&&(offs==cursor.pos*2)) { |
| 370 | | int k=height-cursor.top; |
| 371 | | rectangle rect2=r; |
| 372 | | rect2.min_y+=cursor.top; |
| 373 | | if (cursor.bottom<height) k=cursor.bottom-cursor.top+1; |
| 425 | memset( &mda, 0, sizeof(mda)); |
| 426 | mda.update_row = NULL; |
| 427 | mda.chr_gen = memory_region( REGION_GFX1 ); |
| 374 | 428 | |
| 375 | | if (k>0) |
| 376 | | plot_box(bitmap, r.min_x, |
| 377 | | r.min_y+cursor.top, |
| 378 | | char_width, k, Machine->pens[2/*?*/]); |
| 379 | | } |
| 380 | | } |
| 381 | | } |
| 429 | videoram_size = 0x10000; |
| 430 | videoram = auto_malloc(videoram_size); |
| 431 | memory_set_bankptr(11, videoram); |
| 382 | 432 | } |
| 383 | 433 | |
| 434 | |
| 384 | 435 | /*************************************************************************** |
| 385 | | Draw graphics with 720x384 pixels (default); so called Hercules gfx. |
| 436 | Draw graphics with 720x348 pixels (default); so called Hercules gfx. |
| 386 | 437 | The memory layout is divided into 4 banks where of size 0x2000. |
| 387 | 438 | Every bank holds data for every n'th scanline, 8 pixels per byte, |
| 388 | 439 | bit 7 being the leftmost. |
| 389 | 440 | ***************************************************************************/ |
| 390 | 441 | |
| 391 | | static void hercules_gfx(bitmap_t *bitmap, struct mscrtc6845 *crtc) |
| 392 | | { |
| 393 | | const UINT8 *vram = videoram; |
| 394 | | static const UINT16 palette[2] = {0, 10}; |
| 442 | static MC6845_UPDATE_ROW( hercules_gfx_update_row ) { |
| 443 | UINT16 *p = BITMAP_ADDR16( bitmap, y, 0 ); |
| 444 | UINT16 gfx_base = ( ( mda.mode_control & 0x80 ) ? 0x8000 : 0x0000 ) | ( ( y & 0x03 ) << 13 ); |
| 445 | int i; |
| 395 | 446 | |
| 396 | | if (mda.mode_control & 0x80) |
| 397 | | vram += 0x8000; |
| 447 | if ( y == 0 ) logerror("hercules_gfx_update_row\n"); |
| 448 | for ( i = 0; i < x_count; i++ ) { |
| 449 | UINT8 data = videoram[ gfx_base + ( ( ma + i ) << 1 ) ]; |
| 398 | 450 | |
| 399 | | pc_render_gfx_1bpp(bitmap, crtc, vram, palette, 4); |
| 451 | *p = ( data & 0x80 ) ? 2 : 0; p++; |
| 452 | *p = ( data & 0x40 ) ? 2 : 0; p++; |
| 453 | *p = ( data & 0x20 ) ? 2 : 0; p++; |
| 454 | *p = ( data & 0x10 ) ? 2 : 0; p++; |
| 455 | *p = ( data & 0x08 ) ? 2 : 0; p++; |
| 456 | *p = ( data & 0x04 ) ? 2 : 0; p++; |
| 457 | *p = ( data & 0x02 ) ? 2 : 0; p++; |
| 458 | *p = ( data & 0x01 ) ? 2 : 0; p++; |
| 459 | |
| 460 | data = videoram[ gfx_base + ( ( ma + i ) << 1 ) + 1 ]; |
| 461 | |
| 462 | *p = ( data & 0x80 ) ? 2 : 0; p++; |
| 463 | *p = ( data & 0x40 ) ? 2 : 0; p++; |
| 464 | *p = ( data & 0x20 ) ? 2 : 0; p++; |
| 465 | *p = ( data & 0x10 ) ? 2 : 0; p++; |
| 466 | *p = ( data & 0x08 ) ? 2 : 0; p++; |
| 467 | *p = ( data & 0x04 ) ? 2 : 0; p++; |
| 468 | *p = ( data & 0x02 ) ? 2 : 0; p++; |
| 469 | *p = ( data & 0x01 ) ? 2 : 0; p++; |
| 470 | } |
| 400 | 471 | } |
| 401 | 472 | |
| 402 | 473 | |
| 474 | static VIDEO_UPDATE( mc6845_hercules ) { |
| 475 | device_config *devconf = (device_config *) device_list_find_by_tag(screen->machine->config->devicelist, MC6845, HERCULES_MC6845_NAME); |
| 476 | mc6845_update( devconf, bitmap, cliprect ); |
| 477 | return 0; |
| 478 | } |
| 403 | 479 | |
| 404 | | /*************************************************************************** |
| 405 | | Choose the appropriate video mode |
| 406 | | ***************************************************************************/ |
| 407 | 480 | |
| 408 | | pc_video_update_proc pc_mda_choosevideomode(int *width, int *height, struct mscrtc6845 *crtc) |
| 409 | | { |
| 410 | | pc_video_update_proc proc = NULL; |
| 411 | | const device_config *screen = video_screen_first(Machine->config); |
| 412 | | int screen_width = video_screen_get_width(screen); |
| 481 | static void hercules_mode_control_w(int data) { |
| 482 | MDA_LOG(1,"hercules_mode_control_w",("$%02x: colums %d, gfx %d, enable %d, blink %d\n", |
| 483 | data, (data&1)?80:40, (data>>1)&1, (data>>3)&1, (data>>5)&1)); |
| 484 | mda.mode_control = data; |
| 413 | 485 | |
| 414 | | switch (mda.mode_control & 0x2a) { /* text and gfx modes */ |
| 486 | switch( mda.mode_control & 0x2a ) { |
| 415 | 487 | case 0x08: |
| 416 | | proc = mda_text_inten; |
| 417 | | *width *= screen_width / 80; |
| 488 | mda.update_row = mda_text_inten_update_row; |
| 418 | 489 | break; |
| 419 | 490 | case 0x28: |
| 420 | | proc = mda_text_blink; |
| 421 | | *width *= screen_width / 80; |
| 491 | mda.update_row = mda_text_blink_update_row; |
| 422 | 492 | break; |
| 423 | | case 0x0a: |
| 424 | | case 0x2a: |
| 425 | | proc = hercules_gfx; |
| 426 | | *width *= 16; |
| 493 | case 0x0A: /* Hercules modes */ |
| 494 | case 0x2A: |
| 495 | mda.update_row = hercules_gfx_update_row; |
| 427 | 496 | break; |
| 428 | | } |
| 429 | | return proc; |
| 497 | default: |
| 498 | mda.update_row = NULL; |
| 499 | } |
| 430 | 500 | } |
| 431 | 501 | |
| 502 | |
| 503 | static void hercules_config_w(int data) |
| 504 | { |
| 505 | MDA_LOG(1,"HGC_config_w",("$%02x\n", data)); |
| 506 | mda.configuration_switch = data; |
| 507 | } |
| 508 | |
| 509 | |
| 510 | static WRITE8_HANDLER ( pc_hercules_w ) { |
| 511 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, HERCULES_MC6845_NAME); |
| 512 | |
| 513 | switch( offset ) { |
| 514 | case 0: case 2: case 4: case 6: |
| 515 | mc6845_address_w( devconf, offset, data ); |
| 516 | break; |
| 517 | case 1: case 3: case 5: case 7: |
| 518 | mc6845_register_w( devconf, offset, data ); |
| 519 | break; |
| 520 | case 8: |
| 521 | hercules_mode_control_w(data); |
| 522 | break; |
| 523 | case 15: |
| 524 | hercules_config_w(data); |
| 525 | break; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | |
| 530 | /* R- CRT status register (see #P139) |
| 531 | * (EGA/VGA) input status 1 register |
| 532 | * 7 HGC vertical sync in progress |
| 533 | * 6-4 adapter 000 hercules |
| 534 | * 001 hercules+ |
| 535 | * 101 hercules InColor |
| 536 | * else unknown |
| 537 | * 3 pixel stream (0 black, 1 white) |
| 538 | * 2-1 reserved |
| 539 | * 0 horizontal drive enable |
| 540 | */ |
| 541 | static int pc_hercules_status_r(void) |
| 542 | { |
| 543 | int data = mda.vsync | 0x08 | mda.hsync; |
| 544 | return data; |
| 545 | } |
| 546 | |
| 547 | |
| 548 | static READ8_HANDLER ( pc_hercules_r ) { |
| 549 | device_config *devconf = (device_config *) device_list_find_by_tag(machine->config->devicelist, MC6845, HERCULES_MC6845_NAME); |
| 550 | int data = 0xff; |
| 551 | |
| 552 | switch( offset ) { |
| 553 | case 0: case 2: case 4: case 6: |
| 554 | /* return last written mc6845 address value here? */ |
| 555 | break; |
| 556 | case 1: case 3: case 5: case 7: |
| 557 | data = mc6845_register_r( devconf, offset ); |
| 558 | break; |
| 559 | case 10: |
| 560 | data = pc_hercules_status_r(); |
| 561 | break; |
| 562 | /* 12, 13, 14 are the LPT1 ports */ |
| 563 | } |
| 564 | return data; |
| 565 | } |
| 566 | |