# MFP, keyboard, mouse, clock and joysticks ## The MC68901 MFP (DOC: MFP, Motorola's data sheet ADI-984, January 1984) Eight general-purpose I/O lines (GPIP) each with an edge-select bit and an interrupt channel; 16 interrupt channels in fixed priority (eight internal, eight external, GPIP 7 highest, section 3); four timers, of which A and B are multi-mode (delay, pulse-width measurement, event count) and C and D are delay-only (section 5.1); delay-mode prescalers of 4, 10, 16, 50, 64, 100 and 200 (TACR/TBCR/TCDCR tables, section 5); a USART (asynchronous, or synchronous with a polynomial generator; section 6) whose transmit and receive clocks come from the TC and RC pins, commonly from Timer D's output. "All of the 24 registers are also directly addressable" (section 1), at odd addresses 01-2F when RS1-RS5 connect to A1-A5 (table 1-1): GPIP 01, AER 03, DDR 05, IERA 07, IERB 09, IPRA 0B, IPRB 0D, ISRA 0F, ISRB 11, IMRA 13, IMRB 15, VR 17, TACR 19, TBCR 1B, TCDCR 1D, TADR 1F, TBDR 21, TCDR 23, TDDR 25, SCR 27, UCR 29, RSR 2B, TSR 2D, UDR 2F. After reset the vector register is 0F and all timers and the USART are stopped (section 2/3, reset). The MFP supplies its vector in the acknowledge cycle: the upper four bits from VR, the lower four the channel number. ### On the X68000 At E88000, so register r is at E88001 + 2r (OBSERVED: the IPL writes E88003-E8802F). The GPIP lines' sources are HYPOTHESIS (community knowledge) except GPIP 3: | GPIP | Source | | --- | --- | | 0 | RTC alarm | | 1 | EXPON (external power) | | 2 | POWER switch | | 3 | **YM2151 /IRQ** (ym2151-python `docs/users.md`, citing MAME's BSD-3-Clause `sharp/x68k.cpp`) | | 4 | V-DISP (vertical display period) | | 5 | (fixed) | | 6 | CIRQ: the CRTC's raster interrupt (R09) | | 7 | H-SYNC | **The IPL's MFP set-up (OBSERVED, first 60 frames, in order):** DDR = 00 (all inputs), AER = 06, TCDCR = 70, TCDR = C8, IERA = 18, IERB = 26, IMRA = 18, IMRB = 26, VR = 40, TACR = 08, TBCR = 01, TBDR = 0D, UCR = 88, RSR = 01, TSR = 01, then keyboard command bytes through UDR (FF, 41, 49, 59, 51, 5C, 63, 72, ...). Read through the data sheet (DOC): vectors 0x40-0x4F with automatic end of interrupt (VR bit 3 clear); Timer C in delay mode with the /200 prescaler and a count of 200, which at MAME's 4.00 MHz MFP clock is a **100 Hz tick** (arithmetic); Timer A in event-count mode (TACR = 08; its data register not written yet); Timer B in delay mode /4 with a count of 13; interrupts enabled for the receiver (buffer full and error), Timer C and GPIP 1-2; UCR = 88: clock / 16, 8 data bits, asynchronous with one stop bit, no parity. Timer B's output toggles at every time-out, so it is a square wave of 4 MHz / 4 / 13 / 2 = 38.46 kHz; divided by the USART's 16 that is **2,404 bit/s**, the keyboard's commonly quoted 2,400 baud. So Timer B's output is very likely the USART's TC/RC clock (arithmetic on OBSERVED values; the wiring itself is HYPOTHESIS, U7). Timer A in event count with V-DISP as its input is the commonly described use (HYPOTHESIS). ## The keyboard (on the MFP's USART) The keyboard is its own microcontroller talking serially to the MFP's USART: key codes in, LED and control commands out (the IPL's UDR writes above; MAME's keyboard device logs "LED status set to 7f", a 500 ms repeat delay and 30 ms repeat rate from them: OBSERVED). Its rate (2,400 bit/s, by the Timer B arithmetic above) and its command set are HYPOTHESIS (U8). The keyboard MCU's firmware is not dumped (MAME models it high-level: its keyboard device has no ROM), so the board models it **functionally** at the serial line: a socket `KeyboardPort` that turns host key events into the byte stream and decodes the commands. ## The mouse (on the Z8530 SCC, channel B) **Correction to the brief's wording:** the mouse is not on the MFP's USART. The IPL programs the **SCC's channel B** (E98001) as the mouse port (OBSERVED, 182 SCC writes): WR5 = 60/62/E2/EA (the RTS bit toggled), WR9 = C0 (hardware reset) then 80, WR4 = 45 (clock x16, one stop bit, parity on, odd), WR2 = 50 (vector base 0x50), WR3 = C0 then C1 (receive 8 bits, then enable), WR11 = 56, WR12/13 = 0E/00 (baud time constant 14), WR14 = 02 then 03 (baud generator on), WR15 = 00, WR1 = 00, WR0 = 80/10. Read through the SCC technical manual (DOC: SCC), RTS on channel B is the line the mouse protocol uses as its "send now" strobe (MSCTRL: HYPOTHESIS), and the baud generator's rate depends on which clock feeds it (U15). MAME's device tree has a separate `mouse_port` RS-232 port (OBSERVED). Channel A is the RS-232C port. The SCC interrupts at level 5 (HYPOTHESIS) with vectors from WR2. The Z8530 is new to the family (no core or board models it). It stays in the board. ## The RTC (Ricoh RP5C15; DOC: RTC, the Ricoh 1988 data book) "A real-time clock for microcomputer that can be connected directly with the data bus of 16-bit" processors (RTC, RP5C15 section), with a 32.768 kHz crystal (MAME: "Ricoh RP5C15 RTC @ 32.76 kHz", OBSERVED) and an alarm output (to MFP GPIP 0: HYPOTHESIS). At E8A000, odd bytes; the IPL writes E8A01B (the mode register: bank select, timer and alarm enables), E8A01D, E8A01F and E8A001 (OBSERVED addresses; meanings from the data sheet's register table). The family's msx-python plans the RP5C01, a sibling part, inside its board; the two are not proposed for a shared core (different bus width and pin-out; U13 checks how close their register sets are). ## The joysticks (8255 PPI) Two Atari-style (MSX-compatible) joystick ports on PPI ports A and B; port C carries the ADPCM's rate and pan bits and the joystick control lines (sound.md). The IPL sets the PPI control word to 92 (OBSERVED; read through the 8255's control-word format: mode 0, ports A and B input, port C output) and port C to 0B. MAME's ports default to the FM Towns 2-button pad (OBSERVED). The 8255 is modelled in-board in several family boards (msx-python, cpc-python plan theirs in-board); no shared core exists or is proposed here. ## The system port (E8E000) The IPL unlocks SRAM writing with E8E00D = 31 and locks it again with 00, and writes E8E001, E8E003 (bit 3 toggled about 120 times in 60 frames), E8E007 = 08 (OBSERVED). The meanings (contrast, display and 3D-scope control, keyboard enable, NMI reset, the SRAM lock, the machine ID reads) are HYPOTHESIS (U14).