Skip to content

Commit

Permalink
HDD LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
harbaum committed Jan 15, 2024
1 parent 883df07 commit a6fbc7e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 24 deletions.
9 changes: 8 additions & 1 deletion bl616/misterynano_fw/sdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ int sdc_handle_event(void) {
// translate sector into a cluster number inside image
sdc_lock();
f_lseek(&fil[drive], (rsector+1)*512);
sdc_unlock();

// and add sector offset within cluster
unsigned long dsector = clst2sect(fil[drive].clust) + rsector%fs.csize;
Expand All @@ -286,7 +285,15 @@ int sdc_handle_event(void) {
spi_tx_u08(spi, (dsector >> 16) & 0xff);
spi_tx_u08(spi, (dsector >> 8) & 0xff);
spi_tx_u08(spi, dsector & 0xff);

// wait while core is busy to make sure we don't start
// requesting data for ourselves while the core is still
// doing its own io
while(spi_tx_u08(spi, 0) & 1);

spi_end(spi);

sdc_unlock();
}

return 0;
Expand Down
15 changes: 14 additions & 1 deletion src/atarist/acsi.v
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ module acsi (
output reply_req,
input reply_ack,

output reg irq
output reg irq,

output [1:0] leds
);

reg [15:0] led_counter [2];
assign leds = { |led_counter[1], |led_counter[0] };

reg cpu_selD;
always @(posedge clk) if (clk_en) cpu_selD <= cpu_sel;
wire cpu_req = ~cpu_selD & cpu_sel;
Expand Down Expand Up @@ -206,7 +211,13 @@ always @(posedge clk) begin
data_rd_req <= 2'b00;
data_wr_req <= 2'b00;
reply_cnt <= REPLY_IDLE;
led_counter[0] <= 16'd0;
led_counter[1] <= 16'd0;
end else begin

if(led_counter[0]) led_counter[0] <= led_counter[0] - 16'd1;
if(led_counter[1]) led_counter[1] <= led_counter[1] - 16'd1;

if(reply_cnt != REPLY_IDLE) begin
if(reply_ack) begin
if(reply_cnt < cmd_reply_len) begin
Expand Down Expand Up @@ -322,6 +333,7 @@ always @(posedge clk) begin
// target can only be 0 or 1
data_rd_req[current_target] <= 1'b1;
data_lba <= lba;
led_counter[current_target] <= 16'hffff;
end

// write(6) and write(10)
Expand All @@ -330,6 +342,7 @@ always @(posedge clk) begin
// device. target can only be 0 or 1
data_wr_req[current_target] <= 1'b1;
data_lba <= lba;
led_counter[current_target] <= 16'hffff;
end

// commands to be rejected incl.
Expand Down
8 changes: 5 additions & 3 deletions src/atarist/atarist.v
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module atarist (
input wire [15:0] rom_data_out,

// export all LEDs
output wire [1:0] leds
output wire [3:0] leds
);

// registered reset signals
Expand Down Expand Up @@ -788,7 +788,7 @@ end
/* ------------------------------------- DMA ------------------------------------ */
/* ------------------------------------------------------------------------------ */

assign leds = floppy_sel ^ 2'b11;
assign leds[1:0] = floppy_sel ^ 2'b11;
wire fdc_drq;
wire [1:0] fdc_addr;
wire fdc_sel;
Expand Down Expand Up @@ -838,7 +838,9 @@ dma dma (
// ram interface
.rdy_i ( rdy_i ),
.rdy_o ( rdy_o ),
.ram_din ( shifter_dout )
.ram_din ( shifter_dout ),

.hdd_leds ( leds[3:2] )
);

// Some broken software selects both drives at the same time. On real hardware this
Expand Down
8 changes: 6 additions & 2 deletions src/atarist/dma.v
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ module dma (
// ram interface for dma engine
input rdy_i,
output rdy_o,
input [15:0] ram_din
input [15:0] ram_din,

output [1:0] hdd_leds
);

// some games access right after writing the sector count
Expand Down Expand Up @@ -383,7 +385,9 @@ acsi acsi(
.cpu_a1 ( dma_mode[1] ),
.cpu_rw ( cpu_rw ),
.cpu_din ( cpu_din[7:0] ),
.cpu_dout ( acsi_dout )
.cpu_dout ( acsi_dout ),

.leds ( hdd_leds )
);

wire [15:0] ram_dout;
Expand Down
31 changes: 17 additions & 14 deletions src/misc/sd_card.v
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ always @(posedge clk) begin
// can wait for 0 to be read when waiting for
// sector data to become available
if(byte_cnt <= 4'd3) data_out <= 8'hff;
else data_out <= { 7'd0, rstart_int || wstart_int };
else data_out <= { 7'd0, rstart_int || wstart_int };

if(byte_cnt == 4'd0) lsector[31:24] <= data_in;
if(byte_cnt == 4'd1) lsector[23:16] <= data_in;
Expand All @@ -232,20 +232,23 @@ always @(posedge clk) begin
if(wstart_any) wstart_int <= 1'b1;
end

// If sector has been requested from sd card, rstart_int
// has thus been set and all data has arrived, so
// rstart_int is reset again, then start mcu transfer
if(byte_cnt >= 4'd4) begin
if(!rstart_int) begin
state <= MCU_READ_TX;
mcu_tx_cnt <= 9'd0;
end
// MCU has requested a sector. Start returning data once it arrives
if(command == 8'd3) begin
// If sector has been requested from sd card, rstart_int
// has thus been set and all data has arrived, so
// rstart_int is reset again, then start mcu transfer
if(byte_cnt >= 4'd4) begin
if(!rstart_int) begin
state <= MCU_READ_TX;
mcu_tx_cnt <= 9'd0;
end

if(state == MCU_READ_TX) begin
data_out <= doutb;
mcu_tx_cnt <= mcu_tx_cnt + 9'd1;
end
end
if(state == MCU_READ_TX) begin
data_out <= doutb;
mcu_tx_cnt <= mcu_tx_cnt + 9'd1;
end
end
end
end

// SDC CMD 4: INSERTED
Expand Down
5 changes: 2 additions & 3 deletions src/tangnano20k/top.sv
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ atarist atarist (
.ram_data_in(mdout),
.ram_data_out(mdin),

.leds(leds[1:0])
.leds(leds[3:0]) // HDD 1:0 / FDC 1:0
);

video video (
Expand Down Expand Up @@ -479,8 +479,7 @@ video video (

// -------------------------- SD card -------------------------------

// assign leds[5:2] = { system_leds, sd_rd };
assign leds[5:2] = { spi_ext, 1'b0, sd_rd };
assign leds[5:4] = system_leds[1:0];

// Give MCU some time to open a default disk image before booting the core
// image_size != 0 means card is initialized. Wait up to 2 seconds for this before
Expand Down

0 comments on commit a6fbc7e

Please sign in to comment.