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

Merge next as master. #397

Merged
merged 7 commits into from
Feb 28, 2024
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
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
X-Emulators - aka "Xemu" - (C)2016-2023 LGB Gábor Lénárt [email protected]
X-Emulators - aka "Xemu" - (C)2016-2024 LGB Gábor Lénárt [email protected]

[ Xemu is licensed under the terms of GNU/GPL v2, for more information please read file LICENSE ]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Emulators running on Linux/Unix/Windows/OSX of various (mainly 8 bit) machines,
including the Commodore LCD and Commodore 65 and MEGA65 as well.

Written by (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Written by (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>
Source repository: https://github.com/lgblgblgb/xemu

Xemu also contains code wasn't written by me (sources I use from others,
Expand Down
17 changes: 15 additions & 2 deletions targets/mega65/cart.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "xemu/emutools.h"
#include "cart.h"
#include "xemu/emutools_files.h"
#include "audio65.h"

static Uint8 cart_mem[0x10000];
static int loaded = 0;
Expand All @@ -35,13 +36,25 @@ Uint8 cart_read_byte ( unsigned int addr )
Uint8 data = 0xFF;
if (addr < sizeof(cart_mem))
data = cart_mem[addr];
DEBUGPRINT("CART: reading byte ($%02X) at $%X" NL, data, addr + 0x4000000);
if (loaded && addr != 0x3FFDF60) // see the comment about OPL at cart_write_byte()
DEBUGPRINT("CART: reading byte ($%02X) at $%X" NL, data, addr + 0x4000000);
return data;
}


void cart_write_byte ( unsigned int addr, Uint8 data )
{
if (!loaded) {
// a hack OPL to be able to work in the "slow device area" [if no cartridge is loaded]
static Uint8 opl_reg_sel = 0;
if (addr == 0x3FFDF40) {
opl_reg_sel = data;
return;
} else if (addr == 0x3FFDF50) {
audio65_opl3_write(opl_reg_sel, data);
return;
}
}
DEBUGPRINT("CART: writing byte ($%02X) at $%X" NL, data, addr + 0x4000000);
}

Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/cart.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
5 changes: 3 additions & 2 deletions targets/mega65/configdb.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -76,6 +76,7 @@ static const struct xemutools_configdef_str_st str_options[] = {
{ "gui", NULL, "Select GUI type for usage. Specify some insane str to get a list", &configdb.selectedgui },
{ "importbas", NULL, "Import and RUN BASIC65 program from TEXT file", &configdb.importbas },
{ "cartbin8000",NULL, "Load binary cartridge image from $8000", &configdb.cartbin8000 },
{ "winpos", NULL, "Window position: x,y (integers)", &configdb.winpos },
{ NULL }
};

Expand Down Expand Up @@ -155,7 +156,7 @@ static const void *do_not_save_opts[] = {
&configdb.matrixstart,
&configdb.dumpmem, &configdb.dumpscreen, &configdb.screenshot_and_exit,
&configdb.testing, &configdb.hyperdebug, &configdb.hyperdebugfreezer, &configdb.usestubrom, &configdb.useinitrom, &configdb.useutilmenu,
&configdb.cartbin8000,
&configdb.cartbin8000, &configdb.winpos,
NULL
};

Expand Down
3 changes: 2 additions & 1 deletion targets/mega65/configdb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -115,6 +115,7 @@ struct configdb_st {
int fastboot;
int matrixstart;
int matrixdisable;
char *winpos;
};

extern struct configdb_st configdb;
Expand Down
89 changes: 75 additions & 14 deletions targets/mega65/matrix_mode.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -44,7 +44,7 @@ int in_the_matrix = 0;
// TODO: many inventions here eventlually should be moved into some common place as
// probably other emulators ("generic OSD console API"), and OSD GUI want to use them as well!

// TODO: some code here (Xemu specific matrix commands ...) should share interfade with
// TODO: some code here (Xemu specific matrix commands ...) should share interface with
// the uart_mon/umon, and in fact, that should be accessed from here, as on a real MEGA65!


Expand All @@ -65,7 +65,7 @@ int in_the_matrix = 0;
#define CLI_AREA_BYTE_SIZE ((chrscreen_ysize - CLI_START_LINE) * chrscreen_xsize * 2)
#define CLI_AREA_BYTE_OFFSET TOP_AREA_BYTE_SIZE

static const Uint8 console_colours[] = {
static Uint8 console_colours[] = {
0x00, 0x00, 0x00, 0x80, // 0: for background shade of the console
0x00, 0xFF, 0x00, 0xFF, // 1: normal green colour of the console text
0xFF, 0xFF, 0x00, 0xFF, // 2: alternative yellow colour of the console text
Expand Down Expand Up @@ -94,11 +94,19 @@ static unsigned int matrix_counter = 0;
static int live_update_enabled = 1;
static int blink_phase = 0; // used with flashing the cursor, etc
static int current_viewport = 0;
static int write_special_chars_mode = 0;


#define PARTIAL_OSD_TEXTURE_UPDATE


static void init_colour_mappings ( void )
{
for (unsigned int i = 0; i < sizeof(console_colours) / 4; i++)
colour_mappings[i] = SDL_MapRGBA(sdl_pix_fmt, console_colours[i * 4], console_colours[i * 4 + 1], console_colours[i * 4 + 2], console_colours[i * 4 + 3]);
}


static void matrix_update ( void )
{
if (!need_update)
Expand Down Expand Up @@ -186,6 +194,14 @@ static void matrix_write_char ( const Uint8 c )
} else if (c == 8) {
if (current_x > 0)
current_x--;
} else if (c == '{' && write_special_chars_mode) {
if (write_special_chars_mode == 2)
current_colour = BANNER_COLOUR;
return;
} else if (c == '}' && write_special_chars_mode) {
if (write_special_chars_mode == 2)
current_colour = NORMAL_COLOUR;
return;
} else {
write_char_raw(current_x, current_y, c, current_colour);
current_x++;
Expand Down Expand Up @@ -244,7 +260,7 @@ static inline void matrix_write_string ( const char *s )
static void dump_regs ( const char rot_fig )
{
const Uint8 pf = cpu65_get_pf();
MATRIX("PC:%04X A:%02X X:%02X Y:%02X Z:%02X SP:%04X B:%02X %c%c%c%c%c%c%c%c IO:%X (%c) %c %s %s ",
MATRIX("{PC}:%04X {A}:%02X {X}:%02X {Y}:%02X {Z}:%02X {SP}:%04X {B}:%02X %c%c%c%c%c%c%c%c {IO}:%X (%c) %c %s %s%c",
cpu65.pc, cpu65.a, cpu65.x, cpu65.y, cpu65.z,
cpu65.sphi + cpu65.s, cpu65.bphi >> 8,
(pf & CPU65_PF_N) ? 'N' : 'n',
Expand All @@ -259,11 +275,22 @@ static void dump_regs ( const char rot_fig )
in_hypervisor ? 'H' : 'U',
rot_fig,
videostd_id ? "NTSC" : "PAL ",
cpu_clock_speed_string
cpu_clock_speed_string,
(D6XX_registers[0x7D] & 16) ? '!' : ' '
);
}


static void dump_map ( void )
{
char desc[10];
for (unsigned int i = 0; i < 16; i++) {
mem_get_4k_region_short_desc(desc, sizeof desc, i);
MATRIX("{%X:}%7s%c", i, desc, (i & 7) == 7 ? ' ' : '|');
}
}


/* COMMANDS */


Expand All @@ -281,21 +308,35 @@ static void cmd_uname ( char *p )

static void cmd_ver ( char *p )
{
MATRIX("Xemu/%s %s %s %s %s %s\n", TARGET_DESC, XEMU_BUILDINFO_CDATE, XEMU_BUILDINFO_GIT, XEMU_BUILDINFO_ON, XEMU_BUILDINFO_AT, XEMU_BUILDINFO_CC);
MATRIX("SDL base dir: %s\n", sdl_base_dir);
MATRIX("SDL pref dir: %s\n", sdl_pref_dir);
matrix_write_string("Command line: ");
MATRIX(
"Xemu/%s %s %s %s %s %s\n"
"SDL base dir: %s\n"
"SDL pref dir: %s\n"
"Command line:",
TARGET_DESC, XEMU_BUILDINFO_CDATE, XEMU_BUILDINFO_GIT, XEMU_BUILDINFO_ON, XEMU_BUILDINFO_AT, XEMU_BUILDINFO_CC,
sdl_base_dir,
sdl_pref_dir
);
for (int i = 0; i < xemu_initial_argc; i++) {
if (i)
matrix_write_string(" ");
matrix_write_char(' ');
matrix_write_string(xemu_initial_argv[i]);
}
}


static void cmd_reg ( char *p )
{
write_special_chars_mode = 1;
dump_regs(' ');
write_special_chars_mode = 0;
}


static void cmd_map ( char *arg )
{
write_special_chars_mode = 1;
dump_map();
write_special_chars_mode = 0;
}


Expand Down Expand Up @@ -525,6 +566,18 @@ static void cmd_reset ( char *p )
}


static void cmd_shade ( char *p )
{
unsigned int shade;
if (sscanf(p, "%u", &shade) == 1 && shade <= 100) {
console_colours[3] = shade * 255 / 100;
need_update = 1 | 2;
init_colour_mappings();
} else
MATRIX("?BAD VALUE");
}


static void cmd_help ( char *p );


Expand All @@ -545,6 +598,8 @@ static const struct command_tab_st {
{ "uname", cmd_uname, NULL },
{ "ver", cmd_ver, NULL },
{ "write", cmd_write, "w" },
{ "map", cmd_map, "m" },
{ "shade", cmd_shade, NULL },
{ .cmdname = NULL },
};

Expand Down Expand Up @@ -656,8 +711,15 @@ static void matrix_updater_callback ( void )
const int saved_x = current_x, saved_y = current_y;
current_x = 0;
current_y = 1;
write_special_chars_mode = 2;
static const char rotator[4] = { '-', '\\', '|', '/' };
dump_regs(rotator[(matrix_counter >> 3) & 3]);
// make sure the rest of the line is cleared (the regs line length can vary in size!), also position for the next line for the map dump
while (current_x)
matrix_write_char(' ');
dump_map();
current_colour = NORMAL_COLOUR;
write_special_chars_mode = 0;
if (live_update_enabled)
live_dump_update();
current_x = saved_x;
Expand Down Expand Up @@ -742,8 +804,7 @@ void matrix_mode_toggle ( int status )
osd_hijack(matrix_updater_callback, &backend_xsize, &backend_ysize, &backend_pixels);
if (!init_done) {
init_done = 1;
for (int i = 0; i < sizeof(console_colours) / 4; i++)
colour_mappings[i] = SDL_MapRGBA(sdl_pix_fmt, console_colours[i * 4], console_colours[i * 4 + 1], console_colours[i * 4 + 2], console_colours[i * 4 + 3]);
init_colour_mappings();
chrscreen_xsize = backend_xsize / 8;
chrscreen_ysize = backend_ysize / 8;
vmem = xemu_malloc(FULL_SCREEN_BYTE_SIZE);
Expand All @@ -757,7 +818,7 @@ void matrix_mode_toggle ( int status )
matrix_clear();
memcpy(vmem_prev, vmem + CLI_AREA_BYTE_OFFSET, CLI_AREA_BYTE_SIZE);
current_colour = BANNER_COLOUR;
static const char banner_msg[] = "*** Xemu's pre-matrix ... press left-CTRL + TAB to exit ***";
static const char banner_msg[] = "*** Xemu's pre-matrix ... press left-CTRL + TAB to exit / re-enter ***";
current_x = (chrscreen_xsize - strlen(banner_msg)) >> 1;
matrix_write_string(banner_msg);
current_colour = NORMAL_COLOUR;
Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/matrix_mode.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore-65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2022 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
15 changes: 13 additions & 2 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2016-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2016-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -420,6 +420,13 @@ static void mega65_init ( void )
cia2_setint_cb // callback: SETINT ~ that would be NMI in our case
);
cia2.DDRA = 3; // Ugly workaround ... I think, SD-card setup "CRAM UTIL" (or better: Hyppo) should set this by its own. Maybe Xemu bug, maybe not?
// These are workarounds, newer ROMs seems to fail to finish initialization without these, see here:
// https://github.com/lgblgblgb/xemu/issues/395
// This workaround is surely not fully correct, but seems to solve the issue to allow newer ROMs to start at least.
cia1.TLAL = 1;
cia1.TLAH = 1;
cia2.TLAL = 1;
cia2.TLAH = 1;
// *** Initialize DMA (we rely on memory and I/O decoder provided functions here for the purpose)
dma_init();
#ifdef HAS_UARTMON_SUPPORT
Expand Down Expand Up @@ -564,12 +571,15 @@ void m65mon_show_regs ( void )
{
Uint8 pf = cpu65_get_pf();
umon_printf(
"\r\n"
"PC A X Y Z B SP MAPL MAPH LAST-OP P P-FLAGS RGP uS IO\r\n"
"%04X %02X %02X %02X %02X %02X %04X " // register banned message and things from PC to SP
"%04X %04X %02X %02X %02X " // from MAPL to P
"%c%c%c%c%c%c%c%c ", // P-FLAGS
cpu65.pc, cpu65.a, cpu65.x, cpu65.y, cpu65.z, cpu65.bphi >> 8, cpu65.sphi | cpu65.s,
map_offset_low >> 8, map_offset_high >> 8, cpu65.op,
((map_mask & 0x0F) << 12) | (map_offset_low >> 8),
((map_mask & 0xF0) << 8) | (map_offset_high >> 8),
cpu65.op,
pf, 0, // flags
(pf & CPU65_PF_N) ? 'N' : '-',
(pf & CPU65_PF_V) ? 'V' : '-',
Expand Down Expand Up @@ -818,6 +828,7 @@ int main ( int argc, char **argv )
xemu_set_installer(configdb.installer);
#endif
/* Initiailize SDL - note, it must be before loading ROMs, as it depends on path info from SDL! */
xemu_set_default_win_pos_from_string(configdb.winpos);
window_title_info_addon = emulator_speed_title;
if (xemu_post_init(
TARGET_DESC APP_DESC_APPEND, // window title
Expand Down
21 changes: 20 additions & 1 deletion targets/mega65/memory_mapper.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* A work-in-progess MEGA65 (Commodore 65 clone origins) emulator
Part of the Xemu project, please visit: https://github.com/lgblgblgb/xemu
Copyright (C)2017-2023 LGB (Gábor Lénárt) <[email protected]>
Copyright (C)2017-2024 LGB (Gábor Lénárt) <[email protected]>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -733,6 +733,25 @@ static void apply_cpu_io_port_config ( void )
}


unsigned int mem_get_4k_region_short_desc ( char *p, const unsigned int n, const unsigned int i )
{
if (map_mask & (1 << (i >> 1)))
return snprintf(p, n, "%X", (i & 8 ? map_megabyte_high : map_megabyte_low) + (((i & 8 ? map_offset_high : map_offset_low) + (i << 12)) & 0xFFFFF));
else if ((i == 0x8 || i == 0x9) && (vic_registers[0x30] & 8))
return snprintf(p, n, "ROM8000");
else if ((i == 0xA || i == 0xB) && ((vic_registers[0x30] & 16) || memcfg_cpu_io_port_last == 3 || memcfg_cpu_io_port_last == 7))
return snprintf(p, n, "BASIC");
else if ((i == 0xC ) && (vic_registers[0x30] & 32))
return snprintf(p, n, "ROMC000");
else if ((i == 0xD ) && (memcfg_cpu_io_port_last == 1 || memcfg_cpu_io_port_last == 2 || memcfg_cpu_io_port_last == 3))
return snprintf(p, n, "CHARGEN");
else if ( i == 0xD && memcfg_cpu_io_port_last >= 5)
return snprintf(p, n, "IO");
else if ((i == 0xE || i == 0xF) && ((vic_registers[0x30] & 128) || memcfg_cpu_io_port_last == 2 || memcfg_cpu_io_port_last == 3 || memcfg_cpu_io_port_last == 6 || memcfg_cpu_io_port_last == 7))
return snprintf(p, n, "KERNAL");
return snprintf(p, n, "unmap");
}


// must be called on CPU I/O port write, addr=0/1 for DDR/DATA
// do not call with other addr than 0/1!
Expand Down
Loading