message "division by zero error"

Basic and Machine Language

Moderator: Moderators

User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: message "division by zero error"

Post by Mike »

armypavarmy wrote:example: first origin with point 1,100,100 after only the draw to x, y command as I do with Minigrafik I have to write @1,100,100 to x, y and then?

I should write @ 1,100,100 and then @ 1 to x, y [...]
As per my example above you rewrite the DRAW commands as follows:

@1,100,100:XC=100:YC=100

@1,XC,YC TO X,Y:XC=X:YC=Y

Of course you still need to take into account, that Super Expander uses another coordinate range (1024x1024 'virtual' coordinates) than MINIGRAFIK (160x192 pixel coordinates), so you have to re-scale all coordinates as well.
[...] but it is not possible.
As you see, it is possible. You just need to understand what the TO part with the missing first coordinate values actually means and rewrite it with temporary variables!
Minigrafik that I have [...]
The version of MINIGRAFIK that I released in 2008, and which is part of the MG batch suite, is the most recent.
[...] does not accept also multiple TO I don't know how to do it any other way
Multiple TOs are done in exactly the same way as I laid out above, with temporary variables that hold the last coordinate pair of a single line stroke in the traverse.
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: message "division by zero error"

Post by armypavarmy »

Hello Mike
thanks for help.
Command changed for Minigrafik
as you indicated the draw works.
However, it is not enough because there are problems with the parameters entered.
Listed for me strange and unusual.
It should be rewritten for Minigrafik
for 100% operation
Thanks anyway…….Armando
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: message "division by zero error"

Post by Mike »

You should be able to keep those parts of the program unchanged that are not directly involved with graphics.

However, one part of the input screen needs to be adapted to the changed screen start (4096 with +8K or more vs. 7680 with unexpanded or +3K), this is what wimoos pointed out in an earlier post here:
wimoos wrote: Wed Oct 07, 2020 1:43 amchange line 260 to

Code: Select all

260 FOR I=4536 TO 4579 : POKE I,32 : NEXT I
Also, the re-scaling procedure should only be done once - as last step from the originally calculated values! -, right before putting them into the @ commands, by multiplying the x-coordinate with 5/32 and the y-coordinate with 3/16 (both fractions were reduced from 160/1024 and 192/1024, respectively).
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: message "division by zero error"

Post by armypavarmy »

Hello Mike
The version for Minigrafik
which I am trying to do.
It works partly because the
number entered in "Spin"
is not shared.
With Minigrafik the graphic
is repeated beyond the number of
sometimes referred to in "Spin- 1 to 18"
and consequently if it does not stop it goes Out of screen.
Also with the Movement or Decrement options.
I do not understand why'?.
Thanks ..... Armando
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: message "division by zero error"

Post by Mike »

These are the necessary changes to port Spiralizer from Super Expander to MINIGRAFIK:

Code: Select all

SE: 100 IF FL=1 THEN:GRAPHIC 4
MG: 100 @RETURN:SX=5/32:SY=3/16
MG always returns to text mode here (the graphics area remains allocated). SX and SY are extra and define the scaling ratios for later use.

Code: Select all

SE: 170 FOR I=7TO0 STEP-1:FORJ=1TO50:NEXT J:POKE 38680,I:NEXT I
MG: 170 FOR I=7TO0 STEP-1:FORJ=1TO50:NEXT J:POKE 38168,I:NEXT I
Changed address in colour RAM because of different screen (and colour RAM) base address (unexpanded/+3K vs. >=+8K).

Code: Select all

SE: 260 FOR I=8120 TO 8163:POKE I,32:NEXT I
MG: 260 FOR I=4536 TO 4579:POKE I,32:NEXT I
Again change of screen RAM address.

Code: Select all

SE: 420 GRAPHIC 2:COLOR 1,2,C5,C5
MG: 420 POKE36879,26:POKE646,C5:@ON:@CLR
Set background (1=white), border (2=red) and foreground colour (C5=random), enable graphics, clear screen. No need to define the auxiliary colour.

Code: Select all

SE: 430 POINT C5,125+(Z+100)/1.3,130
MG: 430 CX=SX*(125+(Z+100)/1.3):CY=SY*(520-J-I)
The MG version just remembers the 'last drawn pixel' here in CX and CY and doesn't draw it. That pixel duly gets drawn with the first DRAW TO equivalent. Using "520-J-I" instead of plain "130" prevents a small glitch from being drawn. Using "C5" as colour source in the SE POINT command is in error and the value should actually be 1 (=foreground) instead.

Code: Select all

SE: 490 IF X<0 OR Y<0 THEN 650
MG: 490 IF X<0 OR X>=1024 OR Y<0 OR Y>=1024 THEN 650
Slightly improved bounds check, still in "SE coordinates".

Code: Select all

SE: 500 DRAW 1 TO X,Y:NEXT
MG: 500 @1,CX,CYTOSX*X,SY*Y:CX=SX*X:CY=SY*Y:NEXT
Transformation of SE coordinates into MG coordinates, update of CX and CY to continue the traverse with the next "DRAW TO" commands.

Code: Select all

SE: 660 GRAPHIC 4:PRINT"{CLR,2 DOWN}COORDINATES ARE OUR{3 SPACE}OF RANGE"
MG: 660 @RETURN:PRINT"{CLR,2 DOWN}COORDINATES ARE OUT{3 SPACE}OF RANGE"
Return to text mode for the error message. Again, the graphics area remains allocated. Typo corrected.

Code: Select all

SE: 690 FORV=15 TO 0 STEP -.5:SOUND245,0,0,0,V:NEXT:RETURN
MG: 690 FORV=15 TO 0 STEP -.5:POKE36874,245:POKE36878,V:NEXT:RETURN
That's what the SOUND command only does: syntactic sugar (only the "Alto" voice is written to in the MG port; "Tenore", "Soprano" and "Noise" are left out).
armypavarmy wrote:The version for Minigrafik which I am trying to do.

It works partly because the number entered in "Spin" is not shared. With Minigrafik the graphic is repeated beyond the number of sometimes referred to in "Spin- 1 to 18" and consequently if it does not stop it goes Out of screen. Also with the Movement or Decrement options. I do not understand why?
Whatever went wrong with your attempt to port the Spiralizer program - MINIGRAFIK was not the reason it didn't work.

Greetings,

Michael
armypavarmy
Vic 20 Hobbyist
Posts: 107
Joined: Wed Oct 02, 2013 1:54 am
Location: Italy

Re: message "division by zero error"

Post by armypavarmy »

[attachment=0]spiramgr.zip
Hello Mike
I made all the changes
that you told me.
There continue to be problems.
In addition to the parameters m and d
also the first data (for number of designs on one
screen only) is accepted but always runs only one graph.
I don't know if I did something wrong?
I am attaching rows so you know what I am
managed to do.
I wanted to publish it but I don't like how it works.
If only for your curiosity, look at it.
Attachments
spiramgr.zip
(1.46 KiB) Downloaded 28 times
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: message "division by zero error"

Post by Mike »

I compared your MG version with mine, and besides "boilerplate" (the extra caption you inserted about this being the MG version), they're mostly identical - except this extra line statement:

Code: Select all

425 W=(125+(Z+100)/1.3)/6.4:Q=130/6.4
... which truly shouldn't be there. It looks like remnants of an earlier attempt of yours to scale down the coordinates from 1024x1024 to 160x160. The assignment to Q is quite harmless, Q is used nowhere else in the program. However, the assignment to W overwrites a vital value important for the drawing algorithm, which explains the strange behaviour.

When you delete line 425, everything should work as expected.
Post Reply