src/mess/machine/teleprinter.c
| r14605 | r14606 | |
| 1 | | #include "emu.h" |
| 2 | 1 | #include "machine/teleprinter.h" |
| 3 | | #include "machine/terminal.h" |
| 4 | 2 | |
| 5 | | /*************************************************************************** |
| 6 | | TYPE DEFINITIONS |
| 7 | | ***************************************************************************/ |
| 8 | | #define TELEPRINTER_WIDTH 80 |
| 9 | | #define TELEPRINTER_HEIGHT 50 |
| 10 | | typedef struct _teleprinter_state teleprinter_state; |
| 11 | | struct _teleprinter_state |
| 12 | | { |
| 13 | | UINT8 buffer[TELEPRINTER_WIDTH*TELEPRINTER_HEIGHT]; |
| 14 | | UINT8 x_pos; |
| 15 | | UINT8 last_code; |
| 16 | | UINT8 scan_line; |
| 17 | | devcb_resolved_write8 teleprinter_keyboard_func; |
| 18 | | }; |
| 19 | | |
| 20 | | /***************************************************************************** |
| 21 | | INLINE FUNCTIONS |
| 22 | | *****************************************************************************/ |
| 23 | | INLINE teleprinter_state *get_safe_token(device_t *device) |
| 24 | | { |
| 25 | | assert(device != NULL); |
| 26 | | assert(device->type() == GENERIC_TELEPRINTER); |
| 27 | | |
| 28 | | return (teleprinter_state *)downcast<legacy_device_base *>(device)->token(); |
| 29 | | } |
| 30 | | |
| 31 | | INLINE const teleprinter_interface *get_interface(device_t *device) |
| 32 | | { |
| 33 | | assert(device != NULL); |
| 34 | | assert(device->type() == GENERIC_TELEPRINTER); |
| 35 | | return (const teleprinter_interface *) device->static_config(); |
| 36 | | } |
| 37 | | |
| 38 | | /*************************************************************************** |
| 39 | | IMPLEMENTATION |
| 40 | | ***************************************************************************/ |
| 41 | | |
| 42 | 3 | static const UINT8 teleprinter_font[128*8] = |
| 43 | 4 | { |
| 44 | 5 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
| r14605 | r14606 | |
| 171 | 132 | 0x2a,0x15,0x2a,0x15,0x2a,0x15,0x2a,0x15 |
| 172 | 133 | }; |
| 173 | 134 | |
| 174 | | static void teleprinter_scroll_line(device_t *device) |
| 135 | teleprinter_device::teleprinter_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 136 | : generic_terminal_device(mconfig, TELEPRINTER, "Teleprinter", tag, owner, clock) |
| 175 | 137 | { |
| 176 | | teleprinter_state *term = get_safe_token(device); |
| 138 | } |
| 177 | 139 | |
| 178 | | memcpy(term->buffer,term->buffer+TELEPRINTER_WIDTH,(TELEPRINTER_HEIGHT-1)*TELEPRINTER_WIDTH); |
| 179 | | memset(term->buffer + TELEPRINTER_WIDTH*(TELEPRINTER_HEIGHT-1),0x20,TELEPRINTER_WIDTH); |
| 140 | void teleprinter_device::scroll_line() |
| 141 | { |
| 142 | memcpy(m_buffer,m_buffer+TELEPRINTER_WIDTH,(TELEPRINTER_HEIGHT-1)*TELEPRINTER_WIDTH); |
| 143 | memset(m_buffer + TELEPRINTER_WIDTH*(TELEPRINTER_HEIGHT-1),0x20,TELEPRINTER_WIDTH); |
| 180 | 144 | } |
| 181 | 145 | |
| 182 | | static void teleprinter_write_char(device_t *device,UINT8 data) { |
| 183 | | teleprinter_state *term = get_safe_token(device); |
| 184 | | |
| 185 | | term->buffer[(TELEPRINTER_HEIGHT-1)*TELEPRINTER_WIDTH+term->x_pos] = data; |
| 186 | | term->x_pos++; |
| 187 | | if (term->x_pos >= TELEPRINTER_WIDTH) |
| 146 | void teleprinter_device::write_char(UINT8 data) { |
| 147 | m_buffer[(TELEPRINTER_HEIGHT-1)*TELEPRINTER_WIDTH+m_x_pos] = data; |
| 148 | m_x_pos++; |
| 149 | if (m_x_pos >= TELEPRINTER_WIDTH) |
| 188 | 150 | { |
| 189 | | term->x_pos = 0; |
| 190 | | teleprinter_scroll_line(device); |
| 151 | m_x_pos = 0; |
| 152 | scroll_line(); |
| 191 | 153 | } |
| 192 | 154 | } |
| 193 | 155 | |
| 194 | | static void teleprinter_clear(device_t *device) { |
| 195 | | teleprinter_state *term = get_safe_token(device); |
| 196 | | |
| 197 | | memset(term->buffer,0,TELEPRINTER_WIDTH*TELEPRINTER_HEIGHT); |
| 198 | | term->x_pos = 0; |
| 156 | void teleprinter_device::clear() { |
| 157 | memset(m_buffer,0,TELEPRINTER_WIDTH*TELEPRINTER_HEIGHT); |
| 158 | m_x_pos = 0; |
| 199 | 159 | } |
| 200 | 160 | |
| 201 | | WRITE8_DEVICE_HANDLER ( teleprinter_write ) |
| 161 | void teleprinter_device::term_write(UINT8 data) |
| 202 | 162 | { |
| 203 | | teleprinter_state *term = get_safe_token(device); |
| 204 | 163 | switch(data) { |
| 205 | | case 10: term->x_pos = 0; |
| 206 | | teleprinter_scroll_line(device); |
| 164 | case 10: m_x_pos = 0; |
| 165 | scroll_line(); |
| 207 | 166 | break; |
| 208 | | case 13: term->x_pos = 0; break; |
| 209 | | case 9: term->x_pos = (term->x_pos & 0xf8) + 8; |
| 210 | | if (term->x_pos >= TELEPRINTER_WIDTH) |
| 211 | | term->x_pos = TELEPRINTER_WIDTH-1; |
| 167 | case 13: m_x_pos = 0; break; |
| 168 | case 9: m_x_pos = (m_x_pos & 0xf8) + 8; |
| 169 | if (m_x_pos >= TELEPRINTER_WIDTH) |
| 170 | m_x_pos = TELEPRINTER_WIDTH-1; |
| 212 | 171 | |
| 213 | 172 | break; |
| 214 | 173 | case 16: break; |
| 215 | | default: teleprinter_write_char(device,data); break; |
| 174 | default: write_char(data); break; |
| 216 | 175 | } |
| 217 | 176 | } |
| 218 | 177 | |
| 219 | 178 | /*************************************************************************** |
| 220 | 179 | VIDEO HARDWARE |
| 221 | 180 | ***************************************************************************/ |
| 222 | | static void generic_teleprinter_update(device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 181 | UINT32 teleprinter_device::tp_update(screen_device &device, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 223 | 182 | { |
| 224 | 183 | UINT8 code; |
| 225 | 184 | int y, c, x, b; |
| 226 | | teleprinter_state *term = get_safe_token(device); |
| 227 | 185 | |
| 228 | 186 | for (y = 0; y < TELEPRINTER_HEIGHT; y++) |
| 229 | 187 | { |
| r14605 | r14606 | |
| 232 | 190 | int horpos = 0; |
| 233 | 191 | for (x = 0; x < TELEPRINTER_WIDTH; x++) |
| 234 | 192 | { |
| 235 | | code = teleprinter_font[(term->buffer[y*TELEPRINTER_WIDTH + x] & 0x7f) *8 + c]; |
| 193 | code = teleprinter_font[(m_buffer[y*TELEPRINTER_WIDTH + x] & 0x7f) *8 + c]; |
| 236 | 194 | for (b = 0; b < 8; b++) |
| 237 | 195 | { |
| 238 | | bitmap.pix16(y*8 + c, horpos++) = (code >> b) & 0x01 ? 0 : 1; |
| 196 | bitmap.pix32(y*8 + c, horpos++) = (code >> b) & 0x01 ? 0 : 0x00ffffff; |
| 239 | 197 | } |
| 240 | 198 | } |
| 241 | 199 | } |
| 242 | 200 | } |
| 201 | return 0; |
| 243 | 202 | } |
| 244 | 203 | |
| 245 | | static TIMER_CALLBACK(keyboard_callback) |
| 246 | | { |
| 247 | | UINT8 new_code; |
| 248 | | teleprinter_state *term = get_safe_token((device_t *)ptr); |
| 249 | | new_code = terminal_keyboard_handler(machine, term->last_code, &term->scan_line, NULL, NULL, (device_t *)ptr); |
| 250 | | |
| 251 | | if(new_code != term->last_code) |
| 252 | | term->teleprinter_keyboard_func(0, new_code); |
| 253 | | term->last_code = new_code; |
| 254 | | } |
| 255 | | |
| 256 | 204 | /*************************************************************************** |
| 257 | 205 | VIDEO HARDWARE |
| 258 | 206 | ***************************************************************************/ |
| 259 | | static VIDEO_START( teleprinter ) |
| 260 | | { |
| 261 | | |
| 262 | | } |
| 263 | | |
| 264 | | static SCREEN_UPDATE_IND16(teleprinter ) |
| 265 | | { |
| 266 | | device_t *devconf = screen.machine().device(TELEPRINTER_TAG); |
| 267 | | generic_teleprinter_update( devconf, bitmap, cliprect); |
| 268 | | return 0; |
| 269 | | } |
| 270 | | |
| 271 | 207 | MACHINE_CONFIG_FRAGMENT( generic_teleprinter ) |
| 272 | 208 | MCFG_SCREEN_ADD(TELEPRINTER_SCREEN_TAG, RASTER) |
| 273 | 209 | MCFG_SCREEN_REFRESH_RATE(50) |
| 274 | 210 | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| 275 | 211 | MCFG_SCREEN_SIZE(TELEPRINTER_WIDTH*8, TELEPRINTER_HEIGHT*8) |
| 276 | 212 | MCFG_SCREEN_VISIBLE_AREA(0, TELEPRINTER_WIDTH*8-1, 0, TELEPRINTER_HEIGHT*8-1) |
| 277 | | MCFG_SCREEN_UPDATE_STATIC(teleprinter) |
| 278 | | |
| 279 | | MCFG_PALETTE_LENGTH(2) |
| 280 | | MCFG_PALETTE_INIT(black_and_white) |
| 281 | | |
| 282 | | MCFG_VIDEO_START(teleprinter) |
| 213 | MCFG_SCREEN_UPDATE_DEVICE(DEVICE_SELF, teleprinter_device, tp_update) |
| 283 | 214 | MACHINE_CONFIG_END |
| 284 | 215 | |
| 285 | | |
| 286 | | /*------------------------------------------------- |
| 287 | | DEVICE_START( teleprinter ) |
| 288 | | -------------------------------------------------*/ |
| 289 | | |
| 290 | | static DEVICE_START( teleprinter ) |
| 216 | machine_config_constructor teleprinter_device::device_mconfig_additions() const |
| 291 | 217 | { |
| 292 | | teleprinter_state *term = get_safe_token(device); |
| 293 | | const teleprinter_interface *intf = get_interface(device); |
| 294 | | |
| 295 | | term->teleprinter_keyboard_func.resolve(intf->teleprinter_keyboard_func, *device); |
| 296 | | |
| 297 | | if (!term->teleprinter_keyboard_func.isnull()) |
| 298 | | device->machine().scheduler().timer_pulse(attotime::from_hz(240), FUNC(keyboard_callback), 0, (void*)device); |
| 218 | return MACHINE_CONFIG_NAME(generic_teleprinter); |
| 299 | 219 | } |
| 300 | 220 | |
| 301 | 221 | /*------------------------------------------------- |
| 302 | 222 | DEVICE_RESET( teleprinter ) |
| 303 | 223 | -------------------------------------------------*/ |
| 304 | 224 | |
| 305 | | static DEVICE_RESET( teleprinter ) |
| 225 | void teleprinter_device::device_reset() |
| 306 | 226 | { |
| 307 | | teleprinter_state *term = get_safe_token(device); |
| 308 | | |
| 309 | | teleprinter_clear(device); |
| 310 | | term->last_code = 0; |
| 311 | | term->scan_line = 0; |
| 227 | clear(); |
| 228 | generic_terminal_device::device_reset(); |
| 312 | 229 | } |
| 313 | 230 | |
| 314 | | /*------------------------------------------------- |
| 315 | | DEVICE_GET_INFO( teleprinter ) |
| 316 | | -------------------------------------------------*/ |
| 317 | | |
| 318 | | DEVICE_GET_INFO( teleprinter ) |
| 319 | | { |
| 320 | | switch (state) |
| 321 | | { |
| 322 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 323 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 324 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(teleprinter_state); break; |
| 325 | | |
| 326 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 327 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(teleprinter); break; |
| 328 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 329 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(teleprinter); break; |
| 330 | | |
| 331 | | case DEVINFO_PTR_INPUT_PORTS: info->ipt = INPUT_PORTS_NAME(generic_terminal); break; |
| 332 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 333 | | case DEVINFO_STR_NAME: strcpy(info->s, "Generic Teleprinter"); break; |
| 334 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Teleprinter"); break; |
| 335 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 336 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 337 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 338 | | } |
| 339 | | } |
| 340 | | |
| 341 | | DEFINE_LEGACY_DEVICE(GENERIC_TELEPRINTER, teleprinter); |
| 231 | const device_type TELEPRINTER = &device_creator<teleprinter_device>; |
src/mess/machine/terminal.c
| r14605 | r14606 | |
| 1 | | #include "emu.h" |
| 2 | 1 | #include "machine/terminal.h" |
| 3 | 2 | |
| 4 | 3 | /*************************************************************************** |
| 5 | | TYPE DEFINITIONS |
| 6 | | ***************************************************************************/ |
| 7 | | enum |
| 8 | | { |
| 9 | | START = 0, |
| 10 | | STOP = 9, |
| 11 | | DONE = 10 |
| 12 | | }; |
| 13 | | |
| 14 | | #define TERMINAL_WIDTH 80 |
| 15 | | #define TERMINAL_HEIGHT 24 |
| 16 | | typedef struct _terminal_state terminal_state; |
| 17 | | struct _terminal_state |
| 18 | | { |
| 19 | | UINT8 framecnt; |
| 20 | | UINT8 buffer[TERMINAL_WIDTH*TERMINAL_HEIGHT]; |
| 21 | | UINT8 x_pos; |
| 22 | | UINT8 y_pos; |
| 23 | | UINT8 last_code; |
| 24 | | UINT8 scan_line; |
| 25 | | int rx_state; |
| 26 | | int tx_state; |
| 27 | | UINT8 rx_shift; |
| 28 | | UINT8 tx_shift; |
| 29 | | devcb_resolved_write8 terminal_keyboard_func; |
| 30 | | }; |
| 31 | | |
| 32 | | /***************************************************************************** |
| 33 | | INLINE FUNCTIONS |
| 34 | | *****************************************************************************/ |
| 35 | | INLINE terminal_state *get_safe_token(device_t *device) |
| 36 | | { |
| 37 | | assert(device != NULL); |
| 38 | | assert(device->type() == GENERIC_TERMINAL); |
| 39 | | |
| 40 | | return (terminal_state *)downcast<legacy_device_base *>(device)->token(); |
| 41 | | } |
| 42 | | |
| 43 | | INLINE const terminal_interface *get_interface(device_t *device) |
| 44 | | { |
| 45 | | assert(device != NULL); |
| 46 | | assert(device->type() == GENERIC_TERMINAL); |
| 47 | | return (const terminal_interface *) device->static_config(); |
| 48 | | } |
| 49 | | |
| 50 | | /*************************************************************************** |
| 51 | 4 | IMPLEMENTATION |
| 52 | 5 | ***************************************************************************/ |
| 53 | 6 | |
| r14605 | r14606 | |
| 183 | 136 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 184 | 137 | }; |
| 185 | 138 | |
| 186 | | static void terminal_scroll_line(device_t *device) |
| 139 | generic_terminal_device::generic_terminal_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) |
| 140 | : device_t(mconfig, type, name, tag, owner, clock) |
| 187 | 141 | { |
| 188 | | terminal_state *term = get_safe_token(device); |
| 189 | | |
| 190 | | memcpy(term->buffer,term->buffer+TERMINAL_WIDTH,(TERMINAL_HEIGHT-1)*TERMINAL_WIDTH); |
| 191 | | memset(term->buffer + TERMINAL_WIDTH*(TERMINAL_HEIGHT-1),0x20,TERMINAL_WIDTH); |
| 192 | 142 | } |
| 193 | 143 | |
| 194 | | static void terminal_write_char(device_t *device,UINT8 data) { |
| 195 | | terminal_state *term = get_safe_token(device); |
| 196 | | |
| 197 | | term->buffer[term->y_pos*TERMINAL_WIDTH+term->x_pos] = data; |
| 198 | | term->x_pos++; |
| 199 | | if (term->x_pos >= TERMINAL_WIDTH) |
| 200 | | { |
| 201 | | term->x_pos = 0; |
| 202 | | term->y_pos++; |
| 203 | | if (term->y_pos >= TERMINAL_HEIGHT) |
| 204 | | { |
| 205 | | terminal_scroll_line(device); |
| 206 | | term->y_pos = TERMINAL_HEIGHT-1; |
| 207 | | } |
| 208 | | } |
| 144 | generic_terminal_device::generic_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 145 | : device_t(mconfig, GENERIC_TERMINAL, "Generic Terminal", tag, owner, clock) |
| 146 | { |
| 209 | 147 | } |
| 210 | 148 | |
| 211 | | static void terminal_clear(device_t *device) { |
| 212 | | terminal_state *term = get_safe_token(device); |
| 213 | | |
| 214 | | memset(term->buffer,0x20,TERMINAL_WIDTH*TERMINAL_HEIGHT); |
| 215 | | term->x_pos = 0; |
| 216 | | term->y_pos = 0; |
| 149 | void generic_terminal_device::scroll_line() |
| 150 | { |
| 151 | memcpy(m_buffer,m_buffer+TERMINAL_WIDTH,(TERMINAL_HEIGHT-1)*TERMINAL_WIDTH); |
| 152 | memset(m_buffer + TERMINAL_WIDTH*(TERMINAL_HEIGHT-1),0x20,TERMINAL_WIDTH); |
| 217 | 153 | } |
| 218 | 154 | |
| 219 | | READ_LINE_DEVICE_HANDLER( terminal_serial_r ) |
| 155 | void generic_terminal_device::write_char(UINT8 data) |
| 220 | 156 | { |
| 221 | | terminal_state *term = get_safe_token(device); |
| 222 | | |
| 223 | | UINT8 data = 1; |
| 224 | | |
| 225 | | switch (term->tx_state) |
| 157 | m_buffer[m_y_pos*TERMINAL_WIDTH+m_x_pos] = data; |
| 158 | m_x_pos++; |
| 159 | if (m_x_pos >= TERMINAL_WIDTH) |
| 226 | 160 | { |
| 227 | | case DONE: |
| 228 | | break; |
| 229 | | case STOP: |
| 230 | | data = 1; |
| 231 | | term->tx_state++; |
| 232 | | break; |
| 233 | | |
| 234 | | case START: |
| 235 | | data = 0; |
| 236 | | term->tx_state++; |
| 237 | | break; |
| 238 | | |
| 239 | | default: |
| 240 | | data = BIT(term->tx_shift, 0); |
| 241 | | term->tx_shift >>= 1; |
| 242 | | term->tx_state++; |
| 243 | | break; |
| 161 | m_x_pos = 0; |
| 162 | m_y_pos++; |
| 163 | if (m_y_pos >= TERMINAL_HEIGHT) |
| 164 | { |
| 165 | scroll_line(); |
| 166 | m_y_pos = TERMINAL_HEIGHT-1; |
| 167 | } |
| 244 | 168 | } |
| 245 | | |
| 246 | | return data; |
| 247 | 169 | } |
| 248 | 170 | |
| 249 | | WRITE_LINE_DEVICE_HANDLER( terminal_serial_w ) |
| 171 | void generic_terminal_device::clear() |
| 250 | 172 | { |
| 251 | | terminal_state *term = get_safe_token(device); |
| 252 | | |
| 253 | | switch (term->rx_state) |
| 254 | | { |
| 255 | | case START: |
| 256 | | if (!state) term->rx_state++; |
| 257 | | break; |
| 258 | | |
| 259 | | case STOP: |
| 260 | | terminal_write(device, 0, term->rx_shift); |
| 261 | | term->rx_state = START; |
| 262 | | break; |
| 263 | | |
| 264 | | default: |
| 265 | | term->rx_shift >>= 1; |
| 266 | | term->rx_shift |= (state << 7); |
| 267 | | term->rx_state++; |
| 268 | | break; |
| 269 | | } |
| 173 | memset(m_buffer,0x20,TERMINAL_WIDTH*TERMINAL_HEIGHT); |
| 174 | m_x_pos = 0; |
| 175 | m_y_pos = 0; |
| 270 | 176 | } |
| 271 | 177 | |
| 272 | | WRITE8_DEVICE_HANDLER ( terminal_write ) |
| 178 | void generic_terminal_device::term_write(UINT8 data) |
| 273 | 179 | { |
| 274 | | terminal_state *term = get_safe_token(device); |
| 275 | 180 | if (data > 0x1f) |
| 276 | 181 | { |
| 277 | 182 | // printable char |
| 278 | | if (data!=0x7f) terminal_write_char(device,data); |
| 183 | if (data!=0x7f) write_char(data); |
| 279 | 184 | } |
| 280 | 185 | else |
| 281 | 186 | { |
| r14605 | r14606 | |
| 284 | 189 | case 0x07 : // bell |
| 285 | 190 | break; |
| 286 | 191 | |
| 287 | | case 0x08: if (term->x_pos) term->x_pos--; |
| 192 | case 0x08: if (m_x_pos) m_x_pos--; |
| 288 | 193 | break; |
| 289 | 194 | |
| 290 | | case 0x09: term->x_pos = (term->x_pos & 0xf8) + 8; |
| 291 | | if (term->x_pos >= TERMINAL_WIDTH) |
| 292 | | term->x_pos = TERMINAL_WIDTH-1; |
| 195 | case 0x09: m_x_pos = (m_x_pos & 0xf8) + 8; |
| 196 | if (m_x_pos >= TERMINAL_WIDTH) |
| 197 | m_x_pos = TERMINAL_WIDTH-1; |
| 293 | 198 | break; |
| 294 | 199 | |
| 295 | | case 0x0a: term->y_pos++; |
| 296 | | term->x_pos = 0; |
| 297 | | if (term->y_pos >= TERMINAL_HEIGHT) |
| 200 | case 0x0a: m_y_pos++; |
| 201 | m_x_pos = 0; |
| 202 | if (m_y_pos >= TERMINAL_HEIGHT) |
| 298 | 203 | { |
| 299 | | terminal_scroll_line(device); |
| 300 | | term->y_pos = TERMINAL_HEIGHT-1; |
| 204 | scroll_line(); |
| 205 | m_y_pos = TERMINAL_HEIGHT-1; |
| 301 | 206 | } |
| 302 | 207 | break; |
| 303 | 208 | |
| 304 | | case 0x0b: if (term->y_pos) term->y_pos--; |
| 209 | case 0x0b: if (m_y_pos) m_y_pos--; |
| 305 | 210 | break; |
| 306 | 211 | |
| 307 | | case 0x0d: term->x_pos = 0; |
| 212 | case 0x0d: m_x_pos = 0; |
| 308 | 213 | break; |
| 309 | 214 | |
| 310 | | case 0x1e: term->x_pos = 0; |
| 311 | | term->y_pos = 0; |
| 215 | case 0x1e: m_x_pos = 0; |
| 216 | m_y_pos = 0; |
| 312 | 217 | break; |
| 313 | 218 | } |
| 314 | 219 | } |
| r14605 | r14606 | |
| 317 | 222 | /*************************************************************************** |
| 318 | 223 | VIDEO HARDWARE |
| 319 | 224 | ***************************************************************************/ |
| 320 | | static void generic_terminal_update(device_t *device, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 225 | UINT32 generic_terminal_device::update(screen_device &device, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 321 | 226 | { |
| 322 | | terminal_state *term = get_safe_token(device); |
| 323 | | UINT8 options = input_port_read(*device, "TERM_CONF"); |
| 324 | | UINT16 cursor = term->y_pos * TERMINAL_WIDTH + term->x_pos; |
| 227 | UINT8 options = input_port_read(*this, "TERM_CONF"); |
| 228 | UINT16 cursor = m_y_pos * TERMINAL_WIDTH + m_x_pos; |
| 325 | 229 | UINT8 y,ra,chr,gfx; |
| 326 | 230 | UINT16 sy=0,ma=0,x; |
| 327 | 231 | UINT32 font_color; |
| r14605 | r14606 | |
| 338 | 242 | break; |
| 339 | 243 | } |
| 340 | 244 | |
| 341 | | term->framecnt++; |
| 245 | m_framecnt++; |
| 342 | 246 | |
| 343 | 247 | for (y = 0; y < TERMINAL_HEIGHT; y++) |
| 344 | 248 | { |
| r14605 | r14606 | |
| 348 | 252 | |
| 349 | 253 | for (x = ma; x < ma + TERMINAL_WIDTH; x++) |
| 350 | 254 | { |
| 351 | | chr = term->buffer[x]; |
| 255 | chr = m_buffer[x]; |
| 352 | 256 | gfx = terminal_font[(chr<<4) | ra ]; |
| 353 | 257 | |
| 354 | 258 | if ((x == cursor) && (options & 1)) // at cursor position and want a cursor |
| 355 | 259 | { |
| 356 | 260 | if ((options & 2) || (ra == 9)) // block, or underline & at bottom line |
| 357 | 261 | { |
| 358 | | if ((options & 4) && (term->framecnt & 8)) // want blink & time to blink |
| 262 | if ((options & 4) && (m_framecnt & 8)) // want blink & time to blink |
| 359 | 263 | { |
| 360 | 264 | } |
| 361 | 265 | else |
| r14605 | r14606 | |
| 381 | 285 | } |
| 382 | 286 | ma+=TERMINAL_WIDTH; |
| 383 | 287 | } |
| 288 | return 0; |
| 384 | 289 | } |
| 385 | 290 | |
| 386 | | static UINT8 row_number(UINT8 code) { |
| 291 | UINT8 generic_terminal_device::row_number(UINT8 code) { |
| 387 | 292 | if BIT(code,0) return 0; |
| 388 | 293 | if BIT(code,1) return 1; |
| 389 | 294 | if BIT(code,2) return 2; |
| r14605 | r14606 | |
| 395 | 300 | return 0; |
| 396 | 301 | } |
| 397 | 302 | |
| 398 | | UINT8 terminal_keyboard_handler(running_machine &machine, UINT8 last_code, UINT8 *scan_line, UINT8 *tx_shift, int *tx_state, device_t *device) |
| 303 | UINT8 generic_terminal_device::keyboard_handler(UINT8 last_code, UINT8 *scan_line) |
| 399 | 304 | { |
| 400 | 305 | static const char *const keynames[] = { "TERM_LINE0", "TERM_LINE1", "TERM_LINE2", "TERM_LINE3", "TERM_LINE4", "TERM_LINE5", "TERM_LINE6", "TERM_LINE7" }; |
| 401 | 306 | int i; |
| 402 | 307 | UINT8 code; |
| 403 | 308 | UINT8 key_code = 0; |
| 404 | 309 | UINT8 retVal = 0; |
| 405 | | UINT8 shift = BIT(input_port_read(*device, "TERM_LINEC"), 1); |
| 406 | | UINT8 caps = BIT(input_port_read(*device, "TERM_LINEC"), 2); |
| 407 | | UINT8 ctrl = BIT(input_port_read(*device, "TERM_LINEC"), 0); |
| 310 | UINT8 shift = BIT(input_port_read(*this, "TERM_LINEC"), 1); |
| 311 | UINT8 caps = BIT(input_port_read(*this, "TERM_LINEC"), 2); |
| 312 | UINT8 ctrl = BIT(input_port_read(*this, "TERM_LINEC"), 0); |
| 408 | 313 | i = *scan_line; |
| 409 | 314 | { |
| 410 | | code = input_port_read(*device, keynames[i]); |
| 315 | code = input_port_read(*this, keynames[i]); |
| 411 | 316 | if (code != 0) |
| 412 | 317 | { |
| 413 | 318 | if (i==0 && shift==0) { |
| r14605 | r14606 | |
| 484 | 389 | case 0: key_code = 0x1B; break; // Escape |
| 485 | 390 | } |
| 486 | 391 | } |
| 487 | | if (last_code != key_code ) { |
| 488 | | if (tx_shift) *tx_shift = key_code; |
| 489 | | if (tx_state) *tx_state = START; |
| 490 | | } |
| 491 | 392 | retVal = key_code; |
| 492 | 393 | } else { |
| 493 | 394 | *scan_line += 1; |
| r14605 | r14606 | |
| 499 | 400 | return retVal; |
| 500 | 401 | } |
| 501 | 402 | |
| 502 | | static TIMER_CALLBACK(keyboard_callback) |
| 403 | void generic_terminal_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 503 | 404 | { |
| 504 | 405 | UINT8 new_code; |
| 505 | | terminal_state *term = get_safe_token((device_t *)ptr); |
| 506 | | new_code = terminal_keyboard_handler(machine, term->last_code, &term->scan_line, &term->tx_shift, &term->tx_state, (device_t *)ptr); |
| 507 | | if(term->last_code != new_code) |
| 508 | | term->terminal_keyboard_func(0, new_code); |
| 509 | | term->last_code = new_code; |
| 406 | new_code = keyboard_handler(m_last_code, &m_scan_line); |
| 407 | if(m_last_code != new_code) |
| 408 | send_key(new_code); |
| 409 | m_last_code = new_code; |
| 510 | 410 | } |
| 511 | 411 | |
| 512 | | static TIMER_CALLBACK(serial_callback) |
| 513 | | { |
| 514 | | static int count = 0; |
| 515 | | terminal_state *term = get_safe_token((device_t *)ptr); |
| 516 | | if(term->tx_state == DONE) { |
| 517 | | if(count == 0) { |
| 518 | | term->last_code = terminal_keyboard_handler(machine, term->last_code, &term->scan_line, &term->tx_shift, &term->tx_state, (device_t *)ptr); |
| 519 | | } else |
| 520 | | ++count %= 8; |
| 521 | | } else |
| 522 | | term->terminal_keyboard_func(0, terminal_serial_r((device_t *)ptr)); |
| 523 | | } |
| 524 | | |
| 525 | 412 | /*************************************************************************** |
| 526 | 413 | VIDEO HARDWARE |
| 527 | 414 | ***************************************************************************/ |
| 528 | 415 | |
| 529 | | static SCREEN_UPDATE_RGB32(terminal ) |
| 530 | | { |
| 531 | | device_t *devconf = screen.owner(); |
| 532 | | generic_terminal_update( devconf, bitmap, cliprect); |
| 533 | | return 0; |
| 534 | | } |
| 535 | | |
| 536 | 416 | static MACHINE_CONFIG_FRAGMENT( generic_terminal ) |
| 537 | 417 | MCFG_SCREEN_ADD(TERMINAL_SCREEN_TAG, RASTER) |
| 538 | 418 | MCFG_SCREEN_REFRESH_RATE(50) |
| 539 | 419 | MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| 540 | 420 | MCFG_SCREEN_SIZE(TERMINAL_WIDTH*8, TERMINAL_HEIGHT*10) |
| 541 | 421 | MCFG_SCREEN_VISIBLE_AREA(0, TERMINAL_WIDTH*8-1, 0, TERMINAL_HEIGHT*10-1) |
| 542 | | MCFG_SCREEN_UPDATE_STATIC(terminal) |
| 422 | MCFG_SCREEN_UPDATE_DEVICE(DEVICE_SELF, generic_terminal_device, update) |
| 543 | 423 | MACHINE_CONFIG_END |
| 544 | 424 | |
| 425 | machine_config_constructor generic_terminal_device::device_mconfig_additions() const |
| 426 | { |
| 427 | return MACHINE_CONFIG_NAME(generic_terminal); |
| 428 | } |
| 545 | 429 | |
| 546 | | /*------------------------------------------------- |
| 547 | | DEVICE_START( terminal ) |
| 548 | | -------------------------------------------------*/ |
| 549 | | |
| 550 | | static DEVICE_START( terminal ) |
| 430 | void generic_terminal_device::device_start() |
| 551 | 431 | { |
| 552 | | terminal_state *term = get_safe_token(device); |
| 553 | | const terminal_interface *intf = get_interface(device); |
| 554 | | term->terminal_keyboard_func.resolve(intf->terminal_keyboard_func, *device); |
| 432 | m_keyboard_func.resolve(m_keyboard_cb, *this); |
| 433 | m_timer = timer_alloc(); |
| 434 | } |
| 555 | 435 | |
| 556 | | if (device->clock()) |
| 557 | | device->machine().scheduler().timer_pulse(attotime::from_hz(device->clock()), FUNC(serial_callback), 0, (void*)device); |
| 558 | | else if (!term->terminal_keyboard_func.isnull()) |
| 559 | | device->machine().scheduler().timer_pulse(attotime::from_hz(2400), FUNC(keyboard_callback), 0, (void*)device); |
| 436 | void generic_terminal_device::device_config_complete() |
| 437 | { |
| 438 | const _terminal_interface *intf = reinterpret_cast<const _terminal_interface *>(static_config()); |
| 439 | if(intf != NULL) |
| 440 | { |
| 441 | *static_cast<_terminal_interface *>(this) = *intf; |
| 442 | } |
| 443 | else |
| 444 | { |
| 445 | memset(&m_keyboard_cb, 0, sizeof(m_keyboard_cb)); |
| 446 | } |
| 560 | 447 | } |
| 561 | 448 | |
| 562 | | /*------------------------------------------------- |
| 563 | | DEVICE_RESET( terminal ) |
| 564 | | -------------------------------------------------*/ |
| 565 | | |
| 566 | | static DEVICE_RESET( terminal ) |
| 449 | void generic_terminal_device::device_reset() |
| 567 | 450 | { |
| 568 | | terminal_state *term = get_safe_token(device); |
| 569 | | terminal_clear(device); |
| 570 | | term->last_code = 0; |
| 571 | | term->scan_line = 0; |
| 572 | | term->rx_state = START; |
| 573 | | term->tx_state = DONE; |
| 451 | clear(); |
| 452 | m_last_code = 0; |
| 453 | m_scan_line = 0; |
| 454 | m_timer->adjust(attotime::from_hz(2400), 0, attotime::from_hz(2400)); |
| 574 | 455 | } |
| 575 | 456 | |
| 576 | 457 | /* |
| r14605 | r14606 | |
| 610 | 491 | (us) 31 0037 0x1f | ? 63 0077 0x3f | _ 95 0137 0x5f | (del) 127 0177 0x7f |
| 611 | 492 | |
| 612 | 493 | */ |
| 613 | | INPUT_PORTS_START( generic_terminal ) |
| 494 | static INPUT_PORTS_START( generic_terminal ) |
| 614 | 495 | PORT_START("TERM_LINEC") |
| 615 | 496 | PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Ctrl") PORT_CODE(KEYCODE_LCONTROL) PORT_CODE(KEYCODE_RCONTROL) |
| 616 | 497 | PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYBOARD) PORT_NAME("Shift") PORT_CODE(KEYCODE_LSHIFT) PORT_CODE(KEYCODE_RSHIFT) PORT_CHAR(UCHAR_SHIFT_1) |
| r14605 | r14606 | |
| 713 | 594 | PORT_CONFSETTING( 0x20, "White") |
| 714 | 595 | INPUT_PORTS_END |
| 715 | 596 | |
| 716 | | /*------------------------------------------------- |
| 717 | | DEVICE_GET_INFO( terminal ) |
| 718 | | -------------------------------------------------*/ |
| 597 | ioport_constructor generic_terminal_device::device_input_ports() const |
| 598 | { |
| 599 | return INPUT_PORTS_NAME(generic_terminal); |
| 600 | } |
| 719 | 601 | |
| 720 | | DEVICE_GET_INFO( terminal ) |
| 602 | const device_type GENERIC_TERMINAL = &device_creator<generic_terminal_device>; |
| 603 | |
| 604 | static INPUT_PORTS_START(serial_terminal) |
| 605 | PORT_INCLUDE(generic_terminal) |
| 606 | PORT_START("TERM_FRAME") |
| 607 | PORT_CONFNAME(0x0f, 0x06, "Baud") PORT_CHANGED_MEMBER(DEVICE_SELF, serial_terminal_device, update_frame, 0) |
| 608 | PORT_CONFSETTING( 0x00, "150") |
| 609 | PORT_CONFSETTING( 0x01, "300") |
| 610 | PORT_CONFSETTING( 0x02, "600") |
| 611 | PORT_CONFSETTING( 0x03, "1200") |
| 612 | PORT_CONFSETTING( 0x04, "2400") |
| 613 | PORT_CONFSETTING( 0x05, "4800") |
| 614 | PORT_CONFSETTING( 0x06, "9600") |
| 615 | PORT_CONFSETTING( 0x07, "14400") |
| 616 | PORT_CONFSETTING( 0x08, "19200") |
| 617 | PORT_CONFSETTING( 0x09, "28800") |
| 618 | PORT_CONFSETTING( 0x0a, "38400") |
| 619 | PORT_CONFSETTING( 0x0b, "57600") |
| 620 | PORT_CONFSETTING( 0x0c, "115200") |
| 621 | PORT_CONFNAME(0x30, 0x00, "Format") PORT_CHANGED_MEMBER(DEVICE_SELF, serial_terminal_device, update_frame, 0) |
| 622 | PORT_CONFSETTING( 0x00, "8N1") |
| 623 | PORT_CONFSETTING( 0x10, "7E1") |
| 624 | INPUT_PORTS_END |
| 625 | |
| 626 | ioport_constructor serial_terminal_device::device_input_ports() const |
| 721 | 627 | { |
| 722 | | switch (state) |
| 628 | return INPUT_PORTS_NAME(serial_terminal); |
| 629 | } |
| 630 | |
| 631 | serial_terminal_device::serial_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 632 | : generic_terminal_device(mconfig, SERIAL_TERMINAL, "Serial Terminal", tag, owner, clock), |
| 633 | device_serial_interface(mconfig, *this), |
| 634 | device_serial_port_interface(mconfig, *this) |
| 635 | { |
| 636 | } |
| 637 | |
| 638 | void serial_terminal_device::device_config_complete() |
| 639 | { |
| 640 | const serial_terminal_interface *intf = reinterpret_cast<const serial_terminal_interface *>(static_config()); |
| 641 | if(intf != NULL) |
| 723 | 642 | { |
| 724 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 725 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 726 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(terminal_state); break; |
| 643 | *static_cast<serial_terminal_interface *>(this) = *intf; |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | memset(&m_out_tx_cb, 0, sizeof(m_out_tx_cb)); |
| 648 | } |
| 649 | m_shortname = "serial_terminal"; |
| 650 | } |
| 727 | 651 | |
| 728 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 729 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(terminal); break; |
| 730 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 731 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(terminal); break; |
| 652 | static int rates[] = {150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200}; |
| 732 | 653 | |
| 733 | | case DEVINFO_PTR_INPUT_PORTS: info->ipt = INPUT_PORTS_NAME(generic_terminal); break; |
| 734 | | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = MACHINE_CONFIG_NAME(generic_terminal); break; |
| 735 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 736 | | case DEVINFO_STR_NAME: strcpy(info->s, "Generic Terminal"); break; |
| 737 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Terminal"); break; |
| 738 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 739 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 740 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 654 | void serial_terminal_device::device_start() |
| 655 | { |
| 656 | int baud = clock(); |
| 657 | if(!baud) baud = 9600; |
| 658 | m_owner = dynamic_cast<serial_port_device *>(owner()); |
| 659 | m_out_tx_func.resolve(m_out_tx_cb, *this); |
| 660 | m_slot = m_owner && 1; |
| 661 | m_timer = timer_alloc(); |
| 662 | set_rcv_rate(baud); |
| 663 | set_tra_rate(baud); |
| 664 | set_data_frame(8, 1, SERIAL_PARITY_NONE); |
| 665 | } |
| 666 | |
| 667 | INPUT_CHANGED_MEMBER(serial_terminal_device::update_frame) |
| 668 | { |
| 669 | set_tra_rate(rates[newval & 0x0f]); |
| 670 | set_rcv_rate(rates[newval & 0x0f]); |
| 671 | |
| 672 | switch(newval & 0x30) |
| 673 | { |
| 674 | case 0x10: |
| 675 | set_data_frame(7, 1, SERIAL_PARITY_EVEN); |
| 676 | break; |
| 677 | case 0x00: |
| 678 | default: |
| 679 | set_data_frame(8, 1, SERIAL_PARITY_NONE); |
| 680 | break; |
| 741 | 681 | } |
| 742 | 682 | } |
| 743 | 683 | |
| 744 | | DEFINE_LEGACY_DEVICE(GENERIC_TERMINAL, terminal); |
| 684 | void serial_terminal_device::device_reset() |
| 685 | { |
| 686 | generic_terminal_device::device_reset(); |
| 687 | m_rbit = 1; |
| 688 | if(m_slot) |
| 689 | m_owner->out_rx(m_rbit); |
| 690 | else |
| 691 | m_out_tx_func(m_rbit); |
| 692 | } |
| 745 | 693 | |
| 746 | | serial_terminal_device::serial_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 747 | | : device_t(mconfig, SERIAL_TERMINAL, "Serial Terminal", tag, owner, clock), |
| 748 | | device_serial_port_interface(mconfig, *this), |
| 749 | | m_terminal(*this, TERMINAL_TAG) |
| 694 | void serial_terminal_device::send_key(UINT8 code) |
| 750 | 695 | { |
| 696 | if(is_transmit_register_empty()) |
| 697 | { |
| 698 | transmit_register_setup(code); |
| 699 | return; |
| 700 | } |
| 701 | m_key_valid = true; |
| 702 | m_curr_key = code; |
| 751 | 703 | } |
| 752 | 704 | |
| 753 | | static const terminal_interface serial_terminal_terminal_interface = { |
| 754 | | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, serial_terminal_device, serial_keyboard_func) |
| 755 | | }; |
| 705 | void serial_terminal_device::tra_callback() |
| 706 | { |
| 707 | m_rbit = transmit_register_get_data_bit(); |
| 708 | if(m_slot) |
| 709 | m_owner->out_rx(m_rbit); |
| 710 | else |
| 711 | m_out_tx_func(m_rbit); |
| 712 | } |
| 756 | 713 | |
| 757 | | static MACHINE_CONFIG_FRAGMENT(serial_terminal_config) |
| 758 | | MCFG_SERIAL_TERMINAL_ADD(TERMINAL_TAG, serial_terminal_terminal_interface, 9600) |
| 759 | | MACHINE_CONFIG_END |
| 714 | void serial_terminal_device::tra_complete() |
| 715 | { |
| 716 | if(m_key_valid) |
| 717 | { |
| 718 | transmit_register_setup(m_curr_key); |
| 719 | m_key_valid = false; |
| 720 | } |
| 721 | } |
| 760 | 722 | |
| 761 | | const device_type SERIAL_TERMINAL = &device_creator<serial_terminal_device>; |
| 723 | void serial_terminal_device::rcv_complete() |
| 724 | { |
| 725 | receive_register_extract(); |
| 726 | term_write(get_received_char()); |
| 727 | } |
| 762 | 728 | |
| 763 | | machine_config_constructor serial_terminal_device::device_mconfig_additions() const |
| 729 | READ_LINE_MEMBER(serial_terminal_device::tx_r) |
| 764 | 730 | { |
| 765 | | return MACHINE_CONFIG_NAME(serial_terminal_config); |
| 731 | return m_rbit; |
| 766 | 732 | } |
| 733 | |
| 734 | const device_type SERIAL_TERMINAL = &device_creator<serial_terminal_device>; |
src/mess/machine/terminal.h
| r14605 | r14606 | |
| 3 | 3 | |
| 4 | 4 | #include "emu.h" |
| 5 | 5 | #include "machine/serial.h" |
| 6 | | #include "devcb.h" |
| 7 | 6 | |
| 8 | 7 | /*************************************************************************** |
| 9 | 8 | TYPE DEFINITIONS |
| r14605 | r14606 | |
| 12 | 11 | typedef struct _terminal_interface terminal_interface; |
| 13 | 12 | struct _terminal_interface |
| 14 | 13 | { |
| 15 | | devcb_write8 terminal_keyboard_func; |
| 14 | devcb_write8 m_keyboard_cb; |
| 16 | 15 | }; |
| 17 | 16 | |
| 18 | 17 | #define GENERIC_TERMINAL_INTERFACE(name) const terminal_interface (name) = |
| 19 | 18 | |
| 19 | struct serial_terminal_interface |
| 20 | { |
| 21 | devcb_write_line m_out_tx_cb; |
| 22 | }; |
| 23 | |
| 20 | 24 | /*************************************************************************** |
| 21 | 25 | DEVICE CONFIGURATION MACROS |
| 22 | 26 | ***************************************************************************/ |
| 23 | 27 | #define TERMINAL_TAG "terminal" |
| 24 | 28 | #define TERMINAL_SCREEN_TAG "terminal_screen" |
| 25 | 29 | |
| 26 | | DECLARE_LEGACY_DEVICE(GENERIC_TERMINAL, terminal); |
| 27 | | |
| 28 | 30 | #define MCFG_GENERIC_TERMINAL_ADD(_tag, _intrf) \ |
| 29 | 31 | MCFG_DEVICE_ADD(_tag, GENERIC_TERMINAL, 0) \ |
| 30 | 32 | MCFG_DEVICE_CONFIG(_intrf) |
| r14605 | r14606 | |
| 32 | 34 | #define MCFG_GENERIC_TERMINAL_REMOVE(_tag) \ |
| 33 | 35 | MCFG_DEVICE_REMOVE(_tag) |
| 34 | 36 | |
| 35 | | #define MCFG_SERIAL_TERMINAL_ADD(_tag, _intrf, _baud) \ |
| 36 | | MCFG_DEVICE_ADD(_tag, GENERIC_TERMINAL, _baud) \ |
| 37 | #define MCFG_SERIAL_TERMINAL_ADD(_tag, _intrf, _clock) \ |
| 38 | MCFG_DEVICE_ADD(_tag, SERIAL_TERMINAL, _clock) \ |
| 37 | 39 | MCFG_DEVICE_CONFIG(_intrf) |
| 38 | 40 | |
| 39 | 41 | /*************************************************************************** |
| 40 | 42 | FUNCTION PROTOTYPES |
| 41 | 43 | ***************************************************************************/ |
| 42 | 44 | |
| 43 | | READ_LINE_DEVICE_HANDLER( terminal_serial_r ); |
| 44 | | WRITE_LINE_DEVICE_HANDLER( terminal_serial_w ); |
| 45 | #define TERMINAL_WIDTH 80 |
| 46 | #define TERMINAL_HEIGHT 24 |
| 45 | 47 | |
| 46 | | WRITE8_DEVICE_HANDLER ( terminal_write ); |
| 48 | class generic_terminal_device : |
| 49 | public device_t, |
| 50 | public _terminal_interface |
| 51 | { |
| 52 | public: |
| 53 | generic_terminal_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 54 | generic_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 55 | DECLARE_WRITE8_MEMBER(write) { term_write(data); } |
| 56 | UINT32 update(screen_device &device, bitmap_rgb32 &bitmap, const rectangle &cliprect); |
| 47 | 57 | |
| 48 | | INPUT_PORTS_EXTERN(generic_terminal); |
| 58 | virtual ioport_constructor device_input_ports() const; |
| 59 | virtual machine_config_constructor device_mconfig_additions() const; |
| 60 | protected: |
| 61 | virtual void term_write(UINT8 data); |
| 62 | virtual void device_start(); |
| 63 | virtual void device_reset(); |
| 64 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 65 | virtual void device_config_complete(); |
| 66 | virtual void send_key(UINT8 code) { m_keyboard_func(0, code); } |
| 67 | UINT8 m_buffer[TERMINAL_WIDTH*50]; // make big enough for teleprinter |
| 68 | UINT8 m_x_pos; |
| 69 | emu_timer *m_timer; |
| 70 | private: |
| 71 | UINT8 keyboard_handler(UINT8 last_code, UINT8 *scan_line); |
| 72 | void scroll_line(); |
| 73 | void write_char(UINT8 data); |
| 74 | void clear(); |
| 75 | UINT8 row_number(UINT8 code); |
| 49 | 76 | |
| 50 | | UINT8 terminal_keyboard_handler(running_machine &machine, UINT8 last_code, UINT8 *scan_line, UINT8 *tx_shift, int *tx_state, device_t *device); |
| 77 | UINT8 m_framecnt; |
| 78 | UINT8 m_y_pos; |
| 79 | UINT8 m_last_code; |
| 80 | UINT8 m_scan_line; |
| 51 | 81 | |
| 82 | devcb_resolved_write8 m_keyboard_func; |
| 83 | }; |
| 84 | |
| 85 | extern const device_type GENERIC_TERMINAL; |
| 86 | |
| 52 | 87 | class serial_terminal_device : |
| 53 | | public device_t, |
| 54 | | public device_serial_port_interface |
| 88 | public generic_terminal_device, |
| 89 | public device_serial_interface, |
| 90 | public device_serial_port_interface, |
| 91 | public serial_terminal_interface |
| 55 | 92 | { |
| 56 | 93 | public: |
| 57 | 94 | serial_terminal_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 58 | | virtual machine_config_constructor device_mconfig_additions() const; |
| 59 | | virtual void tx(UINT8 state) { terminal_serial_w(m_terminal, state); } |
| 60 | | DECLARE_WRITE8_MEMBER(serial_keyboard_func) { m_rbit = data&&1; m_owner->out_rx(m_rbit); } |
| 95 | |
| 96 | DECLARE_WRITE_LINE_MEMBER(rx_w) { m_tbit = state; check_for_start(state); } |
| 97 | DECLARE_READ_LINE_MEMBER(tx_r); |
| 98 | virtual ioport_constructor device_input_ports() const; |
| 99 | |
| 100 | DECLARE_INPUT_CHANGED_MEMBER(update_frame); |
| 61 | 101 | protected: |
| 62 | | virtual void device_start() { m_owner = dynamic_cast<serial_port_device *>(owner()); } |
| 63 | | virtual void device_reset() { m_owner->out_rx(1); m_rbit = 1; } |
| 64 | | virtual void device_config_complete() { m_shortname = "serial_terminal"; } |
| 102 | virtual void device_start(); |
| 103 | virtual void device_config_complete(); |
| 104 | virtual void device_reset(); |
| 105 | virtual void tra_callback(); |
| 106 | virtual void tra_complete(); |
| 107 | virtual void rcv_complete(); |
| 108 | virtual void input_callback(UINT8 state) { m_input_state = state; } |
| 109 | virtual void send_key(UINT8 code); |
| 65 | 110 | private: |
| 66 | | required_device<device_t> m_terminal; |
| 67 | 111 | serial_port_device *m_owner; |
| 112 | bool m_slot; |
| 113 | UINT8 m_curr_key; |
| 114 | bool m_key_valid; |
| 115 | devcb_resolved_write_line m_out_tx_func; |
| 68 | 116 | }; |
| 69 | 117 | |
| 70 | 118 | extern const device_type SERIAL_TERMINAL; |