0 Members and 1 Guest are viewing this topic.
;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 ymenudisploop: 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 itemmenukeyloop: 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 itemmenucancel: inc hl ;increase to inc hl ;the next item in the jump list djnz menucancel ;repeat until at the right itemmenujump: 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 hlmenudown: 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 backmenuup: 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 backmenupickdraw: 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
;outputs the string in HL at penCol and penRow and wraps it on the screen. It also allows for manual newlines with \nDrawWrappedString: 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 DrawWrappedStringTab: ld a,(penCol) add a,6 ld (penCol),a cp 55 call nc,Newline jr DrawWrappedStringWrapLine: call Newline jr DrawWrappedStringWrapPage: lcdupdate call pause clearlcd homeup jr DrawWrappedString
;newline, wrapps screen if necessary;preserves afNewline: push af xor a ld (penCol),a ld a,(penRow) add a, 6 cp 55 jr nc,NewLine_top ld (penRow),a pop af retNewLine_top: xor a ld (penRow),a pop af ret
;Renders the text animation and text box to screen and handles text reading stuffs;inputs: hl=text_pointerText_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 stuffSlowdown: ld c,$0F_ ld b,$FF_ push bc pop bc djnz -_ dec c ld a,c or a jr nz,--_ ret