Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header guards and fix some compiler warnings #29

Merged
merged 4 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions include/conio.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@

*/

#ifndef __MEGA65_CONIO_H
#define __MEGA65_CONIO_H

#ifndef __CC65__
#define fastcall
#endif

#ifndef M65LIBC_CONIO_H
#define M65LIBC_CONIO_H

/*------------------------------------------------------------------------
Color and attributes
-----------------------------------------------------------------------*/
Expand Down Expand Up @@ -837,4 +837,4 @@ void flushkeybuf(void);
unsigned char cinput(
unsigned char* buffer, unsigned char buflen, unsigned char flags);

#endif // M65LIBC_CONIO_H
#endif /* __MEGA65_CONIO_H */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this one /* .. */ is used, but the rest in the PR uses //. It would hurt if it was consistent, using // is C99 and will not work with C89/C94. C99 is close to 25 years old, but I do not know if we expect issues with old compilers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh ok, I think we can resolve it in a separate issue, either now or when a new compiler becomes relevant. I'm unsure of what standards are out there.

5 changes: 5 additions & 0 deletions include/debug.h
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
#ifndef __MEGA65_DEBUG_H
#define __MEGA65_DEBUG_H

void debug_msg(char* m);

#endif // __MEGA65_DEBUG_H
7 changes: 7 additions & 0 deletions include/dirent.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#ifndef __MEGA65_DIRENT_H
#define __MEGA65_DIRENT_H

#include <stdint.h>

unsigned char opendir(void);
struct m65_dirent* readdir(unsigned char);
void closedir(unsigned char);
Expand All @@ -9,3 +14,5 @@ struct m65_dirent {
uint16_t d_type;
char d_name[256];
};

#endif // __MEGA65_DIRENT_H
6 changes: 3 additions & 3 deletions include/fcio.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Details.
*/

#ifndef __FCIO
#define __FCIO
#ifndef __MEGA65_FCIO_H
#define __MEGA65_FCIO_H

#include <memory.h>
mlund marked this conversation as resolved.
Show resolved Hide resolved
#include <stdbool.h>
Expand Down Expand Up @@ -521,4 +521,4 @@ void fc_plotExtChar(byte x, byte y, byte c);
*/
void fc_plotPetsciiChar(byte x, byte y, byte c, byte color, byte exAttr);

#endif
#endif // __MEGA65_FCIO_H
5 changes: 5 additions & 0 deletions include/fileio.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __MEGA65_FILEIO_H
#define __MEGA65_FILEIO_H

void toggle_rom_write_protect();
void closeall(void);
void close(unsigned char fd);
Expand All @@ -15,3 +18,5 @@ unsigned char chdir(char* filename);

// Change working directory to the root directory
unsigned char chdirroot(void);

#endif // __MEGA65_FILEIO_H
2 changes: 1 addition & 1 deletion include/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

void usleep(uint32_t micros);

#endif
#endif // __MEGA65_HAL_H
2 changes: 1 addition & 1 deletion include/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ void lfill_skip(long destination_address, unsigned char value,
#define PEEK32(X)
#endif

#endif
#endif // __MEGA65_MEMORY_H
5 changes: 5 additions & 0 deletions include/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
Date 2020-07-01
*/

#ifndef __MEGA65_MOUSE_H
#define __MEGA65_MOUSE_H

void mouse_warp_to(unsigned short x, unsigned short y);
void mouse_update_position(unsigned short* mx, unsigned short* my);
void mouse_update_pointer(void);
Expand All @@ -27,3 +30,5 @@ void mouse_clip_position(void);
void mouse_bind_to_sprite(unsigned char sprite_num);
void mouse_set_bounding_box(
unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2);

#endif // __MEGA65_MOUSE_H
5 changes: 5 additions & 0 deletions include/random.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#include <stdint.h>

#ifndef __MEGA65_RANDOM_H
#define __MEGA65_RANDOM_H

uint32_t random32(uint32_t range);
uint16_t random16(uint16_t range);
uint8_t random8(uint8_t range);
void srand(uint32_t seed);
uint8_t rand8(uint8_t range);
uint16_t rand16(uint16_t range);
uint32_t rand32(uint32_t range);

#endif // __MEGA65_RANDOM_H
2 changes: 1 addition & 1 deletion include/sdcard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ uint8_t mega65_sdcard_writesector(const uint32_t sector_number);
void mega65_sdcard_erase(
const uint32_t first_sector, const uint32_t last_sector);

#endif
#endif // __MEGA65_SDCARD_H
6 changes: 3 additions & 3 deletions include/targets.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _TARGETS_H_
#define _TARGETS_H_
#ifndef __MEGA65_TARGETS_H
#define __MEGA65_TARGETS_H

#define TARGET_UNKNOWN 0
#define TARGET_MEGA65R1 1
Expand All @@ -15,4 +15,4 @@

unsigned char detect_target(void);

#endif
#endif // __MEGA65_TARGETS_H
6 changes: 3 additions & 3 deletions include/tests.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef TESTS_H
#define TESTS_H
#ifndef __MEGA65_TESTS_H
#define __MEGA65_TESTS_H

#include <stdint.h>

Expand Down Expand Up @@ -128,4 +128,4 @@ void unit_test_print(uint8_t x, uint8_t y, uint8_t colour, char* msg);
void unit_test_read_pixel(
short x, short y, uint8_t* red, uint8_t* green, uint8_t* blue);

#endif
#endif // __MEGA65_TESTS_H
6 changes: 3 additions & 3 deletions include/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
that into account.
*/

#ifndef _TIME_H_
#define _TIME_H_
#ifndef __MEGA65_TIME_H
#define __MEGA65_TIME_H

struct m65_tm {
unsigned char tm_sec; /* Seconds (0-60) */
Expand All @@ -24,4 +24,4 @@ struct m65_tm {
void getrtc(struct m65_tm* tm);
void setrtc(struct m65_tm* tm);

#endif
#endif // __MEGA65_TIME_H
6 changes: 3 additions & 3 deletions src/conio.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "../include/conio.h"
#include "../include/memory.h"
#include <conio.h>
#include <memory.h>
#include <string.h>

#define VIC_BASE 0xD000UL
Expand Down Expand Up @@ -94,7 +94,7 @@ static unsigned char hash(const unsigned char* str, const unsigned char maxLen)
len++;
hash = ((hash << 5) + hash) + c;
}
return hash;
return (unsigned char)hash;
}

static void clrscr_(unsigned char)
Expand Down
2 changes: 1 addition & 1 deletion src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Date 2020-07-01
*/

#include "../include/memory.h"
#include <memory.h>

unsigned short mouse_min_x = 0;
unsigned short mouse_min_y = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/sdcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ void mega65_sdcard_unmap_sector_buffer(void)

unsigned short timeout;

// @todo Return -1 corresponds to 255. Is this what we want?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume all bits set is an error value. This corresponds a bit to EOF which is used by some C library functions for error result.
Typically such cases use int in as the return type. This may be less ideal on an 8-bit CPU when given the choice of return type.
Personally I think it is ugly to return -1 when the return type is unsigned. One can use ~0 or ~0u, or perhaps better a macro to represent it.
Another way is to use int8_t as the return type which would signal that one can test for error by testing if the result is less than 0. In such case a negative value does not look inappropriate, which it kind of does now.

uint8_t mega65_sdcard_readsector(const uint32_t sector_number)
{
char tries = 0;
Expand Down Expand Up @@ -267,6 +268,7 @@ uint8_t mega65_sdcard_readsector(const uint32_t sector_number)

uint8_t verify_buffer[512];

// @todo Return -1 corresponds to 255. Is this what we want?
uint8_t mega65_sdcard_writesector(const uint32_t sector_number)
{
// Copy buffer into the SD card buffer, and then execute the write job
Expand Down
6 changes: 3 additions & 3 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ static uint8_t frame_num;
void unit_test_read_pixel(
short x, short y, uint8_t* red, uint8_t* green, uint8_t* blue)
{
POKE(0xD07D, x);
POKE(0xD07E, y);
POKE(0xD07F, (x >> 8) + ((y >> 8) << 4));
POKE(0xD07D, (uint8_t)x);
POKE(0xD07E, (uint8_t)y);
POKE(0xD07F, (uint8_t)((x >> 8) + ((y >> 8) << 4)));

// Wait at least two whole frames
frame_num = PEEK(0xD7FA);
Expand Down