Search This Blog

Friday, September 6, 2013

The Borg Collective

Dear reader. Please understand that I am only writing this blog to make people more aware of the technical nature of the topic and spur some meaningful discussion. My statements here deal with operating system intrinsic and design. If you do not possess the core knowledge and fundamentals about the working and design of operating systems, you may still continue to read and ask questions. Meaningless, stupid, unintelligent comments/sarcasms/statements will be ignored. Moreover, you will be insulting yourself with such actions. I do not accept responsibility for any effects, adverse or otherwise, that this blog may have on you, your devices, your sanity, your dog, and anything else that you can think of. Read it at your own risk. Now with that off my chest, let's begin…

There are times when I fling out my Windows Phone 8 device out of my pocket, few of my friends and colleagues go… why? Why Windows Phone 8? Why not Android? To all of them, my standard response is that I do not want to become a part of the "Borg Collective". Well, that is the short answer. Here goes the long one…

Please understand that as a company, Google creates excellent services like Google Search, Mail, YouTube, Maps etc. However, in my opinion, Android and Chrome OS are not one of them. They are just a bloody mess with sugar coating on top. I am not against the open source community either. I love and use Ubuntu. I even test Haiku OS and ReactOS on my machines. My primary machine runs Windows 8. Let's face it. 91.56% of our computer using population runs Windows on their machines and I am no different. I am not a Microsoft fan boy either. I do understand where they came from and what they are doing. However, simply dismissing their product on their previous reputation and not being open source is stupidity. Open Source operating system has been with us for a long time now and they have really done wonders in the enterprise world. However, in the consumer world, Windows became a hit for a reason. It makes your system more usable and allows a variety of standard ways for a developer to leverage the hardware for his or her applications. Yes, there are plenty of ways to screw up Windows. You could install anything from the internet that flashes and is free. And for people who do that, we have something called as "Tech Support". Microsoft is trying to change all that with Windows Store apps like Apple with its App Store and Google with Google Play.

First of all, the "Windows" the general public knows is actually just one part of the modern Windows NT operating system. They usually mean the Win32 subsystem, a layer that sits upon the NT kernel, providing the user and application interface. NT is still around, known as XP, Vista, 7 and 8. Most people think of "NT" as "WinNT 4", while in reality the term NT refers to the NT series, which ranges from version 3 over NT5 (2000, XP, 2003) to NT6 (Vista, 2008, 7, 8). The NT architecture was designed by a team lead by David Cutler, a former lead developer of VMS. It took them more than 4 years to combine the best of UNIX, VMS and OS/2 and create the NT architecture.

The ReactOS team has been around for ages trying to clone the Windows NT architecture. However, reverse engineering anything for which you do not have the source code is hard and time consuming. Still, ReactOS is in beta; 0.3.15 as of this date and is fairly useable most of the time. I for one what to see this project succeed so that the world gets an open source replacement for Windows. The ReactOS project re-implements a state-of-the-art and open NT-like operating system based on the NT architecture. It comes with a WIN32 subsystem, NT driver compatibility and a handful of useful applications and tools. ReactOS combines the power and strengths of the NT kernel - which is well known for its extensibility, portability, reliability, robustness, performance and compatibility - with Win32 compatibility.

Mac OS X, Linux, BSD and other UNIX derivate share a common heritage based on a more than three decades old design of a simple basic operating system, which has evolved over time into a complex structure. Modern incarnations like Mac OS X put a fancy graphical user interface on top of UNIX/Linux, to hide system details, but focus mainly on beginners, and many advanced users are left out in the rain, as most advanced features cannot be accessed from the graphical user interface. Almost all UNIX flavors retain some of the original design flaws and binary compatibility between various versions is usually non-existent. In theory there are a few UNIX standards like POSIX but in practice the standards are old and cover only the basic operating system and the terminal environment. Other standards such as the Linux Standard Base are often not implemented faithfully. As there is no user interface standard or a standard API, most people still have to use command line applications or fight through the GUI mess. Many UNIX derivate uses the de-facto standard X-Window system for graphical output, which might well possess one of the worst designs in software history. Still, modern UNIX derivate are trying to catch up with recent innovations and some of them already possess important features like access control list support.

What about Android?

Android is a Linux-based operating system designed primarily for touchscreen mobile devices such as smartphones and tablet computers. Google uses a modified Linux kernel for Android. In the recent past Google has not played fair with the open source community. Read
this and this. However, Google has since learnt that you must give back from where you once took.

Apart from the Linux kernel and few libraries and tools, there is nothing that is same with Android and other Linux distributions. Almost all Linux distributions uses X as the software system and network protocol that provides a basis for graphical user interfaces (GUIs). Android does not do that like iOS and MacOS X. This, by the way, completely thrills me. Both Apple and Google realize that X can be a real bitch to deal with. Ubuntu has already announced that they will move away from X gradually and most probably embrace the Wayland display server.

Google (Android Inc.) did all the right things when it came to taking the best of all open source technologies and putting it together. But, the choices that it made while deciding the application runtime layer is what ticks me off. Dalvik VM and Java! Java bytecode running in the Dalvik VM. Are you FKM? Now, I understand why Google did it. Even if Android where to be re-compiled for a different architecture, your apps would still run because the Dalvik VM will take care of the translation. And if you wrote a pure Java app, Android will take care of the Java bindings automatically. This is a big plus. But what about performance? Simply put, it sucks! Yes, I already hear people screaming that Dalvik has JIT and you can do JNI. More on that later. Dalvik is a register-based VM. The relative merits of stack machines versus register-based approaches are a subject of ongoing debate. Read
this. As of Android 2.2, Dalvik has a just-in-time compiler. However, tests performed on ARM devices by Oracle (owner of the Java technology) in 2010 with standard non-graphical Java benchmarks on both Android 2.2 (the initial release to include a just-in-time compiler) and Java SE embedded (both based on Java SE 6) seemed to show that Android 2.2 was 2 to 3 times slower than Java SE embedded. Java SE is a stack-based VM. Read this. In my opinion, Google should have never used Dalvik and the Java language from the start and thus could have avoided the litigation they have with Oracle.

What about JNI? WTF? People use native code for better performance or reusing existing code. And that is exactly my point. Why should I have to use C/C++ and Java for my project? That to me is just creating Frankenstein. Moreover, running native code is complicated by Android's use of a non-standard C library (libc, known as Bionic). And unlike the Java application development based on the Eclipse IDE, the NDK is based on command-line tools and requires invoking them manually to build, deploy and debug the apps. Yes. I know there are 3rd party solutions. But why 3rd party in the first place? If Google had made the Android runtime in native code, we could have all used a GCC based SDK (which does a brilliant job at generating optimized native code). Microsoft solved this problem for WinRT apps by allowing Visual Studio to generate different binaries for different platforms at the same time from the same source code. Google should have done the same. I think Java programmers are sloppy. No offence (if you are a Java programmer), but the language and the runtime will convert you to one. Imagine, allocating a big chunk of memory and not releasing it. A C/C++ programmer will shudder at that thought. The Java guy will just say - "The GC will take care of it!" What? Imagine playing a first-person multiplayer shooter game written in Java. Just when you are about to frag that guy for a win, the GC kicks in! Damn! This is exactly the reason why all big budget games are written in C/C++ by real programmers. Then again, Java programmer can be found at the drop of a hat. There are too many of them. The fact is Java programmers have no programming discipline. They are like drivers who have to be constantly monitored by a police (VM). A C/C++ programmer on the other hand knows what to do when he sees the traffic lights… he follows the rules! There are many things that you can do in Java and get away with it. I guess that is why you can ship your software faster. No wonder it is called RAD. But RAD is not a solution for everything. Windows Phone is not perfect either. I hated Microsoft when they said that all apps on Windows Phone 7 had to be written with Silverlight and .Net. That meant I had to use a managed runtime. However, at least on the Windows Phone 7 the CLR (read .Net VM) is a mature and optimized one. Then Windows Phone 8 came along and Microsoft did the right thing. They allowed apps to made using native code only and easily harness the power of DirectX. Something that most Windows programmers are aware of. Microsoft still retained the ability to run Windows Phone 7 apps on Windows Phone 8. Getting the hint Google? Heck even Apple knows this! All iOS apps are native code. No wonder all Apple devices feel so fast and fluid. The same can be said about Windows Phone. On two similar spec devices power by the Qualcomm Snapdragon S4, Windows Phone feels faster and works better.

There are people who say all devices in the world will start using Android. Seriously man? What are you smoking? If you say only tablets and smartphones, I might just believe you. But do you use a tablet or smartphone to finish that report for your boss? Can you run an office with Android laptops and desktop? I dare you. I recently had a chance to use an Android 4.2 based TV stick from Rikomagic. The setup experience was absolutely horrible to say the least. I had to go through multiple huddles to get my external hard drive working. Android does not make use of the external keyboard properly. For instance, there are almost zero keyboard shortcuts and tab key does not move the focus on the screen. There are almost no configurations options for an external mouse. My Microsoft LifeCam does not work at all. All these things worked beautifully right out of the box on an Ubuntu system. I am now considering putting Ubuntu on the device and using XBMC as a Media Center. As of now Android is only good on a smartphone or tablet and I am pretty sure that is where it is going to remain for the next 20 years unless Google starts doing things right. There are people who call Android a mature operating system. Mature? The only thing mature about it is the Linux kernel. Google, you still have lots of homework to do.

The next mistake Google did when it released the Android OS was to invite everyone to the party! I am taking about Google Play. Any Tom, Dick or Harry can be an Android developer and submit apps to Google Play. There are tons on apps on Google Play but more than half of it is junk. Even worse, some are malware. If you are using an Apple or Microsoft device (running Windows Phone/RT), you can be rest assured that you will not get any malware. Almost no anti-malware program exists for Apple and Windows Phone/RT devices. Now, can we say the same for an Android device? Only recently Google has started to be stricter about what a Google Play app can or cannot do. They should have done this from the beginning. And giving people access to install apps from "Unknown sources" is a bad idea Google! People say Android has many free apps. Oh yes. It does. But when you install and run those, half of the screen is filled with ads. Many times these are in-your-face types! This is exactly what you are good at Google. We all love your search engine, YouTube and Maps!

No two Android devices will work and feel the same. Take HTC and Samsung Android devices for instance. You are using an HTC phone and decide to buy a Samsung. If you have not used a Samsung phone before then get ready to spend your quality time with your phone for some time. On the other hand a Windows Phone user feels right at home even when the hardware manufacture changes. The worst part is that Google allows the hardware vendors to change/modify many parts of the Android UI which effectively kills the real Android experience. Most hardware vendor seldom updates these customized parts of the OS. You are at the mercy of the hardware vendor to get the next version of Android on your device. On Windows Phones, all OS updates are pushed directly by Microsoft.
 

Update:
 
I really like now the Ubuntu Phone/Tablet (Convergence) platform is shaping up. I was taken aback when Canonical announced that they were switching from Wayland to Mir. However, it is not X. Thank god! I really hoped that Wayland be the way to go for all Linux distributions. What is really interesting about the platform that it allows you to write native apps including HTML5 + JavaScript apps. This is what Google should have done with Android to start with. The ability to use full OpenGL on this platform also sounds yummy!

Enough rants for today. I might update the blog with additional stuff as and when they cross my mind. In the meantime, you may put your comments below.

Sunday, February 10, 2013

Digital Distribution Platforms I like and use

I have been using Windows 8 for quite some time now and have noticed myself using 3 popular Digital Distribution Platforms for purchasing and downloading games on my computers. These are:

1. Steam

Steam

2. Desura

Desura

3. Windows Store & GFWM/Xbox.com

Screenshot (11)

Sunday, April 3, 2011

Permanently overclocked my NVIDIA GeForce 8600M GT (Dell Inspiron 1520)

I seem to be on a Video BIOS flashing spree. First my Radeon HD4670, and now my GeForce 8600M GT. Well, I thought of breathing new life to my ageing Dell Inspiron 1520 and here is what I accomplished...

I downloaded an overclocked version of the NVIDIA GeForce 8600M GT BIOS from techPowerUp. After a few hours of research I came to a conclusion that 490 MHz core clock and 490 MHz memory clock should be stable on this system. For some strange reason Dell used DDR2 memory for the video cards on the Inspiron 1520 which severely bottlenecks the performance. Overclocking the memory and the GPU can do wonders. I downloaded the Windows version of the NVFlash tool from techPowerUp and flashed the OCed video BIOS.

Wednesday, March 30, 2011

Permanently overclocked my Sapphire ATI Radeon HD4670

Permanently overclocked my Sapphire ATI Radeon HD4670! How? Ripped the video BIOS using GPU-Z. Downloaded a factory OCed BIOS for a Sapphire HD4670 (Core Clock 775 MHz, RAM Clock 1000 MHz) from techPowerUp. Opened both BIOSes using RBE (Radeon BIOS Editor) and copied over the original BIOS identifier to the downloaded one. Adjusted fan speed setting in the new BIOS to linearly scale with the temperature. 0 C : 0% speed - 100 C : 100% speed. Save the new BIOS and flashed it using ATIFlash. Restarted system. Result: Old GPU Core Clock = 750 MHz, New GPU Core Clock = 775 MHz. No overclocking software required. Damn thing overclocked in hardware! Did not stop there though. Enabled AMD OverDrive in CCC and set the damn thing to auto-tune. Turns out the card is stable at CC of 790 MHz and RC of 1130 MHz. Finally called it a day!

Monday, February 7, 2011

Using Threads in Visual Basic

Threads in Visual Basic are not commonly used because of complexity. In a 32 bit Windows environment (talking about Windows 95/98/NT) it has become a necessity to use more than one thread for each process. But is it true that creating threads in Visual Basic is tough? Not really! Visual Basic has its own feature of simplifying Windows 32 bit API calls. Think about a long backup procedure, which needs to be intervened in case the user wants to suspend or stop the backup procedure. If you have not implemented a separate thread for this copy purpose, you will not be able to stop the process until and unless you kill the process forcefully or you restart your machine (Windows 95 non-OEM versions might show endless blue screens). This is not a good idea for a professional grade application. Therefore let us talk about creating threads.
We will look at creating free threading model (and not apartment model of threading) in Visual Basic using the 'CreateThread' Win32 API call. Those who are familiar with creating Win32 applications using Visual C++, will be able to recognize this little function which helps in creating a new thread within a process very easily. In Visual Basic, it is also pretty easy to create a thread. I will take a look at the example code ExCopy (which is supplied with this article). This code is used to break a long file into several small 3¼-inch high-density floppy disks (similar to what you see in WinZip utility). An independent thread handles the copy process. Therefore you can see that during the copy process, you can easily move the ExCopy window.

How the thread is created:
Let us have a look at the following function written in the example code…

'StartCopy
'Thread creation helper function
Public Function StartCopy(clsObject As clsExCopy)
    Dim NewThreadID As Long
    Dim Threadhandle As Long
    Dim Param As Long

    ' Free threaded approach
    Param = ObjPtr(clsObject)

    'Create a thread with no security attribute but
    'with default stack size and default creation flag
    Threadhandle = CreateThread(0,_
        0, _
        AddressOf ThreadFunction, _
        Param, _
        0, _
        NewThreadID)

    If Threadhandle = 0 Then
        ' Return with zero (error)
        Debug.Print "Unable to create the free thread"
        Exit Function
    End If

    ' We don't need the thread handle
    CloseHandle Threadhandle

    'Return the created ID
    StartCopy = NewThreadID
End Function

This public function is used to create the thread. StartCopy takes only one parameter of clsExCopy type. The class clsExCopy is defined in the ExCopyFile_IO.cls module. This class is used to copy data to the disks. You should call the StartCopy function with a valid clsExCopy class object. For example you might want to call this function when the user clicks on 'Start' button…

Private Sub StartBtn_Click()
    'Create a new Thread object
    If ExCopyObj Is Nothing Then
        Set ExCopyObj = New clsExCopy
    Else
        Set ExCopyObj = Nothing
        Set ExCopyObj = New clsExCopy
    End If

    ExCopyObj.bStopNow = False

    'Create a new thread
    StartCopy ExCopyObj

    'Can not click on Start now
    StartBtn.Enabled = False
End Sub

Therefore you are passing an object value to the StartCopy function. In this function the Win32 API CreateThread function is used to create a new thread.
Now take a closer look at the call to this function.
The first parameter is actually a pointer to the SECURITY_ATTRIBUTE structure. We are passing zero to avoid any security feature.
The second parameter is used to represent the stack size of the newly created thread. We are passing zero to let Windows Kernel determine the stack value.
The CreateThread function uses the third parameter as a function pointer, which it calls when the thread is created. The third parameter uses the 'AddressOf' unary operator which returns the pointer to a function (acceptable by the API). Therefore AddressOf ThreadFunction will return the actual pointer to the function 'ThreadFunction' which does the Win32 API very well accept.
The fourth parameter is used as a pointer to the arguments passed to the function mentioned in third parameter. Visual Basic has a function ObjPtr which returns the pointer to memory object which I have used to pass as a parameter to the function ThreadFunction.
The fifth parameter is used to specify how you want the thread to behave. For example you may set the thread priority of a particular thread to a higher value by specifying THREAD_PRIORITY_ABOVE_NORMAL to this parameter. This is a bit field where several options can be OR-ed.
The CreateThread function returns the thread identification value in the sixth and the final parameter.
The StartCopy function returns the handle of the thread which you can destroy using the CloseHandle Win32 API call after the thread is successfully created. Destroying this handle does not destroy the thread. This merely frees the handle associated with that thread.
The CreateThread function returns immediately after it creates the thread. The newly created thread runs as an independent thread.
As you have noticed that we have passed a pointer the function ThreadFunction to the third parameter of CreateThread function, let us see what it looks like…

'ThreadFunction
'The thread entry point
Public Function ThreadFunction(ByVal Param As IUnknown) As Long
    Dim clsObject As clsExCopy
    ' Free threaded approach
    Set clsObject = Param
    clsObject.ExCopy
End Function

Pretty small, isn't it? ThreadFunction is used to call a method (ExCopy in this case) from the clsExCopy class. This function accepts parameters as IUnknown which represents the basic interface supported by Visual Basic COM layer. The value from this parameter is copied to a clsExCopy class object. Remember that once you go out of this function, the thread is destroyed.
This is all about creating multiple threads in Visual Basic. Remember to create the project as 'ActiveX EXE'. The rest of the example code deals with form controls and the copy technique (in clsExCopy). This way of creating a thread is called 'Free Threading', which is not supported by Visual Basic COM/DCOM layer. Visual Basic COM/DCOM uses either 'Single Threading' model or 'Apartment model' threading. But free threading models are very fast compared to Apartment model threading which uses marshalling technique to transport data between two objects. Anyway we will discuss about this approach later.

Article by:
Samit Ray
Consultant
Price Waterhouse Associates (P) Ltd.
Samit_Ray@india.notes.pw.com SamitRay@cal.vsnl.net.in

BSP Trees

This article explains how BSP (binary space partitioning) trees can be used in
a game such as DOOM as part of the rendering pipeline to perform back-face
culling, partial Z-ordering and hidden surface removal.
To explain the use of BSP trees, it is best to start with an example. Consider
a very simple DOOM level.
     A---------------------------------a----------------------------------B
  |  |                                                                    |  |
  |  |                                            y                       |  |
  d1 |                                                                    |  b1
  |  |                               f'                                   |  |
  |  |                                                                    |  |
     |          C--------------------f-----------------------D            |
  |  |          |                                            |            |  |
  |  |          |                    f"                      |            |  |
  |  d          |                                            |            b  |
  |  |          |                                            |            |  |
  |  |       e" e  e'                                     g' g  g"        |  |
  d2 |          |                                            |            |  b2
  |  |          |                                            |            |  |
  |  |          |                                            |            |  |
  |  |          E                                            F            |  |
  |  |                              x                                     |  |
  |  |                                                                    |  |
     G---------------------------------c----------------------------------H
      ----c1---- ----------------------c2-------------------- -----c3-----
The level consists of a room within a room. The player cannot go outside of the
area within the square ABHG.
First some definitions (sorry :-)
The _vertices_ are marked A-H, the _faces_ are marked a-g.
We define a _line_ by using an ordered pair of vertices, so that
      a = (A,B)  e = (E,C)  f = (C,D)  g = (F,D)
We say a point is to the _left_ of a line if it is to the left of the vector
between its two vertices, taken in order.
So, in the above example, nothing is to the left of line a; everything is to
the right of it. Note that this depends upon our definition of line a, and if
we had defined a = (B,A) then everything would be to the left of line a.
A _face_ is a side of a line which is visible to the player. Wall e above, for
example, has two faces (marked e' and e"). Not all walls have two faces - if
the player can never see one side of a wall it only has one.
A face is fully defined by an ordered pair of vertices and an ordered pair of
faces - a left face and a right face.
The BSP tree for the example above might look like this:
                     f
                    / \
                   /   \
                  /     \
           a,d1,b1       e
                        / \
                       /   \
                      /     \
                 d2,c1       g
                            / \
                           /   \
                          /     \
                        c2       c3,b2
Each node contains a line. Everything to the left of that line is in the left
subtree, and everything to the right of that line is in the right subtree.
Note that face d is neither completely to the right of nor to the left of face
f. To accommodate this, we split it up into two halves, and put one half into
the left subtree and one half into the right subtree. Thus, we have to generate
new faces in order to build the BSP tree.
I will explain how the BSP tree is created later. Firstly, I will give the
algorithm used to render a picture using the tree.
Suppose the player is standing at position 'x', and looking North.
We start at the top of the tree at line f. We are standing to the right of line
f, so we go down the LEFT of the tree. This is because we want the furthest
polygons first.
We come to the left-hand-most terminating node. We write down the faces here
in our notepad. "a,d1,b1".
Since we've come to a terminator, we back up a level. Back to the top, but we
have to go down the right subtree yet. Firstly, though, we look at face f - the
deciding face for this node. We've got everything behind it in our list, we've
yet to look at anything in front of it, but we must put it into our list.
Note that face f has two sides - f' and f". Since we already know we're on the
right of line f, we know that we can only see its right side - so we write
f" in our notepad. It now says a,d1,b1,f".
Note, though, that if we were looking south (i.e. our line-of-sight vector
points away from face f) then we could not see either face f or anything on
the other side of face f - in this case, we just don't bother going any further
down the tree.
Now we go down the subtree and come to node e. We are on the right of e, so we
go down the left subtree and get a terminal node - we just write d2,c1 in our
notepad.
Back up, decide on which side of e to put in. We decide e'. The notepad now
says a,d1,b1,f",d2,c1,e'.
Down the right subtree to node g. We're on the left, so down the right subtree
to c3,b2, up, check g (we're on the left = g'), back down to the final node,
get c2, up, up, up, and we're done.
The notepad ends up saying:
a d1 b1 f" d2 c1 e' c3 b2 g' c2
If we draw these walls, in this order, then we will get the correct scene. I
would recommend using a one-dimensional Z-buffer to get finer granularity than
the painter's algorithm provides, before plotting the walls. Note also that
some walls are behind you - however, since you need to calculate their z
coordinates for the perspective transform, you can merely discard faces with
negative z values.
Creating the BSP tree
---------------------
The BSP tree almost creates itself. The only difficulty is knowing when to stop
recursing. Notice that the terminal nodes are just put into the list - so a
sufficient condition for a group of faces to form a terminal node is that they
can be drawn in a set order without any mistakes occurring in the drawing. That
is, if wherever the player can stand, the group of walls will never obscure
each other.
So let us begin: Choose face f (the choice is fairly arbitrary - it is best
to choose faces which don't split many other faces up. However, in this case
it is unavoidable). Split up faces d and b, because they straddle the line f.
(The line you are splitting along is known as the _nodeline_ in DOOM-speak).
Then put everything to the left of f in the left subtree, and vice-versa:
                            f
                           / \
                          /   \
                         /     \
                  a,d1,b1       b2,c,d2,e,g
We can terminate the left node - because walls a,d1 and b1 form a convex
shape, they can never overlap each other from any point of view. However, on
the other side, face e can obscure face d2 from certain viewpoints (our example
viewpoint above, for one) so we divide along side e. This causes side c to be
split, but side a is not split because it's not in our current list of sides.
The next level is:
                            f
                           / \
                          /   \
                         /     \
                  a,d1,b1       e
                               / \
                              /   \
                             /     \
                        d2,c1       b2,c2,g
Now, c1 and d2 never overlap, so we have another terminal node. We next divide
along line g, splitting c2 into c2 and c3, and the last nodes are terminals
(a node with one face in is always terminal :-).
This is the basic idea behind a BSP tree - to give an example how effective it
is, consider standing at point y and looking North. Because you're looking
away from face f, you don't bother recursing down the entire left subtree. This
then very quickly gives you the ordered list of faces: a,d1,b1.
Refinements
-----------
If at each node we define a bounding box for each subtree, such that every line
in a subtree is contained by its corresponding bounding box, then we can cut
some invisible polygons (ones which lie to the left or right of the screen) out
by comparing each bounding box with the cone of vision - if they don't
intersect, then you don't go down the whole subtree. DOOM does this, allowing
it to store an *entire* level in one huge BSP tree.
Here's some pseudo-code to traverse the tree. The function left() returns TRUE
if the second input vector is to the left of the first input vector. This is
a simple dot product, and by pre-calculating the slope of the nodeline can be
done with one multiply and one subtract.
vector  player                         ; player's map position
vector  left_sightline                 ; vector representing a ray cast through
                                       ; the left-most pixel of the screen
vector  right_sightline                ; the right-most pixel of the screen
structure node
{
  vector vertex1
  vector vertex2
  node   left_subtree
  node   right_subtree
  face   left_face
  face   right_face
  box    bounding_box
  bool   terminal_node
  face   terminal_node_faces[lots]
}
recurse(node input)
if (cone defined by left and right sightlines does not intersect the node's
    bounding box)
  return
fi
if node.terminal_node
  ; terminal node - add faces to list
  add(node.terminal_node_faces)
  return
fi
if left(vertex2-vertex1,player-vertex1)
  ; player is to the left of the nodeline
  if not left(vertex2-vertex1,right_sightline)
    ; sight points right - we are looking at the face
    recurse(node.right_subtree)
    add(node.left_face)
  fi
  ; now go down the left subtree
  recurse(node.left_subtree)
else
  ; player is to the right of the nodeline
  if left(vertex2-vertex1,left_sightline)
    ; sight points left - we are looking at the face
    recurse(node.left_subtree)
    add(node.right_face)
  fi
  ; now go down the right subtree
  recurse(node.right_subtree)
fi
return
end recurse
This isn't anywhere near a decent implementation - the data structures, for
example, leave a *lot* to be desired :-)
It should be possible to encode all the functions inline; in fact, it would be
feasible to take a BSP tree and hard-code it into some run-time generated code
which you just call to recurse the tree ... but I'm just a hacker at heart ;-)
Anyway, I hope this helps answer some peoples' questions on this subject. If
you have any more questions, please don't hesitate to email me.
Catch you later,
Eddie xxx
ee@datcon.co.uk
===========================================================================
Official Archimedes convertor of : Hear and remember, see and understand,
Wolfenstein 3D and proud of it!! : do and forget.
=================================: Something like that, anyway.
         ee@datcon.co.uk         ==========================================

Let Us 'C'

struct Indian_female_professionals { 
    double styles;
    short skirts;
    long time_to_understand_problems;
    float mind;
    void knowledge;
    char non_co-operative;
}
struct married_females {
    double weight;
    short tempered;
    long gossip;
    float hopes;
    void word;
    char unstable;
}
struct engaged_females {
    double time_on_phone;
    short attention_on_work;
    long boast;
    float on_cloud_nine;
    void understanding;
    char edgy;
}
struct newly_married_females {
    double dinner_invitation;
    short time_at_work;
    long lunch_break;
    void bank_balance;
    char hen_pecked;
}
struct Indian_husband_wife_professionals {
    double income;
    short tempered;
    long time_no_see_each_other;
    void love_life;
    char money_making;
}

MacOS X on regular Intel compatible hardware

I think MacOS X running on regular Intel hardware is a great idea. Just think about the kind of interoperability that would offer. I guess I am biased because I think from the developer's point of view (being a developer myself). If MacOS X is able to run on regular Intel compatible hardware, then it can become as popular as Windows is today. And that would give developer motivation to write the same software the write for Windows. Just think about it. Today the best games come for the Windows platform first and then they are PORTED to the Mac. Now, since the Mac is using regular Intel compatible hardware, developers can target both platforms at the same time. Besides if MacOS X runs for regular Intel chips it also means it would run on those sexy AMD chips (which I am a great fan of). Compare to those many OSes out there, the MacOS X really stands out. Take a look. UNIX like core (Darwin), stability, features, performance, looks, it has it all. Not many people can afford the costly (albeit great) Mac hardware. So this would be a real big thing. If I were to rate all those Desktop OSes out there, my rating would go like this (earlier the better): 1. Windows 7, 2. MacOSX, 3. Haiku, 4. ReactOS. Sorry I am not a Linux fan due to the bitter experience I had with it and lack of standardization.

Edit: This post was written nearly 5+ years ago and was moved over from Windows Live Spaces to here.

Sunday, November 16, 2008

Legacy Free PCs

Many people don't know it, but today's PCs--including the system you're using right now--contain elements that have hardly changed at all in the last 20 years. Yes, CPUs are faster, hard drives are bigger, and RAM banks are larger. But in many fundamental ways, your PC isn't very different from the PCs of two decades ago.
Although some of the system elements have been modified over time, almost everything in your PC is a direct lineal descendent of the IBM PC AT--a seminal design that still shapes PC architecture two decades later.
In many ways, the PC's hardware consistency over time has been a good thing, a stabilizing force in the otherwise rapidly changing world of computing. It's been a huge positive for businesses and users because this consistency has made many peripherals completely interchangeable. For decades, we've been able to mix and match printers, keyboards, mice, monitors, scanners, modems, and more, largely without regard to the brand of PC.
Hardware standardization also has helped the bottom line by driving down prices: System and peripheral vendors have had a vast and uniform market from which to draw supplies, and to which to sell products, resulting in the commodity-level pricing that's behind today's amazingly low hardware costs. Overall, the PC AT's legacy has been an enormously positive one.
But it also has had a downside, principally in retarding innovation and slowing hardware advancements. The installed base--that is, the mass of existing, older, in-use hardware--acts like a giant speed brake on the computer industry because businesses and users are loath to give up older equipment that's still functional, even if newer designs would perform better or faster. As a result, new technologies tend to emerge piecemeal and more slowly than they would if hardware vendors could make a clean break with the past.
There's even a joke that made the rounds of the computing industry awhile ago: "Why was God able to create the universe in only seven days? Because he didn't have an installed base to deal with."
Despite this backward drag from the installed base, the Grail of many hardware engineers has long been a totally "legacy free" PC that can employ only fully modern, state-of-the-art, high-speed components and architectures. Such a PC would be faster, more compact, more reliable, and less expensive, as well as easier to manufacture and maintain.

- Fred Langa

The IBM PC shipped in 1981 -- over twenty years ago. The PC offered various expansion capabilities, including a parallel port, a pair of serial ports (on a separate card), and a keyboard port. It also supported a 5.25" 160KB single-sided floppy disk. The 8-bit PC/XT bus slots were expanded to 16-bit ISA slots in the PC/AT in late 1984. Later, IBM shipped the PS/2, whose enduring legacy in the PC universe today is a pair of compact connectors for the keyboard and mouse, and the 3.5" 1.44MB floppy drive.
Recently, I dug out an old Northgate Omnikey keyboard that's been gathering dust in my storage area. It's at least ten years old. I plugged in a PC-to-PS/2 keyboard adapter. It still works. This type of backwards compatibility has been the great strength of the PC over the years, but it's rapidly becoming an Achilles heel. Various factors have kept these anachronisms in place, such as corporate IT shops that need to support parallel and serial ports, or users with a pile of floppies that contain valuable data. We've even seen an ISA slots in a few new systems. And no doubt the Super I/O chip is still using ISA signaling to support legacy I/O.
So it's no surprise that a company like Apple Computers can push interesting new technologies into their hardware and software more quickly than PC manufacturers. But the buzz over the "legacy free" PCs is starting to heat up. It began several years ago, with both Intel and Microsoft encouraging PC makers to move away from legacy connections. Back then, the pleas fell mostly on deaf ears, but it's beginning to look like the industry is ready. Dell is starting to ship USB keyboards, Gateway will pay you to delete the floppy drive, and at least one component company -- ABIT -- is shipping a line of "legacy-free" motherboards.
What do we mean by "legacy" here? Specifically, we're talking about a set of I/O options that have been part of the PC architecture for a long, long time.
If you look at "legacy-free" meaning a system that eliminates the entire kit and caboodle of this table, then we're still several years out. PCI and AGP will be around for at least two more years before PCI Express surfaces in force. Even then, don't expect systems to get rid of PCI slots anytime soon. Parallel IDE hard drives will probably be around for a couple more years, but will gradually give way to Serial ATA. Similarly, parallel SCSI will yield to serial-attached SCSI.
Actually, we shouldn't forget that the VGA port is also a legacy standard. In fact, VGA hardware is the only remaining piece of hardware that interacts directly with Windows. There is a move afoot to eliminate VGA, called the Universal Graphics Adapter or "UGA". The firmware-based UGA functionality will be accessible via a UGA driver built into the next version of Windows, codenamed Longhorn. If the graphics chip makers consider removing VGA at that time, we could be completely legacy-free.

- Loyd Case

Did you know that the latest Intel Macs are actually "Legacy Free PCs"? In case you do not believe me, do a Google search for any Intel Mac's hardware specifications.

Why a Legacy Free PC?
Three words... simplicity, stability and evolution.

How can we define Legacy Free PCs now? Here is an overview:

Must Have

x86-64 Processor
http://en.wikipedia.org/wiki/X86-64

EFI
http://en.wikipedia.org/wiki/Extensible_Firmware_Interface

PCI-Express
http://en.wikipedia.org/wiki/PCI-Express

USB
http://en.wikipedia.org/wiki/USB

SATA
http://en.wikipedia.org/wiki/SATA

Must Not Have

BIOS
http://en.wikipedia.org/wiki/BIOS

ISA Bus
http://en.wikipedia.org/wiki/ISA_bus

PCI Bus
http://en.wikipedia.org/wiki/PCI_bus

AGP
http://en.wikipedia.org/wiki/Accelerated_Graphics_Port

Serial Ports
http://en.wikipedia.org/wiki/Serial_ports

Parallel Port
http://en.wikipedia.org/wiki/Parallel_port

PS/2 Ports
http://en.wikipedia.org/wiki/PS/2_connector

VGA Port
http://en.wikipedia.org/wiki/Vga_port

Floppy Disk Controller
http://en.wikipedia.org/wiki/Floppy_disk_controller

Game Port
http://en.wikipedia.org/wiki/Game_port

Indeed, as system designers are freed of the constraints of the past, we'll likely see radical PC designs that will not only be faster, smaller, and better than today's designs, but that will make the traditional beige-box PC seem positively antiquated. And I, for one, can't wait!

Wednesday, May 14, 2008

Running Blood 2 on Windows Vista x64

I would like to share my experiences running Blood 2 Chosen and Nightmare Levels on Windows Vista x64. First off the both game installers use 16-bit installer stubs because of which it does not allow you to install the game directly on 64-bit Windows (32-bit Windows should work fine). Anyways, I installed both games and the patches inside Microsoft Virtual PC on Windows XP 32-bit. Then I moved the full game folder out to Windows Vista x64. If you are using 32-bit Windows, you should not face the same problem. To my surprise mostly everything worked out of the box except the music. I cranked the game to it's highest settings and ran it a 1280x960. It looked good for it's standard. But I was missing the music. So I started examining the files. The game uses Microsoft IMA (Interactive Music Architecture - old form of DirectMusic). Then I loaded the game in Dependency Viewer and start profiling it. I found that the Music failed to work due to a missing function "DirectSoundCreate" in the DLL "dslite.dll". Having done some DirectX programming before, I quickly figured that this is a mini version of the DirectSound library. The file that depends on "dslite.dll" is "am18.dll" that you will find in the Blood2 directory. I quickly opened "am18.dll" in a binary editor ("edit.com /72 am18.dll" works good) and binary edited the string "dslite.dll" to "dsound.dll" and saved the file (always remember to be in overwrite mode - this will not change the DLL file size and structure; do not overwrite other parts of the DLL). Then I fired Bood 2 and voila! Everything worked... even the music. :)

Edit:
Find the hacked AM18.dll file here.

Monday, February 18, 2008

Funny, but real spoken english!

In Tamilnadu, there is a well known person by name, Mr. Jeppier, Chairman of Sathyabama deemed university and some more self financing colleges who always speaks in English. That college students have collected & published a book by name "Jappier's Spoken English". Now, here are some classic English sentences from the great "Jappier's Spoken English".

# At the ground:
-----------------
All of you stand in a straight circle. There is no wind in the balloon. The girl with the mirror please comes her... (i.e. girl with specs please come here).

# To a boy, angrily:
--------------------
I talk, he talk, why you middle middle talk?

# While punishing students:
---------------------------
You, rotate the ground four times... You, go and understand the tree... You three of you stand together separately. Why are you late - say YES or NO .....(?)

# While addressing students about Dress Code: (he is very strict about this)
----------------------------------------------------------------------------
Every body should wear dress to college.
Boys no proplum.
Girls are pig proplum. (pig=big)
Girls should wear only slawar no nitee.

# Sir at his best:
------------------
Sir had once gone to a film with his wife. By chance, he happened to see one of our boys at the theatre, though the boy did not see them. So the next day at school... (to that boy) - "Yesterday I saw you WITH MY WIFE at the Cinema Theatre".

# Sir at his best inside the Class room:
----------------------------------------
Open the doors of the window. Let the atmosphere come in.
Open the doors of the window. Let the Air Force come in.
Cut an apple into two halves - I will take the bigger half.
Shhh... Quiet, boys... the principal JUST PASSED AWAY in the corridor.
You, meet me behind the class. (Meaning AFTER the class.)
Both of you three get out of the class.
Close the doors of the windows please. I have winter in my nose today...
Take Copper Wire of any metal especially of Silver...
Take 5 cm wire of any length....

# Last but not the least some Jeppiar experiences...
----------------------------------------------------
Once Sir had come late to a college function, by the time he reached, the function had begun, so he went to the dais, and said, sorry I am late, because on the way my car hit 2 muttons (Meaning goats).

# At Sathyabama college day 2002:
---------------------------------
"This college strict u the worry no .... U get good marks, I the happy, tomorrow u get good job, jpr the happy, tomorrow u marry I the enjoy".

# At St. Josephs college of engineering fresh years day 2003:
-------------------------------------------------------------
"No ragging this college. Anybody rag we arrest the police "

Enjoy this English, but don't forget your English!!! :)

Sunday, September 16, 2007

Modding your K750i phone to a W800i

Warning: Do this at your own risk!


This blog explains how you can mod your Sony Ericsson K750i to a Sony Ericsson W800i or just replace the worn out K750i chassis.



Tools that you will need:

  1. Small Philips screwdriver

  2. T6 Torx screwdriver

  3. A small blunt (plastic) knife/shim to pry stuff
Watch this video for further details (sorry audio is in chinese):

Friday, August 31, 2007

The AMD Athlon™ 64 Processor Operational Modes (also applies to Intel chips with EM64T)

Legacy Mode: Legacy mode is what the processor defaults to in basic 32-bit software. If you run a 32-bit Linux or Windows installation you’ve been running in legacy mode; if you’ve looked at any performance benchmarks it should be obvious that not only is the AMD Athlon™ 64 processor more than happy to run this way, it delivers excellent performance while doing so.

Compatibility Mode: Compatibility mode is designed for a 64-bit processor that still needs the capability to run 32-bit applications. The AMD Athlon 64 processor is capable of this natively, which eliminates the need for 32-bit emulation on the hardware level.

Long Mode: True 64-bit Long Mode is intended for a native 64-bit OS environment where the application is also running 64-bit. Windows XP Professional x64 Edition is capable of using both modes, and the AMD Athlon 64 processor is capable of switching between 64-bit Long Mode and Compatibility mode from within the 64-bit OS.

Why Move to 64-bit?

If 32-bit systems offer excellent performance now, why move to a 64-bit OS at all? It’s a question with a multi-faceted answer, depending on your needs.

Increased Memory Addressing: Standard 32-bit computers have a 4 GB limit on addressable memory. 64-bit computing offers a memory address limitation measured in exabytes that will open this potential bottleneck for years to come.

Increased Computational Power: The AMD Athlon™ 64 processor adds an additional eight General Purpose Registers and eight 128-bit streaming SIMD extension (SSE) registers. Using a 64-bit OS opens these for application-usage for the first time. Increasing the raw computation capability of the processor in turn opens the door to increased visual detail in games, unprecedented scientific modeling, and stronger performance across a wide range of applications.

No Performance Penalty for Running in 32-bit: Unlike computer platforms that emulate 32-bit or x86 compatibility, AMD64 architecture can execute such commands natively. The advantage to this is that even legacy 32-bit code is delivered with no performance penalty. When running in a 64-bit OS, Microsoft’s WoW (Windows on Windows) 64 mode allows the chip to natively access programs; in a 32-bit OS such as Windows XP (standard), no such operating mode is needed. This is in direct contrast to other 64-bit designs, which require emulation (and take a massive performance penalty for executing 32-bit x86 operations).

Moving to 64-bit will not universally improve performance in all applications and test suites, but it won’t degrade performance either. This logically translates into a scenario where the “worst case” possibility is performance equality, and the best-case is a significant performance boost. For end-user, corporation, or major business server, this is a universal win.

This information was taken from a document on http://www.amd.com

Sunday, July 15, 2007

Windows XP Product Key Finder

' Windows XP Product Key Finder
' Copy text and paste it in a vbs file and run it.
' Code found by SaM. EnJoY!
' We work in the dark. We get what we want.

Public Function sGetXPCDKey()

Dim bDigitalProductID
Dim bProductKey()
Dim bKeyChars(24)
Dim ilByte
Dim nCur
Dim sCDKey
Dim ilKeyByte
Dim ilBit

ReDim Preserve bProductKey(14)

Set objShell = CreateObject("WScript.Shell")

bDigitalProductID = objShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Windows NT\CurrentVersion\DigitalProductId")

Set objShell = Nothing

For ilByte = 52 To 66
bProductKey(ilByte - 52) = bDigitalProductID(ilByte)
Next

'Possible characters in the CD Key:
bKeyChars(0) = Asc("B")
bKeyChars(1) = Asc("C")
bKeyChars(2) = Asc("D")
bKeyChars(3) = Asc("F")
bKeyChars(4) = Asc("G")
bKeyChars(5) = Asc("H")
bKeyChars(6) = Asc("J")
bKeyChars(7) = Asc("K")
bKeyChars(8) = Asc("M")
bKeyChars(9) = Asc("P")
bKeyChars(10) = Asc("Q")
bKeyChars(11) = Asc("R")
bKeyChars(12) = Asc("T")
bKeyChars(13) = Asc("V")
bKeyChars(14) = Asc("W")
bKeyChars(15) = Asc("X")
bKeyChars(16) = Asc("Y")
bKeyChars(17) = Asc("2")
bKeyChars(18) = Asc("3")
bKeyChars(19) = Asc("4")
bKeyChars(20) = Asc("6")
bKeyChars(21) = Asc("7")
bKeyChars(22) = Asc("8")
bKeyChars(23) = Asc("9")

For ilByte = 24 To 0 Step -1
nCur = 0

For ilKeyByte = 14 To 0 Step -1
'Step through each byte in the Product Key
nCur = nCur * 256 Xor bProductKey(ilKeyByte)
bProductKey(ilKeyByte) = Int(nCur / 24)
nCur = nCur Mod 24
Next

sCDKey = Chr(bKeyChars(nCur)) & sCDKey
If ilByte Mod 5 = 0 And ilByte <> 0 Then sCDKey = "-" & sCDKey
Next

sGetXPCDKey = sCDKey
End Function

Public Function Question()

Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim Ans

Ans = MsgBox("Yes = Write Windows XP Serial key to the C Drive and No =
Prompt with Serial key",4)

If Ans = vbYes then

Set oOutFile = objFSO.CreateTextFile("c:\XP_Serial_Key.txt")

oOutFile.WriteLine sGetXPCDKey
else
wscript.echo sGetXPCDKey
End If
End Function

call Question

' Script ends here

Get the script here.

Change Office 2007 Key without reinstalling

1.      Close all Microsoft Office applications.

2.      Click Start, click Run, type regedit in the Open box, and then click OK.

3.      Locate the following registry subkey:
HKEY_LOCAL_MACHINE\Software\Microsoft\Office\12.0\Registration

Note You may also find another subkey that resembles the following subkey:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\{91120000-0011-0000-0000-0000000FF1CE}

4.      If you find additional subkeys that reference Microsoft 12.0 registration, open each subkey, and then identify the product by the ProductName entry.
For example: ProductName=Microsoft Office Professional Plus 2007

5.      When you find the subkey for the product from which you want to remove the existing product license key, delete the following entries:

o    DigitalProductID

o    ProductID

6.      Exit Registry Editor.

The next time that you try to run an Office application, you will be prompted for a new product license key. Then, you can enter the product license key.

Hit the "Install Now" button and you Office app, will be updated with the new key. After updating you can activate your Office app, without reinstalling it.

Wednesday, July 11, 2007

A feeling which I had long forgotten

Today after much though, I realized what is actually bothering me. Well, "bothering" would be the incorrect word to use in this context because I believe that I have once again fallen in love! And that too with the person I never expected to fall in love with... a very good friend. I realized that I was missing something after moving away from her and then I realized that I was missing her (a lot). It happens all the time... we never care for things which we can easily avail, but once those things become hard to get we come to know its worth. I never imagined myself falling in love again after I crashed and burned at my first attempt which was very painful to say the least. And now once again I am treading on the same path and guess what... I can't see what's ahead! I guess I would have never felt this way about her unless she allowed me to, so she too must be having some idea about how I feel about her. I guess I should confess to her about my feelings soon before it gets deeper in my head. Love is good and bad at the same time. It gives you that awesome feeling and the same time make you a worthless piece of s**t. So baby here I come and you're going to tell me if "I am in" or "I am out"!

Feedback Please

I would like to formally announce that right now I am working on my very own website. Please visit http://gomes.samuel.googlepages.com/
I need feedback and support from all you guys out there.

P.S.: It is still a work in progress.