src/mess/video/smsvdp.c
| r6078 | r6079 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | smsvdp.c |
| 4 | |
| 5 | Implementation of video hardware chip used by Sega Master System |
| 6 | |
| 7 | **********************************************************************/ |
| 8 | |
| 1 | 9 | /* |
| 2 | 10 | For more information, please see: |
| 3 | 11 | - http://cgfm2.emuviews.com/txt/msvdp.txt |
| r6078 | r6079 | |
| 34 | 42 | - bottom border 48 C0-EF 32 E0-FF 24 F0-07 |
| 35 | 43 | - bottom blanking 3 F0-F2 3 00-02 3 08-0A |
| 36 | 44 | |
| 45 | TODO: |
| 46 | - implement differences between SMS1_VDP & SMS_VDP/GG_VDP |
| 47 | |
| 37 | 48 | */ |
| 38 | 49 | |
| 39 | 50 | #include "driver.h" |
| 40 | 51 | #include "video/smsvdp.h" |
| 41 | | #include "includes/sms.h" |
| 42 | 52 | |
| 53 | #define IS_SMS1_VDP (smsvdp->features & MODEL_315_5124) |
| 54 | #define IS_SMS2_VDP (smsvdp->features & MODEL_315_5246) |
| 55 | #define IS_GAMEGEAR_VDP (smsvdp->features & MODEL_315_5378) |
| 43 | 56 | |
| 44 | | #define IS_SMS1_VDP ( smsvdp.features & MODEL_315_5124 ) |
| 45 | | #define IS_SMS2_VDP ( smsvdp.features & MODEL_315_5246 ) |
| 46 | | #define IS_GAMEGEAR_VDP ( smsvdp.features & MODEL_315_5378 ) |
| 57 | #define STATUS_VINT 0x80 /* Pending vertical interrupt flag */ |
| 58 | #define STATUS_SPROVR 0x40 /* Sprite overflow flag */ |
| 59 | #define STATUS_SPRCOL 0x20 /* Object collision flag */ |
| 60 | #define STATUS_HINT 0x02 /* Pending horizontal interrupt flag */ |
| 47 | 61 | |
| 48 | | #define STATUS_VINT (0x80) /* Pending vertical interrupt flag */ |
| 49 | | #define STATUS_SPROVR (0x40) /* Sprite overflow flag */ |
| 50 | | #define STATUS_SPRCOL (0x20) /* Object collision flag */ |
| 51 | | #define STATUS_HINT (0x02) /* Pending horizontal interrupt flag */ |
| 62 | #define GG_CRAM_SIZE 0x40 /* 32 colors x 2 bytes per color = 64 bytes */ |
| 63 | #define SMS_CRAM_SIZE 0x20 /* 32 colors x 1 bytes per color = 32 bytes */ |
| 64 | #define MAX_CRAM_SIZE 0x40 |
| 52 | 65 | |
| 53 | | #define GG_CRAM_SIZE (0x40) /* 32 colors x 2 bytes per color = 64 bytes */ |
| 54 | | #define SMS_CRAM_SIZE (0x20) /* 32 colors x 1 bytes per color = 32 bytes */ |
| 55 | | #define MAX_CRAM_SIZE 0x40 |
| 66 | #define VRAM_SIZE 0x4000 |
| 56 | 67 | |
| 57 | | #define VRAM_SIZE (0x4000) |
| 68 | #define PRIORITY_BIT 0x1000 |
| 69 | #define BACKDROP_COLOR ((smsvdp->vdp_mode == 4 ? 0x10 : 0x00) + (smsvdp->reg[0x07] & 0x0f)) |
| 58 | 70 | |
| 59 | | #define PRIORITY_BIT 0x1000 |
| 60 | | #define BACKDROP_COLOR ( ( smsvdp.vdp_mode == 4 ? 0x10 : 0x00 ) + (smsvdp.reg[0x07] & 0x0F)) |
| 71 | #define NUM_OF_REGISTER 0x10 /* 16 registers */ |
| 61 | 72 | |
| 62 | | #define NUM_OF_REGISTER (0x10) /* 16 registers */ |
| 73 | #define INIT_VCOUNT 0 |
| 74 | #define VERTICAL_BLANKING 1 |
| 75 | #define TOP_BLANKING 2 |
| 76 | #define TOP_BORDER 3 |
| 77 | #define ACTIVE_DISPLAY_V 4 |
| 78 | #define BOTTOM_BORDER 5 |
| 79 | #define BOTTOM_BLANKING 6 |
| 63 | 80 | |
| 64 | | #define INIT_VCOUNT 0 |
| 65 | | #define VERTICAL_BLANKING 1 |
| 66 | | #define TOP_BLANKING 2 |
| 67 | | #define TOP_BORDER 3 |
| 68 | | #define ACTIVE_DISPLAY_V 4 |
| 69 | | #define BOTTOM_BORDER 5 |
| 70 | | #define BOTTOM_BLANKING 6 |
| 81 | static const UINT8 sms_ntsc_192[7] = { 0xd5, 3, 13, 27, 192, 24, 3 }; |
| 82 | static const UINT8 sms_ntsc_224[7] = { 0xe5, 3, 13, 11, 224, 8, 3 }; |
| 83 | static const UINT8 sms_ntsc_240[7] = { 0xee, 3, 13, 3, 240, 0, 3 }; |
| 84 | static const UINT8 sms_pal_192[7] = { 0xba, 3, 13, 54, 192, 48, 3 }; |
| 85 | static const UINT8 sms_pal_224[7] = { 0xca, 3, 13, 38, 224, 32, 3 }; |
| 86 | static const UINT8 sms_pal_240[7] = { 0xd2, 3, 13, 30, 240, 24, 3 }; |
| 71 | 87 | |
| 72 | | static const UINT8 sms_ntsc_192[7] = { 0xD5, 3, 13, 27, 192, 24, 3 }; |
| 73 | | static const UINT8 sms_ntsc_224[7] = { 0xE5, 3, 13, 11, 224, 8, 3 }; |
| 74 | | static const UINT8 sms_ntsc_240[7] = { 0xEE, 3, 13, 3, 240, 0, 3 }; |
| 75 | | static const UINT8 sms_pal_192[7] = { 0xBA, 3, 13, 54, 192, 48, 3 }; |
| 76 | | static const UINT8 sms_pal_224[7] = { 0xCA, 3, 13, 38, 224, 32, 3 }; |
| 77 | | static const UINT8 sms_pal_240[7] = { 0xD2, 3, 13, 30, 240, 24, 3 }; |
| 78 | 88 | |
| 79 | | static struct _smsvdp |
| 89 | typedef struct _smsvdp_t smsvdp_t; |
| 90 | struct _smsvdp_t |
| 80 | 91 | { |
| 81 | | UINT32 features; |
| 82 | | UINT8 reg[NUM_OF_REGISTER]; /* All the registers */ |
| 83 | | UINT8 status; /* Status register */ |
| 84 | | UINT8 reg9copy; /* Internal copy of register 9 */ |
| 85 | | UINT8 addrmode; /* Type of VDP action */ |
| 86 | | UINT16 addr; /* Contents of internal VDP address register */ |
| 87 | | UINT8 cram_mask; /* Mask to switch between SMS and GG CRAM sizes */ |
| 88 | | int cram_dirty; /* Have there been any changes to the CRAM area */ |
| 89 | | int pending; |
| 90 | | UINT8 buffer; |
| 91 | | int gg_sms_mode; /* Shrunk SMS screen on GG lcd mode flag */ |
| 92 | | int irq_state; /* The status of the IRQ line of the VDP */ |
| 93 | | int vdp_mode; /* Current mode of the VDP: 0,1,2,3,4 */ |
| 94 | | int y_pixels; /* 192, 224, 240 */ |
| 95 | | int line_counter; |
| 96 | | UINT8 *VRAM; /* Pointer to VRAM */ |
| 97 | | UINT8 *CRAM; /* Pointer to CRAM */ |
| 98 | | const UINT8 *sms_frame_timing; |
| 99 | | bitmap_t *prev_bitmap; |
| 100 | | int prev_bitmap_saved; |
| 101 | | UINT8 *collision_buffer; |
| 92 | UINT32 features; |
| 93 | UINT8 reg[NUM_OF_REGISTER]; /* All the registers */ |
| 94 | UINT8 status; /* Status register */ |
| 95 | UINT8 reg9copy; /* Internal copy of register 9 */ |
| 96 | UINT8 addrmode; /* Type of VDP action */ |
| 97 | UINT16 addr; /* Contents of internal VDP address register */ |
| 98 | UINT8 cram_mask; /* Mask to switch between SMS and GG CRAM sizes */ |
| 99 | int cram_dirty; /* Have there been any changes to the CRAM area */ |
| 100 | int pending; |
| 101 | UINT8 buffer; |
| 102 | int gg_sms_mode; /* Shrunk SMS screen on GG lcd mode flag */ |
| 103 | int irq_state; /* The status of the IRQ line of the VDP */ |
| 104 | int vdp_mode; /* Current mode of the VDP: 0,1,2,3,4 */ |
| 105 | int y_pixels; /* 192, 224, 240 */ |
| 106 | int line_counter; |
| 107 | UINT8 hcounter; |
| 108 | UINT8 *VRAM; /* Pointer to VRAM */ |
| 109 | UINT8 *CRAM; /* Pointer to CRAM */ |
| 110 | const UINT8 *sms_frame_timing; |
| 111 | bitmap_t *prev_bitmap; |
| 112 | bitmap_t *tmpbitmap; |
| 113 | int prev_bitmap_saved; |
| 114 | UINT8 *collision_buffer; |
| 102 | 115 | |
| 103 | | /* lineBuffer will be used to hold 5 lines of line data. Line #0 is the regular blitting area. |
| 116 | /* line_buffer will be used to hold 5 lines of line data. Line #0 is the regular blitting area. |
| 104 | 117 | Lines #1-#4 will be used as a kind of cache to be used for vertical scaling in the gamegear |
| 105 | | sms compatibility mode. |
| 106 | | */ |
| 107 | | int *line_buffer; |
| 108 | | int current_palette[32]; |
| 109 | | void (*int_callback)(running_machine*,int); |
| 110 | | emu_timer *smsvdp_display_timer; |
| 111 | | } smsvdp; |
| 118 | sms compatibility mode. */ |
| 119 | int *line_buffer; |
| 120 | int current_palette[32]; |
| 121 | smsvdp_int_cb int_callback; |
| 122 | smsvdp_pause_cb pause_callback; |
| 123 | emu_timer *smsvdp_display_timer; |
| 124 | }; |
| 112 | 125 | |
| 113 | | static TIMER_CALLBACK(smsvdp_display_callback); |
| 114 | | static void sms_refresh_line(running_machine *machine, bitmap_t *bitmap, int offsetx, int offsety, int line); |
| 115 | | static void sms_update_palette(void); |
| 126 | static TIMER_CALLBACK( smsvdp_display_callback ); |
| 127 | static void sms_refresh_line( running_machine *machine, smsvdp_t *smsvdp, bitmap_t *bitmap, int offsetx, int offsety, int line ); |
| 128 | static void sms_update_palette( smsvdp_t *smsvdp ); |
| 116 | 129 | |
| 117 | | static void set_display_settings( running_machine *machine ) |
| 130 | |
| 131 | /***************************************************************************** |
| 132 | INLINE FUNCTIONS |
| 133 | *****************************************************************************/ |
| 134 | |
| 135 | INLINE smsvdp_t *get_safe_token(const device_config *device) |
| 118 | 136 | { |
| 119 | | const device_config *screen = video_screen_first(machine->config); |
| 137 | assert(device != NULL); |
| 138 | assert(device->token != NULL); |
| 139 | assert(device->type == SMSVDP); |
| 140 | |
| 141 | return (smsvdp_t *)device->token; |
| 142 | } |
| 143 | |
| 144 | INLINE const smsvdp_interface *get_interface(const device_config *device) |
| 145 | { |
| 146 | assert(device != NULL); |
| 147 | assert((device->type == SMSVDP)); |
| 148 | return (const smsvdp_interface *) device->static_config; |
| 149 | } |
| 150 | |
| 151 | /************************************* |
| 152 | * |
| 153 | * Utilities |
| 154 | * |
| 155 | *************************************/ |
| 156 | |
| 157 | static void set_display_settings( const device_config *device ) |
| 158 | { |
| 159 | smsvdp_t *smsvdp = get_safe_token(device); |
| 160 | |
| 161 | const device_config *screen = video_screen_first(device->machine->config); |
| 120 | 162 | int height = video_screen_get_height(screen); |
| 121 | 163 | int M1, M2, M3, M4; |
| 122 | | M1 = smsvdp.reg[0x01] & 0x10; |
| 123 | | M2 = smsvdp.reg[0x00] & 0x02; |
| 124 | | M3 = smsvdp.reg[0x01] & 0x08; |
| 125 | | M4 = smsvdp.reg[0x00] & 0x04; |
| 126 | | smsvdp.y_pixels = 192; |
| 127 | | if ( M4 ) |
| 164 | M1 = smsvdp->reg[0x01] & 0x10; |
| 165 | M2 = smsvdp->reg[0x00] & 0x02; |
| 166 | M3 = smsvdp->reg[0x01] & 0x08; |
| 167 | M4 = smsvdp->reg[0x00] & 0x04; |
| 168 | smsvdp->y_pixels = 192; |
| 169 | if (M4) |
| 128 | 170 | { |
| 129 | 171 | /* mode 4 */ |
| 130 | | smsvdp.vdp_mode = 4; |
| 131 | | if ( M2 && ( IS_SMS2_VDP || IS_GAMEGEAR_VDP ) ) |
| 172 | smsvdp->vdp_mode = 4; |
| 173 | if (M2 && (IS_SMS2_VDP || IS_GAMEGEAR_VDP)) |
| 132 | 174 | { |
| 133 | | /* Is it 224-line display */ |
| 134 | | if ( M1 && ! M3 ) |
| 135 | | { |
| 136 | | smsvdp.y_pixels = 224; |
| 137 | | } |
| 138 | | else if ( ! M1 && M3 ) |
| 139 | | { |
| 140 | | /* 240-line display */ |
| 141 | | smsvdp.y_pixels = 240; |
| 142 | | } |
| 175 | if (M1 && !M3) |
| 176 | smsvdp->y_pixels = 224; /* 224-line display */ |
| 177 | else if (!M1 && M3) |
| 178 | smsvdp->y_pixels = 240; /* 240-line display */ |
| 143 | 179 | } |
| 144 | 180 | } |
| 145 | 181 | else |
| 146 | 182 | { |
| 147 | 183 | /* original TMS9918 mode */ |
| 148 | | if ( ! M1 && ! M2 && ! M3 ) |
| 184 | if (!M1 && !M2 && !M3) |
| 149 | 185 | { |
| 150 | | smsvdp.vdp_mode = 0; |
| 186 | smsvdp->vdp_mode = 0; |
| 151 | 187 | } |
| 152 | 188 | else |
| 153 | | // if ( M1 && ! M2 && ! M3 ) |
| 189 | // if (M1 && !M2 && !M3) |
| 154 | 190 | // { |
| 155 | | // smsvdp.vdp_mode = 1; |
| 191 | // smsvdp->vdp_mode = 1; |
| 156 | 192 | // } |
| 157 | 193 | // else |
| 158 | | if ( ! M1 && M2 && ! M3 ) |
| 194 | if (!M1 && M2 && !M3) |
| 159 | 195 | { |
| 160 | | smsvdp.vdp_mode = 2; |
| 196 | smsvdp->vdp_mode = 2; |
| 161 | 197 | // } |
| 162 | 198 | // else |
| 163 | | // if ( ! M1 && ! M2 && M3 ) |
| 199 | // if (!M1 && !M2 && M3) |
| 164 | 200 | // { |
| 165 | | // smsvdp.vdp_mode = 3; |
| 201 | // smsvdp->vdp_mode = 3; |
| 166 | 202 | } |
| 167 | 203 | else |
| 168 | 204 | { |
| 169 | | logerror( "Unknown video mode detected (M1=%c, M2=%c, M3=%c, M4=%c)\n", M1 ? '1' : '0', M2 ? '1' : '0', M3 ? '1' : '0', M4 ? '1' : '0'); |
| 205 | logerror("Unknown video mode detected (M1 = %c, M2 = %c, M3 = %c, M4 = %c)\n", M1 ? '1' : '0', M2 ? '1' : '0', M3 ? '1' : '0', M4 ? '1' : '0'); |
| 170 | 206 | } |
| 171 | 207 | } |
| 172 | 208 | |
| 173 | | switch( smsvdp.y_pixels ) |
| 209 | switch (smsvdp->y_pixels) |
| 174 | 210 | { |
| 175 | 211 | case 192: |
| 176 | | smsvdp.sms_frame_timing = ( height == PAL_Y_PIXELS ) ? sms_pal_192 : sms_ntsc_192; |
| 212 | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_192 : sms_ntsc_192; |
| 177 | 213 | break; |
| 178 | 214 | |
| 179 | 215 | case 224: |
| 180 | | smsvdp.sms_frame_timing = ( height == PAL_Y_PIXELS ) ? sms_pal_224 : sms_ntsc_224; |
| 216 | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_224 : sms_ntsc_224; |
| 181 | 217 | break; |
| 182 | 218 | |
| 183 | 219 | case 240: |
| 184 | | smsvdp.sms_frame_timing = ( height == PAL_Y_PIXELS ) ? sms_pal_240 : sms_ntsc_240; |
| 220 | smsvdp->sms_frame_timing = (height == PAL_Y_PIXELS) ? sms_pal_240 : sms_ntsc_240; |
| 185 | 221 | break; |
| 186 | 222 | } |
| 187 | | smsvdp.cram_dirty = 1; |
| 223 | smsvdp->cram_dirty = 1; |
| 188 | 224 | } |
| 189 | 225 | |
| 190 | 226 | |
| 191 | | READ8_HANDLER(sms_vdp_vcount_r) |
| 227 | READ8_DEVICE_HANDLER( sms_vdp_vcount_r ) |
| 192 | 228 | { |
| 193 | | return ( smsvdp.sms_frame_timing[ INIT_VCOUNT ] + video_screen_get_vpos(space->machine->primary_screen) ) & 0xFF; |
| 229 | smsvdp_t *smsvdp = get_safe_token(device); |
| 230 | |
| 231 | return (smsvdp->sms_frame_timing[INIT_VCOUNT] + video_screen_get_vpos(device->machine->primary_screen)) & 0xff; |
| 194 | 232 | } |
| 195 | 233 | |
| 196 | 234 | |
| 197 | | READ8_HANDLER(sms_vdp_hcount_r) |
| 235 | READ8_DEVICE_HANDLER( sms_vdp_hcount_latch_r ) |
| 198 | 236 | { |
| 199 | | return video_screen_get_hpos(space->machine->primary_screen) >> 1; |
| 237 | smsvdp_t *smsvdp = get_safe_token(device); |
| 238 | |
| 239 | return smsvdp->hcounter; |
| 200 | 240 | } |
| 201 | 241 | |
| 202 | | |
| 203 | | void sms_set_ggsmsmode( int mode ) |
| 242 | WRITE8_DEVICE_HANDLER( sms_vdp_hcount_latch_w ) |
| 204 | 243 | { |
| 205 | | smsvdp.gg_sms_mode = mode; |
| 244 | smsvdp_t *smsvdp = get_safe_token(device); |
| 245 | |
| 246 | smsvdp->hcounter = data; |
| 206 | 247 | } |
| 207 | 248 | |
| 208 | 249 | |
| 209 | | int smsvdp_video_init( running_machine *machine, const smsvdp_configuration *config ) |
| 250 | void sms_set_ggsmsmode( const device_config *device, int mode ) |
| 210 | 251 | { |
| 211 | | const device_config *screen = video_screen_first(machine->config); |
| 212 | | int width = video_screen_get_width(screen); |
| 213 | | int height = video_screen_get_height(screen); |
| 252 | smsvdp_t *smsvdp = get_safe_token(device); |
| 214 | 253 | |
| 215 | | memset( &smsvdp, 0, sizeof smsvdp ); |
| 254 | smsvdp->gg_sms_mode = mode; |
| 255 | smsvdp->cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 256 | } |
| 216 | 257 | |
| 217 | | smsvdp.features = config->model; |
| 218 | | smsvdp.int_callback = config->int_callback; |
| 219 | 258 | |
| 220 | | /* Allocate video RAM |
| 221 | | In theory the driver could have a "gfx1" and/or "gfx2" memory region |
| 222 | | of it's own. So this code could potentially cause a clash. |
| 223 | | */ |
| 224 | | smsvdp.VRAM = memory_region_alloc( machine, "gfx1", VRAM_SIZE, ROM_REQUIRED ); |
| 225 | | smsvdp.CRAM = memory_region_alloc( machine, "gfx2", MAX_CRAM_SIZE, ROM_REQUIRED ); |
| 226 | | smsvdp.line_buffer = auto_alloc_array(machine, int, 256 * 5); |
| 227 | | memset( smsvdp.line_buffer, 0, 256 * 5 * sizeof(int) ); |
| 259 | static TIMER_CALLBACK( smsvdp_set_irq ) |
| 260 | { |
| 261 | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 228 | 262 | |
| 229 | | /* Clear RAM */ |
| 230 | | smsvdp.cram_dirty = 1; |
| 231 | | memset(smsvdp.VRAM, 0, VRAM_SIZE); |
| 232 | | memset(smsvdp.CRAM, 0, MAX_CRAM_SIZE); |
| 233 | | smsvdp.reg[0x02] = 0x0E; /* power up default */ |
| 234 | | smsvdp.reg[0x0a] = 0xff; |
| 263 | smsvdp->irq_state = 1; |
| 235 | 264 | |
| 236 | | smsvdp.cram_mask = ( IS_GAMEGEAR_VDP && ! smsvdp.gg_sms_mode ) ? ( GG_CRAM_SIZE - 1 ) : ( SMS_CRAM_SIZE - 1 ); |
| 237 | | |
| 238 | | smsvdp.collision_buffer = auto_alloc_array(machine, UINT8, SMS_X_PIXELS); |
| 239 | | |
| 240 | | /* Make temp bitmap for rendering */ |
| 241 | | tmpbitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 242 | | |
| 243 | | smsvdp.prev_bitmap = auto_bitmap_alloc(machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 244 | | |
| 245 | | set_display_settings( machine ); |
| 246 | | |
| 247 | | smsvdp.smsvdp_display_timer = timer_alloc(machine, smsvdp_display_callback , NULL); |
| 248 | | timer_adjust_periodic(smsvdp.smsvdp_display_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0 ), 0, video_screen_get_scan_period( machine->primary_screen )); |
| 249 | | return 0; |
| 265 | if (smsvdp->int_callback) |
| 266 | smsvdp->int_callback(machine, ASSERT_LINE); |
| 250 | 267 | } |
| 251 | 268 | |
| 252 | 269 | |
| 253 | | static TIMER_CALLBACK(smsvdp_set_irq) |
| 270 | static TIMER_CALLBACK( smsvdp_display_callback ) |
| 254 | 271 | { |
| 255 | | smsvdp.irq_state = 1; |
| 256 | | if ( smsvdp.int_callback ) |
| 257 | | { |
| 258 | | smsvdp.int_callback( machine, ASSERT_LINE ); |
| 259 | | } |
| 260 | | } |
| 272 | smsvdp_t *smsvdp = (smsvdp_t *) ptr; |
| 261 | 273 | |
| 262 | | |
| 263 | | static TIMER_CALLBACK(smsvdp_display_callback) |
| 264 | | { |
| 265 | 274 | rectangle rec; |
| 266 | 275 | int vpos = video_screen_get_vpos(machine->primary_screen); |
| 267 | | int vpos_limit = smsvdp.sms_frame_timing[VERTICAL_BLANKING] + smsvdp.sms_frame_timing[TOP_BLANKING] |
| 268 | | + smsvdp.sms_frame_timing[TOP_BORDER] + smsvdp.sms_frame_timing[ACTIVE_DISPLAY_V] |
| 269 | | + smsvdp.sms_frame_timing[BOTTOM_BORDER] + smsvdp.sms_frame_timing[BOTTOM_BLANKING]; |
| 276 | int vpos_limit = smsvdp->sms_frame_timing[VERTICAL_BLANKING] + smsvdp->sms_frame_timing[TOP_BLANKING] |
| 277 | + smsvdp->sms_frame_timing[TOP_BORDER] + smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V] |
| 278 | + smsvdp->sms_frame_timing[BOTTOM_BORDER] + smsvdp->sms_frame_timing[BOTTOM_BLANKING]; |
| 270 | 279 | |
| 271 | 280 | rec.min_y = rec.max_y = vpos; |
| 272 | 281 | |
| 273 | 282 | /* Check if we're on the last line of a frame */ |
| 274 | | if ( vpos == vpos_limit - 1 ) |
| 283 | if (vpos == vpos_limit - 1) |
| 275 | 284 | { |
| 276 | | sms_check_pause_button( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM) ); |
| 285 | if (smsvdp->pause_callback) |
| 286 | smsvdp->pause_callback(machine); |
| 287 | // sms_check_pause_button(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM)); |
| 277 | 288 | return; |
| 278 | 289 | } |
| 279 | 290 | |
| 280 | | vpos_limit -= smsvdp.sms_frame_timing[BOTTOM_BLANKING]; |
| 291 | vpos_limit -= smsvdp->sms_frame_timing[BOTTOM_BLANKING]; |
| 281 | 292 | |
| 282 | 293 | /* Check if we're below the bottom border */ |
| 283 | | if ( vpos >= vpos_limit ) |
| 294 | if (vpos >= vpos_limit) |
| 284 | 295 | { |
| 285 | 296 | return; |
| 286 | 297 | } |
| 287 | 298 | |
| 288 | | vpos_limit -= smsvdp.sms_frame_timing[BOTTOM_BORDER]; |
| 299 | vpos_limit -= smsvdp->sms_frame_timing[BOTTOM_BORDER]; |
| 289 | 300 | |
| 290 | 301 | /* Check if we're in the bottom border area */ |
| 291 | | if ( vpos >= vpos_limit ) |
| 302 | if (vpos >= vpos_limit) |
| 292 | 303 | { |
| 293 | | if ( vpos == vpos_limit ) |
| 304 | if (vpos == vpos_limit) |
| 294 | 305 | { |
| 295 | | if ( smsvdp.line_counter == 0x00 ) |
| 306 | if (smsvdp->line_counter == 0x00) |
| 296 | 307 | { |
| 297 | | smsvdp.line_counter = smsvdp.reg[0x0A]; |
| 298 | | smsvdp.status |= STATUS_HINT; |
| 308 | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 309 | smsvdp->status |= STATUS_HINT; |
| 299 | 310 | |
| 300 | | if ( smsvdp.reg[0x00] & 0x10 ) |
| 311 | if (smsvdp->reg[0x00] & 0x10) |
| 301 | 312 | { |
| 302 | 313 | /* Delay triggering of interrupt to allow software to read the status bit before the irq */ |
| 303 | | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1 ), NULL, 0, smsvdp_set_irq ); |
| 314 | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1), smsvdp, 0, smsvdp_set_irq); |
| 304 | 315 | } |
| 305 | 316 | } |
| 306 | 317 | |
| 307 | 318 | } |
| 308 | 319 | |
| 309 | | if ( vpos == vpos_limit + 1 ) |
| 320 | if (vpos == vpos_limit + 1) |
| 310 | 321 | { |
| 311 | | smsvdp.status |= STATUS_VINT; |
| 322 | smsvdp->status |= STATUS_VINT; |
| 312 | 323 | |
| 313 | | if ( smsvdp.reg[0x01] & 0x20 ) |
| 324 | if (smsvdp->reg[0x01] & 0x20) |
| 314 | 325 | { |
| 315 | 326 | /* Delay triggering of interrupt to allow software to read the status bit before the irq */ |
| 316 | | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1 ), NULL, 0, smsvdp_set_irq ); |
| 327 | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1), smsvdp, 0, smsvdp_set_irq); |
| 317 | 328 | } |
| 318 | 329 | } |
| 319 | 330 | |
| 320 | | sms_update_palette(); |
| 331 | sms_update_palette(smsvdp); |
| 321 | 332 | |
| 322 | 333 | /* Draw left border */ |
| 323 | 334 | rec.min_x = LBORDER_START; |
| 324 | 335 | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 325 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 336 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 326 | 337 | |
| 327 | 338 | /* Draw right border */ |
| 328 | 339 | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 329 | 340 | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 330 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 341 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 331 | 342 | |
| 332 | 343 | /* Draw middle of the border */ |
| 333 | 344 | /* We need to do this through the regular drawing function so it will */ |
| 334 | 345 | /* be included in the gamegear scaling functions */ |
| 335 | | sms_refresh_line( machine, tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit - smsvdp.sms_frame_timing[ACTIVE_DISPLAY_V], vpos - ( vpos_limit - smsvdp.sms_frame_timing[ACTIVE_DISPLAY_V] ) ); |
| 346 | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit - smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V], vpos - (vpos_limit - smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V])); |
| 336 | 347 | return; |
| 337 | 348 | } |
| 338 | 349 | |
| 339 | | vpos_limit -= smsvdp.sms_frame_timing[ACTIVE_DISPLAY_V]; |
| 350 | vpos_limit -= smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]; |
| 340 | 351 | |
| 341 | 352 | /* Check if we're in the active display area */ |
| 342 | | if ( vpos >= vpos_limit ) |
| 353 | if (vpos >= vpos_limit) |
| 343 | 354 | { |
| 344 | | if ( vpos == vpos_limit ) |
| 355 | if (vpos == vpos_limit) |
| 345 | 356 | { |
| 346 | | smsvdp.line_counter = smsvdp.reg[0x0A]; |
| 347 | | smsvdp.reg9copy = smsvdp.reg[0x09]; |
| 357 | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 358 | smsvdp->reg9copy = smsvdp->reg[0x09]; |
| 348 | 359 | } |
| 349 | 360 | |
| 350 | | if ( smsvdp.line_counter == 0x00 ) |
| 361 | if (smsvdp->line_counter == 0x00) |
| 351 | 362 | { |
| 352 | | smsvdp.line_counter = smsvdp.reg[0x0A]; |
| 353 | | smsvdp.status |= STATUS_HINT; |
| 363 | smsvdp->line_counter = smsvdp->reg[0x0a]; |
| 364 | smsvdp->status |= STATUS_HINT; |
| 354 | 365 | |
| 355 | | if ( smsvdp.reg[0x00] & 0x10 ) |
| 366 | if (smsvdp->reg[0x00] & 0x10) |
| 356 | 367 | { |
| 357 | 368 | /* Delay triggering of interrupt to allow software to read the status bit before the irq */ |
| 358 | | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1 ), NULL, 0, smsvdp_set_irq ); |
| 369 | timer_set(machine, video_screen_get_time_until_pos(machine->primary_screen, video_screen_get_vpos(machine->primary_screen), video_screen_get_hpos(machine->primary_screen) + 1), smsvdp, 0, smsvdp_set_irq); |
| 359 | 370 | } |
| 360 | 371 | } |
| 361 | 372 | else |
| 362 | 373 | { |
| 363 | | smsvdp.line_counter -= 1; |
| 374 | smsvdp->line_counter -= 1; |
| 364 | 375 | } |
| 365 | 376 | |
| 366 | | sms_update_palette(); |
| 377 | sms_update_palette(smsvdp); |
| 367 | 378 | |
| 368 | 379 | /* Check if display is disabled */ |
| 369 | | if ( ! ( smsvdp.reg[0x01] & 0x40 ) ) |
| 380 | if (!(smsvdp->reg[0x01] & 0x40)) |
| 370 | 381 | { |
| 371 | 382 | /* set whole line to backdrop color */ |
| 372 | 383 | rec.min_x = LBORDER_START; |
| 373 | 384 | rec.max_x = LBORDER_START + LBORDER_X_PIXELS + 255 + RBORDER_X_PIXELS; |
| 374 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 385 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 375 | 386 | } |
| 376 | 387 | else |
| 377 | 388 | { |
| 378 | 389 | /* Draw left border */ |
| 379 | 390 | rec.min_x = LBORDER_START; |
| 380 | 391 | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 381 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 392 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 382 | 393 | |
| 383 | 394 | /* Draw right border */ |
| 384 | 395 | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 385 | 396 | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 386 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 387 | | sms_refresh_line( machine, tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit ); |
| 397 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 398 | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit, vpos - vpos_limit); |
| 388 | 399 | } |
| 389 | 400 | return; |
| 390 | 401 | } |
| 391 | 402 | |
| 392 | | vpos_limit -= smsvdp.sms_frame_timing[TOP_BORDER]; |
| 403 | vpos_limit -= smsvdp->sms_frame_timing[TOP_BORDER]; |
| 393 | 404 | |
| 394 | 405 | /* Check if we're in the top border area */ |
| 395 | | if ( vpos >= vpos_limit ) |
| 406 | if (vpos >= vpos_limit) |
| 396 | 407 | { |
| 397 | | sms_update_palette(); |
| 408 | sms_update_palette(smsvdp); |
| 398 | 409 | |
| 399 | 410 | /* Draw left border */ |
| 400 | 411 | rec.min_x = LBORDER_START; |
| 401 | 412 | rec.max_x = LBORDER_START + LBORDER_X_PIXELS - 1; |
| 402 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 413 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 403 | 414 | |
| 404 | 415 | /* Draw right border */ |
| 405 | 416 | rec.min_x = LBORDER_START + LBORDER_X_PIXELS + 256; |
| 406 | 417 | rec.max_x = rec.min_x + RBORDER_X_PIXELS - 1; |
| 407 | | bitmap_fill( tmpbitmap, &rec , machine->pens[smsvdp.current_palette[BACKDROP_COLOR]]); |
| 418 | bitmap_fill(smsvdp->tmpbitmap, &rec, machine->pens[smsvdp->current_palette[BACKDROP_COLOR]]); |
| 408 | 419 | |
| 409 | 420 | /* Draw middle of the border */ |
| 410 | 421 | /* We need to do this through the regular drawing function so it will */ |
| 411 | 422 | /* be included in the gamegear scaling functions */ |
| 412 | | sms_refresh_line( machine, tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit + smsvdp.sms_frame_timing[TOP_BORDER], vpos - ( vpos_limit + smsvdp.sms_frame_timing[TOP_BORDER] ) ); |
| 423 | sms_refresh_line(machine, smsvdp, smsvdp->tmpbitmap, LBORDER_START + LBORDER_X_PIXELS, vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER], vpos - (vpos_limit + smsvdp->sms_frame_timing[TOP_BORDER])); |
| 413 | 424 | return; |
| 414 | 425 | } |
| 415 | 426 | } |
| 416 | 427 | |
| 417 | 428 | |
| 418 | | READ8_HANDLER(sms_vdp_data_r) |
| 429 | READ8_DEVICE_HANDLER( sms_vdp_data_r ) |
| 419 | 430 | { |
| 431 | smsvdp_t *smsvdp = get_safe_token(device); |
| 420 | 432 | UINT8 temp; |
| 421 | 433 | |
| 422 | 434 | /* SMS 2 & GG behaviour. Seems like the latched data is passed straight through */ |
| 423 | 435 | /* to the address register when in the middle of doing a command. */ |
| 424 | 436 | /* Cosmic Spacehead needs this, among others */ |
| 425 | 437 | /* Clear pending write flag */ |
| 426 | | smsvdp.pending = 0; |
| 438 | smsvdp->pending = 0; |
| 427 | 439 | |
| 428 | 440 | /* Return read buffer contents */ |
| 429 | | temp = smsvdp.buffer; |
| 441 | temp = smsvdp->buffer; |
| 430 | 442 | |
| 431 | 443 | /* Load read buffer */ |
| 432 | | smsvdp.buffer = smsvdp.VRAM[(smsvdp.addr & 0x3FFF)]; |
| 444 | smsvdp->buffer = smsvdp->VRAM[(smsvdp->addr & 0x3fff)]; |
| 433 | 445 | |
| 434 | 446 | /* Bump internal address register */ |
| 435 | | smsvdp.addr += 1; |
| 436 | | return (temp); |
| 447 | smsvdp->addr += 1; |
| 448 | return temp; |
| 437 | 449 | } |
| 438 | 450 | |
| 439 | 451 | |
| 440 | | READ8_HANDLER(sms_vdp_ctrl_r) |
| 452 | READ8_DEVICE_HANDLER( sms_vdp_ctrl_r ) |
| 441 | 453 | { |
| 442 | | UINT8 temp = smsvdp.status; |
| 454 | smsvdp_t *smsvdp = get_safe_token(device); |
| 443 | 455 | |
| 456 | UINT8 temp = smsvdp->status; |
| 457 | |
| 444 | 458 | /* Clear pending write flag */ |
| 445 | | smsvdp.pending = 0; |
| 459 | smsvdp->pending = 0; |
| 446 | 460 | |
| 447 | | smsvdp.status &= ~( STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT ); |
| 461 | smsvdp->status &= ~(STATUS_VINT | STATUS_SPROVR | STATUS_SPRCOL | STATUS_HINT); |
| 448 | 462 | |
| 449 | | if (smsvdp.irq_state == 1) |
| 463 | if (smsvdp->irq_state == 1) |
| 450 | 464 | { |
| 451 | | smsvdp.irq_state = 0; |
| 465 | smsvdp->irq_state = 0; |
| 452 | 466 | |
| 453 | | if ( smsvdp.int_callback ) |
| 454 | | { |
| 455 | | smsvdp.int_callback( space->machine, CLEAR_LINE ); |
| 456 | | } |
| 467 | if (smsvdp->int_callback) |
| 468 | smsvdp->int_callback(device->machine, CLEAR_LINE); |
| 457 | 469 | } |
| 458 | | |
| 459 | | return (temp); |
| 470 | return temp; |
| 460 | 471 | } |
| 461 | 472 | |
| 462 | 473 | |
| 463 | | WRITE8_HANDLER(sms_vdp_data_w) |
| 474 | WRITE8_DEVICE_HANDLER( sms_vdp_data_w ) |
| 464 | 475 | { |
| 476 | smsvdp_t *smsvdp = get_safe_token(device); |
| 477 | int address; |
| 478 | |
| 465 | 479 | /* SMS 2 & GG behaviour. Seems like the latched data is passed straight through */ |
| 466 | 480 | /* to the address register when in the middle of doing a command. */ |
| 467 | 481 | /* Cosmic Spacehead needs this, among others */ |
| 468 | 482 | /* Clear pending write flag */ |
| 469 | | smsvdp.pending = 0; |
| 483 | smsvdp->pending = 0; |
| 470 | 484 | |
| 471 | | switch(smsvdp.addrmode) |
| 485 | switch(smsvdp->addrmode) |
| 472 | 486 | { |
| 473 | 487 | case 0x00: |
| 474 | 488 | case 0x01: |
| 475 | 489 | case 0x02: |
| 476 | | { |
| 477 | | int address = (smsvdp.addr & 0x3FFF); |
| 478 | | |
| 479 | | smsvdp.VRAM[address] = data; |
| 480 | | } |
| 490 | address = (smsvdp->addr & 0x3fff); |
| 491 | smsvdp->VRAM[address] = data; |
| 481 | 492 | break; |
| 482 | 493 | |
| 483 | 494 | case 0x03: |
| 495 | address = smsvdp->addr & smsvdp->cram_mask; |
| 496 | if (data != smsvdp->CRAM[address]) |
| 484 | 497 | { |
| 485 | | int address = smsvdp.addr & smsvdp.cram_mask; |
| 486 | | |
| 487 | | if (data != smsvdp.CRAM[address]) |
| 488 | | { |
| 489 | | smsvdp.CRAM[address] = data; |
| 490 | | smsvdp.cram_dirty = 1; |
| 491 | | } |
| 498 | smsvdp->CRAM[address] = data; |
| 499 | smsvdp->cram_dirty = 1; |
| 492 | 500 | } |
| 493 | 501 | break; |
| 494 | 502 | } |
| 495 | 503 | |
| 496 | | smsvdp.buffer = data; |
| 497 | | smsvdp.addr += 1; |
| 504 | smsvdp->buffer = data; |
| 505 | smsvdp->addr += 1; |
| 498 | 506 | } |
| 499 | 507 | |
| 500 | 508 | |
| 501 | | WRITE8_HANDLER(sms_vdp_ctrl_w) |
| 509 | WRITE8_DEVICE_HANDLER( sms_vdp_ctrl_w ) |
| 502 | 510 | { |
| 503 | | int regNum; |
| 511 | smsvdp_t *smsvdp = get_safe_token(device); |
| 504 | 512 | |
| 505 | | if (smsvdp.pending == 0) |
| 513 | int reg_num; |
| 514 | |
| 515 | if (smsvdp->pending == 0) |
| 506 | 516 | { |
| 507 | | smsvdp.addr = ( smsvdp.addr & 0xff00 ) | data; |
| 508 | | smsvdp.pending = 1; |
| 517 | smsvdp->addr = (smsvdp->addr & 0xff00) | data; |
| 518 | smsvdp->pending = 1; |
| 509 | 519 | } |
| 510 | 520 | else |
| 511 | 521 | { |
| 512 | 522 | /* Clear pending write flag */ |
| 513 | | smsvdp.pending = 0; |
| 523 | smsvdp->pending = 0; |
| 514 | 524 | |
| 515 | | smsvdp.addrmode = (data >> 6) & 0x03; |
| 516 | | smsvdp.addr = ( data << 8 ) | ( smsvdp.addr & 0xff ); |
| 517 | | switch( smsvdp.addrmode ) |
| 525 | smsvdp->addrmode = (data >> 6) & 0x03; |
| 526 | smsvdp->addr = (data << 8) | (smsvdp->addr & 0xff); |
| 527 | switch (smsvdp->addrmode) |
| 518 | 528 | { |
| 519 | 529 | case 0: /* VRAM reading mode */ |
| 520 | | smsvdp.buffer = smsvdp.VRAM[ smsvdp.addr & 0x3FFF ]; |
| 521 | | smsvdp.addr += 1; |
| 530 | smsvdp->buffer = smsvdp->VRAM[smsvdp->addr & 0x3fff]; |
| 531 | smsvdp->addr += 1; |
| 522 | 532 | break; |
| 523 | 533 | |
| 524 | 534 | case 1: /* VRAM writing mode */ |
| 525 | 535 | break; |
| 526 | 536 | |
| 527 | 537 | case 2: /* VDP register write */ |
| 528 | | regNum = data & 0x0F; |
| 529 | | smsvdp.reg[regNum] = smsvdp.addr & 0xff; |
| 530 | | if (regNum == 0 && smsvdp.addr & 0x02) |
| 531 | | { |
| 538 | reg_num = data & 0x0f; |
| 539 | smsvdp->reg[reg_num] = smsvdp->addr & 0xff; |
| 540 | if (reg_num == 0 && smsvdp->addr & 0x02) |
| 532 | 541 | logerror("overscan enabled.\n"); |
| 533 | | } |
| 534 | | if ( regNum == 0 || regNum == 1 ) |
| 542 | |
| 543 | if (reg_num == 0 || reg_num == 1) |
| 544 | set_display_settings(device); |
| 545 | |
| 546 | if ((reg_num == 1) && (smsvdp->reg[0x01] & 0x20) && (smsvdp->status & STATUS_VINT)) |
| 535 | 547 | { |
| 536 | | set_display_settings( space->machine ); |
| 548 | smsvdp->irq_state = 1; |
| 549 | |
| 550 | if (smsvdp->int_callback) |
| 551 | smsvdp->int_callback(device->machine, ASSERT_LINE); |
| 537 | 552 | } |
| 538 | | if ( ( regNum == 1 ) && ( smsvdp.reg[0x01] & 0x20 ) && ( smsvdp.status & STATUS_VINT ) ) |
| 539 | | { |
| 540 | | smsvdp.irq_state = 1; |
| 541 | | smsvdp.int_callback( space->machine, ASSERT_LINE ); |
| 542 | | } |
| 543 | | smsvdp.addrmode = 0; |
| 553 | smsvdp->addrmode = 0; |
| 544 | 554 | break; |
| 545 | 555 | |
| 546 | 556 | case 3: /* CRAM writing mode */ |
| r6078 | r6079 | |
| 550 | 560 | } |
| 551 | 561 | |
| 552 | 562 | |
| 553 | | static void sms_refresh_line_mode4(int *lineBuffer, int line) |
| 563 | static void sms_refresh_line_mode4( smsvdp_t *smsvdp, int *line_buffer, int line ) |
| 554 | 564 | { |
| 555 | | int tileColumn; |
| 556 | | int xScroll, yScroll, xScrollStartColumn; |
| 557 | | int spriteIndex; |
| 558 | | int pixelX, pixelPlotX, prioritySelected[256]; |
| 559 | | int spriteX, spriteY, spriteLine, spriteTileSelected, spriteHeight, spriteZoom; |
| 560 | | int spriteBuffer[8], spriteBufferCount, spriteBufferIndex; |
| 561 | | int bitPlane0, bitPlane1, bitPlane2, bitPlane3; |
| 565 | int tile_column; |
| 566 | int x_scroll, y_scroll, x_scroll_start_column; |
| 567 | int sprite_index; |
| 568 | int pixel_x, pixel_plot_x, priority_selected[256]; |
| 569 | int sprite_x, sprite_y, sprite_line, sprite_tile_selected, sprite_height, sprite_zoom; |
| 570 | int sprite_buffer[8], sprite_buffer_count, sprite_buffer_index; |
| 571 | int bit_plane_0, bit_plane_1, bit_plane_2, bit_plane_3; |
| 562 | 572 | int scroll_mod; |
| 563 | | UINT16 nameTableAddress; |
| 564 | | UINT8 *nameTable; |
| 565 | | UINT8 *spriteTable = smsvdp.VRAM + ( (smsvdp.reg[0x05] << 7) & 0x3F00 ); |
| 573 | UINT16 name_table_address; |
| 574 | UINT8 *name_table; |
| 575 | UINT8 *sprite_table = smsvdp->VRAM + ((smsvdp->reg[0x05] << 7) & 0x3f00); |
| 566 | 576 | |
| 567 | | if ( smsvdp.y_pixels != 192 ) |
| 577 | if (smsvdp->y_pixels != 192) |
| 568 | 578 | { |
| 569 | | nameTableAddress = ((smsvdp.reg[0x02] & 0x0C) << 10) | 0x0700; |
| 579 | name_table_address = ((smsvdp->reg[0x02] & 0x0c) << 10) | 0x0700; |
| 570 | 580 | scroll_mod = 256; |
| 571 | 581 | } |
| 572 | 582 | else |
| 573 | 583 | { |
| 574 | | nameTableAddress = (smsvdp.reg[0x02] << 10) & 0x3800; |
| 584 | name_table_address = (smsvdp->reg[0x02] << 10) & 0x3800; |
| 575 | 585 | scroll_mod = 224; |
| 576 | 586 | } |
| 577 | 587 | |
| 578 | | if ( IS_SMS1_VDP ) |
| 579 | | { |
| 580 | | nameTableAddress = nameTableAddress & (((smsvdp.reg[0x02] & 0x01) << 10) | 0x3BFF); |
| 581 | | } |
| 588 | if (IS_SMS1_VDP) |
| 589 | name_table_address = name_table_address & (((smsvdp->reg[0x02] & 0x01) << 10) | 0x3bff); |
| 582 | 590 | |
| 583 | | /* if top 2 rows of screen not affected by horizontal scrolling, then xScroll = 0 */ |
| 584 | | /* else xScroll = reg[0x08] */ |
| 585 | | xScroll = (((smsvdp.reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - smsvdp.reg[0x08]); |
| 591 | /* if top 2 rows of screen not affected by horizontal scrolling, then x_scroll = 0 */ |
| 592 | /* else x_scroll = reg[0x08] */ |
| 593 | x_scroll = (((smsvdp->reg[0x00] & 0x40) && (line < 16)) ? 0 : 0x0100 - smsvdp->reg[0x08]); |
| 586 | 594 | |
| 587 | | xScrollStartColumn = (xScroll >> 3); /* x starting column tile */ |
| 595 | x_scroll_start_column = (x_scroll >> 3); /* x starting column tile */ |
| 588 | 596 | |
| 589 | 597 | /* Draw background layer */ |
| 590 | | for (tileColumn = 0; tileColumn < 33; tileColumn++) |
| 598 | for (tile_column = 0; tile_column < 33; tile_column++) |
| 591 | 599 | { |
| 592 | | UINT16 tileData; |
| 593 | | int tileSelected, palletteSelected, horizSelected, vertSelected, prioritySelect; |
| 594 | | int tileLine; |
| 600 | UINT16 tile_data; |
| 601 | int tile_selected, palette_selected, horiz_selected, vert_selected, priority_select; |
| 602 | int tile_line; |
| 595 | 603 | |
| 596 | 604 | /* Rightmost 8 columns for SMS (or 2 columns for GG) not affected by */ |
| 597 | 605 | /* vertical scrolling when bit 7 of reg[0x00] is set */ |
| 598 | | yScroll = ((smsvdp.reg[0x00] & 0x80) && (tileColumn > 23)) ? 0 : smsvdp.reg9copy; |
| 606 | y_scroll = ((smsvdp->reg[0x00] & 0x80) && (tile_column > 23)) ? 0 : smsvdp->reg9copy; |
| 599 | 607 | |
| 600 | | nameTable = smsvdp.VRAM + nameTableAddress + ((((line + yScroll) % scroll_mod) >> 3) << 6); |
| 608 | name_table = smsvdp->VRAM + name_table_address + ((((line + y_scroll) % scroll_mod) >> 3) << 6); |
| 601 | 609 | |
| 602 | | tileLine = ( ( tileColumn + xScrollStartColumn ) & 0x1F ) * 2; |
| 603 | | tileData = nameTable[ tileLine ] | ( nameTable[ tileLine + 1 ] << 8 ); |
| 610 | tile_line = ((tile_column + x_scroll_start_column) & 0x1f) * 2; |
| 611 | tile_data = name_table[tile_line] | (name_table[tile_line + 1] << 8); |
| 604 | 612 | |
| 605 | | tileSelected = (tileData & 0x01FF); |
| 606 | | prioritySelect = tileData & PRIORITY_BIT; |
| 607 | | palletteSelected = (tileData >> 11) & 0x01; |
| 608 | | vertSelected = (tileData >> 10) & 0x01; |
| 609 | | horizSelected = (tileData >> 9) & 0x01; |
| 613 | tile_selected = (tile_data & 0x01ff); |
| 614 | priority_select = tile_data & PRIORITY_BIT; |
| 615 | palette_selected = (tile_data >> 11) & 0x01; |
| 616 | vert_selected = (tile_data >> 10) & 0x01; |
| 617 | horiz_selected = (tile_data >> 9) & 0x01; |
| 610 | 618 | |
| 611 | | tileLine = line - ((0x07 - (yScroll & 0x07)) + 1); |
| 612 | | if (vertSelected) |
| 613 | | { |
| 614 | | tileLine = 0x07 - tileLine; |
| 615 | | } |
| 616 | | bitPlane0 = smsvdp.VRAM[((tileSelected << 5) + ((tileLine & 0x07) << 2)) + 0x00]; |
| 617 | | bitPlane1 = smsvdp.VRAM[((tileSelected << 5) + ((tileLine & 0x07) << 2)) + 0x01]; |
| 618 | | bitPlane2 = smsvdp.VRAM[((tileSelected << 5) + ((tileLine & 0x07) << 2)) + 0x02]; |
| 619 | | bitPlane3 = smsvdp.VRAM[((tileSelected << 5) + ((tileLine & 0x07) << 2)) + 0x03]; |
| 619 | tile_line = line - ((0x07 - (y_scroll & 0x07)) + 1); |
| 620 | if (vert_selected) |
| 621 | tile_line = 0x07 - tile_line; |
| 620 | 622 | |
| 621 | | for (pixelX = 0; pixelX < 8 ; pixelX++) |
| 623 | bit_plane_0 = smsvdp->VRAM[((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x00]; |
| 624 | bit_plane_1 = smsvdp->VRAM[((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x01]; |
| 625 | bit_plane_2 = smsvdp->VRAM[((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x02]; |
| 626 | bit_plane_3 = smsvdp->VRAM[((tile_selected << 5) + ((tile_line & 0x07) << 2)) + 0x03]; |
| 627 | |
| 628 | for (pixel_x = 0; pixel_x < 8 ; pixel_x++) |
| 622 | 629 | { |
| 623 | | UINT8 penBit0, penBit1, penBit2, penBit3; |
| 624 | | UINT8 penSelected; |
| 630 | UINT8 pen_bit_0, pen_bit_1, pen_bit_2, pen_bit_3; |
| 631 | UINT8 pen_selected; |
| 625 | 632 | |
| 626 | | penBit0 = (bitPlane0 >> (7 - pixelX)) & 0x01; |
| 627 | | penBit1 = (bitPlane1 >> (7 - pixelX)) & 0x01; |
| 628 | | penBit2 = (bitPlane2 >> (7 - pixelX)) & 0x01; |
| 629 | | penBit3 = (bitPlane3 >> (7 - pixelX)) & 0x01; |
| 633 | pen_bit_0 = (bit_plane_0 >> (7 - pixel_x)) & 0x01; |
| 634 | pen_bit_1 = (bit_plane_1 >> (7 - pixel_x)) & 0x01; |
| 635 | pen_bit_2 = (bit_plane_2 >> (7 - pixel_x)) & 0x01; |
| 636 | pen_bit_3 = (bit_plane_3 >> (7 - pixel_x)) & 0x01; |
| 630 | 637 | |
| 631 | | penSelected = (penBit3 << 3 | penBit2 << 2 | penBit1 << 1 | penBit0); |
| 632 | | if (palletteSelected) |
| 633 | | { |
| 634 | | penSelected |= 0x10; |
| 635 | | } |
| 638 | pen_selected = (pen_bit_3 << 3 | pen_bit_2 << 2 | pen_bit_1 << 1 | pen_bit_0); |
| 639 | if (palette_selected) |
| 640 | pen_selected |= 0x10; |
| 636 | 641 | |
| 637 | | if (!horizSelected) |
| 642 | |
| 643 | if (!horiz_selected) |
| 638 | 644 | { |
| 639 | | pixelPlotX = pixelX; |
| 645 | pixel_plot_x = pixel_x; |
| 640 | 646 | } |
| 641 | 647 | else |
| 642 | 648 | { |
| 643 | | pixelPlotX = 7 - pixelX; |
| 649 | pixel_plot_x = 7 - pixel_x; |
| 644 | 650 | } |
| 645 | | pixelPlotX = (0 - (xScroll & 0x07) + (tileColumn << 3) + pixelPlotX); |
| 646 | | if (pixelPlotX >= 0 && pixelPlotX < 256) |
| 651 | pixel_plot_x = (0 - (x_scroll & 0x07) + (tile_column << 3) + pixel_plot_x); |
| 652 | if (pixel_plot_x >= 0 && pixel_plot_x < 256) |
| 647 | 653 | { |
| 648 | | // logerror("%x %x\n", pixelPlotX + pixelOffsetX, pixelPlotY); |
| 649 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 650 | | prioritySelected[pixelPlotX] = prioritySelect | ( penSelected & 0x0F ); |
| 654 | // logerror("%x %x\n", pixel_plot_x + pixel_offset_x, pixel_plot_y); |
| 655 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 656 | priority_selected[pixel_plot_x] = priority_select | (pen_selected & 0x0f); |
| 651 | 657 | } |
| 652 | 658 | } |
| 653 | 659 | } |
| 654 | 660 | |
| 655 | 661 | /* Draw sprite layer */ |
| 656 | | spriteHeight = (smsvdp.reg[0x01] & 0x02 ? 16 : 8); |
| 657 | | spriteZoom = 1; |
| 658 | | if (smsvdp.reg[0x01] & 0x01) |
| 659 | | { |
| 662 | sprite_height = (smsvdp->reg[0x01] & 0x02 ? 16 : 8); |
| 663 | sprite_zoom = 1; |
| 664 | |
| 665 | if (smsvdp->reg[0x01] & 0x01) |
| 660 | 666 | /* sprite doubling */ |
| 661 | | spriteZoom = 2; |
| 662 | | } |
| 663 | | spriteBufferCount = 0; |
| 664 | | for (spriteIndex = 0; (spriteIndex < 64) && (spriteTable[spriteIndex] != 0xD0 || smsvdp.y_pixels != 192) && (spriteBufferCount < 9); spriteIndex++) |
| 667 | sprite_zoom = 2; |
| 668 | |
| 669 | sprite_buffer_count = 0; |
| 670 | for (sprite_index = 0; (sprite_index < 64) && (sprite_table[sprite_index] != 0xd0 || smsvdp->y_pixels != 192) && (sprite_buffer_count < 9); sprite_index++) |
| 665 | 671 | { |
| 666 | | spriteY = spriteTable[spriteIndex] + 1; /* sprite y position starts at line 1 */ |
| 667 | | if (spriteY > 240) |
| 672 | sprite_y = sprite_table[sprite_index] + 1; /* sprite y position starts at line 1 */ |
| 673 | |
| 674 | if (sprite_y > 240) |
| 675 | sprite_y -= 256; /* wrap from top if y position is > 240 */ |
| 676 | |
| 677 | if ((line >= sprite_y) && (line < (sprite_y + sprite_height * sprite_zoom))) |
| 668 | 678 | { |
| 669 | | spriteY -= 256; /* wrap from top if y position is > 240 */ |
| 670 | | } |
| 671 | | if ((line >= spriteY) && (line < (spriteY + spriteHeight * spriteZoom))) |
| 672 | | { |
| 673 | | if (spriteBufferCount < 8) |
| 679 | if (sprite_buffer_count < 8) |
| 674 | 680 | { |
| 675 | | spriteBuffer[spriteBufferCount] = spriteIndex; |
| 681 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 676 | 682 | } |
| 677 | 683 | else |
| 678 | 684 | { |
| 679 | 685 | /* Too many sprites per line */ |
| 680 | | smsvdp.status |= STATUS_SPROVR; |
| 686 | smsvdp->status |= STATUS_SPROVR; |
| 681 | 687 | } |
| 682 | | spriteBufferCount++; |
| 688 | sprite_buffer_count++; |
| 683 | 689 | } |
| 684 | 690 | } |
| 685 | | if ( spriteBufferCount > 8 ) |
| 691 | |
| 692 | if (sprite_buffer_count > 8) |
| 693 | sprite_buffer_count = 8; |
| 694 | |
| 695 | memset(smsvdp->collision_buffer, 0, SMS_X_PIXELS); |
| 696 | sprite_buffer_count--; |
| 697 | |
| 698 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| 686 | 699 | { |
| 687 | | spriteBufferCount = 8; |
| 688 | | } |
| 689 | | memset(smsvdp.collision_buffer, 0, SMS_X_PIXELS); |
| 690 | | spriteBufferCount--; |
| 691 | | for (spriteBufferIndex = spriteBufferCount; spriteBufferIndex >= 0; spriteBufferIndex--) |
| 692 | | { |
| 693 | | spriteIndex = spriteBuffer[spriteBufferIndex]; |
| 694 | | spriteY = spriteTable[spriteIndex] + 1; /* sprite y position starts at line 1 */ |
| 695 | | if (spriteY > 240) |
| 696 | | { |
| 697 | | spriteY -= 256; /* wrap from top if y position is > 240 */ |
| 698 | | } |
| 700 | sprite_index = sprite_buffer[sprite_buffer_index]; |
| 701 | sprite_y = sprite_table[sprite_index] + 1; /* sprite y position starts at line 1 */ |
| 699 | 702 | |
| 700 | | spriteX = spriteTable[0x80 + (spriteIndex << 1)]; |
| 701 | | if (smsvdp.reg[0x00] & 0x08) |
| 702 | | { |
| 703 | | spriteX -= 0x08; /* sprite shift */ |
| 704 | | } |
| 705 | | spriteTileSelected = spriteTable[0x81 + (spriteIndex << 1)]; |
| 706 | | if (smsvdp.reg[0x06] & 0x04) |
| 707 | | { |
| 708 | | spriteTileSelected += 256; /* pattern table select */ |
| 709 | | } |
| 710 | | if (smsvdp.reg[0x01] & 0x02) |
| 711 | | { |
| 712 | | spriteTileSelected &= 0x01FE; /* force even index */ |
| 713 | | } |
| 714 | | spriteLine = ( line - spriteY ) / spriteZoom; |
| 703 | if (sprite_y > 240) |
| 704 | sprite_y -= 256; /* wrap from top if y position is > 240 */ |
| 715 | 705 | |
| 716 | | if (spriteLine > 0x07) |
| 717 | | { |
| 718 | | spriteTileSelected += 1; |
| 719 | | } |
| 706 | sprite_x = sprite_table[0x80 + (sprite_index << 1)]; |
| 720 | 707 | |
| 721 | | bitPlane0 = smsvdp.VRAM[((spriteTileSelected << 5) + ((spriteLine & 0x07) << 2)) + 0x00]; |
| 722 | | bitPlane1 = smsvdp.VRAM[((spriteTileSelected << 5) + ((spriteLine & 0x07) << 2)) + 0x01]; |
| 723 | | bitPlane2 = smsvdp.VRAM[((spriteTileSelected << 5) + ((spriteLine & 0x07) << 2)) + 0x02]; |
| 724 | | bitPlane3 = smsvdp.VRAM[((spriteTileSelected << 5) + ((spriteLine & 0x07) << 2)) + 0x03]; |
| 708 | if (smsvdp->reg[0x00] & 0x08) |
| 709 | sprite_x -= 0x08; /* sprite shift */ |
| 725 | 710 | |
| 726 | | for (pixelX = 0; pixelX < 8 ; pixelX++) |
| 711 | sprite_tile_selected = sprite_table[0x81 + (sprite_index << 1)]; |
| 712 | |
| 713 | if (smsvdp->reg[0x06] & 0x04) |
| 714 | sprite_tile_selected += 256; /* pattern table select */ |
| 715 | |
| 716 | if (smsvdp->reg[0x01] & 0x02) |
| 717 | sprite_tile_selected &= 0x01fe; /* force even index */ |
| 718 | |
| 719 | sprite_line = (line - sprite_y) / sprite_zoom; |
| 720 | |
| 721 | if (sprite_line > 0x07) |
| 722 | sprite_tile_selected += 1; |
| 723 | |
| 724 | bit_plane_0 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x00]; |
| 725 | bit_plane_1 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x01]; |
| 726 | bit_plane_2 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x02]; |
| 727 | bit_plane_3 = smsvdp->VRAM[((sprite_tile_selected << 5) + ((sprite_line & 0x07) << 2)) + 0x03]; |
| 728 | |
| 729 | for (pixel_x = 0; pixel_x < 8 ; pixel_x++) |
| 727 | 730 | { |
| 728 | | UINT8 penBit0, penBit1, penBit2, penBit3; |
| 729 | | int penSelected; |
| 731 | UINT8 pen_bit_0, pen_bit_1, pen_bit_2, pen_bit_3; |
| 732 | int pen_selected; |
| 730 | 733 | |
| 731 | | penBit0 = (bitPlane0 >> (7 - pixelX)) & 0x01; |
| 732 | | penBit1 = (bitPlane1 >> (7 - pixelX)) & 0x01; |
| 733 | | penBit2 = (bitPlane2 >> (7 - pixelX)) & 0x01; |
| 734 | | penBit3 = (bitPlane3 >> (7 - pixelX)) & 0x01; |
| 734 | pen_bit_0 = (bit_plane_0 >> (7 - pixel_x)) & 0x01; |
| 735 | pen_bit_1 = (bit_plane_1 >> (7 - pixel_x)) & 0x01; |
| 736 | pen_bit_2 = (bit_plane_2 >> (7 - pixel_x)) & 0x01; |
| 737 | pen_bit_3 = (bit_plane_3 >> (7 - pixel_x)) & 0x01; |
| 735 | 738 | |
| 736 | | penSelected = (penBit3 << 3 | penBit2 << 2 | penBit1 << 1 | penBit0) | 0x10; |
| 739 | pen_selected = (pen_bit_3 << 3 | pen_bit_2 << 2 | pen_bit_1 << 1 | pen_bit_0) | 0x10; |
| 737 | 740 | |
| 738 | | if ( penSelected == 0x10 ) /* Transparent palette so skip draw */ |
| 741 | if (pen_selected == 0x10) /* Transparent palette so skip draw */ |
| 739 | 742 | { |
| 740 | 743 | continue; |
| 741 | 744 | } |
| 742 | 745 | |
| 743 | | if (smsvdp.reg[0x01] & 0x01) |
| 746 | if (smsvdp->reg[0x01] & 0x01) |
| 744 | 747 | { |
| 745 | 748 | /* sprite doubling is enabled */ |
| 746 | | pixelPlotX = spriteX + (pixelX << 1); |
| 749 | pixel_plot_x = sprite_x + (pixel_x << 1); |
| 747 | 750 | |
| 748 | 751 | /* check to prevent going outside of active display area */ |
| 749 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 752 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 750 | 753 | { |
| 751 | 754 | continue; |
| 752 | 755 | } |
| 753 | 756 | |
| 754 | | if ( ! ( prioritySelected[pixelPlotX] & PRIORITY_BIT ) ) |
| 757 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 755 | 758 | { |
| 756 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 757 | | lineBuffer[pixelPlotX+1] = smsvdp.current_palette[penSelected]; |
| 759 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 760 | line_buffer[pixel_plot_x + 1] = smsvdp->current_palette[pen_selected]; |
| 758 | 761 | } |
| 759 | 762 | else |
| 760 | 763 | { |
| 761 | | if ( prioritySelected[pixelPlotX] == PRIORITY_BIT ) |
| 764 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 762 | 765 | { |
| 763 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 766 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 764 | 767 | } |
| 765 | | if ( prioritySelected[pixelPlotX + 1] == PRIORITY_BIT ) |
| 768 | if (priority_selected[pixel_plot_x + 1] == PRIORITY_BIT) |
| 766 | 769 | { |
| 767 | | lineBuffer[pixelPlotX+1] = smsvdp.current_palette[penSelected]; |
| 770 | line_buffer[pixel_plot_x + 1] = smsvdp->current_palette[pen_selected]; |
| 768 | 771 | } |
| 769 | 772 | } |
| 770 | | if (smsvdp.collision_buffer[pixelPlotX] != 1) |
| 773 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 771 | 774 | { |
| 772 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 775 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 773 | 776 | } |
| 774 | 777 | else |
| 775 | 778 | { |
| 776 | 779 | /* sprite collision occurred */ |
| 777 | | smsvdp.status |= STATUS_SPRCOL; |
| 780 | smsvdp->status |= STATUS_SPRCOL; |
| 778 | 781 | } |
| 779 | | if (smsvdp.collision_buffer[pixelPlotX + 1] != 1) |
| 782 | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 780 | 783 | { |
| 781 | | smsvdp.collision_buffer[pixelPlotX + 1] = 1; |
| 784 | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 782 | 785 | } |
| 783 | 786 | else |
| 784 | 787 | { |
| 785 | 788 | /* sprite collision occurred */ |
| 786 | | smsvdp.status |= STATUS_SPRCOL; |
| 789 | smsvdp->status |= STATUS_SPRCOL; |
| 787 | 790 | } |
| 788 | 791 | } |
| 789 | 792 | else |
| 790 | 793 | { |
| 791 | | pixelPlotX = spriteX + pixelX; |
| 794 | pixel_plot_x = sprite_x + pixel_x; |
| 792 | 795 | |
| 793 | 796 | /* check to prevent going outside of active display area */ |
| 794 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 797 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 795 | 798 | { |
| 796 | 799 | continue; |
| 797 | 800 | } |
| 798 | 801 | |
| 799 | | if ( ! ( prioritySelected[pixelPlotX] & PRIORITY_BIT ) ) |
| 802 | if (!(priority_selected[pixel_plot_x] & PRIORITY_BIT)) |
| 800 | 803 | { |
| 801 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 804 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 802 | 805 | } |
| 803 | 806 | else |
| 804 | 807 | { |
| 805 | | if ( prioritySelected[pixelPlotX] == PRIORITY_BIT ) |
| 808 | if (priority_selected[pixel_plot_x] == PRIORITY_BIT) |
| 806 | 809 | { |
| 807 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 810 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 808 | 811 | } |
| 809 | 812 | } |
| 810 | | if (smsvdp.collision_buffer[pixelPlotX] != 1) |
| 813 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 811 | 814 | { |
| 812 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 815 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 813 | 816 | } |
| 814 | 817 | else |
| 815 | 818 | { |
| 816 | 819 | /* sprite collision occurred */ |
| 817 | | smsvdp.status |= STATUS_SPRCOL; |
| 820 | smsvdp->status |= STATUS_SPRCOL; |
| 818 | 821 | } |
| 819 | 822 | } |
| 820 | 823 | } |
| 821 | 824 | } |
| 822 | 825 | |
| 823 | 826 | /* Fill column 0 with overscan color from reg[0x07] */ |
| 824 | | if (smsvdp.reg[0x00] & 0x20) |
| 827 | if (smsvdp->reg[0x00] & 0x20) |
| 825 | 828 | { |
| 826 | | lineBuffer[0] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 827 | | lineBuffer[1] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 828 | | lineBuffer[2] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 829 | | lineBuffer[3] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 830 | | lineBuffer[4] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 831 | | lineBuffer[5] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 832 | | lineBuffer[6] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 833 | | lineBuffer[7] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 829 | line_buffer[0] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 830 | line_buffer[1] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 831 | line_buffer[2] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 832 | line_buffer[3] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 833 | line_buffer[4] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 834 | line_buffer[5] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 835 | line_buffer[6] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 836 | line_buffer[7] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 834 | 837 | } |
| 835 | 838 | } |
| 836 | 839 | |
| 837 | 840 | |
| 838 | | static void sms_refresh_tms9918_sprites(int *lineBuffer, int line) |
| 841 | static void sms_refresh_tms9918_sprites( smsvdp_t *smsvdp, int *line_buffer, int line ) |
| 839 | 842 | { |
| 840 | | int pixelPlotX; |
| 841 | | int spriteHeight, spriteBufferCount, spriteIndex, spriteBuffer[4], spriteBufferIndex; |
| 842 | | UINT8 *spriteTable, *spritePatternTable; |
| 843 | int pixel_plot_x; |
| 844 | int sprite_height, sprite_buffer_count, sprite_index, sprite_buffer[4], sprite_buffer_index; |
| 845 | UINT8 *sprite_table, *sprite_pattern_table; |
| 843 | 846 | |
| 844 | 847 | /* Draw sprite layer */ |
| 845 | | spriteTable = smsvdp.VRAM + ( ( smsvdp.reg[0x05] & 0x7F ) << 7 ); |
| 846 | | spritePatternTable = smsvdp.VRAM + ( ( smsvdp.reg[0x06] & 0x07 ) << 11 ); |
| 847 | | spriteHeight = 8; |
| 848 | sprite_table = smsvdp->VRAM + ((smsvdp->reg[0x05] & 0x7f) << 7); |
| 849 | sprite_pattern_table = smsvdp->VRAM + ((smsvdp->reg[0x06] & 0x07) << 11); |
| 850 | sprite_height = 8; |
| 848 | 851 | |
| 849 | | if ( smsvdp.reg[0x01] & 0x02 ) /* Check if SI is set */ |
| 850 | | spriteHeight = spriteHeight * 2; |
| 851 | | if ( smsvdp.reg[0x01] & 0x01 ) /* Check if MAG is set */ |
| 852 | | spriteHeight = spriteHeight * 2; |
| 852 | if (smsvdp->reg[0x01] & 0x02) /* Check if SI is set */ |
| 853 | sprite_height = sprite_height * 2; |
| 854 | if (smsvdp->reg[0x01] & 0x01) /* Check if MAG is set */ |
| 855 | sprite_height = sprite_height * 2; |
| 853 | 856 | |
| 854 | | spriteBufferCount = 0; |
| 855 | | for ( spriteIndex = 0; (spriteIndex < 32*4 ) && ( spriteTable[spriteIndex] != 0xD0 ) && ( spriteBufferCount < 5); spriteIndex+= 4 ) |
| 857 | sprite_buffer_count = 0; |
| 858 | for (sprite_index = 0; (sprite_index < 32 * 4) && (sprite_table[sprite_index] != 0xd0) && (sprite_buffer_count < 5); sprite_index += 4) |
| 856 | 859 | { |
| 857 | | int spriteY = spriteTable[spriteIndex] + 1; |
| 860 | int sprite_y = sprite_table[sprite_index] + 1; |
| 858 | 861 | |
| 859 | | if ( spriteY > 240 ) |
| 860 | | { |
| 861 | | spriteY -= 256; |
| 862 | | } |
| 862 | if (sprite_y > 240) |
| 863 | sprite_y -= 256; |
| 863 | 864 | |
| 864 | | if ( ( line >= spriteY ) && ( line < ( spriteY + spriteHeight ) ) ) |
| 865 | if ((line >= sprite_y) && (line < (sprite_y + sprite_height))) |
| 865 | 866 | { |
| 866 | | if ( spriteBufferCount < 5 ) |
| 867 | if (sprite_buffer_count < 5) |
| 867 | 868 | { |
| 868 | | spriteBuffer[spriteBufferCount] = spriteIndex; |
| 869 | sprite_buffer[sprite_buffer_count] = sprite_index; |
| 869 | 870 | } |
| 870 | 871 | else |
| 871 | 872 | { |
| 872 | 873 | /* Too many sprites per line */ |
| 873 | | smsvdp.status |= STATUS_SPROVR; |
| 874 | smsvdp->status |= STATUS_SPROVR; |
| 874 | 875 | } |
| 875 | | spriteBufferCount++; |
| 876 | sprite_buffer_count++; |
| 876 | 877 | } |
| 877 | 878 | } |
| 878 | 879 | |
| 879 | | if ( spriteBufferCount > 4 ) |
| 880 | | { |
| 881 | | spriteBufferCount = 4; |
| 882 | | } |
| 880 | if (sprite_buffer_count > 4) |
| 881 | sprite_buffer_count = 4; |
| 883 | 882 | |
| 884 | | memset( smsvdp.collision_buffer, 0, SMS_X_PIXELS ); |
| 885 | | spriteBufferCount--; |
| 883 | memset(smsvdp->collision_buffer, 0, SMS_X_PIXELS); |
| 884 | sprite_buffer_count--; |
| 886 | 885 | |
| 887 | | for ( spriteBufferIndex = spriteBufferCount; spriteBufferIndex >= 0; spriteBufferIndex-- ) |
| 886 | for (sprite_buffer_index = sprite_buffer_count; sprite_buffer_index >= 0; sprite_buffer_index--) |
| 888 | 887 | { |
| 889 | | int penSelected; |
| 890 | | int spriteLine, pixelX, spriteX, spriteTileSelected; |
| 891 | | int spriteY; |
| 888 | int pen_selected; |
| 889 | int sprite_line, pixel_x, sprite_x, sprite_tile_selected; |
| 890 | int sprite_y; |
| 892 | 891 | UINT8 pattern; |
| 893 | 892 | |
| 894 | | spriteIndex = spriteBuffer[ spriteBufferIndex ]; |
| 895 | | spriteY = spriteTable[ spriteIndex ] + 1; |
| 893 | sprite_index = sprite_buffer[sprite_buffer_index]; |
| 894 | sprite_y = sprite_table[sprite_index] + 1; |
| 896 | 895 | |
| 897 | | if ( spriteY > 240 ) |
| 898 | | { |
| 899 | | spriteY -= 256; |
| 900 | | } |
| 896 | if (sprite_y > 240) |
| 897 | sprite_y -= 256; |
| 901 | 898 | |
| 902 | | spriteX = spriteTable[ spriteIndex + 1 ]; |
| 903 | | penSelected = spriteTable[ spriteIndex + 3 ] & 0x0F; |
| 899 | sprite_x = sprite_table[sprite_index + 1]; |
| 900 | pen_selected = sprite_table[sprite_index + 3] & 0x0f; |
| 904 | 901 | |
| 905 | | if ( IS_GAMEGEAR_VDP ) |
| 906 | | { |
| 907 | | penSelected |= 0x10; |
| 908 | | } |
| 902 | if (IS_GAMEGEAR_VDP) |
| 903 | pen_selected |= 0x10; |
| 909 | 904 | |
| 910 | | if ( spriteTable[ spriteIndex + 3 ] & 0x80 ) |
| 911 | | { |
| 912 | | spriteX -= 32; |
| 913 | | } |
| 905 | if (sprite_table[sprite_index + 3] & 0x80) |
| 906 | sprite_x -= 32; |
| 914 | 907 | |
| 915 | | spriteTileSelected = spriteTable[ spriteIndex + 2 ]; |
| 916 | | spriteLine = line - spriteY; |
| 908 | sprite_tile_selected = sprite_table[sprite_index + 2]; |
| 909 | sprite_line = line - sprite_y; |
| 917 | 910 | |
| 918 | | if ( smsvdp.reg[0x01] & 0x01 ) |
| 919 | | { |
| 920 | | spriteLine >>= 1; |
| 921 | | } |
| 911 | if (smsvdp->reg[0x01] & 0x01) |
| 912 | sprite_line >>= 1; |
| 922 | 913 | |
| 923 | | if ( smsvdp.reg[0x01] & 0x02 ) |
| 914 | if (smsvdp->reg[0x01] & 0x02) |
| 924 | 915 | { |
| 925 | | spriteTileSelected &= 0xFC; |
| 916 | sprite_tile_selected &= 0xfc; |
| 926 | 917 | |
| 927 | | if ( spriteLine > 0x07 ) |
| 918 | if (sprite_line > 0x07) |
| 928 | 919 | { |
| 929 | | spriteTileSelected += 1; |
| 930 | | spriteLine -= 8; |
| 920 | sprite_tile_selected += 1; |
| 921 | sprite_line -= 8; |
| 931 | 922 | } |
| 932 | 923 | } |
| 933 | 924 | |
| 934 | | pattern = spritePatternTable[ spriteTileSelected * 8 + spriteLine ]; |
| 925 | pattern = sprite_pattern_table[sprite_tile_selected * 8 + sprite_line]; |
| 935 | 926 | |
| 936 | | for ( pixelX = 0; pixelX < 8; pixelX++ ) |
| 927 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 937 | 928 | { |
| 938 | | if ( smsvdp.reg[0x01] & 0x01 ) |
| 929 | if (smsvdp->reg[0x01] & 0x01) |
| 939 | 930 | { |
| 940 | | pixelPlotX = spriteX + pixelX * 2; |
| 941 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 931 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 932 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 942 | 933 | { |
| 943 | 934 | continue; |
| 944 | 935 | } |
| 945 | 936 | |
| 946 | | if ( penSelected && ( pattern & ( 1 << ( 7 - pixelX ) ) ) ) |
| 937 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 947 | 938 | { |
| 948 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 939 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 949 | 940 | |
| 950 | | if ( smsvdp.collision_buffer[pixelPlotX] != 1 ) |
| 941 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 951 | 942 | { |
| 952 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 943 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 953 | 944 | } |
| 954 | 945 | else |
| 955 | 946 | { |
| 956 | | smsvdp.status |= STATUS_SPRCOL; |
| 947 | smsvdp->status |= STATUS_SPRCOL; |
| 957 | 948 | } |
| 958 | 949 | |
| 959 | | lineBuffer[pixelPlotX+1] = smsvdp.current_palette[penSelected]; |
| 950 | line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected]; |
| 960 | 951 | |
| 961 | | if ( smsvdp.collision_buffer[pixelPlotX + 1] != 1 ) |
| 952 | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 962 | 953 | { |
| 963 | | smsvdp.collision_buffer[pixelPlotX + 1] = 1; |
| 954 | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 964 | 955 | } |
| 965 | 956 | else |
| 966 | 957 | { |
| 967 | | smsvdp.status |= STATUS_SPRCOL; |
| 958 | smsvdp->status |= STATUS_SPRCOL; |
| 968 | 959 | } |
| 969 | 960 | } |
| 970 | 961 | } |
| 971 | 962 | else |
| 972 | 963 | { |
| 973 | | pixelPlotX = spriteX + pixelX; |
| 964 | pixel_plot_x = sprite_x + pixel_x; |
| 974 | 965 | |
| 975 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 966 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 976 | 967 | { |
| 977 | 968 | continue; |
| 978 | 969 | } |
| 979 | 970 | |
| 980 | | if ( penSelected && ( pattern & ( 1 << ( 7 - pixelX ) ) ) ) |
| 971 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 981 | 972 | { |
| 982 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 973 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 983 | 974 | |
| 984 | | if ( smsvdp.collision_buffer[pixelPlotX] != 1 ) |
| 975 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 985 | 976 | { |
| 986 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 977 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 987 | 978 | } |
| 988 | 979 | else |
| 989 | 980 | { |
| 990 | | smsvdp.status |= STATUS_SPRCOL; |
| 981 | smsvdp->status |= STATUS_SPRCOL; |
| 991 | 982 | } |
| 992 | 983 | } |
| 993 | 984 | } |
| 994 | 985 | } |
| 995 | 986 | |
| 996 | | if ( smsvdp.reg[0x01] & 0x02 ) |
| 987 | if (smsvdp->reg[0x01] & 0x02) |
| 997 | 988 | { |
| 998 | | spriteTileSelected += 2; |
| 999 | | pattern = spritePatternTable[ spriteTileSelected * 8 + spriteLine ]; |
| 1000 | | spriteX += ( smsvdp.reg[0x01] & 0x01 ? 16 : 8 ); |
| 989 | sprite_tile_selected += 2; |
| 990 | pattern = sprite_pattern_table[sprite_tile_selected * 8 + sprite_line]; |
| 991 | sprite_x += (smsvdp->reg[0x01] & 0x01 ? 16 : 8); |
| 1001 | 992 | |
| 1002 | | for ( pixelX = 0; pixelX < 8; pixelX++ ) |
| 993 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 1003 | 994 | { |
| 1004 | | if ( smsvdp.reg[0x01] & 0x01 ) |
| 995 | if (smsvdp->reg[0x01] & 0x01) |
| 1005 | 996 | { |
| 1006 | | pixelPlotX = spriteX + pixelX * 2; |
| 997 | pixel_plot_x = sprite_x + pixel_x * 2; |
| 1007 | 998 | |
| 1008 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 999 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 1009 | 1000 | { |
| 1010 | 1001 | continue; |
| 1011 | 1002 | } |
| 1012 | 1003 | |
| 1013 | | if ( penSelected && ( pattern & ( 1 << ( 7 - pixelX ) ) ) ) |
| 1004 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1014 | 1005 | { |
| 1015 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 1006 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1016 | 1007 | |
| 1017 | | if ( smsvdp.collision_buffer[pixelPlotX] != 1 ) |
| 1008 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 1018 | 1009 | { |
| 1019 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 1010 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 1020 | 1011 | } |
| 1021 | 1012 | else |
| 1022 | 1013 | { |
| 1023 | | smsvdp.status |= STATUS_SPRCOL; |
| 1014 | smsvdp->status |= STATUS_SPRCOL; |
| 1024 | 1015 | } |
| 1025 | 1016 | |
| 1026 | | lineBuffer[pixelPlotX+1] = smsvdp.current_palette[penSelected]; |
| 1017 | line_buffer[pixel_plot_x+1] = smsvdp->current_palette[pen_selected]; |
| 1027 | 1018 | |
| 1028 | | if ( smsvdp.collision_buffer[pixelPlotX + 1] != 1 ) |
| 1019 | if (smsvdp->collision_buffer[pixel_plot_x + 1] != 1) |
| 1029 | 1020 | { |
| 1030 | | smsvdp.collision_buffer[pixelPlotX + 1] = 1; |
| 1021 | smsvdp->collision_buffer[pixel_plot_x + 1] = 1; |
| 1031 | 1022 | } |
| 1032 | 1023 | else |
| 1033 | 1024 | { |
| 1034 | | smsvdp.status |= STATUS_SPRCOL; |
| 1025 | smsvdp->status |= STATUS_SPRCOL; |
| 1035 | 1026 | } |
| 1036 | 1027 | } |
| 1037 | 1028 | } |
| 1038 | 1029 | else |
| 1039 | 1030 | { |
| 1040 | | pixelPlotX = spriteX + pixelX; |
| 1031 | pixel_plot_x = sprite_x + pixel_x; |
| 1041 | 1032 | |
| 1042 | | if ( pixelPlotX < 0 || pixelPlotX > 255 ) |
| 1033 | if (pixel_plot_x < 0 || pixel_plot_x > 255) |
| 1043 | 1034 | { |
| 1044 | 1035 | continue; |
| 1045 | 1036 | } |
| 1046 | 1037 | |
| 1047 | | if ( penSelected && ( pattern & ( 1 << ( 7 - pixelX ) ) ) ) |
| 1038 | if (pen_selected && (pattern & (1 << (7 - pixel_x)))) |
| 1048 | 1039 | { |
| 1049 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 1040 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1050 | 1041 | |
| 1051 | | if ( smsvdp.collision_buffer[pixelPlotX] != 1 ) |
| 1042 | if (smsvdp->collision_buffer[pixel_plot_x] != 1) |
| 1052 | 1043 | { |
| 1053 | | smsvdp.collision_buffer[pixelPlotX] = 1; |
| 1044 | smsvdp->collision_buffer[pixel_plot_x] = 1; |
| 1054 | 1045 | } |
| 1055 | 1046 | else |
| 1056 | 1047 | { |
| 1057 | | smsvdp.status |= STATUS_SPRCOL; |
| 1048 | smsvdp->status |= STATUS_SPRCOL; |
| 1058 | 1049 | } |
| 1059 | 1050 | } |
| 1060 | 1051 | } |
| r6078 | r6079 | |
| 1064 | 1055 | } |
| 1065 | 1056 | |
| 1066 | 1057 | |
| 1067 | | static void sms_refresh_line_mode2(int *lineBuffer, int line) |
| 1058 | static void sms_refresh_line_mode2( smsvdp_t *smsvdp, int *line_buffer, int line ) |
| 1068 | 1059 | { |
| 1069 | | int tileColumn; |
| 1070 | | int pixelX, pixelPlotX; |
| 1071 | | UINT8 *nameTable, *colorTable, *patternTable; |
| 1072 | | int patternMask, colorMask, patternOffset; |
| 1060 | int tile_column; |
| 1061 | int pixel_x, pixel_plot_x; |
| 1062 | UINT8 *name_table, *color_table, *pattern_table; |
| 1063 | int pattern_mask, color_mask, pattern_offset; |
| 1073 | 1064 | |
| 1074 | 1065 | /* Draw background layer */ |
| 1075 | | nameTable = smsvdp.VRAM + ( ( smsvdp.reg[0x02] & 0x0F ) << 10 ) + ( ( line >> 3 ) * 32 ); |
| 1076 | | colorTable = smsvdp.VRAM + ( ( smsvdp.reg[0x03] & 0x80 ) << 6 ); |
| 1077 | | colorMask = ( ( smsvdp.reg[0x03] & 0x7F ) << 3 ) | 0x07; |
| 1078 | | patternTable = smsvdp.VRAM + ( ( smsvdp.reg[0x04] & 0x04 ) << 11 ); |
| 1079 | | patternMask = ( ( smsvdp.reg[0x04] & 0x03 ) << 8 ) | 0xFF; |
| 1080 | | patternOffset = ( line & 0xC0 ) << 2; |
| 1066 | name_table = smsvdp->VRAM + ((smsvdp->reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1067 | color_table = smsvdp->VRAM + ((smsvdp->reg[0x03] & 0x80) << 6); |
| 1068 | color_mask = ((smsvdp->reg[0x03] & 0x7f) << 3) | 0x07; |
| 1069 | pattern_table = smsvdp->VRAM + ((smsvdp->reg[0x04] & 0x04) << 11); |
| 1070 | pattern_mask = ((smsvdp->reg[0x04] & 0x03) << 8) | 0xff; |
| 1071 | pattern_offset = (line & 0xc0) << 2; |
| 1081 | 1072 | |
| 1082 | | for ( tileColumn = 0; tileColumn < 32; tileColumn++ ) |
| 1073 | for (tile_column = 0; tile_column < 32; tile_column++) |
| 1083 | 1074 | { |
| 1084 | 1075 | UINT8 pattern; |
| 1085 | 1076 | UINT8 colors; |
| 1086 | 1077 | |
| 1087 | | pattern = patternTable[ ( ( ( patternOffset + nameTable[tileColumn] ) & patternMask ) * 8 ) + ( line & 0x07 ) ]; |
| 1088 | | colors = colorTable[ ( ( ( patternOffset + nameTable[tileColumn] ) & colorMask ) * 8 ) + ( line & 0x07 ) ]; |
| 1078 | pattern = pattern_table[(((pattern_offset + name_table[tile_column]) & pattern_mask) * 8) + (line & 0x07)]; |
| 1079 | colors = color_table[(((pattern_offset + name_table[tile_column]) & color_mask) * 8) + (line & 0x07)]; |
| 1089 | 1080 | |
| 1090 | | for ( pixelX = 0; pixelX < 8; pixelX++ ) |
| 1081 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 1091 | 1082 | { |
| 1092 | | UINT8 penSelected; |
| 1083 | UINT8 pen_selected; |
| 1093 | 1084 | |
| 1094 | | if ( pattern & ( 1 << ( 7 - pixelX ) ) ) |
| 1085 | if (pattern & (1 << (7 - pixel_x))) |
| 1095 | 1086 | { |
| 1096 | | penSelected = colors >> 4; |
| 1087 | pen_selected = colors >> 4; |
| 1097 | 1088 | } |
| 1098 | 1089 | else |
| 1099 | 1090 | { |
| 1100 | | penSelected = colors & 0x0F; |
| 1091 | pen_selected = colors & 0x0f; |
| 1101 | 1092 | } |
| 1102 | 1093 | |
| 1103 | | if ( ! penSelected ) |
| 1104 | | { |
| 1105 | | penSelected = BACKDROP_COLOR; |
| 1106 | | } |
| 1094 | if (!pen_selected) |
| 1095 | pen_selected = BACKDROP_COLOR; |
| 1107 | 1096 | |
| 1108 | | pixelPlotX = ( tileColumn << 3 ) + pixelX; |
| 1097 | pixel_plot_x = (tile_column << 3) + pixel_x; |
| 1109 | 1098 | |
| 1110 | | if ( IS_GAMEGEAR_VDP ) |
| 1111 | | { |
| 1112 | | penSelected |= 0x10; |
| 1113 | | } |
| 1099 | if (IS_GAMEGEAR_VDP) |
| 1100 | pen_selected |= 0x10; |
| 1114 | 1101 | |
| 1115 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 1102 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1116 | 1103 | } |
| 1117 | 1104 | } |
| 1118 | 1105 | |
| 1119 | 1106 | /* Draw sprite layer */ |
| 1120 | | sms_refresh_tms9918_sprites( lineBuffer, line ); |
| 1107 | sms_refresh_tms9918_sprites(smsvdp, line_buffer, line); |
| 1121 | 1108 | } |
| 1122 | 1109 | |
| 1123 | 1110 | |
| 1124 | | static void sms_refresh_line_mode0(int *lineBuffer, int line) |
| 1111 | static void sms_refresh_line_mode0( smsvdp_t *smsvdp, int *line_buffer, int line) |
| 1125 | 1112 | { |
| 1126 | | int tileColumn; |
| 1127 | | int pixelX, pixelPlotX; |
| 1128 | | UINT8 *nameTable, *colorTable, *patternTable; |
| 1113 | int tile_column; |
| 1114 | int pixel_x, pixel_plot_x; |
| 1115 | UINT8 *name_table, *color_table, *pattern_table; |
| 1129 | 1116 | |
| 1130 | 1117 | /* Draw background layer */ |
| 1131 | | nameTable = smsvdp.VRAM + ( ( smsvdp.reg[0x02] & 0x0F ) << 10 ) + ( ( line >> 3 ) * 32 ); |
| 1132 | | colorTable = smsvdp.VRAM + ( ( smsvdp.reg[0x03] << 6 ) & ( VRAM_SIZE - 1 ) ); |
| 1133 | | patternTable = smsvdp.VRAM + ( ( smsvdp.reg[0x04] << 11 ) & ( VRAM_SIZE - 1 ) ); |
| 1118 | name_table = smsvdp->VRAM + ((smsvdp->reg[0x02] & 0x0f) << 10) + ((line >> 3) * 32); |
| 1119 | color_table = smsvdp->VRAM + ((smsvdp->reg[0x03] << 6) & (VRAM_SIZE - 1)); |
| 1120 | pattern_table = smsvdp->VRAM + ((smsvdp->reg[0x04] << 11) & (VRAM_SIZE - 1)); |
| 1134 | 1121 | |
| 1135 | | for ( tileColumn = 0; tileColumn < 32; tileColumn++ ) |
| 1122 | for (tile_column = 0; tile_column < 32; tile_column++) |
| 1136 | 1123 | { |
| 1137 | 1124 | UINT8 pattern; |
| 1138 | 1125 | UINT8 colors; |
| 1139 | 1126 | |
| 1140 | | pattern = patternTable[ ( nameTable[tileColumn] * 8 ) + ( line & 0x07 ) ]; |
| 1141 | | colors = colorTable[ nameTable[tileColumn] >> 3 ]; |
| 1127 | pattern = pattern_table[(name_table[tile_column] * 8) + (line & 0x07)]; |
| 1128 | colors = color_table[name_table[tile_column] >> 3]; |
| 1142 | 1129 | |
| 1143 | | for ( pixelX = 0; pixelX < 8; pixelX++ ) |
| 1130 | for (pixel_x = 0; pixel_x < 8; pixel_x++) |
| 1144 | 1131 | { |
| 1145 | | int penSelected; |
| 1132 | int pen_selected; |
| 1146 | 1133 | |
| 1147 | | if ( pattern & ( 1 << ( 7 - pixelX ) ) ) |
| 1148 | | { |
| 1149 | | penSelected = colors >> 4; |
| 1150 | | } |
| 1134 | if (pattern & (1 << (7 - pixel_x))) |
| 1135 | pen_selected = colors >> 4; |
| 1151 | 1136 | else |
| 1152 | | { |
| 1153 | | penSelected = colors & 0x0F; |
| 1154 | | } |
| 1137 | pen_selected = colors & 0x0f; |
| 1155 | 1138 | |
| 1156 | | if ( IS_GAMEGEAR_VDP ) |
| 1157 | | { |
| 1158 | | penSelected |= 0x10; |
| 1159 | | } |
| 1139 | if (IS_GAMEGEAR_VDP) |
| 1140 | pen_selected |= 0x10; |
| 1160 | 1141 | |
| 1161 | | pixelPlotX = ( tileColumn << 3 ) + pixelX; |
| 1162 | | lineBuffer[pixelPlotX] = smsvdp.current_palette[penSelected]; |
| 1142 | pixel_plot_x = (tile_column << 3) + pixel_x; |
| 1143 | line_buffer[pixel_plot_x] = smsvdp->current_palette[pen_selected]; |
| 1163 | 1144 | } |
| 1164 | 1145 | } |
| 1165 | 1146 | |
| 1166 | 1147 | /* Draw sprite layer */ |
| 1167 | | sms_refresh_tms9918_sprites( lineBuffer, line ); |
| 1148 | sms_refresh_tms9918_sprites(smsvdp, line_buffer, line); |
| 1168 | 1149 | } |
| 1169 | 1150 | |
| 1170 | 1151 | |
| 1171 | | static void sms_refresh_line( running_machine *machine, bitmap_t *bitmap, int pixelOffsetX, int pixelPlotY, int line ) |
| 1152 | static void sms_refresh_line( running_machine *machine, smsvdp_t *smsvdp, bitmap_t *bitmap, int pixel_offset_x, int pixel_plot_y, int line ) |
| 1172 | 1153 | { |
| 1173 | 1154 | int x; |
| 1174 | | int *blitLineBuffer = smsvdp.line_buffer; |
| 1155 | int *blitline_buffer = smsvdp->line_buffer; |
| 1175 | 1156 | |
| 1176 | | if ( line >= 0 && line < smsvdp.sms_frame_timing[ACTIVE_DISPLAY_V] ) |
| 1157 | if (line >= 0 && line < smsvdp->sms_frame_timing[ACTIVE_DISPLAY_V]) |
| 1177 | 1158 | { |
| 1178 | | switch( smsvdp.vdp_mode ) |
| 1159 | switch( smsvdp->vdp_mode ) |
| 1179 | 1160 | { |
| 1180 | 1161 | case 0: |
| 1181 | | sms_refresh_line_mode0( blitLineBuffer, line ); |
| 1162 | sms_refresh_line_mode0(smsvdp, blitline_buffer, line); |
| 1182 | 1163 | break; |
| 1183 | 1164 | |
| 1184 | 1165 | case 2: |
| 1185 | | sms_refresh_line_mode2( blitLineBuffer, line ); |
| 1166 | sms_refresh_line_mode2(smsvdp, blitline_buffer, line); |
| 1186 | 1167 | break; |
| 1187 | 1168 | |
| 1188 | 1169 | case 4: |
| 1189 | 1170 | default: |
| 1190 | | sms_refresh_line_mode4( blitLineBuffer, line ); |
| 1171 | sms_refresh_line_mode4(smsvdp, blitline_buffer, line); |
| 1191 | 1172 | break; |
| 1192 | 1173 | } |
| 1193 | 1174 | } |
| 1194 | 1175 | else |
| 1195 | 1176 | { |
| 1196 | | for ( x = 0; x < 256; x++ ) |
| 1177 | for (x = 0; x < 256; x++) |
| 1197 | 1178 | { |
| 1198 | | blitLineBuffer[x] = smsvdp.current_palette[BACKDROP_COLOR]; |
| 1179 | blitline_buffer[x] = smsvdp->current_palette[BACKDROP_COLOR]; |
| 1199 | 1180 | } |
| 1200 | 1181 | } |
| 1201 | 1182 | |
| 1202 | | if ( IS_GAMEGEAR_VDP && smsvdp.gg_sms_mode ) |
| 1183 | if (IS_GAMEGEAR_VDP && smsvdp->gg_sms_mode) |
| 1203 | 1184 | { |
| 1204 | | int *combineLineBuffer = smsvdp.line_buffer + ( ( line & 0x03 ) + 1 ) * 256; |
| 1205 | | int plotX = 48; |
| 1185 | int *combineline_buffer = smsvdp->line_buffer + ((line & 0x03) + 1) * 256; |
| 1186 | int plot_x = 48; |
| 1206 | 1187 | |
| 1207 | 1188 | /* Do horizontal scaling */ |
| 1208 | | for( x = 8; x < 248; ) |
| 1189 | for (x = 8; x < 248;) |
| 1209 | 1190 | { |
| 1210 | | int combined; |
| 1191 | int combined; |
| 1211 | 1192 | |
| 1212 | 1193 | /* Take red and green from first pixel, and blue from second pixel */ |
| 1213 | | combined = ( blitLineBuffer[x] & 0x00FF ) | ( blitLineBuffer[x+1] & 0x0F00 ); |
| 1214 | | combineLineBuffer[plotX] = combined; |
| 1194 | combined = (blitline_buffer[x] & 0x00ff) | (blitline_buffer[x + 1] & 0x0f00); |
| 1195 | combineline_buffer[plot_x] = combined; |
| 1215 | 1196 | |
| 1216 | 1197 | /* Take red from second pixel, and green and blue from third pixel */ |
| 1217 | | combined = ( blitLineBuffer[x+1] & 0x000F ) | ( blitLineBuffer[x+2] & 0x0FF0 ); |
| 1218 | | combineLineBuffer[plotX+1] = combined; |
| 1198 | combined = (blitline_buffer[x + 1] & 0x000f) | (blitline_buffer[x + 2] & 0x0ff0); |
| 1199 | combineline_buffer[plot_x + 1] = combined; |
| 1219 | 1200 | x += 3; |
| 1220 | | plotX += 2; |
| 1201 | plot_x += 2; |
| 1221 | 1202 | } |
| 1222 | 1203 | |
| 1223 | 1204 | /* Do vertical scaling for a screen with 192 or 224 lines |
| r6078 | r6079 | |
| 1233 | 1214 | GG_143 = 1/6 * SMS_217 + 1/3 * SMS_218 + 1/3 * SMS_219 + 1/6 * SMS_220 |
| 1234 | 1215 | */ |
| 1235 | 1216 | { |
| 1236 | | int ggLine; |
| 1237 | | int myLine = pixelPlotY + line - ( TBORDER_START + NTSC_224_TBORDER_Y_PIXELS ); |
| 1238 | | int *line1, *line2, *line3, *line4; |
| 1217 | int gg_line; |
| 1218 | int my_line = pixel_plot_y + line - (TBORDER_START + NTSC_224_TBORDER_Y_PIXELS); |
| 1219 | int *line1, *line2, *line3, *line4; |
| 1239 | 1220 | |
| 1240 | 1221 | /* First make sure there's enough data to draw anything */ |
| 1241 | 1222 | /* We need one more line of data if we're on line 8, 11, 14, 17, etc */ |
| 1242 | | if ( myLine < 6 || myLine > 220 || ( ( myLine - 8 ) % 3 == 0 ) ) |
| 1223 | if (my_line < 6 || my_line > 220 || ((my_line - 8) % 3 == 0)) |
| 1243 | 1224 | { |
| 1244 | 1225 | return; |
| 1245 | 1226 | } |
| 1246 | 1227 | |
| 1247 | | ggLine = ( ( myLine - 6 ) / 3 ) * 2; |
| 1228 | gg_line = ((my_line - 6) / 3) * 2; |
| 1248 | 1229 | |
| 1249 | 1230 | /* If we're on SMS line 7, 10, 13, etc we're on an odd GG line */ |
| 1250 | | if ( myLine % 3 ) |
| 1231 | if (my_line % 3) |
| 1251 | 1232 | { |
| 1252 | | ggLine++; |
| 1233 | gg_line++; |
| 1253 | 1234 | } |
| 1254 | 1235 | |
| 1255 | 1236 | /* Calculate the line we will be drawing on */ |
| 1256 | | pixelPlotY = TBORDER_START + NTSC_192_TBORDER_Y_PIXELS + 24 + ggLine; |
| 1237 | pixel_plot_y = TBORDER_START + NTSC_192_TBORDER_Y_PIXELS + 24 + gg_line; |
| 1257 | 1238 | |
| 1258 | 1239 | /* Setup our source lines */ |
| 1259 | | line1 = smsvdp.line_buffer + ( ( ( myLine - 3 ) & 0x03 ) + 1 ) * 256; |
| 1260 | | line2 = smsvdp.line_buffer + ( ( ( myLine - 2 ) & 0x03 ) + 1 ) * 256; |
| 1261 | | line3 = smsvdp.line_buffer + ( ( ( myLine - 1 ) & 0x03 ) + 1 ) * 256; |
| 1262 | | line4 = smsvdp.line_buffer + ( ( ( myLine - 0 ) & 0x03 ) + 1 ) * 256; |
| 1240 | line1 = smsvdp->line_buffer + (((my_line - 3) & 0x03) + 1) * 256; |
| 1241 | line2 = smsvdp->line_buffer + (((my_line - 2) & 0x03) + 1) * 256; |
| 1242 | line3 = smsvdp->line_buffer + (((my_line - 1) & 0x03) + 1) * 256; |
| 1243 | line4 = smsvdp->line_buffer + (((my_line - 0) & 0x03) + 1) * 256; |
| 1263 | 1244 | |
| 1264 | | for( x = 0+48; x < 160+48; x++ ) |
| 1245 | for (x = 0 + 48; x < 160 + 48; x++) |
| 1265 | 1246 | { |
| 1266 | 1247 | rgb_t c1 = machine->pens[line1[x]]; |
| 1267 | 1248 | rgb_t c2 = machine->pens[line2[x]]; |
| 1268 | 1249 | rgb_t c3 = machine->pens[line3[x]]; |
| 1269 | 1250 | rgb_t c4 = machine->pens[line4[x]]; |
| 1270 | | *BITMAP_ADDR32( bitmap, pixelPlotY, pixelOffsetX + x) = |
| 1271 | | MAKE_RGB( ( RGB_RED(c1)/6 + RGB_RED(c2)/3 + RGB_RED(c3)/3 + RGB_RED(c4)/6 ), |
| 1272 | | ( RGB_GREEN(c1)/6 + RGB_GREEN(c2)/3 + RGB_GREEN(c3)/3 + RGB_GREEN(c4)/6 ), |
| 1273 | | ( RGB_BLUE(c1)/6 + RGB_BLUE(c2)/3 + RGB_BLUE(c3)/3 + RGB_BLUE(c4)/6 ) ); |
| 1251 | *BITMAP_ADDR32(bitmap, pixel_plot_y, pixel_offset_x + x) = |
| 1252 | MAKE_RGB((RGB_RED(c1) / 6 + RGB_RED(c2) / 3 + RGB_RED(c3) / 3 + RGB_RED(c4) / 6 ), |
| 1253 | (RGB_GREEN(c1) / 6 + RGB_GREEN(c2) / 3 + RGB_GREEN(c3) / 3 + RGB_GREEN(c4) / 6 ), |
| 1254 | (RGB_BLUE(c1) / 6 + RGB_BLUE(c2) / 3 + RGB_BLUE(c3) / 3 + RGB_BLUE(c4) / 6 ) ); |
| 1274 | 1255 | } |
| 1275 | 1256 | return; |
| 1276 | 1257 | } |
| 1277 | | blitLineBuffer = combineLineBuffer; |
| 1258 | blitline_buffer = combineline_buffer; |
| 1278 | 1259 | } |
| 1279 | 1260 | |
| 1280 | | for( x = 0; x < 256; x++ ) |
| 1261 | for (x = 0; x < 256; x++) |
| 1281 | 1262 | { |
| 1282 | | *BITMAP_ADDR32( bitmap, pixelPlotY + line, pixelOffsetX + x) = machine->pens[blitLineBuffer[x]]; |
| 1263 | *BITMAP_ADDR32(bitmap, pixel_plot_y + line, pixel_offset_x + x) = machine->pens[blitline_buffer[x]]; |
| 1283 | 1264 | } |
| 1284 | 1265 | } |
| 1285 | 1266 | |
| 1286 | 1267 | |
| 1287 | | static void sms_update_palette(void) |
| 1268 | static void sms_update_palette( smsvdp_t *smsvdp ) |
| 1288 | 1269 | { |
| 1289 | 1270 | int i; |
| 1290 | 1271 | |
| 1291 | 1272 | /* Exit if palette is has no changes */ |
| 1292 | | if (smsvdp.cram_dirty == 0) |
| 1273 | if (smsvdp->cram_dirty == 0) |
| 1293 | 1274 | { |
| 1294 | 1275 | return; |
| 1295 | 1276 | } |
| 1296 | | smsvdp.cram_dirty = 0; |
| 1277 | smsvdp->cram_dirty = 0; |
| 1297 | 1278 | |
| 1298 | | if ( smsvdp.vdp_mode != 4 && ! IS_GAMEGEAR_VDP ) |
| 1279 | if (smsvdp->vdp_mode != 4 && ! IS_GAMEGEAR_VDP) |
| 1299 | 1280 | { |
| 1300 | | for( i = 0; i < 16; i++ ) |
| 1281 | for(i = 0; i < 16; i++) |
| 1301 | 1282 | { |
| 1302 | | smsvdp.current_palette[i] = 64+i; |
| 1283 | smsvdp->current_palette[i] = 64 + i; |
| 1303 | 1284 | } |
| 1304 | 1285 | return; |
| 1305 | 1286 | } |
| 1306 | 1287 | |
| 1307 | | if ( IS_GAMEGEAR_VDP ) |
| 1288 | if (IS_GAMEGEAR_VDP) |
| 1308 | 1289 | { |
| 1309 | | if ( smsvdp.gg_sms_mode ) |
| 1290 | if (smsvdp->gg_sms_mode) |
| 1310 | 1291 | { |
| 1311 | | for ( i = 0; i < 32; i++ ) |
| 1292 | for (i = 0; i < 32; i++) |
| 1312 | 1293 | { |
| 1313 | | smsvdp.current_palette[i] = ( ( smsvdp.CRAM[i] & 0x30 ) << 6 ) | ( ( smsvdp.CRAM[i] & 0x0C ) << 4 ) | ( ( smsvdp.CRAM[i] & 0x03 ) << 2 ); |
| 1294 | smsvdp->current_palette[i] = ((smsvdp->CRAM[i] & 0x30) << 6) | ((smsvdp->CRAM[i] & 0x0c ) << 4) | ((smsvdp->CRAM[i] & 0x03) << 2); |
| 1314 | 1295 | } |
| 1315 | 1296 | } |
| 1316 | 1297 | else |
| 1317 | 1298 | { |
| 1318 | | for ( i = 0; i < 32; i++ ) |
| 1299 | for (i = 0; i < 32; i++) |
| 1319 | 1300 | { |
| 1320 | | smsvdp.current_palette[i] = ( ( smsvdp.CRAM[i*2+1] << 8 ) | smsvdp.CRAM[i*2] ) & 0x0FFF; |
| 1301 | smsvdp->current_palette[i] = ((smsvdp->CRAM[i * 2 + 1] << 8) | smsvdp->CRAM[i * 2]) & 0x0fff; |
| 1321 | 1302 | } |
| 1322 | 1303 | } |
| 1323 | 1304 | } |
| 1324 | 1305 | else |
| 1325 | 1306 | { |
| 1326 | | for ( i = 0; i < 32; i++ ) |
| 1307 | for (i = 0; i < 32; i++) |
| 1327 | 1308 | { |
| 1328 | | smsvdp.current_palette[i] = smsvdp.CRAM[i] & 0x3F; |
| 1309 | smsvdp->current_palette[i] = smsvdp->CRAM[i] & 0x3f; |
| 1329 | 1310 | } |
| 1330 | 1311 | } |
| 1331 | 1312 | } |
| 1332 | 1313 | |
| 1333 | 1314 | |
| 1334 | | VIDEO_UPDATE(sms) |
| 1315 | UINT32 smsvdp_update( const device_config *device, bitmap_t *bitmap, const rectangle *cliprect ) |
| 1335 | 1316 | { |
| 1317 | smsvdp_t *smsvdp = get_safe_token(device); |
| 1318 | const device_config *screen = video_screen_first(device->machine->config); |
| 1336 | 1319 | int width = video_screen_get_width(screen); |
| 1337 | 1320 | int height = video_screen_get_height(screen); |
| 1338 | 1321 | int x, y; |
| 1339 | 1322 | |
| 1340 | | if (smsvdp.prev_bitmap_saved) |
| 1323 | if (smsvdp->prev_bitmap_saved) |
| 1341 | 1324 | { |
| 1342 | 1325 | for (y = 0; y < height; y++) |
| 1343 | 1326 | { |
| 1344 | 1327 | for (x = 0; x < width; x++) |
| 1345 | 1328 | { |
| 1346 | | *BITMAP_ADDR32(bitmap, y, x) = (*BITMAP_ADDR32(tmpbitmap, y, x) + *BITMAP_ADDR32(smsvdp.prev_bitmap, y, x)) >> 2; |
| 1347 | | logerror("%x %x %x\n", *BITMAP_ADDR32(tmpbitmap, y, x), *BITMAP_ADDR32(smsvdp.prev_bitmap, y, x), (*BITMAP_ADDR32(tmpbitmap, y, x) + *BITMAP_ADDR32(smsvdp.prev_bitmap, y, x)) >> 2); |
| 1329 | *BITMAP_ADDR32(bitmap, y, x) = (*BITMAP_ADDR32(smsvdp->tmpbitmap, y, x) + *BITMAP_ADDR32(smsvdp->prev_bitmap, y, x)) >> 2; |
| 1330 | logerror("%x %x %x\n", *BITMAP_ADDR32(smsvdp->tmpbitmap, y, x), *BITMAP_ADDR32(smsvdp->prev_bitmap, y, x), (*BITMAP_ADDR32(smsvdp->tmpbitmap, y, x) + *BITMAP_ADDR32(smsvdp->prev_bitmap, y, x)) >> 2); |
| 1348 | 1331 | } |
| 1349 | 1332 | } |
| 1350 | 1333 | } |
| 1351 | 1334 | else |
| 1352 | 1335 | { |
| 1353 | | copybitmap(bitmap, tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1336 | copybitmap(bitmap, smsvdp->tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1354 | 1337 | } |
| 1355 | 1338 | |
| 1356 | | if (!smsvdp.prev_bitmap_saved) |
| 1339 | if (!smsvdp->prev_bitmap_saved) |
| 1357 | 1340 | { |
| 1358 | | copybitmap(smsvdp.prev_bitmap, tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1359 | | //smsvdp.prev_bitmap_saved = 1; |
| 1341 | copybitmap(smsvdp->prev_bitmap, smsvdp->tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1342 | //smsvdp->prev_bitmap_saved = 1; |
| 1360 | 1343 | } |
| 1361 | 1344 | |
| 1362 | 1345 | return 0; |
| 1363 | 1346 | } |
| 1364 | 1347 | |
| 1365 | 1348 | |
| 1349 | /***************************************************************************** |
| 1350 | DEVICE INTERFACE |
| 1351 | *****************************************************************************/ |
| 1352 | |
| 1353 | static DEVICE_START( smsvdp ) |
| 1354 | { |
| 1355 | smsvdp_t *smsvdp = get_safe_token(device); |
| 1356 | const smsvdp_interface *intf = get_interface(device); |
| 1357 | |
| 1358 | const device_config *screen = video_screen_first(device->machine->config); |
| 1359 | int width = video_screen_get_width(screen); |
| 1360 | int height = video_screen_get_height(screen); |
| 1361 | |
| 1362 | smsvdp->features = intf->model; |
| 1363 | smsvdp->int_callback = intf->int_callback; |
| 1364 | smsvdp->pause_callback = intf->pause_callback; |
| 1365 | |
| 1366 | /* Allocate video RAM */ |
| 1367 | smsvdp->VRAM = memory_region_alloc(device->machine, "vdp_vram", VRAM_SIZE, ROM_REQUIRED); |
| 1368 | smsvdp->CRAM = memory_region_alloc(device->machine, "vdp_cram", MAX_CRAM_SIZE, ROM_REQUIRED); |
| 1369 | smsvdp->line_buffer = auto_alloc_array(device->machine, int, 256 * 5); |
| 1370 | |
| 1371 | smsvdp->collision_buffer = auto_alloc_array(device->machine, UINT8, SMS_X_PIXELS); |
| 1372 | smsvdp->sms_frame_timing = auto_alloc_array(device->machine, UINT8, 7); |
| 1373 | |
| 1374 | /* Make temp bitmap for rendering */ |
| 1375 | smsvdp->tmpbitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1376 | |
| 1377 | smsvdp->prev_bitmap = auto_bitmap_alloc(device->machine, width, height, BITMAP_FORMAT_INDEXED32); |
| 1378 | |
| 1379 | |
| 1380 | smsvdp->smsvdp_display_timer = timer_alloc(device->machine, smsvdp_display_callback, smsvdp); |
| 1381 | timer_adjust_periodic(smsvdp->smsvdp_display_timer, video_screen_get_time_until_pos(screen, 0, 0), 0, video_screen_get_scan_period(screen)); |
| 1382 | |
| 1383 | state_save_register_device_item(device, 0, smsvdp->status); |
| 1384 | state_save_register_device_item(device, 0, smsvdp->reg9copy); |
| 1385 | state_save_register_device_item(device, 0, smsvdp->addrmode); |
| 1386 | state_save_register_device_item(device, 0, smsvdp->addr); |
| 1387 | state_save_register_device_item(device, 0, smsvdp->cram_mask); |
| 1388 | state_save_register_device_item(device, 0, smsvdp->cram_dirty); |
| 1389 | state_save_register_device_item(device, 0, smsvdp->pending); |
| 1390 | state_save_register_device_item(device, 0, smsvdp->buffer); |
| 1391 | state_save_register_device_item(device, 0, smsvdp->gg_sms_mode); |
| 1392 | state_save_register_device_item(device, 0, smsvdp->irq_state); |
| 1393 | state_save_register_device_item(device, 0, smsvdp->vdp_mode); |
| 1394 | state_save_register_device_item(device, 0, smsvdp->y_pixels); |
| 1395 | state_save_register_device_item(device, 0, smsvdp->line_counter); |
| 1396 | state_save_register_device_item(device, 0, smsvdp->hcounter); |
| 1397 | state_save_register_device_item(device, 0, smsvdp->prev_bitmap_saved); |
| 1398 | state_save_register_device_item_array(device, 0, smsvdp->reg); |
| 1399 | state_save_register_device_item_array(device, 0, smsvdp->current_palette); |
| 1400 | } |
| 1401 | |
| 1402 | static DEVICE_RESET( smsvdp ) |
| 1403 | { |
| 1404 | smsvdp_t *smsvdp = get_safe_token(device); |
| 1405 | int i; |
| 1406 | |
| 1407 | /* Most register are 0x00 at power-up */ |
| 1408 | for (i = 0; i < NUM_OF_REGISTER; i++) |
| 1409 | smsvdp->reg[i] = 0x00; |
| 1410 | |
| 1411 | smsvdp->reg[0x02] = 0x0e; |
| 1412 | smsvdp->reg[0x0a] = 0xff; |
| 1413 | |
| 1414 | smsvdp->status = 0; |
| 1415 | smsvdp->reg9copy = 0; |
| 1416 | smsvdp->addrmode = 0; |
| 1417 | smsvdp->addr = 0; |
| 1418 | smsvdp->gg_sms_mode = 0; |
| 1419 | smsvdp->cram_mask = (IS_GAMEGEAR_VDP && !smsvdp->gg_sms_mode) ? (GG_CRAM_SIZE - 1) : (SMS_CRAM_SIZE - 1); |
| 1420 | smsvdp->cram_dirty = 1; |
| 1421 | smsvdp->pending = 0; |
| 1422 | smsvdp->buffer = 0; |
| 1423 | smsvdp->irq_state = 0; |
| 1424 | smsvdp->line_counter = 0; |
| 1425 | smsvdp->prev_bitmap_saved = 0; |
| 1426 | |
| 1427 | /* for light gun input with "Hang-On & Safari Hunt", hcounter seems to |
| 1428 | need initialization to some value */ |
| 1429 | smsvdp->hcounter = 0x40; |
| 1430 | |
| 1431 | for (i = 0; i < 0x20; i++) |
| 1432 | smsvdp->current_palette[i] = 0; |
| 1433 | |
| 1434 | set_display_settings(device); |
| 1435 | |
| 1436 | /* Clear RAM */ |
| 1437 | memset(smsvdp->VRAM, 0, VRAM_SIZE); |
| 1438 | memset(smsvdp->CRAM, 0, MAX_CRAM_SIZE); |
| 1439 | memset(smsvdp->line_buffer, 0, 256 * 5 * sizeof(int)); |
| 1440 | } |
| 1441 | |
| 1442 | DEVICE_GET_INFO( smsvdp ) |
| 1443 | { |
| 1444 | switch (state) |
| 1445 | { |
| 1446 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1447 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(smsvdp_t); break; |
| 1448 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_VIDEO; break; |
| 1449 | |
| 1450 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1451 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(smsvdp); break; |
| 1452 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1453 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(smsvdp); break; |
| 1454 | |
| 1455 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1456 | case DEVINFO_STR_NAME: strcpy(info->s, "Sega Master SYstem / Game Gear VDP"); break; |
| 1457 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Sega MS VDP"); break; |
| 1458 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1459 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1460 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MAME / MESS Team"); break; |
| 1461 | } |
| 1462 | } |
src/mess/machine/sms.c
| r6078 | r6079 | |
| 9 | 9 | #define VERBOSE 0 |
| 10 | 10 | #define LOG(x) do { if (VERBOSE) logerror x; } while (0) |
| 11 | 11 | |
| 12 | | #define FLAG_GAMEGEAR 0x00020000 |
| 13 | | #define FLAG_BIOS_0400 0x00040000 |
| 14 | | #define FLAG_BIOS_2000 0x00080000 |
| 15 | | #define FLAG_BIOS_FULL 0x00100000 |
| 16 | | #define FLAG_FM 0x00200000 |
| 17 | | #define FLAG_REGION_JAPAN 0x00400000 |
| 12 | #define CF_CODEMASTERS_MAPPER 0x01 |
| 13 | #define CF_KOREAN_MAPPER 0x02 |
| 14 | #define CF_93C46_EEPROM 0x04 |
| 15 | #define CF_ONCART_RAM 0x08 |
| 16 | #define CF_GG_SMS_MODE 0x10 |
| 18 | 17 | |
| 18 | #define MAX_CARTRIDGES 16 |
| 19 | 19 | |
| 20 | | #define IS_GAMEGEAR ( sms_state.flags & FLAG_GAMEGEAR ) |
| 21 | | #define HAS_BIOS_0400 ( sms_state.flags & FLAG_BIOS_0400 ) |
| 22 | | #define HAS_BIOS_2000 ( sms_state.flags & FLAG_BIOS_2000 ) |
| 23 | | #define HAS_BIOS_FULL ( sms_state.flags & FLAG_BIOS_FULL ) |
| 24 | | #define HAS_BIOS ( sms_state.flags & ( FLAG_BIOS_0400 | FLAG_BIOS_2000 | FLAG_BIOS_FULL ) ) |
| 25 | | #define HAS_FM ( sms_state.flags & FLAG_FM ) |
| 26 | | #define IS_REGION_JAPAN ( sms_state.flags & FLAG_REGION_JAPAN ) |
| 27 | | |
| 28 | | |
| 29 | | #define CF_CODEMASTERS_MAPPER 0x01 |
| 30 | | #define CF_KOREAN_MAPPER 0x02 |
| 31 | | #define CF_93C46_EEPROM 0x04 |
| 32 | | #define CF_ONCART_RAM 0x08 |
| 33 | | #define CF_GG_SMS_MODE 0x10 |
| 34 | | |
| 35 | | #define MAX_CARTRIDGES 16 |
| 36 | | |
| 37 | | |
| 38 | 20 | typedef struct _sms_driver_data sms_driver_data; |
| 39 | 21 | struct _sms_driver_data { |
| 40 | | UINT8 BiosPageCount; |
| 41 | | UINT8 FMDetect; |
| 42 | | UINT8 Version; |
| 43 | | int Paused; |
| 44 | | UINT8 biosPort; |
| 45 | | UINT32 flags; |
| 46 | | UINT8 *BIOS; |
| 47 | | UINT8 *mapper_ram; |
| 48 | | UINT8 mapper[4]; |
| 49 | | UINT8 *banking_bios[5]; /* we are going to use 1-4, same as bank numbers */ |
| 50 | | UINT8 *banking_cart[5]; /* we are going to use 1-4, same as bank numbers */ |
| 51 | | UINT8 *banking_none[5]; /* we are going to use 1-4, same as bank numbers */ |
| 52 | | UINT8 ggSIO[5]; |
| 53 | | UINT8 store_control; |
| 54 | | UINT8 input_port0; |
| 55 | | UINT8 input_port1; |
| 22 | UINT8 bios_page_count; |
| 23 | UINT8 fm_detect; |
| 24 | UINT8 ctrl_reg; |
| 25 | int paused; |
| 26 | UINT8 bios_port; |
| 27 | UINT8 *BIOS; |
| 28 | UINT8 *mapper_ram; |
| 29 | UINT8 mapper[4]; |
| 30 | UINT8 *banking_bios[5]; /* we are going to use 1-4, same as bank numbers */ |
| 31 | UINT8 *banking_cart[5]; /* we are going to use 1-4, same as bank numbers */ |
| 32 | UINT8 *banking_none[5]; /* we are going to use 1-4, same as bank numbers */ |
| 33 | UINT8 gg_sio[5]; |
| 34 | UINT8 store_control; |
| 35 | UINT8 input_port0; |
| 36 | UINT8 input_port1; |
| 56 | 37 | |
| 38 | /* Model identifiers */ |
| 39 | UINT8 is_gamegear; |
| 40 | UINT8 is_region_japan; |
| 41 | UINT8 has_bios_0400; |
| 42 | UINT8 has_bios_2000; |
| 43 | UINT8 has_bios_full; |
| 44 | UINT8 has_bios; |
| 45 | UINT8 has_fm; |
| 46 | |
| 57 | 47 | /* Data needed for Rapid Fire Unit support */ |
| 58 | | emu_timer *rapid_fire_timer; |
| 59 | | UINT8 rapid_fire_state_1; |
| 60 | | UINT8 rapid_fire_state_2; |
| 61 | | |
| 48 | emu_timer *rapid_fire_timer; |
| 49 | UINT8 rapid_fire_state_1; |
| 50 | UINT8 rapid_fire_state_2; |
| 51 | |
| 62 | 52 | /* Data needed for Paddle Control controller */ |
| 63 | | UINT32 last_paddle_read_time; |
| 64 | | UINT8 paddle_read_state; |
| 65 | | |
| 53 | UINT32 last_paddle_read_time; |
| 54 | UINT8 paddle_read_state; |
| 55 | |
| 66 | 56 | /* Data needed for Sports Pad controller */ |
| 67 | | UINT32 last_sports_pad_time_1; |
| 68 | | UINT32 last_sports_pad_time_2; |
| 69 | | UINT8 sports_pad_state_1; |
| 70 | | UINT8 sports_pad_state_2; |
| 71 | | UINT8 sports_pad_last_data_1; |
| 72 | | UINT8 sports_pad_last_data_2; |
| 73 | | UINT8 sports_pad_1_x; |
| 74 | | UINT8 sports_pad_1_y; |
| 75 | | UINT8 sports_pad_2_x; |
| 76 | | UINT8 sports_pad_2_y; |
| 57 | UINT32 last_sports_pad_time_1; |
| 58 | UINT32 last_sports_pad_time_2; |
| 59 | UINT8 sports_pad_state_1; |
| 60 | UINT8 sports_pad_state_2; |
| 61 | UINT8 sports_pad_last_data_1; |
| 62 | UINT8 sports_pad_last_data_2; |
| 63 | UINT8 sports_pad_1_x; |
| 64 | UINT8 sports_pad_1_y; |
| 65 | UINT8 sports_pad_2_x; |
| 66 | UINT8 sports_pad_2_y; |
| 67 | |
| 68 | /* Data needed for Light Phaser */ |
| 69 | UINT8 lphaser_latch; |
| 70 | UINT8 lphaser_1_x; |
| 71 | UINT8 lphaser_1_y; |
| 72 | UINT8 lphaser_2_x; |
| 73 | UINT8 lphaser_2_y; |
| 74 | UINT8 lphaser_x_offs; /* Needed to 'calibrate' lphaser; set at cart loading */ |
| 77 | 75 | |
| 78 | 76 | /* Cartridge slot info */ |
| 79 | | UINT8 current_cartridge; |
| 77 | UINT8 current_cartridge; |
| 80 | 78 | struct |
| 81 | 79 | { |
| 82 | | UINT8 *ROM; /* Pointer to ROM image data */ |
| 83 | | UINT32 size; /* Size of the ROM image */ |
| 84 | | UINT8 features; /* on-cartridge special hardware */ |
| 85 | | UINT8 *cartSRAM; /* on-cartridge SRAM */ |
| 86 | | UINT8 sram_save; /* should be the contents of the on-cartridge SRAM be saved */ |
| 87 | | UINT8 *cartRAM; /* additional on-cartridge RAM (64KB for Ernie Els Golf) */ |
| 88 | | UINT32 ram_size; /* size of the on-cartridge RAM */ |
| 89 | | UINT8 ram_page; /* currently swapped in cartridge RAM */ |
| 80 | UINT8 *ROM; /* Pointer to ROM image data */ |
| 81 | UINT32 size; /* Size of the ROM image */ |
| 82 | UINT8 features; /* on-cartridge special hardware */ |
| 83 | UINT8 *cartSRAM; /* on-cartridge SRAM */ |
| 84 | UINT8 sram_save; /* should be the contents of the on-cartridge SRAM be saved */ |
| 85 | UINT8 *cartRAM; /* additional on-cartridge RAM (64KB for Ernie Els Golf) */ |
| 86 | UINT32 ram_size; /* size of the on-cartridge RAM */ |
| 87 | UINT8 ram_page; /* currently swapped in cartridge RAM */ |
| 90 | 88 | } cartridge[MAX_CARTRIDGES]; |
| 91 | 89 | }; |
| 92 | 90 | |
| 93 | 91 | static sms_driver_data sms_state; |
| 94 | 92 | |
| 93 | |
| 95 | 94 | static void setup_rom(const address_space *space); |
| 96 | 95 | |
| 97 | 96 | |
| 98 | 97 | static TIMER_CALLBACK( rapid_fire_callback ) |
| 99 | 98 | { |
| 100 | | sms_state.rapid_fire_state_1 ^= 0xFF; |
| 101 | | sms_state.rapid_fire_state_2 ^= 0xFF; |
| 99 | sms_state.rapid_fire_state_1 ^= 0xff; |
| 100 | sms_state.rapid_fire_state_2 ^= 0xff; |
| 102 | 101 | } |
| 103 | 102 | |
| 104 | 103 | |
| 105 | 104 | static WRITE8_HANDLER( sms_input_write ) |
| 106 | 105 | { |
| 107 | | switch( offset ) |
| 106 | switch (offset) |
| 108 | 107 | { |
| 109 | 108 | case 0: |
| 110 | | switch( input_port_read_safe(space->machine, "CTRLSEL", 0x00) & 0x0F ) |
| 109 | switch (input_port_read_safe(space->machine, "CTRLSEL", 0x00) & 0x0f) |
| 111 | 110 | { |
| 112 | 111 | case 0x03: /* Sports Pad */ |
| 113 | | if ( data != sms_state.sports_pad_last_data_1 ) |
| 112 | if (data != sms_state.sports_pad_last_data_1) |
| 114 | 113 | { |
| 115 | 114 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 116 | 115 | |
| 117 | 116 | sms_state.sports_pad_last_data_1 = data; |
| 118 | | if ( cpu_cycles - sms_state.last_sports_pad_time_1 > 512 ) |
| 117 | if (cpu_cycles - sms_state.last_sports_pad_time_1 > 512) |
| 119 | 118 | { |
| 120 | 119 | sms_state.sports_pad_state_1 = 3; |
| 121 | 120 | sms_state.sports_pad_1_x = input_port_read(space->machine, "SPORT0"); |
| 122 | 121 | sms_state.sports_pad_1_y = input_port_read(space->machine, "SPORT1"); |
| 123 | 122 | } |
| 124 | 123 | sms_state.last_sports_pad_time_1 = cpu_cycles; |
| 125 | | sms_state.sports_pad_state_1 = ( sms_state.sports_pad_state_1 + 1 ) & 3; |
| 124 | sms_state.sports_pad_state_1 = (sms_state.sports_pad_state_1 + 1) & 3; |
| 126 | 125 | } |
| 127 | 126 | break; |
| 128 | 127 | } |
| 129 | 128 | break; |
| 130 | 129 | |
| 131 | 130 | case 1: |
| 132 | | switch( input_port_read_safe(space->machine, "CTRLSEL", 0x00) >> 4 ) |
| 131 | switch (input_port_read_safe(space->machine, "CTRLSEL", 0x00) >> 4) |
| 133 | 132 | { |
| 134 | 133 | case 0x03: /* Sports Pad */ |
| 135 | | if ( data != sms_state.sports_pad_last_data_2 ) |
| 134 | if (data != sms_state.sports_pad_last_data_2) |
| 136 | 135 | { |
| 137 | 136 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 138 | 137 | |
| 139 | 138 | sms_state.sports_pad_last_data_2 = data; |
| 140 | | if ( cpu_cycles - sms_state.last_sports_pad_time_2 > 2048 ) |
| 139 | if (cpu_cycles - sms_state.last_sports_pad_time_2 > 2048) |
| 141 | 140 | { |
| 142 | 141 | sms_state.sports_pad_state_2 = 3; |
| 143 | 142 | sms_state.sports_pad_2_x = input_port_read(space->machine, "SPORT2"); |
| 144 | 143 | sms_state.sports_pad_2_y = input_port_read(space->machine, "SPORT3"); |
| 145 | 144 | } |
| 146 | 145 | sms_state.last_sports_pad_time_2 = cpu_cycles; |
| 147 | | sms_state.sports_pad_state_2 = ( sms_state.sports_pad_state_2 + 1 ) & 3; |
| 146 | sms_state.sports_pad_state_2 = (sms_state.sports_pad_state_2 + 1) & 3; |
| 148 | 147 | } |
| 149 | 148 | break; |
| 150 | 149 | } |
| r6078 | r6079 | |
| 152 | 151 | } |
| 153 | 152 | } |
| 154 | 153 | |
| 155 | | static void sms_get_inputs(const address_space *space) |
| 154 | static TIMER_CALLBACK( lightgun_tick ) |
| 156 | 155 | { |
| 156 | if ((input_port_read_safe(machine, "CTRLSEL", 0x00) & 0x0f) == 0x01) |
| 157 | { |
| 158 | /* enable crosshair */ |
| 159 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_ALL); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | /* disable crosshair */ |
| 164 | crosshair_set_screen(machine, 0, CROSSHAIR_SCREEN_NONE); |
| 165 | } |
| 166 | |
| 167 | if ((input_port_read_safe(machine, "CTRLSEL", 0x00) & 0xf0) == 0x10) |
| 168 | { |
| 169 | /* enable crosshair */ |
| 170 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_ALL); |
| 171 | } |
| 172 | else |
| 173 | { |
| 174 | /* disable crosshair */ |
| 175 | crosshair_set_screen(machine, 1, CROSSHAIR_SCREEN_NONE); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | |
| 180 | /* FIXME: this function is a hack. For Light Phaser X pos sms_vdp_hcount_latch |
| 181 | function should be used instead, but emulation (timming?) needs to improve. */ |
| 182 | void sms_vdp_hcount_lphaser( running_machine *machine, int hpos) |
| 183 | { |
| 184 | UINT8 tmp = ((hpos - 46) >> 1) & 0xff; |
| 185 | const device_config *smsvdp = devtag_get_device(machine, "sms_vdp"); |
| 186 | |
| 187 | //printf ("sms_vdp_hcount_lphaser: hpos %3d => hcount %2X\n", hpos, tmp); |
| 188 | sms_vdp_hcount_latch_w(smsvdp, 0, tmp); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | static UINT8 sms_vdp_hcount( running_machine *machine ) |
| 193 | { |
| 194 | UINT8 tmp; |
| 195 | UINT64 calc_cycles; |
| 196 | attotime time_end; |
| 197 | const device_config *screen = video_screen_first(machine->config); |
| 198 | int vpos = video_screen_get_vpos(screen); |
| 199 | int width = video_screen_get_width(screen); |
| 200 | |
| 201 | /* this is simpler and independent of other clocks */ |
| 202 | //tmp = ( (hpos - 46) >> 1 ) & 0xFF; |
| 203 | |
| 204 | /* ... but this is closer to the behavior described by Flubba */ |
| 205 | /* and makes use of his equation posted at SMSPower forum. */ |
| 206 | time_end = video_screen_get_time_until_pos(screen, vpos, width - 1); |
| 207 | calc_cycles = cpu_attotime_to_clocks(cputag_get_cpu(machine, "maincpu"), time_end); |
| 208 | tmp = ((590 - (calc_cycles * 3)) / 4) & 0xff; |
| 209 | |
| 210 | //printf ("sms_vdp_hcount: hpos %3d => hcount %2X\n", hpos, tmp); |
| 211 | return tmp; |
| 212 | } |
| 213 | |
| 214 | |
| 215 | static void sms_vdp_hcount_latch( running_machine *machine ) |
| 216 | { |
| 217 | UINT8 value = sms_vdp_hcount(machine); |
| 218 | const device_config *smsvdp = devtag_get_device(machine, "sms_vdp"); |
| 219 | |
| 220 | sms_vdp_hcount_latch_w(smsvdp, 0, value); |
| 221 | } |
| 222 | |
| 223 | static int lphaser_sensor_is_on( running_machine *machine, int x, int y ) |
| 224 | { |
| 225 | const device_config *screen = video_screen_first(machine->config); |
| 226 | int dx, dy; |
| 227 | //const int r_x_r = 20 * 20; /* radius^2 */ |
| 228 | int hpos, vpos; |
| 229 | |
| 230 | if (x < LBORDER_START + LBORDER_X_PIXELS || x >= LBORDER_START + LBORDER_X_PIXELS + 256) |
| 231 | { |
| 232 | sms_state.lphaser_latch = 0; |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | hpos = video_screen_get_hpos(screen); |
| 237 | vpos = video_screen_get_vpos(screen); |
| 238 | |
| 239 | /* some offset seems needed for sms_vdp_hcount_latch() */ |
| 240 | //hpos -= 44; |
| 241 | |
| 242 | dx = x - hpos; |
| 243 | dy = y - vpos; |
| 244 | |
| 245 | //printf ("Light Phaser polling at %3d x %3d for shot %3d x %3d\n", hpos, vpos, x, y); |
| 246 | |
| 247 | /* SMSPower Wiki: the Light Phaser sensor "sees" a circular portion of the screen */ |
| 248 | //if ( (dx * dx) + (dy * dy) - (r_x_r) <= 0 ) |
| 249 | if (abs(dy) <= 5 && abs(dx) <= 60) /* simpler method used by SMSPlus-GX */ |
| 250 | { |
| 251 | /* avoid latching hcount more than once in a line */ |
| 252 | if (sms_state.lphaser_latch == 0) |
| 253 | { |
| 254 | sms_state.lphaser_latch = 1; |
| 255 | //sms_vdp_hcount_latch(screen); |
| 256 | /* FIXME: sms_vdp_hcount_lphaser() is a hack necessary while normal latch gives too inconstant shot positions */ |
| 257 | x += sms_state.lphaser_x_offs; |
| 258 | sms_vdp_hcount_lphaser(machine, x); |
| 259 | } |
| 260 | |
| 261 | return 1; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | sms_state.lphaser_latch = 0; |
| 266 | return 0; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | |
| 271 | static int screen_hpos_nonscaled( const device_config *screen, int scaled_hpos ) |
| 272 | { |
| 273 | const rectangle *visarea = video_screen_get_visible_area(screen); |
| 274 | int offset_x = (scaled_hpos * (visarea->max_x - visarea->min_x)) / 255; |
| 275 | return visarea->min_x + offset_x; |
| 276 | } |
| 277 | |
| 278 | |
| 279 | static int screen_vpos_nonscaled( const device_config *screen, int scaled_vpos ) |
| 280 | { |
| 281 | const rectangle *visarea = video_screen_get_visible_area(screen); |
| 282 | int offset_y = (scaled_vpos * (visarea->max_y - visarea->min_y)) / 255; |
| 283 | return visarea->min_y + offset_y; |
| 284 | } |
| 285 | |
| 286 | |
| 287 | static void sms_get_inputs( const address_space *space ) |
| 288 | { |
| 157 | 289 | UINT8 data = 0x00; |
| 290 | UINT8 data_x = 0x00; |
| 291 | UINT8 data_y = 0x00; |
| 158 | 292 | UINT32 cpu_cycles = cpu_get_total_cycles(space->cpu); |
| 159 | 293 | running_machine *machine = space->machine; |
| 160 | 294 | |
| 161 | | sms_state.input_port0 = 0xFF; |
| 162 | | sms_state.input_port1 = 0xFF; |
| 295 | sms_state.input_port0 = 0xff; |
| 296 | sms_state.input_port1 = 0xff; |
| 163 | 297 | |
| 164 | | if ( cpu_cycles - sms_state.last_paddle_read_time > 256 ) { |
| 165 | | sms_state.paddle_read_state ^= 0xFF; |
| 298 | if (cpu_cycles - sms_state.last_paddle_read_time > 256) |
| 299 | { |
| 300 | sms_state.paddle_read_state ^= 0xff; |
| 166 | 301 | sms_state.last_paddle_read_time = cpu_cycles; |
| 167 | 302 | } |
| 168 | 303 | |
| 304 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 305 | timer_set(machine, attotime_zero, NULL, 0, lightgun_tick); |
| 306 | |
| 169 | 307 | /* Player 1 */ |
| 170 | | switch( input_port_read_safe(machine, "CTRLSEL", 0x00) & 0x0F ) |
| 308 | switch (input_port_read_safe(machine, "CTRLSEL", 0x00) & 0x0f) |
| 171 | 309 | { |
| 172 | 310 | case 0x00: /* Joystick */ |
| 173 | 311 | data = input_port_read(machine, "PORT_DC"); |
| 174 | | /* Rapid Fire setting for Button A */ |
| 175 | | if ( !(data & 0x10 ) && ( input_port_read(machine, "RFU") & 0x01) ) |
| 176 | | { |
| 312 | /* Check Rapid Fire setting for Button A */ |
| 313 | if (!(data & 0x10) && (input_port_read(machine, "RFU") & 0x01)) |
| 177 | 314 | data |= sms_state.rapid_fire_state_1 & 0x10; |
| 178 | | } |
| 315 | |
| 179 | 316 | /* Check Rapid Fire setting for Button B */ |
| 180 | | if ( !(data & 0x20) && (input_port_read(machine, "RFU") & 0x02) ) |
| 181 | | { |
| 317 | if (!(data & 0x20) && (input_port_read(machine, "RFU") & 0x02)) |
| 182 | 318 | data |= sms_state.rapid_fire_state_1 & 0x20; |
| 183 | | } |
| 184 | | sms_state.input_port0 = ( sms_state.input_port0 & 0xC0 ) | ( data & 0x3F ); |
| 319 | |
| 320 | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x3f); |
| 185 | 321 | break; |
| 186 | 322 | |
| 187 | 323 | case 0x01: /* Light Phaser */ |
| 324 | data = (input_port_read(machine, "CTRLIPT") & 0x01) << 4; |
| 325 | if (!(data & 0x10)) |
| 326 | { |
| 327 | if (input_port_read(machine, "RFU") & 0x01) |
| 328 | data |= sms_state.rapid_fire_state_1 & 0x10; |
| 329 | |
| 330 | data_x = input_port_read(machine, "LPHASER0"); |
| 331 | data_y = input_port_read(machine, "LPHASER1"); |
| 332 | |
| 333 | sms_state.lphaser_1_x = screen_hpos_nonscaled(machine->primary_screen, data_x); |
| 334 | sms_state.lphaser_1_y = screen_vpos_nonscaled(machine->primary_screen, data_y); |
| 335 | } |
| 336 | /* just consider the button (trigger) bit */ |
| 337 | data |= ~0x10; |
| 338 | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x3f); |
| 188 | 339 | break; |
| 189 | 340 | |
| 190 | 341 | case 0x02: /* Paddle Control */ |
| 191 | 342 | /* Get button A state */ |
| 192 | 343 | data = input_port_read(machine, "PADDLE0"); |
| 193 | | if ( sms_state.paddle_read_state ) |
| 194 | | { |
| 344 | |
| 345 | if (sms_state.paddle_read_state) |
| 195 | 346 | data = data >> 4; |
| 196 | | } |
| 197 | | sms_state.input_port0 = ( sms_state.input_port0 & 0xC0 ) | ( data & 0x0F ) | ( sms_state.paddle_read_state & 0x20 ) |
| 198 | | | ( ( input_port_read(machine, "CTRLIPT") & 0x02 ) << 3 ); |
| 347 | |
| 348 | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | (data & 0x0f) | (sms_state.paddle_read_state & 0x20) |
| 349 | | ((input_port_read(machine, "CTRLIPT") & 0x02) << 3); |
| 199 | 350 | break; |
| 200 | 351 | |
| 201 | 352 | case 0x03: /* Sega Sports Pad */ |
| 202 | | switch( sms_state.sports_pad_state_1 ) |
| 353 | switch (sms_state.sports_pad_state_1) |
| 203 | 354 | { |
| 204 | 355 | case 0: |
| 205 | | data = ( sms_state.sports_pad_1_x >> 4 ) & 0x0F; |
| 356 | data = (sms_state.sports_pad_1_x >> 4) & 0x0f; |
| 206 | 357 | break; |
| 207 | 358 | case 1: |
| 208 | | data = sms_state.sports_pad_1_x & 0x0F; |
| 359 | data = sms_state.sports_pad_1_x & 0x0f; |
| 209 | 360 | break; |
| 210 | 361 | case 2: |
| 211 | | data = ( sms_state.sports_pad_1_y >> 4 ) & 0x0F; |
| 362 | data = (sms_state.sports_pad_1_y >> 4) & 0x0f; |
| 212 | 363 | break; |
| 213 | 364 | case 3: |
| 214 | | data = sms_state.sports_pad_1_y & 0x0F; |
| 365 | data = sms_state.sports_pad_1_y & 0x0f; |
| 215 | 366 | break; |
| 216 | 367 | } |
| 217 | | sms_state.input_port0 = ( sms_state.input_port0 & 0xC0 ) | data | ( ( input_port_read(machine, "CTRLIPT") & 0x0C ) << 2 ); |
| 368 | sms_state.input_port0 = (sms_state.input_port0 & 0xc0) | data | ((input_port_read(machine, "CTRLIPT") & 0x0c) << 2); |
| 218 | 369 | break; |
| 219 | 370 | } |
| 220 | 371 | |
| 221 | 372 | /* Player 2 */ |
| 222 | | switch( input_port_read_safe(machine, "CTRLSEL", 0x00) >> 4 ) |
| 373 | switch (input_port_read_safe(machine, "CTRLSEL", 0x00) & 0xf0) |
| 223 | 374 | { |
| 224 | 375 | case 0x00: /* Joystick */ |
| 225 | 376 | data = input_port_read(machine, "PORT_DC"); |
| 226 | | sms_state.input_port0 = ( sms_state.input_port0 & 0x3F ) | ( data & 0xC0 ); |
| 377 | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | (data & 0xc0); |
| 378 | |
| 227 | 379 | data = input_port_read(machine, "PORT_DD"); |
| 228 | | if ( !(data & 0x04) && (input_port_read(machine, "RFU") & 0x04) ) |
| 229 | | { |
| 380 | /* Check Rapid Fire setting for Button A */ |
| 381 | if (!(data & 0x04) && (input_port_read(machine, "RFU") & 0x04)) |
| 230 | 382 | data |= sms_state.rapid_fire_state_2 & 0x04; |
| 231 | | } |
| 232 | | if ( !(data & 0x08) && (input_port_read(machine, "RFU") & 0x08) ) |
| 233 | | { |
| 383 | |
| 384 | /* Check Rapid Fire setting for Button B */ |
| 385 | if (!(data & 0x08) && (input_port_read(machine, "RFU") & 0x08)) |
| 234 | 386 | data |= sms_state.rapid_fire_state_2 & 0x08; |
| 235 | | } |
| 236 | | sms_state.input_port1 = ( sms_state.input_port1 & 0xF0 ) | ( data & 0x0F ); |
| 387 | |
| 388 | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data & 0x0f); |
| 237 | 389 | break; |
| 238 | 390 | |
| 239 | | case 0x01: /* Light Phaser */ |
| 391 | case 0x10: /* Light Phaser */ |
| 392 | data = (input_port_read(machine, "CTRLIPT") & 0x10) >> 2; |
| 393 | if (!(data & 0x04)) |
| 394 | { |
| 395 | if (input_port_read(machine, "RFU") & 0x04) |
| 396 | data |= sms_state.rapid_fire_state_2 & 0x04; |
| 397 | |
| 398 | data_x = input_port_read(machine, "LPHASER2"); |
| 399 | data_y = input_port_read(machine, "LPHASER3"); |
| 400 | |
| 401 | sms_state.lphaser_2_x = screen_hpos_nonscaled (machine->primary_screen, data_x); |
| 402 | sms_state.lphaser_2_y = screen_vpos_nonscaled (machine->primary_screen, data_y); |
| 403 | } |
| 404 | /* just consider the button (trigger) bit */ |
| 405 | data |= ~0x04; |
| 406 | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data & 0x0f); |
| 240 | 407 | break; |
| 241 | 408 | |
| 242 | | case 0x02: /* Paddle Control */ |
| 409 | case 0x20: /* Paddle Control */ |
| 243 | 410 | /* Get button A state */ |
| 244 | 411 | data = input_port_read(machine, "PADDLE1"); |
| 245 | | if ( sms_state.paddle_read_state ) |
| 246 | | { |
| 412 | if (sms_state.paddle_read_state) |
| 247 | 413 | data = data >> 4; |
| 248 | | } |
| 249 | | sms_state.input_port0 = ( sms_state.input_port0 & 0x3F ) | ( ( data & 0x03 ) << 6 ); |
| 250 | | sms_state.input_port1 = ( sms_state.input_port1 & 0xF0 ) | ( ( data & 0x0C ) >> 2 ) | ( sms_state.paddle_read_state & 0x08 ) |
| 251 | | | ( ( input_port_read(machine, "CTRLIPT") & 0x20 ) >> 3 ); |
| 414 | |
| 415 | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 416 | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | ((data & 0x0c) >> 2) | (sms_state.paddle_read_state & 0x08) |
| 417 | | ((input_port_read(machine, "CTRLIPT") & 0x20) >> 3); |
| 252 | 418 | break; |
| 253 | 419 | |
| 254 | | case 0x03: /* Sega Sports Pad */ |
| 255 | | switch( sms_state.sports_pad_state_2 ) |
| 420 | case 0x30: /* Sega Sports Pad */ |
| 421 | switch (sms_state.sports_pad_state_2) |
| 256 | 422 | { |
| 257 | 423 | case 0: |
| 258 | | data = sms_state.sports_pad_2_x & 0x0F; |
| 424 | data = sms_state.sports_pad_2_x & 0x0f; |
| 259 | 425 | break; |
| 260 | 426 | case 1: |
| 261 | | data = ( sms_state.sports_pad_2_x >> 4 ) & 0x0F; |
| 427 | data = (sms_state.sports_pad_2_x >> 4) & 0x0f; |
| 428 | break; |
| 262 | 429 | case 2: |
| 263 | | data = sms_state.sports_pad_2_y & 0x0F; |
| 430 | data = sms_state.sports_pad_2_y & 0x0f; |
| 264 | 431 | break; |
| 265 | 432 | case 3: |
| 266 | | data = ( sms_state.sports_pad_2_y >> 4 ) & 0x0F; |
| 433 | data = (sms_state.sports_pad_2_y >> 4) & 0x0f; |
| 267 | 434 | break; |
| 268 | 435 | } |
| 269 | | sms_state.input_port0 = ( sms_state.input_port0 & 0x3F ) | ( ( data & 0x03 ) << 6 ); |
| 270 | | sms_state.input_port1 = ( sms_state.input_port1 & 0xF0 ) | ( data >> 2 ) | ( ( input_port_read(machine, "CTRLIPT") & 0xC0 ) >> 4 ); |
| 436 | sms_state.input_port0 = (sms_state.input_port0 & 0x3f) | ((data & 0x03) << 6); |
| 437 | sms_state.input_port1 = (sms_state.input_port1 & 0xf0) | (data >> 2) | ((input_port_read(machine, "CTRLIPT") & 0xc0) >> 4); |
| 271 | 438 | break; |
| 272 | 439 | } |
| 273 | 440 | } |
| 274 | 441 | |
| 275 | 442 | |
| 276 | | WRITE8_HANDLER(sms_fm_detect_w) |
| 443 | WRITE8_HANDLER( sms_fm_detect_w ) |
| 277 | 444 | { |
| 278 | | if ( HAS_FM ) |
| 279 | | { |
| 280 | | sms_state.FMDetect = (data & 0x01); |
| 281 | | } |
| 445 | if (sms_state.has_fm) |
| 446 | sms_state.fm_detect = (data & 0x01); |
| 282 | 447 | } |
| 283 | 448 | |
| 284 | 449 | |
| 285 | | READ8_HANDLER(sms_fm_detect_r) |
| 450 | READ8_HANDLER( sms_fm_detect_r ) |
| 286 | 451 | { |
| 287 | | if ( HAS_FM ) |
| 452 | if (sms_state.has_fm) |
| 288 | 453 | { |
| 289 | | return sms_state.FMDetect; |
| 454 | return sms_state.fm_detect; |
| 290 | 455 | } |
| 291 | 456 | else |
| 292 | 457 | { |
| 293 | | if ( sms_state.biosPort & IO_CHIP ) |
| 458 | if (sms_state.bios_port & IO_CHIP) |
| 294 | 459 | { |
| 295 | | return 0xFF; |
| 460 | return 0xff; |
| 296 | 461 | } |
| 297 | 462 | else |
| 298 | 463 | { |
| r6078 | r6079 | |
| 302 | 467 | } |
| 303 | 468 | } |
| 304 | 469 | |
| 305 | | |
| 306 | | WRITE8_HANDLER(sms_version_w) |
| 470 | WRITE8_HANDLER( sms_io_control_w ) |
| 307 | 471 | { |
| 308 | | if ((data & 0x01) && (data & 0x04)) |
| 472 | if (data & 0x08) |
| 309 | 473 | { |
| 310 | | sms_state.Version = (data & 0xA0); |
| 474 | /* check if TH pin level is high (1) and was low last time */ |
| 475 | if (data & 0x80 && !(sms_state.ctrl_reg & 0x80)) |
| 476 | { |
| 477 | sms_vdp_hcount_latch(space->machine); |
| 478 | } |
| 479 | sms_input_write(space, 0, (data & 0x20) >> 5); |
| 311 | 480 | } |
| 312 | | if ( data & 0x08 ) |
| 313 | | { |
| 314 | | sms_input_write( space, 0, ( data & 0x20 ) >> 5 ); |
| 315 | | } |
| 316 | | if ( data & 0x02 ) |
| 317 | | { |
| 318 | | sms_input_write( space, 1, ( data & 0x80 ) >> 7 ); |
| 319 | | } |
| 320 | | } |
| 321 | 481 | |
| 322 | | |
| 323 | | READ8_HANDLER(sms_version_r) |
| 324 | | { |
| 325 | | UINT8 temp; |
| 326 | | |
| 327 | | if (sms_state.biosPort & IO_CHIP) |
| 482 | if (data & 0x02) |
| 328 | 483 | { |
| 329 | | return (0xFF); |
| 484 | if (data & 0x20 && !(sms_state.ctrl_reg & 0x20)) |
| 485 | { |
| 486 | sms_vdp_hcount_latch(space->machine); |
| 487 | } |
| 488 | sms_input_write(space, 1, (data & 0x80) >> 7); |
| 330 | 489 | } |
| 331 | 490 | |
| 332 | | /* Move bits 7,5 of port 3F into bits 7, 6 */ |
| 333 | | temp = (sms_state.Version & 0x80) | (sms_state.Version & 0x20) << 1; |
| 334 | | |
| 335 | | /* Inverse version detect value for Japanese machines */ |
| 336 | | if ( IS_REGION_JAPAN ) |
| 337 | | { |
| 338 | | temp ^= 0xC0; |
| 339 | | } |
| 340 | | |
| 341 | | /* Merge version data with input port #2 data */ |
| 342 | | sms_get_inputs(space); |
| 343 | | temp = (temp & 0xC0) | (sms_state.input_port1 & 0x3F); |
| 344 | | |
| 345 | | return (temp); |
| 491 | sms_state.ctrl_reg = data; |
| 346 | 492 | } |
| 347 | 493 | |
| 348 | 494 | |
| 349 | | READ8_HANDLER(sms_count_r) |
| 495 | READ8_HANDLER( sms_count_r ) |
| 350 | 496 | { |
| 351 | | if ( offset & 0x01 ) |
| 352 | | { |
| 353 | | return sms_vdp_hcount_r(space, offset); |
| 354 | | } |
| 497 | const device_config *smsvdp = devtag_get_device(space->machine, "sms_vdp"); |
| 498 | |
| 499 | if (offset & 0x01) |
| 500 | return sms_vdp_hcount_latch_r(smsvdp, offset); |
| 355 | 501 | else |
| 356 | | { |
| 357 | | /* VCount read */ |
| 358 | | return sms_vdp_vcount_r(space, offset); |
| 359 | | } |
| 502 | return sms_vdp_vcount_r(smsvdp, offset); |
| 360 | 503 | } |
| 361 | 504 | |
| 362 | 505 | |
| 363 | 506 | /* |
| 364 | | Check if the pause button is pressed. |
| 365 | | If the gamegear is in sms mode, check if the start button is pressed. |
| 507 | Check if the pause button is pressed. |
| 508 | If the gamegear is in sms mode, check if the start button is pressed. |
| 366 | 509 | */ |
| 367 | | void sms_check_pause_button(const address_space *space) |
| 510 | void sms_pause_callback( running_machine *machine ) |
| 368 | 511 | { |
| 369 | | if ( IS_GAMEGEAR && ! ( sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE ) ) |
| 512 | if (sms_state.is_gamegear && !(sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE)) |
| 513 | return; |
| 514 | |
| 515 | if (!(input_port_read(machine, sms_state.is_gamegear ? "START" : "PAUSE") & 0x80)) |
| 370 | 516 | { |
| 371 | | return; |
| 372 | | } |
| 373 | | if ( ! (input_port_read(space->machine, IS_GAMEGEAR ? "START" : "PAUSE") & 0x80) ) { |
| 374 | | if ( ! sms_state.Paused ) { |
| 375 | | cputag_set_input_line(space->machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE ); |
| 517 | if (!sms_state.paused) |
| 518 | { |
| 519 | cputag_set_input_line(machine, "maincpu", INPUT_LINE_NMI, PULSE_LINE); |
| 376 | 520 | } |
| 377 | | sms_state.Paused = 1; |
| 521 | sms_state.paused = 1; |
| 378 | 522 | } |
| 379 | 523 | else |
| 380 | 524 | { |
| 381 | | sms_state.Paused = 0; |
| 525 | sms_state.paused = 0; |
| 382 | 526 | } |
| 383 | 527 | } |
| 384 | 528 | |
| 385 | | |
| 386 | | READ8_HANDLER(sms_input_port_0_r) |
| 529 | READ8_HANDLER( sms_input_port_0_r ) |
| 387 | 530 | { |
| 388 | | if (sms_state.biosPort & IO_CHIP) |
| 531 | if (sms_state.bios_port & IO_CHIP) |
| 389 | 532 | { |
| 390 | | return (0xFF); |
| 533 | return 0xff; |
| 391 | 534 | } |
| 392 | 535 | else |
| 393 | 536 | { |
| r6078 | r6079 | |
| 397 | 540 | } |
| 398 | 541 | |
| 399 | 542 | |
| 400 | | WRITE8_HANDLER(sms_ym2413_register_port_0_w) |
| 543 | READ8_HANDLER( sms_input_port_1_r ) |
| 401 | 544 | { |
| 402 | | if ( HAS_FM ) |
| 545 | if (sms_state.bios_port & IO_CHIP) |
| 546 | return 0xff; |
| 547 | |
| 548 | sms_get_inputs(space); |
| 549 | |
| 550 | /* Do region detection if TH of ports A and B are set to output (0) */ |
| 551 | if (!(sms_state.ctrl_reg & 0x0a)) |
| 552 | { |
| 553 | /* Move bits 7,5 of IO control port into bits 7, 6 */ |
| 554 | sms_state.input_port1 = (sms_state.input_port1 & 0x3f) | (sms_state.ctrl_reg & 0x80) | (sms_state.ctrl_reg & 0x20) << 1; |
| 555 | |
| 556 | /* Inverse region detect value for Japanese machines */ |
| 557 | if (sms_state.is_region_japan) |
| 558 | sms_state.input_port1 ^= 0xc0; |
| 559 | } |
| 560 | else if (sms_state.ctrl_reg & 0x02 && lphaser_sensor_is_on(space->machine, sms_state.lphaser_1_x, sms_state.lphaser_1_y)) |
| 403 | 561 | { |
| 562 | sms_state.input_port1 &= ~0x40; |
| 563 | } |
| 564 | else if (sms_state.ctrl_reg & 0x08 && lphaser_sensor_is_on(space->machine, sms_state.lphaser_2_x, sms_state.lphaser_2_y)) |
| 565 | { |
| 566 | sms_state.input_port1 &= ~0x80; |
| 567 | } |
| 568 | |
| 569 | return sms_state.input_port1; |
| 570 | } |
| 571 | |
| 572 | |
| 573 | |
| 574 | WRITE8_HANDLER( sms_ym2413_register_port_0_w ) |
| 575 | { |
| 576 | if (sms_state.has_fm) |
| 577 | { |
| 404 | 578 | const device_config *ym = devtag_get_device(space->machine, "ym2413"); |
| 405 | | ym2413_w(ym, 0, (data & 0x3F)); |
| 579 | ym2413_w(ym, 0, (data & 0x3f)); |
| 406 | 580 | } |
| 407 | 581 | } |
| 408 | 582 | |
| 409 | 583 | |
| 410 | | WRITE8_HANDLER(sms_ym2413_data_port_0_w) |
| 584 | WRITE8_HANDLER( sms_ym2413_data_port_0_w ) |
| 411 | 585 | { |
| 412 | | if ( HAS_FM ) |
| 586 | if (sms_state.has_fm) |
| 413 | 587 | { |
| 414 | 588 | const device_config *ym = devtag_get_device(space->machine, "ym2413"); |
| 415 | 589 | logerror("data_port_0_w %x %x\n", offset, data); |
| r6078 | r6079 | |
| 418 | 592 | } |
| 419 | 593 | |
| 420 | 594 | |
| 421 | | READ8_HANDLER(gg_input_port_2_r) |
| 595 | READ8_HANDLER( gg_input_port_2_r ) |
| 422 | 596 | { |
| 423 | | //logerror("joy 2 read, val: %02x, pc: %04x\n", (( IS_REGION_JAPAN ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc()); |
| 424 | | return (( IS_REGION_JAPAN ? 0x00 : 0x40 ) | (input_port_read(space->machine, "START") & 0x80)); |
| 597 | //logerror("joy 2 read, val: %02x, pc: %04x\n", ((sms_state.is_region_japan ? 0x00 : 0x40) | (input_port_read(machine, "START") & 0x80)), activecpu_get_pc()); |
| 598 | return ((sms_state.is_region_japan ? 0x00 : 0x40) | (input_port_read(space->machine, "START") & 0x80)); |
| 425 | 599 | } |
| 426 | 600 | |
| 427 | 601 | |
| 428 | | READ8_HANDLER(sms_mapper_r) |
| 602 | READ8_HANDLER( sms_mapper_r ) |
| 429 | 603 | { |
| 430 | 604 | return sms_state.mapper[offset]; |
| 431 | 605 | } |
| 432 | 606 | |
| 433 | 607 | |
| 434 | | WRITE8_HANDLER(sms_mapper_w) |
| 608 | WRITE8_HANDLER( sms_mapper_w ) |
| 435 | 609 | { |
| 436 | 610 | int page; |
| 437 | 611 | UINT8 *SOURCE_BIOS; |
| 438 | 612 | UINT8 *SOURCE_CART; |
| 439 | 613 | UINT8 *SOURCE; |
| 440 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 614 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 441 | 615 | |
| 442 | 616 | offset &= 3; |
| 443 | 617 | |
| 444 | 618 | sms_state.mapper[offset] = data; |
| 445 | 619 | sms_state.mapper_ram[offset] = data; |
| 446 | 620 | |
| 447 | | if ( sms_state.cartridge[sms_state.current_cartridge].ROM ) |
| 621 | if (sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 448 | 622 | { |
| 449 | | SOURCE_CART = sms_state.cartridge[sms_state.current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000; |
| 623 | SOURCE_CART = sms_state.cartridge[sms_state.current_cartridge].ROM + (( rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 450 | 624 | } |
| 451 | 625 | else |
| 452 | 626 | { |
| 453 | 627 | SOURCE_CART = sms_state.banking_none[1]; |
| 454 | 628 | } |
| 455 | | if ( sms_state.BIOS ) |
| 629 | |
| 630 | if (sms_state.BIOS) |
| 456 | 631 | { |
| 457 | | SOURCE_BIOS = sms_state.BIOS + ( (sms_state.BiosPageCount > 0) ? data % sms_state.BiosPageCount : 0 ) * 0x4000; |
| 632 | SOURCE_BIOS = sms_state.BIOS + ((sms_state.bios_page_count > 0) ? data % sms_state.bios_page_count : 0) * 0x4000; |
| 458 | 633 | } |
| 459 | 634 | else |
| 460 | 635 | { |
| 461 | 636 | SOURCE_BIOS = sms_state.banking_none[1]; |
| 462 | 637 | } |
| 463 | 638 | |
| 464 | | if (sms_state.biosPort & IO_BIOS_ROM || ( IS_GAMEGEAR && sms_state.BIOS == NULL ) ) |
| 639 | if (sms_state.bios_port & IO_BIOS_ROM || (sms_state.is_gamegear && sms_state.BIOS == NULL)) |
| 465 | 640 | { |
| 466 | | if (!(sms_state.biosPort & IO_CARTRIDGE) || ( IS_GAMEGEAR && sms_state.BIOS == NULL ) ) |
| 641 | if (!(sms_state.bios_port & IO_CARTRIDGE) || (sms_state.is_gamegear && sms_state.BIOS == NULL)) |
| 467 | 642 | { |
| 468 | | page = ( rom_page_count > 0) ? data % rom_page_count : 0; |
| 469 | | if ( ! sms_state.cartridge[sms_state.current_cartridge].ROM ) |
| 643 | page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 644 | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 470 | 645 | return; |
| 471 | 646 | SOURCE = SOURCE_CART; |
| 472 | 647 | } |
| r6078 | r6079 | |
| 478 | 653 | } |
| 479 | 654 | else |
| 480 | 655 | { |
| 481 | | page = (sms_state.BiosPageCount > 0) ? data % sms_state.BiosPageCount : 0; |
| 482 | | if ( ! sms_state.BIOS ) |
| 656 | page = (sms_state.bios_page_count > 0) ? data % sms_state.bios_page_count : 0; |
| 657 | if (!sms_state.BIOS) |
| 483 | 658 | return; |
| 484 | 659 | SOURCE = SOURCE_BIOS; |
| 485 | 660 | } |
| 486 | 661 | |
| 487 | | switch(offset) |
| 662 | switch (offset) |
| 488 | 663 | { |
| 489 | | case 0: /* Control */ |
| 490 | | /* Is it ram or rom? */ |
| 491 | | if (data & 0x08) /* it's ram */ |
| 664 | case 0: /* Control */ |
| 665 | /* Is it ram or rom? */ |
| 666 | if (data & 0x08) /* it's ram */ |
| 667 | { |
| 668 | sms_state.cartridge[sms_state.current_cartridge].sram_save = 1; /* SRAM should be saved on exit. */ |
| 669 | if (data & 0x04) |
| 492 | 670 | { |
| 493 | | sms_state.cartridge[sms_state.current_cartridge].sram_save = 1; /* SRAM should be saved on exit. */ |
| 494 | | if (data & 0x04) |
| 495 | | { |
| 496 | | LOG(("ram 1 paged.\n")); |
| 497 | | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM + 0x4000; |
| 498 | | } |
| 499 | | else |
| 500 | | { |
| 501 | | LOG(("ram 0 paged.\n")); |
| 502 | | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM; |
| 503 | | } |
| 504 | | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 505 | | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 671 | LOG(("ram 1 paged.\n")); |
| 672 | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM + 0x4000; |
| 506 | 673 | } |
| 507 | | else /* it's rom */ |
| 674 | else |
| 508 | 675 | { |
| 509 | | if ( sms_state.biosPort & IO_BIOS_ROM || ! HAS_BIOS ) |
| 510 | | { |
| 511 | | page = ( rom_page_count > 0) ? sms_state.mapper[3] % rom_page_count : 0; |
| 512 | | SOURCE = sms_state.banking_cart[4]; |
| 513 | | } |
| 514 | | else |
| 515 | | { |
| 516 | | page = (sms_state.BiosPageCount > 0) ? sms_state.mapper[3] % sms_state.BiosPageCount : 0; |
| 517 | | SOURCE = sms_state.banking_bios[4]; |
| 518 | | } |
| 519 | | LOG(("rom 2 paged in %x.\n", page)); |
| 520 | | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 521 | | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 676 | LOG(("ram 0 paged.\n")); |
| 677 | SOURCE = sms_state.cartridge[sms_state.current_cartridge].cartSRAM; |
| 522 | 678 | } |
| 523 | | break; |
| 524 | | |
| 525 | | case 1: /* Select 16k ROM bank for 0400-3FFF */ |
| 526 | | LOG(("rom 0 paged in %x.\n", page)); |
| 527 | | sms_state.banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 528 | | sms_state.banking_cart[2] = SOURCE_CART + 0x0400; |
| 529 | | if ( IS_GAMEGEAR ) |
| 679 | memory_set_bankptr(space->machine, 4, SOURCE); |
| 680 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000); |
| 681 | } |
| 682 | else /* it's rom */ |
| 683 | { |
| 684 | if (sms_state.bios_port & IO_BIOS_ROM || ! sms_state.has_bios) |
| 530 | 685 | { |
| 531 | | SOURCE = SOURCE_CART; |
| 686 | page = (rom_page_count > 0) ? sms_state.mapper[3] % rom_page_count : 0; |
| 687 | SOURCE = sms_state.banking_cart[4]; |
| 532 | 688 | } |
| 533 | | memory_set_bankptr(space->machine, 2, SOURCE + 0x0400 ); |
| 534 | | break; |
| 535 | | |
| 536 | | case 2: /* Select 16k ROM bank for 4000-7FFF */ |
| 537 | | LOG(("rom 1 paged in %x.\n", page)); |
| 538 | | sms_state.banking_bios[3] = SOURCE_BIOS; |
| 539 | | sms_state.banking_cart[3] = SOURCE_CART; |
| 540 | | if ( IS_GAMEGEAR ) |
| 689 | else |
| 541 | 690 | { |
| 542 | | SOURCE = SOURCE_CART; |
| 691 | page = (sms_state.bios_page_count > 0) ? sms_state.mapper[3] % sms_state.bios_page_count : 0; |
| 692 | SOURCE = sms_state.banking_bios[4]; |
| 543 | 693 | } |
| 544 | | memory_set_bankptr(space->machine, 3, SOURCE ); |
| 545 | | break; |
| 694 | LOG(("rom 2 paged in %x.\n", page)); |
| 695 | memory_set_bankptr(space->machine, 4, SOURCE); |
| 696 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000); |
| 697 | } |
| 698 | break; |
| 546 | 699 | |
| 547 | | case 3: /* Select 16k ROM bank for 8000-BFFF */ |
| 548 | | sms_state.banking_bios[4] = SOURCE_BIOS; |
| 549 | | if ( IS_GAMEGEAR ) |
| 700 | case 1: /* Select 16k ROM bank for 0400-3FFF */ |
| 701 | LOG(("rom 0 paged in %x.\n", page)); |
| 702 | sms_state.banking_bios[2] = SOURCE_BIOS + 0x0400; |
| 703 | sms_state.banking_cart[2] = SOURCE_CART + 0x0400; |
| 704 | if (sms_state.is_gamegear) |
| 705 | SOURCE = SOURCE_CART; |
| 706 | |
| 707 | memory_set_bankptr(space->machine, 2, SOURCE + 0x0400); |
| 708 | break; |
| 709 | |
| 710 | case 2: /* Select 16k ROM bank for 4000-7FFF */ |
| 711 | LOG(("rom 1 paged in %x.\n", page)); |
| 712 | sms_state.banking_bios[3] = SOURCE_BIOS; |
| 713 | sms_state.banking_cart[3] = SOURCE_CART; |
| 714 | if (sms_state.is_gamegear) |
| 715 | SOURCE = SOURCE_CART; |
| 716 | |
| 717 | memory_set_bankptr(space->machine, 3, SOURCE); |
| 718 | break; |
| 719 | |
| 720 | case 3: /* Select 16k ROM bank for 8000-BFFF */ |
| 721 | sms_state.banking_bios[4] = SOURCE_BIOS; |
| 722 | if (sms_state.is_gamegear) |
| 723 | SOURCE = SOURCE_CART; |
| 724 | |
| 725 | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 726 | { |
| 727 | if (SOURCE == SOURCE_CART) |
| 550 | 728 | { |
| 551 | | SOURCE = SOURCE_CART; |
| 729 | SOURCE = sms_state.banking_cart[4]; |
| 552 | 730 | } |
| 553 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) |
| 554 | | { |
| 555 | | if ( SOURCE == SOURCE_CART ) |
| 556 | | { |
| 557 | | SOURCE = sms_state.banking_cart[4]; |
| 558 | | } |
| 559 | | } |
| 560 | | else |
| 561 | | { |
| 562 | | sms_state.banking_cart[4] = SOURCE_CART; |
| 563 | | } |
| 564 | | if ( ! ( sms_state.mapper[0] & 0x08 ) ) /* is RAM disabled? */ |
| 565 | | { |
| 566 | | LOG(("rom 2 paged in %x.\n", page)); |
| 567 | | memory_set_bankptr(space->machine, 4, SOURCE ); |
| 568 | | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000 ); |
| 569 | | } |
| 570 | | break; |
| 731 | } |
| 732 | else |
| 733 | { |
| 734 | sms_state.banking_cart[4] = SOURCE_CART; |
| 735 | } |
| 736 | |
| 737 | if (!(sms_state.mapper[0] & 0x08)) /* is RAM disabled? */ |
| 738 | { |
| 739 | LOG(("rom 2 paged in %x.\n", page)); |
| 740 | memory_set_bankptr(space->machine, 4, SOURCE); |
| 741 | memory_set_bankptr(space->machine, 5, SOURCE + 0x2000); |
| 742 | } |
| 743 | break; |
| 571 | 744 | } |
| 572 | 745 | } |
| 573 | 746 | |
| 574 | 747 | |
| 575 | | static WRITE8_HANDLER(sms_codemasters_page0_w) |
| 748 | static WRITE8_HANDLER( sms_codemasters_page0_w ) |
| 576 | 749 | { |
| 577 | | if ( sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) |
| 750 | if (sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 578 | 751 | { |
| 579 | 752 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 580 | | sms_state.banking_cart[1] = sms_state.cartridge[sms_state.current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000; |
| 753 | sms_state.banking_cart[1] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 581 | 754 | sms_state.banking_cart[2] = sms_state.banking_cart[1] + 0x0400; |
| 582 | | memory_set_bankptr(space->machine, 1, sms_state.banking_cart[1] ); |
| 583 | | memory_set_bankptr(space->machine, 2, sms_state.banking_cart[2] ); |
| 755 | memory_set_bankptr(space->machine, 1, sms_state.banking_cart[1]); |
| 756 | memory_set_bankptr(space->machine, 2, sms_state.banking_cart[2]); |
| 584 | 757 | } |
| 585 | 758 | } |
| 586 | 759 | |
| 587 | 760 | |
| 588 | | static WRITE8_HANDLER(sms_codemasters_page1_w) |
| 761 | static WRITE8_HANDLER( sms_codemasters_page1_w ) |
| 589 | 762 | { |
| 590 | | if ( sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) |
| 763 | if (sms_state.cartridge[sms_state.current_cartridge].ROM && sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 591 | 764 | { |
| 592 | 765 | /* Check if we need to switch in some RAM */ |
| 593 | | if ( data & 0x80 ) |
| 766 | if (data & 0x80) |
| 594 | 767 | { |
| 595 | 768 | sms_state.cartridge[sms_state.current_cartridge].ram_page = data & 0x07; |
| 596 | | memory_set_bankptr(space->machine, 5, sms_state.cartridge[sms_state.current_cartridge].cartRAM + sms_state.cartridge[sms_state.current_cartridge].ram_page * 0x2000 ); |
| 769 | memory_set_bankptr(space->machine, 5, sms_state.cartridge[sms_state.current_cartridge].cartRAM + sms_state.cartridge[sms_state.current_cartridge].ram_page * 0x2000); |
| 597 | 770 | } |
| 598 | 771 | else |
| 599 | 772 | { |
| 600 | 773 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 601 | | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ( ( rom_page_count > 0) ? data % rom_page_count : 0 ) * 0x4000; |
| 602 | | memory_set_bankptr(space->machine, 3, sms_state.banking_cart[3] ); |
| 603 | | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000 ); |
| 774 | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((rom_page_count > 0) ? data % rom_page_count : 0) * 0x4000; |
| 775 | memory_set_bankptr(space->machine, 3, sms_state.banking_cart[3]); |
| 776 | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000); |
| 604 | 777 | } |
| 605 | 778 | } |
| 606 | 779 | } |
| 607 | 780 | |
| 608 | 781 | |
| 609 | | WRITE8_HANDLER(sms_bios_w) |
| 782 | WRITE8_HANDLER( sms_bios_w ) |
| 610 | 783 | { |
| 611 | | sms_state.biosPort = data; |
| 784 | sms_state.bios_port = data; |
| 612 | 785 | |
| 613 | 786 | logerror("bios write %02x, pc: %04x\n", data, cpu_get_pc(space->cpu)); |
| 614 | 787 | |
| r6078 | r6079 | |
| 616 | 789 | } |
| 617 | 790 | |
| 618 | 791 | |
| 619 | | WRITE8_HANDLER(sms_cartram2_w) |
| 792 | WRITE8_HANDLER( sms_cartram2_w ) |
| 620 | 793 | { |
| 621 | 794 | if (sms_state.mapper[0] & 0x08) |
| 622 | 795 | { |
| r6078 | r6079 | |
| 630 | 803 | sms_state.cartridge[sms_state.current_cartridge].cartSRAM[offset + 0x2000] = data; |
| 631 | 804 | } |
| 632 | 805 | } |
| 633 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) |
| 806 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 634 | 807 | { |
| 635 | 808 | sms_state.cartridge[sms_state.current_cartridge].cartRAM[sms_state.cartridge[sms_state.current_cartridge].ram_page * 0x2000 + offset] = data; |
| 636 | 809 | } |
| 637 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_KOREAN_MAPPER && offset == 0 ) /* Dodgeball King mapper */ |
| 810 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_KOREAN_MAPPER && offset == 0) /* Dodgeball King mapper */ |
| 638 | 811 | { |
| 639 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 640 | | int page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 641 | | if ( ! sms_state.cartridge[sms_state.current_cartridge].ROM ) |
| 812 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 813 | int page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 814 | |
| 815 | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 642 | 816 | return; |
| 817 | |
| 643 | 818 | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x4000; |
| 644 | | memory_set_bankptr(space->machine, 4, sms_state.banking_cart[4] ); |
| 645 | | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000 ); |
| 819 | memory_set_bankptr(space->machine, 4, sms_state.banking_cart[4]); |
| 820 | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000); |
| 646 | 821 | LOG(("rom 2 paged in %x dodgeball king.\n", page)); |
| 647 | 822 | } |
| 648 | 823 | } |
| 649 | 824 | |
| 650 | 825 | |
| 651 | | WRITE8_HANDLER(sms_cartram_w) |
| 826 | WRITE8_HANDLER( sms_cartram_w ) |
| 652 | 827 | { |
| 653 | 828 | int page; |
| 654 | 829 | |
| r6078 | r6079 | |
| 666 | 841 | } |
| 667 | 842 | else |
| 668 | 843 | { |
| 669 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER && offset == 0 ) /* Codemasters mapper */ |
| 844 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER && offset == 0) /* Codemasters mapper */ |
| 670 | 845 | { |
| 671 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 846 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 672 | 847 | page = (rom_page_count > 0) ? data % rom_page_count : 0; |
| 673 | | if ( ! sms_state.cartridge[sms_state.current_cartridge].ROM ) |
| 848 | if (!sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 674 | 849 | return; |
| 675 | 850 | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM + page * 0x4000; |
| 676 | | memory_set_bankptr(space->machine, 4, sms_state.banking_cart[4] ); |
| 677 | | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000 ); |
| 851 | memory_set_bankptr(space->machine, 4, sms_state.banking_cart[4]); |
| 852 | memory_set_bankptr(space->machine, 5, sms_state.banking_cart[4] + 0x2000); |
| 678 | 853 | LOG(("rom 2 paged in %x codemasters.\n", page)); |
| 679 | 854 | } |
| 680 | | else if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM ) |
| 855 | else if (sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM) |
| 681 | 856 | { |
| 682 | | sms_state.cartridge[sms_state.current_cartridge].cartRAM[offset & ( sms_state.cartridge[sms_state.current_cartridge].ram_size - 1 ) ] = data; |
| 857 | sms_state.cartridge[sms_state.current_cartridge].cartRAM[offset & (sms_state.cartridge[sms_state.current_cartridge].ram_size - 1)] = data; |
| 683 | 858 | } |
| 684 | 859 | else |
| 685 | 860 | { |
| r6078 | r6079 | |
| 689 | 864 | } |
| 690 | 865 | |
| 691 | 866 | |
| 692 | | WRITE8_HANDLER(gg_sio_w) |
| 867 | WRITE8_HANDLER( gg_sio_w ) |
| 693 | 868 | { |
| 694 | 869 | logerror("*** write %02X to SIO register #%d\n", data, offset); |
| 695 | 870 | |
| 696 | | sms_state.ggSIO[offset & 0x07] = data; |
| 697 | | switch(offset & 7) |
| 871 | sms_state.gg_sio[offset & 0x07] = data; |
| 872 | switch (offset & 7) |
| 698 | 873 | { |
| 699 | 874 | case 0x00: /* Parallel Data */ |
| 700 | 875 | break; |
| r6078 | r6079 | |
| 714 | 889 | } |
| 715 | 890 | |
| 716 | 891 | |
| 717 | | READ8_HANDLER(gg_sio_r) |
| 892 | READ8_HANDLER( gg_sio_r ) |
| 718 | 893 | { |
| 719 | 894 | logerror("*** read SIO register #%d\n", offset); |
| 720 | 895 | |
| 721 | | switch(offset & 7) |
| 896 | switch (offset & 7) |
| 722 | 897 | { |
| 723 | 898 | case 0x00: /* Parallel Data */ |
| 724 | 899 | break; |
| r6078 | r6079 | |
| 736 | 911 | break; |
| 737 | 912 | } |
| 738 | 913 | |
| 739 | | return sms_state.ggSIO[offset]; |
| 914 | return sms_state.gg_sio[offset]; |
| 740 | 915 | } |
| 741 | 916 | |
| 742 | 917 | |
| 743 | | READ8_HANDLER(gg_psg_r) |
| 918 | READ8_HANDLER( gg_psg_r ) |
| 744 | 919 | { |
| 745 | | return 0xFF; |
| 920 | return 0xff; |
| 746 | 921 | } |
| 747 | 922 | |
| 748 | 923 | |
| 749 | | WRITE8_HANDLER(gg_psg_w) |
| 924 | WRITE8_HANDLER( gg_psg_w ) |
| 750 | 925 | { |
| 751 | 926 | logerror("write %02X to psg at offset #%d.\n",data , offset); |
| 752 | 927 | |
| r6078 | r6079 | |
| 762 | 937 | } |
| 763 | 938 | |
| 764 | 939 | |
| 765 | | static void sms_machine_stop(running_machine *machine) |
| 940 | static void sms_machine_stop( running_machine *machine ) |
| 766 | 941 | { |
| 767 | 942 | /* Does the cartridge have SRAM that should be saved? */ |
| 768 | | if ( sms_state.cartridge[sms_state.current_cartridge].sram_save ) |
| 943 | if (sms_state.cartridge[sms_state.current_cartridge].sram_save) |
| 769 | 944 | image_battery_save(devtag_get_device(machine, "cart1"), sms_state.cartridge[sms_state.current_cartridge].cartSRAM, sizeof(UINT8) * NVRAM_SIZE ); |
| 770 | 945 | } |
| 771 | 946 | |
| 772 | 947 | |
| 773 | | static void setup_rom(const address_space *space) |
| 948 | static void setup_rom( const address_space *space ) |
| 774 | 949 | { |
| 775 | 950 | running_machine *machine = space->machine; |
| 776 | 951 | |
| 777 | 952 | /* 1. set up bank pointers to point to nothing */ |
| 778 | | memory_set_bankptr(machine, 1, sms_state.banking_none[1] ); |
| 779 | | memory_set_bankptr(machine, 2, sms_state.banking_none[2] ); |
| 780 | | memory_set_bankptr(machine, 3, sms_state.banking_none[3] ); |
| 781 | | memory_set_bankptr(machine, 4, sms_state.banking_none[4] ); |
| 782 | | memory_set_bankptr(machine, 5, sms_state.banking_none[4] + 0x2000 ); |
| 953 | memory_set_bankptr(machine, 1, sms_state.banking_none[1]); |
| 954 | memory_set_bankptr(machine, 2, sms_state.banking_none[2]); |
| 955 | memory_set_bankptr(machine, 3, sms_state.banking_none[3]); |
| 956 | memory_set_bankptr(machine, 4, sms_state.banking_none[4]); |
| 957 | memory_set_bankptr(machine, 5, sms_state.banking_none[4] + 0x2000); |
| 783 | 958 | |
| 784 | 959 | /* 2. check and set up expansion port */ |
| 785 | | if (!(sms_state.biosPort & IO_EXPANSION) && (sms_state.biosPort & IO_CARTRIDGE) && (sms_state.biosPort & IO_CARD)) |
| 960 | if (!(sms_state.bios_port & IO_EXPANSION) && (sms_state.bios_port & IO_CARTRIDGE) && (sms_state.bios_port & IO_CARD)) |
| 786 | 961 | { |
| 787 | 962 | /* TODO: Implement me */ |
| 788 | | logerror( "Switching to unsupported expansion port.\n" ); |
| 963 | logerror("Switching to unsupported expansion port.\n"); |
| 789 | 964 | } |
| 790 | 965 | |
| 791 | 966 | /* 3. check and set up card rom */ |
| 792 | | if (!(sms_state.biosPort & IO_CARD) && (sms_state.biosPort & IO_CARTRIDGE) && (sms_state.biosPort & IO_EXPANSION)) |
| 967 | if (!(sms_state.bios_port & IO_CARD) && (sms_state.bios_port & IO_CARTRIDGE) && (sms_state.bios_port & IO_EXPANSION)) |
| 793 | 968 | { |
| 794 | 969 | /* TODO: Implement me */ |
| 795 | | logerror( "Switching to unsupported card rom port.\n" ); |
| 970 | logerror("Switching to unsupported card rom port.\n"); |
| 796 | 971 | } |
| 797 | 972 | |
| 798 | 973 | /* 4. check and set up cartridge rom */ |
| 799 | | /* if ( ( !(sms_state.biosPort & IO_CARTRIDGE) && (sms_state.biosPort & IO_EXPANSION) && (sms_state.biosPort & IO_CARD) ) || IS_GAMEGEAR ) { */ |
| 974 | /* if ((!(bios_port & IO_CARTRIDGE) && (bios_port & IO_EXPANSION) && (bios_port & IO_CARD)) || sms_state.is_gamegear) { */ |
| 800 | 975 | /* Out Run Europa initially writes a value to port 3E where IO_CARTRIDGE, IO_EXPANSION and IO_CARD are reset */ |
| 801 | | if ( ( ! ( sms_state.biosPort & IO_CARTRIDGE ) ) || IS_GAMEGEAR ) |
| 976 | if ((!(sms_state.bios_port & IO_CARTRIDGE)) || sms_state.is_gamegear) |
| 802 | 977 | { |
| 803 | | memory_set_bankptr(machine, 1, sms_state.banking_cart[1] ); |
| 804 | | memory_set_bankptr(machine, 2, sms_state.banking_cart[2] ); |
| 805 | | memory_set_bankptr(machine, 3, sms_state.banking_cart[3] ); |
| 806 | | memory_set_bankptr(machine, 4, sms_state.banking_cart[4] ); |
| 807 | | memory_set_bankptr(machine, 5, sms_state.banking_cart[4] + 0x2000 ); |
| 808 | | logerror( "Switched in cartridge rom.\n" ); |
| 978 | memory_set_bankptr(machine, 1, sms_state.banking_cart[1]); |
| 979 | memory_set_bankptr(machine, 2, sms_state.banking_cart[2]); |
| 980 | memory_set_bankptr(machine, 3, sms_state.banking_cart[3]); |
| 981 | memory_set_bankptr(machine, 4, sms_state.banking_cart[4]); |
| 982 | memory_set_bankptr(machine, 5, sms_state.banking_cart[4] + 0x2000); |
| 983 | logerror("Switched in cartridge rom.\n"); |
| 809 | 984 | } |
| 810 | 985 | |
| 811 | 986 | /* 5. check and set up bios rom */ |
| 812 | | if ( !(sms_state.biosPort & IO_BIOS_ROM) ) |
| 987 | if (!(sms_state.bios_port & IO_BIOS_ROM)) |
| 813 | 988 | { |
| 814 | 989 | /* 0x0400 bioses */ |
| 815 | | if ( HAS_BIOS_0400 ) |
| 990 | if (sms_state.has_bios_0400) |
| 816 | 991 | { |
| 817 | | memory_set_bankptr(machine, 1, sms_state.banking_bios[1] ); |
| 818 | | logerror( "Switched in 0x0400 bios.\n" ); |
| 992 | memory_set_bankptr(machine, 1, sms_state.banking_bios[1]); |
| 993 | logerror("Switched in 0x0400 bios.\n"); |
| 819 | 994 | } |
| 820 | 995 | /* 0x2000 bioses */ |
| 821 | | if ( HAS_BIOS_2000 ) |
| 996 | if (sms_state.has_bios_2000) |
| 822 | 997 | { |
| 823 | | memory_set_bankptr(machine, 1, sms_state.banking_bios[1] ); |
| 824 | | memory_set_bankptr(machine, 2, sms_state.banking_bios[2] ); |
| 825 | | logerror( "Switched in 0x2000 bios.\n" ); |
| 998 | memory_set_bankptr(machine, 1, sms_state.banking_bios[1]); |
| 999 | memory_set_bankptr(machine, 2, sms_state.banking_bios[2]); |
| 1000 | logerror("Switched in 0x2000 bios.\n"); |
| 826 | 1001 | } |
| 827 | | if ( HAS_BIOS_FULL ) |
| 1002 | if (sms_state.has_bios_full) |
| 828 | 1003 | { |
| 829 | | memory_set_bankptr(machine, 1, sms_state.banking_bios[1] ); |
| 830 | | memory_set_bankptr(machine, 2, sms_state.banking_bios[2] ); |
| 831 | | memory_set_bankptr(machine, 3, sms_state.banking_bios[3] ); |
| 832 | | memory_set_bankptr(machine, 4, sms_state.banking_bios[4] ); |
| 833 | | memory_set_bankptr(machine, 5, sms_state.banking_bios[4] + 0x2000 ); |
| 834 | | logerror( "Switched in full bios.\n" ); |
| 1004 | memory_set_bankptr(machine, 1, sms_state.banking_bios[1]); |
| 1005 | memory_set_bankptr(machine, 2, sms_state.banking_bios[2]); |
| 1006 | memory_set_bankptr(machine, 3, sms_state.banking_bios[3]); |
| 1007 | memory_set_bankptr(machine, 4, sms_state.banking_bios[4]); |
| 1008 | memory_set_bankptr(machine, 5, sms_state.banking_bios[4] + 0x2000); |
| 1009 | logerror("Switched in full bios.\n"); |
| 835 | 1010 | } |
| 836 | 1011 | } |
| 837 | 1012 | |
| 838 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM ) |
| 1013 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_ONCART_RAM) |
| 839 | 1014 | { |
| 840 | | memory_set_bankptr(machine, 4, sms_state.cartridge[sms_state.current_cartridge].cartRAM ); |
| 841 | | memory_set_bankptr(machine, 5, sms_state.cartridge[sms_state.current_cartridge].cartRAM ); |
| 1015 | memory_set_bankptr(machine, 4, sms_state.cartridge[sms_state.current_cartridge].cartRAM); |
| 1016 | memory_set_bankptr(machine, 5, sms_state.cartridge[sms_state.current_cartridge].cartRAM); |
| 842 | 1017 | } |
| 843 | 1018 | } |
| 844 | 1019 | |
| 845 | 1020 | |
| 846 | | static int sms_verify_cart(UINT8 *magic, int size) |
| 1021 | static int sms_verify_cart( UINT8 *magic, int size ) |
| 847 | 1022 | { |
| 848 | 1023 | int retval; |
| 849 | 1024 | |
| r6078 | r6079 | |
| 852 | 1027 | /* Verify the file is a valid image - check $7ff0 for "TMR SEGA" */ |
| 853 | 1028 | if (size >= 0x8000) |
| 854 | 1029 | { |
| 855 | | if (!strncmp((char*)&magic[0x7FF0], "TMR SEGA", 8)) |
| 1030 | if (!strncmp((char*)&magic[0x7ff0], "TMR SEGA", 8)) |
| 856 | 1031 | { |
| 857 | 1032 | /* Technically, it should be this, but remove for now until verified: |
| 858 | 1033 | if (!strcmp(sysname, "gamegear")) |
| 859 | 1034 | { |
| 860 | | if ((unsigned char)magic[0x7FFD] < 0x50) |
| 1035 | if ((unsigned char)magic[0x7ffd] < 0x50) |
| 861 | 1036 | retval = IMAGE_VERIFY_PASS; |
| 862 | 1037 | } |
| 863 | 1038 | if (!strcmp(sysname, "sms")) |
| 864 | 1039 | { |
| 865 | | if ((unsigned char)magic[0x7FFD] >= 0x50) |
| 1040 | if ((unsigned char)magic[0x7ffd] >= 0x50) |
| 866 | 1041 | retval = IMAGE_VERIFY_PASS; |
| 867 | 1042 | } |
| 868 | 1043 | */ |
| r6078 | r6079 | |
| 874 | 1049 | //if (!retval) { |
| 875 | 1050 | // if (!strncmp(&magic[0x81f0], "TMR SEGA", 8)) { |
| 876 | 1051 | /* Technically, it should be this, but remove for now until verified: |
| 877 | | if (!strcmp(sysname, "gamegear")) { |
| 1052 | if (!strcmp(sysname, "gamegear")) |
| 1053 | { |
| 878 | 1054 | if ((unsigned char)magic[0x81fd] < 0x50) |
| 879 | 1055 | retval = IMAGE_VERIFY_PASS; |
| 880 | 1056 | } |
| 881 | | if (!strcmp(sysname, "sms")) { |
| 1057 | if (!strcmp(sysname, "sms")) |
| 1058 | { |
| 882 | 1059 | if ((unsigned char)magic[0x81fd] >= 0x50) |
| 883 | 1060 | retval = IMAGE_VERIFY_PASS; |
| 884 | 1061 | } |
| r6078 | r6079 | |
| 908 | 1085 | */ |
| 909 | 1086 | static int detect_codemasters_mapper( UINT8 *rom ) |
| 910 | 1087 | { |
| 911 | | static const UINT8 jang_pung2[16] = { 0x00, 0xBA, 0x38, 0x0D, 0x00, 0xB8, 0x38, 0x0C, 0x00, 0xB6, 0x38, 0x0B, 0x00, 0xB4, 0x38, 0x0A }; |
| 1088 | static const UINT8 jang_pung2[16] = { 0x00, 0xba, 0x38, 0x0d, 0x00, 0xb8, 0x38, 0x0c, 0x00, 0xb6, 0x38, 0x0b, 0x00, 0xb4, 0x38, 0x0a }; |
| 912 | 1089 | |
| 913 | | if ( ( ( rom[0x7fe0] & 0x0F ) <= 9 ) && |
| 914 | | ( rom[0x7fe3] == 0x93 || rom[0x7fe3] == 0x94 || rom[0x7fe3] == 0x95 ) && |
| 915 | | rom[0x7fef] == 0x00 ) |
| 916 | | { |
| 1090 | if (((rom[0x7fe0] & 0x0f ) <= 9) && (rom[0x7fe3] == 0x93 || rom[0x7fe3] == 0x94 || rom[0x7fe3] == 0x95) && rom[0x7fef] == 0x00) |
| 917 | 1091 | return 1; |
| 918 | | } |
| 919 | 1092 | |
| 920 | | if ( ! memcmp( &rom[0x7ff0], jang_pung2, 16 ) ) |
| 921 | | { |
| 1093 | if (!memcmp(&rom[0x7ff0], jang_pung2, 16)) |
| 922 | 1094 | return 1; |
| 923 | | } |
| 924 | 1095 | |
| 925 | 1096 | return 0; |
| 926 | 1097 | } |
| r6078 | r6079 | |
| 930 | 1101 | { |
| 931 | 1102 | static const UINT8 signatures[2][16] = |
| 932 | 1103 | { |
| 933 | | { 0x3E, 0x11, 0x32, 0x00, 0xA0, 0x78, 0xCD, 0x84, 0x85, 0x3E, 0x02, 0x32, 0x00, 0xA0, 0xC9, 0xFF }, /* Dodgeball King */ |
| 934 | | { 0x41, 0x48, 0x37, 0x37, 0x44, 0x37, 0x4E, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20 }, /* Sangokushi 3 */ |
| 1104 | { 0x3e, 0x11, 0x32, 0x00, 0xa0, 0x78, 0xcd, 0x84, 0x85, 0x3e, 0x02, 0x32, 0x00, 0xa0, 0xc9, 0xff }, /* Dodgeball King */ |
| 1105 | { 0x41, 0x48, 0x37, 0x37, 0x44, 0x37, 0x4e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20 }, /* Sangokushi 3 */ |
| 935 | 1106 | }; |
| 936 | 1107 | int i; |
| 937 | 1108 | |
| 938 | | for( i = 0; i < 2; i++ ) |
| 1109 | for (i = 0; i < 2; i++) |
| 939 | 1110 | { |
| 940 | | if ( !memcmp( &rom[0x7ff0], signatures[i], 16 ) ) |
| 1111 | if (!memcmp(&rom[0x7ff0], signatures[i], 16)) |
| 941 | 1112 | { |
| 942 | 1113 | return 1; |
| 943 | 1114 | } |
| r6078 | r6079 | |
| 945 | 1116 | return 0; |
| 946 | 1117 | } |
| 947 | 1118 | |
| 1119 | static UINT8 detect_lphaser_xoffset( UINT8 *rom ) |
| 1120 | { |
| 1121 | static const UINT8 signatures[6][16] = |
| 1122 | { |
| 1123 | /* Spacegun */ |
| 1124 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0xff, 0xff, 0x9d, 0x99, 0x10, 0x90, 0x00, 0x40 }, |
| 1125 | /* Gangster Town */ |
| 1126 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0x19, 0x87, 0x1b, 0xc9, 0x74, 0x50, 0x00, 0x4f }, |
| 1127 | /* Shooting Gallery */ |
| 1128 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0x20, 0x20, 0x8a, 0x3a, 0x72, 0x50, 0x00, 0x4f }, |
| 1129 | /* Rescue Mission */ |
| 1130 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0x20, 0x20, 0xfb, 0xd3, 0x06, 0x51, 0x00, 0x4f }, |
| 1131 | /* Laser Ghost */ |
| 1132 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0x00, 0x00, 0xb7, 0x55, 0x74, 0x70, 0x00, 0x40 }, |
| 1133 | /* Assault City */ |
| 1134 | { 0x54, 0x4d, 0x52, 0x20, 0x53, 0x45, 0x47, 0x41, 0xff, 0xff, 0x9f, 0x74, 0x34, 0x70, 0x00, 0x40 }, |
| 1135 | }; |
| 1136 | |
| 1137 | if (!(sms_state.bios_port & IO_CARTRIDGE) && sms_state.cartridge[sms_state.current_cartridge].size >= 0x8000) |
| 1138 | { |
| 1139 | if (!memcmp(&rom[0x7ff0], signatures[0], 16) || !memcmp(&rom[0x7ff0], signatures[1], 16)) |
| 1140 | return 40; |
| 1141 | |
| 1142 | if (!memcmp(&rom[0x7ff0], signatures[2], 16)) |
| 1143 | return 49; |
| 1144 | |
| 1145 | if (!memcmp(&rom[0x7ff0], signatures[3], 16)) |
| 1146 | return 47; |
| 1147 | |
| 1148 | if (!memcmp(&rom[0x7ff0], signatures[4], 16)) |
| 1149 | return 44; |
| 1150 | |
| 1151 | if (!memcmp(&rom[0x7ff0], signatures[5], 16)) |
| 1152 | return 53; |
| 1153 | |
| 1154 | } |
| 1155 | return 50; |
| 1156 | } |
| 948 | 1157 | |
| 1158 | |
| 949 | 1159 | DEVICE_START( sms_cart ) |
| 950 | 1160 | { |
| 951 | 1161 | int i; |
| 952 | 1162 | |
| 953 | | for ( i = 0; i < MAX_CARTRIDGES; i++ ) |
| 1163 | for (i = 0; i < MAX_CARTRIDGES; i++) |
| 954 | 1164 | { |
| 955 | 1165 | sms_state.cartridge[i].ROM = NULL; |
| 956 | 1166 | sms_state.cartridge[i].size = 0; |
| r6078 | r6079 | |
| 963 | 1173 | } |
| 964 | 1174 | sms_state.current_cartridge = 0; |
| 965 | 1175 | |
| 966 | | sms_state.biosPort = (IO_EXPANSION | IO_CARTRIDGE | IO_CARD); |
| 967 | | if ( ! IS_GAMEGEAR && ! HAS_BIOS ) |
| 1176 | sms_state.bios_port = (IO_EXPANSION | IO_CARTRIDGE | IO_CARD); |
| 1177 | if (!sms_state.is_gamegear && ! sms_state.has_bios) |
| 968 | 1178 | { |
| 969 | | sms_state.biosPort &= ~(IO_CARTRIDGE); |
| 970 | | sms_state.biosPort |= IO_BIOS_ROM; |
| 1179 | sms_state.bios_port &= ~(IO_CARTRIDGE); |
| 1180 | sms_state.bios_port |= IO_BIOS_ROM; |
| 971 | 1181 | } |
| 972 | 1182 | } |
| 973 | 1183 | |
| r6078 | r6079 | |
| 976 | 1186 | { |
| 977 | 1187 | int size = image_length(image); |
| 978 | 1188 | int index = 0; |
| 979 | | const char *fname = image_filename( image ); |
| 980 | | int fname_len = fname ? strlen( fname ) : 0; |
| 981 | | const char *extrainfo = image_extrainfo( image ); |
| 1189 | const char *fname = image_filename(image); |
| 1190 | int fname_len = fname ? strlen(fname) : 0; |
| 1191 | const char *extrainfo = image_extrainfo(image); |
| 982 | 1192 | |
| 983 | | if (strcmp(image->tag,"cart1")==0) |
| 984 | | { |
| 1193 | if (strcmp(image->tag,"cart1") == 0) |
| 985 | 1194 | index = 0; |
| 986 | | } |
| 987 | | if (strcmp(image->tag,"cart2")==0) |
| 988 | | { |
| 1195 | |
| 1196 | if (strcmp(image->tag,"cart2") == 0) |
| 989 | 1197 | index = 1; |
| 990 | | } |
| 991 | | if (strcmp(image->tag,"cart3")==0) |
| 992 | | { |
| 1198 | |
| 1199 | if (strcmp(image->tag,"cart3") == 0) |
| 993 | 1200 | index = 2; |
| 994 | | } |
| 995 | | if (strcmp(image->tag,"cart4")==0) |
| 996 | | { |
| 1201 | |
| 1202 | if (strcmp(image->tag,"cart4") == 0) |
| 997 | 1203 | index = 3; |
| 998 | | } |
| 999 | | if (strcmp(image->tag,"cart5")==0) |
| 1000 | | { |
| 1204 | |
| 1205 | if (strcmp(image->tag,"cart5") == 0) |
| 1001 | 1206 | index = 4; |
| 1002 | | } |
| 1207 | |
| 1003 | 1208 | /* Check for 512-byte header */ |
| 1004 | 1209 | if ((size / 512) & 1) |
| 1005 | 1210 | { |
| r6078 | r6079 | |
| 1007 | 1212 | size -= 512; |
| 1008 | 1213 | } |
| 1009 | 1214 | |
| 1010 | | if ( ! size ) |
| 1215 | if (!size) |
| 1011 | 1216 | { |
| 1012 | | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too small" ); |
| 1217 | image_seterror(image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too small"); |
| 1013 | 1218 | return INIT_FAIL; |
| 1014 | 1219 | } |
| 1015 | 1220 | |
| 1016 | 1221 | /* Create a new memory region to hold the ROM. */ |
| 1017 | 1222 | /* Make sure the region holds only complete (0x4000) rom banks */ |
| 1018 | | sms_state.cartridge[index].size = (size&0x3FFF) ? (((size>>14)+1)<<14) : size; |
| 1019 | | sms_state.cartridge[index].ROM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].size ); |
| 1223 | sms_state.cartridge[index].size = (size & 0x3fff) ? (((size >> 14) + 1) << 14) : size; |
| 1224 | sms_state.cartridge[index].ROM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].size); |
| 1020 | 1225 | |
| 1021 | | sms_state.cartridge[index].cartSRAM = auto_alloc_array(image->machine, UINT8, NVRAM_SIZE ); |
| 1226 | sms_state.cartridge[index].cartSRAM = auto_alloc_array(image->machine, UINT8, NVRAM_SIZE); |
| 1022 | 1227 | |
| 1023 | 1228 | /* Load ROM banks */ |
| 1024 | 1229 | size = image_fread(image, sms_state.cartridge[index].ROM, size); |
| 1025 | 1230 | |
| 1026 | 1231 | /* check the image */ |
| 1027 | | if ( ! HAS_BIOS ) |
| 1232 | if (!sms_state.has_bios) |
| 1028 | 1233 | { |
| 1029 | 1234 | if (sms_verify_cart(sms_state.cartridge[index].ROM, size) == IMAGE_VERIFY_FAIL) |
| 1030 | 1235 | { |
| r6078 | r6079 | |
| 1035 | 1240 | sms_state.cartridge[index].features = 0; |
| 1036 | 1241 | |
| 1037 | 1242 | /* Detect special features from the extrainfo field */ |
| 1038 | | if ( extrainfo ) |
| 1243 | if (extrainfo) |
| 1039 | 1244 | { |
| 1040 | 1245 | /* Check for codemasters mapper */ |
| 1041 | | if ( strstr( extrainfo, "CODEMASTERS" ) ) |
| 1042 | | { |
| 1246 | if (strstr(extrainfo, "CODEMASTERS")) |
| 1043 | 1247 | sms_state.cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1044 | | } |
| 1045 | 1248 | |
| 1046 | 1249 | /* Check for korean mapper */ |
| 1047 | | if ( strstr( extrainfo, "KOREAN" ) ) |
| 1048 | | { |
| 1250 | if (strstr(extrainfo, "KOREAN")) |
| 1049 | 1251 | sms_state.cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1050 | | } |
| 1051 | 1252 | |
| 1052 | 1253 | /* Check for special SMS Compatibility mode gamegear cartridges */ |
| 1053 | | if ( IS_GAMEGEAR && strstr( extrainfo, "GGSMS" ) ) |
| 1054 | | { |
| 1254 | if (sms_state.is_gamegear && strstr(extrainfo, "GGSMS")) |
| 1055 | 1255 | sms_state.cartridge[index].features |= CF_GG_SMS_MODE; |
| 1056 | | } |
| 1057 | 1256 | |
| 1058 | 1257 | /* Check for 93C46 eeprom */ |
| 1059 | | if ( strstr( extrainfo, "93C46" ) ) |
| 1060 | | { |
| 1258 | if (strstr( extrainfo, "93C46")) |
| 1061 | 1259 | sms_state.cartridge[index].features |= CF_93C46_EEPROM; |
| 1062 | | } |
| 1063 | 1260 | |
| 1064 | 1261 | /* Check for 8KB on-cart RAM */ |
| 1065 | | if ( strstr( extrainfo, "8KB_CART_RAM" ) ) |
| 1262 | if (strstr(extrainfo, "8KB_CART_RAM")) |
| 1066 | 1263 | { |
| 1067 | 1264 | sms_state.cartridge[index].features |= CF_ONCART_RAM; |
| 1068 | 1265 | sms_state.cartridge[index].ram_size = 0x2000; |
| 1069 | | sms_state.cartridge[index].cartRAM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].ram_size ); |
| 1266 | sms_state.cartridge[index].cartRAM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].ram_size); |
| 1070 | 1267 | } |
| 1071 | 1268 | } |
| 1072 | 1269 | else |
| 1073 | 1270 | { |
| 1074 | 1271 | /* If no extrainfo information is available try to find special information out on our own */ |
| 1075 | 1272 | /* Check for special cartridge features */ |
| 1076 | | if ( size >= 0x8000 ) |
| 1273 | if (size >= 0x8000) |
| 1077 | 1274 | { |
| 1078 | 1275 | /* Check for special mappers */ |
| 1079 | | if ( detect_codemasters_mapper( sms_state.cartridge[index].ROM ) ) |
| 1080 | | { |
| 1276 | if (detect_codemasters_mapper(sms_state.cartridge[index].ROM)) |
| 1081 | 1277 | sms_state.cartridge[index].features |= CF_CODEMASTERS_MAPPER; |
| 1082 | | } |
| 1083 | | if ( detect_korean_mapper( sms_state.cartridge[index].ROM ) ) |
| 1084 | | { |
| 1278 | |
| 1279 | if (detect_korean_mapper(sms_state.cartridge[index].ROM)) |
| 1085 | 1280 | sms_state.cartridge[index].features |= CF_KOREAN_MAPPER; |
| 1086 | | } |
| 1281 | |
| 1087 | 1282 | } |
| 1088 | 1283 | |
| 1089 | 1284 | /* Check for special SMS Compatibility mode gamegear cartridges */ |
| 1090 | | if ( IS_GAMEGEAR ) |
| 1285 | if (sms_state.is_gamegear) |
| 1091 | 1286 | { |
| 1092 | 1287 | /* Just in case someone passes us an sms file */ |
| 1093 | | if ( fname_len > 3 && ! mame_stricmp( fname + fname_len - 3, "sms" ) ) |
| 1094 | | { |
| 1288 | if (fname_len > 3 && ! mame_stricmp(fname + fname_len - 3, "sms")) |
| 1095 | 1289 | sms_state.cartridge[index].features |= CF_GG_SMS_MODE; |
| 1096 | | } |
| 1097 | 1290 | } |
| 1098 | 1291 | } |
| 1099 | 1292 | |
| 1100 | | if ( sms_state.cartridge[index].features & CF_CODEMASTERS_MAPPER ) |
| 1293 | if (sms_state.cartridge[index].features & CF_CODEMASTERS_MAPPER) |
| 1101 | 1294 | { |
| 1102 | 1295 | sms_state.cartridge[index].ram_size = 0x10000; |
| 1103 | | sms_state.cartridge[index].cartRAM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].ram_size ); |
| 1296 | sms_state.cartridge[index].cartRAM = auto_alloc_array(image->machine, UINT8, sms_state.cartridge[index].ram_size); |
| 1104 | 1297 | sms_state.cartridge[index].ram_page = 0; |
| 1105 | 1298 | } |
| 1299 | |
| 1300 | /* For Light Phaser games, we have to detect the x offset */ |
| 1301 | sms_state.lphaser_x_offs = detect_lphaser_xoffset(sms_state.cartridge[index].ROM); |
| 1106 | 1302 | |
| 1107 | 1303 | /* Load battery backed RAM, if available */ |
| 1108 | | image_battery_load( image, sms_state.cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE ); |
| 1304 | image_battery_load(image, sms_state.cartridge[index].cartSRAM, sizeof(UINT8) * NVRAM_SIZE); |
| 1109 | 1305 | |
| 1110 | 1306 | return INIT_PASS; |
| 1111 | 1307 | } |
| r6078 | r6079 | |
| 1113 | 1309 | |
| 1114 | 1310 | static void setup_cart_banks( void ) |
| 1115 | 1311 | { |
| 1116 | | if ( sms_state.cartridge[sms_state.current_cartridge].ROM ) |
| 1312 | if (sms_state.cartridge[sms_state.current_cartridge].ROM) |
| 1117 | 1313 | { |
| 1118 | | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 1314 | UINT8 rom_page_count = sms_state.cartridge[sms_state.current_cartridge].size / 0x4000; |
| 1119 | 1315 | sms_state.banking_cart[1] = sms_state.cartridge[sms_state.current_cartridge].ROM; |
| 1120 | 1316 | sms_state.banking_cart[2] = sms_state.cartridge[sms_state.current_cartridge].ROM + 0x0400; |
| 1121 | | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ( ( 1 < rom_page_count ) ? 0x4000 : 0 ); |
| 1122 | | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM + ( ( 2 < rom_page_count ) ? 0x8000 : 0 ); |
| 1317 | sms_state.banking_cart[3] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((1 < rom_page_count) ? 0x4000 : 0); |
| 1318 | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM + ((2 < rom_page_count) ? 0x8000 : 0); |
| 1123 | 1319 | /* Codemasters mapper points to bank 0 for page 2 */ |
| 1124 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) { |
| 1320 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1321 | { |
| 1125 | 1322 | sms_state.banking_cart[4] = sms_state.cartridge[sms_state.current_cartridge].ROM; |
| 1126 | 1323 | } |
| 1127 | 1324 | } |
| r6078 | r6079 | |
| 1145 | 1342 | |
| 1146 | 1343 | sms_state.BIOS = memory_region(machine, "user1"); |
| 1147 | 1344 | |
| 1148 | | sms_state.BiosPageCount = ( sms_state.BIOS ? memory_region_length(machine, "user1") / 0x4000 : 0 ); |
| 1345 | sms_state.bios_page_count = (sms_state.BIOS ? memory_region_length(machine, "user1") / 0x4000 : 0); |
| 1149 | 1346 | |
| 1150 | 1347 | setup_cart_banks(); |
| 1151 | 1348 | |
| 1152 | | if ( sms_state.BIOS == NULL || sms_state.BIOS[0] == 0x00 ) |
| 1349 | if (sms_state.BIOS == NULL || sms_state.BIOS[0] == 0x00) |
| 1153 | 1350 | { |
| 1154 | 1351 | sms_state.BIOS = NULL; |
| 1155 | | sms_state.biosPort |= IO_BIOS_ROM; |
| 1352 | sms_state.bios_port |= IO_BIOS_ROM; |
| 1156 | 1353 | } |
| 1157 | 1354 | |
| 1158 | | if ( sms_state.BIOS ) |
| 1355 | if (sms_state.BIOS) |
| 1159 | 1356 | { |
| 1160 | 1357 | sms_state.banking_bios[1] = sms_state.BIOS; |
| 1161 | 1358 | sms_state.banking_bios[2] = sms_state.BIOS + 0x0400; |
| 1162 | | sms_state.banking_bios[3] = sms_state.BIOS + ( ( 1 < sms_state.BiosPageCount) ? 0x4000 : 0 ); |
| 1163 | | sms_state.banking_bios[4] = sms_state.BIOS + ( ( 2 < sms_state.BiosPageCount) ? 0x8000 : 0 ); |
| 1359 | sms_state.banking_bios[3] = sms_state.BIOS + ((1 < sms_state.bios_page_count) ? 0x4000 : 0); |
| 1360 | sms_state.banking_bios[4] = sms_state.BIOS + ((2 < sms_state.bios_page_count) ? 0x8000 : 0); |
| 1164 | 1361 | } |
| 1165 | 1362 | } |
| 1166 | 1363 | |
| 1167 | 1364 | |
| 1168 | | MACHINE_START(sms) |
| 1365 | MACHINE_START( sms ) |
| 1169 | 1366 | { |
| 1170 | 1367 | add_exit_callback(machine, sms_machine_stop); |
| 1171 | 1368 | } |
| 1172 | 1369 | |
| 1173 | 1370 | |
| 1174 | | MACHINE_RESET(sms) |
| 1371 | MACHINE_RESET( sms ) |
| 1175 | 1372 | { |
| 1176 | 1373 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1374 | const device_config *smsvdp = devtag_get_device(machine, "sms_vdp"); |
| 1177 | 1375 | |
| 1178 | | sms_state.Version = 0x00; |
| 1179 | | if ( HAS_FM ) |
| 1180 | | { |
| 1181 | | sms_state.FMDetect = 0x01; |
| 1182 | | } |
| 1376 | sms_state.ctrl_reg = 0xff; |
| 1377 | if (sms_state.has_fm) |
| 1378 | sms_state.fm_detect = 0x01; |
| 1183 | 1379 | |
| 1184 | | sms_state.mapper_ram = memory_get_write_ptr( space, 0xDFFC ); |
| 1380 | sms_state.mapper_ram = memory_get_write_ptr(space, 0xdffc); |
| 1185 | 1381 | |
| 1186 | | sms_state.biosPort = 0; |
| 1382 | sms_state.bios_port = 0; |
| 1187 | 1383 | |
| 1188 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER ) |
| 1384 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_CODEMASTERS_MAPPER) |
| 1189 | 1385 | { |
| 1190 | 1386 | /* Install special memory handlers */ |
| 1191 | | memory_install_write8_handler(space, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w ); |
| 1192 | | memory_install_write8_handler(space, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w ); |
| 1387 | memory_install_write8_handler(space, 0x0000, 0x0000, 0, 0, sms_codemasters_page0_w); |
| 1388 | memory_install_write8_handler(space, 0x4000, 0x4000, 0, 0, sms_codemasters_page1_w); |
| 1193 | 1389 | } |
| 1194 | 1390 | |
| 1195 | | if ( sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE ) |
| 1196 | | { |
| 1197 | | sms_set_ggsmsmode( 1 ); |
| 1198 | | } |
| 1391 | if (sms_state.cartridge[sms_state.current_cartridge].features & CF_GG_SMS_MODE) |
| 1392 | sms_set_ggsmsmode(smsvdp, 1); |
| 1199 | 1393 | |
| 1200 | 1394 | /* Initialize SIO stuff for GG */ |
| 1201 | | sms_state.ggSIO[0] = 0x7F; |
| 1202 | | sms_state.ggSIO[1] = 0xFF; |
| 1203 | | sms_state.ggSIO[2] = 0x00; |
| 1204 | | sms_state.ggSIO[3] = 0xFF; |
| 1205 | | sms_state.ggSIO[4] = 0x00; |
| 1395 | sms_state.gg_sio[0] = 0x7f; |
| 1396 | sms_state.gg_sio[1] = 0xff; |
| 1397 | sms_state.gg_sio[2] = 0x00; |
| 1398 | sms_state.gg_sio[3] = 0xff; |
| 1399 | sms_state.gg_sio[4] = 0x00; |
| 1206 | 1400 | |
| 1207 | 1401 | sms_state.store_control = 0; |
| 1208 | 1402 | |
| r6078 | r6079 | |
| 1212 | 1406 | |
| 1213 | 1407 | sms_state.rapid_fire_state_1 = 0; |
| 1214 | 1408 | sms_state.rapid_fire_state_2 = 0; |
| 1215 | | sms_state.rapid_fire_timer = timer_alloc(machine, rapid_fire_callback , NULL); |
| 1409 | sms_state.rapid_fire_timer = timer_alloc(machine, rapid_fire_callback , NULL); |
| 1216 | 1410 | timer_adjust_periodic(sms_state.rapid_fire_timer, ATTOTIME_IN_HZ(10), 0, ATTOTIME_IN_HZ(10)); |
| 1217 | 1411 | |
| 1218 | 1412 | sms_state.last_paddle_read_time = 0; |
| r6078 | r6079 | |
| 1228 | 1422 | sms_state.sports_pad_1_y = 0; |
| 1229 | 1423 | sms_state.sports_pad_2_x = 0; |
| 1230 | 1424 | sms_state.sports_pad_2_y = 0; |
| 1425 | |
| 1426 | sms_state.lphaser_latch = 0; |
| 1427 | sms_state.lphaser_1_x = 0; |
| 1428 | sms_state.lphaser_1_y = 0; |
| 1429 | sms_state.lphaser_2_x = 0; |
| 1430 | sms_state.lphaser_2_x = 0; |
| 1431 | |
| 1432 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 1433 | timer_set(space->machine, attotime_zero, NULL, 0, lightgun_tick); |
| 1231 | 1434 | } |
| 1232 | 1435 | |
| 1233 | 1436 | |
| 1234 | | READ8_HANDLER(sms_store_cart_select_r) |
| 1437 | READ8_HANDLER( sms_store_cart_select_r ) |
| 1235 | 1438 | { |
| 1236 | | return 0xFF; |
| 1439 | return 0xff; |
| 1237 | 1440 | } |
| 1238 | 1441 | |
| 1239 | 1442 | |
| 1240 | | WRITE8_HANDLER(sms_store_cart_select_w) |
| 1443 | WRITE8_HANDLER( sms_store_cart_select_w ) |
| 1241 | 1444 | { |
| 1242 | 1445 | UINT8 slot = data >> 4; |
| 1243 | 1446 | UINT8 slottype = data & 0x08; |
| 1244 | 1447 | |
| 1245 | 1448 | logerror("switching in part of %s slot #%d\n", slottype ? "card" : "cartridge", slot ); |
| 1246 | 1449 | /* cartridge? slot #0 */ |
| 1247 | | if ( slottype == 0 ) |
| 1248 | | { |
| 1450 | if (slottype == 0) |
| 1249 | 1451 | sms_state.current_cartridge = slot; |
| 1250 | | } |
| 1452 | |
| 1251 | 1453 | setup_cart_banks(); |
| 1252 | | memory_set_bankptr(space->machine, 10, sms_state.banking_cart[3] + 0x2000 ); |
| 1454 | memory_set_bankptr(space->machine, 10, sms_state.banking_cart[3] + 0x2000); |
| 1253 | 1455 | setup_rom(space); |
| 1254 | 1456 | } |
| 1255 | 1457 | |
| 1256 | 1458 | |
| 1257 | | READ8_HANDLER(sms_store_select1) |
| 1459 | READ8_HANDLER( sms_store_select1 ) |
| 1258 | 1460 | { |
| 1259 | | return 0xFF; |
| 1461 | return 0xff; |
| 1260 | 1462 | } |
| 1261 | 1463 | |
| 1262 | 1464 | |
| 1263 | | READ8_HANDLER(sms_store_select2) |
| 1465 | READ8_HANDLER( sms_store_select2 ) |
| 1264 | 1466 | { |
| 1265 | | return 0xFF; |
| 1467 | return 0xff; |
| 1266 | 1468 | } |
| 1267 | 1469 | |
| 1268 | 1470 | |
| 1269 | | READ8_HANDLER(sms_store_control_r) |
| 1471 | READ8_HANDLER( sms_store_control_r ) |
| 1270 | 1472 | { |
| 1271 | 1473 | return sms_state.store_control; |
| 1272 | 1474 | } |
| 1273 | 1475 | |
| 1274 | 1476 | |
| 1275 | | WRITE8_HANDLER(sms_store_control_w) |
| 1477 | WRITE8_HANDLER( sms_store_control_w ) |
| 1276 | 1478 | { |
| 1277 | | logerror( "0x%04X: sms_store_control write 0x%02X\n", cpu_get_pc(space->cpu), data ); |
| 1278 | | if ( data & 0x02 ) |
| 1479 | logerror("0x%04X: sms_store_control write 0x%02X\n", cpu_get_pc(space->cpu), data); |
| 1480 | if (data & 0x02) |
| 1279 | 1481 | { |
| 1280 | | cputag_resume( space->machine, "maincpu", SUSPEND_REASON_HALT ); |
| 1482 | cputag_resume(space->machine, "maincpu", SUSPEND_REASON_HALT); |
| 1281 | 1483 | } |
| 1282 | 1484 | else |
| 1283 | 1485 | { |
| 1284 | 1486 | /* Pull reset line of CPU #0 low */ |
| 1285 | | cputag_suspend( space->machine, "maincpu", SUSPEND_REASON_HALT, 1 ); |
| 1487 | cputag_suspend(space->machine, "maincpu", SUSPEND_REASON_HALT, 1); |
| 1286 | 1488 | device_reset(cputag_get_cpu(space->machine, "maincpu")); |
| 1287 | 1489 | } |
| 1288 | 1490 | sms_state.store_control = data; |
| 1289 | 1491 | } |
| 1290 | 1492 | |
| 1291 | | |
| 1292 | | void sms_int_callback( running_machine *machine, int state ) |
| 1493 | void sms_store_int_callback( running_machine *machine, int state ) |
| 1293 | 1494 | { |
| 1294 | | cputag_set_input_line(machine, "maincpu", 0, state ); |
| 1495 | cputag_set_input_line(machine, "maincpu", sms_state.store_control & 0x01 ? 1 : 0, state); |
| 1295 | 1496 | } |
| 1296 | 1497 | |
| 1297 | 1498 | |
| 1298 | | void sms_store_int_callback( running_machine *machine, int state ) |
| 1499 | static void sms_set_zero_flag( void ) |
| 1299 | 1500 | { |
| 1300 | | cputag_set_input_line(machine, "maincpu", sms_state.store_control & 0x01 ? 1 : 0, state ); |
| 1501 | sms_state.is_gamegear = 0; |
| 1502 | sms_state.is_region_japan = 0; |
| 1503 | sms_state.has_bios_0400 = 0; |
| 1504 | sms_state.has_bios_2000 = 0; |
| 1505 | sms_state.has_bios_full = 0; |
| 1506 | sms_state.has_bios = 0; |
| 1507 | sms_state.has_fm = 0; |
| 1301 | 1508 | } |
| 1302 | 1509 | |
| 1303 | | |
| 1304 | 1510 | DRIVER_INIT( sg1000m3 ) |
| 1305 | 1511 | { |
| 1306 | | sms_state.flags = FLAG_REGION_JAPAN | FLAG_FM; |
| 1512 | sms_set_zero_flag(); |
| 1513 | sms_state.is_region_japan = 1; |
| 1514 | sms_state.has_fm = 1; |
| 1307 | 1515 | } |
| 1308 | 1516 | |
| 1309 | 1517 | |
| 1310 | 1518 | DRIVER_INIT( sms1 ) |
| 1311 | 1519 | { |
| 1312 | | sms_state.flags = FLAG_BIOS_FULL; |
| 1520 | sms_set_zero_flag(); |
| 1521 | sms_state.has_bios_full = 1; |
| 1313 | 1522 | } |
| 1314 | 1523 | |
| 1315 | 1524 | |
| 1316 | 1525 | DRIVER_INIT( smsj ) |
| 1317 | 1526 | { |
| 1318 | | sms_state.flags = FLAG_REGION_JAPAN | FLAG_BIOS_2000 | FLAG_FM; |
| 1527 | sms_set_zero_flag(); |
| 1528 | sms_state.is_region_japan = 1; |
| 1529 | sms_state.has_bios_2000 = 1; |
| 1530 | sms_state.has_fm = 1; |
| 1319 | 1531 | } |
| 1320 | 1532 | |
| 1321 | 1533 | |
| 1322 | 1534 | DRIVER_INIT( sms2kr ) |
| 1323 | 1535 | { |
| 1324 | | sms_state.flags = FLAG_REGION_JAPAN | FLAG_BIOS_FULL | FLAG_FM; |
| 1536 | sms_set_zero_flag(); |
| 1537 | sms_state.is_region_japan = 1; |
| 1538 | sms_state.has_bios_full = 1; |
| 1539 | sms_state.has_fm = 1; |
| 1325 | 1540 | } |
| 1326 | 1541 | |
| 1327 | 1542 | |
| 1328 | 1543 | DRIVER_INIT( smssdisp ) |
| 1329 | 1544 | { |
| 1330 | | sms_state.flags = 0; |
| 1545 | sms_set_zero_flag(); |
| 1331 | 1546 | } |
| 1332 | 1547 | |
| 1333 | 1548 | |
| 1334 | 1549 | DRIVER_INIT( gamegear ) |
| 1335 | 1550 | { |
| 1336 | | sms_state.flags = FLAG_GAMEGEAR; |
| 1551 | sms_set_zero_flag(); |
| 1552 | sms_state.is_gamegear = 1; |
| 1337 | 1553 | } |
| 1338 | 1554 | |
| 1339 | 1555 | |
| 1340 | 1556 | DRIVER_INIT( gamegeaj ) |
| 1341 | 1557 | { |
| 1342 | | sms_state.flags = FLAG_REGION_JAPAN | FLAG_GAMEGEAR | FLAG_BIOS_0400; |
| 1558 | sms_set_zero_flag(); |
| 1559 | sms_state.is_region_japan = 1; |
| 1560 | sms_state.is_gamegear = 1; |
| 1561 | sms_state.has_bios_0400 = 1; |
| 1343 | 1562 | } |
src/mess/drivers/sms.c
| r6078 | r6079 | |
| 95 | 95 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 96 | 96 | ADDRESS_MAP_UNMAP_HIGH |
| 97 | 97 | AM_RANGE(0x00, 0x00) AM_MIRROR(0x3e) AM_WRITE(sms_bios_w) |
| 98 | | AM_RANGE(0x01, 0x01) AM_MIRROR(0x3e) AM_WRITE(sms_version_w) |
| 98 | AM_RANGE(0x01, 0x01) AM_MIRROR(0x3e) AM_WRITE(sms_io_control_w) |
| 99 | 99 | AM_RANGE(0x40, 0x7F) AM_READ(sms_count_r) |
| 100 | 100 | AM_RANGE(0x40, 0x7F) AM_DEVWRITE("smsiii", sn76496_w) |
| 101 | | AM_RANGE(0x80, 0x80) AM_MIRROR(0x3e) AM_READWRITE(sms_vdp_data_r, sms_vdp_data_w) |
| 102 | | AM_RANGE(0x80, 0x81) AM_MIRROR(0x3e) AM_READWRITE(sms_vdp_ctrl_r, sms_vdp_ctrl_w) |
| 101 | AM_RANGE(0x80, 0x80) AM_MIRROR(0x3e) AM_DEVREADWRITE("sms_vdp", sms_vdp_data_r, sms_vdp_data_w) |
| 102 | AM_RANGE(0x81, 0x81) AM_MIRROR(0x3e) AM_DEVREADWRITE("sms_vdp", sms_vdp_ctrl_r, sms_vdp_ctrl_w) |
| 103 | 103 | AM_RANGE(0xC0, 0xC0) AM_MIRROR(0x1e) AM_READ(sms_input_port_0_r) |
| 104 | | AM_RANGE(0xC1, 0xC1) AM_MIRROR(0x1e) AM_READ(sms_version_r) |
| 104 | AM_RANGE(0xC1, 0xC1) AM_MIRROR(0x1e) AM_READ(sms_input_port_1_r) |
| 105 | 105 | AM_RANGE(0xE0, 0xE0) AM_MIRROR(0x0e) AM_READ(sms_input_port_0_r) |
| 106 | | AM_RANGE(0xE1, 0xE1) AM_MIRROR(0x0e) AM_READ(sms_version_r) |
| 107 | | AM_RANGE(0xF0, 0xF0) AM_READWRITE(sms_input_port_0_r, sms_ym2413_register_port_0_w) |
| 108 | | AM_RANGE(0xF1, 0xF1) AM_READWRITE(sms_version_r, sms_ym2413_data_port_0_w) |
| 109 | | AM_RANGE(0xF2, 0xF2) AM_READWRITE(sms_fm_detect_r, sms_fm_detect_w) |
| 110 | | AM_RANGE(0xF3, 0xF3) AM_READ(sms_version_r) |
| 106 | AM_RANGE(0xE1, 0xE1) AM_MIRROR(0x0e) AM_READ(sms_input_port_1_r) |
| 107 | AM_RANGE(0xF0, 0xF0) AM_READWRITE(sms_input_port_0_r, sms_ym2413_register_port_0_w) |
| 108 | AM_RANGE(0xF1, 0xF1) AM_READWRITE(sms_input_port_1_r, sms_ym2413_data_port_0_w) |
| 109 | AM_RANGE(0xF2, 0xF2) AM_READWRITE(sms_fm_detect_r, sms_fm_detect_w) |
| 110 | AM_RANGE(0xF3, 0xF3) AM_READ(sms_input_port_1_r) |
| 111 | 111 | AM_RANGE(0xF4, 0xF4) AM_MIRROR(0x02) AM_READ(sms_input_port_0_r) |
| 112 | | AM_RANGE(0xF5, 0xF5) AM_MIRROR(0x02) AM_READ(sms_version_r) |
| 112 | AM_RANGE(0xF5, 0xF5) AM_MIRROR(0x02) AM_READ(sms_input_port_1_r) |
| 113 | 113 | AM_RANGE(0xF8, 0xF8) AM_MIRROR(0x06) AM_READ(sms_input_port_0_r) |
| 114 | | AM_RANGE(0xF9, 0xF9) AM_MIRROR(0x06) AM_READ(sms_version_r) |
| 114 | AM_RANGE(0xF9, 0xF9) AM_MIRROR(0x06) AM_READ(sms_input_port_1_r) |
| 115 | 115 | ADDRESS_MAP_END |
| 116 | 116 | |
| 117 | 117 | static ADDRESS_MAP_START( gg_io, ADDRESS_SPACE_IO, 8 ) |
| 118 | 118 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 119 | 119 | ADDRESS_MAP_UNMAP_HIGH |
| 120 | | AM_RANGE(0x00, 0x00) AM_READ(gg_input_port_2_r) |
| 121 | | AM_RANGE(0x01, 0x05) AM_READWRITE(gg_sio_r, gg_sio_w) |
| 122 | | AM_RANGE(0x06, 0x06) AM_READWRITE(gg_psg_r, gg_psg_w) |
| 123 | | AM_RANGE(0x07, 0x07) AM_WRITE(sms_version_w) |
| 120 | AM_RANGE(0x00, 0x00) AM_READ(gg_input_port_2_r) |
| 121 | AM_RANGE(0x01, 0x05) AM_READWRITE(gg_sio_r, gg_sio_w) |
| 122 | AM_RANGE(0x06, 0x06) AM_READWRITE(gg_psg_r, gg_psg_w) |
| 123 | AM_RANGE(0x07, 0x07) AM_WRITE(sms_io_control_w) |
| 124 | 124 | AM_RANGE(0x08, 0x08) AM_MIRROR(0x06) AM_WRITE(sms_bios_w) |
| 125 | | AM_RANGE(0x09, 0x09) AM_MIRROR(0x06) AM_WRITE(sms_version_w) |
| 125 | AM_RANGE(0x09, 0x09) AM_MIRROR(0x06) AM_WRITE(sms_io_control_w) |
| 126 | 126 | AM_RANGE(0x10, 0x10) AM_MIRROR(0x0e) AM_WRITE(sms_bios_w) |
| 127 | | AM_RANGE(0x11, 0x11) AM_MIRROR(0x0e) AM_WRITE(sms_version_w) |
| 127 | AM_RANGE(0x11, 0x11) AM_MIRROR(0x0e) AM_WRITE(sms_io_control_w) |
| 128 | 128 | AM_RANGE(0x20, 0x20) AM_MIRROR(0x1e) AM_WRITE(sms_bios_w) |
| 129 | | AM_RANGE(0x21, 0x21) AM_MIRROR(0x1e) AM_WRITE(sms_version_w) |
| 129 | AM_RANGE(0x21, 0x21) AM_MIRROR(0x1e) AM_WRITE(sms_io_control_w) |
| 130 | 130 | AM_RANGE(0x40, 0x7F) AM_READ(sms_count_r) |
| 131 | 131 | AM_RANGE(0x40, 0x7F) AM_DEVWRITE("gamegear", sn76496_w) |
| 132 | | AM_RANGE(0x80, 0x80) AM_MIRROR(0x3e) AM_READWRITE(sms_vdp_data_r, sms_vdp_data_w) |
| 133 | | AM_RANGE(0x80, 0x81) AM_MIRROR(0x3e) AM_READWRITE(sms_vdp_ctrl_r, sms_vdp_ctrl_w) |
| 134 | | AM_RANGE(0xC0, 0xC0) AM_READ_PORT("PORT_DC") |
| 135 | | AM_RANGE(0xC1, 0xC1) AM_READ_PORT("PORT_DD") |
| 136 | | AM_RANGE(0xDC, 0xDC) AM_READ_PORT("PORT_DC") |
| 137 | | AM_RANGE(0xDD, 0xDD) AM_READ_PORT("PORT_DD") |
| 132 | AM_RANGE(0x80, 0x80) AM_MIRROR(0x3e) AM_DEVREADWRITE("sms_vdp", sms_vdp_data_r, sms_vdp_data_w) |
| 133 | AM_RANGE(0x81, 0x81) AM_MIRROR(0x3e) AM_DEVREADWRITE("sms_vdp", sms_vdp_ctrl_r, sms_vdp_ctrl_w) |
| 134 | AM_RANGE(0xC0, 0xC0) AM_READ_PORT("PORT_DC") |
| 135 | AM_RANGE(0xC1, 0xC1) AM_READ_PORT("PORT_DD") |
| 136 | AM_RANGE(0xDC, 0xDC) AM_READ_PORT("PORT_DC") |
| 137 | AM_RANGE(0xDD, 0xDD) AM_READ_PORT("PORT_DD") |
| 138 | 138 | ADDRESS_MAP_END |
| 139 | 139 | |
| 140 | 140 | |
| r6078 | r6079 | |
| 164 | 164 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START ) PORT_NAME(DEF_STR(Pause)) |
| 165 | 165 | |
| 166 | 166 | PORT_START("LPHASER0") /* Light phaser X - player 1 */ |
| 167 | | // PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR( X, 1.0, 0.0, 0 ) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_CATEGORY(11) PORT_PLAYER(1) |
| 167 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR( X, 1.0, 0.0, 0 ) PORT_SENSITIVITY(50) PORT_KEYDELTA(15) PORT_CATEGORY(11) PORT_PLAYER(1) |
| 168 | 168 | |
| 169 | 169 | PORT_START("LPHASER1") /* Light phaser Y - player 1 */ |
| 170 | | // PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR( Y, 1.0, 0.0, 0 ) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_CATEGORY(11) PORT_PLAYER(1) |
| 170 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR( Y, 1.0, 0.0, 0 ) PORT_SENSITIVITY(50) PORT_KEYDELTA(15) PORT_CATEGORY(11) PORT_PLAYER(1) |
| 171 | 171 | |
| 172 | | PORT_START("LPHASER2") /* Light phaser X - player 2 */ |
| 173 | | // PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR( X, 1.0, 0.0, 0 ) PORT_SENSITIVITY(25) PORT_KEUDELTA(15) PORT_CATEGORY(21) PORT_PLAYER(2) |
| 172 | PORT_START("LPHASER2") /* Light phaser X - player 2 */ |
| 173 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_X ) PORT_CROSSHAIR( X, 1.0, 0.0, 0 ) PORT_SENSITIVITY(50) PORT_KEYDELTA(15) PORT_CATEGORY(21) PORT_PLAYER(2) |
| 174 | 174 | |
| 175 | 175 | PORT_START("LPHASER3") /* Light phaser Y - player 2 */ |
| 176 | | // PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR( Y, 1.0, 0.0, 0 ) PORT_SENSITIVITY(25) PORT_KEYDELTA(25) PORT_CATEGORY(21) PORT_PLAYER(2) |
| 176 | PORT_BIT( 0xff, 0x80, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR( Y, 1.0, 0.0, 0 ) PORT_SENSITIVITY(50) PORT_KEYDELTA(25) PORT_CATEGORY(21) PORT_PLAYER(2) |
| 177 | 177 | |
| 178 | 178 | PORT_START("RFU") /* Rapid Fire Unit */ |
| 179 | 179 | PORT_DIPNAME( 0x03, 0x00, "Rapid Fire Unit - Player 1" ) |
| r6078 | r6079 | |
| 204 | 204 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_CATEGORY(23) PORT_PLAYER(2) |
| 205 | 205 | |
| 206 | 206 | PORT_START("CTRLSEL") /* Controller selection */ |
| 207 | | PORT_CATEGORY_CLASS( 0x0F, 0x00, "Player 1 Controller" ) |
| 207 | PORT_CATEGORY_CLASS( 0x0f, 0x00, "Player 1 Controller" ) |
| 208 | 208 | PORT_CATEGORY_ITEM( 0x00, DEF_STR( Joystick ), 10 ) |
| 209 | | // PORT_CATEGORY_ITEM( 0x01, "Light Phaser", 11 ) |
| 209 | PORT_CATEGORY_ITEM( 0x01, "Light Phaser", 11 ) |
| 210 | 210 | PORT_CATEGORY_ITEM( 0x02, "Sega Paddle Control", 12 ) |
| 211 | 211 | PORT_CATEGORY_ITEM( 0x03, "Sega Sports Pad", 13 ) |
| 212 | | PORT_CATEGORY_CLASS( 0xF0, 0x00, "Player 2 Controller" ) |
| 212 | PORT_CATEGORY_CLASS( 0xf0, 0x00, "Player 2 Controller" ) |
| 213 | 213 | PORT_CATEGORY_ITEM( 0x00, DEF_STR( Joystick ), 20 ) |
| 214 | | // PORT_CATEGORY_ITEM( 0x10, "Light Phaser", 21 ) |
| 214 | PORT_CATEGORY_ITEM( 0x10, "Light Phaser", 21 ) |
| 215 | 215 | PORT_CATEGORY_ITEM( 0x20, "Sega Paddle Control", 22 ) |
| 216 | 216 | PORT_CATEGORY_ITEM( 0x30, "Sega Sports Pad", 23 ) |
| 217 | 217 | |
| r6078 | r6079 | |
| 249 | 249 | static PALETTE_INIT( sms ) |
| 250 | 250 | { |
| 251 | 251 | int i; |
| 252 | | for( i = 0; i < 64; i++ ) |
| 252 | for (i = 0; i < 64; i++) |
| 253 | 253 | { |
| 254 | 254 | int r = i & 0x03; |
| 255 | | int g = ( i & 0x0C ) >> 2; |
| 256 | | int b = ( i & 0x30 ) >> 4; |
| 257 | | palette_set_color_rgb(machine, i, r << 6, g << 6, b << 6 ); |
| 255 | int g = (i & 0x0c) >> 2; |
| 256 | int b = (i & 0x30) >> 4; |
| 257 | palette_set_color_rgb(machine, i, r << 6, g << 6, b << 6); |
| 258 | 258 | } |
| 259 | 259 | /* TMS9918 palette */ |
| 260 | | palette_set_color_rgb(machine, 64+ 0, 0, 0, 0 ); |
| 261 | | palette_set_color_rgb(machine, 64+ 1, 0, 0, 0 ); |
| 262 | | palette_set_color_rgb(machine, 64+ 2, 33, 200, 66 ); |
| 263 | | palette_set_color_rgb(machine, 64+ 3, 94, 220, 120 ); |
| 264 | | palette_set_color_rgb(machine, 64+ 4, 84, 85, 237 ); |
| 265 | | palette_set_color_rgb(machine, 64+ 5, 125, 118, 252 ); |
| 266 | | palette_set_color_rgb(machine, 64+ 6, 212, 82, 77 ); |
| 267 | | palette_set_color_rgb(machine, 64+ 7, 66, 235, 245 ); |
| 268 | | palette_set_color_rgb(machine, 64+ 8, 252, 85, 84 ); |
| 269 | | palette_set_color_rgb(machine, 64+ 9, 255, 121, 120 ); |
| 270 | | palette_set_color_rgb(machine, 64+10, 212, 193, 84 ); |
| 271 | | palette_set_color_rgb(machine, 64+11, 230, 206, 128 ); |
| 272 | | palette_set_color_rgb(machine, 64+12, 33, 176, 59 ); |
| 273 | | palette_set_color_rgb(machine, 64+13, 201, 91, 186 ); |
| 274 | | palette_set_color_rgb(machine, 64+14, 204, 204, 204 ); |
| 275 | | palette_set_color_rgb(machine, 64+15, 255, 255, 255 ); |
| 260 | palette_set_color_rgb(machine, 64+ 0, 0, 0, 0); |
| 261 | palette_set_color_rgb(machine, 64+ 1, 0, 0, 0); |
| 262 | palette_set_color_rgb(machine, 64+ 2, 33, 200, 66); |
| 263 | palette_set_color_rgb(machine, 64+ 3, 94, 220, 120); |
| 264 | palette_set_color_rgb(machine, 64+ 4, 84, 85, 237); |
| 265 | palette_set_color_rgb(machine, 64+ 5, 125, 118, 252); |
| 266 | palette_set_color_rgb(machine, 64+ 6, 212, 82, 77); |
| 267 | palette_set_color_rgb(machine, 64+ 7, 66, 235, 245); |
| 268 | palette_set_color_rgb(machine, 64+ 8, 252, 85, 84); |
| 269 | palette_set_color_rgb(machine, 64+ 9, 255, 121, 120); |
| 270 | palette_set_color_rgb(machine, 64+10, 212, 193, 84); |
| 271 | palette_set_color_rgb(machine, 64+11, 230, 206, 128); |
| 272 | palette_set_color_rgb(machine, 64+12, 33, 176, 59); |
| 273 | palette_set_color_rgb(machine, 64+13, 201, 91, 186); |
| 274 | palette_set_color_rgb(machine, 64+14, 204, 204, 204); |
| 275 | palette_set_color_rgb(machine, 64+15, 255, 255, 255); |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | static PALETTE_INIT( gamegear ) |
| 279 | 279 | { |
| 280 | 280 | int i; |
| 281 | | for( i = 0; i < 4096; i++ ) |
| 281 | for (i = 0; i < 4096; i++) |
| 282 | 282 | { |
| 283 | | int r = i & 0x000F; |
| 284 | | int g = ( i & 0x00F0 ) >> 4; |
| 285 | | int b = ( i & 0x0F00 ) >> 8; |
| 286 | | palette_set_color_rgb(machine, i, r << 4, g << 4, b << 4 ); |
| 283 | int r = i & 0x000f; |
| 284 | int g = (i & 0x00f0) >> 4; |
| 285 | int b = (i & 0x0f00) >> 8; |
| 286 | palette_set_color_rgb(machine, i, r << 4, g << 4, b << 4); |
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | | static const smsvdp_configuration config_315_5124 = { MODEL_315_5124, sms_int_callback }; |
| 291 | | static const smsvdp_configuration config_315_5246 = { MODEL_315_5246, sms_int_callback }; |
| 292 | | static const smsvdp_configuration config_315_5378 = { MODEL_315_5378, sms_int_callback }; |
| 293 | | static const smsvdp_configuration config_store = { MODEL_315_5124, sms_store_int_callback }; |
| 294 | 290 | |
| 295 | | static VIDEO_START(sega_315_5124) |
| 291 | |
| 292 | static void sms_int_callback( running_machine *machine, int state ) |
| 296 | 293 | { |
| 297 | | smsvdp_video_init( machine, &config_315_5124 ); |
| 294 | cputag_set_input_line(machine, "maincpu", 0, state); |
| 298 | 295 | } |
| 299 | 296 | |
| 300 | | static VIDEO_START(sega_315_5246) |
| 297 | static const smsvdp_interface _315_5124_intf = |
| 301 | 298 | { |
| 302 | | smsvdp_video_init( machine, &config_315_5246 ); |
| 303 | | } |
| 299 | MODEL_315_5124, |
| 300 | sms_int_callback, |
| 301 | sms_pause_callback |
| 302 | }; |
| 304 | 303 | |
| 305 | | static VIDEO_START(sega_315_5378) |
| 304 | static const smsvdp_interface _315_5246_intf = |
| 306 | 305 | { |
| 307 | | smsvdp_video_init( machine, &config_315_5378 ); |
| 308 | | } |
| 306 | MODEL_315_5246, |
| 307 | sms_int_callback, |
| 308 | sms_pause_callback |
| 309 | }; |
| 309 | 310 | |
| 310 | | static VIDEO_START(sega_store_315_5124) |
| 311 | static const smsvdp_interface _315_5378_intf = |
| 311 | 312 | { |
| 312 | | smsvdp_video_init( machine, &config_store ); |
| 313 | MODEL_315_5378, |
| 314 | sms_int_callback, |
| 315 | sms_pause_callback |
| 316 | }; |
| 317 | |
| 318 | static const smsvdp_interface sms_store_intf = |
| 319 | { |
| 320 | MODEL_315_5124, |
| 321 | sms_store_int_callback, |
| 322 | sms_pause_callback |
| 323 | }; |
| 324 | |
| 325 | static VIDEO_UPDATE(sms) |
| 326 | { |
| 327 | const device_config *smsvdp = devtag_get_device(screen->machine, "sms_vdp"); |
| 328 | smsvdp_update(smsvdp, bitmap, cliprect); |
| 329 | |
| 330 | return 0; |
| 313 | 331 | } |
| 314 | 332 | |
| 315 | 333 | static MACHINE_DRIVER_START( sms_cartslot ) |
| r6078 | r6079 | |
| 339 | 357 | MDRV_PALETTE_LENGTH(64+16) |
| 340 | 358 | MDRV_PALETTE_INIT(sms) |
| 341 | 359 | |
| 342 | | MDRV_VIDEO_START(sega_315_5124) |
| 343 | 360 | MDRV_VIDEO_UPDATE(sms) |
| 344 | 361 | |
| 362 | MDRV_SMSVDP_ADD("sms_vdp", _315_5124_intf) |
| 363 | |
| 345 | 364 | /* sound hardware */ |
| 346 | 365 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 347 | 366 | MDRV_SOUND_ADD("smsiii", SMSIII, XTAL_53_693175MHz/15) |
| r6078 | r6079 | |
| 352 | 371 | |
| 353 | 372 | static MACHINE_DRIVER_START(sms2ntsc) |
| 354 | 373 | MDRV_IMPORT_FROM(sms1ntsc) |
| 355 | | MDRV_VIDEO_START(sega_315_5246) |
| 374 | |
| 375 | MDRV_DEVICE_REMOVE("sms_vdp") |
| 376 | MDRV_SMSVDP_ADD("sms_vdp", _315_5246_intf) |
| 356 | 377 | MACHINE_DRIVER_END |
| 357 | 378 | |
| 358 | 379 | static MACHINE_DRIVER_START(smssdisp) |
| 359 | 380 | MDRV_IMPORT_FROM(sms1ntsc) |
| 360 | 381 | |
| 361 | | MDRV_VIDEO_START(sega_store_315_5124) |
| 382 | MDRV_DEVICE_REMOVE("sms_vdp") |
| 383 | MDRV_SMSVDP_ADD("sms_vdp", sms_store_intf) |
| 362 | 384 | |
| 363 | 385 | MDRV_CPU_ADD("control", Z80, XTAL_53_693175MHz/15) |
| 364 | 386 | MDRV_CPU_PROGRAM_MAP(sms_store_mem) |
| r6078 | r6079 | |
| 406 | 428 | MDRV_PALETTE_LENGTH(64+16) |
| 407 | 429 | MDRV_PALETTE_INIT(sms) |
| 408 | 430 | |
| 409 | | MDRV_VIDEO_START(sega_315_5124) |
| 410 | 431 | MDRV_VIDEO_UPDATE(sms) |
| 411 | 432 | |
| 433 | MDRV_SMSVDP_ADD("sms_vdp", _315_5124_intf) |
| 434 | |
| 412 | 435 | /* sound hardware */ |
| 413 | 436 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 414 | 437 | MDRV_SOUND_ADD("smsiii", SMSIII, MASTER_CLOCK_PAL/15) |
| r6078 | r6079 | |
| 419 | 442 | |
| 420 | 443 | static MACHINE_DRIVER_START(sms2pal) |
| 421 | 444 | MDRV_IMPORT_FROM(sms1pal) |
| 422 | | MDRV_VIDEO_START(sega_315_5246) |
| 445 | |
| 446 | MDRV_DEVICE_REMOVE("sms_vdp") |
| 447 | MDRV_SMSVDP_ADD("sms_vdp", _315_5246_intf) |
| 423 | 448 | MACHINE_DRIVER_END |
| 424 | 449 | |
| 425 | 450 | static MACHINE_DRIVER_START(smsfm) |
| r6078 | r6079 | |
| 464 | 489 | MDRV_PALETTE_LENGTH(4096) |
| 465 | 490 | MDRV_PALETTE_INIT(gamegear) |
| 466 | 491 | |
| 467 | | MDRV_VIDEO_START(sega_315_5378) |
| 468 | 492 | MDRV_VIDEO_UPDATE(sms) |
| 469 | 493 | |
| 494 | MDRV_SMSVDP_ADD("sms_vdp", _315_5378_intf) |
| 495 | |
| 470 | 496 | /* sound hardware */ |
| 471 | 497 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 472 | 498 | MDRV_SOUND_ADD("gamegear", GAMEGEAR, XTAL_53_693175MHz/15) |
| r6078 | r6079 | |
| 482 | 508 | |
| 483 | 509 | ROM_START(sms1) |
| 484 | 510 | ROM_REGION(0x4000, "maincpu", 0) |
| 485 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 511 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 512 | |
| 486 | 513 | ROM_REGION(0x20000, "user1", 0) |
| 487 | 514 | ROM_SYSTEM_BIOS( 0, "bios13", "US/European BIOS v1.3 (1986)" ) |
| 488 | 515 | ROMX_LOAD("bios13fx.rom", 0x0000, 0x2000, CRC(0072ED54) SHA1(c315672807d8ddb8d91443729405c766dd95cae7), ROM_BIOS(1)) |
| r6078 | r6079 | |
| 498 | 525 | |
| 499 | 526 | ROM_START(sms) |
| 500 | 527 | ROM_REGION(0x4000, "maincpu", 0) |
| 501 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 528 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 529 | |
| 502 | 530 | ROM_REGION(0x20000, "user1", 0) |
| 503 | 531 | ROM_SYSTEM_BIOS( 0, "alexkidd", "US/European BIOS with Alex Kidd in Miracle World (1990)" ) |
| 504 | 532 | ROMX_LOAD("akbios.rom", 0x0000, 0x20000, CRC(CF4A09EA) SHA1(3af7b66248d34eb26da40c92bf2fa4c73a46a051), ROM_BIOS(1)) |
| r6078 | r6079 | |
| 506 | 534 | |
| 507 | 535 | ROM_START(smssdisp) |
| 508 | 536 | ROM_REGION(0x4000, "maincpu", 0) |
| 509 | | ROM_FILL(0x0000,0x4000,0x00) |
| 537 | ROM_FILL(0x0000, 0x4000, 0x00) |
| 538 | |
| 510 | 539 | ROM_REGION(0x4000, "user1", 0) |
| 511 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 540 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 541 | |
| 512 | 542 | ROM_REGION(0x4000, "control", 0) |
| 513 | 543 | ROM_LOAD("smssdisp.rom", 0x0000, 0x4000, CRC(ee2c29ba) SHA1(fc465122134d95363112eb51b9ab71db3576cefd)) |
| 514 | 544 | ROM_END |
| 515 | 545 | |
| 516 | 546 | ROM_START(sms1pal) |
| 517 | 547 | ROM_REGION(0x4000, "maincpu", 0) |
| 518 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 548 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 549 | |
| 519 | 550 | ROM_REGION(0x20000, "user1", 0) |
| 520 | | ROM_SYSTEM_BIOS( 0, "bios13", "US/European BIOS v1.3 (1986)" ) |
| 551 | ROM_SYSTEM_BIOS( 0, "bios13", "US/European BIOS v1.3 (1986)" ) |
| 521 | 552 | ROMX_LOAD("bios13fx.rom", 0x0000, 0x2000, CRC(0072ED54) SHA1(c315672807d8ddb8d91443729405c766dd95cae7), ROM_BIOS(1)) |
| 522 | 553 | ROM_SYSTEM_BIOS( 1, "hangonsh", "US/European BIOS v2.4 with Hang On and Safari Hunt (1988)" ) |
| 523 | 554 | ROMX_LOAD("hshbios.rom", 0x0000, 0x20000, CRC(91E93385) SHA1(9e179392cd416af14024d8f31c981d9ee9a64517), ROM_BIOS(2)) |
| r6078 | r6079 | |
| 529 | 560 | |
| 530 | 561 | ROM_START(smspal) |
| 531 | 562 | ROM_REGION(0x4000, "maincpu", 0) |
| 532 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 563 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 564 | |
| 533 | 565 | ROM_REGION(0x40000, "user1", 0) |
| 534 | 566 | ROM_SYSTEM_BIOS( 0, "alexkidd", "US/European BIOS with Alex Kidd in Miracle World (1990)" ) |
| 535 | 567 | ROMX_LOAD("akbios.rom", 0x0000, 0x20000, CRC(CF4A09EA) SHA1(3af7b66248d34eb26da40c92bf2fa4c73a46a051), ROM_BIOS(1)) |
| r6078 | r6079 | |
| 539 | 571 | |
| 540 | 572 | ROM_START(sg1000m3) |
| 541 | 573 | ROM_REGION(0x4000, "maincpu", 0) |
| 542 | | ROM_FILL(0x0000,0x4000,0x00) |
| 574 | ROM_FILL(0x0000, 0x4000, 0x00) |
| 543 | 575 | ROM_END |
| 544 | 576 | |
| 545 | 577 | ROM_START(smsj) |
| 546 | 578 | ROM_REGION(0x4000, "maincpu", 0) |
| 547 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 579 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 580 | |
| 548 | 581 | ROM_REGION(0x4000, "user1", 0) |
| 549 | | ROM_SYSTEM_BIOS( 0, "jbios21", "Japanese BIOS v2.1 (1987)" ) |
| 582 | ROM_SYSTEM_BIOS( 0, "jbios21", "Japanese BIOS v2.1 (1987)" ) |
| 550 | 583 | ROMX_LOAD("jbios21.rom", 0x0000, 0x2000, CRC(48D44A13) SHA1(a8c1b39a2e41137835eda6a5de6d46dd9fadbaf2), ROM_BIOS(1)) |
| 551 | 584 | ROM_END |
| 552 | 585 | |
| 553 | 586 | ROM_START(sms2kr) |
| 554 | 587 | ROM_REGION(0x4000, "maincpu", 0) |
| 555 | | ROM_FILL(0x0000,0x4000,0xFF) |
| 588 | ROM_FILL(0x0000, 0x4000, 0xff) |
| 589 | |
| 556 | 590 | ROM_REGION(0x20000, "user1", 0) |
| 557 | 591 | ROM_SYSTEM_BIOS( 0, "akbioskr", "Samsung Gam*Boy II with Alex Kidd in Miracle World (1990)" ) |
| 558 | 592 | ROMX_LOAD("akbioskr.rom", 0x000, 0x20000, CRC(9c5bad91) SHA1(2feafd8f1c40fdf1bd5668f8c5c02e5560945b17), ROM_BIOS(1)) |
| 559 | 593 | ROM_END |
| 560 | 594 | |
| 561 | 595 | ROM_START(gamegear) |
| 562 | | ROM_REGION(0x4000, "maincpu",0) |
| 563 | | ROM_FILL(0x0000,0x4000,0x00) |
| 596 | ROM_REGION(0x4000, "maincpu", 0) |
| 597 | ROM_FILL(0x0000, 0x4000, 0x00) |
| 598 | |
| 564 | 599 | ROM_REGION(0x0400, "user1", 0) |
| 565 | 600 | ROM_SYSTEM_BIOS( 0, "none", "No BIOS" ) /* gamegear */ |
| 566 | 601 | ROM_SYSTEM_BIOS( 1, "majesco", "Majesco BIOS" ) /* gamg */ |