writing to flashrom (2MB rom) and support for emulators

Pagina 4/8
1 | 2 | 3 | | 5 | 6 | 7 | 8

Van norakomi

Paragon (1084)

afbeelding van norakomi

03-05-2020, 12:47

Thanks Giangiacomo

Quote:

If needed I can arrange a KONAMI mapper version or ASC16 ASCII 16KBytes pages.

That would be great.
I only need 2 routines to get started:
1) erasing a romblock
2) writing 1 byte to a romblock

I wrote these 2 routines, but I'm not sure if this is correct... I can't really test it until the emulation is available (I don't have an msx atm to test it with).
The routines I have written are:
1) erasing a romblock:

EraseBlock:
	ld 		a,(slot.page12rom)		; alles RAM behalve in page 1+2
	out 	($a8),a	
	
	ld		a,$fc                 ; erase block $fc-$ff (64kb)
	call	block1234

  ld    a,%0101 0000  ;Flash write enable + A20 / FlashROM address lines to switch 2 MB banks.
  ld    ($7fff),a
  
;erase block command
	LD		A,$AA
	LD		($4555),A
	LD		A,$55
	LD		($42AA),A
	LD		A,$80
	LD		($4555),a
	LD		A,$AA
	LD		($4555),A
	LD		A,$55
	LD		($42AA),A
	LD		A,$30					; sector erase
	LD		($4000),a				; matra style
;	LD		($4555),a				; pasos style

	LD		B,0						; after erasing wait 2 seconds
	EI
.waitloop:
	HALT
	DJNZ	.waitloop
	ret

2) writing 1 byte to a romblock

WriteToSram:
	ld 		a,(slot.page12rom)		; all RAM except page 1+2
	out 	($a8),a	
	
	ld		a,$fc         ;set block $fc-$ff in page 1+2
	call	block1234

  ld    a,%0101 0000  ;Flash write enable + A20 / FlashROM address lines to switch 2 MB banks.
  ld    ($7fff),a
  
WriteOneByteToFlash:
	LD		A,$AA
	LD		($4555),A
	LD		A,$55
	LD		($42AA),A
	LD		A,$A0
	LD		($4555),a
	
	LD		A,100     ;write value 100
	LD		($4000),A

.WaitUntilByteWritten:
	LD		A,($4000)
	CP		100
	JR		NZ,.WaitUntilByteWritten
	RET

This should work I think... but again... I'm not sure

I saw this piece of code in your program above:

	ld	a,0f0h
	ld	(4000h),a	; The Reset command is required to return to reading array data when device is in the autoselect mode
	ld	a,0aah
	ld	(4555h),a	; unlock cycle #1
	ld	a,055h
	ld	(42aah),a	; unlock cycle #2
	ld	a,090h
	ld	(4555h),a	; Autoselect Mode ON command

Can you try to explain what that is for ?

Van Manuel

Ascended (16851)

afbeelding van Manuel

03-05-2020, 15:24

norakomi wrote:

no, it doesn't work like that.

On a real msx, I insert the rom into the msx, and then I can save to the flashrom.
But on the emulator it doesn't work.

Which cartridge are you talking about here, exactly? Manbow 2? MegaFlashROM?

You said in reply to me:

norakomi wrote:
manuel wrote:

the flashing process is emulated

Can you explain me how I can do this in openmsx ?

I was simply telling to daemos, that the flashing process of the MegaFlashROM SCC+ cartridges is emulated. Then you asked me how you can do this in openMSX. I assumed you meant "how can we flash in openMSX?" Then the answer really is: exactly like on real hardware. Just follow the steps from the MegaFlashROM manual as if you are using a real MegaFlashROM cartridge.

Quote:

It's the same issue I had back then with Manbow2.

For bluemsx, a special romtype was develloped/added (romtype: manbow2).
You then you had insert the manbow.rom into bluemsx, and choose romtype: manbow2.
Then the ability to save to flashrom was enabled.

In openmsx there was a similar option.
(carta manbow2.rom -romtype manbow2)

This is the same as inserting a real Manbow 2 cartridge. From only the ROM file, the emulator cannot know which hardware is around it (in case of a Manbow 2 cartridge, the hardware is a flash ROM chip and some extra stuff), so you have to tell the emulator. Note that for the (official) Manbow 2 ROM, openMSX knows it from a database and will use the proper manbow2 mapper type automatically. But any new program/game is of course not in that database.

But it is exactly equivalent to inserting a real Manbow 2 cartridge, from MSX point of view.

Quote:

But now the story is slightly different, because the rom we use now is 2MB.

So trying the same thing doesn't work now.

If your games would be the same size you could have used the same hardware as Manbow 2 and then also telling the emulator to emulate that same hardware.

But your games are larger, so you need different hardware on the cartridge and the emulation must be made to match that hardware.

I hope it's clearer now. Please ask if something is still not clear.

Van Daemos

Paragon (1713)

afbeelding van Daemos

03-05-2020, 16:00

Manuel, Thank you for your expalantions. I got everything to run in emulation.

Another good news is that I finally managed to write a byte to the megaflashrom! Smile

Actually as of writing I got it to work on the megaflashrom wooot

Van Manuel

Ascended (16851)

afbeelding van Manuel

03-05-2020, 16:14

Daemos: regarding SRAM: perhaps you can support the PAC (and thus also the FM-PAC) SRAM? That's actually meant to save game data in, unlike the turboR SRAM. And it's available widely.

Van Daemos

Paragon (1713)

afbeelding van Daemos

03-05-2020, 16:24

exploring the fmpak as well. Shouldn't be too difficult to support but it will require some code to be written and eventually be tested on real hardware.

What is very interesting is that I can flash a byte into the megaflashrom in emulation but in the exact same situation not in the real hardware. The real hardware always returns 0. Things are getting more wierd by the minute.

Van norakomi

Paragon (1084)

afbeelding van norakomi

03-05-2020, 16:37

deleted

Van Daemos

Paragon (1713)

afbeelding van Daemos

03-05-2020, 17:33

eraseflashrom:

    di
    
    ;reset command
    ld a,$aa
    ld ($4aaa),a
    ld a,$55
    ld ($4555),a
    ld a,$f0
    ld ($4000),a
    
    ;erase block command
    ld a,$aa
    ld ($4aaa),a
    ld a,$55
    ld ($4555),a
    ld a,$80
    ld ($4aaa),a
    ld a,$aa
    ld ($4aaa),a
    ld a,$55
    ld ($4555),a
    ld a,$30
    ld ($4000),a    

    ;read command
    ld a,$f0
    ld ($4000),a 
    
    
    ei
  
    ld b,10
    .wait:
    halt ;wait some time
    djnz .wait
  
    
    ret
    



writetoflashrom:

    di
    
    ;reset command
    ld a,$aa
    ld ($4aaa),a
    ld a,$55
    ld ($4555),a
    ld a,$f0
    ld ($4000),a
    
    ;write command
    ld a,$aa
    ld ($4aaa),a
    ld a,$55
    ld ($4555),a
    ld a,$a0
    ld ($4aaa),a
    ld a,(color)
    ;ld a,55
    ld ($4000),a
    
    ;read command
    ld a,$f0
    ld ($4000),a  
    
    
    
	ei
	
    ret

This works perfectly in emulation. I select a block switch to that block perform a write command and the bytes get written into the megaflashrom. On a real megaflashrom however it doesn't stick. The read also returns only zeros while in emulation it returns $FF.

Also writing into block $04 erases the header.

Ideas??

Van max_iwamoto

Champion (487)

afbeelding van max_iwamoto

03-05-2020, 17:53

Daemos wrote:

exploring the fmpak as well. Shouldn't be too difficult to support but it will require some code to be written and eventually be tested on real hardware.

I created FMPAC save for Woody Poco translation. I want to share it here and hope it helps. Usually companies used 8 save slots fro their games (each 1KB in size). But since data was a lot smaller, I added extra subslots from "A" to "P".

The code consists of 2 parts. 1st part runs at start and finds FMPAC slot (if present). And 2nd part saving or loads the data. I can also see from code now that FMPAC doesn't work good with turbo mode enabled, so it should be disabled during wrting to FMPAC and re-enabled after (if turbo mode used of course). "WP" is used as ID that save data present in current slot. Can be changed to anything else.

Let me know if you have any questions.

PART 1 - DETECTING FMPAC

SCANSLT:
	XOR	A		; start from slot 0
	LD	HL,0FCC1h
.loop:
	LD	C,(HL)
	OR	C
.loop2:
	EXX

	PUSH	AF

	LD	H,40h
	CALL	ENASLT

	CALL	.chk_FM

	POP	AF

	EXX

	ADD	A,%00000100	; increase subslot number
	LD	C,A		; C = new slot+subslot
	BIT	7,A		; check if slot expanded
	JR	Z,.next		; if not expanded go for next slot
	AND	%00001100	; check if already checked all subslots
	LD	A,C
	JR	NZ,.loop2	; still some subslots left
.next:
	INC	HL
	LD	A,C
	INC	A
	AND	%00000011
	RET	Z		; return if all slots & subslots are checked!
;
	JR	.loop

.chk_FM:
	LD	DE,(5FFEh)

	LD	HL,694Dh	; enable FM-PAC SRAM
	LD	(5FFEh),HL

	LD	HL,4000h

	LD	A,(HL)
	INC	A
	LD	(HL),A
	CP	(HL)
	JR	NZ,.exit

	DEC	A
	LD	(HL),A		; return previous value to RAM

	LD	(5FFEh),HL	; disable SRAM

	LD	A,(HL)
	INC	A
	LD	(HL),A
	CP	(HL)
	JR	Z,.exit

	POP	HL
	POP	AF

	LD	(FMPAC.fmslt),A		; save FM-PAC slot
	RET

.exit:
	LD	(5FFEh),DE	; return previous value to 5FFE
	RET

PART 2 - SAVE / LOAD DATA

FMPAC:
	LD	HL,FMTXT01
	CALL	.print

.k1:
	CALL	.wait_k
	OR	20h
	CP	"s"
	JR	Z,.workFM
	CP	"l"
	JR	Z,.workFM
	CP	"e"
	RET	Z

	JR	.k1

.workFM:
	LD	(.mode),A	; store SAVE or LOAD mode

	LD	HL,FMTXT02
	CALL	.print

.loop1:
	CALL	.wait_k

	CP	31h
	JR	C,.loop1
	CP	39h
	JR	C,.cont1

	OR	20h
	CP	"q"
	RET	Z

	JR	.loop1

.cont1:
	AND	0Fh
	DEC	A
	RLCA
	RLCA
	LD	(.slot),A	; A = SAVE SLOT NUMBER

	LD	HL,FMTXT03
	CALL	.print

.loop2:
	CALL	.wait_k

	OR	20h
	CP	"a"
	JR	C,.loop2
	CP	"q"
	JR	C,.cont2

	RET	Z

	JR	.loop2

.cont2:
	SUB	61h		; A = SAVE DATA NUMBER in CURRENT SAVE SLOT

	LD	H,00h
.slot:	EQU	$-1

	RRCA
	RRCA
	LD	C,A
	AND	%11000000
	LD	L,A
	LD	A,C
	AND	%00000011
	OR	H
	OR	40h		; SRAM location 4000..5FFF
	LD	H,A		; HL = SRAM save / load address

	CALL	checkTR
	JR	NZ,.no_TR
	XOR	A
	CALL	0180h		; disable turbo mode

.no_TR:
	DI
	PUSH	HL

	CALL	CEC8.gen_KW	; generate RAW KEYWORD

	LD	A,0FFh		; FM-PAC slot
.fmslt:	EQU	$ - 1

	CALL	.enaslt

	LD	HL,694Dh	; enable FM-PAC SRAM
	LD	(5FFEh),HL

	POP	HL

	LD	DE,0F128h
	LD	BC,003Ch

	LD	A,00h
.mode:	EQU	$ - 1
	CP	"s"
	JR	Z,.save
.load:
	LD	A,"W"
	CP	(HL)
	JR	NZ,.error
	INC	HL
	LD	A,"P"
	CP	(HL)
	JR	NZ,.error
	INC	HL

	LDIR

	CALL	.setROM		; return Woody Poco ROM to 4000h

	JP	CHECKPW		; validate data

.error:
	CALL	.setROM

	JP	0D09Dh		; print error message if there is no Woody Poco game data

.save:
	LD	(HL),"W"
	INC	HL
	LD	(HL),"P"
	INC	HL
	EX	DE,HL
	LDIR

.setROM:
	LD	(5FFEh),HL

	LD	A,(0FDA0h)	; get ROM slot from int subroutine

	CALL	.enaslt

	CALL	checkTR
	RET	NZ

	JP	RET_TUR		; return turbo mode

.enaslt:
	LD	H,40h
	JP	0024h

.wait_k:
	CALL	0156h
	JP	009Fh

.print:
	PUSH	HL
	CALL	4A70h
	POP	HL
.ploop:
	LD	A,(HL)
	OR	A
	RET	Z
	PUSH	HL
	CALL	4A10h		; PRNnoSH
	POP	HL
	INC	HL
	JR	.ploop

FMTXT01:
	DB	"S : SAVE to SRAM",0Dh
	DB	"L : LOAD from SRAM",0Dh
	DB	"E : Exit",0

FMTXT02:
	DB	"Select SLOT 1..8",0Dh
	DB	"Q : Quit",0

FMTXT03:
	DB	"Select DATA A..P",0Dh
	DB	"Q : Quit",0

Van norakomi

Paragon (1084)

afbeelding van norakomi

03-05-2020, 18:02

Quote:

But your games are larger, so you need different hardware on the cartridge and the emulation must be made to match that hardware.

It's clear now.
Is it possible that you make this emulation ?
If the emulation is working then we can test it better, and also in the end people will be able to play the .rom version as well a the physical release.

Van Manuel

Ascended (16851)

afbeelding van Manuel

03-05-2020, 19:05

norakomi: I can, but only if it's clear which hardware is going to be emulated. That's why I asked about that. And at the moment, the hardware seems to be not capable of partly making the flash read/write and partly making it readonly. That doesn't have to be a problem (as Grauw also pointed out), but I do need to know this is indeed the thing you're going to use.

@max_iwamoto: does it also support the PAC (so, the plain PAC, without FM-).

Pagina 4/8
1 | 2 | 3 | | 5 | 6 | 7 | 8