3D Stars

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

3D Stars

Post by MrSterlingBS »

Hello,

i have converted the 3D Stars routine from the fridge http://www.ffd2.com/fridge/chacking/c=hacking16.txt to VIC BASIC with the MG expansion from Mike.

It is so slow. :shock: Does anyone have an idea how to speed this up in BASIC?

This is the original code.

Code: Select all

10 rem starfield
15 mode16:gron16
20 dim x(100),y(100):a=rnd(ti)
25 xc=160:yc=100:n=12:v=1/8
30 for i=1 to n:gosub200:next
40 :
50 for i=1 to n
55 color0:plot x(i),y(i):color 1
60 dx=x(i)-xc:dy=y(i)-yc
65 x1=x(i)+v*dx+x0:y1=y(i)+v*dy+y0
67 x2=abs(x1-x(i)):y2=abs(y1-y(i)):if (x2+y2<3*abs(v)) then gosub 200:goto 60
70 if (x1<0) or (y1<0) or (x1>319) or (y1>199) then gosub 200:dx=0:dy=0:goto65
75 plot x1,y1:x(i)=x1:y(i)=y1
80 next
90 get a$
100 if a$=";" then x0=x0-3:goto 40
110 if a$=":" then x0=x0+3:goto 40
120 if a$="@" then y0=y0-3:goto 40
130 if a$="/" then y0=y0+3:goto 40
133 if a$="a" then v=v+1/32
135 if a$="z" then v=v-1/32
140 if a$<>"q" then 40
150 groff:stop
200 x(i)=280*rnd(1)+20:y(i)=170*rnd(1)+15:return
This is the MG conversion.

Code: Select all

5 rem starfield minigrafik
10 poke36879,8:poke646,1
15 @on:@clr
20 dim x(32),y(32)
25 xc=79:yc=95:n=22:v=1/8:z=0:d=3
30 xm=159:ym=191:rx=120:ry=150:zw=20:fz=15
35 for i=1 to n:gosub80:next
40 for i=1 to n
45 @0,x(i),y(i)
50 dx=x(i)-xc:dy=y(i)-yc
55 x1=x(i)+v*dx:y1=y(i)+v*dy
60 x2=abs(x1-x(i)):y2=abs(y1-y(i)):if x2+y2<d*abs(v) then gosub80:goto50
65 if x1<z or y1<z or x1>xm or y1>ym then gosub80:dx=z:dy=z:goto55
70 @1,x1,y1:x(i)=x1:y(i)=y1
75 next:goto40
80 x(i)=rx*rnd(1)+zw:y(i)=ry*rnd(1)+fz:return
User avatar
srowe
Vic 20 Scientist
Posts: 1341
Joined: Mon Jun 16, 2014 3:19 pm

Re: 3D Stars

Post by srowe »

Line number lookup in BASIC is a linear search from the start of the program. I'd suggest moving line 80 to the top of the program.
User avatar
Mike
Herr VC
Posts: 4849
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: 3D Stars

Post by Mike »

MrSterlingBS wrote:It is so slow. :shock:
It isn't fast on the C64 either. The article in C=Hacking recommends using a SuperCPU.
Does anyone have an idea how to speed this up in BASIC?
Simplify the arithmetic stuff as much as possible. Factor out repeated calculations out of the main loop that yield the same value during each iteration.

That starfield demo does not even feature proper perspective correction - I would call that the bare minimum to get a good display of apparent space flight. Normally, this would involve two expensive divisions per point, but a table of reciprocals helps a lot here.

In the end however, this effect is a clear candidate for using machine code. Doing it in BASIC (with MG) can however help to outline the algorithm before it is translated.

srowe wrote:Line number lookup in BASIC is a linear search from the start of the program.
That is only the case for GOTOs or GOSUBs to a smaller or to the same line number. Forward jumps start their lookup from the current line.
I'd suggest moving line 80 to the top of the program.
There won't be any noticable improvement from this.
wimoos
Vic 20 Afficionado
Posts: 350
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: 3D Stars

Post by wimoos »

compacted and renumbered
removed spaces
removed Z=0 and replaced by . inline
replaced D=3 by D=3/8 and removed ABS(V)
replace X(I) by XA and Y(I) by YA in appropriate places (prevents array element lookups)
remove X2 and Y2 calculations

can't test it, unfortunately.
after testing this, you could replace double-char variable names by single char names.

that's about it what you can do in BASIC, maybe review the double, tangled spaghetti loop.

Code: Select all

1 poke36879,8:poke646,1:@on:@clr:dimx(32),y(32):xc=79:yc=95:n=22:v=1/8:d=3/8
2 xm=159:ym=191:rx=120:ry=150:zw=20:fz=15:fori=1ton:gosub8:x(i)=xa:y(i)=ya:next
3 fori=1ton:xa=x(i):ya=y(i):@0,xa,ya
4 dx=xa-xc:dy=ya-yc
5 x1=xa+v*dx:y1=ya+v*dy:ifabs(x1-xa)+abs(y1-ya)<dthengosub8:goto4
6 ifx1<.ory1<.orx1>xmory1>ymthengosub8:dx=.:dy=.:goto5
7 @1,x1,y1:x(i)=x1:y(i)=y1:next:goto3
8 xa=rx*rnd(1)+zw:ya=ry*rnd(1)+fz:return
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
Merytsetesh
Vic 20 Amateur
Posts: 41
Joined: Sat Mar 02, 2024 8:57 pm
Location: Canada

Re: 3D Stars

Post by Merytsetesh »

My suggestion would be to normalise this so it's integer-based. They're always faster than FP calculations. You could then use X% and Y%, and so forth, which I think speeds up the interpreter. You could also unroll the GOSUB calls, though that's a personal call.
User avatar
srowe
Vic 20 Scientist
Posts: 1341
Joined: Mon Jun 16, 2014 3:19 pm

Re: 3D Stars

Post by srowe »

Merytsetesh wrote: Sun Apr 28, 2024 11:40 am My suggestion would be to normalise this so it's integer-based. They're always faster than FP calculations. You could then use X% and Y%, and so forth, which I think speeds up the interpreter. You could also unroll the GOSUB calls, though that's a personal call.
Integer arithmetic in CBM BASIC is slower than floating point. Integer variables are converted to fp, operators evaluated then converted back to integers.
wimoos
Vic 20 Afficionado
Posts: 350
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: 3D Stars

Post by wimoos »

Did some more rearrangement here. Curious to know if it still works, and if there is some speed improvement.

Code: Select all

1 poke36879,8:poke646,1:@on:@clr:dimx(32),y(32):xc=79:yc=95:n=22:v=1/8:d=3
2 xm=159:ym=191:rx=120:ry=150:zw=20:fz=15:fori=1ton:gosub7:x(i)=xa:y(i)=ya:next
3 fori=1ton:xa=x(i):ya=y(i):@0,xa,ya
4 dx=xa-xc:dy=ya-yc:ifabs(dx)+abs(dy)<dthengosub7:goto4
5 x1=xa+v*dx:y1=ya+v*dy:ifx1<.ory1<.orx1>xmory1>ymthendx=.:dy=.:gosub7:goto5
6 @1,x1,y1:x(i)=x1:y(i)=y1:next:goto3
7 xa=rx*rnd(1)+zw:ya=ry*rnd(1)+fz:return
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
Mike
Herr VC
Posts: 4849
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: 3D Stars

Post by Mike »

Interpreted BASIC on the VIC-20 is too slow by about two orders of magnitude to make this effect viable. No amount of trying to optimize the BASIC code is going to change that, even in the presence of a BASIC extension like MINIGRAFIK that at least gives a headache-free access to bitmap graphics.

As I already wrote above, the effect is a clear candidate for an implementation in machine code, and that implementation will likely want to use integers, not floats. The 'original' BASIC version can still be used as a blue print, and also once again, the effect should be re-written to make it perspective correct (as is, the algorithm accelerates the points away from the center in a 2D plane which is not all what you're supposed to see as a starfield effect).
groepaz
Vic 20 Scientist
Posts: 1191
Joined: Wed Aug 25, 2010 5:30 pm

Re: 3D Stars

Post by groepaz »

This isn't trivial to do even in assembly :)
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
AndyH
Vic 20 Afficionado
Posts: 368
Joined: Thu Jun 17, 2004 5:51 am
Website: https://www.hewco.uk
Location: UK
Occupation: Developer

Re: 3D Stars

Post by AndyH »

groepaz wrote: Mon Apr 29, 2024 9:28 am This isn't trivial to do even in assembly :)
Unless you cheat and use pretend 3D. :)

--
AndyH
HEWCO | Vic 20 blog
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: 3D Stars

Post by MrSterlingBS »

I like this demo much! :mrgreen:
groepaz
Vic 20 Scientist
Posts: 1191
Joined: Wed Aug 25, 2010 5:30 pm

Re: 3D Stars

Post by groepaz »

Unless you cheat and use pretend 3D
Even then really, far from trivial.
I'm just a Software Guy who has no Idea how the Hardware works. Don't listen to me.
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: 3D Stars

Post by MrSterlingBS »

Hi,

I found a great example of the 3D Stars on the following page.
https://8bitshack.org/post/starfield/

After transferring to the VIC 20 I ran into some problems.
The program collapses at some point.
If anyone has the time and desire to take a look at it that would be really great.

Many greetings and a nice May

Code: Select all

;********************************
;*     STARFIELD-SIMULATION     ;*
;*                              ;*
;*      BY MARC GOLOMBECK       ;*
;*                              ;*
;*   VERSION 1.00 / 02.04.2018  ;*
;********************************
;*
;DSK 	starfield3D
;MX   	%11
;	ORG 	$6000
;*
Temp		EQU $F0
;ADRHIR		EQU	$FB		; + $FB
PRNG		EQU	$06		; pseudo random number generator EOR-val
MATOR		EQU	$07
;ANDMSK		EQU	$08
PHLX0		EQU $20
;PHLX1		EQU $21
;PHLX2		EQU $22

PSLO      	EQU $D8     	; USING FAC-ADRESS RANGE
PSHI      	EQU $DA     	; FOR POINTER IN MULT-TAB
PDLO      	EQU $DC     	; USING ARG-ADRESS RANGE
PDHI      	EQU $DE     	; FOR POINTER IN MULT-TAB
;*
;HCLR      	EQU $F3F2   	; CLEAR HIRES SCREEN TO BLACK1
;WAIT		EQU	$FCA8		; wait a bit
;*
; MEMORY from $2000 to $3FFF

*=$1201
        dB	$0B, $12, $0A, $00, $9E
		dB	$38, $31, $39, $32			; SYS8192 = $2000
		dB	$00, $00, $00
*=$2000


INIT	
		SEI						; disable interrupt		
		lda #$7f
		sta $912e     			; disable and acknowledge interrupts
		sta $912d
		sta $911e     			; disable NMIs (Restore key)
		
; set up screen bitmap (168x192 pixels)
        LDA #%00011001          ; Decimal 12+1	; 12 lines as double char (y=192 pixel) 
        STA $9003
        LDA #%10010101			; Decimal 21 	; 21 columns (x=168 pixel)
        STA $9002
        LDA #%10001100			; Decimal 204   ; $0200-$02FF/512 screen, $1000-$1FFF/4096 charmap
        STA $9005
		
		LDA	#13					; set the screen in the middle of the TV/Monitor
		STA $9000
		LDA #$0E
		STA $900F
		
        LDX #$FC
		LDA #3					; color of pixel
SetColor:
        STA $95FF,X             
        DEX
        BNE SetColor
		
; Clean up bitmap:
CleanBitMap:  
		LDA #$00
        STA $02
        LDX #$10        		; Bitmap start @ $1000
ClBi2:   
		STX $03
        TAY
ClBi3:   
		DEY
        STA ($02),Y
		BNE ClBi3
        INX
        CPX #$20				; Bitmap ends @ $1FFF
		BNE ClBi2
		
; Set the characters on the right place				
On:								
		CLC						; CLC
		LDA #$04				; LDA #$10	= 16
		TAY						; TAY
On_00:
		STA $01FC,Y				; STA $0FF0,Y	= 4080
		ADC #$0C				; ADC #$0C	= 12
		BCC On_01				; BCC On_01
		SBC #$FB				; SBC #$EF	= 239
On_01:
		INY						; INY
		BNE On_00				; BNE On_00
			
		;STA $C010   	; delete keystrobe
		;LDA $C050		; text
		;LDA $C054		; page 1
		;LDA $C052 		; mixed off
		;LDA $C057		; hires
        ;LDA #32
        ;STA $E6         	; DRAW ON 1
		;JSR HCLR		; clear screen
		
		LDA #0
		STA PRNG
		;STZ	PRNG
				
		LDA #SSQLO/256  	; SETUP MULT-TAB
        STA PSLO+1
        LDA #SSQHI/256
        STA PSHI+1
       	LDA #DSQLO/256
        STA PDLO+1
        LDA #DSQHI/256
        STA PDHI+1
;*
MAIN
_BP1	
		lda #20
Raster:
		cmp $9004
		bne Raster
		
		LDX	#60					; number of stars max 75
_BP		DEC	STAR_Z,X			; decrease star z-distance
		BMI	_reset				; reset Z-distance 
		TXA
		AND	#%00000011			; every fourth star has double the z-speed
		BNE	_noDEC1
		DEC	STAR_Z,X
		BMI	_reset
		TXA
_noDEC1	AND	#%00000111			; every eigth star has triple the z-speed
		BNE	_noDEC2
		DEC	STAR_Z,X
		BMI	_reset
		DEC	STAR_Z,X
		BMI	_reset
_noDEC2	;LDA	#10				; slow down value for WAIT-routine
		;JSR	WAIT			; slow down the animation, approx 660 cycles for A=10
		
		;BRA	_action			; move a star	; no BRA instruction on 6502
		;CLV 					; Clear Overflow
		;BVC _action
		jmp _action
_cont	DEX						; 
		BPL 	_BP				; 
		;BRA 	_BP1
		;CLV 					; Clear Overflow
		;BVC _BP1
		jmp _BP1
_reset		
		LDA	#30
		STA	STAR_Z,X
		LDA	Temp 				; calculate new star base speed
		ADC	STAR_X,X
		ASL
		BEQ	noEOR1
		BCC	noEOR1
		INC	PRNG
		EOR	PRNG				; pseudo random number generation
noEOR1	;STA	Temp	
		BNE	noFIX1				; avoid zero value
		ADC	PRNG
noFIX1	STA	STAR_X,X			; save generated pseudo random star base speed
		ADC	STAR_Y,X
		ASL
		BEQ	noEOR2
		BCC	noEOR2
		EOR	PRNG				; pseudo random number generation
noEOR2	STA	Temp
		BNE	noFIX2
		ADC	PRNG
noFIX2	STA	STAR_Y,X			; save generated pseudo random star base speed
		JMP	_cont		
;*				
_action ;PHX					; save X index  ; no PHX instruction on 6502
		STX PHLX0
		LDY	STAR_PLOT_Y,X		; move Star y pos to Y-reg
		;LDA YLOOKLO,Y	; 
		;LDA lowb,Y
		
		;STA ADRHIR				; calc HIRES line bas address
		;LDA YLOOKHI,Y			; 
		;LDA highb,Y
		;ORA	#$20			; draw on page 1
		;STA ADRHIR+1	; 
		LDA	STAR_PLOT_X,X
		TAX
LOTABLE2  	;LDY DIV7LO,X
          	;LDA MOD7LO,X
GOTTAB2   	;TAX
          	;LDA CLRMASK,X
          	;STA ANDMSK
          	;LDA	(ADRHIR),Y
          	;AND	ANDMSK
          	;STA	(ADRHIR),Y
			
		lda highb,x
		sta $fc
		lda lowb,x
		sta $fb
		lda ($fb),y
		and xtableclr,x
		sta ($fb),y
		
		
		;PLX
		LDX PHLX0
;*
		;PHX			; calc XPLOT = STAR_X/STAR_Z
		;STX PHLX0
		LDA	STAR_X,X	; can be a signed value here
		TAY
		LDA	STAR_Z,X
		TAX
		LDA	PROJTAB,X
		STA	MATOR
		;PLX
		LDX PHLX0
		
		STA	PSHI
		EOR	#$FF
		STA	PDHI
		SEC
		LDA	(PSHI),Y
		SBC	(PDHI),Y
		LDY	STAR_X,X
		BPL	starx_done
		SEC
		SBC	MATOR
starx_done			
		CLC
		;ADC	#140		; add xoffset 140 pixel
		ADC	#78		; add xoffset 140 pixel
;		BCC	addHIGH		; X-value > 255 -> plotting at right screen edge
		STA	STAR_PLOT_X,X
		CMP #168
		BCS _doCONT
		;sta PHLX1
		;LDA #0
		;STZ	STAR_PLOT_XH,X
		;STA	STAR_PLOT_XH,X
		;BRA	doY
		;CLV 				;Clear Overflow
		;BVC doY
		;jmp doY
addHIGH	;STA	STAR_PLOT_X,X
		;LDA	#1
		;STA	STAR_PLOT_XH,X
doY		;PHX			; calc XPLOT = STAR_X/STAR_Z
		;STX PHLX0
		LDA	STAR_Y,X	; can be a signed value here
		TAY
		
		LDA	STAR_Z,X
		TAX
		
		LDA	PROJTAB,X
		
		STA	MATOR
		;PLX
		LDX PHLX0
		
		STA	PSHI
		EOR	#$FF
		STA	PDHI
		SEC
		LDA	(PSHI),Y
		SBC	(PDHI),Y
		
		LDY	STAR_Y,X
		BPL	stary_done
		SEC
		SBC	MATOR
stary_done	
		CLC
		ADC	#95				; add yoffset 96 pixel
		STA	STAR_PLOT_Y,X
		CMP	#192			; check for illegal line numbers!
		BCS	_doCONT
		;PHX
		;STX PHLX0
		TAY					; move Star y-pos to Y-reg
		;LDA 	YLOOKLO,Y	; 
		;LDA lowb,Y
		;STA ADRHIR		; 
		;LDA 	YLOOKHI,Y	; 
		;LDA highb,Y
		;ORA	#$20		; draw on page 1
		;STA ADRHIR+1	; 
		;LDA	STAR_PLOT_XH,X	; x-coordinate > 255?
		;BEQ	doLOTABLE
		;LDY STAR_PLOT_Y,X

		LDA	STAR_PLOT_X,X
		;CMP #25
		;BCS	_doCONT1	; if x > 279 then do not plot!
		TAX
		;LDY	DIV7HI,X
		;LDA	MOD7HI,X
		;BRA	GOTTAB
		;CLV 				;Clear Overflow
		;BVC GOTTAB
doLOTABLE	;LDA	STAR_PLOT_X,X
			;TAX				
LOTABLE   	;LDY DIV7LO,X
          	;LDA MOD7LO,X
GOTTAB    	;TAX
          	;LDA ANDMASK,X
          	;STA ANDMSK
          	;LDA	(ADRHIR),Y
          	;ORA	ANDMSK
          	;STA	(ADRHIR),Y
			lda highb,x
			sta $fc
			lda lowb,x
			sta $fb
			lda ($fb),y
			ora xtable,x
			sta ($fb),y
_doCONT1	;PLX			; pull X-register back from stack
			;LDX PHLX0
;*	
_doCONT		
		LDX PHLX0
		JMP	_cont			

;*
;* pixel masks for setting and clearing a pixel in a HIRES-byte
;*

* = $2500
		; 8 x 21 columns needed = 168 pixel
xtable: 
        db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; Column 1
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; Column 2
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; ...
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; ...
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; Column 20
		db %10000000,%01000000,%00100000,%00010000,%00001000,%00000100,%00000010,%00000001		; Column 21	
		
STAR_PLOT_Y	
		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
		byte	00,00,00
		
* = $2600
lowb:  
		db $40,$40,$40,$40,$40,$40,$40,$40
		db $00,$00,$00,$00,$00,$00,$00,$00
		db $C0,$C0,$C0,$C0,$C0,$C0,$C0,$C0
		db $80,$80,$80,$80,$80,$80,$80,$80
		db $40,$40,$40,$40,$40,$40,$40,$40
		db $00,$00,$00,$00,$00,$00,$00,$00
		db $C0,$C0,$C0,$C0,$C0,$C0,$C0,$C0
		db $80,$80,$80,$80,$80,$80,$80,$80
		db $40,$40,$40,$40,$40,$40,$40,$40
		db $00,$00,$00,$00,$00,$00,$00,$00
		db $C0,$C0,$C0,$C0,$C0,$C0,$C0,$C0
		db $80,$80,$80,$80,$80,$80,$80,$80
		db $40,$40,$40,$40,$40,$40,$40,$40
		db $00,$00,$00,$00,$00,$00,$00,$00
		db $C0,$C0,$C0,$C0,$C0,$C0,$C0,$C0
		db $80,$80,$80,$80,$80,$80,$80,$80
		db $40,$40,$40,$40,$40,$40,$40,$40
		db $00,$00,$00,$00,$00,$00,$00,$00
		db $C0,$C0,$C0,$C0,$C0,$C0,$C0,$C0
		db $80,$80,$80,$80,$80,$80,$80,$80
		db $40,$40,$40,$40,$40,$40,$40,$40
		
STAR_PLOT_X	
		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
   		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
		byte	00,00,00
		
* = $2700		
highb: 
        db $10,$10,$10,$10,$10,$10,$10,$10
		db $11,$11,$11,$11,$11,$11,$11,$11
		db $11,$11,$11,$11,$11,$11,$11,$11
		db $12,$12,$12,$12,$12,$12,$12,$12
		db $13,$13,$13,$13,$13,$13,$13,$13
		db $14,$14,$14,$14,$14,$14,$14,$14
		db $14,$14,$14,$14,$14,$14,$14,$14
		db $15,$15,$15,$15,$15,$15,$15,$15
		db $16,$16,$16,$16,$16,$16,$16,$16
		db $17,$17,$17,$17,$17,$17,$17,$17
		db $17,$17,$17,$17,$17,$17,$17,$17
		db $18,$18,$18,$18,$18,$18,$18,$18
		db $19,$19,$19,$19,$19,$19,$19,$19
		db $1A,$1A,$1A,$1A,$1A,$1A,$1A,$1A
		db $1A,$1A,$1A,$1A,$1A,$1A,$1A,$1A
		db $1B,$1B,$1B,$1B,$1B,$1B,$1B,$1B
		db $1C,$1C,$1C,$1C,$1C,$1C,$1C,$1C
		db $1D,$1D,$1D,$1D,$1D,$1D,$1D,$1D
		db $1D,$1D,$1D,$1D,$1D,$1D,$1D,$1D
		db $1E,$1E,$1E,$1E,$1E,$1E,$1E,$1E
		db $1F,$1F,$1F,$1F,$1F,$1F,$1F,$1F	
		
;ANDMASK   	byte 	$81,$82,$84,$88,$90,$a0,$c0
;CLRMASK		byte	$7E,$7D,$7B,$77,$6F,$5F,$3F		
;*
          	;DS \	; page alignment
;YLOOKLO   		
;				byte 	$0000000000000000
;				byte 	$8080808080808080
 ;               byte   	$0000000000000000
;                byte   	$8080808080808080
;                byte   	$0000000000000000
;                byte  	$8080808080808080
;                byte   	$0000000000000000
;                byte   	$8080808080808080
;                byte   	$2828282828282828
;                byte   	$a8a8a8a8a8a8a8a8
;                byte   	$2828282828282828
;                byte   	$a8a8a8a8a8a8a8a8
;                byte   	$2828282828282828
;                byte   	$a8a8a8a8a8a8a8a8
;                byte   	$2828282828282828
;                byte   	$a8a8a8a8a8a8a8a8
;                byte   	$5050505050505050
;                byte   	$d0d0d0d0d0d0d0d0
;                byte   	$5050505050505050
;                byte   	$d0d0d0d0d0d0d0d0
;                byte   	$5050505050505050
;                byte   	$d0d0d0d0d0d0d0d0
;                byte   	$5050505050505050
;                byte   	$d0d0d0d0d0d0d0d0
          	;DS \
;*                  
;YLOOKHI   	byte 	$0004080c1014181c
;                byte   	$0004080c1014181c
;                byte   	$0105090d1115191d
;                byte   	$0105090d1115191d
;                byte   	$02060a0e12161a1e
;                byte   	$02060a0e12161a1e
;                byte  	$03070b0f13171b1f
;                byte   	$03070b0f13171b1f
;                byte   	$0004080c1014181c
;                byte   	$0004080c1014181c
;                byte   	$0105090d1115191d
;                byte   	$0105090d1115191d
;                byte   	$02060a0e12161a1e
;                byte   	$02060a0e12161a1e
;                byte   	$03070b0f13171b1f
;                byte   	$03070b0f13171b1f
;                byte   	$0004080c1014181c
;                byte   	$0004080c1014181c
;                byte   	$0105090d1115191d
;                byte   	$0105090d1115191d
;                byte   	$02060a0e12161a1e
;                byte   	$02060a0e12161a1e
;                byte   	$03070b0f13171b1f
;                byte   	$03070b0f13171b1f
		;DS \

;*
;* multiplication tables
;*
*=$2800
SSQLO            byte $00,$00,$01,$02,$04,$06,$09,$0C
                 byte $10,$14,$19,$1E,$24,$2A,$31,$38
                 byte $40,$48,$51,$5A,$64,$6E,$79,$84
                 byte $90,$9C,$A9,$B6,$C4,$D2,$E1,$F0
                 byte $00,$10,$21,$32,$44,$56,$69,$7C
                 byte $90,$A4,$B9,$CE,$E4,$FA,$11,$28
                 byte $40,$58,$71,$8A,$A4,$BE,$D9,$F4
                 byte $10,$2C,$49,$66,$84,$A2,$C1,$E0
                 byte $00,$20,$41,$62,$84,$A6,$C9,$EC
                 byte $10,$34,$59,$7E,$A4,$CA,$F1,$18
                 byte $40,$68,$91,$BA,$E4,$0E,$39,$64
                 byte $90,$BC,$E9,$16,$44,$72,$A1,$D0
                 byte $00,$30,$61,$92,$C4,$F6,$29,$5C
                 byte $90,$C4,$F9,$2E,$64,$9A,$D1,$08
                 byte $40,$78,$B1,$EA,$24,$5E,$99,$D4
                 byte $10,$4C,$89,$C6,$04,$42,$81,$C0
                 byte $00,$40,$81,$C2,$04,$46,$89,$CC
                 byte $10,$54,$99,$DE,$24,$6A,$B1,$F8
                 byte $40,$88,$D1,$1A,$64,$AE,$F9,$44
                 byte $90,$DC,$29,$76,$C4,$12,$61,$B0
                 byte $00,$50,$A1,$F2,$44,$96,$E9,$3C
                 byte $90,$E4,$39,$8E,$E4,$3A,$91,$E8
                 byte $40,$98,$F1,$4A,$A4,$FE,$59,$B4
                 byte $10,$6C,$C9,$26,$84,$E2,$41,$A0
                 byte $00,$60,$C1,$22,$84,$E6,$49,$AC
                 byte $10,$74,$D9,$3E,$A4,$0A,$71,$D8
                 byte $40,$A8,$11,$7A,$E4,$4E,$B9,$24
                 byte $90,$FC,$69,$D6,$44,$B2,$21,$90
                 byte $00,$70,$E1,$52,$C4,$36,$A9,$1C
                 byte $90,$04,$79,$EE,$64,$DA,$51,$C8
                 byte $40,$B8,$31,$AA,$24,$9E,$19,$94
                 byte $10,$8C,$09,$86,$04,$82,$01,$80
                 byte $00,$80,$01,$82,$04,$86,$09,$8C
                 byte $10,$94,$19,$9E,$24,$AA,$31,$B8
                 byte $40,$C8,$51,$DA,$64,$EE,$79,$04
                 byte $90,$1C,$A9,$36,$C4,$52,$E1,$70
                 byte $00,$90,$21,$B2,$44,$D6,$69,$FC
                 byte $90,$24,$B9,$4E,$E4,$7A,$11,$A8
                 byte $40,$D8,$71,$0A,$A4,$3E,$D9,$74
                 byte $10,$AC,$49,$E6,$84,$22,$C1,$60
                 byte $00,$A0,$41,$E2,$84,$26,$C9,$6C
                 byte $10,$B4,$59,$FE,$A4,$4A,$F1,$98
                 byte $40,$E8,$91,$3A,$E4,$8E,$39,$E4
                 byte $90,$3C,$E9,$96,$44,$F2,$A1,$50
                 byte $00,$B0,$61,$12,$C4,$76,$29,$DC
                 byte $90,$44,$F9,$AE,$64,$1A,$D1,$88
                 byte $40,$F8,$B1,$6A,$24,$DE,$99,$54
                 byte $10,$CC,$89,$46,$04,$C2,$81,$40
                 byte $00,$C0,$81,$42,$04,$C6,$89,$4C
                 byte $10,$D4,$99,$5E,$24,$EA,$B1,$78
                 byte $40,$08,$D1,$9A,$64,$2E,$F9,$C4
                 byte $90,$5C,$29,$F6,$C4,$92,$61,$30
                 byte $00,$D0,$A1,$72,$44,$16,$E9,$BC
                 byte $90,$64,$39,$0E,$E4,$BA,$91,$68
                 byte $40,$18,$F1,$CA,$A4,$7E,$59,$34
                 byte $10,$EC,$C9,$A6,$84,$62,$41,$20
                 byte $00,$E0,$C1,$A2,$84,$66,$49,$2C
                 byte $10,$F4,$D9,$BE,$A4,$8A,$71,$58
                 byte $40,$28,$11,$FA,$E4,$CE,$B9,$A4
                 byte $90,$7C,$69,$56,$44,$32,$21,$10
                 byte $00,$F0,$E1,$D2,$C4,$B6,$A9,$9C
                 byte $90,$84,$79,$6E,$64,$5A,$51,$48
                 byte $40,$38,$31,$2A,$24,$1E,$19,$14
                 byte $10,$0C,$09,$06,$04,$02,$01,$00
;*
*=$2A00
SSQHI            byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $01,$01,$01,$01,$01,$01,$01,$01
                 byte $01,$01,$01,$01,$01,$01,$02,$02
                 byte $02,$02,$02,$02,$02,$02,$02,$02
                 byte $03,$03,$03,$03,$03,$03,$03,$03
                 byte $04,$04,$04,$04,$04,$04,$04,$04
                 byte $05,$05,$05,$05,$05,$05,$05,$06
                 byte $06,$06,$06,$06,$06,$07,$07,$07
                 byte $07,$07,$07,$08,$08,$08,$08,$08
                 byte $09,$09,$09,$09,$09,$09,$0A,$0A
                 byte $0A,$0A,$0A,$0B,$0B,$0B,$0B,$0C
                 byte $0C,$0C,$0C,$0C,$0D,$0D,$0D,$0D
                 byte $0E,$0E,$0E,$0E,$0F,$0F,$0F,$0F
                 byte $10,$10,$10,$10,$11,$11,$11,$11
                 byte $12,$12,$12,$12,$13,$13,$13,$13
                 byte $14,$14,$14,$15,$15,$15,$15,$16
                 byte $16,$16,$17,$17,$17,$18,$18,$18
                 byte $19,$19,$19,$19,$1A,$1A,$1A,$1B
                 byte $1B,$1B,$1C,$1C,$1C,$1D,$1D,$1D
                 byte $1E,$1E,$1E,$1F,$1F,$1F,$20,$20
                 byte $21,$21,$21,$22,$22,$22,$23,$23
                 byte $24,$24,$24,$25,$25,$25,$26,$26
                 byte $27,$27,$27,$28,$28,$29,$29,$29
                 byte $2A,$2A,$2B,$2B,$2B,$2C,$2C,$2D
                 byte $2D,$2D,$2E,$2E,$2F,$2F,$30,$30
                 byte $31,$31,$31,$32,$32,$33,$33,$34
                 byte $34,$35,$35,$35,$36,$36,$37,$37
                 byte $38,$38,$39,$39,$3A,$3A,$3B,$3B
                 byte $3C,$3C,$3D,$3D,$3E,$3E,$3F,$3F
                 byte $40,$40,$41,$41,$42,$42,$43,$43
                 byte $44,$44,$45,$45,$46,$46,$47,$47
                 byte $48,$48,$49,$49,$4A,$4A,$4B,$4C
                 byte $4C,$4D,$4D,$4E,$4E,$4F,$4F,$50
                 byte $51,$51,$52,$52,$53,$53,$54,$54
                 byte $55,$56,$56,$57,$57,$58,$59,$59
                 byte $5A,$5A,$5B,$5C,$5C,$5D,$5D,$5E
                 byte $5F,$5F,$60,$60,$61,$62,$62,$63
                 byte $64,$64,$65,$65,$66,$67,$67,$68
                 byte $69,$69,$6A,$6A,$6B,$6C,$6C,$6D
                 byte $6E,$6E,$6F,$70,$70,$71,$72,$72
                 byte $73,$74,$74,$75,$76,$76,$77,$78
                 byte $79,$79,$7A,$7B,$7B,$7C,$7D,$7D
                 byte $7E,$7F,$7F,$80,$81,$82,$82,$83
                 byte $84,$84,$85,$86,$87,$87,$88,$89
                 byte $8A,$8A,$8B,$8C,$8D,$8D,$8E,$8F
                 byte $90,$90,$91,$92,$93,$93,$94,$95
                 byte $96,$96,$97,$98,$99,$99,$9A,$9B
                 byte $9C,$9D,$9D,$9E,$9F,$A0,$A0,$A1
                 byte $A2,$A3,$A4,$A4,$A5,$A6,$A7,$A8
                 byte $A9,$A9,$AA,$AB,$AC,$AD,$AD,$AE
                 byte $AF,$B0,$B1,$B2,$B2,$B3,$B4,$B5
                 byte $B6,$B7,$B7,$B8,$B9,$BA,$BB,$BC
                 byte $BD,$BD,$BE,$BF,$C0,$C1,$C2,$C3
                 byte $C4,$C4,$C5,$C6,$C7,$C8,$C9,$CA
                 byte $CB,$CB,$CC,$CD,$CE,$CF,$D0,$D1
                 byte $D2,$D3,$D4,$D4,$D5,$D6,$D7,$D8
                 byte $D9,$DA,$DB,$DC,$DD,$DE,$DF,$E0
                 byte $E1,$E1,$E2,$E3,$E4,$E5,$E6,$E7
                 byte $E8,$E9,$EA,$EB,$EC,$ED,$EE,$EF
                 byte $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7
                 byte $F8,$F9,$FA,$FB,$FC,$FD,$FE,$00
;*
*=$2C00
DSQLO            byte $80,$01,$82,$04,$86,$09,$8C,$10
                 byte $94,$19,$9E,$24,$AA,$31,$B8,$40
                 byte $C8,$51,$DA,$64,$EE,$79,$04,$90
                 byte $1C,$A9,$36,$C4,$52,$E1,$70,$00
                 byte $90,$21,$B2,$44,$D6,$69,$FC,$90
                 byte $24,$B9,$4E,$E4,$7A,$11,$A8,$40
                 byte $D8,$71,$0A,$A4,$3E,$D9,$74,$10
                 byte $AC,$49,$E6,$84,$22,$C1,$60,$00
                 byte $A0,$41,$E2,$84,$26,$C9,$6C,$10
                 byte $B4,$59,$FE,$A4,$4A,$F1,$98,$40
                 byte $E8,$91,$3A,$E4,$8E,$39,$E4,$90
                 byte $3C,$E9,$96,$44,$F2,$A1,$50,$00
                 byte $B0,$61,$12,$C4,$76,$29,$DC,$90
                 byte $44,$F9,$AE,$64,$1A,$D1,$88,$40
                 byte $F8,$B1,$6A,$24,$DE,$99,$54,$10
                 byte $CC,$89,$46,$04,$C2,$81,$40,$00
                 byte $C0,$81,$42,$04,$C6,$89,$4C,$10
                 byte $D4,$99,$5E,$24,$EA,$B1,$78,$40
                 byte $08,$D1,$9A,$64,$2E,$F9,$C4,$90
                 byte $5C,$29,$F6,$C4,$92,$61,$30,$00
                 byte $D0,$A1,$72,$44,$16,$E9,$BC,$90
                 byte $64,$39,$0E,$E4,$BA,$91,$68,$40
                 byte $18,$F1,$CA,$A4,$7E,$59,$34,$10
                 byte $EC,$C9,$A6,$84,$62,$41,$20,$00
                 byte $E0,$C1,$A2,$84,$66,$49,$2C,$10
                 byte $F4,$D9,$BE,$A4,$8A,$71,$58,$40
                 byte $28,$11,$FA,$E4,$CE,$B9,$A4,$90
                 byte $7C,$69,$56,$44,$32,$21,$10,$00
                 byte $F0,$E1,$D2,$C4,$B6,$A9,$9C,$90
                 byte $84,$79,$6E,$64,$5A,$51,$48,$40
                 byte $38,$31,$2A,$24,$1E,$19,$14,$10
                 byte $0C,$09,$06,$04,$02,$01,$00,$00
                 byte $00,$01,$02,$04,$06,$09,$0C,$10
                 byte $14,$19,$1E,$24,$2A,$31,$38,$40
                 byte $48,$51,$5A,$64,$6E,$79,$84,$90
                 byte $9C,$A9,$B6,$C4,$D2,$E1,$F0,$00
                 byte $10,$21,$32,$44,$56,$69,$7C,$90
                 byte $A4,$B9,$CE,$E4,$FA,$11,$28,$40
                 byte $58,$71,$8A,$A4,$BE,$D9,$F4,$10
                 byte $2C,$49,$66,$84,$A2,$C1,$E0,$00
                 byte $20,$41,$62,$84,$A6,$C9,$EC,$10
                 byte $34,$59,$7E,$A4,$CA,$F1,$18,$40
                 byte $68,$91,$BA,$E4,$0E,$39,$64,$90
                 byte $BC,$E9,$16,$44,$72,$A1,$D0,$00
                 byte $30,$61,$92,$C4,$F6,$29,$5C,$90
                 byte $C4,$F9,$2E,$64,$9A,$D1,$08,$40
                 byte $78,$B1,$EA,$24,$5E,$99,$D4,$10
                 byte $4C,$89,$C6,$04,$42,$81,$C0,$00
                 byte $40,$81,$C2,$04,$46,$89,$CC,$10
                 byte $54,$99,$DE,$24,$6A,$B1,$F8,$40
                 byte $88,$D1,$1A,$64,$AE,$F9,$44,$90
                 byte $DC,$29,$76,$C4,$12,$61,$B0,$00
                 byte $50,$A1,$F2,$44,$96,$E9,$3C,$90
                 byte $E4,$39,$8E,$E4,$3A,$91,$E8,$40
                 byte $98,$F1,$4A,$A4,$FE,$59,$B4,$10
                 byte $6C,$C9,$26,$84,$E2,$41,$A0,$00
                 byte $60,$C1,$22,$84,$E6,$49,$AC,$10
                 byte $74,$D9,$3E,$A4,$0A,$71,$D8,$40
                 byte $A8,$11,$7A,$E4,$4E,$B9,$24,$90
                 byte $FC,$69,$D6,$44,$B2,$21,$90,$00
                 byte $70,$E1,$52,$C4,$36,$A9,$1C,$90
                 byte $04,$79,$EE,$64,$DA,$51,$C8,$40
                 byte $B8,$31,$AA,$24,$9E,$19,$94,$10
                 byte $8C,$09,$86,$04,$82,$01,$80,$00
;*
*=$2E00
DSQHI            byte $3F,$3F,$3E,$3E,$3D,$3D,$3C,$3C
                 byte $3B,$3B,$3A,$3A,$39,$39,$38,$38
                 byte $37,$37,$36,$36,$35,$35,$35,$34
                 byte $34,$33,$33,$32,$32,$31,$31,$31
                 byte $30,$30,$2F,$2F,$2E,$2E,$2D,$2D
                 byte $2D,$2C,$2C,$2B,$2B,$2B,$2A,$2A
                 byte $29,$29,$29,$28,$28,$27,$27,$27
                 byte $26,$26,$25,$25,$25,$24,$24,$24
                 byte $23,$23,$22,$22,$22,$21,$21,$21
                 byte $20,$20,$1F,$1F,$1F,$1E,$1E,$1E
                 byte $1D,$1D,$1D,$1C,$1C,$1C,$1B,$1B
                 byte $1B,$1A,$1A,$1A,$19,$19,$19,$19
                 byte $18,$18,$18,$17,$17,$17,$16,$16
                 byte $16,$15,$15,$15,$15,$14,$14,$14
                 byte $13,$13,$13,$13,$12,$12,$12,$12
                 byte $11,$11,$11,$11,$10,$10,$10,$10
                 byte $0F,$0F,$0F,$0F,$0E,$0E,$0E,$0E
                 byte $0D,$0D,$0D,$0D,$0C,$0C,$0C,$0C
                 byte $0C,$0B,$0B,$0B,$0B,$0A,$0A,$0A
                 byte $0A,$0A,$09,$09,$09,$09,$09,$09
                 byte $08,$08,$08,$08,$08,$07,$07,$07
                 byte $07,$07,$07,$06,$06,$06,$06,$06
                 byte $06,$05,$05,$05,$05,$05,$05,$05
                 byte $04,$04,$04,$04,$04,$04,$04,$04
                 byte $03,$03,$03,$03,$03,$03,$03,$03
                 byte $02,$02,$02,$02,$02,$02,$02,$02
                 byte $02,$02,$01,$01,$01,$01,$01,$01
                 byte $01,$01,$01,$01,$01,$01,$01,$01
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$00
                 byte $00,$00,$00,$00,$00,$00,$00,$01
                 byte $01,$01,$01,$01,$01,$01,$01,$01
                 byte $01,$01,$01,$01,$01,$02,$02,$02
                 byte $02,$02,$02,$02,$02,$02,$02,$03
                 byte $03,$03,$03,$03,$03,$03,$03,$04
                 byte $04,$04,$04,$04,$04,$04,$04,$05
                 byte $05,$05,$05,$05,$05,$05,$06,$06
                 byte $06,$06,$06,$06,$07,$07,$07,$07
                 byte $07,$07,$08,$08,$08,$08,$08,$09
                 byte $09,$09,$09,$09,$09,$0A,$0A,$0A
                 byte $0A,$0A,$0B,$0B,$0B,$0B,$0C,$0C
                 byte $0C,$0C,$0C,$0D,$0D,$0D,$0D,$0E
                 byte $0E,$0E,$0E,$0F,$0F,$0F,$0F,$10
                 byte $10,$10,$10,$11,$11,$11,$11,$12
                 byte $12,$12,$12,$13,$13,$13,$13,$14
                 byte $14,$14,$15,$15,$15,$15,$16,$16
                 byte $16,$17,$17,$17,$18,$18,$18,$19
                 byte $19,$19,$19,$1A,$1A,$1A,$1B,$1B
                 byte $1B,$1C,$1C,$1C,$1D,$1D,$1D,$1E
                 byte $1E,$1E,$1F,$1F,$1F,$20,$20,$21
                 byte $21,$21,$22,$22,$22,$23,$23,$24
                 byte $24,$24,$25,$25,$25,$26,$26,$27
                 byte $27,$27,$28,$28,$29,$29,$29,$2A
                 byte $2A,$2B,$2B,$2B,$2C,$2C,$2D,$2D
                 byte $2D,$2E,$2E,$2F,$2F,$30,$30,$31
                 byte $31,$31,$32,$32,$33,$33,$34,$34
                 byte $35,$35,$35,$36,$36,$37,$37,$38
                 byte $38,$39,$39,$3A,$3A,$3B,$3B,$3C
                 byte $3C,$3D,$3D,$3E,$3E,$3F,$3F,$00

*=$3000


xtableclr: 
        db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110
		db %01111111,%10111111,%11011111,%11101111,%11110111,%11111011,%11111101,%11111110		
*=$3100		
;*
;* Table for 1/Z-calculus
;*
PROJTAB   	
		byte 	$FF,$F0
 		byte 	$E8,$D5,$C4,$B6,$AA,$9F,$96
 		byte 	$8E,$86,$80,$79,$7A,$6F,$6A
 		byte 	$66,$62,$5E,$5B,$58,$55,$52
 		byte 	$50,$4D,$4B,$49,$47,$45,$43
 		byte 	$41,$40,$3E,$3D,$3B,$3A,$39
 		byte 	$37,$36,$35,$34,$33,$32,$31
 		byte 	$30,$2F,$2E,$2C,$29,$27
        byte 	$24,$21,$1E,$1B,$19,$17,$16,$14
        byte 	$13,$12,$11,$0F,$0E,$0D,$0C,$0B
        byte 	$0A,$0A,$09,$09,$08,$08,$07,$07
        byte 	$07,$07,$06,$06,$06,$06,$05,$05
        byte 	$05,$05,$05,$05,$05,$04,$04,$04
		;DS \
;*
;* division by 7 tables for pixel positioning
;*
;DIV7HI    	byte   	$24,$24,$24,$25,$25,$25,$25,$25
;          	byte   	$25,$25,$26,$26,$26,$26,$26,$26
;          	byte   	$26,$27,$27,$27,$27,$27,$27,$27
;MOD7HI    	byte   	$04,$05,$06,$00,$01,$02,$03,$04
;          	byte   	$05,$06,$00,$01,$02,$03,$04,$05
;         	byte   	$06,$00,$01,$02,$03,$04,$05,$06
          	;DS \
;*
;DIV7LO          byte   	$00,$00,$00,$00,$00,$00,$00,$01
;                byte  	$01,$01,$01,$01,$01,$01,$02,$02
;                byte   	$02,$02,$02,$02,$02,$03,$03,$03
;				byte   	$03,$03,$03,$03,$04,$04,$04,$04
;                byte   	$04,$04,$04,$05,$05,$05,$05,$05
;                byte  	$05,$05,$06,$06,$06,$06,$06,$06
;                byte   	$06,$07,$07,$07,$07,$07,$07,$07
;                byte   	$08,$08,$08,$08,$08,$08,$08,$09
;                byte   	$09,$09,$09,$09,$09,$09,$0a,$0a
;                byte   	$0a,$0a,$0a,$0a,$0a,$0b,$0b,$0b
;                byte   	$0b,$0b,$0b,$0b,$0c,$0c,$0c,$0c
;                byte   	$0c,$0c,$0c,$0d,$0d,$0d,$0d,$0d
;                byte   	$0d,$0d,$0e,$0e,$0e,$0e,$0e,$0e
;                byte   	$0e,$0f,$0f,$0f,$0f,$0f,$0f,$0f
;                byte   	$10,$10,$10,$10,$10,$10,$10,$11
;                byte   	$11,$11,$11,$11,$11,$11,$12,$12
;                byte   	$12,$12,$12,$12,$12,$13,$13,$13
;                byte   	$13,$13,$13,$13,$14,$14,$14,$14
;                byte   	$14,$14,$14,$15,$15,$15,$15,$15
;                byte   	$15,$15,$16,$16,$16,$16,$16,$16
;                byte   	$16,$17,$17,$17,$17,$17,$17,$17
;                byte   	$18,$18,$18,$18,$18,$18,$18,$19
;                byte   	$19,$19,$19,$19,$19,$19,$1a,$1a
;                byte   	$1a,$1a,$1a,$1a,$1a,$1b,$1b,$1b
;                byte   	$1b,$1b,$1b,$1b,$1c,$1c,$1c,$1c
;                byte   	$1c,$1c,$1c,$1d,$1d,$1d,$1d,$1d
;                byte   	$1d,$1d,$1e,$1e,$1e,$1e,$1e,$1e
;                byte   	$1e,$1f,$1f,$1f,$1f,$1f,$1f,$1f
;                byte   	$20,$20,$20,$20,$20,$20,$20,$21
;                byte   	$21,$21,$21,$21,$21,$21,$22,$22
;                byte   	$22,$22,$22,$22,$22,$23,$23,$23
;                byte   	$23,$23,$23,$23,$24,$24,$24,$24
;          
;MOD7LO          byte   	$00,$01,$02,$03,$04,$05,$06,$00
;                byte   	$01,$02,$03,$04,$05,$06,$00,$01
;                byte   	$02,$03,$04,$05,$06,$00,$01,$02
;                byte   	$03,$04,$05,$06,$00,$01,$02,$03
;                byte   	$04,$05,$06,$00,$01,$02,$03,$04
;                byte   	$05,$06,$00,$01,$02,$03,$04,$05
;                byte   	$06,$00,$01,$02,$03,$04,$05,$06
;                byte   	$00,$01,$02,$03,$04,$05,$06,$00
;                byte   	$01,$02,$03,$04,$05,$06,$00,$01
;                byte   	$02,$03,$04,$05,$06,$00,$01,$02
;                byte   	$03,$04,$05,$06,$00,$01,$02,$03
;                byte   	$04,$05,$06,$00,$01,$02,$03,$04
;                byte   	$05,$06,$00,$01,$02,$03,$04,$05
;                byte   	$06,$00,$01,$02,$03,$04,$05,$06
;                byte   	$00,$01,$02,$03,$04,$05,$06,$00
;                byte   	$01,$02,$03,$04,$05,$06,$00,$01
;                byte   	$02,$03,$04,$05,$06,$00,$01,$02
;                byte   	$03,$04,$05,$06,$00,$01,$02,$03
;                byte   	$04,$05,$06,$00,$01,$02,$03,$04
;                byte   	$05,$06,$00,$01,$02,$03,$04,$05
;                byte   	$06,$00,$01,$02,$03,$04,$05,$06
;                byte   	$00,$01,$02,$03,$04,$05,$06,$00
;                byte   	$01,$02,$03,$04,$05,$06,$00,$01
;                byte   	$02,$03,$04,$05,$06,$00,$01,$02
;                byte   	$03,$04,$05,$06,$00,$01,$02,$03
;                byte   	$04,$05,$06,$00,$01,$02,$03,$04
;                byte   	$05,$06,$00,$01,$02,$03,$04,$05
;                byte   	$06,$00,$01,$02,$03,$04,$05,$06
;                byte   	$00,$01,$02,$03,$04,$05,$06,$00
;                byte  	$01,$02,$03,$04,$05,$06,$00,$01
;                byte   	$02,$03,$04,$05,$06,$00,$01,$02
;                byte   	$03,$04,$05,$06,$00,$01,$02,$03

*=$3200				
;*
;* intermediate star X,Y,Z-data storage with initial values
;*
STAR_Y 		
		byte 	120,-20,40,-60,80,-100,120,-70,4,-45,60,-5,90,-75,110,-95,80,-17
		byte	12,-7,8,-24,31,115,120,125,130,135,140,145,150,155
		byte	160,165,170,175,180,185,190
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
STAR_X 	
		byte 	120,100,80,60,-40,-60,-80,-100,70,10,43,122,-23,-70,-92,-5,15,12
		byte	39,5,-34,-21,-14,-35,8,13,19,25,11,3,20,30,37,18,4,16
		byte	17,9,38
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
		byte	10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10
STAR_Z	
		byte 	25,30,35,60,35,50,32,17,5,47,23,59,17,31,5,52,16,38,20,41,13,39
		byte	2,36
		byte	10,15,20,25,30,35,40,45,40,35,30,25,20,15,10,05,10,15,20,25,30,35
		byte	40,34,29,24,19,14,9,4,8,13,18,23,28,33,38,43,39,34,29,24,19,14,9
		byte	4,7,12,17,22,27,32,37,42,47,46,41,36,31,26,21,16,11,6,1

;STAR_PLOT_XH	
;		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
;  		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
;  		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
;  		byte	00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
;		byte	00,00,00



		
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: 3D Stars

Post by MrSterlingBS »

I still have some questions about the 65C02 processor and its instructions.

STZ $20
is the same like
LDA #$00 / STA $20

PHX = STX $FB
PLX = LDX $FB

This ist not clear to me:
BRA XXXX

CLV
BVC XXXX

or can i write
JMP XXXX

***
User avatar
MrSterlingBS
Vic 20 Enthusiast
Posts: 183
Joined: Tue Jan 31, 2023 2:56 am
Location: Germany,Braunschweig

Re: 3D Stars

Post by MrSterlingBS »

Okay,

sorry for the double post.

I have found my mistake.

The value 1/Z ist calculated in a range from 4-255, if we reduce it to the maxium x value of 168 the routine works fine.
Additionally, a second table with 1/Z for Y should be created. :mrgreen:

Code: Select all

PROJTAB   	
		;byte 	$FF,$F0								; 255, 240
 		;byte 	$E8,$D5,$C4,$B6,$AA,$9F,
		byte 	$96,$8E,$86,$80,$79,$7A			; 232, 213, 196, 182, 170, 159
 		byte 	$8E,$86,$80,$79,$7A,$6F,$6A
 		byte 	$66,$62,$5E,$5B,$58,$55,$52
 		byte 	$50,$4D,$4B,$49,$47,$45,$43
 		byte 	$41,$40,$3E,$3D,$3B,$3A,$39
 		byte 	$37,$36,$35,$34,$33,$32,$31
 		byte 	$30,$2F,$2E,$2C,$29,$27
        byte 	$24,$21,$1E,$1B,$19,$17,$16,$14
        byte 	$13,$12,$11,$0F,$0E,$0D,$0C,$0B
        byte 	$0A,$0A,$09,$09,$08,$08,$07,$07
        byte 	$07,$07,$06,$06,$06,$06,$05,$05
        byte 	$05,$05,$05,$05,$05,$04,$04,$04				
Post Reply