Karoshi MSX Community
05 de Julio de 2021, 10:47:39 am *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: Fast NAMTBL address calculation  (Leído 6120 veces)
0 Usuarios y 1 Visitante están viendo este tema.
jltursan
Karoshi Forum's Guru
*******
Mensajes: 1516


¿Que es lo que has aprendido hoy?


WWW Email
« : 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... Smiley )

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
En línea

Doom dee doom dee doom
CBM64
Karoshi Newbie
*
Mensajes: 20


La Gran Era de los 8 Bits


Email
« Respuesta #1 : 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
En línea
ARTRAG
Visitante
« Respuesta #2 : 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
« Última modificación: 09 de Noviembre de 2008, 09:36:11 pm por AR » En línea
CBM64
Karoshi Newbie
*
Mensajes: 20


La Gran Era de los 8 Bits


Email
« Respuesta #3 : 09 de Noviembre de 2008, 08:39:06 pm »

So sure !!! It will be very useful !!!

Thanks a lot.
En línea
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!