From e074a11bebcfa846600304e9af17eb7bbb030feb Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 16 Feb 2024 01:15:15 -0500 Subject: [PATCH] bubble: update codes --- graphics/hgr/bubble_universe/Makefile | 27 +- graphics/hgr/bubble_universe/bubble_c64.s | 291 +++++++++++++++ graphics/hgr/bubble_universe/bubble_slow.s | 354 ++++++++++++++++++ graphics/hgr/bubble_universe/fast_dots.s | 403 +++++++++++++++++++++ graphics/hgr/bubble_universe/make_table2.c | 59 +++ 5 files changed, 1131 insertions(+), 3 deletions(-) create mode 100644 graphics/hgr/bubble_universe/bubble_c64.s create mode 100644 graphics/hgr/bubble_universe/bubble_slow.s create mode 100644 graphics/hgr/bubble_universe/fast_dots.s create mode 100644 graphics/hgr/bubble_universe/make_table2.c diff --git a/graphics/hgr/bubble_universe/Makefile b/graphics/hgr/bubble_universe/Makefile index 9457d0b9..e74b713b 100644 --- a/graphics/hgr/bubble_universe/Makefile +++ b/graphics/hgr/bubble_universe/Makefile @@ -7,7 +7,8 @@ EMPTY_DISK = ../../../empty_disk all: bubble.dsk make_table -bubble.dsk: HELLO BUBBLE.BAS BUBBLE BUBBLE_ORIG BUBBLE_ROLLED DIAMOND +bubble.dsk: HELLO BUBBLE.BAS BUBBLE BUBBLE_C64 \ + BUBBLE_ORIG BUBBLE_ROLLED DIAMOND FAST_DOTS cp $(EMPTY_DISK)/empty.dsk bubble.dsk $(DOS33) -y bubble.dsk SAVE A HELLO $(DOS33) -y bubble.dsk SAVE A BUBBLE.BAS @@ -15,6 +16,8 @@ bubble.dsk: HELLO BUBBLE.BAS BUBBLE BUBBLE_ORIG BUBBLE_ROLLED DIAMOND $(DOS33) -y bubble.dsk BSAVE -a 0x0C00 BUBBLE_ORIG $(DOS33) -y bubble.dsk BSAVE -a 0x0C00 BUBBLE_ROLLED $(DOS33) -y bubble.dsk BSAVE -a 0x0C00 DIAMOND + $(DOS33) -y bubble.dsk BSAVE -a 0x0C00 FAST_DOTS + $(DOS33) -y bubble.dsk BSAVE -a 0x0C00 BUBBLE_C64 ### @@ -31,6 +34,15 @@ bubble.o: bubble.s hgr_clear_part.s sin_unrolled.s ### +BUBBLE_C64: bubble_c64.o + ld65 -o BUBBLE_C64 bubble_c64.o -C $(LINKER_SCRIPTS)/apple2_c00.inc + +bubble_c64.o: bubble_c64.s hgr_clear_part.s sin_unrolled.s + ca65 -o bubble_c64.o bubble_c64.s -l bubble_c64.lst + + +### + BUBBLE_ORIG: bubble_orig.o ld65 -o BUBBLE_ORIG bubble_orig.o -C $(LINKER_SCRIPTS)/apple2_c00.inc @@ -55,6 +67,15 @@ DIAMOND: diamond.o diamond.o: diamond.s ca65 -o diamond.o diamond.s -l diamond.lst +### + +FAST_DOTS: fast_dots.o + ld65 -o FAST_DOTS fast_dots.o -C $(LINKER_SCRIPTS)/apple2_c00.inc + +fast_dots.o: fast_dots.s + ca65 -o fast_dots.o fast_dots.s -l fast_dots.lst + + ### @@ -73,5 +94,5 @@ make_table.o: make_table.c ### clean: - rm -f *~ *.o *.lst BUBBLE.BAS HELLO BUBBLE \ - DIAMOND BUBBLE_ORIG BUBBLE_ROLLED + rm -f *~ *.o *.lst BUBBLE.BAS HELLO BUBBLE BUBBLE_C64 \ + DIAMOND BUBBLE_ORIG BUBBLE_ROLLED FAST_DOTS diff --git a/graphics/hgr/bubble_universe/bubble_c64.s b/graphics/hgr/bubble_universe/bubble_c64.s new file mode 100644 index 00000000..25754f50 --- /dev/null +++ b/graphics/hgr/bubble_universe/bubble_c64.s @@ -0,0 +1,291 @@ +; bubble universe -- Apple II Hires + +; by Vince `deater` Weaver +; based roughly on the BASIC code posted on the pouet forum +; original effect by yuruyrau on twitter + +; this version based on fast c64 code + +; soft-switches + +;KEYPRESS = $C000 +;KEYRESET = $C010 +PAGE1 = $C054 +PAGE2 = $C055 + +; ROM routines + +BKGND0 = $F3F4 ; clear current page to A +HGR2 = $F3D8 ; set hires page2 and clear $4000-$5fff +HGR = $F3E2 ; set hires page1 and clear $2000-$3fff +HPLOT0 = $F457 ; plot at (Y,X), (A) +;HLINRL = $F530 ; line to (X,A), (Y) +;HCOLOR1 = $F6F0 ; set HGR_COLOR to value in X +;COLORTBL = $F6F6 +;WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +; zero page + +GBASL = $26 +GBASH = $27 + + +HPLOTYL = $92 + +RXL = $96 +RXH = $97 +STEMP1L = $98 +STEMP1H = $99 +STEMP2L = $9A + + +IC = $D0 +J = $D1 +XL = $D2 +XH = $D3 +;VL = $D4 +;VH = $D5 +;TL = $D6 +T = $D7 +U = $D8 +V = $D9 + +HGR_PAGE = $E6 + +; const + +;NUM = 32 +NUM = 24 + +bubble: + + ;======================== + ; setup lookup tables + + jsr hgr_make_tables + + ;======================= + ; init graphics + + jsr HGR + jsr HGR2 + + ;======================= + ; init variables + + lda #0 + sta U + sta V + sta T + + + ;========================= + ;========================= + ; main loop + ;========================= + ;========================= + +next_frame: + + ;=========================== + ; "fast" clear screen + +.include "hgr_clear_part.s" + + lda T + sta IT1 + sta IT2 + lda #0 + sta IS1 + sta IS2 + lda #24 ; 40 + sta IC + ldx U + ldy V +i_loop: + lda #24 ; 200 + sta J +j_loop: + clc ; 2 +IS1 = *+1 + lda sin_t,Y ; 4+ +IT1 = *+1 + adc sin_t,X ; 4+ + sta U ; 3 +IS2 = *+1 + lda cos_t,Y ; 4+ +IT2 = *+1 + adc cos_t,X ; 4+ + tay ; 2 = 23-27 cycles + + sty V + + ;=========================================================== + ; HPLOT 32*U+140,32*V+96 + + + lda U + clc ; 2 + adc #140 ; 2 + tax ; 2 + + ; calculate Ypos + + lda V + clc + adc #96 + + ; "fast" hplot, Xpos in X, Ypos in A + + ; Apple II hi-res is more-or-less 280x192 + ; two consecutive pixels on are white + ; single pixels are colored based on palette + ; we treat things as a monochrome display, on a color + ; display odd/even pixels will have different colors + + ; The Y memory offset is a horrible interleaved mess, so we use + ; a lookup table we generated at start. We also add in + ; the proper value for page-flipping + + ; Apple II hi-res is 7 pixels/byte, so we also pre-generate + ; div and mod by 7 tables at start and use those + ; instead of dividing by 7 + ; We cheat and don't worry about the X positions larger + ; than 256 because our algorithm only goes up to 208 + + tay ; 2 + lda hposn_low,Y ; 4 + sta GBASL ; 3 + clc ; 2 + lda hposn_high,Y ; 4 + adc HGR_PAGE ; 3 + sta GBASH ; 3 +; 21 + + ldy div7_table,X ; 4 + + lda mod7_table,X ; 4 + tax ; 2 +; 31 + ; get current 7-bit pixel range, OR in to set new pixel + + lda (GBASL),Y ; 5 + ora log_lookup,X ; 4 + sta (GBASL),Y ; 6 +; 46 + + dec J + bne j_loop + +; dec J ; 5 +; bmi done_j ; 2/3 +; jmp inner_loop ; 3 +; bpl inner_loop +done_j: + + lda IS1 + clc + adc #41 + sta IS1 + sta IS2 + dec IC + bne i_loop + + + + + +; inc I ; 5 +; lda I ; 3 +; cmp #NUM ; 2 +; beq done_i ; 2/3 +; jmp outer_loop ; 3 +;done_i: + + ; t=t+(1.0/32.0); + ; 1/2 1/4 1/8 1/16 | 1/32 1/64 1/128 1/256 + ; $0x08 + + ; carry always set here as we got here from a BEQ + ; (bcs=bge, bcc=blt) + +; lda tl_smc+1 ; 4 +; adc #$7 ; really 8, carry always set ; 2 +; sta tl_smc+1 ; 4 +; lda #0 ; 2 +; adc th_smc+1 ; 4 +; sta th_smc+1 ; 4 + + sty V + inc T +; jmp new_frame + +end: + ; flip pages + + ; if $20 (draw PAGE1) draw PAGE2, SHOW page1 + ; if $40 (draw PAGE2) draw PAGE1, SHOW page2 + + lda HGR_PAGE + eor #$60 + sta HGR_PAGE + + cmp #$40 + bne flip2 +flip1: + bit PAGE1 + jmp next_frame +flip2: + bit PAGE2 + jmp next_frame + +.include "hgr_table.s" + + ; we could calculate these, or else build them from + ; a 0..pi/2 table to save a lot of space + + ; the alignment was there to potentially save cycles on page + ; crossing. Maybe not as useful that the cosine + ; goes off the page + + + ; which of 7 pixels to draw + ; note high bit is set to pick blue/orange palette + ; clear to get purple/green instead +log_lookup: + .byte $81,$82,$84,$88,$90,$A0,$C0,$80 + +sin_t: + .byte $0F,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0A,$0A,$09,$09,$08,$08,$08,$07 + .byte $07,$07,$06,$06,$06,$06,$06,$06,$05,$05,$05,$05,$05,$05,$05,$05 + .byte $05,$06,$06,$06,$06,$06,$06,$07,$07,$07,$08,$08,$08,$09,$09,$0A + .byte $0A,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0F,$0F,$10,$10,$11,$12,$13,$13 + .byte $14,$15,$16,$17,$17,$18,$19,$1A,$1B,$1C,$1D,$1D,$1E,$1F,$20,$21 + .byte $22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F,$30,$31 + .byte $32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F,$3F,$40 + .byte $41,$42,$43,$44,$45,$45,$46,$47,$48,$49,$49,$4A,$4B,$4C,$4C,$4D + .byte $4D,$4E,$4F,$4F,$50,$50,$51,$51,$52,$52,$53,$53,$54,$54,$54,$55 + .byte $55,$55,$56,$56,$56,$56,$56,$56,$57,$57,$57,$57,$57,$57,$57,$57 + .byte $57,$56,$56,$56,$56,$56,$56,$55,$55,$55,$54,$54,$54,$53,$53,$52 + .byte $52,$51,$51,$50,$50,$4F,$4F,$4E,$4D,$4D,$4C,$4C,$4B,$4A,$49,$49 + .byte $48,$47,$46,$45,$45,$44,$43,$42,$41,$40,$3F,$3F,$3E,$3D,$3C,$3B + .byte $3A,$39,$38,$37,$36,$35,$34,$33,$32,$31,$30,$2F,$2E,$2D,$2C,$2B + .byte $2A,$29,$28,$27,$26,$25,$24,$23,$22,$21,$20,$1F,$1E,$1D,$1D,$1C + .byte $1B,$1A,$19,$18,$17,$17,$16,$15,$14,$13,$13,$12,$11,$10,$10,$0F +cos_t: + .byte $14,$15,$16,$17,$17,$18,$19,$1A,$1B,$1C,$1D,$1D,$1E,$1F,$20,$21 + .byte $22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F,$30,$31 + .byte $32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F,$3F,$40 + .byte $41,$42,$43,$44,$45,$45,$46,$47,$48,$49,$49,$4A,$4B,$4C,$4C,$4D + .byte $4D,$4E,$4F,$4F,$50,$50,$51,$51,$52,$52,$53,$53,$54,$54,$54,$55 + .byte $55,$55,$56,$56,$56,$56,$56,$56,$57,$57,$57,$57,$57,$57,$57,$57 + .byte $57,$56,$56,$56,$56,$56,$56,$55,$55,$55,$54,$54,$54,$53,$53,$52 + .byte $52,$51,$51,$50,$50,$4F,$4F,$4E,$4D,$4D,$4C,$4C,$4B,$4A,$49,$49 + .byte $48,$47,$46,$45,$45,$44,$43,$42,$41,$40,$3F,$3F,$3E,$3D,$3C,$3B + .byte $3A,$39,$38,$37,$36,$35,$34,$33,$32,$31,$30,$2F,$2E,$2D,$2C,$2B + .byte $2A,$29,$28,$27,$26,$25,$24,$23,$22,$21,$20,$1F,$1E,$1D,$1D,$1C + .byte $1B,$1A,$19,$18,$17,$17,$16,$15,$14,$13,$13,$12,$11,$10,$10,$0F + .byte $0F,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0A,$0A,$09,$09,$08,$08,$08,$07 + .byte $07,$07,$06,$06,$06,$06,$06,$06,$05,$05,$05,$05,$05,$05,$05,$05 + .byte $05,$06,$06,$06,$06,$06,$06,$07,$07,$07,$08,$08,$08,$09,$09,$0A + .byte $0A,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0F,$0F,$10,$10,$11,$12,$13,$13 diff --git a/graphics/hgr/bubble_universe/bubble_slow.s b/graphics/hgr/bubble_universe/bubble_slow.s new file mode 100644 index 00000000..684e5dd1 --- /dev/null +++ b/graphics/hgr/bubble_universe/bubble_slow.s @@ -0,0 +1,354 @@ +; bubble universe -- Apple II Hires + +; soft-switches + +KEYPRESS = $C000 +KEYRESET = $C010 +PAGE1 = $C054 +PAGE2 = $C055 + +; ROM routines + +BKGND0 = $F3F4 ; clear current page to A +HGR2 = $F3D8 ; set hires page2 and clear $4000-$5fff +HGR = $F3E2 ; set hires page1 and clear $2000-$3fff +HPLOT0 = $F457 ; plot at (Y,X), (A) +HLINRL = $F530 ; line to (X,A), (Y) +HCOLOR1 = $F6F0 ; set HGR_COLOR to value in X +COLORTBL = $F6F6 +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +; zero page + +HPLOTXL = $90 +HPLOTXH = $91 +HPLOTYL = $92 +HPLOTYH = $93 +IVL = $94 +IVH = $95 +RXL = $96 +RXH = $97 +OUT1L = $98 +OUT1H = $99 +OUT2L = $9A +OUT2H = $9B +STEMP1L = $9C +STEMP1H = $9D +STEMP2L = $9E +STEMP2H = $9F + +I = $D0 +J = $D1 +XL = $D4 +XH = $D5 +VL = $D6 +VH = $D7 +TL = $DA +TH = $DB +UL = $DC +UH = $DD + +HGR_PAGE = $E6 + +; const + +NUM = 32 + +bubble: + + jsr HGR2 + + ldx #7 + jsr HCOLOR1 + + lda #0 + sta XL + sta XH + sta VL + sta VH + sta TL + sta TH + +next_frame: + + lda #0 + jsr BKGND0 + +main_loop: + + ldx #0 + stx I +outer_loop: + + ldx #0 + stx J + +inner_loop: + + ; fixed_add(rh[i],rl[i],xh,xl,&rxh,&rxl); + ; note: rh is always 0 + + ldx I ; 3 + clc ; 2 + lda rl,X + adc XL ; 3 + sta RXL ; 3 + lda #0 ; 2 + adc XH ; 3 + sta RXH ; 3 + + ; fixed_add(i,0,vh,vl,&ivh,&ivl); + clc + lda #0 + adc VL + sta IVL + lda I + adc VH + sta IVH + + ; U=SIN(I+V)+SIN(RR+X) + ; float_to_fixed(sin(ivh,ivl) + sin(rxh,rxl), &uh,&ul); + + ldy #0 + jsr sin + ldy #2 + jsr sin + + clc + lda OUT1L + adc OUT2L + sta UL + lda OUT1H + adc OUT2H + sta UH + + ; V=COS(I+V)+COS(RR+X) + ; float_to_fixed(cos(ivh,ivl) + cos(rxh,rxl), &vh,&vl); + + ldy #0 + jsr cos + ldy #2 + jsr cos + + clc + lda OUT1L + adc OUT2L + sta VL + lda OUT1H + adc OUT2H + sta VH + + + ; X=U+T + ; fixed_add(uh,ul,th,tl,&xh,&xl); + clc + lda UL + adc TL + sta XL + lda UH + adc TH + sta XH + + ; HPLOT 32*U+140,32*V+96 + ; hplot(48*fixed_to_float(uh,ul)+140, + ; 48*fixed_to_float(vh,vl)+96); + + ; HPLOT0 plot at (Y,X), (A) + + lda UL + sta HPLOTYL + + lda UH + + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + + clc + adc #140 + tax + + lda VL + sta HPLOTYL + + lda VH + + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + + clc + adc #96 + + + ldy #0 ; never bigger than 140+48 = 188 +; ldx #140 +; lda #96 + jsr HPLOT0 + + inc J + lda J + cmp #NUM + beq done_j + jmp inner_loop +done_j: + + inc I + lda I + cmp #NUM + beq done_i + jmp outer_loop +done_i: + + ; t=t+(1.0/32.0); + ; 1/2 1/4 1/8 1/16 | 1/32 1/64 1/128 1/256 + ; $0x08 + + clc + lda TL + adc #$8 + sta TL + lda #0 + adc TH + sta TH + +end: + ; flip pages + + ; if $20 (draw PAGE1) draw PAGE2, SHOW page1 + ; if $40 (draw PAGE2) draw PAGE1, SHOW page2 + + lda HGR_PAGE + eor #$60 + sta HGR_PAGE + + cmp #$40 + bne flip2 +flip1: + bit PAGE1 + jmp next_frame +flip2: + bit PAGE2 + jmp next_frame + + + + + ;======================= +sin: + + ; / 6.28 is roughly the same as *0.16 + ; = .5 .25 .125 .0625 .03125 + ; 1/6.28 = 0.16 = 0 0 1 0 1 0 0 0 = 0x28 + + ; i=(i*0x28)>>8; + + lda IVL,Y + sta STEMP1L + lda IVH,Y + sta STEMP1H +already_loaded: + ; i2=i<<3; + + asl STEMP1L + rol STEMP1H + asl STEMP1L + rol STEMP1H + asl STEMP1L + rol STEMP1H + + ; i1=i<<5; + + lda STEMP1L + sta STEMP2L + lda STEMP1H + sta STEMP2H + + asl STEMP2L + rol STEMP2H + asl STEMP2L + rol STEMP2H + + ; i=(i1+i2)>>8; + + clc + lda STEMP1L + adc STEMP2L + sta STEMP1L + + lda STEMP1H + adc STEMP2H + sta STEMP1H + + ldx STEMP1H + + ; sl=fsinh[i]; + + lda sin_lookup,X + asl + sta OUT1L,Y + + bcs sin_negative +sin_positive: + lda #$0 + beq set_sin_sign +sin_negative: + lda #$FF +set_sin_sign: + sta OUT1H,Y + + rts + + ;============================= +cos: + ; 1.57 is roughly 0x0192 in 8.8 + + clc + lda IVL,Y + adc #$92 + sta STEMP1L + lda IVH,Y + adc #1 + sta STEMP1H + + jmp already_loaded + + +rl: +.byte $00,$06,$0C,$12,$19,$1F,$25,$2B +.byte $32,$38,$3E,$45,$4B,$51,$57,$5E +.byte $64,$6A,$71,$77,$7D,$83,$8A,$90 +.byte $96,$9D,$A3,$A9,$AF,$B6,$BC,$C2 + +sin_lookup: +.byte $00,$03,$06,$09,$0C,$0F,$12,$15,$18,$1C,$1F,$22,$25,$28,$2B,$2E +.byte $30,$33,$36,$39,$3C,$3F,$41,$44,$47,$49,$4C,$4E,$51,$53,$55,$58 +.byte $5A,$5C,$5E,$60,$62,$64,$66,$68,$6A,$6C,$6D,$6F,$70,$72,$73,$74 +.byte $76,$77,$78,$79,$7A,$7B,$7C,$7C,$7D,$7E,$7E,$7F,$7F,$7F,$7F,$7F +.byte $7F,$7F,$7F,$7F,$7F,$7F,$7E,$7E,$7D,$7C,$7C,$7B,$7A,$79,$78,$77 +.byte $76,$75,$73,$72,$70,$6F,$6D,$6C,$6A,$68,$66,$64,$63,$61,$5E,$5C +.byte $5A,$58,$56,$53,$51,$4E,$4C,$49,$47,$44,$41,$3F,$3C,$39,$36,$34 +.byte $31,$2E,$2B,$28,$25,$22,$1F,$1C,$19,$16,$12,$0F,$0C,$09,$06,$03 +.byte $00,$FE,$FA,$F7,$F4,$F1,$EE,$EB,$E8,$E5,$E2,$DF,$DC,$D9,$D6,$D3 +.byte $D0,$CD,$CA,$C7,$C4,$C2,$BF,$BC,$BA,$B7,$B4,$B2,$AF,$AD,$AB,$A8 +.byte $A6,$A4,$A2,$A0,$9E,$9C,$9A,$98,$96,$95,$93,$91,$90,$8E,$8D,$8C +.byte $8A,$89,$88,$87,$86,$85,$84,$84,$83,$82,$82,$81,$81,$81,$81,$81 +.byte $81,$81,$81,$81,$81,$81,$82,$82,$83,$84,$84,$85,$86,$87,$88,$89 +.byte $8A,$8B,$8D,$8E,$8F,$91,$93,$94,$96,$98,$99,$9B,$9D,$9F,$A1,$A4 +.byte $A6,$A8,$AA,$AD,$AF,$B1,$B4,$B6,$B9,$BC,$BE,$C1,$C4,$C7,$C9,$CC +.byte $CF,$D2,$D5,$D8,$DB,$DE,$E1,$E4,$E7,$EA,$ED,$F0,$F4,$F7,$FA,$FD + diff --git a/graphics/hgr/bubble_universe/fast_dots.s b/graphics/hgr/bubble_universe/fast_dots.s new file mode 100644 index 00000000..c0b085dd --- /dev/null +++ b/graphics/hgr/bubble_universe/fast_dots.s @@ -0,0 +1,403 @@ +; bubble universe -- Apple II Hires + +; original = 612 bytes +; clear screen: +; bkgnd0 = $44198 = 278936 cycles = max ~4fps +; new: $A616 = 42518 = max ~22fps +; hplot +; hplot0 = ($14E-$15C) $14E = 334 * 1024 = 342016 = max ~3fps +; lookup = 46 * 1024 = 47104 = max ~21fps + + +; after fast graphics +; D7E77 = 884343 = 1.1fps + + +; soft-switches + +KEYPRESS = $C000 +KEYRESET = $C010 +PAGE1 = $C054 +PAGE2 = $C055 + +; ROM routines + +BKGND0 = $F3F4 ; clear current page to A +HGR2 = $F3D8 ; set hires page2 and clear $4000-$5fff +HGR = $F3E2 ; set hires page1 and clear $2000-$3fff +HPLOT0 = $F457 ; plot at (Y,X), (A) +HLINRL = $F530 ; line to (X,A), (Y) +HCOLOR1 = $F6F0 ; set HGR_COLOR to value in X +COLORTBL = $F6F6 +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +; zero page + +GBASL = $26 +GBASH = $27 + + +HPLOTXL = $90 +HPLOTXH = $91 +HPLOTYL = $92 +HPLOTYH = $93 +IVL = $94 +IVH = $95 +RXL = $96 +RXH = $97 +OUT1L = $98 +OUT1H = $99 +OUT2L = $9A +OUT2H = $9B +STEMP1L = $9C +STEMP1H = $9D +STEMP2L = $9E +STEMP2H = $9F + +I = $D0 +J = $D1 +XL = $D4 +XH = $D5 +VL = $D6 +VH = $D7 +TL = $DA +TH = $DB +UL = $DC +UH = $DD + +HGR_PAGE = $E6 + +; const + +NUM = 32 + +bubble: + + jsr hgr_make_tables + + jsr HGR2 + + ldx #7 + jsr HCOLOR1 + + lda #0 + sta XL + sta XH + sta VL + sta VH + sta TL + sta TH + +next_frame: + + jsr hgr_clear_screen + +; lda #0 +; jsr BKGND0 + +main_loop: + + ldx #0 + stx I +outer_loop: + + ldx #NUM + stx J + +inner_loop: + + ; fixed_add(rh[i],rl[i],xh,xl,&rxh,&rxl); + ; note: rh is always 0 + + ldx I ; 3 + clc ; 2 + lda rl,X + adc XL ; 3 + sta RXL ; 3 + lda #0 ; 2 + adc XH ; 3 + sta RXH ; 3 + + ; fixed_add(i,0,vh,vl,&ivh,&ivl); + clc + lda #0 + adc VL + sta IVL + lda I + adc VH + sta IVH + + ; U=SIN(I+V)+SIN(RR+X) + ; float_to_fixed(sin(ivh,ivl) + sin(rxh,rxl), &uh,&ul); + + ldy #0 + jsr sin + ldy #2 + jsr sin + + clc + lda OUT1L + adc OUT2L + sta UL + lda OUT1H + adc OUT2H + sta UH + + ; V=COS(I+V)+COS(RR+X) + ; float_to_fixed(cos(ivh,ivl) + cos(rxh,rxl), &vh,&vl); + + ldy #0 + jsr cos + ldy #2 + jsr cos + + clc + lda OUT1L + adc OUT2L + sta VL + lda OUT1H + adc OUT2H + sta VH + + + ; X=U+T + ; fixed_add(uh,ul,th,tl,&xh,&xl); + clc + lda UL + adc TL + sta XL + lda UH + adc TH + sta XH + + ; HPLOT 32*U+140,32*V+96 + ; hplot(48*fixed_to_float(uh,ul)+140, + ; 48*fixed_to_float(vh,vl)+96); + + ; HPLOT0 plot at (Y,X), (A) + + lda UL + sta HPLOTYL + + lda UH + + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + + clc + adc #140 + tax + + lda VL + sta HPLOTYL + + lda VH + + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + asl HPLOTYL + rol + + clc + adc #96 + + +; ldy #0 ; never bigger than 140+48 = 188 +; ldx #140 +; lda #96 +; jsr HPLOT0 + + tay ; 2 + lda hposn_low,Y ; 4 + sta GBASL ; 3 + clc ; 2 + lda hposn_high,Y ; 4 + adc HGR_PAGE ; 3 + sta GBASH ; 3 +; 21 + + ldy div7_table,X ; 4 + + lda mod7_table,X ; 4 + tax ; 2 +; 31 + lda (GBASL),Y ; 5 + ora log_lookup,X ; 4 + sta (GBASL),Y ; 6 +; 46 + +;div7_table = $6800 +;mod7_table = $6900 +;hposn_high = $6a00 +;hposn_low = $6b00 + + + dec J ; 5 + bne done_j ; 2/3 + jmp inner_loop ; 3 +done_j: + + inc I + lda I + cmp #NUM + beq done_i + jmp outer_loop +done_i: + + ; t=t+(1.0/32.0); + ; 1/2 1/4 1/8 1/16 | 1/32 1/64 1/128 1/256 + ; $0x08 + + clc + lda TL + adc #$8 + sta TL + lda #0 + adc TH + sta TH + +end: + ; flip pages + + ; if $20 (draw PAGE1) draw PAGE2, SHOW page1 + ; if $40 (draw PAGE2) draw PAGE1, SHOW page2 + + lda HGR_PAGE + eor #$60 + sta HGR_PAGE + + cmp #$40 + bne flip2 +flip1: + bit PAGE1 + jmp next_frame +flip2: + bit PAGE2 + jmp next_frame + + + + + ;======================= +sin: + + ; / 6.28 is roughly the same as *0.16 + ; = .5 .25 .125 .0625 .03125 + ; 1/6.28 = 0.16 = 0 0 1 0 1 0 0 0 = 0x28 + + ; i=(i*0x28)>>8; + + lda IVL,Y + sta STEMP1L + lda IVH,Y + sta STEMP1H +already_loaded: + ; i2=i<<3; + + asl STEMP1L + rol STEMP1H + asl STEMP1L + rol STEMP1H + asl STEMP1L + rol STEMP1H + + ; i1=i<<5; + + lda STEMP1L + sta STEMP2L + lda STEMP1H + sta STEMP2H + + asl STEMP2L + rol STEMP2H + asl STEMP2L + rol STEMP2H + + ; i=(i1+i2)>>8; + + clc + lda STEMP1L + adc STEMP2L + sta STEMP1L + + lda STEMP1H + adc STEMP2H + sta STEMP1H + + ldx STEMP1H + + ; sl=fsinh[i]; + + lda sin_lookup,X + asl + sta OUT1L,Y + + bcs sin_negative +sin_positive: + lda #$0 + beq set_sin_sign +sin_negative: + lda #$FF +set_sin_sign: + sta OUT1H,Y + + rts + + ;============================= +cos: + ; 1.57 is roughly 0x0192 in 8.8 + + clc + lda IVL,Y + adc #$92 + sta STEMP1L + lda IVH,Y + adc #1 + sta STEMP1H + + jmp already_loaded + + +rl: +.byte $00,$06,$0C,$12,$19,$1F,$25,$2B +.byte $32,$38,$3E,$45,$4B,$51,$57,$5E +.byte $64,$6A,$71,$77,$7D,$83,$8A,$90 +.byte $96,$9D,$A3,$A9,$AF,$B6,$BC,$C2 + +sin_lookup: +.byte $00,$03,$06,$09,$0C,$0F,$12,$15,$18,$1C,$1F,$22,$25,$28,$2B,$2E +.byte $30,$33,$36,$39,$3C,$3F,$41,$44,$47,$49,$4C,$4E,$51,$53,$55,$58 +.byte $5A,$5C,$5E,$60,$62,$64,$66,$68,$6A,$6C,$6D,$6F,$70,$72,$73,$74 +.byte $76,$77,$78,$79,$7A,$7B,$7C,$7C,$7D,$7E,$7E,$7F,$7F,$7F,$7F,$7F +.byte $7F,$7F,$7F,$7F,$7F,$7F,$7E,$7E,$7D,$7C,$7C,$7B,$7A,$79,$78,$77 +.byte $76,$75,$73,$72,$70,$6F,$6D,$6C,$6A,$68,$66,$64,$63,$61,$5E,$5C +.byte $5A,$58,$56,$53,$51,$4E,$4C,$49,$47,$44,$41,$3F,$3C,$39,$36,$34 +.byte $31,$2E,$2B,$28,$25,$22,$1F,$1C,$19,$16,$12,$0F,$0C,$09,$06,$03 +.byte $00,$FE,$FA,$F7,$F4,$F1,$EE,$EB,$E8,$E5,$E2,$DF,$DC,$D9,$D6,$D3 +.byte $D0,$CD,$CA,$C7,$C4,$C2,$BF,$BC,$BA,$B7,$B4,$B2,$AF,$AD,$AB,$A8 +.byte $A6,$A4,$A2,$A0,$9E,$9C,$9A,$98,$96,$95,$93,$91,$90,$8E,$8D,$8C +.byte $8A,$89,$88,$87,$86,$85,$84,$84,$83,$82,$82,$81,$81,$81,$81,$81 +.byte $81,$81,$81,$81,$81,$81,$82,$82,$83,$84,$84,$85,$86,$87,$88,$89 +.byte $8A,$8B,$8D,$8E,$8F,$91,$93,$94,$96,$98,$99,$9B,$9D,$9F,$A1,$A4 +.byte $A6,$A8,$AA,$AD,$AF,$B1,$B4,$B6,$B9,$BC,$BE,$C1,$C4,$C7,$C9,$CC +.byte $CF,$D2,$D5,$D8,$DB,$DE,$E1,$E4,$E7,$EA,$ED,$F0,$F4,$F7,$FA,$FD + +log_lookup: + .byte $81,$82,$84,$88,$90,$A0,$C0,$80 + +.include "hgr_clear_screen.s" +.include "hgr_table.s" diff --git a/graphics/hgr/bubble_universe/make_table2.c b/graphics/hgr/bubble_universe/make_table2.c new file mode 100644 index 00000000..84315a91 --- /dev/null +++ b/graphics/hgr/bubble_universe/make_table2.c @@ -0,0 +1,59 @@ +/* Bubble table */ + +#include +#include +#include +#include +#include +#include + +#define PI 3.14159265358979323846264 + +int main(int argc, char **argv) { + + int i,t; + double d; + +// in other words, scaled to 46+/-256/2pi. and shifted by 2*46 +// the shift is there to remove the offset from u and v +// being sums of 2 sins and 2 coses. +// Building in the offset means my coordinates are all positive +//cos_t .char round(cos((range(256)-92)*2.0*pi/256)*256.0/2.0/pi+46) +//sin_t .char round(sin((range(256)-92)*2.0*pi/256)*256.0/2.0/pi+46) + + + + int sine_table[256]; + int cos_table[256]; + + for(i=0;i<256;i++) { + d=round(sin((i-92)*2.0*PI/256.0)*256.0/2.0/PI+46); + sine_table[i]=(int)d; + } + + printf("sin_t:\n"); + for(i=0;i<256;i++) { + if (i%16==0) printf("\t.byte\t"); + t=sine_table[i]; + printf("$%02X",t&0xff); + if (i%16!=15) printf(","); + else printf("\n"); + } + + for(i=0;i<256;i++) { + d=round(cos((i-92)*2.0*PI/256.0)*256.0/2.0/PI+46); + cos_table[i]=(int)d; + } + + printf("cos_t:\n"); + for(i=0;i<256;i++) { + if (i%16==0) printf("\t.byte\t"); + t=cos_table[i]; + printf("$%02X",t&0xff); + if (i%16!=15) printf(","); + else printf("\n"); + } + + + +}