Uevent

 BBS: Inland Empire Archive
Date: 08-07-92 (13:57)             Number: 62
From: JEAN CREPEAU                 Refer#: NONE
  To: JAMES VAHN                    Recvd: NO  
Subj: Uevent                         Conf: (2) Quik_Bas
In a message to ALL, JAMES VAHN wrote:
JV=> Could someone explain the use of QB4.5's  ON UEVENT GOSUB ...? I  wish
    to run a background task and  think that's the ticket. I'd like  to tap
    into INT  8 or  better yet  set up  the 8255  PPI and  the 8253  timer.
    Actually would like to see both methods.

        The ON ... GOSUB is called a trap. You can force QuickBASIC to make
an automatic  GOSUB on  certain events.  For instance,  you can  trap a key
sequence, the timer or the joystick.

On timer(1) gosub timetrap
(cont...)

timetrap:
        print "Another second just passed"
        return

        The trap will be executed once every second.

        The only  problem with  the QB  traps is  that they  check for  the
events between instructions  (compiled with /v)  or between lines  (/w). If
you INPUT  something, no  trap will  be executed  until the  instruction is
finished (i.e. the user presses enter).

        You  could  try  to  program  the  INT  8,  but making an interrupt
subroutine with QuickBASIC is not a good idea. QB doesn't provide any  mean
to do that anyway.

        If you want to  program the PPI or  CTC, it's easy... Here  are the
internal registers of the PPI and the CRC:

PPI+0:  Port A  (The adress is 60h on XT)
PPI+1:  Port B  (The adress is 61h on XT)
PPI+2:  Port C  (The adress is 62h on XT)
PPI+3:  Control (The adress is 63h on XT)
        b7: Always 1
        b6-b5: Port A mode (00=mode 0, 01=mode 1, 10=mode 2)
        b4: Port A dir (0=Output, 1=Input)
        b3: Port C, high nibble dir (0=Out,1=In)
        b2: Port B mode (0=mode 0, 1=mode 1)
        b1: Port B dir (0=Output, 1=Input)
        b0: Port C, low nibble dir (0=Out, 1=In)
        Mode 0 is generally used

CTC+0:  Channel 0 counter I/O   (adress=40h)
CTC+1:  Channel 1 counter I/O   (adress=41h)
CTC+2:  Channel 2 counter I/O   (adress=42h)
CTC+3:  Control                 (adress=43h)
        b7-b6: counter select (00=0, 01=1, 10=2, 11=illegal)
        b5-b4:  00: Temp. freeze counter for reading
                01: Read/write the LSB
                10: Read/write the MSB
                11: Read/write the LSB, then the MSB
        b3-b1:  000: Mode 0 (restart to count when a new counter is loaded)
                001: Mode 1 (restart to count when the trigger activated)
                x10: Mode 2 (automatic restart when counter is finished)
                x11: Mode 3 (like 2, but generates a square signal=>sound)
                100: Mode 4 (like 0, but generates a pulse)
                101: Mode 5 (like 1, but generates a pulse)
        b0: counter type (0=16-bit, 1=BCD)

        Normally, all input clocks for the three timers are connected to  a
1.19047 MHz clock. Channel 0 is  used for DOS internal clock. Channel  1 is
used for RAM refresh. And channel 2 is used for sound generation.

        For instance if you want to program channel 2 for sound:

Out 43h,10110110
        (Program channel 2, LSB/MSB, mode 3 in 16-bit)
Counter&=1190470/Freq
MSB%=int(Counter&/256)
LSB%=Counter& and 255
Out 42h,LSB%
Out 42h,MSB%
Out 61h,In(61h) or 3

        The last line is used to  activate the speaker with the channel  2,
by setting bits 0 and 1 of PPI Port B to 1.

                Jean
---
 * Origin: INTERACESS Montreal (QC) Canada (514) 528-1415 (1:167/280)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET