- Optimizing grayscale and other questions
- 06 Dec 2009 01:28:25 pm
- Last edited by lindenk on 14 Dec 2009 05:54:25 pm; edited 13 times in total
Ok so for a game I'm programming I have a grayscale routine and I'd like to know if I can make it better. I haven't actually had a chance to test it yet because I'm still working on the game but I need to have it done very soon so I'm asking about it now. Heres the code -
Code:
Code:
.deflong sprite1()
ld a,(hl)
inc hl
xor (hl)
and c
xor (hl)
out (11),a
inc hl
.enddeflong
.deflong sprite2()
ld a,(hl)
inc hl
xor (hl)
and d
xor (hl)
out (11),a
inc hl
.enddeflong
.deflong sprite3()
ld a,(hl)
inc hl
xor (hl)
and e
xor (hl)
out (11),a
inc hl
.enddeflong
Grayscale: ;x = 16/40/64 y = 21
exx
ex af,af'
push af
sub 0
jr z,grycont
pop af
ld a,3
push af
ld c,%01101101
ld d,%10110110
ld e,%11011011
jr grycont3
grycont
dec a
jr z,grycont2
ld c,%10110110
ld d,%11011011
ld e,%01101101
jr grycont3
grycont2
ld c,%11011011
ld d,%01101101
ld e,%10110110
grycont3
ld a,$94 ;only displaying sprites in set locations
out (10),a
ld b,2
ld hl,monsprite1
ld a,$22
out (10),a
Gryloop:
sprite1()
sprite2()
sprite3()
sprite1()
sprite2()
sprite3()
sprite1()
sprite2() ;8 times
sprite3()
sprite1()
sprite2()
sprite3()
sprite1()
sprite2()
sprite3()
sprite1() ;16 times
ld a,$07 ;go right
out (10),a
sprite2()
ld a,$04
out (10),a ;go up
sprite3()
sprite1()
sprite2()
sprite3()
sprite1()
sprite2()
sprite3()
sprite1() ;8
sprite2()
sprite3()
sprite1()
sprite2()
sprite3()
sprite1()
sprite2() ;15
ld a,$05 ;go down
out (10),a
GryWaitloop:
in a,(10)
jr m,grywaitloop
dec b ;1st go b = 1, 2nd b=0 3rd = 255 + c
jr z,grymon3
jr c,gryret
ld a,$25 ;row is set at the right spot
out (10),a
jr gryloop
grymon3:
ld a,$28
out (10),a
gryret:
pop af
dec a
ex af,af'
exx
ret