-
Notifications
You must be signed in to change notification settings - Fork 0
/
sgb.inc
54 lines (51 loc) · 1.54 KB
/
sgb.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; Super gameboy utility functions
; Is a SGB present ?
check_sgb:
call clear_packet
ld a,010001001b
ld (sgb_packet),a
ld a,000000011b
ld (sgb_packet+1),a
call send_packet
ld a, 030h
ldh (P1 & 0FFh), a
ldh a, (P1 & 0FFh)
ld a, 000h
ldh (P1 & 0FFh), a
ld a, 030h
ldh (P1 & 0FFh), a
ldh a, (P1 & 0FFh)
ret
clear_packet:
ld hl, sgb_packet
xor a
ld b, 16
cp_l1: ldi (hl),a
dec b
jr nz, cp_l1
ret
send_packet:
ld c, 0
ld a, 000h
ld (c), a
ld d, 16
ld hl, sgb_packet
sp_l3: ld b, 8
ldi a, (hl)
ld e, a
sp_l2: ld a, 010h
rr e
jr c, sp_l1
ld a, 020h
sp_l1: ld (c), a
ld a, 030h
ld (c),a
dec b
jr nz, sp_l2
dec d
jr nz, sp_l3
ld a, 020h
ld (c), a
ld a, 030h
ld (c),a
ret