Standard ROM entrypoints?

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

Re: Standard ROM entrypoints?

Post by hjalfi » Thu Jul 19, 2018 8:38 pm

Ast A. Moore wrote:
Thu Jul 19, 2018 5: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 8:48 pm, edited 1 time in total.
0 x

AndyC
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC » Thu Jul 19, 2018 8:46 pm

hjalfi wrote:
Thu Jul 19, 2018 8: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).
0 x

hjalfi
Berk
Posts: 28
Joined: Wed Jul 18, 2018 10:58 am

Re: Standard ROM entrypoints?

Post by hjalfi » Thu Jul 19, 2018 8:51 pm

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...
0 x

AndyC
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC » Thu Jul 19, 2018 8:59 pm

hjalfi wrote:
Thu Jul 19, 2018 8: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.
0 x

User avatar
Ast A. Moore
Dynamite Dan
Posts: 1224
Joined: Mon Nov 13, 2017 3:16 pm

Re: Standard ROM entrypoints?

Post by Ast A. Moore » Thu Jul 19, 2018 9:26 pm

hjalfi wrote:
Thu Jul 19, 2018 8:38 pm
Ast A. Moore wrote:
Thu Jul 19, 2018 5: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.
0 x
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
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC » Thu Jul 19, 2018 10:00 pm

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)
0 x

hjalfi
Berk
Posts: 28
Joined: Wed Jul 18, 2018 10:58 am

Re: Standard ROM entrypoints?

Post by hjalfi » Thu Jul 19, 2018 10:02 pm

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
0 x

AndyC
Manic Miner
Posts: 251
Joined: Mon Nov 13, 2017 5:12 am

Re: Standard ROM entrypoints?

Post by AndyC » Thu Jul 19, 2018 10:14 pm

hjalfi wrote:
Thu Jul 19, 2018 10: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.
0 x

User avatar
ZXDunny
Manic Miner
Posts: 250
Joined: Tue Nov 14, 2017 3:45 pm

Re: Standard ROM entrypoints?

Post by ZXDunny » Thu Jul 19, 2018 10:21 pm

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.
0 x

User avatar
djnzx48
Manic Miner
Posts: 568
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Standard ROM entrypoints?

Post by djnzx48 » Fri Jul 20, 2018 1:00 am

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
0 x

Post Reply