A new ZX Spectrum is coming (time to learn Z80 machine code!)

  Рет қаралды 71,327

Darryl Sloan

Darryl Sloan

Күн бұрын

Пікірлер: 345
@darrylsloan
@darrylsloan 4 жыл бұрын
As a companion to this tutorial series, please avail yourself of my free Z80 ebook: ped.7gods.org/z80.pdf
@darrylsloan
@darrylsloan 4 жыл бұрын
@XXX XXX I dabbled in BASIC in the 1980s, in my teens. Pascal and COBOL were the languages I got to grips with during my A-levels. But I can't remember much about those today. My current coding interests are MicroPython, NextBASIC and Z80.
@schismaticschematics
@schismaticschematics 4 жыл бұрын
I'm on the same trip and found your pdf via the ZXSNext website. I've found the writing style and the way your presented the info really clear and easy to understand. Thanks for making it available.
@yVFIdqca
@yVFIdqca 3 жыл бұрын
Are you planning any epub / mobi version?
@darrylsloan
@darrylsloan 3 жыл бұрын
@@yVFIdqca I'm not sure when I'll get around to doing that, but I'm a Kindle user, so I do like the idea.
@vincentmiller6977
@vincentmiller6977 3 жыл бұрын
you all probably dont give a shit but does someone know a tool to get back into an Instagram account? I somehow forgot the password. I appreciate any help you can offer me.
@gnamp
@gnamp 5 жыл бұрын
For those struggling with using the Spectrum input/ compound tokens; when using a PC keyboard, for the 10 RANDOMIZE USR 50000 BASIC bit... Type 10 then the T key (to get randomize), then ctrl + shift to enter extended mode (E) and type L (which gives you USR)... enter then R (for run!) enter again and away you go.
@b213videoz
@b213videoz 2 ай бұрын
Ever since I was 11 I've been haunted by this question "Why must it be RANDOMIZE with USR ?" I mean USR is just a function returning a value (which we do not care about as the game once started has no return)
@Daeve42
@Daeve42 7 жыл бұрын
Came from the ZX Spectrum Next Kickstarter page, stayed for the "wow". I've tried multiple times this week to get to grips with z80 assembly in preparation for my trip back to the early 80's and a re-investigation of the Speccy, I've failed everytime due to not knowing/having forgotten something the author skipped over or assumed the reader/listener should know. Your video is the first thing that has held my attention and been understandable. From a childhood background of Sinclair Basic, no machine code and the odd struggle with python and R nowadays, after watching your video I think I might just be able to make a breakthrough and give this a proper go. Thanks! Please keep up this series - I'd love to see it integrated into the Spectrum Next new website/home when it goes online.
@makepool
@makepool 3 жыл бұрын
I'm a software developer by trade but I've always regretted never having done any Assembly. This video was really instructive and has fired up my interest for sinking time into learning Z80. You're a good teacher.
@spinnetti
@spinnetti 3 жыл бұрын
assembly is an addiction. Having to count t-states and optimize ML is more rewarding than any other sort of coding.
@viktororban5684
@viktororban5684 7 жыл бұрын
You have a really relaxed teaching style and a great voice, loving it. +subbed for more Z80 goodness
@GrahamDIY
@GrahamDIY 5 жыл бұрын
You wrote, ok a year ago now :), what I was going to write. Completely agree 👍
@sambrown9494
@sambrown9494 6 жыл бұрын
Do you know, this is the best / simplest tutorial I've ever seen, after 30 years of books that make you give up after the first chapter. Bravo! Looking forward to watching the rest. Many thanks. Well worth doing! :)
@antonnym214
@antonnym214 6 жыл бұрын
I was a Z-80 programmer. DJNZ stands for "Decrement B and Jump if Not Zero". It's important to note that it decrements and tests the B register only, which is why we often use register B for looping structures. An advanced note is that this instruction performs a relative jump only, so your destination must be within 128 bytes of the DJNZ instruction.
@refractedphoton
@refractedphoton 5 жыл бұрын
Does that mean in the video at c.23min 55seconds where it seems to show the memory locations taken up by the code it is wrong as it seems to show the memory location to jump to taking up 2 bytes/2 memory locations (50012 and 50013)? If it is what you call a relative jump which has to be within 128 bytes then I assume that means it only takes up one byte???
@ped7g
@ped7g 5 жыл бұрын
@@refractedphoton yes, there's mistake in the video, the `djnz` opcode takes only two bytes (jut like `jr` which stands for `Jump Relative`). `jp` (JumP) and `call` occupy three bytes, capable to address any byte in 64ki address space. Then there are also 1-byte shortcuts for `call` pointing to addresses 0, 8, 16, ..., 56, which all belong to the ROM area, so they are not very interesting for classic ZX 48k programmer (things may change on +3 model or extended clone models, where you can map RAM into the 0000 area, and place your own subroutines at those fixed entry points).
@antonnym214
@antonnym214 5 жыл бұрын
@@refractedphoton The destination address itself is a 2-byte address, but it's within a 128-byte range of where we are jumping FROM, so it's okay. Hope this helps.
@user-sw8vb2qo8y
@user-sw8vb2qo8y 2 ай бұрын
I can't believe it's been 7 years since I signed up for the first ZX Next Kickstarter. I've been saving civilians and hunting for treasures in Cyclone ever since I received it 🙂
@solangoose8372
@solangoose8372 5 жыл бұрын
I was born in 71 in the UK. The 48k Spectrum was my first real computer. I did lots of basic programming back in the day on the Spectrum and later Microsoft basic. I always wanted a crack at assembly language but never got round to it. I really want to have a go and this video is the perfect intro. You asked and answered all the questions I wanted as you were walking through this. Thank you!
@darrylsloan
@darrylsloan 5 жыл бұрын
Glad you found this helpful. I'm from '72.
@Lord-Sméagol
@Lord-Sméagol Ай бұрын
It's so much easier for you using an emulator and assembler. My first computer was a Nascom 1 with 1K of screen RAM and 1K of user RAM (960 bytes free). I didn't have enough RAM for an assembler; I had to do that myself, looking up each instruction in the fat Mostek book! After a while, I got to remember the common instruction codes, but after LOTS of programming I memorized the codes for all the instruction groups. And all these years later, I can still assemble and disassemble Z80 without looking anything up!
@petermirtitsch1235
@petermirtitsch1235 5 жыл бұрын
I still have my original Spectrum 48k (converted from a 16k) and a spectrum + and +128. Great machines, and loads of nostalgia. I might actually start coding again. Watching this video brought some of it back.
@Teppic11
@Teppic11 7 жыл бұрын
Good overview. I'd probably have mentioned that when you write code in assembly it takes full and total control of the machine, it's not run under basic. So without the 'ret' the CPU would just keep running whatever values happened to be in memory, which locks the machine up.
@Javier197y2
@Javier197y2 7 жыл бұрын
Darryl, being an old time ZX BASIC programmer and assembler newbie, I have to say watching your video is a pure delight for all of us Speccy lovers :-)
@rebeccamacgregor549
@rebeccamacgregor549 6 ай бұрын
Brilliantly explained. I look forward to watching more of your videos.
@nicadi2005
@nicadi2005 6 жыл бұрын
Hi Darryl, DJNZ stands for "Decrement-(and)-Jump-(if)-Not-Zero" and it's classed as a jump instruction - although it's more of an oddball at that (meaning "one of a kind", really ;-) I should also point out that it only occupies 2 bytes in memory (1x opcode, 1x displacement), not 3 as you implied when showing the memory addresses alongside your code. The reason for that is because it does a RELATIVE jump, rather than an absolute one. The displacement is given as a SIGNED (two's complement) byte, limiting the range of the jump between -128 and +127 from the current address - which is the address for the instruction following immediately after DJNZ. I hope that helped you to better understand what's going on. Cheers!
@nicadi2005
@nicadi2005 6 жыл бұрын
+Darryl Sloan " It jumps in the fashion of JR instead of JP." - Yep, precisely. ;-) "So many subtleties to remember." - Ah, but wait till you hit the really nifty stuff: I/O operations, BCD arithmetic, interrupts, working with floats etc. etc.
@Sabre_Wulf1
@Sabre_Wulf1 7 жыл бұрын
Bang on mate...here's your first students.. I'm over 40 , had my speccy in 84 at 11 years old...too young to cope with assembly. So 35 years on and a Snext backer.. I have a notepad and subscribed to your channel. You have my ears sir !
@fecheverria
@fecheverria Жыл бұрын
I like the peace of how you explain all this. Thanks
@RetroSteveUK
@RetroSteveUK 5 жыл бұрын
Thanks for this. Assembler demystified! I feel motivated now, to go learn more.
@moozoo2589
@moozoo2589 2 жыл бұрын
Back in 90's I made my own disassembler. The whole program fit in 4 kbytes and I was loading it into the screen memory to keep rest of the memory available for hacking/debugging games. The remaining one third of screen memory was used to display the debug window. Basically I had a custom ROM that allowed you to load a game, press reset and system would bring you to command prompt without wiping the game from RAM. Browsing the code helped me a lot to improve my programing skills.
@nicks6649
@nicks6649 2 жыл бұрын
I just managed to get hold of a second hand spectrum next, haven't written a line of z80 for nearly 40 years and this was a really good reintroduction - Thanks Darryl
@VRBug
@VRBug 7 ай бұрын
I've got an N-go and have been a speccy fan since I was a kid. I've loved the games and dabbled in BASIC but it is time to take the programming seriously as its on my bucket list - thanks for this!
@juliegreen7604
@juliegreen7604 9 ай бұрын
Djnz means Decrement [B], Jump , (if) Non-Zero. It takes 8 or 13 clock cycles depending upon the outcome.
@royloveday4350
@royloveday4350 4 жыл бұрын
You have just flipped me out. I taught myself to do that for my GCSE, it was an unbelievably intense moment in time. I reverse engineered from scraps of code, Input Magazine and the manual way back in the 80's without a compiler or the internet. I created a kind of cefax emulator that used machine code to write new pages rapidly to the screen because the means to do it in Basic was chuggingly slow. Everything was compiled by hand and calculated on paper. It took me an eternity to work out how to write to the screen memory in a way that didn't create a total mess and which didn't either hang or restart the machine all without any kind of real time feedback and then tape loading each time to get back up and running again. I got a C for my GCSE because they literally had no idea what I had achieved and probably also because I failed to 'show my working' . 30 years on and I'm feeling vindicated as if someone finally understood. 👍
@darrylsloan
@darrylsloan 4 жыл бұрын
You did better than me, Roy. I was bamboozled by Z80 assembly in the 1980s. I learned it in my 40s for fun. I'm still blown away by how many views this tutorial gets. Check out my free Z80 ebook, too: ped.7gods.org/z80.pdf
@royloveday4350
@royloveday4350 4 жыл бұрын
@@darrylsloan I had little reference to anything other than Input magazine and the Spectrum Manual, nobody who could assist, it was essentially brute force and reason and the time I was allowed to use the family TV. I'll check out the stuff. It's been quite a trip seeing all this again.
@darrylsloan
@darrylsloan 4 жыл бұрын
@@royloveday4350 I started off with my Spectrum attached to a little black and white portable TV in my bedroom. The irony of a computer called Spectrum running in greyscale! But we all had what we had, and we love it.
@royloveday4350
@royloveday4350 4 жыл бұрын
@Jamie McLaughlin I have to say it's wonderful even after all this time to find some kind of recognition. We are so affected by our world at that age and I couldn't share my achievement with anyone in a meaningful way at the time. Lockdown has allowed me to pursue a latent curiosity and I loved the skill of the educator.
@beakytwitch7905
@beakytwitch7905 6 ай бұрын
The Spectrum was the first adequate and yet inexpensive computer. I did a lot of programming on it in both Basic and assembler.
@harrivayrynen
@harrivayrynen 4 жыл бұрын
This is one of the best programming tutorial! From zero to one working program. Good work!
@Psycandy
@Psycandy Жыл бұрын
i got my speccy in 83, age 13, and also dabbled in assembly and likewise have an idea to finally learn it, almost as if actually doing what i promised myself i would do. Turns out speccy devs used emulaors and tools too.
@erichobbs4042
@erichobbs4042 4 жыл бұрын
I've spent most of my career working with high level languages like C#, JavaScript, and Basic. I was surprised by just how logical and understandable the Z80 assembly code looks. Can't wait to try this out myself now.
@jhonny1392
@jhonny1392 7 жыл бұрын
Thank you so much for this great tutorial. be waiting for the next one !. Can´t wait to see ZX Spectrum Next in person !. Cheers, John from Chile, South America.
@MarcKloos
@MarcKloos 4 жыл бұрын
@jhonny1392 Have you got your Next already?
@jhonny1392
@jhonny1392 4 жыл бұрын
@@MarcKloos No. At the end, never bought it, cos it was a partial versión of the original and for me this way, it was not worth it. Cheers.
@MarcKloos
@MarcKloos 4 жыл бұрын
You can still get one on the current KickStarter. But it's more expensive now.
@blue552
@blue552 3 жыл бұрын
@@jhonny1392 An 'enhanced version'?! 🤪
@Havanacuba1985
@Havanacuba1985 3 жыл бұрын
Thank you for this and the book,it is really exciting ,I only ever had a very basic understanding of basic ,but this and your book is making sense,I found spectrum basic the best of the bunch at the time , so to find your guide to machine code and assembly is absolutely brilliant. I have just watched several minutes of the video and read the first pages of the book and it’s really making sense . Thank you so much . I got my first speccy in 84 and have just got myself a lovely refurbished one with an Divmmc sd card disk system
@GrahamDIY
@GrahamDIY 5 жыл бұрын
I’ve only just started watching this video but it seems perfect. I had a Speccy 48 in the early 80’s and programmed in basic a lot. I tried assembler and failed I’m now someone whose been programming for 25y in C, Java, Ada and lots of others. All real time programming. But....But I still want to master Z80 assembler Video is looking perfect so far:.. 👍
@F61Wolf
@F61Wolf 7 жыл бұрын
Love the ZX Spectrum (first introduced to it through Rare Replay). Been struggling to wrap my head around assembly. I thought I was learning things, but I still couldn't do anything simple. So happy I found this video! Who knew making a checkerboard would be so interesting?
@Cp-71
@Cp-71 5 жыл бұрын
I feel strange here. I'm a fan of ZX Spectrum yet I don't have any nostalgia for it... because I'm 17.
@donaldklopper
@donaldklopper 3 жыл бұрын
@MD now that's a comment ... I think there's a lot of fun to be had playing with the ZX Spectrum and various other 8-bit computers, and a lot to be learnt.
@frankx8739
@frankx8739 3 жыл бұрын
Well it's a year later now: feeling nostalgia yet?
@edmund-osborne
@edmund-osborne 3 жыл бұрын
I was born in the 21st century and love the spectrum too! Computers in the 1980's were very different to what we have now and better in a few ways, like allowing the programmer complete access to the hardware and being simple enough to boot instantly and one person understand how the entire thing works.
@b213videoz
@b213videoz 5 ай бұрын
I'm the opposite: I have nostalgia for ZX but I'm not its fan 🤪
@timrichter1980
@timrichter1980 6 жыл бұрын
The thing is, I came to your channel because of this cool Z80 assembly video, and stayed because there are even more interesting non-IT videos. Keep your style!
@timrichter1980
@timrichter1980 6 жыл бұрын
Odd in terms of different, yes! And I find it interesting, that I share some things with you, like programming, Amiga, ZX Spectrum and a little bit of spirituality. I have lost my way a bit, have problems with myself but your videos help me quite a bit and are entertaining at the same time! Edit: I forgot to say thank you!
@Javier197y2
@Javier197y2 6 жыл бұрын
Hey Darryl, another simple way to implement the main loop is by also using B register (LD B,12) plus DJNZ at the end and preserving B using the stack at beginning of each 2 rows....thanks for the video, great stuff!
@psycronizer
@psycronizer 6 жыл бұрын
you just blew my mind ! another speccy is coming out ??!! WTF ??!! I got mine when I 15 in 1984....learnt the BASIC pretty quick and then delved into the assembly language just because I got curious about the codes for it in the back of the manual...the first book I got to learn from was specifically for the Spectrum but it helped...loved that little plastic thing.....I wrote a defender type game, nearly finished it but then I got into typical teen trouble etc...a lot of respect for the guys who wrote all those great games for us...so many awesome titles, guys who single handedly wrote titles like Jeff Minter and Matt Smith etc etc..they had some real talent....
@NickT6630
@NickT6630 5 жыл бұрын
I had a ZX Spectrum + back in its day. That was when I first learnt basic programming but I didn't understand machine code then. That changed in 1990 when I bought a Maplin electronics kit for a Z80 single board computer with hex keypad. You typed the code on the keypad into memory addresses and viewed it on LED seven segment displays and could run it directly. Shortly after that I built another z80 based computer based on the Microproffessor. In 2019 I'm still programming in z80 machine code on more advanced customized versions of the microproffessor that I've built over the years.
@darrylsloan
@darrylsloan 5 жыл бұрын
Ah yes, I saw somebody demoing one of those on KZbin once. Fascinating.
@elektron2kim666
@elektron2kim666 7 жыл бұрын
Thanks for sharing this, Darryl Sloan. Might buy one in 2018 because I always miss the speccys basic programming. Wrote many games as a teenager between work and school for my friends and family to try out. It sparked off my english and a computer education later. I run a speccy app on my iPad sometimes, but it's hard to type as fast as I did on the original in the 80's. I had microdrive, microdrive tapes and printer in the end. The machine language speeds blew my mind and I managed to construct a little racing game with a preprogrammed road from basic coding where the machine code then looked at these stored numbers to recreate the road very quickly. It took 10-15 minutes to restart from audio tape on each human programming error.
@MattBaker1965
@MattBaker1965 6 жыл бұрын
OMG I'm 17 again :)
@mikedench1110
@mikedench1110 7 жыл бұрын
I've been struggling to get to grips with machine code on the Spectrum and this is the first tutorial that has been helpful. I'll have to play it several times and take notes but at least I can understand what you're saying.
@petermirtitsch1235
@petermirtitsch1235 5 жыл бұрын
I used to use OCP Assembler. That was a great package on the Speccy.
@newyoda
@newyoda 7 жыл бұрын
I loved learning to code Basic on the 48k when I was a boy. My dad got some scripts of games like Bricks, it would take about an hour to write it and then the satisfaction of playing (after corrections) was great. Great to hear a new model is coming out, I will have to research it. Thanks for the assembly guide, good stuff.
@newyoda
@newyoda 7 жыл бұрын
Sold - to the man in the blue hat. Thank you Mr Sloan =)
@Lord-Sméagol
@Lord-Sméagol Ай бұрын
I still have a 48K ZX Spectrum! It was still working in 2018 when I used it in a YT video: Toccata & Fugue in D Minor (J. S. Bach) on the Sinclair ZX Spectrum (5 voices).
@MrGradlet
@MrGradlet 4 жыл бұрын
Exactly what I was looking for. Been wanting to scratch the assembler itch for more years than is probably healthy. Thanks for sharing.
@darrylsloan
@darrylsloan 4 жыл бұрын
Gareth Williams Great to year! I got as far as making my own Soectrum game. If you’d like to play it, or look at the ASM code, you can grab it from the Spectrum Computing site. It’s called “Knights”.
@MrGradlet
@MrGradlet 4 жыл бұрын
Darryl Sloan I will definitely check it out. I’m up to part 3 of the video and my OCD forces me to complete them before moving on!
@edz
@edz 7 жыл бұрын
Great video. My first step into the world of assembly. I've got until January to master it ready for my ZX Spectrum Next!
@RandyFortier
@RandyFortier 3 жыл бұрын
FYI, djnz stands for "decrement and jump if non-zero"
@tonybkent
@tonybkent 5 жыл бұрын
Good video Darryl. I'm currently using it to remind myself how it all works and doing some comparisons in speed between BASIC and assembly language. I didn't realise quite how slow a BASIC for-next loop was to do the same as what your video does in assembly! I taught myself Z80 assembly language back in 1983 / 84 and used it eventually to write tape-to-microdrive conversion for some games and a little bit of code for a game that never came to anything. Nice and nostalgic messing around with this again.
@Tom53Tech
@Tom53Tech 6 жыл бұрын
In The Mid 80s I Owned The Sinclair 1000, A Cousin To The Original ZX models. I Loved Programming Machine Level On It; Something I Learned On My Tandy Model 1 Years Earlier. Now Retired And Still Code.
@bobzeepl
@bobzeepl 5 жыл бұрын
I am an IT guy, but mostly into hardware and servers. Did learn assembly at school, but always hated it, and mostly cheated on exams. My father programmed a Minesweeper in assembly for he ZX. Really impressive to me.
@rebeccamacgregor549
@rebeccamacgregor549 5 жыл бұрын
Brilliant video. The first on machine code hat I have found to be really helpful. A brilliant visual example too. Thank you for making this video..
@rodoherty1
@rodoherty1 7 жыл бұрын
Really nicely explained! I've never used a Spectrum, myself, but I still enjoyed that intro to Z80.
@oldmossystone
@oldmossystone 5 жыл бұрын
JR is 'jump relative' which is a bit faster than JP because it uses fewer bytes to encode the instruction, but this also means it is limited in scope. I think it's limited to +127/-128 relative to it's own position in the code. Haven't checked a reference for that though so :)
@darrylsloan
@darrylsloan 5 жыл бұрын
colb Your explanation is right, but I used JP in this instance because I didn’t want to overwhelm the listener with unfamiliar technical concepts in lesson 1.
@stephenkelly6301
@stephenkelly6301 7 жыл бұрын
Thanks for the interesting upload. The old Speccy 48k is probably the machine I look back on most fondly as well. In the past few months I seem to have been swept up with the whole retro computer thing, Z80 in particular. I've been building some RC2014 machines and a Spectrum Harlequin clone, which I have put in a RetroRadionics replica case. I haven't looked at Z80 assembly for pushing 30 years, but I have been meaning to for a few weeks. Your video has just given me another nudge, so thanks! I hope you do some more and make it a series. Looking at the backing that the Spectrum Next has been receiving (me included ) I'm sure there would be some interest.
@niallmartin590
@niallmartin590 3 жыл бұрын
You can use these tutorials with Linux, FUSE and Pasmo assembler, just add "end 50000" or whatever address you started with before the final "ret" instruction
@DJFuZionDnB
@DJFuZionDnB 7 жыл бұрын
Thank you for this. I'm here because of the Next too. Time is always tight, but looking forward to giving this all a try. Great explanations btw.
@nickpearson1487
@nickpearson1487 4 жыл бұрын
Cheers for this Daryl - excellent vid, and book, you've made a 53 year old feel 15 again :) I'm looking forward to getting back to assembler - I used to love coding in it (z80,6502 and 68000). I'm an IT bloke by profession (c#, vb,c, SQL, shell script and many others - I started life with COBOL, C and Informix), so hope to pick this up relatively quickly (wishful thinking), and see what I can contribute to the excellent Spectrum Next community. Great vids, keep them coming.
@charleshawes9479
@charleshawes9479 7 жыл бұрын
Great video explanation. I also want to try my hand at assembler for the first time. I was a keen Basic programmer and especially enjoyed MasterDOS for the Sam Coupe to create databases, screen animations etc. Assembler seemed too advanced back in the mid-80's, and I'd like to see if I can make some progress on some simple graphics routines and perhaps some simple games to help expand my assembler knowledge from zero to at least amateur. I am looking forward to the Spectrum Next being released to see what talented programmers can do with it. Good luck with your Assembler knowledge. Hope you may post another video showing your advancement of knowledge in a few months?
@Inaflap
@Inaflap 7 жыл бұрын
Here's another way you can do a checker board pattern on the Spectrum. After loading HL with the screen attribute start position, as you did, register A is set to zero using xor A. That's just a more efficient way of doing ld a,0 A loop (l2) of 32 columns is nested inside a loop (l1) of 25 rows by utilising the stack to preserve the value of B register. Instead of loading the value of 0 or 127, we can simply alternate using xor 127. We just need to initialising register A with zero (xor a). We want to offset the following row, so that calls for another xor 127 in the outer loop (l1). scrattr equ 0x57E0 org 50000 di ld hl, scrattr xor a ld b,25 l1 push bc ld b,32 l2 ld (hl),a inc hl xor 127 djnz l2 xor 127 pop bc djnz l1 ei ret ; to BASIC
@amigalemming
@amigalemming 5 жыл бұрын
What about using C for counting in the outer loop?
@markretro3612
@markretro3612 2 жыл бұрын
great video, i have watched a few different starter guides and ended up more confused, this actually made sense to me .
@Inaflap
@Inaflap 7 жыл бұрын
You can use the B register in the outer loop by utilising the stack. You have to push / pop the register pair BC (not just the B register you care about). Be sure that you always pop off anything you pushed on the stack before attempting to return to BASIC or you'll return to the wrong point in RAM (and crash the machine). ld b, 23 outer push bc ld b, 32 inner nop djnz inner pop bc djnz outer
@pandoraefretum
@pandoraefretum 7 жыл бұрын
I'm about the same as you : I am delving deeper into Forth, which I first came across on the Spectrum 35 years ago.
@Metastate12
@Metastate12 6 жыл бұрын
The JR NZ is a relative jump (+127/-128). Faster, as it only reads 8 bit for the (relative) address. But you can't use it for larger jumps. If you only use relative jumps, you can execute your code from any location (relocatable).
@ped7g
@ped7g 5 жыл бұрын
`jp nz` is faster for "jump taken/condition true" case (`jp` is 10T/10T, while `jr` is 12T/7T, so `jr` is faster when condition is false)... so if you were optimizing for speed, you often did use `jp` in similar loops like in video (although most often one didn't need those 2T per loop that desperately, as any very intensive loop did end "unrolled" anyway, so the few remaining loops were of higher-level kind, and not that critical).
@davidkmatthews
@davidkmatthews 6 жыл бұрын
Quite a good intro to Z80 machine code programming for the Speccy - well done! However for those unfamiliar with SInclair BASIC, you could do with explaining what the utterly obscure "RANDOMIZE USR" command is for. (IIRC you can use "PRINT USR" instead)
@tobobobo2842
@tobobobo2842 7 жыл бұрын
Thanks so much for these.m - devouring them all right now. You have a knack of getting the method across that all my books on Z80 can't. Keep it up pls.
@anthonychallis2472
@anthonychallis2472 7 жыл бұрын
Thank you, great memories, hours spent slaving over a hot Speccy writing machine code. It would have been good if you had written the program in basic and machine code and demonstrated the difference in speed to draw the chequer patten. That was the real benefit of using machine code, speed and efficiency. Great video, thanks.
@axtrifonov
@axtrifonov 4 жыл бұрын
Thank You! I already did some stuff in x86 assembly, now i want to try Z80/Spectrum one.
@londongaz2
@londongaz2 4 жыл бұрын
Thank you! I'm just putting together a home brew z80 project, so this is really useful.
@darrylsloan
@darrylsloan 4 жыл бұрын
Cool. Glad to help.
@niallmartin590
@niallmartin590 3 жыл бұрын
Sitting in front of a real +2 with Zeus loaded, this is brilliant, thank you
@thundersos8087
@thundersos8087 3 жыл бұрын
Just some comments to help you along I hope you find them useful. ld is short for load or can sort of think of it as basic LET. djnz stands for decrease and jump if not zero. It only works with register B. ROM can't be written even temporarily on the real hardware, an emulator might allow it though. And it might be a better idea to use register C (the other half of B) for the outer loop. A is the accumulator so if you did any calculations in between writing the values to the screen then A would be changed.
@psycronizer
@psycronizer 6 жыл бұрын
22:18...talking about the working's of the DJNZ instruction....back when I was doing this I had no assembler program, did it all on paper, so I had to count the number of bytes BACKWARD for the number to enter into the field...and when you have hundred's of lines of code with lines and arrows trailing all over the paper to show where each jump goes to it get's messy and damn confusing..oh the headaches and the coffee...I remember it well....
@James-fo8rf
@James-fo8rf 3 жыл бұрын
Thanks for a great series. I understand assembly a lot more now. Thanks.
@JimGiant
@JimGiant 6 жыл бұрын
I'm in my early 30s but still have some nostagia for that generation. I bought an Amstrad cpc from a boot sale for £7.5 when I was about 6 with a bin bag full of games. I did a fair bit with basic for a kid that age. I'm learning assembler for Mega Drive now.
@SwainyAtRetroAsylum
@SwainyAtRetroAsylum 7 жыл бұрын
Just wanted to say thanks for this video. It's great to have this explained in such an understandable way.
@YouTubeSupportTeams
@YouTubeSupportTeams 4 жыл бұрын
greetings from BT39, just discovered your channel, some interesting video titles that took my interest. Like 'Jim Browning''s channel it's nice to hear a Northern Ireland accent spoken without sounding absolute cringe.
@darrylsloan
@darrylsloan 4 жыл бұрын
Thank you. Hope you enjoy the other videos.
@reddie_zx
@reddie_zx 3 жыл бұрын
LD HL, #5AFF ; end of attributes LD A, L ; for white, or XOR A for black row LD B, 32 LD (HL), A DEC HL CPL ; inversion, A=255 (white) or 0 (black) DJNZ row CPL ; inversion after each row BIT 3,H JR NZ, row ; if HL >= #5800 (attr start) RET original program: 29 bytes, optimized - 17 bytes =)
@TechRyze
@TechRyze 6 жыл бұрын
This is excellent stuff. I can't wait until I have the time to sit down with this and get cracking. I want to write a few simple utilities, but with nice interfaces. I'll be back to run through this in the near future.
@chrismcauley4596
@chrismcauley4596 4 жыл бұрын
Great Video and has got me started into Spectrum Assembly after looking at C64 Assembly
@Retrospective.
@Retrospective. 7 жыл бұрын
Lovin your work! i gave up trying to learn 6502 code on the Oric years ago, but like you, with the advent of the next, i wanna learn code, and like you, i already have a very good understanding of higher level languages. But this is the first "idiots" guide, and i dont mean that unkindly, that actually explains it. you gotta do more videos fella, although having all the code on screen is good when you talk about it, it would be good to see the program run, to give some idea of speed over basic etc. looking forward to your next video thjough. great stuff, slainte :)
@jal051
@jal051 7 ай бұрын
I did this when I was 13. I didn't fully finish anything, but I got a 2d character to move in a simple platforms map. Only the character movement/animation was in machine code. The "map" loading was in basic. I had written in basic my little input program to introduce the hex codes that I earlier had written in a paper. I didn't know there were assembler programs 🤣 I wanted to make a game, but then I was 14 and girls started to matter more.
@user-sw8vb2qo8y
@user-sw8vb2qo8y 2 ай бұрын
I used to translate my first assembler programs into machine code using pen, paper and a table of instructions from a magazine. I used DATA to store the code in a Basic program, and I used POKE commands to write into memory. When I first learned about the existence of assemblers, I considered it 'cheating'.
@jal051
@jal051 2 ай бұрын
@@user-sw8vb2qo8y Hahahaha. It's definitely cheating.
@mikedench1110
@mikedench1110 7 жыл бұрын
What would be really helpful for me is if you could make a short demo showing how you actually use SPIN thats to say keeping the camera on the Spin screen as you do the coding, assemble it and then add the Basic loader so I can figure out what I'm doing wrong! I finally got SPIN to work and I'm determined to not give up on following your tutorials because you explain things well and at the right pace. I'm just a bit thick! SPIN isnt obvious how it works
@mikedench1110
@mikedench1110 7 жыл бұрын
Thanks, Darryl. I'll go and try that.
@richallenxbox1976
@richallenxbox1976 3 жыл бұрын
40 years ago I basically taught myself (at the age of nearly 5) Spectrum BASIC and wrote several text based quizzes and Adventure games.
@neo-frame9369
@neo-frame9369 7 жыл бұрын
It's time to Z80 :) In 80-ties I programing my commodore 6510 in assembler but never learn and Z80. Now I fill it's perfect time . :D I also have two working Spectrums ...
@santiagotelemach8236
@santiagotelemach8236 7 жыл бұрын
Excellent tutorial! the pace is perfect for begginers...
@neilwright128
@neilwright128 6 жыл бұрын
This is amazing! I actually understand this! Thanks so much. Please keep these coming!
@ThePopeandrew
@ThePopeandrew 4 жыл бұрын
Fantastic video once again Darryl. I'm all ready to take the plunge again. You could have chosen some music from 2 Tone records to accompany the lesson :)
@HuntersMoon78
@HuntersMoon78 7 жыл бұрын
I'm getting a ZX Spectrum next, can't wait to get it and use it
@greenmotion2160
@greenmotion2160 5 жыл бұрын
thanks a lot you made me go back to 1983 souvenirs
@peterhodges2535
@peterhodges2535 7 жыл бұрын
Thanks for posting. It gave me the kick I needed to download some tools and have a go myself. If you fancy doing this with less loops, then this also works: org 50000 ld hl,22528 ld de,0 ld bc,768 loop ld (hl),d inc hl dec bc ld a,c and 31 jr z,skip ld a,d xor 127 ld d,a skip ld a,b or c jr nz, loop ret
@peterhodges2535
@peterhodges2535 7 жыл бұрын
Glad it helped, but I wasn't happy with the two branches, so I read a bit more and gave it another poke: org 50000 ld hl,22528 ld de,0 ld bc,768 loop ld (hl),d inc hl dec bc ld a,c and 31 add a,0x1f and 0x20 sra a sra a neg and 0x7f xor d ld d,a ld a,b or c jr nz, loop ret
@nicadi2005
@nicadi2005 4 жыл бұрын
@@peterhodges2535 I don't understand: where's the blue paper coming from?! (using BASin's v15.8 built-in assembler, with a quick copy-paste) Going through the motions: ld a,c and 31 ; at this point, I expect A to contain the current character column position (a value between 0 and 31). It will never be anything else. add a,31 ; adding 31 will produce a value less than 32 if and only if A was 0 (zero). Otherwise, the result would be 32 or larger. and 32 ; isolate bit 5 - i.e. 0 (zero) if A was 31, otherwise 1 (one). All other bits are zeroes. sra a sra a ; shift all bits to right, copying bit 7 in place and feeding bit 0 into the Carry flag - so bit 5 becomes bit 3. All other bits should be zeroes. (Right??) neg ; Ooh, this is interesting, negating the accumulator. Two's complement: flip all bits, then add 1. Based on whether bit 3 was 0 or 1 (i.e. A = 0 or A = 8). The result can only be 0 or 248. (Right??) and 127 ; easy: wipe off bit 7 - so no bloody irritating flash attributes! At the end of this sequence, you end up with either A = 0 (black ink on black paper, no brightness) or A = 120 (black ink on bright white paper). *Sooo... what the heck am I missing??* EDIT: OK, mystery solved. It turns out the BASin v15.8 built-in assembler does NOT recognize the NEG mnemonic (negation of Accumulator content - 8-bit two's complement). It simply ignores it, giving no error and producing no opcode for it. Also, on a separate issue, why are you using LD DE,0 at the beginning instead of just LD D,0?
@peterhodges2535
@peterhodges2535 4 жыл бұрын
@@nicadi2005 this was a long time ago. I think that clearing the pair was just stylistic preference on my part.
@nicadi2005
@nicadi2005 4 жыл бұрын
@@peterhodges2535 "this was a long time ago." - Oh, yes, it was. Three years... I was still young back then! ;-P "I think that clearing the pair was just stylistic preference on my part." - That sounds very odd to me - to make a coding choice, in assembler, due to 'stylistic concerns'... Whenever I design some (sub)routine to do something, whatever it may be, I always assume it will eventually be part of a larger project. Therefore, I always want to make sure I only use STRICTLY the minimum resources I need to carry out the task at hand... This is my design philosophy. *In your case, using LD D,0 spares one byte of memory and frees register E for other potential uses...*
@peterhodges2535
@peterhodges2535 4 жыл бұрын
@@nicadi2005 an entirely valid point, which I put down to this being my beginning with z80 and enjoying the reassurance of clean/touched looking registers in the debugger. Last time I touched assembly in anger was MIPS, quite some years ago.
@avrilcadabra
@avrilcadabra 7 жыл бұрын
Hi found this video after watching your microbit stuff, I am a c64 era kid (well was once upon time) have only tinkered in assembly really, you explained it very well. I never had a spectrum, but used to see them mentioned in the 80's magazines (commodore was king in australia) anyway great job found your video easy to follow. will sub incase you post more
@TheMoonKingdom
@TheMoonKingdom 7 жыл бұрын
Even though I'm not into programming beyond basic mel scripting for 3D; I appreciate how cool this is:)
@domorewithsage
@domorewithsage 7 жыл бұрын
Darryl this is an excellent video and you *must* do more! :) Very well explained concepts, I know some z80 and did 6502 back in the day but other stuff I've seen isn't basic enough to get you going. Well done
@domorewithsage
@domorewithsage 7 жыл бұрын
Thank you when I try and use spin and follow the instructions I get a '2 variable not found, 10:1', assembled the code just fine not sure if I am missing something? imgur.com/a/B8Zp7
@domorewithsage
@domorewithsage 7 жыл бұрын
Fantastic, silly me! Yes thats what it was, I'd remembered the keywords for the first word but not the second. Thanks Darryl!
@TheFusedplug
@TheFusedplug 7 жыл бұрын
Going to learn ZX Speccy programming for exact same reasons I own a + 2 (grey) still from back in the day but never got around to programming properly
@cthutu
@cthutu 7 жыл бұрын
The ROM can't be written to ever actually. It's not even temporary like you suggested in your video.
@jackpret4547
@jackpret4547 6 жыл бұрын
I was obsessed with Spectrum Machine code! My first hacked program was Planetoids Dec hl!! The Manic miner! Merge then Poke xxx(cant remember) Also used "Assem P".
@Kamakazi_-tp2lb
@Kamakazi_-tp2lb 3 жыл бұрын
Decrement jump if not zero basicly makes a compare decrements and jumps if not equal to zero
@JamesT65
@JamesT65 7 жыл бұрын
thanks for doing this, I had the same challenges with machine code.
@gdm413229
@gdm413229 5 жыл бұрын
Memory addresses from 16384 to 32767 are contended by the ULA chip in 48k Spectrums.
@frankx8739
@frankx8739 3 жыл бұрын
Used to be a big machine code programmr on my Speccy {yes I assembled by hand). One thing i could NEVER get to work were the interrupts.
@darrylsloan
@darrylsloan 3 жыл бұрын
I don't understand interrupts either!
@jarisipilainen3875
@jarisipilainen3875 6 жыл бұрын
nice :) but 10 RANDOMIZE USR 50000 gives error. 2 variable not found 10,1 ok fixed it. need use SE basic ROM
@gdm413229
@gdm413229 5 жыл бұрын
Embedded systems engineers might use this machine (ZX Spectrum Next) as a test platform for their Z80 code in custom sandboxes.
@sdfsdghhjjf3880
@sdfsdghhjjf3880 5 жыл бұрын
Excellent !, nicely explained, tempted by the Spektrum Next :)
❌Разве такое возможно? #story
01:00
Кэри Найс
Рет қаралды 7 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 7 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 16 МЛН
Machine Code Explained - Computerphile
20:32
Computerphile
Рет қаралды 116 М.
Zilog Z80 Deep Dive - How does it work?
15:05
NCOT Technology
Рет қаралды 25 М.
Фирменная защита игр на ZX Spectrum: ад из 80 - х
19:50
Как это было
Рет қаралды 101 М.
before you code, learn how computers work
7:05
Low Level Learning
Рет қаралды 294 М.
Timex Sinclair 2068 - The American ZX Spectrum
17:22
The 8-Bit Guy
Рет қаралды 568 М.
ZX Spectrum Laptop
15:02
The Taylor and Amy Show
Рет қаралды 26 М.
Z80 Assembly Language
1:44:45
John's Basement
Рет қаралды 16 М.
Sinclair BASIC vs BBC BASIC - How to fit an entire devkit inside 64K
22:01
ZX80/81 Video Circuit Part 2.  Hi-res display of 256 x 192 pixels.
15:32
❌Разве такое возможно? #story
01:00
Кэри Найс
Рет қаралды 7 МЛН