Skip to content

Commit 8b15dfc

Browse files
committed
Changed input_str to just return 0 in length if ESC pressed
1 parent 5b56863 commit 8b15dfc

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ Preparatory routines: gotoxy (optional)<br>
375375
Registers affected: .A & .Y<br>
376376
ZP registers affected: r1 ($04-05)<br>
377377

378-
**Description** Show a cursor and get input from keyboard. The routine supports characters in the range $20-$5F and backspace. Input is written to screen and stored in the buffer at r0. The function does not return until enter/return or ESC is pressed. At that time the buffer will contain the entered string as PETSCII, .Y will contain the actual length of the input string and .A will contain the last key pressed.
378+
**Description** Show a cursor and get input from keyboard. The routine supports characters in the range $20-$5F and backspace. Input is written to screen and stored in the buffer at r0. The function does not return until enter/return or ESC is pressed. At that time the buffer will contain the entered string as PETSCII, .Y will contain the actual length of the input string or 0 if ESC was pressed.
379379

380380
|Registers | Purpose |
381381
|------|-----------------------|
382382
| .X | bg-/fg-color |
383-
| .Y | maximum length of string / Actual length on return |
383+
| .Y | maximum length of string / Actual length or 0 on return |
384384
| r0 | Pointer to pre-allocated buffer |
385385

386386
## Function name: fill_box

vtuilib-cc65.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ extern void __fastcall__ vtui_rest_rect(unsigned srcaddr, char srcram, char widt
8989
// maxlen is the maximum length allowed for the string.
9090
// Typed characters will have 'color'
9191
// High-byte = last key pressed (ENTER or ESC), low-byte = actual length
92-
extern unsigned __fastcall__ vtui_input_str(char *str, char maxlen, char color);
92+
extern char __fastcall__ vtui_input_str(char *str, char maxlen, char color);
9393

94-
#endif
94+
#endif

vtuilib-generic.asm

+7-7
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ vtui_rest_rect:
729729
; INPUTS: r0 = pointer to buffer to hold string (must be pre-allocated)
730730
; .Y = maximum length of string
731731
; .X = color information for input characters
732-
; OUPUTS: .Y = actual length of input
733-
; .A = last key pressed (RETURN or ESC)
732+
; OUPUTS: .Y = actual length of input (0 if user pressed ESC)
734733
; USES: r1l
735734
; *****************************************************************************
736735
vtui_input_str:
@@ -757,9 +756,11 @@ vtui_input_str:
757756
beq @inputloop
758757
cmp #$0D ; If RETURN has been pressed, we exit
759758
beq @end
760-
cmp #$1B ; If ESC has been pressed, we exit
761-
beq @end
762-
cmp #$14 ; We need to handle backspace
759+
cmp #$1B ; If ESC has been pressed,
760+
bne +
761+
ldy #0 ; we set length to 0 and exit
762+
bra @end
763+
+ cmp #$14 ; We need to handle backspace
763764
bne @istext
764765
cpy #0 ; If .Y is 0, we can not delete
765766
beq @inputloop
@@ -802,10 +803,9 @@ vtui_input_str:
802803
iny ; Inc .Y to show a char has been added
803804
bra @inputloop
804805

805-
@end: pha
806+
@end:
806807
lda #' '
807808
sta VERA_DATA0
808-
pla
809809
rts
810810

811811
; *****************************************************************************

0 commit comments

Comments
 (0)