I just uploaded version 0.21 and updated the link in the OP accordingly. So download it and give it a try.darkatx wrote:This looks just perfect for my needs!
Thanks for the effort put into this!
BTW, what is your favorite assembler?
Moderator: Moderators
Mike wrote:Presumably it is the hires toolkit written by Thomas Magnusson you are using. That one was featured in the OP of the thread 'Hires Graphics' (download) and it includes a line routine and an interface that fits your description, but it is not related to MINIGRAFIK.
O.K., that being cleared up, here's one question: How would you implement an ellipse drawing routine in TCB? A version which only uses MINIGRAFIK commands could be written as follows (all variables and expressions contain integer values):CurtisP wrote:Yes, that is the one I am using. Sorry for the confusion.
Code: Select all
10 @ON:@CLR
11 CX=80:CY=96:A=57:B=95:GOSUB15
12 GETA$:IFA$=""THEN12
13 @RETURN:END
14 :
15 X=0:Y=B:S=B*B:T=A*A*(2*Y-1):U=2*B*B:V=2*A*A:E=0
16 X1=CX+X:Y1=CY+Y:P1=X1>=0ANDX1<160:P2=Y1>=0ANDY1<192
17 X2=CX-X:Y2=CY-Y:P3=X2>=0ANDX2<160:P4=Y2>=0ANDY2<192
18 IFP1ANDP2THEN:@1,X1,Y1
19 IFP1ANDP4THEN:@1,X1,Y2
20 IFP3ANDP4THEN:@1,X2,Y2
21 IFP3ANDP2THEN:@1,X2,Y1
22 IFX=AANDY=0THENRETURN
23 F=E+S:D=0
24 G=F-T:IFABS(F)>ABS(G)THENF=G:D=1
25 G=E-T:IFABS(F)>ABS(G)THENF=G:D=2
26 E=F
27 IFD<2THENX=X+1:S=S+U
28 IFD>0THENY=Y-1:T=T-V
29 GOTO16
I will need to implement 16-bit (word) variables. My main stumbling block was that the 6502 only has an 8 bit accumulator, so I would need to use memory locations as an accumulator, and that would require making the code machine specific. But I recently realized I can temporarily store the high and low byte in Y and X.Mike wrote:O.K., that being cleared up, here's one question: How would you implement an ellipse drawing routine in TCB? A version which only uses MINIGRAFIK commands could be written as follows (all variables and expressions contain integer values):
Code: Select all
;IF FOO! = BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BNE clb00001
CMP wrdBAR
BNE clb00001
JSR lblYES
clb00001
;IF FOO! <> BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BEQ clb00002
CMP wrdBAR
BEQ clb00002
JSR lblYES
clb00002
;IF FOO! > BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BMI clb00003
BNE clb00004
CMP wrdBAR
BMI clb00003
BEQ clb00003
clb00004
JSR lblYES
clb00003
;IF FOO! >= BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BMI clb00005
BNE clb00005
CMP wrdBAR
BMI clb00005
JSR lblYES
clb00005
;IF FOO! < BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BPL clb00006
BNE clb00007
CMP wrdBAR
BPL clb00006
clb00007
JSR lblYES
clb00006
;IF FOO! <= BAR! THEN GOSUB YES
LDY wrdFOO+1
LDA wrdFOO
CPY wrdBAR+1
BEQ clb00009
BCS clb00008
BNE clb00010
clb00009
CMP wrdBAR
BEQ clb00011
BCS clb00008
clb00011
clb00010
JSR lblYES
clb00008
Mike wrote:[...](all variables and expressions contain integer values):
Actually, I meant values without fractional digits. I did not make a statement about the value range, though: CX and CY should be 16-bit signed integer (so the centre of the ellipse may be placed outside the screen in all directions), A and B may sensibly be restricted to unsigned byte, i.e. 0 .. 255. Even with that last restriction, the values in E, F, G, S, T, U, and V require 32 bits to be represented.CurtisP wrote:I will need to implement 16-bit (word) variables. [...]
What is the problem setting aside a data area to handle 2- or 4-byte values? Then you add two 32-bit values like this:My main stumbling block was that the 6502 only has an 8 bit accumulator, so I would need to use memory locations as an accumulator, and that would require making the code machine specific.
Code: Select all
CLC
LDA A
ADC B
STA C
LDA A+1
ADC B+1
STA C+1
LDA A+2
ADC B+2
STA C+2
LDA A+3
ADC B+3
STA C+3 ; C = A + B: A, B, C either all signed or all unsigned, 32-bit values
You should try this one:I just finished coding 16 bit comparisons. I still have to test them, but here is the code that I am currently generating:
Code: Select all
LDA A
CMP B
LDA A+1
SBC B+1
BCC skip
JSR A_gteq_B ; A >= B: A, B unsigned 16-bit values
.skip
[...]
Code: Select all
;IF A!+B!-C! = D! THEN LET E! = G! & H!
LDY wrdA+1
LDA wrdA
CLC
ADC wrdB
PHA
TYA
ADC wrdB+1
TAY
PLA
SEC
SBC wrdC
PHA
TYA
SBC wrdC+1
TAY
PLA
CPY wrdD+1
BNE clb00012
CMP wrdD
BNE clb00012
LDY wrdG+1
LDA wrdG
AND wrdH
PHA
TYA
AND wrdH+1
TAY
PLA
STA wrdE
STY wrdE+1
clb00012
Code: Select all
CLC
LDA wrdA
ADC wrdB
TAX
LDA wrdA+1
ADC wrdB+1
TAY
SEC
TXA
SBC wrdC
TAX
TYA
SBC wrdC+1
CMP wrdD+1 ; instead of TAY:CPY wrdD+1
BNE skip
CPX wrdD
BNE skip
LDA wrdG
AND wrdH
STA wrdE
LDA wrdG+1
AND wrdH+1
STA wrdE+1
.skip
Well dang. All variations of the mid-point algorithm require not only multiplication, but signed arithmetic as well. I wasn't planning on implementing the latter at all.Mike wrote:O.K., that being cleared up, here's one question: How would you implement an ellipse drawing routine in TCB? A version which only uses MINIGRAFIK commands could be written as follows (all variables and expressions contain integer values):
Code: Select all
REM Draw Ellipse using Bresenham Algorithm
IMPORT "LIB"
INCLUDE "MACROS"
IMPORT "GFX"
INCLUDE "MACROGFX"
IMPORT "MTH"
INCLUDE "MACROMTH"
DIM rx, ry, cx, cy, z
LET cx=64
LET cy=64
LET rx=20
LET ry=30
GRAPHICS
CLEAR
GOSUB BELLIPSE
INP z
EXIT
LABEL BELLIPSE
REM Draw Ellipse
REM rx = x radius, ry = y radius, cx = center x, cy = center y
DIM d1!,rxsq!,rysq!,tworxsq!,tworysq!,dx!,dy!,z!
DIM i,gd,gm,x,y
LET rxsq!=MULT(rx,rx)
LET rysq!=MULT(ry,ry)
REM tworxsq=2*rxsqy
LET tworxsq!=rxsq!
SHIFTL tworxsq!
REM tworysq=2*rysq
LET tworysq!=rysq!
SHIFTL tworysq!
LET x=0
LET y=ry
REM d1=rysq-rxsq*ry+(0.25*rxsq)
LET d1!=MULTW(rxsq!,ry)
SHIFTR rxsq!
SHIFTR rxsq!
LET d1!=rysq!-d1!+rxsq!
LET dx!=MULTW(tworysq,x)
LET dy!=MULTW(tworxsq,y)
WHILE Y>0
LET z=cy+y
PLOT cx+x,z
PLOT cx-x,z
LET z=cy-y
PLOT cx-x,z
PLOT cx+x,z
LET x=x+1
LET dx!=dx!+tworysq!
IF d1! >= $8000 THEN
LET d1!=d1!+dx!+rysq!
ELSE
LET y=y-1
LET dy!=dy!-tworxsq!
LET d1!=d1!+dx!-dy!+rysq!
ENDIF
WEND
RETURN
No need to test it, because the routine won't work anyway, for several reasons.CurtisP wrote:OK, an elipse drawing program would look something like this (i say something like this, because this code is untested).
A Bresenham-style line routine for a resolution up to 256x256 pixels implements quite easily with anything that supports 8-bit values. The corresponding code in MINIGRAFIK is roughly 100 bytes in size.CurtisP wrote:I really think that any kind of Bressenham or Mid-Point Algorithm is outside the scope of small or tiny languages.
Smoke testing the routine in, say, CBM BASIC + MINIGRAFIK would have revealed immediately, that your implementation was not working. And, unlike logic errors buried deep within some code, the errorneous graphics output is right before your eyes.Thanks for the input.