~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/emu/tilemap.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
};
122
122
 
123
123
 
124
 
 
125
 
/***************************************************************************
126
 
    GLOBAL VARIABLES
127
 
***************************************************************************/
128
 
 
129
 
bitmap_t *                              priority_bitmap;
130
 
 
131
 
static tilemap *                tilemap_list;
132
 
static tilemap **               tilemap_tailptr;
133
 
static int                              tilemap_instance;
 
124
struct _tilemap_private
 
125
{
 
126
        tilemap *               list;
 
127
        tilemap **              tailptr;
 
128
        int                             instance;
 
129
};
134
130
 
135
131
 
136
132
 
241
237
    indexed_tilemap - return a tilemap by index
242
238
-------------------------------------------------*/
243
239
 
244
 
INLINE tilemap *indexed_tilemap(int index)
 
240
INLINE tilemap *indexed_tilemap(running_machine *machine, int index)
245
241
{
246
242
        tilemap *tmap;
247
243
 
248
244
        /* find by the tilemap index */
249
 
        for (tmap = tilemap_list; tmap != NULL; tmap = tmap->next)
 
245
        for (tmap = machine->tilemap_data->list; tmap != NULL; tmap = tmap->next)
250
246
                if (index-- == 0)
251
247
                        return tmap;
252
248
 
299
295
 
300
296
        if (screen_width != 0 && screen_height != 0)
301
297
        {
302
 
                tilemap_list     = NULL;
303
 
                tilemap_tailptr  = &tilemap_list;
304
 
                tilemap_instance = 0;
 
298
                machine->tilemap_data = auto_alloc_clear(machine, tilemap_private);
 
299
                machine->tilemap_data->tailptr = &machine->tilemap_data->list;
305
300
 
306
 
                priority_bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED8);
 
301
                machine->priority_bitmap = auto_bitmap_alloc(machine, screen_width, screen_height, BITMAP_FORMAT_INDEXED8);
307
302
                add_exit_callback(machine, tilemap_exit);
308
303
        }
309
304
}
321
316
tilemap *tilemap_create(running_machine *machine, tile_get_info_func tile_get_info, tilemap_mapper_func mapper, int tilewidth, int tileheight, int cols, int rows)
322
317
{
323
318
        tilemap *tmap;
 
319
        int tilemap_instance = machine->tilemap_data->instance;
324
320
        int group;
325
321
 
326
322
        /* allocate the tilemap itself */
367
363
                tilemap_map_pens_to_layer(tmap, group, 0, 0, TILEMAP_PIXEL_LAYER0);
368
364
 
369
365
        /* add us to the end of the list of tilemaps */
370
 
        *tilemap_tailptr = tmap;
371
 
        tilemap_tailptr = &tmap->next;
 
366
        *machine->tilemap_data->tailptr = tmap;
 
367
        machine->tilemap_data->tailptr = &tmap->next;
372
368
 
373
369
        /* save relevant state */
374
370
        state_save_register_item(machine, "tilemap", NULL, tilemap_instance, tmap->enable);
383
379
        state_save_register_item(machine, "tilemap", NULL, tilemap_instance, tmap->dx_flipped);
384
380
        state_save_register_item(machine, "tilemap", NULL, tilemap_instance, tmap->dy);
385
381
        state_save_register_item(machine, "tilemap", NULL, tilemap_instance, tmap->dy_flipped);
386
 
        tilemap_instance++;
 
382
        machine->tilemap_data->instance++;
387
383
 
388
384
        /* reset everything after a load */
389
385
        state_save_register_postload(machine, tilemap_postload, tmap);
428
424
 
429
425
/*-------------------------------------------------
430
426
    tilemap_set_flip - set a global flip for the
431
 
    tilemap; ALL_TILEMAPS can be passed here as
432
 
    well
 
427
    tilemap
433
428
-------------------------------------------------*/
434
429
 
435
430
void tilemap_set_flip(tilemap *tmap, UINT32 attributes)
436
431
{
437
 
        /* handle ALL_TILEMAPS */
438
 
        if (tmap == ALL_TILEMAPS)
439
 
        {
440
 
                for (tmap = tilemap_list; tmap != NULL; tmap = tmap->next)
441
 
                        tilemap_set_flip(tmap, attributes);
442
 
        }
443
 
 
444
432
        /* if we're changing things, force a refresh of the mappings and mark it all dirty */
445
 
        else if (tmap->attributes != attributes)
 
433
        if (tmap->attributes != attributes)
446
434
        {
447
435
                tmap->attributes = attributes;
448
436
                mappings_update(tmap);
450
438
}
451
439
 
452
440
 
 
441
/*-------------------------------------------------
 
442
    tilemap_set_flip_all - set a global flip for all
 
443
    the tilemaps
 
444
-------------------------------------------------*/
 
445
 
 
446
void tilemap_set_flip_all(running_machine *machine, UINT32 attributes)
 
447
{
 
448
        tilemap *tmap;
 
449
        for (tmap = machine->tilemap_data->list; tmap != NULL; tmap = tmap->next)
 
450
                tilemap_set_flip(tmap, attributes);
 
451
}
 
452
 
 
453
 
453
454
 
454
455
/***************************************************************************
455
456
    DIRTY TILE MARKING
484
485
 
485
486
void tilemap_mark_all_tiles_dirty(tilemap *tmap)
486
487
{
487
 
        /* handle ALL_TILEMAPS */
488
 
        if (tmap == ALL_TILEMAPS)
489
 
        {
490
 
                for (tmap = tilemap_list; tmap != NULL; tmap = tmap->next)
491
 
                        tilemap_mark_all_tiles_dirty(tmap);
492
 
        }
493
 
 
494
488
        /* mark all tiles dirty and clear the clean flag */
495
 
        else
496
 
        {
497
 
                tmap->all_tiles_dirty = TRUE;
498
 
                tmap->all_tiles_clean = FALSE;
499
 
        }
500
 
}
501
 
 
 
489
        tmap->all_tiles_dirty = TRUE;
 
490
        tmap->all_tiles_clean = FALSE;
 
491
}
 
492
 
 
493
 
 
494
/*-------------------------------------------------
 
495
    tilemap_mark_all_tiles_dirty_all - mark all the
 
496
    tiles in all the tilemaps dirty
 
497
-------------------------------------------------*/
 
498
 
 
499
void tilemap_mark_all_tiles_dirty_all(running_machine *machine)
 
500
{
 
501
        tilemap *tmap;
 
502
        for (tmap = machine->tilemap_data->list; tmap != NULL; tmap = tmap->next)
 
503
                tilemap_mark_all_tiles_dirty(tmap);
 
504
}
502
505
 
503
506
 
504
507
/***************************************************************************
778
781
        if (!tmap->enable)
779
782
                return;
780
783
 
781
 
profiler_mark(PROFILER_TILEMAP_DRAW);
 
784
profiler_mark_start(PROFILER_TILEMAP_DRAW);
782
785
        /* configure the blit parameters based on the input parameters */
783
786
        configure_blit_parameters(&blit, tmap, dest, cliprect, flags, priority, priority_mask);
784
787
 
881
884
                        }
882
885
                }
883
886
        }
884
 
profiler_mark(PROFILER_END);
 
887
profiler_mark_end();
885
888
}
886
889
 
887
890
 
916
919
                return;
917
920
        }
918
921
 
919
 
profiler_mark(PROFILER_TILEMAP_DRAW_ROZ);
 
922
profiler_mark_start(PROFILER_TILEMAP_DRAW_ROZ);
920
923
        /* configure the blit parameters */
921
924
        configure_blit_parameters(&blit, tmap, dest, cliprect, flags, priority, priority_mask);
922
925
 
925
928
 
926
929
        /* then do the roz copy */
927
930
        tilemap_draw_roz_core(tmap, &blit, startx, starty, incxx, incxy, incyx, incyy, wraparound);
928
 
profiler_mark(PROFILER_END);
 
931
profiler_mark_end();
929
932
}
930
933
 
931
934
 
938
941
    tilemap_count - return the number of tilemaps
939
942
-------------------------------------------------*/
940
943
 
941
 
int tilemap_count(void)
 
944
int tilemap_count(running_machine *machine)
942
945
{
943
946
        tilemap *tmap;
944
947
        int count = 0;
945
948
 
946
949
        /* find by the tilemap index */
947
 
        for (tmap = tilemap_list; tmap != NULL; tmap = tmap->next)
 
950
        for (tmap = machine->tilemap_data->list; tmap != NULL; tmap = tmap->next)
948
951
                count++;
949
952
        return count;
950
953
}
955
958
    indexed tilemap
956
959
-------------------------------------------------*/
957
960
 
958
 
void tilemap_size_by_index(int number, UINT32 *width, UINT32 *height)
 
961
void tilemap_size_by_index(running_machine *machine, int number, UINT32 *width, UINT32 *height)
959
962
{
960
 
        tilemap *tmap = indexed_tilemap(number);
 
963
        tilemap *tmap = indexed_tilemap(machine, number);
961
964
        *width = tmap->width;
962
965
        *height = tmap->height;
963
966
}
969
972
    priority)
970
973
-------------------------------------------------*/
971
974
 
972
 
void tilemap_draw_by_index(bitmap_t *dest, int number, UINT32 scrollx, UINT32 scrolly)
 
975
void tilemap_draw_by_index(running_machine *machine, bitmap_t *dest, int number, UINT32 scrollx, UINT32 scrolly)
973
976
{
974
 
        tilemap *tmap = indexed_tilemap(number);
 
977
        tilemap *tmap = indexed_tilemap(machine, number);
975
978
        blit_parameters blit;
976
979
        int xpos,ypos;
977
980
 
1072
1075
 
1073
1076
static void tilemap_exit(running_machine *machine)
1074
1077
{
 
1078
        tilemap_private *tilemap_data = machine->tilemap_data;
 
1079
 
1075
1080
        /* free all the tilemaps in the list */
1076
 
        while (tilemap_list != NULL)
 
1081
        while (tilemap_data->list != NULL)
1077
1082
        {
1078
 
                tilemap *next = tilemap_list->next;
1079
 
                tilemap_dispose(tilemap_list);
1080
 
                tilemap_list = next;
 
1083
                tilemap *next = tilemap_data->list->next;
 
1084
                tilemap_dispose(tilemap_data->list);
 
1085
                tilemap_data->list = next;
1081
1086
        }
1082
 
        tilemap_tailptr = NULL;
 
1087
        tilemap_data->tailptr = &tilemap_data->list;
1083
1088
}
1084
1089
 
1085
1090
 
1105
1110
        tilemap **tmapptr;
1106
1111
 
1107
1112
        /* walk the list of tilemaps; when we find ourself, remove it */
1108
 
        for (tmapptr = &tilemap_list; *tmapptr != NULL; tmapptr = &(*tmapptr)->next)
 
1113
        for (tmapptr = &tmap->machine->tilemap_data->list; *tmapptr != NULL; tmapptr = &(*tmapptr)->next)
1109
1114
                if (*tmapptr == tmap)
1110
1115
                {
1111
1116
                        *tmapptr = tmap->next;
1223
1228
        if (tmap->all_tiles_clean)
1224
1229
                return;
1225
1230
 
1226
 
profiler_mark(PROFILER_TILEMAP_DRAW);
 
1231
profiler_mark_start(PROFILER_TILEMAP_DRAW);
1227
1232
 
1228
1233
        /* compute which columns and rows to update */
1229
1234
        if (cliprect != NULL)
1263
1268
        if (mincol == 0 && minrow == 0 && maxcol == tmap->cols - 1 && maxcol == tmap->rows - 1)
1264
1269
                tmap->all_tiles_clean = TRUE;
1265
1270
 
1266
 
profiler_mark(PROFILER_END);
 
1271
profiler_mark_end();
1267
1272
}
1268
1273
 
1269
1274
 
1278
1283
        tilemap_memory_index memindex;
1279
1284
        UINT32 flags;
1280
1285
 
1281
 
profiler_mark(PROFILER_TILEMAP_UPDATE);
 
1286
profiler_mark_start(PROFILER_TILEMAP_UPDATE);
1282
1287
 
1283
1288
        /* call the get info callback for the associated memory index */
1284
1289
        memindex = tmap->logical_to_memory[logindex];
1302
1307
                tmap->gfx_dirtyseq[tmap->tileinfo.gfxnum] = tmap->machine->gfx[tmap->tileinfo.gfxnum]->dirtyseq;
1303
1308
        }
1304
1309
 
1305
 
profiler_mark(PROFILER_END);
 
1310
profiler_mark_end();
1306
1311
}
1307
1312
 
1308
1313
 
1564
1569
 
1565
1570
static void tilemap_draw_instance(tilemap *tmap, const blit_parameters *blit, int xpos, int ypos)
1566
1571
{
 
1572
        bitmap_t *priority_bitmap = tmap->machine->priority_bitmap;
1567
1573
        bitmap_t *dest = blit->bitmap;
1568
1574
        const UINT16 *source_baseaddr;
1569
1575
        const UINT8 *mask_baseaddr;
1743
1749
                UINT32 startx, UINT32 starty, int incxx, int incxy, int incyx, int incyy, int wraparound)
1744
1750
{
1745
1751
        const pen_t *clut = &tmap->machine->pens[blit->tilemap_priority_code >> 16];
 
1752
        bitmap_t *priority_bitmap = tmap->machine->priority_bitmap;
1746
1753
        bitmap_t *destbitmap = blit->bitmap;
1747
1754
        bitmap_t *srcbitmap = tmap->pixmap;
1748
1755
        bitmap_t *flagsmap = tmap->flagsmap;