home *** CD-ROM | disk | FTP | other *** search
- ;------------------------------------------------------------------------------
- ;TextIn version 1.0-- Text input that handles upper, lowercase, and numeric chars.
- ;by Cassady Roop
- ;INPUT: hl- points to string storage area.
- ; b- max number of characters to accept and store, up to 255.
- ;OUTPUT: string stored to desired location.
- ; string displayed at pen location on the screen.
- ; if canceled with EXIT key, returns with nz. If successful, returns z.
- ;------------------------------------------------------------------------------
- TextIn:
- push hl
- call _getkey ;get keypress. it destroys hl.
- pop hl
- ld c, a
- cp kenter
- jp z, textin_commit ;enter was pressed
- cp kexit ;exit key?
- jr z, textin_cancel ;EXIT
- ld a, b ;load counter value
- cp 0 ;see if char allowance has maxed out
- jr z, TextIn ;too many characters, so bypass remaining input but not the enter and exit keys.
- ld a, c ;restore keycode to a
- cp kSpace ;is it space?
- jr z, textin_space ;it is a space
- push af ;preserve the keycode
- sub $1C ;k0
- jp m, TextIn_unknown ;it's not a known key if negative
- sub $0A ;k9 +1
- jp m, textin_number ;if neg, assumed to be a number key
- sub $02 ;kCapA
- jp m, TextIn_unknown ;it's not a known key if negative
- sub $1A ;kCapZ +1
- jp m, textin_capletter ;if negative, then assume capital letter
- sub $1B ;kz +1
- jp m, textin_lowletter ;if neg, assume lower case letter
- textin_unknown: ;go here if it is unknown
- pop af ;what gets pushed, must get popped
- jr TextIn ;must be an unknown key at this point
- textin_space:
- ld a, Lspace ;char code for space
- ld (hl), a ;put into string storage
- call _vputmap ;display a space
- inc hl ;forward pointer
- dec b ;decrement counter
- jr TextIn ;re-loop
- textin_number:
- pop af ;get the original keycode
- add a, 20 ;keycode-->char code
- ld (hl), a ;store
- call _vputmap ;display the number
- inc hl ;inc storage pointer
- dec b ;dec counter
- jr TextIn
- textin_capletter:
- pop af
- add a, 25 ;keycode-->char code
- ld (hl), a ;store
- call _vputmap ;display the letter
- inc hl ;increment string pointer
- dec b ;dec counter
- jr TextIn
- textin_lowletter:
- pop af
- add a, 31 ;keycode-->char code
- ld (hl), a
- call _vputmap
- inc hl
- dec b
- jr TextIn
- textin_commit: ;enter key pressed
- xor a ;a=0
- cp 0 ;set the z flag
- ret ;done
- textin_cancel: ;exit key pressed
- xor a ;a=0
- cp 1 ;res the z flag
- ret ;return with error
-