mirror of
https://github.com/mist64/perfect6502.git
synced 2024-06-08 12:29:28 +00:00
Fix warnings/errors with newer gcc/glibc and vc++
Also fixes a memory leak in measure.c
This commit is contained in:
parent
268d16647c
commit
bb3616502b
|
@ -1,9 +1,13 @@
|
|||
#include <stdio.h>
|
||||
#ifndef _WIN32
|
||||
#include <sys/stat.h>
|
||||
|
||||
#else
|
||||
#include <io.h>
|
||||
#endif
|
||||
#include "../perfect6502.h"
|
||||
|
||||
state_t *state;
|
||||
|
||||
/************************************************************
|
||||
*
|
||||
* Interface to OS Library Code / Monitor
|
||||
|
@ -15,24 +19,31 @@ unsigned char A, X, Y, S, P;
|
|||
unsigned short PC;
|
||||
int N, Z, C;
|
||||
|
||||
void
|
||||
int
|
||||
init_monitor()
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen("apple1basic.bin", "r");
|
||||
fread(memory + 0xE000, 1, 4096, f);
|
||||
f = fopen("apple1basic/apple1basic.bin", "rb");
|
||||
if (f == NULL) {
|
||||
perror("Error opening ROM image");
|
||||
return 1;
|
||||
}
|
||||
if (fread(memory + 0xE000, 1, 4096, f) != 4096) {
|
||||
perror("Error reading ROM image");
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
memory[0xfffc] = 0x00;
|
||||
memory[0xfffd] = 0xE0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
charout(char ch) {
|
||||
unsigned char S = readSP();
|
||||
unsigned short a = 1 + memory[0x0100+S+1] | memory[0x0100+((S+2) & 0xFF)] << 8;
|
||||
unsigned char S = readSP(state);
|
||||
unsigned short a = (1 + memory[0x0100+S+1]) | memory[0x0100+((S+2) & 0xFF)] << 8;
|
||||
|
||||
/*
|
||||
* Apple I BASIC prints every character received
|
||||
|
@ -57,7 +68,7 @@ charout(char ch) {
|
|||
/* INPUT */
|
||||
if (a==0xe182) {
|
||||
#if _WIN32
|
||||
if (!isatty(0))
|
||||
if (!_isatty(0))
|
||||
return;
|
||||
#else
|
||||
struct stat st;
|
||||
|
@ -66,7 +77,6 @@ charout(char ch) {
|
|||
return;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
putc(ch, stdout);
|
||||
fflush(stdout);
|
||||
|
@ -75,30 +85,30 @@ charout(char ch) {
|
|||
void
|
||||
handle_monitor()
|
||||
{
|
||||
if (readRW()) {
|
||||
unsigned short a = readAddressBus();
|
||||
if (readRW(state)) {
|
||||
unsigned short a = readAddressBus(state);
|
||||
if ((a & 0xFF1F) == 0xD010) {
|
||||
unsigned char c = getchar();
|
||||
if (c == 10)
|
||||
c = 13;
|
||||
c |= 0x80;
|
||||
writeDataBus(c);
|
||||
writeDataBus(state, c);
|
||||
}
|
||||
if ((a & 0xFF1F) == 0xD011) {
|
||||
if (readPC() == 0xE006)
|
||||
if (readPC(state) == 0xE006)
|
||||
/* if the code is reading a character, we have one ready */
|
||||
writeDataBus(0x80);
|
||||
writeDataBus(state, 0x80);
|
||||
else
|
||||
/* if the code checks for a STOP condition, nothing is pressed */
|
||||
writeDataBus(0);
|
||||
writeDataBus(state, 0);
|
||||
}
|
||||
if ((a & 0xFF1F) == 0xD012) {
|
||||
/* 0x80 would mean we're not yet ready to receive a character */
|
||||
writeDataBus(0);
|
||||
writeDataBus(state, 0);
|
||||
}
|
||||
} else {
|
||||
unsigned short a = readAddressBus();
|
||||
unsigned char d = readDataBus();
|
||||
unsigned short a = readAddressBus(state);
|
||||
unsigned char d = readDataBus(state);
|
||||
if ((a & 0xFF1F) == 0xD012) {
|
||||
unsigned char temp8 = d & 0x7F;
|
||||
if (temp8 == 13)
|
||||
|
@ -109,23 +119,25 @@ handle_monitor()
|
|||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int clk = 0;
|
||||
|
||||
initAndResetChip();
|
||||
state = initAndResetChip();
|
||||
|
||||
/* set up memory for user program */
|
||||
init_monitor();
|
||||
if (init_monitor()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* emulate the 6502! */
|
||||
for (;;) {
|
||||
step();
|
||||
step(state);
|
||||
clk = !clk;
|
||||
if (!clk)
|
||||
handle_monitor();
|
||||
|
||||
chipStatus();
|
||||
chipStatus(state);
|
||||
//if (!(cycle % 1000)) printf("%d\n", cycle);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ main()
|
|||
void *state = initAndResetChip();
|
||||
|
||||
/* set up memory for user program */
|
||||
init_monitor();
|
||||
if (init_monitor()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* emulate the 6502! */
|
||||
for (;;) {
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#undef ERROR_FILE_NOT_FOUND /* avoid conflict with CBM value below */
|
||||
|
@ -243,6 +244,7 @@ plugin_gone() {
|
|||
a = get_word();
|
||||
check_comma();
|
||||
b = get_byte();
|
||||
(void)b;
|
||||
if (a==6502) {
|
||||
printf("MICROSOFT!");
|
||||
continue;
|
||||
|
@ -262,7 +264,10 @@ plugin_gone() {
|
|||
char s[256];
|
||||
|
||||
get_string(s);
|
||||
system(s);
|
||||
errno = 0;
|
||||
if (system(s) == -1 && errno != 0) {
|
||||
perror("System call failed");
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -555,7 +555,7 @@ LOAD() {
|
|||
struct stat st;
|
||||
unsigned short start;
|
||||
unsigned short end;
|
||||
unsigned char savedbyte;
|
||||
// unsigned char savedbyte;
|
||||
|
||||
if (A) {
|
||||
printf("UNIMPL: VERIFY\n");
|
||||
|
@ -648,7 +648,7 @@ for (i=0; i<255; i++) {
|
|||
goto load_noerr;
|
||||
} /* end if( RAM[kernal_filename]=='$' ) */
|
||||
|
||||
savedbyte = RAM[kernal_filename+kernal_filename_len]; /* TODO possible overflow */
|
||||
// savedbyte = RAM[kernal_filename+kernal_filename_len]; /* TODO possible overflow */
|
||||
RAM[kernal_filename+kernal_filename_len] = 0;
|
||||
|
||||
/* on directory filename chdir on it */
|
||||
|
@ -698,7 +698,7 @@ missing_file_name:
|
|||
static void
|
||||
SAVE() {
|
||||
FILE *f;
|
||||
unsigned char savedbyte;
|
||||
// unsigned char savedbyte;
|
||||
unsigned short start;
|
||||
unsigned short end;
|
||||
|
||||
|
@ -714,7 +714,7 @@ SAVE() {
|
|||
A = KERN_ERR_MISSING_FILE_NAME;
|
||||
return;
|
||||
}
|
||||
savedbyte = RAM[kernal_filename+kernal_filename_len]; /* TODO possible overflow */
|
||||
// savedbyte = RAM[kernal_filename+kernal_filename_len]; /* TODO possible overflow */
|
||||
RAM[kernal_filename+kernal_filename_len] = 0;
|
||||
f = fopen((char*)&RAM[kernal_filename], "wb"); /* overwrite - these are not the COMMODORE DOS semantics! */
|
||||
if (!f) {
|
||||
|
|
|
@ -16,13 +16,21 @@ unsigned char A, X, Y, S, P;
|
|||
unsigned short PC;
|
||||
int N, Z, C;
|
||||
|
||||
void
|
||||
int
|
||||
init_monitor()
|
||||
{
|
||||
FILE *f;
|
||||
f = fopen("cbmbasic/cbmbasic.bin", "r");
|
||||
fread(memory + 0xA000, 1, 17591, f);
|
||||
f = fopen("cbmbasic/cbmbasic.bin", "rb");
|
||||
if (f == NULL) {
|
||||
perror("Error opening cbmbasic/cbmbasic.bin");
|
||||
return 1;
|
||||
}
|
||||
size_t readlen = fread(memory + 0xA000, 1, 17591, f);
|
||||
fclose(f);
|
||||
if (readlen != 17591) {
|
||||
perror("Error reading cbmbasic/cbmbasic.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* fill the KERNAL jumptable with JMP $F800;
|
||||
|
@ -47,6 +55,7 @@ init_monitor()
|
|||
|
||||
memory[0xfffc] = 0x00;
|
||||
memory[0xfffd] = 0xF0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1 +1 @@
|
|||
void init_monitor();
|
||||
int init_monitor();
|
||||
|
|
12
measure.c
12
measure.c
|
@ -1,5 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "perfect6502.h"
|
||||
|
||||
|
@ -74,7 +74,7 @@ uint16_t initial_s, initial_p, initial_a, initial_x, initial_y;
|
|||
void
|
||||
setup_memory(uint8_t opcode)
|
||||
{
|
||||
bzero(memory, 65536);
|
||||
memset(memory, 0, 65536);
|
||||
|
||||
memory[0xFFFC] = SETUP_ADDR & 0xFF;
|
||||
memory[0xFFFD] = SETUP_ADDR >> 8;
|
||||
|
@ -116,6 +116,9 @@ void *state;
|
|||
void
|
||||
resetChip_test()
|
||||
{
|
||||
if (state != NULL) {
|
||||
destroyChip(state);
|
||||
}
|
||||
state = initAndResetChip();
|
||||
for (int i = 0; i < 62; i++)
|
||||
step(state);
|
||||
|
@ -222,11 +225,12 @@ main()
|
|||
data[opcode].izy = YES;
|
||||
else
|
||||
is_data_access = NO;
|
||||
if (is_data_access)
|
||||
if (is_data_access) {
|
||||
if (IS_READ_CYCLE)
|
||||
data[opcode].reads = YES;
|
||||
if (IS_WRITE_CYCLE)
|
||||
data[opcode].writes = YES;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -270,7 +274,7 @@ main()
|
|||
BOOL different = NO;
|
||||
int reads, writes;
|
||||
uint16_t read[100], write[100], write_data[100];
|
||||
uint8_t end_a, end_x, end_y, end_s, end_p;
|
||||
uint8_t end_a, end_x, end_y, end_s = 0, end_p = 0;
|
||||
for (int j = 0; j < sizeof(magics)/sizeof(*magics); j++) {
|
||||
setup_memory(opcode);
|
||||
if (data[opcode].length == 2) {
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "types.h"
|
||||
|
||||
/* the smallest types to fit the numbers */
|
||||
|
@ -387,6 +388,8 @@ getGroupValue(state_t *state)
|
|||
case contains_nothing:
|
||||
return NO;
|
||||
}
|
||||
assert(0);
|
||||
return NO;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
Loading…
Reference in New Issue
Block a user