#!/bin/sh
# generate jumptab.h from kfunc_tab.s
# kfunc_tab.s is just a list of all provided kernel functions
# the functions are numbered 0,2,4,6,... and are mapped to virtual
# addresses starting at lk_jumptab (currently $0200) those
# virtual addresses get remapped to the proper kernel address by
# the code relocator.
# jumptab.h is generated by processing jumptab.s line by line
#  .word  <function_name>
# becomes
#  #define <function_name> [lk_jumptab + OFFS]
# (OFFS starts with 0 and is incremented by 2 each line)
 
grep "w"ord kfunc_tab.s | cut -d" " -f2 | (
 printf ";// *** DO NOT EDIT THIS FILE ***\n"
 printf ";// `ls -l kfunc_tab.s`\n"
 printf "#ifndef _JUMPTAB_H\n#define _JUMPTAB_H\n#include <system.h>\n"
 OFFS=0; while read MARK; do printf "#define lkf_$MARK [lk_jumptab + $OFFS]\n";
 OFFS=`expr $OFFS + 2`; done
printf "#endif\n" ) > ../include/jumptab.h

grep "w"ord kfunc_tab.s | cut -d" " -f2 | (
 printf ";// *** DO NOT EDIT THIS FILE ***\n"
 printf ";// this is include file for ca65 with .o65 lunix target\n"
 printf ";// use it only with current kernel - make LNG first to regenerate this file\n"
 printf ";// `ls -l kfunc_tab.s`\n\n"
 printf ".import LUNIXKERNEL\n\n"
 printf "lkf_jumptab = LUNIXKERNEL\n"
 OFFS=0; while read MARK; do printf "lkf_$MARK = lkf_jumptab + $OFFS\n";
 OFFS=`expr $OFFS + 2`; done
 ) > ../include/jumptab.ca65.h
