Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c3e7f0d
Merge: 47494b7 8e86ae2
Author: mesheets <[email protected]>
Date:   Fri Jul 26 22:30:15 2024 -0400

    Merge branch 'master' into cycle-count-typedef

commit 47494b7
Merge: 0f6a0a0 bc9ef83
Author: mesheets <[email protected]>
Date:   Fri Jul 26 22:06:20 2024 -0400

    Merge branch 'master' into cycle-count-typedef

commit 0f6a0a0
Author: mesheets <[email protected]>
Date:   Fri Feb 9 22:21:03 2024 -0500

    Refactor to introduce type cycle_count_t
  • Loading branch information
mesheets committed Jul 27, 2024
1 parent 8e86ae2 commit 8d1f8c4
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 99 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,13 @@ touches a number of different areas—each one of which needed to be
adjusted for the increased integer size—, so it is possible that if an area
was missed, the app might hang after the prior rollover period elapses
when that area’s functionality is invoked.
- Note: In the original codebase, `long` referred to a 32-bit integer
- **NOTE**: In the original codebase, `long` referred to a 32-bit integer
(c.f. NUM_REG_BYTES in debugger.c)

* Save/Load State – Save/Load state functionality has not yet been
updated to account for the increase in cycle counter size, so neither
saving nor loading will work at this time.
saving nor loading will work at this time. Multiple 32-bit ntohl()
and htonl() calls exist that would need to be addressed.

* Prior Saved States — Due to the change in cycle counter size, any prior
saved states will not be compatible with the updated program version.
Expand Down
8 changes: 4 additions & 4 deletions adsensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
static uint16 values[8], polled[4];
static uint8 tmp;
static uint8 adcsr, read_adcsr, adcr, adchannel;
static long long ad_start_cycle;
static cycle_count_t ad_start_cycle;

typedef struct {
long long ad_start_cycle;
cycle_count_t ad_start_cycle;
uint16 polled[4];
uint8 tmp;
uint8 adcsr, read_adcsr, adcr, adchannel;
Expand Down Expand Up @@ -99,8 +99,8 @@ static void ad_check_next_cycle() {
next_timer_cycle = cycles;
} else if ((adcsr & (ADCSR_ADIE|ADCSR_ADST)) == (ADCSR_ADIE|ADCSR_ADST)) {

long long next_conv_time = add_to_cycle('S', ad_start_cycle, (adcsr & ADCSR_CKS ? 134 : 266));
if ((next_conv_time - cycles) < (next_timer_cycle - cycles)) {
cycle_count_t next_conv_time = add_to_cycle('S', ad_start_cycle, (adcsr & ADCSR_CKS ? 134 : 266));
if (next_conv_time < next_timer_cycle) {
next_timer_cycle = next_conv_time;
}
}
Expand Down
2 changes: 1 addition & 1 deletion buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void btn_read_fd(int fd) {
irqpending |= btn_state & mask & iscr & 7;
btn_state ^= mask;
#ifdef VERBOSE_BUTTON
printf("%10lld: BTN %02x\n", cycles, btn_state);
printf("%" CYCLE_COUNT_F ": BTN %02x\n", cycles, btn_state);
#endif
btn_check_next_cycle();
}
Expand Down
36 changes: 18 additions & 18 deletions frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,33 @@ unsigned int frame_asmopcstat[256];

typedef struct callee_info {
uint32 calls;
long long cycles;
cycle_count_t cycles;
} callee_info;

typedef struct profile_info {
long long local_cycles;
long long irq_cycles;
long long total_cycles;
long long max_local_cycles;
long long max_total_cycles;
cycle_count_t local_cycles;
cycle_count_t irq_cycles;
cycle_count_t total_cycles;
cycle_count_t max_local_cycles;
cycle_count_t max_total_cycles;
uint32 calls;
uint8 isIRQ;
hash_type callees;
} profile_info;

typedef struct frame_info {
long long startcycle;
long long childcycles;
long long irqcycles;
long long threadcycles;
cycle_count_t startcycle;
cycle_count_t childcycles;
cycle_count_t irqcycles;
cycle_count_t threadcycles;
uint16 pc;
uint16 fp;
} frame_info;

typedef struct thread_info {
uint16 savefp;
uint16 minfp;
long long switchcycle;
cycle_count_t switchcycle;
int num_frames;
int size_frames;
struct frame_info frames[1];
Expand Down Expand Up @@ -142,7 +142,7 @@ void frame_switch(uint16 oldframe, uint16 newframe) {
#endif

#ifdef VERBOSE_FRAME
printf("Frame switch: %04x --> %04x cycles: %11lld\n",
printf("Frame switch: %04x --> %04x cycles: %" CYCLE_COUNT_F "\n",
oldframe, newframe, cycles);
#endif
if (current_thread) {
Expand Down Expand Up @@ -228,7 +228,7 @@ static void frame_insert_subframe(uint16 fp) {
static void frame_create_callee(profile_info *prof, uint16 pc) {
}

static void frame_add_callee(profile_info *prof, uint16 pc, long long cycles) {
static void frame_add_callee(profile_info *prof, uint16 pc, cycle_count_t cycles) {
callee_info * callee = hash_get(&prof->callees, pc);
if (!callee) {
callee = hash_create(&prof->callees, pc, sizeof(callee_info));
Expand Down Expand Up @@ -323,7 +323,7 @@ void frame_begin(uint16 fp, int in_irq) {
}

void frame_end(uint16 fp, int in_irq) {
long long local, total;
cycle_count_t local, total;
frame_info * frame;
frame_info * pframe;
profile_info *prof, *pprof;
Expand Down Expand Up @@ -485,19 +485,19 @@ static void frame_dump_callee(unsigned int key, void *param) {
}


fprintf(proffile, " %2s%30s: %6u calls %11lld cycles\n",
fprintf(proffile, " %2s%30s: %6u calls %" CYCLE_COUNT_F " cycles\n",
key & 1 ? "I:" : " ",
funcname, callee->calls, callee->cycles);
}

static void frame_close_thread(unsigned int key, void *param) {
thread_info *thread = param;
long long switchcycle, local, total;
cycle_count_t switchcycle, local, total;
frame_info *frame, *pframe;
profile_info *prof, *pprof;
int i;

switchcycle = thread == current_thread ? cycles : thread->switchcycle;
switchcycle = (thread == current_thread ? cycles : thread->switchcycle);
for (i = thread->num_frames; i >= 0; i--) {
frame = &thread->frames[i];

Expand Down Expand Up @@ -571,7 +571,7 @@ static void frame_dump_function(unsigned int key, void *param) {
}

if (prof->calls) {
fprintf(proffile, "%2s%30s: %11u %11lld %11lld %11lld %11lld %11lld %11lld %11lld\n",
fprintf(proffile, "%2s%30s: %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F " %" CYCLE_COUNT_F "\n",
prof->isIRQ ? "I:" : " ",
funcname, prof->calls, prof->local_cycles,
prof->total_cycles,
Expand Down
18 changes: 8 additions & 10 deletions h8300.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint8 reg[16];
uint16 pc;
uint8 ccr;

long long cycles, next_timer_cycle, next_nmi_cycle;
cycle_count_t cycles, next_timer_cycle, next_nmi_cycle;
int irq_disabled_one;
volatile int db_trap;
int db_singlestep;
Expand Down Expand Up @@ -83,7 +83,7 @@ void dump_state(void) {
printf(" R%d: %02x%02x (%3d:%3d == %5d)\n",
i, reg[i], reg[i+8], reg[i], reg[i+8], GET_REG16(i));
}
printf (" PC: %04x ccr: %c%c%c%c%c%c%c%c cycles: %10lld->%10lld\n",
printf (" PC: %04x ccr: %c%c%c%c%c%c%c%c cycles: %" CYCLE_COUNT_F "->%" CYCLE_COUNT_F "\n",
pc,
(ccr & 0x80 ? 'I':'.'),
(ccr & 0x40 ? '-':'.'),
Expand Down Expand Up @@ -132,22 +132,21 @@ static void debug_set_word(uint16 old_pc, uint16 addr, uint16 value) {
}
}
static void debug_cpu_asm(void) {
long long old_next_timer_cycle = next_timer_cycle;
long long old_next_nmi_cycle = next_nmi_cycle;
cycle_count_t old_next_timer_cycle = next_timer_cycle;
cycle_count_t old_next_nmi_cycle = next_nmi_cycle;

uint8 old_reg[16];
uint16 old_pc;
uint8 old_ccr;
long long old_cycles;
cycle_count_t old_cycles;
uint8 new_reg[16];
uint16 new_pc;
uint8 new_ccr;
long long new_cycles;
cycle_count_t new_cycles;
uint8 opcval;
unsigned int opc;

while ((long long) (cycles - (ccr & 0x80 ? old_next_nmi_cycle
: old_next_timer_cycle)) < 0) {
while (cycles < (ccr & 0x80 ? old_next_nmi_cycle : old_next_timer_cycle)) {
memcpy(old_reg, reg, 16);
old_pc = pc;
old_ccr = ccr;
Expand Down Expand Up @@ -288,8 +287,7 @@ void run_cpu(void) {
goto handletrap;
}
#endif
if ((cycles - (ccr & 0x80 ? next_nmi_cycle
: next_timer_cycle)) >= 0) {
if (cycles >= (ccr & 0x80 ? next_nmi_cycle : next_timer_cycle)) {
if (!db_singlestep) {
check_irq();

Expand Down
2 changes: 1 addition & 1 deletion h8300.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
extern uint8 reg[16];
extern uint16 pc;
extern uint8 ccr;
extern long long cycles, next_timer_cycle, next_nmi_cycle;
extern cycle_count_t cycles, next_timer_cycle, next_nmi_cycle;
extern int irq_disabled_one;
extern volatile int db_trap;
extern int db_singlestep;
Expand Down
15 changes: 8 additions & 7 deletions motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#define UPDATE_INTERVAL (100 * 16000)
#define SCALER 256

static long long next_output_cycles;
static long long motor_cycles;
static cycle_count_t next_output_cycles = 0;
static cycle_count_t motor_cycles = 0;

static int on[3];
static int last_on[3];
static cycle_count_t on[3];
static cycle_count_t last_on[3];
static int dir[3];
static int last_dir[3];

Expand All @@ -22,7 +22,7 @@ static char analog_active;
static char last_analog_active;

static void motor_update() {
int dcycles = cycles - motor_cycles;
cycle_count_t dcycles = cycles - motor_cycles;
if (motor_val & 0xc0) {
on[0] += dcycles;
dir[0] = (motor_val >> 6) & 3;
Expand All @@ -43,7 +43,7 @@ static void motor_update_time() {
char out[20];

motor_update(cycles - motor_cycles);
if ((cycles - next_output_cycles) >= 0) {
if (cycles >= next_output_cycles) {
int analog_changed;
next_output_cycles = add_to_cycle('M', next_output_cycles, UPDATE_INTERVAL);

Expand All @@ -68,8 +68,9 @@ static void motor_update_time() {
analog_active = cur_analog_active;
}

if ((next_timer_cycle - next_output_cycles) > 0)
if (next_timer_cycle > next_output_cycles) {
next_timer_cycle = next_output_cycles;
}
}

void set_analog_active(unsigned char val) {
Expand Down
Loading

0 comments on commit 8d1f8c4

Please sign in to comment.