6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 5:43 pm

All times are UTC




Post new topic Reply to topic  [ 609 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24 ... 41  Next
Author Message
PostPosted: Tue Mar 12, 2013 10:50 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
ClearScreen and the Origin (green pixel):
Code:
START:       LDA #$0000
            TAZP                 ;SET ZEROPAGE @$0000_0000
            LDA #$0001
            TASP                 ;SET STACKPAGE @$0001_0000
           
            LDWi $0000           ;  LDW #$0000 - SET BLACK SCREEN ACCORDING TO COLOR LUT
            LDBaw COLTABLE       ;  LDB COLTABLE,w
            STBa SCRCOL          ;  STB SCRCOL
            JSR CLRSCR
           
            LDWi $0005           ;  LDW #$0005 - SET PIXEL COLOR GREEN ACCORDING TO COLOR LUT
            LDBaw COLTABLE       ;  LDB COLTABLE,w
            STBa PXLCOL          ;  STB PXLCOL
            LDA #$0140           ;X CENTER OF 640x480 SCREEN
            STA SCRLO
            LDA #$80F0           ;Y CENTER OF 640x480 SCREEN
            STA SCRHI
            LDY #$0000
            LDX #$0010           ;16 PIXELS WIDE AROUND THE ORIGIN
            STBiy SCRLO          ;  STB (SCRLO),Y
           
END         JMP END
                                             
CLRSCR      LDA #$0000        ;$8000_0000 START OF VIDEO MEMORY
            STA SCRLO         ;X VALUE
            LDA #$8000
            STA SCRHI         ;Y VALUE
            LDX #$01E0       
            LDA SCRCOL
AB          LDY #$0280        ;$81DF_027F END OF VIDEO MEMORY
AA          STA (SCRLO),Y
            DEY
            BNE AA
            STA (SCRLO),Y     ;GET THAT LAST PIXEL!
            INC SCRHI
            DEX
            BNE AB
            RTS


Attachments:
P1000959b.JPG
P1000959b.JPG [ 95 KiB | Viewed 1275 times ]

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 9:19 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Having some fun with the .b core (RADIUS is $0010):) :
Code:
LDA #$0140           ;X CENTER OF 640x480 SCREEN
            STA SCRLO
            LDA #$80F0           ;Y CENTER OF 640x480 SCREEN
            STA SCRHI
            STBiy SCRLO          ;  STB (SCRLO),Y    PLOT
           
            LDA SCRHI            ;A ACCUMULATOR, Y COORDINATE
            SBCAopCzp YRADIUS     ;C ACCUMULATOR, Y MATH
            STCzp SCRHI
            STBiy SCRLO          ;PLOT
            ADCAopCzp YRADIUS
            STCzp SCRHI
            STBiy SCRLO          ;PLOT
            STA SCRHI            ;RE-CENTER
           
            LDDzp SCRLO          ;D ACCUMULATOR, X COORDINATE
            SBCDopEzp XRADIUS     ;E ACCUMULATOR, X MATH
            STEzp SCRLO
            STBiy SCRLO          ;PLOT
            ADCDopEzp XRADIUS
            STEzp SCRLO
            STBiy SCRLO          ;PLOT


Attachments:
P1000962.JPG
P1000962.JPG [ 17.46 KiB | Viewed 1260 times ]

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 4:58 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Ugh, not so easy to convert 6502 programs to 65Org16!
I successfully converted Lee's Square routine made for the 6502.
But I have a headache from trying to convert his SquareRoot routine.

EDIT: Ohhh, I found a fast routine here I'll try to convert! It works in MK's assembler/debugger, but there is no remainder, so testing sqrt(13)=3.6 = 3. Not even rounded off. :|

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 6:41 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
If your goal is to draw circles, you should check out Bresenham's circle algorithm. It only uses simple operations as long as you draw full circles.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 7:17 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Yes I'm going for circles, but I need some code now! I can't afford weeks of figuring that stuff out. I never learned C.
I already have the Square routine, all I need is the SQRT and I'll have something I hope.

Maybe I will have to take some time converting Bresenham line algorithm to assembly. After these 2 algorithms, circle and line, the sky is the limit.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 9:25 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Arlet wrote:
If your goal is to draw circles, you should check out Bresenham's circle algorithm. It only uses simple operations as long as you draw full circles.

Hey EE,

My SBC-3 cc65 library uses the Bresenham alorithm. So does my AVR 320x240 display. I posted a QuickBASIC conversion here:
viewtopic.php?f=1&t=2087&hilit=320x240&start=16

I can post a stand alone aseembly version if you want it... might take a day to put it together though.

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 10:06 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
8BIT wrote:
...I can post a stand alone assembly version if you want it... might take a day to put it together though.

Daryl

I would be in your debt!

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 10:58 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
I just now realized (even after I was celebrating! :lol: ) I had to reset the origin after plotting each and every pixel! WOOOO!
EDIT: It's still not 100% because I was expecting a 1/2 circle on the right side only, but I may learn from the mistake!


Attachments:
P1000963.JPG
P1000963.JPG [ 151.78 KiB | Viewed 1209 times ]

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 13, 2013 11:26 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
This is what I was after, had the loop check (bne) too early. The following is correct together with these 1st 2 subroutines:
Code:
START:       LDA #$0000
            TAZP                 ;SET ZEROPAGE @$0000_0000
            LDA #$0001
            TASP                 ;SET STACKPAGE @$0001_0000
           
            LDWi $0000           ;  LDW #$0000 - SET BLACK SCREEN ACCORDING TO COLOR LUT
            LDBaw COLTABLE       ;  LDB COLTABLE,w
            STBzp SCRCOL          ;  STB SCRCOL
            JSR CLRSCR
           
            LDWi $0005           ;  LDW #$0005 - SET PIXEL COLOR GREEN ACCORDING TO COLOR LUT
            LDBaw COLTABLE       ;  LDB COLTABLE,w
            STBzp PXLCOL         ; B ACCUMULATOR, PIXELCOLOR
            LDA #$0000
            STA Numberh
            CLC
           
            LDWi $0000           ; LDW #$0000
           
AC          LDA #$0140           ; X CENTER OF 640x480 SCREEN
            STA SCRLO
            LDA #$80F0           ; Y CENTER OF 640x480 SCREEN
            STA SCRHI            ; START @ORIGIN
                       
            STWzp Number         ; This 'Number' is actually X
            JSR Square           ; Now square it!
            LDA #$E100           ; Radius=$F0, R^2=$E100
            SBC Sqr              ; Sqr=Number^2
            STA Numberl          ; This Numberl IS (R^2-X^2)
            JSR SqRoot           ; THIS ROUTINE WILL RETURN Root=SQRT(Numberl)
           
            TWY
            LDA SCRHI            ;A ACCUMULATOR, Y COORDINATE
            SBCAopCzp Root       ;C ACCUMULATOR, Y MATH
            STCzp SCRHI
            STBiy SCRLO          ;PLOT 1st Quadrant
            ADCAopCzp Root
            STCzp SCRHI
            STBiy SCRLO          ;PLOT 2nd Quadrant
                                   
            INW
            CPWi $00EF           ; CPW #$00EF
            BNE AC
           
END         JMP END


EDIT: Tightened up the assembly code, same result except for the center pixel.


Attachments:
P1000965.JPG
P1000965.JPG [ 70.36 KiB | Viewed 1207 times ]

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502
Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 1:35 am 
Offline
User avatar

Joined: Thu Mar 11, 2004 7:42 am
Posts: 362
ElEctric_EyE wrote:
I was thinking Mandlebrot that Bruce had made for the 65816 and adapt it to 65Org16 (I thought he had originally made it for the 65Org16, guess I was wrong).


It was written to be easily ported to the 65org16, though. Except the for IIgs-specific code, like the ReadAsciiTime toolbox call, there are no 65C02 or later opcodes, like PHX, nor 65C02 or later addressing modes, like (stack,S),Y. So all that should be necessary is to discard the IIgs code and add your own OUTPUT, PLOT, etc. routines. I haven't tried actually porting it to the 65org16, but that's the intent.

GARTHWILSON wrote:
and there's Samuel Falvo's blitter article at http://6502org.wikidot.com/blitter-theory-part-1 (although it looks like a few equations need fixing in order to show up at all. I'll contact him.)


Garth! It's a wiki, fer cryin' out loud. You can make fixes yourself as you spot them. There's online reference material and everything. For info on \left and \right in LaTeX (used for the equations), see section 6 (p.13) here:

ftp://ftp.ams.org/pub/tex/doc/amsmath/s ... -guide.pdf


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 4:47 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
ElEctric_EyE wrote:
8BIT wrote:
...I can post a stand alone assembly version if you want it... might take a day to put it together though.

Daryl

I would be in your debt!


Here ya go!

Code:
;*************************************************************************
; Draw a circle using Bresenham's circle algorithm
;
; 65C02 code written by Daryl Rictor
;*************************************************************************

; ZP variables

; ZP base address of data area
ZPBase = $00

XC   =   $00 + ZPBase      ; Center Point
YC   =   $02 + ZPBase      ;
R   =   $04 + ZPBase      ; radius (1 byte)
XP   =   $06 + ZPBase      ; plot point
YP   =   $08 + ZPBase      ;
X1   =   $0a + ZPBase      ; x,y intermediate
Y1   =   $0c + ZPBase      ;
FF   =   $0e + ZPBase      ; difference
FX   =   $10 + ZPBase      ; diff x
FY   =   $12 + ZPBase      ; diff y



; ------------------------------------------------------------------------
; SETPIXELCLIP: Test pixel @ XP,YP and plot if on screen
SETPIXELCLIP

; insert user code here

   rts

; ------------------------------------------------------------------------
; CIRCLE: Draw a circle around the center XC/YC with radius in R.
;
; Must set an error code: NO
;
CIRCLE
   lda   R      ; get Radius
   bne   _C1
   lda   XC      ; if R=0, plot center point and exit
   sta   XP      ; move center point to plot point var
   lda   XC+1
   sta   XP+1
   lda   YC
   sta   YP
   lda   YC+1
   sta   YP+1
   jmp   SETPIXELCLIP   ; Plot as a point and exit

;  int y = radius;
_C1   lda   R      ; 8 bit radius - can be expanded to 16 bit
   sta   Y1
   stz   Y1+1

;  int x = 0;
   stz   X1
   stz   X1+1

; int f = 1 - radius;      ; if using 16 bit radius, this code section
   sec         ; will need modifications
   lda   #$01
   sbc   R
   sta   FF
   stz   FF+1
   bcs      _C2
   dec   FF+1

; int ddF_x = 1;
_C2    lda   #$01
   sta   FX
   stz   FX+1

; int ddF_y = -2 * radius;   ; if using 16 bit radius, this code section
   stz   FY+1      ; will need modifications also
   lda   R
   asl         ; *2
   sta   FY
   rol   FY+1
   lda      FY
   EOR   #$FF
         sta   FY
   lda   FY+1
   EOR   #$FF
   sta   FY+1
   inc   FY
   bne   _C3
   inc   FY+1

;  tgi_setpixel(xC, yC + y);
_C3   lda   XC
   sta   XP
   lda   XC+1
   sta   XP+1
   clc
   lda   YC
   adc   Y1
   sta   YP
   lda   YC+1
   adc   Y1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC, yC - y);
   sec
   lda   YC
   sbc   Y1
   sta   YP
   lda   YC+1
   sbc   Y1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC + y, yC);
   clc
   lda   XC
   adc   Y1
   sta   XP
   lda   XC+1
   adc   Y1+1
   sta   XP+1
   lda   YC
   sta   YP
   lda   YC+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC - y, yC);
   sec
   lda   XC
   sbc   Y1
   sta   XP
   lda   XC+1
   sbc   Y1+1
   sta   XP+1
   jsr   SETPIXELCLIP

_CLOOP
;  while (x < y) {      ; calculate next plot step
   sec
   lda   X1
   sbc   Y1
   lda   X1+1
   sbc   Y1+1
   bcc   _C4   ; x<y
   rts

_C4   lda   FF+1
   bmi   _C6

   lda   Y1
   bne   _C5
   dec   Y1+1
_C5   dec   Y1
   clc
   lda   FY
   adc   #$02
   sta   FY
   tax
   lda   FY+1
   adc   #$00
   sta   FY+1
   tay
   clc
   txa
   adc   FF
   sta   FF
   tya
   ADC   FF+1
   sta   FF+1

_C6   inc   X1
   bne   _C7
   inc   X1+1
_C7   clc
   lda   FX
   adc   #$02
   sta   FX
   tax
   lda   FX+1
   adc   #$00
   sta   FX+1
   tay
   clc
   txa
   adc   FF
   sta   FF
   tya
   ADC   FF+1
   sta   FF+1      ; computations done - now plot 8 Octants

;  tgi_setpixel(xC + x, yC + y);
   clc
   lda   XC
   adc   X1
   sta   XP
   pha
   lda   XC+1
   adc   X1+1
   sta   XP+1
   pha
   clc
   lda   YC
   adc   Y1
   sta   YP
   lda   YC+1
   adc   Y1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC - x, yC + y);
   sec
   lda   XC
   sbc   X1
   sta   XP
   lda   XC+1
   sbc   X1+1
   sta   XP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC - x, yC - y);
   sec
   lda   YC
   sbc   Y1
   sta   YP
   lda   YC+1
   sbc   Y1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC + x, yC - y);
   pla
   sta   XP+1
   pla   
   sta   XP
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC + y, yC + x);
   clc
   lda   XC
   adc   Y1
   sta   XP
   pha
   lda   XC+1
   adc   Y1+1
   sta   XP+1
   pha
   clc
   lda   YC
   adc   X1
   sta   YP
   lda   YC+1
   adc   X1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC - y, yC + x);
   sec
   lda   XC
   sbc   Y1
   sta   XP
   lda   XC+1
   sbc   Y1+1
   sta   XP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC - y, yC - x);
   sec
   lda   YC
   sbc   X1
   sta   YP
   lda   YC+1
   sbc   X1+1
   sta   YP+1
   jsr   SETPIXELCLIP

;  tgi_setpixel(xC + x, yC - y);
   pla
   sta   XP+1
   pla   
   sta   XP
   jsr   SETPIXELCLIP
   jmp   _CLOOP


Attachments:
circle.asm [3.93 KiB]
Downloaded 75 times

_________________
Please visit my website -> https://sbc.rictor.org/
Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 10:42 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Awesome work, and thanks!
I'll add it to 65Org16 routines after I convert it and test it.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 12:37 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Thanks... happy to help!

Daryl


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 6:23 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
By the way, another technique to draw a circle is to draw a polygon instead using straight line segments from one point to the next. The location of the points are x=r*cos(phi) and y=r*sin(phi), but you can replace the sin() by a lookup table. This method is simple, reasonably fast (if you use the table), and can be easily modified to draw partial circles.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 14, 2013 9:47 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
I reckon tables would be much faster, but looking at Daryl's take on the Bresenham algorithm I don't see any loops. That has got to be fast too, probably faster than what I'm doing now.

Is there another advantage besides speed for your idea?

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 609 posts ]  Go to page Previous  1 ... 18, 19, 20, 21, 22, 23, 24 ... 41  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: