-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathc64vm.c
73 lines (56 loc) · 1.89 KB
/
c64vm.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
71
72
73
/*
Copyright (c) 2023-2024 Noah Scholz
This file is part of the c64vm project.
c64vm is free software: you can redistribute it and/or modify
it under the terms of the MIT License.
c64vm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the MIT License for more details.
You should have received a copy of the MIT License
along with c64vm. If not, see <https://mit-license.org/>.
*/
#include <c64vm.h>
static void c64vm_inject(c64mm_t *mm, uint64_t address, uint8_t *data, size_t size)
{
for (size_t i = 0; i < size; i++)
{
c64mm_setUint8(mm, address + i, data[i]);
}
}
static void c64vm_inject_file(c64mm_t *mm, uint64_t address, const char *filename)
{
FILE *file = fopen(filename, "rb");
if (file == NULL)
{
error("c64vm_inject_file: failed to open file %s\n", filename);
}
fseek(file, 0, SEEK_END);
size_t size = ftell(file);
fseek(file, 0, SEEK_SET);
uint8_t *data = (uint8_t *)malloc(size);
if (data == NULL)
{
error("c64vm_inject_file: malloc failed\n");
}
fread(data, 1, size, file);
fclose(file);
c64vm_inject(mm, address, data, size);
free(data);
}
// Just for now
// will be modified into a more complex interface
void c64vm_run()
{
c64mm_t *mm = c64mm_create();
c64cpu_t *cpu = c64cpu_create(mm, 0x10000000);
c64dev_t *mem = c64mem_createDevice(0x000000000fffffff, cpu);
c64dev_t *stack = c64mem_createDevice(0x000000000fffffff, cpu);
c64mm_map(mm, mem, 0x0000000000000000, 0x000000000fffffff, 1);
c64mm_map(mm, stack, 0xfffffffff0000000, 0xffffffffffffffff, 1);
const char *filename = "out.bin";
c64vm_inject_file(mm, 0x0000000000000000, filename);
c64cpu_viewMemoryAt(cpu, 0x0000000000000000, 64);
c64cpu_run(cpu, 1);
c64cpu_destroy(cpu);
}