Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
chip-ahoyto
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
chip-ahoyto
Commits
6bef8cc6
Verified
Commit
6bef8cc6
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: more conditional quirks
parent
9cdbc0fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#800
passed
2 years ago
Stage: build
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/chip8_neo.rs
+11
-51
11 additions, 51 deletions
src/chip8_neo.rs
src/lib.rs
+1
-0
1 addition, 0 deletions
src/lib.rs
src/macros.rs
+119
-0
119 additions, 0 deletions
src/macros.rs
with
131 additions
and
51 deletions
src/chip8_neo.rs
+
11
−
51
View file @
6bef8cc6
...
...
@@ -3,7 +3,9 @@ use std::io::{Cursor, Read};
use
crate
::{
chip8
::
Chip8
,
chip8
::{
Quirk
,
DISPLAY_HEIGHT
,
DISPLAY_WIDTH
,
FONT_SET
},
display_blank
,
jumping
,
memory
,
shifting
,
util
::
random
,
vf_reset
,
clipping
,
};
#[cfg(feature
=
"wasm"
)]
...
...
@@ -18,24 +20,6 @@ const KEYS_SIZE: usize = 16;
/// the initial PC position for execution.
const
ROM_START
:
usize
=
0x200
;
#[cfg(feature
=
"quirks"
)]
macro_rules!
shifting
{
(
$self:expr
,
$x:expr
,
$y:expr
,
$shift:tt
)
=>
{
if
$self
.quirks.shifting
{
$self
.regs
[
$x
]
=
$self
.regs
[
$x
]
$shift
1
;
}
else
{
$self
.regs
[
$x
]
=
$self
.regs
[
$y
]
$shift
1
;
}
}
}
#[cfg(not(feature
=
"quirks"
))]
macro_rules!
shifting
{
(
$self:expr
,
$x:expr
,
$y:expr
,
$shift:tt
)
=>
{
$self
.regs
[
$x
]
=
$self
.regs
[
$y
]
$shift
1
;
}
}
#[derive(PartialEq)]
enum
WaitVblank
{
NotWaiting
,
...
...
@@ -246,21 +230,15 @@ impl Chip8 for Chip8Neo {
0x0
=>
self
.regs
[
x
]
=
self
.regs
[
y
],
0x1
=>
{
self
.regs
[
x
]
|
=
self
.regs
[
y
];
if
self
.quirks.vf_reset
{
self
.regs
[
0xf
]
=
0
;
}
vf_reset!
(
self
);
}
0x2
=>
{
self
.regs
[
x
]
&=
self
.regs
[
y
];
if
self
.quirks.vf_reset
{
self
.regs
[
0xf
]
=
0
;
}
vf_reset!
(
self
);
}
0x3
=>
{
self
.regs
[
x
]
^=
self
.regs
[
y
];
if
self
.quirks.vf_reset
{
self
.regs
[
0xf
]
=
0
;
}
vf_reset!
(
self
);
}
0x4
=>
{
let
(
result
,
overflow
)
=
self
.regs
[
x
]
.overflowing_add
(
self
.regs
[
y
]);
...
...
@@ -291,11 +269,7 @@ impl Chip8 for Chip8Neo {
0x9000
=>
self
.pc
+=
if
self
.regs
[
x
]
!=
self
.regs
[
y
]
{
2
}
else
{
0
},
0xa000
=>
self
.i
=
address
,
0xb000
=>
{
if
self
.quirks.jumping
{
self
.pc
=
address
+
self
.regs
[
x
]
as
u16
;
}
else
{
self
.pc
=
address
+
self
.regs
[
0x0
]
as
u16
;
}
jumping!
(
self
,
address
,
x
);
}
0xc000
=>
self
.regs
[
x
]
=
byte
&
random
(),
0xd000
=>
{
...
...
@@ -341,16 +315,12 @@ impl Chip8 for Chip8Neo {
0x55
=>
{
self
.ram
[
self
.i
as
usize
..
self
.i
as
usize
+
x
+
1
]
.clone_from_slice
(
&
self
.regs
[
0
..
x
+
1
]);
if
self
.quirks.memory
{
self
.i
=
self
.i
.saturating_add
(
1
);
}
memory!
(
self
);
}
0x65
=>
{
self
.regs
[
0
..
x
+
1
]
.clone_from_slice
(
&
self
.ram
[
self
.i
as
usize
..
self
.i
as
usize
+
x
+
1
]);
if
self
.quirks.memory
{
self
.i
=
self
.i
.saturating_add
(
1
);
}
memory!
(
self
);
}
_
=>
panic!
(
"unimplemented instruction 0xf000, instruction 0x{:04x}"
,
...
...
@@ -444,11 +414,7 @@ impl Chip8Neo {
#[inline(always)]
fn
draw_sprite
(
&
mut
self
,
addr
:
usize
,
x0
:
usize
,
y0
:
usize
,
height
:
usize
)
{
if
self
.quirks.display_blank
&&
self
.wait_vblank
!=
WaitVblank
::
Vblank
{
self
.pause_vblank
();
return
;
}
self
.wait_vblank
=
WaitVblank
::
NotWaiting
;
display_blank!
(
self
);
self
.regs
[
0xf
]
=
0
;
for
y
in
0
..
height
{
let
line_byte
=
self
.ram
[(
addr
+
y
)];
...
...
@@ -457,14 +423,7 @@ impl Chip8Neo {
continue
;
}
let
yf
;
if
self
.quirks.clipping
{
yf
=
y0
+
y
;
if
yf
>=
DISPLAY_HEIGHT
{
continue
;
}
}
else
{
yf
=
(
y0
+
y
)
%
DISPLAY_HEIGHT
;
}
clipping!
(
self
,
y
,
y0
,
yf
);
let
xf
=
(
x0
+
x
)
%
DISPLAY_WIDTH
;
let
addr
=
yf
*
DISPLAY_WIDTH
+
xf
;
if
self
.vram
[
addr
]
==
1
{
...
...
@@ -475,6 +434,7 @@ impl Chip8Neo {
}
}
#[cfg(feature
=
"quirks"
)]
fn
pause_vblank
(
&
mut
self
)
{
self
.paused
=
true
;
self
.wait_vblank
=
WaitVblank
::
Waiting
;
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
1
−
0
View file @
6bef8cc6
pub
mod
chip8
;
pub
mod
chip8_classic
;
pub
mod
chip8_neo
;
pub
mod
macros
;
pub
mod
util
;
This diff is collapsed.
Click to expand it.
src/macros.rs
0 → 100644
+
119
−
0
View file @
6bef8cc6
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
vf_reset
{
(
$self:expr
)
=>
{
if
$self
.quirks.vf_reset
{
$self
.regs
[
0xf
]
=
0
;
}
};
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
vf_reset
{
(
$self:expr
)
=>
{
$self
.regs
[
0xf
]
=
0
;
};
}
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
memory
{
(
$self:expr
)
=>
{
if
$self
.quirks.memory
{
$self
.i
=
$self
.i
.saturating_add
(
1
);
}
};
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
memory
{
(
$self:expr
)
=>
{
$self
.i
=
$self
.i
.saturating_add
(
1
);
};
}
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
display_blank
{
(
$self:expr
)
=>
{
if
$self
.quirks.display_blank
&&
$self
.wait_vblank
!=
WaitVblank
::
Vblank
{
$self
.pause_vblank
();
return
;
}
$self
.wait_vblank
=
WaitVblank
::
NotWaiting
;
};
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
display_blank
{
(
$self:expr
)
=>
{};
}
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
display_blank
{
(
$self:expr
,
$y:expr
,
$y0:expr
,
$yf:expr
)
=>
{
if
$self
.quirks.clipping
{
$yf
=
$y0
+
$y
;
if
$yf
>=
DISPLAY_HEIGHT
{
continue
;
}
}
else
{
$yf
=
(
$y0
+
$y
)
%
DISPLAY_HEIGHT
;
}
};
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
clipping
{
(
$self:expr
,
$y:expr
,
$y0:expr
,
$yf:expr
)
=>
{
$yf
=
$y0
+
$y
;
if
$yf
>=
DISPLAY_HEIGHT
{
continue
;
}
}
}
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
shifting
{
(
$self:expr
,
$x:expr
,
$y:expr
,
$shift:tt
)
=>
{
if
$self
.quirks.shifting
{
$self
.regs
[
$x
]
=
$self
.regs
[
$x
]
$shift
1
;
}
else
{
$self
.regs
[
$x
]
=
$self
.regs
[
$y
]
$shift
1
;
}
}
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
shifting
{
(
$self:expr
,
$x:expr
,
$y:expr
,
$shift:tt
)
=>
{
$self
.regs
[
$x
]
=
$self
.regs
[
$y
]
$shift
1
;
}
}
#[cfg(feature
=
"quirks"
)]
#[macro_export]
macro_rules!
jumping
{
(
$self:expr
,
$address:expr
,
$x:expr
)
=>
{
if
$self
.quirks.jumping
{
$self
.pc
=
$address
+
$self
.regs
[
$x
]
as
u16
;
}
else
{
$self
.pc
=
$address
+
$self
.regs
[
0x0
]
as
u16
;
}
};
}
#[cfg(not(feature
=
"quirks"
))]
#[macro_export]
macro_rules!
jumping
{
(
$self:expr
,
$address:expr
,
$x:expr
)
=>
{
$self
.pc
=
$address
+
$self
.regs
[
0x0
]
as
u16
;
};
}
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