-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathand2.cpp
85 lines (71 loc) · 2.16 KB
/
and2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const char *help = "hold 'a' and 'b' at the same time -> the screen turns red";
#include <cstdlib>
#include "Vand2.h"
#include "verilated.h"
#include <SDL2/SDL.h>
#define WINDOW_WIDTH 512
#define WINDOW_HEIGHT (WINDOW_WIDTH)
int main(int argc, char **argv, char **env) {
SDL_Event event;
SDL_Rect rect;
SDL_Renderer *renderer;
SDL_Window *window;
int a_pressed, b_pressed;
int quit;
quit = 0;
a_pressed = 0;
b_pressed = 0;
Verilated::commandArgs(argc, argv);
Vand2 *top = new Vand2;
SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO);
SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_WIDTH, 0, &window, &renderer);
SDL_SetWindowTitle(window, help);
rect.x = 0;
rect.y = 0;
rect.w = WINDOW_WIDTH;
rect.h = WINDOW_HEIGHT;
while (!quit) {
while (SDL_PollEvent(&event) == 1) {
if (event.type == SDL_QUIT) {
quit = 1;
} else if (event.type == SDL_KEYDOWN) {
switch(event.key.keysym.sym) {
case SDLK_a:
a_pressed = 1;
break;
case SDLK_b:
b_pressed = 1;
break;
default:
break;
}
} else if (event.type == SDL_KEYUP) {
switch(event.key.keysym.sym) {
case SDLK_a:
a_pressed = 0;
break;
case SDLK_b:
b_pressed = 0;
break;
default:
break;
}
}
}
top->in1 = a_pressed;
top->in2 = b_pressed;
top->eval();
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
if (top->out == 1)
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
top->final();
delete top;
return EXIT_SUCCESS;
}