Basic course for newbies

Página 5/11
1 | 2 | 3 | 4 | | 6 | 7 | 8 | 9 | 10

Por ericb59

Paragon (1071)

imagem de ericb59

23-12-2013, 15:04

OK.
I think I understand my error !

The bigger basic program I talked, is initiated with a CLEAR 400
It reserve the memory for the variables. But, perhaps it modify also the variables pointer in memory.

So If I want to reload an ARRAY saved with COPY in a program with CLEAR 400.
I must saved the array in the same conditions, so WITH a CLEAR 400 initialization.

So the easiest way to save and reload ARRAY DATA can be

10 CLEAR 400
20 DIM TB(10)
30 FOR I=1TO10:TB(I)=i:NEXT I 
40 COPY TB TO "a:TBARRAY.BIN"

Reload the ARRAY content

10 CLEAR 400
20 DIM OM(10)
30 COPY "TBARRAY.BIN" TO OM

Por Manuel

Ascended (18788)

imagem de Manuel

23-12-2013, 16:07

Sorry I have no experience with the COPY command and arrays. I don't think it's used often. (Which probably has a reason!)

Regarding getting the file names of a disk... that's a bit tricky. There's no real good basic-only way for that. Perhaps the most basic (but ugly!) way is to issue a files command and peek the output from the VRAM... I have a menu program that does exactly that.

Lots of stuff you say is possible. But you can't get screenshots form a ROM file. Unless you actually run the game, make a screendump while the game is running (if possible?) or copy the VRAM content after the game was running and put that into a file.

Just try to start with something and see where you get!

Por ericb59

Paragon (1071)

imagem de ericb59

23-12-2013, 17:00

what i'm talking about is a way to reduce memory cost of basic program.

for example, when making a game we often have to use static data.
the best way to store static data is the DATA command.
But, when we have to use those data, we have to read them, and put them in variables or array.
like this

10 DIM DT(10)
20 for i=1 to 10 : read a: DT(i)=a:next
30  (...) 
100 DATA 2,5,7,9,12,23,90,56,4,12

in this situation the DATA are twice in the memory
first in the DT array
second in the DATA command line

To save basic memory, I want to get out the data.
I build the array and save it in program

10 DIM DT(10)
20 for i=1 to 10 : read a: DT(i)=a:next
30  copy DT to "file.bin":end
100 DATA 2,5,7,9,12,23,90,56,4,12

Now I can have the array data in my game program without the data command
just with 1 line of code

10 dim DT(10):copy "file.bin" to D

Shocked!

Por edoz

Prophet (2441)

imagem de edoz

23-12-2013, 17:21

Manuel wrote:

Regarding getting the file names of a disk... that's a bit tricky. There's no real good basic-only way for that. Perhaps the most basic (but ugly!) way is to issue a files command and peek the output from the VRAM... I have a menu program that does exactly that.

Ok. It was a simple idea,Wink ..... If you have a sample how to Proceed in basic I appreciatie it.

Por Manuel

Ascended (18788)

imagem de Manuel

23-12-2013, 20:36

Do you know how VPEEK works and how the video RAM is organized in screen 0?

You can try a bit with VPOKE. E.g. just try VPOKE 0, 65 (or VPOKE 0, ASC("A") to avoid a magic number) in your basic screen and see what happens Smile Especially when you change the address from 0 to something else.

If you know that, it's easy. You run a FILES command. This command will print all filenames on the screen. As they're on the screen, they are in video RAM. And if you can read out the video RAM (using VPEEK), you can find out the file names. With the VPOKE command you learned which addresses are the right ones.

It's very clumsy, but it's probably the easiest way Smile (There is no way to let FILES give its output as an array, that's why workarounds like this are necessary. Alternatively you can query the disk manually for file names, but that's a lot more complicated than this.)

Por PingPong

Prophet (3889)

imagem de PingPong

23-12-2013, 20:47

DSKI$ functions can be used to read the FAT

Por edoz

Prophet (2441)

imagem de edoz

23-12-2013, 21:19

I see in my basic manual that you can read sectors with this function. But how can determinate witch files are on disk or hard disk partition ?

DSKI$ (,)

Por Manuel

Ascended (18788)

imagem de Manuel

23-12-2013, 21:37

As I said, it's a lot more complicated than using the FILES trick. You'll have to understand how the disk format is.

Por Poltergeist

Champion (278)

imagem de Poltergeist

23-12-2013, 21:48

On harddrives, I would not use dski$. On the diskmagazines I worked on, we used something like this (which, in fact, is the way Manuel described it)

10 dim a$(112) :x=0:y=0:screen 0:width 80:color 0,0,0:files "*.ldr":fi=0
20 b$="": for d=0 to 11:b$=b$+chr$(vpeek(x+y*80+d)):next d: if b$<>space$(12) then a$(fi)=b$:fi=fi+1:x=x+13:if x>72 then y=y+1:x=0:goto 80 else 80

We only had diskdrives in those days, so that's what we build on: No subdirs and a maximum of 112 files.
Line 10 creates an array of 113 items (we only needed 112, so that could be lowered to 111), we initialize x and y. go to screen 0, and set the width to 80 columns, so more files could fit on the screen. We set everything to black, give the files command, so all files would (in this case with the extension .ldr) were shown on screen (which you cannot see, as the screen is black, as is the tekst)

in Line 20, we empty b$, start a for next loop, and start vpeeking the videoram. As it is screen 0, the upper right corner can be accessed with vpeek(0). We then read 12 characters (filename, point, extension) and put these in the variable B$.

if B$ is not empty, we fill the array with the value of b$, move the x/y cursos to the next file, and go to line 20 again. If b$ is empy, nothing happens, and we go to the next line.

And this is how we could read files to an array, so we could display them on a graphical screen.

Por NYYRIKKI

Enlighted (5918)

imagem de NYYRIKKI

23-12-2013, 21:58

No, no no no nooo!!!

FILES trick depends on screen width MSX Disk BASIC version etc. : Very bad idea
DSKI$ depends on disk format, file system (FAT12/FAT16), masterboot record etc. : Very bad idea

Please use the standard functions! ie:

10 FM$="????????.???" 'File mask '?' means any character
20 DA$="0E11110E12C51100C10E1ACD7DF3C11180C0CD7DF332F8F7C9"
30 AD=&HC080:POKE AD,0'Drive: 0=Default, 1=A: 2=B: ... 8=H:
40 FOR I=1 TO 12:AD=AD-(I<>10):POKE AD,ASC(MID$(FM$,I,1)):NEXT I
50 FOR I=&HC08C TO &HC0C0:POKE I,0:NEXT I
60 FOR I=0 TO 25:POKE &HC000+I,VAL("&H"+MID$(DA$,I*2+1,2)):NEXT I
70 DEFUSR=&HC000:DEFUSR1=&HC003
80 IF USR(0)>0 THEN END
90 FOR I=1 TO 12:PRINTCHR$(PEEK(&HC100+I));
100 IF I=8 THEN PRINT".";
110 NEXT I:PRINT
120 IF USR1(0)=0 THEN 90
Página 5/11
1 | 2 | 3 | 4 | | 6 | 7 | 8 | 9 | 10