当前位置:网站首页>Developing NES games (cc65) 05 and palette with C language
Developing NES games (cc65) 05 and palette with C language
2022-07-28 12:28:00 【firseve】
Paste the CSDN The format is not adjusted , If you want to see a good format, click below
https://happysoul.github.io/nes/nesdoug/
About NES Palette information

altogether 64 Medium colors available (0-$3F), But many of them are black .neslib Ask you to use $0F According to black ,$30 Said the white .
Do not use xD Color , In especial $0D ( He will make some TV problems , The oil pipe has video )
https://www.youtube.com/watch?v=3fhyX3HdVcg
PPU The address of the palette is $3f00-3f0f. Color index #0 (PPU The position in is $3F00 ) Is the general background color . other 3 Palette 0 Sign color and the first palette 0 The color of the sign is the same .
Yes 4 A background palette (4 A sprite palette ),4 Sub palette .
U Represents a universal color ( To put it bluntly, next 4 Location U It's all one color , Cut must be the same color )
U123 U123 U123 U123
The screen shows 13 Medium color .
Each map block of the sprite can only be used 3 Color ,0 The numerical value at position No. indicates transparency . Elves use PPU The palette address is $3F10-3F1F, You can use 12 Plant different colors .

up to now , We only used 1 A palette (4 Color ), So let's use all bg Palette make something .
You can use pal_all() Change the entire palette (32 Bytes ),
Or use pal_bg() change 16 Byte background palette ,
Use pal_spr() change 16 Byte sprite palette .
Just pass one 16 An array of bytes . You can use it. pal_col(index, color)( Indexes , Color ) change 1 Color , among index yes 0-$1f.
There will be one on the next page pal_col Example ( Spirit collision ).
The palette is located in PPU in , And in PPU Cannot write while rendering , all neslib Palette functions are written to the buffer , The buffer is only in v-blank Period copied to PPU( stay nmi In the code ). therefore , You can switch the screen and call these functions at any time .
( The author means to switch the screen and the above functions casually ,nmi The code will judge v-blank And take it out of the cache and put it in PPU in )
Background attribute table
stay PPU in , Each name table (tilemap) At the end of is the attribute table . For maps #0, That is $23c0-$23ff. The only thing they can have “ attribute ” Is palette selection , therefore , You can think of it as a palette table .
The name table only has 64 Bytes can be used for palette selection , So we can generate 8×8 grid . Each byte represents BG Of 32×32 block . Each byte is further divided into 2 Bits , Every 2 Bits represent the background 16×16 Block .

therefore , Each tile does not have its own palette selection . You can only 4(2×2) Block definition palette options .
Try to use NES Screen tools and try to change the palette , You can see it immediately .
Most games are just 16×16 Design the game in blocks of . I did the same thing .

Notice how the ground plate and window block are accurately 16×16 Pixels . The column happens to be 32 Pixel width . The curtain area is just 32 Pixel width .
There are several options to choose from , It expands our tileset, Because we can reuse the same for different objects by changing its palette tile. Look at the clouds and bushes . They use the same tiles on the top .

Again ,1 Attribute bytes affect 16×16 block . each 2 position . therefore , The layout of attribute bytes is like this , Bitwise ......
In the attribute byte 44332211 position
11 22
11 22
33 44
33 44
therefore , If the bit 44 Turn into 00, Then the block will use the 0 A palette . If 22 Turn into 01, It will use the next palette and so on .
therefore , I am here NES A background is made in the screen tool . The whole picture is gray , Use the palette #0, But the code writes the attribute table with padding , Change palette options .
Please note that , I use get_at_addr(0,0,0) To calculate the address in the property sheet . And then use vram_fill() Set attribute bytes .

In the middle of the game , The property sheet is difficult to modify ...... Displacement and shielding are involved here .
Many games just avoid changing it , Unless as part of the rolling engine . You can design the game as 32×32 block , You only need to change one full byte , Don't worry about displacement .
I write a method vram_put() To change 1 Lower attribute bytes , So you can see its size and ability .
vram_put(0xe4); // Put in 1 Bytes 1110 0100
Now? , If in NES Create background in screen tool , Just save the name table of attribute bytes as compressed rle, And copy it when the game is loaded .
https://github.com/nesdoug/06_Color/blob/master/color.c
https://github.com/nesdoug/06_Color
Part of my library is data element processing , Can handle attribute bytes .
边栏推荐
- Laravel form data validation
- Anhui Jingzhun: Beidou satellite synchronous clock | Beidou synchronous clock | NTP network clock server
- The game process and the underlying implementation are gradually completed
- Implementation method of mouse hover, click and double click in ue4/5
- Foam exploded three times, why did Luo Yonghao put all his eggs in one basket to do ar?
- Developing NES games with C language (cc65) 08. Background collision
- [try to hack] at, SC, PS command authorization
- [leetcode] 7. valid anagram · effective letter ectopic words
- Interpretable ml of Li Hongyi's machine learning model
- Latex矩阵简单使用
猜你喜欢

Full analysis of seven classical regression analysis methods

If you don't roll the golden nine and silver ten, it's too late

玩转诗词-领略古诗文之美

Interpretation of the paper: attention mechanism in medical images

The principle and use of the wrap file of tolua

要想组建敏捷团队,这些方法不可少

Google Earth engine (GEE) -- problems in the use of coordinate projection and reduceresolution functions in image downscaling

Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held

With the continuous waves of infringement, the U.S. patent and trademark office began to study the impact of NFT on copyright

Uniapp wechat applet realizes the function of connecting low-power Bluetooth printing
随机推荐
用C语言开发NES游戏(CC65)08、背景 碰撞
IRBuilder
金九银十 再不卷就来不及了
SQL injection less24 (secondary injection)
【Try to Hack】AT、SC、PS命令提权
Image filter from the perspective of convolution
How can a novice quickly complete the establishment of a website? Come to the free "fitting room" experience
Use Baidu PaddlePaddle easydl to complete garbage classification
Full resolution of the use of go native plug-ins
After abolishing Tencent cloud: meiyabaike won the bid of 98.3 million
“蔚来杯“2022牛客暑期多校训练营2
用C语言开发NES游戏(CC65)10、游戏循环
PHP ⽉ the simplest way to add and subtract ⽅
Uniapp wechat applet realizes the function of connecting low-power Bluetooth printing
Arduino Pro Mini atmega328p connect and light the first LED (at the same time, record the problem of burning failure stk500_recv)
SQL注入 Less23(过滤注释符)
用C语言开发NES游戏(CC65)06、精灵
ObjectAnimator使用注意点
Some knowledge concepts
"Weilai Cup" 2022 Niuke summer multi school training camp 2