Skip to content

Commit

Permalink
Add raster_skip option to cmdline.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
randyrossi committed Feb 15, 2020
1 parent 339958d commit 492790c
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 19 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ NOTE: This mode has a 15khz horizontal refresh rate which many monitors don't su

Many thanks goes out to Alessio Scanderebech and Andrea Mazzoleni for their assistance with getting this working.

# VGA Display without 15khz hsync support

If you have a VGA monitor that doesn't support 15khz hsync, you can try using a 1920x1080 resolution and add raster_skip=true to the machine config. The 'raster_skip' option doubles the vertical height of the frame buffer and draws the emulated display into every other line. When this is integer scaled up to 1080, you can achieve more or less the same effect you would get with a monitor that could do 15khz. That is, there will be gaps between each 'scanline' as though there were only ~270 lines. This looks pretty decent on a Trinitron tube because there are no horizontal gaps in the phosphor bars and the 2 real scanlines that resulted from doubling the one line from the frame buffer looks like one solid scanline (...at least that's what I think is happening)

[C64/PAL/DPI/VGA666:1920x1080@50hz]
enable_dpi=true
machine_timing=pal-custom
cycles_per_second=985257
enable_dpi_lcd=1
display_default_lcd=1
dpi_group=1
dpi_mode=31
raster_skip=true
scaling_params=1920,540,1920,1080

# Video Scaling Algorithm

The emulated resolutions are small and must be scaled up to the video mode's resolution. You can tell the Pi to change the way it scales the video using the 'scaling_kernel' option in config.txt:
Expand Down
4 changes: 3 additions & 1 deletion emulatorcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
#ifndef emualtorcore_h
#define emulatorcore_h

#include "viceoptions.h"

class EmulatorCore {
public:
EmulatorCore(void) = default;
~EmulatorCore(void) = default;

virtual bool Init() = 0;
virtual bool Init(ViceOptions *options) = 0;
virtual void LaunchEmulator(char *timing_option) = 0;
};

Expand Down
5 changes: 3 additions & 2 deletions plus4emulatorcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Plus4EmulatorCore::RunMainPlus4(bool wait) {
printf("Starting emulator main loop\n");
int argc = 0;
char *argv[] = {};
emu_machine_init();
emu_machine_init(m_options->GetRasterSkip());
main_program(argc, argv);
emu_exit();
}
Expand Down Expand Up @@ -89,7 +89,8 @@ void Plus4EmulatorCore::Run(unsigned nCore) {
#endif
}

bool Plus4EmulatorCore::Init(void) {
bool Plus4EmulatorCore::Init(ViceOptions* options) {
m_options = options;
return Initialize();
}

Expand Down
3 changes: 2 additions & 1 deletion plus4emulatorcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ class Plus4EmulatorCore
bool Initialize() { return true; }
#endif

bool Init(void) override;
bool Init(ViceOptions* options) override;
void LaunchEmulator(char *timing_option) override;

private:
bool launch_;
int cyclesPerSecond_;
char timing_option_[8];
CSpinLock m_Lock;
ViceOptions *m_options;

void RunMainPlus4(bool wait);
void ComputeResidFilter(int model);
Expand Down
2 changes: 1 addition & 1 deletion third_party/common/circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ extern void circle_set_interpolation(int enable);

// Init some common layer stuff about the machine being emulated.
// Must be called before launching emulator's main_program func.
extern void emu_machine_init(void);
extern void emu_machine_init(int raster_skip_enabled);

// Compares the previous button state for 'button_num' with
// the current state and will return a press or release event
Expand Down
15 changes: 14 additions & 1 deletion third_party/common/menu_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct s_cfg_flags {
int have_enable_dpi;
int have_scaling_params;
int have_scaling_params2;
int have_raster_skip;

// Have flags for config.txt
int have_kernel;
Expand Down Expand Up @@ -278,7 +279,8 @@ void free_machines(struct machine_entry* head) {
}
}

static struct machine_option* find_option(char *key, struct machine_option *head) {
static struct machine_option* find_option(const char *key,
struct machine_option *head) {
struct machine_option* opt = head;
while (opt) {
if(strcmp(opt->key, key) == 0) {
Expand Down Expand Up @@ -441,6 +443,7 @@ static int apply_override_m(char *line, struct machine_entry *head,
if (strcmp(key,"enable_dpi") == 0) { cfg_flags->have_enable_dpi = 1; }
if (strcmp(key,"scaling_params") == 0) { cfg_flags->have_scaling_params = 1; }
if (strcmp(key,"scaling_params2") == 0) { cfg_flags->have_scaling_params2 = 1; }
if (strcmp(key,"raster_skip") == 0) { cfg_flags->have_raster_skip = 1; }

struct machine_option* found = find_option(key, head->options);
if (found) {
Expand All @@ -458,6 +461,7 @@ static int apply_override_m(char *line, struct machine_entry *head,
strcmp(key,"audio_out")!=0 &&
strcmp(key,"disk_partition")!=0 &&
strcmp(key,"enable_dpi")!=0 &&
strcmp(key,"raster_skip")!=0 &&
strcmp(key,"scaling_params")!=0 &&
strcmp(key,"scaling_params2")!=0) {
if (need_space) { strcat(replacement," "); }
Expand Down Expand Up @@ -552,6 +556,15 @@ static int apply_override_m(char *line, struct machine_entry *head,
need_space=1;
}
}
if (!cfg_flags->have_raster_skip) {
struct machine_option* found = find_option("raster_skip", head->options);
if (found) {
if (need_space) { strcat(replacement," "); }
snprintf(new_option, OPTION_SCRATCH_LEN, "%s=%s", found->key, found->value);
strcat(replacement, new_option);
need_space=1;
}
}

strcat(replacement, "\n");
strcpy(line, replacement);
Expand Down
10 changes: 8 additions & 2 deletions third_party/plus4emu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int color_brightness = 1000;
int color_contrast = 666;
int color_gamma = 800;
int color_tint = 1000;
int raster_skip = 1; // Never going to change.
int raster_skip = 1;

static struct menu_item *sid_model_item;
static struct menu_item *sid_write_access_item;
Expand Down Expand Up @@ -784,8 +784,14 @@ int main_program(int argc, char **argv)

// Begin emu_api impl.

void emu_machine_init() {
void emu_machine_init(int raster_skip_enabled) {
emux_machine_class = BMC64_MACHINE_CLASS_PLUS4EMU;

raster_skip = raster_skip_enabled ? 2 : 1;

// For plus4emu, raster_skip can't be turned off
// at runtime. There's no line dupe like in our
// VICE mod.
}

void emux_trap_main_loop_ui(void) {
Expand Down
9 changes: 6 additions & 3 deletions third_party/vice-3.3/src/arch/raspi/vice_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static void check_sid_options() {
}
}

void emu_machine_init(void) {
void emu_machine_init(int raster_skip_enabled) {
switch (machine_class) {
case VICE_MACHINE_C64:
emux_machine_class = BMC64_MACHINE_CLASS_C64;
Expand Down Expand Up @@ -160,9 +160,12 @@ void emu_machine_init(void) {
// frame buffer so we can do our 'cheap' scanlines effect.
canvas_state[VIC_INDEX].raster_skip = 2;
} else {
canvas_state[VIC_INDEX].raster_skip = 1;
canvas_state[VDC_INDEX].raster_skip = 1;
canvas_state[VIC_INDEX].raster_skip = raster_skip_enabled ? 2 : 1;
canvas_state[VDC_INDEX].raster_skip = raster_skip_enabled ? 2 : 1;
}

// If raster skip enabled via kernel params, enable lines.
set_raster_lines(raster_skip_enabled);
}

static int vice_keymap_index_to_bmc(int value) {
Expand Down
16 changes: 15 additions & 1 deletion third_party/vice-3.3/src/arch/raspi/videoarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,15 @@ const unsigned long video_tick_inc = 10000;
unsigned long video_freq;
unsigned long video_frame_count;

int raspi_warp = 0;
int raspi_warp;
static int raspi_boot_warp = 1;

static int vdc_map[] = {0, 12, 6, 14, 5, 13, 11, 3, 2, 10, 8, 4, 9, 7, 15, 1};

// Should be set only when raster_skip=true is present
// in the kernel args.
int raster_lines;

#define COLOR16(r,g,b) (((r)>>3)<<11 | ((g)>>2)<<5 | (b)>>3)

int is_vic(struct video_canvas_s *canvas) {
Expand Down Expand Up @@ -179,6 +183,9 @@ static void check_dimensions(struct video_canvas_s* canvas,

canvas_state[canvas_index].max_padding_w = max_padding_w;
canvas_state[canvas_index].max_padding_h = max_padding_h;

// If config says raster lines, do it here.
canvas->raster_lines |= raster_lines;
}

// Draw buffer bridge functions back to kernel
Expand Down Expand Up @@ -496,3 +503,10 @@ palette_t *raspi_video_load_palette(int num_entries, char *name) {
}
return palette;
}

void set_raster_lines(int v) {
vic_canvas->raster_lines = v;
if (vdc_canvas) {
vdc_canvas->raster_lines = v;
}
}
1 change: 1 addition & 0 deletions third_party/vice-3.3/src/arch/raspi/videoarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ void main_exit(void);
// holding the lock.
void key_interrupt_locked(long key, int pressed);

void set_raster_lines(int v);
#endif
2 changes: 1 addition & 1 deletion viceapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool ViceScreenApp::Initialize(void) {
}
}

if (!mEmulatorCore->Init()) {
if (!mEmulatorCore->Init(&mViceOptions)) {
return false;
}

Expand Down
5 changes: 3 additions & 2 deletions viceemulatorcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void ViceEmulatorCore::RunMainVice(bool wait) {
#else
#error "RASPI_[model] NOT DEFINED"
#endif
emu_machine_init();
emu_machine_init(m_options->GetRasterSkip());
main_program(argc, argv);
emu_exit();
}
Expand Down Expand Up @@ -213,7 +213,8 @@ void ViceEmulatorCore::Run(unsigned nCore) {
#endif
}

bool ViceEmulatorCore::Init(void) {
bool ViceEmulatorCore::Init(ViceOptions* options) {
m_options = options;
return Initialize();
}

Expand Down
3 changes: 2 additions & 1 deletion viceemulatorcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ViceEmulatorCore
bool Initialize() { return true; }
#endif

bool Init(void) override;
bool Init(ViceOptions* options) override;
void LaunchEmulator(char *timing_option) override;

private:
Expand All @@ -54,6 +54,7 @@ class ViceEmulatorCore
int passBandFreq_;
char timing_option_[8];
CSpinLock m_Lock;
ViceOptions *m_options;

void RunMainVice(bool wait);
void ComputeResidFilter(int model);
Expand Down
13 changes: 11 additions & 2 deletions viceoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ ViceOptions::ViceOptions(void)
m_bGPIOOutputsEnabled(false), m_nCyclesPerSecond(0),
m_audioOut(VCHIQSoundDestinationAuto), m_bDPIEnabled(false),
m_scaling_param_fbw{0,0}, m_scaling_param_fbh{0,0},
m_scaling_param_sx{0,0}, m_scaling_param_sy{0,0} {
m_scaling_param_sx{0,0}, m_scaling_param_sy{0,0},
m_raster_skip(false) {
s_pThis = this;

CBcmPropertyTags Tags;
Expand Down Expand Up @@ -140,6 +141,12 @@ ViceOptions::ViceOptions(void)
m_scaling_param_fbh[num] = atoi(fbh_s);
m_scaling_param_sx[num] = atoi(sx_s);
m_scaling_param_sy[num] = atoi(sy_s);
} else if (strcmp(pOption, "raster_skip") == 0) {
if (strcmp(pValue, "true") == 0 || strcmp(pValue, "1") == 0) {
m_raster_skip = true;
} else {
m_raster_skip = false;
}
}
}

Expand Down Expand Up @@ -186,7 +193,7 @@ bool ViceOptions::DPIEnabled(void) const { return m_bDPIEnabled; }

int ViceOptions::GetDiskPartition(void) const { return m_disk_partition; }

void ViceOptions::GetScalingParams(int display, int *fbw, int *fbh, int *sx, int *sy) {
void ViceOptions::GetScalingParams(int display, int *fbw, int *fbh, int *sx, int *sy) const {
if (display >=0 && display < 2) {
*fbw = m_scaling_param_fbw[display];
*fbh = m_scaling_param_fbh[display];
Expand All @@ -195,6 +202,8 @@ void ViceOptions::GetScalingParams(int display, int *fbw, int *fbh, int *sx, int
}
}

bool ViceOptions::GetRasterSkip(void) const { return m_raster_skip; }

const char *ViceOptions::GetDiskVolume(void) const { return m_disk_volume; }

unsigned long ViceOptions::GetCyclesPerSecond(void) const {
Expand Down
4 changes: 3 additions & 1 deletion viceoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class ViceOptions {
unsigned long GetCyclesPerSecond(void) const;
TVCHIQSoundDestination GetAudioOut(void) const;
bool DPIEnabled(void) const;
void GetScalingParams(int display, int *fbw, int *fbh, int *sx, int *sy);
void GetScalingParams(int display, int *fbw, int *fbh, int *sx, int *sy) const;
bool GetRasterSkip(void) const;

static ViceOptions *Get(void);

Expand Down Expand Up @@ -67,6 +68,7 @@ class ViceOptions {
int m_scaling_param_fbh[2];
int m_scaling_param_sx[2];
int m_scaling_param_sy[2];
bool m_raster_skip;

static ViceOptions *s_pThis;
};
Expand Down

0 comments on commit 492790c

Please sign in to comment.