Previous Thread
Next Thread
Print Thread
Joined: Feb 2014
Posts: 674
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 674
Likes: 9
Hi guys,

I'm probably not using the timer system correctly so I was wondering how to configure a periodic timer where you could change its rate.


so in device_add_mconfig I setup my timer:

Code
TIMER(config, m_timer_rxclock, 0);
m_timer_rxclock->configure_periodic(FUNC(apple_imagewriter_printer_device::pulse_uart_clock), attotime::from_hz( 9600 * 16 * 2));


but I can't read from an ioport here. Mame blows up with a segfault.

Code
Stack trace of thread 866121:
#0  0x00005592f04291d4 _ZNK8device_t6ioportESt17basic_string_viewIcSt11char_traitsIcEE (mame + 0xc54c1d4)
#1  0x00005592ee1022be _ZN32apple_imagewriter_printer_device18device_add_mconfigER14machine_config (mame + 0xa2252be)
#2  0x00005592f0427bc2 _ZN8device_t25add_machine_configurationER14machine_config (mame + 0xc54abc2)
#3  0x00005592f12c97da _ZN14machine_config10device_addEPKcRKN3emu6detail21device_type_impl_baseEj (mame + 0xd3ec7da)
#4  0x00005592f12ca09a _ZN14machine_configC1ERK11game_driverR11emu_options (mame + 0xd3ed09a)
#5  0x00005592f12515a0 _ZN11emu_options27add_and_remove_slot_optionsEv (mame + 0xd3745a0)


So I have a PORT_CHANGED_MEMBER where I'd like to change the clock's period to match the baud bits that have been chosen, but when it calls configure_periodic a second time, it segfaults in device_timer.


Code
	

INPUT_CHANGED_MEMBER(baud_rate_changed)
{
	int baudbits = ioport("DIPSW2")->read() & 0x03;
	int baserate = (baudbits < 2) ? 9600 : 1200;

	m_timer_rxclock->configure_periodic(FUNC(apple_imagewriter_printer_device::pulse_uart_clock), attotime::from_hz( baserate * 16 * 2));	
}


I tried m_timer_rxclock->reset() and that gave:

Code
Ignoring MAME exception: Cannot adjust a non-generic timer.

Fatal error: Cannot adjust a non-generic timer.




running "coredumpctl debug" in ubuntu gives:
Code
#0  0x0000000000000000 in ?? ()
[Current thread is 1 (Thread 0x7fbdda064880 (LWP 864809))]
(gdb) bt
#0  0x0000000000000000 in  ()
#1  0x000055e4bc5de891 in timer_device::device_timer(emu_timer&, unsigned int, int, void*) ()
#2  0x000055e4be18e572 in device_scheduler::timeslice() ()
#3  0x000055e4be11efc0 in running_machine::run(bool) ()
#4  0x000055e4ba344759 in mame_machine_manager::execute() ()
#5  0x000055e4ba3f04ce in cli_frontend::start_execution(mame_machine_manager*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) ()
#6  0x000055e4ba3f0762 in cli_frontend::execute(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) ()
#7  0x000055e4ba3421aa in emulator_info::start_frontend(emu_options&, osd_interface&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) ()
#8  0x000055e4b5843edf in main ()
(gdb) quit

Joined: Feb 2004
Posts: 2,274
Likes: 14
Very Senior Member
Offline
Very Senior Member
Joined: Feb 2004
Posts: 2,274
Likes: 14
Don’t use a timer device. Use a regular timer and set it up at reset time. The timer device is just a horribly inefficient wrapper for a regular timer, anyway.

Joined: Feb 2014
Posts: 674
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 674
Likes: 9
Ok, I didn't realize there was a distinction between the two. I see the word timer and I think they're equivalent.



The imagewriter uses 2 different clock rates, one for 9600 and 2400 baud, and one that's 1/8th that rate for 1200 and 300.

So I put a counter in for the other rate that basically delays the clock signal for 8 counts. That seems to work fine:

Here's c64 printing at 300 baud (seems to work on initial testing):

./mame c64 -user rs232 -user:rs232:rs232 imagewriter

Code
100  OPEN 1,2,0,CHR$(6) 

200  FOR A = 1 TO 20 : PRINT#1,"LINE";A;
210  FOR I=32 TO 96 : PRINT#1,CHR$(I); : NEXT I :
220  PRINT#1,"" : NEXT A

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]

changing the baud rate dip switches, resetting the printer, and then
open 1,2,0,chr$(6) for 300 baud
chr$(8) for 1200 baud
chr$(10) for 2400 baud
(c64 doesn't support 9600 baud) (I think NI means not implemented)

[Linked Image from i.imgur.com]
[Linked Image from i.imgur.com]


Link Copied to Clipboard
Who's Online Now
1 members (SoltanGris42), 30 guests, and 2 robots.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics8,974
Posts117,896
Members5,001
Most Online890
Jan 17th, 2020
Forum Host
These forums are hosted by www.retrogamesformac.com
Forum hosted by www.retrogamesformac.com