Skip to navigation


Keyboard: UpdateKeyLogger

Name: UpdateKeyLogger [Show more] Type: Subroutine Category: Keyboard Summary: Scan the keyboard for keys in the two key tables and update the key logger Deep dive: The key logger
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * MainLoop (Part 1 of 15) calls UpdateKeyLogger * NewGame calls UpdateKeyLogger

This routine updates the value in the key logger, which is stored in (keyLoggerHi keyLoggerLo). If a key is pressed, then the corresponding 16-bit value in the key logger is set to the corresponding value from the KeyTable tables, which are stored at (keyTable1Hi keyTable1Lo) and (keyTable2Hi keyTable2Lo).
.UpdateKeyLogger LDA #5 \ Set V = 5 to act as an offset as we work our way STA V \ through the six keys in keyTable1 .klog1 LDY V \ Set Y = the offset of the key we are processing LDX keyTable1,Y \ Scan the keyboard to see if the Y-th key in keyTable1 JSR ScanKeyboard \ is being pressed BNE klog2 \ If the key is not being pressed, jump down to klog2 to \ check the Y-th key in keyTable1 LDX V \ Set X = the offset of the key we are processing LDY keyTable1Lo,X \ Fetch the key logger value for this key press into LDA keyTable1Hi,X \ (A Y) JMP klog4 \ Jump down to klog4 to store (A Y) in the key logger .klog2 LDY V \ Set Y = the offset of the key we are processing LDX keyTable2,Y \ Scan the keyboard to see if the Y-th key in keyTable2 JSR ScanKeyboard \ is being pressed BNE klog3 \ If the key is not being pressed, jump down to klog3 to \ store 0 in the key logger LDX V \ Set X = the offset of the key we are processing LDY keyTable2Lo,X \ Fetch the key logger value for this key press into LDA keyTable2Hi,X \ (A Y) JMP klog4 \ Jump down to klog4 to store (A Y) in the key logger .klog3 LDA #0 \ Set A = 0 LDX V \ Set X = the offset of the key we are processing TAY \ Set Y = 0, so the key logger value in (A Y) is 0 .klog4 STA keyLoggerHi,X \ Store the high byte of the key logger value in (A Y) \ in the X-th byte of keyLoggerHi TYA \ Store the low byte of the key logger value in (A Y) STA keyLoggerLo,X \ in the X-th byte of keyLoggerLo DEC V \ Decrement the offset to point to the next key to \ process BPL klog1 \ Loop back until we have processed all six key pairs RTS \ Return from the subroutine