Help to read a character from VRAM with ASM

By fpracek

Resident (58)

fpracek さんの画像

17-03-2023, 12:59

Hi,
sorry for my dummy question, but I don'tunderstand how I can read the character present on screen 0 at a specific position.

I think to use out(#98) instruction (in a specific address), but I don't understand where I can find the character code after its execution.

If I'd read each character on screen 0 (80 columns) I' must read each address from 4000h for (80x26 places). Is it true?

Thanks a lot

ログイン/登録して投稿

By aoineko

Paragon (1138)

aoineko さんの画像

17-03-2023, 13:42

The theory: To know the value of the character at column X and row Y, you need to look in VRAM at LayoutTableAddress + Y * 80 + X.

In practice: You can find a good tutorial on the Grauw's MAP website (http://map.tni.nl/articles/vdp_tut.php).
You have to initialize the VRAM address to read (and activating the incremental access if you want to read several data), then a simple in a,(0x98) allows to get the VRAM content in the A register.

Not tested but should work:

; Read VRAM at address AHL (17-bit) and return value in A
VRAM_Peek:
	rlc	h
	rla
	rlc	h
	rla
	srl	h
	srl	h
	di
	out	(0x99),a
	ld	a,14+128
	out	(0x99),a
	ld	a,l
	nop
	out	(0x99),a
	ld	a,h
	out	(0x99),a
        nop
	ei
        in	a,(0x98)
	ret

By fpracek

Resident (58)

fpracek さんの画像

17-03-2023, 13:59

Thanks for info, but I don't undestand 17 bit value (reg A and HL?)

By santiontanon

Paragon (1832)

santiontanon さんの画像

17-03-2023, 14:08

Maybe aoineko is considering the general case of an MSX2 where there can be more than 64KB of VRAM, and hence you need addresses bigger than 16bit?

By thegeps

Paragon (1260)

thegeps さんの画像

17-03-2023, 15:09

Yep, the example is about V9938. Screen 0 (80 columns) is indeed an MSX2 mode

By fpracek

Resident (58)

fpracek さんの画像

17-03-2023, 15:37

Yes, I understand it is an MSX2 example and for me it's ok, but I neet to know how I must use this function, because I don't know how I must put the adress into the ALH. I never used ALH before.
Can you give me an example, please?
Thanks

By aoineko

Paragon (1138)

aoineko さんの画像

17-03-2023, 15:39

Put address bits #0 to #15 in HL and bit #16 in A (so yes, A will be 0 or 1).

By aoineko

Paragon (1138)

aoineko さんの画像

17-03-2023, 23:30

BTW, you have a BIOS function to do that easily.
Function is named RDVRM and located at address 0x004A.
Just set address in HL, call 0x004A, then you get the return value in A.

By fpracek

Resident (58)

fpracek さんの画像

18-03-2023, 10:12

RDVRM is perfect!!!
Thanks!!!

By aoineko

Paragon (1138)

aoineko さんの画像

18-03-2023, 15:01

If you don't need 100% of the power of an MSX, you have plenty of functions in the BIOS to perform all the operations you might need to create an MSX application.
You have the list here: https://map.grauw.nl/resources/msxbios.php