;********************************************************************** ;* Filename: table.asm ;* Project: EPROM emulator ;* Date: 05 June 2005 ;* Version: 0.1 ;* Author: Philip Pemberton ;* ;* Data table handling code. ;********************************************************************** include "config.inc" ; Device configuration ;********************************************************************** ;** HEADERS ;********************************************************************** ;********************************************************************** ;** CONSTANTS ;********************************************************************** lbank equ 0 ;register bank for the local state of this module lbankadr equ bankadr(lbank) ;address within local state register bank ;********************************************************************** ;** RAM VARIABLES ;********************************************************************** ; Global state. defram gbankadr global table_High, table_Low table_High res 1 ; Table high address table_Low res 1 ; Table low address ; Local state defram lbankadr ;********************************************************************** ;** SUBROUTINES ;********************************************************************** .table CODE ; Code segment ;---------------------------------- ; Subroutine: table_Get ; Inputs: ; W = Offset in table ; table_High = Table high address byte (HIGH table) ; table_Low = Table low address byte (LOW table) ; Outputs: ; W = Data byte from table ; PCLATH set appropriately ; Function: ; Calculates the offset values for a table lookup. Tables can be anywhere ; in program memory. Returns with W=offset, and PCLATH set correctly. ; glbsub table_Get dbankif gbankadr addwf table_Low, F ; 8-bit add operation movf table_High, W ; Get high 5 bits of address skpnc ; Page crossed? addlw D'1' ; Yes, so increment the high byte dbankif PCLATH movwf PCLATH ; Load high address into latch dbankif gbankadr movf table_Low, W ; Load computed offset into W dbankif PCL movwf PCL ; Call the table leave END