int main(void) { // init GPIO PORTB = 0b11111000; // bits 0-2 are driven externally DDRB = 0b00011000; // data read and data write latches PORTC = 0b11111111; // pullups enabled PORTD = 0b11111111; // pullups enabled // init UART UCSR0B = (1<<TXEN0);//|(1<<RXEN0); UBRR0 = BAUD_MIDI; // init timer TCCR1B |= (1<<WGM12)|(1<<CS10); // timer1 ctc mode, no prescaler TIMSK1 |= (1<<OCIE1A); // enable ctc interrupt OCR1A = F_CPU / RTCFREQ - 1; // ctc value // init emulator MPU401_Init(); // enable interrupts sei(); while(1) // main loop { // do isa i/o if (QueueUsed() && (~PINB & PIN_DSR)) { send_isa_byte(MPU401_ReadData()); // send data if there's any in the buffer } if (PINB & PIN_CRR) { // isa control input latch is full MPU401_WriteCommand(recv_isa_byte()); } if (PINB & PIN_DRR) { // isa data input latch is full MPU401_WriteData(recv_isa_byte()); } // do midi i/o send_midi_byte(); // see if we need to send a byte /* if (UCSR0A & (1<<RXC0)) { // midi uart rx buffer is full process_midi_byte(); } */ } }
static uint8_t mpu401_read(uint16_t addr, void *p) { mpu_t *mpu = (mpu_t *)p; uint8_t ret; switch (addr & 1) { case 0: //Read Data ret = MPU401_ReadData(mpu); pclog("Read Data (0x330) %X\n", ret); break; case 1: //Read Status ret = 0x3f; /* Bits 6 and 7 clear */ if (mpu->state.cmd_pending) ret|=STATUS_OUTPUT_NOT_READY; if (!mpu->queue_used) ret|=STATUS_INPUT_NOT_READY; pclog("Read Status (0x331) %x\n", ret); break; } /* pclog("MPU401 Read Port %04X, ret %x\n", addr, ret); */ return ret; }