; PLANET.ASM -- A 40-column CoCo 3 program for Disk Extended Color BASIC.
; Start at the BASIC prompt. In VCC Plus, open this file and choose Run.

POLCAT      equ     $a000       ; ROM vector: poll keyboard, ASCII key in A
CHROUT      equ     $a002       ; ROM vector: print the character in A
WIDTH       equ     $f643       ; CoCo 3 ROM: set text width to B columns
ATTR        equ     $fe08       ; Attribute BASIC uses for the next character
BG6         equ     $ffb6       ; GIME background palette slot 6
CR          equ     13          ; ASCII carriage return starts a new line

            org     $3f00
start       ldb     #40
            jsr     WIDTH       ; Use the CoCo 3 lowercase-capable text display.
            ldx     #menu
            bsr     puts

choose      jsr     [POLCAT]    ; Poll until we get ASCII '1' or '2'.
            cmpa    #'1
            beq     earth
            cmpa    #'2
            bne     choose      ; No key (or a different key)? Try again.

mars        ldb     #$25        ; Warm red background, visible on RGB and CMP.
            ldx     #redmsg
            bra     greet
earth       ldb     #$0a        ; Cool blue background.
            ldx     #bluemsg

greet       stb     BG6         ; Choose the tint for the greeting only.
            lda     #%00011110  ; White foreground (3), background slot 6.
            sta     ATTR
            bsr     puts        ; X points to the selected greeting.
            clr     ATTR        ; Back to BASIC's usual text colors.
            lda     #CR
            jsr     [CHROUT]
            rts                 ; Return to BASIC, just as puts returns to us.

; Print the zero-terminated string at X. X+ advances to the next byte.
puts        lda     ,x+
            beq     done
            pshs    x           ; Keep our place across the ROM call.
            jsr     [CHROUT]
            puls    x
            bra     puts
done        rts                 ; Return to the caller of puts.

menu        fcc     "What planet do you live on?"
            fcb     CR
            fcc     "1) Earth"
            fcb     CR
            fcc     "2) Mars"
            fcb     CR,0
bluemsg     fcc     "Hello Nice Blue Dot World!"
            fcb     0
redmsg      fcc     "Hello Cold Red Dot World!"
            fcb     0
            end     start       ; DECB execution address for Run or EXEC.
