Heath8080A — Product Design : PAM/8 GUI

Page last updated

home    release    support    design    resources    legal    site map

26-October-2002

 

On this page

keypad
leds
sound

Related links

system architecture
i/o package

PAM/8 GUI

Management of the PAM/8 GUI window is split between the event loop, which handles all the mouse-down and key-down events for the front panel, and a drawing routine that keeps the window itself updated. All of the PAM/8 I/O ports are managed by the I/O package.

This page focuses on keypad handling, which is done in the event handler, LED drawing, which is done in panel drawing, and sound, which is done entirely in the I/O package.


Keypad Events

Keypad/Mouse Use

When there's a mouse-down event in the body of the GUI window, it may be on a front-panel keypad button.

The buttons are icons drawn on adjacent 36 x 36 pixel squares. Our requirements for mouse-down notification are very simple, so I bypassed the overhead of using controls to represent the buttons and handle the mouse-down events locally.

If the point hit is not within the keypad rectangle, it's ignored. Otherwise, the point is scaled by subtracting the top and left rectangle offset so that we're working from an origin of zero. The event handler maintains an array of buttons, starting at the top left and working across then down to the bottom right. An index to that array is developed from this scaled v & h coordinate pair:

    keyHit = (v/36)*4 + (h/36);

The key table contains the key code to put on PAM's input port (360q) and a button-down version of the icon, which is drawn. Key code values are:

    Key code Values

    Key

    Value

    Key

    Value

    0

    0xfe

    8

    0xef

    1

    0xfc

    9

    0xcf

    2

    0xfa

    +

    0xaf

    3

    0xf8

    -

    0x8f

    4

    0xf6

    *

    0x6f

    5

    0xf4

    /

    0x4f

    6

    0xf2

    #

    0x2f

    7

    0xf0

    . (dot)

    0x0f

The button stays down as long as you keep the mouse button down. When the subsequent mouse-up event comes in, the no-key value (377q) is placed on PAM's input port and the button-up version of the icon is drawn.

The two-key sequences, 0-# and 0-/, are entered by holding down the keyboard option key while clicking the # or / button, respectively. Option-/ resets the H8 hardware. Option-#, Return to Monitor, forces a clock interrupt and places the value 0x2e (the value of the # key in the high bank and the 0 key in the low bank) on the PAM/8 keypad input port.

Keyboard Use

For convenience and speed in operating the emulator, I mapped certain Mac keyboard keys to emulator functions so that, for example, to enter a "go" command you can click the '4' key on the GUI using the mouse, type '4' on the keyboard, or type 'g' on the keyboard.

Key-down events are processed for the GUI only if the GUI window is front. Keys are mapped as follows:

    Keyboard Mapping

    H8 Key

    Mac Key(s)

    H8 Key

    Mac Key(s)

    0

    0

    8

    8

    1

    1, s

    9

    9

    2

    2, f

    (dot)

    (period), r

    3

    3, b

    #

    #, m

    4

    4, d, g

    /

    /, a

    5

    5, h

    *

    *

    6

    6, p

    -

    -

    7

    7, x

    +

    +



    Alpha Key Meaning

    Key

    Meaning

    r

    Register - Select a register.

    m

    Memory - Select a memory address to display.

    a

    Alter - Enter alter mode.

    p

    Select the PC register pair.

    b

    Select the BC register pair.

    d

    Select the DE register pair.

    f

    Select the AF register pair (f = flags).

    s

    Select the SP register pair.

    h

    Select the HL register pair.

    g

    Go.

    x

    Single Step

Usage example: to set PC to 040.100a and go, enter this command string:

        r p a 0 4 0 1 0 0 a g

... which is equivalent to this command string:

        . 6 / 0 4 0 1 0 0 / 4

There is no state checking in the emulator: we don't verify that 'p' is only used after 'r'. Pressing 'p' is the same as pressing '6' and any user-interface state-related processing is done by PAM/8 as if the front panel keypad were being used.

Both upper and lower case characters are supported.

The two-key sequences, 0-# and 0-/, are entered by holding down the keyboard option key while typing the # or either / key. Option-/ resets the H8 hardware. Option-#, Return to Monitor, forces a clock interrupt and places the value 0x2e on the PAM/8 keypad input port.

The implementation goes generally like this:

  1. On receipt of a key-down or auto-repeat event, check for the Option key modifier. If present:
    • If the keystroke entered is '/', reset the system.
    • If the keystroke entered is '#', force a clock interrupt and put the "return to monitor mode" code (0x2e) on the PAM/8 input port.
    • Exit.
  2. Continuing if no option key: Scan the mapping table for a matching entry. If none is found, exit ignoring the key.
  3. Place the PAM/8 key value corresponding to the keyboard key onto the PAM/8 input port (360q). Then set a timer to expire in 30ms.
  4. Exit key handler.

The scheduling loop decrements the key-down timer and when it expires, puts the no-key code (377q) onto port 360q (ref. time distribution).

PAM/8 expects keystrokes to stay on the port for at least 20ms. I felt that 30ms was a good length of time to keep the key on the port, and it has proven to be very responsive in practice, keeping up with fairly fast typing.

go to top


LED Drawing

The H8's 8-segment LEDs are managed by PAM/8. The LEDs themselves, when written, will flash briefly and then blank, and have to be repeatedly refreshed so that, to the user, they appear to be on constantly. If the LED is not refreshed, it will go blank. This happens when interrupts are disabled for too long — say, during a disk I/O operation — or when front panel refresh is disabled.

PAM/8 refreshes one LED every 2ms clock tick; a given LED will be refreshed every 18ms. The refresh is done in reverse order, right to left. PAM starts by outputting the selected digit index in the low-order nibble of the hardware control port (360q). (The high-order nibble holds hardware flags that control sound, the clock, the single-step instruction interrupt and the monitor lamp.) The LED segment pattern is then output to port 361q.

Bit to Segment Mapping

LED segments are active-off — zero bits are on and one bits are off. Bits correspond to segments as shown in the figure. (Bit zero is the low-order bit.)

The LEDs are addressed with indices of '1' through '9'. Front panel LED refresh can be disabled by setting the UO.NFR bit in the .MFLAG byte in PAM/8's workspace. In that case, the first OUT still takes place but the selected LED index is '0'.

Redrawing a LED every two milliseconds is way too much overhead, so the emulator will buffer output digit patterns. The front panel LEDs are updated en mass immediately before checking for Macintosh events (every 25ms if we're in the foreground and every 10ms if background; ref. time distribution). To simulate blanking when refresh stops, the time of the last refresh is kept. If an LED is not refreshed within 50ms, its pattern is set to 377q — all segments off.

In order to reduce overhead even further, we only redraw the segments that change from draw to draw. To do that, we keep a before and after picture of each LED. Before drawing, the before and after segment patterns are XOR'd together to create a mask; the '1' bits in the mask represent changed bits. Only the "after" segments that correspond with '1' bits in the mask are actually drawn.

While the emulator doesn't redraw on the same frequency as a real H8, the visual appearance is identical, at least according to my memory of the beast.

go to top


Sound

The H8's beeps and clicks are produced in the I/O package.

A real H8 will produce sound by resetting the high-order bit of the byte output to the control port (360q). (The bit is active-on.) While any program can produce sound by setting and resetting this bit, PAM/8 produces only three sounds:

    Sound

    Out Count

    Usage

    short click

    < 10

    Key click

    medium click

    approx. 30

    "Bip" after the 3rd digit when entering octal data

    beep

    > 36

    Alarm

The emulator ignores the short sound, counting on the Mac keyboard and mouse to produce effective feedback. The medium sound is produced by playing a sound resource.

The long alarm is produced by allocating a sound channel and playing a suitable tone using SndDoCommand. This was a simple thing under Mac OS System 8.5, but under System 9.1, I have to clock the sound down myself and clear the channel to clear the sound.

go to top



home   release   support   design   resources   legal   site map