New dev using sjasm for MSX2, requesting aid :)

Page 4/7
1 | 2 | 3 | | 5 | 6 | 7

By santiontanon

Paladin (833)

santiontanon's picture

26-04-2019, 19:59

But if you just want to create a normal small ROM (e.g. a 16KB or 32KB ROM), there is nothing special you need to do on the sjasm side. Just add this header and name the file .rom instead of .bin, and that's it Smile

    org #4000  
    db "AB"     ; ROM signature
    dw Execute  ; start address
    db 0,0,0,0,0,0,0,0,0,0,0,0
Execute:
    ; your code here

By ARTRAG

Enlighted (6242)

ARTRAG's picture

27-04-2019, 01:31

Well, this sample if for 16KB roms, if you want a 32KB rom you need to set the page at 8000h to your slot, or you will get ram there.

By shram86

Expert (88)

shram86's picture

27-04-2019, 02:00

santiontanon wrote:

But if you just want to create a normal small ROM (e.g. a 16KB or 32KB ROM), there is nothing special you need to do on the sjasm side. Just add this header and name the file .rom instead of .bin, and that's it Smile

    org #4000  
    db "AB"     ; ROM signature
    dw Execute  ; start address
    db 0,0,0,0,0,0,0,0,0,0,0,0
Execute:
    ; your code here

How strange - I swear I tried that and it didn't work. I have yet to read up on how to swap memory banks on the MSX2 so my ability to construct a workable ROM is limited at the moment anyway.

Why is the org at $4000 when I thought the system ROM goes up to $8000 by default?

In more productive news, I finished a tool in python that makes sprite mode 2 sprites (for GRAPHIC3/screen4) using two OR-layered masks. It is basically like TinySprite (though much less pretty) and specifically exports mode 2 palettes and tables in z80 asm.

Is there any interest in this? Here is the github link:
MSX2 mode-2 spriter for Python (github)

By santiontanon

Paladin (833)

santiontanon's picture

27-04-2019, 05:33

Yep what I said above would just work for basic 16KB ROMS. If you want 32KB ROMS, that part will remain the same, but you'll need to insert some code on start up to select the other 16KB of the ROM. But that's the easiest one to start with, and you can build from there Smile

Also, the BIOS just uses from #000 to #3fff, and standard (16KB) ROM cartridges start at #4000 and up to #7fff, and RAM starts at #C000. If you create a 32KB ROM, you can make the second part of the cartridge be from #8000 to #bfff. And you can do even 48KB and 64KB cartridges by kicking the BIOS out. But larger than that, then you need rom mappers and use a megaROM as Artrag was suggesting.

edit: and that sprite editor looks nice! I build something very similar (but in Java) for my games, which is the one I use. But it has a lot of hardcoded functionality that I swap in and out by recompiling, so, not very useful to anyone else hehehe. I'll give yours a try! Smile

By shram86

Expert (88)

shram86's picture

27-04-2019, 19:14

Thanks, that's pretty easy.

Are there any hard disadvantages to shucking out the BIOS? I like using kernel save/load and things like that, is it possible to swap the bank back to the BIOS after you load in the cart's mapper?

And let me know if you have any recommendations to the editor - I will probably add a more visible selection, plus the ability to copy and paste and other small features, like maybe toggling what the right mouse button does. (I also just fixed a dumb bug where I forgot to toggle bit 6 (the CC bit) on the higher-order mask. Export should work fine now!)

Samurai guy rendered in openMSX

By ARTRAG

Enlighted (6242)

ARTRAG's picture

27-04-2019, 19:35

For games, no reason to keep it in.
Just do your custom ISR and take full control of the machine.
You can always swap it in in case of need (in games never).
For other purposes it can be different, but it is controversial :-)

Ps
Nice samurai

By Grauw

Ascended (8439)

Grauw's picture

27-04-2019, 20:13

Kicking out the BIOS is not common practice I think and not something I would recommend someone to do normally, especially not when you’re just starting out with the system. There’s no real good reason for it unless you really are extremely short of TPA space, it’s just gonna make your life harder and waste your time on fixing compatibility issues rather than useful stuff. And if you don’t care for the BIOS and would like to use all 64K TPA space, maybe consider to use the DOS programming environment.

I mean, at least let the guy figure out ROM headers and ROM mappers first before you start recommending hard core stuff like that y’know Big smile. There’s already enough to learn while working with the system, no need to complicate it by teaching to swim against the flow right from the start.

By shram86

Expert (88)

shram86's picture

27-04-2019, 21:10

The ROM header you posted did indeed work. The problem was my not understanding how sjasm deals with pages (I still don't quite get it, seems different from other compilers). Removing all page definition allowed it to boot @ address 0x4000.

Still getting used to the fact that the MSX2 can configure each 16kb block, and I'm probably mistaken on this much, but let me know how much I have right:

While by default, the MSX2 maps 0h-7fff to Main ROM, very little of this is actually used - I don't see any indication there is any data above $0200(?). That's why initializing a cart in $4000 is ok, but anywhere between 0-3fff will prevent the BIOS from loading -- because the system will automatically configure itself to map the active target memory page to the cartridge slot.
e.g. you put a cart into slot 1, and on boot, the system scans cartridge slots. It finds one, and reading the header, sees it has data in the 0x0-0x3fff range, so it changes memory configuration to target the cartridge, and that kicks out the BIOS (so things like "call $5f" will no longer work).

The ROM example above also makes the target memory mapping change automatically to slot 0, slot 1, slot 0, slot 0 (for a 16kb cartridge)?

My understanding is still iffy, but I do get that seeing more than 16kb of the cartridge requires manual configuration in register $ab.

One thing I am also still confused about is how, for instance, the HB-F1XD (my system) only has "64kb" of RAM, when the specification on this site's wiki makes it look like most of the 3 expansion slots are empty. Lets assume I have 128kb of program data on a floppy. How much of this can actually be stored on the system at once, and where?

edit: Grauwl, thank you very much for maintaining your website, your examples of how to read the keyboard register and system registers were very easy to understand.

By ARTRAG

Enlighted (6242)

ARTRAG's picture

27-04-2019, 23:27

In a nutshell, the bios at boot time will scan for rom headers and will activate the first slot with a valid "AB" signature in the page 4000h-7FFFh (just 16KB!). The system does not swaps the BIOS out.
When your start address is called, you will find BIOS at 0000h-3FFFFh, your rom at 4000h-7FFFh and RAM at 8000h-FFFFh (if your system has at least 32KB of ram, but for msx2 all machines have at least 64KB of ram).

If you need a window of 32KB on your rom, you have to swap out the 16KB of ram at 8000h-BFFFh. This is done by reading the slot and the sub-slot where your rom is in 4000h-7FFFh and setting the same slot and subslot in page 8000h-BFFFh.

This is a common configuration e.g. for megaroms, where you can swap the mapped pages of your rom in the 32KB window from 4000h to BFFFh and you use the bios in 0000h-3FFFh. Moreover, when megaroms are swapped in at page 0 (0000-3FFF), can show different behaviors according to the implementation.

The contra are that:
1) the BIOS, apart maybe for the slot management code, is almost wasted space, and
2) your RAM is limited to 16KB of ram in C000h-FFFFh.

Actually you could use the ram mapper in that area to access the rest of the system RAM, but it is a very bad idea, because it would swap out the stack (!!) and some useful system data.

If you need more RAM, or simply you are not using a megarom and you need to access to more rom space, you can swap out the bios and swap in RAM or your ROM in 0000-3FFF. This implies you need to define your ISR handler at 030h and manage slot and subslots with your own code.

By NYYRIKKI

Enlighted (5381)

NYYRIKKI's picture

28-04-2019, 10:06

I'll give a try explaining the options as well...

In BASIC the BIOS+BASIC is located in #0000-#7FFF and RAM is in #8000-#FFFE
When you make a ROM the situation is like in BASIC before your program is called... The process goes so that it looks for "AB"-header first from #4000 and then from #8000... If it finds one, it will read next two bytes (#4002/#8002) and make an interslot call to that address. What this means is that the start address actually defines what 16KB block from your ROM is selected as visible at startup. After that it is up to you to change the memory layout as you want. MSX2 technical handbook has some practical assembly examples.

The BIOS routines are indeed called from addresses below #200 but you are then accessing only the standard jump table. The actual BIOS routines are located in somewhere #200-#2E00 (about) and in case of MSX2 also part of the routines are in SUB-ROM, but you don't need to worry about that. The BIOS will swap the ROMs without you need to know about it. In case you want to loan floating point math or something like that from BASIC then you may want to keep the whole #0000-#7FFF as ROM, but for normal BIOS routines it is enough that you have #0000-#3FFF as ROM.

In DOS all of the 64KB memory space is used for RAM. In case you need to access BIOS routine like that #5F you need to use interslot call or similar. Here is one example how to make it easily:

CHANGE_MODE:
	LD A,4
	RST #30
	DB #80 ; SlotID
	DW #5F ; BIOS-routine
	RET

The .COM programs in DOS are always loaded to #100 and if you are familiar with MS-DOS or CP/M programming you should feel like home with MSX-DOS as well... Since the BDOS disk routines are actually in ROM the same routines are easily available in BASIC as well, but in ROM environment you need to do few tricks first if you want to use the disk drive & files.

Page 4/7
1 | 2 | 3 | | 5 | 6 | 7