; eeprom.asm
;
; Copyright (C) 2006,2007 Nuno Sucena Almeida
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
;

; routines to access the microcontroller internal eeprom

	include	<proc.inc>

	udata

;--------------------------------------------------------------------
; external functions
	extern	uart_send

	code
; -------------------------------------------------------------------
; reads a 0 terminated string from the eeprom location provided by 'W'
; and sends it to the uart.
; see page 29 of 16F88 manual for details
uart_send_ee_string:
        banksel EEADR
        movwf   EEADR           ; set the initial EEPROM address to 'W'
uart_send_ee_string_loop:
	banksel	EECON1
	bcf	EECON1,EEPGD	; point to data memory
        bsf     EECON1,RD       ; initiate read cycle
	banksel	EEDATA
        movf    EEDATA,W        ; move data to W
        addlw   0               ; dummy instruction so that we
				; can get the STATUS register...
        btfsc   STATUS,Z        ; check if the previous result is not 0
                                ; sec 4.2.2.1 (page 22 of the manual).
        goto    uart_send_ee_string_end
        call    uart_send
        banksel EEADR
        incf    EEADR,F         ; increment EEPROM address
        goto    uart_send_ee_string_loop
uart_send_ee_string_end:
        return


; -------------------------------------------------------------------
; WARNING: the current bootloader DOES NOT update the microcontroller
; EEPROM data!
        org     0x2100
	;; clear screen, put it in reverse and at the end put no attributes
ee_ct1fox		de	"\033[2J\033[7m(c) 2006 Nuno Sucena Almeida - CT1FOX\033[0m\n\r",0
ee_prompt_ready		de	"Ready>",0
ee_prompt_config	de	"Config>",0
ee_prompt_eeprom	de	"EEPROM>",0
ee_prompt_i2c		de	"I2C>",0
ee_prompt_bootloader	de	"Boot Loader>",0
ee_OK			de	"OK",0
ee_ERROR		de	"Error",0
	;; VT100 control codes
ee_screen_clear		de	"\033[2J",0
ee_char_attr_off	de	"\033[0m",0
ee_char_bold		de	"\033[1m",0
ee_char_blink		de	"\033[5m",0
ee_char_reverse		de	"\033[7m",0

	global	uart_send_ee_string

	global	ee_ct1fox
	global	ee_prompt_ready
	global	ee_prompt_config
	global	ee_prompt_eeprom
	global	ee_prompt_i2c
	global	ee_prompt_bootloader
	global	ee_OK

	end