Learning Machine Code

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Hedge1970
Berk
Posts: 47
Joined: Mon Feb 18, 2019 2:41 pm

Learning Machine Code

Post by Hedge1970 » Wed Jan 15, 2020 11:13 am

Hi all, looking for some advice, sorry for the long post, I wanted to at least try and describe where I am at...

I started programming the spectrum a few years ago. My aim to produce a game. My initial foray in BASIC lead me to believe in order to get the game playable I would need to do it in machine code (I did actually do it in Basic and posted it here last year, but...) So I started reading up.

The aim was to do this on a real ZX Spectrum 48k.

Google lead me to a couple of books and BigJons Road Race game http://chuntey.arjunnair.in/?p=63

The books where Machine code for the Absolute Beginner by William Tang and Mastering Machine Code on your ZX Spectrum by Toni Baker. Then just lately I’ve watched Darryl Sloans Machine code tutorials https://www.youtube.com › playlistWeb resultsMachine code tutorials (Darryl Sloan) - YouTube

Of course I also read the advice here so what’s the question

1. is there a good Spectrum Based assembler and disassembler.

I have been trying to use Zeus but the problem is the wide variance of interpretation between all the above materials. Example

Roadrace needed tweaking to work in Zeus

Toni Bakers examples from say Page 79 to 80 I can’t get to work in Zeus

Darryl Sloans example on Tutorial 2 wont work on Zeus.

So I could use ZX Spin Emulator for Darryl and all good, or I could use the program Toni provides called HEXLD2 all good but I don’t want to start a lengthy project only to find it won’t run native.

I like the idea of Zeus and it’s Dissasembler. I find it easy to use and essentially a nice environment to work in but it’s no good if I can’t practice what I am learning.

My next move is to go the (one of) route suggested here Notepad++ and Pasmo and see if I can get the above examples all working through that route but running in the real ZX.

I am sure it’s obvious to people who understand M/code what to do but from a standing start you can only leverage the tools around you and for me that is primarily books. But spending hours trying to not only understand what is written but then trying to figure out how to change it so it works in Zeus is just not effective.

I do feel it’s all doable but I feel I need a solid dev environment to move forward, so any help or advice - even how to get Zeus working - is most gratefully received.
1 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1319
Joined: Mon Nov 13, 2017 3:16 pm

Re: Learning Machine Code

Post by Ast A. Moore » Wed Jan 15, 2020 12:13 pm

Forget about Spectrum-native assemblers for serious development work. They’re fun for nostalgic reasons, but if you want any serious work done, you’ll need a so-called cross-assembler (that is, an assembler that produces code of an architecture different from what it runs on).

I’m afraid I can’t recommend you a particular one—I’m not a Windows user—but it does help to have a Spectrum-centric assembler, rather than a generic Z80 one. I’m lucky to have discovered zasm (and to which I have contributed in a small way). I made a special syntax highlighter for it and worked closely with the developer to essentially turn it into a small IDE.

That said, I think a combination of Notepad and some flavor of cross-assembler is the general route you should take. You’ll find it easier to use something more sophisticated than Notepad for writing and organizing your code; I’m sure there are plenty of programming-specific text editors on Windows.

Now, while a good assembler, which can generate TAP or TZX files (of which you have complete control) is a great boon, a more essential tool is your monitor/debugger. For that you’ll need an emulator that has one. Fuse has a pretty decent debugger, but nothing beats SpecEmu’s, in my book.

Note that trimming raw sources to fit your particular assembler is always going to be something you’ll need to do. However, as you become more savvy, you’ll (a) need to copy someone else’s code less and less, and (b) learn to do it with relative ease.

Oh, and I personally use real hardware only for the final stages of program testing (aside from a few very specific cases). Not only is it cumbersome and time consuming, but it also puts unnecessary stress on the 30-year-old hardware. While no particular emulator is perfect, they generally do a pretty good job for 99 percent of testing purposes.
1 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

User avatar
1bvl109
Dizzy
Posts: 56
Joined: Tue Jun 04, 2019 8:00 pm

Re: Learning Machine Code

Post by 1bvl109 » Wed Jan 15, 2020 1:12 pm

I second every word you wrote, but can't help to be deeply impressed by the journey he embarked on. This is the way of the Real Programmer. I liked ASZMIC, but that was for the 81. https://media.oglaf.com/comic/feralchic.jpg
0 x
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken

Hedge1970
Berk
Posts: 47
Joined: Mon Feb 18, 2019 2:41 pm

Re: Learning Machine Code

Post by Hedge1970 » Wed Jan 15, 2020 1:16 pm

Thank you for the reply. Finding the right assembler and debugger is key, hopefully someone who is using one with success will pass by and post. It’s a shame nothing native seems worth while. Not sure about “serious” dev, of course in my dreams I would write the next Manic Miner or Elite, but in reality (if I am lucky) it will be closer to Snake :-)

FYI Notepad++ is a full on text editor created as freeware by Don Ho and used worldwide by developers. Not to be confused with Notepad in windows, which while useful (and my go to everyday tool) is very basic indeed.
0 x

User avatar
1bvl109
Dizzy
Posts: 56
Joined: Tue Jun 04, 2019 8:00 pm

Re: Learning Machine Code

Post by 1bvl109 » Wed Jan 15, 2020 2:05 pm

While browsing for something completely different i stumbled across this German emulator which seems to be a whole IDE. Assembler, BASIC-Compiler and what not. I've no idea, if the UI also talks English though. http://www.jens-mueller.org/jkcemu/assembler.html
0 x
"Truth would quickly cease to be stranger than fiction, once we got used to it." - H.L. Mencken

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1319
Joined: Mon Nov 13, 2017 3:16 pm

Re: Learning Machine Code

Post by Ast A. Moore » Wed Jan 15, 2020 2:22 pm

Hedge1970 wrote:
Wed Jan 15, 2020 1:16 pm
It’s a shame nothing native seems worth while. Not sure about “serious” dev, of course in my dreams I would write the next Manic Miner or Elite, but in reality (if I am lucky) it will be closer to Snake :-)
Well, the thing is virtually no commercial Spectrum software was written on the same machine it was run on. That would have been immensely impractical. True, people often used another Speccy or even a less powerful machine (such as the TRS-80) for writing code and assembling it, but most software houses used much more powerful development platforms.

I made this post on a similar topic elsewhere. It’s worth repeating it here just to demonstrate the difference in the two approaches:

Image
Hedge1970 wrote:
Wed Jan 15, 2020 1:16 pm
Notepad++ is a full on text editor created as freeware by Don Ho and used worldwide by developers.
Oh, I see. Well, then you’re half way there. Get yourself a decent Z80 assembler, and use your favorite emulator to test your games!

Don’t get too hung up on the actual examples in “learn to program” books (although, they can be useful). The key knowledge you must acquire is the understanding of how the Spectrum actually works. The assembly language itself is a pretty straighforward affair and doesn’t require much learning per se. Browse this and any other Spectrum forum, and don’t hesitate to ask questions, both general and very specific.
2 x
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.

Alone Coder
Berk
Posts: 19
Joined: Fri Jan 03, 2020 10:00 am

Re: Learning Machine Code

Post by Alone Coder » Wed Jan 15, 2020 3:24 pm

If you want a handy native ZX Spectrum assembler, there is ALASM. A lot of software is written in it.
It needs TR-DOS, but I heard of MB02 version.
1 x

Hedge1970
Berk
Posts: 47
Joined: Mon Feb 18, 2019 2:41 pm

Re: Learning Machine Code

Post by Hedge1970 » Thu Jan 16, 2020 6:02 pm

So I have gone with Pasmo as the cross assembler and Notepad++ as the text editor. I created a batch file that I can start from Notepad++ to run Pasmo, it takes two inputs, the file name I want and the file location - both of which are cut and pasted. I would like to help others who may stumble here but having only just set it all up and tested it I am not sure my way will be the most efficient... but here goes.

Pasmo can be downloaded here pasmo.speccy.org/
It is not the sort of program you install, rather it sits wherever you cut 'n' paste it. It uses the CMD or command line. You need to be in the same directory as Pasmo - As an example if Pasmo was just extracted to the C:\ drive - use the following

c:\Pasmo.exe --name programname --tabbas programname.asm programname.tap

Instructions are here
http://pasmo.speccy.org/pasmodoc.html

I am using tapbas as it adds a Basic loader to the code

Once the TAP is created I then load that into Spectrum and then Type RANDOMIZE USR 32768 (note 32768 is where you started writing to.)

I am using Notepad++ a very good text editor to create my programs, it comes with many language syntax definitions out of the box including assembly. It also has a handy RUN command to let you run an external program such as Pasmo. I created the following Batch file and simply start it from within Notepad++ off the top menu called "Run".

Code: Select all

@ECHO OFF
SET/P filename="Enter File Name: "
SET/P directory="Enter Directory of Source File: "
E:\personal\computer\ZXSpectrum48K\programing\pasmo-0.5.3\pasmo-0.5.3\pasmo.exe --name %filename% --tapbas %directory%\%filename%.asm %directory%\%filename%.tap 
MKDIR %directory%\TAP
MOVE %directory%\*.tap %directory%\TAP
pause
The file asks you for the source file name and the source file location then creates the TAP file in a Folder called TAP in the SourceFile location. Its much easier to do than it sounds as all you do is open explorer and follow the prompts and copy/paste return.

This solution has allowed me to run all the examples I have tried both from the books and also from Darryl Sloans Youtube videos.

Thanks for your help. I will get used to it a bit more then If you dont mind I am sure I will have some pretty low level but confusing questions :)
0 x

Joefish
Manic Miner
Posts: 667
Joined: Tue Nov 14, 2017 10:26 am

Re: Learning Machine Code

Post by Joefish » Thu Jan 16, 2020 6:46 pm

I use Crimson Editor for the same job.
You can define function keys to do command-line strings and so call PASMO on whatever file you're currently editing with a single keypress.

You can set another function key in Crimson Editor to launch an emulator like ZXSpin with a command-line parameter made from the current PATH\FILE name with .TAP added and it will launch the compiled .TAP file in the emulator.

If you've compiled with the --TAPBAS option then the .TAP should load, run and execute the machine code automatically when you load it into the emulator.
1 x

Hedge1970
Berk
Posts: 47
Joined: Mon Feb 18, 2019 2:41 pm

Re: Learning Machine Code

Post by Hedge1970 » Thu Jan 16, 2020 7:46 pm

I’ll grab a copy of that as well, thanks.
0 x

Post Reply