-
Notifications
You must be signed in to change notification settings - Fork 3
/
input.asm
executable file
·129 lines (108 loc) · 2.76 KB
/
input.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Keyboard input
// --------------
//
// Uses the kernel to get data from the keyboard.
// Taken from http://codebase64.org/doku.php?id=base:robust_string_input
//
//======================================================================
//Input a string and store it in INPUT_BUFFER, terminated with a null byte.
//x:a is a pointer to the allowed list of characters, null-terminated.
//max # of chars in y returns num of chars entered in y.
//======================================================================
// Get alphanumeric text
GET_TEXT:
lda #>ALPHANUM_FILTER
ldx #<ALPHANUM_FILTER
ldy #32
jmp FILTERED_INPUT
// Get decimal numbers.
// y = max chars
GET_DECIMAL:
lda #>DECIMAL_FILTER
ldx #<DECIMAL_FILTER
jmp FILTERED_INPUT
// y = max chars
// x = lsb filter string
// a = msb filter string
FILTERED_INPUT:
sty MAXCHARS
stx allowed+1 // set pointer to filter list.
sta allowed+2
lda #$00 // Zero characters received.
sta INPUT_LEN
sta INPUT_BUFFER
jsr print_cursor
get_input:
jsr GETIN
beq get_input
sta LASTCHAR // store character typed
cmp #$14 // Delete
beq delete
cmp #$0d // Return
beq input_done
// Check the allowed list of characters.
ldx #$00
allowed:
lda $FFFF,x // get allowed char list
beq get_input // reached end with no match
cmp LASTCHAR
beq input_ok // Match found
inx
jmp allowed // get next character
input_ok:
lda INPUT_LEN
cmp MAXCHARS // max length reached?
bne !+
dec INPUT_LEN // replace last character in buffer
lda #$9d // do crsr left on screen
jsr BSOUT
!:
lda LASTCHAR // get typed character
ldy INPUT_LEN // get buffer index
sta INPUT_BUFFER,y // Add char to buffer
jsr BSOUT // Print it
jsr print_cursor
inc INPUT_LEN // update index
lda INPUT_LEN
jmp get_input
input_done:
ldy INPUT_LEN
lda #$00
sta INPUT_BUFFER,y // Zero-terminate the input buffer
jsr remove_cursor
rts
delete:
lda INPUT_LEN
beq get_input
dec INPUT_LEN
lda #$14 // do back space on screen
jsr BSOUT
jmp get_input
print_cursor:
lda #>CURSOR
ldx #<CURSOR
jsr PRINT
rts
remove_cursor:
lda #>CURSOR_REM
ldx #<CURSOR_REM
jsr PRINT
rts
DECIMAL_FILTER:
.text "1234567890"
.byte 0
ALPHANUM_FILTER:
.text " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.,-+!#$%&'()*/"
.byte 0
MAXCHARS:
.byte 0
LASTCHAR:
.byte 0
INPUT_LEN:
.byte 0
INPUT_BUFFER:
.fill 32, 0
CURSOR:
.byte $12, $20, $92, $9d, 0
CURSOR_REM:
.byte $20, 0