Standard ROM entrypoints?

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Standard ROM entrypoints?

Post by hjalfi »

So I've got this compiler: http://cowlark.com/cowgol/

It's a self-hosting fully compiled language for the Z80 and 6502, where the Cowgol compiler is written in Cowgol and you can (technically; it's far too slow to be feasible) rebuild the compiler on the target machines.

Now that I own a mostly-working Spectrum 48kB I'd like to port it to generate Spectrum executables. The compiler needs a fast random access filesystem and a proper DOS to run on a target machine, but cross-compiling for a target machine is much easier; the minimum functionality necessary is the ability to write characters to the screen. (The entire Commodore 64 runtime, for example, is 16 lines:
https://github.com/davidgiven/cowgol/bl ... untime.cow)

Does the Spectrum have reasonably portable standard system calls for doing things like printing text, etc, from machine code programs?

I've found rst $10 for printing a single character, and I've seen references to things like $0daf for clearing the screen, and I've found the huge list at http://skoolkid.github.io/rom/maps/routines.html, but that doesn't distinguish between internal BASIC routines and the nominally public ones (or tell me what the register requirements are). Does such a thing exist?
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore »

hjalfi wrote: Thu Jul 19, 2018 11:05 am I've found the huge list at http://skoolkid.github.io/rom/maps/routines.html, but that doesn't distinguish between internal BASIC routines and the nominally public ones (or tell me what the register requirements are). Does such a thing exist?
First, the document at that link is not just a “huge list,” is the disassembly of the Spectrum’s ROM in its entirety. It does tell you what the register requirements are most of the time. Second, there’s no such thing as “nominally public” routines in the Spectrum’s ROM. The BASIC interpreter and the operating system are pretty much interconnected.

I’m not entirely sure what you’re trying to achieve. There are many Spectrum-specific Z80 assemblers out there for many platforms. Unless you’re hell-bent on using the output of a general-purpose Z80 assembler and then loading it into the Spectrum manually somehow.

If you’re using an emulator, it’s normally not difficult—most will accept BIN files. Not sure how you’re planning on loading it into a real Spectrum, though. You best option is to import it into an emulator, save to a tape file from it, and then play it back into the Spectrum.

Sounds like a lot of self-inflicted pain. You’d be better off finding an assembler that can generate a TAP/TZX file for you, which you can then easily load into the Spectrum the usual way.

I apologize if I completely misunderstood your original motives, though.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

I don't have an assembler. My compiler generates binaries directly. I already know how to turn these into loadable TZX images which can be used on emulators or real hardware; that's not the difficult bit.

I know that the huge list is a disassembly of the entire ROM, which is why it's not very useful to me. I don't want a warts-and-all analysis of the ROM; what I want is a curated set of useful entrypoints which can be used from machine code, which I can use to implement my language's runtime library. In particular, I need to know what BASIC's expectations are when I call these. This shouldn't be controversial --- anybody whose tried to call BASIC from machine code will need to know this stuff. I also need to know which entrypoints are stable across ROM versions so that I can produce reasonable portable binaries.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore »

Okay, let me see if I got this straight.

You’re not planning to program in assembly, only in Cowgol. Okay, that part is now clear. What I’m still fuzzy about is this: “anybody whose tried to call BASIC from machine code will need to know this stuff.” I don’t know anybody who does this (aside from the people at Hisoft). The normal course of programming is to either ignore the ROM and system variables altogether, or to use a few ROM calls for specific tasks. The latter implies the knowledge of the Spectrum ROM, as well as the differences between different ROM versions.

Machine code routines can be called from BASIC, in which case, the BC register will often be the “exchange point.” For example, if you have the following MC sitting at address 40000:

Code: Select all

	ld bc,12345
	ret
Then running PRINT USR 40000 will print 12345. The same result will be the output of the following BASIC program:

Code: Select all

10 LET a=USR 40000
20 PRINT a
You don’t really “call BASIC from machine code” per se. You make calls to the various entry points in ROM. Each will expect different parameters, depending on the routine or even an entry point. (It’s common to use entry points that are different from “normal” BASIC entry points to speed things up, for example.)

As far as portability is concerned, indeed, a few modifications to the original 48K ROM were made in 128K, +2, and +3 ROMS, and some entry points moved. Mostly, the previously empty spaces were used to hold additional routines (part of the reason a few games became incompatible with the 128K and +3 Spectrums). There were also ROMs produced for different languages (notably, Spanish, French, and I think German), which presented further compatibility issues.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
User avatar
Guesser
Manic Miner
Posts: 639
Joined: Wed Nov 15, 2017 2:35 pm
Contact:

Re: Standard ROM entrypoints?

Post by Guesser »

Ast A. Moore wrote: Thu Jul 19, 2018 2:57 pm What I’m still fuzzy about is this: “anybody whose tried to call BASIC from machine code will need to know this stuff.” I don’t know anybody who does this (aside from the people at Hisoft). The normal course of programming is to either ignore the ROM and system variables altogether, or to use a few ROM calls for specific tasks.
I think it's those specific tasks he's asking for a list of :P
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore »

Guesser wrote: Thu Jul 19, 2018 3:29 pm
Ast A. Moore wrote: Thu Jul 19, 2018 2:57 pm What I’m still fuzzy about is this: “anybody whose tried to call BASIC from machine code will need to know this stuff.” I don’t know anybody who does this (aside from the people at Hisoft). The normal course of programming is to either ignore the ROM and system variables altogether, or to use a few ROM calls for specific tasks.
I think it's those specific tasks he's asking for a list of :P
Heh. Well, he’s in for a surprise, then. I’ve seen people use the “entry point” at $33c3 for the LDIR/RET combo. Not sure what the point of it was other than obfuscation. :lol:
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

Re not wanting to do this much --- so far every single Spectrum machine code tutorial I've found has used the Basic entrypoints for drawing on the screen; plus I've found two different Forth interpreters which do it, for all their I/O; plus a Pascal interpreter which does it; etc, etc... although interestingly z88dk doesn't, preferring to implement its own console driver instead.

https://chuntey.wordpress.com/tag/printing/

I can infer pretty much everything I need from the above article, but it's far too fuzzy on things like which registers I need to preserve, stack status, etc. (e.g. which routines need the system variable pointer in IY? Does anything touch the alternate register set? Flags? Interrupts?)

I was hoping for some actual hard information!
Heh. Well, he’s in for a surprise, then. I’ve seen people use the “entry point” at $33c3 for the LDIR/RET combo. Not sure what the point of it was other than obfuscation.
Probably for speed. When the Z80 executes LDIR it reads and decodes the instruction every time a byte is processed, even though it's always the same instruction. On systems where ROM is faster than RAM (the section of RAM between 0x4000 and 0x8000 is slow on the Spectrum, because it's shared with the video system, right?) then calling out to ROM for memory copies will mosty be a win.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore »

hjalfi wrote: Thu Jul 19, 2018 5:45 pm I can infer pretty much everything I need from the above article, but it's far too fuzzy on things like which registers I need to preserve, stack status, etc. (e.g. which routines need the system variable pointer in IY? Does anything touch the alternate register set? Flags? Interrupts?)

I was hoping for some actual hard information!
Again, there are no “universal” entry points—each programmer uses mostly arbitrary points based on his particular needs. In addition, some entry points were moved around in different Spectrum models. That’s why some BASIC compilers will work on some models but not others (hence my mention of Hisoft).

The IY register is best left alone or, at the very least, preserved, if one intends to return to BASIC from machine code. Yes, quite a few routines use the prime registers (mostly HL′, see this, for instance), so they too need to be preserved. Interrupts are enabled most of the time while the BASIC is running and flags, too, are used extensively.

The Spectrum ROM is not a collection of libraries. It’s a mishmash of a BASIC interpreter and an operating system with quite a few interdependencies. Those tutorials you refer to, simply use a subset of “most commonly used shortcuts” to ease a novice into programming in languages other than Sinclair BASIC. There’s no secret set of standard entry points circulating among the few initiated (even it there were, I couldn’t tell you—I took an oath).
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Bizzley
Microbot
Posts: 124
Joined: Thu Nov 16, 2017 10:47 am

Re: Standard ROM entrypoints?

Post by Bizzley »

hjalfi wrote: Thu Jul 19, 2018 5:45 pm I was hoping for some actual hard information!
Everything you need to know is here :

https://computerarchive.org/files/comp/ ... blyThe.pdf

Every single byte of code, every routine and subroutine, what registers are used, when they are used and how they are used. You'll see what alternate registers are used by each piece of code, what Stack operations are carried out, what the state of the interrupts are and much more. It's all in there.
"He made eloquent speeches to an audience consisting of a few depressed daffodil roots, and sometimes the cat from next door."
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

Bizzley wrote: Thu Jul 19, 2018 8:34 pm
hjalfi wrote: Thu Jul 19, 2018 5:45 pm I was hoping for some actual hard information!
Everything you need to know is here :

https://computerarchive.org/files/comp/ ... blyThe.pdf

Every single byte of code, every routine and subroutine, what registers are used, when they are used and how they are used. You'll see what alternate registers are used by each piece of code, what Stack operations are carried out, what the state of the interrupts are and much more. It's all in there.
The ROM disassembly is great and certainly useful as a good guide to finding entry points which can allow you to get BASIC-like functionality. But it is is no means official nor exactly definitive - there are certainly sequences of instructions part-way through those identified which might be useful if called in the right order (for added fun: PUSH a sequence of fake return addresses to chain things in weirder ways). There is also the issue that it doesn't tell you what is "safe" across different ROM versions.

Sinclair BASIC just wasn't designed to have version independent, documented entry points in the way that, for example, the Amstrad CPC or Elan Enterprise ROMs were. It's just one great big program that you can leap into at arbitrary points to trick it into doing what you want. It may be easier to tackle the problem from the other way around, document the system calls you want to exist and ask about any that you can't find an obvious entry point for. And then test everywhere. :lol:
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

Ast A. Moore wrote: Thu Jul 19, 2018 6:28 pm Again, there are no “universal” entry points—each programmer uses mostly arbitrary points based on his particular needs.
[...]
Those tutorials you refer to, simply use a subset of “most commonly used shortcuts” to ease a novice into programming in languages other than Sinclair BASIC.
Yes, precisely. There must be, somewhere in the community, information about which of these routines do useful things, and how to call them. Otherwise people wouldn't use them. This must be written down somewhere in a easier-to-digest form them just groping through the raw disassembly --- so, where?
Last edited by hjalfi on Thu Jul 19, 2018 9:48 pm, edited 1 time in total.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

hjalfi wrote: Thu Jul 19, 2018 9:38 pm Yes! This! This is exactly what I'm looking for! What are these shortcuts? Is there a known set of useful ones? What registers do they use? How do I use them? Is this stuff actually written down somewhere, or is this just tribal knowledge passed as samizdat from developer to developer?
You'll find it's sporadic at best. Pretty much RST #10 for printing a character (occasionally accompanied by the hint you should really do a Channel Select call first but can often get away without it) and maybe the odd routine entry point that any one given developer particularly favours. A lot of tutorials were designed around games and the Sinclair ROM routines are eye-wateringly slow for doing anything so many people just write their own (with the exception of maybe doing something like finding an LDIR/RET pair in ROM to circumvent contention).
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

Note that I rewrote my last post to be less obviously frustrated --- sorry about that.

I'm used to the BBC Micro, which has a significantly more complex operating system (like, it actually has an operating system). The Spectrum's so much simpler, better understood and has such a larger community that I refuse to believe that what I'm looking for isn't out there somewhere...
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

hjalfi wrote: Thu Jul 19, 2018 9:51 pm The Spectrum's so much simpler, better understood and has such a larger community that I refuse to believe that what I'm looking for isn't out there somewhere...
And therein lies the problem. The Speccy hardware is so simple that is bonkers insanely easier to just write the routines directly (and gain gads of speed) than to use the ROM calls. Particularly because the ROM was mainly designed to squeeze into 8K (from the ZX81) and is heavily tuned for size over performance.

And, as someone who does a fair bit of CPC coding, yes this does seem insane.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore »

hjalfi wrote: Thu Jul 19, 2018 9:38 pm
Ast A. Moore wrote: Thu Jul 19, 2018 6:28 pm [Those tutorials you refer to, simply use a subset of “most commonly used shortcuts” to ease a novice into programming in languages other than Sinclair BASIC.
Yes! This! This is exactly what I'm looking for! What are these shortcuts? Is there a known set of useful ones? What registers do they use? How do I use them? Is this stuff actually written down somewhere, or is this just tribal knowledge passed as samizdat from developer to developer?
Buddy, no offense, but I’ve already answered all of these questions. More than once. ;) Everything you need to know is in Logan and O’Hara’s book (and the excellent hypertext version thereof you’ve already discovered on your own). Read, experiment, learn. That’s how the cookie crumbles. There was never an officially documented breakdown of the Spectrum ROM from Sinclair Research or Amstrad. All the tutorials use the information found in that book or original discoveries (or someone else’s discoveries). Period.

A word of advice: Don’t get too hung up on the ROM routines. Their goal was universality (within the scope of the BASIC interpreter and the operating system) and being able to squeeze into 16K. Some are good in a pinch, but for the most part they’re painfully slow (and sometimes buggy, too). The print character routine (the famous Restart 16 one) is notoriously slow. It’s trivial to speed it up five or six times with a lot smaller footprint.

I think your frustration comes from misplaced expectations. The Spectrum is a very, very, very, very simple machine. A lot of programmers’ ingenuity originated out of necessity, rather than from studying some tome of sacred knowledge. People came up with creative and brilliant ways of making the simple (and quirky) hardware do amazing things because they were constantly inventing new approaches, and not because they looked for a set of standard ones. For the most part, the only thing we knew for certain was where our towel was. We never took trains or buses, we hitchhiked.
Every man should plant a tree, build a house, and write a ZX Spectrum game.

Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

Spec-chums curious of the difference could do worse than grab a copy of the +3DOS manual and look at the documentation for that, which documents a bunch of entry points each apparently exactly three bytes long. That's because the ROM pretty much starts out with a block of code like:

Code: Select all

function1 JP implementation_of_function1
function2 JP implementation_of_function2
function3 JP implementation_of_function3
function4 JP implementation_of_function4
So that when you do a CALL function1, it will pass through to the real routine, even if it shifts around between implementations and the entry points will always be consistent (since a three byte JP is all it ever needs). This is pretty much the same pattern used in the CPC firmware jumpblock to call system routines (though there is often a RST instruction followed by a specially coded two bytes that encode the entry point in one of the system ROMs)
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

Well, that was anticlimactic.

Code: Select all

var i: uint8 := 10;
while i != 0 loop
    print("I can do it ");
    print_i8(i);
    print(" time");
    if i != 1 then
        print("s");
    end if;
    print_newline();
    i := i - 1;
end loop;
...compiles to:

Image

The binary is pretty poor at 446 bytes, but I do notice that it appears to have decided to include the 32-bit division routine. I've been cross-compiling from a PC but there's no reason at all why you couldn't do this from a +3 running CP/M (if you were patient). The only ROM routine it's using is rst 0x16, and preserving iy.

Sadly, I don't think this is worth pursuing further --- without concrete information it's only really working by accident, so the only way forward is to essentially bolt on a complete operating system for the runtime, which is way out of scope. Still, I do have a project I need Cowgol-compiling-to-pure-code for, which this should work for.

If anyone discovers any decent docs, please get in touch!

Code is here: https://github.com/davidgiven/cowgol
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

hjalfi wrote: Thu Jul 19, 2018 11:02 pm Sadly, I don't think this is worth pursuing further --- without concrete information it's only really working by accident, so the only way forward is to essentially bolt on a complete operating system for the runtime, which is way out of scope. Still, I do have a project I need Cowgol-compiling-to-pure-code for, which this should work for.
You shouldn't entirely give up, it's a genuinely interesting idea. You might, however, want to document the required OS functionality somewhere as it's hard to determine from the codebase (especially if, like me, you don't grok 6502) and quite a few links in the GitHub documentation seem to 404. Also you might genuinely find it easier to try targetting the Amstrad first, Amstrad published an extensive reference in SOFT-968 (http://www.cpcwiki.eu/index.php/Soft968 ... 8_Firmware) and it's got a much cleaner design. What's more if you can nail it down to the firmware calls there, people can probably easily locate very similar entry points in the Spectrum ROM - RST #10 is effectively equivalent to CALL &BB5A, for example - because the Z80's non-orthagonal instruction set often lead to very similar patterns in terms of instruction passing.
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: Standard ROM entrypoints?

Post by ZXDunny »

Was the 48k ROM image substantially different in the various flavours of Spectrum? In my experience, the entry points documented in the unofficial-but-pretty-much-used-by-everyone ROM disassembly are universal as long as you page in the 48k ROM on the 128k and above machines? That's the only one that really has any useful stuff (except for disk handling on the +3) in it anyway.
User avatar
djnzx48
Manic Miner
Posts: 729
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Standard ROM entrypoints?

Post by djnzx48 »

I don't think the 48K ROM really changed that much, but the Interface 1 ROM at least had a lot of routines shuffled around between versions. This article has a brief summary: http://www.users.globalnet.co.uk/~jg27p ... r18_27.htm
User avatar
1024MAK
Bugaboo
Posts: 3104
Joined: Wed Nov 15, 2017 2:52 pm
Location: Sunny Somerset in the U.K. in Europe

Re: Standard ROM entrypoints?

Post by 1024MAK »

I think the point that may have been missed is this: the ZX80, ZX81 and ZX Spectrum did not, and do not have an operating system.

The ZX80 ROM is 4K bytes in size and contains BASIC and just enough code to process the keyboard and screen.
The ZX81 ROM is 8K bytes in size. The BASIC was developed from the ZX80 and is enhanced, but again, there is no OS.
Yep, same story with the ZX Spectrum. The ROM is 16k bytes in size. The intent at the time was to include code to handle the forthcoming microdrives (but instead ended up with some unused space). Again, the BASIC was developed from the ZX81 and is enhanced, but again, there is no OS.

Compare this with a Acorn BBC. This has a 16k OS ROM (approx 3/4 k byte is mapped out for the I/O hardware area). Plus one or more sideways ROMs (each up to 16k bytes) containing language(s), filing systems or other programs, one of which is the BASIC. The Master 128 can even be used without BASIC being active as it has a simple command line.

Of course, Z80 code can be made more compact compared to 6502 code. But even so, it's a big difference.

The print RESTART routine when fed with the correct data is the most useful routine, as it can output any character to the screen or the ZX printer. Read the BASIC manual to understand the control codes/control characters that BASIC can use.
In the ROM, there is also a keyboard reading routine. And there is the BASIC bleeper routine.

As alluded to above, the writers of the ROM were aiming for as much functionality as possible in 16k bytes, as that is apparently what Sir Clive wanted. Hence the ROM routines are slow. Hence machine code programmers preferred to write and read from the hardware directly.

The screen is a memory mapped bit-map. The only strange thing being the actual layout.

Apart from the 'unused' space and a couple of other areas which were altered in the 128k, +2, +2A, +2B, +3 and +3B, the 'original' ROM (often called the 48k ROM, even though it's exactly the same as the ROM in the 16k ZX Spectrum) is the same across all ZX Spectrums (there was ONLY one official ZX Spectrum ROM until the Spanish developed the 128k machine). So most useful routines stayed in the same place. In the 128k etc models, it's wise to ensure that this ROM image is mapped in rather than the editor ROM or disk OS ROM.

Mark
:!: Standby alert :!:
“There are four lights!”
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb :dance
Looking forward to summer later in the year.
User avatar
Seven.FFF
Manic Miner
Posts: 735
Joined: Sat Nov 25, 2017 10:50 pm
Location: USA

Re: Standard ROM entrypoints?

Post by Seven.FFF »

1024MAK wrote: Fri Jul 20, 2018 4:46 pm I think the point that may have been missed is this: the ZX80, ZX81 and ZX Spectrum did not, and do not have an operating system.
If you're ever tempted to think it did, you just have to look at the Acorn MOS to readjust your perspective :D

Garry Lancaster's NextZXOS is starting to turn +3eDOS into a useful operating system, with drivers and chained interrupts, and some system services.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins
hjalfi
Drutt
Posts: 28
Joined: Wed Jul 18, 2018 11:58 am

Re: Standard ROM entrypoints?

Post by hjalfi »

Yeah, the Acorn MOS is a bit of an unfair comparison; having 16kB BASIC + 16kB OS was unheard of luxury back then (and went a long way to explaining why the BBC Micro was so special, and so expensive).

A better comparison is the Commodore 64. (Also supported by Cowgol! https://pbs.twimg.com/media/DOnxU7CWkAA6a5N.jpg:large) It managed to pack into 20kB an 8kB OS, 8kB standard Microsoft Basic and a whole 4kB of character generator ROM (256 characters compared to the Spectrum's 128). The kernel was pretty crummy --- it wasn't even spelt correctly! --- but it did provide a set of standard entrypoints for console I/O, accessing devices, etc. See http://sta.c64.org/cbm64krnfunc.html. And that's on the 6502, which has maybe 20% worse code density than the Z80 (ref: http://web.eece.maine.edu/~vweaver/pape ... iccd09.pdf).

It'd be totally possible to implement a similar system, complete with Basic, into the Spectrum's 16kB ROM. You could even fit a DOS there --- Microsoft Extended Basic was 8kB of fairly rubbish 8080 code, the CP/M portable kernel is 3.5kB, the CP/M BIOS for talking to the hardware is another 3.5kB, leaving a whole kilobyte left over...
AndyC
Dynamite Dan
Posts: 1388
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC »

hjalfi wrote: Fri Jul 20, 2018 7:35 pm A better comparison is the Commodore 64. (Also supported by Cowgol! https://pbs.twimg.com/media/DOnxU7CWkAA6a5N.jpg:large) It managed to pack into 20kB an 8kB OS, 8kB standard Microsoft Basic and a whole 4kB of character generator ROM (256 characters compared to the Spectrum's 128). The kernel was pretty crummy --- it wasn't even spelt correctly! --- but it did provide a set of standard entrypoints for console I/O, accessing devices, etc. See http://sta.c64.org/cbm64krnfunc.html. And that's on the 6502, which has maybe 20% worse code density than the Z80 (ref: http://web.eece.maine.edu/~vweaver/pape ... iccd09.pdf).
True. Though not only is the kernel pretty crappy and limited, the BASIC implementation is massively lacking. Sinclair clearly wanted something the could show off the capabilities of their machine, particularly high res graphics and colour (remembering they're coming form the ZX81). Commodore on the other hand did the cheapest deal possible for a completely uncustomised version of Microsoft Basic (which was abnormal in and of itself, the usual process was to get Microsoft to extend it to cover machine capabilities).
Post Reply