DeHex

SBASIC allows the use of hex and binary literals in programs. This makes for clearer code in many cases, for example where system offsets are referenced, or to set 24bit RGB colour values, etc. Unfortunately, SuperBASIC cannot handle SBASIC programs containing hex or binary literals. Each line containing such code is flagged as a MISTake and has to be altered before the program can be run or compiled. Prior to V3.42 Q-Liberator also couldnt handle these and, AFAIK, Turbo still cant.

Here is the cure: LOAD your program into SBASIC, MERGE DeHex_bas into it, and type DeHex. The program will terminate with a "PROC/FN cleared" message. (This is normal.) Then QSAVE or SAVE your program (in the latter case perhaps with a new name!). Youll find that all the hex and binary literals have magically been translated into decimal numbers, and DeHex itself has disappeared. The saved program is now ok to compile or be moved to SuperBASIC.

Note: Make sure you dont RENUMber this program, or your own program after merging DeHex. Also ensure that your program doesnt have line numbers above 32738 before you merge!

32738 :
32739 DEFine PROCedure DeHex
32740 LOCal scan, pos, tb%, l%
32741 REMark Program to convert SBAS $hex
32742 REMark and  %bin literals to decimal
32743 REMark © pjwitte 2oo1
32744 :
32745 pos = PEEK_L(\\$10) + 2: REMark Get start of program
32746 REPeat scan
32747  IF pos > PEEK_L(\\$14): EXIT scan
32748 :
32749  tb% = PEEK(\\pos)
32750  SELect ON tb%
32751   = $8B,  $8C : REMark strings
32752                 pos = pos + 2
32753                 l% = PEEK_W(\\pos): REMark Length of text
32754                 pos = pos + ((l% + 3 ) && -2): REMark skip text
32755   = $8D,  $88 : REMark skip line numbers and names
32756                 pos = pos + 4
32757   = $D0 TO $FF: REMark numbers % to $, and beyond
32758                 POKE\\pos, tb% || $F0 : REMark Convert type to decimal
32759                 pos = pos + 6
32760   = REMAINDER :
32761                 pos = pos + 2
32762  END SELect
32763 END REPeat scan
32764 DLINE 32738 TO
32765 END DEFine
32766 :
  
Generated with sb2htm on 2019 Mar 28
©pjwitte March 2oi9