; *** Register rules *** ; Dedicated registers: ; r15 -- A23..A16 for external IO ; r14 -- A15..A8 for external IO ; r9 -- Current character for UART ; r5 -- Menu selection value ; General purpose registers: ; r10, r8, r7, r6 -- Return values for number conversion ; r4 -- Parameter value ; r23, r22, r21, r20, r19, r18, r12, r11, r3, r2, r1, r0 -- Temporary values ; Open: r31, r26, r25, r24, r13 ;================ ; ROUTINES ; the user input (a character from the hyperterminal) ; is matched to a function get_char: movi r15,UART import r5, REG_UART_DATA ; Read from UART cmpi r5, 'm' bz display_menu cmpi r5, 't' callz read_uptime cmpi r5, 'r' callz read_switches cmpi r5, '0' callz write_led cmpi r5, '1' callz write_led cmpi r5, '2' callz write_led cmpi r5, '3' callz write_led cmpi r5, '4' callz write_led cmpi r5, '5' callz write_led cmpi r5, '6' callz write_led cmpi r5, '7' callz write_led cmpi r5, '8' callz write_led cmpi r5, '9' callz write_led call new_prompt ret write_led: movi r9, ' ' call send_uart_data movi r9, ' ' call send_uart_data ;echo the BCD character to Hyperterminal mov r9, r5 call send_uart_data movi r15, LED_SW xori r5, 0xFF export r5, 0x00 ret ; read data from dip-switches and tx ; to hyperterminal read_switches: movi r15, LED_SW import r4, 0x00 ;call send_crlf call wait_for_uart_txrdy movi r9, ' ' call send_uart_data movi r9, ' ' call send_uart_data movi r9, 'S' call send_uart_data movi r9, 'W' call send_uart_data movi r9, ':' call send_uart_data call int2asc ; takes r4 and converts to hex nibbles in r8,r7 -- eg 0x4A => '4', 'A' movi r9, '0' call send_uart_data movi r9, 'x' call send_uart_data mov r9, r8 call send_uart_data mov r9, r7 call send_uart_data setz ret read_uptime: movi r15, TIMER export r0, 0x00 ;; issue a 'write' to latch the current time value import r4, 0x02 ;; hour byte of latched time value call wait_for_uart_txrdy movi r9, ' ' call send_uart_data movi r9, ' ' call send_uart_data movi r9, 'U' call send_uart_data movi r9, 'p' call send_uart_data movi r9, 't' call send_uart_data movi r9, 'i' call send_uart_data movi r9, 'm' call send_uart_data movi r9, 'e' call send_uart_data movi r9, ':' call send_uart_data movi r9, ' ' call send_uart_data call int2asc10 ; takes r4 and converts to BCD in r8,r7,r6 mov r9, r8 call send_uart_data mov r9, r7 call send_uart_data mov r9, r6 call send_uart_data movi r9, 'h' call send_uart_data movi r15, TIMER import r4, 0x01 ;; minute byte of time of latched time value call int2asc10 ; takes r4 and converts to BCD in r8,r7,r6 mov r9, r7 call send_uart_data mov r9, r6 call send_uart_data movi r9, 'm' call send_uart_data movi r15, TIMER import r4, 0x00 ;; seconds byte of time of latched time value call int2asc10 ; takes r4 and converts to BCD in r8,r7,r6 mov r9, r7 call send_uart_data mov r9, r6 call send_uart_data movi r9, 's' call send_uart_data setz ret int2asc10: ; input in r4 ; outputs to r8(100's), r7(10's), r6(1's) mov r6, r4 movi r7, 0x00 ; tens movi r8, 0x00 ; hundreds compare_10: cmpi r6, 10 bnc incr_tens b bcd_done incr_tens: subi r6, 10 addi r7, 1 cmpi r7, 10 bz incr_hundreds b compare_10 incr_hundreds: addi r8, 1 movi r7, 0 b compare_10 bcd_done: addi r6, 0x30 addi r7, 0x30 addi r8, 0x30 ret int2asc: ; input in r4 ; outputs to r8 (MS-Nibble), r7 (LS-Nibble) mov r7, r4 mov r8, r4 andi r7, 0x0F andi r8, 0xF0 ror r8, r8 ror r8, r8 ror r8, r8 ror r8, r8 cmpi r7, 0x0A bnc r7_is_alpha addi r7, 0x30 conv_r8: cmpi r8, 0x0A bnc r8_is_alpha addi r8, 0x30 b int2asc_done r7_is_alpha: addi r7, 0x37 b conv_r8 r8_is_alpha: addi r8, 0x37 int2asc_done: ret