summaryrefslogtreecommitdiff
path: root/transz80.c
diff options
context:
space:
mode:
authorMike Pavone <pavone@retrodev.com>2013-04-28 21:00:16 -0700
committerMike Pavone <pavone@retrodev.com>2013-04-28 21:00:16 -0700
commit9489f6e28326a2420b691ffe3266d63a2626f131 (patch)
treed68bc9f25dcea36d8c4c89c258519ead9c56d770 /transz80.c
parent9c4a07e1e04310480313e9b963d5ee49421a319b (diff)
Implement cartridge rom loading in transz80
Diffstat (limited to 'transz80.c')
-rw-r--r--transz80.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/transz80.c b/transz80.c
index 680a520..897adee 100644
--- a/transz80.c
+++ b/transz80.c
@@ -5,6 +5,7 @@
#include <stdlib.h>
uint8_t z80_ram[0x2000];
+uint16_t cart[0x200000];
int main(int argc, char ** argv)
{
@@ -12,19 +13,39 @@ int main(int argc, char ** argv)
uint8_t *filebuf;
x86_z80_options opts;
z80_context context;
+ if (argc < 2) {
+ fputs("usage: transz80 zrom [cartrom]\n", stderr);
+ exit(1);
+ }
FILE * f = fopen(argv[1], "rb");
+ if (!f) {
+ fprintf(stderr, "unable to open file %s\n", argv[2]);
+ exit(1);
+ }
fseek(f, 0, SEEK_END);
filesize = ftell(f);
fseek(f, 0, SEEK_SET);
fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f);
fclose(f);
+ if (argc > 2) {
+ f = fopen(argv[2], "rb");
+ if (!f) {
+ fprintf(stderr, "unable to open file %s\n", argv[2]);
+ exit(1);
+ }
+ fseek(f, 0, SEEK_END);
+ filesize = ftell(f);
+ fseek(f, 0, SEEK_SET);
+ fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f);
+ fclose(f);
+ }
init_x86_z80_opts(&opts);
init_z80_context(&context, &opts);
- //cartridge ROM
+ //Z80 RAM
context.mem_pointers[0] = z80_ram;
context.sync_cycle = context.target_cycle = 0x7FFFFFFF;
- //work RAM
- context.mem_pointers[1] = context.mem_pointers[2] = NULL;
+ //cartridge/bank
+ context.mem_pointers[1] = context.mem_pointers[2] = cart;
z80_reset(&context);
for(;;)
{