Announcement

Collapse
No announcement yet.

UVENT Problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • UVENT Problems

    Hello from Germany
    It would be very nice if someone could help me.
    Excude me for this terribel english. I will do my very best.

    I found a code snippet on the net where the guy
    called "Mark Junker" programms a multitasking add
    on for Power Basic DOS. I found it very interesting
    and tried to modify it. So, pricipil it works fine
    but the problem is that you must start the programm
    more then one time.

    First time the User Event never happens.
    When you stop the programm and restart it again then
    it works. After that you can stop and start how much
    you like. It never fails.
    After new rebooting (cold or warm) the problem is back.

    Too fix this problem i have removed all "Mutitasking"
    Programm Lines and all unnessary parts.

    Now there are a few lines left . Only the Uvent Hook
    is nearly the same. And it looks now much like many
    Uvent Code, Tips and Tricks i found here on your great BBS.

    Now i will explain what the programm shood do.

    I must hook on the RealTimeClock Period Interupt.

    By the way. When i change this Hook to Timer Int &H1C
    it works...............
    But Sorry, i need this special RTC Interupt &H70

    Because this Hardware Interupt is controlled via PIC2
    (Interupt Controller 2) i think i had send zwo EOI
    Command. First to the Slave then to the Master PIC.

    But that is the problem. I don't know where and how.
    I have tried many. I cannot find special information
    in the Power Basic Doku or the net. Most examples only
    explain how to hook on software interupts (which works)
    not on hardware interupts. (And when hardware int's then
    only via PIC1 Interuptcontroller 1)

    Does anyone has an idea whats going wrong or how Power Basic
    handles EOI's in IRS Service Routines.

    I attach the code which i have compiled with PB 3.2 and 3.5.
    Tested on W98 (DosBox), DOS6.2, Caldera DOS,W95 Command Line
    Always the same result.

    I think that somethings going wrong with the PIC Controller.
    Perharps the Interupt is Requested but when no EOI Commando
    returns because i shortly disabled INT8 while installing the
    hook the SetUvent Procedur is never called.

    Can Anyone please help
    Best Regards

    Rainer

    Code:
    ###############################################################
    
    $LIB ALL OFF                   ' Alles übrflüssige weg
    $LIB COM ON                    ' Com Unterstützung linken
    $STRING 32
    
    declare sub SetUEvent ()       ' SetUEvent' verfuegbar machen
    
    %INT_HOOK   = &H70     'Real Time Clock
    
    %IMR1=33    ' $H21 IMR (Interupt Mask Register von Controller 1)
    %IMR2=161   ' $HA1 IMR (Interupt Mask Register von Controller 2)
    
    DIM IRQ8HandlerPTR AS SHARED DWORD PTR
    
    DIM OldStatRegB    AS SHARED BYTE         ' CMOS Register merken
    DIM OldPic2Value   AS SHARED BYTE         ' Interupt Controller 2
    
    '***************************************************************************
    
    on uevent gosub TaskHandler    ' Basic-Part des INT-Handlers aktivieren
    on error goto TaskerStop       ' Bei Fehlern Programm SOFORT beenden
    exit far at TaskerStop         ' Bei kritischen Fehlern bei TASK.CREATE
                                   ' wird EXIT FAR ausgefuehrt (SOFORT ENDE)
    
    Set_CMOS_Register              ' Handler installierund und RTC
                                   ' aktivieren
    UEVENT ON
    
    $EVENT ON
    
      cls
    
       do
          call Test1
       loop until inkey$ = chr$(27)     'ESC
    
    $EVENT OFF
    
    TaskerStop:
    Reset_CMOS_Register             'Handler deinstallieren und RTC auf Default
    end
    
    '***************************************************************************
    
    $event off
    
    IRQ8Handler:
    
     !       PUSH    AX
     !       PUSH    BX
     !       PUSH    CX
     !       PUSH    DX
     !       PUSH    SI
     !       PUSH    DI
     !       PUSH    BP
     !       PUSH    DS
     !       PUSH    ES
     !       CALL    far ptr SetUEvent
    
    ' !       MOV DX,&HA0      ' For Test Purposes
    ' !       MOV AX,&H20
    ' !       OUT DX,AX        ' EOI Slave
    ' !       MOV DX,AX        ' Adress is &h20 too
    ' !       OUT DX,AX        ' EOI Master
    
     !       POP     ES
     !       POP     DS
     !       POP     BP
     !       POP     DI
     !       POP     SI
     !       POP     DX
     !       POP     CX
     !       POP     BX
     !       POP     AX
    
     !       jmp dword ptr OldIRQ8Handler    ; Alten IRQ8-Handler aufrufen
    
    OldIRQ8Handler:
    
     ! dd 0                             ; New Pointer
     ! dd 0                             ; Patched here
     ! dd 255
     ! dd 255
    
    $event on
    
    '***************************************************************************
    
    $event off
    
    TaskHandler:
    
     locate 12,1
     incr ticker???
     print ticker???
    
     return
    
    $event on
    
    '***************************************************************************
    
    sub Test1                'Dummy SUB
    
     static x???
    
    $event off
    
      locate 10,1
      print "This counter runs ";;x???;
    
    $event on
    
      incr x???
    
    end sub
    
    '***************************************************************************
    
    SUB Set_CMOS_Register
    
    $event off
    
     ! cli
    
     out &H70,11
     OldStatRegB = inp(&H71)                ' Alten C-MOS-Wert (f. INTs) merken
    
     out &H70,11
     out &H71,OldStatRegB and 7             ' Alle RTC-Ints abschalten
    
     DISABLEHARDINT 8
    
     IRQ8HandlerPtr  = codeptr32(OldIRQ8Handler)  ' Adresse f. alten Handler
     @IRQ8HandlerPTR = GetInteruptVektor(%INT_HOOK)
    
     SetInteruptVektor %INT_HOOK, codeptr32(IRQ8Handler)
    
     out &H70,10
     OldStageDiv?=inp(&H71) and &HF0
     out &H70,10
     out &H71,OldStageDiv? or &B1010   ' Interrupt-Speed=15,258*2^Wert Mikrosek.
                                       '  Je langsamer, desto sicherer ...
                                       '  ... unter WIN u. a. Multitaskern
                                       ' &B1010
     out &H70,11
     out &H71,OldStatRegB or 64        ' periodischen RTC-Interrupt anschalten
    
    
     ENABLEHARDINT 8
    
     ! sti
    
    END SUB
    
    '***************************************************************************
    
    SUB Reset_CMOS_Register
    
    $event off                ' UEvent verbieten
    
     ! cli                    ; Interrupts verbieten
    
     out &Ha1,OldPIC2Value    : ' Alte IRQ-Maske fuer PIC 2
     out &H70,11              : ' Interrupts so an- od. ausstellen, wie vorher
     out &H71,OldStatRegB
    
     out &H70,10
     OldStageDiv?=inp(&H71) and &HF0
     out &H70,10
     out &H71,OldStageDiv? or &B0110 : ' Standard RTC-Interrupt-Speed
    
     DISABLEHARDINT 8
     SetInteruptVektor %INT_HOOK,@IRQ8HandlerPTR
     ENABLEHARDINT 8
    
     ! sti                                ; Interrupts wieder zulassen
    
     if err>0 then
      print "ERROR: ",pbvErr,eradr        : ' Wenn Abbruch durch Fehler, dann ...
     end if
    
    END SUB
    
    '***************************************************************************
    
    Sub SetInteruptVektor (Byval Interupt As Integer,Zeiger As Dword)
    
     DIM Segment AS Local Word
     DIM Offset AS Local Word
    
     Segment = PointSeg (Zeiger)
     Offset=   PointOff (Zeiger)
     ! Push DS
     ! Push DX
     ! MOV AH,&H25
     ! MOV AL,Interupt
     ! MOV DS,Segment
     ! Mov DX,Offset
     ! INT &H21
     ! Pop DX
     ! Pop DS
    
    End Sub
    
    '***************************************************************************
    
    Function GetInteruptVektor (BYVAL NU AS INTEGER) AS DWORD
    
      DIM TEMP AS LOCAL DWORD
      ! MOV AH,&H35
      ! MOV AL,NU
      ! INT &H21
      ! MOV TEMP[2],ES
      ! MOV TEMP[0],BX
      GetInteruptVektor=Temp
    
    End Function
    
    '***************************************************************************
    
    Function PointSeg (Adresse AS DWORD) AS WORD
    
     PointSeg=Adresse \ 65536
    
    End Function
    
    '****************************************************************************
    
    Function Pointoff (Adresse AS DWORD) AS WORD
    
     PointOff=Adresse MOD 65536
    
    End Function
    
    '****************************************************************************
    
    Sub EnableHardInt (IntNr%)
    
     DIM IrqMaske AS Byte
    
     Nr%=IntNr%
    
     IF Nr% >7 Then
        DECR Nr%,8
        MaskPort%=%IMR2
     ELSE
        MaskPort%=%IMR1
     END IF
    
     irqMaske=255
     BIT RESET irqMaske,NR%
     irqMaske=INP(MaskPort%) AND irqMASKE
    
     ! CLI
       OUT MaskPort%,irqMASKE
     ! STI
    
    END Sub
    
    '***************************************************************************
    
    Sub DisableHardInt (IntNr%)
    
     Nr%=IntNr%
    
     IF Nr% >7 Then
        DECR Nr%,8
        MaskPort%=%IMR2
     ELSE
        MaskPort%=%IMR1
     END IF
    
     irqMaske%=0
     BIT SET irqMaske%,NR%
    
     ! CLI
      OUT MaskPort%,INP(MaskPort%) OR irqMASKE%
     ! STI
    
    End Sub
    
    '***************************************************************************
    
    
    
    
    ------------------
    Last edited by Gary Beene; 10 Jul 2014, 07:38 PM. Reason: Code: tags added

  • #2
    there was a recent thread on isr coding that may be of interest to you...
    http://www.powerbasic.com/support/pb...read.php?t=401

    beyond this, i'm not sure what else to suggest... maybe someone else has some ideas or experience with this?

    ------------------
    lance
    powerbasic support
    mailto:[email protected][email protected]</a>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Hello and Happy New Year All Togehter.

      for Lance:
      I had read this thread before but he did not help me with my
      problem. I have read ALL related threads before i asked.

      by the way. I have send you an additional email to
      [email protected] where i have asked for updated handbooks.
      I have version 3.5 but old 3.0 handbooks.
      You said nothing about that question !!!!

      for All:
      I hope that someone will try to compile and
      run my sourcecode so he will see the problem.
      If there are difficults with "text formatting"
      i will send the source code via email.
      Please contact me then if that's the problem

      The easyiest way to see what i mean is to run the proggie
      within the IDE in a W98/95 Dos Box for one time.
      Then you see a test counter which runs.
      When you then stop the proggie and start it again the
      second counter from the Uvent Routine runs too.
      At that point you can run the proggie always fine until
      you close the W98 Dos box (virtual machine)

      In a new DOS Box its again the same. So you can test and
      try without rebooting the pc.

      If you change the constant %INT_HOOK from &h70 to &H08
      you will see that with this other interupt it works
      without the reported problem.

      But i need the RTC interupt because of changing the
      interupt frequency on the fly. Also this interupt
      (alarm, periodly) is usually not used, in other words FREE.

      If someone needs additional explainings about the
      settings for the realtimeclock i made, please ask.

      Shortly
      in the Sub Set_Cmos_Register following should happen

      1. Masking Interupt - Disable
      2. store old rtc register
      3. store old pic2 register
      4. manipulating rtc registers for interupt frequency
      6. install new handler
      5. activating periodly RTC interupt
      7. Masking Interupt - Enable

      after that sub i switched UEVENT ON.

      It seems to be that for any unknown reason PowerBasic
      not get a SetUvent Trigger at the first time. But why
      it's ok when you run the proggie twice ??????????????

      best regards
      Rainer



      ------------------

      Comment


      • #4
        Code:
        ' ! MOV DX,&HA0 ' For Test Purposes
        ' ! MOV AX,&H20
        ' ! OUT DX,AX ' EOI Slave
        ' ! MOV DX,AX ' Adress is &h20 too
        ' ! OUT DX,AX ' EOI Master
        It's been more than a few years but, if I recall correctly, you
        want 8-bit OUTs here. Try replacing the OUT DX,AX instructions
        with OUT DX,AL instructions.

        ------------------
        Tom Hanlin
        PowerBASIC Staff
        Last edited by Gary Beene; 10 Jul 2014, 07:39 PM. Reason: Code: tags added

        Comment


        • #5
          Thanx Tom
          for your reply.

          But i had tested AX and AL before.
          I could not right here all i have tested until now
          because my mails would then bee too long and i think
          no one will read it then ))

          The only stupid but running workaround i found for 2 hours
          is the following code snippet.

          Code:
           **********************************************************
          on uevent gosub TaskHandler 
          on error goto TaskerStop  
          exit far at TaskerStop                                
          
          Set_CMOS_Register     ' ON
          Reset_CMOS_Register   ' OFF            Two Line Work     
          Set_CMOS_Register     ' ON AGAIN       Around
          
          UEVENT ON             ' And now it works !!!!!!
                                ' But i don't know why !!!!
          $EVENT ON
            cls
             do
                call Test1
             loop until inkey$ = chr$(27)     'ESC
          $EVENT OFF
          
          TaskerStop:
          Reset_CMOS_Register  
          end
          
          **********************************************************
          best regards
          Rainer



          ------------------
          Last edited by Gary Beene; 10 Jul 2014, 07:40 PM.

          Comment

          Working...
          X