diff --git a/graphics/hgr/bubble_universe/bubble_c64.s b/graphics/hgr/bubble_universe/bubble_c64.s index 25754f50..ab172a67 100644 --- a/graphics/hgr/bubble_universe/bubble_c64.s +++ b/graphics/hgr/bubble_universe/bubble_c64.s @@ -19,7 +19,6 @@ 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 @@ -32,20 +31,8 @@ GBASH = $27 HPLOTYL = $92 -RXL = $96 -RXH = $97 -STEMP1L = $98 -STEMP1H = $99 -STEMP2L = $9A - - -IC = $D0 +I = $D0 J = $D1 -XL = $D2 -XH = $D3 -;VL = $D4 -;VH = $D5 -;TL = $D6 T = $D7 U = $D8 V = $D9 @@ -73,7 +60,9 @@ bubble: ;======================= ; init variables - lda #0 + ; HGR leaves A at 0 + +; lda #0 sta U sta V sta T @@ -92,48 +81,65 @@ next_frame: .include "hgr_clear_part.s" + ; reset I*T + lda T - sta IT1 - sta IT2 + sta it1_smc+1 + sta it2_smc+1 + + ; reset I*S + lda #0 - sta IS1 - sta IS2 + sta is1_smc+1 + sta is2_smc+1 + lda #24 ; 40 - sta IC - ldx U - ldy V + sta I + 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 + ldx U + ldy V - sty V + + ; where S=41 (approximately 1/6.28) + + clc ; 2 + + + + ; calc: b=i+t+u; + ; u=cosines[a]+cosines[b]; +is2_smc: + lda cosines,Y ; 4+ +it2_smc: + adc cosines,X ; 4+ + sta V + + ; calc: a=i*s+v; + ; u=sines[a]+sines[b]; +is1_smc: + lda sines,Y ; 4+ +it1_smc: + adc sines,X ; 4+ + sta U ; 3 ;=========================================================== ; HPLOT 32*U+140,32*V+96 - lda U - clc ; 2 - adc #140 ; 2 +; lda U +; clc ; 2 + adc #44 ; 2 tax ; 2 ; calculate Ypos lda V - clc - adc #96 +; clc +; adc #96 ; "fast" hplot, Xpos in X, Ypos in A @@ -177,48 +183,19 @@ IT2 = *+1 dec J bne j_loop -; dec J ; 5 -; bmi done_j ; 2/3 -; jmp inner_loop ; 3 -; bpl inner_loop done_j: - lda IS1 + lda is1_smc+1 clc - adc #41 - sta IS1 - sta IS2 - dec IC + adc #41 ; 1/6.28 = 0.16 = 0 0 1 0 1 0 0 0 = 0x28 + sta is1_smc+1 + sta is2_smc+1 + dec I bne i_loop +done_i: - - - - -; 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 +; sty V inc T -; jmp new_frame end: ; flip pages @@ -241,51 +218,87 @@ flip2: .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 + ; the current "fast" code expects to be aligned on boundary + ; also have to double things up as the code can go up to 255 off + ; end for speed reasons + + +; floor(s*sin((x-96)*PI*2/256.0)+48.5); + +.align $100 +sines: + .byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B + .byte $0A,$0A,$09,$09,$09,$08,$08,$08,$08,$08,$07,$07,$07,$07,$07,$07 + .byte $07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$09,$09,$09,$0A + .byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12 + .byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F + .byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F + .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F + .byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C + .byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55 + .byte $56,$56,$57,$57,$57,$58,$58,$58,$58,$58,$59,$59,$59,$59,$59,$59 + .byte $59,$59,$59,$59,$59,$59,$59,$58,$58,$58,$58,$58,$57,$57,$57,$56 + .byte $56,$55,$55,$55,$54,$54,$53,$53,$52,$52,$51,$50,$50,$4F,$4E,$4E + .byte $4D,$4C,$4C,$4B,$4A,$49,$48,$48,$47,$46,$45,$44,$43,$42,$42,$41 + .byte $40,$3F,$3E,$3D,$3C,$3B,$3A,$39,$38,$37,$36,$35,$34,$33,$32,$31 + .byte $30,$2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$27,$26,$25,$24,$23,$22,$21 + .byte $20,$1F,$1E,$1E,$1D,$1C,$1B,$1A,$19,$18,$18,$17,$16,$15,$14,$14 +sines2: + .byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B + .byte $0A,$0A,$09,$09,$09,$08,$08,$08,$08,$08,$07,$07,$07,$07,$07,$07 + .byte $07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$09,$09,$09,$0A + .byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12 + .byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F + .byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F + .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F + .byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C + .byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55 + .byte $56,$56,$57,$57,$57,$58,$58,$58,$58,$58,$59,$59,$59,$59,$59,$59 + .byte $59,$59,$59,$59,$59,$59,$59,$58,$58,$58,$58,$58,$57,$57,$57,$56 + .byte $56,$55,$55,$55,$54,$54,$53,$53,$52,$52,$51,$50,$50,$4F,$4E,$4E + .byte $4D,$4C,$4C,$4B,$4A,$49,$48,$48,$47,$46,$45,$44,$43,$42,$42,$41 + .byte $40,$3F,$3E,$3D,$3C,$3B,$3A,$39,$38,$37,$36,$35,$34,$33,$32,$31 + .byte $30,$2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$27,$26,$25,$24,$23,$22,$21 + .byte $20,$1F,$1E,$1E,$1D,$1C,$1B,$1A,$19,$18,$18,$17,$16,$15,$14,$14 + +; floor(s*cos((x-96)*PI*2/256.0)+48.5); +cosines: + .byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F + .byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F + .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F + .byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C + .byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55 + .byte $56,$56,$57,$57,$57,$58,$58,$58,$58,$58,$59,$59,$59,$59,$59,$59 + .byte $59,$59,$59,$59,$59,$59,$59,$58,$58,$58,$58,$58,$57,$57,$57,$56 + .byte $56,$55,$55,$55,$54,$54,$53,$53,$52,$52,$51,$50,$50,$4F,$4E,$4E + .byte $4D,$4C,$4C,$4B,$4A,$49,$48,$48,$47,$46,$45,$44,$43,$42,$42,$41 + .byte $40,$3F,$3E,$3D,$3C,$3B,$3A,$39,$38,$37,$36,$35,$34,$33,$32,$31 + .byte $30,$2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$27,$26,$25,$24,$23,$22,$21 + .byte $20,$1F,$1E,$1E,$1D,$1C,$1B,$1A,$19,$18,$18,$17,$16,$15,$14,$14 + .byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B + .byte $0A,$0A,$09,$09,$09,$08,$08,$08,$08,$08,$07,$07,$07,$07,$07,$07 + .byte $07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$09,$09,$09,$0A + .byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12 +cosines2: + .byte $13,$14,$14,$15,$16,$17,$18,$18,$19,$1A,$1B,$1C,$1D,$1E,$1E,$1F + .byte $20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$2A,$2B,$2C,$2D,$2E,$2F + .byte $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$3A,$3B,$3C,$3D,$3E,$3F + .byte $40,$41,$42,$42,$43,$44,$45,$46,$47,$48,$48,$49,$4A,$4B,$4C,$4C + .byte $4D,$4E,$4E,$4F,$50,$50,$51,$52,$52,$53,$53,$54,$54,$55,$55,$55 + .byte $56,$56,$57,$57,$57,$58,$58,$58,$58,$58,$59,$59,$59,$59,$59,$59 + .byte $59,$59,$59,$59,$59,$59,$59,$58,$58,$58,$58,$58,$57,$57,$57,$56 + .byte $56,$55,$55,$55,$54,$54,$53,$53,$52,$52,$51,$50,$50,$4F,$4E,$4E + .byte $4D,$4C,$4C,$4B,$4A,$49,$48,$48,$47,$46,$45,$44,$43,$42,$42,$41 + .byte $40,$3F,$3E,$3D,$3C,$3B,$3A,$39,$38,$37,$36,$35,$34,$33,$32,$31 + .byte $30,$2F,$2E,$2D,$2C,$2B,$2A,$29,$28,$27,$26,$25,$24,$23,$22,$21 + .byte $20,$1F,$1E,$1E,$1D,$1C,$1B,$1A,$19,$18,$18,$17,$16,$15,$14,$14 + .byte $13,$12,$12,$11,$10,$10,$0F,$0E,$0E,$0D,$0D,$0C,$0C,$0B,$0B,$0B + .byte $0A,$0A,$09,$09,$09,$08,$08,$08,$08,$08,$07,$07,$07,$07,$07,$07 + .byte $07,$07,$07,$07,$07,$07,$07,$08,$08,$08,$08,$08,$09,$09,$09,$0A + .byte $0A,$0B,$0B,$0B,$0C,$0C,$0D,$0D,$0E,$0E,$0F,$10,$10,$11,$12,$12 diff --git a/graphics/hgr/bubble_universe/hgr_clear_part.s b/graphics/hgr/bubble_universe/hgr_clear_part.s index f88a3961..c8ab00be 100644 --- a/graphics/hgr/bubble_universe/hgr_clear_part.s +++ b/graphics/hgr/bubble_universe/hgr_clear_part.s @@ -13,7 +13,7 @@ hgr_clear_part: hgr_page1_clearscreen: - ldy #10 + ldy #8 hgr_page1_cls_loop: .if 0 sta $2000,Y ; 0 @@ -30,6 +30,7 @@ hgr_page1_cls_loop: sta $2880,Y ; 10 sta $2C80,Y ; 11 sta $3080,Y ; 12 +.endif sta $3480,Y ; 13 sta $3880,Y ; 14 sta $3C80,Y ; 15 @@ -51,7 +52,7 @@ hgr_page1_cls_loop: sta $3580,Y ; 29 sta $3980,Y ; 30 sta $3D80,Y ; 31 -.endif + sta $2200,Y ; 32 sta $2600,Y ; 33 sta $2A00,Y ; 34 @@ -199,7 +200,7 @@ hgr_page1_cls_loop: sta $35D0,Y ; 29 sta $39D0,Y ; 30 sta $3DD0,Y ; 31 -.if 0 + sta $2250,Y ; 160 sta $2650,Y ; 33 sta $2A50,Y ; 34 @@ -222,6 +223,7 @@ hgr_page1_cls_loop: sta $2750,Y ; 49 sta $2B50,Y ; 50 sta $2F50,Y ; 51 +.if 0 sta $3350,Y ; 52 sta $3750,Y ; 53 sta $3B50,Y ; 54 @@ -237,7 +239,7 @@ hgr_page1_cls_loop: sta $3FD0,Y ; 63 .endif iny - cpy #30 + cpy #32 beq hgr_page1_cls_done jmp hgr_page1_cls_loop @@ -248,7 +250,7 @@ hgr_page1_cls_done: hgr_page2_clearscreen: - ldy #10 + ldy #8 hgr_page2_cls_loop: .if 0 sta $4000,Y ; 0 @@ -265,6 +267,7 @@ hgr_page2_cls_loop: sta $4880,Y ; 10 sta $4C80,Y ; 11 sta $5080,Y ; 12 +.endif sta $5480,Y ; 13 sta $5880,Y ; 14 sta $5C80,Y ; 15 @@ -286,7 +289,7 @@ hgr_page2_cls_loop: sta $5580,Y ; 29 sta $5980,Y ; 30 sta $5D80,Y ; 31 -.endif + sta $4200,Y ; 32 sta $4600,Y ; 33 sta $4A00,Y ; 34 @@ -434,7 +437,7 @@ hgr_page2_cls_loop: sta $55D0,Y ; 29 sta $59D0,Y ; 30 sta $5DD0,Y ; 31 -.if 0 + sta $4250,Y ; 160 sta $4650,Y ; 33 sta $4A50,Y ; 34 @@ -456,6 +459,7 @@ hgr_page2_cls_loop: sta $4350,Y ; 176 sta $4750,Y ; 49 sta $4B50,Y ; 50 +.if 0 sta $4F50,Y ; 51 sta $5350,Y ; 52 sta $5750,Y ; 53 @@ -472,7 +476,7 @@ hgr_page2_cls_loop: sta $5FD0,Y ; 63 .endif iny - cpy #30 + cpy #32 beq hgr_page2_cls_done jmp hgr_page2_cls_loop hgr_page2_cls_done: diff --git a/utils/gr-sim/bubble/bubble_sf.c b/utils/gr-sim/bubble/bubble_sf.c new file mode 100644 index 00000000..330ab257 --- /dev/null +++ b/utils/gr-sim/bubble/bubble_sf.c @@ -0,0 +1,115 @@ +/* Bubble */ + +/* based on updated TIC-80 version by serato_fig */ + +#include +#include +#include +#include +#include +#include + +#include "gr-sim.h" +#include "tfv_utils.h" +#include "tfv_zp.h" + +#define NUM 20 + +#define PI 3.14159265358978323846264 + +uint8_t s=41;//s=41; + // ; 1/6.28 = 0.16 = 0 0 1 0 1 0 0 0 = 0x28 + + +uint8_t sine(uint8_t x) { + + return floor(s*sin((x-96)*PI*2/256.0)+48.5); + +} + +uint8_t cose(uint8_t x) { + + return floor(s*cos((x-96)*PI*2/256.0)+48.5); + +} + + +int main(int argc, char **argv) { + + int ch; + int i,j; + + + uint8_t u=0,v=0,t=0,a,b; + + uint8_t sines[256]; + uint8_t cosines[256]; + + grsim_init(); + + // HCOLOR=7 + hcolor_equals(7); + + + for(i=0;i<256;i++) { + sines[i]=sine(i); + cosines[i]=cose(i); + } + +#if 0 + printf("sines:\n"); + for(i=0;i<256;i++) { + if (i%16==0) printf("\t.byte "); + printf("$%02X",sines[i]); + if (i%16==15) printf("\n"); + else printf(","); + } + printf("cosines:\n"); + for(i=0;i<256;i++) { + if (i%16==0) printf("\t.byte "); + printf("$%02X",cosines[i]); + if (i%16==15) printf("\n"); + else printf(","); + } +#endif + + // HGR2:FOR I=0 TO N:RR=R*I:FOR J=0 TO N + + hgr(); + soft_switch(MIXCLR); + while(1) { + hclr(); + for(i=0;i192) printf("V out of range %d\n",v); + hplot(u+44, + v); + } + + + } + + grsim_update(); + usleep(100000); + + ch=grsim_input(); + if (ch=='q') exit(0); + + t=t+1; + + } + + return 0; +}