当前位置:网站首页>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表单数据验证
- 用C语言开发NES游戏(CC65)10、游戏循环
- Play with poetry - appreciate the beauty of ancient poetry
- Is it difficult for cloud native machine learning to land? Lingqueyun helps enterprises quickly apply mlops
- Latex matrix is simple to use
- WebView details
- Test platform (V) knowledge points supplement
- Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
- 用C语言开发NES游戏(CC65)07、控制器(和精灵碰撞)
- Top level "redis notes", cache avalanche + breakdown + penetration + cluster + distributed lock, Nb
猜你喜欢

laravel表单数据验证

聚变云原生,赋能新里程 | 2022 开放原子全球开源峰会云原生分论坛圆满召开

华为发布HarmonyOS 3及全场景新品,智慧体验更进一步

Interpretable ml of Li Hongyi's machine learning model

Idea replication module

Design process sharing of wireless anti loss alarm based on single chip microcomputer

用C语言开发NES游戏(CC65)09、滚动

Character function and string function (Part 1)

IDEA复制模块

Laravel form data validation
随机推荐
Most of the interfaces of Tiktok are already available, and more interfaces are still open. Please look forward to it
PHP时间戳相减转化为天小时分秒
Test platform (V) knowledge points supplement
Kuzaobao: summary of Web3 encryption industry news on July 13
[leetcode] 8. binary search · binary search
Huawei releases harmonyos 3 and all scene new products, and the smart experience goes further
Character function and string function (Part 1)
2022.07.10 summer training personal qualifying (V)
WebView详解
ViewPager2+Fragment
Unity one key replacement of objects in the scene
Basic use of JSON server
[real question of written examination]
【Try to Hack】内网基础
8000 字讲透 OBSA 原理与应用实践
[leetcode] 7. valid anagram · effective letter ectopic words
Fusion cloud native, enabling new mileage | 2022 open atom global open source summit cloud native sub forum successfully held
顶级“Redis笔记”,缓存雪崩+击穿+穿透+集群+分布式锁,NB了
IRBuilder
Full analysis of seven classical regression analysis methods