; ;WZRD is 'slow' routine that reads WZ[13:0] ;place instruction to be tested at WZRD0 ;or use JP (IX) / JP (IY) to jump to WZRD ;after test instruction if it is elsewhere WZRD: DI WZRD0: LD A,(3456H) ;instruction under test NOP ;allow for 4-byte instruction ; ;read WZ[13] immediately after test instruction ; BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11] LD D,20H ;D = 1 << 5 = WZ[13] bit mask PUSH AF POP BC ;C[5] = WZ[13] LD A,C AND D ;A = 20H or 00H if WZ[13] = 1 or 0 LD E,A ;save WZ[13] ; ;patch JR instruction below ; RRCA ;A = 10H or 00H RRCA ;A = 08H or 00H OR D ;A = 28H or 20H = JR Z or JR NZ opcode LD (WZRD2),A ;write opcode ; ;find WZ[12:0] by using following method: ;decrement WZ using CPD until WZ[13] flips ; LD HL,0 ;initialise WZ[12:0] counter to 0 LD IX,WZRD1 ;IX = loop address WZRD1: CPD ;dec HL and WZ ; ;read WZ[13] after decrementing ; BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11] PUSH AF POP BC ;C[5] = WZ[13] LD A,C AND D ;NZ or Z if WZ[13] = 1 or 0 WZRD2: JR Z,WZRD3 ;or JR NZ,... jump if WZ[13] flipped JP (IX) ;loop to WZRD1 ; ;WZ[13] flipped so WZ[12:0] counting finished ;invert HL = !WZ[12:0] and add WZ[13] ; WZRD3: LD A,H CPL OR E LD H,A ;H = WZ[13:8] LD A,L CPL LD L,A ;HL = WZ[13:0] RET ; ; ; ;WZRDF is 'fast' routine that reads WZ[13:0] ;place instruction to be tested at WZRDF0 ;or use JP (IX) / JP (IY) to jump to WZRDF ;after test instruction if it is elsewhere ; WZRDF: DI WZRDF0: LD A,(3456H) ;instruction under test NOP ;allow for 4-byte instruction ; ;read WZ[13] immediately after test instruction ; BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11] LD D,20H ;D = 1 << 5 = WZ[13] bit mask PUSH AF POP BC ;C[5] = WZ[13] LD A,C AND D ;A = 20H or 00H if WZ[13] = 1 or 0 LD E,A ;save WZ[13] ; ;patch JR instructions below ; RRCA ;A = 10H or 00H RRCA ;A = 08H or 00H OR D ;A = 28H or 20H = JR Z or JR NZ opcode LD (WZRDF2),A ;write opcode 1 XOR 08H ;A = 20H or 28H = JR NZ or JR Z opcode LD (WZRDF5),A ;write opcode 2 ; ;find WZ[12:0] by using following method: ;decrement WZ using block of CPDs until WZ[13] flips ;block size = 25 but could be changed as desired ; LD HL,0FFFFH ;initialise WZ[12:0] counter to -1 LD IX,WZRDF1 ;IX = loop address WZRDF1: CPD ;dec HL and WZ for each CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD CPD ; ;read WZ[13] after decrementing ; BIT 0,(HL) ;F[5] = WZ[13], F[3] = WZ[11] PUSH AF POP BC ;C[5] = WZ[13] LD A,C AND D ;NZ or Z if WZ[13] = 1 or 0 WZRDF2: JR Z,WZRDF3 ;or JR NZ,... jump if WZ[13] flipped JP (IX) ;loop to WZRDF1 ; ;WZ[13] flipped during CPD block ;increment WZ until WZ[13] flips back ; WZRDF3: LD IX,WZRDF4 ;IX = loop address WZRDF4: CPI ;inc HL and WZ ; ;read WZ[13] after incrementing ; BIT 0,(HL) ;F[5] = WZ[13] {F[3] = WZ[11]} PUSH AF POP BC ;C[5] = WZ[13] LD A,C AND D ;NZ or Z if WZ[13] = 1 or 0 WZRDF5: JR NZ,WZRDF6 ;or JR Z,... jump if WZ[13] flipped JP (IX) ;loop to WZRDF4 ; ;WZ[13] flipped so WZ[12:0] counting finished ;invert HL = !WZ[12:0] and add WZ[13] ; WZRDF6: LD A,H CPL OR E LD H,A ;H = WZ[13:8] LD A,L CPL LD L,A ;HL = WZ[13:0] RET ; ; ; END