putchar:equ 08000h getchar:equ 08003h ld D,1 ld E,1 loop: call getchar ld B,A ; if C == 'T' then D = 0 ld A,B cp 'T' jr NZ,endif_T ld D,0 endif_T: ; if C == 'K' then E = 0 ld A,B cp 'K' jr NZ,endif_K ld E,0 endif_K: ; if D == 0 || E == 0 then putchar 'X' ld A,D cp 0 jr Z,if_C ld A,E cp 0 jr Z,if_C ld A,B jr endif_C if_C: ld A,'X' jr endif_C endif_C: ; output call putchar ; if D == 0 and E == 0 then exit ld A,D or E jr NZ,endif_halt halt endif_halt: ; D = (D+1)%51 inc D ld A,D cp 51 jr NZ,endif_step ld D,0 endif_step: jr loop