home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol236 / if.mac < prev    next >
Encoding:
Text File  |  1986-02-13  |  2.4 KB  |  98 lines

  1.         title 'if'
  2.  
  3.         .z80
  4.  
  5. bdos    equ 5
  6. wboot   equ 0
  7.  
  8. ifx:    ld sp,stack        ; local stack
  9.         ld a,(80h)         ; number of characters
  10.         ld hl,81h          ; address of first character
  11.         and a
  12.         jp z,err1          ; error if no input string
  13.         ld b,a             ; for djnz counter
  14. lp0:    ld a,(hl)
  15.         cp ' '             ; scan spaces
  16.         jr nz,ex0          ; jump on non-space
  17.         inc hl
  18.         djnz lp0
  19.         jp err1
  20. ex0:    ld d,h             ; keep start location
  21.         ld e,l
  22.         ld c,0             ; to count characters
  23. lp1:    ld a,(hl)          ; get char from input string
  24.         cp '0'
  25.         jr c,ex1           ; exit if below '0'
  26.         cp '9'+1
  27.         jr c,cn1           ; accept if below '9'+1
  28.         cp 'A'
  29.         jr c,ex1           ; exit if below 'A'
  30.         cp 'Z'+1
  31.         jr nc,ex1          ; exit if below 'Z'
  32. cn1:    inc hl             ; location in string
  33.         inc c              ; character count
  34.         djnz lp1
  35.         jp err1
  36. ex1:
  37. lp2:    ld a,(hl)          ; get char from input string
  38.         cp ' '
  39.         jr nz,ex2          ; non-space
  40.         inc hl
  41.         djnz lp2           ; scan thru spaces
  42.         jp err1
  43. ex2:    cp '='
  44.         jr z,cn2
  45.         cp '#'
  46.         jp nz,err1
  47. cn2:    ld (op),a          ; keep operator
  48.         inc hl
  49.         dec b
  50.         jp z,ex4           ; second string blank
  51. lp3:    ld a,(hl)
  52.         cp ' '
  53.         jr nz,ex3          ; jump on non-space
  54.         inc hl
  55.         djnz lp3
  56.         jr ex4             ; second string blank
  57. ex3:    ex de,hl
  58. lp4:    ld a,(de)          ; char from second string
  59.         cp ' '             ; allow space
  60.         jr z,ex4
  61.         cp (hl)            ; compare with first string
  62.         jp nz,diff
  63.         inc hl
  64.         inc de
  65.         dec c
  66.         djnz lp4
  67. ex4:    ld a,c
  68.         and a
  69.         jp nz,diff         ; strings different length
  70.  
  71.                            ; strings equal
  72.         ld a,(op)          ; recover operator
  73.         cp '='
  74.         jr z,succ
  75.         jr unsu
  76. diff:   ld a,(op)          ; strings different
  77.         cp '='
  78.         jr z,unsu
  79.         jr succ
  80. succ:   ld de,0
  81.         jr ex5
  82. unsu:   ld de,0ff00h
  83.         jr ex5
  84. ex5:    ld c,108
  85.         call bdos
  86.         jp wboot
  87.  
  88. err1:   ld de,errm
  89.         ld c,9
  90.         call bdos
  91.         jr unsu
  92. errm:   db 13,10,'error in IF statement - treat as false',13,10,'$'
  93. op:     ds 1
  94.         ds 32              ; stack
  95. stack:
  96.  
  97.         end ifx
  98.