Commodore Amiga 1000 — Commodore Amiga 1000 Hardware Reference Manual PDF Download

READING THE COUNTERS The mouse/trackball counter contents can be accessed by reading register addresses named JOY0DAT and JOY1DAT. These contains counts for ports 1 and 2 respectively. The contents of each of these 16-bit registers are as follows: Bits 15-8 Mouse/trackball vertical count Bits 7-0 Mouse/trackball horizontal count COUNTER LIMITATIONS These counters will "wrap around" in either the positive or negative direction. If you wish to use the mouse to control something that is happening on the screen, you must read the counters at least once each vertical blanking period and save the previous contents of the registers.

Then you can subtract from the previous readings to determine direction of movement and speed. The mouse produces about 200 count pulses per inch of movement in either a horizontal or vertical direction. Vertical blanking happens once each 1/60th of a second. If you read the mouse once each vertical blanking period, you will most likely find a count difference (from the previous count) of less than 127. Only if a user moves the mouse at a speed of more than 38 inches per second will the counter values wrap. Fast-action games may need to read the mouse register twice per frame to prevent counter overrun.

If you subtract the current count from the previous count, the absolute value of the difference will represent the speed. The sign of the difference (positive or negative) lets you determine which direction the mouse is travelling. The easiest way to calculate mouse velocity is with 8-bit signed arithmetic. The new value of a counter minus the previous value will represent the number of mouse counts since the last check. The example shown in Table 8-2 presents an alternate method. It treats both counts as unsigned values, ranging from 0 to 255. A count of 100 pulses is measured in each case. - Interface Hardware 225 -