Basic course for newbies

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

Por NYYRIKKI

Enlighted (5939)

imagem de NYYRIKKI

27-12-2013, 10:45

@Vampier I still think your idea is very good, but you just picked up a very wrong way to implement it. WIKI or WWW-page would be the correct way. If you want to discuss about the idea or implementation then this is good place but forum topics are (and should be if you ask me) open for wider discussion around the topic (Learning BASIC in this case) and when discussion ends the topics disappear in to noise... And that is why I like your idea... I'm very sorry if I'm the one who spoiled your day.

Quote:

You can easily access files whose names you know already, both ascii and binary files are supported

Yes, but even then the file access feels like it is glued to top of BASIC. All kind of DSKI, DSKO$, GET, FIELD, RSET etc. commands & functions tend to work against the original way of doing things in BASIC. They just don't share the common logic that other commands do. This is why I think it is better to learn first the "BASIC way of doing things" and then these "exceptions" later.

Por edoz

Prophet (2443)

imagem de edoz

27-12-2013, 21:53

Hi, i did some change on NYYRIKKI read files code. And í want to post it here because i have a question about it.
If i save the file to disk on my MSX (as .bas file) and open it in notepad it looks a bit scrambled. How can i save it on my MSX so i can open it in notepad on windows ? Is there a way to save it with some basic ASCII option ?

Por NYYRIKKI

Enlighted (5939)

imagem de NYYRIKKI

27-12-2013, 22:05

Yes, you can save it as ASCII code by using ",A"-parameter ie:

SAVE "FILEDISP.TXT",A

Por Vampier

Prophet (2397)

imagem de Vampier

28-12-2013, 07:24

NYYRIKKI wrote:

@Vampier I still think your idea is very good, but you just picked up a very wrong way to implement it. WIKI or WWW-page would be the correct way. If you want to discuss about the idea or implementation then this is good place but forum topics are (and should be if you ask me) open for wider discussion around the topic (Learning BASIC in this case) and when discussion ends the topics disappear in to noise... And that is why I like your idea... I'm very sorry if I'm the one who spoiled your day.

Here is how I think... how can someone who never saw a basic program understand where to start... read through a bunch of wiki pages? Instead of that I chose to give a bunch of clear examples which aren't overly complicated and stick to the basics of basic. print/input/goto and if/then. From there I was going to expand and slowly introduce more and more constructs that are easy to understand and implement. Code optimization comes with experience (which you obviously have a lot and want to show this to the whole world)

I program for the fun of it and you seem to thrive on challenge. If I was 7 or 8 years again I would feel very intimidated by your one liners and I would have given up before even trying.

My next step would have been a quick introduction to the graphic screen and sprites in the chapter thereafter (binary explained) I had a whole plan written out. I'll probably will write a course on my homepage with youtube movies to demonstrate some examples.

Por edoz

Prophet (2443)

imagem de edoz

28-12-2013, 09:49

10 DIM FO$(1000)
20 DIM COUNTER
30 FM$="????????.???"
40 DA$="0E11110E12C51100C10E1ACD7DF3C11180C0CD7DF332F8F7C9"
50 AD=&HC080:POKE AD,0
60 FOR I=1 TO 12:AD=AD-(I<>10):POKE AD,ASC(MID$(FM$,I,1)):NEXT I
70 FOR I=&HC08C TO &HC0C0:POKE I,0:NEXT I
80 FOR I=0 TO 25:POKE &HC000+I,VAL("&H"+MID$(DA$,I*2+1,2)):NEXT I
90 DEFUSR=&HC000:DEFUSR1=&HC003
100 IF USR(0)>0 THEN END
110 FOR I=1 TO 12
120 FO$(COUNTER)=FO$(COUNTER) + CHR$(PEEK(&HC100+I))
130 IF I=8 THEN FO$(COUNTER)=FO$(COUNTER)+ "."
140 NEXT I
150 IF USR1(0)=0 THEN COUNTER = COUNTER +1: GOTO 110
151 SCREEN 0:WIDTH80:COLOR15,0,0:CLS
160 FOR I=0 TO COUNTER
170 LOCATE X,Y :PRINT FO$(I)
171 X=X+12:IF X>80 THEN Y=Y+1:X=0
180 NEXT I

Ok. I changed the code a bit. To get the filenames in an array. (So I can display them on the screen) The idea is to make a selectable file browser using the keyboard) I created 2 variables.
10 DIM FO$(1000), This array holds the files
20 DIM COUNTER, and this is the counter for the array.

110 FOR I=1 TO 12
120 FO$(COUNTER)=FO$(COUNTER) + CHR$(PEEK(&HC100+I))
130 IF I=8 THEN FO$(COUNTER)=FO$(COUNTER)+ "."
140 NEXT I

In this step, compared to the original code, I push the filename into the Variable array.

160 FOR I=0 TO COUNTER
170 LOCATE X,Y TongueRINT FO$(I)
171 X=X+13:IF X>80 THEN Y=Y+1:X=0
180 NEXT I

Now I read the variable again and display it on the screen on specific locations.

There are 2 things wrong. (maybe more Wink)
- First is that I want a blank space between the files, but that don't seem to work. that's the reason for 13 steps in X
- Second, if there more than 15 files I got an out of memory problem. Why ?

Por NYYRIKKI

Enlighted (5939)

imagem de NYYRIKKI

28-12-2013, 10:55

Vampier wrote:

Here is how I think... how can someone who never saw a basic program understand where to start... read through a bunch of wiki pages? Instead of that I chose to give a bunch of clear examples which aren't overly complicated and stick to the basics of basic.

Yes... I think that would work... I didn't mean that you would expand the existing wiki-pages, but how about if you would make a WIKI-page "How to get started with MSX-BASIC" and link that under topic "MSX-BASIC"? I think this way it would be much more easy to find than a random forum-topic. I think your examples are good and I'm not in anyway against them.

Quote:

Code optimization comes with experience

Yes, but it can be teached as well... If you teach people to do things in complicated way, then they will repeat the same over and over again without even thinking about it. I don't mean that you should start from the effective ways as that will make the examples too difficult, but don't leave the examples to just basics of basic. In the end (when it is the time) also explain how to do things better. This way people don't get used to "wrong implementations".

I say this just because I've seen tons of BASIC-programs that have hundreds of lines of code and only very little functionality.

Por NYYRIKKI

Enlighted (5939)

imagem de NYYRIKKI

28-12-2013, 10:56

edoz wrote:

20 DIM COUNTER, and this is the counter for the array.

Please note that MSX-BASIC understands only 2-letters of variable name... It is ok to use ie. COUNTER as variable name but it is good to know that later variable names ie. COOL, COOKIE and CO point to same variable. To avoid confusion and to save memory people usually use only 1 or 2 letters.

Quote:

There are 2 things wrong. (maybe more Wink)
- First is that I want a blank space between the files, but that don't seem to work. that's the reason for 13 steps in X

You are forgeting the "." that we insert in to the filename... Therefore try:
171 X=X+13:IF X>70 THEN Y=Y+1:X=0

Quote:

- Second, if there more than 15 files I got an out of memory problem. Why ?

By default MSX-BASIC reserves only ridiculously small space (200 bytes) for storing all the strings. Try inserting:
5 CLEAR 2000

... this will make the string space 10-times bigger.

Por edoz

Prophet (2443)

imagem de edoz

28-12-2013, 21:56


10 CLEAR 2000
20 DIM FO$(1000)
30 FM$="????????.???"
40 DA$="0E11110E12C51100C10E1ACD7DF3C11180C0CD7DF332F8F7C9"
50 AD=&HC080:POKE AD,0
60 FOR I=1 TO 12:AD=AD-(I<>10):POKE AD,ASC(MID$(FM$,I,1)):NEXT I
70 FOR I=&HC08C TO &HC0C0:POKE I,0:NEXT I
80 FOR I=0 TO 25:POKE &HC000+I,VAL("&H"+MID$(DA$,I*2+1,2)):NEXT I
90 DEFUSR=&HC000:DEFUSR1=&HC003
100 IF USR(0)>0 THEN END
110 FOR I=1 TO 12
120 FO$(COUNTER)=FO$(COUNTER) + CHR$(PEEK(&HC100+I))
130 IF I=8 THEN FO$(COUNTER)=FO$(COUNTER)+ "."
140 NEXT I
150 IF USR1(0)=0 THEN COUNTER = COUNTER +1: GOTO 110
160 SCREEN 0:WIDTH80:COLOR15,0,0:CLS
170 FOR I=0 TO COUNTER
180 LOCATE X,Y :PRINT FO$(I)
190 X=X+13:IF X>70 THEN Y=Y+1:X=0
200 NEXT I
210 DIM ST:DIM SX:DIM SY:SX=12:DIM AX:DIM AY:AX=12
211 LOCATE SX,SY : PRINT "<"
220 ST = STICK(0)
230 IF ST=0 THEN 220
231 LOCATE AX,AY : PRINT " "
240 IF ST=1 THEN SY=SY-1:IF SY=<0 THEN SY=0
250 IF ST=5 THEN SY=SY+1:IF SY=>Y THEN SY=Y
260 IF ST=7 THEN SX=SX-13:IF SX=<12THEN SX=12
270 IF ST=3 THEN SX=SX+13:IF SX=>77 THEN SX=77
280 AX=SX:AY=SY:LOCATE SX,SY : PRINT "<"
290 FOR I=1 TO 100:NEXT I
310 GOTO 220


Ok, I added the 'selector' to choose a filename. I used the < to point to the file. It is working, and maybe I can add two arrows like this >FILENAME.EXT< But, maybe better/ more beautiful to highlight the filename it self when selected. But is this possible in basic ? Line 290 is to delay it a bit because it was to fast.. (maybe because I used a turbo-r)

Por Manuel

Ascended (18864)

imagem de Manuel

28-12-2013, 22:23

How do you want to highlight the filename? The problem is that in standard text modes you can't do much in plain basic. But with direct VDP programming it's possible to add 2 extra colors to screen 0. It's way out of league for a basic beginner's course though.

If you want to make a delay, it's better not to use a for loop, because that one is executed faster on a turboR than on a Z80. A better option is to use the TIME function. E.g. if you want to wait 1/10 second on a 50Hz machine you can do:

285 TIME=0
290 IF TIME < 5 THEN GOTO 290

You can set TIME to any value and what happens is that it will increase every 1/50th or 1/60th of a second, depending whether your MSX is running in 50 or 60Hz mode.
So the disadvantage is: you're still depending on the 50/60 Hz mode. But you can check that mode by reading out bit 1 of VDP(10). You're on 50Hz if VDP(10) AND 2 = 2 and on 60Hz if it results in 0.

With this you can improve some things further, have fun! Smile

Por Poltergeist

Champion (278)

imagem de Poltergeist

28-12-2013, 22:56

@manuel: you can ofcourse sacrifice the upper half of the msx characterset to create an inverse characterset. This can be done with simple vpeek/vpoke commands and some logical operators (xor comes in mind). Should not be to difficult to start with.. All you need to know is where the characterset is stored, and if I'm not mistaken, this address could be retrieved with BASE(2) (I'm not wrong, see http://www.msx.org/wiki/BASE)

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