mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-06-20 01:29:36 +00:00
rotozoom: have it working
This commit is contained in:
parent
c6f548f251
commit
b5cc84ac91
|
@ -4,7 +4,7 @@ DOS33 = ../../../utils/dos33fs-utils/dos33
|
||||||
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
|
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
|
||||||
LINKERSCRIPTS = ../../../linker_scripts
|
LINKERSCRIPTS = ../../../linker_scripts
|
||||||
|
|
||||||
all: roto.dsk
|
all: roto.dsk make_sine_table
|
||||||
|
|
||||||
roto.dsk: HELLO ROTO
|
roto.dsk: HELLO ROTO
|
||||||
cp empty.dsk roto.dsk
|
cp empty.dsk roto.dsk
|
||||||
|
@ -26,5 +26,13 @@ roto.o: roto.s rotozoom.s gr_plot.s gr_scrn.s
|
||||||
|
|
||||||
###
|
###
|
||||||
|
|
||||||
|
make_sine_table: make_sine_table.o
|
||||||
|
$(CC) -o make_sine_table make_sine_table.o -lm
|
||||||
|
|
||||||
|
make_sine_table.o: make_sine_table.c
|
||||||
|
$(CC) $(CFLAGS) -c make_sine_table.c
|
||||||
|
|
||||||
|
###
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *~ *.o *.lst ROTO
|
rm -f *~ *.o *.lst ROTO make_sine_table
|
||||||
|
|
10
graphics/gr/rotozoom/c00_scrn_offsets.s
Normal file
10
graphics/gr/rotozoom/c00_scrn_offsets.s
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
c00_scrn_offsets_l:
|
||||||
|
.byte <$c00,<$c80,<$d00,<$d80,<$e00,<$e80,<$f00,<$f80
|
||||||
|
.byte <$c28,<$ca8,<$d28,<$da8,<$e28,<$ea8,<$f28,<$fa8
|
||||||
|
.byte <$c50,<$cd0,<$d50,<$dd0,<$e50,<$ed0,<$f50,<$fd0
|
||||||
|
|
||||||
|
c00_scrn_offsets_h:
|
||||||
|
.byte >$c00,>$c80,>$d00,>$d80,>$e00,>$e80,>$f00,>$f80
|
||||||
|
.byte >$c28,>$ca8,>$d28,>$da8,>$e28,>$ea8,>$f28,>$fa8
|
||||||
|
.byte >$c50,>$cd0,>$d50,>$dd0,>$e50,>$ed0,>$f50,>$fd0
|
||||||
|
|
30
graphics/gr/rotozoom/make_sine_table.c
Normal file
30
graphics/gr/rotozoom/make_sine_table.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define PI 3.14159265358979323846264
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
int num=16,i;
|
||||||
|
short temp;
|
||||||
|
double s;
|
||||||
|
int sh,sl;
|
||||||
|
|
||||||
|
if (argc>1) {
|
||||||
|
num=atoi(argv[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i=0;i<num;i++) {
|
||||||
|
s=sin(2.0*PI*(double)i/(double)num);
|
||||||
|
temp=s*256;
|
||||||
|
sl=temp&0xff;
|
||||||
|
sh=(temp>>8)&0xff;
|
||||||
|
|
||||||
|
printf("\t.byte $%02X,$%02X ; %lf\n",sh,sl,
|
||||||
|
s);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
351
graphics/gr/rotozoom/multiply_fast.s
Normal file
351
graphics/gr/rotozoom/multiply_fast.s
Normal file
|
@ -0,0 +1,351 @@
|
||||||
|
; Fast mutiply
|
||||||
|
|
||||||
|
|
||||||
|
; Note for our purposes we only care about 8.8 x 8.8 fixed point
|
||||||
|
; with 8.8 result, which means we only care about the middle two bytes
|
||||||
|
; of the 32 bit result. So we disable generation of the high and low byte
|
||||||
|
; to save some cycles.
|
||||||
|
|
||||||
|
;
|
||||||
|
; The old routine took around 700 cycles for a 16bitx16bit=32bit mutiply
|
||||||
|
; This routine, at an expense of 2kB of looku tables, takes around 250
|
||||||
|
; If you reuse a term the next time this drops closer to 200
|
||||||
|
|
||||||
|
; This routine was described by Stephen Judd and found
|
||||||
|
; in The Fridge and in the C=Hacking magazine
|
||||||
|
; http://codebase64.org/doku.php?id=base:seriously_fast_multiplication
|
||||||
|
|
||||||
|
; The key thing to note is that
|
||||||
|
; (a+b)^2 (a-b)^2
|
||||||
|
; a*b = ------- - --------
|
||||||
|
; 4 4
|
||||||
|
; So if you have tables of the squares of 0..511 you can lookup and subtract
|
||||||
|
; instead of multiplying.
|
||||||
|
|
||||||
|
; Table generation: I:0..511
|
||||||
|
; square1_lo = <((I*I)/4)
|
||||||
|
; square1_hi = >((I*I)/4)
|
||||||
|
; square2_lo = <(((I-255)*(I-255))/4)
|
||||||
|
; square2_hi = >(((I-255)*(I-255))/4)
|
||||||
|
|
||||||
|
; Note: DOS3.3 starts at $9600
|
||||||
|
|
||||||
|
.ifndef square1_lo
|
||||||
|
square1_lo = $B400
|
||||||
|
square1_hi = $B600
|
||||||
|
square2_lo = $B800
|
||||||
|
square2_hi = $BA00
|
||||||
|
.endif
|
||||||
|
|
||||||
|
; for(i=0;i<512;i++) {
|
||||||
|
; square1_lo[i]=((i*i)/4)&0xff;
|
||||||
|
; square1_hi[i]=(((i*i)/4)>>8)&0xff;
|
||||||
|
; square2_lo[i]=( ((i-255)*(i-255))/4)&0xff;
|
||||||
|
; square2_hi[i]=(( ((i-255)*(i-255))/4)>>8)&0xff;
|
||||||
|
; }
|
||||||
|
|
||||||
|
init_multiply_tables:
|
||||||
|
|
||||||
|
; Build the add tables
|
||||||
|
|
||||||
|
ldx #$00
|
||||||
|
txa
|
||||||
|
.byte $c9 ; CMP #immediate - skip TYA and clear carry flag
|
||||||
|
lb1: tya
|
||||||
|
adc #$00 ; 0
|
||||||
|
ml1: sta square1_hi,x ; square1_hi[0]=0
|
||||||
|
tay ; y=0
|
||||||
|
cmp #$40 ; subtract 64 and update flags (c=0)
|
||||||
|
txa ; a=0
|
||||||
|
ror ; rotate
|
||||||
|
ml9: adc #$00 ; add 0
|
||||||
|
sta ml9+1 ; update add value
|
||||||
|
inx ; x=1
|
||||||
|
ml0: sta square1_lo,x ; square1_lo[0]=1
|
||||||
|
bne lb1 ; if not zero, loop
|
||||||
|
inc ml0+2 ; increment values
|
||||||
|
inc ml1+2 ; increment values
|
||||||
|
clc ; c=0
|
||||||
|
iny ; y=1
|
||||||
|
bne lb1 ; loop
|
||||||
|
|
||||||
|
; Build the subtract tables based on the existing one
|
||||||
|
|
||||||
|
ldx #$00
|
||||||
|
ldy #$ff
|
||||||
|
second_table:
|
||||||
|
lda square1_hi+1,x
|
||||||
|
sta square2_hi+$100,x
|
||||||
|
lda square1_hi,x
|
||||||
|
sta square2_hi,y
|
||||||
|
lda square1_lo+1,x
|
||||||
|
sta square2_lo+$100,x
|
||||||
|
lda square1_lo,x
|
||||||
|
sta square2_lo,y
|
||||||
|
dey
|
||||||
|
inx
|
||||||
|
bne second_table
|
||||||
|
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
; Fast 16x16 bit unsigned multiplication, 32-bit result
|
||||||
|
; Input: NUM1H:NUM1L * NUM2H:NUM2L
|
||||||
|
; Result: RESULT3:RESULT2:RESULT1:RESULT0
|
||||||
|
;
|
||||||
|
; Does self-modifying code to hard-code NUM1H:NUM1L into the code
|
||||||
|
; carry=0: re-use previous NUM1H:NUM1L
|
||||||
|
; carry=1: reload NUM1H:NUM1L (58 cycles slower)
|
||||||
|
;
|
||||||
|
; clobbered: RESULT, X, A, C
|
||||||
|
; Allocation setup: T1,T2 and RESULT preferably on Zero-page.
|
||||||
|
;
|
||||||
|
; NUM1H (x_i), NUM1L (x_f)
|
||||||
|
; NUM2H (y_i), NUM2L (y_f)
|
||||||
|
|
||||||
|
; NUM1L * NUM2L = AAaa
|
||||||
|
; NUM1L * NUM2H = BBbb
|
||||||
|
; NUM1H * NUM2L = CCcc
|
||||||
|
; NUM1H * NUM2H = DDdd
|
||||||
|
;
|
||||||
|
; AAaa
|
||||||
|
; BBbb
|
||||||
|
; CCcc
|
||||||
|
; + DDdd
|
||||||
|
; ----------
|
||||||
|
; RESULT
|
||||||
|
|
||||||
|
;fixed_16x16_mul_unsigned:
|
||||||
|
|
||||||
|
multiply:
|
||||||
|
|
||||||
|
bcc num1_same_as_last_time ; 2nt/3
|
||||||
|
|
||||||
|
;============================
|
||||||
|
; Set up self-modifying code
|
||||||
|
; this changes the code to be hard-coded to multiply by NUM1H:NUM1L
|
||||||
|
;============================
|
||||||
|
|
||||||
|
lda NUM1L ; load the low byte ; 3
|
||||||
|
sta sm1a+1 ; 3
|
||||||
|
sta sm3a+1 ; 3
|
||||||
|
sta sm5a+1 ; 3
|
||||||
|
sta sm7a+1 ; 3
|
||||||
|
eor #$ff ; invert the bits for subtracting ; 2
|
||||||
|
sta sm2a+1 ; 3
|
||||||
|
sta sm4a+1 ; 3
|
||||||
|
sta sm6a+1 ; 3
|
||||||
|
sta sm8a+1 ; 3
|
||||||
|
lda NUM1H ; load the high byte ; 3
|
||||||
|
sta sm1b+1 ; 3
|
||||||
|
sta sm3b+1 ; 3
|
||||||
|
sta sm5b+1 ; 3
|
||||||
|
; sta sm7b+1 ;
|
||||||
|
eor #$ff ; invert the bits for subtractin ; 2
|
||||||
|
sta sm2b+1 ; 3
|
||||||
|
sta sm4b+1 ; 3
|
||||||
|
sta sm6b+1 ; 3
|
||||||
|
; sta sm8b+1 ;
|
||||||
|
;===========
|
||||||
|
; 52
|
||||||
|
|
||||||
|
num1_same_as_last_time:
|
||||||
|
|
||||||
|
;==========================
|
||||||
|
; Perform NUM1L * NUM2L = AAaa
|
||||||
|
;==========================
|
||||||
|
|
||||||
|
ldx NUM2L ; (low le) ; 3
|
||||||
|
sec ; 2
|
||||||
|
sm1a:
|
||||||
|
lda square1_lo,x ; 4
|
||||||
|
sm2a:
|
||||||
|
sbc square2_lo,x ; 4
|
||||||
|
|
||||||
|
; a is _aa
|
||||||
|
|
||||||
|
; sta RESULT+0 ;
|
||||||
|
|
||||||
|
sm3a:
|
||||||
|
lda square1_hi,x ; 4
|
||||||
|
sm4a:
|
||||||
|
sbc square2_hi,x ; 4
|
||||||
|
; a is _AA
|
||||||
|
sta _AA+1 ; 3
|
||||||
|
;===========
|
||||||
|
; 24
|
||||||
|
|
||||||
|
; Perform NUM1H * NUM2L = CCcc
|
||||||
|
sec ; 2
|
||||||
|
sm1b:
|
||||||
|
lda square1_lo,x ; 4
|
||||||
|
sm2b:
|
||||||
|
sbc square2_lo,x ; 4
|
||||||
|
; a is _cc
|
||||||
|
sta _cc+1 ; 3
|
||||||
|
sm3b:
|
||||||
|
lda square1_hi,x ; 4
|
||||||
|
sm4b:
|
||||||
|
sbc square2_hi,x ; 4
|
||||||
|
; a is _CC
|
||||||
|
sta _CC+1 ; 3
|
||||||
|
;===========
|
||||||
|
; 24
|
||||||
|
|
||||||
|
;==========================
|
||||||
|
; Perform NUM1L * NUM2H = BBbb
|
||||||
|
;==========================
|
||||||
|
ldx NUM2H ; 3
|
||||||
|
sec ; 2
|
||||||
|
sm5a:
|
||||||
|
lda square1_lo,x ; 4
|
||||||
|
sm6a:
|
||||||
|
sbc square2_lo,x ; 4
|
||||||
|
; a is _bb
|
||||||
|
sta _bb+1 ; 3
|
||||||
|
|
||||||
|
sm7a:
|
||||||
|
lda square1_hi,x ; 4
|
||||||
|
sm8a:
|
||||||
|
sbc square2_hi,x ; 4
|
||||||
|
; a is _BB
|
||||||
|
sta _BB+1 ; 3
|
||||||
|
;===========
|
||||||
|
; 27
|
||||||
|
|
||||||
|
;==========================
|
||||||
|
; Perform NUM1H * NUM2H = DDdd
|
||||||
|
;==========================
|
||||||
|
sec ; 2
|
||||||
|
sm5b:
|
||||||
|
lda square1_lo,x ; 4
|
||||||
|
sm6b:
|
||||||
|
sbc square2_lo,x ; 4
|
||||||
|
; a is _dd
|
||||||
|
sta _dd+1 ; 3
|
||||||
|
;sm7b:
|
||||||
|
; lda square1_hi,x ;
|
||||||
|
;sm8b:
|
||||||
|
; sbc square2_hi,x ;
|
||||||
|
; a = _DD
|
||||||
|
; sta RESULT+3 ;
|
||||||
|
;===========
|
||||||
|
; 13
|
||||||
|
|
||||||
|
;===========================================
|
||||||
|
; Add the separate multiplications together
|
||||||
|
;===========================================
|
||||||
|
|
||||||
|
clc ; 2
|
||||||
|
_AA:
|
||||||
|
lda #0 ; loading _AA ; 2
|
||||||
|
_bb:
|
||||||
|
adc #0 ; adding in _bb ; 2
|
||||||
|
sta RESULT+1 ; 3
|
||||||
|
;==========
|
||||||
|
; 9
|
||||||
|
; product[2]=_BB+_CC+c
|
||||||
|
|
||||||
|
_BB:
|
||||||
|
lda #0 ; loading _BB ; 2
|
||||||
|
_CC:
|
||||||
|
adc #0 ; adding in _CC ; 2
|
||||||
|
sta RESULT+2 ; 3
|
||||||
|
;===========
|
||||||
|
; 7
|
||||||
|
|
||||||
|
; product[3]=_DD+c
|
||||||
|
|
||||||
|
; bcc dd_no_carry1 ;
|
||||||
|
; inc RESULT+3 ;
|
||||||
|
clc ; 2
|
||||||
|
;=============
|
||||||
|
; 2
|
||||||
|
dd_no_carry1:
|
||||||
|
|
||||||
|
; product[1]=_AA+_bb+_cc
|
||||||
|
|
||||||
|
_cc:
|
||||||
|
lda #0 ; load _cc ; 2
|
||||||
|
adc RESULT+1 ; 3
|
||||||
|
sta RESULT+1 ; 3
|
||||||
|
|
||||||
|
; product[2]=_BB+_CC+_dd+c
|
||||||
|
|
||||||
|
_dd:
|
||||||
|
lda #0 ; load _dd ; 2
|
||||||
|
adc RESULT+2 ; 3
|
||||||
|
sta RESULT+2 ; 3
|
||||||
|
|
||||||
|
;===========
|
||||||
|
; 16
|
||||||
|
; product[3]=_DD+c
|
||||||
|
|
||||||
|
|
||||||
|
; bcc dd_no_carry2 ;
|
||||||
|
; inc RESULT+3 ;
|
||||||
|
|
||||||
|
;=============
|
||||||
|
; 0
|
||||||
|
|
||||||
|
dd_no_carry2:
|
||||||
|
|
||||||
|
; *z_i=product[1];
|
||||||
|
; *z_f=product[0];
|
||||||
|
|
||||||
|
; rts ; 6
|
||||||
|
|
||||||
|
|
||||||
|
;=================
|
||||||
|
; Signed multiply
|
||||||
|
;=================
|
||||||
|
|
||||||
|
;multiply:
|
||||||
|
|
||||||
|
; jsr fixed_16x16_mul_unsigned ; 6
|
||||||
|
|
||||||
|
lda NUM1H ; x_i ; 3
|
||||||
|
;===========
|
||||||
|
; 12
|
||||||
|
|
||||||
|
|
||||||
|
bpl x_positive ;^3/2nt
|
||||||
|
|
||||||
|
sec ; 2
|
||||||
|
lda RESULT+2 ; 3
|
||||||
|
sbc NUM2L ; 3
|
||||||
|
sta RESULT+2 ; 3
|
||||||
|
; lda RESULT+3 ;
|
||||||
|
; sbc NUM2H ;
|
||||||
|
; sta RESULT+3 ;
|
||||||
|
;============
|
||||||
|
; 10
|
||||||
|
|
||||||
|
x_positive:
|
||||||
|
|
||||||
|
lda NUM2H ; y_i ; 3
|
||||||
|
;============
|
||||||
|
; ; 6
|
||||||
|
|
||||||
|
bpl y_positive ;^3/2nt
|
||||||
|
|
||||||
|
|
||||||
|
sec ; 2
|
||||||
|
lda RESULT+2 ; 3
|
||||||
|
sbc NUM1L ; 3
|
||||||
|
sta RESULT+2 ; 3
|
||||||
|
; lda RESULT+3 ;
|
||||||
|
; sbc NUM1H ;
|
||||||
|
; sta RESULT+3 ;
|
||||||
|
;===========
|
||||||
|
; 10
|
||||||
|
|
||||||
|
y_positive:
|
||||||
|
ldx RESULT+2 ; *z_i=product[2]; ; 3
|
||||||
|
lda RESULT+1 ; *z_f=product[1]; ; 3
|
||||||
|
|
||||||
|
rts ; 6
|
||||||
|
;==========
|
||||||
|
; 12
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
|
|
||||||
jsr clear_screens
|
jsr clear_screens
|
||||||
|
|
||||||
|
;===================================
|
||||||
|
; init the multiply tables
|
||||||
|
;===================================
|
||||||
|
|
||||||
|
jsr init_multiply_tables
|
||||||
|
|
||||||
;======================
|
;======================
|
||||||
; show the title screen
|
; show the title screen
|
||||||
;======================
|
;======================
|
||||||
|
@ -32,22 +38,7 @@
|
||||||
|
|
||||||
title_screen:
|
title_screen:
|
||||||
|
|
||||||
;===========================
|
jsr load_background
|
||||||
; Clear both bottoms
|
|
||||||
|
|
||||||
jsr clear_bottoms
|
|
||||||
|
|
||||||
;=============================
|
|
||||||
; Load title
|
|
||||||
|
|
||||||
lda #<(title_lzsa)
|
|
||||||
sta getsrc_smc+1
|
|
||||||
lda #>(title_lzsa)
|
|
||||||
sta getsrc_smc+2
|
|
||||||
|
|
||||||
lda #$0c
|
|
||||||
|
|
||||||
jsr decompress_lzsa2_fast
|
|
||||||
|
|
||||||
;=================================
|
;=================================
|
||||||
; copy to both pages
|
; copy to both pages
|
||||||
|
@ -61,6 +52,11 @@ title_screen:
|
||||||
|
|
||||||
lda #0
|
lda #0
|
||||||
sta ANGLE
|
sta ANGLE
|
||||||
|
sta SCALE_F
|
||||||
|
sta FRAMEL
|
||||||
|
|
||||||
|
lda #1
|
||||||
|
sta SCALE_I
|
||||||
|
|
||||||
main_loop:
|
main_loop:
|
||||||
|
|
||||||
|
@ -69,19 +65,103 @@ main_loop:
|
||||||
jsr page_flip
|
jsr page_flip
|
||||||
|
|
||||||
wait_for_keypress:
|
wait_for_keypress:
|
||||||
lda KEYPRESS
|
; lda KEYPRESS
|
||||||
bpl wait_for_keypress
|
; bpl wait_for_keypress
|
||||||
|
; bit KEYRESET
|
||||||
|
|
||||||
bit KEYRESET
|
|
||||||
|
|
||||||
inc ANGLE
|
clc
|
||||||
|
lda FRAMEL
|
||||||
|
adc direction
|
||||||
|
sta FRAMEL
|
||||||
|
|
||||||
|
cmp #$f8
|
||||||
|
beq back_at_zero
|
||||||
|
cmp #33
|
||||||
|
beq at_far_end
|
||||||
|
bne done_reverse
|
||||||
|
|
||||||
|
back_at_zero:
|
||||||
|
inc which_image
|
||||||
|
lda which_image
|
||||||
|
cmp #3
|
||||||
|
bne refresh_image
|
||||||
|
lda #0
|
||||||
|
sta which_image
|
||||||
|
refresh_image:
|
||||||
|
jsr load_background
|
||||||
|
|
||||||
|
at_far_end:
|
||||||
|
|
||||||
|
; 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
|
lda ANGLE
|
||||||
and #$f
|
adc direction
|
||||||
|
and #$1f
|
||||||
sta ANGLE
|
sta ANGLE
|
||||||
|
|
||||||
|
clc
|
||||||
|
lda SCALE_F
|
||||||
|
adc scaleaddl
|
||||||
|
sta SCALE_F
|
||||||
|
lda SCALE_I
|
||||||
|
adc scaleaddh
|
||||||
|
sta SCALE_I
|
||||||
|
|
||||||
jmp main_loop
|
jmp main_loop
|
||||||
|
|
||||||
|
|
||||||
|
direction: .byte $01
|
||||||
|
scaleaddl: .byte $10
|
||||||
|
scaleaddh: .byte $00
|
||||||
|
|
||||||
|
|
||||||
|
load_background:
|
||||||
|
|
||||||
|
;===========================
|
||||||
|
; Clear both bottoms
|
||||||
|
|
||||||
|
jsr clear_bottoms
|
||||||
|
|
||||||
|
;=============================
|
||||||
|
; Load title
|
||||||
|
|
||||||
|
lda which_image
|
||||||
|
asl
|
||||||
|
tay
|
||||||
|
|
||||||
|
lda images,Y
|
||||||
|
sta getsrc_smc+1
|
||||||
|
lda images+1,Y
|
||||||
|
sta getsrc_smc+2
|
||||||
|
|
||||||
|
lda #$0c
|
||||||
|
|
||||||
|
jsr decompress_lzsa2_fast
|
||||||
|
|
||||||
|
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
which_image: .byte $00
|
||||||
|
|
||||||
;===============================================
|
;===============================================
|
||||||
; External modules
|
; External modules
|
||||||
|
@ -93,13 +173,24 @@ wait_for_keypress:
|
||||||
.include "gr_fast_clear.s"
|
.include "gr_fast_clear.s"
|
||||||
.include "gr_copy.s"
|
.include "gr_copy.s"
|
||||||
.include "decompress_fast_v2.s"
|
.include "decompress_fast_v2.s"
|
||||||
|
|
||||||
.include "gr_offsets.s"
|
.include "gr_offsets.s"
|
||||||
|
.include "c00_scrn_offsets.s"
|
||||||
|
|
||||||
;.include "gr_plot.s"
|
;.include "gr_plot.s"
|
||||||
;.include "gr_scrn.s"
|
;.include "gr_scrn.s"
|
||||||
|
|
||||||
|
.include "multiply_fast.s"
|
||||||
|
|
||||||
;===============================================
|
;===============================================
|
||||||
; Data
|
; Data
|
||||||
;===============================================
|
;===============================================
|
||||||
|
|
||||||
.include "tfv_title.inc"
|
images:
|
||||||
|
.word title_lzsa
|
||||||
|
.word shipup_lzsa
|
||||||
|
.word monkey_lzsa
|
||||||
|
|
||||||
|
title_lzsa: .incbin "title.lzsa"
|
||||||
|
shipup_lzsa: .incbin "tree1_shipup_n.lzsa"
|
||||||
|
monkey_lzsa: .incbin "monkey.lzsa"
|
||||||
|
|
|
@ -4,7 +4,14 @@
|
||||||
; $6BD76=441,718=2.26fps initial code with external plot and scrn
|
; $6BD76=441,718=2.26fps initial code with external plot and scrn
|
||||||
; $62776=403,318=2.48fps inline plot
|
; $62776=403,318=2.48fps inline plot
|
||||||
; $597b6=366,518=2.73fps inline scrn
|
; $597b6=366,518=2.73fps inline scrn
|
||||||
; $45496=324,758=3.08fps move plot line calc outside of inner loop
|
; $4F496=324,758=3.08fps move plot line calc outside of inner loop
|
||||||
|
; $49d16=302,358=3.31fps do color*17 ourselves
|
||||||
|
; $4645e=287,838=3.47fps move XX into X
|
||||||
|
; $3ef7e=257,918=3.87fps optimize plot
|
||||||
|
; $3c9fe=248,318=4.03fps optimize scrn
|
||||||
|
; $39e3e=237,118=4.22fps add scrn address lookup table
|
||||||
|
; $39fdf=237,535 add two scale multiplies
|
||||||
|
; $39e17=237,079=4.22fps change the init to also use multiply
|
||||||
|
|
||||||
CAL = $B0
|
CAL = $B0
|
||||||
CAH = $B1
|
CAH = $B1
|
||||||
|
@ -27,67 +34,118 @@ YSAH = $BF
|
||||||
|
|
||||||
rotozoom:
|
rotozoom:
|
||||||
|
|
||||||
|
lda SCALE_I
|
||||||
|
sta NUM1H
|
||||||
|
lda SCALE_F
|
||||||
|
sta NUM1L
|
||||||
|
|
||||||
; ca = cos(theta)*scale;
|
; ca = cos(theta)*scale;
|
||||||
; ca=fixed_sin[(theta+4)&0xf]
|
; ca=fixed_sin[(theta+4)&0xf]
|
||||||
|
|
||||||
lda ANGLE ; 3
|
lda ANGLE ; 3
|
||||||
clc ; 2
|
clc ; 2
|
||||||
adc #4 ; 2
|
adc #8 ; 2
|
||||||
and #$f ; 2
|
and #$1f ; 2
|
||||||
asl ; 2
|
asl ; 2
|
||||||
tay ; 2
|
tay ; 2
|
||||||
lda fixed_sin,Y ; load integer half ; 4
|
lda fixed_sin,Y ; load integer half ; 4
|
||||||
sta CAH ; 3
|
sta NUM2H ; 3
|
||||||
lda fixed_sin+1,Y ; load integer half ; 4
|
lda fixed_sin+1,Y ; load float half ; 4
|
||||||
sta CAL ; 3
|
sta NUM2L ; 3
|
||||||
;===========
|
;===========
|
||||||
; 27
|
; 27
|
||||||
|
|
||||||
|
sec
|
||||||
|
jsr multiply
|
||||||
|
stx CAH
|
||||||
|
sta CAL
|
||||||
|
|
||||||
|
|
||||||
; sa = sin(theta)*scale;
|
; sa = sin(theta)*scale;
|
||||||
|
|
||||||
lda ANGLE ; 3
|
lda ANGLE ; 3
|
||||||
asl ; 2
|
asl ; 2
|
||||||
tay ; 2
|
tay ; 2
|
||||||
lda fixed_sin,Y ; load integer half ; 4
|
lda fixed_sin,Y ; load integer half ; 4
|
||||||
sta SAH ; 3
|
sta NUM2H ; 3
|
||||||
lda fixed_sin+1,Y ; load integer half ; 4
|
lda fixed_sin+1,Y ; load integer half ; 4
|
||||||
sta SAL ; 3
|
sta NUM2L ; 3
|
||||||
;==========
|
;==========
|
||||||
; 21
|
; 21
|
||||||
|
|
||||||
|
clc
|
||||||
|
jsr multiply
|
||||||
|
|
||||||
|
stx SAH
|
||||||
|
sta SAL
|
||||||
|
|
||||||
|
|
||||||
; cca = -20*ca;
|
; cca = -20*ca;
|
||||||
|
|
||||||
|
lda #-20
|
||||||
|
sta NUM1H
|
||||||
|
lda #0
|
||||||
|
sta NUM1L
|
||||||
|
|
||||||
|
lda CAL
|
||||||
|
sta NUM2L
|
||||||
|
lda CAH
|
||||||
|
sta NUM2H
|
||||||
|
|
||||||
|
sec
|
||||||
|
jsr multiply
|
||||||
|
stx CCAH
|
||||||
|
sta CCAL
|
||||||
|
|
||||||
|
|
||||||
; csa = -20*sa;
|
; csa = -20*sa;
|
||||||
|
|
||||||
lda #0 ; 2
|
lda SAL
|
||||||
sta CCAL ; 3
|
sta NUM2L
|
||||||
sta CCAH ; 3
|
lda SAH
|
||||||
sta CSAL ; 3
|
sta NUM2H
|
||||||
sta CSAH ; 3
|
|
||||||
|
clc
|
||||||
|
jsr multiply
|
||||||
|
|
||||||
|
stx CSAH
|
||||||
|
sta CSAL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; lda #0 ; 2
|
||||||
|
; sta CCAL ; 3
|
||||||
|
; sta CCAH ; 3
|
||||||
|
; sta CSAL ; 3
|
||||||
|
; sta CSAH ; 3
|
||||||
;===========
|
;===========
|
||||||
; 14
|
; 14
|
||||||
|
|
||||||
ldx #20 ; 2
|
; ldx #20 ; 2
|
||||||
mul20_loop:
|
;mul20_loop:
|
||||||
sec ; 2
|
; sec ; 2
|
||||||
lda CCAL ; 3
|
; lda CCAL ; 3
|
||||||
sbc CAL ; 3
|
; sbc CAL ; 3
|
||||||
sta CCAL ; 3
|
; sta CCAL ; 3
|
||||||
lda CCAH ; 3
|
; lda CCAH ; 3
|
||||||
sbc CAH ; 3
|
; sbc CAH ; 3
|
||||||
sta CCAH ; 3
|
; sta CCAH ; 3
|
||||||
;===========
|
;===========
|
||||||
; 20
|
; 20
|
||||||
|
|
||||||
sec ; 2
|
; sec ; 2
|
||||||
lda CSAL ; 3
|
; lda CSAL ; 3
|
||||||
sbc SAL ; 3
|
; sbc SAL ; 3
|
||||||
sta CSAL ; 3
|
; sta CSAL ; 3
|
||||||
lda CSAH ; 3
|
; lda CSAH ; 3
|
||||||
sbc SAH ; 3
|
; sbc SAH ; 3
|
||||||
sta CSAH ; 3
|
; sta CSAH ; 3
|
||||||
;===========
|
;===========
|
||||||
; 20
|
; 20
|
||||||
|
|
||||||
dex ; 2
|
; dex ; 2
|
||||||
bne mul20_loop ;2nt/3
|
; bne mul20_loop ;2nt/3
|
||||||
|
|
||||||
;===================
|
;===================
|
||||||
; total=2+(45*20)-1
|
; total=2+(45*20)-1
|
||||||
|
@ -146,7 +204,17 @@ rotozoom_yloop:
|
||||||
|
|
||||||
; setup self-modifying code for plot
|
; setup self-modifying code for plot
|
||||||
lda YY ; 3
|
lda YY ; 3
|
||||||
and #$fe ; make even ; 2
|
lsr ; get low bit in carry ; 2
|
||||||
|
bcc smc_even ; 2nt/3
|
||||||
|
smc_odd:
|
||||||
|
ldy #$2c ; bit ; 2
|
||||||
|
jmp smc_write ; 3
|
||||||
|
smc_even:
|
||||||
|
ldy #$4c ; jmp ; 2
|
||||||
|
smc_write:
|
||||||
|
sty rplot3_smc ; 4
|
||||||
|
asl ; now even ; 2
|
||||||
|
|
||||||
tay ; 2
|
tay ; 2
|
||||||
|
|
||||||
lda gr_offsets,Y ; lookup low-res memory address ; 4
|
lda gr_offsets,Y ; lookup low-res memory address ; 4
|
||||||
|
@ -160,55 +228,69 @@ rotozoom_yloop:
|
||||||
sta rplot2_smc+2 ; 4
|
sta rplot2_smc+2 ; 4
|
||||||
|
|
||||||
; for(xx=0;xx<40;xx++) {
|
; for(xx=0;xx<40;xx++) {
|
||||||
lda #0 ; 2
|
ldx #0 ; 2
|
||||||
sta XX ; 3
|
|
||||||
rotozoom_xloop:
|
rotozoom_xloop:
|
||||||
|
;==========================
|
||||||
|
; note: every cycle saved below here
|
||||||
|
; saves 1600 cycles
|
||||||
|
;==========================
|
||||||
|
|
||||||
|
|
||||||
; if ((xp<0) || (xp>39)) color=0;
|
; if ((xp<0) || (xp>39)) color=0;
|
||||||
; else if ((yp<0) || (yp>39)) color=0;
|
; else if ((yp<0) || (yp>39)) color=0;
|
||||||
; else color=scrn_page(xp,yp,PAGE2);
|
; else color=scrn_page(xp,yp,PAGE2);
|
||||||
|
|
||||||
lda #0 ; 2
|
; 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
|
||||||
|
|
||||||
ldx XPH ; 3
|
lda #0 ; default color ; 2
|
||||||
bmi rotozoom_set_color ; 2nt/3
|
|
||||||
cpx #40 ; 2
|
ldy XPH ; 3
|
||||||
bcs rotozoom_set_color ; 2nt/3
|
bmi rplot ; 2nt/3
|
||||||
|
cpy #40 ; 2
|
||||||
|
bcs rplot ; 2nt/3
|
||||||
|
|
||||||
|
ldy YPH ; 3
|
||||||
|
bmi rplot ; 2nt/3
|
||||||
|
cpy #40 ; 2
|
||||||
|
bcs rplot ; 2nt/3
|
||||||
|
|
||||||
ldx YPH ; 3
|
|
||||||
bmi rotozoom_set_color ; 2nt/3
|
|
||||||
cpx #40 ; 2
|
|
||||||
bcs rotozoom_set_color ; 2nt/3
|
|
||||||
|
|
||||||
; scrn(xp,yp)
|
|
||||||
|
|
||||||
;==================================================
|
;==================================================
|
||||||
|
|
||||||
lda YPH ; 3
|
; scrn(xp,yp)
|
||||||
|
|
||||||
and #$fe ; make even ; 2
|
tya ; YPH ; 2
|
||||||
|
|
||||||
|
lsr ; divide to get index, also low bit in carry ; 2
|
||||||
tay ; 2
|
tay ; 2
|
||||||
|
|
||||||
lda gr_offsets,Y ; lookup low-res memory address ; 4
|
; TODO: put these in zero page?
|
||||||
clc ; 2
|
; also we can share low bytes with other lookup
|
||||||
adc XPH ; 3
|
|
||||||
sta BASL ; 3
|
|
||||||
|
|
||||||
lda gr_offsets+1,Y ; 4
|
lda c00_scrn_offsets_l,Y ; lookup low-res memory address ; 4
|
||||||
adc #$8 ; assume reading from $c0 ; 3
|
sta BASL ; 3
|
||||||
|
lda c00_scrn_offsets_h,Y ; 4
|
||||||
sta BASH ; 3
|
sta BASH ; 3
|
||||||
|
|
||||||
ldy #0 ; 2
|
; carry was set a bit before to low bit of YPH
|
||||||
|
; hopefully nothing has cleared it
|
||||||
|
|
||||||
lda YPH ; 3
|
bcs rscrn_adjust_odd ; 3
|
||||||
lsr ; 2
|
|
||||||
bcs rscrn_adjust_even ;2nt/3t
|
|
||||||
|
|
||||||
rscrn_adjust_odd:
|
|
||||||
lda (BASL),Y ; top/bottom color ; 5+
|
|
||||||
jmp rscrn_done ; 3
|
|
||||||
|
|
||||||
rscrn_adjust_even:
|
rscrn_adjust_even:
|
||||||
|
ldy XPH ; 3
|
||||||
|
; want bottom
|
||||||
|
lda (BASL),Y ; top/bottom color ; 5+
|
||||||
|
and #$f ; 2
|
||||||
|
jmp rscrn_done ; 3
|
||||||
|
|
||||||
|
rscrn_adjust_odd:
|
||||||
|
ldy XPH ; 3
|
||||||
|
; want top
|
||||||
lda (BASL),Y ; top/bottom color ; 5+
|
lda (BASL),Y ; top/bottom color ; 5+
|
||||||
|
|
||||||
lsr ; 2
|
lsr ; 2
|
||||||
|
@ -218,49 +300,48 @@ rscrn_adjust_even:
|
||||||
|
|
||||||
rscrn_done:
|
rscrn_done:
|
||||||
|
|
||||||
and #$f ; 2
|
|
||||||
|
|
||||||
;=============================================
|
;=============================================
|
||||||
|
|
||||||
|
|
||||||
rotozoom_set_color:
|
rotozoom_set_color:
|
||||||
; color_equals(color);
|
; want same color in top and bottom nibbles
|
||||||
jsr SETCOL ; 6+??
|
sta TEMP ; 3
|
||||||
|
asl ; 2
|
||||||
|
asl ; 2
|
||||||
|
asl ; 2
|
||||||
|
asl ; 2
|
||||||
|
ora TEMP ; 3
|
||||||
|
;==========
|
||||||
|
; 14
|
||||||
|
|
||||||
;=================================================
|
;=================================================
|
||||||
|
|
||||||
; plot(xx,yy);
|
rplot:
|
||||||
|
|
||||||
lda YY ; 3
|
; plot(xx,yy); (color is in A)
|
||||||
|
|
||||||
lsr ; shift bottom bit into carry ; 2
|
; smc based on if Y is odd or even
|
||||||
|
rplot3_smc:
|
||||||
|
jmp rplot_even ; 3
|
||||||
|
|
||||||
bcc rplot_even ; 2nt/3
|
|
||||||
rplot_odd:
|
rplot_odd:
|
||||||
ldx #$f0 ; 2
|
and #$f0 ; 2
|
||||||
bcs rplot_c_done ;bra ; 3
|
sta COLOR ; 3
|
||||||
|
lda #$0f ; 2
|
||||||
|
bne rplot1_smc ; bra ; 3
|
||||||
|
|
||||||
rplot_even:
|
rplot_even:
|
||||||
ldx #$0f ; 2
|
and #$0f ; 2
|
||||||
rplot_c_done:
|
sta COLOR ; 3
|
||||||
stx MASK ; 3
|
lda #$f0 ; 2
|
||||||
|
|
||||||
rplot_write:
|
|
||||||
|
|
||||||
ldy XX ; 3
|
|
||||||
|
|
||||||
lda MASK ; 3
|
|
||||||
eor #$ff ; 2
|
|
||||||
|
|
||||||
rplot1_smc:
|
rplot1_smc:
|
||||||
and $400,Y ; 4+
|
and $400,X ; 4
|
||||||
sta COLOR_MASK ; 3
|
ora COLOR ; 3
|
||||||
|
|
||||||
lda COLOR ; 3
|
|
||||||
and MASK ; 3
|
|
||||||
ora COLOR_MASK ; 3
|
|
||||||
rplot2_smc:
|
rplot2_smc:
|
||||||
sta $400,Y ; 5+
|
sta $400,X ; 5
|
||||||
|
|
||||||
|
|
||||||
;=======================
|
;=======================
|
||||||
|
@ -287,9 +368,8 @@ rplot2_smc:
|
||||||
|
|
||||||
|
|
||||||
rotozoom_end_xloop:
|
rotozoom_end_xloop:
|
||||||
inc XX ; 5
|
inx ; 2
|
||||||
lda XX ; 3
|
cpx #40 ; 2
|
||||||
cmp #40 ; 2
|
|
||||||
beq rotozoom_xloop_done ; 2nt/3
|
beq rotozoom_xloop_done ; 2nt/3
|
||||||
jmp rotozoom_xloop ; 3
|
jmp rotozoom_xloop ; 3
|
||||||
rotozoom_xloop_done:
|
rotozoom_xloop_done:
|
||||||
|
@ -331,20 +411,52 @@ done_rotozoom:
|
||||||
|
|
||||||
|
|
||||||
fixed_sin:
|
fixed_sin:
|
||||||
.byte $00,$00 ; 0.000000=00.00
|
; .byte $00,$00 ; 0.000000=00.00
|
||||||
.byte $00,$61 ; 0.382683=00.61
|
; .byte $00,$61 ; 0.382683=00.61
|
||||||
.byte $00,$b5 ; 0.707107=00.b5
|
; .byte $00,$b5 ; 0.707107=00.b5
|
||||||
.byte $00,$ec ; 0.923880=00.ec
|
; .byte $00,$ec ; 0.923880=00.ec
|
||||||
.byte $01,$00 ; 1.000000=01.00
|
; .byte $01,$00 ; 1.000000=01.00
|
||||||
.byte $00,$ec ; 0.923880=00.ec
|
; .byte $00,$ec ; 0.923880=00.ec
|
||||||
.byte $00,$b5 ; 0.707107=00.b5
|
; .byte $00,$b5 ; 0.707107=00.b5
|
||||||
.byte $00,$61 ; 0.382683=00.61
|
; .byte $00,$61 ; 0.382683=00.61
|
||||||
.byte $00,$00 ; 0.000000=00.00
|
; .byte $00,$00 ; 0.000000=00.00
|
||||||
.byte $ff,$9f ; -0.382683=ff.9f
|
; .byte $ff,$9f ; -0.382683=ff.9f
|
||||||
.byte $ff,$4b ; -0.707107=ff.4b
|
; .byte $ff,$4b ; -0.707107=ff.4b
|
||||||
.byte $ff,$14 ; -0.923880=ff.14
|
; .byte $ff,$14 ; -0.923880=ff.14
|
||||||
.byte $ff,$00 ; -1.000000=ff.00
|
; .byte $ff,$00 ; -1.000000=ff.00
|
||||||
.byte $ff,$14 ; -0.923880=ff.14
|
; .byte $ff,$14 ; -0.923880=ff.14
|
||||||
.byte $ff,$4b ; -0.707107=ff.4b
|
; .byte $ff,$4b ; -0.707107=ff.4b
|
||||||
.byte $ff,$9f ; -0.382683=ff.9f
|
; .byte $ff,$9f ; -0.382683=ff.9f
|
||||||
|
|
||||||
|
.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
|
||||||
|
|
|
@ -30,6 +30,10 @@ SCREEN_Y = $62
|
||||||
ANGLE = $63
|
ANGLE = $63
|
||||||
HORIZ_SCALE_I = $64
|
HORIZ_SCALE_I = $64
|
||||||
HORIZ_SCALE_F = $65
|
HORIZ_SCALE_F = $65
|
||||||
|
|
||||||
|
SCALE_I = $64
|
||||||
|
SCALE_F = $65
|
||||||
|
|
||||||
FACTOR_I = $66
|
FACTOR_I = $66
|
||||||
FACTOR_F = $67
|
FACTOR_F = $67
|
||||||
DX_I = $68
|
DX_I = $68
|
||||||
|
|
Loading…
Reference in New Issue
Block a user