Go Down

Topic: Algorithm to rotate data (Read 2 times) previous topic - next topic

Krupski


It's been a while since I wrote any BASIC, so can you explain lines 70 and 80, please?


Sure.

[font=monospace]
-- CODE: ---------------------------------------------------------------------------------------------------
70 for c=1 to r step 8 // c is the first byte of 8 to read (index into one character worth of font data)
80   for b=0 to 7 // b is an index into the character data
90     get #1,c+b // read byte "offset + index"
100     fin(b)=asc(d$) // store byte in fin(x) (asc() returns the numeric value of the string byte)
110   next b // get next byte of char data block
120   gosub 160 // rotate one character
130 next c // do next character
------------------------------------------------------------------------------------------------------------
[/font]


BTW, the variable "r" in line 70 is the file size - i.e. it does "for 1 to 2048".

Oh and thanks for the reply. Thanks to all the replies, I've got it working. Thanks!

-- Roger
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

AWOL

I'm still confused why one loop starts at one, and the other starts at zero.
Surely the first block of data starts at (0 + 0) , not (1 + 0) ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johncc


I'm still confused why one loop starts at one, and the other starts at zero.
Surely the first block of data starts at (0 + 0) , not (1 + 0) ?


Basic uses 1-based arrays.  And he is simulating a 2d array so his lower-level index "b" is more sensibly zero-based...

John

AWOL

Quote
Basic uses 1-based arrays.

I know that
Code: [Select]
90     get #1,c+b // read byte "offset + index"
But that's not an array - it's file, isn't it?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Krupski


I'm still confused why one loop starts at one, and the other starts at zero.
Surely the first block of data starts at (0 + 0) , not (1 + 0) ?


In BASIC, the index of the first random record (i.e. byte) is 1, not 0. I know it looks strange, but that's how it works.

BTW, the BASIC I'm using is BAS 2.3 by Michael Haardt, compiled and running in 64 bit Linux. It's syntax identical to GWBASIC.

When I need to whip up a quick and dirty program, I usually use BASIC because it's interactive - I can write, run, debug, edit and re-run without doing the "editor / compiler / debugger / editor / complier  ...." dance.
Gentlemen may prefer Blondes, but Real Men prefer Redheads!

Go Up