#include "SDL.h"
#include "SDL_syswm.h"
#include "SDL_keyboard.h"
#include <time.h>
#include <stdlib.h>
#include "draw.h"

extern int xy_do_events, xy_shift;
int main(void) {
    xy_init();
    SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
    xy_factor = 5;
    xy_do_events = 0;
    while(1) {
        for(int j=0; j<24; j++) {
        for(int i=0; i<255; i+= 8) {
            xy_draw_line(i, 128-(i+1)/2, i, 128+i/2);
            // xy_draw_line(i+4, 128+i/2, i+4, 128-(i+1)/2);
            xy_nextline();
        }
        xy_nextline();
        xy_draw_line(0, 128, 255, 255);
        xy_nextline();
        }
        // xy_draw_line(0, 128, 255, 0);
        xy_nextline();
        xy_flipscreen();    
        SDL_Event event;
        while(SDL_PollEvent(&event)) {
            switch(event.type) {
            case SDL_KEYDOWN:
                switch(event.key.keysym.sym) {
                    case 'a':
                        xy_shift += 5; printf("shift=%d\n", xy_shift); break;
                    case 'q':
                        xy_shift -= 5; printf("shift=%d\n", xy_shift); break;
                    case SDLK_ESCAPE:  case SDL_QUIT:
                        exit(0);
                }
            }
        }
        if(xy_shift < 0) xy_shift = 0;
        if(xy_shift > 600) xy_shift = 600;
    }
}
