Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
section code load 3f00
entry start
+32
View File
@@ -0,0 +1,32 @@
; Dispatch: entry, display and data. The copy routine lives in receive.asm.
CHROUT equ $a002 ; ROM's indirect character-output vector
section code
export start
import receive
start leax packet,pcr
leay received,pcr
ldb #expected-packet ; number of bytes before the checksum
jsr receive ; LWLINK supplies the other module's address
inspect cmpa expected,pcr
bne damaged
leax received,pcr
bra print
damaged leax badmsg,pcr
print lda ,x+
beq finish
bsr emit
bra print
finish lda #13
bsr emit
rts ; hand control back to BASIC
emit pshs x ; the print loop needs X after the ROM call
jsr [CHROUT]
puls x,pc
packet fcc "ORB"
expected fcb $e3
received fcb 0,0,0,0 ; the fourth byte terminates the printed string
badmsg fcc "CHECK"
fcb 0
endsection
+14
View File
@@ -0,0 +1,14 @@
; Contract: X = input, Y = output, B = positive number of bytes.
; Returns A = sum modulo 256. Both pointers advance and B reaches zero.
section code
export receive
receive clra
next adda ,x
pshs a
lda ,x+
sta ,y+
puls a
decb
bne next
rts
endsection
@@ -0,0 +1,5 @@
{
"main": "main.asm",
"modules": ["receive.asm"],
"linkScript": "layout.link"
}
@@ -0,0 +1,11 @@
; PIXEL-MASK.ASM -- follow one byte from a register into ordinary RAM.
; This scratch byte belongs to the program. You can examine it without
; changing the live display. Later you will look for a byte on a video page.
org $3f00
start leax sample,pcr ; X points to our one-byte sample.
lda #$81 ; Two end bits are set: %10000001.
shift lsra ; Shift right. Which bit goes into carry?
store sta ,x ; Set a breakpoint here, before the write.
done rts ; Return to the caller with the byte stored.
sample fcb $00 ; Assembling and running reloads this zero.
end start
+26
View File
@@ -0,0 +1,26 @@
; BANKWALK.ASM -- a reversible mapping experiment for a fresh 512 KB Disk BASIC.
; Before running, verify MMU enabled, task 0, block 2 = $3A in the debugger.
; Begin at the BASIC prompt with no unsaved program or active devices.
bank2 equ $ffa2 ; task 0, logical $4000-$5fff
window equ $4123 ; offset $0123 into block 2
org $3f00 ; code and scratch live in block 1
start pshs cc,a ; preserve incoming flags and A
orcc #$50 ; hold IRQ and FIRQ until restored
lda bank2
anda #$3f ; 512 KB supplies six bank bits
sta oldbank,pcr
lda #1
sta bank2 ; window now sees physical $02123
lda window
sta oldbyte,pcr ; keep the byte even on a fresh machine
lda #$a5
sta window
inspect lda oldbyte,pcr ; pause BEFORE this instruction
sta window ; put the borrowed byte back
lda oldbank,pcr
sta bank2 ; restore the original translation
restored puls cc,a,pc ; flags restored, return to BASIC
oldbank fcb 0
oldbyte fcb 0
end start
+6
View File
@@ -0,0 +1,6 @@
; BYTE.ASM -- Watch register A while the processor counts up one step.
org $3f00
start lda #$29 ; Load the number $29 (decimal 41) into A.
inca ; Add one. What will A hold after this step?
done rts ; Return to BASIC with the result still in A.
end start
+21
View File
@@ -0,0 +1,21 @@
; CHOICE.ASM -- Press 1 for E (Earth) or 2 for M (Mars).
POLCAT equ $a000 ; Keyboard polling vector. Returns a key in A.
CHROUT equ $a002 ; Character-output vector.
CR equ 13
org $3f00
start lda #'? ; Show that the program is waiting for a key.
jsr [CHROUT]
choose jsr [POLCAT] ; Check the keyboard without waiting for Enter.
cmpa #'1
beq earth ; A matching comparison sets the Z flag.
cmpa #'2
bne choose ; No key or an unexpected key: try again.
mars lda #'M
bra printit ; Skip the Earth path.
earth lda #'E
printit jsr [CHROUT] ; Both paths meet here with one letter in A.
lda #CR
jsr [CHROUT]
rts
end start
+44
View File
@@ -0,0 +1,44 @@
; DISPATCH.ASM -- receive a three-byte station code and check its sum.
; Disk BASIC, MC6809 or HD6309. Run a personal copy from the assembly editor.
CHROUT equ $a002 ; indirect ROM character-output vector
org $3f00
start leax packet,pcr ; X walks the incoming bytes
leay received,pcr ; Y walks a separate writable buffer
ldb #size
bsr receive
inspect cmpa expected,pcr ; stop here to inspect A and the copy
bne damaged
leax received,pcr
bra print
damaged leax badmsg,pcr
print lda ,x+
beq finish ; both text paths end with a zero byte
bsr emit
bra print
finish lda #13 ; put the BASIC prompt on its own line
bsr emit
rts
; Input: X source, Y destination, B positive byte count.
; Output: A = sum modulo 256. X and Y advance; B ends at zero.
receive clra
next adda ,x ; add this byte, leave X at it for the copy
pshs a ; keep the running sum while moving the byte
lda ,x+
sta ,y+
puls a
decb
bne next
rts
emit pshs x ; caller still needs its position after ROM I/O
jsr [CHROUT]
puls x,pc
packet fcc "ORB"
size equ *-packet
expected fcb $e3 ; $4F + $52 + $42 = $E3
received fcb 0,0,0,0 ; fourth byte stays zero for printing
badmsg fcc "CHECK"
fcb 0
end start
+22
View File
@@ -0,0 +1,22 @@
; DISPATCH6309.ASM -- copy a station code with the HD6309 block move.
; Choose the HD6309 guest and assembly target. Start in Disk BASIC.
CHROUT equ $a002
org $3f00
start leax packet,pcr
leay received,pcr
ldw #size ; W counts the bytes left to transfer
copy tfm x+,y+ ; move from X to Y and increment both
inspect leax received,pcr ; stop here to inspect W, X, Y and RAM
next lda ,x+
beq finish
pshs x
jsr [CHROUT]
puls x
bra next
finish lda #13
jsr [CHROUT]
rts ; no change to the guest's processor mode
packet fcc "ORB"
size equ *-packet
received fcb 0,0,0,0
end start
+11
View File
@@ -0,0 +1,11 @@
; LETTER.ASM -- Give one byte to BASIC's character output routine.
CHROUT equ $a002 ; Address of the ROM character-output vector.
CR equ 13 ; Carriage return starts a fresh line.
org $3f00
start lda #'A ; Load this character's ASCII code into A.
jsr [CHROUT] ; Call the routine whose address is at CHROUT.
lda #CR
jsr [CHROUT] ; Leave the next BASIC prompt on its own line.
rts ; Return to the caller in BASIC.
end start
+11
View File
@@ -0,0 +1,11 @@
; MODE.ASM -- a bounded HD6309 experiment for Disk BASIC at reset mode.
; Run on a fresh HD6309 guest, with MD=0. Both stops are before instructions.
org $3f00
start pshs cc ; remember BASIC's interrupt masks
orcc #$50 ; mask IRQ and FIRQ for the short experiment
ldmd #1 ; select 6309 native mode
native ldw #$1234 ; inspect MD, then step and read E and F
ldmd #0 ; restore reset mode before calling BASIC
restored puls cc ; restore the caller's condition codes
rts
end start
+15
View File
@@ -0,0 +1,15 @@
; RETURN.ASM -- A subroutine advances one letter, then returns to its caller.
CHROUT equ $a002 ; Address of the ROM character-output vector.
CR equ 13
org $3f00
start lda #'A ; Begin with the letter A ($41).
call jsr nextletter ; Save the address of 'display' on the S stack.
display jsr [CHROUT] ; The subroutine has left the new letter in A.
lda #CR
jsr [CHROUT]
rts ; Finish the main program and return to BASIC.
nextletter inca ; ASCII B follows ASCII A.
back rts ; Retrieve the saved address and resume at display.
end start
+31
View File
@@ -0,0 +1,31 @@
; SOFTIRQ.ASM -- install, call and remove a BASIC RAM SWI trampoline.
; Fresh CoCo 3 Disk BASIC, MC6809 or HD6309 in emulation mode only.
; From a debugger stop, Continue through cleanup before returning to BASIC.
hook equ $0106 ; three-byte RAM stub reached via $FFFA
org $3f00
start pshs cc,d,x ; preserve the caller's flags, D and X
orcc #$50 ; keep IRQ & FIRQ out during this experiment
lda hook
ldx hook+1
sta oldop,pcr
stx oldaddr,pcr
lda #$7e ; extended JMP opcode
leax handler,pcr
stx hook+1
sta hook ; JMP handler now complete
clr visits,pcr
lda #$4f ; known bytes to locate in the stack frame
ldb #$52
trigger swi ; CPU stacks state and follows the SWI vector
returned lda oldop,pcr ; breakpoint to compare S after RTI
sta hook
ldx oldaddr,pcr
stx hook+1
restored puls cc,d,x,pc ; restore flags, D and X, return to BASIC
handler inc visits,pcr ; memory survives the return
rti ; reload the stacked context, including PC
oldop fcb 0
oldaddr fdb 0
visits fcb 0
end start
+57
View File
@@ -0,0 +1,57 @@
; 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.
+5
View File
@@ -0,0 +1,5 @@
10 WIDTH 40
20 PRINT "WELCOME BACK TO PORT ZERO."
30 INPUT "CALL SIGN";N$
40 PRINT "GOOD TO HAVE YOU ABOARD, ";N$;"!"
50 END
@@ -0,0 +1,7 @@
10 PMODE 4,1:PCLS 0:SCREEN 1,1
20 FOR X=24 TO 118 STEP 2
30 LINE (X,48)-(X,144),PSET
40 LINE (X+113,48)-(X+113,144),PSET
50 NEXT X
60 IF INKEY$="" THEN 60
70 SCREEN 0,0:END
@@ -0,0 +1,15 @@
10 WIDTH 32:PCLEAR 4:CLS
20 PMODE 1,1:PCLS 0:SCREEN 1,0
30 COLOR 1,0:LINE(32,80)-(96,112),PSET,B
40 LINE(32,80)-(64,48),PSET:LINE(64,48)-(96,80),PSET
50 PMODE 1,3:PCLS 0:COLOR 3,0
60 LINE(144,48)-(184,80),PSET,B
70 PSET(162,64,3)
80 A$=INKEY$:IF A$="" THEN 80
90 SCREEN 1,0
100 A$=INKEY$:IF A$="" THEN 100
110 PMODE 1,1:SCREEN 1,0
120 A$=INKEY$:IF A$="" THEN 120
130 SCREEN 0,0:WIDTH 40:CLS
140 PRINT "BEACON CHECK COMPLETE"
150 END
@@ -0,0 +1,2 @@
10 PRINT "THIS IS MOON BASE."
20 PRINT "CAN YOU HEAR ME?"
@@ -0,0 +1,17 @@
10 CLS
20 S=0
30 PRINT "MOON BASE CREW QUIZ"
40 PRINT "WHICH PART SHOWS A MESSAGE?"
50 PRINT "1 SCREEN 2 KEYBOARD"
60 INPUT A
70 IF A=1 THEN S=S+1
80 PRINT "WHICH KEEPS A SAVED PROGRAM?"
90 PRINT "1 RAM 2 DISK"
100 INPUT A
110 IF A=2 THEN S=S+1
120 PRINT "WHAT DOES PRINT 2+3 SHOW?"
130 PRINT "1 FIVE 2 THE TEXT 2+3"
140 INPUT A
150 IF A=1 THEN S=S+1
160 PRINT "YOUR SCORE";S;"OUT OF 3"
170 END
@@ -0,0 +1,5 @@
10 CLS
20 FOR I=1 TO 3
30 PRINT "BLINK";I
40 NEXT I
50 PRINT "SIGNAL SENT!"
@@ -0,0 +1,6 @@
10 WIDTH 40:CLS
20 A=42
30 PRINT "VALUE";A
40 PRINT "ADDRESS ";HEX$(VARPTR(A))
50 PRINT "FIRST BYTE";PEEK(VARPTR(A))
60 END
+18
View File
@@ -0,0 +1,18 @@
10 WIDTH 40:CLS
20 DIM P$(2),X(2),Y(2)
30 FOR I=1 TO 2:READ P$(I),X(I),Y(I):NEXT I
40 HSCREEN 2:HCLS 0
42 PALETTE 0,0:PALETTE 1,9:PALETTE 2,36:PALETTE 3,63
45 HCOLOR 3:HPRINT(1,1),"STAR CHART - PRESS A KEY TO LAND"
50 FOR I=1 TO 2
60 HCIRCLE(X(I),Y(I)),12,I
70 HSET(X(I),Y(I),I)
75 HPRINT(INT(X(I)/8)-2,INT(Y(I)/8)+2),P$(I)
80 NEXT I
90 A=HPOINT(X(1),Y(1)):B=HPOINT(X(2),Y(2))
100 IF INKEY$="" THEN 100
110 HSCREEN 0:PALETTE RGB:WIDTH 40:CLS
120 PRINT P$(1);" MARKER";A
130 PRINT P$(2);" MARKER";B
140 END
150 DATA EARTH,64,80,MARS,176,100
@@ -0,0 +1,13 @@
10 WIDTH 32:CLS:PRINT "32 COLUMNS - PRESS A KEY"
20 IF INKEY$="" THEN 20
30 WIDTH 40:CLS:ATTR 3,0
40 LOCATE 0,1:PRINT "40 COLUMNS - PRESS A KEY";
50 LOCATE 38,2:PRINT "*";
60 IF INKEY$="" THEN 60
70 WIDTH 80:CLS
80 LOCATE 0,1:PRINT "80 COLUMNS";
90 LOCATE 48,1:PRINT "SUPPLIES LEFT";
100 LOCATE 0,2:PRINT "PRESS A KEY";
110 LOCATE 48,2:PRINT USING "##";6
120 IF INKEY$="" THEN 120
130 ATTR 0,1:WIDTH 40:CLS:PRINT "BACK AT THE HELM"
+10
View File
@@ -0,0 +1,10 @@
10 WIDTH 40:CLS
20 PRINT "PLANET EXPLORER"
30 PRINT "1 EARTH 2 MARS"
40 INPUT "SET COURSE";C$
50 IF C$="1" THEN P$="EARTH":GOTO 90
60 IF C$="2" THEN P$="MARS":GOTO 90
70 PRINT "TRY 1 OR 2"
80 GOTO 40
90 PRINT "BOUND FOR ";P$
100 END
+8
View File
@@ -0,0 +1,8 @@
10 WIDTH 40:CLS
20 S=6
30 FOR T=1 TO 3
40 S=S-1
50 S=S-1
60 PRINT "TURN";T;" SUPPLIES";S
70 NEXT T
80 END
@@ -0,0 +1,8 @@
10 WIDTH 40:CLS
20 OPEN "D",#1,"LOCKERS.DAT:0",8
30 FIELD #1,8 AS N$
40 LSET N$="EARTH":PUT #1,1
50 LSET N$="MARS":PUT #1,2
60 GET #1,2:PRINT "LOCKER TWO: ";N$
70 GET #1,1:PRINT "LOCKER ONE: ";N$
80 CLOSE #1
@@ -0,0 +1,9 @@
10 WIDTH 80:CLS
20 OPEN "I",#1,"VOYAGE.DAT:0"
30 INPUT #1,P$,S
40 CLOSE #1
50 LOCATE 0,1:PRINT "FLIGHT LOG";
60 LOCATE 48,1:PRINT "SUPPLIES LEFT";
70 LOCATE 0,2:PRINT P$;
80 LOCATE 48,2:PRINT S
90 END
+10
View File
@@ -0,0 +1,10 @@
10 WIDTH 40:CLS
20 PRINT 2+3*4
30 PRINT (2+3)*4
40 PRINT 2^3
50 PRINT 6/2-1
60 PRINT 4>3;4=3;4<>3
70 PRINT "RED"+" DUST"
80 PRINT (4>3) AND (2=2)
90 PRINT NOT (4>3)
100 END
+13
View File
@@ -0,0 +1,13 @@
5 WIDTH 32:CLS
10 PMODE 1,1:PCLS 0:SCREEN 1,0
20 COLOR 1,0:LINE(16,16)-(95,95),PSET,BF
30 PMODE 1,3:PCLS 0:COLOR 3,0
40 LINE(160,64)-(223,127),PSET,BF
50 IF INKEY$="" THEN 50
60 SCREEN 1,0
70 IF INKEY$="" THEN 70
80 PMODE 1,1:SCREEN 1,0
90 IF INKEY$="" THEN 90
100 SCREEN 0,0:WIDTH 40:CLS
110 PRINT "BOTH PAGES ARE HOME"
120 END
+8
View File
@@ -0,0 +1,8 @@
10 WIDTH 40:CLS
20 PRINT "RIGHT STICK SCANNER"
30 PRINT "MOVE THE STICK. PRESS A KEY TO SCAN."
40 IF INKEY$="" THEN 40
50 X=JOYSTK(0)
60 IF X<24 THEN PRINT "WEST SIGNAL":END
70 IF X>39 THEN PRINT "EAST SIGNAL":END
80 PRINT "CENTER SIGNAL"
@@ -0,0 +1,7 @@
10 WIDTH 40:CLS
20 S=6
30 FOR T=1 TO 3
40 S=S-1
60 PRINT "TURN";T;" SUPPLIES";S
70 NEXT T
80 END
+33
View File
@@ -0,0 +1,33 @@
5 DIM P$(2),X(2),Y(2)
6 FOR I=1 TO 2:READ P$(I),X(I),Y(I):NEXT I
10 WIDTH 40:CLS
20 PRINT "FLIGHT DECK"
30 PRINT "1 EARTH 2 MARS"
40 INPUT "SET COURSE";C$
50 IF C$="1" THEN D=1:GOTO 90
60 IF C$="2" THEN D=2:GOTO 90
70 PRINT "TRY 1 OR 2"
80 GOTO 40
90 S=6
100 FOR T=1 TO D+1
110 S=S-1
120 PRINT "TURN";T;" SUPPLIES";S
130 NEXT T
135 GOSUB 300
140 PLAY "T180O3L8CEG"
150 GOSUB 200
160 PRINT "LOG SAVED FOR ";P$(D)
170 END
200 OPEN "O",#1,"VOYAGE.DAT:0"
210 WRITE #1,P$(D),S
220 CLOSE #1
230 RETURN
300 HSCREEN 2:HCLS 0:HCOLOR 3
305 PALETTE 0,0:PALETTE 1,9:PALETTE 2,36:PALETTE 3,63
310 HPRINT(1,1),"LANDING AT "+P$(D)
320 HCIRCLE(X(D),Y(D)),12,D
330 HSET(X(D),Y(D),D)
340 HPRINT(1,20),"PRESS A KEY TO LAND"
350 IF INKEY$="" THEN 350
360 HSCREEN 0:PALETTE RGB:WIDTH 40:CLS:RETURN
400 DATA EARTH,64,80,MARS,176,100
+14
View File
@@ -0,0 +1,14 @@
10 REM EARTH OR MARS - COCO 3
20 WIDTH 40:CLS
30 PRINT "What planet do you live on?"
40 PRINT "1) Earth"
50 PRINT "2) Mars"
60 K$=INKEY$
70 IF K$="1" THEN 110
80 IF K$<>"2" THEN 60
90 PALETTE 6,37:M$="Hello Cold Red Dot World!"
100 GOTO 120
110 PALETTE 6,10:M$="Hello Nice Blue Dot World!"
120 ATTR 3,6
130 PRINT M$
140 ATTR 0,0:END
@@ -0,0 +1 @@
10 PRINT "CARGO ORIGINAL"
@@ -0,0 +1,12 @@
10 REM A GREETING FOR THE SPEECH/SOUND CARTRIDGE
20 A=&HFF7E
30 M$="HELLO FROM YOUR COLOR COMPUTER. "+CHR$(13)
40 PRINT "SENDING GREETING"
50 FOR I=1 TO LEN(M$)
60 T=0
70 IF PEEK(A)>=128 THEN 100
80 T=T+1:IF T<500 THEN 70
90 PRINT "CHECK SPEECH CARTRIDGE":END
100 POKE A,ASC(MID$(M$,I,1))
110 NEXT I
120 PRINT "GREETING SENT"
+4
View File
@@ -0,0 +1,4 @@
10 CLS
20 INPUT "FLIGHT NUMBER";N
30 PRINT "FLIGHT";N
40 END
+17
View File
@@ -0,0 +1,17 @@
10 WIDTH 32:CLS
20 PRINT "BEACON LANDING"
30 PRINT "FIND THE PAD WITH THE BEACON."
40 PRINT "PRESS L OR R TO LAND."
50 PRINT "PRESS SPACE TO SEE THE PADS."
60 IF INKEY$<>" " THEN 60
70 PMODE 4,1:PCLS 0:SCREEN 1,1
80 FOR X=26 TO 96 STEP 2
90 LINE (X,86)-(X,140),PSET
100 LINE (X+131,86)-(X+131,140),PSET
110 NEXT X
120 LINE (192,38)-(192,66),PSET
130 LINE (178,52)-(206,52),PSET
140 K$=INKEY$:IF K$<>"L" AND K$<>"R" THEN 140
150 SCREEN 0,0:CLS
160 IF K$="R" THEN PRINT "BEACON FOUND!":END
170 PRINT "DARK PAD. TRY THE OTHER ONE!":END
+7
View File
@@ -0,0 +1,7 @@
obj/
generated/
HELLO.bin
HELLO.dsk
HELLO.map
HELLO.link
.vccplus-build/
+74
View File
@@ -0,0 +1,74 @@
# Generated by VCC Plus — edit Project Settings to regenerate.
# Ordinary GNU Make; no VCC Plus project parser is required to build it.
CMOC ?= cmoc
PERL ?= perl
WRITECOCOFILE ?= writecocofile
INSTALL_LOADER ?= install-coco-boot-loader
VCC_CONFIGURATION ?= Debug
ifeq ($(VCC_CONFIGURATION),Release)
OPTIM ?= -O2
else
OPTIM ?= -O0
DEBUG_FRAME ?= -fno-omit-frame-pointer
endif
define VCC_DEFINES
endef
define VCC_COMPILER_OPTIONS
endef
define VCC_LINKER_OPTIONS
endef
CPPFLAGS += -Iinclude $(VCC_DEFINES)
CFLAGS += --coco --intermediate --deps --stack-space=2048 $(OPTIM) $(DEBUG_FRAME) $(VCC_COMPILER_OPTIONS)
LDFLAGS += --coco --intermediate --org=2800 $(VCC_LINKER_OPTIONS)
LDLIBS += -ldecbfile
OBJECTS := obj/main.o obj/src/display.o obj/src/disk.o obj/generated/word-count.o
.PHONY: all build clean disk libraries
all: build
build: HELLO.bin
HELLO.bin: $(OBJECTS) Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
obj/main.o: main.c Makefile generated/word-count.c generated/WORDS.DAT
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
obj/src/display.o: src/display.c Makefile generated/word-count.c generated/WORDS.DAT
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
obj/src/disk.o: src/disk.c Makefile generated/word-count.c generated/WORDS.DAT
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
obj/generated/word-count.o: generated/word-count.c Makefile generated/word-count.c generated/WORDS.DAT
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
generated/word-count.c generated/WORDS.DAT &: tools/build-data.pl assets/words.txt Makefile
@mkdir -p generated
$(PERL) tools/build-data.pl assets/words.txt generated/word-count.c generated/WORDS.DAT
test -f generated/word-count.c
test -f generated/WORDS.DAT
# DOS helper: Pierre Sarrazin, autostart.c 0.1.2, public domain.
obj/vcc-dos-boot/loader.bin: Makefile
@mkdir -p $(dir $@)
@printf '%s\n' '// autostart.c - Program to be run by the Disk Basic DOS command.' '// By Pierre Sarrazin <http://sarrazip.com/>' '// This file is in the public domain.' '//' '// Reference: Roger Schrag, "A Special Use For The DOS Command",' '// The Rainbow, November 1984, p.140.' '//' '// To compile: cmoc --dos autostart.c' '// To install on CoCo disk image: install-coco-boot-loader some-image.dsk autostart.bin' '// To run on CoCo: type DOS and <Enter> to automatically run *.BAS.' '//' '// Version history:' '// 0.1.0 2016-01-16 Use of legacy.h discontinued.' '// 0.1.1 2018-04-03 Adapted to CMOC 0.1.51 (const).' '// 0.1.2 2018-08-04 Basic line now forced to be uppercase.' '' '#include <coco.h>' '' '#define ENDFLG 0x00 // STOP/END FLAG: POSITIVE=STOP, NEG=END' '#define CINBFL 0x70 // CONSOLE IN BUFFER FLAG: 00=NOT EMPTY, $$FF=EMPTY' '#define RVEC4 0x016a // RAM hook: CONSOLE IN' '' '' 'byte oldHookInstr;' 'word oldHookAddr;' 'const char *basicLineReader;' '' '' 'void feedKeyboard()' '{' ' word preservedX;' ' asm("stx", preservedX);' '' ' * (byte *) CINBFL = 0; // console in buffer now not empty' '' ' char nextBasicByte = (char) toupper(*basicLineReader);' ' ++basicLineReader;' ' if (nextBasicByte == 0) // if finished returning Basic line' ' {' ' * (byte *) RVEC4 = oldHookInstr;' ' * (word *) (RVEC4 + 1) = oldHookAddr;' ' nextBasicByte = '"'"'\r'"'"'; // return "Enter" to cause execution of Basic line' ' }' '' ' asm {' ' lda nextBasicByte' ' ldx preservedX' ' tfr u,s // discard stack frame' ' leas 4,s // discard previous stack frame ptr and return addr' ' rts // return to caller of CONSOLE IN' ' }' '}' '' '' 'int main()' '{' ' * (byte *) ENDFLG = - * (byte *) ENDFLG; // why?' '' ' basicLineReader =' ' #ifndef COMMAND' ' "RUN\"*.BAS\""' ' #else' ' COMMAND' ' #endif' ' ;' '' ' // Install function feedKeyboard() as CONSOLE IN routine.' ' //' ' oldHookInstr = * (byte *) RVEC4;' ' oldHookAddr = * (word *) (RVEC4 + 1);' '' ' * (byte *) RVEC4 = 0x7e; // JMP instruction' ' * (void **) (RVEC4 + 1) = (void *) feedKeyboard;' '' ' * (word *) 0x2600 = 0; // overwrite "OS" marker with two null bytes' '' ' asm("jmp", "$$ac7c"); // go interpret a Basic line (which is read from console)' '' ' return 0; // avoids compiler error' '}' > obj/vcc-dos-boot/loader.c
"$(CMOC)" --dos -O0 --limit=2800 -o $@ '-DCOMMAND="LOADM\"HELLO.BIN\":EXEC"' obj/vcc-dos-boot/loader.c
disk: HELLO.dsk
HELLO.dsk: HELLO.bin generated/WORDS.DAT obj/vcc-dos-boot/loader.bin Makefile
@mkdir -p $(dir $@)
$(PERL) -e 'print chr(255) x (35*18*256)' > $@
$(INSTALL_LOADER) $@ obj/vcc-dos-boot/loader.bin
$(WRITECOCOFILE) $@ HELLO.bin
$(WRITECOCOFILE) $@ generated/WORDS.DAT
clean:
rm -rf obj
rm -f HELLO.bin HELLO.map HELLO.link HELLO.dsk generated/word-count.c generated/WORDS.DAT
-include $(OBJECTS:.o=.d)
+45
View File
@@ -0,0 +1,45 @@
# Hello Disk — CMOC project example
An authored VCC Plus example under GPL-3.0-or-later, using the public-domain,
ROM-backed decbfile library included in the development runtime. No game source,
ROM, third-party standalone disk driver, generated executable, or disk image is
included in this example.
1. In VCC Plus choose **Develop → C Development → New** and select **Hello Disk — multi-file disk example** (the default). Choose a new writable folder.
2. Alternatively, copy this repository folder and **Open** it. Both approaches create your own editable source; the installed template stays unchanged.
3. **Project Settings** shows the source files, include directory, disk library,
generated resource recipe and disk launch command. Its Makefile is generated
using the same settings available in that window.
4. Boot the **Disk BASIC** machine profile. **Build** creates `HELLO.bin` and a
`HELLO.dsk` containing the executable and `WORDS.DAT`, entirely in the isolated
build workspace. It does not alter your source folder or mounted disks.
5. Use the disk launch control to mount the development disk in FD0 and run the
configured `DOS` command. You can also type `LOADM"HELLO":EXEC` at BASIC.
Confirm the media replacement when
prompted; retain any existing unsaved disk changes first.
6. The program reads its words from the emulated floppy through the Disk BASIC
ROM, prints them, then reports disk result `0` and generated word count `5`.
`main.c` calls functions in `src/display.c` and `src/disk.c`. Their shared header
is `include/hello.h`. A short Perl build recipe turns `assets/words.txt` into a C
translation unit and disk data together. Change the word list, build again and
observe the regenerated outputs. Add a breakpoint on an executable C line to
inspect the program using the existing debugger. Generated C can be inspected
from the frozen build snapshot; the editable input is the word list and recipe.
**Project Settings → Disk & Run → DOS boot** defaults to **Run this program**
for new Hello Disk copies. The build creates a small public-domain loader from
Pierre Sarrazin’s `autostart.c` under `obj/vcc-dos-boot` and reserves track 34
before adding files. It does not add a C source file to your editable project.
Choose **None** to build a disk without DOS boot. Existing project copies are
not changed automatically. Building or mounting alone does not run the program.
For command-line builds, put VCC Plus's `Contents/Resources/Toolchain/bin` on
`PATH` and run its bundled `make disk`. `make VCC_CONFIGURATION=Release disk`
uses the optimized configuration. Source changes are tracked through CMOC `.d`
header dependencies. `make clean` removes generated objects, data and disks.
Unlike the native app's isolated build, command-line Make writes these outputs
in this folder.
This example needs a functioning CoCo/Disk BASIC ROM configuration and keeps
those ROM services mapped. It is not a standalone-ROM-free disk implementation.
+5
View File
@@ -0,0 +1,5 @@
HELLO
WORLD
CMOC
VCC
PLUS
+8
View File
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef HELLO_DISK_H
#define HELLO_DISK_H
#include <cmoc.h>
extern const unsigned char generatedWordCount;
void showHeading(void);
unsigned char showDiskWords(void);
#endif
+16
View File
@@ -0,0 +1,16 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <cmoc.h>
#include <coco.h>
#include "hello.h"
int main(void)
{
unsigned char status;
initCoCoSupport();
setHighSpeed(FALSE);
showHeading();
status = showDiskWords();
printf("DISK RESULT: %u\n", status);
printf("GENERATED WORD COUNT: %u\n", generatedWordCount);
return status;
}
+28
View File
@@ -0,0 +1,28 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <cmoc.h>
#include <decbfile.h>
#include "hello.h"
static DECBDrive drives[1];
static DECBFile file;
static byte words[256];
byte showDiskWords(void)
{
byte status = decb_init(drives, 1);
if (status != DECB_OK)
return status;
status = decb_registerDrive(0);
if (status == DECB_OK)
status = decb_openSectorFile(&file, 0, "WORDS.DAT");
if (status == DECB_OK)
{
status = decb_readSector(&file, words, 0);
words[255] = 0;
if (status == DECB_OK)
printf("%s\n", words);
decb_closeSectorFile(&file);
}
decb_shutdown();
return status;
}
+8
View File
@@ -0,0 +1,8 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <cmoc.h>
#include "hello.h"
void showHeading(void)
{
printf("HELLO FROM A MULTI-FILE PROJECT\n");
printf("WORDS READ FROM THE FLOPPY:\n");
}
@@ -0,0 +1,24 @@
#!/usr/bin/env perl
# SPDX-License-Identifier: GPL-3.0-or-later
use strict;
use warnings;
@ARGV == 3 or die "Usage: build-data.pl words.txt generated.c WORDS.DAT\n";
my ($input, $source, $disk_data) = @ARGV;
open my $in, '<', $input or die "$input: $!\n";
my @words;
while (<$in>) {
s/\r?\n\z//;
next if $_ eq '';
/\A[A-Z]+\z/ or die "Words must contain uppercase A-Z only\n";
push @words, $_;
}
close $in;
@words <= 255 or die "Too many words\n";
my $bytes = join("\r", @words) . "\r\0";
length($bytes) <= 256 or die "Example data must fit one disk sector\n";
open my $c, '>', $source or die "$source: $!\n";
print {$c} "/* Generated from assets/words.txt. */\n#include <cmoc.h>\nconst unsigned char generatedWordCount = " . scalar(@words) . ";\n";
close $c or die "$source: $!\n";
open my $data, '>:raw', $disk_data or die "$disk_data: $!\n";
print {$data} $bytes . ("\0" x (256 - length($bytes)));
close $data or die "$disk_data: $!\n";
@@ -0,0 +1,79 @@
{
"binary" : "HELLO.bin",
"buildTarget" : "disk",
"cleanTarget" : "clean",
"configurations" : [
{
"makeArguments" : [
],
"name" : "Debug"
},
{
"makeArguments" : [
"VCC_CONFIGURATION=Release"
],
"name" : "Release"
}
],
"diskImage" : "HELLO.dsk",
"diskTarget" : "disk",
"entrySource" : "main.c",
"jobs" : 4,
"launchCommands" : [
"DOS"
],
"launchMode" : "disk",
"makefile" : "Makefile",
"makefileSettings" : {
"compilerOptions" : [
],
"defines" : [
],
"diskBootMode" : "program",
"diskFiles" : [
"generated/WORDS.DAT"
],
"diskImage" : "HELLO.dsk",
"executable" : "HELLO.bin",
"generatedResources" : [
{
"command" : "$(PERL) tools/build-data.pl assets/words.txt generated/word-count.c generated/WORDS.DAT",
"inputs" : [
"tools/build-data.pl",
"assets/words.txt"
],
"outputs" : [
"generated/word-count.c",
"generated/WORDS.DAT"
]
}
],
"includePaths" : [
"include"
],
"libraries" : [
"decbfile"
],
"libraryPaths" : [
],
"libraryProjects" : [
],
"linkerOptions" : [
],
"origin" : "2800",
"releaseOptimization" : "-O2",
"sources" : [
"main.c",
"src/display.c",
"src/disk.c",
"generated/word-count.c"
],
"stackSpace" : 2048
}
}
+57
View File
@@ -0,0 +1,57 @@
# Generated by VCC Plus — edit Project Settings to regenerate.
# Ordinary GNU Make; no VCC Plus project parser is required to build it.
CMOC ?= cmoc
PERL ?= perl
WRITECOCOFILE ?= writecocofile
INSTALL_LOADER ?= install-coco-boot-loader
VCC_CONFIGURATION ?= Debug
ifeq ($(VCC_CONFIGURATION),Release)
OPTIM ?= -O2
else
OPTIM ?= -O0
DEBUG_FRAME ?= -fno-omit-frame-pointer
endif
define VCC_DEFINES
endef
define VCC_COMPILER_OPTIONS
endef
define VCC_LINKER_OPTIONS
endef
export VCC_CMOC_COMPAT = 1
CPPFLAGS += $(VCC_DEFINES)
CFLAGS += --coco --intermediate --deps --stack-space=2048 $(OPTIM) $(DEBUG_FRAME) $(VCC_COMPILER_OPTIONS)
LDFLAGS += --coco --intermediate --org=2000 --limit=7800 $(VCC_LINKER_OPTIONS)
LDLIBS += -lbank -lgime -linput -lbcontrol -lssc -lorch90 -lhirestxt -lvcccompat -ldecbfile
OBJECTS := obj/main.o obj/flight.o obj/report.o
.PHONY: all build clean disk libraries
all: build
build: RECORDER.bin
RECORDER.bin: $(OBJECTS) Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
obj/main.o: main.c Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
obj/flight.o: flight.c Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
obj/report.o: report.c Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
disk: RECORDER.dsk
RECORDER.dsk: RECORDER.bin Makefile
@mkdir -p $(dir $@)
$(PERL) -e 'print chr(255) x (35*18*256)' > $@
$(WRITECOCOFILE) $@ RECORDER.bin
clean:
rm -rf obj
rm -f RECORDER.bin RECORDER.map RECORDER.link RECORDER.dsk
-include $(OBJECTS:.o=.d)
+182
View File
@@ -0,0 +1,182 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <coco.h>
#include <font5x8.h>
#include <vcc/bank.h>
#include <vcc/gime.h>
#include <vcc/input.h>
#include <vcc/orch90.h>
#include <vcc/ssc.h>
#include "mission.h"
enum { SKY, WHITE, ICE, GOLD, BASALT, RIDGE, TEAL };
#define NO_MARK 255
/* The steady beacon plays from resident, read-only data during the flight. */
static const struct orch90_frame beacon[] = {
{128,128}, {142,128}, {148,128}, {142,128}, {128,128}, {114,128}, {108,128}, {114,128},
{128,128}, {142,128}, {148,128}, {142,128}, {128,128}, {128,128}, {128,128}, {128,128},
{128,128}, {128,128}, {128,142}, {128,142}, {128,148}, {128,148}, {128,142}, {128,142},
{128,128}, {128,128}, {128,114}, {128,114}, {128,128}, {128,128}, {128,128}, {128,128}
};
static byte previousShip[2], previousMark[2], hidden;
static void label(unsigned x, byte y, const char *text, byte color)
{
while (*text) {
const byte *glyph = font5x8 + ((unsigned)*text++ - ' ') * 8;
byte row, col;
for (row = 0; row < 8; ++row)
for (col = 0; col < 5; ++col)
if (!(glyph[row] & (0x80 >> col)))
gime_plot(x + col, y + row, color);
x += 6;
}
}
/* Paint the permanent landscape once on each page before switching on sound. */
static void landscape(void)
{
unsigned i;
gime_clear(SKY);
label(8, 7, "MISSION RECORDER", ICE);
label(240, 7, "SURVEY / 01", WHITE);
gime_fill_rect(8, 20, 304, 1, TEAL);
for (i = 0; i < 16; ++i) {
unsigned x = i * 20, y = 106 + ((i * 7) % 19);
gime_plot(x + 4, 28 + ((i * 11) % 17), WHITE);
gime_fill_rect(x, y, 20, 141 - y, BASALT);
gime_fill_rect(x, y, 20, 2, RIDGE);
gime_fill_rect(x + 9, 139, 2, 4, ICE);
}
label(8, 149, "SECTOR 07 MARK --", WHITE);
label(8, 164, "A/D OR RIGHT STICK: STEER SPACE/FIRE: MARK", WHITE);
label(8, 178, "S: SAVE AND PRINT Q: DISCARD", ICE);
}
static void digits(unsigned x, byte value)
{
char pair[3];
pair[0] = '0' + value / 10;
pair[1] = '0' + value % 10;
pair[2] = 0;
gime_fill_rect(x, 149, 11, 8, SKY);
label(x, 149, pair, WHITE);
}
/* Each hidden page remembers where its own ship was painted. Erase just
that footprint. A mark stays put for the rest of this flight. */
static byte draw(byte sector, byte mark)
{
byte old = previousShip[hidden];
unsigned x = (unsigned)sector * 20;
if (old != sector) {
if (old != NO_MARK)
gime_fill_rect((unsigned)old * 20 + 2, 53, 16, 12, SKY);
gime_fill_rect(x + 7, 53, 6, 3, ICE);
gime_fill_rect(x + 4, 56, 12, 3, WHITE);
gime_fill_rect(x + 2, 59, 16, 3, TEAL);
gime_fill_rect(x + 5, 62, 2, 3, GOLD);
gime_fill_rect(x + 13, 62, 2, 3, GOLD);
digits(50, sector);
previousShip[hidden] = sector;
}
if (mark != NO_MARK && previousMark[hidden] != mark) {
gime_fill_rect((unsigned)mark * 20 + 8, 68, 4, 4, GOLD);
digits(110, mark);
previousMark[hidden] = mark;
}
hidden ^= 1;
return gime_present();
}
static byte flightLoop(byte speech, byte *mark, byte *speechError)
{
VccInput stick;
byte sector = 7, recorded = NO_MARK;
ssc_phrase words;
byte exit = 0;
unsigned started = 0, lastSample = getTimer();
words.remaining = 0;
input_init(&stick, INPUT_RIGHT);
for (;;) {
byte key = inkey(), fire = 0, previous = sector;
unsigned now = getTimer();
if (key >= 'a' && key <= 'z') key -= 'a' - 'A';
if (key == 'Q') exit = DISCARDED;
if (key == 'S' && recorded != NO_MARK) exit = RECORDED;
/* Service one cartridge byte per turn. Remember Save or Quit even
when there is no ready signal. Two seconds bounds the whole phrase. */
if (words.remaining) {
if ((unsigned)(now - started) < 120) ssc_service(&words);
else { words.remaining = 0; *speechError = SSC_TIMEOUT; }
}
if (exit) {
if (words.remaining) continue;
if (exit == RECORDED && !bank_read(0, mark, 1)) return FLIGHT_ERROR;
return exit;
}
if ((unsigned)(now - lastSample) >= 5) {
lastSample = now;
input_sample(&stick);
fire = stick.pressed & INPUT_PRIMARY;
if (stick.dx < 0 && sector > 0) --sector;
if (stick.dx > 0 && sector < 15) ++sector;
}
if (key == 'A' && sector > 0) --sector;
if (key == 'D' && sector < 15) ++sector;
if ((key == ' ' || fire) && recorded == NO_MARK) {
if (!bank_write(0, &sector, 1)) return FLIGHT_ERROR;
recorded = sector;
if (speech) {
started = now;
ssc_begin_phrase(&words, "MARK RECORDED");
}
} else if (previous == sector) {
continue;
}
if (!draw(sector, recorded)) {
if (words.remaining) *speechError = SSC_TIMEOUT;
return FLIGHT_ERROR;
}
}
}
unsigned char fly(unsigned char audio, unsigned char *mark)
{
static const byte colors[] = {0x01, 0x3f, 0x1f, 0x36, 0x20, 0x34, 0x0f};
byte i, result = FLIGHT_ERROR, stereo = 0, speechError = SSC_OK;
unsigned route = 0;
if (!bank_open()) {
printf("USE STANDARD COCO 3 BASIC WITH\n512K OR MORE\n");
return FLIGHT_ERROR;
}
if (!gime_open()) {
bank_close();
printf("GRAPHICS UNAVAILABLE\n");
return FLIGHT_ERROR;
}
for (i = 0; i < sizeof(colors); ++i) gime_set_palette(i, colors[i]);
previousShip[0] = previousShip[1] = NO_MARK;
previousMark[0] = previousMark[1] = NO_MARK;
hidden = 0;
landscape();
if (gime_present()) {
/* Show the ship only when the second page and controls are ready. */
landscape();
if (audio & AUDIO_SPEECH) route = ssc_route_audio();
if (audio & AUDIO_STEREO)
stereo = orch90_start(beacon, sizeof(beacon) / sizeof(beacon[0]), 1, ORCH90_CLOCK_NORMAL);
if (draw(7, NO_MARK))
result = flightLoop(audio & AUDIO_SPEECH, mark, &speechError);
if (stereo) orch90_stop();
if (audio & AUDIO_SPEECH) {
if (speechError == SSC_TIMEOUT) ssc_reset();
ssc_restore_audio(route);
}
}
gime_close();
bank_close();
if (speechError != SSC_OK) printf("SPEECH UNAVAILABLE\n");
if ((audio & AUDIO_STEREO) && !stereo) printf("STEREO PLAYER UNAVAILABLE\n");
if (result == FLIGHT_ERROR) printf("FLIGHT TRANSFER OR DISPLAY ERROR\n");
return result;
}
+20
View File
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <coco.h>
#include "mission.h"
int main(void)
{
byte key, sector, result;
cls(1);
printf("MISSION RECORDER\n\n1 SILENT 2 SPEECH\n3 STEREO 4 BOTH\nQ QUIT\nSELECT AUDIO\n");
do {
key = waitkey(0);
if (key == 'Q' || key == 'q') return 0;
} while (key < '1' || key > '4');
result = fly(key - '1', &sector);
if (result == DISCARDED) printf("FLIGHT DISCARDED\n");
if (result == FLIGHT_ERROR) return 1;
if (result == RECORDED) return saveReport(sector);
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef MISSION_H
#define MISSION_H
#define AUDIO_SPEECH 1
#define AUDIO_STEREO 2
enum FlightResult { FLIGHT_ERROR, DISCARDED, RECORDED };
unsigned char fly(unsigned char audio, unsigned char *mark);
int saveReport(unsigned char sector);
#endif
+72
View File
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <coco.h>
#include <stdio.h>
#include <decbfile.h>
#include <vcc/printer.h>
#include "mission.h"
enum { IO_ERROR, MISSING, OCCUPIED };
static int inspect(const char *name)
{
FILE *f = fopen(name, "rb");
if (!f) return vcc_file_error() == DECB_ERR_NOT_FOUND ? MISSING : IO_ERROR;
return fclose(f) == 0 ? OCCUPIED : IO_ERROR;
}
/* Verify every byte, the exact EOF, and the close before publishing the name. */
static int matches(const char *name, const char *report)
{
FILE *f = fopen(name, "rb");
if (!f) return 0;
while (*report && fgetc(f) == *report) ++report;
int exact = !*report && fgetc(f) == EOF && !ferror(f);
return fclose(f) == 0 && exact;
}
static int publish(const char *report, char *name)
{
char draft[] = "LOG00.TMP:0";
unsigned i;
for (i = 1; i <= 99; ++i) {
name[3] = draft[3] = (char)('0' + i / 10);
name[4] = draft[4] = (char)('0' + i % 10);
int live = inspect(name), temp = inspect(draft);
if (live == IO_ERROR || temp == IO_ERROR) return 0;
if (live == OCCUPIED || temp == OCCUPIED) continue;
/* Old reports and interrupted drafts belong to the disk owner.
Only an unused pair is eligible. rename also refuses collisions. */
FILE *f = fopen(draft, "w");
if (!f) return 0;
int written = fputs(report, f) != EOF;
if (fclose(f) != 0 || !written || !matches(draft, report)) return 0;
return rename(draft, name) == 0;
}
printf("ALL REPORT NAMES IN USE\n");
return 0;
}
int saveReport(unsigned char sector)
{
/* One byte string, including the CoCo's CR line endings, goes to both
devices. A paper copy is requested only after publication succeeds. */
char report[sizeof("MISSION RECORDER\rSECTOR 00\r")];
char name[] = "LOG00.TXT:0";
snprintf(report, sizeof(report), "MISSION RECORDER\rSECTOR %02u\r", (unsigned)sector);
while (!publish(report, name)) {
byte key;
printf("SAVE FAILED\nCHECK DRIVE 0; R RETRY OR Q QUIT\n");
do { key = waitkey(0); } while (key != 'R' && key != 'r' &&
key != 'Q' && key != 'q');
if (key == 'Q' || key == 'q') return 1;
}
name[9] = '\0';
printf("SAVED %s\n", name);
if (vcc_printer_printf("%s", report) < 0) {
printf("REPORT DELIVERY INCOMPLETE\n");
return 1;
}
printf("REPORT SENT TO PRINTER PORT\n");
return 0;
}
@@ -0,0 +1,57 @@
{
"binary": "RECORDER.bin",
"buildTarget": "build",
"cleanTarget": "clean",
"configurations": [
{
"makeArguments": [],
"name": "Debug"
},
{
"makeArguments": [
"VCC_CONFIGURATION=Release"
],
"name": "Release"
}
],
"diskImage": "RECORDER.dsk",
"diskTarget": "disk",
"entrySource": "main.c",
"jobs": 4,
"launchCommands": [],
"launchMode": "quickload",
"makefile": "Makefile",
"makefileSettings": {
"compilerOptions": [],
"defines": [],
"diskBootMode": "none",
"diskFiles": [],
"diskImage": "RECORDER.dsk",
"executable": "RECORDER.bin",
"generatedResources": [],
"includePaths": [],
"libraries": [
"bank",
"gime",
"input",
"bcontrol",
"ssc",
"orch90",
"hirestxt",
"vcccompat",
"decbfile"
],
"libraryPaths": [],
"libraryProjects": [],
"linkerOptions": [],
"origin": "2000",
"releaseOptimization": "-O2",
"sources": [
"main.c",
"flight.c",
"report.c"
],
"stackSpace": 2048,
"limit": "7800"
}
}
+38
View File
@@ -0,0 +1,38 @@
# SPDX-License-Identifier: GPL-3.0-or-later
# Build with GNU Make and the VCC Plus CMOC toolchain on PATH.
CMOC ?= cmoc
WRITECOCOFILE ?= writecocofile
PERL ?= perl
VCC_CONFIGURATION ?= Debug
ifeq ($(VCC_CONFIGURATION),Release)
OPTIM ?= -O2
else
OPTIM ?= -O0 -fno-omit-frame-pointer
endif
export VCC_CMOC_COMPAT = 1
# The IDE supplies its selected library bindings. At the command line the
# same archives are available by name from the bundled toolchain.
LIBRARIES = $(if $(strip $(GUEST_LIBS)),$(GUEST_LIBS),-lsdc -lvcccompat -ldecbfile)
DISKS := EXPED/EXPLORE.DSK EXPED/EARTH.DSK EXPED/MARS.DSK
.PHONY: all build disk clean
.DELETE_ON_ERROR:
all build disk: $(DISKS)
EXPLORE.BIN: expedition.c Makefile
"$(CMOC)" --coco --intermediate --org=2800 --stack-space=2048 $(OPTIM) -Werror -o $@ $< $(LIBRARIES)
generated/%/LANDING.TXT: assets/%.txt Makefile
@mkdir -p $(dir $@)
"$(PERL)" -pe 's/\r?\n/\r/' $< > $@
EXPED/EXPLORE.DSK: EXPLORE.BIN
EXPED/EARTH.DSK: generated/earth/LANDING.TXT
EXPED/MARS.DSK: generated/mars/LANDING.TXT
$(DISKS): Makefile
@mkdir -p $(dir $@)
"$(PERL)" -e 'print chr(255) x (35*18*256)' > $@
"$(WRITECOCOFILE)" $@ $(filter-out Makefile,$^)
clean:
rm -f $(DISKS) EXPLORE.BIN expedition.o expedition.s expedition.lst EXPLORE.map EXPLORE.link
rm -f generated/earth/LANDING.TXT generated/mars/LANDING.TXT
@@ -0,0 +1,2 @@
EARTH: BLUE OCEAN
SPLASH DOWN BESIDE THE BUOY.
@@ -0,0 +1,2 @@
MARS: RED RIDGE
LAND BEYOND THE DUST FIELD.
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// The card holds disk images. Each planet disk holds its own LANDING.TXT.
#include <coco.h>
#include <stdio.h>
#include <vcc/sdc.h>
// Browse the card once. A directory entry describes the image file itself.
static void showChart(void)
{
SdcEntry entry;
unsigned char result = sdc_list_begin("/*.DSK");
printf("DISKS ON THE PRACTICE CARD\n");
if (result == SDC_OK)
while ((result = sdc_list_next(&entry)) == SDC_OK)
if (!(entry.attributes & SDC_DIRECTORY))
printf(" %s\n", entry.name);
if (result != SDC_END)
printf("CHART UNAVAILABLE (%u)\n", (unsigned)result);
}
// The controller reports the actual filename, even after a failed mount.
static void showDrive(unsigned char drive)
{
SdcEntry entry;
unsigned char result = sdc_mounted(drive, &entry);
printf("SDC%u: ", (unsigned)drive);
if (result == SDC_OK)
printf("%s\n", entry.name);
else if (result == SDC_NOT_FOUND)
printf("EMPTY\n");
else
printf("CANNOT QUERY (%u)\n", (unsigned)result);
}
static void landingReport(void)
{
// :1 asks the Disk BASIC ROM for a file inside the mounted planet.
FILE *file = fopen("LANDING.TXT:1", "r");
char line[40];
int ok;
if (!file)
{
printf("NO LANDING REPORT ON DRIVE 1\n");
return;
}
while (fgets(line, sizeof(line), file))
printf("%s", line);
ok = !ferror(file);
if (fclose(file) == EOF || !ok)
printf("ERROR READING LANDING REPORT\n");
}
int main(void)
{
int key;
unsigned char result;
const char *path;
width(40);
cls(1);
printf("PLANET EXPEDITION\n\n");
if (sdc_probe() != SDC_OK)
{
printf("CHOOSE THE COCO SDC PROFILE\n");
return 1;
}
showChart();
for (;;)
{
printf("\n");
showDrive(0);
showDrive(1);
printf("\n1 EARTH 2 MARS\n3 TRY MISSING DISK Q QUIT\n");
do {
key = waitkey(0);
} while (key != '1' && key != '2' && key != '3' && key != 'Q' && key != 'q');
if (key == 'Q' || key == 'q')
break;
// No file is open here. Leave drive 0 alone and change only drive 1.
path = key == '1' ? "/EARTH.DSK" : key == '2' ? "/MARS.DSK" : "/MISSING.DSK";
result = sdc_mount(1, path);
cls(1);
printf("PLANET EXPEDITION\n\n");
if (result == SDC_OK)
printf("LANDED\n");
else
printf("COULD NOT MOUNT %s (%u)\n", path, (unsigned)result);
// Read what is actually mounted, including after a rejected change.
landingReport();
}
printf("EXPEDITION COMPLETE\n");
return 0;
}
@@ -0,0 +1,37 @@
{
"entrySource": "expedition.c",
"makefile": "Makefile",
"buildTarget": "build",
"cleanTarget": "clean",
"diskTarget": "disk",
"binary": "EXPLORE.BIN",
"diskImage": "EXPED/EXPLORE.DSK",
"launchMode": "quickload",
"jobs": 3,
"configurations": [
{
"name": "Debug",
"makeArguments": []
},
{
"name": "Release",
"makeArguments": [
"VCC_CONFIGURATION=Release"
]
}
],
"bundledLibraries": [
{
"library": "sdc",
"linkVariable": "GUEST_LIBS"
},
{
"library": "vcccompat",
"linkVariable": "GUEST_LIBS"
},
{
"library": "decbfile",
"linkVariable": "GUEST_LIBS"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
obj/
SURVEY.bin
SURVEY.dsk
SURVEY.map
SURVEY.link
.vccplus-build/
generated/
+55
View File
@@ -0,0 +1,55 @@
# Generated by VCC Plus — edit Project Settings to regenerate.
# Ordinary GNU Make; no VCC Plus project parser is required to build it.
CMOC ?= cmoc
PERL ?= perl
WRITECOCOFILE ?= writecocofile
INSTALL_LOADER ?= install-coco-boot-loader
VCC_CONFIGURATION ?= Debug
ifeq ($(VCC_CONFIGURATION),Release)
OPTIM ?= -O2
else
OPTIM ?= -O0
DEBUG_FRAME ?= -fno-omit-frame-pointer
endif
define VCC_DEFINES
endef
define VCC_COMPILER_OPTIONS
endef
define VCC_LINKER_OPTIONS
endef
export VCC_CMOC_COMPAT = 1
CPPFLAGS += $(VCC_DEFINES)
CFLAGS += --coco --intermediate --deps --stack-space=2048 $(OPTIM) $(DEBUG_FRAME) $(VCC_COMPILER_OPTIONS)
LDFLAGS += --coco --intermediate --org=2800 $(VCC_LINKER_OPTIONS)
LDLIBS += -lvcccompat -ldecbfile
OBJECTS := obj/main.o
.PHONY: all build clean disk libraries
all: build
build: SURVEY.bin
SURVEY.bin: $(OBJECTS) Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
obj/main.o: main.c Makefile generated/PLANETS.TXT
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
generated/PLANETS.TXT &: assets/planets.txt Makefile
@mkdir -p generated
$(PERL) -pe 's/\r?\n/\r/' assets/planets.txt > generated/PLANETS.TXT
test -f generated/PLANETS.TXT
disk: SURVEY.dsk
SURVEY.dsk: SURVEY.bin generated/PLANETS.TXT Makefile
@mkdir -p $(dir $@)
$(PERL) -e 'print chr(255) x (35*18*256)' > $@
$(WRITECOCOFILE) $@ SURVEY.bin
$(WRITECOCOFILE) $@ generated/PLANETS.TXT
clean:
rm -rf obj
rm -f SURVEY.bin SURVEY.map SURVEY.link SURVEY.dsk generated/PLANETS.TXT
-include $(OBJECTS:.o=.d)
@@ -0,0 +1,8 @@
# PLANET SURVEY / FLIGHT LOG / LOG 0042
# Read before picking a landing site.
# 1: Check the blue planet from orbit.
# 2: Mark the red planet on the map.
# Pick one of the two reports below.
# Columns: planet|trait,trait|orbit (1 to 8).
EARTH|BLUE,WET|3
MARS|RED,COLD|4
+92
View File
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <coco.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Split a writable record such as MARS|RED,COLD|4. Each cursor belongs
to one scan. The tokens point directly into the line read from disk. */
static int showRecord(char *line)
{
char *fields, *traits, *end;
char summary[112];
char *name = strtok_r(line, "|", &fields);
char *list = strtok_r(NULL, "|", &fields);
if (!name || !list)
return 0;
char *first = strtok_r(list, ",", &traits);
char *second = strtok_r(NULL, ",", &traits);
if (!first || !second || strtok_r(NULL, ",", &traits))
return 0;
/* Resume the outer scan exactly where we left it. */
char *text = strtok_r(NULL, "|", &fields);
if (!text || strtok_r(NULL, "|", &fields) || !isdigit((unsigned char)*text))
return 0;
errno = 0;
unsigned long orbit = strtoul(text, &end, 10);
if (*end || errno == ERANGE || orbit < 1UL || orbit > 8UL)
return 0;
int length = snprintf(summary, sizeof(summary),
"SURVEY: %s\nTRAITS: %s AND %s\nORBIT FROM SUN: %lu",
name, first, second, orbit);
if (length < 0 || length >= (int)sizeof(summary))
return 0;
printf("%s\n", summary);
return 1;
}
int main(void)
{
char line[64], choice;
unsigned record = 0;
int tooLong = 0;
cls(1);
printf("PLANET SURVEY\n1 EARTH 2 MARS\n");
do
choice = waitkey(0);
while (choice != '1' && choice != '2');
FILE *log = fopen("PLANETS.TXT", "r");
if (!log)
{
printf("CANNOT OPEN PLANETS.TXT\n");
return 1;
}
/* Skip the flight notes. The first data line is Earth, the second Mars. */
while (fgets(line, sizeof(line), log))
{
unsigned length = strcspn(line, "\n");
if (length == sizeof(line) - 1)
{
tooLong = 1; // Never mistake part of a long line for a new record.
break;
}
line[length] = '\0';
if (!line[0] || line[0] == '#')
continue;
if (++record == (unsigned)(choice - '0'))
break;
}
/* An error can end a read loop just as end-of-file can. */
int diskError = ferror(log);
if (fclose(log) == EOF || diskError)
printf("DISK READ ERROR\n");
else if (tooLong)
printf("SURVEY LINE TOO LONG\n");
else if (record != (unsigned)(choice - '0'))
printf("NO MATCHING SURVEY RECORD\n");
else if (!showRecord(line))
printf("INVALID SURVEY RECORD\n");
else
{
printf("SURVEY COMPLETE\n");
return 0;
}
return 1;
}
@@ -0,0 +1,61 @@
{
"binary": "SURVEY.bin",
"buildTarget": "disk",
"cleanTarget": "clean",
"configurations": [
{
"makeArguments": [],
"name": "Debug"
},
{
"makeArguments": [
"VCC_CONFIGURATION=Release"
],
"name": "Release"
}
],
"diskImage": "SURVEY.dsk",
"diskTarget": "disk",
"entrySource": "main.c",
"jobs": 4,
"launchCommands": [
"LOADM\"SURVEY\":EXEC"
],
"launchMode": "disk",
"makefile": "Makefile",
"makefileSettings": {
"compilerOptions": [],
"defines": [],
"diskBootMode": "none",
"diskFiles": [
"generated/PLANETS.TXT"
],
"diskImage": "SURVEY.dsk",
"executable": "SURVEY.bin",
"generatedResources": [
{
"inputs": [
"assets/planets.txt"
],
"outputs": [
"generated/PLANETS.TXT"
],
"command": "$(PERL) -pe 's/\\r?\\n/\\r/' assets/planets.txt > generated/PLANETS.TXT"
}
],
"includePaths": [],
"libraries": [
"vcccompat",
"decbfile"
],
"libraryPaths": [],
"libraryProjects": [],
"linkerOptions": [],
"origin": "2800",
"releaseOptimization": "-O2",
"sources": [
"main.c"
],
"stackSpace": 2048
}
}
@@ -0,0 +1,6 @@
obj/
LANDER.bin
LANDER.dsk
LANDER.map
LANDER.link
.vccplus-build/
@@ -0,0 +1,49 @@
# Generated by VCC Plus — edit Project Settings to regenerate.
# Ordinary GNU Make; no VCC Plus project parser is required to build it.
CMOC ?= cmoc
PERL ?= perl
WRITECOCOFILE ?= writecocofile
INSTALL_LOADER ?= install-coco-boot-loader
VCC_CONFIGURATION ?= Debug
ifeq ($(VCC_CONFIGURATION),Release)
OPTIM ?= -O2
else
OPTIM ?= -O0
DEBUG_FRAME ?= -fno-omit-frame-pointer
endif
define VCC_DEFINES
endef
define VCC_COMPILER_OPTIONS
endef
define VCC_LINKER_OPTIONS
endef
export VCC_CMOC_COMPAT = 1
CPPFLAGS += $(VCC_DEFINES)
CFLAGS += --coco --intermediate --deps --stack-space=2048 $(OPTIM) $(DEBUG_FRAME) $(VCC_COMPILER_OPTIONS)
LDFLAGS += --coco --intermediate --org=2800 $(VCC_LINKER_OPTIONS)
LDLIBS += -lssc -lorch90 -lbcontrol -lvcccompat
OBJECTS := obj/main.o
.PHONY: all build clean disk libraries
all: build
build: LANDER.bin
LANDER.bin: $(OBJECTS) Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
obj/main.o: main.c Makefile
@mkdir -p $(dir $@)
"$(CMOC)" $(CPPFLAGS) $(CFLAGS) --intdir=$(dir $@) -c -o $@ $<
disk: LANDER.dsk
LANDER.dsk: LANDER.bin Makefile
@mkdir -p $(dir $@)
$(PERL) -e 'print chr(255) x (35*18*256)' > $@
$(WRITECOCOFILE) $@ LANDER.bin
clean:
rm -rf obj
rm -f LANDER.bin LANDER.map LANDER.link LANDER.dsk
-include $(OBJECTS:.o=.d)
@@ -0,0 +1,11 @@
# Talking Planet Lander
Start the Disk BASIC system profile. In Cartridges, enable the Multi-Pak and install Speech/Sound in slot 1 and Orchestra-90 in slot 2. Keep the floppy controller in startup slot 4. Speech/Sound needs its PIC and speech ROMs. Orchestra-90 works in sound-only mode. Use normal CoCo CPU speed for the beacon.
Build and Run in C Development, then press **1** for Earth or **2** for Mars in the emulator window. Listen for a low note on the left and a higher one on the right. The pilot announces the destination and landing. During either phrase, press the primary fire button on either CoCo joystick to print **THRUST**. Each press counts once. With either cartridge omitted the visual landing still works.
The project uses VCC Plus's optional bounded formatter, Speech/Sound and Orchestra-90 libraries, plus BControl for buttons. The source shows how to poll the guest while the cartridge speaks. The stereo beacon uses foreground playback and briefly occupies the processor.
Use **Build Disk** for a floppy copy. Mount LANDER.dsk in FD0 and enter `LOADM"LANDER":EXEC`. Building on the command line uses the bundled toolchain on PATH and ordinary Make.
The original example and VCC Plus guest libraries are licensed GPL-3.0-or-later. BControl retains its upstream license.
+80
View File
@@ -0,0 +1,80 @@
// SPDX-License-Identifier: GPL-3.0-or-later
#include <cmoc.h>
#include <coco.h>
#include <stdio.h>
#include <Joystick.h>
#include <vcc/orch90.h>
#include <vcc/ssc.h>
// Poll the two primary buttons. Reading buttons alone preserves the audio mux.
static unsigned char buttonDown;
static void checkThruster(void)
{
unsigned char down = (Joystick_getButtonStates2() & 3) != 3;
if (down && !buttonDown)
printf("THRUST\n");
buttonDown = down;
}
// Send one byte at a time so the player can fire while the cartridge is busy.
// The firmware asserts busy after accepting the terminator. Give it time to
// start, then wait for it to finish before sending another announcement.
static unsigned char announce(const char *words)
{
ssc_phrase phrase;
unsigned int start = getTimer();
if (ssc_begin_phrase(&phrase, words) != SSC_OK)
return 0;
while (ssc_service(&phrase) == SSC_PENDING) {
checkThruster();
if ((unsigned int)(getTimer() - start) >= 90)
return 0;
}
start = getTimer();
while (ssc_status() & SSC_SPEECH_IDLE) {
checkThruster();
if ((unsigned int)(getTimer() - start) >= 60)
return 0;
}
while (!(ssc_status() & SSC_SPEECH_IDLE)) {
checkThruster();
if ((unsigned int)(getTimer() - start) >= 600)
return 0;
}
return 1;
}
// Make an original two-note beacon. At normal CPU speed 16 frames repeat
// about 250 times a second. The right-hand note is one octave higher.
static void beacon(void)
{
struct orch90_frame block[128];
unsigned char side, i, repeat;
for (side = 0; side < 2; ++side) {
for (i = 0; i < 128; ++i) {
block[i].left = side ? 128 : (i & 8 ? 152 : 104);
block[i].right = side ? (i & 4 ? 152 : 104) : 128;
}
for (repeat = 0; repeat < 6; ++repeat)
orch90_play(block, 128, ORCH90_CLOCK_NORMAL);
}
orch90_write(128, 128);
}
int main(void)
{
char key, message[24];
unsigned int route;
cls(1);
printf("TALKING PLANET LANDER\n1 EARTH 2 MARS\n");
do { key = waitkey(0); } while (key != '1' && key != '2');
snprintf(message, sizeof(message), "DESTINATION %s", key == '1' ? "EARTH" : "MARS");
printf("%s\nPRESS FIRE FOR THRUST\n", message);
route = ssc_route_audio();
beacon();
if (announce(message))
announce("LANDING COMPLETE");
ssc_restore_audio(route);
printf("TOUCHDOWN\n");
return 0;
}
@@ -0,0 +1,49 @@
{
"binary": "LANDER.bin",
"buildTarget": "build",
"cleanTarget": "clean",
"configurations": [
{
"makeArguments": [],
"name": "Debug"
},
{
"makeArguments": [
"VCC_CONFIGURATION=Release"
],
"name": "Release"
}
],
"diskImage": "LANDER.dsk",
"diskTarget": "disk",
"entrySource": "main.c",
"jobs": 4,
"launchCommands": [],
"launchMode": "quickload",
"makefile": "Makefile",
"makefileSettings": {
"compilerOptions": [],
"defines": [],
"diskBootMode": "none",
"diskFiles": [],
"diskImage": "LANDER.dsk",
"executable": "LANDER.bin",
"generatedResources": [],
"includePaths": [],
"libraries": [
"ssc",
"orch90",
"bcontrol",
"vcccompat"
],
"libraryPaths": [],
"libraryProjects": [],
"linkerOptions": [],
"origin": "2800",
"releaseOptimization": "-O2",
"sources": [
"main.c"
],
"stackSpace": 2048
}
}
+70
View File
@@ -0,0 +1,70 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Mission Announcer. Select ssc, input and bcontrol in Project Settings. */
#include <cmoc.h>
#include <coco.h>
#include <vcc/input.h>
#include <vcc/ssc.h>
#define VOICE_SLOT 1
#define ALERT_SLOT 2
#define MESSAGE_SLOT 3
#define POLL_LIMIT 30000
/* Z + "or" + an unstressed vowel: give our invented planet a voice. */
static const unsigned char zora[] = { SSC_AL_ZZ, SSC_AL_OR, SSC_AL_AX };
int main(void)
{
unsigned int route, lastSample, now, landings = 0;
unsigned char key, status;
VccInput stick;
cls(1);
printf("MISSION ANNOUNCER\n");
route = ssc_route_audio();
/* Store each recipe once. The two slot numbers belong to separate banks. */
status = ssc_store_allophones(VOICE_SLOT, zora, sizeof(zora), POLL_LIMIT);
if (status == SSC_OK)
status = ssc_store_phrase(MESSAGE_SLOT, "WELCOME ABOARD", POLL_LIMIT);
if (status == SSC_OK)
status = ssc_store_enveloped_tone(ALERT_SLOT, 0, 420, SSC_ENV_DECAY,
1800, 18, POLL_LIMIT);
if (status == SSC_OK) {
input_init(&stick, INPUT_RIGHT);
lastSample = getTimer();
printf("1 ANNOUNCE ZORA\n2 CREW MESSAGE\nFIRE LANDING ALERT\nQ RETURN TO BASIC\n");
while (status == SSC_OK) {
key = inkey();
if (key == 'Q' || key == 'q')
break;
if (key == '1') {
status = ssc_play_allophones(VOICE_SLOT, POLL_LIMIT);
if (status == SSC_OK)
printf("APPROACHING ZORA\n");
} else if (key == '2') {
status = ssc_play_phrase(MESSAGE_SLOT, POLL_LIMIT);
if (status == SSC_OK)
printf("WELCOME ABOARD\n");
}
/* Joystick readings share the audio mux. Sample once per guest tick. */
now = getTimer();
if (now == lastSample)
continue;
lastSample = now;
input_sample(&stick);
/* A press is an edge: holding the button counts as one landing. */
if (status == SSC_OK && (stick.pressed & INPUT_PRIMARY)) {
status = ssc_play_stored_effect(ALERT_SLOT, POLL_LIMIT);
if (status == SSC_OK)
printf("LANDING ALERT %u\n", ++landings);
}
}
}
/* A partial command may remain after timeout. Reset only on that path. */
if (status == SSC_TIMEOUT)
ssc_reset();
ssc_restore_audio(route);
if (status != SSC_OK)
printf("CHECK CARTRIDGE AND FIRMWARE\n");
return status;
}
+159
View File
@@ -0,0 +1,159 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Planet Atlas creates ATLAS.DAT on drive 0 the first time you run it.
#include <coco.h>
#include <decbfile.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#define ATLAS_NAME "ATLAS.DAT:0"
#define CARD_SIZE 24
static const char cards[][CARD_SIZE] = {
"MERCURY: CRATERS", "VENUS: CLOUDS", "EARTH: BLUE SEA", "MARS: RED RIDGE"
};
/* Keep any atlas already on the disk. On a fresh disk, write four cards. */
static FILE *openAtlas(void)
{
FILE *atlas = fopen(ATLAS_NAME, "r+b");
int complete;
if (atlas || vcc_file_error() != DECB_ERR_NOT_FOUND)
return atlas;
atlas = fopen(ATLAS_NAME, "wb");
if (!atlas)
return NULL;
complete = fwrite(cards, CARD_SIZE, 4, atlas) == 4;
if (fclose(atlas) == EOF || !complete)
return NULL;
return fopen(ATLAS_NAME, "r+b");
}
/* Read exactly one card from the current position. Leave room for a zero
so even a card that fills all 24 bytes can be displayed as a C string. */
static int showCard(FILE *atlas)
{
char card[CARD_SIZE + 1];
if (fread(card, CARD_SIZE, 1, atlas) != 1)
return 0;
card[CARD_SIZE] = 0;
printf("%s\n", card);
return 1;
}
static int takeTrip(FILE *atlas, int number)
{
/* Card numbers begin at 1. Disk offsets begin at 0. */
long offset = (long)(number - 1) * CARD_SIZE;
long bookmark;
if (fseek(atlas, offset, SEEK_SET) != 0)
return 0;
bookmark = ftell(atlas); // Save the start before reading the card.
if (bookmark < 0)
return 0;
printf("YOUR PICK AT BYTE %ld\n", bookmark);
if (!showCard(atlas))
return 0;
printf("HOME BASE\n");
if (fseek(atlas, 2L * CARD_SIZE, SEEK_SET) != 0 || !showCard(atlas))
return 0;
printf("BACK TO YOUR BOOKMARK\n");
if (fseek(atlas, bookmark, SEEK_SET) != 0 || !showCard(atlas))
return 0;
rewind(atlas); // The first card is Mercury again.
printf("FIRST CARD\n");
return ftell(atlas) == 0L && showCard(atlas);
}
/* Enter a whole record number. Base zero accepts 2 and 0x2 for Venus. */
static int choosePlanet(void)
{
for (;;)
{
char *line, *end;
unsigned long number;
printf("PICK A PLANET (1-4), THEN ENTER\n");
line = readline();
if (!line)
return 0;
if (!isdigit((unsigned char)*line))
{
printf("START WITH A DIGIT\n");
continue;
}
errno = 0;
number = strtoul(line, &end, 0);
if (*end)
printf("EXTRA CHARACTER: %c\n", *end);
else if (errno == ERANGE || number < 1UL || number > 4UL)
printf("CHOOSE A NUMBER FROM 1 TO 4\n");
else
return (int)number; // Now the value is small enough for an int.
}
}
/* The last padding byte is a visit flag. A custom card that uses the whole
field for its description has no spare byte; leave its text intact. */
static int recordVisit(FILE *atlas, int number)
{
char card[CARD_SIZE];
long start = (long)(number - 1) * CARD_SIZE;
if (fseek(atlas, start, SEEK_SET) != 0 || fread(card, CARD_SIZE, 1, atlas) != 1)
return 0;
if (!memchr(card, 0, CARD_SIZE - 1) ||
(card[CARD_SIZE - 1] != 0 && card[CARD_SIZE - 1] != 'V'))
{
printf("NO ROOM FOR VISIT MARK\n");
return 1;
}
if (card[CARD_SIZE - 1] == 'V')
{
printf("ALREADY VISITED\n");
return 1;
}
// Position the update stream between reading the card and writing its flag.
if (fseek(atlas, start + CARD_SIZE - 1, SEEK_SET) != 0 ||
fputc('V', atlas) == EOF || fflush(atlas) == EOF)
return 0;
printf("VISIT SAVED\n");
return 1;
}
int main(void)
{
FILE *atlas;
int number, ok;
cls(1);
atlas = openAtlas();
if (!atlas)
{
printf("CANNOT OPEN ATLAS.DAT\n");
return 1;
}
printf("PLANET ATLAS\n1 MERCURY 2 VENUS\n3 EARTH 4 MARS\n");
number = choosePlanet();
if (!number)
{
fclose(atlas);
printf("CANNOT READ KEYBOARD\n");
return 1;
}
cls(1);
printf("PLANET ATLAS\n\n");
ok = takeTrip(atlas, number);
if (!ok)
printf("CANNOT READ ATLAS CARD\n");
else if (!recordVisit(atlas, number))
{
printf("CANNOT SAVE VISIT\n");
ok = 0;
}
if (fclose(atlas) == EOF)
ok = 0;
if (ok)
printf("ATLAS CLOSED\n");
return ok ? 0 : 1;
}
+140
View File
@@ -0,0 +1,140 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Run on a practice disk. This exercise recognizes the four Planet char cards[][CARD_SIZE].
#include <coco.h>
#include <decbfile.h>
#include <stdio.h>
#define LIVE "ATLAS.DAT:0"
#define DRAFT "ATLAS.NEW:0"
#define BACKUP "ATLAS.BAK:0"
#define CARD_SIZE 24
static const char original[][CARD_SIZE] = {
"MERCURY: CRATERS", "VENUS: CLOUDS", "EARTH: BLUE SEA", "MARS: RED RIDGE"
};
static const char newMars[CARD_SIZE] = "MARS: DUST STORM";
static char live[4][CARD_SIZE], draft[4][CARD_SIZE], backup[4][CARD_SIZE];
enum { ABSENT, FIRST, SECOND, UNRECOGNIZED, DISK_ERROR };
/* A valid edition contains four exact cards. Each may also have a visit mark
in its final byte. Check file length as well as text before changing a name. */
static int inspect(const char *name, char cards[][CARD_SIZE])
{
unsigned i;
FILE *f = fopen(name, "rb");
if (!f)
return vcc_file_error() == DECB_ERR_NOT_FOUND ? ABSENT : DISK_ERROR;
size_t count = fread(cards, 1, sizeof(original), f);
int extra = fgetc(f);
int failed = ferror(f);
if (fclose(f) == EOF || failed)
return DISK_ERROR;
if (count != sizeof(original) || extra != EOF)
return UNRECOGNIZED;
for (i = 0; i < 4; ++i)
{
char mark = cards[i][CARD_SIZE - 1];
if (mark != 0 && mark != 'V')
return UNRECOGNIZED;
if (memcmp(cards[i], original[i], CARD_SIZE - 1) != 0)
{
if (i == 3 && memcmp(cards[3], newMars, CARD_SIZE - 1) == 0)
return SECOND;
return UNRECOGNIZED;
}
}
return FIRST;
}
/* Write only after the caller has checked that the name is unused. */
static int writeCards(const char *name, const void *cards)
{
FILE *f = fopen(name, "wb");
if (!f)
return 0;
int complete = fwrite(cards, 1, sizeof(original), f) == sizeof(original);
return fclose(f) == 0 && complete;
}
static void reviseMars(char cards[][CARD_SIZE])
{
// The old visit mark belongs to the traveler. Keep the last byte.
memcpy(cards[3], newMars, CARD_SIZE - 1);
}
static int recover(int draftState)
{
// The live name was missing. Restore the known old edition first.
if (rename(BACKUP, LIVE) != 0)
return 0;
printf("ORIGINAL ATLAS RESTORED\n%s\n", backup[3]);
reviseMars(backup);
if (draftState == SECOND && memcmp(backup, draft, sizeof(original)) == 0)
return remove(DRAFT) == 0;
if (draftState != ABSENT)
printf("KEPT UNEXPECTED ATLAS.NEW\n");
return 1;
}
static int saveAtlas(void)
{
int current = inspect(LIVE, live);
int old = inspect(BACKUP, backup);
int next = inspect(DRAFT, draft);
if (current == DISK_ERROR || old == DISK_ERROR || next == DISK_ERROR)
return 0;
if (current == ABSENT && old == FIRST)
return recover(next);
if (current == SECOND && next == ABSENT)
{
printf("ATLAS ALREADY UPDATED\n%s\n", live[3]);
return 1;
}
if (current == ABSENT && old == ABSENT && next == ABSENT)
{
if (!writeCards(LIVE, original) || inspect(LIVE, live) != FIRST ||
memcmp(live, original, sizeof(original)) != 0)
return 0;
current = FIRST;
}
if (current != FIRST || old != ABSENT)
{
printf("CHECK THE THREE ATLAS FILES\n");
return 0;
}
reviseMars(live); // Only the copy in RAM has changed.
if (next == ABSENT)
{
if (!writeCards(DRAFT, live))
return 0;
next = inspect(DRAFT, draft);
}
if (next != SECOND || memcmp(live, draft, sizeof(original)) != 0)
{
printf("CHECK ATLAS.NEW\n");
return 0;
}
// Both files are closed. At this checkpoint the old edition is complete
// under BACKUP, and the new edition is complete under DRAFT.
if (rename(LIVE, BACKUP) != 0)
return 0;
printf("BACKUP IN PLACE\nPRESS A KEY TO INSTALL\n");
waitkey(0);
if (rename(DRAFT, LIVE) != 0)
return 0;
printf("UPDATED ATLAS SAVED\n%s\n", draft[3]);
return 1;
}
int main(void)
{
cls(1);
printf("PLANET ATLAS BACKUP\n");
if (saveAtlas())
return 0;
printf("SAVE STOPPED - CHECK DISK\n");
return 1;
}
+41
View File
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Draw a small landing beacon on a CoCo 3. Link bgraph. */
#include <coco.h>
#include <Primitive.h>
/* BGraph's 320x16 routines use 160 bytes per row. We need just 13 rows. */
enum { SIDE = 13, MIDDLE = 6, STRIDE = 160, INK = 3 };
static byte stamp[SIDE * STRIDE];
int main(void)
{
byte x, y;
byte *slots = (byte *) 0xFFB0;
byte oldPaper = slots[0] & 63, oldInk = slots[INK] & 63;
if (!hscreen(2))
return 1;
paletteRGB(0, 0, 0, 0);
paletteRGB(INK, 3, 3, 3);
for (x = 0; x < SIDE; ++x)
{
Primitive_setPixel320x16(x, MIDDLE, INK, stamp);
Primitive_setPixel320x16(MIDDLE, x, INK, stamp);
}
/* Let Disk BASIC find the visible page. Magnify each stamp dot 3 by 3. */
for (y = 0; y < SIDE; ++y)
for (x = 0; x < SIDE; ++x)
{
byte dx, dy;
byte color = Primitive_getPixel320x16(x, y, stamp);
for (dy = 0; dy < 3; ++dy)
for (dx = 0; dx < 3; ++dx)
hset(140 + 3 * x + dx, 76 + 3 * y + dy, color);
}
waitkey(FALSE);
hscreen(0);
palette(0, oldPaper);
palette(INK, oldInk);
printf("BEACON CENTER: %u\n", (unsigned) Primitive_getPixel320x16(MIDDLE, MIDDLE, stamp));
return 0;
}
+39
View File
@@ -0,0 +1,39 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Count a delivery on two planets. The manifest stays in guest RAM. */
#include <cmoc.h>
#include <coco.h>
struct Shipment
{
const char *destination;
byte crates;
byte mealsPerCrate;
};
static const struct Shipment manifest[] =
{
{ "EARTH", 12, 20 },
{ "MARS", 8, 15 }
};
/* A pointer lets us read one row without copying the whole structure. */
static word mealsFor(const struct Shipment *shipment)
{
return (word) shipment->crates * shipment->mealsPerCrate;
}
int main(void)
{
word total = 0;
byte row;
width(40);
for (row = 0; row < sizeof(manifest) / sizeof(manifest[0]); ++row)
{
word meals = mealsFor(&manifest[row]);
printf("%s: %u MEALS\n", manifest[row].destination, meals);
total += meals;
}
printf("TOTAL: %u MEALS\n", total);
return 0;
}
+43
View File
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Crew log: each seat holds 1 when occupied and 0 when empty. */
#include <cmoc.h>
#include <stdlib.h>
static unsigned char storage[96];
int main(void)
{
unsigned char *seats, *larger;
if (!vcc_heap_init(storage, sizeof(storage)))
return 1;
seats = (unsigned char *) calloc(2, sizeof(*seats));
if (!seats)
return 1;
printf("CREW AT LAUNCH: %u\n", (unsigned)(seats[0] + seats[1]));
seats[0] = seats[1] = 1;
/* Keep the current seat list until we know it can grow. */
larger = (unsigned char *) realloc(seats, 3);
if (!larger)
{
free(seats);
return 1;
}
seats = larger;
seats[2] = 1;
printf("CREW AFTER GROWTH: %u\n", (unsigned)(seats[0] + seats[1] + seats[2]));
/* The request exceeds the entire 96-byte budget. */
larger = (unsigned char *) realloc(seats, 200);
if (larger)
{
free(larger);
return 1;
}
printf("NO ROOM FOR 200\n");
printf("CREW STILL ABOARD: %u\n", (unsigned)(seats[0] + seats[1] + seats[2]));
free(seats);
printf("CREW LOG CLOSED\n");
return 0;
}
+12
View File
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* The deck count belongs to the caller. Link cardgame. */
#include <cardgame.h>
int main(void)
{
byte deck[3] = { 1, 2, 3 };
byte count = 3;
byte drawn = pickCardFromDeck(deck, &count);
printf("DREW %u, %u LEFT\n", (unsigned) drawn, (unsigned) count);
return 0;
}
+44
View File
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Descent Computer. Use the CoCo BASIC float backend and link vcccompat. */
#include <cmoc.h>
#include <coco.h>
#include <vcc/decimal.h>
/* Print a complete instrument reading or mark the field unavailable. */
static void reading(const char *label, float value, byte places, const char *unit)
{
char field[12];
int length = vcc_fixed(field, sizeof(field), value, places);
if (length < 0 || (unsigned)length >= sizeof(field))
printf("%s--- %s\n", label, unit);
else
printf("%s%s %s\n", label, field, unit);
}
static void report(float firstHeight, float lastHeight, float seconds)
{
float speed;
if (seconds <= 0.0f) {
printf("CHECK RADAR INTERVAL\n");
return;
}
/* Falling gives a negative speed. Keep the full value for the estimate. */
speed = (lastHeight - firstHeight) / seconds;
reading("HEIGHT ", lastHeight, 2, "M");
reading("SPEED ", speed, 2, "M/S");
if (speed < 0.0f)
reading("ETA ", lastHeight / -speed, 1, "S");
else
printf("ETA NO DESCENT\n");
}
int main(void)
{
cls(1);
printf("DESCENT COMPUTER\n\n");
/* Two radar heights in metres, measured two seconds apart. */
report(105.50f, 101.75f, 2.0f);
printf("\nRADAR PASS COMPLETE\n");
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Insert two keys into a tiny terminal editor. Link ebitor. */
#include <Ebitor.h>
#include <sg4term.h>
static byte readKey(void *cookie)
{
return inkey();
}
int main(void)
{
char log[32] = "";
ebitor_Window window = { 32, 15, 0, 0, 0, 0 };
width(32);
sg4term_init((char *) 0x0400, &window, readKey, NULL, (word *) 0x0112);
Ebitor_init(log, sizeof(log), 32, 15, sg4term_clear, sg4term_locate,
sg4term_getCursorPos, sg4term_print, sg4term_printPrefix,
sg4term_clrtoeol, sg4term_scrollWindowUp, sg4term_scrollWindowDown,
sg4term_waitEditorKey);
Ebitor_setContentLength(0);
Ebitor_locateCursorAtSavedPosition();
Ebitor_processKey('O');
Ebitor_processKey('K');
Ebitor_processKey(ebitor_KEY_ARROW_LEFT); /* Commit the inserted run and move left. */
Ebitor_saveCursorPosition();
unsigned count = Ebitor_getContentLength();
Ebitor_shutdown();
cls(255);
log[count] = 0; /* Two characters fit comfortably in our buffer. */
printf("LOG: %s\n", log);
return 0;
}
+67
View File
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Work on a practice disk. Each run starts a new FIELD.LOG on drive 0.
#include <coco.h>
#include <stdio.h>
#define LOG_NAME "FIELD.LOG:0"
/* Each reader starts at the beginning and sees the length saved on disk. */
static int showLog(void)
{
char line[40];
FILE *reader = fopen(LOG_NAME, "r");
int ok;
if (!reader)
return 0;
while (fgets(line, sizeof(line), reader))
printf("%s", line);
ok = !ferror(reader);
if (fclose(reader) == EOF)
ok = 0;
return ok;
}
int main(void)
{
FILE *writer;
int ok;
cls(1);
printf("PLANET FIELD LOG\n");
writer = fopen(LOG_NAME, "w");
if (!writer)
{
printf("CANNOT START FIELD.LOG\n");
return 1;
}
/* Publish the first observation while we still hold the writer. */
ok = fputs("EARTH: BLUE SEA\n", writer) != EOF && fflush(writer) == 0;
if (ok)
{
printf("CHECKPOINT READER SEES:\n");
ok = showLog();
}
if (ok)
{
printf("SPACE TO LAND ON MARS\n");
while (waitkey(0) != ' ') {}
ok = fputs("MARS: RED RIDGE\n", writer) != EOF;
}
/* Closing delivers the second observation and releases the stream. */
if (fclose(writer) == EOF)
ok = 0;
if (!ok)
{
printf("CHECK DISK AND LOG\n");
return 1;
}
printf("FINAL READER SEES:\n");
if (!showLog())
{
printf("CANNOT READ FIELD.LOG\n");
return 1;
}
printf("SURVEY FILED\n");
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
10 OPEN "I",#-1,"FLIGHT"
20 IF EOF(-1) THEN 60
30 LINE INPUT #-1,A$
40 PRINT A$
50 GOTO 20
60 CLOSE #-1
70 PRINT "END OF FLIGHT"
+52
View File
@@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Give Mission Control two observations it can read back in recording order.
#include <coco.h>
#include <vcc/cassette.h>
static int recordFlight(void)
{
int status = vcc_tape_open_write("FLIGHT");
if (status != VCC_TAPE_OK)
return status;
status = vcc_tape_write_line("EARTH BLUE SEA");
if (status == VCC_TAPE_OK)
status = vcc_tape_write_line("MARS RED RIDGE");
/* Closing writes the end-of-file block on a successful recording. */
int closed = vcc_tape_close();
return status == VCC_TAPE_OK ? closed : status;
}
static int replayFlight(void)
{
char observation[32];
int status = vcc_tape_open_read("FLIGHT");
if (status != VCC_TAPE_OK)
return status;
while ((status = vcc_tape_read_line(observation, sizeof observation)) == VCC_TAPE_OK)
printf("%s\n", observation);
int closed = vcc_tape_close();
/* A damaged last block also stops the loop. Only EOF completes the flight. */
return status == VCC_TAPE_EOF ? closed : status;
}
int main(void)
{
cls(1);
printf("FLIGHT RECORDER\n");
printf("W WRITE R READ\n");
char choice;
do {
choice = waitkey(0);
} while (choice != 'W' && choice != 'w' && choice != 'R' && choice != 'r');
int write = choice == 'W' || choice == 'w';
int status = write ? recordFlight() : replayFlight();
if (status != VCC_TAPE_OK) {
printf("TAPE ERROR %d\n", status);
return 1;
}
printf("%s\n", write ? "FLIGHT SAVED" : "END OF FLIGHT");
return 0;
}
+33
View File
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Send a text report through the CoCo printer port. No disk file is needed.
#include <coco.h>
#include <vcc/printer.h>
static int printLanding(unsigned visit, const char *planet, const char *observation)
{
/* Two digits for the visit, a five-character field for the planet. */
return vcc_printer_printf("%02u %-5s %s\n", visit, planet, observation);
}
int main(void)
{
cls(1);
printf("FLIGHT CONTROL\n");
printf("START CAPTURE IN PRINTER OUTPUT\n");
printf("PRESS SPACE TO SEND REPORT\n");
while (waitkey(0) != ' ') {}
/* Ordinary printf still goes to the screen. These four lines go to the port. */
if (vcc_printer_printf("TP-10 FLIGHT REPORT\n") < 0 ||
printLanding(1, "EARTH", "BLUE SEA") < 0 ||
printLanding(2, "MARS", "RED RIDGE") < 0 ||
vcc_printer_printf("END OF REPORT\n") < 0)
{
printf("REPORT FORMAT ERROR\n");
return 1;
}
/* The guest cannot tell whether the Mac is capturing the port. */
printf("REPORT SENT TO PRINTER PORT\n");
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
10 OPEN "O",#-1,"FLIGHT"
20 PRINT #-1,"EARTH TIDE POOL"
30 PRINT #-1,"MARS DUST DEVIL"
40 CLOSE #-1
50 PRINT "FLIGHT SAVED"
+84
View File
@@ -0,0 +1,84 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Stereo Flyby. Link orch90, input and bcontrol, in that order. */
#include <cmoc.h>
#include <coco.h>
#include <vcc/input.h>
#include <vcc/orch90.h>
#define FRAMES 2048
#define FIRST_COLUMN 2
#define LAST_COLUMN 29
#define STAR_ROW 8
#define SHIP_ROW 10
/* Keep the sample in guest RAM for as long as the interrupt can read it. */
static struct orch90_frame beacon[FRAMES];
static void makeBeacon(void)
{
static const byte wave[] = {
128, 146, 162, 172, 176, 172, 162, 146,
128, 110, 94, 84, 80, 84, 94, 110
};
unsigned i;
for (i = 0; i < FRAMES; ++i) {
/* The first note comes from the left. The right note is an octave up.
128 in both channels is the quiet space between notes. */
beacon[i].left = i < 768 ? wave[i & 15] : 128;
beacon[i].right = i >= 1024 && i < 1792 ? wave[(i << 1) & 15] : 128;
}
}
static void mark(byte column, byte row, char symbol)
{
locate(column, row);
putchar(symbol);
}
int main(void)
{
VccInput stick;
unsigned lastUpdate, now;
byte ship = 15, star = LAST_COLUMN, key;
width(32);
cls(1);
makeBeacon();
input_init(&stick, INPUT_RIGHT);
printf("STEREO FLYBY\n\n1 TRANSMIT BEACON\nRIGHT STICK STEER Q QUIT\n");
locate(1, 7); printf("+----------------------------+");
locate(1, 12); printf("+----------------------------+");
mark(ship, SHIP_ROW, '^');
mark(star, STAR_ROW, '*');
lastUpdate = getTimer();
for (;;) {
key = inkey();
if (key == 'Q' || key == 'q')
break;
if (key == '1' && !orch90_active()) {
locate(0, 5);
if (orch90_start(beacon, FRAMES, 1, ORCH90_CLOCK_NORMAL))
printf("BEACON ON AIR");
else
printf("PLAYBACK UNAVAILABLE");
}
/* The guest clock drives the flight display. Audio advances between
updates, even when this loop is busy drawing or reading input. */
now = getTimer();
if ((unsigned)(now - lastUpdate) < 4)
continue;
lastUpdate = now;
input_sample(&stick);
mark(ship, SHIP_ROW, ' ');
if (stick.dx < 0 && ship > FIRST_COLUMN) --ship;
if (stick.dx > 0 && ship < LAST_COLUMN) ++ship;
mark(ship, SHIP_ROW, '^');
mark(star, STAR_ROW, ' ');
star = star == FIRST_COLUMN ? LAST_COLUMN : star - 1;
mark(star, STAR_ROW, '*');
}
orch90_stop();
locate(0, 14);
printf("FLYBY COMPLETE\n");
return 0;
}
+25
View File
@@ -0,0 +1,25 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Draw letters in the four graphics pages reserved by fresh Disk BASIC. Link hirestxt. */
#include <hirestxt.h>
int main(void)
{
struct HiResTextScreenInit2 setup;
byte *page = (byte *) ((word) * (byte *) 0x00BC << 8);
memset(&setup, 0, sizeof(setup));
setup.init.numColumns = 51;
setup.init.writeCharAtFuncPtr = writeCharAt_51cols;
setup.init.textScreenBuffer = page;
setup.init.timer = (word *) 0x0112; /* BASIC's 60 Hz clock */
if (!pmode(4, page))
return 1;
pcls(0);
screen(1, 1);
initHiResTextScreen2(&setup);
writeString("MARS STATION");
waitkey(FALSE);
closeHiResTextScreen();
screen(0, 0);
printf("BACK FROM THE GRAPHICS PAGE\n");
return 0;
}
+121
View File
@@ -0,0 +1,121 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Land on the gold pad. Link gime, bgraph and bcontrol. */
#include <vcc/gime.h>
#include <Primitive.h>
#include <Joystick.h>
enum { SPACE, WHITE, CYAN, GOLD, FLAME, BLUE, VIOLET };
enum { CRAFT_W = 20, CRAFT_H = 16, PAD_LEFT = 220, PAD_RIGHT = 270 };
typedef struct { unsigned x, y; } Position;
/* BGraph supplies the line algorithm. Send each pixel to the hidden page. */
static void pixel(word x, byte y, byte color, void *unused)
{
(void) unused;
gime_plot(x, y, color);
}
static void landscape(void)
{
static const byte ridge[] = {183, 167, 177, 161, 176, 170, 184, 165, 177, 168};
unsigned i; /* Star and ridge x coordinates extend beyond 255. */
/* gime_open cleared both pages to SPACE before the first frame. */
for (i = 0; i < 22; ++i)
gime_plot(7 + i * 14, 8 + (i * 13) % 34, WHITE);
/* The crescent and stars sit above the flight area. */
gime_fill_rect(258, 18, 12, 2, GOLD);
gime_fill_rect(254, 20, 6, 10, GOLD);
gime_fill_rect(258, 30, 12, 2, GOLD);
gime_fill_rect(0, 184, GIME_WIDTH, GIME_HEIGHT - 184, BLUE);
for (i = 0; i < 9; ++i)
Primitive_line(i * 35, ridge[i], (i + 1) * 35, ridge[i + 1], VIOLET, pixel, 0);
gime_fill_rect(PAD_LEFT, 160, PAD_RIGHT - PAD_LEFT, 2, GOLD);
gime_fill_rect(PAD_LEFT + 3, 162, 2, 12, CYAN);
gime_fill_rect(PAD_RIGHT - 5, 162, 2, 12, CYAN);
}
static void drawCraft(unsigned x, unsigned y)
{
gime_fill_rect(x + 7, y, 6, 2, WHITE);
gime_fill_rect(x + 5, y + 2, 10, 5, CYAN);
gime_fill_rect(x + 8, y + 3, 4, 3, BLUE);
gime_fill_rect(x + 2, y + 7, 16, 4, WHITE);
gime_fill_rect(x + 3, y + 11, 2, 4, GOLD);
gime_fill_rect(x + 15, y + 11, 2, 4, GOLD);
gime_fill_rect(x, y + 15, 5, 1, WHITE);
gime_fill_rect(x + 15, y + 15, 5, 1, WHITE);
gime_fill_rect(x + 8, y + 11, 4, 3, FLAME);
}
static int direction(byte axis, byte lowProbe, byte lowBit, byte highProbe, byte highBit)
{
/* When a key is held, it takes precedence over this joystick axis. */
if (isKeyPressed(lowProbe, lowBit))
return -2;
if (isKeyPressed(highProbe, highBit))
return 2;
Joystick_selectAnalogMuxInputs(axis);
if (!Joystick_compareAxis(16))
return -2;
return Joystick_compareAxis(48) ? 2 : 0;
}
static unsigned move(int value, int delta, int minimum, int maximum)
{
value += delta;
if (value < minimum) return minimum;
if (value > maximum) return maximum;
return value;
}
int main(void)
{
Position craft = {144, 82}, previous[2];
byte page = 0, initialized = 0, landed = 0, presented = 1;
static const byte colors[] = {0x00, 0x3F, 0x1B, 0x34, 0x26, 0x08, 0x29};
byte i;
if (!gime_open())
{
printf("USE A SUPPORTED COCO 3 BASIC SETUP\n");
return 1;
}
for (i = 0; i < sizeof(colors); ++i)
gime_set_palette(i, colors[i]);
Joystick_disableSound();
while (!isKeyPressed(KEY_PROBE_Q, KEY_BIT_Q))
{
if (initialized < 2)
{
landscape(); /* Each physical page gets the scenery once. */
++initialized;
}
else
gime_fill_rect(previous[page].x, previous[page].y, CRAFT_W, CRAFT_H, SPACE);
craft.x = move(craft.x, direction(0, KEY_PROBE_A, KEY_BIT_A, KEY_PROBE_D, KEY_BIT_D), 0, GIME_WIDTH - CRAFT_W);
craft.y = move(craft.y, direction(1, KEY_PROBE_W, KEY_BIT_W, KEY_PROBE_S, KEY_BIT_S), 44, 160 - CRAFT_H);
drawCraft(craft.x, craft.y);
previous[page] = craft; /* Where to erase when this page comes around again. */
presented = gime_present();
if (!presented)
break;
page ^= 1;
if (craft.y == 160 - CRAFT_H && craft.x >= PAD_LEFT && craft.x + CRAFT_W <= PAD_RIGHT)
{
landed = 1;
break;
}
}
Joystick_selectAnalogMuxInputs(0);
Joystick_enableSound();
gime_close();
if (!presented)
{
printf("DISPLAY TIMING UNAVAILABLE\n");
return 1;
}
printf("%s\n", landed ? "ON THE PAD!" : "FLIGHT ENDED");
return 0;
}
+23
View File
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Fit a call sign on a four-character cargo tag. Default CMOC runtime. */
#include <cmoc.h>
static int setTag(char *tag, size_t capacity, const char *name)
{
size_t length = strlen(name);
if (length >= capacity)
return 0; /* Leave the previous tag intact. */
memcpy(tag, name, length + 1); /* Copy the terminating zero as well. */
return 1;
}
int main(void)
{
char tag[5] = "";
if (!setTag(tag, sizeof(tag), "MARS"))
return 1;
printf("TAG: %s, LETTERS: %u\n", tag, (unsigned) strlen(tag));
if (!setTag(tag, sizeof(tag), "EARTH") && strcmp(tag, "MARS") == 0)
printf("EARTH TOO LONG. KEPT %s\n", tag);
return 0;
}
+23
View File
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Count on the pool to reject a request larger than its region. Link wydealloc. */
#include <wydealloc.h>
#include <cmoc.h>
static unsigned char storage[64];
int main(void)
{
MemPool pool;
void *small, *tooBig;
if (!MemPool_init(&pool, storage, storage + sizeof(storage)))
return 1;
small = MemPool_alloc(&pool, 8);
tooBig = MemPool_alloc(&pool, 80);
printf("SMALL %s, LARGE %s\n", small ? "OK" : "FAILED", tooBig ? "OK" : "REFUSED");
MemPool_free(&pool, small);
MemPool_free(&pool, tooBig);
small = MemPool_alloc(&pool, 8);
printf("AFTER FREE: %s\n", small ? "OK" : "FAILED");
MemPool_free(&pool, small);
return 0;
}
+117
View File
@@ -0,0 +1,117 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Survey the gold deposit. Link gime, input and bcontrol. */
#include <coco.h>
#include <vcc/gime.h>
#include <vcc/input.h>
enum { SKY, WHITE, CYAN, GOLD, MAGENTA, ROCK, SHADOW };
enum { LAUNCH_Y = 66, DEPOSIT_X = 216, DEPOSIT_Y = 152, MAX_CHARGE = 16 };
typedef struct {
unsigned shipX, probeX;
byte probeY; /* Zero when no probe is in flight. */
} Flight;
/* The craft and probe fly through clear sky, so a hidden page can erase
its previous sprites without saving any of the scenery beneath them. */
static void scenery(void)
{
static const byte horizon[] = {172, 170, 168, 171, 174, 175, 179, 180, 178, 173,
170, 166, 162, 165, 172, 176, 180, 177, 174, 171};
unsigned i;
for (i = 0; i < 20; ++i) {
unsigned x = i * 16;
unsigned top = horizon[i];
gime_fill_rect(x, top, 16, 192 - top, ROCK);
gime_fill_rect(x, top, 16, 1, MAGENTA);
if (i % 3 == 0) gime_fill_rect(x + 6, top + 6, 7, 2, SHADOW);
gime_plot(x + 4, 20 + i * 7 % 23, WHITE);
}
gime_fill_rect(264, 15, 8, 2, GOLD); /* Crescent over the landing site. */
gime_fill_rect(261, 17, 3, 7, GOLD);
gime_fill_rect(264, 24, 8, 2, GOLD);
gime_fill_rect(DEPOSIT_X + 2, DEPOSIT_Y + 3, 4, 11, CYAN);
gime_fill_rect(DEPOSIT_X + 20, DEPOSIT_Y + 3, 4, 22, CYAN);
gime_fill_rect(7, 7, 52, 8, WHITE); /* Charge gauge surround. */
}
static void drawShip(unsigned x)
{
gime_fill_rect(x + 6, 49, 8, 2, WHITE);
gime_fill_rect(x + 4, 51, 12, 6, CYAN);
gime_fill_rect(x + 8, 52, 5, 3, SHADOW);
gime_fill_rect(x, 57, 20, 4, WHITE);
gime_fill_rect(x + 2, 61, 3, 3, GOLD);
gime_fill_rect(x + 15, 61, 3, 3, GOLD);
}
int main(void)
{
static const byte colors[] = {0x00, 0x3f, 0x1b, 0x34, 0x29, 0x08, 0x01};
VccInput stick;
Flight now = {144, 0, 0}, old[2];
unsigned launched = 0;
byte ready = 0, charge = 0, limit = 0, charging = 0, found = 0;
byte page = 0, freshPages = 2, i;
if (!gime_open()) {
printf("USE COCO 3 BASIC WITH 512K OR MORE\n");
return 1;
}
for (i = 0; i < sizeof(colors); ++i) gime_set_palette(i, colors[i]);
input_init(&stick, INPUT_RIGHT);
while (!isKeyPressed(KEY_PROBE_Q, KEY_BIT_Q)) {
input_sample(&stick); /* One sample for this entire update. */
if (stick.dx < 0 && now.shipX >= 2) now.shipX -= 2;
if (stick.dx > 0 && now.shipX < GIME_WIDTH - 20) now.shipX += 2;
if (stick.pressed & INPUT_PRIMARY) {
++launched; /* Start one new probe at the craft. */
now.probeX = now.shipX + 9;
now.probeY = LAUNCH_Y;
limit = LAUNCH_Y + 24 + 4 * ready;
charge = 0;
charging = 1;
} else if (now.probeY) {
if (now.probeY >= limit) now.probeY = 0;
else now.probeY += 2;
}
if (charging && (stick.held & INPUT_PRIMARY) && charge < MAX_CHARGE)
++charge; /* Build energy for the NEXT probe. */
if (charging && (stick.released & INPUT_PRIMARY)) {
ready = charge; /* Lock in the range for the next press. */
charging = 0;
}
if (now.probeY + 3 >= DEPOSIT_Y && now.probeX >= DEPOSIT_X &&
now.probeX < DEPOSIT_X + 26) {
found = 1;
now.probeY = 0;
}
if (freshPages) {
scenery();
--freshPages;
} else {
gime_fill_rect(old[page].shipX, 49, 20, 15, SKY);
if (old[page].probeY)
gime_fill_rect(old[page].probeX, old[page].probeY, 2, 4, SKY);
}
drawShip(now.shipX);
if (now.probeY) gime_fill_rect(now.probeX, now.probeY, 2, 4, CYAN);
gime_fill_rect(DEPOSIT_X, DEPOSIT_Y, 26, 3, found ? CYAN : GOLD);
gime_fill_rect(9, 9, 48, 4, SHADOW);
gime_fill_rect(9, 9, 3 * (charging ? charge : ready), 4, charging ? GOLD : CYAN);
old[page] = now;
if (!gime_present()) {
gime_close();
printf("DISPLAY TIMING UNAVAILABLE\n");
return 1;
}
page ^= 1;
}
gime_close();
printf("PROBES LAUNCHED: %u\n", launched);
if (found) printf("DEPOSIT SURVEYED\n");
return 0;
}
+106
View File
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Run twice on the same practice disk. Each flight adds one observation.
#include <coco.h>
#include <decbfile.h>
#include <stdio.h>
#include <string.h>
#define LOG_NAME "TRIP.LOG:0"
static int fly(FILE *log)
{
char line[32];
unsigned visits = 0;
const char *planet;
/* a+ opens even a new log at byte zero so we can read earlier flights. */
while (fgets(line, sizeof(line), log))
{
if ((visits == 0 && strcmp(line, "VISIT 1: EARTH\n") == 0) ||
(visits == 1 && strcmp(line, "VISIT 2: MARS\n") == 0))
++visits;
else
{
printf("UNRECOGNIZED TRIP.LOG\n");
return 0;
}
}
if (ferror(log))
return 0;
if (visits == 2)
{
printf("BOTH VISITS ALREADY FILED\n");
return 1;
}
/* Move the cursor to the first record. With a+, output still appends. */
if (fseek(log, 0L, SEEK_SET) != 0)
return 0;
planet = visits ? "MARS" : "EARTH";
printf("AT BYTE ZERO\nFILING %s\n", planet);
if (fprintf(log, "VISIT %u: %s\n", visits + 1, planet) < 0)
return 0;
/* This short record is buffered. Keep the stream open if saving fails. */
while (fflush(log) == EOF)
{
char key;
if (ferror(log) != DECB_ERR_IO)
return 0;
printf("SAVE FAILED\nKEEP THE SAME DISK IN DRIVE 0\n");
printf("IF PROTECTED, TURN PROTECT OFF\nR: RETRY Q: QUIT\n");
do {
key = waitkey(0);
} while (key != 'R' && key != 'r' && key != 'Q' && key != 'q');
if (key == 'Q' || key == 'q')
return 0;
/* Retry just the flush. Printing the observation again could duplicate it. */
clearerr(log);
printf("RETRYING SAVE\n");
}
return 1;
}
int main(void)
{
FILE *log;
char line[32];
int ok;
cls(1);
printf("RETURN TRIP\n");
log = fopen(LOG_NAME, "a+");
if (!log)
{
printf("CANNOT OPEN TRIP.LOG\n");
return 1;
}
ok = fly(log);
/* Check the result of closing the stream, even after an explicit flush. */
if (fclose(log) == EOF)
ok = 0;
if (!ok)
{
printf("CHECK DISK AND LOG\n");
return 1;
}
/* A new reader shows what the next flight will find on the disk. */
log = fopen(LOG_NAME, "r");
if (!log)
{
printf("CANNOT REOPEN TRIP.LOG\n");
return 1;
}
printf("REOPENED TRIP.LOG\n");
while (fgets(line, sizeof(line), log))
printf("%s", line);
ok = !ferror(log);
if (fclose(log) == EOF)
ok = 0;
if (!ok)
{
printf("CANNOT READ TRIP.LOG\n");
return 1;
}
return 0;
}
+130
View File
@@ -0,0 +1,130 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Two landscapes, one working array. Link bank, gime and hirestxt. */
#include <coco.h>
#include <font5x8.h>
#include <vcc/bank.h>
#include <vcc/gime.h>
enum { COLUMNS = 20, FIRST_COLUMN = 10, FLOOR = 169 };
enum { NIGHT, INK, WHITE, GOLD, WINDOW, EARTH_FAR, EARTH_SOIL, EARTH_EDGE,
MARS_FAR, MARS_SOIL, MARS_EDGE };
static const byte earth[COLUMNS] = {
128, 122, 116, 120, 132, 140, 136, 128, 122, 126,
132, 140, 146, 138, 134, 122, 112, 120, 132, 140
};
static const byte mars[COLUMNS] = {
156, 146, 132, 128, 140, 154, 150, 140, 142, 148,
152, 146, 136, 126, 118, 130, 142, 154, 146, 138
};
/* Pierre Sarrazin's HiresText font has five ink columns, encoded as zero bits. */
static void label(unsigned x, byte y, const char *text)
{
while (*text) {
const byte *glyph = font5x8 + ((unsigned)*text++ - ' ') * 8;
byte row, col;
for (row = 0; row < 8; ++row)
for (col = 0; col < 5; ++col)
if (!(glyph[row] & (0x80 >> col)))
gime_plot(x + col, y + row, WHITE);
x += 6;
}
}
static byte draw(const byte *ridge, byte onMars, byte column)
{
char reading[10]; /* "RIDGE $FF" and its terminator. */
unsigned i, x = column * 16;
byte farRock = onMars ? MARS_FAR : EARTH_FAR;
byte soil = onMars ? MARS_SOIL : EARTH_SOIL;
byte edge = onMars ? MARS_EDGE : EARTH_EDGE;
gime_clear(NIGHT);
for (i = 0; i < COLUMNS; ++i) {
unsigned left = i * 16;
unsigned farY = 101 + ((i * 7 + (onMars ? 19 : 5)) % 27);
gime_plot(left + 3, 31 + i * 11 % 43, WHITE);
gime_fill_rect(left, farY, 16, FLOOR - farY, farRock);
gime_fill_rect(left, ridge[i], 16, FLOOR - ridge[i], soil);
gime_fill_rect(left, ridge[i], 16, 2, edge);
if ((i & 1) == 0 && ridge[i] + 9 < FLOOR)
gime_fill_rect(left + 3, ridge[i] + 8, 6, 1, farRock);
}
/* A crescent hangs above the distant range. */
gime_fill_rect(259, 28, 8, 2, edge);
gime_fill_rect(256, 30, 4, 8, edge);
gime_fill_rect(259, 38, 8, 2, edge);
/* A small survey craft and the sounding line beneath it. */
for (i = 67; i < ridge[column]; i += 6)
gime_plot(x + 8, i, GOLD);
gime_fill_rect(x + 5, 51, 8, 5, WINDOW);
gime_fill_rect(x + 2, 56, 13, 3, WHITE);
gime_fill_rect(x, 59, 16, 3, edge);
gime_fill_rect(x + 4, 62, 2, 3, GOLD);
gime_fill_rect(x + 11, 62, 2, 3, GOLD);
label(8, 8, onMars ? "MARS SURVEY" : "EARTH SURVEY");
sprintf(reading, "RIDGE $%02X", (unsigned)ridge[column]);
label(131, 8, reading);
label(258, 8, onMars ? "BANK $29" : "BANK $28");
gime_fill_rect(8, 19, 304, 1, edge);
gime_fill_rect(0, FLOOR, 320, 192 - FLOOR, INK);
label(8, 176, "A/D FLY SPACE SWAP R RAISE ON MARS Q QUIT");
return gime_present();
}
static byte survey(void)
{
byte ridge[COLUMNS], column = FIRST_COLUMN, onMars = 0;
unsigned offset;
/* Seed once. Changing planets must read the saved map, not reseed it. */
if (!bank_write(0, earth, COLUMNS) ||
!bank_write(BANK_PAGE_SIZE, mars, COLUMNS))
return 0;
for (;;) {
byte key;
offset = onMars ? BANK_PAGE_SIZE : 0u;
if (!bank_read(offset, ridge, COLUMNS) || !draw(ridge, onMars, column))
return 0;
do {
key = waitkey(0);
if (key >= 'a' && key <= 'z') key -= 'a' - 'A';
if (key == 'Q') return 1;
if (key == ' ') { onMars ^= 1; break; }
if (key == 'A' && column > 0) { --column; break; }
if (key == 'D' && column + 1 < COLUMNS) { ++column; break; }
if (key == 'R' && onMars && ridge[column] >= 96) {
/* Screen y grows downward. Save just the changed byte. */
ridge[column] -= 16;
if (!bank_write(offset + column, &ridge[column], 1))
return 0;
break;
}
} while (1);
}
}
int main(void)
{
static const byte colors[] = {
0x01, 0x00, 0x3f, 0x36, 0x1b, 0x0a, 0x15, 0x1e, 0x21, 0x26, 0x37
};
byte i, ok;
if (!bank_open()) {
printf("USE STANDARD COCO 3 BASIC WITH 512K OR MORE\n");
return 1;
}
if (!gime_open()) {
bank_close();
printf("GRAPHICS UNAVAILABLE\n");
return 1;
}
for (i = 0; i < sizeof(colors); ++i) gime_set_palette(i, colors[i]);
ok = survey();
gime_close();
bank_close();
printf("%s\n", ok ? "SURVEY COMPLETE" : "SURVEY TRANSFER OR DISPLAY FAILED");
return ok ? 0 : 1;
}
+22
View File
@@ -0,0 +1,22 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Three rooms in a straight corridor. Link astar. */
#include <astar.h>
int main(void)
{
AStarNode rooms[3];
AStarGraph map = { rooms, 3, 1 };
AStarPathIterator it;
AStarNode *room;
byte i;
for (i = 0; i < 3; ++i)
astar_initNode(rooms + i, NULL, i < 2, FALSE);
if (!astar_searchGrid(&map, 0, 0, 2, 0))
return 1;
astar_startPathIteration(&it, &map, 2, 0);
printf("BACK FROM GOAL:");
while ((room = astar_advancePathIteration(&it)) != NULL)
printf(" %u", (unsigned) (room - rooms));
printf("\n");
return 0;
}
+23
View File
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Fly the right stick to a position and press its first button. Link bcontrol. */
#include <Joystick.h>
int main(void)
{
byte axes[4] = { 0, 0, 0, 0 };
byte buttons;
word start;
printf("MOVE THE RIGHT STICK AND FIRE\n");
Joystick_disableSound();
start = getTimer();
do
{
buttons = Joystick_getButtonStates();
} while ((buttons & 1) && (word) (getTimer() - start) < 600);
Joystick_getAxisValues(axes, 0x03);
Joystick_selectAnalogMuxInputs(0);
Joystick_enableSound();
printf("RIGHT X=%u Y=%u\n", (unsigned) axes[0], (unsigned) axes[1]);
printf("BUTTON %s\n", (buttons & 1) ? "UP" : "DOWN");
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Sound a landing signal and give the interrupt vector back. Link bsound. */
#include <Player.h>
int main(void)
{
Player player;
printf("BEACON ON\n");
Player_init(&player, TRUE, NULL);
Player_sound(130, 12);
Player_shutdown();
printf("BEACON OFF\n");
return 0;
}
+29
View File
@@ -0,0 +1,29 @@
/* Earth or Mars -- one key chooses the greeting on a 40-column CoCo 3. */
#include <cmoc.h>
#include <coco.h>
int main(void)
{
byte choice;
width(40);
printf("What planet do you live on?\n1) Earth\n2) Mars\n");
do
{
choice = inkey(); /* No Enter needed. Ignore other keys. */
} while (choice != '1' && choice != '2');
attr(3, 6, FALSE, FALSE); /* White text on background slot 6. */
if (choice == '1')
{
palette(6, 10); /* Blue */
printf("Hello Nice Blue Dot World!\n");
}
else
{
palette(6, 37); /* Red */
printf("Hello Cold Red Dot World!\n");
}
attr(0, 0, FALSE, FALSE); /* Back to BASIC's usual colors. */
return 0;
}