; This routine takes in user input in numeral values from 0 to 65535. ; Originally written in LADS 128, an assembler by Compute!'s Gazette. ; The fundamental idea of parsing ASCII numbers into concrete decimal numbers was taken from the Second Book of Machine Language by Richard Mansfield. ; (I think.) This routine was written sometime in 1988. ; Anyway, feel free to use this routine without attribution. ; This may be hazardous to your health- LADS did not incorporate temporary ; labels, I was forced to improvise. As a result, it is slightly unreadable. ; By Todd S. Elliott ; Email addy: telliott@ubmail.ubalt.edu ; local labels bytes =4; Decrement counter. ysave =*; it is a single byte field. buffer1 =*+1; it is a 5 byte field. res =*+6; it is a 5 byte field. parsingRoutine =*; Note: This is not a valid LADS 128 symbol. I just put it ; for the sake of clarity. ldy #4; clears the buffer1 with zero's loop3 lda #0 sta buffer1,y dey bpl loop3 tay ck sty ysave; saves the y-register because getin corrupts the y-register ; The following routine actually accepts user input, deletes characters, etc. ; And only accepts numerical characters in the range of 0 to 65535. ck1 jsr getin; get a keypress cmp #13; return beq exit; if return, then exit cmp #20; delete beq del; if delete, then delete cmp #48; ascii number for 0 bcc ck1; this routine only accepts a range of numbers 0 to 9 by their cmp #58; ascii counterparts bcs ck1; ascii number for 9 plus 1 jsr chrout; prints the input ldy ysave; loads the y-register sta buffer1,y; stores the input character into the buffer1 location iny cpy #5; is it five characters, i.e., 0 to 65535? bne ck; if not, go back to get more keypresses exit lda buffer1; checks the buffer1 location for a zero. if a zero results, beq query; then exit the decimal mode. This is an unreferenced label- Just exit ; the subroutine instead. jmp cnv del ldy ysave; loads the y-register cpy #0; if it equals zero, then the user hasn't inputted a character beq ck1; go back to the input routine jsr chrout; else print the delete lda #148 jsr chrout; print a insert character lda #32 jsr chrout; print a space to negate insert mode lda #157 jsr chrout; use cursor left to go back to original position dec ysave; decrement the yregister jmp ck1; go get another keypress ; This routine actually converts the ASCII number sequence stored at BUFFER1 ; to a two-byte integer number for later processing. cnv lda #0; this routine converts the ascii numbers into a two byte integer ldx #bytes; number of bytes in result zloop sta res,x dex bpl zloop tax; .a holds a zero mainlp lda buffer1,x; gets a number sec; strip off the ascii trappings by subtracting 48 to get the number sbc #48 bcc finis pha; save this number temporarily jsr times10; multiplies the number by ten times pla clc adc res sta res bcc dox inc res+1; does the high bytes bne dox inc res+2 bne dox inc res+3 dox inx bne mainlp finis lda res+2; checks for a byte larger than zero, if so, then it beq wild; means an illegal number and must start again to get another jmp parsingRoutine; input. else return wild jsr dectohex; Unreferenced label- Use this as an opportunity to add on the ; manipulations of the RES field, as it is done. jmp parsingRoutine times10 jsr times2; multiply result by 2 jsr copyit; store it jsr times4 jsr addem rts times4 jsr times2; multiply result by 8 times2 asl res rol res+1 rol res+2 rol res+3; it adds the results of times 2 and times 8 to make times 10 rts copyit ldy #bytes cploop lda res,y sta temp,y dey bpl cploop rts addem ldy #0; how this routine works - take for example, the number 2481. clc; start with the leftmost number, 2. multiply the result (0) by 10. it's php; still zero. then add 2. now you have 2 in result. start with number 4, adloop plp; the next numeral. multiply the result (2) by 10 to get 20. then lda temp,y; add 4. now you have 24 in result. get the next numeral, 8. adc res,y; multiply the result (24) by 10 to get 240, and then add 8 to get sta res,y; 248 in the result. grab the final number, 1, and multiply the php; the result (248) by 10 to get 2480 and add 1 to get the number 2481! iny; this routine converts ascii inputted characters into an integer value cpy #max; to be used by the program bne adloop plp rts