For discussions about development of TAPs, patches and other software for the Toppy

Moderator: Technical

Post Reply
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

TAP_SetSystemVar

Post by EMJB »

Am having problems with the above:

(1) Case SYSVAR_TvType with a value of anything but zero causes a crash

(2) Case SYSVAR_ScartType with a value of 1 does not change from Standard to External, but a value of 0 does change from External to Standard SCART type.

Anyone got any bright ideas what I might be doing wrong?

EMJB
R2-D2
Frequent contributor
Posts: 12148
Joined: Mon Dec 18, 2006 11:15 am
Contact:

Re: TAP_SetSystemVar

Post by R2-D2 »

EMJB wrote:(2) Case SYSVAR_ScartType with a value of 1 does not change from Standard to External, but a value of 0 does change from External to Standard SCART type.
All this one does is set/unset the relevant bit in the "etc" structure, so it's really hard to see how it wouldn't work. TF5810 or TF5800?

There's a fairly general issue concerning the TAP API and reentrancy, so might that be a possibility with the SYSVAR_TvType crash? One thing to try is to run with no TAPs then launch your TAP (so it's the only one running).
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Re: TAP_SetSystemVar

Post by EMJB »

R2-D2 wrote:
EMJB wrote:(2) Case SYSVAR_ScartType with a value of 1 does not change from Standard to External, but a value of 0 does change from External to Standard SCART type.
All this one does is set/unset the relevant bit in the "etc" structure, so it's really hard to see how it wouldn't work. TF5810 or TF5800? ).
TF5800. Since posting, I have found that manipulating the relevant EEPROM bit generates the right toppy menu indication and the right GetSystemVar response, but I think you need to reboot for the hardware state to actually change. If you manipulate the EEPROM bit and then call TAP_SetSystemVar(SYSVAR_ScartType,1) it behaves as if you had called TAP_SetSystemVar(SYSVAR_ScartType,0)!
R2-D2 wrote:There's a fairly general issue concerning the TAP API and reentrancy, so might that be a possibility with the SYSVAR_TvType crash? One thing to try is to run with no TAPs then launch your TAP (so it's the only one running).
Will give it a try

Thanks,

EMJB
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Re: TAP_SetSystemVar

Post by EMJB »

R2-D2 wrote:There's a fairly general issue concerning the TAP API and reentrancy, so might that be a possibility with the SYSVAR_TvType crash? One thing to try is to run with no TAPs then launch your TAP (so it's the only one running).
Running without any other TAPs doesn't help.

EMJB
FireBird
Frequent contributor
Posts: 358
Joined: Thu May 05, 2005 10:47 pm
Location: Vienna/Austria

Post by FireBird »

To check if it is a reentrance problem, please try the following code:

Code: Select all

dword TAP_EventHandler(word event, dword param1, dword param2)
{
  static bool DoNotReenter = FALSE;

  if(DoNotReenter) return param1;
  DoNotReenter = TRUE;
  
  //your code
  ...
  
  DoNotReenter = FALSE;
  return param1;
}
If there are any returns within your code, you need to reset DoNotReenter to false before, or your TAP will be "dead" afterwards.
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Post by EMJB »

@FireBird

Already have code in to detect & report if my code is re-entrant along the lines of your suggestion, so that does not appear to be the problem with the TV type causing crashes. In any case, why should it re-enter only when the type is non-zero?

EMJB
R2-D2
Frequent contributor
Posts: 12148
Joined: Mon Dec 18, 2006 11:15 am
Contact:

Post by R2-D2 »

EMJB wrote:In any case, why should it re-enter only when the type is non-zero?
Because zero (Multi) might not actually cause a change to anything significant? The other changes require resets that might cause TAPs to be sent idle events (although I haven't actually checked).

I was going to ask if we've ever seen this before, but I see [url=http://forum.toppy.org.uk/forum/viewtopic.php?p=137671]you have[/ur]! Can you remember how you coped before?
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Post by EMJB »

R2-D2 wrote:I was going to ask if we've ever seen this before, but I see [url=http://forum.toppy.org.uk/forum/viewtopic.php?p=137671]you have[/ur]! Can you remember how you coped before?
Oops - I forgot that I raised it before - I just gave up trying to set TV Type.

EMJB
R2-D2
Frequent contributor
Posts: 12148
Joined: Mon Dec 18, 2006 11:15 am
Contact:

Post by R2-D2 »

Do you have some CrashTrace analyses of a few crashes?
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Post by EMJB »

R2-D2 wrote:Do you have some CrashTrace analyses of a few crashes?
Generated with simple test program with no idle handler to re-enter and changes initiated with 0/1/2 keys and my usual selection of TAPs running:

Code: Select all

$sp=805000b8
$at=00000001    $v0=00000000    $v1=8fb50044    $a0=10000401
$a1=8226adb8    $a2=00001047    $a3=81d033e8    $t0=00000000
$t1=00000000    $t2=00000000    $t3=8042f178    $t4=80402844
$t5=00000002    $t6=3000030c    $t7=3000020c    $t8=00000001
$t9=8017a364    $s0=82268690    $s1=00010001    $s2=8226ae78
$s3=0000e300    $s4=00000000    $s5=8017a384    $s6=00010001
$s7=8226ae78    $s8=80500250    $ra=822687dc    $t0=00000044
$t1=00000000    $gp=8fb50044    $k1=82268824


<<< Unexpected Exception >>>
CAUSE   = 00008408
  EPC = 82268824
 *EPC   = 8c420000
   SR   = 10000403
badVAddr = 00000000
 task = 0
_runCount=1
ÿastTask&#40;0&#41; = 0

Code: Select all

$sp=805000b8
$at=00000001    $v0=27bdffe0    $v1=82ce27f0    $a0=80500164
$a1=8227add0    $a2=00001047    $a3=81d033e8    $t0=00000000
$t1=00000000    $t2=00000000    $t3=8042f178    $t4=80402800
$t5=00000002    $t6=3000030c    $t7=3000020c    $t8=00000001
$t9=27bdffe0    $s0=82278690    $s1=00010002    $s2=8227ae78
$s3=0000e300    $s4=00000000    $s5=8017a384    $s6=00010002
$s7=8227ae78    $s8=80500250    $ra=82278838    $t0=00000044
$t1=00000000    $gp=82ce27f0    $k1=27bdffe0


<<< Unexpected Exception >>>
CAUSE   = 00008408
  EPC = 27bdffe0
Invalid EPC Address
   SR   = 10000403
badVAddr = 27bdffe0
 task = 0
_runCount=1
lastTask&#40;0&#41; = 0

Code: Select all

$sp=805000b8
$at=00000001    $v0=00000000    $v1=8fb50044    $a0=10000401
$a1=8226adb8    $a2=00001047    $a3=81d033e8    $t0=00000000
$t1=00000000    $t2=00000000    $t3=8042f178    $t4=80402800
$t5=00000002    $t6=3000030c    $t7=3000020c    $t8=00000001
$t9=8017a364    $s0=82268690    $s1=00010001    $s2=8226ae78
$s3=0000e300    $s4=00000000    $s5=8017a384    $s6=00010001
$s7=8226ae78    $s8=80500250    $ra=822687dc    $t0=00000044
$t1=00000000    $gp=8fb50044    $k1=82268824


<<< Unexpected Exception >>>
CAUSE   = 00008408
  EPC = 82268824
 *EPC   = 8c420000
   SR   = 10000403
badVAddr = 00000000
 task = 0
_runCount=1
lastTask&#40;0&#41; = 0
and this one with no other TAPs running:

Code: Select all

$sp=805000b8
$at=00000001    $v0=00000000    $v1=8fb50044    $a0=10000401
$a1=8226adb8    $a2=00001047    $a3=81d033e8    $t0=00000000
$t1=00000000    $t2=00000000    $t3=8042f178    $t4=80402844
$t5=00000002    $t6=3000030c    $t7=3000020c    $t8=00000001
$t9=8017a364    $s0=82268690    $s1=00010001    $s2=8226ae78
$s3=0000e300    $s4=00000000    $s5=8017a384    $s6=00010001
$s7=8226ae78    $s8=80500250    $ra=822687dc    $t0=00000044
$t1=00000000    $gp=8fb50044    $k1=82268824


<<< Unexpected Exception >>>
CAUSE   = 00008408
  EPC = 82268824
 *EPC   = 8c420000
   SR   = 10000403
badVAddr = 00000000
 task = 0
_runCount=1
lastTask&#40;0&#41; = 0
Hope these help to discover the cause

EMJB
R2-D2
Frequent contributor
Posts: 12148
Joined: Mon Dec 18, 2006 11:15 am
Contact:

Post by R2-D2 »

Sorry, I should have been clearer: can you get some output from CrashTrace?
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Post by EMJB »

R2-D2 wrote:Sorry, I should have been clearer: can you get some output from CrashTrace?
PM sent with requested info.

EMJB
EMJB
Frequent contributor
Posts: 3645
Joined: Fri Jul 08, 2005 9:43 am
Location: Maldon Essex

Post by EMJB »

Thanks to R2-D2, I now have a solution to both these problems.

The cause of crashing is as follows: the change of video to PAL or NTSC ends up sending EVT_VIDEO_CONV to every TAP. Due to the stupid way Topfield have done things, that long-predicted issue with the single global TAP index raises its head, since the loop to send these events just
overwrites the index.

The SCART setting problem is caused by the Topfield code completely ignoring the "value" parameter.

The fixed code is as follows:

Code: Select all

#include ... FirebirdLib.h

int Fixed_TAP_SetSystemVar&#40;int varId, int value&#41;
&#123;

	if &#40;varId == SYSVAR_TvType&#41;
	&#123;
		register dword gp_r asm &#40;"gp"&#41;; volatile dword gp = gp_r;
		int res;
		dword *tapIndexPtr;
		dword myIndex;
		
		InitTAPex&#40;&#41;;
		tapIndexPtr = &#40;dword*&#41; TAP_IndexAddress;  //0x8017a584;
		myIndex = *&#40;dword*&#41; tapIndexPtr;
		res = TAP_SetSystemVar&#40;varId, value&#41;;
		gp_r = gp;
		*tapIndexPtr = myIndex;
		return res;
	&#125;
	ef &#40;&#40;varId == SYSVAR_ScartType&#41; && &#40;value != 0&#41;&#41;
	&#123;
		EEPROMSTRUCT *EprStr;
		dword fwResetVideo = FindInstructionSequence&#40;
							"8f99a13c 9339000b 0019ce40 0c022166 00192782 8f9ea13c 93cf000b 93d9000d 000f7fc0 0019cf40 000f27c2 0c02217f 00192f82",
							"ffe00000 fc00ffff ffe000ff fc000000 ffe0ffff ffff0000 ffe0ffff ffffffff ffe000ff ffffffff ffe0ffff fc000000 ffffffff",
							0x80080000, 0x80150000, 0, TRUE&#41;;
							
		EprStr = &#40;EEPROMSTRUCT*&#41;GetEEPROMAddress&#40;&#41;;
		if &#40;EprStr != NULL&#41;
		&#123;
			EprStr->ScartType = 1;
			CallFirmware&#40;fwResetVideo,0,0,0,0&#41;;
			return&#40;1&#41;;
		&#125;
		else
			return&#40;TAP_GetSystemVar&#40;SYSVAR_ScartType&#41;&#41;;
	&#125;
	else
		return&#40;TAP_SetSystemVar&#40;varId, value&#41;&#41;;
&#125;
which seems to work OK for me.

Thanks again, R2-D2.

EMJB
Post Reply