all repos — mgba @ 0c665cf5a3d3067a6377a2fef5bffc484bbbd0c3

mGBA Game Boy Advance Emulator

src/gb/test/rtc.c (view raw)

  1/* Copyright (c) 2013-2016 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#include "util/test/suite.h"
  7
  8#include "core/core.h"
  9#include "gb/core.h"
 10#include "gb/gb.h"
 11#include "gb/mbc.h"
 12#include "util/vfs.h"
 13
 14struct GBRTCTest {
 15	struct mRTCSource d;
 16	struct mCore* core;
 17	struct VFile* fakeROM;
 18	time_t nextTime;
 19};
 20
 21static void _sampleRtc(struct GB* gb) {
 22	gb->memory.rtcLastLatch = 0;
 23	GBStore8(gb->cpu, 0x6000, 0);
 24	GBStore8(gb->cpu, 0x6000, 1);
 25}
 26
 27static void _sampleRtcKeepLatch(struct GB* gb) {
 28	GBStore8(gb->cpu, 0x6000, 0);
 29	GBStore8(gb->cpu, 0x6000, 1);
 30}
 31
 32static time_t _testTime(struct mRTCSource* source) {
 33	struct GBRTCTest* test = (struct GBRTCTest*) source;
 34	return test->nextTime;
 35}
 36
 37M_TEST_SUITE_SETUP(GBRTC) {
 38	struct GBRTCTest* test = malloc(sizeof(*test));
 39	if (!test) {
 40		return -1;
 41	}
 42	test->core = GBCoreCreate();
 43	test->d.sample = NULL;
 44	test->d.unixTime = _testTime;
 45	test->nextTime = 0;
 46	if (!test->core) {
 47		*state = NULL;
 48		return -1;
 49	}
 50	test->core->init(test->core);
 51	struct VFile* vf = VFileMemChunk(NULL, 2048);
 52	GBSynthesizeROM(vf);
 53	test->core->loadROM(test->core, vf);
 54	test->core->setRTC(test->core, &test->d);
 55	struct GB* gb = test->core->board;
 56	struct GBCartridge* cart = (struct GBCartridge*) &gb->memory.rom[0x100];
 57	cart->type = 0x0F;
 58
 59	*state = test;
 60	return 0;
 61}
 62
 63M_TEST_SUITE_TEARDOWN(GBRTC) {
 64	if (!*state) {
 65		return 0;
 66	}
 67	struct GBRTCTest* test = *state;
 68	test->core->deinit(test->core);
 69	free(test);
 70	return 0;
 71}
 72
 73M_TEST_DEFINE(create) {
 74	struct GBRTCTest* test = *state;
 75	test->core->reset(test->core);
 76	struct GB* gb = test->core->board;
 77
 78	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
 79	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
 80}
 81
 82M_TEST_DEFINE(tickSecond) {
 83	struct GBRTCTest* test = *state;
 84	test->core->reset(test->core);
 85	struct GB* gb = test->core->board;
 86	test->nextTime = 1;
 87
 88	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
 89	memset(gb->memory.rtcRegs, 0, sizeof(expected));
 90
 91	gb->memory.rtcRegs[0] = 0;
 92	expected[0] = 1;
 93	_sampleRtc(gb);
 94	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
 95
 96	gb->memory.rtcRegs[0] = 1;
 97	expected[0] = 2;
 98	_sampleRtc(gb);
 99	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
100
101	gb->memory.rtcRegs[0] = 59;
102	gb->memory.rtcRegs[1] = 0;
103	expected[0] = 0;
104	expected[1] = 1;
105	_sampleRtc(gb);
106	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
107}
108
109M_TEST_DEFINE(tick30Seconds) {
110	struct GBRTCTest* test = *state;
111	test->core->reset(test->core);
112	struct GB* gb = test->core->board;
113	test->nextTime = 30;
114
115	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
116	memset(gb->memory.rtcRegs, 0, sizeof(expected));
117
118	gb->memory.rtcRegs[0] = 0;
119	expected[0] = 30;
120	_sampleRtc(gb);
121	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
122
123	gb->memory.rtcRegs[0] = 1;
124	expected[0] = 31;
125	_sampleRtc(gb);
126	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
127
128	gb->memory.rtcRegs[0] = 30;
129	gb->memory.rtcRegs[1] = 0;
130	expected[0] = 0;
131	expected[1] = 1;
132	_sampleRtc(gb);
133	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
134
135	gb->memory.rtcRegs[0] = 59;
136	gb->memory.rtcRegs[1] = 0;
137	expected[0] = 29;
138	expected[1] = 1;
139	_sampleRtc(gb);
140	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
141}
142
143M_TEST_DEFINE(tickMinute) {
144	struct GBRTCTest* test = *state;
145	test->core->reset(test->core);
146	struct GB* gb = test->core->board;
147	test->nextTime = 60;
148
149	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
150	memset(gb->memory.rtcRegs, 0, sizeof(expected));
151
152	gb->memory.rtcRegs[0] = 0;
153	gb->memory.rtcRegs[1] = 0;
154	expected[0] = 0;
155	expected[1] = 1;
156	_sampleRtc(gb);
157	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
158
159	gb->memory.rtcRegs[0] = 1;
160	gb->memory.rtcRegs[1] = 0;
161	expected[0] = 1;
162	expected[1] = 1;
163	_sampleRtc(gb);
164	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
165
166	gb->memory.rtcRegs[0] = 0;
167	gb->memory.rtcRegs[1] = 59;
168	gb->memory.rtcRegs[2] = 0;
169	expected[0] = 0;
170	expected[1] = 0;
171	expected[2] = 1;
172	_sampleRtc(gb);
173	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
174
175	gb->memory.rtcRegs[0] = 1;
176	gb->memory.rtcRegs[1] = 59;
177	gb->memory.rtcRegs[2] = 0;
178	expected[0] = 1;
179	expected[1] = 0;
180	expected[2] = 1;
181	_sampleRtc(gb);
182	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
183}
184
185M_TEST_DEFINE(tick90Seconds) {
186	struct GBRTCTest* test = *state;
187	test->core->reset(test->core);
188	struct GB* gb = test->core->board;
189	test->nextTime = 90;
190
191	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
192	memset(gb->memory.rtcRegs, 0, sizeof(expected));
193
194	gb->memory.rtcRegs[0] = 0;
195	gb->memory.rtcRegs[1] = 0;
196	expected[0] = 30;
197	expected[1] = 1;
198	_sampleRtc(gb);
199	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
200
201	gb->memory.rtcRegs[0] = 1;
202	gb->memory.rtcRegs[1] = 0;
203	expected[0] = 31;
204	expected[1] = 1;
205	_sampleRtc(gb);
206	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
207
208	gb->memory.rtcRegs[0] = 30;
209	gb->memory.rtcRegs[1] = 0;
210	expected[0] = 0;
211	expected[1] = 2;
212	_sampleRtc(gb);
213	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
214
215	gb->memory.rtcRegs[0] = 59;
216	gb->memory.rtcRegs[1] = 0;
217	expected[0] = 29;
218	expected[1] = 2;
219	_sampleRtc(gb);
220	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
221
222	gb->memory.rtcRegs[0] = 0;
223	gb->memory.rtcRegs[1] = 59;
224	gb->memory.rtcRegs[2] = 0;
225	expected[0] = 30;
226	expected[1] = 0;
227	expected[2] = 1;
228	_sampleRtc(gb);
229	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
230
231	gb->memory.rtcRegs[0] = 1;
232	gb->memory.rtcRegs[1] = 59;
233	gb->memory.rtcRegs[2] = 0;
234	expected[0] = 31;
235	expected[1] = 0;
236	expected[2] = 1;
237	_sampleRtc(gb);
238	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
239}
240
241M_TEST_DEFINE(tick30Minutes) {
242	struct GBRTCTest* test = *state;
243	test->core->reset(test->core);
244	struct GB* gb = test->core->board;
245	test->nextTime = 1800;
246
247	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
248	memset(gb->memory.rtcRegs, 0, sizeof(expected));
249
250	gb->memory.rtcRegs[0] = 0;
251	gb->memory.rtcRegs[1] = 0;
252	expected[0] = 0;
253	expected[1] = 30;
254	_sampleRtc(gb);
255	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
256
257	gb->memory.rtcRegs[0] = 1;
258	gb->memory.rtcRegs[1] = 0;
259	expected[0] = 1;
260	expected[1] = 30;
261	_sampleRtc(gb);
262	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
263
264	gb->memory.rtcRegs[0] = 0;
265	gb->memory.rtcRegs[1] = 59;
266	gb->memory.rtcRegs[2] = 0;
267	expected[0] = 0;
268	expected[1] = 29;
269	expected[2] = 1;
270	_sampleRtc(gb);
271	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
272
273	gb->memory.rtcRegs[0] = 1;
274	gb->memory.rtcRegs[1] = 59;
275	gb->memory.rtcRegs[2] = 0;
276	expected[0] = 1;
277	expected[1] = 29;
278	expected[2] = 1;
279	_sampleRtc(gb);
280	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
281}
282
283M_TEST_DEFINE(tickHour) {
284	struct GBRTCTest* test = *state;
285	test->core->reset(test->core);
286	struct GB* gb = test->core->board;
287	test->nextTime = 3600;
288
289	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
290	memset(gb->memory.rtcRegs, 0, sizeof(expected));
291
292	gb->memory.rtcRegs[0] = 0;
293	gb->memory.rtcRegs[1] = 0;
294	gb->memory.rtcRegs[2] = 0;
295	expected[0] = 0;
296	expected[1] = 0;
297	expected[2] = 1;
298	_sampleRtc(gb);
299	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
300
301	gb->memory.rtcRegs[0] = 1;
302	gb->memory.rtcRegs[1] = 0;
303	gb->memory.rtcRegs[2] = 0;
304	expected[0] = 1;
305	expected[1] = 0;
306	expected[2] = 1;
307	_sampleRtc(gb);
308	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
309
310	gb->memory.rtcRegs[0] = 0;
311	gb->memory.rtcRegs[1] = 1;
312	gb->memory.rtcRegs[2] = 0;
313	expected[0] = 0;
314	expected[1] = 1;
315	expected[2] = 1;
316	_sampleRtc(gb);
317	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
318
319	gb->memory.rtcRegs[0] = 0;
320	gb->memory.rtcRegs[1] = 0;
321	gb->memory.rtcRegs[2] = 1;
322	expected[0] = 0;
323	expected[1] = 0;
324	expected[2] = 2;
325	_sampleRtc(gb);
326	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
327
328	gb->memory.rtcRegs[0] = 0;
329	gb->memory.rtcRegs[1] = 0;
330	gb->memory.rtcRegs[2] = 23;
331	gb->memory.rtcRegs[3] = 0;
332	expected[0] = 0;
333	expected[1] = 0;
334	expected[2] = 0;
335	expected[3] = 1;
336	_sampleRtc(gb);
337	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
338}
339
340M_TEST_DEFINE(tick12Hours) {
341	struct GBRTCTest* test = *state;
342	test->core->reset(test->core);
343	struct GB* gb = test->core->board;
344	test->nextTime = 3600 * 12;
345
346	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
347	memset(gb->memory.rtcRegs, 0, sizeof(expected));
348
349	gb->memory.rtcRegs[0] = 0;
350	gb->memory.rtcRegs[1] = 0;
351	gb->memory.rtcRegs[2] = 0;
352	expected[0] = 0;
353	expected[1] = 0;
354	expected[2] = 12;
355	_sampleRtc(gb);
356	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
357
358	gb->memory.rtcRegs[0] = 1;
359	gb->memory.rtcRegs[1] = 0;
360	gb->memory.rtcRegs[2] = 0;
361	expected[0] = 1;
362	expected[1] = 0;
363	expected[2] = 12;
364	_sampleRtc(gb);
365	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
366
367	gb->memory.rtcRegs[0] = 0;
368	gb->memory.rtcRegs[1] = 1;
369	gb->memory.rtcRegs[2] = 0;
370	expected[0] = 0;
371	expected[1] = 1;
372	expected[2] = 12;
373	_sampleRtc(gb);
374	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
375
376	gb->memory.rtcRegs[0] = 1;
377	gb->memory.rtcRegs[1] = 1;
378	gb->memory.rtcRegs[2] = 0;
379	expected[0] = 1;
380	expected[1] = 1;
381	expected[2] = 12;
382	_sampleRtc(gb);
383	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
384
385	gb->memory.rtcRegs[0] = 0;
386	gb->memory.rtcRegs[1] = 0;
387	gb->memory.rtcRegs[2] = 12;
388	gb->memory.rtcRegs[3] = 0;
389	expected[0] = 0;
390	expected[1] = 0;
391	expected[2] = 0;
392	expected[3] = 1;
393	_sampleRtc(gb);
394	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
395
396	gb->memory.rtcRegs[0] = 0;
397	gb->memory.rtcRegs[1] = 0;
398	gb->memory.rtcRegs[2] = 23;
399	gb->memory.rtcRegs[3] = 0;
400	expected[0] = 0;
401	expected[1] = 0;
402	expected[2] = 11;
403	expected[3] = 1;
404	_sampleRtc(gb);
405	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
406}
407
408M_TEST_DEFINE(tickDay) {
409	struct GBRTCTest* test = *state;
410	test->core->reset(test->core);
411	struct GB* gb = test->core->board;
412	test->nextTime = 3600 * 24;
413
414	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
415	memset(gb->memory.rtcRegs, 0, sizeof(expected));
416
417	gb->memory.rtcRegs[0] = 0;
418	gb->memory.rtcRegs[1] = 0;
419	gb->memory.rtcRegs[2] = 0;
420	gb->memory.rtcRegs[3] = 0;
421	expected[0] = 0;
422	expected[1] = 0;
423	expected[2] = 0;
424	expected[3] = 1;
425	_sampleRtc(gb);
426	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
427
428	gb->memory.rtcRegs[0] = 1;
429	gb->memory.rtcRegs[1] = 0;
430	gb->memory.rtcRegs[2] = 0;
431	gb->memory.rtcRegs[3] = 0;
432	expected[0] = 1;
433	expected[1] = 0;
434	expected[2] = 0;
435	expected[3] = 1;
436	_sampleRtc(gb);
437	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
438
439	gb->memory.rtcRegs[0] = 0;
440	gb->memory.rtcRegs[1] = 1;
441	gb->memory.rtcRegs[2] = 0;
442	gb->memory.rtcRegs[3] = 0;
443	expected[0] = 0;
444	expected[1] = 1;
445	expected[2] = 0;
446	expected[3] = 1;
447	_sampleRtc(gb);
448	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
449
450	gb->memory.rtcRegs[0] = 1;
451	gb->memory.rtcRegs[1] = 1;
452	gb->memory.rtcRegs[2] = 0;
453	gb->memory.rtcRegs[3] = 0;
454	expected[0] = 1;
455	expected[1] = 1;
456	expected[2] = 0;
457	expected[3] = 1;
458	_sampleRtc(gb);
459	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
460
461	gb->memory.rtcRegs[0] = 0;
462	gb->memory.rtcRegs[1] = 0;
463	gb->memory.rtcRegs[2] = 12;
464	gb->memory.rtcRegs[3] = 0;
465	expected[0] = 0;
466	expected[1] = 0;
467	expected[2] = 12;
468	expected[3] = 1;
469	_sampleRtc(gb);
470	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
471
472	gb->memory.rtcRegs[0] = 0;
473	gb->memory.rtcRegs[1] = 0;
474	gb->memory.rtcRegs[2] = 23;
475	gb->memory.rtcRegs[3] = 0;
476	expected[0] = 0;
477	expected[1] = 0;
478	expected[2] = 23;
479	expected[3] = 1;
480	_sampleRtc(gb);
481	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
482
483	gb->memory.rtcRegs[0] = 0;
484	gb->memory.rtcRegs[1] = 0;
485	gb->memory.rtcRegs[2] = 0;
486	gb->memory.rtcRegs[3] = 1;
487	expected[0] = 0;
488	expected[1] = 0;
489	expected[2] = 0;
490	expected[3] = 2;
491	_sampleRtc(gb);
492	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
493
494	gb->memory.rtcRegs[0] = 0;
495	gb->memory.rtcRegs[1] = 0;
496	gb->memory.rtcRegs[2] = 1;
497	gb->memory.rtcRegs[3] = 1;
498	expected[0] = 0;
499	expected[1] = 0;
500	expected[2] = 1;
501	expected[3] = 2;
502	_sampleRtc(gb);
503	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
504}
505
506M_TEST_DEFINE(wideTickDay) {
507	struct GBRTCTest* test = *state;
508	test->core->reset(test->core);
509	struct GB* gb = test->core->board;
510	test->nextTime = 3600 * 24 * 2001;
511
512	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
513	memset(gb->memory.rtcRegs, 0, sizeof(expected));
514
515	gb->memory.rtcRegs[0] = 0;
516	gb->memory.rtcRegs[1] = 0;
517	gb->memory.rtcRegs[2] = 0;
518	gb->memory.rtcRegs[3] = 0;
519	expected[0] = 0;
520	expected[1] = 0;
521	expected[2] = 0;
522	expected[3] = 1;
523	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
524	_sampleRtcKeepLatch(gb);
525	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
526
527	gb->memory.rtcRegs[0] = 1;
528	gb->memory.rtcRegs[1] = 0;
529	gb->memory.rtcRegs[2] = 0;
530	gb->memory.rtcRegs[3] = 0;
531	expected[0] = 1;
532	expected[1] = 0;
533	expected[2] = 0;
534	expected[3] = 1;
535	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
536	_sampleRtcKeepLatch(gb);
537	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
538
539	gb->memory.rtcRegs[0] = 0;
540	gb->memory.rtcRegs[1] = 1;
541	gb->memory.rtcRegs[2] = 0;
542	gb->memory.rtcRegs[3] = 0;
543	expected[0] = 0;
544	expected[1] = 1;
545	expected[2] = 0;
546	expected[3] = 1;
547	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
548	_sampleRtcKeepLatch(gb);
549	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
550
551	gb->memory.rtcRegs[0] = 1;
552	gb->memory.rtcRegs[1] = 1;
553	gb->memory.rtcRegs[2] = 0;
554	gb->memory.rtcRegs[3] = 0;
555	expected[0] = 1;
556	expected[1] = 1;
557	expected[2] = 0;
558	expected[3] = 1;
559	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
560	_sampleRtcKeepLatch(gb);
561	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
562
563	gb->memory.rtcRegs[0] = 0;
564	gb->memory.rtcRegs[1] = 0;
565	gb->memory.rtcRegs[2] = 12;
566	gb->memory.rtcRegs[3] = 0;
567	expected[0] = 0;
568	expected[1] = 0;
569	expected[2] = 12;
570	expected[3] = 1;
571	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
572	_sampleRtcKeepLatch(gb);
573	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
574
575	gb->memory.rtcRegs[0] = 0;
576	gb->memory.rtcRegs[1] = 0;
577	gb->memory.rtcRegs[2] = 23;
578	gb->memory.rtcRegs[3] = 0;
579	expected[0] = 0;
580	expected[1] = 0;
581	expected[2] = 23;
582	expected[3] = 1;
583	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
584	_sampleRtcKeepLatch(gb);
585	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
586
587	gb->memory.rtcRegs[0] = 0;
588	gb->memory.rtcRegs[1] = 0;
589	gb->memory.rtcRegs[2] = 0;
590	gb->memory.rtcRegs[3] = 1;
591	expected[0] = 0;
592	expected[1] = 0;
593	expected[2] = 0;
594	expected[3] = 2;
595	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
596	_sampleRtcKeepLatch(gb);
597	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
598
599	gb->memory.rtcRegs[0] = 0;
600	gb->memory.rtcRegs[1] = 0;
601	gb->memory.rtcRegs[2] = 1;
602	gb->memory.rtcRegs[3] = 1;
603	expected[0] = 0;
604	expected[1] = 0;
605	expected[2] = 1;
606	expected[3] = 2;
607	gb->memory.rtcLastLatch = 3600 * 24 * 2000;
608	_sampleRtcKeepLatch(gb);
609	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
610}
611
612M_TEST_DEFINE(rolloverSecond) {
613	struct GBRTCTest* test = *state;
614	test->core->reset(test->core);
615	struct GB* gb = test->core->board;
616	test->nextTime = 1;
617
618	uint8_t expected[sizeof(gb->memory.rtcRegs)] = { 0, 0, 0, 0, 0 };
619	memset(gb->memory.rtcRegs, 0, sizeof(expected));
620
621	gb->memory.rtcRegs[0] = 59;
622	gb->memory.rtcRegs[1] = 0;
623	expected[0] = 0;
624	expected[1] = 1;
625	_sampleRtc(gb);
626	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
627
628	gb->memory.rtcRegs[0] = 59;
629	gb->memory.rtcRegs[1] = 59;
630	gb->memory.rtcRegs[2] = 0;
631	expected[0] = 0;
632	expected[1] = 0;
633	expected[2] = 1;
634	_sampleRtc(gb);
635	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
636
637	gb->memory.rtcRegs[0] = 59;
638	gb->memory.rtcRegs[1] = 59;
639	gb->memory.rtcRegs[2] = 23;
640	gb->memory.rtcRegs[3] = 0;
641	expected[0] = 0;
642	expected[1] = 0;
643	expected[2] = 0;
644	expected[3] = 1;
645	_sampleRtc(gb);
646	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
647
648	gb->memory.rtcRegs[0] = 59;
649	gb->memory.rtcRegs[1] = 59;
650	gb->memory.rtcRegs[2] = 23;
651	gb->memory.rtcRegs[3] = 0xFF;
652	gb->memory.rtcRegs[4] = 0;
653	expected[0] = 0;
654	expected[1] = 0;
655	expected[2] = 0;
656	expected[3] = 0;
657	expected[4] = 1;
658	_sampleRtc(gb);
659	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
660
661	gb->memory.rtcRegs[0] = 59;
662	gb->memory.rtcRegs[1] = 59;
663	gb->memory.rtcRegs[2] = 23;
664	gb->memory.rtcRegs[3] = 0xFF;
665	gb->memory.rtcRegs[4] = 1;
666	expected[0] = 0;
667	expected[1] = 0;
668	expected[2] = 0;
669	expected[3] = 0;
670	expected[4] = 0x80;
671	_sampleRtc(gb);
672	assert_memory_equal(gb->memory.rtcRegs, expected, sizeof(expected));
673}
674
675M_TEST_SUITE_DEFINE_SETUP_TEARDOWN(GBRTC,
676	cmocka_unit_test(create),
677	cmocka_unit_test(tickSecond),
678	cmocka_unit_test(tick30Seconds),
679	cmocka_unit_test(tickMinute),
680	cmocka_unit_test(tick90Seconds),
681	cmocka_unit_test(tick30Minutes),
682	cmocka_unit_test(tickHour),
683	cmocka_unit_test(tick12Hours),
684	cmocka_unit_test(tickDay),
685	cmocka_unit_test(wideTickDay),
686	cmocka_unit_test(rolloverSecond))