ENTERPRISE KLUB
2019. május 25., 1055 Budapest, Nyugati tér 9. 14-19 óráig
Részletek
Welcome, Guest. Please login or register.


Author Topic: Where am I? (Read 1328 times)

Online gflorez

  • EP addict
  • *
  • Posts: 2558
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
Where am I?
« on: 2014.April.16. 12:03:14 »
How can I make a Z80 relocatable code aware of its position in memory?

In the "Machine Code for Beginners" program header there is an error:

1 ALLOCATE 40
2 LET B$="F7,18.............
3 LET C$="F7,01.............
4 LET D$="00,CA.............
5 CODE MC=HEX$(B$&C$&D$)&"MACHINEC"
6 CALL USR(MC,0)

Then, in memory, the code is allocated on different position depending of the configuration of the EP:



exos 24          !Allocate segment
ld A,C
ld (0xBFF8), A
out (0xB2),A
ld A,0x6A        !channel 106 (file io)
ld DE,0x12EA   !            <----------------Here the programmer assumes the allocated area is immovable.
exos 1          !open channel
ld A,0x6A
ld BC,0x18B2
ld DE,0x8151
exos 6            !read block
jp z,0x87B5
di
hang: jp hang

defstring:8,"MACHINEC"  ! here points the buggy instruction

Is easy to search the string in the Basic program and then modify the code before the USR call, but I have though if I know the value of PC inside the code I only need to add the direction of the string. Then the basic header would work on all the configurations of the EP...
« Last Edit: 2014.April.16. 14:58:52 by szipucsu »

Online Zozosoft

  • EP addict
  • *
  • Posts: 13336
  • Country: hu
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
    • http://enterprise.iko.hu/
Re: Where am I?
« Reply #1 on: 2014.April.16. 12:21:02 »
The second parameter of USR placed to HL.
CALL USR(MC,MC) then you got the address of your routine and it can be used for address calculations.
« Last Edit: 2014.April.16. 14:59:34 by szipucsu »

Online gflorez

  • EP addict
  • *
  • Posts: 2558
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
Re: Where am I?
« Reply #2 on: 2014.April.16. 16:30:37 »
Thanks Zozo!


This is the debugged code:


Start#:      ld BC, 0x0024   !filename#-start#.  HL must contain the entry point
                add HL,BC        
                Exos 24          !Allocate segment
                ld A,C
                ld (0xBFF8), A
                out (0xB2),A
                ld A,0x6A        !channel 106 (file io)
                ld D,H            !<----------------Here we put the correct address in DE.
                ld E,L            !<----------------/
                Exos 1          !open channel
                ld A,0x6A        !channel 106 (file io)
                ld BC,0x18B2
                ld DE,0x8151
                Exos 6            !read block
                jp z,0x87B5
                di
hang#:       jp hang#
filename#:  8,"MACHINEC"


And the corrected header and program:
« Last Edit: 2014.April.19. 00:33:53 by gflorez »

Online gflorez

  • EP addict
  • *
  • Posts: 2558
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
Re: Where am I?
« Reply #3 on: 2014.April.16. 16:37:14 »
Another equally transcendental question:

How do I save a Basic program in ASCII? I did it lots of times on some distant past, but don't remember how, and the manual doesn't help very much mentioning the LIST command.
« Last Edit: 2014.April.16. 17:37:01 by gflorez »

Online Zozosoft

  • EP addict
  • *
  • Posts: 13336
  • Country: hu
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
    • http://enterprise.iko.hu/
Re: Where am I?
« Reply #4 on: 2014.April.16. 16:39:38 »
Quote from: gflorez
How do I save a Basic program in ASCII?
OPEN #1:"LIST.TXT" ACCESS OUTPUT
LIST #1
CLOSE #1

Online gflorez

  • EP addict
  • *
  • Posts: 2558
  • Country: es
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 28.0 Firefox 28.0
    • View Profile
Re: Where am I?
« Reply #5 on: 2014.April.16. 17:00:39 »
Thanks again Zozo.