home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / Asm / Demos / MapEditor.s < prev    next >
Encoding:
Text File  |  1997-02-16  |  13.1 KB  |  516 lines

  1. ;-------T-------T------------------------T----------------------------------;
  2. ;Map Editor V0.1
  3. ;---------------
  4. ;A very fast map editor, normally we would do one of these with the OS, but
  5. ;this one hardware scrolls in the same way as it would in a game :-).  It
  6. ;still needs a lot of work, but you can play with it.
  7. ;
  8. ;Push SPACE to switch between the map and tile screen.  You can pickup
  9. ;and putdown tiles using the left mouse button.  Press right mouse button
  10. ;to exit.
  11.  
  12.     INCDIR    "INCLUDES:"
  13.     INCLUDE    "exec/exec_lib.i"
  14.     INCLUDE    "games/games_lib.i"
  15.     INCLUDE    "games/games.i"
  16.  
  17. CALL    MACRO
  18.     jsr    _LVO\1(a6)
  19.     ENDM
  20.  
  21. SAVEREGS MACRO
  22.     MOVEM.L    D0-D7/A0-A6,-(SP)
  23.     ENDM
  24.  
  25. RETURNREGS MACRO
  26.     MOVEM.L    (SP)+,D0-D7/A0-A6
  27.     ENDM
  28.  
  29.     SECTION    "MapEditor",CODE
  30.  
  31. ;===========================================================================;
  32. ;                             INITIALISE DEMO
  33. ;===========================================================================;
  34.  
  35. Start:    MOVEM.L    A0-A6/D1-D7,-(SP)
  36.     lea    All_Offsets,a5
  37.     move.l    #KP_Keys,Keys(a5)
  38.  
  39.     move.l    ($4).w,a6
  40.     lea    GMS_Name(pc),a1
  41.     moveq    #$00,d0
  42.     CALL    OpenLibrary
  43.     move.l    d0,GMS_Base(a5)
  44.     beq    .Error_GMS
  45.  
  46.     move.l    GMS_Base(a5),a6
  47.     sub.l    a0,a0
  48.     CALL    SetUserPrefs
  49.  
  50.     lea    LevelMaps(pc),a1
  51.     move.l    MAP_Picture(a1),a1
  52.     CALL    LoadPic
  53.     tst.w    d0
  54.     bne    .Error_Picture
  55.  
  56.     lea    GS_MapScreen(pc),a0
  57.     move.l    PIC_Palette(a1),GS_Palette(a0)
  58.     move.w    PIC_Planes(a1),GS_Planes(a0)
  59.     move.w    PIC_ScrType(a1),GS_ScrType(a0)
  60.     CALL    AddScreen
  61.     tst.w    d0
  62.     bne.s    .Error_MapScreen
  63.  
  64.     lea    GS_TileScreen(pc),a0
  65.     move.l    PIC_Data(a1),GS_MemPtr1(a0)
  66.     move.l    PIC_Palette(a1),GS_Palette(a0)
  67.     move.w    PIC_Height(a1),GS_PicHeight(a0)
  68.     move.w    PIC_ByteWidth(a1),GS_PicByteWidth(a0)
  69.     move.w    PIC_Planes(a1),GS_Planes(a0)
  70.     CALL    AddScreen
  71.     tst.l    d0
  72.     bne.s    .Error_TileScreen
  73.  
  74.     lea    GS_MapScreen(pc),a0
  75.     lea    LevelMaps(pc),a1
  76.     CALL    InitMap
  77.     tst.w    d0
  78.     bne.s    .Error_Map
  79.  
  80.     lea    LevelMaps(pc),a1    ;a1 = Map structure.
  81.     moveq    #0,d0    ;d0 = X destination.
  82.     moveq    #0,d1    ;d1 = Y destination.
  83.     CALL    DrawMap    ;>> = Draw all the map blocks.
  84.  
  85.     lea    GS_MapScreen(pc),a0
  86.     lea    SPR_Pointer(pc),a1
  87.     CALL    InitSprite
  88.     tst.w    d0
  89.     bne.s    .Error_Pointer
  90.  
  91.     bsr.s    Main
  92.  
  93. .ReturnToDOS
  94.     move.l    GMS_Base(a5),a6
  95.     lea    SPR_Pointer(pc),a1
  96.     CALL    FreeSprite
  97. .Error_Pointer
  98.     lea    LevelMaps(pc),a1
  99.     CALL    FreeMap
  100. .Error_Map
  101.     lea    GS_TileScreen(pc),a0
  102.     CALL    DeleteScreen
  103. .Error_TileScreen
  104.     lea    GS_MapScreen(pc),a0
  105.     CALL    DeleteScreen
  106. .Error_MapScreen
  107.     lea    LevelMaps(pc),a1
  108.     move.l    MAP_Picture(a1),a1
  109.     CALL    FreePic
  110. .Error_Picture
  111.     move.l    GMS_Base(a5),a1
  112.     move.l    ($4).w,a6
  113.     CALL    CloseLibrary
  114. .Error_GMS
  115.     MOVEM.L    (SP)+,A0-A6/D1-D7
  116.     moveq    #$00,d0
  117.     rts
  118.  
  119. ;===========================================================================;
  120. ;                                MAIN LOOP
  121. ;===========================================================================;
  122.  
  123. Main:    CALL    InitJoyPorts
  124.  
  125. ;---------------------------------------------------------------------------;
  126. ;                              DRAW TILES LOOP
  127. ;---------------------------------------------------------------------------;
  128.  
  129. Show_Map:
  130.     clr.b    Display(a5)
  131.     lea    GS_MapScreen(pc),a0
  132.     lea    SPR_Pointer(pc),a1
  133.     CALL    InitSprite    ;Initialise sprite for this screen.
  134.     CALL    UpdateSprite    ;Display the sprite.
  135.     CALL    ShowScreen    ;Show the tile screen.
  136.  
  137. .loop    moveq    #JPORT1,d0
  138.     CALL    ReadMouse
  139.     btst    #MB_RMB,d0
  140.     beq.s    .move
  141.     rts
  142. .move    bsr    Move_Pointer
  143.     btst    #MB_LMB,d0
  144.     beq.s    .VBL
  145.     bsr    Draw_Tile
  146. .VBL    CALL    WaitSVBL
  147.     lea    GS_MapScreen(pc),a0
  148.     lea    SPR_Pointer(pc),a1
  149.     CALL    MoveSprite
  150.     move.l    Keys(a5),a1
  151.     CALL    ReadKey
  152.     cmp.b    #" ",d0
  153.     beq.s    Show_Tiles
  154.     bra.s    .loop
  155.  
  156. ;---------------------------------------------------------------------------;
  157. ;                            TILE SELECTION LOOP
  158. ;---------------------------------------------------------------------------;
  159.  
  160. Show_Tiles:
  161.     st    Display(a5)
  162.     lea    GS_TileScreen(pc),a0
  163.     lea    SPR_Pointer(pc),a1
  164.     CALL    InitSprite    ;Initialise sprite for this screen.
  165.     CALL    UpdateSprite    ;Display the sprite.
  166.     CALL    ShowScreen    ;Show the tile screen.
  167. .loop    moveq    #JPORT1,d0
  168.     CALL    ReadMouse
  169.     btst    #MB_RMB,d0
  170.     beq.s    .move
  171.     rts
  172. .move    bsr.s    Move_Pointer
  173.     btst    #MB_LMB,d0
  174.     beq.s    .VBL
  175.     bsr.s    Pickup_Tile
  176. .VBL    CALL    WaitSVBL
  177.     lea    GS_TileScreen(pc),a0
  178.     lea    SPR_Pointer(pc),a1
  179.     CALL    MoveSprite
  180.     move.l    Keys(a5),a1
  181.     CALL    ReadKey
  182.     cmp.b    #" ",d0
  183.     beq    Show_Map
  184.     bra.s    .loop
  185.  
  186. Pickup_Tile:
  187.     SAVEREGS
  188.     lea    GS_TileScreen(pc),a0    ;a0 = GameScreen
  189.     lea    LevelMaps(pc),a1    ;a1 = Map structure.
  190.     lea    SPR_Pointer(pc),a2    ;a2 = Mouse pointer.
  191.     move.w    SPR_XCoord(a2),d0    ;d0 = XCoord [mouse]
  192.     move.w    SPR_YCoord(a2),d1    ;d1 = YCoord [mouse]
  193.     add.w    GS_PicXOffset(a0),d0    ;d0 = (XCoord)+PicXCoord
  194.     add.w    GS_PicYOffset(a0),d1    ;d1 = (YCoord)+PicYCoord
  195.     lsr.w    #4,d0    ;d0 = /16 [XPlace to store block]
  196.     lsr.w    #4,d1    ;d1 = /16 [YPlace to store block]
  197.     mulu    #20,d1
  198.     add.w    d0,d1
  199.     move.w    d1,BlockNumber(a5)
  200.     RETURNREGS
  201.     rts
  202.  
  203. ;===========================================================================;
  204. ;                        MOVE MOUSE POINTER & SCREEN
  205. ;===========================================================================;
  206.  
  207. Move_Pointer:
  208.     SAVEREGS
  209.     lea    SPR_Pointer(pc),a1
  210.     move.w    d0,d1
  211.     asr.w    #8,d0    ;d0 = X Change
  212.     ext.w    d1
  213.     add.w    d0,SPR_XCoord(a1)
  214.     add.w    d1,SPR_YCoord(a1)
  215.     moveq    #$00,d1
  216.     moveq    #$00,d2
  217. .ChkLX    tst.w    SPR_XCoord(a1)
  218.     bgt.s    .ChkTY
  219.     move.w    SPR_XCoord(a1),d1
  220.     clr.w    SPR_XCoord(a1)
  221. .ChkTY    tst.w    SPR_YCoord(a1)
  222.     bgt.s    .ChkRX
  223.     move.w    SPR_YCoord(a1),d2
  224.     clr.w    SPR_YCoord(a1)
  225. .ChkRX    move.w    SPR_XCoord(a1),d0
  226.     move.w    GS_ScrWidth(a0),d3
  227.     subq.w    #1,d3
  228.     cmp.w    d3,d0
  229.     blt.s    .ChkBY
  230.     move.w    d0,d1
  231.     sub.w    d3,d1
  232.     move.w    d3,SPR_XCoord(a1)
  233. .ChkBY    move.w    SPR_YCoord(a1),d0
  234.     move.w    GS_ScrHeight(a0),d3
  235.     subq.w    #1,d3
  236.     cmp.w    d3,d0
  237.     blt.s    .done
  238.     move.w    d0,d2
  239.     sub.w    d3,d2
  240.     move.w    d3,SPR_YCoord(a1)
  241.  
  242. .done    tst.w    d1
  243.     bne.s    Move_Picture
  244.     tst.w    d2
  245.     bne.s    Move_Picture
  246.     RETURNREGS
  247.     rts
  248.  
  249. ;---------------------------------------------------------------------------;
  250. ;                                MOVE PICTURE
  251. ;---------------------------------------------------------------------------;
  252. ;Requires: d1 = XChange
  253. ;       d2 = YChange
  254.  
  255. Move_Picture:
  256.     tst.b    Display(a5)
  257.     beq.s    Move_Map
  258.     add.w    d1,GS_PicXOffset(a0)
  259.     add.w    d2,GS_PicYOffset(a0)
  260. .ChkTY    tst.w    GS_PicYOffset(a0)
  261.     bge.s    .ChkLX
  262.     clr.w    GS_PicYOffset(a0)
  263. .ChkLX    tst.w    GS_PicXOffset(a0)
  264.     bgt.s    .ChkBY
  265.     clr.w    GS_PicXOffset(a0)
  266. .ChkBY    move.w    GS_PicHeight(a0),d0
  267.     sub.w    GS_ScrHeight(a0),d0
  268.     cmp.w    GS_PicYOffset(a0),d0
  269.     bge.s    .ChkRX
  270.     move.w    d0,GS_PicYOffset(a0)
  271. .ChkRX    move.w    GS_PicWidth(a0),d0
  272.     sub.w    GS_ScrWidth(a0),d0
  273.     cmp.w    GS_PicXOffset(a0),d0
  274.     bge.s    .move
  275.     move.w    d0,GS_PicXOffset(a0)
  276. .move    CALL    MovePicture
  277.     RETURNREGS
  278.     rts
  279.  
  280. ;---------------------------------------------------------------------------;
  281. ;                          MOVE AND AND DRAW MAP ROWS
  282. ;---------------------------------------------------------------------------;
  283.  
  284. Move_Map:
  285.     cmp.w    #16,d1
  286.     blt.s    .ChkL
  287.     move.w    #16,d1
  288. .ChkL    cmp.w    #-16,d1
  289.     bgt.s    .go
  290.     move.w    #-16,d1
  291. .go    add.w    d1,GS_PicXOffset(a0)
  292.     add.w    d2,GS_PicYOffset(a0)
  293. .ChkTY    tst.w    GS_PicYOffset(a0)
  294.     bge.s    .ChkLX
  295.     clr.w    GS_PicYOffset(a0)
  296. .ChkLX    tst.w    GS_PicXOffset(a0)
  297.     bgt.s    .ChkBY
  298.     clr.w    GS_PicXOffset(a0)
  299. .ChkBY    move.w    GS_PicYOffset(a0),d0
  300.     cmp.w    GS_ScrHeight(a0),d0
  301.     blt.s    .ChkRX
  302.     move.w    GS_ScrHeight(a0),GS_PicYOffset(a0)
  303. .ChkRX    cmp.w    #(X_SCREENS-1)*320,GS_PicXOffset(a0)
  304.     blt.s    .move
  305.     move.w    #(X_SCREENS-1)*320,GS_PicXOffset(a0)
  306. .move    CALL    MovePicture
  307.     tst.w    d1
  308.     bgt.s    .Right
  309.     beq.s    .done
  310. .Left    lea    LevelMaps(pc),a1    ;a1 = Map structure.
  311.     move.w    GS_PicXOffset(a0),d0    ;d0 = PicXOffset
  312.     lsr.w    #4,d0    ;d0 = /16
  313.     move.w    d0,MAP_XStart(a1)    ;a1 = The XCoord to get the row.
  314.     clr.w    MAP_YStart(a1)    ;a1 = The YCoord to get the row.
  315.     moveq    #00,d0    ;d0 = X destination.
  316.     moveq    #00,d1    ;d1 = Y destination.
  317.     CALL    DrawMapVRow    ;>> = Draw a row of map blocks.
  318. .done    RETURNREGS
  319.     rts
  320.  
  321. .Right    lea    LevelMaps(pc),a1    ;a1 = Map structure.
  322.     move.w    GS_PicXOffset(a0),d0    ;d0 = PicXOffset
  323.     lsr.w    #4,d0    ;d0 = /16
  324.     add.w    #(336-16)/16,d0
  325.     move.w    d0,MAP_XStart(a1)    ;a1 = The XCoord to get the row.
  326.     clr.w    MAP_YStart(a1)    ;a1 = The YCoord to get the row.
  327.     move.w    #336-16,d0    ;d0 = X destination.
  328.     moveq    #00,d1    ;d1 = Y destination.
  329.     CALL    DrawMapVRow    ;>> = Draw a row of map blocks.
  330.     RETURNREGS
  331.     rts
  332.  
  333. ;===========================================================================;
  334. ;                          DRAW MAP TILE TO SCREEN
  335. ;===========================================================================;
  336.  
  337. Draw_Tile:
  338.     SAVEREGS
  339.     lea    GS_MapScreen(pc),a0    ;a0 = GameScreen
  340.     lea    LevelMaps(pc),a1    ;a1 = Map structure.
  341.     lea    SPR_Pointer(pc),a2    ;a2 = Mouse pointer.
  342.  
  343.     ;Put the tile in the map data.
  344.  
  345.     move.l    MAP_MapList(a1),a3    ;a3 = List of maps.
  346.     move.l    (a3),a3    ;a3 = Level 1 map data.
  347.     move.w    SPR_XCoord(a2),d0    ;d0 = XCoord [mouse]
  348.     move.w    SPR_YCoord(a2),d1    ;d1 = YCoord [mouse]
  349.     add.w    GS_PicXOffset(a0),d0    ;d0 = (XCoord)+PicXCoord
  350.     add.w    GS_PicYOffset(a0),d1    ;d1 = (YCoord)+PicYCoord
  351.     lsr.w    #4,d0    ;d0 = /16 [XPlace to store block]
  352.     lsr.w    #4,d1    ;d1 = /16 [YPlace to store block]
  353.     move.w    d0,MAP_XStart(a1)    ;a1 = Make a note for Draw_Tile()
  354.     move.w    d1,MAP_YStart(a1)    ;a1 = Make a note for Draw_Tile()
  355.     lsl.w    #1,d0    ;d0 = *2 [word]
  356.     add.w    d0,a3    ;a3 = (Map)+XOffset
  357.     mulu    #M_WIDTH,d1    ;d1 = *RowSize
  358.     add.w    d1,a3    ;a3 = (Map)+YOffset
  359.     move.w    BlockNumber(a5),(a3)    ;a3 = Store new block number.
  360.  
  361.     ;Draw the map tile.
  362.  
  363.     move.w    SPR_XCoord(a2),d0
  364.     move.w    GS_PicXOffset(a0),d1    ;Correct the XCoord from the offset.
  365.     and.w    #%1111,d1
  366.     add.w    d1,d0
  367.     move.w    SPR_YCoord(a2),d1
  368.     add.w    GS_PicYOffset(a0),d1
  369.     and.w    #%1111111111110000,d0
  370.     and.w    #%1111111111110000,d1
  371.     CALL    DrawMapTile
  372.     RETURNREGS
  373.     rts
  374.  
  375. ;===========================================================================;
  376. ;                                  DATA
  377. ;===========================================================================;
  378.  
  379. GMS_Name:
  380.     dc.b    "games.library",0
  381.     even
  382.  
  383. AMT_PLANES =    5
  384.  
  385. GS_MapScreen:
  386.     dc.l    GSV1,0    ;Structure version.
  387.     dc.l    0,0,0    ;Screen Memory 1/2/3.
  388.     dc.l    0    ;Screen link.
  389.     dc.l    0    ;Address of palette.
  390.     dc.l    0    ;Address of rasterlist.
  391.     dc.l    0    ;Amt of colours in palette.
  392.     dc.w    320,256    ;Screen Width, Height.
  393.     dc.w    336,336/8,256*2    ;Picture Widths, Height.
  394.     dc.w    0    ;Amount of planes
  395.     dc.w    0,0    ;X/Y Screen offset.
  396.     dc.w    0,0    ;X/Y Picture offset.
  397.     dc.l    HSCROLL|VSCROLL|SBUFFER    ;Special attributes.
  398.     dc.w    LORES|COL12BIT    ;Screen mode.
  399.     dc.w    0    ;Screen type
  400.  
  401. GS_TileScreen:
  402.     dc.l    GSV1,0    ;Structure version.
  403.     dc.l    0,0,0    ;Screen Memory 1/2/3.
  404.     dc.l    0    ;Screen link.
  405.     dc.l    0    ;Address of palette.
  406.     dc.l    0    ;Address of rasterlist.
  407.     dc.l    0    ;Amt of colours in palette.
  408.     dc.w    320,256    ;Screen Width, Height.
  409.     dc.w    0,0,0    ;Picture Widths, Height.
  410.     dc.w    0    ;Amount of planes
  411.     dc.w    0,0    ;X/Y Screen offset.
  412.     dc.w    0,0    ;X/Y Picture offset.
  413.     dc.l    HSCROLL|VSCROLL    ;Special attributes.
  414.     dc.w    LORES|COL12BIT    ;Screen mode.
  415.     dc.w    0    ;Screen type
  416.  
  417. ;===========================================================================;
  418. ;                                  MOUSE POINTER
  419. ;===========================================================================;
  420.  
  421. SPR_Pointer:
  422.     dc.l    SPV1,0    ;Structure version.
  423.     dc.w    0    ;Number 0.
  424.     dc.l    GFX_Pointer    ;Pointer to graphic.
  425.     dc.w    0,0    ;Beginning X/Y position
  426.     dc.w    0    ;Current frame.
  427.     dc.w    16,11    ;Width, Height.
  428.     dc.w    4    ;Amount of colours.
  429.     dc.w    16    ;Colour start in palette.
  430.     dc.w    2    ;Amount of planes.
  431.     dc.w    LORES    ;Resolution.
  432.     dc.w    0    ;PlayField position.
  433.     dc.w    0    ;Special attributes.
  434.  
  435. ;===========================================================================;
  436. ;                              MAP STRUCTURE
  437. ;===========================================================================;
  438.  
  439. X_SCREENS =    10
  440. Y_SCREENS =    10
  441.  
  442. M_WIDTH =    ((320/16)*MAPSIZE_WORD)*X_SCREENS
  443. M_HEIGHT =    (256/16)*Y_SCREENS
  444.  
  445. LevelMaps:
  446.     dc.l    MPV1,0    ;Structure version.
  447.     dc.w    BUFFER1    ;Buffer to blit to.
  448.     dc.w    0    ;Map number to access.
  449.     dc.l    .Levels    ;Pointer to map list.
  450.     dc.w    M_WIDTH,M_HEIGHT    ;Total Width in bytes, Height.
  451.     dc.w    0,0    ;XStart, YStart.
  452.     dc.w    MAPSIZE_WORD    ;Entry Size - WORD.
  453.     dc.l    $0000ffff    ;Entry Mask - set for word.
  454.     dc.w    16,16/8,16    ;Tile Width, ByteWidth, Height.
  455.     dc.w    0;XLOCKED    ;Map options
  456.     dc.l    .Blocks    ;Pointer to map graphics.
  457.     dc.l    0    ;Pointer to map file.
  458. .Levels    dc.l    Level1
  459.     dc.l    -1
  460.     even
  461.  
  462. .Blocks    dc.l    PCV1,0    ;Version header.
  463.     dc.l    0    ;Source data.
  464.     dc.w    0,0,0    ;Width, Height.
  465.     dc.w    0    ;Amount of Planes.
  466.     dc.l    0    ;Amount of colours.
  467.     dc.l    0    ;Source palette.
  468.     dc.w    LORES|COL12BIT    ;Screen mode.
  469.     dc.w    0    ;Destination
  470.     dc.l    GETPALETTE|VIDEOMEM    ;Parameters.
  471.     dc.l    .File
  472. .File    dc.b    "GAMESLIB:data/IFF.MapBlocks",0
  473.     even
  474.  
  475.     SECTION    "EmptyData",BSS_C
  476.  
  477. Level1    ds.b    M_WIDTH*M_HEIGHT
  478.     even
  479.  
  480. ;---------------------------------------------------------------------------;
  481.  
  482.    STRUCTURE    Offsets,00
  483.     APTR    GMS_Base
  484.     UWORD    BlockNumber
  485.     APTR    Keys
  486.     UBYTE    Display
  487.     LABEL    RS_SIZEOF
  488.  
  489. All_Offsets:
  490.     ds.b    RS_SIZEOF
  491.     even
  492.  
  493. KP_Keys:
  494.     ds.b    KP_SIZEOF
  495.     even
  496.  
  497. ;===========================================================================;
  498. ;                                  CHIP RAM DATA
  499. ;===========================================================================;
  500.  
  501.     SECTION    "ChipData",DATA_C
  502.  
  503. GFX_Pointer:
  504.     dc.w    0,0
  505.     dc.w    %1111111000000000,%0000000000000000
  506.     dc.w    %1111110000000000,%0000000000000000
  507.     dc.w    %1111100000000000,%0000000000000000
  508.     dc.w    %1111110000000000,%0000000000000000
  509.     dc.w    %1111111000000000,%0000000000000000
  510.     dc.w    %1101111100000000,%0000000000000000
  511.     dc.w    %1000111110000000,%0000000000000000
  512.     dc.w    %0000011111000000,%0000000000000000
  513.     dc.w    %0000001111100000,%0000000000000000
  514.     dc.w    %0000000111000000,%0000000000000000
  515.     dc.w    %0000000010000000,%0000000000000000
  516.