Developing my new game for the scene!

صفحة 41/75
34 | 35 | 36 | 37 | 38 | 39 | 40 | | 42 | 43 | 44 | 45 | 46

بواسطة flyguille

Prophet (3031)

صورة flyguille

28-03-2016, 23:46

well a pointer list for this kind of object will be a must have.....

Air coding

I can think something like.

for subscription
ld hl, list ; IN DE = object address.
.loop
ld a, (hl)
inc hl
or (hl)
jr z, .sub
inc hl
jp.loop
.sub:
ld (hl),d
dec hl
ld (hl), e
inc hl
inc hl
xor a
ld (hl), a
inc hl
ld (hl), a
ret

so running it will be.

ld hl, list

.loop:
ld e, (hl)
ld a, e
inc hl
or (hl)
ret z
ld d, (hl)
inc hl
push hl
ld iyl, e
ld iyh, d
....
pop hl
jp .loop

for unsuscribe

de = address

ld hl, list
.loop
ld a, (hl)
cp e
inc hl
jp nz, .next
ld a, (hl)
cp d
.next
inc hl
jp nz, .loop

ld e, l
ld d, h
dec de
dec de

.moveloop
ld a, (hl)
ld (de), a
inc hl
inc de
and a
jr nz, .nozero

ld a, (hl)
ld (de), a
inc hl
inc de
and a
ret z
jp .moveloop

ld a, (hl)
ld (de), a
inc hl
inc de
jp .moveloop

بواسطة MOA

Champion (293)

صورة MOA

28-03-2016, 23:52

	11 	ld bc, $100				; 16 pixels, remember that it is in the Map format tttttttt pppp 0000.
	 5 	and a
	17 	sbc hl, bc
	13/8	jr c, .OverlapsInTheBox

; faster alternative, using the overflow flag:

	 5 	dec h
	11  	jp pe, .OverlapsInTheBox

بواسطة flyguille

Prophet (3031)

صورة flyguille

28-03-2016, 23:55

MOA wrote:
	11 	ld bc, $100				; 16 pixels, remember that it is in the Map format tttttttt pppp 0000.
	 5 	and a
	17 	sbc hl, bc
	13/8	jr c, .OverlapsInTheBox

; faster alternative, using the overflow flag:

	 5 	dec h
	11  	jp pe, .OverlapsInTheBox

manual says about "dec r"

P/V is set if m was 80H before operation; reset otherwise

I don't understand it has to do with the previous value of the sign.

بواسطة MOA

Champion (293)

صورة MOA

29-03-2016, 00:12

Hmm, my docs were vague... only said DEC/INC 8 bit affects the overflow flag.

In that case you could still optimize it with something like:

inc h
dec h
jr z, .OverlapsInTheBox - 1
dec h
.
.


.OverlapsInTheBoxAndDecH:
dec h
.OverlapsInTheBox:

or if you don't need A to be preserved

ld a,h
sub 1
ld h,a
jr c, .OverlapsInTheBox

Subtracting or adding a multiple of 256 to a 16 bit register at least smells like an optimization target to me.

بواسطة flyguille

Prophet (3031)

صورة flyguille

29-03-2016, 00:17

MOA wrote:

Hmm, my docs were vague... only said DEC/INC 8 bit affects the overflow flag.

In that case you could still optimize it with something like:

inc h
dec h
jr z, .OverlapsInTheBox - 1
dec h
.
.


.OverlapsInTheBoxAndDecH:
dec h
.OverlapsInTheBox:

or if you don't need A to be preserved

ld a,h
sub 1
ld h,a
jr c, .OverlapsInTheBox

Subtracting or adding a multiple of 256 to a 16 bit register at least smells like an optimization target to me.

maybe P/V is handle like an overflow of the signed number, when passing the 80H barrier, like it will do in add/subs instructions

بواسطة MOA

Champion (293)

صورة MOA

29-03-2016, 00:33

Another underutilized trick is to only increase lower 8 bits of a 16 bit register if you know its alignment.

i.e.:

hl=pointer to some table, 4 byte aligned

ld e,(hl)
inc l
ld d,(hl)
inc l
.
.

hl = pointer to some table, 2 byte aligned

ld e, (hl)
inc l
ld d, (hl)
inc hl
.
.

(saving 2 cycles for each inc RR vs inc R)

بواسطة flyguille

Prophet (3031)

صورة flyguille

29-03-2016, 00:36

the previous hint

better

ld a, h ; 16 pixels, remember that it is in the Map format tttttttt pppp 0000.
and a
jr z, .OverlapsInTheBox

dec h

بواسطة MOA

Champion (293)

صورة MOA

29-03-2016, 00:39

flyguille wrote:

the previous hint

better

ld a, h ; 16 pixels, remember that it is in the Map format tttttttt pppp 0000.
and a
jr z, .OverlapsInTheBox

dec h

Yeah, I was trying to edit with an OR A, but MRC wouldn't let me as you already replied Smile The INC H/DEC H is still the best though as it doesn't spoil a register.

بواسطة hit9918

Prophet (2927)

صورة hit9918

29-03-2016, 00:49

"all is in the objects rack", the problem is always first algorithmic.
a way to avoid registering things in pointerarrays is to fill two pointerarrays on the fly.
in the one paste the addresses of objects of category 1, in the other the addresses of category 2.

say you got 32 objects.
when you couldn't make sub-regions, collision things go 32 * 32 = 1024 loops.
while wanted is M * N loops.
with filling 2 pointerarrays, it is 32 + 32 + M * N loops.

well and when you know one sub-region, that would go N * 32 loops and with one pointerarray it is 32 + N * M loops.

one array gets pasted the addresses of the objects that fit category 1,
the other one the addresses of category 2.
at the end of the arrays paste a 0 pointer.
this saves loop registers in the loops.

well and aside the algorithmic things, generaly things could be written faster. that double ex (sp),hl was extreme.
when all is cut down then the game goes in no time, it's just the blits.

بواسطة hit9918

Prophet (2927)

صورة hit9918

29-03-2016, 01:05

when in the pointerarray you put the addresses of obj.x, then you can load the X without using IX.
the tight loop can go without IX.
then, when one got an X hit, one can calculate obj base address from obj.x and continue with IX.

صفحة 41/75
34 | 35 | 36 | 37 | 38 | 39 | 40 | | 42 | 43 | 44 | 45 | 46