Subversion Repositories Spectranet

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

Show entire file | Details | Blame | View Log

Rev 371 Rev 384
Line 18... Line 18...
;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        "sockdefs.inc"
 
.include        "sysvars.inc"
 
.include        "sysdefs.inc"
 
.include        "w5100_defs.inc"
 
 
;
;
; Sockinfo.asm: Routines to get information about a socket, analagous
; Sockinfo.asm0: Routines to get information about a socket, analagous
; to filling a struct sockaddr_t in C.
; to filling a struct sockaddr_t in C.
;
;
; The data structure that is returned looks like this:
; The data structure that is returned looks like this:
;
;
; remote IP   - 32 bits
; remote IP   - 32 bits
Line 36... Line 41...
; Returns information about a hardware socket. It's assumed that the W5100
; Returns information about a hardware socket. It's assumed that the W5100
; register area is paged in.
; register area is paged in.
;
;
; Parameters:  H = High order of socket hardware register address
; Parameters:  H = High order of socket hardware register address
;             DE = Address of the buffer to fill.
;             DE = Address of the buffer to fill.
F_sockinfo
.globl F_sockinfo
 
F_sockinfo:
        call F_checkpageA
        call F_checkpageA
        ld l, Sn_DIPR0 % 256    ; remote IP address register
        ld l, Sn_DIPR0 % 256    ; remote IP address register
        ldi
        ldi
        ldi
        ldi
        ldi
        ldi
Line 70... Line 76...
; F_setsockinfo:
; F_setsockinfo:
; Sets socket information from structure described above.
; Sets socket information from structure described above.
;
;
; Parameters:  H = MSB of W5100 socket register area
; Parameters:  H = MSB of W5100 socket register area
;             DE = address of the 8 byte socket info structure.
;             DE = address of the 8 byte socket info structure.
F_setsockinfo
.globl F_setsockinfo
 
F_setsockinfo:
        call F_checkpageA
        call F_checkpageA
        ex de, hl
        ex de, hl
        ld e, Sn_DIPR0 % 256    ; destination IP address
        ld e, Sn_DIPR0 % 256    ; destination IP address
        ldi
        ldi
        ldi
        ldi
Line 92... Line 99...
        ; only set source port if source port is set.
        ; only set source port if source port is set.
        ld a, (hl)
        ld a, (hl)
        inc hl
        inc hl
        or (hl)
        or (hl)
        ex de, hl               ; restore registers to expected order
        ex de, hl               ; restore registers to expected order
        jr z, .checkset         ; need to set random source port?
        jr z, .checkset2                ; need to set random source port?
        ld l, Sn_PORT0 % 256    ; hl points at source port
        ld l, Sn_PORT0 % 256    ; hl points at source port
        ld a, (de)              ; source port MSB
        ld a, (de)              ; source port MSB
        ld (hl), a              ; set MSB
        ld (hl), a              ; set MSB
        inc l
        inc l
        dec de
        dec de
        ld a, (de)
        ld a, (de)
        ld (hl), a              ; set LSB
        ld (hl), a              ; set LSB
        jr .leave
        jr .leave2
.checkset
.checkset2:
        ld l, Sn_PORT0 % 256    ; port MSB
        ld l, Sn_PORT0 % 256    ; port MSB
        ld a, (hl)
        ld a, (hl)
        inc l                   ; port LSB
        inc l                   ; port LSB
        or (hl)                 ; is it zero?
        or (hl)                 ; is it zero?
        jr nz, .leave           ; no - nothing to do
        jr nz, .leave2          ; no - nothing to do
        ex de, hl               ; yes - set the local port
        ex de, hl               ; yes - set the local port
        ld hl, v_localport
        ld hl, v_localport
        ld e, Sn_PORT1 % 256    ; set local port LSB
        ld e, Sn_PORT1 % 256    ; set local port LSB
        ldi
        ldi
        ld e, Sn_PORT0 % 256    ; set local port MSB
        ld e, Sn_PORT0 % 256    ; set local port MSB
        ldi
        ldi
        ld hl, (v_localport)    ; update the local port number
        ld hl, (v_localport)    ; update the local port number
        inc hl
        inc hl
        ld (v_localport), hl
        ld (v_localport), hl
        ex de, hl
        ex de, hl
.leave
.leave2:
        ld a, (v_buf_pgb)
        ld a, (v_buf_pgb)
        and a
        and a
        jp nz, F_setpageB
        jp nz, F_setpageB
        ret
        ret
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_fillsockaddr
; F_fillsockaddr
; Fills a struct sockaddr_in with the remote socket info
; Fills a struct sockaddr_in with the remote socket info
; Parameters: Socket in A
; Parameters: Socket in A
;             Pointer to sockaddr_in in DE
;             Pointer to sockaddr_in in DE
F_remoteaddress
.globl F_remoteaddress
 
F_remoteaddress:
        call F_gethwsock
        call F_gethwsock
        jp c, J_leavesockfn     ; invalid socket
        jp c, J_leavesockfn     ; invalid socket
 
 
        call F_checkpageA
        call F_checkpageA
        inc de                  ; increment past int sin_family
        inc de                  ; increment past int sin_family