; ----------------------------------------------------------------------------- ; interrupt ; ----------------------------------------------------------------------------- .int_received - repeat -- get data - until EOF or Length > 1518 <-- ethernet type II frame - until EOF or Length > 1526 <-- complete ethernet frame - if length > 1518 then discard LDA &F4 PHA LDA #&00 \ change this STA &F4 STA &FE30 PHX JSR ethernet_frame_received PLX PLA STA &F4 STA &FE30 PLA RTI ; ----------------------------------------------------------------------------- ; Ethernet frame received ; ----------------------------------------------------------------------------- .ethernet_frame_received JSR calc_ethernet_crc \ calculate frame crc LDX #&03 \ crc size is 4 bytes .crc_check_loop LDA calced_crc,X \ check if calculated crc is same as frame crc CMP data+1514,X BNE exit DEX BPL crc_check_loop \ check if frame is for us LDX #&05 \ mac address is 6 bytes .mac_check_loop LDA my_mac_addr,X CMP data,X BNE check_frame_broadcast DEX BPL mac_check_loop BMI frame_is_for_us \ it's our mac address, so jump for further processing .check_frame_broadcast \ check if frame is broadcast LDA data+&6 AND data+&07 AND data+&08 AND data+&09 AND data+&0A AND data+&0B INC A BNE exit .frame_is_for_us LDA data+&0C CMP #&08 \ check if ethertype msb is 08xx BNE exit LDA data+&0D BNE frame_is_for_us1 \ is ethertype 0800 (IP) JMP ip_received \ yes, jump to ip packet received .frame_is_for_us1 CMP #&06 \ is ethertype 0806 (ARP) BNE frame_is_for_us2 JMP arp_received \ yes, jump to arp packet received frame_is_for_us2 CMP #&35 \is ethertype 0835 (RARP) BNE exit JMP rarp_received .exit RTS ; ----------------------------------------------------------------------------- ; IP packet received ; ----------------------------------------------------------------------------- .ip_received \\\\\offset = 0x000E LDA data AND #&F0 \ mask out version bits CMP #4 \ is it version 4? BNE exit \ no, then exit JSR calc_ip_crc \ calculate packet crc LDA calced_crc CMP data+&000A \ check crc lsb BNE exit LDA calced_crc+1 CMP data+&000B \ check crc msb BNE exit \ check for our ip address LDX #&03 \ ip address size is 4 bytes .ip_address_check_loop LDA data+&000C,X \ check if ip address is our ip address CMP my_ip_address,X BNE check_ip_broadcast DEX BPL ip_address_check_loop \ check for ip broadcast LDA data+&000C,X AND data+&000D,X AND data+&000E,X AND data+&000F,X INC A BNE exit LDA data+&0009 \ check ip protocol number CMP #&01 \ is it ICMP? BEQ icmp_received \ yes, then jump CMP #&06 \ is it TCP? BEQ tcp_received \ yes, then jump CMP #&17 \ is it UDP? BEQ udp_received \ yes, then jump