lib/cpu/opcodes.js
function swap (cpu, n) {
    const r = n << 4 | n >> 4;

    cpu.f = 0;
    if ((r & 0xff) == 0) cpu.f |= FLAG_Z;

    return r;
}
function swap (cpu, n) {
    const r = n << 4 | n >> 4;

    cpu.f = 0;
    if ((r & 0xff) == 0) cpu.f |= FLAG_Z;

    return r;
}
function swap ( cpu , n ) { const r = n << 4 | n >> 4 ; cpu . f = 0 ; if ( ( r & 0xff ) == 0 ) cpu . f |= FLAG_Z ; return r ; }
Miscellaneous 
SWAP n

Description:
Swap upper & lower nibles of n.

Use with:
n = A, B, C, D, E, H, L, (HL)

Flags affected:
Z - Set if result is zero.
N - Reset.
H - Reset.
C - Reset.

Opcodes:
Instruction    Parameters    Opcode    Cycles
SWAP           A             CB 37     8
SWAP           B             CB 30     8
SWAP           C             CB 31     8
SWAP           D             CB 32     8
SWAP           E             CB 33     8
SWAP           H             CB 34     8
SWAP           L             CB 35     8
SWAP           (HL)          CB 36     16
Miscellaneous SWAP n