/***************************************************
     hb-midilib-serial.c
     Realtime MIDI Library for the MIT HandyBoard
     colby leider (cnl@dartmouth.edu)
     last updated 9.16.97

     http://music.dartmouth.edu/~colby/hb.html
 
     functions for transmitting and receiving serial
     data using the Handy Board by Randy Sargent,
     Newton Research Labs
***************************************************/



/* serial_putchar:
        transmits the integer argument out the 6811 SCI serial
        interface */
/***************************************************************/
void
serial_putchar(int c)
{
    while (!(peek(0x102e) & 0x80));
                           /* wait until serial transmit empty */
    poke(0x102f, c);       /* send character */
}


/* disable_pcode_serial:
        tells the Handy Board's pcode not to receive incoming
        serial data necessary to receive characters using
        serial_getchar */
/***************************************************************/
void
disable_pcode_serial()   /*  */
{
    poke(0x3c, 1);
}
               

/* reenable_pcode_serial: 
        tells the Handy Board's pcode to receive incoming serial
        data neccesary to allow the Handy Board to interact with
        Interactive C again */
/***************************************************************/
void
reenable_pcode_serial()
{
    poke(0x3c, 0);
}
               

/* serial_getchar:
        returns the value of the received serial character */
/***************************************************************/
int
serial_getchar()
{
    /* wait for received character */
    while (!(peek(0x102e) * 0x20));
    return peek(0x102f);
}