polly: automate sample

This commit is contained in:
Vince Weaver 2022-05-13 23:37:13 -04:00
parent 4fcefd0ad0
commit ccea46bc50
6 changed files with 398 additions and 8 deletions

View File

@ -12,7 +12,7 @@ all: scroller.dsk
$(DOS33):
cd ../../../utils/dos33fs-utils && make
scroller.dsk: $(DOS33) HELLO DIAMOND DIAMOND_BOT RANDOM RANDOM_BOT RANDOM_128
scroller.dsk: $(DOS33) HELLO DIAMOND DIAMOND_BOT RANDOM RANDOM_BOT RANDOM_128 RANDOM_FUN
cp $(EMPTY_DISK)/empty.dsk scroller.dsk
$(DOS33) -y scroller.dsk SAVE A HELLO
$(DOS33) -y scroller.dsk BSAVE -a 0xc00 DIAMOND
@ -20,6 +20,7 @@ scroller.dsk: $(DOS33) HELLO DIAMOND DIAMOND_BOT RANDOM RANDOM_BOT RANDOM_128
$(DOS33) -y scroller.dsk BSAVE -a 0xc00 RANDOM
$(DOS33) -y scroller.dsk BSAVE -a 0x36B RANDOM_BOT
$(DOS33) -y scroller.dsk BSAVE -a 0x70 RANDOM_128
$(DOS33) -y scroller.dsk BSAVE -a 0x70 RANDOM_FUN
###
HELLO: hello.bas
@ -59,6 +60,15 @@ random_128.o: random_128.s
###
RANDOM_FUN: random_fun.o
ld65 -o RANDOM_FUN random_fun.o -C $(LINKERSCRIPTS)/apple2_70_zp.inc
random_fun.o: random_fun.s
ca65 -o random_fun.o random_fun.s -l random_fun.lst
###
RANDOM_BOT: random_bot.o
ld65 -o RANDOM_BOT random_bot.o -C $(LINKERSCRIPTS)/apple2_36b.inc

View File

@ -0,0 +1,262 @@
; random scroll bot 128
; 141 bytes -- bot version
; 138 bytes -- no need for back jump
; 140 bytes -- load at 0x70
; 134 bytes -- enforce ZP addresses
; 133 bytes -- convert JMP to BPL
; 131 bytes -- make OUTL live in program
; 130 bytes -- use EOR instead of ADD
; 127 bytes -- don't wrap pattern lookup at 8
; 126 bytes -- use X for loop
; by Vince `deater` Weaver
SET_GR = $C050
SET_TEXT = $C051
FULLGR = $C052
PAGE1 = $C054
PAGE2 = $C055
LORES = $C056 ; Enable LORES graphics
HGR2 = $F3D8
PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved)
GBASCALC = $F847 ; Y in A, put addr in GBASL/GBASH
SETGR = $FB40
WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us
GBASL = $26
GBASH = $27
OUTL = $74
OUTH = $75
PAGE = $6E
LINE = $6F
pattern1 = $f000 ; location in memory
.zeropage
.globalzp pattern_smc
.globalzp bitmap
.globalzp bitmap2
.globalzp inner_loop_smc
random:
jsr SETGR ; set LORES ; 70 71 72
lda #0 ; also OUTL=0/OUTH ; 73 74
bit FULLGR ; set FULL 48x40 ; 75 76 77
; bit SETTEXT
main_loop:
sta PAGE ; start at page 1
asl ; make OUTH $4 or $8 depending on value in PAGE
; which we have in A above or at end of loop
asl ; C is 0
adc #4
sta OUTH
lda #200
jsr WAIT
;============================
; draw an interleaved line
full_loop:
ldx #3
line_loop:
ldy #119
screen_loop:
tya ; extrapolate X from Y
; and #$7 ; could be bigger?
; tax
pattern_smc:
lda pattern1,Y
inner_loop_smc:
sta (OUTL),Y
dey
bpl screen_loop
;=================================
; move to next pattern
scroll_pattern:
clc
lda pattern_smc+1
adc #8
and #$1f
sta pattern_smc+1
; move to next line by adding $80
; we save a byte by using EOR instead
lda OUTL
eor #$80 ; add $80
sta OUTL
bne line_loop
; we overflowed, so increment OUTH
inc OUTH
; lda OUTH ; check if at end
; and #$3
; bne line_loop
dex
bpl line_loop
done_bg:
;=======================================
; done drawing frame
;=======================================
;======================
; draw bitmap
ldx #7
boxloop:
txa
jsr GBASCALC ; calc address of X
; note we center to middle of screen
; by noting the middle 8 lines
; are offset by $28 from first 8 lines
; GBASL is in A at this point
clc
adc #12+$28
sta GBASL ; center x-coord and y-coord at same time
lda PAGE ; want to add 0 or 4 (not 0 or 1)
asl
asl ; this sets C to 0
adc GBASH
sta GBASH
ldy #15
draw_line_loop:
lda bitmap2,X ; get low bit of bitmap2 into carry
lsr
lda #$00 ; black is default color
ror bitmap,X ; 16-bit rotate (in memory)
ror bitmap2,X
bcc its_black
lda #$ff
its_black:
sta (GBASL),Y ; partway down screen
dey
bpl draw_line_loop
dex
bpl boxloop
;=========================
; scroll one line
; to scroll up need to add 8?
inc pattern_smc+1
; switch page
lda PAGE
tax
ldy PAGE1,X ; flip page
eor #$1
bpl main_loop ; bra
;012|456|012|456|
;@@@@@@@@@@@@@@@@'
;@@@@ @ @@@@@@'
;@@@@ @ @@@@@@@@@'
;@ @ @ @'
;@ @@ @@@@ @ @@@@'
;@ @ @ @@@@'
;@@@@@@@@@@@@@@@@'
;
bitmap:
.byte $FF ;,$FF
.byte $F4 ;,$3F
.byte $F5 ;,$FF
.byte $84 ;,$21
.byte $B7 ;,$AF
.byte $84 ;,$2F
.byte $FF ;,$FF
.byte $00 ;,$00
bitmap2:
.byte $FF
.byte $3F
.byte $FF
.byte $21
.byte $AF
.byte $2F
.byte $FF
.byte $00
;01234567|01234567
;
; @@@@ @@@@
; @@ @@
; @@ @@
; @@ @@
; @@@@ @@@@
;
;@@@@@@@@@@@@@@@@
.if 0
bitmap:
.byte $FF ;,$FF
.byte $E1 ;,$87
.byte $F9 ;,$9F
.byte $F9 ;,$9F
.byte $F9 ;,$9F
.byte $E1 ;,$87
.byte $FF ;,$FF
.byte $00 ;,$00
bitmap2:
.byte $FF
.byte $87
.byte $9F
.byte $9F
.byte $9F
.byte $87
.byte $FF
.byte $00
.endif

View File

@ -6,18 +6,18 @@ PNG_TO_40x48D = ../../utils/gr-utils/png_to_40x48d
PNG2RLE = ../../utils/gr-utils/png2rle
B2D = ../../utils/bmp2dhr/b2d
TOKENIZE = ../../utils/asoft_basic-utils/tokenize_asoft
EMPTY_DISK = ../../empty_disk/empty.dsk
all: polly.dsk
polly.dsk: HELLO POLLY BOOP
cp empty.dsk polly.dsk
polly.dsk: HELLO POLLY BOOP REPO
cp $(EMPTY_DISK) polly.dsk
$(DOS33) -y polly.dsk SAVE A HELLO
$(DOS33) -y polly.dsk BSAVE -a 0x1000 POLLY
$(DOS33) -y polly.dsk BSAVE -a 0x1000 BOOP
$(DOS33) -y polly.dsk BSAVE -a 0x1000 REPO
###
BOOP: boop.o
ld65 -o BOOP boop.o -C ../../linker_scripts/apple2_1000.inc
@ -35,6 +35,23 @@ polly.o: polly.s
###
decode_trace.o: decode_trace.c
$(CC) $(CFLAGS) -c decode_trace.c
decode_trace: decode_trace.o
$(CC) -o decode_trace decode_trace.o $(LFLAGS)
sample.inc: poly.trace decode_trace
./decode_trace < poly.trace > sample.inc
REPO: repo.o
ld65 -o REPO repo.o -C ../../linker_scripts/apple2_1000.inc
repo.o: repo.s sample.inc
ca65 -o repo.o repo.s -l repo.lst
###
HELLO: hello.bas
$(TOKENIZE) < hello.bas > HELLO
@ -42,6 +59,5 @@ HELLO: hello.bas
####
clean:
rm -f *~ *.o *.lst HELLO POLLY BOOP
rm -f *~ *.o *.lst HELLO POLLY BOOP REPO decode_trace

View File

@ -0,0 +1,57 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 16384
int main(int argc, char **argv) {
char string[BUFSIZ];
char *result;
long long cycles,oldcycles=0;
int speaker_access;
int count=0,which=0;
int diffs[MAX];
while(1) {
result=fgets(string,BUFSIZ,stdin);
if (result==NULL) break;
speaker_access=0;
sscanf(result,"%llx",&cycles);
if (strstr(result,"$C030")) speaker_access=1;
if (speaker_access) {
diffs[count]=cycles-oldcycles;
count++;
oldcycles=cycles;
}
if (count>=MAX-1) {
fprintf(stderr,"Error! Too big!\n");
exit(1);
}
}
/* now print low */
printf("low_values:\n");
for(which=0;which<count;which++) {
if ((which%16)==0) {
printf(".byte\t");
}
else {
printf(",");
}
printf("$%02X",diffs[which]&0xff);
if ((which%16)!=15) {
}
else {
printf("\n");
}
}
printf("\n.byte\t$FF\n");
return 0;
}

Binary file not shown.

45
music/polly/repo.s Normal file
View File

@ -0,0 +1,45 @@
; Soft Switches
KEYPRESS= $C000
KEYRESET= $C010
SPEAKER = $C030
repo:
ldy #0
repo_loop:
bit SPEAKER
addr_smc:
lda low_values,Y
cmp #$FF
beq done
jsr delay_a
clc
lda addr_smc+1
adc #1
sta addr_smc+1
lda #0
adc addr_smc+2
sta addr_smc+2
jmp repo_loop
done:
lda KEYPRESS
bpl done
bit KEYRESET
lda #<low_values
sta addr_smc+1
lda #>low_values
sta addr_smc+2
jmp repo
.include "sample.inc"
.align $100
.include "delay_a.s"