Previous Thread
Next Thread
Print Thread
#119783 10/06/21 10:31 PM
Joined: Feb 2014
Posts: 676
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 676
Likes: 9
So I wanted to be able to set a top margin for a printed page and be able to modify it with a PORT_ADJUSTER


Code
#define PORT_ADJUSTER_16MASK(_default, _name)					\
        configurer.field_alloc(IPT_ADJUSTER, (_default), 0xffff, (_name)); \
        configurer.field_set_min_max(0, 100);


	PORT_START("TOPMARGIN")
	PORT_ADJUSTER_16MASK(14, "Top Margin")
	PORT_MINMAX(18,500)

	PORT_START("BOTTOMMARGIN")
	PORT_ADJUSTER_16MASK(72, "Bottom Margin")
	PORT_MINMAX(18,500)	


and it works pretty well, just using

ioport("TOPMARGIN")->read() to access the value, and using Slider Options to change the values.

I really wanted to be able to write the value as well from code, but doing

ioport("TOPMARGIN")->write(36);

seems to have no effect. It doesn't seem to generate an error, but the value doesn't change.


Accessing it from lua doesn't seem to be able to write the value either:
Code
function printt(t) for i,j in pairs(t) do print(i,j) end end
printt(manager.machine.ioport.ports)

:sl1:ssc:rs232:imagewriter:BOTTOMMARGIN	sol.ioport_port*: 0x561e53c0fe08
:sl1:ssc:rs232:imagewriter:TOPMARGIN	sol.ioport_port*: 0x561e53c10cb8

[MAME]> manager.machine.ioport.ports[":sl1:ssc:rs232:imagewriter:TOPMARGIN"].fields["Top Margin"]:set_value(36)

[MAME]> print(manager.machine.ioport.ports[":sl1:ssc:rs232:imagewriter:TOPMARGIN"].fields["Top Margin"].user_value)
18

My plan was to be able to print a page, then be able to hit a key to set up the top/bottom and starting left margin to perfectly center it for the next print.


[Linked Image from i.imgur.com]



edit: Hmmm, looking at ioport.cpp I think this function does the write:

Code
//-------------------------------------------------
//  write - write a value to a port
//-------------------------------------------------

void ioport_port::write(ioport_value data, ioport_value mem_mask)
{
        // call device line write handlers
        COMBINE_DATA(&m_live->outputvalue);
        for (dynamic_field &dynfield : m_live->writelist)
                if (dynfield.field().type() == IPT_OUTPUT)
                        dynfield.write(m_live->outputvalue ^ dynfield.field().defvalue());
}


Last edited by Golden Child; 10/06/21 11:09 PM.
Joined: Feb 2014
Posts: 676
Likes: 9
G
Senior Member
OP Offline
Senior Member
G
Joined: Feb 2014
Posts: 676
Likes: 9
taking some code from src/frontend/mame/ui/ui.cpp:

Code
//-------------------------------------------------
//  slider_adjuster - analog adjuster slider
//  callback
//-------------------------------------------------

int32_t mame_ui_manager::slider_adjuster(ioport_field &field, std::string *str, int32_t newval)
{
        ioport_field::user_settings settings;

        field.get_user_settings(settings);
        if (newval != SLIDER_NOCHANGE)
        {
                settings.value = newval;
                field.set_user_settings(settings);
        }
        if (str)
                *str = string_format(_("%1$d%%"), settings.value);
        return settings.value;
}


This seems to work:

Code
//-------------------------------------------------
//  write - write a value to a port
//-------------------------------------------------

void ioport_port::write(ioport_value data, ioport_value mem_mask)
{
	printf("IOPORT WRITE data=%x mem_mask=%x\n",data,mem_mask);

	// call device line write handlers
	COMBINE_DATA(&m_live->outputvalue);
	for (dynamic_field &dynfield : m_live->writelist)
		if (dynfield.field().type() == IPT_OUTPUT)
			dynfield.write(m_live->outputvalue ^ dynfield.field().defvalue());

	for (ioport_field &field : m_fieldlist)
		if (field.type() == IPT_ADJUSTER)
		{	
		    ioport_field::user_settings settings;
		    field.get_user_settings(settings);
		    settings.value = data;
		    field.set_user_settings(settings);
		}
}

It's interesting that it doesn't seem to get updated immediately, since


Code

	printf("topmargin = %x\n",ioport("TOPMARGIN")->read());
	ioport("TOPMARGIN")->write(28);
	printf("topmargin = %x\n",ioport("TOPMARGIN")->read());


topmargin = 30
IOPORT WRITE data=1c mem_mask=ff
topmargin = 30

[MAME]> print(manager.machine.ioport.ports[":sl1:ssc:rs232:imagewriter:TOPMARGIN"].fields["Top Margin"].user_value)
28



will show the old value just after writing, but will update it at the next frame update (I think)


Link Copied to Clipboard
Who's Online Now
0 members (), 44 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,981
Posts117,966
Members5,003
Most Online890
Jan 17th, 2020
Forum Host
These forums are hosted by www.retrogamesformac.com
Forum hosted by www.retrogamesformac.com