Difference between revisions of "83Plus:Memory Mapping"
(Add naming conventions) |
(Port 27 and 28) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 36: | Line 36: | ||
The page 0 region in fixed to flash page 0 in normal operation on all models. (*However, when the calculator boots, it contains the boot page temporarily, but there is no way to make it come back after booting; see [[83Plus:State of the calculator at boot]] for more information.) | The page 0 region in fixed to flash page 0 in normal operation on all models. (*However, when the calculator boots, it contains the boot page temporarily, but there is no way to make it come back after booting; see [[83Plus:State of the calculator at boot]] for more information.) | ||
− | Memory Bank A (MemA) is selected by [[83Plus:Ports:06|port 6]], and MemB is selected by [[83Plus:Ports:07|port 7]]. The C000 region contains RAM page 0. There is no way to change the page in C000 on the TI-83+. Flash memory pages run from 00h to 1Fh, inclusive. You can also map RAM into MemA and MemB. To do so, write 40h (R0) or 41h (R1) to port 6 or 7 . Normally, R1 is in 8000 (meaning write 41h to port | + | Memory Bank A (MemA) is selected by [[83Plus:Ports:06|port 6]], and MemB is selected by [[83Plus:Ports:07|port 7]]. The C000 region contains RAM page 0. There is no way to change the page in C000 on the TI-83+. Flash memory pages run from 00h to 1Fh, inclusive. You can also map RAM into MemA and MemB. To do so, write 40h (R0) or 41h (R1) to port 6 or 7 . Normally, R1 is in 8000 (meaning write 41h to port 7 for normal operation) and R0 is in C000. |
==== TI-83+SE, TI-84+, TI-84+SE, and TI-84+CSE Memory Map Mode 0 ==== | ==== TI-83+SE, TI-84+, TI-84+SE, and TI-84+CSE Memory Map Mode 0 ==== | ||
Line 95: | Line 95: | ||
|- | |- | ||
|C000-FFFF | |C000-FFFF | ||
− | |Memory Bank | + | |Memory Bank B |
|} | |} | ||
''Even'' page means whatever page number is in port 6 logical ANDed with 3FEh; ''odd'' page means whatever is in port 6 ORed with 1. On the TI-83+, no OR is performed, so writing 10h to port 6 will map page 10h into both 4000 and 8000, whereas on everything else, writing either 10h or 11h will map 10h into 4000 and 11h into 8000. | ''Even'' page means whatever page number is in port 6 logical ANDed with 3FEh; ''odd'' page means whatever is in port 6 ORed with 1. On the TI-83+, no OR is performed, so writing 10h to port 6 will map page 10h into both 4000 and 8000, whereas on everything else, writing either 10h or 11h will map 10h into 4000 and 11h into 8000. | ||
+ | |||
+ | === Partial Page Mapping === | ||
+ | |||
+ | The TI-83+SE and above have two further ports that affect memory mapping (in mode 0 only), ports [[83Plus:Ports:27|27]] and [[83Plus:Ports:28|28]]. These ports partially override the normal memory banks B and C settings, such that part of RAM pages 1 and/or 0 is always present in memory. The ports are rarely used. See their page for more information. | ||
[[Category:83Plus:General Hardware Information|Memory Mapping]] | [[Category:83Plus:General Hardware Information|Memory Mapping]] | ||
[[Category:84PCSE:General Hardware Information|Memory Mapping]] | [[Category:84PCSE:General Hardware Information|Memory Mapping]] |
Latest revision as of 22:10, 19 May 2013
Contents
Overview
The Z80 is a 16-bit processor, able to address 65536 unique bytes of memory automatically. This was a lot of memory when the Z80 was created. Unfortunately, it is no longer nearly enough. Consequently, TI has concocted a complex scheme for memory mapping. In this system, known as paging (which is similar to, but different than, paging and virtual memory on x86/x64 PCs), the calculator's logical 24-bit address space for flash and RAM is mapped to the Z80s 16-bit physical address space in blocks known as pages.
Each page is 4000h (16384d) bytes long, so up to four pages can exist in the Z80's physical address space at once. For example, whenever an assembly program is run, you will find that flash memory data from addresses 1C000h to 1FFFFh are in Z80 addresses 4000h to 7FFFh. By writing to port 6, you can make a different set of flash memory appear in 4000h to 7FFFh.
There are four memory mapping regions, each also 4000h bytes long, starting at 0000h, 4000h, 8000h and 0C000h. The TI-83+ has 20h different 16 K flash pages, TI-84+ has 40h, the TI-83+SE and TI-84+SE have 80h, and the TI-84+CSE has 100h. The first flash page is named page 0, and the last flash page is, respectively, 1Fh, 2Fh, 3Fh, 7Fh, or 0FFh.
There are also multiple RAM pages. The TI-83+ has two RAM pages. Everything else has either 3 or 8 pages, depending on the ASIC version; 48 K of RAM implies 3 pages, whereas 128 K of RAM implies 8 pages.
Naming Conventions
For brevity, you can refer to a single flash page by the notation F:nn, where nn is any flash page number in hex (-h suffix not required), e.g., "The TI-84+ has the certificate on F:3E.". Similarly, RAM pages are prefixed with R: or R. Additionally—contrary to previous convention—RAM pages are not numbered starting from 80h. So, the TI-83+ has two RAM pages, R0 and R1 or R:0 and R:1. Additionally, P: refers to ports (e.g. P:10 for the LCD command port), and on the TI-84+CSE, LR: refers to LCD registers.
Additionally, because there a difference between the addresses the CPU sees and the addresses programs abstractly work with, we must sometimes specify which type we are referring to. A physical address is the address the CPU sees; a logical address is the combination of page and address. Additionally, we may also think about hardware addresses, of which there are two types: RAM and flash. They refer to each type of memory as a single contiguous block. RAM hardware address range from either 0000 to 7FFF, 00000 to 0BFFF, or 00000 to 1FFFF. Flash hardware addresses are 000000-07FFFF, 000000-0FFFFF, 000000-1FFFFF, 000000-2FFFFF, or 000000-3FFFFF. (Hardware people may think this is backwards. From the point-of-view of hardware, it is. But we're software programmers, not hardware developers.)
Details
Memory Map Mode 0
However, choosing what flash memory exists in a given bank is not as simple as writing the page to a port. Oh, no. First, there are two memory mapping modes, 0 and 1, which on the TI-83+ behave slightly differently than on everything else. The current memory map mode can be set using port 4, but there's no way to read it.
TI-83+ Memory Map Mode 0
Range | Name |
0000–3FFF | Flash Page 0 (fixed*) |
4000-7FFF | Memory Bank A (MemA) |
8000-BFFF | Memory Bank B (MemB) |
C000-FFFF | RAM Page 0 (fixed) |
The page 0 region in fixed to flash page 0 in normal operation on all models. (*However, when the calculator boots, it contains the boot page temporarily, but there is no way to make it come back after booting; see 83Plus:State of the calculator at boot for more information.)
Memory Bank A (MemA) is selected by port 6, and MemB is selected by port 7. The C000 region contains RAM page 0. There is no way to change the page in C000 on the TI-83+. Flash memory pages run from 00h to 1Fh, inclusive. You can also map RAM into MemA and MemB. To do so, write 40h (R0) or 41h (R1) to port 6 or 7 . Normally, R1 is in 8000 (meaning write 41h to port 7 for normal operation) and R0 is in C000.
TI-83+SE, TI-84+, TI-84+SE, and TI-84+CSE Memory Map Mode 0
Range | Name |
0000–3FFF | Flash Page 0 |
4000-7FFF | Memory Bank A (MemA) |
8000-BFFF | Memory Bank B (MemB) |
C000-FFFF | Memory Bank C (MemC) |
Like the TI-83+, Memory Bank A (MemA) is selected by port 6, and MemB is selected by port 7. On the TI-84+CSE, ports 0E and 0F also play a role in selecting flash pages. Specifically, for MemA, the value in port 0E sets bits 7 and 8 of the flash page selected; 0F does the same thing for MemB. That is to say, if you set 0E to 00, the value in port 06 will select a flash page between 00 and 7F, and if you write 01, the value in port 06 will select a flash page between 80 and FF. Bit 1 of 0E and 0F are ignored on the TI-84+CSE. On the TI-84+/SE, both bits of 0E and 0F are ignored, because there is less flash. (But, see the page for 0E and 21 for more information.)
Unlike the TI-83+, on everything else RAM pages are not selected in MemA and MemB by setting bit 6 (40h = 0100 0000). Instead, they are selected by setting bit 7 (i.e. hex numbers starting with 8). Normally, R1 (write 81h) is in MemB. On everything but the TI-83+, the RAM page in the C000 region can be changed with port 5, which is known as MemC. Only RAM can be mapped into MemC, and the numbers you write and read from port 5 are not prefixed with 8. If you write 81h to port 5, you will get R1 in 0C000h, but when you read port 5, you will see 01h, not 81h. Normally, like on the TI-83+, R0 is in MemC.
Memory Map Mode 1
Memory map mode 0 is the normal mode. Disassembling the boot code makes it clear that the boot code changes the memory map mode to mode 1 briefly when booting. Thereafter, TI never changes it again in any software. Little, if any, 3rd-party software uses Memory Map Mode 1.
TI-83+ Memory Mode 1
Range | Name |
0000–3FFF | Flash Page 0 |
4000-7FFF | Memory Bank A even page |
8000-BFFF | Memory Bank A |
C000-FFFF | Memory Bank B |
TI-83+SE, TI-84+, TI-84+SE, and TI-84+CSE Memory Map Mode 1
Range | Name |
0000–3FFF | Flash Page 0 |
4000-7FFF | Memory Bank A even page |
8000-BFFF | Memory Bank A odd page |
C000-FFFF | Memory Bank B |
Even page means whatever page number is in port 6 logical ANDed with 3FEh; odd page means whatever is in port 6 ORed with 1. On the TI-83+, no OR is performed, so writing 10h to port 6 will map page 10h into both 4000 and 8000, whereas on everything else, writing either 10h or 11h will map 10h into 4000 and 11h into 8000.
Partial Page Mapping
The TI-83+SE and above have two further ports that affect memory mapping (in mode 0 only), ports 27 and 28. These ports partially override the normal memory banks B and C settings, such that part of RAM pages 1 and/or 0 is always present in memory. The ports are rarely used. See their page for more information.