MS_ZONES INTRODUCTION One if the key areas of writing a game or for that matter any graphic FRONT END / interface is developing a point and click interface that the user can click the mouse in to select program controls and other features. Usually this process is tedious from BASIC because of all the IF END constructs. And then it is still a pretty slow process. MAGE has a powerful and fast zone handling feature built in. This feature is already installed into the MS_DESIGN SHELL. There are several routines that make this a FAST and easy feature to work with. There are 255 zones available to set up and manipulate. To set up a zone: ----------------------------------------------------------------- ms_zoneset(v1,v2,v3,v4,v5) ! Init a zone (Turns it on also) v1=zone number (1-255) v2 & v3 = top left corner of zone rectangle v4 & v5 = bottom right corner of zone rectangle ----------------------------------------------------------------- To turn a zone off or on: ms_zonestatus(v1,v2) ! Sets the zone on or off v1=zone (1-255) v2=status 1=ON 0=OFF Note: When a ZONE is turned off, this means it will not be checked when you call the MS_ZONECHECK command. ----------------------------------------------------------------- To check and see if a location has entered a zone: ms_zonecheck(v1,v2,v3,v4,v5) ! Check zones v1=horizontal location of object v2=vertical location of object v3=how many pixels across to determine total width of object v4=how many pixels down to determine total length of object v5=how many zones to check. (WORKS FROM BOTTOM UP STARTING AT 1) TO SEE IF A MOUSE WHEN INTO A ZONE AREA: ms_zonecheck(MOUSEX,MOUSEY,0,0,20) ! Check 20 zones ' IF ms_var% ' ' ms_var% holds the exact zone the mouse was in. ' ENDIF ' ' Or how about...(checking a 16x10 sprite location...) ' ms_zonecheck(ms_shor&(0)+7,ms_sver&(0)+4,15,9,20) ! Check 20 zones IF ms_var% ' ' ms_var% holds the exact zone sprite 0 entered. ' ENDIF ----------------------------------------------------------------- There are 2 global zone move routines that allow you to move all of the zone areas at one time. ms_zonejupdate(v1,v2,v3,v4,v5) ! Move zones based on Joystick. v1=Starting Zone v2=HORIZONTAL pixels to move v3=VERTICAL pixels to move v4=Joystick direction. (You can pass STICK (1) or STICK (0) ) v5=How many zones to move starting at 1 NOTE: This routine works by passing information to it based on the same values used by the STICK command. If you pass a value 8 (moving to the right) to this routine the resulting ZONES would actually move to the LEFT, as if they were scrolling by the user. ms_zonemove(v1,v2,v3,v4) ! Move all zones based on values v1=Starting zone to move. v2=Horizontal pixels to move zone. v3=Vertical pixels to move zone. v4=How many zones to move starting at 1. Simply moves all the zones at one time. Useful for game screens. ----------------------------------------------------------------- The MS_BLIT commands. While the built in page flipping/screen redraw commands of the MAGE system are quite fast and easy to use they really don't represent the fastest way to redraw or clear the background where your sprites will be drawn on. Games like KID_KONG and EVADER wouldn't run at 30 frames a second if it weren't for these faster methods of screen handling. The MS_BLIT commands are so fast because they are dedicated routines to perform a certain amount of screen redraw or clear. No parameters to control the length of the redraw are needed. Therefore the routines can be optimized to perform the task as fast as possible. There are two MS_BLIT type available. The CLR blits vs the MOV blits: The ms_clr% routines will clear a segment of memory lighting fast where as the ms_mov% routines will perform a memory move blit just about as fast as possible with a 68000 cpu. While experienced coders will be able to use these routines to perform other tasks than just for the background of the game, these routines were designed to speed of the page flip/screen redraw portion of the MAGE system. There are 4 sizes of blits available for each type of blit. 140, 160, 180, 200 scan lines, we say scan lines because they are designed to work on a certain size of sequential memory block that works out be a uniform number of scan lines. The MS_CLR% routines. (xxx can be equal to 140,160,180,200) ~c:ms_clrxxx%(L:adr%) ! Clear a segment of memory...FAST!! VITAL!! IMPORTANT!! PLEASE UNDERSTAND THIS!!! Because of the way the MS_CLR% routines work adr% should be equal to the address that you want to clear PLUS the number of scan lines * 160. In otherwords, the clr routines work from bottom to top. So if you were using the ms_clr140% routine: ~c:ms_clr140%(L:adr%+(140*160)) ! Easy enough eh? FAILURE to correctly add the correct number of bytes will surely result in unwanted memory being cleared, resulting in a bomb!!! ----------------------------------------------------------------- The MS_MOV% routines. (xxx can be equal to 140,160,180,200) ~c:ms_movxxx%(L:source%,L:dest%) ! Blit a chunk of memory!! This routine is very easy to work with, simply supply the starting source% address and the starting dest% address. You don't have to do anything tricky to perform the blit. Just remember that the actual number of bytes moved relates to the number of scan lines used * 160. (200*160=32000...A full screen!!) ----------------------------------------------------------------- Actually using the blits in your own program: So, how do you actually use the blits in your own program to gain that extra speed needed? The easiest and fastest way to accomplish this is to use the blit routines to REPLACE the MS_VSYNCx( ) commands with the MS_MOVxxx% commands. Notice that the MS_BLIT commands do not use PROCEDURES but the actual C: command itself. Remeber, SPEED is vital at this point so we don't use parameter passing for the blit commands. Let's assume in your game your using the standard MS_VSYNC20(10,0) routine to page flip and redraw the background. You could replace this command with: MS_VSYNC20(10,0) ! The old slower way to page flip and redraw with ~C:ms_vsync%(L:ms_vs1%,L:ms_vs2%,L:ms_vscnt%,W:0) ! Page flip ~C:ms_mov200%(L:ms_background%,L:ms_logical%) ! Redraw the screen If you only needed to redraw a smaller section of the screen because your sprites never go past a certain scan line than you could replace the 200 with say 180 or 160. And ofcourse you could replace the ms_mov200% with the command: ~C:ms_clr200%(L:ms_logical%+(200*160)) ! clear the screen to clear the entire screen lightning fast!! NOTE:You will have to type in the above lines EXACTLY as shown in order to avoid a system bomb or error. Technically the ms_blit commands will let the more experienced coder generate complex animations or indeed complete game speeds of 50-60 frames a second. The key is to only redraw the exact amount of background needed. If your game has a text display either on top or bottom just pass the correct locations needed to draw only in the area the sprites will be redraw every cycle at. VERTICAL SCROLLING with the MS_MOVxxx% routine. It should be noted that vertically scrolling areas of memory can easily be designed by changing the pointer of the background screen. ~C:ms_vsync%(L:ms_vs1%,L:ms_vs2%,L:ms_vscnt%,W:0) ! Page flip ~C:ms_mov200%(L:scoll_adr%,L:ms_logical%) ! Redraw the screen If scroll_adr% was set up to point to the BOTTOM of your scroll buffer area then each cycle you could add or subtract 160 from scroll_adr% to perfrom scrolling!! It's very easy to acheive!!