Karoshi MSX Community

Desarrollo MSX => Rutinas - Snipets => Mensaje iniciado por: jltursan en 02 de Octubre de 2006, 07:20:36 pm



Título: Fast NAMTBL address calculation
Publicado por: jltursan en 02 de Octubre de 2006, 07:20:36 pm
Here is a useful routine to all plattform-game makers out there (or at least I hope so... :) )

Código:
    ;------------------------------------------------------
    ;
    ; Description: Finds the address in NAMTBL of a SC2 pair of coordinates. It really works with any buffer with a width of 32 bytes... :)
    ; Input: D = coord. Y (0-191), E = coord. X (0-255)
    ; Output: HL = address in buffer
    ; Modifies: AF,HL
    ;
    ;------------------------------------------------------
    GET_ADDRESS:
    ld a,d
    and $F8
    ld h,0
    ld l,a
    add hl,hl
    add hl,hl ; (Y/8)*32
    ld a,e
    and $F8
    rrca
    rrca
    rrca ; X/8
    add a,l
    jr nc,@@NOCARRY
    inc h
    @@NOCARRY:
    ld l,a
    ld a,h
    add a,NAMTBL>>8
    ld h,a
    ret


Título: Re: Fast NAMTBL address calculation
Publicado por: CBM64 en 09 de Noviembre de 2008, 04:58:18 pm

Cojonudo, yo he estado rucando un algoritmo para hacer esto, y lo tenía aqui al alcance de la mano !!!

Además creo que el tuyo es más eficiente, ¿no?

Código:
;Calculate screen pattern's position ( 32x24 ) d=posX, e=posY, hl=Pattern name exact position
ld      a,[SPRITE1_X]
ld d, a
srl d ; d=d/2
srl d ; d=d/2
srl d ; d=d/2
ld      a,[SPRITE1_Y]
ld e, a
srl e ; e=e/2
srl e ; e=e/2
srl e ; e=e/2
xor a
ld bc, 0
ld hl, NAMETABLE1

ld a, e
cp 0
jr z, @@FINREPETICION ;There is not any Y lines left
@@NUEVALINEA:
ld bc, 32
add hl, bc  ; hl = hl + 32
dec e ; posY = posY - 1
jr nz, @@NUEVALINEA ;There is any Y lines left

@@FINREPETICION:
ld b, 0
ld c, d
add hl, bc ; hl=hl+bc


Título: Re: Fast NAMTBL address calculation
Publicado por: ARTRAG en 09 de Noviembre de 2008, 06:36:43 pm
hi CBM64,
your code is very readable and clean, but jltursan's is by far FASTER
:-)

 jltursan's code is 130/135 cycles
 yours is far longher than 230 according to Y

A trick for you:
use this
http://msx.jannone.org/bit/
to compute the cycles your code will have on MSX


Título: Re: Fast NAMTBL address calculation
Publicado por: CBM64 en 09 de Noviembre de 2008, 08:39:06 pm
So sure !!! It will be very useful !!!

Thanks a lot.