|
Post by VDC 8x2 on Jul 31, 2014 14:49:12 GMT
Near as I can tell, it is the chr function and mid behaving badly on values over 127
|
|
|
Post by hydrophilic on Aug 1, 2014 5:42:14 GMT
Are you still trying to use ReadAllText ? It should work fine with open, but to be safe, include the binary property: Open fileName For Binary As #22 to read in the old file, or to write the new file, Open fileName For Binary Access Write As #33 of course the file# is arbitrary, just be sure it matches your GET#/PRINT#/PUT# commands EditJust thought of this.. if you use the first open, you should be able to verify correct file size is read into memory (see previous post), if that is correct, then MAYBE the problem is using Mid() / Chr() without the $. I always use Mid$() and Chr$() because I'm old school, but VB will accept Mid() and Chr() without a $. So MAYBE when you use Mid/Chr without $ it is doing the unicode conversion for non-ASCII values (bytes > 127) ? Actually, I was just looking at the source code for D64PlusEditor and I see strings can be longer than 64K... for example, it is creating an entire D64 with image$ = String$(174848, 0) which is 170.75 kiBytes. Oh yeah, D64Plus is kind of a mess to look at... originally by Forest Mook and then extended by me to work with D71 and D81. I tried to clean it up and make it more logical, but it is still a mess... Anyway if you look in 'frmMain' you can see code to open a D64 and create a D64... but the way he reads/writes data is not very informative, because it is indirect (going through a 'memory window' as intermediate step). I have some other VB code that is more logical but much more complex; however it is reading text data and writing binary data, so not a good example either.
|
|
|
Post by VDC 8x2 on Aug 1, 2014 13:40:48 GMT
What visual basic compiler are you using for your code?
|
|
|
Post by hydrophilic on Aug 2, 2014 6:42:36 GMT
I believe D64Plus was originally written for VB6 (you'd have to ask Forest Mook to be sure), and therefore it should run with any version of VisualStudio released in 1998 or later... I'm not sure about how it would work/fail with the free download of VB/C# from the MS website that is available now. I haven't had the money to spend on the latest version of VisualStudio, but it does compile / run(without compile) in other versions (2000~2010). I think new/modern versions of VisualStudio prefer to open a "Solution" file... but in the Open dialog you should be able to select "VB Workspace" or "VB Project" and with those options you should be able to access all source code of D64Plus... for example, "D64Editor.vbw" or "D64Editor.vbp" Umm... if anybody has looked at my CBM BASIC web-section, it should be obvious (after viewing several commands, disk commands in particular) that not everything is compatible... so just want to say/bitch/whine that after 30 years (!!!!) that the same problems of version conflicts exist... EditGoing off on a tangent topic, I think that some countries (definately Canada, and I beliveve also France) are hurting their language with futile attempts at regulation. Those countries set up of Regulatory Agencies to define what is "acceptible." On the one hand, I think it is a good idea to have a conservative/suggestive/preferred form of language, but on the other hand I believe it stifles growth. I think most everyone on planet Earth would agree that any "body" (any official organization) is MUCH slower to adopt to changes in the Real World (which is why new "start-up" companies [for example] often do well compared to "veteran" companies). I mean, langauges are actually a living thing... attempting to constrain them with laws and regulations is not only futile, but determental. Of course, a language is not a living thing in the sense of a tree outside my home or a pet inside my home, but it is still a living thing! (Of course some languages are dead, or dying.) Umm... so languages don't exist as physical things in reality, but as mental models in the minds of the people who use it. There was a really great discussion about the German language and its (declining) use in the world (compared to English across Europe as a whole). Sorry, I don't know where I was reading that... but it was a very fascinating discussion (Ja, so tun, als ich manchmal Deutsch sprechen!)
|
|
|
Post by VDC 8x2 on Aug 2, 2014 7:34:19 GMT
If we were in a rpg. english would be Common trade tongue.
|
|
|
Post by VDC 8x2 on Aug 16, 2014 16:58:48 GMT
I got a little frustrated with visual basic's handling of 8bit strings. So, I did the insane thing and made a lite version of it using basic7. It is just to get my head around it before diving back into vb. The history buffer is 255 characters and the look ahead buffer is 64 characters. The 255 is a limitation of sting length on basic 7 I think... run length, mirror, far64copy, far8copy and raw are implemented in the limitations of 255. This is a rough draft. I am testing it on a 40 col screen before trying vdc. This listing is very alpha you could say... 90 trap 830 100 rem vdcompress by vdc8x2 8/6/2014 110 hb$="":fb$="":sa=dec("1c00"):ea=dec("4000"):sp=0:l=ea-sa:fp=0 120 graphic 1,1 130 bload"testdata.prg",b0,p(sa),u10 140 scratch"output.cmp",u9 150 dopen #13,"output.cmp",u9,w 160 rem load future buffer 170 fast 180 do 190 :do 200 : if sp=l then exit 210 : if len(fb$)=64 then exit 220 : a=peek(sa+sp) 230 : sp=sp+1 240 : fp=fp+1 250 : fb$=fb$+chr$(a) 260 :loop 270 :if fp=0 then exit 280 :sc=fp 290 rem mirror copy 300 :if len(hb$)>1 and fp>1 then begin 310 : do 320 : if right$(hb$,sc)<>left$(fb$,sc)then sc=sc-1:else exit 330 : sc=sc-1:if sc=1 then exit 340 : loop 350 : if sc>1 then os$=chr$((sc-1)*4+2):mm=sc:print"mir";mm:goto 750 360 :bend 370 rem 64 copy far 380 :if len(hb$)=255 and len(fb$)=64 then begin 390 : sc=1 400 : do 410 : if mid$(hb$,sc,64)=fb$ then exit:else sc=sc+1 420 : if sc=192 then exit 430 : loop 440 : if sc<192 then sc=256-sc:os$=chr$((sc and 224)/8+3)+chr$((sc and 31)*8):mm=64:print"far64";mm:goto 750 450 :bend 460 rem 8 copy far 470 :if len(hb$)=255 and len(fb$)>7 then begin 480 : y=8:fg=0 490 : do 500 : sc=1 510 : do 520 : if mid$(hb$,sc,y)=left$(fb$,y)then fg=1:exit:else sc=sc+1 530 : if sc>255-y then exit 540 : loop 550 : if fg=1 then exit 560 : y=y-1 570 : if y=1 then exit 580 : loop 590 : if fg=1 then sc=256-sc:os$=chr$((sc and 224)/8+3)+chr$((sc and 31)*8+(y-1)):mm=y:print"far8";mm:goto 750 600 :bend 610 rem rel encoding section 620 :sc=1 630 :do 640 : if mid$(fb$,sc,1)=mid$(fb$,sc+1,1)then sc=sc+1:else exit 650 : if sc>fp then exit 660 :loop 670 :if sc>1 then os$=chr$((sc-1)*4+2)+left$(fb$,1):mm=sc:print"run";mm:goto750 680 rem raw encoding 690 :do 700 : if mid$(fb$,sc,1)<>mid$(fb$,sc+1,1)then sc=sc+1:else exit 710 : if sc>fp-1 then exit 720 :loop:sc=sc-1 730 :if sc>0 then os$=chr$(sc*4)+left$(fb$,sc):mm=sc:print"raw";mm 740 rem move future into history buffer 750 :print#13,os$;:rem print comp string to file 760 :PRINT hex$(sp+sa) 770 :hb$=right$(hb$,(255-mm))+left$(fb$,mm) 780 :if mm=fp then fb$="":else fb$=right$(fb$,fp-mm) 790 :print len(fb$) 800 :fp=fp-mm 810 loop 820 print#13,chr$(0) 830 dclose#13 Attachments:vdcompress.prg (1.45 KB)
|
|
|
Post by hydrophilic on Aug 17, 2014 14:59:36 GMT
Huh, I was wondering why you would be having problems with VB, but I was looking at docs for newer versions of VB and it says MidB is no longer supported (MidB supports 8bit byte-access); strings are all in unicode now which means you only have 16bit word-access. While it is natural the string handling would evolve to natively support unicode, I really don't know why they would break comptability by removing MidB (and LenB)... obviously Microsoft doesn't care about compatibility. Well being a big company, I can see why they might not be concerned with combatibility to other company's software, but it still boggles my mind they would be incompatible with themselves. This seems like a huge reason for a business (or student or hacker) NOT to use microsoft... why would you 'upgrade' if it will break many of your existing applications? C and Java are not as easy to use as V.BASIC, but the nice thing about them is they are 'always' backwards compatible, assuming you have the 'class' files used in older versions (just import them into the new version). That wouldn't work with MidB / LenB because they are (were) represented as internal keywords, not external functions. Anyway, I find it funny (in the pathetic sense) that huge incompatibilities exist today, 30 years after BASIC 7... language programmers still haven't solved the problem or perhaps ignore it and claim there is no problem. Sad Must be becuase some things change, and other things stay the same. Umm... really obvious if you think like that. Anyway, you are pretty crazy to try it in BASIC 7. I'm sure it could be done with enough effort, but it isn't something I would attempt. So +1 for tenacity!
|
|
|
Post by VDC 8x2 on Aug 19, 2014 17:35:09 GMT
I think I have figured out the vb thing...
I just have to take the whole output string a char at time then convert it into an array, a word at a time.
Since the values are 16 bit but numbers 0 to 255, I will downsize them down to 8bit one word at a time. Then saving each byte into the array, Then to file
|
|
|
Post by hydrophilic on Aug 20, 2014 7:59:57 GMT
So you are reading the file by words (16-bit) and the storing them in a char/byte array (8-bit)? That sounds reasonable. Sorry MS made things so difficult for you!
Edit On a positive note, once you have the data in byte array, it should not be much effort to generate a simple output file. As I was saying before, generating a simple "no RLE/Copy" (all raw/skip) codes should be a good place to start (easy to verify). If you can get that working, then it should just be a few lines of code to implement RLE... and several more to implement Copy.
Keep up the good work, and remember...
|
|
|
Post by VDC 8x2 on Aug 21, 2014 16:25:20 GMT
I got the Raw part working as intended, had to add the leading zero padding for start address. Otherwise the start of compressed file would be in the starting address on the c128 side when loaded.
Module Module1
Sub Main() Dim outputString As String = "" Dim packetSize As Integer = 0 Dim starting() As Byte = {0} Dim stringCount As Integer Dim historyPointer As Integer Dim processPointer As Integer Dim futurePointer As Integer Dim endOfProcess As Integer Dim raw As String = "" Dim compressTarget As String = "" Dim anyCompression As Integer Dim count As Integer
Dim bytes = My.Computer.FileSystem.ReadAllBytes("D:/Emulation/drive10/testdata.prg") 'convert array into our workstring For index = 0 To bytes.GetUpperBound(0) compressTarget = compressTarget & Chr(bytes(index)) Next historyPointer = 0 processPointer = 1 futurePointer = 256 stringCount = 1 endOfProcess = Len(compressTarget) Do anyCompression = 0 If anyCompression = 0 Then raw = raw & Mid(compressTarget, processPointer, 1) End If processPointer = processPointer + 1 If Len(raw) = 63 Then outputString = outputString & Chr(63 * 4) & raw raw = "" End If If processPointer > endOfProcess Then If Len(raw) = 0 Then outputString = outputString & Chr(0) Exit Do End If outputString = outputString & Chr(Len(raw) * 4) & raw & Chr(0) Exit Do End If Loop Dim outputFile(Len(outputString)) As Byte For count = 1 To Len(outputString) outputFile(count) = Asc(Mid(outputString, count, 1)) Next My.Computer.FileSystem.WriteAllBytes("D:/Emulation/drive10/outputData.prg", starting, False) My.Computer.FileSystem.WriteAllBytes("D:/Emulation/drive10/outputData.prg", outputFile, True) End Sub
End Module
|
|