AuthorTopic: Easy relocatable code in basic (Read 6852 times)

It is not the most elegant solution, but if there is any fixed address that is safe to temporarily overwrite, then a JP (HL) (E9h byte) can be stored there and called so that it effectively becomes CALL (HL). Or even something like CALL (IX + DE) with a few more bytes. Possible places to store the JP (HL) at include the beginning of page 0, and usually unused parts of the EXOS stack around AC00h.

EXOS have a support for a relocatable modules, header 02h1) little code needed which is using EXOS 30 for load the remaining code from relocatable module2) IS-BASIC extension also using relocatable modules, these are handled with simple LOAD command. Then needed to write the thing as new BASIC instructios or functions.

The code to convert is very simple and short, it is not necessary to change pages, only an EXOs call to print characters to the EDITOR channel.

I know it is un-elegant and ugly... but it is a challenge for me to write a program that doesn't need absolute addresses nor auto-modifiable code. Doing it needs a twist of the mind. 10 instructions or more in exchange of only one... At least simulating a JP is easier....

EXOS have a support for a relocatable modules, header 02h1) little code needed which is using EXOS 30 for load the remaining code from relocatable module2) IS-BASIC extension also using relocatable modules, these are handled with simple LOAD command. Then needed to write the thing as new BASIC instructios or functions.

I know, header 02H, once in a time I decoded the "Mordon's quest" adventure only searching for the vocabulary, at the end I found the game rules and the map.... Without EXDOS controller, only tape and a printer, with a Basic listing, reading the flow of 1s and 0s. I was very young and used to thought that I was the only Enterprise owner in Spain. Today I have less knowledge than then...

Recently I have also decoded the first version of the Mouse.xr(extension relocatable) driver. But this time searching the memory of the emulator...

---I don't want to load Basic extensions, I like the code to run on all Enterprises. But we lack the utility to make relocatable modules.

I remember another app decoded with the emulator, it was that Joystick driver listing submitted by an user to a Dutch magazine.

On classic times it must have been a very normal application. Why it still doesn't surface?

It is a good challenge, if I decoded the game with a Basic listing, another listing is enough to do the encoding task. Then, once Ziiiped, it can make the task at a reasonable speed. Needed are two binaries of the same file compiled at different addresses, one of them at 0000h.

The input is raw machine code that is compiled at org 0000h, and the code is repeated twice. With sjasm, this is achieved by including the original source file from another file and using MODULE to avoid duplicate labels.

With an Hex editor, I have changed the module type to 02 on byte 1 on the header of the dbasx.xr file created by Zozo. I have also put 0FFh on bytes 4 and 5 of the header(no offset). It has loaded correctly without installing the extension.

-Is this the procedure?

-How can I create raw machine code with sjasm? The executable file is not admitted by reloc.

With an Hex editor, I have changed the module type to 02 on byte 1 on the header of the dbasx.xr file created by Zozo. I have also put 0FFh on bytes 4 and 5 of the header(no offset). It has loaded correctly without installing the extension.

-Is this the procedure?

I tried the same, it is even in reloc.cpp as commented out code, but type 2 modules apparently need to be written as BASIC extensions, I do not know how to do that, so I changed it to type 7.

Quote

-How can I create raw machine code with sjasm? The executable file is not admitted by reloc.

There is a simple example in the .zip file and also Zozosoft's dbasx extension, you need to compile reloc2.s or dbasx2.s to create a file that is accepted by reloc.exe. reloc2.s contains only these lines:

Code: ZiLOG Z80 Assembler

org 0000h

module Reloc_0

include "reloc.s"

endmod

module Reloc_1

include "reloc.s"

endmod

The actual source code is in reloc.s, the reason why it is compiled in two instances is that reloc.exe needs this to find the absolute addresses (16-bit words) that require relocation.

I tried using ASMON in the past to assemble relocatable modules (it was to play around with some BASIC extensions actually). I used .CSEG and .ASEG but I found that it didn't work properly for me (I seem to remember that it didn't write the last byte properly or something). Maybe I was doing something wrong.

But... did you know that Hisoft Devpac will create relocatable modules? And it automatically knows which values are addresses and which aren't. I used it several times successfully to create relocatable modules.

did you know that Hisoft Devpac will create relocatable modules? And it automatically knows which values are addresses and which aren't. I used it several times successfully to create relocatable modules.

Yes. Just I don't liked too much the GEN But I only wrote few examples as relocatable, 99% of my programs are fixed Today I prefer Sjasm