@@ -2314,10 +2314,10 @@ _Tilemap:
23142314; uint8_t x, x_tile, y_tile, y_next;
23152315; uint8_t x_res = x_offset/tilemap->tile_width;
23162316; uint8_t y = y_offset/tilemap->tile_height;
2317- ;
2317+ ;
23182318; x_offset = x_offset%tilemap->tile_width;
23192319; y_offset = y_offset%tilemap->tile_height;
2320- ;
2320+ ;
23212321; y_draw = tilemap->y_loc-y_offset;
23222322; for(y_tile = 0; y_tile <= tilemap->draw_height; y_tile++) {
23232323; x = x_res;
@@ -2333,6 +2333,19 @@ _Tilemap:
23332333; }
23342334; }
23352335;
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
23362349 ld hl , _Sprite \.r
23372350_: ld (DrawTile_SMC) , hl \.r
23382351 push ix
@@ -2341,65 +2354,79 @@ _: ld (DrawTile_SMC),hl \.r
23412354 add ix , sp
23422355 lea hl , ix +- 12
23432356 ld sp , hl
2344- ld iy , (ix + 6 )
2357+ ld iy , (ix + 6 ) ; iy -> tilemap structure
23452358
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
23492368 dec c
23502369 ld a , l
23512370 and a , c
23522371 ld c , a
23532372_: srl h
23542373 rr l
23552374 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;
23582378
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
23622388 dec c
23632389 ld a , l
23642390 and a , c
23652391 ld c , a
23662392_: srl h
23672393 rr l
23682394 djnz - _
2395+ _width_is_not_pow2:
23692396 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 )
23722399 or a , a
23732400 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;
23752402
23762403 or a , a
23772404 sbc hl , hl
23782405 ld l , (iy + 14 )
2379- ld bc , (ix + 12 )
2406+ ld bc , (ix + y_offset )
23802407 ld (ix +- 3 ) , h
23812408 sbc hl , bc
23822409 ld (ix +- 12 ) , hl
23832410 jp Y_Loop \.r
23842411
2385- X_Res_SMC =$+ 3
2412+ x_res_smc =$+ 3
23862413n_8: ld (ix +- 1 ) , 0
2387- ld (ix +- 2 ) , 0
2388- X_Draw_SMC =$ + 1
2414+ x_offset_smc =$ + 1
23892415 ld hl , 0
23902416 ld (ix +- 7 ) , hl
2391- ld l , (iy + 13 )
2417+ ld l , (iy + t_width )
23922418 ld h , (ix +- 4 )
23932419 mlt hl
2394- ld (Y_Next_SMC) , hl \.r
2420+ ld (y_next_smc) , hl \.r
2421+ xor a , a
23952422 jr X_Loop
23962423
2397- _InLoop_ASM :
2424+ _x_loop_inner :
23982425 sbc hl , hl
23992426 ld l , (ix +- 1 )
2400- ld bc , (iy + 0 )
2427+ ld bc , (iy + t_data) ; iy -> tilemap data
24012428 add hl , bc
2402- Y_Next_SMC =$+ 1
2429+ y_next_smc =$+ 1
24032430 ld bc , 0
24042431 add hl , bc
24052432 ld a , (hl)
@@ -2417,7 +2444,7 @@ Y_Next_SMC =$+1
24172444 ld bc , (hl)
24182445 push bc
24192446DrawTile_SMC =$ + 1
2420- call 0
2447+ call 0 ; call sprite drawing routine
24212448 lea hl , ix +- 12
24222449 ld sp , hl
24232450BlankTile:
@@ -2429,14 +2456,14 @@ BlankTile:
24292456 add hl , bc
24302457 ld (ix +- 7 ) , hl
24312458 inc (ix +- 1 )
2432- inc (ix +- 2 )
2459+ ld a , (ix +- 2 )
2460+ inc a
24332461
24342462X_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
24402467 ld l , (iy + 6 )
24412468 ld bc , (ix +- 12 )
24422469 add hl , bc
@@ -2445,7 +2472,7 @@ X_Loop:
24452472 inc (ix +- 3 )
24462473
24472474Y_Loop:
2448- ld a , (iy + 8 )
2475+ ld a , (iy + t_draw_height )
24492476 cp a , (ix +- 3 )
24502477 jp nz , n_8 \.r
24512478 ld sp , ix
@@ -2463,27 +2490,43 @@ _TilePtr:
24632490; A pointer to an indexed tile in the tilemap (so it can be looked at or changed)
24642491; C Function:
24652492; 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)];
24672494; }
24682495 push ix
24692496 ld ix , 0
24702497 add ix , sp
24712498 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
24742508_: srl h
24752509 rr l
24762510 djnz - _
2511+ _width_no_pow2:
24772512 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
24802522_: srl h
24812523 rr l
24822524 djnz - _
2483- ld h , (iy + 13 )
2525+ _height_no_pow2:
2526+ ld h , (iy + t_width)
24842527 mlt hl
24852528 add hl , de
2486- ld de , (iy + 0 )
2529+ ld de , (iy + t_data )
24872530 add hl , de
24882531 pop ix
24892532 ret
0 commit comments