Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Ralf »

Thanks!

I'd like to make a confession now ;) I always wanted to learn writing code for Amstrad CPC. Unofortunately out of all classic computers I can write code only for Zx Spectrum. I can't do it for Amstrad, can't do it for Sam Coupe, can't do it for MSX, not to mention machines with different CPUs than Z80 and completely different architecture.

I believe the easiest switch would be from Spectrum to CPC. With some experience at both platforms I could even maybe one day try to decompile and port some game from CPC to Spectrum ;) Or maybe not as it would turn too difficult. Anyway I'd like to try something new.

Unfortunately I never did it. I can see two obstacles - graphic modes of CPC which are quite badly documented (or at least Google failed me here) and different tools - emulators, debuggers, decompilers, art utilities, graphic rippers and so on.

So I'm really happy to see your tutorial. Don't hesitate to write about CPC. We know Zx Spectrum and I suppose there are people like me who would like to learn something new.
User avatar
R-Tape
Site Admin
Posts: 6353
Joined: Thu Nov 09, 2017 11:46 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by R-Tape »

"You probably think 64 kilobytes doesn't sound much "

Actually I wasn't!

Thanks, I will be following these. A lot of people here will be familiar with the assembly and need to know the peculiarities of the CPC, I heard the screen layout is more wonky than the Speccy's.

I'd like to see my panic style platformer (Lost Tapes of Albion/EFMB) converted to as many platforms as possible (currently Speccy, SAM, Amiga, MSX, PC and someone's working on a C64 version), the CPC may be one I can manage myself eventually.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Ralf wrote: Sat Jan 20, 2018 5:42 pm Unfortunately I never did it. I can see two obstacles - graphic modes of CPC which are quite badly documented (or at least Google failed me here) and different tools - emulators, debuggers, decompilers, art utilities, graphic rippers and so on.
The display on the CPC comes down to two chips, the CRTC which controls things like positioning on the screen, size of the displayed area and other timing issues and then the custom Gate Array, which encodes pixels based on the screen mode and handles palette selection (as well as doing ROM/RAM paging).

The CPC wiki has some pretty good documentation on how these work:

http://cpcwiki.eu/index.php/CRTC
http://cpcwiki.eu/index.php/Gate_Array
User avatar
Spud
Manic Miner
Posts: 372
Joined: Sun Nov 12, 2017 8:50 pm
Contact:

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Spud »

R-Tape wrote: Sat Jan 20, 2018 6:01 pm I'd like to see my panic style platformer (Lost Tapes of Albion/EFMB) converted to as many platforms as possible (currently Speccy, SAM, Amiga, MSX, PC and someone's working on a C64 version), the CPC may be one I can manage myself eventually.
Jaco is going to stab me to death, but I am going to convert it to the Sega Master System in that case (I've been wanting an excuse to code for that system for years). It would be also be a cool title to see on the Game Boy.
Ralf
Rick Dangerous
Posts: 2279
Joined: Mon Nov 13, 2017 11:59 am
Location: Poland

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Ralf »

The CPC wiki has some pretty good documentation on how these work:

http://cpcwiki.eu/index.php/CRTC
http://cpcwiki.eu/index.php/Gate_Array
Well, I suppose it is correct, I suppose it is thorough. But for learning it is terrible. When I opened these links I immediately wanted to run away ;) It's full of some long scary lists of names, numbers, ports, bits, palette indexes, suble differences in models and so on.

Good tutorial gives you knowledge in small doses and not throws everything at your face at once. You start from some simple things and at each step have practical examples which use only the stuff that you learnt so far.

So at this moment I'll just wait how Keith's tutorial develops. I hope at some moment he'll show how to draw a sprite/tile in assembler on CPC.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Yes, it's more documentation than tutorial, Grimware's site was a bit better in that regard but it's disappeared for now at least. Hopefully Keith's videos will fill that niche a bit better. Generic sprite routines on the CPC are trickier to show than on the Speccy, because it depends a lot on how you arrange the screen ram and there are various tricks which work better in some circumstances than others.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Pretty good intro to the screens video. I think maybe it might have been instructive to scroll the screen slightly on the CPC to show how things start to get weird and possibly fiddle with the CRTC screen size registers - it can be quite instructive to show that making a 64-byte (32 characters in Mode 1) wide screen gives you a similar advantage in next line calculations to the Speccy. Those are effects that can be quite easily demonstrated from BASIC too, whereas some of the more cunning CRTC effects require a fairly deep understanding of the hardware and probably a smattering or two of assembly.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Yeah, I figured that was pretty much your line of thought. I was thinking more in terms of "If you're playing around in BASIC and the screen scrolls, then weird stuff like this happens, so just remember to do a MODE first" rather than necessarily an in-depth explanation of how you could use it in a game. Particularly be cause the advice of doing a POKE &C000,x to see the effect is a good thing, unless it's not where you think it is!
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Nomad »

I must admit I would love to be able to port crapchess to the MSX/CPC.

Are there any good books about assembly for the MSX, I found a few books but they were not so practical (much like the spectrum). If I can find a rom disassembly that goes into some detail how the system handled different tasks would be great. There also does not seem to be many assembly books in English for the msx. (well not on the net).

That is one thing the spectrum (and atari/commodore/apple ii) has going for it - lots of info out there. MSX is such a nice platform if I could only figure out how to use it :lol: CPC is more of a abusive relationship I think, I would have to think hard about attempting a port for that beast.
C.Born
Manic Miner
Posts: 202
Joined: Sat Dec 09, 2017 4:09 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by C.Born »

hi Keith,

may i say that you use a bit to much table lines? i work on 1920x1080 and i see a lot of red on black between fine white lines..
Image
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Nomad »

Hey Keith,

I have a 23" monitor, and the text in the videos is so tiny its unreadable. Is there not some way you can zoom or maximise the window when your showing the code?

Good on you for having a go at the tutorials but unless your watching it on some huge screen / projector I don't see how you can follow along.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Nomad »

I am always curious how other people go about development.. can I ask, do you just go straight in and start coding the projects or do you go through an analysis phase/problem definition kinda deal?

Would have thought doing multi platform projects there would have been more need to study the problem first before jumping in.
User avatar
PeterJ
Site Admin
Posts: 6854
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by PeterJ »

Many thanks [mention]keith56[/mention] for doing this. You have obviously put a lot of time and effort in. It's all very good stuff.

Would it be possible to calm down the text colours on the website? It's all rather bright!

I could not get your Enterprise 128 page to load

http://www.chibiakumas.com/z80/enterprise128.html

There is a type up of a Enterprise 128 Assembly Language book here. If you use Google translate its possible to get the grasp of it:

http://www.ep128.hu/Ep_Konyv/Gepi_kod.htm

Peter
User avatar
PeterJ
Site Admin
Posts: 6854
Joined: Thu Nov 09, 2017 7:19 pm
Location: Surrey, UK

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by PeterJ »

Just found 'Print Mode' That looks much better!
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Nomad »

I would use the whole screen to zoom in on the area that you are currently using and not the whole desktop. That way the font is large enough to be seen easily. Unless you got good eyesight its very difficult to see what is going on with a regular screen.

For example, this fella has the open window zoomed.

[media]https://youtu.be/qBFJgoceljQ[/media]

Length is fine, better to cover something properly than gloss over something important.

I wouldn't worry about focusing on the Amstrad, as long as eventually you are going to cover the memory map, screen layout, and rom calls for msx I think its not an issue. I think that is the interesting point about doing the ports is showing how to find the equivalent rom calls, adjust the memory pokes/peeks for the various platforms. I don't think that has been covered in a youtube tutorial. Sure it all comes down to RTFM in the end but to show the process I figure that will add a lot of value. :lol:

Nice work so far by the way, it must take a lot of time to prepare.

Post edited by admin to change to new media tags.
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Nomad »

Nice work Keith,

One thing I have noticed that is a 'barrier to entry' with the CPC stuff is none of the books seem to have been scanned (well English language ones anyway). How are you supposed to figure out the system without the books?

I know cpcwiki is there but its not the same as having the primary source material to look at. Were the books really that worthless that nobody thought it was worth preserving them?

The CPC wargaming book looked pretty interesting but so far as I can tell its not been preserved anywhere.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Nice. I think maybe you missed a trick using self modifying code in the example - it might have been slightly more instructive to pre-stage the HL' register with the address of the colour values and then just let the ISR reset it as and when it needed to. That might have shown another one of the benefits of the alternate register set in that kind of scenario, they can persist values for the ISR allowing you not only to avoid having to PUSH/POP the registers used by the main program, but also to avoid having to reload values needed by your interrupt code.
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

keith56 wrote: Sun Mar 11, 2018 7:18 am It's quite curious how the different systems use the shadow registers
in my game, I use DI/EI when I use the shadow registers in a normal loop, but two EXX 'es and DI/EI are pretty much the same speed as a PUSH/POP, so there's rarely any cases it's worthwhile.
it seems interrupt handlers on most do not alter them, but the CPC does, I wonder what the 'best' way to use them overall is?
I think the Amstrad is using them pretty much as Zilog intended, as a sort of precursor to kernel/user mode separation we see on modern CPUs with one set of registers that "belong" to the system and another for user mode. That best explains the rather "all or nothing" swap arrangement, with AF really being singled out as a way of transferring simple values between the two. It's often difficult to make really good use of them under normal cicrumstances (for the reasons you indicate) but often you see more use in cases where a subroutine needs to juggle just ever so slightly more values than normally fit - that does normally preclude from using them in interrupt handlers though (although sometimes using push/pop there instead is preferable if you don't need the full register range).
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Wall_Axe »

that is pretty interesting thanks

so if a digit is zero and we subtract one, the result will be 255
so does daa fix the result to 9 (and activates the carry flag)?


so daa also allows someone to use nibbles?
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

If A was 0, and you subtract 1 (so it's now 255), DAA would reset it to 99 (with Carry).
Wall_Axe
Manic Miner
Posts: 492
Joined: Mon Nov 13, 2017 11:13 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by Wall_Axe »

ohh you mean '9 and 9' in 2 nibbles
this does make outputting numbers to the screen a lot easier
AndyC
Dynamite Dan
Posts: 1387
Joined: Mon Nov 13, 2017 5:12 am

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by AndyC »

Wall_Axe wrote: Thu May 10, 2018 1:58 am ohh you mean '9 and 9' in 2 nibbles
this does make outputting numbers to the screen a lot easier
Yup. BCD is very handy when it comes to numbers you display on screen.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by RMartins »

keith56 wrote: Sun Mar 11, 2018 7:18 am It's quite curious how the different systems use the shadow registers
in my game, I use DI/EI when I use the shadow registers in a normal loop, but two EXX 'es and DI/EI are pretty much the same speed as a PUSH/POP, so there's rarely any cases it's worthwhile.
it seems interrupt handlers on most do not alter them, but the CPC does, I wonder what the 'best' way to use them overall is?
I believe you are not equating all the variables here, and mixing a few concepts.

DI/EI (4T/4T), just controls if maskable interrupts are enabled or not.
Nothing to do with preserving register contents. You can still receive an NMI in the middle of the loop.

NOTE: This is one of the reasons, why assembly tricks using the stack register (SP) and PUSH/POP can be dangerous on machines that have support for NMIs. Any ZX Spectrum can have NMIs being generated, by an external interface, like DivMMC for example.

EX Af, Af' (4T)
EXX (4T)
These are used to SWAP between the register banks, they do not save anything anywhere.

These were designed/created for REAL TIME applications, where time spent inside an interrupt routine is crucial, and must be very low, so these systems, usually, reserve the shadow registers, to be used inside the interrupt routine, to avoid having to backup the registers before using them.
This obviously reduces the number of register you can use in regular programming.

PUSH RR/ POP RR (11T/10T)
These actually, allow you to save the registers on stack, or somewhere else you might move the stack to.
However, to save the registers, and then restore them, you will need a lot of operations:

Code: Select all

PUSH AF
PUSH BC
PUSH DE
PUSH HL

... do the interrupt magic here

POP HL
POP DE
POP BC
POP AF
For the same registers, that you use EX AF, AF and EXX, you will need:
4 * 11T + 4 * 10T = 44 + 40 = 88T

Which is a lot different from 4 + 4 = 8T, for the Swap instructions.

NOTE: I did not include PUSH/POP for IX and IY, to be fair on the comparison.
User avatar
RMartins
Manic Miner
Posts: 776
Joined: Thu Nov 16, 2017 3:26 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by RMartins »

Just a correction, for the Swap instructions, we need 4 instructions, not 2:

Code: Select all

EX AF, AF'
EXX

... do the interrupt magic here

EX AF, AF'
EXX
Which is ( 4 + 4 ) + ( 4 + 4 ) = 16T
Still a long way from the 88T for the PUSH/POP solution.
User avatar
g0blinish
Manic Miner
Posts: 281
Joined: Sun Jun 17, 2018 2:54 pm

Re: Beginner's ASM Tutorial: Multiplatform Z80 ASM development videos... with vampires!

Post by g0blinish »

RMartins wrote: Thu May 24, 2018 6:41 pm Just a correction, for the Swap instructions, we need 4 instructions, not 2:

Code: Select all

EX AF, AF'
EXX

... do the interrupt magic here

EX AF, AF'
EXX
Which is ( 4 + 4 ) + ( 4 + 4 ) = 16T
Still a long way from the 88T for the PUSH/POP solution.
unsafe solution. If you are using music player into interrupt, alt pairs may changed
Post Reply