diff -up src/emu/emu.mak.orig src/emu/emu.mak --- src/emu/emu.mak.orig 2009-10-31 20:44:54.000000000 -0400 +++ src/emu/emu.mak 2009-12-24 11:47:04.000000000 -0500 @@ -156,6 +156,7 @@ EMUMACHINEOBJS = \ $(EMUMACHINE)/pic8259.o \ $(EMUMACHINE)/pit8253.o \ $(EMUMACHINE)/pd4990a.o \ + $(EMUMACHINE)/pseudotty.o \ $(EMUMACHINE)/roc10937.o \ $(EMUMACHINE)/rp5h01.o \ $(EMUMACHINE)/rtc65271.o \ diff -up src/emu/machine/pseudotty.c.orig src/emu/machine/pseudotty.c --- src/emu/machine/pseudotty.c.orig 2009-12-24 11:47:04.000000000 -0500 +++ src/emu/machine/pseudotty.c 2009-12-24 11:47:04.000000000 -0500 @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include + +#include "driver.h" +#include "pseudotty.h" + +struct pseudotty pty[MAX_PTY] = { {0, }, }; + +void pseudotty_alloc(running_machine *machine, int which) +{ + char msg[20]; + char *slave; + struct pseudotty *p = pty + which; + + p->fd = posix_openpt(O_RDWR); + grantpt(p->fd); + unlockpt(p->fd); + + slave = ptsname(p->fd); + printf("Debug pseudo-terminal %d slave is %s\n", which, slave); + + sprintf(msg, "MAME debug port %d\n", which); + write(p->fd, msg, strlen(msg)); + + /* request callback upon exiting */ + add_exit_callback(machine, pseudotty_exit); +} + +void pseudotty_exit(running_machine *machine) +{ + int which; + + for (which = 0; which < MAX_PTY; which++) { + close(pty[which].fd); + } +} + +int pseudotty_read(int which, int offset) +{ + char line[80]; + char data = 0x5a; + struct timeval timeout; + fd_set readfds; + struct pseudotty *p = pty + which; + + switch (offset) { + case PTY_DATA: + if (!p->rx_pending) { + fprintf(stderr, "%s: buffer underrun on %d\n", + __func__, which); + break; + } + data = p->buf[p->head++]; + p->rx_pending--; + break; + case PTY_CONTROL: + if (!p->rx_pending) { + /* Try to read from pty */ + FD_ZERO(&readfds); + FD_SET(p->fd, &readfds); + timeout.tv_sec = timeout.tv_usec = 0; + + if (select(p->fd + 1, &readfds, NULL, NULL, &timeout) + < 0) { + sprintf(line, "%s : %s : %d ", __func__, + __FILE__, __LINE__); + perror(line); + } else if (FD_ISSET(p->fd, &readfds)) { + p->head = 0; + p->rx_pending = read(p->fd, p->buf, + sizeof(p->buf)); + if (p->rx_pending == -1) { + p->rx_pending = 0; + sprintf(line, "%s : %s : %d ", __func__, + __FILE__, __LINE__); + perror(line); + } + } + } + data = p->rx_pending; + break; + default: + fprintf(stderr, "%s: read from bad offset %d on %d\n", __FILE__, + offset, which); + } + + return (int)data; +} + +void pseudotty_write(int which, int offset, int data) +{ + char d = (char)data; + struct pseudotty *p = pty + which; + + switch (offset) { + case PTY_DATA: + write(p->fd, &d, 1); + break; + case PTY_CONTROL: + p->rx_pending = p->head = 0; + break; + default: + fprintf(stderr, "%s: write to bad offset %d on %d\n", __FILE__, + offset, which); + } +} + +READ8_HANDLER( pseudotty_0_r ) { return pseudotty_read(0, offset); } +READ8_HANDLER( pseudotty_1_r ) { return pseudotty_read(1, offset); } + +WRITE8_HANDLER( pseudotty_0_w ) { pseudotty_write(0, offset, data); } +WRITE8_HANDLER( pseudotty_1_w ) { pseudotty_write(1, offset, data); } diff -up src/emu/machine/pseudotty.h.orig src/emu/machine/pseudotty.h --- src/emu/machine/pseudotty.h.orig 2009-12-24 11:47:04.000000000 -0500 +++ src/emu/machine/pseudotty.h 2009-12-24 11:47:04.000000000 -0500 @@ -0,0 +1,27 @@ +#ifndef _PSEUDOTTY_H_ +#define _PSEUDOTTY_H_ + +#define MAX_PTY 2 + +enum pseudotty_ports { + PTY_DATA, + PTY_CONTROL +}; + +struct pseudotty { + int fd; + int rx_pending; + int head; + char buf[0x80]; +}; + +void pseudotty_alloc(running_machine *machine, int which); +void pseudotty_exit(running_machine *machine); + +READ8_HANDLER( pseudotty_0_r ); +READ8_HANDLER( pseudotty_1_r ); + +WRITE8_HANDLER( pseudotty_0_w ); +WRITE8_HANDLER( pseudotty_1_w ); + +#endif /* _PSEUDOTTY_H_ */ diff -up src/mess/drivers/coco.c.orig src/mess/drivers/coco.c --- src/mess/drivers/coco.c.orig 2009-11-06 06:33:07.000000000 -0500 +++ src/mess/drivers/coco.c 2009-12-24 11:49:37.000000000 -0500 @@ -33,6 +33,7 @@ #include "includes/coco.h" #include "machine/wd17xx.h" #include "machine/6551.h" +#include "machine/pseudotty.h" #include "formats/coco_dsk.h" #include "formats/coco_cas.h" #include "devices/printer.h" @@ -74,7 +75,8 @@ static ADDRESS_MAP_START( coco_map, ADDR AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE("coco_cartslot", coco_cartridge_r, coco_cartridge_w) AM_RANGE(0xff90, 0xffbf) AM_NOP AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffef) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) + AM_RANGE(0xffe2, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0) ADDRESS_MAP_END @@ -101,7 +103,8 @@ static ADDRESS_MAP_START( dragon_map, AD AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE("coco_cartslot", coco_cartridge_r, coco_cartridge_w) AM_RANGE(0xff90, 0xffbf) AM_NOP AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffef) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) + AM_RANGE(0xffe2, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0) ADDRESS_MAP_END @@ -132,7 +135,8 @@ static ADDRESS_MAP_START( coco3_map, ADD AM_RANGE(0xffa0, 0xffaf) AM_READWRITE(coco3_mmu_r, coco3_mmu_w) AM_RANGE(0xffb0, 0xffbf) AM_READWRITE(SMH_BANK(10), coco3_palette_w) AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffef) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) + AM_RANGE(0xffe2, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x7ff0) ADDRESS_MAP_END @@ -161,7 +165,8 @@ static ADDRESS_MAP_START( d64_map, ADDRE AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE("coco_cartslot", coco_cartridge_r, coco_cartridge_w) AM_RANGE(0xff90, 0xffbf) AM_NOP AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffef) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) + AM_RANGE(0xffe2, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0) ADDRESS_MAP_END @@ -195,7 +200,7 @@ static ADDRESS_MAP_START( d64_plus_map, AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE("coco_cartslot", coco_cartridge_r, coco_cartridge_w) AM_RANGE(0xff90, 0xffbf) AM_NOP AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffe1) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) AM_RANGE(0xffe2, 0xffe2) AM_READWRITE(plus_reg_r,plus_reg_w) /* Dragon plus control / status reg */ AM_RANGE(0xffe3, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_ROM AM_REGION("maincpu", 0x3ff0) @@ -276,7 +281,8 @@ static ADDRESS_MAP_START( dgnalpha_map, AM_RANGE(0xff40, 0xff7f) AM_DEVREADWRITE("coco_cartslot", coco_cartridge_r, coco_cartridge_w) AM_RANGE(0xff90, 0xffbf) AM_NOP AM_RANGE(0xffc0, 0xffdf) AM_DEVWRITE("sam", sam6883_w) - AM_RANGE(0xffe0, 0xffef) AM_NOP + AM_RANGE(0xffe0, 0xffe1) AM_READWRITE(pseudotty_0_r, pseudotty_0_w) + AM_RANGE(0xffe2, 0xffef) AM_NOP AM_RANGE(0xfff0, 0xffff) AM_READ(dragon_alpha_mapped_irq_r) ADDRESS_MAP_END @@ -1389,21 +1395,26 @@ ROM_END #define rom_coco3h rom_coco3 +static DRIVER_INIT(coco) +{ + pseudotty_alloc(machine, 0); +} + /* I have split up coco and cocoe, as the basic rom in the coco, cannot */ /* use 64K rams, and will boot with 4k, if this is selected, so I have */ /* split these to avoid confusion -- PHS */ /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ -COMP( 1980, coco, 0, 0, coco, coco, 0, 0, "Tandy Radio Shack", "Color Computer", 0) -COMP( 1981, cocoe, coco, 0, cocoe, coco, 0, 0, "Tandy Radio Shack", "Color Computer (Extended BASIC 1.0)", 0) -COMP( 1983, coco2, coco, 0, coco2, coco, 0, 0, "Tandy Radio Shack", "Color Computer 2", 0) -COMP( 1985?, coco2b, coco, 0, coco2b, coco, 0, 0, "Tandy Radio Shack", "Color Computer 2B", 0) -COMP( 1986, coco3, coco, 0, coco3, coco3, 0, 0, "Tandy Radio Shack", "Color Computer 3 (NTSC)", 0) -COMP( 1986, coco3p, coco, 0, coco3p, coco3, 0, 0, "Tandy Radio Shack", "Color Computer 3 (PAL)", 0) -COMP( 19??, coco3h, coco, 0, coco3h, coco3, 0, 0, "Tandy Radio Shack", "Color Computer 3 (NTSC; HD6309)", GAME_COMPUTER_MODIFIED) -COMP( 1982, dragon32, coco, 0, dragon32, dragon32, 0, 0, "Dragon Data Ltd", "Dragon 32", 0) -COMP( 1983, dragon64, coco, 0, dragon64, dragon32, 0, 0, "Dragon Data Ltd", "Dragon 64", 0) -COMP( 1983, d64plus, coco, 0, d64plus, dragon32, 0, 0, "Dragon Data Ltd", "Dragon 64 Plus", 0) -COMP( 1983, tanodr64, coco, 0, tanodr64, dragon32, 0, 0, "Dragon Data Ltd / Tano Ltd", "Tano Dragon 64 (NTSC)", 0) -COMP( 1984, dgnalpha, coco, 0, dgnalpha, dragon32, 0, 0, "Dragon Data Ltd", "Dragon Alpha Prototype", 0) -COMP( 1984, cp400, coco, 0, coco, coco, 0, 0, "Prologica", "CP400", 0) +COMP( 1980, coco, 0, 0, coco, coco, coco, 0, "Tandy Radio Shack", "Color Computer", 0) +COMP( 1981, cocoe, coco, 0, cocoe, coco, coco, 0, "Tandy Radio Shack", "Color Computer (Extended BASIC 1.0)", 0) +COMP( 1983, coco2, coco, 0, coco2, coco, coco, 0, "Tandy Radio Shack", "Color Computer 2", 0) +COMP( 1985?, coco2b, coco, 0, coco2b, coco, coco, 0, "Tandy Radio Shack", "Color Computer 2B", 0) +COMP( 1986, coco3, coco, 0, coco3, coco3, coco, 0, "Tandy Radio Shack", "Color Computer 3 (NTSC)", 0) +COMP( 1986, coco3p, coco, 0, coco3p, coco3, coco, 0, "Tandy Radio Shack", "Color Computer 3 (PAL)", 0) +COMP( 19??, coco3h, coco, 0, coco3h, coco3, coco, 0, "Tandy Radio Shack", "Color Computer 3 (NTSC; HD6309)", GAME_COMPUTER_MODIFIED) +COMP( 1982, dragon32, coco, 0, dragon32, dragon32, coco, 0, "Dragon Data Ltd", "Dragon 32", 0) +COMP( 1983, dragon64, coco, 0, dragon64, dragon32, coco, 0, "Dragon Data Ltd", "Dragon 64", 0) +COMP( 1983, d64plus, coco, 0, d64plus, dragon32, coco, 0, "Dragon Data Ltd", "Dragon 64 Plus", 0) +COMP( 1983, tanodr64, coco, 0, tanodr64, dragon32, coco, 0, "Dragon Data Ltd / Tano Ltd", "Tano Dragon 64 (NTSC)", 0) +COMP( 1984, dgnalpha, coco, 0, dgnalpha, dragon32, coco, 0, "Dragon Data Ltd", "Dragon Alpha Prototype", 0) +COMP( 1984, cp400, coco, 0, coco, coco, coco, 0, "Prologica", "CP400", 0)