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

MEGA65: Add nybl16 colour mode #239

Merged
merged 7 commits into from
Apr 15, 2021
Merged
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
48 changes: 31 additions & 17 deletions targets/mega65/vic4.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ static void vic4_update_sideborder_dimensions ( void )
else // 78-col mode
border_x_left = FRAME_H_FRONT + SINGLE_SIDE_BORDER + 15;
}
DEBUGPRINT("VIC4: set border left=%d, right=%d, textxpos=%d" NL, border_x_left, border_x_right, CHARGEN_X_START);
}


static void vic4_update_vertical_borders( void )
{
if (REG_CSEL) { // 40-columns?
Expand Down Expand Up @@ -290,9 +292,12 @@ static void vic4_update_vertical_borders( void )
display_row_count = 24*2;
}
SET_CHARGEN_Y_START(RASTER_CORRECTION + SINGLE_TOP_BORDER_400 - (2 * vicii_first_raster) - 6 + (REG_VIC2_YSCROLL * 2));
}
}
DEBUGPRINT("VIC4: set border top=%d, bottom=%d, textypos=%d, display_row_count=%d vic_ii_first_raster=%d" NL, BORDER_Y_TOP, BORDER_Y_BOTTOM,
CHARGEN_Y_START, display_row_count, vicii_first_raster);
}


static void vic4_interpret_legacy_mode_registers ( void )
{
// See https://github.com/MEGA65/mega65-core/blob/257d78aa6a21638cb0120fd34bc0e6ab11adfd7c/src/vhdl/viciv.vhdl#L1277
Expand Down Expand Up @@ -320,19 +325,13 @@ static void vic4_interpret_legacy_mode_registers ( void )
REG_CHARPTR_B1 = (~last_dd00_bits << 6) | (REG_CHARPTR_B1 & 0x3F);

SET_COLORRAM_BASE(0);
DEBUGPRINT(
"VIC4: 16bit=%d, chrcount=%d, charstep=%d bytes, charscale=%d, vic_ii_first_raster=%d, ras_src=%d, "
"border yt=%d, yb=%d, xl=%d, xr=%d, textxpos=%d, textypos=%d, "
DEBUGPRINT("VIC4: 16bit=%d, chrcount=%d, charstep=%d bytes, charxscale=%d, ras_src=%d "
"screen_ram=$%06x, charset/bitmap=$%06x, sprite=$%06x" NL,
REG_16BITCHARSET, REG_CHRCOUNT, CHARSTEP_BYTES, REG_CHARXSCALE,
vicii_first_raster, REG_FNRST, BORDER_Y_TOP, BORDER_Y_BOTTOM, border_x_left, border_x_right, CHARGEN_X_START, CHARGEN_Y_START,
SCREEN_ADDR, CHARSET_ADDR, SPRITE_POINTER_ADDR
);
REG_16BITCHARSET, REG_CHRCOUNT, CHARSTEP_BYTES, REG_CHARXSCALE,
REG_FNRST, SCREEN_ADDR, CHARSET_ADDR, SPRITE_POINTER_ADDR);
}




// Must be called before using the texture at all, otherwise crash will happen, or nothing at all.
// Access must be closed with vic4_close_frame_access().
// Do NOT call this function from vic4.c! It must be used by the emulator's main loop!
Expand Down Expand Up @@ -375,6 +374,11 @@ void vic4_open_frame_access ( void )
DEBUGPRINT("VIC: switching video standard from %s to %s (1MHz line cycle count is %f, frame time is %dusec, max raster is %d, visible area height is %d)" NL, videostd_name, new_name, videostd_1mhz_cycles_per_scanline, videostd_frametime, max_rasters, visible_area_height);
videostd_name = new_name;
vic_readjust_sdl_viewport = 1;
vicii_first_raster = vic_registers[0x6F] & 0x1F;
if (!in_hypervisor) {
vic4_update_sideborder_dimensions();
vic4_update_vertical_borders();
}
}
// handle this via vic_readjust_sdl_viewport variable (not directly above) so external stuff (like UI) can also
// force to adjust viewport, not just the PAL/NTSC change itself (ie: fullborder/clipped border change)
Expand All @@ -385,12 +389,6 @@ void vic4_open_frame_access ( void )
else
xemu_set_viewport(48, 0, TEXTURE_WIDTH - 48, visible_area_height - 1, XEMU_VIEWPORT_ADJUST_LOGICAL_SIZE);
}

vicii_first_raster = vic_registers[0x6F] & 0x1F;
if (!in_hypervisor) {
vic4_update_sideborder_dimensions();
vic4_update_vertical_borders();
}
}


Expand Down Expand Up @@ -1065,6 +1063,22 @@ static void vic4_render_fullcolor_char_row ( const Uint8* char_row, int glyph_wi
}


Copy link
Owner

@lgblgblgb lgblgblgb Apr 15, 2021

Choose a reason for hiding this comment

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

Sorry for the question again, just make it clear :) So the part after this comment ( https://github.com/lgblgblgb/xemu/pull/239/files/55e202c05494a99e4b5bedca17b6145ed6dbe3a2#r614328716 ) looks like what I expected. What about the changes before? Are those really intended? I can't see it's connected to the implementation of the nybl mode video. Sorry for the so much confusion here, this turned out to be a very strange situation though the change itself for nybl mode is not so complex or anything in its own ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the file history, that comments were suited for better debugging the NTSC/PAL mode change.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes but the !in_hypervisor again changed position what I worry for, but if you say it's intended that way, of course I believe you ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's the correct position -- may be the performance regression was due to this? e.g: recalculating modes on every frame access. The regressed output should have a lot of VIC4: border top=xxx etc.

// 16-color (Nybl) mode (4-bit per pixel / 16 pixel wide characters)
static void vic4_render_16color_char_row ( const Uint8* char_row, int glyph_width )
{
for (float cx = 0; cx < glyph_width && xcounter < border_x_right; cx += char_x_step) {
Uint8 char_data = char_row[((int)cx) / 2];
if (((int)cx) & 1)
char_data >>= 4;
else
char_data &= 0xf;
Uint32 pixel_color = palette[char_data];
*(current_pixel++) = pixel_color;
bg_pixel_state[xcounter++] = pixel_color ? FOREGROUND_PIXEL : BACKGROUND_PIXEL;
}
}


// Render a bitplane-mode character cell row
static void vic4_render_bitplane_char_row ( Uint8* bp_base[8], int glyph_width )
{
Expand Down Expand Up @@ -1196,7 +1210,7 @@ void vic4_render_char_raster ( void )
char_byte = reverse_byte_table[char_byte]; // LGB: I killed the function, and type-conv, as char_byte is byte, OK to index as-is
// Render character cell row
if (SXA_4BIT_PER_PIXEL(color_data)) { // 16-color character
// FIXME: TODO??
vic4_render_16color_char_row(main_ram + (((char_id * 64) + (sel_char_row * 8) ) & 0x7FFFF), glyph_width);
} else if (CHAR_IS256_COLOR(char_id)) { // 256-color character
vic4_render_fullcolor_char_row(main_ram + (((char_id * 64) + (sel_char_row * 8) ) & 0x7FFFF), 8);
} else if ((REG_MCM && (char_fgcolor & 8)) || (REG_MCM && REG_BMM)) { // Multicolor character
Expand Down