-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
357 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
SubsecondTests: | ||
dw .short_second_write, ShortSecondWrite | ||
dw .long_second_write, LongSecondWrite | ||
dw .short_minute_write, ShortMinuteWrite | ||
dw .long_minute_write, LongMinuteWrite | ||
dw .hour_write, HourWrite | ||
dw .day_low_write, DayLowWrite | ||
dw .day_high_write, DayHighWrite | ||
dw .rtc_off_write, RTCOffTimingTest | ||
dw -1 | ||
|
||
.short_second_write | ||
db "RTCS/500@" | ||
.long_second_write | ||
db "RTCS/900@" | ||
.short_minute_write | ||
db "RTCM/50@" | ||
.long_minute_write | ||
db "RTCM/600@" | ||
.hour_write | ||
db "RTCH/200@" | ||
.day_low_write | ||
db "RTCDL/800@" | ||
.day_high_write | ||
db "RTCDH/300@" | ||
.rtc_off_write | ||
db "RTC off/400@" | ||
|
||
ShortSecondWrite: | ||
write_RTC_register RTCDH, 0 | ||
call WaitNextRTCTick ;ensure that the RTC is actually working! | ||
jp c, TimeoutResult | ||
ld a, RTCS | ||
ld [rRAMB], a | ||
call PrepareTimer | ||
latch_RTC | ||
ld hl, $a000 | ||
ld b, [hl] | ||
.wait | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
jr z, .wait | ||
ld b, a | ||
ld a, 10 | ||
call WaitATimes50ms | ||
ld [hl], b | ||
start_timer | ||
.check | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
check_timer .check, nz | ||
jr LongSecondWrite.done | ||
|
||
LongSecondWrite: | ||
call WaitNextRTCTick | ||
jp c, TimeoutResult | ||
ld a, RTCS | ||
ld [rRAMB], a | ||
ld hl, $a000 | ||
.reject | ||
call Random | ||
and 63 | ||
cp 58 | ||
jr nc, .reject | ||
inc a | ||
ld b, a | ||
call PrepareTimer | ||
ld [hl], b | ||
.wait | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
jr z, .wait | ||
ld a, 2 | ||
call WaitATimes50ms | ||
ld [hl], 0 | ||
start_timer | ||
.check | ||
latch_RTC | ||
ld a, [hl] | ||
and a | ||
check_timer .check, nz | ||
.done | ||
ld hl, hTestResult | ||
call PrintTime | ||
cpw de, 9920 | ||
ret c | ||
cpw de, 10081 | ||
ccf | ||
ret | ||
|
||
; These tests are all identical. I only want to write this thing once. | ||
___test_sub_second_register_write: MACRO | ||
; in: \1: register, \2: time to tick when the register is written (in 50ms increments) | ||
; no \@ in local labels because this is meant to be used as a function body | ||
call WaitNextRTCTick | ||
jp c, TimeoutResult | ||
ld a, \1 | ||
ld [rRAMB], a | ||
ld hl, $a000 | ||
ld [hl], 1 | ||
if (\1) == RTCM | ||
dec a | ||
else | ||
ld a, RTCS | ||
endc | ||
ld [rRAMB], a | ||
call PrepareTimer | ||
latch_RTC | ||
ld b, [hl] | ||
.wait | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
jr z, .wait | ||
ld b, a | ||
ld a, 20 - (\2) | ||
call WaitATimes50ms | ||
start_timer ;start it a few cycles early to make up for the earlier delay | ||
ld a, \1 | ||
ld [rRAMB], a | ||
ld [hl], 0 | ||
if (\1) == RTCM | ||
dec a | ||
else | ||
ld a, RTCS | ||
endc | ||
ld [rRAMB], a | ||
.check | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
check_timer .check, nz | ||
ld hl, hTestResult | ||
call PrintTime | ||
cpw de, (\2) * 500 - 80 | ||
ret c | ||
cpw de, (\2) * 500 + 81 | ||
ccf | ||
ret | ||
ENDM | ||
|
||
ShortMinuteWrite: | ||
___test_sub_second_register_write RTCM, 1 | ||
|
||
LongMinuteWrite: | ||
___test_sub_second_register_write RTCM, 12 | ||
|
||
HourWrite: | ||
___test_sub_second_register_write RTCH, 4 | ||
|
||
DayLowWrite: | ||
___test_sub_second_register_write RTCDL, 16 | ||
|
||
DayHighWrite: | ||
___test_sub_second_register_write RTCDH, 6 | ||
|
||
RTCOffTimingTest: | ||
write_RTC_register RTCDH, 0 | ||
call WaitNextRTCTick | ||
jp c, TimeoutResult | ||
ld a, RTCS | ||
ld [rRAMB], a | ||
latch_RTC | ||
ld hl, $a000 | ||
ld b, [hl] | ||
.wait | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
jr z, .wait | ||
ld b, a | ||
ld a, 12 | ||
call WaitATimes50ms | ||
ld a, RTCDH | ||
ld [rRAMB], a | ||
ld [hl], $40 | ||
ld a, 30 | ||
.loop | ||
rst WaitVBlank | ||
dec a | ||
jr nz, .loop | ||
call PrepareTimer | ||
ld [hl], 0 | ||
start_timer | ||
ld a, RTCS | ||
ld [rRAMB], a | ||
.check | ||
latch_RTC | ||
ld a, [hl] | ||
cp b | ||
check_timer .check, nz | ||
ld hl, hTestResult | ||
call PrintTime | ||
cpw de, 3920 | ||
ret c | ||
cpw de, 4081 | ||
ccf | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
; Test menus: | ||
; - each entry contains two pointers: one to the label and one to the actual test list | ||
; - the list ends with the .end label; no final entry is needed | ||
|
||
Menus: | ||
dw .basic_tests, BasicTests | ||
dw .range_tests, RangeTests | ||
dw .subsecond_tests, SubsecondTests | ||
.end | ||
|
||
.basic_tests | ||
db "Basic tests@" | ||
.range_tests | ||
db "Range tests@" | ||
.subsecond_tests | ||
db "Sub-second writes@" | ||
|
||
; Each test menu entry (defined at the top of its own file) defines the tests in order: | ||
; SampleTests: | ||
; dw .first_test, FirstTest | ||
; dw .second_test, SecondTest | ||
; dw -1 | ||
; Each entry contains a pointer to the label (that will be printed in front of its result) and a | ||
; pointer to the actual test routine. If bit 15 of the label is set (by ORing $8000 into the label), | ||
; the label will be ended with a colon and the result will be printed on the following line. If bit | ||
; 15 of the test routine is set, the test will be skipped (with a result of N/A) if the previous | ||
; test either failed or was also skipped. | ||
; The test routine returns the result message in hTestResult and carry if the test failed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
WaitATimes50ms: | ||
; exactly what it says on the can (assumes a > 0) | ||
; preserves everything but af | ||
; 50 ms = 52428.8 cycles. This is not a nice number by any means. | ||
; all indicated loop timings are one cycle too long (because the last jump is not taken) | ||
push bc | ||
push hl | ||
ld l, a | ||
ld b, a | ||
ld c, 0 | ||
; running total (including call): 18 cycles | ||
.longwait | ||
ld a, 49 | ||
.inner | ||
dec a | ||
jr nz, .inner | ||
dec bc | ||
ld a, b | ||
or c | ||
jr nz, .longwait | ||
; loop total: 204 cycles (times 256 * N iterations) | ||
; running total: 52224 * N + 17 cycles | ||
; remaining: 204.8 * (N - 1) + 187.8 cycles | ||
ld c, l | ||
ld b, a ;a = 0 here | ||
ld a, 2 | ||
; this weird way of dividing by 5 ensures that the time taken is a linear function of N | ||
.divloop | ||
inc a | ||
cp 5 | ||
jr nz, .first_div_skip | ||
inc b | ||
.first_div_skip | ||
cp 5 | ||
jr nz, .second_div_skip | ||
xor a | ||
.second_div_skip | ||
dec c | ||
jr nz, .divloop | ||
; loop total: 15 cycles (times N iterations) | ||
; remaining: 189.8 * (N - 1) + 169.8 cycles | ||
; = 190 * (N - 1) + 170 - b cycles (because b = N / 5 at this point, rounded to nearest) | ||
dec l | ||
jr z, .no_extra | ||
.extraloop | ||
ld a, 46 | ||
.extrainner | ||
dec a | ||
jr nz, .extrainner | ||
nop | ||
dec l | ||
jr nz, .extraloop | ||
; loop total: 190 cycles (times N - 1 iterations) | ||
add hl, hl ;dummy instruction to make up for the two lost cycles for jumps not taken | ||
.no_extra | ||
; remaining: 166 - b cycles (b <= 51) | ||
ld a, 138 | ||
sub b | ||
; remaining: 163 - b = a + 25 cycles | ||
ld b, a | ||
srl b | ||
srl b | ||
.final_loop | ||
dec b | ||
jr nz, .final_loop | ||
; loop total: 4 cycles (times a & ~3 iterations) | ||
cpl | ||
and 3 | ||
; remaining: (a ^ 3) + 18 cycles | ||
add a, LOW(.exit) | ||
ld l, a | ||
adc HIGH(.exit) | ||
sub l | ||
ld h, a | ||
jp hl | ||
; remaining: (old a ^ 3) + 10 cycles - exactly enough for 0-3 nops, two pops and a ret | ||
|
||
.exit | ||
nop | ||
nop | ||
nop | ||
pop hl | ||
pop bc | ||
ret |
Oops, something went wrong.