Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new packed cartridge format in preparation for, stuff
- Loading branch information
Showing
5 changed files
with
123 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "config.h" | ||
|
||
#include <fcntl.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
#include "vg8m.h" | ||
#include "internal.h" | ||
|
||
static const char MAGIC[] = "VGDMP100"; | ||
|
||
typedef struct s_dump_header DumpHeader; | ||
struct s_dump_header { | ||
char magic[8]; | ||
uint16_t flags; | ||
uint16_t prog_offset; | ||
uint16_t prog_size; | ||
uint16_t pat_2bpp_offset; | ||
uint16_t pat_2bpp_size; | ||
uint16_t pat_3bpp_offset; | ||
uint16_t pat_3bpp_size; | ||
}; | ||
|
||
typedef struct s_cart_header CartHeader; | ||
struct s_cart_header { | ||
char magic[8]; | ||
char title[0x20]; | ||
char developer[0x20]; | ||
char lang[2]; | ||
uint16_t flags; | ||
uint8_t version; | ||
}; | ||
|
||
bool vg8m_load_cart(VG8M *emu, const char *filename) { | ||
DumpHeader header; | ||
int fd = open(filename, O_RDONLY); | ||
if (fd == -1) goto error; | ||
|
||
if (read(fd, &header, sizeof(header)) == -1) | ||
goto error; | ||
|
||
if (header.prog_size > 0) { | ||
if (lseek(fd, header.prog_offset, SEEK_SET) == -1 | ||
|| read(fd, emu->cart_prog_rom, header.prog_size) == -1) | ||
goto error; | ||
} | ||
|
||
if (header.pat_2bpp_size > 0) { | ||
if (lseek(fd, header.pat_2bpp_offset, SEEK_SET) == -1 | ||
|| read(fd, emu->cart_2bpp_rom, header.pat_2bpp_size) == -1) | ||
goto error; | ||
} | ||
|
||
if (header.pat_3bpp_size > 0) { | ||
if (lseek(fd, header.pat_3bpp_offset, SEEK_SET) == -1 | ||
|| read(fd, emu->cart_3bpp_rom, header.pat_3bpp_size) == -1) | ||
goto error; | ||
} | ||
|
||
close(fd); | ||
return true; | ||
error: | ||
if (fd != -1) close(fd); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
#include "vg8m.h" | ||
|
||
enum { | ||
SYS_ROM_SIZE = 0x0800, | ||
SYS_RAM_SIZE = 0x0700, | ||
HWREGS_SIZE = sizeof(VG8MRegisters), | ||
CHAR_ROM_SIZE = 0x1000, | ||
USER_RAM_SIZE = 0x4000, | ||
CART_ROM_SIZE = 0x8000, | ||
|
||
CART_2BPP_SIZE = 0x4000, | ||
CART_3BPP_SIZE = 0x3000, | ||
}; | ||
|
||
|
||
enum { | ||
SYS_ROM_ADDR = 0x0000, SYS_ROM_END = 0x07FF, | ||
SYS_RAM_ADDR = 0x0800, SYS_RAM_END = 0x0EFF, | ||
HWREGS_ADDR = 0x0F00, HWREGS_END = HWREGS_ADDR + HWREGS_SIZE - 1, | ||
CHAR_ROM_ADDR = 0x1000, CHAR_ROM_END = 0x1FFF, | ||
USER_RAM_ADDR = 0x4000, USER_RAM_END = 0x7FFF, | ||
CART_ROM_ADDR = 0x8000, CART_ROM_END = 0xFFFF, | ||
}; | ||
|
||
enum { | ||
INT_VBLANK = 0x20, | ||
INT_HBLANK = 0x22, | ||
}; | ||
|
||
enum { | ||
MODE_HBLANK, | ||
MODE_VBLANK, | ||
MODE_DRAW, | ||
}; | ||
|
||
enum { | ||
CYCLES_HBLANK = 200, | ||
CYCLES_VBLANK = 500, | ||
CYCLES_DRAW = 200, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters