Skip to content

Commit 5dad52f

Browse files
committed
Update source code to fix some new clang-tidy warnings
1 parent ca7ace2 commit 5dad52f

35 files changed

Lines changed: 312 additions & 399 deletions

src/bios.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include "bios.h"
22

33
#include "conf.h"
4+
#include "module.h"
5+
#include "type.h"
46
#include "units.h"
57

8+
#include <stdint.h>
69
#include <stdio.h>
710
#include <stdlib.h>
811
#include <string.h>
@@ -12,9 +15,10 @@
1215
#define ROM_BIOS_PATH "rom/V1.01_ROM.bin"
1316
#define ROM_BIOS_SIZE (ceda_size_t)(4 * KiB)
1417

15-
static zuint8 bios[ROM_BIOS_SIZE] = {0};
18+
static uint8_t bios[ROM_BIOS_SIZE] = {0};
1619

1720
static bool rom_bios_start(void) {
21+
bool ret = false;
1822
const char *rom_path = ROM_BIOS_PATH;
1923
const char *rom_path_cfg = conf_getString("path", "bios_rom");
2024

@@ -27,21 +31,24 @@ static bool rom_bios_start(void) {
2731

2832
if (fp == NULL) {
2933
LOG_ERR("missing bios rom file\n");
30-
return false;
34+
ret = false;
35+
goto err_missingFile;
3136
}
3237

3338
const size_t read = fread(bios, 1, ROM_BIOS_SIZE, fp);
3439
if (read != ROM_BIOS_SIZE) {
3540
LOG_ERR("bad bios rom file size: %lu\n", read);
36-
return false;
41+
ret = false;
42+
goto err_cannotRead;
3743
}
3844

39-
if (fclose(fp) != 0) {
40-
LOG_ERR("error closing bios rom file\n");
41-
return false;
42-
}
45+
ret = true;
4346

44-
return true;
47+
err_cannotRead:
48+
if (fclose(fp) != 0)
49+
LOG_WARN("error closing bios rom file\n");
50+
err_missingFile:
51+
return ret;
4552
}
4653

4754
void rom_bios_init(CEDAModule *mod) {
@@ -51,7 +58,7 @@ void rom_bios_init(CEDAModule *mod) {
5158
}
5259

5360
uint8_t rom_bios_read(ceda_address_t address) {
54-
const zuint8 value = bios[address];
61+
const uint8_t value = bios[address];
5562
LOG_DEBUG("ROM [%04x] => %02x\n", address, value);
5663
return value;
5764
}

src/bus.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#include "bus.h"
22

33
#include "bios.h"
4-
#include "cpu.h"
54
#include "crtc.h"
65
#include "fdc.h"
76
#include "macro.h"
7+
#include "module.h"
88
#include "ram/auxram.h"
99
#include "ram/dynamic.h"
1010
#include "sio2.h"
1111
#include "speaker.h"
1212
#include "timer.h"
13+
#include "type.h"
1314
#include "ubus.h"
1415
#include "upd8255.h"
1516
#include "video.h"
1617

17-
#include <Z80.h>
1818
#include <inttypes.h>
1919
#include <stdint.h>
2020
#include <string.h>
@@ -74,7 +74,7 @@ uint8_t bus_mem_read(ceda_address_t address) {
7474
const struct bus_mem_slot *slot = &bus_mem_slots[i];
7575
if (address >= slot->base && address < slot->top) {
7676
if (slot->read) {
77-
const zuint8 value = slot->read(address - slot->base);
77+
const uint8_t value = slot->read(address - slot->base);
7878
LOG_DEBUG("%s: [%04x] => %02x\n", __func__, address, value);
7979
return value;
8080
}
@@ -83,15 +83,15 @@ uint8_t bus_mem_read(ceda_address_t address) {
8383
}
8484

8585
// default: read from dynamic ram
86-
const zuint8 value = dyn_ram_read(address);
86+
const uint8_t value = dyn_ram_read(address);
8787
LOG_DEBUG("%s: [%04x] => %02x\n", __func__, address, value);
8888
return value;
8989
}
9090

9191
void bus_mem_readsome(uint8_t *blob, ceda_address_t address, ceda_size_t len) {
9292
LOG_DEBUG("%s: [%04x] x %hu\n", __func__, address, len);
9393

94-
for (zuint16 i = 0; i < len; ++i) {
94+
for (uint16_t i = 0; i < len; ++i) {
9595
blob[i] = bus_mem_read(address + i);
9696
}
9797
}
@@ -119,7 +119,7 @@ void bus_mem_write(ceda_address_t address, uint8_t value) {
119119
}
120120

121121
uint8_t bus_io_in(ceda_ioaddr_t address) {
122-
LOG_DEBUG("%s: [%02x]\n", __func__, (zuint8)address);
122+
LOG_DEBUG("%s: [%02x]\n", __func__, (uint8_t)address);
123123

124124
// IO access, rom override condition is de-asserted
125125
is_bios_rom_switched = false;
@@ -137,7 +137,7 @@ uint8_t bus_io_in(ceda_ioaddr_t address) {
137137
}
138138

139139
void bus_io_out(ceda_ioaddr_t _address, uint8_t value) {
140-
const zuint8 address = (zuint8)_address;
140+
const uint8_t address = (uint8_t)_address;
141141
LOG_DEBUG("%s: [%02x] <= %02x\n", __func__, address, value);
142142

143143
// IO access, rom override condition is de-asserted

src/ceda.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "serial.h"
1616
#include "sio2.h"
1717
#include "speaker.h"
18+
#include "time.h"
1819
#include "timer.h"
1920
#include "ubus.h"
2021
#include "upd8255.h"
@@ -24,6 +25,7 @@
2425
#include "charmon.h"
2526

2627
#include <assert.h>
28+
2729
#include <unistd.h>
2830

2931
#include "log.h"
@@ -101,7 +103,7 @@ static void ceda_remaining(void) {
101103
wait = MIN(remaining(), wait);
102104
}
103105
if (wait > 0) {
104-
usleep((__useconds_t)wait);
106+
usleep((__useconds_t)wait); /* NOLINT */
105107
}
106108
}
107109

src/ceda_string.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "ceda_string.h"
22

33
#include "macro.h"
4+
#include "type.h"
45

6+
#include <assert.h>
57
#include <stdarg.h>
68
#include <stdbool.h>
79
#include <stddef.h>
10+
#include <stdint.h>
811
#include <stdio.h>
912
#include <stdlib.h>
1013
#include <string.h>
@@ -85,7 +88,7 @@ void ceda_string_cat(ceda_string_t *str, const char *data) {
8588

8689
// concatenate data, overwriting old null-terminator
8790
--str->used;
88-
for (ceda_size_t i = 0; i < strlen_data; ++i) {
91+
for (ceda_size_t i = 0; i < (ceda_size_t)strlen_data; ++i) {
8992
str->data[str->used++] = data[i];
9093
}
9194
str->data[str->used++] = '\0';

src/charmon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include "charmon.h"
22

33
#include "conf.h"
4+
#include "module.h"
5+
#include "type.h"
46
#include "ubus.h"
57

8+
#include <stdint.h>
69
#include <stdio.h>
710
#include <string.h>
811

src/cli.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// NOLINTBEGIN
12
#include "cli.h"
23

34
#include "3rd/disassembler.h"
@@ -11,13 +12,15 @@
1112
#include "serial.h"
1213
#include "time.h"
1314
#include "tokenizer.h"
15+
#include "type.h"
1416

1517
#include <assert.h>
1618
#include <ctype.h>
1719
#include <errno.h>
1820
#include <inttypes.h>
1921
#include <netinet/in.h>
2022
#include <stdbool.h>
23+
#include <stdint.h>
2124
#include <stdlib.h>
2225
#include <string.h>
2326
#include <sys/select.h>
@@ -163,7 +166,7 @@ static ceda_string_t *cli_break(const char *arg) {
163166
ceda_string_cpy(msg, USER_BAD_ARG_STR "address must be 16 bit\n");
164167
return msg;
165168
}
166-
const zuint16 address = (zuint16)_address;
169+
const uint16_t address = (uint16_t)_address;
167170

168171
// actually set breakpoint
169172
bool ret = cpu_addBreakpoint(address);
@@ -255,7 +258,7 @@ static ceda_string_t *cli_read(const char *arg) {
255258
// read some mem
256259
const ceda_size_t BLOB_SIZE = 8 * (size_t)16;
257260
uint8_t blob[BLOB_SIZE];
258-
bus_mem_readsome(blob, (zuint16)address, BLOB_SIZE);
261+
bus_mem_readsome(blob, (uint16_t)address, BLOB_SIZE);
259262

260263
// print nice hexdump
261264
uint8_t ascii[16 + 1] = {0};
@@ -266,7 +269,7 @@ static ceda_string_t *cli_read(const char *arg) {
266269
ceda_string_printf(msg, "%04x\t", address + i);
267270
}
268271

269-
ceda_string_printf(msg, "%02x ", ((unsigned int)(c)) & 0xff);
272+
ceda_string_printf(msg, "%02x ", ((unsigned int)c) & 0xff);
270273
ascii[i % 16] = isprint(c) ? c : '.';
271274

272275
if (i % 16 == 8 - 1) {
@@ -301,10 +304,10 @@ static ceda_string_t *cli_write(const char *arg) {
301304
ceda_string_cpy(msg, USER_BAD_ARG_STR "address must be 16 bit\n");
302305
return msg;
303306
}
304-
const zuint16 address = (zuint16)_address;
307+
const uint16_t address = (uint16_t)_address;
305308

306309
// read values, and put them in memory
307-
for (zuint16 i = 0;; ++i) {
310+
for (uint16_t i = 0;; ++i) {
308311
// extract value
309312
unsigned int _value;
310313
arg = tokenizer_next_hex(&_value, arg);
@@ -324,7 +327,7 @@ static ceda_string_t *cli_write(const char *arg) {
324327
ceda_string_cpy(msg, USER_BAD_ARG_STR "value must be 8 bit\n");
325328
return msg;
326329
}
327-
const zuint8 value = (zuint8)_value;
330+
const uint8_t value = (uint8_t)_value;
328331

329332
bus_mem_write(address + i, value);
330333
}
@@ -353,7 +356,7 @@ static ceda_string_t *cli_dis(const char *arg) {
353356
char line[LINE_BUFFER_SIZE];
354357
uint8_t blob[CPU_MAX_OPCODE_LEN];
355358
for (int i = 0; i < 16; ++i) {
356-
bus_mem_readsome(blob, (zuint16)(address + (unsigned int)disb),
359+
bus_mem_readsome(blob, (uint16_t)(address + (unsigned int)disb),
357360
CPU_MAX_OPCODE_LEN);
358361
disb += disassemble(blob, (int)address + disb, line, BLOCK_BUFFER_SIZE);
359362
ceda_string_printf(msg, "%s\n", line);
@@ -440,7 +443,7 @@ static ceda_string_t *cli_save(const char *arg) {
440443
blob[0] = lsb;
441444
blob[1] = msb;
442445
// payload
443-
bus_mem_readsome(&blob[2], (zuint16)start_address, data_size);
446+
bus_mem_readsome(&blob[2], (uint16_t)start_address, data_size);
444447
// write
445448
size_t written = fwrite(blob, 1, alloc_size, fp);
446449
if (written != alloc_size) {
@@ -545,7 +548,7 @@ static ceda_string_t *cli_load_and_run(const char *arg, bool run) {
545548
ret = fread(&c, 1, 1, fp);
546549
if (ret == 0)
547550
break;
548-
bus_mem_write((zuint16)address++, (zuint8)c);
551+
bus_mem_write((uint16_t)address++, (uint8_t)c);
549552
}
550553

551554
(void)fclose(fp);
@@ -662,7 +665,7 @@ static ceda_string_t *cli_goto(const char *arg) {
662665
}
663666

664667
// inconditional jump
665-
cpu_goto((zuint16)address);
668+
cpu_goto((uint16_t)address);
666669
return NULL;
667670
}
668671

@@ -728,7 +731,7 @@ static ceda_string_t *cli_in(const char *arg) {
728731
return msg;
729732
}
730733

731-
const zuint8 value = bus_io_in((ceda_ioaddr_t)address);
734+
const uint8_t value = bus_io_in((ceda_ioaddr_t)address);
732735
ceda_string_printf(msg, "%02x\n", value);
733736
return msg;
734737
}
@@ -764,7 +767,7 @@ static ceda_string_t *cli_out(const char *arg) {
764767
return msg;
765768
}
766769

767-
bus_io_out((ceda_ioaddr_t)address, (zuint8)value);
770+
bus_io_out((ceda_ioaddr_t)address, (uint8_t)value);
768771

769772
ceda_string_delete(msg);
770773
return NULL;
@@ -1201,3 +1204,5 @@ Test(cli, delete, .init = cli_test_setup) {
12011204
}
12021205

12031206
#endif
1207+
//NOLINTEND
1208+

0 commit comments

Comments
 (0)