   .include #macros
   .include #16bit                  ; 1 TAB = three spaces 
                                    ; use 6 for coding                      
   .if .not .def TEST
      .vfl_bochum _string1
      .vfl_bochum _string2
   .else

      .include #cio

_string1 == $F0
_string2 == $F2

main:
      dpoke    _string1,buffer1
      dpoke    _string2,headbuf
      lda      #155
      sec
      jsr      kill_0lead
      print    0,header,255,@p1+@p2+@p3
      dpoke    _string1,buffer2
      lda      #155
      sec
      jsr      kill_0lead
      print    0,header,255,@p1+@p2+@p3
      brk


header:
      .byte    "Value = "
headbuf:      
      .ds      8
         
buffer1:
      .byte    "12345",0

buffer2:
      .byte    "-00123450",0

      .endif

;; -------------------------------------------------------------
;; Pretties up a ASCII integer, this is useful after having
;; converted something via ITOA. If carry is set, then kill_0lead
;; assumes that in A there is a character that should be put 
;; at the end of the string. The integer can't be longer than
;; 255 characters and must end with a 0.
;; This routine does no error checking!!
;; 
;; _STRING1 : ASCII integer
;; -------------------------------------------------------------
kill_0lead:
      ldx   #0                ; [like to keep STD.L65 ROMamble]
      ldy   #0                ; can't optimize here, sorry
      bcs   :over             ; CS = APPEND A, CC = APPEND 0
      tya
:over      
      pha                     ; push EOS on stack
      
:loop
      lda   (_string1),y
      beq   :done
:xloop
      cmp   #'-               ; ought to be in the front only
      beq   :still
      cmp   #'+
      beq   :still
      cmp   #'0        
      beq   :eliminate
      inx  
:still
:nope
      sta   (_string2),y
      iny                     ; must not fall thru
      bne   :loop             ; that's the users responsibility
; ---
           
:eliminate
      cpx   #1                ; still in the header
      bcs   :nope             ; nope ->
      
      dec.w _string2          ; char *_string2; _string2--
      iny
      lda   (_string1),y      ; this the last 0 (was 00000 probably...)
      bne   :xloop            ; try next

:done
      pla
      sta   (_string2),y
      rts
      
