; ; This small program demonstrates the use of several of the user callable functions ; contained in D-Bug12. The routine performs the following functions: ; ; 1.) Displays a prompt by calling printf() ; 2.) Accepts an ASCII hexadecimal number typed by the user by calling GetCmdLine() ; 3.) Converts the entered number to binary by calling sscanhex() ; 4.) Displays the entered hexadecimal number as Signed Decimal, Hexadecimal, and Unsigned decimal number. ; 5.) Returns to D-Bug12 when a blank line is entered. ; ; include "DB12Macros.Asm" opt lis ; Space equ $20 ; space character. ; org $800 Buffer ds 20 ; character buffer for user input BufferP ds 2 ; pointer into the character buffer. BinNum ds 2 ; converted hex number. ; ; org $7000 ; Test: ldd #PromptStr ; load a pointer to the prompt string. jsr [printf,pcr] ; go print the prompt. GetCmdLine #Buffer,#20 ; now, go get an ASCII hex number from the user. ldx #Buffer ; point to the start of the buffer. SkipSpcs: ldaa 0,x ; get a character from the buffer. cmpa #Space ; leading space character? bne DoneSkip ; no, we're done. inx ; yes. point to the next character in the buffer. bra SkipSpcs ; go check for another space character. DoneSkip: stx BufferP ; save a pointer to the first non-blank character in the buffer. tst 0,x ; check to see if a blank line was entered. beq Done ; return to D-Bug12 if done. sscanhex BufferP,#BinNum ; convert the number from ascii to binary. cpd #0 bne PrtResult ldd #Error ; load a pointer to the error string. jsr [printf,pcr] ; go print the error message. bra Test PrtResult: ldd BinNum ; get the value of the converted number. pshd ; place three copies of the number on the stack. one for "%u" pshd ; one for "%4.4X" pshd ; one for "%d" ldd #ResultStr jsr [printf,pcr] leas 6,s bra Test Done: swi ; ; PromptStr: db $0d, $0a,"Enter a Hex number: ",0 Error: db $0d, $0a,"Invalid hexadecimal number entered.",$0d, $0a,0 ResultStr: db $0d, $0a, $0d, $0a,"Signed Decimal = %d",$0d, $0a,"Hexadecimal = %4.4X",$0d, $0a,"Unsigned decimal = %u",$0d, $0a,0