/*
 * "Hello World" example.
 *
 * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
 * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example
 * designs. It runs with or without the MicroC/OS-II RTOS and requires a STDOUT
 * device in your system's hardware.
 * The memory footprint of this hosted application is ~69 kbytes by default
 * using the standard reference design.
 *
 * For a reduced footprint version of this template, and an explanation of how
 * to reduce the memory footprint for a given application, see the
 * "small_hello_world" template.
 *
 */

// Software controller that interacts with the NIOS II hardware via an Avalon Bus interface
// Created by : Jonathan Chen (jtc2119)
// Last modified : Apr. 7, 2008


#include <io.h>
#include <system.h>
#include <stdio.h>

#define IOWR_AUDIO_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data) 
#define IORD_AUDIO_DATA(base, offset) \
  IORD_16DIRECT(base, (offset) * 2)
#define IOWR_SRAM_DATA(base, offset, data) \
  IOWR_16DIRECT(base, (offset) * 2, data) 
#define IORD_SRAM_DATA(base, offset) \
  IORD_16DIRECT(base, (offset) * 2)
#define HORT_OFFSET 0
#define VERT_OFFSET 1
#define HORT_CORD 20
#define VERT_CORD 400
#define HORT_BEG 10
#define HORT_END 600
#define VERT_BEG 10
#define VERT_END 450
#define DELAY 10

int main()
{
  int count = 0;
  int hort, vert;
  int down, right;
  int i = 0;
  int audio_data; 
  
  printf("Hello Mr. Anderson\n");

  hort = HORT_CORD;
  vert = VERT_CORD;
  down = 1;
  right = 1;
  LCD_Test();
  
  
 /* short * audioPtr = SRAM_0_BASE;
  
  for (i=0; i<200; i++) {
    //ignor read
    audioPtr[i] = audio_data; 
    audioPtr[5] = 7;
    audioPtr[5] = 8; 
    value = audioPtr[5];
    value2= audioPtr[5]; 
  }*/
  
  while (1) {    
       for (i = 0; i < 2; i++) {
           audio_data = IORD_AUDIO_DATA(AUDIO_BASE, HORT_OFFSET); 
           IOWR_SRAM_DATA(SRAM_0_BASE, i, audio_data);           
       }
       for (i = 0; i < 2; i++) { 
           audio_data = IORD_SRAM_DATA(SRAM_0_BASE, i);
           IOWR_AUDIO_DATA(AUDIO_BASE, i, audio_data);           
       }
       
  /*       audio_data = IORD_AUDIO_DATA(AUDIO_BASE, HORT_OFFSET); 
          IOWR_SRAM_DATA(SRAM_0_BASE, HORT_OFFSET, audio_data);
          audio_data = IORD_SRAM_DATA(SRAM_0_BASE, HORT_OFFSET);
          IOWR_AUDIO_DATA(AUDIO_BASE, HORT_OFFSET, audio_data); 
          IOWR(SEG7_DISPLAY_BASE,0,i++);
  */
        printf("The button pressed is %x:\n", IORD_AUDIO_DATA(BUTTON_PIO_BASE, HORT_OFFSET));
        for (count = 0; count < DELAY; count++);
  }    
  return 0;
}
