Guest User

Untitled

a guest
Sep 14th, 2013
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <avr/io.h>
  2. #include <stdbool.h>
  3. #include "data.h"
  4.  
  5. //PD data
  6. //PC control
  7. //PB programming + xtal + clocko (CKOUT fuse)
  8.  
  9. #define CE (_BV(PC0))
  10. #define WE (_BV(PC1))
  11. #define READY (_BV(PC2))
  12.  
  13. inline static unsigned char get( uint16_t p){
  14. return pgm_read_byte(&data[p]);
  15. }
  16.  
  17. #define PRESCALER 8
  18.  
  19. #if PRESCALER == 1
  20. #define PRESCALERSETTING _BV(CS10)
  21. #define SLEEPNTSC 59659
  22. //wait an overflow before this
  23. #define SLEEPPALOVERSLEEP
  24. #define SLEEPPAL 6055
  25. #elif PRESCALER == 8
  26. #define PRESCALERSETTING _BV(CS11)
  27. #define SLEEPNTSC 7457
  28. #define SLEEPPAL 8949
  29. #elif PRESCALER == 64
  30. #define PRESCALERSETTING _BV(CS11)|_BV(CS10)
  31. #define SLEEPNTSC 932
  32. #define SLEEPPAL 1119
  33. #endif
  34.  
  35.  
  36.  
  37. void write(unsigned char c){
  38. PORTD=c;
  39. PORTC&=~CE;
  40. PORTC&=~WE;
  41. while(PINC&READY){}//wait READY to go down
  42. while((PINC&READY)==0){}//wait READY to go up
  43. PORTC|=CE|WE;
  44. }
  45.  
  46.  
  47. int main(){
  48. DDRD=0xFF;
  49. DDRC|=CE|WE;
  50. PORTC|=READY;//enable the pullup
  51. TCCR1A=0;
  52. TCCR1B=PRESCALERSETTING;
  53. PORTC|=CE|WE;
  54. uint16_t p=0;
  55.  
  56. while(true){
  57. unsigned char cmd=get(p++);
  58. switch(cmd){
  59. case 0x4f: //game gear psg stereo
  60. p++;
  61. break;
  62. case 0x50://write value
  63. write(get(p++));
  64. break;
  65. case 0x61:{//variable delay
  66. uint16_t delay;
  67. unsigned char low,high;
  68. TCNT1=0;
  69. low=get(p++);
  70. high=get(p++);
  71. delay=high*256+low;
  72. while (TCNT1<delay){};
  73. }
  74. break;
  75. case 0x62://NTSC delay
  76. TCNT1=0;
  77. while (TCNT1<SLEEPNTSC){};
  78. break;
  79. case 0x63://PAL delay
  80. TCNT1=0;
  81. #ifdef SLEEPPALOVERSLEEP
  82. while (TCNT1<60000){};
  83. #endif
  84. while (TCNT1<SLEEPPAL){};
  85. break;
  86. case 0x66:
  87. p=0;
  88. break;
  89. } //switch
  90. }//while true
  91. }//main
Advertisement
Add Comment
Please, Sign In to add comment