Ctrl-C¶
To interrupt a running system at any time and reset it to the prompt a keyboard command ctrl-c is often used. AmForth can honour such a keystroke as well. To achieve it, a small code change needs to be applied and a new hex file pair has to be flashed to the controller.
The code change affects the interrupt usart handler
(drivers/usart-rx-isr.asm). Here add the 4
lines 5-8:
1 lds xh, USART_DATA
2 ; optional: check for certain character(s) (e.g. CTRL-C)
3 ; and trigger a soft interrupt instead of storing the
4 ; charater into the input queue.
5 cpi xh, 3
6 brne usart_rx_store
7 jmp 0
8usart_rx_store:
9 lds xl, usart_rx_in
With this change, whenever the keyboard sends the ascii code 3 (for ctrl-c) it is catched immediately and a soft reset is made. it requires that the WANT_ISR_RX option is set to 1.