- Optimized LAN91C96 driver for speed and size.
- Speed: The primary byte copy loops are reduzed to the bare minimum by adjusting the base pointer 'ptr' and loop register 'y' in such a way that the 'y' overflow matches the low byte of the loop size. - Introduced a loop for setting the MAC address. Additional minor fix: - Properly start self modification with first location.
This commit is contained in:
parent
ea08635ca4
commit
2263c1aa55
1 changed files with 70 additions and 73 deletions
|
@ -78,8 +78,7 @@ fixup: .byte fixup02-fixup01, fixup03-fixup02, fixup04-fixup03
|
|||
.byte fixup29-fixup28, fixup30-fixup29, fixup31-fixup30
|
||||
.byte fixup32-fixup31, fixup33-fixup32, fixup34-fixup33
|
||||
.byte fixup35-fixup34, fixup36-fixup35, fixup37-fixup36
|
||||
.byte fixup38-fixup37, fixup39-fixup38, fixup40-fixup39
|
||||
.byte fixup41-fixup40, fixup42-fixup41
|
||||
.byte fixup38-fixup37
|
||||
|
||||
fixups = * - fixup
|
||||
|
||||
|
@ -160,14 +159,14 @@ init:
|
|||
|
||||
; Reset ETH card
|
||||
: lda #$00 ; Bank 0
|
||||
fixup00:sta ethbsr
|
||||
fixup01:sta ethbsr
|
||||
|
||||
lda #%10000000 ; Software reset
|
||||
fixup01:sta ethrcr+1
|
||||
fixup02:sta ethrcr+1
|
||||
|
||||
ldy #$00
|
||||
fixup02:sty ethrcr
|
||||
fixup03:sty ethrcr+1
|
||||
fixup03:sty ethrcr
|
||||
fixup04:sty ethrcr+1
|
||||
|
||||
; Delay
|
||||
: cmp ($FF,x) ; 6 cycles
|
||||
|
@ -179,45 +178,39 @@ fixup03:sty ethrcr+1
|
|||
; Enable transmit and receive
|
||||
lda #%10000001 ; Enable transmit TXENA, PAD_EN
|
||||
ldx #%00000011 ; Enable receive, strip CRC ???
|
||||
fixup04:sta ethtcr
|
||||
fixup05:stx ethrcr+1
|
||||
fixup05:sta ethtcr
|
||||
fixup06:stx ethrcr+1
|
||||
|
||||
lda #$01 ; Bank 1
|
||||
fixup06:sta ethbsr
|
||||
fixup07:sta ethbsr
|
||||
|
||||
fixup07:lda ethcr+1
|
||||
fixup08:lda ethcr+1
|
||||
ora #%00010000 ; No wait (IOCHRDY)
|
||||
fixup08:sta ethcr+1
|
||||
fixup09:sta ethcr+1
|
||||
|
||||
lda #%00001001 ; Auto release
|
||||
fixup09:sta ethctr+1
|
||||
fixup10:sta ethctr+1
|
||||
|
||||
; Set MAC address
|
||||
lda mac
|
||||
ldx mac+1
|
||||
fixup10:sta ethiar
|
||||
fixup11:stx ethiar+1
|
||||
lda mac+2
|
||||
ldx mac+3
|
||||
fixup12:sta ethiar+2
|
||||
fixup13:stx ethiar+3
|
||||
lda mac+4
|
||||
ldx mac+5
|
||||
fixup14:sta ethiar+4
|
||||
fixup15:stx ethiar+5
|
||||
ldy #$00
|
||||
: lda mac,y
|
||||
fixup11:sta ethiar,y
|
||||
iny
|
||||
cpy #$06
|
||||
bcc :-
|
||||
|
||||
; Set interrupt mask
|
||||
lda #$02 ; Bank 2
|
||||
fixup16:sta ethbsr
|
||||
fixup12:sta ethbsr
|
||||
|
||||
lda #%00000000 ; No interrupts
|
||||
fixup17:sta ethmsk
|
||||
fixup13:sta ethmsk
|
||||
rts
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
poll:
|
||||
fixup18:lda ethist
|
||||
fixup14:lda ethist
|
||||
and #%00000001 ; RCV INT
|
||||
bne :+
|
||||
|
||||
|
@ -230,12 +223,12 @@ fixup18:lda ethist
|
|||
|
||||
: lda #$00
|
||||
ldx #%11100000 ; RCV, AUTO INCR., READ
|
||||
fixup19:sta ethptr
|
||||
fixup20:stx ethptr+1
|
||||
fixup15:sta ethptr
|
||||
fixup16:stx ethptr+1
|
||||
|
||||
; Last word contains 'last data byte' and $60 or 'fill byte' and $40
|
||||
fixup21:lda ethdata ; Status word
|
||||
fixup22:lda ethdata ; Need high byte only
|
||||
fixup17:lda ethdata ; Status word
|
||||
fixup18:lda ethdata ; Need high byte only
|
||||
|
||||
; Move ODDFRM bit into carry:
|
||||
; - Even packet length -> carry clear -> subtract 6 bytes
|
||||
|
@ -247,10 +240,10 @@ fixup22:lda ethdata ; Need high byte only
|
|||
lsr
|
||||
|
||||
; The packet contains 3 extra words
|
||||
fixup23:lda ethdata ; Total number of bytes
|
||||
fixup19:lda ethdata ; Total number of bytes
|
||||
sbc #$05 ; Actually 5 or 6 depending on carry
|
||||
sta len
|
||||
fixup24:lda ethdata
|
||||
fixup20:lda ethdata
|
||||
sbc #$00
|
||||
sta len+1
|
||||
|
||||
|
@ -265,7 +258,7 @@ fixup24:lda ethdata
|
|||
; Yes, skip packet
|
||||
; Remove and release RX packet from the FIFO
|
||||
lda #%10000000
|
||||
fixup25:sta ethmmucr
|
||||
fixup21:sta ethmmucr
|
||||
|
||||
; No packet available
|
||||
lda #$00
|
||||
|
@ -273,26 +266,19 @@ fixup25:sta ethmmucr
|
|||
rts
|
||||
|
||||
; Read bytes into buffer
|
||||
: lda bufaddr
|
||||
ldx bufaddr+1
|
||||
sta ptr
|
||||
stx ptr+1
|
||||
ldx len+1
|
||||
ldy #$00
|
||||
read:
|
||||
fixup26:lda ethdata
|
||||
: jsr adjustptr
|
||||
:
|
||||
fixup22:lda ethdata
|
||||
sta (ptr),y
|
||||
iny
|
||||
bne :+
|
||||
bne :-
|
||||
inc ptr+1
|
||||
: cpy len
|
||||
bne read
|
||||
dex
|
||||
bpl read
|
||||
bpl :-
|
||||
|
||||
; Remove and release RX packet from the FIFO
|
||||
lda #%10000000
|
||||
fixup27:sta ethmmucr
|
||||
fixup23:sta ethmmucr
|
||||
|
||||
; Return packet length
|
||||
lda len
|
||||
|
@ -309,14 +295,14 @@ send:
|
|||
; Allocate memory for TX
|
||||
txa
|
||||
ora #%00100000
|
||||
fixup28:sta ethmmucr
|
||||
fixup24:sta ethmmucr
|
||||
|
||||
; 8 retries
|
||||
ldy #$08
|
||||
|
||||
; Wait for allocation ready
|
||||
:
|
||||
fixup29:lda ethist
|
||||
fixup25:lda ethist
|
||||
and #%00001000 ; ALLOC INT
|
||||
bne :+
|
||||
|
||||
|
@ -330,21 +316,21 @@ fixup29:lda ethist
|
|||
|
||||
; Acknowledge interrupt, is it necessary ???
|
||||
: lda #%00001000
|
||||
fixup30:sta ethack
|
||||
fixup26:sta ethack
|
||||
|
||||
; Set packet address
|
||||
fixup31:lda etharr
|
||||
fixup32:sta ethpnr
|
||||
fixup27:lda etharr
|
||||
fixup28:sta ethpnr
|
||||
|
||||
lda #$00
|
||||
ldx #%01000000 ; AUTO INCR.
|
||||
fixup33:sta ethptr
|
||||
fixup34:stx ethptr+1
|
||||
fixup29:sta ethptr
|
||||
fixup30:stx ethptr+1
|
||||
|
||||
; Status written by CSMA
|
||||
lda #$00
|
||||
fixup35:sta ethdata
|
||||
fixup36:sta ethdata
|
||||
fixup31:sta ethdata
|
||||
fixup32:sta ethdata
|
||||
|
||||
; Check packet length parity:
|
||||
; - Even packet length -> carry set -> add 6 bytes
|
||||
|
@ -356,30 +342,23 @@ fixup36:sta ethdata
|
|||
; The packet contains 3 extra words
|
||||
lda len
|
||||
adc #$05 ; Actually 5 or 6 depending on carry
|
||||
fixup37:sta ethdata
|
||||
fixup33:sta ethdata
|
||||
lda len+1
|
||||
adc #$00
|
||||
fixup38:sta ethdata
|
||||
fixup34:sta ethdata
|
||||
|
||||
; Send the packet
|
||||
; ---------------
|
||||
|
||||
; Write bytes from buffer
|
||||
lda bufaddr
|
||||
ldx bufaddr+1
|
||||
sta ptr
|
||||
stx ptr+1
|
||||
ldx len+1
|
||||
ldy #$00
|
||||
write: lda (ptr),y
|
||||
fixup39:sta ethdata
|
||||
jsr adjustptr
|
||||
: lda (ptr),y
|
||||
fixup35:sta ethdata
|
||||
iny
|
||||
bne :+
|
||||
bne :-
|
||||
inc ptr+1
|
||||
: cpy len
|
||||
bne write
|
||||
dex
|
||||
bpl write
|
||||
bpl :-
|
||||
|
||||
; Odd packet length ?
|
||||
lda len
|
||||
|
@ -392,13 +371,13 @@ fixup39:sta ethdata
|
|||
|
||||
; No
|
||||
: lda #$00
|
||||
fixup40:sta ethdata ; Fill byte
|
||||
fixup36:sta ethdata ; Fill byte
|
||||
:
|
||||
fixup41:sta ethdata ; Control byte
|
||||
fixup37:sta ethdata ; Control byte
|
||||
|
||||
; Add packet to FIFO
|
||||
lda #%11000000 ; ENQUEUE PACKET - transmit packet
|
||||
fixup42:sta ethmmucr
|
||||
fixup38:sta ethmmucr
|
||||
rts
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
|
@ -407,3 +386,21 @@ exit:
|
|||
rts
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
|
||||
adjustptr:
|
||||
lda len
|
||||
eor #$FF ; Two's complement part 1
|
||||
tay
|
||||
iny ; Two's complement part 2
|
||||
sty reg
|
||||
sec
|
||||
lda bufaddr
|
||||
sbc reg
|
||||
sta ptr
|
||||
lda bufaddr+1
|
||||
sbc #$00
|
||||
sta ptr+1
|
||||
ldx len+1
|
||||
rts
|
||||
|
||||
;---------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue