@@ -2314,10 +2314,10 @@ _Tilemap:
2314
2314
; uint8_t x, x_tile, y_tile, y_next;
2315
2315
; uint8_t x_res = x_offset/tilemap->tile_width;
2316
2316
; uint8_t y = y_offset/tilemap->tile_height;
2317
- ;
2317
+ ;
2318
2318
; x_offset = x_offset%tilemap->tile_width;
2319
2319
; y_offset = y_offset%tilemap->tile_height;
2320
- ;
2320
+ ;
2321
2321
; y_draw = tilemap->y_loc-y_offset;
2322
2322
; for(y_tile = 0; y_tile <= tilemap->draw_height; y_tile++) {
2323
2323
; x = x_res;
@@ -2333,6 +2333,19 @@ _Tilemap:
2333
2333
; }
2334
2334
; }
2335
2335
;
2336
+ t_data .equ 0
2337
+ t_type_width .equ 10
2338
+ t_type_height .equ 11
2339
+ t_height .equ 12
2340
+ t_width .equ 13
2341
+ t_tile_height .equ 6
2342
+ t_tile_width .equ 7
2343
+ t_draw_height .equ 8
2344
+ t_draw_width .equ 9
2345
+ t_x_loc .equ 15
2346
+
2347
+ x_offset .equ 9
2348
+ y_offset .equ 12
2336
2349
ld hl , _Sprite \.r
2337
2350
_: ld (DrawTile_SMC) , hl \.r
2338
2351
push ix
@@ -2341,65 +2354,79 @@ _: ld (DrawTile_SMC),hl \.r
2341
2354
add ix , sp
2342
2355
lea hl , ix +- 12
2343
2356
ld sp , hl
2344
- ld iy , (ix + 6 )
2357
+ ld iy , (ix + 6 ) ; iy -> tilemap structure
2345
2358
2346
- ld b , (iy + 11 )
2347
- ld hl , (ix + 12 )
2348
- ld c , (iy + 6 )
2359
+ ld hl , (ix + y_offset)
2360
+ ld c , (iy + t_tile_height)
2361
+ ld a , (iy + t_type_height)
2362
+ or a , a
2363
+ jr nz , _height_is_pow2
2364
+ call __idvrmu
2365
+ jr _height_is_not_pow2
2366
+ _height_is_pow2: ; compute as power of 2 height using shifts
2367
+ ld b , a
2349
2368
dec c
2350
2369
ld a , l
2351
2370
and a , c
2352
2371
ld c , a
2353
2372
_: srl h
2354
2373
rr l
2355
2374
djnz - _
2356
- ld (ix +- 4 ) , l ; y = y_offset / tilemap->tile_height
2357
- ld (ix + 12 ) , bc ; y_offset = y_offset % tilemap->tile_height;
2375
+ _height_is_not_pow2:
2376
+ ld (ix +- 4 ) , l ; y = y_offset / tilemap->t_tile_height
2377
+ ld (ix + y_offset) , bc ; y_offset = y_offset % tilemap->t_tile_height;
2358
2378
2359
- ld b , (iy + 10 )
2360
- ld hl , (ix + 9 ) ; x offset
2361
- ld c , (iy + 7 )
2379
+ ld c , (iy + t_tile_width)
2380
+ ld hl , (ix + x_offset) ; x offset
2381
+ ld a , (iy + t_type_width)
2382
+ or a , a
2383
+ jr nz , _width_is_pow2
2384
+ call __idvrmu
2385
+ jr _width_is_not_pow2
2386
+ _width_is_pow2:
2387
+ ld b , a
2362
2388
dec c
2363
2389
ld a , l
2364
2390
and a , c
2365
2391
ld c , a
2366
2392
_: srl h
2367
2393
rr l
2368
2394
djnz - _
2395
+ _width_is_not_pow2:
2369
2396
ld a , l
2370
- ld (X_Res_SMC ) , a \.r
2371
- ld hl , (iy + 15 )
2397
+ ld (x_res_smc ) , a \.r
2398
+ ld hl , (iy + t_x_loc )
2372
2399
or a , a
2373
2400
sbc hl , bc
2374
- ld (X_Draw_SMC ) , hl \.r ; x_draw = tilemap->x_loc- x_offset;
2401
+ ld (x_offset_smc ) , hl \.r ; x_offset_smc = tilemap->t_x_loc - x_offset;
2375
2402
2376
2403
or a , a
2377
2404
sbc hl , hl
2378
2405
ld l , (iy + 14 )
2379
- ld bc , (ix + 12 )
2406
+ ld bc , (ix + y_offset )
2380
2407
ld (ix +- 3 ) , h
2381
2408
sbc hl , bc
2382
2409
ld (ix +- 12 ) , hl
2383
2410
jp Y_Loop \.r
2384
2411
2385
- X_Res_SMC =$+ 3
2412
+ x_res_smc =$+ 3
2386
2413
n_8: ld (ix +- 1 ) , 0
2387
- ld (ix +- 2 ) , 0
2388
- X_Draw_SMC =$ + 1
2414
+ x_offset_smc =$ + 1
2389
2415
ld hl , 0
2390
2416
ld (ix +- 7 ) , hl
2391
- ld l , (iy + 13 )
2417
+ ld l , (iy + t_width )
2392
2418
ld h , (ix +- 4 )
2393
2419
mlt hl
2394
- ld (Y_Next_SMC) , hl \.r
2420
+ ld (y_next_smc) , hl \.r
2421
+ xor a , a
2395
2422
jr X_Loop
2396
2423
2397
- _InLoop_ASM :
2424
+ _x_loop_inner :
2398
2425
sbc hl , hl
2399
2426
ld l , (ix +- 1 )
2400
- ld bc , (iy + 0 )
2427
+ ld bc , (iy + t_data) ; iy -> tilemap data
2401
2428
add hl , bc
2402
- Y_Next_SMC =$+ 1
2429
+ y_next_smc =$+ 1
2403
2430
ld bc , 0
2404
2431
add hl , bc
2405
2432
ld a , (hl)
@@ -2417,7 +2444,7 @@ Y_Next_SMC =$+1
2417
2444
ld bc , (hl)
2418
2445
push bc
2419
2446
DrawTile_SMC =$ + 1
2420
- call 0
2447
+ call 0 ; call sprite drawing routine
2421
2448
lea hl , ix +- 12
2422
2449
ld sp , hl
2423
2450
BlankTile:
@@ -2429,14 +2456,14 @@ BlankTile:
2429
2456
add hl , bc
2430
2457
ld (ix +- 7 ) , hl
2431
2458
inc (ix +- 1 )
2432
- inc (ix +- 2 )
2459
+ ld a , (ix +- 2 )
2460
+ inc a
2433
2461
2434
2462
X_Loop:
2435
- ld a , (iy + 9 )
2436
- cp a , (ix +- 2 )
2437
- jr nz , _InLoop_ASM
2438
- or a , a
2439
- sbc hl , hl
2463
+ ld (ix +- 2 ) , a
2464
+ cp a , (iy + t_draw_width)
2465
+ jr nz , _x_loop_inner
2466
+ ld h , 0
2440
2467
ld l , (iy + 6 )
2441
2468
ld bc , (ix +- 12 )
2442
2469
add hl , bc
@@ -2445,7 +2472,7 @@ X_Loop:
2445
2472
inc (ix +- 3 )
2446
2473
2447
2474
Y_Loop:
2448
- ld a , (iy + 8 )
2475
+ ld a , (iy + t_draw_height )
2449
2476
cp a , (ix +- 3 )
2450
2477
jp nz , n_8 \.r
2451
2478
ld sp , ix
@@ -2463,27 +2490,43 @@ _TilePtr:
2463
2490
; A pointer to an indexed tile in the tilemap (so it can be looked at or changed)
2464
2491
; C Function:
2465
2492
; uint8_t *gfx_TilePtr(gfx_tilemap_t *tilemap, unsigned x_offset, unsigned y_offset) {
2466
- ; return &tilemap->map[(x_offset/tilemap->tile_width )+((y_offset/tilemap->tile_height )*tilemap->width)];
2493
+ ; return &tilemap->map[(x_offset/tilemap->t_tile_width )+((y_offset/tilemap->t_tile_height )*tilemap->width)];
2467
2494
; }
2468
2495
push ix
2469
2496
ld ix , 0
2470
2497
add ix , sp
2471
2498
ld iy , (ix + 6 )
2472
- ld b , (iy + 10 )
2473
- ld hl , (ix + 9 )
2499
+ ld hl , (ix + x_offset)
2500
+ ld a , (iy + t_type_width)
2501
+ or a , a
2502
+ jr z ,+ _
2503
+ ld bc , 0
2504
+ ld c , (iy + t_tile_width)
2505
+ call __idvrmu
2506
+ jr _width_no_pow2
2507
+ _: ld b , a
2474
2508
_: srl h
2475
2509
rr l
2476
2510
djnz - _
2511
+ _width_no_pow2:
2477
2512
ex de , hl
2478
- ld b , (iy + 11 )
2479
- ld hl , (ix + 12 )
2513
+ ld hl , (ix + y_offset)
2514
+ ld a , (iy + t_type_height)
2515
+ or a , a
2516
+ jr z ,+ _
2517
+ ld bc , 0
2518
+ ld c , (iy + t_tile_height)
2519
+ call __idvrmu
2520
+ jr _height_no_pow2
2521
+ _: ld b , a
2480
2522
_: srl h
2481
2523
rr l
2482
2524
djnz - _
2483
- ld h , (iy + 13 )
2525
+ _height_no_pow2:
2526
+ ld h , (iy + t_width)
2484
2527
mlt hl
2485
2528
add hl , de
2486
- ld de , (iy + 0 )
2529
+ ld de , (iy + t_data )
2487
2530
add hl , de
2488
2531
pop ix
2489
2532
ret
0 commit comments