2013-12-27 13:57:56 +00:00
|
|
|
.export get_key
|
2013-12-13 21:24:03 +00:00
|
|
|
.export check_for_abort_key
|
|
|
|
.export get_filtered_input
|
|
|
|
.export filter_text
|
|
|
|
.export filter_ip
|
|
|
|
.export filter_dns
|
|
|
|
.export filter_number
|
|
|
|
.export get_key_ip65
|
|
|
|
.export get_key_if_available
|
|
|
|
|
|
|
|
.import ip65_process
|
|
|
|
.import print_a
|
|
|
|
.import print_hex
|
|
|
|
|
|
|
|
.importzp copy_src
|
|
|
|
|
|
|
|
.include "../inc/common.i"
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
allowed_ptr = copy_src ; reuse zero page
|
|
|
|
|
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
.code
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
; use Apple 2 monitor ROM function to read from keyboard
|
|
|
|
; inputs: none
|
|
|
|
; outputs: A contains ASCII code of key pressed
|
2013-12-13 21:24:03 +00:00
|
|
|
get_key:
|
2013-12-27 13:57:56 +00:00
|
|
|
; lda #$a0
|
|
|
|
; lda #$20
|
|
|
|
; ldy #$24 ; KEYIN assumes Y is loaded with column
|
|
|
|
; jmp $fd1b
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp $fd0c
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; inputs: none
|
|
|
|
; outputs: A contains ASCII value of key just pressed (0 if no key pressed)
|
2013-12-13 21:24:03 +00:00
|
|
|
get_key_if_available:
|
2013-12-27 13:57:56 +00:00
|
|
|
bit $c000 ; Key down?
|
2013-12-13 21:24:03 +00:00
|
|
|
bmi get_key
|
|
|
|
lda #0
|
|
|
|
rts
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; check whether the escape key is being pressed
|
|
|
|
; inputs: none
|
|
|
|
; outputs: sec if escape pressed, clear otherwise
|
2013-12-13 21:24:03 +00:00
|
|
|
check_for_abort_key:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda $c000 ; current key pressed
|
|
|
|
cmp #$9B
|
|
|
|
bne :+
|
|
|
|
bit $c010 ; clear the keyboard strobe
|
|
|
|
sec
|
|
|
|
rts
|
|
|
|
: clc
|
|
|
|
rts
|
|
|
|
|
|
|
|
; process inbound ip packets while waiting for a keypress
|
2013-12-13 21:24:03 +00:00
|
|
|
get_key_ip65:
|
|
|
|
jsr ip65_process
|
2013-12-27 13:57:56 +00:00
|
|
|
bit $c000 ; Key down?
|
2013-12-13 21:24:03 +00:00
|
|
|
bpl get_key_ip65
|
|
|
|
jmp get_key
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; cribbed from http://codebase64.org/doku.php?id=base:robust_string_input
|
|
|
|
; ======================================================================
|
|
|
|
; Input a string and store it in GOTINPUT, terminated with a null byte.
|
|
|
|
; AX is a pointer to the allowed list of characters, null-terminated.
|
|
|
|
; set AX to $0000 for no filter on input
|
|
|
|
; max # of chars in y returns num of chars entered in y.
|
|
|
|
; ======================================================================
|
2013-12-13 21:24:03 +00:00
|
|
|
; Main entry
|
|
|
|
get_filtered_input:
|
|
|
|
sty MAXCHARS
|
|
|
|
stax temp_allowed
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Zero characters received.
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #$00
|
|
|
|
sta INPUT_Y
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Wait for a character.
|
2013-12-13 21:24:03 +00:00
|
|
|
@input_get:
|
2013-12-27 13:57:56 +00:00
|
|
|
jsr get_key_ip65
|
|
|
|
; convert to standard ASCII by turning off high bit
|
2013-12-13 21:24:03 +00:00
|
|
|
and #$7f
|
|
|
|
sta LASTCHAR
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$08 ; Delete
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @delete
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
cmp #$0d ; Return
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @input_done
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; End reached?
|
2013-12-13 21:24:03 +00:00
|
|
|
lda INPUT_Y
|
|
|
|
cmp MAXCHARS
|
|
|
|
beq @input_get
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Check the allowed list of characters.
|
2013-12-13 21:24:03 +00:00
|
|
|
ldax temp_allowed
|
2013-12-27 13:57:56 +00:00
|
|
|
stax allowed_ptr ; Since we are reusing this zero page, it may not stil be the same value since last time!
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy #$00
|
2013-12-27 13:57:56 +00:00
|
|
|
lda allowed_ptr+1 ; Was the input filter point nul?
|
2013-12-13 21:24:03 +00:00
|
|
|
beq @input_ok
|
|
|
|
@check_allowed:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda (allowed_ptr),y ; Overwritten
|
|
|
|
beq @input_get ; Reached end of list (0)
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
cmp LASTCHAR
|
2013-12-27 13:57:56 +00:00
|
|
|
beq @input_ok ; Match found
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Not end or match, keep checking
|
2013-12-13 21:24:03 +00:00
|
|
|
iny
|
|
|
|
jmp @check_allowed
|
|
|
|
|
|
|
|
@input_ok:
|
2013-12-27 13:57:56 +00:00
|
|
|
lda LASTCHAR ; Get the char back
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy INPUT_Y
|
2013-12-27 13:57:56 +00:00
|
|
|
sta GOTINPUT,y ; Add it to string
|
2013-12-13 21:24:03 +00:00
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
inc INPUT_Y ; Next character
|
|
|
|
jsr print_a
|
|
|
|
; Not yet.
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @input_get
|
|
|
|
|
|
|
|
@input_done:
|
2013-12-27 13:57:56 +00:00
|
|
|
ldy INPUT_Y
|
|
|
|
beq @no_input
|
|
|
|
lda #$00
|
|
|
|
sta GOTINPUT,y ; Zero-terminate
|
|
|
|
clc
|
|
|
|
ldax #GOTINPUT
|
|
|
|
rts
|
2013-12-13 21:24:03 +00:00
|
|
|
@no_input:
|
2013-12-27 13:57:56 +00:00
|
|
|
sec
|
|
|
|
rts
|
|
|
|
; Delete last character.
|
2013-12-13 21:24:03 +00:00
|
|
|
@delete:
|
2013-12-27 13:57:56 +00:00
|
|
|
; First, check if we're at the beginning. If so, just exit.
|
2013-12-13 21:24:03 +00:00
|
|
|
lda INPUT_Y
|
|
|
|
bne @delete_ok
|
|
|
|
jmp @input_get
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; At least one character entered.
|
2013-12-13 21:24:03 +00:00
|
|
|
@delete_ok:
|
2013-12-27 13:57:56 +00:00
|
|
|
; Move pointer back.
|
2013-12-13 21:24:03 +00:00
|
|
|
dec INPUT_Y
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Store a zero over top of last character, just in case no other characters are entered.
|
2013-12-13 21:24:03 +00:00
|
|
|
ldy INPUT_Y
|
|
|
|
lda #$00
|
|
|
|
sta GOTINPUT,y
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Print the backspace char
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #$88
|
|
|
|
jsr print_a
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Print the a space
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #$a0
|
|
|
|
jsr print_a
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Print the backspace char
|
2013-12-13 21:24:03 +00:00
|
|
|
lda #$88
|
|
|
|
jsr print_a
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; Wait for next char
|
2013-12-13 21:24:03 +00:00
|
|
|
jmp @input_get
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; =================================================
|
|
|
|
; Some example filters
|
|
|
|
; =================================================
|
2013-12-13 21:24:03 +00:00
|
|
|
filter_text:
|
|
|
|
.byte ",+!#$%&'()* "
|
|
|
|
filter_dns:
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte "-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
2013-12-13 21:24:03 +00:00
|
|
|
filter_ip:
|
2013-12-27 13:57:56 +00:00
|
|
|
.byte "."
|
|
|
|
filter_number:
|
|
|
|
.byte "1234567890",0
|
|
|
|
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
.bss
|
2013-12-27 13:57:56 +00:00
|
|
|
|
|
|
|
temp_allowed: .res 2
|
|
|
|
MAXCHARS: .res 1
|
|
|
|
LASTCHAR: .res 1
|
|
|
|
INPUT_Y: .res 1
|
|
|
|
GOTINPUT: .res 40
|
2013-12-13 21:24:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-27 13:57:56 +00:00
|
|
|
; -- LICENSE FOR a2input.s --
|
2013-12-13 21:24:03 +00:00
|
|
|
; The contents of this file are subject to the Mozilla Public License
|
|
|
|
; Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
; compliance with the License. You may obtain a copy of the License at
|
|
|
|
; http://www.mozilla.org/MPL/
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; Software distributed under the License is distributed on an "AS IS"
|
|
|
|
; basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
; License for the specific language governing rights and limitations
|
|
|
|
; under the License.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Original Code is ip65.
|
2013-12-27 13:57:56 +00:00
|
|
|
;
|
2013-12-13 21:24:03 +00:00
|
|
|
; The Initial Developer of the Original Code is Jonno Downes,
|
|
|
|
; jonno@jamtronix.com.
|
|
|
|
; Portions created by the Initial Developer are Copyright (C) 2009
|
2013-12-27 13:57:56 +00:00
|
|
|
; Jonno Downes. All Rights Reserved.
|
2013-12-13 21:24:03 +00:00
|
|
|
; -- LICENSE END --
|