Project on ZX Spectrum in University

edited January 2013 in Announcements
Hi everyone,

I am Max, student of media studies in berlin, and I have to do a little project on the spectrum. I am working on a sinclair zx spectrum +2 in class and we are basicly learning basic BASIC programming in order to get to know the medium computer better... In the end of january we have to present the computer in class and explain the history, the differences to other retro computers, talk about communities, forums and present the best or most famous games...

maybe you can help me out a little, to make my presentation more exciting;)

So if you know some interesting stories, insiders and so on, maybe you can just write to me or post something here... There is a lot to say about the spectrum yet I think, but maybe there is something else, you can not find in the books, if you know what I am saying!

Thanks you and best regards,

Max
Post edited by lomax030 on

Comments

  • edited December 2012
    Hello and welcome to the WOS forum :)

    I am the author of Spectrumpedia, the most comprehensive book available at the moment about general knowledge of the Spectrum, which surely could help you in what you need. However, at present the book is only available in Italian, so if you don't understand that language it won't be of much use to you! In that case, send me a PM and I will gladly try to help you.
  • edited December 2012
    Maybe it would be even better if you asked all your doubts about the Spectrum here ;)
  • edited December 2012
    Hi, thank you for the quick reply. I will try to get together some stuff I have questions about. Sometimes it's just differences in the basic language, I have to work around, because many of the programs (which is really low level programming) do not work like presented in class... often the use of "(...)" like in chr$ (97) which is chr$ 97, but doesn't work if you do thinks like chr$ (97,5)+rnd(1) or so... if that even exists in BASIC but I think so;))

    I will write some examples these days...

    best,
    Max
  • edited December 2012
    As announced here are some questions, examples for differences in basic language. Maybe you can give me some answers, ways how to program these things on the zx spectrum.

    This is how it was shown in class:

    1. This was just to show how to work with arrays / vectors:

    dim a(10)
    let a(1)=7
    let a(2)=-3
    let a(3)=5

    FOR i=1 to 3: b=b+a(i): next

    print b

    instead of just adding: print a(1)+a(2)+a(3)

    2. get the value of a integer or string, I don't know what for but we did it;)
    a=val("hallo")
    a=val("15")

    this is written in the original manual (page 66) but doesnt work properly like:

    val$="hallo"

    3. the "functions" upper$, left$, mid$, right$, tl$ are not included in spectrum... any other ways?

    4. switch between radiant and degree (sin, cos and stuff). there should be things like DEG and RAD in Basic...

    5. finally, playing music, also something in the manual which didn't work on the machine:(

    10 Let a$="ux1000w0c&w1c&w2c&w3c&w4c&w5c&w6c&w7c"
    20 play a$

    I know things are simple, but it's not about programming it's about getting to know the machine.

    that's all for now. thanks for every input!!

    best,
    Max

    PS: I post this also in basic programming section here
  • edited December 2012
    lomax030 wrote: »
    1. This was just to show how to work with arrays / vectors:

    Your example needs just the NEXT changing to NEXT i - the Spectrum always needs the variable reference on the NEXT.
    2. (...) val$="hallo"

    I'm not really sure what you're trying to do here. The first two VAL lines you gave would work perfectly well on the Spectrum with the LET keyword added. The Spectrum always needs LET at the start of an assignment.
    3. the "functions" upper$, left$, mid$, right$, tl$ are not included in spectrum... any other ways?

    LEFT$, RIGHT$ and MID$ are replaced with a simpler system: a$(start TO end), where start and end are the character positions you want to extract. You can omit start and use a$(TO end), which works like LEFT$. Or you can omit end instead - a$(start TO) which does a similar job to RIGHT$, except the number you pass is the position of the first character you want to extract, rather than the number of characters as in RIGHT$. Oh yes, and a$(pos) extracts a single character at position pos.

    The Spectrum has no UPPER$ or LOWER$, so you'd have to write a routine using a FOR/NEXT loop, checking the ASCII value of each character (using CODE, the Spectrum's equivalent to ASC).
    4. switch between radiant and degree (sin, cos and stuff). there should be things like DEG and RAD in Basic...

    I can't remember if ZX Basic has these functions, but if not, you can easily work degrees out by dividing radians by PI and multiplying by 180. The Spectrum has a PI keyword.
    5. (...) 10 Let a$="ux1000w0c&w1c&w2c&w3c&w4c&w5c&w6c&w7c"
    20 play a$

    As it happens I was playing with this just yesterday and made the same mistake as you. The Cs need to be in upper case; I'm not sure about the other characters in the play string, but I put them in upper case as they are in the manual, just to be sure.
  • edited December 2012
    Some quick answers:

    2. VAL is a function which "turns" a text string into a numeric value, provided the string does not include letters. Therefore:

    PRINT VAL "15"

    returns 15.

    LET a$ = "15" : LET k = VAL a$ : PRINT k

    returns 15 as well.

    VAL$ instead treats a text variable like a string. Therefore:

    LET a$ = "HELLO": PRINT VAL$ "a$"
    returns HELLO.

    3. You must use (x TO y) if you want to choose the part of a string between characters x and y. (x TO) is roughly equivalent to RIGHT$ and (TO y) to LEFT$.

    5. C's in music strings might be lower case as well if they refer to the lower octave (see the diagram at page 11 of the 128 Spectrum introductory booklet).
  • edited December 2012
    snigfarp wrote: »


    As it happens I was playing with this just yesterday and made the same mistake as you. The Cs need to be in upper case; I'm not sure about the other characters in the play string, but I put them in upper case as they are in the manual, just to be sure.

    Yes, put all the letters inside the string upper case and it will work!
  • edited December 2012
    DaRkHoRaCe wrote: »
    Yes, put all the letters inside the string upper case and it will work!

    No. This will work in 128 BASIC:

    10 LET a$="4c"
    20 PLAY a$

    It's the same as writing:

    10 LET a$="O4N4C"
    20 PLAY a$

    because O5 is the default octave PLAY will consider when reading music strings.
  • edited December 2012
    VAL$ instead treats a text variable like a string. Therefore:

    LET a$ = "HELLO": PRINT VAL$ "a$"
    returns HELLO.

    VAL$ always puzzles me. I'm not sure if it's really necessary keyword. Anyway, a better example would be,

    10 LET a$="b$+c$"
    20 LET b$="Merge"
    30 LET c$="Me"
    40 PRINT VAL$ a$

    Outputs:
    (as val$'s behavior is similar to php, it recognizes variables in a string,)

    MergeMe

    I don't know where to use this kind of thing as using PRINT b$+c$ is way faster.
  • edited December 2012
    Arda wrote: »
    VAL$ ...
    I don't know where to use this kind of thing as using PRINT b$+c$ is way faster.

    I suppose it could be a clumsy replacement for PRINT USING found in other BASICs, or (s)printf in countless other languages, e.g.
    10 LET f$="(""0000""+STR$ f)(LEN (""0000""+STR$ f)-4 TO )"
    20 LET f=20
    30 PRINT VAL$ f$
    

    equivalent to something like:
    20 F=20
    30 PRINT USING "#####",F
    
    in some other BASICs, or
    printf ("%05d\n", f);
    

    in some other languages. I'm not sure you could include decimal places though, with ZX BASIC's lack of an INSTR type function.
  • edited December 2012
    Without VAL$ it would be impossible to write certain forms of recursive function. For example, this function PEEKs 'l' bytes from memory starting at 's' and returns them as a string:

    DEF FN j$(s,l)=CHR$ PEEK (s)+VAL$ (("FN j$("+STR$ (s+1)+","+STR$ (l-1)+")" and l>1)+("""""" AND l=1))

    I use it for extracting connections from a node in a network defined in an array with variable length rows (ie. tracing routes on a map). 's' is the node address and 'l' is the number of edges (connections to other nodes).

    Also, it's possible to make the RH-side variable names in a LET statement be themselves variable by using VAL$. Thus, if v$ holds the name of another variable, then:

    LET a$=VAL$ v$
    for a string, or:

    LET anumber=VAL VAL$ "v$"
    for a number, will assign the content of the variable named in v$. This can be used, for example, to write a routine for handling arrays with the same structure but different names.
  • edited December 2012
    snigfarp wrote: »
    LEFT$, RIGHT$ and MID$ are replaced with a simpler system: a$(start TO end), where start and end are the character positions you want to extract. You can omit start and use a$(TO end), which works like LEFT$. Or you can omit end instead - a$(start TO) which does a similar job to RIGHT$, except the number you pass is the position of the first character you want to extract, rather than the number of characters as in RIGHT$. Oh yes, and a$(pos) extracts a single character at position pos.

    Hi, the correct word for this string treatment is string slicing or array slicing since a string is nothing but a character array
    http://en.wikipedia.org/wiki/Array_slicing
    I just noticed that ZX Spectrum Basic is not mentioned on the wikipage
    {edit:which is corrected by now !!}

    Spectrum BASIC example
    10 LET a$="HelloWorld!"(5 TO 7)
    20 PRINT a$
    
    or eg
    10 LET a$="HelloWorld!"
    20 PRINT a$(5 TO 7);a$(11)
    
    my old website http://home.hccnet.nl/c.born/ has changed to http://www.cborn.nl/zxfiles/ so just click it and select a file
  • edited December 2012
    first of all, thank you for the many replies!!

    I will work myself through the thread, try things with the emulator (I am using fuse for mac) and then I will get at you again, if there are further questions;)

    Max
  • utzutz
    edited December 2012
    so I take it you are in Dr. H?ltgen's course? an excellent start into 8bit computing, i'd say. ;)
  • edited January 2013
    Happy New Year everyone! I worked myself through the stuff most of it worked, and do not have any new questions yet! but they will come for sure.

    best,
    Max

    PS: @utz yes I am;)
Sign In or Register to comment.