1 // license:GPL-2.0+ 2 // copyright-holders:Raphael Nabet 3 /***************************************************************************** 4 * 5 * includes/tx0.h 6 * 7 ****************************************************************************/ 8 #ifndef MAME_INCLUDES_TX0_H 9 #define MAME_INCLUDES_TX0_H 10 11 #pragma once 12 13 #include "video/crt.h" 14 #include "cpu/pdp1/tx0.h" 15 #include "emupal.h" 16 17 enum state_t 18 { 19 MTS_UNSELECTED, 20 MTS_SELECTING, 21 MTS_SELECTED, 22 MTS_UNSELECTING 23 }; 24 25 enum backspace_state_t 26 { 27 MTBSS_STATE0, 28 MTBSS_STATE1, 29 MTBSS_STATE2, 30 MTBSS_STATE3, 31 MTBSS_STATE4, 32 MTBSS_STATE5, 33 MTBSS_STATE6 34 }; 35 36 enum state_2_t 37 { 38 MTRDS_STATE0, 39 MTRDS_STATE1, 40 MTRDS_STATE2, 41 MTRDS_STATE3, 42 MTRDS_STATE4, 43 MTRDS_STATE5, 44 MTRDS_STATE6 45 }; 46 47 enum state_3_t 48 { 49 MTWTS_STATE0, 50 MTWTS_STATE1, 51 MTWTS_STATE2, 52 MTWTS_STATE3 53 }; 54 55 enum irg_pos_t 56 { 57 MTIRGP_START, 58 MTIRGP_ENDMINUS1, 59 MTIRGP_END 60 }; 61 62 63 64 /* tape reader registers */ 65 struct tx0_tape_reader_t 66 { 67 device_image_interface *fd; /* file descriptor of tape image */ 68 69 int motor_on; /* 1-bit reader motor on */ 70 71 int rcl; /* 1-bit reader clutch */ 72 int rc; /* 2-bit reader counter */ 73 74 emu_timer *timer; /* timer to simulate reader timing */ 75 }; 76 77 78 79 /* tape puncher registers */ 80 struct tape_puncher_t 81 { 82 device_image_interface *fd; /* file descriptor of tape image */ 83 84 emu_timer *timer; /* timer to generate completion pulses */ 85 }; 86 87 88 89 /* typewriter registers */ 90 struct tx0_typewriter_t 91 { 92 device_image_interface *fd; /* file descriptor of output image */ 93 94 emu_timer *prt_timer;/* timer to generate completion pulses */ 95 }; 96 97 98 /* magnetic tape unit registers */ 99 struct magtape_t 100 { 101 device_image_interface *img; /* image descriptor */ 102 103 state_t state; 104 105 int command; 106 int binary_flag; 107 108 union 109 { 110 backspace_state_t backspace_state; 111 struct 112 { 113 state_2_t state; 114 int space_flag; 115 } read; 116 struct 117 { 118 state_3_t state; 119 int counter; 120 } write; 121 } u; 122 123 int sel_pending; 124 int cpy_pending; 125 126 irg_pos_t irg_pos; /* position relative to inter-record gap */ 127 128 int long_parity; 129 130 emu_timer *timer; /* timer to simulate reader timing */ 131 }; 132 133 134 class tx0_state : public driver_device 135 { 136 public: tx0_state(const machine_config & mconfig,device_type type,const char * tag)137 tx0_state(const machine_config &mconfig, device_type type, const char *tag) : 138 driver_device(mconfig, type, tag), 139 m_maincpu(*this, "maincpu"), 140 m_gfxdecode(*this, "gfxdecode"), 141 m_palette(*this, "palette"), 142 m_crt(*this, "crt"), 143 m_csw(*this, "CSW"), 144 m_twr(*this, "TWR.%u", 0) 145 { } 146 147 void tx0_64kw(machine_config &config); 148 void tx0_8kw(machine_config &config); 149 150 void init_tx0(); 151 152 required_device<tx0_device> m_maincpu; 153 tx0_tape_reader_t m_tape_reader; 154 tape_puncher_t m_tape_puncher; 155 tx0_typewriter_t m_typewriter; 156 emu_timer *m_dis_timer; 157 magtape_t m_magtape; 158 159 void schedule_select(); 160 void schedule_unselect(); 161 162 protected: 163 int m_old_typewriter_keys[4]; 164 int m_old_control_keys; 165 int m_old_tsr_keys; 166 int m_tsr_index; 167 int m_typewriter_color; 168 bitmap_ind16 m_panel_bitmap; 169 bitmap_ind16 m_typewriter_bitmap; 170 int m_pos; 171 int m_case_shift; 172 virtual void machine_start() override; 173 virtual void machine_reset() override; 174 virtual void video_start() override; 175 void tx0_palette(palette_device &palette) const; 176 uint32_t screen_update_tx0(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); 177 DECLARE_WRITE_LINE_MEMBER(screen_vblank_tx0); 178 INTERRUPT_GEN_MEMBER(tx0_interrupt); 179 TIMER_CALLBACK_MEMBER(reader_callback); 180 TIMER_CALLBACK_MEMBER(puncher_callback); 181 TIMER_CALLBACK_MEMBER(prt_callback); 182 TIMER_CALLBACK_MEMBER(dis_callback); 183 void tx0_machine_stop(); 184 inline void tx0_plot_pixel(bitmap_ind16 &bitmap, int x, int y, uint32_t color); 185 void tx0_plot(int x, int y); 186 void tx0_draw_led(bitmap_ind16 &bitmap, int x, int y, int state); 187 void tx0_draw_multipleled(bitmap_ind16 &bitmap, int x, int y, int value, int nb_bits); 188 void tx0_draw_switch(bitmap_ind16 &bitmap, int x, int y, int state); 189 void tx0_draw_multipleswitch(bitmap_ind16 &bitmap, int x, int y, int value, int nb_bits); 190 void tx0_draw_char(bitmap_ind16 &bitmap, char character, int x, int y, int color); 191 void tx0_draw_string(bitmap_ind16 &bitmap, const char *buf, int x, int y, int color); 192 void tx0_draw_vline(bitmap_ind16 &bitmap, int x, int y, int height, int color); 193 void tx0_draw_panel_backdrop(bitmap_ind16 &bitmap); 194 void tx0_draw_panel(bitmap_ind16 &bitmap); 195 void tx0_typewriter_linefeed(); 196 void tx0_typewriter_drawchar(int character); 197 int tape_read(uint8_t *reply); 198 void tape_write(uint8_t data); 199 void begin_tape_read(int binary); 200 void typewriter_out(uint8_t data); 201 202 void tx0_keyboard(); 203 DECLARE_WRITE_LINE_MEMBER(tx0_io_cpy); 204 DECLARE_WRITE_LINE_MEMBER(tx0_io_r1l); 205 DECLARE_WRITE_LINE_MEMBER(tx0_io_r3l); 206 DECLARE_WRITE_LINE_MEMBER(tx0_io_p6h); 207 DECLARE_WRITE_LINE_MEMBER(tx0_io_p7h); 208 DECLARE_WRITE_LINE_MEMBER(tx0_io_prt); 209 DECLARE_WRITE_LINE_MEMBER(tx0_io_dis); 210 DECLARE_WRITE_LINE_MEMBER(tx0_sel); 211 DECLARE_WRITE_LINE_MEMBER(tx0_io_reset_callback); 212 void magtape_callback(); 213 214 void tx0_64kw_map(address_map &map); 215 void tx0_8kw_map(address_map &map); 216 217 required_device<gfxdecode_device> m_gfxdecode; 218 required_device<palette_device> m_palette; 219 required_device<crt_device> m_crt; 220 required_ioport m_csw; 221 required_ioport_array<4> m_twr; 222 }; 223 224 /* defines for each bit and mask in input port "CSW" */ 225 enum 226 { 227 /* bit numbers */ 228 tx0_control_bit = 0, 229 230 tx0_stop_c0_bit = 1, 231 tx0_stop_c1_bit = 2, 232 tx0_gbl_cm_sel_bit = 3, 233 tx0_stop_bit = 4, 234 tx0_restart_bit = 5, 235 tx0_read_in_bit = 6, 236 237 tx0_toggle_dn_bit = 12, 238 tx0_toggle_up_bit = 13, 239 tx0_cm_sel_bit = 14, 240 tx0_lr_sel_bit = 15, 241 242 /* masks */ 243 tx0_control = (1 << tx0_control_bit), 244 245 tx0_stop_cyc0 = (1 << tx0_stop_c0_bit), 246 tx0_stop_cyc1 = (1 << tx0_stop_c1_bit), 247 tx0_gbl_cm_sel = (1 << tx0_gbl_cm_sel_bit), 248 tx0_stop = (1 << tx0_stop_bit), 249 tx0_restart = (1 << tx0_restart_bit), 250 tx0_read_in = (1 << tx0_read_in_bit), 251 252 tx0_toggle_dn = (1 << tx0_toggle_dn_bit), 253 tx0_toggle_up = (1 << tx0_toggle_up_bit), 254 tx0_cm_sel = (1 << tx0_cm_sel_bit), 255 tx0_lr_sel = (1 << tx0_lr_sel_bit) 256 }; 257 258 /* defines for our font */ 259 enum 260 { 261 tx0_charnum = /*96*/128, /* ASCII set + xx special characters */ 262 /* for whatever reason, 96 breaks some characters */ 263 264 tx0_fontdata_size = 8 * tx0_charnum 265 }; 266 267 enum 268 { 269 /* size and position of crt window */ 270 crt_window_width = /*511*/512, 271 crt_window_height = /*511*/512, 272 crt_window_offset_x = 0, 273 crt_window_offset_y = 0, 274 /* size and position of operator control panel window */ 275 panel_window_width = 272, 276 panel_window_height = 264, 277 panel_window_offset_x = crt_window_width, 278 panel_window_offset_y = 0, 279 /* size and position of typewriter window */ 280 typewriter_window_width = 640, 281 typewriter_window_height = 160, 282 typewriter_window_offset_x = 0, 283 typewriter_window_offset_y = crt_window_height 284 }; 285 286 enum 287 { 288 total_width = crt_window_width + panel_window_width, 289 total_height = crt_window_height + typewriter_window_height, 290 291 /* respect 4:3 aspect ratio to keep pixels square */ 292 virtual_width_1 = ((total_width+3)/4)*4, 293 virtual_height_1 = ((total_height+2)/3)*3, 294 virtual_width_2 = virtual_height_1*4/3, 295 virtual_height_2 = virtual_width_1*3/4, 296 virtual_width = (virtual_width_1 > virtual_width_2) ? virtual_width_1 : virtual_width_2, 297 virtual_height = (virtual_height_1 > virtual_height_2) ? virtual_height_1 : virtual_height_2 298 }; 299 300 enum 301 { /* refresh rate in Hz: can be changed at will */ 302 refresh_rate = 60 303 }; 304 305 /* Color codes */ 306 enum 307 { 308 /* first pen_crt_num_levels colors used for CRT (with remanence) */ 309 pen_crt_num_levels = 69, 310 pen_crt_max_intensity = pen_crt_num_levels-1, 311 312 /* next colors used for control panel and typewriter */ 313 pen_black = pen_crt_num_levels, 314 pen_white, 315 pen_green, 316 pen_dk_green, 317 pen_red, 318 pen_lt_gray, 319 320 /* color constants for control panel */ 321 pen_panel_bg = pen_black, 322 pen_panel_caption = pen_white, 323 color_panel_caption = 0, 324 pen_switch_nut = pen_lt_gray, 325 pen_switch_button = pen_white, 326 pen_lit_lamp = pen_green, 327 pen_unlit_lamp = pen_dk_green, 328 329 /* color constants for typewriter */ 330 pen_typewriter_bg = pen_white, 331 color_typewriter_black = 1, /* palette 1 = black on white */ 332 color_typewriter_red = 2, /* palette 2 = red on white */ 333 334 /* color constants used for light pen */ 335 pen_lightpen_nonpressed = pen_red, 336 pen_lightpen_pressed = pen_green 337 }; 338 339 340 #endif // MAME_INCLUDES_TX0_H 341