annotate blastcpm.c @ 989:d70000fdff0b

Implemented IR and undefined bits of info word for address error exception frames
author Michael Pavone <pavone@retrodev.com>
date Wed, 27 Apr 2016 21:39:17 -0700
parents cf6149b7c6e5
children fe8c79f82c22
rev   line source
pavone@820 1 #include <stdio.h>
pavone@820 2 #include <stdlib.h>
pavone@820 3 #include <stddef.h>
pavone@820 4 #include <string.h>
pavone@820 5 #include <sys/select.h>
pavone@820 6
pavone@820 7 #include "z80_to_x86.h"
pavone@820 8 #include "util.h"
pavone@820 9
pavone@820 10 uint8_t ram[64 * 1024];
pavone@820 11
pavone@820 12 #define START_OFF 0x100
pavone@820 13 #define OS_START 0xE400
pavone@820 14 #define OS_RESET 0xE403
pavone@820 15 int headless = 1;
pavone@820 16
pavone@820 17 void z80_next_int_pulse(z80_context * context)
pavone@820 18 {
pavone@820 19 context->int_pulse_start = context->int_pulse_end = CYCLE_NEVER;
pavone@820 20 }
pavone@820 21
pavone@820 22 void render_errorbox(char *title, char *message)
pavone@820 23 {
pavone@820 24 }
pavone@820 25
pavone@820 26 void render_infobox(char *title, char *message)
pavone@820 27 {
pavone@820 28 }
pavone@820 29
pavone@820 30 void *console_write(uint32_t address, void *context, uint8_t value)
pavone@820 31 {
pavone@820 32 putchar(value);
pavone@820 33 return context;
pavone@820 34 }
pavone@820 35
pavone@820 36 uint8_t console_read(uint32_t address, void *context)
pavone@820 37 {
pavone@820 38 return getchar();
pavone@820 39 }
pavone@820 40
pavone@820 41 void *console_flush_write(uint32_t address, void *context, uint8_t value)
pavone@820 42 {
pavone@820 43 fflush(stdout);
pavone@820 44 return context;
pavone@820 45 }
pavone@820 46
pavone@820 47 uint8_t console_status_read(uint32_t address, void *context)
pavone@820 48 {
pavone@820 49 fd_set read_fds;
pavone@820 50 FD_ZERO(&read_fds);
pavone@820 51 struct timeval timeout;
pavone@820 52 timeout.tv_sec = 0;
pavone@820 53 timeout.tv_usec = 0;
pavone@820 54 FD_SET(fileno(stdin), &read_fds);
pavone@820 55 return select(fileno(stdin)+1, &read_fds, NULL, NULL, &timeout) > 0;
pavone@820 56 }
pavone@820 57
pavone@820 58 void *exit_write(uint32_t address, void *context, uint8_t value)
pavone@820 59 {
pavone@820 60 exit(0);
pavone@820 61 return context;
pavone@820 62 }
pavone@820 63
pavone@820 64 const memmap_chunk z80_map[] = {
pavone@820 65 { 0x0000, 0x10000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, NULL, NULL, NULL, NULL},
pavone@820 66 };
pavone@820 67
pavone@820 68 const memmap_chunk io_map[] = {
pavone@820 69 { 0x0, 0x1, 0xFFFF, 0, 0, NULL, NULL, NULL, console_read, console_write},
pavone@820 70 { 0x1, 0x2, 0xFFFF, 0, 0, NULL, NULL, NULL, console_status_read, console_flush_write},
pavone@820 71 { 0x2, 0x3, 0xFFFF, 0, 0, NULL, NULL, NULL, NULL, exit_write},
pavone@820 72 };
pavone@820 73
pavone@820 74 int main(int argc, char **argv)
pavone@820 75 {
pavone@820 76 FILE *f = fopen("fake_cpm.bin", "rb");
pavone@820 77 long fsize = file_size(f);
pavone@820 78 if (fsize > sizeof(ram) - OS_START) {
pavone@820 79 fsize = sizeof(ram) - OS_START;
pavone@820 80 }
pavone@820 81 if (fread(ram + OS_START, 1, fsize, f) != fsize) {
pavone@820 82 fprintf(stderr, "Error reading from fake_cpm.bin\n");
pavone@820 83 exit(1);
pavone@820 84 }
pavone@820 85 f = fopen(argv[1], "rb");
pavone@820 86 fsize = file_size(f);
pavone@820 87 if (fsize > OS_START - START_OFF) {
pavone@820 88 fsize = OS_START - START_OFF;
pavone@820 89 }
pavone@820 90 if (fread(ram + START_OFF, 1, fsize, f) != fsize) {
pavone@820 91 fprintf(stderr, "Error reading from file %s\n", argv[1]);
pavone@820 92 exit(1);
pavone@820 93 }
pavone@820 94 fclose(f);
pavone@820 95 ram[0] = 0xC3;
pavone@820 96 ram[1] = OS_RESET & 0xFF;
pavone@820 97 ram[2] = OS_RESET >> 8;
pavone@820 98 ram[5] = 0xC3;
pavone@820 99 ram[6] = OS_START & 0xFF;
pavone@820 100 ram[7] = OS_START >> 8;
pavone@820 101
pavone@820 102 z80_options opts;
pavone@820 103 z80_context context;
pavone@820 104 init_z80_opts(&opts, z80_map, 1, io_map, 3, 1);
pavone@820 105 init_z80_context(&context, &opts);
pavone@820 106 for(;;)
pavone@820 107 {
pavone@820 108 z80_run(&context, 1000000);
pavone@820 109 context.current_cycle = 0;
pavone@820 110 }
pavone@820 111 return 0;
pavone@820 112 }