Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2200 lines
72 KiB

  1. `timescale 1 ns / 1 ps
  2. /*
  3. * MNT ZZ9000 Amiga Graphics and Coprocessor Card Firmware
  4. * Zorro 2/3 AXI4-Lite Interface, 24-bit Video Capture (AXI DMA)
  5. *
  6. * Copyright (C) 2019-2020, Lukas F. Hartmann <lukas@mntre.com>
  7. * MNT Research GmbH, Berlin
  8. * https://mntre.com
  9. *
  10. * Contributors: _Bnu, shanshe
  11. *
  12. * More Info: https://mntre.com/zz9000
  13. *
  14. * SPDX-License-Identifier: GPL-3.0-or-later
  15. * GNU General Public License v3.0 or later
  16. *
  17. * https://spdx.org/licenses/GPL-3.0-or-later.html
  18. *
  19. */
  20. // ZORRO2/3 switch
  21. //`define ZORRO2
  22. `define ZORRO3
  23. // use together with ZORRO2:
  24. //`define VARIANT_ZZ9500 // uses Denise adapter/A500 specific video capture
  25. //`define VARIANT_2MB // uses only 2MB address space
  26. //`define VARIANT_SUPERDENISE // for A500+ and super denise
  27. //`define VARIANT_FW20
  28. `define C_S_AXI_DATA_WIDTH 32
  29. `define C_S_AXI_ADDR_WIDTH 5
  30. `ifdef VARIANT_2MB
  31. `define RAM_SIZE 32'h200000 // 2MB for Zorro 2
  32. `else
  33. `define RAM_SIZE 32'h400000 // 4MB for Zorro 2
  34. `endif
  35. `define REG_SIZE 32'h01000
  36. `define AUTOCONF_LOW 24'he80000
  37. `define AUTOCONF_HIGH 24'he80080
  38. `define Z3_RAM_SIZE 32'h10000000 // 256MB for Zorro 3
  39. `define ARM_MEMORY_START 32'h001f0000
  40. `define VIDEOCAP_ADDR 32'h01000000 // ARM_MEMORY_START+0xe0_0000
  41. `define TX_FRAME_ADDRESS 32'h0fd10000
  42. `define RX_FRAME_ADDRESS 32'h0fd20000
  43. `define RX_BACKLOG_ADDRESS 32'h0fe00000
  44. `define FRAME_SIZE 24'h2048
  45. `define USB_BLOCK_STORAGE_ADDRESS 32'h0fe10000
  46. `define C_M00_AXI_TARGET_SLAVE_BASE_ADDR 32'h10000000
  47. `define C_M00_AXI_ID_WIDTH 1
  48. `define C_M00_AXI_ADDR_WIDTH 32
  49. `define C_M00_AXI_DATA_WIDTH 32
  50. `define C_M00_AXI_AWUSER_WIDTH 0
  51. `define C_M00_AXI_ARUSER_WIDTH 0
  52. `define C_M00_AXI_WUSER_WIDTH 0
  53. `define C_M00_AXI_RUSER_WIDTH 0
  54. `define C_M00_AXI_BUSER_WIDTH 0
  55. module MNTZorro_v0_1_S00_AXI
  56. (
  57. output wire arm_interrupt,
  58. inout wire [22:0] ZORRO_ADDR,
  59. inout wire [15:0] ZORRO_DATA,
  60. output wire ZORRO_INT6,
  61. output wire ZORRO_DATADIR,
  62. output wire ZORRO_ADDRDIR,
  63. output wire ZORRO_ADDRDIR2,
  64. output wire ZORRO_NBRN,
  65. input wire ZORRO_NBGN,
  66. input wire ZORRO_READ,
  67. //input wire ZORRO_NMTCR,
  68. input wire ZORRO_NUDS,
  69. input wire ZORRO_NLDS,
  70. input wire ZORRO_NDS1,
  71. input wire ZORRO_NDS0,
  72. input wire ZORRO_NCCS,
  73. input wire ZORRO_NFCS,
  74. input wire ZORRO_DOE,
  75. input wire ZORRO_NIORST,
  76. input wire ZORRO_NCFGIN,
  77. input wire ZORRO_E7M,
  78. input wire ZORRO_C28D,
  79. input wire VCAP_VSYNC,
  80. input wire VCAP_HSYNC,
  81. input wire VCAP_G0,
  82. input wire VCAP_G1,
  83. input wire VCAP_G2,
  84. input wire VCAP_G3,
  85. input wire VCAP_G4,
  86. input wire VCAP_G5,
  87. input wire VCAP_G6,
  88. input wire VCAP_G7,
  89. input wire VCAP_B7,
  90. input wire VCAP_B6,
  91. input wire VCAP_B5,
  92. input wire VCAP_B4,
  93. input wire VCAP_B3,
  94. input wire VCAP_B2,
  95. input wire VCAP_B1,
  96. input wire VCAP_B0,
  97. input wire VCAP_R7,
  98. input wire VCAP_R6,
  99. input wire VCAP_R5,
  100. input wire VCAP_R4,
  101. input wire VCAP_R3,
  102. input wire VCAP_R2,
  103. input wire VCAP_R1,
  104. input wire VCAP_R0,
  105. output wire ZORRO_NCFGOUT,
  106. output wire ZORRO_NSLAVE,
  107. output wire ZORRO_NCINH,
  108. output wire ZORRO_NDTACK,
  109. // HP master interface to write to PS memory directly
  110. input wire m00_axi_aclk,
  111. input wire m00_axi_aresetn,
  112. // write address channel
  113. input wire m00_axi_awready,
  114. output wire [`C_M00_AXI_ADDR_WIDTH-1 : 0] m00_axi_awaddr,
  115. output reg [3:0] m00_axi_awlen,
  116. output reg [2:0] m00_axi_awsize,
  117. output reg [1:0] m00_axi_awburst,
  118. output reg m00_axi_awlock,
  119. output reg [3:0] m00_axi_awcache,
  120. output reg [2:0] m00_axi_awprot,
  121. //output reg [3:0] m00_axi_awqos,
  122. output wire m00_axi_awvalid,
  123. // write channel
  124. input wire m00_axi_wready,
  125. output wire [`C_M00_AXI_DATA_WIDTH-1 : 0] m00_axi_wdata,
  126. output wire [`C_M00_AXI_DATA_WIDTH/8-1 : 0] m00_axi_wstrb,
  127. output reg m00_axi_wlast,
  128. output wire m00_axi_wvalid,
  129. // buffered write response channel
  130. input wire [1 : 0] m00_axi_bresp,
  131. input wire m00_axi_bvalid,
  132. output reg m00_axi_bready,
  133. // read address channel
  134. input wire m00_axi_arready,
  135. output reg [`C_M00_AXI_ADDR_WIDTH-1 : 0] m00_axi_araddr,
  136. output reg [3 : 0] m00_axi_arlen,
  137. output reg [2 : 0] m00_axi_arsize,
  138. output reg [1 : 0] m00_axi_arburst,
  139. output reg m00_axi_arlock,
  140. output reg [3 : 0] m00_axi_arcache,
  141. output reg [2 : 0] m00_axi_arprot,
  142. //output reg [3 : 0] m00_axi_arqos,
  143. output reg m00_axi_arvalid,
  144. output reg m00_axi_rready,
  145. input wire [`C_M00_AXI_DATA_WIDTH-1 : 0] m00_axi_rdata,
  146. input wire [1 : 0] m00_axi_rresp,
  147. input wire m00_axi_rlast,
  148. input wire m00_axi_rvalid,
  149. // HP master interface 2 to write to PS memory directly (for videocap)
  150. input wire m01_axi_aclk,
  151. input wire m01_axi_aresetn,
  152. // write address channel
  153. input wire m01_axi_awready,
  154. output wire [`C_M00_AXI_ADDR_WIDTH-1 : 0] m01_axi_awaddr,
  155. output reg [7:0] m01_axi_awlen,
  156. output reg [2:0] m01_axi_awsize,
  157. output reg [1:0] m01_axi_awburst,
  158. output reg m01_axi_awlock,
  159. output reg [3:0] m01_axi_awcache,
  160. output reg [2:0] m01_axi_awprot,
  161. output reg [3:0] m01_axi_awqos,
  162. output wire m01_axi_awvalid,
  163. // write channel
  164. input wire m01_axi_wready,
  165. output wire [`C_M00_AXI_DATA_WIDTH-1 : 0] m01_axi_wdata,
  166. output wire [`C_M00_AXI_DATA_WIDTH/8-1 : 0] m01_axi_wstrb,
  167. output reg m01_axi_wlast,
  168. output wire m01_axi_wvalid,
  169. // buffered write response channel
  170. input wire [1 : 0] m01_axi_bresp,
  171. input wire m01_axi_bvalid,
  172. output reg m01_axi_bready,
  173. // video_formatter control interface
  174. output reg [31:0] video_control_data_out,
  175. output reg [7:0] video_control_op_out,
  176. output reg video_control_interlace_out,
  177. input wire video_control_vblank_in,
  178. // Xilinx AXI4-Lite implementation starts here ==============================
  179. // Global Clock Signal
  180. input wire S_AXI_ACLK,
  181. // Global Reset Signal. This Signal is Active LOW
  182. input wire S_AXI_ARESETN,
  183. // Write address (issued by master, acceped by Slave)
  184. input wire [`C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_AWADDR,
  185. // Write channel Protection type. This signal indicates the
  186. // privilege and security level of the transaction, and whether
  187. // the transaction is a data access or an instruction access.
  188. input wire [2 : 0] S_AXI_AWPROT,
  189. // Write address valid. This signal indicates that the master signaling
  190. // valid write address and control information.
  191. input wire S_AXI_AWVALID,
  192. // Write address ready. This signal indicates that the slave is ready
  193. // to accept an address and associated control signals.
  194. output wire S_AXI_AWREADY,
  195. // Write data (issued by master, acceped by Slave)
  196. input wire [`C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_WDATA,
  197. // Write strobes. This signal indicates which byte lanes hold
  198. // valid data. There is one write strobe bit for each eight
  199. // bits of the write data bus.
  200. input wire [(`C_S_AXI_DATA_WIDTH/8)-1 : 0] S_AXI_WSTRB,
  201. // Write valid. This signal indicates that valid write
  202. // data and strobes are available.
  203. input wire S_AXI_WVALID,
  204. // Write ready. This signal indicates that the slave
  205. // can accept the write data.
  206. output wire S_AXI_WREADY,
  207. // Write response. This signal indicates the status
  208. // of the write transaction.
  209. output wire [1 : 0] S_AXI_BRESP,
  210. // Write response valid. This signal indicates that the channel
  211. // is signaling a valid write response.
  212. output wire S_AXI_BVALID,
  213. // Response ready. This signal indicates that the master
  214. // can accept a write response.
  215. input wire S_AXI_BREADY,
  216. // Read address (issued by master, acceped by Slave)
  217. input wire [`C_S_AXI_ADDR_WIDTH-1 : 0] S_AXI_ARADDR,
  218. // Protection type. This signal indicates the privilege
  219. // and security level of the transaction, and whether the
  220. // transaction is a data access or an instruction access.
  221. input wire [2 : 0] S_AXI_ARPROT,
  222. // Read address valid. This signal indicates that the channel
  223. // is signaling valid read address and control information.
  224. input wire S_AXI_ARVALID,
  225. // Read address ready. This signal indicates that the slave is
  226. // ready to accept an address and associated control signals.
  227. output wire S_AXI_ARREADY,
  228. // Read data (issued by slave)
  229. output wire [`C_S_AXI_DATA_WIDTH-1 : 0] S_AXI_RDATA,
  230. // Read response. This signal indicates the status of the
  231. // read transfer.
  232. output wire [1 : 0] S_AXI_RRESP,
  233. // Read valid. This signal indicates that the channel is
  234. // signaling the required read data.
  235. output wire S_AXI_RVALID,
  236. // Read ready. This signal indicates that the master can
  237. // accept the read data and response information.
  238. input wire S_AXI_RREADY
  239. );
  240. // AXI4LITE signals
  241. reg [`C_S_AXI_ADDR_WIDTH-1 : 0] axi_awaddr;
  242. reg axi_awready;
  243. reg axi_wready;
  244. reg [1 : 0] axi_bresp;
  245. reg axi_bvalid;
  246. reg [`C_S_AXI_ADDR_WIDTH-1 : 0] axi_araddr;
  247. reg axi_arready;
  248. reg [`C_S_AXI_DATA_WIDTH-1 : 0] axi_rdata;
  249. reg [1 : 0] axi_rresp;
  250. reg axi_rvalid;
  251. // Example-specific design signals
  252. // local localparam for addressing 32 bit / 64 bit C_S_AXI_DATA_WIDTH
  253. // ADDR_LSB is used for addressing 32/64 bit registers/memories
  254. // ADDR_LSB = 2 for 32 bits (n downto 2)
  255. // ADDR_LSB = 3 for 64 bits (n downto 3)
  256. localparam integer ADDR_LSB = (`C_S_AXI_DATA_WIDTH/32) + 1;
  257. localparam integer OPT_MEM_ADDR_BITS = 2;
  258. //----------------------------------------------
  259. //-- Signals for user logic register space example
  260. //------------------------------------------------
  261. //-- Number of Slave Registers 4
  262. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg0;
  263. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg1;
  264. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg2;
  265. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg3;
  266. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg4;
  267. reg [`C_S_AXI_DATA_WIDTH-1:0] slv_reg5;
  268. wire slv_reg_rden;
  269. wire slv_reg_wren;
  270. reg [`C_S_AXI_DATA_WIDTH-1:0] reg_data_out;
  271. integer byte_index;
  272. reg aw_en;
  273. reg [`C_S_AXI_DATA_WIDTH-1:0] out_reg0;
  274. reg [`C_S_AXI_DATA_WIDTH-1:0] out_reg1;
  275. reg [`C_S_AXI_DATA_WIDTH-1:0] out_reg2;
  276. reg [`C_S_AXI_DATA_WIDTH-1:0] out_reg3;
  277. // I/O Connections assignments
  278. assign S_AXI_AWREADY = axi_awready;
  279. assign S_AXI_WREADY = axi_wready;
  280. assign S_AXI_BRESP = axi_bresp;
  281. assign S_AXI_BVALID = axi_bvalid;
  282. assign S_AXI_ARREADY = axi_arready;
  283. assign S_AXI_RDATA = axi_rdata;
  284. assign S_AXI_RRESP = axi_rresp;
  285. assign S_AXI_RVALID = axi_rvalid;
  286. // Implement axi_awready generation
  287. // axi_awready is asserted for one S_AXI_ACLK clock cycle when both
  288. // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_awready is
  289. // de-asserted when reset is low.
  290. always @( posedge S_AXI_ACLK )
  291. begin
  292. if ( S_AXI_ARESETN == 1'b0 )
  293. begin
  294. axi_awready <= 1'b0;
  295. aw_en <= 1'b1;
  296. end
  297. else
  298. begin
  299. if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID && aw_en)
  300. begin
  301. // slave is ready to accept write address when
  302. // there is a valid write address and write data
  303. // on the write address and data bus. This design
  304. // expects no outstanding transactions.
  305. axi_awready <= 1'b1;
  306. aw_en <= 1'b0;
  307. end
  308. else if (S_AXI_BREADY && axi_bvalid)
  309. begin
  310. aw_en <= 1'b1;
  311. axi_awready <= 1'b0;
  312. end
  313. else
  314. begin
  315. axi_awready <= 1'b0;
  316. end
  317. end
  318. end
  319. // Implement axi_awaddr latching
  320. // This process is used to latch the address when both
  321. // S_AXI_AWVALID and S_AXI_WVALID are valid.
  322. always @( posedge S_AXI_ACLK )
  323. begin
  324. if ( S_AXI_ARESETN == 1'b0 )
  325. begin
  326. axi_awaddr <= 0;
  327. end
  328. else
  329. begin
  330. if (~axi_awready && S_AXI_AWVALID && S_AXI_WVALID && aw_en)
  331. begin
  332. // Write Address latching
  333. axi_awaddr <= S_AXI_AWADDR;
  334. end
  335. end
  336. end
  337. // Implement axi_wready generation
  338. // axi_wready is asserted for one S_AXI_ACLK clock cycle when both
  339. // S_AXI_AWVALID and S_AXI_WVALID are asserted. axi_wready is
  340. // de-asserted when reset is low.
  341. always @( posedge S_AXI_ACLK )
  342. begin
  343. if ( S_AXI_ARESETN == 1'b0 )
  344. begin
  345. axi_wready <= 1'b0;
  346. end
  347. else
  348. begin
  349. if (~axi_wready && S_AXI_WVALID && S_AXI_AWVALID && aw_en )
  350. begin
  351. // slave is ready to accept write data when
  352. // there is a valid write address and write data
  353. // on the write address and data bus. This design
  354. // expects no outstanding transactions.
  355. axi_wready <= 1'b1;
  356. end
  357. else
  358. begin
  359. axi_wready <= 1'b0;
  360. end
  361. end
  362. end
  363. // Implement memory mapped register select and write logic generation
  364. // The write data is accepted and written to memory mapped registers when
  365. // axi_awready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted. Write strobes are used to
  366. // select byte enables of slave registers while writing.
  367. // These registers are cleared when reset (active low) is applied.
  368. // Slave register write enable is asserted when valid address and data are available
  369. // and the slave is ready to accept the write address and write data.
  370. assign slv_reg_wren = axi_wready && S_AXI_WVALID && axi_awready && S_AXI_AWVALID;
  371. always @( posedge S_AXI_ACLK )
  372. begin
  373. if ( S_AXI_ARESETN == 1'b0 )
  374. begin
  375. slv_reg0 <= 0;
  376. slv_reg1 <= 0;
  377. slv_reg2 <= 0;
  378. slv_reg3 <= 0;
  379. slv_reg4 <= 0;
  380. slv_reg5 <= 0;
  381. end
  382. else begin
  383. if (slv_reg_wren)
  384. begin
  385. case ( axi_awaddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
  386. 3'h0:
  387. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  388. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  389. // Respective byte enables are asserted as per write strobes
  390. // Slave register 0
  391. slv_reg0[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  392. end
  393. 3'h1:
  394. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  395. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  396. // Respective byte enables are asserted as per write strobes
  397. // Slave register 1
  398. slv_reg1[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  399. end
  400. 3'h2:
  401. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  402. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  403. // Respective byte enables are asserted as per write strobes
  404. // Slave register 2
  405. slv_reg2[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  406. end
  407. 3'h3:
  408. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  409. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  410. // Respective byte enables are asserted as per write strobes
  411. // Slave register 3
  412. slv_reg3[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  413. end
  414. 3'h4:
  415. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  416. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  417. // Respective byte enables are asserted as per write strobes
  418. // Slave register 4
  419. slv_reg4[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  420. end
  421. 3'h5:
  422. for ( byte_index = 0; byte_index <= (`C_S_AXI_DATA_WIDTH/8)-1; byte_index = byte_index+1 )
  423. if ( S_AXI_WSTRB[byte_index] == 1 ) begin
  424. // Respective byte enables are asserted as per write strobes
  425. // Slave register 4
  426. slv_reg5[(byte_index*8) +: 8] <= S_AXI_WDATA[(byte_index*8) +: 8];
  427. end
  428. default : begin
  429. slv_reg0 <= slv_reg0;
  430. slv_reg1 <= slv_reg1;
  431. slv_reg2 <= slv_reg2;
  432. slv_reg3 <= slv_reg3;
  433. slv_reg4 <= slv_reg4;
  434. slv_reg5 <= slv_reg5;
  435. end
  436. endcase
  437. end
  438. end
  439. end
  440. // Implement write response logic generation
  441. // The write response and response valid signals are asserted by the slave
  442. // when axi_wready, S_AXI_WVALID, axi_wready and S_AXI_WVALID are asserted.
  443. // This marks the acceptance of address and indicates the status of
  444. // write transaction.
  445. always @( posedge S_AXI_ACLK )
  446. begin
  447. if ( S_AXI_ARESETN == 1'b0 )
  448. begin
  449. axi_bvalid <= 0;
  450. axi_bresp <= 2'b0;
  451. end
  452. else
  453. begin
  454. if (axi_awready && S_AXI_AWVALID && ~axi_bvalid && axi_wready && S_AXI_WVALID)
  455. begin
  456. // indicates a valid write response is available
  457. axi_bvalid <= 1'b1;
  458. axi_bresp <= 2'b0; // 'OKAY' response
  459. end // work error responses in future
  460. else
  461. begin
  462. if (S_AXI_BREADY && axi_bvalid)
  463. //check if bready is asserted while bvalid is high)
  464. //(there is a possibility that bready is always asserted high)
  465. begin
  466. axi_bvalid <= 1'b0;
  467. end
  468. end
  469. end
  470. end
  471. // Implement axi_arready generation
  472. // axi_arready is asserted for one S_AXI_ACLK clock cycle when
  473. // S_AXI_ARVALID is asserted. axi_awready is
  474. // de-asserted when reset (active low) is asserted.
  475. // The read address is also latched when S_AXI_ARVALID is
  476. // asserted. axi_araddr is reset to zero on reset assertion.
  477. always @( posedge S_AXI_ACLK )
  478. begin
  479. if ( S_AXI_ARESETN == 1'b0 )
  480. begin
  481. axi_arready <= 1'b0;
  482. axi_araddr <= 32'b0;
  483. end
  484. else
  485. begin
  486. if (~axi_arready && S_AXI_ARVALID)
  487. begin
  488. // indicates that the slave has acceped the valid read address
  489. axi_arready <= 1'b1;
  490. // Read address latching
  491. axi_araddr <= S_AXI_ARADDR;
  492. end
  493. else
  494. begin
  495. axi_arready <= 1'b0;
  496. end
  497. end
  498. end
  499. // Implement axi_arvalid generation
  500. // axi_rvalid is asserted for one S_AXI_ACLK clock cycle when both
  501. // S_AXI_ARVALID and axi_arready are asserted. The slave registers
  502. // data are available on the axi_rdata bus at this instance. The
  503. // assertion of axi_rvalid marks the validity of read data on the
  504. // bus and axi_rresp indicates the status of read transaction.axi_rvalid
  505. // is deasserted on reset (active low). axi_rresp and axi_rdata are
  506. // cleared to zero on reset (active low).
  507. always @( posedge S_AXI_ACLK )
  508. begin
  509. if ( S_AXI_ARESETN == 1'b0 )
  510. begin
  511. axi_rvalid <= 0;
  512. axi_rresp <= 0;
  513. end
  514. else
  515. begin
  516. if (axi_arready && S_AXI_ARVALID && ~axi_rvalid)
  517. begin
  518. // Valid read data is available at the read data bus
  519. axi_rvalid <= 1'b1;
  520. axi_rresp <= 2'b0; // 'OKAY' response
  521. end
  522. else if (axi_rvalid && S_AXI_RREADY)
  523. begin
  524. // Read data is accepted by the master
  525. axi_rvalid <= 1'b0;
  526. end
  527. end
  528. end
  529. // Output register or memory read data
  530. always @( posedge S_AXI_ACLK )
  531. begin
  532. if ( S_AXI_ARESETN == 1'b0 )
  533. begin
  534. axi_rdata <= 0;
  535. end
  536. else
  537. begin
  538. // When there is a valid read address (S_AXI_ARVALID) with
  539. // acceptance of read address by the slave (axi_arready),
  540. // output the read dada
  541. if (slv_reg_rden)
  542. begin
  543. axi_rdata <= reg_data_out; // register read data
  544. end
  545. end
  546. end
  547. // end of AXI-Lite interface ==================================================
  548. (* mark_debug = "true" *) reg [4:0] znAS_sync;
  549. (* mark_debug = "true" *) reg [2:0] znUDS_sync;
  550. (* mark_debug = "true" *) reg [2:0] znLDS_sync;
  551. (* mark_debug = "true" *) reg [2:0] zREAD_sync;
  552. (* mark_debug = "true" *) reg [4:0] znFCS_sync;
  553. (* mark_debug = "true" *) reg [2:0] znDS1_sync;
  554. (* mark_debug = "true" *) reg [2:0] znDS0_sync;
  555. reg [1:0] znRST_sync;
  556. (* mark_debug = "true" *) reg [1:0] zDOE_sync;
  557. (* mark_debug = "true" *) reg [4:0] zE7M_sync;
  558. reg [2:0] znCFGIN_sync;
  559. (* mark_debug = "true" *) reg [23:0] zaddr; // zorro 2 address
  560. (* mark_debug = "true" *) reg [23:0] zaddr_sync;
  561. (* mark_debug = "true" *) reg [23:0] zaddr_sync2;
  562. (* mark_debug = "true" *) reg [15:0] zdata_in_sync;
  563. (* mark_debug = "true" *) reg [15:0] zdata_in_sync2;
  564. reg z2_addr_valid;
  565. reg [23:0] z2_mapped_addr;
  566. reg z2_read;
  567. reg z2_write;
  568. reg z2_datastrobe_synced;
  569. reg z2addr_in_ram;
  570. reg z2addr_in_reg;
  571. reg z2addr_autoconfig;
  572. reg [31:0] ram_low ;//= 32'h600000;
  573. reg [31:0] ram_high ;//= 32'ha00000;
  574. reg [31:0] reg_low ;//= 32'h601000;
  575. reg [31:0] reg_high ;//= 32'h602000;
  576. reg z2_uds;
  577. reg z2_lds;
  578. reg [31:0] z3_ram_low ;//= 32'h50000000;
  579. reg [31:0] z3_ram_high ;//= 32'h50000000 + `Z3_RAM_SIZE -4;
  580. reg [31:0] z3_reg_low ;//= 32'h50001000;
  581. reg [31:0] z3_reg_high ;//= 32'h50002000;
  582. reg [15:0] data_z3_hi16;
  583. reg [15:0] data_z3_low16;
  584. (* mark_debug = "true" *) reg [15:0] data_z3_hi16_latched;
  585. (* mark_debug = "true" *) reg [15:0] data_z3_low16_latched;
  586. (* mark_debug = "true" *) reg [15:0] z3_din_high_s2;
  587. (* mark_debug = "true" *) reg [15:0] z3_din_low_s2;
  588. (* mark_debug = "true" *) reg [31:0] z3addr;
  589. (* mark_debug = "true" *) reg [31:0] last_z3addr;
  590. (* mark_debug = "true" *) reg [31:0] z3addr2;
  591. (* mark_debug = "true" *) reg [31:0] z3_mapped_addr;
  592. (* mark_debug = "true" *) reg [31:0] z3_read_addr;
  593. (* mark_debug = "true" *) reg [15:0] z3_read_data;
  594. reg z3_din_latch;
  595. (* mark_debug = "true" *) reg z3_fcs_state;
  596. (* mark_debug = "true" *) reg z3_end_cycle;
  597. (* mark_debug = "true" *) reg z3addr_in_ram;
  598. (* mark_debug = "true" *) reg z3addr_in_reg;
  599. (* mark_debug = "true" *) reg z3addr_autoconfig;
  600. `ifdef ZORRO3
  601. reg ZORRO3 = 1;
  602. `else
  603. reg ZORRO3 = 0;
  604. `endif
  605. (* mark_debug = "true" *) reg dataout;
  606. (* mark_debug = "true" *) reg dataout_z3;
  607. (* mark_debug = "true" *) reg dataout_enable;
  608. (* mark_debug = "true" *) reg slaven;
  609. (* mark_debug = "true" *) reg dtack;
  610. reg z_reset;
  611. reg z_reset_delayed;
  612. reg z_cfgin;
  613. reg z_cfgin_lo;
  614. reg z3_confdone;
  615. reg zorro_read;
  616. reg zorro_write;
  617. reg zorro_interrupt;
  618. reg clear_interrupt;
  619. assign ZORRO_INT6 = zorro_interrupt;
  620. reg [15:0] data_in;
  621. reg [31:0] rr_data;
  622. reg [15:0] data_out;
  623. reg [15:0] regdata_in;
  624. // ram arbiter
  625. (* mark_debug = "true" *) reg zorro_ram_read_request;
  626. (* mark_debug = "true" *) reg zorro_ram_write_request;
  627. reg [31:0] zorro_ram_read_addr;
  628. reg [3:0] zorro_ram_read_bytes;
  629. reg [31:0] zorro_ram_write_addr;
  630. reg [31:0] zorro_ram_write_data;
  631. reg [3:0] zorro_ram_write_bytes;
  632. reg [15:0] default_data = 'hffff; // causes read/write glitches on A2000 (data bus interference) when 0
  633. reg [1:0] zorro_write_capture_bytes;
  634. reg [15:0] zorro_write_capture_data;
  635. // z3 strobes
  636. reg z3_ds3;
  637. reg z3_ds2;
  638. reg z3_ds1;
  639. reg z3_ds0;
  640. // level shifter direction pins
  641. assign ZORRO_DATADIR = ZORRO_DOE & (dataout_enable | dataout_z3); // d2-d9 d10-15, d0-d1
  642. assign ZORRO_ADDRDIR = ZORRO_DOE & (dataout_z3); // a16-a23 <- input a8-a15 <- input
  643. assign ZORRO_ADDRDIR2 = 0; //ZORRO_DOE & (dataout_z3_latched);
  644. assign ZORRO_NBRN = 1; // TODO busmastering
  645. // data/addr out signals are gated by master's DOE signal
  646. wire ZORRO_DATA_T = ~(ZORRO_DOE & (dataout_enable | dataout_z3));
  647. wire ZORRO_ADDR_T = ~(ZORRO_DOE & dataout_z3);
  648. reg z_ovr = 0;
  649. assign ZORRO_NCINH = z_ovr?1'b1:1'b0; // inverse
  650. // "slave" signals are gated by master's FCS signal
  651. assign ZORRO_NSLAVE = (ZORRO_DOE & slaven)?1'b0:1'b1; // cannot gate by FCS for Z2
  652. assign ZORRO_NDTACK = (ZORRO_DOE & dtack) ?1'b1:1'b0; // inverse, pull-down transistor on output
  653. wire [22:0] z3_addr_out = {data_z3_low16_latched, 7'bZZZ_ZZZZ}; // FIXME this creates tri-cell warning?
  654. //wire [22:0] z3_addr_out = {data_z3_low16_latched, 7'b111_1111}; // FIXME this creates tri-cell warning?
  655. wire [15:0] ZORRO_DATA_IN;
  656. wire [22:0] ZORRO_ADDR_IN;
  657. genvar i;
  658. generate
  659. for (i=0; i < 16; i=i+1) begin : ZORRO_DATABUS
  660. IOBUF u_iobuf_dq
  661. (
  662. .I (ZORRO3 ? data_z3_hi16_latched[i] : data_out[i]),
  663. .T (ZORRO_DATA_T),
  664. .IO (ZORRO_DATA[i]),
  665. .O (ZORRO_DATA_IN[i])
  666. );
  667. end
  668. endgenerate
  669. generate
  670. for (i=0; i < 23; i=i+1) begin : ZORRO_ADDRBUS
  671. IOBUF u_iobuf_dq
  672. (
  673. .I (z3_addr_out[i]),
  674. .T (ZORRO_ADDR_T),
  675. .IO (ZORRO_ADDR[i]),
  676. .O (ZORRO_ADDR_IN[i])
  677. );
  678. end
  679. endgenerate
  680. // autoconf output signal
  681. reg z_confout = 0;
  682. assign ZORRO_NCFGOUT = ZORRO_NCFGIN?1'b1:(~z_confout);
  683. reg [7:0] video_debug_reg;
  684. assign arm_interrupt = zorro_ram_write_request | zorro_ram_read_request;
  685. // -- synchronizers ------------------------------------------
  686. always @(posedge S_AXI_ACLK) begin
  687. znUDS_sync <= {znUDS_sync[1:0],ZORRO_NUDS};
  688. znLDS_sync <= {znLDS_sync[1:0],ZORRO_NLDS};
  689. znAS_sync <= {znAS_sync[3:0],ZORRO_NCCS};
  690. zREAD_sync <= {zREAD_sync[1:0],ZORRO_READ};
  691. znDS1_sync <= {znDS1_sync[1:0],ZORRO_NDS1};
  692. znDS0_sync <= {znDS0_sync[1:0],ZORRO_NDS0};
  693. znFCS_sync <= {znFCS_sync[3:0],ZORRO_NFCS};
  694. znCFGIN_sync<= {znCFGIN_sync[1:0],ZORRO_NCFGIN};
  695. zDOE_sync <= {zDOE_sync[0],ZORRO_DOE};
  696. znRST_sync <= {znRST_sync[0],ZORRO_NIORST};
  697. // Z2 ------------------------------------------------
  698. `ifdef ZORRO2
  699. // READ and nAS can happen dangerously close to each other. so we delay
  700. // the recognition of a valid Z2 cycle 2 clocks more than the other signals.
  701. z2_addr_valid <= (znAS_sync[4]==0 && znAS_sync[3]==0);
  702. z2_read <= (zREAD_sync[2] == 1'b1);
  703. z2_write <= (zREAD_sync[2] == 1'b0);
  704. zaddr <= ZORRO_ADDR_IN[22:0];
  705. zaddr_sync <= zaddr;
  706. zaddr_sync2 <= zaddr_sync;
  707. z2_mapped_addr <= {zaddr_sync2[22:0],1'b0};
  708. z2_datastrobe_synced <= ((znUDS_sync[2]==0 && znUDS_sync[1]==0) || (znLDS_sync[2]==0 && znLDS_sync[1]==0));
  709. z2_uds <= (znUDS_sync[2]==0 && znUDS_sync[1]==0);
  710. z2_lds <= (znLDS_sync[2]==0 && znLDS_sync[1]==0);
  711. zdata_in_sync2 <= ZORRO_DATA_IN;
  712. zdata_in_sync <= zdata_in_sync2;
  713. z2addr_in_ram <= (z2_mapped_addr>=ram_low && z2_mapped_addr<ram_high);
  714. z2addr_in_reg <= (z2_mapped_addr>=reg_low && z2_mapped_addr<reg_high);
  715. // FIXME was 1
  716. if (znAS_sync[4]==0 && z2_mapped_addr>=`AUTOCONF_LOW && z2_mapped_addr<`AUTOCONF_HIGH)
  717. z2addr_autoconfig <= 1'b1;
  718. else
  719. z2addr_autoconfig <= 1'b0;
  720. `endif
  721. // Z3 ------------------------------------------------
  722. `ifdef ZORRO3
  723. // sample z3addr on falling edge of /FCS
  724. // according to Z3 spec, we have max 25ns to react to falling FCS.
  725. case (znFCS_sync[1:0])
  726. 2'b01: begin
  727. z3_fcs_state <= 1;
  728. z3addr <= 0;
  729. end
  730. 2'b10: begin
  731. z3_fcs_state <= 0;
  732. z3addr <= z3addr2;
  733. end
  734. endcase
  735. z3addr2 <= {ZORRO_DATA_IN[15:8],ZORRO_ADDR_IN[22:1],2'b00};
  736. z3addr_in_ram <= (z3addr >= z3_ram_low) && (z3addr < z3_ram_high);
  737. z3addr_in_reg <= (z3addr >= z3_reg_low) && (z3addr < z3_reg_high);
  738. z3_ds0 <= ~znDS0_sync[1];
  739. z3_ds1 <= ~znDS1_sync[1];
  740. z3_ds2 <= ~znLDS_sync[1];
  741. z3_ds3 <= ~znUDS_sync[1];
  742. z3addr_autoconfig <= (z3addr[31:16]=='hff00);
  743. z3_mapped_addr <= (z3addr-z3_ram_low);
  744. z3_din_high_s2 <= ZORRO_DATA_IN; //zD[15:0];
  745. z3_din_low_s2 <= ZORRO_ADDR_IN[22:7]; //zA[22:7];
  746. // pipelined for better timing
  747. data_z3_hi16_latched <= data_z3_hi16;
  748. data_z3_low16_latched <= data_z3_low16;
  749. zorro_read <= zREAD_sync[0];
  750. zorro_write <= ~zREAD_sync[0];
  751. `endif
  752. z_reset_delayed <= (znRST_sync==2'b00);
  753. z_reset <= z_reset_delayed;
  754. z_cfgin <= (znCFGIN_sync==3'b000);
  755. z_cfgin_lo <= (znCFGIN_sync==3'b111);
  756. //video_debug_reg <= video_debug;
  757. end // always @ (posedge S_AXI_ACLK)
  758. reg [15:0] REVISION = 'h7a09; // z9
  759. // main FSM
  760. localparam RESET = 0;
  761. localparam Z2_CONFIGURING = 1;
  762. localparam Z2_IDLE = 2;
  763. localparam WAIT_WRITE = 3;
  764. localparam WAIT_WRITE2 = 4;
  765. localparam Z2_WRITE_FINALIZE = 5;
  766. localparam WAIT_READ = 6;
  767. localparam WAIT_READ2 = 7;
  768. localparam WAIT_READ3 = 8;
  769. localparam CONFIGURED = 9;
  770. localparam CONFIGURED_CLEAR = 10;
  771. localparam DECIDE_Z2_Z3 = 11;
  772. localparam Z3_IDLE = 12;
  773. localparam Z3_WRITE_UPPER = 13;
  774. localparam Z3_WRITE_LOWER = 14;
  775. localparam Z3_READ_UPPER = 15;
  776. localparam Z3_READ_LOWER = 16;
  777. localparam Z3_READ_DELAY = 17;
  778. localparam Z3_READ_DELAY1 = 18;
  779. localparam Z3_READ_DELAY2 = 19;
  780. localparam Z3_WRITE_PRE = 20;
  781. localparam Z3_WRITE_FINALIZE = 21;
  782. localparam Z3_ENDCYCLE = 22;
  783. localparam Z3_DTACK = 23;
  784. localparam Z3_CONFIGURING = 24;
  785. localparam Z2_REGWRITE = 25;
  786. localparam REGWRITE = 26;
  787. localparam REGREAD = 27;
  788. localparam Z2_REGREAD_POST = 28;
  789. localparam Z3_REGREAD_POST = 29;
  790. localparam Z3_REGWRITE = 30;
  791. localparam Z2_REGREAD = 31;
  792. localparam Z3_REGREAD = 32;
  793. localparam Z2_PRE_CONFIGURED = 34;
  794. localparam Z2_ENDCYCLE = 35;
  795. localparam WAIT_WRITE_DMA_Z2 = 36;
  796. localparam WAIT_WRITE_DMA_Z2_FINALIZE = 37;
  797. localparam RESET_DVID = 39;
  798. localparam COLD = 40;
  799. localparam WAIT_READ2B = 41; // delay states
  800. localparam WAIT_READ2C = 42;
  801. localparam WAIT_READ2D = 54;
  802. localparam WAIT_WRITE_DMA_Z3 = 43;
  803. localparam WAIT_WRITE_DMA_Z3_FINALIZE = 44;
  804. localparam Z3_AUTOCONF_READ = 45;
  805. localparam Z3_AUTOCONF_WRITE = 46;
  806. localparam Z3_AUTOCONF_READ_DLY = 47;
  807. localparam Z3_AUTOCONF_READ_DLY2 = 48;
  808. localparam Z3_REGWRITE_PRE = 49;
  809. localparam Z3_REGREAD_PRE = 50;
  810. localparam Z3_WRITE_PRE2 = 51;
  811. localparam WAIT_WRITE_DMA_Z3B = 52;
  812. localparam WAIT_WRITE_DMA_Z3C = 53;
  813. localparam WAIT_READ_DMA_Z3 = 54;
  814. localparam WAIT_READ_DMA_Z3B = 55;
  815. localparam WAIT_READ_DMA_Z3C = 56;
  816. (* mark_debug = "true" *) reg [7:0] zorro_state = COLD;
  817. reg zorro_idle;
  818. reg [7:0] read_counter; // used by Z3
  819. `ifdef ZORRO2
  820. // experimentally found for TF536
  821. reg [5:0] dtack_timeout = 'h02; // number of cycles before we turn off our dtack signal
  822. `else
  823. reg [5:0] dtack_timeout = 6; // number of cycles before we turn off our dtack signal
  824. `endif
  825. reg [7:0] dataout_time = 'h02;
  826. reg [23:0] last_addr;
  827. reg [23:0] last_read_addr;
  828. reg [15:0] last_data;
  829. reg [15:0] last_read_data;
  830. reg [15:0] zaddr_regpart;
  831. reg [15:0] z3addr_regpart;
  832. reg [15:0] regread_addr;
  833. reg [15:0] regwrite_addr;
  834. reg [31:0] axi_reg0;
  835. reg [31:0] axi_reg1;
  836. reg [31:0] axi_reg2;
  837. reg [31:0] axi_reg3;
  838. reg [31:0] axi_reg4;
  839. reg [31:0] axi_reg5;
  840. reg [31:0] frfb;
  841. reg [31:0] usbb;
  842. reg [31:0] video_control_data_zorro;
  843. reg [7:0] video_control_op_zorro;
  844. reg [31:0] video_control_data_axi;
  845. reg [7:0] video_control_op_axi;
  846. reg video_control_axi;
  847. reg [31:0] video_control_data; // to output
  848. reg [7:0] video_control_op; // to output
  849. reg video_control_vblank; // from input
  850. reg video_control_interlace;
  851. reg zorro_ram_read_flag;
  852. reg zorro_ram_write_flag ;
  853. reg videocap_mode;
  854. reg videocap_mode_in;
  855. (* mark_debug = "true" *) reg [6:0] videocap_hs;
  856. (* mark_debug = "true" *) reg [6:0] videocap_vs;
  857. reg [23:0] videocap_rgbin = 0;
  858. (* mark_debug = "true" *) reg [9:0] videocap_x;
  859. (* mark_debug = "true" *) reg [9:0] videocap_y;
  860. (* mark_debug = "true" *) reg [9:0] videocap_x2;
  861. (* mark_debug = "true" *) reg videocap_x_done;
  862. (* mark_debug = "true" *) reg [9:0] videocap_y2;
  863. (* mark_debug = "true" *) reg [9:0] videocap_y_sync;
  864. (* mark_debug = "true" *) reg [9:0] videocap_ymax;
  865. (* mark_debug = "true" *) reg [9:0] videocap_ymax2;
  866. (* mark_debug = "true" *) reg [9:0] videocap_ymax_sync;
  867. (* mark_debug = "true" *) reg [9:0] videocap_y3;
  868. reg vc_next_lace_field = 0;
  869. reg [3:0] vc_shortlines = 0;
  870. parameter VCAPW = 799;
  871. reg [31:0] videocap_buf [0:VCAPW];
  872. reg videocap_lace_field;
  873. (* mark_debug = "true" *) reg videocap_interlace;
  874. (* mark_debug = "true" *) reg videocap_ntsc;
  875. (* mark_debug = "true" *) reg [7:0] videocap_hs_pulse_width;
  876. reg E7M_PSEN = 0;
  877. reg E7M_PSINCDEC = 0;
  878. wire clkfbout_zz9000_ps_clk_wiz_1_0;
  879. wire e7m_shifted;
  880. wire e7m_shifted180;
  881. // video capture clock adjustment
  882. MMCME2_ADV #(
  883. .BANDWIDTH("OPTIMIZED"),
  884. .CLKFBOUT_MULT_F(32.000000),
  885. .CLKFBOUT_PHASE(0.000000),
  886. .CLKFBOUT_USE_FINE_PS("TRUE"),
  887. .CLKIN1_PERIOD(35.000000),
  888. .CLKIN2_PERIOD(0.000000),
  889. .CLKOUT0_DIVIDE_F(16.000000),
  890. .CLKOUT0_DUTY_CYCLE(0.500000),
  891. `ifdef ZORRO3
  892. .CLKOUT0_PHASE(0.000000),
  893. `elsif VARIANT_SUPERDENISE
  894. .CLKOUT0_PHASE(0.000000),
  895. `elsif VARIANT_ZZ9500
  896. .CLKOUT0_PHASE(90.000000),
  897. `else
  898. .CLKOUT0_PHASE(315.000000),
  899. `endif
  900. .CLKOUT0_USE_FINE_PS("TRUE"),
  901. .CLKOUT1_DIVIDE(32),
  902. .CLKOUT1_DUTY_CYCLE(0.500000),
  903. `ifdef ZORRO3
  904. .CLKOUT1_PHASE(0.000000),
  905. `elsif VARIANT_SUPERDENISE
  906. .CLKOUT1_PHASE(0.000000),
  907. `elsif VARIANT_ZZ9500
  908. .CLKOUT1_PHASE(270.000000),
  909. `else
  910. .CLKOUT1_PHASE(135.000000),
  911. `endif
  912. .CLKOUT1_USE_FINE_PS("TRUE"),
  913. .COMPENSATION("ZHOLD"),
  914. .DIVCLK_DIVIDE(1),
  915. .IS_CLKINSEL_INVERTED(1'b0),
  916. .IS_PSEN_INVERTED(1'b0),
  917. .IS_PSINCDEC_INVERTED(1'b0),
  918. .IS_PWRDWN_INVERTED(1'b0),
  919. .IS_RST_INVERTED(1'b0),
  920. .REF_JITTER1(0.001000),
  921. .REF_JITTER2(0.001000),
  922. .SS_EN("FALSE"),
  923. .SS_MODE("CENTER_HIGH"),
  924. .SS_MOD_PERIOD(10000),
  925. .STARTUP_WAIT("FALSE"))
  926. mmcm_adv_inst
  927. (.CLKFBIN(clkfbout_zz9000_ps_clk_wiz_1_0),
  928. .CLKFBOUT(clkfbout_zz9000_ps_clk_wiz_1_0),
  929. //.CLKFBOUTB(NLW_mmcm_adv_inst_CLKFBOUTB_UNCONNECTED),
  930. //.CLKFBSTOPPED(NLW_mmcm_adv_inst_CLKFBSTOPPED_UNCONNECTED),
  931. .CLKIN1(ZORRO_E7M),
  932. .CLKIN2(1'b0),
  933. .CLKINSEL(1'b1),
  934. //.CLKINSTOPPED(NLW_mmcm_adv_inst_CLKINSTOPPED_UNCONNECTED),
  935. .CLKOUT0(e7m_shifted),
  936. //.CLKOUT0B(NLW_mmcm_adv_inst_CLKOUT0B_UNCONNECTED),
  937. .CLKOUT1(e7m_shifted180),
  938. //.CLKOUT1B(NLW_mmcm_adv_inst_CLKOUT1B_UNCONNECTED),
  939. .DADDR({1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0}),
  940. .DCLK(1'b0),
  941. .DEN(1'b0),
  942. .DI({1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0,1'b0}),
  943. //.DO(NLW_mmcm_adv_inst_DO_UNCONNECTED[15:0]),
  944. //.DRDY(NLW_mmcm_adv_inst_DRDY_UNCONNECTED),
  945. .DWE(1'b0),
  946. //.LOCKED(NLW_mmcm_adv_inst_LOCKED_UNCONNECTED),
  947. .PSCLK(S_AXI_ACLK),
  948. //.PSDONE(psdone),
  949. .PSEN(E7M_PSEN),
  950. .PSINCDEC(E7M_PSINCDEC),
  951. .PWRDWN(1'b0),
  952. .RST(1'b0));
  953. always @(posedge e7m_shifted) begin
  954. videocap_vs <= {videocap_vs[5:0], VCAP_VSYNC};
  955. videocap_hs <= {videocap_hs[5:0], VCAP_HSYNC};
  956. `ifdef VARIANT_ZZ9500
  957. videocap_rgbin <= {VCAP_R3,VCAP_R2,VCAP_R1,VCAP_R0,VCAP_R3,VCAP_R2,VCAP_R1,VCAP_R0,
  958. VCAP_G3,VCAP_G2,VCAP_G1,VCAP_G0,VCAP_G3,VCAP_G2,VCAP_G1,VCAP_G0,
  959. VCAP_B3,VCAP_B2,VCAP_B1,VCAP_B0,VCAP_B3,VCAP_B2,VCAP_B1,VCAP_B0};
  960. `elsif ZORRO2
  961. videocap_rgbin <= {VCAP_R7,VCAP_R6,VCAP_R5,VCAP_R4,VCAP_R7,VCAP_R6,VCAP_R5,VCAP_R4,
  962. VCAP_G7,VCAP_G6,VCAP_G5,VCAP_G4,VCAP_G7,VCAP_G6,VCAP_G5,VCAP_G4,
  963. VCAP_B7,VCAP_B6,VCAP_B5,VCAP_B4,VCAP_B7,VCAP_B6,VCAP_B5,VCAP_B4};
  964. `else
  965. videocap_rgbin <= {VCAP_R7,VCAP_R6,VCAP_R5,VCAP_R4,VCAP_R3,VCAP_R2,VCAP_R1,VCAP_R0,
  966. VCAP_G7,VCAP_G6,VCAP_G5,VCAP_G4,VCAP_G3,VCAP_G2,VCAP_G1,VCAP_G0,
  967. VCAP_B7,VCAP_B6,VCAP_B5,VCAP_B4,VCAP_B3,VCAP_B2,VCAP_B1,VCAP_B0};
  968. `endif
  969. if (videocap_hs==0) begin
  970. if (videocap_hs_pulse_width<'hff)
  971. videocap_hs_pulse_width<=videocap_hs_pulse_width+1;
  972. end else if (videocap_hs=='b111111)
  973. videocap_hs_pulse_width<=0;
  974. `ifdef VARIANT_ZZ9500
  975. // on A500, HSYNC is really CSYNC and we can recognize vertical sync
  976. // by looking at the pulse width of it
  977. // direct sampling from denise
  978. if(videocap_hs[6:1]=='b000111 && videocap_hs_pulse_width>=128) begin
  979. if (videocap_ymax[0]) begin
  980. videocap_interlace <= 1;
  981. end else begin
  982. videocap_interlace <= 0;
  983. end
  984. videocap_lace_field <= vc_next_lace_field;
  985. if (videocap_ymax>='h130)
  986. videocap_ntsc <= 0;
  987. else
  988. videocap_ntsc <= 1;
  989. if (videocap_interlace) begin
  990. videocap_y2 <= 0;
  991. videocap_y3 <= vc_next_lace_field;
  992. end else begin
  993. videocap_y2 <= 0;
  994. videocap_y3 <= 0;
  995. end
  996. `else
  997. // with videoslot machines, we have a real VSYNC to work with
  998. if (videocap_vs[6:1]=='b111000) begin
  999. if (videocap_ymax[0]!=videocap_ymax2[0])
  1000. videocap_interlace <= 1;
  1001. else
  1002. videocap_interlace <= 0;
  1003. videocap_lace_field <= videocap_ymax[0];
  1004. if (videocap_ymax>='h138)
  1005. videocap_ntsc <= 0;
  1006. else
  1007. videocap_ntsc <= 1;
  1008. if (videocap_interlace) begin
  1009. videocap_y2 <= 0;
  1010. videocap_y3 <= videocap_lace_field;
  1011. end else begin
  1012. videocap_y2 <= 0;
  1013. videocap_y3 <= 0;
  1014. end
  1015. `endif
  1016. if (videocap_y2!=0) begin
  1017. videocap_ymax <= videocap_y2;
  1018. videocap_ymax2 <= videocap_ymax;
  1019. end
  1020. end else if (videocap_hs[6:1]=='b000111) begin
  1021. videocap_x <= 0;
  1022. videocap_x2 <= 0;
  1023. `ifdef VARIANT_ZZ9500
  1024. if (videocap_hs_pulse_width < 'h20) begin
  1025. // count short pulses terminating lines
  1026. vc_shortlines <= vc_shortlines+1;
  1027. if (vc_shortlines==0) begin
  1028. // first time
  1029. if (videocap_x>='h200)
  1030. // last line was long?
  1031. vc_next_lace_field <= 1;
  1032. else
  1033. vc_next_lace_field <= 0;
  1034. end
  1035. end else
  1036. vc_shortlines <= 0;
  1037. `endif
  1038. if (videocap_y2>'h1a) begin
  1039. if (videocap_interlace)
  1040. videocap_y3 <= videocap_y3 + 2'b10;
  1041. else
  1042. videocap_y3 <= videocap_y3 + 1'b1;
  1043. end
  1044. videocap_y2 <= videocap_y2 + 1'b1;
  1045. end else if (videocap_x2<'h5e) begin // 5a worked
  1046. // left crop
  1047. videocap_x2 <= videocap_x2 + 1'b1;
  1048. end else begin
  1049. videocap_x <= videocap_x + 1'b1;
  1050. end
  1051. if (videocap_x>2)
  1052. videocap_buf[videocap_x] <= videocap_rgbin;
  1053. else
  1054. videocap_buf[videocap_x] <= 0;
  1055. if (videocap_x>'h200)
  1056. videocap_x_done <= 1;
  1057. else
  1058. videocap_x_done <= 0;
  1059. end
  1060. reg [11:0] videocap_save_x;
  1061. reg [11:0] videocap_save_x2;
  1062. reg [11:0] videocap_save_x3;
  1063. reg [11:0] videocap_yoffset;
  1064. reg [11:0] videocap_xoffset;
  1065. reg [11:0] videocap_pitch;
  1066. reg [11:0] videocap_pitch_sync;
  1067. reg [11:0] videocap_pitch_snoop;
  1068. reg videocap_pitch_snooped;
  1069. reg [9:0] videocap_save_line_done;
  1070. reg [11:0] videocap_save_y;
  1071. reg [31:0] videocap_save_y2;
  1072. reg [31:0] videocap_save_addr;
  1073. reg [3:0] videocap_save_state;
  1074. reg videocap_mode_sync;
  1075. reg [31:0] m01_axi_awaddr_out;
  1076. reg [31:0] m01_axi_wdata_out;
  1077. reg m01_axi_awvalid_out = 0;
  1078. reg m01_axi_wvalid_out = 0;
  1079. reg [31:0] m00_axi_awaddr_z3;
  1080. reg [31:0] m00_axi_wdata_z3;
  1081. reg m00_axi_awvalid_z3 = 0;
  1082. reg m00_axi_wvalid_z3 = 0;
  1083. reg [3:0] m00_axi_wstrb_z3;
  1084. assign m00_axi_awaddr = m00_axi_awaddr_z3;
  1085. assign m00_axi_awvalid = m00_axi_awvalid_z3;
  1086. assign m00_axi_wdata = m00_axi_wdata_z3;
  1087. assign m00_axi_wstrb = m00_axi_wstrb_z3;
  1088. assign m00_axi_wvalid = m00_axi_wvalid_z3;
  1089. assign m01_axi_awaddr = m01_axi_awaddr_out;
  1090. assign m01_axi_awvalid = m01_axi_awvalid_out;
  1091. assign m01_axi_wdata = m01_axi_wdata_out;
  1092. assign m01_axi_wstrb = 4'b1111;
  1093. assign m01_axi_wvalid = m01_axi_wvalid_out;
  1094. // AXI DMA defaults
  1095. always @(posedge S_AXI_ACLK) begin
  1096. m00_axi_awlen <= 'h0; // 1 burst (1 write)
  1097. m00_axi_awsize <= 'h2; // 2^2 == 4 bytes
  1098. m00_axi_awburst <= 'h0; // FIXED (non incrementing)
  1099. m00_axi_awcache <= 'h3;
  1100. m00_axi_awlock <= 'h0;
  1101. m00_axi_awprot <= 'h0;
  1102. //m00_axi_awqos <= 'h0;
  1103. m00_axi_wlast <= 'h1;
  1104. m00_axi_bready <= 'h1;
  1105. m00_axi_arlen <= 'h0;
  1106. m00_axi_arsize <= 'h2;
  1107. m00_axi_arburst <= 'h0;
  1108. m00_axi_arcache <= 'hf; //was 3
  1109. m00_axi_arlock <= 'h0;
  1110. m00_axi_arprot <= 'h0;
  1111. //m00_axi_arqos <= 'h0;
  1112. m00_axi_rready <= 1;
  1113. // FIXME this could use bursts
  1114. m01_axi_awlen <= 'h0; // 1 burst (1 write)
  1115. m01_axi_awsize <= 'h2; //'h2; // 2^2 == 4 bytes
  1116. m01_axi_awburst <= 'h0; // FIXED (non incrementing)
  1117. m01_axi_awcache <= 'h0;
  1118. m01_axi_awlock <= 'h0;
  1119. m01_axi_awprot <= 'h0;
  1120. m01_axi_awqos <= 'h0;
  1121. m01_axi_wlast <= 'h1;
  1122. m01_axi_bready <= 'h1;
  1123. `ifdef ZORRO2
  1124. // ZORRO2 doesn't implement AXI DMA read yet
  1125. m00_axi_araddr <= 0;
  1126. m00_axi_arvalid <= 0;
  1127. m00_axi_rready <= 0;
  1128. `endif
  1129. end
  1130. reg [9:0] videocap_x_sync;
  1131. reg [9:0] vc_saving_line;
  1132. reg [9:0] videocap_y_sync2;
  1133. // pipeline stages for videocap save addr calculation
  1134. reg [31:0] vc_saveaddr1;
  1135. reg [31:0] vc_saveaddr2;
  1136. always @(posedge S_AXI_ACLK) begin
  1137. // VIDEOCAP
  1138. // pass interlace mode to video control block
  1139. video_control_interlace <= videocap_interlace;
  1140. videocap_pitch_sync <= videocap_pitch;
  1141. //videocap_x_sync <= videocap_x;
  1142. videocap_y_sync2 <= videocap_y3;
  1143. videocap_mode_sync <= videocap_mode;
  1144. `ifdef VARIANT_ZZ9500
  1145. if (videocap_interlace)
  1146. videocap_ymax_sync <= (videocap_ymax<<1)-(2*40);
  1147. else
  1148. videocap_ymax_sync <= videocap_ymax-36;
  1149. // letterbox top and bottom to box out noisy lines
  1150. if (videocap_y_sync2<videocap_ymax_sync && videocap_x_done) begin
  1151. videocap_y_sync <= videocap_y_sync2;
  1152. end
  1153. `else
  1154. if (videocap_interlace)
  1155. videocap_ymax_sync <= (videocap_ymax<<1);
  1156. else
  1157. videocap_ymax_sync <= videocap_ymax;
  1158. if (videocap_x_done) begin
  1159. videocap_y_sync <= videocap_y_sync2;
  1160. end
  1161. `endif
  1162. videocap_save_x2 <= videocap_save_x;
  1163. vc_saveaddr1 <= vc_saving_line*videocap_pitch_sync;
  1164. // we shift left by 2 bits to scale from 1 pixel to 4 bytes
  1165. vc_saveaddr2 <= (vc_saveaddr1+videocap_save_x)<<2;
  1166. // FIXME
  1167. if (videocap_save_line_done!=videocap_y_sync) begin
  1168. vc_saving_line <= videocap_y_sync;
  1169. end
  1170. if (m01_axi_aresetn == 0) begin
  1171. videocap_save_state <= 4;
  1172. //m01_axi_wvalid_out <= 0;
  1173. //m01_axi_awvalid_out <= 0;
  1174. end else begin
  1175. m01_axi_awaddr_out <= `VIDEOCAP_ADDR+vc_saveaddr2;
  1176. m01_axi_wdata_out <= videocap_buf[videocap_save_x];
  1177. // one-hot encoded
  1178. case (videocap_save_state)
  1179. 4'h0: begin
  1180. // initial state
  1181. if (m01_axi_awready) begin
  1182. videocap_save_state <= 2;
  1183. end
  1184. end
  1185. 4'h1: begin
  1186. m01_axi_awvalid_out <= 0;
  1187. m01_axi_wvalid_out <= 1;
  1188. if (m01_axi_wready) begin
  1189. videocap_save_state <= 2;
  1190. end
  1191. end
  1192. 4'h2: begin
  1193. // FIXME this was moved from state 1 wready clause
  1194. `ifdef VARIANT_ZZ9500
  1195. if (videocap_save_x >= videocap_pitch_sync-2) begin
  1196. `else
  1197. if (videocap_save_x >= videocap_pitch_sync) begin // 728 FIXME
  1198. `endif
  1199. videocap_save_line_done <= vc_saving_line;
  1200. videocap_save_x <= 0;
  1201. end else if (videocap_save_line_done != vc_saving_line)
  1202. videocap_save_x <= videocap_save_x + 1'b1;
  1203. m01_axi_awvalid_out <= 1;
  1204. m01_axi_wvalid_out <= 0;
  1205. if (m01_axi_awready) begin
  1206. if (videocap_mode_sync)
  1207. videocap_save_state <= 1;
  1208. else
  1209. videocap_save_state <= 4;
  1210. end
  1211. end
  1212. 4'h4: begin
  1213. // videocap is disabled, lets wait here
  1214. if (videocap_mode_sync)
  1215. videocap_save_state <= 0;
  1216. m01_axi_wvalid_out <= 0;
  1217. m01_axi_awvalid_out <= 0;
  1218. end
  1219. endcase
  1220. end
  1221. end
  1222. // -- main zorro fsm ---------------------------------------------
  1223. always @(posedge S_AXI_ACLK) begin
  1224. zorro_idle <= ((zorro_state==Z2_IDLE)||(zorro_state==Z3_IDLE));
  1225. `ifndef VARIANT_FW20
  1226. // FIXME videocap disabled for FW20
  1227. videocap_mode <= videocap_mode_in;
  1228. `endif
  1229. if (/*z_cfgin_lo ||*/ z_reset) begin
  1230. zorro_state <= RESET;
  1231. end //else
  1232. case (zorro_state)
  1233. COLD: begin
  1234. zorro_state <= RESET;
  1235. end
  1236. RESET: begin
  1237. dataout_enable <= 0;
  1238. dataout <= 0;
  1239. dataout_z3 <= 0;
  1240. slaven <= 0;
  1241. dtack <= 0;
  1242. z_ovr <= 0;
  1243. z_confout <= 0;
  1244. z3_confdone <= 0;
  1245. zorro_ram_read_request <= 0;
  1246. zorro_ram_write_request <= 0;
  1247. zorro_ram_read_flag <= 0;
  1248. zorro_ram_write_flag <= 0;
  1249. videocap_mode_in <= 0;
  1250. videocap_pitch <= 720; // FIXME?
  1251. if (!z_reset)
  1252. zorro_state <= DECIDE_Z2_Z3;
  1253. // uncomment this to have native video capture
  1254. // directly on startup, before/without autoconfig.
  1255. // we don't do this by default because it messes
  1256. // up the timing sometimes.
  1257. //videocap_mode_in <= 1;
  1258. end
  1259. DECIDE_Z2_Z3: begin
  1260. `ifdef ZORRO2
  1261. if (z2addr_autoconfig) begin
  1262. //ZORRO3 <= 0;
  1263. zorro_state <= Z2_CONFIGURING;
  1264. end
  1265. `endif
  1266. `ifdef ZORRO3
  1267. if (z3addr_autoconfig) begin
  1268. //ZORRO3 <= 1;
  1269. zorro_state <= Z3_CONFIGURING;
  1270. end
  1271. `endif
  1272. end
  1273. `ifdef ZORRO3
  1274. Z3_AUTOCONF_READ_DLY: begin
  1275. // wait for data to be latched out
  1276. zorro_state <= Z3_AUTOCONF_READ_DLY2;
  1277. end
  1278. Z3_AUTOCONF_READ_DLY2: begin
  1279. // wait for data to be latched out
  1280. zorro_state <= Z3_DTACK;
  1281. end
  1282. Z3_AUTOCONF_READ: begin
  1283. dataout_z3 <= 1;
  1284. slaven <= 1;
  1285. zorro_state <= Z3_AUTOCONF_READ_DLY;
  1286. last_z3addr <= z3addr;
  1287. case (z3addr[15:0])
  1288. 'h0000: data_z3_hi16 <= 'b1000_1111_1111_1111; // zorro 3 (10), no pool link (0), autoboot ROM (1)
  1289. 'h0100: data_z3_hi16 <= 'b0100_1111_1111_1111; // next board unrelated (0), 256MB 1024MB fixme
  1290. 'h0004: data_z3_hi16 <= 'b1111_1111_1111_1111; // product number
  1291. 'h0104: data_z3_hi16 <= 'b1011_1111_1111_1111; // (4)
  1292. 'h0008: data_z3_hi16 <= 'b0000_1111_1111_1111; // flags inverted 0111 io,shutup,extension,reserved(1)
  1293. 'h0108: data_z3_hi16 <= 'b1111_1111_1111_1111; // inverted zero
  1294. 'h000c: data_z3_hi16 <= 'b1111_1111_1111_1111; // reserved?
  1295. 'h010c: data_z3_hi16 <= 'b1111_1111_1111_1111; //
  1296. 'h0010: data_z3_hi16 <= 'b1001_1111_1111_1111; // manufacturer high byte inverted
  1297. 'h0110: data_z3_hi16 <= 'b0010_1111_1111_1111; //
  1298. 'h0014: data_z3_hi16 <= 'b1001_1111_1111_1111; // manufacturer low byte
  1299. 'h0114: data_z3_hi16 <= 'b0001_1111_1111_1111;
  1300. 'h0018: data_z3_hi16 <= 'b1111_1111_1111_1111; // serial 01 01 01 01
  1301. 'h0118: data_z3_hi16 <= 'b1110_1111_1111_1111; //
  1302. 'h001c: data_z3_hi16 <= 'b1111_1111_1111_1111; //
  1303. 'h011c: data_z3_hi16 <= 'b1110_1111_1111_1111; //
  1304. 'h0020: data_z3_hi16 <= 'b1111_1111_1111_1111; //
  1305. 'h0120: data_z3_hi16 <= 'b1110_1111_1111_1111; //
  1306. 'h0024: data_z3_hi16 <= 'b1111_1111_1111_1111; //
  1307. 'h0124: data_z3_hi16 <= 'b1110_1111_1111_1111; //
  1308. /*'h0028: data_z3_hi16 <= 'b1111_1111_1111_1111; // autoboot rom vector (er_InitDiagVec)
  1309. 'h0128: data_z3_hi16 <= 'b1111_1111_1111_1111; // ff7f = ~0080
  1310. 'h002c: data_z3_hi16 <= 'b0111_1111_1111_1111;
  1311. 'h012c: data_z3_hi16 <= 'b1111_1111_1111_1111;*/
  1312. default: data_z3_hi16 <= 'b1111_1111_1111_1110; // FIXME
  1313. endcase
  1314. end
  1315. Z3_AUTOCONF_WRITE: begin
  1316. slaven <= 1;
  1317. if (z3_ds0||z3_ds1||z3_ds2||z3_ds3) begin
  1318. zorro_state <= Z3_DTACK;
  1319. casex (z3addr[15:0])
  1320. 'hXX44: begin
  1321. z3_ram_low[31:16] <= z3_din_high_s2;
  1322. z_confout <= 1;
  1323. z3_confdone <= 1;
  1324. end
  1325. 'hXX48: begin
  1326. end
  1327. 'hXX4c: begin
  1328. // shutup
  1329. z_confout <= 1;
  1330. z3_confdone <= 1;
  1331. end
  1332. endcase
  1333. end
  1334. end
  1335. Z3_CONFIGURING: begin
  1336. // FIXME why?
  1337. //data_z3_low16 <= 'hffff;
  1338. if (z_cfgin && z3addr_autoconfig) begin
  1339. if (zorro_read) begin
  1340. // autoconfig ROM
  1341. zorro_state <= Z3_AUTOCONF_READ;
  1342. end else begin
  1343. // write to autoconfig register
  1344. zorro_state <= Z3_AUTOCONF_WRITE;
  1345. end
  1346. end
  1347. dataout_z3 <= 0;
  1348. slaven <= 0;
  1349. dtack <= 0;
  1350. end
  1351. Z3_DTACK: begin
  1352. if (z3_fcs_state == 1) begin
  1353. dtack <= 0;
  1354. dataout_z3 <= 0;
  1355. slaven <= 0;
  1356. if (z3_confdone) begin
  1357. zorro_state <= CONFIGURED;
  1358. end else
  1359. zorro_state <= Z3_CONFIGURING;
  1360. end else
  1361. dtack <= 1;
  1362. end
  1363. `endif
  1364. CONFIGURED: begin
  1365. ram_high <= ram_low + `RAM_SIZE;
  1366. reg_low <= ram_low + 'h1000;
  1367. reg_high <= ram_low + 'h2000;
  1368. z3_ram_high <= z3_ram_low + `Z3_RAM_SIZE;
  1369. z3_reg_low <= z3_ram_low + 'h1000;
  1370. z3_reg_high <= z3_ram_low + 'h2000;
  1371. zorro_state <= CONFIGURED_CLEAR;
  1372. end
  1373. CONFIGURED_CLEAR: begin
  1374. // this is a fix for the "pixel swap" bug: if AXI HP is getting writes too early,
  1375. // it would sometimes (~10% of cold starts) get confused and swap pairs of writes.
  1376. `ifndef VARIANT_FW20
  1377. videocap_mode_in <= 1;
  1378. `endif
  1379. `ifdef ZORRO3
  1380. zorro_state <= Z3_IDLE;
  1381. `else
  1382. zorro_state <= Z2_IDLE;
  1383. `endif
  1384. end
  1385. // ---------------------------------------------------------------------------------
  1386. `ifdef ZORRO2
  1387. Z2_CONFIGURING: begin
  1388. z_ovr <= 0;
  1389. if (z2_addr_valid && z2addr_autoconfig && z_cfgin) begin
  1390. if (z2_read) begin
  1391. // read iospace 'he80000 (Autoconfig ROM)
  1392. dataout_enable <= 1;
  1393. dataout <= 1;
  1394. slaven <= 1;
  1395. case (z2_mapped_addr[7:0])
  1396. 8'h00: data_out <= 'b1100_1111_1111_1111; // zorro 2 (11), no pool (0) autoboot rom (0)
  1397. `ifdef VARIANT_2MB
  1398. 8'h02: data_out <= 'b0110_1111_1111_1111; // next board unrelated (0), 2mb (110)
  1399. `else
  1400. 8'h02: data_out <= 'b0111_1111_1111_1111; // next board unrelated (0), 4mb (111)
  1401. `endif
  1402. 8'h04: data_out <= 'b1111_1111_1111_1111; // product number
  1403. 8'h06: data_out <= 'b1100_1111_1111_1111; // (3)
  1404. 8'h08: data_out <= 'b1111_1111_1111_1111; // flags inverted 0000
  1405. 8'h0a: data_out <= 'b1111_1111_1111_1111; // inverted 0000 = log=phys
  1406. 8'h10: data_out <= 'b1001_1111_1111_1111; // manufacturer high byte inverted (02)
  1407. 8'h12: data_out <= 'b0010_1111_1111_1111; //
  1408. 8'h14: data_out <= 'b1001_1111_1111_1111; // manufacturer low byte (9a)
  1409. 8'h16: data_out <= 'b0001_1111_1111_1111;
  1410. /*8'h28: data_out <= 'b1111_1111_1111_1111; // autoboot rom vector (er_InitDiagVec)
  1411. 8'h2a: data_out <= 'b1111_1111_1111_1111; // ff7f = ~0080
  1412. 8'h2c: data_out <= 'b0111_1111_1111_1111;
  1413. 8'h2e: data_out <= 'b1111_1111_1111_1111;*/
  1414. 8'h40: data_out <= 'b0000_0000_0000_0000; // interrupts (not inverted)
  1415. 8'h42: data_out <= 'b0000_0000_0000_0000; //
  1416. default: data_out <= 'b1111_1111_1111_1111;
  1417. endcase
  1418. end else begin
  1419. // write to autoconfig register
  1420. if (z2_datastrobe_synced) begin
  1421. case (z2_mapped_addr[7:0])
  1422. 8'h48: begin
  1423. ram_low[31:24] <= 8'h0;
  1424. ram_low[23:20] <= zdata_in_sync[15:12];
  1425. ram_low[15:0] <= 16'h0;
  1426. zorro_state <= Z2_PRE_CONFIGURED; // configured
  1427. end
  1428. 8'h4a: begin
  1429. ram_low[31:24] <= 8'h0;
  1430. ram_low[19:16] <= zdata_in_sync[15:12];
  1431. ram_low[15:0] <= 16'h0;
  1432. end
  1433. 8'h4c: begin
  1434. zorro_state <= Z2_PRE_CONFIGURED; // configured, shut up
  1435. end
  1436. endcase
  1437. end
  1438. end
  1439. end else begin
  1440. // no address match
  1441. dataout <= 0;
  1442. dataout_enable <= 0;
  1443. slaven <= 0;
  1444. end
  1445. end
  1446. Z2_PRE_CONFIGURED: begin
  1447. if (!z2_addr_valid) begin
  1448. z_confout<=1;
  1449. zorro_state <= CONFIGURED;
  1450. end
  1451. end
  1452. Z2_IDLE: begin
  1453. if (z2_addr_valid) begin
  1454. if (z2_write && z2addr_in_reg) begin
  1455. // write to register
  1456. dataout_enable <= 0;
  1457. dataout <= 0;
  1458. slaven <= 1;
  1459. z_ovr <= 1;
  1460. zaddr_regpart <= z2_mapped_addr;
  1461. zorro_state <= Z2_REGWRITE;
  1462. end else if (z2_read && z2addr_in_reg) begin
  1463. // read from registers
  1464. dataout_enable <= 1;
  1465. dataout <= 1;
  1466. data_out <= default_data; //'hffff;
  1467. slaven <= 1;
  1468. z_ovr <= 1;
  1469. zaddr_regpart <= z2_mapped_addr;
  1470. zorro_state <= Z2_REGREAD;
  1471. end else if (z2_read && z2addr_in_ram) begin
  1472. // read RAM
  1473. // request ram access from arbiter
  1474. last_addr <= z2_mapped_addr-ram_low; // differently done in z3
  1475. data_out <= default_data; //'hffff;
  1476. dataout_enable <= 1;
  1477. dataout <= 1;
  1478. slaven <= 1;
  1479. z_ovr <= 1;
  1480. zorro_state <= WAIT_READ3;
  1481. end else if (z2_write && z2addr_in_ram) begin
  1482. // write RAM
  1483. last_addr <= z2_mapped_addr-ram_low;
  1484. dataout_enable <= 0;
  1485. dataout <= 0;
  1486. slaven <= 1;
  1487. z_ovr <= 1;
  1488. //count_writes <= count_writes + 1;
  1489. zorro_state <= WAIT_WRITE;
  1490. end else begin
  1491. dataout <= 0;
  1492. dataout_enable <= 0;
  1493. slaven <= 0;
  1494. end
  1495. end else begin
  1496. dataout <= 0;
  1497. dataout_enable <= 0;
  1498. slaven <= 0;
  1499. end
  1500. end
  1501. Z2_REGWRITE: begin
  1502. if (z2_datastrobe_synced) begin
  1503. regdata_in <= zdata_in_sync;
  1504. regwrite_addr <= zaddr_regpart;
  1505. zorro_state <= REGWRITE;
  1506. end
  1507. end
  1508. WAIT_READ3: begin
  1509. zorro_ram_read_addr <= last_addr;
  1510. zorro_ram_read_request <= 1;
  1511. zorro_state <= WAIT_READ2;
  1512. end
  1513. WAIT_READ2: begin
  1514. // FIXME there can be a race here where read_request is immediately cancelled
  1515. if (zorro_ram_read_flag) begin
  1516. zorro_ram_read_request <= 0;
  1517. data_out <= axi_reg1[15:0];
  1518. zorro_state <= WAIT_READ2B;
  1519. end
  1520. end
  1521. WAIT_READ2B: begin
  1522. // FIXME trying to fix the race using the same approach as in Z3
  1523. if (!zorro_ram_read_flag) begin
  1524. read_counter <= 0;
  1525. zorro_state <= WAIT_READ2C;
  1526. end
  1527. end
  1528. WAIT_READ2C: begin
  1529. if (read_counter>dataout_time) // FIXME tune this
  1530. zorro_state <= WAIT_READ2D;
  1531. read_counter <= read_counter + 1'b1;
  1532. end
  1533. WAIT_READ2D: begin
  1534. read_counter <= 0;
  1535. dtack <= 1;
  1536. zorro_state <= Z2_ENDCYCLE;
  1537. end
  1538. WAIT_WRITE: begin
  1539. if (z2_datastrobe_synced) begin
  1540. zorro_write_capture_bytes <= {~znUDS_sync[2],~znLDS_sync[2]}; // FIXME was 1
  1541. zorro_write_capture_data <= zdata_in_sync;
  1542. if (last_addr<'h10000)
  1543. zorro_state <= WAIT_WRITE2;
  1544. else
  1545. zorro_state <= WAIT_WRITE_DMA_Z2;
  1546. end
  1547. end
  1548. WAIT_WRITE2: begin
  1549. zorro_ram_write_addr <= last_addr;
  1550. zorro_ram_write_bytes <= {2'b0,zorro_write_capture_bytes};
  1551. zorro_ram_write_data <= {16'b0,zorro_write_capture_data};
  1552. zorro_ram_write_request <= 1;
  1553. zorro_state <= Z2_WRITE_FINALIZE;
  1554. end
  1555. WAIT_WRITE_DMA_Z2: begin
  1556. if (last_addr[1])
  1557. m00_axi_wstrb_z3 <= {zorro_write_capture_bytes[0],zorro_write_capture_bytes[1],2'b0};
  1558. else
  1559. m00_axi_wstrb_z3 <= {2'b0,zorro_write_capture_bytes[0],zorro_write_capture_bytes[1]};
  1560. m00_axi_awaddr_z3 <= (last_addr+`ARM_MEMORY_START)&'hfffffc;
  1561. m00_axi_wdata_z3 <= {zorro_write_capture_data[7:0],zorro_write_capture_data[15:8],zorro_write_capture_data[7:0],zorro_write_capture_data[15:8]};
  1562. m00_axi_awvalid_z3 <= 1;
  1563. if (m00_axi_awready) begin // TODO wready?
  1564. zorro_state <= WAIT_WRITE_DMA_Z2_FINALIZE;
  1565. end
  1566. end
  1567. WAIT_WRITE_DMA_Z2_FINALIZE: begin
  1568. m00_axi_awvalid_z3 <= 0;
  1569. m00_axi_wvalid_z3 <= 1;
  1570. if (m00_axi_wready) begin
  1571. dtack <= 1;
  1572. zorro_state <= Z2_ENDCYCLE;
  1573. end
  1574. end
  1575. Z2_WRITE_FINALIZE: begin
  1576. if (zorro_ram_write_flag) begin
  1577. dtack <= 1;
  1578. zorro_state <= Z2_ENDCYCLE;
  1579. zorro_ram_write_request <= 0;
  1580. end
  1581. end
  1582. Z2_ENDCYCLE: begin
  1583. m00_axi_wvalid_z3 <= 0;
  1584. z_ovr <= 0;
  1585. // FIXME
  1586. read_counter <= read_counter + 1'b1;
  1587. if (read_counter >= dtack_timeout) begin
  1588. dtack <= 0;
  1589. end
  1590. if (!z2_addr_valid) begin
  1591. dtack <= 0;
  1592. slaven <= 0;
  1593. dataout_enable <= 0;
  1594. dataout <= 0;
  1595. zorro_state <= Z2_IDLE;
  1596. read_counter <= 0;
  1597. end
  1598. end
  1599. // 16bit reg read
  1600. Z2_REGREAD_POST: begin
  1601. if (zaddr_regpart[1]==1'b1)
  1602. data_out <= rr_data[15:0];
  1603. else
  1604. data_out <= rr_data[31:16];
  1605. dtack <= 1;
  1606. zorro_state <= Z2_ENDCYCLE;
  1607. end
  1608. // relaxing the data pipeline a bit
  1609. Z2_REGREAD: begin
  1610. regread_addr <= zaddr_regpart;
  1611. zorro_state <= REGREAD;
  1612. end
  1613. `endif
  1614. `ifdef ZORRO3
  1615. // =========================================================================
  1616. // ZORRO 3
  1617. // =========================================================================
  1618. Z3_REGWRITE_PRE: begin
  1619. if (z3_ds1) begin
  1620. regdata_in <= z3_din_low_s2;
  1621. z3addr_regpart <= (z3addr[15:0])|16'h2;
  1622. zorro_state <= Z3_REGWRITE;
  1623. end else if (z3_ds3) begin
  1624. regdata_in <= z3_din_high_s2;
  1625. z3addr_regpart <= z3addr[15:0];
  1626. zorro_state <= Z3_REGWRITE;
  1627. end
  1628. end
  1629. Z3_REGREAD_PRE: begin
  1630. z3addr_regpart <= z3addr[15:0]; //|16'h2;
  1631. zorro_state <= Z3_REGREAD;
  1632. dataout_z3 <= 1;
  1633. end
  1634. Z3_IDLE: begin
  1635. read_counter <= 0;
  1636. if (z3_fcs_state==0) begin
  1637. // falling edge of /FCS
  1638. if (zorro_write && z3addr_in_reg) begin
  1639. // FIXME doesn't support 32 bit access
  1640. // write to register
  1641. zorro_state <= Z3_REGWRITE_PRE;
  1642. slaven <= 1;
  1643. end else if (zorro_read && z3addr_in_reg) begin
  1644. // read registers
  1645. data_z3_hi16 <= default_data;
  1646. data_z3_low16 <= default_data;
  1647. zorro_state <= Z3_REGREAD_PRE;
  1648. slaven <= 1;
  1649. end else if (z3addr_in_ram && zorro_write) begin
  1650. // write to memory
  1651. slaven <= 1;
  1652. zorro_state <= Z3_WRITE_PRE;
  1653. end else if (z3addr_in_ram && zorro_read) begin
  1654. // read from memory
  1655. data_z3_hi16 <= default_data;
  1656. data_z3_low16 <= default_data;
  1657. slaven <= 1;
  1658. if (z3_mapped_addr<'h2000)
  1659. zorro_state <= Z3_READ_UPPER;
  1660. else
  1661. zorro_state <= WAIT_READ_DMA_Z3;
  1662. end else begin
  1663. // address not recognized
  1664. slaven <= 0;
  1665. end
  1666. end else begin
  1667. // not in a cycle
  1668. slaven <= 0;
  1669. end
  1670. end
  1671. Z3_REGWRITE: begin
  1672. regwrite_addr <= z3addr_regpart;
  1673. zorro_state <= REGWRITE;
  1674. dtack <= 1;
  1675. end
  1676. Z3_REGREAD: begin
  1677. regread_addr <= z3addr_regpart;
  1678. zorro_state <= REGREAD;
  1679. end
  1680. // 32bit reg read
  1681. Z3_REGREAD_POST: begin
  1682. data_z3_hi16 <= rr_data[31:16];
  1683. data_z3_low16 <= rr_data[15:0];
  1684. zorro_state <= Z3_ENDCYCLE;
  1685. dtack <= 1;
  1686. end
  1687. Z3_READ_UPPER: begin
  1688. zorro_state <= Z3_READ_DELAY1;
  1689. last_z3addr <= z3_mapped_addr;
  1690. zorro_ram_read_addr <= z3_mapped_addr;
  1691. zorro_ram_read_bytes <= 4'b1111;
  1692. zorro_ram_read_request <= 1;
  1693. dataout_z3 <= 1; // enable data output
  1694. // dummy read for debug
  1695. /*dtack <= 1;
  1696. data_z3_hi16 <= 'hffff;
  1697. data_z3_low16 <= 'hffff;
  1698. zorro_state <= Z3_ENDCYCLE;*/
  1699. end
  1700. Z3_READ_DELAY1: begin
  1701. data_z3_hi16 <= axi_reg1[31:16];
  1702. data_z3_low16 <= axi_reg1[15:0];
  1703. if (zorro_ram_read_flag) begin
  1704. zorro_ram_read_request <= 0; // acknowledge read request done
  1705. zorro_state <= Z3_READ_DELAY2; // CHECK DELAY
  1706. end
  1707. end
  1708. Z3_READ_DELAY2: begin
  1709. if (!zorro_ram_read_flag) begin
  1710. zorro_state <= Z3_ENDCYCLE;
  1711. dtack <= 1;
  1712. slaven <= 0;
  1713. end
  1714. end
  1715. Z3_WRITE_PRE: begin
  1716. if (z3_ds0||z3_ds1||z3_ds2||z3_ds3) begin
  1717. zorro_state <= Z3_WRITE_PRE2;
  1718. end
  1719. end
  1720. Z3_WRITE_PRE2: begin
  1721. // FIXME DMA temporarily disabled for FW2.0
  1722. `ifdef VARIANT_FW20
  1723. zorro_state <= Z3_WRITE_UPPER;
  1724. `else
  1725. if (z3_mapped_addr<'h2000)
  1726. zorro_state <= Z3_WRITE_UPPER;
  1727. else
  1728. zorro_state <= WAIT_WRITE_DMA_Z3;
  1729. `endif
  1730. end
  1731. Z3_WRITE_UPPER: begin
  1732. last_z3addr <= z3_mapped_addr;
  1733. zorro_ram_write_addr <= z3_mapped_addr;
  1734. zorro_ram_write_bytes <= {z3_ds3,z3_ds2,z3_ds1,z3_ds0};
  1735. zorro_ram_write_data <= {z3_din_high_s2,z3_din_low_s2};
  1736. zorro_ram_write_request <= 1;
  1737. zorro_state <= Z3_WRITE_FINALIZE;
  1738. end
  1739. Z3_WRITE_FINALIZE: begin
  1740. if (zorro_ram_write_flag) begin
  1741. zorro_ram_write_request <= 0; // acknowledge write request done
  1742. zorro_state <= Z3_ENDCYCLE;
  1743. dtack <= 1;
  1744. slaven <= 0;
  1745. end
  1746. end
  1747. WAIT_READ_DMA_Z3: begin
  1748. if ( (z3_mapped_addr>='hA000)&&(z3_mapped_addr<'h10000) )
  1749. m00_axi_araddr <= (`USB_BLOCK_STORAGE_ADDRESS - 32'hA000) + z3_mapped_addr + {usbb[22:0],9'h0}; // 9'h0 is USB_BLOCK_SIZE = 512
  1750. else
  1751. if ( (z3_mapped_addr>='h8000)&&(z3_mapped_addr<'hA000) )
  1752. m00_axi_araddr <= (`TX_FRAME_ADDRESS - 32'h8000) + z3_mapped_addr;
  1753. else
  1754. if ( (z3_mapped_addr>='h2000)&&(z3_mapped_addr<'h8000) ) begin
  1755. m00_axi_araddr <= (`RX_BACKLOG_ADDRESS - 32'h2000) + z3_mapped_addr + {frfb[20:0],11'h0}; // 11'h0 is FRAME_SIZE = 2048
  1756. clear_interrupt<=1;
  1757. end else
  1758. m00_axi_araddr <= `ARM_MEMORY_START + (z3_mapped_addr/*&32'hfffffffc*/); // max 256MB
  1759. m00_axi_arvalid <= 1;
  1760. // m00_axi_rready <= 1;
  1761. if (m00_axi_arready) begin
  1762. zorro_state <= WAIT_READ_DMA_Z3B;
  1763. end
  1764. end
  1765. WAIT_READ_DMA_Z3B: begin
  1766. m00_axi_arvalid <= 0;
  1767. // m00_axi_rready <= 1;
  1768. if (m00_axi_rvalid) begin
  1769. zorro_state <= Z3_ENDCYCLE;
  1770. data_z3_hi16 <= {m00_axi_rdata[7:0], m00_axi_rdata[15:8]};
  1771. data_z3_low16 <= {m00_axi_rdata[23:16], m00_axi_rdata[31:24]};
  1772. dataout_z3 <= 1; // enable data output
  1773. dtack <= 1;
  1774. end
  1775. end
  1776. WAIT_WRITE_DMA_Z3: begin
  1777. m00_axi_wstrb_z3 <= {z3_ds0, z3_ds1, z3_ds2, z3_ds3};
  1778. if ( (z3_mapped_addr>='hA000)&&(z3_mapped_addr<'h10000) )
  1779. m00_axi_awaddr_z3 <= (`USB_BLOCK_STORAGE_ADDRESS - 32'hA000) + z3_mapped_addr + {usbb[22:0],9'h0}; // 9'h0 is USB_BLOCK_SIZE = 512
  1780. else
  1781. if ( (z3_mapped_addr>='h8000)&&(z3_mapped_addr<'hA000) )
  1782. m00_axi_awaddr_z3 <= (`TX_FRAME_ADDRESS - 32'h8000) + z3_mapped_addr;
  1783. else
  1784. if ( (z3_mapped_addr>='h2000)&&(z3_mapped_addr<'h8000) ) // this is marked in main.c as "FIXME remove"
  1785. m00_axi_awaddr_z3 <= (`RX_FRAME_ADDRESS - 32'h2000) + z3_mapped_addr;
  1786. else
  1787. m00_axi_awaddr_z3 <= `ARM_MEMORY_START + (z3_mapped_addr/*&32'hfffffffc*/); // max 256MB
  1788. m00_axi_wdata_z3 <= {z3_din_low_s2[7:0], z3_din_low_s2[15:8], z3_din_high_s2[7:0], z3_din_high_s2[15:8]};
  1789. m00_axi_awvalid_z3 <= 1;
  1790. if (m00_axi_awready) begin
  1791. zorro_state <= WAIT_WRITE_DMA_Z3B;
  1792. end
  1793. end
  1794. WAIT_WRITE_DMA_Z3B: begin
  1795. dtack <= 1;
  1796. m00_axi_awvalid_z3 <= 0;
  1797. m00_axi_wvalid_z3 <= 1;
  1798. if (m00_axi_wready) begin
  1799. zorro_state <= WAIT_WRITE_DMA_Z3C;
  1800. end
  1801. end
  1802. // not sure if this extra state is needed actually
  1803. WAIT_WRITE_DMA_Z3C: begin
  1804. m00_axi_wvalid_z3 <= 0;
  1805. zorro_state <= Z3_ENDCYCLE;
  1806. end
  1807. Z3_ENDCYCLE: begin
  1808. dtack <= 1;
  1809. // we're timing out or own dtack here. because of a zorro
  1810. // bug / subtlety, dtack can be sampled incorrectly to "hang over"
  1811. // into the next amiga zorro cycle.
  1812. // this is because we have a long rise time on our DTACK
  1813. // output/1k pullup.
  1814. read_counter <= read_counter + 1'b1;
  1815. if (read_counter >= dtack_timeout) begin
  1816. dtack <= 0;
  1817. end
  1818. if (z3_fcs_state==1) begin
  1819. dtack <= 0;
  1820. slaven <= 0;
  1821. dataout_z3 <= 0;
  1822. zorro_state <= Z3_IDLE;
  1823. end
  1824. end
  1825. `endif
  1826. // FIXME why is there no dataout time on REGREAD? (see memory reads)
  1827. // now fixed for Z3, still pending for Z2
  1828. REGREAD: begin
  1829. // TODO split up into z3/z2
  1830. `ifdef ZORRO3
  1831. zorro_state <= Z3_REGREAD_POST;
  1832. `else
  1833. zorro_state <= Z2_REGREAD_POST;
  1834. `endif
  1835. case (regread_addr&'hff)
  1836. /*'h00: begin
  1837. rr_data <= video_control_data;
  1838. end
  1839. 'h04: begin
  1840. rr_data <= video_control_op;
  1841. end*/
  1842. 'h00: begin
  1843. // this flag is read by Amiga software to check if all writes are done
  1844. rr_data <= video_control_vblank << 16; //zorro_ram_write_request;
  1845. end
  1846. default: begin
  1847. rr_data[31:16] <= REVISION;
  1848. rr_data[15:0] <= REVISION;
  1849. end
  1850. endcase
  1851. end
  1852. REGWRITE: begin
  1853. `ifdef ZORRO3
  1854. zorro_state <= Z3_ENDCYCLE;
  1855. `else
  1856. dtack <= 1;
  1857. zorro_state <= Z2_ENDCYCLE;
  1858. `endif
  1859. case (regwrite_addr&'hff)
  1860. 'h00: video_control_data_zorro[31:16] <= regdata_in[15:0];
  1861. 'h02: video_control_data_zorro[15:0] <= regdata_in[15:0];
  1862. 'h04: video_control_op_zorro[7:0] <= regdata_in[7:0]; // FIXME
  1863. 'h06: videocap_mode_in <= regdata_in[0];
  1864. 'h10: dataout_time[7:0] <= regdata_in[7:0];
  1865. 'h20: dtack_timeout <= regdata_in[5:0];
  1866. //'h14: zorro_interrupt <= regdata_in[0];
  1867. //'h10: E7M_PSINCDEC <= regdata_in[0];
  1868. //'h12: E7M_PSEN <= regdata_in[0];
  1869. endcase
  1870. end
  1871. endcase
  1872. // PSEN reset
  1873. //if (E7M_PSEN==1'b1) E7M_PSEN <= 1'b0;
  1874. // ARM video control
  1875. if (axi_reg2[31]==1'b1) begin
  1876. video_control_data_axi <= axi_reg3[31:0];
  1877. video_control_op_axi <= axi_reg2[7:0];
  1878. video_control_axi <= 1;
  1879. end else
  1880. video_control_axi <= 0;
  1881. if (axi_reg2[30]==1'b1) begin
  1882. zorro_interrupt <= axi_reg2[0];
  1883. end
  1884. else if (clear_interrupt==1) begin
  1885. zorro_interrupt<=0;
  1886. clear_interrupt<=0;
  1887. end
  1888. // read / write request acknowledged by ARM
  1889. zorro_ram_read_flag <= axi_reg0[30];
  1890. zorro_ram_write_flag <= axi_reg0[31];
  1891. frfb <= axi_reg4;
  1892. usbb <= axi_reg5;
  1893. axi_reg0 <= slv_reg0;
  1894. axi_reg1 <= slv_reg1;
  1895. axi_reg2 <= slv_reg2;
  1896. axi_reg3 <= slv_reg3;
  1897. axi_reg4 <= slv_reg4;
  1898. axi_reg5 <= slv_reg5;
  1899. if (video_control_axi) begin
  1900. video_control_data <= video_control_data_axi;
  1901. video_control_op <= video_control_op_axi;
  1902. end else begin
  1903. video_control_data <= video_control_data_zorro;
  1904. video_control_op <= video_control_op_zorro;
  1905. end
  1906. video_control_data_out <= video_control_data;
  1907. video_control_op_out <= video_control_op;
  1908. video_control_vblank <= video_control_vblank_in;
  1909. video_control_interlace_out <= video_control_interlace;
  1910. // snoop the screen width for correct capture pitch
  1911. if (video_control_op == 2) begin
  1912. // OP_DIMENSIONS = 2
  1913. videocap_pitch_snoop <= video_control_data[11:0];
  1914. end
  1915. videocap_pitch <= videocap_pitch_snoop;
  1916. out_reg0 <= ZORRO3 ? last_z3addr : last_addr;
  1917. out_reg1 <= zorro_ram_write_data;
  1918. out_reg2 <= last_z3addr;
  1919. //out_reg3 <= {zorro_ram_write_request, zorro_ram_read_request, zorro_ram_write_bytes, ZORRO3,
  1920. // video_control_interlace, videocap_mode, 15'b0, zorro_state};
  1921. // `-- 24 `-- 23 `-- 22 `-- 7:0
  1922. out_reg3 <= {zorro_ram_write_request, zorro_ram_read_request, zorro_ram_write_bytes, ZORRO3,
  1923. video_control_interlace, videocap_mode, videocap_ntsc, video_control_vblank, 13'b0, zorro_state};
  1924. end
  1925. assign slv_reg_rden = axi_arready & S_AXI_ARVALID & ~axi_rvalid;
  1926. always @(*)
  1927. begin
  1928. // Address decoding for reading registers
  1929. case ( axi_araddr[ADDR_LSB+OPT_MEM_ADDR_BITS:ADDR_LSB] )
  1930. 3'h0 : reg_data_out <= out_reg0;
  1931. 3'h1 : reg_data_out <= out_reg1;
  1932. 3'h2 : reg_data_out <= out_reg2;
  1933. 3'h3 : reg_data_out <= out_reg3;
  1934. default : reg_data_out <= 'h0;
  1935. endcase
  1936. end
  1937. endmodule