Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [w5100_sockctrl.asm] - Diff between revs 371 and 384

Show entire file | Details | Blame | View Log

Rev 371 Rev 384
Line 17... Line 17...
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;THE SOFTWARE.
;THE SOFTWARE.
 
.include        "w5100_defs.inc"
 
.include        "sysvars.inc"
 
.include        "sockdefs.inc"
 
 
; Socket control routines. In this file:
; Socket control routines. In this file:
; F_bind
; F_bind
; F_connect
; F_connect
;
;
Line 52... Line 54...
; (the local port to listen on).
; (the local port to listen on).
;
;
; Parameters: A  = socket fd
; Parameters: A  = socket fd
;             DE = port
;             DE = port
; On error, carry flag is set and A contains error number.
; On error, carry flag is set and A contains error number.
F_bind
.text
 
.globl F_bind
 
F_bind:
        call F_gethwsock        ; H now is hardware socket MSB address
        call F_gethwsock        ; H now is hardware socket MSB address
        jp c, J_leavesockfn     ; carry is set on error
        jp c, J_leavesockfn     ; carry is set on error
        ld l, Sn_PORT0 % 256    ; port register
        ld l, Sn_PORT0 % 256    ; port register
        ld (hl), d              ; set port MSB
        ld (hl), d              ; set port MSB
        inc l
        inc l
Line 68... Line 72...
; Tell a socket to listen for incoming connections.
; Tell a socket to listen for incoming connections.
;
;
; Parameters: A  = socket fd
; Parameters: A  = socket fd
;
;
; On error, the carry flag is set and A contains the error number.
; On error, the carry flag is set and A contains the error number.
F_listen
.globl F_listen
 
F_listen:
        call F_gethwsock        ; H is now hardware socket MSB address
        call F_gethwsock        ; H is now hardware socket MSB address
        jp c, J_leavesockfn     ; unless carry is set because of an error
        jp c, J_leavesockfn     ; unless carry is set because of an error
 
 
        ld l, Sn_CR % 256       ; hl points at hardware socket's command reg
        ld l, Sn_CR % 256       ; hl points at hardware socket's command reg
        ld (hl), S_CR_LISTEN    ; tell the socket to listen
        ld (hl), S_CR_LISTEN    ; tell the socket to listen
Line 91... Line 96...
; Parameters: A = socket fd
; Parameters: A = socket fd
;            DE = pointer to 4 byte buffer containing destination IP
;            DE = pointer to 4 byte buffer containing destination IP
;            BC = port number
;            BC = port number
; On error, the carry flag is set and A contains the error number.
; On error, the carry flag is set and A contains the error number.
; On success, returns zero in A
; On success, returns zero in A
F_connect
.globl F_connect
 
F_connect:
        call F_gethwsock        ; H = socket register bank MSB
        call F_gethwsock        ; H = socket register bank MSB
        ld l, Sn_DPORT0 % 256   ; destination port register
        ld l, Sn_DPORT0 % 256   ; destination port register
        ld (hl), b              ; high order of port
        ld (hl), b              ; high order of port
        inc l
        inc l
        ld (hl), c              ; low order of port
        ld (hl), c              ; low order of port
Line 117... Line 123...
        ex de, hl
        ex de, hl
        ld l, Sn_CR % 256       ; command register
        ld l, Sn_CR % 256       ; command register
        ld (hl), S_CR_CONNECT   ; instruction to connect to remote host
        ld (hl), S_CR_CONNECT   ; instruction to connect to remote host
 
 
        ld l, Sn_IR % 256       ; interrupt register
        ld l, Sn_IR % 256       ; interrupt register
.waitforconn
.waitforconn3:
        ld a, (hl)
        ld a, (hl)
        bit BIT_IR_CON, a
        bit BIT_IR_CON, a
        jr nz, .connected
        jr nz, .connected3
        and a                   ; if not, is it zero (no flags set?)
        and a                   ; if not, is it zero (no flags set?)
        jr z, .waitforconn
        jr z, .waitforconn3
        and S_IR_DISCON         ; connection refused?
        and S_IR_DISCON         ; connection refused?
        jr nz, .refused
        jr nz, .refused3
        ld a, ETIMEDOUT         ; connection timed out
        ld a, ETIMEDOUT         ; connection timed out
        scf
        scf
        jp J_leavesockfn
        jp J_leavesockfn
.refused
.refused3:
        ld a, ECONNREFUSED
        ld a, ECONNREFUSED
        scf
        scf
        jp J_leavesockfn
        jp J_leavesockfn
.connected
.connected3:
        set BIT_IR_CON, (hl)    ; reset interrupt bit
        set BIT_IR_CON, (hl)    ; reset interrupt bit
        xor a                   ; connection OK
        xor a                   ; connection OK
        jp J_leavesockfn
        jp J_leavesockfn