Skip to content

Commit

Permalink
Small fixes, readNodes uses count, some ANSI console stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
phf committed Apr 23, 2015
1 parent 4142ac1 commit a66e209
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OBJS=perfect6502.o netlist_sim.o
OBJS+=cbmbasic.o runtime.o runtime_init.o plugin.o console.o emu.o
#OBJS+=measure.o
CFLAGS=-Werror -Wall -O3
CFLAGS=-std=c11 -Werror -Wall -Wextra -Wpedantic -O2 -D_DEFAULT_SOURCE
CC=clang

all: cbmbasic
Expand Down
2 changes: 1 addition & 1 deletion apple1basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sys/stat.h>

#include "perfect6502.h"

/************************************************************
*
* Interface to OS Library Code / Monitor
Expand Down
4 changes: 2 additions & 2 deletions compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ perfect_measure_instruction()
* the test instruction MIGHT be done
*/
state = STATE_FIRST_FETCH;
}
}

if (state == STATE_DURING_INSTRUCTION) {
instr_rw[c] = r_w;
Expand All @@ -129,7 +129,7 @@ perfect_measure_instruction()

if (ab == TRIGGER1) {
state = STATE_DURING_INSTRUCTION; /* we're done writing the trigger value; now comes the instruction! */
}
}
if (ab == TRIGGER3) {
break; /* we're done dumping the CPU state */
}
Expand Down
70 changes: 68 additions & 2 deletions console.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void clear_screen() {

if( (get_console_info(&hstd_out, &dummy1, &size)) == -1 )
return;

FillConsoleOutputCharacter(hstd_out, ' ', size, upper_left, &dummy2);
SetConsoleCursorPosition(hstd_out, upper_left);
#else /* ANSI */
Expand Down Expand Up @@ -222,6 +222,72 @@ void set_color(int c)
SetConsoleTextAttribute(h, info.wAttributes);

#else /* ANSI */
/* TODO */
/* this is far from perfect [phf] */
switch (c)
{
case COLOR_WHITE:
fputs("\033[37;1m", stdout); /* same as GREY3 */
break;

case COLOR_RED:
fputs("\033[31m", stdout);
break;

case COLOR_GREEN:
fputs("\033[32m", stdout);
break;

case COLOR_BLUE:
fputs("\033[34m", stdout);
break;

case COLOR_BLACK:
fputs("\033[30m", stdout);
break;

case COLOR_PURPLE:
fputs("\033[35m", stdout);
break;

case COLOR_YELLOW:
fputs("\033[33;1m", stdout);
break;

case COLOR_CYAN:
fputs("\033[36m", stdout);
break;

case COLOR_ORANGE:
fputs("\033[33m", stdout); /* ORANGE on Windows only? */
break;

case COLOR_BROWN:
fputs("\033[33m", stdout); /* closest thing on Linux? */
break;

case COLOR_LTRED:
fputs("\033[31;1m", stdout);
break;

case COLOR_GREY1:
fputs("\033[30;1m", stdout);
break;

case COLOR_GREY2:
fputs("\033[37m", stdout);
break;

case COLOR_LTGREEN:
fputs("\033[32;1m", stdout);
break;

case COLOR_LTBLUE:
fputs("\033[34;1m", stdout);
break;

case COLOR_GREY3:
fputs("\033[37;1m", stdout); /* same as WHITE */
break;
}
#endif /* _WIN32 */
}
9 changes: 6 additions & 3 deletions netlist_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ typedef struct {
static inline void
bitmap_clear(bitmap_t *bitmap, count_t count)
{
bzero(bitmap, WORDS_FOR_BITS(count)*sizeof(bitmap_t));
memset(bitmap, 0, WORDS_FOR_BITS(count)*sizeof(bitmap_t));
}

static inline void
Expand Down Expand Up @@ -649,6 +649,9 @@ readNodes(state_t *state, int count, nodenum_t *nodelist)
void
writeNodes(state_t *state, int count, nodenum_t *nodelist, int v)
{
for (int i = 0; i < 8; i++, v >>= 1)
setNode(state, nodelist[i], v & 1);
/* was hardedcoded to 8 instead of count but only called with
* a parameter of 8 by writeDataBus anyway? [phf] */
for (int i = 0; i < count; i++, v >>= 1) {
setNode(state, nodelist[i], v & 1);
}
}
2 changes: 1 addition & 1 deletion perfect6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ extern unsigned char readIR(state_t *state);

extern unsigned char memory[65536];
extern unsigned int cycle;
extern unsigned int transistors;
extern unsigned int transistors;
2 changes: 1 addition & 1 deletion readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ DIR *opendir(const char *name)
DIR *ret = NULL;
char name2[MAX_PATH];
WIN32_FIND_DATAA findData;

if (strlen(name) >= MAX_PATH - 2 - 1)
{
errno = ENAMETOOLONG;
Expand Down
20 changes: 10 additions & 10 deletions runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ plugin_on() {
replace_vector(VEC_QPLOP, MAGIC_QPLOP, &orig_qplop);
replace_vector(VEC_GONE, MAGIC_GONE, &orig_gone);
replace_vector(VEC_EVAL, MAGIC_EVAL, &orig_eval);

plugin = 1;
}

Expand Down Expand Up @@ -445,7 +445,7 @@ printf("CHROUT: %d @ %x,%x,%x,%x\n", A, a, b, c, d);
C = 0;
return;
}

#if 0
printf("CHROUT: %c (%d)\n", A, A);
#else
Expand Down Expand Up @@ -593,7 +593,7 @@ LOAD() {

RAM[old_memp] = (memp) & 0xFF;
RAM[old_memp+1] = (memp) >> 8;

if ( !(dirp = opendir(".")) )
goto device_not_present;
while ((dp = readdir(dirp))) {
Expand Down Expand Up @@ -748,7 +748,7 @@ SETTIM() {
time_t now = time(0);
struct tm bd;
struct timeval tv;

localtime_r(&now, &bd);

bd.tm_sec = seconds%60;
Expand All @@ -757,7 +757,7 @@ SETTIM() {

tv.tv_sec = mktime(&bd);
tv.tv_usec = (jiffies % 60) * (1000000/60);

settimeofday(&tv, 0);
#endif
}
Expand All @@ -775,16 +775,16 @@ RDTIM() {
time_t now = time(0);
struct tm bd;
struct timeval tv;

localtime_r(&now, &bd);
gettimeofday(&tv, 0);

jiffies = ((bd.tm_hour*60 + bd.tm_min)*60 + bd.tm_sec)*60 + tv.tv_usec / (1000000/60);
#endif
Y = (unsigned char)(jiffies/65536);
X = (unsigned char)((jiffies%65536)/256);
A = (unsigned char)(jiffies%256);

}

/* STOP */
Expand Down Expand Up @@ -827,7 +827,7 @@ GETIN() {
/* CLALL */
static void
CLALL() {
int i;
size_t i;
for (i = 0; i < sizeof(kernal_files)/sizeof(kernal_files[0]); ++i) {
if (kernal_files[i]) {
fclose(kernal_files[i]);
Expand Down Expand Up @@ -911,7 +911,7 @@ kernal_dispatch() {
case MAGIC_QPLOP: new_pc = plugin_qplop(); PUSH_WORD(new_pc? new_pc-1:orig_qplop-1); break;
case MAGIC_GONE: new_pc = plugin_gone(); PUSH_WORD(new_pc? new_pc-1:orig_gone-1); break;
case MAGIC_EVAL: new_pc = plugin_eval(); PUSH_WORD(new_pc? new_pc-1:orig_eval-1); break;

case MAGIC_CONTINUATION: /*printf("--CONTINUATION--\n");*/ return 0;

#if 0
Expand Down
4 changes: 2 additions & 2 deletions runtime_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "perfect6502.h"
/* XXX hook up memory[] with RAM[] in runtime.c */

/************************************************************
*
* Interface to OS Library Code / Monitor
Expand Down Expand Up @@ -44,7 +44,7 @@ init_monitor()
memory[0xf000] = 0x20;
memory[0xf001] = 0x94;
memory[0xf002] = 0xE3;

memory[0xfffc] = 0x00;
memory[0xfffd] = 0xF0;
}
Expand Down
2 changes: 1 addition & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ typedef struct {
#define YES 1
#define NO 0

#endif
#endif

0 comments on commit a66e209

Please sign in to comment.