Welcome, Guest. Please login or register.


Author Topic: Easy relocatable code in basic (Read 22260 times)

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Easy relocatable code in basic
« Reply #15 on: 2018.April.25. 18:21:14 »
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.
« Last Edit: 2018.April.25. 18:28:20 by IstvanV »

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14776
  • Country: hu
    • http://enterprise.iko.hu/
Re: Easy relocatable code in basic
« Reply #16 on: 2018.April.25. 20:05:43 »
EXOS have a support for a relocatable modules, header 02h
1) little code needed which is using EXOS 30 for load the remaining code from relocatable module
2) 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.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #17 on: 2018.April.25. 20:24:54 »
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....

I think I have seen that call to a JP (HL) used on EXOS.


I will do a version of each one to see.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #18 on: 2018.April.25. 21:16:46 »
EXOS have a support for a relocatable modules, header 02h
1) little code needed which is using EXOS 30 for load the remaining code from relocatable module
2) 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.
« Last Edit: 2018.April.25. 23:16:54 by gflorez »

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: Easy relocatable code in basic
« Reply #19 on: 2018.April.25. 21:26:38 »
The real problem I found about doing relocatable code with the Z80 is the impossibility to read the PC register to know the address of the instruction the processor is actually executing.
Here's a bit of a wild idea if you know interrupts are enabled:
Code: [Select]
        HALT
        DI
        DEC SP
        DEC SP
        POP HL    ; HL=address of DI instruction :-)
        EI

(untested :mrgreen: )

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #20 on: 2018.April.25. 23:15:09 »
Thanks! It can make the experiment more weird, even without the first absolute address at the start....
« Last Edit: 2018.April.25. 23:49:36 by gflorez »

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Easy relocatable code in basic
« Reply #21 on: 2018.April.26. 16:55:18 »
Simple program to create EXOS module type 7 (relocatable extension):

[ Guests cannot view attachments ]

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.

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14776
  • Country: hu
    • http://enterprise.iko.hu/
Re: Easy relocatable code in basic
« Reply #22 on: 2018.April.26. 19:17:34 »
Simple program to create EXOS module type 7 (relocatable extension):
Working! :smt038

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #23 on: 2018.April.26. 20:19:17 »
Thanks! I have to try it first. This can work with an extension, like Mouse.xr.
« Last Edit: 2018.April.26. 20:26:26 by gflorez »

Offline BruceTanner

  • EP lover
  • *
  • Posts: 609
  • Country: gb
Re: Easy relocatable code in basic
« Reply #24 on: 2018.April.26. 21:22:32 »
:smt041 :smt041 :smt041

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #25 on: 2018.April.27. 12:09:23 »
Some silly questions:

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.

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Easy relocatable code in basic
« Reply #26 on: 2018.April.27. 13:36:01 »
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
  1.         org     0000h
  2.  
  3.         module  Reloc_0
  4.         include "reloc.s"
  5.         endmod
  6.  
  7.         module  Reloc_1
  8.         include "reloc.s"
  9.         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.

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: Easy relocatable code in basic
« Reply #27 on: 2018.April.27. 18:59:52 »
I forgot to remove all ORGs and ENDs from the code....

Offline dangerman

  • EP fan
  • *
  • Posts: 100
Re: Easy relocatable code in basic
« Reply #28 on: 2018.May.03. 10:51:15 »
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.


Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14776
  • Country: hu
    • http://enterprise.iko.hu/
Re: Easy relocatable code in basic
« Reply #29 on: 2018.May.03. 11:04:18 »
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 :oops: But I only wrote few examples as relocatable, 99% of my programs are fixed :-)
Today I prefer Sjasm :-)