Spectrum Machine Language For The Absolute Beginner

edited July 2008 in Sinclair Basic
Not quite sure if this should be in here but here goes.

Having never delved into machine code before I thought id have a go at this book and its quite easy to follow for a while, I got to the part where you have to type in the programs to continue anyway. I typed in the ezcode routine. Now ive checked, double checked, triple checked, done it all again and im pretty certain i got no errors in the basic program whatsoever yet when i enter a line or command into it i either get C nonscence in basic or 0 OK, 0:1. Can anyone confirm that this program actually works properly? Did you/anyone you know ever type it in and use it?
http://www.worldofspectrum.org/infoseekid.cgi?id=2000363

I saved a snapshot of the program after i typed it in too if anyone cares to check this http://www.geetechperformance.co.uk/index_files/ezcode.z80
In the listing in the book the font shows a triangle as a character, I have replaced this with an underscore seeing as the spectrum has no such character.

ZX-MAD
Post edited by ZX-MAD on

Comments

  • edited April 2008
    Hi ZX MAD,

    The little triangles represent a "space" character.
    The triangles have been used because whitespace in BASIC can be important but at the same time difficult to spot, particularly in a tokenised editor such as the ZX BASIC editor.

    The program is attempting to parse the string that you input (e.g. 1 210064) but because you have used underscores, it doesn't detect the "space" character that separates the line number (1) with the hex codes (210064).

    Change the underscores back to spaces on the following lines and the program will work:
    Line 1120: 7 spaces
    Line 2030: 4 spaces
    Line 2060: 1 space
    Line 2140: 1 space
    Line 2210: 2 spaces
    Line 2290: 2 spaces
    Line 2360: 2 spaces

    (Ideally, work through the whole program changing your underscores back to spaces)


    You've spelt "Command" wrong on line 2020! :-)
  • edited April 2008
    On another note, the montior program was written back in 1982.
    There are a number of great "assembler" programs written for the spectrum around which allow you to type your assembly code in directly, load, save it, and compile it.

    Other Wossers will tell you what they use.

    You can still work through the book but try using an assembler software instead to write the code as it is much more intuitive and easier as you don't have to reconsile all of your addresses.

    Alternatively, use Dunny's BASin program. It has a built in assembler.
    1) Install BASin from here
    2) Launch it from the start menu
    3) Click Tools --> Assembler
    4) Paste in the following
    org 32768
      ld b,255
      ld d, 10
    outerloop:
      ld a,16
      out (254),a
    
    ; Wait
      push bc
    loop1:
      djnz loop1
      pop bc
    
      ld a, 2
      out (254),a
    
    ; Wait
      push bc
    loop2:
      djnz loop2
      pop bc
      dec d
      jr nz, outerloop
      ld d, 10
      djnz outerloop
      ret
    
    5) Press CTRL + A to assemble the code (it will tell you that 28 bytes were compiled)
    6) Run the code by clicking in the main BASin window and typing:
    RANDOMIZE USR 32768
    
    for a cool sound effect.

    You can save the source code in a text editor and save the code using SAVE "sound" CODE 32768,28
  • edited April 2008
    Super, manic miner leg sound effects LOL thanks for the help, I had a feeling it was because of the triangles/spaces thing, thats why i mentioned it. It is working great now.
  • edited April 2008
    You're probably better off using SPin, it is the same assembler though.
    I wanna tell you a story 'bout a woman I know...
  • edited April 2008
    ZX-MAD wrote: »
    Super, manic miner leg sound effects LOL thanks for the help, I had a feeling it was because of the triangles/spaces thing, thats why i mentioned it. It is working great now.

    Glad you like it. Good to hear you got to grips with it.
    I should have said, it would be better to put an DI just after the org statement and an EI just after before the ret statement - for a smoother sound.
  • edited May 2008
    On a slightly related note, back in the good'ol'days, I bought the same book, bundled together with "Supercharge Your Spectrum" - there are some pretty nice routines in there, if (like me) you enjoy working in BASIC but want to add some more clever stuff.

    Cheers!
  • edited May 2008
    gcallard wrote: »
    On a slightly related note, back in the good'ol'days, I bought the same book, bundled together with "Supercharge Your Spectrum" - there are some pretty nice routines in there, if (like me) you enjoy working in BASIC but want to add some more clever stuff.

    Cheers!

    Yes, I like that book. That and An Expert Guide to the Spectrum
  • edited June 2008
    I've had a go at typing in this program myself and also tried downloading the one posted by ZXMAD, i seemed to have gone wrong somewhere both are giving me the same problem, the book says that when i enter the command "1 c9" it's supposed to be displayed on the screen which it does ok during the listing process but when i type 'Dump' it seems to change to 'A9' so when i run it it just crashes .. it seems too much of a coincidence that both me and ZXMAD both typed in the same error in exactly the same place but i guess it's not an impossibility, i'm thinking there's a typo or faint text somewhere .. i know there's loads of better assemblers out there and i'll use one of those if i can't get any joy with this one but i'm trying to go as much by the book as possible and i'd like to get this one working if possible
    suggestions welcome!
  • edited June 2008
    This is a great idea for a thread, following examples as laid out in a Speccy programming book. Could be done for other MC books as well. I'm gonna rake this one out and follow a few of the progs. Can never tire of reading Machine code books. :)
  • jpjp
    edited June 2008
    Glue wrote: »
    ...and also tried downloading the one posted by ZXMAD, i seemed to have gone wrong somewhere both are giving me the same problem...

    Unless ZXMAD has fixed his version and uploaded it, you may need to fix it as per BloodBaz's post
  • edited June 2008
    I love typing in listings written by other programmers and i was a huge fan of 'Sincalir Programs' in it's hey-day, i've still got a bundle of the magazines stashed away somewhere

    I think the trouble is Mr Tang has made it dificult to follow the basic programming in the listing for novices like me whose knowledge extends little beyond typing in LOAD"" but even i can tell there's a lot of what appears to be deliberately going around the houses, referring to the variables ZE ON TW TH and FR which could have just been replaced with 1, 2, 3 and 4.

    Digressing aside, i noticed that ZXMAD had posted that he had got his version working simply by replacing the underscores with spaces, when i typed in the listing myself i started using spaces after getting numerous 'variable not found' and 'nonsense in BASIC' messages

    Perhaps ZXMAD could post a link to a working EZCODE listing? i'd be really grateful :)
  • edited July 2008
    Tell you what Glue, you replace the underscores (2 Vars/C Nonsense and all), then we will address the runtime errors with you.

    Can't say fairer that that :-)

    We would all like to see you get this one working.
Sign In or Register to comment.