From 23445b482e61d14f514820286fc7b03e76e1094c Mon Sep 17 00:00:00 2001 From: Eugene Lozovoy Date: Wed, 2 Oct 2024 20:00:03 +0300 Subject: [PATCH] limit max cpu freq to 7MHz for NMOS CPU's --- cpld/rtl/magic.sv | 10 ++++--- rom_src/config.asm | 1 + rom_src/main.asm | 55 +++++++++++++++++++++++++++----------- rom_src/menu_structure.asm | 4 ++- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/cpld/rtl/magic.sv b/cpld/rtl/magic.sv index e045654..4ce5a72 100644 --- a/cpld/rtl/magic.sv +++ b/cpld/rtl/magic.sv @@ -129,6 +129,7 @@ initial sd_indication_en = 1'b1; initial bright_boost = 1'b0; `endif reg autoturbo_en = 1'b0; +reg cmoscpu = 1'b0; initial zxkit1 = 1'b0; initial joy_a_up = 1'b0; @@ -158,11 +159,12 @@ always @(posedge clk28 or negedge rst_n) begin 8'h0F: zxkit1 <= bus.d[0]; 8'h10: joy_a_up <= bus.d[0]; 8'h11: fastforward <= bus.d[0]; + 8'h12: cmoscpu <= bus.d[0]; endcase end reg config_rd; -wire [7:0] config_data = {4'b0000, div_paged, fastforward_button, pause_button, magic_button}; +wire [7:0] config_data = {3'b000, cmoscpu, div_paged, fastforward_button, pause_button, magic_button}; always @(posedge clk28 or negedge rst_n) begin if (!rst_n) config_rd <= 0; @@ -194,13 +196,13 @@ always @(posedge clk28 or negedge rst_n) begin if (!rst_n) turbo <= TURBO_NONE; else if (fastforward) - turbo <= TURBO_14; + turbo <= cmoscpu? TURBO_14 : TURBO_7; else if (autoturbo_en && div_paged && !magic_map) - turbo <= TURBO_14; + turbo <= cmoscpu? TURBO_14 : TURBO_7; else if (autoturbo_en && |portfe_noturbo) turbo <= TURBO_NONE; else if (autoturbo_en && basic48_ramclear_turbo) - turbo <= TURBO_14; + turbo <= cmoscpu? TURBO_14 : TURBO_7; else turbo <= turbo0; end diff --git a/rom_src/config.asm b/rom_src/config.asm index 46ab376..531eac8 100644 --- a/rom_src/config.asm +++ b/rom_src/config.asm @@ -47,6 +47,7 @@ autoturbo DB 0 zxkit1 DB 0 joy_a_up DB 0 fastforward DB 0 +cmoscpu DB 0 ENDS STRUCT CFGEXT_T diff --git a/rom_src/main.asm b/rom_src/main.asm index 50b1a2a..f46346d 100644 --- a/rom_src/main.asm +++ b/rom_src/main.asm @@ -1,5 +1,6 @@ ASSERT __SJASMPLUS__ >= 0x011402 ; SjASMPlus 1.20.2 OPT --syntax=abf + OPT -Wno-out0 DEVICE ZXSPECTRUM48 ; Startup handler @@ -50,6 +51,7 @@ startup_handler: djnz .loop ; ... call init_default_config call load_user_config + call detect_cpu call detect_sd_card call detect_ext_board call detect_external_ay @@ -294,22 +296,43 @@ init_cpld: ld bc, #1ffd ; ... out (c), a ; ... .do_load: - ld b, CFG_T ; B = registers count - ld c, #ff ; - ld hl, cfg+CFG_T-1 ; HL = &cfg[registers count-1] - otdr ; do { b--; out(bc, *hl); hl--; } while(b) -.do_load_ext: ; same for extension board - ld d, CFGEXT_T ; ... - ld bc, #e1ff ; ... - ld hl, cfgext ; ... -.do_load_ext_loop: ; ... - ld a, (hl) ; ... - out (c), a ; ... - inc hl ; ... - inc b ; ... - dec d ; ... - jr nz, .do_load_ext_loop ; ... - ret + ld b, CFG_T ; B = registers count + ld c, #ff ; + ld hl, cfg+CFG_T-1 ; HL = &cfg[registers count-1] + otdr ; do { b--; out(bc, *hl); hl--; } while(b) +.do_load_ext: ; same for extension board + ld d, CFGEXT_T ; ... + ld bc, #e1ff ; ... + ld hl, cfgext ; ... +.do_load_ext_loop: ; ... + ld a, (hl) ; ... + out (c), a ; ... + inc hl ; ... + inc b ; ... + dec d ; ... + jr nz, .do_load_ext_loop ; ... + ret ; + + +detect_cpu: + ld bc, #12ff ; + out (c), 0 ; on NMOS Z80 0x00 will be written, on CMOS Z80 - 0xFF + ld b, 0 ; + in a, (c) ; port #00FF bit 4 contains value we wrote + and #10 ; + jr z, .nmos ; +.cmos: + ld a, 1 ; + ld (cfg_saved.cmoscpu), a ; + ret ; +.nmos: + ld (cfg_saved.cmoscpu), a ; + ld a, (cfg_saved.clock) ; if clock >= 14MHz then clock = 7MHz + cp 4 ; ... + ret c ; ... + ld a, 3 ; ... + ld (cfg_saved.clock), a ; ... + ret ; detect_sd_card: diff --git a/rom_src/menu_structure.asm b/rom_src/menu_structure.asm index 92a92b5..4196ea8 100644 --- a/rom_src/menu_structure.asm +++ b/rom_src/menu_structure.asm @@ -272,8 +272,10 @@ menu_machine_cb: ret menu_clock_cb: + ld a, (cfg.cmoscpu) ; for CMOS - max clock is 4 (14MHz) + add 3 ; for NMOS - max clock is 3 (7MHz) + ld c, a ; ... ld a, (cfg.clock) - ld c, 4 call menu_handle_press ld (cfg.clock), a ld bc, #03ff