• DIY dandy game console. How it's made, how it works, how it works. Modern developments for the NES

    At first I didn’t even think of writing an article on this topic, but it looks like this is already part of a whole series of articles on Dandy topics. And yes, this time we are primarily talking about the domestic Dandy, and not about the original consoles - Famicom or NES. I just made the device as a gift to one person who makes very interesting videos about Dandy, and was focused on compatibility with this particular clone.

    The fact is that a variety of accessories were released for both the Famicom and the NES: 3D glasses, keyboards, robots, barcode readers, all sorts of game controllers and much more. Only the light pistol has reached us. I was faced with the task of assembling a device that would combine a splitter for four players (yes, there were such games) and an Arkanoid controller.

    I/O ports

    First of all, it’s worth telling how the Famicom, NES and Dendy game controllers work with joysticks, and how they differ in this regard.

    From a gaming perspective, I/O ports are two registers with addresses $4016 And $4017 , which are respectively associated with two ports, where everything is connected. But on standard controllers, only one wire is used to read data - D0, the data from which is respectively accessible through the least significant (zero) bit in each of the registers: $4016.0 And $4017.0 . Similarly, one wire per recording is used, it is usually called STROBE(or LATCH), which resets the counter inside the gamepad, and which is accessible via writing to $4016.0 (yes, it is common for both controllers).

    Simply put, to get the state of the buttons on the first controller, you must first write 1 to $4016.0 , immediately write 0 there, thus resetting the counter, and then read $4016 And $4017 eight times (for each of the buttons), obtaining data about the buttons from the least significant bit. But what are the other bits in these registers for, where do these lines go? Consider the controller port on the NES:

    Yes, they actually go for it D3 And D4! They are the ones that are available through $4016.3 , $4016.4 at the first port and $4017.3 , $4017.4 the second one, and they are the ones used for non-standard controllers.

    As for its Japanese counterpart - the Famicom, it does not have these ports, and the game controllers themselves are not detachable from the console, but it does have an expansion port, which is a DB-15 connector.

    Looks familiar, doesn't it? Yes, when the Chinese designed our Dandy (I doubt that we designed it), and they needed to make detachable controllers, they decided to use the expansion port as a basis, because it has contacts for the second controller, and it is located slightly on the Famicom to the right of center. They didn't even have to change the pinout. As for the first controller, they took the same DB-15, placed it on the left and changed the pinout so that the first controller could be connected. And only him.

    Compare the front ports of the Famicom and our Dandy:

    This is the strange history of these fifteen-pin connectors on gamepads that are used in our country.

    But let's see what is output to this expansion port on the Famicom?


    (screenshot from wiki.nesdev.com)

    Yes, they are still going for it $4016.1 (for input), $4017.0-4 (for input), $4017.0-2 (to output), external interruption and even sound! I was very pleasantly surprised when I took Dandy apart and saw that it was all there:

    True, not in all models, as it turned out later. But if it is, then it is fully compatible with Famicom accessories, and the corresponding Japanese games can use them. But let me remind you that Dandy is a very strange mixture of NES and Famicom, PAL and NTSC. Pirates released both Japanese and American games for it, which are essentially 100% compatible, if you do not take into account these accessories and different cartridge formats.

    Total: Some Dandies have all the same outputs as on the Famicom, which at the same time include some of the outputs available on the NES. No access to $4016.3 And $4016.4 , but they are used extremely rarely. In the form of a plate for clarity:

    How the accessories work

    The American four-player splitter for the NES is called Four Score is a simple set of shift registers. Those. first eight readings from $4016.0 give data from the first controller, and the second eight - from the third. Likewise $4017.0 gives data about the second and fourth controllers. In addition, when you continue reading, the device produces its own signature, with the help of which the game determines that it is connected Four Score, and not something else. It turns out that such a device can be assembled from six shift registers (4021 or 74165), and it will work on any Dandy, because it does not require additional data lines. Of course, only with American games that were released for the NES.

    The Japanese analogue for Famicom is much simpler. The third and fourth controllers are connected directly to the expansion port and are accessible via $4016.1 And $4017.1 . Accordingly, for such an adapter we already need a full-fledged expansion port from Dandy, otherwise it won’t be possible for four of us to play Japanese games.

    The Arkanoid controller, as the name suggests, is used for the Arkanoid game and consists of a rotary knob and one button. Inside, there is an analog-to-digital converter and a shift register, which also sequentially outputs the position of the knob. The only difference between the Japanese and American versions is the connection method. The Japanese version of the game reads the handle position and button state from $4016.1 And $4017.1 , and the American version is from $4016.3 And $4016.4 respectively. It turns out that for the Japanese Arkanoid you need a full-fledged expansion port, and for the American one, any dandy where a light gun works (it uses the same pins) is suitable.

    Creating your own accessory

    Although the above devices themselves have a simple circuit and are assembled from the simplest logical components, for the heart of the all-in-one device I decided to use an FPGA. Moreover, I was expressed a desire to make a simple switch switch there, and I wanted to make it possible to swap buttons A and B. At first I chose Altera EPM3064ATC100, but it soon became clear that 64 macrocells were not enough for me, and the choice fell on EPM3128ATC100, where there are already 128 macrocells.

    For that matter, I decided not to waste time on trifles at all and put some kind of screen in the device that would show the current mode and menu with settings; besides, I had one character-synthesizing “16x2” display lying around for a long time. To work with it you already need a microcontroller, and I chose ATMEGA16.

    I've always had the hardest time making a device look nice. After all, I am a programmer, not a designer, but when making a device as a gift, I wanted to make it as beautiful and convenient as possible. Moreover, this is almost the only way to somehow show others your work of art: photographs and videos are not the same, only a few can recreate such things using ready-made diagrams and 3D models, mass production is difficult to establish, but a gift is just that.

    So, the requirements for the appearance were as follows: four ports for standard DB-15 controllers from Dandy, four buttons for selecting and configuring them, a “mode” button, a “settings” button, a comfortable handle for Arkanoid and a button for it, which should be located quite comfortably and not get in the way. In addition, I wanted to make sure that the active ports were illuminated with LEDs and somehow intuitively connected with the corresponding buttons; the most logical thing to do was to arrange the connectors in a row, but these stupid DB-15s are too huge for that. In addition, the device should fit comfortably in your hands, because it is itself a game controller for Arkanoid. In the end I came up with something like this:

    Buttons in a row, ports on top of each other, handle on the side, button for Arkanoid on the back left.

    It turns out that there is quite a lot of space inside. Therefore, I decided to place the FPGA with connectors for wires and sockets on one board, and the microcontroller with a screen and buttons on another. They are connected via a simple serial interface.

    FPGA board (first version):

    Second board:

    I wrote the code for the FPGA in Verilog. For each mode it turns out to be quite simple. First of all, for many of them we need to count calls to each of the ports, i.e. pulses on the clock wire:

    Reg counter1; reg counter2; always @ (posedge strobe_in, posedge clock1_in) begin if (strobe_in) counter1<= 1; else if (counter1 < 31) counter1 <= counter1 + 1; end always @ (posedge strobe_in, posedge clock2_in) begin if (strobe_in) counter2 <= 1; else if (counter2 < 31) counter2 <= counter2 + 1; end
    (sorry, Habr doesn’t know how to highlight Verilog)

    Where strobe_in- this is a strobe (one for both ports), and clock1_in And clock2_in- this is respectively clock on each of the ports. There is logic inside the console: clock = R/W nand (address == $4016/$4017), i.e. clock is a logical zero when the console reads data at the corresponding address.

    The simulated American splitter mode for four players looks like this:
    always @ (*) begin // Strobe is connected directly - inputs to outputs assign strobe_out = strobe_in; assign strobe_out = strobe_in; assign strobe_out = strobe_in; assign strobe_out = strobe_in; // Pull the clock for each gamepad depending on the time the console reads the data clock_out<= (counter1 <= 8) ? clock1_in: 1; clock_out <= (counter2 <= 8) ? clock2_in: 1; clock_out <= (counter1 >8 && counter1<= 16) ? clock1_in: 1; clock_out <= (counter2 >8 && counter2<= 16) ? clock2_in: 1; if (counter1 <= 8) // Первый контроллер joy1_data_out <= joy_data; else if (counter1 <= 16) // Третий контроллер joy1_data_out <= joy_data; // Сигнатура else if (counter1 == 20) joy1_data_out <= 0; else joy1_data_out <= 1; // Второй контроллер if (counter2 <= 8) joy2_data_out <= joy_data; // Четвёртый контроллер else if (counter2 <= 16) joy2_data_out <= joy_data; // Сигнатура else if (counter2 == 19) joy2_data_out <= 0; else joy2_data_out <= 1; // Неиспользуемые выводы оставляем в высокоимпедансном состоянии, они подтягиваются к VCC внутри самой консоли joy1_data_out <= 1"bZ; joy2_data_out <= 4"bZZZZ; end

    In the Japanese splitter mode for four, you just need to connect the inputs to outputs directly:
    always @ (*) begin clock_out<= clock1_in; clock_out <= clock2_in; clock_out <= clock1_in; clock_out <= clock2_in; joy1_data_out <= joy_data; joy2_data_out <= joy_data; joy1_data_out <= joy_data; joy2_data_out <= joy_data; // Неиспользуемые выводы оставляем в высокоимпедансном состоянии, они подтягиваются к VCC внутри самой консоли joy2_data_out <= 3"bZZZ; end

    The most difficult thing was to make it possible to swap buttons A and B, because they are read sequentially, i.e. you need to know the value of B in advance when the console requests A, but it is issued just after A. At first I thought of somehow quickly reading data from the controller using some kind of external clock generator, but in the end I decided to just take the value from the previous reading . This gives a delay, but it is completely unnoticeable. Moreover, games usually read the state of the buttons several times in a row.

    Of course, all these modes and settings must be set somehow. For this I defined a 12-bit register control, data to which is written via a serial connection, with an additional bit for parity checking:
    reg control; reg control_parity; reg control_receiver; reg control_counter; always @ (posedge control_strobe, posedge control_clock) begin if (control_strobe) begin control_counter = 0; control_parity = 0; end else begin if (control_counter<= 11) begin control_receiver = control_data; control_parity = control_parity ^ control_data; end; if (control_counter < 12) control_counter = control_counter + 1; end end always @ (posedge strobe_in) begin if (control_counter == 12 && !control_parity) control = control_receiver; end

    Accordingly, from the microcontroller side the code (very dirty) looks like this:
    void control_send(uint16_t data) ( set_bit(CTRL_PORT, CTRL_STROBE_PIN); // Strobe _delay_us(10); unset_bit(CTRL_PORT, CTRL_STROBE_PIN); // Strobe _delay_us(10); int b; char parity = 0; for (b = 0 ;b< 11; b++) { if (data & (1<

    Otherwise, there is nothing special in the microcontroller code: working with the display on the HD44780 controller, buttons, LEDs, a simple menu and working with an analog-to-digital converter to determine the angle of rotation of the knob.

    I debugged everything, made sure it was working, and already started stuffing the components into the case...

    But before closing the lid, I decided to check it on the original Famicom, because the device will also be used with it. Unfortunately, the modes where it was necessary to count clock pulses did not work correctly. Using a logic analyzer, it turned out that interference was coming from the data line to the clock line:

    This interference, lasting only a few tens of nanoseconds, ruins everything. I decided to use my simple oscilloscope to see what was happening on Dandy’s clock line:

    And here's what Famicom has:

    It can be seen that this line is pulled towards VCC, very strongly in Dandy and very weakly in the original Famicom. I started experimenting with the body kit. It soon became clear that it was better to look at the result not with a logic analyzer, but with the console itself. I had to remember the assembler for the 6502 processor, write a simple program for testing and write it onto the cartridge:

    Everything became clearly visible on it, and at the same time it was possible to test all modes at once without changing the game. ROM can be downloaded

  • Games and game consoles,
  • Electronics for Beginners
    • Tutorial

    First of all, we read how interaction with him occurs. And it happens through recording at certain addresses, there are 8 groups of them: $8000-$9FFE(even), $8001-$9FFF(odd), $A000-$BFFE(even), $A001-$BFFF(odd), $C000-$DFFE(even), $C001-$DFFF(odd), $E000-$FFFE(even) and $E001-$FFFF(odd). An entry to any address within the group is equivalent. See the pattern? The register is selected using three address bits: A0, A13 And A14, the rest do not matter.

    Let's try to imitate the operation of a mapper using an FPGA. I write the code in Verilog. It is not highlighted here, I apologize for that.
    First, we describe our registers that store the current state:
    reg bank_select; reg prg_mode; reg chr_mode; reg r ; reg mirroring; reg ram_protect; reg irq_latch; reg irq_counter; reg a12_low_time; reg irq_reload; reg irq_reload_clear; reg irq_enabled;

    We describe the reaction to the entry at the corresponding addresses. Rising signal /ROMSEL We are talking about the fact that there was an access to the cartridge memory, i.e. by addresses $8000-$FFFF, we need to react at this very moment.
    always @ (posedge romsel) begin // But only if it was a record if (cpu_rw_in == 0) begin // Consider the state of A14, A13 and A0, update the corresponding registers case ((cpu_addr_in, cpu_addr_in)) 3"b000: begin / / $8000-$9FFE, even bank_select<= cpu_data_in; prg_mode <= cpu_data_in; chr_mode <= cpu_data_in; end 3"b001: r <= cpu_data_in; // $8001-$9FFF, odd 3"b010: mirroring <= cpu_data_in; // $A000-$BFFE, even 3"b011: ram_protect <= cpu_data_in; // $A001-$BFFF, odd 3"b100: irq_latch <= cpu_data_in; // $C000-$DFFE, even 3"b101: irq_reload <= 1; // $C001-$DFFF, odd 3"b110: irq_enabled <= 0; // $E000-$FFFE, even 3"b111: irq_enabled <= 1; // $E001-$FFFF, odd endcase end if (irq_reload_clear) irq_reload <= 0; end

    Now we will describe which bank should be selected when accessing the corresponding part of memory, depending on our registers.
    They are switched in accordance with the following table:

    Where $8000 & #$40 - this is our prg_mode, and -2 and -1 are the penultimate and last bank, respectively. This results in the following code:
    // PRG banking always @ (*) begin case ((cpu_addr_in, prg_mode)) // $8000-$9FFF 3"b000: cpu_addr_out<= r; 3"b001: cpu_addr_out <= 6"b111110; // Предпоследний банк // $A000-$BFFF 3"b010, 3"b011: cpu_addr_out <= r; // $C000-$DFFF 3"b100: cpu_addr_out <= 6"b111110; // Предпоследний банк 3"b101: cpu_addr_out <= r; // $E000-$FFFF - всегда является последним банком default: cpu_addr_out <= 6"b111111; endcase // A12 у MMC3 на выходе всегда как на входе, он идёт напрямую в память cpu_addr_out <= cpu_addr_in; end

    Now CHR. There's this diagram:

    Where $8000 & #$40 - this is chr_mode. It turns out like this:
    // CHR banking always @ (*) begin if (ppu_addr_in == chr_mode) ppu_addr_out<= {r, ppu_addr_in}; else ppu_addr_out <= r]; // Максимальный размер CHR у MMC3 - 256 килобайт, поэтому A18 всегда 0. ppu_addr_out <= 0; end

    The mirroring mode is described in just one line. Depending on it, we close the cartridge output CIRAM A10 either on A10, or on A11:
    assign ppu_ciram_a10 = mirroring ? ppu_addr_in : ppu_addr_in;

    Further more difficult. MMC3 can generate interrupts when a certain line is drawn on the screen. This is quite useful, and games often use it. Lines on the screen are counted using calls to A12 at PPU. With typical settings, the signal is A12 goes from logical 0 to logical 1 exactly once per line, not counting short-term transitions to 0. But they should not be counted, this complicates everything a little:

    // Enable interrupts only when A12 is low always @ (*) begin if (!irq_enabled) begin irq_ready = 0; irq<= 1"bZ; end else if (irq_enabled && !irq_value) irq_ready = 1; else if (irq_ready && irq_value) irq <= 1"b0; end // Сам счётчик always @ (posedge ppu_addr_in) begin if (a12_low_time == 3) // Время низкого уровня A12 должно быть не менее 3 циклов CPU begin if ((irq_reload && !irq_reload_clear) || (irq_counter == 0)) begin irq_counter = irq_latch; if (irq_reload) irq_reload_clear <= 1; end else irq_counter = irq_counter-1; if (irq_counter == 0 && irq_enabled) irq_value = 1; else irq_value = 0; end if (!irq_reload) irq_reload_clear <= 0; end // Время низкого уровня A12 должно быть не менее 3 циклов CPU always @ (posedge m2, posedge ppu_addr_in) begin if (ppu_addr_in) a12_low_time <= 0; else if (a12_low_time < 3) a12_low_time <= a12_low_time + 1; end

    Oh yes, MMC3 also supports connecting additional RAM at $6000-$7FFF! We must not forget to describe this:
    assign cpu_wr_out = cpu_rw_in || ram_protect; assign cpu_rd_out = ~cpu_rw_in; assign cpu_sram_ce = !(cpu_addr_in && cpu_addr_in && m2 && romsel && ram_protect);

    That's it, our MMC3 is ready! The full code can be viewed here.

    1.3. Schematic diagram


    This section provides detailed schematic diagrams of the processor module and remote controls, and also considers the option of constructing a cartridge with software for 8-bit DENDY game consoles.

    1.3.1. Processor module


    The DENDY game console usually has three boards:
    * central processor;
    * output connectors;
    * RF modulator and stabilizer.
    The boards are connected to each other by flexible flat (ribbon) cables. Sometimes there are options made on one or two printed circuit boards, but this does not affect the design of the set-top box.
    Initially, game consoles contained several chips of varying degrees of integration, with the main ones being the central processor and video processor chips.
    The development of microelectronics has led to the fact that game consoles now include only LSI type UM6561 or its equivalent. This chip houses the CPU, GPU, memory, and I/O registers on a single chip.
    Many Korean-made video consoles use several chips (usually two or three) instead of one UM6561. However, the operating principle of the set-top box and the signals at the output connectors do not change in this case, so these circuit options will not be considered here.

    Multi-chip option
    A schematic diagram of the first version of the DENDY game console, manufactured using several microcircuits of varying degrees of integration, is shown in Fig. 1.12.
    So, the basis of the game console is the central processor chip (IC1). The operation of the processor is synchronized by an external clock pulse generator made on transistors Q1 and Q2, the frequency of which is stabilized by quartz X1 (21.251465 MHz).
    The signals of all internal buses (addresses A0 - A15, data DO - D7 and control) of the game console are output to connector XS1, to which the cartridge is connected. Data buses (pins IC1/21-28), addresses (pins IC1/4-19) and control (pins IC1/31,34) connect the central processor (IC1) with the RAM chip (IC3) and the video processor (IC2).
    The address decoder on the 74LS139 chip (IC8) produces signals that allow other chips to communicate with the central processor. The decoder inputs receive the three most significant bits of the address bus A13 - A15 (pins IC8/2,3,13) and the M2 signal (pin IC8/14). If the processor operates with memory installed in a cartridge, then the V3 signal at pin IC8/9 is low. When data exchange occurs with the built-in RAM of the set-top box (IC3), the low level receives the AO signal at pin IC8/4. A low level signal at pin IC8/5 indicates that the central processor is using the video processor chip IC2.
    The sound processor of the game console and the I/O port address decoder circuit are also located on the same chip with the central processor.


    The output signals of the first and second audio channels are mixed and sent to output AU1 (pin IC1/1), and the signals of the remaining channels are sent to output AU2 (pin IC1/2). The complete audio signal is formed by mixing in a circuit made with resistors R8 - R12 and capacitor C7, and then fed to the output connector of the game console and to the input of the modulator that generates the RF signal.
    Three digits of the number (D0, D1 and D2) written to port 4016h are transmitted to the IC1/39-37 pins.

    Every time the processor reads from a port with address 4016h, a low-level pulse appears at the output CK1 (pin IC1/36). And if the processor reads from a port with address 4017h, a similar pulse is generated at the output of CK2 (pin IC1/35).
    The output signals of the gaming consoles and the light gun are transmitted to the data bus through two buffer registers IC6 and IC7 (type 74HC368).
    The video processor chip IC2 together with the video memory chip IC4 produces full


    video signal IC2 and IC4 are connected by address, data and control buses. The video memory chip IC4 is similar to the main RAM chip.
    Please note: in video processor IC2, the same pins (IC2/31-37) are used as both a data bus and an address bus. First, the low-order eight bits of the video memory cell address come here. When a low level signal appears at the ALE output (pin IC2/39), this data is stored in the buffer register IC5 (74LS373). Then the ALE output is set to a high voltage level, the high-order bits of the address remain at the IC2/26-30 pins, and the IC2/31-37 pins are used as a data bus.
    The video processor bus signals are also output to the XS1 cartridge connector.
    The complete video signal from the VIDEO OUT output of the video processor (pin IC2/21) is supplied through an emitter follower made on transistor Q3 to the VIDEO OUT output connector and to the modulator.
    Some models may not have a video signal amplification stage.

    Now we will briefly talk about the main differences from the basic circuit present in other models. They all relate to the connectors used and the purpose of individual pins.
    There are two main design options for the gaming system in question. The NES console is equipped with a 72-pin connector for connecting a cartridge, a 48-pin expansion connector and 7-pin connectors for connecting game consoles. The FAMICOM (DENDY) game console is fully software compatible with the NES console, but uses a 60-pin cartridge connector, a 15-pin expansion connector and 9-pin connectors for connecting game consoles.
    The layout of all connectors of the DENDY game console is shown in Fig. 1.13a-c, and NES consoles - in Fig. 1.13g-e.

    Single-chip option
    A schematic diagram of a single-chip version of the DENDY game console is shown in Fig. 1.14.
    Here, the functions of the central processor, video processor and memory are performed by one LSI of the UM6561 type. The frequency of the internal clock generator is stabilized by the XI quartz resonator (26.601712 MHz). Sometimes the clock generator circuit also contains a transistor.
    Most output signals go directly to the XS4 cartridge connector. Some of the signals are sent to the connectors for connecting game consoles XS1, XS2 and the expansion connector XS3.
    Video and audio signals are transmitted to the output connectors of the game console and to the input of the modulator, sometimes through transistor amplifiers.

    Output connectors
    The DENDY console has two or three connectors for connecting remote controls, a light gun and other peripheral devices. Connectors can be of three types: 7-, 9- and 15-pin.
    Game consoles can be connected to the 7-1 or 9-pin connector for connecting the console or to the 15-pin console expansion connector, the light gun - only to the 7- or 15-pin connector, other devices - to the 15-pin connector.
    Two 9-pin connectors and one 15-pin expansion connector are used to connect remote controls. The DENDY console cartridge uses a 60-pin connector located on the top.
    The NES game console has two 7-pin connectors and one 48-pin expansion connector for game consoles.
    To connect a cartridge, the NES console uses a 72-pin connector, which differs from the 60-pin connector by the presence of additional circuits connected to the expansion connector. This connector carries signals from the video processor and central processor buses.
    The appearance of the connectors of the DENDY game console and the purpose of individual contacts are shown in Fig. 1.13. The expansion connector (Fig. 1.136) is discussed below, since it is the most

    Convenient for connecting various additional devices.
    Pin 2 (AUDIO IN) provides an audio signal that is mixed with the output signals from the sound processor.
    Pins 4-8 (J2 DO - J2 D4) are the inputs of the corresponding bits of the second joystick port. The signal codes from these inputs can be obtained from port 4017h with the LDA $4017 command.
    The J1 D1 input (pin 13) is connected to the D1 bit of the 4016h port.
    When the central processor accesses ports with addresses 4016h and 4017h, short-term low-level pulses are generated at outputs CLK1 (pin 14) and CLK2 (pin 9). The DO -D2 bits of the word written to port 4 016h are transmitted to the OUT0 -OUT2 outputs (pins 10-12).
    The IRQ input (pin 3) receives an interrupt request signal.

    1.3.2. Cartridge


    The replaceable module of the DENDY game console - the cartridge - usually contains two ROM or RAM chips.
    One ROM chip is connected to the video processor and stores character generator information. Instead of character generator ROM, some cartridges use a static RAM chip. Another ROM chip with software is connected to the central processor. Sometimes the cartridge board contains additional RAM powered by a lithium battery, which is designed to save the game situation.
    Almost all cartridges, with the exception of the simplest ones, have a memory page controller chip that performs the function of a programmable address decoder.
    Structurally, the DENDY console cartridge is a protective plastic case measuring 105x90x20 mm with a key in the form of two bevels for proper installation. It contains a printed circuit board with a 60-pin connector and installed unpackaged microcircuits: ROM, RAM and page controller.
    A schematic diagram of a game cartridge without additional RAM with an MVS1 type page controller is shown in Fig. 1.15.
    The cartridge consists of two ROM chips (IC1 and IC2) and a memory page controller IC3. Chip IC1 (27С128) is the ROM of the video processor! with character generators written in it.
    In the address space of the video processor, individual ROM pages are placed at addresses 0000h - 1FFFh. The low-order bits of the address are supplied to the IC1 chip directly from the corresponding pins of the XS1 connector. Senior ranks


    Rice. 1.15. Schematic diagram of the DENDY game console cartridge

    addresses VA12 and VA13 are generated by the memory page controller chip IC3.
    The selection of a ROM chip occurs when there is a low level signal at the CS input (pin IC1/20), connected to line VA13 of the video processor address bus. Data is transferred from the ROM outputs to the contacts of the XS1 connector.
    Chip IC2 (KONAMI ROM 1Mbit) is a mask ROM with a program recorded in it with a capacity of 1 Mbit (128 KB). The low-order bits of the address A0 - A13 come from the corresponding contacts of the cartridge, and the high-order bits of the address A14 - A16 are generated by the memory page controller IC3. The CS signal, which enables the operation of ROM IC2, is also transmitted from IC3.
    IC3 is a programmable address decoder that generates the most significant bits of the address for ROM chips IC1 and IC2. It also produces a VA10 signal, the level of which determines the choice of screen display mode.
    In the cartridge under consideration, some of the outputs are not connected, so the capabilities of the microcircuit are not fully used.

    1.3.3. Modulator


    The DENDY game console modulator receives an image signal from the video processor chip IC2 and an audio signal from the central processor chip IC1 and generates a full RF television signal in one of the meter ranges. The modulator circuit is not standardized and is usually determined by the manufacturer. However, the operating principle and composition of the main components are always the same, so changes in the circuit should not cause difficulties during repairs.
    A schematic diagram of one of the possible options for the RF modulator is shown in Fig. 1.16.
    The RF master oscillator is made of high-frequency transistor Q2 (analogue of transistor
    KT368A). It forms the carrier frequency of one of the television channels. Typically, the operating frequency of the set-top box generator is in the range of 170-230 MHz and is determined by elements L1, C8 - C11 1, R9 - R11. The frequency is adjusted by changing the inductance of coil L1.
    The generator, implemented on transistor Q1 (analogue of transistor KT3102), forms the audio subcarrier for the full television signal. The output signal of the generator is modulated by an audio frequency signal coming through circuit R4, C1 from the AUDIO IN input (pin 4 of CN1 connector).
    Depending on the country of manufacture of the set-top box, the generator frequency is 5.5 or 6.5 MHz. Fine adjustment of the signal frequency is carried out by rotating the core of transformer T1.
    The mixer, made on diodes D1, D2 (analogue of the KD503A diode), transformer T2 and transistor Q3, generates a complete RF television signal. The mixer input receives a master oscillator signal and a low-frequency video signal from pin 3 of the CN1 connector. From the output of the mixer, the RF signal is transmitted through the matching circuit C15, L3 to the RF OUT output connector of the processor module.

    1.3.4. Game consoles


    There are about ten different types of game consoles for the DENDY game console. However, the most widely used are the standard gaming remote control included in the package, a turbo remote control with additional buttons, and a light gun.
    Below are the schematic diagrams of these devices, as well as an adapter diagram for simultaneously connecting four remote controls.

    Standard game controller
    A standard gaming console for the DENDY console consists of a movable crosspiece and four

    separate buttons. An unframed shift register microcircuit, which is an analogue of the HEF4021B microcircuit, is installed inside the remote control. If the original chip is not available, almost any 8-bit shift register can be used.
    A schematic diagram of a standard remote control is shown in Fig. 1.17.


    Rice. 1.17. Schematic diagram of a standard game console for the DENDY console
    When a button is pressed during a game, a low level signal is sent to the corresponding input of the shift register. A high level when the buttons are open is ensured by connecting the register input lines to the +5 V power bus through resistors with a resistance of 10-68 kOhm.
    The states of the inputs in register IC1 are remembered when a high-level pulse arrives at the PE input of the microcircuit. After this, on the negative edge of the signal at the CLK input (pin IC1/10), the contents of the register are shifted and the most significant bit is issued via the D0 bus
    The second game console supplied with the console may not have the START and SELECT buttons, but this does not affect the design of the console and the principle of its operation.

    Turbo remote
    The schematic diagram of the turbo remote control for the DENDY game console is shown in Fig. 1.18.
    The only difference between the turbo remote control and the standard one is the presence of an additional T6 Hz output on the shift register chip and two additional buttons TURBO A and TURBO B connected to this output.
    The internal generator of the remote control chip generates a sequence of pulses with a frequency of 6-10 Hz at the T output. Thus, pressing and holding the TURBO A button is the same as pressing and releasing the A button at an intensity of 6 times per second. The use of these buttons reduces wear and tear on the remote control keys, since buttons A and B are usually used in the game when shooting.


    Rice. 1.18. Schematic diagram of a turbo remote control for the DENDY game console

    Adapter for connecting four remote controls
    Some games allow up to four players. In this case, four game consoles are connected in parallel to the connectors of the game console via a special adapter.
    A schematic diagram of the adapter is shown in Fig. 1.19.
    As can be seen from the circuit diagram, the main task of the adapter is to ensure that information is read from consoles 1 and 3 during the arrival of the first eight sync pulses, and from consoles 2 and 4 during the next eight.
    The synchronization signal supplied via the STRB line fixes the state of the consoles in their internal registers and carries out the initial installation of the adapter circuits.
    During the first eight clock pulses, low logic level signals are generated at the Q8 outputs of counters IC1 and IC2, which ensures the arrival of clock pulses to consoles 1 and 3, as well as the transmission of information from these consoles to the inputs of the game console.
    After the eighth clock pulse sent from the game console when reading from the I/O port, a high logic level signal (log. 1) appears at the Q8 output of the corresponding microcircuit (IC1 or IC2), which leads to switching of the switch IC3 or IC4 and connection to the console connectors 2 or 4 remote controls respectively.

    Light gun
    In Fig. 1.20 shows possible options for the concept of a light gun for the DENDY game console.
    A phototransistor is used as a photosensitive element. In the cheapest set-top boxes it is sometimes replaced with a photodiode, which leads to a deterioration in the sensitivity of the device.
    The signal from the output of the photodiode through the isolation capacitor C1 is fed to an amplifier made on transistor Q1. From the collector of this transistor, the inverted signal through pin 5 along circuit D4 is transmitted to the processor module of the game console.

    If the gun is pointed at the television screen, then a pulse signal is generated at output D4 with a frequency equal to the vertical scanning period.
    The trigger of the light gun is connected to a button with normally closed contacts. If the trigger is released, the contact of connector D3 is connected to the common wire. When the trigger is pressed, the contacts open, and a high logic level signal appears at input D3, which is provided by connecting this circuit inside the game console through a 10-51 kOhm resistor to the +5 V bus.

    1.3.5. power unit


    The power supply for the DENDY game console consists of an external network adapter and an internal stabilizer.

    The task of the external network adapter is to convert the mains voltage ~220 V into a constant voltage of 9-12 V, which is transmitted to the internal stabilizer of the game console.
    The schematic diagram of the DENDY network adapter is shown in Fig. 1.21.
    When repairing the unit, remember that on the output connector the central contact is connected to the common wire.

    The unstabilized voltage from the adapter is supplied to the internal stabilizer of the game console, made on an AN7805 chip or on a transistor and located in the processor module. A constant voltage of +5 V is generated at the output of the stabilizer.
    Schematic diagrams of two options for the supply voltage stabilizer for the DENDY game console are shown in Fig. 1.22 and do not need additional description.


    Rice. 1.22. Schematic diagrams of the supply voltage stabilizer for the DENDY game console

    1.4. Typical faults


    The set-top box does not turn on
    Possible reasons: faulty network adapter or internal stabilizer; short circuit or break in power supply circuits; cartridge malfunction; processor module malfunction.
    1. Measure the output voltage of the network adapter. If it exceeds 9-12 V, replace the mains
    adapter. Practice shows that most often failures are caused by rectifier bridge diodes. If the transformer fails, any power source with an output voltage of 9-12 V and a permissible load current of 500 mA will do.
    2. Disconnect the remote control, cartridge and modulator from the processor module, and then check the game console units for short circuits. If a short circuit is detected, after eliminating it, check the stabilizer and the low-resistance resistor installed in it. When an overload occurs, one of the printed conductors in the power circuit usually breaks, so it is necessary to carefully inspect the boards and ensure the integrity of the conductors.
    3. If there is no short circuit, check the internal stabilizer of the game console. The voltage at the stabilizer output should be within 5±0.1 V; otherwise, in a stabilizer made on the AN7805 chip, you should replace the IC1 chip (analogous to KR142E-N5A) and check the capacitors C1 - C4. In a stabilizer implemented on a transistor, check transistor Q1 (possible replacement - KT815), zener diode D1 (possible replacement - KS156A) and resistor R1. Instead of a resistor, it is permissible to install a fuse that will protect the stabilizer from a short circuit.
    4. Turn on the set-top box without remote controls, modulator and cartridge. The VIDEO OUT jack must have a video signal. When this signal is applied to the low-frequency input of the TV, a chaotic image consisting of colored dots and squares will appear on the screen. The presence of an output signal indicates a malfunction in the remote control or modulator.
    5. If there is no output signal, check the crystal oscillator and transistor video signal amplification stage. The serviceability of the quartz resonator X1 and transistors Q1 - Q3 allows us to conclude that it is necessary to replace the entire processor module.

    The device is unstable
    Possible reasons: malfunction of the external network adapter or internal stabilizer; contacts of the cartridge connector are dirty.

    1. Check the output voltage of the network adapter. Often a failure occurs due to the low load capacity of the adapter supplied with the game console. The problem is solved by connecting a more powerful adapter.
    2. Check the reliability of the contact connections in the connectors of the set-top box. The cartridge connector must be inspected especially carefully. Clean contacts with alcohol.
    3. Check the internal stabilizer of the game console. It is useful to install a stabilizer chip or power transistor on a radiator with a sufficient dissipation area (about 10 cm2).
    4.Install additional capacitors in the power supply circuit, for example, with a nominal value of 100.0 µF x 16 V and 0.01 µF on each of the set-top boards and in the cartridge.

    Light gun doesn't work
    Possible reasons: a break in the connecting cable or bad contacts in the connector; malfunction of the photodiode or transistor of the light gun; faulty trigger contacts in the light gun.
    Troubleshooting algorithm:
    2. Check the transistor in the light gun and the contacts under the trigger. Make sure that the contacts are closed when the trigger is pressed, since failure, as a rule, occurs in the mechanical part of the gun.
    3. The low sensitivity of the pistol is often explained by the displacement of the focusing lens installed in the barrel. In this case, it is necessary to install the lens in place and secure it. Adjusting the lens mounting location can improve the performance of even a working light gun.
    4. The serviceability of the internal circuits of the light gun indicates the need to replace the entire processor module of the game console.

    The remote control doesn't work
    Possible reasons: break in the connecting cable or poor contact in the connector; dirty buttons; The remote control chip is faulty.
    Troubleshooting algorithm:
    1. Check the integrity of the connecting cable and the reliability of the connection in the connector. If the connector fails, replace it together with the mating part with any available 7-pin connector.
    2. Check the PE and STROBE input signals. The absence of signals indicates the need to replace the central processor.
    3. Check the output signal of the microcircuit installed in the remote control. If there is no signal, replace the remote control.

    Some remote buttons do not work

    Possible reasons: the remote control is dirty or the microcircuit is faulty.
    Troubleshooting algorithm:
    1. Wipe the remote control board and the rubber gasket with conductive pads with alcohol.
    2. If the conductive pads on the rubber gasket are faulty, restore them by gluing pieces of foil. It is more convenient to use foil from cigarette packs: it has a paper base, which provides better adhesion to rubber.
    3. If the conductive coating on the board is damaged, restore it using a cleaned mounting wire soldered to the tracks of the printed circuit board.
    4. If all contact pads are in good condition, it is necessary to replace the microcircuit installed in the remote control, or the entire remote control.

    No RF signal at the modulator output
    Possible reasons: violation of the generator settings, malfunction of the master generator or mixer.
    Troubleshooting algorithm:
    1. Make sure that the faulty element is in the RF modulator circuit by checking the presence of video audio signals at the LF output. The absence of any of these signals indicates a breakdown of the processor module.
    2. If there is no sound or image, the master oscillator is most likely malfunctioning. To check the generator, you should measure the frequency of the output signal: it should be in the range of 170-230 MHz. The absence of a signal allows us to conclude that it is necessary to replace transistor Q2. If the generator frequency goes beyond the specified limits, it is necessary to check elements LI, C8 - C11, R10, R11.
    3. After making sure that the master oscillator is in good condition, check the mixer (diodes D1, D2 and transformer T2), as well as the matching circuit L2. C13, C14.
    4. The absence of an audio signal during a normal image indicates a failure of the audio frequency sub-carrier generator. In this case, check that the frequency of the IF sound generator corresponds to the television standard (5.5 or 6.5 MHz) and, if necessary, adjust the generator by rotating the core of transformer T1. If there is no signal at the generator output, replace transistor Q1.

    How to make a game console with your own hands aslan wrote in November 8th, 2017

    In general, I had the idea to do this quite a long time ago, but only now the software for such crafts has reached a more or less decent state.
    Previously, I tried to make this from an x86 nettop, but the thing turned out to be quite cumbersome and capricious. Then I sold my nettop and bought a used Android TV Box. It’s much more compact and lighter, but I haven’t been able to get the RetroArch emulator to work correctly on Android, no matter what the build is, it’s full of bugs.

    Therefore, it was decided to build a set-top box based on Raspberry Pi 3, since there are already ready-made system images for these purposes, and the configuration flexibility is simply amazing.


    So, we will need:
    - Raspberry Pi (any one will do, I bought the most powerful one, with a reserve);
    - Power supply 5V 3A;
    - Two USB joysticks;
    - Housing (you can use anything);
    - Various connectors and fasteners (to taste);
    - Glue (to taste, I like two-component epoxy).

    I decided to use the case from a dead console, and at a flea market I found this 16-bit, Chinese copy of SEGA Genesis 3 for a couple of bucks.

    It took a lot of time, effort and isopropyl to wash off the clumsy inscriptions. But it’s better this way. Unfortunately, there are a couple of significant scratches on the case, but for now I left it as is.

    I figured out the location of the elements inside the case. As you can see, I bought a block of RCA connectors and a mother-to-father HDMI adapter, which is extremely useless in everyday life, but indispensable for my needs. It is needed to move the board away from the edge of the case. And then a parcel arrived with a set of various brass racks (at the local market they are somehow unrealistically expensive).

    I cut off the soft housing of the HDMI adapter a couple of millimeters and cut out a rectangular hole in both halves of the housing. I placed the stands under the board and filled them with epoxy, not forgetting to clean the gluing areas with fine sandpaper.

    In the same manner, I cut out round holes for the tulips and glued the stands. It was scary to cut, it’s not so easy to do it straight.

    But everything turned out almost perfect! I'm more than pleased.

    Let's move on! I cut out a piece of the breadboard and attached the power socket to it. It would be possible to output micro-usb, but this is more canonical. Of course, it will be mounted on the same racks.

    Pinned it. Great. I couldn’t figure out where to fit the large round hole next to the power supply; initially I wanted to output an analog signal there, but I decided that tulips were more versatile. Therefore, I will close it with a plastic plug.

    I prepared the board and soldered two USB sockets for joysticks.

    I secured it to the racks in the right place on the body. But, of course, the shape of the connectors does not match Segov’s, and I really didn’t like this.

    Therefore, I sawed off the jumper between the original holes, and glued a cut plastic false panel inside. The color is a little off, but it's hardly noticeable.

    I wired up the power supply, USB sockets and analog outputs. By the way, I don’t know whether this is a software feature or a hardware one, but in Raspberry Pi 3 the output detection (analog/digital) is automatic, but in the first version of the computer I had to switch manually.

    Time to make the power and reset buttons. Since the Raspberry Pi does not have standard buttons for these things, and I didn’t want to turn it off by severely cutting off the power, I decided to connect the buttons to the GPIO contacts and write scripts for shutdown and reboot into the startup. The power button must be attached to strictly defined GPIOs, so that when the button is pressed, our set-top box not only turns off, but also turns on.
    And scripts are easy to find on the Internet. An unpleasant surprise awaited me here. To turn it on/off you need a non-latching button, and the original switch in the set-top box was a simple slider. I had to make a return mechanism and coat the slider with silicone grease.

    And here comes the second surprise: which switch should I install? In the end, I simply pulled the switch with the tab out of the dead printer and bent the tab. Now when you press the slider, the foot presses the switch. Great. I soldered it onto the board and secured it to the stands.

    I pulled out the reset button from the same printer and attached it to the board. However, the button itself (on the case) rested on the power button connector, and it should be strictly at 5 and 6 GPIOs. I had to cut the connector. It was possible to solder directly, but I didn’t want to.

    The cartridge slot was covered with a mesh purchased at a flea market and spray-painted white. I had to straighten the body from the inside, but it's not difficult.
    And then joysticks in the Sega Saturn style arrived. Why them? Because they have 6 buttons and two buttons on top, that is, the functionality covers NES, SNES and Sega Mega Drive without any problems. You just need to configure the joystick when you turn it on for the first time, and then correct the configs for each emulator and distribute them into folders.

    The quality of the joysticks themselves is 3 out of 5, the assembly is excellent, but the cross-pieces are pressed indistinctly. I'm talking about Retrolink. You can find licensed Sega USB joysticks, but their prices are VERY high.

    Actually, it's ready! All that remains is to turn it on, configure the joysticks and connect Wi-Fi (you will need a keyboard), and then go through Total Commander to the shared folders of the device and drop your favorite games there.

    This is the picture when connected via RCA. The idea immediately suggests itself of making larger fonts.

    And this is how it works if you connect HDMI. Much better. But the analog outputs will come in handy for playing with friends in the countryside over a beer.

    Disclaimer: there is a slight input lag (Input Lag), I was not the only one who noticed this, and the TV has nothing to do with it. There are ways to reduce latency on the Internet, but that's another story.

    And one more unpleasant minus - when the power is connected, the set-top box turns on immediately, rather than waiting for a button to be pressed. I haven't figured out how to win yet.
    We also plan to order film inscriptions on the body using plotter cutting. Otherwise, I’m happy, and so are my friends.

    At first I didn’t even think of writing an article on this topic, but it looks like this is already part of a whole series of articles on Dandy topics. And yes, this time we are primarily talking about the domestic Dandy, and not about the original consoles - Famicom or NES. I just made the device as a gift to one person who makes very interesting videos about Dandy, and was focused on compatibility with this particular clone.

    The fact is that a variety of accessories were released for both the Famicom and the NES: 3D glasses, keyboards, robots, barcode readers, all sorts of game controllers and much more. Only the light pistol has reached us. I was faced with the task of assembling a device that would combine a splitter for four players (yes, there were such games) and an Arkanoid controller.

    I/O ports

    First of all, it’s worth telling how the Famicom, NES and Dendy game controllers work with joysticks, and how they differ in this regard.

    From a gaming perspective, I/O ports are two registers with addresses $4016 And $4017 , which are respectively associated with two ports, where everything is connected. But on standard controllers, only one wire is used to read data - D0, the data from which is respectively accessible through the least significant (zero) bit in each of the registers: $4016.0 And $4017.0 . Similarly, one wire per recording is used, it is usually called STROBE(or LATCH), which resets the counter inside the gamepad, and which is accessible via writing to $4016.0 (yes, it is common for both controllers).

    Simply put, to get the state of the buttons on the first controller, you must first write 1 to $4016.0 , immediately write 0 there, thus resetting the counter, and then read $4016 And $4017 eight times (for each of the buttons), obtaining data about the buttons from the least significant bit. But what are the other bits in these registers for, where do these lines go? Consider the controller port on the NES:

    Yes, they actually go for it D3 And D4! They are the ones that are available through $4016.3 , $4016.4 at the first port and $4017.3 , $4017.4 the second one, and they are the ones used for non-standard controllers.

    As for its Japanese counterpart - the Famicom, it does not have these ports, and the game controllers themselves are not detachable from the console, but it does have an expansion port, which is a DB-15 connector.

    Looks familiar, doesn't it? Yes, when the Chinese designed our Dandy (I doubt that we designed it), and they needed to make detachable controllers, they decided to use the expansion port as a basis, because it has contacts for the second controller, and it is located slightly on the Famicom to the right of center. They didn't even have to change the pinout. As for the first controller, they took the same DB-15, placed it on the left and changed the pinout so that the first controller could be connected. And only him.

    Compare the front ports of the Famicom and our Dandy:

    This is the strange history of these fifteen-pin connectors on gamepads that are used in our country.

    But let's see what is output to this expansion port on the Famicom?


    (screenshot from wiki.nesdev.com)

    Yes, they are still going for it $4016.1 (for input), $4017.0-4 (for input), $4017.0-2 (to output), external interruption and even sound! I was very pleasantly surprised when I took Dandy apart and saw that it was all there:

    True, not in all models, as it turned out later. But if it is, then it is fully compatible with Famicom accessories, and the corresponding Japanese games can use them. But let me remind you that Dandy is a very strange mixture of NES and Famicom, PAL and NTSC. Pirates released both Japanese and American games for it, which are essentially 100% compatible, if you do not take into account these accessories and different cartridge formats.

    Total: Some Dandies have all the same outputs as on the Famicom, which at the same time include some of the outputs available on the NES. No access to $4016.3 And $4016.4 , but they are used extremely rarely. In the form of a plate for clarity:

    How the accessories work

    The American four-player splitter for the NES is called Four Score is a simple set of shift registers. Those. first eight readings from $4016.0 give data from the first controller, and the second eight - from the third. Likewise $4017.0 gives data about the second and fourth controllers. In addition, when you continue reading, the device produces its own signature, with the help of which the game determines that it is connected Four Score, and not something else. It turns out that such a device can be assembled from six shift registers (4021 or 74165), and it will work on any Dandy, because it does not require additional data lines. Of course, only with American games that were released for the NES.

    The Japanese analogue for Famicom is much simpler. The third and fourth controllers are connected directly to the expansion port and are accessible via $4016.1 And $4017.1 . Accordingly, for such an adapter we already need a full-fledged expansion port from Dandy, otherwise it won’t be possible for four of us to play Japanese games.

    The Arkanoid controller, as the name suggests, is used for the Arkanoid game and consists of a rotary knob and one button. Inside, there is an analog-to-digital converter and a shift register, which also sequentially outputs the position of the knob. The only difference between the Japanese and American versions is the connection method. The Japanese version of the game reads the handle position and button state from $4016.1 And $4017.1 , and the American version is from $4016.3 And $4016.4 respectively. It turns out that for the Japanese Arkanoid you need a full-fledged expansion port, and for the American one, any dandy where a light gun works (it uses the same pins) is suitable.

    Creating your own accessory

    Although the above devices themselves have a simple circuit and are assembled from the simplest logical components, for the heart of the all-in-one device I decided to use an FPGA. Moreover, I was expressed a desire to make a simple switch switch there, and I wanted to make it possible to swap buttons A and B. At first I chose Altera EPM3064ATC100, but it soon became clear that 64 macrocells were not enough for me, and the choice fell on EPM3128ATC100, where there are already 128 macrocells.

    For that matter, I decided not to waste time on trifles at all and put some kind of screen in the device that would show the current mode and menu with settings; besides, I had one character-synthesizing “16x2” display lying around for a long time. To work with it you already need a microcontroller, and I chose ATMEGA16.

    I've always had the hardest time making a device look nice. After all, I am a programmer, not a designer, but when making a device as a gift, I wanted to make it as beautiful and convenient as possible. Moreover, this is almost the only way to somehow show others your work of art: photographs and videos are not the same, only a few can recreate such things using ready-made diagrams and 3D models, mass production is difficult to establish, but a gift is just that.

    So, the requirements for the appearance were as follows: four ports for standard DB-15 controllers from Dandy, four buttons for selecting and configuring them, a “mode” button, a “settings” button, a comfortable handle for Arkanoid and a button for it, which should be located quite comfortably and not get in the way. In addition, I wanted to make sure that the active ports were illuminated with LEDs and somehow intuitively connected with the corresponding buttons; the most logical thing to do was to arrange the connectors in a row, but these stupid DB-15s are too huge for that. In addition, the device should fit comfortably in your hands, because it is itself a game controller for Arkanoid. In the end I came up with something like this:

    Buttons in a row, ports on top of each other, handle on the side, button for Arkanoid on the back left.

    It turns out that there is quite a lot of space inside. Therefore, I decided to place the FPGA with connectors for wires and sockets on one board, and the microcontroller with a screen and buttons on another. They are connected via a simple serial interface.

    FPGA board (first version):

    Second board:

    I wrote the code for the FPGA in Verilog. For each mode it turns out to be quite simple. First of all, for many of them we need to count calls to each of the ports, i.e. pulses on the clock wire:

    Reg counter1; reg counter2; always @ (posedge strobe_in, posedge clock1_in) begin if (strobe_in) counter1<= 1; else if (counter1 < 31) counter1 <= counter1 + 1; end always @ (posedge strobe_in, posedge clock2_in) begin if (strobe_in) counter2 <= 1; else if (counter2 < 31) counter2 <= counter2 + 1; end
    (sorry, Habr doesn’t know how to highlight Verilog)

    Where strobe_in- this is a strobe (one for both ports), and clock1_in And clock2_in- this is respectively clock on each of the ports. There is logic inside the console: clock = R/W nand (address == $4016/$4017), i.e. clock is a logical zero when the console reads data at the corresponding address.

    The simulated American splitter mode for four players looks like this:
    always @ (*) begin // Strobe is connected directly - inputs to outputs assign strobe_out = strobe_in; assign strobe_out = strobe_in; assign strobe_out = strobe_in; assign strobe_out = strobe_in; // Pull the clock for each gamepad depending on the time the console reads the data clock_out<= (counter1 <= 8) ? clock1_in: 1; clock_out <= (counter2 <= 8) ? clock2_in: 1; clock_out <= (counter1 >8 && counter1<= 16) ? clock1_in: 1; clock_out <= (counter2 >8 && counter2<= 16) ? clock2_in: 1; if (counter1 <= 8) // Первый контроллер joy1_data_out <= joy_data; else if (counter1 <= 16) // Третий контроллер joy1_data_out <= joy_data; // Сигнатура else if (counter1 == 20) joy1_data_out <= 0; else joy1_data_out <= 1; // Второй контроллер if (counter2 <= 8) joy2_data_out <= joy_data; // Четвёртый контроллер else if (counter2 <= 16) joy2_data_out <= joy_data; // Сигнатура else if (counter2 == 19) joy2_data_out <= 0; else joy2_data_out <= 1; // Неиспользуемые выводы оставляем в высокоимпедансном состоянии, они подтягиваются к VCC внутри самой консоли joy1_data_out <= 1"bZ; joy2_data_out <= 4"bZZZZ; end

    In the Japanese splitter mode for four, you just need to connect the inputs to outputs directly:
    always @ (*) begin clock_out<= clock1_in; clock_out <= clock2_in; clock_out <= clock1_in; clock_out <= clock2_in; joy1_data_out <= joy_data; joy2_data_out <= joy_data; joy1_data_out <= joy_data; joy2_data_out <= joy_data; // Неиспользуемые выводы оставляем в высокоимпедансном состоянии, они подтягиваются к VCC внутри самой консоли joy2_data_out <= 3"bZZZ; end

    The most difficult thing was to make it possible to swap buttons A and B, because they are read sequentially, i.e. you need to know the value of B in advance when the console requests A, but it is issued just after A. At first I thought of somehow quickly reading data from the controller using some kind of external clock generator, but in the end I decided to just take the value from the previous reading . This gives a delay, but it is completely unnoticeable. Moreover, games usually read the state of the buttons several times in a row.

    Of course, all these modes and settings must be set somehow. For this I defined a 12-bit register control, data to which is written via a serial connection, with an additional bit for parity checking:
    reg control; reg control_parity; reg control_receiver; reg control_counter; always @ (posedge control_strobe, posedge control_clock) begin if (control_strobe) begin control_counter = 0; control_parity = 0; end else begin if (control_counter<= 11) begin control_receiver = control_data; control_parity = control_parity ^ control_data; end; if (control_counter < 12) control_counter = control_counter + 1; end end always @ (posedge strobe_in) begin if (control_counter == 12 && !control_parity) control = control_receiver; end

    Accordingly, from the microcontroller side the code (very dirty) looks like this:
    void control_send(uint16_t data) ( set_bit(CTRL_PORT, CTRL_STROBE_PIN); // Strobe _delay_us(10); unset_bit(CTRL_PORT, CTRL_STROBE_PIN); // Strobe _delay_us(10); int b; char parity = 0; for (b = 0 ;b< 11; b++) { if (data & (1<

    Otherwise, there is nothing special in the microcontroller code: working with the display on the HD44780 controller, buttons, LEDs, a simple menu and working with an analog-to-digital converter to determine the angle of rotation of the knob.

    I debugged everything, made sure it was working, and already started stuffing the components into the case...

    But before closing the lid, I decided to check it on the original Famicom, because the device will also be used with it. Unfortunately, the modes where it was necessary to count clock pulses did not work correctly. Using a logic analyzer, it turned out that interference was coming from the data line to the clock line:

    This interference, lasting only a few tens of nanoseconds, ruins everything. I decided to use my simple oscilloscope to see what was happening on Dandy’s clock line:

    And here's what Famicom has:

    It can be seen that this line is pulled towards VCC, very strongly in Dandy and very weakly in the original Famicom. I started experimenting with the body kit. It soon became clear that it was better to look at the result not with a logic analyzer, but with the console itself. I had to remember the assembler for the 6502 processor, write a simple program for testing and write it onto the cartridge:

    Everything became clearly visible on it, and at the same time it was possible to test all modes at once without changing the game. ROM can be downloaded