Z80 assembly language tutorial, part 2: text and graphics (ZX Spectrum)

Sdílet
Vložit
  • čas přidán 18. 05. 2017
  • PATREON | / darrylsloan
    PAYPAL | www.paypal.me/darrylsloan
    Learn how to print text to the screen and create simple graphics (UDGs). Also covered: how to convert binary to decimal and vice versa.

Komentáře • 80

  • @retrocomputeruser
    @retrocomputeruser Před 4 lety +1

    Note to self. Never watch these tutorials after consuming too much beer. Thanks Daryl for these. I think there are sad people who just dislike any video regardless.

  • @bindgagger
    @bindgagger Před 4 lety +4

    I always thought the textbooks of the time, on ZX Spectrum Assembly coding, were too academic with not enough examples, which is why I gave up too early. These tutorials are great. 38 years late but great!

  • @KingPepper41
    @KingPepper41 Před 6 lety +14

    Thanks Darryl Sloan for these tutorials, its jogging my 51 year old brain, to understand Z80 again, it's been over 25 years since i coded Z80, great memories are flooding back.

  • @peterjones6357
    @peterjones6357 Před 3 lety +1

    Thank you for doing these Darryl, these and the PDF are the the clearest guides available. I can tell you are an author!

  • @wikusvandemerwe2762
    @wikusvandemerwe2762 Před 6 lety +1

    After teaching myself 6502 machine language by writing out instructions on paper and poking them to memory directly, eventually using an assembler was like using BASIC! It made things so much easier. I really wish kids these days were taught something at least as low level as assembly language; they might even enjoy designing graphics on paper and converting the binary to decimal and poking it in, or maybe I'm just easily entertained.

  • @AstAMoore
    @AstAMoore Před 7 lety +2

    That’s a neat tutorial. I’m glad people still express interest in Z80 assembly.
    One small clarification (perhaps not hugely important, but useful to know, nevertheless). RST (which stands for “restart,” by the way) is essentially a subroutine call. It’s advantage over the CALL instruction is that it takes less memory-just one byte, as opposed to three-and it executes faster. The disadvantages are that it is limited to eight fixed addresses (0, 8, 16, 24, 32, 40, 48, and 56) and that it cannot be used with conditionals.
    Anyway, keep up the good work!

  • @LukeAvedon
    @LukeAvedon Před 5 lety +3

    Fantastic how you took the trouble to add in code slides. Wonderful, thanks!

  • @avsie
    @avsie Před 7 lety

    Found these very good Darryl. Hope you decide to continue the series. I'm new to assembly language with some general programming knowledge. I've currently followed parts 1 and 2 and processing them in my thoughts for a bit before moving to part 3. Im just messing about with the code from parts 1 and 2 to get familiar with it. Understanding it so far with a bit of thinking now and then. Found your tips on binary VERY good and the scheme for converting to decimal and from decimal has taught me more than my previous 43 years about binary. It clicked as you described the process. Thanks.

  • @intrepidis1
    @intrepidis1 Před 3 lety

    You're a splendid teacher sir, many thanks!

    • @darrylsloan
      @darrylsloan  Před 3 lety

      My pleasure. Glad you're enjoying this.

  • @TechRyze
    @TechRyze Před 6 lety +1

    Great stuff. Well needed. Not done assembler since uni.
    I really want to make use of this to make some useful little utilities using a serial port.
    I really hope I'll get into this. Can't wait :)

  • @fiko2390
    @fiko2390 Před 2 lety

    tnx i started this months to learn assembly and i read some book of 80s but i find your tut most easy to understand to books

    • @darrylsloan
      @darrylsloan  Před 2 lety

      Thanks. Glad you were helped by this. Be sure and get my free Z80 ebook. ped.7gods.org/z80.pdf

    • @fiko2390
      @fiko2390 Před 2 lety

      @@darrylsloan very tnx!!! i see it on next day

  • @leeh3568
    @leeh3568 Před 5 lety

    Wow I'm getting it. Must be good teaching style, thankyou Darryl.

  • @brainyspex
    @brainyspex Před 7 lety

    Really enjoying this series, Darryl; the pace is spot on. Also, it's a great idea to do a Connect 4 game - looking forward to seeing how this develops. Cheers.

  • @barry2e0dts
    @barry2e0dts Před 7 lety

    Part 2 done Great

  • @74teppic
    @74teppic Před 7 lety +6

    ASCII only goes up to 127 as it's a 7bit set. The Spectrum's character set above that is non standard. (The Spectrum doesn't actually use ASCII, but a very close version -- there's no £ sign in ASCII for example).

  • @monoman4083
    @monoman4083 Před 5 lety

    great stuff, keep going with these. thanks..

  • @bertkoerts3991
    @bertkoerts3991 Před 5 lety

    Love your posts!!! Exactly the level I'm at right now. Sorry I cannot sponsor you, you really deserve it! Tnx a lot!! (Btw - love your accent 😊👍) Brt

    • @darrylsloan
      @darrylsloan  Před 5 lety

      Thanks! Glad you're finding this of value.

  • @David-vq5zh
    @David-vq5zh Před 7 lety

    Excellent!

  • @stephenkelly6301
    @stephenkelly6301 Před 7 lety

    Thanks, Daryl. That was as interesting as the first part.
    Please keep making them!

  • @JasonMasters
    @JasonMasters Před 6 lety +1

    If I remember correctly, the $ sign outside of quotes in assembly code means "the current memory location" so what you're saying in the last line is "eostr EQUals the current memory location" which lets eostr-string calculate the length of the string to print, which is the value loaded into the BC register pair.
    This reminds me of when I created a machine code routine for the TRS-80 color computer to allow me to print the whole of the IBM extended ASCII character set on the high-res graphics screen via a USR call from BASIC. The data for the character set took up more space than the machine code, in spite of me adding heaps of fancy commands to do such things as redefining characters under control of the BASIC program (good for games).

    • @refractedphoton
      @refractedphoton Před 5 lety +1

      I think what is actually happening is that the compiler is being made to know the memory address immediately following the last letter of the word "Hello" in order for that to be used to be able to work out how many letters there are. I don't think the contents of the memory location labelled "eostr" matters as the calculation "eostr - string" uses the memory locations and not their contents as the operands. I think he has just happened to load it with its own location in order to set up a memory location that can be referenced as the one immediately after the last letter's location.

  • @michalnemecek3575
    @michalnemecek3575 Před 6 lety

    17:09 If the program uses data to keep track of items and you make a mistake somewhere else in it, the data can be run. This is called arbitrary code execution or ACE for short. Examples include the 8F item (8th floor, its ID isn't 8F) in Pokemon Red and the coin case in US and european versions of Pokemon Gold

  • @donepearce
    @donepearce Před 4 lety

    defb = define bytes. They are normal memory locations, starting wherever you put them in your code. It is perfectly possible to run them as a programme - just jump or call to one of those bytes.

  • @zxrenew5642
    @zxrenew5642 Před 7 lety

    Thoroughly enjoying this Sir. Keep up the good work!

  • @tn0wl361
    @tn0wl361 Před 6 lety

    decimal to binary reminds me of synthetic division from algebra 2.

  • @ByteMeCompletely
    @ByteMeCompletely Před 2 lety

    A more useful technique is to terminate strings with a null(0), then copy string until you find the null. Tip from Bell Labs.

  • @Retrospective.
    @Retrospective. Před 7 lety

    quality fella, many thanks for investing your time into this. its appreciated.

  • @booleanenator
    @booleanenator Před 6 lety

    The easier way to deal with the binary is to convert it to hex, every 4 bits is one hex digit, so that graphic at 18:26 woud be 00, 18, 3C, 7E, 7E, 3C, 18, 00. Split right down the middle.

  • @scunnerdarkly4929
    @scunnerdarkly4929 Před 3 lety

    18:32 - There are 10 kinds of people in this world - those that understand binary and those that don’t 😄

    • @darrylsloan
      @darrylsloan  Před 3 lety +1

      Ahhh, tech humour - gotta love it. :-)

  • @EmmittBrownBTTF1
    @EmmittBrownBTTF1 Před 4 lety

    The sequence
    ld a,2
    call 5633
    is equivalent to print #2; This selects the channel for the upper screen as the current output stream. calling with a having 3 selects the printer. Using Open #3,"b" would send data through an interface 1's rs232 port, if LPrint.... or Print #3 is used, like wise if ld a,3; call 5633....

  • @TheRaticide
    @TheRaticide Před 7 lety +1

    Awesome stuff, man. I've been meaning to make a Speccy game for years, but the Next is a good excuse to finally do it.

  • @richardcoldwell9223
    @richardcoldwell9223 Před 7 lety +1

    excellent tutorial,looks like the rest of my day is going to be spent making a connect 4 board😀

    • @croccy22
      @croccy22 Před 7 lety +1

      My other half thinks I'm getting programming lessons from Colin Turkington. If you watch British Touring cars you'll understand lol :).

    • @richardcoldwell9223
      @richardcoldwell9223 Před 7 lety +1

      finally got my board working correctly. Its not the most elegant code but it works. Looking forward to the next tutorial.
      drive.google.com/file/d/0B-clecJ31PPVeEhQRzdXVDJYUnM/view?usp=sharing

  • @Nation1A1List
    @Nation1A1List Před 3 lety

    Hi Darryl. Many thanks for your great tutorials that I've just belatedly stumbled upon. I have a question if you wouldn't mind helping. How do you save the basic program in ZX Spin as so far I've been unable to do this? (I can save the assembler code). Best regards, Bob

    • @darrylsloan
      @darrylsloan  Před 3 lety

      There is a way, but I forget. It involves loading a virtual tape into the emulator, setting it to record, then using SAVE from BASIC. You can, of course, just use the snapshot feature to save the entire virtual Spectrum's memory as a .sna file that can be loaded back in.

  • @Daeve42
    @Daeve42 Před 7 lety +6

    Trying to figure what the routines are that you "call" 5633 and 8252, eventually led me to this book which seems to be a decent reference guide (not all understandable by me yet!) -
    wos.meulie.net/pub/sinclair/books/s/SpectrumOperatingSystemThe.pdf and Paul Land's SpeccyVirgins site of links.
    What resources do you use for reference (or is it mostly rememebered)?

    • @AstAMoore
      @AstAMoore Před 7 lety +3

      If you want to know in detail what the ROM routines do in a Spectrum, I highly recommend _The Complete Spectrum ROM Disassembly_ by Ian Logan and Frank O’Hara. There’s a fully searchable online version as well: skoolkid.github.io/rom/index.html

  • @luicyfer3283
    @luicyfer3283 Před 2 lety +1

    Hello, thank you for the great job you're doing with this. I have a question, is there a way to print out a memory's value ? I mean if i poke 32000,144 how can i print out the value (144) ? TX

    • @darrylsloan
      @darrylsloan  Před 2 lety

      Thanks. Tricky problem. Here's how I would tackle it (but there might be an easier way, as my Z80 knowledge isn't comprehensive). You'd have to do a number of checks, such as: Is the number greater than 199? Then print "2", else is the number greater than 99? Then print "1". That takes care of the hundred's column. Then do a similar piece of logic for the tens, then the units. I'm summarising, but you get the idea.

    • @luicyfer3283
      @luicyfer3283 Před 2 lety

      @@darrylsloan thank's. i thought, better, i was hoping there was some callable routin somewhere in the z80 to do so but writing it. I already wrote it for the 8 bit number, working on 16 bit now.
      Greetings

  • @huynhthanhphong1136
    @huynhthanhphong1136 Před 2 lety

    how did you do it can you share with me , thank you

  • @Daeve42
    @Daeve42 Před 7 lety

    Thanks!

  • @nihonam
    @nihonam Před 7 lety +2

    What does 'rst 16' line do?

    • @pev_
      @pev_ Před 7 lety +1

      Strictly speaking, it does not. The RST x (RST comes from Restart) instruction behaves like a CALL x, but the x (if expressed in decimal) can only be from 0 to 56 and only a multiple of 8. It is a shorter and quicker instruction for calling one of eight locations (0,8,16,...,56) at the beginning of the memory space. It is then the ROM that is in the Spectrum where the address 16 has a jump to a routine (further in the ROM) that prints one character (defined by the A register) to where ever is the current position.

    • @JasonMasters
      @JasonMasters Před 6 lety +1

      Basically what pev said. The RST (restart) instruction was intended to be used by interrupt controller chips so that they could send a single-byte instruction to the CPU to tell it how to handle the interrupt.
      Programmers quickly realised that the instruction could also be used as a single-byte CALL instruction (the CALL instruction requires 3 bytes) and so make your program smaller (an important consideration in the days when computer memory was small and expensive) and slightly faster (only having to load one byte instead of three to CALL a subroutine).

  • @ImperatorGrausam
    @ImperatorGrausam Před 5 lety

    Why exactly did you add "!" into the accumulator? I'm new to ASM and want to program stuff on my MSX.

    • @darrylsloan
      @darrylsloan  Před 5 lety +1

      My intention is to print an exclamation point to the screen. In the ASCII lookup table, "!" is character 33. So LD A, "!" is the same as typing LD A, 33. The assembler will translate anything in quotes for you. I chose "!" merely because it is the first printable character after a space (32).

    • @ImperatorGrausam
      @ImperatorGrausam Před 5 lety

      @@darrylsloan Ah. Thank you. But what I should've said is, what is the point of the accumulator? What does it do?

    • @darrylsloan
      @darrylsloan  Před 5 lety

      @@ImperatorGrausam The accumulator, "A", is one of several registers. The others are B, C, D, E, H, L. They are a bit like variables that you can use in the short-term purposes, such as addition, subtraction, moving data around. In my purpose, I'm moving the data "!" to the screen. The instruction RST 16 moves whatever it finds in the accumulator to the screen. Ultimately, you'll need a book to gain a proper understanding of all this.

    • @ImperatorGrausam
      @ImperatorGrausam Před 5 lety

      @@darrylsloan I see. Thanks.

  • @mikedench1110
    @mikedench1110 Před 7 lety

    Hey I'm using FUSE to test what I'm learning. It won't let me enter the machine code and I did type in the Basic line first.

    • @mikedench1110
      @mikedench1110 Před 7 lety

      I tried to download SPIN like you said in Part 1 but it wouldnt install said a file was missing, a dll I think.

    • @mikedench1110
      @mikedench1110 Před 7 lety

      Thanks Darryl but unfortunately Norton wont allow me to keep Spin it flags the file as unsafe and removes the dll's immediately doesnt even offer me the option to run it

    • @mikedench1110
      @mikedench1110 Před 7 lety

      Thankyou for being so helpful and quick to reply. I'll go ask at World of Spectrum they'll sort me out then I can get back to the tutorial which is the best I've yet encountered. I have written everything down in a notebook with the coding annotated explaining what it does from your narrative. This PC is a 64 bit one running Vista and perhaps thats why it doesnt like Spin?

    • @markwalker3484
      @markwalker3484 Před 6 lety

      I'm using pasmo (assembler) and Visual Studio Code on Linux to edit the assembly code and generate the binary.
      To get the assembled binary into fuse, just use the menu command: File>Load Binary Data and locate the assembly.

    • @AllGamingStarred
      @AllGamingStarred Před 6 lety

      i was wondering, where is the Rom version of Zeus (not the new exe version for windows)?

  • @365tito3
    @365tito3 Před 5 lety

    Another question I have is: Is there a way to redefine a string I defined with db? For example I set the string to "TEST" then print it then set it to "HELLO" and print it? I can't seem to find the way, since I've tried loading the address of str into HL then loading "HELLO" into the address currently held in HL but it won't work.

    • @darrylsloan
      @darrylsloan  Před 5 lety

      "Is there a way to redefine a string I defined with db?" Yes, but it's not really the right approach. You'd end up using more lines of code to do that than to simply create a new string with a new label (say string2), then replicate the code for the routine that prints a string and tweak it to point at string2. I do think I cover multiple strings in this lesson somewhere.

    • @365tito3
      @365tito3 Před 5 lety

      @@darrylsloan But replicating this code for every string I have to print looks very cluttered. I asked if there's a way to assign a string to another string.

    • @darrylsloan
      @darrylsloan  Před 5 lety

      @@365tito3 It may look cluttered but in Z80, you're going to find that things which took one instruction in BASIC, such as PRINT, take several in Z80.

    • @365tito3
      @365tito3 Před 5 lety

      @@darrylsloan Completely understand that. Just another thing. Won't just defining more and more strings take up memory? Is there a memoryfree command of sorts?

    • @darrylsloan
      @darrylsloan  Před 5 lety

      @@365tito3 You're not quite grasping what's happening yet. "call 8252" doesn't create a string. It's a ROM routine that prints data to the screen, depending on what values are preloaded into DE and BC. It's says, "Fetch the data starting at address DE and print it to the screen for next BC number of bytes." If I put 30000 into DE and 00005 into BC, then the data that is stored in 30000, 30001, 30002, 30003, 30004 will be printed to the screen, one byte/char at a time.

  • @365tito3
    @365tito3 Před 5 lety

    I tried this but it just flashed "Hello world" to the screen for a second and then returned me to the basic prompt. Where did I go wrong?

    • @darrylsloan
      @darrylsloan  Před 5 lety +1

      Have you got the PAUSE 0 instruction in your program? Listen to what I say around 2:15.

    • @365tito3
      @365tito3 Před 5 lety

      @@darrylsloan Sorry, I ran it directly from ZXSpin

  • @asktheprophet
    @asktheprophet Před 7 lety +2

    Ast A more (comments below) Peeked (excuse joke) my interest in the rest of the Restart Calls for my own Assembly notes. Here you go...
    RST ROM ‘Calls’ aka Restart Calls
    ------------------------------------------------------
    DEC HEX DESCRIPTION
    00 00 Reset/Start the Speccy
    08 08 Error restart. Also used to Invoke the ZX Interface 1
    16 10 Print a character held in the ‘A’ register to the current channel
    24 18 Collect a character
    32 20 Collect next character
    40 28 Floating Point Calculator
    48 30 Make 'BC' spaces - creates free locations in the workspace
    56 38 Maskable interrupt. Read the keyboard and update Real time clock (RTC)
    Keep for future reference!
    P.S. Your doing a great job Darryl.

  • @jasonking1284
    @jasonking1284 Před 5 lety

    Actually, there is still some compiling going on from assembly language, which the CPU doesn't directly understand to machine code, 0s and 1s, that the CPU does directly understand....... Assembly language is the lowest level language that humans can practically work with....

  • @jarisipilainen3875
    @jarisipilainen3875 Před 5 lety

    why there is no c64 with z80 cpu and rewrite kernel becouse spectrum graphic suck lol