CpcAlive est un
environnement
de programmation
compatible
Amstrad CPC
pour création
d'animations
 graphiques.




Z80 opcodes et programmation

SmallAsm est un assembleur Z80
pour Dos


Les mots clés du basic Cpc

Les messages d'erreur du basic Cpc

La mémoire

La gestion des disquettes


Installateur CpcAlive pour
Windows & pour DosBox


Documentation CpcAlive






English

* HEX2BIN - Intel hex to binary conversion *


BAS: <- file header for the emulator CpcAlive for Dosbox
//HEX2BIN - Intel hex to binary conversion - cpcalive.com//
    defint a-z:sor=8:er%=0:mode 2
    input"Intel Hex Input file name:",InputFile$
    input"Output file name:",OutputFile$
    |OUTPUT,OutputFile$,@er%
    if er%<>0 then OFileEr
    |INPUT,InputFile$+":K",@er%:'(":K" forces Intel Hex lines throught keyboard manager)
    if er%<>0 then IFileEr

NextLine:
    a$=inkey$:if a$="" or a$=chr$(13) then |exit,"File converted"
    if a$<>":" then |exit,"Error in hex file"
    input" ",ObjLine$
    adr=val("&"+mid$(ObjLine$,3,4))
    if adr<adrbak then |exit,"addresses not in order (change ORG's location in source)"
    if adrbak<>0 then gosub ZeroFill:'replaces holes with zeros
    adrbak=adr
    ObjLine$=right$(ObjLine$,len(ObjLine$)-8)

//binary output
    for i=1 to len(ObjLine$)-2 step 2
        x=val("&"+mid$(ObjLine$,i,2))
        ?#sor,chr$(x);
        adrbak=adrbak+1
    next
    goto NextLine

/*output in form DB 0XXH,...
    ?#sor,"db ";
    for i=1 to len(ObjLine$)-4 step 2
        x=val("&"+mid$(ObjLine$,i,2)):?#sor,hex$(x,3)"h,";
    next
    x=val("&"+mid$(ObjLine$,len(ObjLine$)-3,2)):?#sor,hex$(x,3)"h"
    goto NextLine
*/

//replaces holes with zeros
ZeroFill:
    while adrbak<>adr
        ?#sor,chr$(0);
        adrbak=adrbak+1
    wend
    return
   
//I/O error messages
IFileEr:
        if er%=2 then |exit,"Input error: file not found"
        if er%=3 then |exit,"Input error: directory or file not found"
        if er%=4 then |exit,"Input error: no more Dos handle"
        if er%=5 then |exit,"Input error: refused access"
        |exit,"Input file error"
OFileEr:
        if er%=2 or er%=5 then |exit,"Output error: refused access"
        if er%=3 then |exit,"Output error: directory not found"
        if er%=4 then |exit,"Output error: no more Dos handle"
        |exit,"Output file error"