I am working on a function for the amstrad diagnostics to get the line and bits of the keyboardmatrix that were pressed
The purpose is to identify if there is any borken track in the physical membrane.
PresseddMatrixBuffer is a 10 byte array ->8 bits * 10 lines
For the bits I have it already working.
For the lines it does not work and I do not understand my mistake, would you help me?
This is the code for lines to check the first 8 bytes(lines). For the two other ones I call this function but with hl + 8 and just ignore bits 2-7
[asm]
;; This function returns a 8bit mask with the status of 8 bytes in a buffer
;; In the mask, each bit corresponds to one byte in the array
;; A bit is set (1) if the corresponding byte had any key pressed (non-zero)
;; For example: if bit 0 is set, row 0 had at least one key pressed == 0
;; if bit 7 is set, row 7 had at least one key pressed > 0
;; IN: HL - address of the buffer
;; OUT A - mask
@GetPressedRowsMask:
push hl ; Save HL register
push bc ; Save BC register
; push de ; Save DE register
xor a ; Clear A (our result mask)
ld b, 8 ; Process 8 rows
ld c, 1 ; Initialize mask to bit 0 (00000001)
.rowLoop:
;ld d, a ; Save current result
ex af, af'
ld a, (hl) ; Get byte for current row
inc hl ; Move to next row
; Check if any bits are set in this row
or a ; Test if row has any keys pressed
jr z, .noKeysPressed ; Skip if no keys pressed
; This row has keys pressed, set the corresponding bit
;ld a, d ; Restore result
ex af, af'
or c ; Combine with current mask
.noKeysPressed:
sla c ; Shift mask left (multiply by 2)
djnz .rowLoop ; Repeat for all rows (decrements B and jumps if not zero)
; pop de ; Restore DE
pop bc ; Restore BC
pop hl ; Restore HL
ret ; Return with mask in A
I have solved it (well, a friend of mine (https://discord.com/assets/0424e06a82d250e2.svg) ) the second ex af, af' is not restored if there is a jump to .noKeysPressed
Coming soon a merge request to amstrad-diagnostics