-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamul.c
70 lines (59 loc) · 1.55 KB
/
gamul.c
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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "gamul.h"
// font set for rendering
const unsigned char fontset[FONTSET_SIZE] = {
0xF0, 0x90, 0x90, 0x90, 0xF0, // 0
0x20, 0x60, 0x20, 0x20, 0x70, // 1
0xF0, 0x10, 0xF0, 0x80, 0xF0, // 2
0xF0, 0x10, 0xF0, 0x10, 0xF0, // 3
0x90, 0x90, 0xF0, 0x10, 0x10, // 4
0xF0, 0x80, 0xF0, 0x10, 0xF0, // 5
0xF0, 0x80, 0xF0, 0x90, 0xF0, // 6
0xF0, 0x10, 0x20, 0x40, 0x40, // 7
0xF0, 0x90, 0xF0, 0x90, 0xF0, // 8
0xF0, 0x90, 0xF0, 0x10, 0xF0, // 9
0xF0, 0x90, 0xF0, 0x90, 0x90, // A
0xE0, 0x90, 0xE0, 0x90, 0xE0, // B
0xF0, 0x80, 0x80, 0x80, 0xF0, // C
0xE0, 0x90, 0x90, 0x90, 0xE0, // D
0xF0, 0x80, 0xF0, 0x80, 0xF0, // E
0xF0, 0x80, 0xF0, 0x80, 0x80 // F
};
void loadFont(uint8_t memory[]) {
for (int i = 0; i < FONTSET_SIZE; i++) {
memory[i] = fontset[i];
}
}
int load_file(char *file_name, unsigned char *buffer)
{
FILE *file;
int file_size;
file = fopen(file_name, "rb");
if (file == NULL) {
printf("Unable to open file\n");
return -1;
}
fseek(file, 0, SEEK_END);
file_size = ftell(file);
rewind(file);
fread(buffer, 1, file_size, file);
return 0;
}
/* FUNCTION: display_func
* ----------------------
* Sample function that displays a pixel on the screen
* PARAMETERS:
* gamer: architecture to be emulated, defined in gamul.h
* RETURNS: none
*/
void display_func(gamul8 *gamer) {
gamer->display[20][40] = 1;
gamer->display[10][30] = 0;
gamer->display[0][0] = 1;
gamer->display[31][0] = 1;
gamer->display[0][62] = 1;
}