Difference between revisions of "Receive byte across link cable"

From GbdevWiki
Jump to: navigation, search
 
Line 1: Line 1:
/*
+
<pre>
 
/*
 
/*
 
The MIT License (MIT)
 
The MIT License (MIT)
Line 22: Line 22:
 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
THE SOFTWARE.
 
THE SOFTWARE.
 +
*/
  
*/
 
*/
 
<pre>
 
 
#include <gb/gb.h>
 
#include <gb/gb.h>
 
#include <stdio.h>
 
#include <stdio.h>

Latest revision as of 13:56, 23 May 2015

/*
The MIT License (MIT)

Copyright (c) <2014> <Tom Lukeywood>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#include <gb/gb.h>
#include <stdio.h>

void main(void){
    while(1){//the program is in a while loop so it keeps checking again and again for a byte

      printf("Receiving...");

      /*look for a byte being sent through the link cable
      if there is a byte set _io_in to the value of the byte
      */
      receive_byte();

      /* Wait for IO completion... */
      while(_io_status == IO_RECEIVING){;}

      if(_io_status == IO_IDLE){
       printf("Received:\n%d\n", (int)_io_in);
}
      else{
      printf("error: %d\n", _io_status);
}
}
}