; What the console just handed over, in hexadecimal and by name. ; ; The keys that are not characters - the arrows, Home, End and forward Delete - arrive as ; the console's own values above ASCII rather than as the escape sequences a terminal sends ; or as nothing at all, which is what a window used to make of them. This is what shows ; that, and it shows both halves of the rule in one run: ; ; A LINE FIRST, read the way everything reads one. Line mode delivers characters, so the ; keys are dropped before they reach the buffer and what comes back is what a person could ; have typed. Pressing Up while something else is collecting a line does nothing, which is ; an improvement on putting an escape and a bracket in the middle of it. ; ; THEN THE KEYS, in key mode, where a program has asked for every keystroke as it happens ; and these are keystrokes like any other. ; ; Written by Anachronaut #Include services.asm #Program #Base 0x5000 start: SETD.0 LineText CALL printString CALL newLine SETD.0 Buffer INIB 0d63 CALL readLine SETD.0 Buffer CALL showBytes SETD.0 KeyText CALL printString CALL newLine INIA 0x01 OUTA 0x02 ; Key mode. Nothing echoes, so everything below says what it saw. keyLoop: INA 0x00 INIB 0xFF XOR BRQ keyDone ; Nothing more is coming. INIB 0x71 ; q, which is how this is stopped. XOR BRQ keyDone CALL showKey BRI keyLoop keyDone: RSTA OUTA 0x02 ; Line mode, the way it was found. SETD.0 DoneText CALL printString CALL newLine RSTA SWI osExit ; DP0 names a string of bytes ending in a zero. Prints each as two hexadecimal digits, so ; that what is in the buffer can be read rather than guessed at. showBytes: LDA.0 BRA showBytesDone CALL printByteHex INIA 0x20 OUTA 0x00 INCD.0 BRI showBytes showBytesDone: CALL newLine RET ; A holds a key. Prints its value and then what it is. ; ; A survives a CALL, so the byte is still here after printing it - but only until something ; else is put in A, which the space below does. So it is kept where the naming can find it. showKey: SETD.1 KeyByte STA.1 CALL printByteHex INIA 0x20 OUTA 0x00 SETD.1 KeyByte LDA.1 ; XOR leaves the answer in Q and A alone, so one load stands for the whole ladder. INIB 0x80 XOR BRQ keyUp INIB 0x81 XOR BRQ keyDown INIB 0x82 XOR BRQ keyLeft INIB 0x83 XOR BRQ keyRight INIB 0x84 XOR BRQ keyHome INIB 0x85 XOR BRQ keyEnd INIB 0x86 XOR BRQ keyDelete ; An ordinary character, which is its own best name. OUTA 0x00 CALL newLine RET keyUp: SETD.0 UpText BRI keySay keyDown: SETD.0 DownText BRI keySay keyLeft: SETD.0 LeftText BRI keySay keyRight: SETD.0 RightText BRI keySay keyHome: SETD.0 HomeText BRI keySay keyEnd: SETD.0 EndText BRI keySay keyDelete: SETD.0 DeleteText keySay: CALL printString CALL newLine RET #Data #Base 0x3000 LineText: "a line, then keys. q stops." KeyText: "keys:" DoneText: "done" UpText: "up" DownText: "down" LeftText: "left" RightText: "right" HomeText: "home" EndText: "end" DeleteText: "delete" KeyByte: 0x00 Buffer: #Reserve 0d64 #Vectors Boot start #Include console.asm