Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 15:35 29 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : out of memory error

Author Message
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1567
Posted: 04:02pm 23 Mar 2023
Copy link to clipboard 
Print this post

Hi, I tried bresenham line code,not basic but think I converted it but gives out of memory error.
I want to plot the x,y co-ordinates from x1,y1 to x2,y2 but use for sprite co-ords
and move each loop or slower.
OPTION EXPLICIT
OPTION DEFAULT NONE
OPTION DEFAULT INTEGER
dim dy, dx, incrE, incrNE, d, x, y
dim x1,x0,y1,y0
cls rgb(black)
'The procedure takes the start points (x0,y0) and end points(x1,y1) of the line as arguments.
'draw_line (x0,y0,x1,y1)

x0=160:y0=200:x1=50:y1=40 'test line

'The internal variables dy, dx, incrE, incrNE, d, x, y. dx is the change in x, dy the change in y. d determines if the next pixel is on the same line or rises one. The variables incrE and incrNE are used to change the value of d. x and y are the point to be plotted, initially the first point given.
 dx = x1 - x0
 dy = y1 - y0
 d = 2 * dy - dx
 incrE = 2*dy
 incrNE = 2*(dy - dx)
 x = x0
 y = y0
 pixel (x,y,rgb(yellow))
'The while loop does the work. x is incremented each time through the loop. Because the plot happens at the end of the loop, x is incremented before each plot.
do while (x < x1)
   {
'If d is less than one d is increased by incrE, y remains the same, and x is incremented.
 if (d <= 0)
   d=d+incrE
   x=x+1
'Otherwise d is increased by incrNE, and both x and y are incremented.
 else
   d=d+incrNE
   x=x+1
   y=y+1
 endif
 pixel(x,y,rgb(yellow))
loop
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 1567
Posted: 04:17pm 23 Mar 2023
Copy link to clipboard 
Print this post

if there's a missile command game in mmbasic the slow line code would be there.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 04:24pm 23 Mar 2023
Copy link to clipboard 
Print this post

  stanleyella said  if there's a missile command game in mmbasic the slow line code would be there.


Yes for the CMM2, by @Vegipete, but it may be unreadable because the BASIC was "compressed" to meet the size requisites of the 2021 Programming Challenge: https://multimite.strongedge.net/greenhills.html

Best wishes,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3807
Posted: 05:57pm 23 Mar 2023
Copy link to clipboard 
Print this post

Not sure if that was your actual code that you posted, but there is an errant '{' after the DO WHILE. Possibly the problem is an incorrectly reported syntax error?

Also don't forget you can use the INC command for incrementing and decrementing variables.

Best wishes,

Tom
Edited 2023-03-24 03:57 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 06:22pm 23 Mar 2023
Copy link to clipboard 
Print this post

  thwill said  
  stanleyella said  if there's a missile command game in mmbasic the slow line code would be there.


Yes for the CMM2, by @Vegipete, but it may be unreadable because the BASIC was "compressed" to meet the size requisites of the 2021 Programming Challenge


There's a less compressed version of VegiPete's In Defense of the Green Hills for the F4 here

I'm not sure how successfully it could be made to run on the PicoMite--it was slow on the Armmite F4--but the firmware has been tweaked considerably since then. For speed, it would need VGA or an SSD1963 (Mick has a PicoMite design). The algorithm for slow line draw from there should be fine.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024