• Please review our updated Terms and Rules here

Accessing BASIC ROM Calls From Assembly

VinnieMan

New Member
Joined
Mar 7, 2022
Messages
9
Does anyone know how to “initialize” Model I Disk BASIC so that its ROM calls (ie, floating point math) can be used from a TRSDOS machine code application? I believe that at least one program did this “back in the day”—Phelps Gates amazing APL/80.
 
It depends on how much of BASIC you want to use.

If all you want is the math functions, and you use the two floating point accumulator areas 411Dh and 4127h properly (so no error that would trigger BASIC's error handling), then only one small area needs to be set up. And even that is only for floating point division or exponential. You just need to copy 14 bytes from ROM starting at 18F7h to RAM starting at 4080h:

LD HL,18F7H
LD DE,4080H
LD BC,000EH
LDIR

But if you want to use more, like BASIC's convenient floating point ASCII conversion routines, or many printing routines, then you'll probably have to plug the Disk BASIC RAM "exits" from 41A6h to 41E2h with C9 "ret" instructions the way Level 2 does. And if you want a functional disk, you have to be very careful with RST 28h, which is shared with both DOS function calls and Break key handling.

I recommend reading The Alternate Source's "ROM Routines Documented" book, which explains how to use much of the ROM properly. Plugging Disk exits is covered on page 4, and the whole Chapter 2 is on using the math routines, with my example LDIR above coming from page 30. It even explains string functions that other books skip. You can find it on archive.org at

(Note the "live" pages of that link are scanned so horribly as to be unreadable. But under Download Options, either PDF version is perfectly readable, so use those to read the book.)
 
For anyone who’s interested, I expect that Dusty will have my article about setting up to call Model I Math ROM subroutines in the March 2024 issue of TRS8bit magazine.
 
You might get more insight to it by looking at some later genuine Microsoft source code. There shouldn't have been too many changes to the math code between the TRS-80 version and the CP/M 5.2 version.


Look for F4.MAC, and you can probably find a lot of common code.

Anyhow, as long as you know where the floating point accumulators are, you should be able to use the floating point math functions without any special initialization.
 
Thanks to everyone who helped me find the necessary setup routines in order to call Model I ROM BASIC routines from a DOS-based assembly language program. I’ve gathered all my findings in an article in the latest issue of TRS8bit. Click the “Downloads” link here:

 
Back
Top