home *** CD-ROM | disk | FTP | other *** search
- ;************************************************************************
- ;* formatiere Strings *
- ;* iy ist Adresse der Ausgaberoutine *
- ;* alle Register werden gerettet *
- ;************************************************************************
-
- .z80 ;
- entry _scanf ;
- cr equ 13 ;
- lf equ 10 ;
-
- _scanf: ld b,0 ; args for now...
- scanf_main: ld a,(hl) ; Zeichen
- or a ; 0 = Ende!
- jr z,exit_scan ;
- inc hl ; point to next char
- cp '\' ; DataLinkEscape?
- jr z,special_char ;
- cp '%' ; insert-Byte?
- jr z,insrt_number ;
- cp '^' ; ctrl-char?
- jr z,ctrl_char ;
- cmp_this: ld c,a ; save akku
- call _iy ; get char
- cp c ; equal?
- jr z,scanf_main ;
- ret_bad: scf ; not ok
- exit_scan: ret nc ; if everything in order...
- exit_bad: inc b ;
- dec b ;
- ret z ; no args (yet)
- pop hl ;
- flush: pop de ; all bad args down!
- djnz flush ;
- jp (hl) ; return this way...
-
-
- ctrl_char: ld a,(hl) ;
- sub '@' ;
- cp ' ' ; must be less...
- jr nc,scanf_main ; then try again
- inc hl ;
- jr cmp_this ;
-
- special_char: ld a,(hl) ;
- cp ' ' ; must be greater
- jr c,scanf_main ;
- inc hl ;
- cp 'n' ; for cr,lf
- jr nz,cmp_this ;
- call _iy ;
- cp cr ; must follow cr,lf
- jr nz,ret_bad ;
- ld a,lf ;
- jr cmp_this ;
-
- insrt_number: ld ix,tab_base ;
- call _parms## ; get base & other spec. values
- ; returns carry, if error
- jr c,scanf_main ; format error, ignore
-
- jp p,calc_base ;
- cp 0feh ;
- jr nz,scanf_main ;
-
- prchar: call _iy ; get character
- ld c,0 ;
- set_a: inc hl ;
- inc b ;
- pop de ;
- push hl ;
- ld l,a ;
- ld h,c ;
- ex (sp),hl ;
- push de ; arg. on stack
- jp scanf_main ; auf zu neuen Taten...
-
- calc_base: ld (base),a ;
- push hl ;
- push bc ;
- ld a,(n_digit) ;
- ld c,a ;
- ld hl,0 ;
- get_num: ld a,0 ;
- base equ $-1 ;
- call _multa## ;
- call _iy ;
- ld b,a ;
- ld a,(leading) ;
- sub b ;
- jr z,below_10 ; akku = 0, all OK
- ld a,'0' ; disable leading spaces
- ld (leading),a ;
- ld a,b ;
- sub '0' ;
- cp 10 ;
- jr c,below_10 ;
- or ' ' ; tolower
- sub ' '+7 ;
- below_10: ld b,a ;
- ld a,(base) ;
- dec a ;
- cp b ;
- jr c,ret_bad2 ; bad digit
- ld a,b ;
- call _adda## ;
- jr c,ret_bad2 ; overflow
- dec c ;
- jr nz,get_num ;
- ld a,(mask_h) ;
- cp h ; over 00ffh?
- jr c,ret_bad2 ;
- pop bc ;
- ld c,h ;
- ld a,l ;
- pop hl ;
- jr set_a ;
- ret_bad2: pop bc ;
- pop hl ;
- jp exit_bad ; Carry is set!
-
- _iy: jp (iy) ;
-
- dseg ;
- mask_h: db 0 ;
- n_digit: db 0ffh ;
- leading: db ' ' ;
- tab_base: ;
- cseg ;
- end ;
-