Objective
Load any file, convert it into 16‑byte hexadecimal blocks, and generate retro BASIC code ready to save as .bas.
The memory load command (POKE) is not included; see below.
Load any file, convert it into 16‑byte hexadecimal blocks, and generate retro BASIC code ready to save as .bas.
The memory load command (POKE) is not included; see below.
Expect about 30–35% less source size (may be more) when using concatenated hex strings (16 bytes per line).
In this version, each DATA line contains a long string of hexadecimal characters representing 16 bytes. The program reads the string, splits it into two-character chunks, converts each chunk into a numeric value, and then POKEs it into memory. The loop continues until the special end marker "ZZ" is reached.
1000 REM Concatenated hex blocks
1010 DATA A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5A5
1020 DATA ZZ
1030 ADR = &HC000: REM start address in memory
1040 READ D$
1050 IF D$="ZZ" THEN 2020
1060 FOR I=1 TO LEN(D$) STEP 2
1070 V = VAL("&H"+MID$(D$,I,2))
1080 POKE ADR, V
1090 ADR = ADR + 1
2000 NEXT I
2010 GOTO 1040
2020 RETURN
Concatenated
1000 REM Sub-routine
1010 ADR = &HC000: REM start address in memory
1020 READ D$:IF D$="ZZ" THEN 1050
1030 FOR I=1 TO LEN(D$) STEP 2: V=VAL("&H"+MID$(D$,I,2)):POKE ADR,V:ADR=ADR+1:NEXT
1040 GOTO 1020
1050 RETURN
Here, each DATA line lists hexadecimal values separated by commas. The program reads each value directly, converts it into a number, and POKEs it into memory one by one. The process stops when the "ZZ" marker is encountered, signaling the end of the data.
100 REM Comma-separated hex values
110 DATA A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5,A5
120 DATA ZZ
130 ADR = &HC000: REM start address in memory
140 READ D$
150 IF D$="ZZ" THEN END: REM or GOTO line
160 V = VAL("&H"+D$)
170 POKE ADR, V
180 ADR = ADR + 1
190 GOTO 140