#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include "../libsdl/print.h"
#include "execute.h"
#include "m68k.h"
#include "m68kcpu.h"
/* checking if game does not hit any 'stop_at' break point, give error output */
if (instruction_count >= 10000000) {
if (instruction_count == 10000000)
- fprintf(stderr, "!!! games seems to got stuck in an endless loop, please fix !!!\n");
+ print_error("!!! games seems to got stuck in an endless loop, please fix !!!\n");
fprintf(stderr, "program counter at: %06x\n", REG_PC);
if (instruction_count == 10000020)
break;
for (i = 0; stop_at[i].event; i++) {
if (REG_PC == stop_at[i].pc) {
#ifdef DEBUG_CPU
- printf("execution to address 0x%06x took %d opcodes\n", REG_PC, instruction_count);
+ print_error("execution to address 0x%06x took %d opcodes\n", REG_PC, instruction_count);
#endif
*event = stop_at[i].event;
return cycle_count;
#include <stdio.h>
#include <stdint.h>
#include <string.h>
+#include "../libsdl/print.h"
#include "keyboard.h"
//#define DEBUG_KEYS
}
}
if (code < 0 || code >= 0x80) {
- fprintf(stderr, "Key code '%s' unknown, please fix!\n", key);
+ print_error("Key code '%s' unknown, please fix!\n", key);
return;
}
}
if (buffer_len == buffer_size) {
- fprintf(stderr, "keyboard buffer overflow\n");
+ print_error("keyboard buffer overflow\n");
return;
}
libsdl_a_SOURCES = \
sdl.c \
- opengl.c
+ opengl.c \
+ print.c
#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
+#include "print.h"
#include "opengl.h"
#include <GL/glew.h>
;
text_rgb = calloc(texture_size * texture_size * 10, 3);
if (!text_rgb) {
- fprintf(stderr, "Failed to allocate texture\n");
+ print_error("Failed to allocate texture\n");
rc = -ENOMEM;
goto error;
}
--- /dev/null
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <SDL2/SDL_log.h>
+
+void __attribute__ ((format (printf, 1, 2))) _print_info(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+
+ SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, args);
+
+ va_end(args);
+}
+
+void __attribute__ ((format (printf, 3, 4))) _print_error(const char *_file, int _line, const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+
+ SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Error in %s line %d:\n", _file, _line);
+ SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, args);
+
+ va_end(args);
+}
+
--- /dev/null
+
+#define print_info(format, arg...) _print_info(format, ##arg)
+void __attribute__ ((format (printf, 1, 2))) _print_info(const char *format, ...);
+
+#define print_error(format, arg...) _print_error(__FILE__, __LINE__, format, ##arg)
+void __attribute__ ((format (printf, 3, 4))) _print_error(const char *_file, int _line, const char *format, ...);
+
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
+#include "print.h"
#include "sdl.h"
#include "opengl.h"
/* init SDL library */
rc = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
if (rc < 0) {
- fprintf(stderr, "Failed to init SDL\n");
+ print_error("Failed to init SDL\n");
goto error;
}
sdl_initialized = 1;
/* open window */
gl_window = SDL_CreateWindow(progname, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!gl_window) {
- fprintf(stderr, "Failed to open SDL window: %s\n", SDL_GetError());
+ print_error("Failed to open SDL window: %s\n", SDL_GetError());
rc = EIO;
goto error;
}
/* create GL context */
gl_context = SDL_GL_CreateContext(gl_window);
if (!gl_context) {
- fprintf(stderr, "Failed to create SDL's OpenGL context: %s\n", SDL_GetError());
+ print_error("Failed to create SDL's OpenGL context: %s\n", SDL_GetError());
rc = EIO;
goto error;
}
rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
if (rc < 0) {
- fprintf(stderr, "Failed to set SDL's OpenGL context profile\n");
+ print_error("Failed to set SDL's OpenGL context profile\n");
goto error;
}
rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
if (rc < 0) {
- fprintf(stderr, "Failed to set SDL's OpenGL major version\n");
+ print_error("Failed to set SDL's OpenGL major version\n");
goto error;
}
rc = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
if (rc < 0) {
- fprintf(stderr, "Failed to set SDL's OpenGL minor version\n");
+ print_error("Failed to set SDL's OpenGL minor version\n");
goto error;
}
rc = SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (rc < 0) {
- fprintf(stderr, "Failed to set SDL's OpenGL doublebuffer\n");
+ print_error("Failed to set SDL's OpenGL doublebuffer\n");
goto error;
}
rc = SDL_GL_SetSwapInterval(1);
if (rc < 0) {
- fprintf(stderr, "Failed to set SDL's OpenGL swap interval to VBLANK\n");
+ print_error("Failed to set SDL's OpenGL swap interval to VBLANK\n");
goto error;
}
#ifndef __APPLE__
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
- fprintf(stderr, "Failed to init GLEW\n");
+ print_error("Failed to init GLEW\n");
goto error;
}
#endif
want.callback = audio_cb;
rc = SDL_OpenAudio(&want, &have);
if (rc < 0) {
- fprintf(stderr, "Failed to open audio\n");
+ print_error("Failed to open audio\n");
goto error;
} else if (have.format != want.format) {
- fprintf(stderr, "Failed to open audio with desired audio format\n");
+ print_error("Failed to open audio with desired audio format\n");
SDL_CloseAudio();
rc = -EIO;
goto error;
} else if (have.freq != want.freq) {
- fprintf(stderr, "Failed to open audio with desired sample rate\n");
+ print_error("Failed to open audio with desired sample rate\n");
SDL_CloseAudio();
rc = -EIO;
goto error;
#include <stdint.h>
#include <string.h>
#include <math.h>
+#include "../libsdl/print.h"
#include "sound.h"
#include "../libcpu/m68kcpu.h"
chan->end = chan->start + chan->length;
/* check ranges */
if (chan->length == 0) {
- fprintf(stderr, "Sample length of channel %d is 0, please fix!\n", c);
+ print_error("Sample length of channel %d is 0, please fix!\n", c);
chan->dma_on = 0;
return -1;
}
if (chan->pointer >= 0x80000) {
- fprintf(stderr, "Sample pointer 0x%08x of channel %d is outside memory, please fix!\n", chan->pointer, c);
+ print_error("Sample pointer 0x%08x of channel %d is outside memory, please fix!\n", chan->pointer, c);
chan->dma_on = 0;
return -1;
}
if (chan->end > 0x80000) {
- fprintf(stderr, "Sample end (pointer 0x%08x + length 0x%x) of channel %d is outside memory, please fix!\n", chan->pointer, chan->length, c);
+ print_error("Sample end (pointer 0x%08x + length 0x%x) of channel %d is outside memory, please fix!\n", chan->pointer, chan->length, c);
chan->dma_on = 0;
return -1;
}
#include <stdio.h>
#include <stdint.h>
+#include "../libsdl/print.h"
#include "video.h"
#include "../libcpu/m68kcpu.h"
/* get copper list start pointer */
copperlist = (io[COP1LCH] << 16) | io[COP1LCL];
if (!copperlist) {
- fprintf(stderr, "Copper list pointer not initialized, please fix!\n");
+ print_error("Copper list pointer not initialized, please fix!\n");
return;
}
last_line = 0;
while (42) {
if (++count == 100) {
- fprintf(stderr, "Copper list does not seem to terminate, please fix!\n");
+ print_error("Copper list does not seem to terminate, please fix!\n");
return;
}
c1 = m68k_read_memory_16(copperlist);
}
} else {
if ((c2 & 1)) {
- fprintf(stderr, "We suppport no SKIP command in copper list, please fix!\n");
+ print_error("We suppport no SKIP command in copper list, please fix!\n");
continue;
}
/* WAIT */
printf(" %06x", bitplane[i]);
#endif
if (bitplane[i] == 0 || bitplane[i] + width * height / 8 >= 0x80000) {
+#ifdef DEBUG_COPPERLIST
printf("\n");
- fprintf(stderr, "Bitplane %d in copper list not set or out of range, please fix!\n", i);
+#endif
+ print_error("Bitplane %d in copper list not set or out of range, please fix!\n", i);
return;
}
bitmem[i] = memory + bitplane[i];
#include <sys/types.h>
#include "../libsdl/sdl.h"
#include "../libsdl/opengl.h"
+#include "../libsdl/print.h"
#include "../libcpu/m68k.h"
#include "../libcpu/execute.h"
#include "../libvideo/video.h"
while (argc > i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
- printf("Usage: %s\n", argv[0]);
- printf(" -s --amiga-speed original | full\n");
- printf(" Set speed of rendering to original Amiga or full speed.\n");
- printf(" -v --video-filter on | off\n");
- printf(" Set video filter.\n");
- printf(" -a --audio-filter on | off\n");
- printf(" Set audio filter.\n");
+ print_info("Usage: %s\n", argv[0]);
+ print_info(" -s --amiga-speed original | full\n");
+ print_info(" Set speed of rendering to original Amiga or full speed.\n");
+ print_info(" -v --video-filter on | off\n");
+ print_info(" Set video filter.\n");
+ print_info(" -a --audio-filter on | off\n");
+ print_info(" Set audio filter.\n");
return -1;
} else
if (!strcmp(argv[i], "-s") || !strcmp(argv[i], "--amiga-speed")) {
i++;
if (argc == i) {
missing_parameter:
- printf("Missing parameter, use '--help'!\n");
+ print_info("Missing parameter, use '--help'!\n");
return -1;
}
if (!strcmp(argv[i], "original"))
config_amiga_speed = 0;
else {
illegal_parameter:
- printf("Illegal parameter, use '--help'!\n");
+ print_info("Illegal parameter, use '--help'!\n");
return -1;
}
} else
else
goto illegal_parameter;
} else {
- printf("Illegal option '%s', use '--help'!\n", argv[i]);
+ print_info("Illegal option '%s', use '--help'!\n", argv[i]);
return -1;
}
i++;
static void disk_read(int track, int __attribute__((unused)) side, uint32_t data, uint16_t length)
{
if (length > sizeof(game_save[0])) {
- fprintf(stderr, "loading game state failed, because length exceeds game save data size, please fix!\n");
+ print_error("loading game state failed, because length exceeds game save data size, please fix!\n");
return;
}
fp = fopen(filename, "r");
if (!fp) {
fail:
- fprintf(stderr, "failed to load game from '%s'\n", filename);
+ print_error("failed to load game from '%s'\n", filename);
goto copy;
}
got = fread(game_save, sizeof(game_save[0]), 2, fp);
length -= 0x200;
if (length != sizeof(game_save[0])) {
- fprintf(stderr, "saving game state failed, because length of data does not match, please fix!\n");
+ print_error("saving game state failed, because length of data does not match, please fix!\n");
return;
}
/* don't save if last track is the same, because disk is written on both sides with the same data */
if (track == last_track) {
if (memcmp(memory + data, game_save[track & 1], length)) {
- fprintf(stderr, "saving game data on other side of the disk is different, please fix!\n");
+ print_error("saving game data on other side of the disk is different, please fix!\n");
}
return;
}
fp = fopen(filename, "w");
if (!fp) {
fail:
- fprintf(stderr, "failed to save game to '%s'\n", filename);
+ print_error("failed to save game to '%s'\n", filename);
return;
}
- printf("Game state saved to '%s'\n", filename);
+ print_info("Game state saved to '%s'\n", filename);
wrote = fwrite(game_save, sizeof(game_save[0]), 2, fp);
fclose(fp);
if (wrote != 2)
case SDLK_v:
if (down && ctrl) {
config_video_filter ^= 1;
- printf("video filter: %s\n", (config_video_filter) ? "on" : "off");
+ print_info("video filter: %s\n", (config_video_filter) ? "on" : "off");
}
break;
case SDLK_a:
if (down && ctrl) {
config_audio_filter ^= 1;
- printf("audio filter: %s\n", (config_audio_filter) ? "on" : "off");
+ print_info("audio filter: %s\n", (config_audio_filter) ? "on" : "off");
}
break;
case SDLK_s:
if (down && ctrl) {
config_amiga_speed ^= 1;
- printf("amiga speed: %s\n", (config_amiga_speed) ? "original" : "full");
+ print_info("amiga speed: %s\n", (config_amiga_speed) ? "original" : "full");
}
break;
case SDLK_c:
/* allocate image */
image = calloc(IMAGE_WIDTH * IMAGE_HEIGHT * ((double_size) ? 4 : 1), 3);
if (!image) {
- fprintf(stderr, "Failed to allocate image buffer\n");
+ print_error("Failed to allocate image buffer\n");
goto done;
}
if ((SOUND_SAMPLERATE % IRQ_RATE)) {
- fprintf(stderr, "Sample rate must be a multiple of IRQ rate, please fix!\n");
+ print_error("Sample rate must be a multiple of IRQ rate, please fix!\n");
goto done;
}
if ((1000 % IRQ_RATE)) {
- fprintf(stderr, "1000 (Ticks per second) rate must be a multiple of IRQ rate, please fix!\n");
+ print_error("1000 (Ticks per second) rate must be a multiple of IRQ rate, please fix!\n");
goto done;
}
sound_buffer_size = SOUND_SAMPLERATE / IRQ_RATE * SOUND_CHUNKS;
sound_buffer = calloc(sound_buffer_size, sizeof(*sound_buffer));
if (!sound_buffer) {
- fprintf(stderr, "Failed to allocate image buffer\n");
+ print_error("Failed to allocate image buffer\n");
goto done;
}
/* allocate memory */
memory = calloc(MEMORY_SIZE, 1);
if (!memory) {
- fprintf(stderr, "Failed to allocate cpu's memory\n");
+ print_error("Failed to allocate cpu's memory\n");
goto done;
}
chipreg = calloc(IOSIZE, 1);
if (!chipreg) {
- fprintf(stderr, "Failed to allocate chip register\n");
+ print_error("Failed to allocate chip register\n");
goto done;
}
/* start cpu */
reset_cpu();
- printf("**********************************\n");
- printf("* Welcome to Mercenary Reloaded! *\n");
- printf("**********************************\n\n");
- printf("Press CTRL + cursor keys to select inventory or pickup/drop item.\n");
- printf("Press CTRL + f to toggle full screen.\n");
- printf("Press CTRL + s to toggle rendering speed.\n");
- printf("Press CTRL + v to toggle video filter.\n");
- printf("Press CTRL + a to toggle audio filter.\n");
- printf("Press CTRL + c to exit game.\n\n");
- printf("Use '--help' as command line option for configuration settings.\n\n");
+ print_info("**********************************\n");
+ print_info("* Welcome to Mercenary Reloaded! *\n");
+ print_info("**********************************\n\n");
+ print_info("Press CTRL + cursor keys to select inventory or pickup/drop item.\n");
+ print_info("Press CTRL + f to toggle full screen.\n");
+ print_info("Press CTRL + s to toggle rendering speed.\n");
+ print_info("Press CTRL + v to toggle video filter.\n");
+ print_info("Press CTRL + a to toggle audio filter.\n");
+ print_info("Press CTRL + c to exit game.\n\n");
+ print_info("Use '--help' as command line option for configuration settings.\n\n");
/* run game */
main_loop();
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include "../libsdl/print.h"
#include "../libcpu/m68k.h"
#include "../libcpu/execute.h"
#include "mercenary.h"
/* reduce loop that waits for disk stepper to move */
if (m68k_read_memory_32(0x55398) != 0x0000091b) {
- fprintf(stderr, "expecting loop counter of 0x0000091b here, please fix!\n");
+ print_error("expecting loop counter of 0x0000091b here, please fix!\n");
exit(0);
}
m68k_write_memory_32(0x55398, 1);
/* reduce loop that waits for disk side change */
if (m68k_read_memory_32(0x54ffc) != 0x00000d02) {
- fprintf(stderr, "expecting loop counter of 0x00000d02 here, please fix!\n");
+ print_error("expecting loop counter of 0x00000d02 here, please fix!\n");
exit(0);
}
m68k_write_memory_32(0x54ffc, 1);
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include "../libsdl/print.h"
#include "../libcpu/m68k.h"
#include "../libcpu/execute.h"
#include "mercenary.h"
/* reduce loop that waits for disk stepper to move */
if (m68k_read_memory_32(0x562f8) != 0x000091b0) {
- fprintf(stderr, "expecting loop counter of 0x000091b0 here, please fix!\n");
+ print_error("expecting loop counter of 0x000091b0 here, please fix!\n");
exit(0);
}
m68k_write_memory_32(0x562f8, 1);
/* reduce loop that waits for disk side change */
if (m68k_read_memory_32(0x55f5c) != 0x0000d020) {
- fprintf(stderr, "expecting loop counter of 0x0000d020 here, please fix!\n");
+ print_error("expecting loop counter of 0x0000d020 here, please fix!\n");
exit(0);
}
m68k_write_memory_32(0x55f5c, 1);