home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 83 / asm / source / routines / vputsc.z80 < prev   
Encoding:
Text File  |  2001-07-01  |  2.7 KB  |  78 lines

  1. ;--------= put string centered =--------
  2. ; Author:       Ian Graf
  3. ;               (ian_graf@geocities.com)
  4. ; Platform:     TI-83 Assembly
  5. ; Version:      1.0
  6. ; Date:         10/6/98
  7. ;---------------------------------------
  8. ; to use this routine load hl with the
  9. ; location of the string to center on
  10. ; the graph screen. the string will be
  11. ; drawn centered at penrow.
  12. ;
  13. ; ex:
  14. ;
  15. ;       ld      hl,somestring
  16. ;       call    vputsc
  17. ;
  18. ; feel free to use this in your own
  19. ; programs, but please give me credit.
  20. ;---------------------------------------
  21.  
  22.  
  23.         #define sfontlen        $4A6C
  24.         #define vputs           $4781
  25.         #define pencol          $8252
  26.  
  27.  
  28. ;--------= put string centered =--------
  29. ; input:        hl - string
  30. ;               penrow - row
  31. ; output:       string drawn centered/
  32. ;               cliped
  33.  
  34. vputsc: push    hl                      ;
  35.         call    getlength               ; get length of string
  36.         ld      b,e                     ;
  37.         xor     a                       ;
  38. countl: push    bc                      ;
  39.         push    hl                      ;
  40.         push    af                      ;
  41.         ld      a,(hl)                  ; get character
  42.         ld      h,0                     ;
  43.         ld      l,a                     ;
  44.         add     hl,hl                   ; hl = hl*8
  45.         add     hl,hl                   ;
  46.         add     hl,hl                   ;
  47.         call    sfontlen                ; get char width
  48.         pop     af                      ;
  49.         cp      93                      ; clip?
  50.         jr      nc,contc                ;
  51.         add     a,b                     ;
  52. contc:  pop     hl                      ;
  53.         inc     hl                      ;
  54.         pop     bc                      ;
  55.         djnz    countl                  ;
  56.         ld      b,a                     ; center string
  57.         ld      a,96                    ;
  58.         sub     b                       ;
  59.         srl     a                       ;
  60.         ld      (pencol),a              ;
  61.         pop     hl                      ;
  62.         jp      vputs                   ; draw string
  63.  
  64.  
  65. ;--------= get length of string =-------
  66.  
  67. getlength:
  68.         ld      bc,100                  ; get length of string in hl
  69.         xor     a                       ; max length 100 chars
  70.         push    hl                      ; (the max length can be changed
  71.         cpir                            ; to fit your needs)
  72.         ld      hl,99                   ;
  73.         sbc     hl,bc                   ;
  74.         ex      de,hl                   ;
  75.         pop     hl                      ;
  76.         ret                             ; de = length
  77.  
  78.