2019-06-29 07:55:12 +00:00
|
|
|
// Find atan2(x, y) using the CORDIC method
|
|
|
|
// See http://bsvi.ru/uploads/CORDIC--_10EBA/cordic.pdf
|
|
|
|
.pc = $801 "Basic"
|
|
|
|
:BasicUpstart(main)
|
|
|
|
.pc = $80d "Program"
|
|
|
|
// The number of iterations performed during 16-bit CORDIC atan2 calculation
|
|
|
|
.const CORDIC_ITERATIONS_16 = $f
|
|
|
|
.label D018 = $d018
|
|
|
|
// Color Ram
|
|
|
|
.label COLS = $d800
|
|
|
|
.label CHARSET = $2000
|
|
|
|
.label SCREEN = $2800
|
2020-06-27 18:32:09 +00:00
|
|
|
.label print_screen = $400
|
2020-03-08 22:26:49 +00:00
|
|
|
.label print_char_cursor = 8
|
2019-06-29 07:55:12 +00:00
|
|
|
main: {
|
|
|
|
.const toD0181_return = (>(SCREEN&$3fff)*4)|(>CHARSET)/4&$f
|
2020-04-30 20:15:59 +00:00
|
|
|
.label col00 = COLS+$c*$28+$13
|
2020-04-19 09:05:54 +00:00
|
|
|
.label __4 = $a
|
2020-03-08 22:26:49 +00:00
|
|
|
.label xw = $17
|
|
|
|
.label yw = $19
|
|
|
|
.label angle_w = $a
|
|
|
|
.label diff_sum = 4
|
|
|
|
.label screen = 6
|
|
|
|
.label screen_ref = 8
|
|
|
|
.label x = 3
|
|
|
|
.label y = 2
|
2020-02-23 08:44:36 +00:00
|
|
|
// init_font_hex(CHARSET)
|
2019-06-29 07:55:12 +00:00
|
|
|
jsr init_font_hex
|
2020-02-23 08:44:36 +00:00
|
|
|
// *D018 = toD018(SCREEN, CHARSET)
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #toD0181_return
|
|
|
|
sta D018
|
|
|
|
lda #<SCREEN
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>SCREEN
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen+1
|
2019-07-10 18:54:35 +00:00
|
|
|
lda #<0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z diff_sum
|
|
|
|
sta.z diff_sum+1
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #<SCREEN_REF
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen_ref
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>SCREEN_REF
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z screen_ref+1
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #-$c
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z y
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2019-07-04 17:56:11 +00:00
|
|
|
lda #-$13
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z x
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-04-19 09:05:54 +00:00
|
|
|
// xw = (signed word)(word){ (byte)x, 0 }
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z x
|
2019-06-29 07:55:12 +00:00
|
|
|
ldy #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z xw+1
|
|
|
|
sty.z xw
|
2020-04-19 09:05:54 +00:00
|
|
|
// yw = (signed word)(word){ (byte)y, 0 }
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z y
|
|
|
|
sta.z yw+1
|
|
|
|
sty.z yw
|
2020-02-23 08:44:36 +00:00
|
|
|
// atan2_16(xw, yw)
|
2019-06-29 07:55:12 +00:00
|
|
|
jsr atan2_16
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle_w = atan2_16(xw, yw)
|
|
|
|
// angle_w+0x0080
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #$80
|
|
|
|
clc
|
2020-04-19 09:05:54 +00:00
|
|
|
adc.z __4
|
|
|
|
sta.z __4
|
2019-06-29 08:08:46 +00:00
|
|
|
bcc !+
|
2020-04-19 09:05:54 +00:00
|
|
|
inc.z __4+1
|
2019-06-29 08:08:46 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// ang_w = >(angle_w+0x0080)
|
2020-04-19 09:05:54 +00:00
|
|
|
ldx.z __4+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// diff(ang_w, *screen_ref)
|
2019-06-29 08:08:46 +00:00
|
|
|
ldy #0
|
|
|
|
lda (screen_ref),y
|
|
|
|
jsr diff
|
2020-02-23 08:44:36 +00:00
|
|
|
// diff_sum += diff(ang_w, *screen_ref)
|
2019-06-29 08:08:46 +00:00
|
|
|
//*screen = (>angle_w)-angle_b;
|
|
|
|
//*screen = >angle_w;
|
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z diff_sum
|
|
|
|
sta.z diff_sum
|
2019-06-29 07:55:12 +00:00
|
|
|
bcc !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z diff_sum+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// ang_w - *screen_ref
|
2019-07-04 17:56:11 +00:00
|
|
|
txa
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
|
|
|
ldy #0
|
|
|
|
sbc (screen_ref),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// *screen = ang_w - *screen_ref
|
2019-06-29 07:55:12 +00:00
|
|
|
sta (screen),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// screen++;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z screen
|
2019-06-29 07:55:12 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z screen+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// screen_ref++;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z screen_ref
|
2019-06-29 07:55:12 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z screen_ref+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// for(signed byte x: -19..20)
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z x
|
2019-07-04 17:56:11 +00:00
|
|
|
lda #$15
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z x
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// for(signed byte y: -12..12)
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z y
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #$d
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z y
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b1
|
2020-04-13 18:00:13 +00:00
|
|
|
// print_uint(diff_sum)
|
|
|
|
jsr print_uint
|
2019-09-29 21:13:37 +00:00
|
|
|
__b5:
|
2020-02-23 08:44:36 +00:00
|
|
|
// (*col00)++;
|
2019-11-03 16:05:55 +00:00
|
|
|
inc col00
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b5
|
2019-06-29 08:08:46 +00:00
|
|
|
}
|
2020-04-13 18:00:13 +00:00
|
|
|
// Print a unsigned int as HEX
|
|
|
|
// print_uint(word zp(4) w)
|
|
|
|
print_uint: {
|
2020-03-08 22:26:49 +00:00
|
|
|
.label w = 4
|
2020-04-13 18:06:30 +00:00
|
|
|
// print_uchar(>w)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z w+1
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #<print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_char_cursor
|
2020-06-27 18:32:09 +00:00
|
|
|
lda #>print_screen
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z print_char_cursor+1
|
2020-04-13 18:06:30 +00:00
|
|
|
jsr print_uchar
|
|
|
|
// print_uchar(<w)
|
2020-03-22 21:26:39 +00:00
|
|
|
ldx.z w
|
2020-04-13 18:06:30 +00:00
|
|
|
jsr print_uchar
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 08:08:46 +00:00
|
|
|
rts
|
|
|
|
}
|
2020-04-13 18:00:13 +00:00
|
|
|
// Print a char as HEX
|
2020-04-13 18:06:30 +00:00
|
|
|
// print_uchar(byte register(X) b)
|
|
|
|
print_uchar: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// b>>4
|
2019-06-29 08:08:46 +00:00
|
|
|
txa
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_char(print_hextab[b>>4])
|
2019-06-29 08:08:46 +00:00
|
|
|
tay
|
|
|
|
lda print_hextab,y
|
2020-03-07 21:38:40 +00:00
|
|
|
// Table of hexadecimal digits
|
2019-06-29 08:08:46 +00:00
|
|
|
jsr print_char
|
2020-02-23 08:44:36 +00:00
|
|
|
// b&$f
|
2019-06-29 08:08:46 +00:00
|
|
|
lda #$f
|
|
|
|
axs #0
|
2020-02-23 08:44:36 +00:00
|
|
|
// print_char(print_hextab[b&$f])
|
2019-06-29 08:08:46 +00:00
|
|
|
lda print_hextab,x
|
|
|
|
jsr print_char
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 08:08:46 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// Print a single char
|
|
|
|
// print_char(byte register(A) ch)
|
|
|
|
print_char: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// *(print_char_cursor++) = ch
|
2019-06-29 08:08:46 +00:00
|
|
|
ldy #0
|
|
|
|
sta (print_char_cursor),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// *(print_char_cursor++) = ch;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z print_char_cursor
|
2019-06-29 08:08:46 +00:00
|
|
|
bne !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z print_char_cursor+1
|
2019-06-29 08:08:46 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 08:08:46 +00:00
|
|
|
rts
|
|
|
|
}
|
2019-07-04 17:56:11 +00:00
|
|
|
// diff(byte register(X) bb1, byte register(A) bb2)
|
2019-06-29 08:08:46 +00:00
|
|
|
diff: {
|
2020-02-23 08:44:36 +00:00
|
|
|
// (bb1<bb2)?(bb2-bb1):bb1-bb2
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z $ff
|
|
|
|
cpx.z $ff
|
2019-09-29 21:13:37 +00:00
|
|
|
bcc __b1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z $ff
|
2019-07-04 17:56:11 +00:00
|
|
|
txa
|
2019-06-29 08:08:46 +00:00
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z $ff
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 08:08:46 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2020-02-23 08:44:36 +00:00
|
|
|
// (bb1<bb2)?(bb2-bb1):bb1-bb2
|
2019-08-07 19:00:19 +00:00
|
|
|
stx.z $ff
|
2019-06-29 08:08:46 +00:00
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z $ff
|
2019-06-29 08:08:46 +00:00
|
|
|
rts
|
2019-06-29 07:55:12 +00:00
|
|
|
}
|
|
|
|
// Find the atan2(x, y) - which is the angle of the line from (0,0) to (x,y)
|
|
|
|
// Finding the angle requires a binary search using CORDIC_ITERATIONS_16
|
|
|
|
// Returns the angle in hex-degrees (0=0, 0x8000=PI, 0x10000=2*PI)
|
2020-03-08 22:26:49 +00:00
|
|
|
// atan2_16(signed word zp($17) x, signed word zp($19) y)
|
2019-06-29 07:55:12 +00:00
|
|
|
atan2_16: {
|
2020-03-08 22:26:49 +00:00
|
|
|
.label __2 = $e
|
|
|
|
.label __7 = $11
|
|
|
|
.label yi = $e
|
|
|
|
.label xi = $11
|
|
|
|
.label angle = $a
|
|
|
|
.label xd = $c
|
|
|
|
.label yd = $13
|
|
|
|
.label return = $a
|
|
|
|
.label x = $17
|
|
|
|
.label y = $19
|
2020-02-23 08:44:36 +00:00
|
|
|
// (y>=0)?y:-y
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z y+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bmi !__b1+
|
|
|
|
jmp __b1
|
|
|
|
!__b1:
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z y
|
2019-09-29 21:13:37 +00:00
|
|
|
sta.z __2
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z y+1
|
2019-09-29 21:13:37 +00:00
|
|
|
sta.z __2+1
|
|
|
|
__b3:
|
2020-02-23 08:44:36 +00:00
|
|
|
// (x>=0)?x:-x
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z x+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bmi !__b4+
|
|
|
|
jmp __b4
|
|
|
|
!__b4:
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z x
|
2019-09-29 21:13:37 +00:00
|
|
|
sta.z __7
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z x+1
|
2019-09-29 21:13:37 +00:00
|
|
|
sta.z __7+1
|
|
|
|
__b6:
|
2019-07-10 18:54:35 +00:00
|
|
|
lda #<0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z angle
|
|
|
|
sta.z angle+1
|
2019-07-04 17:56:11 +00:00
|
|
|
tax
|
2019-09-29 21:13:37 +00:00
|
|
|
__b10:
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(yi==0)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yi+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b11
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yi
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b11
|
|
|
|
__b12:
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle /=2
|
2019-08-07 19:00:19 +00:00
|
|
|
lsr.z angle+1
|
|
|
|
ror.z angle
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(x<0)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z x+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bpl __b7
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle = 0x8000-angle
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
|
|
|
lda #<$8000
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z angle
|
|
|
|
sta.z angle
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>$8000
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z angle+1
|
|
|
|
sta.z angle+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b7:
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(y<0)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z y+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bpl __b8
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle = -angle
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z angle
|
|
|
|
sta.z angle
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z angle+1
|
|
|
|
sta.z angle+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b8:
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 07:55:12 +00:00
|
|
|
rts
|
2019-09-29 21:13:37 +00:00
|
|
|
__b11:
|
2019-07-04 17:56:11 +00:00
|
|
|
txa
|
|
|
|
tay
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z xi
|
|
|
|
sta.z xd
|
|
|
|
lda.z xi+1
|
|
|
|
sta.z xd+1
|
|
|
|
lda.z yi
|
|
|
|
sta.z yd
|
|
|
|
lda.z yi+1
|
|
|
|
sta.z yd+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b13:
|
2020-02-23 08:44:36 +00:00
|
|
|
// while(shift>=2)
|
2019-07-05 04:56:24 +00:00
|
|
|
cpy #2
|
2019-09-29 21:13:37 +00:00
|
|
|
bcs __b14
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(shift)
|
2019-06-29 07:55:12 +00:00
|
|
|
cpy #0
|
2019-09-29 21:13:37 +00:00
|
|
|
beq __b17
|
2020-02-23 08:44:36 +00:00
|
|
|
// xd >>= 1
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z xd+1
|
2019-07-04 17:56:11 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z xd+1
|
|
|
|
ror.z xd
|
2020-02-23 08:44:36 +00:00
|
|
|
// yd >>= 1
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yd+1
|
2019-06-29 07:55:12 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z yd+1
|
|
|
|
ror.z yd
|
2019-09-29 21:13:37 +00:00
|
|
|
__b17:
|
2020-02-23 08:44:36 +00:00
|
|
|
// if(yi>=0)
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yi+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bpl __b18
|
2020-02-23 08:44:36 +00:00
|
|
|
// xi -= yd
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z xi
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z yd
|
|
|
|
sta.z xi
|
|
|
|
lda.z xi+1
|
|
|
|
sbc.z yd+1
|
|
|
|
sta.z xi+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// yi += xd
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yi
|
2019-06-29 07:55:12 +00:00
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z xd
|
|
|
|
sta.z yi
|
|
|
|
lda.z yi+1
|
|
|
|
adc.z xd+1
|
|
|
|
sta.z yi+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle -= CORDIC_ATAN2_ANGLES_16[i]
|
2019-07-04 17:56:11 +00:00
|
|
|
txa
|
2019-06-29 07:55:12 +00:00
|
|
|
asl
|
|
|
|
tay
|
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z angle
|
2019-06-29 07:55:12 +00:00
|
|
|
sbc CORDIC_ATAN2_ANGLES_16,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z angle
|
|
|
|
lda.z angle+1
|
2019-06-29 07:55:12 +00:00
|
|
|
sbc CORDIC_ATAN2_ANGLES_16+1,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z angle+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b19:
|
2020-04-13 18:00:13 +00:00
|
|
|
// for( char i: 0..CORDIC_ITERATIONS_16-1)
|
2019-07-04 17:56:11 +00:00
|
|
|
inx
|
|
|
|
cpx #CORDIC_ITERATIONS_16-1+1
|
2019-09-29 21:13:37 +00:00
|
|
|
bne !__b12+
|
|
|
|
jmp __b12
|
|
|
|
!__b12:
|
|
|
|
jmp __b10
|
|
|
|
__b18:
|
2020-02-23 08:44:36 +00:00
|
|
|
// xi += yd
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z xi
|
2019-06-29 07:55:12 +00:00
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z yd
|
|
|
|
sta.z xi
|
|
|
|
lda.z xi+1
|
|
|
|
adc.z yd+1
|
|
|
|
sta.z xi+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// yi -= xd
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yi
|
2019-06-29 07:55:12 +00:00
|
|
|
sec
|
2019-08-07 19:00:19 +00:00
|
|
|
sbc.z xd
|
|
|
|
sta.z yi
|
|
|
|
lda.z yi+1
|
|
|
|
sbc.z xd+1
|
|
|
|
sta.z yi+1
|
2020-02-23 08:44:36 +00:00
|
|
|
// angle += CORDIC_ATAN2_ANGLES_16[i]
|
2019-07-04 17:56:11 +00:00
|
|
|
txa
|
2019-06-29 07:55:12 +00:00
|
|
|
asl
|
|
|
|
tay
|
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z angle
|
2019-06-29 07:55:12 +00:00
|
|
|
adc CORDIC_ATAN2_ANGLES_16,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z angle
|
|
|
|
lda.z angle+1
|
2019-06-29 07:55:12 +00:00
|
|
|
adc CORDIC_ATAN2_ANGLES_16+1,y
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z angle+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b19
|
|
|
|
__b14:
|
2020-02-23 08:44:36 +00:00
|
|
|
// xd >>= 2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z xd+1
|
2019-07-04 17:56:11 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z xd+1
|
|
|
|
ror.z xd
|
|
|
|
lda.z xd+1
|
2019-07-04 17:56:11 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z xd+1
|
|
|
|
ror.z xd
|
2020-02-23 08:44:36 +00:00
|
|
|
// yd >>= 2
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z yd+1
|
2019-07-04 17:56:11 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z yd+1
|
|
|
|
ror.z yd
|
|
|
|
lda.z yd+1
|
2019-07-04 17:56:11 +00:00
|
|
|
cmp #$80
|
2019-08-07 19:00:19 +00:00
|
|
|
ror.z yd+1
|
|
|
|
ror.z yd
|
2020-02-23 08:44:36 +00:00
|
|
|
// shift -=2
|
2019-07-04 17:56:11 +00:00
|
|
|
dey
|
|
|
|
dey
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b13
|
|
|
|
__b4:
|
2020-03-07 21:38:40 +00:00
|
|
|
// (x>=0)?x:-x
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z x
|
|
|
|
sta.z xi
|
|
|
|
lda.z x+1
|
|
|
|
sta.z xi+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b6
|
|
|
|
__b1:
|
2020-03-07 21:38:40 +00:00
|
|
|
// (y>=0)?y:-y
|
2019-08-07 19:00:19 +00:00
|
|
|
lda.z y
|
|
|
|
sta.z yi
|
|
|
|
lda.z y+1
|
|
|
|
sta.z yi+1
|
2019-09-29 21:13:37 +00:00
|
|
|
jmp __b3
|
2019-06-29 07:55:12 +00:00
|
|
|
}
|
|
|
|
// Make charset from proto chars
|
2020-03-08 22:26:49 +00:00
|
|
|
// init_font_hex(byte* zp($11) charset)
|
2019-06-29 07:55:12 +00:00
|
|
|
init_font_hex: {
|
2020-03-08 22:26:49 +00:00
|
|
|
.label __0 = $1b
|
|
|
|
.label idx = $16
|
|
|
|
.label proto_lo = $13
|
|
|
|
.label charset = $11
|
|
|
|
.label c1 = $15
|
|
|
|
.label proto_hi = $e
|
|
|
|
.label c = $10
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z c
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #<FONT_HEX_PROTO
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z proto_hi
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>FONT_HEX_PROTO
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z proto_hi+1
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #<CHARSET
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z charset
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>CHARSET
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z charset+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b1:
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z c1
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #<FONT_HEX_PROTO
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z proto_lo
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #>FONT_HEX_PROTO
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z proto_lo+1
|
2019-09-29 21:13:37 +00:00
|
|
|
__b2:
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = 0
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
|
|
|
tay
|
|
|
|
sta (charset),y
|
|
|
|
lda #1
|
2019-08-07 19:00:19 +00:00
|
|
|
sta.z idx
|
2019-06-29 07:55:12 +00:00
|
|
|
ldx #0
|
2019-09-29 21:13:37 +00:00
|
|
|
__b3:
|
2020-02-23 08:44:36 +00:00
|
|
|
// proto_hi[i]<<4
|
2019-06-29 07:55:12 +00:00
|
|
|
txa
|
|
|
|
tay
|
|
|
|
lda (proto_hi),y
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl
|
|
|
|
asl
|
2019-09-29 21:13:37 +00:00
|
|
|
sta.z __0
|
2020-02-23 08:44:36 +00:00
|
|
|
// proto_lo[i]<<1
|
2019-06-29 07:55:12 +00:00
|
|
|
txa
|
|
|
|
tay
|
|
|
|
lda (proto_lo),y
|
|
|
|
asl
|
2020-02-23 08:44:36 +00:00
|
|
|
// proto_hi[i]<<4 | proto_lo[i]<<1
|
2019-09-29 21:13:37 +00:00
|
|
|
ora.z __0
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = proto_hi[i]<<4 | proto_lo[i]<<1
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z idx
|
2019-06-29 07:55:12 +00:00
|
|
|
sta (charset),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = proto_hi[i]<<4 | proto_lo[i]<<1;
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z idx
|
2020-02-23 08:44:36 +00:00
|
|
|
// for( byte i: 0..4)
|
2019-06-29 07:55:12 +00:00
|
|
|
inx
|
|
|
|
cpx #5
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b3
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = 0
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #0
|
2019-08-07 19:00:19 +00:00
|
|
|
ldy.z idx
|
2019-06-29 07:55:12 +00:00
|
|
|
sta (charset),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = 0;
|
2019-06-29 07:55:12 +00:00
|
|
|
iny
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset[idx++] = 0
|
2019-06-29 07:55:12 +00:00
|
|
|
sta (charset),y
|
2020-02-23 08:44:36 +00:00
|
|
|
// proto_lo += 5
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #5
|
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z proto_lo
|
|
|
|
sta.z proto_lo
|
2019-06-29 07:55:12 +00:00
|
|
|
bcc !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z proto_lo+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// charset += 8
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #8
|
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z charset
|
|
|
|
sta.z charset
|
2019-06-29 07:55:12 +00:00
|
|
|
bcc !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z charset+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// for( byte c: 0..15 )
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z c1
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #$10
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z c1
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b2
|
2020-02-23 08:44:36 +00:00
|
|
|
// proto_hi += 5
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #5
|
|
|
|
clc
|
2019-08-07 19:00:19 +00:00
|
|
|
adc.z proto_hi
|
|
|
|
sta.z proto_hi
|
2019-06-29 07:55:12 +00:00
|
|
|
bcc !+
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z proto_hi+1
|
2019-06-29 07:55:12 +00:00
|
|
|
!:
|
2020-02-23 08:44:36 +00:00
|
|
|
// for( byte c: 0..15 )
|
2019-08-07 19:00:19 +00:00
|
|
|
inc.z c
|
2019-06-29 07:55:12 +00:00
|
|
|
lda #$10
|
2019-08-07 19:00:19 +00:00
|
|
|
cmp.z c
|
2019-09-29 21:13:37 +00:00
|
|
|
bne __b1
|
2020-02-23 08:44:36 +00:00
|
|
|
// }
|
2019-06-29 07:55:12 +00:00
|
|
|
rts
|
|
|
|
}
|
|
|
|
// Bit patterns for symbols 0-f (3x5 pixels) used in font hex
|
|
|
|
FONT_HEX_PROTO: .byte 2, 5, 5, 5, 2, 6, 2, 2, 2, 7, 6, 1, 2, 4, 7, 6, 1, 2, 1, 6, 5, 5, 7, 1, 1, 7, 4, 6, 1, 6, 3, 4, 6, 5, 2, 7, 1, 1, 1, 1, 2, 5, 2, 5, 2, 2, 5, 3, 1, 1, 2, 5, 7, 5, 5, 6, 5, 6, 5, 6, 2, 5, 4, 5, 2, 6, 5, 5, 5, 6, 7, 4, 6, 4, 7, 7, 4, 6, 4, 4
|
2019-11-22 22:41:01 +00:00
|
|
|
// Angles representing ATAN(0.5), ATAN(0.25), ATAN(0.125), ...
|
2019-06-30 21:33:30 +00:00
|
|
|
CORDIC_ATAN2_ANGLES_16:
|
|
|
|
.for (var i=0; i<CORDIC_ITERATIONS_16; i++)
|
2019-06-30 13:30:08 +00:00
|
|
|
.word 256*2*256*atan(1/pow(2,i))/PI/2
|
2019-06-29 07:55:12 +00:00
|
|
|
|
2019-11-22 22:41:01 +00:00
|
|
|
print_hextab: .text "0123456789abcdef"
|
2019-07-01 07:21:11 +00:00
|
|
|
SCREEN_REF:
|
|
|
|
.for(var y=-12;y<=12;y++)
|
2019-06-29 07:55:12 +00:00
|
|
|
.for(var x=-19;x<=20;x++)
|
|
|
|
.byte round(256*atan2(y, x)/PI/2)
|
|
|
|
|