Hi guys,

I was trying to set the monitor type "on the fly" in the apple2p driver from lua, and was having problems.

There's an ioport named ":a2_config" that controls the configuration of the "Composite monitor type" from 0=Color, 1=B+W, 2=Green, 3=Amber.

INPUT_PORTS_START( apple2_sysconfig )
PORT_START("a2_config")
PORT_CONFNAME(0x03, 0x00, "Composite monitor type")
PORT_CONFSETTING(0x00, "Color")
PORT_CONFSETTING(0x01, "B&W")
PORT_CONFSETTING(0x02, "Green")
PORT_CONFSETTING(0x03, "Amber")

PORT_CONFNAME(0x04, 0x04, "Shift key mod") // default to installed
PORT_CONFSETTING(0x00, "Not present")
PORT_CONFSETTING(0x04, "Installed")
INPUT_PORTS_END

I can set it with:

manager:machine():ioport().ports[":a2_config"].fields["Composite monitor type"]:set_value(x)

and I read it back with

print(manager:machine():ioport().ports[":a2_config"]:read())


but for some reason, when I read it, it doesn't seem to change it right away.

So let's see what happens if we set a value, and read it right back:

function portsetvalue(x)
manager:machine():ioport().ports[":a2_config"].fields["Composite monitor type"]:set_value(x) print(manager:machine():ioport().ports[":a2_config"]:read())
end

function portwrite(x,mask)
manager:machine():ioport().ports[":a2_config"]:write(x,mask)
print(manager:machine():ioport().ports[":a2_config"]:read())
end

[MAME]> portsetvalue(0)
6
[MAME]> portsetvalue(0)
6
[MAME]> portsetvalue(0)
6
[MAME]> portsetvalue(1)
6
[MAME]> portsetvalue(0)
7
[MAME]> portsetvalue(1)
7
[MAME]> portsetvalue(0)
4
[MAME]> portsetvalue(1)
4
[MAME]> portsetvalue(0)
5
[MAME]> portsetvalue(1)
5
[MAME]> portsetvalue(0)
6
[MAME]>

and what's weird is that it the port's read() value seems to lag where it changes to a value that I've set awhile back.

I can see the monitor type change at different points but it seems very disconnected from what I'm trying to write to the port. It seems to be sensitive to actually sending a different number to set_value.


Edit: I wrote a little function that will call setvalue(0) and setvalue(1) and have an emu:wait() in between.

What's strange is that it seems to cycle the values for the monitor type 0,1,2,3 and you can see the monitor type change, cycling through (color,b&w,green,amber) in the apple2 display which doesn't make sense to me.

Code

function co1() 
for i=1,20 do 
  print("cycle="..i) 
  manager:machine():ioport().ports[":a2_config"].fields["Composite monitor type"]:set_value(0)
  print("set_value(0)")
  print(":a2_config="..manager:machine():ioport().ports[":a2_config"]:read()) 
  emu.wait(60/60) 
  manager:machine():ioport().ports[":a2_config"].fields["Composite monitor type"]:set_value(1)
  print("set_value(1)")
  print(":a2_config="..manager:machine():ioport().ports[":a2_config"]:read()) 
emu.wait(30/60) 
end 
end

co1co = coroutine.create(co1)
coroutine.resume(co1co)


cycle=1
set_value(0)
:a2_config=5
set_value(1)
:a2_config=5
cycle=2
set_value(0)
:a2_config=6
set_value(1)
:a2_config=6
cycle=3
set_value(0)
:a2_config=7
set_value(1)
:a2_config=7
cycle=4
set_value(0)
:a2_config=4
set_value(1)
:a2_config=4
cycle=5
set_value(0)
:a2_config=5
set_value(1)
:a2_config=5
cycle=6
set_value(0)
:a2_config=6
set_value(1)
:a2_config=6
... repeats 7,4,5,6,7

Edit:

I think that the ioport values update every frame so if I wait a little bit, and set_value again, I could get it to cycle on purpose.

Code
function portsetvalue(x) 
print ("set_value="..x)
manager:machine():ioport().ports[":a2_config"].fields["Composite monitor type"]:set_value(x) print(manager:machine():ioport().ports[":a2_config"]:read()) 
end

function keepcyclingport(wanted)
print(wanted)
for i=0,30 do
if (manager:machine():ioport().ports[":a2_config"]:read() & 0x03) ~= wanted then
portsetvalue(0)
emu.wait(2/60)
portsetvalue(1)
emu.wait(2/60)
else
  return
end end end

keepco =coroutine.create(keepcyclingport) coroutine.resume(keepco,2)

keepco=coroutine.create(keepcyclingport)  coroutine.resume(keepco,0)



Last edited by Golden Child; 02/02/19 06:04 PM.