From: "Steve Agnew" To: EarlGlynn Date: Fri, 1 Oct 1999 14:02:12 +1200 Hi Earl, I came across your message in Deja News when I was looking for some delphi code to do ebcdic & ascii conversion. We were looking for code to convert a buffer in one go, rather than character by character, so the source code on your site wasn't really suitable. In the end we couldn't find anything useful on the net, so we wrote it ourselves. I thought I would send you a copy too in case you were interested. Anyway, here is the code we ended up with (Delphi 4): unit EBCDIC; //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INTERFACE //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PROCEDURE Ebcdic2Ascii( Var Buffer; Count : Cardinal ); PROCEDURE Ascii2Ebcdic( Var Buffer; Count : Cardinal ); //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPLEMENTATION //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Const E2ATable : Array[ 0..255 ] of Byte = ( $00,$01,$02,$03,$20,$09,$20,$7F,$20,$20,$20,$0B,$0C,$0D,$0E,$0F, $10,$11,$12,$20,$20,$20,$08,$20,$18,$19,$20,$20,$1C,$1D,$1E,$1F, $20,$20,$1C,$20,$20,$0A,$17,$1B,$20,$20,$20,$20,$20,$05,$06,$07, $20,$20,$16,$20,$20,$1E,$20,$04,$20,$20,$20,$20,$14,$15,$20,$20, $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$2E,$3C,$28,$2B,$7C, $26,$20,$20,$20,$20,$20,$20,$20,$20,$20,$21,$24,$2A,$29,$3B,$7E, $2D,$2F,$20,$20,$20,$20,$20,$20,$20,$20,$20,$2C,$25,$20,$3E,$3F, $20,$20,$20,$20,$20,$20,$20,$20,$20,$60,$3A,$23,$40,$60,$3D,$22, $20,$61,$62,$63,$64,$65,$66,$67,$68,$69,$20,$20,$20,$20,$20,$20, $20,$6A,$6B,$6C,$6D,$6E,$6F,$70,$71,$72,$20,$20,$20,$20,$20,$20, $20,$20,$73,$74,$75,$76,$77,$78,$79,$7A,$20,$20,$20,$20,$20,$20, $20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20,$20, $7B,$41,$42,$43,$44,$45,$46,$47,$48,$49,$20,$20,$20,$20,$20,$20, $7D,$4A,$4B,$4C,$4D,$4E,$4F,$50,$51,$52,$20,$20,$20,$20,$20,$20, $20,$20,$53,$54,$55,$56,$57,$58,$59,$5A,$20,$20,$20,$20,$20,$20, $30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$20,$20,$20,$20,$20,$20 ); A2ETable : Array[ 0..255 ] of Byte = ( $00,$01,$02,$03,$37,$2D,$2E,$2F,$16,$05,$25,$0B,$0C,$0D,$0E,$0F, $10,$11,$12,$13,$3C,$3D,$32,$26,$18,$19,$3F,$27,$1C,$1D,$1E,$1F, $40,$5A,$7F,$7B,$5B,$6C,$50,$7D,$4D,$5D,$5C,$4E,$6B,$60,$4B,$61, $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7,$F8,$F9,$7A,$5E,$4C,$7E,$6E,$6F, $7C,$C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$C9,$D1,$D2,$D3,$D4,$D5,$D6, $D7,$D8,$D9,$E2,$E3,$E4,$E5,$E6,$E7,$E8,$E9,$5B,$E0,$5D,$5E,$6D, $79,$81,$82,$83,$84,$85,$86,$87,$88,$89,$91,$92,$93,$94,$95,$96, $97,$98,$99,$A2,$A3,$A4,$A5,$A6,$A7,$A8,$A9,$C0,$6A,$D0,$5F,$07, $00,$01,$02,$03,$37,$2D,$2E,$2F,$16,$05,$25,$0B,$0C,$0D,$0E,$0F, $10,$11,$12,$13,$3C,$3D,$32,$26,$18,$19,$3F,$27,$1C,$1D,$1E,$1F, $40,$5A,$7F,$7B,$5B,$6C,$50,$7D,$4D,$5D,$5C,$4E,$6B,$60,$4B,$61, $F0,$F1,$F2,$F3,$F4,$F5,$F6,$F7,$F8,$F9,$7A,$5E,$4C,$7E,$6E,$6F, $7C,$C1,$C2,$C3,$C4,$C5,$C6,$C7,$C8,$C9,$D1,$D2,$D3,$D4,$D5,$D6, $D7,$D8,$D9,$E2,$E3,$E4,$E5,$E6,$E7,$E8,$E9,$5B,$E0,$5D,$5E,$6D, $79,$81,$82,$83,$84,$85,$86,$87,$88,$89,$91,$92,$93,$94,$95,$96, $97,$98,$99,$A2,$A3,$A4,$A5,$A6,$A7,$A8,$A9,$C0,$6A,$D0,$5F,$07 ); //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PROCEDURE Ebcdic2Ascii( Var Buffer; Count : Cardinal ); register; asm push edi push esi push ebx { On Entry, eax is a pointer to the Buffer } { edx is Count } or edx, edx { Anything to do? } jz @@Done mov ecx, edx { Put the count into ecx } mov edx, eax { Use [edx] as the buffer pointer } lea ebx, E2ATable @@Loop: mov al, [edx] xlat mov [edx], al inc edx Loop @@Loop { Repeat until ecx = 0 } @@Done: pop ebx pop esi pop edi end; //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - PROCEDURE Ascii2Ebcdic( Var Buffer; Count : Cardinal ); register; asm push edi push esi push ebx { On Entry, eax is a pointer to the Buffer } { edx is Count } or edx, edx { Anything to do? } jz @@Done mov ecx, edx { Put the count into ecx } mov edx, eax { Use [edx] as the buffer pointer } lea ebx, A2ETable @@Loop: mov al, [edx] xlat mov [edx], al inc edx Loop @@Loop { Repeat until ecx = 0 } @@Done: pop ebx pop esi pop edi end; end.