Welcome, Guest. Please login or register.

Author Topic: AmigaBasic revisited  (Read 2704 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline melottTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2002
  • Posts: 989
    • Show only replies by melott
AmigaBasic revisited
« on: February 18, 2003, 02:08:40 PM »
So....

For x=0 to 255
Print chr$(x) ;
Gosub LineLen
Next x
end

LineLen:
for y=1 to 25
If y<25 then Return
If y=25 then Print chr$(13)
next y

What I'm tring to do is print 25 characters
per line then a carrage return and start another
line until X reaches 255.

This doesn't work .
Anyone????
And how do I do a carrage return without
doing a Print chr$(13) ?

Mel Ott
 :-?
Stealth ONE  8-)
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: AmigaBasic revisited
« Reply #1 on: February 18, 2003, 02:23:03 PM »
I'm no BASIC man, as anybody checking the developer forum could vouch for by now ;-), but I'll have a go..

I think your problem comes down to the fact that your 'y' variable is initialized with the value 1 every time you call the subroutine. The subroutine returns  immediately because of the 'if y<25 then return' condition. Consequently, y never gets to 25 and you don't get your carriage return.

You could just use a modulus of your 'x' value in the main loop. Not sure about the syntax, but something like

for x=0 to 255
print chr$(x)
if x%25 == 0 then print chrs$(13)
next x

Does BASIC have a modulus anybody?

In any event, bear in mind that there are lots of unprintable characters before when x < 32
int p; // A
 

Offline Thomas

Re: AmigaBasic revisited
« Reply #2 on: February 18, 2003, 03:03:07 PM »
Oh dear...

Here is how it could work:

len = 0
for i=32  to 255
   print chr$(i);
   len = len + 1
   if len >= 25 then
      print
      len = 0
   endif
next

Note: characters below 32 are not printable

Example 2:

a$ = ""
for i=32 to 255
   a$ = a$ + chr$(i)
   if len(a$) >= 25 then
      print a$
      a$ = ""
   endif
next

Example 3:

for i = 32 to 231 step 25
   for j=0 to 24
      print chr$(i+j);
   next
   print
next
for j=232 to 255
   print chr$(j);
next
print

Note: this one would work better if the line length (25) was a divider of 256 (e.g. 32).

Bye,
Thomas

  • Guest
Re: AmigaBasic revisited
« Reply #3 on: February 18, 2003, 04:42:37 PM »
The Amiga does not use Chr$(13) for line
termination. It uses Chr$(10) which
produces a and . A will just
restart printing at the beginning of the
same line.
 

Offline MarkTime

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 901
    • Show only replies by MarkTime
    • http://www.tanooshka.com
Re: AmigaBasic revisited
« Reply #4 on: February 18, 2003, 07:11:59 PM »
well, as someone already stated, that LineLen routine just doesn't do anything useful.

But I think this can be accomplished in one line, using modulo division, just divide y by 25, and if the "remainder" (from hand calculated long division)
is zero then you have a multiple of 25, and its time to go to the next line.

I do not know how to write that in Amiga basic, but here is some pseudo code:

after printing x, then just check:

if x%25=0 then print;


EDITED......
oh crud, just saw someone already gave the answer, well, let me say I agree!!!

 ;-)  ;-)  ;-)
 

Offline FluffyMcDeath

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 3440
    • Show only replies by FluffyMcDeath
Re: AmigaBasic revisited
« Reply #5 on: February 18, 2003, 07:55:44 PM »
Quote


Does BASIC have a modulus anybody?


I think it's mod , but I'm not sure and can't remember how to use it if it is. However,

let n=25
...
if (x/n) = int(x/n) then
 blah blah blah

will do the same in AmigaBasic MOST of the time. Certainly for small numbers AmigaBasic was pretty good about rounding its floats. I'd stay away from it though because, while it may be mathematically correct, computers aren't.

Safer way, if you don't have mod is to just count:
if count > 0 then
{
  print char(x)
  count--
}
else
{
  print
  count = n
}




 

Offline FluffyMcDeath

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 3440
    • Show only replies by FluffyMcDeath
Re: AmigaBasic revisited
« Reply #6 on: February 18, 2003, 08:09:54 PM »
Oh well, just checked an online faq and there doesn't appear to be a mod operator.

Thomas' number 2 looks nice. But for speed, counting beats LEN$ ing.  Then again, if you want speed go C.
 

Offline MarkTime

  • Hero Member
  • *****
  • Join Date: Jun 2002
  • Posts: 901
    • Show only replies by MarkTime
    • http://www.tanooshka.com
Re: AmigaBasic revisited
« Reply #7 on: February 18, 2003, 08:24:00 PM »
If you want speed, just unravel the loops....

I mean

print chr$(33)
print chr$(34)
print chr$(35)
etc...etc....
print chr$(50)
print chr$(13)
print chr$(51)

this is a legitimate practice, unraveling loops!

<--everyone stares at me in horror -->

also you could probably have a 'DATA' field doing the same thing, which would look a little cleaner

psuedo code:

for x = 33 to 264
print read data
next x

DATA 33,34,35, etc.etc.etc., 50,13,51

sure C is faster, so is machine code...and btw, this would be faster if he had all the codes memorized and didn't need to read them. :-D  :-D  :-D
 

Offline weirdami

  • Hero Member
  • *****
  • Join Date: Jan 2003
  • Posts: 3776
    • Show only replies by weirdami
    • Http://Bindingpolymer.com
Re: AmigaBasic revisited
« Reply #8 on: February 18, 2003, 10:49:46 PM »
That LineLen thing is a waste of code. :-) Someone pointed out that it will always return without counting because y always starts out <25. I didn't catch that. :-(  

What I thought was that it's a waste of time to count to 25 if the loop does nothing but count to 25. Which, is what it will do if you remove the return if y<25. Why not just take out the y loop and just put in a y=y+1 and a if y=25 then y=0 and print this character. The loop does nothing for you.

What results are you getting with the way the code is now? I'm assuming you're either getting a 256 long listing 1 character wide or a 1 long listing 256 characters wide(if the carriage return doesn't work).

----
Binding Polymer: Keeping you together since 1892.
 

Offline melottTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2002
  • Posts: 989
    • Show only replies by melott
Re: AmigaBasic revisited
« Reply #9 on: February 19, 2003, 02:12:24 AM »
Thanks guys....
 I guess I just needed a little push in a different
 direction. This works...........

 Y=0
FOR X=0 to 255
PRINT CHR$(X) ;
Y=Y+1
IF Y=25 THEN PTINT CHR$(10) : Y=0
NEXT X

Mel Ott
 :-D
Stealth ONE  8-)
 

Offline Ilwrath

Re: AmigaBasic revisited
« Reply #10 on: February 19, 2003, 03:36:01 AM »
Quote

For x=0 to 255
Print chr$(x) ;
Gosub LineLen
Next x
end

LineLen:
for y=1 to 25
If y<25 then Return
If y=25 then Print chr$(13)
next y


Yikes!  This code isn't doing things you want it to do!

On the first iteration, you are entering the "For X" loop.  Then, you are doing a GOSUB, and entering a "For Y" loop.  This is all valid. You have a nested "For...Next loop".  What goes wrong is that you are then issuing a RETURN statement before your "Next Y" statement.  Essentially, if you remove the GOSUB here, you'll see the problem.

For x=0 to 255
Print chr$(x) ;
for y=1 to 25
If y<25 then Next x
If y=25 then Print chr$(13)
next y
end

It's not valid to nest loops in the style of
For X
For Y
Next X
Next Y

The reason being that you will initialize multiple instances of the For Y loop, without finishing them.  In your case, 255 For Y loops will be started.  This will blow the stack on your BASIC interpreter and either return an error, or cause a memory leak.  Even if by some miracle your BASIC interpreter has enough stack to get by this problem, you'll run into a "Next without For" condition on the Next X once the For X loop has run past 255.

The other methods previous posters have typed are much cleaner.  :-)
 

Offline Atheist

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 820
    • Show only replies by Atheist
Re: AmigaBasic revisited
« Reply #11 on: February 19, 2003, 10:13:15 AM »
Quote

melott wrote:
IF Y=25 THEN PTINT CHR$(10) : Y=0


Just use "print"
Chr$(10) was meant for printers to drop down a line.

Also Chr$(28 29 30 and 31)  one is move cursur up, one is down, one is left, one is right, without erasing the letter that is there.

Amiga!
\\"Which would you buy? The Crappy A1200, 15 years out of date... or the Mobile Phone that I have?\\" -- bloodline
So I guess that A500, 600, 1000, 2000, CDTV, CD32, are pure garbage then? Thanks for posting here.
 

Offline melottTopic starter

  • Hero Member
  • *****
  • Join Date: Dec 2002
  • Posts: 989
    • Show only replies by melott
Re: AmigaBasic revisited
« Reply #12 on: February 20, 2003, 03:42:49 PM »
Thanks ...
 
 I posted, up a reply or two, that I got it
 worked out. Yes the "LINELEN" thing wasn't
 the way to go. I'm a beginner and it takes
 time to learn.
 Yes I know that the first 32 or so characters
 don't print. It was only a test example to
 work out the code. What I was looking for
 is to get a specific number of chrs. reguardless
 what they are to print on a line then goto
 the next line.
 
 Mel Ott
   
Stealth ONE  8-)