base:ip_address_input
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | base:ip_address_input [2015-04-17 04:32] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | With all the network cards for the C64 these days, a user-friendly IP address input/ | ||
+ | Use in conjunction with the [[robust_string_input]] code. DASM. | ||
+ | |||
+ | < | ||
+ | ; ====================================== | ||
+ | ; IP Address Input routine - Schema/AIC | ||
+ | ; ====================================== | ||
+ | |||
+ | ;Converts e.g. | ||
+ | ; | ||
+ | ;to | ||
+ | ;ABC ABC ABC ABC | ||
+ | ; | ||
+ | ;and then to 4 bytes at gotip | ||
+ | |||
+ | include " | ||
+ | |||
+ | IPADDRESS_FILTER | ||
+ | dc.b " | ||
+ | |||
+ | getip | ||
+ | lda #$00 | ||
+ | sta $cc ; Force cursor to flash | ||
+ | | ||
+ | lda #> | ||
+ | ldx #< | ||
+ | ldy # | ||
+ | jsr FILTERED_INPUT | ||
+ | jsr CONVERTIP | ||
+ | | ||
+ | lda #$01 | ||
+ | sta $cc ; Force cursor to not flash | ||
+ | lda # | ||
+ | jsr $ffd2 ;overwrite cursor detritus | ||
+ | rts | ||
+ | |||
+ | gotip | ||
+ | dc.b $00, | ||
+ | |||
+ | ; | ||
+ | |||
+ | DOTS | ||
+ | dc.b #$00 | ||
+ | |||
+ | STRINDEX | ||
+ | dc.b #$00 | ||
+ | |||
+ | IPINDEX | ||
+ | dc.b $00 | ||
+ | |||
+ | CONVERTIP | ||
+ | ;First, check that there are three periods ' | ||
+ | ldx #$00 | ||
+ | sta DOTS | ||
+ | sta IPINDEX | ||
+ | sta STRINDEX | ||
+ | COUNTLOOP | ||
+ | lda GOTINPUT,x | ||
+ | beq DONECOUNT | ||
+ | cmp #'. | ||
+ | bne COUNTNEXT | ||
+ | inc DOTS | ||
+ | COUNTNEXT | ||
+ | inx | ||
+ | jmp COUNTLOOP | ||
+ | |||
+ | DONECOUNT | ||
+ | lda DOTS | ||
+ | cmp #$03 | ||
+ | beq DOTSOK | ||
+ | jmp INVALIDIP | ||
+ | |||
+ | |||
+ | ; OK, now pad the values if needed for the conversion, one octet at a time | ||
+ | DOTSOK | ||
+ | |||
+ | ;Init A,B,C with 0 | ||
+ | NEXTBYTE | ||
+ | lda #$0 | ||
+ | sta A | ||
+ | sta B | ||
+ | sta C | ||
+ | |||
+ | BYTELOOP | ||
+ | ldx STRINDEX | ||
+ | lda GOTINPUT,x | ||
+ | beq ENDOFBYTE | ||
+ | cmp #'. | ||
+ | beq ENDOFBYTE | ||
+ | | ||
+ | ;Shift ABC over | ||
+ | ldy B | ||
+ | sty A ;old A is lost | ||
+ | ldy C | ||
+ | sty B | ||
+ | sbc #$30 ;Convert from PETSCII to equivalent value | ||
+ | sta C ; | ||
+ | |||
+ | NEXTDIGIT | ||
+ | inc STRINDEX | ||
+ | jmp BYTELOOP | ||
+ | |||
+ | ENDOFBYTE | ||
+ | jsr dec2hex | ||
+ | | ||
+ | bcs INVALIDIP | ||
+ | | ||
+ | ;Save the returned byte | ||
+ | ldy IPINDEX | ||
+ | sta gotip,y | ||
+ | inc IPINDEX | ||
+ | lda IPINDEX | ||
+ | cmp #$04 ;Done | ||
+ | beq IP_DONE | ||
+ | | ||
+ | inc STRINDEX | ||
+ | jmp NEXTBYTE | ||
+ | |||
+ | IP_DONE | ||
+ | rts | ||
+ | |||
+ | |||
+ | INVALIDIP | ||
+ | ; ERROR MESSAGE HERE! | ||
+ | inc $d020 | ||
+ | jmp INVALIDIP | ||
+ | rts | ||
+ | |||
+ | |||
+ | ; | ||
+ | ; Convert three-digit decimal (ABC) into a byte | ||
+ | ; | ||
+ | |||
+ | dec2hex | ||
+ | lda A | ||
+ | jsr MULT10 | ||
+ | jsr MULT10 | ||
+ | sta TMP0 | ||
+ | lda B | ||
+ | jsr MULT10 | ||
+ | sta TMP1 | ||
+ | lda C | ||
+ | sta TMP2 ;x1 | ||
+ | | ||
+ | clc | ||
+ | lda #$00 | ||
+ | adc TMP0 | ||
+ | adc TMP1 | ||
+ | adc TMP2 | ||
+ | rts ; | ||
+ | |||
+ | ; =================== | ||
+ | |||
+ | TMP0 | ||
+ | dc.b #$00 | ||
+ | |||
+ | TMP1 | ||
+ | dc.b #$00 | ||
+ | |||
+ | TMP2 | ||
+ | dc.b #$00 | ||
+ | |||
+ | A ; | ||
+ | dc.b #$00 | ||
+ | |||
+ | B ; | ||
+ | dc.b #$00 | ||
+ | |||
+ | C ; | ||
+ | dc.b #$00 | ||
+ | |||
+ | |||
+ | ; ======================================================================= | ||
+ | ; Multiply by 10 - from http:// | ||
+ | |||
+ | MULT10 | ||
+ | STA TEMP10 | ||
+ | ASL ; | ||
+ | ASL ; | ||
+ | CLC | ||
+ | ADC TEMP10 | ||
+ | RTS | ||
+ | |||
+ | TEMP10 | ||
+ | </ |
base/ip_address_input.txt · Last modified: 2015-04-17 04:32 by 127.0.0.1