Alone Cáfe
There is no limit to learning.
阿龙咖啡
编写 NES 模拟器的难题记录

关于 Bank Switching 的含义

The bank switching technique provides a way for computer systems to access more memory than they would otherwise be capable of. When a computer processor is limited to a specific amount of addressable memory space, additional banks of memory can be set up for the processor to use. These separate banks can then be used to switch away from code that is no longer being used, such as read only memory (ROM) used when starting up the computer, and open up banks of memory for multiple users on the system or store memory for other devices on the system.

Bank switching came about as a cost-effective way to keep computers up and running back in the 1980s without having to replace the processor. It found a good deal of use on older 8-bit computer systems, extending the useful life of a computer by simply adding more memory. As newer systems were developed, they also implemented bank switching methods so that programs created on the older systems could still run.

The way bank switching works is by implementing what’s called a latch technique. The latch is really just something of a switch that toggles the address space that the computer processor is using. For example, 8-bit computers use a 16-bit address space, meaning that they are only capable of working with 64K, or 65,536, individual memory locations at any given time. When a latch was added, either by means of software or hardware, it could then toggle between multiple banks of memory.

The latch is set up separate from the processor, leaving the bank switching in the hands of an external operation. In some cases, it’s simply a bit hiding out in the upper register of memory addresses and toggled as necessary by the computer’s operating system or some other software. As the memory fills, the processor can check the bit at the top and toggle to another bank. Other methods of decoding the latch involved bit-addressable ports that granted access to another bank of memory.

Bank switching found its way into a number of video game consoles from the era as well. The ROM cartridges would come equipped with additional hardware built-in that would expand the console beyond its limited available memory space, allowing for better graphics in games and longer game play through additional stages. As technology and techniques improved, however, the method fell out of use. Some modern operating systems can still emulate bank switching in order to operate older software. Many modern embedded computer systems, those computer systems built into some other device or system and typically designed to perform a single task, also still use bank switching due to its cost effectiveness and ease of use.

一个文件中间有0x1A字符(会触发EOF()),这样的文件如何用文件流读取?

我用的是ifstream,文本方式打开,用EOF()来控制读操作结束,结果读到这个1A的时候ifstream的EOF()就被触发了,所以後面的内容就读不下来了。

解决方案

std::ifstream in("path/to/file", std::ios::binary);
赞赏
知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。欢迎转载、使用、重新发布,但务必保留文章署名。

发表评论

textsms
account_circle
email

阿龙咖啡

编写 NES 模拟器的难题记录
关于 Bank Switching 的含义 The bank switching technique provides a way for computer systems to access more memory than they would otherwise be capable of. When a computer …
扫描二维码继续阅读
2020-04-01