Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
put small ASM programs like bin in a bank 128 and call from basic
#1
hello, good day.

zxbasic:
put small ASM programs like bin in a bank(1,3,4,6)  from spectrum 128 and then call them from basic in the $c000 ?


how does that work please?



thanks.
Reply
#2
Hello @funkheld,

I explain it in detail in my book: https://www.amazon.co.uk/dp/B0CQD65FXZ

Here is the source code of an application that implements bank switching with code execution: https://github.com/Duefectu/BorielBasicG...re/Demo128

In summary, for example: you need to divide your code into a main module that does not exceed the memory address $c000 and create modules of less than 16K that run at $c000. To achieve this, you must split your code and define the variables you want to share in a fixed memory area.

Take a look, and if you have any questions, feel free to ask me.
Duefectu
https://zx.duefectucorp.com
duefectucorp@gmail.com
Reply
#3
Hello , thanks for help.

greeting.
Reply
#4
demo128 :

what is the address $8000 in bank 2 for?

what is bank 7 for?

thanks.
Reply
#5
In this link you have a quick explanation of the operation and distribution of the memory banks in 128K machines: https://worldofspectrum.org/faq/referenc...erence.htm

Regarding address $8000, it is the start of slot 2. The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.

It depends on the architecture you implement, but normally the executable should be located at $8000 as I explain in my book...  Big Grin

But you don't have to use $c000, but you have to plan the structure well and that depends on each project.

Best regards!
Duefectu
https://zx.duefectucorp.com
duefectucorp@gmail.com
Reply
#6
hello thanks for the info.

---------------------------------
The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.
----------------------------------

I don't understand this sentence.

greeting.
Reply
#7
funkheld Wrote:---------------------------------
The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.
----------------------------------

I don't understand this sentence.

Zilog 80 has 16 bit address bus, hence it can work with 2^16 addresses (that is 64K of addressable memory). The processor doesn't make any difference between rom and ram memory, for each memory address there are three possibilities actually - 1. rom, 2. ram, 3. nothing at all. But all the processor does is:
1. read a byte from a memory address (that is from one of 2^16 possible addresses, the processor does not know it it is mapped to rom, ram or nothing at all, it will take whatever is on databus).
2. write a byte to a memory address ( --||-- ).

On different Spectrum models, the memory is mapped differently. Let's see the difference:
First, let's take a look how it is on the early Spectrum 16K model - the first 16K (addresses $0000-$3FFF) is mapped to rom memory, then we have 16K of ram memory (addresses $4000-7FFF), and on the remaining 32K ($8000-$FFFF) there isn't anything physically mounted.
When reading from rom address and from ram address, the processor gets the byte located in that memory location. When reading from an upper address which is not mapped to anything, the processor always gets $FF. The processor does not know the origin of the byte it gets, it just reads the byte and processes it.
When writing, the processor puts the byte it wants to write on databus, puts the two-byte address on address bus and processes the writting normally, but then:
- if the address belongs to ram, the byte is actually written to the memory location at this address.
- if the address belongs to rom or to "nothing", the byte gets lost.
The processor does not know it, it did what it was told to do - write this byte to this address, it does not check whether the byte is actually written anywhere.

On 48K model, we have 16K rom (same as on 16K model), but then whole remaining 48K address space is mapped to the ram memory. So every read actually reads something from physical memory (be it rom or ram). Writing to rom (lowest 16K of address space) is lost, and everything above 16K is actually written to ram memory.

So far so good... But it gets complicated on 128K model - there we have 128K of ram memory, and the same Z80 processor.
As we know this processor can only see the address space of 64K in total. The first 16K belong to rom, leaving only 48K of addressable memory to ram. So, how can we make it use 128K ram?
The answer is - by something called "memory paging". Let's look at the 128K of ram memory as eight memory banks (also called pages), 16K each. We will call them "page 0", "page 1", ... "page 7".
The first 16K belongs to rom (the rom slot - $0000-$7FFF). The following 16K ($4000-7FFF, let's call it the first ram slot) always belongs to ram page 5, the next 16K ($8000-$BFFF - the second ram slot) belongs to page 2.
Then the remaining 16K of addressable memory ($C000-$FFFF - the third ram slot) can be mapped to any ram page! When the Spectrum is turned on, the page 0 is mapped there. However, when the processor executes an "out" instruction to address $7ffd, the page mapped to this "slot" gets changed (the lowest three bits in byte written to this port determine which ram page is going to be switched in - 0 to 7). That is how each byte in the 128K of ram can be accessed.
So I hope you now understand what Duefecty means by:

Duefectu Wrote:The only slot that can be switched is slot 3 which starts at $c000 and ends at $ffff.

Executing an out instruction to address $7ffd does more than switching the ram page on the third slot. So read carefully here and here.

I'd also say that, if you want to use ram pages switching technique, it is usually (depending on your use case it might not be so) good practice to avoid contendend ram pages (on 128K/+2 odd pages are contended, and even pages not, you can find more details about it in the first link I gave above).

I didn't cover +3/+2A models. Although there is also 128K of ram, the ram switching system is somewhat different there, more complicated but more powerful; you can find more in the links given above.

Swan, my ZX Spectrum emulator https://github.com/zoran-vucenovic/swan
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)