Showing posts with label Guide. Show all posts
Showing posts with label Guide. Show all posts

Friday, 16 March 2012

CRT, Upscaling and 2D Games

I'm a big fan of Super Street Fighter 2 Turbo and I play it on GGPO, so I scrutinise every aspect of my setup to achieve the best image and sound quality, and also eliminate lag or at least keep it to the bare minimum.

Just recently I decided to pick up a Sony Trinitron E530 CRT monitor to use with my Xbox so I have a complete setup to take with me to tournaments, but I also now use it at home for when I play Super Turbo on my laptop.  The CRT simply has way better colours and black levels than the laptop panel, not to mention way better motion (this is a huge thing in a reaction based game like ST) so that you can recognise individual frames rather than it being a bit blurry from motion.


The way I have my GGPO configured gives me a perfect 60fps offline, but I got a lot of complaints about lag, despite the fact that it certainly wasn't anything to do with my laptop or the internet connection.  I asked someone on shoryuken.com to share their config file and I found that while the framerate was not as good, I didn't get any complaints about lag.  I can only guess that maybe the Vsync was causing a conflict with the usual way the emulators sync when playing online.

My usual setting before getting the CRT was to use a bilinear filter at the panel's native 1920x1080 resolution and it looked really good, however the config file that I now use, uses a nearest neighbor filter which can look ugly when scaling by a non-whole number.  It was when I was using my CRT when this became apparent.  The default resolution that was set for the monitor when I plugged it in was 1024x768, so I thought, "Ok, I'll go with that".  When I put the game into fullscreen, I noticed the hatching effect on the Super and life meters wasn't consistent in size.


Left: 100%, Right 400%
The hatching pattern in the life and super bars are 1 pixel blocks
Above we have a 100% view of Super Turbo and to the right of it a 4x zoom to show the hatching pattern.  As you can see, the pattern is a grid of single red coloured pixels.  The problem with playing a game like Super Turbo at fullscreen using the basic renderer in GGPO is that it doesn't do any resampling of the image - it literally just multiplies the amount of pixels which means you get this inconsistent effect:



The observant of you will notice that the life bars in the first and second screenshots are different sizes.  The reason for this is because Super Turbo is a 4:3 aspect ratio game, but has a resolution of 384x224 which is closer to widescreen which needs to be stretched to 4:3 for the game to look correct.  This means that the first image was at it's native resolution/aspect ratio, but the second image was with the game running at 1024x768, which is a correct 4:3 aspect ratio.



If we go back to the first image, you can see that the hatching is nice and clean, and the large version is clean too since it's a simple 4x upscale.  The problem arises when you are trying to play a game like this which needs the aspect ratio correcting or that it's native resolution does not translate well to your upscaled resolution.

Since the game's resolution is neither 16:9 or 4:3, it means that in whichever situation you are in, the width and height are being scaled at different factors.  For example to take the 384x224 image from ST and display it on a 4:3 screen at 1024x768, the width is upscaled by 2.666x and the height by 3.429x.  For 1920x1080 that would be 5x for the width and 4.821x for the height, or if you were to run it at 1080p with the correct aspect ratio (1440x1080) it would mean the width gets stretched by 3.75x and height by 4.281x.


Because of how nearest neighbor works where it just increases the number of pixels by whole numbers rather than drawing any inbetween pixels, it causes a problem when being asked to upscale by a non-whole number.


The red blocks should all be the same size, but upscaling to a non-whole number causes this uneven effect since nearest neighbor only uses whole pixels
There are only 2 ways round this, and that is to either use a smarter upscaling algorithm like cubic or linear, or if you have a CRT, to set a custom resolution.


Solution: Custom Resolution
Because of how CRTs work in that they don't have a native resolution as such, it means you can send pretty much any resolution to it up to its supported maximum and it just displays it, without scaling.  If you are lucky, you may even be able to find monitors that will run arcade games at their native resolution but these are rare since a lot of PC monitors won't do this as the resolution and refresh rate is usually too low.  Some people prefer using a bit of upscaling in the emulator to avoid the scanline effect caused by low resolution games on CRT, but then again some people like scanlines and even buy additional hardware to emulate them!

This non-native resolution trait of CRT monitors is particularly useful for 2D/sprite based games which have these weird resolutions that are neither 16:9 or 4:3 since we can set the emulator to upscale the image by whole numbers to avoid the scaling artifacts caused by nearest neighbor.

For example upscaling 384x224 by 4x to 1536x896, the monitor will then display that resolution and fill the screen without additional upscaling.  Rather than being stuck at one resolution like an LCD at 1920x1080, a CRT is able to "adapt" it's resolution, and would be able to display something like 1920x768 should you wish.  It simply means the width would be the same, but it would change the vertical resolution to fill the screen.

If you were to send the upscaled 1536x896 game image to a 1080p LCD panel, it would then have to upscale it again in the monitor logic board to fill the screen (otherwise you would have big black borders where the outer pixels were not in use).  This is bad because generally any kind of LCD based upscaling creates input lag which is why you should always try to use a resolution that matches the number of pixels on your display.  In the case of a PC, it is preferable to use a non-integer upscaled resolution like 1920x1080 with a bit of ugly scaling than it would be to let the monitor handle the upscaling, which is usually not only ugly, but adds input delay.  Some consumer TVs have as much as 50ms input lag, which is around 3 frames.  That's simply unacceptable in a game where reversals must be performed with frame accuracy.

So bear in mind then, that the following guide mainly applies to CRT, but if you don't care about upscaling or incorrect aspect ratios, then these methods can also be applied to LCD.

Creating a Custom Resolution for GGPO
In order to find and create the correct custom resolution for you, you need to know:
1) The native resolution of the game
2) The maximum, native or recommended resolution for your monitor
This assumes that the game was intended for use on 4:3 screens.

In my case, the resolution of the game is 384x224 and the recommended resolution for my CRT is 1600x1200.  If we work back from the width for example, and calculate that 1600/384 is 4.166r, the resulting number you get is not a whole number so you will get the ugly scaling when using nearest neighbor.  In this intance we take the nearest whole number and multiply that by the width of the game, so 384x4=1536 which is our new upscaled width.  Doing the same for the height I get 1200/224=5.357, and if we take 5 as the scaling factor, 5x224 gives us 1120 pixels.

That gives us an integer scaled resolution of 1536x1120.  It's what I would describe as a bastard resolution as it doesn't fit any of the nice round resolutions that you usually find in your graphics driver like 1024x768, 1280x960 or 1600x1200, so we will have to deal with that later but first on to adding the resolution to GGPO.


Adding the Resolution to GGPO
1) First get to a window where you can browse your HDD (C: usually).  If you don't have an icon for "Computer" on your desktop, you can find it in the start menu.

2) Look for the GGPO config folder.  Where it is may depend on your Operating System, or where you put it but generally speaking you need to go into Program Files (x86)\GGPO\config

3) At this point make a copy/backup of ggpofba.ini as this is the settings file that we will be editing.  Once you have done that, open it by double clicking or in a text editor.

4) In the file you will notice the following chunk of text which are the custom resolutions.
// The preset resolutions appearing in the menu
VidPreset[0].nWidth 400
VidPreset[0].nHeight 300
VidPreset[1].nWidth 640
VidPreset[1].nHeight 480
VidPreset[2].nWidth 1024
VidPreset[2].nHeight 768
VidPreset[3].nWidth 1280
VidPreset[3].nHeight 960

In case you haven't figured it out already, we need to add another couple of lines to this with our own resolution which would look like this:
VidPreset[4].nWidth 1536
VidPreset[4].nHeight 1120

5) With that done, save and close ggpofba.ini and run the emulator.  Click Video>Fullscreen Resolution>Other and you should see your new resolution in there.  Select it, then press Alt and Enter to go fullscreen and try it out.

Do not worry if you get a message that the emulator couldn't set the resolution blah blah blah with a load of random numbers.  It generally means that your video driver doesn't see this as a valid resolution, which brings us on to the next part...

Adding the Custom Resolution to the Video Driver
This next part is written for adding the custom resolution to nvidia graphics cards.  If you have an ATI GPU or something else, you should google for advice.

1) On your desktop, right click and choose NVIDIA control panel, then under the Display tab select Change resolution and then Customize.  A popup with a list of standard resolutions will pop up, but we just want to click Create Custom Resolution.


2) Enter your resolution and the refresh rate (usually 60Hz).  I found keeping the timing set to auto works for me, but if you get tearing or judder you may be able to fix that with different timings.  The basic auto timings only allow you to specify an integer framerate, but most games were designed to run at 59.94Hz (the NTSC field rate) so if you can't get smooth scrolling motion, it may be worth playing around with custom timings where you can specify 59.94 fps.

It may also depend on the emulator as some may run at 60fps and others may run at 59.94fps.  In GGPO there is an option to force 60fps, and triple buffering/VSync also helps eliminate tearing but having said that, I think those last 3 settings were what was causing the apparent lag with GGPO before - so try to stick with the basic settings.
 

Once you've tested the resolution and it has passed, it is automatically saved.  You should now be able to run GGPO again at the new resolution.

Friday, 10 February 2012

How to Make Almost Any Wired Device Wireless

Running my Xbox 360 wirelessly without using the official Microsoft wireless adapter is something I've been doing for a number of years now, and it's not that difficult.  I wanted to write this guide for a long time as I believe it's such a better alternative to the grossly overpriced Xbox 360 wireless USB adapter (seriously, it's around 4x the price of the PC equivalent), and more to the point has the potential to be much faster.  Fortunately, I decided to upgrade my wireless bridge which means I'll be revisiting the setup.

Basically it involves taking a standard internet router and putting custom firmware on it that gives it additional features such as wireless bridge mode.  This is what will let your secondary router connect to your internet wireless router, wirelessly which effectively turns it into a wireless adapter or a client just like a laptop.  The clever part is that since your devices connect to it with ethernet cable, they act just like a wired device, so once the initial setup is completed, adding "wireless" devices to your network is as easy as plugging the cable in.  No messing with router passwords or anything ever again.

Top: Xbox 360 with original adapter connected to a wireless router limited to around 20mbps.
Bottom: Xbox 360 connected to a wireless router acting as a bridge, which is connected wirelessly to another router transferring at least 105mbps.




There are numerous advantages to this, which is what stood out to me more than the fact I was getting one over on Microsoft, or saving a good amount of money.  For instance, depending on the router model you go for, it can be cheaper than the Xbox 360 wireless adapter.  My old router was £35 compared to £60 for the USB adapter and since it allowed me to connect multiple devices it meant I didn't have to buy an adapter for each device.


The other big advantage with this method is that you are not bound to the speeds of internal or official wireless adapters.  My PS3 has an internal 54G wireless card which has a real world performance of about 20mbps max which is the same as the original Xbox 360 wireless USB adapter.  Even with the new Xbox 360 built in wireless or the Wireless N adapter, those are dual stream which means they top out at around 60mbps at any realistic range, but since the routers I am using are triple stream I am able to get around 120mbps from them at opposite sides of the house.  Remember that even if you decide to replace your existing router with an E4200 triple stream router, the client must support it which means having 3 antennas, and the Xbox 360 only has two.  It will still work, but it will be limited to around 60-80mbps at best, whereas a triple antenna device can transfer as fast as 230mbps at very close range

Wifi speed ratings are very misleading.  One of the most common standards we will have come across at some point is Wireless G which is rated as 54mbps, but since wireless communications are effectively half duplex in the way they work, the bandwidth available is at best half of the rated link speed or less.  In other words when they rate a device as 54mbps, that's 54mbps shared in both directions, operating in the best theoretical conditions.

Wireless G is fine for a lot of people, but is not so good for streaming high definition movies that can have bitrates peak in excess of 20mbps, or people with fast connections.  With the wireless bridge method, the wireless adapter is in effect external now, it means I can upgrade the routers as and when faster products and new specifications come out, so you are never stuck to a certain wifi speed or spec.  In fact right now, it's the Xbox 360's ethernet port that is the bottleneck in my setup.  If it had gigabit like the PS3, I would be able to download up to 120mbps in theory once Virgin carry out the upgrade in the summer.


Take a look at the above picture. In this typical situation, all devices are competing for wireless bandwidth. If someone is streaming movies from the PC to the PS3, it will take away from the total wireless bandwidth that could be otherwise used for the Xbox 360 causing slower downloads or the real possibility of lag.  The PS3 wireless is limited to around 20mbps, meaning that high bitrate movies could stutter and lag and the Xbox 360's original wireless adapter is also limited to around 20mbps (since it is also Wireless G), which means if you have a connection over 20mbps, you simply won't make the most of it.  What's worst is that if your main router is only Wireless G, then it will only have about 20mbps to share out between all the devices, so if when your brother or sister is streaming films on the PS3 from the laptop and it hits a part of the video that comes close to or exceeds 20mbps, the router will run out of bandwidth meaning there is none left for the Xbox and then your download will stall or game will lag.  You should at the very least ensure you have a high quality wireless router, even if you don't go to the trouble of setting up a second router as a wireless bridge.


Now let's revisit that situation but put a wireless bridge in there.  Straight away you eliminate a lot of potential for wireless bottlenecking, in particular with things like streaming.  Now instead of the laptop having to send the movie data through it's wireless to the router, and from the router through the PS3's wireless, the transfer now just takes place over ethernet, which in this situation is way better since the PS3 has gigabit lan, so do most laptops and the routers used in this example (Linksys E4200) have gigabit ports too.  Not only are transfers faster to the PS3, but lag in movies is eliminated and it has no impact on local users as the wireless link is now only used for internet data, and not communication between devices.  Communication between devices is now done on a switch/ethernet level, unless of course you have another laptop connected directly via wireless to the main router/modem.  Since the PS3 and PC are communicating through the switch, the Xbox 360 is free to request data from the internet using the wireless link as it likes.

One of the other cool things about this setup is that I can share my ethernet laser printer on the network, so if you imagine the laser printer is connected at the same point where the Xbox and PS3 are, and that the laptops in my house connect to the first router on the left, it means I can print wirelessly.

Port forwarding remains unchanged too, and rather than having to set port forwards on both devices, you just set them on the main router.  There is no need to set port forwards on your wireless bridge.

The only real downsides to this method are that it can be expensive if you want a good router (£130 for a Linksys E4200 for example) and that the choices of routers are limited by what are supported by custom firmwares, and at the end of the day, you still require some amount of cable (although if you are like me, all your entertainment stuff tends to be in a corner of the room).  One other limitation that was present the first time I tried this was that when your router is set up as a wireless bridge, other wireless devices cannot connect to it directly as the link is used solely for communications between the wireless routers.  Wireless clients will have to connect to the original wireless router/modem as usual. That said, I'm sure you will agree that the advantages far outweigh the disadvantages.


Flashing the Custom Firmware
For this particular project I will be using DD-WRT again.  Although stability is as much a hardware thing as it is software, my old faithful WRT-54GL has had in excess of 100 days uptime with no signs of getting bogged down with an 8% overclock.  There are two ways to attack this, either check the website to see if an existing/spare router you have is supported (in general, hardware with built in ADSL modems are not supported), or if you are looking to buy some hardware specifically to use as a wireless bridge, check the router database.  I will be using a Linksys E4200 V1 with DD-WRT.  It is currently a work in progress as the hardware isn't really that old in comparison with some of the supported routers.  Normally I would say to stick with tried and tested stable builds and hardware, but my hand has been forced a little into this because the WAN/Internet port on my E4200 was acting funny, so I bought a new one and decided to retire the old one to replace my decrepit WRT54GL.  Although the E4200 is a very good piece of hardware there are certain reasons why it is unlikely that DD-WRT will ever be able to extract the full speed out of it, but people on the forums are saying it should be good for 100mbps over wireless, which is good enough for my use.

1) 30-30-30 Reset
The very first thing you must do is a 30-30-30 reset.  This should be done before and after the firmware upgrade as this clears contents from NVRAM.  If you don't do this, remnants of information may be left in the NVRAM and cause conflicts with the new firmware.

A 30-30-30 reset is as follows.  First with the router switched on and everything else unplugged, hold the reset button in for 30 seconds.  While still holding the button in, pull the power cable out and wait another 30 seconds.  Finally while still keeping the reset button pressed in, connect the power and wait for another 30 seconds.  In all, you should have held the reset button in for 90 seconds continuously.

2) Inital Flash
The next step is an initial flash, which flashes a base version of DD-WRT onto your router, which you may then upgrade later to a version with more features.  The process for flashing can be a little different for each router and may also require different files, so it's strongly advised that you visit the DD-WRT Wiki and look for instructions relating to your specific model.  I'll be using this page for my E4200.  Download the initial flash file, then disconnect all your network connections, turn off wireless and connect the router to be flashed by ethernet cable.  The file I am using for the initial flash is:
ftp://ftp.dd-wrt.com/others/eko/V24-K26/svn16773/dd-wrt.v24-16773_NEWD-2_K2.6_mini-e4200.bin

Load up the web interface for the router you are flashing.  The exact address for these vary depending on model and manufacturer, but in general Linksys stuff can be accessed at http://192.168.1.1  Once you have logged in, find the administration tab and click to browse for and upload the firmware.


Click start and leave the web page open.  Flashing only took about 30 seconds for my router, but the DD-WRT guys say to wait for at least 5 minutes just to make sure.  When that has passed, click Continue and you should be greeted with a screen similar to this:



When prompted for a login, the default username is root and the password is admin.  These can both be changed later.

3) 30-30-30 Reset
As a matter of course, disconnect all network cables and clients then perform another 30-30-30 reset as outlined in step 1.  This will ensure that the NVRAM is cleared of any settings left by the stock Linksys firmware.

4) Upgrading to a Bigger/Newer Build
This step is optional since the initial build you just flashed should be pretty much fully functional, but you will probably want to flash one of the later builds for increased performance, stability and features.  Routers have a limited amount of flash memory, so this will dictate which build you can use.  Check the wiki to see how much flash and RAM your device has.  Recommended builds are sometimes listed in the Wiki for your device, but may not be up to date, so check this thread for recommended builds.  Pay special attention to details in the Wiki about any special requirements your device may have, such as the E4200 must have a build that uses no more than 60KB NVRAM, as denoted by -nv60k in the filename.  Do not use micro builds as they are reported to brick Wireless N devices.

The version I am upgrading to is:
ftp://dd-wrt.com/others/eko/BrainSlayer-V24-preSP2/2011/12-12-11-r18000/broadcom_K26/dd-wrt.v24-18000_NEWD-2_K2.6_big-nv60k.bin

Now that you have your device with the initial file flashed and have performed a 30-30-30 reset, you can proceed to upgrade the firmware.  Enter your router's address in your web browser to reach the interface.  If prompted for a username, it is root and password is admin, then find your way to the administration tab and then firmware upgrade from within that.  Again, making sure all other network devices are disconnected and wifi is shut off, select the firmware to be flashed and press upgrade.  Keep the browser window open all the time while the upgrade is in effect and wait for about 5 minutes.

5) 30-30-30 Reset
After 5 minutes has passed and your router has come back online, perform one last 30-30-30 reset.  You are now up and running with DD-WRT and can move on to configuration.


Configuring DD-WRT as a Wireless Bridge
Setting up DD-WRT to connect to your other wireless routers is very easy but we need to change some settings while the router is connected to only your computer as if you try to add it to the network with it's default settings it will likely cause an IP address conflict.

1) Ensuring your wireless is turned off and the only device connected to your computer is the one you just flashed, enter http://192.168.1.1 in your browser to reach the DD-WRT setup page.  At this point it will probably prompt you to enter a new username and password from the last 30-30-30 reset.  Do so and then click the setup tab.

2) Set the WAN connection type to disabled.  Next under the Network Setup header, change the local IP address to an unused one.  Since most Linksys routers default at 192.168.1.1, if we leave the DD-WRT flashed router with the same address it would cause a conflict.  You only need to change the number in the last segment of the address.  I have mine set at 192.168.1.3.  The gateway address should be that of your router that provides the internet connection.  Net mask should be left at 255.255.255.0 unless you have specific needs.  Local DNS is fine if it is left empty.  Check the option, Assign WAN port to switch.  Disable the DHCP server.  Click save settings and then apply.

Click for larger image.
Left page shows defaults and right page shows example settings for wireless bridging (your default gateway and IP settings may vary)


3) Once those settings have been saved and applied, you will have to enter the new address of the router into your browser to continue working in the GUI.  Once you are back into the setup, click the Wireless tab.  Depending on the hardware you have, you may see one or two sections.  Since I am using the 5GHz link, I disabled the 2.4GHz radio.  To set up the 5GHz radio to connect to my other router, set the wireless mode to client bridge, select your network mode from the drop down (5GHz was disabled by default) and under wireless network name (SSID), enter the name of the router you wish to connect to exactly.  Next go to the wireless security tab and enter the wireless key that you use to connect to the main router.  For Wireless N connections the encryption should be set as AES as TKIP will revert to Wireless G speeds.

Click for larger image.
Left page shows defaults and right page shows example settings for wireless settings (page may differ depending on DD-WRT version and how mant radios your device has)


4) Save and apply all settings.  It may also help if you reboot or power cycle your router.


Conclusion
It's pretty much as simple as that.  Of course I have a little experience with networking now so I am familar with most of the terms mentioned in the firmware, but as long as you know the IP address of your modem/router (which is referred to as the gateway) and you know of an open IP address to assign your router, you are good to go.

There are alternatives to this method.  You can actually buy wireless ethernet bridges from the likes of Linksys and Netgear, but in my past experience I found that they were often much lower spec than the routers and the performance just isn't that good.  All they do is flash existing hardware with their own wireless bridge firmware on it and that's pretty much all that device can do.  Flashing your own router with DD-WRT is a much better choice simply because of the amount of options and flexibility DD-WRT gives you.  For example if you ever decide to change how your network is set up or go wired instead of a wireless bridge, you can change some settings in the router and have it do something else ie working as another router or a switch, unlike off the shelf wireless bridges which tend to have such restrictive firmwares that you can't do anything else with them.

There are of course some alternatives too.  Possibly the easiest method of networking between floors without wires is with power line adapters, but I can't comment on how secure they are, much less the performance of them.  Last thing I heard was that the performance was pretty awful.  Basically they use your house wiring and transfer data over the mains.

Of course nothing beats the speed or security of Cat 6 cable and a couple of gigabit switches, but if like me you only need a means of getting internet data from one place to another this works quite well, and the local transfers are very fast over ethernet too.