-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
108 lines (92 loc) · 2.66 KB
/
main.c
File metadata and controls
108 lines (92 loc) · 2.66 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by jswag on 4/12/18.
//
#include <stdio.h>
#include <stdbool.h>
#include <SDL_events.h>
#include <SDL_timer.h>
#include <SDL.h>
#include "includes.h"
#include "cpu.h"
#include "joypad.h"
CPU *cpu;
void HandleInput(SDL_Event event){
int key;
switch(event.type){
case SDL_KEYUP:
key = -1;
switch( event.key.keysym.sym )
{
case SDLK_a : key = 4 ; break ;
case SDLK_s : key = 5 ; break ;
case SDLK_RETURN : key = 7 ; break ;
case SDLK_SPACE : key = 6; break ;
case SDLK_RIGHT : key = 0 ; break ;
case SDLK_LEFT : key = 1 ; break ;
case SDLK_UP : key = 2 ; break ;
case SDLK_DOWN : key = 3 ; break ;
default: break;
}
if (key != -1)
{
KeyReleased(cpu->mmu, key);
}
break;
case SDL_KEYDOWN:
key = -1;
switch( event.key.keysym.sym )
{
case SDLK_a : puts("A down\n");key = 4 ; break ;
case SDLK_s : puts("S down\n");key = 5 ; break ;
case SDLK_RETURN : puts("Ret down\n");key = 7 ; break ;
case SDLK_SPACE :puts("Space down\n"); key = 6; break ;
case SDLK_RIGHT : puts("Right down\n");key = 0 ; break ;
case SDLK_LEFT : puts("Left down\n");key = 1 ; break ;
case SDLK_UP : puts("UP down\n");key = 2 ; break ;
case SDLK_DOWN :puts("Down\n"); key = 3 ; break ;
default: break;
}
if (key != -1)
{
KeyPressed(cpu->mmu, key);
}
break;
}
}
int main(int argc, char *argv[]){
if(argc < 2) {
printf("Format: jemulator <rom filename>\n");
return 0;
}
cpu = malloc(sizeof(CPU));
init(cpu, argv[1]);
bool quit = 0;
SDL_Event event;
float fps = 59.73 ;
float interval = 1000 ;
interval /= fps;
FILE *fp = fopen("Dcompile.txt", "w");
unsigned int time2 = SDL_GetTicks( ) ;
while (!quit)
{
while( SDL_PollEvent( &event ) )
{
HandleInput( event ) ;
if( event.type == SDL_QUIT )
{
quit = true;
}
}
unsigned int current = SDL_GetTicks( ) ;
if( (time2 + interval) < current )
{
// fprintf(fp, "PC: %x\n", cpu->PC.val);
update(fp, cpu);
time2 = current ;
// draw_screen(cpu->mmu->lcd);
// getchar();
}
}
SDL_Quit( ) ;
return 0;
}