; $Id: emuiftst.s,v 1.3 2025/04/09 22:31:59 chris Exp $
;
; Atari800 emulator interface test program
; Christian Groessler, 2025

.list off
.include "atari.inc"
.list on

.export start

.define MAGIC_ADDR $1a1

.macro a800req
        ldx     #'A'
        stx     MAGIC_ADDR
        ldx     #'p'
        stx     MAGIC_ADDR
        ldx     #'C'
        stx     MAGIC_ADDR
.endmacro

.macro print_string text
        .local  start, cont
        jmp     cont
start:  .byte   text, ATEOL
cont:   ldx     #0              ; channel 0
        lda     #<start
        sta     ICBAL,x         ; address
        lda     #>start
        sta     ICBAH,x
        lda     #<(cont - start)
        sta     ICBLL,x         ; length
        lda     #>(cont - start)
        sta     ICBLH,x
        lda     #PUTCHR
        sta     ICCOM,x
        jsr     CIOV
.endmacro


        rts     ; for Sparta (old versions)
start:  print_string "EMUIFTST start"

        lda     MAGIC_ADDR
        pha

        ldy     #0      ; func: detect emu
        lda     #0
        a800req

        cmp     #0      ; emu present?
        beq     :+      ; no

        print_string "Emu detected!"

        ldy     #1      ; func: exit with return code in A
        lda     #65
        a800req
        ; not reached?
        jmp     :++

:       print_string "NO Emu detected!"

:       pla
        sta     MAGIC_ADDR

        print_string "EMUIFTST end"
        rts

.end
