Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [w5100_ifconfig.asm] - Blame information for rev 384

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 93 winston
;The MIT License
2
;
3
;Copyright (c) 2008 Dylan Smith
4
;
5
;Permission is hereby granted, free of charge, to any person obtaining a copy
6
;of this software and associated documentation files (the "Software"), to deal
7
;in the Software without restriction, including without limitation the rights
8
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
;copies of the Software, and to permit persons to whom the Software is
10
;furnished to do so, subject to the following conditions:
11
;
12
;The above copyright notice and this permission notice shall be included in
13
;all copies or substantial portions of the Software.
14
;
15
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
;THE SOFTWARE.
22
;
23
; Interface configuration functions - to abstract the W5100 away from
24
; software that needs to configure the interface.
25
;
26 384 winston
.include        "w5100_defs.inc"
27
.include        "sysvars.inc"
28 93 winston
 
29
;-------------------------------------------------------------------------
30
; F_ifconfig_ routines: F_ifconfig_inet, F_ifconfig_gw, F_ifconfig_netmask
31
; Configures the basic settings needed for the W5100.
32
; Parameters: HL - pointer to the 4 byte block of memory with the IPv4
33
; info.
34
; DE is incremented by 4.
35 384 winston
.text
36
.globl F_ifconfig_gw
37
F_ifconfig_gw:
38 93 winston
        call F_regpage
39
        ld de, GAR0     ; gateway address register
40 316 winston
        jr J_copy_cfg
41 93 winston
 
42 384 winston
.globl F_ifconfig_inet
43
F_ifconfig_inet:
44 93 winston
        call F_regpage
45
        ld de, SIPR0
46 316 winston
        jr J_copy_cfg
47 93 winston
 
48 384 winston
.globl F_ifconfig_netmask
49
F_ifconfig_netmask:
50 93 winston
        call F_regpage
51
        ld de, SUBR0
52 316 winston
        jr J_copy_cfg
53
 
54 384 winston
J_copy_cfg:
55 307 winston
        ld bc, 4
56
        ldir
57 142 winston
        jp J_leavesockfn
58 114 winston
 
59
;-------------------------------------------------------------------------
60
; F_get_ifconfig routines: F_get_ifconfig_inet, gw, netmask:
61
; Returns the inet settings into a 4-byte buffer pointed to by DE
62
; in big-endian format.
63 384 winston
.globl F_get_ifconfig_gw
64
F_get_ifconfig_gw:
65 114 winston
        call F_regpage
66
        ld hl, GAR0
67 316 winston
        jr J_copy_cfg
68 114 winston
 
69 384 winston
.globl F_get_ifconfig_inet
70
F_get_ifconfig_inet:
71 114 winston
        call F_regpage
72
        ld hl, SIPR0
73 316 winston
        jr J_copy_cfg
74 114 winston
 
75 384 winston
.globl F_get_ifconfig_netmask
76
F_get_ifconfig_netmask:
77 114 winston
        call F_regpage
78
        ld hl, SUBR0
79 316 winston
        jr J_copy_cfg
80 93 winston
 
81 384 winston
.globl F_regpage
82
F_regpage:
83 142 winston
        ld a, (v_pga)           ; copy original page A value
84
        ld (v_buf_pga), a
85 110 winston
        ld a, REGPAGE
86 93 winston
        call F_setpageA
87
        ret
88
 
89
;-------------------------------------------------------------------------
90
; F_sethwaddr
91
; Configures the W5100 hardware (MAC) address.
92
; Parameters: HL - pointer to a 6 byte buffer containing the hardware addr.
93
; Returns with carry set if the readback fails to give the same result.
94 384 winston
.globl F_sethwaddr
95
F_sethwaddr:
96 93 winston
        call F_regpage
97
        push hl         ; preserve buffer pointer
98
        ld de, SHAR0    ; hardware address register
99
        ld bc, 6        ; is 6 bytes long
100
        ldir
101
 
102
        pop hl
103
        ld de, SHAR0    ; readback
104
        ld bc, 6        ; check 6 bytes
105 384 winston
.readback8:
106 93 winston
        ld a, (de)
107
        cpi
108 384 winston
        jr nz, .readbackerr8
109 93 winston
        inc de
110 384 winston
        jp pe, .readback8 ; keep going till BC=0
111 93 winston
        or 0            ; ensure carry is cleared
112 142 winston
        jp J_leavesockfn
113 384 winston
.readbackerr8:
114 93 winston
        scf
115 142 winston
        jp J_leavesockfn
116 93 winston
 
117
;---------------------------------------------------------------------------
118
; F_gethwaddr
119
; Read the hardware address and fill a 6 byte buffer.
120
; Parameters: DE = pointer to buffer to fill.
121 384 winston
.globl F_gethwaddr
122
F_gethwaddr:
123 142 winston
        call F_regpage
124 93 winston
        ld hl, SHAR0
125
        ld bc, 6
126
        ldir
127 142 winston
        jp J_leavesockfn
128 93 winston
 
129
;---------------------------------------------------------------------------
130
; F_deconfig
131
; Deconfigure the interface (reset the inet, gateway and netmask fields).
132
; Parameters: None.
133 384 winston
.globl F_deconfig
134
F_deconfig:
135 142 winston
        call F_regpage
136 93 winston
        ld hl, GAR0
137
        ld de, GAR1
138
        ld bc, 7
139
        ld (hl), 0
140
        ldir
141
        ld hl, GAR0
142
        ld de, SIPR0
143 307 winston
        ld bc, 4
144
        ldir
145 142 winston
        jp J_leavesockfn
146 93 winston