The website of Lei Chen

Sunshine and rain of a developer

Archive for June, 2009

System 6 Forever

Posted by hide1713 on June 28, 2009

sys6_1sys6_2

System 6 (also referred to as System Software 6) is a graphical user interface-based operating system for Macintosh computers. It was released in 1988 by Apple Computer and was part of the Mac OS line of operating systems. System 6 was shipped with various Macintosh computers until it was succeeded by System 7 in 1991. The boxed version of System 6 cost 49 USD when introduced.[1] System 6 is classed as a monolithic operating system. It featured an improved MultiFinder, which allowed for co-operative multitasking. The last version of System 6 was released in 1991.

Why system 6?

Macintosh Operating System 6 is probably the nicest operating system ever made. Nowadays it’s considered ancient (development stopped somewhere in 1991) but it’s far from backward and with the use of the proper vintage software you can be just as productive on a System 6 machine as you’d be on a modern Mac. System 6 runs on most older Macintosh computers with 68000, 68020 and 68030 processors. Some of these Machines are also able to run later versions of the Mac OS up to 7.55 and 7.61, but the lower-end models, most notably the so called Compact Macs, the Mac Plus, the SE and the Classic, and the lowend 68020’s, the Mac II and the LC, are better off running System 6. They will be a lot faster with System 6 than with System 7. The reason behind this is the fact that System 6 is not only a lot more compact (it has less features and therefore less code to crunch), but also because System 6 was written in assembly code instead of the high level language C. Assembly code is a bit lower level and because of that a bit closer to the hardware of the machine, making it a lot more responsive.

Read some more system 6 advocacy here

Link System 6 Heven

Posted in Uncategorized | Leave a Comment »

Travelling Salesman Problem

Posted by hide1713 on June 23, 2009

Posted in C | Leave a Comment »

Virtual Studio Smart Operator ‘=’. Add Spaces Around Every ‘=’.

Posted by hide1713 on June 22, 2009

I find it’s really hard to extend the environemnt under VS 2008. Anyway, I have to learn some VB.

I really like the SmartOperator.el in Emacs. When I press ‘=’ key, it automatically insert two spaces around ‘=’.  The following code can do the same thing. You need to create a new macro in VS and put the code in the new macro and bind ‘=’ key to this function.  I hope the code could inspire someone.


Sub space_around_eq()
 Dim s As TextSelection = DTE.ActiveDocument.Selection
 s.CharLeft(True, 2)
 Dim selection = s.Text
 If selection.StartsWith("=") Then
 DTE.ActiveDocument.Selection.Text = "== "
 ElseIf selection.EndsWith("-") Or selection.EndsWith("+") Or selection.EndsWith("*") Or selection.EndsWith("=") Or selection.EndsWith(" ") Then
 DTE.ActiveDocument.Selection.Text = selection.ToString() + "= "
 Else
 DTE.ActiveDocument.Selection.Text = selection.ToString() + " = "
 End If
 End Sub

Posted in C, CPP | Leave a Comment »

DirectX DrawText Cause Vertex Shader linkage error. Here’s how to fix it

Posted by hide1713 on June 21, 2009

When I drew 3D objects  and text together, the first frame was fine. However, the second frame failed. This bug took me very long time to debug.  The pseudo code looks like this:


EveryFrame(){

   Draw3d();

   DrawText();

}

The shader generated  following output:

D3D10: ERROR: ID3D10Device::Draw: Input Assembler - Vertex Shader linkage error: Signatures between stages are incompatible. The reason is that the input stage requires Semantic/Index (POSITION,0) as input, but it is not provided by the output stage. [ EXECUTION ERROR #342: DEVICE_SHADER_LINKAGE_SEMANTICNAME_NOT_FOUND ]

Here is a post about the detail. Breafly speaking, DirectX DrawText() function changes the inner state of device; therefore, the input layout is changed after the first frame and, of course, the program failed in the second frame.

The solution is to use D3DX10_SPRITE_SAVE_STATE flag.


void cGraphicsLayer::DrawTextString(int x, int y,
 D3DXCOLOR color, const TCHAR* strOutput)
{
 m_pFontSprite->Begin(D3DX10_SPRITE_SAVE_STATE);
 RECT rect = {x, y, m_rcScreenRect.right, m_rcScreenRect.bottom};
 m_pFont->DrawText(m_pFontSprite, strOutput, -1, &rect, DT_LEFT, color);
 m_pFontSprite->End();
}

Posted in DirectX | Tagged: | Leave a Comment »

Will it blend? Iphone

Posted by hide1713 on June 18, 2009

They blend almost everything which that be put in to the blender

Posted in Uncategorized | Leave a Comment »

Configure Boost library in Visual Studio 2008

Posted by hide1713 on June 18, 2009

This tutorial teaches you how to setup boost library in Visual Stuido 2008. There’s a perbuild version you can download from Boost pro . The perbuild package can save you lots of time and effort. Believe me.

The boost pro downloader is not smart enough to detect old version; therefore, I highly recommend you install all the packages. There are many dependency within boost library. For example, the boost filesystem is depend on boost system and boost regular expression. If you miss one of them, you have to install the boost library again :(

Now, let’s setup Visual Studio so that it can find the file and library. Go to Tools->Option->Projects and Solutions->VC++ Directories.

Select “Include files” and Add a new directory. In my computer, it is

C:\Program Files (x86)\boost\boost_1_38\

Select “Library files” and Add a new directory

C:\Program Files (x86)\boost\boost_1_38\lib

That’s it.  Enjoy your life with Boost

Posted in CPP | Tagged: | Leave a Comment »

Use Python To Convert ASCII to UTF-16

Posted by hide1713 on June 17, 2009

Such an easy thing. But I took 1 hours to figure out.

import codecs
f=open(“wall.obj”,’r')
txt = f.read()
print txt
f.close()

of = codecs.open(“uwall.obj”,’w',’utf-16′)
of.write(txt)
of.close()

Posted in Uncategorized | Leave a Comment »

Intergrade CPPUNIT in Visual Studio 2008

Posted by hide1713 on June 15, 2009

This tutorial helps you configure the CPPUNIT  unit test environment in Visual Studio 2008. If you have any questions, please look at the trouble shooting section at the end of tutorial.

Firstly, There’s a bug in CPPUNIT. If you compile cppunit-1.12.1 under VS2008.You will either fail to compile the code or generate cppunit library without correct debug information.

Let’s fix the bug first. According to this post

I just tried to compile CPP Unit Under Visual C++ 2008. Compiler. There was one problem When I tried to compile MFC Test Runner.

MsDevCallerListCtrl.cpp

.\MsDevCallerListCtrl.cpp(67) : error C3505: cannot load type library ‘{80CC9F66-E7D8-4DDD-85B6-D9E6CD0E93E2}’

.\MsDevCallerListCtrl.cpp(67) : fatal error C1104: fatal error importing libid: ‘80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2′

CPP Unit using IDE Automation component to track the source lines in the MFCTest runner. Version cppunit-1.12.0 currently support till version 7 of IDE Automation. I’ve only version 2008 of Visual Studio installed in my machine. So just correct the version number in MsDevCallerListCtrl.cpp file

#pragma warning( disable : 4278 )

#pragma warning( disable : 4146 )

#import “libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2″ version(”9.0″) lcid(”0″) raw_interfaces_only named_guids

#pragma warning( default : 4146 )

#pragma warning( default : 4278 )

When you build the source code. You should see some assertion errors. That’s fine. They are not real errors, just some unit test code. Don’t worry about it. You should look into ./lib directory. There should be many files including cppunitd.dll, cppunit.dll,cppunitd_dll.pdb.

Now, you have code compiled. It won’t be difficult to setup right environemnt. Follow the money tutorial

In the following document, $CPPUNIT is the directory where you unpacked CppUnit: $CPPUNIT/: include/ lib/ src/ cppunit/First, you need to compile CppUnit libraries:

  • Open the $CPPUNIT/src/CppUnitLibraries.dsw workspace in VC++.
  • In the ‘Build’ menu, select ‘Batch Build…’
  • In the batch build dialog, select all projects and press the build button.
  • The resulting libraries can be found in the $CPPUNIT/lib/ directory.

Once it is done, you need to tell VC++ where are the includes and librairies to use them in other projects. Open the ‘Tools/Options…’ dialog, and in the ‘Directories’ tab, select ‘include files’ in the combo. Add a new entry that points to $CPPUNIT/include/. Change to ‘libraries files’ in the combo and add a new entry for $CPPUNIT/lib/. Repeat the process with ’source files’ and add $CPPUNIT/src/cppunit/.

Getting started

Creates a new console application (‘a simple application’ template will do). Let’s link CppUnit library to our project. In the project settings:

  • In tab ‘C++’, combo ‘Code generation’, set the combo to ‘Multithreaded DLL’ for the release configuration, and ‘Debug Multithreaded DLL’ for the debug configure,
  • In tab ‘C++’, combo ‘C++ langage’, for All Configurations, check ‘enable Run-Time Type Information (RTTI)’,
  • In tab ‘Link’, in the ‘Object/library modules’ field, add cppunitd.lib for the debug configuration, and cppunit.lib for the release configuration.

We’re done !

We are not done yet. There are three more things you should know.

1. By default, the cppunit is liked to Dll with /MDd option. Make sure other projects are using the same option. You will get many weird errors if you link other parts with static library /MTd

If you compile your code with MTd, you should link your code with cppunitd_dll.lib. otherwise, you should link with cppunitd.dll.

2. There are many ways to manage your unit test. You can setup  a subproject in a solution which generates unit test binary.  I spent few hours to figure out that I need to add cpp files to the unit test project so that  linker could find those functions.  If you see “Symbol unsolved” errors,  this is the right direction to look into.

3. Look at your project path. The default project path contain space. So Visual Studio postcompile command can not correctly execute if you follow the “Money” tutorial.

Posted in CPP | Leave a Comment »

Magic C++ comment trick

Posted by hide1713 on June 8, 2009

A fast swith to comment/ uncomment block of code


/*   <---
 return 1;
 /*/
 return 0;
 //*/

There are bugs in word press cpp highlight plugin. copy the following code to your IDE and try it yourself 

//*   <----

 return 1;
 /*/
 return 0;
 //*/

Posted in CPP | Leave a Comment »

Run Cmd and Python In Windows XP & Vista Background

Posted by hide1713 on June 1, 2009

This wonderful tiny tool give you the ability to run program in XP & Vista background.  It helps me  hide the cmd.exe window so that I can run my python wiki server complete in the background.

hstart home page and download:

http://www.ntwind.com/software/utilities/hstart.html

Usage:

hstart /NOCONSOLE “whatever command you want”

Posted in Python | Leave a Comment »