Subversion Repositories SvarDOS

Rev

Rev 426 | Rev 437 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 426 Rev 430
Line 327... Line 327...
327
    dst[end] = 0;
327
    dst[end] = 0;
328
  }
328
  }
329
}
329
}
330
 
330
 
331
 
331
 
332
/* converts an ASCIIZ string into an unsigned short. returns 0 on success. */
332
/* converts an ASCIIZ string into an unsigned short. returns 0 on success.
-
 
333
 * on error, result will contain all valid digits that were read until
-
 
334
 * error occurred (0 on overflow or if parsing failed immediately) */
333
int atous(unsigned short *r, const char *s) {
335
int atous(unsigned short *r, const char *s) {
334
  int err = 0;
336
  int err = 0;
335
 
337
 
336
  _asm {
338
  _asm {
337
    mov si, s
339
    mov si, s
Line 345... Line 347...
345
    /* is AL 0? if so we're done */
347
    /* is AL 0? if so we're done */
346
    test al, al
348
    test al, al
347
    jz DONE
349
    jz DONE
348
    /* validate that AL is in range '0'-'9' */
350
    /* validate that AL is in range '0'-'9' */
349
    sub al, '0'
351
    sub al, '0'
350
    jc FAIL   /* neg result */
352
    jc FAIL   /* invalid character detected */
351
    cmp al, 9
353
    cmp al, 9
352
    jg FAIL
354
    jg FAIL   /* invalid character detected */
353
    /* restore result into AX (CX contains the new digit) */
355
    /* restore result into AX (CX contains the new digit) */
354
    xchg cx, ax
356
    xchg cx, ax
355
    /* multiply result by 10 and add cl */
357
    /* multiply result by 10 and add cl */
356
    mul bx    /* DX AX = AX * BX(10) */
358
    mul bx    /* DX AX = AX * BX(10) */
357
    jc FAIL   /* overflow */
359
    jc OVERFLOW  /* overflow */
358
    add ax, cx
360
    add ax, cx
359
    /* if CF then overflow occured (overflow part lands in DX) */
361
    /* if CF is set then overflow occurred (overflow part lands in DX) */
360
    jnc NEXTBYTE
362
    jnc NEXTBYTE
361
 
363
 
-
 
364
    OVERFLOW:
-
 
365
    xor cx, cx  /* make sure result is zeroed in case overflow occured */
-
 
366
 
362
    FAIL:
367
    FAIL:
363
    inc [err]
368
    inc [err]
364
 
369
 
365
    DONE: /* save result (CX) into indirect memory address r */
370
    DONE: /* save result (CX) into indirect memory address r */
366
    mov bx, [r]
371
    mov bx, [r]