Skip to content

Commit

Permalink
MEGA65: hwerrata register initial support
Browse files Browse the repository at this point in the history
sync with next:

	dae4fa2

Author: LGB (Gabor Lenart) <[email protected]>
Date:   Fri Sep 20 23:19:17 2024 +0200

    MEGA65: hwerrata register initial support #414

    * Basic HWERRATA and VIC BUGCOMPAT bit support
    * Rudimentary X scroll register offset fix support from level 1 and up
    * But NO support yet for char attribute fix at level 2
  • Loading branch information
lgblgblgb committed Oct 22, 2024
1 parent ef9be42 commit 5748566
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
5 changes: 3 additions & 2 deletions targets/mega65/io_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ void set_hw_errata_level ( const Uint8 desired_level, const char *reason )
const Uint8 level = desired_level > HW_ERRATA_MAX_LEVEL ? HW_ERRATA_MAX_LEVEL : desired_level;
if (level == desired_level && level == hw_errata_level)
return;
DEBUGPRINT("HW_ERRATA: $%02X -> $%02X (wanted: $%02X) [%s]" NL, hw_errata_level, level, desired_level, reason);
DEBUGPRINT("HW_ERRATA: %u -> %u (wanted: %u, xemu-max: %u) [%s]" NL, hw_errata_level, level, desired_level, HW_ERRATA_MAX_LEVEL, reason);
if (level == hw_errata_level)
return;
hw_errata_level = level;
// TODO: the actual work should go here, setting various bug stuff variables based on "level"
// --- Do the actual work, set things based on the new hardware errata level:
vic4_set_errata_level(level);
}


Expand Down
4 changes: 2 additions & 2 deletions targets/mega65/io_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

#include "xemu/cia6526.h"

// Hardware errata level what Xemu supports at max. TODO: currently: *NONE*
#define HW_ERRATA_MAX_LEVEL 0
// Hardware errata level what Xemu supports at max.
#define HW_ERRATA_MAX_LEVEL 2

// Default HW_ERRATA_RESET_LEVEL when calling reset_hw_errata_level()
#define HW_ERRATA_RESET_LEVEL 0
Expand Down
23 changes: 20 additions & 3 deletions targets/mega65/vic4.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ static int EFFECTIVE_V400;
static Uint8 sprite_is_being_rendered[8];
#warning "Sprite coordinate latching is an experimental feature (SPRITE_COORD_LATCHING is defined)!"
#endif
static Uint8 bug_compat_vic_iii_d016_delta = 2;
static bool bug_compat_char_attr = true;

// --- these things are altered by vic4_open_frame_access() ONLY at every fame ONLY based on PAL or NTSC selection
Uint8 videostd_id = 0xFF; // 0=PAL, 1=NTSC [give some insane value by default to force the change at the fist frame after starting Xemu]
Expand Down Expand Up @@ -308,7 +310,7 @@ static void vic4_update_sideborder_dimensions ( void )
}


static void vic4_update_vertical_borders( void )
static void vic4_update_vertical_borders ( void )
{
// FIXME: it seems we need this line here! Otherwise EFFECTIVE_V400 may not reflect what
// it should be, if just updated in vic4_open_frame_access(). This seems to fix the OpenROMs
Expand All @@ -319,12 +321,12 @@ static void vic4_update_vertical_borders( void )
if (!REG_H640)
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL));
else // 80-col mode
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL) - 2);
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL) - bug_compat_vic_iii_d016_delta);
} else { // 38-columns
if (!REG_H640)
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL));
else // 78-col mode
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL) - 2);
SET_CHARGEN_X_START(FRAME_H_FRONT + SINGLE_SIDE_BORDER + (2 * REG_VIC2_XSCROLL) - bug_compat_vic_iii_d016_delta);
}
if (!EFFECTIVE_V400) { // Standard mode (200-lines)
display_row_count = 24;
Expand Down Expand Up @@ -354,6 +356,21 @@ static void vic4_update_vertical_borders( void )
}


// Called from set_hw_errata_level() in io_mapper.c
void vic4_set_errata_level ( const Uint8 level )
{
static Uint8 old_bug_compat_vic_iii_d016_delta = 2;
bug_compat_vic_iii_d016_delta = level > 0 ? 0 : 2; // if level > 0, no delta, if level == 0 then delta = 2 (VIC-III/C65 "buggy" default)
bug_compat_char_attr = level > 1 ? false : true;
DEBUGPRINT("VIC: errata level is set %u: d016_delta=%u, char_attr_buggy=%u" NL, level, bug_compat_vic_iii_d016_delta, bug_compat_char_attr);
if (bug_compat_vic_iii_d016_delta != old_bug_compat_vic_iii_d016_delta) {
old_bug_compat_vic_iii_d016_delta = bug_compat_vic_iii_d016_delta;
if (REG_HOTREG)
vic4_update_vertical_borders(); // so "bug_compat_vic_iii_d016_delta" will have effect ... However maybe this is FIXME in case of hot-register issue (?)
}
}


static void vic4_interpret_legacy_mode_registers ( void )
{
// See https://github.com/MEGA65/mega65-core/blob/257d78aa6a21638cb0120fd34bc0e6ab11adfd7c/src/vhdl/viciv.vhdl#L1277
Expand Down
1 change: 1 addition & 0 deletions targets/mega65/vic4.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ extern int vic4_render_scanline ( void );
extern void vic4_open_frame_access ( void );
extern void vic4_close_frame_access ( void );
extern void vic4_set_videostd ( const int mode, const char *comment );
extern void vic4_set_errata_level ( const Uint8 level );

extern Uint8*vic4_query_screen_address ( void );
extern Uint8*vic4_query_colour_address ( void );
Expand Down

0 comments on commit 5748566

Please sign in to comment.