home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 86 / asm / source / routines / textin.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  2.5 KB  |  78 lines

  1. ;------------------------------------------------------------------------------
  2. ;TextIn version 1.0-- Text input that handles upper, lowercase, and numeric chars.
  3. ;by Cassady Roop
  4. ;INPUT: hl- points to string storage area.
  5. ;        b-  max number of characters to accept and store, up to 255.
  6. ;OUTPUT: string stored to desired location.
  7. ;         string displayed at pen location on the screen.
  8. ;         if canceled with EXIT key, returns with nz. If successful, returns z.
  9. ;------------------------------------------------------------------------------
  10. TextIn:
  11.     push hl
  12.     call _getkey            ;get keypress. it destroys hl.
  13.     pop hl
  14.     ld c, a
  15.     cp kenter
  16.     jp z, textin_commit        ;enter was pressed
  17.     cp kexit                ;exit key?
  18.     jr z, textin_cancel        ;EXIT    
  19.     ld a, b                    ;load counter value
  20.     cp 0                    ;see if char allowance has maxed out
  21.     jr z, TextIn            ;too many characters, so bypass remaining input but not the enter and exit keys.
  22.     ld a, c                    ;restore keycode to a
  23.     cp kSpace                ;is it space?
  24.     jr z, textin_space        ;it is a space
  25.     push af                    ;preserve the keycode
  26.     sub $1C                    ;k0
  27.     jp m, TextIn_unknown    ;it's not a known key if negative
  28.     sub $0A                    ;k9 +1
  29.     jp m, textin_number        ;if neg, assumed to be a number key
  30.     sub $02                    ;kCapA
  31.     jp m, TextIn_unknown    ;it's not a known key if negative
  32.     sub $1A                    ;kCapZ +1
  33.     jp m, textin_capletter    ;if negative, then assume capital letter
  34.     sub $1B                    ;kz +1
  35.     jp m, textin_lowletter    ;if neg, assume lower case letter
  36. textin_unknown:                ;go here if it is unknown
  37.     pop af                    ;what gets pushed, must get popped
  38.     jr TextIn                ;must be an unknown key at this point
  39. textin_space:
  40.     ld a, Lspace            ;char code for space
  41.     ld (hl), a                ;put into string storage
  42.     call _vputmap            ;display a space
  43.     inc hl                    ;forward pointer
  44.     dec b                    ;decrement counter
  45.     jr TextIn                ;re-loop
  46. textin_number:
  47.     pop af                    ;get the original keycode
  48.     add a, 20                ;keycode-->char code
  49.     ld (hl), a                ;store
  50.     call _vputmap            ;display the number
  51.     inc hl                    ;inc storage pointer
  52.     dec b                    ;dec counter
  53.     jr TextIn
  54. textin_capletter:
  55.     pop af
  56.     add a, 25                ;keycode-->char code
  57.     ld (hl), a                ;store
  58.     call _vputmap            ;display the letter
  59.     inc hl                    ;increment string pointer
  60.     dec b                    ;dec counter
  61.     jr TextIn
  62. textin_lowletter:
  63.     pop af
  64.     add a, 31                ;keycode-->char code
  65.     ld (hl), a
  66.     call _vputmap
  67.     inc hl
  68.     dec b
  69.     jr TextIn
  70. textin_commit:                ;enter key pressed
  71.     xor a                    ;a=0
  72.     cp 0                    ;set the z flag
  73.     ret                        ;done
  74. textin_cancel:                ;exit key pressed
  75.     xor a                    ;a=0
  76.     cp 1                    ;res the z flag
  77.     ret                        ;return with error
  78.