home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / ZCNFG21.LZH / CFGLIB.LZH / RJUSTIP.Z80 < prev    next >
Text File  |  1992-11-03  |  2KB  |  78 lines

  1. ;RJUSTIP - Right JUStify Text In Place
  2. ;maves left justified text to the right end of
  3. ;the buffer at HL and move terminal spaces to
  4. ;the beginning of the buffer
  5.  
  6. ;CALL WITH:
  7. ;    HL -> fixed length buffer, left justified
  8. ;    BC: B = field width, C = Number of spaces at end
  9. ;RETURN WITH:
  10. ;    HL preserved
  11. ;    BC, DE destroyed
  12.  
  13.     public    rjip,ntspcs
  14.  
  15. rjip:    ld    a,c
  16.     cp    b
  17.     ret    z    ;all spaces - nothing to do
  18.     or    a    ;no spaces?
  19.     ret    z    ;ret if none - nothing to do
  20. ;set up pointers to move text to end of buffer
  21.     xor    a    ;reset cy, get zero
  22.     ld    d,a
  23.     ld    e,b
  24.     add    hl,de    ;->buffer end +1
  25.     dec    hl    ;-> last char
  26.     push    hl
  27.     ld    e,c
  28.     sbc    hl,de    ;->text end
  29.     pop    de    ;HL->text end, DE -> buffer end
  30. ;transfer text to end of buffer
  31.     push    bc
  32.     ld    a,b
  33.     sub    c    ;text length = b-c
  34.     ld    c,a
  35.     ld    b,0
  36.     lddr        ;de ->start of spaces
  37.     pop    bc    ;recover # of spaces
  38.     ld    b,c
  39.     ex    de,hl    ;hl->end of left fill portion
  40. bfill:    ld    (hl),' '
  41.     dec    hl
  42.     djnz    bfill    ;insert spaces until b=0
  43.     inc    hl    ;->first char of buffer
  44.     ret
  45.  
  46. NTSPCS:
  47. ;scan the field at (HL) whose length is given in BC
  48. ;or just C, counting trailing spaces.
  49. ;This routine may be used to provide input for RJIP
  50.  
  51. ;CALL WITH:
  52. ;    HL -> start of field containing text
  53. ;    C  =  length of the field (1...255)
  54.  
  55. ;RETURN WITH:
  56. ;    DE, HL are preserved
  57. ;    BC = field length in B, number of trailing spaces in C
  58.  
  59.     push    hl
  60.     ld    b,0
  61.     add    hl,bc        ;->field end + 1
  62.     ld    a,c        ;save for exit
  63.     ex    af,af'
  64.     ld    b,c        ;for max field count
  65.     ld    a,' '        ;spaces to count
  66.     ld    c,0        ;initialize counter
  67. ntspc1:    dec    hl
  68.     cp    (hl)
  69.     jr    nz,ntspcx
  70.     inc    c        ;count a space
  71.     djnz    ntspc1        ;look for another
  72. ntspcx:    pop    hl        ;-> start of field
  73.     ex    af,af'        ;recover field size
  74.     ld    b,a
  75.     ret            ;b=length, c=# terminal spaces
  76.  
  77.     end
  78.