44 ____ \/__/ /\_\ __ \\ \/\ \ ________________________________________________
55| /\_____\\_____\\_____\ |
66| Zilog \/_____//_____//_____/ CPU Emulator - Step Testing Tool |
7- | Copyright (C) 2024 Manuel Sainz de Baranda y Goñi. |
7+ | Copyright (C) 2024-2025 Manuel Sainz de Baranda y Goñi. |
88| |
99| This program is free software: you can redistribute it and/or modify it |
1010| under the terms of the GNU General Public License as published by the Free |
3232#include <stdlib.h>
3333#include <string.h>
3434
35- #define INPUT_BLOCK_SIZE (750 * 1024)
35+ #define INPUT_BLOCK_SIZE (512 * 1024)
3636
3737
3838/* MARK: - Types */
@@ -95,21 +95,21 @@ static Z80 cpu;
9595static Z80InsnClock insn_clock ;
9696static zuint8 memory [65536 ];
9797
98- static Cycle * cycles = Z_NULL ;
98+ static Cycle * cycles ;
9999static int cycles_size ;
100100static int cycles_index ;
101101
102- static Port * ports = Z_NULL ;
102+ static Port * ports ;
103103static int ports_size ;
104104static int ports_index ;
105105
106- static cJSON * expected_ports = Z_NULL ;
106+ static cJSON * expected_ports ;
107107static int expected_port_count ;
108108
109109static zboolean file_failed , test_failed , array_failed ;
110110static char const * field_separator = "" ;
111111
112- static zboolean cpu_break = Z_FALSE ;
112+ static zboolean cpu_break ;
113113
114114
115115static void add_cycle (zuint16 address , zsint16 value , char const * pins )
@@ -215,7 +215,6 @@ static zuint8 cpu_read(void *context, zuint16 address)
215215
216216static void cpu_write (void * context , zuint16 address , zuint8 value )
217217 {
218- Cycle * cycle = cycles + cycles_index ;
219218 zuint8 extra = z80_insn_clock_extra_m (& insn_clock );
220219
221220 Z_UNUSED (context )
@@ -230,7 +229,6 @@ static void cpu_write(void *context, zuint16 address, zuint8 value)
230229
231230static zuint8 cpu_in (void * context , zuint16 port )
232231 {
233- Cycle * cycle = cycles + cycles_index ;
234232 zuint8 value = (zuint8 )cJSON_GetNumberValue (cJSON_GetArrayItem (
235233 cJSON_GetArrayItem (expected_ports , ports_index ), 1 ));
236234
@@ -247,7 +245,6 @@ static zuint8 cpu_in(void *context, zuint16 port)
247245
248246static void cpu_out (void * context , zuint16 port , zuint8 value )
249247 {
250- Cycle * cycle = cycles + cycles_index ;
251248 zuint8 extra = z80_insn_clock_extra_out (& insn_clock );
252249
253250 Z_UNUSED (context )
@@ -358,7 +355,7 @@ static zboolean validate_tests(cJSON *tests)
358355
359356 cJSON_ArrayForEach (test , tests )
360357 {
361- cJSON * item , * array , * subarray ;
358+ cJSON * item , * array ;
362359 int size ;
363360
364361 if ( !cJSON_IsObject (test ) ||
@@ -589,7 +586,7 @@ int main(int argc, char **argv)
589586 if (string_is_option (argv [i ], "-V" , "--version" ))
590587 {
591588 puts ( "step-test-Z80 v" Z80_LIBRARY_VERSION_STRING "\n"
592- "Copyright (C) 2024 Manuel Sainz de Baranda y Goñi.\n"
589+ "Copyright (C) 2024-2025 Manuel Sainz de Baranda y Goñi.\n"
593590 "Released under the terms of the GNU General Public License v3." );
594591
595592 return 0 ;
@@ -673,7 +670,7 @@ int main(int argc, char **argv)
673670 goto bad_syntax ;
674671 }
675672
676- /* Initialize CPU */
673+ /* Initialize the CPU emulator and the instruction clock. */
677674
678675 cpu .context = Z_NULL ;
679676 cpu .fetch_opcode = cpu_fetch_opcode ;
@@ -701,7 +698,7 @@ int main(int argc, char **argv)
701698
702699 for (; !read_from_stdin && i != argc ; i ++ )
703700 {
704- char const * error = Z_NULL , * parse_end ;
701+ char const * error = Z_NULL , * parse_end = Z_NULL ;
705702 char * json = Z_NULL ;
706703 zusize json_size ;
707704 cJSON * tests = Z_NULL ;
@@ -780,7 +777,7 @@ int main(int argc, char **argv)
780777 else if ((tests = cJSON_ParseWithLengthOpts (json , json_size , & parse_end , Z_FALSE )) == Z_NULL )
781778 {
782779 free (json );
783- if (errno == ENOMEM ) goto cannot_allocate_memory ;
780+ if (parse_end == Z_NULL ) goto cannot_allocate_memory ;
784781 goto invalid_format ;
785782 }
786783
0 commit comments