From b317bb7d8ee16976c62acc2165ae8d8b31a49b2d Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 25 Jan 2022 21:28:46 -0500 Subject: [PATCH] rotate: happy accident --- graphics/hgr/sine/Makefile | 21 +++-- graphics/hgr/sine/rotate.s | 175 +++++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 graphics/hgr/sine/rotate.s diff --git a/graphics/hgr/sine/Makefile b/graphics/hgr/sine/Makefile index bcf5e1ee..8abcd7e5 100644 --- a/graphics/hgr/sine/Makefile +++ b/graphics/hgr/sine/Makefile @@ -8,7 +8,7 @@ EMPTYDISK = ../../../empty_disk/empty.dsk all: plasma_hgr.dsk plasma_hgr.dsk: HELLO APPROX_SINE THICK_SINE THICK_COS TABLE_SINE ROM_SINE \ - OOPS_COS OOPS2_COS OOPS3_COS OOPS4_COS + OOPS_COS OOPS2_COS OOPS3_COS OOPS4_COS ROTATE cp $(EMPTYDISK) plasma_hgr.dsk $(DOS33) -y plasma_hgr.dsk SAVE A HELLO $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 APPROX_SINE @@ -18,8 +18,9 @@ plasma_hgr.dsk: HELLO APPROX_SINE THICK_SINE THICK_COS TABLE_SINE ROM_SINE \ $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 THICK_COS $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS_COS $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS2_COS - $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS3_COS - $(DOS33) -y plasma_hgr.dsk BSAVE -a 0xc00 OOPS4_COS + $(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 OOPS3_COS + $(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 OOPS4_COS + $(DOS33) -y plasma_hgr.dsk BSAVE -a 0x3f5 ROTATE ### @@ -71,7 +72,7 @@ oops2_cos.o: oops2_cos.s ### OOPS3_COS: oops3_cos.o - ld65 -o OOPS3_COS oops3_cos.o -C $(LINKERSCRIPTS)/apple2_c00.inc + ld65 -o OOPS3_COS oops3_cos.o -C $(LINKERSCRIPTS)/apple2_3f5.inc oops3_cos.o: oops3_cos.s ca65 -o oops3_cos.o oops3_cos.s -l oops3_cos.lst @@ -79,13 +80,21 @@ oops3_cos.o: oops3_cos.s ### OOPS4_COS: oops4_cos.o - ld65 -o OOPS4_COS oops4_cos.o -C $(LINKERSCRIPTS)/apple2_c00.inc + ld65 -o OOPS4_COS oops4_cos.o -C $(LINKERSCRIPTS)/apple2_3f5.inc oops4_cos.o: oops4_cos.s ca65 -o oops4_cos.o oops4_cos.s -l oops4_cos.lst ### +ROTATE: rotate.o + ld65 -o ROTATE rotate.o -C $(LINKERSCRIPTS)/apple2_3f5.inc + +rotate.o: rotate.s + ca65 -o rotate.o rotate.s -l rotate.lst + +### + TABLE_SINE: table_sine.o ld65 -o TABLE_SINE table_sine.o -C $(LINKERSCRIPTS)/apple2_c00.inc @@ -105,5 +114,5 @@ rom_sine.o: rom_sine.s clean: rm -f *~ *.o *.lst THICK_SINE THICK_COS \ TABLE_SINE ROM_SINE APPROX_SINE \ - OOPS_COS OOPS2_COS OOPS3_COS OOPS4_COS + OOPS_COS OOPS2_COS OOPS3_COS OOPS4_COS ROTATE diff --git a/graphics/hgr/sine/rotate.s b/graphics/hgr/sine/rotate.s new file mode 100644 index 00000000..e222c0c5 --- /dev/null +++ b/graphics/hgr/sine/rotate.s @@ -0,0 +1,175 @@ +; rotate + +; zero page +sinetable=$70 +HGR_X = $E0 +HGR_XH = $E1 +HGR_Y = $E2 +HGR_COLOR = $E4 +HGR_PAGE = $E6 + + +FRAME = $FF + +PAGE1 = $C054 +PAGE2 = $C055 + +; ROM routines + +HGR2 = $F3D8 +HGR = $F3E2 +HPOSN = $F411 ; (Y,X),(A) (values stores in HGRX,XH,Y) +HPLOT0 = $F457 ; plot at (Y,X), (A) +costable_base = $F5BA +WAIT = $FCA8 + + ;================================ + ; Clear screen and setup graphics + ;================================ +thick_sine: + + jsr HGR +; jsr HGR2 ; set hi-res 140x192, page2, fullscreen + ; A and Y both 0 at end + +; try to get sine table from ROM + +rom_sine: + + ;========================================== + ; create sinetable using ROM cosine table + +; ldy #0 + ldx #$f +sinetable_loop: + + lda costable_base+1,Y +force_zero: + lsr ; rom value is *256 + lsr ; we want *32 +; lsr + + sta sinetable+$10,Y + sta sinetable+$00,X + eor #$FF + sec + adc #$0 + sta sinetable+$30,Y + sta sinetable+$20,X + + lda #0 ; hack, ROM cosine table doesn't + ; have a good zero for some reason + + iny + dex + + beq force_zero + bpl sinetable_loop + + ; x is FF at this point + + inx + stx FRAME + + jsr draw_sine + + + jsr HGR2 ; set hi-res 140x192, page2, fullscreen + ; A and Y both 0 at end + sty FRAME + inc invert_smc+1 + + jsr draw_sine + +flip_loop: + +; flip draw page $20/$40 + lda HGR_PAGE + eor #$60 + sta HGR_PAGE + + ; flip page + ; have $20/$40 want to map to C054/C055 + + asl + asl ; $20 -> C=1 $00 + asl ; $40 -> C=0 $00 + rol + tax + sta PAGE1,X + + lda #255 + jsr WAIT + + jmp flip_loop + + + + ;============================ + ; main loop + ;============================ + +draw_sine: + ; X is 0 here, either from above, or from end of loop + + ldx #0 ; HGR_X + + ; offset next time through + + inc FRAME + + ; X is zero here + + ; 10 bytes to flip color (was 14) + +; txa + lda #$FF + bit FRAME + bvc color_white + + rts + +; eor #$FF +color_white: + sta HGR_COLOR + + +circle_loop: + + ; get sine value + +invert_smc: + lda #$0 + beq skip_invert + + rol ; invert carry + eor #$01 + ror +skip_invert: + + lda FRAME + and #$3f ; wrap value to 0..63 + tay + lda sinetable,Y + + ; multiply by 2 and center on screen $60 is midscreen +; asl + +; clc + + adc #$60 + +; ldx HGR_X ; saved in HGR_X + ldy #0 ; saved in HGR_XH + jsr HPLOT0 ; plot at (Y,X), (A) + + inc FRAME + + ldx HGR_X + inx ; HGR_X + + bne circle_loop + + beq draw_sine + +