Mosaic Tutorial (win32asm)
Introduction
In this lesson you will create a simple mosaic game. You probably know this kind of puzzles. An image or a matrix of numbers have to be placed in the right order by shuffeling the pieces into place. This lesson will teach you how to create this game step by step. It is useful to read the tutorials first before you start with this lesson. It's level is aimed at the beginner, everything is explained.
Prologue
This lesson is aimed at the beginner in asm. Every step in creating the program is explained. It is not just source code with comments, but it teaches you how to build up a program from scratch. My advice is to fully read the tutorial, and try to make the program yourself. This lesson is quite long but it will help you very much if you read it all.
Checklist
Make sure you have the following installed:
- The masm32 package, at least version 6 with service pack 2 (www.movsd.com)
- A good resource editor. This is not necessary, but a lot easier to do it by hand. To make this lesson accessible for anyone, I'll explain how to write the resources by hand (they are simply text files), but if you know how to use a resource editor you can use that instead. Good resource editors are: Borland Resource Workshop and the resource editor in Microsoft Visual Studio (Visual C++).
- A resource compiler (rc.exe will do for hand written files and microsoft visual studio's resource editor, but not for BRW).
- make sure that you have included the \masm32\bin folder and the paths of the other necessairy tools included in your path.
* BRW is no longer supported by Borland so you can download this legally (although I don't know for sure), but you need the brc32 tool to compile it (their resoure format is somewhat different from microsoft's, so using rc.exe wouldn't work). This tool is included in the TASM package but you cannot download this legally.
Glossary
As this is a lesson for the real beginners, this list of definitions can be useful. Read them if you don't know them already, it will help you understand the rest of the lesson.
Resources
A resource is data that is stored in the program file. A resource can be an icon, a table with strings, menu, dialog, bitmap, user defined data etc. The resources are first defined in a .rc file. This is a simple text file which you can write manually but it's much easier to use a resource editor like borland resource workshop or the editor in visual studio. The resources are then compiled into a binary file (.res). This file is then linked (yes with link) to the executable. Resources are accessed by their IDs. These IDs can be set in the resource file and in your source code you use the same ID to access the resource.
Owner-drawn windows
Owner-drawn windows are windows that are drawn by the program instead of the system. In this lesson a static control is used as an owner-drawn window. A WM_DRAWITEM message is sent to the window when the control needs to be drawn.
Local variables
Local variables are variables (i.e. data) that is used only in a specific procedure. Local data is saved while the procedure is running, but deleted afterwards (it is stored on the stack). Local variables are declared with LOCAL at the start of a procedure:
SomeProc proc ....
LOCAL localvar:DWORD