Files
CoCo3_Plus_MiSTer/rtl/ssc/ssc_tms7000_bcd.sv
T
bholman cb40fed3b9 Introduce Coco 3 Plus for MiSTer
Add original-firmware Sound & Speech, four configurable Multi-Pak sockets,
bounded per-slot ROM allocation and a nine-page menu organized around devices
and media. Repair inherited clock/reset/CPU-memory/video paths and add explicit
conditional external-I/O timing contracts. Preserve native Main startup-file
ordering, saved layouts, stock-core separation and the coco3plus media profile.

Provide native Windows tool downloads, pinned ToolShed ROM assembly, fresh
Quartus builds, functional and fitted timing checks, reviewed release packaging
and passwordless SSH installation with backups. Retain original component
notices, document contribution copyright and keep SSC ROM inputs outside Git.

Validation: Quartus17.0.2 Build602 seed5, zero errors; 15 functional jobs,
368 both-corner timing scopes and eight tooling-integrity checks pass.
The renamed build reaches Disk BASIC, PRINT1+1 returns2 and SSC loads ready.
Physical cold power cycling and conditional board-delay assumptions remain
separate. Full original upstream histories are preserved before this single
consolidated implementation commit.
2026-11-18 16:00:45 -07:00

33 lines
1.6 KiB
Systemverilog

// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
// SPDX-License-Identifier: BSD-3-Clause
// Two-stage parallel decimal adjust, VCCPlus/MAME TMS7000; see LICENSE.
// No operation-select mux precedes the nibble arithmetic. Both results are
// available two rising edges after stable operands, including invalid BCD.
module ssc_tms7000_bcd(input wire clk,reset,input wire [7:0] destination,source,
input wire carry,output reg [7:0] add_result,sub_result,
output reg add_carry,sub_carry);
reg [7:0] add_base,sub_base;
reg [2:0] add_adjust,sub_adjust;
wire [5:0] high_sum={2'd0,destination[7:4]}+{2'd0,source[7:4]};
wire [5:0] low_sum={2'd0,destination[3:0]}+{2'd0,source[3:0]}+{5'd0,carry};
wire low_borrow={1'b0,destination[3:0]}<({1'b0,source[3:0]}+{4'd0,!carry});
function [7:0] correction(input [2:0] index);
begin case(index) 1:correction=8'h06;3,5:correction=8'h66;4:correction=8'h60;default:correction=0;endcase end
endfunction
always @(posedge clk)begin
if(reset)begin
add_base<=0;sub_base<=0;add_adjust<=0;sub_adjust<=0;
add_result<=0;sub_result<=0;add_carry<=0;sub_carry<=0;
end else begin
add_base<=destination+source+{7'd0,carry};
sub_base<=destination-source-{7'd0,!carry};
add_adjust<={(high_sum>9),(high_sum==9),(low_sum>=10)};
sub_adjust<={(destination[7:4]<source[7:4]),(destination[7:4]==source[7:4]),low_borrow};
add_result<=add_base+correction(add_adjust);
sub_result<=sub_base-correction(sub_adjust);
add_carry<=(add_adjust>2);sub_carry<=(sub_adjust<=2);
end
end
endmodule