Showing posts with label #mame. Show all posts
Showing posts with label #mame. Show all posts

Friday, 1 March 2024

Day Off Fixes

Today is a "Global Reset Day" so I took the opportunity to fix some things on the PacMan cabinet. First, I never hooked up the 2 pin header buttons to the 3 pin sockets - and so re-use the buttons from the original cabinet. After some research, I discovered it is as simple as "forcing" the 2 pin header into the socket leaving pin 3 disconnected. However, these buttons are cheap, and sound terrible side mounted. Then, my research on audio cables implied I should twist my speaker wires together - braid them - to reduce noise. I did this, and low and behold the hum from the HDMI connector to the speaker disappeared. I was able to remove the lo-hi pass filter and the sound is less muffled. Important to remember that the Odroid uses HDMI out, so with my last update, I need to reset sound output to the HDMI device. Also important to remember that over driving the ALSA mixer is a very bad idea (and MAME sound, like for Karate Champ, will clip out.) Good day off.

Monday, 12 February 2024

Fixing Galaxian sound on ARM 8 core

** updated ** I was wrong about adding a mutex. One of the MAME developers, in pointing out I was wrong, also pointed out what was wrong, and subsequently fixed the issue and more. See https://github.com/mamedev/mame/pull/12034 for details.
 

Sunday, 11 February 2024

4:3 MAME Project

After turning my 1Up PacMan into a MAME cabinet, I wanted to get two more cabinets because I wanted full screen experience for horizontal and square displays in addition to vertical.

I found a Marvel Super Heroes aka Marvel vs Capcom 1Up used for $200 on Facebook Marketplace.

When I went to pick it up,  I had an unexpected visitor: George.


I set it up in the living room and played a few games with the boy.


Taking it apart, I noticed the controller looked a lot like a stock USB encoder.  I wanted to reuse as much hardware as possible.  (I have another project now to revers engineer the encoder.)



The brain had an on/off switch, and a power outlet (likely for a marquee in other 1Up models).



This is what the logic board looks like (AllWinner effectvely an Android device; note the debug uart pins, the micro USB, and other cool stuff.


I wanted to reuse the power and volume buttons on this thing, so all buttons are usable.

As reverse engineering the 1Up encoder will take time, I added two DragonRise USB controller.


The joystick is a four button model. The block 4 pin terminus doesn't fit the 5 pin sawa style, so I needed to splice on a couple 2 pin terminus (22 gauge wire).


No need to solder when you can use a mini marrette. 



You can split the 3 position switch for volume into 2 x 2 pin terminus.

+------------+
| A |  B | C | SWITCH
+------------+
  |    |    |
  |   / \   |
  |  |   |  |
+-----+ +-----+
| 1| 2| | 3| 4|
+-----+ +-----+

Next step was taking apart the speaker assembly to map right and left wires and check the Ohms and Watts on the speakers (8O3W).


So the usual Kinter amplifier will do. Cut off the 4 contact stereo jack and connect to 22 guage wire from the amplifier.

I used a modified SVG of my previous J Panel to have two buttons and I moved the amplifier up.  Cut with the Epilog laser cutter at work.


Using hot glue like last time with a joint to add some strength. Used a grinder to allow the screws to hide flush.



The buttons are for coin or service (or whatever.)


Here is a video of how to attach the button to the switch.


A picture of the assembled J Panel.



Like last project, I attached the encoders with screws and spacers from poly tubing.  I pointed the USB B towards the guts to make room but this was a mistake.  The cables molding was way to big and even though I left room, the monitor back panel descended too low and I had to notch two holes for the plugs.  (Also don't forget to label left and right wires; I just use colored tape.)


I attached the video controller to a bit of wood so I could hot glue it to the back of the display.


Secured.  Again, poly tube and screws to secure to the wood.


Zippies on all the cables, I also added a shelf for the Geekom Mini I'm using as the brain for this cabinet. I still need to secure the display buttons and mini with a VESA (or bigger zippie).

So booting the Mini Air 11 (Windows GONE, Ubuntu 22.04 with XFCE4), 


Attract is fine. (I compile everything from current source.)


JSTest all buttons/switches firing okay (including power and volume). Sound working fine through the headphone jack and amplifier in stereo.

And now time to play Tekken 2 with the boy.


And after... It took about 8 hours to convert the cabinet. Total project cost about $450 (including the 1Up used $200, the Air Mini at $150, and $100 for amp, buttons, 2 encoders...)





Monday, 18 December 2023

MAME: Getting Things Working

Its frustrating when the games you love don't work.
  • Moon Cresta and Galaxian crash on ARM because of a threading glitch (possibly in discrete.cpp), with an "negative samples" exception because the threads to generate the sound go out of order
  • Tekken 1 and 2 play no sound, and the coin button doesn't work
  • Vector games look like crap (asteroid, star wars, etc.)

Multithreading Issues

When I turned off optimization, and turned on debugging, the threading issue did not manifest. Its hard to debug. I tried to ask Bard what was up with the code, and it suggested std::launder on the pointers, that only masked the issue. Then "chuckie_the_egg" on Reddit suggested something brilliant: Set the number of processors to one or two and the problem likely won't happen. And Chuckie was right. 48 hours, even with mame's debug on, and no crashing. So, in your .mame folder, create a mooncrst.ini and galaxian.ini and add numprocessors 2.

Compiling for Aarch64

Chuckie also pointed out that he compiles with -fsigned-char on as this is a key difference between ARM and Intel (gcc vs mscode). I got to thinking, maybe this, and the odd behaviors I was experiencing on games like Tekken are due to this. Decades ago I wrote a uLaw to PCM converter. I know the old Sun Microsystems machines used signed bytes to represent the signed 8 bit audio. Maybe I should care about tuning MAME for the ODroid N2L too. In the makefile: ARCHOPTS = -fsigned-char -mtune=cortex-a73.cortex-a53 -march=armv8-a Wonderful, Tekken 1 and 2 both started working with sound. (Soul Edge does not, so I need to figure out why as it does on Intel.)

Vector

This is posted in many places, but vector games at high resolutions lose points and have weak lines. To fix all vector games, created a vector.ini and put this in as it will make points and lines bigger and brighter:
beam_width_min 1.5
beam_width_max 1.5
beam_dot_size 1.5
beam_intensity_weight 1.0

Tuesday, 30 May 2023

1Up Arcade Mod: Powering the Cab

The ODROID is recommended 12V 2.5a. The LCD is recommended "same as 1Up power" that is 12V 2.0a. The amp is also 12V 3.0a. However, having multiple transformers (power adapters) just creates heat and cabling mess. Putting in an industrial rectifier is more my style, but not so simple, and I don't need different voltages. And, I learned the hard way, that the amplifier draws more than 2 amps, and the ODROIOD can't satisfy a wifi nub, remote keyboard nub, the 4 port mini hub, and the two joystick/button decoders that in turn power .5 amp worth of button LEDs. I figured I was about 2 amps short of power.


very close to what I had, and I didn't have luck with the independant powered hubs
I replaced the 3' USB A - USB B cables with 1' versions.
So, I found a 12V 10a power supply typically used in home security systems, and a 3 way splitter. I re-used the extension cable for the 1Up. Plenty of juice.


And here is the finished, powered cabinet in use.

Monday, 29 May 2023

1Up Arcade Mod: Displays, MAME and X11 Linux

ODROID

I use a 6 core 4G ODROID, with 128G EMMC and 128G SD storage, because its pretty zippy.


Getting the Right Ubuntu

You don't need nor want a lot of Operating System or Windowing overhead if you just want gaming emulation. It makes sense that you want to squeeze every cycle out of your CPU, and not waste them on over-processing. So, because the stock Ubuntu 22 runs on the 4.9 Kernel on ODROID, we have a problem: the Mali GPU driver isn't supported for OpenGL. We need 5.* or later and the Bifrost video drivers. And we want a minimal Window manager - in fact we want a server build (no X11) to start with and only install the minimum amount of XWindows to save on space (and time). And, you really want to use the GPU - not just the framebuffer and software rendering (that is ... slow).

Fortunately, to_better has these linux builds for ODROID. http://docs.linuxfactory.or.kr/ has lots of great advice and images for a server tuned Ubuntu on ODROID. You can grab ubuntu-22.04-server-odroidn2l, and use Etcher on Windows or Linux to write the image to SD CARD or EMMC.
odroid@server:~$ uname -a
Linux server 5.15.0-odroid-arm64 #1 SMP PREEMPT Ubuntu 5.15.110-202305030140~jammy (2023-05-02) aarch64 aarch64 aarch64 GNU/Linux
I wanted a fast disk, so I got the EMMC card from ODROID, but I needed to blast the new image with this cool little adapter:
Note I nerfed my boot EMMC several times, and it is possible to hack the /boot boot.scr file to swap the devno to bootstrap from the EMMC but launch from the SD card. But this is another story... and its easier just to get the EMMC adapter to flash new images / edit files.

Updating the Linux Kernel to Support Rotate

I face a challenge in that the PacMan display is portrait (so height > width). Once I attached the video card, and booted, the world was sideways. Also, the video logic board is in Chinese, so there wasn't a "hardware" configuration change I could see. The folks at HardKernel fixed the kernel to support console rotation ( see the ODROID forum ) - you'd need to install this kernel if you want to rotate the frame buffer.

A Light Weight Window Manager

Once you have your Linux, you can install a light weight Window manager to make life easier should you choose - like I do - to be more than a kiosk. xfce4 should install what you need for bare bones X11.
sudo apt install xserver-xorg-core xfce4
If you just want a kiosk, then some suggest openbox or ratpoison.
The next step is telling X11 you want to be rotated too. After starting xfce4, open your display settings, and select left under rotation. This should stay rotated, but I think there is a glitch somewhere that when screen savers or power savers kick in, the screen will rotate back. It is an issue with xfce4 / window manager as I don't have this issue when I run as a kiosk (described later.)

Building the Emulator Front End and Emulators

Getting into the details of building tools is not here - there are many pages that instruct folks how to build the tools you use. Remember to move your compiled code to a place like /usr/games after executables are compiled. Also, the config files for both MAME and Attract will be in your $HOME directory (as whatever user you work under). Don't run X11 or the these applications as root (but you likely should build them as root.)

You should make sure you turn on swap before compiling and linking MAME, as 4G may not be enough to compile fully with optimization, so I recommend creating an 8G swap.
 sudo fallocate -l 8G /swapfile
 sudo chmod 600 /swapfile
 sudo mkswap /swapfile
 sudo swapon /swapfile
 sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab


Attract

I used attract-2.6.2 aka Attract Mode as my front end because it is simple and easy to configure.

MAME

I used MAME 2.5.4 as my machine emulator. The documentation isn't great for Linux but you can get what you need to compile MAME. Note that MAME on X11 uses Simple DirectMedia Layer (SDL) for input, output, and the MESA OpenGL shim. My makefile turns on the following compile options:
NOWERROR = 1
OSD = sdl
SDLMAME_X11 = 1
OPTIMIZE = 2
TARGETOS = linux
that you can then use with a make -j6 to use all 6 cores (takes a few hours to compile full MAME.)

If you, like me, like to play and optimize code, MAME doesn't do a good job cleaning up after itself, so you will need to do this from the MAME source directory:
make clean
rm -rf `find . -name *.gch -print`
rm -rf `find . -name *.a -print`
  
to prevent "symbol not found" type errors if you fiddle with optimizations and headers.

Autostart to Kiosk, XFCE4 or Shell

There are several ways you can get linux to start an application instead of gettty terminal. I wanted to still log in, but after log in, auto run attract to be a kiosk. So, a .bash_profile is the trick to prompt what to do or timeout and just run attract!
odroid@server:~$ cat .bash_profile
read -t 10 -p "1) shell 2) xfce4 or do nothing and launch as kiosk: " v
if [[ $? -gt 128 ]] ; then
  startx ./headless.sh
else
  case "$v" in
    [1])
      ;; # dont exit as it will quit the shell
    [2])
      startxfce4;;
    *)
      echo "Huh?? I think you mean exit.";;
  esac
fi
This script does on of three things when the user logs in.
  • exit to console shell
  • start xfce4 as a Window Manager
  • just launch attract without a Window Manager under X11 if the user doesn't enter 1 or 2


The script I use to start as a kiosk:
odroid@server:~$ cat headless.sh
xrdb -merge $HOME/.Xresourcesii &
xrandr --output HDMI-1 --panning 0x0+0+0 --fb 0x0 --rotate left &
xset s off && xset -dpms &
xfconf-query -c xsettings -l &
attract
Translating into english,
  • attach fonts and whatnot I might set from the Window Manager
  • rotate the display left, resetting the pan and framebuffer, and output to HDMI-1
  • turn off screen saver and power management (I use Attract's screen saver)
  • dump out my settings and run attract

1Up Arcade Mod: Adding Video

Screwed onto the LCD is a small tin box. Inside this is the game board. (Interestingly, 1Up sands off the identifying information on the chips.) Detach the power and video cables from the 1Up board.

Installing the Video Board

Buy a video logic board to decode HDMI and sound for your ODROID. If you don't have an ODROID, and your single board has a mini stereo out, you can use that instead of the audio decoder on the video board. I got the video board below with the two EPROMS. You can discard this driver board as you don't need it (you just need the decoder and LCD driver card - the one with the HDMI or VGA inputs).
 

Note that you should try install this as low as possible on the front panel that the LCD is mounted to so the cables to the SBU and amplifier can be short. To avoid RF interference, you should not attach this video controller to the LCD. I did, because the cable was not long enough from the LCD - so I attached a wooden mount with hot glue.

I used 1/4" polyethelene tubing (125degF) as a spacer, cut to 1/4 sections, as finding spacers was (a PITA), its workable, and strong (like bone). Also, polyethelene is a very weak conductor of electricity (or restated its a good insulator).

My temperature gun tells me the video controll runs about 90 degF, so it does not need specific cooling, nor does it present a fire risk to the 1/2" wood mounting board..

Plugging It In

A decent short (18") HDMI cable can run from the video board to the SBC.




Attach the Audio

I don't like clutter and the longer the analog audio cable the more chance for noise, so I used an 18" stereo mini to RCA cable to connect to the amplifier. Plug this into the video logic board.

Thursday, 4 May 2023

1Up Arcade Mod: Adding Speakers and Amplifier

The 1Up has a slat directly under the joystick panel on an angle. It is about 1/4" thick and its coated with some laminate and 460mm W by 180mm H. I measured out the speakers (80mm D), amplifier (100mm W 40mm H) and the old buttons from the PacMan (1" D about 28mm D). (Inspect the page if you want this template for your laser cutter. You will see a scale factor for mm to pt and the measurements are in mm. It's hand coded SVG.)
I went to the maker room at work and cut the board. The laser had issue with the laminate, so we had to run it 3 times.

I like recycling, so I had an old Insignia NS-PCS40 pair of desktop speakers. I didn't find the speaker specifications, aside from it using a power adapter that output 12V and 700mA load. When we ripped the speakers appart (doh, screws behind the fabric), I found they were 4 Ohm 40 W. The amplifier I bought, the Kinter MA 170, would have no problem powering those...





So if you want an inexpensive set of speakers, you can try these


I debated using hot glue or expoxy. At least with hot glue, a heat gun can help fix a mistake. But expoxy is permanent, so I used hot glue.


The issue with the hot glue is it is not compressible. So I ended up with 1-2mm of gap between the speaker mount and the faceplate board. Here is the result

However, the final product was almost perfect. I just needed to use my dremmel to make notches for the arcade buttons. My plan for them is to connect them to the GPIO on the Odroid and use them for restart or shutdown. Almost - means that in hind sight I should lower the buttons by 3/4" because I miscalculated the USB hub position and height for when USB cables are plugged in! I was lucky in that I could position the cables around the button and still use the wiress network and keyboard adapters.

I added 1/2" angle brackets under the amplifier with hot glue to give it more stability. Again, hindsight tells me I should have raised the amplifier box by 1/4".