Advertisement
lpdunwell

Arduino based AY-3-8910 Player

Apr 15th, 2012
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. // Edited by Luke Dunwell
  2.  
  3. #include <MsTimer2.h> //See www.arduino.cc
  4. #include <avr/pgmspace.h>
  5.  
  6. #define DATADDR  DDRL
  7. #define DATAPORT PORTL
  8. #define BCDDR    DDRB
  9. #define BCPORT   PORTB
  10. #define BC1      0
  11. #define BDIR     2
  12. // BC2 = HIGH (that's for Hardware)
  13.  
  14. const int ledPin = 52;
  15.  
  16. extern prog_uint8_t rawData0[32752]; //As from C# prog
  17.  
  18. byte buffer[16];
  19. int i = 0, j, led = 0;
  20.  
  21. void send_data(unsigned char address, unsigned char data)
  22. {
  23.   DATAPORT = address;                 // Write Address
  24.   BCPORT |=  ((1<<BDIR)|(1<<BC1));    // Validate Address
  25.   delayMicroseconds(1);
  26.   BCPORT &= ~((1<<BDIR)|(1<<BC1));
  27.   DATAPORT = data;                    // Write Data
  28.   BCPORT |=  (1<<BDIR);               // Validate Data
  29.   delayMicroseconds(1);
  30.   BCPORT &= ~(1<<BDIR);
  31. }
  32.  
  33. void update(void)
  34. {
  35.   digitalWrite(ledPin, led ^= 1);
  36.  
  37.   for(j=0; j<16; j++) send_data(j, pgm_read_byte_near(rawData0 + i + j));
  38.  
  39.   i += 16;
  40.   if(i >= 32752) i = 0;
  41. }
  42.  
  43. void setup(void)
  44. {
  45.   // Configure Ports for PSG
  46.   BCDDR |= ((1<<BC1)|(1<<BDIR));
  47.   DATADDR = 0xFF;
  48.   pinMode(ledPin, OUTPUT);
  49.  
  50.   // Deactivate PSG
  51.   BCPORT &=  ~((1<<BDIR)|(1<<BC1));
  52.  
  53.   // Start 50Hz Interrupt
  54.   MsTimer2::set(20, update); // 20ms
  55.   MsTimer2::start();
  56. }
  57.  
  58. void loop(void)
  59. {
  60.   // "whistle while you work"
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement