ROM generation

This commit is contained in:
Aaron Culliney 2014-06-22 11:09:59 -07:00
parent 670a776571
commit a3973b2e35
5 changed files with 130 additions and 8 deletions

2
.gitignore vendored
View File

@ -44,12 +44,14 @@ apple2ix*.tar.gz
test-driver
# generated sources
src/rom.c
src/x86/glue.S
src/meta/debug.c
# generated binaries
apple2ix
genfont
genrom
# man testing
man

View File

@ -21,7 +21,7 @@ noinst_HEADERS = src/apple2.h src/common.h src/cpu.h src/disk.h src/glue.h \
src/audio/soundcore-openal.h src/audio/speaker.h \
src/audio/SSI263Phonemes.h src/audio/win-shim.h
noinst_PROGRAMS = genfont
noinst_PROGRAMS = genfont genrom
###############################################################################
# Apple //ix and supporting sources
@ -57,7 +57,7 @@ EXTRA_apple2ix_SOURCES = \
\
$(META_SRC)
apple2ix_SOURCES = src/font.c src/misc.c src/display.c src/vm.c \
apple2ix_SOURCES = src/font.c src/rom.c src/misc.c src/display.c src/vm.c \
src/timing.c src/zlib-helpers.c src/joystick.c src/keys.c src/prefs.c \
src/disk.c src/cpu-supp.c
@ -68,9 +68,14 @@ apple2ix_DEPENDENCIES = @ASM_O@ @INTERFACE_O@ @VIDEO_O@ @AUDIO_O@ @META_O@
genfont_SOURCES = src/genfont.c
genrom_SOURCES = src/genrom.c
src/font.c: src/font.txt genfont
./genfont < $< > $@
src/rom.c: src/rom/apple_IIe.rom src/rom/slot6.rom genrom
./genrom $^ > $@
src/x86/glue.S: src/disk.c src/misc.c src/display.c src/vm.c @AUDIO_GLUE_C@
./src/x86/genglue $^ > $@
@ -126,4 +131,4 @@ EXTRA_DIST = reconf.sh configure README.debugger PROBLEMS .apple2 \
src/font.txt \
src/x86/genglue
CLEANFILES = src/font.c src/meta/debug.c src/x86/glue.S
CLEANFILES = src/font.c src/rom.c src/meta/debug.c src/x86/glue.S

View File

@ -21,8 +21,8 @@
#define NIB_SIZE 232960
#define DSK_SIZE 143360
static unsigned char slot6_rom[256];
static int slot6_rom_loaded = 0;
extern uint8_t slot6_rom[256];
extern bool slot6_rom_loaded;
struct drive disk6;
@ -781,7 +781,7 @@ void disk_io_initialize(unsigned int slot)
}
fclose(f);
slot6_rom_loaded = 1;
slot6_rom_loaded = true;
}
memcpy(apple_ii_64k[0] + 0xC600, slot6_rom, 0x100);

115
src/genrom.c Normal file
View File

@ -0,0 +1,115 @@
/*
* Apple // emulator for *nix
*
* ROM converter
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
static const char *roms[] = {
NULL,
"apple_iie_rom",
"slot6_rom",
NULL
};
static const char *bools[] = {
NULL,
"iie_rom_loaded",
"slot6_rom_loaded",
NULL
};
static const size_t sizes[] = {
0,
32768,
256,
0
};
static void convert_rom(const uint8_t *buf, const size_t len) {
for (size_t i=0; i<len; i++) {
uint8_t ch = buf[i];
if ((i % 16) == 0) {
printf("\n");
}
printf(" 0x%02x", ch);
if (i < len-1) {
printf(",");
}
}
}
int main(int argc, const char *argv[]) {
printf("/* Apple II ROM data\n"
" *\n"
" * THIS FILE IS AUTOMATICALLY GENERATED --- DO NOT EDIT\n"
" */\n"
" \n"
"#include <stdbool.h>\n"
"#include <stdint.h>\n");
FILE *fp = NULL;
bool error = true;
uint8_t *buf = NULL;
size_t num = 0;
unsigned int idx = 1;
do {
printf("\n/* ROM : %s */\n", roms[idx]);
error = true;
do {
if (idx >= argc) {
fprintf(stderr, "rom file unspecified\n");
break;
}
fp = fopen(argv[idx], "r");
if (!fp) {
fprintf(stderr, "cannot open %s\n", argv[idx]);
break;
}
buf = malloc(sizes[idx]);
if (!buf) {
break;
}
num = fread(buf, 1, sizes[idx], fp);
if (num != sizes[idx]) {
fprintf(stderr, "rom file size %d mismatched with expected %d\n", num, sizes[idx]);
break;
}
fclose(fp);
printf("\nbool %s = true;\n", bools[idx]);
printf("\nuint8_t %s[%u] = {", roms[idx], sizes[idx]);
convert_rom(buf, sizes[idx]);
printf("\n};\n");
error = false;
} while(0);
if (error) {
printf("\nbool %s = false;\n", bools[idx]);
printf("\nuint8_t %s[%u] = { 0 };\n", roms[idx], sizes[idx]);
}
if (buf) {
free(buf);
buf = NULL;
}
} while(roms[++idx] != NULL);
return error;
}

View File

@ -20,7 +20,8 @@
internal apple2 variables
---------------------------------- */
static unsigned char apple_iie_rom[32768]; /* //e */
extern uint8_t apple_iie_rom[32768];
extern bool iie_rom_loaded;
bool do_logging = true; // also controlled by NDEBUG
FILE *error_log = NULL;
@ -453,7 +454,6 @@ void c_initialize_apple_ii_memory()
{
FILE *f;
int i;
static int iie_rom_loaded = 0;
for (i = 0; i < 0x10000; i++)
{