85 Commits

Author SHA1 Message Date
1076d02638 interrupt: first-pass implementation of interrupts
Only manual and V-blank interrupts work, for now. This implements
enough to make the EI and DI parts of Blargg's Interrupt test pass.
2018-09-20 20:55:51 -07:00
593d9d3600 gbdb,memory: require memory files on initialization
This will make it a little bit easier to set up the proper MBC when
they are implemented.
2018-09-11 21:15:14 -07:00
927886b7f3 cpu: pass blargg cpu tests 1,3-9 2018-09-10 22:11:36 -07:00
a1e12fc594 cpu: make blarg cpu instr test 7 pass 2018-09-10 22:11:00 -07:00
5675aedc91 integrate readline with gbdb
...for better interactive debugging with history.

Also, make commands return error codes so that only commands that
execute successfully will be added to the command history.
2018-09-10 22:11:00 -07:00
b22fc6f44a cpu: pass blargh instr tests 3,5,6,8,9 2018-09-03 21:57:55 -07:00
c0262cba63 cpu: get blargh cpu test 3 passing 2018-08-28 22:39:36 -07:00
c4ded6d077 cpu: get blarg CPU instruction test 6 passing
Its been too long since a checkin, but here's some of the
improvements:

- Support for diffing with other emulators
- Better disassmbed output
- New CPU instructions implemented
- Lots of CPU fixes
2018-08-26 22:57:35 -07:00
6f9ed73ef2 gbdb: refactor command parsing
Instead of passing around a string and having each command parse off
additional tokens, have a single command to parse all of the tokens,
and the commands can pass around a token list. Then each
command/subcommand can pop off whatever arguments they need.
2018-07-22 21:55:10 -07:00
5a5ccafbb4 common: add generic tokenization code
This is a little cleaner than passing around strings which are parsed
incrementally.
2018-07-22 16:18:32 -07:00
66539071de tri: exact matches are never ambiguous
Even when the exact match is a prefix of a longer match.
2018-07-22 16:17:50 -07:00
9c8c3bda9e fixup: more logging code 2018-07-22 16:17:36 -07:00
e1e3111976 cpu: add more asserts for unimplemented ops
Since the bootrom is now executing successfully, these will be more
necessary for identifying when new instructions are used.
2018-07-22 16:15:52 -07:00
f659af54e1 gbdb,video: improve logging
Add more runtime toggles and add the ability to log to a file for
faster runs and better searchability.
2018-07-22 16:15:10 -07:00
53cd4ab7e5 video: first signs of life
The video code now writes out a bmp file per-frame. With this patch
applied, the Nintendo logo is rendered in each frame.

There is still plenty of work to be done. Pretty much everything is
hardcoded to make the bootrom work.
2018-07-20 20:08:15 -07:00
cd66ad8a89 memory: separate the memory-related code into it's own file
After doing a little reading about the way the memory banks are
mapped, it looks like this code is going to grow. Separate it into
it's own file.

While we're at it, make gb_mem_read() a proper function instead of a
callback. Because these functions are used so frequently, this
corresponds to a ~10-20% performance benefit (due to LTO).
2018-07-09 05:28:14 +00:00
c8ba18f6e3 gbdb: re-indent the file
To make up for variations in editor config.
2018-07-09 02:41:42 +00:00
81f74815d8 cpu: re-indent the file
Running text editors in different environments led to some variations
in indentation.
2018-07-09 02:41:42 +00:00
86191c3c09 cpu: remove some double-calls of mem_read()
For a veeery small performance benefit.
2018-07-09 02:41:41 +00:00
ea2ea1e293 gbdb,cpu,video: reduce number of calls to cycle functions
Instead of calling cpu_cycle() and video_cycle() once per emulated
cycle, call cpu_cycle() once per emulated instruction. This should not
have any obvious effects on the emulation (as currently written),
because all of the memory reads and writes are done in the first
"cycle" of the instruction.

This patch results in a substantial performance gain (>100%, if I
recall correctly).
2018-07-09 02:38:50 +00:00
447276d029 boot_test: updates for changes to breakpoints
Because now they actually stop in the correct place.

Also, some other fixups because I'm too lazy to properly split patches
for a personal project.
2018-07-09 02:36:20 +00:00
213c08fa18 gbdb: remove some conditionals from mem_read()
By reading directly from a "RAM" array, and copying in the cart data
over the old bootrom.

Also, some other fixups because I'm too lazy to properly split patches
for a personal project.
2018-07-09 02:34:24 +00:00
1bb3d8512a cpu,gbdb: implement better breakpoints
Previously, gbdb had to check several signals, including the current
PC, to determine when do_run() should stop. This code was hotpath and
unecessarily slow.

Instead, leverage a n undefined instruction (0xd3) as a breakpoint instruction.
When the CPU emulation encounters this instruction, it will call a callback
which is implemented by gbdb. This can set a simple flag which is less expensive to
query.

Finally, both the signal handler and the breakpoint callback set specific
"paused" flags and a generic "pause" flag. Now, do_run() can simply check
the generic "paused" flag, then use the specific flags to determine the
stop reason.

This change increased performance by ~10% on Raspberry Pi.
2018-07-01 23:59:50 +00:00
9d40f5026a cpu: change cpu cycle calculation
The Gameboy CPU runs at ~4MHz, but all the instructions take some
number of cycles divisible by 4.

This patch causes the cpu_cycle() to run a single 1MHz cycle, instead
of requiring 4 calls at 4MHz to perform the same emulation. Based on
the code in gbdb, the video controller now appears to run much slower,
and the timings needs to be verified.

This results in a large performance gain.
2018-07-01 22:00:02 +00:00
01c1c9e393 gbdb: change cycle calculation for better performance
The conditions are hotpath, so pre-calcuate the end cycle count instead of doing it every loop.

I didn't verify that the compiler wasn't doing this anyway, but this won't hurt.
2018-07-01 21:57:25 +00:00
c53802495c build: do not use LTO for --perf
LTO results in a significant performance boost, but hurts debugability of the results from perf. For now, disable it.
2018-07-01 21:54:27 +00:00
25e26804a9 cpu: correct some print formats and use more "native" types
These were found while running on a Raspberry Pi (ARM).
2018-07-01 21:43:49 +00:00
100704eb1a common: add simple bitmap image writer
This will be useful for initial testing of the video processor.
2018-06-30 09:45:50 -07:00
e520e64bc4 cpu: fix C flag calculation during ADD A,* 2018-06-17 14:34:09 -07:00
6e3c9f4448 cpu: implement all BIT, SET, and RES opcodes
The CPU now runs until it hits a "HALT" instruction in my test game.
2018-06-17 14:34:09 -07:00
fb1deb05d5 cpu: correct opcode 0x22 to be "LD (HL+), A" 2018-06-17 14:34:09 -07:00
c1f972c448 cpu: fix DEC C to decrement the correct register
Now the CPU runs to the end of the boot ROM
2018-06-17 14:34:09 -07:00
0a3340f4fc Fix assertion on $af register and add more debug output to asserts 2018-06-17 14:34:09 -07:00
a4df6411ca Update boot test to check registers on completion of boot 2018-06-17 14:34:09 -07:00
max
6b2e3464cc cleanup 2018-05-03 05:23:36 +00:00
d20d929335 test: add assertions during video init 2018-02-19 06:52:21 +00:00
ee318b348d video: fix writes 2018-02-19 06:51:48 +00:00
1a0dcbdb81 cpu: implement LDH instructions 2018-02-19 06:51:28 +00:00
bd95e66280 fixup whitespace 2018-02-19 05:41:26 +00:00
29ce85b87c gbdb: optimize breakpoints and add runto 2018-02-19 05:13:40 +00:00
94551e3e61 build: add -flto flag for performance and perf configuration 2018-02-19 04:34:33 +00:00
9b69088b35 pushing to dev 2018-02-18 12:51:10 -08:00
d62a8d3f0e cpu: implement enought to make bootrom use display hardware 2018-01-01 16:51:56 -08:00
92f9ef591b gbdb: add scripting features for automatic testing 2018-01-01 16:50:14 -08:00
3f11a3a167 cpu: rewrite to a single switch-based dispatch
This will make it easier to experiment with direct-threading in the future.
2017-11-19 18:39:12 -08:00
af645d54dd gbasm: make code support gcc -pedantic 2017-11-19 18:27:55 -08:00
ebc65ac4a5 build: make the build emit relative paths 2017-11-19 18:26:39 -08:00
3976d8635e gbdb: add support for multiple commands on single line 2017-11-19 18:25:50 -08:00
23898c72b6 WIP 2017-09-17 19:02:46 -04:00
8e3a8056fa WIP: idk 2017-09-17 10:35:55 -04:00