aboutsummaryrefslogtreecommitdiffstats
path: root/src/net.asm
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.asm')
-rw-r--r--src/net.asm41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/net.asm b/src/net.asm
new file mode 100644
index 0000000..939b975
--- /dev/null
+++ b/src/net.asm
@@ -0,0 +1,41 @@
+; =============================================================================
+; net.asm - raw link-port serial for networking (bypasses the console/terminal).
+;
+; The Game Boy link port is one 8-bit shift register. These two calls move a
+; byte at a time: ssend transmits with the GB as clock master; srecv waits for
+; a byte with the GB as slave (external clock), yielding while it blocks. On top
+; of these, userland runs SLIP framing and talks to a host-side gateway.
+;
+; The LCD terminal + on-screen keyboard mean the console no longer needs the
+; link port, so it is free to be the network.
+; =============================================================================
+INCLUDE "include/gbos.inc"
+
+SECTION "net", ROM0
+
+; sys_ssend(E = byte) - transmit one byte (GB drives the clock).
+sys_ssend::
+ ld a, e
+ ld [rSB], a
+ ld a, $81 ; start transfer, internal clock
+ ld [rSC], a
+.wait
+ ld a, [rSC]
+ bit 7, a
+ jr nz, .wait ; bit7 clears when the byte has shifted out
+ ret
+
+; sys_srecv() -> A = received byte. GB is the slave; blocks (yields) until the
+; peer clocks a byte in.
+sys_srecv::
+.poll
+ ld a, $80 ; start transfer, external clock (receive)
+ ld [rSC], a
+ ld a, [rSC]
+ bit 7, a
+ jr z, .got ; bit7 clear => a byte arrived
+ call SchedYield
+ jr .poll
+.got
+ ld a, [rSB]
+ ret