Running raw z80 code on MSX

페이지 1/2
| 2

By M2X_E1

Rookie (21)

M2X_E1의 아바타

31-03-2018, 18:35

Hi All,
I'm looking to run some z80 code on my msx and/or emulator. Unfortunately having no luck at all.
I've tried to convert to msx binary using 'msxr2b' which fails to produce any output and won't work on the cart port anyway as the file may need extra header info.
I've searched google for ages and going round in circles.

Does anyone know a straightforward way of getting the file to run?

Regards

Login or 등록 to post comments

By Manuel

Ascended (15825)

Manuel의 아바타

31-03-2018, 21:13

What file did you create?
Is the code relocatable or targeted for an address?
Does the code use any ROM routines?

By sd_snatcher

Prophet (3092)

sd_snatcher의 아바타

31-03-2018, 21:27

What do you mean by "raw z80 code"? Is it from another platform? CP/M?

What kind of output did you expect it to produce? Text?

By Manuel

Ascended (15825)

Manuel의 아바타

31-03-2018, 22:29

Looks like apparently msxr2b converts a ROM image into a BLOADable file for under BASIC. Anyway, without answers to the above questions, we can't help you further.

By santiontanon

Paladin (847)

santiontanon의 아바타

01-04-2018, 03:11

Same here, without more info, it's hard to help. By "raw z80 code" do you mean you just have a binary file with a sequence of bytes representing z80 instructions?

By M2X_E1

Rookie (21)

M2X_E1의 아바타

03-04-2018, 22:36

sd_snatcher wrote:

What do you mean by "raw z80 code"? Is it from another platform? CP/M?

What kind of output did you expect it to produce? Text?

Hi There,
It was a simple 'hello world' type program as below:

  .org 40000

   CHPUT   .equ $00A2


       ld hl, msg
       call puts
       ret

   puts:               ; print 0-terminated string in HL
       ld a,(hl)
       or a
       ret z
       call CHPUT      ; displays one character in A
       inc hl
       jr puts

   msg:    
   	.defm "Hello, world!",13,10,0

compiled using 'ZASM' the output as viewed in hex format is:
21 50 9C CD 47 9C C9 7E B7 C8 CD A2 00 23 18 F7 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 00

This contains only z80 code, there are no headers or start addresses (except for the .org which may have no effect as the addressing used in the simple program is relative to wherever the program is stored, so anywhere in the msx memory map should work in theory).

I know that there are some header info needed by the msx 's .bin files, just looking for some means of being able to wrap my code above so that I can store on floppy and load using BLOAD.

Regards

By Manuel

Ascended (15825)

Manuel의 아바타

03-04-2018, 22:49

That org address is 40000 decimal, right? That would be OK in a BASIC environment if the BASIC program is not too large.
Here's the information of the header you need to BLOAD it: https://www.msx.org/wiki/MSX-BASIC_file_formats#MSX-BASIC_bi...

By M2X_E1

Rookie (21)

M2X_E1의 아바타

03-04-2018, 23:33

Manuel wrote:

That org address is 40000 decimal, right? That would be OK in a BASIC environment if the BASIC program is not too large.
Here's the information of the header you need to BLOAD it: https://www.msx.org/wiki/MSX-BASIC_file_formats#MSX-BASIC_binary_files

Hi Manuel,
Yes its in decimal (I was going to remove as it appears irrelevant in the case of the relative jumps but decided to leave as is).

Thank you for the link regarding the bin file headers. I guess i can manually insert these using the hex editor.
Just want to confirm re the Begin address, start address and the end address.
What would be the best address for 'Begin' and how does this differ from the 'Start' address?
Guessing the end address is the length of the original z80 code (excluding the header info)?

Regards

By Pencioner

Paladin (993)

Pencioner의 아바타

03-04-2018, 23:53

Begin address is where your code will be loaded. Start address is the start execution point (in your case it is the same as begin address, but it may have another entry point). End address is begin address + length of your program.

In MSX basic it is always good idea to protect some higher addresses by CLEAR command, then BLOAD your program and run it. Like (if your program has .org $c000 as an example):

10 CLEAR 512, &hC000
20 BLOAD "yourcode.bin", R

This way, with protected addresses from $C000 to the beginning of system area (current system area bottom address is stored in two bytes at $FC4A) it is safe to return from your code back to basic and run it many times if needed. Usually it is safe to assume that system area doesn't reach $d000 or lower addresses so you have in our case at least 4kb from $c000 (if your code is bigger, you can move down to $b000 or $a000 etc, depends on size of your basic program, if it is very small then you can have up to 27Kb for your asm code).

PS note that the first argument to CLEAR doesn't indicate size of your program, it is size of memory reserved for basic string variables

By Grauw

Ascended (8515)

Grauw의 아바타

04-04-2018, 00:18

M2X_E1 wrote:

Yes its in decimal (I was going to remove as it appears irrelevant in the case of the relative jumps but decided to leave as is).

The call is not relative though. And I would suggest using hexadecimal for the org address Smile. I almost thought you had a typo there, writing one 0 too many. 0C000H is a common choice in Basic.

About end address, I think it’s begin address + length - 1 ?

By santiontanon

Paladin (847)

santiontanon의 아바타

04-04-2018, 06:34

I was going to say that same as Grauw. There are at least 2 instructions in that program that will not work as expected unless the program is loaded in address 40000: the "ld hl,msg' and 'call puts', since both those instructions use absolute addresses. So, you should also make sure to us the same address in your "org" statement as the one in which you are going to load the program on.

페이지 1/2
| 2