; Amiga Newton Package Installer SetErr:End:End SetErr crcinit.l = 0; Dim crctab.l(256) For i=0 To 255 Read crctab(i) Next i crcdata: Data.l $0000, $c0c1, $c181, $0140, $c301, $03c0, $0280, $c241 Data.l $c601, $06c0, $0780, $c741, $0500, $c5c1, $c481, $0440 Data.l $cc01, $0cc0, $0d80, $cd41, $0f00, $cfc1, $ce81, $0e40 Data.l $0a00, $cac1, $cb81, $0b40, $c901, $09c0, $0880, $c841 Data.l $d801, $18c0, $1980, $d941, $1b00, $dbc1, $da81, $1a40 Data.l $1e00, $dec1, $df81, $1f40, $dd01, $1dc0, $1c80, $dc41 Data.l $1400, $d4c1, $d581, $1540, $d701, $17c0, $1680, $d641 Data.l $d201, $12c0, $1380, $d341, $1100, $d1c1, $d081, $1040 Data.l $f001, $30c0, $3180, $f141, $3300, $f3c1, $f281, $3240 Data.l $3600, $f6c1, $f781, $3740, $f501, $35c0, $3480, $f441 Data.l $3c00, $fcc1, $fd81, $3d40, $ff01, $3fc0, $3e80, $fe41 Data.l $fa01, $3ac0, $3b80, $fb41, $3900, $f9c1, $f881, $3840 Data.l $2800, $e8c1, $e981, $2940, $eb01, $2bc0, $2a80, $ea41 Data.l $ee01, $2ec0, $2f80, $ef41, $2d00, $edc1, $ec81, $2c40 Data.l $e401, $24c0, $2580, $e541, $2700, $e7c1, $e681, $2640 Data.l $2200, $e2c1, $e381, $2340, $e101, $21c0, $2080, $e041 Data.l $a001, $60c0, $6180, $a141, $6300, $a3c1, $a281, $6240 Data.l $6600, $a6c1, $a781, $6740, $a501, $65c0, $6480, $a441 Data.l $6c00, $acc1, $ad81, $6d40, $af01, $6fc0, $6e80, $ae41 Data.l $aa01, $6ac0, $6b80, $ab41, $6900, $a9c1, $a881, $6840 Data.l $7800, $b8c1, $b981, $7940, $bb01, $7bc0, $7a80, $ba41 Data.l $be01, $7ec0, $7f80, $bf41, $7d00, $bdc1, $bc81, $7c40 Data.l $b401, $74c0, $7580, $b541, $7700, $b7c1, $b681, $7640 Data.l $7200, $b2c1, $b381, $7340, $b101, $71c0, $7080, $b041 Data.l $5000, $90c1, $9181, $5140, $9301, $53c0, $5280, $9241 Data.l $9601, $56c0, $5780, $9741, $5500, $95c1, $9481, $5440 Data.l $9c01, $5cc0, $5d80, $9d41, $5f00, $9fc1, $9e81, $5e40 Data.l $5a00, $9ac1, $9b81, $5b40, $9901, $59c0, $5880, $9841 Data.l $8801, $48c0, $4980, $8941, $4b00, $8bc1, $8a81, $4a40 Data.l $4e00, $8ec1, $8f81, $4f40, $8d01, $4dc0, $4c80, $8c41 Data.l $4400, $84c1, $8581, $4540, $8701, $47c0, $4680, $8641 Data.l $8201, $42c0, $4380, $8341, $4100, $81c1, $8081, $4040 #M1=$ff #M2=$ff00 Function GetByte{} a.w=ReadSerial (0,True) Function Return a End Function Function updcrc{icrc.l,icp.l,icnt.l} SHARED crctab() crc.l = icrc cp.l = icp cnt.l = icnt While cnt>0 cnt-1 dummy1.l=(crc ASR 8)&#M1 dummy2.l=crc&#M1 dummy3.l=Peek.b(cp)&#M1 cp+1 dummy4.l=crctab((dummy2|dummy3)&(NOT(dummy2&dummy3))) crc=(dummy1|dummy4)&(NOT(dummy1&dummy4)) Wend Function Return crc End Function #SYN=$16 #DLE=$10 #STX=$02 #ETX=$03 Statement fcscalc{fcs.l,d$} ;fcs is a pointer to a variable Poke.l fcs,updcrc{Peek.l(fcs),&d$,1} End Statement Function read_frame{buff.l} ;buff is the address to a buffer buf.w=#SYN ;a byte type will not return `-1' i=0 org.l=buff; fcs.l=0; fcs_rec.l=0; While buf=#SYN buf=GetByte{} Wend If buf=#DLE buf=GetByte{} If buf=#STX Repeat buf=GetByte{} If buf=#DLE buf=GetByte{} Select buf Case #ETX fcscalc{&fcs,Chr$(buf)} fcs_rec=GetByte{} fcs_rec=((GetByte{}) ASL 8)+fcs_rec If fcs_rec&$ffff=fcs&$ffff Then Function Return i NPrint "Bad CRC ",Hex$(fcs_rec)," ",Hex$(fcs)," " Function Return -1 Case #DLE Poke.b buff,buf buff+1 fcscalc{&fcs,Chr$(buf)} i+1 Default NPrint "Invalid frame" Function Return -1 End Select Else Poke.b buff,buf buff+1 fcscalc{&fcs,Chr$(buf)} i+1 EndIf Forever EndIf EndIf End Function Statement send_frame{buff.l,size.l} ;buff is a pointer to a series of bytes fcs.l=0 WriteSerial 0,#SYN WriteSerial 0,#DLE WriteSerial 0,#STX For i=0 To size-1 WriteSerial 0,Peek.b(buff+i)&$ff If Peek.b(buff+i)=#DLE Then WriteSerial 0,#DLE fcscalc{&fcs,Chr$(Peek.b(buff+i)&$ff)} Next i WriteSerial 0,#DLE WriteSerial 0,#ETX fcscalc{&fcs,Chr$(#ETX)} WriteSerial 0,fcs&$ff WriteSerial 0,(fcs&$ff00) ASR 8 End Statement #LR=1 #LD=2 #LT=4 #LA=5 #LN=6 #LNA=7 Statement sendLA{nr,cr} la$=Chr$(3)+Chr$(5)+Chr$(0)+Chr$(0) Poke.b &la$+2,nr Poke.b &la$+3,cr send_frame{&la$,Len(la$)} End Statement s.w=0 r.w=0 Function sendData{d.l,size.l} ;data is a pointer to a string of bytes SHARED s,r buf$=String$(" ",2048) buf2$=String$(" ",2048) i.l=0 Poke.b &buf$,2 Poke.b &buf$+1,4 Poke.b &buf$+2,s For i=0 To size-1 Poke.b &buf$+i+3,Peek.b(d+i) Next i Repeat send_frame{&buf$,size+3} dummy.l=read_frame{&buf2$} If (Peek.b(&buf2$)=3) & (Peek.b(&buf2$+1)=5) & ((Peek.b(&buf2$+2)&$ff)=s) s=(s+1)&$ff Function Return size Else Print "...NEWTON REJECTS DATA FRAME..." Else EndIf Forever End Function Function receiveData{d.l,size.l} ;data is a pointer to a string of bytes SHARED r buf$=String$(" ",2048) ss.l=0 i.l=0 Repeat ss=read_frame{&buf$} If ss>0 sendLA{r,1} r=(r+1)&$ff If ss>size Then ss=size For i=0 To ss-1 Poke.b d+i,Peek.b(&buf$+i+3) Next i Function Return ss EndIf Forever End Function Statement waitConnection{} SHARED s,r buf$=String$(" ",2048) lr$=Chr$(23)+Chr$(1)+Chr$(2)+Chr$(1)+Chr$(6)+Chr$(1)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(255)+Chr$(2)+Chr$(1)+Chr$(2) lr$=lr$+Chr$(3)+Chr$(1)+Chr$(1)+Chr$(4)+Chr$(2)+Chr$(64)+Chr$(0)+Chr$(8)+Chr$(1)+Chr$(3) buf$=String$(" ",64) While read_frame{&buf$}<0 Wend send_frame{&lr$,Len(lr$)} r=1 dummy.l=read_frame{&buf$} s=1 End Statement Statement sendDisconnect{} ld$=Chr$(7)+Chr$(2)+Chr$(1)+Chr$(1)+Chr$(255)+Chr$(2)+Chr$(1)+Chr$(0) send_frame{&ld$,Len(ld$)} End Statement ;main routine lt$="newtdockdock"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4) lt2$="newtdockstim"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(4)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(5) lt3$="newtdocklpkg"+Chr$(0)+Chr$(0)+Chr$($2f)+Chr$($a0) lt4$="newtdockdisc"+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0) buf$=String$(" ",128) NPrint "Amiga NPI 0.1" NPrint "" If OpenSerial ("serial.device",0,38400,16) If (NumPars=1) & ReadFile(0,Par$(1)) Poke.l <3$+12,Lof(0) Print "Waiting..." waitConnection{} NPrint "Connecting" dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockrtdk Print "Request to dock received..." dummy.l=sendData{<$,Len(lt$)} ;newtdockdock NPrint "Docking initiated" dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockname Print "Newton name received..." dummy.l=sendData{<2$,Len(lt2$)} ;newtdockstim Print "Timeout set..." dummy.l=receiveData{&buf$,Len(buf$)} ;newtdockdres NPrint "Result received" file_length.l=Lof(0) NPrint "Loading ",Par$(1),", ",file_length," bytes..." dummy.l=sendData{<3$,Len(lt3$)} ;newtdocklpkg NPrint "Transferring package" ReadMem 0,&buf$,Len(buf$) rr.l=0 size.l=0 If Lof(0)0 ;file length is not an evenly divisible by four NPrint "" NPrint "WARNING - package file length is incorrect..." NPrint "...padding file with extras zeros" rr2.l=(rr+4)&$fffffffc ;round up file length For i=rr+1 To rr2 ;fill with zeros Poke &buf$+i,0 Next i rr=rr2 EndIf If rr>0 Then dummy.l=sendData{&buf$,rr} Wend NPrint "" Print "Package sent..." dummy.l=receiveData{&buf$,Len(buf$)} ; newtdockdres NPrint "Result received" dummy.l=sendData{<4$,Len(lt4$)} ; newtdockdisc Print "Sent disconnect..." VWait 50 sendDisconnect{} NPrint "Disconnected" CloseFile 0 Else NPrint "ERROR - Could not open input file" NPrint "" NPrint "AmigaNPI PackageFile" NPrint "" NPrint "Converted to the Amiga by David Fong" NPrint "Written by Filip R. Zawadiak" NPrint "" NPrint "Note that this program can only load files with" NPrint "the .pkg extension. It cannot upload .hqx files" NPrint "or Stuffit (.sit) files" EndIf CloseSerial 0 Else NPrint "ERROR - Could not open serial port." EndIf End