
                  org   32768

start             call  3435
                  ld    a,2
                  call  #1601

                  ld    de,you_are_on.txt
                  call  printtext

                  ld    l,%11101111
                  call  porttest
                  ld    de,issue3.txt
                  jr    nz,output

                  ld    l,%11100111
                  call  porttest
                  ld    de,issue2.txt
                  jr    nz,output

                  ld    de,emulator.txt

output            call  printtext
                  ret

porttest          proc

                  di
                  ld    bc,#00fe

                  ld    h,%11111111
                  out   (c),l
                  in    a,(c)
                  and   64
                  ld    d,a

_loop             out   (c),h

                  ld    a,h
                  ld    h,l
                  ld    l,a

                  in    a,(c)
                  and   64
                  cp    d
                  jr    z,_exit

                  ld    d,a

                  djnz  _loop

_exit             ei
                  ret

                  endp

printtext         proc
_loop             ld    a,(de)
                  inc   de
                  cp    255
                  ret   z
                  rst   16
                  jr    _loop
                  endp

you_are_on.txt    db    "You are on Spectrum ", 255
issue2.txt        db    "Issue 2", 255
issue3.txt        db    "Issue 3", 255
emulator.txt      db    "Emulator", 255

                  end   start
