sjasmpluss stupid n00b question

By Hari Seldon

Supporter (2)

Аватар пользователя Hari Seldon

17-02-2021, 00:43

Hi guys,
Sorry for the stupid n00b question but I have been playing around with sjasmplus and openMSX, I am able to assemble a .bin file and run it with bload but I would like to make a cart file as well. So I need to pad out the cart with 0's but I can't workout how to do it. I'm pretty sold on using sjasmplus, I have the feeling I need some kind of command line arg or maybe some DEVICE declaration ?

When assembling for a bload i was just using: sjasmplus input.z80 --raw=output.bin

I tried googling for an answer but my search terms obviously were wrong; padding, paging not sure what to ask google for.

        org 0x4000                              ;Base Cart Address
        db "AB"                                 ;Fixed Header
        dw ProgramStart                 ;Pointer to start of program
        db 00,00,00,00,00,00    ;Unused

ProgramStart:
        nop
        nop


        org 0xC000              ;Pad to 32k
Для того, чтобы оставить комментарий, необходимо регистрация или !login

By santiontanon

Paragon (1521)

Аватар пользователя santiontanon

17-02-2021, 03:08

I am no expert in sjasmplus, but this is my understanding:
- In principle you'd do that with the "device" command, unfortunately sjasmplus only has spectrum-variant built-in devices. So, you'll have to do it manually.
- The easy way to do it manually is to replace the last line you have by this:

        ds 0xC000 - $

An "org" only changes the address that the labels you define afterwards will have, but it does not "create space". If you want to fill a space with 0s, you need to "define space" ("ds"). "$" refers to the current address, so "0xc000 - $" is whatever number of bytes you need to reach there.

I hope this helps! Smile

ps: nice user name Wink

By Hari Seldon

Supporter (2)

Аватар пользователя Hari Seldon

17-02-2021, 05:12

That's exactly what I need thanks for your assistance.

By Metalion

Paragon (1451)

Аватар пользователя Metalion

17-02-2021, 08:47

And why would you need to pad the cart with 0's ?

By Daemos

Paragon (1954)

Аватар пользователя Daemos

17-02-2021, 09:31

Or 1's because not every msx or emulator likes rom's that aren't multiples of 8k. I never used to pad roms but then the bug reports came in and warnings or even errors on some software.

Nowadays it shouldn't be a required any longer but for the sake of legacy its good practice to pad the roms.

By Metalion

Paragon (1451)

Аватар пользователя Metalion

17-02-2021, 15:35

Yes, but in Sjasm it's not necessary.
When you define the page length, it automatically pads the page to make the correct length.

defpage 0,8000h,04000h
page 0

will define a code page of 4000h in length, and pads the empty part with 0's.
And I suppose that Sjasmplus does the same.

By santiontanon

Paragon (1521)

Аватар пользователя santiontanon

17-02-2021, 16:12

Yeah, you can define a "page" and both sjasm/sjasmplus would fill with 0s. But in the code example above, there was no page defined Smile

I opted for the "define space" solution instead of suggesting a "page" just because of portability (I'm obsessed with it after working on MDL, sorry haha). Padding with 0s is more portable than using a page definition. Page definitions are not supported in many other assemblers, but space definitions are universally supported. So, the code above compiles in most assemblers, while with a "page" definition it would only compile in sjasm/sjasmplus Smile [if portability is not an issue, then sure, a page definition would do; again, just my personal bias because of working on MDL haha Smile ]

By Ped7g

Resident (41)

Аватар пользователя Ped7g

25-02-2021, 03:04

"raw" option: either the mentioned `ds 0xC000-$` or if you need to reach power of two, then you can also `ALIGN 0x4000` or `ALIGN 0x4000,0xFF` to fill with ones (also `ds` takes second argument with filler value) (but not ALIGN 0xC000 - that's not power of two).

`OUTPUT` option http://z00m128.github.io/sjasmplus/documentation.html#po_output :

    OUTPUT "t.bin"
    SIZE 0x1000
    db 0,1,2,3,4,5,6,7
    OUTEND

`DEVICE` option http://z00m128.github.io/sjasmplus/documentation.html#po_device :
- the ZX 48/128/... "devices" have memory paging per 16kiB pages, and taint the virtual memory with fake ZX sysvars upon init (should not matter if you overwrite the memory with your content for cart), total memory depends on particular device seleced (from 64kiB up to 8MiB) (ie. don't worry about "ZXSPECTRUM" name, if the device has configuration which is useful also for MSX, you can use it, should work well and if not, please report any issues)
- the ZX Next device has memory paging per 8kiB pages (all zeroed, no pre-init with anything), total memory 2MiB. Thinking about it, this device does actually have one more extra, it enables Z80N instruction extensions, which are useless outside of Spectrum Next, but if you don't use the extra instructions, the "device" is as generic as "noslot64k"
- "noslot64k" device has paging per 64kiB pages (all zeroed), total memory 2MiB, no other extra, just plain block of memory to fill with code/data

Then you can `SAVEDEV` ( http://z00m128.github.io/sjasmplus/documentation.html#po_sav... ) whole cart in one go, if you have everything layed out in the virtual-device memory as designed (the current snapshot of virtual memory is saved by SAVEDEV, so you put it after all the code and data specified/incbin, not at beginning of file).

For first two option you may be interested also in --longptr option in case you want 24bit label values working with full cart size (in case of 64ki+ carts), and you can technically produce any size of cart.

The device option brings extra support for paging, during assembly time the MMU directive may be handy, and in the code you can then use stuff like `ld a,$$label` to get page number where the label was defined, etc.

(all of this does apply to z00m's fork of sjasmplus)

So there are many possible ways how to do it, may depend on your personal preference what you want to use and also how much time you want to spend giving docs quick glance to learn about various directives and operators.

If you feel like there's anything seriously missing hampering the ability to produce MSX carts (AFAIK the sjasmplus should be usable for this, I'm not aware of any problem, but I don't do MSX dev, so I may just not have idea), let me know what the issue is. Cheers.