This video did not exist back then. However, I am the best. So there is no need to worry. All in due time, my friend. Learn patience, and your key to success will lie within.
Oh, what a joy. Thanks for reviving these childhood memories of my school holidays in the '80-s, converting mnemonics to op-code with pencil and paper.
Exactly this! Not on a ZX, I had a single board computer called a TEC1 by an Australian company called Talking Electronics. I went mad with it, making expansions, and hand assembling code to punch in opcodes on a 4x4 keypad.
This is a hugely valuable resource! Modern processors are far too sophisticated to trivially jump into for beginners, so something like the Zilog Z80 is just the right balance of sophistication and approachability. Having a full series on this processor is something Im exceptionally keen on as i am looking to write my own Z80 emulator. Thank you so much!
There are 2 things that made the Z80 the 8080 killer. The fact that it only needed +5v instead of +5v, +12V, and -5V was absolutely huge, as well as the fact that it only needed a simple oscillator for the clock as well. The 8080 required a weird 2 phase clock that was beyond bizarre.
@@klave8511 that isn't quite accurate. While it did allow a single +5v power supply to be used, and a single phase oscillator to be used as well, it's touting of being 100% binary compatible was false. There were originally undocumented changes to flags that complicated code to support both processors. Plus, it had none of the additional functionality of the Z80, which eclipsed all use of the 8080 and 8085 combined. I will say that the 8032 line of microcontrollers was nice, but that was a completely different market, which the 8085 sort of entered.
I have a vintage computer that uses the Intel 8085 - the Tandy TRS-80 Model 200. It's really a powerhouse of a portable computer with productivity programs that can be quickly sommoned from ROM - like the Multiplan spreadsheet. Probably safe to say that this line of portables from Tandy (Model 100 and follow-ons) were the most successful 8085 computers
I never programmed in assembly on a Spectrum but I have on a PC and just passed a course on it. I came across this video due to interests in the Spectrum's programming languages when code appears on screen after crashing a game.
I cut my teeth on a ZX80 kit which was a lot of effort but the damned thing was too limited to do anything of consequence, the ZX81 improved things but the Spectrum took it all to a new level and because it was built upon the 80 and 81's core, was a breeze to migrate too. Another contender also entered the fray at this time, that of CP/M much favoured by the Amstrad machines and became cohabitable on the Spectrum 3's where many Amstrad games could work natively on Spectrum 3's and I used to create personalised Locoscript installs for companies which was a nice bit of extra money using CP/M. I used to have big notepads for setting up a programme, create its flowchart, break the flowchart down into modules then work on each module once I had set up the framework, I was working in a bank in the 90's and I sat there one lunchtime and knocked them up a far better database with decent sockets to talk with other bank systems, the programme was actually tiny and super robust and they stopped using it in early 2000's so it lasted pretty well, of course me being green around the gills I got a cheque for £500 for doing that but £500 in the eighties was not to be sniffed at and like any young lad I blew it on beer, parties and young ladies hehe I spotted this vid as I used to be pretty good at all of this but have lost my way the last 20 odd years, would love to relearn it all and all thru this vid I was thinking "Oh yes, that's how it went" lol
The Latin and Classical Studies teacher at our school was a computer hobbyist. He gave me his copy of Picturesque Editor/Assembler/Monitor/Debugger and said "See if you can work out how to use it, I have no idea". It took me another year or so but I eventually worked it out with a little help from a friend :D I wrote a couple of little games for the Spectrum in Z80 but never fully finished for release. I've still got the tapes but don't think they'll work after all these years. I'd have to guess at the org address to run it and the source was created using Laser Genius Assembler Suite.
I'll be following this - I'm 54 and cut my teeth on creating assembly code and hardware design for various different 4- and 8-bit processors. The first machine I programmed was an 8085 in hex - I remember cheating and using absolute addressing rather than relative addressing to make life easier. Assemblers make life so much easier. Good luck with the series! :)
Oooh that‘s so great! The Spectrum was my first computer and I loved to code in assembler (also later in M68000 assembler for the QL). Watching this video is like travelling back in time and all the memories coming back. Thank you!
Bravo!! Loved every minute of this. Early micro computers, assembly language, emulators, Mac’s and even Atom. Wow. It does not get much better than that. I wrote tons of z80 code back in the day. I even wrote most of my code and compiled it on the mainframe z80 cross assembler. ah, the days of single threaded programming. A simpler time.
My first computer was a ZX81 with 1K of memory. And although I wanted to program the Z80 in Assembler, and asked my dad for the book "Programming the Z80" for Christmas, but never got round to actually doing it. Great to see something for the Z80, I've been following Ben Eater's 6502 projects, but it's not the same.
You've made this video sound like child's play! Thank you. Z80 was always my best processor along with 6502 thank you, you made it easier to understand...better than some lecturers 😊
Thanks for this series. I had a spectrum as a kid and just wasn’t smart enough to understand assembly. Now I’m a LOT older it’s fun to look back now I’m a BIT wiser. The Z80 is such a manageable cpu to understand.
OMG finally somebody doing everything on Linux! Thank you so much. I was so tired of emulating programs under wine to follow along with other tutorials.
Good video. I have been interested in learning assembly for a while and as I still have my original spectrum +3 this series seems like a good place to start.
I know that feeling! I've wanted to write a C64 game for so long. I'm working through Matt's X16 series and, so far, I'm hanging in there! Hope you get to realise that dream!
I consider it respectful to pronounce the Z in Z-80 and ZX as "zed" when talking about British computers and "zee" when talking about American computers, at least in public (-:
Most native English speakers in the world are American. So let's use the American way. I'm sure most non Americans like me don't care much either way anyway.
@@StarsManny that’s completely not true. If you add up Indian, Nigerians, British, Irish, Australian, New Zealand, South Africa, Germans then it’s far more than America and they all use real English, not American English. See Wikipedia article entitled “List of countries by English-speaking population”
neat! for following episodes, could we expect an explanation of the ZX48 memory map, how did develop in asm back in the 80's, and what made the ZX48 a unique platform (ROM, graphics, sound and input subsystems, etc), different from other Z80 based microcomputers?
Awesome introduction! I wish I'd had this kind of resource back in the day (although that maybe would have killed some of the joy of discover things on my own, but anyway).
7:32 - "(absolute), C" is an invalid LD operand combination on the Z80. 13:27 - There are instructions that load an immediate to the memory byte pointed to by HL, IX+offset, and IY+offset, but not by a 16-bit absolute address. You can make the code clobber HL instead of A as a result.
Good catch with the LD (xx),C. I'm not sure how I missed that! And yeah, you could use (hl), too, but I didn't want to get into indirect addressing in the first example
Awesome. Used to have a Speccy in the late 80's. Would be nice to reminisce and finally write assembly instead of basic. 10 Print 'ME' . 20 GOTO 10 ... lol
Just good enough, just cheap enough, just simple enough, and with a huge number of people who know how to work with them gave this thing a very long life in embedded applications after the 8 bit PC era faded. It's still being made! And being used for so long every tiny edge case has been figured out making its behavior incredibly predictable, which is crucial in a lot of embedded applications.
I won't be getting into the hardware specifics of those platforms in this series, but I hope it provides a good basis for understanding Z80 assembly, which you can then apply to systems besides the ZX Spectrum. Just be aware that the Game Boy CPU only has a subset of the Z80 instructions
Interesting video, and a commendable effort to teach the basics of Z80 assembly to the masses. However, I have some reservations. I find the exclusive use of the hexadecimal system in a tutorial aimed at absolute beginners a questionable choice, more so if it is proposed without explaining anything about it. Also, ZesarUX is far too complex to use for a beginner: Spectaculator and SpecEmu would have been better choices in my opinion. Not that I am a Z80 Assembly expert - far from it - but if I had your experience and knowledge, I would have chosen a more "for dummies" approach, delving into details that I could genuinely believe not to need any explanation.
16:36 AFAIK, $ sign means current compilation address in most assembly languages. And hexadecimal form is written as ####H, started with decimal number, so you have to prefix it with zero sometimes to obey the rule.
No, it just means hex. Each assembler has different notation, but $ is very common for hex. Some assemblers allow multiple notation, including prepending # or postpending H
@@slithymatt, M80 and GEN80 support H-suffixed and do not support $-prefixed hex notation, even Zeus does not. All three use $ as the current compliation address. I did not tell $ is not supported at all for this purpose, simply uncommon. Is common for Pascal though.
The alternate registers are moderately useful. If zilog had added a means to find out which set is active, that would have increased their usefulness...
If I remember the IX and IY registers could be addresses as 8 bit registers IX.L and IX.H my old assembler had this functionality. Not sure if it was common practice though. I did a lot with screen drawing on the specky. Most people used LDIR which would cause a screen flicker but it was faster to call LDI in a block 1024 blocks as the LDIR took 24 T states and the LDI 8 ( memory falling here). I think the fastest way was to move the SP to the top of screen memory and push the screen byte. Had a lot of fun with the z80 and 68000
Yes, you can address ixh and ixl in the same ways you can h and l, for the most part. There are a few exceptions where you can't substitute index register halves, when h or l is one operand, but (hl) is the other. For example: ld (hl),h is valid, but you can't do ld (hl),ixh. What you can do is ld(ix+x),h, but again not ld(ix+x),ixh.
@Gruntos "I think the fastest way was to move the SP to the top of screen memory and push the screen byte." - Yes, I do recall hearing about that technique - fairly recently, as a matter of fact. But I haven't quite figured it out yet, to be honest... I do understand (to some extent) why this would be an attractive approach, though: i.e. using 16-bit transfers per opcode (rather than 8-bit ones), as well as the address decrement/increment being handled automatically. However, I keep seeing the fact that the stack is implemented 'upside-down' for the Z80 as a serious (potential) impediment to achieving high performance for this technique, in certain applications... (P.S. I can explain more thoroughly what I actually mean by all of that, however I would risk turning this post into an interminable essay - and I would rather NOT go that way... At least, not unless someone else here first manifests further interest in hearing more about my musings on the matter...)
Back in the day, I dreamt of creating a program (game) such a Manic Miner, or Jet Set Willy... just like my hero Matthew Smith. It all seemed far too complicated though - indeed, almost magical - and I had no idea where to start. Now that I'm in my 50s, I'd really like to give it a proper go. Would this be a good series to get me off and running, or at least walking? Does anyone have any other recommendations? Bear in mind, when it comes to any kind of coding at all, I am a *complete* beginner! Cheers!
I would first recommend learning some basic programming first. Not literally BASIC per se, but something like Python just to get your feet wet before getting into assembly.
@@slithymatt 24K for sure. I just love the application to the Spectrum ecosystem. Even your narration is on point :-) Where were you in 1983 when I got my ZX81?
There are many reasons, but mostly when you are dealing with extremely tight constraints, like on a low-RAM system with a slow CPU and no operating system (which is pretty much all 8-bit home computers and game consoles), the code generated by C will be too bulky and inefficient. C was invented for Unix and systems capable of running it.
@@cyberp0et I used to program in basic a long time ago and ill probably tinker with it a little when I get around to it. I like to code in language like rust and probably c is the closest thing to that that u can code with on this machine.
It's difficult to imagine how constrained the Spectrum and other machines of the time were unless you've used them. The ancient (2010) PC I'm running a Spectrum emulator on to follow these tutorials has a quad-core Intel CPU running at 2.66Ghz and 4G of memory; that's around 750 times the CPU clock speed and over 85000 times the memory of my original Spectrum 48K.
This is an excellent level of explanation. Even to a veteran programmer in different languages. My question is: will this code work for MSX computers? I am interested in writing programs for the MSX, but could not find enough information and videos for it, since it was not very popular in the USA
the video ram and other memory layout of MSX is very likely completely different (I don't know how MSX has it), so the code itself will still work the same, write value $D6 into memory at address $5800, but the MSX computer will not create blinking square on screen. (what will happen on MSX depends what is in that area of memory, probably nothing of significance/direct response). Also the output format SNA is ZX snapshot, so you will need to figure out how to produce binary which can be loaded by MSX emulator (or real MSX computer), AFAIK games for MSX are often produced as ROM-cartridge images, I know one huge MSX project does use sjasmplus for it, but it builds the whole file byte by byte manually, ie. any required "headers" of ROM cartridge and special values like checksum are part of the source code, and the source output is captured "as is" as raw stream of bytes (OUTPUT -> OUTEND directives of sjasmplus, or --raw command line option). in other words, it makes some sense to follow ZX tutorials (the Z80 assembly is still Z80 assembly, but [only] the machine-specific parts differ), and you can also use tools presented here, but you need to find some "glue" tutorial dedicated to MSX which will fill you on those machine-specific details, what's the memory layout of MSX, how to use it's HW features like graphics, sound, sprites, etc.... There's excellent web dedicated to MSX at msx dot org, where you can find also wiki with tips for programmers, and probably also some links to other tutorials or example projects and HW info. If you are completely new to assembly, and you really want to do MSX, it may make sense to start rather with MSX tutorials, and scavenge the ZX assembly tutorials a bit later, when you can somewhat tell which parts are machine specific features, and pick up the Z80 assembly tricks which do apply also for MSX.
Since even when writing for the speccy you'll probably want to have some kind of hardware reference in hand, writing for the msx shouldn't be much different - you just need a different reference =)
Also be aware that this assembler does not use the original Z80 syntax. The “$” (dollar sign) used by this assembler is not a part of the Z80 assembly syntax. Also, by default, all numbers in Z80 assembly are considered to be hexadecimal, not decimal. There are other differences as well, but you get the jist.. If you are using a different assembler, you might need to tweak the assembly in order for it to work for you.
The basic information about how the instructions work is the same. However MSX is totally different to the Spectrum. Anything to do with writing to screen, reading the keyboard, etc will be completely different. The MSX did not have an area of screen memory in the main 64K. It used dedicated VRAM accessed by a visual display processor chip (a Texas Instruments one for earlier MSX machines). The process for writing (and reading) the MSX VRAM (and VDP) require a few techniques Matt hasn't talked about. Basically using OUT and IN instructions (and also DI / EI to disable / enable interrupts). There were probably also MSX bios routines to do some of that too (just as we saw in the Hello World example program).
Atom has been discontinued and the Z80 language package for syntax is not available any more. Can anyone recommend an alternative editor for this tutorial?
The MEMOTECH MTX512 can combine Assembly and BASIC together I.E. ASSEM 10 10 CODE &H4000 LD HL,&H20 &H4004 LD BC,AH32 &H4008 ADD BC,HL &H400C LD (HL),BC &H4010 RET 20 REM End of assembly. the MTX512 also has a proper keyboard which makes coding easier. What about storing you assembly language in the REM statements and do CALL RAND USER(16384) or you can do like in this example goto 10.
@@slithymatt if a special piece of hardware plugged into the back of the computer you can load and run SINCLAIR Spectrum games for both the 48K and 64K machines and it just happens that you can get the MEMOTECM HDX512 (Hard drive) or the MEMOTECH FDX512 (Dual floppy drive) and can run CPM/80.
Are you sure the MTX512's assembler supports "ADD BC, HL" and "LD (HL), BC" as pseudo-instructions? The Z80 has neither. I'm gonna guess you reversed the operand order for those. The latter can be done via: LD C, (HL) ; Load low byte INC HL ; Advance to high byte LD B, (HL) ; Load high byte DEC HL ; Go back (may not be needed) Once again, I know nothing about the BASIC used by that machine.
Speccy is an affectionate name often used in magazines back in the day but it kind of makes my skin crawl when it’s used too often or in inappropriate places. For me at least, I prefer just hearing the regular name of Spectrum. It’s kind of similar to if you kept saying Bro all the time, you could but in general you likely wouldn’t. No hate, just my opinion.
Thank you for that video! I have a ZX Spectrum since the 80ies, and programmed video games in assembler. I really would like to turn this thing on again, but there are two impediments: I have no old fashioned TV as a monitor, and I have no cassette drive, not to speak of the cassettes with the assembler and so on. Any clue, how to fix this?
Any TV with an analog PAL tuner should work, assuming you have a PAL unit. Most modern TVs still support analog RF video, but it may be stretched out on the screen. As for a tape deck, you can use anything that can play a sound through a headphone jack. You just need a dubbing cable, with a 3.5mm plug on both ends. Then you can just play the sound file through the cable.
There is a simple mod to bypass the TV modulator and give a composite video output. As for storage there are several modern alternatives to tape. Some use SD cards to copy file images from your PC to the SD interface that plugs into the Spectrum.
takes me back not codedd any z80 since the 1990s, I dont think i done any assembly on spectrums mostly Amstrad CPC when i developed a text editor and some small projects on the PCW systems but mostly coding on low power stand alone chips systems hardware like controllers, io ect .. serial devices with Z80 logic.. but mostly other CP/M based systems .. mad really that Digital Research could have been instead of Microsoft .. Gary Kildall could have been instead of Bill Gates
"bro i cant pass this level on this game can you do something?" ok looking for DEC (HL) on the code , remove it and there you go infinity lives...oh the memories lol
IMHO it's a bit better to end these early snapshot examples with `jr $` (infinite loop of self-jump). (and leave the "ret to basic" for later, when you will deal also with loader/sysvars/etc) It's also nice reminder for asm beginners, that the CPU doesn't stop where the source does, and keeps executing whatever it finds in memory further down, unless it is explicitly prevented.
If you’d have posted these videos earlier I could of learnt assembly coding from you and would of been a hero in my High School and maybe Bill Gates instead of a geek who became an accountant. Thanks. 35 years too late. Try harder next time! 🤣
Inspired, I've now got a tiny blue stick-person rotating in a character cell... with a pause subroutine to slow it down enough to see it. I'd make it move around the screen but sprites on a spectrum memory map are beyond my brain for today :) I mean, it's easy-ish to move "sprites" sideways on a speccy screen, it's just the moving up and down that gets tricky :) As a child I had a language extension tape _"Fifth"_ (I'd link to it, but a product name like that wasn't built for legacy searching an internet :) , which was a library of sprite routines and such, and wasn't a derivative of Forth, despite its obvious pun. I recall it being quite nice - hacking around with its demos, but I think at the time I hadn't tuned into the delights of such things, or what I was doing. edit: found a reference, if anyone remembers this: worldofspectrum.org/archive/software/utilities/fifth-crl-group-plc ... I cite this, since when a 12yr old, I remember I found it fascinating, and looking back at the manual on this link, I can see why... but I can also see why it went over my head at the time :)
@@slithymatt I believe so, aye... I can't recall why I bought it back then, but I imagine I read an advert in _Your Spectrum_ magazine saying "WRITE YOUR OWN GAMES, MAKE ££££", sent off naively, opened the box and realised I was lacking various other parts, namely those in my brain :)
Wish I'd seen this vid in 1983. Better late than never.
This video did not exist back then. However, I am the best. So there is no need to worry. All in due time, my friend. Learn patience, and your key to success will lie within.
This playlist comes to the rescue. It's like seeing an old book of photographs of a dearest friend in a moment like this.
Farewell, Z80.
Oh, what a joy. Thanks for reviving these childhood memories of my school holidays in the '80-s, converting mnemonics to op-code with pencil and paper.
Exactly this! Not on a ZX, I had a single board computer called a TEC1 by an Australian company called Talking Electronics. I went mad with it, making expansions, and hand assembling code to punch in opcodes on a 4x4 keypad.
@@michaelclift6849 that is hard core! Wish I had a hex keypad today.
Exactly what I had to do until I saved enough to buy an Assembler :)
This is a hugely valuable resource! Modern processors are far too sophisticated to trivially jump into for beginners, so something like the Zilog Z80 is just the right balance of sophistication and approachability. Having a full series on this processor is something Im exceptionally keen on as i am looking to write my own Z80 emulator. Thank you so much!
There are 2 things that made the Z80 the 8080 killer. The fact that it only needed +5v instead of +5v, +12V, and -5V was absolutely huge, as well as the fact that it only needed a simple oscillator for the clock as well. The 8080 required a weird 2 phase clock that was beyond bizarre.
The 8085 sorted all that out in 1976.
@@klave8511 that isn't quite accurate. While it did allow a single +5v power supply to be used, and a single phase oscillator to be used as well, it's touting of being 100% binary compatible was false. There were originally undocumented changes to flags that complicated code to support both processors. Plus, it had none of the additional functionality of the Z80, which eclipsed all use of the 8080 and 8085 combined. I will say that the 8032 line of microcontrollers was nice, but that was a completely different market, which the 8085 sort of entered.
I have a vintage computer that uses the Intel 8085 - the Tandy TRS-80 Model 200. It's really a powerhouse of a portable computer with productivity programs that can be quickly sommoned from ROM - like the Multiplan spreadsheet. Probably safe to say that this line of portables from Tandy (Model 100 and follow-ons) were the most successful 8085 computers
Also the LDIR/OTIR type opcodes make a big difference. Thanks to those opcodes, the Z80 could do copy and search operations much faster than the 8080.
Reading books and saw this videos several times. Awesome ❤
Best memories.
I loved assembly programming on my Spectrum.
Dot Net on my PC is not as much fun.
Starting now to do assembly on the PC.
I never programmed in assembly on a Spectrum but I have on a PC and just passed a course on it. I came across this video due to interests in the Spectrum's programming languages when code appears on screen after crashing a game.
I cut my teeth on a ZX80 kit which was a lot of effort but the damned thing was too limited to do anything of consequence, the ZX81 improved things but the Spectrum took it all to a new level and because it was built upon the 80 and 81's core, was a breeze to migrate too. Another contender also entered the fray at this time, that of CP/M much favoured by the Amstrad machines and became cohabitable on the Spectrum 3's where many Amstrad games could work natively on Spectrum 3's and I used to create personalised Locoscript installs for companies which was a nice bit of extra money using CP/M. I used to have big notepads for setting up a programme, create its flowchart, break the flowchart down into modules then work on each module once I had set up the framework, I was working in a bank in the 90's and I sat there one lunchtime and knocked them up a far better database with decent sockets to talk with other bank systems, the programme was actually tiny and super robust and they stopped using it in early 2000's so it lasted pretty well, of course me being green around the gills I got a cheque for £500 for doing that but £500 in the eighties was not to be sniffed at and like any young lad I blew it on beer, parties and young ladies hehe I spotted this vid as I used to be pretty good at all of this but have lost my way the last 20 odd years, would love to relearn it all and all thru this vid I was thinking "Oh yes, that's how it went" lol
The Latin and Classical Studies teacher at our school was a computer hobbyist. He gave me his copy of Picturesque Editor/Assembler/Monitor/Debugger and said "See if you can work out how to use it, I have no idea". It took me another year or so but I eventually worked it out with a little help from a friend :D I wrote a couple of little games for the Spectrum in Z80 but never fully finished for release. I've still got the tapes but don't think they'll work after all these years. I'd have to guess at the org address to run it and the source was created using Laser Genius Assembler Suite.
this takes me back to Z80 assembly experiments on my ZX81... to go into assembly mode there we had to do smtg like
RAND USR
I'll be following this - I'm 54 and cut my teeth on creating assembly code and hardware design for various different 4- and 8-bit processors. The first machine I programmed was an 8085 in hex - I remember cheating and using absolute addressing rather than relative addressing to make life easier. Assemblers make life so much easier.
Good luck with the series! :)
Oooh that‘s so great! The Spectrum was my first computer and I loved to code in assembler (also later in M68000 assembler for the QL). Watching this video is like travelling back in time and all the memories coming back. Thank you!
Bravo!! Loved every minute of this. Early micro computers, assembly language, emulators, Mac’s and even Atom. Wow. It does not get much better than that. I wrote tons of z80 code back in the day. I even wrote most of my code and compiled it on the mainframe z80 cross assembler. ah, the days of single threaded programming. A simpler time.
Fantastic tutorial. As a C64 owner I always wondered about programming the Speccy. Looking forward to the next episode!
Great start - looking forward to the next one.
My first computer was a ZX81 with 1K of memory. And although I wanted to program the Z80 in Assembler, and asked my dad for the book "Programming the Z80" for Christmas, but never got round to actually doing it.
Great to see something for the Z80, I've been following Ben Eater's 6502 projects, but it's not the same.
You've made this video sound like child's play! Thank you. Z80 was always my best processor along with 6502 thank you, you made it easier to understand...better than some lecturers 😊
just getting into Z80 programming - nice primer :) looking forward to working through the series.
Thanks for this series. I had a spectrum as a kid and just wasn’t smart enough to understand assembly. Now I’m a LOT older it’s fun to look back now I’m a BIT wiser. The Z80 is such a manageable cpu to understand.
OMG finally somebody doing everything on Linux! Thank you so much. I was so tired of emulating programs under wine to follow along with other tutorials.
Clear explanation, nice and comprehensive infografics and pleasant narration! Thank you!
Very nice video! Clearly explained, good pace, good information density. Can't wait for the next one!
Good video. I have been interested in learning assembly for a while and as I still have my original spectrum +3 this series seems like a good place to start.
I feel 25 years younger watching this video. I did a 3ph PWM inverter project based on Z80 back then.
Thanks, it was informative
Nothing new for me, but well explained! But it makes me remember a lot of good times. Gives me a very good reason to visit your next presentation!
oooooh I'm so in! Subbed. Perhaps I will finally write a game after all these years? :D
I know that feeling! I've wanted to write a C64 game for so long. I'm working through Matt's X16 series and, so far, I'm hanging in there! Hope you get to realise that dream!
I consider it respectful to pronounce the Z in Z-80 and ZX as "zed" when talking about British computers and "zee" when talking about American computers, at least in public (-:
The trouble is that the Z80 is a yankee chip, so I guess it should be called the Zee 80, but Zed 80 sounds better
Most native English speakers in the world are American. So let's use the American way. I'm sure most non Americans like me don't care much either way anyway.
@@StarsManny that’s completely not true. If you add up Indian, Nigerians, British, Irish, Australian, New Zealand, South Africa, Germans then it’s far more than America and they all use real English, not American English.
See Wikipedia article entitled “List of countries by English-speaking population”
@@StarsManny The language is English, not American. In English it is pronounced "zed". Anything else is wrong in an English exam.
Some good points, one very bad point here. All of it respectful (maybe not mine 😂) but yes, it is Zed 😅
Great to see such a series begin!
Great little tutorial. Thoroughly enjoyed it!
Great channel...
I am traveling back in time 😁. Very nice! Thanks!
neat! for following episodes, could we expect an explanation of the ZX48 memory map, how did develop in asm back in the 80's, and what made the ZX48 a unique platform (ROM, graphics, sound and input subsystems, etc), different from other Z80 based microcomputers?
Memory layout: ua-cam.com/video/_J4ahkWtNYw/v-deo.html 😉🙂
Yes, we'll get into all of that
Brilliant, looking forward to the series.
Awesome introduction! I wish I'd had this kind of resource back in the day (although that maybe would have killed some of the joy of discover things on my own, but anyway).
7:32 - "(absolute), C" is an invalid LD operand combination on the Z80.
13:27 - There are instructions that load an immediate to the memory byte pointed to by HL, IX+offset, and IY+offset, but not by a 16-bit absolute address. You can make the code clobber HL instead of A as a result.
Good catch with the LD (xx),C. I'm not sure how I missed that! And yeah, you could use (hl), too, but I didn't want to get into indirect addressing in the first example
There's a Z80 knockoff I'm kind of obsessed with that has that LD...
UK game developers often worked on the Z80 Amstrad CPC when targeting the spectrum.
I could see that. Definitely a better system for development on.
gee this is wonderful info, i wished i had this when learning logic and the 8080, etc... thanks a lot...:)
Well done!
Awesome. Used to have a Speccy in the late 80's. Would be nice to reminisce and finally write assembly instead of basic. 10 Print 'ME' . 20 GOTO 10 ... lol
Just good enough, just cheap enough, just simple enough, and with a huge number of people who know how to work with them gave this thing a very long life in embedded applications after the 8 bit PC era faded. It's still being made! And being used for so long every tiny edge case has been figured out making its behavior incredibly predictable, which is crucial in a lot of embedded applications.
Oh yes. I'm really looking forward to this series. Specifically beca6ineant to make games for the Amstrad CPC and Gameboy.
I won't be getting into the hardware specifics of those platforms in this series, but I hope it provides a good basis for understanding Z80 assembly, which you can then apply to systems besides the ZX Spectrum. Just be aware that the Game Boy CPU only has a subset of the Z80 instructions
Great video. If I draw a box using Plot and Draw, how do I fill in the box with colour?
Having just programmed 8085 I can already see this is waaaay friendlier, despite being closely related...
6502 was fun ... I wrote code for the BBC model B.
Interesting video, and a commendable effort to teach the basics of Z80 assembly to the masses. However, I have some reservations. I find the exclusive use of the hexadecimal system in a tutorial aimed at absolute beginners a questionable choice, more so if it is proposed without explaining anything about it. Also, ZesarUX is far too complex to use for a beginner: Spectaculator and SpecEmu would have been better choices in my opinion. Not that I am a Z80 Assembly expert - far from it - but if I had your experience and knowledge, I would have chosen a more "for dummies" approach, delving into details that I could genuinely believe not to need any explanation.
Great video, thanks for posting!
16:36 AFAIK, $ sign means current compilation address in most assembly languages. And hexadecimal form is written as ####H, started with decimal number, so you have to prefix it with zero sometimes to obey the rule.
No, it just means hex. Each assembler has different notation, but $ is very common for hex. Some assemblers allow multiple notation, including prepending # or postpending H
@@slithymatt, M80 and GEN80 support H-suffixed and do not support $-prefixed hex notation, even Zeus does not. All three use $ as the current compliation address. I did not tell $ is not supported at all for this purpose, simply uncommon. Is common for Pascal though.
Thank you for making this!
The alternate registers are moderately useful. If zilog had added a means to find out which set is active, that would have increased their usefulness...
Indeed! Instead the alternate registers are always the ones not directly accessible. One of the unused status bits would be nice!
Fantastic !!!!!!!!
👍👍awesome series!
Would love to see this when I got my spectrum :) Any plans to make a series for the 68K?
I've definitely considered it. That was my first assembly language many years ago, and I still have my textbook. I would probably target the Amiga.
Very very very good !
Beautiful
so grateful. thank you!
Very awesome. Great tutorial.
Yep, just got sjasmplus up and running on my raspberry pi zero w. Your code worked just fine.
If I remember the IX and IY registers could be addresses as 8 bit registers IX.L and IX.H my old assembler had this functionality. Not sure if it was common practice though.
I did a lot with screen drawing on the specky. Most people used LDIR which would cause a screen flicker but it was faster to call LDI in a block 1024 blocks as the LDIR took 24 T states and the LDI 8 ( memory falling here).
I think the fastest way was to move the SP to the top of screen memory and push the screen byte.
Had a lot of fun with the z80 and 68000
Yes, you can address ixh and ixl in the same ways you can h and l, for the most part. There are a few exceptions where you can't substitute index register halves, when h or l is one operand, but (hl) is the other. For example: ld (hl),h is valid, but you can't do ld (hl),ixh. What you can do is ld(ix+x),h, but again not ld(ix+x),ixh.
@Gruntos "I think the fastest way was to move the SP to the top of screen memory and push the screen byte." - Yes, I do recall hearing about that technique - fairly recently, as a matter of fact. But I haven't quite figured it out yet, to be honest...
I do understand (to some extent) why this would be an attractive approach, though: i.e. using 16-bit transfers per opcode (rather than 8-bit ones), as well as the address decrement/increment being handled automatically. However, I keep seeing the fact that the stack is implemented 'upside-down' for the Z80 as a serious (potential) impediment to achieving high performance for this technique, in certain applications...
(P.S. I can explain more thoroughly what I actually mean by all of that, however I would risk turning this post into an interminable essay - and I would rather NOT go that way... At least, not unless someone else here first manifests further interest in hearing more about my musings on the matter...)
This was great, thank you!
Back in the day, I dreamt of creating a program (game) such a Manic Miner, or Jet Set Willy... just like my hero Matthew Smith. It all seemed far too complicated though - indeed, almost magical - and I had no idea where to start. Now that I'm in my 50s, I'd really like to give it a proper go. Would this be a good series to get me off and running, or at least walking? Does anyone have any other recommendations? Bear in mind, when it comes to any kind of coding at all, I am a *complete* beginner!
Cheers!
I would first recommend learning some basic programming first. Not literally BASIC per se, but something like Python just to get your feet wet before getting into assembly.
@@slithymatt Thanks!
I liked it. TY
Pure gold, man!
Thanks! I was shooting for at least 18K
@@slithymatt 24K for sure. I just love the application to the Spectrum ecosystem. Even your narration is on point :-) Where were you in 1983 when I got my ZX81?
@@donaldklopper learning how to code at school using Logo on an Apple II, naturally.
What a great video! Maybe a daft question but why would you use assembly if you can compile c to machine code.
There are many reasons, but mostly when you are dealing with extremely tight constraints, like on a low-RAM system with a slow CPU and no operating system (which is pretty much all 8-bit home computers and game consoles), the code generated by C will be too bulky and inefficient. C was invented for Unix and systems capable of running it.
Why not program in BASIC, since it comes with the system :)
@@cyberp0et I used to program in basic a long time ago and ill probably tinker with it a little when I get around to it. I like to code in language like rust and probably c is the closest thing to that that u can code with on this machine.
It's difficult to imagine how constrained the Spectrum and other machines of the time were unless you've used them. The ancient (2010) PC I'm running a Spectrum emulator on to follow these tutorials has a quad-core Intel CPU running at 2.66Ghz and 4G of memory; that's around 750 times the CPU clock speed and over 85000 times the memory of my original Spectrum 48K.
ZX Spectrum, best computer EVER 🤣
Is this possible to write in BBC BASIC SDL?
This is an excellent level of explanation. Even to a veteran programmer in different languages. My question is: will this code work for MSX computers?
I am interested in writing programs for the MSX, but could not find enough information and videos for it, since it was not very popular in the USA
the video ram and other memory layout of MSX is very likely completely different (I don't know how MSX has it), so the code itself will still work the same, write value $D6 into memory at address $5800, but the MSX computer will not create blinking square on screen. (what will happen on MSX depends what is in that area of memory, probably nothing of significance/direct response). Also the output format SNA is ZX snapshot, so you will need to figure out how to produce binary which can be loaded by MSX emulator (or real MSX computer), AFAIK games for MSX are often produced as ROM-cartridge images, I know one huge MSX project does use sjasmplus for it, but it builds the whole file byte by byte manually, ie. any required "headers" of ROM cartridge and special values like checksum are part of the source code, and the source output is captured "as is" as raw stream of bytes (OUTPUT -> OUTEND directives of sjasmplus, or --raw command line option).
in other words, it makes some sense to follow ZX tutorials (the Z80 assembly is still Z80 assembly, but [only] the machine-specific parts differ), and you can also use tools presented here, but you need to find some "glue" tutorial dedicated to MSX which will fill you on those machine-specific details, what's the memory layout of MSX, how to use it's HW features like graphics, sound, sprites, etc.... There's excellent web dedicated to MSX at msx dot org, where you can find also wiki with tips for programmers, and probably also some links to other tutorials or example projects and HW info.
If you are completely new to assembly, and you really want to do MSX, it may make sense to start rather with MSX tutorials, and scavenge the ZX assembly tutorials a bit later, when you can somewhat tell which parts are machine specific features, and pick up the Z80 assembly tricks which do apply also for MSX.
The z80 code itself will "work", but referring to anything outside it (like display memory) will differ from one z80 computer to another.
Since even when writing for the speccy you'll probably want to have some kind of hardware reference in hand, writing for the msx shouldn't be much different - you just need a different reference =)
Also be aware that this assembler does not use the original Z80 syntax. The “$” (dollar sign) used by this assembler is not a part of the Z80 assembly syntax. Also, by default, all numbers in Z80 assembly are considered to be hexadecimal, not decimal. There are other differences as well, but you get the jist.. If you are using a different assembler, you might need to tweak the assembly in order for it to work for you.
The basic information about how the instructions work is the same. However MSX is totally different to the Spectrum. Anything to do with writing to screen, reading the keyboard, etc will be completely different. The MSX did not have an area of screen memory in the main 64K. It used dedicated VRAM accessed by a visual display processor chip (a Texas Instruments one for earlier MSX machines). The process for writing (and reading) the MSX VRAM (and VDP) require a few techniques Matt hasn't talked about. Basically using OUT and IN instructions (and also DI / EI to disable / enable interrupts). There were probably also MSX bios routines to do some of that too (just as we saw in the Hello World example program).
Atom has been discontinued and the Z80 language package for syntax is not available any more. Can anyone recommend an alternative editor for this tutorial?
VSCode is the closest, and if you don't want the Microsoft proprietary libraries you can install the fully FOSS version "Codium"
How would I do this direcly on the spectrum?
Were there any good asemblers back in the day?
I don't know about anything specific, but I'm sure it would be possible. There were several assemblers for Z80-based computers that ran CP/M
The MEMOTECH MTX512 can combine Assembly and BASIC together I.E.
ASSEM 10
10 CODE
&H4000 LD HL,&H20
&H4004 LD BC,AH32
&H4008 ADD BC,HL
&H400C LD (HL),BC
&H4010 RET
20 REM End of assembly.
the MTX512 also has a proper keyboard which makes coding easier.
What about storing you assembly language in the REM statements and do CALL RAND USER(16384) or you can do like in this example goto 10.
I don't know anything about the Memotech computers. Looks like a nice feature!
@@slithymatt if a special piece of hardware plugged into the back of the computer you can load and run SINCLAIR Spectrum games for both the 48K and 64K machines and it just happens that you can get the MEMOTECM HDX512 (Hard drive) or the MEMOTECH FDX512 (Dual floppy drive) and can run CPM/80.
Are you sure the MTX512's assembler supports "ADD BC, HL" and "LD (HL), BC" as pseudo-instructions? The Z80 has neither.
I'm gonna guess you reversed the operand order for those. The latter can be done via:
LD C, (HL) ; Load low byte
INC HL ; Advance to high byte
LD B, (HL) ; Load high byte
DEC HL ; Go back (may not be needed)
Once again, I know nothing about the BASIC used by that machine.
The processor is the ZILOG Z80A get the the MEMOTECH program book and have a look at the machine code for the Sound To Light programme
@@DAVIDGREGORYKERR I know! I saw that it used the Z80.
I need to ask a question the tutorial is very helpful but i am having a rough time finding an ide to make the .asm file work
I don't use an IDE, all you need is a text editor and the sjasmplus assembler. See the GitHub link in the description for more info
@@slithymatt thank you
Speccy is an affectionate name often used in magazines back in the day but it kind of makes my skin crawl when it’s used too often or in inappropriate places. For me at least, I prefer just hearing the regular name of Spectrum. It’s kind of similar to if you kept saying Bro all the time, you could but in general you likely wouldn’t. No hate, just my opinion.
I try to switch it up, because saying Zed-Ecks-Spectrum over and over can get monotonous.
@@slithymatt absolutely it’s full name is far too long winded but just Spectrum is easy enough I think. I mean it’s your channel, do your thing.
Have you some experience with gens-3 assembler directly on spectrum computer/emulator ?
No, never tried it.
Thank you for that video! I have a ZX Spectrum since the 80ies, and programmed video games in assembler. I really would like to turn this thing on again, but there are two impediments: I have no old fashioned TV as a monitor, and I have no cassette drive, not to speak of the cassettes with the assembler and so on. Any clue, how to fix this?
Any TV with an analog PAL tuner should work, assuming you have a PAL unit. Most modern TVs still support analog RF video, but it may be stretched out on the screen. As for a tape deck, you can use anything that can play a sound through a headphone jack. You just need a dubbing cable, with a 3.5mm plug on both ends. Then you can just play the sound file through the cable.
@@slithymatt Thank you! That helps a lot.
There is a simple mod to bypass the TV modulator and give a composite video output. As for storage there are several modern alternatives to tape. Some use SD cards to copy file images from your PC to the SD interface that plugs into the Spectrum.
@@XXXXXX-dy5fs thank you!
There will never again be a register pair as great as hl.
HL' is just waiting in the wings, though...
@@slithymatt Well I admit, I tend to flip-flop between the two.
takes me back not codedd any z80 since the 1990s, I dont think i done any assembly on spectrums mostly Amstrad CPC when i developed a text editor and some small projects on the PCW systems but mostly coding on low power stand alone chips systems hardware like controllers, io ect .. serial devices with Z80 logic.. but mostly other CP/M based systems .. mad really that Digital Research could have been instead of Microsoft .. Gary Kildall could have been instead of Bill Gates
Why is it See-Eighty and Said-Ex-Eighty but not See-Ex-Eighty?
The Z80 is an American chip, while the ZX80 is a British computer
7:40 shows a LD (NN),C instruction that Z80 doesn't have.
But the contents is promising and I hope many will learn lots.
Yeah, someone else caught that already. Had a bit of a brain fart there. I'm to change it to A in the slides in the repo
@@slithymatt There was no damage caused :)
"bro i cant pass this level on this game can you do something?" ok looking for DEC (HL) on the code , remove it and there you go infinity lives...oh the memories lol
Emacs also have syntax highlightning.
There's one in every crowd... 😉
@@slithymatt yes, but it is plain better. :-)
IMHO it's a bit better to end these early snapshot examples with `jr $` (infinite loop of self-jump). (and leave the "ret to basic" for later, when you will deal also with loader/sysvars/etc) It's also nice reminder for asm beginners, that the CPU doesn't stop where the source does, and keeps executing whatever it finds in memory further down, unless it is explicitly prevented.
If you’d have posted these videos earlier I could of learnt assembly coding from you and would of been a hero in my High School and maybe Bill Gates instead of a geek who became an accountant. Thanks. 35 years too late. Try harder next time! 🤣
Shut
Inspired, I've now got a tiny blue stick-person rotating in a character cell... with a pause subroutine to slow it down enough to see it. I'd make it move around the screen but sprites on a spectrum memory map are beyond my brain for today :) I mean, it's easy-ish to move "sprites" sideways on a speccy screen, it's just the moving up and down that gets tricky :)
As a child I had a language extension tape _"Fifth"_ (I'd link to it, but a product name like that wasn't built for legacy searching an internet :) , which was a library of sprite routines and such, and wasn't a derivative of Forth, despite its obvious pun. I recall it being quite nice - hacking around with its demos, but I think at the time I hadn't tuned into the delights of such things, or what I was doing.
edit: found a reference, if anyone remembers this: worldofspectrum.org/archive/software/utilities/fifth-crl-group-plc
... I cite this, since when a 12yr old, I remember I found it fascinating, and looking back at the manual on this link, I can see why... but I can also see why it went over my head at the time :)
Very cool! I never heard of this "Fifth" -- very cute name. Was it only for the Spectrum?
@@slithymatt I believe so, aye...
I can't recall why I bought it back then, but I imagine I read an advert in _Your Spectrum_ magazine saying "WRITE YOUR OWN GAMES, MAKE ££££", sent off naively, opened the box and realised I was lacking various other parts, namely those in my brain :)