src/mess/video/spec128.c
| r4140 | r4141 | |
| 1 | | /*************************************************************************** |
| 2 | | |
| 3 | | spectrum.c |
| 4 | | |
| 5 | | Functions to emulate the video hardware of the ZX Spectrum. |
| 6 | | |
| 7 | | Changes: |
| 8 | | |
| 9 | | DJR 08/02/00 - Added support for FLASH 1. |
| 10 | | DJR 16/05/00 - Support for TS2068/TC2048 hires and 64 column modes. |
| 11 | | DJR 19/05/00 - Speeded up Spectrum 128 screen refresh. |
| 12 | | DJR 23/05/00 - Preliminary support for border colour emulation. |
| 13 | | |
| 14 | | ***************************************************************************/ |
| 15 | | |
| 16 | | #include "driver.h" |
| 17 | | #include "includes/spectrum.h" |
| 18 | | #include "eventlst.h" |
| 19 | | #include "video/border.h" |
| 20 | | |
| 21 | | INLINE void spectrum_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color) |
| 22 | | { |
| 23 | | *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color; |
| 24 | | } |
| 25 | | |
| 26 | | |
| 27 | | VIDEO_START( spectrum_128 ) |
| 28 | | { |
| 29 | | frame_number = 0; |
| 30 | | flash_invert = 0; |
| 31 | | |
| 32 | | EventList_Initialise(30000); |
| 33 | | } |
| 34 | | |
| 35 | | /* Refresh the spectrum 128 screen (code modified from COUPE.C) */ |
| 36 | | VIDEO_UPDATE( spectrum_128 ) |
| 37 | | { |
| 38 | | /* for now do a full-refresh */ |
| 39 | | int x, y, b, scrx, scry; |
| 40 | | unsigned short ink, pap; |
| 41 | | unsigned char *attr, *scr; |
| 42 | | int full_refresh = 1; |
| 43 | | |
| 44 | | scr=spectrum_128_screen_location; |
| 45 | | |
| 46 | | for (y=0; y<192; y++) |
| 47 | | { |
| 48 | | scrx=SPEC_LEFT_BORDER; |
| 49 | | scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0); |
| 50 | | attr=spectrum_128_screen_location + ((scry>>3)*32) + 0x1800; |
| 51 | | |
| 52 | | for (x=0;x<32;x++) |
| 53 | | { |
| 54 | | /* Get ink and paper colour with bright */ |
| 55 | | if (flash_invert && (*attr & 0x80)) |
| 56 | | { |
| 57 | | ink=((*attr)>>3) & 0x0f; |
| 58 | | pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08); |
| 59 | | } |
| 60 | | else |
| 61 | | { |
| 62 | | ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08); |
| 63 | | pap=((*attr)>>3) & 0x0f; |
| 64 | | } |
| 65 | | |
| 66 | | for (b=0x80;b!=0;b>>=1) |
| 67 | | { |
| 68 | | if (*scr&b) |
| 69 | | spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,ink); |
| 70 | | else |
| 71 | | spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,pap); |
| 72 | | } |
| 73 | | scr++; |
| 74 | | attr++; |
| 75 | | } |
| 76 | | } |
| 77 | | |
| 78 | | draw_border(screen->machine, bitmap, full_refresh, |
| 79 | | SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER, |
| 80 | | SPEC_LEFT_BORDER, SPEC_DISPLAY_XSIZE, SPEC_RIGHT_BORDER, |
| 81 | | SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES, |
| 82 | | SPEC_RIGHT_BORDER_CYCLES, SPEC128_RETRACE_CYCLES, 200, 0xfe); |
| 83 | | return 0; |
| 84 | | } |
| 85 | | |
| 86 | | |
| 87 | | |
| 88 | | static const rgb_t spectrum_128_palette[16] = { |
| 89 | | MAKE_RGB(0x00, 0x00, 0x00), |
| 90 | | MAKE_RGB(0x00, 0x00, 0xbf), |
| 91 | | MAKE_RGB(0xbf, 0x00, 0x00), |
| 92 | | MAKE_RGB(0xbf, 0x00, 0xbf), |
| 93 | | MAKE_RGB(0x00, 0xbf, 0x00), |
| 94 | | MAKE_RGB(0x00, 0xbf, 0xbf), |
| 95 | | MAKE_RGB(0xbf, 0xbf, 0x00), |
| 96 | | MAKE_RGB(0xbf, 0xbf, 0xbf), |
| 97 | | MAKE_RGB(0x00, 0x00, 0x00), |
| 98 | | MAKE_RGB(0x00, 0x00, 0xff), |
| 99 | | MAKE_RGB(0xff, 0x00, 0x00), |
| 100 | | MAKE_RGB(0xff, 0x00, 0xff), |
| 101 | | MAKE_RGB(0x00, 0xff, 0x00), |
| 102 | | MAKE_RGB(0x00, 0xff, 0xff), |
| 103 | | MAKE_RGB(0xff, 0xff, 0x00), |
| 104 | | MAKE_RGB(0xff, 0xff, 0xff) |
| 105 | | }; |
| 106 | | |
| 107 | | PALETTE_INIT( spectrum_128 ) |
| 108 | | { |
| 109 | | palette_set_colors(machine, 0, spectrum_128_palette, ARRAY_LENGTH(spectrum_128_palette)); |
| 110 | | } |
| 111 | | |
src/mess/video/spectrum.c
| r4140 | r4141 | |
| 19 | 19 | #include "video/border.h" |
| 20 | 20 | |
| 21 | 21 | |
| 22 | | UINT8 *spectrum_characterram; |
| 23 | | UINT8 *spectrum_colorram; |
| 24 | | |
| 22 | unsigned char *spectrum_video_ram; |
| 23 | UINT8 retrace_cycles; |
| 25 | 24 | int frame_number; /* Used for handling FLASH 1 */ |
| 26 | 25 | int flash_invert; |
| 27 | 26 | |
| r4140 | r4141 | |
| 32 | 31 | { |
| 33 | 32 | frame_number = 0; |
| 34 | 33 | flash_invert = 0; |
| 34 | |
| 35 | 35 | EventList_Initialise(30000); |
| 36 | |
| 37 | retrace_cycles = SPEC_RETRACE_CYCLES; |
| 38 | |
| 39 | spectrum_screen_location = spectrum_video_ram; |
| 36 | 40 | } |
| 37 | 41 | |
| 42 | VIDEO_START( spectrum_128 ) |
| 43 | { |
| 44 | frame_number = 0; |
| 45 | flash_invert = 0; |
| 38 | 46 | |
| 47 | EventList_Initialise(30000); |
| 48 | |
| 49 | retrace_cycles = SPEC128_RETRACE_CYCLES; |
| 50 | } |
| 51 | |
| 52 | |
| 39 | 53 | /* return the color to be used inverting FLASHing colors if necessary */ |
| 40 | 54 | INLINE unsigned char get_display_color (unsigned char color, int invert) |
| 41 | 55 | { |
| r4140 | r4141 | |
| 97 | 111 | |
| 98 | 112 | ***************************************************************************/ |
| 99 | 113 | |
| 114 | INLINE void spectrum_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color) |
| 115 | { |
| 116 | *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color; |
| 117 | } |
| 118 | |
| 100 | 119 | VIDEO_UPDATE( spectrum ) |
| 101 | 120 | { |
| 102 | | int count; |
| 103 | | int full_refresh = 1; |
| 104 | | static int last_invert = 0; |
| 121 | /* for now do a full-refresh */ |
| 122 | int x, y, b, scrx, scry; |
| 123 | unsigned short ink, pap; |
| 124 | unsigned char *attr, *scr; |
| 125 | int full_refresh = 1; |
| 105 | 126 | |
| 106 | | if (full_refresh) |
| 107 | | { |
| 108 | | last_invert = flash_invert; |
| 109 | | } |
| 110 | | else |
| 111 | | { |
| 112 | | /* Update all flashing characters when necessary */ |
| 113 | | if (last_invert != flash_invert) |
| 114 | | { |
| 115 | | last_invert = flash_invert; |
| 116 | | } |
| 117 | | } |
| 127 | scr=spectrum_screen_location; |
| 118 | 128 | |
| 119 | | for (count=0;count<32*8;count++) |
| 120 | | { |
| 121 | | gfx_element_mark_dirty( screen->machine->gfx[0],count); |
| 122 | | gfx_element_mark_dirty( screen->machine->gfx[1],count); |
| 123 | | gfx_element_mark_dirty( screen->machine->gfx[2],count); |
| 124 | | } |
| 129 | for (y=0; y<192; y++) |
| 130 | { |
| 131 | scrx=SPEC_LEFT_BORDER; |
| 132 | scry=((y&7) * 8) + ((y&0x38)>>3) + (y&0xC0); |
| 133 | attr=spectrum_screen_location + ((scry>>3)*32) + 0x1800; |
| 125 | 134 | |
| 126 | | for (count=0;count<32*8;count++) |
| 127 | | { |
| 128 | | int sx=count%32; |
| 129 | | int sy=count/32; |
| 130 | | unsigned char color; |
| 135 | for (x=0;x<32;x++) |
| 136 | { |
| 137 | /* Get ink and paper colour with bright */ |
| 138 | if (flash_invert && (*attr & 0x80)) |
| 139 | { |
| 140 | ink=((*attr)>>3) & 0x0f; |
| 141 | pap=((*attr) & 0x07) + (((*attr)>>3) & 0x08); |
| 142 | } |
| 143 | else |
| 144 | { |
| 145 | ink=((*attr) & 0x07) + (((*attr)>>3) & 0x08); |
| 146 | pap=((*attr)>>3) & 0x0f; |
| 147 | } |
| 131 | 148 | |
| 132 | | color=get_display_color(spectrum_colorram[count],flash_invert); |
| 133 | | drawgfx(bitmap,screen->machine->gfx[0], |
| 134 | | count, |
| 135 | | color+8, // use 2nd part of palette |
| 136 | | 0,0, |
| 137 | | (sx*8)+SPEC_LEFT_BORDER,(sy*8)+SPEC_TOP_BORDER, |
| 138 | | 0,TRANSPARENCY_NONE,0); |
| 139 | | |
| 140 | | color=get_display_color(spectrum_colorram[count+0x100],flash_invert); |
| 141 | | drawgfx(bitmap,screen->machine->gfx[1], |
| 142 | | count, |
| 143 | | color+8, // use 2nd part of palette |
| 144 | | 0,0, |
| 145 | | (sx*8)+SPEC_LEFT_BORDER,((sy+8)*8)+SPEC_TOP_BORDER, |
| 146 | | 0,TRANSPARENCY_NONE,0); |
| 147 | | |
| 148 | | color=get_display_color(spectrum_colorram[count+0x200],flash_invert); |
| 149 | | drawgfx(bitmap,screen->machine->gfx[2], |
| 150 | | count, |
| 151 | | color+8, // use 2nd part of palette |
| 152 | | 0,0, |
| 153 | | (sx*8)+SPEC_LEFT_BORDER,((sy+16)*8)+SPEC_TOP_BORDER, |
| 154 | | 0,TRANSPARENCY_NONE,0); |
| 149 | for (b=0x80;b!=0;b>>=1) |
| 150 | { |
| 151 | if (*scr&b) |
| 152 | spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,ink); |
| 153 | else |
| 154 | spectrum_plot_pixel(bitmap,scrx++,SPEC_TOP_BORDER+scry,pap); |
| 155 | } |
| 156 | scr++; |
| 157 | attr++; |
| 158 | } |
| 155 | 159 | } |
| 156 | 160 | |
| 157 | | /* When screen refresh is called there is only one blank line |
| 158 | | (synchronised with start of screen data) before the border lines. |
| 159 | | There should be 16 blank lines after an interrupt is called. |
| 160 | | */ |
| 161 | | draw_border(screen->machine, bitmap, full_refresh, |
| 162 | | SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER, |
| 163 | | SPEC_LEFT_BORDER, SPEC_DISPLAY_XSIZE, SPEC_RIGHT_BORDER, |
| 164 | | SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES, |
| 165 | | SPEC_RIGHT_BORDER_CYCLES, SPEC_RETRACE_CYCLES, 200, 0xfe); |
| 161 | draw_border(screen->machine, bitmap, full_refresh, |
| 162 | SPEC_TOP_BORDER, SPEC_DISPLAY_YSIZE, SPEC_BOTTOM_BORDER, |
| 163 | SPEC_LEFT_BORDER, SPEC_DISPLAY_XSIZE, SPEC_RIGHT_BORDER, |
| 164 | SPEC_LEFT_BORDER_CYCLES, SPEC_DISPLAY_XSIZE_CYCLES, |
| 165 | SPEC_RIGHT_BORDER_CYCLES, retrace_cycles, 200, 0xfe); |
| 166 | 166 | return 0; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | | const gfx_layout spectrum_charlayout = |
| 170 | | { |
| 171 | | 8,8, |
| 172 | | 256, |
| 173 | | 1, /* 1 bits per pixel */ |
| 174 | 169 | |
| 175 | | { 0 }, /* no bitplanes; 1 bit per pixel */ |
| 176 | | |
| 177 | | { 0, 1, 2, 3, 4, 5, 6, 7 }, |
| 178 | | { 0, 8*256, 16*256, 24*256, 32*256, 40*256, 48*256, 56*256 }, |
| 179 | | |
| 180 | | 8 /* every char takes 1 consecutive byte */ |
| 170 | static const rgb_t spectrum_palette[16] = { |
| 171 | MAKE_RGB(0x00, 0x00, 0x00), |
| 172 | MAKE_RGB(0x00, 0x00, 0xbf), |
| 173 | MAKE_RGB(0xbf, 0x00, 0x00), |
| 174 | MAKE_RGB(0xbf, 0x00, 0xbf), |
| 175 | MAKE_RGB(0x00, 0xbf, 0x00), |
| 176 | MAKE_RGB(0x00, 0xbf, 0xbf), |
| 177 | MAKE_RGB(0xbf, 0xbf, 0x00), |
| 178 | MAKE_RGB(0xbf, 0xbf, 0xbf), |
| 179 | MAKE_RGB(0x00, 0x00, 0x00), |
| 180 | MAKE_RGB(0x00, 0x00, 0xff), |
| 181 | MAKE_RGB(0xff, 0x00, 0x00), |
| 182 | MAKE_RGB(0xff, 0x00, 0xff), |
| 183 | MAKE_RGB(0x00, 0xff, 0x00), |
| 184 | MAKE_RGB(0x00, 0xff, 0xff), |
| 185 | MAKE_RGB(0xff, 0xff, 0x00), |
| 186 | MAKE_RGB(0xff, 0xff, 0xff) |
| 181 | 187 | }; |
| 182 | | |
| 183 | | #define ZX_COL_0 MAKE_RGB(0x00, 0x00, 0x00) |
| 184 | | #define ZX_COL_1 MAKE_RGB(0x00, 0x00, 0xbf) |
| 185 | | #define ZX_COL_2 MAKE_RGB(0xbf, 0x00, 0x00) |
| 186 | | #define ZX_COL_3 MAKE_RGB(0xbf, 0x00, 0xbf) |
| 187 | | #define ZX_COL_4 MAKE_RGB(0x00, 0xbf, 0x00) |
| 188 | | #define ZX_COL_5 MAKE_RGB(0x00, 0xbf, 0xbf) |
| 189 | | #define ZX_COL_6 MAKE_RGB(0xbf, 0xbf, 0x00) |
| 190 | | #define ZX_COL_7 MAKE_RGB(0xbf, 0xbf, 0xbf) |
| 191 | | #define ZX_COL_8 MAKE_RGB(0x00, 0x00, 0x00) |
| 192 | | #define ZX_COL_9 MAKE_RGB(0x00, 0x00, 0xff) |
| 193 | | #define ZX_COL_A MAKE_RGB(0xff, 0x00, 0x00) |
| 194 | | #define ZX_COL_B MAKE_RGB(0xff, 0x00, 0xff) |
| 195 | | #define ZX_COL_C MAKE_RGB(0x00, 0xff, 0x00) |
| 196 | | #define ZX_COL_D MAKE_RGB(0x00, 0xff, 0xff) |
| 197 | | #define ZX_COL_E MAKE_RGB(0xff, 0xff, 0x00) |
| 198 | | #define ZX_COL_F MAKE_RGB(0xff, 0xff, 0xff) |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