Author Topic: [TBP] Help Optimize  (Read 2730 times)

0 Members and 1 Guest are viewing this topic.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
[TBP] Help Optimize
« on: January 06, 2011, 08:33:38 pm »
Please help me optimize! Here are some of the routines I've made, let me know of any optimizations I could make :)
Thanks!
Keep in mind that I use some special defines, so if you want to know what something does, feel free to ask
Code: [Select]
;draws a menu based on a table.
MenuRoutine:
call Flushkey
call tobackbuff ;store to backbuffer to save screen
push hl ;store input
rectangle(5,4,75,61,0) \ rectangle(4,5,76,60,0) ;clear the box beneath the menu
largeSprite(4,4,9,57,MenuImg) ;draw the menu item
pop hl ;recall the input
ld a,6 ;set
ld (penCol),a ;x and
ld (penRow),a ;y loc
call DrawWrappedString ;draw it
ld a,(hl) ;get value
ld b,a ;store to b for loop
ld c,b ;current selected position
inc hl ;increase to the string
ld a,11 ;store the correct location
ld (penRow),a ;to y
menudisploop:
ld a,16 ;set
ld (penCol),a ;x
ld a,(penRow) ;get y
add a,6 ;go to newline
ld (penRow),a ;store y
call DrawWrappedString ;draw it
djnz menudisploop ;loop until b is 0
ld b,c ;store amount of items back to b
ld c,0 ;set c to first item
menukeyloop:
call menupickdraw ;draw the menu selector
lcdupdate ;update the screen
call Pause ;wait until key is pressed
call menupickdraw ;erase the menu selector
cp 04h ;up key
jr z,menuup
cp 01h ;down key
jr z,menudown
cp 0Fh ;clear key
jr z,menucancel
cp 36h ;2nd key
jr z,_
cp 09h ;enter key
jr nz,menukeyloop
_ call frombackbuff ;restore original screen
ld a,c ;check to see if c is the first item
or a ;skip next loop if so
jr z,menujump
ld b,c ;b is the selected item
menucancel:
inc hl ;increase to
inc hl ;the next item in the jump list
djnz menucancel ;repeat until at the right item
menujump:
call Flushkey
ld a,(hl) ;store the value of the first part into a
inc hl ;increate to the second half of the address
ld h,(hl) ;store the second part to h
ld l,a ;and the first to l
jp (hl) ;jump now to the address in hl
menudown:
ld a,c ;get the current item
inc a ;increase it
cp b ;if it is the max
jr z,menukeyloop ;skip next step
inc c ;otherwise actually increase it
jr menukeyloop ;then jump back
menuup:
ld a,c ;get current item
cp 0 ;if it is zero
jr z,menukeyloop ;do nothing to it
dec c ;otherwise decrease it
jr menukeyloop ;then jump back
menupickdraw:
push bc ;don't want to effect
push af ;all the registers
push hl ;so lets push them onto the stack
ld a,6 ;lets now set the correct x location
call menusetl ;and y
ld b,8 ;and height
ld ix,menupicker ;and give it the right sprite
call IPutSprite ;draw it now!
pop hl ;and now we restore
pop af ;all the registers
pop bc ;back to normal that we need
ret ;routine done!
menusetl:
push af ;protect af
ld a,c ;because we are puttin the current item into it
or a ;checking if it is zero
jr z,++_ ;if so jump forward two
xor a ;otherwise set a to zero for some math
push bc ;protect current bc
ld b,c ;load c into b
_:
add a,6 ;add 6 to a until done with b
djnz -_ ;loop de loop
pop bc ;lets get the original b back
_:
add a,16 ;add the standard 16 offset
ld l,a ;store it all to e
pop af ;reset a
ret ;done setting e
Code: [Select]
;outputs the string in HL at penCol and penRow and wraps it on the screen. It also allows for manual newlines with \n
DrawWrappedString:
ld a, (hl)
inc hl
cp '\n'
jr z, WrapLine
cp '\r'
jr z, WrapPage
cp '\t'
jr z,Tab
or a
ret z
b_call _VPutMap
ld a,(penCol)
cp 92
jr nc,WrapLine
jr DrawWrappedString
Tab:
ld a,(penCol)
add a,6
ld (penCol),a
cp 55
call nc,Newline
jr DrawWrappedString
WrapLine:
call Newline
jr DrawWrappedString
WrapPage:
lcdupdate
call pause
clearlcd
homeup
jr DrawWrappedString
Code: [Select]
;newline, wrapps screen if necessary
;preserves af
Newline:
push af
xor a
ld (penCol),a
ld a,(penRow)
add a, 6
cp 55
jr nc,NewLine_top
ld (penRow),a
pop af
ret
NewLine_top:
xor a
ld (penRow),a
pop af
ret
/e

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6266
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: [TBP] Help Optimize
« Reply #1 on: January 14, 2011, 11:12:22 am »
Code: [Select]
;Renders the text animation and text box to screen and handles text reading stuffs
;inputs: hl=text_pointer
Text_Output:
call tobackbuff
___TORevert:
push hl
rectangle(0,43,95,63,0)
box(0,43,95,63,1)
ld a,44
ld (penRow),a
ld a,2
ld (penCol),a
pop hl
___TOloop:
call Slowdown
ld a, (hl)
inc hl
cp '\n'
jr z, ___TOWrapLine
cp '\r'
jr z,___TOPage
or a
jr z, __TOEnd
b_call _VPutMap
lcdupdate
ld a,(penCol)
cp 92
jr nc,___TOWrapLine
cp 86
jr nc,+_
jr ___TOloop
_ ld a,(penRow)
push af
cp 51
jr nc,+_
pop af
jr ___TOloop
___TOWrapLine:
push af
ld a,2
ld (penCol),a
ld a,(penRow)
add a, 6
cp 57
jr nc,_
ld (penRow),a
pop af
jr ___TOloop
___TOPage:
push af
_:
push hl
sprite(87,55,8,parse_pause_sprite)
lcdupdate
call Pause
rectangle(0,43,95,63,0)
box(0,43,95,63,1)
pop hl
pop af
jp ___TORevert
__TOEnd:
push hl
sprite(87,55,8,parse_pause_sprite)
lcdupdate
call frombackbuff
call Pause
lcdupdate
pop hl
ret
;slows down stuff
Slowdown:
ld c,$0F
_ ld b,$FF
_ push bc
pop bc
djnz -_
dec c
ld a,c
or a
jr nz,--_
ret
More code for people to help me optimize, let me know if you need to know any routines called that I haven't listed.
I would really appreciate all the help I can get!
/e