Simulating protected mode in the Z80 [video]
youtube.com
youtube.com
If only I had had the internet, maybe I would have stumbled on the concept of an "assembler". Not sure if it had been more fun? In any case, I did not find the protected mode.
Because, unless I'm misunderstanding the video, it doesn't exist until you add a whole bunch of external hardware (which is why the video is clickbait - a fact he acknowledges later.)
Why mind this if the hardware to add is the same level of technology like Z80 itself? I would be glad to build a computer as advanced as possible combining some Z80s and additional HW.
But it's not "the Z80's protected mode" - it's "the Z80 + an extra circuit to emulate protected mode". It's a super clever hack, yes! But filthy clickbait also.
The Tiki-100 is an obscure Norwegian 8-bit computer from 1984, also Z80-based. It had nice graphics for its time, with 16 colours from a 256-colour palette. However, it was very hard to use productively, since the machine had no video sync interrupts.
What the guys in the demogroups figured out, was that it did have parallel port interrupts, and with a tiny hardware mod (just a wire from the expansion port to the parallel port), they could "steal" those for Commodore 64-style raster interrupts.
That it wasn't something usual with microcomputers of the time wasn't because it would have required some uniquely clever design. Rather it had to do with them being single-user/single-task, with simple operating systems where programs were expected to have full access to the machine.
A common use for multitasking in the 8-bitter era was print spooling; it was very inconvenient to have to wait for your document to finish printing before you could continue editing! People frequently bought external hardware printer spooler boxes to connect between their computer and printer because of this. Similarly, duplicating floppies was pretty inconvenient because you couldn't do anything else while it was happening, even if you had four floppy drives like I did, with literal megabytes of storage space available to read porn or play video games while the floppies were copying.
Historically on larger machines it was also common to use multitasking to overlap very slow disk I/O with useful computation. (The alternative is to use asynchronous I/O and write your program as an event loop, like a game or Node.js, or to do your I/O from interrupts, which is close to multitasking.) In theory this could have been useful on 8-bit micros as well but I don't think I saw any cases of it actually happening.
https://en.wikipedia.org/wiki/Kludge
It's on display at the Paul G. Allen Living Computer Museum.
https://sites.google.com/site/mthompsonorg/Home/pdp-10/pdp-1...
https://donhopkins.com/home/catalog/images/mc-console.jpg
Lars Brinkhoff has taken photos of the KL-UDGE blinken lights panel and naked wire wrap boards:
https://twitter.com/larsbrinkhoff/status/1128601896619524097
>Photo 6/7: KL-UDGE lights panel
>Photo 7/7: KL-UDGE boards. Real-time time of day clock?
Was a pretty popular machine - sold 5.7 units worldwide. But probably only a tiny fraction actually used the CP/M mode that used the Z80.
I never understood how the English, and sometimes the Dutch, seemed in general (looking at their results) to be able to learn many times faster than amateurs in other territories. Sometimes with borrowed machines! "They gave me this, and after some weeks I had my first videogame working". I guess/ed it may have been a matter of human network - of being able to find knowledgeable people in the neighborhood to learn and exchange -, but it seems to have been often a solitary effort. It seems in a way like a talent, like that of the Scots for inventions, but there have to be keys that made kids talented coders through their own natural grit.
Others have had difficulties in finding documentation alone, not to mention competent peers.
Edit: corollary, some of the best new art happens in the most restrictive environments. Maybe it’s a case of living at the extremes?
> some of the best new art happens in the most restrictive environments
You reminded me of Paul Buchanan, frontman of The Blue Nile, revealing that they would compose and rehearse standing shoulders to a wall in a narrow corridor in a house in Glasgow - that was the room they had.
I grew up real poor and it made me hungry. I think that's where a lot of the hacker mentality comes from, one form of poverty or another.
I am hoping to raise children soon and I am wondering how to help them to feel a hunger for the world without suffering in the same way I was raised. It's hard for me to imagine how they'll learn to thirst for the experience of the world if they don't have the same socioeconomic pressures, but I think that will be one of my most profound growing experiences in this life. I intend to accept them for who they are and to try to give them as much opportunity as they can stomach.
If you have little to work with, adding stuff often forces you to remove or shrink something else.
I suppose there is something in our culture. A lot of inventions and science has come out of the UK.
There's also an (I assume) cultural phenomenon of tinkering in the garden shed.
I suppose there's the Protestant work ethic, the ethic of self improvement, a general acceptance and perhaps celebration of odd balls and tinkerers.
It the field of computing, it probably helps that we speak the same language (ISH) as the us, where a lot of this tech came from, but didn't have the money to just buy solutions.
But I don't really have any experience of other cultures in this context to say whether these things are unique.
Then again, I think working through untranslated English material for my computer hobby helped me gain language proficiency more quickly than many peers.
Of course in the end you have computing skills and a second language.
Slightly off topic question though. Are programming constructs based around or influenced English making it easier to learn as an anglophone?
Would (true)if be more common, or do{}while(true) be more common if English weren't the Lingua Franca?
I know you could find examples of these in many languages, but they aren't 'standard'
Paradise! (No, really, that is respectful and intelligent - if in general people can perceive that "the guy has something", that is already a big social asset.)
> other cultures
Other cultures may be quite diffident and promoting different "values" - in the streets you will more often find "socialites". At the extreme, a Siberian once told me: "They would go and beat up the different. «You are different», they would say, and beat you up".
I don't think that's the case, I think it's that the achievements form the English and the Dutch are shared on the English speaking internet so it's more easily to run into them VS for example, the German speaking hackers who, at least in the past, only shared their work on the German speaking internet instead, so their achievements are less likely to get international visibility.
It's the same with other cultures that have a huge population/market share. If you'd venture on the Russian speaking part of the internet, you'll find a gold mine of hacks, cracks, reverse engineering, and crazy software that flies under the radar.
We are talking about the scene in the early '80s.
Products were sold in shops and via mail and were advertised on magazines. Remote networking was on Bulletin Board Systems - and with limited diffusion. The hacker coding his¹ product probably did not easily have those things around.
¹(A 'his' that calls for a pluralized 'her', out of respect to a group that created a closed-doors women-only community in Ireland and produced "women-only" themed adventure games: they were in a way similar to a sect but sold their own software as part of the funding - I cannot remember names right now. I believe there exists a photo of a group of coders with two ladies dressed in Victorian costumes (which apparently were the uniform in said community), after a social gathering. This gives an idea of what could contribute to the scene. Edit: found: it was the "Silver Sisterhood", in County Donegal - https://en.wikipedia.org/wiki/Silver_Sisterhood )
i.e. BBC Micros came with an assembler so it's the kind of thing BBC users would tell CPC464 users about and they would then buy third party.
Why did the BBC Micro have an assembler? Well the people made it started out in a university setting with access to all sorts of things that they wanted on their small computers.
E.g. BBC Micros had networking before most other 8-bit machines simply because the original developers had used it in a research lab.
In other markets you might just be working on your own and so wouldn't know about things like networking because you wouldn't have an immediate need for it.
To quote William Gibson, the future is here already it's just poorly diffused.
I still had to know about it. If I'd never found Rick Saada's experiment in win32 packaged as a game for a dollar, would I know about any of this? I wonder if the growing availability of the internet has closed the gap any.
It's now in the public domain and should run under Wine on Linux, as well as 32 bit versions of Windows:
I made a Tetris clone in Pascal, running in a 286 machine with 1 MB of RAM. It took me about a week of coding, and it ran as a single segment program, so it was limited to 64Kb of memory.
For me, this was the moment I learn about for loops. The program was a big collection of for loops.
I could have made some original game, but being Colombian, living in Bogotá, no one would have bought it. Everything we had was pirated, so there was no incentive to actually publish anything.
People would swap games on disk, and there was less pressure to learn how the underlying system works.
Having a disk drive also enables more complex, larger games, which would be harder to produce as a lone programmer.
Contrast this with the UK - we had much less money, it was common to type games in from magazines, which is how a lot of us learned programming.
We mostly had to make do with tapes, which limits the size of a game and its sound and graphics to physical RAM. It was entirely possible as a lone programmer to create a commercial level game with a few weeks of late night hacking.
None of my peers did any programming, and since Denmark does not have flat-rate local calls, calling up via modem to connect to a BBS was never really an option -- so there was really no-one to share with. That is certainly somewhere were the internet would have been a plus.
I did know about the concept of "assembler", I just wasn't able to obtain one.
I started with the 6502 on the C64, the Z80 came much later when i wrote some trainer patches for Gameboy ROMs.
LD HL,nnnn: 21 nn nn
LDIR: ED B0
JMP nnnn: C3 nn nn
CALL nnnn: CD nn nn
RET: C9
...etc..., and probably dozens more after getting back into the groove :)
Other Z80 computers did have pretty capable assemblers, even with simple macros as I recall.
I cobbled together a basic understanding from various machine code listings (Toni Baker, Your Sinclair IIRC), and my "assembler" was paper, pencil and a FOR/INPUT/POKE loop...
My uncle loaned me a Sharp MZ700 one summer, its manual had a detailed breakdown of Z80 opcodes (in mere 4 pages) which was a revelation to me, and an annotated monitor in assembler. https://archive.org/details/sharpmz700ownersmanual (p160-)
I think the Jupiter Ace manual might have had that too, but it's been a long time since I've even seen my copy of that.
I used the "Programming the Z-80" book by Rodney Zaks, which is still on my bookshelf. Some manuals just can't be disposed of!
From memory I recall my favourite instruction - LDIR (Z80 block memory move) is EDB0, and JMP is CA.
Slightly more on topic, I piggybacked a 2716 EPROM onto the back of the TRS-80 ROM so I could get to the previous hard-coded RST locations and interrupt vector of the Z80 processor. In a nutshell, that allowed me to stop/debug/hack running programs without software being able to prevent me.
Fun times.
I have that and the 6502 book by Zaks also. I read those books when I was a teenager as if they were tomes filled with wisdom of the ancients. I protected them with plastic book covers and wrote my own notes in the margins in pencil. I worked a Saturday job when I was 16 and spent the money on them. At the time they were so expensive!
(The book also includes a discussion on VLIW-style microcoding, a plea for more registers, and a note how a population count instruction may be worth including despite its situational utility because of how easy it is to do in hardware compared to a software emulation. That team did one of the first chess programs, though, so it’s not surprising popcount came to minds easily.)
I didn't have a disk drive, only the standard cassette deck, so before selling it to me he had to slightly rewrite the assembler to support loading and saving programs to cassette.
In the end, the syntax was not exactly like in the Rodney books. Some examples worked, some not, so I resorted quite a bit to hand assembling myself.
Couldn't write BASIC to save my life, but Z80 Assembler using MAXAM and the 6128 detailed manual and I flew along happily.
https://www.cpcwiki.eu/imgs/e/e2/Maxam_Manual.pdf
Edit to add: Found the Firmware Manual
https://archive.org/details/SOFT968TheAmstrad6128FirmwareMan...
(I forgot it all. It's been 35 years ago last I did this and high school mostly crowded it out of my memory. But C9 was RET, that I still remember. ZX Spectrum, for me. But Z80 manual (dis)assembly nonetheless.)
I had Discology, it had built-in disassembler. So I wrote a binary file like 00 00 01 00 00 02 00 00 03... and disassembled, and put in a notebook what code produced what command (then adding different arguments than all zeros, then finding longer opcodes and generating a new file for them...)
Now I wonder if you meant CPC464 or CPC664 :)
(Probably the former, as the 664 was relatively rare, at least in my experience. I’m not sure I ever saw one.)
Registers were numbered [0-7] b,c,d,e,h,l,m,a if I remember right. h and l were 'high' and 'low' part of the 16-bit indirect 'm' memory address.
So in octal, 134 was "mov e,h".
You now know 1/4 of the entire Z80 instruction set!
I joined the fray later, in the early 1980's. I had access to public libraries, computer magazines like Byte and Creative Computing, computer stores with software, books and magazines, dial-up BBSes, computer expo events, enthusiast meet ups and swap meets, ...
I used an interactive instruction-at-a-time assembler inside the Apple II+ ROM. This was a small level above entering hex. MS-DOS had a similar facility in DEBUG.COM.
Eventually I got my hands on a copy of Randy Hyde's LISA (Laser-Systems Interactive Symbolic Assembler), and was able to make larger, more complex programs.
At 12:10: "Nonetheless, I have made a clickbait video, the type of video that I hate to see" the meta goes deep :D
The general consensus seems to be they wish they didn't have to, but you've got to earn a living somehow
That's one reason why I will likely never become a parent. I don't want to inflict on anyone the need to somehow earn a living in a world of too many other people trying to do the same.
Though if you're doing this, highly recommend not letting them realize you're fairly well-off until they're old enough to know the value of a buck/peso/ruble/euro.
There are even more secrets that were discovered in recent years that aren't in the talk.
Could you give details?
I haven't researched any of those yet, but many have and did publish those results ! redcode's Z80 emulator seems to be the most up-to-date on those subjects: https://github.com/redcode/Z80/blob/master/THANKS (has many links to the various reverse engineered parts).
> In 1975 Federico Faggin who had had worked at Intel on the 4004 and its successors left the company and joined forces with Masatoshi Shima [] from Zilog. At their new company Faggin and Shima designed a microprocessor that was compatible with Intel’s 8080 (it ran all 78 instructions of the 8080 in almost the same way that Intel’s chip did)1 but had many more abilities (an extra 120 instructions, many more registers, simplified connection to hardware). Thus was born the mighty Z80! and thus was the empire forged
Not to discredit author's huge effort on this, but that part alone lowers the value of this video orders of magnitude solely because of how the video was titled.
I wish they titled it "Make Z80 protected mode capable with a simple hardware change". Setting expectations right is important.
And yes, it's clickbait.
It’s like the tweet- and video-ification of online discourse have destroyed peoples’ reading comprehension. (On reflection, though, the average person was never good at it. At least it’s mostly confined to annoyances on the Internet instead of, like, political elections or mob violence, right? Right??)
Sounds like he is a good EE but was a bit frustrated with the growth of his channel numbers. Think his audience will give him a freebee this one time but do it again and they will nope out.
It would be possible to add more hardware to detect these instructions, so it could then trap and emulate them.
Zilog actually designed their peripheral chips to handle the RETI (return from interrupt) opcode specially. On the Z80 itself it does the same thing as a normal RET, but other chips can detect it on the bus and treat it as the signal that their interrupt handler is finished.
I also recall reading about some hobby project to add a PC-relative addressing mode to the 8080 or Z80. A redundant opcode like "MOV A,A" would be used as a prefix, which caused the external hardware to add the program counter to the immediate operand of the following instruction. Can't find it right now.
I guess it’s a short step to looking up memory addresses against a bitmap for validation. I couldn’t tell from the video if this is what he did. Cutting the addresses into pages would let you save or add more levels and I guess you could implement a TLB similarly.
6502 doesn't have a pin for "IO space" but you just pick your MMIO range e.g. 0xCnnn on the Apple ][ and a NAND gate on the 2 MSBs and a 3-input OR/NOR on the output and the next two bits gives you effectively the same signal. (or an OR gate on bits 12&13 plus a 3-input AND/NAND on bits 14&15 and the output).
It was common to use 6522 VIA 8 bit output ports to bank switch one or two 4k ranges to allow each such 4k range to access 256*4k = 1 MB of RAM. You could use a 16x8 bit SRAM to do the same thing for the whole address space.
transcript >>> video
This section might also relevant even if you don’t do anything with hardware; it might give some insight into how the Z80 operates. Besides, it took me hours to draw this.
I feel so validated because I myself have included content in user manuals for the pretty much the same reason.
That PDF isn't what the video is about though.
It's not really that much click-bait either. "Method to implement Z80 protected mode discovered after 40 years" would be more correct, but that's too convoluted for YouTube's algorithm.