diff options
| author | user <user@clank> | 2026-07-17 01:28:23 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-07-17 01:28:23 +0200 |
| commit | b5544e84232b80351e7c58501c1632080a354d12 (patch) | |
| tree | a4087d5c9df0589b613bcb6696962825099ce8b7 /src | |
| parent | pipe: PIPE_MAX 2->4 (5-stage pipelines) + fix cross-yield byte corruption (diff) | |
| download | gbos-b5544e84232b80351e7c58501c1632080a354d12.tar.gz gbos-b5544e84232b80351e7c58501c1632080a354d12.tar.xz gbos-b5544e84232b80351e7c58501c1632080a354d12.zip | |
net: SLIP framing over the link port + a host gateway (echo round-trip)
First step of link-port networking. The LCD terminal + OSK freed the serial
port from console duty, so it can be the network link.
Kernel (src/net.asm): raw link-port serial that bypasses the console/
terminal - sys_ssend (transmit, GB drives the clock) and sys_srecv (receive,
GB slave, blocks by yielding). Syscalls 29/30.
Userland: libc ssend()/srecv(); c/necho.c does SLIP (RFC 1055) framing over
them - send a packet, receive the reply, print it.
Host: tools/gateway.py wraps the emulator, owns its link serial, speaks SLIP,
and (for now) echoes every frame back - the "link cable adapter". Console
(ASCII) bytes on the same channel are printed for visibility.
Verified: `necho` sends a SLIP frame, the gateway decodes+echoes it, and gbos
prints the reply - a real framed round-trip over the Game Boy link port.
Next: swap the echo for actual network ops (DNS/HTTP or IRC/chat).
Diffstat (limited to '')
| -rw-r--r-- | src/net.asm | 41 | ||||
| -rw-r--r-- | src/programs.asm | 7 | ||||
| -rw-r--r-- | src/syscall.asm | 2 |
3 files changed, 50 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 diff --git a/src/programs.asm b/src/programs.asm index e659cee..a0bef96 100644 --- a/src/programs.asm +++ b/src/programs.asm @@ -109,6 +109,9 @@ ProgCount: SECTION "prog_ptest", ROMX[$4000], BANK[24] ProgPtest: INCBIN "c/ptest.bin" +SECTION "prog_necho", ROMX[$4000], BANK[25] +ProgNecho: + INCBIN "c/necho.bin" ; ----------------------------------------------------------------------------- ; PROG_SH (bank 3) - the shell, now written in C (c/sh.c): parses >/</| and @@ -197,6 +200,8 @@ ProgramTable:: dw ProgCount db LOW(BANK(ProgPtest)), HIGH(BANK(ProgPtest)) dw ProgPtest + db LOW(BANK(ProgNecho)), HIGH(BANK(ProgNecho)) + dw ProgNecho ; ----------------------------------------------------------------------------- ; NameTable (ROM0) - command name -> program id, searched by sys_lookup. @@ -249,4 +254,6 @@ NameTable:: db PROG_COUNT db "ptest", 0 db PROG_PTEST + db "necho", 0 + db PROG_NECHO db 0 diff --git a/src/syscall.asm b/src/syscall.asm index c602097..cb16bbe 100644 --- a/src/syscall.asm +++ b/src/syscall.asm @@ -63,6 +63,8 @@ SyscallTable: dw sys_chdir ; 26 CHDIR dw sys_opendir ; 27 OPENDIR dw sys_pipe ; 28 PIPE + dw sys_ssend ; 29 SSEND + dw sys_srecv ; 30 SRECV ; ----------------------------------------------------------------------------- sys_nosys: |
