questions about mmu and layer2

Do you live and breathe hexadecimal? Do you like speaking to hardware directly?

Moderator: Programming Moderators

Posts: 10
Joined: Thu Jul 26, 2018 8:55 am

questions about mmu and layer2

Postby Sayman » Fri Aug 17, 2018 6:46 am

Hello! I have some questions, can somebody help me?
1. the pages of the wiki say that the mmu registers ($50 - $57) can be written and read. for change page in some slot`s, i write code like this:

Code: Select all

ld a,page
NEXTREG_A MMU6      ;0xc000 addr area
but, what am i must to do, for read mmu register? in a,(mmu6) read some trash.

2. can i "mount" layer2 screen to other slots? default is slot0 ($0000 - $3fff area). but if i need to set layer2 to 0xc000 or somewhere else, what am i must to do for this?

User avatar
Posts: 287
Joined: Tue May 30, 2017 7:43 pm

Re: questions about mmu and layer2

Postby Timbucus » Fri Aug 17, 2018 8:01 am

Another resource you should check is:

In here you will find the documents for the hardware - the bit you are missing is that the registry needs to first to be told WHICH
registry entry is to be used. So for MMU7 that is $57 (in hex the page is easily seen)

This is part of the code from the UART driver - note that as it will run on interrupt we save the current registry index as we may
interrupt someone's code (or our own) half way between the two OUT's! You can also defend against this with DI/EI around where
you do it in your own code but, this is safer...

Code: Select all

	LD BC,9275		;$243B Need to Save MMU registers

	IN A,(C)		        ;Save current registry state
	LD (saved_reg),A
	LD A,$57
	OUT (C),A
	INC B			;$253B
	IN A,(C)
	LD (saved_mmu7),A			
	LD A,(stream0_mmu7)	;The page I want to switch too
	OUT (C),A

	DEC B			;$243B
	LD A,2
saved_reg equ $-1	
	OUT (C),A		;just in case IRQ was in between registry work 

;to put back the original page when I have finished.

	DEFB $ED,$91,$57,$01	
saved_mmu7 equ $-1

I am no expert on the graphics sorry but, yes Layer2 can be put anywhere in the memory map - you just use something like the above code to map in 8K pages 16-21 although exactly which pages the screen is at is affected by the Layer 2 register $123B.

I'm Infinite Imaginations when not in work... PAWS for thought.

Posts: 10
Joined: Thu Jul 26, 2018 8:55 am

Re: questions about mmu and layer2

Postby Sayman » Fri Aug 17, 2018 9:25 am

Layer2 can be put anywhere in the memory map
i don`t think so. all demos that i see, used 0x0000 - 0x3fff mem area. i can`t found some info in docs about "mount" L2 screen to other slots.

Alcoholics Anonymous
Posts: 780
Joined: Mon May 29, 2017 7:00 pm

Re: questions about mmu and layer2

Postby Alcoholics Anonymous » Fri Aug 17, 2018 1:16 pm

You can put layer 2 into any mmu slot(s) you want. Layer 2 is read from regular memory with one caveat - it must be completely contained in the first 512k chip which means layer 2 must be confined to banks 0-15. The location of layer 2 is controlled by nextreg 0x12:

Code: Select all

(R/W) 0x12 (18) => Layer 2 RAM page
 bits 7-6 = Reserved, must be 0
 bits 5-0 = SRAM page (point to page 8 after a Reset)
It's unfortunate that the documentation is calling this a "page" as it is actually a 16k bank that is written here. The nomenclature is "bank" for 16k banks as on the 128k spectrum and "page" for 8k pages.

If you're running in cooperation with NextOS, you can read the location of layer 2 from nextreg 0x12 but it is highly likely to be sitting in bank 9 which is where NextOS initializes its location. So layer 2 normally occupies banks 9,10,11 or pages 18-23. You can make that memory available in the z80's address space however you like. For example, if you want layer 2 completely visible in the bottom 48k:

Code: Select all

nextreg 0x50,18  ; mmu0 18
nextreg 0x51,19  ; mmu1 19
nextreg 0x52,20  ; mmu2 20
nextreg 0x53,21  ; mmu3 21
nextreg 0x54,22  ; mmu4 22
nextreg 0x55,23  ; mmu5 23
In addition to this, port 0x123b allows one third of layer 2 to be mapped to the bottom 16k write-only so that it can co-exist with the 16k rom. But layer 2 is not readable with this method so whether you can use this or not depends on what you are doing.

As Tim pointed out, reading nextreg state is a two step process. The selected register is written to port 0x243b and data is read/written to the nextreg via port 0x253b. The contents of port 0x243b is part of the state of the program so, as in Tim's example, your isr must read port 0x243b at its start and restore its setting on exit if the isr makes any changes to port 0x243b. This is not a problem for writing to nextregs because writing to a nextreg can be done atomically without altering port 0x243b using the special instruction "nextreg".

Who is online

Users browsing this forum: No registered users and 3 guests