PCem

view src/sound_mpu401_uart.c @ 154:d0d530adce12

Initial port to Linux (using Allegro). 64-bit fixes. Some changes to aid portability. A few other tweaks.
author TomW
date Thu Sep 04 21:07:24 2014 +0100
parents ee7a3f8ad75d
children
line source
1 #include "ibm.h"
2 #include "io.h"
3 #include "sound_mpu401_uart.h"
5 enum
6 {
7 STATUS_OUTPUT_NOT_READY = 0x40,
8 STATUS_INPUT_NOT_READY = 0x80
9 };
11 static void mpu401_uart_write(uint16_t addr, uint8_t val, void *p)
12 {
13 mpu401_uart_t *mpu = (mpu401_uart_t *)p;
15 if (addr & 1) /*Command*/
16 {
17 switch (val)
18 {
19 case 0xff: /*Reset*/
20 mpu->rx_data = 0xfe; /*Acknowledge*/
21 mpu->status = 0;
22 mpu->uart_mode = 0;
23 break;
25 case 0x3f: /*Enter UART mode*/
26 mpu->rx_data = 0xfe; /*Acknowledge*/
27 mpu->status = 0;
28 mpu->uart_mode = 1;
29 break;
30 }
31 return;
32 }
34 /*Data*/
35 if (mpu->uart_mode)
36 midi_write(val);
37 }
39 static uint8_t mpu401_uart_read(uint16_t addr, void *p)
40 {
41 mpu401_uart_t *mpu = (mpu401_uart_t *)p;
43 if (addr & 1) /*Status*/
44 return mpu->status;
46 /*Data*/
47 mpu->status |= STATUS_INPUT_NOT_READY;
48 return mpu->rx_data;
49 }
51 void mpu401_uart_init(mpu401_uart_t *mpu, uint16_t addr)
52 {
53 mpu->status = STATUS_INPUT_NOT_READY;
54 mpu->uart_mode = 0;
56 io_sethandler(addr, 0x0002, mpu401_uart_read, NULL, NULL, mpu401_uart_write, NULL, NULL, mpu);
57 }