rotoplasma: add a rotoplasma

This commit is contained in:
Vince Weaver 2021-01-10 23:56:51 -05:00
parent 47dfd72f21
commit 70c9c75f01
7 changed files with 932 additions and 4 deletions

View File

@ -45,7 +45,7 @@ HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y
CLRSCR = $F832 ;; Clear low-res screen
CLRTOP = $F836 ;; clear only top of low-res screen
GBASCALC= $F847 ;; take Y coord in A, put address in GBASL/H ( a trashed, C clear)
GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A
ROM_TEXT2COPY = $F962 ;; iigs
SETTXT = $FB36

View File

@ -6,10 +6,11 @@ LINKERSCRIPTS = ../../../linker_scripts
all: roto.dsk make_sine_table
roto.dsk: HELLO ROTO
roto.dsk: HELLO ROTO ROTOPLASMA
cp empty.dsk roto.dsk
$(DOS33) -y roto.dsk SAVE A HELLO
$(DOS33) -y roto.dsk BSAVE -a 0x1000 ROTO
$(DOS33) -y roto.dsk BSAVE -a 0x1000 ROTOPLASMA
###
@ -26,6 +27,15 @@ roto.o: roto.s rotozoom.s gr_plot.s gr_scrn.s
###
ROTOPLASMA: rotoplasma.o
ld65 -o ROTOPLASMA rotoplasma.o -C $(LINKERSCRIPTS)/apple2_1000.inc
rotoplasma.o: rotoplasma.s rotozoom_texture.s plasma.s
ca65 -o rotoplasma.o rotoplasma.s -l rotoplasma.lst
###
make_sine_table: make_sine_table.o
$(CC) -o make_sine_table make_sine_table.o -lm
@ -35,4 +45,4 @@ make_sine_table.o: make_sine_table.c
###
clean:
rm -f *~ *.o *.lst ROTO make_sine_table
rm -f *~ *.o *.lst ROTO ROTOPLASMA make_sine_table

View File

@ -39,13 +39,17 @@ NORMAL = $F273
;; MONITOR ROUTINES
PLOT = $F800 ;; PLOT AT Y,A
PLOT1 = $F80E ;; PLOT at (GBASL),Y (need MASK to be $0f or $f0)
HLINE = $F819 ;; HLINE Y,$2C at A
VLINE = $F828 ;; VLINE A,$2D at Y
CLRSCR = $F832 ;; Clear low-res screen
CLRTOP = $F836 ;; clear only top of low-res screen
GBASCALC= $F847 ;; take Y-coord/2 in A, put address in GBASL/H ( a trashed, C clear)
SETCOL = $F864 ;; COLOR=A
ROM_TEXT2COPY = $F962 ;; iigs
TEXT = $FB36
SETTXT = $FB36
SETGR = $FB40
TABV = $FB5B ;; VTAB to A
ROM_MACHINEID = $FBB3 ;; iigs
BELL = $FBDD ;; ring the bell

View File

@ -0,0 +1,144 @@
lookup = $d00
;col = ( 8.0 + (sintable[xx&0xf])
; + 8.0 + (sintable[yy&0xf])
; ) / 2;
init_plasma_texture:
ldy #15
create_yloop:
ldx #15
create_xloop:
clc
lda #15
adc sinetable,X
adc sinetable,Y
lsr
lookup_smc:
sta lookup ; always starts at $d00
inc lookup_smc+1
dex
bpl create_xloop
dey
bpl create_yloop
rts
;==============================
; update plasma
update_plasma:
cycle_colors:
; cycle colors
ldx #0
cycle_loop:
inc lookup,X
inx
bne cycle_loop
rts
.if 0
plot_frame:
; plot frame
ldx #47 ; YY=0
plot_yloop:
txa ; get (y&0xf)<<4
pha ; save YY
asl
asl
asl
asl
sta CTEMP
txa
lsr
ldy #$0f ; setup mask
bcc plot_mask
ldy #$f0
plot_mask:
sty MASK
jsr GBASCALC ; point GBASL/H to address in A
; after, A trashed, C is clear
;==========
ldy #39 ; XX = 39 (countdown)
plot_xloop:
tya ; get x&0xf
and #$f
ora CTEMP ; get ((y&0xf)*16)+x
tax
plot_lookup:
; sta plot_lookup_smc+1
plot_lookup_smc:
lda lookup,X ; load lookup, (y*16)+x
; lda lookup ; load lookup, (y*16)+x
and #$f
lsr
tax
lda colorlookup,X
sta COLOR
jsr PLOT1 ; plot at GBASL,Y (x co-ord in Y)
dey
bpl plot_xloop
pla
tax ; restore YY
dex
bpl plot_yloop
bmi forever_loop
.endif
which_color: .byte $0
colorlookup:
.word blue_lookup,red_lookup,green_lookup,yellow_lookup
; blue
blue_lookup:
.byte $55,$22,$66,$77,$ff,$77,$55,$00
; red
red_lookup:
.byte $55,$11,$33,$bb,$ff,$bb,$55,$00
; green
green_lookup:
.byte $55,$44,$cc,$ee,$ff,$ee,$55,$00
; yellow
yellow_lookup:
.byte $55,$88,$99,$dd,$ff,$dd,$55,$00
sinetable:
.byte $00,$03,$05,$07,$08,$07,$05,$03
.byte $00,$FD,$FB,$F9,$F8,$F9,$FB,$FD

View File

@ -0,0 +1,170 @@
; rotozoom with cycling plasma texture
;
; TODO:
; make angle 64 degrees?
; remove scaling step?
; cycle between all four color schemes?
.include "zp.inc"
.include "hardware.inc"
;================================
; Clear screen and setup graphics
;================================
jsr HOME
bit PAGE0 ; set page 0
bit LORES ; Lo-res graphics
bit FULLGR ; mixed gr/text mode
bit SET_GR ; set graphics
lda #0
sta DISP_PAGE
lda #4
sta DRAW_PAGE
;===================================
; Clear top/bottom of page 0 and 1
;===================================
; jsr clear_screens
;===================================
; init the multiply tables
;===================================
jsr init_multiply_tables
;======================
; init plasma texture
;======================
jsr init_plasma_texture
;=================================
; main loop
lda #0
sta ANGLE
sta SCALE_F
sta FRAMEL
lda #1
sta SCALE_I
main_loop:
jsr update_plasma
jsr rotozoom
jsr page_flip
wait_for_keypress:
; lda KEYPRESS
; bpl wait_for_keypress
; bit KEYRESET
clc
lda FRAMEL
adc direction
sta FRAMEL
cmp #$f8
beq back_at_zero
cmp #33
; beq at_far_end
beq back_at_zero
bne done_reverse
back_at_zero:
; change plasma color
inc which_color
lda which_color
cmp #4
bne refresh_color
lda #0
sta which_color
refresh_color:
asl
tay
lda colorlookup,Y
sta colorlookup_smc+1
sta colorlookup2_smc+1
lda colorlookup+1,Y
sta colorlookup_smc+2
sta colorlookup2_smc+2
at_far_end:
; change bg color
; reverse direction
lda direction
eor #$ff
clc
adc #1
sta direction
lda scaleaddl
eor #$ff
clc
adc #1
sta scaleaddl
lda scaleaddh
eor #$ff
adc #0
sta scaleaddh
done_reverse:
clc
lda ANGLE
adc direction
and #$3f
sta ANGLE
; increment zoom
; clc
; lda SCALE_F
; adc scaleaddl
; sta SCALE_F
; lda SCALE_I
; adc scaleaddh
; sta SCALE_I
jmp main_loop
direction: .byte $01
scaleaddl: .byte $10
scaleaddh: .byte $00
;===============================================
; External modules
;===============================================
.include "rotozoom_texture.s"
.include "plasma.s"
.include "gr_pageflip.s"
.include "gr_fast_clear.s"
.include "gr_copy.s"
;.include "decompress_fast_v2.s"
.include "gr_offsets.s"
.include "c00_scrn_offsets.s"
.include "multiply_fast.s"
;===============================================
; Data
;===============================================

View File

@ -0,0 +1,599 @@
; rotozoomer!
; with 16x16 texture
; takes a lores-formatted image in $c00 and rotozooms it
; by ANGLE and SCALE_I/SCALE_F and draws it to the
; lo-res page in DRAW_PAGE
; ANGLE in our case is 0..31
; SCALE_I/SCALE_F is 8.8 fixed point scale multiplier
CAL = $B0
CAH = $B1
SAL = $B2
SAH = $B3
YPL = $B4
YPH = $B5
XPL = $B6
XPH = $B7
;YY
;XX
CCAL = $B8
CCAH = $B9
CSAL = $BA
CSAH = $BB
YCAL = $BC
YCAH = $BD
YSAL = $BE
YSAH = $BF
rotozoom:
; setup scale for multiply
lda SCALE_I ; 3
sta NUM1H ; 3
lda SCALE_F ; 3
sta NUM1L ; 3
; ca = cos(theta)*scale;
; (we use equiv ca=fixed_sin[(theta+8)&0xf] )
lda ANGLE ; 3
clc ; 2
adc #16 ; 2
and #$3f ; 2
asl ; 2
tay ; 2
lda fixed_sin,Y ; load integer half ; 4
sta NUM2H ; 3
lda fixed_sin+1,Y ; load float half ; 4
sta NUM2L ; 3
;===========
; 27
sec ; reload NUM1H/NUM1L ; 2
jsr multiply ; 6+???
stx CAH ; 3
sta CAL ; 3
; sa = sin(theta)*scale;
lda ANGLE ; 3
asl ; 2
tay ; 2
lda fixed_sin,Y ; load integer half ; 4
sta NUM2H ; 3
lda fixed_sin+1,Y ; load integer half ; 4
sta NUM2L ; 3
;==========
; 21
clc ; NUM1H/NUM1L same as last time ; 2
jsr multiply ; 6+???
stx SAH ; 3
sta SAL ; 3
; cca = -20*ca;
lda #-20 ; 2
sta NUM1H ; 3
lda #0 ; 2
sta NUM1L ; 3
lda CAL ; 3
sta NUM2L ; 3
lda CAH ; 3
sta NUM2H ; 3
sec ; reload NUM1H/NUM1L ; 2
jsr multiply ; 6+???
stx CCAH ; 3
sta CCAL ; 3
; csa = -20*sa;
lda SAL ; 3
sta NUM2L ; 3
lda SAH ; 3
sta NUM2H ; 3
clc ; same NUM1H/NUM1L as las time ; 2
jsr multiply ; 6+???
stx CSAH ; 3
sta CSAL ; 3
; yca=cca+ycenter;
lda CCAL ; 3
sta YCAL ; 3
clc ; 2
lda CCAH ; 3
adc #20 ; 2
sta YCAH ; 3
;===========
; 16
; ysa=csa+xcenter;
lda CSAL ; 3
sta YSAL ; 3
clc ; 2
lda CSAH ; 3
adc #20 ; 2
sta YSAH ; 3
;===========
; 16
; yloop, unrolled once
;===================================================================
; for(yy=0;yy<40;yy++) {
;===================================================================
ldy #0 ; 2
sty YY ; 3
rotozoom_yloop:
; setup self-modifying code for plot
; YY already in Y from end of loop
; ldy YY ; 3
lda common_offsets_l,Y ; lookup low-res memory address ; 4
sta rplot2_smc+1 ; 4
sta rplot12_smc+1 ; 4
sta rplot22_smc+1 ; 4
clc ; 2
lda gr_400_offsets_h,Y ; 4
adc DRAW_PAGE ; add in draw page offset ; 3
sta rplot2_smc+2 ; 4
sta rplot12_smc+2 ; 4
sta rplot22_smc+2 ; 4
;=====================
; unroll 0, even line
;=====================
; xp=cca+ysa; 8.8 fixed point
clc ; 2
lda YSAL ; 3
adc CCAL ; 3
sta XPL ; 3
lda YSAH ; 3
adc CCAH ; 3
sta XPH ; 3
;==========
; 20
; yp=yca-csa; 8.8 fixed point
sec ; 2
lda YCAL ; 3
sbc CSAL ; 3
sta YPL ; 3
lda YCAH ; 3
sbc CSAH ; 3
sta YPH ; 3
;===========
; 20
; for(xx=0;xx<40;xx++) {
ldx #0 ; 2
rotozoom_xloop:
;===================================================================
;===================================================================
; note: every cycle saved below here
; saves 1600 cycles
;===================================================================
;===================================================================
lda XPH
and #$f
sta CTEMP
lda YPH
asl
asl
asl
asl
clc
adc CTEMP
tay
lda lookup,Y
and #$f
lsr
tay
colorlookup2_smc:
lda blue_lookup,Y
and #$0f
rscrn_done:
;=============================================
; always even, want A in bottom of nibble
; so we are all set
rotozoom_set_color:
; want same color in top and bottom nibbles
;==========
; 0
;=================================================
rplot:
; plot(xx,yy); (color is in A)
; we are in loop unroll0 so always even line here
; meaning we want to load old color, save top nibble, and over-write
; bottom nibble with our value
; but! we don't need to save old as we are re-drawing whole screen!
rplot_even:
rplot2_smc:
sta $400,X ; 5
;============
; 5
;=======================
; xp=xp+ca; fixed point 8.8
clc ; 2
lda CAL ; 3
adc XPL ; 3
sta XPL ; 3
lda CAH ; 3
adc XPH ; 3
sta XPH ; 3
; yp=yp-sa; fixed point 8.8
sec ; 2
lda YPL ; 3
sbc SAL ; 3
sta YPL ; 3
lda YPH ; 3
sbc SAH ; 3
sta YPH ; 3
rotozoom_end_xloop:
inx ; 2
cpx #40 ; 2
bne rotozoom_xloop ; 2nt/3
rotozoom_xloop_done:
; yca+=ca; 8.8 fixed point
clc ; 2
lda YCAL ; 3
adc CAL ; 3
sta YCAL ; 3
lda YCAH ; 3
adc CAH ; 3
sta YCAH ; 3
;===========
; 20
; ysa+=sa; 8.8 fixed point
clc ; 2
lda YSAL ; 3
adc SAL ; 3
sta YSAL ; 3
lda YSAH ; 3
adc SAH ; 3
sta YSAH ; 3
;==========
; 20
;===============
; loop unroll 1
;===============
;rotozoom_yloop:
; xp=cca+ysa; 8.8 fixed point
clc ; 2
lda YSAL ; 3
adc CCAL ; 3
sta XPL ; 3
lda YSAH ; 3
adc CCAH ; 3
sta XPH ; 3
;==========
; 20
; yp=yca-csa; 8.8 fixed point
sec ; 2
lda YCAL ; 3
sbc CSAL ; 3
sta YPL ; 3
lda YCAH ; 3
sbc CSAH ; 3
sta YPH ; 3
;===========
; 20
; for(xx=0;xx<40;xx++) {
ldx #0 ; 2
rotozoom_xloop2:
;===================================================================
;===================================================================
; note: every cycle saved below here
; saves 1600 cycles
;===================================================================
;===================================================================
; if ((xp<0) || (xp>39)) color=0;
; else if ((yp<0) || (yp>39)) color=0;
; else color=scrn_page(xp,yp,PAGE2);
; we know it's never going to go *that* far out of bounds
; so we could avoid the Y check by just having "0"
; on the edges of the screen? Tricky due to Apple II
; interlacing
lda XPH
and #$f
sta CTEMP
lda YPH
asl
asl
asl
asl
clc
adc CTEMP
tay
lda lookup,Y
and #$f
lsr
tay
colorlookup_smc:
lda blue_lookup,Y
and #$f0
;=============================================
rotozoom_set_color2:
; always odd
; want color in top, which it is from above
;==========
; 0
;=================================================
rplot2:
; plot(xx,yy); (color is in A)
; always odd, so place color in top
; note! since we are drawing whole screen, we know the top of
; the value is already clear from loop=0 so we don't have to mask
rplot_odd:
rplot12_smc:
ora $400,X ; 4
rplot22_smc:
sta $400,X ; 5
;============
; 9
;=======================
; xp=xp+ca; 8.8 fixed point
clc ; 2
lda CAL ; 3
adc XPL ; 3
sta XPL ; 3
lda CAH ; 3
adc XPH ; 3
sta XPH ; 3
; yp=yp-sa; 8.8 fixed point
sec ; 2
lda YPL ; 3
sbc SAL ; 3
sta YPL ; 3
lda YPH ; 3
sbc SAH ; 3
sta YPH ; 3
rotozoom_end_xloop2:
inx ; 2
cpx #40 ; 2
bne rotozoom_xloop2 ; 3
rotozoom_xloop_done2:
; yca+=ca; 8.8 fixed point
clc ; 2
lda YCAL ; 3
adc CAL ; 3
sta YCAL ; 3
lda YCAH ; 3
adc CAH ; 3
sta YCAH ; 3
;===========
; 20
; ysa+=sa; 8.8 fixed point
clc ; 2
lda YSAL ; 3
adc SAL ; 3
sta YSAL ; 3
lda YSAH ; 3
adc SAH ; 3
sta YSAH ; 3
;==========
; 20
rotozoom_end_yloop:
inc YY ; 5
ldy YY ; 3
cpy #24 ; 2
beq done_rotozoom ; 2nt/3
jmp rotozoom_yloop ; too far ; 3
done_rotozoom:
rts ; 6
fixed_sin:
; .byte $00,$00 ; 0.000000=00.00
; .byte $00,$61 ; 0.382683=00.61
; .byte $00,$b5 ; 0.707107=00.b5
; .byte $00,$ec ; 0.923880=00.ec
; .byte $01,$00 ; 1.000000=01.00
; .byte $00,$ec ; 0.923880=00.ec
; .byte $00,$b5 ; 0.707107=00.b5
; .byte $00,$61 ; 0.382683=00.61
; .byte $00,$00 ; 0.000000=00.00
; .byte $ff,$9f ; -0.382683=ff.9f
; .byte $ff,$4b ; -0.707107=ff.4b
; .byte $ff,$14 ; -0.923880=ff.14
; .byte $ff,$00 ; -1.000000=ff.00
; .byte $ff,$14 ; -0.923880=ff.14
; .byte $ff,$4b ; -0.707107=ff.4b
; .byte $ff,$9f ; -0.382683=ff.9f
.if 0
.byte $00,$00 ; 0.000000
.byte $00,$31 ; 0.195090
.byte $00,$61 ; 0.382683
.byte $00,$8E ; 0.555570
.byte $00,$B5 ; 0.707107
.byte $00,$D4 ; 0.831470
.byte $00,$EC ; 0.923880
.byte $00,$FB ; 0.980785
.byte $01,$00 ; 1.000000
.byte $00,$FB ; 0.980785
.byte $00,$EC ; 0.923880
.byte $00,$D4 ; 0.831470
.byte $00,$B5 ; 0.707107
.byte $00,$8E ; 0.555570
.byte $00,$61 ; 0.382683
.byte $00,$31 ; 0.195090
.byte $00,$00 ; 0.000000
.byte $FF,$CF ; -0.195090
.byte $FF,$9F ; -0.382683
.byte $FF,$72 ; -0.555570
.byte $FF,$4B ; -0.707107
.byte $FF,$2C ; -0.831470
.byte $FF,$14 ; -0.923880
.byte $FF,$05 ; -0.980785
.byte $FF,$00 ; -1.000000
.byte $FF,$05 ; -0.980785
.byte $FF,$14 ; -0.923880
.byte $FF,$2C ; -0.831470
.byte $FF,$4B ; -0.707107
.byte $FF,$72 ; -0.555570
.byte $FF,$9F ; -0.382683
.byte $FF,$CF ; -0.195090
.endif
.byte $00,$00 ; 0.000000
.byte $00,$19 ; 0.098017
.byte $00,$31 ; 0.195090
.byte $00,$4A ; 0.290285
.byte $00,$61 ; 0.382683
.byte $00,$78 ; 0.471397
.byte $00,$8E ; 0.555570
.byte $00,$A2 ; 0.634393
.byte $00,$B5 ; 0.707107
.byte $00,$C5 ; 0.773010
.byte $00,$D4 ; 0.831470
.byte $00,$E1 ; 0.881921
.byte $00,$EC ; 0.923880
.byte $00,$F4 ; 0.956940
.byte $00,$FB ; 0.980785
.byte $00,$FE ; 0.995185
.byte $01,$00 ; 1.000000
.byte $00,$FE ; 0.995185
.byte $00,$FB ; 0.980785
.byte $00,$F4 ; 0.956940
.byte $00,$EC ; 0.923880
.byte $00,$E1 ; 0.881921
.byte $00,$D4 ; 0.831470
.byte $00,$C5 ; 0.773010
.byte $00,$B5 ; 0.707107
.byte $00,$A2 ; 0.634393
.byte $00,$8E ; 0.555570
.byte $00,$78 ; 0.471397
.byte $00,$61 ; 0.382683
.byte $00,$4A ; 0.290285
.byte $00,$31 ; 0.195090
.byte $00,$19 ; 0.098017
.byte $00,$00 ; 0.000000
.byte $FF,$E7 ; -0.098017
.byte $FF,$CF ; -0.195090
.byte $FF,$B6 ; -0.290285
.byte $FF,$9F ; -0.382683
.byte $FF,$88 ; -0.471397
.byte $FF,$72 ; -0.555570
.byte $FF,$5E ; -0.634393
.byte $FF,$4B ; -0.707107
.byte $FF,$3B ; -0.773010
.byte $FF,$2C ; -0.831470
.byte $FF,$1F ; -0.881921
.byte $FF,$14 ; -0.923880
.byte $FF,$0C ; -0.956940
.byte $FF,$05 ; -0.980785
.byte $FF,$02 ; -0.995185
.byte $FF,$00 ; -1.000000
.byte $FF,$02 ; -0.995185
.byte $FF,$05 ; -0.980785
.byte $FF,$0C ; -0.956940
.byte $FF,$14 ; -0.923880
.byte $FF,$1F ; -0.881921
.byte $FF,$2C ; -0.831470
.byte $FF,$3B ; -0.773010
.byte $FF,$4B ; -0.707107
.byte $FF,$5E ; -0.634393
.byte $FF,$72 ; -0.555570
.byte $FF,$88 ; -0.471397
.byte $FF,$9F ; -0.382683
.byte $FF,$B6 ; -0.290285
.byte $FF,$CF ; -0.195090
.byte $FF,$E7 ; -0.098017

View File

@ -97,6 +97,7 @@ SOUND_STATUS = $A6
SOUND_MOCKINGBOARD = $02 ; mockingboard detected
JS_BUTTON_STATE = $A7
CTEMP = $C0
COLOR1 = $E0
COLOR2 = $E1
MATCH = $E2