z00m128 / sjasmplus

Command-line cross-compiler of assembly language for Z80 CPU.
http://z00m128.github.io/sjasmplus/
BSD 3-Clause "New" or "Revised" License
382 stars 54 forks source link

How to use NEX format and PAGE #59

Closed maziac closed 5 years ago

maziac commented 5 years ago

Hi,

I'm trying to use the NEX file format and the ZXSPECTRUMNEXT device but I somehow don't understand how this should work. I have been playing aroung with the page/slot parameters but it never saves the page that I intend to save.

Here is some source code.

    DEVICE ZXSPECTRUMNEXT

    PAGE 10
    ORG 0x0000
    DEFB "MAIN_START",0

    SAVENEX OPEN "sjasm_test.nex", 0 
    ;SAVENEX BANK 2
    SAVENEX AUTO
    SAVENEX CLOSE

The hex output of the produced nex file shows that page 7 has ben used.

4E 65 78 74 56 31 2E 32 00 01 00 00 FE FF 00 00 
00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 

It seems that no matter which PAGE I supply always bank 7 is used in the nex file.

How can I provide the correct information to the sources so that I create the assembly in the correct pages?

(SjASMPlus Z80 Cross-Assembler v1.13.3)

ped7g commented 5 years ago

So the usage pattern of SAVENEX is more like: use SLOT+PAGE (MMU) to modify whole device memory as you want, and then do SAVENEX AUTO to store all of it. And layout your init code with regards to the snapshot-like initialo state, i.e. use rather entry point like $8000 or $C000. (your "0" is anyway "do not exec", so that's valid choice too, but value like $100 would just start some ROM gibberish).

You can also check the docs_example asm (maybe that will make some of this even clearer, or at least you can point at particular line/value and ask "wtf" :) ): https://github.com/z00m128/sjasmplus/blob/master/tests/docs_examples/s_savenex_examples.asm

How can I provide the correct information to the sources so that I create the assembly in the correct pages?

To create machine code in correct page, you need to use combination of SLOT+PAGE+ORG directives (or you can use the new MMU which is basically SLOT+PAGE fused into one, with extra options). So by MMU you page-in the desired page at desired memory range, and then with ORG and normal source you modify that page. Repeat that until you have all of the device memory set as desired, then do the SAVENEX (which is not affected by current SLOT+PAGE values, as it is working directly with the device memory and all "bank" values in NEX file are the 16kiB banks numbers, so make sure you are using doubled values with PAGE/MMU, as those operate with 8kiB pages.

(but this is non-bug to me ... or if bug, then it's the device docs which are lacking, but I already asked you to pinpoint which parts are confusing in the issue #55, so I can try to improve on them .. for me it's all very clear, because I know the implementation and I fully understand how those "virtual device" of sjasmplus work, and how to use them, but you failed second time to grasp how it works, so the docs are probably crap, but I need more feedback why this happened to you and which part of docs fooled you)

maziac commented 5 years ago

OK, I got it now. I think the problem in my brain was that I didn't fully understood the "emulation" that is done in sjasmplus. I didn't get what the SLOT was used for. I thought you could directly set the PAGE and then the binary would be written there although this also didn't fully make sense. Now I think I understood: with the PAGE/SLOT or MMU command you somehow slide a window over the different banks also during assembly.

At least I now managed to create a NEX file the way I wanted :-)

Thanks for the explanations.