-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3forth.asm
More file actions
88 lines (76 loc) · 1.66 KB
/
3forth.asm
File metadata and controls
88 lines (76 loc) · 1.66 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
; 3-instruction Forth bootroom for Game Boy (DMG).
;
; Wire protocol on the link cable (GB is slave, PC is master):
; 01 hi lo -> GB replies with byte at address hi:lo (XC@ fetch)
; 02 hi lo val -> GB stores val at hi:lo (XC! store)
; 03 hi lo -> GB calls subroutine at hi:lo (XCALL)
;
; Every byte from PC clocks in one byte from GB's SB register, so XC@'s
; response is clocked out by the PC sending one dummy byte after the address.
; The PC is responsible for setting up VRAM, LCDC, palettes, etc. via XC!.
SB EQU $01 ; serial data register (FF01)
SC EQU $02 ; serial control register (FF02)
; XCALL $0008 halts the CPU in a tight loop; BGB's -br 0008 breakpoint lands
; here so we can auto-exit with a screenshot for scripted smoke tests.
SECTION "Stop", ROM0[$0008]
StopHere:
ld b, b
.loop:
jr .loop
SECTION "Header", ROM0[$100]
nop
jp Start
ds $4C ; $104..$14F: logo/title/checksum; rgbfix fills this
SECTION "Main", ROM0[$150]
Start:
di
ld sp, $FFFE
.loop:
call GetByte
cp 1
jr z, .fetch
cp 2
jr z, .store
cp 3
jr z, .call
jr .loop
.fetch:
call GetAddr
ld a, [hl]
call SendByte
jr .loop
.store:
call GetAddr
call GetByte
ld [hl], a
jr .loop
.call:
call GetAddr
call CallHL
jr .loop
GetByte:
ld a, $80
ldh [SC], a
.wait:
ldh a, [SC]
bit 7, a
jr nz, .wait
ldh a, [SB]
ret
SendByte:
ldh [SB], a
ld a, $80
ldh [SC], a
.wait:
ldh a, [SC]
bit 7, a
jr nz, .wait
ret
GetAddr:
call GetByte
ld h, a
call GetByte
ld l, a
ret
CallHL:
jp hl