Read Layer 2

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

Moderator: Programming Moderators

Post Reply
johnxmcmanus
Posts: 17
Joined: Mon Aug 07, 2017 8:08 pm

Read Layer 2

Post by johnxmcmanus » Thu Sep 28, 2017 10:09 pm

You cannot read from L2 write location, so you need to use bank swap.
I want to read something from the last 16 row of the screen so bank 2 (0,1,2).
How do I swap bank 2 into memory so I can read it.
I found this snip of code but just pulling back 0 data
;bank switching
LD A,(0x5b5c) ;Previous value of port
AND 0xf8
OR 10 ;Select bank 10
LD BC,0x7ffd
DI
LD (0x5b5c),A
OUT (C),A
EI
Thanks

User avatar
varmfskii
Posts: 183
Joined: Fri Jun 23, 2017 1:13 pm
Location: Albuquerque, NM USA

Re: Read Layer 2

Post by varmfskii » Fri Sep 29, 2017 12:08 am

It looks like there are two ways to page memory on the ZX Next: one which is backward compatible with older Spectrums, and a new one for the Next. The backward compatible one allows you to select which 16k bank resides in solt 4 (0xc000-0xffff). This uses ports 07ffd (or the least significant 3 bits of the page) and 0x1ffd for the most significant 3-bits.
;; bank switch 1
ld a,(0x5b5c)
and a,0xf8
or 0x02 ; least significant 3 bits of 10 (0x0a)
di ; don't allow system access when paging is in an unknown state
ld (0x5b5c),a
out (c),a
ei
ld a,(0x5b67)
and a,0x1f
or 0x20 ; most significant 3 bits of 10 shifted left 5 places
ld bc,0x1ffd
di
ld (0x5b67),a
out (c),a
ei
There is also a ZX Next specific way that allows you to page 8k pages anywhere in the memory map, but it is likely to be incompatible with the system routines that need to know about memory pages. If you want to do the same thing that way, it would look like:
;; bank switching 2
nextreg 0x56,0x14 ; 8k page 20 into 0xc000-0xdfff
nextreg 0x57,0x15 ; 8k page 21 into 0xe000-0xffff

And since you only want the last 16 lines of the screen, you could get away with just:
;; bank switching 3
nextreg 0x57,0x15 ; 8k page 21 into 0xe000-0xffff (last 32 lines of layer2 screen)
Last edited by varmfskii on Sat Sep 30, 2017 3:55 pm, edited 1 time in total.
Backer #2741 - TS2068, Byte, ZX Evolution

johnxmcmanus
Posts: 17
Joined: Mon Aug 07, 2017 8:08 pm

Re: Read Layer 2

Post by johnxmcmanus » Sat Sep 30, 2017 3:08 pm

Thanks will give this a go.

Post Reply