; program: drawing lines - marcello of retro64 blog * = $801 byteaddr = $fc ;fc, fd used basic byte 11,8,10,0,158,50,48,54,49,0,0,0 ;basic program for autostart bmpscreen = 24576 ;bmpscreen start ;dummy = $0 lda #>bmpscreen ;initialize self-mod code sta mod1+2 lda #319 sta x1 lda #<319 sta x1+1 lda #100 sta y1+2 lda #00 sta x2 lda #160 sta x2+1 lda #199 sta y2 jsr line_subroutine sec lda #199 sbc #19 sta y2 jsr line_subroutine subtract_20_2 sec lda y2 sbc #20 sta y2 jsr line_subroutine lda y2 bne subtract_20_2 lda #00 sta y1 lda #00 sta x1 lda #160 sta x1+1 lda #100 sta y2 lda #$00 sta x2 lda #20 sta x2+1 jsr line_subroutine add_20 clc lda x2+1 adc #20 sta x2+1 lda x2 adc #$00 sta x2 jsr line_subroutine lda x2 cmp #>300 bne add_20 lda x2+1 cmp #<300 bne add_20 lda #>300 sta x1 lda #<300 sta x1+1 lda #100 sta y1 lda #0 sta x2 lda #160 sta x2+1 lda #199 sta y2 jsr line_subroutine subtract_20_3 sec lda x1+1 sbc #20 sta x1+1 lda x1 sbc #00 sta x1 jsr line_subroutine lda x1 cmp #00 bne subtract_20_3 lda x1+1 cmp #20 bne subtract_20_3 lda #15 sta $d020 spacechk lda $dc01 cmp #$ef bne spacechk lda #$9b sta $d011 lda #4 sta 648 lda #21 sta $d018 lda #151 sta $dd00 ;default vic-ii bank lda #147 jsr $ffd2 lda #15 sta $286 lda #00 sta 198 rts line_subroutine ; computes deltax, deltay, decides what routine to be used lda x1 cmp x2 bcc compute_delta_x2_x1 bne compute_delta_x1_x2 lda x1+1 cmp x2+1 bcc compute_delta_x2_x1 ;compares x1 and x2 compute_delta_x1_x2 sec lda x1+1 sbc x2+1 sta delta_x+1 lda x1 sbc x2 sta delta_x ;delta_x = x1-x2 lda #$01 sta x_n ;delta_x negative jmp skip_compute_delta_x2_x1 compute_delta_x2_x1 sec lda x2+1 sbc x1+1 sta delta_x+1 lda x2 sbc x1 sta delta_x ;delta_x = x2-x1 lda #$00 sta x_n ;delta_x positive skip_compute_delta_x2_x1 lda y1 cmp y2 bcc compute_delta_y2_y1 ;compares y1 and y2 sec lda y1 sbc y2 sta delta_y ;delta_y = y1 - y2 lda #$01 sta y_n ;delta_y negative jmp skip_compute_delta_y2_y1 compute_delta_y2_y1 sec lda y2 sbc y1 sta delta_y ;delta_y = y2 - y1 lda #$00 sta y_n ;delta_y positive skip_compute_delta_y2_y1 lda delta_x bne jump_110 ;if high byte delta_x <> 0 then delta_x > delta_y lda delta_x+1 cmp delta_y bcc jump_170 ;if delta_x+1 < delta_y use routine 170 jump_110 jsr line_110 ;else use routine 110 jmp skip_jump_170 jump_170 jsr line_170 skip_jump_170 rts ;subroutine: line_110 (deltax > deltay) line_110 lda #$00 sta to_mult ;delta_y_highest = 0 lda #$00 sta to_mult+1 ;delta_y_high = 0 lda delta_y sta to_mult+2 jsr off_multiply ;delta_y * offset = to_mult (24 bit) lda #$00 sta a ;higher byte of a unused lda to_mult sta a+1 lda to_mult+1 sta a+2 lda to_mult+2 sta a+3 ;lower bytes used (delta_y * offset = to_mult is 24 bit) ;a is dividend lda delta_x sta b lda delta_x+1 sta b+1 ;delta x on b (b is divisor) jsr divide_ab ;computes to_mult/b lda rs+1 sta m lda rs+2 sta m+1 lda rs+3 sta m+2 ;m = to_mult/b (24 bit) ;rs: higher bytes of quotient: unused ;rs+1, rs+2 and rs+3: lower bytes of quotient: used lda y_n eor x_n sta m_s ;determines sign of m lda m_s lda x2 cmp x1 bcc x_increment_sign_negative bne x_increment_sign_positive lda x2+1 cmp x1+1 bcc x_increment_sign_negative bne x_increment_sign_positive x_increment_sign_negative lda #$01 sta x_increment_sign jmp skip_x_increment_sign_positive x_increment_sign_positive lda #$00 sta x_increment_sign ;determines sign of increment of x during line plotting skip_x_increment_sign_positive lda x1 sta multiplier lda x1+1 sta multiplier+1 lda m sta multiplicand lda m+1 sta multiplicand+1 lda m+2 sta multiplicand+2 ;prepares to perform 32 bit multiply ;operation: x1 * m = TT jsr multiply_ab ;performs multiplication lda multiplier+1 sta mc lda sum sta mc+1 lda sum+1 sta mc+2 ;MC = x1 * M, used later jsr divide_off ;divides result of multiplication by offset lda multiplier+1 sta tt lda sum sta tt+1 lda sum+1 sta tt+2 ;TT (24 bit) = (x1*M)/offset ;16 bit are not enough! ;now ready to draw the line lda x1 sta x_domain lda x1+1 sta x_domain+1 ;starting point for line plotting lda x_increment_sign bne x2_minus_1 clc lda x2+1 adc #01 sta x_limit+1 lda x2 adc #$00 sta x_limit ;x_limit = x2+1 or x2-1 so that last point is plotted jmp skip_x2_minus_1 x2_minus_1 sec lda x2+1 sbc #$01 sta x_limit+1 lda x2 sbc #$00 sta x_limit skip_x2_minus_1 ; tests if tn = tt+y1 can be calculated outside loop lda m_s beq draw_loop clc ;calculates tn lda tt+2 adc y1 sta tn+2 lda tt+1 adc #$00 ;higher bytes of y seen as a 24 bit number are 0 sta tn+1 lda tt adc #$00 sta tn ;tn = tt + y1 draw_loop lda mc+1 sta mx+2 lda mc sta mx+1 lda #$00 sta mx ;MX = MC/offset ;take MC, divide it by 256 and store result in MX ;MC is unchanged lda m_s beq m_s_zero_formula ;y calculation if m is negative sec lda tn+2 sbc mx+2 sta y_calc+2 lda tn+1 sbc mx+1 sta y_calc+1 lda tn sbc mx sta y_calc ;y_calc = y_calc -mx ;(y_calc = tt + y1 - mx) ==> y_calc = tn - mx jmp skip_ms_zero_formula m_s_zero_formula clc ;y calculation if m is positive lda mx+2 ;lower byte of mx+2 adc y1 ;add to y1 sta y_calc+2 lda mx+1 adc #$00 ;medium byte of y seen as a 24 bit number sta y_calc+1 lda mx ;higher byte of y seen as a 24 bit number adc #$00 sta y_calc ;y_calc = mx + y1 sec lda y_calc+2 sbc tt+2 sta y_calc+2 lda y_calc+1 sbc tt+1 sta y_calc+1 lda y_calc sbc tt sta y_calc ;y_calc = y_calc - tt ;(y_calc = mx + y1 - tt) skip_ms_zero_formula lda x_domain sta xp lda x_domain+1 sta xp+1 lda y_calc+2 sta yp ;prepares values for point plotting jsr plot ;plots the point lda x_increment_sign beq increment_mc sec lda mc+2 sbc m+2 sta mc+2 lda mc+1 sbc m+1 sta mc+1 lda mc sbc m sta mc ;MC = MC - M dec x_domain+1 ;x_domain = x_domain -1 (16 bit) lda x_domain+1 cmp #$ff bne skip_increment_mc dec x_domain jmp skip_increment_mc increment_mc clc lda mc+2 adc m+2 sta mc+2 lda mc+1 adc m+1 sta mc+1 lda mc adc m sta mc ;MC = MC + M inc x_domain+1 ;x_domain = x_domain + 1 (16 bit) lda x_domain+1 bne skip_increment_mc inc x_domain skip_increment_mc lda x_domain cmp x_limit bne draw_loop_jump lda x_domain+1 cmp x_limit+1 bne draw_loop_jump rts draw_loop_jump jmp draw_loop ;subroutine: line_170 (deltax < deltay) line_170 lda #$00 sta to_mult ;highest byte of delta_x is 0 lda delta_x sta to_mult+1 ;delta_x_high lda delta_x+1 sta to_mult+2 jsr off_multiply ;delta_x * offset = to_mult (24 bit) lda #$00 sta a ;higher bytes of a unused lda to_mult sta a+1 lda to_mult+1 sta a+2 lda to_mult+2 sta a+3 ;lower bytes used (delta_y * offset = to_mult is 16 bit) ;a is dividend lda #$00 ;high byte of delta_x is 0 sta b lda delta_y sta b+1 ;delta y on b (b is divisor) jsr divide_ab ;computes to_mult/b lda rs+1 sta m lda rs+2 sta m+1 lda rs+3 sta m+2 ;m = to_mult/b (24 bit) ;rs: higher byte of quotient: unused ;rs+1, rs+2 and rs+3: lower bytes of quotient: used lda y_n eor x_n sta m_s ;determines sign of m lda m_s lda y2 cmp y1 bcc y_increment_sign_negative bne y_increment_sign_positive y_increment_sign_negative lda #$01 sta y_increment_sign jmp skip_y_increment_sign_positive y_increment_sign_positive lda #$00 sta y_increment_sign ;determines sign of increment of x during line plotting skip_y_increment_sign_positive lda y_increment_sign lda #$00 ;high byte of y1 is 0 sta multiplier lda y1 sta multiplier+1 ;only low bytes of multiplier used lda m sta multiplicand lda m+1 sta multiplicand+1 lda m+2 sta multiplicand+2 ;prepares to perform 32 bit multiply ;operation: y1 * m = TT jsr multiply_ab ;performs multiplication lda multiplier+1 sta mc lda sum sta mc+1 lda sum+1 sta mc+2 ;MC = y1 * M, used later jsr divide_off ;divides result of multiplication by offset lda multiplier+1 sta tt lda sum sta tt+1 lda sum+1 sta tt+2 ;TT (24 bit) = (y1*M)/offset ;16 bit are not enough! ;now ready to draw the line lda y1 sta y_domain ;starting point for line plotting lda y2 sta y_limit lda y_increment_sign bne y2_minus_1 inc y_limit jmp skip_y2_minus_1 y2_minus_1 dec y_limit skip_y2_minus_1 lda m_s beq draw_loop_170 ;checks if tn can be calculated outside loop clc ;calculates tt lda tt+2 adc x1+1 sta tn+2 lda tt+1 adc x1 ;higher bytes of y seen as a 24 bit number are 0 sta tn+1 lda tt adc #$00 sta tn ;tn = tt + x1 draw_loop_170 lda mc+1 sta my+2 lda mc sta my+1 lda #$00 sta my ;MY = MC/offset ;take MC, divide it by 256 and store result in MY ;MC is unchanged lda m_s beq m_s_zero_formula_170 sec ;x calculation if m is negative lda tn+2 sbc my+2 sta x_calc+2 lda tn+1 sbc my+1 sta x_calc+1 lda tn sbc my sta x_calc ;x_calc = x_calc -my ;(x_calc = tt + x1 - my) ==> x_calc = tn - my jmp skip_ms_zero_formula_170 m_s_zero_formula_170 clc ;x calculation if m is positive lda my+2 ;lower byte of my+2 adc x1+1 ;add to x1+1 (lower byte of x1) sta x_calc+2 lda my+1 adc x1 ;high byte of x1 now added sta x_calc+1 lda my ;highest byte of x1 seen as a 24 bit number is 0 adc #$00 sta x_calc ;x_calc = my + x1 sec lda x_calc+2 sbc tt+2 sta x_calc+2 lda x_calc+1 sbc tt+1 sta x_calc+1 lda x_calc sbc tt sta x_calc ;x_calc = x_calc - tt ;(x_calc = my + x1 - tt) skip_ms_zero_formula_170 lda y_domain sta yp lda x_calc+1 sta xp lda x_calc+2 sta xp+1 ;prepares values for point plotting jsr plot ;plots the point lda y_increment_sign beq increment_mc_170 sec lda mc+2 sbc m+2 sta mc+2 lda mc+1 sbc m+1 sta mc+1 lda mc sbc m sta mc ;MC = MC - M dec y_domain jmp skip_increment_mc_170 increment_mc_170 clc lda mc+2 adc m+2 sta mc+2 lda mc+1 adc m+1 sta mc+1 lda mc adc m sta mc ;MC = MC + M inc y_domain skip_increment_mc_170 lda y_domain cmp y_limit bne draw_loop_jump_170 rts draw_loop_jump_170 jmp draw_loop_170 ;subroutine: multiply by 256 (to_mult) ;to_mult is 24 bit (three bytes) off_multiply lda to_mult+1 sta to_mult lda to_mult+2 sta to_mult+1 lda #$00 sta to_mult+2 rts ; 31 bit by 15 bit divide (2 bilions etc... maximum value for a, 32767 for b) ; marcello of retro64 blog divide_ab lda #$00 sta rs sta rs+1 ;rs = 0 sta rs+2 sta rs+3 sta k sta k+1 ;k = 0 sta k+2 sta k+3 ;lda a ;sta oa ;lda a+1 ;sta oa+1 ;oa = a ;lda a+2 ;sta oa+2 ;lda a+3 ;sta oa+3 lda a bmi skip_ab_check_close lda b bmi skip_ab_check_close ;exits if b >32767 or a > 4 bilions etc... jmp label_40 skip_ab_check_close rts label_40 sec lda a+3 sbc k+3 sta a+3 lda a+2 sbc k+2 sta a+2 lda a+1 sbc k+1 sta a+1 lda a sbc k sta a ;a = a-k lda a cmp #$00 bcc label_50 bne label_48 lda a+1 cmp #$00 bcc label_50 bne label_48 lda a+2 cmp b bcc label_50 bne label_48 lda a+3 cmp b+1 bcc label_50 ;if a < b then goto 50 label_48 jsr routine_1000 clc lda rs+3 adc q+3 sta rs+3 lda rs+2 adc q+2 sta rs+2 lda rs+1 adc q+1 sta rs+1 lda rs adc q sta rs ;rs=rs+q jmp label_40 label_50 lda a cmp #$00 bne skip_ab_check lda a+1 cmp #$00 bne skip_ab_check lda a+2 cmp b bne skip_ab_check lda a+3 cmp b+1 beq inc_rs_low ;if a = b then rs = 1 skip_ab_check rts inc_rs_low inc rs+3 rts routine_1000 lda #$00 sta k lda #$00 sta k+1 lda b sta k+2 lda b+1 sta k+3 ;k = b lda b bne skip_b_0_check lda b+1 beq end ;return to caller of main program if b = 0 skip_b_0_check lda #$00 sta ct ;ct = 0 label_1010 asl k+3 rol k+2 rol k+1 rol k ;k = k * 2 lda k+3 bne skip_check_k lda k+2 bne skip_check_k lda k+1 bne skip_check_k lda k beq end ;if k = 0 (low and hi byte) then return to caller of main program ;overflow condition skip_check_k lda k cmp a bcc inc_ct bne label_1020 lda k+1 cmp a+1 bcc inc_ct bne label_1020 lda k+2 cmp a+2 bcc inc_ct bne label_1020 lda k+3 cmp a+3 bcc inc_ct label_1020 lsr k ror k+1 ror k+2 ror k+3 ;a = a/2 ldx ct lda power,x sta q inx lda power,x sta q+1 inx lda power,x sta q+2 inx lda power,x sta q+3 ; q = 2 ^ ct rts end pla pla rts inc_ct inc ct inc ct inc ct inc ct ;four times because power table is 32 bit jmp label_1010 ;subroutine: plot a point (codebase64.org) plot ;bmpscreen = start of bitmap screen ;byteaddr = address of the byte where the point to plot lies ldy yp ldx xp+1 lda #>xtablehigh sta XTBmdf+2 lda xp beq skipadj lda #>(xtablehigh + $ff) ;added brackets, otherwise it won't work sta XTBmdf+2 skipadj: lda ytablelow,y clc adc xtablelow,x sta byteaddr lda ytablehigh,y XTBmdf: adc xtablehigh,x sta byteaddr+1 lda byteaddr clc adc #bmpscreen sta byteaddr+1 ldy #$00 lda (byteaddr),y ora bitable,x sta (byteaddr),y rts ; clear bitmap screen clear_screen ldy #32 loopbmp ldx #$00 lda #$00 mod1 sta bmpscreen,x inx cpx #250 bne mod1 clc lda mod1+1 adc #250 sta mod1+1 lda mod1+2 adc #00 sta mod1+2 dey bne loopbmp lda #bmpscreen sta mod1+2 rts multiply_ab lda #$00 sta temp_sum sta temp_sum+1 sta temp_sum+2 sta temp_sum+3 sta p32 sta p32+1 sta p32+2 sta p32+3 ;lda 700 ;sta multiplicand ;lda 701 ;sta multiplicand+1 ;lda 702 ;sta multiplier ;lda 703 ;sta multiplier+1 ;test lda multiplicand+1 beq zero_result3 sta multiplier8 lda multiplier+1 beq zero_result3 sta multiplicand8 jsr multiply_ab_fast jmp skip_zero_result3 zero_result3 lda #$00 sta sum8 sta multiplier8 skip_zero_result3 lda sum8 sta p32_1+3 lda multiplier8 sta p32_1+2 ;p32_1 <--- al*bl lda #$00 sta p32_1+1 sta p32_1 lda multiplicand beq skip_ahbl sta multiplier8 lda multiplier+1 beq skip_ahbl sta multiplicand8 jsr multiply_ab_fast ;lda #$00 ;sta temp_sum+3 lda sum8 sta temp_sum+2 lda multiplier8 sta temp_sum+1 ;lda #$00 ;sta temp_sum ;temp_sum <--- ah*bl*256 skip_ahbl lda multiplicand+1 beq zero_result sta multiplier8 lda multiplier beq zero_result sta multiplicand8 jsr multiply_ab_fast jmp skip_zero_result zero_result lda #$00 sta sum8 sta multiplier8 skip_zero_result clc lda #$00 sta p32_2+3 lda sum8 adc temp_sum+2 sta p32_2+2 lda multiplier8 adc temp_sum+1 sta p32_2+1 lda #$00 adc #$00 sta p32_2 ;p32_2 <--- (ah*bl+al*bh)*256 lda multiplicand beq zero_result2 sta multiplicand8 lda multiplier beq zero_result2 sta multiplier8 jsr multiply_ab_fast jmp skip_zero_result2 zero_result2 lda #$00 sta sum8 sta multiplier8 skip_zero_result2 lda sum8 sta p32_3+1 lda multiplier8 sta p32_3 lda #$00 sta p32_3+2 sta p32_3+3 ;p32_3 <---65536*ah*bh clc lda p32_1+3 adc p32_2+3 sta p32+3 lda p32_1+2 adc p32_2+2 sta p32+2 lda p32_1+1 adc p32_2+1 sta p32+1 lda p32_1 adc p32_2 sta p32 clc lda p32+3 adc p32_3+3 sta sum+1 ;sta 707 lda p32+2 adc p32_3+2 sta sum ;sta 706 lda p32+1 adc p32_3+1 sta multiplier+1 ;sta 705 lda p32 adc p32_3 sta multiplier ;sta 704 rts ; subroutine: fast multiply 8 bit multiply_ab_fast lda #>square_low sta mod12+2 lda #>square_high sta mod22+2 clc lda multiplicand8 adc multiplier8 bcc skip_inc inc mod12+2 inc mod22+2 skip_inc tax sec lda multiplicand8 sbc multiplier8 bcs no_diff_fix sec lda multiplier8 sbc multiplicand8 no_diff_fix tay sec mod12 lda square_low,x sbc square_low,y sta sum8 mod22 lda square_high, x sbc square_high, y sta multiplier8 rts ;subroutine: divide result of multiply_ab (32 bit) by 256 ;divide_result_of_32bit_multiply_by_256 ;multiplier, multiplier+1, sum, sum+1 (32 bits, 4 bytes) divide_off lda sum sta sum+1 lda multiplier+1 sta sum lda multiplier sta multiplier+1 lda #$00 sta multiplier rts ;storage locations for main program x1 byte 0,0 y1 byte 0 x2 byte 0,0 y2 byte 0 delta_x byte 0,0 delta_y byte 0 to_mult byte 0,0,0 x_n byte 0 y_n byte 0 m byte 0,0,0 x_increment_sign byte 0 tt byte 0,0,0 mx byte 0,0,0 x_domain byte 0,0 y_calc byte 0,0,0 m_s byte 0 y_increment_sign byte 0 y_domain byte 0 x_calc byte 0,0,0 my byte 0,0,0 x_limit byte 0,0 y_limit byte 0 mc byte 0,0,0 tn byte 0,0,0 ;storage locations for plot routine xp byte 0,0 yp byte 0 bit_table byte 128,64,32,16,8,4,2,1 temp byte 0 temp2 byte 0,0 byteaddr_y byte 0,0 yp_old byte 0 xp_old byte 0,0 ;storage locations and table for divide routine power byte 0,0,0,1,0,0,0,2,0,0,0,4,0,0,0,8,0,0,0,16,0,0,0,32,0,0,0,64,0,0,0,128 byte 0,0,1,0,0,0,2,0,0,0,4,0,0,0,8,0,0,0,16,0,0,0,32,0,0,0,64,0,0,0,128,0 byte 0,1,0,0,0,2,0,0,0,4,0,0,0,8,0,0,0,16,0,0,0,32,0,0,0,64,0,0,0,128,0,0 byte 1,0,0,0,2,0,0,0,4,0,0,0,8,0,0,0,16,0,0,0,32,0,0,0,64,0,0,0,128,0,0,0 ct byte 0 q byte 0,0,0,0 k byte 0,0,0,0 oa byte 0,0,0,0 a byte 0,0,0,0 b byte 0,0 rs byte 0,0,0,0 ;storage locations for 16 bit multiplication multiplicand byte 0,0,0 multiplier byte 0,0 sum byte 0,0 ; result on multiplier and sum index byte 0,0 dummy byte 0,0 multiplicand8 byte 0 multiplier8 byte 0 sum8 byte 0 ;multiplier byte 0,0 ;multiplicand byte 0,0 temp_sum2 byte 0,0,0,0 ; temp_sum byte 0,0,0,0 ; 8192, 8193,8194,8195 (ah*bl) p32_1 byte 0,0,0,0 ; 8200, 8201, 8202, 8203 (al*bl) p32_2 byte 0,0,0,0 ; 8204, 8205, 8206, 8207 (ah*bl+al*bh)*256 p32_3 byte 0,0,0,0 ; 8208, 8209, 8210, 8211 (ah*bh)*65536 p32 byte 0,0,0,0 ; 8212, 8213, 8214, 8215 SUM ;******************** PLOT TABLE ********************* ytablelow byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 byte 64,65,66,67,68,69,70,71 byte 128,129,130,131,132,133,134,135 ;********************* byte 192,193,194,195,196,197,198,199 byte 0,1,2,3,4,5,6,7 ytablehigh byte 0,0,0,0,0,0,0,0 byte 1,1,1,1,1,1,1,1 byte 2,2,2,2,2,2,2,2 byte 3,3,3,3,3,3,3,3 byte 5,5,5,5,5,5,5,5 byte 6,6,6,6,6,6,6,6 byte 7,7,7,7,7,7,7,7 byte 8,8,8,8,8,8,8,8 byte 10,10,10,10,10,10,10,10 byte 11,11,11,11,11,11,11,11 byte 12,12,12,12,12,12,12,12 byte 13,13,13,13,13,13,13,13 byte 15,15,15,15,15,15,15,15 byte 16,16,16,16,16,16,16,16 byte 17,17,17,17,17,17,17,17 byte 18,18,18,18,18,18,18,18 byte 20,20,20,20,20,20,20,20 byte 21,21,21,21,21,21,21,21 byte 22,22,22,22,22,22,22,22 ;********************* byte 23,23,23,23,23,23,23,23 byte 25,25,25,25,25,25,25,25 byte 26,26,26,26,26,26,26,26 byte 27,27,27,27,27,27,27,27 byte 28,28,28,28,28,28,28,28 byte 30,30,30,30,30,30,30,30 xtablelow byte 0,0,0,0,0,0,0,0 byte 8,8,8,8,8,8,8,8 byte 16,16,16,16,16,16,16,16 byte 24,24,24,24,24,24,24,24 byte 32,32,32,32,32,32,32,32 byte 40,40,40,40,40,40,40,40 byte 48,48,48,48,48,48,48,48 byte 56,56,56,56,56,56,56,56 byte 64,64,64,64,64,64,64,64 byte 72,72,72,72,72,72,72,72 byte 80,80,80,80,80,80,80,80 byte 88,88,88,88,88,88,88,88 byte 96,96,96,96,96,96,96,96 byte 104,104,104,104,104,104,104,104 byte 112,112,112,112,112,112,112,112 ;********************* byte 120,120,120,120,120,120,120,120 byte 128,128,128,128,128,128,128,128 byte 136,136,136,136,136,136,136,136 byte 144,144,144,144,144,144,144,144 byte 152,152,152,152,152,152,152,152 byte 160,160,160,160,160,160,160,160 byte 168,168,168,168,168,168,168,168 byte 176,176,176,176,176,176,176,176 byte 184,184,184,184,184,184,184,184 byte 192,192,192,192,192,192,192,192 byte 200,200,200,200,200,200,200,200 byte 208,208,208,208,208,208,208,208 byte 216,216,216,216,216,216,216,216 byte 224,224,224,224,224,224,224,224 byte 232,232,232,232,232,232,232,232 byte 240,240,240,240,240,240,240,240 byte 248,248,248,248,248,248,248,248 byte 0,0,0,0,0,0,0,0 byte 8,8,8,8,8,8,8,8 byte 16,16,16,16,16,16,16,16 byte 24,24,24,24,24,24,24,24 byte 32,32,32,32,32,32,32,32 byte 40,40,40,40,40,40,40,40 ;********************* byte 48,48,48,48,48,48,48,48 byte 56,56,56,56,56,56,56,56 xtablehigh byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 ;********************* byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 0,0,0,0,0,0,0,0 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 byte 1,1,1,1,1,1,1,1 bitable byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 ;********************* byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 ;those values from here should not be necessary, but leaved in place for safety byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 byte 128,64,32,16,8,4,2,1 square_high ;squares 0...510 high bytes byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 0 , 0 , 0 byte 0 , 0 , 1 , 1 , 1 byte 1 , 1 , 1 , 1 , 1 byte 1 , 1 , 1 , 1 , 1 byte 1 , 2 , 2 , 2 , 2 byte 2 , 2 , 2 , 2 , 2 byte 2 , 3 , 3 , 3 , 3 byte 3 , 3 , 3 , 3 , 4 byte 4 , 4 , 4 , 4 , 4 byte 4 , 4 , 5 , 5 , 5 byte 5 , 5 , 5 , 5 , 6 byte 6 , 6 , 6 , 6 , 6 byte 7 , 7 , 7 , 7 , 7 byte 7 , 8 , 8 , 8 , 8 byte 8 , 9 , 9 , 9 , 9 ;*************************** byte 9 , 9 , 10 , 10 , 10 byte 10 , 10 , 11 , 11 , 11 byte 11 , 12 , 12 , 12 , 12 byte 12 , 13 , 13 , 13 , 13 byte 14 , 14 , 14 , 14 , 15 byte 15 , 15 , 15 , 16 , 16 byte 16 , 16 , 17 , 17 , 17 byte 17 , 18 , 18 , 18 , 18 byte 19 , 19 , 19 , 19 , 20 byte 20 , 20 , 21 , 21 , 21 byte 21 , 22 , 22 , 22 , 23 byte 23 , 23 , 24 , 24 , 24 byte 25 , 25 , 25 , 25 , 26 byte 26 , 26 , 27 , 27 , 27 byte 28 , 28 , 28 , 29 , 29 byte 29 , 30 , 30 , 30 , 31 byte 31 , 31 , 32 , 32 , 33 byte 33 , 33 , 34 , 34 , 34 byte 35 , 35 , 36 , 36 , 36 byte 37 , 37 , 37 , 38 , 38 ;*************************** byte 39 , 39 , 39 , 40 , 40 byte 41 , 41 , 41 , 42 , 42 byte 43 , 43 , 43 , 44 , 44 byte 45 , 45 , 45 , 46 , 46 byte 47 , 47 , 48 , 48 , 49 byte 49 , 49 , 50 , 50 , 51 byte 51 , 52 , 52 , 53 , 53 byte 53 , 54 , 54 , 55 , 55 byte 56 , 56 , 57 , 57 , 58 byte 58 , 59 , 59 , 60 , 60 byte 61 , 61 , 62 , 62 , 63 byte 63 , 64 , 64 , 65 , 65 byte 66 , 66 , 67 , 67 , 68 byte 68 , 69 , 69 , 70 , 70 byte 71 , 71 , 72 , 72 , 73 byte 73 , 74 , 74 , 75 , 76 byte 76 , 77 , 77 , 78 , 78 byte 79 , 79 , 80 , 81 , 81 byte 82 , 82 , 83 , 83 , 84 byte 84 , 85 , 86 , 86 , 87 ;*************************** byte 87 , 88 , 89 , 89 , 90 byte 90 , 91 , 92 , 92 , 93 byte 93 , 94 , 95 , 95 , 96 byte 96 , 97 , 98 , 98 , 99 byte 100 , 100 , 101 , 101 , 102 byte 103 , 103 , 104 , 105 , 105 byte 106 , 106 , 107 , 108 , 108 byte 109 , 110 , 110 , 111 , 112 byte 112 , 113 , 114 , 114 , 115 byte 116 , 116 , 117 , 118 , 118 byte 119 , 120 , 121 , 121 , 122 byte 123 , 123 , 124 , 125 , 125 byte 126 , 127 , 127 , 128 , 129 byte 130 , 130 , 131 , 132 , 132 byte 133 , 134 , 135 , 135 , 136 byte 137 , 138 , 138 , 139 , 140 byte 141 , 141 , 142 , 143 , 144 byte 144 , 145 , 146 , 147 , 147 byte 148 , 149 , 150 , 150 , 151 byte 152 , 153 , 153 , 154 , 155 ;*************************** byte 156 , 157 , 157 , 158 , 159 byte 160 , 160 , 161 , 162 , 163 byte 164 , 164 , 165 , 166 , 167 byte 168 , 169 , 169 , 170 , 171 byte 172 , 173 , 173 , 174 , 175 byte 176 , 177 , 178 , 178 , 179 byte 180 , 181 , 182 , 183 , 183 byte 184 , 185 , 186 , 187 , 188 byte 189 , 189 , 190 , 191 , 192 byte 193 , 194 , 195 , 196 , 196 byte 197 , 198 , 199 , 200 , 201 byte 202 , 203 , 203 , 204 , 205 byte 206 , 207 , 208 , 209 , 210 byte 211 , 212 , 212 , 213 , 214 byte 215 , 216 , 217 , 218 , 219 byte 220 , 221 , 222 , 223 , 224 byte 225 , 225 , 226 , 227 , 228 byte 229 , 230 , 231 , 232 , 233 byte 234 , 235 , 236 , 237 , 238 byte 239 , 240 , 241 , 242 , 243 ;*************************** byte 244 , 245 , 246 , 247 , 248 byte 249 , 250 , 251 , 252 , 253 byte 254 ;*************************** ;*************************** square_low ;squares 0...510 low bytes byte 0 , 0 , 1 , 2 , 4 byte 6 , 9 , 12 , 16 , 20 byte 25 , 30 , 36 , 42 , 49 byte 56 , 64 , 72 , 81 , 90 byte 100 , 110 , 121 , 132 , 144 byte 156 , 169 , 182 , 196 , 210 byte 225 , 240 , 0 , 16 , 33 byte 50 , 68 , 86 , 105 , 124 byte 144 , 164 , 185 , 206 , 228 byte 250 , 17 , 40 , 64 , 88 byte 113 , 138 , 164 , 190 , 217 byte 244 , 16 , 44 , 73 , 102 byte 132 , 162 , 193 , 224 , 0 byte 32 , 65 , 98 , 132 , 166 byte 201 , 236 , 16 , 52 , 89 byte 126 , 164 , 202 , 241 , 24 byte 64 , 104 , 145 , 186 , 228 byte 14 , 57 , 100 , 144 , 188 byte 233 , 22 , 68 , 114 , 161 byte 208 , 0 , 48 , 97 , 146 ;*************************** byte 196 , 246 , 41 , 92 , 144 byte 196 , 249 , 46 , 100 , 154 byte 209 , 8 , 64 , 120 , 177 byte 234 , 36 , 94 , 153 , 212 byte 16 , 76 , 137 , 198 , 4 byte 66 , 129 , 192 , 0 , 64 byte 129 , 194 , 4 , 70 , 137 byte 204 , 16 , 84 , 153 , 222 byte 36 , 106 , 177 , 248 , 64 byte 136 , 209 , 26 , 100 , 174 byte 249 , 68 , 144 , 220 , 41 byte 118 , 196 , 18 , 97 , 176 byte 0 , 80 , 161 , 242 , 68 byte 150 , 233 , 60 , 144 , 228 byte 57 , 142 , 228 , 58 , 145 byte 232 , 64 , 152 , 241 , 74 byte 164 , 254 , 89 , 180 , 16 byte 108 , 201 , 38 , 132 , 226 byte 65 , 160 , 0 , 96 , 193 byte 34 , 132 , 230 , 73 , 172 ;*************************** byte 16 , 116 , 217 , 62 , 164 byte 10 , 113 , 216 , 64 , 168 byte 17 , 122 , 228 , 78 , 185 byte 36 , 144 , 252 , 105 , 214 byte 68 , 178 , 33 , 144 , 0 byte 112 , 225 , 82 , 196 , 54 byte 169 , 28 , 144 , 4 , 121 byte 238 , 100 , 218 , 81 , 200 byte 64 , 184 , 49 , 170 , 36 byte 158 , 25 , 148 , 16 , 140 byte 9 , 134 , 4 , 130 , 1 byte 128 , 0 , 128 , 1 , 130 byte 4 , 134 , 9 , 140 , 16 byte 148 , 25 , 158 , 36 , 170 byte 49 , 184 , 64 , 200 , 81 byte 218 , 100 , 238 , 121 , 4 byte 144 , 28 , 169 , 54 , 196 byte 82 , 225 , 112 , 0 , 144 byte 33 , 178 , 68 , 214 , 105 byte 252 , 144 , 36 , 185 , 78 ;*************************** byte 228 , 122 , 17 , 168 , 64 byte 216 , 113 , 10 , 164 , 62 byte 217 , 116 , 16 , 172 , 73 byte 230 , 132 , 34 , 193 , 96 byte 0 , 160 , 65 , 226 , 132 byte 38 , 201 , 108 , 16 , 180 byte 89 , 254 , 164 , 74 , 241 byte 152 , 64 , 232 , 145 , 58 byte 228 , 142 , 57 , 228 , 144 byte 60 , 233 , 150 , 68 , 242 byte 161 , 80 , 0 , 176 , 97 byte 18 , 196 , 118 , 41 , 220 byte 144 , 68 , 249 , 174 , 100 byte 26 , 209 , 136 , 64 , 248 byte 177 , 106 , 36 , 222 , 153 byte 84 , 16 , 204 , 137 , 70 byte 4 , 194 , 129 , 64 , 0 byte 192 , 129 , 66 , 4 , 198 byte 137 , 76 , 16 , 212 , 153 byte 94 , 36 , 234 , 177 , 120 ;*************************** byte 64 , 8 , 209 , 154 , 100 byte 46 , 249 , 196 , 144 , 92 byte 41 , 246 , 196 , 146 , 97 byte 48 , 0 , 208 , 161 , 114 byte 68 , 22 , 233 , 188 , 144 byte 100 , 57 , 14 , 228 , 186 byte 145 , 104 , 64 , 24 , 241 byte 202 , 164 , 126 , 89 , 52 byte 16 , 236 , 201 , 166 , 132 byte 98 , 65 , 32 , 0 , 224 byte 193 , 162 , 132 , 102 , 73 byte 44 , 16 , 244 , 217 , 190 byte 164 , 138 , 113 , 88 , 64 byte 40 , 17 , 250 , 228 , 206 byte 185 , 164 , 144 , 124 , 105 byte 86 , 68 , 50 , 33 , 16 byte 0 , 240 , 225 , 210 , 196 byte 182 , 169 , 156 , 144 , 132 byte 121 , 110 , 100 , 90 , 81 byte 72 , 64 , 56 , 49 , 42 ;*************************** byte 36 , 30 , 25 , 20 , 16 byte 12 , 9 , 6 , 4 , 2 byte 1