Compare commits
2 commits
75cee1b333
...
0b0258802f
Author | SHA1 | Date | |
---|---|---|---|
0b0258802f | |||
f88805c849 |
3 changed files with 11722 additions and 0 deletions
11654
Opcodes.json
Normal file
11654
Opcodes.json
Normal file
File diff suppressed because it is too large
Load diff
68
disassembler.c
Normal file
68
disassembler.c
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// How to compile? Like this!
|
||||||
|
// gcc disassembler.c -o disassembler
|
||||||
|
|
||||||
|
// Large chunks of the code are from my Intel 8080 emulator
|
||||||
|
|
||||||
|
typedef struct buffer {
|
||||||
|
unsigned char* buffer;
|
||||||
|
int length;
|
||||||
|
} buffer;
|
||||||
|
|
||||||
|
buffer* read_file(char** argv) {
|
||||||
|
FILE* file = fopen(argv[1], "rb");
|
||||||
|
if (file == NULL) {
|
||||||
|
printf("Issue opening the file.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
fseek(file, 0L, SEEK_END);
|
||||||
|
int fsize = ftell(file);
|
||||||
|
fseek(file, 0L, SEEK_SET);
|
||||||
|
|
||||||
|
buffer *b = malloc(sizeof(buffer));
|
||||||
|
b->buffer = malloc(fsize);
|
||||||
|
b->length = fsize;
|
||||||
|
|
||||||
|
fread(b->buffer, fsize, 1, file);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_buffer(buffer* b) {
|
||||||
|
for (int i = 0; i < 40; i++) {
|
||||||
|
printf("%02x \n", b->buffer[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int disassemble8080(buffer* b, int pc) {
|
||||||
|
unsigned char *code = &(b->buffer[pc]);
|
||||||
|
int opbytes = 1;
|
||||||
|
printf("%04x ", pc);
|
||||||
|
|
||||||
|
// Will parse the opcodes.json for this
|
||||||
|
// To be done after the MMT blog post
|
||||||
|
printf("\n");
|
||||||
|
return opbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main (int argc, char** argv) {
|
||||||
|
int pc = 0; //Program Counter
|
||||||
|
|
||||||
|
buffer* buff = read_file(argv);
|
||||||
|
if (buff == NULL) {
|
||||||
|
printf("Fatal error.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
print_buffer(buff);
|
||||||
|
while (pc < 400) {//buff->length) {
|
||||||
|
pc += disassemble8080(buff, pc);
|
||||||
|
}
|
||||||
|
free(buff);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
BIN
snake.gb
Normal file
BIN
snake.gb
Normal file
Binary file not shown.
Loading…
Reference in a new issue