src/mess/video/fmtowns.c
| r8380 | r8381 | |
| 92 | 92 | //#define CRTC_REG_DISP 1 |
| 93 | 93 | //#define SPR_DEBUG 1 |
| 94 | 94 | |
| 95 | | static UINT8 towns_vram_wplane; |
| 96 | | static UINT8 towns_vram_rplane; |
| 97 | | static UINT8 towns_vram_page_sel; |
| 98 | | static UINT8 towns_palette_select; |
| 99 | | static UINT8 towns_palette_r[256]; |
| 100 | | static UINT8 towns_palette_g[256]; |
| 101 | | static UINT8 towns_palette_b[256]; |
| 102 | | static UINT8 towns_degipal[8]; |
| 103 | | static UINT8 towns_dpmd_flag; |
| 104 | | static UINT8 towns_crtc_mix; |
| 105 | | static UINT8 towns_crtc_sel; // selected CRTC register |
| 106 | | static UINT16 towns_crtc_reg[32]; |
| 107 | | static UINT8 towns_video_sel; // selected video register |
| 108 | | static UINT8 towns_video_reg[2]; |
| 109 | | static UINT8 towns_sprite_sel; // selected sprite register |
| 110 | | static UINT8 towns_sprite_reg[8]; |
| 111 | | static UINT8 towns_tvram_enable; |
| 112 | | static UINT16 towns_kanji_offset; |
| 113 | | static UINT8 towns_kanji_code_h; |
| 114 | | static UINT8 towns_kanji_code_l; |
| 115 | | static rectangle towns_crtc_layerscr[2]; // each layer has independent sizes |
| 116 | | static UINT8 towns_display_plane; |
| 117 | | static UINT8 towns_display_page_sel; |
| 118 | | static UINT8 towns_vblank_flag; |
| 119 | | static UINT8 towns_layer_ctrl; |
| 120 | | |
| 121 | | extern UINT32* towns_vram; |
| 122 | | extern UINT8* towns_gfxvram; |
| 123 | | extern UINT8* towns_txtvram; |
| 95 | //extern UINT32* towns_vram; |
| 96 | //extern UINT8* towns_gfxvram; |
| 97 | //extern UINT8* towns_txtvram; |
| 124 | 98 | //extern UINT8* towns_sprram; |
| 125 | 99 | |
| 126 | | extern UINT32 towns_mainmem_enable; |
| 127 | | extern UINT32 towns_ankcg_enable; |
| 100 | //extern UINT32 towns_mainmem_enable; |
| 101 | //extern UINT32 towns_ankcg_enable; |
| 128 | 102 | |
| 129 | 103 | //static UINT32 pshift; // for debugging |
| 130 | 104 | |
| 131 | 105 | void towns_crtc_refresh_mode(running_machine* machine) |
| 132 | 106 | { |
| 107 | towns_state* state = (towns_state*)machine->driver_data; |
| 133 | 108 | rectangle scr; |
| 134 | 109 | unsigned int width,height; |
| 135 | 110 | |
| 136 | 111 | scr.min_x = scr.min_y = 0; |
| 137 | | scr.max_x = towns_crtc_reg[4]; |
| 138 | | scr.max_y = towns_crtc_reg[8] / 2; |
| 112 | scr.max_x = state->video.towns_crtc_reg[4]; |
| 113 | scr.max_y = state->video.towns_crtc_reg[8] / 2; |
| 139 | 114 | |
| 140 | 115 | // layer 0 |
| 141 | | width = towns_crtc_reg[10] - towns_crtc_reg[9]; |
| 142 | | height = (towns_crtc_reg[14] - towns_crtc_reg[13]) / 2; |
| 143 | | towns_crtc_layerscr[0].min_x = (scr.max_x / 2) - (width / 2); |
| 144 | | towns_crtc_layerscr[0].min_y = (scr.max_y / 2) - (height / 2); |
| 145 | | towns_crtc_layerscr[0].max_x = (scr.max_x / 2) + (width / 2); |
| 146 | | towns_crtc_layerscr[0].max_y = (scr.max_y / 2) + (height / 2); |
| 116 | width = state->video.towns_crtc_reg[10] - state->video.towns_crtc_reg[9]; |
| 117 | height = (state->video.towns_crtc_reg[14] - state->video.towns_crtc_reg[13]) / 2; |
| 118 | state->video.towns_crtc_layerscr[0].min_x = (scr.max_x / 2) - (width / 2); |
| 119 | state->video.towns_crtc_layerscr[0].min_y = (scr.max_y / 2) - (height / 2); |
| 120 | state->video.towns_crtc_layerscr[0].max_x = (scr.max_x / 2) + (width / 2); |
| 121 | state->video.towns_crtc_layerscr[0].max_y = (scr.max_y / 2) + (height / 2); |
| 147 | 122 | |
| 148 | 123 | // layer 1 |
| 149 | | width = towns_crtc_reg[12] - towns_crtc_reg[11]; |
| 150 | | height = (towns_crtc_reg[16] - towns_crtc_reg[15]) / 2; |
| 151 | | towns_crtc_layerscr[1].min_x = (scr.max_x / 2) - (width / 2); |
| 152 | | towns_crtc_layerscr[1].min_y = (scr.max_y / 2) - (height / 2); |
| 153 | | towns_crtc_layerscr[1].max_x = (scr.max_x / 2) + (width / 2); |
| 154 | | towns_crtc_layerscr[1].max_y = (scr.max_y / 2) + (height / 2); |
| 124 | width = state->video.towns_crtc_reg[12] - state->video.towns_crtc_reg[11]; |
| 125 | height = (state->video.towns_crtc_reg[16] - state->video.towns_crtc_reg[15]) / 2; |
| 126 | state->video.towns_crtc_layerscr[1].min_x = (scr.max_x / 2) - (width / 2); |
| 127 | state->video.towns_crtc_layerscr[1].min_y = (scr.max_y / 2) - (height / 2); |
| 128 | state->video.towns_crtc_layerscr[1].max_x = (scr.max_x / 2) + (width / 2); |
| 129 | state->video.towns_crtc_layerscr[1].max_y = (scr.max_y / 2) + (height / 2); |
| 155 | 130 | |
| 156 | 131 | // sanity checks |
| 157 | 132 | if(scr.max_x == 0 || scr.max_y == 0) |
| r8380 | r8381 | |
| 164 | 139 | |
| 165 | 140 | READ8_HANDLER( towns_gfx_high_r ) |
| 166 | 141 | { |
| 167 | | return towns_gfxvram[offset]; |
| 142 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 143 | return state->towns_gfxvram[offset]; |
| 168 | 144 | } |
| 169 | 145 | |
| 170 | 146 | WRITE8_HANDLER( towns_gfx_high_w ) |
| 171 | 147 | { |
| 172 | | towns_gfxvram[offset] = data; |
| 148 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 149 | state->towns_gfxvram[offset] = data; |
| 173 | 150 | } |
| 174 | 151 | |
| 175 | 152 | READ8_HANDLER( towns_gfx_r ) |
| 176 | 153 | { |
| 154 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 177 | 155 | UINT8 ret = 0; |
| 178 | 156 | |
| 179 | | if(towns_mainmem_enable != 0) |
| 180 | | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000]; |
| 157 | if(state->towns_mainmem_enable != 0) |
| 158 | return messram_get_ptr(state->messram)[offset+0xc0000]; |
| 181 | 159 | |
| 182 | 160 | offset = offset << 2; |
| 183 | 161 | |
| 184 | | if(towns_vram_page_sel != 0) |
| 162 | if(state->video.towns_vram_page_sel != 0) |
| 185 | 163 | offset += 0x20000; |
| 186 | 164 | |
| 187 | | ret = (((towns_gfxvram[offset] >> towns_vram_rplane) << 7) & 0x80) |
| 188 | | | (((towns_gfxvram[offset] >> towns_vram_rplane) << 2) & 0x40) |
| 189 | | | (((towns_gfxvram[offset+1] >> towns_vram_rplane) << 5) & 0x20) |
| 190 | | | (((towns_gfxvram[offset+1] >> towns_vram_rplane)) & 0x10) |
| 191 | | | (((towns_gfxvram[offset+2] >> towns_vram_rplane) << 3) & 0x08) |
| 192 | | | (((towns_gfxvram[offset+2] >> towns_vram_rplane) >> 2) & 0x04) |
| 193 | | | (((towns_gfxvram[offset+3] >> towns_vram_rplane) << 1) & 0x02) |
| 194 | | | (((towns_gfxvram[offset+3] >> towns_vram_rplane) >> 4) & 0x01); |
| 165 | ret = (((state->towns_gfxvram[offset] >> state->video.towns_vram_rplane) << 7) & 0x80) |
| 166 | | (((state->towns_gfxvram[offset] >> state->video.towns_vram_rplane) << 2) & 0x40) |
| 167 | | (((state->towns_gfxvram[offset+1] >> state->video.towns_vram_rplane) << 5) & 0x20) |
| 168 | | (((state->towns_gfxvram[offset+1] >> state->video.towns_vram_rplane)) & 0x10) |
| 169 | | (((state->towns_gfxvram[offset+2] >> state->video.towns_vram_rplane) << 3) & 0x08) |
| 170 | | (((state->towns_gfxvram[offset+2] >> state->video.towns_vram_rplane) >> 2) & 0x04) |
| 171 | | (((state->towns_gfxvram[offset+3] >> state->video.towns_vram_rplane) << 1) & 0x02) |
| 172 | | (((state->towns_gfxvram[offset+3] >> state->video.towns_vram_rplane) >> 4) & 0x01); |
| 195 | 173 | |
| 196 | 174 | return ret; |
| 197 | 175 | } |
| 198 | 176 | |
| 199 | 177 | WRITE8_HANDLER( towns_gfx_w ) |
| 200 | 178 | { |
| 201 | | if(towns_mainmem_enable != 0) |
| 179 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 180 | |
| 181 | if(state->towns_mainmem_enable != 0) |
| 202 | 182 | { |
| 203 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xc0000] = data; |
| 183 | messram_get_ptr(state->messram)[offset+0xc0000] = data; |
| 204 | 184 | return; |
| 205 | 185 | } |
| 206 | 186 | offset = offset << 2; |
| 207 | | if(towns_vram_page_sel != 0) |
| 187 | if(state->video.towns_vram_page_sel != 0) |
| 208 | 188 | offset += 0x20000; |
| 209 | | if(towns_vram_wplane & 0x08) |
| 189 | if(state->video.towns_vram_wplane & 0x08) |
| 210 | 190 | { |
| 211 | | towns_gfxvram[offset] &= ~0x88; |
| 212 | | towns_gfxvram[offset] |= ((data & 0x80) >> 4) | ((data & 0x40) << 1); |
| 213 | | towns_gfxvram[offset + 1] &= ~0x88; |
| 214 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 2) | ((data & 0x10) << 3); |
| 215 | | towns_gfxvram[offset + 2] &= ~0x88; |
| 216 | | towns_gfxvram[offset + 2] |= ((data & 0x08)) | ((data & 0x04) << 5); |
| 217 | | towns_gfxvram[offset + 3] &= ~0x88; |
| 218 | | towns_gfxvram[offset + 3] |= ((data & 0x02) << 2) | ((data & 0x01) << 7); |
| 191 | state->towns_gfxvram[offset] &= ~0x88; |
| 192 | state->towns_gfxvram[offset] |= ((data & 0x80) >> 4) | ((data & 0x40) << 1); |
| 193 | state->towns_gfxvram[offset + 1] &= ~0x88; |
| 194 | state->towns_gfxvram[offset + 1] |= ((data & 0x20) >> 2) | ((data & 0x10) << 3); |
| 195 | state->towns_gfxvram[offset + 2] &= ~0x88; |
| 196 | state->towns_gfxvram[offset + 2] |= ((data & 0x08)) | ((data & 0x04) << 5); |
| 197 | state->towns_gfxvram[offset + 3] &= ~0x88; |
| 198 | state->towns_gfxvram[offset + 3] |= ((data & 0x02) << 2) | ((data & 0x01) << 7); |
| 219 | 199 | } |
| 220 | | if(towns_vram_wplane & 0x04) |
| 200 | if(state->video.towns_vram_wplane & 0x04) |
| 221 | 201 | { |
| 222 | | towns_gfxvram[offset] &= ~0x44; |
| 223 | | towns_gfxvram[offset] |= ((data & 0x80) >> 5) | ((data & 0x40)); |
| 224 | | towns_gfxvram[offset + 1] &= ~0x44; |
| 225 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 3) | ((data & 0x10) << 2); |
| 226 | | towns_gfxvram[offset + 2] &= ~0x44; |
| 227 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 1) | ((data & 0x04) << 4); |
| 228 | | towns_gfxvram[offset + 3] &= ~0x44; |
| 229 | | towns_gfxvram[offset + 3] |= ((data & 0x02) << 1) | ((data & 0x01) << 6); |
| 202 | state->towns_gfxvram[offset] &= ~0x44; |
| 203 | state->towns_gfxvram[offset] |= ((data & 0x80) >> 5) | ((data & 0x40)); |
| 204 | state->towns_gfxvram[offset + 1] &= ~0x44; |
| 205 | state->towns_gfxvram[offset + 1] |= ((data & 0x20) >> 3) | ((data & 0x10) << 2); |
| 206 | state->towns_gfxvram[offset + 2] &= ~0x44; |
| 207 | state->towns_gfxvram[offset + 2] |= ((data & 0x08) >> 1) | ((data & 0x04) << 4); |
| 208 | state->towns_gfxvram[offset + 3] &= ~0x44; |
| 209 | state->towns_gfxvram[offset + 3] |= ((data & 0x02) << 1) | ((data & 0x01) << 6); |
| 230 | 210 | } |
| 231 | | if(towns_vram_wplane & 0x02) |
| 211 | if(state->video.towns_vram_wplane & 0x02) |
| 232 | 212 | { |
| 233 | | towns_gfxvram[offset] &= ~0x22; |
| 234 | | towns_gfxvram[offset] |= ((data & 0x80) >> 6) | ((data & 0x40) >> 1); |
| 235 | | towns_gfxvram[offset + 1] &= ~0x22; |
| 236 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 4) | ((data & 0x10) << 1); |
| 237 | | towns_gfxvram[offset + 2] &= ~0x22; |
| 238 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 2) | ((data & 0x04) << 3); |
| 239 | | towns_gfxvram[offset + 3] &= ~0x22; |
| 240 | | towns_gfxvram[offset + 3] |= ((data & 0x02)) | ((data & 0x01) << 5); |
| 213 | state->towns_gfxvram[offset] &= ~0x22; |
| 214 | state->towns_gfxvram[offset] |= ((data & 0x80) >> 6) | ((data & 0x40) >> 1); |
| 215 | state->towns_gfxvram[offset + 1] &= ~0x22; |
| 216 | state->towns_gfxvram[offset + 1] |= ((data & 0x20) >> 4) | ((data & 0x10) << 1); |
| 217 | state->towns_gfxvram[offset + 2] &= ~0x22; |
| 218 | state->towns_gfxvram[offset + 2] |= ((data & 0x08) >> 2) | ((data & 0x04) << 3); |
| 219 | state->towns_gfxvram[offset + 3] &= ~0x22; |
| 220 | state->towns_gfxvram[offset + 3] |= ((data & 0x02)) | ((data & 0x01) << 5); |
| 241 | 221 | } |
| 242 | | if(towns_vram_wplane & 0x01) |
| 222 | if(state->video.towns_vram_wplane & 0x01) |
| 243 | 223 | { |
| 244 | | towns_gfxvram[offset] &= ~0x11; |
| 245 | | towns_gfxvram[offset] |= ((data & 0x80) >> 7) | ((data & 0x40) >> 2); |
| 246 | | towns_gfxvram[offset + 1] &= ~0x11; |
| 247 | | towns_gfxvram[offset + 1] |= ((data & 0x20) >> 5) | ((data & 0x10)); |
| 248 | | towns_gfxvram[offset + 2] &= ~0x11; |
| 249 | | towns_gfxvram[offset + 2] |= ((data & 0x08) >> 3) | ((data & 0x04) << 2); |
| 250 | | towns_gfxvram[offset + 3] &= ~0x11; |
| 251 | | towns_gfxvram[offset + 3] |= ((data & 0x02) >> 1) | ((data & 0x01) << 4); |
| 224 | state->towns_gfxvram[offset] &= ~0x11; |
| 225 | state->towns_gfxvram[offset] |= ((data & 0x80) >> 7) | ((data & 0x40) >> 2); |
| 226 | state->towns_gfxvram[offset + 1] &= ~0x11; |
| 227 | state->towns_gfxvram[offset + 1] |= ((data & 0x20) >> 5) | ((data & 0x10)); |
| 228 | state->towns_gfxvram[offset + 2] &= ~0x11; |
| 229 | state->towns_gfxvram[offset + 2] |= ((data & 0x08) >> 3) | ((data & 0x04) << 2); |
| 230 | state->towns_gfxvram[offset + 3] &= ~0x11; |
| 231 | state->towns_gfxvram[offset + 3] |= ((data & 0x02) >> 1) | ((data & 0x01) << 4); |
| 252 | 232 | } |
| 253 | 233 | } |
| 254 | 234 | |
| 255 | | static void towns_update_kanji_offset(void) |
| 235 | static void towns_update_kanji_offset(running_machine* machine) |
| 256 | 236 | { |
| 237 | towns_state* state = (towns_state*)machine->driver_data; |
| 257 | 238 | // this is a little over the top... |
| 258 | | if(towns_kanji_code_h < 0x30) |
| 239 | if(state->video.towns_kanji_code_h < 0x30) |
| 259 | 240 | { |
| 260 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 261 | | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 262 | | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 263 | | | ((towns_kanji_code_h & 0x07) << 9); |
| 241 | state->video.towns_kanji_offset = ((state->video.towns_kanji_code_l & 0x1f) << 4) |
| 242 | | (((state->video.towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 243 | | (((state->video.towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 244 | | ((state->video.towns_kanji_code_h & 0x07) << 9); |
| 264 | 245 | } |
| 265 | | else if(towns_kanji_code_h < 0x70) |
| 246 | else if(state->video.towns_kanji_code_h < 0x70) |
| 266 | 247 | { |
| 267 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 268 | | + (((towns_kanji_code_l - 0x20) & 0x60) << 8) |
| 269 | | + ((towns_kanji_code_h & 0x0f) << 9) |
| 270 | | + (((towns_kanji_code_h - 0x30) & 0x70) * 0xc00) |
| 248 | state->video.towns_kanji_offset = ((state->video.towns_kanji_code_l & 0x1f) << 4) |
| 249 | + (((state->video.towns_kanji_code_l - 0x20) & 0x60) << 8) |
| 250 | + ((state->video.towns_kanji_code_h & 0x0f) << 9) |
| 251 | + (((state->video.towns_kanji_code_h - 0x30) & 0x70) * 0xc00) |
| 271 | 252 | + 0x8000; |
| 272 | 253 | } |
| 273 | 254 | else |
| 274 | 255 | { |
| 275 | | towns_kanji_offset = ((towns_kanji_code_l & 0x1f) << 4) |
| 276 | | | (((towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 277 | | | (((towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 278 | | | ((towns_kanji_code_h & 0x07) << 9) |
| 256 | state->video.towns_kanji_offset = ((state->video.towns_kanji_code_l & 0x1f) << 4) |
| 257 | | (((state->video.towns_kanji_code_l - 0x20) & 0x20) << 8) |
| 258 | | (((state->video.towns_kanji_code_l - 0x20) & 0x40) << 6) |
| 259 | | ((state->video.towns_kanji_code_h & 0x07) << 9) |
| 279 | 260 | | 0x38000; |
| 280 | 261 | } |
| 281 | 262 | } |
| 282 | 263 | |
| 283 | 264 | READ8_HANDLER( towns_video_cff80_r ) |
| 284 | 265 | { |
| 266 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 285 | 267 | UINT8* ROM = memory_region(space->machine,"user"); |
| 286 | 268 | |
| 287 | 269 | switch(offset) |
| 288 | 270 | { |
| 289 | 271 | case 0x00: // mix register |
| 290 | | return towns_crtc_mix; |
| 272 | return state->video.towns_crtc_mix; |
| 291 | 273 | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 292 | | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 274 | return ((state->video.towns_vram_rplane << 6) & 0xc0) | state->video.towns_vram_wplane; |
| 293 | 275 | case 0x02: // display planes (bits 0-2,5), display page select (bit 4) |
| 294 | | return towns_display_plane | towns_display_page_sel; |
| 276 | return state->video.towns_display_plane | state->video.towns_display_page_sel; |
| 295 | 277 | case 0x03: // VRAM page select (bit 5) |
| 296 | | if(towns_vram_page_sel != 0) |
| 278 | if(state->video.towns_vram_page_sel != 0) |
| 297 | 279 | return 0x10; |
| 298 | 280 | else |
| 299 | 281 | return 0x00; |
| 300 | 282 | case 0x16: // Kanji character data |
| 301 | | return ROM[(towns_kanji_offset << 1) + 0x180000]; |
| 283 | return ROM[(state->video.towns_kanji_offset << 1) + 0x180000]; |
| 302 | 284 | case 0x17: // Kanji character data |
| 303 | | return ROM[(towns_kanji_offset++ << 1) + 0x180001]; |
| 285 | return ROM[(state->video.towns_kanji_offset++ << 1) + 0x180001]; |
| 304 | 286 | case 0x19: // ANK CG ROM |
| 305 | | if(towns_ankcg_enable != 0) |
| 287 | if(state->towns_ankcg_enable != 0) |
| 306 | 288 | return 0x01; |
| 307 | 289 | else |
| 308 | 290 | return 0x00; |
| r8380 | r8381 | |
| 315 | 297 | |
| 316 | 298 | WRITE8_HANDLER( towns_video_cff80_w ) |
| 317 | 299 | { |
| 300 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 301 | |
| 318 | 302 | switch(offset) |
| 319 | 303 | { |
| 320 | 304 | case 0x00: // mix register |
| 321 | | towns_crtc_mix = data; |
| 305 | state->video.towns_crtc_mix = data; |
| 322 | 306 | break; |
| 323 | 307 | case 0x01: // read/write plane select (bit 0-3 write, bit 6-7 read) |
| 324 | | towns_vram_wplane = data & 0x0f; |
| 325 | | towns_vram_rplane = (data & 0xc0) >> 6; |
| 308 | state->video.towns_vram_wplane = data & 0x0f; |
| 309 | state->video.towns_vram_rplane = (data & 0xc0) >> 6; |
| 326 | 310 | towns_update_video_banks(space); |
| 327 | 311 | //logerror("VGA: VRAM wplane select = 0x%02x\n",towns_vram_wplane); |
| 328 | 312 | break; |
| 329 | 313 | case 0x02: // display plane (bits 0-2), display page select (bit 4) |
| 330 | | towns_display_plane = data & 0x27; |
| 331 | | towns_display_page_sel = data & 0x10; |
| 314 | state->video.towns_display_plane = data & 0x27; |
| 315 | state->video.towns_display_page_sel = data & 0x10; |
| 332 | 316 | break; |
| 333 | 317 | case 0x03: // VRAM page select (bit 4) |
| 334 | | towns_vram_page_sel = data & 0x10; |
| 318 | state->video.towns_vram_page_sel = data & 0x10; |
| 335 | 319 | break; |
| 336 | 320 | case 0x14: // Kanji offset (high) |
| 337 | | towns_kanji_code_h = data & 0x7f; |
| 338 | | towns_update_kanji_offset(); |
| 321 | state->video.towns_kanji_code_h = data & 0x7f; |
| 322 | towns_update_kanji_offset(space->machine); |
| 339 | 323 | //logerror("VID: Kanji code set (high) = %02x %02x\n",towns_kanji_code_h,towns_kanji_code_l); |
| 340 | 324 | break; |
| 341 | 325 | case 0x15: // Kanji offset (low) |
| 342 | | towns_kanji_code_l = data & 0x7f; |
| 343 | | towns_update_kanji_offset(); |
| 326 | state->video.towns_kanji_code_l = data & 0x7f; |
| 327 | towns_update_kanji_offset(space->machine); |
| 344 | 328 | //logerror("VID: Kanji code set (low) = %02x %02x\n",towns_kanji_code_h,towns_kanji_code_l); |
| 345 | 329 | break; |
| 346 | 330 | case 0x19: // ANK CG ROM |
| 347 | | towns_ankcg_enable = data & 0x01; |
| 331 | state->towns_ankcg_enable = data & 0x01; |
| 348 | 332 | towns_update_video_banks(space); |
| 349 | 333 | break; |
| 350 | 334 | default: |
| r8380 | r8381 | |
| 354 | 338 | |
| 355 | 339 | READ8_HANDLER( towns_video_cff80_mem_r ) |
| 356 | 340 | { |
| 357 | | if(towns_mainmem_enable != 0) |
| 358 | | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80]; |
| 341 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 359 | 342 | |
| 343 | if(state->towns_mainmem_enable != 0) |
| 344 | return messram_get_ptr(state->messram)[offset+0xcff80]; |
| 345 | |
| 360 | 346 | return towns_video_cff80_r(space,offset); |
| 361 | 347 | } |
| 362 | 348 | |
| 363 | 349 | WRITE8_HANDLER( towns_video_cff80_mem_w ) |
| 364 | 350 | { |
| 365 | | if(towns_mainmem_enable != 0) |
| 351 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 352 | |
| 353 | if(state->towns_mainmem_enable != 0) |
| 366 | 354 | { |
| 367 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xcff80] = data; |
| 355 | messram_get_ptr(state->messram)[offset+0xcff80] = data; |
| 368 | 356 | return; |
| 369 | 357 | } |
| 370 | 358 | towns_video_cff80_w(space,offset,data); |
| r8380 | r8381 | |
| 379 | 367 | */ |
| 380 | 368 | READ8_HANDLER(towns_video_440_r) |
| 381 | 369 | { |
| 370 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 382 | 371 | UINT8 ret = 0; |
| 383 | 372 | UINT16 xpos,ypos; |
| 384 | 373 | |
| 385 | 374 | switch(offset) |
| 386 | 375 | { |
| 387 | 376 | case 0x00: |
| 388 | | return towns_crtc_sel; |
| 377 | return state->video.towns_crtc_sel; |
| 389 | 378 | case 0x02: |
| 390 | 379 | // logerror("CRTC: reading register %i (0x442) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 391 | | if(towns_crtc_sel == 30) |
| 380 | if(state->video.towns_crtc_sel == 30) |
| 392 | 381 | return 0x00; |
| 393 | | return towns_crtc_reg[towns_crtc_sel] & 0x00ff; |
| 382 | return state->video.towns_crtc_reg[state->video.towns_crtc_sel] & 0x00ff; |
| 394 | 383 | case 0x03: |
| 395 | 384 | // logerror("CRTC: reading register %i (0x443) [%04x]\n",towns_crtc_sel,towns_crtc_reg[towns_crtc_sel]); |
| 396 | | if(towns_crtc_sel == 30) |
| 385 | if(state->video.towns_crtc_sel == 30) |
| 397 | 386 | { |
| 398 | 387 | // check video position |
| 399 | 388 | xpos = space->machine->primary_screen->hpos(); |
| 400 | 389 | ypos = space->machine->primary_screen->vpos(); |
| 401 | 390 | |
| 402 | | if(xpos < (towns_crtc_reg[0] & 0xfe)) |
| 391 | if(xpos < (state->video.towns_crtc_reg[0] & 0xfe)) |
| 403 | 392 | ret |= 0x02; |
| 404 | | if(ypos < (towns_crtc_reg[6] & 0x1f)) |
| 393 | if(ypos < (state->video.towns_crtc_reg[6] & 0x1f)) |
| 405 | 394 | ret |= 0x04; |
| 406 | | if(xpos < towns_crtc_layerscr[0].max_x && xpos > towns_crtc_layerscr[0].min_x) |
| 395 | if(xpos < state->video.towns_crtc_layerscr[0].max_x && xpos > state->video.towns_crtc_layerscr[0].min_x) |
| 407 | 396 | ret |= 0x10; |
| 408 | | if(xpos < towns_crtc_layerscr[1].max_x && xpos > towns_crtc_layerscr[1].min_x) |
| 397 | if(xpos < state->video.towns_crtc_layerscr[1].max_x && xpos > state->video.towns_crtc_layerscr[1].min_x) |
| 409 | 398 | ret |= 0x20; |
| 410 | | if(ypos < towns_crtc_layerscr[0].max_y && ypos > towns_crtc_layerscr[0].min_y) |
| 399 | if(ypos < state->video.towns_crtc_layerscr[0].max_y && ypos > state->video.towns_crtc_layerscr[0].min_y) |
| 411 | 400 | ret |= 0x40; |
| 412 | | if(ypos < towns_crtc_layerscr[1].max_y && ypos > towns_crtc_layerscr[1].min_y) |
| 401 | if(ypos < state->video.towns_crtc_layerscr[1].max_y && ypos > state->video.towns_crtc_layerscr[1].min_y) |
| 413 | 402 | ret |= 0x80; |
| 414 | 403 | |
| 415 | 404 | return ret; |
| 416 | 405 | } |
| 417 | | return (towns_crtc_reg[towns_crtc_sel] & 0xff00) >> 8; |
| 406 | return (state->video.towns_crtc_reg[state->video.towns_crtc_sel] & 0xff00) >> 8; |
| 418 | 407 | case 0x08: |
| 419 | | return towns_video_sel; |
| 408 | return state->video.towns_video_sel; |
| 420 | 409 | case 0x0a: |
| 421 | | logerror("Video: reading register %i (0x44a) [%02x]\n",towns_video_sel,towns_video_reg[towns_video_sel]); |
| 422 | | return towns_video_reg[towns_video_sel]; |
| 410 | logerror("Video: reading register %i (0x44a) [%02x]\n",state->video.towns_video_sel,state->video.towns_video_reg[state->video.towns_video_sel]); |
| 411 | return state->video.towns_video_reg[state->video.towns_video_sel]; |
| 423 | 412 | case 0x0c: |
| 424 | | if(towns_dpmd_flag != 0) |
| 413 | if(state->video.towns_dpmd_flag != 0) |
| 425 | 414 | { |
| 426 | | towns_dpmd_flag = 0; |
| 415 | state->video.towns_dpmd_flag = 0; |
| 427 | 416 | ret |= 0x80; |
| 428 | 417 | } |
| 429 | | ret |= (towns_vblank_flag ? 0x02 : 0x00); // TODO: figure out just what this bit is... |
| 418 | ret |= (state->video.towns_vblank_flag ? 0x02 : 0x00); // TODO: figure out just what this bit is... |
| 430 | 419 | return ret; |
| 431 | 420 | case 0x10: |
| 432 | | return towns_sprite_sel; |
| 421 | return state->video.towns_sprite_sel; |
| 433 | 422 | case 0x12: |
| 434 | | logerror("SPR: reading register %i (0x452) [%02x]\n",towns_sprite_sel,towns_sprite_reg[towns_sprite_sel]); |
| 435 | | return towns_sprite_reg[towns_sprite_sel]; |
| 423 | logerror("SPR: reading register %i (0x452) [%02x]\n",state->video.towns_sprite_sel,state->video.towns_sprite_reg[state->video.towns_sprite_sel]); |
| 424 | return state->video.towns_sprite_reg[state->video.towns_sprite_sel]; |
| 436 | 425 | default: |
| 437 | 426 | logerror("VID: read port %04x\n",offset+0x440); |
| 438 | 427 | } |
| r8380 | r8381 | |
| 441 | 430 | |
| 442 | 431 | WRITE8_HANDLER(towns_video_440_w) |
| 443 | 432 | { |
| 433 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 434 | |
| 444 | 435 | switch(offset) |
| 445 | 436 | { |
| 446 | 437 | case 0x00: |
| 447 | | towns_crtc_sel = data; |
| 438 | state->video.towns_crtc_sel = data; |
| 448 | 439 | break; |
| 449 | 440 | case 0x02: |
| 450 | 441 | // logerror("CRTC: writing register %i (0x442) [%02x]\n",towns_crtc_sel,data); |
| 451 | | towns_crtc_reg[towns_crtc_sel] = |
| 452 | | (towns_crtc_reg[towns_crtc_sel] & 0xff00) | data; |
| 442 | state->video.towns_crtc_reg[state->video.towns_crtc_sel] = |
| 443 | (state->video.towns_crtc_reg[state->video.towns_crtc_sel] & 0xff00) | data; |
| 453 | 444 | towns_crtc_refresh_mode(space->machine); |
| 454 | 445 | break; |
| 455 | 446 | case 0x03: |
| 456 | 447 | // logerror("CRTC: writing register %i (0x443) [%02x]\n",towns_crtc_sel,data); |
| 457 | | towns_crtc_reg[towns_crtc_sel] = |
| 458 | | (towns_crtc_reg[towns_crtc_sel] & 0x00ff) | (data << 8); |
| 448 | state->video.towns_crtc_reg[state->video.towns_crtc_sel] = |
| 449 | (state->video.towns_crtc_reg[state->video.towns_crtc_sel] & 0x00ff) | (data << 8); |
| 459 | 450 | towns_crtc_refresh_mode(space->machine); |
| 460 | 451 | break; |
| 461 | 452 | case 0x08: |
| 462 | | towns_video_sel = data & 0x01; |
| 453 | state->video.towns_video_sel = data & 0x01; |
| 463 | 454 | break; |
| 464 | 455 | case 0x0a: |
| 465 | | logerror("Video: writing register %i (0x44a) [%02x]\n",towns_video_sel,data); |
| 466 | | towns_video_reg[towns_video_sel] = data; |
| 456 | logerror("Video: writing register %i (0x44a) [%02x]\n",state->video.towns_video_sel,data); |
| 457 | state->video.towns_video_reg[state->video.towns_video_sel] = data; |
| 467 | 458 | break; |
| 468 | 459 | case 0x10: |
| 469 | | towns_sprite_sel = data & 0x07; |
| 460 | state->video.towns_sprite_sel = data & 0x07; |
| 470 | 461 | break; |
| 471 | 462 | case 0x12: |
| 472 | | logerror("SPR: writing register %i (0x452) [%02x]\n",towns_sprite_sel,data); |
| 473 | | towns_sprite_reg[towns_sprite_sel] = data; |
| 463 | logerror("SPR: writing register %i (0x452) [%02x]\n",state->video.towns_sprite_sel,data); |
| 464 | state->video.towns_sprite_reg[state->video.towns_sprite_sel] = data; |
| 474 | 465 | break; |
| 475 | 466 | default: |
| 476 | 467 | logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0x440); |
| r8380 | r8381 | |
| 479 | 470 | |
| 480 | 471 | READ8_HANDLER(towns_video_5c8_r) |
| 481 | 472 | { |
| 473 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 474 | |
| 482 | 475 | logerror("VID: read port %04x\n",offset+0x5c8); |
| 483 | 476 | switch(offset) |
| 484 | 477 | { |
| 485 | 478 | case 0x00: // 0x5c8 - disable TVRAM? |
| 486 | | if(towns_tvram_enable != 0) |
| 479 | if(state->video.towns_tvram_enable != 0) |
| 487 | 480 | { |
| 488 | | towns_tvram_enable = 0; |
| 481 | state->video.towns_tvram_enable = 0; |
| 489 | 482 | return 0x80; |
| 490 | 483 | } |
| 491 | 484 | else |
| r8380 | r8381 | |
| 496 | 489 | |
| 497 | 490 | WRITE8_HANDLER(towns_video_5c8_w) |
| 498 | 491 | { |
| 499 | | running_device* dev = devtag_get_device(space->machine,"pic8259_slave"); |
| 492 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 493 | running_device* dev = state->pic_slave; |
| 494 | |
| 500 | 495 | switch(offset) |
| 501 | 496 | { |
| 502 | 497 | case 0x02: // 0x5ca - VSync clear? |
| 503 | 498 | pic8259_ir3_w(dev, 0); |
| 499 | logerror("PIC: IRQ11 (VSync) set low\n"); |
| 504 | 500 | //towns_vblank_flag = 0; |
| 505 | 501 | break; |
| 506 | 502 | } |
| r8380 | r8381 | |
| 515 | 511 | */ |
| 516 | 512 | READ8_HANDLER(towns_video_fd90_r) |
| 517 | 513 | { |
| 514 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 518 | 515 | UINT8 ret = 0; |
| 519 | 516 | UINT16 xpos; |
| 520 | 517 | switch(offset) |
| 521 | 518 | { |
| 522 | 519 | case 0x00: |
| 523 | | return towns_palette_select; |
| 520 | return state->video.towns_palette_select; |
| 524 | 521 | case 0x02: |
| 525 | | return towns_palette_b[towns_palette_select]; |
| 522 | return state->video.towns_palette_b[state->video.towns_palette_select]; |
| 526 | 523 | case 0x04: |
| 527 | | return towns_palette_r[towns_palette_select]; |
| 524 | return state->video.towns_palette_r[state->video.towns_palette_select]; |
| 528 | 525 | case 0x06: |
| 529 | | return towns_palette_g[towns_palette_select]; |
| 526 | return state->video.towns_palette_g[state->video.towns_palette_select]; |
| 530 | 527 | case 0x08: |
| 531 | 528 | case 0x09: |
| 532 | 529 | case 0x0a: |
| r8380 | r8381 | |
| 535 | 532 | case 0x0d: |
| 536 | 533 | case 0x0e: |
| 537 | 534 | case 0x0f: |
| 538 | | return towns_degipal[offset-0x08]; |
| 535 | return state->video.towns_degipal[offset-0x08]; |
| 539 | 536 | case 0x10: // "sub status register" |
| 540 | 537 | // check video position |
| 541 | 538 | xpos = space->machine->primary_screen->hpos(); |
| 542 | 539 | |
| 543 | | if(xpos < towns_crtc_layerscr[0].max_x && xpos > towns_crtc_layerscr[0].min_x) |
| 540 | if(xpos < state->video.towns_crtc_layerscr[0].max_x && xpos > state->video.towns_crtc_layerscr[0].min_x) |
| 544 | 541 | ret |= 0x02; |
| 545 | | if(towns_vblank_flag) |
| 542 | if(state->video.towns_vblank_flag) |
| 546 | 543 | ret |= 0x01; |
| 547 | 544 | return ret; |
| 548 | 545 | } |
| r8380 | r8381 | |
| 552 | 549 | |
| 553 | 550 | WRITE8_HANDLER(towns_video_fd90_w) |
| 554 | 551 | { |
| 552 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 553 | |
| 555 | 554 | switch(offset) |
| 556 | 555 | { |
| 557 | 556 | case 0x00: |
| 558 | | towns_palette_select = data; |
| 557 | state->video.towns_palette_select = data; |
| 559 | 558 | break; |
| 560 | 559 | case 0x02: |
| 561 | | towns_palette_b[towns_palette_select] = data; |
| 560 | state->video.towns_palette_b[state->video.towns_palette_select] = data; |
| 562 | 561 | break; |
| 563 | 562 | case 0x04: |
| 564 | | towns_palette_r[towns_palette_select] = data; |
| 563 | state->video.towns_palette_r[state->video.towns_palette_select] = data; |
| 565 | 564 | break; |
| 566 | 565 | case 0x06: |
| 567 | | towns_palette_g[towns_palette_select] = data; |
| 566 | state->video.towns_palette_g[state->video.towns_palette_select] = data; |
| 568 | 567 | break; |
| 569 | 568 | case 0x08: |
| 570 | 569 | case 0x09: |
| r8380 | r8381 | |
| 574 | 573 | case 0x0d: |
| 575 | 574 | case 0x0e: |
| 576 | 575 | case 0x0f: |
| 577 | | towns_degipal[offset-0x08] = data; |
| 578 | | towns_dpmd_flag = 1; |
| 576 | state->video.towns_degipal[offset-0x08] = data; |
| 577 | state->video.towns_dpmd_flag = 1; |
| 579 | 578 | break; |
| 580 | 579 | case 0x10: |
| 581 | | towns_layer_ctrl = data; |
| 580 | state->video.towns_layer_ctrl = data; |
| 582 | 581 | break; |
| 583 | 582 | } |
| 584 | 583 | //logerror("VID: wrote 0x%02x to port %04x\n",data,offset+0xfd90); |
| r8380 | r8381 | |
| 586 | 585 | |
| 587 | 586 | READ8_HANDLER(towns_video_ff81_r) |
| 588 | 587 | { |
| 589 | | return ((towns_vram_rplane << 6) & 0xc0) | towns_vram_wplane; |
| 588 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 589 | |
| 590 | return ((state->video.towns_vram_rplane << 6) & 0xc0) | state->video.towns_vram_wplane; |
| 590 | 591 | } |
| 591 | 592 | |
| 592 | 593 | WRITE8_HANDLER(towns_video_ff81_w) |
| 593 | 594 | { |
| 594 | | towns_vram_wplane = data & 0x0f; |
| 595 | | towns_vram_rplane = (data & 0xc0) >> 6; |
| 595 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 596 | |
| 597 | state->video.towns_vram_wplane = data & 0x0f; |
| 598 | state->video.towns_vram_rplane = (data & 0xc0) >> 6; |
| 596 | 599 | towns_update_video_banks(space); |
| 597 | | logerror("VGA: VRAM wplane select (I/O) = 0x%02x\n",towns_vram_wplane); |
| 600 | logerror("VGA: VRAM wplane select (I/O) = 0x%02x\n",state->video.towns_vram_wplane); |
| 598 | 601 | } |
| 599 | 602 | |
| 600 | 603 | /* |
| r8380 | r8381 | |
| 609 | 612 | */ |
| 610 | 613 | READ8_HANDLER(towns_spriteram_low_r) |
| 611 | 614 | { |
| 612 | | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 615 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 616 | UINT8* RAM = messram_get_ptr(state->messram); |
| 613 | 617 | UINT8* ROM = memory_region(space->machine,"user"); |
| 614 | 618 | |
| 615 | 619 | if(offset < 0x1000) |
| 616 | 620 | { // 0xc8000-0xc8fff |
| 617 | | if(towns_mainmem_enable == 0) |
| 621 | if(state->towns_mainmem_enable == 0) |
| 618 | 622 | { |
| 619 | 623 | // if(towns_tvram_enable == 0) |
| 620 | 624 | // return towns_sprram[offset]; |
| 621 | 625 | // else |
| 622 | | return towns_txtvram[offset]; |
| 626 | return state->towns_txtvram[offset]; |
| 623 | 627 | } |
| 624 | 628 | else |
| 625 | 629 | return RAM[offset + 0xc8000]; |
| r8380 | r8381 | |
| 630 | 634 | } |
| 631 | 635 | if(offset >= 0x2000 && offset < 0x3000) |
| 632 | 636 | { // 0xca000-0xcafff |
| 633 | | if(towns_mainmem_enable == 0) |
| 637 | if(state->towns_mainmem_enable == 0) |
| 634 | 638 | { |
| 635 | | if(towns_ankcg_enable != 0 && offset < 0x2800) |
| 639 | if(state->towns_ankcg_enable != 0 && offset < 0x2800) |
| 636 | 640 | return ROM[0x180000 + 0x3d000 + (offset-0x2000)]; |
| 637 | 641 | // if(towns_tvram_enable == 0) |
| 638 | | // return towns_sprram[offset]; |
| 642 | // return state->towns_sprram[offset]; |
| 639 | 643 | // else |
| 640 | | return towns_txtvram[offset]; |
| 644 | return state->towns_txtvram[offset]; |
| 641 | 645 | } |
| 642 | 646 | else |
| 643 | 647 | return RAM[offset + 0xca000]; |
| r8380 | r8381 | |
| 647 | 651 | |
| 648 | 652 | WRITE8_HANDLER(towns_spriteram_low_w) |
| 649 | 653 | { |
| 650 | | UINT8* RAM = messram_get_ptr(devtag_get_device(space->machine, "messram")); |
| 654 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 655 | UINT8* RAM = messram_get_ptr(state->messram); |
| 656 | |
| 651 | 657 | if(offset < 0x1000) |
| 652 | 658 | { // 0xc8000-0xc8fff |
| 653 | | towns_tvram_enable = 1; |
| 654 | | if(towns_mainmem_enable == 0) |
| 655 | | towns_txtvram[offset] = data; |
| 659 | state->video.towns_tvram_enable = 1; |
| 660 | if(state->towns_mainmem_enable == 0) |
| 661 | state->towns_txtvram[offset] = data; |
| 656 | 662 | else |
| 657 | 663 | RAM[offset + 0xc8000] = data; |
| 658 | 664 | } |
| r8380 | r8381 | |
| 662 | 668 | } |
| 663 | 669 | if(offset >= 0x2000 && offset < 0x3000) |
| 664 | 670 | { // 0xca000-0xcafff |
| 665 | | towns_tvram_enable = 1; |
| 666 | | if(towns_mainmem_enable == 0) |
| 667 | | towns_txtvram[offset] = data; |
| 671 | state->video.towns_tvram_enable = 1; |
| 672 | if(state->towns_mainmem_enable == 0) |
| 673 | state->towns_txtvram[offset] = data; |
| 668 | 674 | else |
| 669 | 675 | RAM[offset + 0xca000] = data; |
| 670 | 676 | } |
| r8380 | r8381 | |
| 672 | 678 | |
| 673 | 679 | READ8_HANDLER( towns_spriteram_r) |
| 674 | 680 | { |
| 675 | | return towns_txtvram[offset]; |
| 681 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 682 | |
| 683 | return state->towns_txtvram[offset]; |
| 676 | 684 | } |
| 677 | 685 | |
| 678 | 686 | WRITE8_HANDLER( towns_spriteram_w) |
| 679 | 687 | { |
| 680 | | towns_txtvram[offset] = data; |
| 688 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 689 | |
| 690 | state->towns_txtvram[offset] = data; |
| 681 | 691 | } |
| 682 | 692 | |
| 683 | 693 | /* |
| r8380 | r8381 | |
| 699 | 709 | * +6: Sprite Colour |
| 700 | 710 | * bit 15: use colour data in located in sprite RAM offset in bits 11-0 (x32) |
| 701 | 711 | */ |
| 702 | | void render_sprite_4(UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect) |
| 712 | void render_sprite_4(running_machine* machine, UINT32 poffset, UINT32 coffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect) |
| 703 | 713 | { |
| 714 | towns_state* state = (towns_state*)machine->driver_data; |
| 704 | 715 | UINT16 xpos,ypos; |
| 705 | 716 | UINT16 col,pixel; |
| 706 | 717 | UINT32 voffset; |
| 707 | 718 | UINT16 xstart,xend,ystart,yend; |
| 708 | 719 | int xdir,ydir; |
| 709 | | int width = (towns_crtc_reg[12] - towns_crtc_reg[11]) / (((towns_crtc_reg[27] & 0x0f00) >> 8)+1); |
| 710 | | int height = (towns_crtc_reg[16] - towns_crtc_reg[15]) / (((towns_crtc_reg[27] & 0xf000) >> 12)+1); |
| 711 | | UINT32 vram_start = (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 720 | int width = (state->video.towns_crtc_reg[12] - state->video.towns_crtc_reg[11]) / (((state->video.towns_crtc_reg[27] & 0x0f00) >> 8)+1); |
| 721 | int height = (state->video.towns_crtc_reg[16] - state->video.towns_crtc_reg[15]) / (((state->video.towns_crtc_reg[27] & 0xf000) >> 12)+1); |
| 722 | UINT32 vram_start = (state->video.towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 712 | 723 | |
| 713 | 724 | if(xflip) |
| 714 | 725 | { |
| r8380 | r8381 | |
| 745 | 756 | for(xpos=xstart;xpos!=xend;xpos+=xdir,xpos&=0x1ff) |
| 746 | 757 | { |
| 747 | 758 | voffset = 0; |
| 748 | | pixel = (towns_txtvram[poffset] & 0xf0) >> 4; |
| 749 | | col = towns_txtvram[coffset+(pixel*2)] | (towns_txtvram[coffset+(pixel*2)+1] << 8); |
| 750 | | voffset += (towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 759 | pixel = (state->towns_txtvram[poffset] & 0xf0) >> 4; |
| 760 | col = state->towns_txtvram[coffset+(pixel*2)] | (state->towns_txtvram[coffset+(pixel*2)+1] << 8); |
| 761 | voffset += (state->video.towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 751 | 762 | voffset += (xpos & 0x1ff) * 2; |
| 752 | 763 | voffset &= 0x3ffff; |
| 753 | 764 | //voffset += (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 754 | 765 | if(xpos < width && ypos < height && pixel != 0) |
| 755 | 766 | { |
| 756 | | towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 757 | | towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 767 | state->towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 768 | state->towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 758 | 769 | } |
| 759 | 770 | if(xflip) |
| 760 | 771 | voffset+=2; |
| 761 | 772 | else |
| 762 | 773 | voffset-=2; |
| 763 | | pixel = towns_txtvram[poffset] & 0x0f; |
| 764 | | col = towns_txtvram[coffset+(pixel*2)] | (towns_txtvram[coffset+(pixel*2)+1] << 8); |
| 774 | pixel = state->towns_txtvram[poffset] & 0x0f; |
| 775 | col = state->towns_txtvram[coffset+(pixel*2)] | (state->towns_txtvram[coffset+(pixel*2)+1] << 8); |
| 765 | 776 | voffset &= 0x3ffff; |
| 766 | 777 | if(xpos < width && ypos < height && pixel != 0) |
| 767 | 778 | { |
| 768 | | towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 769 | | towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 779 | state->towns_gfxvram[voffset+vram_start+1] = (col & 0xff00) >> 8; |
| 780 | state->towns_gfxvram[voffset+vram_start] = col & 0x00ff; |
| 770 | 781 | } |
| 771 | 782 | poffset++; |
| 772 | 783 | poffset &= 0x1ffff; |
| r8380 | r8381 | |
| 774 | 785 | } |
| 775 | 786 | } |
| 776 | 787 | |
| 777 | | void render_sprite_16(UINT32 poffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect) |
| 788 | void render_sprite_16(running_machine* machine, UINT32 poffset, UINT16 x, UINT16 y, UINT16 xflip, UINT16 yflip, const rectangle* rect) |
| 778 | 789 | { |
| 790 | towns_state* state = (towns_state*)machine->driver_data; |
| 779 | 791 | UINT16 xpos,ypos; |
| 780 | 792 | UINT16 col; |
| 781 | 793 | UINT32 voffset; |
| 782 | 794 | UINT16 xstart,ystart,xend,yend; |
| 783 | 795 | int xdir,ydir; |
| 784 | | int width = (towns_crtc_reg[12] - towns_crtc_reg[11]) / (((towns_crtc_reg[27] & 0x0f00) >> 8)+1); |
| 785 | | int height = (towns_crtc_reg[16] - towns_crtc_reg[15]) / (((towns_crtc_reg[27] & 0xf000) >> 12)+1); |
| 796 | int width = (state->video.towns_crtc_reg[12] - state->video.towns_crtc_reg[11]) / (((state->video.towns_crtc_reg[27] & 0x0f00) >> 8)+1); |
| 797 | int height = (state->video.towns_crtc_reg[16] - state->video.towns_crtc_reg[15]) / (((state->video.towns_crtc_reg[27] & 0xf000) >> 12)+1); |
| 786 | 798 | |
| 787 | 799 | if(xflip) |
| 788 | 800 | { |
| r8380 | r8381 | |
| 818 | 830 | { |
| 819 | 831 | for(xpos=xstart;xpos!=xend;xpos+=xdir,xpos&=0x1ff) |
| 820 | 832 | { |
| 821 | | voffset = (towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 822 | | col = towns_txtvram[poffset] | (towns_txtvram[poffset+1] << 8); |
| 823 | | voffset += (towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 833 | voffset = (state->video.towns_sprite_reg[6] & 0x10) ? 0x60000 : 0x40000; |
| 834 | col = state->towns_txtvram[poffset] | (state->towns_txtvram[poffset+1] << 8); |
| 835 | voffset += (state->video.towns_crtc_reg[24] * 4) * ypos; // scanline size in bytes * y pos |
| 824 | 836 | voffset += (xpos & 0x1ff) * 2; |
| 825 | 837 | voffset &= 0x7ffff; |
| 826 | 838 | if(xpos < width && ypos < height && col < 0x8000) |
| 827 | 839 | { |
| 828 | | towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 829 | | towns_gfxvram[voffset] = col & 0x00ff; |
| 840 | state->towns_gfxvram[voffset+1] = (col & 0xff00) >> 8; |
| 841 | state->towns_gfxvram[voffset] = col & 0x00ff; |
| 830 | 842 | } |
| 831 | 843 | poffset+=2; |
| 832 | 844 | poffset &= 0x1ffff; |
| r8380 | r8381 | |
| 836 | 848 | |
| 837 | 849 | void draw_sprites(running_machine* machine, const rectangle* rect) |
| 838 | 850 | { |
| 839 | | UINT16 sprite_limit = (towns_sprite_reg[0] | (towns_sprite_reg[1] << 8)) & 0x3ff; |
| 851 | towns_state* state = (towns_state*)machine->driver_data; |
| 852 | UINT16 sprite_limit = (state->video.towns_sprite_reg[0] | (state->video.towns_sprite_reg[1] << 8)) & 0x3ff; |
| 840 | 853 | int n; |
| 841 | 854 | UINT16 x,y,attr,colour; |
| 842 | | UINT16 xoff = (towns_sprite_reg[2] | (towns_sprite_reg[3] << 8)) & 0x1ff; |
| 843 | | UINT16 yoff = (towns_sprite_reg[4] | (towns_sprite_reg[5] << 8)) & 0x1ff; |
| 855 | UINT16 xoff = (state->video.towns_sprite_reg[2] | (state->video.towns_sprite_reg[3] << 8)) & 0x1ff; |
| 856 | UINT16 yoff = (state->video.towns_sprite_reg[4] | (state->video.towns_sprite_reg[5] << 8)) & 0x1ff; |
| 844 | 857 | UINT32 poffset,coffset; |
| 845 | 858 | |
| 846 | | if(!(towns_sprite_reg[1] & 0x80)) |
| 859 | if(!(state->video.towns_sprite_reg[1] & 0x80)) |
| 847 | 860 | return; |
| 848 | 861 | |
| 849 | 862 | // clears VRAM for each frame? |
| 850 | | if(towns_sprite_reg[6] & 0x10) |
| 851 | | memset(towns_gfxvram+0x60000,0x80,0x20000); |
| 863 | if(state->video.towns_sprite_reg[6] & 0x10) |
| 864 | memset(state->towns_gfxvram+0x60000,0x80,0x20000); |
| 852 | 865 | else |
| 853 | | memset(towns_gfxvram+0x40000,0x80,0x20000); |
| 866 | memset(state->towns_gfxvram+0x40000,0x80,0x20000); |
| 854 | 867 | |
| 855 | 868 | for(n=sprite_limit;n<1024;n++) |
| 856 | 869 | { |
| 857 | | x = towns_txtvram[8*n] | (towns_txtvram[8*n+1] << 8); |
| 858 | | y = towns_txtvram[8*n+2] | (towns_txtvram[8*n+3] << 8); |
| 859 | | attr = towns_txtvram[8*n+4] | (towns_txtvram[8*n+5] << 8); |
| 860 | | colour = towns_txtvram[8*n+6] | (towns_txtvram[8*n+7] << 8); |
| 870 | x = state->towns_txtvram[8*n] | (state->towns_txtvram[8*n+1] << 8); |
| 871 | y = state->towns_txtvram[8*n+2] | (state->towns_txtvram[8*n+3] << 8); |
| 872 | attr = state->towns_txtvram[8*n+4] | (state->towns_txtvram[8*n+5] << 8); |
| 873 | colour = state->towns_txtvram[8*n+6] | (state->towns_txtvram[8*n+7] << 8); |
| 861 | 874 | if(attr & 0x8000) |
| 862 | 875 | { |
| 863 | 876 | x += xoff; |
| r8380 | r8381 | |
| 875 | 888 | n,x,y,attr,colour,poffset,coffset); |
| 876 | 889 | #endif |
| 877 | 890 | if(!(colour & 0x2000)) |
| 878 | | render_sprite_4((poffset)&0x1ffff,coffset,x,y,attr&0x2000,attr&0x1000,rect); |
| 891 | render_sprite_4(machine,(poffset)&0x1ffff,coffset,x,y,attr&0x2000,attr&0x1000,rect); |
| 879 | 892 | } |
| 880 | 893 | else |
| 881 | 894 | { |
| r8380 | r8381 | |
| 886 | 899 | n,x,y,attr,colour,poffset,coffset); |
| 887 | 900 | #endif |
| 888 | 901 | if(!(colour & 0x2000)) |
| 889 | | render_sprite_16((poffset)&0x1ffff,x,y,attr&0x2000,attr&0x1000,rect); |
| 902 | render_sprite_16(machine,(poffset)&0x1ffff,x,y,attr&0x2000,attr&0x1000,rect); |
| 890 | 903 | } |
| 891 | 904 | } |
| 892 | 905 | } |
| 893 | 906 | |
| 894 | | void towns_crtc_draw_scan_layer_hicolour(bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 907 | void towns_crtc_draw_scan_layer_hicolour(running_machine* machine, bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 895 | 908 | { |
| 909 | towns_state* state = (towns_state*)machine->driver_data; |
| 896 | 910 | UINT32 off = 0; |
| 897 | 911 | int x; |
| 898 | 912 | UINT16 colour; |
| r8380 | r8381 | |
| 901 | 915 | UINT32 scroll; |
| 902 | 916 | |
| 903 | 917 | if(layer == 0) |
| 904 | | linesize = towns_crtc_reg[20] * 4; |
| 918 | linesize = state->video.towns_crtc_reg[20] * 4; |
| 905 | 919 | else |
| 906 | | linesize = towns_crtc_reg[24] * 4; |
| 920 | linesize = state->video.towns_crtc_reg[24] * 4; |
| 907 | 921 | |
| 908 | | if(towns_display_page_sel != 0) |
| 922 | if(state->video.towns_display_page_sel != 0) |
| 909 | 923 | off = 0x20000; |
| 910 | 924 | if(layer != 0) |
| 911 | 925 | { |
| 912 | | if(!(towns_video_reg[0] & 0x10)) |
| 926 | if(!(state->video.towns_video_reg[0] & 0x10)) |
| 913 | 927 | return; |
| 914 | | if(!(towns_crtc_reg[28] & 0x10)) |
| 915 | | off += (towns_crtc_reg[21]) << 2; // initial offset |
| 928 | if(!(state->video.towns_crtc_reg[28] & 0x10)) |
| 929 | off += (state->video.towns_crtc_reg[21]) << 2; // initial offset |
| 916 | 930 | else |
| 917 | 931 | { |
| 918 | | scroll = ((towns_crtc_reg[21] & 0xfc00) << 2) | (((towns_crtc_reg[21] & 0x3ff) << 2)); |
| 932 | scroll = ((state->video.towns_crtc_reg[21] & 0xfc00) << 2) | (((state->video.towns_crtc_reg[21] & 0x3ff) << 2)); |
| 919 | 933 | off += scroll; |
| 920 | 934 | } |
| 921 | | off += (towns_crtc_reg[11] - towns_crtc_reg[22]); |
| 922 | | if(towns_crtc_reg[27] & 0x0100) |
| 935 | off += (state->video.towns_crtc_reg[11] - state->video.towns_crtc_reg[22]); |
| 936 | if(state->video.towns_crtc_reg[27] & 0x0100) |
| 923 | 937 | hzoom = 2; |
| 924 | 938 | } |
| 925 | 939 | else |
| 926 | 940 | { |
| 927 | | if(!(towns_crtc_reg[28] & 0x20)) |
| 928 | | off += (towns_crtc_reg[17]) << 2; // initial offset |
| 941 | if(!(state->video.towns_crtc_reg[28] & 0x20)) |
| 942 | off += (state->video.towns_crtc_reg[17]) << 2; // initial offset |
| 929 | 943 | else |
| 930 | 944 | { |
| 931 | | scroll = ((towns_crtc_reg[17] & 0xfc00) << 2) | (((towns_crtc_reg[17] & 0x3ff) << 2)); |
| 945 | scroll = ((state->video.towns_crtc_reg[17] & 0xfc00) << 2) | (((state->video.towns_crtc_reg[17] & 0x3ff) << 2)); |
| 932 | 946 | off += scroll; |
| 933 | 947 | } |
| 934 | | off += (towns_crtc_reg[9] - towns_crtc_reg[18]); |
| 935 | | if(towns_crtc_reg[27] & 0x0001) |
| 948 | off += (state->video.towns_crtc_reg[9] - state->video.towns_crtc_reg[18]); |
| 949 | if(state->video.towns_crtc_reg[27] & 0x0001) |
| 936 | 950 | hzoom = 2; |
| 937 | 951 | } |
| 938 | 952 | |
| r8380 | r8381 | |
| 942 | 956 | { |
| 943 | 957 | for(x=rect->min_x;x<rect->max_x;x++) |
| 944 | 958 | { |
| 945 | | if(towns_video_reg[0] & 0x10) |
| 959 | if(state->video.towns_video_reg[0] & 0x10) |
| 946 | 960 | off &= 0x3ffff; // 2 layers |
| 947 | 961 | else |
| 948 | 962 | off &= 0x7ffff; // 1 layer |
| 949 | 963 | |
| 950 | | colour = (towns_gfxvram[off+(layer*0x40000)+1] << 8) | towns_gfxvram[off+(layer*0x40000)]; |
| 964 | colour = (state->towns_gfxvram[off+(layer*0x40000)+1] << 8) | state->towns_gfxvram[off+(layer*0x40000)]; |
| 951 | 965 | if(colour < 0x8000) |
| 952 | 966 | { |
| 953 | 967 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| r8380 | r8381 | |
| 962 | 976 | { // x2 horizontal zoom |
| 963 | 977 | for(x=rect->min_x;x<rect->max_x;x+=2) |
| 964 | 978 | { |
| 965 | | if(towns_video_reg[0] & 0x10) |
| 979 | if(state->video.towns_video_reg[0] & 0x10) |
| 966 | 980 | off &= 0x3ffff; // 2 layers |
| 967 | 981 | else |
| 968 | 982 | off &= 0x7ffff; // 1 layer |
| 969 | | colour = (towns_gfxvram[off+(layer*0x40000)+1] << 8) | towns_gfxvram[off+(layer*0x40000)]; |
| 983 | colour = (state->towns_gfxvram[off+(layer*0x40000)+1] << 8) | state->towns_gfxvram[off+(layer*0x40000)]; |
| 970 | 984 | if(colour < 0x8000) |
| 971 | 985 | { |
| 972 | 986 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| r8380 | r8381 | |
| 983 | 997 | } |
| 984 | 998 | } |
| 985 | 999 | |
| 986 | | void towns_crtc_draw_scan_layer_256(bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 1000 | void towns_crtc_draw_scan_layer_256(running_machine* machine, bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 987 | 1001 | { |
| 1002 | towns_state* state = (towns_state*)machine->driver_data; |
| 988 | 1003 | int off = 0; |
| 989 | 1004 | int x; |
| 990 | 1005 | UINT8 colour; |
| r8380 | r8381 | |
| 992 | 1007 | int linesize; |
| 993 | 1008 | UINT32 scroll; |
| 994 | 1009 | |
| 995 | | if(towns_display_page_sel != 0) |
| 1010 | if(state->video.towns_display_page_sel != 0) |
| 996 | 1011 | off = 0x20000; |
| 997 | 1012 | if(layer == 0) |
| 998 | | linesize = towns_crtc_reg[20] * 8; |
| 1013 | linesize = state->video.towns_crtc_reg[20] * 8; |
| 999 | 1014 | else |
| 1000 | | linesize = towns_crtc_reg[24] * 8; |
| 1015 | linesize = state->video.towns_crtc_reg[24] * 8; |
| 1001 | 1016 | |
| 1002 | 1017 | if(layer != 0) |
| 1003 | 1018 | { |
| 1004 | | if(!(towns_video_reg[0] & 0x10)) |
| 1019 | if(!(state->video.towns_video_reg[0] & 0x10)) |
| 1005 | 1020 | return; |
| 1006 | | if(!(towns_crtc_reg[28] & 0x10)) |
| 1007 | | off += towns_crtc_reg[21] << 3; // initial offset |
| 1021 | if(!(state->video.towns_crtc_reg[28] & 0x10)) |
| 1022 | off += state->video.towns_crtc_reg[21] << 3; // initial offset |
| 1008 | 1023 | else |
| 1009 | 1024 | { |
| 1010 | | scroll = ((towns_crtc_reg[21] & 0xfc00) << 3) | (((towns_crtc_reg[21] & 0x3ff) << 3)); |
| 1025 | scroll = ((state->video.towns_crtc_reg[21] & 0xfc00) << 3) | (((state->video.towns_crtc_reg[21] & 0x3ff) << 3)); |
| 1011 | 1026 | off += scroll; |
| 1012 | 1027 | } |
| 1013 | | off += (towns_crtc_reg[11] - towns_crtc_reg[22]); |
| 1014 | | if(towns_crtc_reg[27] & 0x0100) |
| 1028 | off += (state->video.towns_crtc_reg[11] - state->video.towns_crtc_reg[22]); |
| 1029 | if(state->video.towns_crtc_reg[27] & 0x0100) |
| 1015 | 1030 | hzoom = 2; |
| 1016 | 1031 | } |
| 1017 | 1032 | else |
| 1018 | 1033 | { |
| 1019 | | if(!(towns_crtc_reg[28] & 0x20)) |
| 1020 | | off += towns_crtc_reg[17] << 3; // initial offset |
| 1034 | if(!(state->video.towns_crtc_reg[28] & 0x20)) |
| 1035 | off += state->video.towns_crtc_reg[17] << 3; // initial offset |
| 1021 | 1036 | else |
| 1022 | 1037 | { |
| 1023 | | scroll = ((towns_crtc_reg[17] & 0xfc00) << 3) | (((towns_crtc_reg[17] & 0x3ff) << 3)); |
| 1038 | scroll = ((state->video.towns_crtc_reg[17] & 0xfc00) << 3) | (((state->video.towns_crtc_reg[17] & 0x3ff) << 3)); |
| 1024 | 1039 | off += scroll; |
| 1025 | 1040 | } |
| 1026 | | off += (towns_crtc_reg[9] - towns_crtc_reg[18]); |
| 1027 | | if(towns_crtc_reg[27] & 0x0001) |
| 1041 | off += (state->video.towns_crtc_reg[9] - state->video.towns_crtc_reg[18]); |
| 1042 | if(state->video.towns_crtc_reg[27] & 0x0001) |
| 1028 | 1043 | hzoom = 2; |
| 1029 | 1044 | } |
| 1030 | 1045 | |
| r8380 | r8381 | |
| 1034 | 1049 | { |
| 1035 | 1050 | for(x=rect->min_x;x<rect->max_x;x++) |
| 1036 | 1051 | { |
| 1037 | | colour = towns_gfxvram[off+(layer*0x40000)]; |
| 1052 | colour = state->towns_gfxvram[off+(layer*0x40000)]; |
| 1038 | 1053 | if(colour != 0) |
| 1039 | 1054 | { |
| 1040 | 1055 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| 1041 | | (towns_palette_r[colour] << 16) |
| 1042 | | | (towns_palette_g[colour] << 8) |
| 1043 | | | (towns_palette_b[colour]); |
| 1056 | (state->video.towns_palette_r[colour] << 16) |
| 1057 | | (state->video.towns_palette_g[colour] << 8) |
| 1058 | | (state->video.towns_palette_b[colour]); |
| 1044 | 1059 | } |
| 1045 | 1060 | off++; |
| 1046 | 1061 | } |
| r8380 | r8381 | |
| 1049 | 1064 | { // x2 horizontal zoom |
| 1050 | 1065 | for(x=rect->min_x;x<rect->max_x;x+=2) |
| 1051 | 1066 | { |
| 1052 | | colour = towns_gfxvram[off+(layer*0x40000)+1]; |
| 1067 | colour = state->towns_gfxvram[off+(layer*0x40000)+1]; |
| 1053 | 1068 | if(colour != 0) |
| 1054 | 1069 | { |
| 1055 | 1070 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| 1056 | | (towns_palette_r[colour] << 16) |
| 1057 | | | (towns_palette_g[colour] << 8) |
| 1058 | | | (towns_palette_b[colour]); |
| 1071 | (state->video.towns_palette_r[colour] << 16) |
| 1072 | | (state->video.towns_palette_g[colour] << 8) |
| 1073 | | (state->video.towns_palette_b[colour]); |
| 1059 | 1074 | *BITMAP_ADDR32(bitmap,scanline,x+1) = |
| 1060 | | (towns_palette_r[colour] << 16) |
| 1061 | | | (towns_palette_g[colour] << 8) |
| 1062 | | | (towns_palette_b[colour]); |
| 1075 | (state->video.towns_palette_r[colour] << 16) |
| 1076 | | (state->video.towns_palette_g[colour] << 8) |
| 1077 | | (state->video.towns_palette_b[colour]); |
| 1063 | 1078 | } |
| 1064 | 1079 | off++; |
| 1065 | 1080 | } |
| 1066 | 1081 | } |
| 1067 | 1082 | } |
| 1068 | 1083 | |
| 1069 | | void towns_crtc_draw_scan_layer_16(bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 1084 | void towns_crtc_draw_scan_layer_16(running_machine* machine, bitmap_t* bitmap,const rectangle* rect,int layer,int line,int scanline) |
| 1070 | 1085 | { |
| 1086 | towns_state* state = (towns_state*)machine->driver_data; |
| 1071 | 1087 | int off = 0; |
| 1072 | 1088 | int x; |
| 1073 | 1089 | UINT8 colour; |
| r8380 | r8381 | |
| 1075 | 1091 | int linesize; |
| 1076 | 1092 | UINT32 scroll; |
| 1077 | 1093 | |
| 1078 | | if(towns_display_page_sel != 0) |
| 1094 | if(state->video.towns_display_page_sel != 0) |
| 1079 | 1095 | off = 0x20000; |
| 1080 | 1096 | if(layer == 0) |
| 1081 | | linesize = towns_crtc_reg[20] * 4; |
| 1097 | linesize = state->video.towns_crtc_reg[20] * 4; |
| 1082 | 1098 | else |
| 1083 | | linesize = towns_crtc_reg[24] * 4; |
| 1099 | linesize = state->video.towns_crtc_reg[24] * 4; |
| 1084 | 1100 | |
| 1085 | 1101 | if(layer != 0) |
| 1086 | 1102 | { |
| 1087 | | if(!(towns_video_reg[0] & 0x10)) |
| 1103 | if(!(state->video.towns_video_reg[0] & 0x10)) |
| 1088 | 1104 | return; |
| 1089 | | if(!(towns_crtc_reg[28] & 0x10)) |
| 1090 | | off += towns_crtc_reg[21]; // initial offset |
| 1105 | if(!(state->video.towns_crtc_reg[28] & 0x10)) |
| 1106 | off += state->video.towns_crtc_reg[21]; // initial offset |
| 1091 | 1107 | else |
| 1092 | 1108 | { |
| 1093 | | scroll = ((towns_crtc_reg[21] & 0xfc00)<<2) | (((towns_crtc_reg[21] & 0x3ff)<<2)); |
| 1109 | scroll = ((state->video.towns_crtc_reg[21] & 0xfc00)<<2) | (((state->video.towns_crtc_reg[21] & 0x3ff)<<2)); |
| 1094 | 1110 | off += scroll; |
| 1095 | 1111 | } |
| 1096 | | off += (towns_crtc_reg[11] - towns_crtc_reg[22]); |
| 1097 | | if(towns_crtc_reg[27] & 0x0100) |
| 1112 | off += (state->video.towns_crtc_reg[11] - state->video.towns_crtc_reg[22]); |
| 1113 | if(state->video.towns_crtc_reg[27] & 0x0100) |
| 1098 | 1114 | hzoom = 2; |
| 1099 | 1115 | } |
| 1100 | 1116 | else |
| 1101 | 1117 | { |
| 1102 | | if(!(towns_crtc_reg[28] & 0x20)) |
| 1103 | | off += towns_crtc_reg[17]; // initial offset |
| 1118 | if(!(state->video.towns_crtc_reg[28] & 0x20)) |
| 1119 | off += state->video.towns_crtc_reg[17]; // initial offset |
| 1104 | 1120 | else |
| 1105 | 1121 | { |
| 1106 | | scroll = ((towns_crtc_reg[17] & 0xfc00)<<2) | (((towns_crtc_reg[17] & 0x3ff)<<2)); |
| 1122 | scroll = ((state->video.towns_crtc_reg[17] & 0xfc00)<<2) | (((state->video.towns_crtc_reg[17] & 0x3ff)<<2)); |
| 1107 | 1123 | off += scroll; |
| 1108 | 1124 | } |
| 1109 | | off += (towns_crtc_reg[9] - towns_crtc_reg[18]); |
| 1110 | | if(towns_crtc_reg[27] & 0x0001) |
| 1125 | off += (state->video.towns_crtc_reg[9] - state->video.towns_crtc_reg[18]); |
| 1126 | if(state->video.towns_crtc_reg[27] & 0x0001) |
| 1111 | 1127 | hzoom = 2; |
| 1112 | 1128 | } |
| 1113 | 1129 | |
| r8380 | r8381 | |
| 1117 | 1133 | { |
| 1118 | 1134 | for(x=rect->min_x;x<rect->max_x;x+=2) |
| 1119 | 1135 | { |
| 1120 | | colour = towns_gfxvram[off+(layer*0x40000)] >> 4; |
| 1136 | colour = state->towns_gfxvram[off+(layer*0x40000)] >> 4; |
| 1121 | 1137 | if(colour != 0) |
| 1122 | 1138 | { |
| 1123 | 1139 | *BITMAP_ADDR32(bitmap,scanline,x+1) = |
| 1124 | | (towns_palette_r[colour] << 16) |
| 1125 | | | (towns_palette_g[colour] << 8) |
| 1126 | | | (towns_palette_b[colour]); |
| 1140 | (state->video.towns_palette_r[colour] << 16) |
| 1141 | | (state->video.towns_palette_g[colour] << 8) |
| 1142 | | (state->video.towns_palette_b[colour]); |
| 1127 | 1143 | } |
| 1128 | | colour = towns_gfxvram[off+(layer*0x40000)] & 0x0f; |
| 1144 | colour = state->towns_gfxvram[off+(layer*0x40000)] & 0x0f; |
| 1129 | 1145 | if(colour != 0) |
| 1130 | 1146 | { |
| 1131 | 1147 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| 1132 | | (towns_palette_r[colour] << 16) |
| 1133 | | | (towns_palette_g[colour] << 8) |
| 1134 | | | (towns_palette_b[colour]); |
| 1148 | (state->video.towns_palette_r[colour] << 16) |
| 1149 | | (state->video.towns_palette_g[colour] << 8) |
| 1150 | | (state->video.towns_palette_b[colour]); |
| 1135 | 1151 | } |
| 1136 | 1152 | off++; |
| 1137 | 1153 | } |
| r8380 | r8381 | |
| 1140 | 1156 | { // x2 horizontal zoom |
| 1141 | 1157 | for(x=rect->min_x;x<rect->max_x;x+=4) |
| 1142 | 1158 | { |
| 1143 | | if(towns_video_reg[0] & 0x10) |
| 1159 | if(state->video.towns_video_reg[0] & 0x10) |
| 1144 | 1160 | off &= 0x3ffff; // 2 layers |
| 1145 | 1161 | else |
| 1146 | 1162 | off &= 0x7ffff; // 1 layer |
| 1147 | | colour = towns_gfxvram[off+(layer*0x40000)] >> 4; |
| 1163 | colour = state->towns_gfxvram[off+(layer*0x40000)] >> 4; |
| 1148 | 1164 | if(colour != 0) |
| 1149 | 1165 | { |
| 1150 | 1166 | *BITMAP_ADDR32(bitmap,scanline,x+2) = |
| 1151 | | (towns_palette_r[colour] << 16) |
| 1152 | | | (towns_palette_g[colour] << 8) |
| 1153 | | | (towns_palette_b[colour]); |
| 1167 | (state->video.towns_palette_r[colour] << 16) |
| 1168 | | (state->video.towns_palette_g[colour] << 8) |
| 1169 | | (state->video.towns_palette_b[colour]); |
| 1154 | 1170 | *BITMAP_ADDR32(bitmap,scanline,x+3) = |
| 1155 | | (towns_palette_r[colour] << 16) |
| 1156 | | | (towns_palette_g[colour] << 8) |
| 1157 | | | (towns_palette_b[colour]); |
| 1171 | (state->video.towns_palette_r[colour] << 16) |
| 1172 | | (state->video.towns_palette_g[colour] << 8) |
| 1173 | | (state->video.towns_palette_b[colour]); |
| 1158 | 1174 | } |
| 1159 | | colour = towns_gfxvram[off+(layer*0x40000)] & 0x0f; |
| 1175 | colour = state->towns_gfxvram[off+(layer*0x40000)] & 0x0f; |
| 1160 | 1176 | if(colour != 0) |
| 1161 | 1177 | { |
| 1162 | 1178 | *BITMAP_ADDR32(bitmap,scanline,x) = |
| 1163 | | (towns_palette_r[colour] << 16) |
| 1164 | | | (towns_palette_g[colour] << 8) |
| 1165 | | | (towns_palette_b[colour]); |
| 1179 | (state->video.towns_palette_r[colour] << 16) |
| 1180 | | (state->video.towns_palette_g[colour] << 8) |
| 1181 | | (state->video.towns_palette_b[colour]); |
| 1166 | 1182 | *BITMAP_ADDR32(bitmap,scanline,x+1) = |
| 1167 | | (towns_palette_r[colour] << 16) |
| 1168 | | | (towns_palette_g[colour] << 8) |
| 1169 | | | (towns_palette_b[colour]); |
| 1183 | (state->video.towns_palette_r[colour] << 16) |
| 1184 | | (state->video.towns_palette_g[colour] << 8) |
| 1185 | | (state->video.towns_palette_b[colour]); |
| 1170 | 1186 | } |
| 1171 | 1187 | off++; |
| 1172 | 1188 | } |
| r8380 | r8381 | |
| 1175 | 1191 | |
| 1176 | 1192 | void towns_crtc_draw_layer(running_machine* machine,bitmap_t* bitmap,const rectangle* rect,int layer) |
| 1177 | 1193 | { |
| 1194 | towns_state* state = (towns_state*)machine->driver_data; |
| 1178 | 1195 | int line; |
| 1179 | 1196 | int scanline; |
| 1180 | 1197 | int height; |
| r8380 | r8381 | |
| 1183 | 1200 | { |
| 1184 | 1201 | scanline = rect->min_y; |
| 1185 | 1202 | height = (rect->max_y - rect->min_y); |
| 1186 | | if(towns_crtc_reg[27] & 0x0010) |
| 1203 | if(state->video.towns_crtc_reg[27] & 0x0010) |
| 1187 | 1204 | height /= 2; |
| 1188 | | switch(towns_video_reg[0] & 0x03) |
| 1205 | switch(state->video.towns_video_reg[0] & 0x03) |
| 1189 | 1206 | { |
| 1190 | 1207 | case 0x01: |
| 1191 | 1208 | for(line=0;line<height;line++) |
| 1192 | 1209 | { |
| 1193 | | towns_crtc_draw_scan_layer_16(bitmap,rect,layer,line,scanline); |
| 1210 | towns_crtc_draw_scan_layer_16(machine,bitmap,rect,layer,line,scanline); |
| 1194 | 1211 | scanline++; |
| 1195 | | if(towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1212 | if(state->video.towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1196 | 1213 | { |
| 1197 | | towns_crtc_draw_scan_layer_16(bitmap,rect,layer,line,scanline); |
| 1214 | towns_crtc_draw_scan_layer_16(machine,bitmap,rect,layer,line,scanline); |
| 1198 | 1215 | scanline++; |
| 1199 | 1216 | } |
| 1200 | 1217 | } |
| r8380 | r8381 | |
| 1202 | 1219 | case 0x02: |
| 1203 | 1220 | for(line=0;line<height;line++) |
| 1204 | 1221 | { |
| 1205 | | towns_crtc_draw_scan_layer_256(bitmap,rect,layer,line,scanline); |
| 1222 | towns_crtc_draw_scan_layer_256(machine,bitmap,rect,layer,line,scanline); |
| 1206 | 1223 | scanline++; |
| 1207 | | if(towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1224 | if(state->video.towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1208 | 1225 | { |
| 1209 | | towns_crtc_draw_scan_layer_256(bitmap,rect,layer,line,scanline); |
| 1226 | towns_crtc_draw_scan_layer_256(machine,bitmap,rect,layer,line,scanline); |
| 1210 | 1227 | scanline++; |
| 1211 | 1228 | } |
| 1212 | 1229 | } |
| r8380 | r8381 | |
| 1214 | 1231 | case 0x03: |
| 1215 | 1232 | for(line=0;line<height;line++) |
| 1216 | 1233 | { |
| 1217 | | towns_crtc_draw_scan_layer_hicolour(bitmap,rect,layer,line,scanline); |
| 1234 | towns_crtc_draw_scan_layer_hicolour(machine,bitmap,rect,layer,line,scanline); |
| 1218 | 1235 | scanline++; |
| 1219 | | if(towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1236 | if(state->video.towns_crtc_reg[27] & 0x0010) // vertical zoom |
| 1220 | 1237 | { |
| 1221 | | towns_crtc_draw_scan_layer_hicolour(bitmap,rect,layer,line,scanline); |
| 1238 | towns_crtc_draw_scan_layer_hicolour(machine,bitmap,rect,layer,line,scanline); |
| 1222 | 1239 | scanline++; |
| 1223 | 1240 | } |
| 1224 | 1241 | } |
| r8380 | r8381 | |
| 1229 | 1246 | { |
| 1230 | 1247 | scanline = rect->min_y; |
| 1231 | 1248 | height = (rect->max_y - rect->min_y); |
| 1232 | | if(towns_crtc_reg[27] & 0x1000) |
| 1249 | if(state->video.towns_crtc_reg[27] & 0x1000) |
| 1233 | 1250 | height /= 2; |
| 1234 | | switch(towns_video_reg[0] & 0x0c) |
| 1251 | switch(state->video.towns_video_reg[0] & 0x0c) |
| 1235 | 1252 | { |
| 1236 | 1253 | case 0x04: |
| 1237 | 1254 | for(line=0;line<height;line++) |
| 1238 | 1255 | { |
| 1239 | | towns_crtc_draw_scan_layer_16(bitmap,rect,layer,line,scanline); |
| 1256 | towns_crtc_draw_scan_layer_16(machine,bitmap,rect,layer,line,scanline); |
| 1240 | 1257 | scanline++; |
| 1241 | | if(towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1258 | if(state->video.towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1242 | 1259 | { |
| 1243 | | towns_crtc_draw_scan_layer_16(bitmap,rect,layer,line,scanline); |
| 1260 | towns_crtc_draw_scan_layer_16(machine,bitmap,rect,layer,line,scanline); |
| 1244 | 1261 | scanline++; |
| 1245 | 1262 | } |
| 1246 | 1263 | } |
| r8380 | r8381 | |
| 1248 | 1265 | case 0x08: |
| 1249 | 1266 | for(line=0;line<height;line++) |
| 1250 | 1267 | { |
| 1251 | | towns_crtc_draw_scan_layer_256(bitmap,rect,layer,line,scanline); |
| 1268 | towns_crtc_draw_scan_layer_256(machine,bitmap,rect,layer,line,scanline); |
| 1252 | 1269 | scanline++; |
| 1253 | | if(towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1270 | if(state->video.towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1254 | 1271 | { |
| 1255 | | towns_crtc_draw_scan_layer_256(bitmap,rect,layer,line,scanline); |
| 1272 | towns_crtc_draw_scan_layer_256(machine,bitmap,rect,layer,line,scanline); |
| 1256 | 1273 | scanline++; |
| 1257 | 1274 | } |
| 1258 | 1275 | } |
| r8380 | r8381 | |
| 1260 | 1277 | case 0x0c: |
| 1261 | 1278 | for(line=0;line<height;line++) |
| 1262 | 1279 | { |
| 1263 | | towns_crtc_draw_scan_layer_hicolour(bitmap,rect,layer,line,scanline); |
| 1280 | towns_crtc_draw_scan_layer_hicolour(machine,bitmap,rect,layer,line,scanline); |
| 1264 | 1281 | scanline++; |
| 1265 | | if(towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1282 | if(state->video.towns_crtc_reg[27] & 0x1000) // vertical zoom |
| 1266 | 1283 | { |
| 1267 | | towns_crtc_draw_scan_layer_hicolour(bitmap,rect,layer,line,scanline); |
| 1284 | towns_crtc_draw_scan_layer_hicolour(machine,bitmap,rect,layer,line,scanline); |
| 1268 | 1285 | scanline++; |
| 1269 | 1286 | } |
| 1270 | 1287 | } |
| r8380 | r8381 | |
| 1275 | 1292 | |
| 1276 | 1293 | void render_text_char(running_machine* machine, UINT8 x, UINT8 y, UINT8 ascii, UINT16 jis, UINT8 attr) |
| 1277 | 1294 | { |
| 1295 | towns_state* state = (towns_state*)machine->driver_data; |
| 1278 | 1296 | UINT32 rom_addr; |
| 1279 | 1297 | UINT32 vram_addr; |
| 1280 | | UINT16 linesize = towns_crtc_reg[24] * 4; |
| 1298 | UINT16 linesize = state->video.towns_crtc_reg[24] * 4; |
| 1281 | 1299 | UINT8 code_h,code_l; |
| 1282 | 1300 | UINT8 colour; |
| 1283 | 1301 | UINT8 data; |
| r8380 | r8381 | |
| 1301 | 1319 | | (((code_l - 0x20) & 0x40) << 6) |
| 1302 | 1320 | | ((code_h & 0x07) << 9); |
| 1303 | 1321 | } |
| 1304 | | else if(towns_kanji_code_h < 0x70) |
| 1322 | else if(code_h < 0x70) |
| 1305 | 1323 | { |
| 1306 | 1324 | rom_addr = ((code_l & 0x1f) << 4) |
| 1307 | 1325 | + (((code_l - 0x20) & 0x60) << 8) |
| r8380 | r8381 | |
| 1370 | 1388 | * |
| 1371 | 1389 | * The video hardware renders text to VRAM layer 1, there is no separate text layer |
| 1372 | 1390 | */ |
| 1391 | towns_state* state = (towns_state*)machine->driver_data; |
| 1373 | 1392 | int x,y,c = 0; |
| 1374 | 1393 | |
| 1375 | 1394 | for(y=0;y<40;y++) |
| 1376 | 1395 | { |
| 1377 | 1396 | for(x=0;x<80;x++) |
| 1378 | 1397 | { |
| 1379 | | render_text_char(machine,x,y,towns_txtvram[c],((towns_txtvram[c+0x2000] << 8)|(towns_txtvram[c+0x2001])),towns_txtvram[c+1]); |
| 1398 | render_text_char(machine,x,y,state->towns_txtvram[c],((state->towns_txtvram[c+0x2000] << 8)|(state->towns_txtvram[c+0x2001])),state->towns_txtvram[c+1]); |
| 1380 | 1399 | c+=2; |
| 1381 | 1400 | } |
| 1382 | 1401 | } |
| r8380 | r8381 | |
| 1385 | 1404 | static TIMER_CALLBACK( towns_vblank_end ) |
| 1386 | 1405 | { |
| 1387 | 1406 | // here we'll clear the vsync signal, I presume it goes low on it's own eventually |
| 1407 | towns_state* state = (towns_state*)machine->driver_data; |
| 1388 | 1408 | running_device* dev = (running_device*)ptr; |
| 1389 | 1409 | pic8259_ir3_w(dev, 0); // IRQ11 = VSync |
| 1390 | | towns_vblank_flag = 0; |
| 1410 | logerror("PIC: IRQ11 (VSync) set low\n"); |
| 1411 | state->video.towns_vblank_flag = 0; |
| 1391 | 1412 | } |
| 1392 | 1413 | |
| 1393 | 1414 | INTERRUPT_GEN( towns_vsync_irq ) |
| 1394 | 1415 | { |
| 1395 | | running_device* dev = devtag_get_device(device->machine,"pic8259_slave"); |
| 1416 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1417 | running_device* dev = state->pic_slave; |
| 1396 | 1418 | pic8259_ir3_w(dev, 1); // IRQ11 = VSync |
| 1397 | | towns_vblank_flag = 1; |
| 1419 | logerror("PIC: IRQ11 (VSync) set high\n"); |
| 1420 | state->video.towns_vblank_flag = 1; |
| 1398 | 1421 | timer_set(device->machine,device->machine->primary_screen->time_until_vblank_end(),(void*)dev,0,towns_vblank_end); |
| 1399 | | if(towns_tvram_enable) |
| 1422 | if(state->video.towns_tvram_enable) |
| 1400 | 1423 | draw_text_layer(dev->machine); |
| 1401 | | if(towns_sprite_reg[1] & 0x80) // if sprites are enabled, then sprites are drawn on this layer. |
| 1402 | | draw_sprites(dev->machine,&towns_crtc_layerscr[1]); |
| 1424 | if(state->video.towns_sprite_reg[1] & 0x80) // if sprites are enabled, then sprites are drawn on this layer. |
| 1425 | draw_sprites(dev->machine,&state->video.towns_crtc_layerscr[1]); |
| 1403 | 1426 | } |
| 1404 | 1427 | |
| 1405 | 1428 | VIDEO_START( towns ) |
| 1406 | 1429 | { |
| 1407 | | towns_vram_wplane = 0x00; |
| 1430 | towns_state* state = (towns_state*)machine->driver_data; |
| 1431 | |
| 1432 | state->video.towns_vram_wplane = 0x00; |
| 1408 | 1433 | } |
| 1409 | 1434 | |
| 1410 | 1435 | VIDEO_UPDATE( towns ) |
| 1411 | 1436 | { |
| 1437 | towns_state* state = (towns_state*)screen->machine->driver_data; |
| 1438 | |
| 1412 | 1439 | bitmap_fill(bitmap,cliprect,0x00000000); |
| 1413 | 1440 | |
| 1414 | | if(!(towns_video_reg[1] & 0x01)) |
| 1441 | if(!(state->video.towns_video_reg[1] & 0x01)) |
| 1415 | 1442 | { |
| 1416 | 1443 | if(!input_code_pressed(screen->machine,KEYCODE_Q)) |
| 1417 | 1444 | { |
| 1418 | | if((towns_layer_ctrl & 0x03) != 0) |
| 1419 | | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1); |
| 1445 | if((state->video.towns_layer_ctrl & 0x03) != 0) |
| 1446 | towns_crtc_draw_layer(screen->machine,bitmap,&state->video.towns_crtc_layerscr[1],1); |
| 1420 | 1447 | } |
| 1421 | 1448 | if(!input_code_pressed(screen->machine,KEYCODE_W)) |
| 1422 | 1449 | { |
| 1423 | | if((towns_layer_ctrl & 0x0c) != 0) |
| 1424 | | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0); |
| 1450 | if((state->video.towns_layer_ctrl & 0x0c) != 0) |
| 1451 | towns_crtc_draw_layer(screen->machine,bitmap,&state->video.towns_crtc_layerscr[0],0); |
| 1425 | 1452 | } |
| 1426 | 1453 | } |
| 1427 | 1454 | else |
| 1428 | 1455 | { |
| 1429 | 1456 | if(!input_code_pressed(screen->machine,KEYCODE_Q)) |
| 1430 | 1457 | { |
| 1431 | | if((towns_layer_ctrl & 0x0c) != 0) |
| 1432 | | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[0],0); |
| 1458 | if((state->video.towns_layer_ctrl & 0x0c) != 0) |
| 1459 | towns_crtc_draw_layer(screen->machine,bitmap,&state->video.towns_crtc_layerscr[0],0); |
| 1433 | 1460 | } |
| 1434 | 1461 | if(!input_code_pressed(screen->machine,KEYCODE_W)) |
| 1435 | 1462 | { |
| 1436 | | if((towns_layer_ctrl & 0x03) != 0) |
| 1437 | | towns_crtc_draw_layer(screen->machine,bitmap,&towns_crtc_layerscr[1],1); |
| 1463 | if((state->video.towns_layer_ctrl & 0x03) != 0) |
| 1464 | towns_crtc_draw_layer(screen->machine,bitmap,&state->video.towns_crtc_layerscr[1],1); |
| 1438 | 1465 | } |
| 1439 | 1466 | } |
| 1440 | 1467 | |
src/mess/drivers/fmtowns.c
| r8380 | r8381 | |
| 140 | 140 | MOUSE_Y_LOW |
| 141 | 141 | }; |
| 142 | 142 | |
| 143 | | static UINT8 ftimer; |
| 144 | | static UINT8 nmi_mask; |
| 145 | | static UINT8 compat_mode; |
| 146 | | static UINT8 towns_system_port; |
| 147 | | UINT32 towns_ankcg_enable; |
| 148 | | UINT32 towns_mainmem_enable; |
| 149 | | static UINT32 towns_ram_enable; |
| 150 | | static UINT8* towns_cmos; |
| 151 | | UINT32* towns_vram; |
| 152 | | UINT8* towns_gfxvram; |
| 153 | | UINT8* towns_txtvram; |
| 154 | | //UINT8* towns_sprram; |
| 155 | | static int towns_selected_drive; |
| 156 | | static UINT8 towns_fdc_irq6mask; |
| 157 | | static UINT8* towns_serial_rom; |
| 158 | | static int towns_srom_position; |
| 159 | | static UINT8 towns_srom_clk; |
| 160 | | static UINT8 towns_srom_reset; |
| 161 | | static UINT8 towns_rtc_select; |
| 162 | | static UINT8 towns_rtc_data; |
| 163 | | static UINT8 towns_rtc_reg[16]; |
| 164 | | static emu_timer* towns_rtc_timer; |
| 165 | | static UINT8 towns_timer_mask; |
| 166 | | static UINT16 towns_machine_id; // default is 0x0101 |
| 167 | | static UINT8 towns_kb_status; |
| 168 | | static UINT8 towns_kb_irq1_enable; |
| 169 | | static UINT8 towns_kb_output; // key output |
| 170 | | static UINT8 towns_kb_extend; // extended key output |
| 171 | | static emu_timer* towns_kb_timer; |
| 172 | | static emu_timer* towns_mouse_timer; |
| 173 | | static UINT8 towns_fm_irq_flag; |
| 174 | | static UINT8 towns_pcm_irq_flag; |
| 175 | | static UINT8 towns_pcm_channel_flag; |
| 176 | | static UINT8 towns_pcm_channel_mask; |
| 177 | | static UINT8 towns_pad_mask; |
| 178 | | static UINT8 towns_mouse_output; |
| 179 | | static UINT8 towns_mouse_x; |
| 180 | | static UINT8 towns_mouse_y; |
| 181 | | |
| 182 | | static struct towns_cdrom_controller |
| 183 | | { |
| 184 | | UINT8 command; |
| 185 | | UINT8 status; |
| 186 | | UINT8 cmd_status[4]; |
| 187 | | UINT8 cmd_status_ptr; |
| 188 | | UINT8 extra_status; |
| 189 | | UINT8 parameter[8]; |
| 190 | | UINT8 mpu_irq_enable; |
| 191 | | UINT8 dma_irq_enable; |
| 192 | | UINT8 buffer[2048]; |
| 193 | | INT32 buffer_ptr; |
| 194 | | UINT32 lba_current; |
| 195 | | UINT32 lba_last; |
| 196 | | UINT32 cdda_current; |
| 197 | | UINT32 cdda_length; |
| 198 | | emu_timer* read_timer; |
| 199 | | } towns_cd; |
| 200 | | |
| 201 | 143 | static WRITE_LINE_DEVICE_HANDLER( towns_pic_irq ); |
| 202 | 144 | |
| 203 | 145 | INLINE UINT8 byte_to_bcd(UINT8 val) |
| r8380 | r8381 | |
| 216 | 158 | f = bcd_to_byte(val & 0x0000ff); |
| 217 | 159 | s = (bcd_to_byte((val & 0x00ff00) >> 8)); |
| 218 | 160 | m = (bcd_to_byte((val & 0xff0000) >> 16)); |
| 219 | | return (m * (60 * 75)) + (s * 75) + f; |
| 161 | return ((m * (60 * 75)) + (s * 75) + f); |
| 220 | 162 | } |
| 221 | 163 | |
| 222 | 164 | static void towns_init_serial_rom(running_machine* machine) |
| 223 | 165 | { |
| 224 | 166 | // TODO: init serial ROM contents |
| 167 | towns_state* state = (towns_state*)machine->driver_data; |
| 225 | 168 | int x; |
| 226 | 169 | UINT8 code[8] = { 0x04,0x65,0x54,0xA4,0x95,0x45,0x35,0x5F }; |
| 227 | 170 | UINT8* srom = memory_region(machine,"serial"); |
| 228 | 171 | |
| 229 | | memset(towns_serial_rom,0,256/8); |
| 172 | memset(state->towns_serial_rom,0,256/8); |
| 230 | 173 | |
| 231 | 174 | if(srom) |
| 232 | 175 | { |
| 233 | | memcpy(towns_serial_rom,srom,32); |
| 234 | | towns_machine_id = (towns_serial_rom[0x18] << 8) | towns_serial_rom[0x17]; |
| 235 | | popmessage("Machine ID in serial ROM: %04x",towns_machine_id); |
| 176 | memcpy(state->towns_serial_rom,srom,32); |
| 177 | state->towns_machine_id = (state->towns_serial_rom[0x18] << 8) | state->towns_serial_rom[0x17]; |
| 178 | popmessage("Machine ID in serial ROM: %04x",state->towns_machine_id); |
| 236 | 179 | return; |
| 237 | 180 | } |
| 238 | 181 | |
| 239 | 182 | for(x=8;x<=21;x++) |
| 240 | | towns_serial_rom[x] = 0xff; |
| 183 | state->towns_serial_rom[x] = 0xff; |
| 241 | 184 | |
| 242 | 185 | for(x=0;x<=7;x++) |
| 243 | 186 | { |
| 244 | | towns_serial_rom[x] = code[x]; |
| 187 | state->towns_serial_rom[x] = code[x]; |
| 245 | 188 | } |
| 246 | 189 | |
| 247 | 190 | // add Machine ID |
| 248 | | towns_machine_id = 0x0101; |
| 249 | | towns_serial_rom[0x17] = 0x01; |
| 250 | | towns_serial_rom[0x18] = 0x01; |
| 191 | state->towns_machine_id = 0x0101; |
| 192 | state->towns_serial_rom[0x17] = 0x01; |
| 193 | state->towns_serial_rom[0x18] = 0x01; |
| 251 | 194 | |
| 252 | 195 | // serial number? |
| 253 | | towns_serial_rom[29] = 0x10; |
| 254 | | towns_serial_rom[28] = 0x6e; |
| 255 | | towns_serial_rom[27] = 0x54; |
| 256 | | towns_serial_rom[26] = 0x32; |
| 257 | | towns_serial_rom[25] = 0x10; |
| 196 | state->towns_serial_rom[29] = 0x10; |
| 197 | state->towns_serial_rom[28] = 0x6e; |
| 198 | state->towns_serial_rom[27] = 0x54; |
| 199 | state->towns_serial_rom[26] = 0x32; |
| 200 | state->towns_serial_rom[25] = 0x10; |
| 258 | 201 | } |
| 259 | 202 | |
| 260 | | static void towns_init_rtc(void) |
| 203 | static void towns_init_rtc(running_machine* machine) |
| 261 | 204 | { |
| 205 | towns_state* state = (towns_state*)machine->driver_data; |
| 262 | 206 | // for now, we'll just keep a static time stored here |
| 263 | 207 | // seconds |
| 264 | | towns_rtc_reg[0] = 0; |
| 265 | | towns_rtc_reg[1] = 3; |
| 208 | state->towns_rtc_reg[0] = 0; |
| 209 | state->towns_rtc_reg[1] = 3; |
| 266 | 210 | // minutes |
| 267 | | towns_rtc_reg[2] = 2; |
| 268 | | towns_rtc_reg[3] = 1; |
| 211 | state->towns_rtc_reg[2] = 2; |
| 212 | state->towns_rtc_reg[3] = 1; |
| 269 | 213 | // hours |
| 270 | | towns_rtc_reg[4] = 8; |
| 271 | | towns_rtc_reg[5] = 0; |
| 214 | state->towns_rtc_reg[4] = 8; |
| 215 | state->towns_rtc_reg[5] = 0; |
| 272 | 216 | // weekday |
| 273 | | towns_rtc_reg[6] = 2; |
| 217 | state->towns_rtc_reg[6] = 2; |
| 274 | 218 | // day |
| 275 | | towns_rtc_reg[7] = 1; |
| 276 | | towns_rtc_reg[8] = 1; |
| 219 | state->towns_rtc_reg[7] = 1; |
| 220 | state->towns_rtc_reg[8] = 1; |
| 277 | 221 | // month |
| 278 | | towns_rtc_reg[9] = 6; |
| 279 | | towns_rtc_reg[10] = 0; |
| 222 | state->towns_rtc_reg[9] = 6; |
| 223 | state->towns_rtc_reg[10] = 0; |
| 280 | 224 | // year |
| 281 | | towns_rtc_reg[11] = 9; |
| 282 | | towns_rtc_reg[12] = 0; |
| 225 | state->towns_rtc_reg[11] = 9; |
| 226 | state->towns_rtc_reg[12] = 0; |
| 283 | 227 | } |
| 284 | 228 | |
| 285 | 229 | static READ8_HANDLER(towns_system_r) |
| 286 | 230 | { |
| 231 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 287 | 232 | UINT8 ret = 0; |
| 288 | 233 | |
| 289 | 234 | switch(offset) |
| r8380 | r8381 | |
| 296 | 241 | return 0x00; |
| 297 | 242 | case 0x06: |
| 298 | 243 | //logerror("SYS: (0x26) timer read\n"); |
| 299 | | ftimer -= 0x13; |
| 300 | | return ftimer; |
| 244 | state->ftimer -= 0x13; |
| 245 | return state->ftimer; |
| 301 | 246 | case 0x08: |
| 302 | 247 | //logerror("SYS: (0x28) NMI mask read\n"); |
| 303 | | return nmi_mask & 0x01; |
| 248 | return state->nmi_mask & 0x01; |
| 304 | 249 | case 0x10: |
| 305 | 250 | logerror("SYS: (0x30) Machine ID read\n"); |
| 306 | | return (towns_machine_id >> 8) & 0xff; |
| 251 | return (state->towns_machine_id >> 8) & 0xff; |
| 307 | 252 | case 0x11: |
| 308 | 253 | logerror("SYS: (0x31) Machine ID read\n"); |
| 309 | | return towns_machine_id & 0xff; |
| 254 | return state->towns_machine_id & 0xff; |
| 310 | 255 | case 0x12: |
| 311 | 256 | /* Bit 0 = data, bit 6 = CLK, bit 7 = RESET, bit 5 is always 1? */ |
| 312 | | ret = (towns_serial_rom[towns_srom_position/8] & (1 << (towns_srom_position%8))) ? 1 : 0; |
| 313 | | ret |= towns_srom_clk; |
| 314 | | ret |= towns_srom_reset; |
| 257 | ret = (state->towns_serial_rom[state->towns_srom_position/8] & (1 << (state->towns_srom_position%8))) ? 1 : 0; |
| 258 | ret |= state->towns_srom_clk; |
| 259 | ret |= state->towns_srom_reset; |
| 315 | 260 | //logerror("SYS: (0x32) Serial ROM read [0x%02x, pos=%i]\n",ret,towns_srom_position); |
| 316 | 261 | return ret; |
| 317 | 262 | default: |
| r8380 | r8381 | |
| 322 | 267 | |
| 323 | 268 | static WRITE8_HANDLER(towns_system_w) |
| 324 | 269 | { |
| 270 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 271 | |
| 325 | 272 | switch(offset) |
| 326 | 273 | { |
| 327 | 274 | case 0x00: // bit 7 = NMI vector protect, bit 6 = power off, bit 0 = software reset |
| r8380 | r8381 | |
| 332 | 279 | break; |
| 333 | 280 | case 0x08: |
| 334 | 281 | //logerror("SYS: (0x28) NMI mask write %02x\n",data); |
| 335 | | nmi_mask = data & 0x01; |
| 282 | state->nmi_mask = data & 0x01; |
| 336 | 283 | break; |
| 337 | 284 | case 0x12: |
| 338 | 285 | //logerror("SYS: (0x32) Serial ROM write %02x\n",data); |
| 339 | 286 | // clocks on low-to-high transition |
| 340 | | if((data & 0x40) && towns_srom_clk == 0) // CLK |
| 287 | if((data & 0x40) && state->towns_srom_clk == 0) // CLK |
| 341 | 288 | { // advance to next bit |
| 342 | | towns_srom_position++; |
| 289 | state->towns_srom_position++; |
| 343 | 290 | } |
| 344 | | if((data & 0x80) && towns_srom_reset == 0) // reset |
| 291 | if((data & 0x80) && state->towns_srom_reset == 0) // reset |
| 345 | 292 | { // reset to beginning |
| 346 | | towns_srom_position = 0; |
| 293 | state->towns_srom_position = 0; |
| 347 | 294 | } |
| 348 | | towns_srom_clk = data & 0x40; |
| 349 | | towns_srom_reset = data & 0x80; |
| 295 | state->towns_srom_clk = data & 0x40; |
| 296 | state->towns_srom_reset = data & 0x80; |
| 350 | 297 | break; |
| 351 | 298 | default: |
| 352 | 299 | logerror("SYS: Unknown system port write 0x%02x (0x%02x)\n",data,offset); |
| r8380 | r8381 | |
| 361 | 308 | |
| 362 | 309 | static WRITE8_HANDLER(towns_sys6c_w) |
| 363 | 310 | { |
| 311 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 364 | 312 | // logerror("SYS: (0x6c) write to timer (0x%02x)\n",data); |
| 365 | | ftimer -= 0x54; |
| 313 | state->ftimer -= 0x54; |
| 366 | 314 | } |
| 367 | 315 | |
| 368 | 316 | static READ8_HANDLER(towns_dma1_r) |
| 369 | 317 | { |
| 370 | | running_device* dev = devtag_get_device(space->machine,"dma_1"); |
| 318 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 319 | running_device* dev = state->dma_1; |
| 371 | 320 | |
| 372 | 321 | logerror("DMA#1: read register %i\n",offset); |
| 373 | 322 | return upd71071_r(dev,offset); |
| r8380 | r8381 | |
| 375 | 324 | |
| 376 | 325 | static WRITE8_HANDLER(towns_dma1_w) |
| 377 | 326 | { |
| 378 | | running_device* dev = devtag_get_device(space->machine,"dma_1"); |
| 327 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 328 | running_device* dev = state->dma_1; |
| 379 | 329 | |
| 380 | 330 | logerror("DMA#1: wrote 0x%02x to register %i\n",data,offset); |
| 381 | 331 | upd71071_w(dev,offset,data); |
| r8380 | r8381 | |
| 383 | 333 | |
| 384 | 334 | static READ8_HANDLER(towns_dma2_r) |
| 385 | 335 | { |
| 386 | | running_device* dev = devtag_get_device(space->machine,"dma_2"); |
| 336 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 337 | running_device* dev = state->dma_2; |
| 387 | 338 | |
| 388 | 339 | logerror("DMA#2: read register %i\n",offset); |
| 389 | 340 | return upd71071_r(dev,offset); |
| r8380 | r8381 | |
| 391 | 342 | |
| 392 | 343 | static WRITE8_HANDLER(towns_dma2_w) |
| 393 | 344 | { |
| 394 | | running_device* dev = devtag_get_device(space->machine,"dma_2"); |
| 345 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 346 | running_device* dev = state->dma_2; |
| 395 | 347 | |
| 396 | 348 | logerror("DMA#2: wrote 0x%02x to register %i\n",data,offset); |
| 397 | 349 | upd71071_w(dev,offset,data); |
| r8380 | r8381 | |
| 403 | 355 | |
| 404 | 356 | static WRITE_LINE_DEVICE_HANDLER( towns_mb8877a_irq_w ) |
| 405 | 357 | { |
| 406 | | if(towns_fdc_irq6mask == 0) |
| 358 | towns_state* tstate = (towns_state*)device->machine->driver_data; |
| 359 | |
| 360 | if(tstate->towns_fdc_irq6mask == 0) |
| 407 | 361 | state = 0; |
| 408 | 362 | pic8259_ir6_w(device, state); // IRQ6 = FDC |
| 409 | 363 | logerror("PIC: IRQ6 (FDC) set to %i\n",state); |
| r8380 | r8381 | |
| 416 | 370 | |
| 417 | 371 | static READ8_HANDLER(towns_floppy_r) |
| 418 | 372 | { |
| 419 | | running_device* fdc = devtag_get_device(space->machine,"fdc"); |
| 373 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 374 | running_device* fdc = state->fdc; |
| 420 | 375 | |
| 421 | 376 | switch(offset) |
| 422 | 377 | { |
| r8380 | r8381 | |
| 430 | 385 | return wd17xx_data_r(fdc,offset/2); |
| 431 | 386 | case 0x08: // selected drive status? |
| 432 | 387 | //logerror("FDC: read from offset 0x08\n"); |
| 433 | | if(towns_selected_drive < 1 || towns_selected_drive > 2) |
| 388 | if(state->towns_selected_drive < 1 || state->towns_selected_drive > 2) |
| 434 | 389 | return 0x01; |
| 435 | 390 | else |
| 436 | 391 | return 0x07; |
| r8380 | r8381 | |
| 445 | 400 | |
| 446 | 401 | static WRITE8_HANDLER(towns_floppy_w) |
| 447 | 402 | { |
| 448 | | running_device* fdc = devtag_get_device(space->machine,"fdc"); |
| 403 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 404 | running_device* fdc = state->fdc; |
| 449 | 405 | |
| 450 | 406 | switch(offset) |
| 451 | 407 | { |
| r8380 | r8381 | |
| 468 | 424 | break; |
| 469 | 425 | case 0x08: |
| 470 | 426 | // bit 5 - CLKSEL |
| 471 | | if(towns_selected_drive != 0 && towns_selected_drive < 2) |
| 427 | if(state->towns_selected_drive != 0 && state->towns_selected_drive < 2) |
| 472 | 428 | { |
| 473 | | floppy_mon_w(floppy_get_device(space->machine, towns_selected_drive-1), !BIT(data, 4)); |
| 474 | | floppy_drive_set_ready_state(floppy_get_device(space->machine, towns_selected_drive-1), data & 0x10,0); |
| 429 | floppy_mon_w(floppy_get_device(space->machine, state->towns_selected_drive-1), !BIT(data, 4)); |
| 430 | floppy_drive_set_ready_state(floppy_get_device(space->machine, state->towns_selected_drive-1), data & 0x10,0); |
| 475 | 431 | } |
| 476 | 432 | wd17xx_set_side(fdc,(data & 0x04)>>2); |
| 477 | 433 | wd17xx_dden_w(fdc, BIT(~data, 1)); |
| 478 | 434 | |
| 479 | | towns_fdc_irq6mask = data & 0x01; |
| 435 | state->towns_fdc_irq6mask = data & 0x01; |
| 480 | 436 | logerror("FDC: write %02x to offset 0x08\n",data); |
| 481 | 437 | break; |
| 482 | 438 | case 0x0c: // drive select |
| 483 | 439 | switch(data & 0x0f) |
| 484 | 440 | { |
| 485 | 441 | case 0x00: |
| 486 | | towns_selected_drive = 0; // No drive selected |
| 442 | state->towns_selected_drive = 0; // No drive selected |
| 487 | 443 | break; |
| 488 | 444 | case 0x01: |
| 489 | | towns_selected_drive = 1; |
| 445 | state->towns_selected_drive = 1; |
| 490 | 446 | wd17xx_set_drive(fdc,0); |
| 491 | 447 | break; |
| 492 | 448 | case 0x02: |
| 493 | | towns_selected_drive = 2; |
| 449 | state->towns_selected_drive = 2; |
| 494 | 450 | wd17xx_set_drive(fdc,1); |
| 495 | 451 | break; |
| 496 | 452 | case 0x04: |
| 497 | | towns_selected_drive = 3; |
| 453 | state->towns_selected_drive = 3; |
| 498 | 454 | wd17xx_set_drive(fdc,2); |
| 499 | 455 | break; |
| 500 | 456 | case 0x08: |
| 501 | | towns_selected_drive = 4; |
| 457 | state->towns_selected_drive = 4; |
| 502 | 458 | wd17xx_set_drive(fdc,3); |
| 503 | 459 | break; |
| 504 | 460 | } |
| r8380 | r8381 | |
| 511 | 467 | |
| 512 | 468 | static UINT16 towns_fdc_dma_r(running_machine* machine) |
| 513 | 469 | { |
| 514 | | running_device* fdc = devtag_get_device(machine,"fdc"); |
| 470 | towns_state* state = (towns_state*)machine->driver_data; |
| 471 | running_device* fdc = state->fdc; |
| 515 | 472 | return wd17xx_data_r(fdc,0); |
| 516 | 473 | } |
| 517 | 474 | |
| 518 | 475 | static void towns_fdc_dma_w(running_machine* machine, UINT16 data) |
| 519 | 476 | { |
| 520 | | running_device* fdc = devtag_get_device(machine,"fdc"); |
| 477 | towns_state* state = (towns_state*)machine->driver_data; |
| 478 | running_device* fdc = state->fdc; |
| 521 | 479 | wd17xx_data_w(fdc,0,data); |
| 522 | 480 | } |
| 523 | 481 | |
| r8380 | r8381 | |
| 539 | 497 | */ |
| 540 | 498 | static void towns_kb_sendcode(running_machine* machine, UINT8 scancode, int release) |
| 541 | 499 | { |
| 542 | | running_device* dev = devtag_get_device(machine,"pic8259_master"); |
| 500 | towns_state* state = (towns_state*)machine->driver_data; |
| 501 | running_device* dev = state->pic_master; |
| 543 | 502 | |
| 544 | 503 | switch(release) |
| 545 | 504 | { |
| 546 | 505 | case 0: // key press |
| 547 | | towns_kb_output = 0x80; |
| 548 | | towns_kb_extend = scancode & 0x7f; |
| 506 | state->towns_kb_output = 0x80; |
| 507 | state->towns_kb_extend = scancode & 0x7f; |
| 549 | 508 | if(input_port_read(machine,"key3") & 0x00080000) |
| 550 | | towns_kb_output |= 0x04; |
| 509 | state->towns_kb_output |= 0x04; |
| 551 | 510 | if(input_port_read(machine,"key3") & 0x00040000) |
| 552 | | towns_kb_output |= 0x08; |
| 511 | state->towns_kb_output |= 0x08; |
| 553 | 512 | if(input_port_read(machine,"key3") & 0x06400000) |
| 554 | | towns_kb_output |= 0x20; |
| 513 | state->towns_kb_output |= 0x20; |
| 555 | 514 | break; |
| 556 | 515 | case 1: // key release |
| 557 | | towns_kb_output = 0x90; |
| 558 | | towns_kb_extend = scancode & 0x7f; |
| 516 | state->towns_kb_output = 0x90; |
| 517 | state->towns_kb_extend = scancode & 0x7f; |
| 559 | 518 | if(input_port_read(machine,"key3") & 0x00080000) |
| 560 | | towns_kb_output |= 0x04; |
| 519 | state->towns_kb_output |= 0x04; |
| 561 | 520 | if(input_port_read(machine,"key3") & 0x00040000) |
| 562 | | towns_kb_output |= 0x08; |
| 521 | state->towns_kb_output |= 0x08; |
| 563 | 522 | if(input_port_read(machine,"key3") & 0x06400000) |
| 564 | | towns_kb_output |= 0x20; |
| 523 | state->towns_kb_output |= 0x20; |
| 565 | 524 | break; |
| 566 | 525 | case 2: // extended byte |
| 567 | | towns_kb_output = scancode; |
| 568 | | towns_kb_extend = 0xff; |
| 526 | state->towns_kb_output = scancode; |
| 527 | state->towns_kb_extend = 0xff; |
| 569 | 528 | break; |
| 570 | 529 | } |
| 571 | | towns_kb_status |= 0x01; |
| 572 | | if(towns_kb_irq1_enable) |
| 530 | state->towns_kb_status |= 0x01; |
| 531 | if(state->towns_kb_irq1_enable) |
| 573 | 532 | { |
| 574 | 533 | pic8259_ir1_w(dev, 1); |
| 575 | 534 | logerror("PIC: IRQ1 (keyboard) set high\n"); |
| r8380 | r8381 | |
| 606 | 565 | |
| 607 | 566 | static READ8_HANDLER(towns_keyboard_r) |
| 608 | 567 | { |
| 568 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 609 | 569 | UINT8 ret = 0x00; |
| 570 | |
| 610 | 571 | switch(offset) |
| 611 | 572 | { |
| 612 | 573 | case 0: // scancode output |
| 613 | | ret = towns_kb_output; |
| 574 | ret = state->towns_kb_output; |
| 614 | 575 | //logerror("KB: read keyboard output port, returning %02x\n",ret); |
| 615 | | pic8259_ir1_w(devtag_get_device(space->machine,"pic8259_master"), 0); |
| 576 | pic8259_ir1_w(state->pic_master, 0); |
| 616 | 577 | logerror("PIC: IRQ1 (keyboard) set low\n"); |
| 617 | | if(towns_kb_extend != 0xff) |
| 578 | if(state->towns_kb_extend != 0xff) |
| 618 | 579 | { |
| 619 | | towns_kb_sendcode(space->machine,towns_kb_extend,2); |
| 580 | towns_kb_sendcode(space->machine,state->towns_kb_extend,2); |
| 620 | 581 | } |
| 621 | 582 | else |
| 622 | | towns_kb_status &= ~0x01; |
| 583 | state->towns_kb_status &= ~0x01; |
| 623 | 584 | return ret; |
| 624 | 585 | case 1: // status |
| 625 | | logerror("KB: read status port, returning %02x\n",towns_kb_status); |
| 626 | | return towns_kb_status; |
| 586 | logerror("KB: read status port, returning %02x\n",state->towns_kb_status); |
| 587 | return state->towns_kb_status; |
| 627 | 588 | default: |
| 628 | 589 | logerror("KB: read offset %02x\n",offset); |
| 629 | 590 | } |
| r8380 | r8381 | |
| 632 | 593 | |
| 633 | 594 | static WRITE8_HANDLER(towns_keyboard_w) |
| 634 | 595 | { |
| 596 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 597 | |
| 635 | 598 | switch(offset) |
| 636 | 599 | { |
| 637 | 600 | case 0: // command input |
| 638 | | towns_kb_status &= ~0x08; |
| 639 | | towns_kb_status |= 0x01; |
| 601 | state->towns_kb_status &= ~0x08; |
| 602 | state->towns_kb_status |= 0x01; |
| 640 | 603 | break; |
| 641 | 604 | case 1: // control |
| 642 | | towns_kb_status |= 0x08; |
| 605 | state->towns_kb_status |= 0x08; |
| 643 | 606 | break; |
| 644 | 607 | case 2: // IRQ1 enable |
| 645 | | towns_kb_irq1_enable = data & 0x01; |
| 608 | state->towns_kb_irq1_enable = data & 0x01; |
| 646 | 609 | break; |
| 647 | 610 | default: |
| 648 | 611 | logerror("KB: wrote 0x%02x to offset %02x\n",data,offset); |
| r8380 | r8381 | |
| 659 | 622 | */ |
| 660 | 623 | static READ8_HANDLER(towns_port60_r) |
| 661 | 624 | { |
| 625 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 662 | 626 | UINT8 val = 0x00; |
| 663 | 627 | |
| 664 | | if ( pit8253_get_output(devtag_get_device(space->machine, "pit"), 0 ) ) |
| 628 | if ( pit8253_get_output(state->pit, 0 ) ) |
| 665 | 629 | val |= 0x01; |
| 666 | | if ( pit8253_get_output(devtag_get_device(space->machine, "pit"), 1 ) ) |
| 630 | if ( pit8253_get_output(state->pit, 1 ) ) |
| 667 | 631 | val |= 0x02; |
| 668 | 632 | |
| 669 | | val |= (towns_timer_mask & 0x07) << 2; |
| 633 | val |= (state->towns_timer_mask & 0x07) << 2; |
| 670 | 634 | |
| 671 | 635 | //logerror("PIT: port 0x60 read, returning 0x%02x\n",val); |
| 672 | 636 | return val; |
| r8380 | r8381 | |
| 674 | 638 | |
| 675 | 639 | static WRITE8_HANDLER(towns_port60_w) |
| 676 | 640 | { |
| 677 | | running_device* dev = devtag_get_device(space->machine,"pic8259_master"); |
| 641 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 642 | running_device* dev = state->pic_master; |
| 678 | 643 | |
| 679 | 644 | if(data & 0x80) |
| 680 | 645 | { |
| 681 | 646 | towns_pic_irq(dev,0); |
| 682 | 647 | } |
| 683 | | towns_timer_mask = data & 0x07; |
| 648 | state->towns_timer_mask = data & 0x07; |
| 684 | 649 | // bit 2 = sound (beeper?) |
| 685 | 650 | //logerror("PIT: wrote 0x%02x to port 0x60\n",data); |
| 686 | 651 | } |
| 687 | 652 | |
| 688 | 653 | static READ32_HANDLER(towns_sys5e8_r) |
| 689 | 654 | { |
| 655 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 656 | |
| 690 | 657 | switch(offset) |
| 691 | 658 | { |
| 692 | 659 | case 0x00: |
| r8380 | r8381 | |
| 700 | 667 | if(ACCESSING_BITS_0_7) |
| 701 | 668 | { |
| 702 | 669 | logerror("SYS: read port 5ec\n"); |
| 703 | | return compat_mode & 0x01; |
| 670 | return state->compat_mode & 0x01; |
| 704 | 671 | } |
| 705 | 672 | break; |
| 706 | 673 | } |
| r8380 | r8381 | |
| 709 | 676 | |
| 710 | 677 | static WRITE32_HANDLER(towns_sys5e8_w) |
| 711 | 678 | { |
| 679 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 680 | |
| 712 | 681 | switch(offset) |
| 713 | 682 | { |
| 714 | 683 | case 0x00: |
| r8380 | r8381 | |
| 721 | 690 | if(ACCESSING_BITS_0_7) |
| 722 | 691 | { |
| 723 | 692 | logerror("SYS: wrote 0x%02x to port 5ec\n",data); |
| 724 | | compat_mode = data & 0x01; |
| 693 | state->compat_mode = data & 0x01; |
| 725 | 694 | } |
| 726 | 695 | break; |
| 727 | 696 | } |
| r8380 | r8381 | |
| 734 | 703 | // W/O -- (0x4ec) LED control |
| 735 | 704 | static READ8_HANDLER(towns_sound_ctrl_r) |
| 736 | 705 | { |
| 706 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 737 | 707 | UINT8 ret = 0; |
| 738 | 708 | |
| 739 | 709 | switch(offset) |
| 740 | 710 | { |
| 741 | 711 | case 0x01: |
| 742 | | if(towns_fm_irq_flag) |
| 712 | if(state->towns_fm_irq_flag) |
| 743 | 713 | ret |= 0x01; |
| 744 | | if(towns_pcm_irq_flag) |
| 714 | if(state->towns_pcm_irq_flag) |
| 745 | 715 | ret |= 0x08; |
| 746 | 716 | break; |
| 747 | 717 | case 0x03: |
| 748 | | ret = towns_pcm_channel_flag; |
| 749 | | towns_pcm_channel_flag = 0; |
| 750 | | towns_pcm_irq_flag = 0; |
| 751 | | pic8259_ir5_w(devtag_get_device(space->machine,"pic8259_slave"), 0); |
| 718 | ret = state->towns_pcm_channel_flag; |
| 719 | state->towns_pcm_channel_flag = 0; |
| 720 | state->towns_pcm_irq_flag = 0; |
| 721 | pic8259_ir5_w(state->pic_slave, 0); |
| 752 | 722 | logerror("PIC: IRQ13 (PCM) set low\n"); |
| 753 | 723 | break; |
| 754 | 724 | default: |
| r8380 | r8381 | |
| 759 | 729 | |
| 760 | 730 | static WRITE8_HANDLER(towns_sound_ctrl_w) |
| 761 | 731 | { |
| 732 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 762 | 733 | switch(offset) |
| 763 | 734 | { |
| 764 | 735 | case 0x02: // PCM channel interrupt mask |
| 765 | | towns_pcm_channel_mask = data; |
| 736 | state->towns_pcm_channel_mask = data; |
| 766 | 737 | break; |
| 767 | 738 | default: |
| 768 | 739 | logerror("FM: unimplemented port 0x%04x write %02x\n",offset + 0x4e8,data); |
| r8380 | r8381 | |
| 773 | 744 | // Joysticks are multiplexed, with fire buttons available when bits 0 and 1 of port 0x4d6 are high. (bits 2 and 3 for second port?) |
| 774 | 745 | static TIMER_CALLBACK(towns_mouse_timeout) |
| 775 | 746 | { |
| 776 | | towns_mouse_output = MOUSE_START; // reset mouse data |
| 747 | towns_state* state = (towns_state*)machine->driver_data; |
| 748 | state->towns_mouse_output = MOUSE_START; // reset mouse data |
| 777 | 749 | } |
| 778 | 750 | |
| 779 | 751 | static READ32_HANDLER(towns_padport_r) |
| 780 | 752 | { |
| 753 | towns_state* tstate = (towns_state*)space->machine->driver_data; |
| 781 | 754 | UINT32 ret = 0; |
| 782 | 755 | UINT32 porttype = input_port_read(space->machine,"ctrltype"); |
| 783 | 756 | UINT8 extra1; |
| r8380 | r8381 | |
| 792 | 765 | { |
| 793 | 766 | extra1 = input_port_read(space->machine,"joy1_ex"); |
| 794 | 767 | |
| 795 | | if(towns_pad_mask & 0x10) |
| 768 | if(tstate->towns_pad_mask & 0x10) |
| 796 | 769 | ret |= (input_port_read(space->machine,"joy1") & 0x3f) | 0x00000040; |
| 797 | 770 | else |
| 798 | 771 | ret |= (input_port_read(space->machine,"joy1") & 0x0f) | 0x00000030; |
| r8380 | r8381 | |
| 802 | 775 | if(extra1 & 0x02) // Select button = up+down |
| 803 | 776 | ret &= ~0x00000003; |
| 804 | 777 | |
| 805 | | if((extra1 & 0x10) && (towns_pad_mask & 0x01)) |
| 778 | if((extra1 & 0x10) && (tstate->towns_pad_mask & 0x01)) |
| 806 | 779 | ret &= ~0x00000010; |
| 807 | | if((extra1 & 0x20) && (towns_pad_mask & 0x02)) |
| 780 | if((extra1 & 0x20) && (tstate->towns_pad_mask & 0x02)) |
| 808 | 781 | ret &= ~0x00000020; |
| 809 | 782 | } |
| 810 | 783 | if((porttype & 0xf0) == 0x10) |
| 811 | 784 | { |
| 812 | 785 | extra2 = input_port_read(space->machine,"joy2_ex"); |
| 813 | 786 | |
| 814 | | if(towns_pad_mask & 0x20) |
| 787 | if(tstate->towns_pad_mask & 0x20) |
| 815 | 788 | ret |= ((input_port_read(space->machine,"joy2") & 0x3f) << 16) | 0x00400000; |
| 816 | 789 | else |
| 817 | 790 | ret |= ((input_port_read(space->machine,"joy2") & 0x0f) << 16) | 0x00300000; |
| r8380 | r8381 | |
| 821 | 794 | if(extra2 & 0x02) |
| 822 | 795 | ret &= ~0x00030000; |
| 823 | 796 | |
| 824 | | if((extra2 & 0x10) && (towns_pad_mask & 0x04)) |
| 797 | if((extra2 & 0x10) && (tstate->towns_pad_mask & 0x04)) |
| 825 | 798 | ret &= ~0x00100000; |
| 826 | | if((extra2 & 0x20) && (towns_pad_mask & 0x08)) |
| 799 | if((extra2 & 0x20) && (tstate->towns_pad_mask & 0x08)) |
| 827 | 800 | ret &= ~0x00200000; |
| 828 | 801 | } |
| 829 | 802 | if((porttype & 0x0f) == 0x02) // mouse |
| 830 | 803 | { |
| 831 | | switch(towns_mouse_output) |
| 804 | switch(tstate->towns_mouse_output) |
| 832 | 805 | { |
| 833 | 806 | case MOUSE_X_HIGH: |
| 834 | | ret |= ((towns_mouse_x & 0xf0) >> 4); |
| 807 | ret |= ((tstate->towns_mouse_x & 0xf0) >> 4); |
| 835 | 808 | break; |
| 836 | 809 | case MOUSE_X_LOW: |
| 837 | | ret |= (towns_mouse_x & 0x0f); |
| 810 | ret |= (tstate->towns_mouse_x & 0x0f); |
| 838 | 811 | break; |
| 839 | 812 | case MOUSE_Y_HIGH: |
| 840 | | ret |= ((towns_mouse_y & 0xf0) >> 4); |
| 813 | ret |= ((tstate->towns_mouse_y & 0xf0) >> 4); |
| 841 | 814 | break; |
| 842 | 815 | case MOUSE_Y_LOW: |
| 843 | | ret |= (towns_mouse_y & 0x0f); |
| 816 | ret |= (tstate->towns_mouse_y & 0x0f); |
| 844 | 817 | break; |
| 845 | 818 | case MOUSE_START: |
| 846 | 819 | case MOUSE_SYNC: |
| 847 | 820 | default: |
| 848 | | if(towns_mouse_output < MOUSE_Y_LOW) |
| 821 | if(tstate->towns_mouse_output < MOUSE_Y_LOW) |
| 849 | 822 | ret |= 0x0000000f; |
| 850 | 823 | } |
| 851 | 824 | |
| r8380 | r8381 | |
| 855 | 828 | ret |= 0x00000010; |
| 856 | 829 | if(!(state & 0x02)) |
| 857 | 830 | ret |= 0x00000020; |
| 858 | | if(towns_pad_mask & 0x10) |
| 831 | if(tstate->towns_pad_mask & 0x10) |
| 859 | 832 | ret |= 0x00000040; |
| 860 | 833 | } |
| 861 | 834 | if((porttype & 0xf0) == 0x20) // mouse |
| 862 | 835 | { |
| 863 | | switch(towns_mouse_output) |
| 836 | switch(tstate->towns_mouse_output) |
| 864 | 837 | { |
| 865 | 838 | case MOUSE_X_HIGH: |
| 866 | | ret |= ((towns_mouse_x & 0xf0) << 12); |
| 839 | ret |= ((tstate->towns_mouse_x & 0xf0) << 12); |
| 867 | 840 | break; |
| 868 | 841 | case MOUSE_X_LOW: |
| 869 | | ret |= ((towns_mouse_x & 0x0f) << 16); |
| 842 | ret |= ((tstate->towns_mouse_x & 0x0f) << 16); |
| 870 | 843 | break; |
| 871 | 844 | case MOUSE_Y_HIGH: |
| 872 | | ret |= ((towns_mouse_y & 0xf0) << 12); |
| 845 | ret |= ((tstate->towns_mouse_y & 0xf0) << 12); |
| 873 | 846 | break; |
| 874 | 847 | case MOUSE_Y_LOW: |
| 875 | | ret |= ((towns_mouse_y & 0x0f) << 16); |
| 848 | ret |= ((tstate->towns_mouse_y & 0x0f) << 16); |
| 876 | 849 | break; |
| 877 | 850 | case MOUSE_START: |
| 878 | 851 | case MOUSE_SYNC: |
| 879 | 852 | default: |
| 880 | | if(towns_mouse_output < MOUSE_Y_LOW) |
| 853 | if(tstate->towns_mouse_output < MOUSE_Y_LOW) |
| 881 | 854 | ret |= 0x000f0000; |
| 882 | 855 | } |
| 883 | 856 | |
| r8380 | r8381 | |
| 887 | 860 | ret |= 0x00100000; |
| 888 | 861 | if(!(state & 0x02)) |
| 889 | 862 | ret |= 0x00200000; |
| 890 | | if(towns_pad_mask & 0x20) |
| 863 | if(tstate->towns_pad_mask & 0x20) |
| 891 | 864 | ret |= 0x00400000; |
| 892 | 865 | } |
| 893 | 866 | |
| r8380 | r8381 | |
| 896 | 869 | |
| 897 | 870 | static WRITE32_HANDLER(towns_pad_mask_w) |
| 898 | 871 | { |
| 872 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 899 | 873 | static UINT8 prev; |
| 900 | 874 | static UINT8 prev_x,prev_y; |
| 901 | 875 | UINT8 current_x,current_y; |
| r8380 | r8381 | |
| 903 | 877 | |
| 904 | 878 | if(ACCESSING_BITS_16_23) |
| 905 | 879 | { |
| 906 | | towns_pad_mask = (data & 0x00ff0000) >> 16; |
| 880 | state->towns_pad_mask = (data & 0x00ff0000) >> 16; |
| 907 | 881 | if((type & 0x0f) == 0x02) // mouse |
| 908 | 882 | { |
| 909 | | if((towns_pad_mask & 0x10) != 0 && (prev & 0x10) == 0) |
| 883 | if((state->towns_pad_mask & 0x10) != 0 && (prev & 0x10) == 0) |
| 910 | 884 | { |
| 911 | | if(towns_mouse_output == MOUSE_START) |
| 885 | if(state->towns_mouse_output == MOUSE_START) |
| 912 | 886 | { |
| 913 | | towns_mouse_output = MOUSE_X_HIGH; |
| 887 | state->towns_mouse_output = MOUSE_X_HIGH; |
| 914 | 888 | current_x = input_port_read(space->machine,"mouse2"); |
| 915 | 889 | current_y = input_port_read(space->machine,"mouse3"); |
| 916 | | towns_mouse_x = prev_x - current_x; |
| 917 | | towns_mouse_y = prev_y - current_y; |
| 890 | state->towns_mouse_x = prev_x - current_x; |
| 891 | state->towns_mouse_y = prev_y - current_y; |
| 918 | 892 | prev_x = current_x; |
| 919 | 893 | prev_y = current_y; |
| 920 | 894 | } |
| 921 | 895 | else |
| 922 | | towns_mouse_output++; |
| 923 | | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 896 | state->towns_mouse_output++; |
| 897 | timer_adjust_periodic(state->towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 924 | 898 | } |
| 925 | | if((towns_pad_mask & 0x10) == 0 && (prev & 0x10) != 0) |
| 899 | if((state->towns_pad_mask & 0x10) == 0 && (prev & 0x10) != 0) |
| 926 | 900 | { |
| 927 | | if(towns_mouse_output == MOUSE_START) |
| 901 | if(state->towns_mouse_output == MOUSE_START) |
| 928 | 902 | { |
| 929 | | towns_mouse_output = MOUSE_SYNC; |
| 903 | state->towns_mouse_output = MOUSE_SYNC; |
| 930 | 904 | current_x = input_port_read(space->machine,"mouse2"); |
| 931 | 905 | current_y = input_port_read(space->machine,"mouse3"); |
| 932 | | towns_mouse_x = prev_x - current_x; |
| 933 | | towns_mouse_y = prev_y - current_y; |
| 906 | state->towns_mouse_x = prev_x - current_x; |
| 907 | state->towns_mouse_y = prev_y - current_y; |
| 934 | 908 | prev_x = current_x; |
| 935 | 909 | prev_y = current_y; |
| 936 | 910 | } |
| 937 | 911 | else |
| 938 | | towns_mouse_output++; |
| 939 | | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 912 | state->towns_mouse_output++; |
| 913 | timer_adjust_periodic(state->towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 940 | 914 | } |
| 941 | | prev = towns_pad_mask; |
| 915 | prev = state->towns_pad_mask; |
| 942 | 916 | } |
| 943 | 917 | if((type & 0xf0) == 0x20) // mouse |
| 944 | 918 | { |
| 945 | | if((towns_pad_mask & 0x20) != 0 && (prev & 0x20) == 0) |
| 919 | if((state->towns_pad_mask & 0x20) != 0 && (prev & 0x20) == 0) |
| 946 | 920 | { |
| 947 | | if(towns_mouse_output == MOUSE_START) |
| 921 | if(state->towns_mouse_output == MOUSE_START) |
| 948 | 922 | { |
| 949 | | towns_mouse_output = MOUSE_X_HIGH; |
| 923 | state->towns_mouse_output = MOUSE_X_HIGH; |
| 950 | 924 | current_x = input_port_read(space->machine,"mouse2"); |
| 951 | 925 | current_y = input_port_read(space->machine,"mouse3"); |
| 952 | | towns_mouse_x = prev_x - current_x; |
| 953 | | towns_mouse_y = prev_y - current_y; |
| 926 | state->towns_mouse_x = prev_x - current_x; |
| 927 | state->towns_mouse_y = prev_y - current_y; |
| 954 | 928 | prev_x = current_x; |
| 955 | 929 | prev_y = current_y; |
| 956 | 930 | } |
| 957 | 931 | else |
| 958 | | towns_mouse_output++; |
| 959 | | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 932 | state->towns_mouse_output++; |
| 933 | timer_adjust_periodic(state->towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 960 | 934 | } |
| 961 | | if((towns_pad_mask & 0x20) == 0 && (prev & 0x20) != 0) |
| 935 | if((state->towns_pad_mask & 0x20) == 0 && (prev & 0x20) != 0) |
| 962 | 936 | { |
| 963 | | if(towns_mouse_output == MOUSE_START) |
| 937 | if(state->towns_mouse_output == MOUSE_START) |
| 964 | 938 | { |
| 965 | | towns_mouse_output = MOUSE_SYNC; |
| 939 | state->towns_mouse_output = MOUSE_SYNC; |
| 966 | 940 | current_x = input_port_read(space->machine,"mouse2"); |
| 967 | 941 | current_y = input_port_read(space->machine,"mouse3"); |
| 968 | | towns_mouse_x = prev_x - current_x; |
| 969 | | towns_mouse_y = prev_y - current_y; |
| 942 | state->towns_mouse_x = prev_x - current_x; |
| 943 | state->towns_mouse_y = prev_y - current_y; |
| 970 | 944 | prev_x = current_x; |
| 971 | 945 | prev_y = current_y; |
| 972 | 946 | } |
| 973 | 947 | else |
| 974 | | towns_mouse_output++; |
| 975 | | timer_adjust_periodic(towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 948 | state->towns_mouse_output++; |
| 949 | timer_adjust_periodic(state->towns_mouse_timer,ATTOTIME_IN_USEC(600),0,attotime_zero); |
| 976 | 950 | } |
| 977 | | prev = towns_pad_mask; |
| 951 | prev = state->towns_pad_mask; |
| 978 | 952 | } |
| 979 | 953 | } |
| 980 | 954 | } |
| 981 | 955 | |
| 982 | 956 | static READ8_HANDLER( towns_cmos8_r ) |
| 983 | 957 | { |
| 984 | | return towns_cmos[offset]; |
| 958 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 959 | return state->towns_cmos[offset]; |
| 985 | 960 | } |
| 986 | 961 | |
| 987 | 962 | static WRITE8_HANDLER( towns_cmos8_w ) |
| 988 | 963 | { |
| 989 | | towns_cmos[offset] = data; |
| 964 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 965 | state->towns_cmos[offset] = data; |
| 990 | 966 | } |
| 991 | 967 | |
| 992 | 968 | static READ8_HANDLER( towns_cmos_low_r ) |
| 993 | 969 | { |
| 994 | | if(towns_mainmem_enable != 0) |
| 995 | | return messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset + 0xd8000]; |
| 970 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 971 | if(state->towns_mainmem_enable != 0) |
| 972 | return messram_get_ptr(state->messram)[offset + 0xd8000]; |
| 996 | 973 | |
| 997 | | return towns_cmos[offset]; |
| 974 | return state->towns_cmos[offset]; |
| 998 | 975 | } |
| 999 | 976 | |
| 1000 | 977 | static WRITE8_HANDLER( towns_cmos_low_w ) |
| 1001 | 978 | { |
| 1002 | | if(towns_mainmem_enable != 0) |
| 1003 | | messram_get_ptr(devtag_get_device(space->machine, "messram"))[offset+0xd8000] = data; |
| 979 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 980 | if(state->towns_mainmem_enable != 0) |
| 981 | messram_get_ptr(state->messram)[offset+0xd8000] = data; |
| 1004 | 982 | else |
| 1005 | | towns_cmos[offset] = data; |
| 983 | state->towns_cmos[offset] = data; |
| 1006 | 984 | } |
| 1007 | 985 | |
| 1008 | 986 | static READ8_HANDLER( towns_cmos_r ) |
| 1009 | 987 | { |
| 1010 | | return towns_cmos[offset]; |
| 988 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 989 | return state->towns_cmos[offset]; |
| 1011 | 990 | } |
| 1012 | 991 | |
| 1013 | 992 | static WRITE8_HANDLER( towns_cmos_w ) |
| 1014 | 993 | { |
| 1015 | | towns_cmos[offset] = data; |
| 994 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 995 | state->towns_cmos[offset] = data; |
| 1016 | 996 | } |
| 1017 | 997 | |
| 1018 | 998 | void towns_update_video_banks(const address_space* space) |
| 1019 | 999 | { |
| 1000 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1020 | 1001 | UINT8* ROM; |
| 1021 | 1002 | |
| 1022 | | if(towns_mainmem_enable != 0) // first MB is RAM |
| 1003 | if(state->towns_mainmem_enable != 0) // first MB is RAM |
| 1023 | 1004 | { |
| 1024 | 1005 | ROM = memory_region(space->machine,"user"); |
| 1025 | 1006 | |
| 1026 | | // memory_set_bankptr(space->machine,1,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xc0000); |
| 1027 | | // memory_set_bankptr(space->machine,2,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xc8000); |
| 1028 | | // memory_set_bankptr(space->machine,3,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xc9000); |
| 1029 | | // memory_set_bankptr(space->machine,4,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xca000); |
| 1030 | | // memory_set_bankptr(space->machine,5,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xca000); |
| 1031 | | // memory_set_bankptr(space->machine,10,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xca800); |
| 1032 | | memory_set_bankptr(space->machine,"bank6",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xcb000); |
| 1033 | | memory_set_bankptr(space->machine,"bank7",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xcb000); |
| 1034 | | if(towns_system_port & 0x02) |
| 1035 | | memory_set_bankptr(space->machine,"bank11",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xf8000); |
| 1007 | // memory_set_bankptr(space->machine,1,messram_get_ptr(state->messram)+0xc0000); |
| 1008 | // memory_set_bankptr(space->machine,2,messram_get_ptr(state->messram)+0xc8000); |
| 1009 | // memory_set_bankptr(space->machine,3,messram_get_ptr(state->messram)+0xc9000); |
| 1010 | // memory_set_bankptr(space->machine,4,messram_get_ptr(state->messram)+0xca000); |
| 1011 | // memory_set_bankptr(space->machine,5,messram_get_ptr(state->messram)+0xca000); |
| 1012 | // memory_set_bankptr(space->machine,10,messram_get_ptr(state->messram)+0xca800); |
| 1013 | memory_set_bankptr(space->machine,"bank6",messram_get_ptr(state->messram)+0xcb000); |
| 1014 | memory_set_bankptr(space->machine,"bank7",messram_get_ptr(state->messram)+0xcb000); |
| 1015 | if(state->towns_system_port & 0x02) |
| 1016 | memory_set_bankptr(space->machine,"bank11",messram_get_ptr(state->messram)+0xf8000); |
| 1036 | 1017 | else |
| 1037 | 1018 | memory_set_bankptr(space->machine,"bank11",ROM+0x238000); |
| 1038 | | memory_set_bankptr(space->machine,"bank12",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xf8000); |
| 1019 | memory_set_bankptr(space->machine,"bank12",messram_get_ptr(state->messram)+0xf8000); |
| 1039 | 1020 | return; |
| 1040 | 1021 | } |
| 1041 | 1022 | else // enable I/O ports and VRAM |
| r8380 | r8381 | |
| 1044 | 1025 | |
| 1045 | 1026 | // memory_set_bankptr(space->machine,1,towns_gfxvram+(towns_vram_rplane*0x8000)); |
| 1046 | 1027 | // memory_set_bankptr(space->machine,2,towns_txtvram); |
| 1047 | | // memory_set_bankptr(space->machine,3,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xc9000); |
| 1028 | // memory_set_bankptr(space->machine,3,messram_get_ptr(state->messram)+0xc9000); |
| 1048 | 1029 | // if(towns_ankcg_enable != 0) |
| 1049 | 1030 | // memory_set_bankptr(space->machine,4,ROM+0x180000+0x3d000); // ANK CG 8x8 |
| 1050 | 1031 | // else |
| 1051 | 1032 | // memory_set_bankptr(space->machine,4,towns_txtvram+0x2000); |
| 1052 | 1033 | // memory_set_bankptr(space->machine,5,towns_txtvram+0x2000); |
| 1053 | | // memory_set_bankptr(space->machine,10,messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xca800); |
| 1054 | | if(towns_ankcg_enable != 0) |
| 1034 | // memory_set_bankptr(space->machine,10,messram_get_ptr(state->messram)+0xca800); |
| 1035 | if(state->towns_ankcg_enable != 0) |
| 1055 | 1036 | memory_set_bankptr(space->machine,"bank6",ROM+0x180000+0x3d800); // ANK CG 8x16 |
| 1056 | 1037 | else |
| 1057 | | memory_set_bankptr(space->machine,"bank6",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xcb000); |
| 1058 | | memory_set_bankptr(space->machine,"bank7",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xcb000); |
| 1059 | | if(towns_system_port & 0x02) |
| 1060 | | memory_set_bankptr(space->machine,"bank11",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xf8000); |
| 1038 | memory_set_bankptr(space->machine,"bank6",messram_get_ptr(state->messram)+0xcb000); |
| 1039 | memory_set_bankptr(space->machine,"bank7",messram_get_ptr(state->messram)+0xcb000); |
| 1040 | if(state->towns_system_port & 0x02) |
| 1041 | memory_set_bankptr(space->machine,"bank11",messram_get_ptr(state->messram)+0xf8000); |
| 1061 | 1042 | else |
| 1062 | 1043 | memory_set_bankptr(space->machine,"bank11",ROM+0x238000); |
| 1063 | | memory_set_bankptr(space->machine,"bank12",messram_get_ptr(devtag_get_device(space->machine, "messram"))+0xf8000); |
| 1044 | memory_set_bankptr(space->machine,"bank12",messram_get_ptr(state->messram)+0xf8000); |
| 1064 | 1045 | return; |
| 1065 | 1046 | } |
| 1066 | 1047 | } |
| 1067 | 1048 | |
| 1068 | 1049 | static READ8_HANDLER( towns_sys480_r ) |
| 1069 | 1050 | { |
| 1070 | | if(towns_system_port & 0x02) |
| 1051 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1052 | if(state->towns_system_port & 0x02) |
| 1071 | 1053 | return 0x02; |
| 1072 | 1054 | else |
| 1073 | 1055 | return 0x00; |
| r8380 | r8381 | |
| 1075 | 1057 | |
| 1076 | 1058 | static WRITE8_HANDLER( towns_sys480_w ) |
| 1077 | 1059 | { |
| 1078 | | towns_system_port = data; |
| 1079 | | towns_ram_enable = data & 0x02; |
| 1060 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1061 | |
| 1062 | state->towns_system_port = data; |
| 1063 | state->towns_ram_enable = data & 0x02; |
| 1080 | 1064 | towns_update_video_banks(space); |
| 1081 | 1065 | } |
| 1082 | 1066 | |
| 1083 | 1067 | static WRITE32_HANDLER( towns_video_404_w ) |
| 1084 | 1068 | { |
| 1069 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1085 | 1070 | if(ACCESSING_BITS_0_7) |
| 1086 | 1071 | { |
| 1087 | | towns_mainmem_enable = data & 0x80; |
| 1072 | state->towns_mainmem_enable = data & 0x80; |
| 1088 | 1073 | towns_update_video_banks(space); |
| 1074 | logerror("mainmem_enable - set to 0x%02x\n",state->towns_mainmem_enable); |
| 1089 | 1075 | } |
| 1090 | 1076 | } |
| 1091 | 1077 | |
| 1092 | 1078 | static READ32_HANDLER( towns_video_404_r ) |
| 1093 | 1079 | { |
| 1080 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1094 | 1081 | if(ACCESSING_BITS_0_7) |
| 1095 | 1082 | { |
| 1096 | | if(towns_mainmem_enable != 0) |
| 1083 | logerror("mainmem_enable - reading 0x%02x\n",state->towns_mainmem_enable); |
| 1084 | if(state->towns_mainmem_enable != 0) |
| 1097 | 1085 | return 0x00000080; |
| 1098 | 1086 | } |
| 1099 | 1087 | return 0; |
| r8380 | r8381 | |
| 1138 | 1126 | */ |
| 1139 | 1127 | static void towns_cdrom_set_irq(running_machine* machine,int line,int state) |
| 1140 | 1128 | { |
| 1129 | towns_state* tstate = (towns_state*)machine->driver_data; |
| 1141 | 1130 | switch(line) |
| 1142 | 1131 | { |
| 1143 | 1132 | case TOWNS_CD_IRQ_MPU: |
| 1144 | 1133 | if(state != 0) |
| 1145 | 1134 | { |
| 1146 | | if(towns_cd.command & 0x40) |
| 1135 | if(tstate->towns_cd.command & 0x40) |
| 1147 | 1136 | { |
| 1148 | | towns_cd.status |= 0x80; |
| 1149 | | if(towns_cd.mpu_irq_enable) |
| 1137 | tstate->towns_cd.status |= 0x80; |
| 1138 | if(tstate->towns_cd.mpu_irq_enable) |
| 1150 | 1139 | { |
| 1151 | | pic8259_ir1_w(devtag_get_device(machine,"pic8259_slave"), 1); |
| 1140 | pic8259_ir1_w(tstate->pic_slave, 1); |
| 1152 | 1141 | logerror("PIC: IRQ9 (CD-ROM) set high\n"); |
| 1153 | 1142 | } |
| 1154 | 1143 | } |
| 1155 | 1144 | } |
| 1156 | 1145 | else |
| 1157 | 1146 | { |
| 1158 | | towns_cd.status &= ~0x80; |
| 1159 | | pic8259_ir1_w(devtag_get_device(machine,"pic8259_slave"), 0); |
| 1147 | tstate->towns_cd.status &= ~0x80; |
| 1148 | pic8259_ir1_w(tstate->pic_slave, 0); |
| 1160 | 1149 | logerror("PIC: IRQ9 (CD-ROM) set low\n"); |
| 1161 | 1150 | } |
| 1162 | 1151 | break; |
| 1163 | 1152 | case TOWNS_CD_IRQ_DMA: |
| 1164 | 1153 | if(state != 0) |
| 1165 | 1154 | { |
| 1166 | | if(towns_cd.command & 0x40) |
| 1155 | if(tstate->towns_cd.command & 0x40) |
| 1167 | 1156 | { |
| 1168 | | towns_cd.status |= 0x40; |
| 1169 | | if(towns_cd.dma_irq_enable) |
| 1157 | tstate->towns_cd.status |= 0x40; |
| 1158 | if(tstate->towns_cd.dma_irq_enable) |
| 1170 | 1159 | { |
| 1171 | | pic8259_ir1_w(devtag_get_device(machine,"pic8259_slave"), 1); |
| 1160 | pic8259_ir1_w(tstate->pic_slave, 1); |
| 1172 | 1161 | logerror("PIC: IRQ9 (CD-ROM DMA) set high\n"); |
| 1173 | 1162 | } |
| 1174 | 1163 | } |
| 1175 | 1164 | } |
| 1176 | 1165 | else |
| 1177 | 1166 | { |
| 1178 | | towns_cd.status &= ~0x40; |
| 1179 | | pic8259_ir1_w(devtag_get_device(machine,"pic8259_slave"), 0); |
| 1167 | tstate->towns_cd.status &= ~0x40; |
| 1168 | pic8259_ir1_w(tstate->pic_slave, 0); |
| 1180 | 1169 | logerror("PIC: IRQ9 (CD-ROM DMA) set low\n"); |
| 1181 | 1170 | } |
| 1182 | 1171 | break; |
| r8380 | r8381 | |
| 1185 | 1174 | |
| 1186 | 1175 | static TIMER_CALLBACK( towns_cd_status_ready ) |
| 1187 | 1176 | { |
| 1188 | | towns_cd.status |= 0x02; // status read request |
| 1189 | | towns_cd.status |= 0x01; // ready |
| 1190 | | towns_cd.cmd_status_ptr = 0; |
| 1177 | towns_state* state = (towns_state*)machine->driver_data; |
| 1178 | state->towns_cd.status |= 0x02; // status read request |
| 1179 | state->towns_cd.status |= 0x01; // ready |
| 1180 | state->towns_cd.cmd_status_ptr = 0; |
| 1191 | 1181 | towns_cdrom_set_irq((running_machine*)ptr,TOWNS_CD_IRQ_MPU,1); |
| 1192 | 1182 | } |
| 1193 | 1183 | |
| 1194 | 1184 | static void towns_cd_set_status(running_machine* machine, UINT8 st0, UINT8 st1, UINT8 st2, UINT8 st3) |
| 1195 | 1185 | { |
| 1196 | | towns_cd.cmd_status[0] = st0; |
| 1197 | | towns_cd.cmd_status[1] = st1; |
| 1198 | | towns_cd.cmd_status[2] = st2; |
| 1199 | | towns_cd.cmd_status[3] = st3; |
| 1186 | towns_state* state = (towns_state*)machine->driver_data; |
| 1187 | state->towns_cd.cmd_status[0] = st0; |
| 1188 | state->towns_cd.cmd_status[1] = st1; |
| 1189 | state->towns_cd.cmd_status[2] = st2; |
| 1190 | state->towns_cd.cmd_status[3] = st3; |
| 1200 | 1191 | // wait a bit |
| 1201 | 1192 | timer_set(machine,ATTOTIME_IN_MSEC(1),machine,0,towns_cd_status_ready); |
| 1202 | 1193 | } |
| 1203 | 1194 | |
| 1204 | 1195 | static UINT8 towns_cd_get_track(running_machine* machine) |
| 1205 | 1196 | { |
| 1206 | | running_device* cdrom = devtag_get_device(machine,"cdrom"); |
| 1207 | | running_device* cdda = devtag_get_device(machine,"cdda"); |
| 1197 | towns_state* state = (towns_state*)machine->driver_data; |
| 1198 | running_device* cdrom = state->cdrom; |
| 1199 | running_device* cdda = state->cdda; |
| 1208 | 1200 | UINT32 lba = cdda_get_audio_lba(cdda); |
| 1209 | 1201 | UINT8 track; |
| 1210 | 1202 | |
| r8380 | r8381 | |
| 1219 | 1211 | static TIMER_CALLBACK( towns_cdrom_read_byte ) |
| 1220 | 1212 | { |
| 1221 | 1213 | running_device* device = (running_device* )ptr; |
| 1214 | towns_state* state = (towns_state*)machine->driver_data; |
| 1222 | 1215 | int masked; |
| 1223 | 1216 | // TODO: support software transfers, for now DMA is assumed. |
| 1224 | 1217 | |
| 1225 | | if(towns_cd.buffer_ptr < 0) // transfer has ended |
| 1218 | if(state->towns_cd.buffer_ptr < 0) // transfer has ended |
| 1226 | 1219 | return; |
| 1227 | 1220 | |
| 1228 | 1221 | masked = upd71071_dmarq(device,param,3); // CD-ROM controller uses DMA1 channel 3 |
| 1229 | | // logerror("DMARQ: param=%i ret=%i bufferptr=%i\n",param,masked,towns_cd.buffer_ptr); |
| 1222 | // logerror("DMARQ: param=%i ret=%i bufferptr=%i\n",param,masked,state->towns_cd.buffer_ptr); |
| 1230 | 1223 | if(param != 0) |
| 1231 | 1224 | { |
| 1232 | | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),0); |
| 1225 | timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),0); |
| 1233 | 1226 | } |
| 1234 | 1227 | else |
| 1235 | 1228 | { |
| 1236 | 1229 | if(masked != 0) // check if the DMA channel is masked |
| 1237 | 1230 | { |
| 1238 | | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1231 | timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1239 | 1232 | return; |
| 1240 | 1233 | } |
| 1241 | | if(towns_cd.buffer_ptr < 2048) |
| 1242 | | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1234 | if(state->towns_cd.buffer_ptr < 2048) |
| 1235 | timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1243 | 1236 | else |
| 1244 | 1237 | { // end of transfer |
| 1245 | | towns_cd.status &= ~0x10; // no longer transferring by DMA |
| 1246 | | towns_cd.status &= ~0x20; // no longer transferring by software |
| 1247 | | logerror("DMA1: end of transfer (LBA=%08x)\n",towns_cd.lba_current); |
| 1248 | | if(towns_cd.lba_current >= towns_cd.lba_last) |
| 1238 | state->towns_cd.status &= ~0x10; // no longer transferring by DMA |
| 1239 | state->towns_cd.status &= ~0x20; // no longer transferring by software |
| 1240 | logerror("DMA1: end of transfer (LBA=%08x)\n",state->towns_cd.lba_current); |
| 1241 | if(state->towns_cd.lba_current >= state->towns_cd.lba_last) |
| 1249 | 1242 | { |
| 1250 | | towns_cd.extra_status = 0; |
| 1243 | state->towns_cd.extra_status = 0; |
| 1251 | 1244 | towns_cd_set_status(device->machine,0x06,0x00,0x00,0x00); |
| 1252 | 1245 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_DMA,1); |
| 1253 | | towns_cd.buffer_ptr = -1; |
| 1254 | | towns_cd.status |= 0x01; // ready |
| 1246 | state->towns_cd.buffer_ptr = -1; |
| 1247 | state->towns_cd.status |= 0x01; // ready |
| 1255 | 1248 | } |
| 1256 | 1249 | else |
| 1257 | 1250 | { |
| 1258 | | towns_cd.extra_status = 0; |
| 1251 | state->towns_cd.extra_status = 0; |
| 1259 | 1252 | towns_cd_set_status(device->machine,0x22,0x00,0x00,0x00); |
| 1260 | 1253 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_DMA,1); |
| 1261 | | cdrom_read_data(mess_cd_get_cdrom_file(devtag_get_device(device->machine,"cdrom")),++towns_cd.lba_current,towns_cd.buffer,CD_TRACK_MODE1); |
| 1262 | | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1263 | | towns_cd.buffer_ptr = -1; |
| 1254 | cdrom_read_data(mess_cd_get_cdrom_file(state->cdrom),++state->towns_cd.lba_current,state->towns_cd.buffer,CD_TRACK_MODE1); |
| 1255 | timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1256 | state->towns_cd.buffer_ptr = -1; |
| 1264 | 1257 | } |
| 1265 | 1258 | } |
| 1266 | 1259 | } |
| r8380 | r8381 | |
| 1275 | 1268 | // parameters: |
| 1276 | 1269 | // 3 bytes: MSF of first sector to read |
| 1277 | 1270 | // 3 bytes: MSF of last sector to read |
| 1271 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1278 | 1272 | UINT32 lba1,lba2,track; |
| 1279 | 1273 | |
| 1280 | | lba1 = towns_cd.parameter[7] << 16; |
| 1281 | | lba1 += towns_cd.parameter[6] << 8; |
| 1282 | | lba1 += towns_cd.parameter[5]; |
| 1283 | | lba2 = towns_cd.parameter[4] << 16; |
| 1284 | | lba2 += towns_cd.parameter[3] << 8; |
| 1285 | | lba2 += towns_cd.parameter[2]; |
| 1286 | | towns_cd.lba_current = msf_to_lba(lba1); |
| 1287 | | towns_cd.lba_last = msf_to_lba(lba2); |
| 1274 | lba1 = state->towns_cd.parameter[7] << 16; |
| 1275 | lba1 += state->towns_cd.parameter[6] << 8; |
| 1276 | lba1 += state->towns_cd.parameter[5]; |
| 1277 | lba2 = state->towns_cd.parameter[4] << 16; |
| 1278 | lba2 += state->towns_cd.parameter[3] << 8; |
| 1279 | lba2 += state->towns_cd.parameter[2]; |
| 1280 | state->towns_cd.lba_current = msf_to_lba(lba1); |
| 1281 | state->towns_cd.lba_last = msf_to_lba(lba2); |
| 1288 | 1282 | |
| 1289 | 1283 | // first track starts at 00:02:00 - this is hardcoded in the boot procedure |
| 1290 | | track = cdrom_get_track(mess_cd_get_cdrom_file(device),towns_cd.lba_current); |
| 1284 | track = cdrom_get_track(mess_cd_get_cdrom_file(device),state->towns_cd.lba_current); |
| 1291 | 1285 | if(track < 2) |
| 1292 | 1286 | { // recalculate LBA |
| 1293 | | towns_cd.lba_current -= 150; |
| 1294 | | towns_cd.lba_last -= 150; |
| 1287 | state->towns_cd.lba_current -= 150; |
| 1288 | state->towns_cd.lba_last -= 150; |
| 1295 | 1289 | } |
| 1296 | 1290 | |
| 1297 | | logerror("CD: Mode 1 read from LBA next:%i last:%i track:%i\n",towns_cd.lba_current,towns_cd.lba_last,track); |
| 1291 | logerror("CD: Mode 1 read from LBA next:%i last:%i track:%i\n",state->towns_cd.lba_current,state->towns_cd.lba_last,track); |
| 1298 | 1292 | |
| 1299 | | if(towns_cd.lba_current > towns_cd.lba_last) |
| 1293 | if(state->towns_cd.lba_current > state->towns_cd.lba_last) |
| 1300 | 1294 | { |
| 1301 | | towns_cd.extra_status = 0; |
| 1295 | state->towns_cd.extra_status = 0; |
| 1302 | 1296 | towns_cd_set_status(device->machine,0x01,0x00,0x00,0x00); |
| 1303 | 1297 | } |
| 1304 | 1298 | else |
| 1305 | 1299 | { |
| 1306 | | cdrom_read_data(mess_cd_get_cdrom_file(device),towns_cd.lba_current,towns_cd.buffer,CD_TRACK_MODE1); |
| 1307 | | towns_cd.status |= 0x10; // DMA transfer begin |
| 1308 | | towns_cd.status &= ~0x20; // not a software transfer |
| 1309 | | // towns_cd.buffer_ptr = 0; |
| 1310 | | // timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1311 | | towns_cd.extra_status = 2; |
| 1300 | cdrom_read_data(mess_cd_get_cdrom_file(device),state->towns_cd.lba_current,state->towns_cd.buffer,CD_TRACK_MODE1); |
| 1301 | state->towns_cd.status |= 0x10; // DMA transfer begin |
| 1302 | state->towns_cd.status &= ~0x20; // not a software transfer |
| 1303 | // state->towns_cd.buffer_ptr = 0; |
| 1304 | // timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1305 | state->towns_cd.extra_status = 2; |
| 1312 | 1306 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1313 | 1307 | } |
| 1314 | 1308 | } |
| r8380 | r8381 | |
| 1320 | 1314 | // Parameters: |
| 1321 | 1315 | // 3 bytes: starting MSF of audio to play |
| 1322 | 1316 | // 3 bytes: ending MSF of audio to play (can span multiple tracks) |
| 1317 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1323 | 1318 | UINT32 lba1,lba2; |
| 1324 | | running_device* cdda = devtag_get_device(device->machine,"cdda"); |
| 1319 | running_device* cdda = state->cdda; |
| 1325 | 1320 | |
| 1326 | | lba1 = towns_cd.parameter[7] << 16; |
| 1327 | | lba1 += towns_cd.parameter[6] << 8; |
| 1328 | | lba1 += towns_cd.parameter[5]; |
| 1329 | | lba2 = towns_cd.parameter[4] << 16; |
| 1330 | | lba2 += towns_cd.parameter[3] << 8; |
| 1331 | | lba2 += towns_cd.parameter[2]; |
| 1332 | | towns_cd.cdda_current = msf_to_lba(lba1); |
| 1333 | | towns_cd.cdda_length = msf_to_lba(lba2) - towns_cd.cdda_current; |
| 1321 | lba1 = state->towns_cd.parameter[7] << 16; |
| 1322 | lba1 += state->towns_cd.parameter[6] << 8; |
| 1323 | lba1 += state->towns_cd.parameter[5]; |
| 1324 | lba2 = state->towns_cd.parameter[4] << 16; |
| 1325 | lba2 += state->towns_cd.parameter[3] << 8; |
| 1326 | lba2 += state->towns_cd.parameter[2]; |
| 1327 | state->towns_cd.cdda_current = msf_to_lba(lba1); |
| 1328 | state->towns_cd.cdda_length = msf_to_lba(lba2) - state->towns_cd.cdda_current; |
| 1334 | 1329 | |
| 1335 | 1330 | cdda_set_cdrom(cdda,mess_cd_get_cdrom_file(device)); |
| 1336 | | cdda_start_audio(cdda,towns_cd.cdda_current,towns_cd.cdda_length); |
| 1337 | | logerror("CD: CD-DA start from LBA:%i length:%i\n",towns_cd.cdda_current,towns_cd.cdda_length); |
| 1331 | cdda_start_audio(cdda,state->towns_cd.cdda_current,state->towns_cd.cdda_length); |
| 1332 | logerror("CD: CD-DA start from LBA:%i length:%i\n",state->towns_cd.cdda_current,state->towns_cd.cdda_length); |
| 1338 | 1333 | |
| 1339 | | towns_cd.extra_status = 1; |
| 1334 | state->towns_cd.extra_status = 1; |
| 1340 | 1335 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1341 | 1336 | } |
| 1342 | 1337 | |
| 1343 | 1338 | static void towns_cdrom_execute_command(running_device* device) |
| 1344 | 1339 | { |
| 1340 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1341 | |
| 1345 | 1342 | if(mess_cd_get_cdrom_file(device) == NULL) |
| 1346 | 1343 | { // No CD in drive |
| 1347 | | if(towns_cd.command & 0x20) |
| 1344 | if(state->towns_cd.command & 0x20) |
| 1348 | 1345 | { |
| 1349 | | towns_cd.extra_status = 0; |
| 1346 | state->towns_cd.extra_status = 0; |
| 1350 | 1347 | towns_cd_set_status(device->machine,0x10,0x00,0x00,0x00); |
| 1351 | 1348 | } |
| 1352 | 1349 | } |
| 1353 | 1350 | else |
| 1354 | 1351 | { |
| 1355 | | towns_cd.status &= ~0x02; |
| 1356 | | switch(towns_cd.command & 0x9f) |
| 1352 | state->towns_cd.status &= ~0x02; |
| 1353 | switch(state->towns_cd.command & 0x9f) |
| 1357 | 1354 | { |
| 1358 | 1355 | case 0x00: // Seek |
| 1359 | | if(towns_cd.command & 0x20) |
| 1356 | if(state->towns_cd.command & 0x20) |
| 1360 | 1357 | { |
| 1361 | | towns_cd.extra_status = 1; |
| 1358 | state->towns_cd.extra_status = 1; |
| 1362 | 1359 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1363 | 1360 | } |
| 1364 | 1361 | logerror("CD: Command 0x00: SEEK\n"); |
| 1365 | 1362 | break; |
| 1366 | 1363 | case 0x01: // unknown |
| 1367 | | if(towns_cd.command & 0x20) |
| 1364 | if(state->towns_cd.command & 0x20) |
| 1368 | 1365 | { |
| 1369 | | towns_cd.extra_status = 0; |
| 1366 | state->towns_cd.extra_status = 0; |
| 1370 | 1367 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1371 | 1368 | } |
| 1372 | 1369 | logerror("CD: Command 0x01: unknown\n"); |
| r8380 | r8381 | |
| 1381 | 1378 | break; |
| 1382 | 1379 | case 0x05: // Read TOC |
| 1383 | 1380 | logerror("CD: Command 0x05: READ TOC\n"); |
| 1384 | | towns_cd.extra_status = 1; |
| 1381 | state->towns_cd.extra_status = 1; |
| 1385 | 1382 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1386 | 1383 | break; |
| 1387 | 1384 | case 0x06: // Read CD-DA state? |
| 1388 | 1385 | logerror("CD: Command 0x06: READ CD-DA STATE\n"); |
| 1389 | | towns_cd.extra_status = 1; |
| 1386 | state->towns_cd.extra_status = 1; |
| 1390 | 1387 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1391 | 1388 | break; |
| 1392 | 1389 | case 0x80: // set state |
| 1393 | 1390 | logerror("CD: Command 0x80: set state\n"); |
| 1394 | | if(towns_cd.command & 0x20) |
| 1391 | if(state->towns_cd.command & 0x20) |
| 1395 | 1392 | { |
| 1396 | | towns_cd.extra_status = 0; |
| 1397 | | if(towns_cd.parameter[7] != 0) |
| 1393 | state->towns_cd.extra_status = 0; |
| 1394 | if(state->towns_cd.parameter[7] != 0) |
| 1398 | 1395 | { |
| 1399 | 1396 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1400 | 1397 | break; |
| 1401 | 1398 | } |
| 1402 | | if(cdda_audio_active(devtag_get_device(device->machine,"cdda"))) |
| 1399 | if(cdda_audio_active(state->cdda)) |
| 1403 | 1400 | towns_cd_set_status(device->machine,0x00,0x03,0x00,0x00); |
| 1404 | 1401 | else |
| 1405 | 1402 | towns_cd_set_status(device->machine,0x00,0x01,0x00,0x00); |
| r8380 | r8381 | |
| 1407 | 1404 | } |
| 1408 | 1405 | break; |
| 1409 | 1406 | case 0x81: // set state (CDDASET) |
| 1410 | | if(towns_cd.command & 0x20) |
| 1407 | if(state->towns_cd.command & 0x20) |
| 1411 | 1408 | { |
| 1412 | | towns_cd.extra_status = 0; |
| 1409 | state->towns_cd.extra_status = 0; |
| 1413 | 1410 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1414 | 1411 | } |
| 1415 | 1412 | logerror("CD: Command 0x81: set state (CDDASET)\n"); |
| 1416 | 1413 | break; |
| 1417 | 1414 | case 0x84: // Stop CD audio track |
| 1418 | | if(towns_cd.command & 0x20) |
| 1415 | if(state->towns_cd.command & 0x20) |
| 1419 | 1416 | { |
| 1420 | | towns_cd.extra_status = 1; |
| 1417 | state->towns_cd.extra_status = 1; |
| 1421 | 1418 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1422 | | cdda_stop_audio(devtag_get_device(device->machine,"cdda")); |
| 1419 | cdda_stop_audio(state->cdda); |
| 1423 | 1420 | } |
| 1424 | 1421 | logerror("CD: Command 0x84: STOP CD-DA\n"); |
| 1425 | 1422 | break; |
| 1426 | 1423 | case 0x85: // Stop CD audio track (difference from 0x84?) |
| 1427 | | if(towns_cd.command & 0x20) |
| 1424 | if(state->towns_cd.command & 0x20) |
| 1428 | 1425 | { |
| 1429 | | towns_cd.extra_status = 1; |
| 1426 | state->towns_cd.extra_status = 1; |
| 1430 | 1427 | towns_cd_set_status(device->machine,0x00,0x00,0x00,0x00); |
| 1431 | | cdda_stop_audio(devtag_get_device(device->machine,"cdda")); |
| 1428 | cdda_stop_audio(state->cdda); |
| 1432 | 1429 | } |
| 1433 | 1430 | logerror("CD: Command 0x85: STOP CD-DA\n"); |
| 1434 | 1431 | break; |
| 1435 | 1432 | default: |
| 1436 | | towns_cd.extra_status = 0; |
| 1433 | state->towns_cd.extra_status = 0; |
| 1437 | 1434 | towns_cd_set_status(device->machine,0x10,0x00,0x00,0x00); |
| 1438 | | logerror("CD: Unknown or unimplemented command %02x\n",towns_cd.command); |
| 1435 | logerror("CD: Unknown or unimplemented command %02x\n",state->towns_cd.command); |
| 1439 | 1436 | } |
| 1440 | 1437 | } |
| 1441 | 1438 | } |
| 1442 | 1439 | |
| 1443 | 1440 | static UINT16 towns_cdrom_dma_r(running_machine* machine) |
| 1444 | 1441 | { |
| 1445 | | if(towns_cd.buffer_ptr >= 2048) |
| 1442 | towns_state* state = (towns_state*)machine->driver_data; |
| 1443 | if(state->towns_cd.buffer_ptr >= 2048) |
| 1446 | 1444 | return 0x00; |
| 1447 | | return towns_cd.buffer[towns_cd.buffer_ptr++]; |
| 1445 | return state->towns_cd.buffer[state->towns_cd.buffer_ptr++]; |
| 1448 | 1446 | } |
| 1449 | 1447 | |
| 1450 | 1448 | static READ8_HANDLER(towns_cdrom_r) |
| 1451 | 1449 | { |
| 1450 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1452 | 1451 | UINT32 addr = 0; |
| 1453 | 1452 | UINT8 ret = 0; |
| 1454 | 1453 | |
| 1455 | | ret = towns_cd.cmd_status[towns_cd.cmd_status_ptr]; |
| 1454 | ret = state->towns_cd.cmd_status[state->towns_cd.cmd_status_ptr]; |
| 1456 | 1455 | |
| 1457 | 1456 | switch(offset) |
| 1458 | 1457 | { |
| 1459 | 1458 | case 0x00: // status |
| 1460 | 1459 | //logerror("CD: status read, returning %02x\n",towns_cd.status); |
| 1461 | | return towns_cd.status; |
| 1460 | return state->towns_cd.status; |
| 1462 | 1461 | case 0x01: // command status |
| 1463 | | if(towns_cd.cmd_status_ptr >= 3) |
| 1462 | if(state->towns_cd.cmd_status_ptr >= 3) |
| 1464 | 1463 | { |
| 1465 | | towns_cd.status &= ~0x02; |
| 1464 | state->towns_cd.status &= ~0x02; |
| 1466 | 1465 | // check for more status bytes |
| 1467 | | if(towns_cd.extra_status != 0) |
| 1466 | if(state->towns_cd.extra_status != 0) |
| 1468 | 1467 | { |
| 1469 | | switch(towns_cd.command & 0x9f) |
| 1468 | switch(state->towns_cd.command & 0x9f) |
| 1470 | 1469 | { |
| 1471 | 1470 | case 0x00: // seek |
| 1472 | 1471 | towns_cd_set_status(space->machine,0x04,0x00,0x00,0x00); |
| 1473 | | towns_cd.extra_status = 0; |
| 1472 | state->towns_cd.extra_status = 0; |
| 1474 | 1473 | break; |
| 1475 | 1474 | case 0x02: // read |
| 1476 | | if(towns_cd.extra_status == 2) |
| 1475 | if(state->towns_cd.extra_status == 2) |
| 1477 | 1476 | towns_cd_set_status(space->machine,0x22,0x00,0x00,0x00); |
| 1478 | | towns_cd.extra_status = 0; |
| 1477 | state->towns_cd.extra_status = 0; |
| 1479 | 1478 | break; |
| 1480 | 1479 | case 0x04: // play cdda |
| 1481 | 1480 | towns_cd_set_status(space->machine,0x07,0x00,0x00,0x00); |
| 1482 | | towns_cd.extra_status = 0; |
| 1481 | state->towns_cd.extra_status = 0; |
| 1483 | 1482 | break; |
| 1484 | 1483 | case 0x05: // read toc |
| 1485 | | switch(towns_cd.extra_status) |
| 1484 | switch(state->towns_cd.extra_status) |
| 1486 | 1485 | { |
| 1487 | 1486 | case 1: |
| 1488 | 1487 | case 3: |
| 1489 | 1488 | towns_cd_set_status(space->machine,0x16,0x00,0x00,0x00); |
| 1490 | | towns_cd.extra_status++; |
| 1489 | state->towns_cd.extra_status++; |
| 1491 | 1490 | break; |
| 1492 | 1491 | case 2: // st1 = first track number (BCD) |
| 1493 | 1492 | towns_cd_set_status(space->machine,0x17,0x01,0x00,0x00); |
| 1494 | | towns_cd.extra_status++; |
| 1493 | state->towns_cd.extra_status++; |
| 1495 | 1494 | break; |
| 1496 | 1495 | case 4: // st1 = last track number (BCD) |
| 1497 | 1496 | towns_cd_set_status(space->machine,0x17, |
| 1498 | | byte_to_bcd(cdrom_get_last_track(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")))), |
| 1497 | byte_to_bcd(cdrom_get_last_track(mess_cd_get_cdrom_file(state->cdrom))), |
| 1499 | 1498 | 0x00,0x00); |
| 1500 | | towns_cd.extra_status++; |
| 1499 | state->towns_cd.extra_status++; |
| 1501 | 1500 | break; |
| 1502 | 1501 | case 5: // st1 = control/adr of track 0xaa? |
| 1503 | 1502 | towns_cd_set_status(space->machine,0x16, |
| 1504 | | cdrom_get_adr_control(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")),0xaa), |
| 1503 | cdrom_get_adr_control(mess_cd_get_cdrom_file(state->cdrom),0xaa), |
| 1505 | 1504 | 0xaa,0x00); |
| 1506 | | towns_cd.extra_status++; |
| 1505 | state->towns_cd.extra_status++; |
| 1507 | 1506 | break; |
| 1508 | 1507 | case 6: // st1/2/3 = address of track 0xaa? (BCD) |
| 1509 | | addr = cdrom_get_track_start(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")),0xaa); |
| 1508 | addr = cdrom_get_track_start(mess_cd_get_cdrom_file(state->cdrom),0xaa); |
| 1510 | 1509 | addr = lba_to_msf(addr); |
| 1511 | 1510 | towns_cd_set_status(space->machine,0x17, |
| 1512 | 1511 | (addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8,addr & 0x0000ff); |
| 1513 | | towns_cd.extra_status++; |
| 1512 | state->towns_cd.extra_status++; |
| 1514 | 1513 | break; |
| 1515 | 1514 | default: // same as case 5 and 6, but for each individual track |
| 1516 | | if(towns_cd.extra_status & 0x01) |
| 1515 | if(state->towns_cd.extra_status & 0x01) |
| 1517 | 1516 | { |
| 1518 | 1517 | towns_cd_set_status(space->machine,0x16, |
| 1519 | | ((cdrom_get_adr_control(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")),(towns_cd.extra_status/2)-3) & 0x0f) << 4) |
| 1520 | | | ((cdrom_get_adr_control(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")),(towns_cd.extra_status/2)-3) & 0xf0) >> 4), |
| 1521 | | (towns_cd.extra_status/2)-3,0x00); |
| 1522 | | towns_cd.extra_status++; |
| 1518 | ((cdrom_get_adr_control(mess_cd_get_cdrom_file(state->cdrom),(state->towns_cd.extra_status/2)-3) & 0x0f) << 4) |
| 1519 | | ((cdrom_get_adr_control(mess_cd_get_cdrom_file(state->cdrom),(state->towns_cd.extra_status/2)-3) & 0xf0) >> 4), |
| 1520 | (state->towns_cd.extra_status/2)-3,0x00); |
| 1521 | state->towns_cd.extra_status++; |
| 1523 | 1522 | } |
| 1524 | 1523 | else |
| 1525 | 1524 | { |
| 1526 | | addr = cdrom_get_track_start(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")),(towns_cd.extra_status/2)-4); |
| 1525 | addr = cdrom_get_track_start(mess_cd_get_cdrom_file(state->cdrom),(state->towns_cd.extra_status/2)-4); |
| 1527 | 1526 | addr = lba_to_msf(addr); |
| 1528 | 1527 | towns_cd_set_status(space->machine,0x17, |
| 1529 | 1528 | (addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8,addr & 0x0000ff); |
| 1530 | | if(((towns_cd.extra_status/2)-3) >= cdrom_get_last_track(mess_cd_get_cdrom_file(devtag_get_device(space->machine,"cdrom")))) |
| 1529 | if(((state->towns_cd.extra_status/2)-3) >= cdrom_get_last_track(mess_cd_get_cdrom_file(state->cdrom))) |
| 1531 | 1530 | { |
| 1532 | | towns_cd.extra_status = 0; |
| 1531 | state->towns_cd.extra_status = 0; |
| 1533 | 1532 | } |
| 1534 | 1533 | else |
| 1535 | | towns_cd.extra_status++; |
| 1534 | state->towns_cd.extra_status++; |
| 1536 | 1535 | } |
| 1537 | 1536 | break; |
| 1538 | 1537 | } |
| 1539 | 1538 | break; |
| 1540 | 1539 | case 0x06: // read CD-DA state |
| 1541 | | switch(towns_cd.extra_status) |
| 1540 | switch(state->towns_cd.extra_status) |
| 1542 | 1541 | { |
| 1543 | 1542 | case 1: // st2 = track number |
| 1544 | 1543 | towns_cd_set_status(space->machine,0x18, |
| 1545 | 1544 | 0x00,towns_cd_get_track(space->machine),0x00); |
| 1546 | | towns_cd.extra_status++; |
| 1545 | state->towns_cd.extra_status++; |
| 1547 | 1546 | break; |
| 1548 | 1547 | case 2: // st0/1/2 = MSF from beginning of current track |
| 1549 | | addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda")); |
| 1550 | | addr = lba_to_msf(addr - towns_cd.cdda_current); |
| 1548 | addr = cdda_get_audio_lba(state->cdda); |
| 1549 | addr = lba_to_msf(addr - state->towns_cd.cdda_current); |
| 1551 | 1550 | towns_cd_set_status(space->machine,0x19, |
| 1552 | 1551 | (addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8,addr & 0x0000ff); |
| 1553 | | towns_cd.extra_status++; |
| 1552 | state->towns_cd.extra_status++; |
| 1554 | 1553 | break; |
| 1555 | 1554 | case 3: // st1/2 = current MSF |
| 1556 | | addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda")); |
| 1555 | addr = cdda_get_audio_lba(state->cdda); |
| 1557 | 1556 | addr = lba_to_msf(addr); // this data is incorrect, but will do until exact meaning is found |
| 1558 | 1557 | towns_cd_set_status(space->machine,0x19, |
| 1559 | 1558 | 0x00,(addr & 0xff0000) >> 16,(addr & 0x00ff00) >> 8); |
| 1560 | | towns_cd.extra_status++; |
| 1559 | state->towns_cd.extra_status++; |
| 1561 | 1560 | break; |
| 1562 | 1561 | case 4: |
| 1563 | | addr = cdda_get_audio_lba(devtag_get_device(space->machine,"cdda")); |
| 1562 | addr = cdda_get_audio_lba(state->cdda); |
| 1564 | 1563 | addr = lba_to_msf(addr); // this data is incorrect, but will do until exact meaning is found |
| 1565 | 1564 | towns_cd_set_status(space->machine,0x20, |
| 1566 | 1565 | addr & 0x0000ff,0x00,0x00); |
| 1567 | | towns_cd.extra_status = 0; |
| 1566 | state->towns_cd.extra_status = 0; |
| 1568 | 1567 | break; |
| 1569 | 1568 | } |
| 1570 | 1569 | break; |
| 1571 | 1570 | case 0x84: |
| 1572 | 1571 | towns_cd_set_status(space->machine,0x11,0x00,0x00,0x00); |
| 1573 | | towns_cd.extra_status = 0; |
| 1572 | state->towns_cd.extra_status = 0; |
| 1574 | 1573 | break; |
| 1575 | 1574 | case 0x85: |
| 1576 | 1575 | towns_cd_set_status(space->machine,0x12,0x00,0x00,0x00); |
| 1577 | | towns_cd.extra_status = 0; |
| 1576 | state->towns_cd.extra_status = 0; |
| 1578 | 1577 | break; |
| 1579 | 1578 | } |
| 1580 | 1579 | } |
| 1581 | 1580 | } |
| 1582 | | logerror("CD: reading command status port (%i), returning %02x\n",towns_cd.cmd_status_ptr,ret); |
| 1583 | | towns_cd.cmd_status_ptr++; |
| 1584 | | if(towns_cd.cmd_status_ptr > 3) |
| 1581 | logerror("CD: reading command status port (%i), returning %02x\n",state->towns_cd.cmd_status_ptr,ret); |
| 1582 | state->towns_cd.cmd_status_ptr++; |
| 1583 | if(state->towns_cd.cmd_status_ptr > 3) |
| 1585 | 1584 | { |
| 1586 | | towns_cd.cmd_status_ptr = 0; |
| 1587 | | /* if(towns_cd.extra_status != 0) |
| 1585 | state->towns_cd.cmd_status_ptr = 0; |
| 1586 | /* if(state->towns_cd.extra_status != 0) |
| 1588 | 1587 | { |
| 1589 | 1588 | towns_cdrom_set_irq(space->machine,TOWNS_CD_IRQ_MPU,1); |
| 1590 | | towns_cd.status |= 0x02; |
| 1589 | state->towns_cd.status |= 0x02; |
| 1591 | 1590 | }*/ |
| 1592 | 1591 | } |
| 1593 | 1592 | return ret; |
| r8380 | r8381 | |
| 1598 | 1597 | |
| 1599 | 1598 | static WRITE8_HANDLER(towns_cdrom_w) |
| 1600 | 1599 | { |
| 1600 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1601 | 1601 | int x; |
| 1602 | 1602 | switch(offset) |
| 1603 | 1603 | { |
| r8380 | r8381 | |
| 1608 | 1608 | towns_cdrom_set_irq(space->machine,TOWNS_CD_IRQ_DMA,0); |
| 1609 | 1609 | if(data & 0x04) |
| 1610 | 1610 | logerror("CD: sub MPU reset\n"); |
| 1611 | | towns_cd.mpu_irq_enable = data & 0x02; |
| 1612 | | towns_cd.dma_irq_enable = data & 0x01; |
| 1611 | state->towns_cd.mpu_irq_enable = data & 0x02; |
| 1612 | state->towns_cd.dma_irq_enable = data & 0x01; |
| 1613 | 1613 | logerror("CD: status write %02x\n",data); |
| 1614 | 1614 | break; |
| 1615 | 1615 | case 0x01: // command |
| 1616 | | towns_cd.command = data; |
| 1617 | | towns_cdrom_execute_command(devtag_get_device(space->machine,"cdrom")); |
| 1616 | state->towns_cd.command = data; |
| 1617 | towns_cdrom_execute_command(state->cdrom); |
| 1618 | 1618 | logerror("CD: command %02x sent\n",data); |
| 1619 | 1619 | logerror("CD: parameters: %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 1620 | | towns_cd.parameter[7],towns_cd.parameter[6],towns_cd.parameter[5], |
| 1621 | | towns_cd.parameter[4],towns_cd.parameter[3],towns_cd.parameter[2], |
| 1622 | | towns_cd.parameter[1],towns_cd.parameter[0]); |
| 1620 | state->towns_cd.parameter[7],state->towns_cd.parameter[6],state->towns_cd.parameter[5], |
| 1621 | state->towns_cd.parameter[4],state->towns_cd.parameter[3],state->towns_cd.parameter[2], |
| 1622 | state->towns_cd.parameter[1],state->towns_cd.parameter[0]); |
| 1623 | 1623 | break; |
| 1624 | 1624 | case 0x02: // parameter |
| 1625 | 1625 | for(x=7;x>0;x--) |
| 1626 | | towns_cd.parameter[x] = towns_cd.parameter[x-1]; |
| 1627 | | towns_cd.parameter[0] = data; |
| 1626 | state->towns_cd.parameter[x] = state->towns_cd.parameter[x-1]; |
| 1627 | state->towns_cd.parameter[0] = data; |
| 1628 | 1628 | logerror("CD: parameter %02x added\n",data); |
| 1629 | 1629 | break; |
| 1630 | 1630 | case 0x03: |
| 1631 | 1631 | // TODO: software transfer mode (bit 3) |
| 1632 | 1632 | if(data & 0x10) |
| 1633 | 1633 | { |
| 1634 | | towns_cd.status |= 0x10; // DMA transfer begin |
| 1635 | | towns_cd.status &= ~0x20; // not a software transfer |
| 1636 | | if(towns_cd.buffer_ptr < 0) |
| 1634 | state->towns_cd.status |= 0x10; // DMA transfer begin |
| 1635 | state->towns_cd.status &= ~0x20; // not a software transfer |
| 1636 | if(state->towns_cd.buffer_ptr < 0) |
| 1637 | 1637 | { |
| 1638 | | towns_cd.buffer_ptr = 0; |
| 1639 | | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1638 | state->towns_cd.buffer_ptr = 0; |
| 1639 | timer_adjust_oneshot(state->towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1640 | 1640 | } |
| 1641 | 1641 | } |
| 1642 | 1642 | logerror("CD: transfer mode write %02x\n",data); |
| r8380 | r8381 | |
| 1653 | 1653 | */ |
| 1654 | 1654 | static READ32_HANDLER(towns_rtc_r) |
| 1655 | 1655 | { |
| 1656 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1656 | 1657 | if(ACCESSING_BITS_0_7) |
| 1657 | | return 0x80 | towns_rtc_reg[towns_rtc_select]; |
| 1658 | return 0x80 | state->towns_rtc_reg[state->towns_rtc_select]; |
| 1658 | 1659 | |
| 1659 | 1660 | return 0x00; |
| 1660 | 1661 | } |
| 1661 | 1662 | |
| 1662 | 1663 | static WRITE32_HANDLER(towns_rtc_w) |
| 1663 | 1664 | { |
| 1665 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1664 | 1666 | if(ACCESSING_BITS_0_7) |
| 1665 | | towns_rtc_data = data; |
| 1667 | state->towns_rtc_data = data; |
| 1666 | 1668 | } |
| 1667 | 1669 | |
| 1668 | 1670 | static WRITE32_HANDLER(towns_rtc_select_w) |
| 1669 | 1671 | { |
| 1672 | towns_state* state = (towns_state*)space->machine->driver_data; |
| 1670 | 1673 | if(ACCESSING_BITS_0_7) |
| 1671 | 1674 | { |
| 1672 | 1675 | if(data & 0x80) |
| 1673 | 1676 | { |
| 1674 | 1677 | if(data & 0x01) |
| 1675 | | towns_rtc_select = towns_rtc_data & 0x0f; |
| 1678 | state->towns_rtc_select = state->towns_rtc_data & 0x0f; |
| 1676 | 1679 | } |
| 1677 | 1680 | } |
| 1678 | 1681 | } |
| 1679 | 1682 | |
| 1680 | | static void rtc_hour(void) |
| 1683 | static void rtc_hour(running_machine* machine) |
| 1681 | 1684 | { |
| 1682 | | towns_rtc_reg[4]++; |
| 1683 | | if(towns_rtc_reg[4] > 4 && towns_rtc_reg[5] == 2) |
| 1685 | towns_state* state = (towns_state*)machine->driver_data; |
| 1686 | |
| 1687 | state->towns_rtc_reg[4]++; |
| 1688 | if(state->towns_rtc_reg[4] > 4 && state->towns_rtc_reg[5] == 2) |
| 1684 | 1689 | { |
| 1685 | | towns_rtc_reg[4] = 0; |
| 1686 | | towns_rtc_reg[5] = 0; |
| 1690 | state->towns_rtc_reg[4] = 0; |
| 1691 | state->towns_rtc_reg[5] = 0; |
| 1687 | 1692 | } |
| 1688 | | else if(towns_rtc_reg[4] > 9) |
| 1693 | else if(state->towns_rtc_reg[4] > 9) |
| 1689 | 1694 | { |
| 1690 | | towns_rtc_reg[4] = 0; |
| 1691 | | towns_rtc_reg[5]++; |
| 1695 | state->towns_rtc_reg[4] = 0; |
| 1696 | state->towns_rtc_reg[5]++; |
| 1692 | 1697 | } |
| 1693 | 1698 | } |
| 1694 | 1699 | |
| 1695 | | static void rtc_minute(void) |
| 1700 | static void rtc_minute(running_machine* machine) |
| 1696 | 1701 | { |
| 1697 | | towns_rtc_reg[2]++; |
| 1698 | | if(towns_rtc_reg[2] > 9) |
| 1702 | towns_state* state = (towns_state*)machine->driver_data; |
| 1703 | |
| 1704 | state->towns_rtc_reg[2]++; |
| 1705 | if(state->towns_rtc_reg[2] > 9) |
| 1699 | 1706 | { |
| 1700 | | towns_rtc_reg[2] = 0; |
| 1701 | | towns_rtc_reg[3]++; |
| 1702 | | if(towns_rtc_reg[3] > 5) |
| 1707 | state->towns_rtc_reg[2] = 0; |
| 1708 | state->towns_rtc_reg[3]++; |
| 1709 | if(state->towns_rtc_reg[3] > 5) |
| 1703 | 1710 | { |
| 1704 | | towns_rtc_reg[3] = 0; |
| 1705 | | rtc_hour(); |
| 1711 | state->towns_rtc_reg[3] = 0; |
| 1712 | rtc_hour(machine); |
| 1706 | 1713 | } |
| 1707 | 1714 | } |
| 1708 | 1715 | } |
| 1709 | 1716 | |
| 1710 | 1717 | static TIMER_CALLBACK(rtc_second) |
| 1711 | 1718 | { |
| 1719 | towns_state* state = (towns_state*)machine->driver_data; |
| 1712 | 1720 | // increase RTC time by one second |
| 1713 | | towns_rtc_reg[0]++; |
| 1714 | | if(towns_rtc_reg[0] > 9) |
| 1721 | state->towns_rtc_reg[0]++; |
| 1722 | if(state->towns_rtc_reg[0] > 9) |
| 1715 | 1723 | { |
| 1716 | | towns_rtc_reg[0] = 0; |
| 1717 | | towns_rtc_reg[1]++; |
| 1718 | | if(towns_rtc_reg[1] > 5) |
| 1724 | state->towns_rtc_reg[0] = 0; |
| 1725 | state->towns_rtc_reg[1]++; |
| 1726 | if(state->towns_rtc_reg[1] > 5) |
| 1719 | 1727 | { |
| 1720 | | towns_rtc_reg[1] = 0; |
| 1721 | | rtc_minute(); |
| 1728 | state->towns_rtc_reg[1] = 0; |
| 1729 | rtc_minute(machine); |
| 1722 | 1730 | } |
| 1723 | 1731 | } |
| 1724 | 1732 | } |
| r8380 | r8381 | |
| 1741 | 1749 | |
| 1742 | 1750 | static IRQ_CALLBACK( towns_irq_callback ) |
| 1743 | 1751 | { |
| 1744 | | running_device* pic1 = devtag_get_device(device->machine,"pic8259_master"); |
| 1745 | | running_device* pic2 = devtag_get_device(device->machine,"pic8259_slave"); |
| 1752 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1753 | running_device* pic1 = state->pic_master; |
| 1754 | running_device* pic2 = state->pic_slave; |
| 1746 | 1755 | int r; |
| 1747 | 1756 | |
| 1748 | 1757 | r = pic8259_acknowledge(pic2); |
| r8380 | r8381 | |
| 1757 | 1766 | // YM3438 interrupt (IRQ 13) |
| 1758 | 1767 | void towns_fm_irq(running_device* device, int irq) |
| 1759 | 1768 | { |
| 1760 | | running_device* pic = devtag_get_device(device->machine,"pic8259_slave"); |
| 1769 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1770 | running_device* pic = state->pic_slave; |
| 1761 | 1771 | if(irq) |
| 1762 | 1772 | { |
| 1763 | | towns_fm_irq_flag = 1; |
| 1773 | state->towns_fm_irq_flag = 1; |
| 1764 | 1774 | pic8259_ir5_w(pic, 1); |
| 1765 | 1775 | logerror("PIC: IRQ13 (FM) set high\n"); |
| 1766 | 1776 | } |
| 1767 | 1777 | else |
| 1768 | 1778 | { |
| 1769 | | towns_fm_irq_flag = 0; |
| 1779 | state->towns_fm_irq_flag = 0; |
| 1770 | 1780 | pic8259_ir5_w(pic, 0); |
| 1771 | 1781 | logerror("PIC: IRQ13 (FM) set low\n"); |
| 1772 | 1782 | } |
| r8380 | r8381 | |
| 1775 | 1785 | // PCM interrupt (IRQ 13) |
| 1776 | 1786 | void towns_pcm_irq(running_device* device, int channel) |
| 1777 | 1787 | { |
| 1778 | | running_device* pic = devtag_get_device(device->machine,"pic8259_slave"); |
| 1788 | towns_state* state = (towns_state*)device->machine->driver_data; |
| 1789 | running_device* pic = state->pic_slave; |
| 1779 | 1790 | |
| 1780 | | towns_pcm_irq_flag = 1; |
| 1781 | | if(towns_pcm_channel_mask & (1 << channel)) |
| 1791 | state->towns_pcm_irq_flag = 1; |
| 1792 | if(state->towns_pcm_channel_mask & (1 << channel)) |
| 1782 | 1793 | { |
| 1783 | | towns_pcm_channel_flag |= (1 << channel); |
| 1794 | state->towns_pcm_channel_flag |= (1 << channel); |
| 1784 | 1795 | pic8259_ir5_w(pic, 1); |
| 1785 | 1796 | logerror("PIC: IRQ13 (PCM) set high\n"); |
| 1786 | 1797 | } |
| r8380 | r8381 | |
| 1794 | 1805 | |
| 1795 | 1806 | static WRITE_LINE_DEVICE_HANDLER( towns_pit_out0_changed ) |
| 1796 | 1807 | { |
| 1797 | | running_device* dev = devtag_get_device(device->machine,"pic8259_master"); |
| 1808 | towns_state* tstate = (towns_state*)device->machine->driver_data; |
| 1809 | running_device* dev = tstate->pic_master; |
| 1798 | 1810 | |
| 1799 | | if(towns_timer_mask & 0x01) |
| 1811 | if(tstate->towns_timer_mask & 0x01) |
| 1800 | 1812 | { |
| 1801 | 1813 | pic8259_ir0_w(dev, state); |
| 1802 | 1814 | logerror("PIC: IRQ0 (PIT Timer) set to %i\n",state); |
| r8380 | r8381 | |
| 1805 | 1817 | |
| 1806 | 1818 | static WRITE_LINE_DEVICE_HANDLER( towns_pit_out1_changed ) |
| 1807 | 1819 | { |
| 1808 | | // running_device* dev = devtag_get_device(device->machine,"pic8259_master"); |
| 1820 | towns_state* tstate = (towns_state*)device->machine->driver_data; |
| 1821 | // running_device* dev = tstate->pic_master; |
| 1809 | 1822 | |
| 1810 | | if(towns_timer_mask & 0x02) |
| 1823 | if(tstate->towns_timer_mask & 0x02) |
| 1811 | 1824 | { |
| 1812 | 1825 | // pic8259_ir0_w(dev, state); |
| 1813 | 1826 | } |
| r8380 | r8381 | |
| 2130 | 2143 | |
| 2131 | 2144 | static DRIVER_INIT( towns ) |
| 2132 | 2145 | { |
| 2133 | | towns_vram = auto_alloc_array(machine,UINT32,0x20000); |
| 2134 | | towns_cmos = auto_alloc_array(machine,UINT8,0x2000); |
| 2135 | | towns_gfxvram = auto_alloc_array(machine,UINT8,0x80000); |
| 2136 | | towns_txtvram = auto_alloc_array(machine,UINT8,0x20000); |
| 2146 | towns_state* state = (towns_state*)machine->driver_data; |
| 2147 | state->pic_master = devtag_get_device(machine,"pic8259_master"); |
| 2148 | state->pic_slave = devtag_get_device(machine,"pic8259_slave"); |
| 2149 | state->towns_vram = auto_alloc_array(machine,UINT32,0x20000); |
| 2150 | state->towns_cmos = auto_alloc_array(machine,UINT8,0x2000); |
| 2151 | state->towns_gfxvram = auto_alloc_array(machine,UINT8,0x80000); |
| 2152 | state->towns_txtvram = auto_alloc_array(machine,UINT8,0x20000); |
| 2137 | 2153 | //towns_sprram = auto_alloc_array(machine,UINT8,0x20000); |
| 2138 | | towns_serial_rom = auto_alloc_array(machine,UINT8,256/8); |
| 2154 | state->towns_serial_rom = auto_alloc_array(machine,UINT8,256/8); |
| 2139 | 2155 | towns_init_serial_rom(machine); |
| 2140 | | towns_init_rtc(); |
| 2141 | | towns_rtc_timer = timer_alloc(machine,rtc_second,NULL); |
| 2142 | | towns_kb_timer = timer_alloc(machine,poll_keyboard,NULL); |
| 2143 | | towns_mouse_timer = timer_alloc(machine,towns_mouse_timeout,NULL); |
| 2156 | towns_init_rtc(machine); |
| 2157 | state->towns_rtc_timer = timer_alloc(machine,rtc_second,NULL); |
| 2158 | state->towns_kb_timer = timer_alloc(machine,poll_keyboard,NULL); |
| 2159 | state->towns_mouse_timer = timer_alloc(machine,towns_mouse_timeout,NULL); |
| 2144 | 2160 | |
| 2145 | 2161 | // CD-ROM init |
| 2146 | | towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)devtag_get_device(machine,"dma_1")); |
| 2162 | state->towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)devtag_get_device(machine,"dma_1")); |
| 2147 | 2163 | |
| 2148 | 2164 | cpu_set_irq_callback(devtag_get_device(machine,"maincpu"), towns_irq_callback); |
| 2149 | 2165 | } |
| 2150 | 2166 | |
| 2151 | 2167 | static DRIVER_INIT( marty ) |
| 2152 | 2168 | { |
| 2169 | towns_state* state = (towns_state*)machine->driver_data; |
| 2153 | 2170 | DRIVER_INIT_CALL(towns); |
| 2154 | | towns_machine_id = 0x034a; |
| 2171 | state->towns_machine_id = 0x034a; |
| 2155 | 2172 | } |
| 2156 | 2173 | |
| 2157 | 2174 | static MACHINE_RESET( towns ) |
| 2158 | 2175 | { |
| 2159 | | ftimer = 0x00; |
| 2160 | | nmi_mask = 0x00; |
| 2161 | | compat_mode = 0x00; |
| 2162 | | towns_ankcg_enable = 0x00; |
| 2163 | | towns_mainmem_enable = 0x00; |
| 2164 | | towns_ram_enable = 0x00; |
| 2165 | | towns_update_video_banks(cpu_get_address_space(devtag_get_device(machine,"maincpu"),ADDRESS_SPACE_PROGRAM)); |
| 2166 | | towns_kb_status = 0x18; |
| 2167 | | towns_kb_irq1_enable = 0; |
| 2168 | | towns_pad_mask = 0x7f; |
| 2169 | | towns_mouse_output = MOUSE_START; |
| 2170 | | towns_cd.status = 0x01; // CDROM controller ready |
| 2171 | | towns_cd.buffer_ptr = -1; |
| 2172 | | timer_adjust_periodic(towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1)); |
| 2173 | | timer_adjust_periodic(towns_kb_timer,attotime_zero,0,ATTOTIME_IN_MSEC(10)); |
| 2176 | towns_state* state = (towns_state*)machine->driver_data; |
| 2177 | state->maincpu = devtag_get_device(machine,"maincpu"); |
| 2178 | state->dma_1 = devtag_get_device(machine,"dma_1"); |
| 2179 | state->dma_2 = devtag_get_device(machine,"dma_2"); |
| 2180 | state->fdc = devtag_get_device(machine,"fdc"); |
| 2181 | state->pic_master = devtag_get_device(machine,"pic8259_master"); |
| 2182 | state->pic_slave = devtag_get_device(machine,"pic8259_slave"); |
| 2183 | state->pit = devtag_get_device(machine,"pit"); |
| 2184 | state->messram = devtag_get_device(machine,"messram"); |
| 2185 | state->cdrom = devtag_get_device(machine,"cdrom"); |
| 2186 | state->cdda = devtag_get_device(machine,"cdda"); |
| 2187 | state->ftimer = 0x00; |
| 2188 | state->nmi_mask = 0x00; |
| 2189 | state->compat_mode = 0x00; |
| 2190 | state->towns_ankcg_enable = 0x00; |
| 2191 | state->towns_mainmem_enable = 0x00; |
| 2192 | state->towns_system_port = 0x00; |
| 2193 | state->towns_ram_enable = 0x00; |
| 2194 | towns_update_video_banks(cpu_get_address_space(state->maincpu,ADDRESS_SPACE_PROGRAM)); |
| 2195 | state->towns_kb_status = 0x18; |
| 2196 | state->towns_kb_irq1_enable = 0; |
| 2197 | state->towns_pad_mask = 0x7f; |
| 2198 | state->towns_mouse_output = MOUSE_START; |
| 2199 | state->towns_cd.status = 0x01; // CDROM controller ready |
| 2200 | state->towns_cd.buffer_ptr = -1; |
| 2201 | timer_adjust_periodic(state->towns_rtc_timer,attotime_zero,0,ATTOTIME_IN_HZ(1)); |
| 2202 | timer_adjust_periodic(state->towns_kb_timer,attotime_zero,0,ATTOTIME_IN_MSEC(10)); |
| 2174 | 2203 | } |
| 2175 | 2204 | |
| 2176 | 2205 | static const struct pit8253_config towns_pit8253_config = |
| r8380 | r8381 | |
| 2280 | 2309 | GFXDECODE_END |
| 2281 | 2310 | |
| 2282 | 2311 | static MACHINE_DRIVER_START( towns ) |
| 2283 | | /* basic machine hardware */ |
| 2312 | MDRV_DRIVER_DATA(towns_state) |
| 2313 | |
| 2314 | /* basic machine hardware */ |
| 2284 | 2315 | MDRV_CPU_ADD("maincpu",I386, 16000000) |
| 2285 | 2316 | MDRV_CPU_PROGRAM_MAP(towns_mem) |
| 2286 | 2317 | MDRV_CPU_IO_MAP(towns_io) |