From 64a4bb69c0387fad448a648c823c447751f0475f Mon Sep 17 00:00:00 2001 From: Eugene Lozovoy Date: Wed, 10 Jan 2024 15:39:07 +0300 Subject: [PATCH] add auto cpu frequency When this feature enabled: * Frequency sets to 14MHz on esxdos activity - for fastest loading from sd card; * Frequency sets to 14MHz on 48 BASIC startup; * Frequency sets to 3.5MHz within ~1ms after #FE port access - this allows to load from tape within turbo mode. Also this improves beeper sound effects; * Otherwise user configured frequency is used. --- fpga/rtl/magic.sv | 43 ++++++++++++++++++++++++++++++++++++-- fpga/rtl/top.sv | 2 ++ rom_src/config.asm | 2 ++ rom_src/menu_structure.asm | 19 +++++++++++++++++ rom_src/strings.asm | 1 + 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/fpga/rtl/magic.sv b/fpga/rtl/magic.sv index 171927c..9134a79 100755 --- a/fpga/rtl/magic.sv +++ b/fpga/rtl/magic.sv @@ -2,6 +2,7 @@ import common::*; module magic( input rst_n, input clk28, + input ck35, cpu_bus bus, output [7:0] d_out, @@ -14,6 +15,7 @@ module magic( input magic_button, input pause_button, input div_paged, + input basic48_paged, output reg magic_mode, output reg magic_map, @@ -74,13 +76,15 @@ end /* MAGIC CONFIG */ +turbo_t turbo0; +reg autoturbo_en; wire config_cs = magic_map && bus.ioreq && bus.a[7:0] == 8'hFF; always @(posedge clk28 or negedge rst_n) begin if (!rst_n) begin magic_reboot <= 0; magic_beeper <= 0; machine <= MACHINE_PENT; - turbo <= TURBO_NONE; + turbo0 <= TURBO_NONE; panning <= PANNING_ABC; joy_sinclair <= 0; divmmc_en <= 0; @@ -90,11 +94,12 @@ always @(posedge clk28 or negedge rst_n) begin covox_en <= 1'b1; soundrive_en <= 1'b1; sd_indication_en <= 1'b1; + autoturbo_en <= 1'b0; end else if (config_cs && bus.wr) case (bus.a[15:8]) 8'h01: {magic_reboot, magic_beeper} <= bus.d[1:0]; 8'h02: machine <= machine_t'(bus.d[2:0]); - 8'h03: turbo <= turbo_t'(bus.d[2:0]); + 8'h03: turbo0 <= turbo_t'(bus.d[2:0]); 8'h04: panning <= panning_t'(bus.d[1:0]); 8'h07: joy_sinclair <= bus.d[0]; 8'h08: ay_en <= bus.d[0]; @@ -102,6 +107,7 @@ always @(posedge clk28 or negedge rst_n) begin 8'h0A: ulaplus_en <= bus.d[0]; 8'h0B: {soundrive_en, covox_en} <= bus.d[1:0]; 8'h0C: sd_indication_en <= bus.d[0]; + 8'h0E: autoturbo_en <= bus.d[0]; endcase end @@ -115,6 +121,39 @@ always @(posedge clk28 or negedge rst_n) begin end +/* AUTOMATIC TURBO */ +reg [11:0] portfe_noturbo; // 1170uS +always @(posedge clk28 or negedge rst_n) begin + if (!rst_n) + portfe_noturbo <= 0; + else if (bus.ioreq && !bus.a[0]) + portfe_noturbo <= 1'b1; + else if (|portfe_noturbo && ck35) + portfe_noturbo <= portfe_noturbo + 1'b1; +end +reg basic48_ramclear_turbo; +always @(posedge clk28 or negedge rst_n) begin + if (!rst_n) + basic48_ramclear_turbo <= 0; + else if (basic48_paged && bus.m1 && bus.a[15:6] == 10'b0001000111) + basic48_ramclear_turbo <= 1'b1; + else if (!basic48_paged || (bus.m1 && bus.a[15:6] != 10'b0001000111)) + basic48_ramclear_turbo <= 0; +end +always @(posedge clk28 or negedge rst_n) begin + if (!rst_n) + turbo <= TURBO_NONE; + else if (autoturbo_en && div_paged && !magic_map) + turbo <= TURBO_14; + else if (autoturbo_en && |portfe_noturbo) + turbo <= TURBO_NONE; + else if (autoturbo_en && basic48_ramclear_turbo) + turbo <= TURBO_14; + else + turbo <= turbo0; +end + + /* BUS CONTROLLER */ assign d_out_active = config_rd; assign d_out = config_data; diff --git a/fpga/rtl/top.sv b/fpga/rtl/top.sv index a402087..057270d 100755 --- a/fpga/rtl/top.sv +++ b/fpga/rtl/top.sv @@ -227,6 +227,7 @@ assign sd_indication = sd_indication_en & ~sd_cs; magic magic0( .rst_n(n_rstcpu), .clk28(clk28), + .ck35(ck35), .bus(bus), .d_out(magic_dout), @@ -239,6 +240,7 @@ magic magic0( .magic_button(ps2_key_magic), .pause_button(ps2_key_pause), .div_paged(div_map && !div_mapram), + .basic48_paged(basic48_paged), .magic_mode(magic_mode), .magic_map(magic_map), diff --git a/rom_src/config.asm b/rom_src/config.asm index 1f1f9c4..526fb32 100644 --- a/rom_src/config.asm +++ b/rom_src/config.asm @@ -32,6 +32,8 @@ sd DB 2 ulaplus DB 1 dac DB 3 sdind DB 1 +_reserv4 DB 0 +autoturbo DB 0 ENDS CFG_DEFAULT CFG_T diff --git a/rom_src/menu_structure.asm b/rom_src/menu_structure.asm index 3f00c3b..1af68a5 100644 --- a/rom_src/menu_structure.asm +++ b/rom_src/menu_structure.asm @@ -44,6 +44,7 @@ menudefault: MENU_DEF 20 menuadv: MENU_DEF 22 MENUENTRY_T str_sd_indication menu_sdind_value_cb menu_sdind_cb + MENUENTRY_T str_autoturbo menu_autoturbo_value_cb menu_autoturbo_cb MENUENTRY_T str_back 0 menu_back_cb MENUENTRY_T 0 .end: @@ -130,6 +131,15 @@ menu_sdind_value_cb: .values_table: DW str_off_short.end-2 DW str_on_short.end-2 + +menu_autoturbo_value_cb: + ld ix, .values_table + ld a, (cfg.autoturbo) + jp menu_value_get +.values_table: + DW str_off_short.end-2 + DW str_on_short.end-2 + menu_value_get: sla a ld c, a @@ -231,6 +241,15 @@ menu_sdind_cb: out (c), a ret +menu_autoturbo_cb: + ld a, (cfg.autoturbo) + ld c, 1 + call menu_handle_press + ld (cfg.autoturbo), a + ld bc, #0eff + out (c), a + ret + menu_back_cb: call restore_screen ld hl, (var_menumain) diff --git a/rom_src/strings.asm b/rom_src/strings.asm index 9dc0bd7..7846dae 100644 --- a/rom_src/strings.asm +++ b/rom_src/strings.asm @@ -41,4 +41,5 @@ str_dac_sd: DEFSTR " SD" str_dac_covoxsd: DEFSTR "Covox+SD" str_menuadv: DEFSTR "Advanced..." str_sd_indication: DEFSTR "SD indication" +str_autoturbo: DEFSTR "Auto CPU freq" str_back: DEFSTR "Go back..."