emailler/drivers/a2input.s

205 lines
4.6 KiB
ArmAsm
Raw Normal View History

.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
.include "zeropage.inc"
2013-12-13 21:24:03 +00:00
.include "../inc/common.i"
allowed_ptr = ptr1
2013-12-13 21:24:03 +00:00
.code
; 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:
; 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
; 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:
bit $c000 ; Key down?
2013-12-13 21:24:03 +00:00
bmi get_key
lda #0
rts
; 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:
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
bit $c000 ; Key down?
2013-12-13 21:24:03 +00:00
bpl get_key_ip65
jmp get_key
; 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
; Zero characters received.
2013-12-13 21:24:03 +00:00
lda #$00
sta INPUT_Y
; Wait for a character.
2013-12-13 21:24:03 +00:00
@input_get:
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
cmp #$08 ; Delete
2013-12-13 21:24:03 +00:00
beq @delete
cmp #$0d ; Return
2013-12-13 21:24:03 +00:00
beq @input_done
; End reached?
2013-12-13 21:24:03 +00:00
lda INPUT_Y
cmp MAXCHARS
beq @input_get
; Check the allowed list of characters.
2013-12-13 21:24:03 +00:00
ldax temp_allowed
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
lda allowed_ptr+1 ; Was the input filter point nul?
2013-12-13 21:24:03 +00:00
beq @input_ok
@check_allowed:
lda (allowed_ptr),y ; Overwritten
beq @input_get ; Reached end of list (0)
2013-12-13 21:24:03 +00:00
cmp LASTCHAR
beq @input_ok ; Match found
2013-12-13 21:24:03 +00:00
; Not end or match, keep checking
2013-12-13 21:24:03 +00:00
iny
jmp @check_allowed
@input_ok:
lda LASTCHAR ; Get the char back
2013-12-13 21:24:03 +00:00
ldy INPUT_Y
sta GOTINPUT,y ; Add it to string
2013-12-13 21:24:03 +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:
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:
sec
rts
; Delete last character.
2013-12-13 21:24:03 +00:00
@delete:
; 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
; At least one character entered.
2013-12-13 21:24:03 +00:00
@delete_ok:
; Move pointer back.
2013-12-13 21:24:03 +00:00
dec INPUT_Y
; 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
; Print the backspace char
2013-12-13 21:24:03 +00:00
lda #$88
jsr print_a
; Print the a space
2013-12-13 21:24:03 +00:00
lda #$a0
jsr print_a
; Print the backspace char
2013-12-13 21:24:03 +00:00
lda #$88
jsr print_a
; Wait for next char
2013-12-13 21:24:03 +00:00
jmp @input_get
; =================================================
; Some example filters
; =================================================
2013-12-13 21:24:03 +00:00
filter_text:
.byte ",+!#$%&'()* "
filter_dns:
.byte "-ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2013-12-13 21:24:03 +00:00
filter_ip:
.byte "."
filter_number:
.byte "1234567890",0
2013-12-13 21:24:03 +00:00
.bss
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
; -- 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-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-13 21:24:03 +00:00
; The Original Code is ip65.
;
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
; Jonno Downes. All Rights Reserved.
2013-12-13 21:24:03 +00:00
; -- LICENSE END --