• # Win32 Assembly Part 5

General and Gameplay Programming

[size="5"]Where Did We Leave Off?

Until last issue SPACE-TRIS wasn't even a game, it was merely an exercise in coding modules. Well, now we have a game that is working, it is just ugly. Sadly enough though, we are back to coding modules today. The good news is these modules will pretty things up by a large margin.

The modules that we will be covering today are Direct Sound (YUCK!) and screen transitions (YA!). The Direct Sound module isn't going to be anything to complex, just a simple sound effects manager that allows you to play, stop, delete, add, or set variables on the sounds themselves. The screen transitions module is going to consist of one main function that gets called and then a transition is selected at random to perform.

When we last saw each other, the game also needed a way to check for an "out-of-bounds" occurrence while rotating pieces. You guys were working on it, like I told you too, right? Yeah, I'm sure. Anyway, I will present my quick hack of a solution in a few moments. But first, I want to say that I am going to be glossing over many of the things we have already covered in past issues. For instance, in the Direct Sound module you guys have all seen how to check for an error, so I won't be explaining that again. This means, if you are new to the series, do yourself a favor and start at the beginning. This isn't your favorite TV series where you can just pop by, on any old day, and know what is going on. We are going to be moving at warp speed through a lot of things. All I am really going to provide now is an overview of the techniques I use ... it is up to you to understand them.

With that said, let us get right down to business with that solution to the rotation problem.

[size="5"]Rotation Solution

The solution to our rotation problem was fairly straightforward. Basically, we already had all of the routines that we needed. What we had to know was if, at any given frame, the current piece would be out of bounds -- which MoveShape() does for us. So, the fix we have is a simple one. We can just call that routine with the frame it "would" be on next, right? Wrong. That is what I tried at first because it makes sense. But, there is a hidden problem with that method.

The problem lies in that fact that any piece could already be out of bounds when you adjust the frame. Move_Shape() only tells you if you can move the shape to the left or right, and does so if it can. If we fake our next frame for that call it may succeed because it is already out of bounds by one column if it was on the edges previously. This means we need a way to prevent it from ever being out of bounds to begin with.

The solution is to move it in towards the center by one column beforehand. Then, when we make the call, the shape is guaranteed to be on the edge, or in the middle, never outside the grid. The way we decide if we could go to the next frame is by seeing if the X coordinate sent before we made the call matches the one we have after the call. If it does, then that means the shape can be rotated ... if they don't match then the shape can not be rotated.

This method has the advantage of eliminating the need for any other code. The Move_Shape() function will not succeed if something else is blocking its move. Therefore, we do not need to do any other tests on the shape to see if other blocks are in the way. Just that simple call based on the next frame. So, we not only solved the problem ... but also made the routine shorter in the process.

The new Rotate_Shape()

;######################################################################## ; Rotate_Shape Procedure ;######################################################################## Rotate_Shape PROC ;======================================================= ; This function will rotate the current shape it tests ; to make sure there are no blocks already in the place ; where it would rotate. ;======================================================= ;================================ ; Local Variables ;================================ LOCAL Index: DWORD LOCAL CurBlock: DWORD LOCAL Spot: BYTE ;================================= ; Make sure they are low enough ;================================= .IF CurShapeY > 21 JMP err .ENDIF ;================================ ; Are they at the last frame? ;================================ .IF CurShapeFrame == 3 ;===================================== ; Yep ... make sure they can rotate ;===================================== ;======================================== ; We will start by seeing which half of ; the grid they are currently on that way ; we know we much too move the shape ;========================================= .IF CurShapeX < 6 ;=========================== ; They are on the left half ; of the grid ;=========================== ;============================= ; So start by moving them one ; coord right and saving the ; old coordinat ;============================= PUSH CurShapeX INC CurShapeX ;============================= ; Now adjust the frame to what ; it would be ;============================= MOV CurShapeFrame, 0 ;============================= ; Try to move them to the left ;============================= INVOKE Move_Shape, MOVE_LEFT ;============================= ; If we succeeded then the old ; X will be equal to the new ; X coordinate ;============================= MOV EAX, CurShapeX POP CurShapeX .IF EAX == CurShapeX JMP done .ELSE ;================ ; Can't rotate ;================ MOV CurShapeFrame, 3 JMP err .ENDIF .ELSE ;=========================== ; They are on the right half ; of the grid ;=========================== ;============================= ; So start by moving them one ; coord left and saving the ; old coordinat ;============================= PUSH CurShapeX DEC CurShapeX ;============================= ; Now adjust the frame to what ; it would be ;============================= MOV CurShapeFrame, 0 ;============================= ; Try & move them to the right ;============================= INVOKE Move_Shape, MOVE_RIGHT ;============================= ; If we succeeded then the old ; X will be equal to the new ; X coordinate ;============================= MOV EAX, CurShapeX POP CurShapeX .IF EAX == CurShapeX ;================ ; Can rotate ;================ JMP done .ELSE ;================ ; Can't rotate ;================ MOV CurShapeFrame, 3 JMP err .ENDIF .ENDIF .ELSE ;===================================== ; NO ... make sure they can rotate ;===================================== ;======================================== ; We will start by seeing which half of ; the grid they are currently on that way ; we know we much too move the shape ;========================================= .IF CurShapeX < 6 ;=========================== ; They are on the left half ; of the grid ;=========================== ;============================= ; So start by moving them one ; coord right and saving the ; old coordinat ;============================= PUSH CurShapeX INC CurShapeX ;============================= ; Now adjust the frame to what ; it would be ;============================= INC CurShapeFrame ;============================= ; Try to move them to the left ;============================= INVOKE Move_Shape, MOVE_LEFT ;============================= ; If we succeeded then the old ; X will be equal to the new ; X coordinate ;============================= MOV EAX, CurShapeX POP CurShapeX .IF EAX == CurShapeX ;================ ; Can rotate ;================ JMP done .ELSE ;================ ; Can't rotate ;================ DEC CurShapeFrame JMP err .ENDIF .ELSE ;=========================== ; They are on the right half ; of the grid ;=========================== ;============================= ; So start by moving them one ; coord left and saving the ; old coordinat ;============================= PUSH CurShapeX DEC CurShapeX ;============================= ; Now adjust the frame to what ; it would be ;============================= INC CurShapeFrame ;============================= ; Try & move them to the right ;============================= INVOKE Move_Shape, MOVE_RIGHT ;============================= ; If we succeeded then the old ; X will be equal to the new ; X coordinate ;============================= MOV EAX, CurShapeX POP CurShapeX .IF EAX == CurShapeX ;================ ; Can rotate ;================ JMP done .ELSE ;================ ; Can't rotate ;================ DEC CurShapeFrame JMP err .ENDIF .ENDIF .ENDIF done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Rotate_Shape ENDP ;######################################################################## ; END Rotate_Shape ;########################################################################

[size="5"]The Sound Module

The sound module for this game is pretty simple. It merely presents an interface to Load WAV files, play the sounds, delete them, and edit properties about them. However, there are a few tricky things to watch out for in the module.

The first thing I want to illustrate is how to create an array of structures. Take a look at the following modified code snippet.

;################################################################################# ;################################################################################# ; STRUCTURES ;################################################################################# ;################################################################################# ;============================= ; this holds a single sound ;============================= pcm_sound STRUCT dsbuffer DD 0 ; the ds buffer for the sound state DD 0 ; state of the sound rate DD 0 ; playback rate lsize DD 0 ; size of sound pcm_sound ENDS ;============================ ; max number of sounds in ; the game at once ;============================ MAX_SOUNDS EQU 16 ;========================================= ; Our array of sound effects ;========================================= sound_fx pcm_sound MAX_SOUNDS dup(<0,0,0,0>)You will notice that anytime we declare a structure we need to use angle brackets, or curly braces (not shown), for them. The numbers inside consist of the members of your structure and nothing more. Whatever you place there is what things get initialized to. Also, pay attention to how the structure is defined. It consists of normal variable declarations in between a couple of keywords and a tag to give it a name.

Of special note, is that you must use another set of braces, or brackets, if you wish to have nested structures. The way we get an array with a structure is the same as any other variable. We use the number we want followed by the DUP ... then, in parenthesis, what you want the values initialized as.

We are going to skip over the DS_Init() and DS_Shutdown() procedures, since they do the same exact things as the other DX counterparts. Instead let's take a peek at Play_Sound().

;######################################################################## ; Play_Sound Procedure ;######################################################################## Play_Sound PROC id:DWORD, flags:DWORD ;======================================================= ; This function will play the sound contained in the ; id passed in along with the flags which can be either ; NULL or DSBPLAY_LOOPING ;======================================================= ;============================== ; Make sure this buffer exists ;============================== MOV EAX, sizeof(pcm_sound) MOV ECX, id MUL ECX MOV ECX, EAX .IF sound_fx[ECX].dsbuffer != NULL ;================================= ; We exists so reset the position ; to the start of the sound ;================================= PUSH ECX DSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0 POP ECX ;====================== ; Did the call fail? ;====================== .IF EAX != DS_OK ;======================= ; Nope, didn't make it ;======================= JMP err .ENDIF ;============================== ; Now, we can play the sound ;============================== DSBINVOKE Play, sound_fx[ECX].dsbuffer, 0, 0, flags ;====================== ; Did the call fail? ;====================== .IF EAX != DS_OK ;======================= ; Nope, didn't make it ;======================= JMP err .ENDIF .ELSE ;====================== ; No buffer for sound ;====================== JMP err .ENDIF done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Play_Sound ENDP ;######################################################################## ; END Play_Sound ;########################################################################This is the routine that we use to start a sound playing. You can pass it flags to alter how it sounds. So far as I know there are only 2 options for the flags. If you pass in NULL then it plays the sound once. If you pass in DSBPLAY_LOOPING it will play the sound repeatedly.

The routine begins by checking that the sound has a valid buffer associated with it. If so, it sets the position of that sound to the beginning and then makes a call to begin playing it with whatever flags were passed in.

The only thing worth illustrating in this routine is how the structure element is referenced. To begin with we obtain the size of the structure and multiply that by the id of the sound to give us our position in the array. Then, in order to reference a member you treat it just like you would in C/C++ ... StructName[position].member ... the important thing is not to forget to multiply the element by the size of the structure.

The next 3 routines allow you to set the volume, frequency, and pan of a sound. There is nothing to these routines ... they are just wrappers for the Direct Sound function calls. However, if you want to use anything but Set_Sound_Volume() you need to tell Direct Sound that you want those enabled when you load the sound. This is done by passing in DSBCAPS_CTRL_PAN or DSBCAPS_CTRLFREQ respectively. If you do not specify these flags when you load your sound you will not be able to manipulate those items.

The next two functions are for stopping sounds from playing. One will stop the specific sound you pass in and the other will stop all of the sounds from playing. Here is the code if you want to take a peek. Once again these are merely wrapper functions to shield you from the DX headache.

;######################################################################## ; Stop_Sound Procedure ;######################################################################## Stop_Sound PROC id:DWORD ;======================================================= ; This function will stop the passed in sound from ; playing and will reset it's position ;======================================================= ;============================== ; Make sure the sound exists ;============================== MOV EAX, sizeof(pcm_sound) MOV ECX, id MUL ECX MOV ECX, EAX .IF sound_fx[ECX].dsbuffer != NULL ;================================== ; We exist so stop the sound ;================================== PUSH ECX DSBINVOKE Stop, sound_fx[ECX].dsbuffer POP ECX ;================================= ; Now reset the sound position ;================================= DSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0 .ENDIF done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Stop_Sound ENDP ;######################################################################## ; END Stop_Sound ;######################################################################## ;######################################################################## ; Stop_All_Sounds Procedure ;######################################################################## Stop_All_Sounds PROC ;======================================================= ; This function will stop all sounds from playing ;======================================================= ;============================== ; Local Variables ;============================== LOCAL index :DWORD ;============================== ; Loop through all sounds ;============================== MOV index, 0 .WHILE index < MAX_SOUNDS ;================================== ; Stop this sound from playing ;================================== INVOKE Stop_Sound, index ;================ ; Inc the counter ;================ INC index .ENDW done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Stop_All_Sounds ENDP ;######################################################################## ; END Stop_All_Sounds ;########################################################################Delete_Sound() and Delete_All_Sounds() are remarkably similar to the sound stopping functions. The only difference is you make a different function call to DX. Delete_Sound() will call Stop_Sound() first, to make sure the sound isn't trying to be played while you are trying to delete it. The interesting thing about these two functions is that you do not personally have to release any of your sounds if you don't want to. During shutdown of Direct Sound all the sounds that you loaded will be deleted. However, if you have reached your maximum in sounds, and want to free one up, you will need to manually delete it.

The next function Status_Sound() is yet another wrapper routine. It is used when you need to find out if a sound is still playing, or if it has stopped already. You will see this function put to use later on.

There, 90% of that stupid module is out of the way. Now, we need to move on to the final 10% of that code ... the Load_WAV() procedure.

Loading file formats is always a pain to do. Loading a WAV file proves to be no different. It is a long function, that probably could have been broken up a little bit better, but for now it will have to do. It works and that is all I am concerned about. So, have a peek at it.

;######################################################################## ; Load_WAV Procedure ;######################################################################## Load_WAV PROC fname_ptr:DWORD, flags:DWORD ;======================================================= ; This function will load the passed in WAV file ; it returns the id of the sound, or -1 if failed ;======================================================= ;============================== ; Local Variables ;============================== LOCAL sound_id :DWORD LOCAL index :DWORD ;================================= ; Init the sound_id to -1 ;================================= MOV sound_id, -1 ;================================= ; First we need to make sure there ; is an open id for our new sound ;================================= MOV index, 0 .WHILE index < MAX_SOUNDS ;======================== ; Is this sound empty?? ;======================== MOV EAX, sizeof(pcm_sound) MOV ECX, index MUL ECX MOV ECX, EAX .IF sound_fx[ECX].state == SOUND_NULL ;=========================== ; We have found one, so set ; the id and leave our loop ;=========================== MOV EAX, index MOV sound_id, EAX .BREAK .ENDIF ;================ ; Inc the counter ;================ INC index .ENDW ;====================================== ; Make sure we have a valid id now ;====================================== .IF sound_id == -1 ;====================== ; Give err msg ;====================== INVOKE MessageBox, hMainWnd, ADDR szNoID, NULL, MB_OK ;====================== ; Jump and return out ;====================== JMP err .ENDIF ;========================= ; Setup the parent "chunk" ; info structure ;========================= MOV parent.ckid, 0 MOV parent.ckSize, 0 MOV parent.fccType, 0 MOV parent.dwDataOffset, 0 MOV parent.dwFlags, 0 ;============================ ; Do the same with the child ;============================ MOV child.ckid, 0 MOV child.ckSize, 0 MOV child.fccType, 0 MOV child.dwDataOffset, 0 MOV child.dwFlags, 0 ;====================================== ; Now open the WAV file using the MMIO ; API function ;====================================== INVOKE mmioOpen, fname_ptr, NULL, (MMIO_READ OR MMIO_ALLOCBUF) MOV hwav, EAX ;==================================== ; Make sure the call was successful ;==================================== .IF EAX == NULL ;====================== ; Give err msg ;====================== INVOKE MessageBox, hMainWnd, ADDR szNoOp, NULL, MB_OK ;====================== ; Jump and return out ;====================== JMP err .ENDIF ;=============================== ; Set the type in the parent ;=============================== mmioFOURCC 'W', 'A', 'V', 'E' MOV parent.fccType, EAX ;================================= ; Descend into the RIFF ;================================= INVOKE mmioDescend, hwav, ADDR parent, NULL, MMIO_FINDRIFF .IF EAX != NULL ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;============================ ; Set the child id to format ;============================ mmioFOURCC 'f', 'm', 't', ' ' MOV child.ckid, EAX ;================================= ; Descend into the WAVE format ;================================= INVOKE mmioDescend, hwav, ADDR child, ADDR parent, NULL .IF EAX != NULL ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;================================= ; Now read the wave format info in ;================================= INVOKE mmioRead, hwav, ADDR wfmtx, sizeof(WAVEFORMATEX) MOV EBX, sizeof(WAVEFORMATEX) .IF EAX != EBX ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;================================= ; Make sure the data format is PCM ;================================= .IF wfmtx.wFormatTag != WAVE_FORMAT_PCM ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;================================= ; Ascend up one level ;================================= INVOKE mmioAscend, hwav, ADDR child, NULL .IF EAX != NULL ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;============================ ; Set the child id to data ;============================ mmioFOURCC 'd', 'a', 't', 'a' MOV child.ckid, EAX ;================================= ; Descend into the data chunk ;================================= INVOKE mmioDescend, hwav, ADDR child, ADDR parent, MMIO_FINDCHUNK .IF EAX != NULL ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;=================================== ; Now allocate memory for the sound ;=================================== INVOKE GlobalAlloc, GMEM_FIXED, child.ckSize MOV snd_buffer, EAX .IF EAX == NULL ;=================== ; Close the file ;=================== INVOKE mmioClose, hwav, NULL ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;======================================= ; Read the WAV data and close the file ;======================================= INVOKE mmioRead, hwav, snd_buffer, child.ckSize INVOKE mmioClose, hwav, 0 ;================================ ; Set the rate, size, & state ;================================ MOV EAX, sizeof(pcm_sound) MOV ECX, sound_id MUL ECX MOV ECX, EAX MOV EAX, wfmtx.nSamplesPerSec MOV sound_fx[ECX].rate, EAX MOV EAX, child.ckSize MOV sound_fx[ECX].lsize, EAX MOV sound_fx[ECX].state, SOUND_LOADED ;========================== ; Clear the format struc ;========================== INVOKE RtlFillMemory, ADDR pcmwf, sizeof(WAVEFORMATEX), 0 ;============================= ; Now fill our desired fields ;============================= MOV pcmwf.wFormatTag, WAVE_FORMAT_PCM MOV AX, wfmtx.nChannels MOV pcmwf.nChannels, AX MOV EAX, wfmtx.nSamplesPerSec MOV pcmwf.nSamplesPerSec, EAX XOR EAX, EAX MOV AX, wfmtx.nBlockAlign MOV pcmwf.nBlockAlign, AX MOV EAX, pcmwf.nSamplesPerSec XOR ECX, ECX MOV CX, pcmwf.nBlockAlign MUL ECX MOV pcmwf.nAvgBytesPerSec, EAX MOV AX, wfmtx.wBitsPerSample MOV pcmwf.wBitsPerSample, AX MOV pcmwf.cbSize, 0 ;================================= ; Prepare to create the DS buffer ;================================= DSINITSTRUCT ADDR dsbd, sizeof(DSBUFFERDESC) MOV dsbd.dwSize, sizeof(DSBUFFERDESC) ; Put other flags you want to play with in here such ; as CTRL_PAN, CTRL_FREQ, etc or pass them in MOV EAX, flags MOV dsbd.dwFlags, EAX OR dsbd.dwFlags, DSBCAPS_STATIC OR DSBCAPS_CTRLVOLUME \ OR DSBCAPS_LOCSOFTWARE MOV EBX, child.ckSize MOV EAX, OFFSET pcmwf MOV dsbd.dwBufferBytes, EBX MOV dsbd.lpwfxFormat, EAX ;================================= ; Create the sound buffer ;================================= MOV EAX, sizeof(pcm_sound) MOV ECX, sound_id MUL ECX LEA ECX, sound_fx[EAX].dsbuffer DSINVOKE CreateSoundBuffer, lpds, ADDR dsbd, ECX, NULL .IF EAX != DS_OK ;=================== ; Free the buffer ;=================== INVOKE GlobalFree, snd_buffer ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;================================== ; Lock the buffer so we can copy ; our sound data into it ;================================== MOV EAX, sizeof(pcm_sound) MOV ECX, sound_id MUL ECX MOV ECX, EAX DSBINVOKE mLock, sound_fx[ECX].dsbuffer, NULL, child.ckSize, ADDR audio_ptr_1,\ ADDR audio_length_1, ADDR audio_ptr_2, ADDR audio_length_2,\ DSBLOCK_FROMWRITECURSOR .IF EAX != DS_OK ;=================== ; Free the buffer ;=================== INVOKE GlobalFree, snd_buffer ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;============================== ; Copy first section of buffer ; then the second section ;============================== ; First buffer MOV ESI, snd_buffer MOV EDI, audio_ptr_1 MOV ECX, audio_length_1 AND ECX, 3 REP movsb MOV ECX, audio_length_1 SHR ECX, 2 REP movsd ; Second buffer MOV ESI, snd_buffer ADD ESI, audio_length_1 MOV EDI, audio_ptr_2 MOV ECX, audio_length_2 AND ECX, 3 REP movsd MOV ECX, audio_length_2 SHR ECX, 2 REP movsd ;============================== ; Unlock the buffer ;============================== MOV EAX, sizeof(pcm_sound) MOV ECX, sound_id MUL ECX MOV ECX, EAX DSBINVOKE Unlock, sound_fx[ECX].dsbuffer, audio_ptr_1, audio_length_1,\ audio_ptr_2, audio_length_2 .IF EAX != DS_OK ;=================== ; Free the buffer ;=================== INVOKE GlobalFree, snd_buffer ;===================== ; Jump and return out ;===================== JMP err .ENDIF ;=================== ; Free the buffer ;=================== INVOKE GlobalFree, snd_buffer done: ;=================== ; We completed ;=================== return sound_id err: ;=================== ; We didn't make it ;=================== return -1 Load_WAV ENDP ;######################################################################## ; END Load_WAV ;########################################################################The code is fairly simple it is just long. I will skim over the first few parts since they are just setting things up. The code starts out by finding the first available sound in our array. If it finds none, it issues an error and then returns to the caller. Once we have a valid sound id to hold our new sound we can start playing with the file, and setting the structures up for use.

We start by initializing the structures to 0 to make sure we don't have any left over remnants from previous loads. Once that is complete, we get to open up our WAV file using the multimedia I/O functions found in the Winmm.lib file.

Once the file is opened successfully we descend into the internals of the file. This merely takes us to relevant sections in the header so we can setup our structures for loading. A few sections need to be traversed and then we are ready to get the wave format information.

With our wave information intact we can ascend up the file and then down into our data chunk. Once "inside" we allocate memory for our data and then we grab it with the mmioRead() function. Finally, we can close the file ... and the ugly part is over.

Then, we do some more setting of values in structures and clearing things out. All stuff you have seen before, so it should look familiar by now. We are getting ready to create the sound buffer with all these assignments.

Normally I would just say "here is where we create the sound buffer" ... but there is something very weird going on here. If you notice we aren't able to pass in the sound buffer parameter. The reason is that we need to pass in the address. So, the line right before the call uses the LEA (Load Effective Address) instruction to obtain the address of our variable. The reason for this is just a quirk on the INVOKE syntax and something we need to workaround. By loading the address before the call, we can place it in the modified invoke statement without troubles. Another small thing you might want to jot down is that we can't use EAX to hold that value. The reason is that the macro I defined, DSBINVOKE, uses EAX when manipulating things ... this is the only reason, normally you could use it without trouble. Never forget, macros are placed directly into your code ... even if they don't make sense.

Once we have our buffer created we lock the buffer, copy the memory over to the new buffer locations, and then unlock the buffer. The only thing that might seem a little confusing is the method I have chosen to copy the sound data over. Remember how we copied using DWORD's in our Draw_Bitmap() routine? If not, go back and refresh your memory because it is very important. For those of you that do recall ... that is almost exactly what we are doing here.

The only thing that is different, is we have to make sure that our data is on a 4-byte boundary. We do this by AND'ing the length with 3 ... this is the same as Number mod 4 ... then moving byte by byte until we hit zero. At that point we are on a 4-byte boundary and can move DWORD's once again.

It is the same basic concept that we have seen before only this time we have to do the checking for alignment ourselves since the data is not guaranteed to be on even 4-byte boundaries.

Once all of that is out of the way we can free the buffer, along with our headache, and we are finished. The sound is now loaded, in the buffer, and we can return the sound's ID to the caller so that they can play the sound later on. One thing I do want to mention is that this WAV loader should be able to load WAV files of any format (8-bit, 16-bit, stereo, mono, etc.). Yet, only 8-bit sounds can be utilized in the DirectSound buffers. The reason is we only set the cooperative level to normal, instead of exclusive. So, if you want to load in, and play, 16-bit sounds you will need to alter the DS_Init() procedure, and put DirectSound into exclusive mode.

With that, our sound module is complete. It is definitely not "state-of-the-art" ... but hey, it works and it removes a lot of the DirectX burden that would normally be placed on us.

Luckily though, we get to talk about something a lot more fun: Screen Transitions.

[size="5"] Screen Transitions

Screen Transitions are things that are usually fun to write. Of course, most anything would be fun after playing with DirectSound. The screen transition is often one of the most important things in a game. If you have a lot of places where the view/screen completely changes, then a transition is typically needed in order to smooth things out. You do not want the user to just be "jarred" to the next scene. To the user, a transition is like riding in a Lexus, while having none is like riding an old Pan-head [lessthan][lessthan] inside motorcycle joke >>.

I have taken an interesting approach with the screen transitions in this game. I decided there would be one main interface function. This function, intelligently called Transition(), is responsible for selecting a screen transition, at random, and calling it. This provides some break from the monotony of calling the same one over and over again. Of course, I have only provided one simple transition ( with 2 options ), it is your job to write more. All transitions require the surface you want to transition "from" on the primary buffer, and the surface you want to transition "to" on the back buffer.

Here is the code for the interface function:

;######################################################################## ; Transition Procedure ;######################################################################## Transition PROC ;======================================================= ; This function will call one of the our transitions ; based on a random number. All transitions require ; the primary buffer to be the surface that you want ; to transition from and the back buffer to be the ; surface you want to transition to. Both need to ; be unlocked. ;======================================================= ;============================= ; Get a random number ;============================= INVOKE Get_Time ;============================= ; Mod the result with 2 ;============================= AND EAX, 1 ;============================= ; Select the transition based ; on our number ;============================= .IF EAX == 0 ;========================== ; Perform a Horizontal Wipe ;========================== INVOKE Wipe_Trans, 6, WIPE_HORZ ;========================= ; Universal error check ;========================= .IF EAX == FALSE JMP err .ENDIF .ELSEIF EAX == 1 ;========================== ; Perform a Vertical Wipe ;========================== INVOKE Wipe_Trans, 4, WIPE_VERT ;========================= ; Universal error check ;========================= .IF EAX == FALSE JMP err .ENDIF .ENDIF done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Transition ENDP ;######################################################################## ; END Transition ;########################################################################The Transition() function grabs a random number by using the same method as our random shape generator, obtaining the time. This is not the optimum method, and we will be replacing it with a true random number generator later on. But, for now, it will have to do. The proper transition is then made based on the time, you can play with the parameters if you wish. I just selected a couple that didn't seem to take away too much of the screen each iteration.

That is all that is there for the management function. It just keeps things random. You can still call a transition directly, I just thought it was more interesting to do it like this. Besides, on a large project, after 4-6 months of looking at the same transitions, you would probably be insane.

Now, we can look at the actual screen transition: Wipe_Trans(). This routine allows us to perform either a vertical (top to bottom) or horizontal (left to right) transition taking away a width that is passed in each time. So, have a look at the code before we continue.

;######################################################################## ; Wipe_Trans Procedure ;######################################################################## Wipe_Trans PROC strip_width:DWORD, direction:DWORD ;======================================================= ; This function will perform either a horizontal or ; a vertical wipe depending on what you pass in for the ; direction paramter. The width of each step is ; determined by the width that you pass in to it. ;======================================================= ;========================================= ; Local Variables ;========================================= LOCAL StartTime :DWORD ;======================================== ; Setup the source rectangle and the ; destination rectangle ; ; For the first iteration, the strip may ; not be the height passed in. This is to ; make sure we are on an even boundary ; during the loop below ;======================================== .IF direction == WIPE_HORZ MOV SrcRect.top, 0 MOV SrcRect.left, 0 MOV EAX, app_width MOV ECX, strip_width XOR EDX, EDX DIV ECX .IF EDX == 0 MOV EDX, strip_width .ENDIF MOV EBX, app_height MOV SrcRect.bottom, EBX MOV SrcRect.right, EDX MOV DestRect.top, 0 MOV DestRect.left, 0 MOV DestRect.bottom, EBX MOV DestRect.right, EDX .ELSEIF direction == WIPE_VERT MOV SrcRect.top, 0 MOV SrcRect.left, 0 MOV EAX, app_height MOV ECX, strip_width XOR EDX, EDX DIV ECX MOV EAX, app_width .IF EDX == 0 MOV EDX, strip_width .ENDIF MOV SrcRect.bottom, EDX MOV SrcRect.right, EAX MOV DestRect.top, 0 MOV DestRect.left, 0 MOV DestRect.bottom, EDX MOV DestRect.right, EAX .ELSE ;================== ; Invalid direction ;================== JMP err .ENDIF ;================================ ; Get the starting time ;================================ INVOKE Start_Time, ADDR StartTime ;================================ ; Blit the strip onto the screen ;================================ DDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\ lpddsback, ADDR DestRect, DDBLTFAST_WAIT ;=============================== ; Make sure we succeeded ;=============================== .IF EAX != DD_OK JMP err .ENDIF ;=================================================== ; Now adjust the distance between the left & ; right, or top and bottom, so that the top, or ; left, corner is where the right hand side was ; at ... and the bottom, or right, is strip_width ; away from the opposite corner. ;=================================================== MOV EAX, strip_width .IF direction == WIPE_HORZ MOV EBX, SrcRect.right MOV SrcRect.left, EBX MOV DestRect.left, EBX ADD EBX, EAX MOV DestRect.right, EBX MOV SrcRect.right, EBX .ELSEIF direction == WIPE_VERT MOV EBX, SrcRect.bottom MOV SrcRect.top, EBX MOV DestRect.top, EBX ADD EBX, EAX MOV DestRect.bottom, EBX MOV SrcRect.bottom, EBX .ENDIF ;=================================== ; Wait to synchronize the time ;=================================== INVOKE Wait_Time, StartTime, TRANS_TIME ;===================================== ; Drop into a while loop and blit all ; of the strips synching to our ; desired transition rate ;===================================== .WHILE TRUE ;================================ ; Get the starting time ;================================ INVOKE Start_Time, ADDR StartTime ;================================ ; Blit the strip onto the screen ;================================ DDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\ lpddsback, ADDR DestRect, DDBLTFAST_WAIT ;=============================== ; Make sure we succeeded ;=============================== .IF EAX != DD_OK JMP err .ENDIF ;================================== ; Have we reached our extents yet ;================================== MOV EAX, SrcRect.bottom MOV EBX, app_height MOV ECX, SrcRect.right MOV EDX, app_width .IF EAX == EBX && ECX == EDX ;====================== ; Trans complete ;====================== .BREAK .ELSE ;====================== ; Adjust by the strip ;====================== MOV EAX, strip_width .IF direction == WIPE_HORZ ADD SrcRect.left, EAX ADD SrcRect.right, EAX ADD DestRect.left, EAX ADD DestRect.right, EAX .ELSEIF direction == WIPE_VERT ADD SrcRect.top, EAX ADD SrcRect.bottom, EAX ADD DestRect.top, EAX ADD DestRect.bottom, EAX .ENDIF .ENDIF ;=================================== ; Wait to synchronize the time ;=================================== INVOKE Wait_Time, StartTime, TRANS_TIME .ENDW done: ;=================== ; We completed ;=================== return TRUE err: ;=================== ; We didn't make it ;=================== return FALSE Wipe_Trans ENDP ;######################################################################## ; END Wipe_Trans ;######################################################################## Notice, the first thing we do is setup the source and destination rectangles. We are going to be working with "strips" of the bitmap. So, I am going to walk you through exactly what happens when the routine is called.

Pretend the user passed in a 7 for the "strip_width" parameter and they want a horizontal transition. The first section finds out if the strip's width can go evenly into the screen width. If the strip can go in evenly, then it sets the length to be equal to the width. However, if it can't, then the remainder is placed in the width. The reason we place the remainder in, is that the strip is going to have that little strip left over when we finish. Example: with a 7 and a screen width of 640 you will have 91 sections of 7 and a section of 3 left over. So, for the first strip we would store a 3 for the width. From here on note: You would do the exact same thing, except for the height/top/bottom, if you were doing a vertical wipe.

Next, we blit that small 3 pixel strip over from the back buffer onto the primary buffer. With that out of the way we can get setup to do blits with a 7-pixel width. The way we setup is by moving the right-hand side of the rectangle over to the left-hand side. Then, we add the strip_width, in this case 7, to the left-hand side to obtain the new right-hand side. So, for our example, the left coordinate of the rectangles would now have a 3, and the right coordinate would now have a 10. We need this adjustment since our loop is only going to work with 7-pixel strips in the bitmap, instead of an increasing portion of the bitmap.

We are now ready to delve into our loop. The first thing we do, aside from getting the starting time, is blit the current strip (this is why we had to setup the rectangles out of the loop). Then, we check the right hand side and bottom of our source rectangle is still inside the limits of our screen. If it has met the extents, then we break from the loop since we are finished. If we haven't yet reached the edges, then we adjust the rectangles. To adjust the rectangles, we add the strip_width to both the left and right of our source and destination rectangles. By adding to both sides we are able to blit in strips of 7-pixels. But, if we only added to the right-hand side we would blit in pixels of 7, 14, 21, etc. Which, needless to say, is much, much slower than the way we are doing it. Finally, we synchronize the time to our desired rate and keep doing the loop until we are finished.

There isn't very much to the routine, but it should give you a starting point in making screen transitions. Here are some suggestions in case you are lacking in creativity. Make a modified wipe that would have a bunch of strips at intervals grow to meet each other, like something you would see with a pair of blinds in your house. Design a transition that zooms in to a single pixel, then zooms out to the new picture. Create a circular wipe, or even a spiral one. There are many good articles out there on demo effects and I suggest reading some of them if you find this stuff interesting. Finally, if you are really desperate for an idea, just go and play a game and see how their transitions work. Mimicry is one of the first steps in learning.

At any rate, everything in our modules is complete. We now have everything that we need to pretty up the game. So, in the next section, we will tie everything into that nice little bow, just as we always do.

[size="5"]Putting More Pieces Together

The title to this section is really accurate. Most programming, at least in some way, is like a jigsaw puzzle. It is about combining pieces in a manner that works best. Often times, you will obtain a completely different result just be re-ordering some of the steps. In this sense, programming is intellectually stimulating. There are so many millions of ways to accomplish any given task. Keep that in mind while reviewing the code I provide. It isn't written in blood anyplace that you have to do things a certain way -- at least, I don't think it is.

The module, we are going to look at for the changes is the Menu module. The reason we are using this module is that it makes use of all of our new features, which makes it perfect for use as an example.

You had better take a look at the code for the new module before we go any further.

;########################################################################### ;########################################################################### ; ABOUT Menu: ; ; This code module contains all of the functions that relate to ; the menu that we use. ; ; There are routines for each menu we will have. One for the main ; menu and one for the load/save menu stuff. ; ; NOTE: We could have combined these two functions into one generic ; function that used parameters to determine the bahavior. But, by coding ; it explicitly we get a better idea for what is going on in the code. ; ;########################################################################### ;########################################################################### ;########################################################################### ;########################################################################### ; THE COMPILER OPTIONS ;########################################################################### ;########################################################################### .386 .MODEL flat, stdcall OPTION CASEMAP :none ; case sensitive ;########################################################################### ;########################################################################### ; THE INCLUDES SECTION ;########################################################################### ;########################################################################### ;================================================ ; These are the Inlcude files for Window stuff ;================================================ INCLUDE \masm32\include\windows.inc INCLUDE \masm32\include\comctl32.inc INCLUDE \masm32\include\comdlg32.inc INCLUDE \masm32\include\shell32.inc INCLUDE \masm32\include\user32.inc INCLUDE \masm32\include\kernel32.inc INCLUDE \masm32\include\gdi32.inc ;=============================================== ; The Lib's for those included files ;================================================ INCLUDELIB \masm32\lib\comctl32.lib INCLUDELIB \masm32\lib\comdlg32.lib INCLUDELIB \masm32\lib\shell32.lib INCLUDELIB \masm32\lib\gdi32.lib INCLUDELIB \masm32\lib\user32.lib INCLUDELIB \masm32\lib\kernel32.lib ;==================================== ; The Direct Draw include file ;==================================== INCLUDE Includes\DDraw.inc ;==================================== ; The Direct Input include file ;==================================== INCLUDE Includes\DInput.inc ;==================================== ; The Direct Sound include file ;==================================== INCLUDE Includes\DSound.inc ;================================================= ; Include the file that has our protos ;================================================= INCLUDE Protos.inc ;########################################################################### ;########################################################################### ; LOCAL MACROS ;########################################################################### ;########################################################################### m2m MACRO M1, M2 PUSH M2 POP M1 ENDM return MACRO arg MOV EAX, arg RET ENDM ;################################################################################# ;################################################################################# ; Variables we want to use in other modules ;################################################################################# ;################################################################################# ;################################################################################# ;################################################################################# ; External variables ;################################################################################# ;################################################################################# ;================================= ; The DirectDraw stuff ;================================= EXTERN lpddsprimary :LPDIRECTDRAWSURFACE4 EXTERN lpddsback :LPDIRECTDRAWSURFACE4 ;========================================= ; The Input Device state variables ;========================================= EXTERN keyboard_state :BYTE ;################################################################################# ;################################################################################# ; BEGIN INITIALIZED DATA ;################################################################################# ;################################################################################# .DATA ;=============================== ; Strings for the bitmaps ;=============================== szMainMenu DB "Art\Menu.sfp",0 szFileMenu DB "Art\FileMenu.sfp",0 ;================================ ; Our very cool menu sound ;================================ szMenuSnd DB "Sound\Background.wav",0 ;=============================== ; PTR to the BMP's ;=============================== ptr_MAIN_MENU DD 0 ptr_FILE_MENU DD 0 ;=============================== ; ID for the Menu sound ;=============================== Menu_ID DD 0 ;====================================== ; A value to hold lPitch when locking ;====================================== lPitch DD 0 ;======================================== ; Let's us know if we need to transition ;======================================== first_time DD 0 ;################################################################################# ;################################################################################# ; BEGIN CONSTANTS ;################################################################################# ;################################################################################# ;################################################################################# ;################################################################################# ; BEGIN EQUATES ;################################################################################# ;################################################################################# ;================= ;Utility Equates ;================= FALSE EQU 0 TRUE EQU 1 ;================= ; The Screen BPP ;================= screen_bpp EQU 16 ;================= ; The Menu Codes ;================= ; Generic MENU_ERROR EQU 0h MENU_NOTHING EQU 1h ; Main Menu MENU_NEW EQU 2h MENU_FILES EQU 3h MENU_GAME EQU 4h MENU_EXIT EQU 5h ; File Menu MENU_LOAD EQU 6h MENU_SAVE EQU 7h MENU_MAIN EQU 8h ;################################################################################# ;################################################################################# ; BEGIN THE CODE SECTION ;################################################################################# ;################################################################################# .CODE ;######################################################################## ; Init_Menu Procedure ;######################################################################## Init_Menu PROC ;=========================================================== ; This function will initialize our menu systems ;=========================================================== ;================================= ; Local Variables ;================================= ;====================================== ; Read in the bitmap and create buffer ;====================================== INVOKE Create_From_SFP, ADDR ptr_MAIN_MENU, ADDR szMainMenu, screen_bpp ;==================================== ; Test for an error ;==================================== .IF EAX == FALSE ;======================== ; We failed so leave ;======================== JMP err .ENDIF ;====================================== ; Read in the bitmap and create buffer ;====================================== INVOKE Create_From_SFP, ADDR ptr_FILE_MENU, ADDR szFileMenu, screen_bpp ;==================================== ; Test for an error ;==================================== .IF EAX == FALSE ;=
 
 0   Report Article 
 Sign in to follow this   Followers 0 Go to articles General and Gameplay Programming 
 User Feedback 0 Comments 0 Reviews There are no comments to display. Create an account or sign in to comment You need to be a member in order to leave a comment Create an account Sign up for a new account in our community. It's easy! Register a new account Sign in Already have an account? Sign in here. Sign In Now 
•  
 
 Advertisement 
 Advertisement Latest Featured Articles 0 Effect: Area Light Shadows Part 1: PCSS By Vilem Otte Monday at 03:59 AM 0 Color Palettes By gdarchive September 10 1 Ray Tracing - Part 1 By Bacterius August 8 1 Contact-hardening Soft Shadows Made Fast By maxest September 3 3 A Brief Introduction to Lerp By mattdesl August 21 Featured Blogs Summer Baseball Challenge 2018 - Part 2 (Game Graphics) By Rutin in Rutin's Dev Blog    2 Warfront Infinite Dev Blog #18: Decals, New Camera System and Turret Models By EddieK in Warfront Infinite Dev Blog    4 Leadwerks Software to Provide VR Services to NASA By Josh Klint in Leadwerks Developer Blog    4 cross platform development: IDE or do it yourself By GamerX1221 in GamerX1221's Blog    0 Update 1.2 Submitted to Apple – In memory of Sarah Curtis By SOS-CC in SOS-CC Mobile Game Development    8 Popular Now 33 Semi-complete Newbie By Ryan WoodStarted Yesterday at 12:43 AM 13 why we use matrix and only multiplication as operator in transforms? By moeen kStarted Monday at 12:11 PM 10 How to manage inventory system if there are too many classes? By MarkNefedovStarted Monday at 11:37 AM 11 C++/WinRT By matt77hiasStarted Sunday at 05:13 PM 9 plane sprite By phil67rpgStarted Sunday at 02:13 AM Advertisement GameDev.net GameDev.net Articles GameDev.net Event Coverage GameDev.net Forums GameDev.net Blogs GameDev.net Gallery GameDev.net News GameDev.net Projects GDNet Chat All Activity Search In Everywhere This Category This Article More options... Find results that contain... All of my search term words Any of my search term words Find results in... Content titles and body Content titles only Home Articles Programming General and Gameplay Programming Win32 Assembly Part 5 
 
 
 × Existing user? Sign In Sign Up Browse Back Articles & Tutorials Back All Categories Audio Business Game Design Industry Programming Visual Arts Columns Back GameDev Unboxed Event Coverage Back All Events Game Developers Conference Power Up Digital Games Conference GameDev.Market Links News Podcasts Back All Podcasts Game Dev Loadout Archive Community Back Beginners Back Beginners Group Beginners Forum Beginners Resources Blogs Calendar Chat Forums Back All Forums Audio Business Game Design Programming Visual Arts Community GameDev Challenges Affiliates Topical Workshops Gallery Groups Back For Beginners GameDev Challenges All Groups Projects Back All Projects Games Game Assets Game Mods Developer Tools Store Forums Back All Forums For Beginners Audio Back Music and Sound FX Games Career Development Business Back Games Career Development Production and Management Games Business and Law Game Design Back Game Design and Theory Writing for Games Programming Back Artificial Intelligence Engines and Middleware General and Gameplay Programming Graphics and GPU Programming Math and Physics Networking and Multiplayer Visual Arts Back 2D and 3D Art Critique and Feedback Community Back GameDev Challenges GDNet Lounge GDNet Comments, Suggestions, and Ideas Coding Horrors Your Announcements Hobby Project Classifieds Indie Showcase Affiliates Back NeHe Productions AngelCode Topical Workshops Careers Back Contractors Hobby Projects Game Jobs Back Browse on GameDev.Jobs Post a Job Members Back Subscriptions Chat Guidelines Leaderboard Online Users Awards Search Back All Activity My Activity Streams Back Latest Topics Featured Blogs Search var ipsDebug=false;var CKEDITOR_BASEPATH='//www.gamedev.net/applications/core/interface/ckeditor/ckeditor/';var ipsSettings={cookie_path:"/",cookie_prefix:"ips4_",cookie_ssl:true,upload_imgURL:"",message_imgURL:"",notification_imgURL:"",baseURL:"//www.gamedev.net/",jsURL:"//www.gamedev.net/applications/core/interface/js/js.php",csrfKey:"329519fe11bf2c9dce8fbdc019259946",antiCache:"14de000c45",disableNotificationSounds:false,useCompiledFiles:true,links_external:true,memberID:0,analyticsProvider:"ga",viewProfiles:true,mapProvider:'google',mapApiKey:"AIzaSyAeT7tk3vnWWmbgVISkLpbhkQvekG19rHM",}; ips.setSetting('date_format',jQuery.parseJSON('"mm\/dd\/yy"'));ips.setSetting('date_first_day',jQuery.parseJSON('0'));ips.setSetting('remote_image_proxy',jQuery.parseJSON('1'));ips.setSetting('ipb_url_filter_option',jQuery.parseJSON('"none"'));ips.setSetting('url_filter_any_action',jQuery.parseJSON('"allow"'));ips.setSetting('bypass_profanity',jQuery.parseJSON('0'));ips.setSetting('emoji_style',jQuery.parseJSON('"native"'));ips.setSetting('emoji_shortcodes',jQuery.parseJSON('"1"'));ips.setSetting('emoji_ascii',jQuery.parseJSON('"1"'));ips.setSetting('emoji_cache',jQuery.parseJSON('"1"'));ips.setSetting('quickSearchDefault',jQuery.parseJSON('"all"'));ips.setSetting('quickSearchMinimum',jQuery.parseJSON('3'));ips.setSetting('quickSearchShowAdv',jQuery.parseJSON('true'));ips.setSetting('quickSearchIn',jQuery.parseJSON('"title"')); { "@context": "http://schema.org", "@type": "Article", "url": "https://www.gamedev.net/articles/programming/general-and-gameplay-programming/win32-assembly-part-5-r909/", "discussionUrl": "https://www.gamedev.net/articles/programming/general-and-gameplay-programming/win32-assembly-part-5-r909/", "mainEntityOfPage": "https://www.gamedev.net/articles/programming/general-and-gameplay-programming/win32-assembly-part-5-r909/", "name": "Win32 Assembly Part 5", "headline": "Win32 Assembly Part 5", "text": "(Editor\u0027s Note - this article requires additional formatting work and is incomplete)[size=\"5\"]Where Did We Leave Off?\nUntil last issue SPACE-TRIS wasn\u0027t even a game, it was merely an exercise in coding modules. Well, now we have a game that is working, it is just ugly. Sadly enough though, we are back to coding modules today. The good news is these modules will pretty things up by a large margin.\n The modules that we will be covering today are Direct Sound (YUCK!) and screen transitions (YA!). The Direct Sound module isn\u0027t going to be anything to complex, just a simple sound effects manager that allows you to play, stop, delete, add, or set variables on the sounds themselves. The screen transitions module is going to consist of one main function that gets called and then a transition is selected at random to perform.\n When we last saw each other, the game also needed a way to check for an \"out-of-bounds\" occurrence while rotating pieces. You guys were working on it, like I told you too, right? Yeah, I\u0027m sure. Anyway, I will present my quick hack of a solution in a few moments. But first, I want to say that I am going to be glossing over many of the things we have already covered in past issues. For instance, in the Direct Sound module you guys have all seen how to check for an error, so I won\u0027t be explaining that again. This means, if you are new to the series, do yourself a favor and start at the beginning. This isn\u0027t your favorite TV series where you can just pop by, on any old day, and know what is going on. We are going to be moving at warp speed through a lot of things. All I am really going to provide now is an overview of the techniques I use ... it is up to you to understand them.\n With that said, let us get right down to business with that solution to the rotation problem.\n[size=\"5\"]Rotation Solution\nThe solution to our rotation problem was fairly straightforward. Basically, we already had all of the routines that we needed. What we had to know was if, at any given frame, the current piece would be out of bounds -- which MoveShape() does for us. So, the fix we have is a simple one. We can just call that routine with the frame it \"would\" be on next, right? Wrong. That is what I tried at first because it makes sense. But, there is a hidden problem with that method.\n The problem lies in that fact that any piece could already be out of bounds when you adjust the frame. Move_Shape() only tells you if you can move the shape to the left or right, and does so if it can. If we fake our next frame for that call it may succeed because it is already out of bounds by one column if it was on the edges previously. This means we need a way to prevent it from ever being out of bounds to begin with.\n The solution is to move it in towards the center by one column beforehand. Then, when we make the call, the shape is guaranteed to be on the edge, or in the middle, never outside the grid. The way we decide if we could go to the next frame is by seeing if the X coordinate sent before we made the call matches the one we have after the call. If it does, then that means the shape can be rotated ... if they don\u0027t match then the shape can not be rotated.\n This method has the advantage of eliminating the need for any other code. The Move_Shape() function will not succeed if something else is blocking its move. Therefore, we do not need to do any other tests on the shape to see if other blocks are in the way. Just that simple call based on the next frame. So, we not only solved the problem ... but also made the routine shorter in the process.\n The new Rotate_Shape();########################################################################\n; Rotate_Shape Procedure\n;########################################################################\nRotate_Shape\tPROC\t\n\t;=======================================================\n\t; This function will rotate the current shape it tests\n\t; to make sure there are no blocks already in the place\n\t; where it would rotate. \n\t;=======================================================\n\t;================================\n\t; Local Variables\n\t;================================\n\tLOCAL\tIndex:\t\tDWORD\n\tLOCAL\tCurBlock:\tDWORD\n\tLOCAL\tSpot:\t\tBYTE\n\t;=================================\n\t; Make sure they are low enough\n\t;=================================\n\t.IF CurShapeY \u0026gt; 21\n\t\tJMP\terr\n\t.ENDIF\n\t;================================\n\t; Are they at the last frame?\n\t;================================\n\t.IF CurShapeFrame == 3\n\t\t;=====================================\n\t\t; Yep ... make sure they can rotate\n\t\t;=====================================\n\t\t;========================================\n\t\t; We will start by seeing which half of \n\t\t; the grid they are currently on that way\n\t\t; we know we much too move the shape \n\t\t;=========================================\n\t\t.IF CurShapeX \n\t\t\t;===========================\n\t\t\t; They are on the left half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord right and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tINC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tMOV\tCurShapeFrame, 0\n\t\t\t;=============================\n\t\t\t; Try to move them to the left\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_LEFT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tMOV\tCurShapeFrame, 3\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ELSE\n\t\t\t;===========================\n\t\t\t; They are on the right half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord left and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tDEC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tMOV\tCurShapeFrame, 0\n\t\t\t;=============================\n\t\t\t; Try \u0026amp; move them to the right\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_RIGHT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tMOV\tCurShapeFrame, 3\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ENDIF\n\t.ELSE\n\t\t;=====================================\n\t\t; NO ... make sure they can rotate\n\t\t;=====================================\n\t\t;========================================\n\t\t; We will start by seeing which half of \n\t\t; the grid they are currently on that way\n\t\t; we know we much too move the shape \n\t\t;=========================================\n\t\t.IF CurShapeX \n\t\t\t;===========================\n\t\t\t; They are on the left half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord right and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tINC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tINC\tCurShapeFrame\n\t\t\t;=============================\n\t\t\t; Try to move them to the left\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_LEFT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tDEC\tCurShapeFrame\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ELSE\n\t\t\t;===========================\n\t\t\t; They are on the right half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord left and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tDEC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tINC\tCurShapeFrame\n\t\t\t;=============================\n\t\t\t; Try \u0026amp; move them to the right\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_RIGHT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tDEC\tCurShapeFrame\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ENDIF\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nRotate_Shape\tENDP\n;########################################################################\n; END Rotate_Shape\n;########################################################################\n[size=\"5\"]The Sound Module\nThe sound module for this game is pretty simple. It merely presents an interface to Load WAV files, play the sounds, delete them, and edit properties about them. However, there are a few tricky things to watch out for in the module.\n The first thing I want to illustrate is how to create an array of structures. Take a look at the following modified code snippet.;#################################################################################\n;#################################################################################\n; STRUCTURES\n;#################################################################################\n;#################################################################################\n\t;=============================\n\t; this holds a single sound\n\t;=============================\n\tpcm_sound\tSTRUCT \n\t\tdsbuffer\tDD 0\t; the ds buffer for the sound \n\t\tstate\t\tDD 0\t; state of the sound\n\t\trate\t\tDD 0\t; playback rate\n\t\tlsize\t\tDD 0\t; size of sound\n\tpcm_sound\tENDS\n\t;============================\n\t; max number of sounds in \n\t; the game at once \n\t;============================\n\tMAX_SOUNDS\tEQU\t16\n\t;=========================================\n\t; Our array of sound effects\n\t;=========================================\n\tsound_fx\tpcm_sound\tMAX_SOUNDS dup()You will notice that anytime we declare a structure we need to use angle brackets, or curly braces (not shown), for them. The numbers inside consist of the members of your structure and nothing more. Whatever you place there is what things get initialized to. Also, pay attention to how the structure is defined. It consists of normal variable declarations in between a couple of keywords and a tag to give it a name. \n Of special note, is that you must use another set of braces, or brackets, if you wish to have nested structures. The way we get an array with a structure is the same as any other variable. We use the number we want followed by the DUP ... then, in parenthesis, what you want the values initialized as.\n We are going to skip over the DS_Init() and DS_Shutdown() procedures, since they do the same exact things as the other DX counterparts. Instead let\u0027s take a peek at Play_Sound().;########################################################################\n; Play_Sound Procedure\n;########################################################################\nPlay_Sound PROC\tid:DWORD, flags:DWORD\n\t;=======================================================\n\t; This function will play the sound contained in the\n\t; id passed in along with the flags which can be either\n\t; NULL or DSBPLAY_LOOPING\n\t;=======================================================\n\t;==============================\n\t; Make sure this buffer exists\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\t.IF sound_fx[ECX].dsbuffer != NULL\n\t\t;=================================\n\t\t; We exists so reset the position\n\t\t; to the start of the sound\n\t\t;=================================\n\t\tPUSH\tECX\n\t\tDSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0\n\t\tPOP\tECX\n\t\t;======================\n\t\t; Did the call fail?\n\t\t;======================\n\t\t.IF EAX != DS_OK\n\t\t\t;=======================\n\t\t\t; Nope, didn\u0027t make it\n\t\t\t;=======================\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t\t;==============================\n\t\t; Now, we can play the sound\n\t\t;==============================\n\t\tDSBINVOKE Play, sound_fx[ECX].dsbuffer, 0, 0, flags\n\t\t;======================\n\t\t; Did the call fail?\n\t\t;======================\n\t\t.IF EAX != DS_OK\n\t\t\t;=======================\n\t\t\t; Nope, didn\u0027t make it\n\t\t\t;=======================\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ELSE\n\t\t;======================\n\t\t; No buffer for sound\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nPlay_Sound\tENDP\n;########################################################################\n; END Play_Sound\n;########################################################################This is the routine that we use to start a sound playing. You can pass it flags to alter how it sounds. So far as I know there are only 2 options for the flags. If you pass in NULL then it plays the sound once. If you pass in DSBPLAY_LOOPING it will play the sound repeatedly.\n The routine begins by checking that the sound has a valid buffer associated with it. If so, it sets the position of that sound to the beginning and then makes a call to begin playing it with whatever flags were passed in.\n The only thing worth illustrating in this routine is how the structure element is referenced. To begin with we obtain the size of the structure and multiply that by the id of the sound to give us our position in the array. Then, in order to reference a member you treat it just like you would in C/C++ ... StructName[position].member ... the important thing is not to forget to multiply the element by the size of the structure.\n The next 3 routines allow you to set the volume, frequency, and pan of a sound. There is nothing to these routines ... they are just wrappers for the Direct Sound function calls. However, if you want to use anything but Set_Sound_Volume() you need to tell Direct Sound that you want those enabled when you load the sound. This is done by passing in DSBCAPS_CTRL_PAN or DSBCAPS_CTRLFREQ respectively. If you do not specify these flags when you load your sound you will not be able to manipulate those items.\n The next two functions are for stopping sounds from playing. One will stop the specific sound you pass in and the other will stop all of the sounds from playing. Here is the code if you want to take a peek. Once again these are merely wrapper functions to shield you from the DX headache.;########################################################################\n; Stop_Sound Procedure\n;########################################################################\nStop_Sound PROC\tid:DWORD\n\t;=======================================================\n\t; This function will stop the passed in sound from\n\t; playing and will reset it\u0027s position\n\t;=======================================================\n\t;==============================\n\t; Make sure the sound exists\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\t.IF sound_fx[ECX].dsbuffer != NULL\n\t\t;==================================\n\t\t; We exist so stop the sound\n\t\t;==================================\n\t\tPUSH\tECX\n\t\tDSBINVOKE Stop, sound_fx[ECX].dsbuffer\n\t\tPOP\tECX\n\t\t;=================================\n\t\t; Now reset the sound position\n\t\t;=================================\n\t\tDSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nStop_Sound\tENDP\n;########################################################################\n; END Stop_Sound\n;########################################################################\n;########################################################################\n; Stop_All_Sounds Procedure\n;########################################################################\nStop_All_Sounds PROC\n\t;=======================================================\n\t; This function will stop all sounds from playing\n\t;=======================================================\n\t;==============================\n\t; Local Variables\n\t;==============================\n\tLOCAL\tindex\t:DWORD\n\t;==============================\n\t; Loop through all sounds\n\t;==============================\n\tMOV\tindex, 0\n\t.WHILE index \n\t\t;==================================\n\t\t; Stop this sound from playing\n\t\t;==================================\n\t\tINVOKE Stop_Sound, index\n\t\t;================\n\t\t; Inc the counter\n\t\t;================\n\t\tINC\tindex\n\t.ENDW\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nStop_All_Sounds\tENDP\n;########################################################################\n; END Stop_All_Sounds\n;########################################################################Delete_Sound() and Delete_All_Sounds() are remarkably similar to the sound stopping functions. The only difference is you make a different function call to DX. Delete_Sound() will call Stop_Sound() first, to make sure the sound isn\u0027t trying to be played while you are trying to delete it. The interesting thing about these two functions is that you do not personally have to release any of your sounds if you don\u0027t want to. During shutdown of Direct Sound all the sounds that you loaded will be deleted. However, if you have reached your maximum in sounds, and want to free one up, you will need to manually delete it.\n The next function Status_Sound() is yet another wrapper routine. It is used when you need to find out if a sound is still playing, or if it has stopped already. You will see this function put to use later on.\n There, 90% of that stupid module is out of the way. Now, we need to move on to the final 10% of that code ... the Load_WAV() procedure.\n[size=\"5\"]One Big Headache\nLoading file formats is always a pain to do. Loading a WAV file proves to be no different. It is a long function, that probably could have been broken up a little bit better, but for now it will have to do. It works and that is all I am concerned about. So, have a peek at it.;########################################################################\n; Load_WAV Procedure\n;########################################################################\nLoad_WAV\tPROC\tfname_ptr:DWORD, flags:DWORD\n\t;=======================================================\n\t; This function will load the passed in WAV file\n\t; it returns the id of the sound, or -1 if failed\n\t;=======================================================\n\t;==============================\n\t; Local Variables\n\t;==============================\n\tLOCAL\tsound_id\t:DWORD\n\tLOCAL\tindex\t\t:DWORD\n\t;=================================\n\t; Init the sound_id to -1\n\t;=================================\n\tMOV\tsound_id, -1\n\t;=================================\n\t; First we need to make sure there\n\t; is an open id for our new sound\n\t;=================================\n\tMOV\tindex, 0\n\t.WHILE index \n\t\t;========================\n\t\t; Is this sound empty??\n\t\t;========================\n\t\tMOV\tEAX, sizeof(pcm_sound)\n\t\tMOV\tECX, index\n\t\tMUL\tECX\n\t\tMOV\tECX, EAX\n\t\t.IF sound_fx[ECX].state == SOUND_NULL\n\t\t\t;===========================\n\t\t\t; We have found one, so set \n\t\t\t; the id and leave our loop\n\t\t\t;===========================\n\t\t\tMOV\tEAX, index\n\t\t\tMOV\tsound_id, EAX\n\t\t\t.BREAK\n\t\t.ENDIF\n\t\t;================\n\t\t; Inc the counter\n\t\t;================\n\t\tINC\tindex\n\t.ENDW\n\t;======================================\n\t; Make sure we have a valid id now\n\t;======================================\n\t.IF sound_id == -1\n\t\t;======================\n\t\t; Give err msg\n\t\t;======================\n\t\tINVOKE MessageBox, hMainWnd, ADDR szNoID, NULL, MB_OK\n\t\t;======================\n\t\t; Jump and return out\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\n\t;=========================\n\t; Setup the parent \"chunk\"\n\t; info structure\n\t;=========================\n\tMOV\tparent.ckid, 0\n\tMOV\tparent.ckSize, 0\n\tMOV\tparent.fccType, 0\n\tMOV\tparent.dwDataOffset, 0\n\tMOV\tparent.dwFlags, 0\n\t;============================\n\t; Do the same with the child\n\t;============================\n\tMOV\tchild.ckid, 0\n\tMOV\tchild.ckSize, 0\n\tMOV\tchild.fccType, 0\n\tMOV\tchild.dwDataOffset, 0\n\tMOV\tchild.dwFlags, 0\n\t;======================================\n\t; Now open the WAV file using the MMIO\n\t; API function\n\t;======================================\n\tINVOKE mmioOpen, fname_ptr, NULL, (MMIO_READ OR MMIO_ALLOCBUF)\n\tMOV\thwav, EAX\n\t;====================================\n\t; Make sure the call was successful\n\t;====================================\n\t.IF EAX == NULL\n\t\t;======================\n\t\t; Give err msg\n\t\t;======================\n\t\tINVOKE MessageBox, hMainWnd, ADDR szNoOp, NULL, MB_OK\n\t\t;======================\n\t\t; Jump and return out\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\n\t;===============================\n\t; Set the type in the parent\n\t;===============================\n\tmmioFOURCC \u0027W\u0027, \u0027A\u0027, \u0027V\u0027, \u0027E\u0027 \n\tMOV\tparent.fccType, EAX\n\t;=================================\n\t; Descend into the RIFF\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR parent, NULL, MMIO_FINDRIFF\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;============================\n\t; Set the child id to format\n\t;============================\n\tmmioFOURCC \u0027f\u0027, \u0027m\u0027, \u0027t\u0027, \u0027 \u0027 \n\tMOV\tchild.ckid, EAX\n\t;=================================\n\t; Descend into the WAVE format\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR child, ADDR parent, NULL\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Now read the wave format info in\n\t;=================================\n\tINVOKE mmioRead, hwav, ADDR wfmtx, sizeof(WAVEFORMATEX)\n\tMOV\tEBX, sizeof(WAVEFORMATEX)\n\t.IF EAX != EBX\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Make sure the data format is PCM\n\t;=================================\n\t.IF wfmtx.wFormatTag != WAVE_FORMAT_PCM\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Ascend up one level\n\t;=================================\n\tINVOKE mmioAscend, hwav, ADDR child, NULL\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;============================\n\t; Set the child id to data\n\t;============================\n\tmmioFOURCC \u0027d\u0027, \u0027a\u0027, \u0027t\u0027, \u0027a\u0027 \n\tMOV\tchild.ckid, EAX\n\t;=================================\n\t; Descend into the data chunk\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR child, ADDR parent, MMIO_FINDCHUNK\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;===================================\n\t; Now allocate memory for the sound\n\t;===================================\n\tINVOKE GlobalAlloc, GMEM_FIXED, child.ckSize\n\tMOV\tsnd_buffer, EAX\n\t.IF EAX == NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=======================================\n\t; Read the WAV data and close the file\n\t;=======================================\n\tINVOKE mmioRead, hwav, snd_buffer, child.ckSize\n\tINVOKE mmioClose, hwav, 0\n\t;================================\n\t; Set the rate, size, \u0026amp; state\n\t;================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tMOV\tEAX, wfmtx.nSamplesPerSec\n\tMOV\tsound_fx[ECX].rate, EAX\n\tMOV\tEAX, child.ckSize\n\tMOV\tsound_fx[ECX].lsize, EAX\n\tMOV\tsound_fx[ECX].state, SOUND_LOADED\n\t;==========================\n\t; Clear the format struc\n\t;==========================\n\tINVOKE RtlFillMemory, ADDR pcmwf, sizeof(WAVEFORMATEX), 0\n\t;=============================\n\t; Now fill our desired fields\n\t;=============================\n\tMOV\tpcmwf.wFormatTag, WAVE_FORMAT_PCM\n\tMOV\tAX, wfmtx.nChannels\n\tMOV\tpcmwf.nChannels, AX\n\tMOV\tEAX, wfmtx.nSamplesPerSec\n\tMOV\tpcmwf.nSamplesPerSec, EAX\n\tXOR\tEAX, EAX\n\tMOV\tAX, wfmtx.nBlockAlign\n\tMOV\tpcmwf.nBlockAlign, AX\n\tMOV\tEAX, pcmwf.nSamplesPerSec\n\tXOR\tECX, ECX\n\tMOV\tCX, pcmwf.nBlockAlign\n\tMUL\tECX\n\tMOV\tpcmwf.nAvgBytesPerSec, EAX\n\tMOV\tAX, wfmtx.wBitsPerSample\n\tMOV\tpcmwf.wBitsPerSample, AX\n\tMOV\tpcmwf.cbSize, 0\n\t;=================================\n\t; Prepare to create the DS buffer\n\t;=================================\n\tDSINITSTRUCT ADDR dsbd, sizeof(DSBUFFERDESC)\n\tMOV\tdsbd.dwSize, sizeof(DSBUFFERDESC)\n\t\t; Put other flags you want to play with in here such\n\t\t; as CTRL_PAN, CTRL_FREQ, etc or pass them in\n\tMOV\tEAX, flags\n\tMOV\tdsbd.dwFlags, EAX\n\tOR\tdsbd.dwFlags, DSBCAPS_STATIC OR DSBCAPS_CTRLVOLUME \\\n\t\t\tOR DSBCAPS_LOCSOFTWARE\n\tMOV\tEBX, child.ckSize\n\tMOV\tEAX, OFFSET pcmwf\n\tMOV\tdsbd.dwBufferBytes, EBX\n\tMOV\tdsbd.lpwfxFormat, EAX\n\t;=================================\n\t; Create the sound buffer\n\t;=================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tLEA\tECX, sound_fx[EAX].dsbuffer\n\tDSINVOKE CreateSoundBuffer, lpds, ADDR dsbd, ECX, NULL\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;==================================\n\t; Lock the buffer so we can copy\n\t; our sound data into it\n\t;==================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tDSBINVOKE mLock, sound_fx[ECX].dsbuffer, NULL, child.ckSize, ADDR audio_ptr_1,\\ \n\t\tADDR audio_length_1, ADDR audio_ptr_2, ADDR audio_length_2,\\\n\t\tDSBLOCK_FROMWRITECURSOR\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;==============================\n\t; Copy first section of buffer\n\t; then the second section\n\t;==============================\n\t\t; First buffer\n\tMOV\tESI, snd_buffer\n\tMOV\tEDI, audio_ptr_1\n\tMOV\tECX, audio_length_1\n\tAND\tECX, 3\n\tREP\tmovsb\n\tMOV\tECX, audio_length_1\n\tSHR\tECX, 2\n\tREP\tmovsd\n\t\t; Second buffer\n\tMOV\tESI, snd_buffer\n\tADD\tESI, audio_length_1\n\tMOV\tEDI, audio_ptr_2\n\tMOV\tECX, audio_length_2\n\tAND\tECX, 3\n\tREP\tmovsd\n\tMOV\tECX, audio_length_2\n\tSHR\tECX, 2\n\tREP\tmovsd\n\t;==============================\n\t; Unlock the buffer\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tDSBINVOKE Unlock, sound_fx[ECX].dsbuffer, audio_ptr_1, audio_length_1,\\\n\t\taudio_ptr_2, audio_length_2\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;===================\n\t; Free the buffer\n\t;===================\n\tINVOKE GlobalFree, snd_buffer\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn sound_id\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn -1\nLoad_WAV\tENDP\n;########################################################################\n; END Load_WAV\n;########################################################################The code is fairly simple it is just long. I will skim over the first few parts since they are just setting things up. The code starts out by finding the first available sound in our array. If it finds none, it issues an error and then returns to the caller. Once we have a valid sound id to hold our new sound we can start playing with the file, and setting the structures up for use.\n We start by initializing the structures to 0 to make sure we don\u0027t have any left over remnants from previous loads. Once that is complete, we get to open up our WAV file using the multimedia I/O functions found in the Winmm.lib file.\n Once the file is opened successfully we descend into the internals of the file. This merely takes us to relevant sections in the header so we can setup our structures for loading. A few sections need to be traversed and then we are ready to get the wave format information.\n With our wave information intact we can ascend up the file and then down into our data chunk. Once \"inside\" we allocate memory for our data and then we grab it with the mmioRead() function. Finally, we can close the file ... and the ugly part is over.\n Then, we do some more setting of values in structures and clearing things out. All stuff you have seen before, so it should look familiar by now. We are getting ready to create the sound buffer with all these assignments.\n Normally I would just say \"here is where we create the sound buffer\" ... but there is something very weird going on here. If you notice we aren\u0027t able to pass in the sound buffer parameter. The reason is that we need to pass in the address. So, the line right before the call uses the LEA (Load Effective Address) instruction to obtain the address of our variable. The reason for this is just a quirk on the INVOKE syntax and something we need to workaround. By loading the address before the call, we can place it in the modified invoke statement without troubles. Another small thing you might want to jot down is that we can\u0027t use EAX to hold that value. The reason is that the macro I defined, DSBINVOKE, uses EAX when manipulating things ... this is the only reason, normally you could use it without trouble. Never forget, macros are placed directly into your code ... even if they don\u0027t make sense.\n Once we have our buffer created we lock the buffer, copy the memory over to the new buffer locations, and then unlock the buffer. The only thing that might seem a little confusing is the method I have chosen to copy the sound data over. Remember how we copied using DWORD\u0027s in our Draw_Bitmap() routine? If not, go back and refresh your memory because it is very important. For those of you that do recall ... that is almost exactly what we are doing here.\n The only thing that is different, is we have to make sure that our data is on a 4-byte boundary. We do this by AND\u0027ing the length with 3 ... this is the same as Number mod 4 ... then moving byte by byte until we hit zero. At that point we are on a 4-byte boundary and can move DWORD\u0027s once again.\n It is the same basic concept that we have seen before only this time we have to do the checking for alignment ourselves since the data is not guaranteed to be on even 4-byte boundaries.\n Once all of that is out of the way we can free the buffer, along with our headache, and we are finished. The sound is now loaded, in the buffer, and we can return the sound\u0027s ID to the caller so that they can play the sound later on. One thing I do want to mention is that this WAV loader should be able to load WAV files of any format (8-bit, 16-bit, stereo, mono, etc.). Yet, only 8-bit sounds can be utilized in the DirectSound buffers. The reason is we only set the cooperative level to normal, instead of exclusive. So, if you want to load in, and play, 16-bit sounds you will need to alter the DS_Init() procedure, and put DirectSound into exclusive mode.\n With that, our sound module is complete. It is definitely not \"state-of-the-art\" ... but hey, it works and it removes a lot of the DirectX burden that would normally be placed on us.\n Luckily though, we get to talk about something a lot more fun: Screen Transitions.\n[size=\"5\"] Screen Transitions\nScreen Transitions are things that are usually fun to write. Of course, most anything would be fun after playing with DirectSound. The screen transition is often one of the most important things in a game. If you have a lot of places where the view/screen completely changes, then a transition is typically needed in order to smooth things out. You do not want the user to just be \"jarred\" to the next scene. To the user, a transition is like riding in a Lexus, while having none is like riding an old Pan-head [lessthan][lessthan] inside motorcycle joke \u0026gt;\u0026gt;.\n I have taken an interesting approach with the screen transitions in this game. I decided there would be one main interface function. This function, intelligently called Transition(), is responsible for selecting a screen transition, at random, and calling it. This provides some break from the monotony of calling the same one over and over again. Of course, I have only provided one simple transition ( with 2 options ), it is your job to write more. All transitions require the surface you want to transition \"from\" on the primary buffer, and the surface you want to transition \"to\" on the back buffer.\n Here is the code for the interface function:;########################################################################\n; Transition Procedure\n;########################################################################\nTransition\tPROC\n\t;=======================================================\n\t; This function will call one of the our transitions\n\t; based on a random number. All transitions require\n\t; the primary buffer to be the surface that you want\n\t; to transition from and the back buffer to be the\n\t; surface you want to transition to. Both need to\n\t; be unlocked.\n\t;=======================================================\n\t;=============================\n\t; Get a random number\n\t;=============================\n\tINVOKE Get_Time\n\t;=============================\n\t; Mod the result with 2\n\t;=============================\n\tAND\tEAX, 1\n\t;=============================\n\t; Select the transition based\n\t; on our number\n\t;=============================\n\t.IF EAX == 0\n\t\t;==========================\n\t\t; Perform a Horizontal Wipe\n\t\t;==========================\n\t\tINVOKE Wipe_Trans, 6, WIPE_HORZ\n\t\t;=========================\n\t\t; Universal error check\n\t\t;=========================\n\t\t.IF EAX == FALSE\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ELSEIF EAX == 1\n\t\t;==========================\n\t\t; Perform a Vertical Wipe\n\t\t;==========================\n\t\tINVOKE Wipe_Trans, 4, WIPE_VERT\n\t\t;=========================\n\t\t; Universal error check\n\t\t;=========================\n\t\t.IF EAX == FALSE\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nTransition\tENDP\n;########################################################################\n; END Transition\n;########################################################################The Transition() function grabs a random number by using the same method as our random shape generator, obtaining the time. This is not the optimum method, and we will be replacing it with a true random number generator later on. But, for now, it will have to do. The proper transition is then made based on the time, you can play with the parameters if you wish. I just selected a couple that didn\u0027t seem to take away too much of the screen each iteration.\n That is all that is there for the management function. It just keeps things random. You can still call a transition directly, I just thought it was more interesting to do it like this. Besides, on a large project, after 4-6 months of looking at the same transitions, you would probably be insane.\n Now, we can look at the actual screen transition: Wipe_Trans(). This routine allows us to perform either a vertical (top to bottom) or horizontal (left to right) transition taking away a width that is passed in each time. So, have a look at the code before we continue.;########################################################################\n; Wipe_Trans Procedure\n;########################################################################\nWipe_Trans PROC strip_width:DWORD, direction:DWORD\n\t;=======================================================\n\t; This function will perform either a horizontal or\n\t; a vertical wipe depending on what you pass in for the\n\t; direction paramter. The width of each step is \n\t; determined by the width that you pass in to it.\n\t;=======================================================\n\t;=========================================\n\t; Local Variables\n\t;=========================================\n\tLOCAL StartTime :DWORD\n\t;========================================\n\t; Setup the source rectangle and the \n\t; destination rectangle\n\t;\n\t; For the first iteration, the strip may \n\t; not be the height passed in. This is to \n\t; make sure we are on an even boundary \n\t; during the loop below\n\t;========================================\n\t.IF direction == WIPE_HORZ\n \tMOV SrcRect.top, 0\n \tMOV SrcRect.left, 0\n \tMOV EAX, app_width\n \tMOV ECX, strip_width\n \tXOR EDX, EDX\n \tDIV ECX\n \t.IF EDX == 0\n MOV EDX, strip_width\n \t.ENDIF\n \tMOV EBX, app_height\n \tMOV SrcRect.bottom, EBX\n \tMOV SrcRect.right, EDX\n \tMOV DestRect.top, 0\n \tMOV DestRect.left, 0\n \tMOV DestRect.bottom, EBX\n \tMOV DestRect.right, EDX\n\t.ELSEIF direction == WIPE_VERT\n \tMOV SrcRect.top, 0\n \tMOV SrcRect.left, 0\n \tMOV EAX, app_height\n \tMOV ECX, strip_width\n \tXOR EDX, EDX\n \tDIV ECX\n \tMOV EAX, app_width\n \t.IF EDX == 0\n MOV EDX, strip_width\n \t.ENDIF\n \tMOV SrcRect.bottom, EDX\n \tMOV SrcRect.right, EAX\n \tMOV DestRect.top, 0\n \tMOV DestRect.left, 0\n \tMOV DestRect.bottom, EDX\n \tMOV DestRect.right, EAX\n\t.ELSE\n \t;==================\n \t; Invalid direction\n \t;==================\n \tJMP err\n\t.ENDIF\n\t;================================\n\t; Get the starting time\n\t;================================\n\tINVOKE Start_Time, ADDR StartTime\n\t;================================\n\t; Blit the strip onto the screen\n\t;================================\n\tDDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\\\n \tlpddsback, ADDR DestRect, DDBLTFAST_WAIT\n\t;===============================\n\t; Make sure we succeeded\n\t;===============================\n\t.IF EAX != DD_OK\n \tJMP err\n\t.ENDIF\n\t;===================================================\n\t; Now adjust the distance between the left \u0026amp;\n\t; right, or top and bottom, so that the top, or\n\t; left, corner is where the right hand side was \n\t; at ... and the bottom, or right, is strip_width\n\t; away from the opposite corner.\n\t;===================================================\n\tMOV EAX, strip_width\n\t.IF direction == WIPE_HORZ\n \tMOV EBX, SrcRect.right\n \tMOV SrcRect.left, EBX\n \tMOV DestRect.left, EBX\n \tADD EBX, EAX\n \tMOV DestRect.right, EBX\n \tMOV SrcRect.right, EBX\n\t.ELSEIF direction == WIPE_VERT\n \tMOV EBX, SrcRect.bottom\n \tMOV SrcRect.top, EBX\n \tMOV DestRect.top, EBX\n \tADD EBX, EAX\n \tMOV DestRect.bottom, EBX\n \tMOV SrcRect.bottom, EBX\n\t.ENDIF\n\t;===================================\n\t; Wait to synchronize the time\n\t;===================================\n\tINVOKE Wait_Time, StartTime, TRANS_TIME\n\t;=====================================\n\t; Drop into a while loop and blit all\n\t; of the strips synching to our \n\t; desired transition rate\n\t;=====================================\n\t.WHILE TRUE\n \t;================================\n \t; Get the starting time\n \t;================================\n \tINVOKE Start_Time, ADDR StartTime\n \t;================================\n \t; Blit the strip onto the screen\n \t;================================\n \tDDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\\\n lpddsback, ADDR DestRect, DDBLTFAST_WAIT\n \t;===============================\n \t; Make sure we succeeded\n \t;===============================\n \t.IF EAX != DD_OK\n JMP err\n \t.ENDIF\n \t;==================================\n \t; Have we reached our extents yet\n \t;==================================\n \tMOV EAX, SrcRect.bottom \n \tMOV EBX, app_height\n \tMOV ECX, SrcRect.right\n \tMOV EDX, app_width\n \t.IF EAX == EBX \u0026amp;\u0026amp; ECX == EDX\n ;======================\n ; Trans complete\n ;======================\n .BREAK\n \t.ELSE\n ;======================\n ; Adjust by the strip\n ;======================\n MOV EAX, strip_width\n .IF direction == WIPE_HORZ\n \t ADD SrcRect.left, EAX\n \t ADD SrcRect.right, EAX\n \t ADD DestRect.left, EAX\n \t ADD DestRect.right, EAX\n .ELSEIF direction == WIPE_VERT\n \t ADD SrcRect.top, EAX\n \t ADD SrcRect.bottom, EAX\n \t ADD DestRect.top, EAX\n \t ADD DestRect.bottom, EAX\n .ENDIF\n \t.ENDIF\n \t;===================================\n \t; Wait to synchronize the time\n \t;===================================\n \tINVOKE Wait_Time, StartTime, TRANS_TIME\n\t.ENDW \ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nWipe_Trans ENDP\n;########################################################################\n; END Wipe_Trans\n;######################################################################## Notice, the first thing we do is setup the source and destination rectangles. We are going to be working with \"strips\" of the bitmap. So, I am going to walk you through exactly what happens when the routine is called.\nPretend the user passed in a 7 for the \"strip_width\" parameter and they want a horizontal transition. The first section finds out if the strip\u0027s width can go evenly into the screen width. If the strip can go in evenly, then it sets the length to be equal to the width. However, if it can\u0027t, then the remainder is placed in the width. The reason we place the remainder in, is that the strip is going to have that little strip left over when we finish. Example: with a 7 and a screen width of 640 you will have 91 sections of 7 and a section of 3 left over. So, for the first strip we would store a 3 for the width. From here on note: You would do the exact same thing, except for the height/top/bottom, if you were doing a vertical wipe.\nNext, we blit that small 3 pixel strip over from the back buffer onto the primary buffer. With that out of the way we can get setup to do blits with a 7-pixel width. The way we setup is by moving the right-hand side of the rectangle over to the left-hand side. Then, we add the strip_width, in this case 7, to the left-hand side to obtain the new right-hand side. So, for our example, the left coordinate of the rectangles would now have a 3, and the right coordinate would now have a 10. We need this adjustment since our loop is only going to work with 7-pixel strips in the bitmap, instead of an increasing portion of the bitmap.\nWe are now ready to delve into our loop. The first thing we do, aside from getting the starting time, is blit the current strip (this is why we had to setup the rectangles out of the loop). Then, we check the right hand side and bottom of our source rectangle is still inside the limits of our screen. If it has met the extents, then we break from the loop since we are finished. If we haven\u0027t yet reached the edges, then we adjust the rectangles. To adjust the rectangles, we add the strip_width to both the left and right of our source and destination rectangles. By adding to both sides we are able to blit in strips of 7-pixels. But, if we only added to the right-hand side we would blit in pixels of 7, 14, 21, etc. Which, needless to say, is much, much slower than the way we are doing it. Finally, we synchronize the time to our desired rate and keep doing the loop until we are finished.\nThere isn\u0027t very much to the routine, but it should give you a starting point in making screen transitions. Here are some suggestions in case you are lacking in creativity. Make a modified wipe that would have a bunch of strips at intervals grow to meet each other, like something you would see with a pair of blinds in your house. Design a transition that zooms in to a single pixel, then zooms out to the new picture. Create a circular wipe, or even a spiral one. There are many good articles out there on demo effects and I suggest reading some of them if you find this stuff interesting. Finally, if you are really desperate for an idea, just go and play a game and see how their transitions work. Mimicry is one of the first steps in learning.\nAt any rate, everything in our modules is complete. We now have everything that we need to pretty up the game. So, in the next section, we will tie everything into that nice little bow, just as we always do.[size=\"5\"]Putting More Pieces Together\nThe title to this section is really accurate. Most programming, at least in some way, is like a jigsaw puzzle. It is about combining pieces in a manner that works best. Often times, you will obtain a completely different result just be re-ordering some of the steps. In this sense, programming is intellectually stimulating. There are so many millions of ways to accomplish any given task. Keep that in mind while reviewing the code I provide. It isn\u0027t written in blood anyplace that you have to do things a certain way -- at least, I don\u0027t think it is.\nThe module, we are going to look at for the changes is the Menu module. The reason we are using this module is that it makes use of all of our new features, which makes it perfect for use as an example.\nYou had better take a look at the code for the new module before we go any further. ;###########################################################################\n;###########################################################################\n; ABOUT Menu:\n;\n;\tThis code module contains all of the functions that relate to \n; the menu that we use. \n;\n;\tThere are routines for each menu we will have. One for the main\n; menu and one for the load/save menu stuff.\n;\n;\tNOTE: We could have combined these two functions into one generic \n; function that used parameters to determine the bahavior. But, by coding\n; it explicitly we get a better idea for what is going on in the code.\n;\n;###########################################################################\n;###########################################################################\n;###########################################################################\n;###########################################################################\n; THE COMPILER OPTIONS\n;###########################################################################\n;###########################################################################\n\t.386\n\t.MODEL flat, stdcall\n\tOPTION CASEMAP :none ; case sensitive\n;###########################################################################\n;###########################################################################\n; THE INCLUDES SECTION\n;###########################################################################\n;###########################################################################\n\t;================================================\n\t; These are the Inlcude files for Window stuff\n\t;================================================\n\tINCLUDE \\masm32\\include\\windows.inc\n\tINCLUDE \\masm32\\include\\comctl32.inc\n\tINCLUDE \\masm32\\include\\comdlg32.inc\n\tINCLUDE \\masm32\\include\\shell32.inc\n\tINCLUDE \\masm32\\include\\user32.inc\n\tINCLUDE \\masm32\\include\\kernel32.inc\n\tINCLUDE \\masm32\\include\\gdi32.inc\n\t;===============================================\n\t; The Lib\u0027s for those included files\n\t;================================================\n\tINCLUDELIB \\masm32\\lib\\comctl32.lib\n\tINCLUDELIB \\masm32\\lib\\comdlg32.lib\n\tINCLUDELIB \\masm32\\lib\\shell32.lib\n\tINCLUDELIB \\masm32\\lib\\gdi32.lib\n\tINCLUDELIB \\masm32\\lib\\user32.lib\n\tINCLUDELIB \\masm32\\lib\\kernel32.lib\n\t;====================================\n\t; The Direct Draw include file\n\t;====================================\n\tINCLUDE Includes\\DDraw.inc\n\t;====================================\n\t; The Direct Input include file\n\t;====================================\n\tINCLUDE Includes\\DInput.inc\n\t;====================================\n\t; The Direct Sound include file\n\t;====================================\n\tINCLUDE Includes\\DSound.inc\n\t;=================================================\n\t; Include the file that has our protos\n\t;=================================================\n\tINCLUDE Protos.inc\n;###########################################################################\n;###########################################################################\n; LOCAL MACROS\n;###########################################################################\n;###########################################################################\n\tm2m MACRO M1, M2\n\t\tPUSH\t\tM2\n\t\tPOP\t\tM1\n\tENDM\n\treturn MACRO arg\n\t\tMOV\tEAX, arg\n \t\tRET\n\tENDM\n;#################################################################################\n;#################################################################################\n; Variables we want to use in other modules\n;#################################################################################\n;#################################################################################\n;#################################################################################\n;#################################################################################\n; External variables\n;#################################################################################\n;#################################################################################\n\t;=================================\n\t; The DirectDraw stuff\n\t;=================================\n\tEXTERN\tlpddsprimary\t:LPDIRECTDRAWSURFACE4\n\tEXTERN\tlpddsback\t:LPDIRECTDRAWSURFACE4\n\t;=========================================\n\t; The Input Device state variables\n\t;=========================================\n\tEXTERN keyboard_state\t:BYTE\n;#################################################################################\n;#################################################################################\n; BEGIN INITIALIZED DATA\n;#################################################################################\n;#################################################################################\n\t.DATA\n\t;===============================\n\t; Strings for the bitmaps\n\t;===============================\n\tszMainMenu\tDB \"Art\\Menu.sfp\",0\n\tszFileMenu\tDB \"Art\\FileMenu.sfp\",0\n\t;================================\n\t; Our very cool menu sound\n\t;================================\n\tszMenuSnd\tDB \"Sound\\Background.wav\",0\n\t;===============================\n\t; PTR to the BMP\u0027s\n\t;===============================\n\tptr_MAIN_MENU\tDD 0\n\tptr_FILE_MENU\tDD 0\n\t;===============================\n\t; ID for the Menu sound\n\t;===============================\n\tMenu_ID\t\tDD 0\n\t;======================================\n\t; A value to hold lPitch when locking\n\t;======================================\n\tlPitch\t\tDD 0\n\t;========================================\n\t; Let\u0027s us know if we need to transition\n\t;========================================\n\tfirst_time\tDD 0\n;#################################################################################\n;#################################################################################\n; BEGIN CONSTANTS\n;#################################################################################\n;#################################################################################\n;#################################################################################\n;#################################################################################\n; BEGIN EQUATES\n;#################################################################################\n;#################################################################################\n\t;=================\n\t;Utility Equates\n\t;=================\nFALSE\t\tEQU\t0\nTRUE\t\tEQU\t1\n\t;=================\n\t; The Screen BPP\n\t;=================\nscreen_bpp\tEQU\t16\n;=================\n; The Menu Codes\n;=================\n\t; Generic\nMENU_ERROR\tEQU\t0h\nMENU_NOTHING\tEQU\t1h\n\t; Main Menu\nMENU_NEW\tEQU\t2h\nMENU_FILES\tEQU\t3h\nMENU_GAME\tEQU\t4h\nMENU_EXIT\tEQU\t5h\n\t; File Menu\nMENU_LOAD\tEQU\t6h\nMENU_SAVE\tEQU\t7h\nMENU_MAIN\tEQU\t8h\n;#################################################################################\n;#################################################################################\n; BEGIN THE CODE SECTION\n;#################################################################################\n;#################################################################################\n .CODE\n;########################################################################\n; Init_Menu Procedure\n;########################################################################\nInit_Menu\tPROC\t\n\t;===========================================================\n\t; This function will initialize our menu systems\n\t;===========================================================\n\t;=================================\n\t; Local Variables\n\t;=================================\n\t;======================================\n\t; Read in the bitmap and create buffer\n\t;======================================\n\tINVOKE Create_From_SFP, ADDR ptr_MAIN_MENU, ADDR szMainMenu, screen_bpp\n\t;====================================\n\t; Test for an error\n\t;====================================\n\t.IF EAX == FALSE\n\t\t;========================\n\t\t; We failed so leave\n\t\t;========================\n\t\tJMP\terr\n\t.ENDIF\n\t;======================================\n\t; Read in the bitmap and create buffer\n\t;======================================\n\tINVOKE Create_From_SFP, ADDR ptr_FILE_MENU, ADDR szFileMenu, screen_bpp\n\t;====================================\n\t; Test for an error\n\t;====================================\n\t.IF EAX == FALSE\n\t\t;=\n", "articleBody": "(Editor\u0027s Note - this article requires additional formatting work and is incomplete)[size=\"5\"]Where Did We Leave Off?\nUntil last issue SPACE-TRIS wasn\u0027t even a game, it was merely an exercise in coding modules. Well, now we have a game that is working, it is just ugly. Sadly enough though, we are back to coding modules today. The good news is these modules will pretty things up by a large margin.\n The modules that we will be covering today are Direct Sound (YUCK!) and screen transitions (YA!). The Direct Sound module isn\u0027t going to be anything to complex, just a simple sound effects manager that allows you to play, stop, delete, add, or set variables on the sounds themselves. The screen transitions module is going to consist of one main function that gets called and then a transition is selected at random to perform.\n When we last saw each other, the game also needed a way to check for an \"out-of-bounds\" occurrence while rotating pieces. You guys were working on it, like I told you too, right? Yeah, I\u0027m sure. Anyway, I will present my quick hack of a solution in a few moments. But first, I want to say that I am going to be glossing over many of the things we have already covered in past issues. For instance, in the Direct Sound module you guys have all seen how to check for an error, so I won\u0027t be explaining that again. This means, if you are new to the series, do yourself a favor and start at the beginning. This isn\u0027t your favorite TV series where you can just pop by, on any old day, and know what is going on. We are going to be moving at warp speed through a lot of things. All I am really going to provide now is an overview of the techniques I use ... it is up to you to understand them.\n With that said, let us get right down to business with that solution to the rotation problem.\n[size=\"5\"]Rotation Solution\nThe solution to our rotation problem was fairly straightforward. Basically, we already had all of the routines that we needed. What we had to know was if, at any given frame, the current piece would be out of bounds -- which MoveShape() does for us. So, the fix we have is a simple one. We can just call that routine with the frame it \"would\" be on next, right? Wrong. That is what I tried at first because it makes sense. But, there is a hidden problem with that method.\n The problem lies in that fact that any piece could already be out of bounds when you adjust the frame. Move_Shape() only tells you if you can move the shape to the left or right, and does so if it can. If we fake our next frame for that call it may succeed because it is already out of bounds by one column if it was on the edges previously. This means we need a way to prevent it from ever being out of bounds to begin with.\n The solution is to move it in towards the center by one column beforehand. Then, when we make the call, the shape is guaranteed to be on the edge, or in the middle, never outside the grid. The way we decide if we could go to the next frame is by seeing if the X coordinate sent before we made the call matches the one we have after the call. If it does, then that means the shape can be rotated ... if they don\u0027t match then the shape can not be rotated.\n This method has the advantage of eliminating the need for any other code. The Move_Shape() function will not succeed if something else is blocking its move. Therefore, we do not need to do any other tests on the shape to see if other blocks are in the way. Just that simple call based on the next frame. So, we not only solved the problem ... but also made the routine shorter in the process.\n The new Rotate_Shape();########################################################################\n; Rotate_Shape Procedure\n;########################################################################\nRotate_Shape\tPROC\t\n\t;=======================================================\n\t; This function will rotate the current shape it tests\n\t; to make sure there are no blocks already in the place\n\t; where it would rotate. \n\t;=======================================================\n\t;================================\n\t; Local Variables\n\t;================================\n\tLOCAL\tIndex:\t\tDWORD\n\tLOCAL\tCurBlock:\tDWORD\n\tLOCAL\tSpot:\t\tBYTE\n\t;=================================\n\t; Make sure they are low enough\n\t;=================================\n\t.IF CurShapeY \u0026gt; 21\n\t\tJMP\terr\n\t.ENDIF\n\t;================================\n\t; Are they at the last frame?\n\t;================================\n\t.IF CurShapeFrame == 3\n\t\t;=====================================\n\t\t; Yep ... make sure they can rotate\n\t\t;=====================================\n\t\t;========================================\n\t\t; We will start by seeing which half of \n\t\t; the grid they are currently on that way\n\t\t; we know we much too move the shape \n\t\t;=========================================\n\t\t.IF CurShapeX \n\t\t\t;===========================\n\t\t\t; They are on the left half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord right and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tINC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tMOV\tCurShapeFrame, 0\n\t\t\t;=============================\n\t\t\t; Try to move them to the left\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_LEFT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tMOV\tCurShapeFrame, 3\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ELSE\n\t\t\t;===========================\n\t\t\t; They are on the right half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord left and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tDEC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tMOV\tCurShapeFrame, 0\n\t\t\t;=============================\n\t\t\t; Try \u0026amp; move them to the right\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_RIGHT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tMOV\tCurShapeFrame, 3\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ENDIF\n\t.ELSE\n\t\t;=====================================\n\t\t; NO ... make sure they can rotate\n\t\t;=====================================\n\t\t;========================================\n\t\t; We will start by seeing which half of \n\t\t; the grid they are currently on that way\n\t\t; we know we much too move the shape \n\t\t;=========================================\n\t\t.IF CurShapeX \n\t\t\t;===========================\n\t\t\t; They are on the left half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord right and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tINC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tINC\tCurShapeFrame\n\t\t\t;=============================\n\t\t\t; Try to move them to the left\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_LEFT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tDEC\tCurShapeFrame\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ELSE\n\t\t\t;===========================\n\t\t\t; They are on the right half \n\t\t\t; of the grid\n\t\t\t;===========================\n\t\t\t;=============================\n\t\t\t; So start by moving them one \n\t\t\t; coord left and saving the\n\t\t\t; old coordinat\n\t\t\t;=============================\n\t\t\tPUSH\tCurShapeX\n\t\t\tDEC\tCurShapeX\n\t\t\t;=============================\n\t\t\t; Now adjust the frame to what\n\t\t\t; it would be\n\t\t\t;=============================\n\t\t\tINC\tCurShapeFrame\n\t\t\t;=============================\n\t\t\t; Try \u0026amp; move them to the right\n\t\t\t;=============================\n\t\t\tINVOKE Move_Shape, MOVE_RIGHT\n\t\t\t;=============================\n\t\t\t; If we succeeded then the old\n\t\t\t; X will be equal to the new\n\t\t\t; X coordinate\n\t\t\t;=============================\n\t\t\tMOV\tEAX, CurShapeX\n\t\t\tPOP\tCurShapeX\n\t\t\t.IF\tEAX == CurShapeX\n\t\t\t\t;================\n\t\t\t\t; Can rotate\n\t\t\t\t;================\n\t\t\t\tJMP\tdone\n\t\t\t.ELSE\n\t\t\t\t;================\n\t\t\t\t; Can\u0027t rotate\n\t\t\t\t;================\n\t\t\t\tDEC\tCurShapeFrame\n\t\t\t\tJMP\terr\n\t\t\t.ENDIF\n\t\t.ENDIF\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nRotate_Shape\tENDP\n;########################################################################\n; END Rotate_Shape\n;########################################################################\n[size=\"5\"]The Sound Module\nThe sound module for this game is pretty simple. It merely presents an interface to Load WAV files, play the sounds, delete them, and edit properties about them. However, there are a few tricky things to watch out for in the module.\n The first thing I want to illustrate is how to create an array of structures. Take a look at the following modified code snippet.;#################################################################################\n;#################################################################################\n; STRUCTURES\n;#################################################################################\n;#################################################################################\n\t;=============================\n\t; this holds a single sound\n\t;=============================\n\tpcm_sound\tSTRUCT \n\t\tdsbuffer\tDD 0\t; the ds buffer for the sound \n\t\tstate\t\tDD 0\t; state of the sound\n\t\trate\t\tDD 0\t; playback rate\n\t\tlsize\t\tDD 0\t; size of sound\n\tpcm_sound\tENDS\n\t;============================\n\t; max number of sounds in \n\t; the game at once \n\t;============================\n\tMAX_SOUNDS\tEQU\t16\n\t;=========================================\n\t; Our array of sound effects\n\t;=========================================\n\tsound_fx\tpcm_sound\tMAX_SOUNDS dup()You will notice that anytime we declare a structure we need to use angle brackets, or curly braces (not shown), for them. The numbers inside consist of the members of your structure and nothing more. Whatever you place there is what things get initialized to. Also, pay attention to how the structure is defined. It consists of normal variable declarations in between a couple of keywords and a tag to give it a name. \n Of special note, is that you must use another set of braces, or brackets, if you wish to have nested structures. The way we get an array with a structure is the same as any other variable. We use the number we want followed by the DUP ... then, in parenthesis, what you want the values initialized as.\n We are going to skip over the DS_Init() and DS_Shutdown() procedures, since they do the same exact things as the other DX counterparts. Instead let\u0027s take a peek at Play_Sound().;########################################################################\n; Play_Sound Procedure\n;########################################################################\nPlay_Sound PROC\tid:DWORD, flags:DWORD\n\t;=======================================================\n\t; This function will play the sound contained in the\n\t; id passed in along with the flags which can be either\n\t; NULL or DSBPLAY_LOOPING\n\t;=======================================================\n\t;==============================\n\t; Make sure this buffer exists\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\t.IF sound_fx[ECX].dsbuffer != NULL\n\t\t;=================================\n\t\t; We exists so reset the position\n\t\t; to the start of the sound\n\t\t;=================================\n\t\tPUSH\tECX\n\t\tDSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0\n\t\tPOP\tECX\n\t\t;======================\n\t\t; Did the call fail?\n\t\t;======================\n\t\t.IF EAX != DS_OK\n\t\t\t;=======================\n\t\t\t; Nope, didn\u0027t make it\n\t\t\t;=======================\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t\t;==============================\n\t\t; Now, we can play the sound\n\t\t;==============================\n\t\tDSBINVOKE Play, sound_fx[ECX].dsbuffer, 0, 0, flags\n\t\t;======================\n\t\t; Did the call fail?\n\t\t;======================\n\t\t.IF EAX != DS_OK\n\t\t\t;=======================\n\t\t\t; Nope, didn\u0027t make it\n\t\t\t;=======================\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ELSE\n\t\t;======================\n\t\t; No buffer for sound\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nPlay_Sound\tENDP\n;########################################################################\n; END Play_Sound\n;########################################################################This is the routine that we use to start a sound playing. You can pass it flags to alter how it sounds. So far as I know there are only 2 options for the flags. If you pass in NULL then it plays the sound once. If you pass in DSBPLAY_LOOPING it will play the sound repeatedly.\n The routine begins by checking that the sound has a valid buffer associated with it. If so, it sets the position of that sound to the beginning and then makes a call to begin playing it with whatever flags were passed in.\n The only thing worth illustrating in this routine is how the structure element is referenced. To begin with we obtain the size of the structure and multiply that by the id of the sound to give us our position in the array. Then, in order to reference a member you treat it just like you would in C/C++ ... StructName[position].member ... the important thing is not to forget to multiply the element by the size of the structure.\n The next 3 routines allow you to set the volume, frequency, and pan of a sound. There is nothing to these routines ... they are just wrappers for the Direct Sound function calls. However, if you want to use anything but Set_Sound_Volume() you need to tell Direct Sound that you want those enabled when you load the sound. This is done by passing in DSBCAPS_CTRL_PAN or DSBCAPS_CTRLFREQ respectively. If you do not specify these flags when you load your sound you will not be able to manipulate those items.\n The next two functions are for stopping sounds from playing. One will stop the specific sound you pass in and the other will stop all of the sounds from playing. Here is the code if you want to take a peek. Once again these are merely wrapper functions to shield you from the DX headache.;########################################################################\n; Stop_Sound Procedure\n;########################################################################\nStop_Sound PROC\tid:DWORD\n\t;=======================================================\n\t; This function will stop the passed in sound from\n\t; playing and will reset it\u0027s position\n\t;=======================================================\n\t;==============================\n\t; Make sure the sound exists\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\t.IF sound_fx[ECX].dsbuffer != NULL\n\t\t;==================================\n\t\t; We exist so stop the sound\n\t\t;==================================\n\t\tPUSH\tECX\n\t\tDSBINVOKE Stop, sound_fx[ECX].dsbuffer\n\t\tPOP\tECX\n\t\t;=================================\n\t\t; Now reset the sound position\n\t\t;=================================\n\t\tDSBINVOKE SetCurrentPosition, sound_fx[ECX].dsbuffer, 0\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nStop_Sound\tENDP\n;########################################################################\n; END Stop_Sound\n;########################################################################\n;########################################################################\n; Stop_All_Sounds Procedure\n;########################################################################\nStop_All_Sounds PROC\n\t;=======================================================\n\t; This function will stop all sounds from playing\n\t;=======================================================\n\t;==============================\n\t; Local Variables\n\t;==============================\n\tLOCAL\tindex\t:DWORD\n\t;==============================\n\t; Loop through all sounds\n\t;==============================\n\tMOV\tindex, 0\n\t.WHILE index \n\t\t;==================================\n\t\t; Stop this sound from playing\n\t\t;==================================\n\t\tINVOKE Stop_Sound, index\n\t\t;================\n\t\t; Inc the counter\n\t\t;================\n\t\tINC\tindex\n\t.ENDW\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nStop_All_Sounds\tENDP\n;########################################################################\n; END Stop_All_Sounds\n;########################################################################Delete_Sound() and Delete_All_Sounds() are remarkably similar to the sound stopping functions. The only difference is you make a different function call to DX. Delete_Sound() will call Stop_Sound() first, to make sure the sound isn\u0027t trying to be played while you are trying to delete it. The interesting thing about these two functions is that you do not personally have to release any of your sounds if you don\u0027t want to. During shutdown of Direct Sound all the sounds that you loaded will be deleted. However, if you have reached your maximum in sounds, and want to free one up, you will need to manually delete it.\n The next function Status_Sound() is yet another wrapper routine. It is used when you need to find out if a sound is still playing, or if it has stopped already. You will see this function put to use later on.\n There, 90% of that stupid module is out of the way. Now, we need to move on to the final 10% of that code ... the Load_WAV() procedure.\n[size=\"5\"]One Big Headache\nLoading file formats is always a pain to do. Loading a WAV file proves to be no different. It is a long function, that probably could have been broken up a little bit better, but for now it will have to do. It works and that is all I am concerned about. So, have a peek at it.;########################################################################\n; Load_WAV Procedure\n;########################################################################\nLoad_WAV\tPROC\tfname_ptr:DWORD, flags:DWORD\n\t;=======================================================\n\t; This function will load the passed in WAV file\n\t; it returns the id of the sound, or -1 if failed\n\t;=======================================================\n\t;==============================\n\t; Local Variables\n\t;==============================\n\tLOCAL\tsound_id\t:DWORD\n\tLOCAL\tindex\t\t:DWORD\n\t;=================================\n\t; Init the sound_id to -1\n\t;=================================\n\tMOV\tsound_id, -1\n\t;=================================\n\t; First we need to make sure there\n\t; is an open id for our new sound\n\t;=================================\n\tMOV\tindex, 0\n\t.WHILE index \n\t\t;========================\n\t\t; Is this sound empty??\n\t\t;========================\n\t\tMOV\tEAX, sizeof(pcm_sound)\n\t\tMOV\tECX, index\n\t\tMUL\tECX\n\t\tMOV\tECX, EAX\n\t\t.IF sound_fx[ECX].state == SOUND_NULL\n\t\t\t;===========================\n\t\t\t; We have found one, so set \n\t\t\t; the id and leave our loop\n\t\t\t;===========================\n\t\t\tMOV\tEAX, index\n\t\t\tMOV\tsound_id, EAX\n\t\t\t.BREAK\n\t\t.ENDIF\n\t\t;================\n\t\t; Inc the counter\n\t\t;================\n\t\tINC\tindex\n\t.ENDW\n\t;======================================\n\t; Make sure we have a valid id now\n\t;======================================\n\t.IF sound_id == -1\n\t\t;======================\n\t\t; Give err msg\n\t\t;======================\n\t\tINVOKE MessageBox, hMainWnd, ADDR szNoID, NULL, MB_OK\n\t\t;======================\n\t\t; Jump and return out\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\n\t;=========================\n\t; Setup the parent \"chunk\"\n\t; info structure\n\t;=========================\n\tMOV\tparent.ckid, 0\n\tMOV\tparent.ckSize, 0\n\tMOV\tparent.fccType, 0\n\tMOV\tparent.dwDataOffset, 0\n\tMOV\tparent.dwFlags, 0\n\t;============================\n\t; Do the same with the child\n\t;============================\n\tMOV\tchild.ckid, 0\n\tMOV\tchild.ckSize, 0\n\tMOV\tchild.fccType, 0\n\tMOV\tchild.dwDataOffset, 0\n\tMOV\tchild.dwFlags, 0\n\t;======================================\n\t; Now open the WAV file using the MMIO\n\t; API function\n\t;======================================\n\tINVOKE mmioOpen, fname_ptr, NULL, (MMIO_READ OR MMIO_ALLOCBUF)\n\tMOV\thwav, EAX\n\t;====================================\n\t; Make sure the call was successful\n\t;====================================\n\t.IF EAX == NULL\n\t\t;======================\n\t\t; Give err msg\n\t\t;======================\n\t\tINVOKE MessageBox, hMainWnd, ADDR szNoOp, NULL, MB_OK\n\t\t;======================\n\t\t; Jump and return out\n\t\t;======================\n\t\tJMP\terr\n\t.ENDIF\n\t;===============================\n\t; Set the type in the parent\n\t;===============================\n\tmmioFOURCC \u0027W\u0027, \u0027A\u0027, \u0027V\u0027, \u0027E\u0027 \n\tMOV\tparent.fccType, EAX\n\t;=================================\n\t; Descend into the RIFF\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR parent, NULL, MMIO_FINDRIFF\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;============================\n\t; Set the child id to format\n\t;============================\n\tmmioFOURCC \u0027f\u0027, \u0027m\u0027, \u0027t\u0027, \u0027 \u0027 \n\tMOV\tchild.ckid, EAX\n\t;=================================\n\t; Descend into the WAVE format\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR child, ADDR parent, NULL\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Now read the wave format info in\n\t;=================================\n\tINVOKE mmioRead, hwav, ADDR wfmtx, sizeof(WAVEFORMATEX)\n\tMOV\tEBX, sizeof(WAVEFORMATEX)\n\t.IF EAX != EBX\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Make sure the data format is PCM\n\t;=================================\n\t.IF wfmtx.wFormatTag != WAVE_FORMAT_PCM\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=================================\n\t; Ascend up one level\n\t;=================================\n\tINVOKE mmioAscend, hwav, ADDR child, NULL\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;============================\n\t; Set the child id to data\n\t;============================\n\tmmioFOURCC \u0027d\u0027, \u0027a\u0027, \u0027t\u0027, \u0027a\u0027 \n\tMOV\tchild.ckid, EAX\n\t;=================================\n\t; Descend into the data chunk\n\t;=================================\n\tINVOKE mmioDescend, hwav, ADDR child, ADDR parent, MMIO_FINDCHUNK\n\t.IF EAX != NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;===================================\n\t; Now allocate memory for the sound\n\t;===================================\n\tINVOKE GlobalAlloc, GMEM_FIXED, child.ckSize\n\tMOV\tsnd_buffer, EAX\n\t.IF EAX == NULL\n\t\t;===================\n\t\t; Close the file\n\t\t;===================\n\t\tINVOKE mmioClose, hwav, NULL\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;=======================================\n\t; Read the WAV data and close the file\n\t;=======================================\n\tINVOKE mmioRead, hwav, snd_buffer, child.ckSize\n\tINVOKE mmioClose, hwav, 0\n\t;================================\n\t; Set the rate, size, \u0026amp; state\n\t;================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tMOV\tEAX, wfmtx.nSamplesPerSec\n\tMOV\tsound_fx[ECX].rate, EAX\n\tMOV\tEAX, child.ckSize\n\tMOV\tsound_fx[ECX].lsize, EAX\n\tMOV\tsound_fx[ECX].state, SOUND_LOADED\n\t;==========================\n\t; Clear the format struc\n\t;==========================\n\tINVOKE RtlFillMemory, ADDR pcmwf, sizeof(WAVEFORMATEX), 0\n\t;=============================\n\t; Now fill our desired fields\n\t;=============================\n\tMOV\tpcmwf.wFormatTag, WAVE_FORMAT_PCM\n\tMOV\tAX, wfmtx.nChannels\n\tMOV\tpcmwf.nChannels, AX\n\tMOV\tEAX, wfmtx.nSamplesPerSec\n\tMOV\tpcmwf.nSamplesPerSec, EAX\n\tXOR\tEAX, EAX\n\tMOV\tAX, wfmtx.nBlockAlign\n\tMOV\tpcmwf.nBlockAlign, AX\n\tMOV\tEAX, pcmwf.nSamplesPerSec\n\tXOR\tECX, ECX\n\tMOV\tCX, pcmwf.nBlockAlign\n\tMUL\tECX\n\tMOV\tpcmwf.nAvgBytesPerSec, EAX\n\tMOV\tAX, wfmtx.wBitsPerSample\n\tMOV\tpcmwf.wBitsPerSample, AX\n\tMOV\tpcmwf.cbSize, 0\n\t;=================================\n\t; Prepare to create the DS buffer\n\t;=================================\n\tDSINITSTRUCT ADDR dsbd, sizeof(DSBUFFERDESC)\n\tMOV\tdsbd.dwSize, sizeof(DSBUFFERDESC)\n\t\t; Put other flags you want to play with in here such\n\t\t; as CTRL_PAN, CTRL_FREQ, etc or pass them in\n\tMOV\tEAX, flags\n\tMOV\tdsbd.dwFlags, EAX\n\tOR\tdsbd.dwFlags, DSBCAPS_STATIC OR DSBCAPS_CTRLVOLUME \\\n\t\t\tOR DSBCAPS_LOCSOFTWARE\n\tMOV\tEBX, child.ckSize\n\tMOV\tEAX, OFFSET pcmwf\n\tMOV\tdsbd.dwBufferBytes, EBX\n\tMOV\tdsbd.lpwfxFormat, EAX\n\t;=================================\n\t; Create the sound buffer\n\t;=================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tLEA\tECX, sound_fx[EAX].dsbuffer\n\tDSINVOKE CreateSoundBuffer, lpds, ADDR dsbd, ECX, NULL\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;==================================\n\t; Lock the buffer so we can copy\n\t; our sound data into it\n\t;==================================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tDSBINVOKE mLock, sound_fx[ECX].dsbuffer, NULL, child.ckSize, ADDR audio_ptr_1,\\ \n\t\tADDR audio_length_1, ADDR audio_ptr_2, ADDR audio_length_2,\\\n\t\tDSBLOCK_FROMWRITECURSOR\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;==============================\n\t; Copy first section of buffer\n\t; then the second section\n\t;==============================\n\t\t; First buffer\n\tMOV\tESI, snd_buffer\n\tMOV\tEDI, audio_ptr_1\n\tMOV\tECX, audio_length_1\n\tAND\tECX, 3\n\tREP\tmovsb\n\tMOV\tECX, audio_length_1\n\tSHR\tECX, 2\n\tREP\tmovsd\n\t\t; Second buffer\n\tMOV\tESI, snd_buffer\n\tADD\tESI, audio_length_1\n\tMOV\tEDI, audio_ptr_2\n\tMOV\tECX, audio_length_2\n\tAND\tECX, 3\n\tREP\tmovsd\n\tMOV\tECX, audio_length_2\n\tSHR\tECX, 2\n\tREP\tmovsd\n\t;==============================\n\t; Unlock the buffer\n\t;==============================\n\tMOV\tEAX, sizeof(pcm_sound)\n\tMOV\tECX, sound_id\n\tMUL\tECX\n\tMOV\tECX, EAX\n\tDSBINVOKE Unlock, sound_fx[ECX].dsbuffer, audio_ptr_1, audio_length_1,\\\n\t\taudio_ptr_2, audio_length_2\n\t.IF EAX != DS_OK\n\t\t;===================\n\t\t; Free the buffer\n\t\t;===================\n\t\tINVOKE GlobalFree, snd_buffer\n\t\t;=====================\n\t\t; Jump and return out\n\t\t;=====================\n\t\tJMP\terr\n\t.ENDIF\n\t;===================\n\t; Free the buffer\n\t;===================\n\tINVOKE GlobalFree, snd_buffer\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn sound_id\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn -1\nLoad_WAV\tENDP\n;########################################################################\n; END Load_WAV\n;########################################################################The code is fairly simple it is just long. I will skim over the first few parts since they are just setting things up. The code starts out by finding the first available sound in our array. If it finds none, it issues an error and then returns to the caller. Once we have a valid sound id to hold our new sound we can start playing with the file, and setting the structures up for use.\n We start by initializing the structures to 0 to make sure we don\u0027t have any left over remnants from previous loads. Once that is complete, we get to open up our WAV file using the multimedia I/O functions found in the Winmm.lib file.\n Once the file is opened successfully we descend into the internals of the file. This merely takes us to relevant sections in the header so we can setup our structures for loading. A few sections need to be traversed and then we are ready to get the wave format information.\n With our wave information intact we can ascend up the file and then down into our data chunk. Once \"inside\" we allocate memory for our data and then we grab it with the mmioRead() function. Finally, we can close the file ... and the ugly part is over.\n Then, we do some more setting of values in structures and clearing things out. All stuff you have seen before, so it should look familiar by now. We are getting ready to create the sound buffer with all these assignments.\n Normally I would just say \"here is where we create the sound buffer\" ... but there is something very weird going on here. If you notice we aren\u0027t able to pass in the sound buffer parameter. The reason is that we need to pass in the address. So, the line right before the call uses the LEA (Load Effective Address) instruction to obtain the address of our variable. The reason for this is just a quirk on the INVOKE syntax and something we need to workaround. By loading the address before the call, we can place it in the modified invoke statement without troubles. Another small thing you might want to jot down is that we can\u0027t use EAX to hold that value. The reason is that the macro I defined, DSBINVOKE, uses EAX when manipulating things ... this is the only reason, normally you could use it without trouble. Never forget, macros are placed directly into your code ... even if they don\u0027t make sense.\n Once we have our buffer created we lock the buffer, copy the memory over to the new buffer locations, and then unlock the buffer. The only thing that might seem a little confusing is the method I have chosen to copy the sound data over. Remember how we copied using DWORD\u0027s in our Draw_Bitmap() routine? If not, go back and refresh your memory because it is very important. For those of you that do recall ... that is almost exactly what we are doing here.\n The only thing that is different, is we have to make sure that our data is on a 4-byte boundary. We do this by AND\u0027ing the length with 3 ... this is the same as Number mod 4 ... then moving byte by byte until we hit zero. At that point we are on a 4-byte boundary and can move DWORD\u0027s once again.\n It is the same basic concept that we have seen before only this time we have to do the checking for alignment ourselves since the data is not guaranteed to be on even 4-byte boundaries.\n Once all of that is out of the way we can free the buffer, along with our headache, and we are finished. The sound is now loaded, in the buffer, and we can return the sound\u0027s ID to the caller so that they can play the sound later on. One thing I do want to mention is that this WAV loader should be able to load WAV files of any format (8-bit, 16-bit, stereo, mono, etc.). Yet, only 8-bit sounds can be utilized in the DirectSound buffers. The reason is we only set the cooperative level to normal, instead of exclusive. So, if you want to load in, and play, 16-bit sounds you will need to alter the DS_Init() procedure, and put DirectSound into exclusive mode.\n With that, our sound module is complete. It is definitely not \"state-of-the-art\" ... but hey, it works and it removes a lot of the DirectX burden that would normally be placed on us.\n Luckily though, we get to talk about something a lot more fun: Screen Transitions.\n[size=\"5\"] Screen Transitions\nScreen Transitions are things that are usually fun to write. Of course, most anything would be fun after playing with DirectSound. The screen transition is often one of the most important things in a game. If you have a lot of places where the view/screen completely changes, then a transition is typically needed in order to smooth things out. You do not want the user to just be \"jarred\" to the next scene. To the user, a transition is like riding in a Lexus, while having none is like riding an old Pan-head [lessthan][lessthan] inside motorcycle joke \u0026gt;\u0026gt;.\n I have taken an interesting approach with the screen transitions in this game. I decided there would be one main interface function. This function, intelligently called Transition(), is responsible for selecting a screen transition, at random, and calling it. This provides some break from the monotony of calling the same one over and over again. Of course, I have only provided one simple transition ( with 2 options ), it is your job to write more. All transitions require the surface you want to transition \"from\" on the primary buffer, and the surface you want to transition \"to\" on the back buffer.\n Here is the code for the interface function:;########################################################################\n; Transition Procedure\n;########################################################################\nTransition\tPROC\n\t;=======================================================\n\t; This function will call one of the our transitions\n\t; based on a random number. All transitions require\n\t; the primary buffer to be the surface that you want\n\t; to transition from and the back buffer to be the\n\t; surface you want to transition to. Both need to\n\t; be unlocked.\n\t;=======================================================\n\t;=============================\n\t; Get a random number\n\t;=============================\n\tINVOKE Get_Time\n\t;=============================\n\t; Mod the result with 2\n\t;=============================\n\tAND\tEAX, 1\n\t;=============================\n\t; Select the transition based\n\t; on our number\n\t;=============================\n\t.IF EAX == 0\n\t\t;==========================\n\t\t; Perform a Horizontal Wipe\n\t\t;==========================\n\t\tINVOKE Wipe_Trans, 6, WIPE_HORZ\n\t\t;=========================\n\t\t; Universal error check\n\t\t;=========================\n\t\t.IF EAX == FALSE\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ELSEIF EAX == 1\n\t\t;==========================\n\t\t; Perform a Vertical Wipe\n\t\t;==========================\n\t\tINVOKE Wipe_Trans, 4, WIPE_VERT\n\t\t;=========================\n\t\t; Universal error check\n\t\t;=========================\n\t\t.IF EAX == FALSE\n\t\t\tJMP\terr\n\t\t.ENDIF\n\t.ENDIF\ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nTransition\tENDP\n;########################################################################\n; END Transition\n;########################################################################The Transition() function grabs a random number by using the same method as our random shape generator, obtaining the time. This is not the optimum method, and we will be replacing it with a true random number generator later on. But, for now, it will have to do. The proper transition is then made based on the time, you can play with the parameters if you wish. I just selected a couple that didn\u0027t seem to take away too much of the screen each iteration.\n That is all that is there for the management function. It just keeps things random. You can still call a transition directly, I just thought it was more interesting to do it like this. Besides, on a large project, after 4-6 months of looking at the same transitions, you would probably be insane.\n Now, we can look at the actual screen transition: Wipe_Trans(). This routine allows us to perform either a vertical (top to bottom) or horizontal (left to right) transition taking away a width that is passed in each time. So, have a look at the code before we continue.;########################################################################\n; Wipe_Trans Procedure\n;########################################################################\nWipe_Trans PROC strip_width:DWORD, direction:DWORD\n\t;=======================================================\n\t; This function will perform either a horizontal or\n\t; a vertical wipe depending on what you pass in for the\n\t; direction paramter. The width of each step is \n\t; determined by the width that you pass in to it.\n\t;=======================================================\n\t;=========================================\n\t; Local Variables\n\t;=========================================\n\tLOCAL StartTime :DWORD\n\t;========================================\n\t; Setup the source rectangle and the \n\t; destination rectangle\n\t;\n\t; For the first iteration, the strip may \n\t; not be the height passed in. This is to \n\t; make sure we are on an even boundary \n\t; during the loop below\n\t;========================================\n\t.IF direction == WIPE_HORZ\n \tMOV SrcRect.top, 0\n \tMOV SrcRect.left, 0\n \tMOV EAX, app_width\n \tMOV ECX, strip_width\n \tXOR EDX, EDX\n \tDIV ECX\n \t.IF EDX == 0\n MOV EDX, strip_width\n \t.ENDIF\n \tMOV EBX, app_height\n \tMOV SrcRect.bottom, EBX\n \tMOV SrcRect.right, EDX\n \tMOV DestRect.top, 0\n \tMOV DestRect.left, 0\n \tMOV DestRect.bottom, EBX\n \tMOV DestRect.right, EDX\n\t.ELSEIF direction == WIPE_VERT\n \tMOV SrcRect.top, 0\n \tMOV SrcRect.left, 0\n \tMOV EAX, app_height\n \tMOV ECX, strip_width\n \tXOR EDX, EDX\n \tDIV ECX\n \tMOV EAX, app_width\n \t.IF EDX == 0\n MOV EDX, strip_width\n \t.ENDIF\n \tMOV SrcRect.bottom, EDX\n \tMOV SrcRect.right, EAX\n \tMOV DestRect.top, 0\n \tMOV DestRect.left, 0\n \tMOV DestRect.bottom, EDX\n \tMOV DestRect.right, EAX\n\t.ELSE\n \t;==================\n \t; Invalid direction\n \t;==================\n \tJMP err\n\t.ENDIF\n\t;================================\n\t; Get the starting time\n\t;================================\n\tINVOKE Start_Time, ADDR StartTime\n\t;================================\n\t; Blit the strip onto the screen\n\t;================================\n\tDDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\\\n \tlpddsback, ADDR DestRect, DDBLTFAST_WAIT\n\t;===============================\n\t; Make sure we succeeded\n\t;===============================\n\t.IF EAX != DD_OK\n \tJMP err\n\t.ENDIF\n\t;===================================================\n\t; Now adjust the distance between the left \u0026amp;\n\t; right, or top and bottom, so that the top, or\n\t; left, corner is where the right hand side was \n\t; at ... and the bottom, or right, is strip_width\n\t; away from the opposite corner.\n\t;===================================================\n\tMOV EAX, strip_width\n\t.IF direction == WIPE_HORZ\n \tMOV EBX, SrcRect.right\n \tMOV SrcRect.left, EBX\n \tMOV DestRect.left, EBX\n \tADD EBX, EAX\n \tMOV DestRect.right, EBX\n \tMOV SrcRect.right, EBX\n\t.ELSEIF direction == WIPE_VERT\n \tMOV EBX, SrcRect.bottom\n \tMOV SrcRect.top, EBX\n \tMOV DestRect.top, EBX\n \tADD EBX, EAX\n \tMOV DestRect.bottom, EBX\n \tMOV SrcRect.bottom, EBX\n\t.ENDIF\n\t;===================================\n\t; Wait to synchronize the time\n\t;===================================\n\tINVOKE Wait_Time, StartTime, TRANS_TIME\n\t;=====================================\n\t; Drop into a while loop and blit all\n\t; of the strips synching to our \n\t; desired transition rate\n\t;=====================================\n\t.WHILE TRUE\n \t;================================\n \t; Get the starting time\n \t;================================\n \tINVOKE Start_Time, ADDR StartTime\n \t;================================\n \t; Blit the strip onto the screen\n \t;================================\n \tDDS4INVOKE BltFast, lpddsprimary, SrcRect.left, SrcRect.top,\\\n lpddsback, ADDR DestRect, DDBLTFAST_WAIT\n \t;===============================\n \t; Make sure we succeeded\n \t;===============================\n \t.IF EAX != DD_OK\n JMP err\n \t.ENDIF\n \t;==================================\n \t; Have we reached our extents yet\n \t;==================================\n \tMOV EAX, SrcRect.bottom \n \tMOV EBX, app_height\n \tMOV ECX, SrcRect.right\n \tMOV EDX, app_width\n \t.IF EAX == EBX \u0026amp;\u0026amp; ECX == EDX\n ;======================\n ; Trans complete\n ;======================\n .BREAK\n \t.ELSE\n ;======================\n ; Adjust by the strip\n ;======================\n MOV EAX, strip_width\n .IF direction == WIPE_HORZ\n \t ADD SrcRect.left, EAX\n \t ADD SrcRect.right, EAX\n \t ADD DestRect.left, EAX\n \t ADD DestRect.right, EAX\n .ELSEIF direction == WIPE_VERT\n \t ADD SrcRect.top, EAX\n \t ADD SrcRect.bottom, EAX\n \t ADD DestRect.top, EAX\n \t ADD DestRect.bottom, EAX\n .ENDIF\n \t.ENDIF\n \t;===================================\n \t; Wait to synchronize the time\n \t;===================================\n \tINVOKE Wait_Time, StartTime, TRANS_TIME\n\t.ENDW \ndone:\n\t;===================\n\t; We completed\n\t;===================\n\treturn TRUE\nerr:\n\t;===================\n\t; We didn\u0027t make it\n\t;===================\n\treturn FALSE\nWipe_Trans ENDP\n;########################################################################\n; END Wipe_Trans\n;######################################################################## Notice, the first thing we do is setup the source and destination rectangles. We are going to be working with \"strips\" of the bitmap. So, I am going to walk you through exactly what happens when the routine is called.\nPretend the user passed in a 7 for the \"strip_width\" parameter and they want a horizontal transition. The first section finds out if the strip\u0027s width can go evenly into the screen width. If the strip can go in evenly, then it sets the length to be equal to the width. However, if it can\u0027t, then the remainder is placed in the width. The reason we place the remainder in, is that the strip is going to have that little strip left over when we finish. Example: with a 7 and a screen width of 640 you will have 91 sections of 7 and a section of 3 left over. So, for the first strip we would store a 3 for the width. From here on note: You would do the exact same thing, except for the height/top/bottom, if you were doing a vertical wipe.\nNext, we blit that small 3 pixel strip over from the back buffer onto the primary buffer. With that out of the way we can get setup to do blits with a 7-pixel width. The way we setup is by moving the right-hand side of the rectangle over to the left-hand side. Then, we add the strip_width, in this case 7, to the left-hand side to obtain the new right-hand side. So, for our example, the left coordinate of the rectangles would now have a 3, and the right coordinate would now have a 10. We need this adjustment since our loop is only going to work with 7-pixel strips in the bitmap, instead of an increasing portion of the bitmap.\nWe are now ready to delve into our loop. The first thing we do, aside from getting the starting time, is blit the current strip (this is why we had to setup the rectangles out of the loop). Then, we check the right hand side and bottom of our source rectangle is still inside the limits of our screen. If it has met the extents, then we break from the loop since we are finished. If we haven\u0027t yet reached the edges, then we adjust the rectangles. To adjust the rectangles, we add the strip_width to both the left and right of our source and destination rectangles. By adding to both sides we are able to blit in strips of 7-pixels. But, if we only added to the right-hand side we would blit in pixels of 7, 14, 21, etc. Which, needless to say, is much, much slower than the way we are doing it. Finally, we synchronize the time to our desired rate and keep doing the loop until we are finished.\nThere isn\u0027t very much to the routine, but it should give you a starting point in making screen transitions. Here are some suggestions in case you are lacking in creativity. Make a modified wipe that would have a bunch of strips at intervals grow to meet each other, like something you would see with a pair of blinds in your house. Design a transition that zooms in to a single pixel, then zooms out to the new picture. Create a circular wipe, or even a spiral one. There are many good articles out there on demo effects and I suggest reading some of them if you find this stuff interesting. Finally, if you are really desperate for an idea, just go and play a game and see how their transitions work. Mimicry is one of the first steps in learning.\nAt any rate, everything in our modules is complete. We now have everything that we need to pretty up the game. So, in the next section, we will tie everything into that nice little bow, just as we always do.[size=\"5\"]Putting More Pieces Together\nThe title to this section is really accurate. Most programming, at least in some way, is like a jigsaw puzzle. It is about combining pieces in a manner that works best. Often times, you will obtain a completely different result just be re-ordering some of the steps. In this sense, programming is intellectually stimulating. There are so many millions of ways to accomplish any given task. Keep that in mind while reviewing the code I provide. It isn\u0027t written in blood anyplace that you have to do things a certain way -- at least, I don\u0027t think it is.\nThe module, we are going to look at for the changes is the Menu module. The reason we are using this module is that it makes use of all of our new features, which makes it perfect for use as an example.\nYou had better take a look at the code for the new module before we go any further. ;###########################################################################\n;###########################################################################\n; ABOUT Menu:\n;\n;\tThis code module contains all of the functions that relate to \n; the menu that we use. \n;\n;\tThere are routines for each menu we will have. One for the main\n; menu and one for the load/save menu stuff.\n;\n;\tNOTE: We could have combined these two functions into one generic \n; function that used parameters to determine the bahavior. But, by coding\n; it explicitly we get a better idea for what is going on in the code.\n;\n;###########################################################################\n;###########################################################################\n;###########################################################################\n;###########################################################################\n; THE COMPILER OPTIONS\n;###########################################################################\n;###########################################################################\n\t.386\n\t.MODEL flat, stdcall\n\tOPTION CASEMAP :none ; case sensitive\n;###########################################################################\n;###########################################################################\n; THE INCLUDES SECTION\n;###########################################################################\n;###########################################################################\n\t;================================================\n\t; These are the Inlcude files for Window stuff\n\t;================================================\n\tINCLUDE \\masm32\\include\\windows.inc\n\tINCLUDE \\masm32\\include\\comctl32.inc\n\tINCLUDE \\masm32\\include\\comdlg32.inc\n\tINCLUDE \\masm32\\include\\shell32.inc\n\tINCLUDE \\masm32\\include\\user32.inc\n\tINCLUDE \\masm32\\include\\kernel32.inc\n\tINCLUDE \\masm32\\include\\gdi32.inc\n\t;===============================================\n\t; The Lib\u0027s for those included files\n\t;================================================\n\tINCLUDELIB \\masm32\\lib\\comctl32.lib\n\tINCLUDELIB \\masm32\\lib\\comdlg32.lib\n\tINCLUDELIB \\masm32\\lib\\shell32.lib\n\tINCLUDELIB \\masm32\\lib\\gdi32.lib\n\tINCLUDELIB \\masm32\\lib\\user32.lib\n\tINCLUDELIB \\masm32\\lib\\kernel32.lib\n\t;====================================\n\t; The Direct Draw include file\n\t;====================================\n\tINCLUDE Includes\\DDraw.inc\n\t;====================================\n\t; The Direct Input include file\n\t;====================================\n\tINCLUDE Includes\\DInput.inc\n\t;====================================\n\t; The Direct Sound include file\n\t;====================================\n\tINCLUDE Includes\\DSound.inc\n\t;=================================================\n\t; Include the file that has our protos\n\t;=================================================\n\tINCLUDE Protos.inc\n;###########################################################################\n;###########################################################################\n; LOCAL MACROS\n;###########################################################################\n;###########################################################################\n\tm2m MACRO M1, M2\n\t\tPUSH\t\tM2\n\t\tPOP\t\tM1\n\tENDM\n\treturn MACRO arg\n\t\tMOV\tEAX, arg\n \t\tRET\n\tENDM\n;#################################################################################\n;#################################################################################\n; Variables we want to use in other modules\n;#################################################################################\n;#################################################################################\n;#################################################################################\n;#################################################################################\n; External variables\n;#################################################################################\n;#################################################################################\n\t;=================================\n\t; The DirectDraw stuff\n\t;=================================\n\tEXTERN\tlpddsprimary\t:LPDIRECTDRAWSURFACE4\n\tEXTERN\tlpddsback\t:LPDIRECTDRAWSURFACE4\n\t;=========================================\n\t; The Input Device state variables\n\t;=========================================\n\tEXTERN keyboard_state\t:BYTE\n;#################################################################################\n;#################################################################################\n; BEGIN INITIALIZED DATA\n;#################################################################################\n;#################################################################################\n\t.DATA\n\t;===============================\n\t; Strings for the bitmaps\n\t;===============================\n\tszMainMenu\tDB \"Art\\Menu.sfp\",0\n\tszFileMenu\tDB \"Art\\FileMenu.sfp\",0\n\t;================================\n\t; Our very cool menu sound\n\t;================================\n\tszMenuSnd\tDB \"Sound\\Background.wav\",0\n\t;===============================\n\t; PTR to the BMP\u0027s\n\t;===============================\n\tptr_MAIN_MENU\tDD 0\n\tptr_FILE_MENU\tDD 0\n\t;===============================\n\t; ID for the Menu sound\n\t;===============================\n\tMenu_ID\t\tDD 0\n\t;======================================\n\t; A value to hold lPitch when locking\n\t;======================================\n\tlPitch\t\tDD 0\n\t;========================================\n\t; Let\u0027s us know if we need to transition\n\t;========================================\n\tfirst_time\tDD 0\n;#################################################################################\n;#################################################################################\n; BEGIN CONSTANTS\n;#################################################################################\n;#################################################################################\n;#################################################################################\n;#################################################################################\n; BEGIN EQUATES\n;#################################################################################\n;#################################################################################\n\t;=================\n\t;Utility Equates\n\t;=================\nFALSE\t\tEQU\t0\nTRUE\t\tEQU\t1\n\t;=================\n\t; The Screen BPP\n\t;=================\nscreen_bpp\tEQU\t16\n;=================\n; The Menu Codes\n;=================\n\t; Generic\nMENU_ERROR\tEQU\t0h\nMENU_NOTHING\tEQU\t1h\n\t; Main Menu\nMENU_NEW\tEQU\t2h\nMENU_FILES\tEQU\t3h\nMENU_GAME\tEQU\t4h\nMENU_EXIT\tEQU\t5h\n\t; File Menu\nMENU_LOAD\tEQU\t6h\nMENU_SAVE\tEQU\t7h\nMENU_MAIN\tEQU\t8h\n;#################################################################################\n;#################################################################################\n; BEGIN THE CODE SECTION\n;#################################################################################\n;#################################################################################\n .CODE\n;########################################################################\n; Init_Menu Procedure\n;########################################################################\nInit_Menu\tPROC\t\n\t;===========================================================\n\t; This function will initialize our menu systems\n\t;===========================================================\n\t;=================================\n\t; Local Variables\n\t;=================================\n\t;======================================\n\t; Read in the bitmap and create buffer\n\t;======================================\n\tINVOKE Create_From_SFP, ADDR ptr_MAIN_MENU, ADDR szMainMenu, screen_bpp\n\t;====================================\n\t; Test for an error\n\t;====================================\n\t.IF EAX == FALSE\n\t\t;========================\n\t\t; We failed so leave\n\t\t;========================\n\t\tJMP\terr\n\t.ENDIF\n\t;======================================\n\t; Read in the bitmap and create buffer\n\t;======================================\n\tINVOKE Create_From_SFP, ADDR ptr_FILE_MENU, ADDR szFileMenu, screen_bpp\n\t;====================================\n\t; Test for an error\n\t;====================================\n\t.IF EAX == FALSE\n\t\t;=\n", "dateCreated": "2000-01-23T15:59:06+0000", "datePublished": "2000-01-23T15:59:00+0000", "dateModified": "2000-01-23T15:59:00+0000", "pageStart": 1, "pageEnd": 1, "author": { "@type": "Person", "name": "Myopic Rhino", "image": "https://secure.gravatar.com/avatar/16f4f23aa8088c2c27c829623874b42e?d=https://www.gamedev.net/uploads/monthly_2017_08/M.png.3d2e4bcade48bd80a1d6554f9c036e99.png", "url": "https://www.gamedev.net/profile/6-dave-astle/" }, "publisher": { "@type": "Organization", "name": "Myopic Rhino", "image": "https://secure.gravatar.com/avatar/16f4f23aa8088c2c27c829623874b42e?d=https://www.gamedev.net/uploads/monthly_2017_08/M.png.3d2e4bcade48bd80a1d6554f9c036e99.png", "logo": { "@type": "ImageObject", "url": "https://secure.gravatar.com/avatar/16f4f23aa8088c2c27c829623874b42e?d=https://www.gamedev.net/uploads/monthly_2017_08/M.png.3d2e4bcade48bd80a1d6554f9c036e99.png" }, "url": "https://www.gamedev.net/profile/6-dave-astle/" }, "interactionStatistic": [ { "@type": "InteractionCounter", "interactionType": "http://schema.org/ViewAction", "userInteractionCount": 1927 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/FollowAction", "userInteractionCount": 6 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/ReviewAction", "userInteractionCount": 0 }, { "@type": "InteractionCounter", "interactionType": "http://schema.org/CommentAction", "userInteractionCount": 0 } ], "image": { "@type": "ImageObject", "url": "https://secure.gravatar.com/avatar/16f4f23aa8088c2c27c829623874b42e?d=https://www.gamedev.net/uploads/monthly_2017_08/M.png.3d2e4bcade48bd80a1d6554f9c036e99.png", "width": "500", "height": "500" }, "aggregateRating": { "@type": "AggregateRating", "ratingValue": 0, "ratingCount": 0 }, "commentCount": 0 } { "@context": "http://www.schema.org", "@type": "WebSite", "name": "GameDev.net", "url": "https://www.gamedev.net/", "potentialAction": { "type": "SearchAction", "query-input": "required name=query", "target": "https://www.gamedev.net/search/?q={query}" }, "inLanguage": [ { "@type": "Language", "name": "English (USA)", "alternateName": "en-US" } ] } { "@context": "http://www.schema.org", "@type": "Organization", "name": "GameDev.net", "url": "https://www.gamedev.net/", "address": { "@type": "PostalAddress", "streetAddress": "", "addressLocality": null, "addressRegion": null, "postalCode": null, "addressCountry": null } } { "@context": "http://schema.org", "@type": "BreadcrumbList", "itemListElement": [ { "@type": "ListItem", "position": 1, "item": { "@id": "https://www.gamedev.net/articles/", "name": "Articles" } }, { "@type": "ListItem", "position": 2, "item": { "@id": "https://www.gamedev.net/articles/programming/", "name": "Programming" } }, { "@type": "ListItem", "position": 3, "item": { "@id": "https://www.gamedev.net/articles/programming/general-and-gameplay-programming/", "name": "General and Gameplay Programming" } } ] } { "@context": "http://schema.org", "@type": "ContactPage", "url": "https://www.gamedev.net/contact/" } Important Information By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.   I accept We are the game development community. Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up! Sign me up!