0 Members and 2 Guests are viewing this topic.
; Returns NZ if there was a match ld hl,matrix ld d,$08 outerloop: ld bc,$0801 innerloop: rlc (hl) sbc a,a xor (hl) or c ld c,a inc l djnz innerloop ld l,matrix&$ff inc a jr nz,found dec d jr nz,outerloop ret found: ld c,8 dec d foundouterloop: ld b,d foundinnerloop: rlc (hl) djnz foundinnerloop inc l dec c jr nz,foundouterloop scf ret
int colc = 0x33333333;int colcn = 0x33333333;solve: int newcolc = colc + unzipToNibbles[row]; int newcolcn = colcn + unzipToNibbles[row ^0xFF]; if ((colc | colcn) & 0x88888888) more than 4 ones or zeroes else solve(newcolc, newcolcn)
; Returns PE if there is a match ; Does 28 iterations, interrupts must be disabled ld d,matrix >> 8 ld hl,0 add hl,sp ld sp,masktableloop: pop bc ld e,b ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret poend: ld sp,hl retmasktable: .dw (matrix&$FF)*256+%00000011, loop .dw (matrix&$FF)*256+%00000101, loop .dw (matrix&$FF)*256+%00000110, loop .dw (matrix&$FF)*256+%00001001, loop .dw (matrix&$FF)*256+%00001010, loop .dw (matrix&$FF)*256+%00001100, loop .dw (matrix&$FF)*256+%00010001, loop .dw (matrix&$FF)*256+%00010010, loop .dw (matrix&$FF)*256+%00010100, loop .dw (matrix&$FF)*256+%00011000, loop .dw (matrix&$FF)*256+%00100001, loop .dw (matrix&$FF)*256+%00100010, loop .dw (matrix&$FF)*256+%00100100, loop .dw (matrix&$FF)*256+%00101000, loop .dw (matrix&$FF)*256+%00110000, loop .dw (matrix&$FF)*256+%01000001, loop .dw (matrix&$FF)*256+%01000010, loop .dw (matrix&$FF)*256+%01000100, loop .dw (matrix&$FF)*256+%01001000, loop .dw (matrix&$FF)*256+%01010000, loop .dw (matrix&$FF)*256+%01100000, loop .dw (matrix&$FF)*256+%10000001, loop .dw (matrix&$FF)*256+%10000010, loop .dw (matrix&$FF)*256+%10000100, loop .dw (matrix&$FF)*256+%10001000, loop .dw (matrix&$FF)*256+%10010000, loop .dw (matrix&$FF)*256+%10100000, loop .dw (matrix&$FF)*256+%11000000, end
; Returns NC if there is a match ; Does C(8,2) iterations ld b,$80 ld d,matrix >> 8 ld hl,innerloopouterloop: srl b jr c,end ld c,b scfinnerloop: rl c jr c,outerloop ld e,matrix & $FF push hl ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po pop hlend: ret
; Returns PE if there is a match ; Does 28 iterations, interrupts must be disabled ld d,matrix >> 8 ld l,matrix & $FF ld (saveSP),sp ld sp,masktableloop1: pop bc ld e,l ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret po inc e ld a,(de) \ and c \ ret poend: ld sp,(saveSP) ret loop2: ld e,l ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po inc e ld a,(de) \ and b \ ret po ld sp,(saveSP) ret masktable: .dw %0000001100000101, loop2, loop1 .dw %0000011000001001, loop2, loop1 .dw %0000101000001100, loop2, loop1 .dw %0001000100010010, loop2, loop1 .dw %0001010000011000, loop2, loop1 .dw %0010000100100010, loop2, loop1 .dw %0010010000101000, loop2, loop1 .dw %0011000001000001, loop2, loop1 .dw %0100001001000100, loop2, loop1 .dw %0100100001010000, loop2, loop1 .dw %0110000010000001, loop2, loop1 .dw %1000001010000100, loop2, loop1 .dw %1000100010010000, loop2, loop1 .dw %1010000011000000, loop2, end