Up one Vic 20 network - software by Lee Davison Up to top

Main program loop

This is the main program loop that spends most of the time waiting for something to happen. If an interrupt is flagged then that is processed, if that results in a valid packet being received then that packet is now processed.

After this the interrupt flag byte is checked again and if there are still flagged interrupts pending then the service code is re-entered at the start. If not then all interrupt status bits are cleared and the background tasks are serviced.

This would probably work better as a mini task scheduler but that is moving into the realm of OS creation. For now it stays like this.


; *********************************************************************		
; main program loop

LAB_200
	LDA	IB			; get interrupt flag byte
	BEQ	LAB_990			; branch if no interrupt flagged

LAB_210
	AND	#$02			; mask adapter fail interrupt
	BEQ	LAB_220			; branch if not adapter fail

	JSR	LAB_20300		; else do adapter fail interrupt
LAB_220
	LDA	IB			; get interrupt flag byte
	AND	#$04			; mask Tx interrupt
	BEQ	LAB_225			; branch if no Tx interrupt

	JSR	LAB_20200		; else do tx interrupt
LAB_225
	LDA	IB			; get interrupt flag byte
	AND	#$10			; mask Rx interrupt
	BEQ	LAB_300			; branch if no Rx interrupt

	JSR	LAB_20100		; else do rx interrupt
LAB_300
	LDA	valid_pkt		; get valid packet flag
	BEQ	LAB_985			; skip check if no valid packet

					; now decipher packet info
	LDA	pk_buff+ET_type_h	; get type byte
	CMP	#$08			; compare with $08
	BNE	LAB_980			; branch if not recognised

	LDA	pk_buff+ET_type_l	; get type byte
	BNE	LAB_315			; branch if not IP

	JSR	LAB_21500		; handle known IP packet type
	JMP	LAB_980			; go clear packet & loop

LAB_315
	CMP	#$06			; compare with $06
	BNE	LAB_980			; branch if not recognised

	JSR	LAB_21000		; else handle ARP packet
LAB_980
	LDA	#$00			; clear A
	STA	valid_pkt		; clear valid packet

LAB_985
	LDA	IB			; get interrupt flag byte
	AND	#$FE			; mask only needed bits
	BNE	LAB_210			; loop while interrupts to service

	LDX	#$FF			; bit 0 interrupt latch
	LDA	#$68			; acknowledge interrupt command
	STX	com_reg_l		;
	STA	com_reg_h		; ack the interrupt(s)

LAB_990					; do background tasks
	JSR	print_tcp		; print TCP state
	JSR	periodic		; go check periodic timeout(s)
	INC	prng			; increment PRNG seed byte
	JMP	LAB_200			; loop forever

; *********************************************************************


Last page update: 29th February, 2004. e-mail me e-mail