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

Address known issues through 2020 #2

Merged
merged 20 commits into from
Jan 13, 2021
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
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
cmake_minimum_required(VERSION 3.1)
project(gsplus VERSION 0.15)

if(UNIX OR LINUX)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# Uncomment for Pi4/400:
# set(CMAKE_CXX_FLAGS "-Wall -Wextra -fomit-frame-pointer -mcpu=cortex-a72 -mfloat-abi=hard -mfpu=crypto-neon-fp-armv8 -mneon-for-64bits")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
add_compile_definitions(WITH_STATIC)
#add_compile_definitions(WITH_RAWNET)
#set(CMAKE_CXX_FLAGS_RELEASE "-Os")

# OBJECTS = $(OBJECTS1) $(TFEOBJ) $(ATOBJ) $(PCAPOBJ) $(FSTOBJ) sdl2_driver.o sdl2snd_driver.o
# CCOPTS = -O2 -Wall -fomit-frame-pointer -std=gnu99 -march=armv6
# OPTS = -DGSPLUS_LITTLE_ENDIAN -DHAVE_TFE -DHAVE_ATBRIDGE -DHAVE_SDL -I/usr/include/SDL2 -I/usr/include/freetype2

endif()

if(CYGWIN OR MSYS)
set(WIN32 1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Install MSYS2 (not MSYS, not cygwin)
## Linux, OS X, build
mkdir build
cd build
cmake ..
cmake .. -DWITH_RAWNET=ON
(optionally: ccmake .. to configure stuff)
make

Expand Down
14 changes: 9 additions & 5 deletions src/arch/os2/src/dirport.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ int closedir (DIR *dir) {
Author

Mark Martinec <[email protected]>, April 1999, June 2000
Copyright 1999, Mark Martinec
Copyright © 1999, Mark Martinec

*/

Expand Down Expand Up @@ -248,7 +248,8 @@ int vasprintf(char **ptr, const char *fmt, va_list ap) {
{ va_list ap2;
va_copy(ap2, ap); /* don't consume the original ap, we'll need it again */
str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
va_end(ap2);}
va_end(ap2);
}
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
*ptr = (char *) malloc(str_m = (size_t)str_l + 1);
if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
Expand Down Expand Up @@ -296,7 +297,8 @@ int vasnprintf (char **ptr, size_t str_m, const char *fmt, va_list ap) {
{ va_list ap2;
va_copy(ap2, ap); /* don't consume the original ap, we'll need it again */
str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
va_end(ap2);}
va_end(ap2);
}
assert(str_l >= 0); /* possible integer overflow if str_m > INT_MAX */
if ((size_t)str_l + 1 < str_m) str_m = (size_t)str_l + 1; /* truncate */
/* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
Expand Down Expand Up @@ -709,7 +711,8 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) {
}
/* zero padding to specified precision? */
if (num_of_digits < precision)
number_of_zeros_to_pad = precision - num_of_digits; }
number_of_zeros_to_pad = precision - num_of_digits;
}
/* zero padding to specified minimal field width? */
if (!justify_left && zero_padding) {
int n = min_field_width - (str_arg_l+number_of_zeros_to_pad);
Expand Down Expand Up @@ -785,7 +788,8 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) {
(n>avail ? avail : n));
}
str_l += n;
}}
}
}
/* insert right padding */
if (justify_left) { /* right blank padding to the field width */
int n = min_field_width - (str_arg_l+number_of_zeros_to_pad);
Expand Down
11 changes: 6 additions & 5 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "defc.h"
#include <stdarg.h>
#include <ctype.h>
#include <string.h>
#include "config.h"
#include "glog.h"
#include "imagewriter.h"
Expand Down Expand Up @@ -1426,15 +1427,15 @@ void insert_disk(int slot, int drive, const char *name, int ejected, int force_s
}
name_ptr[name_len] = 0;
#else
strncpy(name_ptr, name, name_len + 1);
strcpy(name_ptr, name);
#endif
dsk->name_ptr = name_ptr;

dsk->partition_name = 0;
if(partition_name != 0) {
part_len = strlen(partition_name) + 1;
part_ptr = (char *)malloc(part_len);
strncpy(part_ptr, partition_name, part_len);
strcpy(part_ptr, partition_name);
dsk->partition_name = part_ptr;
}
dsk->partition_num = part_num;
Expand All @@ -1458,7 +1459,7 @@ void insert_disk(int slot, int drive, const char *name, int ejected, int force_s
can_write = 0;

uncomp_ptr = (char *)malloc(name_len + 1);
strncpy(uncomp_ptr, name_ptr, name_len + 1);
strcpy(uncomp_ptr, name_ptr);
uncomp_ptr[name_len - 3] = 0;

system_len = 2*name_len + 100;
Expand Down Expand Up @@ -2570,7 +2571,7 @@ void cfg_file_add_dirent(Cfg_listhdr *listhdrptr, const char *nameptr, int is_di
listhdrptr->max * sizeof(Cfg_dirent));
}
ptr = (char*)malloc(namelen+1+is_dir); // OG Added cast
strncpy(ptr, nameptr, namelen+1);
strcpy(ptr, nameptr);
if(is_dir) {
strcat(ptr, "/");
}
Expand Down Expand Up @@ -2877,7 +2878,7 @@ void cfg_file_draw() {
(g_cfg_slotdrive >> 8), (g_cfg_slotdrive & 0xff) + 1);
} else {
cfg_htab_vtab(5, 0);
cfg_printf("\bSelect file to use as %-40s\b",
cfg_printf("\bSpace to select path to use as %-40s\b",
cfg_shorten_filename(g_cfg_file_def_name, 40));
}
cfg_htab_vtab(2, 1);
Expand Down
6 changes: 3 additions & 3 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ void handle_set_bytes(int address, char *bytes_data) {
while (sscanf(bytes_data, "%02x", &byte) == 1) {
printf("$%02x <---- BYTE @ $%06X\n", byte, address );
bytes_data += 2;
address++;
set_byte_at_address(address, byte & 0xFF);
address++;
}
}

Expand Down Expand Up @@ -1027,7 +1027,7 @@ void debug_server_poll() {
/* failure occurs, we will close the */
/* connection. */
/*****************************************************/
rc = recv(fds[i].fd, buffer, sizeof(buffer), 0);
rc = recv(fds[i].fd, buffer, sizeof(buffer), MSG_DONTWAIT);
if (rc < 0) {
if (errno != EWOULDBLOCK) {
perror("recv() failed");
Expand Down Expand Up @@ -1313,7 +1313,7 @@ int do_dis_json(char *buf, word32 kpc, int accsize, int xsize, int op_provided,
sprintf(buf_disasm,"%s [$%0*x],Y",out,args*2,val);
break;

case IMMED:
case IMMEDIATE:
sprintf(buf_disasm,"%s #$%0*x",out, args*2, val);
break;

Expand Down
9 changes: 9 additions & 0 deletions src/engine_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,15 @@ void fixed_memory_ptrs_shut() {

#if defined(__i386__) || defined(__x86_64__)
#include <x86intrin.h>
#elif defined(_POSIX_MONOTONIC_CLOCK)
#include <time.h>
int64_t __rdtsc() {
struct timespec tp = {0};
int64_t timestamp = 0;
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
timestamp = tp.tv_sec * 1000000000 + tp.tv_nsec;
return timestamp;
}
#elif defined(__powerpc__) || defined(__ppc__)
#define __rdtsc() __builtin_ppc_mftb()
#else
Expand Down
2 changes: 1 addition & 1 deletion src/host_common.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define _BSD_SOURCE
#define _DEFAULT_SOURCE

#include <errno.h>
#include <ctype.h>
Expand Down
50 changes: 40 additions & 10 deletions src/host_fst.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
See LICENSE.txt for license (GPL v2)
*/

#define _BSD_SOURCE
#define _DEFAULT_SOURCE

#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -406,6 +406,14 @@ static char *get_path2(void) {
return NULL;
}

#if defined (__linux__)
static void get_resource_pathname(const char *path, char *rpath) {
char *pos=strrchr(path,'/');
strncpy(rpath, path, (pos-path)+1);
strcat(rpath, "._");
strcat(rpath, pos+1);
}
#endif

/*
* shutdown is called when switching to p8.
Expand Down Expand Up @@ -545,7 +553,18 @@ static word32 fst_destroy(int class, const char *path) {

int ok = S_ISDIR(st.st_mode) ? rmdir(path) : unlink(path);


#if defined(__linux__)
if (! S_ISDIR(st.st_mode)) {
// on linux remove the resource fork file as well.
char rpath[1024];
get_resource_pathname(path, rpath);
if (stat(rpath, &st) == 0) {
int ok2 = unlink(rpath);
if (ok2 < 0) return host_map_errno_path(errno, path);
}
}
#endif

if (ok < 0) return host_map_errno_path(errno, path);
return 0;
}
Expand Down Expand Up @@ -768,12 +787,17 @@ static int open_data_fork(const char *path, word16 *access, word16 *error) {

return fd;
}
#if defined(__APPLE__)
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
#if defined(__APPLE__) || defined(__linux__)
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
#if defined(__APPLE__)
// os x / hfs/apfs don't need to specifically create a resource fork.
// or do they?

char *rpath = host_gc_append_path(path, _PATH_RSRCFORKSPEC);
#else
char rpath[1024];
get_resource_pathname(path, rpath);
#endif

int fd = -1;
for (;;) {
Expand Down Expand Up @@ -852,11 +876,6 @@ static int open_resource_fork(const char *path, word16 *access, word16 *error) {

return fd;
}
#elif defined __linux__
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
*error = resForkNotFound;
return -1;
}
#else
static int open_resource_fork(const char *path, word16 *access, word16 *error) {
*error = resForkNotFound;
Expand Down Expand Up @@ -1534,9 +1553,20 @@ static word32 fst_change_path(int class, const char *path1, const char *path2) {
return invalidAccess;

// rename will delete any previous file. ChangePath should return an error.
#if ! defined(__linux__)
if (stat(path2, &st) == 0) return dupPathname;

if (rename(path1, path2) < 0) return host_map_errno_path(errno, path2);
#else
//on linux rename both the file and the resource file.
char rpath1[1024], rpath2[1024];
get_resource_pathname(path1, rpath1);
get_resource_pathname(path2, rpath2);
if (stat(path2, &st) == 0 || stat(rpath2, &st) == 0) return dupPathname;
if (rename(path1, path2) < 0) return host_map_errno_path(errno, path2);
if (rename(rpath1, rpath2) < 0) return host_map_errno_path(errno, rpath2);

#endif
return 0;
}

Expand Down
5 changes: 2 additions & 3 deletions src/host_mli.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#define _BSD_SOURCE
#define _DEFAULT_SOURCE

#ifdef _WIN32
#include <Windows.h>
Expand Down Expand Up @@ -1553,4 +1552,4 @@ void host_mli_tail() {
engine.psr &= ~I;
engine.psr |= (saved_p & I);
host_gc_free();
}
}
8 changes: 6 additions & 2 deletions src/instable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2257,8 +2257,12 @@ instcb_SYM /* WAI */
b dispatch
stw scratch2,r%g_wait_pending(scratch1)
#else
g_wait_pending = 1;
CYCLES_FINISH
if(g_irq_pending) {
g_wait_pending = 0;
INC_KPC_1;
} else {
g_wait_pending = 1;
}
#endif

instcc_SYM /* CPY abs */
Expand Down
10 changes: 3 additions & 7 deletions src/rawnet/rawnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
*/

#ifdef HAVE_RAWNET
#else
#error RAWNET.H should not be included if HAVE_RAWNET is not defined!
#endif /* #ifdef HAVE_RAWNET */

#ifndef VICE_RAWNET_H
#define VICE_RAWNET_H

/*
This is a helper for the _receive() function of the emulated ethernet chip to determine
Expand Down Expand Up @@ -74,4 +68,6 @@ extern char *rawnet_get_standard_interface(void);

extern int rawnet_status(void);

#endif
#else
#error RAWNET.H should not be included if HAVE_RAWNET is not defined!
#endif /* #ifdef HAVE_RAWNET */
2 changes: 2 additions & 0 deletions src/rawnet/rawnetarch_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#include "rawnetsupp.h"

#if defined(__linux__)
#include <unistd.h> //support for close
#include <arpa/inet.h> //support for close
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
Expand Down
2 changes: 1 addition & 1 deletion src/sdl2snd_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ long sound_init_device_sdl() {
wanted.freq = g_preferred_rate;
wanted.format = AUDIO_S16SYS;
wanted.channels = NUM_CHANNELS;
wanted.samples = 512;
wanted.samples = 2048;
wanted.callback = _snd_callback;
wanted.userdata = NULL;

Expand Down
9 changes: 2 additions & 7 deletions src/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,14 +893,9 @@ void sound_play(double dsamps) {
off = imul * 128;

samps_to_do = MIN(samps_left, num_samps - samp_offset);
if(imul == 0 || samps_to_do == 0) {
if(samps_to_do == 0) {
/* produce no sound */
samps_left = samps_left - samps_to_do;
cur_acc += cur_inc * samps_to_do;
rptr->samps_left = samps_left;
rptr->cur_acc = cur_acc;
cur_dsamp = last_dsamp +
(double)(samps_to_do + samp_offset);
cur_dsamp = cur_dsamp = last_dsamp + (double)(samp_offset);
DOC_LOG("nosnd", osc, cur_dsamp, samps_to_do);
rptr->complete_dsamp = dsamp_now;
cur_pos = rptr->cur_start+(cur_acc & cur_mask);
Expand Down
3 changes: 2 additions & 1 deletion src/to_pro.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "defc.h"
#include <ctype.h>
#include <string.h>

#include "prodos.h"

Expand Down Expand Up @@ -367,7 +368,7 @@ void format_memdisk(ProDisk *disk, char *name) {
set_l2byte(&(dir->next_blk), 3);
vol_hdr = (Vol_hdr *)&(dir->file_entries[0]);
vol_hdr->storage_type_name_len = 0xf0 + strlen(name);
strncpy((char *)vol_hdr->vol_name, name, strlen(name));
strcpy (vol_hdr->vol_name, name);
vol_hdr->version = 0;
vol_hdr->min_version = 0;
vol_hdr->access = 0xc3;
Expand Down
Loading