Statistics
| Branch: | Revision:

root / main.c @ 33c367ee

History | View | Annotate | Download (3.37 KB)

1
#define F_CPU 16000000L                                                                                                                                                  
2
#include <inttypes.h>
3
#include <avr/io.h>
4
#include <util/delay.h>
5
#include <avr/interrupt.h>
6

    
7
//let's make our lives easier :)
8
#define PORT_(port) PORT ## port
9
#define DDR_(port)  DDR  ## port
10
#define PIN_(port)  PIN  ## port
11
#define PORT(port) PORT_(port)
12
#define DDR(port)  DDR_(port)
13
#define PIN(port)  PIN_(port)
14
inline void dot(void);
15
inline void noDot(void);
16
inline void OE(void);
17
inline void ODE(void);
18
void loopLines(void);
19
void rotateLeft(uint16_t *in);
20
void moveFlyingRowsDown(void);
21

    
22

    
23
typedef struct sprite { // TODO generic typedef
24
        uint8_t xLeftPos; // TODO merge with xRightPos
25
        uint8_t xRightPos; 
26
        uint8_t yLowerPos;
27
        uint8_t yUpperPos;
28
        uint8_t image;} sprite_t;
29

    
30
volatile uint8_t lines[90] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
31

    
32
int main(){
33
        sprite_t sprite;        
34
        sprite.yLowerPos = 88;
35
        sprite.yUpperPos = 89;
36
        sprite.xLeftPos = 4;
37
        sprite.xRightPos = 5;
38
        sprite.image = 0b001001010; // TODO just mockup...
39

    
40
        lines[40] = 0b00100100;
41
        lines[41] = 0b00000000;
42
        lines[42] = 0b10000001;
43
        lines[43] = 0b01000010;
44
        lines[44] = 0b00111100;
45

    
46

    
47
        DDR(B) = 0xff;
48
        DDR(C) = 0xff;
49
        volatile uint8_t blup = 0;
50
        while(1){
51
                for(uint8_t delay = 0; delay < 254; delay++){
52
                        for(uint8_t round = 0; round < 8; round++){
53
                                for(uint8_t line = 0; line < 90; line++){
54
                                        if((1<<round) & lines[line]){
55
                                                dot();
56
                                        }
57
                                        else{
58
                                                if(sprite.yLowerPos <= line && sprite.yUpperPos >= line
59
                                                        && round >= sprite.xLeftPos && round <= sprite.xRightPos){
60
                                                        dot(); // FIXME mockup
61
                                                }
62
                                                else{
63
                                                        noDot();
64
                                                }
65
                                        }
66
                                }
67
                                OE();
68
                                _delay_us(10);
69
                                ODE();
70
                                blup++;
71
                                PORT(C) = blup;
72
                        }
73
                }
74
                moveFlyingRowsDown();
75
                sprite.yUpperPos--;
76
                sprite.yLowerPos--;
77
//                loopLines();
78
        }
79
}
80
void moveFlyingRowsDown(){
81
        uint8_t moveDown = 0x00;
82
        for(uint8_t line = 0; line < 89; line++){
83
                if(moveDown == 0xff || lines[line] == 0x00){
84
                        lines[line] = lines[line+1];
85
                        moveDown = 0xff;
86
                }
87
        }
88
}
89

    
90

    
91
//void fallingRow(){
92
//        
93
//}
94

    
95
void loopLines(){
96
        uint8_t tmp = lines[0];
97
        for(uint8_t line = 0; line < 89 ; line++){
98
                lines[line] = lines[line+1];
99
        }
100
        lines[89] = tmp;
101
}
102

    
103
inline void dot(){
104
//        PORT(B) = 0x00;
105
        PORT(B) = 0x03;
106
        PORT(B) = 0x00;
107
}
108

    
109
inline void noDot(){
110
//        PORT(B) = 0x00;
111
        PORT(B) = 0x01;
112
        PORT(B) = 0x00;
113
}
114

    
115
inline void OE(){
116
        PORT(B) = 0x04;
117
}
118

    
119
inline void ODE(){
120
        PORT(B) = 0x00;
121
}
122

    
123
void rotateLeft(uint16_t *in){
124
        uint8_t l = *in&0xff;
125
        uint8_t u = (*in>>8)&0xff;
126
        l = ((u&(1<<7)) ? (1<<7)>>4 : 0) | ((u&(1<<6)) ? ((1<<6)>>1) : 0) | ((u&(1<<3)) ? ((1<<3)>>1) : 0) | ((u&(1<<2)) ? ((1<<2)<<4) : 0) | ((l&(1<<6)) ? (1<<6)>>1 : 0) | ((l&(1<<2)) ? (1<<2)<<2 : 0) | ((l&(1<<3)) ? (1<<3)>>3 : 0) | ((l&(1<<7)) ? (1<<7)>>6 : 0);
127
//        l |=((l&(1<<6))>>1) | ((l&(1<<2))<<2) | ((l&(1<<3))>>3) | ((l&(1<<7))>>6);
128
        *in = l;
129
        //*in = ((*in&(1<<15))>>(15-3) | (*in&(1<<14))>>(14-7) | (*in&(1<<13))>>(13-11) | (*in&(1<<12))<<(15-12) | (*in&(1<<11))>>(11-2) | (*in&(1<<10))>>(10-6) | (*in&(1<<9))<<(10-9) | (*in&(1<<8))<<(14-8) | (*in&(1<<7))>>(7-1) | (*in&(1<<6))>>(6-5) | (*in&(1<<5))<<(9-5) | (*in&(1<<4))<<(13-4) | (*in&(1<<3))>>(3-0) | (*in&(1<<2))<<(4-2) | (*in&(1<<1))<<(8-1) | (*in&(1<<0))<<(12-0) );
130
}