14-對(duì)part12-wgt 的搬運(yùn)和翻譯
非黑色字體均為我自己添加
原文放在文章末尾
移植WordUp圖形工具包
????????回到1990年代中(當(dāng)我年輕的時(shí)候!),想要建立自己游戲的程序員并沒(méi)有像Unity那樣豐富的框架.可能我們能得到的最近的就是WordUp圖形工具包,它是我遇到的Hot Sound & Vision CD光盤(pán) -- 一個(gè)BBS文檔.如果你有空,可以去谷歌看看什么是"公告板系統(tǒng)"...懷舊了!
????????就像我非常簡(jiǎn)單的 fb.c,WGT提供了一組圖形庫(kù)的例程,它可以被重用.然而,這個(gè)庫(kù)比我的成熟的多,并且使得它非常用以用來(lái)構(gòu)建基于電子圖形的游戲(比如 Breakout, Space Invaders, Pacman 等).
目錄結(jié)構(gòu)
????????當(dāng)我移植WGT到我自己的OS時(shí)(也就是說(shuō)讓他能在我的操作系統(tǒng)上工作),我使用如下的目錄:
bin/ :為了WGT的二進(jìn)制文件(字體,電子圖形,位圖等)
controller-ios/ :一個(gè)IOS平臺(tái)的Swift示例 BLE控制器
controller-node/ :一個(gè)Node.js示例BLE控制器
include/ :現(xiàn)在同樣包含了wgt.h 和 wgtspr.h (WGT代碼必須的頭文件)
samples/ :我操作系統(tǒng)中執(zhí)行特定WGT庫(kù)函數(shù)的"內(nèi)核"示例.為了執(zhí)行它們,復(fù)制其中一個(gè)到與Makefile相同的文件加下(每次一個(gè)).
wgt/ :庫(kù)本身.在可能的情況下,我一直忠實(shí)于原始代碼,但請(qǐng)記住它是為x86架構(gòu)編寫(xiě)的,我們是在AArch64上!
????????請(qǐng)注意:我不是一個(gè)Node.js開(kāi)發(fā)者,也不是一個(gè)Swift開(kāi)發(fā)者,并且所有的控制器只是單純服務(wù)于我的目的的樣例.它們并不打算成為樣本!我也非常清楚他倆的很多問(wèn)題...
編譯
????????所以...簡(jiǎn)單的在頂部目錄敲下?cp samples/wgt01.c . ,然后敲下make來(lái)編譯第一個(gè)WGT樣例當(dāng)你使用產(chǎn)生的?kernel8.img 啟動(dòng)的時(shí)候你會(huì)發(fā)現(xiàn)屏幕變?yōu)榱?320*200(VGA!)模式,并且從一個(gè)角到另一個(gè)角花了條白線.如果你看到了,那么這個(gè)庫(kù)在做它該做的事!
boot/boot.S的變化
????????我們?nèi)匀粏?dòng)進(jìn)入多核環(huán)境(只是以防我們需要它).然而?boot/boot.S 仍然有一些非常重要的變化.它們是:
啟動(dòng)FPU(浮點(diǎn)運(yùn)算單元),所以我們能使用非整數(shù)數(shù)學(xué)
從EL3(監(jiān)管者異常水平)下降到EL1(內(nèi)核異常水平),禁用MMU
為spin_cpu移動(dòng)地址來(lái)容納更大的boot.S
實(shí)現(xiàn)一個(gè)get_el函數(shù)來(lái)檢查我們?cè)谀膫€(gè)異常級(jí)別(主要為了debug)
使用IOS BLE 控制器
????????為了使用IOS控制器而不是Node.js控制器,確保你有:
#define IOS_CONTROL
????????在wgt/mouse.c 和?lib/bt.c 頂部都有.沒(méi)有這個(gè) #define , 代碼將會(huì)尋找Node.js控制器(如果那是你想要的,就移除它!).
工作正在進(jìn)行!
????????總是有更多的事情可以做,但我認(rèn)為對(duì)讓別人的代碼在你自己的OS上跑的探索是一個(gè)非常好的練習(xí).這真是刺激.
????????嘗試編譯一些樣例(提示:wgt20和wgt60非常的有取!)...
????????我將要從這里出發(fā),這樣我們就能在自己的OS上有所進(jìn)展.
原文如下

Porting the WordUp Graphics Toolkit
Back in the mid-1990s (when I was young!), programmers who wanted to build their own games didn't have rich frameworks like Unity. Perhaps the closest we got was the WordUp Graphics Toolkit, which I came across on the Hot Sound & Vision CD-ROM - a BBS archive. If you have a moment, perhaps use Google to see what "bulletin board systems" were... nostaglia awaits!
Much like my very simple _fb.c_, the WGT provides a library of graphics routines which can be depended upon for reuse. This library, however, is much more fully-fledged than mine, and makes it easy to build sprite-based games (like Breakout, Space Invaders, Pacman etc.).
The directory structure
As I port the WGT to my OS (a.k.a. make it work on my OS), I am using the following directories:
?* _bin/_ : for WGT binary files (fonts, sprites, bitmaps etc.)
?* _controller-ios/_ : a sample Swift BLE controller for the iOS platform
?* _controller-node/_ : a sample Node.js BLE controller?
?* _include/_ : now contains _wgt.h_ and _wgtspr.h_ too (header files necessary for WGT code)
?* _samples/_ : sample "kernels" for my OS which exercise certain WGT library functions. To build them, copy one of these (and only one at a time) to the same directory as the _Makefile_.
?* _wgt/_ : the library itself. Where possible, I have stayed true to the original code, but do bear in mind it was written for the x86 architecture and we're on AArch64!
Please note: I am neither a Node.js developer, nor a Swift developer, and so the controllers are purely samples that serve my purpose. They are not intended to be exemplars! I am very aware of the multitudinous problems with both...
Building
So... to build the first WGT sample simply type `cp samples/wgt01.c .` from the top-level directory, and then type `make`. When you boot with the generated _kernel8.img_ you will see the screen go into 320x200 (VGA!) mode and draw a white line from corner to corner. If you do, the library is doing its stuff!
boot/boot.S changes
We're still booting into a multicore environment (just in case we need it). There are a few significant changes to _boot/boot.S_ though. They are:
?* Enable FPU (floating-point unit) access so we can do non-integer mathematics
?* Switch from EL3 (supervisor exception level) down to EL1 (kernel exception level), disabling the MMU all the same
?* Move the addresses for the `spin_cpu` variables to accommodate a larger _boot.S_
?* Implement a `get_el` function to check which exception level we're at (for debug mainly)
Using the iOS BLE controller
To use the iOS BLE controller instead of the Node.JS controller, ensure that you have:
```c
#define IOS_CONTROL
```
at the top of each of _wgt/mouse.c_ and _lib/bt.c_. Without this `#define`, the code will be looking for the Node.JS controller (so remove these lines if that's what you want!).
Work in progress!
There's always more that can be done, but I do think this was a good exercise in exploring the joy of getting other people's code to run on your own OS! It's quite a thrill.
_Do have a go at building some of the samples (hint: wgt20 and wgt60 are super fun!)..._
I'm going to move on from here now so we can continue to make progress on the OS itself.