Syscall: 0x24a Keyboard_GetPressedKey() Objective: Determine how to wait for the keyboard when reading port data registers to avoid breaking the keyboard when overclocking. Gather some information on ghosting. Information found: * ... ======================= # Just leave it to <3f9d6>. NB: This is not a syscall. 3fc48: aec5 bra <3f9d6> 3fc4a: 0009 nop ======================= # Make some stack space for memory-mapped keyboard representation. # Disable keyboard interrupts by calling subroutine (see below). 3f9d6: 2fe6 mov.l r14, @-r15 3f9d8: 4f22 sts.l pr, @-r15 3f9da: 7ff0 add #-16, r15 3f9dc: d128 mov.l #0x8003e264, r1 3f9de: 410b jsr @r1 3f9e0: 1f43 mov.l r4, @(12, r15) # Loads 12 bytes of KEYSC data to the stack. # Second subroutine call, with parameters : stack top and {short *matrixcode}. # Checks whether the key given in the matrixcode was pressed. 3f9e2: d528 mov.l #0xa44b0000, r5 3f9e4: 6451 mov.w @r5, r4 3f9e6: 2f41 mov.w r4, @r15 3f9e8: 64f3 mov r15, r4 3f9ea: 8551 mov.w @(2, r5), r0 3f9ec: 81f1 mov.w r0, @(2, r15) 3f9ee: 8552 mov.w @(4, r5), r0 3f9f0: 81f2 mov.w r0, @(4, r15) 3f9f2: 8553 mov.w @(6, r5), r0 3f9f4: 81f3 mov.w r0, @(6, r15) 3f9f6: 8554 mov.w @(8, r5), r0 3f9f8: 81f4 mov.w r0, @(8, r15) 3f9fa: 8555 mov.w @(10, r5), r0 3f9fc: 81f5 mov.w r0, @(10, r15) 3f9fe: bd30 bsr <3f462> 3fa00: 55f3 mov.l @(12, r15), r5 # Loads IPRF address to r6, sets the keyboard interrupt priority to 13 and # performs a third subroutine call : enables keyboard interrupts (curiously # the interrupt priority is set two times). # Also saves the last subroutine result (key pressed) to r14. 3fa02: d621 mov.l <3fa88>(#0xa4080014), r6 3fa04: 9113 mov.w <3fa2e>(#0x0fff), r1 3fa06: 9213 mov.w <3fa30>(#0xd000), r2 3fa08: 6e03 mov r0, r14 3fa0a: 6761 mov.w @r6, r7 3fa0c: 2719 and r1, r7 3fa0e: 272b or r2, r7 3fa10: d212 mov.l #0x8003e26c, r2 3fa12: 420b jsr @r2 3fa14: 2671 mov.w r7, @r6 # Restores the 'key pressed' result to r0, restores saved data and returns. 3fa16: 60e3 mov r14, r0 3fa18: 7f10 add #16, r15 3fa1a: 4f26 lds.l @r15+, pr 3fa1c: 000b rts 3fa1e: 6ef6 mov.l @r15+, r14 ======================= Subroutine call at <3f9de>. - Denies keyboard interrupt in IMR5 - Disables keyboard interrupt in IPRF ======================= # Just leave it to <3e278>. 3e264: a008 bra <3e278> 3e266: 0009 nop ======================= # Writes 0x80 to IMR5. 3e278: d478 mov.l <3e45c>(#0xa4080094), r4 3e27a: e180 mov #-128, r1 3e27c: 955b mov.w <3e336>(#0x0fff), r5 3e27e: 2410 mov.b r1, @r4 # Clear the four upper bits of IPRF. 3e280: 7480 add #-128, r4 3e282: 6241 mov.w @r4, r2 3e284: 2259 and r5, r2 3e286: 000b rts 3e288: 2421 mov.w r2, @r4 ======================= Subroutine call at <3f9fe> - Detects whether a specific key is pressed using the KEYSC data. - Returns 1 if the key is pressed, 0 otherwise. ======================= Stack: r4 (bottom stack address) {short *matrixcode} ------ Bottom stack address. # Pushes {short *matrixcode} on the stack and on top, pushes r4. # Loads the key column to r2 and replaces r5 by #1 (r5 will then be shifted to # be used as a mask in a KEYSC word). 3f462: 7ff8 add #-8, r15 3f464: 1f51 mov.l r5, @(4, r15) 3f466: 6250 mov.b @r5, r2 3f468: e501 mov #1, r5 3f46a: 51f1 mov.l @(4, r15), r1 3f46c: 622c extu.b r2, r2 3f46e: 2f42 mov.l r4, @r15 # Loads the key row to r0. 3f470: 8411 mov.b @(1, r1), r0 3f472: 600c extu.b r0, r0 # Shifts it right within r6 and tests the row's lower bit. 3f474: 6603 mov r0, r6 3f476: 4621 shar r6 3f478: c801 tst #1, r0 # Shift r5 by its column number. # If the row's lower bit was 1, then also shift r5 by 8 (because there are two # rows for each word). 3f47a: 8d01 bt/s <3f480> 3f47c: 452d shld r2, r5 3f47e: 4518 shll8 r5 # Loads the bottom stack address to r1. 3f480: 61f2 mov.l @r15, r1 # Erases the even/odd bit of the row in r6 (because the KEYSC data is read in # words so we don't want to get on a byte offset, and the lower bit has # already been handled when shifting r5). 3f482: 4600 shll r6 # Loads the final mask into r2. 3f484: 625d extu.w r5, r2 3f486: 6063 mov r6, r0 # Tests whether the key represented by the parameter matrixcode is pressed. 3f488: 041d mov.w @(r0, r1), r4 3f48a: 2428 tst r2, r4 # Returns the KEYSC bit, that is 1 if the key was pressed, 0 otherwise. 3f48c: 0029 movt r0 3f48e: ca01 xor #1, r0 3f490: 000b rts 3f492: 7f08 add #8, r15 ----------------------------------- Subroutine call at <3fa12> - Sets the keyboard interrupt priority to 13. - Clears the keyboard interrupt mask. ----------------------------------- Calls redirects to 8003 e28a. 3e28a: d475 mov.l #0xa4080014, r4 3e28c: 9753 mov.w #0x0fff, r7 3e28e: 9253 mov.w #0xd000, r2 3e290: e580 mov #-128, r5 3e292: 6141 mov.w @r4, r1 3e294: 2179 and r7, r1 3e296: 212b or r2, r1 3e298: 2411 mov.w r1, @r4 3e29a: d472 mov.l <3e464>(#0xa40800d4), r4 3e29c: 000b rts 3e29e: 2450 mov.b r5, @r4