Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
2a533129
Verified
Commit
2a533129
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
refactor: small renaming
parent
622d4255
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!18
Multiple PPU fixes that make Boytacean pass dmg_acid2 🎉
Pipeline
#1664
passed
2 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ppu.rs
+22
-17
22 additions, 17 deletions
src/ppu.rs
with
22 additions
and
17 deletions
src/ppu.rs
+
22
−
17
View file @
2a533129
...
...
@@ -763,7 +763,7 @@ impl Ppu {
};
// Get the address of the tile in memory.
let
tile_i
d
_address
=
{
let
tile_i
ndex
_address
=
{
let
tile_map_row
=
tile_y
/
TILE_SIZE
;
let
tile_map_col
=
tile_x
as
u16
/
TILE_SIZE
;
...
...
@@ -784,27 +784,21 @@ impl Ppu {
tile_start_addr
as
u16
+
tile_map_row
*
TILE_MAP_WIDTH
+
tile_map_col
};
let
tile_i
d
=
self
.vram
[
tile_i
d
_address
as
usize
];
let
tile_address
=
self
.tile_data_address
(
tile_i
d
);
let
tile_i
ndex
=
self
.vram
[
tile_i
ndex
_address
as
usize
];
let
tile_address
=
self
.tile_data_address
(
tile_i
ndex
);
// Find the correct vertical position within the tile. Multiply by two because each
// row of the tile takes two bytes.
let
tile_y
=
(
tile_y
%
TILE_SIZE
)
*
2
;
let
addr
=
(
tile_address
+
tile_y
)
as
usize
;
let
mask
=
1
<<
(
TILE_WIDTH
-
1
-
(
tile_x
%
TILE_SIZE
as
u8
)
as
usize
);
let
pixel
=
if
self
.vram
[
addr
]
&
mask
==
mask
{
0x1
}
else
{
0x0
}
|
if
self
.vram
[
addr
+
1
]
&
mask
==
mask
{
0x2
}
else
{
0x0
};
// obtains the current pixel data from the tile and
// re-maps it according to the current palette
// let pixel = self.tiles[tile_index].get(x, y);
let
pixel
=
Ppu
::
shade_number
(
self
.vram
[
addr
],
self
.vram
[
addr
+
1
],
tile_x
%
TILE_SIZE
as
u8
,
);
let
color
=
self
.palette
[
pixel
as
usize
];
// updates the pixel in the color buffer, which stores
...
...
@@ -826,16 +820,27 @@ impl Ppu {
}
}
fn
tile_data_address
(
&
self
,
tile_id
:
u8
)
->
u16
{
fn
shade_number
(
first
:
u8
,
second
:
u8
,
tile_x
:
u8
)
->
u8
{
// Convert x-position into bit position (bit 7 is leftmost bit).
let
color_bit
=
7
-
tile_x
;
let
mask
=
1
<<
color_bit
;
let
mut
color_num
=
0
;
color_num
+=
if
first
&
mask
==
mask
{
0x01
}
else
{
0x00
};
color_num
+=
if
second
&
mask
==
mask
{
0x02
}
else
{
0x00
};
color_num
}
fn
tile_data_address
(
&
self
,
tile_index
:
u8
)
->
u16
{
const
SIGNED_TILE_OFFSET
:
i16
=
128
;
const
TILE_DATA_ROW_SIZE
:
u16
=
16
;
let
start
=
if
self
.bg_tile
{
0x0000
}
else
{
0x0800
};
let
offset
=
if
self
.bg_tile
{
tile_i
d
.into
()
tile_i
ndex
.into
()
}
else
{
(
i16
::
from
(
tile_i
d
as
i8
)
+
SIGNED_TILE_OFFSET
)
as
u16
(
i16
::
from
(
tile_i
ndex
as
i8
)
+
SIGNED_TILE_OFFSET
)
as
u16
};
start
as
u16
+
offset
*
TILE_DATA_ROW_SIZE
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment