comparison transz80.c @ 245:ea3899e3e7ec

Implement cartridge rom loading in transz80
author Mike Pavone <pavone@retrodev.com>
date Sun, 28 Apr 2013 21:00:16 -0700
parents df8a36bf5e1d
children 5f1b68cecfc7
comparison
equal deleted inserted replaced
244:df8a36bf5e1d 245:ea3899e3e7ec
3 #include "mem.h" 3 #include "mem.h"
4 #include <stdio.h> 4 #include <stdio.h>
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 uint8_t z80_ram[0x2000]; 7 uint8_t z80_ram[0x2000];
8 uint16_t cart[0x200000];
8 9
9 int main(int argc, char ** argv) 10 int main(int argc, char ** argv)
10 { 11 {
11 long filesize; 12 long filesize;
12 uint8_t *filebuf; 13 uint8_t *filebuf;
13 x86_z80_options opts; 14 x86_z80_options opts;
14 z80_context context; 15 z80_context context;
16 if (argc < 2) {
17 fputs("usage: transz80 zrom [cartrom]\n", stderr);
18 exit(1);
19 }
15 FILE * f = fopen(argv[1], "rb"); 20 FILE * f = fopen(argv[1], "rb");
21 if (!f) {
22 fprintf(stderr, "unable to open file %s\n", argv[2]);
23 exit(1);
24 }
16 fseek(f, 0, SEEK_END); 25 fseek(f, 0, SEEK_END);
17 filesize = ftell(f); 26 filesize = ftell(f);
18 fseek(f, 0, SEEK_SET); 27 fseek(f, 0, SEEK_SET);
19 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f); 28 fread(z80_ram, 1, filesize < sizeof(z80_ram) ? filesize : sizeof(z80_ram), f);
20 fclose(f); 29 fclose(f);
30 if (argc > 2) {
31 f = fopen(argv[2], "rb");
32 if (!f) {
33 fprintf(stderr, "unable to open file %s\n", argv[2]);
34 exit(1);
35 }
36 fseek(f, 0, SEEK_END);
37 filesize = ftell(f);
38 fseek(f, 0, SEEK_SET);
39 fread(cart, 1, filesize < sizeof(cart) ? filesize : sizeof(cart), f);
40 fclose(f);
41 }
21 init_x86_z80_opts(&opts); 42 init_x86_z80_opts(&opts);
22 init_z80_context(&context, &opts); 43 init_z80_context(&context, &opts);
23 //cartridge ROM 44 //Z80 RAM
24 context.mem_pointers[0] = z80_ram; 45 context.mem_pointers[0] = z80_ram;
25 context.sync_cycle = context.target_cycle = 0x7FFFFFFF; 46 context.sync_cycle = context.target_cycle = 0x7FFFFFFF;
26 //work RAM 47 //cartridge/bank
27 context.mem_pointers[1] = context.mem_pointers[2] = NULL; 48 context.mem_pointers[1] = context.mem_pointers[2] = cart;
28 z80_reset(&context); 49 z80_reset(&context);
29 for(;;) 50 for(;;)
30 { 51 {
31 z80_run(&context); 52 z80_run(&context);
32 } 53 }