Re: A86: automatically centered text
[Prev][Next][Index][Thread]
Re: A86: automatically centered text
In a message dated 6/23/99 19:10:19 Eastern Daylight Time,
walkingmantis@hotmail.com writes:
> i was wondering how you automatically center text that has been typed in by
> the user so it appears in the middle of the screen, (horizontally). So
that
> no matter how big or small the name typed in is, it is centered in the
> middle of the screen..
puts_center:
;display centered string pointed to by hl
;a=row to display on
push hl
ld (_curRow),a
call _strlen ;c=size of string
srl c ;divide by 2
ld a,10 ;center column
sub c ;a=start column
ld (_curCol),a
pop hl ;restore pointer to string.
call _puts ;display line
jp _newline ;update row
vputs_center:
;display centered string pointed to by hl
;a=row to display on
push af
push bc
push hl
ld (_penRow),a ;set pen row
ld e,0 ;length
get_size:
ld a,(hl) ;get next byte
or a ;check if a=0
jr z,got_size ;finished getting size
push hl
push de
call _get_vchar ;hl->size of char
pop de
ld a,(hl) ;get size
add a,e ;add to cumulative length
ld e,a ;save
pop hl
inc hl ;next byte
jr get_size
got_size:
srl e ;divide by 2
ld a,64 ;center column
sub e ;a=center column
ld (_penCol),a
pop hl ;retrieve start of text
call _vputs ;print the text
pop bc
pop af
ret