diff --git a/1801BM1_vm80a/license.md b/1801BM1_vm80a/license.md
new file mode 100644
index 0000000000000000000000000000000000000000..e943acc41a0a5679655eecef34ab2c279c08e15c
--- /dev/null
+++ b/1801BM1_vm80a/license.md
@@ -0,0 +1,328 @@
+## Creative Commons 3.0 CC-BY license
+
+CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL
+SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN ATTORNEY-CLIENT
+RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS.
+CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE INFORMATION PROVIDED,
+AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM ITS USE.
+
+#### License
+
+THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
+COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
+COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
+AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
+
+BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
+TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE
+CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED
+HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
+
+#### 1. Definitions
+
+"Adaptation" means a work based upon the Work, or upon the Work and other
+pre-existing works, such as a translation, adaptation, derivative work,
+arrangement of music or other alterations of a literary or artistic work,
+or phonogram or performance and includes cinematographic adaptations or
+any other form in which the Work may be recast, transformed, or adapted
+including in any form recognizably derived from the original, except that
+a work that constitutes a Collection will not be considered an Adaptation
+for the purpose of this License. For the avoidance of doubt, where the Work
+is a musical work, performance or phonogram, the synchronization of the
+Work in timed-relation with a moving image ("synching") will be considered
+an Adaptation for the purpose of this License.
+
+"Collection" means a collection of literary or artistic works, such as
+encyclopedias and anthologies, or performances, phonograms or broadcasts,
+or other works or subject matter other than works listed in Section 1(f)
+below, which, by reason of the selection and arrangement of their contents,
+constitute intellectual creations, in which the Work is included in its
+entirety in unmodified form along with one or more other contributions,
+each constituting separate and independent works in themselves, which
+together are assembled into a collective whole. A work that constitutes
+a Collection will not be considered an Adaptation (as defined above) for
+the purposes of this License.
+
+"Distribute" means to make available to the public the original and copies
+of the Work or Adaptation, as appropriate, through sale or other transfer
+of ownership.
+
+"Licensor" means the individual, individuals, entity or entities that
+offer(s) the Work under the terms of this License.
+
+"Original Author" means, in the case of a literary or artistic work,
+the individual, individuals, entity or entities who created the Work or
+if no individual or entity can be identified, the publisher; and in
+addition (i) in the case of a performance the actors, singers, musicians,
+dancers, and other persons who act, sing, deliver, declaim, play in,
+interpret or otherwise perform literary or artistic works or expressions
+of folklore; (ii) in the case of a phonogram the producer being the person
+or legal entity who first fixes the sounds of a performance or other sounds;
+and, (iii) in the case of broadcasts, the organization that transmits
+the broadcast.
+
+"Work" means the literary and/or artistic work offered under the terms
+of this License including without limitation any production in the literary,
+scientific and artistic domain, whatever may be the mode or form of its
+expression including digital form, such as a book, pamphlet and other
+writing; a lecture, address, sermon or other work of the same nature;
+a dramatic or dramatico-musical work; a choreographic work or entertainment
+in dumb show; a musical composition with or without words; a cinematographic
+work to which are assimilated works expressed by a process analogous to
+cinematography; a work of drawing, painting, architecture, sculpture,
+engraving or lithography; a photographic work to which are assimilated
+works expressed by a process analogous to photography; a work of applied art;
+an illustration, map, plan, sketch or three-dimensional work relative to
+geography, topography, architecture or science; a performance; a broadcast;
+a phonogram; a compilation of data to the extent it is protected as
+a copyrightable work; or a work performed by a variety or circus performer
+to the extent it is not otherwise considered a literary or artistic work.
+
+"You" means an individual or entity exercising rights under this License
+who has not previously violated the terms of this License with respect to
+the Work, or who has received express permission from the Licensor
+to exercise rights under this License despite a previous violation.
+
+"Publicly Perform" means to perform public recitations of the Work and
+to communicate to the public those public recitations, by any means or
+process, including by wire or wireless means or public digital performances;
+to make available to the public Works in such a way that members of the
+public may access these Works from a place and at a place individually
+chosen by them; to perform the Work to the public by any means or process
+and the communication to the public of the performances of the Work,
+including by public digital performance; to broadcast and rebroadcast
+the Work by any means including signs, sounds or images.
+
+"Reproduce" means to make copies of the Work by any means including without
+limitation by sound or visual recordings and the right of fixation and
+reproducing fixations of the Work, including storage of a protected
+performance or phonogram in digital form or other electronic medium.
+
+#### 2. Fair Dealing Rights.
+
+Nothing in this License is intended to reduce, limit, or restrict any uses
+free from copyright or rights arising from limitations or exceptions that
+are provided for in connection with the copyright protection under copyright
+law or other applicable laws.
+
+#### 3. License Grant.
+
+Subject to the terms and conditions of this License, Licensor hereby grants
+You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of
+the applicable copyright) license to exercise the rights in the Work as
+stated below:
+
+to Reproduce the Work, to incorporate the Work into one or more
+Collections, and to Reproduce the Work as incorporated in the Collections;
+
+to create and Reproduce Adaptations provided that any such Adaptation,
+including any translation in any medium, takes reasonable steps to clearly
+label, demarcate or otherwise identify that changes were made to the
+original Work. For example, a translation could be marked "The original
+work was translated from English to Spanish," or a modification could
+indicate "The original work has been modified.";
+
+to Distribute and Publicly Perform the Work including as incorporated
+in Collections; and,
+
+to Distribute and Publicly Perform Adaptations.
+
+For the avoidance of doubt:
+
+Non-waivable Compulsory License Schemes. In those jurisdictions in which
+the right to collect royalties through any statutory or compulsory licensing
+scheme cannot be waived, the Licensor reserves the exclusive right to
+collect such royalties for any exercise by You of the rights granted under
+this License;
+
+Waivable Compulsory License Schemes. In those jurisdictions in which the
+right to collect royalties through any statutory or compulsory licensing
+scheme can be waived, the Licensor waives the exclusive right to collect
+such royalties for any exercise by You of the rights granted under this
+License; and,
+
+Voluntary License Schemes. The Licensor waives the right to collect
+royalties, whether individually or, in the event that the Licensor is
+a member of a collecting society that administers voluntary licensing
+schemes, via that society, from any exercise by You of the rights
+granted under this License.
+
+The above rights may be exercised in all media and formats whether now
+known or hereafter devised. The above rights include the right to make
+such modifications as are technically necessary to exercise the rights
+in other media and formats. Subject to Section 8(f), all rights not
+expressly granted by Licensor are hereby reserved.
+
+#### 4. Restrictions.
+
+The license granted in Section 3 above is expressly made subject to
+and limited by the following restrictions:
+
+You may Distribute or Publicly Perform the Work only under the terms
+of this License. You must include a copy of, or the Uniform Resource
+Identifier (URI) for, this License with every copy of the Work You
+Distribute or Publicly Perform. You may not offer or impose any terms
+on the Work that restrict the terms of this License or the ability
+of the recipient of the Work to exercise the rights granted to that
+recipient under the terms of the License. You may not sublicense the Work.
+
+You must keep intact all notices that refer to this License and to the
+disclaimer of warranties with every copy of the Work You Distribute
+or Publicly Perform. When You Distribute or Publicly Perform the Work,
+You may not impose any effective technological measures on the Work
+that restrict the ability of a recipient of the Work from You to exercise
+the rights granted to that recipient under the terms of the License.
+This Section 4(a) applies to the Work as incorporated in a Collection,
+but this does not require the Collection apart from the Work itself to
+be made subject to the terms of this License. If You create a Collection,
+upon notice from any Licensor You must, to the extent practicable, remove
+from the Collection any credit as required by Section 4(b), as requested.
+If You create an Adaptation, upon notice from any Licensor You must,
+to the extent practicable, remove from the Adaptation any credit as
+required by Section 4(b), as requested.
+
+If You Distribute, or Publicly Perform the Work or any Adaptations or
+Collections, You must, unless a request has been made pursuant to
+Section 4(a), keep intact all copyright notices for the Work and provide,
+reasonable to the medium or means You are utilizing: (i) the name of
+the Original Author (or pseudonym, if applicable) if supplied, and/or
+if the Original Author and/or Licensor designate another party or
+parties (e.g., a sponsor institute, publishing entity, journal) for
+attribution ("Attribution Parties") in Licensor's copyright notice,
+terms of service or by other reasonable means, the name of such party
+or parties; (ii) the title of the Work if supplied; (iii) to the extent
+reasonably practicable, the URI, if any, that Licensor specifies to be
+associated with the Work, unless such URI does not refer to the copyright
+notice or licensing information for the Work; and (iv) , consistent
+with Section 3(b), in the case of an Adaptation, a credit identifying
+the use of the Work in the Adaptation (e.g., "French translation of
+the Work by Original Author," or "Screenplay based on original Work
+by Original Author"). The credit required by this Section 4 (b) may be
+implemented in any reasonable manner; provided, however, that in the case
+of a Adaptation or Collection, at a minimum such credit will appear,
+if a credit for all contributing authors of the Adaptation or Collection
+appears, then as part of these credits and in a manner at least as
+prominent as the credits for the other contributing authors.
+
+For the avoidance of doubt, You may only use the credit required by
+this Section for the purpose of attribution in the manner set out
+above and, by exercising Your rights under this License, You may not
+implicitly or explicitly assert or imply any connection with, sponsorship
+or endorsement by the Original Author, Licensor and/or Attribution Parties,
+as appropriate, of You or Your use of the Work, without the separate,
+express prior written permission of the Original Author, Licensor
+and/or Attribution Parties. Except as otherwise agreed in writing by
+the Licensor or as may be otherwise permitted by applicable law, if
+You Reproduce, Distribute or Publicly Perform the Work either by itself
+or as part of any Adaptations or Collections, You must not distort,
+mutilate, modify or take other derogatory action in relation to the
+Work which would be prejudicial to the Original Author's honor or
+reputation. Licensor agrees that in those jurisdictions (e.g. Japan),
+in which any exercise of the right granted in Section 3(b) of this
+License (the right to make Adaptations) would be deemed to be a distortion,
+mutilation, modification or other derogatory action prejudicial to the
+Original Author's honor and reputation, the Licensor will waive or not
+assert, as appropriate, this Section, to the fullest extent permitted
+by the applicable national law, to enable You to reasonably exercise
+Your right under Section 3(b) of this License (right to make Adaptations)
+but not otherwise.
+
+#### 5. Representations, Warranties and Disclaimer
+
+UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR
+OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
+KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
+INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
+FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT
+OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER
+OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED
+WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
+
+#### 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW,
+IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY
+SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING
+OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+#### 7. Termination
+
+This License and the rights granted hereunder will terminate automatically
+upon any breach by You of the terms of this License. Individuals or entities
+who have received Adaptations or Collections from You under this License,
+however, will not have their licenses terminated provided such individuals or
+entities remain in full compliance with those licenses. Sections 1, 2, 5,
+6, 7, and 8 will survive any termination of this License.
+
+Subject to the above terms and conditions, the license granted here is
+perpetual (for the duration of the applicable copyright in the Work).
+Notwithstanding the above, Licensor reserves the right to release the Work
+under different license terms or to stop distributing the Work at any time;
+provided, however that any such election will not serve to withdraw this
+License (or any other license that has been, or is required to be, granted
+under the terms of this License), and this License will continue in full
+force and effect unless terminated as stated above.
+
+#### 8. Miscellaneous
+
+Each time You Distribute or Publicly Perform the Work or a Collection,
+the Licensor offers to the recipient a license to the Work on the same
+terms and conditions as the license granted to You under this License.
+
+Each time You Distribute or Publicly Perform an Adaptation, Licensor offers
+to the recipient a license to the original Work on the same terms and
+conditions as the license granted to You under this License.
+
+If any provision of this License is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this License, and without further action by
+the parties to this agreement, such provision shall be reformed to the
+minimum extent necessary to make such provision valid and enforceable.
+
+No term or provision of this License shall be deemed waived and no breach
+consented to unless such waiver or consent shall be in writing and signed
+by the party to be charged with such waiver or consent.
+
+This License constitutes the entire agreement between the parties with
+respect to the Work licensed here. There are no understandings, agreements
+or representations with respect to the Work not specified here. Licensor
+shall not be bound by any additional provisions that may appear in any
+communication from You. This License may not be modified without the
+mutual written agreement of the Licensor and You.
+
+The rights granted under, and the subject matter referenced, in this
+License were drafted utilizing the terminology of the Berne Convention
+for the Protection of Literary and Artistic Works (as amended on September 28,
+1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996,
+the WIPO Performances and Phonograms Treaty of 1996 and the Universal
+Copyright Convention (as revised on July 24, 1971). These rights and
+subject matter take effect in the relevant jurisdiction in which the
+License terms are sought to be enforced according to the corresponding
+provisions of the implementation of those treaty provisions in the
+applicable national law. If the standard suite of rights granted under
+applicable copyright law includes additional rights not granted under
+this License, such additional rights are deemed to be included in the
+License; this License is not intended to restrict the license of any
+rights under applicable law.
+
+#### Creative Commons Notice
+
+Creative Commons is not a party to this License, and makes no warranty
+whatsoever in connection with the Work. Creative Commons will not be
+liable to You or any party on any legal theory for any damages whatsoever,
+including without limitation any general, special, incidental or
+consequential damages arising in connection to this license.
+Notwithstanding the foregoing two (2) sentences, if Creative Commons
+has expressly identified itself as the Licensor hereunder, it shall
+have all rights and obligations of Licensor.
+
+Except for the limited purpose of indicating to the public that the Work
+is licensed under the CCPL, Creative Commons does not authorize the use
+by either party of the trademark "Creative Commons" or any related
+trademark or logo of Creative Commons without the prior written consent
+of Creative Commons. Any permitted use will be in compliance with
+Creative Commons' then-current trademark usage guidelines, as may be
+published on its website or otherwise made available upon request from
+time to time. For the avoidance of doubt, this trademark restriction
+does not form part of this License.
+
+Creative Commons may be contacted at https://creativecommons.org/.
diff --git a/1801BM1_vm80a/org/rtl/ax309/ax309_mem.v b/1801BM1_vm80a/org/rtl/ax309/ax309_mem.v
new file mode 100644
index 0000000000000000000000000000000000000000..375209277ff3c899074ba0c9e40cf55d0f36c505
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/ax309/ax309_mem.v
@@ -0,0 +1,34 @@
+`timescale 1ns/1ps
+
+module ax309_mem
+(
+ input [13:0] addra,
+ input clka,
+ input [7:0] dina,
+ input wea,
+ output [7:0] douta
+);
+
+reg [7:0] mem [0:16383];
+reg [13:0] areg;
+reg wreg;
+
+always @ (posedge clka)
+begin
+ areg <= addra;
+ wreg <= wea;
+
+ if (wreg)
+ mem[areg] <= dina;
+end
+
+assign douta = mem[areg];
+//
+// $readmemh synthezable in XST
+// Use inferred block memory instead core generator (work too boring, difficult to change content)
+//
+initial
+begin
+ $readmemh("..\\..\\..\\tst\\rom\\memini.mem", mem, 0, 16383);
+end
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/ax309/ax309_top.v b/1801BM1_vm80a/org/rtl/ax309/ax309_top.v
new file mode 100644
index 0000000000000000000000000000000000000000..e44838fda23dfcfaad4d440e65482070e7e3ef66
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/ax309/ax309_top.v
@@ -0,0 +1,298 @@
+//______________________________________________________________________________
+//
+// Top module for AX309 board based system
+//
+//______________________________________________________________________________
+//
+// External oscillator clock, feeds the PLLs
+//
+`define OSC_CLOCK 50000000
+//
+// Global system clock
+//
+`define SYS_CLOCK 50000000
+//
+// Console baudrate
+//
+`define SYS_BAUD 115200
+//______________________________________________________________________________
+//
+// Reset button debounce interval (in ms))
+//
+`define RESET_BUTTON_DEBOUNCE_MS 5
+//
+// Internal reset pulse width (in system clocks)
+//
+`define RESET_PULSE_WIDTH_CLK 7
+
+//______________________________________________________________________________
+//
+// Top project module - instantiates the AX309 board itself
+//
+module ax309
+(
+ input ax3_clock_50, // clock input 50 MHz
+ //
+ input ax3_reset_n, // push reset button
+ input [3:0] ax3_button, // push button [3:0]
+ output [3:0] ax3_led, // led outputs [3:0]
+ output [7:0] ax3_hex, // seven segment digit mask
+ output [5:0] ax3_hsel, // seven segment digit select
+// output ax3_buzzer, //
+ //
+ output ax3_uart_txd, // UART transmitter
+ input ax3_uart_rxd // UART receiver
+// //
+// inout [15:0] ax3_dram_dq, // SDRAM data bus 16 bits
+// output [12:0] ax3_dram_addr, // SDRAM address bus 13 bits
+// output ax3_dram_ldqm, // SDRAM low-byte data mask
+// output ax3_dram_udqm, // SDRAM high-byte data mask
+// output ax3_dram_we_n, // SDRAM write enable
+// output ax3_dram_cas_n, // SDRAM column address strobe
+// output ax3_dram_ras_n, // SDRAM row address strobe
+// output ax3_dram_cs_n, // SDRAM chip select
+// output [1:0] ax3_dram_ba, // SDRAM bank address
+// output ax3_dram_clk, // SDRAM clock
+// output ax3_dram_cke, // SDRAM clock enable
+// //
+// output ax3_spi_cs_n, // SPI FLASH chip select
+// output ax3_spi_clk, // SPI FLASH clock
+// output ax3_spi_mosi, // SPI FLASH master output
+// input ax3_spi_miso, // SPI FLASH master input
+// //
+// inout ax3_sd_cs_n, // SD Card chip select
+// inout ax3_sd_clk, // SD Card clock
+// inout ax3_sd_mosi, // SD Card master output
+// inout ax3_sd_miso, // SD Card master input
+// //
+// inout ax3_i2c_clk, // I2C Clock
+// inout ax3_i2c_dat, // I2C Data
+// output ax3_rtc_rst_n, // RTC DS1302 reset
+// output ax3_rtc_sclk, // RTC DS1302_serial clock
+// inout ax3_rtc_sdat, // RTC DS1302 serial data_
+// //
+// output ax3_vga_hs, // VGA H_SYNC
+// output ax3_vga_vs, // VGA V_SYNC
+// output [4:0] ax3_vga_r, // VGA Red[4:0]
+// output [5:0] ax3_vga_g, // VGA Green[5:0]
+// output [4:0] ax3_vga_b, // VGA Blue[4:0]
+// //
+// inout [33:0] ax3_gpio0, // GPIO Connection 0
+// inout [33:0] ax3_gpio1 // GPIO Connection 1
+);
+
+//______________________________________________________________________________
+//
+// Top module for AX309 board based system
+//
+wire [31:0] baud = 921600/`SYS_BAUD-1;
+wire clk, wr_n, rst_n, dbin;
+wire [7:0] dcpu;
+wire [7:0] dsys;
+wire [7:0] dsio;
+wire [7:0] dram;
+wire [15:0] a;
+wire uack;
+
+reg f1, f2;
+reg [7:0] hex0, hex1, hex2, hex3, hex4, hex5;
+reg [2:0] hsel;
+reg [1:0] led;
+reg [7:0] rcnt = 8'h00;
+reg [2:0] div;
+reg [15:0] div1ms;
+reg ms, intrq, inta;
+wire inte, sync;
+
+assign clk = ax3_clock_50;
+assign rst_n = (rcnt == 8'hFF);
+assign dsys = inta ? 8'hE7
+ : (a[15:8] == 8'hFF) ? {4'h0, ax3_button[3:0]}
+ : (a[15:8] == 8'hFE) ? dsio
+ : dram;
+
+assign ax3_hex = (hsel == 3'b000) ? ~hex0
+ : (hsel == 3'b001) ? ~hex1
+ : (hsel == 3'b010) ? ~hex2
+ : (hsel == 3'b011) ? ~hex3
+ : (hsel == 3'b100) ? ~hex4
+ : (hsel == 3'b101) ? ~hex5 : 8'hFF;
+
+assign ax3_hsel[0] = ~(hsel == 3'b000);
+assign ax3_hsel[1] = ~(hsel == 3'b001);
+assign ax3_hsel[2] = ~(hsel == 3'b010);
+assign ax3_hsel[3] = ~(hsel == 3'b011);
+assign ax3_hsel[4] = ~(hsel == 3'b100);
+assign ax3_hsel[5] = ~(hsel == 3'b101);
+
+always @(posedge clk)
+begin
+ div <= div + 3'b001;
+ f1 <= div[0];
+ f2 <= ~div[0];
+
+ if (sync) inta = dcpu[0];
+ if (div1ms == ((`SYS_CLOCK/1000)-1))
+ begin
+ div1ms <= 16'h0000;
+ ms <= 1;
+ end
+ else
+ begin
+ div1ms <= div1ms + 16'h0001;
+ ms <= 0;
+ end
+
+ if (ms) intrq <= 1;
+ if (inta) intrq <= 0;
+
+ if (~rst_n)
+ hsel <= 3'b000;
+ else
+ if (ms)
+ if (hsel == 3'b000)
+ hsel <= 3'b101;
+ else
+ hsel <= hsel - 3'b001;
+end
+
+always @(posedge clk)
+begin
+ if (~ax3_reset_n)
+ rcnt <= 8'h00;
+ else
+ if (rcnt != 8'hFF) rcnt <= rcnt + 8'h01;
+end
+
+/*
+memini ram
+(
+ .address(a[13:0]),
+ .clock(clk),
+ .wren(~wr_n & rst_n & ~a[15] & ~a[14]),
+ .data(dcpu),
+ .q(dram)
+);
+*/
+ax309_mem ram
+(
+ .addra(a[13:0]),
+ .clka(clk),
+ .wea(~wr_n & rst_n & ~a[15] & ~a[14]),
+ .dina(dcpu),
+ .douta(dram)
+);
+
+always @(posedge clk)
+begin
+ if (~wr_n)
+ begin
+ if (a == 16'hFFFB) led <= dcpu[1:0];
+ if (a == 16'hFFFC) hex0 <= dcpu[7:0];
+ if (a == 16'hFFFD) hex1 <= dcpu[7:0];
+ if (a == 16'hFFFE) hex2 <= dcpu[7:0];
+ if (a == 16'hFFFF) hex3 <= dcpu[7:0];
+ if (a == 16'hFFF0) hex4 <= dcpu[7:0];
+ if (a == 16'hFFF1) hex5 <= dcpu[7:0];
+ end
+end
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam uart.REFCLK = `SYS_CLOCK;
+`endif
+
+uart_wb uart
+(
+ .wb_clk_i(clk),
+ .wb_rst_i(~rst_n),
+ .wb_adr_i(a[0]),
+ .wb_dat_i(dcpu),
+ .wb_dat_o(dsio),
+ .wb_cyc_i((~wr_n | dbin) & (a[15:8] == 8'hFE)),
+ .wb_we_i(~wr_n & (a[15:8] == 8'hFE)),
+ .wb_stb_i((~wr_n | (dbin & ~uack)) & (a[15:8] == 8'hFE)),
+ .wb_ack_o(uack),
+
+ .tx_dat_o(ax3_uart_txd),
+ .tx_cts_i(1'b0),
+ .rx_dat_i(ax3_uart_rxd),
+
+// .rx_dtr_o(),
+// .tx_ready(),
+// .tx_empty(),
+// .rx_ready(),
+
+ .cfg_bdiv(baud[15:0]),
+ .cfg_nbit(2'b11),
+ .cfg_nstp(1'b1),
+ .cfg_pena(1'b0),
+ .cfg_podd(1'b0)
+);
+
+vm80a_core cpu
+(
+ .pin_clk(clk),
+ .pin_f1(f1),
+ .pin_f2(f2),
+ .pin_reset(~rst_n),
+ .pin_a(a),
+ .pin_dout(dcpu),
+ .pin_din(dsys),
+ .pin_hold(1'b0),
+ .pin_ready(1'b1),
+ .pin_int(intrq),
+ .pin_wr_n(wr_n),
+ .pin_dbin(dbin),
+ .pin_inte(inte),
+ .pin_sync(sync)
+);
+
+assign ax3_led[1:0] = led;
+assign ax3_led[2] = ~wr_n;
+assign ax3_led[3] = sync;
+
+//______________________________________________________________________________
+//
+// Temporary and debug assignments
+//
+// assign ax3_dram_dq = 16'hzzzz;
+// assign ax3_dram_addr = 13'h0000;
+// assign ax3_dram_ldqm = 1'b0;
+// assign ax3_dram_udqm = 1'b0;
+// assign ax3_dram_we_n = 1'b1;
+// assign ax3_dram_cas_n = 1'b1;
+// assign ax3_dram_ras_n = 1'b1;
+// assign ax3_dram_cs_n = 1'b1;
+// assign ax3_dram_ba[0] = 1'b0;
+// assign ax3_dram_ba[1] = 1'b0;
+// assign ax3_dram_clk = 1'b0;
+// assign ax3_dram_cke = 1'b0;
+//
+// assign ax3_spi_cs_n = 1'b1;
+// assign ax3_spi_clk = 1'b0;
+// assign ax3_spi_mosi = 1'bz;
+//
+// assign ax3_sd_cs_n = 1'bz;
+// assign ax3_sd_clk = 1'b0;
+// assign ax3_sd_mosi = 1'bz;
+// assign ax3_sd_miso = 1'bz;
+//
+// assign ax3_i2c_dat = 1'hz;
+// assign ax3_i2c_clk = 1'hz;
+// assign ax3_rtc_rst_n = 1'hz;
+// assign ax3_rtc_sclk = 1'hz;
+// assign ax3_rtc_sdat = 1'hz;
+assign ax3_buzzer = 1'hz;
+//
+// assign ax3_vga_hs = 1'b0;
+// assign ax3_vga_vs = 1'b0;
+// assign ax3_vga_r = 5'h0;
+// assign ax3_vga_g = 6'h0;
+// assign ax3_vga_b = 5'h0;
+//
+// assign ax3_gpio0 = 34'hzzzzzzzzz;
+// assign ax3_gpio1 = 34'hzzzzzzzzz;
+//
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/ax309/ax309_uart.v b/1801BM1_vm80a/org/rtl/ax309/ax309_uart.v
new file mode 100644
index 0000000000000000000000000000000000000000..3dc00014e21439a6ad9a4c1bf00e624cee436fc9
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/ax309/ax309_uart.v
@@ -0,0 +1,378 @@
+//
+// Copyright (c) 2014-2015 by 1801BM1@gmail.com
+//
+// Universal Serial Asynchronous Receiver-Transmitter (simplified 8251)
+//______________________________________________________________________________
+//
+module uart_wb #(parameter REFCLK=50000000)
+(
+ input wb_clk_i, // system clock
+ input wb_rst_i, // peripheral reset
+ //
+ input [0:0] wb_adr_i, //
+ input [7:0] wb_dat_i, //
+ output reg [7:0] wb_dat_o, //
+ input wb_cyc_i, //
+ input wb_we_i, //
+ input wb_stb_i, //
+ output reg wb_ack_o, //
+ //
+ output tx_dat_o, // output serial data (txd)
+ input tx_cts_i, // enable transmitter (rts)
+ input rx_dat_i, // input serial data (rxd)
+ output rx_dtr_o, // receiver ready (cts)
+ //
+ output tx_ready_o, // tx ready request
+ output tx_empty_o, // tx empty request
+ output rx_ready_o, // rx ready request
+ //
+ input [15:0] cfg_bdiv, // baudrate divisor: (921600/baud)-1
+ input [1:0] cfg_nbit, // word length: 00-5, 01-6, 10-7, 11-8 bit
+ input cfg_nstp, // tx stop bits: 0 - 1 stop, 1 - 2 stop
+ input cfg_pena, // parity control enable
+ input cfg_podd // odd parity (complete to odd ones)
+);
+
+wire [63:0] add_arg;
+reg [16:0] add_reg;
+reg [15:0] baud_div;
+reg baud_x16;
+wire baud_ref;
+
+reg [1:0] tx_cts_reg;
+reg [1:0] rx_dat_reg;
+
+wire csr_wstb;
+wire rbr_rstb;
+wire thr_wstb;
+
+wire tx_par;
+reg [7:0] tx_thr;
+reg [9:0] tx_shr;
+reg [7:0] tx_bcnt;
+reg tx_busy;
+reg tx_ready, tx_empty, tx_break;
+
+wire rx_dat;
+reg [7:0] rx_rbr;
+reg [8:0] rx_shr;
+reg [7:0] rx_bcnt;
+reg rx_ready, rx_perr, rx_ovf, rx_break;
+wire rx_load, rx_stb;
+reg rx_frame, rx_start, rx_par;
+
+//______________________________________________________________________________
+//
+// Caution note: the arithmetic expressions should be calculated in 64-bit width
+//
+assign add_arg = (64'h0000000000100000 * 64'd921600)/REFCLK;
+assign baud_ref = add_reg[16];
+//
+// Phase accumulator to generate 921600 * 16 Hz reference clock strobe
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ add_reg <= 17'h00000;
+ else
+ begin
+ add_reg <= {1'b0, add_reg[15:0]} + add_arg[16:0];
+ end
+end
+//
+// Baud rate x16 generator
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ baud_div <= 16'h0000;
+ baud_x16 <= 1'b0;
+ end
+ else
+ begin
+ if (baud_ref)
+ if (baud_div == 16'h0000)
+ baud_div <= cfg_bdiv;
+ else
+ baud_div <= baud_div - 16'h0001;
+
+ baud_x16 <= baud_ref & (baud_div == 16'h0000);
+ end
+
+end
+
+//______________________________________________________________________________
+//
+assign csr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & wb_adr_i[0];
+assign thr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & ~wb_adr_i[0];
+assign rbr_rstb = wb_cyc_i & wb_stb_i & ~wb_we_i & ~wb_ack_o & ~wb_adr_i[0];
+//
+// Output data multiplexed register
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ wb_dat_o <= 8'h00;
+ else
+//
+// if (wb_cyc_i & wb_stb_i & ~wb_ack_o)
+//
+ begin
+ if (wb_adr_i[0])
+ wb_dat_o <= (tx_ready << 7)
+ | (tx_break << 6)
+ | (tx_empty << 5)
+ | (rx_ready << 3)
+ | (rx_break << 2)
+ | (rx_perr << 1)
+ | (rx_ovf << 0);
+ else
+ wb_dat_o <= rx_rbr;
+ end
+end
+
+always @(posedge wb_clk_i)
+ wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
+
+//
+// Control register bits
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ tx_break <= 1'b0;
+ else
+ if (csr_wstb) tx_break <= wb_dat_i[6];
+end
+
+//______________________________________________________________________________
+//
+// Interrupts
+//
+assign tx_ready_o = tx_ready;
+assign tx_empty_o = tx_empty;
+assign rx_ready_o = rx_ready;
+
+//______________________________________________________________________________
+//
+// Metastability issues
+//
+always @(posedge wb_clk_i)
+begin
+ tx_cts_reg[0] <= ~tx_cts_i;
+ tx_cts_reg[1] <= tx_cts_reg[0];
+
+ rx_dat_reg[0] <= rx_dat_i;
+ rx_dat_reg[1] <= rx_dat_reg[0];
+end
+
+//______________________________________________________________________________
+//
+// Transmitter unit
+//
+assign tx_par = tx_thr[0] ^ tx_thr[1] ^ tx_thr[2] ^ tx_thr[3] ^ tx_thr[4]
+ ^ (tx_thr[5] & (cfg_nbit >= 2'b01))
+ ^ (tx_thr[6] & (cfg_nbit >= 2'b10))
+ ^ (tx_thr[7] & (cfg_nbit == 2'b11))
+ ^ cfg_podd;
+assign tx_dat_o = tx_shr[0] & ~tx_break;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ tx_ready <= 1'b1;
+ tx_empty <= 1'b1;
+ tx_shr <= 10'o1777;
+ tx_busy <= 1'b0;
+ tx_bcnt <= 8'b00000000;
+ tx_thr <= 8'b00000000;
+ end
+ else
+ begin
+ tx_empty <= tx_ready & ~tx_busy;
+ //
+ // Transmitter hold register write
+ //
+ if (thr_wstb)
+ begin
+ tx_ready <= 1'b0;
+ tx_thr <= wb_dat_i[7:0];
+ end
+
+ if (baud_x16)
+ begin
+ //
+ // Transmit process
+ //
+ if (tx_busy)
+ begin
+ if (tx_bcnt == 8'b00000001)
+ tx_busy <= 1'b0;
+
+ if (tx_bcnt != 8'b00000000)
+ tx_bcnt <= tx_bcnt - 8'b00000001;
+
+ if (tx_bcnt[3:0] == 4'b0000)
+ tx_shr <= {1'b1, tx_shr[9:1]};
+ end
+
+ //
+ // Starting new word transmit
+ //
+ if (~tx_ready & ~tx_busy & tx_cts_reg[1])
+ begin
+ tx_busy <= 1'b1;
+ tx_ready <= ~thr_wstb;
+ tx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena} + {3'b000, cfg_nstp}, 4'b1111};
+
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {3'b111, tx_par, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {2'b11, tx_par, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {1'b1, tx_par, tx_thr[6:0], 1'b0};
+ default: tx_shr <= { tx_par, tx_thr[7:0], 1'b0};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {4'b1111, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {3'b111, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {2'b11, tx_thr[6:0], 1'b0};
+ default: tx_shr <= {1'b1, tx_thr[7:0], 1'b0};
+ endcase
+ end
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// Receiver unit
+//
+assign rx_dtr_o = rx_ready;
+assign rx_dat = rx_dat_reg[1];
+
+assign rx_load = rx_stb & (rx_bcnt[7:4] == 4'b0000);
+assign rx_stb = (rx_bcnt[3:0] == 4'b0001) & baud_x16;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ rx_ready <= 1'b0;
+ rx_break <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_start <= 1'b0;
+ rx_par <= 1'b0;
+ rx_rbr <= 8'b00000000;
+ rx_shr <= 9'b00000000;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ if (rx_load)
+ begin
+ rx_ready <= 1'b1;
+ case(cfg_nbit)
+ 2'b00: rx_rbr <= {3'b000, rx_shr[4:0]};
+ 2'b01: rx_rbr <= {2'b00, rx_shr[5:0]};
+ 2'b10: rx_rbr <= {1'b0, rx_shr[6:0]};
+ default: rx_rbr <= rx_shr[7:0];
+ endcase
+ rx_perr <= rx_par;
+ rx_ovf <= rx_ready;
+ rx_break <= ~rx_dat;
+ end
+ else
+ if (rbr_rstb)
+ begin
+ rx_ready <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ end
+
+ if (baud_x16)
+ begin
+ if (~rx_frame)
+ //
+ // Waiting for start bit
+ //
+ if (~rx_dat)
+ begin
+ rx_par <= cfg_pena & cfg_podd;
+ rx_start <= 1'b1;
+ rx_frame <= 1'b1;
+ rx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena}, 4'b0111};
+ end
+ else
+ begin
+ rx_start <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ //
+ // Receiving frame
+ //
+ if (rx_bcnt != 8'b00000000)
+ rx_bcnt <= rx_bcnt - 8'b00000001;
+ //
+ // Start bit monitoring
+ //
+ if (rx_start)
+ begin
+ if (rx_dat)
+ begin
+ //
+ // Spurrious start bit
+ //
+ rx_start <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ if (rx_bcnt[3:0] == 4'b0010)
+ rx_start <= 1'b0;
+ end
+ else
+ begin
+ //
+ // Receiving data
+ //
+ if (rx_stb)
+ begin
+ rx_par <= (rx_par ^ rx_dat) & cfg_pena;
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b01: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ 2'b10: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ default: rx_shr <= {rx_dat, rx_shr[8:1]};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {4'b0000, rx_dat, rx_shr[4:1]};
+ 2'b01: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b10: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ default: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ endcase
+ if (rx_load & rx_dat)
+ begin
+ //
+ // Stop bit detected
+ //
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ end
+ if ((rx_bcnt == 8'b00000000) & rx_dat)
+ rx_frame <= 1'b0;
+ end
+ end
+ end
+ end
+end
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de0/de0_mem.v b/1801BM1_vm80a/org/rtl/de0/de0_mem.v
new file mode 100644
index 0000000000000000000000000000000000000000..35121a76c1ae53fe8156e7669c3ad131d2ee1a8c
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de0/de0_mem.v
@@ -0,0 +1,104 @@
+// megafunction wizard: %RAM: 1-PORT%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altsyncram
+
+// ============================================================
+// File Name: de0_mem.v
+// Megafunction Name(s):
+// altsyncram
+//
+// Simulation Library Files(s):
+// altera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 12.1 Build 177 11/07/2012 SJ Full Version
+// ************************************************************
+
+
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module memini (
+ address,
+ clock,
+ data,
+ wren,
+ q);
+
+ input [13:0] address;
+ input clock;
+ input [7:0] data;
+ input wren;
+ output [7:0] q;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+ tri1 clock;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+ wire [7:0] sub_wire0;
+ wire [7:0] q = sub_wire0[7:0];
+
+ altsyncram altsyncram_component (
+ .address_a (address),
+ .clock0 (clock),
+ .data_a (data),
+ .wren_a (wren),
+ .q_a (sub_wire0),
+ .aclr0 (1'b0),
+ .aclr1 (1'b0),
+ .address_b (1'b1),
+ .addressstall_a (1'b0),
+ .addressstall_b (1'b0),
+ .byteena_a (1'b1),
+ .byteena_b (1'b1),
+ .clock1 (1'b1),
+ .clocken0 (1'b1),
+ .clocken1 (1'b1),
+ .clocken2 (1'b1),
+ .clocken3 (1'b1),
+ .data_b (1'b1),
+ .eccstatus (),
+ .q_b (),
+ .rden_a (1'b1),
+ .rden_b (1'b1),
+ .wren_b (1'b0));
+ defparam
+ altsyncram_component.clock_enable_input_a = "BYPASS",
+ altsyncram_component.clock_enable_output_a = "BYPASS",
+ altsyncram_component.init_file = "../../../tst/rom/memini.mif",
+ altsyncram_component.intended_device_family = "Cyclone III",
+ altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
+ altsyncram_component.lpm_type = "altsyncram",
+ altsyncram_component.numwords_a = 16384,
+ altsyncram_component.operation_mode = "SINGLE_PORT",
+ altsyncram_component.outdata_aclr_a = "NONE",
+ altsyncram_component.outdata_reg_a = "UNREGISTERED",
+ altsyncram_component.power_up_uninitialized = "FALSE",
+ altsyncram_component.ram_block_type = "M9K",
+ altsyncram_component.read_during_write_mode_port_a = "DONT_CARE",
+ altsyncram_component.widthad_a = 14,
+ altsyncram_component.width_a = 8,
+ altsyncram_component.width_byteena_a = 1;
+
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de0/de0_top.v b/1801BM1_vm80a/org/rtl/de0/de0_top.v
new file mode 100644
index 0000000000000000000000000000000000000000..9e9a95772f8ae3fdd9cfe8a214312d57748440f4
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de0/de0_top.v
@@ -0,0 +1,300 @@
+//______________________________________________________________________________
+//
+// Top module for DE0 board based system
+
+//______________________________________________________________________________
+//
+// External oscillator clock, feeds the PLLs
+//
+`define OSC_CLOCK 50000000
+//
+// Global system clock
+//
+`define SYS_CLOCK 50000000
+//
+// Console baudrate
+//
+`define SYS_BAUD 115200
+//______________________________________________________________________________
+//
+// Reset button debounce interval (in ms))
+//
+`define RESET_BUTTON_DEBOUNCE_MS 5
+//
+// Internal reset pulse width (in system clocks)
+//
+`define RESET_PULSE_WIDTH_CLK 7
+
+//______________________________________________________________________________
+//
+// Top project module - instantiates the DE0 board itself
+//
+module de0
+(
+ input de0_clock_50, // clock input 50 MHz
+ input de0_clock_50_2, // clock input 50 MHz
+ //
+ input [2:0] de0_button, // push button[2:0]
+ //
+ input [9:0] de0_sw, // DPDT toggle switch[9:0]
+ output [7:0] de0_hex0, // seven segment digit 0
+ output [7:0] de0_hex1, // seven segment digit 1
+ output [7:0] de0_hex2, // seven segment digit 2
+ output [7:0] de0_hex3, // seven segment digit 3
+ output [9:0] de0_led, // LED green[9:0]
+ //
+ output de0_uart_txd, // UART transmitter
+ input de0_uart_rxd, // UART receiver
+ output de0_uart_cts, // UART clear to send
+ input de0_uart_rts, // UART request to send
+ //
+ inout [15:0] de0_dram_dq, // SDRAM data bus 16 bits
+ output [12:0] de0_dram_addr, // SDRAM address bus 13 bits
+ output de0_dram_ldqm, // SDRAM low-byte data mask
+ output de0_dram_udqm, // SDRAM high-byte data mask
+ output de0_dram_we_n, // SDRAM write enable
+ output de0_dram_cas_n, // SDRAM column address strobe
+ output de0_dram_ras_n, // SDRAM row address strobe
+ output de0_dram_cs_n, // SDRAM chip select
+ output [1:0] de0_dram_ba, // SDRAM bank address
+ output de0_dram_clk, // SDRAM clock
+ output de0_dram_cke, // SDRAM clock enable
+ //
+ inout [15:0] de0_fl_dq, // FLASH data bus 15 Bits
+ output [21:0] de0_fl_addr, // FLASH address bus 22 Bits
+ output de0_fl_we_n, // FLASH write enable
+ output de0_fl_rst_n, // FLASH reset
+ output de0_fl_oe_n, // FLASH output enable
+ output de0_fl_ce_n, // FLASH chip enable
+ output de0_fl_wp_n, // FLASH hardware write protect
+ output de0_fl_byte_n, // FLASH selects 8/16-bit mode
+ input de0_fl_rb, // FLASH ready/busy
+ //
+ output de0_lcd_blig, // LCD back light ON/OFF
+ output de0_lcd_rw, // LCD read/write select, 0 = write, 1 = read
+ output de0_lcd_en, // LCD enable
+ output de0_lcd_rs, // LCD command/data select, 0 = command, 1 = data
+ inout [7:0] de0_lcd_data, // LCD data bus 8 bits
+ //
+ inout de0_sd_mosi, // SD Card Data Output
+ inout de0_sd_miso, // SD Card Data Input
+ inout de0_sd_cmd, // SD Card Command Signal
+ output de0_sd_clk, // SD Card Clock
+ input de0_sd_wp_n, // SD Card Write Protect
+ //
+ inout de0_ps2_kbdat, // PS2 Keyboard Data
+ inout de0_ps2_kbclk, // PS2 Keyboard Clock
+ inout de0_ps2_msdat, // PS2 Mouse Data
+ inout de0_ps2_msclk, // PS2 Mouse Clock
+ //
+ output de0_vga_hs, // VGA H_SYNC
+ output de0_vga_vs, // VGA V_SYNC
+ output [3:0] de0_vga_r, // VGA Red[3:0]
+ output [3:0] de0_vga_g, // VGA Green[3:0]
+ output [3:0] de0_vga_b, // VGA Blue[3:0]
+ //
+ input [1:0] de0_gpio0_clkin, // GPIO Connection 0 Clock In Bus
+ output [1:0] de0_gpio0_clkout, // GPIO Connection 0 Clock Out Bus
+ inout [31:0] de0_gpio0_d, // GPIO Connection 0 Data Bus
+ //
+ input [1:0] de0_gpio1_clkin, // GPIO Connection 1 Clock In Bus
+ output [1:0] de0_gpio1_clkout, // GPIO Connection 1 Clock Out Bus
+ inout [31:0] de0_gpio1_d // GPIO Connection 1 Data Bus
+);
+
+wire [31:0] baud = 921600/`SYS_BAUD-1;
+wire clk, wr_n, rst_n, dbin;
+wire [7:0] dcpu;
+wire [7:0] dsys;
+wire [7:0] dsio;
+wire [7:0] dram;
+wire [15:0] a;
+wire uack;
+
+reg f1, f2;
+reg [7:0] hex0, hex1, hex2, hex3;
+reg [7:0] led;
+reg [7:0] rcnt = 8'h00;
+reg [2:0] div;
+reg [15:0] div1ms;
+reg ms, intrq, inta;
+wire inte, sync;
+
+assign clk = de0_clock_50;
+assign rst_n = (rcnt == 8'hFF);
+assign dsys = inta ? 8'hE7
+ : (a[15:8] == 8'hFF) ? {5'h00, de0_button[2:0]}
+ : (a[15:8] == 8'hFE) ? dsio
+ : dram;
+
+always @(posedge clk)
+begin
+ div <= div + 3'b001;
+ f1 <= div[0];
+ f2 <= ~div[0];
+
+ if (sync) inta = dcpu[0];
+ if (div1ms == ((`SYS_CLOCK/1000)-1))
+ begin
+ div1ms <= 16'h0000;
+ ms <= 1;
+ end
+ else
+ begin
+ div1ms <= div1ms + 16'h0001;
+ ms <= 0;
+ end
+
+ if (ms) intrq <= 1;
+ if (inta) intrq <= 0;
+end
+
+always @(posedge clk)
+begin
+ if (~de0_button[2])
+ rcnt <= 8'h00;
+ else
+ if (rcnt != 8'hFF) rcnt <= rcnt + 8'h01;
+end
+
+memini ram
+(
+ .address(a[13:0]),
+ .clock(clk),
+ .data(dcpu),
+ .wren(~wr_n & rst_n & ~a[15] & ~a[14]),
+ .q(dram)
+);
+
+always @(posedge clk)
+begin
+ if (~wr_n)
+ begin
+ if (a == 16'hFFFB) led <= dcpu;
+ if (a == 16'hFFFC) hex0 <= dcpu;
+ if (a == 16'hFFFD) hex1 <= dcpu;
+ if (a == 16'hFFFE) hex2 <= dcpu;
+ if (a == 16'hFFFF) hex3 <= dcpu;
+ end
+end
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam uart.REFCLK = `SYS_CLOCK;
+`endif
+
+uart_wb uart
+(
+ .wb_clk_i(clk),
+ .wb_rst_i(~rst_n),
+ .wb_adr_i(a[0]),
+ .wb_dat_i(dcpu),
+ .wb_dat_o(dsio),
+ .wb_cyc_i((~wr_n | dbin) & (a[15:8] == 8'hFE)),
+ .wb_we_i(~wr_n & (a[15:8] == 8'hFE)),
+ .wb_stb_i((~wr_n | (dbin & ~uack)) & (a[15:8] == 8'hFE)),
+ .wb_ack_o(uack),
+
+ .tx_dat_o(de0_uart_txd),
+ .tx_cts_i(1'b0),
+ .rx_dat_i(de0_uart_rxd),
+ .rx_dtr_o(de0_uart_cts),
+
+// .tx_ready(),
+// .tx_empty(),
+// .rx_ready(),
+
+ .cfg_bdiv(baud[15:0]),
+ .cfg_nbit(2'b11),
+ .cfg_nstp(1'b1),
+ .cfg_pena(1'b0),
+ .cfg_podd(1'b0)
+);
+
+vm80a_core cpu
+(
+ .pin_clk(clk),
+ .pin_f1(f1),
+ .pin_f2(f2),
+ .pin_reset(~rst_n),
+ .pin_a(a),
+ .pin_dout(dcpu),
+ .pin_din(dsys),
+ .pin_hold(1'b0),
+ .pin_ready(1'b1),
+ .pin_int(intrq),
+ .pin_wr_n(wr_n),
+ .pin_dbin(dbin),
+ .pin_inte(inte),
+ .pin_sync(sync)
+);
+
+assign de0_hex0 = ~hex0;
+assign de0_hex1 = ~hex1;
+assign de0_hex2 = ~hex2;
+assign de0_hex3 = ~hex3;
+
+assign de0_led[7:0] = led;
+assign de0_led[9] = ~wr_n;
+assign de0_led[8] = sync;
+
+//______________________________________________________________________________
+//
+// Temporary and debug assignments
+//
+// assign de0_uart_txd = 1'bz;
+// assign de0_uart_cts = 1'bz;
+
+assign de0_dram_dq = 16'hzzzz;
+assign de0_dram_addr = 13'h0000;
+assign de0_dram_ldqm = 1'b0;
+assign de0_dram_udqm = 1'b0;
+assign de0_dram_we_n = 1'b1;
+assign de0_dram_cas_n = 1'b1;
+assign de0_dram_ras_n = 1'b1;
+assign de0_dram_cs_n = 1'b1;
+assign de0_dram_ba[0] = 1'b0;
+assign de0_dram_ba[1] = 1'b0;
+assign de0_dram_clk = 1'b0;
+assign de0_dram_cke = 1'b0;
+
+assign de0_fl_dq = 16'hzzzz;
+assign de0_fl_addr = 22'hzzzzzz;
+assign de0_fl_we_n = 1'b1;
+assign de0_fl_rst_n = 1'b0;
+assign de0_fl_oe_n = 1'b1;
+assign de0_fl_ce_n = 1'b1;
+assign de0_fl_wp_n = 1'b0;
+assign de0_fl_byte_n = 1'b1;
+
+assign de0_lcd_data = 8'hzz;
+assign de0_lcd_blig = 1'b0;
+assign de0_lcd_rw = 1'b0;
+assign de0_lcd_en = 1'b0;
+assign de0_lcd_rs = 1'b0;
+
+assign de0_sd_clk = 1'h0;
+assign de0_sd_mosi = 1'hz;
+assign de0_sd_miso = 1'hz;
+assign de0_sd_cmd = 1'hz;
+
+assign de0_ps2_kbdat = 1'hz;
+assign de0_ps2_kbclk = 1'hz;
+assign de0_ps2_msdat = 1'hz;
+assign de0_ps2_msclk = 1'hz;
+
+assign de0_vga_hs = 1'b0;
+assign de0_vga_vs = 1'b0;
+assign de0_vga_r = 4'h0;
+assign de0_vga_g = 4'h0;
+assign de0_vga_b = 4'h0;
+
+assign de0_gpio0_clkout = 2'b00;
+assign de0_gpio1_clkout = 2'b00;
+assign de0_gpio0_d = 32'hzzzzzzzz;
+assign de0_gpio1_d = 32'hzzzzzzzz;
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de0/de0_uart.v b/1801BM1_vm80a/org/rtl/de0/de0_uart.v
new file mode 100644
index 0000000000000000000000000000000000000000..3dc00014e21439a6ad9a4c1bf00e624cee436fc9
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de0/de0_uart.v
@@ -0,0 +1,378 @@
+//
+// Copyright (c) 2014-2015 by 1801BM1@gmail.com
+//
+// Universal Serial Asynchronous Receiver-Transmitter (simplified 8251)
+//______________________________________________________________________________
+//
+module uart_wb #(parameter REFCLK=50000000)
+(
+ input wb_clk_i, // system clock
+ input wb_rst_i, // peripheral reset
+ //
+ input [0:0] wb_adr_i, //
+ input [7:0] wb_dat_i, //
+ output reg [7:0] wb_dat_o, //
+ input wb_cyc_i, //
+ input wb_we_i, //
+ input wb_stb_i, //
+ output reg wb_ack_o, //
+ //
+ output tx_dat_o, // output serial data (txd)
+ input tx_cts_i, // enable transmitter (rts)
+ input rx_dat_i, // input serial data (rxd)
+ output rx_dtr_o, // receiver ready (cts)
+ //
+ output tx_ready_o, // tx ready request
+ output tx_empty_o, // tx empty request
+ output rx_ready_o, // rx ready request
+ //
+ input [15:0] cfg_bdiv, // baudrate divisor: (921600/baud)-1
+ input [1:0] cfg_nbit, // word length: 00-5, 01-6, 10-7, 11-8 bit
+ input cfg_nstp, // tx stop bits: 0 - 1 stop, 1 - 2 stop
+ input cfg_pena, // parity control enable
+ input cfg_podd // odd parity (complete to odd ones)
+);
+
+wire [63:0] add_arg;
+reg [16:0] add_reg;
+reg [15:0] baud_div;
+reg baud_x16;
+wire baud_ref;
+
+reg [1:0] tx_cts_reg;
+reg [1:0] rx_dat_reg;
+
+wire csr_wstb;
+wire rbr_rstb;
+wire thr_wstb;
+
+wire tx_par;
+reg [7:0] tx_thr;
+reg [9:0] tx_shr;
+reg [7:0] tx_bcnt;
+reg tx_busy;
+reg tx_ready, tx_empty, tx_break;
+
+wire rx_dat;
+reg [7:0] rx_rbr;
+reg [8:0] rx_shr;
+reg [7:0] rx_bcnt;
+reg rx_ready, rx_perr, rx_ovf, rx_break;
+wire rx_load, rx_stb;
+reg rx_frame, rx_start, rx_par;
+
+//______________________________________________________________________________
+//
+// Caution note: the arithmetic expressions should be calculated in 64-bit width
+//
+assign add_arg = (64'h0000000000100000 * 64'd921600)/REFCLK;
+assign baud_ref = add_reg[16];
+//
+// Phase accumulator to generate 921600 * 16 Hz reference clock strobe
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ add_reg <= 17'h00000;
+ else
+ begin
+ add_reg <= {1'b0, add_reg[15:0]} + add_arg[16:0];
+ end
+end
+//
+// Baud rate x16 generator
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ baud_div <= 16'h0000;
+ baud_x16 <= 1'b0;
+ end
+ else
+ begin
+ if (baud_ref)
+ if (baud_div == 16'h0000)
+ baud_div <= cfg_bdiv;
+ else
+ baud_div <= baud_div - 16'h0001;
+
+ baud_x16 <= baud_ref & (baud_div == 16'h0000);
+ end
+
+end
+
+//______________________________________________________________________________
+//
+assign csr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & wb_adr_i[0];
+assign thr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & ~wb_adr_i[0];
+assign rbr_rstb = wb_cyc_i & wb_stb_i & ~wb_we_i & ~wb_ack_o & ~wb_adr_i[0];
+//
+// Output data multiplexed register
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ wb_dat_o <= 8'h00;
+ else
+//
+// if (wb_cyc_i & wb_stb_i & ~wb_ack_o)
+//
+ begin
+ if (wb_adr_i[0])
+ wb_dat_o <= (tx_ready << 7)
+ | (tx_break << 6)
+ | (tx_empty << 5)
+ | (rx_ready << 3)
+ | (rx_break << 2)
+ | (rx_perr << 1)
+ | (rx_ovf << 0);
+ else
+ wb_dat_o <= rx_rbr;
+ end
+end
+
+always @(posedge wb_clk_i)
+ wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
+
+//
+// Control register bits
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ tx_break <= 1'b0;
+ else
+ if (csr_wstb) tx_break <= wb_dat_i[6];
+end
+
+//______________________________________________________________________________
+//
+// Interrupts
+//
+assign tx_ready_o = tx_ready;
+assign tx_empty_o = tx_empty;
+assign rx_ready_o = rx_ready;
+
+//______________________________________________________________________________
+//
+// Metastability issues
+//
+always @(posedge wb_clk_i)
+begin
+ tx_cts_reg[0] <= ~tx_cts_i;
+ tx_cts_reg[1] <= tx_cts_reg[0];
+
+ rx_dat_reg[0] <= rx_dat_i;
+ rx_dat_reg[1] <= rx_dat_reg[0];
+end
+
+//______________________________________________________________________________
+//
+// Transmitter unit
+//
+assign tx_par = tx_thr[0] ^ tx_thr[1] ^ tx_thr[2] ^ tx_thr[3] ^ tx_thr[4]
+ ^ (tx_thr[5] & (cfg_nbit >= 2'b01))
+ ^ (tx_thr[6] & (cfg_nbit >= 2'b10))
+ ^ (tx_thr[7] & (cfg_nbit == 2'b11))
+ ^ cfg_podd;
+assign tx_dat_o = tx_shr[0] & ~tx_break;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ tx_ready <= 1'b1;
+ tx_empty <= 1'b1;
+ tx_shr <= 10'o1777;
+ tx_busy <= 1'b0;
+ tx_bcnt <= 8'b00000000;
+ tx_thr <= 8'b00000000;
+ end
+ else
+ begin
+ tx_empty <= tx_ready & ~tx_busy;
+ //
+ // Transmitter hold register write
+ //
+ if (thr_wstb)
+ begin
+ tx_ready <= 1'b0;
+ tx_thr <= wb_dat_i[7:0];
+ end
+
+ if (baud_x16)
+ begin
+ //
+ // Transmit process
+ //
+ if (tx_busy)
+ begin
+ if (tx_bcnt == 8'b00000001)
+ tx_busy <= 1'b0;
+
+ if (tx_bcnt != 8'b00000000)
+ tx_bcnt <= tx_bcnt - 8'b00000001;
+
+ if (tx_bcnt[3:0] == 4'b0000)
+ tx_shr <= {1'b1, tx_shr[9:1]};
+ end
+
+ //
+ // Starting new word transmit
+ //
+ if (~tx_ready & ~tx_busy & tx_cts_reg[1])
+ begin
+ tx_busy <= 1'b1;
+ tx_ready <= ~thr_wstb;
+ tx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena} + {3'b000, cfg_nstp}, 4'b1111};
+
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {3'b111, tx_par, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {2'b11, tx_par, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {1'b1, tx_par, tx_thr[6:0], 1'b0};
+ default: tx_shr <= { tx_par, tx_thr[7:0], 1'b0};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {4'b1111, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {3'b111, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {2'b11, tx_thr[6:0], 1'b0};
+ default: tx_shr <= {1'b1, tx_thr[7:0], 1'b0};
+ endcase
+ end
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// Receiver unit
+//
+assign rx_dtr_o = rx_ready;
+assign rx_dat = rx_dat_reg[1];
+
+assign rx_load = rx_stb & (rx_bcnt[7:4] == 4'b0000);
+assign rx_stb = (rx_bcnt[3:0] == 4'b0001) & baud_x16;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ rx_ready <= 1'b0;
+ rx_break <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_start <= 1'b0;
+ rx_par <= 1'b0;
+ rx_rbr <= 8'b00000000;
+ rx_shr <= 9'b00000000;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ if (rx_load)
+ begin
+ rx_ready <= 1'b1;
+ case(cfg_nbit)
+ 2'b00: rx_rbr <= {3'b000, rx_shr[4:0]};
+ 2'b01: rx_rbr <= {2'b00, rx_shr[5:0]};
+ 2'b10: rx_rbr <= {1'b0, rx_shr[6:0]};
+ default: rx_rbr <= rx_shr[7:0];
+ endcase
+ rx_perr <= rx_par;
+ rx_ovf <= rx_ready;
+ rx_break <= ~rx_dat;
+ end
+ else
+ if (rbr_rstb)
+ begin
+ rx_ready <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ end
+
+ if (baud_x16)
+ begin
+ if (~rx_frame)
+ //
+ // Waiting for start bit
+ //
+ if (~rx_dat)
+ begin
+ rx_par <= cfg_pena & cfg_podd;
+ rx_start <= 1'b1;
+ rx_frame <= 1'b1;
+ rx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena}, 4'b0111};
+ end
+ else
+ begin
+ rx_start <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ //
+ // Receiving frame
+ //
+ if (rx_bcnt != 8'b00000000)
+ rx_bcnt <= rx_bcnt - 8'b00000001;
+ //
+ // Start bit monitoring
+ //
+ if (rx_start)
+ begin
+ if (rx_dat)
+ begin
+ //
+ // Spurrious start bit
+ //
+ rx_start <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ if (rx_bcnt[3:0] == 4'b0010)
+ rx_start <= 1'b0;
+ end
+ else
+ begin
+ //
+ // Receiving data
+ //
+ if (rx_stb)
+ begin
+ rx_par <= (rx_par ^ rx_dat) & cfg_pena;
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b01: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ 2'b10: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ default: rx_shr <= {rx_dat, rx_shr[8:1]};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {4'b0000, rx_dat, rx_shr[4:1]};
+ 2'b01: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b10: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ default: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ endcase
+ if (rx_load & rx_dat)
+ begin
+ //
+ // Stop bit detected
+ //
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ end
+ if ((rx_bcnt == 8'b00000000) & rx_dat)
+ rx_frame <= 1'b0;
+ end
+ end
+ end
+ end
+end
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de1/de1_mem.v b/1801BM1_vm80a/org/rtl/de1/de1_mem.v
new file mode 100644
index 0000000000000000000000000000000000000000..e10dd5c8b56cb662f72edd65bce81ee40f5a1021
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de1/de1_mem.v
@@ -0,0 +1,103 @@
+// megafunction wizard: %RAM: 1-PORT%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altsyncram
+
+// ============================================================
+// File Name: de1_mem.v
+// Megafunction Name(s):
+// altsyncram
+//
+// Simulation Library Files(s):
+// altera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 12.1 Build 243 01/31/2013 SP 1 SJ Full Version
+// ************************************************************
+
+
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module memini (
+ address,
+ clock,
+ data,
+ wren,
+ q);
+
+ input [13:0] address;
+ input clock;
+ input [7:0] data;
+ input wren;
+ output [7:0] q;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+ tri1 clock;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+ wire [7:0] sub_wire0;
+ wire [7:0] q = sub_wire0[7:0];
+
+ altsyncram altsyncram_component (
+ .address_a (address),
+ .clock0 (clock),
+ .data_a (data),
+ .wren_a (wren),
+ .q_a (sub_wire0),
+ .aclr0 (1'b0),
+ .aclr1 (1'b0),
+ .address_b (1'b1),
+ .addressstall_a (1'b0),
+ .addressstall_b (1'b0),
+ .byteena_a (1'b1),
+ .byteena_b (1'b1),
+ .clock1 (1'b1),
+ .clocken0 (1'b1),
+ .clocken1 (1'b1),
+ .clocken2 (1'b1),
+ .clocken3 (1'b1),
+ .data_b (1'b1),
+ .eccstatus (),
+ .q_b (),
+ .rden_a (1'b1),
+ .rden_b (1'b1),
+ .wren_b (1'b0));
+ defparam
+ altsyncram_component.clock_enable_input_a = "BYPASS",
+ altsyncram_component.clock_enable_output_a = "BYPASS",
+ altsyncram_component.init_file = "../../../tst/rom/memini.mif",
+ altsyncram_component.intended_device_family = "Cyclone II",
+ altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
+ altsyncram_component.lpm_type = "altsyncram",
+ altsyncram_component.numwords_a = 16384,
+ altsyncram_component.operation_mode = "SINGLE_PORT",
+ altsyncram_component.outdata_aclr_a = "NONE",
+ altsyncram_component.outdata_reg_a = "UNREGISTERED",
+ altsyncram_component.power_up_uninitialized = "FALSE",
+ altsyncram_component.ram_block_type = "M4K",
+ altsyncram_component.widthad_a = 14,
+ altsyncram_component.width_a = 8,
+ altsyncram_component.width_byteena_a = 1;
+
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de1/de1_top.v b/1801BM1_vm80a/org/rtl/de1/de1_top.v
new file mode 100644
index 0000000000000000000000000000000000000000..ae6ee6570f9ffb918f43067802ed1c0e9cc9f4e1
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de1/de1_top.v
@@ -0,0 +1,312 @@
+//______________________________________________________________________________
+//
+// Top module for DE1 board based system
+//
+//______________________________________________________________________________
+//
+// External oscillator clock, feeds the PLLs
+//
+`define OSC_CLOCK 50000000
+//
+// Global system clock
+//
+`define SYS_CLOCK 50000000
+
+//______________________________________________________________________________
+//
+// Reset button debounce interval (in ms))
+//
+`define RESET_BUTTON_DEBOUNCE_MS 5
+//
+// Internal reset pulse width (in system clocks)
+//
+`define RESET_PULSE_WIDTH_CLK 7
+//
+// Console baudrate
+//
+`define SYS_BAUD 115200
+
+//______________________________________________________________________________
+//
+// Top project module - instantiates the DE1 board itself
+//
+module de1
+(
+ input [1:0] de1_clock_24, // clock input 24 MHz
+ input [1:0] de1_clock_27, // clock input 27 MHz
+ input de1_clock_50, // clock input 50 MHz
+ input de1_clock_ext, // external clock input
+ //
+ input [3:0] de1_button, // push button[3:0]
+ //
+ input [9:0] de1_sw, // DPDT toggle switch[9:0]
+ output [6:0] de1_hex0, // seven segment digit 0
+ output [6:0] de1_hex1, // seven segment digit 1
+ output [6:0] de1_hex2, // seven segment digit 2
+ output [6:0] de1_hex3, // seven segment digit 3
+ output [7:0] de1_ledg, // LED green[7:0]
+ output [9:0] de1_ledr, // LED red[9:0]
+ //
+ output de1_uart_txd, // UART transmitter
+ input de1_uart_rxd, // UART receiver
+ //
+ inout [15:0] de1_dram_dq, // SDRAM data bus 16 bits
+ output [11:0] de1_dram_addr, // SDRAM address bus 12 bits
+ output de1_dram_ldqm, // SDRAM low-byte data mask
+ output de1_dram_udqm, // SDRAM high-byte data mask
+ output de1_dram_we_n, // SDRAM write enable
+ output de1_dram_cas_n, // SDRAM column address strobe
+ output de1_dram_ras_n, // SDRAM row address strobe
+ output de1_dram_cs_n, // SDRAM chip select
+ output [1:0] de1_dram_ba, // SDRAM bank address
+ output de1_dram_clk, // SDRAM clock
+ output de1_dram_cke, // SDRAM clock enable
+ //
+ inout [7:0] de1_fl_dq, // FLASH data bus 8 Bits
+ output [21:0] de1_fl_addr, // FLASH address bus 22 Bits
+ output de1_fl_we_n, // FLASH write enable
+ output de1_fl_rst_n, // FLASH reset
+ output de1_fl_oe_n, // FLASH output enable
+ output de1_fl_ce_n, // FLASH chip enable
+ //
+ inout [15:0] de1_sram_dq, // SRAM Data bus 16 Bits
+ output [17:0] de1_sram_addr, // SRAM Address bus 18 Bits
+ output de1_sram_ub_n, // SRAM High-byte Data Mask
+ output de1_sram_lb_n, // SRAM Low-byte Data Mask
+ output de1_sram_we_n, // SRAM Write Enable
+ output de1_sram_ce_n, // SRAM Chip Enable
+ output de1_sram_oe_n, // SRAM Output Enable
+ //
+ inout de1_sd_mosi, // SD Card Data Output
+ inout de1_sd_miso, // SD Card Data Input
+ inout de1_sd_cmd, // SD Card Command Signal
+ output de1_sd_clk, // SD Card Clock
+ //
+ input de1_tdi, // CPLD -> FPGA (data in)
+ input de1_tck, // CPLD -> FPGA (clk)
+ input de1_tms, // CPLD -> FPGA (mode select)
+ output de1_tdo, // FPGA -> CPLD (data out)
+ //
+ inout de1_i2c_dat, // I2C Data
+ output de1_i2c_clk, // I2C Clock
+ inout de1_ps2_dat, // PS2 Data
+ inout de1_ps2_clk, // PS2 Clock
+ //
+ output de1_vga_hs, // VGA H_SYNC
+ output de1_vga_vs, // VGA V_SYNC
+ output [3:0] de1_vga_r, // VGA Red[3:0]
+ output [3:0] de1_vga_g, // VGA Green[3:0]
+ output [3:0] de1_vga_b, // VGA Blue[3:0]
+ //
+ output de1_aud_adclrck, // Audio CODEC ADC LR Clock
+ input de1_aud_adcdat, // Audio CODEC ADC Data
+ output de1_aud_daclrck, // Audio CODEC DAC LR Clock
+ output de1_aud_dacdat, // Audio CODEC DAC Data
+ inout de1_aud_bclk, // Audio CODEC Bit-Stream Clock
+ output de1_aud_xck, // Audio CODEC Chip Clock
+ //
+ inout [35:0] de1_gpio0, // GPIO Connection 0
+ inout [35:0] de1_gpio1 // GPIO Connection 1
+);
+
+//______________________________________________________________________________
+//
+// Top module for DE1 board based system
+//
+wire [31:0] baud = 921600/`SYS_BAUD-1;
+wire clk, wr_n, rst_n, dbin;
+wire [7:0] dcpu;
+wire [7:0] dsys;
+wire [7:0] dsio;
+wire [7:0] dram;
+wire [15:0] a;
+wire uack;
+
+reg f1, f2;
+reg [6:0] hex0, hex1, hex2, hex3;
+reg [7:0] led;
+reg [7:0] rcnt = 8'h00;
+reg [2:0] div;
+reg [15:0] div1ms;
+reg ms, intrq, inta;
+wire inte, sync;
+
+assign clk = de1_clock_50;
+assign rst_n = (rcnt == 8'hFF);
+assign dsys = inta ? 8'hE7
+ : (a[15:8] == 8'hFF) ? {4'h0, de1_button[3:0]}
+ : (a[15:8] == 8'hFE) ? dsio
+ : dram;
+
+always @(posedge clk)
+begin
+ div <= div + 3'b001;
+ f1 <= div[0];
+ f2 <= ~div[0];
+
+ if (sync) inta = dcpu[0];
+ if (div1ms == ((`SYS_CLOCK/1000)-1))
+ begin
+ div1ms <= 16'h0000;
+ ms <= 1;
+ end
+ else
+ begin
+ div1ms <= div1ms + 16'h0001;
+ ms <= 0;
+ end
+
+ if (ms) intrq <= 1;
+ if (inta) intrq <= 0;
+end
+
+always @(posedge clk)
+begin
+ if (~de1_button[3])
+ rcnt <= 8'h00;
+ else
+ if (rcnt != 8'hFF) rcnt <= rcnt + 8'h01;
+end
+
+memini ram
+(
+ .address(a[13:0]),
+ .clock(clk),
+ .data(dcpu),
+ .wren(~wr_n & rst_n & ~a[15] & ~a[14]),
+ .q(dram)
+);
+
+always @(posedge clk)
+begin
+ if (~wr_n)
+ begin
+ if (a == 16'hFFFB) led <= dcpu;
+ if (a == 16'hFFFC) hex0 <= dcpu[6:0];
+ if (a == 16'hFFFD) hex1 <= dcpu[6:0];
+ if (a == 16'hFFFE) hex2 <= dcpu[6:0];
+ if (a == 16'hFFFF) hex3 <= dcpu[6:0];
+ end
+end
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam uart.REFCLK = `SYS_CLOCK;
+`endif
+
+uart_wb uart
+(
+ .wb_clk_i(clk),
+ .wb_rst_i(~rst_n),
+ .wb_adr_i(a[0]),
+ .wb_dat_i(dcpu),
+ .wb_dat_o(dsio),
+ .wb_cyc_i((~wr_n | dbin) & (a[15:8] == 8'hFE)),
+ .wb_we_i(~wr_n & (a[15:8] == 8'hFE)),
+ .wb_stb_i((~wr_n | (dbin & ~uack)) & (a[15:8] == 8'hFE)),
+ .wb_ack_o(uack),
+
+ .tx_dat_o(de1_uart_txd),
+ .tx_cts_i(1'b0),
+ .rx_dat_i(de1_uart_rxd),
+// .rx_dtr_o(de1_uart_cts),
+
+// .tx_ready(),
+// .tx_empty(),
+// .rx_ready(),
+
+ .cfg_bdiv(baud[15:0]),
+ .cfg_nbit(2'b11),
+ .cfg_nstp(1'b1),
+ .cfg_pena(1'b0),
+ .cfg_podd(1'b0)
+);
+
+vm80a_core cpu
+(
+ .pin_clk(clk),
+ .pin_f1(f1),
+ .pin_f2(f2),
+ .pin_reset(~rst_n),
+ .pin_a(a),
+ .pin_dout(dcpu),
+ .pin_din(dsys),
+ .pin_hold(1'b0),
+ .pin_ready(1'b1),
+ .pin_int(intrq),
+ .pin_wr_n(wr_n),
+ .pin_dbin(dbin),
+ .pin_inte(inte),
+ .pin_sync(sync)
+);
+
+assign de1_hex0 = ~hex0;
+assign de1_hex1 = ~hex1;
+assign de1_hex2 = ~hex2;
+assign de1_hex3 = ~hex3;
+
+assign de1_ledr[7:0] = led;
+assign de1_ledr[9] = ~wr_n;
+assign de1_ledr[8] = sync;
+
+//______________________________________________________________________________
+//
+// Temporary and debug assignments
+//
+assign de1_dram_dq = 16'hzzzz;
+assign de1_dram_addr = 12'h000;
+assign de1_dram_ldqm = 1'b0;
+assign de1_dram_udqm = 1'b0;
+assign de1_dram_we_n = 1'b1;
+assign de1_dram_cas_n = 1'b1;
+assign de1_dram_ras_n = 1'b1;
+assign de1_dram_cs_n = 1'b1;
+assign de1_dram_ba[0] = 1'b0;
+assign de1_dram_ba[1] = 1'b0;
+assign de1_dram_clk = 1'b0;
+assign de1_dram_cke = 1'b0;
+
+assign de1_fl_dq = 7'hzz;
+assign de1_fl_addr = 22'hzzzzzz;
+assign de1_fl_we_n = 1'b1;
+assign de1_fl_rst_n = 1'b0;
+assign de1_fl_oe_n = 1'b1;
+assign de1_fl_ce_n = 1'b1;
+
+assign de1_sram_dq = 16'hzzzz;
+assign de1_sram_addr = 18'h00000;
+assign de1_sram_we_n = 1'b1;
+assign de1_sram_ce_n = 1'b1;
+assign de1_sram_oe_n = 1'b1;
+assign de1_sram_lb_n = 1'b1;
+assign de1_sram_ub_n = 1'b1;
+
+assign de1_sd_clk = 1'b0;
+assign de1_sd_mosi = 1'hz;
+assign de1_sd_miso = 1'hz;
+assign de1_sd_cmd = 1'hz;
+
+assign de1_ps2_dat = 1'hz;
+assign de1_ps2_clk = 1'hz;
+assign de1_i2c_dat = 1'hz;
+assign de1_i2c_clk = 1'hz;
+
+assign de1_vga_hs = 1'b0;
+assign de1_vga_vs = 1'b0;
+assign de1_vga_r = 4'h0;
+assign de1_vga_g = 4'h0;
+assign de1_vga_b = 4'h0;
+
+assign de1_gpio0 = 35'hzzzzzzzzz;
+assign de1_gpio1 = 35'hzzzzzzzzz;
+assign de1_ledg = 8'hzz;
+
+assign de1_aud_adclrck = 1'b0;
+assign de1_aud_daclrck = 1'b0;
+assign de1_aud_dacdat = 1'b0;
+assign de1_aud_xck = 1'b0;
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de1/de1_uart.v b/1801BM1_vm80a/org/rtl/de1/de1_uart.v
new file mode 100644
index 0000000000000000000000000000000000000000..3dc00014e21439a6ad9a4c1bf00e624cee436fc9
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de1/de1_uart.v
@@ -0,0 +1,378 @@
+//
+// Copyright (c) 2014-2015 by 1801BM1@gmail.com
+//
+// Universal Serial Asynchronous Receiver-Transmitter (simplified 8251)
+//______________________________________________________________________________
+//
+module uart_wb #(parameter REFCLK=50000000)
+(
+ input wb_clk_i, // system clock
+ input wb_rst_i, // peripheral reset
+ //
+ input [0:0] wb_adr_i, //
+ input [7:0] wb_dat_i, //
+ output reg [7:0] wb_dat_o, //
+ input wb_cyc_i, //
+ input wb_we_i, //
+ input wb_stb_i, //
+ output reg wb_ack_o, //
+ //
+ output tx_dat_o, // output serial data (txd)
+ input tx_cts_i, // enable transmitter (rts)
+ input rx_dat_i, // input serial data (rxd)
+ output rx_dtr_o, // receiver ready (cts)
+ //
+ output tx_ready_o, // tx ready request
+ output tx_empty_o, // tx empty request
+ output rx_ready_o, // rx ready request
+ //
+ input [15:0] cfg_bdiv, // baudrate divisor: (921600/baud)-1
+ input [1:0] cfg_nbit, // word length: 00-5, 01-6, 10-7, 11-8 bit
+ input cfg_nstp, // tx stop bits: 0 - 1 stop, 1 - 2 stop
+ input cfg_pena, // parity control enable
+ input cfg_podd // odd parity (complete to odd ones)
+);
+
+wire [63:0] add_arg;
+reg [16:0] add_reg;
+reg [15:0] baud_div;
+reg baud_x16;
+wire baud_ref;
+
+reg [1:0] tx_cts_reg;
+reg [1:0] rx_dat_reg;
+
+wire csr_wstb;
+wire rbr_rstb;
+wire thr_wstb;
+
+wire tx_par;
+reg [7:0] tx_thr;
+reg [9:0] tx_shr;
+reg [7:0] tx_bcnt;
+reg tx_busy;
+reg tx_ready, tx_empty, tx_break;
+
+wire rx_dat;
+reg [7:0] rx_rbr;
+reg [8:0] rx_shr;
+reg [7:0] rx_bcnt;
+reg rx_ready, rx_perr, rx_ovf, rx_break;
+wire rx_load, rx_stb;
+reg rx_frame, rx_start, rx_par;
+
+//______________________________________________________________________________
+//
+// Caution note: the arithmetic expressions should be calculated in 64-bit width
+//
+assign add_arg = (64'h0000000000100000 * 64'd921600)/REFCLK;
+assign baud_ref = add_reg[16];
+//
+// Phase accumulator to generate 921600 * 16 Hz reference clock strobe
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ add_reg <= 17'h00000;
+ else
+ begin
+ add_reg <= {1'b0, add_reg[15:0]} + add_arg[16:0];
+ end
+end
+//
+// Baud rate x16 generator
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ baud_div <= 16'h0000;
+ baud_x16 <= 1'b0;
+ end
+ else
+ begin
+ if (baud_ref)
+ if (baud_div == 16'h0000)
+ baud_div <= cfg_bdiv;
+ else
+ baud_div <= baud_div - 16'h0001;
+
+ baud_x16 <= baud_ref & (baud_div == 16'h0000);
+ end
+
+end
+
+//______________________________________________________________________________
+//
+assign csr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & wb_adr_i[0];
+assign thr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & ~wb_adr_i[0];
+assign rbr_rstb = wb_cyc_i & wb_stb_i & ~wb_we_i & ~wb_ack_o & ~wb_adr_i[0];
+//
+// Output data multiplexed register
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ wb_dat_o <= 8'h00;
+ else
+//
+// if (wb_cyc_i & wb_stb_i & ~wb_ack_o)
+//
+ begin
+ if (wb_adr_i[0])
+ wb_dat_o <= (tx_ready << 7)
+ | (tx_break << 6)
+ | (tx_empty << 5)
+ | (rx_ready << 3)
+ | (rx_break << 2)
+ | (rx_perr << 1)
+ | (rx_ovf << 0);
+ else
+ wb_dat_o <= rx_rbr;
+ end
+end
+
+always @(posedge wb_clk_i)
+ wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
+
+//
+// Control register bits
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ tx_break <= 1'b0;
+ else
+ if (csr_wstb) tx_break <= wb_dat_i[6];
+end
+
+//______________________________________________________________________________
+//
+// Interrupts
+//
+assign tx_ready_o = tx_ready;
+assign tx_empty_o = tx_empty;
+assign rx_ready_o = rx_ready;
+
+//______________________________________________________________________________
+//
+// Metastability issues
+//
+always @(posedge wb_clk_i)
+begin
+ tx_cts_reg[0] <= ~tx_cts_i;
+ tx_cts_reg[1] <= tx_cts_reg[0];
+
+ rx_dat_reg[0] <= rx_dat_i;
+ rx_dat_reg[1] <= rx_dat_reg[0];
+end
+
+//______________________________________________________________________________
+//
+// Transmitter unit
+//
+assign tx_par = tx_thr[0] ^ tx_thr[1] ^ tx_thr[2] ^ tx_thr[3] ^ tx_thr[4]
+ ^ (tx_thr[5] & (cfg_nbit >= 2'b01))
+ ^ (tx_thr[6] & (cfg_nbit >= 2'b10))
+ ^ (tx_thr[7] & (cfg_nbit == 2'b11))
+ ^ cfg_podd;
+assign tx_dat_o = tx_shr[0] & ~tx_break;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ tx_ready <= 1'b1;
+ tx_empty <= 1'b1;
+ tx_shr <= 10'o1777;
+ tx_busy <= 1'b0;
+ tx_bcnt <= 8'b00000000;
+ tx_thr <= 8'b00000000;
+ end
+ else
+ begin
+ tx_empty <= tx_ready & ~tx_busy;
+ //
+ // Transmitter hold register write
+ //
+ if (thr_wstb)
+ begin
+ tx_ready <= 1'b0;
+ tx_thr <= wb_dat_i[7:0];
+ end
+
+ if (baud_x16)
+ begin
+ //
+ // Transmit process
+ //
+ if (tx_busy)
+ begin
+ if (tx_bcnt == 8'b00000001)
+ tx_busy <= 1'b0;
+
+ if (tx_bcnt != 8'b00000000)
+ tx_bcnt <= tx_bcnt - 8'b00000001;
+
+ if (tx_bcnt[3:0] == 4'b0000)
+ tx_shr <= {1'b1, tx_shr[9:1]};
+ end
+
+ //
+ // Starting new word transmit
+ //
+ if (~tx_ready & ~tx_busy & tx_cts_reg[1])
+ begin
+ tx_busy <= 1'b1;
+ tx_ready <= ~thr_wstb;
+ tx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena} + {3'b000, cfg_nstp}, 4'b1111};
+
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {3'b111, tx_par, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {2'b11, tx_par, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {1'b1, tx_par, tx_thr[6:0], 1'b0};
+ default: tx_shr <= { tx_par, tx_thr[7:0], 1'b0};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {4'b1111, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {3'b111, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {2'b11, tx_thr[6:0], 1'b0};
+ default: tx_shr <= {1'b1, tx_thr[7:0], 1'b0};
+ endcase
+ end
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// Receiver unit
+//
+assign rx_dtr_o = rx_ready;
+assign rx_dat = rx_dat_reg[1];
+
+assign rx_load = rx_stb & (rx_bcnt[7:4] == 4'b0000);
+assign rx_stb = (rx_bcnt[3:0] == 4'b0001) & baud_x16;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ rx_ready <= 1'b0;
+ rx_break <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_start <= 1'b0;
+ rx_par <= 1'b0;
+ rx_rbr <= 8'b00000000;
+ rx_shr <= 9'b00000000;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ if (rx_load)
+ begin
+ rx_ready <= 1'b1;
+ case(cfg_nbit)
+ 2'b00: rx_rbr <= {3'b000, rx_shr[4:0]};
+ 2'b01: rx_rbr <= {2'b00, rx_shr[5:0]};
+ 2'b10: rx_rbr <= {1'b0, rx_shr[6:0]};
+ default: rx_rbr <= rx_shr[7:0];
+ endcase
+ rx_perr <= rx_par;
+ rx_ovf <= rx_ready;
+ rx_break <= ~rx_dat;
+ end
+ else
+ if (rbr_rstb)
+ begin
+ rx_ready <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ end
+
+ if (baud_x16)
+ begin
+ if (~rx_frame)
+ //
+ // Waiting for start bit
+ //
+ if (~rx_dat)
+ begin
+ rx_par <= cfg_pena & cfg_podd;
+ rx_start <= 1'b1;
+ rx_frame <= 1'b1;
+ rx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena}, 4'b0111};
+ end
+ else
+ begin
+ rx_start <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ //
+ // Receiving frame
+ //
+ if (rx_bcnt != 8'b00000000)
+ rx_bcnt <= rx_bcnt - 8'b00000001;
+ //
+ // Start bit monitoring
+ //
+ if (rx_start)
+ begin
+ if (rx_dat)
+ begin
+ //
+ // Spurrious start bit
+ //
+ rx_start <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ if (rx_bcnt[3:0] == 4'b0010)
+ rx_start <= 1'b0;
+ end
+ else
+ begin
+ //
+ // Receiving data
+ //
+ if (rx_stb)
+ begin
+ rx_par <= (rx_par ^ rx_dat) & cfg_pena;
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b01: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ 2'b10: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ default: rx_shr <= {rx_dat, rx_shr[8:1]};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {4'b0000, rx_dat, rx_shr[4:1]};
+ 2'b01: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b10: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ default: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ endcase
+ if (rx_load & rx_dat)
+ begin
+ //
+ // Stop bit detected
+ //
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ end
+ if ((rx_bcnt == 8'b00000000) & rx_dat)
+ rx_frame <= 1'b0;
+ end
+ end
+ end
+ end
+end
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de2-115/de2_mem.v b/1801BM1_vm80a/org/rtl/de2-115/de2_mem.v
new file mode 100644
index 0000000000000000000000000000000000000000..9fc555072762b0780158c6e46c5834f48e380239
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de2-115/de2_mem.v
@@ -0,0 +1,104 @@
+// megafunction wizard: %RAM: 1-PORT%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altsyncram
+
+// ============================================================
+// File Name: de0_mem.v
+// Megafunction Name(s):
+// altsyncram
+//
+// Simulation Library Files(s):
+// altera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 12.1 Build 177 11/07/2012 SJ Full Version
+// ************************************************************
+
+
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module memini (
+ address,
+ clock,
+ data,
+ wren,
+ q);
+
+ input [13:0] address;
+ input clock;
+ input [7:0] data;
+ input wren;
+ output [7:0] q;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+ tri1 clock;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+ wire [7:0] sub_wire0;
+ wire [7:0] q = sub_wire0[7:0];
+
+ altsyncram altsyncram_component (
+ .address_a (address),
+ .clock0 (clock),
+ .data_a (data),
+ .wren_a (wren),
+ .q_a (sub_wire0),
+ .aclr0 (1'b0),
+ .aclr1 (1'b0),
+ .address_b (1'b1),
+ .addressstall_a (1'b0),
+ .addressstall_b (1'b0),
+ .byteena_a (1'b1),
+ .byteena_b (1'b1),
+ .clock1 (1'b1),
+ .clocken0 (1'b1),
+ .clocken1 (1'b1),
+ .clocken2 (1'b1),
+ .clocken3 (1'b1),
+ .data_b (1'b1),
+ .eccstatus (),
+ .q_b (),
+ .rden_a (1'b1),
+ .rden_b (1'b1),
+ .wren_b (1'b0));
+ defparam
+ altsyncram_component.clock_enable_input_a = "BYPASS",
+ altsyncram_component.clock_enable_output_a = "BYPASS",
+ altsyncram_component.init_file = "../../../tst/rom/memini.mif",
+ altsyncram_component.intended_device_family = "Cyclone IV",
+ altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
+ altsyncram_component.lpm_type = "altsyncram",
+ altsyncram_component.numwords_a = 16384,
+ altsyncram_component.operation_mode = "SINGLE_PORT",
+ altsyncram_component.outdata_aclr_a = "NONE",
+ altsyncram_component.outdata_reg_a = "UNREGISTERED",
+ altsyncram_component.power_up_uninitialized = "FALSE",
+ altsyncram_component.ram_block_type = "M9K",
+ altsyncram_component.read_during_write_mode_port_a = "DONT_CARE",
+ altsyncram_component.widthad_a = 14,
+ altsyncram_component.width_a = 8,
+ altsyncram_component.width_byteena_a = 1;
+
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de2-115/de2_top.v b/1801BM1_vm80a/org/rtl/de2-115/de2_top.v
new file mode 100644
index 0000000000000000000000000000000000000000..899248aa7cbe47f137136bba51cd4b61e5ddfd2f
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de2-115/de2_top.v
@@ -0,0 +1,450 @@
+//______________________________________________________________________________
+//
+// Top module for DE2-115 board based system
+//______________________________________________________________________________
+//
+// External oscillator clock, feeds the PLLs
+//
+`define OSC_CLOCK 50000000
+//
+// Global system clock
+//
+`define SYS_CLOCK 50000000
+//
+// Console baudrate
+//
+`define SYS_BAUD 115200
+//______________________________________________________________________________
+//
+// Reset button debounce interval (in ms))
+//
+`define RESET_BUTTON_DEBOUNCE_MS 5
+//
+// Internal reset pulse width (in system clocks)
+//
+`define RESET_PULSE_WIDTH_CLK 7
+
+//______________________________________________________________________________
+//
+// Top project module - instantiates the DE2-115 board itself
+//
+module de2
+(
+ input de2_clock_50, // clock input 50 MHz
+ input de2_clock_50_2, // clock input 50 MHz
+ input de2_clock_50_3, // clock input 50 MHz
+ input de2_clock_25, // Ethernet clock 25MHz
+ input de2_sma_clkin, // SMA socket clock input
+ output de2_sma_clkout, // SMA socket clock output
+ //
+ input [3:0] de2_button, // push buttons
+ input [17:0] de2_sw, // DPDT toggle switches
+ //
+ output [6:0] de2_hex0, // seven segment digit 0
+ output [6:0] de2_hex1, // seven segment digit 1
+ output [6:0] de2_hex2, // seven segment digit 2
+ output [6:0] de2_hex3, // seven segment digit 3
+ output [6:0] de2_hex4, // seven segment digit 4
+ output [6:0] de2_hex5, // seven segment digit 5
+ output [6:0] de2_hex6, // seven segment digit 6
+ output [6:0] de2_hex7, // seven segment digit 7
+ output [8:0] de2_ledg, // LEDs green
+ output [17:0] de2_ledr, // LEDs red
+ //
+ output de2_uart_txd, // UART transmitter
+ input de2_uart_rxd, // UART receiver
+ output de2_uart_cts, // UART clear to send
+ input de2_uart_rts, // UART request to send
+ //
+ inout [31:0] de2_dram_dq, // SDRAM data bus 32 bits
+ output [12:0] de2_dram_addr, // SDRAM address bus 13 bits
+ output [3:0] de2_dram_dqm, // SDRAM byte data lane mask
+ output de2_dram_we_n, // SDRAM write enable
+ output de2_dram_cas_n, // SDRAM column address strobe
+ output de2_dram_ras_n, // SDRAM row address strobe
+ output de2_dram_cs_n, // SDRAM chip select
+ output [1:0] de2_dram_ba, // SDRAM bank address
+ output de2_dram_clk, // SDRAM clock
+ output de2_dram_cke, // SDRAM clock enable
+ //
+ inout [15:0] de2_sram_dq, // SRAM Data bus 16 Bits
+ output [19:0] de2_sram_addr, // SRAM Address bus 20 Bits
+ output de2_sram_ub_n, // SRAM High-byte Data Mask
+ output de2_sram_lb_n, // SRAM Low-byte Data Mask
+ output de2_sram_we_n, // SRAM Write Enable
+ output de2_sram_ce_n, // SRAM Chip Enable
+ output de2_sram_oe_n, // SRAM Output Enable
+ //
+ inout [7:0] de2_fl_dq, // FLASH data bus 8 Bits
+ output [22:0] de2_fl_addr, // FLASH address bus 23 Bits
+ output de2_fl_we_n, // FLASH write enable
+ output de2_fl_rst_n, // FLASH reset
+ output de2_fl_oe_n, // FLASH output enable
+ output de2_fl_ce_n, // FLASH chip enable
+ output de2_fl_wp_n, // FLASH hardware write protect
+ input de2_fl_rb, // FLASH ready/busy
+ //
+ output de2_lcd_blig, // LCD back light ON/OFF
+ output de2_lcd_on, // LCD power ON
+ output de2_lcd_rw, // LCD read/write select, 0 = write, 1 = read
+ output de2_lcd_en, // LCD enable
+ output de2_lcd_rs, // LCD command/data select, 0 = command, 1 = data
+ inout [7:0] de2_lcd_data, // LCD data bus 8 bits
+ //
+ inout [3:0] de2_sd_dat, // SD Card Data
+ inout de2_sd_cmd, // SD Card Command Signal
+ output de2_sd_clk, // SD Card Clock
+ input de2_sd_wp_n, // SD Card Write Protect
+ //
+ inout de2_ps2_kbdat, // PS2 Keyboard Data
+ inout de2_ps2_kbclk, // PS2 Keyboard Clock
+ inout de2_ps2_msdat, // PS2 Mouse Data
+ inout de2_ps2_msclk, // PS2 Mouse Clock
+ //
+ output de2_vga_hs, // VGA H_SYNC
+ output de2_vga_vs, // VGA V_SYNC
+ output [7:0] de2_vga_r, // VGA Red[3:0]
+ output [7:0] de2_vga_g, // VGA Green[3:0]
+ output [7:0] de2_vga_b, // VGA Blue[3:0]
+ output de2_vga_blank_n, // VGA blank
+ output de2_vga_clk, // VGA clock
+ output de2_vga_sync_n, // VGA synchro
+ //
+ output de2_enet0_gtx_clk, // Ethernet 0 RGMII
+ input de2_enet0_int_n, //
+ output de2_enet0_mdc, //
+ inout de2_enet0_mdio, //
+ output de2_enet0_rst_n, //
+ input de2_enet0_rx_clk, //
+ input de2_enet0_rx_col, //
+ input de2_enet0_rx_crs, //
+ input [3:0] de2_enet0_rx_dat, //
+ input de2_enet0_rx_dv, //
+ input de2_enet0_rx_er, //
+ input de2_enet0_tx_clk, //
+ output [3:0] de2_enet0_tx_dat, //
+ output de2_enet0_tx_en, //
+ output de2_enet0_tx_er, //
+ input de2_enet0_link100, //
+ //
+ output de2_enet1_gtx_clk, // Ethernet 1 RGMII
+ input de2_enet1_int_n, //
+ output de2_enet1_mdc, //
+ inout de2_enet1_mdio, //
+ output de2_enet1_rst_n, //
+ input de2_enet1_rx_clk, //
+ input de2_enet1_rx_col, //
+ input de2_enet1_rx_crs, //
+ input [3:0] de2_enet1_rx_dat, //
+ input de2_enet1_rx_dv, //
+ input de2_enet1_rx_er, //
+ input de2_enet1_tx_clk, //
+ output [3:0] de2_enet1_tx_dat, //
+ output de2_enet1_tx_en, //
+ output de2_enet1_tx_er, //
+ input de2_enet1_link100, //
+ //
+ inout [15:0] de2_otg_dat, // USB OTG controller
+ output [1:0] de2_otg_addr, //
+ output de2_otg_cs_n, //
+ output de2_otg_wr_n, //
+ output de2_otg_rd_n, //
+ input [1:0] de2_otg_int, //
+ output de2_otg_rst_n, //
+ input [1:0] de2_otg_dreq, //
+ output [1:0] de2_otg_dack_n, //
+ inout de2_otg_fspeed, //
+ inout de2_otg_lspeed, //
+ //
+ inout [35:0] de2_gpio, // GPIO Connection Data
+ inout [6:0] de2_exio, // Extend IO pins
+ input de2_irda, //
+ //
+ output de2_aud_adclrck, // Audio CODEC ADC LR Clock
+ input de2_aud_adcdat, // Audio CODEC ADC Data
+ output de2_aud_daclrck, // Audio CODEC DAC LR Clock
+ output de2_aud_dacdat, // Audio CODEC DAC Data
+ inout de2_aud_bclk, // Audio CODEC Bit-Stream Clock
+ output de2_aud_xck, // Audio CODEC Chip Clock
+ //
+ inout de2_i2c_dat, // I2C Data, Audio and TV
+ inout de2_i2c_clk, // I2C Clock, Audio and TV
+ inout de2_eeprom_dat, // I2C Data, EEPROM
+ inout de2_eeprom_clk, // I2C Clock, EEPROM
+ //
+ input de2_td_clk27, // TV Decoder
+ input [7:0] de2_td_dat, //
+ input de2_td_hs, //
+ input de2_td_vs, //
+ output de2_td_rst_n, //
+ //
+ input de2_hsmc_clkin_p1, // HSMC (LVDS)
+ input de2_hsmc_clkin_p2, //
+ input de2_hsmc_clkin0, //
+ output de2_hsmc_clkout_p1, //
+ output de2_hsmc_clkout_p2, //
+ output de2_hsmc_clkout0, //
+ inout [3:0] de2_hsmc_d, //
+ input [16:0] de2_hsmc_rxd_p, //
+ output [16:0] de2_hsmc_txd_p //
+);
+
+//______________________________________________________________________________
+//
+wire [31:0] baud = 921600/`SYS_BAUD-1;
+wire clk, wr_n, rst_n, dbin;
+wire [7:0] dcpu;
+wire [7:0] dsys;
+wire [7:0] dsio;
+wire [7:0] dram;
+wire [15:0] a;
+wire uack;
+
+reg f1, f2;
+reg [6:0] hex0, hex1, hex2, hex3;
+reg [6:0] hex4, hex5, hex6, hex7;
+reg [7:0] led;
+reg [7:0] rcnt = 8'h00;
+reg [2:0] div;
+reg [15:0] div1ms;
+reg ms, intrq, inta;
+wire inte, sync;
+
+assign clk = de2_clock_50;
+assign rst_n = (rcnt == 8'hFF);
+assign dsys = inta ? 8'hE7
+ : (a[15:8] == 8'hFF) ? {4'h00, de2_button[3:0]}
+ : (a[15:8] == 8'hFE) ? dsio
+ : dram;
+
+always @(posedge clk)
+begin
+ div <= div + 3'b001;
+ f1 <= div[0];
+ f2 <= ~div[0];
+
+ if (sync) inta = dcpu[0];
+ if (div1ms == ((`SYS_CLOCK/1000)-1))
+ begin
+ div1ms <= 16'h0000;
+ ms <= 1;
+ end
+ else
+ begin
+ div1ms <= div1ms + 16'h0001;
+ ms <= 0;
+ end
+
+ if (ms) intrq <= 1;
+ if (inta) intrq <= 0;
+end
+
+always @(posedge clk)
+begin
+ if (~de2_button[3])
+ rcnt <= 8'h00;
+ else
+ if (rcnt != 8'hFF) rcnt <= rcnt + 8'h01;
+end
+
+memini ram
+(
+ .address(a[13:0]),
+ .clock(clk),
+ .data(dcpu),
+ .wren(~wr_n & rst_n & ~a[15] & ~a[14]),
+ .q(dram)
+);
+
+always @(posedge clk)
+begin
+ if (~wr_n)
+ begin
+ if (a == 16'hFFFB) led <= dcpu;
+ if (a == 16'hFFFC) hex0 <= dcpu[6:0];
+ if (a == 16'hFFFD) hex1 <= dcpu[6:0];
+ if (a == 16'hFFFE) hex2 <= dcpu[6:0];
+ if (a == 16'hFFFF) hex3 <= dcpu[6:0];
+ if (a == 16'hFFF0) hex4 <= dcpu[6:0];
+ if (a == 16'hFFF1) hex5 <= dcpu[6:0];
+ if (a == 16'hFFF2) hex6 <= dcpu[6:0];
+ if (a == 16'hFFF3) hex7 <= dcpu[6:0];
+ end
+end
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam uart.REFCLK = `SYS_CLOCK;
+`endif
+
+uart_wb uart
+(
+ .wb_clk_i(clk),
+ .wb_rst_i(~rst_n),
+ .wb_adr_i(a[0]),
+ .wb_dat_i(dcpu),
+ .wb_dat_o(dsio),
+ .wb_cyc_i((~wr_n | dbin) & (a[15:8] == 8'hFE)),
+ .wb_we_i(~wr_n & (a[15:8] == 8'hFE)),
+ .wb_stb_i((~wr_n | (dbin & ~uack)) & (a[15:8] == 8'hFE)),
+ .wb_ack_o(uack),
+
+ .tx_dat_o(de2_uart_txd),
+ .tx_cts_i(1'b0),
+ .rx_dat_i(de2_uart_rxd),
+ .rx_dtr_o(de2_uart_cts),
+
+// .tx_ready(),
+// .tx_empty(),
+// .rx_ready(),
+
+ .cfg_bdiv(baud[15:0]),
+ .cfg_nbit(2'b11),
+ .cfg_nstp(1'b1),
+ .cfg_pena(1'b0),
+ .cfg_podd(1'b0)
+);
+
+vm80a_core cpu
+(
+ .pin_clk(clk),
+ .pin_f1(f1),
+ .pin_f2(f2),
+ .pin_reset(~rst_n),
+ .pin_a(a),
+ .pin_dout(dcpu),
+ .pin_din(dsys),
+ .pin_hold(1'b0),
+ .pin_ready(1'b1),
+ .pin_int(intrq),
+ .pin_wr_n(wr_n),
+ .pin_dbin(dbin),
+ .pin_inte(inte),
+ .pin_sync(sync)
+);
+
+assign de2_hex0 = ~hex0;
+assign de2_hex1 = ~hex1;
+assign de2_hex2 = ~hex2;
+assign de2_hex3 = ~hex3;
+assign de2_hex4 = ~hex4;
+assign de2_hex5 = ~hex5;
+assign de2_hex6 = ~hex6;
+assign de2_hex7 = ~hex7;
+
+assign de2_ledg[7:0] = led;
+assign de2_ledg[8] = sync;
+
+//______________________________________________________________________________
+//
+// Temporary and debug assignments
+//
+// assign de2_uart_txd = 1'bz;
+// assign de2_uart_cts = 1'bz;
+
+assign de2_dram_dq = 32'hzzzzzzzz;
+assign de2_dram_addr = 13'h0000;
+assign de2_dram_dqm = 4'b0;
+assign de2_dram_we_n = 1'b1;
+assign de2_dram_cas_n = 1'b1;
+assign de2_dram_ras_n = 1'b1;
+assign de2_dram_cs_n = 1'b1;
+assign de2_dram_ba[0] = 1'b0;
+assign de2_dram_ba[1] = 1'b0;
+assign de2_dram_clk = 1'b0;
+assign de2_dram_cke = 1'b0;
+
+assign de2_sram_dq = 16'hzzzz;
+assign de2_sram_addr = 20'h00000;
+assign de2_sram_ub_n = 1'b1;
+assign de2_sram_lb_n = 1'b1;
+assign de2_sram_we_n = 1'b1;
+assign de2_sram_ce_n = 1'b1;
+assign de2_sram_oe_n = 1'b1;
+
+assign de2_fl_dq = 8'hzz;
+assign de2_fl_addr = 23'h000000;
+assign de2_fl_we_n = 1'b1;
+assign de2_fl_rst_n = 1'b0;
+assign de2_fl_oe_n = 1'b1;
+assign de2_fl_ce_n = 1'b1;
+assign de2_fl_wp_n = 1'b0;
+
+assign de2_lcd_data = 8'hzz;
+assign de2_lcd_blig = 1'b0;
+assign de2_lcd_on = 1'b0;
+assign de2_lcd_rw = 1'b0;
+assign de2_lcd_en = 1'b0;
+assign de2_lcd_rs = 1'b0;
+
+assign de2_sd_dat = 4'hz;
+assign de2_sd_cmd = 1'hz;
+assign de2_sd_clk = 1'h0;
+
+assign de2_ps2_kbdat = 1'hz;
+assign de2_ps2_kbclk = 1'hz;
+assign de2_ps2_msdat = 1'hz;
+assign de2_ps2_msclk = 1'hz;
+
+assign de2_vga_blank_n = 1'b0;
+assign de2_vga_hs = 1'b00;
+assign de2_vga_vs = 1'b00;
+assign de2_vga_r = 8'h00;
+assign de2_vga_g = 8'h00;
+assign de2_vga_b = 8'h00;
+assign de2_vga_clk = 1'b00;
+assign de2_vga_sync_n = 1'b00;
+assign de2_td_rst_n = 1'b0;
+
+assign de2_gpio = 36'hzzzzzzzzz;
+assign de2_exio = 7'hzz;
+assign de2_ledr = 18'hzzzzz;
+
+assign de2_enet0_gtx_clk = 1'b0;
+assign de2_enet0_mdc = 1'b0;
+assign de2_enet0_mdio = 1'bz;
+assign de2_enet0_rst_n = 1'b0;
+assign de2_enet0_tx_dat = 4'h0;
+assign de2_enet0_tx_en = 1'b0;
+assign de2_enet0_tx_er = 1'b0;
+
+assign de2_enet1_gtx_clk = 1'b0;
+assign de2_enet1_mdc = 1'b0;
+assign de2_enet1_mdio = 1'bz;
+assign de2_enet1_rst_n = 1'b0;
+assign de2_enet1_tx_dat = 4'h0;
+assign de2_enet1_tx_en = 1'b0;
+assign de2_enet1_tx_er = 1'b0;
+
+assign de2_i2c_dat = 1'bz;
+assign de2_i2c_clk = 1'bz;
+assign de2_eeprom_dat = 1'bz;
+assign de2_eeprom_clk = 1'bz;
+
+assign de2_otg_dat = 16'hzzzz;
+assign de2_otg_addr = 2'b00;
+assign de2_otg_cs_n = 1'b1;
+assign de2_otg_wr_n = 1'b1;
+assign de2_otg_rd_n = 1'b1;
+assign de2_otg_rst_n = 1'b1;
+assign de2_otg_dack_n = 2'b11;
+assign de2_otg_fspeed = 1'bz;
+assign de2_otg_lspeed = 1'bz;
+
+assign de2_aud_adclrck = 1'bz;
+assign de2_aud_daclrck = 1'bz;
+assign de2_aud_dacdat = 1'bz;
+assign de2_aud_bclk = 1'b0;
+assign de2_aud_xck = 1'b0;
+
+assign de2_hsmc_clkout_p1 = 1'b0;
+assign de2_hsmc_clkout_p2 = 1'b0;
+assign de2_hsmc_clkout0 = 1'b0;
+assign de2_hsmc_d = 4'hz;
+assign de2_hsmc_txd_p = 16'h0000;
+assign de2_sma_clkout = 1'b0;
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/de2-115/de2_uart.v b/1801BM1_vm80a/org/rtl/de2-115/de2_uart.v
new file mode 100644
index 0000000000000000000000000000000000000000..3dc00014e21439a6ad9a4c1bf00e624cee436fc9
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/de2-115/de2_uart.v
@@ -0,0 +1,378 @@
+//
+// Copyright (c) 2014-2015 by 1801BM1@gmail.com
+//
+// Universal Serial Asynchronous Receiver-Transmitter (simplified 8251)
+//______________________________________________________________________________
+//
+module uart_wb #(parameter REFCLK=50000000)
+(
+ input wb_clk_i, // system clock
+ input wb_rst_i, // peripheral reset
+ //
+ input [0:0] wb_adr_i, //
+ input [7:0] wb_dat_i, //
+ output reg [7:0] wb_dat_o, //
+ input wb_cyc_i, //
+ input wb_we_i, //
+ input wb_stb_i, //
+ output reg wb_ack_o, //
+ //
+ output tx_dat_o, // output serial data (txd)
+ input tx_cts_i, // enable transmitter (rts)
+ input rx_dat_i, // input serial data (rxd)
+ output rx_dtr_o, // receiver ready (cts)
+ //
+ output tx_ready_o, // tx ready request
+ output tx_empty_o, // tx empty request
+ output rx_ready_o, // rx ready request
+ //
+ input [15:0] cfg_bdiv, // baudrate divisor: (921600/baud)-1
+ input [1:0] cfg_nbit, // word length: 00-5, 01-6, 10-7, 11-8 bit
+ input cfg_nstp, // tx stop bits: 0 - 1 stop, 1 - 2 stop
+ input cfg_pena, // parity control enable
+ input cfg_podd // odd parity (complete to odd ones)
+);
+
+wire [63:0] add_arg;
+reg [16:0] add_reg;
+reg [15:0] baud_div;
+reg baud_x16;
+wire baud_ref;
+
+reg [1:0] tx_cts_reg;
+reg [1:0] rx_dat_reg;
+
+wire csr_wstb;
+wire rbr_rstb;
+wire thr_wstb;
+
+wire tx_par;
+reg [7:0] tx_thr;
+reg [9:0] tx_shr;
+reg [7:0] tx_bcnt;
+reg tx_busy;
+reg tx_ready, tx_empty, tx_break;
+
+wire rx_dat;
+reg [7:0] rx_rbr;
+reg [8:0] rx_shr;
+reg [7:0] rx_bcnt;
+reg rx_ready, rx_perr, rx_ovf, rx_break;
+wire rx_load, rx_stb;
+reg rx_frame, rx_start, rx_par;
+
+//______________________________________________________________________________
+//
+// Caution note: the arithmetic expressions should be calculated in 64-bit width
+//
+assign add_arg = (64'h0000000000100000 * 64'd921600)/REFCLK;
+assign baud_ref = add_reg[16];
+//
+// Phase accumulator to generate 921600 * 16 Hz reference clock strobe
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ add_reg <= 17'h00000;
+ else
+ begin
+ add_reg <= {1'b0, add_reg[15:0]} + add_arg[16:0];
+ end
+end
+//
+// Baud rate x16 generator
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ baud_div <= 16'h0000;
+ baud_x16 <= 1'b0;
+ end
+ else
+ begin
+ if (baud_ref)
+ if (baud_div == 16'h0000)
+ baud_div <= cfg_bdiv;
+ else
+ baud_div <= baud_div - 16'h0001;
+
+ baud_x16 <= baud_ref & (baud_div == 16'h0000);
+ end
+
+end
+
+//______________________________________________________________________________
+//
+assign csr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & wb_adr_i[0];
+assign thr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & ~wb_adr_i[0];
+assign rbr_rstb = wb_cyc_i & wb_stb_i & ~wb_we_i & ~wb_ack_o & ~wb_adr_i[0];
+//
+// Output data multiplexed register
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ wb_dat_o <= 8'h00;
+ else
+//
+// if (wb_cyc_i & wb_stb_i & ~wb_ack_o)
+//
+ begin
+ if (wb_adr_i[0])
+ wb_dat_o <= (tx_ready << 7)
+ | (tx_break << 6)
+ | (tx_empty << 5)
+ | (rx_ready << 3)
+ | (rx_break << 2)
+ | (rx_perr << 1)
+ | (rx_ovf << 0);
+ else
+ wb_dat_o <= rx_rbr;
+ end
+end
+
+always @(posedge wb_clk_i)
+ wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
+
+//
+// Control register bits
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ tx_break <= 1'b0;
+ else
+ if (csr_wstb) tx_break <= wb_dat_i[6];
+end
+
+//______________________________________________________________________________
+//
+// Interrupts
+//
+assign tx_ready_o = tx_ready;
+assign tx_empty_o = tx_empty;
+assign rx_ready_o = rx_ready;
+
+//______________________________________________________________________________
+//
+// Metastability issues
+//
+always @(posedge wb_clk_i)
+begin
+ tx_cts_reg[0] <= ~tx_cts_i;
+ tx_cts_reg[1] <= tx_cts_reg[0];
+
+ rx_dat_reg[0] <= rx_dat_i;
+ rx_dat_reg[1] <= rx_dat_reg[0];
+end
+
+//______________________________________________________________________________
+//
+// Transmitter unit
+//
+assign tx_par = tx_thr[0] ^ tx_thr[1] ^ tx_thr[2] ^ tx_thr[3] ^ tx_thr[4]
+ ^ (tx_thr[5] & (cfg_nbit >= 2'b01))
+ ^ (tx_thr[6] & (cfg_nbit >= 2'b10))
+ ^ (tx_thr[7] & (cfg_nbit == 2'b11))
+ ^ cfg_podd;
+assign tx_dat_o = tx_shr[0] & ~tx_break;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ tx_ready <= 1'b1;
+ tx_empty <= 1'b1;
+ tx_shr <= 10'o1777;
+ tx_busy <= 1'b0;
+ tx_bcnt <= 8'b00000000;
+ tx_thr <= 8'b00000000;
+ end
+ else
+ begin
+ tx_empty <= tx_ready & ~tx_busy;
+ //
+ // Transmitter hold register write
+ //
+ if (thr_wstb)
+ begin
+ tx_ready <= 1'b0;
+ tx_thr <= wb_dat_i[7:0];
+ end
+
+ if (baud_x16)
+ begin
+ //
+ // Transmit process
+ //
+ if (tx_busy)
+ begin
+ if (tx_bcnt == 8'b00000001)
+ tx_busy <= 1'b0;
+
+ if (tx_bcnt != 8'b00000000)
+ tx_bcnt <= tx_bcnt - 8'b00000001;
+
+ if (tx_bcnt[3:0] == 4'b0000)
+ tx_shr <= {1'b1, tx_shr[9:1]};
+ end
+
+ //
+ // Starting new word transmit
+ //
+ if (~tx_ready & ~tx_busy & tx_cts_reg[1])
+ begin
+ tx_busy <= 1'b1;
+ tx_ready <= ~thr_wstb;
+ tx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena} + {3'b000, cfg_nstp}, 4'b1111};
+
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {3'b111, tx_par, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {2'b11, tx_par, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {1'b1, tx_par, tx_thr[6:0], 1'b0};
+ default: tx_shr <= { tx_par, tx_thr[7:0], 1'b0};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {4'b1111, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {3'b111, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {2'b11, tx_thr[6:0], 1'b0};
+ default: tx_shr <= {1'b1, tx_thr[7:0], 1'b0};
+ endcase
+ end
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// Receiver unit
+//
+assign rx_dtr_o = rx_ready;
+assign rx_dat = rx_dat_reg[1];
+
+assign rx_load = rx_stb & (rx_bcnt[7:4] == 4'b0000);
+assign rx_stb = (rx_bcnt[3:0] == 4'b0001) & baud_x16;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ rx_ready <= 1'b0;
+ rx_break <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_start <= 1'b0;
+ rx_par <= 1'b0;
+ rx_rbr <= 8'b00000000;
+ rx_shr <= 9'b00000000;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ if (rx_load)
+ begin
+ rx_ready <= 1'b1;
+ case(cfg_nbit)
+ 2'b00: rx_rbr <= {3'b000, rx_shr[4:0]};
+ 2'b01: rx_rbr <= {2'b00, rx_shr[5:0]};
+ 2'b10: rx_rbr <= {1'b0, rx_shr[6:0]};
+ default: rx_rbr <= rx_shr[7:0];
+ endcase
+ rx_perr <= rx_par;
+ rx_ovf <= rx_ready;
+ rx_break <= ~rx_dat;
+ end
+ else
+ if (rbr_rstb)
+ begin
+ rx_ready <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ end
+
+ if (baud_x16)
+ begin
+ if (~rx_frame)
+ //
+ // Waiting for start bit
+ //
+ if (~rx_dat)
+ begin
+ rx_par <= cfg_pena & cfg_podd;
+ rx_start <= 1'b1;
+ rx_frame <= 1'b1;
+ rx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena}, 4'b0111};
+ end
+ else
+ begin
+ rx_start <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ //
+ // Receiving frame
+ //
+ if (rx_bcnt != 8'b00000000)
+ rx_bcnt <= rx_bcnt - 8'b00000001;
+ //
+ // Start bit monitoring
+ //
+ if (rx_start)
+ begin
+ if (rx_dat)
+ begin
+ //
+ // Spurrious start bit
+ //
+ rx_start <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ if (rx_bcnt[3:0] == 4'b0010)
+ rx_start <= 1'b0;
+ end
+ else
+ begin
+ //
+ // Receiving data
+ //
+ if (rx_stb)
+ begin
+ rx_par <= (rx_par ^ rx_dat) & cfg_pena;
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b01: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ 2'b10: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ default: rx_shr <= {rx_dat, rx_shr[8:1]};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {4'b0000, rx_dat, rx_shr[4:1]};
+ 2'b01: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b10: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ default: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ endcase
+ if (rx_load & rx_dat)
+ begin
+ //
+ // Stop bit detected
+ //
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ end
+ if ((rx_bcnt == 8'b00000000) & rx_dat)
+ rx_frame <= 1'b0;
+ end
+ end
+ end
+ end
+end
+endmodule
diff --git a/1801BM1_vm80a/org/rtl/vm80a.v b/1801BM1_vm80a/org/rtl/vm80a.v
new file mode 100644
index 0000000000000000000000000000000000000000..d6783b99b65d36b6eafc8ef80349aa7d5a6bd938
--- /dev/null
+++ b/1801BM1_vm80a/org/rtl/vm80a.v
@@ -0,0 +1,955 @@
+//
+// Copyright (c) 2014-2018 by 1801BM1@gmail.com
+// Licensed under CC-BY 3.0 (https://creativecommons.org/licenses/by/3.0/)
+//
+//______________________________________________________________________________
+//
+// vm80a wrapper for direct replacement of microprocessor package
+// extra high-speed clock should be provided to operate, F1 and F2
+// phases serve as clock enable gates
+//
+module vm80a
+(
+ input pin_clk, // global module clock (no in original 8080)
+ input pin_f1, // clock phase 1 (used as clock enable)
+ input pin_f2, // clock phase 2 (used as clock enable)
+ input pin_reset, // module reset
+ output[15:0] pin_a, // address bus outputs
+ inout [7:0] pin_d, // data bus inouts
+ input pin_hold, //
+ output pin_hlda, //
+ input pin_ready, //
+ output pin_wait, //
+ input pin_int, //
+ output pin_inte, //
+ output pin_sync, //
+ output pin_dbin, //
+ output pin_wr_n
+);
+
+wire pin_aena, pin_dena;
+wire [7:0] pin_din, pin_dout;
+wire [15:0] pin_addr;
+reg f1_core, f2_core;
+
+assign pin_a = pin_aena ? pin_addr : 16'hZZZZ;
+assign pin_d = pin_dena ? pin_dout : 8'hZZ;
+assign pin_din = pin_d;
+
+always @(posedge pin_clk)
+begin
+ f1_core <= pin_f1;
+ f2_core <= pin_f2;
+end
+
+vm80a_core core
+(
+ .pin_clk (pin_clk),
+ .pin_f1 (f1_core),
+ .pin_f2 (f2_core),
+ .pin_reset (pin_reset),
+ .pin_a (pin_addr),
+ .pin_dout (pin_dout),
+ .pin_din (pin_din),
+ .pin_aena (pin_aena),
+ .pin_dena (pin_dena),
+ .pin_hold (pin_hold),
+ .pin_hlda (pin_hlda),
+ .pin_ready (pin_ready),
+ .pin_wait (pin_wait),
+ .pin_int (pin_int),
+ .pin_inte (pin_inte),
+ .pin_sync (pin_sync),
+ .pin_dbin (pin_dbin),
+ .pin_wr_n (pin_wr_n)
+);
+endmodule
+
+module vm80a_core
+(
+ input pin_clk, // global module clock (no in original 8080)
+ input pin_f1, // clock phase 1 (used as clock enable)
+ input pin_f2, // clock phase 2 (used as clock enable)
+ input pin_reset, // module reset
+ output[15:0] pin_a, // address bus outputs
+ output[7:0] pin_dout, // data bus output
+ input [7:0] pin_din, // data bus input
+ output pin_aena, // address outputs enable
+ output pin_dena, // data outputs enable
+ input pin_hold, //
+ output pin_hlda, //
+ input pin_ready, //
+ output pin_wait, //
+ input pin_int, //
+ output pin_inte, //
+ output pin_sync, //
+ output pin_dbin, //
+ output pin_wr_n
+);
+
+//______________________________________________________________________________
+//
+wire [7:0] d;
+reg [7:0] db, di;
+reg [15:0] a;
+wire clk, f1, f2;
+reg abufena, db_ena, db_stb, dbin_pin, dbin_ext;
+reg reset;
+wire ready;
+
+reg t851, t404, t382, t383, t712, t735, t773;
+reg hold, hlda_pin;
+wire hlda, h889;
+
+reg wr_n, t1124, t1011, sync;
+wire ready_int;
+
+reg [15:0] r16_pc, r16_hl, r16_de, r16_bc, r16_sp, r16_wz, mxo;
+wire [15:0] mxi;
+wire mxr0, mxr1, mxr2, mxr3, mxr4, mxr5;
+wire mxwh, mxwl, mxrh, mxrl, mxw16, mxwadr;
+wire dec16, inc16, iad16;
+reg xchg_dh, xchg_tt, t3144;
+wire t1460, t1467, t1513, t1514, t1519;
+
+wire sy_inta, sy_wo_n, sy_hlta, sy_out, sy_m1, sy_inp, sy_memr;
+reg sy_stack;
+
+wire thalt, twt2;
+reg t1, t2, tw, t3, t4, t5;
+reg t1f1, t2f1, twf1, t3f1, t4f1, t5f1;
+reg m1, m2, m3, m4, m5;
+reg m1f1, m2f1, m3f1, m4f1, m5f1;
+
+wire start, ms0, ms1, m836, m839, m871;
+reg eom, t789, t887, t953, t976, t980;
+
+reg intr, inta, inte, mstart, minta;
+wire irq;
+
+reg [7:0] i;
+reg i25, i14, i03;
+wire imx, acc_sel;
+wire id_op, id_io, id_in, id_popsw, id_pupsw,
+ id_nop, id_lxi, id_inx, id_inr, id_dcr, id_idr, id_mvi, id_dad,
+ id_dcx, id_opa, id_idm, id_hlt, id_mov, id_opm, id_pop, id_rst,
+ id_cxx, id_jxx, id_rxx, id_ret, id_jmp, id_opi, id_out, id_11x,
+ id_rlc, id_rxc, id_rar, id_sha, id_daa, id_cma, id_stc, id_cmc,
+ id_add, id_adc, id_sub, id_sbb, id_ana, id_xra, id_ora, id_cmp,
+ id_lsax, id_mvim, id_shld, id_lhld, id_mvmr, id_mvrm, id_push,
+ id_xthl, id_sphl, id_pchl, id_xchg, id_call, id_eidi, id_stlda;
+
+wire id80, id81, id82, id83, id84, id85, id86, id00, id01,
+ id02, id03, id04, id05, id06, id07, id08, id09, id10;
+wire goto, jmpflag;
+reg jmptake, tree0, tree1, tree2;
+reg t2806, t2817, t2819, t3047, t2998, t3363, t3403, t3335, t3361;
+
+reg [7:0] xr, r, acc;
+wire [7:0] x, s, c;
+wire cl, ch, daa, daa_6x, daa_x6;
+wire a398;
+reg a327, a357, a358;
+wire alu_xout, alu_xwr, alu_xrd, alu_ald, alu_awr, alu_ard,
+ alu_rld, alu_r00, alu_rwr, alu_srd, alu_zrd, alu_frd;
+
+reg psw_z, psw_s, psw_p, psw_c, psw_ac, tmp_c;
+reg t2222, t1375, t1497, t1698, t1668, t1780, t1993, t1994;
+reg psw_ld, psw_wr, t2046, t2133, t2175;
+
+//_____________________________________________________________________________
+//
+assign clk = pin_clk;
+assign f1 = pin_f1;
+assign f2 = pin_f2;
+
+assign pin_a = a;
+assign pin_aena = abufena;
+assign pin_dout = db;
+assign pin_dena = db_ena;
+
+assign d[7] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[7]
+ | mxrl & mxo[7]
+ | mxrh & mxo[15]
+ | t1f1 & sy_memr
+ | alu_xrd & xr[7]
+ | alu_ard & acc[7]
+ | alu_frd & psw_s
+ | alu_srd & s[7] );
+
+assign d[6] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[6]
+ | mxrl & mxo[6]
+ | mxrh & mxo[14]
+ | t1f1 & sy_inp
+ | alu_xrd & xr[6]
+ | alu_ard & acc[6]
+ | alu_frd & psw_z
+ | alu_srd & s[6] );
+
+assign d[5] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[5]
+ | mxrl & mxo[5]
+ | mxrh & mxo[13]
+ | t1f1 & sy_m1
+ | alu_xrd & xr[5]
+ | alu_ard & acc[5]
+ | alu_frd & 1'b0
+ | alu_srd & s[5] );
+
+assign d[4] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[4]
+ | mxrl & mxo[4]
+ | mxrh & mxo[12]
+ | t1f1 & sy_out
+ | alu_xrd & xr[4]
+ | alu_ard & acc[4]
+ | alu_frd & psw_ac
+ | alu_srd & s[4] );
+
+assign d[3] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[3]
+ | mxrl & mxo[3]
+ | mxrh & mxo[11]
+ | t1f1 & sy_hlta
+ | alu_xrd & xr[3]
+ | alu_ard & acc[3]
+ | alu_frd & 1'b0
+ | alu_srd & s[3] );
+
+assign d[2] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[2]
+ | mxrl & mxo[2]
+ | mxrh & mxo[10]
+ | t1f1 & sy_stack
+ | alu_xrd & xr[2]
+ | alu_ard & acc[2]
+ | alu_frd & psw_p
+ | alu_srd & s[2] );
+
+assign d[1] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[1]
+ | mxrl & mxo[1]
+ | mxrh & mxo[9]
+ | t1f1 & sy_wo_n
+ | alu_xrd & xr[1]
+ | alu_ard & acc[1]
+ | alu_frd & 1'b1
+ | alu_srd & s[1] );
+
+assign d[0] = ~reset & ~alu_zrd &
+ ( dbin_ext & di[0]
+ | mxrl & mxo[0]
+ | mxrh & mxo[8]
+ | t1f1 & sy_inta
+ | alu_xrd & xr[0]
+ | alu_ard & acc[0]
+ | alu_frd & psw_c
+ | alu_srd & s[0] );
+
+always @(posedge clk)
+begin
+ if (f2 & db_stb) db <= d;
+ if (f2) abufena <= (~twt2 | ~thalt) & ~hlda_pin;
+ if (f1) db_stb <= t1 | (~sy_wo_n & t2);
+ if (f1) t851 <= t1 | (~sy_wo_n & (t2 | tw | t3));
+ if (f2) db_ena <= ~reset & t851;
+end
+
+//______________________________________________________________________________
+//
+// reset input buffer
+//
+always @(posedge clk)
+begin
+ if (f1) t404 <= pin_reset;
+ if (f2) reset <= t404;
+end
+
+//______________________________________________________________________________
+//
+// hold input buffer
+//
+assign pin_hlda = hlda_pin;
+assign hlda = hold & (t773 | (t3 & sy_wo_n) | (~m1 & sy_hlta) | t735);
+assign h889 = t2f1 | twf1;
+
+always @(posedge clk)
+begin
+ if (f1) t712 <= ~sy_wo_n & t3;
+ if (f2) t735 <= t712;
+ if (~f2) t382 <= pin_hold;
+ if (f2) t383 <= ((~t382 & hold) | t383); // extend the front detector pulse for entire F2 duration
+ if (~f2) t383 <= 1'b0;
+ if (f2) t773 <= hlda_pin;
+ if (f1) hlda_pin <= hlda;
+end
+
+always @(posedge clk)
+begin
+ if (reset)
+ hold <= 1'b0;
+ else
+ if (f2)
+ begin
+ if (t382)
+ begin
+ if (~sy_inta & h889) hold <= 1'b1;
+ end
+ else
+ hold <= 1'b0;
+ end
+end
+
+//______________________________________________________________________________
+//
+assign pin_dbin = dbin_pin;
+assign pin_wr_n = wr_n;
+assign pin_sync = sync;
+
+always @(posedge clk)
+begin
+ dbin_ext <= (f2 | dbin_pin) & ((t1124 & (m1f1 | ~sy_hlta)) | dbin_ext);
+
+ if (dbin_pin) di <= pin_din;
+ if (f2) dbin_pin <= t1124 & (m1f1 | ~sy_hlta);
+ if (f2) sync <= ~ready_int & t1011;
+ if (f1) t1011 <= t1 & ~reset;
+ if (f1) t1124 <= (t2 | tw) & sy_wo_n;
+ if (f1) wr_n <= ~(t3 | tw) | ready_int | sy_wo_n;
+end
+
+//______________________________________________________________________________
+//
+// ready pin and internal circuits
+//
+assign ready_int = (m4 | m5) & id_dad;
+assign ready = ready_int | pin_ready;
+assign pin_wait = twf1;
+
+//______________________________________________________________________________
+//
+// register unit - 6 16-bit registers
+//
+// r0 - pc
+// r1 - hl, de
+// r2 - de, hl
+// r3 - bc
+// r4 - sp
+// r5 - wz
+//
+assign t1467 = tree1 | (id04 & t4f1 & ~id_xthl);
+assign t1519 = tree2 | (id00 & t4f1 & ~id_xthl);
+assign mxi = inc16 ? (a + 16'h0001)
+ : dec16 ? (a - 16'h0001)
+ : a;
+
+assign inc16 = iad16 & ~dec16;
+assign dec16 = iad16 & id05 & (t4f1 | t5f1 | m4f1 | m5f1);
+assign iad16 = ~(id00 & (t4f1 | t5f1)) & (~minta | m5 | t3144);
+
+assign mxw16 = t3403;
+assign mxwadr = t3363 | (t4f1 & ~id_dad & ~id_hlt);
+assign t1513 = (t4f1 & id07) | t3335;
+assign t1514 = (t4f1 & id08) | t3361;
+
+assign mxrh = t2998 | (id08 & t4f1 & ~i03);
+assign mxrl = t3047 | (id08 & t4f1 & i03);
+assign mxwh = t2817 | (t2806 & ~i03);
+assign mxwl = t2819 | (t2806 & i03);
+
+assign mxr0 = tree0;
+assign mxr1 = xchg_dh & (((t1513 | t1514) & (~i14 & i25)) | t1519)
+ | ~xchg_dh & (t1513 | t1514) & (i14 & ~i25);
+assign mxr2 = xchg_dh & (t1513 | t1514) & (i14 & ~i25)
+ | ~xchg_dh & (((t1513 | t1514) & (~i14 & i25)) | t1519);
+assign mxr3 = (t1513 | t1514) & (~i14 & ~i25);
+assign mxr4 = t1467 | (t1513 & i14 & i25);
+assign mxr5 = ~(t1467 | t1513 | t1514 | t1519 | mxr0);
+
+always @ (posedge clk)
+begin
+ if (f1) t3144 <= t4 | t5 | (m4 & ~id02);
+ xchg_tt <= id_xchg & t2;
+ xchg_dh <= ~reset & ((xchg_tt & ~(id_xchg & t2)) ? ~xchg_dh : xchg_dh);
+end
+
+always @ (*)
+case ({mxr0, mxr1, mxr2, mxr3, mxr4, mxr5})
+ 6'b100000: mxo = r16_pc;
+ 6'b010000: mxo = r16_hl;
+ 6'b001000: mxo = r16_de;
+ 6'b000100: mxo = r16_bc;
+ 6'b000010: mxo = r16_sp;
+ 6'b000001: mxo = r16_wz;
+ default: mxo = 16'h0000;
+endcase
+
+always @ (posedge clk)
+if (f2)
+begin
+ if (mxwadr) a <= mxo;
+ if (mxw16)
+ begin
+ if (mxr0) r16_pc <= mxi;
+ if (mxr1) r16_hl <= mxi;
+ if (mxr2) r16_de <= mxi;
+ if (mxr3) r16_bc <= mxi;
+ if (mxr4) r16_sp <= mxi;
+ if (mxr5) r16_wz <= mxi;
+ end
+ else
+ begin
+ if (mxwl)
+ begin
+ if (mxr0) r16_pc[7:0] <= d;
+ if (mxr1) r16_hl[7:0] <= d;
+ if (mxr2) r16_de[7:0] <= d;
+ if (mxr3) r16_bc[7:0] <= d;
+ if (mxr4) r16_sp[7:0] <= d;
+ if (mxr5) r16_wz[7:0] <= d;
+ end
+ if (mxwh)
+ begin
+ if (mxr0) r16_pc[15:8] <= d;
+ if (mxr1) r16_hl[15:8] <= d;
+ if (mxr2) r16_de[15:8] <= d;
+ if (mxr3) r16_bc[15:8] <= d;
+ if (mxr4) r16_sp[15:8] <= d;
+ if (mxr5) r16_wz[15:8] <= d;
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// processor state
+//
+assign sy_hlta = id_hlt;
+assign sy_m1 = m1;
+assign sy_inp = m5 & id_in;
+assign sy_out = m5 & id_out;
+assign sy_inta = inta;
+assign sy_memr = sy_wo_n & ~sy_inp & ~minta;
+assign sy_wo_n = m1 | m2 | m3 | (((m4 & ~id86) | (m5 & ~id85)) & ~ready_int);
+
+always @(posedge clk)
+begin
+ if (f1)
+ begin
+ sy_stack <= (t1 & t1460)
+ | (t3 & m3 & id_cxx & ~jmptake)
+ | (t5 & m1 & id_rxx & ~jmptake);
+ end
+end
+//______________________________________________________________________________
+//
+// ticks state machine
+//
+assign twt2 = (t2f1 | twf1) & ~start;
+assign thalt = ~m1 & sy_hlta;
+
+always @(posedge clk)
+begin
+ if (f1)
+ begin
+ t1f1 <= t1 & ~reset; // ensure the reliable start after reset
+ t2f1 <= t2;
+ twf1 <= tw;
+ t3f1 <= t3;
+ t4f1 <= t4;
+ t5f1 <= t5;
+ end
+ if (f2)
+ begin
+ t1 <= start;
+ t2 <= ~start & t1f1;
+ tw <= ~start & (t2f1 | twf1) & (~ready | thalt);
+ t3 <= ~start & (t2f1 | twf1) & ready & ~thalt;
+ t4 <= ~start & t3f1 & ms0 & ~ms1;
+ t5 <= ~start & t4f1 & ms0 & ~ms1;
+ end
+end
+
+//______________________________________________________________________________
+//
+assign m836 = m1f1 & id82;
+assign m839 = ~t976 | ~sy_hlta;
+assign m871 = t789 | id81;
+
+assign start = ~m839
+ | t953
+ | (eom & ~(hold & t887))
+ | (f2 & ((~t382 & hold) | t383) & ~(twf1 | t3f1 | t4f1 | t5f1));
+
+assign ms0 = ~reset & m839 & ~(sy_stack & ~t1f1) & ~(eom & ~m836);
+assign ms1 = ~reset & m839 & ~(sy_stack & ~t1f1) & ~(m871 & ~m836) & eom;
+
+always @(posedge clk)
+begin
+ if (f1)
+ begin
+ t789 <= (id84 & m3) | (id83 & ~id_mvim & m4) | m5;
+ t887 <= hold;
+ t953 <= reset;
+ t976 <= t980 & m4;
+ eom <= t5
+ | t4 & m1 & id80
+ | t3 & m2
+ | t3 & m3
+ | t3 & m4
+ | t3 & m5 & ~id_xthl;
+ end
+ if (f2)
+ begin
+ t980 <= sy_inta;
+ end
+end
+
+//______________________________________________________________________________
+//
+// processor cycles state machine
+//
+always @(posedge clk)
+begin
+ if (f1)
+ begin
+ m1f1 <= m1;
+ m2f1 <= m2;
+ m3f1 <= m3;
+ m4f1 <= m4;
+ m5f1 <= m5;
+ end
+ if (f2)
+ begin
+ m1 <= (~ms0 & ~ms1) | (~ms1 & m1f1);
+ m2 <= (~ms0 | ~ms1) & ((ms0 & m2f1) | (ms1 & m1f1));
+ m3 <= (ms0 & m3f1) | (ms1 & m2f1);
+ m4 <= (ms0 & m4f1) | (ms1 & m3f1) | (ms0 & ms1);
+ m5 <= (ms0 & m5f1) | (ms1 & m4f1);
+ end
+end
+
+//______________________________________________________________________________
+//
+// interrupt logic
+//
+assign irq = intr & inte & ~reset & ~hold;
+assign pin_inte = inte;
+
+always @(posedge clk)
+begin
+ if (f2) intr <= pin_int;
+ if (f2) mstart <= ~ms0 & ~ms1;
+ if (sy_inta) minta <= 1;
+ if (f1 & t1 & m1) minta <= 0;
+end
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ begin
+ inta <= 0;
+ inte <= 0;
+ end
+ else
+ begin
+ if (f1)
+ begin
+ if (irq & ((tw & sy_hlta) | (mstart & ~id_eidi))) inta <= 1;
+ if (~intr | id_eidi | (t5 & id_rst)) inta <= 0;
+ end
+ if (f2)
+ begin
+ if (t1f1 & id_eidi) inte <= i[3];
+ if (t1f1 & sy_inta) inte <= 0;
+ end
+ end
+end
+//______________________________________________________________________________
+//
+// instruction register and decoder
+//
+function cmp
+(
+ input [7:0] i,
+ input [7:0] c,
+ input [7:0] m
+);
+ cmp = &(~(i ^ c) | m);
+endfunction
+
+assign imx = ~(id_op | (id_mov & t4));
+assign acc_sel = imx ? (i[5:3] == 3'b111) : (i[2:0] == 3'b111);
+assign jmpflag = (psw_c & i14 & ~i25) // Intel original: d[0] instead of psw_c
+ | (psw_p & ~i14 & i25) // Intel original: d[2] instead of psw_p
+ | (psw_z & ~i14 & ~i25) // Intel original: d[6] instead of psw_z
+ | (psw_s & i14 & i25); // Intel original: d[7] instead of psw_s
+
+always @(posedge clk)
+begin
+ //
+ // Simplify the D-bus multiplexer and feed the I-register by input pins directly
+ // if (f2 & dbin_pin & (reset | (m1 & t3))) i <= pin_din;
+ //
+ if (~f2 & (reset | (m1 & t3))) i <= pin_din;
+ if (f1)
+ begin
+ i25 <= imx ? i[5] : i[2];
+ i14 <= imx ? i[4] : i[1];
+ i03 <= imx ? i[3] : i[0];
+ end
+end
+
+assign goto = id_rst | id_jmp | id_call | (jmptake & (id_cxx | id_jxx));
+assign t1460 = (t1 & ((m2 & id00)
+ | (m3 & id00)
+ | (m4 & (id01 | id04))
+ | (m5 & (id01 | id04)))
+ | t2 & ( (m2 & id00)
+ | (m4 & id01)
+ | (m5 & id01))
+ | t3 & ( (m4 & (id04 | id_sphl)))
+ | t5 & ( (m1 & (id04 | id_sphl)))) & ~(~jmptake & id_cxx & t5);
+
+always @(posedge clk)
+begin
+ if (f2 & t4f1)
+ begin
+ jmptake <= i03 ? jmpflag : ~jmpflag;
+ end
+ if (f1)
+ begin
+ tree0 <= t1 & ( (m1 & ~goto)
+ | (m2 & ~id_xthl)
+ | (m3 & ~id_xthl)
+ | (m4 & id02))
+ | t2 & ( m1
+ | (m2 & ~id_xthl)
+ | (m3 & ~id_xthl)
+ | (m4 & (id02 | id_rst | id_cxx | id_call))
+ | (m5 & (id_rst | id_cxx | id_call)))
+ | t3 & ( (m4 & (id_ret | id_rxx))
+ | (m5 & (id_ret | id_rxx)))
+ | t5 & id_pchl;
+
+ tree1 <= t1460;
+
+ tree2 <= t1 & ( (m4 & (id_mov | id_idr | id_op))
+ | (m5 & id08))
+ | t2 & ( (m4 & (id_shld | id00 | id_dad))
+ | (m5 & (id_shld | id00 | id_dad)))
+ | t3 & ( (m4 & (id_lhld | id_dad))
+ | (m5 & (id_lhld | id_dad)))
+ | t5 & m5;
+
+ t2806 <= id08 & ((t3 & m4) | (t5 & m1));
+ t2817 <= reset | (t3 & (m1 | m3 | (m4 & id_io) | (m5 & id06)));
+ t2819 <= reset | (t3 & (m2 | (m4 & id06) | (m5 & id_rst)));
+
+ t3047 <= (t1 | t2) & m4 & id_dad
+ | t2 & ((m4 & id_shld) | (m5 & id03));
+
+ t2998 <= (t1 | t2) & m5 & id_dad
+ | t2 & ((m5 & id_shld) | (m4 & id03));
+
+ t3403 <= t2 & ( (m1 | m2)
+ | (m3 & ~id_xthl)
+ | ((m4 | m5) & ~id_dad & ~id09))
+ | t3 & m4 & id09
+ | t5 & (m5 | (m1 & ~id08));
+
+ t3363 <= t1 & (m1 | m2 | m3 | ((m4 | m5) & ~id_hlt & ~id_dad));
+ t3335 <= id07 & ((t1 & (m4 | m5)) | (t3 & (m2 | m3)) | t5);
+
+ t3361 <= t1 & m4 & id_lsax
+ | t2 & id10 & ~sy_wo_n
+ | t3 & id10 & sy_wo_n & (m4 | m5)
+ | t5 & id08 & m1;
+ end
+end
+
+assign id_nop = cmp(i, 8'b00xxx000, 8'b00111000);
+assign id_lxi = cmp(i, 8'b00xx0001, 8'b00110000);
+assign id_lsax = cmp(i, 8'b000xx010, 8'b00011000);
+assign id_inx = cmp(i, 8'b00xx0011, 8'b00110000);
+assign id_inr = cmp(i, 8'b00xxx100, 8'b00111000);
+assign id_dcr = cmp(i, 8'b00xxx101, 8'b00111000);
+assign id_idr = cmp(i, 8'b00xxx10x, 8'b00111001);
+assign id_mvi = cmp(i, 8'b00xxx110, 8'b00111000);
+assign id_dad = cmp(i, 8'b00xx1001, 8'b00110000);
+assign id_dcx = cmp(i, 8'b00xx1011, 8'b00110000);
+assign id_opa = cmp(i, 8'b00xxx111, 8'b00111000);
+assign id_idm = cmp(i, 8'b0011010x, 8'b00000001);
+assign id_stlda = cmp(i, 8'b0011x010, 8'b00001000);
+assign id_mvim = cmp(i, 8'b00110110, 8'b00000000);
+assign id_shld = cmp(i, 8'b00100010, 8'b00000000);
+assign id_lhld = cmp(i, 8'b00101010, 8'b00000000);
+assign id_mvmr = cmp(i, 8'b01110xxx, 8'b00000111) & ~id_hlt;
+assign id_mvrm = cmp(i, 8'b01xxx110, 8'b00111000) & ~id_hlt;
+assign id_hlt = cmp(i, 8'b01110110, 8'b00000000);
+assign id_mov = cmp(i, 8'b01xxxxxx, 8'b00111111);
+assign id_op = cmp(i, 8'b10xxxxxx, 8'b00111111);
+assign id_opm = cmp(i, 8'b10xxx110, 8'b00111000);
+assign id_pop = cmp(i, 8'b11xx0001, 8'b00110000);
+assign id_push = cmp(i, 8'b11xx0101, 8'b00110000);
+assign id_rst = cmp(i, 8'b11xxx111, 8'b00111000);
+assign id_xthl = cmp(i, 8'b11100011, 8'b00000000);
+assign id_sphl = cmp(i, 8'b11111001, 8'b00000000);
+assign id_pchl = cmp(i, 8'b11101001, 8'b00000000);
+assign id_xchg = cmp(i, 8'b11101011, 8'b00000000);
+assign id_cxx = cmp(i, 8'b11xxx100, 8'b00111000);
+assign id_jxx = cmp(i, 8'b11xxx010, 8'b00111000);
+assign id_rxx = cmp(i, 8'b11xxx000, 8'b00111000);
+assign id_ret = cmp(i, 8'b110x1001, 8'b00010000);
+assign id_call = cmp(i, 8'b11xx1101, 8'b00110000);
+assign id_eidi = cmp(i, 8'b1111x011, 8'b00001000);
+assign id_jmp = cmp(i, 8'b1100x011, 8'b00001000);
+assign id_io = cmp(i, 8'b1101x011, 8'b00001000);
+assign id_opi = cmp(i, 8'b11xxx110, 8'b00111000);
+assign id_in = cmp(i, 8'b11011011, 8'b00000000);
+assign id_popsw = cmp(i, 8'b11110001, 8'b00000000);
+assign id_out = cmp(i, 8'b11010011, 8'b00000000);
+assign id_11x = cmp(i, 8'b11xxxxxx, 8'b00111111);
+assign id_pupsw = cmp(i, 8'b11110101, 8'b00000000);
+
+assign id_rxc = ~i[5] & i[3] & id_opa;
+assign id_sha = ~i[5] & id_opa;
+assign id_rlc = (i[5:3] == 3'b000) & id_opa;
+assign id_rar = (i[5:3] == 3'b011) & id_opa;
+assign id_daa = (i[5:3] == 3'b100) & id_opa;
+assign id_cma = (i[5:3] == 3'b101) & id_opa;
+assign id_stc = (i[5:3] == 3'b110) & id_opa;
+assign id_cmc = (i[5:3] == 3'b111) & id_opa;
+
+assign id_add = (i[5:3] == 3'b000) & (id_op | id_opi);
+assign id_adc = (i[5:3] == 3'b001) & (id_op | id_opi);
+assign id_sub = (i[5:3] == 3'b010) & (id_op | id_opi);
+assign id_sbb = (i[5:3] == 3'b011) & (id_op | id_opi);
+assign id_ana = (i[5:3] == 3'b100) & (id_op | id_opi);
+assign id_xra = (i[5:3] == 3'b101) & (id_op | id_opi);
+assign id_ora = (i[5:3] == 3'b110) & (id_op | id_opi);
+assign id_cmp = (i[5:3] == 3'b111) & (id_op | id_opi);
+
+assign id80 = id_lxi | id_pop | id_opm | id_idm | id_dad
+ | id_xthl | id_xchg | id_jxx | id_ret | id_eidi
+ | id_nop | id_stlda | id_mvmr | id_mvrm | id_hlt
+ | id_opa | id_mvim | id_jmp | id_io | id_opi
+ | id_mvi | id_lsax | id_lhld | id_shld | id_op;
+assign id81 = id_dcx | id_inx | id_sphl | id_pchl | id_xchg
+ | id_eidi | id_nop | id_opa | id_op | id_mov
+ | (id_idr & ~id82);
+assign id82 = id_pop | id_push | id_opm | id_idm | id_dad
+ | id_rst | id_ret | id_rxx | id_mvrm | id_mvmr
+ | id_hlt | id_mvim | id_io | id_opi | id_mvi
+ | id_lsax;
+assign id83 = id_opm | id_stlda | id_mvmr | id_mvrm | id_opi
+ | id_mvi | id_lsax;
+assign id84 = id_lxi | id_jxx | id_jmp;
+assign id85 = id_push | id_idm | id_rst | id_xthl | id_cxx
+ | id_call | id_mvim | id_shld | (id_io & ~i[3]);
+assign id86 = id_push | id_rst | id_xthl | id_cxx | id_call
+ | id_mvmr | id_shld | (~i[3] & (id_lsax | id_stlda));
+
+assign id00 = id_xthl | id_pchl | id_sphl;
+assign id01 = id_pop | id_rxx | id_ret;
+assign id02 = id_mvi | id_opi | id_io;
+assign id03 = id_rst | id_push | id_xthl | id_cxx | id_call;
+assign id04 = id_rst | id_push | id_xthl | id_cxx | id_call;
+assign id05 = id_rst | id_push | id_xthl | id_cxx | id_call | id_dcx;
+assign id06 = id_pop | id_rxx | id_ret | id_dad | id_lhld | id_io;
+assign id07 = id_dcx | id_inx | id_lxi | id_dad;
+assign id08 = id_mov | id_mvi | id_idr | id_op;
+assign id09 = id_rst | id_push | id_xthl | id_cxx | id_call | id_shld;
+assign id10 = id_pop | id_push | id_mvrm | id_mvi;
+
+//______________________________________________________________________________
+//
+// function alu
+// (
+// input rxc,
+// input ora,
+// input ana,
+// input xra,
+// input x,
+// input r,
+// input nc,
+// input rn,
+// input cp
+// );
+// alu = x & r & cp & ~(rxc | ora | ana | xra)
+// | nc & (cp | x | r) & ~(rxc | ora | ana | xra)
+// | rxc & rn
+// | ora & (x | r)
+// | ana & (x & r)
+// | xra & (x ^ r);
+// endfunction
+//
+//
+// assign s[0] = alu(id_rxc, id_ora, id_ana, id_xra, x[0], r[0], ~c[0], r[1], cl) | (id_rlc & c[7]);
+// assign s[1] = alu(id_rxc, id_ora, id_ana, id_xra, x[1], r[1], ~c[1], r[2], c[0]);
+// assign s[2] = alu(id_rxc, id_ora, id_ana, id_xra, x[2], r[2], ~c[2], r[3], c[1]);
+// assign s[3] = alu(id_rxc, id_ora, id_ana, id_xra, x[3], r[3], ~c[3], r[4], c[2]);
+// assign s[4] = alu(id_rxc, id_ora, id_ana, id_xra, x[4], r[4], ~c[4], r[5], c[3]);
+// assign s[5] = alu(id_rxc, id_ora, id_ana, id_xra, x[5], r[5], ~c[5], r[6], c[4]);
+// assign s[6] = alu(id_rxc, id_ora, id_ana, id_xra, x[6], r[6], ~c[6], r[7], c[5]);
+// assign s[7] = alu(id_rxc, id_ora, id_ana, id_xra, x[7], r[7], ~c[7], ch, c[6]);
+//
+//______________________________________________________________________________
+//
+// arithmetic and logic unit
+//
+// assign alu_xwr = (f1 & m1 & t3) | (f2 & (a327 | t4f1 & (id_out | ~id_11x)));
+//
+assign alu_xwr = (a327 | t4f1 & (id_rst | id_out | ~id_11x));
+assign alu_xout = ~(id_sub | id_sbb | id_cmp | id_cma);
+assign alu_xrd = t1698 | a358;
+assign x = alu_xout ? xr : ~xr;
+
+assign alu_ald = t2222 & ( id_adc | id_add | id_daa | id_xra | id_sbb
+ | id_sub | id_ana | id_ora | id_sha | id_cma);
+assign alu_ard = t1375 | a398;
+assign alu_awr = t1497 | a357;
+
+assign alu_r00 = id_dcr & t4f1;
+assign alu_srd = t1668;
+assign alu_rwr = t1780;
+assign alu_rld = t4f1 & (id_sha | id_op | id_opi);
+
+assign daa = id_daa & t4f1;
+assign daa_x6 = (acc[3] & (acc[2] | acc[1])) | psw_ac;
+assign daa_6x = ((acc[3] & (acc[2] | acc[1])) & acc[4] & acc[7])
+ | (acc[7] & (acc[6] | acc[5])) | tmp_c;
+
+assign s = {7'b0000000, id_rlc & c[7]}
+ | ((id_rxc | id_ora | id_ana | id_xra) ? 8'h00 : (x + r + cl))
+ | (id_rxc ? {ch, r[7:1]} : 8'h00)
+ | (id_ora ? (x | r) : 8'h00)
+ | (id_ana ? (x & r) : 8'h00)
+ | (id_xra ? (x ^ r) : 8'h00);
+
+assign cl = tmp_c & ~id_daa & ~id_rlc & ~id_ora & ~id_xra & ~id_rxc;
+assign ch = tmp_c & id_rar | r[0] & ~id_rar;
+
+//
+// wire ca0_n, ca2_n, ca1, ca3;
+// assign ca0_n = ~(cl & (x[0] | r[0])) & ~(x[0] & r[0]) & ~(id_ana & id_rxc);
+// assign ca2_n = ~(ca1 & (x[2] | r[2])) & ~(x[2] & r[2]) & ~(id_ana & id_rxc);
+// assign ca1 = ~(~x[1] & ~r[1]) & ~(ca0_n & (~x[1] | ~r[1])) & ~(id_ora | id_rxc | id_xra);
+// assign ca3 = ~(~x[3] & ~r[3]) & ~(ca2_n & (~x[3] | ~r[3])) & ~(id_ora | id_rxc | id_xra);
+//
+assign c[0] = (r[0] & x[0]) | (cl & (r[0] | x[0]));
+assign c[1] = (r[1] & x[1]) | (c[0] & (r[1] | x[1]));
+assign c[2] = (r[2] & x[2]) | (c[1] & (r[2] | x[2]));
+assign c[3] = (r[3] & x[3]) | (c[2] & (r[3] | x[3]));
+assign c[4] = (r[4] & x[4]) | (c[3] & (r[4] | x[4]));
+assign c[5] = (r[5] & x[5]) | (c[4] & (r[5] | x[5]));
+assign c[6] = (r[6] & x[6]) | (c[5] & (r[6] | x[6]));
+assign c[7] = (r[7] & x[7]) | (c[6] & (r[7] | x[7]));
+
+assign alu_zrd = m1f1 & t3f1;
+assign alu_frd = t2046; /* | t4f1 & (id_11x & ~id_out);
+ // as we do need to translate flags on the bus for conditional unit anymore */
+
+assign a398 = t1993 & ((t1994 & id08) | id_opa | id_stlda | id_lsax | id_io);
+
+always @(posedge clk)
+begin
+ if (f1)
+ begin
+ t1375 <= t2 & m4 & id_pupsw;
+ t1497 <= t3 & m5 & id_popsw;
+ t1698 <= t5 & m1 & ~id_inr & ~id_dcr
+ | t3 & m5 & id_rst;
+ t1668 <= t2 & m5 & (id_inr | id_dcr)
+ | t3 & m5 & id_dad
+ | t3 & m4 & id_dad
+ | t5 & m1 & (id_inr | id_dcr);
+ t1780 <= t3 & m1
+ | t1 & (m4 | m5) & id_dad;
+ t2222 <= (t2 & m1) | (t1 & m5);
+ a327 <= t3 & m4 & ~(id_dad | id_out | id_rst)
+ | t2 & (m4 | m5) & id_dad;
+ a357 <= t3 & m5 & (id_io | id_mvim) & sy_wo_n
+ | t3 & m4 & (id_stlda | id_lsax | id_mvmr) & sy_wo_n
+ | acc_sel & id08 & (t5 & m1 | t3 & m4);
+ a358 <= t2 & ~sy_wo_n & (id_io | id_mvim | id_stlda | id_lsax | id_mvmr);
+
+ psw_ld <= t3 & m4 & id_popsw;
+ psw_wr <= t2 & m1 & (id_opi | id_inr | id_dcr | id_daa | id_op);
+ t2046 <= t2 & m5 & id_pupsw; /* | reset | t3 & m1; */
+//
+// t2047 <= reset
+// | t3 & m1
+// | t3 & m5 & id_rst;
+//
+ t1993 <= t4 & m1;
+ t1994 <= acc_sel;
+ t2133 <= ~id_rxc & c[7];
+ t2175 <= t3 & m1
+ | t2 & m5 & id_dad;
+ end
+end
+
+always @(posedge clk)
+begin
+ if (f2)
+ begin
+ if (alu_xwr) xr <= id_rst ? (i & 8'b00111000) : d;
+ if (alu_awr) acc <= d;
+ if (alu_ald) acc <= s;
+ if (alu_rld) r <= acc;
+ if (alu_rwr) r <= d;
+ if (alu_r00) r <= 8'hff;
+ if (daa)
+ begin
+ r[1] <= daa_x6;
+ r[2] <= daa_x6;
+ r[5] <= daa_6x;
+ r[6] <= daa_6x;
+ end
+ if (psw_ld)
+ begin
+ psw_c <= d[0]; // x register was in original Intel design
+ psw_p <= d[2];
+ psw_ac <= d[4];
+ psw_z <= d[6];
+ psw_s <= d[7];
+ end
+ if (psw_wr)
+ begin
+ psw_p <= ~(^s);
+ psw_ac <= (c[3] & ~id_xra & ~id_ora & ~id_rxc) | (id_ana & (x[3] | r[3]));
+ psw_z <= ~(|s);
+ psw_s <= s[7];
+ end
+ if (t2222)
+ begin
+ if (id_xra | id_stc | id_ora | id_ana | id_cmc)
+ psw_c <= ~tmp_c;
+ if (id_cmp | id_sbb | id_sub)
+ psw_c <= ~(t2133 | id_rxc & x[0]);
+ if (id_dad | id_sha | id_adc | id_add)
+ psw_c <= t2133 | id_rxc & x[0];
+ end
+ if (daa & daa_6x)
+ psw_c <= 1'b1;
+
+ if (t2175)
+ tmp_c <= psw_c;
+ if (t4f1)
+ begin
+ if (id_sbb)
+ tmp_c <= ~psw_c;
+ if (id_inr | id_ora | id_xra | id_ana | id_cmp | id_sub)
+ tmp_c <= 1'b1;
+ if (id_dad | id_cma | id_dcr | id_add | id_stc)
+ tmp_c <= 1'b0;
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/org/syn/de0/de0.sdc b/1801BM1_vm80a/org/syn/de0/de0.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..103e1b20163089721a533d5096670f6c62ae425e
--- /dev/null
+++ b/1801BM1_vm80a/org/syn/de0/de0.sdc
@@ -0,0 +1,36 @@
+#************************************************************
+# THIS IS A WIZARD-GENERATED FILE.
+#
+# Version 12.1 Build 177 11/07/2012 SJ Full Version
+#
+#************************************************************
+
+# Copyright (C) 1991-2012 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions
+# and other software and tools, and its AMPP partner logic
+# functions, and any output files from any of the foregoing
+# (including device programming or simulation files), and any
+# associated documentation or information are expressly subject
+# to the terms and conditions of the Altera Program License
+# Subscription Agreement, Altera MegaCore Function License
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of
+# programming logic devices manufactured by Altera and sold by
+# Altera or its authorized distributors. Please refer to the
+# applicable agreement for further details.
+
+
+
+# Clock constraints
+
+create_clock -name "clk" -period 20.000ns [get_ports {de0_clock_50}]
+
+
+# Automatically calculate clock uncertainty to jitter and other effects.
+derive_clock_uncertainty
+
+# tsu/th constraints
+
+# tco constraints
+
+# tpd constraints
diff --git a/1801BM1_vm80a/org/syn/de1/de1.sdc b/1801BM1_vm80a/org/syn/de1/de1.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..e70db904da67f5296cad8d3b90bd79c5c76454bc
--- /dev/null
+++ b/1801BM1_vm80a/org/syn/de1/de1.sdc
@@ -0,0 +1,36 @@
+#************************************************************
+# THIS IS A WIZARD-GENERATED FILE.
+#
+# Version 12.1 Build 177 11/07/2012 SJ Full Version
+#
+#************************************************************
+
+# Copyright (C) 1991-2012 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions
+# and other software and tools, and its AMPP partner logic
+# functions, and any output files from any of the foregoing
+# (including device programming or simulation files), and any
+# associated documentation or information are expressly subject
+# to the terms and conditions of the Altera Program License
+# Subscription Agreement, Altera MegaCore Function License
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of
+# programming logic devices manufactured by Altera and sold by
+# Altera or its authorized distributors. Please refer to the
+# applicable agreement for further details.
+
+
+
+# Clock constraints
+
+create_clock -name "clk" -period 20.000ns [get_ports {de1_clock_50}]
+
+
+# Automatically calculate clock uncertainty to jitter and other effects.
+derive_clock_uncertainty
+
+# tsu/th constraints
+
+# tco constraints
+
+# tpd constraints
diff --git a/1801BM1_vm80a/org/syn/de2-115/de2-115.sdc b/1801BM1_vm80a/org/syn/de2-115/de2-115.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..56dfe3064a57d8e62d21b3895dae20d0410e4f63
--- /dev/null
+++ b/1801BM1_vm80a/org/syn/de2-115/de2-115.sdc
@@ -0,0 +1,36 @@
+#************************************************************
+# THIS IS A WIZARD-GENERATED FILE.
+#
+# Version 12.1 Build 177 11/07/2012 SJ Full Version
+#
+#************************************************************
+
+# Copyright (C) 1991-2012 Altera Corporation
+# Your use of Altera Corporation's design tools, logic functions
+# and other software and tools, and its AMPP partner logic
+# functions, and any output files from any of the foregoing
+# (including device programming or simulation files), and any
+# associated documentation or information are expressly subject
+# to the terms and conditions of the Altera Program License
+# Subscription Agreement, Altera MegaCore Function License
+# Agreement, or other applicable license agreement, including,
+# without limitation, that your use is for the sole purpose of
+# programming logic devices manufactured by Altera and sold by
+# Altera or its authorized distributors. Please refer to the
+# applicable agreement for further details.
+
+
+
+# Clock constraints
+
+create_clock -name "clk" -period 20.000ns [get_ports {de2_clock_50}]
+
+
+# Automatically calculate clock uncertainty to jitter and other effects.
+derive_clock_uncertainty
+
+# tsu/th constraints
+
+# tco constraints
+
+# tpd constraints
diff --git a/1801BM1_vm80a/org/tbe/config.h b/1801BM1_vm80a/org/tbe/config.h
new file mode 100644
index 0000000000000000000000000000000000000000..bdd18aab23e3c4cbd84f2c2aa20301a52bde62db
--- /dev/null
+++ b/1801BM1_vm80a/org/tbe/config.h
@@ -0,0 +1,26 @@
+//______________________________________________________________________________
+//
+// Simulation configuration parameters
+//
+`timescale 1ns / 100ps
+//
+// CAUTION: SIM_CONFIG_FAST_RESET should be undefined in release version
+// Defining this parameter shorts the system reset time intervals and
+// provides much quicker simulation
+//
+`define SIM_CONFIG_FAST_RESET 1
+//
+// Simulation stops (breakpoint) after this time elapsed
+//
+`define SIM_CONFIG_TIME_LIMIT 2000000
+//
+// External clock frequency
+//
+`define SIM_CONFIG_CLOCK_HPERIOD 10
+
+//
+// Generated F1/F2/pause phase cycles
+//
+`define SIM_CONFIG_F1 1
+`define SIM_CONFIG_F2 1
+`define SIM_CONFIG_F0 0
diff --git a/1801BM1_vm80a/org/tbe/tb80a.v b/1801BM1_vm80a/org/tbe/tb80a.v
new file mode 100644
index 0000000000000000000000000000000000000000..948667bd00bf120df033552925a8ec740674e4d5
--- /dev/null
+++ b/1801BM1_vm80a/org/tbe/tb80a.v
@@ -0,0 +1,262 @@
+//
+// Copyright (c) 2014 by 1801BM1@gmail.com
+// Licensed under CC-BY 3.0 (https://creativecommons.org/licenses/by/3.0/)
+//
+//______________________________________________________________________________
+//
+`include "config.h"
+
+//______________________________________________________________________________
+//
+module memory
+(
+ input [15:0] a,
+ input [7:0] din,
+ output reg [7:0] dout,
+ input read,
+ input write
+);
+reg [7:0] mem [0:16383];
+integer i;
+
+always @ (posedge read)
+begin
+ dout = mem[a[13:0]];
+end
+
+always @ (negedge write)
+begin
+ mem[a[13:0]] = din;
+ if (a >= 16'h4000)
+ begin
+ $display("Fault write @ %04X<-%02X", a, din);
+ $stop;
+ end
+end
+
+always @ (read)
+begin
+ if (a >= 16'h4000)
+ begin
+ $display("Fault read @ %04X", a);
+ $stop;
+ end
+end
+
+initial
+begin
+ for (i=0; i<16384; i = i + 1)
+ begin
+ mem[i] = 8'h00;
+ end
+
+ $readmemh("..\\..\\..\\tst\\rom\\memini.bin", mem);
+end
+endmodule
+
+//______________________________________________________________________________
+//
+
+module tb80a();
+//
+// 580BM80A pins
+//
+tri1 [7:0] d;
+wire [7:0] d_in, d_sys;
+reg [7:0] d_out, d_cyc;
+wire d_oe;
+
+wire [15:0] a;
+reg clk;
+reg f1;
+reg f2;
+reg reset;
+reg ready;
+reg hold;
+reg intr;
+
+wire inte;
+wire hlda;
+wire waitr;
+wire sync;
+wire dbin;
+wire wr_n;
+
+integer i;
+//______________________________________________________________________________
+//
+assign d = d_oe ? d_sys : 8'hZZ;
+assign d_sys = d_cyc[0] ? 8'hE7 : d_in;
+
+//_____________________________________________________________________________
+//
+// Clock generator
+//
+initial
+begin
+ clk = 1'b0;
+ f1 = 1'b0;
+ f2 = 1'b0;
+ forever
+ begin
+ f1 = 1'b1;
+ for (i=0; i<`SIM_CONFIG_F1; i = i + 1)
+ begin
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ end
+ f1 = 1'b0;
+ f2 = 1'b1;
+ for (i=0; i<`SIM_CONFIG_F2; i = i + 1)
+ begin
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ end
+ f2 = 1'b0;
+ for (i=0; i<`SIM_CONFIG_F0; i = i + 1)
+ begin
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ end
+
+ /*
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ f1 = 1'b1;
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ f1 = 1'b0;
+ f2 = 1'b1;
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ ckl = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ f2 = 1'b0;
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+
+ clk = 1'b0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ clk = 1'b1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD);
+ */
+ end
+end
+
+//
+// Simulation time limit (first breakpoint)
+//
+initial
+begin
+ #`SIM_CONFIG_TIME_LIMIT $stop;
+end
+
+memory mem(.a(a), .din(d), .dout(d_in), .read(dbin), .write(~wr_n));
+
+// always @ (DBIN) d_in = a[7:0];
+always @ (posedge wr_n) d_out = d;
+always @ (posedge sync) d_cyc = d;
+
+assign d_oe = dbin;
+initial
+begin
+ reset = 1;
+ intr = 0;
+
+ #(`SIM_CONFIG_CLOCK_HPERIOD*2*9*6);
+ reset = 0;
+
+ #(`SIM_CONFIG_CLOCK_HPERIOD*2*9*20);
+ intr = 1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD*2*9*20);
+ intr = 0;
+end
+
+initial
+begin
+ ready = 1;
+ forever
+ begin
+ #(`SIM_CONFIG_CLOCK_HPERIOD*2*50);
+ ready = 0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD*8);
+ ready = 1;
+ end
+end
+
+initial
+begin
+ hold = 0;
+ #(`SIM_CONFIG_CLOCK_HPERIOD*4);
+ forever
+ begin
+ #(`SIM_CONFIG_CLOCK_HPERIOD*2*500);
+ hold = 1;
+ #(`SIM_CONFIG_CLOCK_HPERIOD*80);
+ hold = 0;
+ end
+end
+
+//_____________________________________________________________________________
+//
+// Instantiation module under test
+//
+//
+vm80a vm80a
+(
+ .pin_clk(clk),
+ .pin_f1(f1),
+ .pin_f2(f2),
+ .pin_d(d),
+ .pin_a(a),
+ .pin_reset(reset),
+ .pin_hold(hold),
+ .pin_hlda(hlda),
+ .pin_ready(ready),
+ .pin_wait(waitr),
+ .pin_int(intr),
+ .pin_inte(inte),
+ .pin_sync(sync),
+ .pin_dbin(dbin),
+ .pin_wr_n(wr_n)
+);
+endmodule
+
diff --git a/1801BM1_vm80a/readme.md b/1801BM1_vm80a/readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..b9e90c28b3262a7e8c2ac7ba6406937dd4ba40b2
--- /dev/null
+++ b/1801BM1_vm80a/readme.md
@@ -0,0 +1,67 @@
+## Die photo
+
+
+
+Links to raw photos (please, note, files are LARGE):
+- [Top metal, 11Kx10K, 95M](http://www.1801bm1.com/files/retro/580/images/580vm80a-2.jpg)
+- [Top metal, 11Kx10K, 140M](http://www.1801bm1.com/files/retro/580/images/580vm80a-3.jpg)
+- [Diffusion, 5.5Kx5K, 28M](http://www.1801bm1.com/files/retro/580/images/580vm80a-sil.jpg)
+
+## Abstract
+The vm80a is the core built on the base of the revengineered real 580BM80A die.
+The 580BM80A chip is the Soviet replica of early Intel i8080A microprocessor,
+and these ones are very close topologically.
+
+The silicon techology parameters are:
+- 5 micron scale
+- one metal and one polycrystalline silicon layer
+- NMOS schematics with depletion mode loads
+- the extra high voltage source (+12V) is required
+- high voltage direct clock phases (+12V)
+- no built-in negative bias generator, extra negative voltage source is required
+
+The reversing was performed in the following stages:
+- crystall decapsulation (with hot acid etching)
+- taking the panorama shapshot of combined upper metal and polysilicon layers
+- etching upper metal and polysilicon layers
+- taking the panorama shapshot of diffusion layer with the prints of polysilicon layer
+- vectorizing the photos in the SprintLayout editor
+- transferring the topology to the PCAD-2004 pcb editor
+- converting topology to PCAD-2004 schematics using the back annotation
+- writing the Verilog code on the precise schematics base
+- patching the code to eliminate the asynchronous nature of original circuits
+- simulating and testing the resulting vm80a core on the real FPGAs
+- thorough i8080 exerciser tests were passed successfully
+
+## Results
+The project provides two i8080 models in Verilog - the one is pin-compatible with original
+processor and other is refactored to be implemented within SoC and has the Wishbone interface.
+Both approaches are proven on the real boards and FPGAs.
+The models are compact and fast enough, the typical speed and area for Wishbone-featured model
+on the DE0 board (Cyclone EP3C16F484C6):
+- 104MHz clock, 607 LUTs and 187 flip-flops, no RAM blocks
+
+## Directory structure
+#### \sch
+- topology in Sprint Layout format
+- topology in PCD-2004 pcb format
+- schematics in PCD-2004 sch format
+- schematics in [pdf](/sch/vm80a.pdf) (gate level)
+
+#### \org
+- synchronous vm80a core, all original timings are kept intact,
+includes the wrapper for usage as in-place-substitution of real i8080/580BM80A
+
+#### \wbc
+- Wishbone compatible version of vm80a core, uses single clock, FPGA-optimized,
+follows the original command execution timings
+
+#### \tst
+- i8080 Exerciser test software and some other tests
+
+## Supported FPGA development boards:
+- [Altera DE0](http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&No=364)
+- [Altera DE1](http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=53&No=83)
+- [Altera DE2-115](http://www.terasic.com.tw/cgi-bin/page/archive.pl?Language=English&CategoryNo=139&No=502)
+- [Alinx AX309](http://artofcircuits.com/product/alinx-ax309-spartan-6-fpga-development-board-xc6slx9-2ftg256c)
+
diff --git a/1801BM1_vm80a/wbc/rtl/de0/de0_mem.v b/1801BM1_vm80a/wbc/rtl/de0/de0_mem.v
new file mode 100644
index 0000000000000000000000000000000000000000..35121a76c1ae53fe8156e7669c3ad131d2ee1a8c
--- /dev/null
+++ b/1801BM1_vm80a/wbc/rtl/de0/de0_mem.v
@@ -0,0 +1,104 @@
+// megafunction wizard: %RAM: 1-PORT%
+// GENERATION: STANDARD
+// VERSION: WM1.0
+// MODULE: altsyncram
+
+// ============================================================
+// File Name: de0_mem.v
+// Megafunction Name(s):
+// altsyncram
+//
+// Simulation Library Files(s):
+// altera_mf
+// ============================================================
+// ************************************************************
+// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
+//
+// 12.1 Build 177 11/07/2012 SJ Full Version
+// ************************************************************
+
+
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module memini (
+ address,
+ clock,
+ data,
+ wren,
+ q);
+
+ input [13:0] address;
+ input clock;
+ input [7:0] data;
+ input wren;
+ output [7:0] q;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_off
+`endif
+ tri1 clock;
+`ifndef ALTERA_RESERVED_QIS
+// synopsys translate_on
+`endif
+
+ wire [7:0] sub_wire0;
+ wire [7:0] q = sub_wire0[7:0];
+
+ altsyncram altsyncram_component (
+ .address_a (address),
+ .clock0 (clock),
+ .data_a (data),
+ .wren_a (wren),
+ .q_a (sub_wire0),
+ .aclr0 (1'b0),
+ .aclr1 (1'b0),
+ .address_b (1'b1),
+ .addressstall_a (1'b0),
+ .addressstall_b (1'b0),
+ .byteena_a (1'b1),
+ .byteena_b (1'b1),
+ .clock1 (1'b1),
+ .clocken0 (1'b1),
+ .clocken1 (1'b1),
+ .clocken2 (1'b1),
+ .clocken3 (1'b1),
+ .data_b (1'b1),
+ .eccstatus (),
+ .q_b (),
+ .rden_a (1'b1),
+ .rden_b (1'b1),
+ .wren_b (1'b0));
+ defparam
+ altsyncram_component.clock_enable_input_a = "BYPASS",
+ altsyncram_component.clock_enable_output_a = "BYPASS",
+ altsyncram_component.init_file = "../../../tst/rom/memini.mif",
+ altsyncram_component.intended_device_family = "Cyclone III",
+ altsyncram_component.lpm_hint = "ENABLE_RUNTIME_MOD=NO",
+ altsyncram_component.lpm_type = "altsyncram",
+ altsyncram_component.numwords_a = 16384,
+ altsyncram_component.operation_mode = "SINGLE_PORT",
+ altsyncram_component.outdata_aclr_a = "NONE",
+ altsyncram_component.outdata_reg_a = "UNREGISTERED",
+ altsyncram_component.power_up_uninitialized = "FALSE",
+ altsyncram_component.ram_block_type = "M9K",
+ altsyncram_component.read_during_write_mode_port_a = "DONT_CARE",
+ altsyncram_component.widthad_a = 14,
+ altsyncram_component.width_a = 8,
+ altsyncram_component.width_byteena_a = 1;
+
+endmodule
diff --git a/1801BM1_vm80a/wbc/rtl/de0/de0_pll.v b/1801BM1_vm80a/wbc/rtl/de0/de0_pll.v
new file mode 100644
index 0000000000000000000000000000000000000000..b49fbd6447eaefd509c536c0024be51fc7a386b7
--- /dev/null
+++ b/1801BM1_vm80a/wbc/rtl/de0/de0_pll.v
@@ -0,0 +1,636 @@
+//
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+//
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module de0_pll50 (
+ inclk0,
+ c0,
+ c1,
+ locked);
+
+ input inclk0;
+ output c0;
+ output c1;
+ output locked;
+
+ wire [4:0] sub_wire0;
+ wire sub_wire2;
+ wire [0:0] sub_wire6 = 1'h0;
+ wire [0:0] sub_wire3 = sub_wire0[0:0];
+ wire [1:1] sub_wire1 = sub_wire0[1:1];
+ wire c1 = sub_wire1;
+ wire locked = sub_wire2;
+ wire c0 = sub_wire3;
+ wire sub_wire4 = inclk0;
+ wire [1:0] sub_wire5 = {sub_wire6, sub_wire4};
+
+ altpll altpll_component (
+ .inclk (sub_wire5),
+ .clk (sub_wire0),
+ .locked (sub_wire2),
+ .activeclock (),
+ .areset (1'b0),
+ .clkbad (),
+ .clkena ({6{1'b1}}),
+ .clkloss (),
+ .clkswitch (1'b0),
+ .configupdate (1'b0),
+ .enable0 (),
+ .enable1 (),
+ .extclk (),
+ .extclkena ({4{1'b1}}),
+ .fbin (1'b1),
+ .fbmimicbidir (),
+ .fbout (),
+ .fref (),
+ .icdrclk (),
+ .pfdena (1'b1),
+ .phasecounterselect ({4{1'b1}}),
+ .phasedone (),
+ .phasestep (1'b1),
+ .phaseupdown (1'b1),
+ .pllena (1'b1),
+ .scanaclr (1'b0),
+ .scanclk (1'b0),
+ .scanclkena (1'b1),
+ .scandata (1'b0),
+ .scandataout (),
+ .scandone (),
+ .scanread (1'b0),
+ .scanwrite (1'b0),
+ .sclkout0 (),
+ .sclkout1 (),
+ .vcooverrange (),
+ .vcounderrange ());
+ defparam
+ altpll_component.bandwidth_type = "AUTO",
+ altpll_component.clk0_divide_by = 1,
+ altpll_component.clk0_duty_cycle = 50,
+ altpll_component.clk0_multiply_by = 1,
+ altpll_component.clk0_phase_shift = "0",
+ altpll_component.clk1_divide_by = 1,
+ altpll_component.clk1_duty_cycle = 50,
+ altpll_component.clk1_multiply_by = 1,
+ altpll_component.clk1_phase_shift = "10000",
+ altpll_component.compensate_clock = "CLK0",
+ altpll_component.inclk0_input_frequency = 20000,
+ altpll_component.intended_device_family = "Cyclone III",
+ altpll_component.lpm_hint = "CBX_MODULE_PREFIX=de0_pll50",
+ altpll_component.lpm_type = "altpll",
+ altpll_component.operation_mode = "NORMAL",
+ altpll_component.pll_type = "AUTO",
+ altpll_component.port_activeclock = "PORT_UNUSED",
+ altpll_component.port_areset = "PORT_UNUSED",
+ altpll_component.port_clkbad0 = "PORT_UNUSED",
+ altpll_component.port_clkbad1 = "PORT_UNUSED",
+ altpll_component.port_clkloss = "PORT_UNUSED",
+ altpll_component.port_clkswitch = "PORT_UNUSED",
+ altpll_component.port_configupdate = "PORT_UNUSED",
+ altpll_component.port_fbin = "PORT_UNUSED",
+ altpll_component.port_inclk0 = "PORT_USED",
+ altpll_component.port_inclk1 = "PORT_UNUSED",
+ altpll_component.port_locked = "PORT_USED",
+ altpll_component.port_pfdena = "PORT_UNUSED",
+ altpll_component.port_phasecounterselect = "PORT_UNUSED",
+ altpll_component.port_phasedone = "PORT_UNUSED",
+ altpll_component.port_phasestep = "PORT_UNUSED",
+ altpll_component.port_phaseupdown = "PORT_UNUSED",
+ altpll_component.port_pllena = "PORT_UNUSED",
+ altpll_component.port_scanaclr = "PORT_UNUSED",
+ altpll_component.port_scanclk = "PORT_UNUSED",
+ altpll_component.port_scanclkena = "PORT_UNUSED",
+ altpll_component.port_scandata = "PORT_UNUSED",
+ altpll_component.port_scandataout = "PORT_UNUSED",
+ altpll_component.port_scandone = "PORT_UNUSED",
+ altpll_component.port_scanread = "PORT_UNUSED",
+ altpll_component.port_scanwrite = "PORT_UNUSED",
+ altpll_component.port_clk0 = "PORT_USED",
+ altpll_component.port_clk1 = "PORT_USED",
+ altpll_component.port_clk2 = "PORT_UNUSED",
+ altpll_component.port_clk3 = "PORT_UNUSED",
+ altpll_component.port_clk4 = "PORT_UNUSED",
+ altpll_component.port_clk5 = "PORT_UNUSED",
+ altpll_component.port_clkena0 = "PORT_UNUSED",
+ altpll_component.port_clkena1 = "PORT_UNUSED",
+ altpll_component.port_clkena2 = "PORT_UNUSED",
+ altpll_component.port_clkena3 = "PORT_UNUSED",
+ altpll_component.port_clkena4 = "PORT_UNUSED",
+ altpll_component.port_clkena5 = "PORT_UNUSED",
+ altpll_component.port_extclk0 = "PORT_UNUSED",
+ altpll_component.port_extclk1 = "PORT_UNUSED",
+ altpll_component.port_extclk2 = "PORT_UNUSED",
+ altpll_component.port_extclk3 = "PORT_UNUSED",
+ altpll_component.self_reset_on_loss_lock = "ON",
+ altpll_component.width_clock = 5;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING "0"
+// Retrieval info: PRIVATE: BANDWIDTH STRING "1.000"
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING "MHz"
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING "Low"
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING "1"
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING "0"
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING "0"
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING "0"
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING "0"
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING "0"
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING "0"
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING "0"
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING "c0"
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING "c0"
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "Any"
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "1"
+// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC "1"
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
+// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING "50.00000000"
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "50.000000"
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING "50.000000"
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING "0"
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING "0"
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC "1048575"
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING "1"
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING "50.000"
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING "MHz"
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING "100.000"
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING "MHz"
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING "1"
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING "1"
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING "1"
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING "Not Available"
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING "deg"
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
+// Retrieval info: PRIVATE: MIRROR_CLK1 STRING "0"
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "1"
+// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC "1"
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "100.00000000"
+// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING "100.00000000"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "0"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING "0"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING "MHz"
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
+// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING "180.00000000"
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING "deg"
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING "inclk0"
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING "de0_pll50"
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING "0"
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING "1"
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING "0"
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING "0"
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING "50.000"
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING "KHz"
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING "0.500"
+// Retrieval info: PRIVATE: SPREAD_USE STRING "0"
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
+// Retrieval info: PRIVATE: STICKY_CLK1 STRING "1"
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
+// Retrieval info: PRIVATE: USE_CLK0 STRING "1"
+// Retrieval info: PRIVATE: USE_CLK1 STRING "1"
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
+// Retrieval info: PRIVATE: USE_CLKENA1 STRING "0"
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
+// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC "50"
+// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING "10000"
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "20000"
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
+// Retrieval info: CONSTANT: LPM_TYPE STRING "altpll"
+// Retrieval info: CONSTANT: OPERATION_MODE STRING "NORMAL"
+// Retrieval info: CONSTANT: PLL_TYPE STRING "AUTO"
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_ARESET STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_FBIN STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_LOCKED STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_PFDENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PLLENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena4 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena5 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING "ON"
+// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC "5"
+// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC "@clk[4..0]"
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
+// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT_CLK_EXT VCC "c1"
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND "locked"
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll50_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
+
+
+//Copyright (C) 1991-2012 Altera Corporation
+//Your use of Altera Corporation's design tools, logic functions
+//and other software and tools, and its AMPP partner logic
+//functions, and any output files from any of the foregoing
+//(including device programming or simulation files), and any
+//associated documentation or information are expressly subject
+//to the terms and conditions of the Altera Program License
+//Subscription Agreement, Altera MegaCore Function License
+//Agreement, or other applicable license agreement, including,
+//without limitation, that your use is for the sole purpose of
+//programming logic devices manufactured by Altera and sold by
+//Altera or its authorized distributors. Please refer to the
+//applicable agreement for further details.
+
+
+// synopsys translate_off
+`timescale 1 ps / 1 ps
+// synopsys translate_on
+module de0_pll100 (
+ inclk0,
+ c0,
+ c1,
+ locked);
+
+ input inclk0;
+ output c0;
+ output c1;
+ output locked;
+
+ wire [4:0] sub_wire0;
+ wire sub_wire2;
+ wire [0:0] sub_wire6 = 1'h0;
+ wire [0:0] sub_wire3 = sub_wire0[0:0];
+ wire [1:1] sub_wire1 = sub_wire0[1:1];
+ wire c1 = sub_wire1;
+ wire locked = sub_wire2;
+ wire c0 = sub_wire3;
+ wire sub_wire4 = inclk0;
+ wire [1:0] sub_wire5 = {sub_wire6, sub_wire4};
+
+ altpll altpll_component (
+ .inclk (sub_wire5),
+ .clk (sub_wire0),
+ .locked (sub_wire2),
+ .activeclock (),
+ .areset (1'b0),
+ .clkbad (),
+ .clkena ({6{1'b1}}),
+ .clkloss (),
+ .clkswitch (1'b0),
+ .configupdate (1'b0),
+ .enable0 (),
+ .enable1 (),
+ .extclk (),
+ .extclkena ({4{1'b1}}),
+ .fbin (1'b1),
+ .fbmimicbidir (),
+ .fbout (),
+ .fref (),
+ .icdrclk (),
+ .pfdena (1'b1),
+ .phasecounterselect ({4{1'b1}}),
+ .phasedone (),
+ .phasestep (1'b1),
+ .phaseupdown (1'b1),
+ .pllena (1'b1),
+ .scanaclr (1'b0),
+ .scanclk (1'b0),
+ .scanclkena (1'b1),
+ .scandata (1'b0),
+ .scandataout (),
+ .scandone (),
+ .scanread (1'b0),
+ .scanwrite (1'b0),
+ .sclkout0 (),
+ .sclkout1 (),
+ .vcooverrange (),
+ .vcounderrange ());
+ defparam
+ altpll_component.bandwidth_type = "AUTO",
+ altpll_component.clk0_divide_by = 1,
+ altpll_component.clk0_duty_cycle = 50,
+ altpll_component.clk0_multiply_by = 2,
+ altpll_component.clk0_phase_shift = "0",
+ altpll_component.clk1_divide_by = 1,
+ altpll_component.clk1_duty_cycle = 50,
+ altpll_component.clk1_multiply_by = 2,
+ altpll_component.clk1_phase_shift = "5000",
+ altpll_component.compensate_clock = "CLK0",
+ altpll_component.inclk0_input_frequency = 20000,
+ altpll_component.intended_device_family = "Cyclone III",
+ altpll_component.lpm_hint = "CBX_MODULE_PREFIX=de0_pll100",
+ altpll_component.lpm_type = "altpll",
+ altpll_component.operation_mode = "NORMAL",
+ altpll_component.pll_type = "AUTO",
+ altpll_component.port_activeclock = "PORT_UNUSED",
+ altpll_component.port_areset = "PORT_UNUSED",
+ altpll_component.port_clkbad0 = "PORT_UNUSED",
+ altpll_component.port_clkbad1 = "PORT_UNUSED",
+ altpll_component.port_clkloss = "PORT_UNUSED",
+ altpll_component.port_clkswitch = "PORT_UNUSED",
+ altpll_component.port_configupdate = "PORT_UNUSED",
+ altpll_component.port_fbin = "PORT_UNUSED",
+ altpll_component.port_inclk0 = "PORT_USED",
+ altpll_component.port_inclk1 = "PORT_UNUSED",
+ altpll_component.port_locked = "PORT_USED",
+ altpll_component.port_pfdena = "PORT_UNUSED",
+ altpll_component.port_phasecounterselect = "PORT_UNUSED",
+ altpll_component.port_phasedone = "PORT_UNUSED",
+ altpll_component.port_phasestep = "PORT_UNUSED",
+ altpll_component.port_phaseupdown = "PORT_UNUSED",
+ altpll_component.port_pllena = "PORT_UNUSED",
+ altpll_component.port_scanaclr = "PORT_UNUSED",
+ altpll_component.port_scanclk = "PORT_UNUSED",
+ altpll_component.port_scanclkena = "PORT_UNUSED",
+ altpll_component.port_scandata = "PORT_UNUSED",
+ altpll_component.port_scandataout = "PORT_UNUSED",
+ altpll_component.port_scandone = "PORT_UNUSED",
+ altpll_component.port_scanread = "PORT_UNUSED",
+ altpll_component.port_scanwrite = "PORT_UNUSED",
+ altpll_component.port_clk0 = "PORT_USED",
+ altpll_component.port_clk1 = "PORT_USED",
+ altpll_component.port_clk2 = "PORT_UNUSED",
+ altpll_component.port_clk3 = "PORT_UNUSED",
+ altpll_component.port_clk4 = "PORT_UNUSED",
+ altpll_component.port_clk5 = "PORT_UNUSED",
+ altpll_component.port_clkena0 = "PORT_UNUSED",
+ altpll_component.port_clkena1 = "PORT_UNUSED",
+ altpll_component.port_clkena2 = "PORT_UNUSED",
+ altpll_component.port_clkena3 = "PORT_UNUSED",
+ altpll_component.port_clkena4 = "PORT_UNUSED",
+ altpll_component.port_clkena5 = "PORT_UNUSED",
+ altpll_component.port_extclk0 = "PORT_UNUSED",
+ altpll_component.port_extclk1 = "PORT_UNUSED",
+ altpll_component.port_extclk2 = "PORT_UNUSED",
+ altpll_component.port_extclk3 = "PORT_UNUSED",
+ altpll_component.self_reset_on_loss_lock = "OFF",
+ altpll_component.width_clock = 5;
+
+
+endmodule
+
+// ============================================================
+// CNX file retrieval info
+// ============================================================
+// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING "0"
+// Retrieval info: PRIVATE: BANDWIDTH STRING "1.000"
+// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING "MHz"
+// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING "Low"
+// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING "1"
+// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING "0"
+// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING "0"
+// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING "0"
+// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING "0"
+// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING "0"
+// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING "0"
+// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING "0"
+// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING "c0"
+// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING "c0"
+// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
+// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "2"
+// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC "2"
+// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
+// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING "50.00000000"
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "100.000000"
+// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING "100.000000"
+// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
+// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
+// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING "0"
+// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING "0"
+// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC "1048575"
+// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING "1"
+// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING "50.000"
+// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING "MHz"
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING "100.000"
+// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING "1"
+// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING "MHz"
+// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
+// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING "1"
+// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING "1"
+// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING "1"
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING "Not Available"
+// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
+// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING "deg"
+// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
+// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
+// Retrieval info: PRIVATE: MIRROR_CLK1 STRING "0"
+// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "4"
+// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC "4"
+// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
+// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "100.00000000"
+// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING "100.00000000"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "0"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING "0"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
+// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING "MHz"
+// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
+// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
+// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING "180.00000000"
+// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
+// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING "deg"
+// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
+// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING "0"
+// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC "0"
+// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING "inclk0"
+// Retrieval info: PRIVATE: RECONFIG_FILE STRING "de0_pll100.mif"
+// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING "0"
+// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING "0"
+// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING "0"
+// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING "0"
+// Retrieval info: PRIVATE: SPREAD_FREQ STRING "50.000"
+// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING "KHz"
+// Retrieval info: PRIVATE: SPREAD_PERCENT STRING "0.500"
+// Retrieval info: PRIVATE: SPREAD_USE STRING "0"
+// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
+// Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
+// Retrieval info: PRIVATE: STICKY_CLK1 STRING "1"
+// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
+// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
+// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
+// Retrieval info: PRIVATE: USE_CLK0 STRING "1"
+// Retrieval info: PRIVATE: USE_CLK1 STRING "1"
+// Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
+// Retrieval info: PRIVATE: USE_CLKENA1 STRING "0"
+// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
+// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
+// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
+// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
+// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
+// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "2"
+// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
+// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC "1"
+// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC "50"
+// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC "2"
+// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING "5000"
+// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
+// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "20000"
+// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
+// Retrieval info: CONSTANT: LPM_TYPE STRING "altpll"
+// Retrieval info: CONSTANT: OPERATION_MODE STRING "NORMAL"
+// Retrieval info: CONSTANT: PLL_TYPE STRING "AUTO"
+// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_ARESET STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKLOSS STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_FBIN STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_INCLK0 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_INCLK1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_LOCKED STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_PFDENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASEDONE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASESTEP STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_PLLENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANACLR STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANCLK STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDATA STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANDONE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANREAD STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_USED"
+// Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena4 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_clkena5 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk0 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk1 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk2 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: PORT_extclk3 STRING "PORT_UNUSED"
+// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING "OFF"
+// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC "5"
+// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC "@clk[4..0]"
+// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
+// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT_CLK_EXT VCC "c1"
+// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
+// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND "locked"
+// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
+// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
+// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
+// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
+// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100.v TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100.ppf TRUE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100.inc FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100.cmp FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100.bsf FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100_inst.v FALSE
+// Retrieval info: GEN_FILE: TYPE_NORMAL de0_pll100_bb.v TRUE
+// Retrieval info: LIB_FILE: altera_mf
+// Retrieval info: CBX_MODULE_PREFIX: ON
diff --git a/1801BM1_vm80a/wbc/rtl/de0/de0_top.v b/1801BM1_vm80a/wbc/rtl/de0/de0_top.v
new file mode 100644
index 0000000000000000000000000000000000000000..2b1103d27327a3c9b42065d1fa5a4bad4b537a5c
--- /dev/null
+++ b/1801BM1_vm80a/wbc/rtl/de0/de0_top.v
@@ -0,0 +1,503 @@
+//______________________________________________________________________________
+//
+// Top module for DE0 board based system
+
+//______________________________________________________________________________
+//
+// External oscillator clock, feeds the PLLs
+//
+`define OSC_CLOCK 50000000
+//
+// Global system clock
+//
+//`define SYS_CLOCK 50000000
+`define SYS_CLOCK 100000000
+//
+// Console baudrate
+//
+`define SYS_BAUD 115200
+//
+// Retro clock for non-turbo clock mode
+//
+`define CPU_CLOCK 2500000
+
+//______________________________________________________________________________
+//
+// Reset button debounce interval (in ms))
+//
+`define RESET_BUTTON_DEBOUNCE_MS 5
+//
+// Internal reset pulse width (in system clocks)
+//
+`define RESET_PULSE_WIDTH_CLK 7
+
+//______________________________________________________________________________
+//
+// Provides the 1 microseconds and 1 milliseconds strobes
+//
+module de0_timer #(parameter REFCLK=100000000, CPUCLK=2500000)
+(
+ input clk,
+ input rst,
+ output reg ena_f2,
+ output reg ena_us,
+ output reg ena_ms,
+ output reg irq_50
+);
+localparam F2_COUNTER_WIDTH = log2(REFCLK/CPUCLK);
+localparam US_COUNTER_WIDTH = log2(REFCLK/1000000);
+localparam MS_COUNTER_WIDTH = log2(1000);
+
+reg [F2_COUNTER_WIDTH-1:0] count_f2;
+reg [US_COUNTER_WIDTH-1:0] count_us;
+reg [MS_COUNTER_WIDTH-1:0] count_ms;
+reg [4:0] count_50;
+
+always @(posedge clk, posedge rst)
+begin
+ if (rst)
+ begin
+ ena_f2 <= 1'b0;
+ ena_us <= 1'b0;
+ ena_ms <= 1'b0;
+ count_f2 <= 0;
+ count_us <= 0;
+ count_ms <= 980;
+ count_50 <= 0;
+ end
+ else
+ begin
+ //
+ // F2 retro clock interval counter
+ // (use this simpler inmplementation,
+ // but the phase accumulator is better
+ // if more precise CPU clock desired)
+ //
+ if (count_f2 == ((REFCLK/CPUCLK)-1))
+ begin
+ ena_f2 <= 1'b1;
+ count_f2 <= 0;
+ end
+ else
+ begin
+ ena_f2 <= 1'b0;
+ count_f2 <= count_f2 + 1'b1;
+ end
+ //
+ // One microsecond interval counter
+ //
+ if (count_us == ((REFCLK/1000000)-1))
+ begin
+ ena_us <= 1'b1;
+ count_us <= 0;
+ end
+ else
+ begin
+ ena_us <= 1'b0;
+ count_us <= count_us + 1'b1;
+ end
+ //
+ // One millisecond interval counter
+ //
+ if (ena_us)
+ if (count_ms == (1000-1))
+ begin
+ ena_ms <= 1'b1;
+ count_ms <= 0;
+ end
+ else
+ begin
+ ena_ms <= 1'b0;
+ count_ms <= count_ms + 1'b1;
+ end
+ else
+ ena_ms <= 1'b0;
+ //
+ // 50Hz timer output
+ //
+ if (ena_ms)
+ if (count_50 == 19)
+ begin
+ irq_50 <= 1'b0;
+ count_50 <= 0;
+ end
+ else
+ begin
+ if (count_50 == 9)
+ irq_50 <= 1'b1;
+
+ count_50 <= count_50 + 1'b1;
+ end
+ end
+end
+
+function integer log2(input integer value);
+ begin
+ for (log2=0; value>0; log2=log2+1)
+ value = value >> 1;
+ end
+endfunction
+endmodule
+
+//______________________________________________________________________________
+//
+// Initialized RAM block - 16K x 8
+//
+module mem_wb
+(
+ input wb_clk_i,
+ input [13:0] wb_adr_i,
+ input [7:0] wb_dat_i,
+ output [7:0] wb_dat_o,
+ input wb_cyc_i,
+ input wb_we_i,
+ input wb_stb_i,
+ output wb_ack_o
+);
+reg ack;
+
+memini ram
+(
+ .clock(wb_clk_i),
+ .address(wb_adr_i[13:0]),
+ .wren(wb_we_i & wb_cyc_i & wb_stb_i),
+ .data(wb_dat_i),
+ .q(wb_dat_o)
+);
+
+assign wb_ack_o = wb_cyc_i & wb_stb_i & (ack | wb_we_i);
+always @ (posedge wb_clk_i) ack <= wb_cyc_i;
+endmodule
+
+//______________________________________________________________________________
+//
+// Top project module - instantiates the DE0 board itself
+//
+module de0
+(
+ input de0_clock_50, // clock input 50 MHz
+ input de0_clock_50_2, // clock input 50 MHz
+ //
+ input [2:0] de0_button, // push button[2:0]
+ //
+ input [9:0] de0_sw, // DPDT toggle switch[9:0]
+ output [7:0] de0_hex0, // seven segment digit 0
+ output [7:0] de0_hex1, // seven segment digit 1
+ output [7:0] de0_hex2, // seven segment digit 2
+ output [7:0] de0_hex3, // seven segment digit 3
+ output [9:0] de0_led, // LED green[9:0]
+ //
+ output de0_uart_txd, // UART transmitter
+ input de0_uart_rxd, // UART receiver
+ output de0_uart_cts, // UART clear to send
+ input de0_uart_rts, // UART request to send
+ //
+ inout [15:0] de0_dram_dq, // SDRAM data bus 16 bits
+ output [12:0] de0_dram_addr, // SDRAM address bus 13 bits
+ output de0_dram_ldqm, // SDRAM low-byte data mask
+ output de0_dram_udqm, // SDRAM high-byte data mask
+ output de0_dram_we_n, // SDRAM write enable
+ output de0_dram_cas_n, // SDRAM column address strobe
+ output de0_dram_ras_n, // SDRAM row address strobe
+ output de0_dram_cs_n, // SDRAM chip select
+ output [1:0] de0_dram_ba, // SDRAM bank address
+ output de0_dram_clk, // SDRAM clock
+ output de0_dram_cke, // SDRAM clock enable
+ //
+ inout [15:0] de0_fl_dq, // FLASH data bus 15 Bits
+ output [21:0] de0_fl_addr, // FLASH address bus 22 Bits
+ output de0_fl_we_n, // FLASH write enable
+ output de0_fl_rst_n, // FLASH reset
+ output de0_fl_oe_n, // FLASH output enable
+ output de0_fl_ce_n, // FLASH chip enable
+ output de0_fl_wp_n, // FLASH hardware write protect
+ output de0_fl_byte_n, // FLASH selects 8/16-bit mode
+ input de0_fl_rb, // FLASH ready/busy
+ //
+ output de0_lcd_blig, // LCD back light ON/OFF
+ output de0_lcd_rw, // LCD read/write select, 0 = write, 1 = read
+ output de0_lcd_en, // LCD enable
+ output de0_lcd_rs, // LCD command/data select, 0 = command, 1 = data
+ inout [7:0] de0_lcd_data, // LCD data bus 8 bits
+ //
+ inout de0_sd_mosi, // SD Card Data Output
+ inout de0_sd_miso, // SD Card Data Input
+ inout de0_sd_cmd, // SD Card Command Signal
+ output de0_sd_clk, // SD Card Clock
+ input de0_sd_wp_n, // SD Card Write Protect
+ //
+ inout de0_ps2_kbdat, // PS2 Keyboard Data
+ inout de0_ps2_kbclk, // PS2 Keyboard Clock
+ inout de0_ps2_msdat, // PS2 Mouse Data
+ inout de0_ps2_msclk, // PS2 Mouse Clock
+ //
+ output de0_vga_hs, // VGA H_SYNC
+ output de0_vga_vs, // VGA V_SYNC
+ output [3:0] de0_vga_r, // VGA Red[3:0]
+ output [3:0] de0_vga_g, // VGA Green[3:0]
+ output [3:0] de0_vga_b, // VGA Blue[3:0]
+ //
+ input [1:0] de0_gpio0_clkin, // GPIO Connection 0 Clock In Bus
+ output [1:0] de0_gpio0_clkout, // GPIO Connection 0 Clock Out Bus
+ inout [31:0] de0_gpio0_d, // GPIO Connection 0 Data Bus
+ //
+ input [1:0] de0_gpio1_clkin, // GPIO Connection 1 Clock In Bus
+ output [1:0] de0_gpio1_clkout, // GPIO Connection 1 Clock Out Bus
+ inout [31:0] de0_gpio1_d // GPIO Connection 1 Data Bus
+);
+
+//______________________________________________________________________________
+//
+wire [31:0] baud = 921600/`SYS_BAUD-1;
+wire clk50, pll_clk, pll_lock, ena_us, ena_ms, ena_f2;
+reg vm_turbo;
+
+wire wb_rst; //
+wire wb_clk; //
+wire [15:0] wb_adr; // master address out bus
+wire [7:0] wb_out; // master data out bus
+wire [7:0] wb_mux; // master data in bus
+wire wb_cyc; // master wishbone cycle
+wire wb_we; // master wishbone direction
+wire wb_stb; // master wishbone strobe
+wire wb_ack; // master wishbone acknowledgement
+wire [5:0] wb_tag; // 8080 tags
+ //
+wire [3:0] mx_stb; //
+wire [3:0] mx_ack; // system wishbone data mux
+wire [7:0] mx_dat[3:0]; //
+ //
+reg [7:0] hex0, hex1, hex2, hex3;
+reg [7:0] led;
+reg [7:0] rcnt = 8'h00;
+reg vm_irq;
+wire vm_inte;
+wire vm_cena;
+
+//______________________________________________________________________________
+//
+// Clock and Reset section
+//
+assign wb_clk = pll_clk;
+assign clk50 = de0_clock_50_2;
+assign wb_rst = ~(rcnt == 8'hFF);
+assign vm_cena = 1'b1; // vm_turbo | ena_f2;
+
+de0_pll100 corepll
+(
+ .inclk0(clk50),
+ .c0(pll_clk),
+ .locked(pll_lock)
+);
+
+always @(posedge wb_clk)
+begin
+ //
+ // SW0 selects turbo/original clock mode for the core
+ //
+ vm_turbo <= de0_sw[0];
+
+ if (~de0_button[2])
+ begin
+ vm_irq <= 0;
+ end
+ else
+ begin
+ if (ena_ms) vm_irq <= 1;
+ if (mx_ack[3]) vm_irq <= 0;
+ end
+
+ if (~de0_button[2] | ~pll_lock)
+ rcnt <= 8'h00;
+ else
+ if (rcnt != 8'hFF)
+ rcnt <= rcnt + 8'h01;
+end
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam uart.REFCLK = `SYS_CLOCK;
+`endif
+
+uart_wb uart
+(
+ .wb_clk_i(wb_clk),
+ .wb_rst_i(wb_rst),
+ .wb_adr_i(wb_adr[0]),
+ .wb_dat_i(wb_out),
+ .wb_dat_o(mx_dat[1]),
+ .wb_cyc_i(wb_cyc),
+ .wb_we_i(wb_we),
+ .wb_stb_i(mx_stb[1]),
+ .wb_ack_o(mx_ack[1]),
+
+ .tx_dat_o(de0_uart_txd),
+ .tx_cts_i(1'b0),
+ .rx_dat_i(de0_uart_rxd),
+ .rx_dtr_o(de0_uart_cts),
+
+// .tx_ready(),
+// .tx_empty(),
+// .rx_ready(),
+
+ .cfg_bdiv(baud[15:0]),
+ .cfg_nbit(2'b11),
+ .cfg_nstp(1'b1),
+ .cfg_pena(1'b0),
+ .cfg_podd(1'b0)
+);
+
+//______________________________________________________________________________
+//
+// Wishbone i8080 CPU
+//
+vm80_wb cpu
+(
+ .wb_clk_i(wb_clk),
+ .wb_rst_i(wb_rst),
+ .wb_adr_o(wb_adr),
+ .wb_dat_o(wb_out),
+ .wb_dat_i(wb_mux),
+ .wb_cyc_o(wb_cyc),
+ .wb_we_o(wb_we),
+ .wb_stb_o(wb_stb),
+ .wb_ack_i(wb_ack),
+ .wb_tgc_o(wb_tag),
+
+ .vm_cena(vm_cena),
+ .vm_irq(vm_irq),
+ .vm_inte(vm_inte)
+);
+
+mem_wb mem(
+ .wb_clk_i(wb_clk),
+ .wb_adr_i(wb_adr),
+ .wb_dat_i(wb_out),
+ .wb_dat_o(mx_dat[0]),
+ .wb_cyc_i(wb_cyc),
+ .wb_we_i(wb_we),
+ .wb_stb_i(mx_stb[0]),
+ .wb_ack_o(mx_ack[0])
+);
+
+//______________________________________________________________________________
+//
+always @(posedge wb_clk)
+begin
+ if (mx_stb[2])
+ begin
+ if (wb_adr == 16'hFFFB) led <= wb_out;
+ if (wb_adr == 16'hFFFC) hex0 <= wb_out;
+ if (wb_adr == 16'hFFFD) hex1 <= wb_out;
+ if (wb_adr == 16'hFFFE) hex2 <= wb_out;
+ if (wb_adr == 16'hFFFF) hex3 <= wb_out;
+ end
+end
+
+assign de0_hex0 = ~hex0;
+assign de0_hex1 = ~hex1;
+assign de0_hex2 = ~hex2;
+assign de0_hex3 = ~hex3;
+
+assign de0_led[7:0] = led;
+assign de0_led[9] = vm_turbo;
+assign de0_led[8] = wb_stb & wb_we;
+
+assign mx_ack[2] = mx_stb[2];
+assign mx_ack[3] = mx_stb[3];
+assign mx_dat[2] = {5'h00, de0_button[2:0]};
+assign mx_dat[3] = 8'hE7; // interrupt rst 4
+
+//______________________________________________________________________________
+//
+assign mx_stb[0] = wb_stb & wb_cyc & (wb_adr[15:14] == 2'b00) & ~wb_tag[4];
+assign mx_stb[1] = wb_stb & wb_cyc & (wb_adr[15:8] == 8'hFE) & ~wb_tag[4];
+assign mx_stb[2] = wb_stb & wb_cyc & (wb_adr[15:8] == 8'hFF) & ~wb_tag[4];
+assign mx_stb[3] = wb_stb & wb_cyc & wb_tag[4]; // interrupt acknowledge
+
+assign wb_ack = mx_ack[0] | mx_ack[1] | mx_ack[2] | mx_ack[3];
+assign wb_mux = (mx_stb[0] ? mx_dat[0] : 8'h00)
+ | (mx_stb[1] ? mx_dat[1] : 8'h00)
+ | (mx_stb[2] ? mx_dat[2] : 8'h00)
+ | (mx_stb[3] ? mx_dat[3] : 8'h00);
+
+//______________________________________________________________________________
+//
+`ifdef SYS_CLOCK
+defparam timer.REFCLK = `SYS_CLOCK;
+`endif
+
+`ifdef CPU_CLOCK
+defparam timer.CPUCLK = `CPU_CLOCK;
+`endif
+
+de0_timer timer
+(
+ .clk(wb_clk),
+ .rst(wb_rst),
+ .ena_f2(ena_f2),
+ .ena_us(ena_us),
+ .ena_ms(ena_ms)
+);
+
+//______________________________________________________________________________
+//
+// Temporary and debug assignments
+//
+// assign de0_uart_txd = 1'bz;
+// assign de0_uart_cts = 1'bz;
+
+assign de0_dram_dq = 16'hzzzz;
+assign de0_dram_addr = 13'h0000;
+assign de0_dram_ldqm = 1'b0;
+assign de0_dram_udqm = 1'b0;
+assign de0_dram_we_n = 1'b1;
+assign de0_dram_cas_n = 1'b1;
+assign de0_dram_ras_n = 1'b1;
+assign de0_dram_cs_n = 1'b1;
+
+assign de0_dram_ba[0] = 1'b0;
+assign de0_dram_ba[1] = 1'b0;
+assign de0_dram_clk = 1'b0;
+assign de0_dram_cke = 1'b0;
+
+assign de0_fl_dq = 16'hzzzz;
+assign de0_fl_addr = 22'hzzzzzz;
+assign de0_fl_we_n = 1'b1;
+assign de0_fl_rst_n = 1'b0;
+assign de0_fl_oe_n = 1'b1;
+assign de0_fl_ce_n = 1'b1;
+assign de0_fl_wp_n = 1'b0;
+assign de0_fl_byte_n = 1'b1;
+
+assign de0_lcd_data = 8'hzz;
+assign de0_lcd_blig = 1'b0;
+assign de0_lcd_rw = 1'b0;
+assign de0_lcd_en = 1'b0;
+assign de0_lcd_rs = 1'b0;
+
+assign de0_sd_clk = 1'h0;
+assign de0_sd_mosi = 1'hz;
+assign de0_sd_miso = 1'hz;
+assign de0_sd_cmd = 1'hz;
+
+assign de0_ps2_kbdat = 1'hz;
+assign de0_ps2_kbclk = 1'hz;
+assign de0_ps2_msdat = 1'hz;
+assign de0_ps2_msclk = 1'hz;
+
+assign de0_vga_hs = 1'b0;
+assign de0_vga_vs = 1'b0;
+assign de0_vga_r = 4'h0;
+assign de0_vga_g = 4'h0;
+assign de0_vga_b = 4'h0;
+
+assign de0_gpio0_clkout = 2'b00;
+assign de0_gpio1_clkout = 2'b00;
+assign de0_gpio0_d = 32'hzzzzzzzz;
+assign de0_gpio1_d = 32'hzzzzzzzz;
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/wbc/rtl/de0/de0_uart.v b/1801BM1_vm80a/wbc/rtl/de0/de0_uart.v
new file mode 100644
index 0000000000000000000000000000000000000000..4828ed86aa54ed63af6cc36d660ca78f685798be
--- /dev/null
+++ b/1801BM1_vm80a/wbc/rtl/de0/de0_uart.v
@@ -0,0 +1,376 @@
+//
+// Copyright (c) 2014-2015 by 1801BM1@gmail.com
+//
+// Universal Serial Asynchronous Receiver-Transmitter (simplified 8251)
+//______________________________________________________________________________
+//
+module uart_wb #(parameter REFCLK=50000000)
+(
+ input wb_clk_i, // system clock
+ input wb_rst_i, // peripheral reset
+ //
+ input [0:0] wb_adr_i, //
+ input [7:0] wb_dat_i, //
+ output reg [7:0] wb_dat_o, //
+ input wb_cyc_i, //
+ input wb_we_i, //
+ input wb_stb_i, //
+ output reg wb_ack_o, //
+ //
+ output tx_dat_o, // output serial data (txd)
+ input tx_cts_i, // enable transmitter (rts)
+ input rx_dat_i, // input serial data (rxd)
+ output rx_dtr_o, // receiver ready (cts)
+ //
+ output tx_ready_o, // tx ready request
+ output tx_empty_o, // tx empty request
+ output rx_ready_o, // rx ready request
+ //
+ input [15:0] cfg_bdiv, // baudrate divisor: (921600/baud)-1
+ input [1:0] cfg_nbit, // word length: 00-5, 01-6, 10-7, 11-8 bit
+ input cfg_nstp, // tx stop bits: 0 - 1 stop, 1 - 2 stop
+ input cfg_pena, // parity control enable
+ input cfg_podd // odd parity (complete to odd ones)
+);
+
+wire [63:0] add_arg;
+reg [16:0] add_reg;
+reg [15:0] baud_div;
+reg baud_x16;
+wire baud_ref;
+
+reg [1:0] tx_cts_reg;
+reg [1:0] rx_dat_reg;
+
+wire csr_wstb;
+wire rbr_rstb;
+wire thr_wstb;
+
+wire tx_par;
+reg [7:0] tx_thr;
+reg [9:0] tx_shr;
+reg [7:0] tx_bcnt;
+reg tx_busy;
+reg tx_ready, tx_empty, tx_break;
+
+wire rx_dat;
+reg [7:0] rx_rbr;
+reg [8:0] rx_shr;
+reg [7:0] rx_bcnt;
+reg rx_ready, rx_perr, rx_ovf, rx_break;
+wire rx_load, rx_stb;
+reg rx_frame, rx_start, rx_par;
+
+//______________________________________________________________________________
+//
+// Caution note: the arithmetic expressions should be calculated in 64-bit width
+//
+assign add_arg = (64'h0000000000100000 * 64'd921600)/REFCLK;
+assign baud_ref = add_reg[16];
+//
+// Phase accumulator to generate 921600 * 16 Hz reference clock strobe
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ add_reg <= 17'h00000;
+ else
+ begin
+ add_reg <= {1'b0, add_reg[15:0]} + add_arg[16:0];
+ end
+end
+//
+// Baud rate x16 generator
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ baud_div <= 16'h0000;
+ baud_x16 <= 1'b0;
+ end
+ else
+ begin
+ if (baud_ref)
+ if (baud_div == 16'h0000)
+ baud_div <= cfg_bdiv;
+ else
+ baud_div <= baud_div - 16'h0001;
+
+ baud_x16 <= baud_ref & (baud_div == 16'h0000);
+ end
+
+end
+
+//______________________________________________________________________________
+//
+assign csr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & wb_adr_i[0];
+assign thr_wstb = wb_cyc_i & wb_stb_i & wb_we_i & wb_ack_o & ~wb_adr_i[0];
+assign rbr_rstb = wb_cyc_i & wb_stb_i & ~wb_we_i & ~wb_ack_o & ~wb_adr_i[0];
+//
+// Output data multiplexed register
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ wb_dat_o <= 8'h00;
+ else
+ if (wb_cyc_i & wb_stb_i & ~wb_ack_o)
+ begin
+ if (wb_adr_i[0])
+ wb_dat_o <= (tx_ready << 7)
+ | (tx_break << 6)
+ | (tx_empty << 5)
+ | (rx_ready << 3)
+ | (rx_break << 2)
+ | (rx_perr << 1)
+ | (rx_ovf << 0);
+ else
+ wb_dat_o <= rx_rbr;
+ end
+end
+
+always @(posedge wb_clk_i)
+ wb_ack_o <= wb_cyc_i & wb_stb_i & ~wb_ack_o;
+
+//
+// Control register bits
+//
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ tx_break <= 1'b0;
+ else
+ if (csr_wstb) tx_break <= wb_dat_i[6];
+end
+
+//______________________________________________________________________________
+//
+// Interrupts
+//
+assign tx_ready_o = tx_ready;
+assign tx_empty_o = tx_empty;
+assign rx_ready_o = rx_ready;
+
+//______________________________________________________________________________
+//
+// Metastability issues
+//
+always @(posedge wb_clk_i)
+begin
+ tx_cts_reg[0] <= ~tx_cts_i;
+ tx_cts_reg[1] <= tx_cts_reg[0];
+
+ rx_dat_reg[0] <= rx_dat_i;
+ rx_dat_reg[1] <= rx_dat_reg[0];
+end
+
+//______________________________________________________________________________
+//
+// Transmitter unit
+//
+assign tx_par = tx_thr[0] ^ tx_thr[1] ^ tx_thr[2] ^ tx_thr[3] ^ tx_thr[4]
+ ^ (tx_thr[5] & (cfg_nbit >= 2'b01))
+ ^ (tx_thr[6] & (cfg_nbit >= 2'b10))
+ ^ (tx_thr[7] & (cfg_nbit == 2'b11))
+ ^ cfg_podd;
+assign tx_dat_o = tx_shr[0] & ~tx_break;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ tx_ready <= 1'b1;
+ tx_empty <= 1'b1;
+ tx_shr <= 10'o1777;
+ tx_busy <= 1'b0;
+ tx_bcnt <= 8'b00000000;
+ tx_thr <= 8'b00000000;
+ end
+ else
+ begin
+ tx_empty <= tx_ready & ~tx_busy;
+ //
+ // Transmitter hold register write
+ //
+ if (thr_wstb)
+ begin
+ tx_ready <= 1'b0;
+ tx_thr <= wb_dat_i[7:0];
+ end
+
+ if (baud_x16)
+ begin
+ //
+ // Transmit process
+ //
+ if (tx_busy)
+ begin
+ if (tx_bcnt == 8'b00000001)
+ tx_busy <= 1'b0;
+
+ if (tx_bcnt != 8'b00000000)
+ tx_bcnt <= tx_bcnt - 8'b00000001;
+
+ if (tx_bcnt[3:0] == 4'b0000)
+ tx_shr <= {1'b1, tx_shr[9:1]};
+ end
+
+ //
+ // Starting new word transmit
+ //
+ if (~tx_ready & ~tx_busy & tx_cts_reg[1])
+ begin
+ tx_busy <= 1'b1;
+ tx_ready <= ~thr_wstb;
+ tx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena} + {3'b000, cfg_nstp}, 4'b1111};
+
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {3'b111, tx_par, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {2'b11, tx_par, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {1'b1, tx_par, tx_thr[6:0], 1'b0};
+ default: tx_shr <= { tx_par, tx_thr[7:0], 1'b0};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: tx_shr <= {4'b1111, tx_thr[4:0], 1'b0};
+ 2'b01: tx_shr <= {3'b111, tx_thr[5:0], 1'b0};
+ 2'b10: tx_shr <= {2'b11, tx_thr[6:0], 1'b0};
+ default: tx_shr <= {1'b1, tx_thr[7:0], 1'b0};
+ endcase
+ end
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// Receiver unit
+//
+assign rx_dtr_o = rx_ready;
+assign rx_dat = rx_dat_reg[1];
+
+assign rx_load = rx_stb & (rx_bcnt[7:4] == 4'b0000);
+assign rx_stb = (rx_bcnt[3:0] == 4'b0001) & baud_x16;
+
+always @(posedge wb_clk_i or posedge wb_rst_i)
+begin
+ if (wb_rst_i)
+ begin
+ rx_ready <= 1'b0;
+ rx_break <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_start <= 1'b0;
+ rx_par <= 1'b0;
+ rx_rbr <= 8'b00000000;
+ rx_shr <= 9'b00000000;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ if (rx_load)
+ begin
+ rx_ready <= 1'b1;
+ case(cfg_nbit)
+ 2'b00: rx_rbr <= {3'b000, rx_shr[4:0]};
+ 2'b01: rx_rbr <= {2'b00, rx_shr[5:0]};
+ 2'b10: rx_rbr <= {1'b0, rx_shr[6:0]};
+ default: rx_rbr <= rx_shr[7:0];
+ endcase
+ rx_perr <= rx_par;
+ rx_ovf <= rx_ready;
+ rx_break <= ~rx_dat;
+ end
+ else
+ if (rbr_rstb)
+ begin
+ rx_ready <= 1'b0;
+ rx_perr <= 1'b0;
+ rx_ovf <= 1'b0;
+ end
+
+ if (baud_x16)
+ begin
+ if (~rx_frame)
+ //
+ // Waiting for start bit
+ //
+ if (~rx_dat)
+ begin
+ rx_par <= cfg_pena & cfg_podd;
+ rx_start <= 1'b1;
+ rx_frame <= 1'b1;
+ rx_bcnt <= {4'b0110 + {2'b00, cfg_nbit} + {3'b000, cfg_pena}, 4'b0111};
+ end
+ else
+ begin
+ rx_start <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ begin
+ //
+ // Receiving frame
+ //
+ if (rx_bcnt != 8'b00000000)
+ rx_bcnt <= rx_bcnt - 8'b00000001;
+ //
+ // Start bit monitoring
+ //
+ if (rx_start)
+ begin
+ if (rx_dat)
+ begin
+ //
+ // Spurrious start bit
+ //
+ rx_start <= 1'b0;
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ else
+ if (rx_bcnt[3:0] == 4'b0010)
+ rx_start <= 1'b0;
+ end
+ else
+ begin
+ //
+ // Receiving data
+ //
+ if (rx_stb)
+ begin
+ rx_par <= (rx_par ^ rx_dat) & cfg_pena;
+ if (cfg_pena)
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b01: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ 2'b10: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ default: rx_shr <= {rx_dat, rx_shr[8:1]};
+ endcase
+ else
+ case(cfg_nbit)
+ 2'b00: rx_shr <= {4'b0000, rx_dat, rx_shr[4:1]};
+ 2'b01: rx_shr <= {3'b000, rx_dat, rx_shr[5:1]};
+ 2'b10: rx_shr <= {2'b00, rx_dat, rx_shr[6:1]};
+ default: rx_shr <= {1'b0, rx_dat, rx_shr[7:1]};
+ endcase
+ if (rx_load & rx_dat)
+ begin
+ //
+ // Stop bit detected
+ //
+ rx_frame <= 1'b0;
+ rx_bcnt <= 8'b00000000;
+ end
+ end
+ if ((rx_bcnt == 8'b00000000) & rx_dat)
+ rx_frame <= 1'b0;
+ end
+ end
+ end
+ end
+end
+endmodule
diff --git a/1801BM1_vm80a/wbc/rtl/vm80_wb.v b/1801BM1_vm80a/wbc/rtl/vm80_wb.v
new file mode 100644
index 0000000000000000000000000000000000000000..d0649bda2743a1563609c07060da40cb653f3e4e
--- /dev/null
+++ b/1801BM1_vm80a/wbc/rtl/vm80_wb.v
@@ -0,0 +1,779 @@
+//
+// Copyright (c) 2014-2018 by 1801BM1@gmail.com
+// Licensed under CC-BY 3.0 (https://creativecommons.org/licenses/by/3.0/)
+//
+// Wishbone compatibe version of revengineered 580BM80A/i8080A
+//______________________________________________________________________________
+//
+module vm80_wb
+(
+ input wb_clk_i, // module clock
+ input wb_rst_i, // module reset
+ //
+ output[15:0] wb_adr_o, // address bus outputs
+ output[7:0] wb_dat_o, // data bus output
+ input [7:0] wb_dat_i, // data bus input
+ output wb_cyc_o, // master wishbone cycle
+ output wb_we_o, // master wishbone direction
+ output wb_stb_o, // master wishbone strobe
+ input wb_ack_i, // master wishbone acknowledge
+ //
+ // Wishbone cycle tags
+ output [5:0] wb_tgc_o, // [0] M1 command fetch
+ // [1] IO space tag
+ // [2] Write cycle tag
+ // [3] Stack operation
+ // [4] Interrupt acknowledge
+ // [5] Processor halted
+ //
+ input vm_cena, // clock enable
+ input vm_irq, // interrupt request
+ output vm_inte // interrupt enable flag
+);
+
+//______________________________________________________________________________
+//
+wire clk; // global module clock
+wire ena; // global clock enable
+reg reset; // latched module reset
+
+reg [15:0] a; // output address buffer
+wire [7:0] d; // internal data bus mux
+reg [7:0] db; // data output buffer
+reg [7:0] di; // data input buffer
+
+reg dbin_rd, wb_cyc;
+reg wb_stb, wb_we;
+wire ready, dad_m45;
+wire io_rdy, io_ena;
+reg [2:0] io_cnt;
+
+reg [15:0] r16_pc, r16_hl, r16_de, r16_bc, r16_sp, r16_wz;
+wire [15:0] mxi, mxo;
+wire mxr0, mxr1, mxr2, mxr3, mxr4, mxr5;
+wire mxwh, mxwl, mxrh, mxrl, mxw16, mxwadr;
+wire dec16, inc16, iad16;
+reg xchg_dh, xchg_tt;
+wire t1467, t1513, t1514, t1519;
+
+wire sy_wo_n, sy_stack;
+
+reg t1, t2, tw, t3, t4, t5;
+reg m1, m2, m3, m4, m5;
+
+wire thalt, start, eom, ms0, ms1, m789, m836;
+reg intr, inta, inte, minta;
+wire irq;
+
+reg [7:0] i;
+wire i25, i14, i03, imx, acc_sel;
+wire id_op, id_io, id_in, id_popsw, id_pupsw,
+ id_nop, id_lxi, id_inx, id_inr, id_dcr, id_idr, id_mvi, id_dad,
+ id_dcx, id_opa, id_idm, id_hlt, id_mov, id_opm, id_pop, id_rst,
+ id_cxx, id_jxx, id_rxx, id_ret, id_jmp, id_opi, id_out, id_11x,
+ id_rlc, id_rxc, id_rar, id_sha, id_daa, id_cma, id_stc, id_cmc,
+ id_add, id_adc, id_sub, id_sbb, id_ana, id_xra, id_ora, id_cmp,
+ id_lsax, id_mvim, id_shld, id_lhld, id_mvmr, id_mvrm, id_push,
+ id_xthl, id_sphl, id_pchl, id_xchg, id_call, id_eidi, id_stlda;
+
+wire id80, id81, id82, id83, id84, id85, id86, id00, id01,
+ id02, id03, id04, id05, id06, id07, id08, id09, id10;
+wire goto, jmpflag;
+reg jmptake, tree1t;
+wire tree1, tree2;
+
+reg [7:0] xr, r, acc;
+wire [7:0] x, s, c;
+wire cl, ch, daa, daa_6x, daa_x6;
+wire alu_xout, alu_xwr, alu_xrd, alu_ald, alu_awr, alu_ard,
+ alu_rld, alu_r00, alu_rwr, alu_srd, alu_zrd, alu_pha;
+
+reg psw_z, psw_s, psw_p, psw_c, psw_ac, tmp_c;
+wire psw_ld, psw_wr, psw_oe;
+
+//_____________________________________________________________________________
+//
+// Wishbone logic
+//
+assign clk = wb_clk_i;
+//
+// Latch the external reset (can has the huge input tree)
+//
+always @(posedge clk) reset <= wb_rst_i;
+
+//
+// We cannot stop the T-state machine while writing, no present written data on the bus,
+// we should wait, but the state machine goes to T3 (at that data and write strobe are)
+// and does not wait there (8080 waits on the transfer T2->T3). So we have to use
+// the global clock enable.
+//
+assign io_ena = ~(wb_cyc_o & wb_we_o & wb_stb_o & ~wb_ack_i);
+assign io_rdy = ~sy_wo_n | (wb_cyc_o & wb_stb_o & wb_ack_i);
+//
+// Use former ready external input to stall the CPU while reading
+//
+assign dad_m45 = (m4 | m5) & id_dad;
+assign ready = dad_m45 | io_rdy;
+//
+// Implement wishbone output registers
+//
+assign wb_adr_o = a;
+assign wb_dat_o = db;
+assign wb_cyc_o = wb_cyc;
+assign wb_stb_o = wb_stb;
+assign wb_we_o = wb_we;
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ begin
+ wb_cyc <= 1'b0;
+ wb_stb <= 1'b0;
+ wb_we <= 1'b0;
+ end
+ else
+ if (wb_ack_i & wb_stb_o & wb_cyc)
+ begin
+ wb_cyc <= 1'b0;
+ wb_stb <= 1'b0;
+ wb_we <= 1'b0;
+ end
+ else
+ begin
+ wb_we <= ~sy_wo_n;
+
+ if ( (t1 & ~dad_m45 & ~sy_wo_n)
+ | (t1 & sy_wo_n))
+ wb_cyc <= 1'b1;
+
+ if ( (t2 & ~dad_m45 & ~sy_wo_n)
+ | (t1 & sy_wo_n))
+ wb_stb <= 1'b1;
+ end
+end
+
+always @(posedge clk)
+if (ena)
+begin
+ dbin_rd <= (t2 | tw) & sy_wo_n & (m1 | ~id_hlt);
+ if ((t2 | tw) & sy_wo_n) di <= wb_dat_i;
+ if (~sy_wo_n & t2) db <= d;
+end
+
+//______________________________________________________________________________
+//
+// Clock moderator for slow origial speed emulation, vm_cena is used for
+// The entire core stopped before entering the T1 tick
+//
+assign ena = ~(~io_ena | eom & (io_cnt != 3'b000));
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ io_cnt <= 3'b000;
+ else
+ begin
+ if (~ena & vm_cena & (io_cnt != 3'b000))
+ io_cnt <= io_cnt - 3'b001;
+
+ if (ena & ~vm_cena & (io_cnt != 3'b111))
+ io_cnt <= io_cnt + 3'b001;
+ end
+end
+
+//______________________________________________________________________________
+//
+// Internal data bus mux
+//
+assign d[7] = ~alu_zrd &
+ ( dbin_rd & di[7]
+ | mxrl & mxo[7]
+ | mxrh & mxo[15]
+ | alu_xrd & xr[7]
+ | alu_ard & acc[7]
+ | alu_srd & s[7]
+ | psw_oe & psw_s);
+
+assign d[6] = ~alu_zrd &
+ ( dbin_rd & di[6]
+ | mxrl & mxo[6]
+ | mxrh & mxo[14]
+ | alu_xrd & xr[6]
+ | alu_ard & acc[6]
+ | alu_srd & s[6]
+ | psw_oe & psw_z);
+
+assign d[5] = ~alu_zrd &
+ ( dbin_rd & di[5]
+ | mxrl & mxo[5]
+ | mxrh & mxo[13]
+ | alu_xrd & xr[5]
+ | alu_ard & acc[5]
+ | alu_srd & s[5]
+ | psw_oe & 1'b0);
+
+assign d[4] = ~alu_zrd &
+ ( dbin_rd & di[4]
+ | mxrl & mxo[4]
+ | mxrh & mxo[12]
+ | alu_xrd & xr[4]
+ | alu_ard & acc[4]
+ | alu_srd & s[4]
+ | psw_oe & psw_ac);
+
+assign d[3] = ~alu_zrd &
+ ( dbin_rd & di[3]
+ | mxrl & mxo[3]
+ | mxrh & mxo[11]
+ | alu_xrd & xr[3]
+ | alu_ard & acc[3]
+ | alu_srd & s[3]
+ | psw_oe & 1'b0);
+
+assign d[2] = ~alu_zrd &
+ ( dbin_rd & di[2]
+ | mxrl & mxo[2]
+ | mxrh & mxo[10]
+ | alu_xrd & xr[2]
+ | alu_ard & acc[2]
+ | alu_srd & s[2]
+ | psw_oe & psw_p);
+
+assign d[1] = ~alu_zrd &
+ ( dbin_rd & di[1]
+ | mxrl & mxo[1]
+ | mxrh & mxo[9]
+ | alu_xrd & xr[1]
+ | alu_ard & acc[1]
+ | alu_srd & s[1]
+ | psw_oe & 1'b1);
+
+assign d[0] = ~alu_zrd &
+ ( dbin_rd & di[0]
+ | mxrl & mxo[0]
+ | mxrh & mxo[8]
+ | alu_xrd & xr[0]
+ | alu_ard & acc[0]
+ | alu_srd & s[0]
+ | psw_oe & psw_c);
+
+//______________________________________________________________________________
+//
+// register unit - 6 16-bit registers
+//
+// r0 - pc
+// r1 - hl, de (runtime alias via xchg_dh flag)
+// r2 - de, hl (runtime alias via xchg_dh flag)
+// r3 - bc
+// r4 - sp
+// r5 - wz
+//
+assign t1467 = tree1 | (id04 & t4 & ~id_xthl);
+
+assign t1513 = (t4 & id07)
+ | id07 & ((t1 & (m4 | m5)) | (t3 & (m2 | m3)) | t5);
+
+assign t1514 = (t4 & id08)
+ | t1 & m4 & id_lsax
+ | t2 & id10 & ~sy_wo_n
+ | t3 & id10 & sy_wo_n & (m4 | m5)
+ | t5 & id08 & m1;
+assign t1519 = tree2 | (id00 & t4 & ~id_xthl);
+
+assign mxi = inc16 ? (a + 16'h0001)
+ : dec16 ? (a - 16'h0001)
+ : a;
+
+assign inc16 = iad16 & ~dec16;
+assign dec16 = iad16 & id05 & (t4 | t5 | m4 | m5);
+assign iad16 = ~(id00 & (t4 | t5)) & (~minta | m5 | t4 | t5 | (m4 & ~id02));
+
+assign mxw16 = t2 & ( (m1 | m2)
+ | (m3 & ~id_xthl)
+ | ((m4 | m5) & ~id_dad & ~id09))
+ | t3 & m4 & id09
+ | t5 & (m5 | (m1 & ~id08));
+
+assign mxwadr = t4 & ~id_dad & ~id_hlt
+ | t1 & (m1 | m2 | m3 | ((m4 | m5) & ~id_hlt & ~id_dad));
+
+
+assign mxrh = id08 & t4 & ~i03
+ | (t1 | t2) & m5 & id_dad
+ | t2 & ((m5 & id_shld) | (m4 & id03));
+
+assign mxrl = id08 & t4 & i03
+ | (t1 | t2) & m4 & id_dad
+ | t2 & ((m4 & id_shld) | (m5 & id03));
+
+assign mxwh = reset
+ | t3 & (m1 | m3 | (m4 & id_io) | (m5 & id06))
+ | ((t3 & m4) | (t5 & m1)) & id08 & ~i03;
+
+assign mxwl = reset
+ | t3 & (m2 | (m4 & id06) | (m5 & id_rst))
+ | ((t3 & m4) | (t5 & m1)) & id08 & i03;
+
+assign mxr0 = t1 & ( (m1 & ~goto)
+ | (m2 & ~id_xthl)
+ | (m3 & ~id_xthl)
+ | (m4 & id02))
+ | t2 & ( m1
+ | (m2 & ~id_xthl)
+ | (m3 & ~id_xthl)
+ | (m4 & (id02 | id_rst | id_cxx | id_call))
+ | (m5 & (id_rst | id_cxx | id_call)))
+ | t3 & ( (m4 & (id_ret | id_rxx))
+ | (m5 & (id_ret | id_rxx)))
+ | t5 & id_pchl;
+
+assign mxr1 = xchg_dh & (((t1513 | t1514) & (~i14 & i25)) | t1519)
+ | ~xchg_dh & (t1513 | t1514) & (i14 & ~i25);
+
+assign mxr2 = xchg_dh & (t1513 | t1514) & (i14 & ~i25)
+ | ~xchg_dh & (((t1513 | t1514) & (~i14 & i25)) | t1519);
+
+assign mxr3 = (t1513 | t1514) & (~i14 & ~i25);
+assign mxr4 = t1467 | (t1513 & i14 & i25);
+assign mxr5 = ~(t1467 | t1513 | t1514 | t1519 | mxr0);
+
+always @ (posedge clk)
+if (ena)
+begin
+ xchg_tt <= id_xchg & t2;
+ xchg_dh <= ~reset & ((xchg_tt & ~(id_xchg & t2)) ? ~xchg_dh : xchg_dh);
+end
+
+assign mxo = (mxr0 ? r16_pc : 16'h0000)
+ | (mxr1 ? r16_hl : 16'h0000)
+ | (mxr2 ? r16_de : 16'h0000)
+ | (mxr3 ? r16_bc : 16'h0000)
+ | (mxr4 ? r16_sp : 16'h0000)
+ | (mxr5 ? r16_wz : 16'h0000);
+
+always @ (posedge clk)
+if (ena)
+begin
+ if (mxwadr) a <= mxo;
+ if (mxw16)
+ begin
+ if (mxr0) r16_pc <= mxi;
+ if (mxr1) r16_hl <= mxi;
+ if (mxr2) r16_de <= mxi;
+ if (mxr3) r16_bc <= mxi;
+ if (mxr4) r16_sp <= mxi;
+ if (mxr5) r16_wz <= mxi;
+ end
+ else
+ begin
+ if (mxwl)
+ begin
+ if (mxr0) r16_pc[7:0] <= d;
+ if (mxr1) r16_hl[7:0] <= d;
+ if (mxr2) r16_de[7:0] <= d;
+ if (mxr3) r16_bc[7:0] <= d;
+ if (mxr4) r16_sp[7:0] <= d;
+ if (mxr5) r16_wz[7:0] <= d;
+ end
+ if (mxwh)
+ begin
+ if (mxr0) r16_pc[15:8] <= d;
+ if (mxr1) r16_hl[15:8] <= d;
+ if (mxr2) r16_de[15:8] <= d;
+ if (mxr3) r16_bc[15:8] <= d;
+ if (mxr4) r16_sp[15:8] <= d;
+ if (mxr5) r16_wz[15:8] <= d;
+ end
+ end
+end
+
+//______________________________________________________________________________
+//
+// processor state
+//
+assign wb_tgc_o[0] = m1; // command fetch
+assign wb_tgc_o[1] = m5 & (id_in | id_out); // in/out transfer
+assign wb_tgc_o[2] = ~sy_wo_n; // write operation
+assign wb_tgc_o[3] = t1 ? tree1 : tree1t; // stack operation
+assign wb_tgc_o[4] = inta; // interrupt acknowledge
+assign wb_tgc_o[5] = id_hlt; // processor halted
+
+assign sy_wo_n = m1 | m2 | m3 | (((m4 & ~id86) | (m5 & ~id85)) & ~dad_m45);
+assign sy_stack = t1 & tree1
+ | t3 & m3 & id_cxx & ~jmptake
+ | t5 & m1 & id_rxx & ~jmptake;
+
+always @(posedge clk)
+ if (ena & t1)
+ tree1t <= tree1;
+
+//______________________________________________________________________________
+//
+// Ticks state machine
+//
+assign thalt = ~m1 & id_hlt;
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ begin
+ t1 <= 1'b1;
+ t2 <= 1'b0;
+ tw <= 1'b0;
+ t3 <= 1'b0;
+ t4 <= 1'b0;
+ t5 <= 1'b0;
+ end
+ else
+ if (ena)
+ begin
+ t1 <= start;
+ t2 <= ~start & t1;
+ tw <= ~start & (t2 | tw) & (~ready | thalt);
+ t3 <= ~start & (t2 | tw) & ready & ~thalt;
+ t4 <= ~start & t3 & ms0 & ~ms1;
+ t5 <= ~start & t4 & ms0 & ~ms1;
+ end
+end
+
+//______________________________________________________________________________
+//
+assign start = reset | eom | (id_hlt & minta & m4);
+assign m836 = m1 & id82;
+assign m789 = (id84 & m3) | (id83 & ~id_mvim & m4) | m5;
+assign eom = t5
+ | t4 & m1 & id80
+ | t3 & m2
+ | t3 & m3
+ | t3 & m4
+ | t3 & m5 & ~id_xthl;
+
+assign ms0 = ~reset & (~(minta & m4) | ~id_hlt) & ~(sy_stack & ~t1) & ~(eom & ~m836);
+assign ms1 = ~reset & (~(minta & m4) | ~id_hlt) & ~(sy_stack & ~t1) & ~((m789 | id81) & ~m836) & eom;
+
+//______________________________________________________________________________
+//
+// Processor M-cycles state machine
+//
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ begin
+ m1 <= 1'b1;
+ m2 <= 1'b0;
+ m3 <= 1'b0;
+ m4 <= 1'b0;
+ m5 <= 1'b0;
+ end
+ else
+ if (ena)
+ begin
+ m1 <= (~ms0 & ~ms1) | (~ms1 & m1);
+ m2 <= (~ms0 | ~ms1) & ((ms0 & m2) | (ms1 & m1));
+ m3 <= (ms0 & m3) | (ms1 & m2);
+ m4 <= (ms0 & m4) | (ms1 & m3) | (ms0 & ms1);
+ m5 <= (ms0 & m5) | (ms1 & m4);
+ end
+end
+
+//______________________________________________________________________________
+//
+// Interrupt logic
+// Interrupt acknowledge in the halt mode and other stuff removed
+//
+assign irq = intr & inte & ~reset;
+assign vm_inte = inte;
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ begin
+ inta <= 0;
+ inte <= 0;
+ minta <= 0;
+ end
+ else
+ if (ena)
+ begin
+ intr <= vm_irq;
+
+ if (irq & (~ms0 & ~ms1 | tw & id_hlt) & ~id_eidi) inta <= 1;
+ if (~intr | id_eidi | (t5 & id_rst)) inta <= 0;
+
+ if (inta) minta <= 1;
+ if (~ms0 & ~ms1) minta <= 0;
+
+ if (t1 & id_eidi) inte <= i[3];
+ if (t1 & inta) inte <= 0;
+ end
+end
+//______________________________________________________________________________
+//
+// Instruction register and decoder
+//
+function cmp
+(
+ input [7:0] i,
+ input [7:0] c,
+ input [7:0] m
+);
+ cmp = &(~(i ^ c) | m);
+endfunction
+
+assign imx = ~(id_op | (id_mov & t4));
+assign i25 = imx ? i[5] : i[2];
+assign i14 = imx ? i[4] : i[1];
+assign i03 = imx ? i[3] : i[0];
+assign acc_sel = imx ? (i[5:3] == 3'b111) : (i[2:0] == 3'b111);
+
+assign jmpflag = (psw_c & i14 & ~i25) // Intel original: d[0] instead of psw_c
+ | (psw_p & ~i14 & i25) // Intel original: d[2] instead of psw_p
+ | (psw_z & ~i14 & ~i25) // Intel original: d[6] instead of psw_z
+ | (psw_s & i14 & i25); // Intel original: d[7] instead of psw_s
+
+
+always @(posedge clk or posedge reset)
+begin
+ if (reset)
+ i <= 8'h00;
+ else
+ if (ena & m1 & t3)
+ i <= di;
+end
+
+assign goto = id_rst | id_jmp | id_call | (jmptake & (id_cxx | id_jxx));
+
+assign tree1 = (t1 & ((m2 & id00)
+ | (m3 & id00)
+ | (m4 & (id01 | id04))
+ | (m5 & (id01 | id04)))
+ | t2 & ( (m2 & id00)
+ | (m4 & id01)
+ | (m5 & id01))
+ | t3 & ( (m4 & (id04 | id_sphl)))
+ | t5 & ( (m1 & (id04 | id_sphl)))) & ~(~jmptake & id_cxx & t5);
+
+assign tree2 = t1 & ( (m4 & (id_mov | id_idr | id_op))
+ | (m5 & id08))
+ | t2 & ( (m4 & (id_shld | id00 | id_dad))
+ | (m5 & (id_shld | id00 | id_dad)))
+ | t3 & ( (m4 & (id_lhld | id_dad))
+ | (m5 & (id_lhld | id_dad)))
+ | t5 & m5;
+
+always @(posedge clk)
+ if (ena & t4)
+ jmptake <= i03 ? jmpflag : ~jmpflag;
+
+assign id_nop = cmp(i, 8'b00xxx000, 8'b00111000);
+assign id_lxi = cmp(i, 8'b00xx0001, 8'b00110000);
+assign id_lsax = cmp(i, 8'b000xx010, 8'b00011000);
+assign id_inx = cmp(i, 8'b00xx0011, 8'b00110000);
+assign id_inr = cmp(i, 8'b00xxx100, 8'b00111000);
+assign id_dcr = cmp(i, 8'b00xxx101, 8'b00111000);
+assign id_idr = cmp(i, 8'b00xxx10x, 8'b00111001);
+assign id_mvi = cmp(i, 8'b00xxx110, 8'b00111000);
+assign id_dad = cmp(i, 8'b00xx1001, 8'b00110000);
+assign id_dcx = cmp(i, 8'b00xx1011, 8'b00110000);
+assign id_opa = cmp(i, 8'b00xxx111, 8'b00111000);
+assign id_idm = cmp(i, 8'b0011010x, 8'b00000001);
+assign id_stlda = cmp(i, 8'b0011x010, 8'b00001000);
+assign id_mvim = cmp(i, 8'b00110110, 8'b00000000);
+assign id_shld = cmp(i, 8'b00100010, 8'b00000000);
+assign id_lhld = cmp(i, 8'b00101010, 8'b00000000);
+assign id_mvmr = cmp(i, 8'b01110xxx, 8'b00000111) & ~id_hlt;
+assign id_mvrm = cmp(i, 8'b01xxx110, 8'b00111000) & ~id_hlt;
+assign id_hlt = cmp(i, 8'b01110110, 8'b00000000);
+assign id_mov = cmp(i, 8'b01xxxxxx, 8'b00111111);
+assign id_op = cmp(i, 8'b10xxxxxx, 8'b00111111);
+assign id_opm = cmp(i, 8'b10xxx110, 8'b00111000);
+assign id_pop = cmp(i, 8'b11xx0001, 8'b00110000);
+assign id_push = cmp(i, 8'b11xx0101, 8'b00110000);
+assign id_rst = cmp(i, 8'b11xxx111, 8'b00111000);
+assign id_xthl = cmp(i, 8'b11100011, 8'b00000000);
+assign id_sphl = cmp(i, 8'b11111001, 8'b00000000);
+assign id_pchl = cmp(i, 8'b11101001, 8'b00000000);
+assign id_xchg = cmp(i, 8'b11101011, 8'b00000000);
+assign id_cxx = cmp(i, 8'b11xxx100, 8'b00111000);
+assign id_jxx = cmp(i, 8'b11xxx010, 8'b00111000);
+assign id_rxx = cmp(i, 8'b11xxx000, 8'b00111000);
+assign id_ret = cmp(i, 8'b110x1001, 8'b00010000);
+assign id_call = cmp(i, 8'b11xx1101, 8'b00110000);
+assign id_eidi = cmp(i, 8'b1111x011, 8'b00001000);
+assign id_jmp = cmp(i, 8'b1100x011, 8'b00001000);
+assign id_io = cmp(i, 8'b1101x011, 8'b00001000);
+assign id_opi = cmp(i, 8'b11xxx110, 8'b00111000);
+assign id_in = cmp(i, 8'b11011011, 8'b00000000);
+assign id_popsw = cmp(i, 8'b11110001, 8'b00000000);
+assign id_out = cmp(i, 8'b11010011, 8'b00000000);
+assign id_11x = cmp(i, 8'b11xxxxxx, 8'b00111111);
+assign id_pupsw = cmp(i, 8'b11110101, 8'b00000000);
+
+assign id_rxc = ~i[5] & i[3] & id_opa;
+assign id_sha = ~i[5] & id_opa;
+assign id_rlc = (i[5:3] == 3'b000) & id_opa;
+assign id_rar = (i[5:3] == 3'b011) & id_opa;
+assign id_daa = (i[5:3] == 3'b100) & id_opa;
+assign id_cma = (i[5:3] == 3'b101) & id_opa;
+assign id_stc = (i[5:3] == 3'b110) & id_opa;
+assign id_cmc = (i[5:3] == 3'b111) & id_opa;
+
+assign id_add = (i[5:3] == 3'b000) & (id_op | id_opi);
+assign id_adc = (i[5:3] == 3'b001) & (id_op | id_opi);
+assign id_sub = (i[5:3] == 3'b010) & (id_op | id_opi);
+assign id_sbb = (i[5:3] == 3'b011) & (id_op | id_opi);
+assign id_ana = (i[5:3] == 3'b100) & (id_op | id_opi);
+assign id_xra = (i[5:3] == 3'b101) & (id_op | id_opi);
+assign id_ora = (i[5:3] == 3'b110) & (id_op | id_opi);
+assign id_cmp = (i[5:3] == 3'b111) & (id_op | id_opi);
+
+assign id80 = id_lxi | id_pop | id_opm | id_idm | id_dad
+ | id_xthl | id_xchg | id_jxx | id_ret | id_eidi
+ | id_nop | id_stlda | id_mvmr | id_mvrm | id_hlt
+ | id_opa | id_mvim | id_jmp | id_io | id_opi
+ | id_mvi | id_lsax | id_lhld | id_shld | id_op;
+assign id81 = id_dcx | id_inx | id_sphl | id_pchl | id_xchg
+ | id_eidi | id_nop | id_opa | id_op | id_mov
+ | (id_idr & ~id82);
+assign id82 = id_pop | id_push | id_opm | id_idm | id_dad
+ | id_rst | id_ret | id_rxx | id_mvrm | id_mvmr
+ | id_hlt | id_mvim | id_io | id_opi | id_mvi
+ | id_lsax;
+assign id83 = id_opm | id_stlda | id_mvmr | id_mvrm | id_opi
+ | id_mvi | id_lsax;
+assign id84 = id_lxi | id_jxx | id_jmp;
+assign id85 = id_push | id_idm | id_rst | id_xthl | id_cxx
+ | id_call | id_mvim | id_shld | (id_io & ~i[3]);
+assign id86 = id_push | id_rst | id_xthl | id_cxx | id_call
+ | id_mvmr | id_shld | (~i[3] & (id_lsax | id_stlda));
+
+assign id00 = id_xthl | id_pchl | id_sphl;
+assign id01 = id_pop | id_rxx | id_ret;
+assign id02 = id_mvi | id_opi | id_io;
+assign id03 = id_rst | id_push | id_xthl | id_cxx | id_call;
+assign id04 = id_rst | id_push | id_xthl | id_cxx | id_call;
+assign id05 = id_rst | id_push | id_xthl | id_cxx | id_call | id_dcx;
+assign id06 = id_pop | id_rxx | id_ret | id_dad | id_lhld | id_io;
+assign id07 = id_dcx | id_inx | id_lxi | id_dad;
+assign id08 = id_mov | id_mvi | id_idr | id_op;
+assign id09 = id_rst | id_push | id_xthl | id_cxx | id_call | id_shld;
+assign id10 = id_pop | id_push | id_mvrm | id_mvi;
+
+//______________________________________________________________________________
+//
+// arithmetic and logic unit (refactored)
+//
+assign alu_xwr = t4 & (id_rst | id_out | ~id_11x)
+ | t3 & m4 & ~(id_dad | id_out | id_rst)
+ | t2 & (m4 | m5) & id_dad;
+
+assign alu_xout = ~(id_sub | id_sbb | id_cmp | id_cma);
+assign alu_xrd = t5 & m1 & ~id_inr & ~id_dcr
+ | t3 & m5 & id_rst
+ | t2 & ~sy_wo_n & (id_io | id_mvim | id_stlda | id_lsax | id_mvmr);
+
+assign alu_pha = (t2 & m1) | (t1 & m5);
+assign alu_r00 = id_dcr & t4;
+
+assign alu_ald = alu_pha & ( id_adc | id_add | id_daa | id_xra | id_sbb
+ | id_sub | id_ana | id_ora | id_sha | id_cma);
+
+assign alu_ard = t4 & m1 & ((acc_sel & id08) | id_opa | id_stlda | id_lsax | id_io)
+ | t2 & m4 & id_pupsw;
+
+assign alu_awr = t3 & m5 & id_popsw
+ | t3 & m5 & (id_io | id_mvim) & sy_wo_n
+ | t3 & m4 & (id_stlda | id_lsax | id_mvmr) & sy_wo_n
+ | acc_sel & id08 & (t5 & m1 | t3 & m4);
+
+assign alu_srd = t2 & m5 & (id_inr | id_dcr)
+ | t3 & m5 & id_dad
+ | t3 & m4 & id_dad
+ | t5 & m1 & (id_inr | id_dcr);
+
+assign alu_rwr = t3 & m1
+ | t1 & (m4 | m5) & id_dad;
+
+assign alu_rld = t4 & (id_sha | id_op | id_opi);
+
+assign daa = id_daa & t4;
+assign daa_x6 = (acc[3] & (acc[2] | acc[1])) | psw_ac;
+assign daa_6x = ((acc[3] & (acc[2] | acc[1])) & acc[4] & acc[7])
+ | (acc[7] & (acc[6] | acc[5])) | tmp_c;
+
+assign x = alu_xout ? xr : ~xr;
+assign s = {7'b0000000, id_rlc & c[7]}
+ | ((id_rxc | id_ora | id_ana | id_xra) ? 8'h00 : (x + r + cl))
+ | (id_rxc ? {ch, r[7:1]} : 8'h00)
+ | (id_ora ? (x | r) : 8'h00)
+ | (id_ana ? (x & r) : 8'h00)
+ | (id_xra ? (x ^ r) : 8'h00);
+
+assign cl = tmp_c & ~id_daa & ~id_rlc & ~id_ora & ~id_xra & ~id_rxc;
+assign ch = tmp_c & id_rar | r[0] & ~id_rar;
+
+assign c[0] = (r[0] & x[0]) | (cl & (r[0] | x[0]));
+assign c[1] = (r[1] & x[1]) | (c[0] & (r[1] | x[1]));
+assign c[2] = (r[2] & x[2]) | (c[1] & (r[2] | x[2]));
+assign c[3] = (r[3] & x[3]) | (c[2] & (r[3] | x[3]));
+assign c[4] = (r[4] & x[4]) | (c[3] & (r[4] | x[4]));
+assign c[5] = (r[5] & x[5]) | (c[4] & (r[5] | x[5]));
+assign c[6] = (r[6] & x[6]) | (c[5] & (r[6] | x[6]));
+assign c[7] = (r[7] & x[7]) | (c[6] & (r[7] | x[7]));
+
+assign alu_zrd = reset | (m1 & t3);
+assign psw_ld = t3 & m4 & id_popsw;
+assign psw_wr = t2 & m1 & (id_opi | id_inr | id_dcr | id_daa | id_op);
+assign psw_oe = t2 & m5 & id_pupsw;
+
+always @(posedge clk)
+if (ena)
+begin
+ if (alu_xwr) xr <= id_rst ? (i & 8'b00111000) : d;
+ if (alu_awr) acc <= d;
+ if (alu_ald) acc <= s;
+ if (alu_rld) r <= acc;
+ if (alu_rwr) r <= d;
+ if (alu_r00) r <= 8'hff;
+ if (daa)
+ begin
+ r[1] <= daa_x6;
+ r[2] <= daa_x6;
+ r[5] <= daa_6x;
+ r[6] <= daa_6x;
+ end
+ if (psw_ld)
+ begin
+ psw_c <= d[0]; // x register was in original Intel design
+ psw_p <= d[2];
+ psw_ac <= d[4];
+ psw_z <= d[6];
+ psw_s <= d[7];
+ end
+ if (psw_wr)
+ begin
+ psw_p <= ~(^s);
+ psw_ac <= (c[3] & ~id_xra & ~id_ora & ~id_rxc) | (id_ana & (x[3] | r[3]));
+ psw_z <= ~(|s);
+ psw_s <= s[7];
+ end
+ if (alu_pha)
+ begin
+ if (id_cmp | id_sbb | id_sub) psw_c <= id_rxc ? ~x[0] : ~c[7];
+ if (id_dad | id_sha | id_adc | id_add) psw_c <= id_rxc ? x[0] : c[7];
+ if (id_xra | id_stc | id_ora | id_ana | id_cmc) psw_c <= ~tmp_c;
+ end
+ if (daa & daa_6x) psw_c <= 1'b1;
+
+ if ((t3 & m1) | (t2 & m5 & id_dad)) tmp_c <= psw_c;
+ if (t4)
+ begin
+ if (id_sbb) tmp_c <= ~psw_c;
+ if (id_dad | id_cma | id_dcr | id_add | id_stc) tmp_c <= 1'b0;
+ if (id_inr | id_ora | id_xra | id_ana | id_cmp | id_sub) tmp_c <= 1'b1;
+ end
+end
+
+//______________________________________________________________________________
+//
+endmodule
diff --git a/1801BM1_vm80a/wbc/syn/de0/de0.sdc b/1801BM1_vm80a/wbc/syn/de0/de0.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..bed3a599c7fee21f5ca855e95e09e5e4bac427e5
--- /dev/null
+++ b/1801BM1_vm80a/wbc/syn/de0/de0.sdc
@@ -0,0 +1,124 @@
+## Generated SDC file "de0.out.sdc"
+
+## Copyright (C) 1991-2012 Altera Corporation
+## Your use of Altera Corporation's design tools, logic functions
+## and other software and tools, and its AMPP partner logic
+## functions, and any output files from any of the foregoing
+## (including device programming or simulation files), and any
+## associated documentation or information are expressly subject
+## to the terms and conditions of the Altera Program License
+## Subscription Agreement, Altera MegaCore Function License
+## Agreement, or other applicable license agreement, including,
+## without limitation, that your use is for the sole purpose of
+## programming logic devices manufactured by Altera and sold by
+## Altera or its authorized distributors. Please refer to the
+## applicable agreement for further details.
+
+
+## VENDOR "Altera"
+## PROGRAM "Quartus II"
+## VERSION "Version 12.1 Build 243 01/31/2013 Service Pack 1 SJ Full Version"
+
+## DATE "Sat Feb 03 11:24:16 2018"
+
+##
+## DEVICE "EP3C16F484C6"
+##
+
+
+#**************************************************************
+# Time Information
+#**************************************************************
+
+set_time_format -unit ns -decimal_places 3
+
+
+
+#**************************************************************
+# Create Clock
+#**************************************************************
+
+create_clock -name {de0_clock_50_2} -period 20.000 -waveform { 0.000 10.000 } [get_ports {de0_clock_50_2}]
+
+
+#**************************************************************
+# Create Generated Clock
+#**************************************************************
+
+create_generated_clock -name {corepll|altpll_component|auto_generated|pll1|clk[0]} -source [get_pins {corepll|altpll_component|auto_generated|pll1|inclk[0]}] -duty_cycle 50.000 -multiply_by 2 -master_clock {de0_clock_50_2} [get_pins {corepll|altpll_component|auto_generated|pll1|clk[0]}]
+
+
+#**************************************************************
+# Set Clock Latency
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Clock Uncertainty
+#**************************************************************
+
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {de0_clock_50_2}] 0.020
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {de0_clock_50_2}] 0.020
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -setup 0.070
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -hold 0.100
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -setup 0.070
+set_clock_uncertainty -rise_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -hold 0.100
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {de0_clock_50_2}] 0.020
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {de0_clock_50_2}] 0.020
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -setup 0.070
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -hold 0.100
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -setup 0.070
+set_clock_uncertainty -fall_from [get_clocks {de0_clock_50_2}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -hold 0.100
+set_clock_uncertainty -rise_from [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] 0.020
+set_clock_uncertainty -rise_from [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] 0.020
+set_clock_uncertainty -fall_from [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -rise_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] 0.020
+set_clock_uncertainty -fall_from [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] -fall_to [get_clocks {corepll|altpll_component|auto_generated|pll1|clk[0]}] 0.020
+
+
+#**************************************************************
+# Set Input Delay
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Output Delay
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Clock Groups
+#**************************************************************
+
+
+
+#**************************************************************
+# Set False Path
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Multicycle Path
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Maximum Delay
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Minimum Delay
+#**************************************************************
+
+
+
+#**************************************************************
+# Set Input Transition
+#**************************************************************
+
diff --git a/1801BM1_vm80a/wbc/tbe/de0_tb0.v b/1801BM1_vm80a/wbc/tbe/de0_tb0.v
new file mode 100644
index 0000000000000000000000000000000000000000..e53fe4b499c82f9478b93777c207e93b77cdd37b
--- /dev/null
+++ b/1801BM1_vm80a/wbc/tbe/de0_tb0.v
@@ -0,0 +1,189 @@
+//
+// Copyright (c) 2014 by 1801BM1@gmail.com
+// Licensed under CC-BY 3.0 (https://creativecommons.org/licenses/by/3.0/)
+//
+//______________________________________________________________________________
+//
+// Simulation configuration parameters
+//
+`timescale 1ns / 100ps
+//
+// Simulation stops (breakpoint) after this time elapsed
+//
+`define SIM_CONFIG_TIME_LIMIT 100000
+//
+// External clock frequency
+//
+`define SIM_CONFIG_CLOCK_HPERIOD 10
+
+module tb80a();
+
+//______________________________________________________________________________
+//
+// DE board connection lines
+//
+reg clk50;
+reg [2:0] button;
+reg [9:0] switch;
+wire [7:0] hex0;
+wire [7:0] hex1;
+wire [7:0] hex2;
+wire [7:0] hex3;
+wire [9:0] led;
+
+wire uart_txd;
+reg uart_rxd;
+wire uart_cts;
+reg uart_rts;
+
+wire [15:0] dram_dq; // SDRAM data bus 16 bits
+wire [12:0] dram_addr; // SDRAM address bus 13 bits
+wire dram_ldqm; // SDRAM low-byte data mask
+wire dram_udqm; // SDRAM high-byte data mask
+wire dram_we_n; // SDRAM write enable
+wire dram_cas_n; // SDRAM column address strobe
+wire dram_ras_n; // SDRAM row address strobe
+wire dram_cs_n; // SDRAM chip select
+wire [1:0] dram_ba; // SDRAM bank address
+wire dram_clk; // SDRAM clock
+wire dram_cke; // SDRAM clock enable
+ //
+wire [15:0] fl_dq; // FLASH data bus 15 Bits
+wire [21:0] fl_addr; // FLASH address bus 22 Bits
+wire fl_we_n; // FLASH write enable
+wire fl_rst_n; // FLASH reset
+wire fl_oe_n; // FLASH output enable
+wire fl_ce_n; // FLASH chip enable
+wire fl_wp_n; // FLASH hardware write protect
+wire fl_byte_n; // FLASH selects 8/16-bit mode
+wire fl_rb; // FLASH ready/busy
+ //
+wire lcd_blig; // LCD back light ON/OFF
+wire lcd_rw; // LCD read/write select, 0 = write, 1 = read
+wire lcd_en; // LCD enable
+wire lcd_rs; // LCD command/data select, 0 = command, 1 = data
+wire [7:0] lcd_data; // LCD data bus 8 bits
+ //
+wire sd_dat0; // SD Card Data 0
+wire sd_dat3; // SD Card Data 3
+wire sd_cmd; // SD Card Command Signal
+wire sd_clk; // SD Card Clock
+wire sd_wp_n; // SD Card Write Protect
+ //
+wire ps2_kbdat; // PS2 Keyboard Data
+wire ps2_kbclk; // PS2 Keyboard Clock
+wire ps2_msdat; // PS2 Mouse Data
+wire ps2_msclk; // PS2 Mouse Clock
+ //
+wire vga_hs; // VGA H_SYNC
+wire vga_vs; // VGA V_SYNC
+wire [3:0] vga_r; // VGA Red[3:0]
+wire [3:0] vga_g; // VGA Green[3:0]
+wire [3:0] vga_b; // VGA Blue[3:0]
+ //
+wire [1:0] gpio0_clkin; // GPIO Connection 0 Clock In Bus
+wire [1:0] gpio0_clkout; // GPIO Connection 0 Clock Out Bus
+wire [31:0] gpio0_d; // GPIO Connection 0 Data Bus
+ //
+wire [1:0] gpio1_clkin; // GPIO Connection 1 Clock In Bus
+wire [1:0] gpio1_clkout; // GPIO Connection 1 Clock Out Bus
+wire [31:0] gpio1_d; // GPIO Connection 1 Data Bus
+
+initial
+begin
+ clk50 = 0;
+ forever
+ begin
+ #`SIM_CONFIG_CLOCK_HPERIOD clk50 = 0;
+ #`SIM_CONFIG_CLOCK_HPERIOD clk50 = 1;
+ end
+end
+
+initial
+begin
+ uart_rxd = 1'b1;
+ uart_rts = 1'b0;
+ button = 3'b000;
+ switch = 10'h001; // SW0 turbo (100MHz)/slow (2.5MHz) mode
+
+#200 button = 3'b111;
+end
+
+initial
+begin
+ #`SIM_CONFIG_TIME_LIMIT $stop;
+end
+
+de0 de0_top(
+ .de0_clock_50(clk50),
+ .de0_clock_50_2(clk50),
+ .de0_button(button),
+ .de0_sw(switch),
+ .de0_hex0(hex0),
+ .de0_hex1(hex1),
+ .de0_hex2(hex2),
+ .de0_hex3(hex3),
+ .de0_led(led),
+
+ .de0_uart_txd(uart_txd),
+ .de0_uart_rxd(uart_rxd),
+ .de0_uart_cts(uart_cts),
+ .de0_uart_rts(uart_rts),
+
+ .de0_dram_dq(dram_dq),
+ .de0_dram_addr(dram_addr),
+ .de0_dram_ldqm(dram_ldqm),
+ .de0_dram_udqm(dram_udqm),
+ .de0_dram_we_n(dram_we_n),
+ .de0_dram_cas_n(dram_cas_n),
+ .de0_dram_ras_n(dram_ras_n),
+ .de0_dram_cs_n(dram_cs_n),
+ .de0_dram_ba(dram_ba),
+ .de0_dram_clk(dram_clk),
+ .de0_dram_cke(dram_cke),
+
+ .de0_fl_dq(fl_dq),
+ .de0_fl_addr(fl_addr),
+ .de0_fl_we_n(fl_we_n),
+ .de0_fl_rst_n(fl_rst_n),
+ .de0_fl_oe_n(fl_oe_n),
+ .de0_fl_ce_n(fl_ce_n),
+ .de0_fl_wp_n(fl_wp_n),
+ .de0_fl_byte_n(fl_byte_n),
+ .de0_fl_rb(fl_rb),
+
+ .de0_lcd_blig(lcd_blig),
+ .de0_lcd_rw(lcd_rw),
+ .de0_lcd_en(lcd_en),
+ .de0_lcd_rs(lcd_rs),
+ .de0_lcd_data(lcd_data),
+
+ .de0_sd_mosi(sd_dat0),
+ .de0_sd_miso(sd_dat3),
+ .de0_sd_cmd(sd_cmd),
+ .de0_sd_clk(sd_clk),
+ .de0_sd_wp_n(sd_wp_n),
+
+ .de0_ps2_kbdat(ps2_kbdat),
+ .de0_ps2_kbclk(ps2_kbclk),
+ .de0_ps2_msdat(ps2_msdat),
+ .de0_ps2_msclk(ps2_msclk),
+
+ .de0_vga_hs(vga_hs),
+ .de0_vga_vs(vga_vs),
+ .de0_vga_r(vga_r),
+ .de0_vga_g(vga_g),
+ .de0_vga_b(vga_b),
+
+ .de0_gpio0_clkin(gpio0_clkin),
+ .de0_gpio0_clkout(gpio0_clkout),
+ .de0_gpio0_d(gpio0_d),
+
+ .de0_gpio1_clkin(gpio1_clkin),
+ .de0_gpio1_clkout(gpio1_clkout),
+ .de0_gpio1_d(gpio1_d)
+);
+
+//_____________________________________________________________________________
+//
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/DEV_NOTES.md b/MiSTer-devel_NeoGeo_MiSTer/DEV_NOTES.md
new file mode 100644
index 0000000000000000000000000000000000000000..9bdbb53728e3b8f1c865711f7988a4ccdb532ea7
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/DEV_NOTES.md
@@ -0,0 +1,242 @@
+These notes were written for myself/my setup but many points could be useful for others.
+
+# MiSTer basics
+The code running on the HPS (ARM CPU) loads the requested core as an .rbf file via fpga_load_rbf in fpga_io.cpp in Main_MiSTer.
+
+In each core, the files in /sys/ provide the common functionalities: video scaling, video and audio output, the OSD, and the HPS interface logic. The hps_io module "breaks out" a bunch of signals for the core to utilize.
+
+The core must be held in reset and provide access to the SDRAM controller and BRAM for the HPS during ROM loading. It can then switch to run mode and start using the data itself.
+
+To connect to the DE10 via ethernet: run `D:\OpenDHCPServer\runstandalone.bat`
+**NOTE**: It may already be running as a service ! Make sure the LAN connection is enabled in the Windows network control panel. By matching its MAC address, the DE10 will be assigned IP 192.168.1.200. It's then possible to use FTP or SSH with root:1 as login.
+
+To debug linux-side stuff (Main_MiSTer):
+Putty `root:1@192.168.1.200`, `killall MiSTer` so that the binary file can be replaced, Ctrl+shift+B in VS to build, upload new binary via FTP, sync, and run `/media/fat/MiSTer`.
+
+neogeo-lite allows for faster compilation time by omitting the HDMI scaler, it outputs 6-6-6 VGA video and stereo audio on the GPIO_1 header as follows:
+```
+Bottom header, pin 1 is upper right
+ _39________________________________________________________01
+| |
+| G0 G1 G2 G3 G4 +3 G5 B3 B4 B5 VS -- -- -- +5 RA -- -- -- -- |
+| |
+| R0 R1 R2 R3 R4 gn R5 B2 B1 B0 HS -- -- -- gn gn -- -- -- LA |
+|_____________________________________________________________|
+ 40 02
+```
+Pin 10 has to be connected to ground to enable the VGA output. This is used to detect the IO extension board.
+
+# NeoGeo core specifics
+
+The generated .rbf is `output_files\neogeo-lite.rbf`
+
+The ROM files are normally loaded by user_io_file_tx from user_io.cpp. For this core, neogeo_romset_tx from `/support/neogeo/loader.cpp` is used instead.
+
+## Save files for cartridge games
+
+Data | Start | End
+---- | ---- | ----
+Backup RAM | 000000 | 00FFFF
+Memory card | 010000 | 0107FF
+
+## Save file for CD systems
+
+Data | Start | End
+---- | ---- | ----
+Memory card | 000000 | 001FFF
+
+## SDRAM multiplexing
+The SDRAM extension board stores the 68k program, sprites and fix graphics.
+It currently runs at 120MHz (5*24M) but may be pushed up to 144MHz (6*24M) if needed.
+
+### 68k data
+Read as soon as nSROMOE (system ROM read), nROMOE (cart ROM read) or nPORTOE (cart ROM extension read) goes low.
+Right now, the 68k always runs with 1 wait cycle :(
+
+An attempt was made to fetch 68k data 4 words at a time with burst reads, but it didn't seem to be very reliable. Try again ?
+
+### Fix graphics
+Read as soon as PCK2B rises.
+Since the SDRAM provides 16-bit words and there's only an 8-bit data bus for the fix (2 pixels), one SDRAM read gives 4 pixels.
+The fix data is re-organized during loading so that pixel pairs are kept adjacent in the SDRAM. This allows to do only one read for 4 pixels and use S2H1 to select which pair must be fed to NEO-B1 at the right time.
+
+An attempt was made to fetch fix data 2 words at a time with burst reads to have the whole 8 pixel line at once. It worked but it seems better to have multiple shorter reads for more efficient SDRAM access interleave.
+
+FIXD is latched on rising edge of CLK_1MB.
+
+### Sprite graphics
+Read as soon as PCK1B rises.
+The sprite graphics data bus is 32-bit, so for one 8-pixel line, two words must be read.
+The sprite data is re-organized during so that the bitplane data can be read in 4-word bursts and used as-is. The PCK1B edge is used to trigger the reads, and CA4 is used to select which 8-pixel group must be fed to NEO-ZMC2 at the right time.
+
+CR is latched on rising edge of CLK_12M when LOAD is high.
+
+## Loading
+
+Fix graphics are loaded in a way that takes advantage of the 16-bit wide SDRAM data bus.
+
+Since fix pixels are stored in pairs in columns but always read in lines, instead of storing:
+`column 2 (lines 0~7), column 3 (lines 0~7), column 0 (lines 0~7), column 1 (lines 0~7)`
+
+Load like:
+`line 0 (columns 0~3), line 1 (columns 0~3)...`
+
+Sprite graphics bytes are loaded like this:
+C2 C2 C1 C1 C2 C2 C1 C1...
+
+So bitplanes for a single line look like this:
+0 1 2 3 0 1 2 3...
+
+Complete 16-pixel line: 4*16 = 64 bits = four 16-bit SDRAM words
+
+ioctl_index is used to tell the core where to store the data being loaded. The currently used values are:
+* 0: System ROM (BIOS)
+* 1: LO ROM
+* 2: SFIX ROM
+* 4: P1 ROM first half (or full)
+* 5: P1 ROM second half
+* 6: P2 ROM
+* 8: S1 ROM
+* 9: M1 ROM
+* 16+: V ROMs, add 512kB bank number
+* 64+: C ROMs, the lower 6 bits are used as a bitfield like this:
+ x1BBBBBS
+ B: 512kB bank number
+ S: word shift (used to interleave odd/even ROMs)
+ So SDRAM address = 0x0800000 + 0b1_BBBBB000_00000000_000000S0 + ioctl_addr
+
+## romsets.xml file
+
+* hw: Special cart chip. 0=None, 1=PRO-CT0, 2=Link MCU, 3=NEO-CMC
+* pcm: 0=Game uses separate V1x and V2x ROMs, 1=Game uses PCM chip with V1, V2... ROMs
+* type: P (68k program), S (fix gfx), C (sprite gfx), M (z80 program) or V (voice samples). See ROM file extension.
+* offset: Where to start reading in file.
+* size: How many bytes to load.
+* index: Where to start writing data in SDRAM. Depends on type.
+ * P: 4=First P1 half (0x000000), 5=Second P1 half (0x080000), 6=P2 (0x200000)
+ * S: Always 8
+ * M: Always 9
+ * V: 16 + (512kB bank). Non-PCM games must have their .v1x ROMs between 16-47, and their .v2x ROMs between 48-63
+ * C: 64 + (0=odd, 1=even) + (1MB bank * 2)
+
+## BRAM zones
+
+Memory | Size
+------ | ----
+68k RAM | 64kB
+Z80 RAM | 2kB
+Slow VRAM | 64kB
+Fast VRAM | 4kB
+Palette RAM | 16kB
+Line buffers | 9kB
+LO ROM | 64kB
+M1 ROM | 128kB
+Memory card | 2kB
+Backup RAM | 32kB
+------ | ----
+Total | 385kB
+
+## SDRAM cart map
+
+See [sdram_map.odg](sdram_map.odg)
+
+Memory | Size | Start | End
+------ | ---- | ----- | ---
+P1 ROM | 1MB | 0000000 | 00FFFFF
+P2 ROMs | 4MB | 0200000 | 05FFFFF
+System ROM | 128kB | 0600000 | 061FFFF
+SFIX ROM | 128kB | 0620000 | 063FFFF
+Free | 256kB | 0640000 | 067FFFF
+S ROM | 512kB | 0680000 | 06FFFFF
+Free | 1MB | 0700000 | 07FFFFF
+C ROM | 24MB | 0800000 | 1FFFFFF
+
+Games using NEO-CMC are able to bankswitch S ROMs larger than 128kB
+
+## SDRAM CD map
+
+See [sdram_map.odg](sdram_map.odg)
+
+Memory | Size | Start | End
+------ | ---- | ----- | ---
+P1 ROM | 1MB | 0000000 | 00FFFFF
+Extended RAM | 1MB | 0100000 | 01FFFFF
+Free | 4MB | 0200000 | 05FFFFF
+System ROM | 512kB | 0600000 | 067FFFF
+S ROM | 512kB | 0680000 | 06FFFFF
+Free | 1MB | 0700000 | 07FFFFF
+C ROM | 4MB | 0800000 | 0BFFFFF
+Free | 20MB | 0C00000 | 1FFFFFF
+
+## Neo CD loading notes
+
+```
+To load sectors, the Neo CD does this:
+-Starts playing CD at requested MSF - 3
+ MSF must be given to the LC8951 module to be copied back in the HEAD registers
+ Start requesting sectors from HPS with interval timer
+ Wait a bit to let the system ROM set up the IRQ masks ?
+-Enables CDC interrupts
+-Sets CMDIEN, DTEIEN, DECIEN and DOUTEN
+-Sets DECEN, E01RQ, WRRQ, QRQ and PRQ
+-Sets SYIEN, SYDEN, DSCREN, COWREN
+-Waits for the CDC decoder interrupt
+ Trigger the decoder interrupt (CDC_nIRQ) when the HPS has finished sending a sector
+-Reads STAT3 to clear the IRQ
+-Does the same thing over again (to let at least one sector go by ?)
+ Need to trigger the decoder interrupt again ? Should have to do that only once per play
+-At the second CDC decoder interrupt:
+-Checks STAT1 to see if there aren't any error flags
+-Checks STAT3 to see if the decoder status is valid
+-Reads the HEAD registers, compares them with the requested MSF, if so:
+-Reads the STAT registers, checks if there aren't any error flags in STAT0 and CRC OK bit
+-Reads PT
+ Can always be 0004 (skips sector header bytes), the Neo CD doesn't care if it changes or not
+-Sets DBC to $7FF (2048-1 bytes)
+-Sets DAC to PT-4
+ So DAC should always be set to 0000
+-Sets up LC8953 DMA to retrieve 2048 bytes
+ This triggers the DMA copy from the cache to the CD sector buffer at $111204
+-After copy is done, increment MFS (pulse MSF_INC)
+-Decrements sector counter until 0
+```
+
+## Neo CD fix data notes
+
+```
+Normal fix data bytes:
+10 18 00 08
+11 19 01 09
+12 1A 02 0A
+13 1B 03 0B
+14 1C 04 0C
+15 1D 05 0D
+16 1E 06 0E
+17 1F 07 0F
+
+SDRAM organization words:
+10-18 00-08 11-19 01-09 12-1A 02-0A 13-1B 03-0B...
+
+The Neo CD will write fix data as bytes so two byte writes would have to be grouped in
+one SDRAM word write, but that won't work with the byte address remapping. It would require
+a 32 byte buffer which would be burst written and it would be a mess...
+Instead of that, just use LDQM/UDQM to do byte writes with the remapped address directly.
+
+addr_out = ?, addr_in[...:0], ~addr_in[4], addr_in[3]
+00 -> 02
+01 -> 06
+02 -> 0A
+...
+07 -> 1E
+
+08 -> 03
+09 -> 07
+...
+
+10 -> 00
+11 -> 04
+...
+
+18 -> 01
+19 -> 05
+```
diff --git a/MiSTer-devel_NeoGeo_MiSTer/NeoGeo.sdc b/MiSTer-devel_NeoGeo_MiSTer/NeoGeo.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..a6b805c497742d2dcf64673a56d15e71196c8c29
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/NeoGeo.sdc
@@ -0,0 +1,7 @@
+derive_pll_clocks
+derive_clock_uncertainty
+
+set_false_path -from {emu|cfg[*]}
+
+set_multicycle_path -from {emu|Z80CPU|*} -setup 2
+set_multicycle_path -from {emu|Z80CPU|*} -hold 1
diff --git a/MiSTer-devel_NeoGeo_MiSTer/README.md b/MiSTer-devel_NeoGeo_MiSTer/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..554a664c71480becff4a92871f12a4c7195b4146
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/README.md
@@ -0,0 +1,47 @@
+
+# [SNK Neo Geo](https://en.wikipedia.org/wiki/Neo_Geo_(system)) for [MiSTer Platform](https://github.com/MiSTer-devel/Main_MiSTer/wiki)
+
+This is an FPGA implementation of the NEO GEO/MVS system by [Furrtek](https://www.patreon.com/furrtek/posts)
+
+## Features
+* Supports memory card saving
+* MVS, AES, and CD system support
+* Compatible with Darksoft ROM sets using provided XML
+* Compatible with decrypted MAME ROM sets using your own XML
+* Compatible with decrypted .neo ROM sets
+* Compatible with gog.com ROMs using provided XML
+* Support for Universe BIOS
+
+Note: This core does not support encrypted ROMs. Make sure the ROM has no encrypted parts before using. MAME ROM pack includes many encrypted ROMs so it's not recommended for inexperienced users. Using the .neo conversion tool with a MAME ROM set will result in some ROMs still being encrypted. There is an alternate .neo conversion tool for the Darksoft ROM set that will give you a fully decrypted set.
+
+* [MAME to .neo conversion tool (by Matt Greer)](https://github.com/city41/neosdconv)
+* [MAME to .neo conversion tool (by Rupert Carmichael)](https://github.com/carmiker/neoconv)
+* [Darksoft to .neo conversion tool](https://gitlab.com/loic.petit/darksoft-to-neosd/)
+
+## Installation
+Copy the NeoGeo_\*.rbf file to the 'Console' or 'Arcade' folder (your choice) on the SD card. ROMs should go in the 'games\NeoGeo' folder. For ease of use, it is strongly suggested that people use the Darksoft ROM pack. These can be either zipped or unzipped with minimal loading speed difference. Several things must be observed:
+* When using an unzipped Darksoft ROM set, each game's ROM files must be in their own folder and the folders containing the ROM sets must be named to match the XML (MAME standard names)
+* ROMs can be placed inside sub-folders for organization
+* Zipped ROMs must **not** contain folders.
+
+In addition, several bios files must be placed in the 'games\NeoGeo' folder for the core to function properly:
+* 000-lo.lo
+* sfix.sfix
+* sp-s2.sp1 (MVS)
+* neo-epo.sp1 (AES)
+* uni-bios.rom
+
+These bios files must be placed in the 'games\NeoGeo-CD' folder:
+* top-sp1.bin (CD)
+* neocd.bin (CDZ)
+* uni-bioscd.rom (CD and CDZ)
+
+Sometimes these files may be named slightly different depending on where they are obtained, but they must be renamed to match the filenames above to work with MiSTer. You may choose between using the original system BIOS (sp-s2.sp1/neo-epo.sp1) or UniBios (uni-bios.rom). Using UniBios is recommended, and can be obtained [here](http://unibios.free.fr/).
+
+Lastly, **romsets.xml** from the release folder must also be placed in the directory. The provided XML is for Darksoft ROMs only, you must make your own for MAME ROMs. This file describes to the core where the ROM sets are located and how to load them. **gog-romsets.xml** can be used (renamed to **romsets.xml**) for games purchased from gog.com (which also include all the needed bios files), see comments in gog-romsets.xml .
+
+## Saving and Loading
+In AES mode, all saves are to the memory card only. In MVS mode, some games and UniBios save their settings to a special area of battery backed ram built into the system, while game data can still be saved to a memory card.
+
+## RAM and Game Sizes
+Neo Geo uses very large ROMs. About 84% of the library will fit onto a 32 megabyte SDRAM module. Another 12% will fit onto a 64 megabyte SDRAM module. The remaining 8 games require a 128 megabyte module. For more information about which games can be loaded with which sized RAM, open romsets.xml in your favorite text editor or github. The games are organized by size.
diff --git a/MiSTer-devel_NeoGeo_MiSTer/neogeo.sv b/MiSTer-devel_NeoGeo_MiSTer/neogeo.sv
new file mode 100644
index 0000000000000000000000000000000000000000..c237adcbb65af438f427450208779a2d444961c3
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/neogeo.sv
@@ -0,0 +1,2120 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+// Current status:
+// Neo CD CD check ok but crashes when loading. No more video glitches.
+
+// How about not using a cache at all and DMAing directly from the data fed by the HPS ?
+// The "sector ready" IRQ could be triggered just when a sector is requested, and the actual transfer
+// could be done when the system ROM starts up the DMA transfer ?
+
+// Neo CD times 12/05/2019:
+// SECTOR_READY goes high at SECTOR_TIMER == 430631
+// So it takes 600000-430631=169369 ticks to get a sector from HPS
+// 169369/120M=1.41ms (1451 kB/s)
+// DMA copy: 215 ticks for 10 bytes
+// So 215/120M/10=179.17ns per byte (5450 kB/s)
+
+// Neo CD times 11/05/2019:
+// DMA copy: 616 ticks for 10 bytes
+// So 215/120M/10=513.3ns per byte (1902 kB/s)
+
+module emu
+(
+ `include "sys/emu_ports.vh"
+);
+
+assign ADC_BUS = 'Z;
+assign USER_OUT = '1;
+assign {UART_RTS, UART_TXD, UART_DTR} = 0;
+assign {SD_SCK, SD_MOSI, SD_CS} = 'Z;
+
+assign AUDIO_S = 1; // Signed
+assign AUDIO_MIX = status[6:5];
+assign AUDIO_L = snd_mix_l[16:1];
+assign AUDIO_R = snd_mix_r[16:1];
+
+assign LED_USER = status[0] | bk_pending;
+assign LED_DISK = 0;
+assign LED_POWER = 0;
+assign BUTTONS = osd_btn;
+assign VGA_SCALER= 0;
+assign VGA_DISABLE = 0;
+assign HDMI_FREEZE = 0;
+assign HDMI_BLACKOUT = 0;
+assign HDMI_BOB_DEINT = 0;
+
+wire [1:0] ar = status[33:32];
+wire vcrop_en = status[34];
+wire [3:0] vcopt = status[38:35];
+reg en216p;
+reg [4:0] voff;
+always @(posedge CLK_VIDEO) begin
+ en216p <= ((HDMI_WIDTH == 1920) && (HDMI_HEIGHT == 1080) && !forced_scandoubler && !scale);
+ voff <= (vcopt < 6) ? {vcopt,1'b0} : ({vcopt,1'b0} - 5'd24);
+end
+
+wire vga_de;
+video_freak video_freak
+(
+ .*,
+ .VGA_DE_IN(vga_de),
+ .ARX((!ar) ? 12'd10 : (ar - 1'd1)),
+ .ARY((!ar) ? 12'd7 : 12'd0),
+ .CROP_SIZE((en216p & vcrop_en) ? 10'd216 : 10'd0),
+ .CROP_OFF(voff),
+ .SCALE(status[40:39])
+);
+
+// status bit definition:
+// 31 23 15 7
+// --AA-PSS -------- L--CGGDD DEEMVTTR
+// : status[0] System Reset, used by the HPS, keep it there
+// T: status[2:1] System type, 0=Console, 1=Arcade, 2=CD, 3=CDZ
+// V: status[3] Video mode
+// M: status[4] Memory card presence
+// E: status[6:5] Stereo mix
+// D: status[9:7] DIP switches
+// G: status[11:10] Neo CD region
+// C: status[12] Save memory card & backup RAM
+// L: status[12] CD lid state (DEBUG)
+// : status[14] Manual Reset
+// : status[20:15] OSD options
+// 0123456789 ABCDEFGHIJKLMNO
+
+// Conditional modification of the CONF strings chaining according to chosen system type
+// Con Arc CD CDz
+// 00 01 10 11
+// F F + + ~SYSTEM_CDx;
+// + + S S SYSTEM_CDx;
+// O O + + ~SYSTEM_CDx;
+// + O + + SYSTEM_MVS;
+// + + O O SYSTEM_CDx;
+
+// Status Bit Map:
+// Upper Lower
+// 0 1 2 3 4 5 6
+// 01234567890123456789012345678901 23456789012345678901234567890123
+// 0123456789ABCDEFGHIJKLMNOPQRSTUV 0123456789ABCDEFGHIJKLMNOPQRSTUV
+// XXXXXXXXXXXXX XXX XXXXX XXXXXXX XXXXXXXXXXXXX XXXXXX
+
+`include "build_id.v"
+localparam CONF_STR = {
+ "NEOGEO;;",
+ "-;",
+ "FS1,*,Load ROM set;",
+ "S1,CUECHD,Load CD Image;",
+ "-;",
+ "H3OP,FM,ON,OFF;",
+ "H3OQ,ADPCMA,ON,OFF;",
+ "H3OR,ADPCMB,ON,OFF;",
+ "H3OS,PSG,ON,OFF;",
+ "H3oP,ADPCMA CH 1,ON,OFF;",
+ "H3oQ,ADPCMA CH 2,ON,OFF;",
+ "H3oR,ADPCMA CH 3,ON,OFF;",
+ "H3oS,ADPCMA CH 4,ON,OFF;",
+ "H3oT,ADPCMA CH 5,ON,OFF;",
+ "H3oU,ADPCMA CH 6,ON,OFF;",
+ "H3-;",
+ "O1,System Type,Console(AES),Arcade(MVS);",
+ "OM,BIOS,UniBIOS,Original;",
+ "O3,Video Mode,NTSC,PAL;",
+ "-;",
+ "o9A,Input,Joystick or Spinner,Joystick,Spinner,Mouse(Irr.Maze);",
+ "oBC,Multitap,No,NEO-FTC1B,NeoTris;",
+ "-;",
+ "H0O4,Memory Card,Plugged,Unplugged;",
+ "RL,Reload Memory Card;",
+ "D4RC,Save Memory Card;",
+ "OO,Autosave,OFF,ON;",
+ "-;",
+ "O2,CD Type,CD,CDZ;",
+ "OTU,CD Speed,1x,2x,3x,4x;",
+ "OAB,CD Region,US,EU,JP,AS;",
+ "OF,CD lid,Closed,Opened;",
+ "H2-;",
+ "H2O7,[DIP] Settings,OFF,ON;",
+ "H2O8,[DIP] Freeplay,OFF,ON;",
+ "H2O9,[DIP] Freeze,OFF,ON;",
+ "-;",
+ "P1,Audio & Video;",
+ "P1-;",
+ "P1OG,Width,320px,304px;",
+ "P1o01,Aspect ratio,Original,Full Screen,[ARC1],[ARC2];",
+ "P1OIK,Scandoubler Fx,None,HQ2x,CRT 25%,CRT 50%,CRT 75%;",
+ "P1-;",
+ "d5P1o2,Vertical Crop,Disabled,216p(5x);",
+ "d5P1o36,Crop Offset,0,2,4,8,10,12,-12,-10,-8,-6,-4,-2;",
+ "P1o78,Scale,Normal,V-Integer,Narrower HV-Integer,Wider HV-Integer;",
+ "P1-;",
+ "P1O56,Stereo Mix,none,25%,50%,100%;",
+ "P1-;",
+ "-;",
+ "RE,Reset & apply;", // decouple manual reset from system reset
+ "J1,A,B,C,D,Start,Select,Coin,ABC,A+B,C+D;", // ABC is a special key to press A+B+C at once, useful for keyboards that don't allow more than 2 keypresses at once; A+B/C+D are useful for fighting games (Samurai Shodown, Garou, etc.)
+ "jn,A,B,X,Y,Start,Select,L,R,L2,R2;", // name mapping
+ "jp,B,A,D,C,Start,Select,L,R,L2,R2;", // positional mapping consistent with NeoGeoCD controller
+ "V,v",`BUILD_DATE //
+};
+
+
+//////////////////// CLOCKS ///////////////////
+
+wire locked;
+wire CLK_48M, CLK_96M;
+assign CLK_VIDEO = CLK_48M;
+wire clk_sys = CLK_48M;
+
+pll pll
+(
+ .refclk(CLK_50M),
+ .rst(0),
+ .outclk_0(CLK_96M),
+ .outclk_1(CLK_48M),
+ .reconfig_to_pll(reconfig_to_pll),
+ .reconfig_from_pll(reconfig_from_pll),
+ .locked(locked)
+);
+
+reg CLK_EN_24M_N, CLK_EN_24M_P;
+always @(posedge CLK_48M) begin
+ CLK_EN_24M_N <= ~CLK_EN_24M_N;
+ CLK_EN_24M_P <= CLK_EN_24M_N;
+end
+
+wire [63:0] reconfig_to_pll;
+wire [63:0] reconfig_from_pll;
+wire cfg_waitrequest;
+reg cfg_write;
+reg [5:0] cfg_address;
+reg [31:0] cfg_data;
+
+pll_cfg pll_cfg
+(
+ .mgmt_clk(CLK_50M),
+ .mgmt_reset(0),
+ .mgmt_waitrequest(cfg_waitrequest),
+ .mgmt_read(0),
+ .mgmt_readdata(),
+ .mgmt_write(cfg_write),
+ .mgmt_address(cfg_address),
+ .mgmt_writedata(cfg_data),
+ .reconfig_to_pll(reconfig_to_pll),
+ .reconfig_from_pll(reconfig_from_pll)
+);
+
+always @(posedge CLK_50M) begin
+ reg sys_mvs = 0, sys_mvs2 = 0;
+ reg [2:0] state = 0;
+ reg sys_mvs_r;
+
+ sys_mvs <= SYSTEM_MVS;
+ sys_mvs2 <= sys_mvs;
+
+ cfg_write <= 0;
+ if(sys_mvs2 == sys_mvs && sys_mvs2 != sys_mvs_r) begin
+ state <= 1;
+ sys_mvs_r <= sys_mvs2;
+ end
+
+ if(!cfg_waitrequest) begin
+ if(state) state<=state+1'd1;
+ case(state)
+ 1: begin
+ cfg_address <= 0;
+ cfg_data <= 0;
+ cfg_write <= 1;
+ end
+ 5: begin
+ cfg_address <= 7;
+ cfg_data <= sys_mvs_r ? 2576980378 : 2865308404;
+ cfg_write <= 1;
+ end
+ 7: begin
+ cfg_address <= 2;
+ cfg_data <= 0;
+ cfg_write <= 1;
+ end
+ endcase
+ end
+end
+
+reg [14:0] TRASH_ADDR;
+reg SYSTEM_TYPE, SYSTEM_CD_TYPE;
+
+reg nRESET_CORE;
+always @(posedge CLK_48M) begin
+ reg rst_n;
+ reg got_rom_write = 0;
+
+ if (RESET) got_rom_write <= 0;
+ if (ioctl_download & ioctl_wr) got_rom_write <= 1;
+
+ nRESET_CORE <= rst_n;
+ rst_n <= &TRASH_ADDR;
+ if(CLK_EN_24M_N && ~&TRASH_ADDR) TRASH_ADDR <= TRASH_ADDR + 1'b1;
+
+ if (status[0] | status[14] | buttons[1] | bk_loading | RESET | ~got_rom_write) begin
+ TRASH_ADDR <= 0;
+ SYSTEM_TYPE <= status[1]; // Latch the system type on reset
+ SYSTEM_CD_TYPE <= status[2];
+ end
+end
+
+reg osd_btn = 0;
+always @(posedge CLK_48M) begin
+ integer timeout = 0;
+ reg last_rst = 0;
+
+ if (RESET) last_rst <= 0;
+ if (status[0]) last_rst <= 1;
+
+ if (last_rst & ~status[0]) begin
+ osd_btn <= 0;
+ if(timeout < 48000000) begin
+ timeout <= timeout + 1;
+ osd_btn <= 1;
+ end
+ end
+end
+
+////////////////// HPS I/O ///////////////////
+
+// VD 0: Save file
+wire [1:0] img_mounted;
+wire sd_buff_wr, img_readonly;
+wire [7:0] sd_buff_addr; // Address inside 256-word sector
+wire [15:0] sd_buff_dout;
+wire [15:0] sd_buff_din[2];
+wire [15:0] sd_req_type;
+wire [63:0] img_size;
+wire [31:0] sd_lba[2];
+wire [1:0] sd_wr;
+wire [1:0] sd_rd;
+wire [1:0] sd_ack;
+
+wire [15:0] joystick_0; // 21--HNLS DCBAUDLR (1=A+B, 2=C+D combos)
+wire [15:0] joystick_1;
+wire [15:0] joystick_2;
+wire [15:0] joystick_3;
+wire [8:0] spinner_0, spinner_1;
+wire [1:0] buttons;
+wire [10:0] ps2_key;
+wire [24:0] ps2_mouse;
+wire forced_scandoubler;
+wire [63:0] status;
+
+wire [64:0] rtc;
+
+wire ioctl_wr;
+wire [26:0] ioctl_addr;
+wire [15:0] ioctl_dout;
+wire ioctl_download;
+wire [7:0] ioctl_idx;
+
+wire SYSTEM_MVS = SYSTEM_TYPE & ~cd_en;
+wire SYSTEM_CDx = cd_en;
+wire SYSTEM_CDZ = SYSTEM_CDx & SYSTEM_CD_TYPE;
+
+wire [15:0] sdram_sz;
+wire [21:0] gamma_bus;
+
+hps_io #(.CONF_STR(CONF_STR), .WIDE(1), .VDNUM(2)) hps_io
+(
+ .clk_sys(clk_sys),
+ .HPS_BUS(HPS_BUS),
+
+ .forced_scandoubler(forced_scandoubler),
+
+ .joystick_0(joystick_0), .joystick_1(joystick_1),
+ .joystick_2(joystick_2), .joystick_3(joystick_3),
+ .spinner_0(spinner_0), .spinner_1(spinner_1),
+ .ps2_mouse(ps2_mouse),
+ .buttons(buttons),
+ .ps2_key(ps2_key),
+
+ .status(status), // status read (32 bits)
+ .status_menumask({status[22], 9'd0, en216p, bk_autosave | ~bk_pending, ~dbg_menu,~SYSTEM_MVS,1'b0,SYSTEM_CDx}),
+
+ .RTC(rtc),
+ .sdram_sz(sdram_sz),
+ .gamma_bus(gamma_bus),
+
+ // Loading signals
+ .ioctl_wr(ioctl_wr),
+ .ioctl_addr(ioctl_addr),
+ .ioctl_dout(ioctl_dout),
+ .ioctl_download(ioctl_download),
+ .ioctl_index(ioctl_idx),
+ .ioctl_wait((ddr_loading & ddram_wait) | memcp_wait),
+
+ .sd_lba(sd_lba),
+ .sd_rd(sd_rd),
+ .sd_wr(sd_wr),
+ .sd_ack(sd_ack),
+ .sd_buff_addr(sd_buff_addr),
+ .sd_buff_dout(sd_buff_dout),
+ .sd_buff_din(sd_buff_din),
+ .sd_buff_wr(sd_buff_wr),
+
+ .img_mounted(img_mounted),
+ .img_readonly(img_readonly),
+ .img_size(img_size),
+
+ .EXT_BUS(EXT_BUS)
+);
+
+reg [7:0] ioctl_index;
+always @(posedge clk_sys) ioctl_index <= ioctl_idx;
+
+reg dbg_menu = 0;
+always @(posedge clk_sys) begin
+ reg old_stb;
+ reg enter = 0;
+ reg esc = 0;
+
+ old_stb <= ps2_key[10];
+ if(old_stb ^ ps2_key[10]) begin
+ if(ps2_key[7:0] == 'h5A) enter <= ps2_key[9];
+ if(ps2_key[7:0] == 'h76) esc <= ps2_key[9];
+ end
+
+ if(enter & esc) begin
+ dbg_menu <= ~dbg_menu;
+ enter <= 0;
+ esc <= 0;
+ end
+end
+
+////////////////// Her Majesty ///////////////////
+
+reg [31:0] cfg = 0;
+wire [15:0] snd_right;
+wire [15:0] snd_left;
+
+wire nRESET, nRESETP, nSYSTEM, CARD_WE, SHADOW, nVEC, nREGEN, nSRAMWEN, PALBNK;
+wire CD_nRESET_Z80;
+
+// Clocks
+wire CLK_EN_12M, CLK_EN_12M_N, CLK_68KCLK, CLK_68KCLKB, CLK_EN_6MB, CLK_EN_1HB, CLK_EN_4M_P, CLK_EN_4M_N, CLK_EN_68K_P, CLK_EN_68K_N;
+
+// 68k stuff
+wire [15:0] M68K_DATA;
+wire [23:1] M68K_ADDR;
+wire A22Z, A23Z;
+wire M68K_RW, nAS, nLDS, nUDS, nDTACK, nHALT, nBR, nBG, nBGACK;
+wire [15:0] M68K_DATA_BYTE_MASK;
+wire [15:0] FX68K_DATAIN;
+wire [15:0] FX68K_DATAOUT;
+wire IPL0, IPL1;
+wire FC0, FC1, FC2;
+reg [3:0] P_BANK;
+
+// RTC stuff
+wire RTC_DOUT, RTC_DIN, RTC_CLK, RTC_STROBE, RTC_TP;
+
+// OEs and WEs
+wire nSROMOEL, nSROMOEU, nSROMOE;
+wire nROMOEL, nROMOEU;
+wire nPORTOEL, nPORTOEU, nPORTWEL, nPORTWEU, nPORTADRS;
+wire nSRAMOEL, nSRAMOEU, nSRAMWEL, nSRAMWEU;
+wire nWRL, nWRU, nWWL, nWWU;
+wire nLSPOE, nLSPWE;
+wire nPAL, nPAL_WE;
+wire nBITW0, nBITW1, nBITWD0, nDIPRD0, nDIPRD1;
+wire nSDROE, nSDPOE;
+
+// RAM outputs
+wire [7:0] WRAML_OUT;
+wire [7:0] WRAMU_OUT;
+wire [15:0] SRAM_OUT;
+wire [7:0] CD_Z80_RAM_OUT;
+
+wire [14:0] WRAM_ADDR;
+wire [7:0] WRAML_DATA, WRAMU_DATA;
+wire WRAML_WREN, WRAMU_WREN;
+
+// Memory card stuff
+wire [23:0] CDA;
+wire [2:0] BNK;
+wire [7:0] CDD;
+wire nCD1, nCD2;
+wire nCRDO, nCRDW, nCRDC;
+wire nCARDWEN, CARDWENB;
+
+// Z80 stuff
+wire [7:0] SDD_IN, SDD_OUT, Z80_SDD_OUT;
+wire [7:0] SDD_RD_C1;
+wire [15:0] SDA, Z80_SDA;
+wire nSDRD, nSDWR, nMREQ, nIORQ, nBUSAK;
+wire Z80_nSDRD, Z80_nSDWR, Z80_nMREQ;
+wire Z80_nINT, Z80_nNMI, nSDW, nSDZ80R, nSDZ80W, nSDZ80CLR;
+wire nSDROM, nSDMRD, nSDMWR, SDRD0, SDRD1, nZRAMCS;
+wire n2610CS, n2610RD, n2610WR;
+
+// Graphics stuff
+wire [23:0] PBUS;
+wire [7:0] LO_ROM_DATA;
+wire nPBUS_OUT_EN;
+
+wire [19:0] C_LATCH;
+reg [3:0] C_LATCH_EXT;
+wire [63:0] CR_DOUBLE;
+wire [26:0] CROM_ADDR;
+
+wire [1:0] FIX_BANK;
+wire [15:0] S_LATCH;
+wire [7:0] FIXD;
+wire [10:0] FIXMAP_ADDR;
+
+wire CWE, BWE, BOE;
+
+wire [14:0] SLOW_VRAM_ADDR;
+reg [15:0] SLOW_VRAM_DATA_IN;
+wire [15:0] SLOW_VRAM_DATA_OUT;
+
+wire [10:0] FAST_VRAM_ADDR;
+wire [15:0] FAST_VRAM_DATA_IN;
+wire [15:0] FAST_VRAM_DATA_OUT;
+
+wire [11:0] PAL_RAM_ADDR;
+wire [15:0] PAL_RAM_DATA;
+reg [15:0] PAL_RAM_REG;
+
+wire PCK1, PCK2, EVEN1, EVEN2, LOAD, H;
+wire PCK1_EN_P, PCK2_EN_P;
+wire PCK1_EN_N, PCK2_EN_N;
+wire DOTA, DOTB;
+wire CA4, S1H1, S2H1;
+wire CHBL, nBNKB, VCS;
+wire CHG, LD1, LD2, SS1, SS2;
+wire [3:0] GAD;
+wire [3:0] GBD;
+wire [3:0] WE;
+wire [3:0] CK;
+
+wire CD_VIDEO_EN, CD_FIX_EN, CD_SPR_EN;
+
+// SDRAM multiplexing stuff
+wire [15:0] SROM_DATA;
+wire [15:0] PROM_DATA;
+
+parameter INDEX_SPROM = 0;
+parameter INDEX_LOROM = 1;
+parameter INDEX_SFIXROM = 2;
+parameter INDEX_P1ROM_A = 4;
+parameter INDEX_P1ROM_B = 5;
+parameter INDEX_P2ROM = 6;
+parameter INDEX_S1ROM = 8;
+parameter INDEX_M1ROM = 9;
+parameter INDEX_MEMCP = 10;
+parameter INDEX_CROM0 = 15;
+parameter INDEX_VROMS = 16;
+parameter INDEX_CROMS = 64;
+
+wire video_mode = status[3];
+
+wire ms5p_bank = cfg[17];
+wire xram = cfg[18];
+wire adpcma_ext = cfg[19];
+wire [2:0] cart_pchip = cfg[22:20];
+wire use_pcm = cfg[23];
+wire [1:0] cart_chip = cfg[25:24]; // legacy option: 0 - none, 1 - PRO-CT0, 2 - Link MCU
+wire [1:0] cmc_chip = cfg[27:26]; // type 1/2
+wire rom_wait = cfg[28]; // ROMWAIT from cart. 0 - Full speed, 1 - 1 wait cycle
+wire [1:0] p_wait = cfg[30:29]; // PWAIT from cart. 0 - Full speed, 1 - 1 wait cycle, 2 - 2 cycles
+wire cd_en = cfg[31]; // Neo CD
+
+// Memory card and backup ram image save/load
+assign sd_rd[0] = bk_rd;
+assign sd_wr[0] = bk_wr;
+assign sd_lba[0] = bk_lba;
+assign sd_buff_din[0] = bk_dout;
+wire bk_ack = sd_ack[0];
+
+assign sd_rd[1] = 0;
+assign sd_wr[1] = 0;
+assign sd_buff_din[1] = 0;
+assign sd_lba[1] = 0;
+
+wire downloading = status[0];
+reg bk_rd, bk_wr;
+reg bk_ena = 0;
+reg bk_pending = 0;
+reg [31:0] bk_lba;
+
+wire bk_autosave = status[24];
+// Memory write flag for backup memory & memory card
+// (~nBWL | ~nBWU) : [AES] Unibios (set to MVS) softdip settings, [MVS] cab settings, dates, timer, high scores, saves, & bookkeeeping
+// CARD_WE : [AES/MVS] game saves and high scores
+wire bk_change = sram_slot_we | CARD_WE;
+wire memcard_change;
+
+reg sram_slot_we;
+always @(posedge clk_sys) begin
+ sram_slot_we <= 0;
+ if(~nBWL | ~nBWU) begin
+ sram_slot_we <= (M68K_ADDR[15:1] >= 'h190 && M68K_ADDR[15:1] < 'h4190);
+ end
+end
+
+always @(posedge clk_sys) begin
+ reg old_downloading = 0;
+
+ old_downloading <= downloading;
+ if(~old_downloading & downloading) bk_ena <= 0;
+
+ // Save file always mounted in the end of downloading state.
+ if(downloading && img_mounted[0] && !img_readonly) bk_ena <= 1;
+
+ // Determine whether file needs to be written
+ if (bk_change) bk_pending <= 1;
+ else if (bk_state) bk_pending <= 0;
+end
+
+wire bk_load = status[21];
+wire bk_save = status[12] | (bk_autosave & OSD_STATUS);
+reg bk_loading = 0;
+reg bk_state = 0;
+
+always @(posedge clk_sys) begin
+ reg old_downloading = 0;
+ reg old_load = 0, old_save = 0, old_ack;
+
+ old_downloading <= downloading;
+
+ old_load <= bk_load;
+ old_save <= bk_save;
+ old_ack <= bk_ack;
+
+ if(~old_ack & bk_ack) {bk_rd, bk_wr} <= 0;
+
+ if(!bk_state) begin
+ if(bk_ena & ((~old_load & bk_load) | (~old_save & bk_save & bk_pending))) begin
+ bk_state <= 1;
+ bk_loading <= bk_load;
+ bk_lba <= 0;
+ bk_rd <= bk_load;
+ bk_wr <= ~bk_load;
+ end
+ // always load backup so it will erase the memory if doesn't exist
+ if(old_downloading & ~downloading & bk_ena) begin
+ bk_state <= 1;
+ bk_loading <= 1;
+ bk_lba <= 0;
+ bk_rd <= 1;
+ bk_wr <= 0;
+ end
+ end else begin
+ if(old_ack & ~bk_ack) begin
+ if (bk_lba >= 'h8F) begin // 64KB + 8KB regardless the selected system
+ bk_loading <= 0;
+ bk_state <= 0;
+ end else begin
+ bk_lba <= bk_lba + 1'd1;
+ bk_rd <= bk_loading;
+ bk_wr <= ~bk_loading;
+ end
+ end
+ end
+end
+
+wire [1:0] CD_REGION;
+always @(status[11:10])
+begin
+ // CD Region code remap:
+ // status[11:10] remap
+ // 00 10 US
+ // 01 01 EU
+ // 10 11 JP
+ // 11 00 ASIA
+ case(status[11:10])
+ 2'b00: CD_REGION = 2'b10;
+ 2'b01: CD_REGION = 2'b01;
+ 2'b10: CD_REGION = 2'b11;
+ 2'b11: CD_REGION = 2'b00;
+ endcase
+end
+
+wire [2:0] CD_TR_AREA; // Transfer area code
+wire [15:0] CD_TR_WR_DATA;
+wire [19:1] CD_TR_WR_ADDR;
+wire [1:0] CD_BANK_SPR;
+
+wire CD_TR_WR_SPR, CD_TR_WR_PCM, CD_TR_WR_Z80, CD_TR_WR_FIX;
+wire CD_TR_RD_SPR, CD_TR_RD_FIX, CD_TR_RD_Z80, CD_TR_RD_PCM;
+wire CD_USE_SPR, CD_USE_FIX, CD_USE_Z80, CD_USE_PCM;
+wire CD_UPLOAD_EN;
+wire CD_BANK_PCM;
+wire CD_IRQ;
+wire CD_VBLANK_IRQ_EN, CD_TIMER_IRQ_EN;
+wire DMA_RUNNING, DMA_WR_OUT, DMA_RD_OUT;
+wire [15:0] DMA_DATA_OUT;
+wire [23:0] DMA_ADDR_IN;
+wire [23:0] DMA_ADDR_OUT;
+
+wire [15:0] DMA_DATA_IN = CD_TR_RD_PCM ? { 8'h00, ADPCMA_DOUT } : PROM_DATA;
+
+wire DMA_SDRAM_BUSY;
+wire PROM_DATA_READY;
+
+wire [15:0] CD_AUDIO_L, CD_AUDIO_R;
+
+//CD communication
+reg [48:0] cd_in;
+wire [48:0] cd_out;
+
+wire [35:0] EXT_BUS;
+
+wire CD_DATA_WR_READY, CDDA_WR_READY;
+
+hps_ext hps_ext
+(
+ .clk_sys(clk_sys),
+ .EXT_BUS(EXT_BUS),
+
+ .cd_data_ready(CD_DATA_WR_READY),
+ .cdda_ready(CDDA_WR_READY),
+
+ .cd_in(cd_in),
+ .cd_out(cd_out)
+);
+
+reg [39:0] CDD_STATUS;
+wire [39:0] CDD_COMMAND_DATA;
+wire CDD_COMMAND_SEND;
+reg CDD_STATUS_LATCH;
+wire [1:0] cd_speed = status[30:29];
+
+always @(posedge clk_sys) begin
+ reg cd_out48_last = 1;
+ reg cdd_send_old = 0;
+
+ CDD_STATUS_LATCH <= 0;
+ if (cd_out[48] != cd_out48_last) begin
+ cd_out48_last <= cd_out[48];
+ CDD_STATUS <= cd_out[39:0];
+ CDD_STATUS_LATCH <= 1;
+ end
+
+ cdd_send_old <= CDD_COMMAND_SEND;
+ if (CDD_COMMAND_SEND && !cdd_send_old) begin
+ cd_in[47:0] <= {6'd0,cd_speed,CDD_COMMAND_DATA};
+ cd_in[48] <= ~cd_in[48];
+ end else begin
+ if (old_reset & ~nRESET) begin
+ cd_in[47:0] <= 8'hFF;
+ cd_in[48] <= ~cd_in[48];
+ end
+ end
+end
+
+//extend ioctl_wr for 16 cycles
+reg ioctl_wr_x;
+always @(posedge clk_sys) begin
+ reg [3:0] cnt = 0;
+
+ if (ioctl_wr) begin
+ cnt <= 4'd15;
+ ioctl_wr_x <= 1;
+ end
+ else if (cnt) begin
+ cnt <= cnt - 1'd1;
+ end
+ else begin
+ ioctl_wr_x <= 0;
+ end
+end
+
+localparam CD_MCLK = 48335658;
+
+wire CDDA_CLK;
+CEGen CEGEN_CDDA_CLK
+(
+ .CLK(CLK_48M),
+ .RST_N(nRESET),
+ .IN_CLK(CD_MCLK),
+ .OUT_CLK(44100),
+ .CE(CDDA_CLK)
+);
+
+wire CD_DATA_DOWNLOAD = ioctl_download & (ioctl_index[5:0] == 6'h02);
+wire CD_DATA_WR = ioctl_wr_x & CD_DATA_DOWNLOAD;
+
+wire CDDA_DOWNLOAD = ioctl_download & (ioctl_index[5:0] == 6'h04);
+wire CDDA_WR = ioctl_wr_x & CDDA_DOWNLOAD;
+
+cd_sys #(.MCLK(CD_MCLK)) cdsystem(
+ .nRESET(nRESET),
+ .clk_sys(CLK_48M), .CLK_68KCLK_EN(CLK_EN_68K_P),
+ .M68K_ADDR(M68K_ADDR), .M68K_DATA(M68K_DATA), .A22Z(A22Z), .A23Z(A23Z),
+ .nLDS(nLDS), .nUDS(nUDS), .M68K_RW(M68K_RW), .nAS(nAS), .nDTACK(nDTACK_ADJ),
+ .nBR(nBR), .nBG(nBG), .nBGACK(nBGACK),
+ .SYSTEM_CDx(SYSTEM_CDx),
+ .CD_REGION(CD_REGION),
+ .CD_SPEED(cd_speed),
+ .CD_LID(~status[15] ^ SYSTEM_CDZ), // CD lid state (DEBUG)
+ .CD_VIDEO_EN(CD_VIDEO_EN), .CD_FIX_EN(CD_FIX_EN), .CD_SPR_EN(CD_SPR_EN),
+ .CD_nRESET_Z80(CD_nRESET_Z80),
+ .CD_TR_WR_SPR(CD_TR_WR_SPR), .CD_TR_WR_PCM(CD_TR_WR_PCM),
+ .CD_TR_WR_Z80(CD_TR_WR_Z80), .CD_TR_WR_FIX(CD_TR_WR_FIX),
+ .CD_TR_RD_FIX(CD_TR_RD_FIX), .CD_TR_RD_SPR(CD_TR_RD_SPR),
+ .CD_TR_RD_Z80(CD_TR_RD_Z80), .CD_TR_RD_PCM(CD_TR_RD_PCM),
+ .CD_USE_FIX(CD_USE_FIX), .CD_USE_SPR(CD_USE_SPR),
+ .CD_USE_Z80(CD_USE_Z80), .CD_USE_PCM(CD_USE_PCM),
+ .CD_TR_AREA(CD_TR_AREA),
+ .CD_BANK_SPR(CD_BANK_SPR), .CD_BANK_PCM(CD_BANK_PCM),
+ .CD_TR_WR_DATA(CD_TR_WR_DATA), .CD_TR_WR_ADDR(CD_TR_WR_ADDR),
+ .CD_UPLOAD_EN(CD_UPLOAD_EN),
+ .CD_IRQ(CD_IRQ), .IACK(IACK),
+ .CD_VBLANK_IRQ_EN(CD_VBLANK_IRQ_EN), .CD_TIMER_IRQ_EN(CD_TIMER_IRQ_EN),
+ .CDD_STATUS_IN(CDD_STATUS), .CDD_STATUS_LATCH(CDD_STATUS_LATCH),
+ .CDD_COMMAND_DATA(CDD_COMMAND_DATA), .CDD_COMMAND_SEND(CDD_COMMAND_SEND),
+ .CD_DATA_DOWNLOAD(CD_DATA_DOWNLOAD), .CD_DATA_WR(CD_DATA_WR),
+ .CD_DATA_DIN(ioctl_dout),
+ .CD_DATA_ADDR(ioctl_addr[11:1]),
+ .CD_DATA_WR_READY(CD_DATA_WR_READY),
+ .CDDA_RD(CDDA_CLK), .CDDA_WR(CDDA_WR),
+ .CD_AUDIO_L(CD_AUDIO_L), .CD_AUDIO_R(CD_AUDIO_R),
+ .CDDA_WR_READY(CDDA_WR_READY),
+ .DMA_RUNNING(DMA_RUNNING),
+ .DMA_DATA_IN(DMA_DATA_IN), .DMA_DATA_OUT(DMA_DATA_OUT),
+ .DMA_WR_OUT(DMA_WR_OUT), .DMA_RD_OUT(DMA_RD_OUT),
+ .DMA_ADDR_IN(DMA_ADDR_IN), // Used for reading
+ .DMA_ADDR_OUT(DMA_ADDR_OUT), // Used for writing
+ .DMA_SDRAM_BUSY(DMA_SDRAM_BUSY | ddram_wait | ADPCMA_RD_WAIT)
+);
+
+// The P1 zone is writable on the Neo CD
+// Is there a write enable register for it ?
+wire CD_EXT_WR = DMA_RUNNING ? (SYSTEM_CDx & (DMA_ADDR_OUT[23:21] == 3'd0) & DMA_WR_OUT) : // DMA writes to $000000~$1FFFFF
+ (SYSTEM_CDx & ~|{A23Z, A22Z, M68K_ADDR[21]} & ~M68K_RW & ~(nLDS & nUDS)); // CPU writes to $000000~$1FFFFF
+
+wire nROMOE = nROMOEL & nROMOEU;
+wire nPORTOE = nPORTOEL & nPORTOEU;
+
+// CD system work ram is in SDRAM
+wire CD_EXT_RD = DMA_RUNNING ? (SYSTEM_CDx & (DMA_ADDR_IN[23:21] == 3'd0) & DMA_RD_OUT) : // DMA reads from $000000~$1FFFFF
+ (SYSTEM_CDx & (~nWRL | ~nWRU)); // CPU reads from $100000~$1FFFFF
+
+wire sdram_ready;
+wire [26:1] sdram_addr;
+wire [15:0] sdram_dout;
+wire [15:0] sdram_din;
+
+// ioctl_download is used to load the system ROM on CD systems, we need it !
+reg ioctl_en;
+always_ff @(posedge clk_sys) begin
+ ioctl_en <= SYSTEM_CDx ? (ioctl_index == INDEX_SPROM) :
+ (ioctl_index != INDEX_LOROM && ioctl_index != INDEX_M1ROM && ioctl_index != INDEX_MEMCP && (ioctl_index < INDEX_VROMS || ioctl_index >= INDEX_CROMS));
+end
+
+wire [26:0] CROM_LOAD_ADDR = ({ioctl_addr[25:0], 1'b0} + {ioctl_index[7:1]-INDEX_CROMS[7:1], 18'h00000, ioctl_index[0], 1'b0});
+wire [26:0] VROM_LOAD_ADDR = ({1'b0, ioctl_addr[25:0]} + {ioctl_index[7:0]-INDEX_VROMS[7:0], 19'h00000});
+
+localparam SPROM_OFFSET = 27'h0000000; // System ROM: $0000000~$007FFFF
+localparam SFIXROM_OFFSET = 27'h0020000; // SFIX: $0020000~$003FFFF (in sys ROM)
+localparam S1ROM_OFFSET = 27'h0080000; // S1: $0080000~$00FFFFF
+localparam P1ROM_A_OFFSET = 27'h0200000; // P1+: $0200000~...
+localparam P1ROM_B_OFFSET = 27'h0280000; // P1: $0280000~$02FFFFF (secondary 512KB)
+localparam P2ROM_OFFSET = 27'h0300000; // P2+: $0300000~...
+
+wire [26:0] ioctl_addr_offset =
+ (ioctl_index == INDEX_SPROM) ? {SPROM_OFFSET[26:19] , ioctl_addr[18:0]} : // System ROM: $0000000~$007FFFF
+ (ioctl_index == INDEX_SFIXROM) ? {SFIXROM_OFFSET[26:17], ioctl_addr[16:0]} : // SFIX: $0020000~$003FFFF (in sys ROM)
+ (ioctl_index == INDEX_S1ROM) ? {S1ROM_OFFSET[26:19] , ioctl_addr[18:0]} : // S1: $0080000~$00FFFFF
+ (ioctl_index == INDEX_P1ROM_A) ? P1ROM_A_OFFSET + ioctl_addr : // P1+: $0200000~...
+ (ioctl_index == INDEX_P1ROM_B) ? {P1ROM_B_OFFSET[26:19], ioctl_addr[18:0]} : // P1: $0280000~$02FFFFF (secondary 512KB)
+ (ioctl_index == INDEX_P2ROM) ? P2ROM_OFFSET + ioctl_addr : // P2+: $0300000~...
+ (ioctl_index == INDEX_CROM0) ? {CROM_START, 20'd0} + ioctl_addr : // C: end of P, consolidated CROM
+ (ioctl_index >= INDEX_CROMS) ? {CROM_START, 20'd0} + CROM_LOAD_ADDR : // C*: end of P
+ 27'h0100000; // undefined case, use work RAM address to make sure no ROM gets overwritten
+
+reg [6:0] CROM_START;
+reg [26:0] P2ROM_MASK, CROM_MASK, V1ROM_MASK, V2ROM_MASK, MROM_MASK;
+always_ff @(posedge clk_sys) begin
+ reg old_rst;
+ reg old_download;
+
+ old_rst <= status[0];
+
+ if(status[0]) begin
+ if (SYSTEM_CDx) begin
+ CROM_MASK <= 27'h3FFFFF; // 4MB
+ V1ROM_MASK <= 27'hFFFFF; // 1MB
+ MROM_MASK <= 27'hFFFF; // 64KB
+ end else begin
+ P2ROM_MASK <= P2ROM_MASK | P2ROM_MASK[26:1];
+ CROM_MASK <= CROM_MASK | CROM_MASK[26:1];
+ V1ROM_MASK <= adpcma_ext ? 27'h1FFFFFF : (V1ROM_MASK | V1ROM_MASK[26:1]);
+ V2ROM_MASK <= adpcma_ext ? 27'h0 : (V2ROM_MASK | V2ROM_MASK[26:1]);
+ MROM_MASK <= MROM_MASK | MROM_MASK[26:1];
+ end
+ end
+
+ if(ioctl_wr) begin
+ if(ioctl_index >= INDEX_CROMS) CROM_MASK <= CROM_MASK | CROM_LOAD_ADDR;
+ else if(ioctl_index >= INDEX_VROMS) begin
+ if(~VROM_LOAD_ADDR[24]) V1ROM_MASK <= V1ROM_MASK | VROM_LOAD_ADDR;
+ else V2ROM_MASK <= V2ROM_MASK | VROM_LOAD_ADDR;
+ end
+ else if(ioctl_index == INDEX_CROM0) CROM_MASK <= CROM_MASK | ioctl_addr;
+ else if(ioctl_index == INDEX_M1ROM) MROM_MASK <= MROM_MASK | ioctl_addr;
+ else if(ioctl_index == INDEX_P2ROM || ioctl_index == INDEX_P1ROM_A) begin
+ if(ioctl_addr_offset >= P2ROM_OFFSET) P2ROM_MASK <= P2ROM_MASK | (ioctl_addr_offset - P2ROM_OFFSET);
+ end
+
+ if(ioctl_index == INDEX_MEMCP && ioctl_addr == 6 && cp_op) begin
+ if(cp_idx >= INDEX_VROMS) begin
+ if(cp_idx < (INDEX_VROMS+32)) V1ROM_MASK <= V1ROM_MASK | (cp_end[23:0]-1'd1);
+ else V2ROM_MASK <= V2ROM_MASK | (cp_end[23:0]-1'd1);
+ end
+ else if(cp_idx == INDEX_CROM0) CROM_MASK <= CROM_MASK | (cp_size-1'd1);
+ else if(cp_idx == INDEX_M1ROM) MROM_MASK <= MROM_MASK | (cp_size-1'd1);
+ else if(cp_idx == INDEX_P2ROM || cp_idx == INDEX_P1ROM_A) begin
+ if((cp_end-1'd1)>=P2ROM_OFFSET) P2ROM_MASK <= P2ROM_MASK | (cp_end - P2ROM_OFFSET - 1'd1);
+ end
+
+ if(cp_idx == INDEX_P2ROM || cp_idx == INDEX_P1ROM_A) begin
+ if(CROM_START < cp_end[26:20]) CROM_START <= cp_end[26:20];
+ end
+ end
+
+ if(old_download && ~ioctl_download && (ioctl_index == INDEX_P2ROM || ioctl_index == INDEX_P1ROM_A)) begin
+ if(CROM_START < ioctl_addr_offset[26:20]) CROM_START <= ioctl_addr_offset[26:20];
+ end
+ end
+
+ if(~old_rst & status[0]) begin
+ CROM_MASK <= 0;
+ V1ROM_MASK <= 0;
+ V2ROM_MASK <= 0;
+ MROM_MASK <= 0;
+ P2ROM_MASK <= 0;
+ CROM_START <= 3;
+ end
+
+ old_download <= ioctl_download;
+ if(old_download && ~ioctl_download && (ioctl_index == INDEX_P2ROM || ioctl_index == INDEX_P1ROM_A)) begin
+ if(CROM_START < ioctl_addr_offset[26:20]) CROM_START <= ioctl_addr_offset[26:20];
+ end
+end
+
+reg [26:0] ioctl_addr_r;
+reg ioctl_wr_r;
+always @(posedge clk_sys) begin
+ ioctl_addr_r <= ioctl_addr_offset;
+ ioctl_wr_r <= ioctl_wr;
+end
+
+reg ioctl_wr_rd, ioctl_wr_rd1;
+always @(posedge CLK_96M) begin
+ ioctl_wr_rd <= ioctl_wr_r;
+ ioctl_wr_rd1 <= ioctl_wr_rd;
+end
+
+wire SDRAM_WR;
+wire SDRAM_RD;
+wire SDRAM_RFSH;
+wire [1:0] SDRAM_BS;
+wire sdr2_en;
+
+sdram_mux SDRAM_MUX(
+ .CLK(CLK_96M),
+ .nRESET(nRESET),
+ .nSYSTEM_G(nSYSTEM_G),
+ .SYSTEM_CDx(SYSTEM_CDx),
+
+ .M68K_ADDR(M68K_ADDR),
+ .M68K_DATA(M68K_DATA),
+ .nAS(nAS | (FC1 == FC0)),
+ .nLDS(nLDS),
+ .nUDS(nUDS),
+ .nROMOE(nROMOE),
+ .nPORTOE(nPORTOE),
+ .nSROMOE(nSROMOE),
+ .DATA_TYPE(~FC1 & FC0), // 0 - program, 1 - data,
+ .P2ROM_ADDR(P2ROM_ADDR & P2ROM_MASK),
+ .PROM_DATA(PROM_DATA),
+ .PROM_DATA_READY(PROM_DATA_READY),
+
+ .CD_TR_AREA(CD_TR_AREA),
+ .CD_EXT_WR(CD_EXT_WR),
+ .CD_EXT_RD(CD_EXT_RD),
+ .CD_USE_FIX(CD_USE_FIX),
+ .CD_TR_RD_FIX(CD_TR_RD_FIX),
+ .CD_TR_WR_FIX(CD_TR_WR_FIX),
+ .CD_BANK_SPR(CD_BANK_SPR),
+ .CD_USE_SPR(CD_USE_SPR),
+ .CD_TR_RD_SPR(CD_TR_RD_SPR),
+ .CD_TR_WR_SPR(CD_TR_WR_SPR),
+
+ .DMA_ADDR_OUT(DMA_ADDR_OUT),
+ .DMA_ADDR_IN(DMA_ADDR_IN),
+ .DMA_DATA_OUT(DMA_DATA_OUT),
+ .DMA_RUNNING(DMA_RUNNING),
+ .DMA_SDRAM_BUSY(DMA_SDRAM_BUSY),
+
+ .PCK1(PCK1),
+ .SPR_EN(SPR_EN),
+ .CROM_ADDR({CROM_ADDR[26:20] + (SYSTEM_CDx ? 7'd8 : CROM_START), CROM_ADDR[19:0]}),
+ .CR_DOUBLE(CR_DOUBLE),
+
+ .PCK2(PCK2),
+ .S_LATCH(S_LATCH),
+ .FIX_BANK(FIX_BANK),
+ .FIX_EN(FIX_EN),
+
+ .SROM_DATA(SROM_DATA),
+
+ .DL_EN(ioctl_download & ioctl_en),
+ .DL_ADDR(ioctl_addr_r),
+ .DL_DATA(ioctl_dout),
+ .DL_WR(~ioctl_wr_rd1 & ioctl_wr_rd),
+
+ .REFRESH_EN(RFSH),
+
+ .SDRAM_ADDR(sdram_addr),
+ .SDRAM_DOUT(sdram_dout),
+ .SDRAM_DIN(sdram_din),
+ .SDRAM_WR(SDRAM_WR),
+ .SDRAM_RD(SDRAM_RD),
+ .SDRAM_RFSH(SDRAM_RFSH),
+ .SDRAM_BS(SDRAM_BS),
+ .SDRAM_READY(sdram_ready)
+);
+
+reg [1:0] sdr_pri_128_64;
+wire sdr_pri_cpsel = (~sdr_cpaddr[26] | sdr_pri_128_64[1]) & (~sdr_cpaddr[25] | sdr_pri_128_64[0]);
+always @(posedge CLK_96M) if (~nRESET) sdr_pri_128_64 <= {~sdram_sz[14] & &sdram_sz[1:0], ~sdram_sz[14] & sdram_sz[1]};
+
+wire sdram1_ready, sdram2_ready;
+wire [15:0] sdram1_dout, sdram2_dout;
+
+sdram ram1(
+ .SDRAM_CLK(SDRAM_CLK),
+ .SDRAM_CKE(SDRAM_CKE),
+ .SDRAM_A(SDRAM_A),
+ .SDRAM_BA(SDRAM_BA),
+ .SDRAM_DQ(SDRAM_DQ),
+ .SDRAM_DQML(SDRAM_DQML),
+ .SDRAM_DQMH(SDRAM_DQMH),
+ .SDRAM_nCS(SDRAM_nCS),
+ .SDRAM_nCAS(SDRAM_nCAS),
+ .SDRAM_nRAS(SDRAM_nRAS),
+ .SDRAM_nWE(SDRAM_nWE),
+ .SDRAM_EN(1),
+
+ .init(~locked), // Init SDRAM as soon as the PLL is locked
+ .clk(CLK_96M),
+ .addr(sdram_addr[26:1]),
+ .sel(sdr_pri_sel),
+ .dout(sdram1_dout),
+ .din(sdram_din),
+ .bs(SDRAM_BS),
+ .wr(SDRAM_WR),
+ .rd(SDRAM_RD),
+ .refresh(SDRAM_RFSH),
+ .ready(sdram1_ready),
+
+ .cpsel(sdr_pri_cpsel),
+ .cpaddr(sdr_cpaddr[26:1]),
+ .cpdin(sdr_cpdin),
+ .cprd(sdr1_cprd),
+ .cpreq(sdr_cpreq),
+ .cpbusy(sdr1_cpbusy)
+);
+
+`ifdef MISTER_DUAL_SDRAM
+sdram ram2(
+ .SDRAM_CLK(SDRAM2_CLK),
+ .SDRAM_A(SDRAM2_A),
+ .SDRAM_BA(SDRAM2_BA),
+ .SDRAM_DQ(SDRAM2_DQ),
+ .SDRAM_nCS(SDRAM2_nCS),
+ .SDRAM_nCAS(SDRAM2_nCAS),
+ .SDRAM_nRAS(SDRAM2_nRAS),
+ .SDRAM_nWE(SDRAM2_nWE),
+ .SDRAM_EN(SDRAM2_EN),
+
+ .init(~locked), // Init SDRAM as soon as the PLL is locked
+ .clk(CLK_96M),
+ .addr(sdram_addr[25:1]),
+ .sel(~sdr_pri_sel),
+ .dout(sdram2_dout),
+ .din(sdram_din),
+ .bs(SDRAM_BS),
+ .wr(SDRAM_WR),
+ .rd(SDRAM_RD),
+ .refresh(SDRAM_RFSH),
+ .ready(sdram2_ready),
+
+ .cpsel(~sdr_pri_cpsel),
+ .cpaddr(sdr_cpaddr[25:1]),
+ .cpdin(sdr_cpdin),
+ .cprd(sdr2_cprd),
+ .cpreq(sdr_cpreq),
+ .cpbusy(sdr2_cpbusy)
+);
+
+wire sdr_pri_sel = (~sdram_addr[26] | sdr_pri_128_64[1]) & (~sdram_addr[25] | sdr_pri_128_64[0]);
+assign sdr2_en = SDRAM2_EN;
+`else
+wire sdr_pri_sel = 1;
+assign sdram2_dout = '0;
+assign sdram2_ready = 1;
+assign sdr2_cprd = 0;
+assign sdr2_cpbusy = 0;
+assign sdr2_en = 0;
+`endif
+
+assign sdram_dout = sdr_pri_sel ? sdram1_dout : sdram2_dout;
+assign sdram_ready = sdram2_ready & sdram1_ready;
+
+wire [2:0] P1_OUT, P2_OUT;
+
+neo_d0 D0(
+ .CLK(CLK_48M),
+ .CLK_EN_24M_P(CLK_EN_24M_P),
+ .CLK_EN_24M_N(CLK_EN_24M_N),
+ .nRESET(nRESET), .nRESETP(nRESETP),
+ .CLK_68KCLK(CLK_68KCLK), .CLK_68KCLKB(CLK_68KCLKB), .CLK_EN_12M(CLK_EN_12M), .CLK_EN_12M_N(CLK_EN_12M_N), .CLK_EN_6MB(CLK_EN_6MB), .CLK_EN_1HB(CLK_EN_1HB),
+ .CLK_EN_68K_P(CLK_EN_68K_P), .CLK_EN_68K_N(CLK_EN_68K_N),
+ .M68K_ADDR_A4(M68K_ADDR[4]),
+ .M68K_DATA(M68K_DATA[5:0]),
+ .nBITWD0(nBITWD0),
+ .SDA_H(SDA[15:11]), .SDA_L(SDA[4:2]),
+ .nSDRD(nSDRD), .nSDWR(nSDWR), .nMREQ(nMREQ), .nIORQ(nIORQ),
+ .nZ80NMI(Z80_nNMI),
+ .nSDW(nSDW), .nSDZ80R(nSDZ80R), .nSDZ80W(nSDZ80W), .nSDZ80CLR(nSDZ80CLR),
+ .nSDROM(nSDROM), .nSDMRD(nSDMRD), .nSDMWR(nSDMWR), .nZRAMCS(nZRAMCS),
+ .SDRD0(SDRD0), .SDRD1(SDRD1),
+ .n2610CS(n2610CS), .n2610RD(n2610RD), .n2610WR(n2610WR),
+ .P1_OUT(P1_OUT), .P2_OUT(P2_OUT),
+ .BNK(BNK)
+);
+
+// Re-priority-encode the interrupt lines with the CD_IRQ one (IPL* are active-low)
+//
+// IPL2 IPL1 IPL0 Cartridge CD
+// 1 1 1 No IRQ No IRQ
+// 1 1 0 Vblank (64) Vblank (68)
+// 1 0 1 Timer (68) CD IRQ (54/58)
+// 1 0 0 Cold boot (6C) Timer (64)
+//
+wire [1:0] CD_IPL = {IPL1,IPL0} == 2'b01 ? 2'b00 // Level 3 Timer
+ : CD_IRQ ? 2'b01 // Level 2 CD IRQ
+ : {IPL1,IPL0} == 2'b10 ? 2'b10 // Level 1 VBlank
+ : 2'b11;
+
+wire [1:0] IPL_OUT = ~SYSTEM_CDx ? { IPL1,IPL0 } : CD_IPL;
+
+// Because of the SDRAM latency, nDTACK is handled differently for ROM zones
+// If the address is in a ROM zone, PROM_DATA_READY is used to extend the normal nDTACK output by NEO-C1
+wire nDTACK_ADJ = ~&{nSROMOE, nROMOE, nPORTOE, ~CD_EXT_RD, ~CD_TR_RD_FIX, ~CD_TR_RD_SPR} ? ~PROM_DATA_READY | nDTACK
+ : (CD_TR_WR_PCM) ? ~ddram_dtack | nDTACK
+ : (CD_TR_RD_PCM) ? ~ADPCMA_RD_DTACK | nDTACK
+ : nDTACK;
+
+cpu_68k M68KCPU(
+ .CLK(CLK_48M),
+ .CLK_EN_68K_P(CLK_EN_68K_P),
+ .CLK_EN_68K_N(CLK_EN_68K_N),
+ .nRESET(nRESET),
+ .M68K_ADDR(M68K_ADDR),
+ .FX68K_DATAIN(FX68K_DATAIN), .FX68K_DATAOUT(FX68K_DATAOUT),
+ .nLDS(nLDS), .nUDS(nUDS), .nAS(nAS), .M68K_RW(M68K_RW),
+ .nDTACK(nDTACK_ADJ), // nDTACK
+ .IPL2(1'b1), .IPL1(IPL_OUT[1]), .IPL0(IPL_OUT[0]),
+ .FC2(FC2), .FC1(FC1), .FC0(FC0),
+ .nBG(nBG), .nBR(nBR), .nBGACK(nBGACK),
+ .SYSTEM_CDx(SYSTEM_CDx)
+);
+
+wire IACK = &{FC2, FC1, FC0};
+
+// FX68K doesn't like byte masking with Z's, replace with 0's:
+assign M68K_DATA_BYTE_MASK = (~|{nLDS, nUDS}) ? M68K_DATA :
+ (~nLDS) ? {8'h00, M68K_DATA[7:0]} :
+ (~nUDS) ? {M68K_DATA[15:8], 8'h00} :
+ 16'h0000;
+
+assign M68K_DATA = M68K_RW ? 16'bzzzzzzzz_zzzzzzzz : FX68K_DATAOUT;
+assign FX68K_DATAIN = M68K_RW ? M68K_DATA_BYTE_MASK : 16'h0000;
+
+assign FIXD = CD_USE_FIX ? 8'bzzzz_zzzz : S2H1 ? SROM_DATA[15:8] : SROM_DATA[7:0];
+
+// Disable ROM read in PORT zone if the game uses a special chip
+assign M68K_DATA = (nROMOE & nSROMOE & ~CD_TR_RD_SPR & |{nPORTOE, cart_chip, cart_pchip, xram, CD_TR_RD_FIX}) ? 16'bzzzzzzzzzzzzzzzz : PROM_DATA;
+
+// Output correct FIX byte
+assign M68K_DATA[7:0] = ~CD_TR_RD_FIX ? 8'bzzzz_zzzz : (M68K_ADDR[4] ? PROM_DATA[15:8] : PROM_DATA[7:0]);
+
+// Neo CD 68k work RAM is in SDRAM so we can use this for Z80 RAM instead.
+assign WRAM_ADDR = SYSTEM_CDx ? SDA[15:1] : M68K_ADDR[15:1];
+assign { WRAMU_DATA, WRAML_DATA } = SYSTEM_CDx ? { SDD_OUT, SDD_OUT } : { M68K_DATA[15:0] };
+assign WRAMU_WREN = SYSTEM_CDx ? (~nSDMWR & SDA[0]) : ~nWWU;
+assign WRAML_WREN = SYSTEM_CDx ? (~nSDMWR & ~SDA[0]) : ~nWWL;
+
+// 68k/Z80 work RAM
+dpram #(15) WRAML(
+ .clock_a(CLK_48M),
+ .address_a(WRAM_ADDR),
+ .data_a(WRAML_DATA),
+ .wren_a(WRAML_WREN),
+ .q_a(WRAML_OUT),
+
+ .clock_b(CLK_48M),
+ .address_b(TRASH_ADDR),
+ .data_b(TRASH_ADDR[7:0]),
+ .wren_b(~nRESET_CORE)
+);
+
+dpram #(15) WRAMU(
+ .clock_a(CLK_48M),
+ .address_a(WRAM_ADDR),
+ .data_a(WRAMU_DATA),
+ .wren_a(WRAMU_WREN),
+ .q_a(WRAMU_OUT),
+
+ .clock_b(CLK_48M),
+ .address_b(TRASH_ADDR),
+ .data_b(TRASH_ADDR[7:0]),
+ .wren_b(~nRESET_CORE)
+);
+
+wire [23:0] P2ROM_ADDR_PVC, P2ROM_ADDR_SMA;
+wire [23:0] P2ROM_ADDR = cart_pchip ? (P2ROM_ADDR_PVC | P2ROM_ADDR_SMA) : {P_BANK, M68K_ADDR[19:1], 1'b0};
+
+neo_pvc neo_pvc
+(
+ .nRESET(nRESET),
+ .CLK_48M(CLK_48M),
+
+ .ENABLE(cart_pchip == 2),
+
+ .M68K_ADDR(M68K_ADDR),
+ .M68K_DATA(M68K_DATA),
+ .PROM_DATA(PROM_DATA),
+ .nPORTOEL(nPORTOEL),
+ .nPORTOEU(nPORTOEU),
+ .nPORTWEL(nPORTWEL),
+ .nPORTWEU(nPORTWEU),
+ .P2_ADDR(P2ROM_ADDR_PVC)
+);
+
+neo_sma neo_sma
+(
+ .nRESET(nRESET),
+ .CLK_48M(CLK_48M),
+
+ .TYPE(cart_pchip),
+
+ .M68K_ADDR(M68K_ADDR),
+ .M68K_DATA(M68K_DATA),
+ .PROM_DATA(PROM_DATA),
+ .nPORTOEL(nPORTOEL),
+ .nPORTOEU(nPORTOEU),
+ .nPORTWEL(nPORTWEL),
+ .nPORTWEU(nPORTWEU),
+ .P2_ADDR(P2ROM_ADDR_SMA)
+);
+
+wire XRAM_CS = ~nPORTADRS && !M68K_ADDR[19:13] && xram;
+wire [15:0] XRAM_OUT;
+wire [15:0] xram_buff_dout;
+
+dpram #(12) XRAML(
+ .clock_a(CLK_48M),
+ .address_a(M68K_ADDR[12:1]),
+ .data_a(M68K_DATA[7:0]),
+ .wren_a(~nPORTWEL & XRAM_CS),
+ .q_a(XRAM_OUT[7:0]),
+
+ .clock_b(clk_sys),
+ .address_b(memcard_addr),
+ .wren_b(memcard_wr & xram),
+ .data_b(sd_buff_dout[7:0]),
+ .q_b(xram_buff_dout[7:0])
+);
+
+dpram #(12) XRAMU(
+ .clock_a(CLK_48M),
+ .address_a(M68K_ADDR[12:1]),
+ .data_a(M68K_DATA[15:8]),
+ .wren_a(~nPORTWEU & XRAM_CS),
+ .q_a(XRAM_OUT[15:8]),
+
+ .clock_b(clk_sys),
+ .address_b(memcard_addr),
+ .wren_b(memcard_wr & xram),
+ .data_b(sd_buff_dout[15:8]),
+ .q_b(xram_buff_dout[15:8])
+);
+
+assign M68K_DATA[7:0] = (XRAM_CS & ~nPORTOEL) ? XRAM_OUT[7:0] : 8'bZ;
+assign M68K_DATA[15:8] = (XRAM_CS & ~nPORTOEU) ? XRAM_OUT[15:8] : 8'bZ;
+
+assign M68K_DATA[7:0] = (~nPORTOEL && M68K_ADDR[19] && !M68K_ADDR[18:1] && xram) ? {~joystick_0[8],1'b1,~joystick_0[9],~joystick_0[11],2'b11, ~joystick_1[10],~joystick_0[10]} : 8'bZ;
+
+// Work RAM or CD extended RAM read
+assign M68K_DATA[7:0] = nWRL ? 8'bzzzzzzzz : SYSTEM_CDx ? PROM_DATA[7:0] : WRAML_OUT;
+assign M68K_DATA[15:8] = nWRU ? 8'bzzzzzzzz : SYSTEM_CDx ? PROM_DATA[15:8] : WRAMU_OUT;
+
+wire save_wr = sd_buff_wr & bk_ack;
+wire sram_wr = ~bk_lba[7] & save_wr; // 000000~00FFFF
+wire memcard_wr = bk_lba[7] & save_wr; // 010000-011FFF
+wire [14:0] sram_addr = {bk_lba[6:0], sd_buff_addr}; //64KB
+wire [11:0] memcard_addr = {bk_lba[3:0], sd_buff_addr}; //8KB
+
+// Backup RAM
+wire nBWL = nSRAMWEL | nSRAMWEN_G;
+wire nBWU = nSRAMWEU | nSRAMWEN_G;
+
+wire [15:0] sram_buff_dout;
+backup BACKUP
+(
+ .CLK(CLK_48M),
+ .M68K_ADDR(M68K_ADDR[15:1]),
+ .M68K_DATA(M68K_DATA),
+ .nBWL(nBWL), .nBWU(nBWU),
+ .SRAM_OUT(SRAM_OUT),
+ .clk_sys(clk_sys),
+ .sram_addr(sram_addr),
+ .sram_wr(sram_wr),
+ .sd_buff_dout(sd_buff_dout),
+ .sd_buff_din_sram(sram_buff_dout)
+);
+
+// Backup RAM is only for MVS
+assign M68K_DATA[7:0] = (nSRAMOEL | ~SYSTEM_MVS) ? 8'bzzzzzzzz : SRAM_OUT[7:0];
+assign M68K_DATA[15:8] = (nSRAMOEU | ~SYSTEM_MVS) ? 8'bzzzzzzzz : SRAM_OUT[15:8];
+
+// Memory card
+assign {nCD1, nCD2} = {2{status[4] & ~SYSTEM_CDx}}; // Always plugged in CD systems
+assign CARD_WE = (SYSTEM_CDx | (~nCARDWEN & CARDWENB)) & ~nCRDW;
+
+wire [15:0] memcard_buff_dout;
+memcard MEMCARD(
+ .CLK(CLK_48M),
+ .SYSTEM_CDx(SYSTEM_CDx),
+ .CDA(CDA), .CDD(CDD),
+ .CARD_WE(CARD_WE),
+ .M68K_DATA(M68K_DATA[7:0]),
+ .clk_sys(clk_sys),
+ .memcard_addr(memcard_addr),
+ .memcard_wr(memcard_wr),
+ .memcard_din(sd_buff_dout),
+ .memcard_dout(memcard_buff_dout)
+);
+
+// Feed save file writer with backup RAM data or memory card data
+wire [15:0] bk_dout = ~bk_lba[7] ? sram_buff_dout : xram ? xram_buff_dout : memcard_buff_dout;
+
+assign CROM_ADDR = {C_LATCH_EXT, C_LATCH, 3'b000} & CROM_MASK;
+
+zmc ZMC(
+ .CLK(CLK_48M),
+ .nRESET(nRESET),
+ .nSDRD0(SDRD0),
+ .SDA_L(SDA[1:0]), .SDA_U(SDA[15:8]),
+ .MA(MA)
+);
+
+// Bankswitching for the PORT zone, do all games use a 1MB window ?
+// P_BANK stays at 0 for CD systems
+always @(posedge CLK_48M)
+begin
+ reg nPORTWEL_d;
+ nPORTWEL_d <= nPORTWEL;
+
+ if (!nRESET || SYSTEM_CDx) P_BANK <= 0;
+ else if (~nPORTWEL & nPORTWEL_d) begin
+ if(~ms5p_bank) P_BANK <= M68K_DATA[3:0];
+ else if(&M68K_ADDR[19:4] && M68K_ADDR[3:1] == 2) P_BANK <= M68K_DATA[7:4] - 1'd1;
+ end
+end
+
+// PRO-CT0 used as security chip
+wire [3:0] GAD_SEC;
+wire [3:0] GBD_SEC;
+
+reg nPORTWEL_D;
+always @(posedge CLK_48M) nPORTWEL_D <= nPORTWEL;
+
+zmc2_dot ZMC2DOT(
+ .CLK(CLK_48M),
+ .CLK_EN_12M_N(nPORTWEL_D & ~nPORTWEL),
+ .EVEN(M68K_ADDR[2]), .LOAD(M68K_ADDR[1]), .H(M68K_ADDR[3]),
+ .CR({
+ M68K_ADDR[19], M68K_ADDR[15], M68K_ADDR[18], M68K_ADDR[14],
+ M68K_ADDR[17], M68K_ADDR[13], M68K_ADDR[16], M68K_ADDR[12],
+ M68K_ADDR[11], M68K_ADDR[7], M68K_ADDR[10], M68K_ADDR[6],
+ M68K_ADDR[9], M68K_ADDR[5], M68K_ADDR[8], M68K_ADDR[4],
+ M68K_DATA[15], M68K_DATA[11], M68K_DATA[14], M68K_DATA[10],
+ M68K_DATA[13], M68K_DATA[9], M68K_DATA[12], M68K_DATA[8],
+ M68K_DATA[7], M68K_DATA[3], M68K_DATA[6], M68K_DATA[2],
+ M68K_DATA[5], M68K_DATA[1], M68K_DATA[4], M68K_DATA[0]
+ }),
+ .GAD(GAD_SEC), .GBD(GBD_SEC)
+);
+
+assign M68K_DATA[7:0] = ((cart_chip == 1) & ~nPORTOEL) ?
+ {GBD_SEC[1], GBD_SEC[0], GBD_SEC[3], GBD_SEC[2],
+ GAD_SEC[1], GAD_SEC[0], GAD_SEC[3], GAD_SEC[2]} : 8'bzzzzzzzz;
+
+neo_273 NEO273(
+ .CLK(CLK_48M),
+ .PBUS(PBUS[19:0]),
+ .PCK1B_EN(PCK1_EN_N), .PCK2B_EN(PCK2_EN_N),
+ .C_LATCH(C_LATCH), .S_LATCH(S_LATCH)
+);
+
+// 4 MSBs not handled by NEO-273
+always @(posedge CLK_48M) begin
+ if (PCK1_EN_N) C_LATCH_EXT <= PBUS[23:20];
+end
+
+neo_cmc neo_cmc
+(
+ .CLK(CLK_48M),
+ .PCK2B_EN(PCK2_EN_N),
+ .PBUS(PBUS[14:0]),
+ .TYPE(cmc_chip),
+ .ADDR(FIXMAP_ADDR),
+ .BANK(FIX_BANK)
+);
+
+
+// Fake COM MCU
+wire [15:0] COM_DOUT;
+
+com COM(
+ .nRESET(nRESET),
+ .CLK_48M(CLK_48M),
+ .nPORTOEL(nPORTOEL), .nPORTOEU(nPORTOEU), .nPORTWEL(nPORTWEL),
+ .M68K_DIN(COM_DOUT)
+);
+
+assign M68K_DATA = (cart_chip == 2) ? COM_DOUT : 16'bzzzzzzzz_zzzzzzzz;
+
+syslatch SL(
+ .nRESET(nRESET),
+ .CLK(CLK_48M),
+ .CLK_EN_68K_P(CLK_EN_68K_P),
+ .M68K_ADDR(M68K_ADDR[4:1]),
+ .nBITW1(nBITW1),
+ .SHADOW(SHADOW), .nVEC(nVEC), .nCARDWEN(nCARDWEN), .CARDWENB(CARDWENB), .nREGEN(nREGEN), .nSYSTEM(nSYSTEM), .nSRAMWEN(nSRAMWEN), .PALBNK(PALBNK)
+);
+
+wire nSRAMWEN_G = SYSTEM_MVS ? nSRAMWEN : 1'b1; // nSRAMWEN is only for MVS
+wire nSYSTEM_G = SYSTEM_MVS ? nSYSTEM : 1'b1; // nSYSTEM is only for MVS
+
+neo_e0 E0(
+ .M68K_ADDR(M68K_ADDR[23:1]),
+ .BNK(BNK),
+ .nSROMOEU(nSROMOEU), .nSROMOEL(nSROMOEL), .nSROMOE(nSROMOE),
+ .nVEC(nVEC),
+ .A23Z(A23Z), .A22Z(A22Z),
+ .CDA(CDA)
+);
+
+neo_f0 F0(
+ .CLK(CLK_48M),
+ .nRESET(nRESET),
+ .nDIPRD0(nDIPRD0), .nDIPRD1(nDIPRD1),
+ .nBITW0(nBITW0), .nBITWD0(nBITWD0),
+ .DIPSW({~status[9:8], 5'b11111, ~status[7]}),
+ .COIN1(~joystick_0[10]), .COIN2(~joystick_1[10]),
+ .M68K_ADDR(M68K_ADDR[7:4]),
+ .M68K_DATA(M68K_DATA[7:0]),
+ .SYSTEMB(~nSYSTEM_G),
+ .RTC_DOUT(RTC_DOUT), .RTC_TP(RTC_TP), .RTC_DIN(RTC_DIN), .RTC_CLK(RTC_CLK), .RTC_STROBE(RTC_STROBE),
+ .SYSTEM_TYPE(SYSTEM_MVS)
+);
+
+uPD4990 RTC(
+ .rtc(rtc),
+ .nRESET(nRESET),
+ .CLK(CLK_48M),
+ .CLK_EN_12M(CLK_EN_12M),
+ .DATA_CLK(RTC_CLK), .STROBE(RTC_STROBE),
+ .DATA_IN(RTC_DIN), .DATA_OUT(RTC_DOUT),
+ .CS(1'b1), .OE(1'b1),
+ .TP(RTC_TP)
+);
+
+neo_g0 G0(
+ .M68K_DATA(M68K_DATA),
+ .G0(nCRDC), .G1(nPAL), .DIR(M68K_RW), .WE(nPAL_WE),
+ .CDD({8'hFF, CDD}), .PC(PAL_RAM_DATA)
+);
+
+wire [11:0] joy_0a = P1_OUT[0] ? (joystick_2[11:0] | {P1_OUT[2],5'b00000}) : (joystick_0[11:0] | {P1_OUT[2],4'b0000});
+wire [11:0] joy_1a = P1_OUT[0] ? (joystick_3[11:0] | {P1_OUT[2],5'b00000}) : (joystick_1[11:0] | {P1_OUT[2],4'b0000});
+
+wire [11:0] joy_0b = ({12{P1_OUT[0]}} & joystick_0[11:0]) | ({12{P1_OUT[1]}} & joystick_2[11:0]) | {P1_OUT[2], 9'd0};
+wire [11:0] joy_1b = ({12{P2_OUT[0]}} & joystick_1[11:0]) | ({12{P2_OUT[1]}} & joystick_3[11:0]) | {P2_OUT[2], 9'd0};
+
+wire [11:0] joy_0 = status[43] ? joy_0a : status[44] ? joy_0b : joystick_0;
+wire [11:0] joy_1 = status[43] ? joy_1a : status[44] ? joy_1b : joystick_1;
+
+
+neo_c1 C1(
+ .CLK(CLK_48M),
+ .M68K_ADDR(M68K_ADDR[21:17]),
+ .M68K_DATA(M68K_DATA[15:8]), .A22Z(A22Z), .A23Z(A23Z),
+ .nLDS(nLDS), .nUDS(nUDS), .RW(M68K_RW), .nAS(nAS),
+ .nROMOEL(nROMOEL), .nROMOEU(nROMOEU),
+ .nPORTOEL(nPORTOEL), .nPORTOEU(nPORTOEU), .nPORTWEL(nPORTWEL), .nPORTWEU(nPORTWEU),
+ .nPORT_ZONE(nPORTADRS),
+ .nWRL(nWRL), .nWRU(nWRU), .nWWL(nWWL), .nWWU(nWWU),
+ .nSROMOEL(nSROMOEL), .nSROMOEU(nSROMOEU),
+ .nSRAMOEL(nSRAMOEL), .nSRAMOEU(nSRAMOEU), .nSRAMWEL(nSRAMWEL), .nSRAMWEU(nSRAMWEU),
+ .nLSPOE(nLSPOE), .nLSPWE(nLSPWE),
+ .nCRDO(nCRDO), .nCRDW(nCRDW), .nCRDC(nCRDC),
+ .nSDW(nSDW),
+ .P1_IN(~{(joy_0[9:8]|ps2_mouse[2]), {use_mouse ? ms_pos : use_sp ? {|{joy_0[7:4],ps2_mouse[1:0]},sp0} : {joy_0[7:4]|{3{~xram & joy_0[11]}}|{{2{joystick_0[13]}},{2{joystick_0[12]}}}, joy_0[0], joy_0[1], joy_0[2], joy_0[3]}}}),
+ .P2_IN(~{ joy_1[9:8], {use_mouse ? ms_btn : use_sp ? {|{joy_1[7:4]}, sp1} : {joy_1[7:4]|{3{~xram & joy_1[11]}}|{{2{joystick_1[13]}},{2{joystick_1[12]}}}, joy_1[0], joy_1[1], joy_1[2], joy_1[3]}}}),
+ .nCD1(nCD1), .nCD2(nCD2),
+ .nWP(0), // Memory card is never write-protected
+ .nROMWAIT(~rom_wait), .nPWAIT0(~p_wait[0]), .nPWAIT1(~p_wait[1]), .PDTACK(1),
+ .SDD_WR(SDD_OUT),
+ .SDD_RD(SDD_RD_C1),
+ .nSDZ80R(nSDZ80R), .nSDZ80W(nSDZ80W), .nSDZ80CLR(nSDZ80CLR),
+ .CLK_EN_68K_P(CLK_EN_68K_P),
+ .nDTACK(nDTACK),
+ .nBITW0(nBITW0), .nBITW1(nBITW1),
+ .nDIPRD0(nDIPRD0), .nDIPRD1(nDIPRD1),
+ .nPAL_ZONE(nPAL),
+ .SYSTEM_TYPE({SYSTEM_CDx, SYSTEM_MVS})
+);
+
+reg use_sp = 0;
+reg [6:0] sp0 = 0, sp1 = 0;
+always @(posedge clk_sys) begin
+ reg old_sp0, old_sp1, old_ms;
+ reg latch_done = 0, ms_filtered = 0;
+
+ old_sp0 <= spinner_0[8];
+ if(latch_done && (old_sp0 ^ spinner_0[8])) sp0 <= sp0 - spinner_0[6:0];
+
+ // Main fires a single mouse event on cold boot in input.cpp in input_notify_mode()
+ // Filter this event once to prevent accidental latching of use_sp on cold boot
+ old_ms <= ps2_mouse[24];
+ if(latch_done && (old_ms ^ ps2_mouse[24])) begin
+ ms_filtered <= 1;
+ if (ms_filtered) sp0 <= sp0 - ps2_mouse[14:8];
+ end
+
+ old_sp1 <= spinner_1[8];
+ if(latch_done && (old_sp1 ^ spinner_1[8])) sp1 <= sp1 - spinner_1[6:0];
+
+ latch_done <= 1;
+
+ if(status[42]) use_sp <= 1;
+ else if(status[41]) use_sp <= 0;
+ else if(latch_done) begin
+ if((old_sp0 ^ spinner_0[8]) || (old_sp1 ^ spinner_1[8]) || (ms_filtered && (old_ms ^ ps2_mouse[24]))) use_sp <= 1;
+ if(joystick_0[3:0] || joystick_1[3:0]) use_sp <= 0;
+ end
+end
+
+wire use_mouse = &status[42:41];
+
+reg ms_xy;
+reg [7:0] ms_x, ms_y;
+wire [7:0] ms_pos = ms_xy ? ms_y : ms_x;
+wire [7:0] ms_btn = {2'b00, ps2_mouse[1:0], 4'b0000};
+
+always @(posedge clk_sys) begin
+ reg old_ms;
+
+ if(!nBITW0 && !M68K_ADDR[6:3]) ms_xy <= M68K_DATA[0];
+
+ old_ms <= ps2_mouse[24];
+ if(old_ms ^ ps2_mouse[24]) begin
+ ms_x <= ms_x + ps2_mouse[15:8];
+ ms_y <= ms_y - ps2_mouse[23:16];
+ end
+end
+
+zmc2_dot ZMC2(
+ .CLK(CLK_48M),
+ .CLK_EN_12M_N(CLK_EN_12M_N),
+ .EVEN(EVEN1), .LOAD(LOAD), .H(H),
+ .CR(CA4 ? CR_DOUBLE[63:32] : CR_DOUBLE[31:0]),
+ .GAD(GAD), .GBD(GBD),
+ .DOTA(DOTA), .DOTB(DOTB)
+);
+
+dpram #(16) LO(
+ .clock_a(clk_sys),
+ .address_a(ioctl_addr[16:1]),
+ .data_a(ioctl_dout[7:0]),
+ .wren_a(ioctl_download & (ioctl_index == INDEX_LOROM) & ioctl_wr),
+ .clock_b(CLK_48M),
+ .address_b(PBUS[15:0]),
+ .q_b(LO_ROM_DATA)
+);
+
+// VCS is normally used as the LO ROM's nOE but the NeoGeo relies on the fact that the LO ROM
+// will still have its output active for a short moment (~50ns) after nOE goes high
+// nPBUS_OUT_EN is used internally by LSPC2 but it's broken out here to use the additional
+// half mclk cycle it provides compared to VCS. This makes sure LO_ROM_DATA is valid when latched.
+assign PBUS[23:16] = nPBUS_OUT_EN ? LO_ROM_DATA : 8'bzzzzzzzz;
+
+spram #(11,16) UFV(
+ .clock(CLK_48M),
+ .address(FAST_VRAM_ADDR),
+ .data(FAST_VRAM_DATA_OUT),
+ .wren(~CWE),
+ .q(FAST_VRAM_DATA_IN)
+);
+
+spram #(15,16) USV(
+ .clock(CLK_48M),
+ .address(SLOW_VRAM_ADDR),
+ .data(SLOW_VRAM_DATA_OUT),
+ .wren(~BWE),
+ .q(SLOW_VRAM_DATA_IN)
+);
+
+wire [18:11] MA;
+wire [7:0] Z80_RAM_DATA;
+
+// 2KB Z80 work RAM (Cart)
+spram #(11) Z80RAM(.clock(CLK_48M), .address(SDA[10:0]), .data(SDD_OUT), .wren(~(nZRAMCS | nSDMWR)), .q(Z80_RAM_DATA));
+
+// 64KB Z80 work RAM (CD)
+assign CD_Z80_RAM_OUT = SDA[0] ? WRAMU_OUT : WRAML_OUT;
+
+assign SDD_IN = (~nSDZ80R) ? SDD_RD_C1 :
+ (~nSDMRD & SYSTEM_CDx) ? CD_Z80_RAM_OUT :
+ (~nSDMRD & ~nSDROM) ? M1_ROM_DATA :
+ (~nSDMRD & ~nZRAMCS) ? Z80_RAM_DATA :
+ (~n2610CS & ~n2610RD) ? YM2610_DOUT :
+ 8'b00000000;
+
+wire Z80_nRESET = SYSTEM_CDx ? nRESET & CD_nRESET_Z80 : nRESET;
+wire CD_HAS_Z80_BUS = (CD_USE_Z80 & ~(nBUSAK & CD_nRESET_Z80));
+
+wire [7:0] M1_ROM_DATA;
+reg z80rd_req;
+wire z80rd_ack;
+wire z80_rom_rd = ~(nSDMRD | nSDROM | SYSTEM_CDx);
+always @(posedge DDRAM_CLK) begin
+ reg old_rd, old_rd1;
+
+ old_rd <= z80_rom_rd;
+ if(old_rd == z80_rom_rd) old_rd1 <= old_rd;
+
+ // nRESET is used here because otherwise z80rd_req is toggled at core boot
+ // which causes problems with DDRAM. (Z80_nSDRD is probably low for a few DDRAM_CLK
+ // cycles at core boot).
+ // If the core is loaded with SignalTap then DDRAM is stuck at waiting for
+ // DDRAM_DOUT_READY to go high which does not happen.
+ if(~old_rd1 & old_rd & nRESET) z80rd_req <= ~z80rd_req;
+end
+
+wire Z80_nWAIT = (z80rd_req == z80rd_ack);
+
+cpu_z80 Z80CPU(
+ .CLK(CLK_48M),
+ .CLK4P_EN(CLK_EN_4M_P),
+ .CLK4N_EN(CLK_EN_4M_N),
+ .nRESET(Z80_nRESET),
+ .SDA(Z80_SDA), .SDD_IN(SDD_IN), .SDD_OUT(Z80_SDD_OUT),
+ .nIORQ(nIORQ), .nMREQ(Z80_nMREQ), .nRD(Z80_nSDRD), .nWR(Z80_nSDWR),
+ .nBUSRQ(~CD_USE_Z80), .nBUSAK(nBUSAK),
+ .nINT(Z80_nINT), .nNMI(Z80_nNMI), .nWAIT(Z80_nWAIT)
+);
+
+assign { SDA, SDD_OUT } = ~CD_HAS_Z80_BUS ? { Z80_SDA, Z80_SDD_OUT } : DMA_RUNNING ? { DMA_ADDR_OUT[16:1], DMA_DATA_OUT[7:0] } : { M68K_ADDR[16:1], M68K_DATA[7:0] };
+assign { nSDRD, nSDWR } = ~CD_HAS_Z80_BUS ? { Z80_nSDRD, Z80_nSDWR } : { ~CD_TR_RD_Z80, ~CD_TR_WR_Z80 };
+assign { nMREQ } = ~CD_HAS_Z80_BUS ? { Z80_nMREQ } : {~(CD_TR_RD_Z80 | CD_TR_WR_Z80)};
+
+assign M68K_DATA[7:0] = ~(CD_HAS_Z80_BUS & CD_TR_RD_Z80) ? 8'bzzzz_zzzz : SDD_IN;
+
+wire [19:0] ADPCMA_ADDR;
+wire [4:0] ADPCMA_BANK;
+wire [23:0] ADPCMB_ADDR;
+
+reg adpcm_wr, adpcm_rd;
+reg old_download, old_reset, old_CD_TR_WR_PCM;
+wire adpcm_wrack, adpcm_rdack;
+
+wire ddr_loading = ioctl_download & (((ioctl_index >= INDEX_VROMS) & (ioctl_index < INDEX_CROMS)) | (ioctl_index == INDEX_M1ROM));
+reg ddram_wait = 0;
+reg ddram_dtack;
+
+// Copied from Genesis_MiSTer/Genesis.sv
+always @(posedge clk_sys)
+begin
+
+ old_download <= ddr_loading;
+ old_reset <= nRESET;
+ old_CD_TR_WR_PCM <= CD_TR_WR_PCM;
+
+ if (old_reset & ~nRESET) ddram_wait <= 0;
+
+ if (old_download & ~ddr_loading)
+ ddram_wait <= 0; // Needed ?
+
+ if (ddram_dtack & nAS) begin
+ ddram_dtack <= 0;
+ end
+
+ if (ddr_loading & ioctl_wr) begin
+ ddram_wait <= 1;
+ adpcm_wr <= ~adpcm_wr;
+ ddr_waddr <= (ioctl_index == INDEX_M1ROM) ? {1'b1,ioctl_addr[24:0]} : VROM_LOAD_ADDR;
+ ddr_wr_din <= ioctl_dout;
+ ddr_we_byte <= 0;
+ end else if (~old_CD_TR_WR_PCM & CD_TR_WR_PCM) begin // CD write to PCM
+ ddram_wait <= 1;
+ adpcm_wr <= ~adpcm_wr;
+ ddr_waddr <= { 6'b00_0000, CD_BANK_PCM, (DMA_RUNNING ? DMA_ADDR_OUT[19:1] : M68K_ADDR[19:1])};
+ ddr_wr_din <= DMA_RUNNING ? DMA_DATA_OUT : M68K_DATA;
+ ddr_we_byte <= 1;
+ end else if (ddram_wait & (adpcm_wr == adpcm_wrack)) begin
+ ddram_wait <= 0;
+ ddram_dtack <= 1;
+ end
+end
+
+assign DDRAM_CLK = CLK_96M;
+
+// The ddram request and ack signals work on either edge
+// To trigger a read request, just set adpcm_rd to ~adpcm_rdack
+
+reg ADPCMA_READ_REQ, ADPCMB_READ_REQ;
+reg ADPCMA_READ_ACK, ADPCMB_READ_ACK;
+reg [24:0] ADPCMA_ADDR_LATCH; // 16MB(32MB)
+reg [24:0] ADPCMB_ADDR_LATCH; // 32MB
+reg [23:0] ADPCMB_MASK;
+reg [7:0] ADPCMA_ACK_COUNTER;
+reg [10:0] ADPCMB_ACK_COUNTER;
+wire ADPCMA_DATA_READY = ~((ADPCMA_READ_REQ ^ ADPCMA_READ_ACK) & (ADPCMA_ACK_COUNTER == 8'd0));
+wire ADPCMB_DATA_READY = ~((ADPCMB_READ_REQ ^ ADPCMB_READ_ACK) & (ADPCMB_ACK_COUNTER == 11'd0));
+
+reg OLD_CD_TR_RD_PCM;
+reg ADPCMA_RD_DTACK, ADPCMA_RD_WAIT;
+always @(posedge DDRAM_CLK) begin
+ reg [1:0] ADPCMA_OE_SR;
+ reg [1:0] ADPCMB_OE_SR;
+ ADPCMA_OE_SR <= {ADPCMA_OE_SR[0], nSDROE};
+ ADPCMA_ACK_COUNTER <= ADPCMA_ACK_COUNTER == 8'd0 ? 8'd0 : ADPCMA_ACK_COUNTER - 8'd1;
+ ADPCMB_ACK_COUNTER <= ADPCMB_ACK_COUNTER == 11'd0 ? 11'd0 : ADPCMB_ACK_COUNTER - 11'd1;
+ // Trigger ADPCM A data read on nSDROE falling edge
+ if (ADPCMA_OE_SR == 2'b10 & ~CD_USE_PCM) begin
+ ADPCMA_READ_REQ <= ~ADPCMA_READ_REQ;
+ ADPCMA_ADDR_LATCH <= {ADPCMA_BANK, ADPCMA_ADDR} & V1ROM_MASK[24:0];
+ // Data is needed on one previous 8MHz clk before next 666KHz clock->(96MHz/666KHz = 144)-12-4=128
+ ADPCMA_ACK_COUNTER <= 8'd128;
+ end
+
+ ADPCMB_MASK <= use_pcm ? V1ROM_MASK[23:0] : V2ROM_MASK[23:0];
+
+ // Trigger ADPCM B data read on nSDPOE falling edge
+ ADPCMB_OE_SR <= {ADPCMB_OE_SR[0], nSDPOE};
+ if (ADPCMB_OE_SR == 2'b10 & ~SYSTEM_CDx) begin
+ ADPCMB_READ_REQ <= ~ADPCMB_READ_REQ;
+ ADPCMB_ADDR_LATCH <= {~use_pcm, ADPCMB_ADDR & ADPCMB_MASK};
+ // Data is needed on one previous 8MHz clk before next 55KHz clock->(96MHz/55KHz = 1728)-144-4=1580
+ ADPCMB_ACK_COUNTER <= 11'd1580;
+ end
+
+ // ADPCM A read by 68K
+ OLD_CD_TR_RD_PCM <= CD_TR_RD_PCM;
+ if (~OLD_CD_TR_RD_PCM & CD_TR_RD_PCM) begin
+ ADPCMA_ADDR_LATCH <= { 4'b0000, CD_BANK_PCM, (DMA_RUNNING ? DMA_ADDR_IN[19:1] : M68K_ADDR[19:1]) };
+ ADPCMA_READ_REQ <= ~ADPCMA_READ_REQ;
+ ADPCMA_RD_WAIT <= 1;
+ end else if (ADPCMA_RD_WAIT & (ADPCMA_READ_REQ == ADPCMA_READ_ACK)) begin
+ ADPCMA_RD_WAIT <= 0;
+ ADPCMA_RD_DTACK <= 1;
+ end
+
+ if (ADPCMA_RD_DTACK & nAS) begin
+ ADPCMA_RD_DTACK <= 0;
+ end
+end
+
+assign M68K_DATA[7:0] = ~CD_TR_RD_PCM ? 8'bzzzz_zzzz : ADPCMA_DOUT;
+
+wire [7:0] ADPCMA_DOUT;
+wire [7:0] ADPCMA_DATA = (CD_USE_PCM || !V1ROM_MASK) ? 8'h80 : ADPCMA_DOUT;
+
+wire [7:0] ADPCMB_DOUT;
+wire [7:0] ADPCMB_DATA = (!ADPCMB_MASK) ? 8'h80 : ADPCMB_DOUT;
+
+reg [27:0] ddr_waddr;
+reg [15:0] ddr_wr_din;
+reg ddr_we_byte;
+
+ddram DDRAM(
+ .*,
+
+ .cache_reset(~nRESET),
+
+ .wraddr(ddr_waddr),
+ .din(ddr_wr_din),
+ .we_req(adpcm_wr),
+ .we_ack(adpcm_wrack),
+ .we_byte(ddr_we_byte),
+
+ .rdaddr(ADPCMA_ADDR_LATCH),
+ .dout(ADPCMA_DOUT),
+ .rd_req(ADPCMA_READ_REQ),
+ .rd_ack(ADPCMA_READ_ACK),
+
+ .rdaddr2(ADPCMB_ADDR_LATCH),
+ .dout2(ADPCMB_DOUT),
+ .rd_req2(ADPCMB_READ_REQ),
+ .rd_ack2(ADPCMB_READ_ACK),
+
+ .rdaddr3({7'b10_0000_0,MA & MROM_MASK[18:11],SDA[10:0]}),
+ .dout3(M1_ROM_DATA),
+ .rd_req3(z80rd_req),
+ .rd_ack3(z80rd_ack),
+
+ .cpaddr({1'b1, ddr_cpaddr}),
+ .cpdout(ddr_cpdout),
+ .cpwr(ddr_cpwr),
+ .cpreq(ddr_cpreq),
+ .cpbusy(ddr_cpbusy)
+);
+
+wire [26:0] ddr_cpaddr = cur_off;
+wire [63:0] ddr_cpdout;
+wire ddr_cpwr;
+wire ddr_cpbusy;
+reg ddr_cpreq;
+wire [26:0] sdr_cpaddr = cp_addr + cur_off;
+wire [15:0] sdr_cpdin;
+wire sdr1_cprd, sdr2_cprd;
+wire sdr_cprd = sdr1_cprd | sdr2_cprd;
+wire sdr1_cpbusy, sdr2_cpbusy;
+wire sdr_cpbusy = sdr1_cpbusy | sdr2_cpbusy;
+reg sdr_cpreq;
+
+cpram cpram
+(
+ .clock(CLK_96M),
+ .reset(~memcp_wait),
+
+ .wr(ddr_cpwr),
+ .data(ddr_cpdout),
+
+ .rd(sdr_cprd),
+ .q(sdr_cpdin)
+);
+
+reg cp_op;
+reg [7:0] cp_idx;
+reg [26:0] cp_size;
+reg [26:0] cp_addr;
+reg [26:0] cp_last;
+reg [26:0] cur_off;
+
+reg [26:0] cp_end;
+
+wire [26:0] cp_offset =
+ (cp_idx == INDEX_SPROM) ? SPROM_OFFSET :
+ (cp_idx == INDEX_SFIXROM) ? SFIXROM_OFFSET :
+ (cp_idx == INDEX_S1ROM) ? S1ROM_OFFSET :
+ (cp_idx == INDEX_P1ROM_A) ? P1ROM_A_OFFSET :
+ (cp_idx == INDEX_P1ROM_B) ? P1ROM_B_OFFSET :
+ (cp_idx == INDEX_P2ROM) ? P2ROM_OFFSET :
+ (cp_idx == INDEX_CROM0) ? {CROM_START, 20'd0}:
+ (cp_idx >= INDEX_VROMS) ? ({cp_idx[7:0]-INDEX_VROMS[7:0], 19'h00000}) :
+ 27'd0;
+
+reg memcp_req = 0;
+reg memcp_ack = 0;
+wire memcp_wait = (memcp_req != memcp_ack);
+
+always @(posedge clk_sys) begin
+ if(ioctl_download && ioctl_index == INDEX_MEMCP) begin
+ if(ioctl_wr) begin
+ case(ioctl_addr[3:0])
+ 0: {cp_op,cp_idx} <= {~ioctl_dout[15],ioctl_dout[7:0]};
+ 2: cp_size[15:0] <= ioctl_dout;
+ 4: begin
+ cp_size[26:16] <= ioctl_dout[10:0];
+ cp_addr <= cp_offset;
+ cp_end <= cp_offset + {ioctl_dout[10:0], cp_size[15:0]};
+ end
+ 6: if(ioctl_dout && cp_op) memcp_req <= ~memcp_req;
+ endcase
+
+ if(~cp_op) begin
+ case(ioctl_addr[3:0])
+ 2: cfg[15:0] <= ioctl_dout;
+ 4: cfg[31:16] <= ioctl_dout;
+ endcase
+ end
+ end
+ end
+end
+
+reg [1:0] memcp_state = 0;
+always @(posedge CLK_96M) begin
+ case(memcp_state)
+ 0: if(~memcp_wait) begin
+ ddr_cpreq <= 0;
+ sdr_cpreq <= 0;
+ cur_off <= 0;
+ end
+ else if((~sdr2_en && ~sdr_pri_cpsel) || (cur_off >= cp_size)) memcp_ack <= memcp_req;
+ else begin
+ ddr_cpreq <= 1;
+ memcp_state <= 1;
+ end
+
+ 1: if(ddr_cpbusy) ddr_cpreq <= 0;
+ else if(~ddr_cpreq & ~ddr_cpbusy) begin
+ sdr_cpreq <= 1;
+ memcp_state <= 2;
+ end
+
+ 2: if(sdr_cpbusy) sdr_cpreq <= 0;
+ else if(~sdr_cpreq & ~sdr_cpbusy) begin
+ cur_off <= cur_off + 27'd1024;
+ memcp_state <= 0;
+ end
+ endcase
+
+ if(~memcp_wait) memcp_state <= 0;
+end
+
+wire [7:0] YM2610_DOUT;
+
+reg adpcm_en;
+reg [7:0] adpcma_d, adpcmb_d;
+always @(posedge CLK_48M) begin
+ reg en;
+ en <= ADPCMA_DATA_READY & ADPCMB_DATA_READY;
+ adpcm_en <= en;
+
+ adpcma_d <= ADPCMA_DATA;
+ adpcmb_d <= ADPCMB_DATA;
+end
+
+jt10 YM2610(
+ .rst(~Z80_nRESET),
+ .clk(CLK_48M), .cen((CLK_EN_4M_P | CLK_EN_4M_N) & adpcm_en),
+ .addr(SDA[1:0]),
+ .din(SDD_OUT), .dout(YM2610_DOUT),
+ .cs_n(n2610CS), .wr_n(n2610WR),
+ .irq_n(Z80_nINT),
+ .adpcma_addr(ADPCMA_ADDR), .adpcma_bank(ADPCMA_BANK), .adpcma_roe_n(nSDROE), .adpcma_data(adpcma_d),
+ .adpcmb_addr(ADPCMB_ADDR), .adpcmb_roe_n(nSDPOE), .adpcmb_data(SYSTEM_CDx ? 8'h08 : adpcmb_d), // CD has no ADPCM-B
+ .snd_right(snd_right), .snd_left(snd_left), .snd_enable(~{4{dbg_menu}} | ~status[28:25]), .ch_enable(~status[62:57])
+);
+
+wire [16:0] snd_mix_l = $signed(snd_left) + $signed(CD_AUDIO_L);
+wire [16:0] snd_mix_r = $signed(snd_right) + $signed(CD_AUDIO_R);
+
+
+// For Neo CD only
+wire VIDEO_EN = SYSTEM_CDx ? CD_VIDEO_EN : 1'b1;
+wire FIX_EN = SYSTEM_CDx ? CD_FIX_EN : 1'b1;
+wire SPR_EN = SYSTEM_CDx ? CD_SPR_EN : 1'b1;
+wire DOTA_GATED = SPR_EN & DOTA;
+wire DOTB_GATED = SPR_EN & DOTB;
+wire HSync; //,VSync;
+
+lspc2_a2_sync LSPC(
+ .CLK(CLK_48M),
+ .CLK_EN_24M_P(CLK_EN_24M_P),
+ .CLK_EN_24M_N(CLK_EN_24M_N),
+ .RESET(nRESET),
+ .nRESETP(nRESETP),
+ .LSPC_8M(), .LSPC_4M(),
+ .LSPC_EN_4M_P(CLK_EN_4M_P), .LSPC_EN_4M_N(CLK_EN_4M_N),
+ .M68K_ADDR(M68K_ADDR[3:1]), .M68K_DATA(M68K_DATA),
+ .IPL0(IPL0), .IPL1(IPL1),
+ .CD_VBLANK_IRQ_EN(CD_VBLANK_IRQ_EN | ~SYSTEM_CDx),
+ .CD_TIMER_IRQ_EN(CD_TIMER_IRQ_EN | ~SYSTEM_CDx),
+ .LSPOE(nLSPOE), .LSPWE(nLSPWE),
+ .PBUS_OUT(PBUS[15:0]), .PBUS_IO(PBUS[23:16]),
+ .nPBUS_OUT_EN(nPBUS_OUT_EN),
+ .DOTA(DOTA_GATED), .DOTB(DOTB_GATED),
+ .CA4(CA4), .S2H1(S2H1), .S1H1(S1H1),
+ .LOAD(LOAD), .H(H), .EVEN1(EVEN1), .EVEN2(EVEN2),
+ .PCK1(PCK1), .PCK2(PCK2),
+ .PCK1_EN_N(PCK1_EN_N), .PCK2_EN_N(PCK2_EN_N),
+ .PCK1_EN_P(PCK1_EN_P), .PCK2_EN_P(PCK2_EN_P),
+ .CHG(CHG),
+ .LD1(LD1), .LD2(LD2),
+ .WE(WE), .CK(CK), .SS1(SS1), .SS2(SS2),
+ .HSYNC(HSync), //.VSYNC(VSync),
+ .CHBL(CHBL), .BNKB(nBNKB),
+ .VCS(VCS),
+ .SVRAM_ADDR(SLOW_VRAM_ADDR),
+ .SVRAM_DATA_IN(SLOW_VRAM_DATA_IN), .SVRAM_DATA_OUT(SLOW_VRAM_DATA_OUT),
+ .BOE(BOE), .BWE(BWE),
+ .FVRAM_ADDR(FAST_VRAM_ADDR),
+ .FVRAM_DATA_IN(FAST_VRAM_DATA_IN), .FVRAM_DATA_OUT(FAST_VRAM_DATA_OUT),
+ .CWE(CWE),
+ .VMODE(video_mode),
+ .FIXMAP_ADDR(FIXMAP_ADDR) // Extracted for NEO-CMC
+);
+
+wire DOGE = SYSTEM_CDx ? ~CD_UPLOAD_EN : 1'b1; // UPLOAD_EN disables Watchdog?
+
+neo_b1 B1(
+ .CLK(CLK_48M), .CLK_EN_6MB(CLK_EN_6MB), .CLK_EN_1HB(CLK_EN_1HB),
+ .S1H1(S1H1),
+ .A23I(A23Z), .A22I(A22Z),
+ .M68K_ADDR_U(M68K_ADDR[21:17]), .M68K_ADDR_L(M68K_ADDR[12:1]),
+ .nLDS(nLDS), .RW(M68K_RW), .nAS(nAS),
+ .PBUS(PBUS),
+ .FIXD(FIXD),
+ .PCK1_EN(PCK1_EN_P), .PCK2_EN(PCK2_EN_P),
+ .CHBL(CHBL), .BNKB(nBNKB),
+ .GAD(GAD), .GBD(GBD),
+ .WE(WE), .CK(CK),
+ .TMS0(CHG), .LD1(LD1), .LD2(LD2), .SS1(SS1), .SS2(SS2),
+ .PA(PAL_RAM_ADDR),
+ .EN_FIX(FIX_EN),
+ .DOGE(DOGE),
+ .nRST(nRESET_CORE),
+ .nRESET(nRESET)
+);
+
+spram #(13,16) PALRAM(
+ .clock(CLK_48M), // Was CLK_12M
+ .address({PALBNK, PAL_RAM_ADDR}),
+ .data(M68K_DATA),
+ .wren(~nPAL_WE),
+ .q(PAL_RAM_DATA)
+);
+
+// DAC latches
+reg ce_pix;
+reg [2:0] HBlank;
+reg HBlank304;
+always @(posedge CLK_VIDEO) begin
+ reg [9:0] pxcnt;
+
+ ce_pix <= 0;
+ if(CLK_EN_6MB) begin
+ ce_pix <= 1;
+ PAL_RAM_REG <= (nRESET && VIDEO_EN && ((pxcnt >= 7 && pxcnt < 311) || ~status[16])) ? PAL_RAM_DATA : 16'h8000;
+ end
+
+ if(ce_pix) begin
+ HBlank <= (HBlank<<1) | CHBL;
+
+ pxcnt <= pxcnt + 1'b1;
+ if(HBlank[1:0] == 2'b10) pxcnt <= 0;
+ end
+end
+
+//Re-create VSync as original one is barely equals to VBlank
+reg VSync;
+reg RFSH;
+always @(posedge CLK_VIDEO) begin
+ reg old_hs;
+ reg old_vbl;
+ reg [2:0] vbl;
+ reg [7:0] vblcnt, vspos, rfsh_cnt;
+
+ if(ce_pix) begin
+ old_hs <= HSync;
+ if(~old_hs & HSync) begin
+ old_vbl <= nBNKB;
+
+ if(~nBNKB) vblcnt <= vblcnt+1'd1;
+ if(old_vbl & ~nBNKB) vblcnt <= 0;
+ if(~old_vbl & nBNKB) begin
+ vspos <= (vblcnt>>1) - 8'd7;
+ rfsh_cnt <= vblcnt-2'd2;
+ end
+
+ {VSync,vbl} <= {vbl,1'b0};
+ if(vblcnt == vspos) {VSync,vbl} <= '1;
+ end
+
+ RFSH <= (vblcnt < rfsh_cnt);
+ end
+end
+
+assign VGA_SL = scale ? scale[1:0] - 1'd1 : 2'd0;
+assign VGA_F1 = 0;
+
+wire [2:0] scale = status[20:18];
+
+wire [6:0] R6 = {1'b0, PAL_RAM_REG[11:8], PAL_RAM_REG[14], PAL_RAM_REG[11]} - PAL_RAM_REG[15];
+wire [6:0] G6 = {1'b0, PAL_RAM_REG[7:4], PAL_RAM_REG[13], PAL_RAM_REG[7] } - PAL_RAM_REG[15];
+wire [6:0] B6 = {1'b0, PAL_RAM_REG[3:0], PAL_RAM_REG[12], PAL_RAM_REG[3] } - PAL_RAM_REG[15];
+
+wire [7:0] R8 = R6[6] ? 8'd0 : {R6[5:0], R6[4:3]};
+wire [7:0] G8 = G6[6] ? 8'd0 : {G6[5:0], G6[4:3]};
+wire [7:0] B8 = B6[6] ? 8'd0 : {B6[5:0], B6[4:3]};
+
+wire [7:0] r,g,b;
+wire hs,vs,hblank,vblank;
+video_cleaner video_cleaner
+(
+ .clk_vid(CLK_VIDEO),
+ .ce_pix(ce_pix),
+
+ .R(~SHADOW ? R8 : {1'b0, R8[7:1]}),
+ .G(~SHADOW ? G8 : {1'b0, G8[7:1]}),
+ .B(~SHADOW ? B8 : {1'b0, B8[7:1]}),
+
+ .HSync(HSync),
+ .VSync(VSync),
+ .HBlank(HBlank[0]),
+ .VBlank(~nBNKB),
+
+ .VGA_R(r),
+ .VGA_G(g),
+ .VGA_B(b),
+ .VGA_VS(vs),
+ .VGA_HS(hs),
+ .HBlank_out(hblank),
+ .VBlank_out(vblank)
+);
+
+video_mixer #(.LINE_LENGTH(320), .HALF_DEPTH(0), .GAMMA(1)) video_mixer
+(
+ .*,
+ .scandoubler(scale || forced_scandoubler),
+ .hq2x(scale==1),
+ .freeze_sync(),
+
+ .VGA_DE(vga_de),
+ .R(r),
+ .G(g),
+ .B(b),
+
+ // Positive pulses.
+ .HSync(hs),
+ .VSync(vs),
+ .HBlank(hblank),
+ .VBlank(vblank)
+);
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/releases/README.md b/MiSTer-devel_NeoGeo_MiSTer/releases/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..91abd5fd1fe831e59d750a409d3f9b19393d5849
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/releases/README.md
@@ -0,0 +1,79 @@
+# Using purchased ROMs (gog-romset.xml)
+
+Good Old Games (at least the Linux versions), Humble Bundle store and possibly
+other sellers contain the image of individual ROM chips, unlike the Darksoft
+rom pack which preprocessed these images.
+
+This document will help you locate the ROM files in an installed game, get them
+where you need them, and get the most out of your purchase.
+
+Note: gog-romsets.xml needs to be renamed to romsets.xml for these games to function.
+
+## BIOS images
+
+Chances are, your purchase contains all the ROM images you need for MiSTer
+(see the top-level README file in this repository), maybe located in an
+archive named `neogeo.zip`.
+
+## Locating game ROM images
+
+You will need to do this once per game.
+
+Once you have installed a game, you will need to locate the game ROMs.
+
+Plain rom images have names which should look like `201-p1.p1` (number, dash,
+one or two letters, a number, dot, one or two letters, a number). The number
+identifies the game, and is listed in the tables below.
+
+Chances are these files will be in a `.zip` archive. For Metal Slug, they would
+be in a file named `mslug.zip`, for example.
+
+Locate your game in the table below. In your MiSTer NeoGeo folder
+(`/games/NeoGeo`), create a folder named like the
+game (this would be `mslug` for Metal Slug) and put the ROM images there
+(extracted from the `.zip` file if any).
+
+Some games contain come in more than one version (ex: a Korean version). In
+this case, create the folders listed in the "other versions" column, and they
+will appear. Unless otherwise noted, you do not have to put anything in these
+folders - they are just here to let MiSTer know these versions should be
+displayed. Note: you must keep the main folder, as it contains the ROMs
+actually being used.
+
+## Game list
+
+Grouped by MiSTer SDRAM requirements.
+
+### 32 MB
+
+| Number | Name | Title | Other Versions | Notes |
+| --- | --- | --- | --- | --- |
+| 056 | `aof2` | Art of Fighting 2 | `aof2a` | |
+| 041 | `bstars2` | Baseball Stars 2 | | |
+| 058 | `fatfursp` | Fatal Fury Special | `fatfurspa` | |
+| 220 | `ironclad` | Iron Clad | ironclado | Most ROM names start with `proto_` |
+| 016 | `kotm` | King of the Monsters | `kotmh` | |
+| 201 | `mslug` | Metal Slug | | |
+| 201 | `mslug2` | Metal Slug 2 | `mslug2t` | `mslug2t` requires the [3rd-party "turbo" patch](http://blog.system11.org/?p=1442). This will produce the `941-p1.p1` file which you must place in the `mslug2t` folder. |
+| 063 | `samsho2` | Samurai Shodown II | `samsho2k` `samsho2k2` | |
+| 200 | `turfmast` | Neo Turf Masters | | |
+| 224 | `twinspri` | Twinkle Star Sprites | | |
+
+### 64 MB
+
+| Number | Name | Title | Other Versions | Notes |
+| --- | --- | --- | --- | --- |
+| 239 | `blazstar` | Blazing Star | | |
+| 234 | `lastblad` | Last Blade (The) | `lastbladh` `lastsold` | |
+| 089 | `pulstar` | Pulstar | | |
+| 240 | `rbff2` | Real Bout Fatal Fury 2 | `rbff2h` `rbff2k` | |
+| 246 | `shocktr2` | Shock Troopers - 2nd Squad | | |
+| 238 | `shocktro` | Shock Troopers | `shcktroa` | |
+
+### 96 MB
+
+(none working)
+
+### 128 MB
+
+(none)
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/CEGen.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/CEGen.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..37d74c4194547d1f575094969f975e13936457c0
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/CEGen.vhd
@@ -0,0 +1,34 @@
+LIBRARY ieee;
+USE ieee.std_logic_1164.all;
+
+ENTITY CEGen IS
+ PORT
+ (
+ CLK : in STD_LOGIC;
+ RST_N : in STD_LOGIC;
+
+ IN_CLK : in integer;
+ OUT_CLK : in integer;
+
+ CE : out STD_LOGIC
+ );
+END CEGen;
+
+ARCHITECTURE SYN OF CEGen IS
+BEGIN
+ process( RST_N, CLK )
+ variable CLK_SUM : integer;
+ begin
+ if RST_N = '0' then
+ CLK_SUM := 0;
+ CE <= '0';
+ elsif falling_edge(CLK) then
+ CE <= '0';
+ CLK_SUM := CLK_SUM + OUT_CLK;
+ if CLK_SUM >= IN_CLK then
+ CLK_SUM := CLK_SUM - IN_CLK;
+ CE <= '1';
+ end if;
+ end if;
+ end process;
+END SYN;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cd.sv b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cd.sv
new file mode 100644
index 0000000000000000000000000000000000000000..b26cd300c9c65f855b5376bf2d609f3274b03347
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cd.sv
@@ -0,0 +1,811 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module cd_sys(
+ input nRESET,
+ //input CLK_68KCLK,
+ input CLK_68KCLK_EN,
+ input [23:1] M68K_ADDR,
+ inout [15:0] M68K_DATA,
+ input A22Z, A23Z,
+ input nLDS, nUDS,
+ input M68K_RW, nAS, nDTACK,
+ input SYSTEM_CDx,
+ input [1:0] CD_REGION,
+ input [1:0] CD_SPEED,
+ output reg CD_VIDEO_EN,
+ output reg CD_FIX_EN,
+ output reg CD_SPR_EN,
+
+ output reg CD_nRESET_Z80,
+
+ output CD_TR_WR_SPR,
+ output CD_TR_WR_PCM,
+ output CD_TR_WR_Z80,
+ output CD_TR_WR_FIX,
+
+ output CD_TR_RD_FIX,
+ output CD_TR_RD_SPR,
+ output CD_TR_RD_Z80,
+ output CD_TR_RD_PCM,
+
+ output reg CD_USE_FIX,
+ output reg CD_USE_SPR,
+ output reg CD_USE_Z80,
+ output reg CD_USE_PCM,
+ output reg [2:0] CD_TR_AREA,
+ output reg [1:0] CD_BANK_SPR,
+ output reg CD_BANK_PCM,
+ output reg [15:0] CD_TR_WR_DATA,
+ output reg [19:1] CD_TR_WR_ADDR,
+ output reg CD_UPLOAD_EN, // The bios writes to Z80 RAM without CD_UPLOAD_EN enabled. Maybe this is only watchdog disable?
+
+ output CD_VBLANK_IRQ_EN,
+ output CD_TIMER_IRQ_EN,
+
+ input IACK,
+ output reg CD_IRQ,
+
+ input clk_sys,
+ input [39:0] CDD_STATUS_IN,
+ input CDD_STATUS_LATCH,
+ output [39:0] CDD_COMMAND_DATA,
+ output CDD_COMMAND_SEND,
+
+ input CD_DATA_DOWNLOAD,
+ input CD_DATA_WR,
+ input [15:0] CD_DATA_DIN,
+ input [11:1] CD_DATA_ADDR, // word address
+ output CD_DATA_WR_READY, // Ready to receive sector
+
+ input CDDA_RD,
+ input CDDA_WR,
+ output [15:0] CD_AUDIO_L,
+ output [15:0] CD_AUDIO_R,
+ output CDDA_WR_READY,
+
+ input CD_LID, // DEBUG
+
+ // For DMA
+ output reg nBR,
+ input nBG,
+ output reg nBGACK,
+
+ output reg DMA_RUNNING,
+ output reg [15:0] DMA_DATA_OUT,
+ input [15:0] DMA_DATA_IN,
+ output reg DMA_WR_OUT,
+ output reg DMA_RD_OUT,
+ output reg [23:0] DMA_ADDR_IN, // Used for reading
+ output reg [23:0] DMA_ADDR_OUT, // Used for writing
+
+ input DMA_SDRAM_BUSY
+);
+ parameter MCLK = 96671316;
+
+ reg CD_nRESET_DRIVE;
+ reg [15:0] REG_FF0002;
+ reg [11:0] REG_FF0004;
+ reg [2:0] CD_IRQ_FLAGS;
+
+ reg [23:0] DMA_ADDR_A;
+ reg [23:0] DMA_ADDR_B;
+ reg [31:0] DMA_VALUE;
+ reg [31:0] DMA_COUNT; // TODO: This can probably be 23:0
+ reg [15:0] DMA_MICROCODE [9];
+
+ reg CDD_nIRQ_PREV, CDC_nIRQ_PREV;
+ reg nLDS_PREV, nUDS_PREV;
+
+ reg [3:0] CDD_DIN;
+ wire [3:0] CDD_DOUT;
+
+ wire HOCK, CDCK, CDD_nIRQ;
+
+ cd_drive DRIVE(
+ .clk_sys(clk_sys),
+ .nRESET(nRESET & CD_nRESET_DRIVE),
+ .HOCK(HOCK), .CDCK(CDCK),
+ .CDD_DIN(CDD_DIN), .CDD_DOUT(CDD_DOUT),
+ .CDD_nIRQ(CDD_nIRQ),
+ .STATUS_IN(CDD_STATUS_IN),
+ .STATUS_LATCH(CDD_STATUS_LATCH),
+ .COMMAND_DATA(CDD_COMMAND_DATA),
+ .COMMAND_SEND(CDD_COMMAND_SEND)
+ );
+
+ wire [7:0] LC8951_DOUT;
+ wire CDC_nIRQ;
+ wire [31:0] HEADER_DIN;
+
+ lc8951 LC8951(
+ .nRESET(nRESET),
+ .clk_sys(clk_sys),
+ //.CLK_12M(CLK_68KCLK),
+ .CLK_68KCLK_EN(CLK_68KCLK_EN),
+ .nWR(~LC8951_WR), .nRD(~LC8951_RD),
+ .RS(M68K_ADDR[1]),
+ .DIN(M68K_DATA[7:0]),
+ .DOUT(LC8951_DOUT),
+ .HEADER_DIN(HEADER_DIN),
+ .SECTOR_READY(SECTOR_READY),
+ .DMA_RUNNING(DMA_RUNNING),
+ .CDC_nIRQ(CDC_nIRQ)
+ );
+
+ cdda CDDA(
+ .CLK(clk_sys),
+ .nRESET(nRESET),
+ .READ(CDDA_RD),
+ .WRITE(CDDA_WR),
+ .DIN(CD_DATA_DIN),
+ .AUDIO_L(CD_AUDIO_L),
+ .AUDIO_R(CD_AUDIO_R),
+ .WRITE_READY(CDDA_WR_READY)
+ );
+
+ localparam SECTOR_TIME_1X = MCLK / 75;
+ localparam SECTOR_TIME_2X = MCLK / 150;
+ localparam SECTOR_TIME_3X = MCLK / 225;
+ localparam SECTOR_TIME_4X = MCLK / 300;
+
+ reg [20:0] SECTOR_TIME;
+ wire [20:0] SECTOR_TIME_SEL = (CD_SPEED == 2'd0) ? SECTOR_TIME_1X[20:0] :
+ (CD_SPEED == 2'd1) ? SECTOR_TIME_2X[20:0] :
+ (CD_SPEED == 2'd2) ? SECTOR_TIME_3X[20:0] :
+ SECTOR_TIME_4X[20:0];
+
+ reg SECTOR_READY; // For decoder interrupt
+ reg SECTOR_FILLED[2];
+ reg [23:0] SECTOR_TIME_CNT;
+
+ reg FORCE_WR;
+ reg [2:0] LOADING_STATE;
+ reg [10:0] CACHE_RD_ADDR, CACHE_WR_ADDR; // 0~2047
+ reg CACHE_RD_BANK, CACHE_WR_BANK;
+ reg CACHE_WR_EN;
+
+ assign CD_DATA_WR_READY = ~SECTOR_FILLED[~CACHE_RD_BANK];
+
+ reg [7:0] HEAD_0[2];
+ reg [7:0] HEAD_1[2];
+ reg [7:0] HEAD_2[2];
+ reg [7:0] HEAD_3[2];
+
+ assign HEADER_DIN = { HEAD_3[CACHE_RD_BANK], HEAD_2[CACHE_RD_BANK], HEAD_1[CACHE_RD_BANK], HEAD_0[CACHE_RD_BANK] };
+
+ wire [7:0] CACHE_DIN = CACHE_WR_ADDR[0] ? CD_DATA_DIN[15:8] : CD_DATA_DIN[7:0];
+ wire CACHE_WR = CACHE_WR_EN & (CD_DATA_WR_START | FORCE_WR);
+ wire [7:0] CACHE_DOUT;
+
+ dpram #(12,8) CACHE(
+ .clock_a(clk_sys),
+ .address_a( {CACHE_WR_BANK, CACHE_WR_ADDR} ),
+ .data_a(CACHE_DIN),
+ .wren_a(CACHE_WR),
+
+ .clock_b(clk_sys),
+ .address_b( {CACHE_RD_BANK, CACHE_RD_ADDR} ),
+ .wren_b(0),
+ .q_b(CACHE_DOUT)
+);
+
+ localparam DMA_STATE_IDLE = 4'd0, DMA_STATE_BR = 4'd1, DMA_STATE_WAIT_BG = 4'd2,
+ DMA_STATE_WAIT_AS = 4'd3, DMA_STATE_START = 4'd4,
+ DMA_STATE_CACHE_RD = 4'd5, DMA_STATE_CACHE_RD_L = 4'd6,
+ DMA_STATE_INIT_RD = 4'd7, DMA_STATE_RD = 4'd8, DMA_STATE_RD_DONE = 4'd9,
+ DMA_STATE_INIT_WR = 4'd10, DMA_STATE_WR = 4'd11, DMA_STATE_WR_DONE = 4'd12,
+ DMA_STATE_DONE = 4'd13;
+
+ localparam DMA_COPY_CD_WORD = 3'd0, DMA_COPY_CD_BYTE = 3'd1, DMA_COPY_WORD = 3'd2,
+ DMA_COPY_BYTE = 3'd3, DMA_FILL_VALUE = 3'd4;
+
+ reg DMA_START_PREV, DMA_START;
+ reg [2:0] DMA_MODE;
+ reg [3:0] DMA_STATE;
+ reg [3:0] DMA_IO_CNT;
+ reg [7:0] DMA_TIMER;
+ reg [15:0] DMA_RD_DATA;
+ reg [31:0] DMA_COUNT_RUN;
+
+ localparam DMA_RW_CYCLES = MCLK / 4800000; // TODO: Tune this
+
+ reg CD_DATA_WR_PREV;
+ wire CD_DATA_WR_START = CD_DATA_WR & ~CD_DATA_WR_PREV;
+ wire CD_DATA_WR_END = ~CD_DATA_WR & CD_DATA_WR_PREV;
+
+ always @(posedge clk_sys)
+ begin
+ if (!nRESET)
+ begin
+ FORCE_WR <= 0;
+ SECTOR_READY <= 0;
+ SECTOR_FILLED[0] <= 0;
+ SECTOR_FILLED[1] <= 0;
+ SECTOR_TIME_CNT <= 0;
+ SECTOR_TIME <= SECTOR_TIME_1X[20:0];
+
+ LOADING_STATE <= 3'd0; // Idle, waiting for request
+
+ DMA_STATE <= 4'd0;
+ nBR <= 1;
+ nBGACK <= 1;
+
+ DMA_RUNNING <= 0;
+ DMA_TIMER <= 8'd0;
+
+ CACHE_WR_EN <= 0;
+ CACHE_RD_BANK <= 0;
+ CACHE_WR_BANK <= 0;
+
+ CD_DATA_WR_PREV <= 0;
+ end
+ else
+ begin
+
+ if (SECTOR_TIME_CNT == {1'b0, SECTOR_TIME[20:1]}) begin
+ SECTOR_READY <= 0;
+ end
+
+ if (SECTOR_TIME_CNT < SECTOR_TIME) begin
+ SECTOR_TIME_CNT <= SECTOR_TIME_CNT + 1'b1;
+ end else begin
+ if (SECTOR_FILLED[~CACHE_RD_BANK]) begin
+ SECTOR_FILLED[CACHE_RD_BANK] <= 0;
+ SECTOR_READY <= 1;
+ CACHE_RD_BANK <= ~CACHE_RD_BANK;
+ SECTOR_TIME_CNT <= 0;
+ SECTOR_TIME <= SECTOR_TIME_SEL;
+ end
+ end
+
+ CD_DATA_WR_PREV <= CD_DATA_WR;
+ if (LOADING_STATE == 3'd0) begin
+ if (CD_DATA_WR_READY) begin
+ if (CD_DATA_DOWNLOAD & CD_DATA_WR_END & (CD_DATA_ADDR == 11'd6)) begin
+ // Bytes 12-13 (Header 0-1)
+ CACHE_WR_BANK <= ~CACHE_RD_BANK;
+
+ HEAD_0[~CACHE_RD_BANK] <= CD_DATA_DIN[7:0];
+ HEAD_1[~CACHE_RD_BANK] <= CD_DATA_DIN[15:8];
+
+ LOADING_STATE <= 3'd1;
+ end
+ end
+ end
+
+ if (LOADING_STATE == 3'd1) begin
+ if (CD_DATA_DOWNLOAD & CD_DATA_WR_END & (CD_DATA_ADDR == 11'd7)) begin
+ // Bytes 14-15 (Header 2-3)
+ HEAD_2[CACHE_WR_BANK] <= CD_DATA_DIN[7:0];
+ HEAD_3[CACHE_WR_BANK] <= CD_DATA_DIN[15:8];
+
+ CACHE_WR_ADDR <= 11'h000;
+ CACHE_WR_EN <= 1;
+
+ LOADING_STATE <= 3'd2;
+ end
+ end
+
+ if (LOADING_STATE == 3'd2) begin
+ if (CD_DATA_WR_START) begin
+ // First byte of pair was written by CD_DATA_WR
+ CACHE_WR_ADDR <= CACHE_WR_ADDR + 1'b1;
+ LOADING_STATE <= 3'd3;
+ FORCE_WR <= 1;
+ end
+
+ if (~CD_DATA_DOWNLOAD) begin // Incomplete data, should not happen.
+ LOADING_STATE <= 3'd4;
+ end
+ end
+
+ if (LOADING_STATE == 3'd3) begin
+ // Second byte of pair was written by FORCE_WR
+ FORCE_WR <= 0;
+ CACHE_WR_ADDR <= CACHE_WR_ADDR + 1'b1;
+ if (CACHE_WR_ADDR == 11'd2047) begin
+ LOADING_STATE <= 3'd4;
+ end else begin
+ LOADING_STATE <= 3'd2;
+ end
+ end
+
+ if (LOADING_STATE == 3'd4) begin
+ // Sector load done
+ CACHE_WR_EN <= 0;
+ SECTOR_FILLED[CACHE_WR_BANK] <= 1;
+ LOADING_STATE <= 3'd0;
+ end
+
+ DMA_START_PREV <= DMA_START;
+
+ // Rising edge of DMA_START
+ if (~DMA_START_PREV & DMA_START)
+ begin
+ DMA_STATE <= 4'd1;
+ DMA_IO_CNT <= 4'd0;
+
+ DMA_COUNT_RUN <= DMA_COUNT;
+
+ case (DMA_MODE)
+
+ DMA_COPY_CD_WORD, DMA_COPY_CD_BYTE:
+ begin
+ // Init byte copy LC8951 cache -> DMA_ADDR_A
+ DMA_ADDR_OUT <= DMA_ADDR_A;
+ CACHE_RD_ADDR <= 11'h000;
+ end
+
+ DMA_COPY_WORD, DMA_COPY_BYTE:
+ begin
+ // Init copy DMA_ADDR_A -> DMA_ADDR_B
+ DMA_ADDR_IN <= DMA_ADDR_A;
+ DMA_ADDR_OUT <= DMA_ADDR_B;
+ end
+
+ DMA_FILL_VALUE:
+ begin
+ // Init word fill from DMA_ADDR_A
+ DMA_ADDR_OUT <= DMA_ADDR_A;
+ DMA_DATA_OUT <= DMA_VALUE[31:16]; // Is [15:0] ever used ?
+ end
+
+ default: ;
+ endcase
+ end
+
+ // DMA logic
+
+ // DMA_TIMER is a minimum wait, so tick it even when DMA_SDRAM_BUSY
+ if (DMA_TIMER)
+ DMA_TIMER <= DMA_TIMER - 1'b1;
+
+ if (!DMA_SDRAM_BUSY)
+ begin
+ if (!DMA_TIMER)
+ begin
+ if (DMA_STATE == DMA_STATE_BR)
+ begin
+ // Init: Do 68k bus request
+ nBR <= 0;
+ DMA_STATE <= DMA_STATE_WAIT_BG;
+ end
+
+ if (DMA_STATE == DMA_STATE_WAIT_BG)
+ begin
+ // Init: Wait for nBG low
+ if (~nBG)
+ DMA_STATE <= DMA_STATE_WAIT_AS;
+ end
+
+ if (DMA_STATE == DMA_STATE_WAIT_AS)
+ begin
+ // Init: Wait for nAS and nDTACK high
+ if (nAS & nDTACK)
+ begin
+ nBR <= 1;
+ nBGACK <= 0;
+ DMA_RUNNING <= 1;
+ DMA_STATE <= DMA_STATE_START;
+ end
+ end
+
+ if (DMA_STATE == DMA_STATE_START)
+ begin
+ // Base state for DMA loop
+ // FX68K doesn't tri-state its outputs when it releases the bus (good !)
+ // So use separate busses and signals when doing DMA and switch them according to DMA_RUNNING
+ if (!DMA_COUNT_RUN)
+ begin
+ // DMA done !
+ DMA_STATE <= DMA_STATE_IDLE; // Go back to idle
+ nBGACK <= 1; // Release bus
+ DMA_RUNNING <= 0; // Inform CDC that the transfer is finished
+ end
+ else
+ begin
+ // Working...
+ case (DMA_MODE)
+ DMA_COPY_CD_WORD:
+ begin
+ // Word copy LC8951 cache -> DMA_ADDR_A
+ case(DMA_IO_CNT)
+ 4'd0: DMA_STATE <= DMA_STATE_CACHE_RD; // Read word from Cache
+ 4'd1: begin
+ DMA_DATA_OUT <= DMA_RD_DATA;
+ DMA_STATE <= DMA_STATE_WR; // Write word
+ end
+
+ default: DMA_STATE <= DMA_STATE_DONE;
+ endcase
+ end
+
+ DMA_COPY_CD_BYTE:
+ begin
+ // Copy LC8951 cache -> DMA_ADDR_A odd bytes
+ case(DMA_IO_CNT)
+ 4'd0: DMA_STATE <= DMA_STATE_CACHE_RD; // Read word from Cache
+ 4'd1: begin
+ DMA_DATA_OUT <= {DMA_RD_DATA[7:0], DMA_RD_DATA[15:8]};
+ DMA_STATE <= DMA_STATE_WR; // Write low byte
+ end
+ 4'd2: begin
+ DMA_DATA_OUT <= DMA_RD_DATA;
+ DMA_STATE <= DMA_STATE_WR; // Write high byte
+ end
+
+ default: DMA_STATE <= DMA_STATE_DONE;
+ endcase
+ end
+
+ DMA_COPY_WORD:
+ begin
+ // Word copy DMA_ADDR_A -> DMA_ADDR_B
+ case(DMA_IO_CNT)
+ 4'd0: DMA_STATE <= DMA_STATE_RD; // Read word
+ 4'd1: begin
+ DMA_DATA_OUT <= DMA_RD_DATA;
+ DMA_STATE <= DMA_STATE_WR; // Write word
+ end
+
+ default: DMA_STATE <= DMA_STATE_DONE;
+ endcase
+ end
+
+ DMA_COPY_BYTE:
+ begin
+ // Byte copy DMA_ADDR_A -> DMA_ADDR_B odd bytes
+ case(DMA_IO_CNT)
+ 4'd0: DMA_STATE <= DMA_STATE_RD; // Read word
+ 4'd1: begin
+ DMA_DATA_OUT <= {DMA_RD_DATA[7:0], DMA_RD_DATA[15:8]};
+ DMA_STATE <= DMA_STATE_WR; // Write low byte
+ end
+ 4'd2: begin
+ DMA_DATA_OUT <= DMA_RD_DATA;
+ DMA_STATE <= DMA_STATE_WR; // Write high byte
+ end
+
+ default: DMA_STATE <= DMA_STATE_DONE;
+ endcase
+ end
+
+ DMA_FILL_VALUE:
+ begin
+ // Word fill from DMA_ADDR_A
+ case(DMA_IO_CNT)
+ 4'd0: DMA_STATE <= DMA_STATE_WR;
+ default: DMA_STATE <= DMA_STATE_DONE;
+ endcase
+ end
+
+ default: ;
+ endcase
+ end
+ end
+
+ if (DMA_STATE == DMA_STATE_CACHE_RD)
+ begin
+ DMA_RD_DATA[15:8] <= CACHE_DOUT; // Got upper byte
+ CACHE_RD_ADDR <= CACHE_RD_ADDR + 1'b1;
+ DMA_TIMER <= DMA_RW_CYCLES[7:0] >> 1; // TODO: Tune this
+ DMA_STATE <= DMA_STATE_CACHE_RD_L;
+ end
+
+ if (DMA_STATE == DMA_STATE_CACHE_RD_L)
+ begin
+ DMA_RD_DATA[7:0] <= CACHE_DOUT; // Got lower byte
+ CACHE_RD_ADDR <= CACHE_RD_ADDR + 1'b1;
+ DMA_IO_CNT <= DMA_IO_CNT + 1'b1;
+ DMA_STATE <= DMA_STATE_START;
+ end
+
+ if (DMA_STATE == DMA_STATE_WR)
+ begin
+ DMA_WR_OUT <= 1;
+ DMA_TIMER <= DMA_RW_CYCLES[7:0]; // TODO: Tune this
+ DMA_STATE <= DMA_STATE_WR_DONE;
+ end
+
+ if (DMA_STATE == DMA_STATE_WR_DONE)
+ begin
+ // Write done
+ DMA_WR_OUT <= 0;
+ DMA_ADDR_OUT <= DMA_ADDR_OUT + 2'd2;
+ DMA_IO_CNT <= DMA_IO_CNT + 1'b1;
+ DMA_STATE <= DMA_STATE_START;
+ end
+
+ if (DMA_STATE == DMA_STATE_RD)
+ begin
+ DMA_RD_OUT <= 1;
+ DMA_TIMER <= DMA_RW_CYCLES[7:0]; // TODO: Tune this
+ DMA_STATE <= DMA_STATE_RD_DONE;
+ end
+
+ if (DMA_STATE == DMA_STATE_RD_DONE)
+ begin
+ DMA_RD_OUT <= 0;
+ DMA_RD_DATA <= DMA_DATA_IN;
+ DMA_ADDR_IN <= DMA_ADDR_IN + 2'd2;
+ DMA_IO_CNT <= DMA_IO_CNT + 1'b1;
+ DMA_STATE <= DMA_STATE_START;
+ end
+
+ if (DMA_STATE == DMA_STATE_DONE)
+ begin
+ DMA_COUNT_RUN <= DMA_COUNT_RUN - 1'b1;
+ DMA_STATE <= DMA_STATE_START;
+ DMA_IO_CNT <= 4'd0;
+ end
+
+ end
+ end
+ end
+ end
+
+ wire READING = ~nAS & M68K_RW & (M68K_ADDR[23:12] == 12'hFF0) & SYSTEM_CDx;
+ wire WRITING = ~nAS & ~M68K_RW & (M68K_ADDR[23:12] == 12'hFF0) & SYSTEM_CDx;
+
+ wire LC8951_RD = (READING & (M68K_ADDR[11:2] == 10'b0001_000000)); // FF0101, FF0103
+ wire LC8951_WR = (WRITING & (M68K_ADDR[11:2] == 10'b0001_000000)); // FF0101, FF0103
+
+ // nAS used ?
+ wire TR_ZONE = (DMA_RUNNING ? (DMA_ADDR_OUT[23:20] == 4'hE) : (M68K_ADDR[23:20] == 4'hE)) & SYSTEM_CDx;
+
+ wire TR_ZONE_RD = TR_ZONE & (DMA_RUNNING ? DMA_RD_OUT : M68K_RW & ~(nLDS & nUDS));
+ wire TR_ZONE_WR = TR_ZONE & (DMA_RUNNING ? DMA_WR_OUT : ~M68K_RW & ~(nLDS & nUDS));
+
+ wire CD_TR_SPR = (CD_TR_AREA == 3'd0) & CD_USE_SPR;
+ wire CD_TR_PCM = (CD_TR_AREA == 3'd1) & CD_USE_PCM;
+ wire CD_TR_Z80 = (CD_TR_AREA == 3'd4) & CD_USE_Z80;
+ wire CD_TR_FIX = (CD_TR_AREA == 3'd5) & CD_USE_FIX;
+
+ // Allow writes only if the "allow write" flag of the corresponding region is set
+ assign CD_TR_WR_SPR = TR_ZONE_WR & CD_TR_SPR;
+ assign CD_TR_WR_PCM = TR_ZONE_WR & CD_TR_PCM;
+ assign CD_TR_WR_Z80 = TR_ZONE_WR & CD_TR_Z80;
+ assign CD_TR_WR_FIX = TR_ZONE_WR & CD_TR_FIX;
+
+ assign CD_TR_RD_FIX = TR_ZONE_RD & CD_TR_FIX;
+ assign CD_TR_RD_SPR = TR_ZONE_RD & CD_TR_SPR;
+ assign CD_TR_RD_Z80 = TR_ZONE_RD & CD_TR_Z80;
+ assign CD_TR_RD_PCM = TR_ZONE_RD & CD_TR_PCM;
+
+ reg [1:0] CDD_nIRQ_SR;
+
+ always @(posedge clk_sys)
+ begin
+ if (!nRESET)
+ begin
+ CD_USE_SPR <= 0;
+ CD_USE_PCM <= 0;
+ CD_USE_Z80 <= 0;
+ CD_USE_FIX <= 0;
+ CD_SPR_EN <= 1; // ?
+ CD_FIX_EN <= 1; // ?
+ CD_VIDEO_EN <= 1; // ?
+ CD_UPLOAD_EN <= 0;
+ CD_nRESET_Z80 <= 0; // ?
+ CD_nRESET_DRIVE <= 0; // ?
+ HOCK <= 1;
+ REG_FF0002 <= 16'h0; // ?
+ REG_FF0004 <= 0; // ?
+ nLDS_PREV <= 1;
+ nUDS_PREV <= 1;
+ CD_IRQ <= 1;
+ CD_IRQ_FLAGS <= 3'b111;
+ DMA_START <= 0;
+
+ CDD_nIRQ_SR <= 2'b11;
+ end
+ else if (CLK_68KCLK_EN) begin
+ nLDS_PREV <= nLDS;
+ nUDS_PREV <= nUDS;
+ CDD_nIRQ_SR <= {CDD_nIRQ_SR[0], CDD_nIRQ};
+ CDC_nIRQ_PREV <= CDC_nIRQ;
+
+ // Falling edge of CDD_nIRQ
+ //if (CDD_nIRQ_PREV & ~CDD_nIRQ)
+ if (CDD_nIRQ_SR == 2'b10)
+ begin
+ // Trigger CD comm. interrupt
+ if (REG_FF0002[6] & REG_FF0002[4])
+ CD_IRQ_FLAGS[1] <= 0;
+
+ // REG_FF0002:
+ // C = CD comm. interrupt
+ // S = Sector ready interrupt ?
+ // 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
+ // S S C C
+ end
+
+ // Falling edge of CDC_nIRQ
+ if (CDC_nIRQ_PREV & ~CDC_nIRQ)
+ begin
+ // Trigger CDC interrupt (decoder or transfer end)
+ if (REG_FF0002[10] & REG_FF0002[8])
+ CD_IRQ_FLAGS[2] <= 0;
+ end
+
+ CD_IRQ <= ~&{CD_IRQ_FLAGS};
+
+ // Trigger
+ if (DMA_START)
+ DMA_START <= 0;
+
+ if (SYSTEM_CDx & ((nLDS_PREV & ~nLDS) | (nUDS_PREV & ~nUDS))) // & PREV_nAS & ~nAS
+ begin
+ // Writes
+ if ((M68K_ADDR[23:9] == 15'b11111111_0000000) & ~M68K_RW)
+ begin
+ casez ({M68K_ADDR[8:1], nUDS, nLDS})
+ // FF00xx
+ 10'b0_0000001_00: REG_FF0002 <= M68K_DATA; // FF0002
+ 10'b0_0000010_00: REG_FF0004 <= M68K_DATA[11:0]; // FF0004
+ 10'b0_0000111_?0: CD_IRQ_FLAGS <= CD_IRQ_FLAGS | M68K_DATA[5:3]; // FF000E
+
+ 10'b0_0110000_10: // FF0061
+ begin
+ if (M68K_DATA[6])
+ begin
+ // DMA start
+ DMA_START <= 1;
+ case (DMA_MICROCODE[0])
+ 16'hFF89, 16'hFFC5:
+ begin
+ // Copy LC8951 cache -> DMA_ADDR_A
+ // Count in words even it's really a byte copy
+ // TOP-SP1 @ C119F4
+ // $FF89 $FCF5 $D8A6 $F627 $03FD $FFFF
+ DMA_MODE <= DMA_COPY_CD_WORD;
+ end
+
+ 16'hFC2D:
+ begin
+ // Copy LC8951 cache -> DMA_ADDR_A odd bytes
+ // FC2D
+ DMA_MODE <= DMA_COPY_CD_BYTE;
+ end
+
+ 16'hFE6D, 16'hFE3D:
+ begin
+ // Word copy DMA_ADDR_A -> DMA_ADDR_B
+ // Count in words
+ // TOP-SP1 @ C119D4
+ // $FE6D $FCF5 $82BF $F693 $BF29 $02FD $FFFF $C515 $FCF5
+
+ // Word copy DMA_ADDR_A -> DMA_ADDR_B
+ // Different microcode, same operation ?
+ // Used by UploadPRGDMAWords, UploadPalDMAWords
+ // TOP-SP1 @ C0C07C
+ // $FE6D $FCF5 $82BF $F693 $BF29 $02FD $FFFF $F97D $FCF5
+ DMA_MODE <= DMA_COPY_WORD;
+ end
+
+ 16'hF2DD, 16'hE2DD:
+ begin
+ // Byte copy DMA_ADDR_A -> odd bytes DMA_ADDR_B ?
+ // Used by UploadFIXDMABytes, UploadPCMDMABytes, UploadZ80DMABytes
+ // Count in words
+ // TOP-SP1 @ C0C09A
+ // $F2DD $82F6 $93DA $BE93 $DABE $2C02 $FDFF
+ DMA_MODE <= DMA_COPY_BYTE;
+ end
+
+ 16'hFFCD, 16'hFFDD:
+ begin
+ // Word fill starting at DMA_ADDR_A
+ // Used by DMAClearPalettes, DMAClearPCMDRAM?
+ // Count in words
+ // TOP-SP1 @ C0C09A
+ // $FFCD $FCF5 $92F6 $2602 $FDFF
+ DMA_MODE <= DMA_FILL_VALUE;
+ end
+
+ default: ;
+ endcase
+ // Other microcodes are used but only for the test mode, those can wait
+ // See TOP-SP1 @ C0AB26, TOP-SP1 @ C0AB3E, TOP-SP1 @ C0AB5A
+ end
+ end
+ 10'b0_0110010_00: DMA_ADDR_A[23:16] <= M68K_DATA[7:0]; // FF0064~FF0065
+ 10'b0_0110011_00: DMA_ADDR_A[15:0] <= M68K_DATA; // FF0066~FF0067
+ 10'b0_0110100_00: DMA_ADDR_B[23:16] <= M68K_DATA[7:0]; // FF0068~FF0069
+ 10'b0_0110101_00: DMA_ADDR_B[15:0] <= M68K_DATA; // FF006A~FF006B
+ 10'b0_0110110_00: DMA_VALUE[31:16] <= M68K_DATA; // FF006C~FF006D
+ 10'b0_0110111_00: DMA_VALUE[15:0] <= M68K_DATA; // FF006E~FF006F
+ 10'b0_0111000_00: DMA_COUNT[31:16] <= M68K_DATA; // FF0070~FF0071
+ 10'b0_0111001_00: DMA_COUNT[15:0] <= M68K_DATA; // FF0072~FF0073
+ 10'b0_0111111_00: DMA_MICROCODE[0] <= M68K_DATA; // FF007E M68K_ADDR[4:1]
+ 10'b0_1000000_00: DMA_MICROCODE[1] <= M68K_DATA; // FF0080 M68K_ADDR[4:1]
+ 10'b0_1000001_00: DMA_MICROCODE[2] <= M68K_DATA; // FF0082 M68K_ADDR[4:1]
+ 10'b0_1000010_00: DMA_MICROCODE[3] <= M68K_DATA; // FF0084 M68K_ADDR[4:1]
+ 10'b0_1000011_00: DMA_MICROCODE[4] <= M68K_DATA; // FF0086 M68K_ADDR[4:1]
+ 10'b0_1000100_00: DMA_MICROCODE[5] <= M68K_DATA; // FF0088 M68K_ADDR[4:1]
+ 10'b0_1000101_00: DMA_MICROCODE[6] <= M68K_DATA; // FF008A M68K_ADDR[4:1]
+ 10'b0_1000110_00: DMA_MICROCODE[7] <= M68K_DATA; // FF008C M68K_ADDR[4:1]
+ 10'b0_1000111_00: DMA_MICROCODE[8] <= M68K_DATA; // FF008E M68K_ADDR[4:1]
+
+ // FF01xx
+ 10'b1_0000010_?0: CD_TR_AREA <= M68K_DATA[2:0]; // FF0105 Upload area select
+ 10'b1_0001000_?0: CD_SPR_EN <= ~M68K_DATA[0]; // FF0111 REG_DISBLSPR
+ 10'b1_0001010_?0: CD_FIX_EN <= ~M68K_DATA[0]; // FF0115 REG_DISBLFIX
+ 10'b1_0001100_?0: CD_VIDEO_EN <= M68K_DATA[0]; // FF0119 REG_ENVIDEO
+ 10'b1_0010000_?0: CD_USE_SPR <= 1; // FF0121 REG_UPMAPSPR
+ 10'b1_0010001_?0: CD_USE_PCM <= 1; // FF0123 REG_UPMAPPCM
+ 10'b1_0010011_?0: CD_USE_Z80 <= 1; // FF0127 REG_UPMAPZ80
+ 10'b1_0010100_?0: CD_USE_FIX <= 1; // FF0129 REG_UPMAPFIX
+ 10'b1_0100000_?0: CD_USE_SPR <= 0; // FF0141 REG_UPUNMAPSPR
+ 10'b1_0100001_?0: CD_USE_PCM <= 0; // FF0143 REG_UPUNMAPSPR
+ 10'b1_0100011_?0: CD_USE_Z80 <= 0; // FF0147 REG_UPUNMAPSPR
+ 10'b1_0100100_?0: CD_USE_FIX <= 0; // FF0149 REG_UPUNMAPSPR
+ 10'b1_0110001_10: CDD_DIN <= M68K_DATA[3:0]; // FF0163 REG_CDDOUTPUT
+ 10'b1_0110010_10: HOCK <= M68K_DATA[0]; // FF0165 REG_CDDCTRL
+ 10'b1_0110111_?0: CD_UPLOAD_EN <= M68K_DATA[0]; // FF016F
+ 10'b1_1000000_?0: CD_nRESET_DRIVE <= M68K_DATA[0]; // FF0181
+ 10'b1_1000001_?0: CD_nRESET_Z80 <= M68K_DATA[0]; // FF0183
+ 10'b1_1010000_?0: CD_BANK_SPR <= M68K_DATA[1:0]; // FF01A1 REG_SPRBANK
+ 10'b1_1010001_?0: CD_BANK_PCM <= M68K_DATA[0]; // FF01A3 REG_PCMBANK
+ default:;
+ endcase
+ end
+ else if ((M68K_ADDR[23:20] == 4'hE) & ~M68K_RW)
+ begin
+ // Upload zone
+ // Is this buffered or is the write directy forwarded to memory ?
+ CD_TR_WR_DATA <= M68K_DATA;
+ CD_TR_WR_ADDR <= M68K_ADDR[19:1];
+ end
+ end
+ end
+ end
+
+ // 1111:JP, 1110:US, 1101: EU
+ wire [3:0] CD_JUMPERS = {2'b11, CD_REGION};
+
+ wire [7:0] CD_IRQ_VECTOR = (M68K_ADDR[2:1] == 2'd3) ? 8'd25 : // Timer $64
+ (M68K_ADDR[2:1] == 2'd2) & ~CD_IRQ_FLAGS[0] ? 8'd23 :
+ (M68K_ADDR[2:1] == 2'd2) & ~CD_IRQ_FLAGS[1] ? 8'd22 : // CD comm. $58
+ (M68K_ADDR[2:1] == 2'd2) & ~CD_IRQ_FLAGS[2] ? 8'd21 : // CD decoder $54
+ (M68K_ADDR[2:1] == 2'd1) ? 8'd26 : // VBlank $68
+ 8'd24; // Spurious interrupt, should not happen
+
+ function [15:0] bit_reverse;
+ input [15:0] a;
+ begin
+ bit_reverse = { a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15] };
+ end
+ endfunction
+
+ assign CD_VBLANK_IRQ_EN = &{REG_FF0004[5:4]};
+ assign CD_TIMER_IRQ_EN = &{REG_FF0004[9:8]};
+
+ assign M68K_DATA = (SYSTEM_CDx & ~nAS & M68K_RW & IACK) ? {8'h00, CD_IRQ_VECTOR} : // Vectored interrupt handler
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h004) ? {4'h0, REG_FF0004} :
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h11C) ? {3'b110, CD_LID, CD_JUMPERS, 8'h00} : // Top mech
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h160) ? {11'b00000000_000, CDCK, CDD_DOUT} : // REG_CDDINPUT
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h166) ? {16'd0} : // Bit 5 needs to be clear for VU meters in CD player to work
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h188) ? bit_reverse(CD_AUDIO_L) : // CDDA L
+ (READING & {M68K_ADDR[11:1], 1'b0} == 12'h18A) ? bit_reverse(CD_AUDIO_R) : // CDDA R
+ (LC8951_RD) ? {8'h00, LC8951_DOUT} :
+ 16'bzzzzzzzz_zzzzzzzz;
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cdda.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cdda.v
new file mode 100644
index 0000000000000000000000000000000000000000..f4a4b54e83bc3efd67922efcdc259f5cbea07ec6
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/cdda.v
@@ -0,0 +1,90 @@
+module cdda
+(
+ input CLK,
+ input nRESET,
+ input READ,
+ input WRITE,
+ input [15:0] DIN,
+ output WRITE_READY,
+ output reg [15:0] AUDIO_L,
+ output reg [15:0] AUDIO_R
+
+);
+
+localparam SECTOR_SIZE = 2352*8/32;
+localparam BUFFER_AMOUNT = 2 * SECTOR_SIZE;
+
+reg OLD_WRITE, OLD_READ, LRCK, WR_REQ;
+
+reg [15:0] DATA;
+reg [12:0] FILLED_COUNT;
+
+reg [12:0] READ_ADDR, WRITE_ADDR;
+
+wire EMPTY = ~|FILLED_COUNT;
+wire FULL = (FILLED_COUNT == BUFFER_AMOUNT);
+wire WRITE_CE = ~OLD_WRITE & WRITE;
+wire READ_CE = ~OLD_READ & READ;
+wire READ_REQ = READ_CE & ~EMPTY;
+
+assign WRITE_READY = (FILLED_COUNT <= (BUFFER_AMOUNT - SECTOR_SIZE)); // Ready to receive sector
+
+always @(posedge CLK) begin
+ if (~nRESET) begin
+ OLD_WRITE <= 0;
+ OLD_READ <= 0;
+ LRCK <= 0;
+ READ_ADDR <= 0;
+ WRITE_ADDR <= 0;
+ FILLED_COUNT <= 0;
+ end else begin
+ OLD_WRITE <= WRITE;
+ OLD_READ <= READ;
+
+ WR_REQ <= 0;
+ if (WRITE_CE) begin
+ LRCK <= ~LRCK;
+ if (~LRCK) begin
+ DATA <= DIN;
+ end else if(~FULL) begin
+ WR_REQ <= 1;
+ end
+ end
+
+ if (WR_REQ) begin
+ if (WRITE_ADDR == BUFFER_AMOUNT-1) begin
+ WRITE_ADDR <= 0;
+ end else begin
+ WRITE_ADDR <= WRITE_ADDR + 1'b1;
+ end
+ end
+
+ if (READ_REQ) begin
+ if (READ_ADDR == BUFFER_AMOUNT-1) begin
+ READ_ADDR <= 0;
+ end else begin
+ READ_ADDR <= READ_ADDR + 1'b1;
+ end
+ AUDIO_L <= BUFFER_Q[15:0];
+ AUDIO_R <= BUFFER_Q[31:16];
+ end
+
+ if (READ_CE & EMPTY) begin
+ AUDIO_L <= 0;
+ AUDIO_R <= 0;
+ end
+
+ FILLED_COUNT <= FILLED_COUNT + WR_REQ - READ_REQ;
+ end
+end
+
+reg [31:0] BUFFER[BUFFER_AMOUNT];
+reg [31:0] BUFFER_Q;
+always @(posedge CLK) begin
+ BUFFER_Q <= BUFFER[READ_ADDR];
+ if (WR_REQ) begin
+ BUFFER[WRITE_ADDR] <= { DIN, DATA };
+ end
+end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/drive.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/drive.v
new file mode 100644
index 0000000000000000000000000000000000000000..d9c4600840578459115dba1ba172619723c21a06
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/drive.v
@@ -0,0 +1,260 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+// This module handles the CDD 4-bit communication bus, TOC readback and keeps
+// track of the current MSF
+// The protocol is very similar (if not identical) to the one used by the Mega CD drive
+
+module cd_drive(
+ input nRESET, // System reset OR drive reset
+ input HOCK,
+ output reg CDCK,
+ input [3:0] CDD_DIN,
+ output reg [3:0] CDD_DOUT,
+ output reg CDD_nIRQ,
+
+ input clk_sys,
+ input [39:0] STATUS_IN,
+ input STATUS_LATCH,
+ output reg [39:0] COMMAND_DATA,
+ output reg COMMAND_SEND
+);
+
+ // Command codes
+ parameter CMD_NOP=4'd0, CMD_STOP=4'd1, CMD_TOC=4'd2, CMD_PLAY=4'd3, CMD_SEEK=4'd4, CMD_PAUSE=4'd6, CMD_RESUME=4'd7,
+ CMD_FFW=4'd8, CMD_REW=4'd9, CMD_CLOSE=4'd12, CMD_OPEN=4'd13;
+
+ // TOC sub-commands
+ parameter TOC_ABSPOS=4'd0, TOC_RELPOS=4'd1, TOC_TRACK=4'd2, TOC_LENGTH=4'd3, TOC_FIRSTLAST=4'd4, TOC_START=4'd5,
+ TOC_ERROR=4'd6;
+
+ // Status codes
+ parameter STAT_STOPPED=4'd0, STAT_PLAYING=4'd1, STAT_READTOC=4'd9;
+
+ // Current TOC sub-command implementation:
+ // 0: Get position
+ // Unimplemented
+ // 1: Get position relative
+ // Unimplemented
+ // 2: Get track number
+ // Unimplemented
+ // 3: Get CD length: sd_req_type = 16'hD100
+ // 0: M
+ // 1: S
+ // 2: F
+ // 4: Get first/last: sd_req_type = 16'hD000
+ // 0: First track # BCD
+ // 1: Last track # BCD
+ // 5: Get track start: sd_req_type = 16'hD2nn
+ // 0: M
+ // 1: S
+ // 2: F
+ // 3: Type
+ // 6: Get last error
+ // Unimplemented
+
+ reg [8:0] CLK_DIV; // SLOW THE FUCK DOWN
+ reg [11:0] IRQ_TIMER;
+ reg [3:0] DOUT_COUNTER; // 0~10
+ reg [3:0] DIN_COUNTER; // 0~10, 11 is special code for processing
+
+ reg [3:0] STATUS_DATA [10];
+ reg STATUS_LATCH_OLD, STATUS_PENDING;
+
+ reg HOCK_PREV;
+ reg [1:0] COMM_STATE; // 0~2
+ reg COMM_RUN;
+
+ always @(posedge clk_sys)
+ begin
+ if (!nRESET)
+ begin
+ CLK_DIV <= 9'd0;
+ IRQ_TIMER <= 12'd0;
+ DOUT_COUNTER <= 4'd0;
+ DIN_COUNTER <= 4'd0;
+ HOCK_PREV <= 0;
+ CDCK <= 1;
+ COMM_STATE <= 2'd0;
+ COMM_RUN <= 0;
+ CDD_nIRQ <= 1;
+ STATUS_DATA[0] <= STAT_STOPPED;
+ STATUS_DATA[1] <= 4'd0;
+ STATUS_DATA[2] <= 4'd0;
+ STATUS_DATA[3] <= 4'd0;
+ STATUS_DATA[4] <= 4'd0;
+ STATUS_DATA[5] <= 4'd0;
+ STATUS_DATA[6] <= 4'd0;
+ STATUS_DATA[7] <= 4'd0;
+ STATUS_DATA[8] <= 4'd0;
+ STATUS_DATA[9] <= 4'd0;
+ STATUS_PENDING <= 0;
+ STATUS_LATCH_OLD <= 0;
+ COMMAND_SEND <= 0;
+ end
+ else
+ begin
+
+ STATUS_LATCH_OLD <= STATUS_LATCH;
+ if (~STATUS_LATCH_OLD & STATUS_LATCH) begin
+ STATUS_PENDING <= 1;
+ end
+
+ COMMAND_SEND <= 0;
+
+ // This simulates the Sony CDD MCU, so it must be quite slow
+ // Here it "runs" at clk_sys/192=48M/192=250kHz
+
+ if (CLK_DIV == 9'd192-1)
+ begin
+ CLK_DIV <= 9'd0;
+
+ HOCK_PREV <= HOCK;
+
+ // Fire CDD comm. IRQ at 64Hz
+ // Does it switch to 75Hz when playing ?
+ if (IRQ_TIMER == 12'd3906-1)
+ begin
+ IRQ_TIMER <= 12'd0;
+ CDD_nIRQ <= 0;
+ COMM_STATE <= 2'd0;
+ COMM_RUN <= 0;
+ end
+ else
+ begin
+ // Retry whatever happens
+ if (IRQ_TIMER == 12'd1953-1)
+ CDD_nIRQ <= 1;
+
+ IRQ_TIMER <= IRQ_TIMER + 1'b1;
+ end
+
+ if (STATUS_PENDING & (DOUT_COUNTER == 4'd10)) begin
+ STATUS_PENDING <= 0;
+ STATUS_DATA[0] <= STATUS_IN[ 3: 0];
+ STATUS_DATA[1] <= STATUS_IN[ 7: 4];
+ STATUS_DATA[2] <= STATUS_IN[11: 8];
+ STATUS_DATA[3] <= STATUS_IN[15:12];
+ STATUS_DATA[4] <= STATUS_IN[19:16];
+ STATUS_DATA[5] <= STATUS_IN[23:20];
+ STATUS_DATA[6] <= STATUS_IN[27:24];
+ STATUS_DATA[7] <= STATUS_IN[31:28];
+ STATUS_DATA[8] <= STATUS_IN[35:32];
+ STATUS_DATA[9] <= STATUS_IN[39:36];
+ end
+
+ if (~HOCK & ~CDD_nIRQ) begin
+ CDD_nIRQ <= 1; // Comm. started ok, ack
+ COMM_RUN <= 1;
+ DOUT_COUNTER <= 4'd0;
+ DIN_COUNTER <= 4'd0;
+ end
+
+ if (COMM_RUN)
+ begin
+ if (DOUT_COUNTER != 4'd10)
+ begin
+ // CDD to HOST
+
+ if (COMM_STATE == 2'd0)
+ begin
+ // Put data on bus
+ CDD_DOUT <= STATUS_DATA[DOUT_COUNTER];
+ CDCK <= 0;
+ COMM_STATE <= 2'd1;
+ end
+ else if (COMM_STATE == 2'd1)
+ begin
+ // Wait for HOCK high
+ if (~HOCK_PREV & HOCK)
+ begin
+ CDCK <= 1;
+ COMM_STATE <= 2'd2;
+ // Escape from CDD -> HOST mode at last word
+ if (DOUT_COUNTER == 4'd9)
+ begin
+ DOUT_COUNTER <= 4'd10;
+ COMM_STATE <= 2'd1;
+ end
+ end
+ end
+ else if (COMM_STATE == 2'd2)
+ begin
+ // Wait for HOCK low
+ if (HOCK_PREV & ~HOCK)
+ begin
+ DOUT_COUNTER <= DOUT_COUNTER + 1'b1;
+ COMM_STATE <= 2'd0;
+ end
+ end
+
+ end
+ else if (DIN_COUNTER < 4'd10)
+ begin
+ // HOST to CDD
+
+ if (COMM_STATE == 2'd0)
+ begin
+ // Wait for HOCK rising edge
+ if (~HOCK_PREV & HOCK)
+ begin
+ case (DIN_COUNTER)
+ 4'd0: COMMAND_DATA[ 3: 0] <= CDD_DIN;
+ 4'd1: COMMAND_DATA[ 7: 4] <= CDD_DIN;
+ 4'd2: COMMAND_DATA[11: 8] <= CDD_DIN;
+ 4'd3: COMMAND_DATA[15:12] <= CDD_DIN;
+ 4'd4: COMMAND_DATA[19:16] <= CDD_DIN;
+ 4'd5: COMMAND_DATA[23:20] <= CDD_DIN;
+ 4'd6: COMMAND_DATA[27:24] <= CDD_DIN;
+ 4'd7: COMMAND_DATA[31:28] <= CDD_DIN;
+ 4'd8: COMMAND_DATA[35:32] <= CDD_DIN;
+ 4'd9: COMMAND_DATA[39:36] <= CDD_DIN;
+ default: ;
+ endcase
+ CDCK <= 1;
+ DIN_COUNTER <= DIN_COUNTER + 1'b1;
+ COMM_STATE <= 2'd1;
+ end
+ end
+ else if (COMM_STATE == 2'd1)
+ begin
+ // Wait for HOCK falling edge
+ if (HOCK_PREV & ~HOCK)
+ begin
+ CDCK <= 0;
+ COMM_STATE <= 2'd0;
+ end
+ end
+
+ end
+ else if (DIN_COUNTER == 4'd10)
+ begin
+ // Comm frame just ended, do this just once
+ COMMAND_SEND <= 1;
+ COMM_RUN <= 0;
+ end
+
+ end
+ end
+ else
+ CLK_DIV <= CLK_DIV + 1'b1;
+ end
+ end
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/hps_ext.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/hps_ext.v
new file mode 100644
index 0000000000000000000000000000000000000000..5bbbfe565d9b851edb69ab9fab8865e898a7fc69
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/hps_ext.v
@@ -0,0 +1,110 @@
+//
+// hps_ext for Mega CD
+//
+// Copyright (c) 2020 Alexey Melnikov
+//
+// This source file is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This source file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+///////////////////////////////////////////////////////////////////////
+
+module hps_ext
+(
+ input clk_sys,
+ inout [35:0] EXT_BUS,
+
+ // CD interface
+ input [48:0] cd_in,
+ output reg [48:0] cd_out,
+
+ input cdda_ready,
+ input cd_data_ready
+);
+
+assign EXT_BUS[15:0] = io_dout;
+wire [15:0] io_din = EXT_BUS[31:16];
+assign EXT_BUS[32] = dout_en;
+wire io_strobe = EXT_BUS[33];
+wire io_enable = EXT_BUS[34];
+
+localparam EXT_CMD_MIN = CD_GET;
+localparam EXT_CMD_MAX = CD_SET;
+
+localparam CD_GET = 'h34;
+localparam CD_SET = 'h35;
+
+reg [15:0] io_dout;
+reg dout_en = 0;
+reg [9:0] byte_cnt;
+
+always@(posedge clk_sys) begin
+ reg [15:0] cmd;
+ reg [7:0] cd_req = 0;
+ reg old_cd = 0;
+ reg [1:0] get_cmd;
+ reg send_data_type;
+
+ old_cd <= cd_in[48];
+ if(old_cd ^ cd_in[48]) cd_req <= cd_req + 1'd1;
+
+ if(~io_enable) begin
+ dout_en <= 0;
+ io_dout <= 0;
+ byte_cnt <= 0;
+ if(cmd == 'h35) cd_out[48] <= ~cd_out[48];
+ end
+ else if(io_strobe) begin
+
+ io_dout <= 0;
+ if(~&byte_cnt) byte_cnt <= byte_cnt + 1'd1;
+
+ if(byte_cnt == 0) begin
+ cmd <= io_din;
+ dout_en <= (io_din >= EXT_CMD_MIN && io_din <= EXT_CMD_MAX);
+ if(io_din == CD_GET) io_dout <= cd_req;
+ end else begin
+ case(cmd)
+ CD_GET:
+ if(!byte_cnt[9:3]) begin
+ if (byte_cnt[2:0] == 1) begin
+ get_cmd <= io_din[1:0];
+ send_data_type <= io_din[2];
+ end else begin
+ if (get_cmd == 0) begin // Request Command data
+ case(byte_cnt[2:0])
+ 2: io_dout <= cd_in[15:0];
+ 3: io_dout <= cd_in[31:16];
+ 4: io_dout <= cd_in[47:32];
+ endcase
+ end else if (get_cmd == 1) begin // Request ready for data
+ if (byte_cnt[2:0] == 2) begin
+ io_dout <= {15'd0, send_data_type ? cd_data_ready : cdda_ready};
+ end
+ end
+ end
+ end
+
+ CD_SET:
+ if(!byte_cnt[9:3]) begin
+ case(byte_cnt[2:0])
+ 1: cd_out[15:0] <= io_din;
+ 2: cd_out[31:16] <= io_din;
+ 3: cd_out[47:32] <= io_din;
+ endcase
+ end
+ endcase
+ end
+ end
+end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/lc8951.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/lc8951.v
new file mode 100644
index 0000000000000000000000000000000000000000..8d5389dc788f8939fd3a7d785d8e3088b10ef6d6
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cd/lc8951.v
@@ -0,0 +1,234 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+// This module handles the bare essentials to make the Neo CD system ROM happy with
+// communicating with the LC8951 CD host chip
+// The LC8953-LC8951 handshake signals aren't implemented, no functional need for
+// that as it's all automatic while the 68k waits
+
+// altera message_off 10036 10240
+
+module lc8951(
+ input nRESET,
+ input clk_sys,
+ input CLK_68KCLK_EN,
+ input nWR, nRD,
+ input RS, // Register select, 0=Access address register, 1=Access pointed register
+ input [7:0] DIN,
+ output reg [7:0] DOUT,
+
+ input [31:0] HEADER_DIN,
+
+ input SECTOR_READY,
+ input DMA_RUNNING,
+
+ output reg CDC_nIRQ // Triggers when SECTOR_READY or DMA_RUNNING rises and IRQ enabled
+);
+
+ reg [3:0] AR; // Address Register
+ reg [7:0] REGS_WRITE [16];
+
+ reg [11:0] DBC; // Byte counter for transfer
+ reg [15:0] DAC; // Transfer address - Can ignore ? Should always be set to 0000
+ //reg [15:0] PT; // Pointer to start of data block - Can always be 0004 ?
+ // System ROM subtracts 4 to ignore MSF/Mode header
+ reg [15:0] WA; // Unused on Neo CD ?
+ reg nDTBSY, nSTBSY, nDTEN, nSTEN, nVALST;
+ reg [7:0] HEAD [4];
+
+ // Bunch of decoder and error detection/correction flags which could be hardcoded
+ // Can't have CD errors if there's no CD !
+ reg CMDI_FLAG, DTEI_FLAG, DECI_FLAG;
+ reg CMDIEN, DTEIEN, DECIEN, nCMDBRK, nDTWAI, nSTWAI, DOUTEN, SOUTEN;
+ reg DTTRG;
+ reg DECEN, EDCRQ, E01RQ, AUTORQ, ERAMRQ, WRRQ, QRQ, PRQ;
+ reg SYIEN, SYDEN, DSCREN, COWREN, MODRQ, FORMRQ, SHDREN;
+
+ reg nWR_PREV, nRD_PREV;
+ reg SECTOR_READY_PREV, DMA_RUNNING_PREV, HEADER_WR_PREV;
+
+ reg [15:0] INT_CYCLE_CNT;
+
+ // 12 x 1800. LC8950 manual says that LC8951 /INT goes low for 1.8ms
+ localparam INT_CYCLES = 16'd21600;
+
+ always @(posedge clk_sys)
+ begin
+ if (!nRESET)
+ begin
+ AR <= 4'd0;
+ nWR_PREV <= 1;
+ nRD_PREV <= 1;
+
+ CDC_nIRQ <= 1;
+
+ DBC <= 12'h000;
+ DAC <= 16'h0000;
+ //PT <= 16'h0000;
+ WA <= 16'h0000;
+
+ CMDI_FLAG <= 0;
+ DTEI_FLAG <= 0;
+ DECI_FLAG <= 0;
+ nDTBSY <= 1;
+ nSTBSY <= 1;
+ nDTEN <= 1;
+ nSTEN <= 1;
+
+ HEAD[0] <= 8'h00;
+ HEAD[1] <= 8'h00;
+ HEAD[2] <= 8'h00;
+ HEAD[3] <= 8'h00;
+
+ nVALST <= 1;
+
+ {CMDIEN, DTEIEN, DECIEN, nCMDBRK, nDTWAI, nSTWAI, DOUTEN, SOUTEN} <= 8'b00000000;
+ DTTRG <= 0;
+ {DECEN, EDCRQ, E01RQ, AUTORQ, ERAMRQ, WRRQ, QRQ, PRQ} <= 8'b00000000;
+ {SYIEN, SYDEN, DSCREN, COWREN, MODRQ, FORMRQ, SHDREN} <= 7'b0000000;
+
+ SECTOR_READY_PREV <= 0;
+ DMA_RUNNING_PREV <= 0;
+ HEADER_WR_PREV <= 0;
+
+ INT_CYCLE_CNT <= 0;
+ end
+ else
+ if (CLK_68KCLK_EN) begin
+
+ SECTOR_READY_PREV <= SECTOR_READY;
+ DMA_RUNNING_PREV <= DMA_RUNNING;
+
+ // Rising edge of SECTOR_READY: Set decoder IRQ flag
+ if (~SECTOR_READY_PREV & SECTOR_READY) begin
+ if (DECEN) begin
+ DECI_FLAG <= 1;
+ nVALST <= 0;
+ INT_CYCLE_CNT <= 0;
+ HEAD[0] <= HEADER_DIN[ 7: 0];
+ HEAD[1] <= HEADER_DIN[15: 8];
+ HEAD[2] <= HEADER_DIN[23:16];
+ HEAD[3] <= HEADER_DIN[31:24];
+ end
+ end else if (~nVALST) begin // Use nVALST because DECI can be reset by reading STAT3.
+ if (INT_CYCLE_CNT < INT_CYCLES) begin
+ INT_CYCLE_CNT <= INT_CYCLE_CNT + 1'b1;
+ end else begin // Decoder INT timeout
+ DECI_FLAG <= 0;
+ nVALST <= 1;
+ end
+ end
+
+ // Falling edge of DMA_RUNNING: Set transfer end IRQ flag
+ if (DMA_RUNNING_PREV & ~DMA_RUNNING) begin
+ //DTEI_FLAG <= 1;
+ nDTBSY <= 1;
+ end
+
+ CDC_nIRQ <= ~|{(CMDI_FLAG & CMDIEN), (DTEI_FLAG & DTEIEN), (DECI_FLAG & DECIEN)};
+
+ nWR_PREV <= nWR;
+ nRD_PREV <= nRD;
+
+ if (nWR_PREV & ~nWR)
+ begin
+ // Write
+ if (~RS)
+ AR <= DIN[3:0];
+ else
+ begin
+ case(AR)
+ 4'd0:; // COMIN - Is the command system used at all ?
+ 4'd1: {CMDIEN, DTEIEN, DECIEN, nCMDBRK, nDTWAI, nSTWAI, DOUTEN, SOUTEN} <= DIN; // IFCTRL
+
+ 4'd2: DBC[7:0] <= DIN; // DBCL - Data transfer byte counter
+ 4'd3: DBC[11:8] <= DIN[3:0]; // DBCH
+
+ 4'd4: DAC[7:0] <= DIN; // DACL
+ 4'd5: DAC[15:8] <= DIN; // DACH
+ 4'd6: begin
+ DTTRG <= 1;
+ if (DOUTEN) begin
+ nDTBSY <= 0;
+ end
+ end
+ 4'd7: DTEI_FLAG <= 0; // DTACK - Clears the transfer end IRQ flag
+
+ 4'd8: WA[7:0] <= DIN; // WAL
+ 4'd9: WA[15:8] <= DIN; // WAH
+
+ 4'd10: {DECEN, EDCRQ, E01RQ, AUTORQ, ERAMRQ, WRRQ, QRQ, PRQ} <= DIN; // CTRL0
+ 4'd11: {SYIEN, SYDEN, DSCREN, COWREN, MODRQ, FORMRQ, SHDREN} <= {DIN[7:2], DIN[0]}; // CTRL1
+
+ 4'd12:; //PT[7:0] <= DIN; // PTL
+ 4'd13:; //PT[15:8] <= DIN; // PTH
+ 4'd14:;
+ 4'd15:; // RESET - Unused ?
+ endcase
+
+ // Auto-inc if AR is nonzero
+ if (|{AR})
+ AR <= AR + 1'b1;
+ end
+ end
+ else if (nRD_PREV & ~nRD)
+ begin
+ // Read
+ if (~RS)
+ DOUT <= {4'b0000, AR};
+ else
+ begin
+ case(AR)
+ 4'd0: DOUT <= 8'b00000000; // SBOUT - Is the command system used at all ?
+ 4'd1: DOUT <= {~CMDI_FLAG, ~DTEI_FLAG, ~DECI_FLAG, 1'b1, nDTBSY, nSTBSY, nDTEN, nSTEN}; // IFSTAT
+
+ 4'd2: DOUT <= DBC[7:0]; // DBCL - Data transfer byte counter
+ 4'd3: DOUT <= {{4{DTEI_FLAG}}, DBC[11:8]}; // DBCH
+
+ 4'd4: DOUT <= HEAD[0];
+ 4'd5: DOUT <= HEAD[1];
+ 4'd6: DOUT <= HEAD[2];
+ 4'd7: DOUT <= HEAD[3]; // CD-ROM mode, always 1
+
+ 4'd8: DOUT <= 8'h04; //PT[7:0]; // PTL
+ 4'd9: DOUT <= 8'h00; //PT[15:8]; // PTH
+
+ 4'd10: DOUT <= WA[7:0]; // WAL - Datasheet says these are undefined after reset
+ 4'd11: DOUT <= WA[15:8]; // WAH
+
+ 4'd12: DOUT <= 8'b10000000; // STAT0 - CRC OK
+ 4'd13: DOUT <= 8'b00000000; // STAT1
+ 4'd14: DOUT <= 8'b00000000; // STAT2 - MODE, FORM (Mode 1)
+ 4'd15:
+ begin
+ DOUT <= {nVALST, 7'b0000000}; // STAT3 - Reading clears the decoder IRQ
+ DECI_FLAG <= 0;
+ end
+ endcase
+
+ // Auto-inc if AR is nonzero
+ if (|{AR})
+ AR <= AR + 1'b1;
+ end
+ end
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/C43.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/C43.v
new file mode 100644
index 0000000000000000000000000000000000000000..4685a9b8ed018e6a40b9ba38580f555258a3dd9f
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/C43.v
@@ -0,0 +1,46 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module C43(
+ input CK,
+ input [3:0] D,
+ input nL, EN, CI, nCL,
+ output reg [3:0] Q = 4'd0,
+ output CO
+);
+
+ wire CL = ~nCL;
+
+ always @(posedge CK, posedge CL)
+ begin
+ if (CL)
+ begin
+ Q <= 4'd0; // Clear
+ end
+ else
+ begin
+ if (!nL)
+ Q <= D; // Load
+ else if (EN & CI)
+ Q <= Q + 1'b1; // Count
+ else
+ Q <= Q;
+ end
+ end
+
+ assign CO = &{Q[3:0], CI};
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/bd3.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/bd3.v
new file mode 100644
index 0000000000000000000000000000000000000000..568487d173935895bc01d04cfb43f2309f5ec795
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/bd3.v
@@ -0,0 +1,24 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module BD3(
+ input INPT,
+ output OUTPT
+);
+
+ assign #5 OUTPT = INPT;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fdm.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fdm.v
new file mode 100644
index 0000000000000000000000000000000000000000..a2a5ac0085934ddb433874c9191b38ed76d53e6b
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fdm.v
@@ -0,0 +1,29 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module FDM(
+ input CK,
+ input D,
+ output reg Q,
+ output nQ
+);
+
+ always @(posedge CK)
+ Q <= #2 D;
+
+ assign nQ = ~Q;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds.v
new file mode 100644
index 0000000000000000000000000000000000000000..42b0a42ecd110a614bce160a8890b094ad06711a
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds.v
@@ -0,0 +1,26 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module FDSCell(
+ input CK,
+ input [3:0] D,
+ output reg [3:0] Q = 4'd0
+);
+
+ always @(posedge CK)
+ Q <= #1 D;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds16bit.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds16bit.v
new file mode 100644
index 0000000000000000000000000000000000000000..4fb9e4b98ba1e7cc4dbce6215c8aa185d2dbec51
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/fds16bit.v
@@ -0,0 +1,28 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module FDS16bit(
+ input CK,
+ input [15:0] D,
+ output [15:0] Q
+);
+
+ FDSCell CellA(CK, D[3:0], Q[3:0]);
+ FDSCell CellB(CK, D[7:4], Q[7:4]);
+ FDSCell CellC(CK, D[11:8], Q[11:8]);
+ FDSCell CellD(CK, D[15:12], Q[15:12]);
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/lt4.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/lt4.v
new file mode 100644
index 0000000000000000000000000000000000000000..5a5f8cf3c1c6f0f60a3f58e42e49f9e7f67cc0ad
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cells/lt4.v
@@ -0,0 +1,30 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// altera message_off 10240
+module LT4(
+ input nG,
+ input [3:0] D,
+ output reg [3:0] P = 4'd0,
+ output [3:0] N
+);
+
+ always @(*)
+ P = (!nG) ? D : P; // Latch
+
+ assign N = ~P;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sdc b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sdc
new file mode 100644
index 0000000000000000000000000000000000000000..b2089ca77d203af002f517b658a4f84b016928fb
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sdc
@@ -0,0 +1,9 @@
+set_multicycle_path -start -setup -from [get_keepers *fx68k:*|Ir[*]] -to [get_keepers *fx68k:*|microAddr[*]] 2
+set_multicycle_path -start -hold -from [get_keepers *fx68k:*|Ir[*]] -to [get_keepers *fx68k:*|microAddr[*]] 1
+set_multicycle_path -start -setup -from [get_keepers *fx68k:*|Ir[*]] -to [get_keepers *fx68k:*|nanoAddr[*]] 2
+set_multicycle_path -start -hold -from [get_keepers *fx68k:*|Ir[*]] -to [get_keepers *fx68k:*|nanoAddr[*]] 1
+
+set_multicycle_path -start -setup -from {*|nanoLatch[*]} -to {*|excUnit|alu|pswCcr[*]} 2
+set_multicycle_path -start -hold -from {*|nanoLatch[*]} -to {*|excUnit|alu|pswCcr[*]} 1
+set_multicycle_path -start -setup -from {*|excUnit|alu|oper[*]} -to {*|excUnit|alu|pswCcr[*]} 2
+set_multicycle_path -start -hold -from {*|excUnit|alu|oper[*]} -to {*|excUnit|alu|pswCcr[*]} 1
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sv b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sv
new file mode 100644
index 0000000000000000000000000000000000000000..c51347dfb28f89b80d005e7358d960a4cba4b3ab
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.sv
@@ -0,0 +1,2684 @@
+//
+// FX68K
+//
+// M68000 cycle accurate, fully synchronous
+// Copyright (c) 2018 by Jorge Cwik
+//
+// TODO:
+// - Everything except bus retry already implemented.
+
+// altera message_off 10030
+// altera message_off 10230
+
+`timescale 1 ns / 1 ns
+
+// Define this to run a self contained compilation test build
+// `define FX68K_TEST
+
+localparam CF = 0, VF = 1, ZF = 2, NF = 3, XF = 4, SF = 13;
+
+localparam UADDR_WIDTH = 10;
+localparam UROM_WIDTH = 17;
+localparam UROM_DEPTH = 1024;
+
+localparam NADDR_WIDTH = 9;
+localparam NANO_WIDTH = 68;
+localparam NANO_DEPTH = 336;
+
+localparam BSER1_NMA = 'h003;
+localparam RSTP0_NMA = 'h002;
+localparam HALT1_NMA = 'h001;
+localparam TRAC1_NMA = 'h1C0;
+localparam ITLX1_NMA = 'h1C4;
+
+localparam TVN_SPURIOUS = 12;
+localparam TVN_AUTOVEC = 13;
+localparam TVN_INTERRUPT = 15;
+
+localparam NANO_DOB_DBD = 2'b01;
+localparam NANO_DOB_ADB = 2'b10;
+localparam NANO_DOB_ALU = 2'b11;
+
+
+// Clocks, phases and resets
+typedef struct {
+ logic clk;
+ logic extReset; // External sync reset on emulated system
+ logic pwrUp; // Asserted together with reset on emulated system coldstart
+ logic enPhi1, enPhi2; // Clock enables. Next cycle is PHI1 or PHI2
+} s_clks;
+
+// IRD decoded signals
+typedef struct {
+ logic isPcRel;
+ logic isTas;
+ logic implicitSp;
+ logic toCcr;
+ logic rxIsDt, ryIsDt;
+ logic rxIsUsp, rxIsMovem, movemPreDecr;
+ logic isByte;
+ logic isMovep;
+ logic [2:0] rx, ry;
+ logic rxIsAreg, ryIsAreg;
+ logic [15:0] ftuConst;
+ logic [5:0] macroTvn;
+ logic inhibitCcr;
+} s_irdecod;
+
+// Nano code decoded signals
+typedef struct {
+ logic permStart;
+ logic waitBusFinish;
+ logic isWrite;
+ logic busByte;
+ logic isRmc;
+ logic noLowByte, noHighByte;
+
+ logic updTpend, clrTpend;
+ logic tvn2Ftu, const2Ftu;
+ logic ftu2Dbl, ftu2Abl;
+ logic abl2Pren, updPren;
+ logic inl2psw, ftu2Sr, sr2Ftu, ftu2Ccr, pswIToFtu;
+ logic ird2Ftu, ssw2Ftu;
+ logic initST;
+ logic Ir2Ird;
+
+ logic auClkEn, noSpAlign;
+ logic [2:0] auCntrl;
+ logic todbin, toIrc;
+ logic dbl2Atl, abl2Atl, atl2Abl, atl2Dbl;
+ logic abh2Ath, dbh2Ath;
+ logic ath2Dbh, ath2Abh;
+
+ logic db2Aob, ab2Aob, au2Aob;
+ logic aob2Ab, updSsw;
+ // logic adb2Dob, dbd2Dob, alu2Dob;
+ logic [1:0] dobCtrl;
+
+ logic abh2reg, abl2reg;
+ logic reg2abl, reg2abh;
+ logic dbh2reg, dbl2reg;
+ logic reg2dbl, reg2dbh;
+ logic ssp, pchdbh, pcldbl, pclabl, pchabh;
+
+ logic rxh2dbh, rxh2abh;
+ logic dbl2rxl, dbh2rxh;
+ logic rxl2db, rxl2ab;
+ logic abl2rxl, abh2rxh;
+ logic dbh2ryh, abh2ryh;
+ logic ryl2db, ryl2ab;
+ logic ryh2dbh, ryh2abh;
+ logic dbl2ryl, abl2ryl;
+ logic rz;
+ logic rxlDbl;
+
+ logic [2:0] aluColumn;
+ logic [1:0] aluDctrl;
+ logic aluActrl;
+ logic aluInit, aluFinish;
+ logic abd2Dcr, dcr2Dbd;
+ logic dbd2Alue, alue2Dbd;
+ logic dbd2Alub, abd2Alub;
+
+ logic alu2Dbd, alu2Abd;
+ logic au2Db, au2Ab, au2Pc;
+ logic dbin2Abd, dbin2Dbd;
+ logic extDbh, extAbh;
+ logic ablAbd, ablAbh;
+ logic dblDbd, dblDbh;
+ logic abdIsByte;
+} s_nanod;
+
+module fx68k(
+ input clk,
+
+ // These two signals don't need to be registered. They are not async reset.
+ input extReset, // External sync reset on emulated system
+ input pwrUp, // Asserted together with reset on emulated system coldstart
+ input enPhi1, enPhi2, // Clock enables. Next cycle is PHI1 or PHI2
+
+ output eRWn, output ASn, output LDSn, output UDSn,
+ output logic E, output VMAn,
+ output FC0, output FC1, output FC2,
+ output BGn,
+ output oRESETn, output oHALTEDn,
+ input DTACKn, input VPAn,
+ input BERRn,
+ input BRn, BGACKn,
+ input IPL0n, input IPL1n, input IPL2n,
+ input [15:0] iEdb, output [15:0] oEdb,
+ output [23:1] eab
+ );
+
+ // wire clock = Clks.clk;
+ s_clks Clks;
+
+ assign Clks.clk = clk;
+ assign Clks.extReset = extReset;
+ assign Clks.pwrUp = pwrUp;
+ assign Clks.enPhi1 = enPhi1;
+ assign Clks.enPhi2 = enPhi2;
+
+ wire wClk;
+
+ // Internal sub clocks T1-T4
+ enum int unsigned { T0 = 0, T1, T2, T3, T4} tState;
+ wire enT1 = Clks.enPhi1 & (tState == T4) & ~wClk;
+ wire enT2 = Clks.enPhi2 & (tState == T1);
+ wire enT3 = Clks.enPhi1 & (tState == T2);
+ wire enT4 = Clks.enPhi2 & ((tState == T0) | (tState == T3));
+
+ // T4 continues ticking during reset and group0 exception.
+ // We also need it to erase ucode output latched on T4.
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp)
+ tState <= T0;
+ else begin
+ case( tState)
+ T0: if( Clks.enPhi2) tState <= T4;
+ T1: if( Clks.enPhi2) tState <= T2;
+ T2: if( Clks.enPhi1) tState <= T3;
+ T3: if( Clks.enPhi2) tState <= T4;
+ T4: if( Clks.enPhi1) tState <= wClk ? T0 : T1;
+ endcase
+ end
+ end
+
+ // The following signals are synchronized with 3 couplers, phi1-phi2-phi1.
+ // Will be valid internally one cycle later if changed at the rasing edge of the clock.
+ //
+ // DTACK, BERR
+
+ // DTACK valid at S6 if changed at the rasing edge of S4 to avoid wait states.
+ // SNC (sncClkEn) is deasserted together (unless DTACK asserted too early).
+ //
+ // We synchronize some signals half clock earlier. We compensate later
+ reg rDtack, rBerr;
+ reg [2:0] rIpl, iIpl;
+ reg Vpai, BeI, BRi, BgackI, BeiDelay;
+ // reg rBR;
+ wire BeDebounced = ~( BeI | BeiDelay);
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp) begin
+ rBerr <= 1'b0;
+ BeI <= 1'b0;
+ end
+ else if( Clks.enPhi2) begin
+ rDtack <= DTACKn;
+ rBerr <= BERRn;
+ rIpl <= ~{ IPL2n, IPL1n, IPL0n};
+ iIpl <= rIpl;
+
+ // rBR <= BRn; // Needed for cycle accuracy but only if BR is changed on the wrong edge of the clock
+ end
+ else if( Clks.enPhi1) begin
+ Vpai <= VPAn;
+ BeI <= rBerr;
+ BeiDelay <= BeI;
+
+ BRi <= BRn;
+ BgackI <= BGACKn;
+ // BRi <= rBR;
+ end
+ end
+
+ // Instantiate micro and nano rom
+ logic [NANO_WIDTH-1:0] nanoLatch;
+ logic [NANO_WIDTH-1:0] nanoOutput;
+ logic [UROM_WIDTH-1:0] microLatch;
+ logic [UROM_WIDTH-1:0] microOutput;
+
+ logic [UADDR_WIDTH-1:0] microAddr, nma;
+ logic [NADDR_WIDTH-1:0] nanoAddr, orgAddr;
+ wire rstUrom;
+
+ // For the time being, address translation is done for nanorom only.
+ microToNanoAddr microToNanoAddr( .uAddr( nma), .orgAddr);
+
+ // Output of these modules will be updated at T2 at the latest (depending on clock division)
+
+ nanoRom nanoRom( .clk( Clks.clk), .nanoAddr, .nanoOutput);
+ uRom uRom( .clk( Clks.clk), .microAddr, .microOutput);
+
+ always_ff @( posedge Clks.clk) begin
+ // uaddr originally latched on T1, except bits 6 & 7, the conditional bits, on T2
+ // Seems we can latch whole address at either T1 or T2
+
+ // Originally it's invalid on hardware reset, and forced later when coming out of reset
+ if( Clks.pwrUp) begin
+ microAddr <= RSTP0_NMA;
+ nanoAddr <= RSTP0_NMA;
+ end
+ else if( enT1) begin
+ microAddr <= nma;
+ nanoAddr <= orgAddr; // Register translated uaddr to naddr
+ end
+
+ if( Clks.extReset) begin
+ microLatch <= '0;
+ nanoLatch <= '0;
+ end
+ else if( rstUrom) begin
+ // Originally reset these bits only. Not strictly needed like this.
+ // Can reset the whole register if it is important.
+ { microLatch[16], microLatch[15], microLatch[0]} <= '0;
+ nanoLatch <= '0;
+ end
+ else if( enT3) begin
+ microLatch <= microOutput;
+ nanoLatch <= nanoOutput;
+ end
+
+ end
+
+
+ // Decoded nanocode signals
+ s_nanod Nanod;
+ // IRD decoded control signals
+ s_irdecod Irdecod;
+
+ //
+ reg Tpend;
+ reg intPend; // Interrupt pending
+ reg pswT, pswS;
+ reg [ 2:0] pswI;
+ wire [7:0] ccr;
+
+ wire [15:0] psw = { pswT, 1'b0, pswS, 2'b00, pswI, ccr};
+
+ reg [15:0] ftu;
+ reg [15:0] Irc, Ir, Ird;
+
+ wire [15:0] alue;
+ wire [15:0] Abl;
+ wire prenEmpty, au05z, dcr4, ze;
+
+ wire [UADDR_WIDTH-1:0] a1, a2, a3;
+ wire isPriv, isIllegal, isLineA, isLineF;
+
+
+ // IR & IRD forwarding
+ always_ff @( posedge Clks.clk) begin
+ if( enT1) begin
+ if( Nanod.Ir2Ird)
+ Ird <= Ir;
+ else if(microLatch[0]) // prevented by IR => IRD !
+ Ir <= Irc;
+ end
+ end
+
+ wire [3:0] tvn;
+ wire waitBusCycle, busStarting;
+ wire BusRetry = 1'b0;
+ wire busAddrErr;
+ wire bciWrite; // Last bus cycle was write
+ wire bgBlock, busAvail;
+ wire addrOe;
+
+ wire busIsByte = Nanod.busByte & (Irdecod.isByte | Irdecod.isMovep);
+ wire aob0;
+
+ reg iStop; // Internal signal for ending bus cycle
+ reg A0Err; // Force bus/address error ucode
+ reg excRst; // Signal reset exception to sequencer
+ reg BerrA;
+ reg Spuria, Avia;
+ wire Iac;
+
+ reg rAddrErr, iBusErr, Err6591;
+ wire iAddrErr = rAddrErr & addrOe; // To simulate async reset
+ wire enErrClk;
+
+ // Reset micro/nano latch after T4 of the current ublock.
+ assign rstUrom = Clks.enPhi1 & enErrClk;
+
+ uaddrDecode uaddrDecode( .opcode( Ir), .a1, .a2, .a3, .isPriv, .isIllegal, .isLineA, .isLineF, .lineBmap());
+
+ sequencer sequencer( .Clks, .enT3, .microLatch, .Ird,
+ .A0Err, .excRst, .BerrA, .busAddrErr, .Spuria, .Avia,
+ .Tpend, .intPend, .isIllegal, .isPriv, .isLineA, .isLineF,
+ .nma, .a1, .a2, .a3, .tvn,
+ .psw, .prenEmpty, .au05z, .dcr4, .ze, .alue01( alue[1:0]), .i11( Irc[ 11]) );
+
+ excUnit excUnit( .Clks, .Nanod, .Irdecod, .enT1, .enT2, .enT3, .enT4,
+ .Ird, .ftu, .iEdb, .pswS,
+ .prenEmpty, .au05z, .dcr4, .ze, .AblOut( Abl), .eab, .aob0, .Irc, .oEdb,
+ .alue, .ccr);
+
+ nDecoder3 nDecoder( .Clks, .Nanod, .Irdecod, .enT2, .enT4, .microLatch, .nanoLatch);
+
+ irdDecode irdDecode( .ird( Ird), .Irdecod);
+
+ busControl busControl( .Clks, .enT1, .enT4, .permStart( Nanod.permStart), .permStop( Nanod.waitBusFinish), .iStop,
+ .aob0, .isWrite( Nanod.isWrite), .isRmc( Nanod.isRmc), .isByte( busIsByte), .busAvail,
+ .bciWrite, .addrOe, .bgBlock, .waitBusCycle, .busStarting, .busAddrErr,
+ .rDtack, .BeDebounced, .Vpai,
+ .ASn, .LDSn, .UDSn, .eRWn);
+
+ busArbiter busArbiter( .Clks, .BRi, .BgackI, .Halti( 1'b1), .bgBlock, .busAvail, .BGn);
+
+
+ // Output reset & halt control
+ wire [1:0] uFc = microLatch[ 16:15];
+ logic oReset, oHalted;
+ assign oRESETn = !oReset;
+ assign oHALTEDn = !oHalted;
+
+ // FC without permStart is special, either reset or halt
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp) begin
+ oReset <= 1'b0;
+ oHalted <= 1'b0;
+ end
+ else if( enT1) begin
+ oReset <= (uFc == 2'b01) & !Nanod.permStart;
+ oHalted <= (uFc == 2'b10) & !Nanod.permStart;
+ end
+ end
+
+ logic [2:0] rFC;
+ assign { FC2, FC1, FC0} = rFC; // ~rFC;
+ assign Iac = {rFC == 3'b111}; // & Control output enable !!
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset)
+ rFC <= '0;
+ else if( enT1 & Nanod.permStart) begin // S0 phase of bus cycle
+ rFC[2] <= pswS;
+ // If FC is type 'n' (0) at ucode, access type depends on PC relative mode
+ // We don't care about RZ in this case. Those uinstructions with RZ don't start a bus cycle.
+ rFC[1] <= microLatch[ 16] | ( ~microLatch[ 15] & Irdecod.isPcRel);
+ rFC[0] <= microLatch[ 15] | ( ~microLatch[ 16] & ~Irdecod.isPcRel);
+ end
+ end
+
+
+ // IPL interface
+ reg [2:0] inl; // Int level latch
+ reg updIll;
+ reg prevNmi;
+
+ wire nmi = (iIpl == 3'b111);
+ wire iplStable = (iIpl == rIpl);
+ wire iplComp = iIpl > pswI;
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset) begin
+ intPend <= 1'b0;
+ prevNmi <= 1'b0;
+ end
+ else begin
+ if( Clks.enPhi2)
+ prevNmi <= nmi;
+
+ // Originally async RS-Latch on PHI2, followed by a transparent latch on T2
+ // Tricky because they might change simultaneously
+ // Syncronous on PHI2 is equivalent as long as the output is read on T3!
+
+ // Set on stable & NMI edge or compare
+ // Clear on: NMI Iack or (stable & !NMI & !Compare)
+
+ if( Clks.enPhi2) begin
+ if( iplStable & ((nmi & ~prevNmi) | iplComp) )
+ intPend <= 1'b1;
+ else if( ((inl == 3'b111) & Iac) | (iplStable & !nmi & !iplComp) )
+ intPend <= 1'b0;
+ end
+ end
+
+ if( Clks.extReset) begin
+ inl <= '1;
+ updIll <= 1'b0;
+ end
+ else if( enT4)
+ updIll <= microLatch[0]; // Update on any IRC->IR
+ else if( enT1 & updIll)
+ inl <= iIpl; // Timing is correct.
+
+ // Spurious interrupt, BERR on Interrupt Ack.
+ // Autovector interrupt. VPA on IACK.
+ // Timing is tight. Spuria is deasserted just after exception exception is recorded.
+ if( enT4) begin
+ Spuria <= ~BeiDelay & Iac;
+ Avia <= ~Vpai & Iac;
+ end
+
+ end
+
+ assign enErrClk = iAddrErr | iBusErr;
+ assign wClk = waitBusCycle | ~BeI | iAddrErr | Err6591;
+
+ // E clock and counter, VMA
+ reg [3:0] eCntr;
+ reg rVma;
+
+ assign VMAn = rVma;
+
+ // Internal stop just one cycle before E falling edge
+ wire xVma = ~rVma & (eCntr == 8);
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp) begin
+ E <= 1'b0;
+ eCntr <='0;
+ rVma <= 1'b1;
+ end
+ if( Clks.enPhi2) begin
+ if( eCntr == 9)
+ E <= 1'b0;
+ else if( eCntr == 5)
+ E <= 1'b1;
+
+ if( eCntr == 9)
+ eCntr <= '0;
+ else
+ eCntr <= eCntr + 1'b1;
+ end
+
+ if( Clks.enPhi2 & addrOe & ~Vpai & (eCntr == 3))
+ rVma <= 1'b0;
+ else if( Clks.enPhi1 & eCntr == '0)
+ rVma <= 1'b1;
+ end
+
+ always_ff @( posedge Clks.clk) begin
+
+ // This timing is critical to stop the clock phases at the exact point on bus/addr error.
+ // Timing should be such that current ublock completes (up to T3 or T4).
+ // But T1 for the next ublock shouldn't happen. Next T1 only after resetting ucode and ncode latches.
+
+ if( Clks.extReset)
+ rAddrErr <= 1'b0;
+ else if( Clks.enPhi1) begin
+ if( busAddrErr & addrOe) // Not on T1 ?!
+ rAddrErr <= 1'b1;
+ else if( ~addrOe) // Actually async reset!
+ rAddrErr <= 1'b0;
+ end
+
+ if( Clks.extReset)
+ iBusErr <= 1'b0;
+ else if( Clks.enPhi1) begin
+ iBusErr <= ( BerrA & ~BeI & ~Iac & !BusRetry);
+ end
+
+ if( Clks.extReset)
+ BerrA <= 1'b0;
+ else if( Clks.enPhi2) begin
+ if( ~BeI & ~Iac & addrOe)
+ BerrA <= 1'b1;
+ // else if( BeI & addrOe) // Bad, async reset since addrOe raising edge
+ else if( BeI & busStarting) // So replaced with this that raises one cycle earlier
+ BerrA <= 1'b0;
+ end
+
+ // Signal reset exception to sequencer.
+ // Originally cleared on 1st T2 after permstart. Must keep it until TVN latched.
+ if( Clks.extReset)
+ excRst <= 1'b1;
+ else if( enT2 & Nanod.permStart)
+ excRst <= 1'b0;
+
+ if( Clks.extReset)
+ A0Err <= 1'b1; // A0 Reset
+ else if( enT3) // Keep set until new urom words are being latched
+ A0Err <= 1'b0;
+ else if( Clks.enPhi1 & enErrClk & (busAddrErr | BerrA)) // Check bus error timing
+ A0Err <= 1'b1;
+
+ if( Clks.extReset) begin
+ iStop <= 1'b0;
+ Err6591 <= 1'b0;
+ end
+ else if( Clks.enPhi1)
+ Err6591 <= enErrClk;
+ else if( Clks.enPhi2)
+ iStop <= xVma | (Vpai & (iAddrErr | ~rBerr));
+ end
+
+ // PSW
+ logic irdToCcr_t4;
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp) begin
+ Tpend <= 1'b0;
+ {pswT, pswS, pswI } <= '0;
+ irdToCcr_t4 <= '0;
+ end
+
+ else if( enT4) begin
+ irdToCcr_t4 <= Irdecod.toCcr;
+ end
+
+ else if( enT3) begin
+
+ // UNIQUE IF !!
+ if( Nanod.updTpend)
+ Tpend <= pswT;
+ else if( Nanod.clrTpend)
+ Tpend <= 1'b0;
+
+ // UNIQUE IF !!
+ if( Nanod.ftu2Sr & !irdToCcr_t4)
+ {pswT, pswS, pswI } <= { ftu[ 15], ftu[13], ftu[10:8]};
+ else begin
+ if( Nanod.initST) begin
+ pswS <= 1'b1;
+ pswT <= 1'b0;
+ end
+ if( Nanod.inl2psw)
+ pswI <= inl;
+ end
+
+ end
+ end
+
+ // FTU
+ reg [4:0] ssw;
+ reg [3:0] tvnLatch;
+ logic [15:0] tvnMux;
+ reg inExcept01;
+
+ // Seems CPU has a buglet here.
+ // Flagging group 0 exceptions from TVN might not work because some bus cycles happen before TVN is updated.
+ // But doesn't matter because a group 0 exception inside another one will halt the CPU anyway and won't save the SSW.
+
+ always_ff @( posedge Clks.clk) begin
+
+ // Updated at the start of the exception ucode
+ if( Nanod.updSsw & enT3) begin
+ ssw <= { ~bciWrite, inExcept01, rFC};
+ end
+
+ // Update TVN on T1 & IR=>IRD
+ if( enT1 & Nanod.Ir2Ird) begin
+ tvnLatch <= tvn;
+ inExcept01 <= (tvn != 1);
+ end
+
+ if( Clks.pwrUp)
+ ftu <= '0;
+ else if( enT3) begin
+ unique case( 1'b1)
+ Nanod.tvn2Ftu: ftu <= tvnMux;
+
+ // 0 on unused bits seem to come from ftuConst PLA previously clearing FBUS
+ Nanod.sr2Ftu: ftu <= {pswT, 1'b0, pswS, 2'b00, pswI, 3'b000, ccr[4:0] };
+
+ Nanod.ird2Ftu: ftu <= Ird;
+ Nanod.ssw2Ftu: ftu[4:0] <= ssw; // Undoc. Other bits must be preserved from IRD saved above!
+ Nanod.pswIToFtu: ftu <= { 12'hFFF, pswI, 1'b0}; // Interrupt level shifted
+ Nanod.const2Ftu: ftu <= Irdecod.ftuConst;
+ Nanod.abl2Pren: ftu <= Abl; // From ALU or datareg. Used for SR modify
+ default: ftu <= ftu;
+ endcase
+ end
+ end
+
+ always_comb begin
+ if( inExcept01) begin
+ // Unique IF !!!
+ if( tvnLatch == TVN_SPURIOUS)
+ tvnMux = {9'b0, 5'd24, 2'b00};
+ else if( tvnLatch == TVN_AUTOVEC)
+ tvnMux = {9'b0, 2'b11, pswI, 2'b00}; // Set TVN PLA decoder
+ else if( tvnLatch == TVN_INTERRUPT)
+ tvnMux = {6'b0, Ird[7:0], 2'b00}; // Interrupt vector was read and transferred to IRD
+ else
+ tvnMux = {10'b0, tvnLatch, 2'b00};
+ end
+ else
+ tvnMux = { 8'h0, Irdecod.macroTvn, 2'b00};
+ end
+
+endmodule
+
+// Nanorom (plus) decoder for die nanocode
+module nDecoder3( input s_clks Clks, input s_irdecod Irdecod, output s_nanod Nanod,
+ input enT2, enT4,
+ input [UROM_WIDTH-1:0] microLatch,
+ input [NANO_WIDTH-1:0] nanoLatch);
+
+localparam NANO_IR2IRD = 67;
+localparam NANO_TOIRC = 66;
+localparam NANO_ALU_COL = 63; // ALU operator column order is 63-64-65 !
+localparam NANO_ALU_FI = 61; // ALU finish-init 62-61
+localparam NANO_TODBIN = 60;
+localparam NANO_ALUE = 57; // 57-59 shared with DCR control
+localparam NANO_DCR = 57; // 57-59 shared with ALUE control
+localparam NANO_DOBCTRL_1 = 56; // Input to control and permwrite
+localparam NANO_LOWBYTE = 55; // Used by MOVEP
+localparam NANO_HIGHBYTE = 54;
+localparam NANO_DOBCTRL_0 = 53; // Input to control and permwrite
+localparam NANO_ALU_DCTRL = 51; // 52-51 databus input mux control
+localparam NANO_ALU_ACTRL = 50; // addrbus input mux control
+localparam NANO_DBD2ALUB = 49;
+localparam NANO_ABD2ALUB = 48;
+localparam NANO_DBIN2DBD = 47;
+localparam NANO_DBIN2ABD = 46;
+localparam NANO_ALU2ABD = 45;
+localparam NANO_ALU2DBD = 44;
+localparam NANO_RZ = 43;
+localparam NANO_BUSBYTE = 42; // If *both* this set and instruction is byte sized, then bus cycle is byte sized.
+localparam NANO_PCLABL = 41;
+localparam NANO_RXL_DBL = 40; // Switches RXL/RYL on DBL/ABL buses
+localparam NANO_PCLDBL = 39;
+localparam NANO_ABDHRECHARGE = 38;
+localparam NANO_REG2ABL = 37; // register to ABL
+localparam NANO_ABL2REG = 36; // ABL to register
+localparam NANO_ABLABD = 35;
+localparam NANO_DBLDBD = 34;
+localparam NANO_DBL2REG = 33; // DBL to register
+localparam NANO_REG2DBL = 32; // register to DBL
+localparam NANO_ATLCTRL = 29; // 31-29
+localparam NANO_FTUCONTROL = 25;
+localparam NANO_SSP = 24;
+localparam NANO_RXH_DBH = 22; // Switches RXH/RYH on DBH/ABH buses
+localparam NANO_AUOUT = 20; // 21-20
+localparam NANO_AUCLKEN = 19;
+localparam NANO_AUCTRL = 16; // 18-16
+localparam NANO_DBLDBH = 15;
+localparam NANO_ABLABH = 14;
+localparam NANO_EXT_ABH = 13;
+localparam NANO_EXT_DBH = 12;
+localparam NANO_ATHCTRL = 9; // 11-9
+localparam NANO_REG2ABH = 8; // register to ABH
+localparam NANO_ABH2REG = 7; // ABH to register
+localparam NANO_REG2DBH = 6; // register to DBH
+localparam NANO_DBH2REG = 5; // DBH to register
+localparam NANO_AOBCTRL = 3; // 4-3
+localparam NANO_PCH = 0; // 1-0 PchDbh PchAbh
+localparam NANO_NO_SP_ALGN = 0; // Same bits as above when both set
+
+localparam NANO_FTU_UPDTPEND = 1; // Also loads FTU constant according to IRD !
+localparam NANO_FTU_INIT_ST = 15; // Set S, clear T (but not TPEND)
+localparam NANO_FTU_CLRTPEND = 14;
+localparam NANO_FTU_TVN = 13;
+localparam NANO_FTU_ABL2PREN = 12; // ABL => FTU & ABL => PREN. Both transfers enabled, but only one will be used depending on uroutine.
+localparam NANO_FTU_SSW = 11;
+localparam NANO_FTU_RSTPREN = 10;
+localparam NANO_FTU_IRD = 9;
+localparam NANO_FTU_2ABL = 8;
+localparam NANO_FTU_RDSR = 7;
+localparam NANO_FTU_INL = 6;
+localparam NANO_FTU_PSWI = 5; // Read Int Mask into FTU
+localparam NANO_FTU_DBL = 4;
+localparam NANO_FTU_2SR = 2;
+localparam NANO_FTU_CONST = 1;
+
+ reg [3:0] ftuCtrl;
+
+ logic [2:0] athCtrl, atlCtrl;
+ assign athCtrl = nanoLatch[ NANO_ATHCTRL+2: NANO_ATHCTRL];
+ assign atlCtrl = nanoLatch[ NANO_ATLCTRL+2: NANO_ATLCTRL];
+ wire [1:0] aobCtrl = nanoLatch[ NANO_AOBCTRL+1:NANO_AOBCTRL];
+ wire [1:0] dobCtrl = {nanoLatch[ NANO_DOBCTRL_1], nanoLatch[NANO_DOBCTRL_0]};
+
+ always_ff @( posedge Clks.clk) begin
+ if( enT4) begin
+ // Reverse order!
+ ftuCtrl <= { nanoLatch[ NANO_FTUCONTROL+0], nanoLatch[ NANO_FTUCONTROL+1], nanoLatch[ NANO_FTUCONTROL+2], nanoLatch[ NANO_FTUCONTROL+3]} ;
+
+ Nanod.auClkEn <= !nanoLatch[ NANO_AUCLKEN];
+ Nanod.auCntrl <= nanoLatch[ NANO_AUCTRL+2 : NANO_AUCTRL+0];
+ Nanod.noSpAlign <= (nanoLatch[ NANO_NO_SP_ALGN + 1:NANO_NO_SP_ALGN] == 2'b11);
+ Nanod.extDbh <= nanoLatch[ NANO_EXT_DBH];
+ Nanod.extAbh <= nanoLatch[ NANO_EXT_ABH];
+ Nanod.todbin <= nanoLatch[ NANO_TODBIN];
+ Nanod.toIrc <= nanoLatch[ NANO_TOIRC];
+
+ // ablAbd is disabled on byte transfers (adbhCharge plus irdIsByte). Not sure the combination makes much sense.
+ // It happens in a few cases but I don't see anything enabled on abL (or abH) section anyway.
+
+ Nanod.ablAbd <= nanoLatch[ NANO_ABLABD];
+ Nanod.ablAbh <= nanoLatch[ NANO_ABLABH];
+ Nanod.dblDbd <= nanoLatch[ NANO_DBLDBD];
+ Nanod.dblDbh <= nanoLatch[ NANO_DBLDBH];
+
+ Nanod.dbl2Atl <= (atlCtrl == 3'b010);
+ Nanod.atl2Dbl <= (atlCtrl == 3'b011);
+ Nanod.abl2Atl <= (atlCtrl == 3'b100);
+ Nanod.atl2Abl <= (atlCtrl == 3'b101);
+
+ Nanod.aob2Ab <= (athCtrl == 3'b101); // Used on BSER1 only
+
+ Nanod.abh2Ath <= (athCtrl == 3'b001) | (athCtrl == 3'b101);
+ Nanod.dbh2Ath <= (athCtrl == 3'b100);
+ Nanod.ath2Dbh <= (athCtrl == 3'b110);
+ Nanod.ath2Abh <= (athCtrl == 3'b011);
+
+ Nanod.alu2Dbd <= nanoLatch[ NANO_ALU2DBD];
+ Nanod.alu2Abd <= nanoLatch[ NANO_ALU2ABD];
+
+ Nanod.abd2Dcr <= (nanoLatch[ NANO_DCR+1:NANO_DCR] == 2'b11);
+ Nanod.dcr2Dbd <= (nanoLatch[ NANO_DCR+2:NANO_DCR+1] == 2'b11);
+ Nanod.dbd2Alue <= (nanoLatch[ NANO_ALUE+2:NANO_ALUE+1] == 2'b10);
+ Nanod.alue2Dbd <= (nanoLatch[ NANO_ALUE+1:NANO_ALUE] == 2'b01);
+
+ Nanod.dbd2Alub <= nanoLatch[ NANO_DBD2ALUB];
+ Nanod.abd2Alub <= nanoLatch[ NANO_ABD2ALUB];
+
+ // Originally not latched. We better should because we transfer one cycle later, T3 instead of T1.
+ Nanod.dobCtrl <= dobCtrl;
+ // Nanod.adb2Dob <= (dobCtrl == 2'b10); Nanod.dbd2Dob <= (dobCtrl == 2'b01); Nanod.alu2Dob <= (dobCtrl == 2'b11);
+
+ end
+ end
+
+ // Update SSW at the start of Bus/Addr error ucode
+ assign Nanod.updSsw = Nanod.aob2Ab;
+
+ assign Nanod.updTpend = (ftuCtrl == NANO_FTU_UPDTPEND);
+ assign Nanod.clrTpend = (ftuCtrl == NANO_FTU_CLRTPEND);
+ assign Nanod.tvn2Ftu = (ftuCtrl == NANO_FTU_TVN);
+ assign Nanod.const2Ftu = (ftuCtrl == NANO_FTU_CONST);
+ assign Nanod.ftu2Dbl = (ftuCtrl == NANO_FTU_DBL) | ( ftuCtrl == NANO_FTU_INL);
+ assign Nanod.ftu2Abl = (ftuCtrl == NANO_FTU_2ABL);
+ assign Nanod.inl2psw = (ftuCtrl == NANO_FTU_INL);
+ assign Nanod.pswIToFtu = (ftuCtrl == NANO_FTU_PSWI);
+ assign Nanod.ftu2Sr = (ftuCtrl == NANO_FTU_2SR);
+ assign Nanod.sr2Ftu = (ftuCtrl == NANO_FTU_RDSR);
+ assign Nanod.ird2Ftu = (ftuCtrl == NANO_FTU_IRD); // Used on bus/addr error
+ assign Nanod.ssw2Ftu = (ftuCtrl == NANO_FTU_SSW);
+ assign Nanod.initST = (ftuCtrl == NANO_FTU_INL) | (ftuCtrl == NANO_FTU_CLRTPEND) | (ftuCtrl == NANO_FTU_INIT_ST);
+ assign Nanod.abl2Pren = (ftuCtrl == NANO_FTU_ABL2PREN);
+ assign Nanod.updPren = (ftuCtrl == NANO_FTU_RSTPREN);
+
+ assign Nanod.Ir2Ird = nanoLatch[ NANO_IR2IRD];
+
+ // ALU control better latched later after combining with IRD decoding
+
+ assign Nanod.aluDctrl = nanoLatch[ NANO_ALU_DCTRL+1 : NANO_ALU_DCTRL];
+ assign Nanod.aluActrl = nanoLatch[ NANO_ALU_ACTRL];
+ assign Nanod.aluColumn = { nanoLatch[ NANO_ALU_COL], nanoLatch[ NANO_ALU_COL+1], nanoLatch[ NANO_ALU_COL+2]};
+ wire [1:0] aluFinInit = nanoLatch[ NANO_ALU_FI+1:NANO_ALU_FI];
+ assign Nanod.aluFinish = (aluFinInit == 2'b10);
+ assign Nanod.aluInit = (aluFinInit == 2'b01);
+
+ // FTU 2 CCR encoded as both ALU Init and ALU Finish set.
+ // In theory this encoding allows writes to CCR without writing to SR
+ // But FTU 2 CCR and to SR are both set together at nanorom.
+ assign Nanod.ftu2Ccr = ( aluFinInit == 2'b11);
+
+ assign Nanod.abdIsByte = nanoLatch[ NANO_ABDHRECHARGE];
+
+ // Not being latched on T4 creates non unique case warning!
+ assign Nanod.au2Db = (nanoLatch[ NANO_AUOUT + 1: NANO_AUOUT] == 2'b01);
+ assign Nanod.au2Ab = (nanoLatch[ NANO_AUOUT + 1: NANO_AUOUT] == 2'b10);
+ assign Nanod.au2Pc = (nanoLatch[ NANO_AUOUT + 1: NANO_AUOUT] == 2'b11);
+
+ assign Nanod.db2Aob = (aobCtrl == 2'b10);
+ assign Nanod.ab2Aob = (aobCtrl == 2'b01);
+ assign Nanod.au2Aob = (aobCtrl == 2'b11);
+
+ assign Nanod.dbin2Abd = nanoLatch[ NANO_DBIN2ABD];
+ assign Nanod.dbin2Dbd = nanoLatch[ NANO_DBIN2DBD];
+
+ assign Nanod.permStart = (| aobCtrl);
+ assign Nanod.isWrite = ( | dobCtrl);
+ assign Nanod.waitBusFinish = nanoLatch[ NANO_TOIRC] | nanoLatch[ NANO_TODBIN] | Nanod.isWrite;
+ assign Nanod.busByte = nanoLatch[ NANO_BUSBYTE];
+
+ assign Nanod.noLowByte = nanoLatch[ NANO_LOWBYTE];
+ assign Nanod.noHighByte = nanoLatch[ NANO_HIGHBYTE];
+
+ // Not registered. Register at T4 after combining
+ // Might be better to remove all those and combine here instead of at execution unit !!
+ assign Nanod.abl2reg = nanoLatch[ NANO_ABL2REG];
+ assign Nanod.abh2reg = nanoLatch[ NANO_ABH2REG];
+ assign Nanod.dbl2reg = nanoLatch[ NANO_DBL2REG];
+ assign Nanod.dbh2reg = nanoLatch[ NANO_DBH2REG];
+ assign Nanod.reg2dbl = nanoLatch[ NANO_REG2DBL];
+ assign Nanod.reg2dbh = nanoLatch[ NANO_REG2DBH];
+ assign Nanod.reg2abl = nanoLatch[ NANO_REG2ABL];
+ assign Nanod.reg2abh = nanoLatch[ NANO_REG2ABH];
+
+ assign Nanod.ssp = nanoLatch[ NANO_SSP];
+
+ assign Nanod.rz = nanoLatch[ NANO_RZ];
+
+ // Actually DTL can't happen on PC relative mode. See IR decoder.
+
+ wire dtldbd = 1'b0;
+ wire dthdbh = 1'b0;
+ wire dtlabd = 1'b0;
+ wire dthabh = 1'b0;
+
+ wire dblSpecial = Nanod.pcldbl | dtldbd;
+ wire dbhSpecial = Nanod.pchdbh | dthdbh;
+ wire ablSpecial = Nanod.pclabl | dtlabd;
+ wire abhSpecial = Nanod.pchabh | dthabh;
+
+ //
+ // Combine with IRD decoding
+ // Careful that IRD is updated only on T1! All output depending on IRD must be latched on T4!
+ //
+
+ // PC used instead of RY on PC relative instuctions
+
+ assign Nanod.rxlDbl = nanoLatch[ NANO_RXL_DBL];
+ wire isPcRel = Irdecod.isPcRel & !Nanod.rz;
+ wire pcRelDbl = isPcRel & !nanoLatch[ NANO_RXL_DBL];
+ wire pcRelDbh = isPcRel & !nanoLatch[ NANO_RXH_DBH];
+ wire pcRelAbl = isPcRel & nanoLatch[ NANO_RXL_DBL];
+ wire pcRelAbh = isPcRel & nanoLatch[ NANO_RXH_DBH];
+
+ assign Nanod.pcldbl = nanoLatch[ NANO_PCLDBL] | pcRelDbl;
+ assign Nanod.pchdbh = (nanoLatch[ NANO_PCH+1:NANO_PCH] == 2'b01) | pcRelDbh;
+
+ assign Nanod.pclabl = nanoLatch[ NANO_PCLABL] | pcRelAbl;
+ assign Nanod.pchabh = (nanoLatch[ NANO_PCH+1:NANO_PCH] == 2'b10) | pcRelAbh;
+
+ // Might be better not to register these signals to allow latching RX/RY mux earlier!
+ // But then must latch Irdecod.isPcRel on T3!
+
+ always_ff @( posedge Clks.clk) begin
+ if( enT4) begin
+ Nanod.rxl2db <= Nanod.reg2dbl & !dblSpecial & nanoLatch[ NANO_RXL_DBL];
+ Nanod.rxl2ab <= Nanod.reg2abl & !ablSpecial & !nanoLatch[ NANO_RXL_DBL];
+
+ Nanod.dbl2rxl <= Nanod.dbl2reg & !dblSpecial & nanoLatch[ NANO_RXL_DBL];
+ Nanod.abl2rxl <= Nanod.abl2reg & !ablSpecial & !nanoLatch[ NANO_RXL_DBL];
+
+ Nanod.rxh2dbh <= Nanod.reg2dbh & !dbhSpecial & nanoLatch[ NANO_RXH_DBH];
+ Nanod.rxh2abh <= Nanod.reg2abh & !abhSpecial & !nanoLatch[ NANO_RXH_DBH];
+
+ Nanod.dbh2rxh <= Nanod.dbh2reg & !dbhSpecial & nanoLatch[ NANO_RXH_DBH];
+ Nanod.abh2rxh <= Nanod.abh2reg & !abhSpecial & !nanoLatch[ NANO_RXH_DBH];
+
+ Nanod.dbh2ryh <= Nanod.dbh2reg & !dbhSpecial & !nanoLatch[ NANO_RXH_DBH];
+ Nanod.abh2ryh <= Nanod.abh2reg & !abhSpecial & nanoLatch[ NANO_RXH_DBH];
+
+ Nanod.dbl2ryl <= Nanod.dbl2reg & !dblSpecial & !nanoLatch[ NANO_RXL_DBL];
+ Nanod.abl2ryl <= Nanod.abl2reg & !ablSpecial & nanoLatch[ NANO_RXL_DBL];
+
+ Nanod.ryl2db <= Nanod.reg2dbl & !dblSpecial & !nanoLatch[ NANO_RXL_DBL];
+ Nanod.ryl2ab <= Nanod.reg2abl & !ablSpecial & nanoLatch[ NANO_RXL_DBL];
+
+ Nanod.ryh2dbh <= Nanod.reg2dbh & !dbhSpecial & !nanoLatch[ NANO_RXH_DBH];
+ Nanod.ryh2abh <= Nanod.reg2abh & !abhSpecial & nanoLatch[ NANO_RXH_DBH];
+ end
+
+ // Originally isTas only delayed on T2 (and seems only a late mask rev fix)
+ // Better latch the combination on T4
+ if( enT4)
+ Nanod.isRmc <= Irdecod.isTas & nanoLatch[ NANO_BUSBYTE];
+ end
+
+
+endmodule
+
+//
+// IRD execution decoder. Complements nano code decoder
+//
+// IRD updated on T1, while ncode still executing. To avoid using the next IRD,
+// decoded signals must be registered on T3, or T4 before using them.
+//
+module irdDecode( input [15:0] ird,
+ output s_irdecod Irdecod);
+
+ wire [3:0] line = ird[15:12];
+ logic [15:0] lineOnehot;
+
+ // This can be registered and pipelined from the IR decoder !
+ onehotEncoder4 irdLines( line, lineOnehot);
+
+ wire isRegShift = (lineOnehot['he]) & (ird[7:6] != 2'b11);
+ wire isDynShift = isRegShift & ird[5];
+
+ assign Irdecod.isPcRel = (& ird[ 5:3]) & ~isDynShift & !ird[2] & ird[1];
+ assign Irdecod.isTas = lineOnehot[4] & (ird[11:6] == 6'b101011);
+
+ assign Irdecod.rx = ird[11:9];
+ assign Irdecod.ry = ird[ 2:0];
+
+ wire isPreDecr = (ird[ 5:3] == 3'b100);
+ wire eaAreg = (ird[5:3] == 3'b001);
+
+ // rx is A or D
+ // movem
+ always_comb begin
+ unique case( 1'b1)
+ lineOnehot[1],
+ lineOnehot[2],
+ lineOnehot[3]:
+ // MOVE: RX always Areg except if dest mode is Dn 000
+ Irdecod.rxIsAreg = (| ird[8:6]);
+
+ lineOnehot[4]: Irdecod.rxIsAreg = (& ird[8:6]); // not CHK (LEA)
+
+ lineOnehot['h8]: Irdecod.rxIsAreg = eaAreg & ird[8] & ~ird[7]; // SBCD
+ lineOnehot['hc]: Irdecod.rxIsAreg = eaAreg & ird[8] & ~ird[7]; // ABCD/EXG An,An
+
+ lineOnehot['h9],
+ lineOnehot['hb],
+ lineOnehot['hd]: Irdecod.rxIsAreg =
+ (ird[7] & ird[6]) | // SUBA/CMPA/ADDA
+ (eaAreg & ird[8] & (ird[7:6] != 2'b11)); // SUBX/CMPM/ADDX
+ default:
+ Irdecod.rxIsAreg = Irdecod.implicitSp;
+ endcase
+ end
+
+ // RX is movem
+ always_comb begin
+ Irdecod.rxIsMovem = lineOnehot[4] & ~ird[8] & ~Irdecod.implicitSp;
+ end
+ assign Irdecod.movemPreDecr = Irdecod.rxIsMovem & isPreDecr;
+
+ // RX is DT.
+ // but SSP explicit or pc explicit has higher priority!
+ // addq/subq (scc & dbcc also, but don't use rx)
+ // Immediate including static bit
+ assign Irdecod.rxIsDt = lineOnehot[5] | (lineOnehot[0] & ~ird[8]);
+
+ // RX is USP
+ assign Irdecod.rxIsUsp = lineOnehot[4] & (ird[ 11:4] == 8'he6);
+
+ // RY is DT
+ // rz or PC explicit has higher priority
+
+ wire eaImmOrAbs = (ird[5:3] == 3'b111) & ~ird[1];
+ assign Irdecod.ryIsDt = eaImmOrAbs & ~isRegShift;
+
+ // RY is Address register
+ always_comb begin
+ logic eaIsAreg;
+
+ // On most cases RY is Areg expect if mode is 000 (DATA REG) or 111 (IMM, ABS,PC REL)
+ eaIsAreg = (ird[5:3] != 3'b000) & (ird[5:3] != 3'b111);
+
+ unique case( 1'b1)
+ // MOVE: RY always Areg expect if mode is 000 (DATA REG) or 111 (IMM, ABS,PC REL)
+ // Most lines, including misc line 4, also.
+ default: Irdecod.ryIsAreg = eaIsAreg;
+
+ lineOnehot[5]: // DBcc is an exception
+ Irdecod.ryIsAreg = eaIsAreg & (ird[7:3] != 5'b11001);
+
+ lineOnehot[6],
+ lineOnehot[7]: Irdecod.ryIsAreg = 1'b0;
+
+ lineOnehot['he]:
+ Irdecod.ryIsAreg = ~isRegShift;
+ endcase
+ end
+
+ // Byte sized instruction
+
+ // Original implementation sets this for some instructions that aren't really byte size
+ // but doesn't matter because they don't have a byte transfer enabled at nanocode, such as MOVEQ
+
+ wire xIsScc = (ird[7:6] == 2'b11) & (ird[5:3] != 3'b001);
+ wire xStaticMem = (ird[11:8] == 4'b1000) & (ird[5:4] == 2'b00); // Static bit to mem
+ always_comb begin
+ unique case( 1'b1)
+ lineOnehot[0]:
+ Irdecod.isByte =
+ ( ird[8] & (ird[5:4] != 2'b00) ) | // Dynamic bit to mem
+ ( (ird[11:8] == 4'b1000) & (ird[5:4] != 2'b00) ) | // Static bit to mem
+ ( (ird[8:7] == 2'b10) & (ird[5:3] == 3'b001) ) | // Movep from mem only! For byte mux
+ ( (ird[8:6] == 3'b000) & !xStaticMem ); // Immediate byte
+
+ lineOnehot[1]: Irdecod.isByte = 1'b1; // MOVE.B
+
+
+ lineOnehot[4]: Irdecod.isByte = (ird[7:6] == 2'b00) | Irdecod.isTas;
+ lineOnehot[5]: Irdecod.isByte = (ird[7:6] == 2'b00) | xIsScc;
+
+ lineOnehot[8],
+ lineOnehot[9],
+ lineOnehot['hb],
+ lineOnehot['hc],
+ lineOnehot['hd],
+ lineOnehot['he]: Irdecod.isByte = (ird[7:6] == 2'b00);
+
+ default: Irdecod.isByte = 1'b0;
+ endcase
+ end
+
+ // Need it for special byte size. Bus is byte, but whole register word is modified.
+ assign Irdecod.isMovep = lineOnehot[0] & ird[8] & eaAreg;
+
+
+ // rxIsSP implicit use of RX for actual SP transfer
+ //
+ // This logic is simple and will include some instructions that don't actually reference SP.
+ // But doesn't matter as long as they don't perform any RX transfer.
+
+ always_comb begin
+ unique case( 1'b1)
+ lineOnehot[6]: Irdecod.implicitSp = (ird[11:8] == 4'b0001); // BSR
+ lineOnehot[4]:
+ // Misc like RTS, JSR, etc
+ Irdecod.implicitSp = (ird[11:8] == 4'b1110) | (ird[11:6] == 6'b1000_01);
+ default: Irdecod.implicitSp = 1'b0;
+ endcase
+ end
+
+ // Modify CCR (and not SR)
+ // Probably overkill !! Only needs to distinguish SR vs CCR
+ // RTR, MOVE to CCR, xxxI to CCR
+ assign Irdecod.toCcr = ( lineOnehot[4] & ((ird[11:0] == 12'he77) | (ird[11:6] == 6'b010011)) ) |
+ ( lineOnehot[0] & (ird[8:6] == 3'b000));
+
+ // FTU constants
+ // This should not be latched on T3/T4. Latch on T2 or not at all. FTU needs it on next T3.
+ // Note: Reset instruction gets constant from ALU not from FTU!
+ logic [15:0] ftuConst;
+ wire [3:0] zero28 = (ird[11:9] == 0) ? 4'h8 : { 1'b0, ird[11:9]}; // xltate 0,1-7 into 8,1-7
+
+ always_comb begin
+ unique case( 1'b1)
+ lineOnehot[6], // Bcc short
+ lineOnehot[7]: ftuConst = { { 8{ ird[ 7]}}, ird[ 7:0] }; // MOVEQ
+
+ lineOnehot['h5], // addq/subq/static shift double check this
+ lineOnehot['he]: ftuConst = { 12'b0, zero28};
+
+ // MULU/MULS DIVU/DIVS
+ lineOnehot['h8],
+ lineOnehot['hc]: ftuConst = 16'h0f;
+
+ lineOnehot[4]: ftuConst = 16'h80; // TAS
+
+ default: ftuConst = '0;
+ endcase
+ end
+ assign Irdecod.ftuConst = ftuConst;
+
+ //
+ // TRAP Vector # for group 2 exceptions
+ //
+
+ always_comb begin
+ if( lineOnehot[4]) begin
+ case ( ird[6:5])
+ 2'b00,2'b01: Irdecod.macroTvn = 6; // CHK
+ 2'b11: Irdecod.macroTvn = 7; // TRAPV
+ 2'b10: Irdecod.macroTvn = {2'b10, ird[3:0]}; // TRAP
+ endcase
+ end
+ else
+ Irdecod.macroTvn = 5; // Division by zero
+ end
+
+
+ wire eaAdir = (ird[ 5:3] == 3'b001);
+ wire size11 = ird[7] & ird[6];
+
+ // Opcodes variants that don't affect flags
+ // ADDA/SUBA ADDQ/SUBQ MOVEA
+
+ assign Irdecod.inhibitCcr =
+ ( (lineOnehot[9] | lineOnehot['hd]) & size11) | // ADDA/SUBA
+ ( lineOnehot[5] & eaAdir) | // ADDQ/SUBQ to An (originally checks for line[4] as well !?)
+ ( (lineOnehot[2] | lineOnehot[3]) & ird[8:6] == 3'b001); // MOVEA
+
+endmodule
+
+/*
+ Execution unit
+
+ Executes register transfers set by the microcode. Originally through a set of bidirectional buses.
+ Most sources are available at T3, but DBIN only at T4! CCR also might be updated at T4, but it is not connected to these buses.
+ We mux at T1 and T2, then transfer to the destination at T3. The exception is AOB that need to be updated earlier.
+
+*/
+
+module excUnit( input s_clks Clks,
+ input enT1, enT2, enT3, enT4,
+ input s_nanod Nanod, input s_irdecod Irdecod,
+ input [15:0] Ird, // ALU row (and others) decoder needs it
+ input pswS,
+ input [15:0] ftu,
+ input [15:0] iEdb,
+
+ output logic [7:0] ccr,
+ output [15:0] alue,
+
+ output prenEmpty, au05z,
+ output logic dcr4, ze,
+ output logic aob0,
+ output [15:0] AblOut,
+ output logic [15:0] Irc,
+ output logic [15:0] oEdb,
+ output logic [23:1] eab);
+
+localparam REG_USP = 15;
+localparam REG_SSP = 16;
+localparam REG_DT = 17;
+
+ // Register file
+ reg [15:0] regs68L[ 18];
+ reg [15:0] regs68H[ 18];
+
+// synthesis translate off
+ /*
+ It is bad practice to initialize simulation registers that the hardware doesn't.
+ There is risk that simulation would be different than the real hardware. But in this case is the other way around.
+ Some ROM uses something like sub.l An,An at powerup which clears the register
+ Simulator power ups the registers with 'X, as they are really undetermined at the real hardware.
+ But the simulator doesn't realize (it can't) that the same value is substracting from itself,
+ and that the result should be zero even when it's 'X - 'X.
+ */
+
+ initial begin
+ for( int i = 0; i < 18; i++) begin
+ regs68L[i] <= '0;
+ regs68H[i] <= '0;
+ end
+ end
+
+ // For simulation display only
+ wire [31:0] SSP = { regs68H[REG_SSP], regs68L[REG_SSP]};
+
+// synthesis translate on
+
+
+ wire [15:0] aluOut;
+ wire [15:0] dbin;
+ logic [15:0] dcrOutput;
+
+ reg [15:0] PcL, PcH;
+
+ reg [31:0] auReg, aob;
+
+ reg [15:0] Ath, Atl;
+
+ // Bus execution
+ reg [15:0] Dbl, Dbh;
+ reg [15:0] Abh, Abl;
+ reg [15:0] Abd, Dbd;
+
+ assign AblOut = Abl;
+ assign au05z = (~| auReg[5:0]);
+
+ logic [15:0] dblMux, dbhMux;
+ logic [15:0] abhMux, ablMux;
+ logic [15:0] abdMux, dbdMux;
+
+ logic abdIsByte;
+
+ logic Pcl2Dbl, Pch2Dbh;
+ logic Pcl2Abl, Pch2Abh;
+
+
+ // RX RY muxes
+ // RX and RY actual registers
+ logic [4:0] actualRx, actualRy;
+ logic [3:0] movemRx;
+ logic byteNotSpAlign; // Byte instruction and no sp word align
+
+ // IRD decoded signals must be latched. See comments on decoder
+ // But nanostore decoding can't be latched before T4.
+ //
+ // If we need this earlier we can register IRD decode on T3 and use nano async
+
+ logic [4:0] rxMux, ryMux;
+ logic [3:0] rxReg, ryReg;
+ logic rxIsSp, ryIsSp;
+ logic rxIsAreg, ryIsAreg;
+
+ always_comb begin
+
+ // Unique IF !!
+ if( Nanod.ssp) begin
+ rxMux = REG_SSP;
+ rxIsSp = 1'b1;
+ rxReg = 1'bX;
+ end
+ else if( Irdecod.rxIsUsp) begin
+ rxMux = REG_USP;
+ rxIsSp = 1'b1;
+ rxReg = 1'bX;
+ end
+ else if( Irdecod.rxIsDt & !Irdecod.implicitSp) begin
+ rxMux = REG_DT;
+ rxIsSp = 1'b0;
+ rxReg = 1'bX;
+ end
+ else begin
+ if( Irdecod.implicitSp)
+ rxReg = 15;
+ else if( Irdecod.rxIsMovem)
+ rxReg = movemRx;
+ else
+ rxReg = { Irdecod.rxIsAreg, Irdecod.rx};
+
+ if( (& rxReg)) begin
+ rxMux = pswS ? REG_SSP : 15;
+ rxIsSp = 1'b1;
+ end
+ else begin
+ rxMux = { 1'b0, rxReg};
+ rxIsSp = 1'b0;
+ end
+ end
+
+ // RZ has higher priority!
+ if( Irdecod.ryIsDt & !Nanod.rz) begin
+ ryMux = REG_DT;
+ ryIsSp = 1'b0;
+ ryReg = 'X;
+ end
+ else begin
+ ryReg = Nanod.rz ? Irc[15:12] : {Irdecod.ryIsAreg, Irdecod.ry};
+ ryIsSp = (& ryReg);
+ if( ryIsSp & pswS) // No implicit SP on RY
+ ryMux = REG_SSP;
+ else
+ ryMux = { 1'b0, ryReg};
+ end
+
+ end
+
+ always_ff @( posedge Clks.clk) begin
+ if( enT4) begin
+ byteNotSpAlign <= Irdecod.isByte & ~(Nanod.rxlDbl ? rxIsSp : ryIsSp);
+
+ actualRx <= rxMux;
+ actualRy <= ryMux;
+
+ rxIsAreg <= rxIsSp | rxMux[3];
+ ryIsAreg <= ryIsSp | ryMux[3];
+ end
+
+ if( enT4)
+ abdIsByte <= Nanod.abdIsByte & Irdecod.isByte;
+ end
+
+ // Set RX/RY low word to which bus segment is connected.
+
+ wire ryl2Abl = Nanod.ryl2ab & (ryIsAreg | Nanod.ablAbd);
+ wire ryl2Abd = Nanod.ryl2ab & (~ryIsAreg | Nanod.ablAbd);
+ wire ryl2Dbl = Nanod.ryl2db & (ryIsAreg | Nanod.dblDbd);
+ wire ryl2Dbd = Nanod.ryl2db & (~ryIsAreg | Nanod.dblDbd);
+
+ wire rxl2Abl = Nanod.rxl2ab & (rxIsAreg | Nanod.ablAbd);
+ wire rxl2Abd = Nanod.rxl2ab & (~rxIsAreg | Nanod.ablAbd);
+ wire rxl2Dbl = Nanod.rxl2db & (rxIsAreg | Nanod.dblDbd);
+ wire rxl2Dbd = Nanod.rxl2db & (~rxIsAreg | Nanod.dblDbd);
+
+ // Buses. Main mux
+
+ logic abhIdle, ablIdle, abdIdle;
+ logic dbhIdle, dblIdle, dbdIdle;
+
+ always_comb begin
+ {abhIdle, ablIdle, abdIdle} = '0;
+ {dbhIdle, dblIdle, dbdIdle} = '0;
+
+ unique case( 1'b1)
+ ryl2Dbd: dbdMux = regs68L[ actualRy];
+ rxl2Dbd: dbdMux = regs68L[ actualRx];
+ Nanod.alue2Dbd: dbdMux = alue;
+ Nanod.dbin2Dbd: dbdMux = dbin;
+ Nanod.alu2Dbd: dbdMux = aluOut;
+ Nanod.dcr2Dbd: dbdMux = dcrOutput;
+ default: begin dbdMux = 'X; dbdIdle = 1'b1; end
+ endcase
+
+ unique case( 1'b1)
+ rxl2Dbl: dblMux = regs68L[ actualRx];
+ ryl2Dbl: dblMux = regs68L[ actualRy];
+ Nanod.ftu2Dbl: dblMux = ftu;
+ Nanod.au2Db: dblMux = auReg[15:0];
+ Nanod.atl2Dbl: dblMux = Atl;
+ Pcl2Dbl: dblMux = PcL;
+ default: begin dblMux = 'X; dblIdle = 1'b1; end
+ endcase
+
+ unique case( 1'b1)
+ Nanod.rxh2dbh: dbhMux = regs68H[ actualRx];
+ Nanod.ryh2dbh: dbhMux = regs68H[ actualRy];
+ Nanod.au2Db: dbhMux = auReg[31:16];
+ Nanod.ath2Dbh: dbhMux = Ath;
+ Pch2Dbh: dbhMux = PcH;
+ default: begin dbhMux = 'X; dbhIdle = 1'b1; end
+ endcase
+
+ unique case( 1'b1)
+ ryl2Abd: abdMux = regs68L[ actualRy];
+ rxl2Abd: abdMux = regs68L[ actualRx];
+ Nanod.dbin2Abd: abdMux = dbin;
+ Nanod.alu2Abd: abdMux = aluOut;
+ default: begin abdMux = 'X; abdIdle = 1'b1; end
+ endcase
+
+ unique case( 1'b1)
+ Pcl2Abl: ablMux = PcL;
+ rxl2Abl: ablMux = regs68L[ actualRx];
+ ryl2Abl: ablMux = regs68L[ actualRy];
+ Nanod.ftu2Abl: ablMux = ftu;
+ Nanod.au2Ab: ablMux = auReg[15:0];
+ Nanod.aob2Ab: ablMux = aob[15:0];
+ Nanod.atl2Abl: ablMux = Atl;
+ default: begin ablMux = 'X; ablIdle = 1'b1; end
+ endcase
+
+ unique case( 1'b1)
+ Pch2Abh: abhMux = PcH;
+ Nanod.rxh2abh: abhMux = regs68H[ actualRx];
+ Nanod.ryh2abh: abhMux = regs68H[ actualRy];
+ Nanod.au2Ab: abhMux = auReg[31:16];
+ Nanod.aob2Ab: abhMux = aob[31:16];
+ Nanod.ath2Abh: abhMux = Ath;
+ default: begin abhMux = 'X; abhIdle = 1'b1; end
+ endcase
+
+ end
+
+ // Source starts driving the bus on T1. Bus holds data until end of T3. Destination latches at T3.
+
+ // These registers store the first level mux, without bus interconnections.
+ // Even when this uses almost to 100 registers, it saves a lot of comb muxing and it is much faster.
+ reg [15:0] preAbh, preAbl, preAbd;
+ reg [15:0] preDbh, preDbl, preDbd;
+
+ always_ff @( posedge Clks.clk) begin
+
+ // Register first level mux at T1
+ if( enT1) begin
+ {preAbh, preAbl, preAbd} <= { abhMux, ablMux, abdMux};
+ {preDbh, preDbl, preDbd} <= { dbhMux, dblMux, dbdMux};
+ end
+
+ // Process bus interconnection at T2. Many combinations only used on DIV
+ // We use a simple method. If a specific bus segment is not driven we know that it should get data from a neighbour segment.
+ // In some cases this is not true and the segment is really idle without any destination. But then it doesn't matter.
+
+ if( enT2) begin
+ if( Nanod.extAbh)
+ Abh <= { 16{ ablIdle ? preAbd[ 15] : preAbl[ 15] }};
+ else if( abhIdle)
+ Abh <= ablIdle ? preAbd : preAbl;
+ else
+ Abh <= preAbh;
+
+ if( ~ablIdle)
+ Abl <= preAbl;
+ else
+ Abl <= Nanod.ablAbh ? preAbh : preAbd;
+
+ Abd <= ~abdIdle ? preAbd : ablIdle ? preAbh : preAbl;
+
+ if( Nanod.extDbh)
+ Dbh <= { 16{ dblIdle ? preDbd[ 15] : preDbl[ 15] }};
+ else if( dbhIdle)
+ Dbh <= dblIdle ? preDbd : preDbl;
+ else
+ Dbh <= preDbh;
+
+ if( ~dblIdle)
+ Dbl <= preDbl;
+ else
+ Dbl <= Nanod.dblDbh ? preDbh : preDbd;
+
+ Dbd <= ~dbdIdle ? preDbd: dblIdle ? preDbh : preDbl;
+
+ /*
+ Dbl <= dblMux; Dbh <= dbhMux;
+ Abd <= abdMux; Dbd <= dbdMux;
+ Abh <= abhMux; Abl <= ablMux; */
+ end
+ end
+
+ // AOB
+ //
+ // Originally change on T1. We do on T2, only then the output is enabled anyway.
+ //
+ // AOB[0] is used for address error. But even when raises on T1, seems not actually used until T2 or possibly T3.
+ // It is used on T1 when deasserted at the BSER exception ucode. Probably deassertion timing is not critical.
+ // But in that case (at BSER), AOB is loaded from AU, so we can safely transfer on T1.
+
+ // We need to take directly from first level muxes that are updated and T1
+
+ wire au2Aob = Nanod.au2Aob | (Nanod.au2Db & Nanod.db2Aob);
+
+ always_ff @( posedge Clks.clk) begin
+ // UNIQUE IF !
+
+ if( enT1 & au2Aob) // From AU we do can on T1
+ aob <= auReg;
+ else if( enT2) begin
+ if( Nanod.db2Aob)
+ aob <= { preDbh, ~dblIdle ? preDbl : preDbd};
+ else if( Nanod.ab2Aob)
+ aob <= { preAbh, ~ablIdle ? preAbl : preAbd};
+ end
+ end
+
+ assign eab = aob[23:1];
+ assign aob0 = aob[0];
+
+ // AU
+ logic [31:0] auInpMux;
+
+ // `ifdef ALW_COMB_BUG
+ // Old Modelsim bug. Doesn't update ouput always. Need excplicit sensitivity list !?
+ // always @( Nanod.auCntrl) begin
+
+ always_comb begin
+ unique case( Nanod.auCntrl)
+ 3'b000: auInpMux = 0;
+ 3'b001: auInpMux = byteNotSpAlign | Nanod.noSpAlign ? 1 : 2; // +1/+2
+ 3'b010: auInpMux = -4;
+ 3'b011: auInpMux = { Abh, Abl};
+ 3'b100: auInpMux = 2;
+ 3'b101: auInpMux = 4;
+ 3'b110: auInpMux = -2;
+ 3'b111: auInpMux = byteNotSpAlign | Nanod.noSpAlign ? -1 : -2; // -1/-2
+ default: auInpMux = 'X;
+ endcase
+ end
+
+ // Simulation problem
+ // Sometimes (like in MULM1) DBH is not set. AU is used in these cases just as a 6 bits counter testing if bits 5-0 are zero.
+ // But when adding something like 32'hXXXX0000, the simulator (incorrectly) will set *all the 32 bits* of the result as X.
+
+// synthesis translate_off
+ `define SIMULBUGX32 1
+ wire [16:0] aulow = Dbl + auInpMux[15:0];
+ wire [31:0] auResult = {Dbh + auInpMux[31:16] + aulow[16], aulow[15:0]};
+// synthesis translate_on
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp)
+ auReg <= '0;
+ else if( enT3 & Nanod.auClkEn)
+ `ifdef SIMULBUGX32
+ auReg <= auResult;
+ `else
+ auReg <= { Dbh, Dbl } + auInpMux;
+ `endif
+ end
+
+
+ // Main A/D registers
+
+ always_ff @( posedge Clks.clk) begin
+ if( enT3) begin
+ if( Nanod.dbl2rxl | Nanod.abl2rxl) begin
+ if( ~rxIsAreg) begin
+ if( Nanod.dbl2rxl) regs68L[ actualRx] <= Dbd;
+ else if( abdIsByte) regs68L[ actualRx][7:0] <= Abd[7:0];
+ else regs68L[ actualRx] <= Abd;
+ end
+ else
+ regs68L[ actualRx] <= Nanod.dbl2rxl ? Dbl : Abl;
+ end
+
+ if( Nanod.dbl2ryl | Nanod.abl2ryl) begin
+ if( ~ryIsAreg) begin
+ if( Nanod.dbl2ryl) regs68L[ actualRy] <= Dbd;
+ else if( abdIsByte) regs68L[ actualRy][7:0] <= Abd[7:0];
+ else regs68L[ actualRy] <= Abd;
+ end
+ else
+ regs68L[ actualRy] <= Nanod.dbl2ryl ? Dbl : Abl;
+ end
+
+ // High registers are easier. Both A & D on the same buses, and not byte ops.
+ if( Nanod.dbh2rxh | Nanod.abh2rxh)
+ regs68H[ actualRx] <= Nanod.dbh2rxh ? Dbh : Abh;
+ if( Nanod.dbh2ryh | Nanod.abh2ryh)
+ regs68H[ actualRy] <= Nanod.dbh2ryh ? Dbh : Abh;
+
+ end
+ end
+
+ // PC & AT
+ reg dbl2Pcl, dbh2Pch, abh2Pch, abl2Pcl;
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset) begin
+ { dbl2Pcl, dbh2Pch, abh2Pch, abl2Pcl } <= '0;
+
+ Pcl2Dbl <= 1'b0;
+ Pch2Dbh <= 1'b0;
+ Pcl2Abl <= 1'b0;
+ Pch2Abh <= 1'b0;
+ end
+ else if( enT4) begin // Must latch on T4 !
+ dbl2Pcl <= Nanod.dbl2reg & Nanod.pcldbl;
+ dbh2Pch <= Nanod.dbh2reg & Nanod.pchdbh;
+ abh2Pch <= Nanod.abh2reg & Nanod.pchabh;
+ abl2Pcl <= Nanod.abl2reg & Nanod.pclabl;
+
+ Pcl2Dbl <= Nanod.reg2dbl & Nanod.pcldbl;
+ Pch2Dbh <= Nanod.reg2dbh & Nanod.pchdbh;
+ Pcl2Abl <= Nanod.reg2abl & Nanod.pclabl;
+ Pch2Abh <= Nanod.reg2abh & Nanod.pchabh;
+ end
+
+ // Unique IF !!!
+ if( enT1 & Nanod.au2Pc)
+ PcL <= auReg[15:0];
+ else if( enT3) begin
+ if( dbl2Pcl)
+ PcL <= Dbl;
+ else if( abl2Pcl)
+ PcL <= Abl;
+ end
+
+ // Unique IF !!!
+ if( enT1 & Nanod.au2Pc)
+ PcH <= auReg[31:16];
+ else if( enT3) begin
+ if( dbh2Pch)
+ PcH <= Dbh;
+ else if( abh2Pch)
+ PcH <= Abh;
+ end
+
+ // Unique IF !!!
+ if( enT3) begin
+ if( Nanod.dbl2Atl)
+ Atl <= Dbl;
+ else if( Nanod.abl2Atl)
+ Atl <= Abl;
+ end
+
+ // Unique IF !!!
+ if( enT3) begin
+ if( Nanod.abh2Ath)
+ Ath <= Abh;
+ else if( Nanod.dbh2Ath)
+ Ath <= Dbh;
+ end
+
+ end
+
+ // Movem reg mask priority encoder
+
+ wire rmIdle;
+ logic [3:0] prHbit;
+ logic [15:0] prenLatch;
+
+ // Invert reg order for predecrement mode
+ assign prenEmpty = (~| prenLatch);
+ pren rmPren( .mask( prenLatch), .hbit (prHbit));
+
+ always_ff @( posedge Clks.clk) begin
+ // Cheating: PREN always loaded from DBIN
+ // Must be on T1 to branch earlier if reg mask is empty!
+ if( enT1 & Nanod.abl2Pren)
+ prenLatch <= dbin;
+ else if( enT3 & Nanod.updPren) begin
+ prenLatch [prHbit] <= 1'b0;
+ movemRx <= Irdecod.movemPreDecr ? ~prHbit : prHbit;
+ end
+ end
+
+ // DCR
+ wire [15:0] dcrCode;
+
+ wire [3:0] dcrInput = abdIsByte ? { 1'b0, Abd[ 2:0]} : Abd[ 3:0];
+ onehotEncoder4 dcrDecoder( .bin( dcrInput), .bitMap( dcrCode));
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp)
+ dcr4 <= '0;
+ else if( enT3 & Nanod.abd2Dcr) begin
+ dcrOutput <= dcrCode;
+ dcr4 <= Abd[4];
+ end
+ end
+
+ // ALUB
+ reg [15:0] alub;
+
+ always_ff @( posedge Clks.clk) begin
+ if( enT3) begin
+ // UNIQUE IF !!
+ if( Nanod.dbd2Alub)
+ alub <= Dbd;
+ else if( Nanod.abd2Alub)
+ alub <= Abd; // abdIsByte affects this !!??
+ end
+ end
+
+ wire alueClkEn = enT3 & Nanod.dbd2Alue;
+
+ // DOB/DBIN/IRC
+
+ logic [15:0] dobInput;
+ wire dobIdle = (~| Nanod.dobCtrl);
+
+ always_comb begin
+ unique case (Nanod.dobCtrl)
+ NANO_DOB_ADB: dobInput = Abd;
+ NANO_DOB_DBD: dobInput = Dbd;
+ NANO_DOB_ALU: dobInput = aluOut;
+ default: dobInput = 'X;
+ endcase
+ end
+
+ dataIo dataIo( .Clks, .enT1, .enT2, .enT3, .enT4, .Nanod, .Irdecod,
+ .iEdb, .dobIdle, .dobInput, .aob0,
+ .Irc, .dbin, .oEdb);
+
+ fx68kAlu alu(
+ .clk( Clks.clk), .pwrUp( Clks.pwrUp), .enT1, .enT3, .enT4,
+ .ird( Ird),
+ .aluColumn( Nanod.aluColumn), .aluAddrCtrl( Nanod.aluActrl),
+ .init( Nanod.aluInit), .finish( Nanod.aluFinish), .aluIsByte( Irdecod.isByte),
+ .ftu2Ccr( Nanod.ftu2Ccr),
+ .alub, .ftu, .alueClkEn, .alue,
+ .aluDataCtrl( Nanod.aluDctrl), .iDataBus( Dbd), .iAddrBus(Abd),
+ .ze, .aluOut, .ccr);
+
+endmodule
+
+//
+// Data bus I/O
+// At a separate module because it is a bit complicated and the timing is special.
+// Here we do the low/high byte mux and the special case of MOVEP.
+//
+// Original implementation is rather complex because both the internal and external buses are bidirectional.
+// Input is latched async at the EDB register.
+// We capture directly from the external data bus to the internal registers (IRC & DBIN) on PHI2, starting the external S7 phase, at a T4 internal period.
+
+module dataIo( input s_clks Clks,
+ input enT1, enT2, enT3, enT4,
+ input s_nanod Nanod, input s_irdecod Irdecod,
+ input [15:0] iEdb,
+ input aob0,
+
+ input dobIdle,
+ input [15:0] dobInput,
+
+ output logic [15:0] Irc,
+ output logic [15:0] dbin,
+ output logic [15:0] oEdb
+ );
+
+ reg [15:0] dob;
+
+ // DBIN/IRC
+
+ // Timing is different than any other register. We can latch only on the next T4 (bus phase S7).
+ // We need to register all control signals correctly because the next ublock will already be started.
+ // Can't latch control on T4 because if there are wait states there might be multiple T4 before we latch.
+
+ reg xToDbin, xToIrc;
+ reg dbinNoLow, dbinNoHigh;
+ reg byteMux, isByte_T4;
+
+ always_ff @( posedge Clks.clk) begin
+
+ // Byte mux control. Can't latch at T1. AOB might be not ready yet.
+ // Must latch IRD decode at T1 (or T4). Then combine and latch only at T3.
+
+ // Can't latch at T3, a new IRD might be loaded already at T1.
+ // Ok to latch at T4 if combination latched then at T3
+ if( enT4)
+ isByte_T4 <= Irdecod.isByte; // Includes MOVEP from mem, we could OR it here
+
+ if( enT3) begin
+ dbinNoHigh <= Nanod.noHighByte;
+ dbinNoLow <= Nanod.noLowByte;
+ byteMux <= Nanod.busByte & isByte_T4 & ~aob0;
+ end
+
+ if( enT1) begin
+ // If on wait states, we continue latching until next T1
+ xToDbin <= 1'b0;
+ xToIrc <= 1'b0;
+ end
+ else if( enT3) begin
+ xToDbin <= Nanod.todbin;
+ xToIrc <= Nanod.toIrc;
+ end
+
+ // Capture on T4 of the next ucycle
+ // If there are wait states, we keep capturing every PHI2 until the next T1
+
+ if( xToIrc & Clks.enPhi2)
+ Irc <= iEdb;
+ if( xToDbin & Clks.enPhi2) begin
+ // Original connects both halves of EDB.
+ if( ~dbinNoLow)
+ dbin[ 7:0] <= byteMux ? iEdb[ 15:8] : iEdb[7:0];
+ if( ~dbinNoHigh)
+ dbin[ 15:8] <= ~byteMux & dbinNoLow ? iEdb[ 7:0] : iEdb[ 15:8];
+ end
+ end
+
+ // DOB
+ logic byteCycle;
+
+ always_ff @( posedge Clks.clk) begin
+ // Originaly on T1. Transfer to internal EDB also on T1 (stays enabled upto the next T1). But only on T4 (S3) output enables.
+ // It is safe to do on T3, then, but control signals if derived from IRD must be registered.
+ // Originally control signals are not registered.
+
+ // Wait states don't affect DOB operation that is done at the start of the bus cycle.
+
+ if( enT4)
+ byteCycle <= Nanod.busByte & Irdecod.isByte; // busIsByte but not MOVEP
+
+ // Originally byte low/high interconnect is done at EDB, not at DOB.
+ if( enT3 & ~dobIdle) begin
+ dob[7:0] <= Nanod.noLowByte ? dobInput[15:8] : dobInput[ 7:0];
+ dob[15:8] <= (byteCycle | Nanod.noHighByte) ? dobInput[ 7:0] : dobInput[15:8];
+ end
+ end
+ assign oEdb = dob;
+
+endmodule
+
+
+// Provides ucode routine entries (A1/A3) for each opcode
+// Also checks for illegal opcode and priv violation
+
+// This is one of the slowest part of the processor.
+// But no need to optimize or pipeline because the result is not needed until at least 4 cycles.
+// IR updated at the least one microinstruction earlier.
+// Just need to configure the timing analizer correctly.
+
+module uaddrDecode(
+ input [15:0] opcode,
+ output [UADDR_WIDTH-1:0] a1, a2, a3,
+ output logic isPriv, isIllegal, isLineA, isLineF,
+ output [15:0] lineBmap);
+
+ wire [3:0] line = opcode[15:12];
+ logic [3:0] eaCol, movEa;
+
+ onehotEncoder4 irLineDecod( line, lineBmap);
+
+ assign isLineA = lineBmap[ 'hA];
+ assign isLineF = lineBmap[ 'hF];
+
+ pla_lined pla_lined( .movEa( movEa), .col( eaCol),
+ .opcode( opcode), .lineBmap( lineBmap),
+ .palIll( isIllegal), .plaA1( a1), .plaA2( a2), .plaA3( a3) );
+
+ // ea decoding
+ assign eaCol = eaDecode( opcode[ 5:0]);
+ assign movEa = eaDecode( {opcode[ 8:6], opcode[ 11:9]} );
+
+ // EA decode
+ function [3:0] eaDecode;
+ input [5:0] eaBits;
+ begin
+ unique case( eaBits[ 5:3])
+ 3'b111:
+ case( eaBits[ 2:0])
+ 3'b000: eaDecode = 7; // Absolute short
+ 3'b001: eaDecode = 8; // Absolute long
+ 3'b010: eaDecode = 9; // PC displacement
+ 3'b011: eaDecode = 10; // PC offset
+ 3'b100: eaDecode = 11; // Immediate
+ default: eaDecode = 12; // Invalid
+ endcase
+
+ default: eaDecode = eaBits[5:3]; // Register based EAs
+ endcase
+ end
+ endfunction
+
+
+ /*
+ Privileged instructions:
+
+ ANDI/EORI/ORI SR
+ MOVE to SR
+ MOVE to/from USP
+ RESET
+ RTE
+ STOP
+ */
+
+ always_comb begin
+ unique case( lineBmap)
+
+ // ori/andi/eori SR
+ 'h01: isPriv = ((opcode & 16'hf5ff) == 16'h007c);
+
+ 'h10:
+ begin
+ // No priority !!!
+ if( (opcode & 16'hffc0) == 16'h46c0) // move to sr
+ isPriv = 1'b1;
+
+ else if( (opcode & 16'hfff0) == 16'h4e60) // move usp
+ isPriv = 1'b1;
+
+ else if( opcode == 16'h4e70 || // reset
+ opcode == 16'h4e73 || // rte
+ opcode == 16'h4e72) // stop
+ isPriv = 1'b1;
+ else
+ isPriv = 1'b0;
+ end
+
+ default: isPriv = 1'b0;
+ endcase
+ end
+
+
+endmodule
+
+// bin to one-hot, 4 bits to 16-bit bitmap
+module onehotEncoder4( input [3:0] bin, output reg [15:0] bitMap);
+ always_comb begin
+ case( bin)
+ 'b0000: bitMap = 16'h0001;
+ 'b0001: bitMap = 16'h0002;
+ 'b0010: bitMap = 16'h0004;
+ 'b0011: bitMap = 16'h0008;
+ 'b0100: bitMap = 16'h0010;
+ 'b0101: bitMap = 16'h0020;
+ 'b0110: bitMap = 16'h0040;
+ 'b0111: bitMap = 16'h0080;
+ 'b1000: bitMap = 16'h0100;
+ 'b1001: bitMap = 16'h0200;
+ 'b1010: bitMap = 16'h0400;
+ 'b1011: bitMap = 16'h0800;
+ 'b1100: bitMap = 16'h1000;
+ 'b1101: bitMap = 16'h2000;
+ 'b1110: bitMap = 16'h4000;
+ 'b1111: bitMap = 16'h8000;
+ endcase
+ end
+endmodule
+
+// priority encoder
+// used by MOVEM regmask
+// this might benefit from device specific features
+// MOVEM doesn't need speed, will read the result 2 CPU cycles after each update.
+module pren( mask, hbit);
+ parameter size = 16;
+ parameter outbits = 4;
+
+ input [size-1:0] mask;
+ output reg [outbits-1:0] hbit;
+ // output reg idle;
+
+ always @( mask) begin
+ integer i;
+ hbit = 0;
+ // idle = 1;
+ for( i = size-1; i >= 0; i = i - 1) begin
+ if( mask[ i]) begin
+ hbit = i;
+ // idle = 0;
+ end
+ end
+ end
+
+endmodule
+
+// Microcode sequencer
+
+module sequencer( input s_clks Clks, input enT3,
+ input [UROM_WIDTH-1:0] microLatch,
+ input A0Err, BerrA, busAddrErr, Spuria, Avia,
+ input Tpend, intPend, isIllegal, isPriv, excRst, isLineA, isLineF,
+ input [15:0] psw,
+ input prenEmpty, au05z, dcr4, ze, i11,
+ input [1:0] alue01,
+ input [15:0] Ird,
+ input [UADDR_WIDTH-1:0] a1, a2, a3,
+ output logic [3:0] tvn,
+ output logic [UADDR_WIDTH-1:0] nma);
+
+ logic [UADDR_WIDTH-1:0] uNma;
+ logic [UADDR_WIDTH-1:0] grp1Nma;
+ logic [1:0] c0c1;
+ reg a0Rst;
+ wire A0Sel;
+ wire inGrp0Exc;
+
+ // assign nma = Clks.extReset ? RSTP0_NMA : (A0Err ? BSER1_NMA : uNma);
+ // assign nma = A0Err ? (a0Rst ? RSTP0_NMA : BSER1_NMA) : uNma;
+
+ // word type I: 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
+ // NMA : .. .. 09 08 01 00 05 04 03 02 07 06 .. .. .. .. ..
+
+ wire [UADDR_WIDTH-1:0] dbNma = { microLatch[ 14:13], microLatch[ 6:5], microLatch[ 10:7], microLatch[ 12:11]};
+
+ // Group 0 exception.
+ // Separated block from regular NMA. Otherwise simulation might depend on order of assigments.
+ always_comb begin
+ if( A0Err) begin
+ if( a0Rst) // Reset
+ nma = RSTP0_NMA;
+ else if( inGrp0Exc) // Double fault
+ nma = HALT1_NMA;
+ else // Bus or address error
+ nma = BSER1_NMA;
+ end
+ else
+ nma = uNma;
+ end
+
+ always_comb begin
+ // Format II (conditional) or I (direct branch)
+ if( microLatch[1])
+ uNma = { microLatch[ 14:13], c0c1, microLatch[ 10:7], microLatch[ 12:11]};
+ else
+ case( microLatch[ 3:2])
+ 0: uNma = dbNma; // DB
+ 1: uNma = A0Sel ? grp1Nma : a1;
+ 2: uNma = a2;
+ 3: uNma = a3;
+ endcase
+ end
+
+ // Format II, conditional, NMA decoding
+ wire [1:0] enl = { Ird[6], prenEmpty}; // Updated on T3
+
+ wire [1:0] ms0 = { Ird[8], alue01[0]};
+ wire [3:0] m01 = { au05z, Ird[8], alue01};
+ wire [1:0] nz1 = { psw[ NF], psw[ ZF]};
+ wire [1:0] nv = { psw[ NF], psw[ VF]};
+
+ logic ccTest;
+ wire [4:0] cbc = microLatch[ 6:2]; // CBC bits
+
+ always_comb begin
+ unique case( cbc)
+ 'h0: c0c1 = {i11, i11}; // W/L offset EA, from IRC
+
+ 'h1: c0c1 = (au05z) ? 2'b01 : 2'b11; // Updated on T3
+ 'h11: c0c1 = (au05z) ? 2'b00 : 2'b11;
+
+ 'h02: c0c1 = { 1'b0, ~psw[ CF]}; // C used in DIV
+ 'h12: c0c1 = { 1'b1, ~psw[ CF]};
+
+ 'h03: c0c1 = {psw[ ZF], psw[ ZF]}; // Z used in DIVU
+
+ 'h04: // nz1, used in DIVS
+ case( nz1)
+ 'b00: c0c1 = 2'b10;
+ 'b10: c0c1 = 2'b01;
+ 'b01,'b11: c0c1 = 2'b11;
+ endcase
+
+ 'h05: c0c1 = {psw[ NF], 1'b1}; // N used in CHK and DIV
+ 'h15: c0c1 = {1'b1, psw[ NF]};
+
+ // nz2, used in DIVS (same combination as nz1)
+ 'h06: c0c1 = { ~nz1[1] & ~nz1[0], 1'b1};
+
+ 'h07: // ms0 used in MUL
+ case( ms0)
+ 'b10, 'b00: c0c1 = 2'b11;
+ 'b01: c0c1 = 2'b01;
+ 'b11: c0c1 = 2'b10;
+ endcase
+
+ 'h08: // m01 used in MUL
+ case( m01)
+ 'b0000,'b0001,'b0100,'b0111: c0c1 = 2'b11;
+ 'b0010,'b0011,'b0101: c0c1 = 2'b01;
+ 'b0110: c0c1 = 2'b10;
+ default: c0c1 = 2'b00;
+ endcase
+
+ // Conditional
+ 'h09: c0c1 = (ccTest) ? 2'b11 : 2'b01;
+ 'h19: c0c1 = (ccTest) ? 2'b11 : 2'b10;
+
+ // DCR bit 4 (high or low word)
+ 'h0c: c0c1 = dcr4 ? 2'b01: 2'b11;
+ 'h1c: c0c1 = dcr4 ? 2'b10: 2'b11;
+
+ // DBcc done
+ 'h0a: c0c1 = ze ? 2'b11 : 2'b00;
+
+ // nv, used in CHK
+ 'h0b: c0c1 = (nv == 2'b00) ? 2'b00 : 2'b11;
+
+ // V, used in trapv
+ 'h0d: c0c1 = { ~psw[ VF], ~psw[VF]};
+
+ // enl, combination of pren idle and word/long on IRD
+ 'h0e,'h1e:
+ case( enl)
+ 2'b00: c0c1 = 'b10;
+ 2'b10: c0c1 = 'b11;
+ // 'hx1 result 00/01 depending on condition 0e/1e
+ 2'b01,2'b11:
+ c0c1 = { 1'b0, microLatch[ 6]};
+ endcase
+
+ default: c0c1 = 'X;
+ endcase
+ end
+
+ // CCR conditional
+ always_comb begin
+ unique case( Ird[ 11:8])
+ 'h0: ccTest = 1'b1; // T
+ 'h1: ccTest = 1'b0; // F
+ 'h2: ccTest = ~psw[ CF] & ~psw[ ZF]; // HI
+ 'h3: ccTest = psw[ CF] | psw[ZF]; // LS
+ 'h4: ccTest = ~psw[ CF]; // CC (HS)
+ 'h5: ccTest = psw[ CF]; // CS (LO)
+ 'h6: ccTest = ~psw[ ZF]; // NE
+ 'h7: ccTest = psw[ ZF]; // EQ
+ 'h8: ccTest = ~psw[ VF]; // VC
+ 'h9: ccTest = psw[ VF]; // VS
+ 'ha: ccTest = ~psw[ NF]; // PL
+ 'hb: ccTest = psw[ NF]; // MI
+ 'hc: ccTest = (psw[ NF] & psw[ VF]) | (~psw[ NF] & ~psw[ VF]); // GE
+ 'hd: ccTest = (psw[ NF] & ~psw[ VF]) | (~psw[ NF] & psw[ VF]); // LT
+ 'he: ccTest = (psw[ NF] & psw[ VF] & ~psw[ ZF]) |
+ (~psw[ NF] & ~psw[ VF] & ~psw[ ZF]); // GT
+ 'hf: ccTest = psw[ ZF] | (psw[ NF] & ~psw[VF]) | (~psw[ NF] & psw[VF]); // LE
+ endcase
+ end
+
+ // Exception logic
+ logic rTrace, rInterrupt;
+ logic rIllegal, rPriv, rLineA, rLineF;
+ logic rExcRst, rExcAdrErr, rExcBusErr;
+ logic rSpurious, rAutovec;
+ wire grp1LatchEn, grp0LatchEn;
+
+ // Originally control signals latched on T4. Then exception latches updated on T3
+ assign grp1LatchEn = microLatch[0] & (microLatch[1] | !microLatch[4]);
+ assign grp0LatchEn = microLatch[4] & !microLatch[1];
+
+ assign inGrp0Exc = rExcRst | rExcBusErr | rExcAdrErr;
+
+ always_ff @( posedge Clks.clk) begin
+ if( grp0LatchEn & enT3) begin
+ rExcRst <= excRst;
+ rExcBusErr <= BerrA;
+ rExcAdrErr <= busAddrErr;
+ rSpurious <= Spuria;
+ rAutovec <= Avia;
+ end
+
+ // Update group 1 exception latches
+ // Inputs from IR decoder updated on T1 as soon as IR loaded
+ // Trace pending updated on T3 at the start of the instruction
+ // Interrupt pending on T2
+ if( grp1LatchEn & enT3) begin
+ rTrace <= Tpend;
+ rInterrupt <= intPend;
+ rIllegal <= isIllegal & ~isLineA & ~isLineF;
+ rLineA <= isLineA;
+ rLineF <= isLineF;
+ rPriv <= isPriv & !psw[ SF];
+ end
+ end
+
+ // exception priority
+ always_comb begin
+ grp1Nma = TRAC1_NMA;
+ if( rExcRst)
+ tvn = '0; // Might need to change that to signal in exception
+ else if( rExcBusErr | rExcAdrErr)
+ tvn = { 1'b1, rExcAdrErr};
+
+ // Seudo group 0 exceptions. Just for updating TVN
+ else if( rSpurious | rAutovec)
+ tvn = rSpurious ? TVN_SPURIOUS : TVN_AUTOVEC;
+
+ else if( rTrace)
+ tvn = 9;
+ else if( rInterrupt) begin
+ tvn = TVN_INTERRUPT;
+ grp1Nma = ITLX1_NMA;
+ end
+ else begin
+ unique case( 1'b1) // Can't happen more than one of these
+ rIllegal: tvn = 4;
+ rPriv: tvn = 8;
+ rLineA: tvn = 10;
+ rLineF: tvn = 11;
+ default: tvn = 1; // Signal no group 0/1 exception
+ endcase
+ end
+ end
+
+ assign A0Sel = rIllegal | rLineF | rLineA | rPriv | rTrace | rInterrupt;
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset)
+ a0Rst <= 1'b1;
+ else if( enT3)
+ a0Rst <= 1'b0;
+ end
+
+endmodule
+
+
+//
+// DMA/BUS Arbitration
+//
+
+module busArbiter( input s_clks Clks,
+ input BRi, BgackI, Halti, bgBlock,
+ output busAvail,
+ output logic BGn);
+
+ enum int unsigned { DRESET = 0, DIDLE, D1, D_BR, D_BA, D_BRA, D3, D2} dmaPhase, next;
+
+ always_comb begin
+ case(dmaPhase)
+ DRESET: next = DIDLE;
+ DIDLE: begin
+ if( bgBlock)
+ next = DIDLE;
+ else if( ~BgackI)
+ next = D_BA;
+ else if( ~BRi)
+ next = D1;
+ else
+ next = DIDLE;
+ end
+
+ D_BA: begin // Loop while only BGACK asserted, BG negated here
+ if( ~BRi & !bgBlock)
+ next = D3;
+ else if( ~BgackI & !bgBlock)
+ next = D_BA;
+ else
+ next = DIDLE;
+ end
+
+ D1: next = D_BR; // Loop while only BR asserted
+ D_BR: next = ~BRi & BgackI ? D_BR : D_BA; // No direct path to IDLE !
+
+ D3: next = D_BRA;
+ D_BRA: begin // Loop while both BR and BGACK asserted
+ case( {BgackI, BRi} )
+ 2'b11: next = DIDLE; // Both deasserted
+ 2'b10: next = D_BR; // BR asserted only
+ 2'b01: next = D2; // BGACK asserted only
+ 2'b00: next = D_BRA; // Stay here while both asserted
+ endcase
+ end
+
+ // Might loop here if both deasserted, should normally don't arrive here anyway?
+ // D2: next = (BgackI & BRi) | bgBlock ? D2: D_BA;
+
+ D2: next = D_BA;
+
+ default: next = DIDLE; // Should not reach here normally
+ endcase
+ end
+
+ logic granting;
+ always_comb begin
+ unique case( next)
+ D1, D3, D_BR, D_BRA: granting = 1'b1;
+ default: granting = 1'b0;
+ endcase
+ end
+
+ reg rGranted;
+ assign busAvail = Halti & BRi & BgackI & ~rGranted;
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset) begin
+ dmaPhase <= DRESET;
+ rGranted <= 1'b0;
+ end
+ else if( Clks.enPhi2) begin
+ dmaPhase <= next;
+ // Internal signal changed on PHI2
+ rGranted <= granting;
+ end
+
+ // External Output changed on PHI1
+ if( Clks.extReset)
+ BGn <= 1'b1;
+ else if( Clks.enPhi1)
+ BGn <= ~rGranted;
+
+ end
+
+endmodule
+
+module busControl( input s_clks Clks, input enT1, input enT4,
+ input permStart, permStop, iStop,
+ input aob0,
+ input isWrite, isByte, isRmc,
+ input busAvail,
+ output bgBlock,
+ output busAddrErr,
+ output waitBusCycle,
+ output busStarting, // Asserted during S0
+ output logic addrOe, // Asserted from S1 to the end, whole bus cycle except S0
+ output bciWrite, // Used for SSW on bus/addr error
+
+ input rDtack, BeDebounced, Vpai,
+ output ASn, output LDSn, output UDSn, eRWn);
+
+ reg rAS, rLDS, rUDS, rRWn;
+ assign ASn = rAS;
+ assign LDSn = rLDS;
+ assign UDSn = rUDS;
+ assign eRWn = rRWn;
+
+ //reg dataOe;
+
+ reg bcPend;
+ reg isWriteReg, bciByte, isRmcReg, wendReg;
+ assign bciWrite = isWriteReg;
+ reg addrOeDelay;
+ reg isByteT4;
+
+ wire canStart, busEnd;
+ wire bcComplete, bcReset;
+
+ wire isRcmReset = bcComplete & bcReset & isRmcReg;
+
+ assign busAddrErr = aob0 & ~bciByte;
+
+ // Bus retry not really supported.
+ // It's BERR and HALT and not address error, and not read-modify cycle.
+ wire busRetry = ~busAddrErr & 1'b0;
+
+ enum int unsigned { SRESET = 0, SIDLE, S0, S2, S4, S6, SRMC_RES} busPhase, next;
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset)
+ busPhase <= SRESET;
+ else if( Clks.enPhi1)
+ busPhase <= next;
+ end
+
+ always_comb begin
+ case( busPhase)
+ SRESET: next = SIDLE;
+ SRMC_RES: next = SIDLE; // Single cycle special state when read phase of RMC reset
+ S0: next = S2;
+ S2: next = S4;
+ S4: next = busEnd ? S6 : S4;
+ S6: next = isRcmReset ? SRMC_RES : (canStart ? S0 : SIDLE);
+ SIDLE: next = canStart ? S0 : SIDLE;
+ default: next = SIDLE;
+ endcase
+ end
+
+ // Idle phase of RMC bus cycle. Might be better to just add a new state
+ wire rmcIdle = (busPhase == SIDLE) & ~ASn & isRmcReg;
+
+ assign canStart = (busAvail | rmcIdle) & (bcPend | permStart) & !busRetry & !bcReset;
+
+ wire busEnding = (next == SIDLE) | (next == S0);
+
+ assign busStarting = (busPhase == S0);
+
+ // term signal (DTACK, BERR, VPA, adress error)
+ assign busEnd = ~rDtack | iStop;
+
+ // bcComplete asserted on raising edge of S6 (together with SNC).
+ assign bcComplete = (busPhase == S6);
+
+ // Clear bus info latch on completion (regular or aborted) and no bus retry (and not PHI1).
+ // bciClear asserted half clock later on PHI2, and bci latches cleared async concurrently
+ wire bciClear = bcComplete & ~busRetry;
+
+ // Reset on reset or (berr & berrDelay & (not halt or rmc) & not 6800 & in bus cycle) (and not PHI1)
+ assign bcReset = Clks.extReset | (addrOeDelay & BeDebounced & Vpai);
+
+ // Enable uclock only on S6 (S8 on Bus Error) or not bciPermStop
+ assign waitBusCycle = wendReg & !bcComplete;
+
+ // Block Bus Grant when starting new bus cycle. But No need if AS already asserted (read phase of RMC)
+ // Except that when that RMC phase aborted on bus error, it's asserted one cycle later!
+ assign bgBlock = ((busPhase == S0) & ASn) | (busPhase == SRMC_RES);
+
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.extReset) begin
+ addrOe <= 1'b0;
+ end
+ else if( Clks.enPhi2 & ( busPhase == S0)) // From S1, whole bus cycle except S0
+ addrOe <= 1'b1;
+ else if( Clks.enPhi1 & (busPhase == SRMC_RES))
+ addrOe <= 1'b0;
+ else if( Clks.enPhi1 & ~isRmcReg & busEnding)
+ addrOe <= 1'b0;
+
+ if( Clks.enPhi1)
+ addrOeDelay <= addrOe;
+
+ if( Clks.extReset) begin
+ rAS <= 1'b1;
+ rUDS <= 1'b1;
+ rLDS <= 1'b1;
+ rRWn <= 1'b1;
+ //dataOe <= '0;
+ end
+ else begin
+/*
+ if( Clks.enPhi2 & isWriteReg & (busPhase == S2))
+ dataOe <= 1'b1;
+ else if( Clks.enPhi1 & (busEnding | (busPhase == SIDLE)) )
+ dataOe <= 1'b0;
+*/
+ if( Clks.enPhi1 & busEnding)
+ rRWn <= 1'b1;
+ else if( Clks.enPhi1 & isWriteReg) begin
+ // Unlike LDS/UDS Asserted even in address error
+ if( (busPhase == S0) & isWriteReg)
+ rRWn <= 1'b0;
+ end
+
+ // AS. Actually follows addrOe half cycle later!
+ if( Clks.enPhi1 & (busPhase == S0))
+ rAS <= 1'b0;
+ else if( Clks.enPhi2 & (busPhase == SRMC_RES)) // Bus error on read phase of RMC. Deasserted one cycle later
+ rAS <= 1'b1;
+ else if( Clks.enPhi2 & bcComplete & ~SRMC_RES)
+ if( ~isRmcReg) // Keep AS asserted on the IDLE phase of RMC
+ rAS <= 1'b1;
+
+ if( Clks.enPhi1 & (busPhase == S0)) begin
+ if( ~isWriteReg & !busAddrErr) begin
+ rUDS <= ~(~bciByte | ~aob0);
+ rLDS <= ~(~bciByte | aob0);
+ end
+ end
+ else if( Clks.enPhi1 & isWriteReg & (busPhase == S2) & !busAddrErr) begin
+ rUDS <= ~(~bciByte | ~aob0);
+ rLDS <= ~(~bciByte | aob0);
+ end
+ else if( Clks.enPhi2 & bcComplete) begin
+ rUDS <= 1'b1;
+ rLDS <= 1'b1;
+ end
+
+ end
+
+ end
+
+ // Bus cycle info latch. Needed because uinstr might change if the bus is busy and we must wait.
+ // Note that urom advances even on wait states. It waits *after* updating urom and nanorom latches.
+ // Even without wait states, ublocks of type ir (init reading) will not wait for bus completion.
+ // Originally latched on (permStart AND T1).
+
+ // Bus cycle info latch: isRead, isByte, read-modify-cycle, and permStart (bus cycle pending). Some previously latched on T4?
+ // permStop also latched, but unconditionally on T1
+
+ // Might make more sense to register this outside this module
+ always_ff @( posedge Clks.clk) begin
+ if( enT4) begin
+ isByteT4 <= isByte;
+ end
+ end
+
+ // Bus Cycle Info Latch
+ always_ff @( posedge Clks.clk) begin
+ if( Clks.pwrUp) begin
+ bcPend <= 1'b0;
+ wendReg <= 1'b0;
+ isWriteReg <= 1'b0;
+ bciByte <= 1'b0;
+ isRmcReg <= 1'b0;
+ end
+
+ else if( Clks.enPhi2 & (bciClear | bcReset)) begin
+ bcPend <= 1'b0;
+ wendReg <= 1'b0;
+ end
+ else begin
+ if( enT1 & permStart) begin
+ isWriteReg <= isWrite;
+ bciByte <= isByteT4;
+ isRmcReg <= isRmc & ~isWrite; // We need special case the end of the read phase only.
+ bcPend <= 1'b1;
+ end
+ if( enT1)
+ wendReg <= permStop;
+ end
+ end
+
+endmodule
+
+//
+// microrom and nanorom instantiation
+//
+// There is bit of wasting of resources here. An extra registering pipeline happens that is not needed.
+// This is just for the purpose of helping inferring block RAM using pure generic code. Inferring RAM is important for performance.
+// Might be more efficient to use vendor specific features such as clock enable.
+//
+
+module uRom( input clk, input [UADDR_WIDTH-1:0] microAddr, output logic [UROM_WIDTH-1:0] microOutput);
+ reg [UROM_WIDTH-1:0] uRam[ UROM_DEPTH];
+ initial begin
+ $readmemb("microrom.mem", uRam);
+ end
+
+ always_ff @( posedge clk)
+ microOutput <= uRam[ microAddr];
+endmodule
+
+
+module nanoRom( input clk, input [NADDR_WIDTH-1:0] nanoAddr, output logic [NANO_WIDTH-1:0] nanoOutput);
+ reg [NANO_WIDTH-1:0] nRam[ NANO_DEPTH];
+ initial begin
+ $readmemb("nanorom.mem", nRam);
+ end
+
+ always_ff @( posedge clk)
+ nanoOutput <= nRam[ nanoAddr];
+endmodule
+
+// Translate uaddr to nanoaddr
+module microToNanoAddr(
+ input [UADDR_WIDTH-1:0] uAddr,
+ output [NADDR_WIDTH-1:0] orgAddr);
+
+ wire [UADDR_WIDTH-1:2] baseAddr = uAddr[UADDR_WIDTH-1:2];
+ logic [NADDR_WIDTH-1:2] orgBase;
+ assign orgAddr = { orgBase, uAddr[1:0]};
+
+ always @( baseAddr)
+ begin
+ // nano ROM (136 addresses)
+ case( baseAddr)
+
+'h00: orgBase = 7'h0 ;
+'h01: orgBase = 7'h1 ;
+'h02: orgBase = 7'h2 ;
+'h03: orgBase = 7'h2 ;
+'h08: orgBase = 7'h3 ;
+'h09: orgBase = 7'h4 ;
+'h0A: orgBase = 7'h5 ;
+'h0B: orgBase = 7'h5 ;
+'h10: orgBase = 7'h6 ;
+'h11: orgBase = 7'h7 ;
+'h12: orgBase = 7'h8 ;
+'h13: orgBase = 7'h8 ;
+'h18: orgBase = 7'h9 ;
+'h19: orgBase = 7'hA ;
+'h1A: orgBase = 7'hB ;
+'h1B: orgBase = 7'hB ;
+'h20: orgBase = 7'hC ;
+'h21: orgBase = 7'hD ;
+'h22: orgBase = 7'hE ;
+'h23: orgBase = 7'hD ;
+'h28: orgBase = 7'hF ;
+'h29: orgBase = 7'h10 ;
+'h2A: orgBase = 7'h11 ;
+'h2B: orgBase = 7'h10 ;
+'h30: orgBase = 7'h12 ;
+'h31: orgBase = 7'h13 ;
+'h32: orgBase = 7'h14 ;
+'h33: orgBase = 7'h14 ;
+'h38: orgBase = 7'h15 ;
+'h39: orgBase = 7'h16 ;
+'h3A: orgBase = 7'h17 ;
+'h3B: orgBase = 7'h17 ;
+'h40: orgBase = 7'h18 ;
+'h41: orgBase = 7'h18 ;
+'h42: orgBase = 7'h18 ;
+'h43: orgBase = 7'h18 ;
+'h44: orgBase = 7'h19 ;
+'h45: orgBase = 7'h19 ;
+'h46: orgBase = 7'h19 ;
+'h47: orgBase = 7'h19 ;
+'h48: orgBase = 7'h1A ;
+'h49: orgBase = 7'h1A ;
+'h4A: orgBase = 7'h1A ;
+'h4B: orgBase = 7'h1A ;
+'h4C: orgBase = 7'h1B ;
+'h4D: orgBase = 7'h1B ;
+'h4E: orgBase = 7'h1B ;
+'h4F: orgBase = 7'h1B ;
+'h54: orgBase = 7'h1C ;
+'h55: orgBase = 7'h1D ;
+'h56: orgBase = 7'h1E ;
+'h57: orgBase = 7'h1F ;
+'h5C: orgBase = 7'h20 ;
+'h5D: orgBase = 7'h21 ;
+'h5E: orgBase = 7'h22 ;
+'h5F: orgBase = 7'h23 ;
+'h70: orgBase = 7'h24 ;
+'h71: orgBase = 7'h24 ;
+'h72: orgBase = 7'h24 ;
+'h73: orgBase = 7'h24 ;
+'h74: orgBase = 7'h24 ;
+'h75: orgBase = 7'h24 ;
+'h76: orgBase = 7'h24 ;
+'h77: orgBase = 7'h24 ;
+'h78: orgBase = 7'h25 ;
+'h79: orgBase = 7'h25 ;
+'h7A: orgBase = 7'h25 ;
+'h7B: orgBase = 7'h25 ;
+'h7C: orgBase = 7'h25 ;
+'h7D: orgBase = 7'h25 ;
+'h7E: orgBase = 7'h25 ;
+'h7F: orgBase = 7'h25 ;
+'h84: orgBase = 7'h26 ;
+'h85: orgBase = 7'h27 ;
+'h86: orgBase = 7'h28 ;
+'h87: orgBase = 7'h29 ;
+'h8C: orgBase = 7'h2A ;
+'h8D: orgBase = 7'h2B ;
+'h8E: orgBase = 7'h2C ;
+'h8F: orgBase = 7'h2D ;
+'h94: orgBase = 7'h2E ;
+'h95: orgBase = 7'h2F ;
+'h96: orgBase = 7'h30 ;
+'h97: orgBase = 7'h31 ;
+'h9C: orgBase = 7'h32 ;
+'h9D: orgBase = 7'h33 ;
+'h9E: orgBase = 7'h34 ;
+'h9F: orgBase = 7'h35 ;
+'hA4: orgBase = 7'h36 ;
+'hA5: orgBase = 7'h36 ;
+'hA6: orgBase = 7'h37 ;
+'hA7: orgBase = 7'h37 ;
+'hAC: orgBase = 7'h38 ;
+'hAD: orgBase = 7'h38 ;
+'hAE: orgBase = 7'h39 ;
+'hAF: orgBase = 7'h39 ;
+'hB4: orgBase = 7'h3A ;
+'hB5: orgBase = 7'h3A ;
+'hB6: orgBase = 7'h3B ;
+'hB7: orgBase = 7'h3B ;
+'hBC: orgBase = 7'h3C ;
+'hBD: orgBase = 7'h3C ;
+'hBE: orgBase = 7'h3D ;
+'hBF: orgBase = 7'h3D ;
+'hC0: orgBase = 7'h3E ;
+'hC1: orgBase = 7'h3F ;
+'hC2: orgBase = 7'h40 ;
+'hC3: orgBase = 7'h41 ;
+'hC8: orgBase = 7'h42 ;
+'hC9: orgBase = 7'h43 ;
+'hCA: orgBase = 7'h44 ;
+'hCB: orgBase = 7'h45 ;
+'hD0: orgBase = 7'h46 ;
+'hD1: orgBase = 7'h47 ;
+'hD2: orgBase = 7'h48 ;
+'hD3: orgBase = 7'h49 ;
+'hD8: orgBase = 7'h4A ;
+'hD9: orgBase = 7'h4B ;
+'hDA: orgBase = 7'h4C ;
+'hDB: orgBase = 7'h4D ;
+'hE0: orgBase = 7'h4E ;
+'hE1: orgBase = 7'h4E ;
+'hE2: orgBase = 7'h4F ;
+'hE3: orgBase = 7'h4F ;
+'hE8: orgBase = 7'h50 ;
+'hE9: orgBase = 7'h50 ;
+'hEA: orgBase = 7'h51 ;
+'hEB: orgBase = 7'h51 ;
+'hF0: orgBase = 7'h52 ;
+'hF1: orgBase = 7'h52 ;
+'hF2: orgBase = 7'h52 ;
+'hF3: orgBase = 7'h52 ;
+'hF8: orgBase = 7'h53 ;
+'hF9: orgBase = 7'h53 ;
+'hFA: orgBase = 7'h53 ;
+'hFB: orgBase = 7'h53 ;
+
+ default:
+ orgBase = 'X;
+ endcase
+ end
+
+endmodule
+
+//
+// For compilation test only
+//
+
+`ifdef FX68K_TEST
+module fx68kTop( input clk32,
+ input extReset,
+ // input pwrUp,
+
+ input DTACKn, input VPAn,
+ input BERRn,
+ input BRn, BGACKn,
+ input IPL0n, input IPL1n, input IPL2n,
+ input [15:0] iEdb,
+
+ output [15:0] oEdb,
+ output eRWn, output ASn, output LDSn, output UDSn,
+ output logic E, output VMAn,
+ output FC0, output FC1, output FC2,
+ output BGn,
+ output oRESETn, output oHALTEDn,
+ output [23:1] eab
+ );
+
+ // Clock must be at least twice the desired frequency. A 32 MHz clock means a maximum 16 MHz effective frequency.
+ // In this example we divide the clock by 4. Resulting on an effective processor running at 8 MHz.
+
+ reg [1:0] clkDivisor = '0;
+ always @( posedge clk32) begin
+ clkDivisor <= clkDivisor + 1'b1;
+ end
+
+ /*
+ These two signals must be a single cycle pulse. They don't need to be registered.
+ Same signal can't be asserted twice in a row. Other than that there are no restrictions.
+ There can be any number of cycles, or none, even variable non constant cycles, between each pulse.
+ */
+
+ wire enPhi1 = (clkDivisor == 2'b11);
+ wire enPhi2 = (clkDivisor == 2'b01);
+
+
+ fx68k fx68k( .clk( clk32),
+ .extReset, .pwrUp( extReset), .enPhi1, .enPhi2,
+
+ .DTACKn, .VPAn, .BERRn, .BRn, .BGACKn,
+ .IPL0n, .IPL1n, .IPL2n,
+ .iEdb,
+
+ .oEdb,
+ .eRWn, .ASn, .LDSn, .UDSn,
+ .E, .VMAn,
+ .FC0, .FC1, .FC2,
+ .BGn,
+ .oRESETn, .oHALTEDn, .eab);
+
+endmodule
+`endif
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.txt b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b9c3c5a4dced49ff317d05736176fa4bf2632f2d
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68k.txt
@@ -0,0 +1,87 @@
+FX68K
+
+68000 cycle accurate core
+Copyright (c) 2018 by Jorge Cwik
+fx68k@fxatari.com
+
+
+FX68K is a 68K cycle exact compatible core. In theory at least, it should be impossible to distinguish functionally from a real 68K processor.
+
+On Cyclone families it uses just over 5,100 LEs and about 5KB internal ram, reaching a max clock frequency close to 40MHz. Some optimizations are still possible to implement and increase the performance.
+
+The core is fully synchronous. Considerable effort was done to avoid any asynchronous logic.
+
+Written in SystemVerilog.
+
+The timing of the external bus signals is exactly as the original processor. The only feature that is not implemented yet is bus retry using the external HALT input signal.
+
+It was designed to replace an actual chip on a real board. This wasn't yet tested however and not all necessary output enable control signals are fully implemented.
+
+
+Copyright
+
+//
+// This source file is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+//
+// This source file is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+//
+
+
+Developer Notes
+
+
+The core receives a clock that must be at least twice the frequency of the desired nominal speed. The core also receives two signals for masking both phases of the clock (PHI1 and PHI2). These signals are implemented as simple clock enable for all the flip flops used by the core. This way, the original clock frequency can be any multiple and it doesn't even need to be regular or constant.
+
+These two signals are enPhi1 and enPhi2. They must be a single cycle pulse, and they don't need to be registered. Because they are actually used as clock enable, the output signals change one cycle later.
+
+enPhi1 should be asserted one cycle before the high phase of the nominal clock, and enPhi2 one cycle before the low phase.
+
+E.g., during a bus cycle, AS is asserted one cycle after enPhi1 is asserted, and AS is deasserted one cycle after enPhi2 is asserted. This follows the original bus timing that specify AS being asserted on the raising edge of the clock, and deasserted on the falling edge one.
+
+All signals follow the original polarity and then most are low active.
+
+extReset is external reset and is synchronous and high active. Hence is doesn't have to be registered.
+
+pwrUp qualifies external reset as being a cold power up reset. If it is asserted, then extReset must be asserted as well. Most system don't need to distinguish between a cold and a warm reset at the CPU level. Then both signals can be always asserted together. The core does expect pwrUp to be asserted initially because there is no true asynchronous reset. The signal is high active.
+
+
+Timing analysis
+
+Microcode access is one of the slowest paths on the core. But the microcode output is not needed immediately. Use the following constraints to get a more accurate timing analysis. Note that the full path might need to be modified:
+
+# Altera/Intel
+
+set_multicycle_path -start -setup -from [get_keepers fx68k:fx68k|Ir[*]] -to [get_keepers fx68k:fx68k|microAddr[*]] 2
+set_multicycle_path -start -hold -from [get_keepers fx68k:fx68k|Ir[*]] -to [get_keepers fx68k:fx68k|microAddr[*]] 1
+set_multicycle_path -start -setup -from [get_keepers fx68k:fx68k|Ir[*]] -to [get_keepers fx68k:fx68k|nanoAddr[*]] 2
+set_multicycle_path -start -hold -from [get_keepers fx68k:fx68k|Ir[*]] -to [get_keepers fx68k:fx68k|nanoAddr[*]] 1
+
+# For Xilinx Vivado
+
+set_multicycle_path -setup -from [get_pins fx68k/Ir*/C] -to [get_pins fx68k/nanoAddr_reg*/D] 2
+set_multicycle_path -setup -from [get_pins fx68k/Ir*/C] -to [get_pins fx68k/microAddr_reg*/D] 2
+set_multicycle_path -hold -from [get_pins fx68k/Ir*/C] -to [get_pins fx68k/nanoAddr_reg*/D] 1
+set_multicycle_path -hold -from [get_pins fx68k/Ir*/C] -to [get_pins fx68k/microAddr_reg*/D] 1
+
+
+The update of the CCR flags is also time critical. Some compilers might benefit with the following constraints, but this wasn't fully verified yet:
+
+
+# Altera/Intel
+# set_multicycle_path -start -setup -from [fx68k:fx68k|nanoLatch[*]]
+# -to [get_keepers fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|pswCcr[*]] 2
+# set_multicycle_path -start -setup -from [fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|oper[*]]
+# -to [get_keepers fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|pswCcr[*]] 2
+# set_multicycle_path -start -hold -from [fx68k:fx68k|nanoLatch[*]]
+# -to [get_keepers fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|pswCcr[*]] 1
+# set_multicycle_path -start -hold -from [fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|oper[*]]
+# -to [get_keepers fx68k:fx68k|excUnit:excUnit|fx68kAlu:alu|pswCcr[*]] 1
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68kAlu.sv b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68kAlu.sv
new file mode 100644
index 0000000000000000000000000000000000000000..49b5a19a2280193cc4d04ac0da06f2dfd588e2f3
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/fx68kAlu.sv
@@ -0,0 +1,843 @@
+//
+// FX 68K
+//
+// M68K cycle accurate, fully synchronous
+// Copyright (c) 2018 by Jorge Cwik
+//
+// ALU
+//
+
+// altera message_off 10230
+// altera message_off 10763
+// altera message_off 10958
+
+`timescale 1 ns / 1 ns
+
+localparam MASK_NBITS = 5;
+
+localparam
+ OP_AND = 1,
+ OP_SUB = 2, OP_SUBX = 3, OP_ADD = 4,
+ OP_EXT = 5, OP_SBCD = 6, OP_SUB0 = 7,
+ OP_OR = 8, OP_EOR = 9,
+ OP_SUBC = 10, OP_ADDC = 11, OP_ADDX = 12,
+ OP_ASL = 13,
+ OP_ASR = 14,
+ OP_LSL = 15,
+ OP_LSR = 16,
+ OP_ROL = 17,
+ OP_ROR = 18,
+ OP_ROXL = 19,
+ OP_ROXR = 20,
+ OP_SLAA = 21,
+ OP_ABCD = 22;
+
+module fx68kAlu ( input clk, pwrUp, enT1, enT3, enT4,
+ input [15:0] ird,
+ input [2:0] aluColumn,
+ input [1:0] aluDataCtrl,
+ input aluAddrCtrl, alueClkEn, ftu2Ccr, init, finish, aluIsByte,
+ input [15:0] ftu,
+ input [15:0] alub,
+ input [15:0] iDataBus, input [15:0] iAddrBus,
+ output ze,
+ output reg [15:0] alue,
+ output reg [7:0] ccr,
+ output [15:0] aluOut);
+
+
+`define ALU_ROW_01 16'h0002
+`define ALU_ROW_02 16'h0004
+`define ALU_ROW_03 16'h0008
+`define ALU_ROW_04 16'h0010
+`define ALU_ROW_05 16'h0020
+`define ALU_ROW_06 16'h0040
+`define ALU_ROW_07 16'h0080
+`define ALU_ROW_08 16'h0100
+`define ALU_ROW_09 16'h0200
+`define ALU_ROW_10 16'h0400
+`define ALU_ROW_11 16'h0800
+`define ALU_ROW_12 16'h1000
+`define ALU_ROW_13 16'h2000
+`define ALU_ROW_14 16'h4000
+`define ALU_ROW_15 16'h8000
+
+
+ // Bit positions for flags in CCR
+ localparam CF = 0, VF = 1, ZF = 2, NF = 3, XF = 4;
+
+ reg [15:0] aluLatch;
+ reg [4:0] pswCcr;
+ reg [4:0] ccrCore;
+
+ logic [15:0] result;
+ logic [4:0] ccrTemp;
+ reg coreH; // half carry latch
+
+ logic [15:0] subResult;
+ logic subHcarry;
+ logic subCout, subOv;
+
+ assign aluOut = aluLatch;
+ assign ze = ~ccrCore[ ZF]; // Check polarity !!!
+
+ //
+ // Control
+ // Signals derived from IRD *must* be registered on either T3 or T4
+ // Signals derived from nano rom can be registered on T4.
+
+ reg [15:0] row;
+ reg isArX; // Don't set Z
+ reg noCcrEn;
+ reg isByte;
+
+ reg [4:0] ccrMask;
+ reg [4:0] oper;
+
+ logic [15:0] aOperand, dOperand;
+ wire isCorf = ( aluDataCtrl == 2'b10);
+
+ wire [15:0] cRow;
+ wire cIsArX;
+ wire cNoCcrEn;
+ rowDecoder rowDecoder( .ird( ird), .row( cRow), .noCcrEn( cNoCcrEn), .isArX( cIsArX));
+
+ // Get Operation & CCR Mask from row/col
+ // Registering them on T4 increase performance. But slowest part seems to be corf !
+ wire [4:0] cMask;
+ wire [4:0] aluOp;
+
+ aluGetOp aluGetOp( .row, .col( aluColumn), .isCorf, .aluOp);
+ ccrTable ccrTable( .col( aluColumn), .row( row), .finish, .ccrMask( cMask));
+
+ // Inefficient, uCode could help !
+ wire shftIsMul = row[7];
+ wire shftIsDiv = row[1];
+
+ wire [31:0] shftResult;
+ reg [7:0] bcdLatch;
+ reg bcdCarry, bcdOverf;
+
+ reg isLong;
+ reg rIrd8;
+ logic isShift;
+ logic shftCin, shftRight, addCin;
+
+ // Register some decoded signals
+ always_ff @( posedge clk) begin
+ if( enT3) begin
+ row <= cRow;
+ isArX <= cIsArX;
+ noCcrEn <= cNoCcrEn;
+ rIrd8 <= ird[8];
+ isByte <= aluIsByte;
+ end
+
+ if( enT4) begin
+ // Decode if long shift
+ // MUL and DIV are long (but special !)
+ isLong <= (ird[7] & ~ird[6]) | shftIsMul | shftIsDiv;
+
+ ccrMask <= cMask;
+ oper <= aluOp;
+ end
+ end
+
+
+ always_comb begin
+ // Dest (addr) operand source
+ // If aluCsr (depends on column/row) addrbus is shifted !!
+ aOperand = (aluAddrCtrl ? alub : iAddrBus);
+
+ // Second (data,source) operand mux
+ case( aluDataCtrl)
+ 2'b00: dOperand = iDataBus;
+ 2'b01: dOperand = 'h0000;
+ 2'b11: dOperand = 'hffff;
+ // 2'b10: dOperand = bcdResult;
+ 2'b10: dOperand = 'X;
+ endcase
+ end
+
+ // Execution
+
+ // shift operand MSB. Input in ASR/ROL. Carry in right.
+ // Can't be registered because uses bus operands that aren't available early !
+ wire shftMsb = isLong ? alue[15] : (isByte ? aOperand[7] : aOperand[15]);
+
+ aluShifter shifter( .data( { alue, aOperand}),
+ .swapWords( shftIsMul | shftIsDiv),
+ .cin( shftCin), .dir( shftRight), .isByte( isByte), .isLong( isLong),
+ .result( shftResult));
+
+ wire [7:0] bcdResult;
+ wire bcdC, bcdV;
+ aluCorf aluCorf( .binResult( aluLatch[7:0]), .hCarry( coreH),
+ .bAdd( (oper != OP_SBCD) ), .cin( pswCcr[ XF]),
+ .bcdResult( bcdResult), .dC( bcdC), .ov( bcdV));
+
+ // BCD adjust is among the slowest processing on ALU !
+ // Precompute and register BCD result on T1
+ // We don't need to wait for execution buses because corf is always added to ALU previous result
+ always_ff @( posedge clk)
+ if( enT1) begin
+ bcdLatch <= bcdResult;
+ bcdCarry <= bcdC;
+ bcdOverf <= bcdV;
+ end
+
+ // Adder carry in selector
+ always_comb
+ begin
+ case( oper)
+ OP_ADD, OP_SUB: addCin = 1'b0;
+ OP_SUB0: addCin = 1'b1; // NOT = 0 - op - 1
+ OP_ADDC,OP_SUBC: addCin = ccrCore[ CF];
+ OP_ADDX,OP_SUBX: addCin = pswCcr[ XF];
+ default: addCin = 1'bX;
+ endcase
+ end
+
+ // Shifter carry in and direction selector
+ always_comb begin
+ case( oper)
+ OP_LSL, OP_ASL, OP_ROL, OP_ROXL, OP_SLAA: shftRight = 1'b0;
+ OP_LSR, OP_ASR, OP_ROR, OP_ROXR: shftRight = 1'b1;
+ default: shftRight = 1'bX;
+ endcase
+
+ case( oper)
+ OP_LSR,
+ OP_ASL,
+ OP_LSL: shftCin = 1'b0;
+ OP_ROL,
+ OP_ASR: shftCin = shftMsb;
+ OP_ROR: shftCin = aOperand[0];
+ OP_ROXL,
+ OP_ROXR:
+ if( shftIsMul)
+ shftCin = rIrd8 ? pswCcr[NF] ^ pswCcr[VF] : pswCcr[ CF];
+ else
+ shftCin = pswCcr[ XF];
+
+ OP_SLAA: shftCin = aluColumn[1]; // col4 -> 0, col 6-> 1
+ default: shftCin = 'X;
+ endcase
+ end
+
+ // ALU operation selector
+ always_comb begin
+
+ // sub is DATA - ADDR
+ mySubber( aOperand, dOperand, addCin,
+ (oper == OP_ADD) | (oper == OP_ADDC) | (oper == OP_ADDX),
+ isByte, subResult, subCout, subOv);
+
+ isShift = 1'b0;
+ case( oper)
+ OP_AND: result = aOperand & dOperand;
+ OP_OR: result = aOperand | dOperand;
+ OP_EOR: result = aOperand ^ dOperand;
+
+ OP_EXT: result = { {8{aOperand[7]}}, aOperand[7:0]};
+
+ OP_SLAA,
+ OP_ASL, OP_ASR,
+ OP_LSL, OP_LSR,
+ OP_ROL, OP_ROR,
+ OP_ROXL, OP_ROXR:
+ begin
+ result = shftResult[15:0];
+ isShift = 1'b1;
+ end
+
+ OP_ADD,
+ OP_ADDC,
+ OP_ADDX,
+ OP_SUB,
+ OP_SUBC,
+ OP_SUB0,
+ OP_SUBX: result = subResult;
+
+ OP_ABCD,
+ OP_SBCD: result = { 8'hXX, bcdLatch};
+
+ default: result = 'X;
+ endcase
+ end
+
+ task mySubber;
+ input [15:0] inpa, inpb;
+ input cin, bAdd, isByte;
+ output reg [15:0] result;
+ output cout, ov;
+
+ // Not very efficient!
+ logic [16:0] rtemp;
+ logic rm,sm,dm,tsm;
+
+ begin
+ if( isByte)
+ begin
+ rtemp = bAdd ? { 1'b0, inpb[7:0]} + { 1'b0, inpa[7:0]} + cin:
+ { 1'b0, inpb[7:0] } - { 1'b0, inpa[7:0]} - cin;
+ result = { {8{ rtemp[7]}}, rtemp[7:0]};
+ cout = rtemp[8];
+ end
+ else begin
+ rtemp = bAdd ? { 1'b0, inpb } + { 1'b0, inpa} + cin:
+ { 1'b0, inpb } - { 1'b0, inpa} - cin;
+ result = rtemp[ 15:0];
+ cout = rtemp[16];
+ end
+
+ rm = isByte ? rtemp[7] : rtemp[15];
+ dm = isByte ? inpb[ 7] : inpb[ 15];
+ tsm = isByte ? inpa[ 7] : inpa[ 15];
+ sm = bAdd ? tsm : ~tsm;
+
+ ov = (sm & dm & ~rm) | (~sm & ~dm & rm);
+
+ // Store half carry for bcd correction
+ subHcarry = inpa[4] ^ inpb[4] ^ rtemp[4];
+
+ end
+ endtask
+
+
+ // CCR flags process
+ always_comb begin
+
+ ccrTemp[XF] = pswCcr[XF]; ccrTemp[CF] = 0; ccrTemp[VF] = 0;
+
+ // Not on all operators
+ ccrTemp[ ZF] = isByte ? ~(| result[7:0]) : ~(| result);
+ ccrTemp[ NF] = isByte ? result[7] : result[15];
+
+ unique case( oper)
+
+ OP_EXT:
+ // Division overflow.
+ if( aluColumn == 5) begin
+ ccrTemp[VF] = 1'b1;
+ ccrTemp[NF] = 1'b1; ccrTemp[ ZF] = 1'b0;
+ end
+
+ OP_SUB0, // used by NOT
+ OP_OR,
+ OP_EOR:
+ begin
+ ccrTemp[CF] = 0; ccrTemp[VF] = 0;
+ end
+
+ OP_AND:
+ begin
+ // ROXL/ROXR indeed copy X to C in column 1 (OP_AND), executed before entering the loop.
+ // Needed when rotate count is zero, the ucode with the ROX operator never reached.
+ // C must be set to the value of X, X remains unaffected.
+ if( (aluColumn == 1) & (row[11] | row[8]))
+ ccrTemp[CF] = pswCcr[XF];
+ else
+ ccrTemp[CF] = 0;
+ ccrTemp[VF] = 0;
+ end
+
+ // Assumes col 3 of DIV use C and not X !
+ // V will be set in other cols (2/3) of DIV
+ OP_SLAA: ccrTemp[ CF] = aOperand[15];
+
+ OP_LSL,OP_ROXL:
+ begin
+ ccrTemp[ CF] = shftMsb;
+ ccrTemp[ XF] = shftMsb;
+ ccrTemp[ VF] = 1'b0;
+ end
+
+ OP_LSR,OP_ROXR:
+ begin
+ // 0 Needed for mul, or carry gets in high word
+ ccrTemp[ CF] = shftIsMul ? 1'b0 : aOperand[0];
+ ccrTemp[ XF] = aOperand[0];
+ // Not relevant for MUL, we clear it at mulm6 (1f) anyway.
+ // Not that MUL can never overlow!
+ ccrTemp[ VF] = 0;
+ // Z is checking here ALU (low result is actually in ALUE).
+ // But it is correct, see comment above.
+ end
+
+ OP_ASL:
+ begin
+ ccrTemp[ XF] = shftMsb; ccrTemp[ CF] = shftMsb;
+ // V set if msb changed on any shift.
+ // Otherwise clear previously on OP_AND (col 1i).
+ ccrTemp[ VF] = pswCcr[VF] | (shftMsb ^
+ (isLong ? alue[15-1] : (isByte ? aOperand[7-1] : aOperand[15-1])) );
+ end
+ OP_ASR:
+ begin
+ ccrTemp[ XF] = aOperand[0]; ccrTemp[ CF] = aOperand[0];
+ ccrTemp[ VF] = 0;
+ end
+
+ // X not changed on ROL/ROR !
+ OP_ROL: ccrTemp[ CF] = shftMsb;
+ OP_ROR: ccrTemp[ CF] = aOperand[0];
+
+ OP_ADD,
+ OP_ADDC,
+ OP_ADDX,
+ OP_SUB,
+ OP_SUBC,
+ OP_SUBX:
+ begin
+ ccrTemp[ CF] = subCout;
+ ccrTemp[ XF] = subCout;
+ ccrTemp[ VF] = subOv;
+ end
+
+ OP_ABCD,
+ OP_SBCD:
+ begin
+ ccrTemp[ XF] = bcdCarry;
+ ccrTemp[ CF] = bcdCarry;
+ ccrTemp[ VF] = bcdOverf;
+ end
+
+ endcase
+
+ end
+
+ // Core and psw latched at the same cycle
+
+ // CCR filter
+ // CCR out mux for Z & C flags
+ // Z flag for 32-bit result
+ // Not described, but should be used also for instructions
+ // that clear but not set Z (ADDX/SUBX/ABCD, etc)!
+ logic [4:0] ccrMasked;
+ always_comb begin
+ ccrMasked = (ccrTemp & ccrMask) | (pswCcr & ~ccrMask);
+ // if( finish | isCorf | isArX) // No need to check specicially for isCorf as they always have the "finish" flag anyway
+ if( finish | isArX)
+ ccrMasked[ ZF] = ccrTemp[ ZF] & pswCcr[ ZF];
+ end
+
+ always_ff @( posedge clk) begin
+ if( enT3) begin
+ // Update latches from ALU operators
+ if( (| aluColumn)) begin
+ aluLatch <= result;
+
+ coreH <= subHcarry;
+
+ // Update CCR core
+ if( (| aluColumn))
+ ccrCore <= ccrTemp; // Most bits not really used
+ end
+
+ if( alueClkEn)
+ alue <= iDataBus;
+ else if( isShift & (| aluColumn))
+ alue <= shftResult[31:16];
+ end
+
+ // CCR
+ // Originally on T3-T4 edge pulse !!
+ // Might be possible to update on T4 (but not after T0) from partial result registered on T3, it will increase performance!
+ if( pwrUp)
+ pswCcr <= '0;
+ else if( enT3 & ftu2Ccr)
+ pswCcr <= ftu[4:0];
+ else if( enT3 & ~noCcrEn & (finish | init))
+ pswCcr <= ccrMasked;
+ end
+ assign ccr = { 3'b0, pswCcr};
+
+
+endmodule
+
+// add bcd correction factor
+// It would be more efficient to merge add/sub with main ALU !!!
+module aluCorf( input [7:0] binResult, input bAdd, input cin, input hCarry,
+ output [7:0] bcdResult, output dC, output logic ov);
+
+ reg [8:0] htemp;
+ reg [4:0] hNib;
+
+ wire lowC = hCarry | (bAdd ? gt9( binResult[ 3:0]) : 1'b0);
+ wire highC = cin | (bAdd ? (gt9( htemp[7:4]) | htemp[8]) : 1'b0);
+
+ always_comb begin
+ if( bAdd) begin
+ htemp = { 1'b0, binResult} + (lowC ? 4'h6 : 4'h0);
+ hNib = htemp[8:4] + (highC ? 4'h6 : 4'h0);
+ ov = hNib[3] & ~binResult[7];
+ end
+ else begin
+ htemp = { 1'b0, binResult} - (lowC ? 4'h6 : 4'h0);
+ hNib = htemp[8:4] - (highC ? 4'h6 : 4'h0);
+ ov = ~hNib[3] & binResult[7];
+ end
+ end
+
+ assign bcdResult = { hNib[ 3:0], htemp[3:0]};
+ assign dC = hNib[4] | cin;
+
+ // Nibble > 9
+ function gt9 (input [3:0] nib);
+ begin
+ gt9 = nib[3] & (nib[2] | nib[1]);
+ end
+ endfunction
+
+endmodule
+
+
+module aluShifter( input [31:0] data,
+ input isByte, input isLong, swapWords,
+ input dir, input cin,
+ output logic [31:0] result);
+ // output reg cout
+
+ logic [31:0] tdata;
+
+ // size mux, put cin in position if dir == right
+ always_comb begin
+ tdata = data;
+ if( isByte & dir)
+ tdata[8] = cin;
+ else if( !isLong & dir)
+ tdata[16] = cin;
+ end
+
+ always_comb begin
+ // Reverse alu/alue position for MUL & DIV
+ // Result reversed again
+ if( swapWords & dir)
+ result = { tdata[0], tdata[31:17], cin, tdata[15:1]};
+ else if( swapWords)
+ result = { tdata[30:16], cin, tdata[14:0], tdata[31]};
+
+ else if( dir)
+ result = { cin, tdata[31:1]};
+ else
+ result = { tdata[30:0], cin};
+ end
+
+endmodule
+
+
+// Get current OP from row & col
+module aluGetOp( input [15:0] row, input [2:0] col, input isCorf,
+ output logic [4:0] aluOp);
+
+ always_comb begin
+ aluOp = 'X;
+ unique case( col)
+ 1: aluOp = OP_AND;
+ 5: aluOp = OP_EXT;
+
+ default:
+ unique case( 1'b1)
+ row[1]:
+ unique case( col)
+ 2: aluOp = OP_SUB;
+ 3: aluOp = OP_SUBC;
+ 4,6: aluOp = OP_SLAA;
+ endcase
+
+ row[2]:
+ unique case( col)
+ 2: aluOp = OP_ADD;
+ 3: aluOp = OP_ADDC;
+ 4: aluOp = OP_ASR;
+ endcase
+
+ row[3]:
+ unique case( col)
+ 2: aluOp = OP_ADDX;
+ 3: aluOp = isCorf ? OP_ABCD : OP_ADD;
+ 4: aluOp = OP_ASL;
+ endcase
+
+ row[4]:
+ aluOp = ( col == 4) ? OP_LSL : OP_AND;
+
+ row[5],
+ row[6]:
+ unique case( col)
+ 2: aluOp = OP_SUB;
+ 3: aluOp = OP_SUBC;
+ 4: aluOp = OP_LSR;
+ endcase
+
+ row[7]: // MUL
+ unique case( col)
+ 2: aluOp = OP_SUB;
+ 3: aluOp = OP_ADD;
+ 4: aluOp = OP_ROXR;
+ endcase
+
+ row[8]:
+ // OP_AND For EXT.L
+ // But would be more efficient to change ucode and use column 1 instead of col3 at ublock extr1!
+ unique case( col)
+ 2: aluOp = OP_EXT;
+ 3: aluOp = OP_AND;
+ 4: aluOp = OP_ROXR;
+ endcase
+
+ row[9]:
+ unique case( col)
+ 2: aluOp = OP_SUBX;
+ 3: aluOp = OP_SBCD;
+ 4: aluOp = OP_ROL;
+ endcase
+
+ row[10]:
+ unique case( col)
+ 2: aluOp = OP_SUBX;
+ 3: aluOp = OP_SUBC;
+ 4: aluOp = OP_ROR;
+ endcase
+
+ row[11]:
+ unique case( col)
+ 2: aluOp = OP_SUB0;
+ 3: aluOp = OP_SUB0;
+ 4: aluOp = OP_ROXL;
+ endcase
+
+ row[12]: aluOp = OP_ADDX;
+ row[13]: aluOp = OP_EOR;
+ row[14]: aluOp = (col == 4) ? OP_EOR : OP_OR;
+ row[15]: aluOp = (col == 3) ? OP_ADD : OP_OR; // OP_ADD used by DBcc
+
+ endcase
+ endcase
+ end
+endmodule
+
+// Decodes IRD into ALU row (1-15)
+// Slow, but no need to optimize for speed since IRD is latched at least two CPU cycles before it is used
+// We also register the result after combining with column from nanocode
+//
+// Many opcodes are not decoded because they either don't do any ALU op,
+// or use only columns 1 and 5 that are the same for all rows.
+
+module rowDecoder( input [15:0] ird,
+ output logic [15:0] row, output noCcrEn, output logic isArX);
+
+
+ // Addr or data register direct
+ wire eaRdir = (ird[ 5:4] == 2'b00);
+ // Addr register direct
+ wire eaAdir = (ird[ 5:3] == 3'b001);
+ wire size11 = ird[7] & ird[6];
+
+ always_comb begin
+ case( ird[15:12])
+ 'h4,
+ 'h9,
+ 'hd:
+ isArX = row[10] | row[12];
+ default:
+ isArX = 1'b0;
+ endcase
+ end
+
+ always_comb begin
+ unique case( ird[15:12])
+
+ 'h4: begin
+ if( ird[8])
+ row = `ALU_ROW_06; // chk (or lea)
+ else case( ird[11:9])
+ 'b000: row = `ALU_ROW_10; // negx
+ 'b001: row = `ALU_ROW_04; // clr
+ 'b010: row = `ALU_ROW_05; // neg
+ 'b011: row = `ALU_ROW_11; // not
+ 'b100: row = (ird[7]) ? `ALU_ROW_08 : `ALU_ROW_09; // nbcd/swap/ext(or pea)
+ 'b101: row = `ALU_ROW_15; // tst & tas
+ default: row = 0;
+ endcase
+ end
+
+ 'h0: begin
+ if( ird[8]) // dynamic bit
+ row = ird[7] ? `ALU_ROW_14 : `ALU_ROW_13;
+ else case( ird[ 11:9])
+ 'b000: row = `ALU_ROW_14; // ori
+ 'b001: row = `ALU_ROW_04; // andi
+ 'b010: row = `ALU_ROW_05; // subi
+ 'b011: row = `ALU_ROW_02; // addi
+ 'b100: row = ird[7] ? `ALU_ROW_14 : `ALU_ROW_13; // static bit
+ 'b101: row = `ALU_ROW_13; // eori
+ 'b110: row = `ALU_ROW_06; // cmpi
+ default: row = 0;
+ endcase
+ end
+
+ // MOVE
+ // move.b originally also rows 5 & 15. Only because IRD bit 14 is not decoded.
+ // It's the same for move the operations performed by MOVE.B
+
+ 'h1,'h2,'h3: row = `ALU_ROW_02;
+
+ 'h5:
+ if( size11)
+ row = `ALU_ROW_15; // As originally and easier to decode
+ else
+ row = ird[8] ? `ALU_ROW_05 : `ALU_ROW_02; // addq/subq
+ 'h6: row = 0; //bcc/bra/bsr
+ 'h7: row = `ALU_ROW_02; // moveq
+ 'h8:
+ if( size11) // div
+ row = `ALU_ROW_01;
+ else if( ird[8] & eaRdir) // sbcd
+ row = `ALU_ROW_09;
+ else
+ row = `ALU_ROW_14; // or
+ 'h9:
+ if( ird[8] & ~size11 & eaRdir)
+ row = `ALU_ROW_10; // subx
+ else
+ row = `ALU_ROW_05; // sub/suba
+ 'hb:
+ if( ird[8] & ~size11 & ~eaAdir)
+ row = `ALU_ROW_13; // eor
+ else
+ row = `ALU_ROW_06; // cmp/cmpa/cmpm
+ 'hc:
+ if( size11)
+ row = `ALU_ROW_07; // mul
+ else if( ird[8] & eaRdir) // abcd
+ row = `ALU_ROW_03;
+ else
+ row = `ALU_ROW_04; // and
+ 'hd:
+ if( ird[8] & ~size11 & eaRdir)
+ row = `ALU_ROW_12; // addx
+ else
+ row = `ALU_ROW_02; // add/adda
+ 'he:
+ begin
+ reg [1:0] stype;
+
+ if( size11) // memory shift/rotate
+ stype = ird[ 10:9];
+ else // register shift/rotate
+ stype = ird[ 4:3];
+
+ case( {stype, ird[8]})
+ 0: row = `ALU_ROW_02; // ASR
+ 1: row = `ALU_ROW_03; // ASL
+ 2: row = `ALU_ROW_05; // LSR
+ 3: row = `ALU_ROW_04; // LSL
+ 4: row = `ALU_ROW_08; // ROXR
+ 5: row = `ALU_ROW_11; // ROXL
+ 6: row = `ALU_ROW_10; // ROR
+ 7: row = `ALU_ROW_09; // ROL
+ endcase
+ end
+
+ default: row = 0;
+ endcase
+ end
+
+ // Decode opcodes that don't affect flags
+ // ADDA/SUBA ADDQ/SUBQ MOVEA
+
+ assign noCcrEn =
+ // ADDA/SUBA
+ ( ird[15] & ~ird[13] & ird[12] & size11) |
+ // ADDQ/SUBQ to An
+ ( (ird[15:12] == 4'h5) & eaAdir) |
+ // MOVEA
+ ( (~ird[15] & ~ird[14] & ird[13]) & ird[8:6] == 3'b001);
+
+endmodule
+
+// Row/col CCR update table
+module ccrTable(
+ input [2:0] col, input [15:0] row, input finish,
+ output logic [MASK_NBITS-1:0] ccrMask);
+
+ localparam
+ KNZ00 = 5'b01111, // ok coz operators clear them
+ KKZKK = 5'b00100,
+ KNZKK = 5'b01100,
+ KNZ10 = 5'b01111, // Used by OP_EXT on divison overflow
+ KNZ0C = 5'b01111, // Used by DIV. V should be 0, but it is ok:
+ // DIVU: ends with quotient - 0, so V & C always clear.
+ // DIVS: ends with 1i (AND), again, V & C always clear.
+
+ KNZVC = 5'b01111,
+ XNKVC = 5'b11011, // Used by BCD instructions. Don't modify Z at all at the binary operation. Only at the BCD correction cycle
+
+ CUPDALL = 5'b11111,
+ CUNUSED = 5'bxxxxx;
+
+
+ logic [MASK_NBITS-1:0] ccrMask1;
+
+ always_comb begin
+ unique case( col)
+ 1: ccrMask = ccrMask1;
+
+ 2,3:
+ unique case( 1'b1)
+ row[1]: ccrMask = KNZ0C; // DIV, used as 3n in col3
+
+ row[3], // ABCD
+ row[9]: // SBCD/NBCD
+ ccrMask = (col == 2) ? XNKVC : CUPDALL;
+
+ row[2],
+ row[5],
+ row[10], // SUBX/NEGX
+ row[12]: ccrMask = CUPDALL; // ADDX
+
+ row[6], // CMP
+ row[7], // MUL
+ row[11]: ccrMask = KNZVC; // NOT
+ row[4],
+ row[8], // Not used in col 3
+ row[13],
+ row[14]: ccrMask = KNZ00;
+ row[15]: ccrMask = 5'b0; // TAS/Scc, not used in col 3
+ // default: ccrMask = CUNUSED;
+ endcase
+
+ 4:
+ unique case( row)
+ // 1: DIV, only n (4n & 6n)
+ // 14: BCLR 4n
+ // 6,12,13,15 // not used
+ `ALU_ROW_02,
+ `ALU_ROW_03, // ASL (originally ANZVA)
+ `ALU_ROW_04,
+ `ALU_ROW_05: ccrMask = CUPDALL; // Shifts (originally ANZ0A)
+
+ `ALU_ROW_07: ccrMask = KNZ00; // MUL (originally KNZ0A)
+ `ALU_ROW_09,
+ `ALU_ROW_10: ccrMask = KNZ00; // RO[lr] (originally KNZ0A)
+ `ALU_ROW_08, // ROXR (originally ANZ0A)
+ `ALU_ROW_11: ccrMask = CUPDALL; // ROXL (originally ANZ0A)
+ default: ccrMask = CUNUSED;
+ endcase
+
+ 5: ccrMask = row[1] ? KNZ10 : 5'b0;
+ default: ccrMask = CUNUSED;
+ endcase
+ end
+
+ // Column 1 (AND)
+ always_comb begin
+ if( finish)
+ ccrMask1 = row[7] ? KNZ00 : KNZKK;
+ else
+ ccrMask1 = row[13] | row[14] ? KKZKK : KNZ00;
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/uaddrPla.sv b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/uaddrPla.sv
new file mode 100644
index 0000000000000000000000000000000000000000..3be2f74d6d351fc52477ee4006942a31c89325d5
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/FX68K/uaddrPla.sv
@@ -0,0 +1,2195 @@
+//
+// FX68K
+//
+// Opcode to uaddr entry routines (A2-A2-A3) PLA
+//
+
+// altera message_off 10230
+
+
+`timescale 1 ns / 1 ns
+
+`define NMA_BITS 10
+
+`define SFTM1 'h3C7
+`define SRRW1 'h382
+`define SRIW1 'h381
+`define SRRL1 'h386
+`define SRIL1 'h385
+`define BSRI1 'h089
+`define BSRW1 'h0A9
+`define BBCI1 'h308
+`define BBCW1 'h068
+`define RLQL1 'h23B
+`define ADRW1 'h006
+`define PINW1 'h21C
+`define PDCW1 'h103
+`define ADSW1 'h1C2
+`define AIXW0 'h1E3
+`define ABWW1 'h00A
+`define ABLW1 'h1E2
+`define TRAP1 'h1D0
+`define LINK1 'h30B
+`define UNLK1 'h119
+`define LUSP1 'h2F5
+`define SUSP1 'h230
+`define TRPV1 'h06D
+`define RSET1 'h3A6
+`define B 'h363
+`define STOP1 'h3A2
+`define RTR1 'h12A
+`define RTS1 'h126
+
+
+module pla_lined(
+ input [3:0] movEa,
+ input [3:0] col,
+
+ input [15:0] opcode,
+ input [15:0] lineBmap,
+
+ output palIll,
+ output logic [`NMA_BITS-1:0] plaA1,
+ output logic [`NMA_BITS-1:0] plaA2,
+ output logic [`NMA_BITS-1:0] plaA3
+ );
+
+ wire [3:0] line = opcode[ 15:12];
+ wire [2:0] row86 = opcode[8:6];
+
+ logic [15:0] arIll;
+ logic [`NMA_BITS-1:0] arA1[ 15:0];
+ logic [`NMA_BITS-1:0] arA23[ 15:0];
+ logic [`NMA_BITS-1:0] scA3;
+
+ logic illMisc;
+ logic [`NMA_BITS-1:0] a1Misc;
+
+ /*
+ reg [`NMA_BITS-1:0] lineMask[ 15:0];
+ always_comb begin
+ integer i;
+ for( i = 0; i < 16; i = i + 1)
+ lineMask[i] = { 16{lineBmap[ i]}};
+ end
+ */
+
+ assign palIll = (| (arIll & lineBmap));
+
+ // Only line 0 has 3 subs
+ assign plaA1 = arA1[ line];
+ assign plaA2 = arA23[ line];
+ assign plaA3 = lineBmap[0] ? scA3 : arA23[ line];
+
+
+ // Simple lines
+ always_comb begin
+ // Line 6: Branch
+ arIll[ 'h6] = 1'b0;
+ arA23[ 'h6] = 'X;
+ if( opcode[ 11:8] == 4'h1)
+ arA1[ 'h6] = (| opcode[7:0]) ? `BSRI1 : `BSRW1;
+ else
+ arA1[ 'h6] = (| opcode[7:0]) ? `BBCI1 : `BBCW1;
+
+ // Line 7: moveq
+ arIll[ 'h7] = opcode[ 8];
+ arA23[ 'h7] = 'X;
+ arA1[ 'h7] = `RLQL1;
+
+ // Line A & F
+ arIll[ 'ha] = 1'b1; arIll[ 'hf] = 1'b1;
+ arA1[ 'ha] = 'X; arA1[ 'hf] = 'X;
+ arA23[ 'ha] = 'X; arA23[ 'hf] = 'X;
+
+ end
+
+ // Special lines
+
+ // Line e: shifts
+ always_comb begin
+ if( ~opcode[11] & opcode[7] & opcode[6])
+ begin
+ arA23[ 'he] = `SFTM1;
+ unique case( col)
+ 2: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `ADRW1; end
+ 3: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `PINW1; end
+ 4: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `PDCW1; end
+ 5: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `ADSW1; end
+ 6: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `AIXW0; end
+ 7: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `ABWW1; end
+ 8: begin arIll[ 'he] = 1'b0; arA1[ 'he] = `ABLW1; end
+ default: begin arIll[ 'he] = 1'b1; arA1[ 'he] = 'X; end
+ endcase
+ end
+ else
+ begin
+ arA23[ 'he] = 'X;
+ unique case( opcode[ 7:6])
+ 2'b00,
+ 2'b01: begin
+ arIll[ 'he] = 1'b0;
+ arA1[ 'he] = opcode[ 5] ? `SRRW1 : `SRIW1;
+ end
+ 2'b10: begin
+ arIll[ 'he] = 1'b0;
+ arA1[ 'he] = opcode[ 5] ? `SRRL1 : `SRIL1;
+ end
+ 2'b11: begin arIll[ 'he] = 1'b1; arA1[ 'he] = 'X; end
+ endcase
+ end
+ end
+
+ // Misc. line 4 row
+ always_comb begin
+ illMisc = 1'b0;
+ case( opcode[ 5:3])
+ 3'b000,
+ 3'b001: a1Misc = `TRAP1;
+ 3'b010: a1Misc = `LINK1;
+ 3'b011: a1Misc = `UNLK1;
+ 3'b100: a1Misc = `LUSP1;
+ 3'b101: a1Misc = `SUSP1;
+
+ 3'b110:
+ case( opcode[ 2:0])
+ 3'b110: a1Misc = `TRPV1;
+ 3'b000: a1Misc = `RSET1;
+ 3'b001: a1Misc = `B;
+ 3'b010: a1Misc = `STOP1;
+ 3'b011: a1Misc = `RTR1;
+ 3'b111: a1Misc = `RTR1;
+ 3'b101: a1Misc = `RTS1;
+ default: begin illMisc = 1'b1; a1Misc = 'X; end
+ endcase
+
+ default: begin illMisc = 1'b1; a1Misc = 'X; end
+ endcase
+ end
+
+//
+// Past here
+//
+
+
+//
+// Line: 0
+//
+always_comb begin
+
+if( (opcode[11:6] & 'h1F) == 'h8) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1CC; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h0) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1CC; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h1F) == 'h9) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1CC; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h1) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1CC; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h1F) == 'hA) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h10C; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00B; scA3 = 'h29D; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00F; scA3 = 'h29D; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h179; scA3 = 'h29D; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1C6; scA3 = 'h29D; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E7; scA3 = 'h29D; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00E; scA3 = 'h29D; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E6; scA3 = 'h29D; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h2) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h10C; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00B; scA3 = 'h29D; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00F; scA3 = 'h29D; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h179; scA3 = 'h29D; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1C6; scA3 = 'h29D; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E7; scA3 = 'h29D; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00E; scA3 = 'h29D; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E6; scA3 = 'h29D; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h10) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h11) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h100; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h299; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h299; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h299; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h299; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h299; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h299; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h299; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h37) == 'h12) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h10C; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00B; scA3 = 'h29D; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00F; scA3 = 'h29D; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h179; scA3 = 'h29D; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1C6; scA3 = 'h29D; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E7; scA3 = 'h29D; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00E; scA3 = 'h29D; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E6; scA3 = 'h29D; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h4) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E7; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1D2; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h006; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h21C; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h103; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1C2; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E3; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h00A; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E2; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 9: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1C2; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 10: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E3; arA23[ 'h0] = 'X; scA3 = 'h215; end
+ 11: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h0EA; arA23[ 'h0] = 'h0AB; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h5) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3EF; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1D6; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h006; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h21C; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h103; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1C2; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E3; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h00A; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E2; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h7) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3EF; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1CE; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h006; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h21C; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h103; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1C2; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E3; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h00A; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E2; arA23[ 'h0] = 'X; scA3 = 'h081; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h6) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3EB; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1CA; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h006; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h21C; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h103; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1C2; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E3; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h00A; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h1E2; arA23[ 'h0] = 'X; scA3 = 'h069; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h20) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h3E7; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h215; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h215; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h215; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h215; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h215; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h215; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h215; end
+ 9: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h215; end
+ 10: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h215; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h21) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h3EF; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h081; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h081; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h081; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h081; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h081; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h081; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h081; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h23) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h3EF; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h081; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h081; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h081; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h081; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h081; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h081; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h081; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h22) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h3EB; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h069; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h069; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h069; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h069; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h069; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h069; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h069; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h30) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h108; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h087; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h087; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h087; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h087; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h087; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h087; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h087; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h31) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h108; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h006; scA3 = 'h087; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h21C; scA3 = 'h087; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h103; scA3 = 'h087; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1C2; scA3 = 'h087; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E3; scA3 = 'h087; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h00A; scA3 = 'h087; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h2B9; arA23[ 'h0] = 'h1E2; scA3 = 'h087; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h32) begin
+ unique case ( col)
+ 0: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h104; scA3 = 'X; end
+ 1: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 2: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00B; scA3 = 'h08F; end
+ 3: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00F; scA3 = 'h08F; end
+ 4: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h179; scA3 = 'h08F; end
+ 5: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1C6; scA3 = 'h08F; end
+ 6: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E7; scA3 = 'h08F; end
+ 7: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h00E; scA3 = 'h08F; end
+ 8: begin arIll[ 'h0] = 1'b0; arA1[ 'h0] = 'h3E0; arA23[ 'h0] = 'h1E6; scA3 = 'h08F; end
+ 9: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 10: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ 11: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ default: begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+ endcase
+end
+
+else begin arIll[ 'h0] = 1'b1; arA1[ 'h0] = 'X ; arA23[ 'h0] = 'X; scA3 = 'X; end
+
+end
+
+
+//
+// Line: 4
+//
+always_comb begin
+
+if( (opcode[11:6] & 'h27) == 'h0) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h133; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h2B8; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h2B8; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h2B8; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h2B8; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h2B8; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h2B8; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h2B8; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h27) == 'h1) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h133; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h2B8; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h2B8; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h2B8; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h2B8; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h2B8; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h2B8; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h2B8; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h27) == 'h2) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h137; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00B; arA23[ 'h4] = 'h2BC; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00F; arA23[ 'h4] = 'h2BC; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h179; arA23[ 'h4] = 'h2BC; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C6; arA23[ 'h4] = 'h2BC; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E7; arA23[ 'h4] = 'h2BC; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00E; arA23[ 'h4] = 'h2BC; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E6; arA23[ 'h4] = 'h2BC; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h3) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3A5; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h3A1; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h3A1; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h3A1; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h3A1; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h3A1; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h3A1; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h3A1; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h13) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h301; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h159; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h159; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h159; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h159; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h159; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h159; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h159; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h159; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h159; end
+ 11: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h0EA; arA23[ 'h4] = 'h301; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h1B) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h301; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h159; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h159; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h159; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h159; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h159; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h159; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h159; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h159; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h159; end
+ 11: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h0EA; arA23[ 'h4] = 'h301; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h20) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h13B; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h15C; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h15C; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h15C; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h15C; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h15C; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h15C; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h15C; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h21) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h341; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h17C; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h17D; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FF; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h178; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FA; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h17D; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FF; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h22) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h133; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3A0; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3A4; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F1; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h325; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1ED; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E5; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h23) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h232; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3A0; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3A4; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F1; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h325; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1ED; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E5; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h28) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h12D; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h3C3; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h3C3; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h3C3; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h3C3; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h3C3; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h3C3; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h3C3; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h29) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h12D; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h3C3; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h3C3; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h3C3; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h3C3; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h3C3; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h3C3; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h3C3; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h2A) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h125; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00B; arA23[ 'h4] = 'h3CB; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00F; arA23[ 'h4] = 'h3CB; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h179; arA23[ 'h4] = 'h3CB; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C6; arA23[ 'h4] = 'h3CB; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E7; arA23[ 'h4] = 'h3CB; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00E; arA23[ 'h4] = 'h3CB; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E6; arA23[ 'h4] = 'h3CB; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h2B) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h345; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h343; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h343; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h343; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h343; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h343; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h343; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h343; end
+ 9: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h3E) == 'h32) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h127; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h123; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FD; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F5; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F9; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E9; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FD; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F5; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h6) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h152; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h006; arA23[ 'h4] = 'h151; end
+ 3: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h21C; arA23[ 'h4] = 'h151; end
+ 4: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h103; arA23[ 'h4] = 'h151; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h151; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h151; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h00A; arA23[ 'h4] = 'h151; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E2; arA23[ 'h4] = 'h151; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1C2; arA23[ 'h4] = 'h151; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1E3; arA23[ 'h4] = 'h151; end
+ 11: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h0EA; arA23[ 'h4] = 'h152; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( (opcode[11:6] & 'h7) == 'h7) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2F1; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2F2; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FB; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h275; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h3E4; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2F2; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1FB; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h3A) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h273; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2B0; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F3; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h293; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F2; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2B0; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F3; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h3B) begin
+ unique case ( col)
+ 0: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 1: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 2: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h255; arA23[ 'h4] = 'X; end
+ 3: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 4: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ 5: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2B4; arA23[ 'h4] = 'X; end
+ 6: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F7; arA23[ 'h4] = 'X; end
+ 7: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h297; arA23[ 'h4] = 'X; end
+ 8: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F6; arA23[ 'h4] = 'X; end
+ 9: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h2B4; arA23[ 'h4] = 'X; end
+ 10: begin arIll[ 'h4] = 1'b0; arA1[ 'h4] = 'h1F7; arA23[ 'h4] = 'X; end
+ 11: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ default: begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+ endcase
+end
+
+else if( opcode[11:6] == 'h39) begin
+ arIll[ 'h4] = illMisc; arA1[ 'h4] = a1Misc ; arA23[ 'h4] = 'X;
+end
+
+else begin arIll[ 'h4] = 1'b1; arA1[ 'h4] = 'X ; arA23[ 'h4] = 'X; end
+
+end
+
+always_comb begin
+
+//
+// Line: 1
+//
+unique case( movEa)
+
+0: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h121; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h29B; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h29B; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h29B; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h29B; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h29B; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h29B; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h29B; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h29B; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h29B; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h121; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+2: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h2FA; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h3AB; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h3AB; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h3AB; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h3AB; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h3AB; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h3AB; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h3AB; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h3AB; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h3AB; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h2FA; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+3: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h2FE; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h3AF; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h3AF; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h3AF; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h3AF; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h3AF; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h3AF; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h3AF; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h3AF; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h3AF; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h2FE; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+4: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h2F8; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h38B; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h38B; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h38B; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h38B; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h38B; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h38B; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h38B; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h38B; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h38B; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h2F8; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+5: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h2DA; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h38A; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h38A; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h38A; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h38A; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h38A; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h38A; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h38A; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h38A; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h38A; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h2DA; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+6: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1EB; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h298; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h298; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h298; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h298; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h298; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h298; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h298; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h298; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h298; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h1EB; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+7: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h2D9; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h388; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h388; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h388; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h388; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h388; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h388; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h388; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h388; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h388; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h2D9; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+
+8: // Row: 8
+ unique case ( col)
+ 0: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1EA; arA23[ 'h1] = 'X; end
+ 1: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ 2: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h006; arA23[ 'h1] = 'h32B; end
+ 3: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h21C; arA23[ 'h1] = 'h32B; end
+ 4: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h103; arA23[ 'h1] = 'h32B; end
+ 5: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h32B; end
+ 6: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h32B; end
+ 7: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h00A; arA23[ 'h1] = 'h32B; end
+ 8: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E2; arA23[ 'h1] = 'h32B; end
+ 9: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1C2; arA23[ 'h1] = 'h32B; end
+ 10: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h1E3; arA23[ 'h1] = 'h32B; end
+ 11: begin arIll[ 'h1] = 1'b0; arA1[ 'h1] = 'h0EA; arA23[ 'h1] = 'h1EA; end
+ default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+ endcase
+default: begin arIll[ 'h1] = 1'b1; arA1[ 'h1] = 'X ; arA23[ 'h1] = 'X; end
+endcase
+
+//
+// Line: 2
+//
+unique case( movEa)
+
+0: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h129; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h129; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h29F; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h29F; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h29F; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29F; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29F; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h29F; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h29F; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29F; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29F; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h129; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+1: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h129; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h129; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h29F; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h29F; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h29F; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29F; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29F; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h29F; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h29F; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29F; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29F; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h129; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+2: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2F9; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2F9; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h3A9; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h3A9; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h3A9; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h3A9; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h3A9; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h3A9; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h3A9; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h3A9; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h3A9; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h2F9; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+3: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2FD; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2FD; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h3AD; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h3AD; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h3AD; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h3AD; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h3AD; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h3AD; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h3AD; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h3AD; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h3AD; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h2FD; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+4: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2FC; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2FC; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h38F; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h38F; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h38F; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38F; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38F; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h38F; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h38F; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38F; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38F; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h2FC; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+5: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2DE; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2DE; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h38E; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h38E; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h38E; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38E; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38E; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h38E; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h38E; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38E; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38E; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h2DE; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+6: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1EF; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1EF; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h29C; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h29C; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h29C; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29C; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29C; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h29C; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h29C; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h29C; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h29C; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h1EF; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+7: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2DD; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h2DD; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h38C; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h38C; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h38C; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38C; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38C; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h38C; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h38C; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h38C; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h38C; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h2DD; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+
+8: // Row: 8
+ unique case ( col)
+ 0: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1EE; arA23[ 'h2] = 'X; end
+ 1: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1EE; arA23[ 'h2] = 'X; end
+ 2: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00B; arA23[ 'h2] = 'h30F; end
+ 3: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00F; arA23[ 'h2] = 'h30F; end
+ 4: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h179; arA23[ 'h2] = 'h30F; end
+ 5: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h30F; end
+ 6: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h30F; end
+ 7: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h00E; arA23[ 'h2] = 'h30F; end
+ 8: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E6; arA23[ 'h2] = 'h30F; end
+ 9: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1C6; arA23[ 'h2] = 'h30F; end
+ 10: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h1E7; arA23[ 'h2] = 'h30F; end
+ 11: begin arIll[ 'h2] = 1'b0; arA1[ 'h2] = 'h0A7; arA23[ 'h2] = 'h1EE; end
+ default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+ endcase
+default: begin arIll[ 'h2] = 1'b1; arA1[ 'h2] = 'X ; arA23[ 'h2] = 'X; end
+endcase
+
+//
+// Line: 3
+//
+unique case( movEa)
+
+0: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h121; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h121; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h29B; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h29B; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h29B; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h29B; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h29B; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h29B; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h29B; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h29B; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h29B; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h121; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+1: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h279; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h279; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h158; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h158; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h158; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h158; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h158; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h158; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h158; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h158; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h158; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h279; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+2: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2FA; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2FA; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h3AB; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h3AB; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h3AB; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h3AB; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h3AB; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h3AB; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h3AB; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h3AB; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h3AB; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h2FA; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+3: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2FE; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2FE; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h3AF; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h3AF; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h3AF; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h3AF; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h3AF; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h3AF; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h3AF; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h3AF; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h3AF; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h2FE; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+4: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2F8; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2F8; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h38B; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h38B; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h38B; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h38B; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h38B; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h38B; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h38B; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h38B; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h38B; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h2F8; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+5: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2DA; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2DA; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h38A; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h38A; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h38A; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h38A; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h38A; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h38A; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h38A; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h38A; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h38A; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h2DA; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+6: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1EB; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1EB; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h298; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h298; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h298; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h298; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h298; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h298; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h298; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h298; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h298; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h1EB; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+7: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2D9; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h2D9; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h388; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h388; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h388; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h388; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h388; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h388; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h388; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h388; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h388; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h2D9; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+
+8: // Row: 8
+ unique case ( col)
+ 0: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1EA; arA23[ 'h3] = 'X; end
+ 1: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1EA; arA23[ 'h3] = 'X; end
+ 2: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h006; arA23[ 'h3] = 'h32B; end
+ 3: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h21C; arA23[ 'h3] = 'h32B; end
+ 4: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h103; arA23[ 'h3] = 'h32B; end
+ 5: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h32B; end
+ 6: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h32B; end
+ 7: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h00A; arA23[ 'h3] = 'h32B; end
+ 8: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E2; arA23[ 'h3] = 'h32B; end
+ 9: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1C2; arA23[ 'h3] = 'h32B; end
+ 10: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h1E3; arA23[ 'h3] = 'h32B; end
+ 11: begin arIll[ 'h3] = 1'b0; arA1[ 'h3] = 'h0EA; arA23[ 'h3] = 'h1EA; end
+ default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+ endcase
+default: begin arIll[ 'h3] = 1'b1; arA1[ 'h3] = 'X ; arA23[ 'h3] = 'X; end
+endcase
+
+//
+// Line: 5
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2D8; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h2F3; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h2F3; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h2F3; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h2F3; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h2F3; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h2F3; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h2F3; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2D8; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h2F3; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h2F3; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h2F3; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h2F3; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h2F3; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h2F3; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h2F3; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00B; arA23[ 'h5] = 'h2F7; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00F; arA23[ 'h5] = 'h2F7; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h179; arA23[ 'h5] = 'h2F7; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C6; arA23[ 'h5] = 'h2F7; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E7; arA23[ 'h5] = 'h2F7; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00E; arA23[ 'h5] = 'h2F7; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E6; arA23[ 'h5] = 'h2F7; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h384; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h06C; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h380; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h380; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h380; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h380; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h380; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h380; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h380; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2D8; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h2F3; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h2F3; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h2F3; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h2F3; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h2F3; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h2F3; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h2F3; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2D8; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h2F3; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h2F3; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h2F3; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h2F3; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h2F3; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h2F3; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h2F3; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h2DC; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00B; arA23[ 'h5] = 'h2F7; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00F; arA23[ 'h5] = 'h2F7; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h179; arA23[ 'h5] = 'h2F7; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C6; arA23[ 'h5] = 'h2F7; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E7; arA23[ 'h5] = 'h2F7; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00E; arA23[ 'h5] = 'h2F7; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E6; arA23[ 'h5] = 'h2F7; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h384; arA23[ 'h5] = 'X; end
+ 1: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h06C; arA23[ 'h5] = 'X; end
+ 2: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h006; arA23[ 'h5] = 'h380; end
+ 3: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h21C; arA23[ 'h5] = 'h380; end
+ 4: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h103; arA23[ 'h5] = 'h380; end
+ 5: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1C2; arA23[ 'h5] = 'h380; end
+ 6: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E3; arA23[ 'h5] = 'h380; end
+ 7: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h00A; arA23[ 'h5] = 'h380; end
+ 8: begin arIll[ 'h5] = 1'b0; arA1[ 'h5] = 'h1E2; arA23[ 'h5] = 'h380; end
+ default: begin arIll[ 'h5] = 1'b1; arA1[ 'h5] = 'X ; arA23[ 'h5] = 'X; end
+ endcase
+endcase
+
+//
+// Line: 8
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C1; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h1C3; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h1C3; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h1C3; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h1C3; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h1C3; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h1C3; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h1C3; end
+ 9: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h1C3; end
+ 10: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h1C3; end
+ 11: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0EA; arA23[ 'h8] = 'h1C1; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C1; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h1C3; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h1C3; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h1C3; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h1C3; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h1C3; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h1C3; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h1C3; end
+ 9: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h1C3; end
+ 10: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h1C3; end
+ 11: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0EA; arA23[ 'h8] = 'h1C1; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C5; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00B; arA23[ 'h8] = 'h1CB; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00F; arA23[ 'h8] = 'h1CB; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h179; arA23[ 'h8] = 'h1CB; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C6; arA23[ 'h8] = 'h1CB; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E7; arA23[ 'h8] = 'h1CB; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00E; arA23[ 'h8] = 'h1CB; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E6; arA23[ 'h8] = 'h1CB; end
+ 9: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C6; arA23[ 'h8] = 'h1CB; end
+ 10: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E7; arA23[ 'h8] = 'h1CB; end
+ 11: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0A7; arA23[ 'h8] = 'h1C5; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0A6; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h0A4; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h0A4; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h0A4; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h0A4; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h0A4; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h0A4; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h0A4; end
+ 9: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h0A4; end
+ 10: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h0A4; end
+ 11: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0EA; arA23[ 'h8] = 'h0A6; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1CD; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h107; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h299; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h299; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h299; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h299; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h299; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h299; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h299; end
+ 9: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 10: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 11: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h299; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h299; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h299; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h299; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h299; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h299; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h299; end
+ 9: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 10: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 11: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00B; arA23[ 'h8] = 'h29D; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00F; arA23[ 'h8] = 'h29D; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h179; arA23[ 'h8] = 'h29D; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C6; arA23[ 'h8] = 'h29D; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E7; arA23[ 'h8] = 'h29D; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00E; arA23[ 'h8] = 'h29D; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E6; arA23[ 'h8] = 'h29D; end
+ 9: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 10: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 11: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0AE; arA23[ 'h8] = 'X; end
+ 1: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ 2: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h006; arA23[ 'h8] = 'h0AC; end
+ 3: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h21C; arA23[ 'h8] = 'h0AC; end
+ 4: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h103; arA23[ 'h8] = 'h0AC; end
+ 5: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h0AC; end
+ 6: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h0AC; end
+ 7: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h00A; arA23[ 'h8] = 'h0AC; end
+ 8: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E2; arA23[ 'h8] = 'h0AC; end
+ 9: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1C2; arA23[ 'h8] = 'h0AC; end
+ 10: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h1E3; arA23[ 'h8] = 'h0AC; end
+ 11: begin arIll[ 'h8] = 1'b0; arA1[ 'h8] = 'h0EA; arA23[ 'h8] = 'h0AE; end
+ default: begin arIll[ 'h8] = 1'b1; arA1[ 'h8] = 'X ; arA23[ 'h8] = 'X; end
+ endcase
+endcase
+
+//
+// Line: 9
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C1; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h006; arA23[ 'h9] = 'h1C3; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h21C; arA23[ 'h9] = 'h1C3; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h103; arA23[ 'h9] = 'h1C3; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C3; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C3; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00A; arA23[ 'h9] = 'h1C3; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E2; arA23[ 'h9] = 'h1C3; end
+ 9: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C3; end
+ 10: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C3; end
+ 11: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h0EA; arA23[ 'h9] = 'h1C1; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C1; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C1; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h006; arA23[ 'h9] = 'h1C3; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h21C; arA23[ 'h9] = 'h1C3; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h103; arA23[ 'h9] = 'h1C3; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C3; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C3; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00A; arA23[ 'h9] = 'h1C3; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E2; arA23[ 'h9] = 'h1C3; end
+ 9: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C3; end
+ 10: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C3; end
+ 11: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h0EA; arA23[ 'h9] = 'h1C1; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C5; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C5; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00B; arA23[ 'h9] = 'h1CB; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00F; arA23[ 'h9] = 'h1CB; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h179; arA23[ 'h9] = 'h1CB; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C6; arA23[ 'h9] = 'h1CB; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E7; arA23[ 'h9] = 'h1CB; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00E; arA23[ 'h9] = 'h1CB; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E6; arA23[ 'h9] = 'h1CB; end
+ 9: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C6; arA23[ 'h9] = 'h1CB; end
+ 10: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E7; arA23[ 'h9] = 'h1CB; end
+ 11: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h0A7; arA23[ 'h9] = 'h1C5; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C9; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C9; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h006; arA23[ 'h9] = 'h1C7; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h21C; arA23[ 'h9] = 'h1C7; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h103; arA23[ 'h9] = 'h1C7; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C7; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C7; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00A; arA23[ 'h9] = 'h1C7; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E2; arA23[ 'h9] = 'h1C7; end
+ 9: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h1C7; end
+ 10: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h1C7; end
+ 11: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h0EA; arA23[ 'h9] = 'h1C9; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C1; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h10F; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h006; arA23[ 'h9] = 'h299; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h21C; arA23[ 'h9] = 'h299; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h103; arA23[ 'h9] = 'h299; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h299; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h299; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00A; arA23[ 'h9] = 'h299; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E2; arA23[ 'h9] = 'h299; end
+ 9: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 10: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 11: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C1; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h10F; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h006; arA23[ 'h9] = 'h299; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h21C; arA23[ 'h9] = 'h299; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h103; arA23[ 'h9] = 'h299; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C2; arA23[ 'h9] = 'h299; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E3; arA23[ 'h9] = 'h299; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00A; arA23[ 'h9] = 'h299; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E2; arA23[ 'h9] = 'h299; end
+ 9: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 10: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 11: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C5; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h10B; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00B; arA23[ 'h9] = 'h29D; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00F; arA23[ 'h9] = 'h29D; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h179; arA23[ 'h9] = 'h29D; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C6; arA23[ 'h9] = 'h29D; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E7; arA23[ 'h9] = 'h29D; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00E; arA23[ 'h9] = 'h29D; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E6; arA23[ 'h9] = 'h29D; end
+ 9: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 10: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ 11: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C5; arA23[ 'h9] = 'X; end
+ 1: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C5; arA23[ 'h9] = 'X; end
+ 2: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00B; arA23[ 'h9] = 'h1CB; end
+ 3: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00F; arA23[ 'h9] = 'h1CB; end
+ 4: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h179; arA23[ 'h9] = 'h1CB; end
+ 5: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C6; arA23[ 'h9] = 'h1CB; end
+ 6: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E7; arA23[ 'h9] = 'h1CB; end
+ 7: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h00E; arA23[ 'h9] = 'h1CB; end
+ 8: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E6; arA23[ 'h9] = 'h1CB; end
+ 9: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1C6; arA23[ 'h9] = 'h1CB; end
+ 10: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h1E7; arA23[ 'h9] = 'h1CB; end
+ 11: begin arIll[ 'h9] = 1'b0; arA1[ 'h9] = 'h0A7; arA23[ 'h9] = 'h1C5; end
+ default: begin arIll[ 'h9] = 1'b1; arA1[ 'h9] = 'X ; arA23[ 'h9] = 'X; end
+ endcase
+endcase
+
+//
+// Line: B
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D1; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h006; arA23[ 'hb] = 'h1D3; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h21C; arA23[ 'hb] = 'h1D3; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h103; arA23[ 'hb] = 'h1D3; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1D3; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1D3; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00A; arA23[ 'hb] = 'h1D3; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E2; arA23[ 'hb] = 'h1D3; end
+ 9: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1D3; end
+ 10: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1D3; end
+ 11: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h0EA; arA23[ 'hb] = 'h1D1; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D1; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D1; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h006; arA23[ 'hb] = 'h1D3; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h21C; arA23[ 'hb] = 'h1D3; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h103; arA23[ 'hb] = 'h1D3; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1D3; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1D3; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00A; arA23[ 'hb] = 'h1D3; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E2; arA23[ 'hb] = 'h1D3; end
+ 9: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1D3; end
+ 10: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1D3; end
+ 11: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h0EA; arA23[ 'hb] = 'h1D1; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D5; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D5; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00B; arA23[ 'hb] = 'h1D7; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00F; arA23[ 'hb] = 'h1D7; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h179; arA23[ 'hb] = 'h1D7; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C6; arA23[ 'hb] = 'h1D7; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E7; arA23[ 'hb] = 'h1D7; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00E; arA23[ 'hb] = 'h1D7; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E6; arA23[ 'hb] = 'h1D7; end
+ 9: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C6; arA23[ 'hb] = 'h1D7; end
+ 10: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E7; arA23[ 'hb] = 'h1D7; end
+ 11: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h0A7; arA23[ 'hb] = 'h1D5; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D9; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D9; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h006; arA23[ 'hb] = 'h1CF; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h21C; arA23[ 'hb] = 'h1CF; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h103; arA23[ 'hb] = 'h1CF; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1CF; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1CF; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00A; arA23[ 'hb] = 'h1CF; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E2; arA23[ 'hb] = 'h1CF; end
+ 9: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h1CF; end
+ 10: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h1CF; end
+ 11: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h0EA; arA23[ 'hb] = 'h1D9; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h100; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h06B; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h006; arA23[ 'hb] = 'h299; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h21C; arA23[ 'hb] = 'h299; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h103; arA23[ 'hb] = 'h299; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h299; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h299; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00A; arA23[ 'hb] = 'h299; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E2; arA23[ 'hb] = 'h299; end
+ 9: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 10: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 11: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h100; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h06B; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h006; arA23[ 'hb] = 'h299; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h21C; arA23[ 'hb] = 'h299; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h103; arA23[ 'hb] = 'h299; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C2; arA23[ 'hb] = 'h299; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E3; arA23[ 'hb] = 'h299; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00A; arA23[ 'hb] = 'h299; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E2; arA23[ 'hb] = 'h299; end
+ 9: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 10: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 11: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h10C; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h06F; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00B; arA23[ 'hb] = 'h29D; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00F; arA23[ 'hb] = 'h29D; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h179; arA23[ 'hb] = 'h29D; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C6; arA23[ 'hb] = 'h29D; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E7; arA23[ 'hb] = 'h29D; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00E; arA23[ 'hb] = 'h29D; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E6; arA23[ 'hb] = 'h29D; end
+ 9: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 10: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ 11: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D5; arA23[ 'hb] = 'X; end
+ 1: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1D5; arA23[ 'hb] = 'X; end
+ 2: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00B; arA23[ 'hb] = 'h1D7; end
+ 3: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00F; arA23[ 'hb] = 'h1D7; end
+ 4: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h179; arA23[ 'hb] = 'h1D7; end
+ 5: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C6; arA23[ 'hb] = 'h1D7; end
+ 6: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E7; arA23[ 'hb] = 'h1D7; end
+ 7: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h00E; arA23[ 'hb] = 'h1D7; end
+ 8: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E6; arA23[ 'hb] = 'h1D7; end
+ 9: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1C6; arA23[ 'hb] = 'h1D7; end
+ 10: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h1E7; arA23[ 'hb] = 'h1D7; end
+ 11: begin arIll[ 'hb] = 1'b0; arA1[ 'hb] = 'h0A7; arA23[ 'hb] = 'h1D5; end
+ default: begin arIll[ 'hb] = 1'b1; arA1[ 'hb] = 'X ; arA23[ 'hb] = 'X; end
+ endcase
+endcase
+
+//
+// Line: C
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C1; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h1C3; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h1C3; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h1C3; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h1C3; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h1C3; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h1C3; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h1C3; end
+ 9: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h1C3; end
+ 10: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h1C3; end
+ 11: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h0EA; arA23[ 'hc] = 'h1C1; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C1; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h1C3; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h1C3; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h1C3; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h1C3; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h1C3; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h1C3; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h1C3; end
+ 9: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h1C3; end
+ 10: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h1C3; end
+ 11: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h0EA; arA23[ 'hc] = 'h1C1; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C5; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00B; arA23[ 'hc] = 'h1CB; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00F; arA23[ 'hc] = 'h1CB; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h179; arA23[ 'hc] = 'h1CB; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C6; arA23[ 'hc] = 'h1CB; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E7; arA23[ 'hc] = 'h1CB; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00E; arA23[ 'hc] = 'h1CB; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E6; arA23[ 'hc] = 'h1CB; end
+ 9: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C6; arA23[ 'hc] = 'h1CB; end
+ 10: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E7; arA23[ 'hc] = 'h1CB; end
+ 11: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h0A7; arA23[ 'hc] = 'h1C5; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h15B; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h15A; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h15A; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h15A; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h15A; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h15A; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h15A; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h15A; end
+ 9: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h15A; end
+ 10: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h15A; end
+ 11: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h0EA; arA23[ 'hc] = 'h15B; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1CD; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h107; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h299; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h299; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h299; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h299; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h299; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h299; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h299; end
+ 9: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 10: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 11: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h3E3; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h3E3; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h299; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h299; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h299; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h299; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h299; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h299; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h299; end
+ 9: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 10: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 11: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h3E3; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00B; arA23[ 'hc] = 'h29D; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00F; arA23[ 'hc] = 'h29D; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h179; arA23[ 'hc] = 'h29D; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C6; arA23[ 'hc] = 'h29D; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E7; arA23[ 'hc] = 'h29D; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00E; arA23[ 'hc] = 'h29D; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E6; arA23[ 'hc] = 'h29D; end
+ 9: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 10: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 11: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h15B; arA23[ 'hc] = 'X; end
+ 1: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ 2: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h006; arA23[ 'hc] = 'h15A; end
+ 3: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h21C; arA23[ 'hc] = 'h15A; end
+ 4: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h103; arA23[ 'hc] = 'h15A; end
+ 5: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h15A; end
+ 6: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h15A; end
+ 7: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h00A; arA23[ 'hc] = 'h15A; end
+ 8: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E2; arA23[ 'hc] = 'h15A; end
+ 9: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1C2; arA23[ 'hc] = 'h15A; end
+ 10: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h1E3; arA23[ 'hc] = 'h15A; end
+ 11: begin arIll[ 'hc] = 1'b0; arA1[ 'hc] = 'h0EA; arA23[ 'hc] = 'h15B; end
+ default: begin arIll[ 'hc] = 1'b1; arA1[ 'hc] = 'X ; arA23[ 'hc] = 'X; end
+ endcase
+endcase
+
+//
+// Line: D
+//
+unique case( row86)
+
+3'b000: // Row: 0
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C1; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h006; arA23[ 'hd] = 'h1C3; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h21C; arA23[ 'hd] = 'h1C3; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h103; arA23[ 'hd] = 'h1C3; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C3; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C3; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00A; arA23[ 'hd] = 'h1C3; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E2; arA23[ 'hd] = 'h1C3; end
+ 9: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C3; end
+ 10: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C3; end
+ 11: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h0EA; arA23[ 'hd] = 'h1C1; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b001: // Row: 1
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C1; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C1; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h006; arA23[ 'hd] = 'h1C3; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h21C; arA23[ 'hd] = 'h1C3; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h103; arA23[ 'hd] = 'h1C3; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C3; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C3; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00A; arA23[ 'hd] = 'h1C3; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E2; arA23[ 'hd] = 'h1C3; end
+ 9: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C3; end
+ 10: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C3; end
+ 11: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h0EA; arA23[ 'hd] = 'h1C1; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b010: // Row: 2
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C5; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C5; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00B; arA23[ 'hd] = 'h1CB; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00F; arA23[ 'hd] = 'h1CB; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h179; arA23[ 'hd] = 'h1CB; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C6; arA23[ 'hd] = 'h1CB; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E7; arA23[ 'hd] = 'h1CB; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00E; arA23[ 'hd] = 'h1CB; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E6; arA23[ 'hd] = 'h1CB; end
+ 9: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C6; arA23[ 'hd] = 'h1CB; end
+ 10: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E7; arA23[ 'hd] = 'h1CB; end
+ 11: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h0A7; arA23[ 'hd] = 'h1C5; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b011: // Row: 3
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C9; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C9; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h006; arA23[ 'hd] = 'h1C7; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h21C; arA23[ 'hd] = 'h1C7; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h103; arA23[ 'hd] = 'h1C7; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C7; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C7; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00A; arA23[ 'hd] = 'h1C7; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E2; arA23[ 'hd] = 'h1C7; end
+ 9: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h1C7; end
+ 10: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h1C7; end
+ 11: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h0EA; arA23[ 'hd] = 'h1C9; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b100: // Row: 4
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C1; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h10F; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h006; arA23[ 'hd] = 'h299; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h21C; arA23[ 'hd] = 'h299; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h103; arA23[ 'hd] = 'h299; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h299; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h299; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00A; arA23[ 'hd] = 'h299; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E2; arA23[ 'hd] = 'h299; end
+ 9: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 10: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 11: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b101: // Row: 5
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C1; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h10F; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h006; arA23[ 'hd] = 'h299; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h21C; arA23[ 'hd] = 'h299; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h103; arA23[ 'hd] = 'h299; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C2; arA23[ 'hd] = 'h299; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E3; arA23[ 'hd] = 'h299; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00A; arA23[ 'hd] = 'h299; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E2; arA23[ 'hd] = 'h299; end
+ 9: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 10: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 11: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b110: // Row: 6
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C5; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h10B; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00B; arA23[ 'hd] = 'h29D; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00F; arA23[ 'hd] = 'h29D; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h179; arA23[ 'hd] = 'h29D; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C6; arA23[ 'hd] = 'h29D; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E7; arA23[ 'hd] = 'h29D; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00E; arA23[ 'hd] = 'h29D; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E6; arA23[ 'hd] = 'h29D; end
+ 9: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 10: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ 11: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+
+3'b111: // Row: 7
+ unique case ( col)
+ 0: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C5; arA23[ 'hd] = 'X; end
+ 1: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C5; arA23[ 'hd] = 'X; end
+ 2: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00B; arA23[ 'hd] = 'h1CB; end
+ 3: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00F; arA23[ 'hd] = 'h1CB; end
+ 4: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h179; arA23[ 'hd] = 'h1CB; end
+ 5: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C6; arA23[ 'hd] = 'h1CB; end
+ 6: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E7; arA23[ 'hd] = 'h1CB; end
+ 7: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h00E; arA23[ 'hd] = 'h1CB; end
+ 8: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E6; arA23[ 'hd] = 'h1CB; end
+ 9: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1C6; arA23[ 'hd] = 'h1CB; end
+ 10: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h1E7; arA23[ 'hd] = 'h1CB; end
+ 11: begin arIll[ 'hd] = 1'b0; arA1[ 'hd] = 'h0A7; arA23[ 'hd] = 'h1C5; end
+ default: begin arIll[ 'hd] = 1'b1; arA1[ 'hd] = 'X ; arA23[ 'hd] = 'X; end
+ endcase
+endcase
+end
+
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..c081f108236c0da105282d255cdee221a13d7ab2
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80.vhd
@@ -0,0 +1,1346 @@
+--------------------------------------------------------------------------------
+-- ****
+-- T80(c) core. Attempt to finish all undocumented features and provide
+-- accurate timings.
+-- Version 350.
+-- Copyright (c) 2018 Sorgelig
+-- Test passed: ZEXDOC, ZEXALL, Z80Full(*), Z80memptr
+-- (*) Currently only SCF and CCF instructions aren't passed X/Y flags check as
+-- correct implementation is still unclear.
+--
+-- ****
+-- T80(b) core. In an effort to merge and maintain bug fixes ....
+--
+-- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
+-- Ver 301 parity flag is just parity for 8080, also overflow for Z80, by Sean Riddle
+-- Ver 300 started tidyup.
+--
+-- MikeJ March 2005
+-- Latest version from www.fpgaarcade.com (original www.opencores.org)
+--
+-- ****
+-- Z80 compatible microprocessor core
+--
+-- Version : 0250
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- Limitations :
+--
+-- File history :
+--
+-- 0208 : First complete release
+-- 0210 : Fixed wait and halt
+-- 0211 : Fixed Refresh addition and IM 1
+-- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
+-- 0232 : Removed refresh address output for Mode > 1 and added DJNZ M1_n fix by Mike Johnson
+-- 0235 : Added clock enable and IM 2 fix by Mike Johnson
+-- 0237 : Changed 8080 I/O address output, added IntE output
+-- 0238 : Fixed (IX/IY+d) timing and 16 bit ADC and SBC zero flag
+-- 0240 : Added interrupt ack fix by Mike Johnson, changed (IX/IY+d) timing and changed flags in GB mode
+-- 0242 : Added I/O wait, fixed refresh address, moved some registers to RAM
+-- 0247 : Fixed bus req/ack cycle
+-- 0250 : Added R800 Multiplier by TobiFlex 2017.10.15
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+use IEEE.STD_LOGIC_UNSIGNED.all;
+use work.T80_Pack.all;
+
+entity T80 is
+ generic(
+ Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
+ IOWait : integer := 0; -- 0 => Single cycle I/O, 1 => Std I/O cycle
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ RESET_n : in std_logic;
+ CLK_n : in std_logic;
+ CEN : in std_logic;
+ WAIT_n : in std_logic;
+ INT_n : in std_logic;
+ NMI_n : in std_logic;
+ BUSRQ_n : in std_logic;
+ M1_n : out std_logic;
+ IORQ : out std_logic;
+ NoRead : out std_logic;
+ Write : out std_logic;
+ RFSH_n : out std_logic;
+ HALT_n : out std_logic;
+ BUSAK_n : out std_logic;
+ A : out std_logic_vector(15 downto 0);
+ DInst : in std_logic_vector(7 downto 0);
+ DI : in std_logic_vector(7 downto 0);
+ DO : out std_logic_vector(7 downto 0);
+ MC : out std_logic_vector(2 downto 0);
+ TS : out std_logic_vector(2 downto 0);
+ IntCycle_n : out std_logic;
+ IntE : out std_logic;
+ Stop : out std_logic;
+ R800_mode : in std_logic := '0';
+ out0 : in std_logic := '0'; -- 0 => OUT(C),0, 1 => OUT(C),255
+ REG : out std_logic_vector(211 downto 0); -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+
+ DIRSet : in std_logic := '0';
+ DIR : in std_logic_vector(211 downto 0) := (others => '0') -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+ );
+end T80;
+
+architecture rtl of T80 is
+
+ -- Registers
+ signal ACC, F : std_logic_vector(7 downto 0);
+ signal Ap, Fp : std_logic_vector(7 downto 0);
+ signal I : std_logic_vector(7 downto 0);
+ signal R : unsigned(7 downto 0);
+ signal SP, PC : unsigned(15 downto 0);
+
+ signal RegDIH : std_logic_vector(7 downto 0);
+ signal RegDIL : std_logic_vector(7 downto 0);
+ signal RegBusA : std_logic_vector(15 downto 0);
+ signal RegBusB : std_logic_vector(15 downto 0);
+ signal RegBusC : std_logic_vector(15 downto 0);
+ signal RegAddrA_r : std_logic_vector(2 downto 0);
+ signal RegAddrA : std_logic_vector(2 downto 0);
+ signal RegAddrB_r : std_logic_vector(2 downto 0);
+ signal RegAddrB : std_logic_vector(2 downto 0);
+ signal RegAddrC : std_logic_vector(2 downto 0);
+ signal RegWEH : std_logic;
+ signal RegWEL : std_logic;
+ signal Alternate : std_logic;
+
+ -- Help Registers
+ signal WZ : std_logic_vector(15 downto 0); -- MEMPTR register
+ signal TmpAddr2 : std_logic_vector(15 downto 0); -- Temporary address register
+ signal IR : std_logic_vector(7 downto 0); -- Instruction register
+ signal ISet : std_logic_vector(1 downto 0); -- Instruction set selector
+ signal RegBusA_r : std_logic_vector(15 downto 0);
+ signal MULU_Prod32 : std_logic_vector(31 downto 0);
+ signal MULU_tmp : std_logic_vector(31 downto 0);
+ signal MULU_Fakt1 : std_logic_vector(15 downto 0);
+
+ signal ID16 : signed(15 downto 0);
+ signal Save_Mux : std_logic_vector(7 downto 0);
+
+ signal TState : unsigned(2 downto 0);
+ signal MCycle : std_logic_vector(2 downto 0);
+ signal IntE_FF1 : std_logic;
+ signal IntE_FF2 : std_logic;
+ signal Halt_FF : std_logic;
+ signal BusReq_s : std_logic := '0';
+ signal BusAck : std_logic := '0';
+ signal ClkEn : std_logic;
+ signal NMI_s : std_logic;
+ signal IStatus : std_logic_vector(1 downto 0);
+
+ signal DI_Reg : std_logic_vector(7 downto 0);
+ signal T_Res : std_logic;
+ signal XY_State : std_logic_vector(1 downto 0);
+ signal Pre_XY_F_M : std_logic_vector(2 downto 0);
+ signal NextIs_XY_Fetch : std_logic;
+ signal XY_Ind : std_logic;
+ signal No_BTR : std_logic;
+ signal BTR_r : std_logic;
+ signal Auto_Wait : std_logic;
+ signal Auto_Wait_t1 : std_logic;
+ signal Auto_Wait_t2 : std_logic;
+ signal IncDecZ : std_logic;
+
+ -- ALU signals
+ signal BusB : std_logic_vector(7 downto 0);
+ signal BusA : std_logic_vector(7 downto 0);
+ signal ALU_Q : std_logic_vector(7 downto 0);
+ signal F_Out : std_logic_vector(7 downto 0);
+
+ -- Registered micro code outputs
+ signal Read_To_Reg_r : std_logic_vector(4 downto 0);
+ signal Arith16_r : std_logic;
+ signal Z16_r : std_logic;
+ signal ALU_Op_r : std_logic_vector(3 downto 0);
+ signal Save_ALU_r : std_logic;
+ signal PreserveC_r : std_logic;
+ signal MCycles : std_logic_vector(2 downto 0);
+
+ -- Micro code outputs
+ signal MCycles_d : std_logic_vector(2 downto 0);
+ signal TStates : std_logic_vector(2 downto 0);
+ signal IntCycle : std_logic;
+ signal NMICycle : std_logic;
+ signal Inc_PC : std_logic;
+ signal Inc_WZ : std_logic;
+ signal IncDec_16 : std_logic_vector(3 downto 0);
+ signal Prefix : std_logic_vector(1 downto 0);
+ signal Read_To_Acc : std_logic;
+ signal Read_To_Reg : std_logic;
+ signal Set_BusB_To : std_logic_vector(3 downto 0);
+ signal Set_BusA_To : std_logic_vector(3 downto 0);
+ signal ALU_Op : std_logic_vector(3 downto 0);
+ signal Save_ALU : std_logic;
+ signal Rot_Akku : std_logic;
+ signal PreserveC : std_logic;
+ signal Arith16 : std_logic;
+ signal Set_Addr_To : std_logic_vector(2 downto 0);
+ signal Jump : std_logic;
+ signal JumpE : std_logic;
+ signal JumpXY : std_logic;
+ signal Call : std_logic;
+ signal RstP : std_logic;
+ signal LDZ : std_logic;
+ signal LDW : std_logic;
+ signal LDSPHL : std_logic;
+ signal LDHLSP : std_logic;
+ signal ADDSPdd : std_logic;
+ signal IORQ_i : std_logic;
+ signal Write_i : std_logic;
+ signal NoRead_i : std_logic;
+ signal Special_LD : std_logic_vector(2 downto 0);
+ signal ExchangeDH : std_logic;
+ signal ExchangeRp : std_logic;
+ signal ExchangeAF : std_logic;
+ signal ExchangeRS : std_logic;
+ signal ExchangeWH : std_logic;
+ signal I_DJNZ : std_logic;
+ signal I_CPL : std_logic;
+ signal I_CCF : std_logic;
+ signal I_SCF : std_logic;
+ signal I_RETN : std_logic;
+ signal I_BT : std_logic;
+ signal I_BC : std_logic;
+ signal I_BTR : std_logic;
+ signal I_RLD : std_logic;
+ signal I_RRD : std_logic;
+ signal I_RXDD : std_logic;
+ signal I_INRC : std_logic;
+ signal I_MULUB : std_logic;
+ signal I_MULU : std_logic;
+ signal SetWZ : std_logic_vector(1 downto 0);
+ signal SetDI : std_logic;
+ signal SetEI : std_logic;
+ signal IMode : std_logic_vector(1 downto 0);
+ signal Halt : std_logic;
+ signal XYbit_undoc : std_logic;
+ signal No_PC : std_logic;
+ signal DOR : std_logic_vector(127 downto 0);
+
+ signal Really_Wait : std_logic;
+
+begin
+
+ REG <= IntE_FF2 & IntE_FF1 & IStatus & DOR & std_logic_vector(PC) & std_logic_vector(SP) & std_logic_vector(R) & I & Fp & Ap & F & ACC when Alternate = '0'
+ else IntE_FF2 & IntE_FF1 & IStatus & DOR(127 downto 112) & DOR(47 downto 0) & DOR(63 downto 48) & DOR(111 downto 64) &
+ std_logic_vector(PC) & std_logic_vector(SP) & std_logic_vector(R) & I & Fp & Ap & F & ACC;
+
+ mcode : T80_MCode
+ generic map(
+ Mode => Mode,
+ Flag_C => Flag_C,
+ Flag_N => Flag_N,
+ Flag_P => Flag_P,
+ Flag_X => Flag_X,
+ Flag_H => Flag_H,
+ Flag_Y => Flag_Y,
+ Flag_Z => Flag_Z,
+ Flag_S => Flag_S)
+ port map(
+ IR => IR,
+ ISet => ISet,
+ MCycle => MCycle,
+ F => F,
+ NMICycle => NMICycle,
+ IntCycle => IntCycle,
+ XY_State => XY_State,
+ MCycles => MCycles_d,
+ TStates => TStates,
+ Prefix => Prefix,
+ Inc_PC => Inc_PC,
+ Inc_WZ => Inc_WZ,
+ IncDec_16 => IncDec_16,
+ Read_To_Acc => Read_To_Acc,
+ Read_To_Reg => Read_To_Reg,
+ Set_BusB_To => Set_BusB_To,
+ Set_BusA_To => Set_BusA_To,
+ ALU_Op => ALU_Op,
+ Save_ALU => Save_ALU,
+ Rot_Akku => Rot_Akku,
+ PreserveC => PreserveC,
+ Arith16 => Arith16,
+ Set_Addr_To => Set_Addr_To,
+ IORQ => IORQ_i,
+ Jump => Jump,
+ JumpE => JumpE,
+ JumpXY => JumpXY,
+ Call => Call,
+ RstP => RstP,
+ LDZ => LDZ,
+ LDW => LDW,
+ LDSPHL => LDSPHL,
+ LDHLSP => LDHLSP,
+ ADDSPdd => ADDSPdd,
+ Special_LD => Special_LD,
+ ExchangeDH => ExchangeDH,
+ ExchangeRp => ExchangeRp,
+ ExchangeAF => ExchangeAF,
+ ExchangeRS => ExchangeRS,
+ ExchangeWH => ExchangeWH,
+ I_DJNZ => I_DJNZ,
+ I_CPL => I_CPL,
+ I_CCF => I_CCF,
+ I_SCF => I_SCF,
+ I_RETN => I_RETN,
+ I_BT => I_BT,
+ I_BC => I_BC,
+ I_BTR => I_BTR,
+ I_RLD => I_RLD,
+ I_RRD => I_RRD,
+ I_INRC => I_INRC,
+ I_MULUB => I_MULUB,
+ I_MULU => I_MULU,
+ SetWZ => SetWZ,
+ SetDI => SetDI,
+ SetEI => SetEI,
+ IMode => IMode,
+ Halt => Halt,
+ NoRead => NoRead_i,
+ Write => Write_i,
+ R800_mode => R800_mode,
+ No_PC => No_PC,
+ XYbit_undoc => XYbit_undoc);
+
+ alu : T80_ALU
+ generic map(
+ Mode => Mode,
+ Flag_C => Flag_C,
+ Flag_N => Flag_N,
+ Flag_P => Flag_P,
+ Flag_X => Flag_X,
+ Flag_H => Flag_H,
+ Flag_Y => Flag_Y,
+ Flag_Z => Flag_Z,
+ Flag_S => Flag_S)
+ port map(
+ Arith16 => Arith16_r,
+ Z16 => Z16_r,
+ WZ => WZ,
+ XY_State=> XY_State,
+ ALU_Op => ALU_Op_r,
+ Rot_Akku => Rot_Akku,
+ IR => IR(5 downto 0),
+ ISet => ISet,
+ BusA => BusA,
+ BusB => BusB,
+ F_In => F,
+ Q => ALU_Q,
+ F_Out => F_Out);
+
+ Really_Wait <= not Wait_n and (Write_i or not NoRead_i);
+
+ ClkEn <= CEN and not BusAck;
+
+ T_Res <= '1' when TState = unsigned(TStates) else '0';
+
+ NextIs_XY_Fetch <= '1' when XY_State /= "00" and XY_Ind = '0' and
+ ((Set_Addr_To = aXY) or
+ (MCycle = "001" and IR = "11001011") or
+ (MCycle = "001" and IR = "00110110")) else '0';
+
+ Save_Mux <= BusB when ExchangeRp = '1' else
+ DI_Reg when Save_ALU_r = '0' else
+ ALU_Q;
+
+ process (RESET_n, CLK_n)
+ variable n : std_logic_vector(7 downto 0);
+ variable ioq : std_logic_vector(8 downto 0);
+ variable temp_c : unsigned(8 downto 0);
+ variable temp_h : unsigned(4 downto 0);
+ begin
+ if RESET_n = '0' then
+ PC <= (others => '0'); -- Program Counter
+ A <= (others => '0');
+ WZ <= (others => '0');
+ IR <= "00000000";
+ ISet <= "00";
+ XY_State <= "00";
+ IStatus <= "00";
+ MCycles <= "000";
+ DO <= "00000000";
+
+ ACC <= (others => '1');
+ F <= (others => '1');
+ if Mode = 3 then
+ ACC <= (others => '0');
+ F <= "11110000";
+ end if;
+
+ Ap <= (others => '1');
+ Fp <= (others => '1');
+ I <= (others => '0');
+ R <= (others => '0');
+ SP <= (others => '1');
+ Alternate <= '0';
+
+ Read_To_Reg_r <= "00000";
+ Arith16_r <= '0';
+ BTR_r <= '0';
+ Z16_r <= '0';
+ ALU_Op_r <= "0000";
+ Save_ALU_r <= '0';
+ PreserveC_r <= '0';
+ XY_Ind <= '0';
+ I_RXDD <= '0';
+
+ elsif rising_edge(CLK_n) then
+
+ if DIRSet = '1' then
+ ACC <= DIR( 7 downto 0);
+ F <= DIR(15 downto 8);
+ Ap <= DIR(23 downto 16);
+ Fp <= DIR(31 downto 24);
+ I <= DIR(39 downto 32);
+ R <= unsigned(DIR(47 downto 40));
+ SP <= unsigned(DIR(63 downto 48));
+ PC <= unsigned(DIR(79 downto 64));
+ A <= DIR(79 downto 64);
+ IStatus <= DIR(209 downto 208);
+
+ elsif ClkEn = '1' then
+ ALU_Op_r <= "0000";
+ Save_ALU_r <= '0';
+ Read_To_Reg_r <= "00000";
+
+ MCycles <= MCycles_d;
+
+ if LDHLSP = '1' and MCycle = "011" and TState = 1 then
+ temp_c := unsigned('0'&SP(7 downto 0))+unsigned('0'&Save_Mux);
+ temp_h := unsigned('0'&SP(3 downto 0))+unsigned('0'&Save_Mux(3 downto 0));
+ F(Flag_Z) <= '0';
+ F(Flag_N) <= '0';
+ F(Flag_H) <= temp_h(4);
+ F(Flag_C) <= temp_c(8);
+ end if;
+
+ if ADDSPdd = '1' and TState = 1 then
+ temp_c := unsigned('0'&SP(7 downto 0))+unsigned('0'&Save_Mux);
+ temp_h := unsigned('0'&SP(3 downto 0))+unsigned('0'&Save_Mux(3 downto 0));
+ F(Flag_Z) <= '0';
+ F(Flag_N) <= '0';
+ F(Flag_H) <= temp_h(4);
+ F(Flag_C) <= temp_c(8);
+ end if;
+
+ if Mode = 3 then
+ IStatus <= "10";
+ elsif IMode /= "11" then
+ IStatus <= IMode;
+ end if;
+
+ Arith16_r <= Arith16;
+ PreserveC_r <= PreserveC;
+ if ISet = "10" and ALU_OP(2) = '0' and ALU_OP(0) = '1' and MCycle = "011" then
+ Z16_r <= '1';
+ else
+ Z16_r <= '0';
+ end if;
+
+ if MCycle = "001" and TState(2) = '0' then
+ -- MCycle = 1 and TState = 1, 2, or 3
+
+ if TState = 2 and Wait_n = '1' then
+ if Mode < 2 then
+ A(7 downto 0) <= std_logic_vector(R);
+ A(15 downto 8) <= I;
+ R(6 downto 0) <= R(6 downto 0) + 1;
+ end if;
+
+ if Jump = '0' and Call = '0' and NMICycle = '0' and IntCycle = '0' and not (Halt_FF = '1' or Halt = '1') then
+ PC <= PC + 1;
+ end if;
+
+ if IntCycle = '1' and IStatus = "01" then
+ IR <= "11111111";
+ elsif Halt_FF = '1' or (IntCycle = '1' and IStatus = "10") or NMICycle = '1' then
+ IR <= "00000000";
+ else
+ IR <= DInst;
+ end if;
+
+ if Mode <= 1 and IntCycle = '1' and IStatus = "10" then
+ -- IM2 vector address low byte from bus
+ WZ(7 downto 0) <= DInst;
+ end if;
+
+ ISet <= "00";
+ if Prefix /= "00" then
+ if Prefix = "11" then
+ if IR(5) = '1' then
+ XY_State <= "10";
+ else
+ XY_State <= "01";
+ end if;
+ else
+ if Prefix = "10" then
+ XY_State <= "00";
+ XY_Ind <= '0';
+ end if;
+ ISet <= Prefix;
+ end if;
+ else
+ XY_State <= "00";
+ XY_Ind <= '0';
+ end if;
+ end if;
+
+ else
+ -- either (MCycle > 1) OR (MCycle = 1 AND TState > 3)
+
+ if MCycle = "110" then
+ XY_Ind <= '1';
+ if Prefix = "01" then
+ ISet <= "01";
+ end if;
+ end if;
+
+ if T_Res = '1' then
+ BTR_r <= (I_BT or I_BC or I_BTR) and not No_BTR;
+ if Jump = '1' then
+ A(15 downto 8) <= DI_Reg;
+ A(7 downto 0) <= WZ(7 downto 0);
+ PC(15 downto 8) <= unsigned(DI_Reg);
+ PC(7 downto 0) <= unsigned(WZ(7 downto 0));
+ elsif JumpXY = '1' then
+ A <= RegBusC;
+ PC <= unsigned(RegBusC);
+ elsif Call = '1' or RstP = '1' then
+ A <= WZ;
+ PC <= unsigned(WZ);
+ elsif MCycle = MCycles and NMICycle = '1' then
+ A <= "0000000001100110";
+ PC <= "0000000001100110";
+ elsif ((Mode /= 3 and MCycle = "011") or (Mode = 3 and MCycle = "100"))
+ and IntCycle = '1' and IStatus = "10" then
+ A(15 downto 8) <= I;
+ A(7 downto 0) <= WZ(7 downto 0);
+ PC(15 downto 8) <= unsigned(I);
+ PC(7 downto 0) <= unsigned(WZ(7 downto 0));
+ else
+ case Set_Addr_To is
+ when aXY =>
+ if XY_State = "00" then
+ A <= RegBusC;
+ else
+ if NextIs_XY_Fetch = '1' then
+ A <= std_logic_vector(PC);
+ else
+ A <= WZ;
+ end if;
+ end if;
+ when aIOA =>
+ if Mode = 3 then
+ -- Memory map I/O on GBZ80
+ A(15 downto 8) <= (others => '1');
+ elsif Mode = 2 then
+ -- Duplicate I/O address on 8080
+ A(15 downto 8) <= DI_Reg;
+ else
+ A(15 downto 8) <= ACC;
+ end if;
+ A(7 downto 0) <= DI_Reg;
+ WZ <= (ACC & DI_Reg) + "1";
+ when aSP =>
+ A <= std_logic_vector(SP);
+ when aBC =>
+ if Mode = 3 and IORQ_i = '1' then
+ -- Memory map I/O on GBZ80
+ A(15 downto 8) <= (others => '1');
+ A(7 downto 0) <= RegBusC(7 downto 0);
+ else
+ A <= RegBusC;
+ if SetWZ = "01" then
+ WZ <= RegBusC + "1";
+ end if;
+ if SetWZ = "10" then
+ WZ(7 downto 0) <= RegBusC(7 downto 0) + "1";
+ WZ(15 downto 8) <= ACC;
+ end if;
+ end if;
+ when aDE =>
+ A <= RegBusC;
+ if SetWZ = "10" then
+ WZ(7 downto 0) <= RegBusC(7 downto 0) + "1";
+ WZ(15 downto 8) <= ACC;
+ end if;
+ when aZI =>
+ if Inc_WZ = '1' then
+ A <= std_logic_vector(unsigned(WZ) + 1);
+ else
+ A(15 downto 8) <= DI_Reg;
+ A(7 downto 0) <= WZ(7 downto 0);
+ if SetWZ = "10" then
+ WZ(7 downto 0) <= WZ(7 downto 0) + "1";
+ WZ(15 downto 8) <= ACC;
+ end if;
+ end if;
+ when others =>
+ if ISet = "10" and IR(7 downto 4) = x"B" and IR(2 downto 1) = "01" and MCycle = 3 and No_BTR = '0' then
+ -- INIR, INDR, OTIR, OTDR
+ A <= RegBusA_r;
+ elsif No_PC = '0' or No_BTR = '1' or (I_DJNZ = '1' and IncDecZ = '1') or Mode > 1 then
+ A <= std_logic_vector(PC);
+ end if;
+ end case;
+ end if;
+
+ if SetWZ = "11" then
+ WZ <= std_logic_vector(ID16);
+ end if;
+
+ Save_ALU_r <= Save_ALU;
+ ALU_Op_r <= ALU_Op;
+
+ if Mode = 3 then
+ if I_CPL = '1' then
+ -- CPL
+ ACC <= not ACC;
+ F(Flag_H) <= '1';
+ F(Flag_N) <= '1';
+ end if;
+ if I_CCF = '1' then
+ -- CCF
+ F(Flag_C) <= not F(Flag_C);
+ F(Flag_H) <= '0';
+ F(Flag_N) <= '0';
+ end if;
+ if I_SCF = '1' then
+ -- SCF
+ F(Flag_C) <= '1';
+ F(Flag_H) <= '0';
+ F(Flag_N) <= '0';
+ end if;
+ else
+ if I_CPL = '1' then
+ -- CPL
+ ACC <= not ACC;
+ F(Flag_Y) <= not ACC(5);
+ F(Flag_H) <= '1';
+ F(Flag_X) <= not ACC(3);
+ F(Flag_N) <= '1';
+ end if;
+ if I_CCF = '1' then
+ -- CCF
+ F(Flag_C) <= not F(Flag_C);
+ F(Flag_Y) <= ACC(5);
+ F(Flag_H) <= F(Flag_C);
+ F(Flag_X) <= ACC(3);
+ F(Flag_N) <= '0';
+ end if;
+ if I_SCF = '1' then
+ -- SCF
+ F(Flag_C) <= '1';
+ F(Flag_Y) <= ACC(5);
+ F(Flag_H) <= '0';
+ F(Flag_X) <= ACC(3);
+ F(Flag_N) <= '0';
+ end if;
+ end if;
+ end if;
+
+ if (TState = 2 and Really_Wait = '0' and I_BTR = '1' and IR(0) = '1') or (TState = 1 and I_BTR = '1' and IR(0) = '0') then
+ ioq := ('0' & DI_Reg) + ('0' & std_logic_vector(ID16(7 downto 0)));
+ F(Flag_N) <= DI_Reg(7);
+ F(Flag_C) <= ioq(8);
+ F(Flag_H) <= ioq(8);
+ ioq := (ioq and "000000111") xor ('0'&BusA);
+ F(Flag_P) <= not (ioq(0) xor ioq(1) xor ioq(2) xor ioq(3) xor ioq(4) xor ioq(5) xor ioq(6) xor ioq(7));
+ end if;
+
+ if TState = 2 and Really_Wait = '0' then
+ if ISet = "01" and MCycle = "111" then
+ IR <= DInst;
+ end if;
+ if JumpE = '1' then
+ PC <= unsigned(signed(PC) + signed(DI_Reg));
+ WZ <= std_logic_vector(signed(PC) + signed(DI_Reg));
+ elsif Inc_PC = '1' then
+ PC <= PC + 1;
+ end if;
+ if BTR_r = '1' then
+ PC <= PC - 2;
+ end if;
+ if RstP = '1' then
+ WZ <= (others =>'0');
+ WZ(5 downto 3) <= IR(5 downto 3);
+ end if;
+ end if;
+ if TState = 3 and MCycle = "110" then
+ WZ <= std_logic_vector(signed(RegBusC) + signed(DI_Reg));
+ end if;
+
+ if MCycle = "011" and TState = 4 and No_BTR = '0' then
+ if I_BT = '1' or I_BC = '1' then
+ WZ <= std_logic_vector(PC)-"1";
+ end if;
+ end if;
+
+ if (TState = 2 and Really_Wait = '0') or (TState = 4 and MCycle = "001") then
+ if IncDec_16(2 downto 0) = "111" then
+ if IncDec_16(3) = '1' then
+ SP <= SP - 1;
+ else
+ SP <= SP + 1;
+ end if;
+ end if;
+ end if;
+
+ if ADDSPdd = '1' and TState = 2 then
+ WZ <= std_logic_vector(SP);
+ SP <= unsigned(signed(SP)+signed(Save_Mux));
+ end if;
+
+ if LDSPHL = '1' then
+ SP <= unsigned(RegBusC);
+ end if;
+ if ExchangeAF = '1' then
+ Ap <= ACC;
+ ACC <= Ap;
+ Fp <= F;
+ F <= Fp;
+ end if;
+ if ExchangeRS = '1' then
+ Alternate <= not Alternate;
+ end if;
+ end if;
+
+ if TState = 3 then
+ if LDZ = '1' then
+ WZ(7 downto 0) <= DI_Reg;
+ end if;
+ if LDW = '1' then
+ WZ(15 downto 8) <= DI_Reg;
+ end if;
+
+ if Special_LD(2) = '1' then
+ case Special_LD(1 downto 0) is
+ when "00" =>
+ ACC <= I;
+ F(Flag_P) <= IntE_FF2;
+ F(Flag_S) <= I(7);
+
+ if I = x"00" then
+ F(Flag_Z) <= '1';
+ else
+ F(Flag_Z) <= '0';
+ end if;
+
+ F(Flag_Y) <= I(5);
+ F(Flag_H) <= '0';
+ F(Flag_X) <= I(3);
+ F(Flag_N) <= '0';
+
+
+ when "01" =>
+ ACC <= std_logic_vector(R);
+ F(Flag_P) <= IntE_FF2;
+ F(Flag_S) <= R(7);
+
+ if R = x"00" then
+ F(Flag_Z) <= '1';
+ else
+ F(Flag_Z) <= '0';
+ end if;
+
+ F(Flag_Y) <= R(5);
+ F(Flag_H) <= '0';
+ F(Flag_X) <= R(3);
+ F(Flag_N) <= '0';
+
+ when "10" =>
+ I <= ACC;
+ when others =>
+ R <= unsigned(ACC);
+ end case;
+ end if;
+ end if;
+
+ if (I_DJNZ = '0' and Save_ALU_r = '1') or ALU_Op_r = "1001" then
+ if Mode = 3 then
+ F(6) <= F_Out(6);
+ F(5) <= F_Out(5);
+ F(7) <= F_Out(7);
+ if PreserveC_r = '0' then
+ F(4) <= F_Out(4);
+ end if;
+ else
+ F(7 downto 1) <= F_Out(7 downto 1);
+ if PreserveC_r = '0' then
+ F(Flag_C) <= F_Out(0);
+ end if;
+ end if;
+ end if;
+ if T_Res = '1' and I_INRC = '1' then
+ F(Flag_H) <= '0';
+ F(Flag_N) <= '0';
+ F(Flag_X) <= DI_Reg(3);
+ F(Flag_Y) <= DI_Reg(5);
+ if DI_Reg(7 downto 0) = "00000000" then
+ F(Flag_Z) <= '1';
+ else
+ F(Flag_Z) <= '0';
+ end if;
+ F(Flag_S) <= DI_Reg(7);
+ F(Flag_P) <= not (DI_Reg(0) xor DI_Reg(1) xor DI_Reg(2) xor DI_Reg(3) xor
+ DI_Reg(4) xor DI_Reg(5) xor DI_Reg(6) xor DI_Reg(7));
+ end if;
+
+ if TState = 1 and Auto_Wait_t1 = '0' then
+ -- Keep D0 from M3 for RLD/RRD (Sorgelig)
+ I_RXDD <= I_RLD or I_RRD;
+ if I_RXDD='0' then
+ DO <= BusB;
+ end if;
+ if I_RLD = '1' then
+ DO(3 downto 0) <= BusA(3 downto 0);
+ DO(7 downto 4) <= BusB(3 downto 0);
+ end if;
+ if I_RRD = '1' then
+ DO(3 downto 0) <= BusB(7 downto 4);
+ DO(7 downto 4) <= BusA(3 downto 0);
+ end if;
+ end if;
+
+ if T_Res = '1' then
+ Read_To_Reg_r(3 downto 0) <= Set_BusA_To;
+ Read_To_Reg_r(4) <= Read_To_Reg;
+ if Read_To_Acc = '1' then
+ Read_To_Reg_r(3 downto 0) <= "0111";
+ Read_To_Reg_r(4) <= '1';
+ end if;
+ end if;
+
+ if TState = 1 and I_BT = '1' then
+ F(Flag_X) <= ALU_Q(3);
+ F(Flag_Y) <= ALU_Q(1);
+ F(Flag_H) <= '0';
+ F(Flag_N) <= '0';
+ end if;
+ if TState = 1 and I_BC = '1' then
+ n := ALU_Q - ("0000000" & F_Out(Flag_H));
+ F(Flag_X) <= n(3);
+ F(Flag_Y) <= n(1);
+ end if;
+ if I_BC = '1' or I_BT = '1' then
+ F(Flag_P) <= IncDecZ;
+ end if;
+
+ if (TState = 1 and Save_ALU_r = '0' and Auto_Wait_t1 = '0') or
+ (Save_ALU_r = '1' and ALU_OP_r /= "0111") then
+ case Read_To_Reg_r is
+ when "10111" =>
+ ACC <= Save_Mux;
+ when "10110" =>
+ DO <= Save_Mux;
+ when "11000" =>
+ SP(7 downto 0) <= unsigned(Save_Mux);
+ when "11001" =>
+ SP(15 downto 8) <= unsigned(Save_Mux);
+ when "11011" =>
+ if Mode = 3 then
+ F(7 downto 4) <= Save_Mux(7 downto 4);
+ F(3 downto 0) <= "0000"; -- bit 3 to 0 always return 0
+ else
+ F <= Save_Mux;
+ end if;
+ when others =>
+ end case;
+ if XYbit_undoc='1' then
+ DO <= ALU_Q;
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+
+---------------------------------------------------------------------------
+--
+-- Multiply
+--
+---------------------------------------------------------------------------
+ process (CLK_n, ACC, RegBusB, MULU_tmp, MULU_Fakt1, MULU_Prod32)
+ begin
+
+ MULU_tmp(31 downto 12) <= std_logic_vector((unsigned(MULU_Fakt1)*unsigned(MULU_Prod32(3 downto 0)))+unsigned("0000"&MULU_Prod32(31 downto 16)));
+ MULU_tmp(11 downto 0) <= MULU_Prod32(15 downto 4);
+
+ if rising_edge(CLK_n) then
+ if ClkEn = '1' then
+ if T_Res='1' then
+ if I_MULUB='1' then
+ MULU_Prod32(7 downto 0) <= ACC;
+ MULU_Prod32(15 downto 8) <= "--------";
+ MULU_Prod32(31 downto 16) <= X"0000";
+ MULU_Fakt1(7 downto 0) <= "00000000";
+ if Set_BusB_To(0) = '1' then
+ MULU_Fakt1(15 downto 8) <= RegBusB(7 downto 0);
+ else
+ MULU_Fakt1(15 downto 8) <= RegBusB(15 downto 8);
+ end if;
+ else
+ MULU_Prod32(15 downto 0) <= RegBusA;
+ MULU_Prod32(31 downto 16) <= X"0000";
+ MULU_Fakt1 <= RegBusB;
+ end if;
+ else
+ MULU_Prod32 <= MULU_tmp;
+ end if;
+ end if;
+ end if;
+ end process;
+
+---------------------------------------------------------------------------
+--
+-- BC('), DE('), HL('), IX and IY
+--
+---------------------------------------------------------------------------
+ process (CLK_n)
+ begin
+ if rising_edge(CLK_n) then
+ if ClkEn = '1' then
+ -- Bus A / Write
+ RegAddrA_r <= Alternate & Set_BusA_To(2 downto 1);
+ if XY_Ind = '0' and XY_State /= "00" and Set_BusA_To(2 downto 1) = "10" then
+ RegAddrA_r <= XY_State(1) & "11";
+ end if;
+
+ -- Bus B
+ RegAddrB_r <= Alternate & Set_BusB_To(2 downto 1);
+ if XY_Ind = '0' and XY_State /= "00" and Set_BusB_To(2 downto 1) = "10" then
+ RegAddrB_r <= XY_State(1) & "11";
+ end if;
+
+ -- Address from register
+ RegAddrC <= Alternate & Set_Addr_To(1 downto 0);
+ -- Jump (HL), LD SP,HL
+ if (JumpXY = '1' or LDSPHL = '1') then
+ RegAddrC <= Alternate & "10";
+ end if;
+ if ((JumpXY = '1' or LDSPHL = '1') and XY_State /= "00") or (MCycle = "110") then
+ RegAddrC <= XY_State(1) & "11";
+ end if;
+
+ if I_DJNZ = '1' and Save_ALU_r = '1' and Mode < 2 then
+ IncDecZ <= F_Out(Flag_Z);
+ end if;
+ if (TState = 2 or (TState = 3 and MCycle = "001")) and IncDec_16(2 downto 0) = "100" then
+ if ID16 = 0 then
+ IncDecZ <= '0';
+ else
+ IncDecZ <= '1';
+ end if;
+ end if;
+
+ RegBusA_r <= RegBusA;
+ end if;
+ end if;
+ end process;
+
+ RegAddrA <=
+ -- 16 bit increment/decrement
+ Alternate & IncDec_16(1 downto 0) when (TState = 2 or
+ (TState = 3 and MCycle = "001" and IncDec_16(2) = '1')) and XY_State = "00" else
+ XY_State(1) & "11" when (TState = 2 or
+ (TState = 3 and MCycle = "001" and IncDec_16(2) = '1')) and IncDec_16(1 downto 0) = "10" else
+ -- EX HL,DL
+ Alternate & "10" when ExchangeDH = '1' and TState = 3 else
+ Alternate & "01" when (ExchangeDH = '1' or I_MULU = '1') and TState = 4 else
+ -- EX (SP),HL (HL(IX,IY) <= WZ)
+ Alternate & "10" when ExchangeWH = '1' and XY_State = "00" and TState = 4 else
+ XY_State(1) & "11" when ExchangeWH = '1' and TState = 4 else
+ -- LDHLSP
+ "010" when LDHLSP = '1' and TState = 4 else
+
+ -- Bus A / Write
+ RegAddrA_r;
+
+ RegAddrB <=
+ -- EX HL,DL
+ Alternate & "01" when ExchangeDH = '1' and TState = 3 else
+ -- Bus B
+ RegAddrB_r;
+
+ ID16 <= signed(RegBusA) - 1 when IncDec_16(3) = '1' else
+ signed(RegBusA) + 1;
+
+ process (Save_ALU_r, Auto_Wait_t1, ALU_OP_r, Read_To_Reg_r, I_MULU, T_Res,
+ ExchangeDH, ExchangeWH, IncDec_16, MCycle, TState, Really_Wait, LDHLSP)
+ begin
+ RegWEH <= '0';
+ RegWEL <= '0';
+ if (TState = 1 and Save_ALU_r = '0' and Auto_Wait_t1 = '0') or
+ (Save_ALU_r = '1' and ALU_OP_r /= "0111") then
+ case Read_To_Reg_r is
+ when "10000" | "10001" | "10010" | "10011" | "10100" | "10101" =>
+ RegWEH <= not Read_To_Reg_r(0);
+ RegWEL <= Read_To_Reg_r(0);
+ when others =>
+ end case;
+ end if;
+
+ if I_MULU = '1' and (T_Res = '1' or TState = 4) then -- TState = 4 DE write
+ RegWEH <= '1';
+ RegWEL <= '1';
+ end if;
+
+ if ExchangeDH = '1' and (TState = 3 or TState = 4) then
+ RegWEH <= '1';
+ RegWEL <= '1';
+ end if;
+
+ if ((LDHLSP = '1' and MCycle = "010") or ExchangeWH = '1') and TState = 4 then
+ RegWEH <= '1';
+ RegWEL <= '1';
+ end if;
+
+ if IncDec_16(2) = '1' and ((TState = 2 and Really_Wait = '0' and MCycle /= "001") or (TState = 3 and MCycle = "001")) then
+ case IncDec_16(1 downto 0) is
+ when "00" | "01" | "10" =>
+ RegWEH <= '1';
+ RegWEL <= '1';
+ when others =>
+ end case;
+ end if;
+ end process;
+
+ TmpAddr2 <= std_logic_vector(unsigned(signed(SP) + signed(Save_Mux)));
+
+ process (Save_Mux, RegBusB, RegBusA_r, ID16, I_MULU, MULU_Prod32, MULU_tmp, T_Res,
+ ExchangeDH, ExchangeWH, IncDec_16, MCycle, TState, Really_Wait, LDHLSP, TmpAddr2, WZ)
+ begin
+ RegDIH <= Save_Mux;
+ RegDIL <= Save_Mux;
+
+ if I_MULU = '1' then
+ if T_Res = '1' then
+ RegDIH <= MULU_Prod32(31 downto 24);
+ RegDIL <= MULU_Prod32(23 downto 16);
+ else
+ RegDIH <= MULU_tmp(15 downto 8); -- TState = 4 DE write
+ RegDIL <= MULU_tmp(7 downto 0);
+ end if;
+ end if;
+
+ if LDHLSP = '1' and MCycle = "010" and TState = 4 then
+ RegDIH <= TmpAddr2(15 downto 8);
+ RegDIL <= TmpAddr2(7 downto 0);
+ end if;
+
+ if ExchangeDH = '1' and TState = 3 then
+ RegDIH <= RegBusB(15 downto 8);
+ RegDIL <= RegBusB(7 downto 0);
+ end if;
+ if ExchangeDH = '1' and TState = 4 then
+ RegDIH <= RegBusA_r(15 downto 8);
+ RegDIL <= RegBusA_r(7 downto 0);
+ end if;
+ if ExchangeWH = '1' and TState = 4 then
+ RegDIH <= WZ(15 downto 8);
+ RegDIL <= WZ(7 downto 0);
+ end if;
+ if IncDec_16(2) = '1' and ((TState = 2 and MCycle /= "001") or (TState = 3 and MCycle = "001")) then
+ RegDIH <= std_logic_vector(ID16(15 downto 8));
+ RegDIL <= std_logic_vector(ID16(7 downto 0));
+ end if;
+ end process;
+
+ Regs : T80_Reg
+ port map(
+ Clk => CLK_n,
+ CEN => ClkEn,
+ WEH => RegWEH,
+ WEL => RegWEL,
+ AddrA => RegAddrA,
+ AddrB => RegAddrB,
+ AddrC => RegAddrC,
+ DIH => RegDIH,
+ DIL => RegDIL,
+ DOAH => RegBusA(15 downto 8),
+ DOAL => RegBusA(7 downto 0),
+ DOBH => RegBusB(15 downto 8),
+ DOBL => RegBusB(7 downto 0),
+ DOCH => RegBusC(15 downto 8),
+ DOCL => RegBusC(7 downto 0),
+ DOR => DOR,
+ DIRSet => DIRSet,
+ DIR => DIR(207 downto 80));
+
+---------------------------------------------------------------------------
+--
+-- Buses
+--
+---------------------------------------------------------------------------
+ process (CLK_n)
+ begin
+ if rising_edge(CLK_n) then
+ if ClkEn = '1' then
+ case Set_BusB_To is
+ when "0111" =>
+ BusB <= ACC;
+ when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" =>
+ if Set_BusB_To(0) = '1' then
+ BusB <= RegBusB(7 downto 0);
+ else
+ BusB <= RegBusB(15 downto 8);
+ end if;
+ when "0110" =>
+ BusB <= DI_Reg;
+ when "1000" =>
+ BusB <= std_logic_vector(SP(7 downto 0));
+ when "1001" =>
+ BusB <= std_logic_vector(SP(15 downto 8));
+ when "1010" =>
+ BusB <= "00000001";
+ when "1011" =>
+ BusB <= F;
+ when "1100" =>
+ BusB <= std_logic_vector(PC(7 downto 0));
+ when "1101" =>
+ BusB <= std_logic_vector(PC(15 downto 8));
+ when "1110" =>
+ if IR = x"71" and out0 = '1' then
+ BusB <= "11111111";
+ else
+ BusB <= "00000000";
+ end if;
+ when others =>
+ BusB <= "--------";
+ end case;
+
+ case Set_BusA_To is
+ when "0111" =>
+ BusA <= ACC;
+ when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" =>
+ if Set_BusA_To(0) = '1' then
+ BusA <= RegBusA(7 downto 0);
+ else
+ BusA <= RegBusA(15 downto 8);
+ end if;
+ when "0110" =>
+ BusA <= DI_Reg;
+ when "1000" =>
+ BusA <= std_logic_vector(SP(7 downto 0));
+ when "1001" =>
+ BusA <= std_logic_vector(SP(15 downto 8));
+ when "1010" =>
+ BusA <= "00000000";
+ when others =>
+ BusA <= "--------";
+ end case;
+ if XYbit_undoc='1' then
+ BusA <= DI_Reg;
+ BusB <= DI_Reg;
+ end if;
+ end if;
+ end if;
+ end process;
+
+---------------------------------------------------------------------------
+--
+-- Generate external control signals
+--
+---------------------------------------------------------------------------
+ process (RESET_n,CLK_n)
+ begin
+ if RESET_n = '0' then
+ RFSH_n <= '1';
+ elsif rising_edge(CLK_n) then
+ if DIRSet = '0' and CEN = '1' then
+ if MCycle = "001" and ((TState = 2 and Wait_n = '1') or TState = 3) then
+ RFSH_n <= '0';
+ else
+ RFSH_n <= '1';
+ end if;
+ end if;
+ end if;
+ end process;
+
+ MC <= std_logic_vector(MCycle);
+ TS <= std_logic_vector(TState);
+ DI_Reg <= DI;
+ HALT_n <= not Halt_FF;
+ BUSAK_n <= not (BusAck and RESET_n);
+ IntCycle_n <= not IntCycle;
+ IntE <= IntE_FF1;
+ IORQ <= IORQ_i;
+ NoRead <= NoRead_i;
+ Write <= Write_i;
+ Stop <= I_DJNZ;
+-------------------------------------------------------------------------
+--
+-- Main state machine
+--
+-------------------------------------------------------------------------
+ process (RESET_n, CLK_n)
+ variable OldNMI_n : std_logic;
+ begin
+ if RESET_n = '0' then
+ MCycle <= "001";
+ TState <= "000";
+ Pre_XY_F_M <= "000";
+ Halt_FF <= '0';
+ --BusAck <= '0';
+ NMICycle <= '0';
+ IntCycle <= '0';
+ IntE_FF1 <= '0';
+ IntE_FF2 <= '0';
+ No_BTR <= '0';
+ Auto_Wait_t1 <= '0';
+ Auto_Wait_t2 <= '0';
+ M1_n <= '1';
+ --BusReq_s <= '0';
+ NMI_s <= '0';
+ elsif rising_edge(CLK_n) then
+ if DIRSet = '1' then
+ IntE_FF2 <= DIR(211);
+ IntE_FF1 <= DIR(210);
+ else
+ if NMI_n = '0' and OldNMI_n = '1' then
+ NMI_s <= '1';
+ end if;
+ OldNMI_n := NMI_n;
+
+ if CEN = '1' then
+ BusReq_s <= not BUSRQ_n;
+ Auto_Wait_t2 <= Auto_Wait_t1;
+ if T_Res = '1' then
+ Auto_Wait_t1 <= '0';
+ Auto_Wait_t2 <= '0';
+ else
+ Auto_Wait_t1 <= Auto_Wait or IORQ_i;
+ end if;
+ No_BTR <= (I_BT and (not IR(4) or not F(Flag_P))) or
+ (I_BC and (not IR(4) or F(Flag_Z) or not F(Flag_P))) or
+ (I_BTR and (not IR(4) or F(Flag_Z)));
+ if TState = 2 then
+ if SetEI = '1' then
+ IntE_FF1 <= '1';
+ IntE_FF2 <= '1';
+ end if;
+ if I_RETN = '1' then
+ IntE_FF1 <= IntE_FF2;
+ end if;
+ end if;
+ if TState = 3 then
+ if SetDI = '1' then
+ IntE_FF1 <= '0';
+ IntE_FF2 <= '0';
+ end if;
+ end if;
+ if IntCycle = '1' or NMICycle = '1' then
+ Halt_FF <= '0';
+ end if;
+ if MCycle = "001" and TState = 2 and Wait_n = '1' then
+ M1_n <= '1';
+ end if;
+ if BusReq_s = '1' and BusAck = '1' then
+ else
+ BusAck <= '0';
+ if TState = 2 and Really_Wait = '1' then
+ elsif T_Res = '1' then
+ if Halt = '1' and ( not(Mode = 3 and INT_n = '0' and IntE_FF1 = '0')) then -- halt bug when Mode = 3 , INT_n = '0' and IME=0
+ Halt_FF <= '1';
+ end if;
+ if BusReq_s = '1' then
+ BusAck <= '1';
+ else
+ TState <= "001";
+ if (IntCycle = '1' and Mode = 3) then -- GB: read interrupt at MCycle 3
+ if (MCycle = "010") then
+ M1_n <= '0';
+ else
+ M1_n <= '1';
+ end if;
+ end if;
+ if NextIs_XY_Fetch = '1' then
+ MCycle <= "110";
+ Pre_XY_F_M <= MCycle;
+ if IR = "00110110" and Mode = 0 then
+ Pre_XY_F_M <= "010";
+ end if;
+ elsif (MCycle = "111") or (MCycle = "110" and Mode = 1 and ISet /= "01") then
+ MCycle <= std_logic_vector(unsigned(Pre_XY_F_M) + 1);
+ elsif (MCycle = MCycles) or No_BTR = '1' or (MCycle = "010" and I_DJNZ = '1' and IncDecZ = '1') then
+ M1_n <= '0';
+ MCycle <= "001";
+ IntCycle <= '0';
+ NMICycle <= '0';
+ if NMI_s = '1' and Prefix = "00" then
+ NMI_s <= '0';
+ NMICycle <= '1';
+ IntE_FF1 <= '0';
+ elsif IntE_FF1 = '1' and INT_n='0' and Prefix = "00" and SetEI = '0' then
+ IntCycle <= '1';
+ IntE_FF1 <= '0';
+ IntE_FF2 <= '0';
+ elsif (Halt_FF = '1' and INT_n = '0' and Mode = 3) then
+ Halt_FF <= '0';
+ end if;
+ else
+ MCycle <= std_logic_vector(unsigned(MCycle) + 1);
+ end if;
+ end if;
+ else
+ if (Auto_Wait = '1' and Auto_Wait_t2 = '0') nor
+ (IOWait = 1 and IORQ_i = '1' and Auto_Wait_t1 = '0') then
+ TState <= TState + 1;
+ end if;
+ end if;
+ end if;
+ if TState = 0 then
+ M1_n <= '0';
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ Auto_Wait <= '1' when IntCycle = '1' and MCycle = "001" else '0';
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_ALU.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_ALU.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..1192e0b9d4998210d1683926b37447f16cb938a5
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_ALU.vhd
@@ -0,0 +1,409 @@
+--------------------------------------------------------------------------------
+-- ****
+-- T80(c) core. Attempt to finish all undocumented features and provide
+-- accurate timings.
+-- Version 350.
+-- Copyright (c) 2018 Sorgelig
+-- Test passed: ZEXDOC, ZEXALL, Z80Full(*), Z80memptr
+-- (*) Currently only SCF and CCF instructions aren't passed X/Y flags check as
+-- correct implementation is still unclear.
+--
+-- ****
+-- T80(b) core. In an effort to merge and maintain bug fixes ....
+--
+-- Ver 301 parity flag is just parity for 8080, also overflow for Z80, by Sean Riddle
+-- Ver 300 started tidyup
+-- MikeJ March 2005
+-- Latest version from www.fpgaarcade.com (original www.opencores.org)
+--
+-- ****
+-- Z80 compatible microprocessor core
+--
+-- Version : 0247
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- Limitations :
+--
+-- File history :
+--
+-- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
+-- 0238 : Fixed zero flag for 16 bit SBC and ADC
+-- 0240 : Added GB operations
+-- 0242 : Cleanup
+-- 0247 : Cleanup
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+entity T80_ALU is
+ generic(
+ Mode : integer := 0;
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ Arith16 : in std_logic;
+ Z16 : in std_logic;
+ WZ : in std_logic_vector(15 downto 0);
+ XY_State : in std_logic_vector(1 downto 0);
+ ALU_Op : in std_logic_vector(3 downto 0);
+ Rot_Akku : in std_logic;
+ IR : in std_logic_vector(5 downto 0);
+ ISet : in std_logic_vector(1 downto 0);
+ BusA : in std_logic_vector(7 downto 0);
+ BusB : in std_logic_vector(7 downto 0);
+ F_In : in std_logic_vector(7 downto 0);
+ Q : out std_logic_vector(7 downto 0);
+ F_Out : out std_logic_vector(7 downto 0)
+ );
+end T80_ALU;
+
+architecture rtl of T80_ALU is
+
+ procedure AddSub(A : std_logic_vector;
+ B : std_logic_vector;
+ Sub : std_logic;
+ Carry_In : std_logic;
+ signal Res : out std_logic_vector;
+ signal Carry : out std_logic) is
+
+ variable B_i : unsigned(A'length - 1 downto 0);
+ variable Res_i : unsigned(A'length + 1 downto 0);
+ begin
+ if Sub = '1' then
+ B_i := not unsigned(B);
+ else
+ B_i := unsigned(B);
+ end if;
+
+ Res_i := unsigned("0" & A & Carry_In) + unsigned("0" & B_i & "1");
+ Carry <= Res_i(A'length + 1);
+ Res <= std_logic_vector(Res_i(A'length downto 1));
+ end;
+
+ -- AddSub variables (temporary signals)
+ signal UseCarry : std_logic;
+ signal Carry7_v : std_logic;
+ signal Overflow_v : std_logic;
+ signal HalfCarry_v : std_logic;
+ signal Carry_v : std_logic;
+ signal Q_v : std_logic_vector(7 downto 0);
+
+ signal BitMask : std_logic_vector(7 downto 0);
+
+begin
+
+ with IR(5 downto 3) select BitMask <= "00000001" when "000",
+ "00000010" when "001",
+ "00000100" when "010",
+ "00001000" when "011",
+ "00010000" when "100",
+ "00100000" when "101",
+ "01000000" when "110",
+ "10000000" when others;
+
+ UseCarry <= not ALU_Op(2) and ALU_Op(0);
+ AddSub(BusA(3 downto 0), BusB(3 downto 0), ALU_Op(1), ALU_Op(1) xor (UseCarry and F_In(Flag_C)), Q_v(3 downto 0), HalfCarry_v);
+ AddSub(BusA(6 downto 4), BusB(6 downto 4), ALU_Op(1), HalfCarry_v, Q_v(6 downto 4), Carry7_v);
+ AddSub(BusA(7 downto 7), BusB(7 downto 7), ALU_Op(1), Carry7_v, Q_v(7 downto 7), Carry_v);
+
+ -- bug fix - parity flag is just parity for 8080, also overflow for Z80
+ process (Carry_v, Carry7_v, Q_v)
+ begin
+ if(Mode=2) then
+ OverFlow_v <= not (Q_v(0) xor Q_v(1) xor Q_v(2) xor Q_v(3) xor
+ Q_v(4) xor Q_v(5) xor Q_v(6) xor Q_v(7)); else
+ OverFlow_v <= Carry_v xor Carry7_v;
+ end if;
+ end process;
+
+ process (Arith16, ALU_OP, F_In, BusA, BusB, IR, Q_v, Carry_v, HalfCarry_v, OverFlow_v, BitMask, ISet, Z16, Rot_Akku, WZ, XY_State)
+ variable Q_t : std_logic_vector(7 downto 0);
+ variable DAA_Q : unsigned(8 downto 0);
+ begin
+ Q_t := "--------";
+ F_Out <= F_In;
+ DAA_Q := "---------";
+ case ALU_Op is
+ when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" | "0110" | "0111" =>
+ F_Out(Flag_N) <= '0';
+ F_Out(Flag_C) <= '0';
+ case ALU_OP(2 downto 0) is
+ when "000" | "001" => -- ADD, ADC
+ Q_t := Q_v;
+ F_Out(Flag_C) <= Carry_v;
+ F_Out(Flag_H) <= HalfCarry_v;
+ F_Out(Flag_P) <= OverFlow_v;
+ when "010" | "011" | "111" => -- SUB, SBC, CP
+ Q_t := Q_v;
+ F_Out(Flag_N) <= '1';
+ F_Out(Flag_C) <= not Carry_v;
+ F_Out(Flag_H) <= not HalfCarry_v;
+ F_Out(Flag_P) <= OverFlow_v;
+ when "100" => -- AND
+ Q_t(7 downto 0) := BusA and BusB;
+ F_Out(Flag_H) <= '1';
+ when "101" => -- XOR
+ Q_t(7 downto 0) := BusA xor BusB;
+ F_Out(Flag_H) <= '0';
+ when others => -- OR "110"
+ Q_t(7 downto 0) := BusA or BusB;
+ F_Out(Flag_H) <= '0';
+ end case;
+ if ALU_Op(2 downto 0) = "111" then -- CP
+ F_Out(Flag_X) <= BusB(3);
+ F_Out(Flag_Y) <= BusB(5);
+ else
+ F_Out(Flag_X) <= Q_t(3);
+ F_Out(Flag_Y) <= Q_t(5);
+ end if;
+ if Q_t(7 downto 0) = "00000000" then
+ F_Out(Flag_Z) <= '1';
+ if Z16 = '1' then
+ F_Out(Flag_Z) <= F_In(Flag_Z); -- 16 bit ADC,SBC
+ end if;
+ else
+ F_Out(Flag_Z) <= '0';
+ end if;
+ F_Out(Flag_S) <= Q_t(7);
+ case ALU_Op(2 downto 0) is
+ when "000" | "001" | "010" | "011" | "111" => -- ADD, ADC, SUB, SBC, CP
+ when others =>
+ F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
+ Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
+ end case;
+ if Arith16 = '1' then
+ F_Out(Flag_S) <= F_In(Flag_S);
+ F_Out(Flag_Z) <= F_In(Flag_Z);
+ F_Out(Flag_P) <= F_In(Flag_P);
+ end if;
+ when "1100" =>
+ -- DAA
+ if Mode = 3 then
+ F_Out(Flag_H) <= '0';
+ F_Out(Flag_C) <= F_In(Flag_C);
+ DAA_Q(7 downto 0) := unsigned(BusA);
+ DAA_Q(8) := '0';
+ if F_In(Flag_N) = '0' then
+ -- After addition
+ -- Alow > 9 or H = 1
+ if DAA_Q(3 downto 0) > 9 or F_In(Flag_H) = '1' then
+ DAA_Q := DAA_Q + 6;
+ end if;
+ -- new Ahigh > 9 or C = 1
+ if DAA_Q(8 downto 4) > 9 or F_In(Flag_C) = '1' then
+ DAA_Q := DAA_Q + 96; -- 0x60
+ end if;
+ else
+ -- After subtraction
+ if F_In(Flag_H) = '1' then
+ DAA_Q := DAA_Q - 6;
+ if F_In(Flag_C) = '0' then
+ DAA_Q(8) := '0';
+ end if;
+ end if;
+ if F_In(Flag_C) = '1' then
+ DAA_Q := DAA_Q - 96; -- 0x60
+ end if;
+ end if;
+ else
+ F_Out(Flag_H) <= F_In(Flag_H);
+ F_Out(Flag_C) <= F_In(Flag_C);
+ DAA_Q(7 downto 0) := unsigned(BusA);
+ DAA_Q(8) := '0';
+ if F_In(Flag_N) = '0' then
+ -- After addition
+ -- Alow > 9 or H = 1
+ if DAA_Q(3 downto 0) > 9 or F_In(Flag_H) = '1' then
+ if (DAA_Q(3 downto 0) > 9) then
+ F_Out(Flag_H) <= '1';
+ else
+ F_Out(Flag_H) <= '0';
+ end if;
+ DAA_Q := DAA_Q + 6;
+ end if;
+ -- new Ahigh > 9 or C = 1
+ if DAA_Q(8 downto 4) > 9 or F_In(Flag_C) = '1' then
+ DAA_Q := DAA_Q + 96; -- 0x60
+ end if;
+ else
+ -- After subtraction
+ if DAA_Q(3 downto 0) > 9 or F_In(Flag_H) = '1' then
+ if DAA_Q(3 downto 0) > 5 then
+ F_Out(Flag_H) <= '0';
+ end if;
+ DAA_Q(7 downto 0) := DAA_Q(7 downto 0) - 6;
+ end if;
+ if unsigned(BusA) > 153 or F_In(Flag_C) = '1' then
+ DAA_Q := DAA_Q - 352; -- 0x160
+ end if;
+ end if;
+ end if;
+ F_Out(Flag_X) <= DAA_Q(3);
+ F_Out(Flag_Y) <= DAA_Q(5);
+ F_Out(Flag_C) <= F_In(Flag_C) or DAA_Q(8);
+ Q_t := std_logic_vector(DAA_Q(7 downto 0));
+ if DAA_Q(7 downto 0) = "00000000" then
+ F_Out(Flag_Z) <= '1';
+ else
+ F_Out(Flag_Z) <= '0';
+ end if;
+ F_Out(Flag_S) <= DAA_Q(7);
+ F_Out(Flag_P) <= not (DAA_Q(0) xor DAA_Q(1) xor DAA_Q(2) xor DAA_Q(3) xor
+ DAA_Q(4) xor DAA_Q(5) xor DAA_Q(6) xor DAA_Q(7));
+ when "1101" | "1110" =>
+ -- RLD, RRD
+ Q_t(7 downto 4) := BusA(7 downto 4);
+ if ALU_Op(0) = '1' then
+ Q_t(3 downto 0) := BusB(7 downto 4);
+ else
+ Q_t(3 downto 0) := BusB(3 downto 0);
+ end if;
+ F_Out(Flag_H) <= '0';
+ F_Out(Flag_N) <= '0';
+ F_Out(Flag_X) <= Q_t(3);
+ F_Out(Flag_Y) <= Q_t(5);
+ if Q_t(7 downto 0) = "00000000" then
+ F_Out(Flag_Z) <= '1';
+ else
+ F_Out(Flag_Z) <= '0';
+ end if;
+ F_Out(Flag_S) <= Q_t(7);
+ F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
+ Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
+ when "1001" =>
+ -- BIT
+ Q_t(7 downto 0) := BusB and BitMask;
+ F_Out(Flag_S) <= Q_t(7);
+ if Q_t(7 downto 0) = "00000000" then
+ F_Out(Flag_Z) <= '1';
+ F_Out(Flag_P) <= '1';
+ else
+ F_Out(Flag_Z) <= '0';
+ F_Out(Flag_P) <= '0';
+ end if;
+ F_Out(Flag_H) <= '1';
+ F_Out(Flag_N) <= '0';
+ if IR(2 downto 0) = "110" or XY_State /= "00" then
+ F_Out(Flag_X) <= WZ(11);
+ F_Out(Flag_Y) <= WZ(13);
+ else
+ F_Out(Flag_X) <= BusB(3);
+ F_Out(Flag_Y) <= BusB(5);
+ end if;
+ when "1010" =>
+ -- SET
+ Q_t(7 downto 0) := BusB or BitMask;
+ when "1011" =>
+ -- RES
+ Q_t(7 downto 0) := BusB and not BitMask;
+ when "1000" =>
+ -- ROT
+ case IR(5 downto 3) is
+ when "000" => -- RLC
+ Q_t(7 downto 1) := BusA(6 downto 0);
+ Q_t(0) := BusA(7);
+ F_Out(Flag_C) <= BusA(7);
+ when "010" => -- RL
+ Q_t(7 downto 1) := BusA(6 downto 0);
+ Q_t(0) := F_In(Flag_C);
+ F_Out(Flag_C) <= BusA(7);
+ when "001" => -- RRC
+ Q_t(6 downto 0) := BusA(7 downto 1);
+ Q_t(7) := BusA(0);
+ F_Out(Flag_C) <= BusA(0);
+ when "011" => -- RR
+ Q_t(6 downto 0) := BusA(7 downto 1);
+ Q_t(7) := F_In(Flag_C);
+ F_Out(Flag_C) <= BusA(0);
+ when "100" => -- SLA
+ Q_t(7 downto 1) := BusA(6 downto 0);
+ Q_t(0) := '0';
+ F_Out(Flag_C) <= BusA(7);
+ when "110" => -- SLL (Undocumented) / SWAP
+ if Mode = 3 then
+ Q_t(7 downto 4) := BusA(3 downto 0);
+ Q_t(3 downto 0) := BusA(7 downto 4);
+ F_Out(Flag_C) <= '0';
+ else
+ Q_t(7 downto 1) := BusA(6 downto 0);
+ Q_t(0) := '1';
+ F_Out(Flag_C) <= BusA(7);
+ end if;
+ when "101" => -- SRA
+ Q_t(6 downto 0) := BusA(7 downto 1);
+ Q_t(7) := BusA(7);
+ F_Out(Flag_C) <= BusA(0);
+ when others => -- SRL
+ Q_t(6 downto 0) := BusA(7 downto 1);
+ Q_t(7) := '0';
+ F_Out(Flag_C) <= BusA(0);
+ end case;
+ F_Out(Flag_H) <= '0';
+ F_Out(Flag_N) <= '0';
+ F_Out(Flag_X) <= Q_t(3);
+ F_Out(Flag_Y) <= Q_t(5);
+ F_Out(Flag_S) <= Q_t(7);
+ if Q_t(7 downto 0) = "00000000" then
+ F_Out(Flag_Z) <= '1';
+ else
+ F_Out(Flag_Z) <= '0';
+ end if;
+ F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
+ Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
+ if ISet = "00" then
+ F_Out(Flag_P) <= F_In(Flag_P);
+ F_Out(Flag_S) <= F_In(Flag_S);
+ F_Out(Flag_Z) <= F_In(Flag_Z);
+ end if;
+ if Mode = 3 and Rot_Akku = '1' then
+ F_Out(Flag_Z) <= '0';
+ end if;
+ when others =>
+ null;
+ end case;
+ Q <= Q_t;
+ end process;
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_MCode.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_MCode.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..554ec9b5bbfdb3fe2fa03a92a2822e3820c00256
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_MCode.vhd
@@ -0,0 +1,2289 @@
+--------------------------------------------------------------------------------
+-- ****
+-- T80(c) core. Attempt to finish all undocumented features and provide
+-- accurate timings.
+-- Version 350.
+-- Copyright (c) 2018 Sorgelig
+-- Test passed: ZEXDOC, ZEXALL, Z80Full(*), Z80memptr
+-- (*) Currently only SCF and CCF instructions aren't passed X/Y flags check as
+-- correct implementation is still unclear.
+--
+-- ****
+-- T80(b) core. In an effort to merge and maintain bug fixes ....
+--
+-- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
+-- Ver 300 started tidyup
+-- MikeJ March 2005
+-- Latest version from www.fpgaarcade.com (original www.opencores.org)
+--
+-- ****
+-- Z80 compatible microprocessor core
+--
+-- Version : 0250
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- Limitations :
+--
+-- File history :
+--
+-- 0208 : First complete release
+-- 0211 : Fixed IM 1
+-- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
+-- 0235 : Added IM 2 fix by Mike Johnson
+-- 0238 : Added NoRead signal
+-- 0238b: Fixed instruction timing for POP and DJNZ
+-- 0240 : Added (IX/IY+d) states, removed op-codes from mode 2 and added all remaining mode 3 op-codes
+-- 0240mj1 fix for HL inc/dec for INI, IND, INIR, INDR, OUTI, OUTD, OTIR, OTDR
+-- 0242 : Fixed I/O instruction timing, cleanup
+-- 0250 : Added R800 Multiplier by TobiFlex 2017.10.15
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+use work.T80_Pack.all;
+
+entity T80_MCode is
+ generic(
+ Mode : integer := 0;
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ IR : in std_logic_vector(7 downto 0);
+ ISet : in std_logic_vector(1 downto 0);
+ MCycle : in std_logic_vector(2 downto 0);
+ F : in std_logic_vector(7 downto 0);
+ NMICycle : in std_logic;
+ IntCycle : in std_logic;
+ XY_State : in std_logic_vector(1 downto 0);
+ MCycles : out std_logic_vector(2 downto 0);
+ TStates : out std_logic_vector(2 downto 0);
+ Prefix : out std_logic_vector(1 downto 0); -- None,CB,ED,DD/FD
+ Inc_PC : out std_logic;
+ Inc_WZ : out std_logic;
+ IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
+ Read_To_Reg : out std_logic;
+ Read_To_Acc : out std_logic;
+ Set_BusA_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
+ Set_BusB_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
+ ALU_Op : out std_logic_vector(3 downto 0);
+ -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
+ Save_ALU : out std_logic;
+ Rot_Akku : out std_logic;
+ PreserveC : out std_logic;
+ Arith16 : out std_logic;
+ Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
+ IORQ : out std_logic;
+ Jump : out std_logic;
+ JumpE : out std_logic;
+ JumpXY : out std_logic;
+ Call : out std_logic;
+ RstP : out std_logic;
+ LDZ : out std_logic;
+ LDW : out std_logic;
+ LDSPHL : out std_logic;
+ LDHLSP : out std_logic;
+ ADDSPdd : out std_logic;
+ Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
+ ExchangeDH : out std_logic;
+ ExchangeRp : out std_logic;
+ ExchangeAF : out std_logic;
+ ExchangeRS : out std_logic;
+ ExchangeWH : out std_logic;
+ I_DJNZ : out std_logic;
+ I_CPL : out std_logic;
+ I_CCF : out std_logic;
+ I_SCF : out std_logic;
+ I_RETN : out std_logic;
+ I_BT : out std_logic;
+ I_BC : out std_logic;
+ I_BTR : out std_logic;
+ I_RLD : out std_logic;
+ I_RRD : out std_logic;
+ I_INRC : out std_logic;
+ I_MULUB : out std_logic;
+ I_MULU : out std_logic;
+ SetWZ : out std_logic_vector(1 downto 0);
+ SetDI : out std_logic;
+ SetEI : out std_logic;
+ IMode : out std_logic_vector(1 downto 0);
+ Halt : out std_logic;
+ NoRead : out std_logic;
+ Write : out std_logic;
+ R800_mode : in std_logic;
+ No_PC : out std_logic;
+ XYbit_undoc : out std_logic
+ );
+end T80_MCode;
+
+architecture rtl of T80_MCode is
+
+ function is_cc_true(
+ F : std_logic_vector(7 downto 0);
+ cc : bit_vector(2 downto 0)
+ ) return boolean is
+ begin
+ if Mode = 3 then
+ case cc is
+ when "000" => return F(Flag_Z) = '0'; -- NZ
+ when "001" => return F(Flag_Z) = '1'; -- Z
+ when "010" => return F(Flag_C) = '0'; -- NC
+ when "011" => return F(Flag_C) = '1'; -- C
+ when "100" => return false;
+ when "101" => return false;
+ when "110" => return false;
+ when "111" => return false;
+ end case;
+ else
+ case cc is
+ when "000" => return F(Flag_Z) = '0'; -- NZ
+ when "001" => return F(Flag_Z) = '1'; -- Z
+ when "010" => return F(Flag_C) = '0'; -- NC
+ when "011" => return F(Flag_C) = '1'; -- C
+ when "100" => return F(Flag_P) = '0'; -- PO
+ when "101" => return F(Flag_P) = '1'; -- PE
+ when "110" => return F(Flag_S) = '0'; -- P
+ when "111" => return F(Flag_S) = '1'; -- M
+ end case;
+ end if;
+ end;
+
+begin
+
+ process (IR, ISet, MCycle, F, NMICycle, IntCycle, XY_State, R800_mode)
+ variable DDD : std_logic_vector(2 downto 0);
+ variable SSS : std_logic_vector(2 downto 0);
+ variable DPair : std_logic_vector(1 downto 0);
+ variable IRB : bit_vector(7 downto 0);
+ begin
+ DDD := IR(5 downto 3);
+ SSS := IR(2 downto 0);
+ DPair := IR(5 downto 4);
+ IRB := to_bitvector(IR);
+
+ MCycles <= "001";
+ if MCycle = "001" then
+ TStates <= "100";
+ else
+ TStates <= "011";
+ end if;
+ Prefix <= "00";
+ Inc_PC <= '0';
+ Inc_WZ <= '0';
+ IncDec_16 <= "0000";
+ Read_To_Acc <= '0';
+ Read_To_Reg <= '0';
+ Set_BusB_To <= "0000";
+ Set_BusA_To <= "0000";
+ ALU_Op <= "0" & IR(5 downto 3);
+ Save_ALU <= '0';
+ Rot_Akku <= '0';
+ PreserveC <= '0';
+ Arith16 <= '0';
+ IORQ <= '0';
+ Set_Addr_To <= aNone;
+ Jump <= '0';
+ JumpE <= '0';
+ JumpXY <= '0';
+ Call <= '0';
+ RstP <= '0';
+ LDZ <= '0';
+ LDW <= '0';
+ LDSPHL <= '0';
+ LDHLSP <= '0';
+ ADDSPdd <= '0';
+ Special_LD <= "000";
+ ExchangeDH <= '0';
+ ExchangeRp <= '0';
+ ExchangeAF <= '0';
+ ExchangeRS <= '0';
+ ExchangeWH <= '0';
+ I_DJNZ <= '0';
+ I_CPL <= '0';
+ I_CCF <= '0';
+ I_SCF <= '0';
+ I_RETN <= '0';
+ I_BT <= '0';
+ I_BC <= '0';
+ I_BTR <= '0';
+ I_RLD <= '0';
+ I_RRD <= '0';
+ I_INRC <= '0';
+ I_MULUB <= '0';
+ I_MULU <= '0';
+ SetDI <= '0';
+ SetEI <= '0';
+ IMode <= "11";
+ Halt <= '0';
+ NoRead <= '0';
+ Write <= '0';
+ No_PC <= '0';
+ XYbit_undoc <= '0';
+ SetWZ <= "00";
+
+ case ISet is
+ when "00" =>
+
+------------------------------------------------------------------------------
+--
+-- Unprefixed instructions
+--
+------------------------------------------------------------------------------
+
+ case IRB is
+-- 8 BIT LOAD GROUP
+ when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
+ |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
+ |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
+ |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
+ |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
+ |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
+ |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
+ -- LD r,r'
+ Set_BusB_To(2 downto 0) <= SSS;
+ ExchangeRp <= '1';
+ Set_BusA_To(2 downto 0) <= DDD;
+ Read_To_Reg <= '1';
+ when "00000110"|"00001110"|"00010110"|"00011110"|"00100110"|"00101110"|"00111110" =>
+ -- LD r,n
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_BusA_To(2 downto 0) <= DDD;
+ Read_To_Reg <= '1';
+ when others => null;
+ end case;
+ when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01111110" =>
+ -- LD r,(HL)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Set_BusA_To(2 downto 0) <= DDD;
+ Read_To_Reg <= '1';
+ when others => null;
+ end case;
+ when "01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111" =>
+ -- LD (HL),r
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusB_To(3) <= '0';
+ when 2 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "00110110" =>
+ -- LD (HL),n
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_Addr_To <= aXY;
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusB_To(3) <= '0';
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "00001010" =>
+ -- LD A,(BC)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ when 2 =>
+ Read_To_Acc <= '1';
+ when others => null;
+ end case;
+ when "00011010" =>
+ -- LD A,(DE)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aDE;
+ when 2 =>
+ Read_To_Acc <= '1';
+ when others => null;
+ end case;
+ when "00111010" =>
+ if Mode = 3 then
+ -- LDD A,(HL)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Read_To_Acc <= '1';
+ IncDec_16 <= "1110";
+ when others => null;
+ end case;
+ else
+ -- LD A,(nn)
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ when 4 =>
+ Read_To_Acc <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "00000010" =>
+ -- LD (BC),A
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ Set_BusB_To <= "0111";
+ SetWZ <= "10";
+ when 2 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "00010010" =>
+ -- LD (DE),A
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aDE;
+ Set_BusB_To <= "0111";
+ SetWZ <= "10";
+ when 2 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "00110010" =>
+ if Mode = 3 then
+ -- LDD (HL),A
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ Set_BusB_To <= "0111";
+ when 2 =>
+ Write <= '1';
+ IncDec_16 <= "1110";
+ when others => null;
+ end case;
+ else
+ -- LD (nn),A
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ SetWZ <= "10";
+ Inc_PC <= '1';
+ Set_BusB_To <= "0111";
+ when 4 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+
+-- 16 BIT LOAD GROUP
+ when "00000001"|"00010001"|"00100001"|"00110001" =>
+ -- LD dd,nn
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Read_To_Reg <= '1';
+ if DPAIR = "11" then
+ Set_BusA_To(3 downto 0) <= "1000";
+ else
+ Set_BusA_To(2 downto 1) <= DPAIR;
+ Set_BusA_To(0) <= '1';
+ end if;
+ when 3 =>
+ Inc_PC <= '1';
+ Read_To_Reg <= '1';
+ if DPAIR = "11" then
+ Set_BusA_To(3 downto 0) <= "1001";
+ else
+ Set_BusA_To(2 downto 1) <= DPAIR;
+ Set_BusA_To(0) <= '0';
+ end if;
+ when others => null;
+ end case;
+ when "00101010" =>
+ if Mode = 3 then
+ -- LDI A,(HL)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Read_To_Acc <= '1';
+ IncDec_16 <= "0110";
+ when others => null;
+ end case;
+ else
+ -- LD HL,(nn)
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ LDW <= '1';
+ when 4 =>
+ Set_BusA_To(2 downto 0) <= "101"; -- L
+ Read_To_Reg <= '1';
+ Inc_WZ <= '1';
+ Set_Addr_To <= aZI;
+ when 5 =>
+ Set_BusA_To(2 downto 0) <= "100"; -- H
+ Read_To_Reg <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "00100010" =>
+ if Mode = 3 then
+ -- LDI (HL),A
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ Set_BusB_To <= "0111";
+ when 2 =>
+ Write <= '1';
+ IncDec_16 <= "0110";
+ when others => null;
+ end case;
+ else
+ -- LD (nn),HL
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ LDW <= '1';
+ Set_BusB_To <= "0101"; -- L
+ when 4 =>
+ Inc_WZ <= '1';
+ Set_Addr_To <= aZI;
+ Write <= '1';
+ Set_BusB_To <= "0100"; -- H
+ when 5 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "11111001" =>
+ -- LD SP,HL
+ if Mode = 3 then
+ MCycles <= "010";
+ if MCycle = "010" then
+ LDSPHL <= '1';
+ end if;
+ else
+ TStates <= "110";
+ LDSPHL <= '1';
+ end if;
+ when "11000101"|"11010101"|"11100101"|"11110101" =>
+ -- PUSH qq
+ if Mode = 3 then
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_TO <= aSP;
+ if DPAIR = "11" then
+ Set_BusB_To <= "0111";
+ else
+ Set_BusB_To(2 downto 1) <= DPAIR;
+ Set_BusB_To(0) <= '0';
+ Set_BusB_To(3) <= '0';
+ end if;
+ when 3 =>
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ if DPAIR = "11" then
+ Set_BusB_To <= "1011";
+ else
+ Set_BusB_To(2 downto 1) <= DPAIR;
+ Set_BusB_To(0) <= '1';
+ Set_BusB_To(3) <= '0';
+ end if;
+ Write <= '1';
+ when 4 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ else
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_TO <= aSP;
+ if DPAIR = "11" then
+ Set_BusB_To <= "0111";
+ else
+ Set_BusB_To(2 downto 1) <= DPAIR;
+ Set_BusB_To(0) <= '0';
+ Set_BusB_To(3) <= '0';
+ end if;
+ when 2 =>
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ if DPAIR = "11" then
+ Set_BusB_To <= "1011";
+ else
+ Set_BusB_To(2 downto 1) <= DPAIR;
+ Set_BusB_To(0) <= '1';
+ Set_BusB_To(3) <= '0';
+ end if;
+ Write <= '1';
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "11000001"|"11010001"|"11100001"|"11110001" =>
+ -- POP qq
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aSP;
+ when 2 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ Read_To_Reg <= '1';
+ if DPAIR = "11" then
+ Set_BusA_To(3 downto 0) <= "1011";
+ else
+ Set_BusA_To(2 downto 1) <= DPAIR;
+ Set_BusA_To(0) <= '1';
+ end if;
+ when 3 =>
+ IncDec_16 <= "0111";
+ Read_To_Reg <= '1';
+ if DPAIR = "11" then
+ Set_BusA_To(3 downto 0) <= "0111";
+ else
+ Set_BusA_To(2 downto 1) <= DPAIR;
+ Set_BusA_To(0) <= '0';
+ end if;
+ when others => null;
+ end case;
+
+-- EXCHANGE, BLOCK TRANSFER AND SEARCH GROUP
+ when "11101011" =>
+ if Mode /= 3 then
+ -- EX DE,HL
+ ExchangeDH <= '1';
+ end if;
+ when "00001000" =>
+ if Mode = 3 then
+ -- LD (nn),SP
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ LDW <= '1';
+ Set_BusB_To <= "1000";
+ when 4 =>
+ Inc_WZ <= '1';
+ Set_Addr_To <= aZI;
+ Write <= '1';
+ Set_BusB_To <= "1001";
+ when 5 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ elsif Mode < 2 then
+ -- EX AF,AF'
+ ExchangeAF <= '1';
+ end if;
+ when "11011001" =>
+ if Mode = 3 then
+ -- RETI
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_TO <= aSP;
+ when 2 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 3 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ --I_RETN <= '1';
+ SetEI <= '1';
+ when others => null;
+ end case;
+ elsif Mode < 2 then
+ -- EXX
+ ExchangeRS <= '1';
+ end if;
+ when "11100011" =>
+ if Mode /= 3 then
+ -- EX (SP),HL
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aSP;
+ when 2 =>
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ IncDec_16 <= "0111"; -- SP <= SP+1
+ when 3 =>
+ TStates <= "100";
+ Set_BusB_To <= "0100";
+ Set_Addr_To <= aSP;
+ LDW <= '1';
+ when 4 =>
+ Set_BusB_To <= "0101";
+ Write <= '1';
+ IncDec_16 <= "1111"; -- SP <= SP-1
+ Set_Addr_To <= aSP;
+ when 5 =>
+ ExchangeWH <= '1'; -- save WZ to HL
+ TStates <= "101";
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+
+-- 8 BIT ARITHMETIC AND LOGICAL GROUP
+ when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
+ |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
+ |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
+ |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
+ |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
+ |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
+ |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
+ |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
+ -- ADD A,r
+ -- ADC A,r
+ -- SUB A,r
+ -- SBC A,r
+ -- AND A,r
+ -- OR A,r
+ -- XOR A,r
+ -- CP A,r
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusA_To(2 downto 0) <= "111";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
+ -- ADD A,(HL)
+ -- ADC A,(HL)
+ -- SUB A,(HL)
+ -- SBC A,(HL)
+ -- AND A,(HL)
+ -- OR A,(HL)
+ -- XOR A,(HL)
+ -- CP A,(HL)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusA_To(2 downto 0) <= "111";
+ when others => null;
+ end case;
+ when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
+ -- ADD A,n
+ -- ADC A,n
+ -- SUB A,n
+ -- SBC A,n
+ -- AND A,n
+ -- OR A,n
+ -- XOR A,n
+ -- CP A,n
+ MCycles <= "010";
+ if MCycle = "010" then
+ Inc_PC <= '1';
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusA_To(2 downto 0) <= "111";
+ end if;
+ when "00000100"|"00001100"|"00010100"|"00011100"|"00100100"|"00101100"|"00111100" =>
+ -- INC r
+ Set_BusB_To <= "1010";
+ Set_BusA_To(2 downto 0) <= DDD;
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ PreserveC <= '1';
+ ALU_Op <= "0000";
+ when "00110100" =>
+ -- INC (HL)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ TStates <= "100";
+ Set_Addr_To <= aXY;
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ PreserveC <= '1';
+ ALU_Op <= "0000";
+ Set_BusB_To <= "1010";
+ Set_BusA_To(2 downto 0) <= DDD;
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "00000101"|"00001101"|"00010101"|"00011101"|"00100101"|"00101101"|"00111101" =>
+ -- DEC r
+ Set_BusB_To <= "1010";
+ Set_BusA_To(2 downto 0) <= DDD;
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ PreserveC <= '1';
+ ALU_Op <= "0010";
+ when "00110101" =>
+ -- DEC (HL)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ TStates <= "100";
+ Set_Addr_To <= aXY;
+ ALU_Op <= "0010";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ PreserveC <= '1';
+ Set_BusB_To <= "1010";
+ Set_BusA_To(2 downto 0) <= DDD;
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+
+-- GENERAL PURPOSE ARITHMETIC AND CPU CONTROL GROUPS
+ when "00100111" =>
+ -- DAA
+ Set_BusA_To(2 downto 0) <= "111";
+ Read_To_Reg <= '1';
+ ALU_Op <= "1100";
+ Save_ALU <= '1';
+ when "00101111" =>
+ -- CPL
+ I_CPL <= '1';
+ when "00111111" =>
+ -- CCF
+ I_CCF <= '1';
+ when "00110111" =>
+ -- SCF
+ I_SCF <= '1';
+ when "00000000" =>
+ if NMICycle = '1' then
+ -- NMI
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1101";
+ when 2 =>
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ elsif IntCycle = '1' then
+ -- INT (IM 2)
+ if Mode = 3 then
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "110";
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1101";
+ when 2 =>
+ Write <= '1';
+ when 3 => -- GB: interrupt is acknowledged on MCycle 3
+ LDZ <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 4 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ else
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1101";
+ when 2 =>
+ --TStates <= "100";
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 3 =>
+ --TStates <= "100";
+ Write <= '1';
+ when 4 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 5 =>
+ Jump <= '1';
+ when others => null;
+ end case;
+ end if;
+ else
+ -- NOP
+ end if;
+ when "01110110" =>
+ -- HALT
+ Halt <= '1';
+ when "11110011" =>
+ -- DI
+ SetDI <= '1';
+ when "11111011" =>
+ -- EI
+ SetEI <= '1';
+
+-- 16 BIT ARITHMETIC GROUP
+ when "00001001"|"00011001"|"00101001"|"00111001" =>
+ -- ADD HL,ss
+ if Mode = 3 then
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ NoRead <= '1';
+ ALU_Op <= "0000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusA_To(2 downto 0) <= "101";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '1';
+ when others =>
+ Set_BusB_To <= "1000";
+ end case;
+ TStates <= "100";
+ Arith16 <= '1';
+ SetWZ <= "11";
+ when 2 =>
+ NoRead <= '1';
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0001";
+ Set_BusA_To(2 downto 0) <= "100";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ when others =>
+ Set_BusB_To <= "1001";
+ end case;
+ Arith16 <= '1';
+ when others =>
+ end case;
+ else
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ No_PC <= '1';
+ when 2 =>
+ NoRead <= '1';
+ ALU_Op <= "0000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusA_To(2 downto 0) <= "101";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '1';
+ when others =>
+ Set_BusB_To <= "1000";
+ end case;
+ TStates <= "100";
+ Arith16 <= '1';
+ SetWZ <= "11";
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0001";
+ Set_BusA_To(2 downto 0) <= "100";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ when others =>
+ Set_BusB_To <= "1001";
+ end case;
+ Arith16 <= '1';
+ when others =>
+ end case;
+ end if;
+ when "00000011"|"00010011"|"00100011"|"00110011" =>
+ -- INC ss
+ if Mode = 3 then
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ IncDec_16(3 downto 2) <= "01";
+ IncDec_16(1 downto 0) <= DPair;
+ when others =>
+ end case;
+ else
+ TStates <= "110";
+ IncDec_16(3 downto 2) <= "01";
+ IncDec_16(1 downto 0) <= DPair;
+ end if;
+ when "00001011"|"00011011"|"00101011"|"00111011" =>
+ -- DEC ss
+ if Mode = 3 then
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ IncDec_16(3 downto 2) <= "11";
+ IncDec_16(1 downto 0) <= DPair;
+ when others =>
+ end case;
+ else
+ TStates <= "110";
+ IncDec_16(3 downto 2) <= "11";
+ IncDec_16(1 downto 0) <= DPair;
+ end if;
+
+-- ROTATE AND SHIFT GROUP
+ when "00000111"
+ -- RLCA
+ |"00010111"
+ -- RLA
+ |"00001111"
+ -- RRCA
+ |"00011111" =>
+ -- RRA
+ Set_BusA_To(2 downto 0) <= "111";
+ ALU_Op <= "1000";
+ Read_To_Reg <= '1';
+ Rot_Akku <= '1';
+ Save_ALU <= '1';
+
+-- JUMP GROUP
+ when "11000011" =>
+ -- JP nn
+ if Mode = 3 then
+ MCycles <= "100";
+ else
+ MCycles <= "011";
+ end if;
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Inc_PC <= '1';
+ Jump <= '1';
+ if Mode /= 3 then
+ LDW <= '1';
+ end if;
+ when others => null;
+ end case;
+ when "11000010"|"11001010"|"11010010"|"11011010"|"11100010"|"11101010"|"11110010"|"11111010" =>
+ if IR(5) = '1' and Mode = 3 then
+ case IRB(4 downto 3) is
+ when "00" =>
+ -- LD ($FF00+C),A
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ Set_BusB_To <= "0111";
+ IORQ <= '1'; --TH must be earlier to be stable when address is generated
+ when 2 =>
+ Write <= '1';
+ when others =>
+ end case;
+ when "01" =>
+ -- LD (nn),A
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ Set_BusB_To <= "0111";
+ when 4 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "10" =>
+ -- LD A,($FF00+C)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ IORQ <= '1'; --TH must be earlier to be stable when address is generated
+ when 2 =>
+ Read_To_Acc <= '1';
+ when others =>
+ end case;
+ when "11" =>
+ -- LD A,(nn)
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ when 4 =>
+ Read_To_Acc <= '1';
+ when others => null;
+ end case;
+ end case;
+ else
+ -- JP cc,nn
+ if Mode = 3 then
+ MCycles <= "100";
+ else
+ MCycles <= "011";
+ end if;
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ if Mode /= 3 then
+ LDW <= '1';
+ end if;
+ Inc_PC <= '1';
+ if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
+ Jump <= '1';
+ elsif Mode = 3 then
+ MCycles <= "011";
+ end if;
+ when others => null;
+ end case;
+ end if;
+ when "00011000" =>
+ if Mode /= 2 then
+ -- JR e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+ when "00111000" =>
+ if Mode /= 2 then
+ -- JR C,e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ if F(Flag_C) = '0' then
+ MCycles <= "010";
+ else
+ No_PC <= '1';
+ end if;
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+ when "00110000" =>
+ if Mode /= 2 then
+ -- JR NC,e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ if F(Flag_C) = '1' then
+ MCycles <= "010";
+ else
+ No_PC <= '1';
+ end if;
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+ when "00101000" =>
+ if Mode /= 2 then
+ -- JR Z,e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ if F(Flag_Z) = '0' then
+ MCycles <= "010";
+ else
+ No_PC <= '1';
+ end if;
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+ when "00100000" =>
+ if Mode /= 2 then
+ -- JR NZ,e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ if F(Flag_Z) = '1' then
+ MCycles <= "010";
+ else
+ No_PC <= '1';
+ end if;
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+ when "11101001" =>
+ -- JP (HL)
+ JumpXY <= '1';
+ when "00010000" =>
+ if Mode = 3 then -- STOP and skip next byte
+ MCycles <= "010";
+ I_DJNZ <= '1';
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ when others => null;
+ end case;
+ elsif Mode < 2 then
+ -- DJNZ,e
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ I_DJNZ <= '1';
+ Set_BusB_To <= "1010";
+ Set_BusA_To(2 downto 0) <= "000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0010";
+ when 2 =>
+ I_DJNZ <= '1';
+ Inc_PC <= '1';
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ JumpE <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ end if;
+
+-- CALL AND RETURN GROUP
+ when "11001101" =>
+ -- CALL nn
+ if Mode = 3 then
+ MCycles <= "110";
+ else
+ MCycles <= "101";
+ end if;
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ IncDec_16 <= "1111";
+ Inc_PC <= '1';
+ TStates <= "100";
+ Set_Addr_To <= aSP;
+ LDW <= '1';
+ Set_BusB_To <= "1101";
+ when 4 =>
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 5 =>
+ Write <= '1';
+ Call <= '1';
+ when others => null;
+ end case;
+ when "11000100"|"11001100"|"11010100"|"11011100"|"11100100"|"11101100"|"11110100"|"11111100" =>
+ if IR(5) = '0' or Mode /= 3 then
+ -- CALL cc,nn
+ if Mode = 3 then
+ MCycles <= "110";
+ else
+ MCycles <= "101";
+ end if;
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Inc_PC <= '1';
+ LDW <= '1';
+ if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
+ IncDec_16 <= "1111";
+ Set_Addr_TO <= aSP;
+ TStates <= "100";
+ Set_BusB_To <= "1101";
+ else
+ MCycles <= "011";
+ end if;
+ when 4 =>
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 5 =>
+ Write <= '1';
+ Call <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "11001001" =>
+ -- RET
+ if Mode = 3 then
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Set_Addr_TO <= aSP;
+ when 3 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 4 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ when others => null;
+ end case;
+ else
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ --TStates <= "101";
+ Set_Addr_TO <= aSP;
+ when 2 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 3 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ when others => null;
+ end case;
+ end if;
+ when "11000000"|"11001000"|"11010000"|"11011000"|"11100000"|"11101000"|"11110000"|"11111000" =>
+ if IR(5) = '1' and Mode = 3 then
+ case IRB(4 downto 3) is
+ when "00" =>
+ -- LD ($FF00+nn),A
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_Addr_To <= aIOA;
+ Set_BusB_To <= "0111";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "01" =>
+ -- ADD SP,n
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 3 =>
+ Inc_PC <= '1';
+ ADDSPdd <= '1';
+ when others =>
+ end case;
+ when "10" =>
+ -- LD A,($FF00+nn)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_Addr_To <= aIOA;
+ when 3 =>
+ Read_To_Acc <= '1';
+ when others => null;
+ end case;
+ when "11" =>
+ -- LD HL,SP+n
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Inc_PC <= '1';
+ when 2 =>
+ LDHLSP <= '1';
+ Inc_PC <= '1';
+ when 3 =>
+ LDHLSP <= '1';
+ when others => null;
+ end case;
+ end case;
+ else
+ -- RET cc
+ if Mode = 3 then
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
+ Set_Addr_TO <= aSP;
+ else
+ MCycles <= "010";
+ end if;
+ TStates <= "101";
+ when 3 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 4 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ when others => null;
+ end case;
+ else
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ if is_cc_true(F, to_bitvector(IR(5 downto 3))) then
+ Set_Addr_TO <= aSP;
+ else
+ MCycles <= "001";
+ end if;
+ TStates <= "101";
+ when 2 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 3 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ when others => null;
+ end case;
+ end if;
+ end if;
+ when "11000111"|"11001111"|"11010111"|"11011111"|"11100111"|"11101111"|"11110111"|"11111111" =>
+ -- RST p
+ if Mode = 3 then
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1101";
+ when 3 =>
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 4 =>
+ Write <= '1';
+ RstP <= '1';
+ when others => null;
+ end case;
+ else
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1101";
+ when 2 =>
+ Write <= '1';
+ IncDec_16 <= "1111";
+ Set_Addr_To <= aSP;
+ Set_BusB_To <= "1100";
+ when 3 =>
+ Write <= '1';
+ RstP <= '1';
+ when others => null;
+ end case;
+ end if;
+
+-- INPUT AND OUTPUT GROUP
+ when "11011011" =>
+ if Mode /= 3 then
+ -- IN A,(n)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_Addr_To <= aIOA;
+ when 3 =>
+ Read_To_Acc <= '1';
+ IORQ <= '1';
+ when others => null;
+ end case;
+ end if;
+ when "11010011" =>
+ if Mode /= 3 then
+ -- OUT (n),A
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ Set_Addr_To <= aIOA;
+ Set_BusB_To <= "0111";
+ when 3 =>
+ Write <= '1';
+ IORQ <= '1';
+ when others => null;
+ end case;
+ end if;
+
+------------------------------------------------------------------------------
+------------------------------------------------------------------------------
+-- MULTIBYTE INSTRUCTIONS
+------------------------------------------------------------------------------
+------------------------------------------------------------------------------
+
+ when "11001011" =>
+ if Mode /= 2 then
+ Prefix <= "01";
+ end if;
+
+ when "11101101" =>
+ if Mode < 2 then
+ Prefix <= "10";
+ end if;
+
+ when "11011101"|"11111101" =>
+ if Mode < 2 then
+ Prefix <= "11";
+ end if;
+
+ end case;
+
+ when "01" =>
+
+------------------------------------------------------------------------------
+--
+-- CB prefixed instructions
+--
+------------------------------------------------------------------------------
+
+ Set_BusA_To(2 downto 0) <= IR(2 downto 0);
+ Set_BusB_To(2 downto 0) <= IR(2 downto 0);
+
+ case IRB is
+ when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000111"
+ |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010111"
+ |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001111"
+ |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011111"
+ |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100111"
+ |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101111"
+ |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110111"
+ |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111111" =>
+ -- RLC r
+ -- RL r
+ -- RRC r
+ -- RR r
+ -- SLA r
+ -- SRA r
+ -- SRL r
+ -- SLL r (Undocumented) / SWAP r
+ if XY_State="00" then
+ if MCycle = "001" then
+ ALU_Op <= "1000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ end if;
+ else
+ -- R/S (IX+d),Reg, undocumented
+ MCycles <= "011";
+ XYbit_undoc <= '1';
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7=>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+
+ when "00000110"|"00010110"|"00001110"|"00011110"|"00101110"|"00111110"|"00100110"|"00110110" =>
+ -- RLC (HL)
+ -- RL (HL)
+ -- RRC (HL)
+ -- RR (HL)
+ -- SRA (HL)
+ -- SRL (HL)
+ -- SLA (HL)
+ -- SLL (HL) (Undocumented) / SWAP (HL)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others =>
+ end case;
+ when "01000000"|"01000001"|"01000010"|"01000011"|"01000100"|"01000101"|"01000111"
+ |"01001000"|"01001001"|"01001010"|"01001011"|"01001100"|"01001101"|"01001111"
+ |"01010000"|"01010001"|"01010010"|"01010011"|"01010100"|"01010101"|"01010111"
+ |"01011000"|"01011001"|"01011010"|"01011011"|"01011100"|"01011101"|"01011111"
+ |"01100000"|"01100001"|"01100010"|"01100011"|"01100100"|"01100101"|"01100111"
+ |"01101000"|"01101001"|"01101010"|"01101011"|"01101100"|"01101101"|"01101111"
+ |"01110000"|"01110001"|"01110010"|"01110011"|"01110100"|"01110101"|"01110111"
+ |"01111000"|"01111001"|"01111010"|"01111011"|"01111100"|"01111101"|"01111111" =>
+ -- BIT b,r
+ if XY_State="00" then
+ if MCycle = "001" then
+ Set_BusB_To(2 downto 0) <= IR(2 downto 0);
+ ALU_Op <= "1001";
+ end if;
+ else
+ -- BIT b,(IX+d), undocumented
+ MCycles <= "010";
+ XYbit_undoc <= '1';
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7=>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1001";
+ TStates <= "100";
+ when others => null;
+ end case;
+ end if;
+
+ when "01000110"|"01001110"|"01010110"|"01011110"|"01100110"|"01101110"|"01110110"|"01111110" =>
+ -- BIT b,(HL)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1001";
+ TStates <= "100";
+ when others => null;
+ end case;
+ when "11000000"|"11000001"|"11000010"|"11000011"|"11000100"|"11000101"|"11000111"
+ |"11001000"|"11001001"|"11001010"|"11001011"|"11001100"|"11001101"|"11001111"
+ |"11010000"|"11010001"|"11010010"|"11010011"|"11010100"|"11010101"|"11010111"
+ |"11011000"|"11011001"|"11011010"|"11011011"|"11011100"|"11011101"|"11011111"
+ |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100111"
+ |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101111"
+ |"11110000"|"11110001"|"11110010"|"11110011"|"11110100"|"11110101"|"11110111"
+ |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111111" =>
+ -- SET b,r
+ if XY_State="00" then
+ if MCycle = "001" then
+ ALU_Op <= "1010";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ end if;
+ else
+ -- SET b,(IX+d),Reg, undocumented
+ MCycles <= "011";
+ XYbit_undoc <= '1';
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7=>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1010";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+
+ when "11000110"|"11001110"|"11010110"|"11011110"|"11100110"|"11101110"|"11110110"|"11111110" =>
+ -- SET b,(HL)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1010";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000111"
+ |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001111"
+ |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010111"
+ |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011111"
+ |"10100000"|"10100001"|"10100010"|"10100011"|"10100100"|"10100101"|"10100111"
+ |"10101000"|"10101001"|"10101010"|"10101011"|"10101100"|"10101101"|"10101111"
+ |"10110000"|"10110001"|"10110010"|"10110011"|"10110100"|"10110101"|"10110111"
+ |"10111000"|"10111001"|"10111010"|"10111011"|"10111100"|"10111101"|"10111111" =>
+ -- RES b,r
+ if XY_State="00" then
+ if MCycle = "001" then
+ ALU_Op <= "1011";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ end if;
+ else
+ -- RES b,(IX+d),Reg, undocumented
+ MCycles <= "011";
+ XYbit_undoc <= '1';
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7=>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1011";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end if;
+
+ when "10000110"|"10001110"|"10010110"|"10011110"|"10100110"|"10101110"|"10110110"|"10111110" =>
+ -- RES b,(HL)
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 | 7 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ ALU_Op <= "1011";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ when 3 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ end case;
+
+ when others =>
+
+------------------------------------------------------------------------------
+--
+-- ED prefixed instructions
+--
+------------------------------------------------------------------------------
+
+ case IRB is
+ when "00000000"|"00000001"|"00000010"|"00000011"|"00000100"|"00000101"|"00000110"|"00000111"
+ |"00001000"|"00001001"|"00001010"|"00001011"|"00001100"|"00001101"|"00001110"|"00001111"
+ |"00010000"|"00010001"|"00010010"|"00010011"|"00010100"|"00010101"|"00010110"|"00010111"
+ |"00011000"|"00011001"|"00011010"|"00011011"|"00011100"|"00011101"|"00011110"|"00011111"
+ |"00100000"|"00100001"|"00100010"|"00100011"|"00100100"|"00100101"|"00100110"|"00100111"
+ |"00101000"|"00101001"|"00101010"|"00101011"|"00101100"|"00101101"|"00101110"|"00101111"
+ |"00110000"|"00110001"|"00110010"|"00110011"|"00110100"|"00110101"|"00110110"|"00110111"
+ |"00111000"|"00111001"|"00111010"|"00111011"|"00111100"|"00111101"|"00111110"|"00111111"
+
+
+ |"10000000"|"10000001"|"10000010"|"10000011"|"10000100"|"10000101"|"10000110"|"10000111"
+ |"10001000"|"10001001"|"10001010"|"10001011"|"10001100"|"10001101"|"10001110"|"10001111"
+ |"10010000"|"10010001"|"10010010"|"10010011"|"10010100"|"10010101"|"10010110"|"10010111"
+ |"10011000"|"10011001"|"10011010"|"10011011"|"10011100"|"10011101"|"10011110"|"10011111"
+ | "10100100"|"10100101"|"10100110"|"10100111"
+ | "10101100"|"10101101"|"10101110"|"10101111"
+ | "10110100"|"10110101"|"10110110"|"10110111"
+ | "10111100"|"10111101"|"10111110"|"10111111"
+ |"11000000"| "11000010" |"11000100"|"11000101"|"11000110"|"11000111"
+ |"11001000"| "11001010"|"11001011"|"11001100"|"11001101"|"11001110"|"11001111"
+ |"11010000"| "11010010"|"11010011"|"11010100"|"11010101"|"11010110"|"11010111"
+ |"11011000"| "11011010"|"11011011"|"11011100"|"11011101"|"11011110"|"11011111"
+ |"11100000"|"11100001"|"11100010"|"11100011"|"11100100"|"11100101"|"11100110"|"11100111"
+ |"11101000"|"11101001"|"11101010"|"11101011"|"11101100"|"11101101"|"11101110"|"11101111"
+ |"11110000"|"11110001"|"11110010" |"11110100"|"11110101"|"11110110"|"11110111"
+ |"11111000"|"11111001"|"11111010"|"11111011"|"11111100"|"11111101"|"11111110"|"11111111" =>
+ null; -- NOP, undocumented
+ when "01110111"|"01111111" =>
+ -- NOP, undocumented
+ null;
+-- 8 BIT LOAD GROUP
+ when "01010111" =>
+ -- LD A,I
+ Special_LD <= "100";
+ TStates <= "101";
+ when "01011111" =>
+ -- LD A,R
+ Special_LD <= "101";
+ TStates <= "101";
+ when "01000111" =>
+ -- LD I,A
+ Special_LD <= "110";
+ TStates <= "101";
+ when "01001111" =>
+ -- LD R,A
+ Special_LD <= "111";
+ TStates <= "101";
+-- 16 BIT LOAD GROUP
+ when "01001011"|"01011011"|"01101011"|"01111011" =>
+ -- LD dd,(nn)
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ LDW <= '1';
+ when 4 =>
+ Read_To_Reg <= '1';
+ if IR(5 downto 4) = "11" then
+ Set_BusA_To <= "1000";
+ else
+ Set_BusA_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusA_To(0) <= '1';
+ end if;
+ Inc_WZ <= '1';
+ Set_Addr_To <= aZI;
+ when 5 =>
+ Read_To_Reg <= '1';
+ if IR(5 downto 4) = "11" then
+ Set_BusA_To <= "1001";
+ else
+ Set_BusA_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusA_To(0) <= '0';
+ end if;
+ when others => null;
+ end case;
+ when "01000011"|"01010011"|"01100011"|"01110011" =>
+ -- LD (nn),dd
+ MCycles <= "101";
+ case to_integer(unsigned(MCycle)) is
+ when 2 =>
+ Inc_PC <= '1';
+ LDZ <= '1';
+ when 3 =>
+ Set_Addr_To <= aZI;
+ Inc_PC <= '1';
+ LDW <= '1';
+ if IR(5 downto 4) = "11" then
+ Set_BusB_To <= "1000";
+ else
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '1';
+ Set_BusB_To(3) <= '0';
+ end if;
+ when 4 =>
+ Inc_WZ <= '1';
+ Set_Addr_To <= aZI;
+ Write <= '1';
+ if IR(5 downto 4) = "11" then
+ Set_BusB_To <= "1001";
+ else
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '0';
+ Set_BusB_To(3) <= '0';
+ end if;
+ when 5 =>
+ Write <= '1';
+ when others => null;
+ end case;
+ when "10100000" | "10101000" | "10110000" | "10111000" =>
+ -- LDI, LDD, LDIR, LDDR
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ IncDec_16 <= "1100"; -- BC
+ when 2 =>
+ Set_BusB_To <= "0110";
+ Set_BusA_To(2 downto 0) <= "111";
+ ALU_Op <= "0000";
+ Set_Addr_To <= aDE;
+ if IR(3) = '0' then
+ IncDec_16 <= "0110"; -- IX
+ else
+ IncDec_16 <= "1110";
+ end if;
+ when 3 =>
+ I_BT <= '1';
+ TStates <= "101";
+ Write <= '1';
+ if IR(3) = '0' then
+ IncDec_16 <= "0101"; -- DE
+ else
+ IncDec_16 <= "1101";
+ end if;
+ No_PC <= '1';
+ when 4 =>
+ NoRead <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ when "10100001" | "10101001" | "10110001" | "10111001" =>
+ -- CPI, CPD, CPIR, CPDR
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ IncDec_16 <= "1100"; -- BC
+ when 2 =>
+ Set_BusB_To <= "0110";
+ Set_BusA_To(2 downto 0) <= "111";
+ ALU_Op <= "0111";
+ Save_ALU <= '1';
+ PreserveC <= '1';
+ if IR(3) = '0' then
+ IncDec_16 <= "0110";
+ else
+ IncDec_16 <= "1110";
+ end if;
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ I_BC <= '1';
+ TStates <= "101";
+ No_PC <= '1';
+ when 4 =>
+ NoRead <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ when "01000100"|"01001100"|"01010100"|"01011100"|"01100100"|"01101100"|"01110100"|"01111100" =>
+ -- NEG
+ Alu_OP <= "0010";
+ Set_BusB_To <= "0111";
+ Set_BusA_To <= "1010";
+ Read_To_Acc <= '1';
+ Save_ALU <= '1';
+ when "01000110"|"01001110"|"01100110"|"01101110" =>
+ -- IM 0
+ IMode <= "00";
+ when "01010110"|"01110110" =>
+ -- IM 1
+ IMode <= "01";
+ when "01011110"|"01111110" =>
+ -- IM 2
+ IMode <= "10";
+-- 16 bit arithmetic
+ when "01001010"|"01011010"|"01101010"|"01111010" =>
+ -- ADC HL,ss
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ No_PC <= '1';
+ when 2 =>
+ NoRead <= '1';
+ ALU_Op <= "0001";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusA_To(2 downto 0) <= "101";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '1';
+ when others =>
+ Set_BusB_To <= "1000";
+ end case;
+ TStates <= "100";
+ SetWZ <= "11";
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0001";
+ Set_BusA_To(2 downto 0) <= "100";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '0';
+ when others =>
+ Set_BusB_To <= "1001";
+ end case;
+ when others =>
+ end case;
+ when "01000010"|"01010010"|"01100010"|"01110010" =>
+ -- SBC HL,ss
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ No_PC <= '1';
+ when 2 =>
+ NoRead <= '1';
+ ALU_Op <= "0011";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusA_To(2 downto 0) <= "101";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ Set_BusB_To(0) <= '1';
+ when others =>
+ Set_BusB_To <= "1000";
+ end case;
+ TStates <= "100";
+ SetWZ <= "11";
+ No_PC <= '1';
+ when 3 =>
+ NoRead <= '1';
+ ALU_Op <= "0011";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ Set_BusA_To(2 downto 0) <= "100";
+ case to_integer(unsigned(IR(5 downto 4))) is
+ when 0|1|2 =>
+ Set_BusB_To(2 downto 1) <= IR(5 downto 4);
+ when others =>
+ Set_BusB_To <= "1001";
+ end case;
+ when others =>
+ end case;
+ when "01101111" =>
+ -- RLD -- Read in M2, not M3! fixed by Sorgelig
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Read_To_Reg <= '1';
+ Set_BusB_To(2 downto 0) <= "110";
+ Set_BusA_To(2 downto 0) <= "111";
+ ALU_Op <= "1101";
+ Save_ALU <= '1';
+ No_PC <= '1';
+ when 3 =>
+ TStates <= "100";
+ I_RLD <= '1';
+ NoRead <= '1';
+ Set_Addr_To <= aXY;
+ when 4 =>
+ Write <= '1';
+ when others =>
+ end case;
+ when "01100111" =>
+ -- RRD -- Read in M2, not M3! fixed by Sorgelig
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aXY;
+ when 2 =>
+ Read_To_Reg <= '1';
+ Set_BusB_To(2 downto 0) <= "110";
+ Set_BusA_To(2 downto 0) <= "111";
+ ALU_Op <= "1110";
+ Save_ALU <= '1';
+ No_PC <= '1';
+ when 3 =>
+ TStates <= "100";
+ I_RRD <= '1';
+ NoRead <= '1';
+ Set_Addr_To <= aXY;
+ when 4 =>
+ Write <= '1';
+ when others =>
+ end case;
+ when "01000101"|"01001101"|"01010101"|"01011101"|"01100101"|"01101101"|"01110101"|"01111101" =>
+ -- RETI/RETN
+ MCycles <= "011";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_TO <= aSP;
+ when 2 =>
+ IncDec_16 <= "0111";
+ Set_Addr_To <= aSP;
+ LDZ <= '1';
+ when 3 =>
+ Jump <= '1';
+ IncDec_16 <= "0111";
+ LDW <= '1';
+ I_RETN <= '1';
+ when others => null;
+ end case;
+ when "01000000"|"01001000"|"01010000"|"01011000"|"01100000"|"01101000"|"01110000"|"01111000" =>
+ -- IN r,(C)
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ SetWZ <= "01";
+ when 2 =>
+ IORQ <= '1';
+ if IR(5 downto 3) /= "110" then
+ Read_To_Reg <= '1';
+ Set_BusA_To(2 downto 0) <= IR(5 downto 3);
+ end if;
+ I_INRC <= '1';
+ when others =>
+ end case;
+ when "01000001"|"01001001"|"01010001"|"01011001"|"01100001"|"01101001"|"01110001"|"01111001" =>
+ -- OUT (C),r
+ -- OUT (C),0
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ Set_Addr_To <= aBC;
+ SetWZ <= "01";
+ Set_BusB_To(2 downto 0) <= IR(5 downto 3);
+ if IR(5 downto 3) = "110" then
+ Set_BusB_To(3) <= '1';
+ end if;
+ when 2 =>
+ Write <= '1';
+ IORQ <= '1';
+ when others =>
+ end case;
+ when "10100010" | "10101010" | "10110010" | "10111010" =>
+ -- INI, IND, INIR, INDR
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ Set_Addr_To <= aBC;
+ Set_BusB_To <= "1010";
+ Set_BusA_To <= "0000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0010";
+ SetWZ <= "11";
+ IncDec_16(3) <= IR(3);
+ when 2 =>
+ IORQ <= '1';
+ Set_BusB_To <= "0110";
+ Set_Addr_To <= aXY;
+ when 3 =>
+ if IR(3) = '0' then
+ IncDec_16 <= "0110";
+ else
+ IncDec_16 <= "1110";
+ end if;
+ Write <= '1';
+ I_BTR <= '1';
+ when 4 =>
+ NoRead <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ when "10100011" | "10101011" | "10110011" | "10111011" =>
+ -- OUTI, OUTD, OTIR, OTDR
+ MCycles <= "100";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ TStates <= "101";
+ Set_Addr_To <= aXY;
+ Set_BusB_To <= "1010";
+ Set_BusA_To <= "0000";
+ Read_To_Reg <= '1';
+ Save_ALU <= '1';
+ ALU_Op <= "0010";
+ when 2 =>
+ Set_BusB_To <= "0110";
+ Set_Addr_To <= aBC;
+ SetWZ <= "11";
+ IncDec_16(3) <= IR(3);
+ when 3 =>
+ if IR(3) = '0' then
+ IncDec_16 <= "0110";
+ else
+ IncDec_16 <= "1110";
+ end if;
+ IORQ <= '1';
+ Write <= '1';
+ I_BTR <= '1';
+ when 4 =>
+ NoRead <= '1';
+ TStates <= "101";
+ when others => null;
+ end case;
+ when "11000001"|"11001001"|"11010001"|"11011001" =>
+ --R800 MULUB
+ if R800_mode = '1' then
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ NoRead <= '1';
+ I_MULUB <= '1';
+ Set_BusB_To(2 downto 0) <= IR(5 downto 3);
+ Set_BusB_To(3) <= '0';
+ when 2 =>
+ NoRead <= '1';
+ I_MULU <= '1';
+ Set_BusA_To(2 downto 0) <= "100";
+ when others => null;
+ end case;
+ end if;
+ when "11000011"|"11110011" =>
+ --R800 MULUW
+ if R800_mode = '1' then
+ MCycles <= "010";
+ case to_integer(unsigned(MCycle)) is
+ when 1 =>
+ NoRead <= '1';
+ if DPAIR = "11" then
+ Set_BusB_To(3 downto 0) <= "1000";
+ else
+ Set_BusB_To(2 downto 1) <= DPAIR;
+ Set_BusB_To(0) <= '0';
+ Set_BusB_To(3) <= '0';
+ end if;
+ Set_BusA_To(2 downto 0) <= "100";
+ when 2 =>
+ TStates <= "101";
+ NoRead <= '1';
+ I_MULU <= '1';
+ Set_BusA_To(2 downto 0) <= "100";
+ when others => null;
+ end case;
+ end if;
+ end case;
+
+ end case;
+
+ if Mode = 1 then
+ if MCycle = "001" then
+-- TStates <= "100";
+ else
+ TStates <= "011";
+ end if;
+ end if;
+
+ if Mode = 3 then
+ if MCycle = "001" then
+-- TStates <= "100";
+ else
+ TStates <= "100";
+ end if;
+ end if;
+
+ if Mode < 2 then
+ if MCycle = "110" then
+ Inc_PC <= '1';
+ if Mode = 1 then
+ Set_Addr_To <= aXY;
+ TStates <= "100";
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusB_To(3) <= '0';
+ end if;
+ if IRB = "00110110" or IRB = "11001011" then
+ Set_Addr_To <= aNone;
+ end if;
+ if not (IRB = "00110110" or ISet = "01") then
+ No_PC <= '1';
+ end if;
+ end if;
+ if MCycle = "111" then
+ if Mode = 0 then
+ TStates <= "101";
+ end if;
+ if ISet /= "01" then
+ Set_Addr_To <= aXY;
+ end if;
+ Set_BusB_To(2 downto 0) <= SSS;
+ Set_BusB_To(3) <= '0';
+ if IRB = "00110110" or ISet = "01" then
+ -- LD (HL),n
+ Inc_PC <= '1';
+ else
+ NoRead <= '1';
+ end if;
+ end if;
+ end if;
+
+ end process;
+
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Pack.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Pack.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..3ac15221eed3eb1df155a70547f31ca5012e64b7
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Pack.vhd
@@ -0,0 +1,248 @@
+-- ****
+-- T80(b) core. In an effort to merge and maintain bug fixes ....
+--
+--
+-- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
+-- Ver 300 started tidyup
+-- MikeJ March 2005
+-- Latest version from www.fpgaarcade.com (original www.opencores.org)
+--
+-- ****
+--
+-- Z80 compatible microprocessor core
+--
+-- Version : 0250
+--
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+--
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- Limitations :
+--
+-- File history :
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+
+package T80_Pack is
+
+ constant aNone : std_logic_vector(2 downto 0) := "111";
+ constant aBC : std_logic_vector(2 downto 0) := "000";
+ constant aDE : std_logic_vector(2 downto 0) := "001";
+ constant aXY : std_logic_vector(2 downto 0) := "010";
+ constant aIOA : std_logic_vector(2 downto 0) := "100";
+ constant aSP : std_logic_vector(2 downto 0) := "101";
+ constant aZI : std_logic_vector(2 downto 0) := "110";
+
+ component T80
+ generic(
+ Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
+ IOWait : integer := 0; -- 1 => Single cycle I/O, 1 => Std I/O cycle
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ RESET_n : in std_logic;
+ CLK_n : in std_logic;
+ CEN : in std_logic;
+ WAIT_n : in std_logic;
+ INT_n : in std_logic;
+ NMI_n : in std_logic;
+ BUSRQ_n : in std_logic;
+ M1_n : out std_logic;
+ IORQ : out std_logic;
+ NoRead : out std_logic;
+ Write : out std_logic;
+ RFSH_n : out std_logic;
+ HALT_n : out std_logic;
+ BUSAK_n : out std_logic;
+ A : out std_logic_vector(15 downto 0);
+ DInst : in std_logic_vector(7 downto 0);
+ DI : in std_logic_vector(7 downto 0);
+ DO : out std_logic_vector(7 downto 0);
+ MC : out std_logic_vector(2 downto 0);
+ TS : out std_logic_vector(2 downto 0);
+ IntCycle_n : out std_logic;
+ IntE : out std_logic;
+ Stop : out std_logic;
+ R800_mode : in std_logic := '0';
+ out0 : in std_logic := '0'; -- 0 => OUT(C),0, 1 => OUT(C),255
+ REG : out std_logic_vector(211 downto 0); -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+ DIRSet : in std_logic := '0';
+ DIR : in std_logic_vector(211 downto 0) := (others => '0') -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+ );
+ end component;
+
+ component T80_Reg
+ port(
+ Clk : in std_logic;
+ CEN : in std_logic;
+ WEH : in std_logic;
+ WEL : in std_logic;
+ AddrA : in std_logic_vector(2 downto 0);
+ AddrB : in std_logic_vector(2 downto 0);
+ AddrC : in std_logic_vector(2 downto 0);
+ DIH : in std_logic_vector(7 downto 0);
+ DIL : in std_logic_vector(7 downto 0);
+ DOAH : out std_logic_vector(7 downto 0);
+ DOAL : out std_logic_vector(7 downto 0);
+ DOBH : out std_logic_vector(7 downto 0);
+ DOBL : out std_logic_vector(7 downto 0);
+ DOCH : out std_logic_vector(7 downto 0);
+ DOCL : out std_logic_vector(7 downto 0);
+ DOR : out std_logic_vector(127 downto 0);
+ DIRSet : in std_logic;
+ DIR : in std_logic_vector(127 downto 0)
+ );
+ end component;
+
+ component T80_MCode
+ generic(
+ Mode : integer := 0;
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ IR : in std_logic_vector(7 downto 0);
+ ISet : in std_logic_vector(1 downto 0);
+ MCycle : in std_logic_vector(2 downto 0);
+ F : in std_logic_vector(7 downto 0);
+ NMICycle : in std_logic;
+ IntCycle : in std_logic;
+ XY_State : in std_logic_vector(1 downto 0);
+ MCycles : out std_logic_vector(2 downto 0);
+ TStates : out std_logic_vector(2 downto 0);
+ Prefix : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
+ Inc_PC : out std_logic;
+ Inc_WZ : out std_logic;
+ IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
+ Read_To_Reg : out std_logic;
+ Read_To_Acc : out std_logic;
+ Set_BusA_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
+ Set_BusB_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
+ ALU_Op : out std_logic_vector(3 downto 0);
+ -- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
+ Save_ALU : out std_logic;
+ Rot_Akku : out std_logic;
+ PreserveC : out std_logic;
+ Arith16 : out std_logic;
+ Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
+ IORQ : out std_logic;
+ Jump : out std_logic;
+ JumpE : out std_logic;
+ JumpXY : out std_logic;
+ Call : out std_logic;
+ RstP : out std_logic;
+ LDZ : out std_logic;
+ LDW : out std_logic;
+ LDSPHL : out std_logic;
+ LDHLSP : out std_logic;
+ ADDSPdd : out std_logic;
+ Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
+ ExchangeDH : out std_logic;
+ ExchangeRp : out std_logic;
+ ExchangeAF : out std_logic;
+ ExchangeRS : out std_logic;
+ ExchangeWH : out std_logic;
+ I_DJNZ : out std_logic;
+ I_CPL : out std_logic;
+ I_CCF : out std_logic;
+ I_SCF : out std_logic;
+ I_RETN : out std_logic;
+ I_BT : out std_logic;
+ I_BC : out std_logic;
+ I_BTR : out std_logic;
+ I_RLD : out std_logic;
+ I_RRD : out std_logic;
+ I_INRC : out std_logic;
+ I_MULUB : out std_logic;
+ I_MULU : out std_logic;
+ SetWZ : out std_logic_vector(1 downto 0);
+ SetDI : out std_logic;
+ SetEI : out std_logic;
+ IMode : out std_logic_vector(1 downto 0);
+ Halt : out std_logic;
+ NoRead : out std_logic;
+ Write : out std_logic;
+ R800_mode : in std_logic;
+ No_PC : out std_logic;
+ XYbit_undoc : out std_logic
+ );
+ end component;
+
+ component T80_ALU
+ generic(
+ Mode : integer := 0;
+ Flag_C : integer := 0;
+ Flag_N : integer := 1;
+ Flag_P : integer := 2;
+ Flag_X : integer := 3;
+ Flag_H : integer := 4;
+ Flag_Y : integer := 5;
+ Flag_Z : integer := 6;
+ Flag_S : integer := 7
+ );
+ port(
+ Arith16 : in std_logic;
+ Z16 : in std_logic;
+ WZ : in std_logic_vector(15 downto 0);
+ XY_State : in std_logic_vector(1 downto 0);
+ ALU_Op : in std_logic_vector(3 downto 0);
+ Rot_Akku : in std_logic;
+ IR : in std_logic_vector(5 downto 0);
+ ISet : in std_logic_vector(1 downto 0);
+ BusA : in std_logic_vector(7 downto 0);
+ BusB : in std_logic_vector(7 downto 0);
+ F_In : in std_logic_vector(7 downto 0);
+ Q : out std_logic_vector(7 downto 0);
+ F_Out : out std_logic_vector(7 downto 0)
+ );
+ end component;
+
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Reg.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Reg.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..e7e86454c36da39f42612d83c5759f7460f21db5
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80_Reg.vhd
@@ -0,0 +1,152 @@
+--------------------------------------------------------------------------------
+-- ****
+-- T80(c) core. Attempt to finish all undocumented features and provide
+-- accurate timings.
+-- Version 350.
+-- Copyright (c) 2018 Sorgelig
+-- Test passed: ZEXDOC, ZEXALL, Z80Full(*), Z80memptr
+-- (*) Currently only SCF and CCF instructions aren't passed X/Y flags check as
+-- correct implementation is still unclear.
+--
+-- ****
+-- T80(b) core. In an effort to merge and maintain bug fixes ....
+--
+--
+-- Ver 300 started tidyup
+-- MikeJ March 2005
+-- Latest version from www.fpgaarcade.com (original www.opencores.org)
+--
+-- ****
+--
+-- T80 Registers, technology independent
+--
+-- Version : 0244
+--
+-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
+--
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t51/
+--
+-- Limitations :
+--
+-- File history :
+--
+-- 0242 : Initial release
+--
+-- 0244 : Changed to single register file
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+
+entity T80_Reg is
+ port(
+ Clk : in std_logic;
+ CEN : in std_logic;
+ WEH : in std_logic;
+ WEL : in std_logic;
+ AddrA : in std_logic_vector(2 downto 0);
+ AddrB : in std_logic_vector(2 downto 0);
+ AddrC : in std_logic_vector(2 downto 0);
+ DIH : in std_logic_vector(7 downto 0);
+ DIL : in std_logic_vector(7 downto 0);
+ DOAH : out std_logic_vector(7 downto 0);
+ DOAL : out std_logic_vector(7 downto 0);
+ DOBH : out std_logic_vector(7 downto 0);
+ DOBL : out std_logic_vector(7 downto 0);
+ DOCH : out std_logic_vector(7 downto 0);
+ DOCL : out std_logic_vector(7 downto 0);
+ DOR : out std_logic_vector(127 downto 0);
+ DIRSet : in std_logic;
+ DIR : in std_logic_vector(127 downto 0)
+ );
+end T80_Reg;
+
+architecture rtl of T80_Reg is
+
+ type Register_Image is array (natural range <>) of std_logic_vector(7 downto 0);
+ signal RegsH : Register_Image(0 to 7);
+ signal RegsL : Register_Image(0 to 7);
+
+begin
+
+ process (Clk)
+ begin
+ if rising_edge(Clk) then
+ if DIRSet = '1' then
+ RegsL(0) <= DIR( 7 downto 0);
+ RegsH(0) <= DIR( 15 downto 8);
+
+ RegsL(1) <= DIR( 23 downto 16);
+ RegsH(1) <= DIR( 31 downto 24);
+
+ RegsL(2) <= DIR( 39 downto 32);
+ RegsH(2) <= DIR( 47 downto 40);
+
+ RegsL(3) <= DIR( 55 downto 48);
+ RegsH(3) <= DIR( 63 downto 56);
+
+ RegsL(4) <= DIR( 71 downto 64);
+ RegsH(4) <= DIR( 79 downto 72);
+
+ RegsL(5) <= DIR( 87 downto 80);
+ RegsH(5) <= DIR( 95 downto 88);
+
+ RegsL(6) <= DIR(103 downto 96);
+ RegsH(6) <= DIR(111 downto 104);
+
+ RegsL(7) <= DIR(119 downto 112);
+ RegsH(7) <= DIR(127 downto 120);
+ elsif CEN = '1' then
+ if WEH = '1' then
+ RegsH(to_integer(unsigned(AddrA))) <= DIH;
+ end if;
+ if WEL = '1' then
+ RegsL(to_integer(unsigned(AddrA))) <= DIL;
+ end if;
+ end if;
+ end if;
+ end process;
+
+ DOAH <= RegsH(to_integer(unsigned(AddrA)));
+ DOAL <= RegsL(to_integer(unsigned(AddrA)));
+ DOBH <= RegsH(to_integer(unsigned(AddrB)));
+ DOBL <= RegsL(to_integer(unsigned(AddrB)));
+ DOCH <= RegsH(to_integer(unsigned(AddrC)));
+ DOCL <= RegsL(to_integer(unsigned(AddrC)));
+ DOR <= RegsH(7) & RegsL(7) & RegsH(6) & RegsL(6) & RegsH(5) & RegsL(5) & RegsH(4) & RegsL(4) & RegsH(3) & RegsL(3) & RegsH(2) & RegsL(2) & RegsH(1) & RegsL(1) & RegsH(0) & RegsL(0);
+
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80pa.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80pa.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..7df3008a2674744e598f7551679688985ae3f578
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80pa.vhd
@@ -0,0 +1,217 @@
+--
+-- Z80 compatible microprocessor core, preudo-asynchronous top level (by Sorgelig)
+--
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+--
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- File history :
+--
+-- v1.0: convert to preudo-asynchronous model with original Z80 timings.
+--
+-- v2.0: rewritten for more precise timings.
+-- support for both CEN_n and CEN_p set to 1. Effective clock will be CLK/2.
+--
+-- v2.1: Output Address 0 during non-bus MCycle (fix ZX contention)
+--
+-- v2.2: Interrupt acknowledge cycle has been corrected
+-- WAIT_n is broken in T80.vhd. Simulate correct WAIT_n locally.
+--
+-- v2.3: Output last used Address during non-bus MCycle seems more correct.
+--
+-- v2.4: Use the fixed WAIT_n in T80.vhd
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+use work.T80_Pack.all;
+
+entity T80pa is
+ generic(
+ Mode : integer := 0 -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
+ );
+ port(
+ RESET_n : in std_logic;
+ CLK : in std_logic;
+ CEN_p : in std_logic := '1';
+ CEN_n : in std_logic := '1';
+ WAIT_n : in std_logic := '1';
+ INT_n : in std_logic := '1';
+ NMI_n : in std_logic := '1';
+ BUSRQ_n : in std_logic := '1';
+ M1_n : out std_logic;
+ MREQ_n : out std_logic;
+ IORQ_n : out std_logic;
+ RD_n : out std_logic;
+ WR_n : out std_logic;
+ RFSH_n : out std_logic;
+ HALT_n : out std_logic;
+ BUSAK_n : out std_logic;
+ OUT0 : in std_logic := '0'; -- 0 => OUT(C),0, 1 => OUT(C),255
+ A : out std_logic_vector(15 downto 0);
+ DI : in std_logic_vector(7 downto 0);
+ DO : out std_logic_vector(7 downto 0);
+ R800_mode : in std_logic := '0';
+ REG : out std_logic_vector(211 downto 0); -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+ DIRSet : in std_logic := '0';
+ DIR : in std_logic_vector(211 downto 0) := (others => '0') -- IFF2, IFF1, IM, IY, HL', DE', BC', IX, HL, DE, BC, PC, SP, R, I, F', A', F, A
+ );
+end T80pa;
+
+architecture rtl of T80pa is
+
+ signal IntCycle_n : std_logic;
+ signal IntCycleD_n : std_logic_vector(1 downto 0);
+ signal IORQ : std_logic;
+ signal NoRead : std_logic;
+ signal Write : std_logic;
+ signal BUSAK : std_logic;
+ signal DI_Reg : std_logic_vector (7 downto 0); -- Input synchroniser
+ signal MCycle : std_logic_vector(2 downto 0);
+ signal TState : std_logic_vector(2 downto 0);
+ signal CEN_pol : std_logic;
+ signal CEN : std_logic;
+ signal Wait_s : std_logic;
+begin
+
+ CEN <= CEN_p and not CEN_pol;
+ BUSAK_n <= BUSAK;
+
+ u0 : T80
+ generic map(
+ Mode => Mode,
+ IOWait => 1
+ )
+ port map(
+ CEN => CEN,
+ M1_n => M1_n,
+ IORQ => IORQ,
+ NoRead => NoRead,
+ Write => Write,
+ RFSH_n => RFSH_n,
+ HALT_n => HALT_n,
+ WAIT_n => Wait_s,
+ INT_n => INT_n,
+ NMI_n => NMI_n,
+ RESET_n => RESET_n,
+ BUSRQ_n => BUSRQ_n,
+ BUSAK_n => BUSAK,
+ CLK_n => CLK,
+ A => A,
+ DInst => DI, -- valid at beginning of T3
+ DI => DI_Reg, -- latched at middle of T3
+ DO => DO,
+ REG => REG,
+ MC => MCycle,
+ TS => TState,
+ OUT0 => OUT0,
+ R800_mode => R800_mode,
+ IntCycle_n => IntCycle_n,
+ DIRSet => DIRSet,
+ DIR => DIR
+ );
+
+ process(CLK)
+ begin
+ if rising_edge(CLK) then
+ if RESET_n = '0' then
+ WR_n <= '1';
+ RD_n <= '1';
+ IORQ_n <= '1';
+ MREQ_n <= '1';
+ DI_Reg <= "00000000";
+ CEN_pol <= '0';
+ IntCycleD_n <= "11";
+ elsif CEN_p = '1' and CEN_pol = '0' then
+ CEN_pol <= '1';
+ if WAIT_s = '1' or TState /= "010" then
+ if MCycle = "001" then
+ if TState = "010" then
+ IORQ_n <= '1';
+ MREQ_n <= '1';
+ RD_n <= '1';
+ end if;
+ else
+ if TState = "001" and IORQ = '1' then
+ WR_n <= not Write;
+ RD_n <= Write;
+ IORQ_n <= '0';
+ end if;
+ end if;
+ end if;
+ elsif CEN_n = '1' and CEN_pol = '1' then
+ Wait_s <= Wait_n;
+ CEN_pol <= '0';
+ if TState = "011" and BUSAK = '1' then
+ DI_Reg <= DI;
+ end if;
+ if MCycle = "001" then
+ if TState = "001" then
+ IntCycleD_n <= IntCycleD_n(0) & IntCycle_n;
+ RD_n <= not IntCycle_n;
+ MREQ_n <= not IntCycle_n;
+ IORQ_n <= IntCycleD_n(1);
+ end if;
+ if TState = "011" then
+ IntCycleD_n <= "11";
+ RD_n <= '1';
+ MREQ_n <= '0';
+ end if;
+ if TState = "100" then
+ MREQ_n <= '1';
+ end if;
+ else
+ if NoRead = '0' and IORQ = '0' then
+ if TState = "001" then
+ RD_n <= Write;
+ MREQ_n <= '0';
+ end if;
+ end if;
+ if TState = "010" then
+ WR_n <= not Write;
+ end if;
+ if TState = "011" then
+ WR_n <= '1';
+ RD_n <= '1';
+ IORQ_n <= '1';
+ MREQ_n <= '1';
+ end if;
+ end if;
+ end if;
+ end if;
+ end process;
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80s.vhd b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80s.vhd
new file mode 100644
index 0000000000000000000000000000000000000000..6967292c952882ff7f57312c8398684f90062aac
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/T80/T80s.vhd
@@ -0,0 +1,193 @@
+--
+-- Z80 compatible microprocessor core, synchronous top level
+-- Different timing than the original z80
+-- Inputs needs to be synchronous and outputs may glitch
+--
+-- Version : 0242
+--
+-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
+--
+-- All rights reserved
+--
+-- Redistribution and use in source and synthezised forms, with or without
+-- modification, are permitted provided that the following conditions are met:
+--
+-- Redistributions of source code must retain the above copyright notice,
+-- this list of conditions and the following disclaimer.
+--
+-- Redistributions in synthesized form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in the
+-- documentation and/or other materials provided with the distribution.
+--
+-- Neither the name of the author nor the names of other contributors may
+-- be used to endorse or promote products derived from this software without
+-- specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
+-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+-- POSSIBILITY OF SUCH DAMAGE.
+--
+-- Please report bugs to the author, but before you do so, please
+-- make sure that this is not a derivative work and that
+-- you have the latest version of this file.
+--
+-- The latest version of this file can be found at:
+-- http://www.opencores.org/cvsweb.shtml/t80/
+--
+-- Limitations :
+--
+-- File history :
+--
+-- 0208 : First complete release
+--
+-- 0210 : Fixed read with wait
+--
+-- 0211 : Fixed interrupt cycle
+--
+-- 0235 : Updated for T80 interface change
+--
+-- 0236 : Added T2Write generic
+--
+-- 0237 : Fixed T2Write with wait state
+--
+-- 0238 : Updated for T80 interface change
+--
+-- 0240 : Updated for T80 interface change
+--
+-- 0242 : Updated for T80 interface change
+--
+
+library IEEE;
+use IEEE.std_logic_1164.all;
+use IEEE.numeric_std.all;
+use IEEE.STD_LOGIC_UNSIGNED.all;
+use work.T80_Pack.all;
+
+entity T80s is
+ generic(
+ Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
+ T2Write : integer := 1; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
+ IOWait : integer := 1 -- 0 => Single cycle I/O, 1 => Std I/O cycle
+ );
+ port(
+ RESET_n : in std_logic;
+ CLK : in std_logic;
+ CEN : in std_logic := '1';
+ WAIT_n : in std_logic := '1';
+ INT_n : in std_logic := '1';
+ NMI_n : in std_logic := '1';
+ BUSRQ_n : in std_logic := '1';
+ M1_n : out std_logic;
+ MREQ_n : out std_logic;
+ IORQ_n : out std_logic;
+ RD_n : out std_logic;
+ WR_n : out std_logic;
+ RFSH_n : out std_logic;
+ HALT_n : out std_logic;
+ BUSAK_n : out std_logic;
+ OUT0 : in std_logic := '0'; -- 0 => OUT(C),0, 1 => OUT(C),255
+ A : out std_logic_vector(15 downto 0);
+ DI : in std_logic_vector(7 downto 0);
+ DO : out std_logic_vector(7 downto 0)
+ );
+end T80s;
+
+architecture rtl of T80s is
+
+ signal IntCycle_n : std_logic;
+ signal NoRead : std_logic;
+ signal Write : std_logic;
+ signal IORQ : std_logic;
+ signal DI_Reg : std_logic_vector(7 downto 0);
+ signal MCycle : std_logic_vector(2 downto 0);
+ signal TState : std_logic_vector(2 downto 0);
+
+begin
+
+ u0 : T80
+ generic map(
+ Mode => Mode,
+ IOWait => IOWait)
+ port map(
+ CEN => CEN,
+ M1_n => M1_n,
+ IORQ => IORQ,
+ NoRead => NoRead,
+ Write => Write,
+ RFSH_n => RFSH_n,
+ HALT_n => HALT_n,
+ WAIT_n => Wait_n,
+ INT_n => INT_n,
+ NMI_n => NMI_n,
+ RESET_n => RESET_n,
+ BUSRQ_n => BUSRQ_n,
+ BUSAK_n => BUSAK_n,
+ CLK_n => CLK,
+ A => A,
+ DInst => DI,
+ DI => DI_Reg,
+ DO => DO,
+ MC => MCycle,
+ TS => TState,
+ OUT0 => OUT0,
+ IntCycle_n => IntCycle_n
+ );
+
+ process (RESET_n, CLK)
+ begin
+ if RESET_n = '0' then
+ RD_n <= '1';
+ WR_n <= '1';
+ IORQ_n <= '1';
+ MREQ_n <= '1';
+ DI_Reg <= "00000000";
+ elsif rising_edge(CLK) then
+ if CEN = '1' then
+ RD_n <= '1';
+ WR_n <= '1';
+ IORQ_n <= '1';
+ MREQ_n <= '1';
+ if MCycle = 1 then
+ if TState = 1 or (TState = 2 and Wait_n = '0') then
+ RD_n <= not IntCycle_n;
+ MREQ_n <= not IntCycle_n;
+ IORQ_n <= IntCycle_n;
+ end if;
+ if TState = 3 then
+ MREQ_n <= '0';
+ end if;
+ else
+ if (TState = 1 or (TState = 2 and Wait_n = '0')) and NoRead = '0' and Write = '0' then
+ RD_n <= '0';
+ IORQ_n <= not IORQ;
+ MREQ_n <= IORQ;
+ end if;
+ if T2Write = 0 then
+ if TState = 2 and Write = '1' then
+ WR_n <= '0';
+ IORQ_n <= not IORQ;
+ MREQ_n <= IORQ;
+ end if;
+ else
+ if (TState = 1 or (TState = 2 and Wait_n = '0')) and Write = '1' then
+ WR_n <= '0';
+ IORQ_n <= not IORQ;
+ MREQ_n <= IORQ;
+ end if;
+ end if;
+ end if;
+ if TState = 2 and Wait_n = '1' then
+ DI_Reg <= DI;
+ end if;
+ end if;
+ end if;
+ end process;
+end;
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_68k.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_68k.v
new file mode 100644
index 0000000000000000000000000000000000000000..16606f52f6da65f0c474b65fee508ca10f94edc5
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_68k.v
@@ -0,0 +1,83 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2019 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module cpu_68k(
+ input CLK,
+ input CLK_EN_68K_P, //CLK_68KCLK
+ input CLK_EN_68K_N,
+ input nRESET,
+ input IPL2, IPL1, IPL0,
+ input nDTACK,
+ output [23:1] M68K_ADDR,
+ input [15:0] FX68K_DATAIN,
+ output [15:0] FX68K_DATAOUT,
+ output nLDS, nUDS,
+ output nAS,
+ output M68K_RW,
+ output FC2, FC1, FC0,
+ output nBG,
+ input nBR, nBGACK,
+ input SYSTEM_CDx
+
+);
+
+wire EN_PHI1 = CLK_EN_68K_P;
+wire EN_PHI2 = CLK_EN_68K_N;
+
+reg reset;
+always @(posedge CLK)
+ if (EN_PHI2) reset <= ~nRESET;
+
+fx68k FX68K(
+ .clk(CLK),
+ .extReset(reset),
+ .pwrUp(reset),
+
+ .enPhi1(EN_PHI1),
+ .enPhi2(EN_PHI2),
+
+ .eRWn(M68K_RW),
+ .ASn(nAS),
+ .UDSn(nUDS),
+ .LDSn(nLDS),
+
+ .BGn(nBG),
+ .BRn(nBR),
+ .BGACKn(nBGACK),
+
+ .DTACKn(nDTACK),
+
+ .VPAn(SYSTEM_CDx | nAS | ~&M68K_ADDR[23:4]), //VPA must be fired only in IACK cycle! (NeoGeo doesn't use FC)
+ .BERRn(1'b1),
+
+ .IPL0n(IPL0),
+ .IPL1n(IPL1),
+ .IPL2n(IPL2),
+
+ .FC0(FC0),
+ .FC1(FC1),
+ .FC2(FC2),
+
+ .iEdb(FX68K_DATAIN),
+ .oEdb(FX68K_DATAOUT),
+ .eab(M68K_ADDR)
+ );
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_z80.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_z80.v
new file mode 100644
index 0000000000000000000000000000000000000000..f0559eb2fe82b6a336234d92d9168837bc199381
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/cpu/cpu_z80.v
@@ -0,0 +1,58 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// Z80 CPU plug into TV80 core
+
+module cpu_z80(
+ input CLK,
+ input CLK4P_EN,
+ input CLK4N_EN,
+ input nRESET,
+ input [7:0] SDD_IN,
+ output [7:0] SDD_OUT,
+ output [15:0] SDA,
+ output reg nIORQ,
+ output nMREQ,
+ output reg nRD, nWR,
+ input nBUSRQ,
+ output nBUSAK,
+ input nINT, nNMI, nWAIT
+);
+
+ wire RFSH_n, MREQ_n;
+ assign nMREQ = MREQ_n | ~RFSH_n;
+
+ T80pa cpu(
+ .RESET_n(nRESET),
+ .CLK(CLK),
+ .CEN_p(CLK4P_EN),
+ .CEN_n(CLK4N_EN),
+ .WAIT_n(nWAIT),
+ .INT_n(nINT),
+ .NMI_n(nNMI),
+ .MREQ_n(MREQ_n),
+ .IORQ_n(nIORQ),
+ .RD_n(nRD),
+ .WR_n(nWR),
+ .RFSH_n(RFSH_n),
+ .BUSRQ_n(nBUSRQ),
+ .BUSAK_n(nBUSAK),
+ .A(SDA),
+ .DI(SDD_IN),
+ .DO(SDD_OUT)
+ );
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_inputs.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_inputs.v
new file mode 100644
index 0000000000000000000000000000000000000000..45954201c3fd38f5cfd4dd41643aa0d891fc4c11
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_inputs.v
@@ -0,0 +1,40 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module c1_inputs(
+ input nCTRL1_ZONE,
+ input nCTRL2_ZONE,
+ input nSTATUSB_ZONE,
+ output [15:8] M68K_DATA,
+ input [9:0] P1_IN,
+ input [9:0] P2_IN,
+ input nWP, nCD2, nCD1,
+ input SYSTEM_TYPE
+);
+
+ // REG_P1CNT
+ assign M68K_DATA[15:8] = nCTRL1_ZONE ? 8'bzzzzzzzz : P1_IN[7:0];
+ // REG_P2CNT
+ assign M68K_DATA[15:8] = nCTRL2_ZONE ? 8'bzzzzzzzz : P2_IN[7:0];
+
+ // REG_STATUS_B
+ assign M68K_DATA[15:8] = nSTATUSB_ZONE ? 8'bzzzzzzzz : {SYSTEM_TYPE, nWP, nCD2, nCD1, P2_IN[9:8], P1_IN[9:8]};
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_regs.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_regs.v
new file mode 100644
index 0000000000000000000000000000000000000000..596bb5507dfcd09c64e8939076cc0a31ce5e21ab
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_regs.v
@@ -0,0 +1,71 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module c1_regs(
+ input CLK,
+ input nICOM_ZONE,
+ input RW,
+ inout [15:8] M68K_DATA,
+ output [7:0] SDD_RD,
+ input [7:0] SDD_WR,
+ input nSDZ80R, nSDZ80W, nSDZ80CLR,
+ output nSDW
+);
+
+ reg [7:0] SDD_LATCH_CMD;
+ reg [7:0] SDD_LATCH_REP;
+
+ // Z80 command read
+ assign SDD_RD = SDD_LATCH_CMD; //nSDZ80R ? 8'bzzzzzzzz : SDD_LATCH_CMD;
+
+ // Z80 reply write
+ always @(posedge CLK) begin
+ reg nSDZ80W_d;
+ nSDZ80W_d <= nSDZ80W;
+ if (nSDZ80W & ~nSDZ80W_d)
+ SDD_LATCH_REP <= SDD_WR;
+ end
+
+ // REG_SOUND read
+ assign M68K_DATA = (RW & ~nICOM_ZONE) ? SDD_LATCH_REP : 8'bzzzzzzzz;
+
+ // REG_SOUND write
+ assign nSDW = (RW | nICOM_ZONE); // Tells Z80 that 68k sent a command
+
+ // REG_SOUND write
+ always @(posedge CLK) // Which one has priority ?
+ begin
+ reg nICOM_ZONE_d;
+ reg nSDZ80CLR_d;
+ nICOM_ZONE_d <= nICOM_ZONE;
+ nSDZ80CLR_d <= nSDZ80CLR;
+
+ if (!nSDZ80CLR & nSDZ80CLR_d)
+ begin
+ SDD_LATCH_CMD <= 8'b00000000;
+ end
+ else
+ if (!nICOM_ZONE & nICOM_ZONE_d) begin
+ if (!RW)
+ SDD_LATCH_CMD <= M68K_DATA;
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_wait.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_wait.v
new file mode 100644
index 0000000000000000000000000000000000000000..0b99dab62bd9ea6e715e828ced2b9031a6eb9166
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/c1_wait.v
@@ -0,0 +1,55 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module c1_wait(
+ input CLK, CLK_EN_68K_P, nAS,
+ input SYSTEM_CDx,
+ input nROM_ZONE, nWRAM_ZONE, nPORT_ZONE, nCARD_ZONE, nSROM_ZONE,
+ input nROMWAIT, nPWAIT0, nPWAIT1, PDTACK,
+ output nDTACK
+);
+
+ reg [2:0] WAIT_CNT;
+
+ //assign nPDTACK = ~(nPORT_ZONE | PDTACK); // Really a NOR ? May stall CPU if PDTACK = GND
+
+ assign nDTACK = nAS | WAIT_MUX;
+
+ // When nROMWAIT == 1, nDTACK = nAS for nROM_ZONE (no wait)
+ wire WAIT_MUX = (!nROM_ZONE & !nROMWAIT) ? (WAIT_CNT > 3) :
+ (!nPORT_ZONE & ( nPWAIT1 & !nPWAIT0)) ? (WAIT_CNT > 3) :
+ (!nPORT_ZONE & (!nPWAIT1 & nPWAIT0)) ? (WAIT_CNT > 2) :
+ (!nCARD_ZONE) ? (WAIT_CNT > 3) : // Maybe 2 but not important here, used JEIDA compliance
+ 1'b0;
+
+ always @(posedge CLK)
+ if (CLK_EN_68K_P) begin
+ if (!nAS)
+ begin
+ if (WAIT_CNT)
+ WAIT_CNT <= WAIT_CNT - 1'b1;
+ end
+ else
+ begin
+ WAIT_CNT <= 5;
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/clocks.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/clocks.v
new file mode 100644
index 0000000000000000000000000000000000000000..4d5076f853e7f4e1b3d597b8a4ed5c6dd97cdaa0
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/clocks.v
@@ -0,0 +1,77 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// Everything here was verified on a MV4 board
+// Todo: Check phase relations between 12M, 68KCLK and 68KCLKB
+// Todo: Check cycle right after nRESETP goes high, real hw might have an important delay added
+
+module clocks_sync(
+ input CLK,
+ input CLK_EN_24M_P,
+ input CLK_EN_24M_N,
+ input nRESETP,
+ output CLK_24M,
+ output CLK_12M,
+ output reg CLK_68KCLK,
+ output CLK_68KCLKB,
+ output CLK_EN_68K_P,
+ output CLK_EN_68K_N,
+ output CLK_6MB,
+ output reg CLK_1HB,
+ output CLK_EN_12M,
+ output CLK_EN_12M_N,
+ output CLK_EN_6MB,
+ output CLK_EN_1HB
+);
+
+ reg [2:0] CLK_DIV;
+ wire CLK_3M;
+
+ assign CLK_68KCLKB = ~CLK_68KCLK;
+
+ always @(posedge CLK or negedge nRESETP)
+ begin
+ if (!nRESETP)
+ CLK_68KCLK <= 1'b0; // Thanks ElectronAsh ! Real hw doesn't clearly init DFF
+ else if (CLK_EN_24M_P)
+ CLK_68KCLK <= ~CLK_68KCLK; // MV4 C4:A
+ end
+ assign CLK_EN_68K_P = ~CLK_68KCLK & CLK_EN_24M_P;
+ assign CLK_EN_68K_N = CLK_68KCLK & CLK_EN_24M_P;
+
+ always @(posedge CLK, negedge nRESETP)
+ begin
+ if (!nRESETP)
+ CLK_DIV <= 3'b100;
+ else if (CLK_EN_24M_N)
+ CLK_DIV <= CLK_DIV + 1'b1;
+ end
+
+ assign CLK_24M = CLK_EN_24M_N;
+ assign CLK_12M = CLK_DIV[0];
+ assign CLK_EN_12M = CLK_EN_24M_N & ~CLK_DIV[0];
+ assign CLK_EN_12M_N = CLK_EN_24M_N & CLK_DIV[0];
+ assign CLK_6MB = ~CLK_DIV[1];
+ assign CLK_3M = CLK_DIV[2];
+
+ // MV4 C4:B
+ always @(posedge CLK)
+ if (CLK_EN_12M) CLK_1HB <= ~CLK_3M;
+
+ assign CLK_EN_6MB = CLK_EN_24M_N & CLK_DIV[1:0] == 3;
+ assign CLK_EN_1HB = CLK_EN_24M_N & CLK_DIV == 0;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/com.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/com.v
new file mode 100644
index 0000000000000000000000000000000000000000..61f1e8fc8568ed8a631439665c57b997f208ddd1
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/com.v
@@ -0,0 +1,53 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2019 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+// This simulates the COM MCU idle reply to make Riding Hero run at normal speed
+
+module com(
+ input nRESET,
+ input CLK_48M,
+ input nPORTOEL,
+ input nPORTOEU,
+ input nPORTWEL,
+ output [15:0] M68K_DIN
+);
+
+reg nPORTWEL_PREV, TOGGLE_BIT;
+
+assign M68K_DIN[15:8] = nPORTOEU ? 8'bzzzzzzzz : {4'b0000, TOGGLE_BIT ,3'b000};
+assign M68K_DIN[7:0] = nPORTOEL ? 8'bzzzzzzzz : 8'h00;
+
+always @(posedge CLK_48M)
+begin
+ if (!nRESET)
+ begin
+ TOGGLE_BIT <= 1'b0;
+ end
+ else
+ begin
+ nPORTWEL_PREV <= nPORTWEL;
+
+ // Detect rising edge of nPORTWEL
+ if (~nPORTWEL_PREV & nPORTWEL)
+ TOGGLE_BIT <= ~TOGGLE_BIT;
+ end
+end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_c1.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_c1.v
new file mode 100644
index 0000000000000000000000000000000000000000..721bafa789467e65d6a05fbad21520ae9f5efc29
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_c1.v
@@ -0,0 +1,161 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+// Missing pin: VPA
+// All address decoding was checked except BITW1, nCTRL1_ZONE, and nCTRL2_ZONE
+
+module neo_c1(
+ input CLK,
+ input [21:17] M68K_ADDR,
+ inout [15:8] M68K_DATA,
+ input A22Z, A23Z,
+ input nLDS, nUDS,
+ input RW, nAS,
+ output nROMOEL, nROMOEU,
+ output nPORTOEL, nPORTOEU,
+ output nPORTWEL, nPORTWEU,
+ output nPORT_ZONE,
+ output nWRL, nWRU,
+ output nWWL, nWWU,
+ output nSROMOEL, nSROMOEU,
+ output nSRAMOEL, nSRAMOEU,
+ output nSRAMWEL, nSRAMWEU,
+ output nLSPOE, nLSPWE,
+ output nCRDO, nCRDW, nCRDC,
+ output nSDW,
+ input [9:0] P1_IN,
+ input [9:0] P2_IN,
+ input nCD1, nCD2, nWP,
+ input nROMWAIT, nPWAIT0, nPWAIT1, PDTACK,
+ input [7:0] SDD_WR,
+ output [7:0] SDD_RD,
+ input nSDZ80R, nSDZ80W, nSDZ80CLR,
+ input CLK_EN_68K_P,
+ output nDTACK,
+ output nBITW0, nBITW1, nDIPRD0, nDIPRD1,
+ output nPAL_ZONE,
+ input [1:0] SYSTEM_TYPE
+);
+
+ wire nIO_ZONE; // Internal
+ wire nC1REGS_ZONE; // Internal
+ wire nROM_ZONE; // Internal
+ wire nWRAM_ZONE; // Internal (external for PCB)
+ wire nCTRL1_ZONE; // Internal (external for PCB)
+ wire nICOM_ZONE; // Internal
+ wire nCTRL2_ZONE; // Internal (external for PCB)
+ wire nSTATUSB_ZONE; // Internal (external for PCB)
+ wire nLSPC_ZONE; // Internal
+ wire nCARD_ZONE; // Internal
+ wire nSROM_ZONE; // Internal
+ wire nSRAM_ZONE; // Internal (external for PCB)
+
+ c1_regs C1REGS(CLK, nICOM_ZONE, RW, M68K_DATA, SDD_RD, SDD_WR, nSDZ80R, nSDZ80W, nSDZ80CLR, nSDW);
+
+ c1_wait C1WAIT(CLK, CLK_EN_68K_P, nAS, SYSTEM_TYPE[1], nROM_ZONE, nWRAM_ZONE, nPORT_ZONE, nCARD_ZONE, nSROM_ZONE,
+ nROMWAIT, nPWAIT0, nPWAIT1, PDTACK, nDTACK);
+
+ c1_inputs C1INPUTS(nCTRL1_ZONE, nCTRL2_ZONE, nSTATUSB_ZONE, M68K_DATA, P1_IN, P2_IN,
+ nWP, nCD2, nCD1, SYSTEM_TYPE[0]);
+
+ // 000000~0FFFFF read/write
+ assign nROM_ZONE = |{A23Z, A22Z, M68K_ADDR[21], M68K_ADDR[20]};
+
+ // 100000~1FFFFF read/write
+ assign nWRAM_ZONE = |{A23Z, A22Z, M68K_ADDR[21], ~M68K_ADDR[20]};
+
+ // 200000~2FFFFF read/write
+ assign nPORT_ZONE = |{A23Z, A22Z, ~M68K_ADDR[21], M68K_ADDR[20]};
+
+ // 300000~3FFFFF read/write
+ assign nIO_ZONE = |{A23Z, A22Z, ~M68K_ADDR[21], ~M68K_ADDR[20]};
+
+ // 300000~3FFFFE even bytes read/write
+ assign nC1REGS_ZONE = nUDS | nIO_ZONE;
+
+ // 300000~31FFFE even bytes read only
+ assign nCTRL1_ZONE = nC1REGS_ZONE | ~RW | |{M68K_ADDR[19], M68K_ADDR[18], M68K_ADDR[17]};
+
+ // 320000~33FFFE even bytes read/write
+ assign nICOM_ZONE = nC1REGS_ZONE | |{M68K_ADDR[19], M68K_ADDR[18], ~M68K_ADDR[17]};
+
+ // 340000~35FFFE even bytes read only - Todo: MAME says A17 is used, see right below
+ assign nCTRL2_ZONE = nC1REGS_ZONE | ~RW | |{M68K_ADDR[19], ~M68K_ADDR[18], M68K_ADDR[17]};
+ // 360000~37FFFF is not mapped ?
+
+ // 30xxxx 31xxxx odd bytes read only
+ assign nDIPRD0 = |{nIO_ZONE, M68K_ADDR[19], M68K_ADDR[18], M68K_ADDR[17], ~RW, nLDS};
+
+ // 32xxxx 33xxxx odd bytes read only
+ assign nDIPRD1 = |{nIO_ZONE, M68K_ADDR[19], M68K_ADDR[18], ~M68K_ADDR[17], ~RW, nLDS};
+
+ // 38xxxx 39xxxx odd bytes write only
+ assign nBITW0 = |{nIO_ZONE, ~M68K_ADDR[19], M68K_ADDR[18], M68K_ADDR[17], RW, nLDS};
+
+ // 380000~39FFFE even bytes read only
+ assign nSTATUSB_ZONE = nC1REGS_ZONE | ~RW | |{~M68K_ADDR[19], M68K_ADDR[18], M68K_ADDR[17]};
+
+ // 3A0001~3BFFFF odd bytes write only
+ assign nBITW1 = |{nIO_ZONE, ~M68K_ADDR[19], M68K_ADDR[18], ~M68K_ADDR[17], RW, nLDS};
+
+ // 3C0000~3DFFFF
+ assign nLSPC_ZONE = |{nIO_ZONE, ~M68K_ADDR[19], ~M68K_ADDR[18], M68K_ADDR[17]};
+
+ // 3E0000~3FFFFF is not mapped ? To check
+
+ // 400000~7FFFFF
+ assign nPAL_ZONE = |{A23Z, ~A22Z, (nLDS & nUDS)};
+
+ // 800000~BFFFFF
+ assign nCARD_ZONE = |{~A23Z, A22Z};
+
+ // C00000~CFFFFF
+ assign nSROM_ZONE = |{~A23Z, ~A22Z, M68K_ADDR[21], M68K_ADDR[20]};
+
+ // D00000~DFFFFF
+ assign nSRAM_ZONE = |{~A23Z, ~A22Z, M68K_ADDR[21], ~M68K_ADDR[20]};
+
+ // Outputs:
+ assign nROMOEL = ~RW | nLDS | nROM_ZONE;
+ assign nROMOEU = ~RW | nUDS | nROM_ZONE;
+ assign nPORTOEL = ~RW | nLDS | nPORT_ZONE;
+ assign nPORTOEU = ~RW | nUDS | nPORT_ZONE;
+ assign nPORTWEL = RW | nLDS | nPORT_ZONE;
+ assign nPORTWEU = RW | nUDS | nPORT_ZONE;
+ assign nWRL = ~RW | nLDS | nWRAM_ZONE;
+ assign nWRU = ~RW | nUDS | nWRAM_ZONE;
+ assign nWWL = RW | nLDS | nWRAM_ZONE;
+ assign nWWU = RW | nUDS | nWRAM_ZONE;
+ assign nSROMOEL = ~RW | nLDS | nSROM_ZONE;
+ assign nSROMOEU = ~RW | nUDS | nSROM_ZONE;
+ assign nSRAMOEL = ~RW | nLDS | nSRAM_ZONE;
+ assign nSRAMOEU = ~RW | nUDS | nSRAM_ZONE;
+ assign nSRAMWEL = RW | nLDS | nSRAM_ZONE;
+ assign nSRAMWEU = RW | nUDS | nSRAM_ZONE;
+
+ // Todo: Check if TG68k duplicates byte on data bus on byte writes (it should !)
+ assign nLSPWE = RW | nUDS | nLSPC_ZONE;
+ assign nLSPOE = ~RW | nUDS | nLSPC_ZONE;
+
+ assign nCRDO = ~RW | nCARD_ZONE | nLDS;
+ assign nCRDW = RW | nCARD_ZONE | nLDS;
+ assign nCRDC = nCARD_ZONE | nAS;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_d0.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_d0.v
new file mode 100644
index 0000000000000000000000000000000000000000..8c0b26727fe060b689dc38dfa5e78a11d880cd69
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_d0.v
@@ -0,0 +1,78 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// All pins ok except TRES, but apparently never used (something to do with crystal oscillator ?)
+
+module neo_d0(
+ input CLK,
+ input CLK_EN_24M_P,
+ input CLK_EN_24M_N,
+ output CLK_24M,
+ input nRESET, nRESETP,
+ output CLK_12M,
+ output CLK_68KCLK,
+ output CLK_68KCLKB,
+ output CLK_EN_68K_P,
+ output CLK_EN_68K_N,
+ output CLK_6MB,
+ output CLK_1HB,
+ output CLK_EN_12M,
+ output CLK_EN_12M_N,
+ output CLK_EN_6MB,
+ output CLK_EN_1HB,
+ input M68K_ADDR_A4,
+ input nBITWD0,
+ input [5:0] M68K_DATA,
+ input [15:11] SDA_H,
+ input [4:2] SDA_L,
+ input nSDRD, nSDWR, nMREQ, nIORQ,
+ output nZ80NMI,
+ input nSDW,
+ output nSDZ80R, nSDZ80W, nSDZ80CLR,
+ output nSDROM, nSDMRD, nSDMWR,
+ output SDRD0, SDRD1,
+ output n2610CS, n2610RD, n2610WR,
+ output nZRAMCS,
+ output [2:0] BNK,
+ output [2:0] P1_OUT,
+ output [2:0] P2_OUT
+);
+ reg [2:0] REG_BNK;
+ reg [5:0] REG_OUT;
+
+ // Clock divider part
+ clocks_sync CLKS(CLK, CLK_EN_24M_P, CLK_EN_24M_N, nRESETP, CLK_24M, CLK_12M, CLK_68KCLK, CLK_68KCLKB, CLK_EN_68K_P, CLK_EN_68K_N, CLK_6MB, CLK_1HB, CLK_EN_12M, CLK_EN_12M_N, CLK_EN_6MB, CLK_EN_1HB);
+
+ // Z80 controller part
+ z80ctrl Z80CTRL(CLK, SDA_L, SDA_H, nSDRD, nSDWR, nMREQ, nIORQ, nSDW, nRESET, nZ80NMI, nSDZ80R, nSDZ80W,
+ nSDZ80CLR, nSDROM, nSDMRD, nSDMWR, SDRD0, SDRD1, n2610CS, n2610RD, n2610WR, nZRAMCS);
+
+ assign {P2_OUT, P1_OUT} = REG_OUT;
+ assign BNK = REG_BNK;
+
+ always @(posedge CLK) begin
+ reg nBITWD0_d;
+ nBITWD0_d <= nBITWD0;
+ if (!nBITWD0 & nBITWD0_d) begin
+ if (M68K_ADDR_A4)
+ REG_BNK <= M68K_DATA[2:0];
+ else
+ REG_OUT <= M68K_DATA[5:0];
+ end
+ if(~nRESETP) {REG_BNK, REG_OUT} <= 0;
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_e0.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_e0.v
new file mode 100644
index 0000000000000000000000000000000000000000..a3771195917be1f2a22562f5d33b6ddb71bf1e69
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_e0.v
@@ -0,0 +1,41 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module neo_e0(
+ input [23:1] M68K_ADDR,
+ input [2:0] BNK,
+ input nSROMOEU, nSROMOEL,
+ output nSROMOE,
+ input nVEC,
+ output A23Z, A22Z,
+ output [23:0] CDA
+);
+
+ assign nSROMOE = nSROMOEU & nSROMOEL;
+
+ // Vector table swap
+ // A2*Z = 1 if nVEC == 0 and A == 11000000000000000xxxxxxx
+ assign {A23Z, A22Z} = M68K_ADDR[23:22] ^ {2{~|{M68K_ADDR[21:7], ^M68K_ADDR[23:22], nVEC}}};
+
+ // Todo: Check this on real hw (MV4 ?)
+ // Memcard area is $800000~$BFFFFF, each word is mapped to one byte
+ // 10000000 00000000 00000000
+ // 10111111 11111111 11111111
+ // --xxxxxx xxxxxxxx xxxxxxx-
+ // bbbaaaaa aaaaaaaa aaaaaaaa
+ assign CDA = {BNK, M68K_ADDR[21:1]};
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_f0.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_f0.v
new file mode 100644
index 0000000000000000000000000000000000000000..32dd248c8b41acfb3796783c4acc7560b6eaea7c
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_f0.v
@@ -0,0 +1,115 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module neo_f0(
+ input CLK,
+ input nRESET,
+ input nDIPRD0,
+ input nDIPRD1, // Also called "IN3"
+ input nBITW0,
+ output nBITWD0, // "nBITW0 for NEO-D0"
+ input [7:0] DIPSW,
+ input COIN1, COIN2,
+ input [7:4] M68K_ADDR,
+ inout [7:0] M68K_DATA,
+ input SYSTEMB,
+ output [5:0] nSLOT,
+ output SLOTA, SLOTB, SLOTC,
+ output reg [2:0] LED_LATCH,
+ output reg [7:0] LED_DATA,
+
+ input RTC_DOUT, RTC_TP,
+ output RTC_DIN, RTC_CLK, RTC_STROBE,
+
+ output nCOUNTOUT,
+
+ input SYSTEM_TYPE
+
+ //output [3:0] EL_OUT,
+ //output [8:0] LED_OUT1,
+ //output [8:0] LED_OUT2
+);
+
+ reg [2:0] REG_RTCCTRL;
+ reg [2:0] SLOTS;
+
+ // Todo: verify
+ // This is used (among other things) for the RTC
+ assign nBITWD0 = |{nBITW0, M68K_ADDR[6:5]};
+
+ // Todo: verify
+ // This is used to select NEO-I0
+ assign nCOUNTOUT = |{nBITW0, ~M68K_ADDR[6:5]};
+
+ assign RTC_DIN = REG_RTCCTRL[0];
+ assign RTC_CLK = REG_RTCCTRL[1];
+ assign RTC_STROBE = REG_RTCCTRL[2];
+
+ // REG_DIPSW $300001~?, odd bytes
+ // REG_SYSTYPE $300081~?, odd bytes (TODO: Test switch and stuff... Neutral for now)
+ assign M68K_DATA = nDIPRD0 ? 8'bzzzzzzzz :
+ (M68K_ADDR[7]) ? 8'b10000000 :
+ DIPSW;
+
+ // REG_STATUS_A $320001~?, odd bytes
+ // In console mode, reading REG_STATUS_A returns 00. This is used by the Unibios to detect the system type. It detects console if read value is $FF or [4:3] = 0.
+ assign M68K_DATA = nDIPRD1 ? 8'bzzzzzzzz :
+ SYSTEM_TYPE ? {RTC_DOUT, RTC_TP, 4'b0111, COIN2, COIN1} : 8'h00;
+
+ reg nBITW0_d;
+ always @(posedge CLK)
+ nBITW0_d <= nBITW0;
+
+ always @(posedge CLK)
+ begin
+ if (!nRESET)
+ begin
+ SLOTS <= 3'b000;
+ REG_RTCCTRL <= 3'b000;
+ end
+ else if (!nBITW0 & nBITW0_d)
+ begin
+ case (M68K_ADDR[6:4])
+ 3'b010:
+ SLOTS <= M68K_DATA[2:0]; // REG_SLOT $380021
+ 3'b011:
+ LED_LATCH <= M68K_DATA[5:3]; // REG_LEDLATCHES $380031
+ 3'b100:
+ LED_DATA <= M68K_DATA[7:0]; // REG_LEDDATA $380041
+ 3'b101:
+ REG_RTCCTRL <= M68K_DATA[2:0]; // REG_RTCCTRL $380051
+ endcase
+ end
+ end
+
+ assign {SLOTC, SLOTB, SLOTA} = SYSTEMB ? SLOTS : 3'b000; // Maybe not
+
+ // TODO: check this
+ assign nSLOT = SYSTEMB ?
+ (SLOTS == 3'b000) ? 6'b111110 :
+ (SLOTS == 3'b001) ? 6'b111101 :
+ (SLOTS == 3'b010) ? 6'b111011 :
+ (SLOTS == 3'b011) ? 6'b110111 :
+ (SLOTS == 3'b100) ? 6'b101111 :
+ (SLOTS == 3'b101) ? 6'b011111 :
+ 6'b111111 : // Invalid
+ 6'b111111 ; // All slots disabled
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_g0.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_g0.v
new file mode 100644
index 0000000000000000000000000000000000000000..b1a94df5523a207cb8d7ed73654b649cbc798f83
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_g0.v
@@ -0,0 +1,51 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2019 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module neo_g0(
+ output [15:0] M68K_DATA,
+ input G0, G1,
+ input DIR,
+ input [15:0] CDD,
+ input [15:0] PC,
+ output WE
+);
+
+ // G0 G1 DIR M68K_DATA CDD PC WE
+ // 0 0 0 Should not happen, write to both hi-z active active 0
+ // 0 0 1 Should not happen, read memcard ? active hi-z hi-z 1
+ // 0 1 0 Write to memcard hi-z active hi-z 1
+ // 0 1 1 Read from memcard active hi-z hi-z 1
+ // 1 0 0 Write to palette hi-z hi-z active 0
+ // 1 0 1 Read from palette active hi-z hi-z 1
+ // 1 1 0 Do nothing hi-z hi-z hi-z 1
+ // 1 1 1 Do nothing hi-z hi-z hi-z 1
+
+ wire [15:0] READ_DATA = G0 ? PC : CDD;
+ assign M68K_DATA = (~(G0 & G1) & DIR) ? READ_DATA : 16'bzzzzzzzz_zzzzzzzz;
+
+ assign WE = G1 | DIR;
+
+ // CDD output is done in the higher-level module
+ //assign CDD = G0 | DIR ? 16'bzzzzzzzz_zzzzzzzz : M68K_DOUT;
+
+ // PC output is done in the higher-level module
+ //assign PC = WE ? 16'bzzzzzzzz_zzzzzzzz : M68K_DOUT;
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_pvc.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_pvc.v
new file mode 100644
index 0000000000000000000000000000000000000000..26b30c8589ddf001b4394cd5a6934178e6db0b04
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_pvc.v
@@ -0,0 +1,156 @@
+//============================================================================
+// NEO-PVC
+//
+// Copyright (C) 2019 Alexey Melnikov
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module neo_pvc
+(
+ input nRESET,
+ input CLK_48M,
+
+ input [19:1] M68K_ADDR,
+ inout [15:0] M68K_DATA,
+ input [15:0] PROM_DATA,
+ input nPORTOEL, nPORTOEU,
+ input nPORTWEL, nPORTWEU,
+
+ input ENABLE,
+ output [23:0] P2_ADDR
+);
+
+assign P2_ADDR = ENABLE ? bank + {M68K_ADDR,1'b0} : 24'h0;
+
+assign M68K_DATA[7:0] = (nPORTOEL | ~ENABLE) ? 8'bZ :
+ PORT_RD ? PORT_DO[7:0] :
+ RAM_ACC ? RAM_DO[7:0] :
+ PROM_DATA[7:0];
+
+assign M68K_DATA[15:8] = (nPORTOEU | ~ENABLE) ? 8'bZ :
+ PORT_RD ? PORT_DO[15:8] :
+ RAM_ACC ? RAM_DO[15:8] :
+ PROM_DATA[15:8];
+
+wire RAM_ACC = &M68K_ADDR[19:13];
+wire PORT_ACC = &M68K_ADDR[19:5];
+wire [3:0] PORT_NO = M68K_ADDR[4:1];
+
+reg [11:0] CLR_ADDR;
+always @(posedge CLK_48M) CLR_ADDR <= CLR_ADDR + 1'd1;
+
+wire [15:0] RAM_DO;
+dpram #(12) RAML(
+ .clock_a(CLK_48M),
+ .address_a(M68K_ADDR[12:1]),
+ .data_a(M68K_DATA[7:0]),
+ .wren_a(RAM_ACC & ~nPORTWEL),
+ .q_a(RAM_DO[7:0]),
+
+ .clock_b(CLK_48M),
+ .address_b(CLR_ADDR),
+ .data_b(CLR_ADDR[7:0]),
+ .wren_b(~nRESET)
+);
+
+dpram #(12) RAMU(
+ .clock_a(CLK_48M),
+ .address_a(M68K_ADDR[12:1]),
+ .data_a(M68K_DATA[15:8]),
+ .wren_a(RAM_ACC & ~nPORTWEU),
+ .q_a(RAM_DO[15:8]),
+
+ .clock_b(CLK_48M),
+ .address_b(CLR_ADDR),
+ .data_b(CLR_ADDR[7:0]),
+ .wren_b(~nRESET)
+);
+
+reg nPORTWEU_d;
+reg nPORTWEL_d;
+always @(posedge CLK_48M) begin
+ nPORTWEU_d <= nPORTWEU;
+ nPORTWEL_d <= nPORTWEL;
+end
+
+reg [23:0] bank = 0;
+always @(posedge CLK_48M) begin
+ if(~nRESET) {bank[23:16],bank[7:0]} <= 0;
+ else if (~nPORTWEU & nPORTWEU_d) begin
+ if(PORT_ACC && PORT_NO == 8) bank[7:0] <= {M68K_DATA[15:9],1'b0};
+ if(PORT_ACC && PORT_NO == 9) bank[23:16] <= {1'b0,M68K_DATA[14:8]};
+ end
+end
+
+always @(posedge CLK_48M) begin
+ if(~nRESET) bank[15:8] <= 0;
+ else if (~nPORTWEL & nPORTWEL_d) begin
+ if(PORT_ACC && PORT_NO == 9) bank[15:8] <= M68K_DATA[7:0];
+ end
+end
+
+reg [4:0] ur,ug,ub;
+reg us;
+always @(posedge CLK_48M) begin
+ if(~nPORTWEU && nPORTWEU_d && PORT_ACC && PORT_NO == 0) begin
+ ub[0] <= M68K_DATA[12];
+ ug[0] <= M68K_DATA[13];
+ ur <= {M68K_DATA[11:8], M68K_DATA[14]};
+ us <= M68K_DATA[15];
+ end
+end
+
+always @(posedge CLK_48M) begin
+ if(~nPORTWEL && nPORTWEL_d && PORT_ACC && PORT_NO == 0) begin
+ ub[4:1] <= M68K_DATA[3:0];
+ ug[4:1] <= M68K_DATA[7:4];
+ end
+end
+
+reg [15:0] pcol;
+always @(posedge CLK_48M) begin
+ if (~nPORTWEU && nPORTWEU_d) begin
+ if(PORT_ACC && PORT_NO == 4) {pcol[13],pcol[7:4] } <= {M68K_DATA[8],M68K_DATA[12:9]};
+ if(PORT_ACC && PORT_NO == 5) pcol[15] <= M68K_DATA[8];
+ end
+end
+
+always @(posedge CLK_48M) begin
+ if (~nPORTWEL && nPORTWEL_d) begin
+ if(PORT_ACC && PORT_NO == 4) {pcol[12],pcol[3:0] } <= {M68K_DATA[0],M68K_DATA[4:1]};
+ if(PORT_ACC && PORT_NO == 5) {pcol[14],pcol[11:8]} <= {M68K_DATA[0],M68K_DATA[4:1]};
+ end
+end
+
+reg [15:0] PORT_DO;
+reg PORT_RD;
+always @(*) begin
+ PORT_RD = PORT_ACC;
+ case(PORT_NO)
+ 1: PORT_DO = {3'b0,ug,3'b0,ub};
+ 2: PORT_DO = {7'b0,us,3'b0,ur};
+ 6: PORT_DO = pcol;
+ 8: PORT_DO = {bank[7:0], 8'hA0};
+ 9: PORT_DO = bank[23:8];
+ default:
+ begin
+ PORT_DO = 0;
+ PORT_RD = 0;
+ end
+ endcase
+end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_sma.sv b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_sma.sv
new file mode 100644
index 0000000000000000000000000000000000000000..9c67588342c1d4f2486c32cebbeb73956c385817
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/neo_sma.sv
@@ -0,0 +1,226 @@
+//============================================================================
+// NEO-SMA
+//
+// Copyright (C) 2019 Alexey Melnikov
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module neo_sma
+(
+ input nRESET,
+ input CLK_48M,
+
+ input [19:1] M68K_ADDR,
+ inout [15:0] M68K_DATA,
+ input [15:0] PROM_DATA,
+ input nPORTOEL, nPORTOEU,
+ input nPORTWEL, nPORTWEU,
+
+ input [2:0] TYPE,
+ output [23:0] P2_ADDR
+);
+
+assign P2_ADDR = ENABLE ? bank + {M68K_ADDR,1'b0} : 24'h0;
+
+wire ENABLE = (TYPE>=3);
+wire BANK_SEL = (M68K_ADDR == BANK_ADDR);
+wire ID_SEL = (M68K_ADDR == 'h7F223);
+wire RNG_SEL = (M68K_ADDR == RNG_ADDR1 || M68K_ADDR == RNG_ADDR2);
+
+reg [19:1] BANK_ADDR, RNG_ADDR1, RNG_ADDR2;
+always @(posedge CLK_48M) begin
+ case(TYPE)
+ 3: begin // kof99
+ BANK_ADDR <= 'h7FFF8;
+ RNG_ADDR1 <= 'h7FFFC;
+ RNG_ADDR2 <= 'h7FFFD;
+ end
+ 4,
+ 5: begin // garou,garouh
+ BANK_ADDR <= 'h7FFE0;
+ RNG_ADDR1 <= 'h7FFE6;
+ RNG_ADDR2 <= 'h7FFF8;
+ end
+ 6: begin // mslug3
+ BANK_ADDR <= 'h7FFF2;
+ //mslug3 has no RNG. (?)
+ RNG_ADDR1 <= 'h7F223;
+ RNG_ADDR2 <= 'h7F223;
+ end
+ 7: begin // kof2000
+ BANK_ADDR <= 'h7FFF6;
+ RNG_ADDR1 <= 'h7FFEC;
+ RNG_ADDR2 <= 'h7FFED;
+ end
+ endcase
+end
+
+assign M68K_DATA[7:0] = (nPORTOEL | ~ENABLE) ? 8'bZ : ID_SEL ? 8'h37 : RNG_SEL ? rng[7:0] : PROM_DATA[7:0];
+assign M68K_DATA[15:8] = (nPORTOEU | ~ENABLE) ? 8'bZ : ID_SEL ? 8'h9A : RNG_SEL ? rng[15:8] : PROM_DATA[15:8];
+
+wire nPORTWE = nPORTWEL & nPORTWEU;
+wire nPORTOE = nPORTOEL & nPORTOEU;
+
+////////////////////////////////////////////////////
+
+wire [23:0] kof99_map[64] =
+'{
+ 'h000000, 'h100000, 'h200000, 'h300000,
+ 'h3cc000, 'h4cc000, 'h3f2000, 'h4f2000,
+ 'h407800, 'h507800, 'h40d000, 'h50d000,
+ 'h417800, 'h517800, 'h420800, 'h520800,
+ 'h424800, 'h524800, 'h429000, 'h529000,
+ 'h42e800, 'h52e800, 'h431800, 'h531800,
+ 'h54d000, 'h551000, 'h567000, 'h592800,
+ 'h588800, 'h581800, 'h599800, 'h594800,
+ 'h598000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000
+};
+
+wire [5:0] kof99_idx = {M68K_DATA[5],M68K_DATA[12],M68K_DATA[10],M68K_DATA[8],M68K_DATA[6],M68K_DATA[14]};
+////////////////////////////////////////////////////
+
+wire [23:0] garou_map[64] =
+'{
+ 'h000000, 'h100000, 'h200000, 'h300000,
+ 'h280000, 'h380000, 'h2d0000, 'h3d0000,
+ 'h2f0000, 'h3f0000, 'h400000, 'h500000,
+ 'h420000, 'h520000, 'h440000, 'h540000,
+ 'h498000, 'h598000, 'h4a0000, 'h5a0000,
+ 'h4a8000, 'h5a8000, 'h4b0000, 'h5b0000,
+ 'h4b8000, 'h5b8000, 'h4c0000, 'h5c0000,
+ 'h4c8000, 'h5c8000, 'h4d0000, 'h5d0000,
+ 'h458000, 'h558000, 'h460000, 'h560000,
+ 'h468000, 'h568000, 'h470000, 'h570000,
+ 'h478000, 'h578000, 'h480000, 'h580000,
+ 'h488000, 'h588000, 'h490000, 'h590000,
+ 'h5d0000, 'h5d8000, 'h5e0000, 'h5e8000,
+ 'h5f0000, 'h5f8000, 'h600000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000
+};
+
+wire [5:0] garou_idx = {M68K_DATA[12],M68K_DATA[14],M68K_DATA[6],M68K_DATA[7],M68K_DATA[9],M68K_DATA[5]};
+////////////////////////////////////////////////////
+
+wire [23:0] garouh_map[64] =
+'{
+ 'h000000, 'h100000, 'h200000, 'h300000,
+ 'h280000, 'h380000, 'h2d0000, 'h3d0000,
+ 'h2c8000, 'h3c8000, 'h400000, 'h500000,
+ 'h420000, 'h520000, 'h440000, 'h540000,
+ 'h598000, 'h698000, 'h5a0000, 'h6a0000,
+ 'h5a8000, 'h6a8000, 'h5b0000, 'h6b0000,
+ 'h5b8000, 'h6b8000, 'h5c0000, 'h6c0000,
+ 'h5c8000, 'h6c8000, 'h5d0000, 'h6d0000,
+ 'h458000, 'h558000, 'h460000, 'h560000,
+ 'h468000, 'h568000, 'h470000, 'h570000,
+ 'h478000, 'h578000, 'h480000, 'h580000,
+ 'h488000, 'h588000, 'h490000, 'h590000,
+ 'h5d8000, 'h6d8000, 'h5e0000, 'h6e0000,
+ 'h5e8000, 'h6e8000, 'h6e8000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000
+};
+
+wire [5:0] garouh_idx = {M68K_DATA[13],M68K_DATA[11],M68K_DATA[2],M68K_DATA[14],M68K_DATA[8],M68K_DATA[4]};
+////////////////////////////////////////////////////
+
+wire [23:0] mslug3_map[64] =
+'{
+ 'h000000, 'h020000, 'h040000, 'h060000,
+ 'h070000, 'h090000, 'h0b0000, 'h0d0000,
+ 'h0e0000, 'h0f0000, 'h120000, 'h130000,
+ 'h140000, 'h150000, 'h180000, 'h190000,
+ 'h1a0000, 'h1b0000, 'h1e0000, 'h1f0000,
+ 'h200000, 'h210000, 'h240000, 'h250000,
+ 'h260000, 'h270000, 'h2a0000, 'h2b0000,
+ 'h2c0000, 'h2d0000, 'h300000, 'h310000,
+ 'h320000, 'h330000, 'h360000, 'h370000,
+ 'h380000, 'h390000, 'h3c0000, 'h3d0000,
+ 'h400000, 'h410000, 'h440000, 'h450000,
+ 'h460000, 'h470000, 'h4a0000, 'h4b0000,
+ 'h4c0000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000
+};
+
+wire [5:0] mslug3_idx = {M68K_DATA[9],M68K_DATA[3],M68K_DATA[6],M68K_DATA[15],M68K_DATA[12],M68K_DATA[14]};
+////////////////////////////////////////////////////
+
+wire [23:0] kof2000_map[64] =
+'{
+ 'h000000, 'h100000, 'h200000, 'h300000,
+ 'h3f7800, 'h4f7800, 'h3ff800, 'h4ff800,
+ 'h407800, 'h507800, 'h40f800, 'h50f800,
+ 'h416800, 'h516800, 'h41d800, 'h51d800,
+ 'h424000, 'h524000, 'h523800, 'h623800,
+ 'h526000, 'h626000, 'h528000, 'h628000,
+ 'h52a000, 'h62a000, 'h52b800, 'h62b800,
+ 'h52d000, 'h62d000, 'h52e800, 'h62e800,
+ 'h618000, 'h619000, 'h61a000, 'h61a800,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000,
+ 'h000000, 'h000000, 'h000000, 'h000000
+};
+
+wire [5:0] kof2000_idx = {M68K_DATA[5],M68K_DATA[10],M68K_DATA[3],M68K_DATA[7],M68K_DATA[14],M68K_DATA[15]};
+////////////////////////////////////////////////////
+
+reg nPORTWE_d;
+reg nPORTOE_d;
+always @(posedge CLK_48M) begin
+ nPORTWE_d <= nPORTWE;
+ nPORTOE_d <= nPORTOE;
+end
+
+reg [23:0] bank = 0;
+always @(posedge CLK_48M) begin
+ if(~nRESET) bank <= 0;
+ else if(~nPORTWE & nPORTWE_d & BANK_SEL) begin
+ case(TYPE)
+ 3: bank <= kof99_map[kof99_idx];
+ 4: bank <= garou_map[garou_idx];
+ 5: bank <= garouh_map[garouh_idx];
+ 6: bank <= mslug3_map[mslug3_idx];
+ 7: bank <= kof2000_map[kof2000_idx];
+ endcase
+ end
+end
+
+reg [15:0] rng = 0;
+always @(posedge CLK_48M) begin
+ reg rst = 0;
+ if(~nRESET) rst = 1;
+ else if (~nPORTOE & nPORTOE_d) begin
+ if(rst) rng <= 'h2345;
+ else rng <= {rng[14:0], rng[2] ^ rng[3] ^ rng[5] ^ rng[6] ^ rng[7] ^ rng[11] ^ rng[12] ^ rng[15]};
+ rst <= 0;
+ end
+end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/pcm.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/pcm.v
new file mode 100644
index 0000000000000000000000000000000000000000..5db55dd2227689d42511e64c03f5795eb22e4290
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/pcm.v
@@ -0,0 +1,86 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2019 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module PCM(
+ input CLK_68KCLKB,
+ input nSDROE, SDRMPX,
+ input nSDPOE, SDPMPX,
+ inout [7:0] SDRAD,
+ input [9:8] SDRA_L,
+ input [23:20] SDRA_U,
+ inout [7:0] SDPAD,
+ input [11:8] SDPA,
+ input [7:0] D,
+ output [23:0] A
+ );
+
+ reg [1:0] COUNT;
+ reg [7:0] RDLATCH;
+ reg [7:0] PDLATCH;
+ reg [23:0] RALATCH;
+ reg [23:0] PALATCH;
+
+ wire nSDRMPX = ~SDRMPX;
+ wire nSDPMPX = ~SDPMPX;
+ wire SDPOE = ~nSDPOE;
+ wire CEN = ~COUNT[1];
+
+ always @(posedge CLK_68KCLKB or negedge nSDPOE)
+ begin
+ if (!nSDPOE)
+ COUNT <= 0;
+ else
+ if (CEN) COUNT <= COUNT + 1'b1;
+ end
+
+ assign SDRAD = nSDROE ? 8'bzzzzzzzz : RDLATCH;
+ always @(*)
+ if (COUNT[1]) RDLATCH <= D;
+
+ assign SDPAD = nSDPOE ? 8'bzzzzzzzz : PDLATCH;
+ always @(*)
+ if (!nSDPOE) PDLATCH <= D;
+
+ assign A = nSDPOE ? RALATCH : PALATCH;
+
+ always @(posedge nSDRMPX)
+ begin
+ RALATCH[7:0] <= SDRAD[7:0];
+ RALATCH[9:8] <= SDRA_L[9:8];
+ end
+ always @(posedge SDRMPX)
+ begin
+ RALATCH[17:10] <= SDRAD[7:0];
+ RALATCH[23:18] <= {SDRA_U[23:20], SDRA_L[9:8]};
+ end
+
+ always @(posedge nSDPMPX)
+ begin
+ PALATCH[7:0] <= SDPAD[7:0];
+ PALATCH[11:8] <= SDPA[11:8];
+ end
+ always @(posedge SDPMPX)
+ begin
+ PALATCH[19:12] <= SDPAD[7:0];
+ PALATCH[23:20] <= SDPA[11:8];
+ end
+
+endmodule
+
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/register.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/register.v
new file mode 100644
index 0000000000000000000000000000000000000000..965a80bd81269dec299d83cc0bf6b8e3ba610bcc
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/register.v
@@ -0,0 +1,46 @@
+// simulate registers with async clocks in the 'clock' domain
+// has a delay of one clock
+
+module register (
+ input clock,
+ input s, // set
+ input r, // reset
+ input c, // write clock
+ input [WIDTH-1:0] d, // new value
+ output reg [WIDTH-1:0] q // value
+);
+
+parameter WIDTH = 1;
+
+reg [WIDTH-1:0] val_reg;
+reg c_d;
+/*
+always @(posedge c, posedge s, posedge r)
+begin
+ if (r)
+ q <= 0;
+ else if (s)
+ q <= 1;
+ else
+ q <= d;
+end
+*/
+
+always @(*) begin
+ if (r)
+ q = 0;
+ else if (s)
+ q = {WIDTH{1'b1}};
+ else
+ q = val_reg;
+end
+
+always @(posedge clock) begin
+ c_d <= c;
+ if (~c_d & c & ~r & ~s)
+ val_reg <= d;
+ else
+ val_reg <= q;
+end
+
+endmodule
\ No newline at end of file
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/resetp.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/resetp.v
new file mode 100644
index 0000000000000000000000000000000000000000..03ac3f837904334f372c8f2e3b14dde586ef5b4c
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/resetp.v
@@ -0,0 +1,42 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2019 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module resetp_sync(
+ input CLK,
+ input CLK_EN_24_N,
+ input nRESET,
+ output reg nRESETP
+);
+
+ reg O49_nQ;
+
+ // 24MB ""__""__""__""__""__
+ // nRESET ____________""""""""
+ // nRESETP """"""""""""""____""
+
+ always @(posedge CLK)
+ begin
+ if (CLK_EN_24_N) begin
+ O49_nQ <= ~nRESET;
+ nRESETP <= ~&{O49_nQ, nRESET};
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/syslatch.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/syslatch.v
new file mode 100644
index 0000000000000000000000000000000000000000..0671053414f2adf3111b754848df0e4ba07dc039
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/syslatch.v
@@ -0,0 +1,89 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module syslatch(
+ input [4:1] M68K_ADDR,
+ input nBITW1,
+ input nRESET,
+ output SHADOW, nVEC, nCARDWEN, CARDWENB, nREGEN, nSYSTEM, nSRAMWEN, PALBNK,
+ input CLK, CLK_EN_68K_P
+);
+
+ reg [7:0] SLATCH;
+
+ assign SHADOW = SLATCH[0];
+ assign nVEC = SLATCH[1];
+ assign nCARDWEN = SLATCH[2];
+ assign CARDWENB = SLATCH[3];
+ assign nREGEN = SLATCH[4];
+ assign nSYSTEM = SLATCH[5];
+ assign nSRAMWEN = ~SLATCH[6]; // See MVS schematics page 3
+ assign PALBNK = SLATCH[7];
+
+ // System latch
+ /*always @(*) // M68K_ADDR[4:1] or nBITW1 or nRESET
+ begin
+ if (!nRESET)
+ begin
+ if (nBITW1)
+ SLATCH <= 8'h00; // Clear
+ else
+ begin // Demux mode
+ case (M68K_ADDR[3:1])
+ 0: SLATCH <= {7'b0000000, M68K_ADDR[4]};
+ 1: SLATCH <= {6'b000000, M68K_ADDR[4], 1'b0};
+ 2: SLATCH <= {5'b00000, M68K_ADDR[4], 2'b00};
+ 3: SLATCH <= {4'b0000, M68K_ADDR[4], 3'b000};
+ 4: SLATCH <= {3'b000, M68K_ADDR[4], 4'b0000};
+ 5: SLATCH <= {2'b00, M68K_ADDR[4], 5'b00000};
+ 6: SLATCH <= {1'b0, M68K_ADDR[4], 6'b000000};
+ 7: SLATCH <= {M68K_ADDR[4], 7'b0000000};
+ endcase
+ end
+ end
+ else if (!nBITW1)
+ begin // Latch mode
+ SLATCH[M68K_ADDR[3:1]] <= M68K_ADDR[4];
+ end
+ end*/
+
+ always @(posedge CLK) // M68K_ADDR[4:1] or nBITW1 or nRESET
+ if (CLK_EN_68K_P) begin
+ if (!nRESET)
+ begin
+ if (nBITW1)
+ SLATCH <= 8'h00; // Clear
+ else
+ begin // Demux mode
+ case (M68K_ADDR[3:1])
+ 0: SLATCH <= {7'b0000000, M68K_ADDR[4]};
+ 1: SLATCH <= {6'b000000, M68K_ADDR[4], 1'b0};
+ 2: SLATCH <= {5'b00000, M68K_ADDR[4], 2'b00};
+ 3: SLATCH <= {4'b0000, M68K_ADDR[4], 3'b000};
+ 4: SLATCH <= {3'b000, M68K_ADDR[4], 4'b0000};
+ 5: SLATCH <= {2'b00, M68K_ADDR[4], 5'b00000};
+ 6: SLATCH <= {1'b0, M68K_ADDR[4], 6'b000000};
+ 7: SLATCH <= {M68K_ADDR[4], 7'b0000000};
+ endcase
+ end
+ end
+ else if (!nBITW1)
+ begin // Latch mode
+ SLATCH[M68K_ADDR[3:1]] <= M68K_ADDR[4];
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/upd4990.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/upd4990.v
new file mode 100644
index 0000000000000000000000000000000000000000..5fee888225ef62cf591a611d3cb14321645bc3da
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/upd4990.v
@@ -0,0 +1,174 @@
+// NeoGeo logic definition
+// MiSTer RTC to uPD4990
+//
+// Copyright (C) 2019 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module uPD4990(
+ input nRESET,
+ input CLK,
+ input CLK_EN_12M, // 12MHz please
+ input [64:0] rtc,
+ input CS, OE, // Both always low
+ input DATA_CLK,
+ input DATA_IN,
+ input STROBE,
+ output TP,
+ output DATA_OUT
+);
+
+ wire [47:0] TIME_DATA;
+ wire [3:0] MONTH_HEX;
+ reg [47:0] SHIFT_REG;
+ reg [3:0] CMD_REG;
+ reg OUT_HOLD; // Prevents CLK from shifting the 48 lower bits of SHIFT_REG
+
+ reg [2:0] TP_SEL;
+ reg [5:0] TP_HSECONDS; // Half seconds (incremented at 2Hz)
+ reg TP_SEC_RUN;
+ reg INTERVAL_FLAG;
+
+ reg [8:0] DIV9;
+ reg [14:0] DIV15;
+ reg [5:0] DIV6;
+
+ reg [1:0] DATA_CLK_G_SR;
+ reg [1:0] STROBE_G_SR;
+
+
+ // "rtc" format:
+ // 64 63 55 47 39 31 23 15 7
+ // x 01000000 00000WWW YYYYYYYY 000MMMMM 00DDDDDD 0PHHHHHH 0MMMMMMM 0SSSSSSS
+ // Values are in BCD
+ // P: 1=PM 0=AM
+ // Weekday: 1 to 7
+ // Month: 1 to 12
+
+ // uPD4990 datasheet:
+ // Data is represented in BCD notation. Only months are represented in hexadecimal notation.
+ // Format:
+ // CCCC YYYYYYYY MMMM WWWW DDDDDDDD HHHHHHHH MMMMMMMM SSSSSSSS
+
+ // BCD to hex
+ assign MONTH_HEX = rtc[36] ? rtc[35:32] + 4'd10 : rtc[35:32];
+
+ assign TIME_DATA = {rtc[47:40], MONTH_HEX, 1'b0, rtc[50:48], rtc[31:24], 2'b00, rtc[21:0]};
+
+ wire [14:0] DIV15_INC = DIV15 + 1'b1; // Look-ahead for edge detection
+ wire [5:0] DIV6_INC = DIV6 + 1'b1; // Look-ahead for edge detection
+
+ wire INTERVAL_TRIG = (((TP_SEL == 3'd4) & (TP_HSECONDS >= 6'd1-1)) |
+ ((TP_SEL == 3'd5) & (TP_HSECONDS >= 6'd10-1)) |
+ ((TP_SEL == 3'd6) & (TP_HSECONDS >= 6'd30-1)) |
+ ((TP_SEL == 3'd7) & (TP_HSECONDS >= 6'd60-1)));
+
+ wire DATA_CLK_G = CS & DATA_CLK;
+ wire STROBE_G = CS & STROBE;
+
+ always @(posedge CLK)
+ begin
+ if (!nRESET)
+ begin
+ OUT_HOLD <= 1;
+ TP_SEL <= 0;
+ CMD_REG <= 0;
+ TP_SEL <= 0;
+ TP_HSECONDS <= 0;
+ TP_SEC_RUN <= 1;
+ INTERVAL_FLAG <= 1;
+ DIV9 <= 9'd0;
+ DIV15 <= 15'd0;
+ DIV6 <= 6'd0;
+ DATA_CLK_G_SR <= 0;
+ STROBE_G_SR <= 0;
+ end
+ else
+ if (CLK_EN_12M) begin
+ if (DIV9 == 9'd366-1) // 12000000/32768
+ begin
+ // 32768Hz from 12MHz
+ DIV9 <= 9'd0;
+
+ DIV15 <= DIV15_INC;
+
+ if ({DIV15[8], DIV15_INC[8]} == 2'b01)
+ begin
+ // 64Hz from 32768Hz
+ if (TP_SEC_RUN)
+ begin
+ DIV6 <= DIV6_INC;
+ if ({DIV6[4], DIV6_INC[4]} == 2'b01)
+ begin
+ // 2Hz from 64Hz
+ // INTERVAL_FLAG is toggled in the middle of the interval (50% duty cycle)
+ // It can be forced back high with command b1100
+ if (INTERVAL_TRIG)
+ begin
+ TP_HSECONDS <= 6'd0;
+ INTERVAL_FLAG <= ~INTERVAL_FLAG;
+ end
+ else
+ TP_HSECONDS <= TP_HSECONDS + 1'b1;
+ end
+ end
+ end
+ end
+ else
+ DIV9 <= DIV9 + 1'b1;
+
+
+ DATA_CLK_G_SR <= {DATA_CLK_G_SR[0], DATA_CLK_G};
+ STROBE_G_SR <= {STROBE_G_SR[0], STROBE_G};
+
+ // Rising edge of DATA_CLK_G
+ if (DATA_CLK_G_SR == 2'b01)
+ begin
+ if (!OUT_HOLD)
+ SHIFT_REG <= {CMD_REG[0], SHIFT_REG[47:1]};
+
+ // CMD_REG always shifts regardless of OUT_HOLD
+ CMD_REG <= {DATA_IN, CMD_REG[3:1]};
+ end
+
+ // Rising edge of STROBE_G
+ if (STROBE_G_SR == 2'b01)
+ begin
+ casez(CMD_REG)
+ 4'b0000: OUT_HOLD <= 1'b1; // Hold
+ 4'b0001: OUT_HOLD <= 1'b0; // Allow shift
+ 4'b0010: OUT_HOLD <= 1'b1; // Setting time isn't supported
+ 4'b0011: // Read time
+ begin
+ SHIFT_REG <= TIME_DATA;
+ OUT_HOLD <= 1'b1;
+ end
+ 4'b01zz, 4'b10zz: TP_SEL <= {CMD_REG[3], CMD_REG[1:0]};
+ 4'b1100: INTERVAL_FLAG <= 1'b1; // Reset
+ 4'b1101: TP_SEC_RUN <= 1'b1;
+ 4'b111z: TP_SEC_RUN <= 1'b0;
+ endcase
+ end
+ end
+ end
+
+ assign TP = (TP_SEL == 3'd0) ? DIV15[8] :
+ (TP_SEL == 3'd1) ? DIV15[6] :
+ (TP_SEL == 3'd2) ? DIV15[3] :
+ (TP_SEL == 3'd3) ? DIV15[2] :
+ INTERVAL_FLAG;
+
+ assign DATA_OUT = OUT_HOLD ? rtc[0] : SHIFT_REG[0];
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/watchdog.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/watchdog.v
new file mode 100644
index 0000000000000000000000000000000000000000..4856fbcb53d8a90eba314f72e44b4dba8c7ad9f8
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/watchdog.v
@@ -0,0 +1,63 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+module watchdog(
+ input CLK,
+ input DOGE,
+ input nLDS, RW,
+ input A23I, A22I,
+ input [21:17] M68K_ADDR_U,
+ //input [12:1] M68K_ADDR_L,
+ input WDCLK,
+ output nHALT,
+ output nRESET,
+ input nRST
+);
+
+ reg [3:0] WDCNT;
+
+ initial
+ WDCNT = 4'b0000;
+
+ // IMPORTANT:
+ // nRESET is an open-collector output on B1, so that the 68k can drive it (RESET instruction)
+ // The line has a 4.7k pullup (schematics page 1)
+ // nRESET changes state on posedge nBNKB (posedge mclk), but takes a slightly variable amount of time to
+ // return high after it is released. Low during 8 frames, released during 8 frames.
+ assign nRESET = nRST & ~WDCNT[3];
+ assign nHALT = nRESET; // Yup (these are open-collector)
+
+ // $300001 (LDS)
+ // 0011000xxxxxxxxxxxxxxxx1
+ // MAME says 00110001xxxxxxxxxxxxxxx1 but NEO-B1 doesn't have A16
+ wire WDRESET = ~DOGE | &{nRST, ~|{nLDS, RW, A23I, A22I}, M68K_ADDR_U[21:20], ~|{M68K_ADDR_U[19:17]}};
+
+ always @(posedge CLK)
+ begin
+ reg WDCLK_D;
+ WDCLK_D <= WDCLK;
+
+ if (WDRESET)
+ WDCNT <= 4'b0000;
+ else if (!nRST)
+ WDCNT <= 4'b1000;
+ else begin
+ if (~WDCLK_D & WDCLK)
+ WDCNT <= WDCNT + 1'b1;
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/z80ctrl.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/z80ctrl.v
new file mode 100644
index 0000000000000000000000000000000000000000..026bb6179a582e6edbc2bcd74ae298dec9dd6811
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/z80ctrl.v
@@ -0,0 +1,101 @@
+// NeoGeo logic definition
+// Copyright (C) 2018 Sean Gonsalves
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+// Everything here was verified on a MV4 board
+
+module z80ctrl(
+ input CLK,
+ input [4:2] SDA_L,
+ input [15:11] SDA_U,
+ input nSDRD, nSDWR,
+ input nMREQ, nIORQ,
+ input nSDW, // From NEO-C1
+ input nRESET,
+ output reg nZ80NMI,
+ output nSDZ80R, nSDZ80W, // To NEO-C1
+ output nSDZ80CLR, // To NEO-C1
+ output nSDROM,
+ output nSDMRD, nSDMWR,
+ output nSDRD0, nSDRD1,
+ output n2610CS,
+ output n2610RD, n2610WR,
+ output nZRAMCS
+);
+
+ reg nNMI_EN;
+ wire nIORD, nIOWR;
+ wire nNMI_SET, nNMI_RESET;
+
+ // $0000~$F7FF: ROM
+ // $F800~$FFFF: RAM
+ assign nSDROM = &{SDA_U};
+ assign nZRAMCS = ~nSDROM;
+
+ assign nSDMRD = nMREQ | nSDRD; // RAM read
+ assign nSDMWR = nMREQ | nSDWR; // RAM write
+
+ assign nIORD = nIORQ | nSDRD; // Port read
+ assign nIOWR = nIORQ | nSDWR; // Port write
+
+ // Port $x0, $x1, $x2, $x3 read
+ assign nSDZ80R = (nIORD | SDA_L[3] | SDA_L[2]);
+ // Port $x0, $x1, $x2, $x3 write
+ assign nSDZ80CLR = (nIOWR | SDA_L[3] | SDA_L[2]);
+
+ // Port $x4, $x5, $x6, $x7 read
+ assign n2610RD = (nIORD | SDA_L[3] | ~SDA_L[2]);
+ // Port $x4, $x5, $x6, $x7 write
+ assign n2610WR = (nIOWR | SDA_L[3] | ~SDA_L[2]);
+ assign n2610CS = n2610RD & n2610WR;
+
+ // Port $x8, $x9, $xA, $xB read
+ assign nSDRD0 = (nIORD | ~SDA_L[3] | SDA_L[2]);
+ // Port $x8, $x9, $xA, $xB write
+ assign nNMI_SET = (nIOWR | ~SDA_L[3] | SDA_L[2]);
+
+ // Port $xC, $xD, $xE, $xF read
+ assign nSDRD1 = (nIORD | ~SDA_L[3] | ~SDA_L[2]);
+ // Port $xC, $xD, $xE, $xF write
+ assign nSDZ80W = (nIOWR | ~SDA_L[3] | ~SDA_L[2]);
+
+ assign nNMI_RESET = nSDZ80R & nRESET;
+
+ // NMI enable DFF
+ reg nNMI_SET_d;
+ reg nSDW_d;
+ always @(posedge CLK) begin
+ nNMI_SET_d <= nNMI_SET;
+ nSDW_d <= nSDW;
+ end
+
+ always @(posedge CLK)
+ begin
+ if (!nRESET)
+ nNMI_EN <= 1'b1;
+ else if (nNMI_SET & !nNMI_SET_d)
+ nNMI_EN <= SDA_L[4];
+ end
+
+ // NMI trig DFF
+ always @(posedge CLK)
+ begin
+ if (!nNMI_RESET)
+ nZ80NMI <= 1'b1;
+ else if (nSDW & !nSDW_d)
+ nZ80NMI <= nNMI_EN;
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/io/zmc.v b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/zmc.v
new file mode 100644
index 0000000000000000000000000000000000000000..1cec0db4edfe4c3b9d46438144bcdee92beb1250
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/io/zmc.v
@@ -0,0 +1,68 @@
+//============================================================================
+// SNK NeoGeo for MiSTer
+//
+// Copyright (C) 2018 Sean 'Furrtek' Gonsalves
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//============================================================================
+
+module zmc(
+ input CLK,
+ input nRESET,
+ input nSDRD0,
+ input [1:0] SDA_L,
+ input [15:8] SDA_U,
+ output [18:11] MA
+);
+
+ // Z80 ROM Region Reg
+ // 1E = F000~F7FF = F000~F7FF 1111 (0)
+ // 0E = E000~EFFF = E000~EFFF 1110 (1)
+ // 06 = C000~DFFF = C000~DFFF 110x (2)
+ // 02 = 8000~BFFF = 8000~BFFF 10xx (3)
+
+ reg [7:0] WINDOW_0;
+ reg [6:0] WINDOW_1;
+ reg [5:0] WINDOW_2;
+ reg [4:0] WINDOW_3;
+
+ assign MA = (~SDA_U[15]) ? {3'b000, SDA_U[15:11]} : // Pass-through
+ (SDA_U[15:12] == 4'b1111) ? WINDOW_0 : // F000~F7FF
+ (SDA_U[15:12] == 4'b1110) ? {WINDOW_1, SDA_U[11]} : // E000~EFFF
+ (SDA_U[15:13] == 3'b110) ? {WINDOW_2, SDA_U[12:11]} : // C000~DFFF
+ {WINDOW_3, SDA_U[13:11]}; // 8000~BFFF
+
+ reg nSDRD0_d;
+ always @(posedge CLK) nSDRD0_d <= nSDRD0;
+
+ always @(posedge CLK)
+ begin
+ if(!nRESET) begin
+ WINDOW_0 <= 'h1E;
+ WINDOW_1 <= 'h0E;
+ WINDOW_2 <= 'h06;
+ WINDOW_3 <= 'h02;
+ end
+ else if (nSDRD0 & !nSDRD0_d) begin
+ case (SDA_L)
+ 0: WINDOW_0 <= SDA_U[15:8];
+ 1: WINDOW_1 <= SDA_U[14:8];
+ 2: WINDOW_2 <= SDA_U[13:8];
+ 3: WINDOW_3 <= SDA_U[12:8];
+ endcase
+ end
+ end
+
+endmodule
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/README.md b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..80f1c7a91f31a24125f1fd8adaf9c68dcbf222fa
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/README.md
@@ -0,0 +1,59 @@
+# JT12 FPGA Clone of Yamaha OPN hardware by Jose Tejada (@topapate)
+===================================================================
+
+You can show your appreciation through
+* [Patreon](https://patreon.com/jotego), by supporting releases
+* [Paypal](https://paypal.me/topapate), with a donation
+
+
+JT12 is an FM sound source written in Verilog, fully compatible with YM2612/YM3438 (Megadrive), YM2610 (NeoGeo) and YM2203 (PC88, arcades).
+
+The implementation tries to be as close to original hardware as possible. Low usage of FPGA resources has also been a design goal. Except in the operator section (jt12_op) where an exact replica of the original circuit is done. This could be done in less space with a different style but because this piece of the circuit was reversed engineered by Sauraen, I decided to use that knowledge.
+
+## Using JT12 in a git project
+
+If you are using JT12 in a git project, the best way to add it to your project is:
+
+1. Optionally fork JT12's repository to your own GitHub account
+2. Add it as a submodule to your git project: `git submodule add https://github.com/jotego/jt12.git`
+3. Now you can refer to the RTL files in **jt12/hdl**
+
+The advantages of a using a git submodule are:
+
+1. Your project contains a reference to a commit of the JT12 repository
+2. As long as you do not manually update the JT12 submodule, it will keep pointing to the same commit
+3. Each time you make a commit in your project, it will include a pointer to the JT12 commit used. So you will always know the JT12 that worked for you
+4. If JT12 is updated and you want to get the changes, simply update the submodule using git. The new JT12 commit used will be annotated in your project's next commit. So the history of your project will reflect that change too.
+5. JT12 files will be intact and you will use the files without altering them.
+
+## Directories
+
+* hdl -> all relevant RTL files, written in verilog
+* ver -> test benches
+* ver/verilator -> test bench that can play vgm files
+
+## Usage
+
+Chip | Top Level | QIP File
+--------|---------------|---------
+YM2610 | jt10.v | jt10.qip
+YM2612 | jt12.v | jt12.qip
+YM2203 | jt03.v | jt03.qip
+
+## Simulation
+
+There are several simulation test benches in the **ver** folder. The most important one is in the **ver/verilator** folder. The simulation script is called with the shell script **go** in the same folder. The script will compile the file **test.cpp** together with other files and the design and will simulate the tune specificied with the -f command. It can read **vgm** tunes and generate .wav output of them.
+
+## Related Projects
+
+Other sound chips from the same author
+
+Chip | Repository
+-----------------------|------------
+YM2203, YM2612, YM2610 | [JT12](https://github.com/jotego/jt12)
+YM2151 | [JT51](https://github.com/jotego/jt51)
+YM3526 | [JTOPL](https://github.com/jotego/jtopl)
+YM2149 | [JT49](https://github.com/jotego/jt49)
+sn76489an | [JT89](https://github.com/jotego/jt89)
+OKI 6295 | [JT6295](https://github.com/jotego/jt6295)
+OKI MSM5205 | [JT5205](https://github.com/jotego/jt5205)
\ No newline at end of file
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nedit.txt b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nedit.txt
new file mode 100644
index 0000000000000000000000000000000000000000..f612e6117b4c98aa851038510bca5bf0b0e6c3ee
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nedit.txt
@@ -0,0 +1,3 @@
+
+(output|input)[\t ]*(reg|\t| )[\t ]*(\[.*\]|\t| )[\t ]*(.*),
+.\4\t\t( \4\t\t),
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/ISN76489.h b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/ISN76489.h
new file mode 100644
index 0000000000000000000000000000000000000000..f2350ee442421e7c544f61488c2fcf444c9cfd8c
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/ISN76489.h
@@ -0,0 +1,64 @@
+#ifndef __ISN76489_H__
+#define __ISN76489_H__
+#include "GenericAccess/GenericAccess.pkg"
+#include
+
+class ISN76489 :public virtual IGenericAccess
+{
+public:
+ //Constants
+ static const unsigned int channelCount = 4;
+ static const unsigned int noiseChannelNo = 3;
+ static const unsigned int toneRegisterBitCount = 10;
+ static const unsigned int volumeRegisterBitCount = 4;
+ static const unsigned int noiseRegisterBitCount = 3;
+
+ //Enumerations
+ enum class ISN76489DataSource;
+
+public:
+ //Interface version functions
+ static inline unsigned int ThisISN76489Version() { return 1; }
+ virtual unsigned int GetISN76489Version() const = 0;
+
+ //Raw register functions
+ inline unsigned int GetVolumeRegisterExternal(unsigned int channelNo) const;
+ inline void SetVolumeRegisterExternal(unsigned int channelNo, unsigned int adata);
+ inline unsigned int GetToneRegisterExternal(unsigned int channelNo) const;
+ inline void SetToneRegisterExternal(unsigned int channelNo, unsigned int adata);
+ inline unsigned int GetNoiseShiftRegisterExternal() const;
+ inline void SetNoiseShiftRegisterExternal(unsigned int adata);
+
+ //Latched register functions
+ inline unsigned int GetLatchedChannelNoExternal() const;
+ inline void SetLatchedChannelNoExternal(unsigned int adata);
+ inline bool GetVolumeRegisterLatchedExternal() const;
+ inline void SetVolumeRegisterLatchedExternal(bool adata);
+
+ //Device property functions
+ inline double GetExternalClockRate() const;
+ inline void SetExternalClockRate(double adata);
+ inline double GetExternalClockDivider() const;
+ inline void SetExternalClockDivider(double adata);
+ inline unsigned int GetShiftRegisterBitCount() const;
+ inline void SetShiftRegisterBitCount(unsigned int adata);
+ inline unsigned int GetShiftRegisterDefaultValue() const;
+ inline void SetShiftRegisterDefaultValue(unsigned int adata);
+ inline unsigned int GetNoiseChannelWhiteNoiseTappedBitMask() const;
+ inline void SetNoiseChannelWhiteNoiseTappedBitMask(unsigned int adata);
+ inline unsigned int GetNoiseChannelPeriodicNoiseTappedBitMask() const;
+ inline void SetNoiseChannelPeriodicNoiseTappedBitMask(unsigned int adata);
+
+ //Audio logging functions
+ inline bool IsAudioLoggingEnabled() const;
+ inline void SetAudioLoggingEnabled(bool adata);
+ inline bool IsChannelAudioLoggingEnabled(unsigned int channelNo) const;
+ inline void SetChannelAudioLoggingEnabled(unsigned int channelNo, bool adata);
+ inline std::wstring GetAudioLoggingOutputPath() const;
+ inline void SetAudioLoggingOutputPath(const std::wstring& adata);
+ inline std::wstring GetChannelAudioLoggingOutputPath(unsigned int channelNo) const;
+ inline void SetChannelAudioLoggingOutputPath(unsigned int channelNo, const std::wstring& adata);
+};
+
+#include "ISN76489.inl"
+#endif
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.cpp b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..62b9170d73cd8fbbfe615aeb4ca3fbdb429f1c44
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.cpp
@@ -0,0 +1,1267 @@
+#include "SN76489.h"
+#include
+#include
+
+//----------------------------------------------------------------------------------------
+//Constructors
+//----------------------------------------------------------------------------------------
+SN76489::SN76489(const std::wstring& aimplementationName, const std::wstring& ainstanceName, unsigned int amoduleID)
+:Device(aimplementationName, ainstanceName, amoduleID), reg(channelCount * 2, false, Data(toneRegisterBitCount))
+{
+ //Initialize the audio output stream
+ outputSampleRate = 48000; //44100;
+ outputStream.Open(1, 16, outputSampleRate, outputSampleRate/4, outputSampleRate/20);
+
+ //Initialize the locked register state
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ channelVolumeRegisterLocked[i] = false;
+ channelDataRegisterLocked[i] = false;
+ }
+ noiseChannelTypeLocked = false;
+ noiseChannelPeriodLocked = false;
+
+ //##TODO## Provide a way for these properties to be defined externally, and provide
+ //debug windows which can modify them on the fly.
+ externalClockRate = 0.0;
+ externalClockDivider = 16.0;
+ shiftRegisterBitCount = 16;
+ shiftRegisterDefaultValue = 0x8000;
+ noiseWhiteTappedBitMask = 0x0009;
+ noisePeriodicTappedBitMask = 0x0001;
+}
+
+//----------------------------------------------------------------------------------------
+//Interface version functions
+//----------------------------------------------------------------------------------------
+unsigned int SN76489::GetISN76489Version() const
+{
+ return ThisISN76489Version();
+}
+
+//----------------------------------------------------------------------------------------
+//Initialization functions
+//----------------------------------------------------------------------------------------
+bool SN76489::BuildDevice()
+{
+ //Initialize the wave logging state
+ std::wstring captureFolder = GetSystemInterface().GetCapturePath();
+ wavLoggingEnabled = false;
+ std::wstring wavLoggingFileName = GetDeviceInstanceName() + L".wav";
+ wavLoggingPath = PathCombinePaths(captureFolder, wavLoggingFileName);
+ for(unsigned int channelNo = 0; channelNo < channelCount; ++channelNo)
+ {
+ wavLoggingChannelEnabled[channelNo] = false;
+ std::wstringstream wavLoggingChannelFileName;
+ wavLoggingChannelFileName << GetDeviceInstanceName() << L" - C" << channelNo << L".wav";
+ wavLoggingChannelPath[channelNo] = PathCombinePaths(captureFolder, wavLoggingChannelFileName.str());
+ }
+
+ //Register each data source with the generic data access base class
+ std::wstring audioLogExtensionFilter = L"Wave file|wav";
+ std::wstring audioLogDefaultExtension = L"wav";
+ GenericAccessDataInfo* dataInfoShiftRegister;
+ GenericAccessDataInfo* dataInfoShiftRegisterDefaultValue;
+ GenericAccessDataInfo* dataInfoShiftRegisterWhiteNoiseBits;
+ GenericAccessDataInfo* dataInfoShiftRegisterPeriodicNoiseBits;
+ bool result = true;
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel1VolumeRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel2VolumeRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel3VolumeRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4VolumeRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel1ToneRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel2ToneRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel3ToneRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4ToneRegister, IGenericAccessDataValue::DataType::UInt))->SetLockingSupported(true)->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4NoiseType, IGenericAccessDataValue::DataType::Bool))->SetLockingSupported(true));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4NoisePeriod, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue(3)->SetLockingSupported(true));
+ result &= AddGenericDataInfo(dataInfoShiftRegister = (new GenericAccessDataInfo(ISN76489DataSource::NoiseShiftRegister, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::LatchedChannelNo, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue(channelCount-1));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::VolumeRegisterLatched, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::ExternalClockRate, IGenericAccessDataValue::DataType::Double))->SetDoubleMinValue(0.0));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::ExternalClockDivider, IGenericAccessDataValue::DataType::Double))->SetDoubleMinValue(1.0));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::ShiftRegisterBitCount, IGenericAccessDataValue::DataType::UInt))->SetUIntMinValue(1)->SetUIntMaxValue(32)->SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Decimal));
+ result &= AddGenericDataInfo(dataInfoShiftRegisterDefaultValue = (new GenericAccessDataInfo(ISN76489DataSource::ShiftRegisterDefaultValue, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo(dataInfoShiftRegisterWhiteNoiseBits = (new GenericAccessDataInfo(ISN76489DataSource::WhiteNoiseTappedBitMask, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo(dataInfoShiftRegisterPeriodicNoiseBits = (new GenericAccessDataInfo(ISN76489DataSource::PeriodicNoiseTappedBitMask, IGenericAccessDataValue::DataType::UInt))->SetUIntMaxValue((1<SetIntDisplayMode(IGenericAccessDataValue::IntDisplayMode::Hexadecimal));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::AudioLoggingEnabled, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::AudioLoggingPath, IGenericAccessDataValue::DataType::FilePath))->SetFilePathExtensionFilter(audioLogExtensionFilter)->SetFilePathDefaultExtension(audioLogDefaultExtension)->SetFilePathCreatingTarget(true));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel1AudioLoggingEnabled, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel2AudioLoggingEnabled, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel3AudioLoggingEnabled, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4AudioLoggingEnabled, IGenericAccessDataValue::DataType::Bool)));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel1AudioLoggingPath, IGenericAccessDataValue::DataType::FilePath))->SetFilePathExtensionFilter(audioLogExtensionFilter)->SetFilePathDefaultExtension(audioLogDefaultExtension)->SetFilePathCreatingTarget(true));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel2AudioLoggingPath, IGenericAccessDataValue::DataType::FilePath))->SetFilePathExtensionFilter(audioLogExtensionFilter)->SetFilePathDefaultExtension(audioLogDefaultExtension)->SetFilePathCreatingTarget(true));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel3AudioLoggingPath, IGenericAccessDataValue::DataType::FilePath))->SetFilePathExtensionFilter(audioLogExtensionFilter)->SetFilePathDefaultExtension(audioLogDefaultExtension)->SetFilePathCreatingTarget(true));
+ result &= AddGenericDataInfo((new GenericAccessDataInfo(ISN76489DataSource::Channel4AudioLoggingPath, IGenericAccessDataValue::DataType::FilePath))->SetFilePathExtensionFilter(audioLogExtensionFilter)->SetFilePathDefaultExtension(audioLogDefaultExtension)->SetFilePathCreatingTarget(true));
+
+ //Save references to the data info structures which contain values that need to have
+ //their limits changed when the bitcount for the shift register is changed.
+ genericDataToUpdateOnShiftRegisterBitCountChange.push_back(dataInfoShiftRegister);
+ genericDataToUpdateOnShiftRegisterBitCountChange.push_back(dataInfoShiftRegisterDefaultValue);
+ genericDataToUpdateOnShiftRegisterBitCountChange.push_back(dataInfoShiftRegisterWhiteNoiseBits);
+ genericDataToUpdateOnShiftRegisterBitCountChange.push_back(dataInfoShiftRegisterPeriodicNoiseBits);
+
+ //Register page layouts for generic access to this device
+ //##TODO## Investigate implementing a central resource system using resource key names
+ //of the form "AssemblyName:DictionaryName:KeyName", where each assembly registers its
+ //internal resource strings using FindResourceEx, LoadResource, LockResource, and the
+ //platform retrieves the most appropriate matching resource based on the current
+ //culture. That would remove literal text strings here and open our platform up for
+ //easy localization. Note that it must be possible for an assembly to register
+ //resource keys against another assembly, as well as register the same resource key
+ //against different cultures. I would also suggest we have the concept of a fallback
+ //value for a particular resource key, where a device for example could ship with all
+ //strings in a particular language, but another assembly could be added later which
+ //specifies resource overrides for all strings, including the invariant culture, while
+ //the fallback resource values are used in the case that nothing else is defined which
+ //is appropriate, IE, as might be the case if the device is updated and the
+ //localization isn't yet.
+ GenericAccessPage* registersPage = new GenericAccessPage(L"Registers", L"Registers");
+ registersPage->AddEntry((new GenericAccessGroup(L"Channel 1"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel1VolumeRegister, L"Volume"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel1ToneRegister, L"Tone")))
+ ->AddEntry((new GenericAccessGroup(L"Channel 2"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel2VolumeRegister, L"Volume"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel2ToneRegister, L"Tone")))
+ ->AddEntry((new GenericAccessGroup(L"Channel 3"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel3VolumeRegister, L"Volume"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel3ToneRegister, L"Tone")))
+ ->AddEntry((new GenericAccessGroup(L"Channel 4"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel4VolumeRegister, L"Volume"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel4ToneRegister, L"Tone"))
+ ->AddEntry((new GenericAccessGroupSingleSelectionList(ISN76489DataSource::Channel4NoiseType, L"Noise Type"))->SetAllowNewItemEntry(true)
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"Periodic [0]"), new GenericAccessDataValueBool(false))
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"White [1]"), new GenericAccessDataValueBool(true)))
+ ->AddEntry((new GenericAccessGroupSingleSelectionList(ISN76489DataSource::Channel4NoisePeriod, L"Noise Period"))->SetAllowNewItemEntry(true)
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"Low"), new GenericAccessDataValueUInt(0x0))
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"Medium"), new GenericAccessDataValueUInt(0x01))
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"High"), new GenericAccessDataValueUInt(0x02))
+ ->AddSelectionListEntry(new GenericAccessDataValueString(L"Channel 3 Tone"), new GenericAccessDataValueUInt(0x03)))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::NoiseShiftRegister, L"Noise Shift Register")))
+ ->AddEntry((new GenericAccessGroup(L"Control"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::LatchedChannelNo, L"Latched Channel No"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::VolumeRegisterLatched, L"Volume Register Latched")));
+ result &= AddGenericAccessPage(registersPage);
+ GenericAccessPage* parametersPage = new GenericAccessPage(L"Parameters", L"Parameters");
+ parametersPage->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::ExternalClockRate, L"External Clock Rate"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::ExternalClockDivider, L"External Clock Divider"))
+ ->AddEntry((new GenericAccessGroup(L"Noise Channel"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::ShiftRegisterBitCount, L"Shift Register Bit Count"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::ShiftRegisterDefaultValue, L"Shift Register Default Value"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::WhiteNoiseTappedBitMask, L"White Noise Tapped Bit Mask"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::PeriodicNoiseTappedBitMask, L"Periodic Noise Tapped Bit Mask")));
+ result &= AddGenericAccessPage(parametersPage);
+ GenericAccessPage* audioLoggingPage = new GenericAccessPage(L"Audio Logging", L"Audio Logging");
+ audioLoggingPage->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::AudioLoggingEnabled, L"Log Enabled"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::AudioLoggingPath, L"Log Path"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel1AudioLoggingEnabled, L"Channel 1 Log Enabled"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel2AudioLoggingEnabled, L"Channel 2 Log Enabled"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel3AudioLoggingEnabled, L"Channel 3 Log Enabled"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel4AudioLoggingEnabled, L"Channel 4 Log Enabled"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel1AudioLoggingPath, L"Channel 1 Log Path"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel2AudioLoggingPath, L"Channel 2 Log Path"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel3AudioLoggingPath, L"Channel 3 Log Path"))
+ ->AddEntry(new GenericAccessGroupDataEntry(ISN76489DataSource::Channel4AudioLoggingPath, L"Channel 4 Log Path"));
+ result &= AddGenericAccessPage(audioLoggingPage);
+
+ return result;
+}
+
+//----------------------------------------------------------------------------------------
+bool SN76489::ValidateDevice()
+{
+ return (externalClockRate != 0.0);
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::Initialize()
+{
+ //Initialize the render thread properties
+ remainingRenderTime = 0;
+
+ //Initialize the render data
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ channelRenderData[i].polarityNegative = false;
+ channelRenderData[i].remainingToneCycles = 0;
+ }
+ noiseShiftRegister = shiftRegisterDefaultValue;
+ noiseOutputMasked = true;
+ outputBuffer.clear();
+
+ //Initialize the register block, and set the correct register sizes for each entry.
+ reg.Initialize();
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ if(i == noiseChannelNo)
+ {
+ reg.ReferenceCommitted((i*2) + 0).Resize(volumeRegisterBitCount);
+ reg.ReferenceCommitted((i*2) + 1).Resize(noiseRegisterBitCount);
+ }
+ else
+ {
+ reg.ReferenceCommitted((i*2) + 0).Resize(volumeRegisterBitCount);
+ reg.ReferenceCommitted((i*2) + 1).Resize(toneRegisterBitCount);
+ }
+ }
+
+ //According to SN76489.txt by Maxim, SEGA integrated versions of the PSG have the
+ //channels initialized with data all zeros, and volume all ones. This has been
+ //verified through hardware tests.
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ if(!channelVolumeRegisterLocked[i])
+ {
+ SetVolumeRegister(i, Data(volumeRegisterBitCount, ~0u), AccessTarget().AccessLatest());
+ }
+ if(!channelDataRegisterLocked[i])
+ {
+ SetToneRegister(i, Data(toneRegisterBitCount, 0), AccessTarget().AccessLatest());
+ }
+ }
+
+ //Note that hardware tests on a Mega Drive have shown that SEGA integrated versions of
+ //the PSG are initialized with the volume register of the second channel latched.
+ //##TODO## Make these power-on defaults configurable through the system XML file
+ latchedChannel = 1;
+ latchedVolume = true;
+}
+
+//----------------------------------------------------------------------------------------
+//Clock source functions
+//----------------------------------------------------------------------------------------
+unsigned int SN76489::GetClockSourceID(const MarshalSupport::Marshal::In& clockSourceName) const
+{
+ if(clockSourceName == L"CLOCK")
+ {
+ return (unsigned int)ClockID::Clock;
+ }
+ return 0;
+}
+
+//----------------------------------------------------------------------------------------
+MarshalSupport::Marshal::Ret SN76489::GetClockSourceName(unsigned int clockSourceID) const
+{
+ switch((ClockID)clockSourceID)
+ {
+ case ClockID::Clock:
+ return L"CLOCK";
+ }
+ return L"";
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::SetClockSourceRate(unsigned int clockInput, double clockRate, IDeviceContext* caller, double accessTime, unsigned int accessContext)
+{
+ //Apply the input clock rate change
+ if((ClockID)clockInput == ClockID::Clock)
+ {
+ externalClockRate = clockRate;
+ }
+
+ //Since a clock rate change will affect our timing point calculations, trigger a
+ //rollback.
+ GetSystemInterface().SetSystemRollback(GetDeviceContext(), caller, accessTime, accessContext);
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::TransparentSetClockSourceRate(unsigned int clockInput, double clockRate)
+{
+ //Apply the input clock rate change
+ if((ClockID)clockInput == ClockID::Clock)
+ {
+ externalClockRate = clockRate;
+ }
+}
+
+//----------------------------------------------------------------------------------------
+//Execute functions
+//----------------------------------------------------------------------------------------
+void SN76489::BeginExecution()
+{
+ //Initialize the worker thread state
+ pendingRenderOperationCount = 0;
+ renderThreadLagging = false;
+ regTimesliceList.clear();
+
+ //Start the render worker thread
+ renderThreadActive = true;
+ std::thread workerThread(std::bind(std::mem_fn(&SN76489::RenderThread), this));
+ workerThread.detach();
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::SuspendExecution()
+{
+ std::unique_lock lock(renderThreadMutex);
+
+ //Suspend the render worker thread
+ if(renderThreadActive)
+ {
+ renderThreadActive = false;
+ renderThreadUpdate.notify_all();
+ renderThreadStopped.wait(lock);
+ }
+}
+
+//----------------------------------------------------------------------------------------
+bool SN76489::SendNotifyUpcomingTimeslice() const
+{
+ return true;
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::NotifyUpcomingTimeslice(double nanoseconds)
+{
+ lastAccessTime = 0;
+
+ //Add the new timeslice to all our timed buffers
+ reg.AddTimeslice(nanoseconds);
+
+ //Add references to the new timeslice entry from our timed buffers to the uncommitted
+ //timeslice lists for the buffers
+ regTimesliceListUncommitted.push_back(reg.GetLatestTimeslice());
+}
+
+//----------------------------------------------------------------------------------------
+Device::UpdateMethod SN76489::GetUpdateMethod() const
+{
+ return UpdateMethod::Timeslice;
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::ExecuteTimeslice(double nanoseconds)
+{
+ //If the render thread is lagging, pause here until it has caught up, so we don't
+ //leave the render thread behind with an ever-increasing workload it will never be
+ //able to complete.
+ if(renderThreadLagging)
+ {
+ std::unique_lock lock(timesliceMutex);
+ while(renderThreadLagging)
+ {
+ renderThreadLaggingStateChange.wait(lock);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::ExecuteRollback()
+{
+ //Rollback our timed buffers
+ reg.Rollback();
+
+ latchedChannel = blatchedChannel;
+ latchedVolume = blatchedVolume;
+
+ //Clear any uncommitted timeslices from our render timeslice buffers
+ regTimesliceListUncommitted.clear();
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::ExecuteCommit()
+{
+ //Commit our timed buffers
+ reg.Commit();
+
+ blatchedChannel = latchedChannel;
+ blatchedVolume = latchedVolume;
+
+ //Ensure that a valid latest timeslice exists in all our buffers. We need this check
+ //here, because commits can be triggered by the system at potentially any point in
+ //time, whether a timeslice has been issued or not.
+ if(!regTimesliceListUncommitted.empty())
+ {
+ //Obtain a timeslice lock so we can update the data we feed to the render thread
+ std::unique_lock lock(timesliceMutex);
+
+ //Add the number of timeslices we are about to commit to the count of pending
+ //render operations. This is used to track if the render thread is lagging.
+ pendingRenderOperationCount += (unsigned int)regTimesliceListUncommitted.size();
+
+ //Move all timeslices in our uncommitted timeslice lists over to the committed
+ //timeslice lists, for processing by the render thread.
+ regTimesliceList.splice(regTimesliceList.end(), regTimesliceListUncommitted);
+
+ //Notify the render thread that it's got more work to do
+ renderThreadUpdate.notify_all();
+ }
+}
+
+//----------------------------------------------------------------------------------------
+//Render functions
+//----------------------------------------------------------------------------------------
+void SN76489::RenderThread()
+{
+ std::unique_lock lock(renderThreadMutex);
+
+ //Start the render loop
+ bool done = false;
+ while(!done)
+ {
+ //Obtain a copy of the latest completed timeslice period
+ RandomTimeAccessBuffer::Timeslice regTimesliceCopy;
+ bool renderTimesliceObtained = false;
+ {
+ std::unique_lock timesliceLock(timesliceMutex);
+
+ //If there is at least one render timeslice pending, grab it from the queue.
+ if(!regTimesliceList.empty())
+ {
+ //Update the lagging state for the render thread
+ --pendingRenderOperationCount;
+ renderThreadLagging = (pendingRenderOperationCount > maxPendingRenderOperationCount);
+ renderThreadLaggingStateChange.notify_all();
+
+ //Grab the next completed timeslice from the timeslice list
+ regTimesliceCopy = *regTimesliceList.begin();
+ regTimesliceList.pop_front();
+
+ //Flag that we managed to obtain a render timeslice
+ renderTimesliceObtained = true;
+ }
+ }
+
+ //If no render timeslice was available, we need to wait for a thread suspension
+ //request or a new timeslice to be received, then begin the loop again.
+ if(!renderTimesliceObtained)
+ {
+ //If the render thread has not already been instructed to stop, suspend this
+ //thread until a timeslice becomes available or this thread is instructed to
+ //stop.
+ if(renderThreadActive)
+ {
+ renderThreadUpdate.wait(lock);
+ }
+
+ //If the render thread has been suspended, flag that we need to exit this
+ //render loop.
+ done = !renderThreadActive;
+
+ //Begin the loop again
+ continue;
+ }
+
+ //Render the audio output
+ size_t outputBufferPos = outputBuffer.size();
+ double outputFrequency = externalClockRate / externalClockDivider;
+ bool moreSamplesRemaining = true;
+ while(moreSamplesRemaining)
+ {
+ //Determine the time of the next write. Note that currently, this may be
+ //negative under certain circumstances, in particular when a write occurs past
+ //the end of a timeslice. Negative times won't cause writes to be processed at
+ //the incorrect time under the current model, but we do need to ensure that
+ //remainingRenderTime isn't negative before attempting to generate an output.
+ remainingRenderTime += reg.GetNextWriteTime(regTimesliceCopy);
+
+ //Calculate the output sample count. Note that remainingRenderTime may be
+ //negative, but we catch that below before using outputSampleCount.
+ unsigned int outputSampleCount = (unsigned int)(remainingRenderTime * (outputFrequency / 1000000000.0));
+
+ //If we have one or more output samples to generate before the next settings
+ //change or the end of the target timeslice, generate and output the samples.
+ if((remainingRenderTime > 0) && (outputSampleCount > 0))
+ {
+ //Resize the output buffer to fit the samples we're about to add
+ outputBuffer.resize(outputBuffer.size() + outputSampleCount);
+
+ //For each channel, calculate the output data for the elapsed time
+ std::vector channelBuffer[channelCount];
+ for(unsigned int channelNo = 0; channelNo < channelCount; ++channelNo)
+ {
+ channelBuffer[channelNo].resize(outputSampleCount);
+ UpdateChannel(channelNo, outputSampleCount, channelBuffer[channelNo]);
+
+ //Output the channel wave log
+ if(wavLoggingChannelEnabled[channelNo])
+ {
+ std::unique_lock lock(waveLoggingMutex);
+ for(unsigned int i = 0; i < channelBuffer[channelNo].size(); ++i)
+ {
+ short sample = (short)(channelBuffer[channelNo][i] * (32767.0f/channelCount));
+ wavLogChannel[channelNo].WriteData(sample);
+ }
+ }
+ }
+
+ //Mix the output from each channel into a combined output buffer
+ for(unsigned int sampleNo = 0; sampleNo < outputSampleCount; ++sampleNo)
+ {
+ float mixedSample = 0.0;
+ for(unsigned int channelNo = 0; channelNo < channelCount; ++channelNo)
+ {
+ mixedSample += channelBuffer[channelNo][sampleNo];
+ }
+ mixedSample /= channelCount;
+ outputBuffer[outputBufferPos++] = (short)(mixedSample * (32767.0f / 6.0f));
+ }
+
+ RandomTimeAccessBuffer::WriteInfo writeInfo = reg.GetWriteInfo(0, regTimesliceCopy);
+ if(writeInfo.exists)
+ {
+ //If the noise register is being modified, we need to reset the LFSR
+ //to the default for value for the next cycle.
+ if(writeInfo.writeAddress == (noiseChannelNo * 2) + 1)
+ {
+ noiseShiftRegister = shiftRegisterDefaultValue;
+ }
+ }
+
+ //Adjust the remainingRenderTime variable to remove the time we just
+ //consumed generating the output samples.
+ remainingRenderTime -= (double)outputSampleCount * (1000000000.0 / outputFrequency);
+ }
+
+ //Advance to the next write operation, or the end of the current timeslice.
+ moreSamplesRemaining = reg.AdvanceByStep(regTimesliceCopy);
+ }
+
+ //Output the mixed channel wave log
+ if(wavLoggingEnabled)
+ {
+ std::unique_lock lock(waveLoggingMutex);
+ wavLog.WriteData(outputBuffer);
+ }
+
+ //Play the mixed audio stream. Note that we fold samples from successive render
+ //operations together, ensuring that we only send data to the output audio stream
+ //when we have a significant number of samples to send.
+ size_t minimumSamplesToOutput = (size_t)(outputFrequency / 60.0);
+ if(outputBuffer.size() >= minimumSamplesToOutput)
+ {
+ unsigned int internalSampleCount = (unsigned int)outputBuffer.size();
+ unsigned int outputSampleCount = (unsigned int)((double)internalSampleCount * ((double)outputSampleRate / outputFrequency));
+ AudioStream::AudioBuffer* outputBufferFinal = outputStream.CreateAudioBuffer(outputSampleCount, 1);
+ if(outputBufferFinal != 0)
+ {
+ outputStream.ConvertSampleRate(outputBuffer, internalSampleCount, 1, outputBufferFinal->buffer, outputSampleCount);
+ outputStream.PlayBuffer(outputBufferFinal);
+ }
+ outputBuffer.clear();
+ outputBuffer.reserve(minimumSamplesToOutput * 2);
+ }
+
+ //Advance past the timeslice we've just rendered from
+ {
+ std::unique_lock lock(timesliceMutex);
+ reg.AdvancePastTimeslice(regTimesliceCopy);
+ }
+ }
+ renderThreadStopped.notify_all();
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::UpdateChannel(unsigned int channelNo, unsigned int outputSampleCount, std::vector& outputBuffer)
+{
+ ChannelRenderData* renderData = &channelRenderData[channelNo];
+
+ //Read current register data, and calculate half-frequency and amplitude
+ Data volumeRegisterData(GetVolumeRegister(channelNo, AccessTarget().AccessCommitted()));
+ Data toneRegisterData(GetToneRegister(channelNo, AccessTarget().AccessCommitted()));
+ float amplitude = 0.0;
+ if(volumeRegisterData.GetData() < 0xF)
+ {
+ //##NOTE## There is an error in SN76489.txt regarding attenuation. The document
+ //correctly states that each step of the volume register corresponds with 2db of
+ //attenuation (as stated by the SN76489 datasheet), however the math that follows
+ //is erroneous. A decibel is a 10th of a bel(0.1 bels), not 10 bels, and a 2db
+ //drop corresponds to the ratio 10^(-0.2), not 10^(-0.1).
+ //##NOTE## There might be more to this. Remember that we had to divide the
+ //attenuation power in the YM2612 core by 2 to get the correct result. Maybe
+ //Maxim is right afterall, and you have to halve the attenuation power in the
+ //YM2612 core, and this core, in order to get the correct result. Examine the
+ //math he provided and do some more research. Maybe we're wrong about our
+ //conversion from db to linear.
+// float attenuationInBels = (float)(volumeRegisterData.GetData() * 2) / 10.0f;
+ float attenuationInBels = (float)volumeRegisterData.GetData() / 10.0f;
+ amplitude = pow(10.0f, -attenuationInBels);
+ }
+
+ //If we're updating the noise register, decode the noise register data.
+ bool whiteNoiseSelected = false;
+ if(channelNo == noiseChannelNo)
+ {
+ //Noise register format
+ // --------------
+ // | 2 | 1 | 0 |
+ // |------------|
+ // |Type|Period |
+ // ==============
+ //Type: Noise type (0 = Periodic, 1 = White)
+ //Period: Shift rate (0 = 0x10, 1 = 0x20, 2 = 0x40, 3 = Tone2)
+ whiteNoiseSelected = toneRegisterData.GetBit(2);
+ switch(toneRegisterData.GetDataSegment(0, 2))
+ {
+ case 0:
+ toneRegisterData = 0x10;
+ break;
+ case 1:
+ toneRegisterData = 0x20;
+ break;
+ case 2:
+ toneRegisterData = 0x40;
+ break;
+ case 3:
+ //Read the current tone register data from channel 2
+ toneRegisterData = GetToneRegister(2, AccessTarget().AccessCommitted()).GetData();
+ break;
+ }
+ }
+
+ //If we were partway through a cycle on this channel when we rendered the last step,
+ //resume the last cycle.
+ unsigned int samplesWritten = 0;
+ while((renderData->remainingToneCycles > 0) && (samplesWritten < outputSampleCount))
+ {
+ //If we're starting the output on a negative cycle, negate the output data.
+ float writeData = (renderData->polarityNegative)? -amplitude: amplitude;
+
+ //If we're updating the noise register, calculate the output data based on
+ //the shift register.
+ if(channelNo == noiseChannelNo)
+ {
+ //Use the current noise bit to calculate the output data
+ writeData = (noiseOutputMasked)? 0: amplitude;
+ }
+
+ //Write the sample to the output buffer
+ outputBuffer[samplesWritten++] = writeData;
+ --renderData->remainingToneCycles;
+ }
+
+ //##NOTE## Hardware tests on the SEGA integrated chip have shown that when the tone
+ //data is set to 0, it behaves the same as a tone data value of 1. This includes the
+ //noise channel when the period is obtained from the channel 2 tone data. This
+ //behaviour contradicts the information in SN76489.txt, but our readings are clear.
+ //Tone data values of both 0 and 1 produce a square wave that toggles between
+ //positive and negative each internal clock cycle. This has been confirmed by
+ //sampling the PSG output directly from the chip using an oscilloscope. SN76489.txt
+ //states that the channel output is held at +1 when the tone data is set to 0.
+ //Perhaps this is true for other implementations of this device, but our observed
+ //behaviour is correct for the SEGA embedded version used in the Mega Drive. Note
+ //that "After Burner II" uses a tone value of 0 in all PSG channels for its audio,
+ //causing distorted sound on the system. The PSG sound emulation for this game is
+ //fundamentally inaccurate when we hold the output at +1.
+ if(toneRegisterData == 0)
+ {
+ toneRegisterData = 1;
+ }
+
+ //Output repeating oscillations of the wave at the target frequency and amplitude
+ while(samplesWritten < outputSampleCount)
+ {
+ unsigned int samplesToWrite = toneRegisterData.GetData();
+
+ //Invert the polarity of the wave in preparation for the new cycle
+ renderData->polarityNegative = !renderData->polarityNegative;
+
+ //If we're starting the output on a negative cycle, negate the output data.
+ float writeData = (renderData->polarityNegative)? -amplitude: amplitude;
+
+ //If we're updating the noise register, calculate the output data based on
+ //the shift register.
+ if(channelNo == noiseChannelNo)
+ {
+ unsigned int tappedBitMask = whiteNoiseSelected? noiseWhiteTappedBitMask: noisePeriodicTappedBitMask;
+
+ //If the polarity has shifted from -1 to +1, read a new output bit
+ //and adjust the shift register.
+ if(!renderData->polarityNegative)
+ {
+ Data shiftRegister(shiftRegisterBitCount, noiseShiftRegister);
+ noiseOutputMasked = !shiftRegister.GetBit(0);
+ bool newUpperBit = !((shiftRegister & tappedBitMask).ParityEven());
+ shiftRegister >>= 1;
+ shiftRegister.SetBit(shiftRegister.GetBitCount() - 1, newUpperBit);
+ noiseShiftRegister = shiftRegister.GetData();
+ }
+
+ //Use the current noise bit to calculate the output data
+ writeData = (noiseOutputMasked)? 0: amplitude;
+ }
+
+ if(samplesToWrite > (outputSampleCount - samplesWritten))
+ {
+ //If we don't have enough samples remaining in this step to complete
+ //the next cycle, clamp the number of samples to write, and save the
+ //number of additional samples we need to complete for the next step.
+ renderData->initialToneCycles = samplesToWrite;
+ renderData->remainingToneCycles = samplesToWrite - (outputSampleCount - samplesWritten);
+ samplesToWrite = (outputSampleCount - samplesWritten);
+ }
+
+ //Write a block of samples to the output buffer
+ for(unsigned int i = 0; i < samplesToWrite; ++i)
+ {
+ outputBuffer[samplesWritten++] = writeData;
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------
+//Memory interface functions
+//----------------------------------------------------------------------------------------
+IBusInterface::AccessResult SN76489::WriteInterface(unsigned int interfaceNumber, unsigned int location, const Data& data, IDeviceContext* caller, double accessTime, unsigned int accessContext)
+{
+ std::unique_lock lock(accessMutex);
+ AccessTarget accessTarget;
+ accessTarget.AccessTime(accessTime);
+
+ //Trigger a system rollback if the device has been accessed out of order. This is
+ //required in order to ensure that the register latch settings are correct when each
+ //write occurs.
+ if(accessTime < lastAccessTime)
+ {
+ GetSystemInterface().SetSystemRollback(GetDeviceContext(), caller, accessTime, accessContext);
+ }
+ lastAccessTime = accessTime;
+
+ //Process the write
+ if(data.MSB())
+ {
+ //Latch/Data byte format
+ //----------------------------------
+ //| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ //|---|-------|----|---------------|
+ //| 1 |Channel|Type|Data (low bits)|
+ //----------------------------------
+
+ //Process a latch/data byte
+ latchedChannel = data.GetDataSegment(5, 2);
+ latchedVolume = data.GetBit(4);
+ if(latchedVolume)
+ {
+ Data temp(GetVolumeRegister(latchedChannel, accessTarget));
+ temp.SetLowerBits(4, data.GetDataSegment(0, 4));
+ if(!channelVolumeRegisterLocked[latchedChannel])
+ {
+ SetVolumeRegister(latchedChannel, temp, accessTarget);
+ }
+ }
+ else
+ {
+ Data temp(GetToneRegister(latchedChannel, accessTarget));
+ temp.SetLowerBits(4, data.GetDataSegment(0, 4));
+ if(latchedChannel == noiseChannelNo)
+ {
+ if(noiseChannelTypeLocked)
+ {
+ temp.SetBit(2, GetToneRegister(latchedChannel, accessTarget).GetBit(2));
+ }
+ if(noiseChannelPeriodLocked)
+ {
+ temp.SetDataSegment(0, 2, GetToneRegister(latchedChannel, accessTarget).GetDataSegment(0, 2));
+ }
+ }
+ if(!channelDataRegisterLocked[latchedChannel])
+ {
+ SetToneRegister(latchedChannel, temp, accessTarget);
+ }
+ }
+ }
+ else
+ {
+ //Data byte format
+ //---------------------------------
+ //| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+ //|---|---|-----------------------|
+ //| 0 | - | Data (high bits) |
+ //---------------------------------
+
+ //Process a data byte
+ if(latchedVolume)
+ {
+ Data temp(GetVolumeRegister(latchedChannel, accessTarget));
+ temp.SetUpperBits(6, data.GetDataSegment(0, 6));
+ if(!channelVolumeRegisterLocked[latchedChannel])
+ {
+ SetVolumeRegister(latchedChannel, temp, accessTarget);
+ }
+ }
+ else
+ {
+ Data temp(GetToneRegister(latchedChannel, accessTarget));
+ temp.SetUpperBits(6, data.GetDataSegment(0, 6));
+ if(latchedChannel == noiseChannelNo)
+ {
+ if(noiseChannelTypeLocked)
+ {
+ temp.SetBit(2, GetToneRegister(latchedChannel, accessTarget).GetBit(2));
+ }
+ if(noiseChannelPeriodLocked)
+ {
+ temp.SetDataSegment(0, 2, GetToneRegister(latchedChannel, accessTarget).GetDataSegment(0, 2));
+ }
+ }
+ if(!channelDataRegisterLocked[latchedChannel])
+ {
+ SetToneRegister(latchedChannel, temp, accessTarget);
+ }
+ }
+ }
+
+ return true;
+}
+
+//----------------------------------------------------------------------------------------
+//Savestate functions
+//----------------------------------------------------------------------------------------
+void SN76489::LoadState(IHierarchicalStorageNode& node)
+{
+ std::list childList = node.GetChildList();
+ for(std::list::iterator i = childList.begin(); i != childList.end(); ++i)
+ {
+ //Clock settings
+ if((*i)->GetName() == L"ExternalClockRate")
+ {
+ (*i)->ExtractData(externalClockRate);
+ }
+
+ //Register data
+ else if((*i)->GetName() == L"Registers")
+ {
+ reg.LoadState(*(*i));
+ }
+
+ //Register latch settings
+ else if((*i)->GetName() == L"LatchedChannel")
+ {
+ (*i)->ExtractData(latchedChannel);
+ if(latchedChannel >= channelCount)
+ {
+ latchedChannel = channelCount - 1;
+ }
+ }
+ else if((*i)->GetName() == L"VolumeRegisterLatched")
+ {
+ (*i)->ExtractData(latchedVolume);
+ }
+
+ //Render thread properties
+ else if((*i)->GetName() == L"RemainingRenderTime")
+ {
+ (*i)->ExtractData(remainingRenderTime);
+ }
+
+ //Render data
+ else if((*i)->GetName() == L"RenderData")
+ {
+ unsigned int channelNo;
+ if((*i)->ExtractAttribute(L"ChannelNo", channelNo) && (channelNo < channelCount))
+ {
+ (*i)->ExtractAttributeHex(L"InitialToneCycles", channelRenderData[channelNo].initialToneCycles);
+ (*i)->ExtractAttributeHex(L"RemainingToneCycles", channelRenderData[channelNo].remainingToneCycles);
+ (*i)->ExtractAttribute(L"PolarityNegative", channelRenderData[channelNo].polarityNegative);
+ }
+ }
+ else if((*i)->GetName() == L"NoiseShiftRegister")
+ {
+ (*i)->ExtractHexData(noiseShiftRegister);
+ }
+ else if((*i)->GetName() == L"NoiseOutputMasked")
+ {
+ (*i)->ExtractData(noiseOutputMasked);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::SaveState(IHierarchicalStorageNode& node) const
+{
+ //Clock settings
+ node.CreateChild(L"ExternalClockRate").SetData(externalClockRate);
+
+ //Register data
+ reg.SaveState(node.CreateChild(L"Registers"), L"", true);
+
+ //Register latch settings
+ node.CreateChild(L"LatchedChannel", latchedChannel);
+ node.CreateChild(L"VolumeRegisterLatched", latchedVolume);
+
+ //Render thread properties
+ node.CreateChild(L"RemainingRenderTime", remainingRenderTime);
+
+ //Render data
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ IHierarchicalStorageNode& renderDataState = node.CreateChild(L"RenderData");
+ renderDataState.CreateAttribute(L"ChannelNo", i);
+ renderDataState.CreateAttributeHex(L"InitialToneCycles", channelRenderData[i].initialToneCycles, (toneRegisterBitCount+3)/4);
+ renderDataState.CreateAttributeHex(L"RemainingToneCycles", channelRenderData[i].remainingToneCycles, (toneRegisterBitCount+3)/4);
+ renderDataState.CreateAttribute(L"PolarityNegative", channelRenderData[i].polarityNegative);
+ }
+ node.CreateChildHex(L"NoiseShiftRegister", noiseShiftRegister, (shiftRegisterBitCount+3)/4);
+ node.CreateChild(L"NoiseOutputMasked", noiseOutputMasked);
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::LoadDebuggerState(IHierarchicalStorageNode& node)
+{
+ //Initialize the register locking state
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ channelVolumeRegisterLocked[i] = false;
+ channelDataRegisterLocked[i] = false;
+ }
+
+ //Load the register locking state
+ std::list childList = node.GetChildList();
+ for(std::list::iterator i = childList.begin(); i != childList.end(); ++i)
+ {
+ if((*i)->GetName() == L"LockedVolumeRegister")
+ {
+ unsigned int channelNo;
+ if((*i)->ExtractAttribute(L"ChannelNo", channelNo) && (channelNo < channelCount))
+ {
+ channelVolumeRegisterLocked[channelNo] = true;
+ }
+ }
+ else if((*i)->GetName() == L"LockedDataRegister")
+ {
+ unsigned int channelNo;
+ if((*i)->ExtractAttribute(L"ChannelNo", channelNo) && (channelNo < channelCount))
+ {
+ channelDataRegisterLocked[channelNo] = true;
+ }
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::SaveDebuggerState(IHierarchicalStorageNode& node) const
+{
+ //Save the register locking state
+ for(unsigned int i = 0; i < channelCount; ++i)
+ {
+ if(channelVolumeRegisterLocked[i])
+ {
+ node.CreateChild(L"LockedVolumeRegister").CreateAttribute(L"ChannelNo", i);
+ }
+ if(channelDataRegisterLocked[i])
+ {
+ node.CreateChild(L"LockedDataRegister").CreateAttribute(L"ChannelNo", i);
+ }
+ }
+}
+
+//----------------------------------------------------------------------------------------
+//Data read/write functions
+//----------------------------------------------------------------------------------------
+bool SN76489::ReadGenericData(unsigned int dataID, const DataContext* dataContext, IGenericAccessDataValue& dataValue) const
+{
+ ApplyGenericDataValueDisplaySettings(dataID, dataValue);
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::Channel1VolumeRegister:
+ return dataValue.SetValue(GetVolumeRegister(0, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel2VolumeRegister:
+ return dataValue.SetValue(GetVolumeRegister(1, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel3VolumeRegister:
+ return dataValue.SetValue(GetVolumeRegister(2, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel4VolumeRegister:
+ return dataValue.SetValue(GetVolumeRegister(3, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel1ToneRegister:
+ return dataValue.SetValue(GetToneRegister(0, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel2ToneRegister:
+ return dataValue.SetValue(GetToneRegister(1, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel3ToneRegister:
+ return dataValue.SetValue(GetToneRegister(2, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel4ToneRegister:
+ return dataValue.SetValue(GetToneRegister(3, AccessTarget().AccessLatest()).GetData());
+ case ISN76489DataSource::Channel4NoiseType:
+ return dataValue.SetValue(GetToneRegister(3, AccessTarget().AccessLatest()).GetBit(2));
+ case ISN76489DataSource::Channel4NoisePeriod:
+ return dataValue.SetValue(GetToneRegister(3, AccessTarget().AccessLatest()).GetDataSegment(0, 2));
+ case ISN76489DataSource::NoiseShiftRegister:
+ return dataValue.SetValue(noiseShiftRegister);
+ case ISN76489DataSource::LatchedChannelNo:
+ return dataValue.SetValue(latchedChannel);
+ case ISN76489DataSource::VolumeRegisterLatched:
+ return dataValue.SetValue(latchedVolume);
+ case ISN76489DataSource::ExternalClockRate:
+ return dataValue.SetValue(externalClockRate);
+ case ISN76489DataSource::ExternalClockDivider:
+ return dataValue.SetValue(externalClockDivider);
+ case ISN76489DataSource::ShiftRegisterBitCount:
+ return dataValue.SetValue(shiftRegisterBitCount);
+ case ISN76489DataSource::ShiftRegisterDefaultValue:
+ return dataValue.SetValue(shiftRegisterDefaultValue);
+ case ISN76489DataSource::WhiteNoiseTappedBitMask:
+ return dataValue.SetValue(noiseWhiteTappedBitMask);
+ case ISN76489DataSource::PeriodicNoiseTappedBitMask:
+ return dataValue.SetValue(noisePeriodicTappedBitMask);
+ case ISN76489DataSource::AudioLoggingEnabled:
+ return dataValue.SetValue(wavLoggingEnabled);
+ case ISN76489DataSource::AudioLoggingPath:
+ return dataValue.SetValue(wavLoggingPath);
+ case ISN76489DataSource::Channel1AudioLoggingEnabled:
+ return dataValue.SetValue(wavLoggingChannelEnabled[0]);
+ case ISN76489DataSource::Channel2AudioLoggingEnabled:
+ return dataValue.SetValue(wavLoggingChannelEnabled[1]);
+ case ISN76489DataSource::Channel3AudioLoggingEnabled:
+ return dataValue.SetValue(wavLoggingChannelEnabled[2]);
+ case ISN76489DataSource::Channel4AudioLoggingEnabled:
+ return dataValue.SetValue(wavLoggingChannelEnabled[3]);
+ case ISN76489DataSource::Channel1AudioLoggingPath:
+ return dataValue.SetValue(wavLoggingChannelPath[0]);
+ case ISN76489DataSource::Channel2AudioLoggingPath:
+ return dataValue.SetValue(wavLoggingChannelPath[1]);
+ case ISN76489DataSource::Channel3AudioLoggingPath:
+ return dataValue.SetValue(wavLoggingChannelPath[2]);
+ case ISN76489DataSource::Channel4AudioLoggingPath:
+ return dataValue.SetValue(wavLoggingChannelPath[3]);
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------------------
+bool SN76489::WriteGenericData(unsigned int dataID, const DataContext* dataContext, IGenericAccessDataValue& dataValue)
+{
+ //##TODO## Restructure this to be a flat switch statement as per other devices
+ ApplyGenericDataValueLimitSettings(dataID, dataValue);
+ IGenericAccessDataValue::DataType dataType = dataValue.GetType();
+ if(dataType == IGenericAccessDataValue::DataType::UInt)
+ {
+ IGenericAccessDataValueUInt& dataValueAsUInt = (IGenericAccessDataValueUInt&)dataValue;
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::Channel1VolumeRegister:
+ SetVolumeRegister(0, Data(volumeRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel2VolumeRegister:
+ SetVolumeRegister(1, Data(volumeRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel3VolumeRegister:
+ SetVolumeRegister(2, Data(volumeRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel4VolumeRegister:
+ SetVolumeRegister(3, Data(volumeRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel1ToneRegister:
+ SetToneRegister(0, Data(toneRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel2ToneRegister:
+ SetToneRegister(1, Data(toneRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel3ToneRegister:
+ SetToneRegister(2, Data(toneRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel4ToneRegister:
+ SetToneRegister(3, Data(toneRegisterBitCount, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::Channel4NoisePeriod:
+ SetToneRegister(3, GetToneRegister(3, AccessTarget().AccessLatest()).SetDataSegment(0, 2, dataValueAsUInt.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::NoiseShiftRegister:
+ noiseShiftRegister = Data(GetShiftRegisterBitCount(), dataValueAsUInt.GetValue()).GetData();
+ return true;
+ case ISN76489DataSource::LatchedChannelNo:
+ latchedChannel = dataValueAsUInt.GetValue();
+ return true;
+ case ISN76489DataSource::ShiftRegisterBitCount:{
+ shiftRegisterBitCount = dataValueAsUInt.GetValue();
+ //Update the maximum allowable values for each data value that depends on the
+ //shift register bit count
+ unsigned int shiftRegisterBitCountMask = (((1 << (shiftRegisterBitCount - 1)) - 1) << 1) | 1;
+ for(std::list::const_iterator i = genericDataToUpdateOnShiftRegisterBitCountChange.begin(); i != genericDataToUpdateOnShiftRegisterBitCountChange.end(); ++i)
+ {
+ (*i)->SetUIntMaxValue(shiftRegisterBitCountMask);
+ }
+ //Limit the current values of any settings that are affected by the shift
+ //register bit count
+ shiftRegisterDefaultValue &= shiftRegisterBitCountMask;
+ noiseWhiteTappedBitMask &= shiftRegisterBitCountMask;
+ noisePeriodicTappedBitMask &= shiftRegisterBitCountMask;
+ return true;}
+ case ISN76489DataSource::ShiftRegisterDefaultValue:
+ shiftRegisterDefaultValue = dataValueAsUInt.GetValue();
+ return true;
+ case ISN76489DataSource::WhiteNoiseTappedBitMask:
+ noiseWhiteTappedBitMask = dataValueAsUInt.GetValue();
+ return true;
+ case ISN76489DataSource::PeriodicNoiseTappedBitMask:
+ noisePeriodicTappedBitMask = dataValueAsUInt.GetValue();
+ return true;
+ }
+ }
+ else if(dataType == IGenericAccessDataValue::DataType::Bool)
+ {
+ IGenericAccessDataValueBool& dataValueAsBool = (IGenericAccessDataValueBool&)dataValue;
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::Channel4NoiseType:
+ SetToneRegister(3, GetToneRegister(3, AccessTarget().AccessLatest()).SetBit(2, dataValueAsBool.GetValue()), AccessTarget().AccessLatest());
+ return true;
+ case ISN76489DataSource::VolumeRegisterLatched:
+ latchedVolume = dataValueAsBool.GetValue();
+ return true;
+ case ISN76489DataSource::AudioLoggingEnabled:
+ SetAudioLoggingEnabled(dataValueAsBool.GetValue());
+ return true;
+ case ISN76489DataSource::Channel1AudioLoggingEnabled:
+ SetChannelAudioLoggingEnabled(0, dataValueAsBool.GetValue());
+ return true;
+ case ISN76489DataSource::Channel2AudioLoggingEnabled:
+ SetChannelAudioLoggingEnabled(1, dataValueAsBool.GetValue());
+ return true;
+ case ISN76489DataSource::Channel3AudioLoggingEnabled:
+ SetChannelAudioLoggingEnabled(2, dataValueAsBool.GetValue());
+ return true;
+ case ISN76489DataSource::Channel4AudioLoggingEnabled:
+ SetChannelAudioLoggingEnabled(3, dataValueAsBool.GetValue());
+ return true;
+ }
+ }
+ else if(dataType == IGenericAccessDataValue::DataType::Double)
+ {
+ IGenericAccessDataValueDouble& dataValueAsDouble = (IGenericAccessDataValueDouble&)dataValue;
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::ExternalClockRate:
+ externalClockRate = dataValueAsDouble.GetValue();
+ return true;
+ case ISN76489DataSource::ExternalClockDivider:
+ externalClockDivider = dataValueAsDouble.GetValue();
+ return true;
+ }
+ }
+ else if(dataType == IGenericAccessDataValue::DataType::FilePath)
+ {
+ IGenericAccessDataValueFilePath& dataValueAsFilePath = (IGenericAccessDataValueFilePath&)dataValue;
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::AudioLoggingPath:
+ wavLoggingPath = dataValueAsFilePath.GetValue();
+ return true;
+ case ISN76489DataSource::Channel1AudioLoggingPath:
+ wavLoggingChannelPath[0] = dataValueAsFilePath.GetValue();
+ return true;
+ case ISN76489DataSource::Channel2AudioLoggingPath:
+ wavLoggingChannelPath[1] = dataValueAsFilePath.GetValue();
+ return true;
+ case ISN76489DataSource::Channel3AudioLoggingPath:
+ wavLoggingChannelPath[2] = dataValueAsFilePath.GetValue();
+ return true;
+ case ISN76489DataSource::Channel4AudioLoggingPath:
+ wavLoggingChannelPath[3] = dataValueAsFilePath.GetValue();
+ return true;
+ }
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------------------
+//Data locking functions
+//----------------------------------------------------------------------------------------
+bool SN76489::GetGenericDataLocked(unsigned int dataID, const DataContext* dataContext) const
+{
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::Channel1VolumeRegister:
+ return channelVolumeRegisterLocked[0];
+ case ISN76489DataSource::Channel2VolumeRegister:
+ return channelVolumeRegisterLocked[1];
+ case ISN76489DataSource::Channel3VolumeRegister:
+ return channelVolumeRegisterLocked[2];
+ case ISN76489DataSource::Channel4VolumeRegister:
+ return channelVolumeRegisterLocked[3];
+ case ISN76489DataSource::Channel1ToneRegister:
+ return channelDataRegisterLocked[0];
+ case ISN76489DataSource::Channel2ToneRegister:
+ return channelDataRegisterLocked[1];
+ case ISN76489DataSource::Channel3ToneRegister:
+ return channelDataRegisterLocked[2];
+ case ISN76489DataSource::Channel4ToneRegister:
+ return channelDataRegisterLocked[3];
+ case ISN76489DataSource::Channel4NoiseType:
+ return channelDataRegisterLocked[3] || noiseChannelTypeLocked;
+ case ISN76489DataSource::Channel4NoisePeriod:
+ return channelDataRegisterLocked[3] || noiseChannelPeriodLocked;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------------------
+bool SN76489::SetGenericDataLocked(unsigned int dataID, const DataContext* dataContext, bool state)
+{
+ switch((ISN76489DataSource)dataID)
+ {
+ case ISN76489DataSource::Channel1VolumeRegister:
+ channelVolumeRegisterLocked[0] = state;
+ return true;
+ case ISN76489DataSource::Channel2VolumeRegister:
+ channelVolumeRegisterLocked[1] = state;
+ return true;
+ case ISN76489DataSource::Channel3VolumeRegister:
+ channelVolumeRegisterLocked[2] = state;
+ return true;
+ case ISN76489DataSource::Channel4VolumeRegister:
+ channelVolumeRegisterLocked[3] = state;
+ return true;
+ case ISN76489DataSource::Channel1ToneRegister:
+ channelDataRegisterLocked[0] = state;
+ return true;
+ case ISN76489DataSource::Channel2ToneRegister:
+ channelDataRegisterLocked[1] = state;
+ return true;
+ case ISN76489DataSource::Channel3ToneRegister:
+ channelDataRegisterLocked[2] = state;
+ return true;
+ case ISN76489DataSource::Channel4ToneRegister:
+ channelDataRegisterLocked[3] = state;
+ return true;
+ case ISN76489DataSource::Channel4NoiseType:
+ noiseChannelTypeLocked = state;
+ channelDataRegisterLocked[3] = false;
+ return true;
+ case ISN76489DataSource::Channel4NoisePeriod:
+ noiseChannelPeriodLocked = state;
+ channelDataRegisterLocked[3] = false;
+ return true;
+ }
+ return false;
+}
+
+//----------------------------------------------------------------------------------------
+//Audio logging functions
+//----------------------------------------------------------------------------------------
+void SN76489::SetAudioLoggingEnabled(bool state)
+{
+ std::unique_lock lock(waveLoggingMutex);
+ if(wavLoggingEnabled != state)
+ {
+ if(state)
+ {
+ double outputFrequency = externalClockRate / externalClockDivider;
+ wavLog.SetDataFormat(1, 16, (unsigned int)outputFrequency);
+ wavLog.Open(wavLoggingPath, Stream::WAVFile::OpenMode::WriteOnly, Stream::WAVFile::CreateMode::Create);
+ }
+ else
+ {
+ wavLog.Close();
+ }
+ wavLoggingEnabled = state;
+ }
+}
+
+//----------------------------------------------------------------------------------------
+void SN76489::SetChannelAudioLoggingEnabled(unsigned int channelNo, bool state)
+{
+ std::unique_lock lock(waveLoggingMutex);
+ if(wavLoggingChannelEnabled[channelNo] != state)
+ {
+ if(state)
+ {
+ double outputFrequency = externalClockRate / externalClockDivider;
+ wavLogChannel[channelNo].SetDataFormat(1, 16, (unsigned int)outputFrequency);
+ wavLogChannel[channelNo].Open(wavLoggingChannelPath[channelNo], Stream::WAVFile::OpenMode::WriteOnly, Stream::WAVFile::CreateMode::Create);
+ }
+ else
+ {
+ wavLogChannel[channelNo].Close();
+ }
+ wavLoggingChannelEnabled[channelNo] = state;
+ }
+}
diff --git a/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.h b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.h
new file mode 100644
index 0000000000000000000000000000000000000000..5de439ec87ddc67eca99fc584234ff2b1770467b
--- /dev/null
+++ b/MiSTer-devel_NeoGeo_MiSTer/rtl/jt12/doc/nemesis/SN76489/SN76489.h
@@ -0,0 +1,190 @@
+/*--------------------------------------------------------------------------------------*\
+Description:
+This core emulates the SN76489 Programmable Sound Generator (PSG), and is designed to
+produce a sample-accurate output. Each channel is generated and mixed at the correct
+internal sample rate, and all known aspects and behaviour of this device are faithfully
+emulated.
+
+Things to do:
+-Get a final answer on the conversion from attenuation to linear power, and document it
+within your core.
+-Make it possible to define the clock and noise register settings externally
+
+Output filtering:
+-Note that there is real "decay-like" behaviour, which comes from the audio output
+circuitry in the Mega Drive. The same circuit affects the output of the YM2612 in the
+same way. If we want to emulate this behaviour, we need to emulate it using a form of
+audio filter which can be applied to any sound core, just like we need to emulate analog
+video distortion using output filters. These filters need to be separate from the device
+cores, and be modular and chainable. Note that we should also use output "filters" to
+balance output levels between sound devices.
+-Measure the final audio output levels from the embedded SN76489 in the Mega Drive, both
+directly from the chip and after the mixing circuit. According to SN76489.txt, several of
+the minimum attenuation levels may in fact be clipped, which will greatly affect the
+overall volume of the PSG, and the relative volume levels of the different register
+settings on the system.
+
+Debug output modifications:
+-Add the calculated frequency, and attenuation in db, for each channel, on the register
+debug window.
+-Display the noise register using its actual separate register values, named correctly,
+on the register debug window.
+
+References:
+-SN76489 Notes (SN76489.txt), Maxim, 2005
+-Genesis Sound Software Manual, Sega Enterprises, 1992, scans by antime
+-SN76489 Datasheet, Texas Instruments
+-SN76494 Datasheet, Texas Instruments
+-SN76489 sound chip details, John Kortink, http://web.inter.nl.net/users/J.Kortink/home/articles/sn76489/index.htm
+\*--------------------------------------------------------------------------------------*/
+#include "ISN76489.h"
+#ifndef __SN76489_H__
+#define __SN76489_H__
+#include "DeviceInterface/DeviceInterface.pkg"
+#include "TimedBuffers/TimedBuffers.pkg"
+#include
+#include