# @(#) xlate.awk - disassemble and pretty print hp-29c code and perhaps others # @(#) $Id: xlate.awk,v 1.1 2000/04/22 18:44:34 bduncan Exp bduncan $ # # Author: Bill Duncan, bduncan@beachnet.org # # Description: # - simple, quick and dirty translator to help document and store programs # for antique HP calculators (like my hp-29c) # - uses a simple-minded symbol table, so theoretically we can change this # to translate for other calculators like the hp-34c, hp-15c etc. # - recognises f, g and h shift keys (ala hp-34c) # - uses two associative arrays for symbol table, one for shifted keys # and one for everything else (including register suffixes etc.) # # Files: # - all files use the unix convention of blank lines being ignored, # comments being preceded with an octothorpe (hash mark "#") and fields # are separated with one or more white space characters (tabs or spaces) # - symbol table file has key two forms of data lines: # (1) unshifted keys have 2 digit key code and mnemonic (2 fields) # (2) shifted keys are preceded with "f", "g" or "h" (3 fields) # # BEGIN { SYMBOLS = "29c.sym" LISTING = 1 # unimplemented page headings, timestamps etc. NUMBERS = 1 # line numbers (always on for now) # for error processing in symbol file... # we use these variables instead filename = SYMBOLS fnr = 0 # get the symbol table while ((getline < SYMBOLS) > 0) { ++fnr # for error handling if (($1 ~ /^#/) || (NF == 0)) # ignore comments and white space continue else if (($1 ~ /^[fgh]$/) && ($2 ~ /^[0-9][0-9]$/)) SHF[ $1, $2 ] = $3 else if ((NF == 2) && ($1 ~ /^[.]?[0-9][0-9]?$/)) USH[ $1 ] = $2 else # anything else is unexpected error("Unexpected error in symbol file") } } END { if (errno) printf "Aborted." } # set this for each line in data file(s) { fnr = FNR } # set the filename to data file(s) filename != FILENAME { filename = FILENAME } # print comments and blank lines NF == 0 { print ; next } $1 ~ /^#/ { print ; next } # process the input file(s) { ++lineno # take all extraneous spaces out by # re-assigning the first field to itself $1 = $1 if (USH[$1] ~ /^[fgh]$/) mnemonics = shifted(USH[$1]) else mnemonics = unshifted() printf "%02d %8s %s\n", lineno, $0, mnemonics } ############# # FUNCTIONS # ############# function error(mesg) { printf "ERROR: [%s]\n", mesg printf "FILE: [%s]\n", filename printf "LINE: [%s]\n", fnr printf "BUFF: [%s]\n", $0 exit ++errno } # wrapper functions which include error handling # function getSHF(shiftkey,code, rtnval) { if (shiftkey SUBSEP code in SHF) rtnval = SHF[ shiftkey, code ] else error("bad shifted keycode: " shiftkey " " code) return rtnval } function getUSH(code, rtnval) { if (code in USH) rtnval = USH[ code ] else error("bad keycode: " code) return rtnval } function shifted(shiftkey, line) { line = getSHF( shiftkey, $2 ) if (NF > 2) line = line " " getUSH( $3 ) return line } function unshifted( line) { line = getUSH( $1 ) if (NF > 1) line = line " " getUSH( $2 ) if (NF > 2) line = line " " getUSH( $3 ) return line }