home *** CD-ROM | disk | FTP | other *** search
- ;-------T-------T------------------------T----------------------------------;
- ;Map Editor V0.1
- ;---------------
- ;A very fast map editor, normally we would do one of these with the OS, but
- ;this one hardware scrolls in the same way as it would in a game :-). It
- ;still needs a lot of work, but you can play with it.
- ;
- ;Push SPACE to switch between the map and tile screen. You can pickup
- ;and putdown tiles using the left mouse button. Press right mouse button
- ;to exit.
-
- INCDIR "INCLUDES:"
- INCLUDE "exec/exec_lib.i"
- INCLUDE "games/games_lib.i"
- INCLUDE "games/games.i"
-
- CALL MACRO
- jsr _LVO\1(a6)
- ENDM
-
- SAVEREGS MACRO
- MOVEM.L D0-D7/A0-A6,-(SP)
- ENDM
-
- RETURNREGS MACRO
- MOVEM.L (SP)+,D0-D7/A0-A6
- ENDM
-
- SECTION "MapEditor",CODE
-
- ;===========================================================================;
- ; INITIALISE DEMO
- ;===========================================================================;
-
- Start: MOVEM.L A0-A6/D1-D7,-(SP)
- lea All_Offsets,a5
- move.l #KP_Keys,Keys(a5)
-
- move.l ($4).w,a6
- lea GMS_Name(pc),a1
- moveq #$00,d0
- CALL OpenLibrary
- move.l d0,GMS_Base(a5)
- beq .Error_GMS
-
- move.l GMS_Base(a5),a6
- sub.l a0,a0
- CALL SetUserPrefs
-
- lea LevelMaps(pc),a1
- move.l MAP_Picture(a1),a1
- CALL LoadPic
- tst.w d0
- bne .Error_Picture
-
- lea GS_MapScreen(pc),a0
- move.l PIC_Palette(a1),GS_Palette(a0)
- move.w PIC_Planes(a1),GS_Planes(a0)
- move.w PIC_ScrType(a1),GS_ScrType(a0)
- CALL AddScreen
- tst.w d0
- bne.s .Error_MapScreen
-
- lea GS_TileScreen(pc),a0
- move.l PIC_Data(a1),GS_MemPtr1(a0)
- move.l PIC_Palette(a1),GS_Palette(a0)
- move.w PIC_Height(a1),GS_PicHeight(a0)
- move.w PIC_ByteWidth(a1),GS_PicByteWidth(a0)
- move.w PIC_Planes(a1),GS_Planes(a0)
- CALL AddScreen
- tst.l d0
- bne.s .Error_TileScreen
-
- lea GS_MapScreen(pc),a0
- lea LevelMaps(pc),a1
- CALL InitMap
- tst.w d0
- bne.s .Error_Map
-
- lea LevelMaps(pc),a1 ;a1 = Map structure.
- moveq #0,d0 ;d0 = X destination.
- moveq #0,d1 ;d1 = Y destination.
- CALL DrawMap ;>> = Draw all the map blocks.
-
- lea GS_MapScreen(pc),a0
- lea SPR_Pointer(pc),a1
- CALL InitSprite
- tst.w d0
- bne.s .Error_Pointer
-
- bsr.s Main
-
- .ReturnToDOS
- move.l GMS_Base(a5),a6
- lea SPR_Pointer(pc),a1
- CALL FreeSprite
- .Error_Pointer
- lea LevelMaps(pc),a1
- CALL FreeMap
- .Error_Map
- lea GS_TileScreen(pc),a0
- CALL DeleteScreen
- .Error_TileScreen
- lea GS_MapScreen(pc),a0
- CALL DeleteScreen
- .Error_MapScreen
- lea LevelMaps(pc),a1
- move.l MAP_Picture(a1),a1
- CALL FreePic
- .Error_Picture
- move.l GMS_Base(a5),a1
- move.l ($4).w,a6
- CALL CloseLibrary
- .Error_GMS
- MOVEM.L (SP)+,A0-A6/D1-D7
- moveq #$00,d0
- rts
-
- ;===========================================================================;
- ; MAIN LOOP
- ;===========================================================================;
-
- Main: CALL InitJoyPorts
-
- ;---------------------------------------------------------------------------;
- ; DRAW TILES LOOP
- ;---------------------------------------------------------------------------;
-
- Show_Map:
- clr.b Display(a5)
- lea GS_MapScreen(pc),a0
- lea SPR_Pointer(pc),a1
- CALL InitSprite ;Initialise sprite for this screen.
- CALL UpdateSprite ;Display the sprite.
- CALL ShowScreen ;Show the tile screen.
-
- .loop moveq #JPORT1,d0
- CALL ReadMouse
- btst #MB_RMB,d0
- beq.s .move
- rts
- .move bsr Move_Pointer
- btst #MB_LMB,d0
- beq.s .VBL
- bsr Draw_Tile
- .VBL CALL WaitSVBL
- lea GS_MapScreen(pc),a0
- lea SPR_Pointer(pc),a1
- CALL MoveSprite
- move.l Keys(a5),a1
- CALL ReadKey
- cmp.b #" ",d0
- beq.s Show_Tiles
- bra.s .loop
-
- ;---------------------------------------------------------------------------;
- ; TILE SELECTION LOOP
- ;---------------------------------------------------------------------------;
-
- Show_Tiles:
- st Display(a5)
- lea GS_TileScreen(pc),a0
- lea SPR_Pointer(pc),a1
- CALL InitSprite ;Initialise sprite for this screen.
- CALL UpdateSprite ;Display the sprite.
- CALL ShowScreen ;Show the tile screen.
- .loop moveq #JPORT1,d0
- CALL ReadMouse
- btst #MB_RMB,d0
- beq.s .move
- rts
- .move bsr.s Move_Pointer
- btst #MB_LMB,d0
- beq.s .VBL
- bsr.s Pickup_Tile
- .VBL CALL WaitSVBL
- lea GS_TileScreen(pc),a0
- lea SPR_Pointer(pc),a1
- CALL MoveSprite
- move.l Keys(a5),a1
- CALL ReadKey
- cmp.b #" ",d0
- beq Show_Map
- bra.s .loop
-
- Pickup_Tile:
- SAVEREGS
- lea GS_TileScreen(pc),a0 ;a0 = GameScreen
- lea LevelMaps(pc),a1 ;a1 = Map structure.
- lea SPR_Pointer(pc),a2 ;a2 = Mouse pointer.
- move.w SPR_XCoord(a2),d0 ;d0 = XCoord [mouse]
- move.w SPR_YCoord(a2),d1 ;d1 = YCoord [mouse]
- add.w GS_PicXOffset(a0),d0 ;d0 = (XCoord)+PicXCoord
- add.w GS_PicYOffset(a0),d1 ;d1 = (YCoord)+PicYCoord
- lsr.w #4,d0 ;d0 = /16 [XPlace to store block]
- lsr.w #4,d1 ;d1 = /16 [YPlace to store block]
- mulu #20,d1
- add.w d0,d1
- move.w d1,BlockNumber(a5)
- RETURNREGS
- rts
-
- ;===========================================================================;
- ; MOVE MOUSE POINTER & SCREEN
- ;===========================================================================;
-
- Move_Pointer:
- SAVEREGS
- lea SPR_Pointer(pc),a1
- move.w d0,d1
- asr.w #8,d0 ;d0 = X Change
- ext.w d1
- add.w d0,SPR_XCoord(a1)
- add.w d1,SPR_YCoord(a1)
- moveq #$00,d1
- moveq #$00,d2
- .ChkLX tst.w SPR_XCoord(a1)
- bgt.s .ChkTY
- move.w SPR_XCoord(a1),d1
- clr.w SPR_XCoord(a1)
- .ChkTY tst.w SPR_YCoord(a1)
- bgt.s .ChkRX
- move.w SPR_YCoord(a1),d2
- clr.w SPR_YCoord(a1)
- .ChkRX move.w SPR_XCoord(a1),d0
- move.w GS_ScrWidth(a0),d3
- subq.w #1,d3
- cmp.w d3,d0
- blt.s .ChkBY
- move.w d0,d1
- sub.w d3,d1
- move.w d3,SPR_XCoord(a1)
- .ChkBY move.w SPR_YCoord(a1),d0
- move.w GS_ScrHeight(a0),d3
- subq.w #1,d3
- cmp.w d3,d0
- blt.s .done
- move.w d0,d2
- sub.w d3,d2
- move.w d3,SPR_YCoord(a1)
-
- .done tst.w d1
- bne.s Move_Picture
- tst.w d2
- bne.s Move_Picture
- RETURNREGS
- rts
-
- ;---------------------------------------------------------------------------;
- ; MOVE PICTURE
- ;---------------------------------------------------------------------------;
- ;Requires: d1 = XChange
- ; d2 = YChange
-
- Move_Picture:
- tst.b Display(a5)
- beq.s Move_Map
- add.w d1,GS_PicXOffset(a0)
- add.w d2,GS_PicYOffset(a0)
- .ChkTY tst.w GS_PicYOffset(a0)
- bge.s .ChkLX
- clr.w GS_PicYOffset(a0)
- .ChkLX tst.w GS_PicXOffset(a0)
- bgt.s .ChkBY
- clr.w GS_PicXOffset(a0)
- .ChkBY move.w GS_PicHeight(a0),d0
- sub.w GS_ScrHeight(a0),d0
- cmp.w GS_PicYOffset(a0),d0
- bge.s .ChkRX
- move.w d0,GS_PicYOffset(a0)
- .ChkRX move.w GS_PicWidth(a0),d0
- sub.w GS_ScrWidth(a0),d0
- cmp.w GS_PicXOffset(a0),d0
- bge.s .move
- move.w d0,GS_PicXOffset(a0)
- .move CALL MovePicture
- RETURNREGS
- rts
-
- ;---------------------------------------------------------------------------;
- ; MOVE AND AND DRAW MAP ROWS
- ;---------------------------------------------------------------------------;
-
- Move_Map:
- cmp.w #16,d1
- blt.s .ChkL
- move.w #16,d1
- .ChkL cmp.w #-16,d1
- bgt.s .go
- move.w #-16,d1
- .go add.w d1,GS_PicXOffset(a0)
- add.w d2,GS_PicYOffset(a0)
- .ChkTY tst.w GS_PicYOffset(a0)
- bge.s .ChkLX
- clr.w GS_PicYOffset(a0)
- .ChkLX tst.w GS_PicXOffset(a0)
- bgt.s .ChkBY
- clr.w GS_PicXOffset(a0)
- .ChkBY move.w GS_PicYOffset(a0),d0
- cmp.w GS_ScrHeight(a0),d0
- blt.s .ChkRX
- move.w GS_ScrHeight(a0),GS_PicYOffset(a0)
- .ChkRX cmp.w #(X_SCREENS-1)*320,GS_PicXOffset(a0)
- blt.s .move
- move.w #(X_SCREENS-1)*320,GS_PicXOffset(a0)
- .move CALL MovePicture
- tst.w d1
- bgt.s .Right
- beq.s .done
- .Left lea LevelMaps(pc),a1 ;a1 = Map structure.
- move.w GS_PicXOffset(a0),d0 ;d0 = PicXOffset
- lsr.w #4,d0 ;d0 = /16
- move.w d0,MAP_XStart(a1) ;a1 = The XCoord to get the row.
- clr.w MAP_YStart(a1) ;a1 = The YCoord to get the row.
- moveq #00,d0 ;d0 = X destination.
- moveq #00,d1 ;d1 = Y destination.
- CALL DrawMapVRow ;>> = Draw a row of map blocks.
- .done RETURNREGS
- rts
-
- .Right lea LevelMaps(pc),a1 ;a1 = Map structure.
- move.w GS_PicXOffset(a0),d0 ;d0 = PicXOffset
- lsr.w #4,d0 ;d0 = /16
- add.w #(336-16)/16,d0
- move.w d0,MAP_XStart(a1) ;a1 = The XCoord to get the row.
- clr.w MAP_YStart(a1) ;a1 = The YCoord to get the row.
- move.w #336-16,d0 ;d0 = X destination.
- moveq #00,d1 ;d1 = Y destination.
- CALL DrawMapVRow ;>> = Draw a row of map blocks.
- RETURNREGS
- rts
-
- ;===========================================================================;
- ; DRAW MAP TILE TO SCREEN
- ;===========================================================================;
-
- Draw_Tile:
- SAVEREGS
- lea GS_MapScreen(pc),a0 ;a0 = GameScreen
- lea LevelMaps(pc),a1 ;a1 = Map structure.
- lea SPR_Pointer(pc),a2 ;a2 = Mouse pointer.
-
- ;Put the tile in the map data.
-
- move.l MAP_MapList(a1),a3 ;a3 = List of maps.
- move.l (a3),a3 ;a3 = Level 1 map data.
- move.w SPR_XCoord(a2),d0 ;d0 = XCoord [mouse]
- move.w SPR_YCoord(a2),d1 ;d1 = YCoord [mouse]
- add.w GS_PicXOffset(a0),d0 ;d0 = (XCoord)+PicXCoord
- add.w GS_PicYOffset(a0),d1 ;d1 = (YCoord)+PicYCoord
- lsr.w #4,d0 ;d0 = /16 [XPlace to store block]
- lsr.w #4,d1 ;d1 = /16 [YPlace to store block]
- move.w d0,MAP_XStart(a1) ;a1 = Make a note for Draw_Tile()
- move.w d1,MAP_YStart(a1) ;a1 = Make a note for Draw_Tile()
- lsl.w #1,d0 ;d0 = *2 [word]
- add.w d0,a3 ;a3 = (Map)+XOffset
- mulu #M_WIDTH,d1 ;d1 = *RowSize
- add.w d1,a3 ;a3 = (Map)+YOffset
- move.w BlockNumber(a5),(a3) ;a3 = Store new block number.
-
- ;Draw the map tile.
-
- move.w SPR_XCoord(a2),d0
- move.w GS_PicXOffset(a0),d1 ;Correct the XCoord from the offset.
- and.w #%1111,d1
- add.w d1,d0
- move.w SPR_YCoord(a2),d1
- add.w GS_PicYOffset(a0),d1
- and.w #%1111111111110000,d0
- and.w #%1111111111110000,d1
- CALL DrawMapTile
- RETURNREGS
- rts
-
- ;===========================================================================;
- ; DATA
- ;===========================================================================;
-
- GMS_Name:
- dc.b "games.library",0
- even
-
- AMT_PLANES = 5
-
- GS_MapScreen:
- dc.l GSV1,0 ;Structure version.
- dc.l 0,0,0 ;Screen Memory 1/2/3.
- dc.l 0 ;Screen link.
- dc.l 0 ;Address of palette.
- dc.l 0 ;Address of rasterlist.
- dc.l 0 ;Amt of colours in palette.
- dc.w 320,256 ;Screen Width, Height.
- dc.w 336,336/8,256*2 ;Picture Widths, Height.
- dc.w 0 ;Amount of planes
- dc.w 0,0 ;X/Y Screen offset.
- dc.w 0,0 ;X/Y Picture offset.
- dc.l HSCROLL|VSCROLL|SBUFFER ;Special attributes.
- dc.w LORES|COL12BIT ;Screen mode.
- dc.w 0 ;Screen type
-
- GS_TileScreen:
- dc.l GSV1,0 ;Structure version.
- dc.l 0,0,0 ;Screen Memory 1/2/3.
- dc.l 0 ;Screen link.
- dc.l 0 ;Address of palette.
- dc.l 0 ;Address of rasterlist.
- dc.l 0 ;Amt of colours in palette.
- dc.w 320,256 ;Screen Width, Height.
- dc.w 0,0,0 ;Picture Widths, Height.
- dc.w 0 ;Amount of planes
- dc.w 0,0 ;X/Y Screen offset.
- dc.w 0,0 ;X/Y Picture offset.
- dc.l HSCROLL|VSCROLL ;Special attributes.
- dc.w LORES|COL12BIT ;Screen mode.
- dc.w 0 ;Screen type
-
- ;===========================================================================;
- ; MOUSE POINTER
- ;===========================================================================;
-
- SPR_Pointer:
- dc.l SPV1,0 ;Structure version.
- dc.w 0 ;Number 0.
- dc.l GFX_Pointer ;Pointer to graphic.
- dc.w 0,0 ;Beginning X/Y position
- dc.w 0 ;Current frame.
- dc.w 16,11 ;Width, Height.
- dc.w 4 ;Amount of colours.
- dc.w 16 ;Colour start in palette.
- dc.w 2 ;Amount of planes.
- dc.w LORES ;Resolution.
- dc.w 0 ;PlayField position.
- dc.w 0 ;Special attributes.
-
- ;===========================================================================;
- ; MAP STRUCTURE
- ;===========================================================================;
-
- X_SCREENS = 10
- Y_SCREENS = 10
-
- M_WIDTH = ((320/16)*MAPSIZE_WORD)*X_SCREENS
- M_HEIGHT = (256/16)*Y_SCREENS
-
- LevelMaps:
- dc.l MPV1,0 ;Structure version.
- dc.w BUFFER1 ;Buffer to blit to.
- dc.w 0 ;Map number to access.
- dc.l .Levels ;Pointer to map list.
- dc.w M_WIDTH,M_HEIGHT ;Total Width in bytes, Height.
- dc.w 0,0 ;XStart, YStart.
- dc.w MAPSIZE_WORD ;Entry Size - WORD.
- dc.l $0000ffff ;Entry Mask - set for word.
- dc.w 16,16/8,16 ;Tile Width, ByteWidth, Height.
- dc.w 0;XLOCKED ;Map options
- dc.l .Blocks ;Pointer to map graphics.
- dc.l 0 ;Pointer to map file.
- .Levels dc.l Level1
- dc.l -1
- even
-
- .Blocks dc.l PCV1,0 ;Version header.
- dc.l 0 ;Source data.
- dc.w 0,0,0 ;Width, Height.
- dc.w 0 ;Amount of Planes.
- dc.l 0 ;Amount of colours.
- dc.l 0 ;Source palette.
- dc.w LORES|COL12BIT ;Screen mode.
- dc.w 0 ;Destination
- dc.l GETPALETTE|VIDEOMEM ;Parameters.
- dc.l .File
- .File dc.b "GAMESLIB:data/IFF.MapBlocks",0
- even
-
- SECTION "EmptyData",BSS_C
-
- Level1 ds.b M_WIDTH*M_HEIGHT
- even
-
- ;---------------------------------------------------------------------------;
-
- STRUCTURE Offsets,00
- APTR GMS_Base
- UWORD BlockNumber
- APTR Keys
- UBYTE Display
- LABEL RS_SIZEOF
-
- All_Offsets:
- ds.b RS_SIZEOF
- even
-
- KP_Keys:
- ds.b KP_SIZEOF
- even
-
- ;===========================================================================;
- ; CHIP RAM DATA
- ;===========================================================================;
-
- SECTION "ChipData",DATA_C
-
- GFX_Pointer:
- dc.w 0,0
- dc.w %1111111000000000,%0000000000000000
- dc.w %1111110000000000,%0000000000000000
- dc.w %1111100000000000,%0000000000000000
- dc.w %1111110000000000,%0000000000000000
- dc.w %1111111000000000,%0000000000000000
- dc.w %1101111100000000,%0000000000000000
- dc.w %1000111110000000,%0000000000000000
- dc.w %0000011111000000,%0000000000000000
- dc.w %0000001111100000,%0000000000000000
- dc.w %0000000111000000,%0000000000000000
- dc.w %0000000010000000,%0000000000000000
-