## 128k memory paging, how can we do that? :S

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

### 128k memory paging, how can we do that? :S

hi everyone!
based on the information i found at http://www.worldofspectrum.org/faq/refe ... erence.htm

i tried this one:
Code:
`clspage1=0a=(((peek(\$5B5C))band \$F8)bor (page1 band 7))poke \$5B5C,a:out \$7FFD,apoke \$C123,80page1=1a=(((peek(\$5B5C))band \$F8)bor (page1 band 7))poke \$5B5C,a:out \$7FFD,apoke \$C123,81page1=0a=(((peek(\$5B5C))band \$F8)bor (page1 band 7))poke \$5B5C,a:out \$7FFD,aprint peek(\$C123)page1=1a=(((peek(\$5B5C))band \$F8)bor (page1 band 7))poke \$5B5C,a:out \$7FFD,aprint peek(\$C123)pause 0`

and i can't figure out what is going wrong there...- any clue? :S

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

### Re: 128k memory paging, how can we do that? :S

now it seems weird why

Code:
`clspoke 23388,16:out 32765,16:poke 50000,16poke 23388,17:out 32765,17:poke 50000,17poke 23388,19:out 32765,19:poke 50000,19poke 23388,20:out 32765,20:poke 50000,20poke 23388,22:out 32765,22:poke 50000,22poke 23388,23:out 32765,23:poke 50000,23poke 23388,16:out 32765,16:print peek (50000)poke 23388,17:out 32765,17:print peek (50000)poke 23388,19:out 32765,19:print peek (50000)poke 23388,20:out 32765,20:print peek (50000)poke 23388,22:out 32765,22:print peek (50000)poke 23388,23:out 32765,23:print peek (50000)pause 0`

works, and

Code:
`sub setmemorypage(ta as ubyte)  dim tb as ubyte  tb=(ta band 7)bor 8  poke 23388,tb:out 32765,tb  end subclssetmemorypage(0):poke 50000,80setmemorypage(1):poke 50000,81setmemorypage(3):poke 50000,83setmemorypage(4):poke 50000,84setmemorypage(6):poke 50000,86setmemorypage(7):poke 50000,87setmemorypage(0):print peek(50000)setmemorypage(1):print peek(50000)setmemorypage(3):print peek(50000)setmemorypage(4):print peek(50000)setmemorypage(6):print peek(50000)setmemorypage(7):print peek(50000)pause 0`

isn't... :S

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

### Re: 128k memory paging, how can we do that? :S

fixed (i think...)
Code:
`sub setmemorypage(ta as uinteger)  tb=(ta band 7)bor 16  poke 23388,tb:out 32765,tb  end subclssetmemorypage(0):poke 50000,80setmemorypage(1):poke 50000,81setmemorypage(3):poke 50000,83setmemorypage(4):poke 50000,84setmemorypage(6):poke 50000,86setmemorypage(7):poke 50000,87setmemorypage(0):print peek(50000)setmemorypage(1):print peek(50000)setmemorypage(3):print peek(50000)setmemorypage(4):print peek(50000)setmemorypage(6):print peek(50000)setmemorypage(7):print peek(50000)pause 0`

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

### Re: 128k memory paging, how can we do that? :S

nitrofurano wrote:fixed (i think...)
Code:
`sub setmemorypage(ta as uinteger)  tb=(ta band 7)bor 16  poke 23388,tb:out 32765,tb  end subclssetmemorypage(0):poke 50000,80setmemorypage(1):poke 50000,81setmemorypage(3):poke 50000,83setmemorypage(4):poke 50000,84setmemorypage(6):poke 50000,86setmemorypage(7):poke 50000,87setmemorypage(0):print peek(50000)setmemorypage(1):print peek(50000)setmemorypage(3):print peek(50000)setmemorypage(4):print peek(50000)setmemorypage(6):print peek(50000)setmemorypage(7):print peek(50000)pause 0`

For what I read in the speccy.org forum, you need to disable interruptions (DI) before bankswitching. If an interrupt enters during bankswitching, the computer might hang, or have unpredictable results.

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

### Re: 128k memory paging, how can we do that? :S

Why not use inline ASM? Not tested:
Code:
`sub setmemorypage(ta as ubyte)   ASM      di      ld a,(ix+5)      and 7      or 8      ld bc,32765      out (c),a      ld (23388),a      ei   END ASMend sub`
------------------------------------------------------------

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

### Re: 128k memory paging, how can we do that? :S

LCD wrote:Why not use inline ASM? Not tested:
Code:
`sub setmemorypage(ta as ubyte)   ASM      di      ld a,(ix+5)      and 7      or 8      ld bc,32765      out (c),a      ld (23388),a      ei   END ASMend sub`

This is a perfect case for FASTCALL
Code:
`sub FASTCALL setmemorypage(ta as ubyte)   ASM      di      ; ld a,(ix+5) ; Not needed already in A      and 7      or 8      ld bc,32765      out (c),a      ld (23388),a      ei   END ASMend sub`

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

### Re: 128k memory paging, how can we do that? :S

boriel wrote:
LCD wrote:Why not use inline ASM? Not tested:
Code:
`sub setmemorypage(ta as ubyte)   ASM      di      ld a,(ix+5)      and 7      or 8      ld bc,32765      out (c),a      ld (23388),a      ei   END ASMend sub`

This is a perfect case for FASTCALL
Code:
`sub FASTCALL setmemorypage(ta as ubyte)   ASM      di      ; ld a,(ix+5) ; Not needed already in A      and 7      or 8      ld bc,32765      out (c),a      ld (23388),a      ei   END ASMend sub`

Ooops, you are right, I overseen it. Thanks! Generally I prefer 128K USR0 mode because interrupts are not harmful in this mode.
------------------------------------------------------------

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

### Re: 128k memory paging, how can we do that? :S

LCD wrote:Ooops, you are right, I overseen it. Thanks! Generally I prefer 128K USR0 mode because interrupts are not harmful in this mode.

128K USR0 What is this mode?
(I'm still learning this maybe I can do something for it in the compiler).

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

### Re: 128k memory paging, how can we do that? :S

boriel wrote:
LCD wrote:Ooops, you are right, I overseen it. Thanks! Generally I prefer 128K USR0 mode because interrupts are not harmful in this mode.

128K USR0 What is this mode?
(I'm still learning this maybe I can do something for it in the compiler).

USR0 mode is if you enter in 128 BASIC the command USR0. This resets the machine into 48K ROM but with enabled 128K features like AY or bank switching+second screen.
You cannot use +3 DOS or RAMDISC commands, but you also don't need to POKE 23388 to switch banks, OUT 32765 is enough. DivIDE also works in this mode on Spectrum 128K machines.
------------------------------------------------------------

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

### Re: 128k memory paging, how can we do that? :S

LCD wrote:
boriel wrote:
LCD wrote:Ooops, you are right, I overseen it. Thanks! Generally I prefer 128K USR0 mode because interrupts are not harmful in this mode.

128K USR0 What is this mode?
(I'm still learning this maybe I can do something for it in the compiler).

USR0 mode is if you enter in 128 BASIC the command USR0. This resets the machine into 48K ROM but with enabled 128K features like AY or bank switching+second screen.
You cannot use +3 DOS or RAMDISC commands, but you also don't need to POKE 23388 to switch banks, OUT 32765 is enough. DivIDE also works in this mode on Spectrum 128K machines.

Interesting!!!!
Could it be possible to start this mode without resetting the RAM? I mean: Executing a program in 128K mode in ZXBASIC and the program manages in some way to enter that mode an continue execution? Seems a good start.
Another question: I guess +2 ROM won't be available. Will it be?

Posts: 596

Joined: Fri Feb 13, 2009 3:11 pm

Location: Vienna, Austria

### Re: 128k memory paging, how can we do that? :S

boriel wrote:Interesting!!!!
Could it be possible to start this mode without resetting the RAM? I mean: Executing a program in 128K mode in ZXBASIC and the program manages in some way to enter that mode an continue execution? Seems a good start.

Maybe switching to the 48K ROM and jumping in the 48K Editor routine will do the job... I think, the topic was discussed on WOS before.
boriel wrote:Another q#uestion: I guess +2 ROM won't be available. Will it be?

It won't be available unless you page it in.
------------------------------------------------------------