03 비디오 모드 제어(Video Mode Control)
원문 : http://kkamagui.springnote.com/pages/410834
들어가기 전에...
0.시작하면서...
NDS는 게임기로 제작되어있기 때문에 다양한 비디오 모드가 존재한다. 홈 브루를 개발하기위해서는 자신이 원하는 모드로 설정해야 하는데, 어떤 순서로 해야 하는지 알아보자.
일단 그래픽을 화면에 표시하기 위해서는 LCD를 켜야 한다. LCD를 키는 부분은 파워 컨트롤(Power Control) 부분에서 하는 것이므로 04 파워 컨트롤(Power Control) 문서를 참조하도록 하자.
그래픽쪽 파워를 설정했으면 이제 비디오 모드를 설정해야 한다. http://nocash.emubase.de/gbatek.htm#dsvideo 를 보면 상세하게 나와있으니 참고하고 몇가지 부분만 보자.
참고로 파워 컨트롤에서 나왔지만 LCD Swap이 되지 않은 상태라면 하단 LCD가 Engine A가 되고 상단 LCD가 Engine B가 된다. Engine B는 A보다 약간 모자란데, GBA 게임을 넣으면 상단으로 표시되는걸 봐서 GBA 게임을 돌리기위한 엔진의 역할도 하고 있는 것 같다.
2D Engines
Includes two 2D Engines, called A and B. Both engines are accessed by the ARM9 processor, each using different memory and register addresses:
Region______Engine A______________Engine B___________
I/O Ports 4000000h 4001000h
Palette 5000000h (1K) 5000400h (1K)
BG VRAM 6000000h (max 512K) 6200000h (max 128K)
OBJ VRAM 6400000h (max 256K) 6600000h (max 128K)
OAM 7000000h (1K) 7000400h (1K)
|
Engine A additionally supports 3D and large-screen 256-color Bitmaps, plus main-memory-display and vram-display modes, plus capture unit.
Engine A에는 B에는 없는 3D와 큰 비트맵을 처리할 수 있는 모드, Main Memory를 그대로 Display해주는 모드(프레임 버퍼 모드), 그리고 비디오 화면을 그대로 캡쳐해서 다시 메모리로 저장해주는 캡쳐모드 등등이 있다.
Engine A와 Engine B의 VRAM 최대크기는 각각 512Kbyte 및 128Kbyte라는 것을 알아두자.
BG VRAM 주소와 OBJ VRAM, OAM 주소는 고정되어 있으나 실제 VRAM 주소에 여러가지 VRAM들(VRAM_A, VRAMB, VRAM_C등등)을 맵핑하여 사용하는 방식이며 Video 모드에 따라서 적당한 크기의 VRAM을 맵핑하면 된다.
위에서 잠깐 OAM이라는 생소한 용어가 나오는데, 스프라이트 관련 정보를 저장하는 메모리이다. 게임 제작에 대해서는 큰 비중을 두지 않을 것이므로 그냥 알고 넘어가자.
OAM - Object Attribute Memory
This memory area contains Attributes which specify position, size, color depth, etc. appearance for each of the 128 OBJs. Additionally, it contains 32 OBJ Rotation/Scaling Parameter groups. OAM is located at 07000000-070003FF (sized 1 KByte).
위의 표에서 보면 알 수 있듯이 메인 메모리가 4Mbyte 밖에 안되는 것을 생각해 볼때 꽤 많은 비디오 메모리를 가지고 있는 것을 알 수 있다. 뒤에 비디오 메모리를 어느 LCD에다 맵핑할지를 결정하는 부분이 있는데, 맵핑하고 남은 영역은 데이터 영역으로도 활용 가능할 것 같다.
비디오 모드를 설정하는 과정을 간단히 요약하면 아래와 같다.
- Display Control Register를 설정하여 비디오 모드를 설정한다.
- VRAMxCNT 레지스터를 이용하여 Video RAM을 MAIN BG Address-Engine A(6000000h), SUB BG Address-Engine B(6200000h)부터 적당히 맵핑해 준다.
- BG 모드 사용시 BGxCNT 레지스터를 사용하여 Background의 속성을 설정한다.
- 비디오 메모리에 쓴다.
아래는 NDS의 Video Memory와 Controller의 관계를 그린것이다.
DS Video Display System Block Diagram |
_____________ __________
VRAM A -->| 2D Graphics |--------OBJ->| |
VRAM B -->| Engine A |--------BG3->| Layering |
VRAM C -->| |--------BG2->| and |
VRAM D -->| |--------BG1->| Special |
VRAM E -->| | ___ | Effects |
VRAM F -->| |->|SEL| | | ______
VRAM G -->| - - - - - - | |BG0|-BG0->| |----+--->| |
| 3D Graphics |->|___| |__________| | |Select|
| Engine | | |Video |
|_____________|--------3D----------------+ | |Input |
_______ _______ ___ | | | |
| | | |<-----------|SEL|<-+ | |and |-->
| | | | _____ |A | | | |
VRAM A <--|Select | |Select | | |<-|___|<----+ |Master|
VRAM B <--|Capture|<---|Capture|<--|Blend| ___ |Bright|
VRAM C <--|Dest. | |Source | |_____|<-|SEL|<----+ |A |
VRAM D <--| | | | |B | | | |
|_______| |_______|<-----------|___|<-+ | | |
_______ | | | |
VRAM A -->|Select | | | | |
VRAM B -->|Display|--------------------------------+------>| |
VRAM C -->|VRAM | | | |
VRAM D -->|_______| _____________ | | |
|Main Memory | | | |
Main ------DMA---->|Display FIFO |------------------+--->|______|
Memory |_____________|
_____________ __________ ______
VRAM C -->| 2D Graphics |--------OBJ->| Layering | | |
VRAM D -->| Engine B |--------BG3->| and | |Master|
VRAM H -->| |--------BG2->| Special |-------->|Bright|-->
VRAM I -->| |--------BG1->| Effects | |B |
|_____________|--------BG0->|__________| |______|
|
이제 각 파트에 대해서 자세히 알아보자.
1. Display Control
제일 처음 Display Control 레지스터를 설정하여 표시될 모드를 설정해야 한다. http://nocash.emubase.de/gbatek.htm#lcdiodisplaycontrol를 보면 아래와 같이 나와있다(GBA의 LCD Control 설정이다. 일단 비트의 기능은 NDS와 거의 동일하니까 먼저 보자).
1.1 GBA Display Control Register
4000000h - DISPCNT - LCD Control (Read/Write)
Bit Expl.
0-2 BG Mode (0-5=Video Mode 0-5, 6-7=Prohibited)
3 Reserved for BIOS (CGB Mode - cannot be changed after startup)
4 Display Frame Select (0-1=Frame 0-1) (for BG Modes 4,5 only)
5 H-Blank Interval Free (1=Allow access to OAM during H-Blank)
6 OBJ Character VRAM Mapping (0=Two dimensional, 1=One dimensional)
7 Forced Blank (1=Allow access to VRAM,Palette,OAM)
8 Screen Display BG0 (0=Off, 1=On)
9 Screen Display BG1 (0=Off, 1=On)
10 Screen Display BG2 (0=Off, 1=On)
11 Screen Display BG3 (0=Off, 1=On)
12 Screen Display OBJ (0=Off, 1=On)
13 Window 0 Display Flag (0=Off, 1=On)
14 Window 1 Display Flag (0=Off, 1=On)
15 OBJ Window Display Flag (0=Off, 1=On)
|
The table summarizes the facilities of the separate BG modes (video modes).
Mode Rot/Scal Layers Size Tiles Colors Features
0 No 0123 256x256..512x515 1024 16/16..256/1 SFMABP
1 Mixed 012- (BG0,BG1 as above Mode 0, BG2 as below Mode 2)
2 Yes --23 128x128..1024x1024 256 256/1 S-MABP
3 Yes --2- 240x160 1 32768 --MABP
4 Yes --2- 240x160 2 256/1 --MABP
5 Yes --2- 160x128 2 32768 --MABP
|
Features: S)crolling, F)lip, M)osaic, A)lphaBlending, B)rightness, P)riority.
BG Modes 0-2bit
BG Modes 0-2 are Tile/Map-based. BG Modes 3-5 are Bitmap-based, in these modes 1 or 2 Frames (ie. bitmaps, or 'full screen tiles') exists, if two frames exist, either one can be displayed, and the other one can be redrawn in background.
Blanking Bits 5, 7Bit
Setting Forced Blank (Bit 7) causes the video controller to display white lines, and all VRAM, Palette RAM, and OAM may be accessed.
"When the internal HV synchronous counter cancels a forced blank during a display period, the display begins from the beginning, following the display of two vertical lines." What ?
Setting H-Blank Interval Free (Bit 5) allows to access OAM during H-Blank time - using this feature reduces the number of sprites that can be displayed per line.
Screen Display BG Bits 8~12Bit, Window Display Bits 13~14Bit, Object Window Display Bit 15Bit
By default, BG0-3 and OBJ Display Flags (Bit 8-12) are used to enable/disable BGs and OBJ. When enabling Window 0 and/or 1 (Bit 13-14), color special effects may be used, and BG0-3 and OBJ are controlled by the window(s).
Frame Selection 4bit
In BG Modes 4 and 5 (Bitmap modes), either one of the two bitmaps/frames may be displayed (Bit 4), allowing the user to update the other (invisible) frame in background. In BG Mode 3, only one frame exists.
In BG Modes 0-2 (Tile/Map based modes), a similar effect may be gained by altering the base address(es) of BG Map and/or BG Character data.
4000002h - Undocumented - Green Swap (R/W)
Normally, red green blue intensities for a group of two pixels is output as BGRbgr (uppercase for left pixel at even xloc, lowercase for right pixel at odd xloc). When the Green Swap bit is set, each pixel group is output as BgRbGr (ie. green intensity of each two pixels exchanged).
Bit Expl.
0 Green Swap (0=Normal, 1=Swap)
1-15 Not used
|
This feature appears to be applied to the final picture (ie. after mixing the separate BG and OBJ layers). Eventually intended for other display types (with other pin-outs). With normal GBA hardware it is just producing an interesting dirt effect.
The NDS DISPCNT registers are 32bit (4000000h..4000003h), so Green Swap doesn't exist in NDS mode, however, the NDS does support Green Swap in GBA mode.
1.2 NDS Display Control Register
이제 본격적으로 NDS에 대해서 알아보자. GBA와 비교해서 같은 이름의 비트는 거의 같은 일을 하므로 GBA의 정보와 같이 비교해서 보자.
DS DISPCNT
Bit Engine Expl.
0-2 A+B BG Mode
3 A BG0 2D/3D Selection (instead CGB Mode) (0=2D, 1=3D)
4 A+B Tile OBJ Mapping (0=2D; max 32KB, 1=1D; max 32KB..256KB)
5 A+B Bitmap OBJ 2D-Dimension (0=128x512 dots, 1=256x256 dots)
6 A+B Bitmap OBJ Mapping (0=2D; max 128KB, 1=1D; max 128KB..256KB)
7 Forced Blank (1=Allow access to VRAM,Palette,OAM)
8 Screen Display BG0 (0=Off, 1=On)
9 Screen Display BG1 (0=Off, 1=On)
10 Screen Display BG2 (0=Off, 1=On)
11 Screen Display BG3 (0=Off, 1=On)
12 Screen Display OBJ (0=Off, 1=On)
13 Window 0 Display Flag (0=Off, 1=On)
14 Window 1 Display Flag (0=Off, 1=On)
15 OBJ Window Display Flag (0=Off, 1=On)
16-17 A+B Display Mode (Engine A: 0..3, Engine B: 0..1, GBA: Green Swap)
18-19 A VRAM block (0..3=VRAM A..D) (For Capture & above Display Mode=2)
20-21 A+B Tile OBJ 1D-Boundary (see Bit4)
22 A Bitmap OBJ 1D-Boundary (see Bit5-6)
23 A+B OBJ Processing during H-Blank (was located in Bit5 on GBA)
24-26 A Character Base (in 64K steps) (merged with 16K step in BGxCNT)
27-29 A Screen Base (in 64K steps) (merged with 2K step in BGxCNT)
30 A+B BG Extended Palettes (0=Disable, 1=Enable)
31 A+B OBJ Extended Palettes (0=Disable, 1=Enable)
|
BG Mode
Engine A BG Mode (DISPCNT LSBs) (0-6, 7=Reserved), Engine B도 5번까지는 같음
Mode BG0 BG1 BG2 BG3
0 Text/3D Text Text Text
1 Text/3D Text Text Affine
2 Text/3D Text Affine Affine
3 Text/3D Text Text Extended
4 Text/3D Text Affine Extended
5 Text/3D Text Extended Extended
6 3D - Large -
|
Extended 모드는 Backgound 속성과 함께 다시 세부 모드로 나누어 진다. 즉 위의 GBA 모드와는 다르다.
Of which, the "Extended" modes are sub-selected by BGxCNT bits:
(BGxCNT.Bit7은 Colors/Palettes Bit이고 , Bit2는 Character Base Block의 첫번째 bit이다)
BGxCNT.Bit7 BGxCNT.Bit2 Extended Affine Mode Selection
0 CharBaseLsb rot/scal with 16bit bgmap entries (Text+Affine mixup)
1 0 rot/scal 256 color bitmap
1 1 rot/scal direct color bitmap
|
direct color bitmap 모드를 사용하면 R/G/B 각각이 5bit이고 Alpha가 1bit인 Color Mode를 사용할 수 있다. 뒤에서 이 모드를 이용하여 프레임 버퍼 모드와 비슷하게 설정할 것이다.
Engine B: Same as above, except that: Mode 6 is reserved (no Large screen bitmap), and BG0 is always Text (no 3D support).
Affine = formerly Rot/Scal mode (with 8bit BG Map entries)
Large Screen Bitmap = rot/scal 256 color bitmap (using all 512K of 2D VRAM)
Display Mode (DISPCNT.16-17):
0 Display off (screen becomes white)
1 Graphics Display (normal BG and OBJ layers)
2 Engine A only: VRAM Display (Bitmap from block selected in DISPCNT.18-19)
3 Engine A only: Main Memory Display (Bitmap DMA transfer from Main RAM)
|
Mode 2-3 display a raw direct color bitmap (15bit RGB values, the upper bit in each halfword is unused), without any further BG,OBJ,3D layers, these modes are completely bypassing the 2D/3D engines as well as any 2D effects, however the Master Brightness effect can be applied to these modes. Mode 2 is particulary useful to display captured 2D/3D images (in that case it can indirectly use the 2D/3D engine).
BGxCNT
character base extended from bit2-3 to bit2-5 (bit4-5 formerly unused)
character base is used only in tile/map modes (not bitmap modes)
screen base is used in tile/map modes, screen base used in bitmap modes as BGxCNT.bits*16K, without DISPCNT.bits*64K
engine A screen base: BGxCNT.bits*2K + DISPCNT.bits*64K
engine B screen base: BGxCNT.bits*2K + 0
engine A char base: BGxCNT.bits*16K + DISPCNT.bits*64K
engine B char base: BGxCNT.bits*16K + 0
engine A bitmap screen base: BGxCNT.bit*16K + 0
engine B bitmap screen base: BGxCNT.bit*16K + 0
|
위와 같이 Bitmap 모드일 경우 Offset은 16K가 곱해진다. 이것을 잘 기억해 두면 Double Buffering을 할 때 잘 사용할 수 있다.
screen base however NOT used at all for Large screen bitmap mode
bgcnt sc.size text rotscal bitmap large bmp
0 256x256 128x128 128x128 512x1024
1 512x256 256x256 256x256 1024x512
2 256x512 512x512 512x256 -
3 512x512 1024x1024 512x512 -
|
bitmaps that require more than 128K VRAM are supported on engine A only.
For BGxCNT.Bit7 and BGxCNT.Bit2 in Extended Affine modes, see above BG Mode description (extended affine doesn't include 16-color modes, so color depth bit can be used for mode selection. Also, bitmap modes do not use charbase, so charbase.0 can be used for mode selection as well).
for BG0, BG1 only: bit13 selects extended palette slot
(BG0: 0=Slot0, 1=Slot2, BG1: 0=Slot1, 1=Slot3)
|
Direct Color Bitmap BG, and Direct Color Bitmap OBJ
BG/OBJ Supports 32K colors (15bit RGB value) - so far same as GBAs BG.
However, the upper bit (Bit15) is used as Alpha flag. That is, Alpha=0=Transparent, Alpha=1=Normal (ie. on the NDS, Direct Color values 0..7FFFh are NOT displayed).
위에서 BGxCNT 레지스터에 대한 설정이 잠깐 나왔는데, Background(BG) 모드를 사용하면 해당 BG에 대한 설정을 해줘야 한다. 자세한 내용은 다음 섹션에서 알아보자
아래는 Charactor(Bitmap)/Screen 모드에 따른 Offset 별 주소 공간을 나타낸 것이다. http://www.dev-scene.com/NDS/Tutorials_Day_3를 보면 잘 나와있다.
1.3 BG Mode Detail
위에서 보면 BG 모드에 따라서 BG 0~3의 용도가 달라졌다. 이제 좀더 자세하게 알아보자. 이 부분에 대한 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdvramoverview에서 찾을 수 있다.
BG Mode 0,1,2 (Tile/Map based Modes)
06000000-0600FFFF 64 KBytes shared for BG Map and Tiles
06010000-06017FFF 32 KBytes OBJ Tiles
|
The shared 64K area can be split into BG Map area(s), and BG Tiles area(s), the respective addresses for Map and Tile areas are set up by BG0CNT-BG3CNT registers. The Map address may be specified in units of 2K (steps of 800h), the Tile address in units of 16K (steps of 4000h).
BG Mode의 0~2 모드는 위와 같이 영역이 정해진다.
BG Mode 0,1 (Tile/Map based Text mode)
The tiles may have 4bit or 8bit color depth, minimum map size is 32x32 tiles, maximum is 64x64 tiles, up to 1024 tiles can be used per map.
Item Depth Required Memory
One Tile 4bit 20h bytes
One Tile 8bit 40h bytes
1024 Tiles 4bit 8000h (32K)
1024 Tiles 8bit 10000h (64K) - excluding some bytes for BG map
BG Map 32x32 800h (2K)
BG Map 64x64 2000h (8K)
|
BG Mode 1,2 (Tile/Map based Rotation/Scaling mode)
The tiles may have 8bit color depth only, minimum map size is 16x16 tiles, maximum is 128x128 tiles, up to 256 tiles can be used per map.
BG Mode 3 (Bitmap based Mode for still images)
06000000-06013FFF 80 KBytes Frame 0 buffer (only 75K actually used)
06014000-06017FFF 16 KBytes OBJ Tiles
|
BG Mode 4,5 (Bitmap based Modes)
06000000-06009FFF 40 KBytes Frame 0 buffer (only 37.5K used in Mode 4)
0600A000-06013FFF 40 KBytes Frame 1 buffer (only 37.5K used in Mode 4)
06014000-06017FFF 16 KBytes OBJ Tiles
|
Note
Additionally to the above VRAM, the GBA also contains 1 KByte Palette RAM (at 05000000h) and 1 KByte OAM (at 07000000h) which are both used by the display controller as well.
위에서 3,4,5와 같은 경우는 우리가 흔히 사용하는 프레임 버퍼모드와 비슷하게 동작하게 만들 수 있다. 단 Direct Color 모드를 사용해야 하는데, Direct Color 모드일 경우 R/G/B 각각 5bit와 Alpha 1bit로 이루어지는 차이 밖에 없다.
각 BG 모드에 따라서 위와 같이 사용된다. 좀 더 자세한 내용은 아래와 같다.
LCD VRAM Character Data
Each character (tile) consists of 8x8 dots (64 dots in total). The color depth may be either 4bit or 8bit (see BG0CNT-BG3CNT).
4bit depth (16 colors, 16 palettes)
Each tile occupies 32 bytes of memory(왜? 8*8*4bit니까), the first 4 bytes for the topmost row of the tile, and so on. Each byte representing two dots, the lower 4 bits define the color for the left dot, the upper 4 bits the color for the right dot.
8bit depth (256 colors, 1 palette)
Each tile occupies 64 bytes of memory(왜? 8*8*8bit니까), the first 8 bytes for the topmost row of the tile, and so on. Each byte selects the palette entry for each dot.
LCD VRAM BG Screen Data Format (BG Map) |
The display background consists of 8x8 dot tiles, the arrangement of these tiles is specified by the BG Screen Data (BG Map). The separate entries in this map are as follows:
Text BG Screen (2 bytes per entry)
Specifies the tile number and attributes. Note that BG tile numbers are always specified in steps of 1 (unlike OBJ tile numbers which are using steps of two in 256 color/1 palette mode).
Bit Expl.
0-9 Tile Number (0-1023) (a bit less in 256 color mode, because
there'd be otherwise no room for the bg map)
10 Horizontal Flip (0=Normal, 1=Mirrored)
11 Vertical Flip (0=Normal, 1=Mirrored)
12-15 Palette Number (0-15) (Not used in 256 color/1 palette mode)
|
A Text BG Map always consists of 32x32 entries (256x256 pixels), 400h entries = 800h bytes. However, depending on the BG Size, one, two, or four of these Maps may be used together, allowing to create backgrounds of 256x256, 512x256, 256x512, or 512x512 pixels, if so, the first map (SC0) is located at base+0, the next map (SC1) at base+800h, and so on.
Rotation/Scaling BG Screen (1 byte per entry)
In this mode, only 256 tiles can be used. There are no x/y-flip attributes, the color depth is always 256 colors/1 palette.
Bit Expl.
0-7 Tile Number (0-255)
|
The dimensions of Rotation/Scaling BG Maps depend on the BG size. For size 0-3 that are: 16x16 tiles (128x128 pixels), 32x32 tiles (256x256 pixels), 64x64 tiles (512x512 pixels), or 128x128 tiles (1024x1024 pixels).
The size and VRAM base address of the separate BG maps for BG0-3 are set up by BG0CNT-BG3CNT registers.
In BG Modes 3-5 the background is defined in form of a bitmap (unlike as for Tile/Map based BG modes). Bitmaps are implemented as BG2, with Rotation/Scaling support. As bitmap modes are occupying 80KBytes of BG memory, only 16KBytes of VRAM can be used for OBJ tiles.
BG Mode 3 - 240x160 pixels, 32768 colors
Two bytes are associated to each pixel, directly defining one of the 32768 colors (without using palette data, and thus not supporting a 'transparent' BG color).
Bit Expl.
0-4 Red Intensity (0-31)
5-9 Green Intensity (0-31)
10-14 Blue Intensity (0-31)
15 Not used
|
The first 480 bytes define the topmost line, the next 480 the next line, and so on. The background occupies 75 KBytes (06000000-06012BFF), most of the 80 Kbytes BG area, not allowing to redraw an invisible second frame in background, so this mode is mostly recommended for still images only.
BG Mode 4 - 240x160 pixels, 256 colors (out of 32768 colors)
One byte is associated to each pixel, selecting one of the 256 palette entries. Color 0 (backdrop) is transparent, and OBJs may be displayed behind the bitmap.
The first 240 bytes define the topmost line, the next 240 the next line, and so on. The background occupies 37.5 KBytes, allowing two frames to be used (06000000-060095FF for Frame 0, and 0600A000-060135FF for Frame 1).
BG Mode 5 - 160x128 pixels, 32768 colors
Colors are defined as for Mode 3 (see above), but horizontal and vertical size are cut down to 160x128 pixels only - smaller than the physical dimensions of the LCD screen.
The background occupies exactly 40 KBytes, so that BG VRAM may be split into two frames (06000000-06009FFF for Frame 0, and 0600A000-06013FFF for Frame 1).
In BG modes 4,5, one Frame may be displayed (selected by DISPCNT Bit 4), the other Frame is invisible and may be redrawn in background.
Frame이 1개 이상일 경우는 Display Control Register의 Bit4에 값을 설정함으로써 현재 표시되는 부분을 바꿀 수 있다.
1.4 Object
Object에 대한 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdobjoverview를 보자.
2. VRAM Control
Display 모드를 선택했으니 이제 적당한 크기에 맞는 VRAM을 각 주소로 맵핑을 시켜야 한다. VRAM 제어에 대한 내용은 http://nocash.emubase.de/gbatek.htm#dsmemorycontrolvram에서 살펴볼 수 있다.
4000240h - NDS7 - VRAMSTAT - 8bit - VRAM Bank Status (R)
0 VRAM C enabled and allocated to NDS7 (0=No, 1=Yes)
1 VRAM D enabled and allocated to NDS7 (0=No, 1=Yes)
2-7 Not used (always zero)
|
The register indicates if VRAM C/D are allocated to NDS7 (as Work RAM), ie. if VRAMCNT_C/D are enabled (Bit7=1), with MST=2 (Bit0-2). However, it does not reflect the OFS value.
위 레지스터는 VRAM C와 D가 ARM7에서 WRAM의 용도로 사용가능한가를 나타내는 레지스터이다.
2.1 VRAM의 종류 및 컨트롤 모드
실제로 VRAM Control 레지스터는 8bit로 되어있으며 아래와 같다.
4000240h - VRAMCNT_A - 8bit - VRAM-A (128K) Bank Control (W)
4000241h - VRAMCNT_B - 8bit - VRAM-B (128K) Bank Control (W)
4000242h - VRAMCNT_C - 8bit - VRAM-C (128K) Bank Control (W)
4000243h - VRAMCNT_D - 8bit - VRAM-D (128K) Bank Control (W)
4000244h - VRAMCNT_E - 8bit - VRAM-E (64K) Bank Control (W)
4000245h - VRAMCNT_F - 8bit - VRAM-F (16K) Bank Control (W)
4000246h - VRAMCNT_G - 8bit - VRAM-G (16K) Bank Control (W)
4000248h - VRAMCNT_H - 8bit - VRAM-H (32K) Bank Control (W)
4000249h - VRAMCNT_I - 8bit - VRAM-I (16K) Bank Control (W)
0-2 VRAM MST ;Bit2 not used by VRAM-A,B,H,I
3-4 VRAM Offset (0-3) ;Offset not used by VRAM-E,H,I
5-6 Not used
7 VRAM Enable (0=Disable, 1=Enable)
|
There is a total of 656KB of VRAM in Blocks A-I.
Notes
In Plain-CPU modes :
VRAM can be accessed only by the CPU (and by the Capture Unit, and by VRAM Display mode). In "Plain <ARM7>-CPU Access" mode, the VRAM blocks are allocated as Work RAM to the NDS7 CPU.
In BG/OBJ VRAM modes :
VRAM can be accessed by the CPU at specified addresses, and by the display controller.
In Extended Palette and Texture Image/Palette modes :
VRAM is not mapped to CPU address space, and can be accessed only by the display controller (so, to initialize or change the memory, it should be temporarily switched to Plain-CPU mode).
All VRAM (and Palette, and OAM) can be written to only in 16bit and 32bit units (STRH, STR opcodes), 8bit writes are ignored (by STRB opcode). The only exception is "Plain <ARM7>-CPU Access" mode: The ARM7 CPU can use STRB to write to VRAM (the reason for this special feature is that, in GBA mode, two 128K VRAM blocks are used to emulate the GBA's 256K Work RAM).
2.2 세부 모드별 VRAM 설정
- Plain ARM9-CPU Access (so-called LCDC mode)
VRAM SIZE MST OFS ARM9
A 128K 0 - 6800000h-681FFFFh
B 128K 0 - 6820000h-683FFFFh
C 128K 0 - 6840000h-685FFFFh
D 128K 0 - 6860000h-687FFFFh
E 64K 0 - 6880000h-688FFFFh
F 16K 0 - 6890000h-6893FFFh
G 16K 0 - 6894000h-6897FFFh
H 32K 0 - 6898000h-689FFFFh
I 16K 0 - 68A0000h-68A3FFFh
- ARM9 2D Graphics Engine A, BG-VRAM (max 512K)
VRAM SIZE MST OFS
A,B,C,D 128K 1 0..3 6000000h+(20000h*OFS)
E 64K 1 - 6000000h
F,G 16K 1 0..3 6000000h+(4000h*OFS.0)+(10000h*OFS.1)
- ARM9 2D Graphics Engine A, OBJ-VRAM (max 256K)
VRAM SIZE MST OFS
A,B 128K 2 0..1 6400000h+(20000h*OFS.0) ;(OFS.1 must be zero)
E 64K 2 - 6400000h
F,G 16K 2 0..3 6400000h+(4000h*OFS.0)+(10000h*OFS.1)
- 2D Graphics Engine A, BG Extended Palette
VRAM SIZE MST OFS
E 64K 4 - Slot 0-3 ;only lower 32K used
F,G 16K 4 0..1 Slot 0-1 (OFS=0), Slot 2-3 (OFS=1)
- 2D Graphics Engine A, OBJ Extended Palette
VRAM SIZE MST OFS
F,G 16K 5 - Slot 0 ;16K each (only lower 8K used)
- Texture/Rear-plane Image
VRAM SIZE MST OFS
A,B,C,D 128K 3 0..3 Slot OFS(0-3) ;(Slot2-3: Texture, or Rear-plane)
- Texture Palette
VRAM SIZE MST OFS
E 64K 3 - Slots 0-3 ;OFS=don't care
F,G 16K 3 0..3 Slot (OFS.0*1)+(OFS.1*4) ;ie. Slot 0, 1, 4, or 5
- ARM9, 2D Graphics Engine B, BG-VRAM (max 128K)
VRAM SIZE MST OFS
C 128K 4 - 6200000h
H 32K 1 - 6200000h
I 16K 1 - 6208000h
- ARM9, 2D Graphics Engine B, OBJ-VRAM (max 128K)
VRAM SIZE MST OFS
D 128K 4 - 6600000h
I 16K 2 - 6600000h
- 2D Graphics Engine B, BG Extended Palette
VRAM SIZE MST OFS
H 32K 2 - Slot 0-3
- 2D Graphics Engine B, OBJ Extended Palette
VRAM SIZE MST OFS
I 16K 3 - Slot 0 ;(only lower 8K used)
- <ARM7>, Plain <ARM7>-CPU Access
VRAM SIZE MST OFS
C,D 128K 2 0..1 6000000h+(20000h*OFS.0) ;OFS.1 must be zero
위에서 보면 Engine A가 확실히 B보다는 VRAM 선택권이 넓다는 것을 알 수 있다. 그리고 Engine A의 경우는 최대 512Kbyte까지 맵핑 가능하며 Engine B의 경우 최대 128Kbyte까지 맵핑이 가능하다.
이렇게 맵핑이 끝나고 나면 Background Control Register를 통해서 해당 Background에 대한 설정을 해줘야 한다.
3. Background Control
3.1 Background Control Register
Display Control Register를 통해서 원하는 Display 모드를 설정했으면 그에 따른 부수적인 처리를 해줘야 한다. Background 모드(BG)를 이용할 경우 해당 BG를 어떻게 사용할 것인지에 대한 처리를 해야 하는데 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdiobgcontrol 를 참고하고 몇가지만 보자.
4000008h - BG0CNT - BG0 Control (R/W)
400000Ah - BG1CNT - BG1 Control (R/W)
400000Ch - BG2CNT - BG2 Control (R/W)
400000Eh - BG3CNT - BG3 Control (R/W)
Bit Expl.
0-1 BG Priority (0-3, 0=Highest)
2-3 Character Base Block (0-3, in units of 16 KBytes) (=BG Tile Data)
4-5 Not used (must be zero)
6 Mosaic (0=Disable, 1=Enable)
7 Colors/Palettes (0=16/16, 1=256/1)
8-12 Screen Base Block (0-31, in units of 2 KBytes) (=BG Map Data)
13 Display Area Overflow (0=Transparent, 1=Wraparound; BG2CNT/BG3CNT only)
14-15 Screen Size (0-3)
In case that some or all BGs are set to same priority then BG0 is having the highest, and BG3 the lowest priority.
|
위의 Display Control에서 보았던 Character Base Block에 대한 영역과 Screen Base Block에 대한 영역값을 볼 수 있다. 그리고 특이한 것이 Display Area를 넘어갈때 그것을 어떻게 처리할 것인지에 대한 설정도 나와있다. Transparent는 아무 것도 안하는 것 같고 Warparound는 넘어선 부분을 다시 0 Base로 하여서 덮어쓰는것 같다.
Internal Screen Size (dots) and size of BG Map (bytes):
Value Text Mode Rotation/Scaling Mode
0 256x256 (2K) 128x128 (256 bytes)
1 512x256 (4K) 256x256 (1K)
2 256x512 (4K) 512x512 (4K)
3 512x512 (8K) 1024x1024 (16K)
|
In 'Text Modes', the screen size is organized as follows:
The screen consists of one or more 256x256 pixel (32x32 tiles) areas. When Size=0: only 1 area (SC0), when Size=1 or Size=2: two areas (SC0,SC1 either horizontally or vertically arranged next to each other), when Size=3: four areas (SC0,SC1 in upper row, SC2,SC3 in lower row). Whereas SC0 is defined by the normal BG Map base address (Bit 8-12 of BG#CNT), SC1 uses same address +2K, SC2 address +4K, SC3 address +6K. When the screen is scrolled it'll always wraparound.
In 'Rotation/Scaling Modes', the screen size is organized as follows:
only one area (SC0) of variable size 128x128..1024x1024 pixels (16x16..128x128 tiles) exists (SC0). When the screen is rotated/scaled (or scrolled?) so that the LCD viewport reaches outside of the background/screen area, then BG may be either displayed as transparent or wraparound (Bit 13 of BG#CNT).
3.2 Background Scrolling Register
위에서 Background Mode에 대해서 설정했으면 Scrolling에 대한 처리를 해야한다. Scrolling은 큰 Bitmap을 그려놓고 해당 Bitmap내에서 일부분을 화면에 표시할때 유용하게 사용할 수 있다. Scrolling에 대한 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdiobgscrolling를 보도록 하자.
4000010h - BG0HOFS - BG0 X-Offset (W)
4000012h - BG0VOFS - BG0 Y-Offset (W)
Bit Expl.
0-8 Offset (0-511)
9-15 Not used
|
Specifies the coordinate of the upperleft first visible dot of BG0 background layer, ie. used to scroll the BG0 area.
4000014h - BG1HOFS - BG1 X-Offset (W)
4000016h - BG1VOFS - BG1 Y-Offset (W)
Same as above BG0HOFS and BG0VOFS for BG1 respectively.
4000018h - BG2HOFS - BG2 X-Offset (W)
400001Ah - BG2VOFS - BG2 Y-Offset (W)
Same as above BG0HOFS and BG0VOFS for BG2 respectively.
400001Ch - BG3HOFS - BG3 X-Offset (W)
400001Eh - BG3VOFS - BG3 Y-Offset (W)
Same as above BG0HOFS and BG0VOFS for BG3 respectively.
The above BG scrolling registers are exclusively used in Text modes, ie. for all layers in BG Mode 0, and for the first two layers in BG mode .
In other BG modes (Rotation/Scaling and Bitmap modes) above registers are ignored. Instead, the screen may be scrolled by modifying the BG Rotation/Scaling Reference Point registers.
위의 레지스터 설명을 보면 BG Layer에서 표시될 위치를 찍는 것임을 알 수 있다. 하지만 정상적으로 사용하기 위해서는 Text Mode 일때만 가능하다고 되어있다. 다른 모드에서는 Rotation/Scaling을 사용하라는 것인데, 나중에 확실히 테스트 해봐야겠다.
3.3 Background Rotation/Scaling Register
Text 모드가 아닌 경우 스크롤및 화면에 사용될 수 있다. 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdiobgrotationscaling을 살펴보자.
4000028h - BG2X_L - BG2 Reference Point X-Coordinate, lower 16 bit (W)
400002Ah - BG2X_H - BG2 Reference Point X-Coordinate, upper 12 bit (W)
400002Ch - BG2Y_L - BG2 Reference Point Y-Coordinate, lower 16 bit (W)
400002Eh - BG2Y_H - BG2 Reference Point Y-Coordinate, upper 12 bit (W)
These registers are replacing the BG scrolling registers which are used for Text mode, ie. the X/Y coordinates specify the source position from inside of the BG Map/Bitmap of the pixel to be displayed at upper left of the GBA display. The normal BG scrolling registers are ignored in Rotation/Scaling and Bitmap modes.
Bit Expl.
0-7 Fractional portion (8 bits)
8-26 Integer portion (19 bits)
27 Sign (1 bit)
28-31 Not used
|
Because values are shifted left by eight, fractional portions may be specified in steps of 1/256 pixels (this would be relevant only if the screen is actually rotated or scaled). Normal signed 32bit values may be written to above registers (the most significant bits will be ignored and the value will be cut-down to 28bits, but this is no actual problem because signed values have set all MSBs to the same value).
Internal Reference Point Registers
The above reference points are automatically copied to internal registers during each vblank, specifying the origin for the first scanline. The internal registers are then incremented by dmx and dmy after each scanline.
Caution: Writing to a reference point register by software outside of the Vblank period does immediately copy the new value to the corresponding internal register, that means: in the current frame, the new value specifies the origin of the <current> scanline (instead of the topmost scanline).
4000020h - BG2PA - BG2 Rotation/Scaling Parameter A (alias dx) (W)
4000022h - BG2PB - BG2 Rotation/Scaling Parameter B (alias dmx) (W)
4000024h - BG2PC - BG2 Rotation/Scaling Parameter C (alias dy) (W)
4000026h - BG2PD - BG2 Rotation/Scaling Parameter D (alias dmy) (W)
Bit Expl.
0-7 Fractional portion (8 bits)
8-14 Integer portion (7 bits)
15 Sign (1 bit)
|
400003Xh - BG3X_L/H, BG3Y_L/H, BG3PA-D - BG3 Rotation/Scaling Parameters
Same as above BG2 Reference Point, and Rotation/Scaling Parameters, for BG3 respectively.
위의 dx, dmx, dy, dmy에 대한 내용은 아래에 나온다.
dx (PA) and dy (PC)
When transforming a horizontal line, dx and dy specify the resulting gradient and magnification for that line. For example:
Horizontal line, length=100, dx=1, and dy=1. The resulting line would be drawn at 45 degrees, f(y)=1/1*x. Note that this would involve that line is magnified, the new length is SQR(100^2+100^2)=141.42. Yup, exactly - that's the old a^2 + b^2 = c^2 formula.
dmx (PB) and dmy (PD)
These values define the resulting gradient and magnification for transformation of vertical lines. However, when rotating a square area (which is surrounded by horizontal and vertical lines), then the desired result should be usually a rotated <square> area (ie. not a parallelogram, for example).
Thus, dmx and dmy must be defined in direct relationship to dx and dy, taking the example above, we'd have to set dmx=-1, and dmy=1, f(x)=-1/1*y.
Area Overflow
In result of rotation/scaling it may often happen that areas outside of the actual BG area become moved into the LCD viewport. Depending of the Area Overflow bit (BG2CNT and BG3CNT, Bit 13) these areas may be either displayed (by wrapping the BG area), or may be displayed transparent.
This works only in BG modes 1 and 2. The area overflow is ignored in Bitmap modes (BG modes 3-5), the outside of the Bitmaps is always transparent.
--- more details and confusing or helpful formulas ---
The following parameters are required for Rotation/Scaling
Rotation Center X and Y Coordinates (x0,y0)
Rotation Angle (alpha)
Magnification X and Y Values (xMag,yMag)
|
The display is rotated by 'alpha' degrees around the center.
The displayed picture is magnified by 'xMag' along x-Axis (Y=y0) and 'yMag' along y-Axis (X=x0).
Calculating Rotation/Scaling Parameters A-D
A = Cos (alpha) / xMag ;distance moved in direction x, same line
B = Sin (alpha) / xMag ;distance moved in direction x, next line
C = Sin (alpha) / yMag ;distance moved in direction y, same line
D = Cos (alpha) / yMag ;distance moved in direction y, next line
|
Calculating the position of a rotated/scaled dot
Using the following expressions,
x0,y0 Rotation Center
x1,y1 Old Position of a pixel (before rotation/scaling)
x2,y2 New position of above pixel (after rotation scaling)
A,B,C,D BG2PA-BG2PD Parameters (as calculated above)
|
the following formula can be used to calculate x2,y2:
x2 = A(x1-x0) + B(y1-y0) + x0
y2 = C(x1-x0) + D(y1-y0) + y0
|
꽤나 복잡한 공식이 있는데, 역시나 게임을 만들진 않을 것이므로 간단히 보고 넘어가자. 뒤에 위에서 나온 것들을 종합하여 프레임 버퍼 모드와 비슷하게 만드는 부분을 볼텐데 그것을 참고자하.
4. Window Register
Window는 스크린을 네개의 영역으로 나눌때 사용된다는데, 자세한 내용은 해보지 않아서 잘 모르겠다. 나중에 테스트 후에 넣도록 하자. 일단 Window에 대한 설명은 http://nocash.emubase.de/gbatek.htm#lcdiowindowfeature에 나와있으니 참고하자.
The Window Feature may be used to split the screen into four regions. The BG0-3,OBJ layers and Color Special Effects can be separately enabled or disabled in each of these regions.
The DISPCNT Register
DISPCNT Bits 13-15 are used to enable Window 0, Window 1, and/or OBJ Window regions, if any of these regions is enabled then the "Outside of Windows" region is automatically enabled, too.
DISPCNT Bits 8-12 are kept used as master enable bits for the BG0-3,OBJ layers, a layer is displayed only if both DISPCNT and WININ/OUT enable bits are set.
4000040h - WIN0H - Window 0 Horizontal Dimensions (W)
4000042h - WIN1H - Window 1 Horizontal Dimensions (W)
Bit Expl.
0-7 X2, Rightmost coordinate of window, plus 1
8-15 X1, Leftmost coordinate of window
|
Garbage values of X2>240 or X1>X2 are interpreted as X2=240.
4000044h - WIN0V - Window 0 Vertical Dimensions (W)
4000046h - WIN1V - Window 1 Vertical Dimensions (W)
Bit Expl.
0-7 Y2, Bottom-most coordinate of window, plus 1
8-15 Y1, Top-most coordinate of window
|
Garbage values of Y2>160 or Y1>Y2 are interpreted as Y2=160.
4000048h - WININ - Control of Inside of Window(s) (R/W)
Bit Expl.
0-3 Window 0 BG0-BG3 Enable Bits (0=No Display, 1=Display)
4 Window 0 OBJ Enable Bit (0=No Display, 1=Display)
5 Window 0 Color Special Effect (0=Disable, 1=Enable)
6-7 Not used
8-11 Window 1 BG0-BG3 Enable Bits (0=No Display, 1=Display)
12 Window 1 OBJ Enable Bit (0=No Display, 1=Display)
13 Window 1 Color Special Effect (0=Disable, 1=Enable)
14-15 Not used
|
400004Ah - WINOUT - Control of Outside of Windows & Inside of OBJ Window (R/W)
Bit Expl.
0-3 Outside BG0-BG3 Enable Bits (0=No Display, 1=Display)
4 Outside OBJ Enable Bit (0=No Display, 1=Display)
5 Outside Color Special Effect (0=Disable, 1=Enable)
6-7 Not used
8-11 OBJ Window BG0-BG3 Enable Bits (0=No Display, 1=Display)
12 OBJ Window OBJ Enable Bit (0=No Display, 1=Display)
13 OBJ Window Color Special Effect (0=Disable, 1=Enable)
14-15 Not used
|
The OBJ Window
The dimension of the OBJ Window is specified by OBJs which are having the "OBJ Mode" attribute being set to "OBJ Window". Any non-transparent dots of any such OBJs are marked as OBJ Window area. The OBJ itself is not displayed.
The color, palette, and display priority of these OBJs are ignored. Both DISPCNT Bits 12 and 15 must be set when defining OBJ Window region(s).
Window Priority
In case that more than one window is enabled, and that these windows do overlap, Window 0 is having highest priority, Window 1 medium, and Obj Window lowest priority. Outside of Window is having zero priority, it is used for all dots which are not inside of any window region.
5. 사용 예제
프로그래밍하기 가장 간단한 모드인 프레임 버퍼 모드로 비디오 모드를 설정해 보자. 일단 Engine A와 Engine B에 모두 설정 가능한 프레임 버퍼모드는 256 * 192 pixel 32768 color(15bit)이다.
그럼 설정하는 순서를 다시 생각해 보면 Display 모드를 선택하고, VRAM을 맵핑한 다음, Background 속성을 설정해 주면 된다.
아래는 간단히 프레임 버퍼 모드로 설정하는 코드이다. 비디오 모드 5를 사용하여 BG2와 BG3을 Extended Afine 모드로 설정하고 Background의 크기를 화면 전체 크기(256 * 192 pixel)보다 크게 설정하여 전체를 커버 가능하도록 설정한다. 그리고 Background 모드는 Direct Color 모드를 사용하여 프레임 버퍼모드와 비슷하게 사용하고 BG3의 시작을 Offset 0에서 시작하도록 하여 VRAM의 첫번째 시작부터 화면에 표시되도록 했다.
- /**
Main LCD 및 SUB LCD를 모두 16bit 256 * 196 로 설정한다.
Frame Buffer와 같이 쓸 수 있도록 수정한다.
*/
void InitVideoMode()
{
// set the mode for 2 text layers and two extended background layers
videoSetMode( MODE_5_2D | DISPLAY_BG3_ACTIVE );
videoSetModeSub( MODE_5_2D | DISPLAY_BG3_ACTIVE );
// Video Memory를 설정한다. MAIN 같은 경우는 2개의 VRAM이 맵핑되어있으므로
// 더블 버퍼의 사용도 가능하다.
vramSetMainBanks( VRAM_A_MAIN_BG_0x06000000, VRAM_B_MAIN_BG_0x06020000,
VRAM_C_SUB_BG, VRAM_D_LCD);
- // Background에 대한 설정을 한다. BG_BMP_BASE를 조절하면 스크롤 및
// 더블 버퍼를 구현할 수 있다.
BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE( 0 );// | BG_PRIORITY( 3 );
- // scale을 1, rotation을 0으로 설정하여 frame buffer와 같게 만듬
BG3_XDX = 1 << 8;
BG3_XDY = 0;
BG3_YDX = 0;
BG3_YDY = 1 << 8;
// Translation(Reference Point X/Y-Coordinate)을 0으로 설정
BG3_CX = 0;
BG3_CY = 0;
// x축 및 y축으로 100 pixel 이동
//BG3_CX = 100 << 8;
//BG3_CY = 100 << 8;
SUB_BG3_CR = BG_BMP16_256x256 | BG_BMP_BASE( 0 );// | BG_PRIORITY( 3 );
SUB_BG3_XDX = 1 << 8;
SUB_BG3_XDY = 0;
SUB_BG3_YDX = 0;
SUB_BG3_YDY = 1 << 8;
SUB_BG3_CX = 0;
SUB_BG3_CY = 0;
- // Display에서 VBlank interrupt를 발생시키도록 한다.
REG_DISPSTAT |= DISP_VBLANK_IRQ;
- }
위의 각 함수 및 메크로들은 ndslib 폴더에 source 및 include 폴더에 있는 video.h/c 파일에 있다. 매크로는 첨부파일을 참고하도록 하자.
마지막에 있는 붉은 색 부분은 Display Status 레지스터에 VBLANK 인터럽트를 발생하도록 설정하는 부분이다. 이렇게 하면 주기적으로 화면을 다시 그리는 타이밍에 인터럽트가 발생하여 작업을 처리할 수가 있다.
인터럽트에 대한 자세한 내용은 04 인터럽트 제어(Interrupt Control) 문서를 참조하자.
5.1 화면 스크롤
만약 화면을 스크롤하고 싶다면 어떻게 하면 될까? BG3를 사용한다면 BG3_CY 및 CX에 값을 넣어주면 된다. BG3_CY/CX는 하위 8bit는 소수점을 나타내고 상위 7Bit는 정수부를 나타내므로 8 만큼 좌측으로 Shift 하면 된다.
5.2 더블 버퍼링
만약 더블 버퍼를 사용한다면 BG3_CX/CY를 사용해도 되지만 BG_BMP_BASE() 매크로를 이용하여서 Base Offset을 변경하는 방법도 사용할 수 있다. 256 * 192 pixel * 2Byte를 하면 한 화면에 총 데이터가 96Kbyte가 된다.
Bitmap 모드일때 Base의 값에 16Kbyte를 곱하게 되므로 BG_BMP_BASE( 6 )과 같이 사용하게 되면 프레임 간에 겹치지 않게 사용할 수 있어서 더블 버퍼링이 가능하다.
5.3 인터럽트(Interrupt)
LCD 화면을 Display 할때 한 라인 또는 전체 화면을 그렸을 때, 특정한 신호를 발생하게 할 수 있다. 한 라인을 그렸을 때 H Blank가 발생하며, 전체 화면을 다 그렸을 때가 V Blank가 발생한다. Display 인터럽트에 대한 자세한 내용은 http://nocash.emubase.de/gbatek.htm#lcdiointerruptsandstatus 에서 볼 수 있으며 NDS 인터럽트에 대한 내용은 04 인터럽트 제어(Interrupt Control)에서 찾을 수 있다.
4000004h - DISPSTAT - General LCD Status (Read/Write)
Display status and Interrupt control. The H-Blank conditions are generated once per scanline, including for the 'hidden' scanlines during V-Blank.
Bit Expl.
0 V-Blank flag (Read only) (1=VBlank)
1 H-Blank flag (Read only) (1=HBlank)
2 V-Counter flag (Read only) (1=Match)
3 V-Blank IRQ Enable (1=Enable)
4 H-Blank IRQ Enable (1=Enable)
5 V-Counter IRQ Enable (1=Enable)
6-7 Not used
8-15 V-Count Setting (0-227)
|
The V-Count-Setting value is much the same as LYC of older gameboys, when its value is identical to the content of the VCOUNT register then the V-Counter flag is set (Bit 2), and (if enabled in Bit 5) an interrupt is requested.
4000006h - VCOUNT - Vertical Counter (Read only)
Indicates the currently drawn scanline, values in range from 160-227 indicate 'hidden' scanlines within VBlank area.
Bit Expl.
0-7 Current scanline (0-227)
8-15 Not Used
|
Note: This is much the same than the 'LY' register of older gameboys.
6. 첨부
이 글은 스프링노트에서 작성되었습니다.