Debian Codegraph @

examples/misc/minibuf0.a

raw
1 ;ACME 0.97
2 ; string entry with cursor, but user cannot destroy the screen.
3
4 !src <cbm/petscii.a>
5
6 ; some zeropage/system/kernal addresses used:
7 !address {
8 z_chars_in_keybuf = $c6
9 z_cursor_disable = $cc ; zero means interrupt handles cursor
10 z_char_under_cursor = $ce
11 z_cursor_is_visible = $cf
12 z_quote_mode = $d4
13 sys_color_under_cursor = $0287
14 k_write_to_screen = $ea13 ; A = screencode, X = color
15 k_chrout = $ffd2
16 k_getin = $ffe4
17 }
18
19 !zone minibuf0
20
21 ; config:
22 .MINIBUF_MAXSIZE = 16 ; maximum length user can type
23 !addr minibuf_buf = $200 ; where the actual buffer space is
24 ; $200 is the system's input buffer.
25 ; you could also use $100, that's what is used when numbers are
26 ; converted to their string representations.
27
28 ; actual code:
29
30 minibuf0 ; call this to get user input
31 ; on entry: place the cursor where you want it to be
32 ; on exit: X = number of characters in buffer (not terminated)
33 ldx #0 ; clear buffer
34 beq @next
35 ;always
36
37 ---- ; check for DEL key
38 cpy #petscii_DEL
39 bne +
40 txa ; if cursor is at start, do nothing!
41 beq @next
42 dex ; "remove" char from buffer
43 ; and now remove it from screen:
44 lda #0 ; clear quote flag so LEFT works
45 sta z_quote_mode
46 lda #petscii_LEFT
47 jsr k_chrout
48 lda #' '
49 jsr k_chrout
50 lda #petscii_LEFT
51 jmp @output
52 + ; check for other control characters
53 tya
54 and #%.##.....
55 beq @next ; control character, so ignore
56 ; printable:
57 tya ; restore byte
58 ; if you want to filter out unwanted characters, add your code here!
59 ; try to add byte to buffer
60 cpx #.MINIBUF_MAXSIZE ; check for overrun
61 beq @next ; buffer is full, so ignore
62 ; add byte to buf
63 sta minibuf_buf, x
64 inx ; fix content length
65 @output jsr k_chrout ; put on screen
66 @next ; wait for key with flashing cursor
67 - lda z_chars_in_keybuf
68 sta z_cursor_disable ; disable cursor on last iteration
69 beq -
70 ; if there is an artefact, remove it
71 lsr z_cursor_is_visible ; check + clear flag in one go
72 txa ; remember length
73 pha
74 bcc +
75 ; restore char under cursor
76 lda z_char_under_cursor
77 ldx sys_color_under_cursor
78 jsr k_write_to_screen ; clobbers y
79 + ; get character
80 jsr k_getin ; returns A, clobbers X and Y
81 tay ; into Y
82 pla ; restore length
83 tax
84 ; check for RETURN
85 cpy #petscii_CR
86 bne ----
87 ; X holds number of characters in buffer
88 ; if you want the string to be terminated, add these two instructions
89 ; (but don't forget to make sure the buffer is large enough):
90 ;lda #0
91 ;sta minibuf_buf, x
92 rts