














Warning
If someone is reading this blog, please be aware that the writer DID NOT consider the experience of the other readers.
After all, the most important thing is about writing things down for better memorization.
CONFIG_AUDIO_CTL_MMIO(0xa0000200) when initializing corresponding devices.rtc_io_handler which effectively returns the uptime in us as a 64-bit int.inl), we have to ‘read’ twice for the complete 64-bit data.There seems to be quite a lot of things going on in nemu/src/device/keyboard.c, but it’s a quite simple task as long as one understand the interaction logic between AM and NEMU, as there’re only 4 bytes(AKA 1 32-bit int) representing a keycode being registered at CONFIG_I8042_DATA_MMIO(0xa0000060).
There’s an interesting design #define KEYDOWN_MASK 0x8000 in AM. It is basically an indicator of whether the key is pressed or released. Here’s how it works:
KEYDOWN_MASK, if the result is 1, that means a pressed key, and vice versa.Fun_Fact
This 15th bit convention is primarily a Windows-specific implementation detail.
Other systems have other conventions, like using XKeyEvent structure on X11(Linux/Unix).
This is a quite troublesome part. Here’s the deal:
CONFIG_FB_ADDR0xa1000000) with the api provided by AM(io_write).FB_ADDR(same as CONFIG_FB_ADDR). There’re no callback function for frame buffer in NEMU, so it is direct write to vmem.1, NEMU will use the data in frame buffer to update the screen.The code in am-kernels/kernels/typing-game is really fun, especially this part:
1 | for (int ch = 0; ch < 26; ch++) { |
This is where each english letter is ‘pre-painted’. By checking each bit(pixel) of the letter with bitwise operation, the program effectively find out the alpha value of each pixel. Then, it writes color data into the corresponding place in texture, COL_PURPLE for zero-alpha pixel.
This is the most difficult part of the emulated device done in PA2. Mostly because it requires a ring buffer queue which is written and read by differenct programs(AM & NEMU). Also, Learning SDL is also a troublesome part, cuz I really don’t consider its official wiki very friendly.
Most of my time was spent on tuning the ring buffer, which is kinda like a producer-consumer model I learnt in OS lessons before. It was the first time that I implement some theoretical OS stuff into actual program, it really took me a while to fix all these bugs created by a fool filled with ignorance, which is me…
Anyway, the core idea is like this:
CONFIG_SB_ADDR).sbuf, the ring buffer) when there’re enough space.sbuf) and copy them to SDL2’s stream. BTW, this process is actually done in SDL_Audio’s callback function.Key difficulties when maintaining sbuf:
When AM writes audio data:
count + len <= sbuf_size). If not, halt until there are.When NEMU reads audio data:
sbuf(count >= 0). If not, return.In real practice, the speed of AM writing audio data is significantly faster than NEMU reading, as the frequency of calling SDL2’s callback function is pretty low.
I want to express my gratitude to:
I will be resting for a while, and then head for the pre-learning of ysyx, which is basicaly knowledge and expirement of Digital Circuit.
Cheers!
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。