English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 20 October 2019, 20:04   #1
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 47
Posts: 282
[blitz] timer device + window IDCMP_INTUITICS = trouble

Hi,
when I open a window and start a timer device to give me signals every few seconds, all is working fine.
But as soon as I add IDCMP_INTUITICKS to the window my program strats ignoring messages coming to timer reply port.
Is that a normal behavior?

See example below
Code:
*ibase._IntuitionBase=IntuitionBase
lock.l=LockIBase_(0)
*scr._Screen=*ibase\FirstScreen
While *scr
  If (*scr\Flags)&#SCREENTYPE=#WBENCHSCREEN
    Pop While:Goto jump_00
  EndIf
  *scr=*scr\NextScreen
Wend
End
jump_00:
UnlockIBase_(lock)


Dim tags.TagItem(20)
quit.w=False
t$="test"


tags(0)\ti_Tag=#WA_Left     ,0
tags(1)\ti_Tag=#WA_Top      ,20
tags(2)\ti_Tag=#WA_Width    ,200
tags(3)\ti_Tag=#WA_Height   ,200
tags(4)\ti_Tag=#WA_PubScreen,*scr
tags(5)\ti_Tag=#WA_Title    ,&t$
tags(6)\ti_Tag=#WA_Activate ,True
tags(7)\ti_Tag=#WA_Flags    ,#WFLG_CLOSEGADGET|#WFLG_DRAGBAR
tags(8)\ti_Tag=#WA_IDCMP    ,#IDCMP_CLOSEWINDOW;|#IDCMP_INTUITICKS
tags(9)\ti_Tag=#TAG_DONE    ,0


*timeport.MsgPort=CreateMsgPort_()
If *timeport
  timmask.l=1 LSL *timeport\mp_SigBit
  *timerio.timerequest=CreateIORequest_(*timeport,SizeOf .timerequest)
  If *timerio
    err.b=OpenDevice_("timer.device",#UNIT_VBLANK,*timerio,0)
    If err=0
      *timerio\tr_node\io_Command=#TR_ADDREQUEST
      *timerio\tr_time\tv_secs=2
      *timerio\tr_time\tv_micro=0

      *win._Window=OpenWindowTagList_(0,&tags(0))
      If *win
        winmask.l=1 LSL *win\UserPort\mp_SigBit

        SendIO_(*timerio)

        Repeat
          mask.l=Wait_(winmask|timmask)
          Select mask
            Case mask&winmask:Gosub winport:
            Case mask&timmask:Gosub timport:
          End Select
        Until quit


        If CheckIO_(*timerio)=0
          AbortIO_(*timerio)
          WaitIO_(*timerio)
        EndIf


        CloseWindow_(*win)
      EndIf
      CloseDevice_(*timerio)
    EndIf
    DeleteIORequest_(*timerio)
  EndIf
  DeleteMsgPort_(*timeport)
EndIf
End


;------------------------------------------------------
.winport
  *msg.IntuiMessage=GetMsg_(*win\UserPort)
  While *msg
    class.l=*msg\Class
    ReplyMsg_(*msg)
    Select class
      Case #IDCMP_CLOSEWINDOW:quit=True
    End Select
    *msg=GetMsg_(*win\UserPort)
  Wend
Return


.timport
  *tmsg.Message=GetMsg_(*timeport)
  While *tmsg
    *tmsg=GetMsg_(*timeport)
  Wend
  DisplayBeep_(*scr)
  *timerio\tr_time\tv_secs=2
  *timerio\tr_time\tv_micro=0
  SendIO_(*timerio)
Return
peceha is offline  
Old 20 October 2019, 20:25   #2
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Don't do GetMsg(timeport). Use WaitIO(timerio). Despite the Wait in its name it does not wait if the request has already finished.

Always use similar pairs:

PutMsg <-> GetMsg
SendIO <-> WaitIO

Do not mix functions of different layers.
thomas is offline  
Old 20 October 2019, 20:31   #3
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 47
Posts: 282
Thanks !!
peceha is offline  
Old 20 October 2019, 21:16   #4
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 47
Posts: 282
I did what you suggested (I hope I did it the right way) and the program works better (ie. longer) - anyway after some time it doesn't trigger SendIO() anymore.
The video is about 1min long - when the screen blinks it means there was a signal from a timer. As you can see after about 40 seconds it stops blinking and my timer is gone from the list of timers.
[ Show youtube player ]
peceha is offline  
Old 20 October 2019, 21:53   #5
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
I don't speak Basic very well, but I wonder about this part:

Code:
          Select mask
            Case mask&winmask:Gosub winport:
            Case mask&timmask:Gosub timport:
          End Select
isnt' this the same as

Code:
if mask = mask&winmask then 
  gosub winport
else
  if mask = mask&timmask then
    gosub timport
  endif
endif
If so then there is a major mistake in it: mask can be either winmask or timmask or both. In the latter case, if you receive both signals at the same time, neither of the two cases match and your program just stops working.

The correct way to check the mask for received signals would be

Code:
if mask&winmask <> 0 then 
  gosub winport
endif

if mask&timmask <> 0 then
    gosub timport
endif
So in case you recive both signals at once, you call both subroutines one after the other.
thomas is offline  
Old 20 October 2019, 21:57   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Oh and by the way, the first part of your program is kinky. To get a pointer to the Workbench screen you call LockPubScreen(NULL) (with a matching UnlockPubScreen at the end of your program).
thomas is offline  
Old 20 October 2019, 22:02   #7
peceha
Registered User
 
peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 47
Posts: 282
You hit the spot !

It is hard to believe but I just wrote that part long time ago and was just "populating" it since then - I never even paid attention to this because I thought it was correct

Thanks again now it works perfectly fine.

Edit.
so it means I just overcomplicated that part ? - LockPubScreen(0) and Unlock.. at the end - ok, I'll change it
peceha is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 105 21 April 2022 19:45
Device type in ATAPI tape IDENTIFY DEVICE data mark_k support.WinUAE 0 17 March 2019 22:21
Using timer.device in C (VBCC) DBAlex Coders. General 2 28 June 2011 22:10
uae.device trouble AlfaRomeo support.Apps 3 19 March 2009 01:52
uaehf.device and HDToolbox: Error 224 reading device description Ebster support.WinUAE 3 16 September 2008 09:24

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:57.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07278 seconds with 15 queries