' keyboard.asm ' asks for user's name and says something polite ' ' Written by: Stefan for R6 ' stefan@imaginarymicrocomputers.net array text = "HI! I AM KEYBOARD.ASM\n\nWHAT'S YOUR NAME?\n\n" device vid VIDEO device key KEYBOARD var i var ax var curX var curY var vidPtr ' ************************* PROCEDURES ************** var spinWait_count procedure spinWait spinWait_count-- if spinWait_count >= 0 goto spinWait end procedure initCursor curX = 0 curY = 0 vidPtr = &vid.buf end var printTxt_txt var printTxt_len var printTxt_delay procedure printTxt if printTxt_len <= 0 goto printTxt_return if curX >= vid.cols goto printTxt_return ax = *printTxt_txt if ax = '\n' goto printTxt_newLine *vidPtr = ax curX++ vidPtr++ if curX >= vid.cols goto printTxt_newLine goto printTxt_cont printTxt_newLine: vidPtr -= curX vidPtr += vid.cols curX = 0 curY++ printTxt_cont: printTxt_txt++ printTxt_len-- vid.cursorX = curX (atomic) vid.cursorY = curY (atomic) spinWait_count = printTxt_delay call spinWait goto printTxt printTxt_return: end ' ************************ MAIN PROGGIE ************* ' turn screen on vid.cols = 25 vid.rows = 10 vid.enable = 1 ' show cursor in top-left corner vid.cursorX = 0 vid.cursorY = 0 vid.cursorEnable = 1 call initCursor ' print the start message printTxt_delay = 1000 printTxt_txt = &text printTxt_len = text.length call printTxt ' receive keyboard input if key.connected > 0 goto keyboardFound ' no keyboard array textNoKey = "ERROR: NO KEYBOARD FOUND" printTxt_txt = &textNoKey printTxt_len = textNoKey.length call printTxt nirvana keyboardFound: array text2 = ">> " printTxt_txt = &text2 printTxt_len = text2.length call printTxt ' *** name input array name[30] var namePtr var startX var maxX var k namePtr = &name startX = curX maxX = vid.cols maxX -= 2 keyLoop: key.ack = 1 (atomic) keyWait: ax = key.ack if ax > 0 goto keyWait k = key.key if k = '\n' goto enterDone if k = '\b' goto backspace if curX >= maxX goto keyLoop ' end of line reached *namePtr = k namePtr++ printTxt_txt = &k printTxt_len = 1 call printTxt goto keyLoop backspace: if curX <= startX goto keyLoop curX-- vidPtr-- *vidPtr = ' ' namePtr-- vid.cursorX = curX (atomic) vid.cursorY = curY (atomic) goto keyLoop enterDone: array thx = "\n\nNice to meet you,\n" printTxt_txt = &thx printTxt_len = thx.length call printTxt printTxt_txt = &name printTxt_len = namePtr printTxt_len -= &name call printTxt array thx2 = "." printTxt_txt = &thx2 printTxt_len = thx2.length call printTxt ' done nirvana